@@ -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
@@ -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);
@@ -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;
+}
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 <parav@nvidia.com> --- drivers/net/netdevsim/dev.c | 1 + drivers/net/netdevsim/netdevsim.h | 4 ++++ drivers/net/netdevsim/port_function.c | 21 +++++++++++++++++++++ 3 files changed, 26 insertions(+)