diff mbox series

[net-next,1/7] netdevsim: Add support for add and delete of a PCI PF port

Message ID 20210206125551.8616-2-parav@nvidia.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series netdevsim port add, delete support | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for net-next
netdev/subject_prefix success Link
netdev/cc_maintainers success CCed 3 of 3 maintainers
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit fail Errors and warnings before: 0 this patch: 1
netdev/kdoc success Errors and warnings before: 1 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch warning CHECK: struct mutex definition without comment WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? WARNING: line length of 81 exceeds 80 columns WARNING: line length of 93 exceeds 80 columns
netdev/build_allmodconfig_warn fail Errors and warnings before: 0 this patch: 1
netdev/header_inline success Link
netdev/stable success Stable not CCed

Commit Message

Parav Pandit Feb. 6, 2021, 12:55 p.m. UTC
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

Signed-off-by: Parav Pandit <parav@nvidia.com>
---
 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

Comments

kernel test robot Feb. 6, 2021, 2:34 p.m. UTC | #1
Hi Parav,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on net-next/master]

url:    https://github.com/0day-ci/linux/commits/Parav-Pandit/netdevsim-port-add-delete-support/20210206-210153
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 6626a0266566c5aea16178c5e6cd7fc4db3f2f56
config: x86_64-allyesconfig (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
reproduce (this is a W=1 build):
        # https://github.com/0day-ci/linux/commit/4234edd1adbb2da7f6f156c2bfdac5170eb97dbb
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Parav-Pandit/netdevsim-port-add-delete-support/20210206-210153
        git checkout 4234edd1adbb2da7f6f156c2bfdac5170eb97dbb
        # save the attached .config to linux build tree
        make W=1 ARCH=x86_64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   In file included from drivers/net/netdevsim/netdev.c:27:
>> drivers/net/netdevsim/netdevsim.h:317:23: warning: 'struct devlink_port_new_attrs' declared inside parameter list will not be visible outside of this definition or declaration
     317 |          const struct devlink_port_new_attrs *attrs,
         |                       ^~~~~~~~~~~~~~~~~~~~~~
--
   In file included from drivers/net/netdevsim/dev.c:36:
>> drivers/net/netdevsim/netdevsim.h:317:23: warning: 'struct devlink_port_new_attrs' declared inside parameter list will not be visible outside of this definition or declaration
     317 |          const struct devlink_port_new_attrs *attrs,
         |                       ^~~~~~~~~~~~~~~~~~~~~~
   drivers/net/netdevsim/dev.c:908:3: error: 'const struct devlink_ops' has no member named 'port_new'
     908 |  .port_new = nsim_dev_devlink_port_new,
         |   ^~~~~~~~
   drivers/net/netdevsim/dev.c:908:14: error: initialization of 'int (*)(struct devlink *, struct devlink_port *, u8 *, int *, struct netlink_ext_ack *)' {aka 'int (*)(struct devlink *, struct devlink_port *, unsigned char *, int *, struct netlink_ext_ack *)'} from incompatible pointer type 'int (*)(struct devlink *, const struct devlink_port_new_attrs *, struct netlink_ext_ack *, unsigned int *)' [-Werror=incompatible-pointer-types]
     908 |  .port_new = nsim_dev_devlink_port_new,
         |              ^~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/net/netdevsim/dev.c:908:14: note: (near initialization for 'nsim_dev_devlink_ops.port_function_hw_addr_get')
   drivers/net/netdevsim/dev.c:909:3: error: 'const struct devlink_ops' has no member named 'port_del'; did you mean 'port_split'?
     909 |  .port_del = nsim_dev_devlink_port_del,
         |   ^~~~~~~~
         |   port_split
   drivers/net/netdevsim/dev.c:909:14: error: initialization of 'int (*)(struct devlink *, struct devlink_port *, const u8 *, int,  struct netlink_ext_ack *)' {aka 'int (*)(struct devlink *, struct devlink_port *, const unsigned char *, int,  struct netlink_ext_ack *)'} from incompatible pointer type 'int (*)(struct devlink *, unsigned int,  struct netlink_ext_ack *)' [-Werror=incompatible-pointer-types]
     909 |  .port_del = nsim_dev_devlink_port_del,
         |              ^~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/net/netdevsim/dev.c:909:14: note: (near initialization for 'nsim_dev_devlink_ops.port_function_hw_addr_set')
   cc1: some warnings being treated as errors
--
   In file included from drivers/net/netdevsim/port_function.c:7:
>> drivers/net/netdevsim/netdevsim.h:317:23: warning: 'struct devlink_port_new_attrs' declared inside parameter list will not be visible outside of this definition or declaration
     317 |          const struct devlink_port_new_attrs *attrs,
         |                       ^~~~~~~~~~~~~~~~~~~~~~
   drivers/net/netdevsim/port_function.c:51:20: warning: 'struct devlink_port_new_attrs' declared inside parameter list will not be visible outside of this definition or declaration
      51 |       const struct devlink_port_new_attrs *attrs)
         |                    ^~~~~~~~~~~~~~~~~~~~~~
   drivers/net/netdevsim/port_function.c: In function 'nsim_devlink_port_fn_alloc':
   drivers/net/netdevsim/port_function.c:71:23: error: dereferencing pointer to incomplete type 'const struct devlink_port_new_attrs'
      71 |  port->flavour = attrs->flavour;
         |                       ^~
   drivers/net/netdevsim/port_function.c: At top level:
   drivers/net/netdevsim/port_function.c:130:19: warning: 'struct devlink_port_new_attrs' declared inside parameter list will not be visible outside of this definition or declaration
     130 |      const struct devlink_port_new_attrs *attrs)
         |                   ^~~~~~~~~~~~~~~~~~~~~~
   drivers/net/netdevsim/port_function.c: In function 'nsim_dev_port_port_exists':
   drivers/net/netdevsim/port_function.c:135:12: error: dereferencing pointer to incomplete type 'const struct devlink_port_new_attrs'
     135 |   if (attrs->port_index_valid &&
         |            ^~
   drivers/net/netdevsim/port_function.c: At top level:
   drivers/net/netdevsim/port_function.c:201:18: warning: 'struct devlink_port_new_attrs' declared inside parameter list will not be visible outside of this definition or declaration
     201 |     const struct devlink_port_new_attrs *attrs)
         |                  ^~~~~~~~~~~~~~~~~~~~~~
   drivers/net/netdevsim/port_function.c: In function 'nsim_dev_port_flavour_supported':
   drivers/net/netdevsim/port_function.c:203:14: error: dereferencing pointer to incomplete type 'const struct devlink_port_new_attrs'
     203 |  return attrs->flavour == DEVLINK_PORT_FLAVOUR_PCI_PF;
         |              ^~
   drivers/net/netdevsim/port_function.c: At top level:
   drivers/net/netdevsim/port_function.c:207:23: warning: 'struct devlink_port_new_attrs' declared inside parameter list will not be visible outside of this definition or declaration
     207 |          const struct devlink_port_new_attrs *attrs,
         |                       ^~~~~~~~~~~~~~~~~~~~~~
   drivers/net/netdevsim/port_function.c:206:5: error: conflicting types for 'nsim_dev_devlink_port_new'
     206 | int nsim_dev_devlink_port_new(struct devlink *devlink,
         |     ^~~~~~~~~~~~~~~~~~~~~~~~~
   In file included from drivers/net/netdevsim/port_function.c:7:
   drivers/net/netdevsim/netdevsim.h:316:5: note: previous declaration of 'nsim_dev_devlink_port_new' was here
     316 | int nsim_dev_devlink_port_new(struct devlink *devlink,
         |     ^~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/net/netdevsim/port_function.c: In function 'nsim_dev_devlink_port_new':
   drivers/net/netdevsim/port_function.c:217:11: error: dereferencing pointer to incomplete type 'const struct devlink_port_new_attrs'
     217 |  if (attrs->port_index_valid &&
         |           ^~
   drivers/net/netdevsim/port_function.c:223:49: error: passing argument 2 of 'nsim_dev_port_flavour_supported' from incompatible pointer type [-Werror=incompatible-pointer-types]
     223 |  if (!nsim_dev_port_flavour_supported(nsim_dev, attrs)) {
         |                                                 ^~~~~
         |                                                 |
         |                                                 const struct devlink_port_new_attrs *
   drivers/net/netdevsim/port_function.c:201:42: note: expected 'const struct devlink_port_new_attrs *' but argument is of type 'const struct devlink_port_new_attrs *'
     201 |     const struct devlink_port_new_attrs *attrs)
         |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
   drivers/net/netdevsim/port_function.c:232:42: error: passing argument 2 of 'nsim_dev_port_port_exists' from incompatible pointer type [-Werror=incompatible-pointer-types]
     232 |  if (nsim_dev_port_port_exists(nsim_dev, attrs)) {
         |                                          ^~~~~
         |                                          |
         |                                          const struct devlink_port_new_attrs *
   drivers/net/netdevsim/port_function.c:130:43: note: expected 'const struct devlink_port_new_attrs *' but argument is of type 'const struct devlink_port_new_attrs *'
     130 |      const struct devlink_port_new_attrs *attrs)
         |      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
   drivers/net/netdevsim/port_function.c:238:46: error: passing argument 2 of 'nsim_devlink_port_fn_alloc' from incompatible pointer type [-Werror=incompatible-pointer-types]
     238 |  port = nsim_devlink_port_fn_alloc(nsim_dev, attrs);
         |                                              ^~~~~
         |                                              |
         |                                              const struct devlink_port_new_attrs *
   drivers/net/netdevsim/port_function.c:51:44: note: expected 'const struct devlink_port_new_attrs *' but argument is of type 'const struct devlink_port_new_attrs *'
      51 |       const struct devlink_port_new_attrs *attrs)
         |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
   drivers/net/netdevsim/port_function.c: In function 'nsim_dev_devlink_port_del':
   drivers/net/netdevsim/port_function.c:269:6: warning: variable 'err' set but not used [-Wunused-but-set-variable]
     269 |  int err = 0;
         |      ^~~
   drivers/net/netdevsim/port_function.c: In function 'nsim_dev_port_flavour_supported':
   drivers/net/netdevsim/port_function.c:204:1: error: control reaches end of non-void function [-Werror=return-type]
     204 | }
         | ^
   cc1: some warnings being treated as errors


vim +317 drivers/net/netdevsim/netdevsim.h

   311	
   312	void nsim_dev_port_fn_init(struct nsim_dev *nsim_dev);
   313	void nsim_dev_port_fn_exit(struct nsim_dev *nsim_dev);
   314	void nsim_dev_port_fn_enable(struct nsim_dev *nsim_dev);
   315	void nsim_dev_port_fn_disable(struct nsim_dev *nsim_dev);
   316	int nsim_dev_devlink_port_new(struct devlink *devlink,
 > 317				      const struct devlink_port_new_attrs *attrs,

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
kernel test robot Feb. 6, 2021, 4:24 p.m. UTC | #2
Hi Parav,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on net-next/master]

url:    https://github.com/0day-ci/linux/commits/Parav-Pandit/netdevsim-port-add-delete-support/20210206-210153
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 6626a0266566c5aea16178c5e6cd7fc4db3f2f56
config: x86_64-randconfig-a004-20210206 (attached as .config)
compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project c9439ca36342fb6013187d0a69aef92736951476)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install x86_64 cross compiling tool for clang build
        # apt-get install binutils-x86-64-linux-gnu
        # https://github.com/0day-ci/linux/commit/4234edd1adbb2da7f6f156c2bfdac5170eb97dbb
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Parav-Pandit/netdevsim-port-add-delete-support/20210206-210153
        git checkout 4234edd1adbb2da7f6f156c2bfdac5170eb97dbb
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All error/warnings (new ones prefixed by >>):

   In file included from drivers/net/netdevsim/netdev.c:27:
