Skip to content

Commit 44c5848

Browse files
Dasaratharaman Chandramoulidledford
authored andcommitted
IB/core: Define 'ib' and 'roce' rdma_ah_attr types
rdma_ah_attr can now be either ib or roce allowing core components to use one type or the other and also to define attributes unique to a specific type. struct ib_ah is also initialized with the type when its first created. This ensures that calls such as modify_ah dont modify the type of the address handle attribute. Reviewed-by: Ira Weiny <[email protected]> Reviewed-by: Don Hiatt <[email protected]> Reviewed-by: Sean Hefty <[email protected]> Reviewed-by: Niranjana Vishwanathapura <[email protected]> Signed-off-by: Dasaratharaman Chandramouli <[email protected]> Signed-off-by: Doug Ledford <[email protected]>
1 parent d8966fc commit 44c5848

File tree

31 files changed

+141
-76
lines changed

31 files changed

+141
-76
lines changed

drivers/infiniband/core/cm.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1761,7 +1761,9 @@ static int cm_req_handler(struct cm_work *work)
17611761
cm_process_routed_req(req_msg, work->mad_recv_wc->wc);
17621762
cm_format_paths_from_req(req_msg, &work->path[0], &work->path[1]);
17631763

1764-
memcpy(work->path[0].dmac, cm_id_priv->av.ah_attr.dmac, ETH_ALEN);
1764+
if (cm_id_priv->av.ah_attr.type == RDMA_AH_ATTR_TYPE_ROCE)
1765+
memcpy(work->path[0].dmac, cm_id_priv->av.ah_attr.roce.dmac,
1766+
ETH_ALEN);
17651767
grh = rdma_ah_read_grh(&cm_id_priv->av.ah_attr);
17661768
work->path[0].hop_limit = grh->hop_limit;
17671769
ret = ib_get_cached_gid(work->port->cm_dev->ib_device,

drivers/infiniband/core/multicast.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,7 @@ int ib_init_ah_from_mcmember(struct ib_device *device, u8 port_num,
743743
return ret;
744744

745745
memset(ah_attr, 0, sizeof *ah_attr);
746+
ah_attr->type = rdma_ah_find_type(device, port_num);
746747

747748
rdma_ah_set_dlid(ah_attr, be16_to_cpu(rec->mlid));
748749
rdma_ah_set_sl(ah_attr, rec->sl);

drivers/infiniband/core/sa_query.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,7 @@ int ib_init_ah_from_path(struct ib_device *device, u8 port_num,
11081108
struct net_device *ndev = NULL;
11091109

11101110
memset(ah_attr, 0, sizeof *ah_attr);
1111+
ah_attr->type = rdma_ah_find_type(device, port_num);
11111112

11121113
rdma_ah_set_dlid(ah_attr, be16_to_cpu(rec->dlid));
11131114
rdma_ah_set_sl(ah_attr, rec->sl);
@@ -1192,7 +1193,7 @@ int ib_init_ah_from_path(struct ib_device *device, u8 port_num,
11921193
}
11931194

11941195
if (use_roce)
1195-
memcpy(ah_attr->dmac, rec->dmac, ETH_ALEN);
1196+
memcpy(ah_attr->roce.dmac, rec->dmac, ETH_ALEN);
11961197

11971198
return 0;
11981199
}
@@ -2029,6 +2030,8 @@ static void update_sm_ah(struct work_struct *work)
20292030
pr_err("Couldn't find index for default PKey\n");
20302031

20312032
memset(&ah_attr, 0, sizeof(ah_attr));
2033+
ah_attr.type = rdma_ah_find_type(port->agent->device,
2034+
port->port_num);
20322035
rdma_ah_set_dlid(&ah_attr, port_attr.sm_lid);
20332036
rdma_ah_set_sl(&ah_attr, port_attr.sm_sl);
20342037
rdma_ah_set_port_num(&ah_attr, port->port_num);

drivers/infiniband/core/user_mad.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,8 @@ static ssize_t ib_umad_write(struct file *filp, const char __user *buf,
491491
}
492492

493493
memset(&ah_attr, 0, sizeof ah_attr);
494+
ah_attr.type = rdma_ah_find_type(file->port->ib_dev,
495+
file->port->port_num);
494496
rdma_ah_set_dlid(&ah_attr, be16_to_cpu(packet->mad.hdr.lid));
495497
rdma_ah_set_sl(&ah_attr, packet->mad.hdr.sl);
496498
rdma_ah_set_path_bits(&ah_attr, packet->mad.hdr.path_bits);

drivers/infiniband/core/uverbs_cmd.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1954,6 +1954,8 @@ static int modify_qp(struct ib_uverbs_file *file,
19541954
attr->alt_timeout = cmd->base.alt_timeout;
19551955
attr->rate_limit = cmd->rate_limit;
19561956

1957+
attr->ah_attr.type = rdma_ah_find_type(qp->device,
1958+
cmd->base.dest.port_num);
19571959
if (cmd->base.dest.is_global) {
19581960
rdma_ah_set_grh(&attr->ah_attr, NULL,
19591961
cmd->base.dest.flow_label,
@@ -1971,6 +1973,8 @@ static int modify_qp(struct ib_uverbs_file *file,
19711973
rdma_ah_set_port_num(&attr->ah_attr,
19721974
cmd->base.dest.port_num);
19731975

1976+
attr->alt_ah_attr.type = rdma_ah_find_type(qp->device,
1977+
cmd->base.dest.port_num);
19741978
if (cmd->base.alt_dest.is_global) {
19751979
rdma_ah_set_grh(&attr->alt_ah_attr, NULL,
19761980
cmd->base.alt_dest.flow_label,
@@ -2551,6 +2555,7 @@ ssize_t ib_uverbs_create_ah(struct ib_uverbs_file *file,
25512555
goto err;
25522556
}
25532557

2558+
attr.type = rdma_ah_find_type(ib_dev, cmd.attr.port_num);
25542559
rdma_ah_set_dlid(&attr, cmd.attr.dlid);
25552560
rdma_ah_set_sl(&attr, cmd.attr.sl);
25562561
rdma_ah_set_path_bits(&attr, cmd.attr.src_path_bits);

drivers/infiniband/core/verbs.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ struct ib_ah *rdma_create_ah(struct ib_pd *pd, struct rdma_ah_attr *ah_attr)
321321
ah->device = pd->device;
322322
ah->pd = pd;
323323
ah->uobject = NULL;
324+
ah->type = ah_attr->type;
324325
atomic_inc(&pd->usecnt);
325326
}
326327

@@ -464,6 +465,7 @@ int ib_init_ah_from_wc(struct ib_device *device, u8 port_num,
464465
union ib_gid sgid;
465466

466467
memset(ah_attr, 0, sizeof *ah_attr);
468+
ah_attr->type = rdma_ah_find_type(device, port_num);
467469
if (rdma_cap_eth_ah(device, port_num)) {
468470
if (wc->wc_flags & IB_WC_WITH_NETWORK_HDR_TYPE)
469471
net_type = wc->network_hdr_type;
@@ -494,7 +496,7 @@ int ib_init_ah_from_wc(struct ib_device *device, u8 port_num,
494496
return -ENODEV;
495497

496498
ret = rdma_addr_find_l2_eth_by_grh(&dgid, &sgid,
497-
ah_attr->dmac,
499+
ah_attr->roce.dmac,
498500
wc->wc_flags & IB_WC_WITH_VLAN ?
499501
NULL : &vlan_id,
500502
&if_index, &hoplimit);
@@ -571,6 +573,9 @@ EXPORT_SYMBOL(ib_create_ah_from_wc);
571573

572574
int rdma_modify_ah(struct ib_ah *ah, struct rdma_ah_attr *ah_attr)
573575
{
576+
if (ah->type != ah_attr->type)
577+
return -EINVAL;
578+
574579
return ah->device->modify_ah ?
575580
ah->device->modify_ah(ah, ah_attr) :
576581
-ENOSYS;
@@ -1207,14 +1212,14 @@ int ib_resolve_eth_dmac(struct ib_device *device,
12071212
if (!rdma_is_port_valid(device, rdma_ah_get_port_num(ah_attr)))
12081213
return -EINVAL;
12091214

1210-
if (!rdma_cap_eth_ah(device, rdma_ah_get_port_num(ah_attr)))
1215+
if (ah_attr->type != RDMA_AH_ATTR_TYPE_ROCE)
12111216
return 0;
12121217

12131218
grh = rdma_ah_retrieve_grh(ah_attr);
12141219

12151220
if (rdma_link_local_addr((struct in6_addr *)grh->dgid.raw)) {
12161221
rdma_get_ll_mac((struct in6_addr *)grh->dgid.raw,
1217-
ah_attr->dmac);
1222+
ah_attr->roce.dmac);
12181223
} else {
12191224
union ib_gid sgid;
12201225
struct ib_gid_attr sgid_attr;
@@ -1236,7 +1241,7 @@ int ib_resolve_eth_dmac(struct ib_device *device,
12361241

12371242
ret =
12381243
rdma_addr_find_l2_eth_by_grh(&sgid, &grh->dgid,
1239-
ah_attr->dmac,
1244+
ah_attr->roce.dmac,
12401245
NULL, &ifindex, &hop_limit);
12411246

12421247
dev_put(sgid_attr.ndev);

drivers/infiniband/hw/bnxt_re/ib_verbs.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ struct ib_ah *bnxt_re_create_ah(struct ib_pd *ib_pd,
597597
break;
598598
}
599599
rc = rdma_addr_find_l2_eth_by_grh(&sgid, &grh->dgid,
600-
ah_attr->dmac, &vlan_tag,
600+
ah_attr->roce.dmac, &vlan_tag,
601601
&sgid_attr.ndev->ifindex,
602602
NULL);
603603
if (rc) {
@@ -606,7 +606,7 @@ struct ib_ah *bnxt_re_create_ah(struct ib_pd *ib_pd,
606606
}
607607
}
608608

609-
memcpy(ah->qplib_ah.dmac, ah_attr->dmac, ETH_ALEN);
609+
memcpy(ah->qplib_ah.dmac, ah_attr->roce.dmac, ETH_ALEN);
610610
rc = bnxt_qplib_create_ah(&rdev->qplib_res, &ah->qplib_ah);
611611
if (rc) {
612612
dev_err(rdev_to_dev(rdev), "Failed to allocate HW AH");
@@ -644,8 +644,9 @@ int bnxt_re_query_ah(struct ib_ah *ib_ah, struct rdma_ah_attr *ah_attr)
644644
{
645645
struct bnxt_re_ah *ah = container_of(ib_ah, struct bnxt_re_ah, ib_ah);
646646

647+
ah_attr->type = ib_ah->type;
647648
rdma_ah_set_sl(ah_attr, ah->qplib_ah.sl);
648-
memcpy(ah_attr->dmac, ah->qplib_ah.dmac, ETH_ALEN);
649+
memcpy(ah_attr->roce.dmac, ah->qplib_ah.dmac, ETH_ALEN);
649650
rdma_ah_set_grh(ah_attr, NULL, 0,
650651
ah->qplib_ah.host_sgid_index,
651652
0, ah->qplib_ah.traffic_class);
@@ -1280,7 +1281,8 @@ int bnxt_re_modify_qp(struct ib_qp *ib_qp, struct ib_qp_attr *qp_attr,
12801281
qp->qplib_qp.ah.hop_limit = grh->hop_limit;
12811282
qp->qplib_qp.ah.traffic_class = grh->traffic_class;
12821283
qp->qplib_qp.ah.sl = rdma_ah_get_sl(&qp_attr->ah_attr);
1283-
ether_addr_copy(qp->qplib_qp.ah.dmac, qp_attr->ah_attr.dmac);
1284+
ether_addr_copy(qp->qplib_qp.ah.dmac,
1285+
qp_attr->ah_attr.roce.dmac);
12841286

12851287
status = ib_get_cached_gid(&rdev->ibdev, 1,
12861288
grh->sgid_index,
@@ -1423,13 +1425,14 @@ int bnxt_re_query_qp(struct ib_qp *ib_qp, struct ib_qp_attr *qp_attr,
14231425
qp_attr->qp_access_flags = __to_ib_access_flags(qplib_qp.access);
14241426
qp_attr->pkey_index = qplib_qp.pkey_index;
14251427
qp_attr->qkey = qplib_qp.qkey;
1428+
qp_attr->ah_attr.type = RDMA_AH_ATTR_TYPE_ROCE;
14261429
rdma_ah_set_grh(&qp_attr->ah_attr, NULL, qplib_qp.ah.flow_label,
14271430
qplib_qp.ah.host_sgid_index,
14281431
qplib_qp.ah.hop_limit,
14291432
qplib_qp.ah.traffic_class);
14301433
rdma_ah_set_dgid_raw(&qp_attr->ah_attr, qplib_qp.ah.dgid.data);
14311434
rdma_ah_set_sl(&qp_attr->ah_attr, qplib_qp.ah.sl);
1432-
ether_addr_copy(qp_attr->ah_attr.dmac, qplib_qp.ah.dmac);
1435+
ether_addr_copy(qp_attr->ah_attr.roce.dmac, qplib_qp.ah.dmac);
14331436
qp_attr->path_mtu = __to_ib_mtu(qplib_qp.path_mtu);
14341437
qp_attr->timeout = qplib_qp.timeout;
14351438
qp_attr->retry_cnt = qplib_qp.retry_cnt;

drivers/infiniband/hw/hfi1/verbs.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,8 +1511,12 @@ struct ib_ah *hfi1_create_qp0_ah(struct hfi1_ibport *ibp, u16 dlid)
15111511
struct rdma_ah_attr attr;
15121512
struct ib_ah *ah = ERR_PTR(-EINVAL);
15131513
struct rvt_qp *qp0;
1514+
struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
1515+
struct hfi1_devdata *dd = dd_from_ppd(ppd);
1516+
u8 port_num = ppd->port;
15141517

15151518
memset(&attr, 0, sizeof(attr));
1519+
attr.type = rdma_ah_find_type(&dd->verbs_dev.rdi.ibdev, port_num);
15161520
rdma_ah_set_dlid(&attr, dlid);
15171521
rdma_ah_set_port_num(&attr, ppd_from_ibp(ibp)->port);
15181522
rcu_read_lock();

drivers/infiniband/hw/hns/hns_roce_hw_v1.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2738,7 +2738,7 @@ static int hns_roce_v1_m_qp(struct ib_qp *ibqp, const struct ib_qp_attr *attr,
27382738
goto out;
27392739
}
27402740

2741-
dmac = (u8 *)attr->ah_attr.dmac;
2741+
dmac = (u8 *)attr->ah_attr.roce.dmac;
27422742

27432743
context->sq_rq_bt_l = (u32)(dma_handle);
27442744
roce_set_field(context->qpc_bytes_24,

drivers/infiniband/hw/mlx4/ah.c

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ static struct ib_ah *create_iboe_ah(struct ib_pd *pd,
9696
is_mcast = 1;
9797
rdma_get_mcast_mac(&in6, ah->av.eth.mac);
9898
} else {
99-
memcpy(ah->av.eth.mac, ah_attr->dmac, ETH_ALEN);
99+
memcpy(ah->av.eth.mac, ah_attr->roce.dmac, ETH_ALEN);
100100
}
101101
ret = ib_get_cached_gid(pd->device, rdma_ah_get_port_num(ah_attr),
102102
grh->sgid_index, &sgid, &gid_attr);
@@ -154,9 +154,7 @@ struct ib_ah *mlx4_ib_create_ah(struct ib_pd *pd, struct rdma_ah_attr *ah_attr,
154154
if (!ah)
155155
return ERR_PTR(-ENOMEM);
156156

157-
if (rdma_port_get_link_layer(pd->device,
158-
rdma_ah_get_port_num(ah_attr)) ==
159-
IB_LINK_LAYER_ETHERNET) {
157+
if (ah_attr->type == RDMA_AH_ATTR_TYPE_ROCE) {
160158
if (!(rdma_ah_get_ah_flags(ah_attr) & IB_AH_GRH)) {
161159
ret = ERR_PTR(-EINVAL);
162160
} else {
@@ -182,30 +180,29 @@ struct ib_ah *mlx4_ib_create_ah(struct ib_pd *pd, struct rdma_ah_attr *ah_attr,
182180
int mlx4_ib_query_ah(struct ib_ah *ibah, struct rdma_ah_attr *ah_attr)
183181
{
184182
struct mlx4_ib_ah *ah = to_mah(ibah);
185-
enum rdma_link_layer ll;
183+
int port_num = be32_to_cpu(ah->av.ib.port_pd) >> 24;
186184

187185
memset(ah_attr, 0, sizeof *ah_attr);
188-
rdma_ah_set_port_num(ah_attr,
189-
be32_to_cpu(ah->av.ib.port_pd) >> 24);
190-
ll = rdma_port_get_link_layer(ibah->device,
191-
rdma_ah_get_port_num(ah_attr));
192-
if (ll == IB_LINK_LAYER_ETHERNET)
186+
ah_attr->type = ibah->type;
187+
188+
if (ah_attr->type == RDMA_AH_ATTR_TYPE_ROCE) {
189+
rdma_ah_set_dlid(ah_attr, 0);
193190
rdma_ah_set_sl(ah_attr,
194191
be32_to_cpu(ah->av.eth.sl_tclass_flowlabel)
195192
>> 29);
196-
else
193+
} else {
194+
rdma_ah_set_dlid(ah_attr, be16_to_cpu(ah->av.ib.dlid));
197195
rdma_ah_set_sl(ah_attr,
198196
be32_to_cpu(ah->av.ib.sl_tclass_flowlabel)
199197
>> 28);
198+
}
200199

201-
rdma_ah_set_dlid(ah_attr, (ll == IB_LINK_LAYER_INFINIBAND) ?
202-
be16_to_cpu(ah->av.ib.dlid) : 0);
200+
rdma_ah_set_port_num(ah_attr, port_num);
203201
if (ah->av.ib.stat_rate)
204202
rdma_ah_set_static_rate(ah_attr,
205203
ah->av.ib.stat_rate -
206204
MLX4_STAT_RATE_OFFSET);
207205
rdma_ah_set_path_bits(ah_attr, ah->av.ib.g_slid & 0x7F);
208-
209206
if (mlx4_ib_ah_grh_present(ah)) {
210207
u32 tc_fl = be32_to_cpu(ah->av.ib.sl_tclass_flowlabel);
211208

drivers/infiniband/hw/mlx4/mad.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ static void update_sm_ah(struct mlx4_ib_dev *dev, u8 port_num, u16 lid, u8 sl)
196196
return;
197197

198198
memset(&ah_attr, 0, sizeof ah_attr);
199+
ah_attr.type = rdma_ah_find_type(&dev->ib_dev, port_num);
199200
rdma_ah_set_dlid(&ah_attr, lid);
200201
rdma_ah_set_sl(&ah_attr, sl);
201202
rdma_ah_set_port_num(&ah_attr, port_num);
@@ -555,6 +556,7 @@ int mlx4_ib_send_to_slave(struct mlx4_ib_dev *dev, int slave, u8 port,
555556
/* create ah. Just need an empty one with the port num for the post send.
556557
* The driver will set the force loopback bit in post_send */
557558
memset(&attr, 0, sizeof attr);
559+
attr.type = rdma_ah_find_type(&dev->ib_dev, port);
558560

559561
rdma_ah_set_port_num(&attr, port);
560562
if (is_eth) {

drivers/infiniband/hw/mlx4/qp.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,8 +1388,6 @@ static int _mlx4_set_path(struct mlx4_ib_dev *dev,
13881388
u64 smac, u16 vlan_tag, struct mlx4_qp_path *path,
13891389
struct mlx4_roce_smac_vlan_info *smac_info, u8 port)
13901390
{
1391-
int is_eth = rdma_port_get_link_layer(&dev->ib_dev, port) ==
1392-
IB_LINK_LAYER_ETHERNET;
13931391
int vidx;
13941392
int smac_index;
13951393
int err;
@@ -1426,7 +1424,7 @@ static int _mlx4_set_path(struct mlx4_ib_dev *dev,
14261424
memcpy(path->rgid, grh->dgid.raw, 16);
14271425
}
14281426

1429-
if (is_eth) {
1427+
if (ah->type == RDMA_AH_ATTR_TYPE_ROCE) {
14301428
if (!(rdma_ah_get_ah_flags(ah) & IB_AH_GRH))
14311429
return -1;
14321430

@@ -1490,7 +1488,7 @@ static int _mlx4_set_path(struct mlx4_ib_dev *dev,
14901488
} else {
14911489
smac_index = smac_info->smac_index;
14921490
}
1493-
memcpy(path->dmac, ah->dmac, 6);
1491+
memcpy(path->dmac, ah->roce.dmac, 6);
14941492
path->ackto = MLX4_IB_LINK_TYPE_ETH;
14951493
/* put MAC table smac index for IBoE */
14961494
path->grh_mylmc = (u8) (smac_index) | 0x80;
@@ -3402,23 +3400,19 @@ static void to_rdma_ah_attr(struct mlx4_ib_dev *ibdev,
34023400
struct mlx4_qp_path *path)
34033401
{
34043402
struct mlx4_dev *dev = ibdev->dev;
3405-
int is_eth;
34063403
u8 port_num = path->sched_queue & 0x40 ? 2 : 1;
34073404

34083405
memset(ah_attr, 0, sizeof(*ah_attr));
3409-
rdma_ah_set_port_num(ah_attr, port_num);
3410-
3406+
ah_attr->type = rdma_ah_find_type(&ibdev->ib_dev, port_num);
34113407
if (port_num == 0 || port_num > dev->caps.num_ports)
34123408
return;
34133409

3414-
is_eth = rdma_port_get_link_layer(&ibdev->ib_dev,
3415-
rdma_ah_get_port_num(ah_attr)) ==
3416-
IB_LINK_LAYER_ETHERNET;
3417-
if (is_eth)
3410+
if (ah_attr->type == RDMA_AH_ATTR_TYPE_ROCE)
34183411
rdma_ah_set_sl(ah_attr, ((path->sched_queue >> 3) & 0x7) |
34193412
((path->sched_queue & 4) << 1));
34203413
else
34213414
rdma_ah_set_sl(ah_attr, (path->sched_queue >> 2) & 0xf);
3415+
rdma_ah_set_port_num(ah_attr, port_num);
34223416

34233417
rdma_ah_set_dlid(ah_attr, be16_to_cpu(path->rlid));
34243418
rdma_ah_set_path_bits(ah_attr, path->grh_mylmc & 0x7f);

0 commit comments

Comments
 (0)