Skip to content

Commit df91c47

Browse files
Konstantin Taranovrleon
authored andcommitted
RDMA/mana_ib: create/destroy AH
Implement create and destroy AH for kernel. In mana_ib, AV is passed as an sge in WQE. Allocate DMA memory and write an AV there. Signed-off-by: Konstantin Taranov <[email protected]> Link: https://patch.msgid.link/[email protected] Reviewed-by: Shiraz Saleem <[email protected]> Reviewed-by: Long Li <[email protected]> Signed-off-by: Leon Romanovsky <[email protected]>
1 parent bd4ee70 commit df91c47

File tree

4 files changed

+101
-2
lines changed

4 files changed

+101
-2
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# SPDX-License-Identifier: GPL-2.0-only
22
obj-$(CONFIG_MANA_INFINIBAND) += mana_ib.o
33

4-
mana_ib-y := device.o main.o wq.o qp.o cq.o mr.o
4+
mana_ib-y := device.o main.o wq.o qp.o cq.o mr.o ah.o

drivers/infiniband/hw/mana/ah.c

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
/*
3+
* Copyright (c) 2024, Microsoft Corporation. All rights reserved.
4+
*/
5+
6+
#include "mana_ib.h"
7+
8+
int mana_ib_create_ah(struct ib_ah *ibah, struct rdma_ah_init_attr *attr,
9+
struct ib_udata *udata)
10+
{
11+
struct mana_ib_dev *mdev = container_of(ibah->device, struct mana_ib_dev, ib_dev);
12+
struct mana_ib_ah *ah = container_of(ibah, struct mana_ib_ah, ibah);
13+
struct rdma_ah_attr *ah_attr = attr->ah_attr;
14+
const struct ib_global_route *grh;
15+
enum rdma_network_type ntype;
16+
17+
if (ah_attr->type != RDMA_AH_ATTR_TYPE_ROCE ||
18+
!(rdma_ah_get_ah_flags(ah_attr) & IB_AH_GRH))
19+
return -EINVAL;
20+
21+
if (udata)
22+
return -EINVAL;
23+
24+
ah->av = dma_pool_zalloc(mdev->av_pool, GFP_ATOMIC, &ah->dma_handle);
25+
if (!ah->av)
26+
return -ENOMEM;
27+
28+
grh = rdma_ah_read_grh(ah_attr);
29+
ntype = rdma_gid_attr_network_type(grh->sgid_attr);
30+
31+
copy_in_reverse(ah->av->dest_mac, ah_attr->roce.dmac, ETH_ALEN);
32+
ah->av->udp_src_port = rdma_flow_label_to_udp_sport(grh->flow_label);
33+
ah->av->hop_limit = grh->hop_limit;
34+
ah->av->dscp = (grh->traffic_class >> 2) & 0x3f;
35+
ah->av->is_ipv6 = (ntype == RDMA_NETWORK_IPV6);
36+
37+
if (ah->av->is_ipv6) {
38+
copy_in_reverse(ah->av->dest_ip, grh->dgid.raw, 16);
39+
copy_in_reverse(ah->av->src_ip, grh->sgid_attr->gid.raw, 16);
40+
} else {
41+
ah->av->dest_ip[10] = 0xFF;
42+
ah->av->dest_ip[11] = 0xFF;
43+
copy_in_reverse(&ah->av->dest_ip[12], &grh->dgid.raw[12], 4);
44+
copy_in_reverse(&ah->av->src_ip[12], &grh->sgid_attr->gid.raw[12], 4);
45+
}
46+
47+
return 0;
48+
}
49+
50+
int mana_ib_destroy_ah(struct ib_ah *ibah, u32 flags)
51+
{
52+
struct mana_ib_dev *mdev = container_of(ibah->device, struct mana_ib_dev, ib_dev);
53+
struct mana_ib_ah *ah = container_of(ibah, struct mana_ib_ah, ibah);
54+
55+
dma_pool_free(mdev->av_pool, ah->av, ah->dma_handle);
56+
57+
return 0;
58+
}

