From patchwork Fri Feb 1 22:06:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Fainelli X-Patchwork-Id: 10793791 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4E361922 for ; Fri, 1 Feb 2019 22:09:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D6BB33258B for ; Fri, 1 Feb 2019 22:09:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C3B4F3258A; Fri, 1 Feb 2019 22:09:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 337EC3258A for ; Fri, 1 Feb 2019 22:09:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727511AbfBAWIa (ORCPT ); Fri, 1 Feb 2019 17:08:30 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:40759 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727382AbfBAWI3 (ORCPT ); Fri, 1 Feb 2019 17:08:29 -0500 Received: by mail-pg1-f195.google.com with SMTP id z10so3556161pgp.7; Fri, 01 Feb 2019 14:08:28 -0800 (PST) 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; bh=DWtHrAlD/PuoBaMP5Yacl9yw0RDRTuKpO9kH1XLTeNg=; b=X6KzAO+3EiAaIB+E+D/zBPdFOZHti5dUNmhAUtSAhPvajk89ieumQr8YIsojKRffNT LDFoL872dhZqMyjAPq1HqlgCgbOhUTM78s9bX1QVXpLljThCsu6WiwreqHxhVBvuctPv zJ63TSJskDj2Oe1h54DEjsUqPHsT7j0QOkJfnKfWRoism9EdJ4pTNgBj+rgMZ4Aly+qz UN9HSAcGp24cWt9EM1war4touzwM2M6qawTinbAM7OfhL84XmpOINz1jTfsl2XoM9slg 1i2AzFIx9K6XVFarMw+1d3oQthfKlPfHqZZGnkmwGYaVDpnZPapCI9OADV3vWnpKUC/v S4sQ== 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; bh=DWtHrAlD/PuoBaMP5Yacl9yw0RDRTuKpO9kH1XLTeNg=; b=dVHNQQwe6FQoRjrWFeASkNvE2/5rVSRxdb1UBUUrcD0pYXb7bHL+Tdb9SGKqMEQevg p1/65KC4nNgW+hrivaV1klSE+aVjZm3czuDzaBxZ979/bxnWUEspxoR/5k+pHN8gBM5n Zhnwdig9P7ohpx6POVBK3lBKV89+wfXQlo0vmeN+xKRAHYPM+1Ih7J7Jm/QIP533BrGt Zu7e5k4Pnv7ld6yzMcybGVbhG2Et7cs3oredIe3StCG6qqru1K0zGBAvQL8LPhxrOWps SSFcGsmg30J4eojgxqPOZty2GGRpMYruzEE3k0RJWAdrTaVKzeNf/p1rk7HvVdR4nVQI w0mg== X-Gm-Message-State: AJcUukeC3RlzmJ9IiafO40AKZ1XCHZ+mh3CoFr7TqTozN/qDMed2bk1S VnZXxgBtrhTaqRLeMJWsn5iqaflf X-Google-Smtp-Source: ALg8bN7dZc8Ee/XVx2Rpmpd5JiP+yRwQ1p8ynfhNaejdlnVy9IfbNPYlt2BjbmcWLuFp6/Q68UOCsg== X-Received: by 2002:a62:c21c:: with SMTP id l28mr40722350pfg.74.1549058907164; Fri, 01 Feb 2019 14:08:27 -0800 (PST) Received: from fainelli-desktop.igp.broadcom.net ([192.19.223.250]) by smtp.gmail.com with ESMTPSA id 78sm11142208pft.184.2019.02.01.14.08.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 01 Feb 2019 14:08:26 -0800 (PST) From: Florian Fainelli To: netdev@vger.kernel.org Cc: Florian Fainelli , Michael Chan , "David S. Miller" , Derek Chickles , Satanand Burla , Felix Manlunas , Saeed Mahameed , Leon Romanovsky , Jiri Pirko , Ido Schimmel , Alexandre Belloni , Microchip Linux Driver Support , Jakub Kicinski , Ioana Radulescu , Ioana Ciornei , Greg Kroah-Hartman , Ivan Vecera , Andrew Lunn , Vivien Didelot , Dirk van der Merwe , "Francois H. Theron" , Simon Horman , Quentin Monnet , Daniel Borkmann , Eric Dumazet , John Hurley , Edwin Peer , linux-kernel@vger.kernel.org (open list), linux-rdma@vger.kernel.org (open list:MELLANOX MLX5 core VPI driver), oss-drivers@netronome.com (open list:NETRONOME ETHERNET DRIVERS), devel@driverdev.osuosl.org (open list:STAGING SUBSYSTEM) Subject: [RFC net-next 11/13] nfp: Handle SWITCHDEV_PORT_ATTR_GET event Date: Fri, 1 Feb 2019 14:06:55 -0800 Message-Id: <20190201220657.30170-12-f.fainelli@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190201220657.30170-1-f.fainelli@gmail.com> References: <20190201220657.30170-1-f.fainelli@gmail.com> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Following patches will change the way we communicate getting or setting a port's attribute and use a blocking notifier to perform those tasks. Prepare nfp to support receiving notifier events targeting SWITCHDEV_PORT_ATTR_GET and simply translate that into the existing switchdev_ops::switchdev_port_attr_get operation. We register a single blocking switchdev notifier for the entire driver instance and we differentiate a "net" from a "repr" by comparing the network device's netdev_ops with the ones that this driver manages. Signed-off-by: Florian Fainelli --- drivers/net/ethernet/netronome/nfp/nfp_main.c | 14 +++++++++++++- drivers/net/ethernet/netronome/nfp/nfp_net.h | 3 +++ .../net/ethernet/netronome/nfp/nfp_net_common.c | 17 +++++++++++++++++ drivers/net/ethernet/netronome/nfp/nfp_port.c | 15 +++++++++++++++ drivers/net/ethernet/netronome/nfp/nfp_port.h | 5 ++++- 5 files changed, 52 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/netronome/nfp/nfp_main.c b/drivers/net/ethernet/netronome/nfp/nfp_main.c index 6c10e8d119e4..50c111280cd4 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_main.c +++ b/drivers/net/ethernet/netronome/nfp/nfp_main.c @@ -17,6 +17,7 @@ #include #include #include +#include #include "nfpcore/nfp.h" #include "nfpcore/nfp_cpp.h" @@ -708,6 +709,10 @@ static void nfp_pci_remove(struct pci_dev *pdev) pci_disable_device(pdev); } +static struct notifier_block nfp_swdev_blocking_nb = { + .notifier_call = nfp_switchdev_blocking_event, +}; + static struct pci_driver nfp_pci_driver = { .name = nfp_driver_name, .id_table = nfp_pci_device_ids, @@ -725,9 +730,13 @@ static int __init nfp_main_init(void) nfp_net_debugfs_create(); + err = register_switchdev_blocking_notifier(&nfp_swdev_blocking_nb); + if (err) + goto err_destroy_debugfs; + err = pci_register_driver(&nfp_pci_driver); if (err < 0) - goto err_destroy_debugfs; + goto err_unreg_notifier; err = pci_register_driver(&nfp_netvf_pci_driver); if (err) @@ -737,6 +746,8 @@ static int __init nfp_main_init(void) err_unreg_pf: pci_unregister_driver(&nfp_pci_driver); +err_unreg_notifier: + unregister_switchdev_blocking_notifier(&nfp_swdev_blocking_nb); err_destroy_debugfs: nfp_net_debugfs_destroy(); return err; @@ -746,6 +757,7 @@ static void __exit nfp_main_exit(void) { pci_unregister_driver(&nfp_netvf_pci_driver); pci_unregister_driver(&nfp_pci_driver); + unregister_switchdev_blocking_notifier(&nfp_swdev_blocking_nb); nfp_net_debugfs_destroy(); } diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net.h b/drivers/net/ethernet/netronome/nfp/nfp_net.h index be37c2d6151c..57f7d6d634ea 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_net.h +++ b/drivers/net/ethernet/netronome/nfp/nfp_net.h @@ -915,4 +915,7 @@ static inline void nfp_net_debugfs_dir_clean(struct dentry **dir) } #endif /* CONFIG_NFP_DEBUG */ +int nfp_switchdev_blocking_event(struct notifier_block *nb, + unsigned long event, void *ptr); + #endif /* _NFP_NET_H_ */ diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_common.c b/drivers/net/ethernet/netronome/nfp/nfp_net_common.c index 7d2d4241498f..c2c5e7e3aab0 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_net_common.c +++ b/drivers/net/ethernet/netronome/nfp/nfp_net_common.c @@ -3955,3 +3955,20 @@ void nfp_net_clean(struct nfp_net *nn) unregister_netdev(nn->dp.netdev); nfp_net_reconfig_wait_posted(nn); } + +int nfp_switchdev_blocking_event(struct notifier_block *nb, + unsigned long event, void *ptr) +{ + struct net_device *dev = switchdev_notifier_info_to_dev(ptr); + + if (!nfp_netdev_is_nfp_repr(dev) && + !nfp_netdev_is_nfp_net(dev)) + return NOTIFY_DONE; + + switch (event) { + case SWITCHDEV_PORT_ATTR_GET: + return nfp_port_switchdev_attr_event(event, dev, ptr); + } + + return NOTIFY_DONE; +} diff --git a/drivers/net/ethernet/netronome/nfp/nfp_port.c b/drivers/net/ethernet/netronome/nfp/nfp_port.c index 86bc149ca231..578477242ae9 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_port.c +++ b/drivers/net/ethernet/netronome/nfp/nfp_port.c @@ -59,6 +59,21 @@ const struct switchdev_ops nfp_port_switchdev_ops = { .switchdev_port_attr_get = nfp_port_attr_get, }; +int nfp_port_switchdev_attr_event(unsigned long event, + struct net_device *netdev, + struct switchdev_notifier_port_attr_info *port_attr_info) +{ + int rc; + + if (event != SWITCHDEV_PORT_ATTR_GET) + return NOTIFY_DONE; + + rc = nfp_port_attr_get(netdev, port_attr_info->attr); + port_attr_info->handled = true; + + return notifier_from_errno(rc); +} + int nfp_port_setup_tc(struct net_device *netdev, enum tc_setup_type type, void *type_data) { diff --git a/drivers/net/ethernet/netronome/nfp/nfp_port.h b/drivers/net/ethernet/netronome/nfp/nfp_port.h index b2479a2a49e5..35342f88f715 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_port.h +++ b/drivers/net/ethernet/netronome/nfp/nfp_port.h @@ -10,6 +10,7 @@ struct net_device; struct nfp_app; struct nfp_pf; struct nfp_port; +struct switchdev_notifier_port_attr_info; /** * enum nfp_port_type - type of port NFP can switch traffic to @@ -90,7 +91,9 @@ struct nfp_port { }; extern const struct ethtool_ops nfp_port_ethtool_ops; -extern const struct switchdev_ops nfp_port_switchdev_ops; + +int nfp_port_switchdev_attr_event(unsigned long event, struct net_device *dev, + struct switchdev_notifier_port_attr_info *port_attr_info); __printf(2, 3) u8 *nfp_pr_et(u8 *data, const char *fmt, ...);