Skip to content

Commit 2307157

Browse files
mrgolinrleon
authored andcommitted
RDMA/efa: Add EFA query MR support
Add EFA driver uapi definitions and register a new query MR method that currently returns the physical interconnects the device is using to reach the MR. Update admin definitions and efa-abi accordingly. Reviewed-by: Anas Mousa <[email protected]> Reviewed-by: Firas Jahjah <[email protected]> Signed-off-by: Michael Margolin <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Leon Romanovsky <[email protected]>
1 parent 2f18882 commit 2307157

File tree

7 files changed

+160
-7
lines changed

7 files changed

+160
-7
lines changed

drivers/infiniband/hw/efa/efa.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause */
22
/*
3-
* Copyright 2018-2021 Amazon.com, Inc. or its affiliates. All rights reserved.
3+
* Copyright 2018-2024 Amazon.com, Inc. or its affiliates. All rights reserved.
44
*/
55

66
#ifndef _EFA_H_
@@ -80,9 +80,19 @@ struct efa_pd {
8080
u16 pdn;
8181
};
8282

83+
struct efa_mr_interconnect_info {
84+
u16 recv_ic_id;
85+
u16 rdma_read_ic_id;
86+
u16 rdma_recv_ic_id;
87+
u8 recv_ic_id_valid : 1;
88+
u8 rdma_read_ic_id_valid : 1;
89+
u8 rdma_recv_ic_id_valid : 1;
90+
};
91+
8392
struct efa_mr {
8493
struct ib_mr ibmr;
8594
struct ib_umem *umem;
95+
struct efa_mr_interconnect_info ic_info;
8696
};
8797

