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
5050 u16 pf; /* Associated PCI PF for this port. */
5151 };
5252
53+struct 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+
5358 struct devlink_port_attrs {
5459 u8 set:1,
5560 split:1,
@@ -59,6 +64,7 @@ struct devlink_port_attrs { · 3 unmodified lines
5964 union {
6065 struct devlink_port_phys_attrs phys;
6166 struct devlink_port_pci_pf_attrs pci_pf;
67+ struct devlink_port_pci_vf_attrs pci_vf;
6268 };
6369 };
6470
@@ -607,6 +613,10 @@ void devlink_port_attrs_set(struct devlink_port *devlink_port, · 542 unmodified lines
607613 void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port,
608614 const unsigned char *switch_id,
609615 unsigned char switch_id_len, u16 pf);
616+void 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);
610620 int devlink_sb_register(struct devlink *devlink, unsigned int sb_index,
611621 u32 size, u16 ingress_pools_count,
612622 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
173173 * the PCI PF. It is an internal
174174 * port that faces the PCI PF.
175175 */
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+ */
176180 };
177181
178182 enum devlink_param_cmode {
@@ -342,6 +346,8 @@ enum devlink_attr { · 163 unmodified lines
342346 DEVLINK_ATTR_FLASH_UPDATE_STATUS_TOTAL, /* u64 */
343347
344348 DEVLINK_ATTR_PORT_PCI_PF_NUMBER, /* u16 */
349+ DEVLINK_ATTR_PORT_PCI_VF_NUMBER, /* u16 */
350+
345351 /* add new attributes above here, update the policy in devlink.c */
346352
347353 __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
519519 if (nla_put_u16(msg, DEVLINK_ATTR_PORT_PCI_PF_NUMBER,
520520 attrs->pci_pf.pf))
521521 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;
522528 }
523529 if (devlink_port->attrs.flavour != DEVLINK_PORT_FLAVOUR_PHYSICAL &&
524530 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
58325838 }
58335839 EXPORT_SYMBOL_GPL(devlink_port_attrs_pci_pf_set);
58345840
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+ */
5851+void 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+}
5867+EXPORT_SYMBOL_GPL(devlink_port_attrs_pci_vf_set);
5868+
58355869 static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port,
58365870 char *name, size_t len)
58375871 {
@@ -5860,6 +5894,10 @@ static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port, · 22 unmodified lines
58605894 case DEVLINK_PORT_FLAVOUR_PCI_PF:
58615895 n = snprintf(name, len, "pf%u", attrs->pci_pf.pf);
58625896 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;
58635901 }
58645902
58655903 if (n >= len)