Skip to content

Commit 641d120

Browse files
mikijoyjgunthorpe
authored andcommitted
IB/core: Move query port to ioctl
Add a method for query port under the uverbs global methods. Current ib_port_attr struct is passed as a single attribute and port_cap_flags2 is added as a new attribute to the function. Signed-off-by: Michael Guralnik <michaelgur@mellanox.com> Signed-off-by: Leon Romanovsky <leonro@mellanox.com> Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
1 parent 4fa2813 commit 641d120

File tree

5 files changed

+118
-53
lines changed

5 files changed

+118
-53
lines changed

drivers/infiniband/core/uverbs.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,4 +293,29 @@ extern const struct uverbs_object_def UVERBS_OBJECT(UVERBS_OBJECT_FLOW_ACTION);
293293
extern const struct uverbs_object_def UVERBS_OBJECT(UVERBS_OBJECT_DM);
294294
extern const struct uverbs_object_def UVERBS_OBJECT(UVERBS_OBJECT_COUNTERS);
295295

296+
/*
297+
* ib_uverbs_query_port_resp.port_cap_flags started out as just a copy of the
298+
* PortInfo CapabilityMask, but was extended with unique bits.
299+
*/
300+
static inline u32 make_port_cap_flags(const struct ib_port_attr *attr)
301+
{
302+
u32 res;
303+
304+
/* All IBA CapabilityMask bits are passed through here, except bit 26,
305+
* which is overridden with IP_BASED_GIDS. This is due to a historical
306+
* mistake in the implementation of IP_BASED_GIDS. Otherwise all other
307+
* bits match the IBA definition across all kernel versions.
308+
*/
309+
res = attr->port_cap_flags & ~(u32)IB_UVERBS_PCF_IP_BASED_GIDS;
310+
311+
if (attr->ip_gids)
312+
res |= IB_UVERBS_PCF_IP_BASED_GIDS;
313+
314+
return res;
315+
}
316+
317+
318+
void copy_port_attr_to_resp(struct ib_port_attr *attr,
319+
struct ib_uverbs_query_port_resp *resp,
320+
struct ib_device *ib_dev, u8 port_num);
296321
#endif /* UVERBS_H */

drivers/infiniband/core/uverbs_cmd.c

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -361,27 +361,6 @@ static int ib_uverbs_query_device(struct uverbs_attr_bundle *attrs)
361361
return uverbs_response(attrs, &resp, sizeof(resp));
362362
}
363363

364-
/*
365-
* ib_uverbs_query_port_resp.port_cap_flags started out as just a copy of the
366-
* PortInfo CapabilityMask, but was extended with unique bits.
367-
*/
368-
static u32 make_port_cap_flags(const struct ib_port_attr *attr)
369-
{
370-
u32 res;
371-
372-
/* All IBA CapabilityMask bits are passed through here, except bit 26,
373-
* which is overridden with IP_BASED_GIDS. This is due to a historical
374-
* mistake in the implementation of IP_BASED_GIDS. Otherwise all other
375-
* bits match the IBA definition across all kernel versions.
376-
*/
377-
res = attr->port_cap_flags & ~(u32)IB_UVERBS_PCF_IP_BASED_GIDS;
378-
379-
if (attr->ip_gids)
380-
res |= IB_UVERBS_PCF_IP_BASED_GIDS;
381-
382-
return res;
383-
}
384-
385364
static int ib_uverbs_query_port(struct uverbs_attr_bundle *attrs)
386365
{
387366
struct ib_uverbs_query_port cmd;
@@ -405,37 +384,7 @@ static int ib_uverbs_query_port(struct uverbs_attr_bundle *attrs)
405384
return ret;
406385

407386
memset(&resp, 0, sizeof resp);
408-
409-
resp.state = attr.state;
410-
resp.max_mtu = attr.max_mtu;
411-
resp.active_mtu = attr.active_mtu;
412-
resp.gid_tbl_len = attr.gid_tbl_len;
413-
resp.port_cap_flags = make_port_cap_flags(&attr);
414-
resp.max_msg_sz = attr.max_msg_sz;
415-
resp.bad_pkey_cntr = attr.bad_pkey_cntr;
416-
resp.qkey_viol_cntr = attr.qkey_viol_cntr;
417-
resp.pkey_tbl_len = attr.pkey_tbl_len;
418-
419-
if (rdma_is_grh_required(ib_dev, cmd.port_num))
420-
resp.flags |= IB_UVERBS_QPF_GRH_REQUIRED;
421-
422-
if (rdma_cap_opa_ah(ib_dev, cmd.port_num)) {
423-
resp.lid = OPA_TO_IB_UCAST_LID(attr.lid);
424-
resp.sm_lid = OPA_TO_IB_UCAST_LID(attr.sm_lid);
425-
} else {
426-
resp.lid = ib_lid_cpu16(attr.lid);
427-
resp.sm_lid = ib_lid_cpu16(attr.sm_lid);
428-
}
429-
resp.lmc = attr.lmc;
430-
resp.max_vl_num = attr.max_vl_num;
431-
resp.sm_sl = attr.sm_sl;
432-
resp.subnet_timeout = attr.subnet_timeout;
433-
resp.init_type_reply = attr.init_type_reply;
434-
resp.active_width = attr.active_width;
435-
resp.active_speed = attr.active_speed;
436-
resp.phys_state = attr.phys_state;
437-
resp.link_layer = rdma_port_get_link_layer(ib_dev,
438-
cmd.port_num);
387+
copy_port_attr_to_resp(&attr, &resp, ib_dev, cmd.port_num);
439388

440389
return uverbs_response(attrs, &resp, sizeof(resp));
441390
}

