From: Sergey Ryazanov <ryazanov.s.a@gmail.com>
To: Loic Poulain <loic.poulain@linaro.org>,
Johannes Berg <johannes@sipsolutions.net>,
"David S. Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>
Cc: netdev@vger.kernel.org
Subject: [PATCH net-next 01/10] wwan_hwsim: support network interface creation
Date: Tue, 15 Jun 2021 03:30:07 +0300 [thread overview]
Message-ID: <20210615003016.477-2-ryazanov.s.a@gmail.com> (raw)
In-Reply-To: <20210615003016.477-1-ryazanov.s.a@gmail.com>
Add support for networking interface creation via the WWAN core by
registering the WWAN netdev creation ops for each simulated WWAN device.
Implemented minimalistic netdev support where the xmit callback just
consumes all egress skbs.
This should help with WWAN network interfaces creation testing.
Signed-off-by: Sergey Ryazanov <ryazanov.s.a@gmail.com>
---
drivers/net/wwan/wwan_hwsim.c | 48 +++++++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+)
diff --git a/drivers/net/wwan/wwan_hwsim.c b/drivers/net/wwan/wwan_hwsim.c
index 472cae544a2b..c1e850b9c087 100644
--- a/drivers/net/wwan/wwan_hwsim.c
+++ b/drivers/net/wwan/wwan_hwsim.c
@@ -14,10 +14,13 @@
#include <linux/spinlock.h>
#include <linux/list.h>
#include <linux/skbuff.h>
+#include <linux/netdevice.h>
#include <linux/wwan.h>
#include <linux/debugfs.h>
#include <linux/workqueue.h>
+#include <net/arp.h>
+
static int wwan_hwsim_devsnum = 2;
module_param_named(devices, wwan_hwsim_devsnum, int, 0444);
MODULE_PARM_DESC(devices, "Number of simulated devices");
@@ -64,6 +67,38 @@ static const struct file_operations wwan_hwsim_debugfs_devdestroy_fops;
static void wwan_hwsim_port_del_work(struct work_struct *work);
static void wwan_hwsim_dev_del_work(struct work_struct *work);
+static netdev_tx_t wwan_hwsim_netdev_xmit(struct sk_buff *skb,
+ struct net_device *ndev)
+{
+ ndev->stats.tx_packets++;
+ ndev->stats.tx_bytes += skb->len;
+ consume_skb(skb);
+ return NETDEV_TX_OK;
+}
+
+static const struct net_device_ops wwan_hwsim_netdev_ops = {
+ .ndo_start_xmit = wwan_hwsim_netdev_xmit,
+};
+
+static void wwan_hwsim_netdev_setup(struct net_device *ndev)
+{
+ ndev->netdev_ops = &wwan_hwsim_netdev_ops;
+ ndev->needs_free_netdev = true;
+
+ ndev->mtu = ETH_DATA_LEN;
+ ndev->min_mtu = ETH_MIN_MTU;
+ ndev->max_mtu = ETH_MAX_MTU;
+
+ ndev->type = ARPHRD_NONE;
+ ndev->flags = IFF_POINTOPOINT | IFF_NOARP;
+}
+
+static const struct wwan_ops wwan_hwsim_wwan_rtnl_ops = {
+ .owner = THIS_MODULE,
+ .priv_size = 0, /* No private data */
+ .setup = wwan_hwsim_netdev_setup,
+};
+
static int wwan_hwsim_port_start(struct wwan_port *wport)
{
struct wwan_hwsim_port *port = wwan_port_get_drvdata(wport);
@@ -254,6 +289,10 @@ static struct wwan_hwsim_dev *wwan_hwsim_dev_new(void)
INIT_WORK(&dev->del_work, wwan_hwsim_dev_del_work);
+ err = wwan_register_ops(&dev->dev, &wwan_hwsim_wwan_rtnl_ops, dev);
+ if (err)
+ goto err_unreg_dev;
+
dev->debugfs_topdir = debugfs_create_dir(dev_name(&dev->dev),
wwan_hwsim_debugfs_topdir);
debugfs_create_file("destroy", 0200, dev->debugfs_topdir, dev,
@@ -265,6 +304,12 @@ static struct wwan_hwsim_dev *wwan_hwsim_dev_new(void)
return dev;
+err_unreg_dev:
+ device_unregister(&dev->dev);
+ /* Memory will be freed in the device release callback */
+
+ return ERR_PTR(err);
+
err_free_dev:
kfree(dev);
@@ -290,6 +335,9 @@ static void wwan_hwsim_dev_del(struct wwan_hwsim_dev *dev)
debugfs_remove(dev->debugfs_topdir);
+ /* This will remove all child netdev(s) */
+ wwan_unregister_ops(&dev->dev);
+
/* Make sure that there is no pending deletion work */
if (current_work() != &dev->del_work)
cancel_work_sync(&dev->del_work);
--
2.26.3
next prev parent reply other threads:[~2021-06-15 0:30 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-15 0:30 [PATCH net-next 00/10] net: WWAN link creation improvements Sergey Ryazanov
2021-06-15 0:30 ` Sergey Ryazanov [this message]
2021-06-15 0:30 ` [PATCH net-next 02/10] wwan: core: relocate ops registering code Sergey Ryazanov
2021-06-15 0:30 ` [PATCH net-next 03/10] wwan: core: require WWAN netdev setup callback existence Sergey Ryazanov
2021-06-15 0:30 ` [PATCH net-next 04/10] wwan: core: multiple netdevs deletion support Sergey Ryazanov
2021-06-15 0:30 ` [PATCH net-next 05/10] wwan: core: remove all netdevs on ops unregistering Sergey Ryazanov
2021-06-15 0:30 ` [PATCH net-next 06/10] net: iosm: drop custom netdev(s) removing Sergey Ryazanov
2021-06-20 15:20 ` Sergey Ryazanov
2021-06-20 15:42 ` Kumar, M Chetan
2021-06-20 16:53 ` Sergey Ryazanov
2021-06-29 14:14 ` Loic Poulain
2021-06-29 14:56 ` Kumar, M Chetan
2021-06-29 15:29 ` Loic Poulain
2021-06-30 5:11 ` Kumar, M Chetan
2021-06-15 0:30 ` [PATCH net-next 07/10] wwan: core: no more hold netdev ops owning module Sergey Ryazanov
2021-06-15 0:30 ` [PATCH net-next 08/10] wwan: core: support default netdev creation Sergey Ryazanov
2021-06-15 0:30 ` [PATCH net-next 09/10] net: mhi_net: create default link via WWAN core Sergey Ryazanov
2021-06-15 7:17 ` Loic Poulain
2021-06-20 13:51 ` Sergey Ryazanov
2021-06-21 6:53 ` Loic Poulain
2021-06-21 9:54 ` Sergey Ryazanov
2021-06-15 0:30 ` [PATCH net-next 10/10] wwan: core: add WWAN common private data for netdev Sergey Ryazanov
2021-06-15 7:31 ` Johannes Berg
2021-06-20 14:49 ` Sergey Ryazanov
2021-06-15 7:33 ` Loic Poulain
2021-06-20 14:39 ` Sergey Ryazanov
2021-06-21 7:37 ` Loic Poulain
2021-06-21 17:22 ` Sergey Ryazanov
2021-06-22 7:21 ` Loic Poulain
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210615003016.477-2-ryazanov.s.a@gmail.com \
--to=ryazanov.s.a@gmail.com \
--cc=davem@davemloft.net \
--cc=johannes@sipsolutions.net \
--cc=kuba@kernel.org \
--cc=loic.poulain@linaro.org \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).