Skip to content

Commit dd4ea1d

Browse files
Sathya Perladavem330
authored andcommitted
bnxt_en: export a common switchdev PARENT_ID for all reps of an adapter
Currently the driver exports different switchdev PARENT_IDs for representors belonging to different SR-IOV PF-pools of an adapter. This is not correct as the adapter can switch across all vports of an adapter. This patch fixes this by exporting a common switchdev PARENT_ID for all reps of an adapter. The PCIE DSN is used as the id. Signed-off-by: Sathya Perla <[email protected]> Signed-off-by: Michael Chan <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent c3480a6 commit dd4ea1d

File tree

5 files changed

+40
-7
lines changed

5 files changed

+40
-7
lines changed

drivers/net/ethernet/broadcom/bnxt/bnxt.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8149,12 +8149,8 @@ int bnxt_port_attr_get(struct bnxt *bp, struct switchdev_attr *attr)
81498149

81508150
switch (attr->id) {
81518151
case SWITCHDEV_ATTR_ID_PORT_PARENT_ID:
8152-
/* In SRIOV each PF-pool (PF + child VFs) serves as a
8153-
* switching domain, the PF's perm mac-addr can be used
8154-
* as the unique parent-id
8155-
*/
8156-
attr->u.ppid.id_len = ETH_ALEN;
8157-
ether_addr_copy(attr->u.ppid.id, bp->pf.mac_addr);
8152+
attr->u.ppid.id_len = sizeof(bp->switch_id);
8153+
memcpy(attr->u.ppid.id, bp->switch_id, attr->u.ppid.id_len);
81588154
break;
81598155
default:
81608156
return -EOPNOTSUPP;

drivers/net/ethernet/broadcom/bnxt/bnxt.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,6 +1371,7 @@ struct bnxt {
13711371
enum devlink_eswitch_mode eswitch_mode;
13721372
struct bnxt_vf_rep **vf_reps; /* array of vf-rep ptrs */
13731373
u16 *cfa_code_map; /* cfa_code -> vf_idx map */
1374+
u8 switch_id[8];
13741375
struct bnxt_tc_info *tc_info;
13751376
};
13761377

drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ static u16 bnxt_flow_get_dst_fid(struct bnxt *pf_bp, struct net_device *dev)
4343
}
4444

4545
/* Is dev a VF-rep? */
46-
if (dev != pf_bp->dev)
46+
if (bnxt_dev_is_vf_rep(dev))
4747
return bnxt_vf_rep_get_fid(dev);
4848

4949
bp = netdev_priv(dev);

drivers/net/ethernet/broadcom/bnxt/bnxt_vfr.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,11 @@ static const struct net_device_ops bnxt_vf_rep_netdev_ops = {
241241
.ndo_get_phys_port_name = bnxt_vf_rep_get_phys_port_name
242242
};
243243

244+
bool bnxt_dev_is_vf_rep(struct net_device *dev)
245+
{
246+
return dev->netdev_ops == &bnxt_vf_rep_netdev_ops;
247+
}
248+
244249
/* Called when the parent PF interface is closed:
245250
* As the mode transition from SWITCHDEV to LEGACY
246251
* happens under the rtnl_lock() this routine is safe
@@ -376,6 +381,26 @@ static void bnxt_vf_rep_netdev_init(struct bnxt *bp, struct bnxt_vf_rep *vf_rep,
376381
ether_addr_copy(dev->dev_addr, dev->perm_addr);
377382
}
378383

384+
static int bnxt_pcie_dsn_get(struct bnxt *bp, u8 dsn[])
385+
{
386+
struct pci_dev *pdev = bp->pdev;
387+
int pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_DSN);
388+
u32 dw;
389+
390+
if (!pos) {
391+
netdev_info(bp->dev, "Unable do read adapter's DSN");
392+
return -EOPNOTSUPP;
393+
}
394+
395+
/* DSN (two dw) is at an offset of 4 from the cap pos */
396+
pos += 4;
397+
pci_read_config_dword(pdev, pos, &dw);
398+
put_unaligned_le32(dw, &dsn[0]);
399+
pci_read_config_dword(pdev, pos + 4, &dw);
400+
put_unaligned_le32(dw, &dsn[4]);
401+
return 0;
402+
}
403+
379404
static int bnxt_vf_reps_create(struct bnxt *bp)
380405
{
381406
u16 *cfa_code_map = NULL, num_vfs = pci_num_vf(bp->pdev);
@@ -440,6 +465,11 @@ static int bnxt_vf_reps_create(struct bnxt *bp)
440465
}
441466
}
442467

468+
/* Read the adapter's DSN to use as the eswitch switch_id */
469+
rc = bnxt_pcie_dsn_get(bp, bp->switch_id);
470+
if (rc)
471+
goto err;
472+
443473
/* publish cfa_code_map only after all VF-reps have been initialized */
444474
bp->cfa_code_map = cfa_code_map;
445475
bp->eswitch_mode = DEVLINK_ESWITCH_MODE_SWITCHDEV;

drivers/net/ethernet/broadcom/bnxt/bnxt_vfr.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ static inline u16 bnxt_vf_rep_get_fid(struct net_device *dev)
2828
return bp->pf.vf[vf_rep->vf_idx].fw_fid;
2929
}
3030

31+
bool bnxt_dev_is_vf_rep(struct net_device *dev);
3132
int bnxt_dl_eswitch_mode_get(struct devlink *devlink, u16 *mode);
3233
int bnxt_dl_eswitch_mode_set(struct devlink *devlink, u16 mode);
3334

@@ -54,5 +55,10 @@ static inline u16 bnxt_vf_rep_get_fid(struct net_device *dev)
5455
{
5556
return 0;
5657
}
58+
59+
static inline bool bnxt_dev_is_vf_rep(struct net_device *dev)
60+
{
61+
return false;
62+
}
5763
#endif /* CONFIG_BNXT_SRIOV */
5864
#endif /* BNXT_VFR_H */

0 commit comments

Comments
 (0)