drivers/infiniband/core/uverbs_std_types_device.c

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include <rdma/uverbs_std_types.h>
77
#include "rdma_core.h"
88
#include "uverbs.h"
9+
#include <rdma/uverbs_ioctl.h>
10+
#include <rdma/opa_addr.h>
911

1012
/*
1113
* This ioctl method allows calling any defined write or write_ex
@@ -127,6 +129,71 @@ static int UVERBS_HANDLER(UVERBS_METHOD_INFO_HANDLES)(
127129
return ret;
128130
}
129131

132+
void copy_port_attr_to_resp(struct ib_port_attr *attr,
133+
struct ib_uverbs_query_port_resp *resp,
134+
struct ib_device *ib_dev, u8 port_num)
135+
{
136+
resp->state = attr->state;
137+
resp->max_mtu = attr->max_mtu;
138+
resp->active_mtu = attr->active_mtu;
139+
resp->gid_tbl_len = attr->gid_tbl_len;
140+
resp->port_cap_flags = make_port_cap_flags(attr);
141+
resp->max_msg_sz = attr->max_msg_sz;
142+
resp->bad_pkey_cntr = attr->bad_pkey_cntr;
143+
resp->qkey_viol_cntr = attr->qkey_viol_cntr;
144+
resp->pkey_tbl_len = attr->pkey_tbl_len;
145+
146+
if (rdma_is_grh_required(ib_dev, port_num))
147+
resp->flags |= IB_UVERBS_QPF_GRH_REQUIRED;
148+
149+
if (rdma_cap_opa_ah(ib_dev, port_num)) {
150+
resp->lid = OPA_TO_IB_UCAST_LID(attr->lid);
151+
resp->sm_lid = OPA_TO_IB_UCAST_LID(attr->sm_lid);
152+
} else {
153+
resp->lid = ib_lid_cpu16(attr->lid);
154+
resp->sm_lid = ib_lid_cpu16(attr->sm_lid);
155+
}
156+
157+
resp->lmc = attr->lmc;
158+
resp->max_vl_num = attr->max_vl_num;
159+
resp->sm_sl = attr->sm_sl;
160+
resp->subnet_timeout = attr->subnet_timeout;
161+
resp->init_type_reply = attr->init_type_reply;
162+
resp->active_width = attr->active_width;
163+
resp->active_speed = attr->active_speed;
164+
resp->phys_state = attr->phys_state;
165+
resp->link_layer = rdma_port_get_link_layer(ib_dev, port_num);
166+
}
167+
168+
static int UVERBS_HANDLER(UVERBS_METHOD_QUERY_PORT)(
169+
struct uverbs_attr_bundle *attrs)
170+
{
171+
struct ib_device *ib_dev = attrs->ufile->device->ib_dev;
172+
struct ib_port_attr attr = {};
173+
struct ib_uverbs_query_port_resp_ex resp = {};
174+
int ret;
175+
u8 port_num;
176+
177+
/* FIXME: Extend the UAPI_DEF_OBJ_NEEDS_FN stuff.. */
178+
if (!ib_dev->ops.query_port)
179+
return -EOPNOTSUPP;
180+
181+
ret = uverbs_get_const(&port_num, attrs,
182+
UVERBS_ATTR_QUERY_PORT_PORT_NUM);
183+
if (ret)
184+
return ret;
185+
186+
ret = ib_query_port(ib_dev, port_num, &attr);
187+
if (ret)
188+
return ret;
189+
190+
copy_port_attr_to_resp(&attr, &resp.legacy_resp, ib_dev, port_num);
191+
resp.port_cap_flags2 = attr.port_cap_flags2;
192+
193+
return uverbs_copy_to_struct_or_zero(attrs, UVERBS_ATTR_QUERY_PORT_RESP,
194+
&resp, sizeof(resp));
195+
}
196+
130197
DECLARE_UVERBS_NAMED_METHOD(
131198
UVERBS_METHOD_INFO_HANDLES,
132199
/* Also includes any device specific object ids */
@@ -137,9 +204,19 @@ DECLARE_UVERBS_NAMED_METHOD(
137204
UVERBS_ATTR_PTR_OUT(UVERBS_ATTR_INFO_HANDLES_LIST,
138205
UVERBS_ATTR_MIN_SIZE(sizeof(u32)), UA_OPTIONAL));
139206

207+
DECLARE_UVERBS_NAMED_METHOD(
208+
UVERBS_METHOD_QUERY_PORT,
209+
UVERBS_ATTR_CONST_IN(UVERBS_ATTR_QUERY_PORT_PORT_NUM, u8, UA_MANDATORY),
210+
UVERBS_ATTR_PTR_OUT(
211+
UVERBS_ATTR_QUERY_PORT_RESP,
212+
UVERBS_ATTR_STRUCT(struct ib_uverbs_query_port_resp_ex,
213+
reserved),
214+
UA_MANDATORY));
215+
140216
DECLARE_UVERBS_GLOBAL_METHODS(UVERBS_OBJECT_DEVICE,
141217
&UVERBS_METHOD(UVERBS_METHOD_INVOKE_WRITE),
142-
&UVERBS_METHOD(UVERBS_METHOD_INFO_HANDLES));
218+
&UVERBS_METHOD(UVERBS_METHOD_INFO_HANDLES),
219+
&UVERBS_METHOD(UVERBS_METHOD_QUERY_PORT));
143220

