Lines Matching refs:dev

56 void ocrdma_get_guid(struct ocrdma_dev *dev, u8 *guid)  in ocrdma_get_guid()  argument
60 memcpy(&mac_addr[0], &dev->nic_info.mac_addr[0], ETH_ALEN); in ocrdma_get_guid()
71 static bool ocrdma_add_sgid(struct ocrdma_dev *dev, union ib_gid *new_sgid) in ocrdma_add_sgid() argument
79 spin_lock_irqsave(&dev->sgid_lock, flags); in ocrdma_add_sgid()
81 if (!memcmp(&dev->sgid_tbl[i], &ocrdma_zero_sgid, in ocrdma_add_sgid()
84 memcpy(&dev->sgid_tbl[i], new_sgid, in ocrdma_add_sgid()
86 spin_unlock_irqrestore(&dev->sgid_lock, flags); in ocrdma_add_sgid()
88 } else if (!memcmp(&dev->sgid_tbl[i], new_sgid, in ocrdma_add_sgid()
91 spin_unlock_irqrestore(&dev->sgid_lock, flags); in ocrdma_add_sgid()
95 spin_unlock_irqrestore(&dev->sgid_lock, flags); in ocrdma_add_sgid()
99 static bool ocrdma_del_sgid(struct ocrdma_dev *dev, union ib_gid *sgid) in ocrdma_del_sgid() argument
106 spin_lock_irqsave(&dev->sgid_lock, flags); in ocrdma_del_sgid()
109 if (!memcmp(&dev->sgid_tbl[i], sgid, sizeof(union ib_gid))) { in ocrdma_del_sgid()
111 memset(&dev->sgid_tbl[i], 0, sizeof(union ib_gid)); in ocrdma_del_sgid()
116 spin_unlock_irqrestore(&dev->sgid_lock, flags); in ocrdma_del_sgid()
124 struct ocrdma_dev *dev; in ocrdma_addr_event() local
134 list_for_each_entry_rcu(dev, &ocrdma_dev_list, entry) { in ocrdma_addr_event()
135 if (dev->nic_info.netdev == netdev) { in ocrdma_addr_event()
145 mutex_lock(&dev->dev_lock); in ocrdma_addr_event()
148 updated = ocrdma_add_sgid(dev, gid); in ocrdma_addr_event()
151 updated = ocrdma_del_sgid(dev, gid); in ocrdma_addr_event()
158 gid_event.device = &dev->ibdev; in ocrdma_addr_event()
163 mutex_unlock(&dev->dev_lock); in ocrdma_addr_event()
172 struct net_device *netdev = ifa->ifa_dev->dev; in ocrdma_inetaddr_event()
189 struct net_device *netdev = ifa->idev->dev; in ocrdma_inet6addr_event()
205 static int ocrdma_register_device(struct ocrdma_dev *dev) in ocrdma_register_device() argument
207 strlcpy(dev->ibdev.name, "ocrdma%d", IB_DEVICE_NAME_MAX); in ocrdma_register_device()
208 ocrdma_get_guid(dev, (u8 *)&dev->ibdev.node_guid); in ocrdma_register_device()
209 memcpy(dev->ibdev.node_desc, OCRDMA_NODE_DESC, in ocrdma_register_device()
211 dev->ibdev.owner = THIS_MODULE; in ocrdma_register_device()
212 dev->ibdev.uverbs_abi_ver = OCRDMA_ABI_VERSION; in ocrdma_register_device()
213 dev->ibdev.uverbs_cmd_mask = in ocrdma_register_device()
234 dev->ibdev.uverbs_cmd_mask |= in ocrdma_register_device()
240 dev->ibdev.node_type = RDMA_NODE_IB_CA; in ocrdma_register_device()
241 dev->ibdev.phys_port_cnt = 1; in ocrdma_register_device()
242 dev->ibdev.num_comp_vectors = dev->eq_cnt; in ocrdma_register_device()
245 dev->ibdev.query_device = ocrdma_query_device; in ocrdma_register_device()
246 dev->ibdev.query_port = ocrdma_query_port; in ocrdma_register_device()
247 dev->ibdev.modify_port = ocrdma_modify_port; in ocrdma_register_device()
248 dev->ibdev.query_gid = ocrdma_query_gid; in ocrdma_register_device()
249 dev->ibdev.get_link_layer = ocrdma_link_layer; in ocrdma_register_device()
250 dev->ibdev.alloc_pd = ocrdma_alloc_pd; in ocrdma_register_device()
251 dev->ibdev.dealloc_pd = ocrdma_dealloc_pd; in ocrdma_register_device()
253 dev->ibdev.create_cq = ocrdma_create_cq; in ocrdma_register_device()
254 dev->ibdev.destroy_cq = ocrdma_destroy_cq; in ocrdma_register_device()
255 dev->ibdev.resize_cq = ocrdma_resize_cq; in ocrdma_register_device()
257 dev->ibdev.create_qp = ocrdma_create_qp; in ocrdma_register_device()
258 dev->ibdev.modify_qp = ocrdma_modify_qp; in ocrdma_register_device()
259 dev->ibdev.query_qp = ocrdma_query_qp; in ocrdma_register_device()
260 dev->ibdev.destroy_qp = ocrdma_destroy_qp; in ocrdma_register_device()
262 dev->ibdev.query_pkey = ocrdma_query_pkey; in ocrdma_register_device()
263 dev->ibdev.create_ah = ocrdma_create_ah; in ocrdma_register_device()
264 dev->ibdev.destroy_ah = ocrdma_destroy_ah; in ocrdma_register_device()
265 dev->ibdev.query_ah = ocrdma_query_ah; in ocrdma_register_device()
266 dev->ibdev.modify_ah = ocrdma_modify_ah; in ocrdma_register_device()
268 dev->ibdev.poll_cq = ocrdma_poll_cq; in ocrdma_register_device()
269 dev->ibdev.post_send = ocrdma_post_send; in ocrdma_register_device()
270 dev->ibdev.post_recv = ocrdma_post_recv; in ocrdma_register_device()
271 dev->ibdev.req_notify_cq = ocrdma_arm_cq; in ocrdma_register_device()
273 dev->ibdev.get_dma_mr = ocrdma_get_dma_mr; in ocrdma_register_device()
274 dev->ibdev.reg_phys_mr = ocrdma_reg_kernel_mr; in ocrdma_register_device()
275 dev->ibdev.dereg_mr = ocrdma_dereg_mr; in ocrdma_register_device()
276 dev->ibdev.reg_user_mr = ocrdma_reg_user_mr; in ocrdma_register_device()
278 dev->ibdev.alloc_fast_reg_mr = ocrdma_alloc_frmr; in ocrdma_register_device()
279 dev->ibdev.alloc_fast_reg_page_list = ocrdma_alloc_frmr_page_list; in ocrdma_register_device()
280 dev->ibdev.free_fast_reg_page_list = ocrdma_free_frmr_page_list; in ocrdma_register_device()
283 dev->ibdev.alloc_ucontext = ocrdma_alloc_ucontext; in ocrdma_register_device()
284 dev->ibdev.dealloc_ucontext = ocrdma_dealloc_ucontext; in ocrdma_register_device()
285 dev->ibdev.mmap = ocrdma_mmap; in ocrdma_register_device()
286 dev->ibdev.dma_device = &dev->nic_info.pdev->dev; in ocrdma_register_device()
288 dev->ibdev.process_mad = ocrdma_process_mad; in ocrdma_register_device()
290 if (ocrdma_get_asic_type(dev) == OCRDMA_ASIC_GEN_SKH_R) { in ocrdma_register_device()
291 dev->ibdev.uverbs_cmd_mask |= in ocrdma_register_device()
298 dev->ibdev.create_srq = ocrdma_create_srq; in ocrdma_register_device()
299 dev->ibdev.modify_srq = ocrdma_modify_srq; in ocrdma_register_device()
300 dev->ibdev.query_srq = ocrdma_query_srq; in ocrdma_register_device()
301 dev->ibdev.destroy_srq = ocrdma_destroy_srq; in ocrdma_register_device()
302 dev->ibdev.post_srq_recv = ocrdma_post_srq_recv; in ocrdma_register_device()
304 return ib_register_device(&dev->ibdev, NULL); in ocrdma_register_device()
307 static int ocrdma_alloc_resources(struct ocrdma_dev *dev) in ocrdma_alloc_resources() argument
309 mutex_init(&dev->dev_lock); in ocrdma_alloc_resources()
310 dev->sgid_tbl = kzalloc(sizeof(union ib_gid) * in ocrdma_alloc_resources()
312 if (!dev->sgid_tbl) in ocrdma_alloc_resources()
314 spin_lock_init(&dev->sgid_lock); in ocrdma_alloc_resources()
316 dev->cq_tbl = kzalloc(sizeof(struct ocrdma_cq *) * in ocrdma_alloc_resources()
318 if (!dev->cq_tbl) in ocrdma_alloc_resources()
321 if (dev->attr.max_qp) { in ocrdma_alloc_resources()
322 dev->qp_tbl = kzalloc(sizeof(struct ocrdma_qp *) * in ocrdma_alloc_resources()
324 if (!dev->qp_tbl) in ocrdma_alloc_resources()
328 dev->stag_arr = kzalloc(sizeof(u64) * OCRDMA_MAX_STAG, GFP_KERNEL); in ocrdma_alloc_resources()
329 if (dev->stag_arr == NULL) in ocrdma_alloc_resources()
332 ocrdma_alloc_pd_pool(dev); in ocrdma_alloc_resources()
334 spin_lock_init(&dev->av_tbl.lock); in ocrdma_alloc_resources()
335 spin_lock_init(&dev->flush_q_lock); in ocrdma_alloc_resources()
338 pr_err("%s(%d) error.\n", __func__, dev->id); in ocrdma_alloc_resources()
342 static void ocrdma_free_resources(struct ocrdma_dev *dev) in ocrdma_free_resources() argument
344 kfree(dev->stag_arr); in ocrdma_free_resources()
345 kfree(dev->qp_tbl); in ocrdma_free_resources()
346 kfree(dev->cq_tbl); in ocrdma_free_resources()
347 kfree(dev->sgid_tbl); in ocrdma_free_resources()
354 struct ocrdma_dev *dev = dev_get_drvdata(device); in show_rev() local
356 return scnprintf(buf, PAGE_SIZE, "0x%x\n", dev->nic_info.pdev->vendor); in show_rev()
362 struct ocrdma_dev *dev = dev_get_drvdata(device); in show_fw_ver() local
364 return scnprintf(buf, PAGE_SIZE, "%s\n", &dev->attr.fw_ver[0]); in show_fw_ver()
370 struct ocrdma_dev *dev = dev_get_drvdata(device); in show_hca_type() local
372 return scnprintf(buf, PAGE_SIZE, "%s\n", &dev->model_number[0]); in show_hca_type()
385 static void ocrdma_remove_sysfiles(struct ocrdma_dev *dev) in ocrdma_remove_sysfiles() argument
390 device_remove_file(&dev->ibdev.dev, ocrdma_attributes[i]); in ocrdma_remove_sysfiles()
393 static void ocrdma_add_default_sgid(struct ocrdma_dev *dev) in ocrdma_add_default_sgid() argument
396 union ib_gid *sgid = &dev->sgid_tbl[0]; in ocrdma_add_default_sgid()
399 ocrdma_get_guid(dev, &sgid->raw[8]); in ocrdma_add_default_sgid()
402 static void ocrdma_init_ipv4_gids(struct ocrdma_dev *dev, in ocrdma_init_ipv4_gids() argument
412 ocrdma_add_sgid(dev, &gid); in ocrdma_init_ipv4_gids()
419 static void ocrdma_init_ipv6_gids(struct ocrdma_dev *dev, in ocrdma_init_ipv6_gids() argument
431 ocrdma_add_sgid(dev, pgid); in ocrdma_init_ipv6_gids()
439 static void ocrdma_init_gid_table(struct ocrdma_dev *dev) in ocrdma_init_gid_table() argument
447 if (real_dev == dev->nic_info.netdev) { in ocrdma_init_gid_table()
448 ocrdma_add_default_sgid(dev); in ocrdma_init_gid_table()
449 ocrdma_init_ipv4_gids(dev, net_dev); in ocrdma_init_gid_table()
450 ocrdma_init_ipv6_gids(dev, net_dev); in ocrdma_init_gid_table()
458 struct ocrdma_dev *dev; in ocrdma_add() local
460 dev = (struct ocrdma_dev *)ib_alloc_device(sizeof(struct ocrdma_dev)); in ocrdma_add()
461 if (!dev) { in ocrdma_add()
465 dev->mbx_cmd = kzalloc(sizeof(struct ocrdma_mqe_emb_cmd), GFP_KERNEL); in ocrdma_add()
466 if (!dev->mbx_cmd) in ocrdma_add()
469 memcpy(&dev->nic_info, dev_info, sizeof(*dev_info)); in ocrdma_add()
470 dev->id = idr_alloc(&ocrdma_dev_id, NULL, 0, 0, GFP_KERNEL); in ocrdma_add()
471 if (dev->id < 0) in ocrdma_add()
474 status = ocrdma_init_hw(dev); in ocrdma_add()
478 status = ocrdma_alloc_resources(dev); in ocrdma_add()
482 ocrdma_init_service_level(dev); in ocrdma_add()
483 ocrdma_init_gid_table(dev); in ocrdma_add()
484 status = ocrdma_register_device(dev); in ocrdma_add()
489 if (device_create_file(&dev->ibdev.dev, ocrdma_attributes[i])) in ocrdma_add()
492 list_add_tail_rcu(&dev->entry, &ocrdma_dev_list); in ocrdma_add()
495 ocrdma_add_port_stats(dev); in ocrdma_add()
497 INIT_DELAYED_WORK(&dev->eqd_work, ocrdma_eqd_set_task); in ocrdma_add()
498 schedule_delayed_work(&dev->eqd_work, msecs_to_jiffies(1000)); in ocrdma_add()
501 dev_name(&dev->nic_info.pdev->dev), hca_name(dev), in ocrdma_add()
502 port_speed_string(dev), dev->model_number, in ocrdma_add()
503 dev->hba_port_num); in ocrdma_add()
505 dev_name(&dev->nic_info.pdev->dev), dev->id); in ocrdma_add()
506 return dev; in ocrdma_add()
509 ocrdma_remove_sysfiles(dev); in ocrdma_add()
511 ocrdma_free_resources(dev); in ocrdma_add()
512 ocrdma_cleanup_hw(dev); in ocrdma_add()
514 idr_remove(&ocrdma_dev_id, dev->id); in ocrdma_add()
516 kfree(dev->mbx_cmd); in ocrdma_add()
517 ib_dealloc_device(&dev->ibdev); in ocrdma_add()
524 struct ocrdma_dev *dev = container_of(rcu, struct ocrdma_dev, rcu); in ocrdma_remove_free() local
526 idr_remove(&ocrdma_dev_id, dev->id); in ocrdma_remove_free()
527 kfree(dev->mbx_cmd); in ocrdma_remove_free()
528 ib_dealloc_device(&dev->ibdev); in ocrdma_remove_free()
531 static void ocrdma_remove(struct ocrdma_dev *dev) in ocrdma_remove() argument
536 cancel_delayed_work_sync(&dev->eqd_work); in ocrdma_remove()
537 ocrdma_remove_sysfiles(dev); in ocrdma_remove()
538 ib_unregister_device(&dev->ibdev); in ocrdma_remove()
540 ocrdma_rem_port_stats(dev); in ocrdma_remove()
543 list_del_rcu(&dev->entry); in ocrdma_remove()
546 ocrdma_free_resources(dev); in ocrdma_remove()
547 ocrdma_cleanup_hw(dev); in ocrdma_remove()
549 call_rcu(&dev->rcu, ocrdma_remove_free); in ocrdma_remove()
552 static int ocrdma_open(struct ocrdma_dev *dev) in ocrdma_open() argument
558 port_event.device = &dev->ibdev; in ocrdma_open()
563 static int ocrdma_close(struct ocrdma_dev *dev) in ocrdma_close() argument
572 mutex_lock(&dev->dev_lock); in ocrdma_close()
573 if (dev->qp_tbl) { in ocrdma_close()
574 cur_qp = dev->qp_tbl; in ocrdma_close()
583 err_event.device = &dev->ibdev; in ocrdma_close()
588 mutex_unlock(&dev->dev_lock); in ocrdma_close()
592 err_event.device = &dev->ibdev; in ocrdma_close()
597 static void ocrdma_shutdown(struct ocrdma_dev *dev) in ocrdma_shutdown() argument
599 ocrdma_close(dev); in ocrdma_shutdown()
600 ocrdma_remove(dev); in ocrdma_shutdown()
607 static void ocrdma_event_handler(struct ocrdma_dev *dev, u32 event) in ocrdma_event_handler() argument
611 ocrdma_open(dev); in ocrdma_event_handler()
614 ocrdma_close(dev); in ocrdma_event_handler()
617 ocrdma_shutdown(dev); in ocrdma_event_handler()