>> drivers/net/netdevsim/netdevsim.h:317:23: warning: declaration of 'struct devlink_port_new_attrs' will not be visible outside of this function [-Wvisibility]
                                 const struct devlink_port_new_attrs *attrs,
                                              ^
   1 warning generated.
--
   In file included from drivers/net/netdevsim/dev.c:36:
>> drivers/net/netdevsim/netdevsim.h:317:23: warning: declaration of 'struct devlink_port_new_attrs' will not be visible outside of this function [-Wvisibility]
                                 const struct devlink_port_new_attrs *attrs,
                                              ^
>> drivers/net/netdevsim/dev.c:908:3: error: field designator 'port_new' does not refer to any field in type 'const struct devlink_ops'
           .port_new = nsim_dev_devlink_port_new,
            ^
>> drivers/net/netdevsim/dev.c:909:3: error: field designator 'port_del' does not refer to any field in type 'const struct devlink_ops'
           .port_del = nsim_dev_devlink_port_del,
            ^
   1 warning and 2 errors generated.
--
   In file included from drivers/net/netdevsim/port_function.c:7:
>> drivers/net/netdevsim/netdevsim.h:317:23: warning: declaration of 'struct devlink_port_new_attrs' will not be visible outside of this function [-Wvisibility]
                                 const struct devlink_port_new_attrs *attrs,
                                              ^
