History

net/devlink: Support querying hardware address of port function

PCI PF and VF devlink port can manage the function represented by a devlink port. Enable users to query port function's hardware address. Example of a PCI VF port which supports a port function: $ devlink port show pci/0000:06:00.0/2 pci/0000:06:00.0/2: type eth netdev enp6s0pf0vf1 flavour pcivf pfnum 0 vfnum 1 function: hw_addr 00:11:22:33:44:66 $ devlink port show pci/0000:06:00.0/2 -jp { "port": { "pci/0000:06:00.0/2": { "type": "eth", "netdev": "enp6s0pf0vf1", "flavour": "pcivf", "pfnum": 0, "vfnum": 1, "function": { "hw_addr": "00:11:22:33:44:66" } } } }

Parav Pandit committed 6 years ago

Commit 2a916ec1 parent a829eb03 files · +67 −0Browse files

Unified · Split

3 files
  1. include/net/devlink.h +12 −0
  2. include/uapi/linux/devlink.h +10 −0
  3. net/core/devlink.c +45 −0
include/net/devlink.h+12−0
@@ -1107,6 +1107,18 @@ struct devlink_ops { · 1106 unmodified lines
11071107 int (*trap_policer_counter_get)(struct devlink *devlink,
11081108 const struct devlink_trap_policer *policer,
11091109 u64 *p_drops);
1110+ /**
1111+ * @port_function_hw_addr_get: Port function's hardware address get function.
1112+ *
1113+ * Should be used by device drivers to report the hardware address of a function managed
1114+ * by the devlink port. Driver should return -EOPNOTSUPP if it doesn't support port
1115+ * function handling for a particular port.
1116+ *
1117+ * Note: @extack can be NULL when port notifier queries the port function.
1118+ */
1119+ int (*port_function_hw_addr_get)(struct devlink *devlink, struct devlink_port *port,
1120+ u8 *hw_addr, int *hw_addr_len,
1121+ struct netlink_ext_ack *extack);
11101122 };
11111123
11121124 static inline void *devlink_priv(struct devlink *devlink)
include/uapi/linux/devlink.h+10−0
@@ -451,6 +451,8 @@ enum devlink_attr { · 450 unmodified lines
451451 DEVLINK_ATTR_TRAP_POLICER_RATE, /* u64 */
452452 DEVLINK_ATTR_TRAP_POLICER_BURST, /* u64 */
453453
454+ DEVLINK_ATTR_PORT_FUNCTION, /* nested */
455+
454456 /* add new attributes above here, update the policy in devlink.c */
455457
456458 __DEVLINK_ATTR_MAX,
@@ -497,4 +499,12 @@ enum devlink_resource_unit { · 40 unmodified lines
497499 DEVLINK_RESOURCE_UNIT_ENTRY,
498500 };
499501
502+enum devlink_port_function_attr {
503+ DEVLINK_PORT_FUNCTION_ATTR_UNSPEC,
504+ DEVLINK_PORT_FUNCTION_ATTR_HW_ADDR, /* binary */
505+
506+ __DEVLINK_PORT_FUNCTION_ATTR_MAX,
507+ DEVLINK_PORT_FUNCTION_ATTR_MAX = __DEVLINK_PORT_FUNCTION_ATTR_MAX - 1
508+};
509+
500510 #endif /* _UAPI_LINUX_DEVLINK_H_ */
net/core/devlink.c+45−0
@@ -563,6 +563,49 @@ static int devlink_nl_port_attrs_put(struct sk_buff *msg, · 562 unmodified lines
563563 return 0;
564564 }
565565
566+static int
567+devlink_nl_port_function_attrs_put(struct sk_buff *msg, struct devlink_port *port,
568+ struct netlink_ext_ack *extack)
569+{
570+ struct devlink *devlink = port->devlink;
571+ const struct devlink_ops *ops;
572+ struct nlattr *function_attr;
573+ bool empty_nest = true;
574+ int err = 0;
575+
576+ function_attr = nla_nest_start_noflag(msg, DEVLINK_ATTR_PORT_FUNCTION);
577+ if (!function_attr)
578+ return -EMSGSIZE;
579+
580+ ops = devlink->ops;
581+ if (ops->port_function_hw_addr_get) {
582+ int uninitialized_var(hw_addr_len);
583+ u8 hw_addr[MAX_ADDR_LEN];
584+
585+ err = ops->port_function_hw_addr_get(devlink, port, hw_addr, &hw_addr_len, extack);
586+ if (err == -EOPNOTSUPP) {
587+ /* Port function attributes are optional for a port. If port doesn't
588+ * support function attribute, returning -EOPNOTSUPP is not an error.
589+ */
590+ err = 0;
591+ goto out;
592+ } else if (err) {
593+ goto out;
594+ }
595+ err = nla_put(msg, DEVLINK_PORT_FUNCTION_ATTR_HW_ADDR, hw_addr_len, hw_addr);
596+ if (err)
597+ goto out;
598+ empty_nest = false;
599+ }
600+
601+out:
602+ if (err || empty_nest)
603+ nla_nest_cancel(msg, function_attr);
604+ else
605+ nla_nest_end(msg, function_attr);
606+ return err;
607+}
608+
566609 static int devlink_nl_port_fill(struct sk_buff *msg, struct devlink *devlink,
567610 struct devlink_port *devlink_port,
568611 enum devlink_command cmd, u32 portid,
@@ -608,6 +651,8 @@ static int devlink_nl_port_fill(struct sk_buff *msg, struct devlink *devlink, · 39 unmodified lines
608651 spin_unlock_bh(&devlink_port->type_lock);
609652 if (devlink_nl_port_attrs_put(msg, devlink_port))
610653 goto nla_put_failure;
654+ if (devlink_nl_port_function_attrs_put(msg, devlink_port, extack))
655+ goto nla_put_failure;
611656
612657 genlmsg_end(msg, hdr);
613658 return 0;