.. | .. |
---|
62 | 62 | MODULE_AUTHOR("Emulex Corporation"); |
---|
63 | 63 | MODULE_LICENSE("Dual BSD/GPL"); |
---|
64 | 64 | |
---|
65 | | -static DEFINE_IDR(ocrdma_dev_id); |
---|
66 | | - |
---|
67 | 65 | void ocrdma_get_guid(struct ocrdma_dev *dev, u8 *guid) |
---|
68 | 66 | { |
---|
69 | 67 | u8 mac_addr[6]; |
---|
.. | .. |
---|
114 | 112 | snprintf(str, IB_FW_VERSION_NAME_MAX, "%s", &dev->attr.fw_ver[0]); |
---|
115 | 113 | } |
---|
116 | 114 | |
---|
| 115 | +/* OCRDMA sysfs interface */ |
---|
| 116 | +static ssize_t hw_rev_show(struct device *device, |
---|
| 117 | + struct device_attribute *attr, char *buf) |
---|
| 118 | +{ |
---|
| 119 | + struct ocrdma_dev *dev = |
---|
| 120 | + rdma_device_to_drv_device(device, struct ocrdma_dev, ibdev); |
---|
| 121 | + |
---|
| 122 | + return scnprintf(buf, PAGE_SIZE, "0x%x\n", dev->nic_info.pdev->vendor); |
---|
| 123 | +} |
---|
| 124 | +static DEVICE_ATTR_RO(hw_rev); |
---|
| 125 | + |
---|
| 126 | +static ssize_t hca_type_show(struct device *device, |
---|
| 127 | + struct device_attribute *attr, char *buf) |
---|
| 128 | +{ |
---|
| 129 | + struct ocrdma_dev *dev = |
---|
| 130 | + rdma_device_to_drv_device(device, struct ocrdma_dev, ibdev); |
---|
| 131 | + |
---|
| 132 | + return scnprintf(buf, PAGE_SIZE, "%s\n", &dev->model_number[0]); |
---|
| 133 | +} |
---|
| 134 | +static DEVICE_ATTR_RO(hca_type); |
---|
| 135 | + |
---|
| 136 | +static struct attribute *ocrdma_attributes[] = { |
---|
| 137 | + &dev_attr_hw_rev.attr, |
---|
| 138 | + &dev_attr_hca_type.attr, |
---|
| 139 | + NULL |
---|
| 140 | +}; |
---|
| 141 | + |
---|
| 142 | +static const struct attribute_group ocrdma_attr_group = { |
---|
| 143 | + .attrs = ocrdma_attributes, |
---|
| 144 | +}; |
---|
| 145 | + |
---|
| 146 | +static const struct ib_device_ops ocrdma_dev_ops = { |
---|
| 147 | + .owner = THIS_MODULE, |
---|
| 148 | + .driver_id = RDMA_DRIVER_OCRDMA, |
---|
| 149 | + .uverbs_abi_ver = OCRDMA_ABI_VERSION, |
---|
| 150 | + |
---|
| 151 | + .alloc_mr = ocrdma_alloc_mr, |
---|
| 152 | + .alloc_pd = ocrdma_alloc_pd, |
---|
| 153 | + .alloc_ucontext = ocrdma_alloc_ucontext, |
---|
| 154 | + .create_ah = ocrdma_create_ah, |
---|
| 155 | + .create_cq = ocrdma_create_cq, |
---|
| 156 | + .create_qp = ocrdma_create_qp, |
---|
| 157 | + .dealloc_pd = ocrdma_dealloc_pd, |
---|
| 158 | + .dealloc_ucontext = ocrdma_dealloc_ucontext, |
---|
| 159 | + .dereg_mr = ocrdma_dereg_mr, |
---|
| 160 | + .destroy_ah = ocrdma_destroy_ah, |
---|
| 161 | + .destroy_cq = ocrdma_destroy_cq, |
---|
| 162 | + .destroy_qp = ocrdma_destroy_qp, |
---|
| 163 | + .get_dev_fw_str = get_dev_fw_str, |
---|
| 164 | + .get_dma_mr = ocrdma_get_dma_mr, |
---|
| 165 | + .get_link_layer = ocrdma_link_layer, |
---|
| 166 | + .get_port_immutable = ocrdma_port_immutable, |
---|
| 167 | + .map_mr_sg = ocrdma_map_mr_sg, |
---|
| 168 | + .mmap = ocrdma_mmap, |
---|
| 169 | + .modify_qp = ocrdma_modify_qp, |
---|
| 170 | + .poll_cq = ocrdma_poll_cq, |
---|
| 171 | + .post_recv = ocrdma_post_recv, |
---|
| 172 | + .post_send = ocrdma_post_send, |
---|
| 173 | + .process_mad = ocrdma_process_mad, |
---|
| 174 | + .query_ah = ocrdma_query_ah, |
---|
| 175 | + .query_device = ocrdma_query_device, |
---|
| 176 | + .query_pkey = ocrdma_query_pkey, |
---|
| 177 | + .query_port = ocrdma_query_port, |
---|
| 178 | + .query_qp = ocrdma_query_qp, |
---|
| 179 | + .reg_user_mr = ocrdma_reg_user_mr, |
---|
| 180 | + .req_notify_cq = ocrdma_arm_cq, |
---|
| 181 | + .resize_cq = ocrdma_resize_cq, |
---|
| 182 | + |
---|
| 183 | + INIT_RDMA_OBJ_SIZE(ib_ah, ocrdma_ah, ibah), |
---|
| 184 | + INIT_RDMA_OBJ_SIZE(ib_cq, ocrdma_cq, ibcq), |
---|
| 185 | + INIT_RDMA_OBJ_SIZE(ib_pd, ocrdma_pd, ibpd), |
---|
| 186 | + INIT_RDMA_OBJ_SIZE(ib_ucontext, ocrdma_ucontext, ibucontext), |
---|
| 187 | +}; |
---|
| 188 | + |
---|
| 189 | +static const struct ib_device_ops ocrdma_dev_srq_ops = { |
---|
| 190 | + .create_srq = ocrdma_create_srq, |
---|
| 191 | + .destroy_srq = ocrdma_destroy_srq, |
---|
| 192 | + .modify_srq = ocrdma_modify_srq, |
---|
| 193 | + .post_srq_recv = ocrdma_post_srq_recv, |
---|
| 194 | + .query_srq = ocrdma_query_srq, |
---|
| 195 | + |
---|
| 196 | + INIT_RDMA_OBJ_SIZE(ib_srq, ocrdma_srq, ibsrq), |
---|
| 197 | +}; |
---|
| 198 | + |
---|
117 | 199 | static int ocrdma_register_device(struct ocrdma_dev *dev) |
---|
118 | 200 | { |
---|
119 | | - strlcpy(dev->ibdev.name, "ocrdma%d", IB_DEVICE_NAME_MAX); |
---|
| 201 | + int ret; |
---|
| 202 | + |
---|
120 | 203 | ocrdma_get_guid(dev, (u8 *)&dev->ibdev.node_guid); |
---|
121 | 204 | BUILD_BUG_ON(sizeof(OCRDMA_NODE_DESC) > IB_DEVICE_NODE_DESC_MAX); |
---|
122 | 205 | memcpy(dev->ibdev.node_desc, OCRDMA_NODE_DESC, |
---|
123 | 206 | sizeof(OCRDMA_NODE_DESC)); |
---|
124 | | - dev->ibdev.owner = THIS_MODULE; |
---|
125 | | - dev->ibdev.uverbs_abi_ver = OCRDMA_ABI_VERSION; |
---|
126 | 207 | dev->ibdev.uverbs_cmd_mask = |
---|
127 | 208 | OCRDMA_UVERBS(GET_CONTEXT) | |
---|
128 | 209 | OCRDMA_UVERBS(QUERY_DEVICE) | |
---|
.. | .. |
---|
154 | 235 | dev->ibdev.phys_port_cnt = 1; |
---|
155 | 236 | dev->ibdev.num_comp_vectors = dev->eq_cnt; |
---|
156 | 237 | |
---|
157 | | - /* mandatory verbs. */ |
---|
158 | | - dev->ibdev.query_device = ocrdma_query_device; |
---|
159 | | - dev->ibdev.query_port = ocrdma_query_port; |
---|
160 | | - dev->ibdev.modify_port = ocrdma_modify_port; |
---|
161 | | - dev->ibdev.get_netdev = ocrdma_get_netdev; |
---|
162 | | - dev->ibdev.get_link_layer = ocrdma_link_layer; |
---|
163 | | - dev->ibdev.alloc_pd = ocrdma_alloc_pd; |
---|
164 | | - dev->ibdev.dealloc_pd = ocrdma_dealloc_pd; |
---|
165 | | - |
---|
166 | | - dev->ibdev.create_cq = ocrdma_create_cq; |
---|
167 | | - dev->ibdev.destroy_cq = ocrdma_destroy_cq; |
---|
168 | | - dev->ibdev.resize_cq = ocrdma_resize_cq; |
---|
169 | | - |
---|
170 | | - dev->ibdev.create_qp = ocrdma_create_qp; |
---|
171 | | - dev->ibdev.modify_qp = ocrdma_modify_qp; |
---|
172 | | - dev->ibdev.query_qp = ocrdma_query_qp; |
---|
173 | | - dev->ibdev.destroy_qp = ocrdma_destroy_qp; |
---|
174 | | - |
---|
175 | | - dev->ibdev.query_pkey = ocrdma_query_pkey; |
---|
176 | | - dev->ibdev.create_ah = ocrdma_create_ah; |
---|
177 | | - dev->ibdev.destroy_ah = ocrdma_destroy_ah; |
---|
178 | | - dev->ibdev.query_ah = ocrdma_query_ah; |
---|
179 | | - |
---|
180 | | - dev->ibdev.poll_cq = ocrdma_poll_cq; |
---|
181 | | - dev->ibdev.post_send = ocrdma_post_send; |
---|
182 | | - dev->ibdev.post_recv = ocrdma_post_recv; |
---|
183 | | - dev->ibdev.req_notify_cq = ocrdma_arm_cq; |
---|
184 | | - |
---|
185 | | - dev->ibdev.get_dma_mr = ocrdma_get_dma_mr; |
---|
186 | | - dev->ibdev.dereg_mr = ocrdma_dereg_mr; |
---|
187 | | - dev->ibdev.reg_user_mr = ocrdma_reg_user_mr; |
---|
188 | | - |
---|
189 | | - dev->ibdev.alloc_mr = ocrdma_alloc_mr; |
---|
190 | | - dev->ibdev.map_mr_sg = ocrdma_map_mr_sg; |
---|
191 | | - |
---|
192 | 238 | /* mandatory to support user space verbs consumer. */ |
---|
193 | | - dev->ibdev.alloc_ucontext = ocrdma_alloc_ucontext; |
---|
194 | | - dev->ibdev.dealloc_ucontext = ocrdma_dealloc_ucontext; |
---|
195 | | - dev->ibdev.mmap = ocrdma_mmap; |
---|
196 | 239 | dev->ibdev.dev.parent = &dev->nic_info.pdev->dev; |
---|
197 | 240 | |
---|
198 | | - dev->ibdev.process_mad = ocrdma_process_mad; |
---|
199 | | - dev->ibdev.get_port_immutable = ocrdma_port_immutable; |
---|
200 | | - dev->ibdev.get_dev_fw_str = get_dev_fw_str; |
---|
| 241 | + ib_set_device_ops(&dev->ibdev, &ocrdma_dev_ops); |
---|
201 | 242 | |
---|
202 | 243 | if (ocrdma_get_asic_type(dev) == OCRDMA_ASIC_GEN_SKH_R) { |
---|
203 | 244 | dev->ibdev.uverbs_cmd_mask |= |
---|
.. | .. |
---|
207 | 248 | OCRDMA_UVERBS(DESTROY_SRQ) | |
---|
208 | 249 | OCRDMA_UVERBS(POST_SRQ_RECV); |
---|
209 | 250 | |
---|
210 | | - dev->ibdev.create_srq = ocrdma_create_srq; |
---|
211 | | - dev->ibdev.modify_srq = ocrdma_modify_srq; |
---|
212 | | - dev->ibdev.query_srq = ocrdma_query_srq; |
---|
213 | | - dev->ibdev.destroy_srq = ocrdma_destroy_srq; |
---|
214 | | - dev->ibdev.post_srq_recv = ocrdma_post_srq_recv; |
---|
| 251 | + ib_set_device_ops(&dev->ibdev, &ocrdma_dev_srq_ops); |
---|
215 | 252 | } |
---|
216 | | - dev->ibdev.driver_id = RDMA_DRIVER_OCRDMA; |
---|
217 | | - return ib_register_device(&dev->ibdev, NULL); |
---|
| 253 | + rdma_set_device_sysfs_group(&dev->ibdev, &ocrdma_attr_group); |
---|
| 254 | + ret = ib_device_set_netdev(&dev->ibdev, dev->nic_info.netdev, 1); |
---|
| 255 | + if (ret) |
---|
| 256 | + return ret; |
---|
| 257 | + |
---|
| 258 | + dma_set_max_seg_size(&dev->nic_info.pdev->dev, UINT_MAX); |
---|
| 259 | + return ib_register_device(&dev->ibdev, "ocrdma%d", |
---|
| 260 | + &dev->nic_info.pdev->dev); |
---|
218 | 261 | } |
---|
219 | 262 | |
---|
220 | 263 | static int ocrdma_alloc_resources(struct ocrdma_dev *dev) |
---|
.. | .. |
---|
260 | 303 | kfree(dev->cq_tbl); |
---|
261 | 304 | } |
---|
262 | 305 | |
---|
263 | | -/* OCRDMA sysfs interface */ |
---|
264 | | -static ssize_t show_rev(struct device *device, struct device_attribute *attr, |
---|
265 | | - char *buf) |
---|
266 | | -{ |
---|
267 | | - struct ocrdma_dev *dev = dev_get_drvdata(device); |
---|
268 | | - |
---|
269 | | - return scnprintf(buf, PAGE_SIZE, "0x%x\n", dev->nic_info.pdev->vendor); |
---|
270 | | -} |
---|
271 | | - |
---|
272 | | -static ssize_t show_hca_type(struct device *device, |
---|
273 | | - struct device_attribute *attr, char *buf) |
---|
274 | | -{ |
---|
275 | | - struct ocrdma_dev *dev = dev_get_drvdata(device); |
---|
276 | | - |
---|
277 | | - return scnprintf(buf, PAGE_SIZE, "%s\n", &dev->model_number[0]); |
---|
278 | | -} |
---|
279 | | - |
---|
280 | | -static DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL); |
---|
281 | | -static DEVICE_ATTR(hca_type, S_IRUGO, show_hca_type, NULL); |
---|
282 | | - |
---|
283 | | -static struct device_attribute *ocrdma_attributes[] = { |
---|
284 | | - &dev_attr_hw_rev, |
---|
285 | | - &dev_attr_hca_type |
---|
286 | | -}; |
---|
287 | | - |
---|
288 | | -static void ocrdma_remove_sysfiles(struct ocrdma_dev *dev) |
---|
289 | | -{ |
---|
290 | | - int i; |
---|
291 | | - |
---|
292 | | - for (i = 0; i < ARRAY_SIZE(ocrdma_attributes); i++) |
---|
293 | | - device_remove_file(&dev->ibdev.dev, ocrdma_attributes[i]); |
---|
294 | | -} |
---|
295 | | - |
---|
296 | 306 | static struct ocrdma_dev *ocrdma_add(struct be_dev_info *dev_info) |
---|
297 | 307 | { |
---|
298 | | - int status = 0, i; |
---|
| 308 | + int status = 0; |
---|
299 | 309 | u8 lstate = 0; |
---|
300 | 310 | struct ocrdma_dev *dev; |
---|
301 | 311 | |
---|
302 | | - dev = (struct ocrdma_dev *)ib_alloc_device(sizeof(struct ocrdma_dev)); |
---|
| 312 | + dev = ib_alloc_device(ocrdma_dev, ibdev); |
---|
303 | 313 | if (!dev) { |
---|
304 | 314 | pr_err("Unable to allocate ib device\n"); |
---|
305 | 315 | return NULL; |
---|
306 | 316 | } |
---|
| 317 | + |
---|
307 | 318 | dev->mbx_cmd = kzalloc(sizeof(struct ocrdma_mqe_emb_cmd), GFP_KERNEL); |
---|
308 | 319 | if (!dev->mbx_cmd) |
---|
309 | | - goto idr_err; |
---|
| 320 | + goto init_err; |
---|
310 | 321 | |
---|
311 | 322 | memcpy(&dev->nic_info, dev_info, sizeof(*dev_info)); |
---|
312 | | - dev->id = idr_alloc(&ocrdma_dev_id, NULL, 0, 0, GFP_KERNEL); |
---|
313 | | - if (dev->id < 0) |
---|
314 | | - goto idr_err; |
---|
315 | | - |
---|
| 323 | + dev->id = PCI_FUNC(dev->nic_info.pdev->devfn); |
---|
316 | 324 | status = ocrdma_init_hw(dev); |
---|
317 | 325 | if (status) |
---|
318 | 326 | goto init_err; |
---|
.. | .. |
---|
331 | 339 | if (!status) |
---|
332 | 340 | ocrdma_update_link_state(dev, lstate); |
---|
333 | 341 | |
---|
334 | | - for (i = 0; i < ARRAY_SIZE(ocrdma_attributes); i++) |
---|
335 | | - if (device_create_file(&dev->ibdev.dev, ocrdma_attributes[i])) |
---|
336 | | - goto sysfs_err; |
---|
337 | 342 | /* Init stats */ |
---|
338 | 343 | ocrdma_add_port_stats(dev); |
---|
339 | 344 | /* Interrupt Moderation */ |
---|
.. | .. |
---|
348 | 353 | dev_name(&dev->nic_info.pdev->dev), dev->id); |
---|
349 | 354 | return dev; |
---|
350 | 355 | |
---|
351 | | -sysfs_err: |
---|
352 | | - ocrdma_remove_sysfiles(dev); |
---|
353 | 356 | alloc_err: |
---|
354 | 357 | ocrdma_free_resources(dev); |
---|
355 | 358 | ocrdma_cleanup_hw(dev); |
---|
356 | 359 | init_err: |
---|
357 | | - idr_remove(&ocrdma_dev_id, dev->id); |
---|
358 | | -idr_err: |
---|
359 | 360 | kfree(dev->mbx_cmd); |
---|
360 | 361 | ib_dealloc_device(&dev->ibdev); |
---|
361 | 362 | pr_err("%s() leaving. ret=%d\n", __func__, status); |
---|
.. | .. |
---|
365 | 366 | static void ocrdma_remove_free(struct ocrdma_dev *dev) |
---|
366 | 367 | { |
---|
367 | 368 | |
---|
368 | | - idr_remove(&ocrdma_dev_id, dev->id); |
---|
369 | 369 | kfree(dev->mbx_cmd); |
---|
370 | 370 | ib_dealloc_device(&dev->ibdev); |
---|
371 | 371 | } |
---|
.. | .. |
---|
376 | 376 | * of the registered clients. |
---|
377 | 377 | */ |
---|
378 | 378 | cancel_delayed_work_sync(&dev->eqd_work); |
---|
379 | | - ocrdma_remove_sysfiles(dev); |
---|
380 | 379 | ib_unregister_device(&dev->ibdev); |
---|
381 | 380 | |
---|
382 | 381 | ocrdma_rem_port_stats(dev); |
---|
.. | .. |
---|
471 | 470 | { |
---|
472 | 471 | be_roce_unregister_driver(&ocrdma_drv); |
---|
473 | 472 | ocrdma_rem_debugfs(); |
---|
474 | | - idr_destroy(&ocrdma_dev_id); |
---|
475 | 473 | } |
---|
476 | 474 | |
---|
477 | 475 | module_init(ocrdma_init_module); |
---|