>> drivers/net/netdevsim/port_function.c:51:20: warning: declaration of 'struct devlink_port_new_attrs' will not be visible outside of this function [-Wvisibility]
                              const struct devlink_port_new_attrs *attrs)
                                           ^
>> drivers/net/netdevsim/port_function.c:71:23: error: incomplete definition of type 'struct devlink_port_new_attrs'
           port->flavour = attrs->flavour;
                           ~~~~~^
   drivers/net/netdevsim/port_function.c:51:20: note: forward declaration of 'struct devlink_port_new_attrs'
                              const struct devlink_port_new_attrs *attrs)
                                           ^
   drivers/net/netdevsim/port_function.c:73:11: error: incomplete definition of type 'struct devlink_port_new_attrs'
           if (attrs->port_index_valid)
               ~~~~~^
   drivers/net/netdevsim/port_function.c:51:20: note: forward declaration of 'struct devlink_port_new_attrs'
                              const struct devlink_port_new_attrs *attrs)
                                           ^
   drivers/net/netdevsim/port_function.c:75:16: error: incomplete definition of type 'struct devlink_port_new_attrs'
                                         attrs->port_index,
                                         ~~~~~^
   drivers/net/netdevsim/port_function.c:51:20: note: forward declaration of 'struct devlink_port_new_attrs'
                              const struct devlink_port_new_attrs *attrs)
                                           ^
   drivers/net/netdevsim/port_function.c:76:16: error: incomplete definition of type 'struct devlink_port_new_attrs'
                                         attrs->port_index, GFP_KERNEL);
                                         ~~~~~^
   drivers/net/netdevsim/port_function.c:51:20: note: forward declaration of 'struct devlink_port_new_attrs'
                              const struct devlink_port_new_attrs *attrs)
                                           ^
   drivers/net/netdevsim/port_function.c:88:16: error: incomplete definition of type 'struct devlink_port_new_attrs'
                                         attrs->pfnum, attrs->pfnum,
                                         ~~~~~^
   drivers/net/netdevsim/port_function.c:51:20: note: forward declaration of 'struct devlink_port_new_attrs'
                              const struct devlink_port_new_attrs *attrs)
                                           ^
   drivers/net/netdevsim/port_function.c:88:30: error: incomplete definition of type 'struct devlink_port_new_attrs'
                                         attrs->pfnum, attrs->pfnum,
                                                       ~~~~~^
   drivers/net/netdevsim/port_function.c:51:20: note: forward declaration of 'struct devlink_port_new_attrs'
                              const struct devlink_port_new_attrs *attrs)
                                           ^
   drivers/net/netdevsim/port_function.c:130:19: warning: declaration of 'struct devlink_port_new_attrs' will not be visible outside of this function [-Wvisibility]
                             const struct devlink_port_new_attrs *attrs)
                                          ^
   drivers/net/netdevsim/port_function.c:135:12: error: incomplete definition of type 'struct devlink_port_new_attrs'
                   if (attrs->port_index_valid &&
                       ~~~~~^
   drivers/net/netdevsim/port_function.c:130:19: note: forward declaration of 'struct devlink_port_new_attrs'
                             const struct devlink_port_new_attrs *attrs)
                                          ^
   drivers/net/netdevsim/port_function.c:136:31: error: incomplete definition of type 'struct devlink_port_new_attrs'
                       tmp->port_index == attrs->port_index)
                                          ~~~~~^
   drivers/net/netdevsim/port_function.c:130:19: note: forward declaration of 'struct devlink_port_new_attrs'
                             const struct devlink_port_new_attrs *attrs)
                                          ^
   drivers/net/netdevsim/port_function.c:138:12: error: incomplete definition of type 'struct devlink_port_new_attrs'
                   if (attrs->flavour == DEVLINK_PORT_FLAVOUR_PCI_PF &&
                       ~~~~~^
   drivers/net/netdevsim/port_function.c:130:19: note: forward declaration of 'struct devlink_port_new_attrs'
                             const struct devlink_port_new_attrs *attrs)
                                          ^
   drivers/net/netdevsim/port_function.c:140:26: error: incomplete definition of type 'struct devlink_port_new_attrs'
                       tmp->pfnum == attrs->pfnum)
                                     ~~~~~^
   drivers/net/netdevsim/port_function.c:130:19: note: forward declaration of 'struct devlink_port_new_attrs'
                             const struct devlink_port_new_attrs *attrs)
                                          ^
   drivers/net/netdevsim/port_function.c:201:18: warning: declaration of 'struct devlink_port_new_attrs' will not be visible outside of this function [-Wvisibility]
                                   const struct devlink_port_new_attrs *attrs)
                                                ^
   drivers/net/netdevsim/port_function.c:203:14: error: incomplete definition of type 'struct devlink_port_new_attrs'
           return attrs->flavour == DEVLINK_PORT_FLAVOUR_PCI_PF;
                  ~~~~~^
   drivers/net/netdevsim/port_function.c:201:18: note: forward declaration of 'struct devlink_port_new_attrs'
                                   const struct devlink_port_new_attrs *attrs)
                                                ^
   drivers/net/netdevsim/port_function.c:207:23: warning: declaration of 'struct devlink_port_new_attrs' will not be visible outside of this function [-Wvisibility]
                                 const struct devlink_port_new_attrs *attrs,
                                              ^
   drivers/net/netdevsim/port_function.c:206:5: error: conflicting types for 'nsim_dev_devlink_port_new'
   int nsim_dev_devlink_port_new(struct devlink *devlink,
       ^
   drivers/net/netdevsim/netdevsim.h:316:5: note: previous declaration is here
   int nsim_dev_devlink_port_new(struct devlink *devlink,
       ^
   drivers/net/netdevsim/port_function.c:217:11: error: incomplete definition of type 'struct devlink_port_new_attrs'
           if (attrs->port_index_valid &&
               ~~~~~^
   drivers/net/netdevsim/port_function.c:207:23: note: forward declaration of 'struct devlink_port_new_attrs'
                                 const struct devlink_port_new_attrs *attrs,
                                              ^
   drivers/net/netdevsim/port_function.c:218:11: error: incomplete definition of type 'struct devlink_port_new_attrs'
               attrs->port_index < nsim_bus_dev->port_count) {
               ~~~~~^
   drivers/net/netdevsim/port_function.c:207:23: note: forward declaration of 'struct devlink_port_new_attrs'
                                 const struct devlink_port_new_attrs *attrs,
                                              ^
   drivers/net/netdevsim/port_function.c:223:49: error: incompatible pointer types passing 'const struct devlink_port_new_attrs *' to parameter of type 'const struct devlink_port_new_attrs *' [-Werror,-Wincompatible-pointer-types]
           if (!nsim_dev_port_flavour_supported(nsim_dev, attrs)) {
                                                          ^~~~~
   drivers/net/netdevsim/port_function.c:201:42: note: passing argument to parameter 'attrs' here
                                   const struct devlink_port_new_attrs *attrs)
                                                                        ^
   drivers/net/netdevsim/port_function.c:232:42: error: incompatible pointer types passing 'const struct devlink_port_new_attrs *' to parameter of type 'const struct devlink_port_new_attrs *' [-Werror,-Wincompatible-pointer-types]
           if (nsim_dev_port_port_exists(nsim_dev, attrs)) {


vim +908 drivers/net/netdevsim/dev.c

   894	
   895	static const struct devlink_ops nsim_dev_devlink_ops = {
   896		.supported_flash_update_params = DEVLINK_SUPPORT_FLASH_UPDATE_COMPONENT |
   897						 DEVLINK_SUPPORT_FLASH_UPDATE_OVERWRITE_MASK,
   898		.reload_actions = BIT(DEVLINK_RELOAD_ACTION_DRIVER_REINIT),
   899		.reload_down = nsim_dev_reload_down,
   900		.reload_up = nsim_dev_reload_up,
   901		.info_get = nsim_dev_info_get,
   902		.flash_update = nsim_dev_flash_update,
   903		.trap_init = nsim_dev_devlink_trap_init,
   904		.trap_action_set = nsim_dev_devlink_trap_action_set,
   905		.trap_group_set = nsim_dev_devlink_trap_group_set,
   906		.trap_policer_set = nsim_dev_devlink_trap_policer_set,
   907		.trap_policer_counter_get = nsim_dev_devlink_trap_policer_counter_get,
 > 908		.port_new = nsim_dev_devlink_port_new,
 > 909		.port_del = nsim_dev_devlink_port_del,
   910	};
   911	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
kernel test robot Feb. 6, 2021, 6:28 p.m. UTC | #3
Hi Parav,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on net-next/master]

url:    https://github.com/0day-ci/linux/commits/Parav-Pandit/netdevsim-port-add-delete-support/20210206-210153
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 6626a0266566c5aea16178c5e6cd7fc4db3f2f56
config: x86_64-allyesconfig (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
reproduce (this is a W=1 build):
        # https://github.com/0day-ci/linux/commit/4234edd1adbb2da7f6f156c2bfdac5170eb97dbb
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Parav-Pandit/netdevsim-port-add-delete-support/20210206-210153
        git checkout 4234edd1adbb2da7f6f156c2bfdac5170eb97dbb
        # save the attached .config to linux build tree
        make W=1 ARCH=x86_64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   In file included from drivers/net/netdevsim/dev.c:36:
   drivers/net/netdevsim/netdevsim.h:317:23: warning: 'struct devlink_port_new_attrs' declared inside parameter list will not be visible outside of this definition or declaration
     317 |          const struct devlink_port_new_attrs *attrs,
         |                       ^~~~~~~~~~~~~~~~~~~~~~
>> drivers/net/netdevsim/dev.c:908:3: error: 'const struct devlink_ops' has no member named 'port_new'
     908 |  .port_new = nsim_dev_devlink_port_new,
         |   ^~~~~~~~
>> drivers/net/netdevsim/dev.c:908:14: error: initialization of 'int (*)(struct devlink *, struct devlink_port *, u8 *, int *, struct netlink_ext_ack *)' {aka 'int (*)(struct devlink *, struct devlink_port *, unsigned char *, int *, struct netlink_ext_ack *)'} from incompatible pointer type 'int (*)(struct devlink *, const struct devlink_port_new_attrs *, struct netlink_ext_ack *, unsigned int *)' [-Werror=incompatible-pointer-types]
     908 |  .port_new = nsim_dev_devlink_port_new,
         |              ^~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/net/netdevsim/dev.c:908:14: note: (near initialization for 'nsim_dev_devlink_ops.port_function_hw_addr_get')
>> drivers/net/netdevsim/dev.c:909:3: error: 'const struct devlink_ops' has no member named 'port_del'; did you mean 'port_split'?
     909 |  .port_del = nsim_dev_devlink_port_del,
         |   ^~~~~~~~
         |   port_split
>> drivers/net/netdevsim/dev.c:909:14: error: initialization of 'int (*)(struct devlink *, struct devlink_port *, const u8 *, int,  struct netlink_ext_ack *)' {aka 'int (*)(struct devlink *, struct devlink_port *, const unsigned char *, int,  struct netlink_ext_ack *)'} from incompatible pointer type 'int (*)(struct devlink *, unsigned int,  struct netlink_ext_ack *)' [-Werror=incompatible-pointer-types]
     909 |  .port_del = nsim_dev_devlink_port_del,
         |              ^~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/net/netdevsim/dev.c:909:14: note: (near initialization for 'nsim_dev_devlink_ops.port_function_hw_addr_set')
   cc1: some warnings being treated as errors


vim +908 drivers/net/netdevsim/dev.c

   894	
   895	static const struct devlink_ops nsim_dev_devlink_ops = {
   896		.supported_flash_update_params = DEVLINK_SUPPORT_FLASH_UPDATE_COMPONENT |
   897						 DEVLINK_SUPPORT_FLASH_UPDATE_OVERWRITE_MASK,
   898		.reload_actions = BIT(DEVLINK_RELOAD_ACTION_DRIVER_REINIT),
   899		.reload_down = nsim_dev_reload_down,
   900		.reload_up = nsim_dev_reload_up,
   901		.info_get = nsim_dev_info_get,
   902		.flash_update = nsim_dev_flash_update,
   903		.trap_init = nsim_dev_devlink_trap_init,
   904		.trap_action_set = nsim_dev_devlink_trap_action_set,
   905		.trap_group_set = nsim_dev_devlink_trap_group_set,
   906		.trap_policer_set = nsim_dev_devlink_trap_policer_set,
   907		.trap_policer_counter_get = nsim_dev_devlink_trap_policer_counter_get,
 > 908		.port_new = nsim_dev_devlink_port_new,
 > 909		.port_del = nsim_dev_devlink_port_del,
   910	};
   911	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
Parav Pandit Feb. 7, 2021, 7:59 a.m. UTC | #4
> From: kernel test robot <lkp@intel.com>
> Sent: Saturday, February 6, 2021 8:05 PM
> 
> Hi Parav,
> 
> Thank you for the patch! Perhaps something to improve:
> 
> [auto build test WARNING on net-next/master]
> 
> url:    https://github.com/0day-ci/linux/commits/Parav-Pandit/netdevsim-
> port-add-delete-support/20210206-210153
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git
> 6626a0266566c5aea16178c5e6cd7fc4db3f2f56
This commit tag doesn't contain the devlink patches required upto commit 142d93d12dc1.
Can you please update the 0day-ci to move to at least commit 142d93d12dc1?

>    drivers/net/netdevsim/port_function.c:269:6: warning: variable 'err' set
> but not used [-Wunused-but-set-variable]
>      269 |  int err = 0;
>          |      ^~~
Sending v2 to fix this warning.
Chen, Rong A Feb. 7, 2021, 8:04 a.m. UTC | #5
On 2/7/21 3:59 PM, Parav Pandit wrote:
>
>> From: kernel test robot <lkp@intel.com>
>> Sent: Saturday, February 6, 2021 8:05 PM
>>
>> Hi Parav,
>>
>> Thank you for the patch! Perhaps something to improve:
>>
>> [auto build test WARNING on net-next/master]
>>
>> url:    https://github.com/0day-ci/linux/commits/Parav-Pandit/netdevsim-
>> port-add-delete-support/20210206-210153
>> base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git
>> 6626a0266566c5aea16178c5e6cd7fc4db3f2f56
> This commit tag doesn't contain the devlink patches required upto commit 142d93d12dc1.
> Can you please update the 0day-ci to move to at least commit 142d93d12dc1?

Thanks for the feedback, we'll take a look.

Best Regards,
Rong Chen

>
>>     drivers/net/netdevsim/port_function.c:269:6: warning: variable 'err' set
>> but not used [-Wunused-but-set-variable]
>>       269 |  int err = 0;
>>           |      ^~~
> Sending v2 to fix this warning.
> _______________________________________________
> kbuild-all mailing list -- kbuild-all@lists.01.org
> To unsubscribe send an email to kbuild-all-leave@lists.01.org
diff mbox series

Patch

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..a957b754ef92
--- /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 <linux/etherdevice.h>
+#include <uapi/linux/devlink.h>
+
+#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 = 0;
+
+	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 PTR_ERR(port);
+}
+
+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);
+	}
+}