Skip to content

Commit 3023a1e

Browse files
Kamalheibjgunthorpe
authored andcommitted
RDMA: Start use ib_device_ops
Make all the required change to start use the ib_device_ops structure. Signed-off-by: Kamal Heib <kamalheib1@gmail.com> Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
1 parent 02a42f8 commit 3023a1e

37 files changed

+353
-617
lines changed

drivers/infiniband/core/cache.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ static void free_gid_entry_locked(struct ib_gid_table_entry *entry)
217217

218218
if (rdma_cap_roce_gid_table(device, port_num) &&
219219
entry->state != GID_TABLE_ENTRY_INVALID)
220-
device->del_gid(&entry->attr, &entry->context);
220+
device->ops.del_gid(&entry->attr, &entry->context);
221221

222222
write_lock_irq(&table->rwlock);
223223

@@ -324,7 +324,7 @@ static int add_roce_gid(struct ib_gid_table_entry *entry)
324324
return -EINVAL;
325325
}
326326
if (rdma_cap_roce_gid_table(attr->device, attr->port_num)) {
327-
ret = attr->device->add_gid(attr, &entry->context);
327+
ret = attr->device->ops.add_gid(attr, &entry->context);
328328
if (ret) {
329329
dev_err(&attr->device->dev,
330330
"%s GID add failed port=%d index=%d\n",
@@ -548,8 +548,8 @@ int ib_cache_gid_add(struct ib_device *ib_dev, u8 port,
548548
unsigned long mask;
549549
int ret;
550550

551-
if (ib_dev->get_netdev) {
552-
idev = ib_dev->get_netdev(ib_dev, port);
551+
if (ib_dev->ops.get_netdev) {
552+
idev = ib_dev->ops.get_netdev(ib_dev, port);
553553
if (idev && attr->ndev != idev) {
554554
union ib_gid default_gid;
555555

@@ -1296,9 +1296,9 @@ static int config_non_roce_gid_cache(struct ib_device *device,
12961296

12971297
mutex_lock(&table->lock);
12981298
for (i = 0; i < gid_tbl_len; ++i) {
1299-
if (!device->query_gid)
1299+
if (!device->ops.query_gid)
13001300
continue;
1301-
ret = device->query_gid(device, port, i, &gid_attr.gid);
1301+
ret = device->ops.query_gid(device, port, i, &gid_attr.gid);
13021302
if (ret) {
13031303
dev_warn(&device->dev,
13041304
"query_gid failed (%d) for index %d\n", ret,

drivers/infiniband/core/core_priv.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,10 @@ static inline int ib_security_modify_qp(struct ib_qp *qp,
215215
int qp_attr_mask,
216216
struct ib_udata *udata)
217217
{
218-
return qp->device->modify_qp(qp->real_qp,
219-
qp_attr,
220-
qp_attr_mask,
221-
udata);
218+
return qp->device->ops.modify_qp(qp->real_qp,
219+
qp_attr,
220+
qp_attr_mask,
221+
udata);
222222
}
223223

224224
static inline int ib_create_qp_security(struct ib_qp *qp,
@@ -280,10 +280,10 @@ static inline struct ib_qp *_ib_create_qp(struct ib_device *dev,
280280
{
281281
struct ib_qp *qp;
282282

283-
if (!dev->create_qp)
283+
if (!dev->ops.create_qp)
284284
return ERR_PTR(-EOPNOTSUPP);
285285

286-
qp = dev->create_qp(pd, attr, udata);
286+
qp = dev->ops.create_qp(pd, attr, udata);
287287
if (IS_ERR(qp))
288288
return qp;
289289

drivers/infiniband/core/cq.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ struct ib_cq *__ib_alloc_cq(struct ib_device *dev, void *private,
145145
struct ib_cq *cq;
146146
int ret = -ENOMEM;
147147

148-
cq = dev->create_cq(dev, &cq_attr, NULL, NULL);
148+
cq = dev->ops.create_cq(dev, &cq_attr, NULL, NULL);
149149
if (IS_ERR(cq))
150150
return cq;
151151

@@ -193,7 +193,7 @@ struct ib_cq *__ib_alloc_cq(struct ib_device *dev, void *private,
193193
kfree(cq->wc);
194194
rdma_restrack_del(&cq->res);
195195
out_destroy_cq:
196-
cq->device->destroy_cq(cq);
196+
cq->device->ops.destroy_cq(cq);
197197
return ERR_PTR(ret);
198198
}
199199
EXPORT_SYMBOL(__ib_alloc_cq);
@@ -225,7 +225,7 @@ void ib_free_cq(struct ib_cq *cq)
225225

226226
kfree(cq->wc);
227227
rdma_restrack_del(&cq->res);
228-
ret = cq->device->destroy_cq(cq);
228+
ret = cq->device->ops.destroy_cq(cq);
229229
WARN_ON_ONCE(ret);
230230
}
231231
EXPORT_SYMBOL(ib_free_cq);

drivers/infiniband/core/device.c

Lines changed: 107 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ static struct notifier_block ibdev_lsm_nb = {
9696

9797
static int ib_device_check_mandatory(struct ib_device *device)
9898
{
99-
#define IB_MANDATORY_FUNC(x) { offsetof(struct ib_device, x), #x }
99+
#define IB_MANDATORY_FUNC(x) { offsetof(struct ib_device_ops, x), #x }
100100
static const struct {
101101
size_t offset;
102102
char *name;
@@ -122,7 +122,8 @@ static int ib_device_check_mandatory(struct ib_device *device)
122122
int i;
123123

124124
for (i = 0; i < ARRAY_SIZE(mandatory_table); ++i) {
125-
if (!*(void **) ((void *) device + mandatory_table[i].offset)) {
125+
if (!*(void **) ((void *) &device->ops +
126+
mandatory_table[i].offset)) {
126127
dev_warn(&device->dev,
127128
"Device is missing mandatory function %s\n",
128129
mandatory_table[i].name);
@@ -373,8 +374,8 @@ static int read_port_immutable(struct ib_device *device)
373374
return -ENOMEM;
374375

375376
for (port = start_port; port <= end_port; ++port) {
376-
ret = device->get_port_immutable(device, port,
377-
&device->port_immutable[port]);
377+
ret = device->ops.get_port_immutable(
378+
device, port, &device->port_immutable[port]);
378379
if (ret)
379380
return ret;
380381

@@ -386,8 +387,8 @@ static int read_port_immutable(struct ib_device *device)
386387

387388
void ib_get_device_fw_str(struct ib_device *dev, char *str)
388389
{
389-
if (dev->get_dev_fw_str)
390-
dev->get_dev_fw_str(dev, str);
390+
if (dev->ops.get_dev_fw_str)
391+
dev->ops.get_dev_fw_str(dev, str);
391392
else
392393
str[0] = '\0';
393394
}
@@ -536,7 +537,7 @@ static int setup_device(struct ib_device *device)
536537
}
537538

538539
memset(&device->attrs, 0, sizeof(device->attrs));
539-
ret = device->query_device(device, &device->attrs, &uhw);
540+
ret = device->ops.query_device(device, &device->attrs, &uhw);
540541
if (ret) {
541542
dev_warn(&device->dev,
542543
"Couldn't query the device attributes\n");
@@ -923,14 +924,14 @@ int ib_query_port(struct ib_device *device,
923924
return -EINVAL;
924925

925926
memset(port_attr, 0, sizeof(*port_attr));
926-
err = device->query_port(device, port_num, port_attr);
927+
err = device->ops.query_port(device, port_num, port_attr);
927928
if (err || port_attr->subnet_prefix)
928929
return err;
929930

930931
if (rdma_port_get_link_layer(device, port_num) != IB_LINK_LAYER_INFINIBAND)
931932
return 0;
932933

933-
err = device->query_gid(device, port_num, 0, &gid);
934+
err = device->ops.query_gid(device, port_num, 0, &gid);
934935
if (err)
935936
return err;
936937

@@ -964,8 +965,8 @@ void ib_enum_roce_netdev(struct ib_device *ib_dev,
964965
if (rdma_protocol_roce(ib_dev, port)) {
965966
struct net_device *idev = NULL;
966967

967-
if (ib_dev->get_netdev)
968-
idev = ib_dev->get_netdev(ib_dev, port);
968+
if (ib_dev->ops.get_netdev)
969+
idev = ib_dev->ops.get_netdev(ib_dev, port);
969970

970971
if (idev &&
971972
idev->reg_state >= NETREG_UNREGISTERED) {
@@ -1045,7 +1046,7 @@ int ib_query_pkey(struct ib_device *device,
10451046
if (!rdma_is_port_valid(device, port_num))
10461047
return -EINVAL;
10471048

1048-
return device->query_pkey(device, port_num, index, pkey);
1049+
return device->ops.query_pkey(device, port_num, index, pkey);
10491050
}
10501051
EXPORT_SYMBOL(ib_query_pkey);
10511052

@@ -1062,11 +1063,11 @@ int ib_modify_device(struct ib_device *device,
10621063
int device_modify_mask,
10631064
struct ib_device_modify *device_modify)
10641065
{
1065-
if (!device->modify_device)
1066+
if (!device->ops.modify_device)
10661067
return -ENOSYS;
10671068

1068-
return device->modify_device(device, device_modify_mask,
1069-
device_modify);
1069+
return device->ops.modify_device(device, device_modify_mask,
1070+
device_modify);
10701071
}
10711072
EXPORT_SYMBOL(ib_modify_device);
10721073

@@ -1090,9 +1091,10 @@ int ib_modify_port(struct ib_device *device,
10901091
if (!rdma_is_port_valid(device, port_num))
10911092
return -EINVAL;
10921093

1093-
if (device->modify_port)
1094-
rc = device->modify_port(device, port_num, port_modify_mask,
1095-
port_modify);
1094+
if (device->ops.modify_port)
1095+
rc = device->ops.modify_port(device, port_num,
1096+
port_modify_mask,
1097+
port_modify);
10961098
else
10971099
rc = rdma_protocol_roce(device, port_num) ? 0 : -ENOSYS;
10981100
return rc;
@@ -1221,99 +1223,100 @@ EXPORT_SYMBOL(ib_get_net_dev_by_params);
12211223

12221224
void ib_set_device_ops(struct ib_device *dev, const struct ib_device_ops *ops)
12231225
{
1226+
struct ib_device_ops *dev_ops = &dev->ops;
12241227
#define SET_DEVICE_OP(ptr, name) \
12251228
do { \
12261229
if (ops->name) \
12271230
if (!((ptr)->name)) \
12281231
(ptr)->name = ops->name; \
12291232
} while (0)
12301233

1231-
SET_DEVICE_OP(dev, add_gid);
1232-
SET_DEVICE_OP(dev, alloc_dm);
1233-
SET_DEVICE_OP(dev, alloc_fmr);
1234-
SET_DEVICE_OP(dev, alloc_hw_stats);
1235-
SET_DEVICE_OP(dev, alloc_mr);
1236-
SET_DEVICE_OP(dev, alloc_mw);
1237-
SET_DEVICE_OP(dev, alloc_pd);
1238-
SET_DEVICE_OP(dev, alloc_rdma_netdev);
1239-
SET_DEVICE_OP(dev, alloc_ucontext);
1240-
SET_DEVICE_OP(dev, alloc_xrcd);
1241-
SET_DEVICE_OP(dev, attach_mcast);
1242-
SET_DEVICE_OP(dev, check_mr_status);
1243-
SET_DEVICE_OP(dev, create_ah);
1244-
SET_DEVICE_OP(dev, create_counters);
1245-
SET_DEVICE_OP(dev, create_cq);
1246-
SET_DEVICE_OP(dev, create_flow);
1247-
SET_DEVICE_OP(dev, create_flow_action_esp);
1248-
SET_DEVICE_OP(dev, create_qp);
1249-
SET_DEVICE_OP(dev, create_rwq_ind_table);
1250-
SET_DEVICE_OP(dev, create_srq);
1251-
SET_DEVICE_OP(dev, create_wq);
1252-
SET_DEVICE_OP(dev, dealloc_dm);
1253-
SET_DEVICE_OP(dev, dealloc_fmr);
1254-
SET_DEVICE_OP(dev, dealloc_mw);
1255-
SET_DEVICE_OP(dev, dealloc_pd);
1256-
SET_DEVICE_OP(dev, dealloc_ucontext);
1257-
SET_DEVICE_OP(dev, dealloc_xrcd);
1258-
SET_DEVICE_OP(dev, del_gid);
1259-
SET_DEVICE_OP(dev, dereg_mr);
1260-
SET_DEVICE_OP(dev, destroy_ah);
1261-
SET_DEVICE_OP(dev, destroy_counters);
1262-
SET_DEVICE_OP(dev, destroy_cq);
1263-
SET_DEVICE_OP(dev, destroy_flow);
1264-
SET_DEVICE_OP(dev, destroy_flow_action);
1265-
SET_DEVICE_OP(dev, destroy_qp);
1266-
SET_DEVICE_OP(dev, destroy_rwq_ind_table);
1267-
SET_DEVICE_OP(dev, destroy_srq);
1268-
SET_DEVICE_OP(dev, destroy_wq);
1269-
SET_DEVICE_OP(dev, detach_mcast);
1270-
SET_DEVICE_OP(dev, disassociate_ucontext);
1271-
SET_DEVICE_OP(dev, drain_rq);
1272-
SET_DEVICE_OP(dev, drain_sq);
1273-
SET_DEVICE_OP(dev, get_dev_fw_str);
1274-
SET_DEVICE_OP(dev, get_dma_mr);
1275-
SET_DEVICE_OP(dev, get_hw_stats);
1276-
SET_DEVICE_OP(dev, get_link_layer);
1277-
SET_DEVICE_OP(dev, get_netdev);
1278-
SET_DEVICE_OP(dev, get_port_immutable);
1279-
SET_DEVICE_OP(dev, get_vector_affinity);
1280-
SET_DEVICE_OP(dev, get_vf_config);
1281-
SET_DEVICE_OP(dev, get_vf_stats);
1282-
SET_DEVICE_OP(dev, map_mr_sg);
1283-
SET_DEVICE_OP(dev, map_phys_fmr);
1284-
SET_DEVICE_OP(dev, mmap);
1285-
SET_DEVICE_OP(dev, modify_ah);
1286-
SET_DEVICE_OP(dev, modify_cq);
1287-
SET_DEVICE_OP(dev, modify_device);
1288-
SET_DEVICE_OP(dev, modify_flow_action_esp);
1289-
SET_DEVICE_OP(dev, modify_port);
1290-
SET_DEVICE_OP(dev, modify_qp);
1291-
SET_DEVICE_OP(dev, modify_srq);
1292-
SET_DEVICE_OP(dev, modify_wq);
1293-
SET_DEVICE_OP(dev, peek_cq);
1294-
SET_DEVICE_OP(dev, poll_cq);
1295-
SET_DEVICE_OP(dev, post_recv);
1296-
SET_DEVICE_OP(dev, post_send);
1297-
SET_DEVICE_OP(dev, post_srq_recv);
1298-
SET_DEVICE_OP(dev, process_mad);
1299-
SET_DEVICE_OP(dev, query_ah);
1300-
SET_DEVICE_OP(dev, query_device);
1301-
SET_DEVICE_OP(dev, query_gid);
1302-
SET_DEVICE_OP(dev, query_pkey);
1303-
SET_DEVICE_OP(dev, query_port);
1304-
SET_DEVICE_OP(dev, query_qp);
1305-
SET_DEVICE_OP(dev, query_srq);
1306-
SET_DEVICE_OP(dev, rdma_netdev_get_params);
1307-
SET_DEVICE_OP(dev, read_counters);
1308-
SET_DEVICE_OP(dev, reg_dm_mr);
1309-
SET_DEVICE_OP(dev, reg_user_mr);
1310-
SET_DEVICE_OP(dev, req_ncomp_notif);
1311-
SET_DEVICE_OP(dev, req_notify_cq);
1312-
SET_DEVICE_OP(dev, rereg_user_mr);
1313-
SET_DEVICE_OP(dev, resize_cq);
1314-
SET_DEVICE_OP(dev, set_vf_guid);
1315-
SET_DEVICE_OP(dev, set_vf_link_state);
1316-
SET_DEVICE_OP(dev, unmap_fmr);
1234+
SET_DEVICE_OP(dev_ops, add_gid);
1235+
SET_DEVICE_OP(dev_ops, alloc_dm);
1236+
SET_DEVICE_OP(dev_ops, alloc_fmr);
1237+
SET_DEVICE_OP(dev_ops, alloc_hw_stats);
1238+
SET_DEVICE_OP(dev_ops, alloc_mr);
1239+
SET_DEVICE_OP(dev_ops, alloc_mw);
1240+
SET_DEVICE_OP(dev_ops, alloc_pd);
1241+
SET_DEVICE_OP(dev_ops, alloc_rdma_netdev);
1242+
SET_DEVICE_OP(dev_ops, alloc_ucontext);
1243+
SET_DEVICE_OP(dev_ops, alloc_xrcd);
1244+
SET_DEVICE_OP(dev_ops, attach_mcast);
1245+
SET_DEVICE_OP(dev_ops, check_mr_status);
1246+
SET_DEVICE_OP(dev_ops, create_ah);
1247+
SET_DEVICE_OP(dev_ops, create_counters);
1248+
SET_DEVICE_OP(dev_ops, create_cq);
1249+
SET_DEVICE_OP(dev_ops, create_flow);
1250+
SET_DEVICE_OP(dev_ops, create_flow_action_esp);
1251+
SET_DEVICE_OP(dev_ops, create_qp);
1252+
SET_DEVICE_OP(dev_ops, create_rwq_ind_table);
1253+
SET_DEVICE_OP(dev_ops, create_srq);
1254+
SET_DEVICE_OP(dev_ops, create_wq);
1255+
SET_DEVICE_OP(dev_ops, dealloc_dm);
1256+
SET_DEVICE_OP(dev_ops, dealloc_fmr);
1257+
SET_DEVICE_OP(dev_ops, dealloc_mw);
1258+
SET_DEVICE_OP(dev_ops, dealloc_pd);
1259+
SET_DEVICE_OP(dev_ops, dealloc_ucontext);
1260+
SET_DEVICE_OP(dev_ops, dealloc_xrcd);
1261+
SET_DEVICE_OP(dev_ops, del_gid);
1262+
SET_DEVICE_OP(dev_ops, dereg_mr);
1263+
SET_DEVICE_OP(dev_ops, destroy_ah);
1264+
SET_DEVICE_OP(dev_ops, destroy_counters);
1265+
SET_DEVICE_OP(dev_ops, destroy_cq);
1266+
SET_DEVICE_OP(dev_ops, destroy_flow);
1267+
SET_DEVICE_OP(dev_ops, destroy_flow_action);
1268+
SET_DEVICE_OP(dev_ops, destroy_qp);
1269+
SET_DEVICE_OP(dev_ops, destroy_rwq_ind_table);
1270+
SET_DEVICE_OP(dev_ops, destroy_srq);
1271+
SET_DEVICE_OP(dev_ops, destroy_wq);
1272+
SET_DEVICE_OP(dev_ops, detach_mcast);
1273+
SET_DEVICE_OP(dev_ops, disassociate_ucontext);
1274+
SET_DEVICE_OP(dev_ops, drain_rq);
1275+
SET_DEVICE_OP(dev_ops, drain_sq);
1276+
SET_DEVICE_OP(dev_ops, get_dev_fw_str);
1277+
SET_DEVICE_OP(dev_ops, get_dma_mr);
1278+
SET_DEVICE_OP(dev_ops, get_hw_stats);
1279+
SET_DEVICE_OP(dev_ops, get_link_layer);
1280+
SET_DEVICE_OP(dev_ops, get_netdev);
1281+
SET_DEVICE_OP(dev_ops, get_port_immutable);
1282+
SET_DEVICE_OP(dev_ops, get_vector_affinity);
1283+
SET_DEVICE_OP(dev_ops, get_vf_config);
1284+
SET_DEVICE_OP(dev_ops, get_vf_stats);
1285+
SET_DEVICE_OP(dev_ops, map_mr_sg);
1286+
SET_DEVICE_OP(dev_ops, map_phys_fmr);
1287+
SET_DEVICE_OP(dev_ops, mmap);
1288+
SET_DEVICE_OP(dev_ops, modify_ah);
1289+
SET_DEVICE_OP(dev_ops, modify_cq);
1290+
SET_DEVICE_OP(dev_ops, modify_device);
1291+
SET_DEVICE_OP(dev_ops, modify_flow_action_esp);
1292+
SET_DEVICE_OP(dev_ops, modify_port);
1293+
SET_DEVICE_OP(dev_ops, modify_qp);
1294+
SET_DEVICE_OP(dev_ops, modify_srq);
1295+
SET_DEVICE_OP(dev_ops, modify_wq);
1296+
SET_DEVICE_OP(dev_ops, peek_cq);
1297+
SET_DEVICE_OP(dev_ops, poll_cq);
1298+
SET_DEVICE_OP(dev_ops, post_recv);
1299+
SET_DEVICE_OP(dev_ops, post_send);
1300+
SET_DEVICE_OP(dev_ops, post_srq_recv);
1301+
SET_DEVICE_OP(dev_ops, process_mad);
1302+
SET_DEVICE_OP(dev_ops, query_ah);
1303+
SET_DEVICE_OP(dev_ops, query_device);
1304+
SET_DEVICE_OP(dev_ops, query_gid);
1305+
SET_DEVICE_OP(dev_ops, query_pkey);
1306+
SET_DEVICE_OP(dev_ops, query_port);
1307+
SET_DEVICE_OP(dev_ops, query_qp);
1308+
SET_DEVICE_OP(dev_ops, query_srq);
1309+
SET_DEVICE_OP(dev_ops, rdma_netdev_get_params);
1310+
SET_DEVICE_OP(dev_ops, read_counters);
1311+
SET_DEVICE_OP(dev_ops, reg_dm_mr);
1312+
SET_DEVICE_OP(dev_ops, reg_user_mr);
1313+
SET_DEVICE_OP(dev_ops, req_ncomp_notif);
1314+
SET_DEVICE_OP(dev_ops, req_notify_cq);
1315+
SET_DEVICE_OP(dev_ops, rereg_user_mr);
1316+
SET_DEVICE_OP(dev_ops, resize_cq);
1317+
SET_DEVICE_OP(dev_ops, set_vf_guid);
1318+
SET_DEVICE_OP(dev_ops, set_vf_link_state);
1319+
SET_DEVICE_OP(dev_ops, unmap_fmr);
13171320
}
13181321
EXPORT_SYMBOL(ib_set_device_ops);
13191322

0 commit comments

Comments
 (0)