drivers/infiniband/hw/mana/device.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ static const struct ib_device_ops mana_ib_dev_ops = {
1919
.add_gid = mana_ib_gd_add_gid,
2020
.alloc_pd = mana_ib_alloc_pd,
2121
.alloc_ucontext = mana_ib_alloc_ucontext,
22+
.create_ah = mana_ib_create_ah,
2223
.create_cq = mana_ib_create_cq,
2324
.create_qp = mana_ib_create_qp,
2425
.create_rwq_ind_table = mana_ib_create_rwq_ind_table,
@@ -27,6 +28,7 @@ static const struct ib_device_ops mana_ib_dev_ops = {
2728
.dealloc_ucontext = mana_ib_dealloc_ucontext,
2829
.del_gid = mana_ib_gd_del_gid,
2930
.dereg_mr = mana_ib_dereg_mr,
31+
.destroy_ah = mana_ib_destroy_ah,
3032
.destroy_cq = mana_ib_destroy_cq,
3133
.destroy_qp = mana_ib_destroy_qp,
3234
.destroy_rwq_ind_table = mana_ib_destroy_rwq_ind_table,
@@ -44,6 +46,7 @@ static const struct ib_device_ops mana_ib_dev_ops = {
4446
.query_port = mana_ib_query_port,
4547
.reg_user_mr = mana_ib_reg_user_mr,
4648

49+
INIT_RDMA_OBJ_SIZE(ib_ah, mana_ib_ah, ibah),
4750
INIT_RDMA_OBJ_SIZE(ib_cq, mana_ib_cq, ibcq),
4851
INIT_RDMA_OBJ_SIZE(ib_pd, mana_ib_pd, ibpd),
4952
INIT_RDMA_OBJ_SIZE(ib_qp, mana_ib_qp, ibqp),
@@ -135,15 +138,22 @@ static int mana_ib_probe(struct auxiliary_device *adev,
135138
goto destroy_rnic;
136139
}
137140

141+
dev->av_pool = dma_pool_create("mana_ib_av", mdev->gdma_context->dev,
142+
MANA_AV_BUFFER_SIZE, MANA_AV_BUFFER_SIZE, 0);
143+
if (!dev->av_pool)
144+
goto destroy_rnic;
145+
138146
ret = ib_register_device(&dev->ib_dev, "mana_%d",
139147
mdev->gdma_context->dev);
140148
if (ret)
141-
goto destroy_rnic;
149+
goto deallocate_pool;
142150

143151
dev_set_drvdata(&adev->dev, dev);
144152

145153
return 0;
146154

155+
deallocate_pool:
156+
dma_pool_destroy(dev->av_pool);
147157
destroy_rnic:
148158
xa_destroy(&dev->qp_table_wq);
149159
mana_ib_gd_destroy_rnic_adapter(dev);
@@ -161,6 +171,7 @@ static void mana_ib_remove(struct auxiliary_device *adev)
161171
struct mana_ib_dev *dev = dev_get_drvdata(&adev->dev);
162172

163173
ib_unregister_device(&dev->ib_dev);
174+
dma_pool_destroy(dev->av_pool);
164175
xa_destroy(&dev->qp_table_wq);
165176
mana_ib_gd_destroy_rnic_adapter(dev);
166177
mana_ib_destroy_eqs(dev);

drivers/infiniband/hw/mana/mana_ib.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <rdma/ib_umem.h>
1212
#include <rdma/mana-abi.h>
1313
#include <rdma/uverbs_ioctl.h>
14+
#include <linux/dmapool.h>
1415

1516
#include <net/mana/mana.h>
1617

@@ -32,6 +33,11 @@
3233
*/
3334
#define MANA_CA_ACK_DELAY 16
3435

36+
/*
37+
* The buffer used for writing AV
38+
*/
39+
#define MANA_AV_BUFFER_SIZE 64
40+
3541
struct mana_ib_adapter_caps {
3642
u32 max_sq_id;
3743
u32 max_rq_id;
@@ -65,6 +71,7 @@ struct mana_ib_dev {
6571
struct gdma_queue **eqs;
6672
struct xarray qp_table_wq;
6773
struct mana_ib_adapter_caps adapter_caps;
74+
struct dma_pool *av_pool;
6875
};
6976

7077
struct mana_ib_wq {
@@ -88,6 +95,25 @@ struct mana_ib_pd {
8895
u32 tx_vp_offset;
8996
};
9097

98+
struct mana_ib_av {
99+
u8 dest_ip[16];
100+
u8 dest_mac[ETH_ALEN];
101+
u16 udp_src_port;
102+
u8 src_ip[16];
103+
u32 hop_limit : 8;
104+
u32 reserved1 : 12;
105+
u32 dscp : 6;
106+
u32 reserved2 : 5;
107+
u32 is_ipv6 : 1;
108+
u32 reserved3 : 32;
109+
};
110+
111+
struct mana_ib_ah {
112+
struct ib_ah ibah;
113+
struct mana_ib_av *av;
114+
dma_addr_t dma_handle;
115+
};
116+
91117
struct mana_ib_mr {
92118
struct ib_mr ibmr;
93119
struct ib_umem *umem;
@@ -532,4 +558,8 @@ int mana_ib_gd_destroy_rc_qp(struct mana_ib_dev *mdev, struct mana_ib_qp *qp);
532558
int mana_ib_gd_create_ud_qp(struct mana_ib_dev *mdev, struct mana_ib_qp *qp,
533559
struct ib_qp_init_attr *attr, u32 doorbell, u32 type);
534560
int mana_ib_gd_destroy_ud_qp(struct mana_ib_dev *mdev, struct mana_ib_qp *qp);
561+
562+
int mana_ib_create_ah(struct ib_ah *ibah, struct rdma_ah_init_attr *init_attr,
563+
struct ib_udata *udata);
564+
int mana_ib_destroy_ah(struct ib_ah *ah, u32 flags);
535565
#endif

0 commit comments

Comments
 (0)