RDMA/erdma: Add the erdma_query_pkey() interface
authorBoshi Yu <boshiyu@linux.alibaba.com>
Wed, 11 Dec 2024 02:09:03 +0000 (10:09 +0800)
committerLeon Romanovsky <leon@kernel.org>
Mon, 16 Dec 2024 13:20:05 +0000 (08:20 -0500)
The erdma_query_pkey() interface queries the PKey at the specified
index. Currently, erdma supports only one partition and returns the
default PKey for each query. Besides, the correct length of the PKey
table can be obtained by calling the erdma_query_port() and
erdma_get_port_immutable() interfaces.

Signed-off-by: Boshi Yu <boshiyu@linux.alibaba.com>
Link: https://patch.msgid.link/20241211020930.68833-4-boshiyu@linux.alibaba.com
Reviewed-by: Cheng Xu <chengyou@linux.alibaba.com>
Signed-off-by: Leon Romanovsky <leon@kernel.org>
drivers/infiniband/hw/erdma/erdma_hw.h
drivers/infiniband/hw/erdma/erdma_main.c
drivers/infiniband/hw/erdma/erdma_verbs.c
drivers/infiniband/hw/erdma/erdma_verbs.h

index 7e03c5f97501a09c74927751786be54b6df64098..f7f9dcac3ab01c3aeb4dc08037512d0341144c44 100644 (file)
@@ -23,6 +23,8 @@
 
 /* RoCEv2 related */
 #define ERDMA_ROCEV2_GID_SIZE 16
+#define ERDMA_MAX_PKEYS 1
+#define ERDMA_DEFAULT_PKEY 0xFFFF
 
 /* erdma device protocol type */
 enum erdma_proto_type {
index 77440324b7e73ecfbcd7b5292670a277b29533f4..b9d0ad77436a7f33e25daff039638e6ae59f0c66 100644 (file)
@@ -481,6 +481,7 @@ static const struct ib_device_ops erdma_device_ops_rocev2 = {
        .get_link_layer = erdma_get_link_layer,
        .add_gid = erdma_add_gid,
        .del_gid = erdma_del_gid,
+       .query_pkey = erdma_query_pkey,
 };
 
 static const struct ib_device_ops erdma_device_ops_iwarp = {
index 9944eed584ecdcfe857e96bee75ea44d2190fbcc..03ea52bb233e345ca4709007135400c08623ac8d 100644 (file)
@@ -336,6 +336,9 @@ int erdma_query_device(struct ib_device *ibdev, struct ib_device_attr *attr,
        attr->max_fast_reg_page_list_len = ERDMA_MAX_FRMR_PA;
        attr->page_size_cap = ERDMA_PAGE_SIZE_SUPPORT;
 
+       if (erdma_device_rocev2(dev))
+               attr->max_pkeys = ERDMA_MAX_PKEYS;
+
        if (dev->attrs.cap_flags & ERDMA_DEV_CAP_FLAGS_ATOMIC)
                attr->atomic_cap = IB_ATOMIC_GLOB;
 
@@ -372,6 +375,7 @@ int erdma_query_port(struct ib_device *ibdev, u32 port,
        } else {
                attr->gid_tbl_len = dev->attrs.max_gid;
                attr->ip_gids = true;
+               attr->pkey_tbl_len = ERDMA_MAX_PKEYS;
        }
 
        attr->port_cap_flags = IB_PORT_CM_SUP | IB_PORT_DEVICE_MGMT_SUP;
@@ -411,6 +415,7 @@ int erdma_get_port_immutable(struct ib_device *ibdev, u32 port,
                        RDMA_CORE_PORT_IBA_ROCE_UDP_ENCAP;
                port_immutable->max_mad_size = IB_MGMT_MAD_SIZE;
                port_immutable->gid_tbl_len = dev->attrs.max_gid;
+               port_immutable->pkey_tbl_len = ERDMA_MAX_PKEYS;
        }
 
        return 0;
@@ -1903,3 +1908,12 @@ int erdma_del_gid(const struct ib_gid_attr *attr, void **context)
        return erdma_set_gid(to_edev(attr->device), ERDMA_SET_GID_OP_DEL,
                             attr->index, NULL);
 }
+
+int erdma_query_pkey(struct ib_device *ibdev, u32 port, u16 index, u16 *pkey)
+{
+       if (index >= ERDMA_MAX_PKEYS)
+               return -EINVAL;
+
+       *pkey = ERDMA_DEFAULT_PKEY;
+       return 0;
+}
index 23cfeaf79eaabcb1367c12013d7e0f063423c8bb..1ae6ba56f59724451108c4a3a970f180298b838a 100644 (file)
@@ -394,5 +394,6 @@ enum rdma_link_layer erdma_get_link_layer(struct ib_device *ibdev,
                                          u32 port_num);
 int erdma_add_gid(const struct ib_gid_attr *attr, void **context);
 int erdma_del_gid(const struct ib_gid_attr *attr, void **context);
+int erdma_query_pkey(struct ib_device *ibdev, u32 port, u16 index, u16 *pkey);
 
 #endif