From patchwork Mon Jun 21 22:50:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Ryazanov X-Patchwork-Id: 12335889 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.7 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 8E094C4743C for ; Mon, 21 Jun 2021 22:51:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6629B6134F for ; Mon, 21 Jun 2021 22:51:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232281AbhFUWxY (ORCPT ); Mon, 21 Jun 2021 18:53:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232064AbhFUWxX (ORCPT ); Mon, 21 Jun 2021 18:53:23 -0400 Received: from mail-lj1-x231.google.com (mail-lj1-x231.google.com [IPv6:2a00:1450:4864:20::231]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34711C061756 for ; Mon, 21 Jun 2021 15:51:07 -0700 (PDT) Received: by mail-lj1-x231.google.com with SMTP id d13so27361998ljg.12 for ; Mon, 21 Jun 2021 15:51:07 -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=dMyzUQy++YboJsJGgtN6WVWJcqkKPrNCnvp07T7VaEs=; b=ZPbk5IJzo+svcvKtsSgT41TSzGeQJjCMb7Ow4I82T6uYGJXZsm2Fv9D07rIIiUmfhq 4X5O9uRZbdCE9tp5W/q377wEYUbbfjJzhO0yvmohSrR6lI4t/wbw/e66vLIkCmCpD2bN 4cgNF6scCdDh3z1cA2j9/jLb26n54g8GXsyy0nWF1aFujRdcrKbGO4iGJo4OtjSSdG+W AUamcjCzdaFkpy5GCGZgSTgHDxAPXswk8SQFYQ+pOlxDzx6Em3yNFipxEmeI+mvQDm1s 6GWMVaVXaO+4b39jGiNeCfGmM2nMPjG2gwPDTg+cSEn0fLHKKh0KaAdtNvMm11tTYQAa /OAw== 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=dMyzUQy++YboJsJGgtN6WVWJcqkKPrNCnvp07T7VaEs=; b=DgQxOXbIF9pagAFUAAsk3zPiSw3OyuS7m+mFgwOsLggSuFBEUKNUfoM4PacYagrHiV XoMSajsZ2NvxTuqCDcKOBLDVkzfa2HeaCaGRVg/uGSNFcmBoX9DB7LYWDNJ2jWPwY7IH DKRV3dUOPmXy+ZMFWTVEePlc+p4MrdmVHPL7eU4CzCxxADw+DlRsXXcYMl24qS6eA0a1 jtp/SB6yiwqCLTdrtIgROzBFgK2ueds+H5PEz3HDB4UncpF2qF+VoCKMISu+zXIGJ2A0 /6yI73HaCfElFWeGYf190wzI2DNezNbLkFPdmSaFbiORfUgulSar84PNYfgpDdu3TTZr qbVA== X-Gm-Message-State: AOAM531b5+cMK7NoZqzYYgr4DerkJbgVKAVg9XhNpIP6xmnZAFdJHBXm ywNCZIO2PO/1jHgunn16gAc= X-Google-Smtp-Source: ABdhPJxoPMRFyMui+6K0Sjgxm78jvq+eImcicKUAE425O/PxnreIKkTtuhg/5HPprwEIN+ZDv8p/OA== X-Received: by 2002:a2e:5c08:: with SMTP id q8mr431730ljb.145.1624315865580; Mon, 21 Jun 2021 15:51:05 -0700 (PDT) Received: from rsa-laptop.internal.lan ([217.25.229.52]) by smtp.gmail.com with ESMTPSA id x207sm124826lff.53.2021.06.21.15.51.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Jun 2021 15:51:05 -0700 (PDT) From: Sergey Ryazanov To: Loic Poulain , Johannes Berg , "David S. Miller" , Jakub Kicinski Cc: netdev@vger.kernel.org Subject: [PATCH net-next v2 01/10] wwan_hwsim: support network interface creation Date: Tue, 22 Jun 2021 01:50:51 +0300 Message-Id: <20210621225100.21005-2-ryazanov.s.a@gmail.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210621225100.21005-1-ryazanov.s.a@gmail.com> References: <20210621225100.21005-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 --- v1 -> v2: * no changes 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 Mon Jun 21 22:50:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Ryazanov X-Patchwork-Id: 12335893 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.7 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 97583C48BE5 for ; Mon, 21 Jun 2021 22:51:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7AA5A61164 for ; Mon, 21 Jun 2021 22:51:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232360AbhFUWx3 (ORCPT ); Mon, 21 Jun 2021 18:53:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232279AbhFUWxY (ORCPT ); Mon, 21 Jun 2021 18:53:24 -0400 Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1AD4CC061574 for ; Mon, 21 Jun 2021 15:51:08 -0700 (PDT) Received: by mail-lf1-x133.google.com with SMTP id j2so32808166lfg.9 for ; Mon, 21 Jun 2021 15:51:08 -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=XeTcl+ojXRGqwK0cxD8Tw9oSI94jFHk2blsIQcbVeRE=; b=pjvpSapXx2sPE4Z2N7TQaEcOzrxkckEwzPCE7LnEaeTdxFOtrQdIa+1XI+nVf8SjiL F5kkNIfoM0qq7WzN1C50ihT+ZOQoHaIJ8qzGneFsY8F2xh0IFh7Ymk4J0jXx5IEWB77p CWbOeEWVPBqnuE9TJMarZ8qeRLlqOk9l812L8td7993UcUqUKl22q8OaDXRFnM3rp5m5 YwCW6uLMfuN1LzVzEedFo+gsoReokQzn9NHE09HnSL7/YC2laV5vRShcQfDanzwdHv+U i6Eu+GX6x8A7dw0FQQBwoWvVdFU+dVS4fJDVpWcpbFEhZrMGksinF36SCNj7h9f+JtTl PBGQ== 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=XeTcl+ojXRGqwK0cxD8Tw9oSI94jFHk2blsIQcbVeRE=; b=PC4kscnEioKxq/n7YK5FejkLWMOg+OoUn3JLnk8T3ravdfqIerzkhFEDsAXO8dydk8 BosD4KMjJSArXmQ5s3QXALoYPfUnvKF7qc4r4vWADMRk7KpVYL4eNtMvfC4Ro59pxWX6 /Eoo7m697iO2W3GciOzVDTBDjWX83zOOncl3EW2Dx6TMKkkQ+CYFn+GgXTqHme0L5g/0 9XHWSXBk6lfIO3pmW5kjscf+DIqbSbLNNuFm5wxEMdIYVXRZgWiKnX7ofVEjEBgXvXg0 o3Rok9f6EdwyyjKBLkv2qPa0E6qiy934Bxi3lvYZX9iQUyb9Ra9TOOZJ4uImkhg/aiK4 Pfzw== X-Gm-Message-State: AOAM532npFtNK6AeLqScbHAj0tk+2pxLqKdXBpp02r085BWniwUWAaW/ JvwED7CXuDtztgmX9WGg2mA= X-Google-Smtp-Source: ABdhPJzinRAruyfRrXHCww1WHMLaSM6IV9SwJ0hwSa/CmqoGRUQUPANScPGReagLMGjJT4yFRJK9GQ== X-Received: by 2002:a19:7d04:: with SMTP id y4mr418858lfc.201.1624315866479; Mon, 21 Jun 2021 15:51:06 -0700 (PDT) Received: from rsa-laptop.internal.lan ([217.25.229.52]) by smtp.gmail.com with ESMTPSA id x207sm124826lff.53.2021.06.21.15.51.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Jun 2021 15:51:06 -0700 (PDT) From: Sergey Ryazanov To: Loic Poulain , Johannes Berg , "David S. Miller" , Jakub Kicinski Cc: netdev@vger.kernel.org Subject: [PATCH net-next v2 02/10] wwan: core: relocate ops registering code Date: Tue, 22 Jun 2021 01:50:52 +0300 Message-Id: <20210621225100.21005-3-ryazanov.s.a@gmail.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210621225100.21005-1-ryazanov.s.a@gmail.com> References: <20210621225100.21005-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 --- v1 -> v2: * no changes 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 165afec1dbd1..688a7278a396 100644 --- a/drivers/net/wwan/wwan_core.c +++ b/drivers/net/wwan/wwan_core.c @@ -789,77 +789,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) { @@ -974,6 +903,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 Mon Jun 21 22:50:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Ryazanov X-Patchwork-Id: 12335891 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.7 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 01F37C4743C for ; Mon, 21 Jun 2021 22:51:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D38086134F for ; Mon, 21 Jun 2021 22:51:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232342AbhFUWx2 (ORCPT ); Mon, 21 Jun 2021 18:53:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232283AbhFUWxY (ORCPT ); Mon, 21 Jun 2021 18:53:24 -0400 Received: from mail-lj1-x22a.google.com (mail-lj1-x22a.google.com [IPv6:2a00:1450:4864:20::22a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2E67C061756 for ; Mon, 21 Jun 2021 15:51:08 -0700 (PDT) Received: by mail-lj1-x22a.google.com with SMTP id a21so2280966ljj.1 for ; Mon, 21 Jun 2021 15:51:08 -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=8YszF+KJknlKGnazgpJVo3N5S+om/qdEPsz9YOytr4g=; b=lDA3R2JGrMcf1sfoSXfEDo9PNFukwoYNwOlM0+I4UlqQGzFyFzUsE0NnLcCEqQ5vgm f8Pe4RX7yhI97ZD6S6ARtKcCeK0BCX6H7FqPSkKVCEnPor/NKGNi/rcN3LR22HRYAJeO JCksutqX6ep1psWW9TS99FFu2k3hICyBanoa/4j2U6XkQ7KKGR9NI1XSfCGmDJf8mdTG MjqzhIaGLZ50bwdDkq2b7e7DB4wslj/4ipuyyCkyXMLftp6VFOIMFhb7u5HgrZptZNY7 w32rPIHEhZrYenQUkwXFguoLjWQsyRHIBELVhBAWXZB3843FQLR7lGt2TsvFEp5FzJz3 MRkQ== 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=8YszF+KJknlKGnazgpJVo3N5S+om/qdEPsz9YOytr4g=; b=n9p/balbA8sjmjzsmCGcQ7QU1vSmwvnlh/pDqKtgsW4jLVjwsB3ovGJ6LucxvAewZA hZUEOtvsY1WV7uVKOUxFU2DI8LMZYAjN63zKuBauU1G/4/R0pam0l/6URG2t9D2qaqNJ EsnqpkFuD7SasWl52UNRrZr9qHsy27m9bX78AhTfMNbwEeS1pGa32APTObAxT+22NJEi KIhEfragcXFG455RTULGbgHsncCK3Oxan0Daq7QfXEj27cmtTol4de7gC9pr+fKA8vdH BeUwzLXOobblS0rghNORz0/yLPvgWATpGiK74XhoKptTpUDDDaCLOB1VT/SldR+/4ZkC qTTQ== X-Gm-Message-State: AOAM531xOy0S7X5IhOV3xEEcz9CETXQJOYHeBWfwJIkozbVdOK7M+TB7 eB5Vw2TO83DTRVrp99NtLFc= X-Google-Smtp-Source: ABdhPJwDN4n5ofMk84XSXCOZAfGzGSKu2NXnxhmVYqkW4fWVBoI/q6/4cv2a0wFpQadIdjfRa050lg== X-Received: by 2002:a2e:b618:: with SMTP id r24mr452310ljn.48.1624315867381; Mon, 21 Jun 2021 15:51:07 -0700 (PDT) Received: from rsa-laptop.internal.lan ([217.25.229.52]) by smtp.gmail.com with ESMTPSA id x207sm124826lff.53.2021.06.21.15.51.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Jun 2021 15:51:07 -0700 (PDT) From: Sergey Ryazanov To: Loic Poulain , Johannes Berg , "David S. Miller" , Jakub Kicinski Cc: netdev@vger.kernel.org Subject: [PATCH net-next v2 03/10] wwan: core: require WWAN netdev setup callback existence Date: Tue, 22 Jun 2021 01:50:53 +0300 Message-Id: <20210621225100.21005-4-ryazanov.s.a@gmail.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210621225100.21005-1-ryazanov.s.a@gmail.com> References: <20210621225100.21005-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 Reviewed-by: Loic Poulain --- v1 -> v2: * no changes 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 688a7278a396..1bd472195813 100644 --- a/drivers/net/wwan/wwan_core.c +++ b/drivers/net/wwan/wwan_core.c @@ -917,7 +917,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 Mon Jun 21 22:50:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Ryazanov X-Patchwork-Id: 12335895 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.7 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 BA4A3C48BC2 for ; Mon, 21 Jun 2021 22:51:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A61B061351 for ; Mon, 21 Jun 2021 22:51:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232387AbhFUWxa (ORCPT ); Mon, 21 Jun 2021 18:53:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232289AbhFUWxY (ORCPT ); Mon, 21 Jun 2021 18:53:24 -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 F0349C061574 for ; Mon, 21 Jun 2021 15:51:09 -0700 (PDT) Received: by mail-lj1-x229.google.com with SMTP id k8so27258417lja.4 for ; Mon, 21 Jun 2021 15:51:09 -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=fFRTgnhaZdiPc4s23/e1DRJMfNzImvLNibkBRz67I0U=; b=C6udMV9IW+azsIT1AE8bakJQpGQCaCZYvfc0d35CyE8TEvw0aYB3w2sjEGs9ufKhP9 EGYN/V62Tv1LcBnLIrgT1Xx8k6ECQvKk0QwpI+/FM0fXIfQ9T2p5Hc6BJJ+6RjrGmG/9 8gRLBjc/9M1pcpMQFoWWHc76rL0Tq5bjpcNomLd3IHKQ90apTtxEXUhijdbT/09vu7Ox /XNr0iGzuflIiwFa1NLpZ5ohQ4sguzP+p2+McwWdnFIelY4b00XSp7VSC28iXn5HqaOO JA2nZZOTnhztVwC9hCrGI/hCWoa8LdiusDvNLsnw1zNpA4WQjiI7te2ZxDzkEZtbSgJO COhg== 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=fFRTgnhaZdiPc4s23/e1DRJMfNzImvLNibkBRz67I0U=; b=Mm5U6INerU+Iq56L4nQzLt3/45D/m3GM8MMfJ7SUhdd8IcOarJsOH46J6k4/ui33lw ntiEajxLpcT+vHa7K/i2qI96NsJ0wQSp0ErOzkdc3xODfjzb/i5BVjofsIGGJfHp/6pd OocCp+TMU2nvw+zVnbzgbgyY5OaldKKToRo2FHHZq6Zc32syLSZ76MsVdRCFhPRR+s3/ FY2hV+qTP9Hx1CupJRonIVlPdWX8tkIw70tVfimUeRygBM3cPY8t/jKs8NGk/DLj51ck VtXkqB8r2twnQEp9jDwp5GZJdzv/tMVg1V5Nk55TM4HE0d8YWB7NhLcZ/icaeYhoij5U Qu6w== X-Gm-Message-State: AOAM5330RqaBfROzotRAQhMFDk+MUkW6G9VhZHTpMg1Qx+TRYPpBqad7 fgnnl29Iavvbm9S60pYWgXE= X-Google-Smtp-Source: ABdhPJzRUW2nS1hyXOMSvrKFTMDZr7bdgmy9H1PlVtLTcNn2fglWo28zLXzyDo3JPBHa22wg5I1VVg== X-Received: by 2002:a05:651c:147:: with SMTP id c7mr460871ljd.98.1624315868374; Mon, 21 Jun 2021 15:51:08 -0700 (PDT) Received: from rsa-laptop.internal.lan ([217.25.229.52]) by smtp.gmail.com with ESMTPSA id x207sm124826lff.53.2021.06.21.15.51.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Jun 2021 15:51:08 -0700 (PDT) From: Sergey Ryazanov To: Loic Poulain , Johannes Berg , "David S. Miller" , Jakub Kicinski Cc: netdev@vger.kernel.org Subject: [PATCH net-next v2 04/10] wwan: core: multiple netdevs deletion support Date: Tue, 22 Jun 2021 01:50:54 +0300 Message-Id: <20210621225100.21005-5-ryazanov.s.a@gmail.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210621225100.21005-1-ryazanov.s.a@gmail.com> References: <20210621225100.21005-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 Reviewed-by: Loic Poulain --- v1 -> v2: * no changes 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 1bd472195813..b6b9c52f617c 100644 --- a/drivers/net/wwan/wwan_core.c +++ b/drivers/net/wwan/wwan_core.c @@ -882,7 +882,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 Mon Jun 21 22:50:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Ryazanov X-Patchwork-Id: 12335897 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.7 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 78F23C49EA4 for ; Mon, 21 Jun 2021 22:51:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5B1C06128A for ; Mon, 21 Jun 2021 22:51:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232290AbhFUWxb (ORCPT ); Mon, 21 Jun 2021 18:53:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232322AbhFUWx0 (ORCPT ); Mon, 21 Jun 2021 18:53:26 -0400 Received: from mail-lj1-x22b.google.com (mail-lj1-x22b.google.com [IPv6:2a00:1450:4864:20::22b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E306CC061574 for ; Mon, 21 Jun 2021 15:51:10 -0700 (PDT) Received: by mail-lj1-x22b.google.com with SMTP id u11so16483197ljh.2 for ; Mon, 21 Jun 2021 15:51:10 -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=7l78aaQEjWX2/qGdM6ykVAxXCOzp5I0Tf9JvJqtJA7Y=; b=fWER/Ne3JysnTovM/VRwXqI7ddwm6jbcLvEANONEJsBzZWXm7yavsyMyGAURLJQ1WL zwnW8SzrWgQ+fyN50NrauUOadT4rYKp6j00zsgDT6fv7zHc1GJY79QP+7JVQI6l64Lke EfyhJlReCAwcZXFTjlpdgXB5ZDUH8VSfMJUKQ/uX8zLSXEweJxlCCof574nHyb6s143E iMsMkiFDW8lMAEYpMDEYj6CUtpTvZIaZxaUBh9OZMG2Wr6kgfNvd/6SvE5/oMmCNq7Jj o6Se1pX+dGxwuZ30+nUPujXziMLQM3S4KO5yej4AZIfijJTK/NeCkYtbQx8Cl72uxyM4 ke6Q== 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=7l78aaQEjWX2/qGdM6ykVAxXCOzp5I0Tf9JvJqtJA7Y=; b=ZTWA7zLjNCp7usbWuRzX7oSHUg36IOD4a3GmOBc3uUsnZw/9V48q7/lGTVFozhsvDb Vco93A7f4mn7JsI34y+zarfroJRVc6sOTxybLBVeV2x2Hn43ZMtinuK+dkRTJdN/3nQy vx02USx/Yucit/HmcAKyXXwhoFBWAmCRkMP0kwqDoMhQNZhYjnyOy8dBqYzPqzUt+seC GmkkChLRf5LAeA0mp2VOKg+Zw7ySEDrJxXaxtH0QICBCDp8BXzbRihnCRiIIgtH/LipC Lu1xFfM5G08H/FMLp89HcjKF04h3GN7dC9ZWrCrKssGmp0ep3sqLdplI0iVLPqf0lg/1 F4cw== X-Gm-Message-State: AOAM530tARL/qQ4fwQw1BfDvjTTRDoq1H6nyNd51UZtNg7Cpw1ahit4Y ofYAMhcp/mGKYFDC/bVHC8I= X-Google-Smtp-Source: ABdhPJw888xvbNW8VlchvIkYZyY393oSDxthVoHFonZC7yKPjjitxGt1CO94K7qLYQmclAr9sG7Z5g== X-Received: by 2002:a2e:9855:: with SMTP id e21mr441799ljj.295.1624315869331; Mon, 21 Jun 2021 15:51:09 -0700 (PDT) Received: from rsa-laptop.internal.lan ([217.25.229.52]) by smtp.gmail.com with ESMTPSA id x207sm124826lff.53.2021.06.21.15.51.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Jun 2021 15:51:08 -0700 (PDT) From: Sergey Ryazanov To: Loic Poulain , Johannes Berg , "David S. Miller" , Jakub Kicinski Cc: netdev@vger.kernel.org Subject: [PATCH net-next v2 05/10] wwan: core: remove all netdevs on ops unregistering Date: Tue, 22 Jun 2021 01:50:55 +0300 Message-Id: <20210621225100.21005-6-ryazanov.s.a@gmail.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210621225100.21005-1-ryazanov.s.a@gmail.com> References: <20210621225100.21005-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 Reviewed-by: Loic Poulain --- v1 -> v2: * no changes 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 b6b9c52f617c..ec6a69b23dd1 100644 --- a/drivers/net/wwan/wwan_core.c +++ b/drivers/net/wwan/wwan_core.c @@ -941,6 +941,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 @@ -949,26 +960,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 Mon Jun 21 22:50:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Ryazanov X-Patchwork-Id: 12335899 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.7 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 8B27AC4743C for ; Mon, 21 Jun 2021 22:51:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7461361245 for ; Mon, 21 Jun 2021 22:51:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232395AbhFUWxc (ORCPT ); Mon, 21 Jun 2021 18:53:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232347AbhFUWx2 (ORCPT ); Mon, 21 Jun 2021 18:53:28 -0400 Received: from mail-lj1-x22f.google.com (mail-lj1-x22f.google.com [IPv6:2a00:1450:4864:20::22f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED153C061756 for ; Mon, 21 Jun 2021 15:51:11 -0700 (PDT) Received: by mail-lj1-x22f.google.com with SMTP id d2so27465764ljj.11 for ; Mon, 21 Jun 2021 15:51:11 -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=6C49aXdYKp9UsIqXJpx6CmJB4xW3x2fJp+8+xbSdrvI=; b=mxCHobv11Az0cI7oTnLMaEmdm3y3Idpf3xJXLFzZI2rjg2yfbk9BRp63u4zia5A3QM GN+PLXYnXYnlwzUL+1p+I/yYZ0mS/08mJv0O6mRAcogit9fBPtlmL6mvakAfxTejecuM 1488dO7erAD3l3eQuvcn7/V31mIWNL92e7Huk/FFZ3Wy9sdb102Zpb2kg2rQb+jR7SlI c5lvi1qTxCh9+KerGbmcLAYCRnrVm/CmjLR+XeRchPxnPWCbnl+pRrg8uyUF3Pls8bzD LlRueNPRNe4D0fXj/toe58oBBAt950nNuzJCPUN+0ISUolxKCguZu7ze/C2bKTW+jAd0 s78A== 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=6C49aXdYKp9UsIqXJpx6CmJB4xW3x2fJp+8+xbSdrvI=; b=sHcNRFOBQToVVKOyl+rHCNCuw5Xe3sgx4GS5slXwZnwNcbJVjs0uXD5bK868zRC3F+ 1Np4yrPk+EYVm8u74gsXzN0wdWhjsPbFOY+v0YH2zI8kwrngIxvu36D5ZFiuoIRQHYPm 6DP/+l2uczx6XEjKVyFWzbV+7djT01pJkPqbPBbrAOxVGYz45mgFhzXgWXelCqxS0NeE 9X5Birbdff2s4M0goto3zb1VAOYqLH/oYCOohZquHJVlvF7fBjYEzIBKNYkpl+gM9Azc xLiMw0vxDGr6A+y3VjEOgyjTxK1Qh4Qmd8Iv2HWLA9Al6KAFaHNqpOJLZUlKwwHO13sC wuqA== X-Gm-Message-State: AOAM533ac4GhFv3pfd2iBT/24fI9D8b3AMkBIpGBpLuVhgcrmhTloIM9 5W3RX7moxH+/5KTmM11qgLw= X-Google-Smtp-Source: ABdhPJzZN8seJqU9fiGABIlKmfH06+bW4KCJ0cd7ycr5Ozv8vX5+7t1qCdaYGMj1JzNYk0a5k6yBdg== X-Received: by 2002:a2e:93c8:: with SMTP id p8mr418313ljh.95.1624315870391; Mon, 21 Jun 2021 15:51:10 -0700 (PDT) Received: from rsa-laptop.internal.lan ([217.25.229.52]) by smtp.gmail.com with ESMTPSA id x207sm124826lff.53.2021.06.21.15.51.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Jun 2021 15:51:09 -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 v2 06/10] net: iosm: drop custom netdev(s) removing Date: Tue, 22 Jun 2021 01:50:56 +0300 Message-Id: <20210621225100.21005-7-ryazanov.s.a@gmail.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210621225100.21005-1-ryazanov.s.a@gmail.com> References: <20210621225100.21005-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 cleans 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 Reviewed-by: M Chetan Kumar CC: M Chetan Kumar CC: Intel Corporation --- v1 -> v2: * no changes 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 Mon Jun 21 22:50:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Ryazanov X-Patchwork-Id: 12335903 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.7 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 6BA8EC4743C for ; Mon, 21 Jun 2021 22:51:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4A45661164 for ; Mon, 21 Jun 2021 22:51:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232421AbhFUWxf (ORCPT ); Mon, 21 Jun 2021 18:53:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232362AbhFUWx3 (ORCPT ); Mon, 21 Jun 2021 18:53:29 -0400 Received: from mail-lj1-x236.google.com (mail-lj1-x236.google.com [IPv6:2a00:1450:4864:20::236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1C1FC061766 for ; Mon, 21 Jun 2021 15:51:12 -0700 (PDT) Received: by mail-lj1-x236.google.com with SMTP id s22so27437091ljg.5 for ; Mon, 21 Jun 2021 15:51:12 -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=zcdADzIGh+z3t+SaH4RHteH4RWCo6WcuMAbfzh1uCAw=; b=eBf1uabi1uionfaYTbnmSj8afVcTCtsuOxiRLm5O9LeNJGvgQ6Cxyo4oPwmvuyDIYI fK3RR2XcOiWPUqwlxCtzizWnipZtYgQlMbasuXY9vTyXr662C5ipiJa4rEvnCNK/kR9i 7J+UXlU0vDAS+gRuwwisBB5S1SW58YBktv2tcQA6JSBnQOc4MA/lro5JmPSp4ftpzaa7 p7LJU7HMo2VtI72LB9Onp3Abxd+8UAM1eZ5Ty0BSXMhZ4vkfni4FzHjcXf3TkM62KWmz EAqHkJsBPlcBB+zL7o0zH/erXOJC0mZoV0Bt7MfYJli6BHjciZ/SR0VClAQd0qS/2Z40 HmeQ== 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=zcdADzIGh+z3t+SaH4RHteH4RWCo6WcuMAbfzh1uCAw=; b=rIAqsMvaY/nX+2wUKKMxDIdROR16z20YBT8wt4w5/GRqeYf6kfTAXfGX27w5/SWTpx 2v2yiJmCSfNontW3Z1aJdzHgX4mmZCcU1A2jjfWboGWy5ChBCHSxl2wvz4FMiPvBYeIk Vg9Bbg08T/vcD42SzsjjXMUQ7evBgAMsat8cBK25FchM7qSuD6cA+3g03jb6ImYzYh68 FmBBSy0Ve3R1dDLVs0TseX+lDxs9SzOCxE7nOMOswRmQy/9+oS8wHLCvFSyYaxQCGSVf jnmMd2MDP/HZLa0Dl7RZLIOyqkr+hw8u/rUADifGXM+N4+RKzXdLMbRjDUSnL0N8l20Q jwhQ== X-Gm-Message-State: AOAM530pui9HB8ZfJPQiu+vWZWTy2jUY09HURuWz5JaKVPsihxQbg1Jr 1sYee54NV9SCRgIfqit7KcQ= X-Google-Smtp-Source: ABdhPJzRrQLbZtnRt0gq7Ezmxrtqr2RG8qZQiwfSTPfTFJx1XaaNHVXjSTQLQ16oSlivxpssh20oTA== X-Received: by 2002:a2e:894e:: with SMTP id b14mr462895ljk.112.1624315871323; Mon, 21 Jun 2021 15:51:11 -0700 (PDT) Received: from rsa-laptop.internal.lan ([217.25.229.52]) by smtp.gmail.com with ESMTPSA id x207sm124826lff.53.2021.06.21.15.51.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Jun 2021 15:51:10 -0700 (PDT) From: Sergey Ryazanov To: Loic Poulain , Johannes Berg , "David S. Miller" , Jakub Kicinski Cc: netdev@vger.kernel.org Subject: [PATCH net-next v2 07/10] wwan: core: no more hold netdev ops owning module Date: Tue, 22 Jun 2021 01:50:57 +0300 Message-Id: <20210621225100.21005-8-ryazanov.s.a@gmail.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210621225100.21005-1-ryazanov.s.a@gmail.com> References: <20210621225100.21005-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 Reviewed-by: Loic Poulain --- v1 -> v2: * fix a comment before wwan_unregister_ops() in the mhi/net.c drivers/net/mhi/net.c | 3 +-- drivers/net/wwan/wwan_core.c | 10 ---------- drivers/net/wwan/wwan_hwsim.c | 1 - include/linux/wwan.h | 2 -- 4 files changed, 1 insertion(+), 15 deletions(-) diff --git a/drivers/net/mhi/net.c b/drivers/net/mhi/net.c index 6aa753387372..ffd1c01b3f35 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, } static 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, @@ -436,7 +435,7 @@ 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 core takes care of removing remaining links */ wwan_unregister_ops(&cntrl->mhi_dev->dev); if (create_default_iface) diff --git a/drivers/net/wwan/wwan_core.c b/drivers/net/wwan/wwan_core.c index ec6a69b23dd1..b634a0ba1196 100644 --- a/drivers/net/wwan/wwan_core.c +++ b/drivers/net/wwan/wwan_core.c @@ -929,11 +929,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; @@ -960,7 +955,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))) @@ -976,8 +970,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 */ @@ -989,8 +981,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 34222230360c..e1981ea3a2fd 100644 --- a/include/linux/wwan.h +++ b/include/linux/wwan.h @@ -128,14 +128,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 Mon Jun 21 22:50:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Ryazanov X-Patchwork-Id: 12335905 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.7 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 4B6F1C48BE5 for ; Mon, 21 Jun 2021 22:51:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 35F5861245 for ; Mon, 21 Jun 2021 22:51:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232443AbhFUWxg (ORCPT ); Mon, 21 Jun 2021 18:53:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232392AbhFUWxa (ORCPT ); Mon, 21 Jun 2021 18:53:30 -0400 Received: from mail-lj1-x232.google.com (mail-lj1-x232.google.com [IPv6:2a00:1450:4864:20::232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03C09C0617A6 for ; Mon, 21 Jun 2021 15:51:14 -0700 (PDT) Received: by mail-lj1-x232.google.com with SMTP id k8so4395739ljk.7 for ; Mon, 21 Jun 2021 15:51:13 -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=9x3aWVhf83fqUBCi5KA2Sw+7A91cTEb+jWWkn/WqcsM=; b=UcvxyrC51Mydu6OmjsD/KAIX287fHYFXQo9+xCVVAsjL2JWJthEMxaketbMCvz+LEz ShM9ST6Yjzi7P+Ca/9cHX6XgjCn2QUGboupAJoR+rPlsP8mWARVPyesdtpss1huCi6Xh oyvwn8xEnFVatTL5H73BMyaWzzL4609y2ffCvVgPlfLr7rF03t2zLUeBq5plDsxS/6NA +GPfdUEIvQgAwDk6CPUeNu/otx+rUlDx7ujzzoLFGEmWdqWW5VRsPaLZmXTUFHrTOt2n X6ZVaEheVU2+YxNilIkFu0YJLWJw8S8PdhL9Tb6XsOR320NXJl7W0+ZBN2a0a2CuBG3y XySA== 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=9x3aWVhf83fqUBCi5KA2Sw+7A91cTEb+jWWkn/WqcsM=; b=KdTZ0ztPMOIWpofFYjqpJCIotyAlIe1VUNcxXOVO1F8ikmthgsImiLWzqq3q79d5Tm S4chOhzWJfXCubMaZiCgbEL5VK9qVK+Sijqiyjs2BfETfDJrFVcL8F3YgIfWl1uNQiH2 kgBu3bZyfWYlo1TXoDtgYBrbND3zO5Xw+Sdlp0vJg7n7SuZab/NnPKlmSHCx4cX0Thli Owdat2vtFz7iLQ9MScLowj+VtEcGal9oclwxKnEWppYTTZwFcBQLZJ8ZEfzdE+k9zQ0j xpO7r02Oz7ujSvvay229B+oUsW/laDfKTR5oUflXkA1yyHi6YugmkvxSMzntkIefhpLl wgCA== X-Gm-Message-State: AOAM531E2TnTEiVTGjPeLznwFdcqPrnF6Yx/BRBo+rdHxE1mhu4/tH3K hMPoVXRO/G3mhiiScof8HuA= X-Google-Smtp-Source: ABdhPJxrGP3nQH5yEpvmTe3Hx1LE57YRBQlOI/AV34pTX8uhdoHXK0ZFnETjnOsSEAgdIyg3pSNVFw== X-Received: by 2002:a05:651c:543:: with SMTP id q3mr436849ljp.432.1624315872385; Mon, 21 Jun 2021 15:51:12 -0700 (PDT) Received: from rsa-laptop.internal.lan ([217.25.229.52]) by smtp.gmail.com with ESMTPSA id x207sm124826lff.53.2021.06.21.15.51.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Jun 2021 15:51:12 -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 v2 08/10] wwan: core: support default netdev creation Date: Tue, 22 Jun 2021 01:50:58 +0300 Message-Id: <20210621225100.21005-9-ryazanov.s.a@gmail.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210621225100.21005-1-ryazanov.s.a@gmail.com> References: <20210621225100.21005-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 --- v1 -> v2: * fix a comment style '/**' -> '/*' to avoid confusion with kernel-doc 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 ffd1c01b3f35..f36ca5c0dfe9 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 b634a0ba1196..ef6ec641d877 100644 --- a/drivers/net/wwan/wwan_core.c +++ b/drivers/net/wwan/wwan_core.c @@ -903,17 +903,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; @@ -932,6 +996,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 e1981ea3a2fd..91590db70a12 100644 --- a/include/linux/wwan.h +++ b/include/linux/wwan.h @@ -126,6 +126,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 @@ -143,7 +149,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 Mon Jun 21 22:50:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Ryazanov X-Patchwork-Id: 12335901 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.7 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 B3860C48BE5 for ; Mon, 21 Jun 2021 22:51:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9D43861164 for ; Mon, 21 Jun 2021 22:51:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232413AbhFUWxe (ORCPT ); Mon, 21 Jun 2021 18:53:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232375AbhFUWxa (ORCPT ); Mon, 21 Jun 2021 18:53:30 -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 0F1D5C061574 for ; Mon, 21 Jun 2021 15:51:15 -0700 (PDT) Received: by mail-lj1-x230.google.com with SMTP id a16so5907421ljq.3 for ; Mon, 21 Jun 2021 15:51:14 -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=2RophEWmKGfalis8s/rgDbmaYuR38nADcNkhX8xfF5M=; b=pCyInXwcEMOjWDwY0QDL5DfN7Eu3+KdaCJHxAD6nvDyas1jUxC1pX2vJh+QohgHpoa EwlFnUmOOe53RZVnHcsTCKxr9F6shPuhG4LFZYB8H3ArTqycfZiDKOpnNloKtInOA4X+ NZd7z1A5USHf21YwfpqIhoeWGDzYT9a073114dl5Hp9+nsjIUiJSBV7Wj64NWYT4pQuI Obwi9CiC/S3oyMi/vyXryEV9dnytaOwbhLb9wxsXNGXkTGvarykP2Kjxlx/eyvmj4/Qe CdYRAPhq3YiBKhKu5yddKaBieWhLeYkHBI46QnDNcFiVs8bRbu6JxP2lsU68TYGfEnjW 0xig== 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=2RophEWmKGfalis8s/rgDbmaYuR38nADcNkhX8xfF5M=; b=F+cdStwZoXu31J8BCfCEgLddAAdjt0YE45TuotavQLPH5zlVVq9Zq6ZvjLQUUEXjKM qgIBtFv8f6nAM1ZQG2MC+ui7cqoMWUR3KFwAoEP/svBVZZq2BjNVSU2c5TJgFJRN61Tf Sc+eZCM69vPVg5acn9WoyZ681s7YY0fB0hqs4M48tWUEsCMyKb2WfyfsbtQBOY27cdmL tzTtp5qri7Mx886rRmSAe0zYz4kj8n6vh5yIYG693yIopXYW0bHL8XopSSGgnJwMNZdQ 1ELuUw8FBF5TMBF1Vq+nN67Xl+HWBq/TxpljRdXt3GPJStr08sKXLvg8AUiHqKBVRq3n u95A== X-Gm-Message-State: AOAM531Wr7UoCwN6gRIqQOEfdA/T8Gz83GGHiQ/wzSBxflJeKT75tcog gOLsgvckF2aPg8sFdoCj9mI= X-Google-Smtp-Source: ABdhPJxqbqzVgFLZ1xg/2BvmPbkLCyqNXsF7jCNiQ5YWzsn2lXy3gucAg3DZVxr/M9wXphyVW7wMdw== X-Received: by 2002:a2e:b78f:: with SMTP id n15mr410680ljo.495.1624315873477; Mon, 21 Jun 2021 15:51:13 -0700 (PDT) Received: from rsa-laptop.internal.lan ([217.25.229.52]) by smtp.gmail.com with ESMTPSA id x207sm124826lff.53.2021.06.21.15.51.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Jun 2021 15:51:13 -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 v2 09/10] net: iosm: create default link via WWAN core Date: Tue, 22 Jun 2021 01:50:59 +0300 Message-Id: <20210621225100.21005-10-ryazanov.s.a@gmail.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210621225100.21005-1-ryazanov.s.a@gmail.com> References: <20210621225100.21005-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 (IP MUX) channel. Signed-off-by: Sergey Ryazanov CC: M Chetan Kumar CC: Intel Corporation --- v1 -> v2: * new patch drivers/net/wwan/iosm/iosm_ipc_imem_ops.h | 3 +++ drivers/net/wwan/iosm/iosm_ipc_wwan.c | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/net/wwan/iosm/iosm_ipc_imem_ops.h b/drivers/net/wwan/iosm/iosm_ipc_imem_ops.h index 84087cf33329..fd356dafbdd6 100644 --- a/drivers/net/wwan/iosm/iosm_ipc_imem_ops.h +++ b/drivers/net/wwan/iosm/iosm_ipc_imem_ops.h @@ -30,6 +30,9 @@ #define IP_MUX_SESSION_START 1 #define IP_MUX_SESSION_END 8 +/* Default IP MUX channel */ +#define IP_MUX_SESSION_DEFAULT 1 + /** * ipc_imem_sys_port_open - Open a port link to CP. * @ipc_imem: Imem instance. diff --git a/drivers/net/wwan/iosm/iosm_ipc_wwan.c b/drivers/net/wwan/iosm/iosm_ipc_wwan.c index adb2bd40a404..d3cb28107836 100644 --- a/drivers/net/wwan/iosm/iosm_ipc_wwan.c +++ b/drivers/net/wwan/iosm/iosm_ipc_wwan.c @@ -317,8 +317,9 @@ struct iosm_wwan *ipc_wwan_init(struct iosm_imem *ipc_imem, struct device *dev) ipc_wwan->dev = dev; ipc_wwan->ipc_imem = ipc_imem; + /* WWAN core will create a netdev for the default IP MUX channel */ if (wwan_register_ops(ipc_wwan->dev, &iosm_wwan_ops, ipc_wwan, - WWAN_NO_DEFAULT_LINK)) { + IP_MUX_SESSION_DEFAULT)) { kfree(ipc_wwan); return NULL; } From patchwork Mon Jun 21 22:51:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Ryazanov X-Patchwork-Id: 12335907 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.7 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 E8160C4743C for ; Mon, 21 Jun 2021 22:51:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D185361164 for ; Mon, 21 Jun 2021 22:51:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232465AbhFUWxi (ORCPT ); Mon, 21 Jun 2021 18:53:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232329AbhFUWxc (ORCPT ); Mon, 21 Jun 2021 18:53:32 -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 467BDC061574 for ; Mon, 21 Jun 2021 15:51:16 -0700 (PDT) Received: by mail-lj1-x22c.google.com with SMTP id r16so27433049ljk.9 for ; Mon, 21 Jun 2021 15:51:16 -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=j2uv2MA4sc1scw7PiZnyqf1yD2PG2cpAR2JMuYS/dOI=; b=d892peFcWnuTnxYxegl1HpkwweO2pTtmBg3OACFYSCm5DWpDJN/ba4JlRxxaPPdjCR AladjOLJqs9uZvXN61+PrCk9mB6G5OHw2Sr1QEGh9stitvOsNhcipKm1DFPC8+BZGjPY y73lr72vmOU2GHIUNUVhw8RFs19Nppkh1JAzPtjJIv/YMfLNZ8Ut5qSkg5nC9IWR6tpF ZBCABzrjJZkQzmYZFzzUusXkua838SLKT1yupiCULepTJpdJxwVS/pqvrUNk3dngRFH2 Sk3T1FXpHqVO5LtLww3Dr7xYHtrOT5rOLoYlpgMP59awGOugaoM3LjcgcDwJXQBrTP28 ac2w== 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=j2uv2MA4sc1scw7PiZnyqf1yD2PG2cpAR2JMuYS/dOI=; b=ptboL5pAlv8/l/dYBJjmA7oU1bDg7UE0i0kQtXF1EHEHUd9BA4cLM96Yrzpwfq12sX 9QK7j000layzObcBA9E3rNmIQvgxfMaU0QqnbDSqDnQXxg4ea991DC5cVAobg9QtN2w/ +18vmRcJKWWlfR2XRqQ0RXbmQ3JGyo549ikaLL3hIHuCrvxmpVNOw2o+/O+rcdR6Jq5n KifxtQ6OTevc0ie1if0oLw6+aKAeyXOKrhRA9jNcPQzOYtsGyENuYZlq+6WsyMLlIiQV eZJf7VaolZAGnKfCsXSrtQNLgahvw+mFhbRilQQeL/XpOsyFRIs8rvPbq3OEIwyw3Oxc e8zg== X-Gm-Message-State: AOAM533Z/z20ObXSRdhi56pU3onGjB3pFcohjiLfvo+GFlZbBAfSfp17 S42MN0DttoNQM3i/UyNzKRw= X-Google-Smtp-Source: ABdhPJwu0XqiCGvaCS7IkjxDrRR33Hy1tOAMayIG49+tO6CikHQ3By+KBzQDM1vEt+UcWJEeeuLT3g== X-Received: by 2002:a2e:9e53:: with SMTP id g19mr469252ljk.58.1624315874654; Mon, 21 Jun 2021 15:51:14 -0700 (PDT) Received: from rsa-laptop.internal.lan ([217.25.229.52]) by smtp.gmail.com with ESMTPSA id x207sm124826lff.53.2021.06.21.15.51.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Jun 2021 15:51:14 -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 v2 10/10] wwan: core: add WWAN common private data for netdev Date: Tue, 22 Jun 2021 01:51:00 +0300 Message-Id: <20210621225100.21005-11-ryazanov.s.a@gmail.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210621225100.21005-1-ryazanov.s.a@gmail.com> References: <20210621225100.21005-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 bound to which WWAN device data channel. Signed-off-by: Sergey Ryazanov CC: M Chetan Kumar CC: Intel Corporation --- v1 -> v2: * fix grammar in description 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 f36ca5c0dfe9..e60e38c1f09d 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 netdev_tx_t 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 netdev_tx_t 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; @@ -367,7 +367,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; if (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 d3cb28107836..c999c64001f4 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 ef6ec641d877..3e16c318e705 100644 --- a/drivers/net/wwan/wwan_core.c +++ b/drivers/net/wwan/wwan_core.c @@ -815,6 +815,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); @@ -825,7 +826,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) { @@ -845,6 +847,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)) @@ -856,6 +859,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); @@ -889,6 +893,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 }, }; @@ -900,6 +925,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 91590db70a12..9fac819f92e3 100644 --- a/include/linux/wwan.h +++ b/include/linux/wwan.h @@ -9,6 +9,7 @@ #include #include #include +#include /** * enum wwan_port_type - WWAN port types @@ -126,6 +127,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.