ice: Add get/set hw address for VFs using devlink commands
Subsystems (3)
PATCH v2 1/1 ice: Add get/set hw address for VFs using devlink commands
Thanks for the review comments and suggestions.
In the V2 version of the patch, I have called ice_set_vf_mac() directly from the devlink port function handlers.
I did the following testing to verify the changes.
root@10:~# ethtool -i enp8s0f0np0 | grep bus bus-info: 0000:08:00.0
root@10:~# devlink dev eswitch set pci/0000:08:00.0 mode switchdev Warning: ice: Changed eswitch mode to switchdev.
root@10:~# echo 4 > /sys/class/net/enp8s0f0np0/device/sriov_numvfs
root@10:~# devlink port show
pci/0000:08:00.0/0: type eth netdev enp8s0f0np0 flavour physical port 0 splittable true lanes 8
pci/0000:08:00.0/2: type eth netdev enp8s0f0npf0vf0 flavour pcivf controller 0 pfnum 0 vfnum 0 external false splittable false
function:
hw_addr 1a:33:f2:e7:64:d8
pci/0000:08:00.0/3: type eth netdev enp8s0f0npf0vf3 flavour pcivf controller 0 pfnum 0 vfnum 3 external false splittable false
function:
hw_addr 4e:ef:ca:9e:e7:5d
pci/0000:08:00.0/4: type eth netdev enp8s0f0npf0vf1 flavour pcivf controller 0 pfnum 0 vfnum 1 external false splittable false
function:
hw_addr 5a:f0:e3:f8:41:93
pci/0000:08:00.0/5: type eth netdev enp8s0f0npf0vf2 flavour pcivf controller 0 pfnum 0 vfnum 2 external false splittable false
function:
hw_addr 1a:62:c6:4b:d2:f0
pci/0000:08:00.1/0: type eth netdev enp8s0f1np1 flavour physical port 1 splittable falseroot@10:~# devlink port function set pci/0000:08:00.0/5 hw_addr 00:11:22:33:44:55
root@10:~# devlink port show
pci/0000:08:00.0/0: type eth netdev enp8s0f0np0 flavour physical port 0 splittable true lanes 8
pci/0000:08:00.0/2: type eth netdev enp8s0f0npf0vf0 flavour pcivf controller 0 pfnum 0 vfnum 0 external false splittable false
function:
hw_addr 1a:33:f2:e7:64:d8
pci/0000:08:00.0/3: type eth netdev enp8s0f0npf0vf3 flavour pcivf controller 0 pfnum 0 vfnum 3 external false splittable false
function:
hw_addr 4e:ef:ca:9e:e7:5d
pci/0000:08:00.0/4: type eth netdev enp8s0f0npf0vf1 flavour pcivf controller 0 pfnum 0 vfnum 1 external false splittable false
function:
hw_addr 5a:f0:e3:f8:41:93
pci/0000:08:00.0/5: type eth netdev enp8s0f0npf0vf2 flavour pcivf controller 0 pfnum 0 vfnum 2 external false splittable false
function:
hw_addr 00:11:22:33:44:55
pci/0000:08:00.1/0: type eth netdev enp8s0f1np1 flavour physical port 1 splittable falseroot@10:~# ip link show enp8s0f0np0
12: enp8s0f0np0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000
link/ether 40:a6:b7:18:dd:68 brd ff:ff:ff:ff:ff:ff
vf 0 link/ether 1a:33:f2:e7:64:d8 brd ff:ff:ff:ff:ff:ff, spoof checking on, link-state enable, trust off
vf 1 link/ether 5a:f0:e3:f8:41:93 brd ff:ff:ff:ff:ff:ff, spoof checking on, link-state enable, trust off
vf 2 link/ether 00:11:22:33:44:55 brd ff:ff:ff:ff:ff:ff, spoof checking on, link-state enable, trust off
vf 3 link/ether 4e:ef:ca:9e:e7:5d brd ff:ff:ff:ff:ff:ff, spoof checking on, link-state enable, trust offroot@10:~# ip link set dev enp8s0f0np0 vf 2 mac AA:BB:CC:DD:EE:FF
root@10:~# ip link show enp8s0f0np0
12: enp8s0f0np0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000
link/ether 40:a6:b7:18:dd:68 brd ff:ff:ff:ff:ff:ff
vf 0 link/ether 1a:33:f2:e7:64:d8 brd ff:ff:ff:ff:ff:ff, spoof checking on, link-state enable, trust off
vf 1 link/ether 5a:f0:e3:f8:41:93 brd ff:ff:ff:ff:ff:ff, spoof checking on, link-state enable, trust off
vf 2 link/ether aa:bb:cc:dd:ee:ff brd ff:ff:ff:ff:ff:ff, spoof checking on, link-state enable, trust off
vf 3 link/ether 4e:ef:ca:9e:e7:5d brd ff:ff:ff:ff:ff:ff, spoof checking on, link-state enable, trust offroot@10:~# devlink port show
pci/0000:08:00.0/0: type eth netdev enp8s0f0np0 flavour physical port 0 splittable true lanes 8
pci/0000:08:00.0/2: type eth netdev enp8s0f0npf0vf0 flavour pcivf controller 0 pfnum 0 vfnum 0 external false splittable false
function:
hw_addr 1a:33:f2:e7:64:d8
pci/0000:08:00.0/3: type eth netdev enp8s0f0npf0vf3 flavour pcivf controller 0 pfnum 0 vfnum 3 external false splittable false
function:
hw_addr 4e:ef:ca:9e:e7:5d
pci/0000:08:00.0/4: type eth netdev enp8s0f0npf0vf1 flavour pcivf controller 0 pfnum 0 vfnum 1 external false splittable false
function:
hw_addr 5a:f0:e3:f8:41:93
pci/0000:08:00.0/5: type eth netdev enp8s0f0npf0vf2 flavour pcivf controller 0 pfnum 0 vfnum 2 external false splittable false
function:
hw_addr aa:bb:cc:dd:ee:ff
pci/0000:08:00.1/0: type eth netdev enp8s0f1np1 flavour physical port 1 splittable falsePATCH v2 1/1 ice: Add get/set hw address for VFs using devlink commands
Changing the MAC address of the VF ports are not available via devlink. Add the function handlers to set and get the HW address for the VF ports.
--- drivers/net/ethernet/intel/ice/ice_devlink.c | 89 +++++++++++++++++++- 1 file changed, 88 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/ice/ice_devlink.c +88 -1
@@ -1576,6 +1576,92 @@ void ice_devlink_destroy_pf_port(struct ice_pf *pf)devlink_port_unregister (&pf->devlink_port); } +/** +* ice_devlink_port_get_vf_mac_address - .port_fn_hw_addr_get devlink handler +* @port: devlink port structure +* @hw_addr: MAC address of the port +* @hw_addr_len: length of MAC address +* @extack: extended netdev ack structure +* +* Callback for the devlink .port_fn_hw_addr_get operation +* Return: zero on success or an error code on failure. +*/ + +static int ice_devlink_port_get_vf_mac_address (struct devlink_port *port, +u8 *hw_addr,int *hw_addr_len, +struct netlink_ext_ack *extack) +{ +struct devlink *devlink = port->devlink; +struct ice_pf *pf =devlink_priv (devlink); +struct device *dev =ice_pf_to_dev (pf); +struct devlink_port_attrs *attrs = &port->attrs; +struct devlink_port_pci_vf_attrs *pci_vf; +int vf_id; +struct ice_vf *vf; + +if (attrs->flavour ==DEVLINK_PORT_FLAVOUR_PCI_VF ) { + pci_vf = &attrs->pci_vf; + vf_id = pci_vf->vf; + }else { +dev_err (dev,"Unable to get the vf id for PF %d\n" , pf->hw.pf_id); +return -EADDRNOTAVAIL ; + } + vf =ice_get_vf_by_id (pf, vf_id); +if (!vf) { +dev_err (dev,"Unable to get the vf for PF %d\n" , pf->hw.pf_id); +return -EINVAL ; + } +ether_addr_copy (hw_addr, vf->dev_lan_addr); + *hw_addr_len =ETH_ALEN ; +return 0 ; +} + +/** +* ice_devlink_port_set_vf_mac_address - .port_fn_hw_addr_set devlink handler +* @port: devlink port structure +* @hw_addr: MAC address of the port +* @hw_addr_len: length of MAC address +* @extack: extended netdev ack structure +* +* Callback for the devlink .port_fn_hw_addr_set operation +* Return: zero on success or an error code on failure. +*/ +static int ice_devlink_port_set_vf_mac_address (struct devlink_port *port, +const u8 *hw_addr, +int hw_addr_len, +struct netlink_ext_ack *extack) +{ +struct devlink *devlink = port->devlink; +struct ice_pf *pf =devlink_priv (devlink); +struct device *dev =ice_pf_to_dev (pf); +struct net_device *netdev = port->type_eth.netdev; +struct devlink_port_attrs *attrs = &port->attrs; +struct devlink_port_pci_vf_attrs *pci_vf; +int vf_id; +u8 mac[ETH_ALEN ]; + +if (attrs->flavour ==DEVLINK_PORT_FLAVOUR_PCI_VF ) { + pci_vf = &attrs->pci_vf; + vf_id = pci_vf->vf; + }else { +dev_err (dev,"Unable to get the vf id for PF %d\n" , pf->hw.pf_id); +return -EADDRNOTAVAIL ; + } + +if (!netdev) { +dev_err (dev,"Unable to get the netdev for PF %d\n" , pf->hw.pf_id); +return -EADDRNOTAVAIL ; + } +ether_addr_copy (mac, hw_addr); + +return ice_set_vf_mac (netdev, vf_id, mac); +} + +static const struct devlink_port_ops ice_devlink_vf_port_ops = { + .port_fn_hw_addr_get = ice_devlink_port_get_vf_mac_address, + .port_fn_hw_addr_set = ice_devlink_port_set_vf_mac_address, +}; +/** * ice_devlink_create_vf_port - Create a devlink port for this VF * @vf: the VF to create a port for
@@ -1611,7 +1697,8 @@ int ice_devlink_create_vf_port(struct ice_vf *vf)devlink_port_attrs_set (devlink_port, &attrs); devlink =priv_to_devlink (pf); - err =devlink_port_register (devlink, devlink_port, vsi->idx); + err =devlink_port_register_with_ops (devlink, devlink_port, + vsi->idx, &ice_devlink_vf_port_ops);if (err) {dev_err (dev,"Failed to create devlink port for VF %d, error %d\n" , vf->vf_id, err);
Signature · 1 line
2.39.3 (Apple Git-145)
Quoted 3 lines · Thu, Feb 08, 2024 at 09:24:55AM CET, [email protected] wrote:
Changing the MAC address of the VF ports are not available via devlink. Add the function handlers to set and get the HW address for the VF ports.
"VFs". Avoid the word "port" here, as it may falsely indicate you are talking about the eswitch representor port.
Quoted 26 lines
Signed-off-by Karthik Sundaravel <[email protected]>---
drivers/net/ethernet/intel/ice/ice_devlink.c| 89 +++++++++++++++++++-1 file changed, 88 insertions(+), 1 deletion(-)drivers/net/ethernet/intel/ice/ice_devlink.c +12
-0@@ -1576,6 +1576,92 @@ void ice_devlink_destroy_pf_port(struct ice_pf *pf)devlink_port_unregister (&pf->devlink_port); } +/** +* ice_devlink_port_get_vf_mac_address - .port_fn_hw_addr_get devlink handler +* @port: devlink port structure +* @hw_addr: MAC address of the port +* @hw_addr_len: length of MAC address +* @extack: extended netdev ack structure +* +* Callback for the devlink .port_fn_hw_addr_get operation +* Return: zero on success or an error code on failure. +*/ + +static int ice_devlink_port_get_vf_mac_address(struct devlink_port *port,
drivers/net/ethernet/intel/ice/ice_devlink.c void ice_devlink_destroy_pf_port(struct ice_pf *pf) · line 1600
Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_devlink.c +10
-0+ u8 *hw_addr, int *hw_addr_len, + struct netlink_ext_ack *extack) +{ +struct devlink *devlink = port->devlink; +struct ice_pf *pf =devlink_priv (devlink); +struct device *dev =ice_pf_to_dev (pf); +struct devlink_port_attrs *attrs = &port->attrs; +struct devlink_port_pci_vf_attrs *pci_vf; +int vf_id; +struct ice_vf *vf;
Reverse xmas tree:
https://www.kernel.org/doc/html/v6.7/process/maintainer-netdev.html#tl-dr
drivers/net/ethernet/intel/ice/ice_devlink.c void ice_devlink_destroy_pf_port(struct ice_pf *pf) · line 1606
Quoted 6 lines
drivers/net/ethernet/intel/ice/ice_devlink.c +6
-0+ +if (attrs->flavour ==DEVLINK_PORT_FLAVOUR_PCI_VF ) { + pci_vf = &attrs->pci_vf; + vf_id = pci_vf->vf; + }else { +dev_err (dev,"Unable to get the vf id for PF %d\n" , pf->hw.pf_id);
Fill the extack message instead.
drivers/net/ethernet/intel/ice/ice_devlink.c void ice_devlink_destroy_pf_port(struct ice_pf *pf) · line 1611
Quoted 5 lines
drivers/net/ethernet/intel/ice/ice_devlink.c +5
-0+return -EADDRNOTAVAIL ; + } + vf =ice_get_vf_by_id (pf, vf_id); +if (!vf) { +dev_err (dev,"Unable to get the vf for PF %d\n" , pf->hw.pf_id);
Fill the extack message instead.
Quoted 20 lines
drivers/net/ethernet/intel/ice/ice_devlink.c +20
-0+return -EINVAL ; + } +ether_addr_copy (hw_addr, vf->dev_lan_addr); + *hw_addr_len =ETH_ALEN ; +return 0 ; +} + +/** +* ice_devlink_port_set_vf_mac_address - .port_fn_hw_addr_set devlink handler +* @port: devlink port structure +* @hw_addr: MAC address of the port +* @hw_addr_len: length of MAC address +* @extack: extended netdev ack structure +* +* Callback for the devlink .port_fn_hw_addr_set operation +* Return: zero on success or an error code on failure. +*/ +static int ice_devlink_port_set_vf_mac_address(struct devlink_port *port, + const u8 *hw_addr, + int hw_addr_len,
drivers/net/ethernet/intel/ice/ice_devlink.c void ice_devlink_destroy_pf_port(struct ice_pf *pf) · line 1641
Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_devlink.c +10
-0+ struct netlink_ext_ack *extack) +{ +struct devlink *devlink = port->devlink; +struct ice_pf *pf =devlink_priv (devlink); +struct device *dev =ice_pf_to_dev (pf); +struct net_device *netdev = port->type_eth.netdev; +struct devlink_port_attrs *attrs = &port->attrs; +struct devlink_port_pci_vf_attrs *pci_vf; +int vf_id; +u8 mac[ETH_ALEN ];
Reverse xmas tree:
https://www.kernel.org/doc/html/v6.7/process/maintainer-netdev.html#tl-dr
drivers/net/ethernet/intel/ice/ice_devlink.c void ice_devlink_destroy_pf_port(struct ice_pf *pf) · line 1606
Quoted 6 lines
drivers/net/ethernet/intel/ice/ice_devlink.c +6
-0+ +if (attrs->flavour ==DEVLINK_PORT_FLAVOUR_PCI_VF ) { + pci_vf = &attrs->pci_vf; + vf_id = pci_vf->vf; + }else { +dev_err (dev,"Unable to get the vf id for PF %d\n" , pf->hw.pf_id);
Fill the extack message instead.
drivers/net/ethernet/intel/ice/ice_devlink.c void ice_devlink_destroy_pf_port(struct ice_pf *pf) · line 1652
Quoted 5 lines
drivers/net/ethernet/intel/ice/ice_devlink.c +5
-0+return -EADDRNOTAVAIL ; + } + +if (!netdev) { +dev_err (dev,"Unable to get the netdev for PF %d\n" , pf->hw.pf_id);
Fill the extack message instead.
Quoted 28 lines
drivers/net/ethernet/intel/ice/ice_devlink.c +14
-1+return -EADDRNOTAVAIL ; + } +ether_addr_copy (mac, hw_addr); + +return ice_set_vf_mac (netdev, vf_id, mac); +} + +static const struct devlink_port_ops ice_devlink_vf_port_ops = { + .port_fn_hw_addr_get = ice_devlink_port_get_vf_mac_address, + .port_fn_hw_addr_set = ice_devlink_port_set_vf_mac_address, +}; +/** * ice_devlink_create_vf_port - Create a devlink port for this VF * @vf: the VF to create a port for @@ -1611,7 +1697,8 @@ int ice_devlink_create_vf_port(struct ice_vf *vf)devlink_port_attrs_set (devlink_port, &attrs); devlink =priv_to_devlink (pf); - err =devlink_port_register (devlink, devlink_port, vsi->idx); + err =devlink_port_register_with_ops (devlink, devlink_port, + vsi->idx, &ice_devlink_vf_port_ops);if (err) {dev_err (dev,"Failed to create devlink port for VF %d, error %d\n" , vf->vf_id, err);Signature · 1 line
2.39.3 (Apple Git-145)