ice: get switch id on switchdev devices
[linux-2.6-microblaze.git] / drivers / net / ethernet / intel / ice / ice_devlink.c
index a230edb..d12852d 100644 (file)
@@ -647,6 +647,23 @@ void ice_devlink_unregister(struct ice_pf *pf)
        devlink_unregister(priv_to_devlink(pf));
 }
 
+/**
+ * ice_devlink_set_switch_id - Set unique switch id based on pci dsn
+ * @pf: the PF to create a devlink port for
+ * @ppid: struct with switch id information
+ */
+static void
+ice_devlink_set_switch_id(struct ice_pf *pf, struct netdev_phys_item_id *ppid)
+{
+       struct pci_dev *pdev = pf->pdev;
+       u64 id;
+
+       id = pci_get_dsn(pdev);
+
+       ppid->id_len = sizeof(id);
+       put_unaligned_be64(id, &ppid->id);
+}
+
 int ice_devlink_register_params(struct ice_pf *pf)
 {
        struct devlink *devlink = priv_to_devlink(pf);
@@ -704,6 +721,9 @@ int ice_devlink_create_pf_port(struct ice_pf *pf)
 
        attrs.flavour = DEVLINK_PORT_FLAVOUR_PHYSICAL;
        attrs.phys.port_number = pf->hw.bus.func;
+
+       ice_devlink_set_switch_id(pf, &attrs.switch_id);
+
        devlink_port_attrs_set(devlink_port, &attrs);
        devlink = priv_to_devlink(pf);
 
@@ -760,6 +780,8 @@ int ice_devlink_create_vf_port(struct ice_vf *vf)
        attrs.pci_vf.pf = pf->hw.bus.func;
        attrs.pci_vf.vf = vf->vf_id;
 
+       ice_devlink_set_switch_id(pf, &attrs.switch_id);
+
        devlink_port_attrs_set(devlink_port, &attrs);
        devlink = priv_to_devlink(pf);