From nobody Tue Feb 10 11:33:01 2026 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 27069274B3B; Mon, 26 Jan 2026 06:23:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.3 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769408612; cv=none; b=RE51CCSACEgbFzpCXhAU9fw1LnY8fMmjmI4ei7AcsZVjYPbH5601Vq+8kcQvAsAVB8du+CJZdjsp+jxbLmtwfvsXKtMy33Zxl0GZ1dqdrKUkEZcQazxcoeRi4pPQ0/ttpAW0NxBADT3TgqYI2IEtyC+Srn1EX6lBDbRzq029m+U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769408612; c=relaxed/simple; bh=ch3WUowE0r41pxeM/FiSHDm2a/bn91+yh/Iqf4f8cno=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=C0xxWGbg8JFcbxTIUY+RmFvbBDLOuIoIzsckd41pUIP2MraFP68O1uCBh90M1EdwH3cPNfU9JxQxDVrBbmv/UiKEge18VMAj5zG/4d/eHdvooJLJrE4YvD6XuxLy16cO42vMsWZ4KmzOniOytmSMKUXLJP7kNawKnYE6gyd4M5M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=LZRIz5PX; arc=none smtp.client-ip=220.197.31.3 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="LZRIz5PX" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=xj XLh9OxB7OyImjOAQduujoqYcXrgtQdnE2zosJw5bA=; b=LZRIz5PXT2dCs1xW6H PsWynbvXE3QNrr7eH7hkvUYaYOAK6nGU5Ko6NvPd8f6+mc5Cx/60m8USTke+IhUr lnu9/26K4rt66kjJw5VoCGLRCdgV4KCf5Umqd9ceEnuZnjsrZws1jkgYDOFbCvwt R+lnuLaIQIx+MO7rqJTF/bKB8= Received: from localhost.localdomain (unknown []) by gzga-smtp-mtada-g1-3 (Coremail) with SMTP id _____wCHzzkJCHdpL7kRIg--.5216S8; Mon, 26 Jan 2026 14:22:15 +0800 (CST) From: Slark Xiao To: loic.poulain@oss.qualcomm.com, ryazanov.s.a@gmail.com, johannes@sipsolutions.net, andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, mani@kernel.org Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, slark_xiao@163.com Subject: [net-next v8 6/8] net: wwan: hwsim: refactor to support more port types Date: Mon, 26 Jan 2026 14:21:56 +0800 Message-Id: <20260126062158.308598-7-slark_xiao@163.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20260126062158.308598-1-slark_xiao@163.com> References: <20260126062158.308598-1-slark_xiao@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wCHzzkJCHdpL7kRIg--.5216S8 X-Coremail-Antispam: 1Uf129KBjvJXoW3Xr4UKr1UAry5CFWfAFykAFb_yoWxJrykpa yqgr9xKrWUt3Z3Wry7tFsrAa4Fkrn5WryvqrWrW34FqFn7t345ZFWvk3s0kr4DAFy7CFy3 Cr98t343Jw47Cr7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0pEG-ewUUUUU= X-CM-SenderInfo: xvod2y5b0lt0i6rwjhhfrp/xtbCvxhApGl3CBgIPwAA36 Content-Type: text/plain; charset="utf-8" From: Sergey Ryazanov Just introduced WWAN NMEA port type needs a testing option. The WWAN HW simulator was developed with the AT port type in mind and cannot be easily extended. Refactor it now to make it capable to support more port types. No big functional changes, mostly renaming with a little code rearrangement. Signed-off-by: Sergey Ryazanov Reviewed-by: Loic Poulain --- drivers/net/wwan/wwan_hwsim.c | 73 ++++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 32 deletions(-) diff --git a/drivers/net/wwan/wwan_hwsim.c b/drivers/net/wwan/wwan_hwsim.c index 733688cd4607..11d15dc39041 100644 --- a/drivers/net/wwan/wwan_hwsim.c +++ b/drivers/net/wwan/wwan_hwsim.c @@ -56,12 +56,16 @@ struct wwan_hwsim_port { struct wwan_port *wwan; struct work_struct del_work; struct dentry *debugfs_topdir; - enum { /* AT command parser state */ - AT_PARSER_WAIT_A, - AT_PARSER_WAIT_T, - AT_PARSER_WAIT_TERM, - AT_PARSER_SKIP_LINE, - } pstate; + union { + struct { + enum { /* AT command parser state */ + AT_PARSER_WAIT_A, + AT_PARSER_WAIT_T, + AT_PARSER_WAIT_TERM, + AT_PARSER_SKIP_LINE, + } pstate; + } at_emul; + }; }; =20 static const struct file_operations wwan_hwsim_debugfs_portdestroy_fops; @@ -101,16 +105,16 @@ static const struct wwan_ops wwan_hwsim_wwan_rtnl_ops= =3D { .setup =3D wwan_hwsim_netdev_setup, }; =20 -static int wwan_hwsim_port_start(struct wwan_port *wport) +static int wwan_hwsim_at_emul_start(struct wwan_port *wport) { struct wwan_hwsim_port *port =3D wwan_port_get_drvdata(wport); =20 - port->pstate =3D AT_PARSER_WAIT_A; + port->at_emul.pstate =3D AT_PARSER_WAIT_A; =20 return 0; } =20 -static void wwan_hwsim_port_stop(struct wwan_port *wport) +static void wwan_hwsim_at_emul_stop(struct wwan_port *wport) { } =20 @@ -120,7 +124,7 @@ static void wwan_hwsim_port_stop(struct wwan_port *wpor= t) * * Be aware that this processor is not fully V.250 compliant. */ -static int wwan_hwsim_port_tx(struct wwan_port *wport, struct sk_buff *in) +static int wwan_hwsim_at_emul_tx(struct wwan_port *wport, struct sk_buff *= in) { struct wwan_hwsim_port *port =3D wwan_port_get_drvdata(wport); struct sk_buff *out; @@ -142,17 +146,17 @@ static int wwan_hwsim_port_tx(struct wwan_port *wport= , struct sk_buff *in) for (i =3D 0, s =3D 0; i < in->len; ++i) { char c =3D in->data[i]; =20 - if (port->pstate =3D=3D AT_PARSER_WAIT_A) { + if (port->at_emul.pstate =3D=3D AT_PARSER_WAIT_A) { if (c =3D=3D 'A' || c =3D=3D 'a') - port->pstate =3D AT_PARSER_WAIT_T; + port->at_emul.pstate =3D AT_PARSER_WAIT_T; else if (c !=3D '\n') /* Ignore formating char */ - port->pstate =3D AT_PARSER_SKIP_LINE; - } else if (port->pstate =3D=3D AT_PARSER_WAIT_T) { + port->at_emul.pstate =3D AT_PARSER_SKIP_LINE; + } else if (port->at_emul.pstate =3D=3D AT_PARSER_WAIT_T) { if (c =3D=3D 'T' || c =3D=3D 't') - port->pstate =3D AT_PARSER_WAIT_TERM; + port->at_emul.pstate =3D AT_PARSER_WAIT_TERM; else - port->pstate =3D AT_PARSER_SKIP_LINE; - } else if (port->pstate =3D=3D AT_PARSER_WAIT_TERM) { + port->at_emul.pstate =3D AT_PARSER_SKIP_LINE; + } else if (port->at_emul.pstate =3D=3D AT_PARSER_WAIT_TERM) { if (c !=3D '\r') continue; /* Consume the trailing formatting char as well */ @@ -162,11 +166,11 @@ static int wwan_hwsim_port_tx(struct wwan_port *wport= , struct sk_buff *in) skb_put_data(out, &in->data[s], n);/* Echo */ skb_put_data(out, "\r\nOK\r\n", 6); s =3D i + 1; - port->pstate =3D AT_PARSER_WAIT_A; - } else if (port->pstate =3D=3D AT_PARSER_SKIP_LINE) { + port->at_emul.pstate =3D AT_PARSER_WAIT_A; + } else if (port->at_emul.pstate =3D=3D AT_PARSER_SKIP_LINE) { if (c !=3D '\r') continue; - port->pstate =3D AT_PARSER_WAIT_A; + port->at_emul.pstate =3D AT_PARSER_WAIT_A; } } =20 @@ -183,18 +187,25 @@ static int wwan_hwsim_port_tx(struct wwan_port *wport= , struct sk_buff *in) return 0; } =20 -static const struct wwan_port_ops wwan_hwsim_port_ops =3D { - .start =3D wwan_hwsim_port_start, - .stop =3D wwan_hwsim_port_stop, - .tx =3D wwan_hwsim_port_tx, +static const struct wwan_port_ops wwan_hwsim_at_emul_port_ops =3D { + .start =3D wwan_hwsim_at_emul_start, + .stop =3D wwan_hwsim_at_emul_stop, + .tx =3D wwan_hwsim_at_emul_tx, }; =20 -static struct wwan_hwsim_port *wwan_hwsim_port_new(struct wwan_hwsim_dev *= dev) +static struct wwan_hwsim_port *wwan_hwsim_port_new(struct wwan_hwsim_dev *= dev, + enum wwan_port_type type) { + const struct wwan_port_ops *ops; struct wwan_hwsim_port *port; char name[0x10]; int err; =20 + if (type =3D=3D WWAN_PORT_AT) + ops =3D &wwan_hwsim_at_emul_port_ops; + else + return ERR_PTR(-EINVAL); + port =3D kzalloc(sizeof(*port), GFP_KERNEL); if (!port) return ERR_PTR(-ENOMEM); @@ -205,9 +216,7 @@ static struct wwan_hwsim_port *wwan_hwsim_port_new(stru= ct wwan_hwsim_dev *dev) port->id =3D dev->port_idx++; spin_unlock(&dev->ports_lock); =20 - port->wwan =3D wwan_create_port(&dev->dev, WWAN_PORT_AT, - &wwan_hwsim_port_ops, - NULL, port); + port->wwan =3D wwan_create_port(&dev->dev, type, ops, NULL, port); if (IS_ERR(port->wwan)) { err =3D PTR_ERR(port->wwan); goto err_free_port; @@ -392,7 +401,7 @@ static ssize_t wwan_hwsim_debugfs_portcreate_write(stru= ct file *file, struct wwan_hwsim_dev *dev =3D file->private_data; struct wwan_hwsim_port *port; =20 - port =3D wwan_hwsim_port_new(dev); + port =3D wwan_hwsim_port_new(dev, WWAN_PORT_AT); if (IS_ERR(port)) return PTR_ERR(port); =20 @@ -459,6 +468,8 @@ static int __init wwan_hwsim_init_devs(void) int i, j; =20 for (i =3D 0; i < wwan_hwsim_devsnum; ++i) { + struct wwan_hwsim_port *port; + dev =3D wwan_hwsim_dev_new(); if (IS_ERR(dev)) return PTR_ERR(dev); @@ -471,9 +482,7 @@ static int __init wwan_hwsim_init_devs(void) * the simulator readiness time. */ for (j =3D 0; j < 2; ++j) { - struct wwan_hwsim_port *port; - - port =3D wwan_hwsim_port_new(dev); + port =3D wwan_hwsim_port_new(dev, WWAN_PORT_AT); if (IS_ERR(port)) return PTR_ERR(port); =20 --=20 2.25.1