Skip to content

Commit 938fe83

Browse files
Saeed Mahameeddavem330
authored andcommitted
net/mlx5_core: New device capabilities handling
- Query all supported types of dev caps on driver load. - Store the Cap data outbox per cap type into driver private data. - Introduce new Macros to access/dump stored caps (using the auto generated data types). - Obsolete SW representation of dev caps (no need for SW copy for each cap). - Modify IB driver to use new macros for checking caps. Signed-off-by: Saeed Mahameed <[email protected]> Signed-off-by: Amir Vadai <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent e281682 commit 938fe83

File tree

15 files changed

+310
-349
lines changed

15 files changed

+310
-349
lines changed

drivers/infiniband/hw/mlx5/cq.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ struct ib_cq *mlx5_ib_create_cq(struct ib_device *ibdev, int entries,
753753
return ERR_PTR(-EINVAL);
754754

755755
entries = roundup_pow_of_two(entries + 1);
756-
if (entries > dev->mdev->caps.gen.max_cqes)
756+
if (entries > (1 << MLX5_CAP_GEN(dev->mdev, log_max_cq_sz)))
757757
return ERR_PTR(-EINVAL);
758758

759759
cq = kzalloc(sizeof(*cq), GFP_KERNEL);
@@ -920,7 +920,7 @@ int mlx5_ib_modify_cq(struct ib_cq *cq, u16 cq_count, u16 cq_period)
920920
int err;
921921
u32 fsel;
922922

923-
if (!(dev->mdev->caps.gen.flags & MLX5_DEV_CAP_FLAG_CQ_MODER))
923+
if (!MLX5_CAP_GEN(dev->mdev, cq_moderation))
924924
return -ENOSYS;
925925

926926
in = kzalloc(sizeof(*in), GFP_KERNEL);
@@ -1075,7 +1075,7 @@ int mlx5_ib_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
10751075
int uninitialized_var(cqe_size);
10761076
unsigned long flags;
10771077

1078-
if (!(dev->mdev->caps.gen.flags & MLX5_DEV_CAP_FLAG_RESIZE_CQ)) {
1078+
if (!MLX5_CAP_GEN(dev->mdev, cq_resize)) {
10791079
pr_info("Firmware does not support resize CQ\n");
10801080
return -ENOSYS;
10811081
}
@@ -1084,7 +1084,7 @@ int mlx5_ib_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
10841084
return -EINVAL;
10851085

10861086
entries = roundup_pow_of_two(entries + 1);
1087-
if (entries > dev->mdev->caps.gen.max_cqes + 1)
1087+
if (entries > (1 << MLX5_CAP_GEN(dev->mdev, log_max_cq_sz)) + 1)
10881088
return -EINVAL;
10891089

10901090
if (entries == ibcq->cqe + 1)

drivers/infiniband/hw/mlx5/mad.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ int mlx5_query_ext_port_caps(struct mlx5_ib_dev *dev, u8 port)
129129

130130
packet_error = be16_to_cpu(out_mad->status);
131131

132-
dev->mdev->caps.gen.ext_port_cap[port - 1] = (!err && !packet_error) ?
132+
dev->mdev->port_caps[port - 1].ext_port_cap = (!err && !packet_error) ?
133133
MLX_EXT_PORT_CAP_FLAG_EXTENDED_PORT_INFO : 0;
134134

135135
out:

drivers/infiniband/hw/mlx5/main.c

Lines changed: 54 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,13 @@ static int mlx5_ib_query_device(struct ib_device *ibdev,
6666
struct ib_device_attr *props)
6767
{
6868
struct mlx5_ib_dev *dev = to_mdev(ibdev);
69+
struct mlx5_core_dev *mdev = dev->mdev;
6970
struct ib_smp *in_mad = NULL;
7071
struct ib_smp *out_mad = NULL;
71-
struct mlx5_general_caps *gen;
7272
int err = -ENOMEM;
7373
int max_rq_sg;
7474
int max_sq_sg;
75-
u64 flags;
7675

77-
gen = &dev->mdev->caps.gen;
7876
in_mad = kzalloc(sizeof(*in_mad), GFP_KERNEL);
7977
out_mad = kmalloc(sizeof(*out_mad), GFP_KERNEL);
8078
if (!in_mad || !out_mad)
@@ -96,18 +94,18 @@ static int mlx5_ib_query_device(struct ib_device *ibdev,
9694
IB_DEVICE_PORT_ACTIVE_EVENT |
9795
IB_DEVICE_SYS_IMAGE_GUID |
9896
IB_DEVICE_RC_RNR_NAK_GEN;
99-
flags = gen->flags;
100-
if (flags & MLX5_DEV_CAP_FLAG_BAD_PKEY_CNTR)
97+
98+
if (MLX5_CAP_GEN(mdev, pkv))
10199
props->device_cap_flags |= IB_DEVICE_BAD_PKEY_CNTR;
102-
if (flags & MLX5_DEV_CAP_FLAG_BAD_QKEY_CNTR)
100+
if (MLX5_CAP_GEN(mdev, qkv))
103101
props->device_cap_flags |= IB_DEVICE_BAD_QKEY_CNTR;
104-
if (flags & MLX5_DEV_CAP_FLAG_APM)
102+
if (MLX5_CAP_GEN(mdev, apm))
105103
props->device_cap_flags |= IB_DEVICE_AUTO_PATH_MIG;
106104
props->device_cap_flags |= IB_DEVICE_LOCAL_DMA_LKEY;
107-
if (flags & MLX5_DEV_CAP_FLAG_XRC)
105+
if (MLX5_CAP_GEN(mdev, xrc))
108106
props->device_cap_flags |= IB_DEVICE_XRC;
109107
props->device_cap_flags |= IB_DEVICE_MEM_MGT_EXTENSIONS;
110-
if (flags & MLX5_DEV_CAP_FLAG_SIG_HAND_OVER) {
108+
if (MLX5_CAP_GEN(mdev, sho)) {
111109
props->device_cap_flags |= IB_DEVICE_SIGNATURE_HANDOVER;
112110
/* At this stage no support for signature handover */
113111
props->sig_prot_cap = IB_PROT_T10DIF_TYPE_1 |
@@ -116,7 +114,7 @@ static int mlx5_ib_query_device(struct ib_device *ibdev,
116114
props->sig_guard_cap = IB_GUARD_T10DIF_CRC |
117115
IB_GUARD_T10DIF_CSUM;
118116
}
119-
if (flags & MLX5_DEV_CAP_FLAG_BLOCK_MCAST)
117+
if (MLX5_CAP_GEN(mdev, block_lb_mc))
120118
props->device_cap_flags |= IB_DEVICE_BLOCK_MULTICAST_LOOPBACK;
121119

122120
props->vendor_id = be32_to_cpup((__be32 *)(out_mad->data + 36)) &
@@ -126,37 +124,38 @@ static int mlx5_ib_query_device(struct ib_device *ibdev,
126124
memcpy(&props->sys_image_guid, out_mad->data + 4, 8);
127125

128126
props->max_mr_size = ~0ull;
129-
props->page_size_cap = gen->min_page_sz;
130-
props->max_qp = 1 << gen->log_max_qp;
131-
props->max_qp_wr = gen->max_wqes;
132-
max_rq_sg = gen->max_rq_desc_sz / sizeof(struct mlx5_wqe_data_seg);
133-
max_sq_sg = (gen->max_sq_desc_sz - sizeof(struct mlx5_wqe_ctrl_seg)) /
134-
sizeof(struct mlx5_wqe_data_seg);
127+
props->page_size_cap = 1ull << MLX5_CAP_GEN(mdev, log_pg_sz);
128+
props->max_qp = 1 << MLX5_CAP_GEN(mdev, log_max_qp);
129+
props->max_qp_wr = 1 << MLX5_CAP_GEN(mdev, log_max_qp_sz);
130+
max_rq_sg = MLX5_CAP_GEN(mdev, max_wqe_sz_rq) /
131+
sizeof(struct mlx5_wqe_data_seg);
132+
max_sq_sg = (MLX5_CAP_GEN(mdev, max_wqe_sz_sq) -
133+
sizeof(struct mlx5_wqe_ctrl_seg)) /
134+
sizeof(struct mlx5_wqe_data_seg);
135135
props->max_sge = min(max_rq_sg, max_sq_sg);
136-
props->max_cq = 1 << gen->log_max_cq;
137-
props->max_cqe = gen->max_cqes - 1;
138-
props->max_mr = 1 << gen->log_max_mkey;
139-
props->max_pd = 1 << gen->log_max_pd;
140-
props->max_qp_rd_atom = 1 << gen->log_max_ra_req_qp;
141-
props->max_qp_init_rd_atom = 1 << gen->log_max_ra_res_qp;
142-
props->max_srq = 1 << gen->log_max_srq;
143-
props->max_srq_wr = gen->max_srq_wqes - 1;
144-
props->local_ca_ack_delay = gen->local_ca_ack_delay;
136+
props->max_cq = 1 << MLX5_CAP_GEN(mdev, log_max_cq);
137+
props->max_cqe = (1 << MLX5_CAP_GEN(mdev, log_max_eq_sz)) - 1;
138+
props->max_mr = 1 << MLX5_CAP_GEN(mdev, log_max_mkey);
139+
props->max_pd = 1 << MLX5_CAP_GEN(mdev, log_max_pd);
140+
props->max_qp_rd_atom = 1 << MLX5_CAP_GEN(mdev, log_max_ra_req_qp);
141+
props->max_qp_init_rd_atom = 1 << MLX5_CAP_GEN(mdev, log_max_ra_res_qp);
142+
props->max_srq = 1 << MLX5_CAP_GEN(mdev, log_max_srq);
143+
props->max_srq_wr = (1 << MLX5_CAP_GEN(mdev, log_max_srq_sz)) - 1;
144+
props->local_ca_ack_delay = MLX5_CAP_GEN(mdev, local_ca_ack_delay);
145145
props->max_res_rd_atom = props->max_qp_rd_atom * props->max_qp;
146146
props->max_srq_sge = max_rq_sg - 1;
147147
props->max_fast_reg_page_list_len = (unsigned int)-1;
148-
props->local_ca_ack_delay = gen->local_ca_ack_delay;
149148
props->atomic_cap = IB_ATOMIC_NONE;
150149
props->masked_atomic_cap = IB_ATOMIC_NONE;
151150
props->max_pkeys = be16_to_cpup((__be16 *)(out_mad->data + 28));
152-
props->max_mcast_grp = 1 << gen->log_max_mcg;
153-
props->max_mcast_qp_attach = gen->max_qp_mcg;
151+
props->max_mcast_grp = 1 << MLX5_CAP_GEN(mdev, log_max_mcg);
152+
props->max_mcast_qp_attach = MLX5_CAP_GEN(mdev, max_qp_mcg);
154153
props->max_total_mcast_qp_attach = props->max_mcast_qp_attach *
155154
props->max_mcast_grp;
156155
props->max_map_per_fmr = INT_MAX; /* no limit in ConnectIB */
157156

158157
#ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
159-
if (dev->mdev->caps.gen.flags & MLX5_DEV_CAP_FLAG_ON_DMND_PG)
158+
if (MLX5_CAP_GEN(mdev, pg))
160159
props->device_cap_flags |= IB_DEVICE_ON_DEMAND_PAGING;
161160
props->odp_caps = dev->odp_caps;
162161
#endif
@@ -172,14 +171,13 @@ int mlx5_ib_query_port(struct ib_device *ibdev, u8 port,
172171
struct ib_port_attr *props)
173172
{
174173
struct mlx5_ib_dev *dev = to_mdev(ibdev);
174+
struct mlx5_core_dev *mdev = dev->mdev;
175175
struct ib_smp *in_mad = NULL;
176176
struct ib_smp *out_mad = NULL;
177-
struct mlx5_general_caps *gen;
178177
int ext_active_speed;
179178
int err = -ENOMEM;
180179

181-
gen = &dev->mdev->caps.gen;
182-
if (port < 1 || port > gen->num_ports) {
180+
if (port < 1 || port > MLX5_CAP_GEN(mdev, num_ports)) {
183181
mlx5_ib_warn(dev, "invalid port number %d\n", port);
184182
return -EINVAL;
185183
}
@@ -210,8 +208,8 @@ int mlx5_ib_query_port(struct ib_device *ibdev, u8 port,
210208
props->phys_state = out_mad->data[33] >> 4;
211209
props->port_cap_flags = be32_to_cpup((__be32 *)(out_mad->data + 20));
212210
props->gid_tbl_len = out_mad->data[50];
213-
props->max_msg_sz = 1 << gen->log_max_msg;
214-
props->pkey_tbl_len = gen->port[port - 1].pkey_table_len;
211+
props->max_msg_sz = 1 << MLX5_CAP_GEN(mdev, log_max_msg);
212+
props->pkey_tbl_len = mdev->port_caps[port - 1].pkey_table_len;
215213
props->bad_pkey_cntr = be16_to_cpup((__be16 *)(out_mad->data + 46));
216214
props->qkey_viol_cntr = be16_to_cpup((__be16 *)(out_mad->data + 48));
217215
props->active_width = out_mad->data[31] & 0xf;
@@ -238,7 +236,7 @@ int mlx5_ib_query_port(struct ib_device *ibdev, u8 port,
238236

239237
/* If reported active speed is QDR, check if is FDR-10 */
240238
if (props->active_speed == 4) {
241-
if (gen->ext_port_cap[port - 1] &
239+
if (mdev->port_caps[port - 1].ext_port_cap &
242240
MLX_EXT_PORT_CAP_FLAG_EXTENDED_PORT_INFO) {
243241
init_query_mad(in_mad);
244242
in_mad->attr_id = MLX5_ATTR_EXTENDED_PORT_INFO;
@@ -392,7 +390,6 @@ static struct ib_ucontext *mlx5_ib_alloc_ucontext(struct ib_device *ibdev,
392390
struct mlx5_ib_alloc_ucontext_req_v2 req;
393391
struct mlx5_ib_alloc_ucontext_resp resp;
394392
struct mlx5_ib_ucontext *context;
395-
struct mlx5_general_caps *gen;
396393
struct mlx5_uuar_info *uuari;
397394
struct mlx5_uar *uars;
398395
int gross_uuars;
@@ -403,7 +400,6 @@ static struct ib_ucontext *mlx5_ib_alloc_ucontext(struct ib_device *ibdev,
403400
int i;
404401
size_t reqlen;
405402

406-
gen = &dev->mdev->caps.gen;
407403
if (!dev->ib_active)
408404
return ERR_PTR(-EAGAIN);
409405

@@ -436,14 +432,14 @@ static struct ib_ucontext *mlx5_ib_alloc_ucontext(struct ib_device *ibdev,
436432

437433
num_uars = req.total_num_uuars / MLX5_NON_FP_BF_REGS_PER_PAGE;
438434
gross_uuars = num_uars * MLX5_BF_REGS_PER_PAGE;
439-
resp.qp_tab_size = 1 << gen->log_max_qp;
440-
resp.bf_reg_size = gen->bf_reg_size;
441-
resp.cache_line_size = L1_CACHE_BYTES;
442-
resp.max_sq_desc_sz = gen->max_sq_desc_sz;
443-
resp.max_rq_desc_sz = gen->max_rq_desc_sz;
444-
resp.max_send_wqebb = gen->max_wqes;
445-
resp.max_recv_wr = gen->max_wqes;
446-
resp.max_srq_recv_wr = gen->max_srq_wqes;
435+
resp.qp_tab_size = 1 << MLX5_CAP_GEN(dev->mdev, log_max_qp);
436+
resp.bf_reg_size = 1 << MLX5_CAP_GEN(dev->mdev, log_bf_reg_size);
437+
resp.cache_line_size = L1_CACHE_BYTES;
438+
resp.max_sq_desc_sz = MLX5_CAP_GEN(dev->mdev, max_wqe_sz_sq);
439+
resp.max_rq_desc_sz = MLX5_CAP_GEN(dev->mdev, max_wqe_sz_rq);
440+
resp.max_send_wqebb = 1 << MLX5_CAP_GEN(dev->mdev, log_max_qp_sz);
441+
resp.max_recv_wr = 1 << MLX5_CAP_GEN(dev->mdev, log_max_qp_sz);
442+
resp.max_srq_recv_wr = 1 << MLX5_CAP_GEN(dev->mdev, log_max_srq_sz);
447443

448444
context = kzalloc(sizeof(*context), GFP_KERNEL);
449445
if (!context)
@@ -493,7 +489,7 @@ static struct ib_ucontext *mlx5_ib_alloc_ucontext(struct ib_device *ibdev,
493489
mutex_init(&context->db_page_mutex);
494490

495491
resp.tot_uuars = req.total_num_uuars;
496-
resp.num_ports = gen->num_ports;
492+
resp.num_ports = MLX5_CAP_GEN(dev->mdev, num_ports);
497493
err = ib_copy_to_udata(udata, &resp,
498494
sizeof(resp) - sizeof(resp.reserved));
499495
if (err)
@@ -895,23 +891,19 @@ static void mlx5_ib_event(struct mlx5_core_dev *dev, void *context,
895891

896892
static void get_ext_port_caps(struct mlx5_ib_dev *dev)
897893
{
898-
struct mlx5_general_caps *gen;
899894
int port;
900895

901-
gen = &dev->mdev->caps.gen;
902-
for (port = 1; port <= gen->num_ports; port++)
896+
for (port = 1; port <= MLX5_CAP_GEN(dev->mdev, num_ports); port++)
903897
mlx5_query_ext_port_caps(dev, port);
904898
}
905899

906900
static int get_port_caps(struct mlx5_ib_dev *dev)
907901
{
908902
struct ib_device_attr *dprops = NULL;
909903
struct ib_port_attr *pprops = NULL;
910-
struct mlx5_general_caps *gen;
911904
int err = -ENOMEM;
912905
int port;
913906

914-
gen = &dev->mdev->caps.gen;
915907
pprops = kmalloc(sizeof(*pprops), GFP_KERNEL);
916908
if (!pprops)
917909
goto out;
@@ -926,14 +918,17 @@ static int get_port_caps(struct mlx5_ib_dev *dev)
926918
goto out;
927919
}
928920

929-
for (port = 1; port <= gen->num_ports; port++) {
921+
for (port = 1; port <= MLX5_CAP_GEN(dev->mdev, num_ports); port++) {
930922
err = mlx5_ib_query_port(&dev->ib_dev, port, pprops);
931923
if (err) {
932-
mlx5_ib_warn(dev, "query_port %d failed %d\n", port, err);
924+
mlx5_ib_warn(dev, "query_port %d failed %d\n",
925+
port, err);
933926
break;
934927
}
935-
gen->port[port - 1].pkey_table_len = dprops->max_pkeys;
936-
gen->port[port - 1].gid_table_len = pprops->gid_tbl_len;
928+
dev->mdev->port_caps[port - 1].pkey_table_len =
929+
dprops->max_pkeys;
930+
dev->mdev->port_caps[port - 1].gid_table_len =
931+
pprops->gid_tbl_len;
937932
mlx5_ib_dbg(dev, "pkey_table_len %d, gid_table_len %d\n",
938933
dprops->max_pkeys, pprops->gid_tbl_len);
939934
}
@@ -1207,8 +1202,8 @@ static void *mlx5_ib_add(struct mlx5_core_dev *mdev)
12071202
strlcpy(dev->ib_dev.name, "mlx5_%d", IB_DEVICE_NAME_MAX);
12081203
dev->ib_dev.owner = THIS_MODULE;
12091204
dev->ib_dev.node_type = RDMA_NODE_IB_CA;
1210-
dev->ib_dev.local_dma_lkey = mdev->caps.gen.reserved_lkey;
1211-
dev->num_ports = mdev->caps.gen.num_ports;
1205+
dev->ib_dev.local_dma_lkey = 0 /* not supported for now */;
1206+
dev->num_ports = MLX5_CAP_GEN(mdev, num_ports);
12121207
dev->ib_dev.phys_port_cnt = dev->num_ports;
12131208
dev->ib_dev.num_comp_vectors =
12141209
dev->mdev->priv.eq_table.num_comp_vectors;
@@ -1286,9 +1281,9 @@ static void *mlx5_ib_add(struct mlx5_core_dev *mdev)
12861281
dev->ib_dev.free_fast_reg_page_list = mlx5_ib_free_fast_reg_page_list;
12871282
dev->ib_dev.check_mr_status = mlx5_ib_check_mr_status;
12881283

1289-
mlx5_ib_internal_query_odp_caps(dev);
1284+
mlx5_ib_internal_fill_odp_caps(dev);
12901285

1291-
if (mdev->caps.gen.flags & MLX5_DEV_CAP_FLAG_XRC) {
1286+
if (MLX5_CAP_GEN(mdev, xrc)) {
12921287
dev->ib_dev.alloc_xrcd = mlx5_ib_alloc_xrcd;
12931288
dev->ib_dev.dealloc_xrcd = mlx5_ib_dealloc_xrcd;
12941289
dev->ib_dev.uverbs_cmd_mask |=

drivers/infiniband/hw/mlx5/mlx5_ib.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ int mlx5_ib_check_mr_status(struct ib_mr *ibmr, u32 check_mask,
617617
#ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
618618
extern struct workqueue_struct *mlx5_ib_page_fault_wq;
619619

620-
int mlx5_ib_internal_query_odp_caps(struct mlx5_ib_dev *dev);
620+
void mlx5_ib_internal_fill_odp_caps(struct mlx5_ib_dev *dev);
621621
void mlx5_ib_mr_pfault_handler(struct mlx5_ib_qp *qp,
622622
struct mlx5_ib_pfault *pfault);
623623
void mlx5_ib_odp_create_qp(struct mlx5_ib_qp *qp);
@@ -631,9 +631,9 @@ void mlx5_ib_invalidate_range(struct ib_umem *umem, unsigned long start,
631631
unsigned long end);
632632

633633
#else /* CONFIG_INFINIBAND_ON_DEMAND_PAGING */
634-
static inline int mlx5_ib_internal_query_odp_caps(struct mlx5_ib_dev *dev)
634+
static inline void mlx5_ib_internal_fill_odp_caps(struct mlx5_ib_dev *dev)
635635
{
636-
return 0;
636+
return;
637637
}
638638

639639
static inline void mlx5_ib_odp_create_qp(struct mlx5_ib_qp *qp) {}

drivers/infiniband/hw/mlx5/mr.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -975,8 +975,7 @@ static struct mlx5_ib_mr *reg_create(struct ib_pd *pd, u64 virt_addr,
975975
struct mlx5_ib_mr *mr;
976976
int inlen;
977977
int err;
978-
bool pg_cap = !!(dev->mdev->caps.gen.flags &
979-
MLX5_DEV_CAP_FLAG_ON_DMND_PG);
978+
bool pg_cap = !!(MLX5_CAP_GEN(dev->mdev, pg));
980979

981980
mr = kzalloc(sizeof(*mr), GFP_KERNEL);
982981
if (!mr)

0 commit comments

Comments
 (0)