History

devlink: Introduce PCI VF port flavour and port attribute

In an eswitch, PCI VF may have port which is normally represented using a representor netdevice. To have better visibility of eswitch port, its association with VF, and its representor netdevice, introduce a PCI VF port flavour. When devlink port flavour is PCI VF, fill up PCI VF attributes of the port. Extend port name creation using PCI PF and VF number scheme on best effort basis, so that vendor drivers can skip defining their own scheme. $ devlink port show pci/0000:05:00.0/0: type eth netdev eth0 flavour pcipf pfnum 0 pci/0000:05:00.0/1: type eth netdev eth1 flavour pcivf pfnum 0 vfnum 0 pci/0000:05:00.0/2: type eth netdev eth2 flavour pcivf pfnum 0 vfnum 1

Parav Pandit committed 7 years ago

Commit e41b6bf1 parent 98fd2d63 files · +54 −0Browse files

Unified · Split

3 files
  1. include/net/devlink.h +10 −0
  2. include/uapi/linux/devlink.h +6 −0
  3. net/core/devlink.c +38 −0
include/net/devlink.h+10−0
@@ -50,6 +50,11 @@ struct devlink_port_pci_pf_attrs { · 49 unmodified lines
50 u16 pf; /* Associated PCI PF for this port. */50 u16 pf; /* Associated PCI PF for this port. */
51};51};
52 52
53struct devlink_port_pci_vf_attrs {
54 u16 pf; /* Associated PCI PF for this port. */
55 u16 vf; /* Associated PCI VF for of the PCI PF for this port. */
56};
57
53struct devlink_port_attrs {58struct devlink_port_attrs {
54 u8 set:1,59 u8 set:1,
55 split:1,60 split:1,
@@ -59,6 +64,7 @@ struct devlink_port_attrs { · 3 unmodified lines
59 union {64 union {
60 struct devlink_port_phys_attrs phys;65 struct devlink_port_phys_attrs phys;
61 struct devlink_port_pci_pf_attrs pci_pf;66 struct devlink_port_pci_pf_attrs pci_pf;
67 struct devlink_port_pci_vf_attrs pci_vf;
62 };68 };
63};69};
64 70
@@ -607,6 +613,10 @@ void devlink_port_attrs_set(struct devlink_port *devlink_port, · 542 unmodified lines
607void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port,613void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port,
608 const unsigned char *switch_id,614 const unsigned char *switch_id,
609 unsigned char switch_id_len, u16 pf);615 unsigned char switch_id_len, u16 pf);
616void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port,
617 const unsigned char *switch_id,
618 unsigned char switch_id_len,
619 u16 pf, u16 vf);
610int devlink_sb_register(struct devlink *devlink, unsigned int sb_index,620int devlink_sb_register(struct devlink *devlink, unsigned int sb_index,
611 u32 size, u16 ingress_pools_count,621 u32 size, u16 ingress_pools_count,
612 u16 egress_pools_count, u16 ingress_tc_count,622 u16 egress_pools_count, u16 ingress_tc_count,
include/uapi/linux/devlink.h+6−0
@@ -173,6 +173,10 @@ enum devlink_port_flavour { · 172 unmodified lines
173 * the PCI PF. It is an internal173 * the PCI PF. It is an internal
174 * port that faces the PCI PF.174 * port that faces the PCI PF.
175 */175 */
176 DEVLINK_PORT_FLAVOUR_PCI_VF, /* Represents eswitch port
177 * for the PCI VF. It is an internal
178 * port that faces the PCI VF.
179 */
176};180};
177 181
178enum devlink_param_cmode {182enum devlink_param_cmode {
@@ -342,6 +346,8 @@ enum devlink_attr { · 163 unmodified lines
342 DEVLINK_ATTR_FLASH_UPDATE_STATUS_TOTAL, /* u64 */346 DEVLINK_ATTR_FLASH_UPDATE_STATUS_TOTAL, /* u64 */
343 347
344 DEVLINK_ATTR_PORT_PCI_PF_NUMBER, /* u16 */348 DEVLINK_ATTR_PORT_PCI_PF_NUMBER, /* u16 */
349 DEVLINK_ATTR_PORT_PCI_VF_NUMBER, /* u16 */
350
345 /* add new attributes above here, update the policy in devlink.c */351 /* add new attributes above here, update the policy in devlink.c */
346 352
347 __DEVLINK_ATTR_MAX,353 __DEVLINK_ATTR_MAX,
net/core/devlink.c+38−0
@@ -519,6 +519,12 @@ static int devlink_nl_port_attrs_put(struct sk_buff *msg, · 518 unmodified lines
519 if (nla_put_u16(msg, DEVLINK_ATTR_PORT_PCI_PF_NUMBER,519 if (nla_put_u16(msg, DEVLINK_ATTR_PORT_PCI_PF_NUMBER,
520 attrs->pci_pf.pf))520 attrs->pci_pf.pf))
521 return -EMSGSIZE;521 return -EMSGSIZE;
522 } else if (devlink_port->attrs.flavour == DEVLINK_PORT_FLAVOUR_PCI_VF) {
523 if (nla_put_u16(msg, DEVLINK_ATTR_PORT_PCI_PF_NUMBER,
524 attrs->pci_vf.pf) ||
525 nla_put_u16(msg, DEVLINK_ATTR_PORT_PCI_VF_NUMBER,
526 attrs->pci_vf.vf))
527 return -EMSGSIZE;
522 }528 }
523 if (devlink_port->attrs.flavour != DEVLINK_PORT_FLAVOUR_PHYSICAL &&529 if (devlink_port->attrs.flavour != DEVLINK_PORT_FLAVOUR_PHYSICAL &&
524 devlink_port->attrs.flavour != DEVLINK_PORT_FLAVOUR_CPU &&530 devlink_port->attrs.flavour != DEVLINK_PORT_FLAVOUR_CPU &&
@@ -5832,6 +5838,34 @@ void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port, · 5307 unmodified lines
5832}5838}
5833EXPORT_SYMBOL_GPL(devlink_port_attrs_pci_pf_set);5839EXPORT_SYMBOL_GPL(devlink_port_attrs_pci_pf_set);
5834 5840
5841/**
5842 * devlink_port_attrs_pci_vf_set - Set PCI VF port attributes
5843 *
5844 * @devlink_port: devlink port
5845 * @pf: associated PF for the devlink port instance
5846 * @vf: associated VF of a PF for the devlink port instance
5847 * @switch_id: if the port is part of switch, this is buffer with ID,
5848 * otherwise this is NULL
5849 * @switch_id_len: length of the switch_id buffer
5850 */
5851void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port,
5852 const unsigned char *switch_id,
5853 unsigned char switch_id_len,
5854 u16 pf, u16 vf)
5855{
5856 struct devlink_port_attrs *attrs = &devlink_port->attrs;
5857 int ret;
5858
5859 ret = __devlink_port_attrs_set(devlink_port,
5860 DEVLINK_PORT_FLAVOUR_PCI_VF,
5861 switch_id, switch_id_len);
5862 if (ret)
5863 return;
5864 attrs->pci_vf.pf = pf;
5865 attrs->pci_vf.vf = vf;
5866}
5867EXPORT_SYMBOL_GPL(devlink_port_attrs_pci_vf_set);
5868
5835static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port,5869static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port,
5836 char *name, size_t len)5870 char *name, size_t len)
5837{5871{
@@ -5860,6 +5894,10 @@ static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port, · 22 unmodified lines
5860 case DEVLINK_PORT_FLAVOUR_PCI_PF:5894 case DEVLINK_PORT_FLAVOUR_PCI_PF:
5861 n = snprintf(name, len, "pf%u", attrs->pci_pf.pf);5895 n = snprintf(name, len, "pf%u", attrs->pci_pf.pf);
5862 break;5896 break;
5897 case DEVLINK_PORT_FLAVOUR_PCI_VF:
5898 n = snprintf(name, len, "pf%uvf%u",
5899 attrs->pci_vf.pf, attrs->pci_vf.vf);
5900 break;
5863 }5901 }
5864 5902
5865 if (n >= len)5903 if (n >= len)