From patchwork Sun Feb 7 08:44:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Parav Pandit X-Patchwork-Id: 12072693 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=-19.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,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 EA5D0C433E0 for ; Sun, 7 Feb 2021 08:45:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9F6A364E33 for ; Sun, 7 Feb 2021 08:45:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229621AbhBGIpK (ORCPT ); Sun, 7 Feb 2021 03:45:10 -0500 Received: from hqnvemgate24.nvidia.com ([216.228.121.143]:4338 "EHLO hqnvemgate24.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229564AbhBGIpH (ORCPT ); Sun, 7 Feb 2021 03:45:07 -0500 Received: from hqmail.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate24.nvidia.com (using TLS: TLSv1.2, AES256-SHA) id ; Sun, 07 Feb 2021 00:44:26 -0800 Received: from sw-mtx-036.mtx.labs.mlnx (172.20.145.6) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Sun, 7 Feb 2021 08:44:26 +0000 From: Parav Pandit To: , , CC: Parav Pandit Subject: [PATCH net-next v2 1/7] netdevsim: Add support for add and delete of a PCI PF port Date: Sun, 7 Feb 2021 10:44:06 +0200 Message-ID: <20210207084412.252259-2-parav@nvidia.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210207084412.252259-1-parav@nvidia.com> References: <20210206125551.8616-1-parav@nvidia.com> <20210207084412.252259-1-parav@nvidia.com> MIME-Version: 1.0 X-Originating-IP: [172.20.145.6] X-ClientProxiedBy: HQMAIL111.nvidia.com (172.20.187.18) To HQMAIL107.nvidia.com (172.20.187.13) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1612687466; bh=YWsKnYvpCxidwvvyILGnK+3NUyJvl4y2nWRuLWrnDm0=; h=From:To:CC:Subject:Date:Message-ID:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:Content-Type: X-Originating-IP:X-ClientProxiedBy; b=nqeeNs4F2GPvg15i+pL01oQ/zHZBPWEEolhVFGJNQj0EMQvMF71EBZOIVjrknWKcu guNdtY3tQu59+/dGjLeH5QIyHibCEZ1B9hPGH5dd5XdRobo0xLT4dnFmWxQT+Iv7Xc hnTIBvmWKkNxnL+tNQ9SVehc/mfQyvKzxwP17Pavaj2b1Xvu2YqVdGSlIxWMFhbAxE R+iyzgLwIXgGdvrKdrl1M+UXpy5XQcVOQWCO9boLy3h+N/XDAQO+mJgymyWAT+T4Ul bjIg2sZ9mEUVezSRyaBrGyQL3dW13W7iVXVT2J0vjpXS4Vo+Kh1ZOQ3a96kLy5tCWb zQgjD4yARzGNA== Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Simulate PCI PF ports. Allow user to create one or more PCI PF ports. Examples: Create a device with ID=10 and one physical port. $ echo "10 1" > /sys/bus/netdevsim/new_device Add devlink port of flavour 'pcipf' for PF number 2: $ devlink port add netdevsim/netdevsim10 flavour pcipf pfnum 2 netdevsim/netdevsim10/4: type eth netdev eth4 flavour pcipf controller 0 pfnum 2 external false splittable false Show the PCI PF port: $ devlink port show netdevsim/netdevsim10/4 netdevsim/netdevsim10/4: type eth netdev eth4 flavour pcipf controller 0 pfnum 2 external false splittable false Delete newly added devlink port: $ devlink port del netdevsim/netdevsim10/4 issue: 2241444 Signed-off-by: Parav Pandit Reported-by: kernel test robot --- changelog: v1->v2: - fixed warning for unused err value --- drivers/net/netdevsim/Makefile | 2 +- drivers/net/netdevsim/dev.c | 10 + drivers/net/netdevsim/netdevsim.h | 20 ++ drivers/net/netdevsim/port_function.c | 340 ++++++++++++++++++++++++++ 4 files changed, 371 insertions(+), 1 deletion(-) create mode 100644 drivers/net/netdevsim/port_function.c diff --git a/drivers/net/netdevsim/Makefile b/drivers/net/netdevsim/Makefile index ade086eed955..be2aefafc498 100644 --- a/drivers/net/netdevsim/Makefile +++ b/drivers/net/netdevsim/Makefile @@ -3,7 +3,7 @@ obj-$(CONFIG_NETDEVSIM) += netdevsim.o netdevsim-objs := \ - netdev.o dev.o ethtool.o fib.o bus.o health.o udp_tunnels.o + netdev.o dev.o ethtool.o fib.o bus.o health.o udp_tunnels.o port_function.o ifeq ($(CONFIG_BPF_SYSCALL),y) netdevsim-objs += \ diff --git a/drivers/net/netdevsim/dev.c b/drivers/net/netdevsim/dev.c index 816af1f55e2c..806e387918fe 100644 --- a/drivers/net/netdevsim/dev.c +++ b/drivers/net/netdevsim/dev.c @@ -905,6 +905,8 @@ static const struct devlink_ops nsim_dev_devlink_ops = { .trap_group_set = nsim_dev_devlink_trap_group_set, .trap_policer_set = nsim_dev_devlink_trap_policer_set, .trap_policer_counter_get = nsim_dev_devlink_trap_policer_counter_get, + .port_new = nsim_dev_devlink_port_new, + .port_del = nsim_dev_devlink_port_del, }; #define NSIM_DEV_MAX_MACS_DEFAULT 32 @@ -1039,6 +1041,8 @@ static int nsim_dev_reload_create(struct nsim_dev *nsim_dev, nsim_dev->ddir, nsim_dev, &nsim_dev_take_snapshot_fops); + + nsim_dev_port_fn_enable(nsim_dev); return 0; err_health_exit: @@ -1073,6 +1077,7 @@ int nsim_dev_probe(struct nsim_bus_dev *nsim_bus_dev) nsim_dev->max_macs = NSIM_DEV_MAX_MACS_DEFAULT; nsim_dev->test1 = NSIM_DEV_TEST1_DEFAULT; spin_lock_init(&nsim_dev->fa_cookie_lock); + nsim_dev_port_fn_init(nsim_dev); dev_set_drvdata(&nsim_bus_dev->dev, nsim_dev); @@ -1120,6 +1125,7 @@ int nsim_dev_probe(struct nsim_bus_dev *nsim_bus_dev) if (err) goto err_bpf_dev_exit; + nsim_dev_port_fn_enable(nsim_dev); devlink_params_publish(devlink); devlink_reload_enable(devlink); return 0; @@ -1154,6 +1160,9 @@ static void nsim_dev_reload_destroy(struct nsim_dev *nsim_dev) if (devlink_is_reload_failed(devlink)) return; + + /* Disable and destroy any user created devlink ports */ + nsim_dev_port_fn_disable(nsim_dev); debugfs_remove(nsim_dev->take_snapshot); nsim_dev_port_del_all(nsim_dev); nsim_dev_health_exit(nsim_dev); @@ -1178,6 +1187,7 @@ void nsim_dev_remove(struct nsim_bus_dev *nsim_bus_dev) ARRAY_SIZE(nsim_devlink_params)); devlink_unregister(devlink); devlink_resources_unregister(devlink, NULL); + nsim_dev_port_fn_exit(nsim_dev); devlink_free(devlink); } diff --git a/drivers/net/netdevsim/netdevsim.h b/drivers/net/netdevsim/netdevsim.h index 48163c5f2ec9..31beddede0f2 100644 --- a/drivers/net/netdevsim/netdevsim.h +++ b/drivers/net/netdevsim/netdevsim.h @@ -229,6 +229,15 @@ struct nsim_dev { bool static_iana_vxlan; u32 sleep; } udp_ports; + struct { + struct list_head head; + struct ida ida; + struct ida pfnum_ida; + struct mutex disable_mutex; /* protects port deletion + * by driver unload context + */ + bool enabled; + } port_functions; }; static inline struct net *nsim_dev_net(struct nsim_dev *nsim_dev) @@ -299,3 +308,14 @@ struct nsim_bus_dev { int nsim_bus_init(void); void nsim_bus_exit(void); + +void nsim_dev_port_fn_init(struct nsim_dev *nsim_dev); +void nsim_dev_port_fn_exit(struct nsim_dev *nsim_dev); +void nsim_dev_port_fn_enable(struct nsim_dev *nsim_dev); +void nsim_dev_port_fn_disable(struct nsim_dev *nsim_dev); +int nsim_dev_devlink_port_new(struct devlink *devlink, + const struct devlink_port_new_attrs *attrs, + struct netlink_ext_ack *extack, + unsigned int *new_port_index); +int nsim_dev_devlink_port_del(struct devlink *devlink, unsigned int port_index, + struct netlink_ext_ack *extack); diff --git a/drivers/net/netdevsim/port_function.c b/drivers/net/netdevsim/port_function.c new file mode 100644 index 000000000000..7df1ca5ad7b8 --- /dev/null +++ b/drivers/net/netdevsim/port_function.c @@ -0,0 +1,340 @@ +// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB +/* Copyright (c) 2020 Mellanox Technologies Ltd. */ + +#include +#include + +#include "netdevsim.h" + +struct nsim_port_fn { + struct devlink_port dl_port; + struct net_device *netdev; + struct list_head list; + unsigned int port_index; + enum devlink_port_flavour flavour; + u16 pfnum; +}; + +static struct devlink_port * +nsim_dev_port_fn_get_devlink_port(struct net_device *dev) +{ + struct nsim_port_fn *port = netdev_priv(dev); + + return &port->dl_port; +} + +static netdev_tx_t +nsim_dev_port_fn_start_xmit(struct sk_buff *skb, struct net_device *dev) +{ + dev_kfree_skb(skb); + return NETDEV_TX_OK; +} + +static const struct net_device_ops nsim_netdev_ops = { + .ndo_start_xmit = nsim_dev_port_fn_start_xmit, + .ndo_get_devlink_port = nsim_dev_port_fn_get_devlink_port, +}; + +static void nsim_port_fn_ndev_setup(struct net_device *dev) +{ + ether_setup(dev); + eth_hw_addr_random(dev); + + dev->tx_queue_len = 0; + dev->flags |= IFF_NOARP; + dev->flags &= ~IFF_MULTICAST; + dev->max_mtu = ETH_MAX_MTU; +} + +static struct nsim_port_fn * +nsim_devlink_port_fn_alloc(struct nsim_dev *dev, + const struct devlink_port_new_attrs *attrs) +{ + struct nsim_bus_dev *nsim_bus_dev = dev->nsim_bus_dev; + struct nsim_port_fn *port; + struct net_device *netdev; + int ret; + + netdev = alloc_netdev(sizeof(*port), "eth%d", NET_NAME_UNKNOWN, + nsim_port_fn_ndev_setup); + if (!netdev) + return ERR_PTR(-ENOMEM); + + dev_net_set(netdev, nsim_dev_net(dev)); + netdev->netdev_ops = &nsim_netdev_ops; + nsim_bus_dev = dev->nsim_bus_dev; + SET_NETDEV_DEV(netdev, &nsim_bus_dev->dev); + + port = netdev_priv(netdev); + memset(port, 0, sizeof(*port)); + port->netdev = netdev; + port->flavour = attrs->flavour; + + if (attrs->port_index_valid) + ret = ida_alloc_range(&dev->port_functions.ida, + attrs->port_index, + attrs->port_index, GFP_KERNEL); + else + ret = ida_alloc_min(&dev->port_functions.ida, + nsim_bus_dev->port_count, GFP_KERNEL); + if (ret < 0) + goto port_ida_err; + + port->port_index = ret; + + switch (port->flavour) { + case DEVLINK_PORT_FLAVOUR_PCI_PF: + ret = ida_alloc_range(&dev->port_functions.pfnum_ida, + attrs->pfnum, attrs->pfnum, + GFP_KERNEL); + if (ret < 0) + goto fn_ida_err; + port->pfnum = ret; + break; + default: + break; + } + return port; + +fn_ida_err: + ida_simple_remove(&dev->port_functions.ida, port->port_index); +port_ida_err: + free_netdev(netdev); + return ERR_PTR(ret); +} + +static void +nsim_devlink_port_fn_free(struct nsim_dev *dev, struct nsim_port_fn *port) +{ + switch (port->flavour) { + case DEVLINK_PORT_FLAVOUR_PCI_PF: + ida_simple_remove(&dev->port_functions.pfnum_ida, port->pfnum); + break; + default: + break; + } + ida_simple_remove(&dev->port_functions.ida, port->port_index); + free_netdev(port->netdev); +} + +static bool +nsim_dev_port_index_internal(struct nsim_dev *nsim_dev, unsigned int port_index) +{ + struct nsim_bus_dev *nsim_bus_dev = nsim_dev->nsim_bus_dev; + + return (port_index < nsim_bus_dev->port_count) ? true : false; +} + +static bool +nsim_dev_port_port_exists(struct nsim_dev *nsim_dev, + const struct devlink_port_new_attrs *attrs) +{ + struct nsim_port_fn *tmp; + + list_for_each_entry(tmp, &nsim_dev->port_functions.head, list) { + if (attrs->port_index_valid && + tmp->port_index == attrs->port_index) + return true; + if (attrs->flavour == DEVLINK_PORT_FLAVOUR_PCI_PF && + tmp->flavour == DEVLINK_PORT_FLAVOUR_PCI_PF && + tmp->pfnum == attrs->pfnum) + return true; + } + return false; +} + +static struct nsim_port_fn * +nsim_dev_devlink_port_index_lookup(const struct nsim_dev *nsim_dev, + unsigned int port_index, + struct netlink_ext_ack *extack) +{ + struct nsim_port_fn *port; + + list_for_each_entry(port, &nsim_dev->port_functions.head, list) { + if (port->port_index != port_index) + continue; + return port; + } + NL_SET_ERR_MSG_MOD(extack, "User created port not found"); + return ERR_PTR(-ENOENT); +} + +static int nsim_devlink_port_fn_add(struct devlink *devlink, + struct nsim_dev *nsim_dev, + struct nsim_port_fn *port, + struct netlink_ext_ack *extack) +{ + int err; + + list_add(&port->list, &nsim_dev->port_functions.head); + + err = devlink_port_register(devlink, &port->dl_port, port->port_index); + if (err) + goto reg_err; + + err = register_netdev(port->netdev); + if (err) + goto netdev_err; + + devlink_port_type_eth_set(&port->dl_port, port->netdev); + return 0; + +netdev_err: + devlink_port_type_clear(&port->dl_port); + devlink_port_unregister(&port->dl_port); +reg_err: + list_del(&port->list); + return err; +} + +static void nsim_devlink_port_fn_del(struct nsim_dev *nsim_dev, + struct nsim_port_fn *port) +{ + devlink_port_type_clear(&port->dl_port); + unregister_netdev(port->netdev); + devlink_port_unregister(&port->dl_port); + list_del(&port->list); +} + +static bool +nsim_dev_port_flavour_supported(const struct nsim_dev *nsim_dev, + const struct devlink_port_new_attrs *attrs) +{ + return attrs->flavour == DEVLINK_PORT_FLAVOUR_PCI_PF; +} + +int nsim_dev_devlink_port_new(struct devlink *devlink, + const struct devlink_port_new_attrs *attrs, + struct netlink_ext_ack *extack, + unsigned int *new_port_index) +{ + struct nsim_dev *nsim_dev = devlink_priv(devlink); + struct nsim_bus_dev *nsim_bus_dev; + struct nsim_port_fn *port; + int err; + + nsim_bus_dev = nsim_dev->nsim_bus_dev; + if (attrs->port_index_valid && + attrs->port_index < nsim_bus_dev->port_count) { + NL_SET_ERR_MSG_MOD(extack, + "Port with given port index already exist"); + return -EEXIST; + } + if (!nsim_dev_port_flavour_supported(nsim_dev, attrs)) { + NL_SET_ERR_MSG_MOD(extack, "Unsupported port flavour specified"); + return -EOPNOTSUPP; + } + mutex_lock(&nsim_dev->port_functions.disable_mutex); + if (!nsim_dev->port_functions.enabled) { + err = -ENODEV; + goto alloc_err; + } + if (nsim_dev_port_port_exists(nsim_dev, attrs)) { + NL_SET_ERR_MSG_MOD(extack, + "Port with given attributes already exists"); + err = -EEXIST; + goto alloc_err; + } + port = nsim_devlink_port_fn_alloc(nsim_dev, attrs); + if (IS_ERR(port)) { + NL_SET_ERR_MSG_MOD(extack, "Fail to allocate port"); + err = PTR_ERR(port); + goto alloc_err; + } + memcpy(port->dl_port.attrs.switch_id.id, nsim_dev->switch_id.id, + nsim_dev->switch_id.id_len); + port->dl_port.attrs.switch_id.id_len = nsim_dev->switch_id.id_len; + + devlink_port_attrs_pci_pf_set(&port->dl_port, 0, port->pfnum, false); + + err = nsim_devlink_port_fn_add(devlink, nsim_dev, port, extack); + if (err) + goto add_err; + *new_port_index = port->port_index; + mutex_unlock(&nsim_dev->port_functions.disable_mutex); + return 0; + +add_err: + nsim_devlink_port_fn_free(nsim_dev, port); +alloc_err: + mutex_unlock(&nsim_dev->port_functions.disable_mutex); + return err; +} + +int nsim_dev_devlink_port_del(struct devlink *devlink, unsigned int port_index, + struct netlink_ext_ack *extack) +{ + struct nsim_dev *nsim_dev = devlink_priv(devlink); + struct nsim_port_fn *port; + int err; + + if (nsim_dev_port_index_internal(nsim_dev, port_index)) { + NL_SET_ERR_MSG_MOD(extack, "Port index doesn't belong to user created port"); + return -EINVAL; + } + + mutex_lock(&nsim_dev->port_functions.disable_mutex); + if (!nsim_dev->port_functions.enabled) { + err = -ENODEV; + goto err; + } + + port = nsim_dev_devlink_port_index_lookup(nsim_dev, port_index, extack); + if (IS_ERR(port)) { + err = PTR_ERR(port); + goto err; + } + nsim_devlink_port_fn_del(nsim_dev, port); + nsim_devlink_port_fn_free(nsim_dev, port); + mutex_unlock(&nsim_dev->port_functions.disable_mutex); + return 0; + +err: + mutex_unlock(&nsim_dev->port_functions.disable_mutex); + return err; +} + +void nsim_dev_port_fn_init(struct nsim_dev *nsim_dev) +{ + mutex_init(&nsim_dev->port_functions.disable_mutex); + INIT_LIST_HEAD(&nsim_dev->port_functions.head); + ida_init(&nsim_dev->port_functions.ida); + ida_init(&nsim_dev->port_functions.pfnum_ida); +} + +void nsim_dev_port_fn_exit(struct nsim_dev *nsim_dev) +{ + WARN_ON(!ida_is_empty(&nsim_dev->port_functions.pfnum_ida)); + ida_destroy(&nsim_dev->port_functions.pfnum_ida); + WARN_ON(!ida_is_empty(&nsim_dev->port_functions.ida)); + ida_destroy(&nsim_dev->port_functions.ida); + WARN_ON(!list_empty(&nsim_dev->port_functions.head)); + mutex_destroy(&nsim_dev->port_functions.disable_mutex); +} + +void nsim_dev_port_fn_enable(struct nsim_dev *nsim_dev) +{ + mutex_lock(&nsim_dev->port_functions.disable_mutex); + nsim_dev->port_functions.enabled = true; + mutex_unlock(&nsim_dev->port_functions.disable_mutex); +} + +void nsim_dev_port_fn_disable(struct nsim_dev *nsim_dev) +{ + struct nsim_port_fn *port; + struct nsim_port_fn *tmp; + + mutex_lock(&nsim_dev->port_functions.disable_mutex); + nsim_dev->port_functions.enabled = false; + mutex_unlock(&nsim_dev->port_functions.disable_mutex); + + /* At this point, no new user commands can start and any ongoing + * commands have completed, so it is safe to delete all user created + * ports. + */ + list_for_each_entry_safe_reverse(port, tmp, + &nsim_dev->port_functions.head, list) { + nsim_devlink_port_fn_del(nsim_dev, port); + nsim_devlink_port_fn_free(nsim_dev, port); + } +} From patchwork Sun Feb 7 08:44:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Parav Pandit X-Patchwork-Id: 12072699 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=-19.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,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 039AFC433E6 for ; Sun, 7 Feb 2021 08:45:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C188364E88 for ; Sun, 7 Feb 2021 08:45:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229636AbhBGIpN (ORCPT ); Sun, 7 Feb 2021 03:45:13 -0500 Received: from hqnvemgate24.nvidia.com ([216.228.121.143]:4341 "EHLO hqnvemgate24.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229506AbhBGIpH (ORCPT ); Sun, 7 Feb 2021 03:45:07 -0500 Received: from hqmail.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate24.nvidia.com (using TLS: TLSv1.2, AES256-SHA) id ; Sun, 07 Feb 2021 00:44:27 -0800 Received: from sw-mtx-036.mtx.labs.mlnx (172.20.145.6) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Sun, 7 Feb 2021 08:44:26 +0000 From: Parav Pandit To: , , CC: Parav Pandit , Jiri Pirko Subject: [PATCH net-next v2 2/7] netdevsim: Add support for add and delete PCI SF port Date: Sun, 7 Feb 2021 10:44:07 +0200 Message-ID: <20210207084412.252259-3-parav@nvidia.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210207084412.252259-1-parav@nvidia.com> References: <20210206125551.8616-1-parav@nvidia.com> <20210207084412.252259-1-parav@nvidia.com> MIME-Version: 1.0 X-Originating-IP: [172.20.145.6] X-ClientProxiedBy: HQMAIL111.nvidia.com (172.20.187.18) To HQMAIL107.nvidia.com (172.20.187.13) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1612687467; bh=USk+Ai2bvGhKmgDS3Of7pY4LSQ7WbOaICHX6RrCXhN8=; h=From:To:CC:Subject:Date:Message-ID:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:Content-Type: X-Originating-IP:X-ClientProxiedBy; b=NQTMXLii1gqAXYDY8ELIJFk75trjOuo6+HjwbfCDrD3j5g4omf9sGlLHXZs7uJ0hh 4YpcGgsfCky5C1LEtllMAFnjAYwZ3EmRjlGkqY2kGQdGod8/+m0wV4bSXpaA4MxdVV 0ahe5cEtcyLIg0EBy+uMPEuvTQx49lxw7ofldHc54Hl7qvhBX78whrsxHqBp/3X/3O 0BOJH1Qcu91LoTyqbuAOKyOu8bzc3B2Fz5nPdxUab3paxWOFST6O4OhbQgq72U3ZMm cfw3Rt4ejy2LrAH8ePfYpwBf+CbaeK5XnFg4Ap8C+CZSze1e9z1t8nCzXyA9kNe++c VxdmSmP3qQoIA== Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Simulate PCI SF ports. Allow user to create one or more PCI SF ports. Examples: echo "10 1" > /sys/bus/netdevsim/new_device Add PCI PF port: $ devlink port add netdevsim/netdevsim10 flavour pcipf pfnum 2 netdevsim/netdevsim10/1: type eth netdev eth1 flavour pcipf controller 0 pfnum 2 external false splittable false Add PCI SF port where port index and sfnum are auto assigned by driver. $ devlink port add netdevsim/netdevsim10 flavour pcisf pfnum 2 netdevsim/netdevsim10/2: type eth netdev eth2 flavour pcisf controller 0 pfnum 2 sfnum 0 splittable false Show devlink ports: $ devlink port show netdevsim/netdevsim10/0: type eth netdev eth0 flavour physical port 1 splittable false netdevsim/netdevsim10/1: type eth netdev eth1 flavour pcipf controller 0 pfnum 2 external false splittable false netdevsim/netdevsim10/2: type eth netdev eth2 flavour pcisf controller 0 pfnum 2 sfnum 0 splittable false Create a PCI SF port whose port index and SF number are assigned by the user. $ devlink port add netdevsim/netdevsim10/66 flavour pcisf pfnum 2 sfnum 66 netdevsim/netdevsim10/66: type eth netdev eth3 flavour pcisf controller 0 pfnum 2 sfnum 66 splittable false Delete PCI SF and PF ports: $ devlink port del netdevsim/netdevsim10/66 $ devlink port del netdevsim/netdevsim10/2 $ devlink port del netdevsim/netdevsim10/1 Signed-off-by: Parav Pandit Reviewed-by: Jiri Pirko Reported-by: kernel test robot --- drivers/net/netdevsim/netdevsim.h | 1 + drivers/net/netdevsim/port_function.c | 99 ++++++++++++++++++++++++++- 2 files changed, 97 insertions(+), 3 deletions(-) diff --git a/drivers/net/netdevsim/netdevsim.h b/drivers/net/netdevsim/netdevsim.h index 31beddede0f2..efa7c08d842a 100644 --- a/drivers/net/netdevsim/netdevsim.h +++ b/drivers/net/netdevsim/netdevsim.h @@ -233,6 +233,7 @@ struct nsim_dev { struct list_head head; struct ida ida; struct ida pfnum_ida; + struct ida sfnum_ida; struct mutex disable_mutex; /* protects port deletion * by driver unload context */ diff --git a/drivers/net/netdevsim/port_function.c b/drivers/net/netdevsim/port_function.c index 7df1ca5ad7b8..86607d574930 100644 --- a/drivers/net/netdevsim/port_function.c +++ b/drivers/net/netdevsim/port_function.c @@ -9,9 +9,12 @@ struct nsim_port_fn { struct devlink_port dl_port; struct net_device *netdev; + struct nsim_port_fn *pf_pfn; struct list_head list; unsigned int port_index; enum devlink_port_flavour flavour; + int refcount; /* Counts how many sf ports are bound attached to this pf port. */ + u32 sfnum; u16 pfnum; }; @@ -91,9 +94,24 @@ nsim_devlink_port_fn_alloc(struct nsim_dev *dev, goto fn_ida_err; port->pfnum = ret; break; + case DEVLINK_PORT_FLAVOUR_PCI_SF: + if (attrs->sfnum_valid) + ret = ida_alloc_range(&dev->port_functions.sfnum_ida, attrs->sfnum, + attrs->sfnum, GFP_KERNEL); + else + ret = ida_alloc(&dev->port_functions.sfnum_ida, GFP_KERNEL); + if (ret < 0) + goto fn_ida_err; + port->sfnum = ret; + port->pfnum = attrs->pfnum; + break; default: break; } + /* refcount_t is not needed as port is protected by port_functions.mutex. + * This count is to keep track of how many SF ports are attached a PF port. + */ + port->refcount = 1; return port; fn_ida_err: @@ -110,6 +128,9 @@ nsim_devlink_port_fn_free(struct nsim_dev *dev, struct nsim_port_fn *port) case DEVLINK_PORT_FLAVOUR_PCI_PF: ida_simple_remove(&dev->port_functions.pfnum_ida, port->pfnum); break; + case DEVLINK_PORT_FLAVOUR_PCI_SF: + ida_simple_remove(&dev->port_functions.sfnum_ida, port->sfnum); + break; default: break; } @@ -139,6 +160,12 @@ nsim_dev_port_port_exists(struct nsim_dev *nsim_dev, tmp->flavour == DEVLINK_PORT_FLAVOUR_PCI_PF && tmp->pfnum == attrs->pfnum) return true; + + if (attrs->flavour == DEVLINK_PORT_FLAVOUR_PCI_SF && + tmp->flavour == DEVLINK_PORT_FLAVOUR_PCI_SF && + attrs->sfnum_valid && + tmp->sfnum == attrs->sfnum && tmp->pfnum == attrs->pfnum) + return true; } return false; } @@ -153,20 +180,72 @@ nsim_dev_devlink_port_index_lookup(const struct nsim_dev *nsim_dev, list_for_each_entry(port, &nsim_dev->port_functions.head, list) { if (port->port_index != port_index) continue; + if (port->refcount > 1) { + NL_SET_ERR_MSG_MOD(extack, "Port is in use"); + return ERR_PTR(-EBUSY); + } return port; } NL_SET_ERR_MSG_MOD(extack, "User created port not found"); return ERR_PTR(-ENOENT); } +static struct nsim_port_fn * +pf_port_get(struct nsim_dev *nsim_dev, struct nsim_port_fn *port) +{ + struct nsim_port_fn *tmp; + + /* PF port addition doesn't need a parent. */ + if (port->flavour == DEVLINK_PORT_FLAVOUR_PCI_PF) + return NULL; + + list_for_each_entry(tmp, &nsim_dev->port_functions.head, list) { + if (tmp->flavour != DEVLINK_PORT_FLAVOUR_PCI_PF || + tmp->pfnum != port->pfnum) + continue; + + if (tmp->refcount + 1 == INT_MAX) + return ERR_PTR(-ENOSPC); + + port->pf_pfn = tmp; + tmp->refcount++; + return tmp; + } + return ERR_PTR(-ENOENT); +} + +static void pf_port_put(struct nsim_port_fn *port) +{ + if (port->pf_pfn) { + port->pf_pfn->refcount--; + WARN_ON(port->pf_pfn->refcount < 0); + } + port->refcount--; + WARN_ON(port->refcount != 0); +} + static int nsim_devlink_port_fn_add(struct devlink *devlink, struct nsim_dev *nsim_dev, struct nsim_port_fn *port, struct netlink_ext_ack *extack) { + struct nsim_port_fn *pf_pfn; int err; - list_add(&port->list, &nsim_dev->port_functions.head); + /* Keep all PF ports at the start, so that when driver is unloaded + * All SF ports from the end of the list can be removed first. + */ + if (port->flavour == DEVLINK_PORT_FLAVOUR_PCI_PF) + list_add(&port->list, &nsim_dev->port_functions.head); + else + list_add_tail(&port->list, &nsim_dev->port_functions.head); + + pf_pfn = pf_port_get(nsim_dev, port); + if (IS_ERR(pf_pfn)) { + NL_SET_ERR_MSG_MOD(extack, "Fail to get pf port"); + err = PTR_ERR(pf_pfn); + goto pf_err; + } err = devlink_port_register(devlink, &port->dl_port, port->port_index); if (err) @@ -183,6 +262,8 @@ static int nsim_devlink_port_fn_add(struct devlink *devlink, devlink_port_type_clear(&port->dl_port); devlink_port_unregister(&port->dl_port); reg_err: + pf_port_put(port); +pf_err: list_del(&port->list); return err; } @@ -194,13 +275,15 @@ static void nsim_devlink_port_fn_del(struct nsim_dev *nsim_dev, unregister_netdev(port->netdev); devlink_port_unregister(&port->dl_port); list_del(&port->list); + pf_port_put(port); } static bool nsim_dev_port_flavour_supported(const struct nsim_dev *nsim_dev, const struct devlink_port_new_attrs *attrs) { - return attrs->flavour == DEVLINK_PORT_FLAVOUR_PCI_PF; + return attrs->flavour == DEVLINK_PORT_FLAVOUR_PCI_PF || + attrs->flavour == DEVLINK_PORT_FLAVOUR_PCI_SF; } int nsim_dev_devlink_port_new(struct devlink *devlink, @@ -245,7 +328,12 @@ int nsim_dev_devlink_port_new(struct devlink *devlink, nsim_dev->switch_id.id_len); port->dl_port.attrs.switch_id.id_len = nsim_dev->switch_id.id_len; - devlink_port_attrs_pci_pf_set(&port->dl_port, 0, port->pfnum, false); + if (attrs->flavour == DEVLINK_PORT_FLAVOUR_PCI_PF) + devlink_port_attrs_pci_pf_set(&port->dl_port, 0, + port->pfnum, false); + else + devlink_port_attrs_pci_sf_set(&port->dl_port, 0, port->pfnum, + port->sfnum); err = nsim_devlink_port_fn_add(devlink, nsim_dev, port, extack); if (err) @@ -300,10 +388,13 @@ void nsim_dev_port_fn_init(struct nsim_dev *nsim_dev) INIT_LIST_HEAD(&nsim_dev->port_functions.head); ida_init(&nsim_dev->port_functions.ida); ida_init(&nsim_dev->port_functions.pfnum_ida); + ida_init(&nsim_dev->port_functions.sfnum_ida); } void nsim_dev_port_fn_exit(struct nsim_dev *nsim_dev) { + WARN_ON(!ida_is_empty(&nsim_dev->port_functions.sfnum_ida)); + ida_destroy(&nsim_dev->port_functions.sfnum_ida); WARN_ON(!ida_is_empty(&nsim_dev->port_functions.pfnum_ida)); ida_destroy(&nsim_dev->port_functions.pfnum_ida); WARN_ON(!ida_is_empty(&nsim_dev->port_functions.ida)); @@ -332,6 +423,8 @@ void nsim_dev_port_fn_disable(struct nsim_dev *nsim_dev) * commands have completed, so it is safe to delete all user created * ports. */ + + /* Remove SF ports first, followed by PF ports. */ list_for_each_entry_safe_reverse(port, tmp, &nsim_dev->port_functions.head, list) { nsim_devlink_port_fn_del(nsim_dev, port); From patchwork Sun Feb 7 08:44:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Parav Pandit X-Patchwork-Id: 12072695 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=-19.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,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 16783C43381 for ; Sun, 7 Feb 2021 08:45:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D7EAB64EA7 for ; Sun, 7 Feb 2021 08:45:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229669AbhBGIpP (ORCPT ); Sun, 7 Feb 2021 03:45:15 -0500 Received: from hqnvemgate26.nvidia.com ([216.228.121.65]:2843 "EHLO hqnvemgate26.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229581AbhBGIpI (ORCPT ); Sun, 7 Feb 2021 03:45:08 -0500 Received: from hqmail.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate26.nvidia.com (using TLS: TLSv1.2, AES256-SHA) id ; Sun, 07 Feb 2021 00:44:28 -0800 Received: from sw-mtx-036.mtx.labs.mlnx (172.20.145.6) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Sun, 7 Feb 2021 08:44:27 +0000 From: Parav Pandit To: , , CC: Parav Pandit Subject: [PATCH net-next v2 3/7] netdevsim: Simulate get hardware address of a PCI port Date: Sun, 7 Feb 2021 10:44:08 +0200 Message-ID: <20210207084412.252259-4-parav@nvidia.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210207084412.252259-1-parav@nvidia.com> References: <20210206125551.8616-1-parav@nvidia.com> <20210207084412.252259-1-parav@nvidia.com> MIME-Version: 1.0 X-Originating-IP: [172.20.145.6] X-ClientProxiedBy: HQMAIL111.nvidia.com (172.20.187.18) To HQMAIL107.nvidia.com (172.20.187.13) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1612687468; bh=mH3pMqgVGdMcGe+Ta7PrYlOYFc3VnRFvayqJLOv+XJs=; h=From:To:CC:Subject:Date:Message-ID:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:Content-Type: X-Originating-IP:X-ClientProxiedBy; b=ViiugQPCxqlvEc02BhLevtG8ADrZSxUildcLZhxYBLxJu/jZM4BO/1hn4q3uYCtq3 f8scJ+e4FyL4gbr464dzNaIhO/Pk8I85+69nuRUeq6y3SNpbk+z6gZLwwmE8ZzF8uB X8gkpTLOSlhOjfTyEtNThODePwpb8BFJJA7phXxQZhDxw9WwM7gB8hUwYiHZfG4waB /ZsN9CYXOyEA6/WpRkAnWzW6nrQoIeOfGAitZjt/YibfzyiS2wJcmi/v2PnS/jsZC8 ZkjS/qbtkvbTpjf5tFC8WtwRzPfsVm3m6CAsA2Dnp0AijcK6bN6xy+CJeIveQ8X1gV Q2jjCWQjtEL2w== Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Allow users to get hardware address for the PCI port. Below example creates one devlink port, queries a port and its hardware address. Example of a PCI SF port which supports a port function hw_addr set: Create a device with ID=10 and one physical port. $ echo "10 1" > /sys/bus/netdevsim/new_device Add PCI PF port: $ devlink port add netdevsim/netdevsim10 flavour pcipf pfnum 2 netdevsim/netdevsim10/1: type eth netdev eth1 flavour pcipf controller 0 pfnum 2 external false splittable false function: hw_addr 00:00:00:00:00:00 $ devlink port add netdevsim/netdevsim10 flavour pcisf pfnum 2 netdevsim/netdevsim10/2: type eth netdev eth2 flavour pcisf controller 0 pfnum 2 sfnum 0 splittable false function: hw_addr 00:00:00:00:00:00 Show devlink ports: $ devlink port show netdevsim/netdevsim10/0: type eth netdev eth0 flavour physical port 1 splittable false netdevsim/netdevsim10/1: type eth netdev eth1 flavour pcipf controller 0 pfnum 2 external false splittable false function: hw_addr 00:00:00:00:00:00 netdevsim/netdevsim10/2: type eth netdev eth2 flavour pcisf controller 0 pfnum 2 sfnum 0 splittable false function: hw_addr 00:00:00:00:00:00 Show the port and function attributes in JSON format: $ devlink port show netdevsim/netdevsim10/2 -jp { "port": { "netdevsim/netdevsim10/2": { "type": "eth", "netdev": "eth2", "flavour": "pcisf", "controller": 0, "pfnum": 2, "sfnum": 0, "splittable": false, "function": { "hw_addr": "00:00:00:00:00:00" } } } } Signed-off-by: Parav Pandit --- drivers/net/netdevsim/dev.c | 1 + drivers/net/netdevsim/netdevsim.h | 4 ++++ drivers/net/netdevsim/port_function.c | 30 +++++++++++++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/drivers/net/netdevsim/dev.c b/drivers/net/netdevsim/dev.c index 806e387918fe..6046906d6b85 100644 --- a/drivers/net/netdevsim/dev.c +++ b/drivers/net/netdevsim/dev.c @@ -907,6 +907,7 @@ static const struct devlink_ops nsim_dev_devlink_ops = { .trap_policer_counter_get = nsim_dev_devlink_trap_policer_counter_get, .port_new = nsim_dev_devlink_port_new, .port_del = nsim_dev_devlink_port_del, + .port_function_hw_addr_get = nsim_dev_port_fn_hw_addr_get, }; #define NSIM_DEV_MAX_MACS_DEFAULT 32 diff --git a/drivers/net/netdevsim/netdevsim.h b/drivers/net/netdevsim/netdevsim.h index efa7c08d842a..e910c3cf480d 100644 --- a/drivers/net/netdevsim/netdevsim.h +++ b/drivers/net/netdevsim/netdevsim.h @@ -320,3 +320,7 @@ int nsim_dev_devlink_port_new(struct devlink *devlink, unsigned int *new_port_index); int nsim_dev_devlink_port_del(struct devlink *devlink, unsigned int port_index, struct netlink_ext_ack *extack); +int nsim_dev_port_fn_hw_addr_get(struct devlink *devlink, + struct devlink_port *port, + u8 *hw_addr, int *hw_addr_len, + struct netlink_ext_ack *extack); diff --git a/drivers/net/netdevsim/port_function.c b/drivers/net/netdevsim/port_function.c index 86607d574930..882d1bdbfcf5 100644 --- a/drivers/net/netdevsim/port_function.c +++ b/drivers/net/netdevsim/port_function.c @@ -16,6 +16,7 @@ struct nsim_port_fn { int refcount; /* Counts how many sf ports are bound attached to this pf port. */ u32 sfnum; u16 pfnum; + u8 hw_addr[ETH_ALEN]; }; static struct devlink_port * @@ -431,3 +432,32 @@ void nsim_dev_port_fn_disable(struct nsim_dev *nsim_dev) nsim_devlink_port_fn_free(nsim_dev, port); } } + +static struct nsim_port_fn * +nsim_dev_to_port_fn(struct nsim_dev *nsim_dev, struct devlink_port *dl_port, + struct netlink_ext_ack *extack) +{ + if (nsim_dev_port_index_internal(nsim_dev, dl_port->index)) { + NL_SET_ERR_MSG_MOD(extack, + "Port index doesn't belong to user created port"); + return ERR_PTR(-EOPNOTSUPP); + } + return container_of(dl_port, struct nsim_port_fn, dl_port); +} + +int nsim_dev_port_fn_hw_addr_get(struct devlink *devlink, + struct devlink_port *dl_port, + u8 *hw_addr, int *hw_addr_len, + struct netlink_ext_ack *extack) +{ + struct nsim_dev *nsim_dev = devlink_priv(devlink); + struct nsim_port_fn *port; + + port = nsim_dev_to_port_fn(nsim_dev, dl_port, extack); + if (IS_ERR(port)) + return PTR_ERR(port); + + memcpy(hw_addr, port->hw_addr, ETH_ALEN); + *hw_addr_len = ETH_ALEN; + return 0; +} From patchwork Sun Feb 7 08:44:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Parav Pandit X-Patchwork-Id: 12072697 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=-19.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,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 2E239C433E9 for ; Sun, 7 Feb 2021 08:45:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0013664E33 for ; Sun, 7 Feb 2021 08:45:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229693AbhBGIpV (ORCPT ); Sun, 7 Feb 2021 03:45:21 -0500 Received: from hqnvemgate24.nvidia.com ([216.228.121.143]:4343 "EHLO hqnvemgate24.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229587AbhBGIpJ (ORCPT ); Sun, 7 Feb 2021 03:45:09 -0500 Received: from hqmail.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate24.nvidia.com (using TLS: TLSv1.2, AES256-SHA) id ; Sun, 07 Feb 2021 00:44:28 -0800 Received: from sw-mtx-036.mtx.labs.mlnx (172.20.145.6) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Sun, 7 Feb 2021 08:44:28 +0000 From: Parav Pandit To: , , CC: Parav Pandit Subject: [PATCH net-next v2 4/7] netdevsim: Simulate set hardware address of a PCI port Date: Sun, 7 Feb 2021 10:44:09 +0200 Message-ID: <20210207084412.252259-5-parav@nvidia.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210207084412.252259-1-parav@nvidia.com> References: <20210206125551.8616-1-parav@nvidia.com> <20210207084412.252259-1-parav@nvidia.com> MIME-Version: 1.0 X-Originating-IP: [172.20.145.6] X-ClientProxiedBy: HQMAIL111.nvidia.com (172.20.187.18) To HQMAIL107.nvidia.com (172.20.187.13) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1612687468; bh=pGK2Af0qn2QRGDOFRDWa+BYwAzh3f5JhXbZqhMSITr8=; h=From:To:CC:Subject:Date:Message-ID:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:Content-Type: X-Originating-IP:X-ClientProxiedBy; b=YZxFymYIva5+8P7SkscZ9OBomcjPXPjLzkYXYSKf6nu8/b8SycYsEfda/OGyovUyd aIJLUI9XLT0UuaC6DdK3XOm28uzh3teYIkb8ri+3Vee9kfiIRh7AtsKnJJfmUAuRLF YNwBRS9BsM7sVCPjLJeMoCFapTgktUcjy86+UPLSCAsWCKeNGJ58U3ZdcTiEpKGcCx aHe/JxobLCs5OvC4sKW0Ah2aMpVD24T400WWb88bV0Kva19ClzcbHyjOjB5mUah1sj MnrmBQUF1lusYSx1JIsizGo7SVCoESpzqrxb5PabUrdAnmSMLJmpjX24zeSYYjCxMg iV45jlfHTBLJA== Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Allow users to get/set hardware address for the PCI port. Below example creates one devlink port, queries a port, sets a hardware address. Example of a PCI SF port which supports a port function hw_addr set: Create a device with ID=10 and one physical port. $ echo "10 1" > /sys/bus/netdevsim/new_device Add PCI PF port: $ devlink port add netdevsim/netdevsim10 flavour pcipf pfnum 2 netdevsim/netdevsim10/1: type eth netdev eth1 flavour pcipf controller 0 pfnum 2 external false splittable false function: hw_addr 00:00:00:00:00:00 $ devlink port add netdevsim/netdevsim10 flavour pcisf pfnum 2 netdevsim/netdevsim10/2: type eth netdev eth2 flavour pcisf controller 0 pfnum 2 sfnum 0 splittable false function: hw_addr 00:00:00:00:00:00 Set the MAC address: $ devlink port function set netdevsim/netdevsim10/2 hw_addr 00:11:22:33:44:55 Show devlink ports: $ devlink port show netdevsim/netdevsim10/0: type eth netdev eth0 flavour physical port 1 splittable false netdevsim/netdevsim10/1: type eth netdev eth1 flavour pcipf controller 0 pfnum 2 external false splittable false function: hw_addr 00:00:00:00:00:00 netdevsim/netdevsim10/2: type eth netdev eth2 flavour pcisf controller 0 pfnum 2 sfnum 0 splittable false function: hw_addr 00:11:22:33:44:55 Show the port and function attributes in JSON format: $ devlink port show netdevsim/netdevsim10/2 -jp { "port": { "netdevsim/netdevsim10/2": { "type": "eth", "netdev": "eth2", "flavour": "pcisf", "controller": 0, "pfnum": 2, "sfnum": 0, "splittable": false, "function": { "hw_addr": "00:11:22:33:44:55" } } } } Signed-off-by: Parav Pandit --- drivers/net/netdevsim/dev.c | 1 + drivers/net/netdevsim/netdevsim.h | 4 ++++ drivers/net/netdevsim/port_function.c | 21 +++++++++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/drivers/net/netdevsim/dev.c b/drivers/net/netdevsim/dev.c index 6046906d6b85..ab15b5f7e955 100644 --- a/drivers/net/netdevsim/dev.c +++ b/drivers/net/netdevsim/dev.c @@ -908,6 +908,7 @@ static const struct devlink_ops nsim_dev_devlink_ops = { .port_new = nsim_dev_devlink_port_new, .port_del = nsim_dev_devlink_port_del, .port_function_hw_addr_get = nsim_dev_port_fn_hw_addr_get, + .port_function_hw_addr_set = nsim_dev_port_fn_hw_addr_set, }; #define NSIM_DEV_MAX_MACS_DEFAULT 32 diff --git a/drivers/net/netdevsim/netdevsim.h b/drivers/net/netdevsim/netdevsim.h index e910c3cf480d..aafe2027a112 100644 --- a/drivers/net/netdevsim/netdevsim.h +++ b/drivers/net/netdevsim/netdevsim.h @@ -324,3 +324,7 @@ int nsim_dev_port_fn_hw_addr_get(struct devlink *devlink, struct devlink_port *port, u8 *hw_addr, int *hw_addr_len, struct netlink_ext_ack *extack); +int nsim_dev_port_fn_hw_addr_set(struct devlink *devlink, + struct devlink_port *port, + const u8 *hw_addr, int hw_addr_len, + struct netlink_ext_ack *extack); diff --git a/drivers/net/netdevsim/port_function.c b/drivers/net/netdevsim/port_function.c index 882d1bdbfcf5..5d6c5a732546 100644 --- a/drivers/net/netdevsim/port_function.c +++ b/drivers/net/netdevsim/port_function.c @@ -461,3 +461,24 @@ int nsim_dev_port_fn_hw_addr_get(struct devlink *devlink, *hw_addr_len = ETH_ALEN; return 0; } + +int nsim_dev_port_fn_hw_addr_set(struct devlink *devlink, + struct devlink_port *dl_port, + const u8 *hw_addr, int hw_addr_len, + struct netlink_ext_ack *extack) +{ + struct nsim_dev *nsim_dev = devlink_priv(devlink); + struct nsim_port_fn *port; + + if (hw_addr_len != ETH_ALEN) { + NL_SET_ERR_MSG_MOD(extack, + "Hardware address must be 6 bytes long"); + return -EOPNOTSUPP; + } + port = nsim_dev_to_port_fn(nsim_dev, dl_port, extack); + if (IS_ERR(port)) + return PTR_ERR(port); + + memcpy(port->hw_addr, hw_addr, ETH_ALEN); + return 0; +} From patchwork Sun Feb 7 08:44:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Parav Pandit X-Patchwork-Id: 12072701 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=-19.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,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 48E6BC4332B for ; Sun, 7 Feb 2021 08:45:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1C3B264E72 for ; Sun, 7 Feb 2021 08:45:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229704AbhBGIpX (ORCPT ); Sun, 7 Feb 2021 03:45:23 -0500 Received: from hqnvemgate25.nvidia.com ([216.228.121.64]:14525 "EHLO hqnvemgate25.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229601AbhBGIpJ (ORCPT ); Sun, 7 Feb 2021 03:45:09 -0500 Received: from hqmail.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate25.nvidia.com (using TLS: TLSv1.2, AES256-SHA) id ; Sun, 07 Feb 2021 00:44:29 -0800 Received: from sw-mtx-036.mtx.labs.mlnx (172.20.145.6) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Sun, 7 Feb 2021 08:44:28 +0000 From: Parav Pandit To: , , CC: Parav Pandit Subject: [PATCH net-next v2 5/7] netdevsim: Simulate port function state for a PCI port Date: Sun, 7 Feb 2021 10:44:10 +0200 Message-ID: <20210207084412.252259-6-parav@nvidia.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210207084412.252259-1-parav@nvidia.com> References: <20210206125551.8616-1-parav@nvidia.com> <20210207084412.252259-1-parav@nvidia.com> MIME-Version: 1.0 X-Originating-IP: [172.20.145.6] X-ClientProxiedBy: HQMAIL111.nvidia.com (172.20.187.18) To HQMAIL107.nvidia.com (172.20.187.13) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1612687469; bh=I+Za4fGJu0Hwrbf3oi5ivQ4WDIg32epMIBugfJ8ZxuM=; h=From:To:CC:Subject:Date:Message-ID:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:Content-Type: X-Originating-IP:X-ClientProxiedBy; b=mkQtNNfwWrAWJYURMY/necrIGNYKrOOPzyxCVcQceXGOkUXjKTOFtLjk+OP80vVkK WPG0mPdWK91Zdy7pWCMTiO/OFLjV/y+5rIKWTRb1sPbHrMbladnZ11kmbF5M0JBw2n Q4ZaIzr92pr/Bi+LQorRVAwKvhMy3AqiyVvU5xaL0MTOc/gx/4Aish5B6coTp5uJqc D5wp9OKR9U3uxEH5Fmu2JfmhkP4K0EO3bA2hXQzyRX4vUhgnDeOGJT/Yguoy4zo4oo asJJELDV2cnZ+O7c3gcKGyrK9HHkU+M4+G5a1lBD0tmv+1tm68rOK6aqBO+s8VUDmW UiJNz2SEbSRAQ== Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Simulate port function state of a PCI port. This enables users to get the state of the PCI port function. Example of a PCI SF port which supports a port function hw_addr set: Create a device with ID=10 and one physical port. $ echo "10 1" > /sys/bus/netdevsim/new_device Add PCI PF port: $ devlink port add netdevsim/netdevsim10 flavour pcipf pfnum 2 netdevsim/netdevsim10/1: type eth netdev eth1 flavour pcipf controller 0 pfnum 2 external false splittable false function: hw_addr 00:00:00:00:00:00 $ devlink port add netdevsim/netdevsim10 flavour pcisf pfnum 2 netdevsim/netdevsim10/2: type eth netdev eth2 flavour pcisf controller 0 pfnum 2 sfnum 0 splittable false function: hw_addr 00:00:00:00:00:00 Show devlink port: $ devlink port show netdevsim/netdevsim10/2 netdevsim/netdevsim10/2: type eth netdev eth2 flavour pcisf controller 0 pfnum 2 sfnum 0 splittable false function: hw_addr 00:00:00:00:00:00 state inactive opstate detached Show the port and function attributes in JSON format: $ devlink port show netdevsim/netdevsim10/2 -jp { "port": { "netdevsim/netdevsim10/2": { "type": "eth", "netdev": "eth2", "flavour": "pcisf", "controller": 0, "pfnum": 2, "sfnum": 0, "splittable": false, "function": { "hw_addr": "00:00:00:00:00:00", "state": "inactive", "opstate": "detached" } } } } Signed-off-by: Parav Pandit Reported-by: kernel test robot --- drivers/net/netdevsim/dev.c | 1 + drivers/net/netdevsim/netdevsim.h | 5 +++++ drivers/net/netdevsim/port_function.c | 22 ++++++++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/drivers/net/netdevsim/dev.c b/drivers/net/netdevsim/dev.c index ab15b5f7e955..9f2164ea89cd 100644 --- a/drivers/net/netdevsim/dev.c +++ b/drivers/net/netdevsim/dev.c @@ -909,6 +909,7 @@ static const struct devlink_ops nsim_dev_devlink_ops = { .port_del = nsim_dev_devlink_port_del, .port_function_hw_addr_get = nsim_dev_port_fn_hw_addr_get, .port_function_hw_addr_set = nsim_dev_port_fn_hw_addr_set, + .port_fn_state_get = nsim_dev_port_fn_state_get, }; #define NSIM_DEV_MAX_MACS_DEFAULT 32 diff --git a/drivers/net/netdevsim/netdevsim.h b/drivers/net/netdevsim/netdevsim.h index aafe2027a112..c0544d93e1e8 100644 --- a/drivers/net/netdevsim/netdevsim.h +++ b/drivers/net/netdevsim/netdevsim.h @@ -328,3 +328,8 @@ int nsim_dev_port_fn_hw_addr_set(struct devlink *devlink, struct devlink_port *port, const u8 *hw_addr, int hw_addr_len, struct netlink_ext_ack *extack); +int nsim_dev_port_fn_state_get(struct devlink *devlink, + struct devlink_port *port, + enum devlink_port_fn_state *state, + enum devlink_port_fn_opstate *opstate, + struct netlink_ext_ack *extack); diff --git a/drivers/net/netdevsim/port_function.c b/drivers/net/netdevsim/port_function.c index 5d6c5a732546..a25c449e4559 100644 --- a/drivers/net/netdevsim/port_function.c +++ b/drivers/net/netdevsim/port_function.c @@ -17,6 +17,7 @@ struct nsim_port_fn { u32 sfnum; u16 pfnum; u8 hw_addr[ETH_ALEN]; + u8 state; /* enum devlink_port_fn_state */ }; static struct devlink_port * @@ -248,6 +249,7 @@ static int nsim_devlink_port_fn_add(struct devlink *devlink, goto pf_err; } + port->state = DEVLINK_PORT_FN_STATE_INACTIVE; err = devlink_port_register(devlink, &port->dl_port, port->port_index); if (err) goto reg_err; @@ -482,3 +484,23 @@ int nsim_dev_port_fn_hw_addr_set(struct devlink *devlink, memcpy(port->hw_addr, hw_addr, ETH_ALEN); return 0; } + +int nsim_dev_port_fn_state_get(struct devlink *devlink, + struct devlink_port *dl_port, + enum devlink_port_fn_state *state, + enum devlink_port_fn_opstate *opstate, + struct netlink_ext_ack *extack) +{ + struct nsim_dev *nsim_dev = devlink_priv(devlink); + struct nsim_port_fn *port; + + port = nsim_dev_to_port_fn(nsim_dev, dl_port, extack); + if (IS_ERR(port)) + return PTR_ERR(port); + *state = port->state; + if (port->state == DEVLINK_PORT_FN_STATE_INACTIVE) + *opstate = DEVLINK_PORT_FN_OPSTATE_DETACHED; + else + *opstate = DEVLINK_PORT_FN_OPSTATE_ATTACHED; + return 0; +} From patchwork Sun Feb 7 08:44:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Parav Pandit X-Patchwork-Id: 12072703 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=-19.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,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 E4AF4C433DB for ; Sun, 7 Feb 2021 08:45:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B75FD64E73 for ; Sun, 7 Feb 2021 08:45:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229716AbhBGIp3 (ORCPT ); Sun, 7 Feb 2021 03:45:29 -0500 Received: from hqnvemgate26.nvidia.com ([216.228.121.65]:2847 "EHLO hqnvemgate26.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229618AbhBGIpK (ORCPT ); Sun, 7 Feb 2021 03:45:10 -0500 Received: from hqmail.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate26.nvidia.com (using TLS: TLSv1.2, AES256-SHA) id ; Sun, 07 Feb 2021 00:44:29 -0800 Received: from sw-mtx-036.mtx.labs.mlnx (172.20.145.6) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Sun, 7 Feb 2021 08:44:29 +0000 From: Parav Pandit To: , , CC: Parav Pandit Subject: [PATCH net-next v2 6/7] netdevsim: Simulate port function set state for a PCI port Date: Sun, 7 Feb 2021 10:44:11 +0200 Message-ID: <20210207084412.252259-7-parav@nvidia.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210207084412.252259-1-parav@nvidia.com> References: <20210206125551.8616-1-parav@nvidia.com> <20210207084412.252259-1-parav@nvidia.com> MIME-Version: 1.0 X-Originating-IP: [172.20.145.6] X-ClientProxiedBy: HQMAIL111.nvidia.com (172.20.187.18) To HQMAIL107.nvidia.com (172.20.187.13) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1612687470; bh=R67O5HmHJ/OHmKeyveXlrX1PdsnwGt00W+qKIA5/xcs=; h=From:To:CC:Subject:Date:Message-ID:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:Content-Type: X-Originating-IP:X-ClientProxiedBy; b=foBdW/lDcg6IrhR/SaeC5jZrG4mme7vKvRmv4Y29M5CeBsUb9IkmbsZeahCxYozrI cKP1M+6kD3G9i7qxGA2ItExiGNOGdvxzMD7R5DuALTA3mnqDVdcz7nTMhfWEpPygDf ApFkNEDq7sQs1RlfERrmDzoWCHA1aCAT7XkxH2+DOP6q8TST2/EYEKxdpeZ6dAvQjL jHYdx6WoSX/+IDcsvrPqvVbPPXX0Eu92erfLb6IMFLeX1+Haj+laGwqz4z5RGB1Hr3 kkzDCUZvszDO20viSLNTK1VR0lYbhtQ3iu5kD3qFe3BG9PLPsyFUI0v2B0rRdIs5uL kpAhMJbzQZCTg== Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Simulate port function state of a PCI port. This enables users to get and set the state of the PCI port function. Example of a PCI SF port which supports a port function: Create a device with ID=10 and one physical port. $ echo "10 1" > /sys/bus/netdevsim/new_device Add PCI PF port: $ devlink port add netdevsim/netdevsim10 flavour pcipf pfnum 2 netdevsim/netdevsim10/1: type eth netdev eth1 flavour pcipf controller 0 pfnum 2 external false splittable false function: hw_addr 00:00:00:00:00:00 $ devlink port add netdevsim/netdevsim10 flavour pcisf pfnum 2 netdevsim/netdevsim10/2: type eth netdev eth2 flavour pcisf controller 0 pfnum 2 sfnum 0 splittable false function: hw_addr 00:00:00:00:00:00 Show devlink port: $ devlink port show netdevsim/netdevsim10/2 netdevsim/netdevsim10/2: type eth netdev eth2 flavour pcisf controller 0 pfnum 2 sfnum 0 splittable false function: hw_addr 00:00:00:00:00:00 state inactive opstate detached Set the MAC address and activate the function: $ devlink port function set netdevsim/netdevsim10/2 hw_addr 00:11:22:33:44:55 state active Show the port and function attributes in JSON format: $ devlink port show netdevsim/netdevsim10/2 -jp { "port": { "netdevsim/netdevsim10/2": { "type": "eth", "netdev": "eth2", "flavour": "pcisf", "controller": 0, "pfnum": 2, "sfnum": 0, "splittable": false, "function": { "hw_addr": "00:11:22:33:44:55", "state": "active", "opstate": "attached" } } } } Signed-off-by: Parav Pandit --- drivers/net/netdevsim/dev.c | 1 + drivers/net/netdevsim/netdevsim.h | 4 ++++ drivers/net/netdevsim/port_function.c | 15 +++++++++++++++ 3 files changed, 20 insertions(+) diff --git a/drivers/net/netdevsim/dev.c b/drivers/net/netdevsim/dev.c index 9f2164ea89cd..e8b6bd22fb1f 100644 --- a/drivers/net/netdevsim/dev.c +++ b/drivers/net/netdevsim/dev.c @@ -910,6 +910,7 @@ static const struct devlink_ops nsim_dev_devlink_ops = { .port_function_hw_addr_get = nsim_dev_port_fn_hw_addr_get, .port_function_hw_addr_set = nsim_dev_port_fn_hw_addr_set, .port_fn_state_get = nsim_dev_port_fn_state_get, + .port_fn_state_set = nsim_dev_port_fn_state_set, }; #define NSIM_DEV_MAX_MACS_DEFAULT 32 diff --git a/drivers/net/netdevsim/netdevsim.h b/drivers/net/netdevsim/netdevsim.h index c0544d93e1e8..93bfa3e946b2 100644 --- a/drivers/net/netdevsim/netdevsim.h +++ b/drivers/net/netdevsim/netdevsim.h @@ -333,3 +333,7 @@ int nsim_dev_port_fn_state_get(struct devlink *devlink, enum devlink_port_fn_state *state, enum devlink_port_fn_opstate *opstate, struct netlink_ext_ack *extack); +int nsim_dev_port_fn_state_set(struct devlink *devlink, + struct devlink_port *port, + enum devlink_port_fn_state state, + struct netlink_ext_ack *extack); diff --git a/drivers/net/netdevsim/port_function.c b/drivers/net/netdevsim/port_function.c index a25c449e4559..5be66ffa8d77 100644 --- a/drivers/net/netdevsim/port_function.c +++ b/drivers/net/netdevsim/port_function.c @@ -504,3 +504,18 @@ int nsim_dev_port_fn_state_get(struct devlink *devlink, *opstate = DEVLINK_PORT_FN_OPSTATE_ATTACHED; return 0; } + +int nsim_dev_port_fn_state_set(struct devlink *devlink, + struct devlink_port *dl_port, + enum devlink_port_fn_state state, + struct netlink_ext_ack *extack) +{ + struct nsim_dev *nsim_dev = devlink_priv(devlink); + struct nsim_port_fn *port; + + port = nsim_dev_to_port_fn(nsim_dev, dl_port, extack); + if (IS_ERR(port)) + return PTR_ERR(port); + port->state = state; + return 0; +} From patchwork Sun Feb 7 08:44:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Parav Pandit X-Patchwork-Id: 12072705 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=-19.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,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 A28C2C433E0 for ; Sun, 7 Feb 2021 08:45:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6649764E73 for ; Sun, 7 Feb 2021 08:45:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229725AbhBGIp5 (ORCPT ); Sun, 7 Feb 2021 03:45:57 -0500 Received: from hqnvemgate24.nvidia.com ([216.228.121.143]:4418 "EHLO hqnvemgate24.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229690AbhBGIps (ORCPT ); Sun, 7 Feb 2021 03:45:48 -0500 Received: from hqmail.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate24.nvidia.com (using TLS: TLSv1.2, AES256-SHA) id ; Sun, 07 Feb 2021 00:44:30 -0800 Received: from sw-mtx-036.mtx.labs.mlnx (172.20.145.6) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Sun, 7 Feb 2021 08:44:29 +0000 From: Parav Pandit To: , , CC: Parav Pandit Subject: [PATCH net-next v2 7/7] netdevsim: Add netdevsim port add test cases Date: Sun, 7 Feb 2021 10:44:12 +0200 Message-ID: <20210207084412.252259-8-parav@nvidia.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210207084412.252259-1-parav@nvidia.com> References: <20210206125551.8616-1-parav@nvidia.com> <20210207084412.252259-1-parav@nvidia.com> MIME-Version: 1.0 X-Originating-IP: [172.20.145.6] X-ClientProxiedBy: HQMAIL111.nvidia.com (172.20.187.18) To HQMAIL107.nvidia.com (172.20.187.13) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1612687470; bh=s0JYRKidIQwPxU3hjTDHghe0hIen03uiAITxUTIUc9U=; h=From:To:CC:Subject:Date:Message-ID:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:Content-Type: X-Originating-IP:X-ClientProxiedBy; b=lnpgoNBl0fitQxGjE+NJAvBTbLsHOGeEuic306sz2+49XrXvM63QNInjUqSlApEag u4sb91gOTUvD1gmrTbn5LrRFi4fsSuXQoz1V/n8zdfwOFV5QQB1DLxs1foCL+VbCMS WPk5bVxiKE7EiXell5tomlHEUqdg5FLVVTaVid5YWhAE1i2t9T079j3gZt+tq+/EzQ ogtQ9zohsSw7t3BFvmNdb/+XlHHw2m+c5+dwz6T4W2s1os8112Bh0XTDdpS7Xwuqpt LsAL+VgGWMfM2d1Gb51g3jAE7Z+5SXKs58oPIYhuJ62Z4jNBarb39201OerRDBIWKY 4Taa0kggtndfQ== Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Add tests for PCI PF and SF port add, configure and delete. Signed-off-by: Parav Pandit --- .../drivers/net/netdevsim/devlink.sh | 72 ++++++++++++++++++- 1 file changed, 71 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/drivers/net/netdevsim/devlink.sh b/tools/testing/selftests/drivers/net/netdevsim/devlink.sh index 40909c254365..ba349909a37e 100755 --- a/tools/testing/selftests/drivers/net/netdevsim/devlink.sh +++ b/tools/testing/selftests/drivers/net/netdevsim/devlink.sh @@ -5,7 +5,7 @@ lib_dir=$(dirname $0)/../../../net/forwarding ALL_TESTS="fw_flash_test params_test regions_test reload_test \ netns_reload_test resource_test dev_info_test \ - empty_reporter_test dummy_reporter_test" + empty_reporter_test dummy_reporter_test devlink_port_add_test" NUM_NETIFS=0 source $lib_dir/lib.sh @@ -507,6 +507,76 @@ dummy_reporter_test() log_test "dummy reporter test" } +function_state_get() +{ + local name=$1 + + cmd_jq "devlink port show $DL_HANDLE/$USR_SF_PORT_INDEX -j" \ + " .[][].function.$1" +} + +devlink_port_add_test() +{ + RET=0 + USR_PF_PORT_INDEX=600 + USR_PFNUM_A=2 + USR_PFNUM_B=3 + USR_SF_PORT_INDEX=601 + USR_SFNUM_A=44 + USR_SFNUM_B=55 + + devlink port add $DL_HANDLE flavour pcipf pfnum $USR_PFNUM_A + check_err $? "Failed PF port addition" + + devlink port show + check_err $? "Failed PF port show" + + devlink port add $DL_HANDLE flavour pcisf pfnum $USR_PFNUM_A + check_err $? "Failed SF port addition" + + devlink port add $DL_HANDLE flavour pcisf pfnum $USR_PFNUM_A \ + sfnum $USR_SFNUM_A + check_err $? "Failed SF port addition" + + devlink port add $DL_HANDLE flavour pcipf pfnum $USR_PFNUM_B + check_err $? "Failed second PF port addition" + + devlink port add $DL_HANDLE/$USR_SF_PORT_INDEX flavour pcisf \ + pfnum $USR_PFNUM_B sfnum $USR_SFNUM_B + check_err $? "Failed SF port addition" + + devlink port show + check_err $? "Failed PF port show" + + state=$(function_state_get "state") + check_err $? "Failed to get function state" + [ "$state" == "inactive" ] + check_err $? "Unexpected function state $state" + + state=$(function_state_get "opstate") + check_err $? "Failed to get operational state" + [ "$state" == "detached" ] + check_err $? "Unexpected function opstate $opstate" + + devlink port function set $DL_HANDLE/$USR_SF_PORT_INDEX state active + check_err $? "Failed to set state" + + state=$(function_state_get "state") + check_err $? "Failed to get function state" + [ "$state" == "active" ] + check_err $? "Unexpected function state $state" + + state=$(function_state_get "opstate") + check_err $? "Failed to get operational state" + [ "$state" == "attached" ] + check_err $? "Unexpected function opstate $opstate" + + devlink port del $DL_HANDLE/$USR_SF_PORT_INDEX + check_err $? "Failed SF port deletion" + + log_test "port_add test" +} + setup_prepare() { modprobe netdevsim