mbox series

[net-next,v2,0/7] netdevsim port add, delete support

Message ID 20210207084412.252259-1-parav@nvidia.com
Headers show
Series netdevsim port add, delete support | expand

Message

Parav Pandit Feb. 7, 2021, 8:44 a.m. UTC
This series simulates one or more PCI PF and SF port addition and function
configuration functionality.

Example sequence:
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"
            }
        }
    }
}

Delete PCI SF and PF ports:
$ devlink port del netdevsim/netdevsim10/2

Patch summary:
patch-1 adds support for adding/remove PCI PF port
patch-2 adds support for adding/remove PCI SF port
patch-3 simulates MAC address query
patch-4 simulates setting MAC address
patch-5 simulates state query
patch-6 simulates setting state
patch-7 adds tests

Parav Pandit (7):
  netdevsim: Add support for add and delete of a PCI PF port
  netdevsim: Add support for add and delete PCI SF port
  netdevsim: Simulate get hardware address of a PCI port
  netdevsim: Simulate set hardware address of a PCI port
  netdevsim: Simulate port function state for a PCI port
  netdevsim: Simulate port function set state for a PCI port
  netdevsim: Add netdevsim port add test cases

 drivers/net/netdevsim/Makefile                |   2 +-
 drivers/net/netdevsim/dev.c                   |  14 +
 drivers/net/netdevsim/netdevsim.h             |  38 ++
 drivers/net/netdevsim/port_function.c         | 521 ++++++++++++++++++
 .../drivers/net/netdevsim/devlink.sh          |  72 ++-
 5 files changed, 645 insertions(+), 2 deletions(-)
 create mode 100644 drivers/net/netdevsim/port_function.c

Comments

Jakub Kicinski Feb. 8, 2021, 9:21 p.m. UTC | #1
On Sun, 7 Feb 2021 10:44:12 +0200 Parav Pandit wrote:
> +	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"


I don't think this very basic test is worth the 600 LoC of netdevsim
code.

If you come up with something better please don't post v3 it in reply 
to previous threads.
Parav Pandit Feb. 9, 2021, 3:59 a.m. UTC | #2
> From: Jakub Kicinski <kuba@kernel.org>

> Sent: Tuesday, February 9, 2021 2:51 AM

> 

> On Sun, 7 Feb 2021 10:44:12 +0200 Parav Pandit wrote:

> > +	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"

> 

> I don't think this very basic test is worth the 600 LoC of netdevsim code.

> 

Do you mean I should improve the test to do more code coverage for 600 LoC?

> If you come up with something better please don't post v3 it in reply to

> previous threads.

Can you please explain? If only test case improves, wouldn't it be v3 for the last patch?
I must be missing something here.