hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/drivers/infiniband/hw/vmw_pvrdma/pvrdma_main.c
....@@ -65,32 +65,36 @@
6565 static int pvrdma_add_gid(const struct ib_gid_attr *attr, void **context);
6666 static int pvrdma_del_gid(const struct ib_gid_attr *attr, void **context);
6767
68
-static ssize_t show_hca(struct device *device, struct device_attribute *attr,
69
- char *buf)
68
+static ssize_t hca_type_show(struct device *device,
69
+ struct device_attribute *attr, char *buf)
7070 {
7171 return sprintf(buf, "VMW_PVRDMA-%s\n", DRV_VERSION);
7272 }
73
+static DEVICE_ATTR_RO(hca_type);
7374
74
-static ssize_t show_rev(struct device *device, struct device_attribute *attr,
75
- char *buf)
75
+static ssize_t hw_rev_show(struct device *device,
76
+ struct device_attribute *attr, char *buf)
7677 {
7778 return sprintf(buf, "%d\n", PVRDMA_REV_ID);
7879 }
80
+static DEVICE_ATTR_RO(hw_rev);
7981
80
-static ssize_t show_board(struct device *device, struct device_attribute *attr,
81
- char *buf)
82
+static ssize_t board_id_show(struct device *device,
83
+ struct device_attribute *attr, char *buf)
8284 {
8385 return sprintf(buf, "%d\n", PVRDMA_BOARD_ID);
8486 }
87
+static DEVICE_ATTR_RO(board_id);
8588
86
-static DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL);
87
-static DEVICE_ATTR(hca_type, S_IRUGO, show_hca, NULL);
88
-static DEVICE_ATTR(board_id, S_IRUGO, show_board, NULL);
89
+static struct attribute *pvrdma_class_attributes[] = {
90
+ &dev_attr_hw_rev.attr,
91
+ &dev_attr_hca_type.attr,
92
+ &dev_attr_board_id.attr,
93
+ NULL,
94
+};
8995
90
-static struct device_attribute *pvrdma_class_attributes[] = {
91
- &dev_attr_hw_rev,
92
- &dev_attr_hca_type,
93
- &dev_attr_board_id
96
+static const struct attribute_group pvrdma_attr_group = {
97
+ .attrs = pvrdma_class_attributes,
9498 };
9599
96100 static void pvrdma_get_fw_ver_str(struct ib_device *device, char *str)
....@@ -139,37 +143,68 @@
139143 return 0;
140144 }
141145
142
-static struct net_device *pvrdma_get_netdev(struct ib_device *ibdev,
143
- u8 port_num)
144
-{
145
- struct net_device *netdev;
146
- struct pvrdma_dev *dev = to_vdev(ibdev);
146
+static const struct ib_device_ops pvrdma_dev_ops = {
147
+ .owner = THIS_MODULE,
148
+ .driver_id = RDMA_DRIVER_VMW_PVRDMA,
149
+ .uverbs_abi_ver = PVRDMA_UVERBS_ABI_VERSION,
147150
148
- if (port_num != 1)
149
- return NULL;
151
+ .add_gid = pvrdma_add_gid,
152
+ .alloc_mr = pvrdma_alloc_mr,
153
+ .alloc_pd = pvrdma_alloc_pd,
154
+ .alloc_ucontext = pvrdma_alloc_ucontext,
155
+ .create_ah = pvrdma_create_ah,
156
+ .create_cq = pvrdma_create_cq,
157
+ .create_qp = pvrdma_create_qp,
158
+ .dealloc_pd = pvrdma_dealloc_pd,
159
+ .dealloc_ucontext = pvrdma_dealloc_ucontext,
160
+ .del_gid = pvrdma_del_gid,
161
+ .dereg_mr = pvrdma_dereg_mr,
162
+ .destroy_ah = pvrdma_destroy_ah,
163
+ .destroy_cq = pvrdma_destroy_cq,
164
+ .destroy_qp = pvrdma_destroy_qp,
165
+ .get_dev_fw_str = pvrdma_get_fw_ver_str,
166
+ .get_dma_mr = pvrdma_get_dma_mr,
167
+ .get_link_layer = pvrdma_port_link_layer,
168
+ .get_port_immutable = pvrdma_port_immutable,
169
+ .map_mr_sg = pvrdma_map_mr_sg,
170
+ .mmap = pvrdma_mmap,
171
+ .modify_port = pvrdma_modify_port,
172
+ .modify_qp = pvrdma_modify_qp,
173
+ .poll_cq = pvrdma_poll_cq,
174
+ .post_recv = pvrdma_post_recv,
175
+ .post_send = pvrdma_post_send,
176
+ .query_device = pvrdma_query_device,
177
+ .query_gid = pvrdma_query_gid,
178
+ .query_pkey = pvrdma_query_pkey,
179
+ .query_port = pvrdma_query_port,
180
+ .query_qp = pvrdma_query_qp,
181
+ .reg_user_mr = pvrdma_reg_user_mr,
182
+ .req_notify_cq = pvrdma_req_notify_cq,
150183
151
- rcu_read_lock();
152
- netdev = dev->netdev;
153
- if (netdev)
154
- dev_hold(netdev);
155
- rcu_read_unlock();
184
+ INIT_RDMA_OBJ_SIZE(ib_ah, pvrdma_ah, ibah),
185
+ INIT_RDMA_OBJ_SIZE(ib_cq, pvrdma_cq, ibcq),
186
+ INIT_RDMA_OBJ_SIZE(ib_pd, pvrdma_pd, ibpd),
187
+ INIT_RDMA_OBJ_SIZE(ib_ucontext, pvrdma_ucontext, ibucontext),
188
+};
156189
157
- return netdev;
158
-}
190
+static const struct ib_device_ops pvrdma_dev_srq_ops = {
191
+ .create_srq = pvrdma_create_srq,
192
+ .destroy_srq = pvrdma_destroy_srq,
193
+ .modify_srq = pvrdma_modify_srq,
194
+ .query_srq = pvrdma_query_srq,
195
+
196
+ INIT_RDMA_OBJ_SIZE(ib_srq, pvrdma_srq, ibsrq),
197
+};
159198
160199 static int pvrdma_register_device(struct pvrdma_dev *dev)
161200 {
162201 int ret = -1;
163
- int i = 0;
164202
165
- strlcpy(dev->ib_dev.name, "vmw_pvrdma%d", IB_DEVICE_NAME_MAX);
166203 dev->ib_dev.node_guid = dev->dsr->caps.node_guid;
167204 dev->sys_image_guid = dev->dsr->caps.sys_image_guid;
168205 dev->flags = 0;
169
- dev->ib_dev.owner = THIS_MODULE;
170206 dev->ib_dev.num_comp_vectors = 1;
171207 dev->ib_dev.dev.parent = &dev->pdev->dev;
172
- dev->ib_dev.uverbs_abi_ver = PVRDMA_UVERBS_ABI_VERSION;
173208 dev->ib_dev.uverbs_cmd_mask =
174209 (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) |
175210 (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) |
....@@ -195,39 +230,7 @@
195230 dev->ib_dev.node_type = RDMA_NODE_IB_CA;
196231 dev->ib_dev.phys_port_cnt = dev->dsr->caps.phys_port_cnt;
197232
198
- dev->ib_dev.query_device = pvrdma_query_device;
199
- dev->ib_dev.query_port = pvrdma_query_port;
200
- dev->ib_dev.query_gid = pvrdma_query_gid;
201
- dev->ib_dev.query_pkey = pvrdma_query_pkey;
202
- dev->ib_dev.modify_port = pvrdma_modify_port;
203
- dev->ib_dev.alloc_ucontext = pvrdma_alloc_ucontext;
204
- dev->ib_dev.dealloc_ucontext = pvrdma_dealloc_ucontext;
205
- dev->ib_dev.mmap = pvrdma_mmap;
206
- dev->ib_dev.alloc_pd = pvrdma_alloc_pd;
207
- dev->ib_dev.dealloc_pd = pvrdma_dealloc_pd;
208
- dev->ib_dev.create_ah = pvrdma_create_ah;
209
- dev->ib_dev.destroy_ah = pvrdma_destroy_ah;
210
- dev->ib_dev.create_qp = pvrdma_create_qp;
211
- dev->ib_dev.modify_qp = pvrdma_modify_qp;
212
- dev->ib_dev.query_qp = pvrdma_query_qp;
213
- dev->ib_dev.destroy_qp = pvrdma_destroy_qp;
214
- dev->ib_dev.post_send = pvrdma_post_send;
215
- dev->ib_dev.post_recv = pvrdma_post_recv;
216
- dev->ib_dev.create_cq = pvrdma_create_cq;
217
- dev->ib_dev.destroy_cq = pvrdma_destroy_cq;
218
- dev->ib_dev.poll_cq = pvrdma_poll_cq;
219
- dev->ib_dev.req_notify_cq = pvrdma_req_notify_cq;
220
- dev->ib_dev.get_dma_mr = pvrdma_get_dma_mr;
221
- dev->ib_dev.reg_user_mr = pvrdma_reg_user_mr;
222
- dev->ib_dev.dereg_mr = pvrdma_dereg_mr;
223
- dev->ib_dev.alloc_mr = pvrdma_alloc_mr;
224
- dev->ib_dev.map_mr_sg = pvrdma_map_mr_sg;
225
- dev->ib_dev.add_gid = pvrdma_add_gid;
226
- dev->ib_dev.del_gid = pvrdma_del_gid;
227
- dev->ib_dev.get_netdev = pvrdma_get_netdev;
228
- dev->ib_dev.get_port_immutable = pvrdma_port_immutable;
229
- dev->ib_dev.get_link_layer = pvrdma_port_link_layer;
230
- dev->ib_dev.get_dev_fw_str = pvrdma_get_fw_ver_str;
233
+ ib_set_device_ops(&dev->ib_dev, &pvrdma_dev_ops);
231234
232235 mutex_init(&dev->port_mutex);
233236 spin_lock_init(&dev->desc_lock);
....@@ -253,10 +256,7 @@
253256 (1ull << IB_USER_VERBS_CMD_DESTROY_SRQ) |
254257 (1ull << IB_USER_VERBS_CMD_POST_SRQ_RECV);
255258
256
- dev->ib_dev.create_srq = pvrdma_create_srq;
257
- dev->ib_dev.modify_srq = pvrdma_modify_srq;
258
- dev->ib_dev.query_srq = pvrdma_query_srq;
259
- dev->ib_dev.destroy_srq = pvrdma_destroy_srq;
259
+ ib_set_device_ops(&dev->ib_dev, &pvrdma_dev_srq_ops);
260260
261261 dev->srq_tbl = kcalloc(dev->dsr->caps.max_srq,
262262 sizeof(struct pvrdma_srq *),
....@@ -264,26 +264,20 @@
264264 if (!dev->srq_tbl)
265265 goto err_qp_free;
266266 }
267
- dev->ib_dev.driver_id = RDMA_DRIVER_VMW_PVRDMA;
268
- spin_lock_init(&dev->srq_tbl_lock);
269
-
270
- ret = ib_register_device(&dev->ib_dev, NULL);
267
+ ret = ib_device_set_netdev(&dev->ib_dev, dev->netdev, 1);
271268 if (ret)
272269 goto err_srq_free;
270
+ spin_lock_init(&dev->srq_tbl_lock);
271
+ rdma_set_device_sysfs_group(&dev->ib_dev, &pvrdma_attr_group);
273272
274
- for (i = 0; i < ARRAY_SIZE(pvrdma_class_attributes); ++i) {
275
- ret = device_create_file(&dev->ib_dev.dev,
276
- pvrdma_class_attributes[i]);
277
- if (ret)
278
- goto err_class;
279
- }
273
+ ret = ib_register_device(&dev->ib_dev, "vmw_pvrdma%d", &dev->pdev->dev);
274
+ if (ret)
275
+ goto err_srq_free;
280276
281277 dev->ib_active = true;
282278
283279 return 0;
284280
285
-err_class:
286
- ib_unregister_device(&dev->ib_dev);
287281 err_srq_free:
288282 kfree(dev->srq_tbl);
289283 err_qp_free:
....@@ -716,6 +710,7 @@
716710 pvrdma_dispatch_event(dev, 1, IB_EVENT_PORT_ACTIVE);
717711 break;
718712 case NETDEV_UNREGISTER:
713
+ ib_device_set_netdev(&dev->ib_dev, NULL, 1);
719714 dev_put(dev->netdev);
720715 dev->netdev = NULL;
721716 break;
....@@ -727,6 +722,7 @@
727722 if ((dev->netdev == NULL) &&
728723 (pci_get_drvdata(pdev_net) == ndev)) {
729724 /* this is our netdev */
725
+ ib_device_set_netdev(&dev->ib_dev, ndev, 1);
730726 dev->netdev = ndev;
731727 dev_hold(ndev);
732728 }
....@@ -735,7 +731,7 @@
735731
736732 default:
737733 dev_dbg(&dev->pdev->dev, "ignore netdevice event %ld on %s\n",
738
- event, dev->ib_dev.name);
734
+ event, dev_name(&dev->ib_dev.dev));
739735 break;
740736 }
741737 }
....@@ -793,7 +789,7 @@
793789 dev_dbg(&pdev->dev, "initializing driver %s\n", pci_name(pdev));
794790
795791 /* Allocate zero-out device */
796
- dev = (struct pvrdma_dev *)ib_alloc_device(sizeof(*dev));
792
+ dev = ib_alloc_device(pvrdma_dev, ib_dev);
797793 if (!dev) {
798794 dev_err(&pdev->dev, "failed to allocate IB device\n");
799795 return -ENOMEM;
....@@ -858,7 +854,7 @@
858854 goto err_free_resource;
859855 }
860856 }
861
-
857
+ dma_set_max_seg_size(&pdev->dev, UINT_MAX);
862858 pci_set_master(pdev);
863859
864860 /* Map register space */
....@@ -888,8 +884,8 @@
888884 dev_info(&pdev->dev, "device version %d, driver version %d\n",
889885 dev->dsr_version, PVRDMA_VERSION);
890886
891
- dev->dsr = dma_zalloc_coherent(&pdev->dev, sizeof(*dev->dsr),
892
- &dev->dsrbase, GFP_KERNEL);
887
+ dev->dsr = dma_alloc_coherent(&pdev->dev, sizeof(*dev->dsr),
888
+ &dev->dsrbase, GFP_KERNEL);
893889 if (!dev->dsr) {
894890 dev_err(&pdev->dev, "failed to allocate shared region\n");
895891 ret = -ENOMEM;
....@@ -903,7 +899,11 @@
903899 PVRDMA_GOS_BITS_64;
904900 dev->dsr->gos_info.gos_type = PVRDMA_GOS_TYPE_LINUX;
905901 dev->dsr->gos_info.gos_ver = 1;
906
- dev->dsr->uar_pfn = dev->driver_uar.pfn;
902
+
903
+ if (dev->dsr_version < PVRDMA_PPN64_VERSION)
904
+ dev->dsr->uar_pfn = dev->driver_uar.pfn;
905
+ else
906
+ dev->dsr->uar_pfn64 = dev->driver_uar.pfn;
907907
908908 /* Command slot. */
909909 dev->cmd_slot = dma_alloc_coherent(&pdev->dev, PAGE_SIZE,