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" } } } }
Unified · Split
| @@ -1107,6 +1107,18 @@ struct devlink_ops { · 1106 unmodified lines | |||
| 1107 | int (*trap_policer_counter_get)(struct devlink *devlink, | 1107 | int (*trap_policer_counter_get)(struct devlink *devlink, |
| 1108 | const struct devlink_trap_policer *policer, | 1108 | const struct devlink_trap_policer *policer, |
| 1109 | u64 *p_drops); | 1109 | 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); | ||
| 1110 | }; | 1122 | }; |
| 1111 | 1123 | ||
| 1112 | static inline void *devlink_priv(struct devlink *devlink) | 1124 | static inline void *devlink_priv(struct devlink *devlink) |
| @@ -451,6 +451,8 @@ enum devlink_attr { · 450 unmodified lines | |||
| 451 | DEVLINK_ATTR_TRAP_POLICER_RATE, /* u64 */ | 451 | DEVLINK_ATTR_TRAP_POLICER_RATE, /* u64 */ |
| 452 | DEVLINK_ATTR_TRAP_POLICER_BURST, /* u64 */ | 452 | DEVLINK_ATTR_TRAP_POLICER_BURST, /* u64 */ |
| 453 | 453 | ||
| 454 | DEVLINK_ATTR_PORT_FUNCTION, /* nested */ | ||
| 455 | |||
| 454 | /* add new attributes above here, update the policy in devlink.c */ | 456 | /* add new attributes above here, update the policy in devlink.c */ |
| 455 | 457 | ||
| 456 | __DEVLINK_ATTR_MAX, | 458 | __DEVLINK_ATTR_MAX, |
| @@ -497,4 +499,12 @@ enum devlink_resource_unit { · 40 unmodified lines | |||
| 497 | DEVLINK_RESOURCE_UNIT_ENTRY, | 499 | DEVLINK_RESOURCE_UNIT_ENTRY, |
| 498 | }; | 500 | }; |
| 499 | 501 | ||
| 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 | |||
| 500 | #endif /* _UAPI_LINUX_DEVLINK_H_ */ | 510 | #endif /* _UAPI_LINUX_DEVLINK_H_ */ |
| @@ -563,6 +563,49 @@ static int devlink_nl_port_attrs_put(struct sk_buff *msg, · 562 unmodified lines | |||
| 563 | return 0; | 563 | return 0; |
| 564 | } | 564 | } |
| 565 | 565 | ||
| 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 | |||
| 566 | static int devlink_nl_port_fill(struct sk_buff *msg, struct devlink *devlink, | 609 | static int devlink_nl_port_fill(struct sk_buff *msg, struct devlink *devlink, |
| 567 | struct devlink_port *devlink_port, | 610 | struct devlink_port *devlink_port, |
| 568 | enum devlink_command cmd, u32 portid, | 611 | 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 | |||
| 608 | spin_unlock_bh(&devlink_port->type_lock); | 651 | spin_unlock_bh(&devlink_port->type_lock); |
| 609 | if (devlink_nl_port_attrs_put(msg, devlink_port)) | 652 | if (devlink_nl_port_attrs_put(msg, devlink_port)) |
| 610 | goto nla_put_failure; | 653 | goto nla_put_failure; |
| 654 | if (devlink_nl_port_function_attrs_put(msg, devlink_port, extack)) | ||
| 655 | goto nla_put_failure; | ||
| 611 | 656 | ||
| 612 | genlmsg_end(msg, hdr); | 657 | genlmsg_end(msg, hdr); |
| 613 | return 0; | 658 | return 0; |