Skip to content

Commit 4dbb4f9

Browse files
karthiksundaravelanguy11
authored andcommitted
ice: Add get/set hw address for VFs using devlink commands
Changing the MAC address of the VFs is currently unsupported via devlink. Add the function handlers to set and get the HW address for the VFs. Signed-off-by: Karthik Sundaravel <ksundara@redhat.com> Tested-by: Rafal Romanowski <rafal.romanowski@intel.com> Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
1 parent 28cf782 commit 4dbb4f9

File tree

3 files changed

+91
-10
lines changed

3 files changed

+91
-10
lines changed

drivers/net/ethernet/intel/ice/devlink/devlink_port.c

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,62 @@ void ice_devlink_destroy_pf_port(struct ice_pf *pf)
372372
devl_port_unregister(&pf->devlink_port);
373373
}
374374

375+
/**
376+
* ice_devlink_port_get_vf_fn_mac - .port_fn_hw_addr_get devlink handler
377+
* @port: devlink port structure
378+
* @hw_addr: MAC address of the port
379+
* @hw_addr_len: length of MAC address
380+
* @extack: extended netdev ack structure
381+
*
382+
* Callback for the devlink .port_fn_hw_addr_get operation
383+
* Return: zero on success or an error code on failure.
384+
*/
385+
static int ice_devlink_port_get_vf_fn_mac(struct devlink_port *port,
386+
u8 *hw_addr, int *hw_addr_len,
387+
struct netlink_ext_ack *extack)
388+
{
389+
struct ice_vf *vf = container_of(port, struct ice_vf, devlink_port);
390+
391+
ether_addr_copy(hw_addr, vf->dev_lan_addr);
392+
*hw_addr_len = ETH_ALEN;
393+
394+
return 0;
395+
}
396+
397+
/**
398+
* ice_devlink_port_set_vf_fn_mac - .port_fn_hw_addr_set devlink handler
399+
* @port: devlink port structure
400+
* @hw_addr: MAC address of the port
401+
* @hw_addr_len: length of MAC address
402+
* @extack: extended netdev ack structure
403+
*
404+
* Callback for the devlink .port_fn_hw_addr_set operation
405+
* Return: zero on success or an error code on failure.
406+
*/
407+
static int ice_devlink_port_set_vf_fn_mac(struct devlink_port *port,
408+
const u8 *hw_addr,
409+
int hw_addr_len,
410+
struct netlink_ext_ack *extack)
411+
412+
{
413+
struct devlink_port_attrs *attrs = &port->attrs;
414+
struct devlink_port_pci_vf_attrs *pci_vf;
415+
struct devlink *devlink = port->devlink;
416+
struct ice_pf *pf;
417+
u16 vf_id;
418+
419+
pf = devlink_priv(devlink);
420+
pci_vf = &attrs->pci_vf;
421+
vf_id = pci_vf->vf;
422+
423+
return __ice_set_vf_mac(pf, vf_id, hw_addr);
424+
}
425+
426+
static const struct devlink_port_ops ice_devlink_vf_port_ops = {
427+
.port_fn_hw_addr_get = ice_devlink_port_get_vf_fn_mac,
428+
.port_fn_hw_addr_set = ice_devlink_port_set_vf_fn_mac,
429+
};
430+
375431
/**
376432
* ice_devlink_create_vf_port - Create a devlink port for this VF
377433
* @vf: the VF to create a port for
@@ -407,7 +463,8 @@ int ice_devlink_create_vf_port(struct ice_vf *vf)
407463
devlink_port_attrs_set(devlink_port, &attrs);
408464
devlink = priv_to_devlink(pf);
409465

410-
err = devl_port_register(devlink, devlink_port, vsi->idx);
466+
err = devl_port_register_with_ops(devlink, devlink_port, vsi->idx,
467+
&ice_devlink_vf_port_ops);
411468
if (err) {
412469
dev_err(dev, "Failed to create devlink port for VF %d, error %d\n",
413470
vf->vf_id, err);

drivers/net/ethernet/intel/ice/ice_sriov.c

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,21 +1416,23 @@ ice_get_vf_cfg(struct net_device *netdev, int vf_id, struct ifla_vf_info *ivi)
14161416
}
14171417

14181418
/**
1419-
* ice_set_vf_mac
1420-
* @netdev: network interface device structure
1419+
* __ice_set_vf_mac - program VF MAC address
1420+
* @pf: PF to be configure
14211421
* @vf_id: VF identifier
14221422
* @mac: MAC address
14231423
*
14241424
* program VF MAC address
1425+
* Return: zero on success or an error code on failure
14251426
*/
1426-
int ice_set_vf_mac(struct net_device *netdev, int vf_id, u8 *mac)
1427+
int __ice_set_vf_mac(struct ice_pf *pf, u16 vf_id, const u8 *mac)
14271428
{
1428-
struct ice_pf *pf = ice_netdev_to_pf(netdev);
1429+
struct device *dev;
14291430
struct ice_vf *vf;
14301431
int ret;
14311432

1433+
dev = ice_pf_to_dev(pf);
14321434
if (is_multicast_ether_addr(mac)) {
1433-
netdev_err(netdev, "%pM not a valid unicast address\n", mac);
1435+
dev_err(dev, "%pM not a valid unicast address\n", mac);
14341436
return -EINVAL;
14351437
}
14361438

@@ -1459,13 +1461,13 @@ int ice_set_vf_mac(struct net_device *netdev, int vf_id, u8 *mac)
14591461
if (is_zero_ether_addr(mac)) {
14601462
/* VF will send VIRTCHNL_OP_ADD_ETH_ADDR message with its MAC */
14611463
vf->pf_set_mac = false;
1462-
netdev_info(netdev, "Removing MAC on VF %d. VF driver will be reinitialized\n",
1463-
vf->vf_id);
1464+
dev_info(dev, "Removing MAC on VF %d. VF driver will be reinitialized\n",
1465+
vf->vf_id);
14641466
} else {
14651467
/* PF will add MAC rule for the VF */
14661468
vf->pf_set_mac = true;
1467-
netdev_info(netdev, "Setting MAC %pM on VF %d. VF driver will be reinitialized\n",
1468-
mac, vf_id);
1469+
dev_info(dev, "Setting MAC %pM on VF %d. VF driver will be reinitialized\n",
1470+
mac, vf_id);
14691471
}
14701472

14711473
ice_reset_vf(vf, ICE_VF_RESET_NOTIFY);
@@ -1476,6 +1478,20 @@ int ice_set_vf_mac(struct net_device *netdev, int vf_id, u8 *mac)
14761478
return ret;
14771479
}
14781480