8898
struct efa_cq {

drivers/infiniband/hw/efa/efa_admin_cmds_defs.h

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause */
22
/*
3-
* Copyright 2018-2023 Amazon.com, Inc. or its affiliates. All rights reserved.
3+
* Copyright 2018-2024 Amazon.com, Inc. or its affiliates. All rights reserved.
44
*/
55

66
#ifndef _EFA_ADMIN_CMDS_H_
@@ -415,6 +415,32 @@ struct efa_admin_reg_mr_resp {
415415
* memory region
416416
*/
417417
u32 r_key;
418+
419+
/*
420+
* Mask indicating which fields have valid values
421+
* 0 : recv_ic_id
422+
* 1 : rdma_read_ic_id
423+
* 2 : rdma_recv_ic_id
424+
*/
425+
u8 validity;
426+
427+
/*
428+
* Physical interconnect used by the device to reach the MR for receive
429+
* operation
430+
*/
431+
u8 recv_ic_id;
432+
433+
/*
434+
* Physical interconnect used by the device to reach the MR for RDMA
435+
* read operation
436+
*/
437+
u8 rdma_read_ic_id;
438+
439+
/*
440+
* Physical interconnect used by the device to reach the MR for RDMA
441+
* write receive
442+
*/
443+
u8 rdma_recv_ic_id;
418444
};
419445

420446
struct efa_admin_dereg_mr_cmd {
@@ -999,6 +1025,11 @@ struct efa_admin_host_info {
9991025
#define EFA_ADMIN_REG_MR_CMD_REMOTE_WRITE_ENABLE_MASK BIT(1)
10001026
#define EFA_ADMIN_REG_MR_CMD_REMOTE_READ_ENABLE_MASK BIT(2)
10011027

1028+
/* reg_mr_resp */
1029+
#define EFA_ADMIN_REG_MR_RESP_RECV_IC_ID_MASK BIT(0)
1030+
#define EFA_ADMIN_REG_MR_RESP_RDMA_READ_IC_ID_MASK BIT(1)
1031+
#define EFA_ADMIN_REG_MR_RESP_RDMA_RECV_IC_ID_MASK BIT(2)
1032+
10021033
/* create_cq_cmd */
10031034
#define EFA_ADMIN_CREATE_CQ_CMD_INTERRUPT_MODE_ENABLED_MASK BIT(5)
10041035
#define EFA_ADMIN_CREATE_CQ_CMD_VIRT_MASK BIT(6)

drivers/infiniband/hw/efa/efa_com_cmd.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause
22
/*
3-
* Copyright 2018-2023 Amazon.com, Inc. or its affiliates. All rights reserved.
3+
* Copyright 2018-2024 Amazon.com, Inc. or its affiliates. All rights reserved.
44
*/
55

66
#include "efa_com.h"
@@ -270,6 +270,15 @@ int efa_com_register_mr(struct efa_com_dev *edev,
270270

271271
result->l_key = cmd_completion.l_key;
272272
result->r_key = cmd_completion.r_key;
273+
result->ic_info.recv_ic_id = cmd_completion.recv_ic_id;
274+
result->ic_info.rdma_read_ic_id = cmd_completion.rdma_read_ic_id;
275+
result->ic_info.rdma_recv_ic_id = cmd_completion.rdma_recv_ic_id;
276+
result->ic_info.recv_ic_id_valid = EFA_GET(&cmd_completion.validity,
277+
EFA_ADMIN_REG_MR_RESP_RECV_IC_ID);
278+
result->ic_info.rdma_read_ic_id_valid = EFA_GET(&cmd_completion.validity,
279+
EFA_ADMIN_REG_MR_RESP_RDMA_READ_IC_ID);
280+
result->ic_info.rdma_recv_ic_id_valid = EFA_GET(&cmd_completion.validity,
281+
EFA_ADMIN_REG_MR_RESP_RDMA_RECV_IC_ID);
273282

274283
return 0;
275284
}

drivers/infiniband/hw/efa/efa_com_cmd.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause */
22
/*
3-
* Copyright 2018-2023 Amazon.com, Inc. or its affiliates. All rights reserved.
3+
* Copyright 2018-2024 Amazon.com, Inc. or its affiliates. All rights reserved.
44
*/
55

66
#ifndef _EFA_COM_CMD_H_
@@ -199,6 +199,15 @@ struct efa_com_reg_mr_params {
199199
u8 indirect;
200200
};
201201

202+
struct efa_com_mr_interconnect_info {
203+
u16 recv_ic_id;
204+
u16 rdma_read_ic_id;
205+
u16 rdma_recv_ic_id;
206+
u8 recv_ic_id_valid : 1;
207+
u8 rdma_read_ic_id_valid : 1;
208+
u8 rdma_recv_ic_id_valid : 1;
209+
};
210+
202211
struct efa_com_reg_mr_result {
203212
/*
204213
* To be used in conjunction with local buffers references in SQ and
@@ -210,6 +219,7 @@ struct efa_com_reg_mr_result {
210219
* accessed memory region
211220
*/
212221
u32 r_key;
222+
struct efa_com_mr_interconnect_info ic_info;
213223
};
214224

215225
struct efa_com_dereg_mr_params {

drivers/infiniband/hw/efa/efa_main.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause
22
/*
3-
* Copyright 2018-2022 Amazon.com, Inc. or its affiliates. All rights reserved.
3+
* Copyright 2018-2024 Amazon.com, Inc. or its affiliates. All rights reserved.
44
*/
55

66
#include <linux/module.h>
@@ -9,6 +9,7 @@
99
#include <linux/version.h>
1010

1111
#include <rdma/ib_user_verbs.h>
12+
#include <rdma/uverbs_ioctl.h>
1213

1314
#include "efa.h"
1415

@@ -36,6 +37,8 @@ MODULE_DEVICE_TABLE(pci, efa_pci_tbl);
3637
(BIT(EFA_ADMIN_FATAL_ERROR) | BIT(EFA_ADMIN_WARNING) | \
3738
BIT(EFA_ADMIN_NOTIFICATION) | BIT(EFA_ADMIN_KEEP_ALIVE))
3839

40+
extern const struct uapi_definition efa_uapi_defs[];
41+
3942
/* This handler will called for unknown event group or unimplemented handlers */
4043
static void unimplemented_aenq_handler(void *data,
4144
struct efa_admin_aenq_entry *aenq_e)
@@ -432,6 +435,8 @@ static int efa_ib_device_add(struct efa_dev *dev)
432435

433436
ib_set_device_ops(&dev->ibdev, &efa_dev_ops);
434437

438+
dev->ibdev.driver_def = efa_uapi_defs;
439+
435440
err = ib_register_device(&dev->ibdev, "efa_%d", &pdev->dev);
436441
if (err)
437442
goto err_destroy_eqs;

drivers/infiniband/hw/efa/efa_verbs.c

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
22
/*
3-
* Copyright 2018-2023 Amazon.com, Inc. or its affiliates. All rights reserved.
3+
* Copyright 2018-2024 Amazon.com, Inc. or its affiliates. All rights reserved.
44
*/
55

66
#include <linux/dma-buf.h>
@@ -13,6 +13,9 @@
1313
#include <rdma/ib_user_verbs.h>
1414
#include <rdma/ib_verbs.h>
1515
#include <rdma/uverbs_ioctl.h>
16+
#define UVERBS_MODULE_NAME efa_ib
17+
#include <rdma/uverbs_named_ioctl.h>
18+
#include <rdma/ib_user_ioctl_cmds.h>
1619

1720
#include "efa.h"
1821
#include "efa_io_defs.h"
@@ -1653,6 +1656,12 @@ static int efa_register_mr(struct ib_pd *ibpd, struct efa_mr *mr, u64 start,
16531656
mr->ibmr.lkey = result.l_key;
16541657
mr->ibmr.rkey = result.r_key;
16551658
mr->ibmr.length = length;
1659+
mr->ic_info.recv_ic_id = result.ic_info.recv_ic_id;
1660+
mr->ic_info.rdma_read_ic_id = result.ic_info.rdma_read_ic_id;
1661+
mr->ic_info.rdma_recv_ic_id = result.ic_info.rdma_recv_ic_id;
1662+
mr->ic_info.recv_ic_id_valid = result.ic_info.recv_ic_id_valid;
1663+
mr->ic_info.rdma_read_ic_id_valid = result.ic_info.rdma_read_ic_id_valid;
1664+
mr->ic_info.rdma_recv_ic_id_valid = result.ic_info.rdma_recv_ic_id_valid;
16561665
ibdev_dbg(&dev->ibdev, "Registered mr[%d]\n", mr->ibmr.lkey);
16571666

16581667
return 0;
@@ -1735,6 +1744,39 @@ struct ib_mr *efa_reg_mr(struct ib_pd *ibpd, u64 start, u64 length,
17351744
return ERR_PTR(err);
17361745
}
17371746

1747+
static int UVERBS_HANDLER(EFA_IB_METHOD_MR_QUERY)(struct uverbs_attr_bundle *attrs)
1748+
{
1749+
struct ib_mr *ibmr = uverbs_attr_get_obj(attrs, EFA_IB_ATTR_QUERY_MR_HANDLE);
1750+
struct efa_mr *mr = to_emr(ibmr);
1751+
u16 ic_id_validity = 0;
1752+
int ret;
1753+
1754+
ret = uverbs_copy_to(attrs, EFA_IB_ATTR_QUERY_MR_RESP_RECV_IC_ID,
1755+
&mr->ic_info.recv_ic_id, sizeof(mr->ic_info.recv_ic_id));
1756+
if (ret)
1757+
return ret;
1758+
1759+
ret = uverbs_copy_to(attrs, EFA_IB_ATTR_QUERY_MR_RESP_RDMA_READ_IC_ID,
1760+
&mr->ic_info.rdma_read_ic_id, sizeof(mr->ic_info.rdma_read_ic_id));
1761+
if (ret)
1762+
return ret;
1763+
1764+
ret = uverbs_copy_to(attrs, EFA_IB_ATTR_QUERY_MR_RESP_RDMA_RECV_IC_ID,
1765+
&mr->ic_info.rdma_recv_ic_id, sizeof(mr->ic_info.rdma_recv_ic_id));
1766+
if (ret)
1767+
return ret;
1768+
1769+
if (mr->ic_info.recv_ic_id_valid)
1770+
ic_id_validity |= EFA_QUERY_MR_VALIDITY_RECV_IC_ID;
1771+
if (mr->ic_info.rdma_read_ic_id_valid)
1772+
ic_id_validity |= EFA_QUERY_MR_VALIDITY_RDMA_READ_IC_ID;
1773+
if (mr->ic_info.rdma_recv_ic_id_valid)
1774+
ic_id_validity |= EFA_QUERY_MR_VALIDITY_RDMA_RECV_IC_ID;
1775+
1776+
return uverbs_copy_to(attrs, EFA_IB_ATTR_QUERY_MR_RESP_IC_ID_VALIDITY,
1777+
&ic_id_validity, sizeof(ic_id_validity));
1778+
}
1779+
17381780
int efa_dereg_mr(struct ib_mr *ibmr, struct ib_udata *udata)
17391781
{
17401782
struct efa_dev *dev = to_edev(ibmr->device);
@@ -2157,3 +2199,30 @@ enum rdma_link_layer efa_port_link_layer(struct ib_device *ibdev,
21572199
return IB_LINK_LAYER_UNSPECIFIED;
21582200
}
21592201

2202+
DECLARE_UVERBS_NAMED_METHOD(EFA_IB_METHOD_MR_QUERY,
2203+
UVERBS_ATTR_IDR(EFA_IB_ATTR_QUERY_MR_HANDLE,
2204+
UVERBS_OBJECT_MR,
2205+
UVERBS_ACCESS_READ,
2206+
UA_MANDATORY),
2207+
UVERBS_ATTR_PTR_OUT(EFA_IB_ATTR_QUERY_MR_RESP_IC_ID_VALIDITY,
2208+
UVERBS_ATTR_TYPE(u16),
2209+
UA_MANDATORY),
2210+
UVERBS_ATTR_PTR_OUT(EFA_IB_ATTR_QUERY_MR_RESP_RECV_IC_ID,
2211+
UVERBS_ATTR_TYPE(u16),
2212+
UA_MANDATORY),
2213+
UVERBS_ATTR_PTR_OUT(EFA_IB_ATTR_QUERY_MR_RESP_RDMA_READ_IC_ID,
2214+
UVERBS_ATTR_TYPE(u16),
2215+
UA_MANDATORY),
2216+
UVERBS_ATTR_PTR_OUT(EFA_IB_ATTR_QUERY_MR_RESP_RDMA_RECV_IC_ID,
2217+
UVERBS_ATTR_TYPE(u16),
2218+
UA_MANDATORY));
2219+
2220+
ADD_UVERBS_METHODS(efa_mr,
2221+
UVERBS_OBJECT_MR,
2222+
&UVERBS_METHOD(EFA_IB_METHOD_MR_QUERY));
2223+
2224+
const struct uapi_definition efa_uapi_defs[] = {
2225+
UAPI_DEF_CHAIN_OBJ_TREE(UVERBS_OBJECT_MR,
2226+
&efa_mr),
2227+
{},
2228+
};

include/uapi/rdma/efa-abi.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) */
22
/*
3-
* Copyright 2018-2023 Amazon.com, Inc. or its affiliates. All rights reserved.
3+
* Copyright 2018-2024 Amazon.com, Inc. or its affiliates. All rights reserved.
44
*/
55

66
#ifndef EFA_ABI_USER_H
77
#define EFA_ABI_USER_H
88

99
#include <linux/types.h>
10+
#include <rdma/ib_user_ioctl_cmds.h>
1011

1112
/*
1213
* Increment this value if any changes that break userspace ABI
@@ -134,4 +135,22 @@ struct efa_ibv_ex_query_device_resp {
134135
__u32 device_caps;
135136
};
136137

138+
enum {
139+
EFA_QUERY_MR_VALIDITY_RECV_IC_ID = 1 << 0,
140+
EFA_QUERY_MR_VALIDITY_RDMA_READ_IC_ID = 1 << 1,
141+
EFA_QUERY_MR_VALIDITY_RDMA_RECV_IC_ID = 1 << 2,
142+
};
143+
144+
enum efa_query_mr_attrs {
145+
EFA_IB_ATTR_QUERY_MR_HANDLE = (1U << UVERBS_ID_NS_SHIFT),
146+
EFA_IB_ATTR_QUERY_MR_RESP_IC_ID_VALIDITY,
147+
EFA_IB_ATTR_QUERY_MR_RESP_RECV_IC_ID,
148+
EFA_IB_ATTR_QUERY_MR_RESP_RDMA_READ_IC_ID,
149+
EFA_IB_ATTR_QUERY_MR_RESP_RDMA_RECV_IC_ID,
150+
};
151+
152+
enum efa_mr_methods {
153+
EFA_IB_METHOD_MR_QUERY = (1U << UVERBS_ID_NS_SHIFT),
154+
};
155+
137156
#endif /* EFA_ABI_USER_H */

0 commit comments

Comments
 (0)