From patchwork Tue Jun 15 00:30:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Ryazanov X-Patchwork-Id: 12320271 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5814FC49EA2 for ; Tue, 15 Jun 2021 00:30:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 312C460FF1 for ; Tue, 15 Jun 2021 00:30:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230314AbhFOAcn (ORCPT ); Mon, 14 Jun 2021 20:32:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230267AbhFOAcl (ORCPT ); Mon, 14 Jun 2021 20:32:41 -0400 Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [IPv6:2a00:1450:4864:20::130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E9483C061767 for ; Mon, 14 Jun 2021 17:30:23 -0700 (PDT) Received: by mail-lf1-x130.google.com with SMTP id v22so24006581lfa.3 for ; Mon, 14 Jun 2021 17:30:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=E6Xx52ZxvktgGxM0I//ONofdK4cxEcOYfqnuaBjbxng=; b=S0B2ua0KbNw1UrCGu4uCA5H72knrFTvayz+XorMxVWipXnadvk4NsF7Z4743m0XddG GU2Rjm/CciW7vLQ8hxvAqH9N1DM0226HFclFjCILvo7U6TQescDbyTGSGyhOWWE2JVqI d7VFafzbnOWlcr8kzJr4jcx0R1b27CzPa/+v/QWF5m7CKnW08k1xrl7YqTWXhR9u6dsW l9LygU5Gd9m4hLGEfAFGfH5pPHsBoNZKJyIeQUIf/tB3EtzIPAObqbGkRSbZsGGwjhyW MRdTBzGavtjd1MBNMVE+bTCWYutHVDU+D4MYzBXDTgvp8FV99Zj9aN9Ric4porTfnrLc JCtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=E6Xx52ZxvktgGxM0I//ONofdK4cxEcOYfqnuaBjbxng=; b=fBgEDSjOR87THKgaf+8WoSdSoJpksI8v4/Oex/N6ZGoigfwcmMapG5+0ojUdFY6GXx qSXPT4gHBtpBaPWj3KgrO6IzHsQPDtNtVtFYdk6AKGsPEk9hbETpCzNxnc3HOh2XTYM3 3ZxJjkaMhpeTKabNsJDkUl+kng6S0biFCGxY5wMwpPHwSJ9nw3qxS0P1yIqXquwIVFl6 sMJKAULRrPl/sm4Vo61gFu1I+xdNOBtKaVVwrHOh0pHrDtDdhjuVRcP0nF8X+fwE9ICS /qWqiqijdufU2VgKIoh6h7IxP7m5GrznszmWXgE7AIYjtf8Ftu5cWQlEqW9wHovmrwW2 eUHQ== X-Gm-Message-State: AOAM533RTEuIc7e7efw8j46tVCbRG9UrUdf0N83WbweJ8tWg3M5BFe6X IYwVYpsPRbHDcFQs/lGo5dk= X-Google-Smtp-Source: ABdhPJwBaW2rgHT9Nnbn6co6NXKACQBw501UEMlE7WMIbpeRWGYzSXpyJKz5mZpLaXElIbLmci4dYw== X-Received: by 2002:a05:6512:1586:: with SMTP id bp6mr13424305lfb.599.1623717021042; Mon, 14 Jun 2021 17:30:21 -0700 (PDT) Received: from rsa-laptop.internal.lan ([217.25.229.52]) by smtp.gmail.com with ESMTPSA id 9sm1635522lfy.41.2021.06.14.17.30.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jun 2021 17:30:20 -0700 (PDT) From: Sergey Ryazanov To: Loic Poulain , Johannes Berg , "David S. Miller" , Jakub Kicinski 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 Message-Id: <20210615003016.477-2-ryazanov.s.a@gmail.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210615003016.477-1-ryazanov.s.a@gmail.com> References: <20210615003016.477-1-ryazanov.s.a@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org 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 --- 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 #include #include +#include #include #include #include +#include + 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); From patchwork Tue Jun 15 00:30:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Ryazanov X-Patchwork-Id: 12320263 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 168A5C2B9F4 for ; Tue, 15 Jun 2021 00:30:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E684F61378 for ; Tue, 15 Jun 2021 00:30:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230040AbhFOAc2 (ORCPT ); Mon, 14 Jun 2021 20:32:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229536AbhFOAc1 (ORCPT ); Mon, 14 Jun 2021 20:32:27 -0400 Received: from mail-lj1-x230.google.com (mail-lj1-x230.google.com [IPv6:2a00:1450:4864:20::230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BEA2FC061574 for ; Mon, 14 Jun 2021 17:30:23 -0700 (PDT) Received: by mail-lj1-x230.google.com with SMTP id l4so9988134ljg.0 for ; Mon, 14 Jun 2021 17:30:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=09saV9KmEfikWFU+B3dYBUDsghoxduQoY/JmTiKZxII=; b=i4w8mj72DESMqzXNaWdjPtsxUAeWqEIzl8bnp5q0QVoJouR7aUg2DEd2CuweXmS/i3 FVjGknvuUA6RFIQDt+DDk9op2c1lEOtdzV1ayM9oulB3xERIxDrvair3bFckZRO8XNVn xT+FwtTx3E7OVlf5Kp9YNiPEWKKTNYw1spsXKjpCP77AluLPHS9dwFsqH41w6xEB938Z b3cgN18i1klKoqlK4F/+2tplFusl7bXahgflKPVECNPeUs7KqFxyKsZ0ArrvTTo+shxd AXUQxvvnjHJM4Hj0q8Jdt+3OmnCCu0wBW80e84gIVG3WJtHdmgx+v9oN6qAr2zCLPzmc p4cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=09saV9KmEfikWFU+B3dYBUDsghoxduQoY/JmTiKZxII=; b=KCUnuUqo0VsRgwsjxXwBPdDG0nMscJYSWQx4sfaAX5kFVQUmAuVissNnJHL53xa+S1 /sQJScA3dYlNvN2UJVLPQDoqWWnHIZtmgwoMNWYVVYDgv8XlVx1znCr+BLgfPXW2GdEb 4tGGWH2hpuAzv8Zllguz3xMT/2KVReDmzC1PlySA2ua+Uu+tbG9QkcH0v3oW16/zQF9s PgTjMhNZyc0D294AGvH8w31JYTZuGTQG76UQELxpNvlV2uo3nkPy8NAmHj2cpFGEJgZ1 ufINyJzIkuLIBytNB4KMQQ8F2k+b1MmYGTrfDEC+M9hAsJS5SxJyenoqY0SfTjC7CUnG 08FA== X-Gm-Message-State: AOAM5330VDyMhRbTAty1lRqKbmB+Ozdt87LhnXWMhrkIGa5RN8pjV7Eo 2SMGA+SU5VQOwRSI9EghhFk= X-Google-Smtp-Source: ABdhPJxLK8DtO1fnEHHvLp9f1oBxz5LyOikPJmLSO+dOUo0ZmRD9oH+MuH44TgA7CYJVy60xqbnZgA== X-Received: by 2002:a2e:8845:: with SMTP id z5mr15278394ljj.405.1623717022051; Mon, 14 Jun 2021 17:30:22 -0700 (PDT) Received: from rsa-laptop.internal.lan ([217.25.229.52]) by smtp.gmail.com with ESMTPSA id 9sm1635522lfy.41.2021.06.14.17.30.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jun 2021 17:30:21 -0700 (PDT) From: Sergey Ryazanov To: Loic Poulain , Johannes Berg , "David S. Miller" , Jakub Kicinski Cc: netdev@vger.kernel.org Subject: [PATCH net-next 02/10] wwan: core: relocate ops registering code Date: Tue, 15 Jun 2021 03:30:08 +0300 Message-Id: <20210615003016.477-3-ryazanov.s.a@gmail.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210615003016.477-1-ryazanov.s.a@gmail.com> References: <20210615003016.477-1-ryazanov.s.a@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org It is unlikely that RTNL callbacks will call WWAN ops (un-)register functions, but it is highly likely that the ops (un-)register functions will use RTNL link create/destroy handlers. So move the WWAN network interface ops (un-)register functions below the RTNL callbacks to be able to call them without forward declarations. No functional changes, just code relocation. Signed-off-by: Sergey Ryazanov --- drivers/net/wwan/wwan_core.c | 142 +++++++++++++++++------------------ 1 file changed, 71 insertions(+), 71 deletions(-) diff --git a/drivers/net/wwan/wwan_core.c b/drivers/net/wwan/wwan_core.c index 7e728042fc41..00b514b01d91 100644 --- a/drivers/net/wwan/wwan_core.c +++ b/drivers/net/wwan/wwan_core.c @@ -781,77 +781,6 @@ static const struct file_operations wwan_port_fops = { .llseek = noop_llseek, }; -/** - * wwan_register_ops - register WWAN device ops - * @parent: Device to use as parent and shared by all WWAN ports and - * created netdevs - * @ops: operations to register - * @ctxt: context to pass to operations - * - * Returns: 0 on success, a negative error code on failure - */ -int wwan_register_ops(struct device *parent, const struct wwan_ops *ops, - void *ctxt) -{ - struct wwan_device *wwandev; - - if (WARN_ON(!parent || !ops)) - return -EINVAL; - - wwandev = wwan_create_dev(parent); - if (!wwandev) - return -ENOMEM; - - if (WARN_ON(wwandev->ops)) { - wwan_remove_dev(wwandev); - return -EBUSY; - } - - if (!try_module_get(ops->owner)) { - wwan_remove_dev(wwandev); - return -ENODEV; - } - - wwandev->ops = ops; - wwandev->ops_ctxt = ctxt; - - return 0; -} -EXPORT_SYMBOL_GPL(wwan_register_ops); - -/** - * wwan_unregister_ops - remove WWAN device ops - * @parent: Device to use as parent and shared by all WWAN ports and - * created netdevs - */ -void wwan_unregister_ops(struct device *parent) -{ - struct wwan_device *wwandev = wwan_dev_get_by_parent(parent); - bool has_ops; - - if (WARN_ON(IS_ERR(wwandev))) - return; - - has_ops = wwandev->ops; - - /* put the reference obtained by wwan_dev_get_by_parent(), - * we should still have one (that the owner is giving back - * now) due to the ops being assigned, check that below - * and return if not. - */ - put_device(&wwandev->dev); - - if (WARN_ON(!has_ops)) - return; - - module_put(wwandev->ops->owner); - - wwandev->ops = NULL; - wwandev->ops_ctxt = NULL; - wwan_remove_dev(wwandev); -} -EXPORT_SYMBOL_GPL(wwan_unregister_ops); - static int wwan_rtnl_validate(struct nlattr *tb[], struct nlattr *data[], struct netlink_ext_ack *extack) { @@ -966,6 +895,77 @@ static struct rtnl_link_ops wwan_rtnl_link_ops __read_mostly = { .policy = wwan_rtnl_policy, }; +/** + * wwan_register_ops - register WWAN device ops + * @parent: Device to use as parent and shared by all WWAN ports and + * created netdevs + * @ops: operations to register + * @ctxt: context to pass to operations + * + * Returns: 0 on success, a negative error code on failure + */ +int wwan_register_ops(struct device *parent, const struct wwan_ops *ops, + void *ctxt) +{ + struct wwan_device *wwandev; + + if (WARN_ON(!parent || !ops)) + return -EINVAL; + + wwandev = wwan_create_dev(parent); + if (!wwandev) + return -ENOMEM; + + if (WARN_ON(wwandev->ops)) { + wwan_remove_dev(wwandev); + return -EBUSY; + } + + if (!try_module_get(ops->owner)) { + wwan_remove_dev(wwandev); + return -ENODEV; + } + + wwandev->ops = ops; + wwandev->ops_ctxt = ctxt; + + return 0; +} +EXPORT_SYMBOL_GPL(wwan_register_ops); + +/** + * wwan_unregister_ops - remove WWAN device ops + * @parent: Device to use as parent and shared by all WWAN ports and + * created netdevs + */ +void wwan_unregister_ops(struct device *parent) +{ + struct wwan_device *wwandev = wwan_dev_get_by_parent(parent); + bool has_ops; + + if (WARN_ON(IS_ERR(wwandev))) + return; + + has_ops = wwandev->ops; + + /* put the reference obtained by wwan_dev_get_by_parent(), + * we should still have one (that the owner is giving back + * now) due to the ops being assigned, check that below + * and return if not. + */ + put_device(&wwandev->dev); + + if (WARN_ON(!has_ops)) + return; + + module_put(wwandev->ops->owner); + + wwandev->ops = NULL; + wwandev->ops_ctxt = NULL; + wwan_remove_dev(wwandev); +} +EXPORT_SYMBOL_GPL(wwan_unregister_ops); + static int __init wwan_init(void) { int err; From patchwork Tue Jun 15 00:30:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Ryazanov X-Patchwork-Id: 12320275 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 08CEAC2B9F4 for ; Tue, 15 Jun 2021 00:31:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CBBAD61166 for ; Tue, 15 Jun 2021 00:31:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230396AbhFOAcq (ORCPT ); Mon, 14 Jun 2021 20:32:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230291AbhFOAcm (ORCPT ); Mon, 14 Jun 2021 20:32:42 -0400 Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [IPv6:2a00:1450:4864:20::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D058C0617AF for ; Mon, 14 Jun 2021 17:30:25 -0700 (PDT) Received: by mail-lj1-x229.google.com with SMTP id d2so22433890ljj.11 for ; Mon, 14 Jun 2021 17:30:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=quswy1jB+1Xar493tlXRtmhFxHeNkxTYoFdb5cftjDI=; b=KL2r9pmhFOUcjuuPJcs7T41YrrFQYM6dgB4thl2x6wIsWGdR75m/cMFhJ2OnfkJdlA CGL2VvLUqfDTwND2ggzVBruutUeOXutSTShw/pyBZq8zFxowQj1hkOtRVyz54ClOtdcO LLA+Y/i+PAKC5d1UljBvYwXdJ1DNrOnFJ4bwSsQ7j5roFTsamnpTyMSDBsPoM4EoNVkY m7RWoGu9iNeUq5UisCz9QVsE9h/DnfnA9jYqS5nT/N8e2qmVaG3pYHhQNW55aY7x4n8C y74bqXFcd7tA5D9tugxyay85SFaHJGyt0sXveSwoaw3JFXgGokkhvCr8y/1QxIg3l/7H F72g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=quswy1jB+1Xar493tlXRtmhFxHeNkxTYoFdb5cftjDI=; b=eSHDXxZKNIEmhSDxWrpHhdU3UjljPDdH+Go2zw7y5Ei5hNUXQVG+09uHT+PumMbMCL QxrkGpXA3hGYzvuXSWskgO1Ki9N6v4CeJj/Ixcleq9hgfIhaZHce5bT8+s+IOr3u3hrp MDnsfAR1HLDk11ZEJf979XWm0OmqvfQ0OxglUjpzUnWprO0kwXo0MOZ1wePPuEzkt2D4 eih3OMWudSeGCACPE7wEjjQlnrIrEMI5XqPTLmAo2gE7m2Bjx22a39sIVb+EHz/sg1fV A10gfVCxoj66ptb26RsU0xGnxshUNvp3e1WE+cpfc0bfcrVUf3h8NzNtkIlEe1oKZHSs 8kiA== X-Gm-Message-State: AOAM532BYoH2o0CeyHeh+ZDAg69oIbbrXAbxa5phhtVOWVgSYGKIQ4Tb 9fCjFETPbjdaQ7CuOTPjKsE= X-Google-Smtp-Source: ABdhPJyhY547xBSuimmYzWR3HokQU6WMCpuSvl6s8RQP1UIeTnMDHeGWN2gspBRNVAjbwM9lgVP/kA== X-Received: by 2002:a2e:7a1a:: with SMTP id v26mr15785026ljc.362.1623717023055; Mon, 14 Jun 2021 17:30:23 -0700 (PDT) Received: from rsa-laptop.internal.lan ([217.25.229.52]) by smtp.gmail.com with ESMTPSA id 9sm1635522lfy.41.2021.06.14.17.30.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jun 2021 17:30:22 -0700 (PDT) From: Sergey Ryazanov To: Loic Poulain , Johannes Berg , "David S. Miller" , Jakub Kicinski Cc: netdev@vger.kernel.org Subject: [PATCH net-next 03/10] wwan: core: require WWAN netdev setup callback existence Date: Tue, 15 Jun 2021 03:30:09 +0300 Message-Id: <20210615003016.477-4-ryazanov.s.a@gmail.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210615003016.477-1-ryazanov.s.a@gmail.com> References: <20210615003016.477-1-ryazanov.s.a@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org The setup callback will be unconditionally passed to the alloc_netdev_mqs(), where the NULL pointer dereference will cause the kernel panic. So refuse to register WWAN netdev ops with warning generation if the setup callback is not provided. Signed-off-by: Sergey Ryazanov --- drivers/net/wwan/wwan_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/wwan/wwan_core.c b/drivers/net/wwan/wwan_core.c index 00b514b01d91..259d49f78998 100644 --- a/drivers/net/wwan/wwan_core.c +++ b/drivers/net/wwan/wwan_core.c @@ -909,7 +909,7 @@ int wwan_register_ops(struct device *parent, const struct wwan_ops *ops, { struct wwan_device *wwandev; - if (WARN_ON(!parent || !ops)) + if (WARN_ON(!parent || !ops || !ops->setup)) return -EINVAL; wwandev = wwan_create_dev(parent); From patchwork Tue Jun 15 00:30:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Ryazanov X-Patchwork-Id: 12320265 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3CC1AC48BE6 for ; Tue, 15 Jun 2021 00:30:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 18F5F613B1 for ; Tue, 15 Jun 2021 00:30:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230251AbhFOAck (ORCPT ); Mon, 14 Jun 2021 20:32:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229536AbhFOAcj (ORCPT ); Mon, 14 Jun 2021 20:32:39 -0400 Received: from mail-lj1-x22c.google.com (mail-lj1-x22c.google.com [IPv6:2a00:1450:4864:20::22c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF095C0613A2 for ; Mon, 14 Jun 2021 17:30:25 -0700 (PDT) Received: by mail-lj1-x22c.google.com with SMTP id d2so22433935ljj.11 for ; Mon, 14 Jun 2021 17:30:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1vr5tF9uC8zxJRF8P1lZIsvwQPoxIVBxYNMsYnxvUr8=; b=iXXMHLMK/C4kZn73PjvGLyTEW6fzshvSKprMvhSFRtKScU+yj8TIeYhcJtilMKagXh SZXz6IQvQoL0TkVrnqwD6yRp69vXB8lBdfbyxKW5bG2tyZRCQemt4SlFCsdHtR6dhYba 1a9V3l5s0SoJYP+Yp+9Bsjq3ZAYzQXNFJVb4WoMOP8CrFieirlgQBU3K9PSYrTasUXTb cwnBRA7L2FUKClijUg6JQqMTMdNBBDP94JeFkbJpWxrjJW5D4NWdFyC2Xgy7C9k8iW+k FD5dVkDKDozd91H5jU7jc7XaxU7IXWXjUCBRdi/qgQPp0VI6tr/1jts6gLJtMoF3wjH1 XmrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1vr5tF9uC8zxJRF8P1lZIsvwQPoxIVBxYNMsYnxvUr8=; b=k3T0gzqyF4EqgZ/5mbEsMVAn49Oxt6iUcwCJtkbAa07xRn1sT0UlfQ4j0zv925HhYP Yhv5UR/FydeNXuxrrVCxk1bGG2mziTERRGJIxXZe29nunCv0Ivgiw8KDYEiKlxPgSt2T vCfM8X4sMvA7R0dFmXEbfUrLa7/+TMakCNXAf0LN5OnNtUbKbLRrk5InbZMHak8qYLg2 Xtn9YUfWD37RJS/muagK80ABDbS1BdOcyvdlv4+7VZZ/zhzSormWFAdi9qXZxw9uTmyN MHwafNsr2LKQjgzXDzsd/FAQCVcJ7hmKJJo9DCAjbskyvCEjcTBpkBzXKxRNLcJ5/t1L GY3Q== X-Gm-Message-State: AOAM531P0MTtWj7kFvaSoPAq6GQAgUz6CcJJJCg6AVRD0YnN+t/EMeT1 huY1ZqQyJKwAMimPVhMdLjM= X-Google-Smtp-Source: ABdhPJwoyGWt0q7T5aHYlCKOgwRjJjgRgH4v5ZE8DwJnlsOzgYLabaHWPdJ9vWkqpCvu/QRP6gb4jQ== X-Received: by 2002:a2e:585e:: with SMTP id x30mr15086173ljd.290.1623717024234; Mon, 14 Jun 2021 17:30:24 -0700 (PDT) Received: from rsa-laptop.internal.lan ([217.25.229.52]) by smtp.gmail.com with ESMTPSA id 9sm1635522lfy.41.2021.06.14.17.30.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jun 2021 17:30:23 -0700 (PDT) From: Sergey Ryazanov To: Loic Poulain , Johannes Berg , "David S. Miller" , Jakub Kicinski Cc: netdev@vger.kernel.org Subject: [PATCH net-next 04/10] wwan: core: multiple netdevs deletion support Date: Tue, 15 Jun 2021 03:30:10 +0300 Message-Id: <20210615003016.477-5-ryazanov.s.a@gmail.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210615003016.477-1-ryazanov.s.a@gmail.com> References: <20210615003016.477-1-ryazanov.s.a@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Use unregister_netdevice_queue() instead of simple unregister_netdevice() if the WWAN netdev ops does not provide a dellink callback. This will help to accelerate deletion of multiple netdevs. Signed-off-by: Sergey Ryazanov --- drivers/net/wwan/wwan_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/wwan/wwan_core.c b/drivers/net/wwan/wwan_core.c index 259d49f78998..634f0a7a2dc6 100644 --- a/drivers/net/wwan/wwan_core.c +++ b/drivers/net/wwan/wwan_core.c @@ -874,7 +874,7 @@ static void wwan_rtnl_dellink(struct net_device *dev, struct list_head *head) if (wwandev->ops->dellink) wwandev->ops->dellink(wwandev->ops_ctxt, dev, head); else - unregister_netdevice(dev); + unregister_netdevice_queue(dev, head); out: /* release the reference */ From patchwork Tue Jun 15 00:30:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Ryazanov X-Patchwork-Id: 12320279 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 34723C49EA2 for ; Tue, 15 Jun 2021 00:31:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 030C76102A for ; Tue, 15 Jun 2021 00:31:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230493AbhFOAdq (ORCPT ); Mon, 14 Jun 2021 20:33:46 -0400 Received: from mail-lj1-f172.google.com ([209.85.208.172]:34529 "EHLO mail-lj1-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229829AbhFOAdp (ORCPT ); Mon, 14 Jun 2021 20:33:45 -0400 Received: by mail-lj1-f172.google.com with SMTP id e25so1363904ljj.1 for ; Mon, 14 Jun 2021 17:31:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8SNH56xDgFaJVGhuv5FEXCpqYqAJ/EXSXsZGOQBgUwQ=; b=Rxos9mueYH3IVB/3P3IIMTFmTCDJKJK007OBHHZaUHnxUJBjuOaLzVY4w2qjT8Ua3g 5yKmimGv3DSam8JMYxoueikEbmX3l477uX8FbFXmoo4rDpuZVLENpCKC/Yd/H7Q1sQP5 zUlxwKA0qX3HyX8Gm3vlALYAZzY7ATx5vrdrA8/2yu+z0H6quLdRCEaPNTZXD9ugF9/c v1VS3N5hVkPJY2YudaBicBDWQyNqkJPcFt5JqyuRTuf2GSFisCPSR+hMaGR6kIZyox5V R+QHlbrkedrk8K8AYmVIrQsypD2AnM3KRC8vabHPk10wUlg7IZEK37oG1C4fkBb3c9PC f99A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8SNH56xDgFaJVGhuv5FEXCpqYqAJ/EXSXsZGOQBgUwQ=; b=HCbkQL8Z9TumKmlGMy63BoWy5spwG+VR8f3dOfqBWHE9sIM4AedufDWBR912zXiHgB txN7F5GJTVyQs8v9OOmCfLpHPt16flvUT5io5airlapxWK9O50i8BQ6of5zuo6/wD5BU BvmhRLlykJCjYtg9oDKPPY2PR1UHhS/uRfOnj3iAPiaDvu7wsjKDpYVdYD6VDsRSNbKd i+320yLOQ6yP656TM8N5ainVL4XE/+MVXdKN6Jljih2d2XEqcXdgrp9LLzvf8Z7X0ya8 v6/rV0AZl7AA4J/D4E+QFNwTgRapVkXMgSlMcIQSMb+pymG4T6GSop3dvkb+eDsQx9rn PFlQ== X-Gm-Message-State: AOAM532EFGFLOtJQLQearHd3C1MyN48CmLS2ClJoW1duaXVpKUHcJfLq IxLKPaf2S0lWTCsnir2MqCk= X-Google-Smtp-Source: ABdhPJxIjMHxZqXhpBIEQJVMxDibQLRYHDPkvrKi1PVira2bLjjgGe9YGxl9nar0P7eEGy0Lyj2fzg== X-Received: by 2002:a05:651c:50c:: with SMTP id o12mr15947895ljp.364.1623717025109; Mon, 14 Jun 2021 17:30:25 -0700 (PDT) Received: from rsa-laptop.internal.lan ([217.25.229.52]) by smtp.gmail.com with ESMTPSA id 9sm1635522lfy.41.2021.06.14.17.30.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jun 2021 17:30:24 -0700 (PDT) From: Sergey Ryazanov To: Loic Poulain , Johannes Berg , "David S. Miller" , Jakub Kicinski Cc: netdev@vger.kernel.org Subject: [PATCH net-next 05/10] wwan: core: remove all netdevs on ops unregistering Date: Tue, 15 Jun 2021 03:30:11 +0300 Message-Id: <20210615003016.477-6-ryazanov.s.a@gmail.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210615003016.477-1-ryazanov.s.a@gmail.com> References: <20210615003016.477-1-ryazanov.s.a@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org We use the ops owner module hold to protect against ops memory disappearing. But this approach does not protect us from a driver that unregisters ops but forgets to remove netdev(s) that were created using this ops. In such case, we are left with netdev(s), which can not be removed since ops is gone. Moreover, batch netdevs removing on deinitialization is a desireable option for WWAN drivers as it is a quite common task. Implement deletion of all created links on WWAN netdev ops unregistering in the same way that RTNL removes all links on RTNL ops unregistering. Simply remove all child netdevs of a device whose WWAN netdev ops is unregistering. This way we protecting the kernel from buggy drivers and make it easier to write a driver deinitialization code. Signed-off-by: Sergey Ryazanov --- drivers/net/wwan/wwan_core.c | 40 ++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/drivers/net/wwan/wwan_core.c b/drivers/net/wwan/wwan_core.c index 634f0a7a2dc6..3f04e674cdaa 100644 --- a/drivers/net/wwan/wwan_core.c +++ b/drivers/net/wwan/wwan_core.c @@ -933,6 +933,17 @@ int wwan_register_ops(struct device *parent, const struct wwan_ops *ops, } EXPORT_SYMBOL_GPL(wwan_register_ops); +/* Enqueue child netdev deletion */ +static int wwan_child_dellink(struct device *dev, void *data) +{ + struct list_head *kill_list = data; + + if (dev->type == &wwan_type) + wwan_rtnl_dellink(to_net_dev(dev), kill_list); + + return 0; +} + /** * wwan_unregister_ops - remove WWAN device ops * @parent: Device to use as parent and shared by all WWAN ports and @@ -941,26 +952,37 @@ EXPORT_SYMBOL_GPL(wwan_register_ops); void wwan_unregister_ops(struct device *parent) { struct wwan_device *wwandev = wwan_dev_get_by_parent(parent); - bool has_ops; + struct module *owner; + LIST_HEAD(kill_list); if (WARN_ON(IS_ERR(wwandev))) return; - - has_ops = wwandev->ops; + if (WARN_ON(!wwandev->ops)) { + put_device(&wwandev->dev); + return; + } /* put the reference obtained by wwan_dev_get_by_parent(), * we should still have one (that the owner is giving back - * now) due to the ops being assigned, check that below - * and return if not. + * now) due to the ops being assigned. */ put_device(&wwandev->dev); - if (WARN_ON(!has_ops)) - return; + owner = wwandev->ops->owner; /* Preserve ops owner */ + + rtnl_lock(); /* Prevent concurent netdev(s) creation/destroying */ + + /* Remove all child netdev(s), using batch removing */ + device_for_each_child(&wwandev->dev, &kill_list, + wwan_child_dellink); + unregister_netdevice_many(&kill_list); + + wwandev->ops = NULL; /* Finally remove ops */ + + rtnl_unlock(); - module_put(wwandev->ops->owner); + module_put(owner); - wwandev->ops = NULL; wwandev->ops_ctxt = NULL; wwan_remove_dev(wwandev); } From patchwork Tue Jun 15 00:30:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Ryazanov X-Patchwork-Id: 12320273 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 09100C48BE6 for ; Tue, 15 Jun 2021 00:31:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D85BD61378 for ; Tue, 15 Jun 2021 00:31:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230411AbhFOAcr (ORCPT ); Mon, 14 Jun 2021 20:32:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230410AbhFOAcq (ORCPT ); Mon, 14 Jun 2021 20:32:46 -0400 Received: from mail-lj1-x22d.google.com (mail-lj1-x22d.google.com [IPv6:2a00:1450:4864:20::22d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2897C0613A3 for ; Mon, 14 Jun 2021 17:30:27 -0700 (PDT) Received: by mail-lj1-x22d.google.com with SMTP id k8so5601916lja.4 for ; Mon, 14 Jun 2021 17:30:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=f7fi9P/9fTNbfzW7zyKkEkMsJd4lNuWm+zuR4Wt1cIw=; b=qP1ZE2B7D2eyVqQEo4K8sNI6KO1VnUPtUG7m1zhWxF4wXn2jDUcmAjHWKJOfmS1u/g 8gX511kCYUpRCbcGdqI+lsfvsEB8p15ZUKW9G8qXL+HbMMj86Py6VbpXYJJjRQ49qgup H8oUjuDBCoEUho67l2y8hclK+cWKP4USMVWw4LePnIiasV8+DoFVRyMTW0baHTfmmlMK PlkAtYjK9E/Ris1vUFGQ0BunuH88gu09T7S+/bNmOLBZR8Wb2cvD2e6Ugvkirzqu1Z6R GT3yLK77Yuo1+4Qy/XLsqr4G1Ji3BhFDbFBsngDUPVaBhgpx+irYBMbmzV5x0dJ777G9 d8ZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=f7fi9P/9fTNbfzW7zyKkEkMsJd4lNuWm+zuR4Wt1cIw=; b=iCbGLXI16Snv6B7+CcEeYtaPDFh42DLFdzyf/smgFUlm06U8/iFapb5ppH30KatGql VKJ+vfoOSm7Q3Z4EweoH74sUZnNBsxtawoJvAwcV8c/1WNaNEsWGnZF1fCWtUbL+0xYm s+inIK4SId2/K3aCbKn1fZya97IywRoOOO8AU4uOrnvYK0749Q9j1xrVwQKD2ysCkJU9 9GZ4kFpF5FMiBELMOJUYsScX2fu0JfBhd5lFnsvHZrC8/Lie1XOiqnX5DUoGAP+WJGUO dYgNw9GYjaYVw/DJ8qOhHjGKtWxS01Xh1i0Uiz9zV30iHsDHntJVP4b6t2XdghZFf5+B 7IKw== X-Gm-Message-State: AOAM530s/1q3b3kbq2p7ZqhwEoPYn3loBdJ646OJc+Uc47FsiB2c1c0I +FaLfJTbuX89++dYGXDSyx0= X-Google-Smtp-Source: ABdhPJxYq1Lf+f0J5vH4im6Sl/nar4NdfubN6av5FanTG9iWfY2vm0WRWEyuMJ6iGt11Sv3BHhlveA== X-Received: by 2002:a2e:a230:: with SMTP id i16mr15828109ljm.169.1623717026286; Mon, 14 Jun 2021 17:30:26 -0700 (PDT) Received: from rsa-laptop.internal.lan ([217.25.229.52]) by smtp.gmail.com with ESMTPSA id 9sm1635522lfy.41.2021.06.14.17.30.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jun 2021 17:30:25 -0700 (PDT) From: Sergey Ryazanov To: Loic Poulain , Johannes Berg , "David S. Miller" , Jakub Kicinski Cc: netdev@vger.kernel.org, M Chetan Kumar , Intel Corporation Subject: [PATCH net-next 06/10] net: iosm: drop custom netdev(s) removing Date: Tue, 15 Jun 2021 03:30:12 +0300 Message-Id: <20210615003016.477-7-ryazanov.s.a@gmail.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210615003016.477-1-ryazanov.s.a@gmail.com> References: <20210615003016.477-1-ryazanov.s.a@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Since the last commit, the WWAN core will remove all our network interfaces for us at the time of the WWAN netdev ops unregistering. Therefore, we can safely drop the custom code that cleaning the list of created netdevs. Anyway it no longer removes any netdev, since all netdevs were removed earlier in the wwan_unregister_ops() call. Signed-off-by: Sergey Ryazanov CC: M Chetan Kumar CC: Intel Corporation Reviewed-by: M Chetan Kumar --- drivers/net/wwan/iosm/iosm_ipc_wwan.c | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/drivers/net/wwan/iosm/iosm_ipc_wwan.c b/drivers/net/wwan/iosm/iosm_ipc_wwan.c index 1711b79fc616..bee9b278223d 100644 --- a/drivers/net/wwan/iosm/iosm_ipc_wwan.c +++ b/drivers/net/wwan/iosm/iosm_ipc_wwan.c @@ -329,22 +329,9 @@ struct iosm_wwan *ipc_wwan_init(struct iosm_imem *ipc_imem, struct device *dev) void ipc_wwan_deinit(struct iosm_wwan *ipc_wwan) { - int if_id; - + /* This call will remove all child netdev(s) */ wwan_unregister_ops(ipc_wwan->dev); - for (if_id = 0; if_id < ARRAY_SIZE(ipc_wwan->sub_netlist); if_id++) { - struct iosm_netdev_priv *priv; - - priv = rcu_access_pointer(ipc_wwan->sub_netlist[if_id]); - if (!priv) - continue; - - rtnl_lock(); - ipc_wwan_dellink(ipc_wwan, priv->netdev, NULL); - rtnl_unlock(); - } - mutex_destroy(&ipc_wwan->if_mutex); kfree(ipc_wwan); From patchwork Tue Jun 15 00:30:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Ryazanov X-Patchwork-Id: 12320267 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2BF36C2B9F4 for ; Tue, 15 Jun 2021 00:30:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 000B360FF1 for ; Tue, 15 Jun 2021 00:30:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230229AbhFOAcd (ORCPT ); Mon, 14 Jun 2021 20:32:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230211AbhFOAcc (ORCPT ); Mon, 14 Jun 2021 20:32:32 -0400 Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2D32C061280 for ; Mon, 14 Jun 2021 17:30:28 -0700 (PDT) Received: by mail-lf1-x12b.google.com with SMTP id f30so24011696lfj.1 for ; Mon, 14 Jun 2021 17:30:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cdp9YxzUFC9kGIUU/5fRFVyTA0S6VIcnorPRw1B//34=; b=qGHoBAdd5afRP+ysBAcia5MeML2sTR9FjF1VBYx9rGSnqqeBFDbgHugCZ3r+AyYNCY gGHs7K+n6MHIbLoh8W1PDEGFz4boCMdBn6AXAhIqryksQJsE4JCPrFh0V77CuMl1spnu zzPzVkOtFTKgnqqti7i7HWRmVFbg3HjDJ/S2ObBOwOSlKx5xH2EMg2UfQo3lwZ0etPtI EZD0tDnW+09aXv4knMm7XCU3dRkWI0YlDs72F8iVore+6pO4468PMoC9N1nGKv6B40Dq 2UFw2mzxMX2n02fB/outCqBM4vrHwyBYmGs7ncUbmFffTNCWvjJGqh18SdnwWK2oWw7i qulA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cdp9YxzUFC9kGIUU/5fRFVyTA0S6VIcnorPRw1B//34=; b=ewxO3Gs4rllnq7IhL3TZSYyMXExdIJ6POIU5/OR15MRUj7nA+hsNwuy4lgUjO2/xKn 2Skif6n6z6Qaxzxm/gaHoVUkI1rTqOmXlw6dBq01NmL3MlrgaaWapk6ErpjytuDMqWVX jejkcKPZN9aPf1f67P1bCY2b14R9xepLC9DoL9iHE90EjKJGetn47kR45ahMffNUDKdc xUdEewgmdDtg3nnNGCIpSOD6D+dv15+c88bFfLosBM6Tx4vxFOaxl2NZrPoxwymFWw7t rPdL6rWJQVmrTIg4q5j+IoSkfw+XNG76YkRsWo0ThAAe4pUjzvycBx24djkzMp/jeU+B Gh2w== X-Gm-Message-State: AOAM53385Muv4ULQLjdfUA0AJc0PQ5bUMfOBJgI8XFkW56gzXTvv42oZ HO5sh+0vued5JSyIdTqQ6gg= X-Google-Smtp-Source: ABdhPJy4GzfjWbsXKuniuP01DeLz0Pk9huyLF7+ziiDOg4a7q3Kp7FtWFlS6QwXK45U7fdLIZhN1tA== X-Received: by 2002:a19:e008:: with SMTP id x8mr14115788lfg.439.1623717027286; Mon, 14 Jun 2021 17:30:27 -0700 (PDT) Received: from rsa-laptop.internal.lan ([217.25.229.52]) by smtp.gmail.com with ESMTPSA id 9sm1635522lfy.41.2021.06.14.17.30.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jun 2021 17:30:26 -0700 (PDT) From: Sergey Ryazanov To: Loic Poulain , Johannes Berg , "David S. Miller" , Jakub Kicinski Cc: netdev@vger.kernel.org Subject: [PATCH net-next 07/10] wwan: core: no more hold netdev ops owning module Date: Tue, 15 Jun 2021 03:30:13 +0300 Message-Id: <20210615003016.477-8-ryazanov.s.a@gmail.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210615003016.477-1-ryazanov.s.a@gmail.com> References: <20210615003016.477-1-ryazanov.s.a@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org The WWAN netdev ops owner holding was used to protect from the unexpected memory disappear. This approach causes a dependency cycle (driver -> core -> driver) and effectively prevents a WWAN driver unloading. E.g. WWAN hwsim could not be unloaded until all simulated devices are removed: ~# modprobe wwan_hwsim devices=2 ~# lsmod | grep wwan wwan_hwsim 16384 2 wwan 20480 1 wwan_hwsim ~# rmmod wwan_hwsim rmmod: ERROR: Module wwan_hwsim is in use ~# echo > /sys/kernel/debug/wwan_hwsim/hwsim0/destroy ~# echo > /sys/kernel/debug/wwan_hwsim/hwsim1/destroy ~# lsmod | grep wwan wwan_hwsim 16384 0 wwan 20480 1 wwan_hwsim ~# rmmod wwan_hwsim For a real device driver this will cause an inability to unload module until a served device is physically detached. Since the last commit we are removing all child netdev(s) when a driver unregister the netdev ops. This allows us to permit the driver unloading, since any sane driver will call ops unregistering on a device deinitialization. So, remove the holding of an ops owner to make it easier to unload a driver module. The owner field has also beed removed from the ops structure as there are no more users of this field. Signed-off-by: Sergey Ryazanov --- drivers/net/mhi/net.c | 1 - drivers/net/wwan/wwan_core.c | 10 ---------- drivers/net/wwan/wwan_hwsim.c | 1 - include/linux/wwan.h | 2 -- 4 files changed, 14 deletions(-) diff --git a/drivers/net/mhi/net.c b/drivers/net/mhi/net.c index 64af1e518484..ebd1dbf0a536 100644 --- a/drivers/net/mhi/net.c +++ b/drivers/net/mhi/net.c @@ -383,7 +383,6 @@ static void mhi_net_dellink(void *ctxt, struct net_device *ndev, } const struct wwan_ops mhi_wwan_ops = { - .owner = THIS_MODULE, .priv_size = sizeof(struct mhi_net_dev), .setup = mhi_net_setup, .newlink = mhi_net_newlink, diff --git a/drivers/net/wwan/wwan_core.c b/drivers/net/wwan/wwan_core.c index 3f04e674cdaa..28590405172c 100644 --- a/drivers/net/wwan/wwan_core.c +++ b/drivers/net/wwan/wwan_core.c @@ -921,11 +921,6 @@ int wwan_register_ops(struct device *parent, const struct wwan_ops *ops, return -EBUSY; } - if (!try_module_get(ops->owner)) { - wwan_remove_dev(wwandev); - return -ENODEV; - } - wwandev->ops = ops; wwandev->ops_ctxt = ctxt; @@ -952,7 +947,6 @@ static int wwan_child_dellink(struct device *dev, void *data) void wwan_unregister_ops(struct device *parent) { struct wwan_device *wwandev = wwan_dev_get_by_parent(parent); - struct module *owner; LIST_HEAD(kill_list); if (WARN_ON(IS_ERR(wwandev))) @@ -968,8 +962,6 @@ void wwan_unregister_ops(struct device *parent) */ put_device(&wwandev->dev); - owner = wwandev->ops->owner; /* Preserve ops owner */ - rtnl_lock(); /* Prevent concurent netdev(s) creation/destroying */ /* Remove all child netdev(s), using batch removing */ @@ -981,8 +973,6 @@ void wwan_unregister_ops(struct device *parent) rtnl_unlock(); - module_put(owner); - wwandev->ops_ctxt = NULL; wwan_remove_dev(wwandev); } diff --git a/drivers/net/wwan/wwan_hwsim.c b/drivers/net/wwan/wwan_hwsim.c index c1e850b9c087..a8582a58a385 100644 --- a/drivers/net/wwan/wwan_hwsim.c +++ b/drivers/net/wwan/wwan_hwsim.c @@ -94,7 +94,6 @@ static void wwan_hwsim_netdev_setup(struct net_device *ndev) } static const struct wwan_ops wwan_hwsim_wwan_rtnl_ops = { - .owner = THIS_MODULE, .priv_size = 0, /* No private data */ .setup = wwan_hwsim_netdev_setup, }; diff --git a/include/linux/wwan.h b/include/linux/wwan.h index 430a3a0817de..656a571b52ed 100644 --- a/include/linux/wwan.h +++ b/include/linux/wwan.h @@ -119,14 +119,12 @@ void *wwan_port_get_drvdata(struct wwan_port *port); /** * struct wwan_ops - WWAN device ops - * @owner: module owner of the WWAN ops * @priv_size: size of private netdev data area * @setup: set up a new netdev * @newlink: register the new netdev * @dellink: remove the given netdev */ struct wwan_ops { - struct module *owner; unsigned int priv_size; void (*setup)(struct net_device *dev); int (*newlink)(void *ctxt, struct net_device *dev, From patchwork Tue Jun 15 00:30:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Ryazanov X-Patchwork-Id: 12320283 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 00306C48BE6 for ; Tue, 15 Jun 2021 00:31:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DE54E61166 for ; Tue, 15 Jun 2021 00:31:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231209AbhFOAdw (ORCPT ); Mon, 14 Jun 2021 20:33:52 -0400 Received: from mail-lj1-f179.google.com ([209.85.208.179]:43526 "EHLO mail-lj1-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231132AbhFOAdt (ORCPT ); Mon, 14 Jun 2021 20:33:49 -0400 Received: by mail-lj1-f179.google.com with SMTP id r14so22394084ljd.10 for ; Mon, 14 Jun 2021 17:31:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=d406S9SJR+a3n/bYdjqMIuYNHZVACu/es/4172VcJjo=; b=p69J0isJaIixZgJnz7DZZNF+FmHvFeTalq6x7D6s82WEolOnqp9XcQj6WWc4viVfKT ItB+CAZ50JVkA7hlWeC7EtTbpOU4lqFEru9uRVP/qG1iYUOTGPSIxmY/aFsFvq4akyWm 8QIBU+UlgVh0AceZku7TjNQ/gW/zQKdmeUjkH7VidbciLgTWLcpXxGYqWEx6PBAL8yo+ Fk6WsEME8MpW8uXBQBH4tQg+l39Ry9AsLii3/3PunYbMX40AH24CpwCBL4yKpnzukhkn wWbwumIDin15mTZPdofmw7n+nywI48/CtPtHM76mEr3RsRucgZvjBnKLscSpQvD+N7dB 7gSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=d406S9SJR+a3n/bYdjqMIuYNHZVACu/es/4172VcJjo=; b=aIjq7TaeN6hZQUBOGvLRUtrMqA+JMBg6MlXwO5Dn+juQoF08TdQC4R5wIqJhZwoJKa C1tyulYqw9ZsyRP4A4+0Hcxw+579ADNB/M3U1cmyxpgNpixsXYH4Ve5ODNfXpbMUN/2/ yGPC0+01O0slItMZ/YcQnHFj7MdL1yPmIaiOsLFZwpX+S+LTlT1qp8eS+k5ggyMdGWEI 5W+kY8jmI0ZSb4PNzU7q/9RHs7f3Qajg/pxay8IGVl0bRsV8/p+hzBIFQTiY0Tvu7/b1 gRi3DtTrBYDvYa08QS6TXW7qiggXZkzpJUKuoGMbR/GCcL5YzwRBhtBbffxaXzrdvQ8m YxDg== X-Gm-Message-State: AOAM533m9IhidHRh/fMIc4oNNT5GG35kELpBzkLkcCZ+3vx+vq/onniz IjSIV4siitcflhJV13uJY5Q= X-Google-Smtp-Source: ABdhPJwsNJ6A7iNpAWLsZkLLCYZCHBA6eMQJd8+TBq5TOzLBpCqHrIOv4+E8a3oEGlh/+xYRTbj3bQ== X-Received: by 2002:a2e:9544:: with SMTP id t4mr15820965ljh.474.1623717028314; Mon, 14 Jun 2021 17:30:28 -0700 (PDT) Received: from rsa-laptop.internal.lan ([217.25.229.52]) by smtp.gmail.com with ESMTPSA id 9sm1635522lfy.41.2021.06.14.17.30.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jun 2021 17:30:27 -0700 (PDT) From: Sergey Ryazanov To: Loic Poulain , Johannes Berg , "David S. Miller" , Jakub Kicinski Cc: netdev@vger.kernel.org, M Chetan Kumar , Intel Corporation Subject: [PATCH net-next 08/10] wwan: core: support default netdev creation Date: Tue, 15 Jun 2021 03:30:14 +0300 Message-Id: <20210615003016.477-9-ryazanov.s.a@gmail.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210615003016.477-1-ryazanov.s.a@gmail.com> References: <20210615003016.477-1-ryazanov.s.a@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Most, if not each WWAN device driver will create a netdev for the default data channel. Therefore, add an option for the WWAN netdev ops registration function to create a default netdev for the WWAN device. A WWAN device driver should pass a default data channel link id to the ops registering function to request the creation of a default netdev, or a special value WWAN_NO_DEFAULT_LINK to inform the WWAN core that the default netdev should not be created. For now, only wwan_hwsim utilize the default link creation option. Other drivers will be reworked next. Signed-off-by: Sergey Ryazanov CC: M Chetan Kumar CC: Intel Corporation --- drivers/net/mhi/net.c | 3 +- drivers/net/wwan/iosm/iosm_ipc_wwan.c | 3 +- drivers/net/wwan/wwan_core.c | 75 ++++++++++++++++++++++++++- drivers/net/wwan/wwan_hwsim.c | 2 +- include/linux/wwan.h | 8 ++- 5 files changed, 86 insertions(+), 5 deletions(-) diff --git a/drivers/net/mhi/net.c b/drivers/net/mhi/net.c index ebd1dbf0a536..b003003cbd42 100644 --- a/drivers/net/mhi/net.c +++ b/drivers/net/mhi/net.c @@ -397,7 +397,8 @@ static int mhi_net_probe(struct mhi_device *mhi_dev, struct net_device *ndev; int err; - err = wwan_register_ops(&cntrl->mhi_dev->dev, &mhi_wwan_ops, mhi_dev); + err = wwan_register_ops(&cntrl->mhi_dev->dev, &mhi_wwan_ops, mhi_dev, + WWAN_NO_DEFAULT_LINK); if (err) return err; diff --git a/drivers/net/wwan/iosm/iosm_ipc_wwan.c b/drivers/net/wwan/iosm/iosm_ipc_wwan.c index bee9b278223d..adb2bd40a404 100644 --- a/drivers/net/wwan/iosm/iosm_ipc_wwan.c +++ b/drivers/net/wwan/iosm/iosm_ipc_wwan.c @@ -317,7 +317,8 @@ struct iosm_wwan *ipc_wwan_init(struct iosm_imem *ipc_imem, struct device *dev) ipc_wwan->dev = dev; ipc_wwan->ipc_imem = ipc_imem; - if (wwan_register_ops(ipc_wwan->dev, &iosm_wwan_ops, ipc_wwan)) { + if (wwan_register_ops(ipc_wwan->dev, &iosm_wwan_ops, ipc_wwan, + WWAN_NO_DEFAULT_LINK)) { kfree(ipc_wwan); return NULL; } diff --git a/drivers/net/wwan/wwan_core.c b/drivers/net/wwan/wwan_core.c index 28590405172c..b99a737a7d77 100644 --- a/drivers/net/wwan/wwan_core.c +++ b/drivers/net/wwan/wwan_core.c @@ -895,17 +895,81 @@ static struct rtnl_link_ops wwan_rtnl_link_ops __read_mostly = { .policy = wwan_rtnl_policy, }; +static void wwan_create_default_link(struct wwan_device *wwandev, + u32 def_link_id) +{ + struct nlattr *tb[IFLA_MAX + 1], *linkinfo[IFLA_INFO_MAX + 1]; + struct nlattr *data[IFLA_WWAN_MAX + 1]; + struct net_device *dev; + struct nlmsghdr *nlh; + struct sk_buff *msg; + + /* Forge attributes required to create a WWAN netdev. We first + * build a netlink message and then parse it. This looks + * odd, but such approach is less error prone. + */ + msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); + if (WARN_ON(!msg)) + return; + nlh = nlmsg_put(msg, 0, 0, RTM_NEWLINK, 0, 0); + if (WARN_ON(!nlh)) + goto free_attrs; + + if (nla_put_string(msg, IFLA_PARENT_DEV_NAME, dev_name(&wwandev->dev))) + goto free_attrs; + tb[IFLA_LINKINFO] = nla_nest_start(msg, IFLA_LINKINFO); + if (!tb[IFLA_LINKINFO]) + goto free_attrs; + linkinfo[IFLA_INFO_DATA] = nla_nest_start(msg, IFLA_INFO_DATA); + if (!linkinfo[IFLA_INFO_DATA]) + goto free_attrs; + if (nla_put_u32(msg, IFLA_WWAN_LINK_ID, def_link_id)) + goto free_attrs; + nla_nest_end(msg, linkinfo[IFLA_INFO_DATA]); + nla_nest_end(msg, tb[IFLA_LINKINFO]); + + nlmsg_end(msg, nlh); + + /* The next three parsing calls can not fail */ + nlmsg_parse_deprecated(nlh, 0, tb, IFLA_MAX, NULL, NULL); + nla_parse_nested_deprecated(linkinfo, IFLA_INFO_MAX, tb[IFLA_LINKINFO], + NULL, NULL); + nla_parse_nested_deprecated(data, IFLA_WWAN_MAX, + linkinfo[IFLA_INFO_DATA], NULL, NULL); + + rtnl_lock(); + + dev = rtnl_create_link(&init_net, "wwan%d", NET_NAME_ENUM, + &wwan_rtnl_link_ops, tb, NULL); + if (WARN_ON(IS_ERR(dev))) + goto unlock; + + if (WARN_ON(wwan_rtnl_newlink(&init_net, dev, tb, data, NULL))) { + free_netdev(dev); + goto unlock; + } + +unlock: + rtnl_unlock(); + +free_attrs: + nlmsg_free(msg); +} + /** * wwan_register_ops - register WWAN device ops * @parent: Device to use as parent and shared by all WWAN ports and * created netdevs * @ops: operations to register * @ctxt: context to pass to operations + * @def_link_id: id of the default link that will be automatically created by + * the WWAN core for the WWAN device. The default link will not be created + * if the passed value is WWAN_NO_DEFAULT_LINK. * * Returns: 0 on success, a negative error code on failure */ int wwan_register_ops(struct device *parent, const struct wwan_ops *ops, - void *ctxt) + void *ctxt, u32 def_link_id) { struct wwan_device *wwandev; @@ -924,6 +988,15 @@ int wwan_register_ops(struct device *parent, const struct wwan_ops *ops, wwandev->ops = ops; wwandev->ops_ctxt = ctxt; + /* NB: we do not abort ops registration in case of default link + * creation failure. Link ops is the management interface, while the + * default link creation is a service option. And we should not prevent + * a user from manually creating a link latter if service option failed + * now. + */ + if (def_link_id != WWAN_NO_DEFAULT_LINK) + wwan_create_default_link(wwandev, def_link_id); + return 0; } EXPORT_SYMBOL_GPL(wwan_register_ops); diff --git a/drivers/net/wwan/wwan_hwsim.c b/drivers/net/wwan/wwan_hwsim.c index a8582a58a385..5b62cf3b3c42 100644 --- a/drivers/net/wwan/wwan_hwsim.c +++ b/drivers/net/wwan/wwan_hwsim.c @@ -288,7 +288,7 @@ 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); + err = wwan_register_ops(&dev->dev, &wwan_hwsim_wwan_rtnl_ops, dev, 1); if (err) goto err_unreg_dev; diff --git a/include/linux/wwan.h b/include/linux/wwan.h index 656a571b52ed..14c9a19f3bf0 100644 --- a/include/linux/wwan.h +++ b/include/linux/wwan.h @@ -117,6 +117,12 @@ void wwan_port_txon(struct wwan_port *port); */ void *wwan_port_get_drvdata(struct wwan_port *port); +/** + * Used to indicate that the WWAN core should not create a default network + * link. + */ +#define WWAN_NO_DEFAULT_LINK U32_MAX + /** * struct wwan_ops - WWAN device ops * @priv_size: size of private netdev data area @@ -134,7 +140,7 @@ struct wwan_ops { }; int wwan_register_ops(struct device *parent, const struct wwan_ops *ops, - void *ctxt); + void *ctxt, u32 def_link_id); void wwan_unregister_ops(struct device *parent); From patchwork Tue Jun 15 00:30:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Ryazanov X-Patchwork-Id: 12320277 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 141A5C49361 for ; Tue, 15 Jun 2021 00:31:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ECCC9613B9 for ; Tue, 15 Jun 2021 00:31:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230458AbhFOAcu (ORCPT ); Mon, 14 Jun 2021 20:32:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230414AbhFOAcs (ORCPT ); Mon, 14 Jun 2021 20:32:48 -0400 Received: from mail-lf1-x12c.google.com (mail-lf1-x12c.google.com [IPv6:2a00:1450:4864:20::12c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF28BC0613A4 for ; Mon, 14 Jun 2021 17:30:30 -0700 (PDT) Received: by mail-lf1-x12c.google.com with SMTP id p17so23930319lfc.6 for ; Mon, 14 Jun 2021 17:30:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XmeWAbPsSaBx+nU+8yJYFKGc/MDEqnOyHS9fhBTh5DI=; b=pCDKEo6hVU/EbsWnloeduAMgDTgpkbEU9IgTzxZXP+gzZNuJW/y0sUggNlIia30VLL aZZVUz24p4mHfhyUTsszpf8X5fSvVdCFBx0FS9YnuDY6Dlfbjo0enkxsj7fhjbhdj5zc WrF3ydnMv/WhRxlSDZsIS50AgrwwoXxPA5RCLEzmC4bBeb62p46jtNVjut2WBEzUcFXY HaPM6uRAtwH47836MYhX0aRNM/3zU8YIsMkuUw9bYb/RDWGZvfZ3XEFltGWD5YXfTrSv QAXF53Rqugt1i24z46iBgPKqAcBXE5pLjt+Q1SkVZPYM32R6pmina+QA1H9th0aOTy9k YEsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XmeWAbPsSaBx+nU+8yJYFKGc/MDEqnOyHS9fhBTh5DI=; b=rJmTU2YNseKYqCtfkqDybUh4gWSDkrD0S7IbtpE2ndazhjQHR5SNraE6lftv3DN7Wx hwFQpiDspbM8yEmcPwAbwGxZcd9meCAv9/P7YPZImN8T2fOYOanHByzYaQM2RurULuyn vEMWwd/FOXr9TJmS3RdhWAXSBiBu2/UTvLZivRzfdWVLAYDBnZhIzj1FxqMAhRxz6CU1 DP4004Pk4AM0B+nQeMsFwpHl5Y0IE66uzbAMbxg9qO0M+8NaKelnepjrs8wWh05q/P7T YAurgt0lQAV+LA2Kd0cVn70cak3ulpdXQFjDnEeMpWjdNMOobNlGVQ4Ry4dboDLpylgk Tluw== X-Gm-Message-State: AOAM532eV9wRkPACKyy2qhiHjPwCox/a4xh37npiVleAl6qSo6uRhFgS w4FjJQmqKOE93ti348x8EwY= X-Google-Smtp-Source: ABdhPJxKzGKsQQHJRq6T+y7qW+i/Fbh7cDdDgQL1g756thAxl7m1j007UyowwSo/PHLxh2WWDCH6wA== X-Received: by 2002:ac2:4888:: with SMTP id x8mr13738167lfc.489.1623717029392; Mon, 14 Jun 2021 17:30:29 -0700 (PDT) Received: from rsa-laptop.internal.lan ([217.25.229.52]) by smtp.gmail.com with ESMTPSA id 9sm1635522lfy.41.2021.06.14.17.30.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jun 2021 17:30:28 -0700 (PDT) From: Sergey Ryazanov To: Loic Poulain , Johannes Berg , "David S. Miller" , Jakub Kicinski Cc: netdev@vger.kernel.org Subject: [PATCH net-next 09/10] net: mhi_net: create default link via WWAN core Date: Tue, 15 Jun 2021 03:30:15 +0300 Message-Id: <20210615003016.477-10-ryazanov.s.a@gmail.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210615003016.477-1-ryazanov.s.a@gmail.com> References: <20210615003016.477-1-ryazanov.s.a@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Utilize the just introduced WWAN core feature to create a default netdev for the default data channel. Since the netdev is now created via the WWAN core, rely on it ability to destroy all child netdevs on ops unregistering. While at it, remove the RTNL lock acquiring hacks that were earlier used to call addlink/dellink without holding the RTNL lock. Also make the WWAN netdev ops structure static to make sparse happy. Signed-off-by: Sergey Ryazanov --- drivers/net/mhi/net.c | 54 +++++-------------------------------------- 1 file changed, 6 insertions(+), 48 deletions(-) diff --git a/drivers/net/mhi/net.c b/drivers/net/mhi/net.c index b003003cbd42..06253acecaa2 100644 --- a/drivers/net/mhi/net.c +++ b/drivers/net/mhi/net.c @@ -342,10 +342,7 @@ static int mhi_net_newlink(void *ctxt, struct net_device *ndev, u32 if_id, /* Number of transfer descriptors determines size of the queue */ mhi_netdev->rx_queue_sz = mhi_get_free_desc_count(mhi_dev, DMA_FROM_DEVICE); - if (extack) - err = register_netdevice(ndev); - else - err = register_netdev(ndev); + err = register_netdevice(ndev); if (err) goto out_err; @@ -370,10 +367,7 @@ static void mhi_net_dellink(void *ctxt, struct net_device *ndev, struct mhi_net_dev *mhi_netdev = netdev_priv(ndev); struct mhi_device *mhi_dev = ctxt; - if (head) - unregister_netdevice_queue(ndev, head); - else - unregister_netdev(ndev); + unregister_netdevice_queue(ndev, head); mhi_unprepare_from_transfer(mhi_dev); @@ -382,7 +376,7 @@ static void mhi_net_dellink(void *ctxt, struct net_device *ndev, dev_set_drvdata(&mhi_dev->dev, NULL); } -const struct wwan_ops mhi_wwan_ops = { +static const struct wwan_ops mhi_wwan_ops = { .priv_size = sizeof(struct mhi_net_dev), .setup = mhi_net_setup, .newlink = mhi_net_newlink, @@ -392,55 +386,19 @@ const struct wwan_ops mhi_wwan_ops = { static int mhi_net_probe(struct mhi_device *mhi_dev, const struct mhi_device_id *id) { - const struct mhi_device_info *info = (struct mhi_device_info *)id->driver_data; struct mhi_controller *cntrl = mhi_dev->mhi_cntrl; - struct net_device *ndev; - int err; - - err = wwan_register_ops(&cntrl->mhi_dev->dev, &mhi_wwan_ops, mhi_dev, - WWAN_NO_DEFAULT_LINK); - if (err) - return err; - - if (!create_default_iface) - return 0; - - /* Create a default interface which is used as either RMNET real-dev, - * MBIM link 0 or ip link 0) - */ - ndev = alloc_netdev(sizeof(struct mhi_net_dev), info->netname, - NET_NAME_PREDICTABLE, mhi_net_setup); - if (!ndev) { - err = -ENOMEM; - goto err_unregister; - } - - SET_NETDEV_DEV(ndev, &mhi_dev->dev); - err = mhi_net_newlink(mhi_dev, ndev, 0, NULL); - if (err) - goto err_release; - - return 0; - -err_release: - free_netdev(ndev); -err_unregister: - wwan_unregister_ops(&cntrl->mhi_dev->dev); - - return err; + return wwan_register_ops(&cntrl->mhi_dev->dev, &mhi_wwan_ops, mhi_dev, + create_default_iface ? 0 : + WWAN_NO_DEFAULT_LINK); } static void mhi_net_remove(struct mhi_device *mhi_dev) { - struct mhi_net_dev *mhi_netdev = dev_get_drvdata(&mhi_dev->dev); struct mhi_controller *cntrl = mhi_dev->mhi_cntrl; /* rtnetlink takes care of removing remaining links */ wwan_unregister_ops(&cntrl->mhi_dev->dev); - - if (create_default_iface) - mhi_net_dellink(mhi_dev, mhi_netdev->ndev, NULL); } static const struct mhi_device_info mhi_hwip0 = { From patchwork Tue Jun 15 00:30:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Ryazanov X-Patchwork-Id: 12320281 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 66ED6C2B9F4 for ; Tue, 15 Jun 2021 00:31:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4AEE361107 for ; Tue, 15 Jun 2021 00:31:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231202AbhFOAdu (ORCPT ); Mon, 14 Jun 2021 20:33:50 -0400 Received: from mail-lf1-f41.google.com ([209.85.167.41]:37520 "EHLO mail-lf1-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230452AbhFOAds (ORCPT ); Mon, 14 Jun 2021 20:33:48 -0400 Received: by mail-lf1-f41.google.com with SMTP id p7so24000859lfg.4 for ; Mon, 14 Jun 2021 17:31:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rK7ngGZWBVcpmOssuPiFzXjHyJ/3C95AHmzppCUZ0Ug=; b=SWMXQ6V43/3SiKZrlIou2lz5W+dA3NdT5JaIy7JSqjchQGeQ2yC8zPDl9qdYSYXPML dMpRwgckX/IZH0kSQwl4L5DVIwssLISorSJl3OSz78gqh1OEiS4h1fteKpQRRpIJcguz /20rSTE6nGdxdO3ntPACTviEUMP2Q1Ldz5ojXX0WF89cZ/FAMtkeLm1RGDgtmt3mCeFz WiM7eLx5XQoPHbMC1S0mW9ZoLXWIvuVvn28CUaGHX2qWJjxH5pt9MagZY6cimOJ1DgcK svxM/L4MXfujOymzfBRRftFX7EpvHFuU8GZgzoJBWCdJbgU4SqqnrA8Ti0LDPVCS2lcI bnWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rK7ngGZWBVcpmOssuPiFzXjHyJ/3C95AHmzppCUZ0Ug=; b=ZXO7u/onubekB4+XCazFOHoaLQifZrnY/rUexrSwNhZLoAC91CPNoXcNuabyv2Qi1u 1Ka4R+TUvySE+NKfZs/NqJNbqQaZNtTl5QAUCxc84Hp1MuelacWI8qA7+e9hVkpCjKHQ aW5PyIRChlp1w32SAXRVqa8kX/DXmSi1P8Ls6/pwJuLl0NwOW3vJPWC+3VIvsjHKLEVy QxZNx1fdS8tsemnxUuAiNOjPDz1AgMA3X6aZxrxarrVtxd7HnEiu1io7va0Z+EAI+GY7 QoJiYKq/lYMYp8QGcet1lV+RxLT+b0EuUmRqA9Vd6gMbjEYLEwp0tUlXA1ZvMewYNBpU JzFw== X-Gm-Message-State: AOAM531ERqKRNQ1L2gyhbtzvOnab1tYiKxwG/63kVPwQNNx3WUUOH7J+ fhqTkfiH13UkmYeYWBMGtlc= X-Google-Smtp-Source: ABdhPJwwjCoYyY3PUzfWQY6zq0lyTL4MND/FEdUrRbnOlc+6XGtGSydcOWT1KEYC5uzIfrOG2qFZFA== X-Received: by 2002:ac2:425a:: with SMTP id m26mr13983165lfl.458.1623717030575; Mon, 14 Jun 2021 17:30:30 -0700 (PDT) Received: from rsa-laptop.internal.lan ([217.25.229.52]) by smtp.gmail.com with ESMTPSA id 9sm1635522lfy.41.2021.06.14.17.30.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jun 2021 17:30:30 -0700 (PDT) From: Sergey Ryazanov To: Loic Poulain , Johannes Berg , "David S. Miller" , Jakub Kicinski Cc: netdev@vger.kernel.org, M Chetan Kumar , Intel Corporation Subject: [PATCH net-next 10/10] wwan: core: add WWAN common private data for netdev Date: Tue, 15 Jun 2021 03:30:16 +0300 Message-Id: <20210615003016.477-11-ryazanov.s.a@gmail.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210615003016.477-1-ryazanov.s.a@gmail.com> References: <20210615003016.477-1-ryazanov.s.a@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org The WWAN core not only multiplex the netdev configuration data, but process it too, and needs some space to store its private data associated with the netdev. Add a structure to keep common WWAN core data. The structure will be stored inside the netdev private data before WWAN driver private data and have a field to make it easier to access the driver data. Also add a helper function that simplifies drivers access to their data. At the moment we use the common WWAN private data to store the WWAN data link (channel) id at the time the link is created, and report it back to user using the .fill_info() RTNL callback. This should help the user to be aware which network interface is binded to which WWAN device data channel. Signed-off-by: Sergey Ryazanov CC: M Chetan Kumar CC: Intel Corporation --- drivers/net/mhi/net.c | 12 +++++------ drivers/net/mhi/proto_mbim.c | 5 +++-- drivers/net/wwan/iosm/iosm_ipc_wwan.c | 12 +++++------ drivers/net/wwan/wwan_core.c | 29 ++++++++++++++++++++++++++- include/linux/wwan.h | 18 +++++++++++++++++ 5 files changed, 61 insertions(+), 15 deletions(-) diff --git a/drivers/net/mhi/net.c b/drivers/net/mhi/net.c index 06253acecaa2..cff433d7b984 100644 --- a/drivers/net/mhi/net.c +++ b/drivers/net/mhi/net.c @@ -32,7 +32,7 @@ struct mhi_device_info { static int mhi_ndo_open(struct net_device *ndev) { - struct mhi_net_dev *mhi_netdev = netdev_priv(ndev); + struct mhi_net_dev *mhi_netdev = wwan_netdev_drvpriv(ndev); /* Feed the rx buffer pool */ schedule_delayed_work(&mhi_netdev->rx_refill, 0); @@ -47,7 +47,7 @@ static int mhi_ndo_open(struct net_device *ndev) static int mhi_ndo_stop(struct net_device *ndev) { - struct mhi_net_dev *mhi_netdev = netdev_priv(ndev); + struct mhi_net_dev *mhi_netdev = wwan_netdev_drvpriv(ndev); netif_stop_queue(ndev); netif_carrier_off(ndev); @@ -58,7 +58,7 @@ static int mhi_ndo_stop(struct net_device *ndev) static int mhi_ndo_xmit(struct sk_buff *skb, struct net_device *ndev) { - struct mhi_net_dev *mhi_netdev = netdev_priv(ndev); + struct mhi_net_dev *mhi_netdev = wwan_netdev_drvpriv(ndev); const struct mhi_net_proto *proto = mhi_netdev->proto; struct mhi_device *mdev = mhi_netdev->mdev; int err; @@ -93,7 +93,7 @@ static int mhi_ndo_xmit(struct sk_buff *skb, struct net_device *ndev) static void mhi_ndo_get_stats64(struct net_device *ndev, struct rtnl_link_stats64 *stats) { - struct mhi_net_dev *mhi_netdev = netdev_priv(ndev); + struct mhi_net_dev *mhi_netdev = wwan_netdev_drvpriv(ndev); unsigned int start; do { @@ -322,7 +322,7 @@ static int mhi_net_newlink(void *ctxt, struct net_device *ndev, u32 if_id, if (dev_get_drvdata(&mhi_dev->dev)) return -EBUSY; - mhi_netdev = netdev_priv(ndev); + mhi_netdev = wwan_netdev_drvpriv(ndev); dev_set_drvdata(&mhi_dev->dev, mhi_netdev); mhi_netdev->ndev = ndev; @@ -364,7 +364,7 @@ static int mhi_net_newlink(void *ctxt, struct net_device *ndev, u32 if_id, static void mhi_net_dellink(void *ctxt, struct net_device *ndev, struct list_head *head) { - struct mhi_net_dev *mhi_netdev = netdev_priv(ndev); + struct mhi_net_dev *mhi_netdev = wwan_netdev_drvpriv(ndev); struct mhi_device *mhi_dev = ctxt; unregister_netdevice_queue(ndev, head); diff --git a/drivers/net/mhi/proto_mbim.c b/drivers/net/mhi/proto_mbim.c index fc72b3f6ec9e..bf1ad863237d 100644 --- a/drivers/net/mhi/proto_mbim.c +++ b/drivers/net/mhi/proto_mbim.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -56,7 +57,7 @@ static void __mbim_errors_inc(struct mhi_net_dev *dev) static int mbim_rx_verify_nth16(struct sk_buff *skb) { - struct mhi_net_dev *dev = netdev_priv(skb->dev); + struct mhi_net_dev *dev = wwan_netdev_drvpriv(skb->dev); struct mbim_context *ctx = dev->proto_data; struct usb_cdc_ncm_nth16 *nth16; int len; @@ -102,7 +103,7 @@ static int mbim_rx_verify_nth16(struct sk_buff *skb) static int mbim_rx_verify_ndp16(struct sk_buff *skb, struct usb_cdc_ncm_ndp16 *ndp16) { - struct mhi_net_dev *dev = netdev_priv(skb->dev); + struct mhi_net_dev *dev = wwan_netdev_drvpriv(skb->dev); int ret; if (le16_to_cpu(ndp16->wLength) < USB_CDC_NCM_NDP16_LENGTH_MIN) { diff --git a/drivers/net/wwan/iosm/iosm_ipc_wwan.c b/drivers/net/wwan/iosm/iosm_ipc_wwan.c index adb2bd40a404..61ec48468b63 100644 --- a/drivers/net/wwan/iosm/iosm_ipc_wwan.c +++ b/drivers/net/wwan/iosm/iosm_ipc_wwan.c @@ -20,7 +20,7 @@ #define IOSM_IF_ID_PAYLOAD 2 /** - * struct iosm_netdev_priv - netdev private data + * struct iosm_netdev_priv - netdev WWAN driver specific private data * @ipc_wwan: Pointer to iosm_wwan struct * @netdev: Pointer to network interface device structure * @if_id: Interface id for device. @@ -51,7 +51,7 @@ struct iosm_wwan { /* Bring-up the wwan net link */ static int ipc_wwan_link_open(struct net_device *netdev) { - struct iosm_netdev_priv *priv = netdev_priv(netdev); + struct iosm_netdev_priv *priv = wwan_netdev_drvpriv(netdev); struct iosm_wwan *ipc_wwan = priv->ipc_wwan; int if_id = priv->if_id; int ret; @@ -88,7 +88,7 @@ static int ipc_wwan_link_open(struct net_device *netdev) /* Bring-down the wwan net link */ static int ipc_wwan_link_stop(struct net_device *netdev) { - struct iosm_netdev_priv *priv = netdev_priv(netdev); + struct iosm_netdev_priv *priv = wwan_netdev_drvpriv(netdev); netif_stop_queue(netdev); @@ -105,7 +105,7 @@ static int ipc_wwan_link_stop(struct net_device *netdev) static int ipc_wwan_link_transmit(struct sk_buff *skb, struct net_device *netdev) { - struct iosm_netdev_priv *priv = netdev_priv(netdev); + struct iosm_netdev_priv *priv = wwan_netdev_drvpriv(netdev); struct iosm_wwan *ipc_wwan = priv->ipc_wwan; int if_id = priv->if_id; int ret; @@ -178,7 +178,7 @@ static int ipc_wwan_newlink(void *ctxt, struct net_device *dev, if_id >= ARRAY_SIZE(ipc_wwan->sub_netlist)) return -EINVAL; - priv = netdev_priv(dev); + priv = wwan_netdev_drvpriv(dev); priv->if_id = if_id; priv->netdev = dev; priv->ipc_wwan = ipc_wwan; @@ -208,8 +208,8 @@ static int ipc_wwan_newlink(void *ctxt, struct net_device *dev, static void ipc_wwan_dellink(void *ctxt, struct net_device *dev, struct list_head *head) { + struct iosm_netdev_priv *priv = wwan_netdev_drvpriv(dev); struct iosm_wwan *ipc_wwan = ctxt; - struct iosm_netdev_priv *priv = netdev_priv(dev); int if_id = priv->if_id; if (WARN_ON(if_id < IP_MUX_SESSION_START || diff --git a/drivers/net/wwan/wwan_core.c b/drivers/net/wwan/wwan_core.c index b99a737a7d77..3b5545f32c0e 100644 --- a/drivers/net/wwan/wwan_core.c +++ b/drivers/net/wwan/wwan_core.c @@ -807,6 +807,7 @@ static struct net_device *wwan_rtnl_alloc(struct nlattr *tb[], const char *devname = nla_data(tb[IFLA_PARENT_DEV_NAME]); struct wwan_device *wwandev = wwan_dev_get_by_name(devname); struct net_device *dev; + unsigned int priv_size; if (IS_ERR(wwandev)) return ERR_CAST(wwandev); @@ -817,7 +818,8 @@ static struct net_device *wwan_rtnl_alloc(struct nlattr *tb[], goto out; } - dev = alloc_netdev_mqs(wwandev->ops->priv_size, ifname, name_assign_type, + priv_size = sizeof(struct wwan_netdev_priv) + wwandev->ops->priv_size; + dev = alloc_netdev_mqs(priv_size, ifname, name_assign_type, wwandev->ops->setup, num_tx_queues, num_rx_queues); if (dev) { @@ -837,6 +839,7 @@ static int wwan_rtnl_newlink(struct net *src_net, struct net_device *dev, { struct wwan_device *wwandev = wwan_dev_get_by_parent(dev->dev.parent); u32 link_id = nla_get_u32(data[IFLA_WWAN_LINK_ID]); + struct wwan_netdev_priv *priv = netdev_priv(dev); int ret; if (IS_ERR(wwandev)) @@ -848,6 +851,7 @@ static int wwan_rtnl_newlink(struct net *src_net, struct net_device *dev, goto out; } + priv->link_id = link_id; if (wwandev->ops->newlink) ret = wwandev->ops->newlink(wwandev->ops_ctxt, dev, link_id, extack); @@ -881,6 +885,27 @@ static void wwan_rtnl_dellink(struct net_device *dev, struct list_head *head) put_device(&wwandev->dev); } +static size_t wwan_rtnl_get_size(const struct net_device *dev) +{ + return + nla_total_size(4) + /* IFLA_WWAN_LINK_ID */ + 0; +} + +static int wwan_rtnl_fill_info(struct sk_buff *skb, + const struct net_device *dev) +{ + struct wwan_netdev_priv *priv = netdev_priv(dev); + + if (nla_put_u32(skb, IFLA_WWAN_LINK_ID, priv->link_id)) + goto nla_put_failure; + + return 0; + +nla_put_failure: + return -EMSGSIZE; +} + static const struct nla_policy wwan_rtnl_policy[IFLA_WWAN_MAX + 1] = { [IFLA_WWAN_LINK_ID] = { .type = NLA_U32 }, }; @@ -892,6 +917,8 @@ static struct rtnl_link_ops wwan_rtnl_link_ops __read_mostly = { .validate = wwan_rtnl_validate, .newlink = wwan_rtnl_newlink, .dellink = wwan_rtnl_dellink, + .get_size = wwan_rtnl_get_size, + .fill_info = wwan_rtnl_fill_info, .policy = wwan_rtnl_policy, }; diff --git a/include/linux/wwan.h b/include/linux/wwan.h index 14c9a19f3bf0..37a14af95845 100644 --- a/include/linux/wwan.h +++ b/include/linux/wwan.h @@ -8,6 +8,7 @@ #include #include #include +#include /** * enum wwan_port_type - WWAN port types @@ -117,6 +118,23 @@ void wwan_port_txon(struct wwan_port *port); */ void *wwan_port_get_drvdata(struct wwan_port *port); +/** + * struct wwan_netdev_priv - WWAN core network device private data + * @link_id: WWAN device data link id + * @drv_priv: driver private data area, size is determined in &wwan_ops + */ +struct wwan_netdev_priv { + u32 link_id; + + /* must be last */ + u8 drv_priv[] __aligned(sizeof(void *)); +}; + +static inline void *wwan_netdev_drvpriv(struct net_device *dev) +{ + return ((struct wwan_netdev_priv *)netdev_priv(dev))->drv_priv; +} + /** * Used to indicate that the WWAN core should not create a default network * link.