144221
const struct uapi_definition uverbs_def_obj_device[] = {
145222
UAPI_DEF_CHAIN_OBJ_TREE_NAMED(UVERBS_OBJECT_DEVICE),

include/uapi/rdma/ib_user_ioctl_cmds.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ enum {
6666
enum uverbs_methods_device {
6767
UVERBS_METHOD_INVOKE_WRITE,
6868
UVERBS_METHOD_INFO_HANDLES,
69+
UVERBS_METHOD_QUERY_PORT,
6970
};
7071

7172
enum uverbs_attrs_invoke_write_cmd_attr_ids {
@@ -74,6 +75,11 @@ enum uverbs_attrs_invoke_write_cmd_attr_ids {
7475
UVERBS_ATTR_WRITE_CMD,
7576
};
7677

78+
enum uverbs_attrs_query_port_cmd_attr_ids {
79+
UVERBS_ATTR_QUERY_PORT_PORT_NUM,
80+
UVERBS_ATTR_QUERY_PORT_RESP,
81+
};
82+
7783
enum uverbs_attrs_create_cq_cmd_attr_ids {
7884
UVERBS_ATTR_CREATE_CQ_HANDLE,
7985
UVERBS_ATTR_CREATE_CQ_CQE,
@@ -234,4 +240,5 @@ enum uverbs_methods_flow {
234240
enum uverbs_attrs_flow_destroy_ids {
235241
UVERBS_ATTR_DESTROY_FLOW_HANDLE,
236242
};
243+
237244
#endif

include/uapi/rdma/ib_user_ioctl_verbs.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#define IB_USER_IOCTL_VERBS_H
3636

3737
#include <linux/types.h>
38+
#include <rdma/ib_user_verbs.h>
3839

3940
#ifndef RDMA_UAPI_PTR
4041
#define RDMA_UAPI_PTR(_type, _name) __aligned_u64 _name
@@ -166,4 +167,10 @@ enum ib_uverbs_advise_mr_flag {
166167
IB_UVERBS_ADVISE_MR_FLAG_FLUSH = 1 << 0,
167168
};
168169

170+
struct ib_uverbs_query_port_resp_ex {
171+
struct ib_uverbs_query_port_resp legacy_resp;
172+
__u16 port_cap_flags2;
173+
__u8 reserved[6];
174+
};
175+
169176
#endif

0 commit comments

Comments
 (0)