Skip to content

Commit

Permalink
net/smc: Use rdma_read_gid_l2_fields to L2 fields
Browse files Browse the repository at this point in the history
Use core provided API to fill the source MAC address and use
rdma_read_gid_attr_ndev_rcu() to get stable netdev.

This is preparation patch to allow gid attribute to become NULL when
associated net device is removed.

Signed-off-by: Parav Pandit <[email protected]>
Signed-off-by: Leon Romanovsky <[email protected]>
Signed-off-by: Jason Gunthorpe <[email protected]>
  • Loading branch information
paravmellanox authored and jgunthorpe committed May 3, 2019
1 parent dab2175 commit 5102eca
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions net/smc/smc_ib.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,18 +146,13 @@ int smc_ib_ready_link(struct smc_link *lnk)
static int smc_ib_fill_mac(struct smc_ib_device *smcibdev, u8 ibport)
{
const struct ib_gid_attr *attr;
int rc = 0;
int rc;

attr = rdma_get_gid_attr(smcibdev->ibdev, ibport, 0);
if (IS_ERR(attr))
return -ENODEV;

if (attr->ndev)
memcpy(smcibdev->mac[ibport - 1], attr->ndev->dev_addr,
ETH_ALEN);
else
rc = -ENODEV;

rc = rdma_read_gid_l2_fields(attr, NULL, smcibdev->mac[ibport - 1]);
rdma_put_gid_attr(attr);
return rc;
}
Expand Down Expand Up @@ -185,25 +180,30 @@ int smc_ib_determine_gid(struct smc_ib_device *smcibdev, u8 ibport,
unsigned short vlan_id, u8 gid[], u8 *sgid_index)
{
const struct ib_gid_attr *attr;
const struct net_device *ndev;
int i;

for (i = 0; i < smcibdev->pattr[ibport - 1].gid_tbl_len; i++) {
attr = rdma_get_gid_attr(smcibdev->ibdev, ibport, i);
if (IS_ERR(attr))
continue;

if (attr->ndev &&
rcu_read_lock();
ndev = rdma_read_gid_attr_ndev_rcu(attr);
if (!IS_ERR(ndev) &&
((!vlan_id && !is_vlan_dev(attr->ndev)) ||
(vlan_id && is_vlan_dev(attr->ndev) &&
vlan_dev_vlan_id(attr->ndev) == vlan_id)) &&
attr->gid_type == IB_GID_TYPE_ROCE) {
rcu_read_unlock();
if (gid)
memcpy(gid, &attr->gid, SMC_GID_SIZE);
if (sgid_index)
*sgid_index = attr->index;
rdma_put_gid_attr(attr);
return 0;
}
rcu_read_unlock();
rdma_put_gid_attr(attr);
}
return -ENODEV;
Expand Down

0 comments on commit 5102eca

Please sign in to comment.