Skip to content

Commit 89af969

Browse files
paravmellanoxjgunthorpe
authored andcommitted
RDMA: Convert drivers to use the AH's sgid_attr in post_wr paths
For UD the drivers were doing a sgid_index lookup into the cache to get the attrs, however we can now directly access the same attrs stores in the ib_ah instead and remove the lookup. Signed-off-by: Parav Pandit <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]> Signed-off-by: Leon Romanovsky <[email protected]>
1 parent 1a1f460 commit 89af969

File tree

4 files changed

+19
-52
lines changed

4 files changed

+19
-52
lines changed

drivers/infiniband/hw/bnxt_re/ib_verbs.c

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1879,15 +1879,13 @@ static int bnxt_re_build_qp1_send_v2(struct bnxt_re_qp *qp,
18791879
struct bnxt_qplib_swqe *wqe,
18801880
int payload_size)
18811881
{
1882-
struct ib_device *ibdev = &qp->rdev->ibdev;
18831882
struct bnxt_re_ah *ah = container_of(ud_wr(wr)->ah, struct bnxt_re_ah,
18841883
ib_ah);
18851884
struct bnxt_qplib_ah *qplib_ah = &ah->qplib_ah;
1885+
const struct ib_gid_attr *sgid_attr = ah->ib_ah.sgid_attr;
18861886
struct bnxt_qplib_sge sge;
1887-
union ib_gid sgid;
18881887
u8 nw_type;
18891888
u16 ether_type;
1890-
struct ib_gid_attr sgid_attr;
18911889
union ib_gid dgid;
18921890
bool is_eth = false;
18931891
bool is_vlan = false;
@@ -1900,22 +1898,10 @@ static int bnxt_re_build_qp1_send_v2(struct bnxt_re_qp *qp,
19001898

19011899
memset(&qp->qp1_hdr, 0, sizeof(qp->qp1_hdr));
19021900

1903-
rc = ib_get_cached_gid(ibdev, 1,
1904-
qplib_ah->host_sgid_index, &sgid,
1905-
&sgid_attr);
1906-
if (rc) {
1907-
dev_err(rdev_to_dev(qp->rdev),
1908-
"Failed to query gid at index %d",
1909-
qplib_ah->host_sgid_index);
1910-
return rc;
1911-
}
1912-
if (sgid_attr.ndev) {
1913-
if (is_vlan_dev(sgid_attr.ndev))
1914-
vlan_id = vlan_dev_vlan_id(sgid_attr.ndev);
1915-
dev_put(sgid_attr.ndev);
1916-
}
1901+
if (is_vlan_dev(sgid_attr->ndev))
1902+
vlan_id = vlan_dev_vlan_id(sgid_attr->ndev);
19171903
/* Get network header type for this GID */
1918-
nw_type = rdma_gid_attr_network_type(&sgid_attr);
1904+
nw_type = rdma_gid_attr_network_type(sgid_attr);
19191905
switch (nw_type) {
19201906
case RDMA_NETWORK_IPV4:
19211907
nw_type = BNXT_RE_ROCEV2_IPV4_PACKET;
@@ -1928,9 +1914,9 @@ static int bnxt_re_build_qp1_send_v2(struct bnxt_re_qp *qp,
19281914
break;
19291915
}
19301916
memcpy(&dgid.raw, &qplib_ah->dgid, 16);
1931-
is_udp = sgid_attr.gid_type == IB_GID_TYPE_ROCE_UDP_ENCAP;
1917+
is_udp = sgid_attr->gid_type == IB_GID_TYPE_ROCE_UDP_ENCAP;
19321918
if (is_udp) {
1933-
if (ipv6_addr_v4mapped((struct in6_addr *)&sgid)) {
1919+
if (ipv6_addr_v4mapped((struct in6_addr *)&sgid_attr->gid)) {
19341920
ip_version = 4;
19351921
ether_type = ETH_P_IP;
19361922
} else {
@@ -1963,9 +1949,10 @@ static int bnxt_re_build_qp1_send_v2(struct bnxt_re_qp *qp,
19631949
}
19641950

19651951
if (is_grh || (ip_version == 6)) {
1966-
memcpy(qp->qp1_hdr.grh.source_gid.raw, sgid.raw, sizeof(sgid));
1952+
memcpy(qp->qp1_hdr.grh.source_gid.raw, sgid_attr->gid.raw,
1953+
sizeof(sgid_attr->gid));
19671954
memcpy(qp->qp1_hdr.grh.destination_gid.raw, qplib_ah->dgid.data,
1968-
sizeof(sgid));
1955+
sizeof(sgid_attr->gid));
19691956
qp->qp1_hdr.grh.hop_limit = qplib_ah->hop_limit;
19701957
}
19711958

@@ -1975,7 +1962,7 @@ static int bnxt_re_build_qp1_send_v2(struct bnxt_re_qp *qp,
19751962
qp->qp1_hdr.ip4.frag_off = htons(IP_DF);
19761963
qp->qp1_hdr.ip4.ttl = qplib_ah->hop_limit;
19771964

1978-
memcpy(&qp->qp1_hdr.ip4.saddr, sgid.raw + 12, 4);
1965+
memcpy(&qp->qp1_hdr.ip4.saddr, sgid_attr->gid.raw + 12, 4);
19791966
memcpy(&qp->qp1_hdr.ip4.daddr, qplib_ah->dgid.data + 12, 4);
19801967
qp->qp1_hdr.ip4.check = ib_ud_ip4_csum(&qp->qp1_hdr);
19811968
}

drivers/infiniband/hw/mlx4/qp.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3169,12 +3169,8 @@ static int build_mlx_header(struct mlx4_ib_sqp *sqp, struct ib_ud_wr *wr,
31693169
to_mdev(ib_dev)->sriov.demux[sqp->qp.port - 1].
31703170
guid_cache[ah->av.ib.gid_index];
31713171
} else {
3172-
err = rdma_query_gid(ib_dev,
3173-
be32_to_cpu(ah->av.ib.port_pd) >> 24,
3174-
ah->av.ib.gid_index,
3175-
&sqp->ud_header.grh.source_gid);
3176-
if (err)
3177-
return err;
3172+
sqp->ud_header.grh.source_gid =
3173+
ah->ibah.sgid_attr->gid;
31783174
}
31793175
}
31803176
memcpy(sqp->ud_header.grh.destination_gid.raw,

drivers/infiniband/hw/mthca/mthca_av.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,7 @@ int mthca_read_ah(struct mthca_dev *dev, struct mthca_ah *ah,
281281
header->grh.flow_label =
282282
ah->av->sl_tclass_flowlabel & cpu_to_be32(0xfffff);
283283
header->grh.hop_limit = ah->av->hop_limit;
284-
ib_get_cached_gid(&dev->ib_dev,
285-
be32_to_cpu(ah->av->port_pd) >> 24,
286-
ah->av->gid_index % dev->limits.gid_table_len,
287-
&header->grh.source_gid, NULL);
284+
header->grh.source_gid = ah->ibah.sgid_attr->gid;
288285
memcpy(header->grh.destination_gid.raw,
289286
ah->av->dgid, 16);
290287
}

drivers/infiniband/hw/qedr/qedr_roce_cm.c

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -387,11 +387,10 @@ static inline int qedr_gsi_build_header(struct qedr_dev *dev,
387387
bool has_vlan = false, has_grh_ipv6 = true;
388388
struct rdma_ah_attr *ah_attr = &get_qedr_ah(ud_wr(swr)->ah)->attr;
389389
const struct ib_global_route *grh = rdma_ah_read_grh(ah_attr);
390-
union ib_gid sgid;
390+
const struct ib_gid_attr *sgid_attr = grh->sgid_attr;
391391
int send_size = 0;
392392
u16 vlan_id = 0;
393393
u16 ether_type;
394-
struct ib_gid_attr sgid_attr;
395394
int rc;
396395
int ip_ver = 0;
397396

@@ -402,28 +401,16 @@ static inline int qedr_gsi_build_header(struct qedr_dev *dev,
402401
for (i = 0; i < swr->num_sge; ++i)
403402
send_size += swr->sg_list[i].length;
404403

405-
rc = ib_get_cached_gid(qp->ibqp.device, rdma_ah_get_port_num(ah_attr),
406-
grh->sgid_index, &sgid, &sgid_attr);
407-
if (rc) {
408-
DP_ERR(dev,
409-
"gsi post send: failed to get cached GID (port=%d, ix=%d)\n",
410-
rdma_ah_get_port_num(ah_attr),
411-
grh->sgid_index);
412-
return rc;
413-
}
414-
415-
vlan_id = rdma_vlan_dev_vlan_id(sgid_attr.ndev);
404+
vlan_id = rdma_vlan_dev_vlan_id(sgid_attr->ndev);
416405
if (vlan_id < VLAN_CFI_MASK)
417406
has_vlan = true;
418407

419-
dev_put(sgid_attr.ndev);
420-
421-
has_udp = (sgid_attr.gid_type == IB_GID_TYPE_ROCE_UDP_ENCAP);
408+
has_udp = (sgid_attr->gid_type == IB_GID_TYPE_ROCE_UDP_ENCAP);
422409
if (!has_udp) {
423410
/* RoCE v1 */
424411
ether_type = ETH_P_IBOE;
425412
*roce_mode = ROCE_V1;
426-
} else if (ipv6_addr_v4mapped((struct in6_addr *)&sgid)) {
413+
} else if (ipv6_addr_v4mapped((struct in6_addr *)&sgid_attr->gid)) {
427414
/* RoCE v2 IPv4 */
428415
ip_ver = 4;
429416
ether_type = ETH_P_IP;
@@ -471,7 +458,7 @@ static inline int qedr_gsi_build_header(struct qedr_dev *dev,
471458
udh->grh.flow_label = grh->flow_label;
472459
udh->grh.hop_limit = grh->hop_limit;
473460
udh->grh.destination_gid = grh->dgid;
474-
memcpy(&udh->grh.source_gid.raw, &sgid.raw,
461+
memcpy(&udh->grh.source_gid.raw, sgid_attr->gid.raw,
475462
sizeof(udh->grh.source_gid.raw));
476463
} else {
477464
/* IPv4 header */
@@ -482,7 +469,7 @@ static inline int qedr_gsi_build_header(struct qedr_dev *dev,
482469
udh->ip4.frag_off = htons(IP_DF);
483470
udh->ip4.ttl = grh->hop_limit;
484471

485-
ipv4_addr = qedr_get_ipv4_from_gid(sgid.raw);
472+
ipv4_addr = qedr_get_ipv4_from_gid(sgid_attr->gid.raw);
486473
udh->ip4.saddr = ipv4_addr;
487474
ipv4_addr = qedr_get_ipv4_from_gid(grh->dgid.raw);
488475
udh->ip4.daddr = ipv4_addr;

0 commit comments

Comments
 (0)