1481+
/**
1482+
* ice_set_vf_mac - .ndo_set_vf_mac handler
1483+
* @netdev: network interface device structure
1484+
* @vf_id: VF identifier
1485+
* @mac: MAC address
1486+
*
1487+
* program VF MAC address
1488+
* Return: zero on success or an error code on failure
1489+
*/
1490+
int ice_set_vf_mac(struct net_device *netdev, int vf_id, u8 *mac)
1491+
{
1492+
return __ice_set_vf_mac(ice_netdev_to_pf(netdev), vf_id, mac);
1493+
}
1494+
14791495
/**
14801496
* ice_set_vf_trust
14811497
* @netdev: network interface device structure

drivers/net/ethernet/intel/ice/ice_sriov.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#ifdef CONFIG_PCI_IOV
2929
void ice_process_vflr_event(struct ice_pf *pf);
3030
int ice_sriov_configure(struct pci_dev *pdev, int num_vfs);
31+
int __ice_set_vf_mac(struct ice_pf *pf, u16 vf_id, const u8 *mac);
3132
int ice_set_vf_mac(struct net_device *netdev, int vf_id, u8 *mac);
3233
int
3334
ice_get_vf_cfg(struct net_device *netdev, int vf_id, struct ifla_vf_info *ivi);
@@ -80,6 +81,13 @@ ice_sriov_configure(struct pci_dev __always_unused *pdev,
8081
return -EOPNOTSUPP;
8182
}
8283

84+
static inline int
85+
__ice_set_vf_mac(struct ice_pf __always_unused *pf,
86+
u16 __always_unused vf_id, const u8 __always_unused *mac)
87+
{
88+
return -EOPNOTSUPP;
89+
}
90+
8391
static inline int
8492
ice_set_vf_mac(struct net_device __always_unused *netdev,
8593
int __always_unused vf_id, u8 __always_unused *mac)

0 commit comments

Comments
 (0)