Commit 5102eca9 authored by Parav Pandit's avatar Parav Pandit Committed by Jason Gunthorpe

net/smc: Use rdma_read_gid_l2_fields to L2 fields

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: default avatarParav Pandit <parav@mellanox.com>
Signed-off-by: default avatarLeon Romanovsky <leonro@mellanox.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@mellanox.com>
parent dab21758
...@@ -146,18 +146,13 @@ int smc_ib_ready_link(struct smc_link *lnk) ...@@ -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) static int smc_ib_fill_mac(struct smc_ib_device *smcibdev, u8 ibport)
{ {
const struct ib_gid_attr *attr; const struct ib_gid_attr *attr;
int rc = 0; int rc;
attr = rdma_get_gid_attr(smcibdev->ibdev, ibport, 0); attr = rdma_get_gid_attr(smcibdev->ibdev, ibport, 0);
if (IS_ERR(attr)) if (IS_ERR(attr))
return -ENODEV; return -ENODEV;
if (attr->ndev) rc = rdma_read_gid_l2_fields(attr, NULL, smcibdev->mac[ibport - 1]);
memcpy(smcibdev->mac[ibport - 1], attr->ndev->dev_addr,
ETH_ALEN);
else
rc = -ENODEV;
rdma_put_gid_attr(attr); rdma_put_gid_attr(attr);
return rc; return rc;
} }
...@@ -185,6 +180,7 @@ int smc_ib_determine_gid(struct smc_ib_device *smcibdev, u8 ibport, ...@@ -185,6 +180,7 @@ int smc_ib_determine_gid(struct smc_ib_device *smcibdev, u8 ibport,
unsigned short vlan_id, u8 gid[], u8 *sgid_index) unsigned short vlan_id, u8 gid[], u8 *sgid_index)
{ {
const struct ib_gid_attr *attr; const struct ib_gid_attr *attr;
const struct net_device *ndev;
int i; int i;
for (i = 0; i < smcibdev->pattr[ibport - 1].gid_tbl_len; i++) { for (i = 0; i < smcibdev->pattr[ibport - 1].gid_tbl_len; i++) {
...@@ -192,11 +188,14 @@ int smc_ib_determine_gid(struct smc_ib_device *smcibdev, u8 ibport, ...@@ -192,11 +188,14 @@ int smc_ib_determine_gid(struct smc_ib_device *smcibdev, u8 ibport,
if (IS_ERR(attr)) if (IS_ERR(attr))
continue; 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_id && is_vlan_dev(attr->ndev) && (vlan_id && is_vlan_dev(attr->ndev) &&
vlan_dev_vlan_id(attr->ndev) == vlan_id)) && vlan_dev_vlan_id(attr->ndev) == vlan_id)) &&
attr->gid_type == IB_GID_TYPE_ROCE) { attr->gid_type == IB_GID_TYPE_ROCE) {
rcu_read_unlock();
if (gid) if (gid)
memcpy(gid, &attr->gid, SMC_GID_SIZE); memcpy(gid, &attr->gid, SMC_GID_SIZE);
if (sgid_index) if (sgid_index)
...@@ -204,6 +203,7 @@ int smc_ib_determine_gid(struct smc_ib_device *smcibdev, u8 ibport, ...@@ -204,6 +203,7 @@ int smc_ib_determine_gid(struct smc_ib_device *smcibdev, u8 ibport,
rdma_put_gid_attr(attr); rdma_put_gid_attr(attr);
return 0; return 0;
} }
rcu_read_unlock();
rdma_put_gid_attr(attr); rdma_put_gid_attr(attr);
} }
return -ENODEV; return -ENODEV;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment