Lines Matching +full:mcast +full:- +full:groups

18  *      - Redistributions of source code must retain the above
22 * - Redistributions in binary form must reproduce the above
70 IB_UVERBS_NUM_DYNAMIC_MINOR = IB_UVERBS_MAX_DEVICES - IB_UVERBS_NUM_FIXED_MINOR,
95 * Must be called with the ufile->device->disassociate_srcu held, and the lock
105 struct ib_ucontext *ucontext = smp_load_acquire(&ufile->ucontext); in ib_uverbs_get_ucontext_file()
107 if (!srcu_dereference(ufile->device->ib_dev, in ib_uverbs_get_ucontext_file()
108 &ufile->device->disassociate_srcu)) in ib_uverbs_get_ucontext_file()
109 return ERR_PTR(-EIO); in ib_uverbs_get_ucontext_file()
112 return ERR_PTR(-EINVAL); in ib_uverbs_get_ucontext_file()
120 struct ib_pd *pd = mw->pd; in uverbs_dealloc_mw()
123 ret = mw->device->ops.dealloc_mw(mw); in uverbs_dealloc_mw()
127 atomic_dec(&pd->usecnt); in uverbs_dealloc_mw()
137 uverbs_destroy_api(dev->uapi); in ib_uverbs_release_dev()
138 cleanup_srcu_struct(&dev->disassociate_srcu); in ib_uverbs_release_dev()
139 mutex_destroy(&dev->lists_mutex); in ib_uverbs_release_dev()
140 mutex_destroy(&dev->xrcd_tree_mutex); in ib_uverbs_release_dev()
150 spin_lock_irq(&ev_file->ev_queue.lock); in ib_uverbs_release_ucq()
151 list_for_each_entry_safe(evt, tmp, &uobj->comp_list, obj_list) { in ib_uverbs_release_ucq()
152 list_del(&evt->list); in ib_uverbs_release_ucq()
155 spin_unlock_irq(&ev_file->ev_queue.lock); in ib_uverbs_release_ucq()
157 uverbs_uobject_put(&ev_file->uobj); in ib_uverbs_release_ucq()
160 ib_uverbs_release_uevent(&uobj->uevent); in ib_uverbs_release_ucq()
165 struct ib_uverbs_async_event_file *async_file = uobj->event_file; in ib_uverbs_release_uevent()
171 spin_lock_irq(&async_file->ev_queue.lock); in ib_uverbs_release_uevent()
172 list_for_each_entry_safe(evt, tmp, &uobj->event_list, obj_list) { in ib_uverbs_release_uevent()
173 list_del(&evt->list); in ib_uverbs_release_uevent()
176 spin_unlock_irq(&async_file->ev_queue.lock); in ib_uverbs_release_uevent()
177 uverbs_uobject_put(&async_file->uobj); in ib_uverbs_release_uevent()
183 struct ib_uverbs_mcast_entry *mcast, *tmp; in ib_uverbs_detach_umcast() local
185 list_for_each_entry_safe(mcast, tmp, &uobj->mcast_list, list) { in ib_uverbs_detach_umcast()
186 ib_detach_mcast(qp, &mcast->gid, mcast->lid); in ib_uverbs_detach_umcast()
187 list_del(&mcast->list); in ib_uverbs_detach_umcast()
188 kfree(mcast); in ib_uverbs_detach_umcast()
194 complete(&dev->comp); in ib_uverbs_comp_dev()
206 srcu_key = srcu_read_lock(&file->device->disassociate_srcu); in ib_uverbs_release_file()
207 ib_dev = srcu_dereference(file->device->ib_dev, in ib_uverbs_release_file()
208 &file->device->disassociate_srcu); in ib_uverbs_release_file()
209 if (ib_dev && !ib_dev->ops.disassociate_ucontext) in ib_uverbs_release_file()
210 module_put(ib_dev->ops.owner); in ib_uverbs_release_file()
211 srcu_read_unlock(&file->device->disassociate_srcu, srcu_key); in ib_uverbs_release_file()
213 if (refcount_dec_and_test(&file->device->refcount)) in ib_uverbs_release_file()
214 ib_uverbs_comp_dev(file->device); in ib_uverbs_release_file()
216 if (file->default_async_file) in ib_uverbs_release_file()
217 uverbs_uobject_put(&file->default_async_file->uobj); in ib_uverbs_release_file()
218 put_device(&file->device->dev); in ib_uverbs_release_file()
220 if (file->disassociate_page) in ib_uverbs_release_file()
221 __free_pages(file->disassociate_page, 0); in ib_uverbs_release_file()
222 mutex_destroy(&file->disassociation_lock); in ib_uverbs_release_file()
223 mutex_destroy(&file->umap_lock); in ib_uverbs_release_file()
224 mutex_destroy(&file->ucontext_lock); in ib_uverbs_release_file()
236 spin_lock_irq(&ev_queue->lock); in ib_uverbs_event_read()
238 while (list_empty(&ev_queue->event_list)) { in ib_uverbs_event_read()
239 if (ev_queue->is_closed) { in ib_uverbs_event_read()
240 spin_unlock_irq(&ev_queue->lock); in ib_uverbs_event_read()
241 return -EIO; in ib_uverbs_event_read()
244 spin_unlock_irq(&ev_queue->lock); in ib_uverbs_event_read()
245 if (filp->f_flags & O_NONBLOCK) in ib_uverbs_event_read()
246 return -EAGAIN; in ib_uverbs_event_read()
248 if (wait_event_interruptible(ev_queue->poll_wait, in ib_uverbs_event_read()
249 (!list_empty(&ev_queue->event_list) || in ib_uverbs_event_read()
250 ev_queue->is_closed))) in ib_uverbs_event_read()
251 return -ERESTARTSYS; in ib_uverbs_event_read()
253 spin_lock_irq(&ev_queue->lock); in ib_uverbs_event_read()
256 event = list_entry(ev_queue->event_list.next, struct ib_uverbs_event, list); in ib_uverbs_event_read()
259 ret = -EINVAL; in ib_uverbs_event_read()
262 list_del(ev_queue->event_list.next); in ib_uverbs_event_read()
263 if (event->counter) { in ib_uverbs_event_read()
264 ++(*event->counter); in ib_uverbs_event_read()
265 list_del(&event->obj_list); in ib_uverbs_event_read()
269 spin_unlock_irq(&ev_queue->lock); in ib_uverbs_event_read()
273 ret = -EFAULT; in ib_uverbs_event_read()
286 struct ib_uverbs_async_event_file *file = filp->private_data; in ib_uverbs_async_event_read()
288 return ib_uverbs_event_read(&file->ev_queue, filp, buf, count, pos, in ib_uverbs_async_event_read()
296 filp->private_data; in ib_uverbs_comp_event_read()
298 return ib_uverbs_event_read(&comp_ev_file->ev_queue, filp, buf, count, in ib_uverbs_comp_event_read()
309 poll_wait(filp, &ev_queue->poll_wait, wait); in ib_uverbs_event_poll()
311 spin_lock_irq(&ev_queue->lock); in ib_uverbs_event_poll()
312 if (!list_empty(&ev_queue->event_list)) in ib_uverbs_event_poll()
314 else if (ev_queue->is_closed) in ib_uverbs_event_poll()
316 spin_unlock_irq(&ev_queue->lock); in ib_uverbs_event_poll()
324 struct ib_uverbs_async_event_file *file = filp->private_data; in ib_uverbs_async_event_poll()
326 return ib_uverbs_event_poll(&file->ev_queue, filp, wait); in ib_uverbs_async_event_poll()
333 filp->private_data; in ib_uverbs_comp_event_poll()
335 return ib_uverbs_event_poll(&comp_ev_file->ev_queue, filp, wait); in ib_uverbs_comp_event_poll()
340 struct ib_uverbs_async_event_file *file = filp->private_data; in ib_uverbs_async_event_fasync()
342 return fasync_helper(fd, filp, on, &file->ev_queue.async_queue); in ib_uverbs_async_event_fasync()
348 filp->private_data; in ib_uverbs_comp_event_fasync()
350 return fasync_helper(fd, filp, on, &comp_ev_file->ev_queue.async_queue); in ib_uverbs_comp_event_fasync()
379 spin_lock_irqsave(&ev_queue->lock, flags); in ib_uverbs_comp_handler()
380 if (ev_queue->is_closed) { in ib_uverbs_comp_handler()
381 spin_unlock_irqrestore(&ev_queue->lock, flags); in ib_uverbs_comp_handler()
387 spin_unlock_irqrestore(&ev_queue->lock, flags); in ib_uverbs_comp_handler()
391 uobj = cq->uobject; in ib_uverbs_comp_handler()
393 entry->desc.comp.cq_handle = cq->uobject->uevent.uobject.user_handle; in ib_uverbs_comp_handler()
394 entry->counter = &uobj->comp_events_reported; in ib_uverbs_comp_handler()
396 list_add_tail(&entry->list, &ev_queue->event_list); in ib_uverbs_comp_handler()
397 list_add_tail(&entry->obj_list, &uobj->comp_list); in ib_uverbs_comp_handler()
398 spin_unlock_irqrestore(&ev_queue->lock, flags); in ib_uverbs_comp_handler()
400 wake_up_interruptible(&ev_queue->poll_wait); in ib_uverbs_comp_handler()
401 kill_fasync(&ev_queue->async_queue, SIGIO, POLL_IN); in ib_uverbs_comp_handler()
414 spin_lock_irqsave(&async_file->ev_queue.lock, flags); in ib_uverbs_async_handler()
415 if (async_file->ev_queue.is_closed) { in ib_uverbs_async_handler()
416 spin_unlock_irqrestore(&async_file->ev_queue.lock, flags); in ib_uverbs_async_handler()
422 spin_unlock_irqrestore(&async_file->ev_queue.lock, flags); in ib_uverbs_async_handler()
426 entry->desc.async.element = element; in ib_uverbs_async_handler()
427 entry->desc.async.event_type = event; in ib_uverbs_async_handler()
428 entry->desc.async.reserved = 0; in ib_uverbs_async_handler()
429 entry->counter = counter; in ib_uverbs_async_handler()
431 list_add_tail(&entry->list, &async_file->ev_queue.event_list); in ib_uverbs_async_handler()
433 list_add_tail(&entry->obj_list, obj_list); in ib_uverbs_async_handler()
434 spin_unlock_irqrestore(&async_file->ev_queue.lock, flags); in ib_uverbs_async_handler()
436 wake_up_interruptible(&async_file->ev_queue.poll_wait); in ib_uverbs_async_handler()
437 kill_fasync(&async_file->ev_queue.async_queue, SIGIO, POLL_IN); in ib_uverbs_async_handler()
443 ib_uverbs_async_handler(eobj->event_file, in uverbs_uobj_event()
444 eobj->uobject.user_handle, event->event, in uverbs_uobj_event()
445 &eobj->event_list, &eobj->events_reported); in uverbs_uobj_event()
450 uverbs_uobj_event(&event->element.cq->uobject->uevent, event); in ib_uverbs_cq_event_handler()
456 if (!event->element.qp->uobject) in ib_uverbs_qp_event_handler()
459 uverbs_uobj_event(&event->element.qp->uobject->uevent, event); in ib_uverbs_qp_event_handler()
464 uverbs_uobj_event(&event->element.wq->uobject->uevent, event); in ib_uverbs_wq_event_handler()
469 uverbs_uobj_event(&event->element.srq->uobject->uevent, event); in ib_uverbs_srq_event_handler()
478 event->element.port_num, event->event, NULL, NULL); in ib_uverbs_event_handler()
483 spin_lock_init(&ev_queue->lock); in ib_uverbs_init_event_queue()
484 INIT_LIST_HEAD(&ev_queue->event_list); in ib_uverbs_init_event_queue()
485 init_waitqueue_head(&ev_queue->poll_wait); in ib_uverbs_init_event_queue()
486 ev_queue->is_closed = 0; in ib_uverbs_init_event_queue()
487 ev_queue->async_queue = NULL; in ib_uverbs_init_event_queue()
493 struct ib_uverbs_file *uverbs_file = async_file->uobj.ufile; in ib_uverbs_init_async_event_file()
494 struct ib_device *ib_dev = async_file->uobj.context->device; in ib_uverbs_init_async_event_file()
496 ib_uverbs_init_event_queue(&async_file->ev_queue); in ib_uverbs_init_async_event_file()
499 mutex_lock(&uverbs_file->ucontext_lock); in ib_uverbs_init_async_event_file()
500 if (!uverbs_file->default_async_file) { in ib_uverbs_init_async_event_file()
502 uverbs_uobject_get(&async_file->uobj); in ib_uverbs_init_async_event_file()
503 smp_store_release(&uverbs_file->default_async_file, async_file); in ib_uverbs_init_async_event_file()
505 mutex_unlock(&uverbs_file->ucontext_lock); in ib_uverbs_init_async_event_file()
507 INIT_IB_EVENT_HANDLER(&async_file->event_handler, ib_dev, in ib_uverbs_init_async_event_file()
509 ib_register_event_handler(&async_file->event_handler); in ib_uverbs_init_async_event_file()
516 if (method_elm->is_ex) { in verify_hdr()
517 count -= sizeof(*hdr) + sizeof(*ex_hdr); in verify_hdr()
519 if ((hdr->in_words + ex_hdr->provider_in_words) * 8 != count) in verify_hdr()
520 return -EINVAL; in verify_hdr()
522 if (hdr->in_words * 8 < method_elm->req_size) in verify_hdr()
523 return -ENOSPC; in verify_hdr()
525 if (ex_hdr->cmd_hdr_reserved) in verify_hdr()
526 return -EINVAL; in verify_hdr()
528 if (ex_hdr->response) { in verify_hdr()
529 if (!hdr->out_words && !ex_hdr->provider_out_words) in verify_hdr()
530 return -EINVAL; in verify_hdr()
532 if (hdr->out_words * 8 < method_elm->resp_size) in verify_hdr()
533 return -ENOSPC; in verify_hdr()
535 if (!access_ok(u64_to_user_ptr(ex_hdr->response), in verify_hdr()
536 (hdr->out_words + ex_hdr->provider_out_words) * 8)) in verify_hdr()
537 return -EFAULT; in verify_hdr()
539 if (hdr->out_words || ex_hdr->provider_out_words) in verify_hdr()
540 return -EINVAL; in verify_hdr()
547 if (hdr->in_words * 4 != count) in verify_hdr()
548 return -EINVAL; in verify_hdr()
550 if (count < method_elm->req_size + sizeof(*hdr)) { in verify_hdr()
552 * rdma-core v18 and v19 have a bug where they send DESTROY_CQ in verify_hdr()
558 if (hdr->command == IB_USER_VERBS_CMD_DESTROY_CQ && in verify_hdr()
560 hdr->in_words = 6; in verify_hdr()
563 return -ENOSPC; in verify_hdr()
565 if (hdr->out_words * 4 < method_elm->resp_size) in verify_hdr()
566 return -ENOSPC; in verify_hdr()
574 struct ib_uverbs_file *file = filp->private_data; in ib_uverbs_write()
576 struct uverbs_api *uapi = file->device->uapi; in ib_uverbs_write()
585 task_tgid_vnr(current), current->comm); in ib_uverbs_write()
586 return -EACCES; in ib_uverbs_write()
590 return -EINVAL; in ib_uverbs_write()
593 return -EFAULT; in ib_uverbs_write()
599 if (method_elm->is_ex) { in ib_uverbs_write()
601 return -EINVAL; in ib_uverbs_write()
603 return -EFAULT; in ib_uverbs_write()
610 srcu_key = srcu_read_lock(&file->device->disassociate_srcu); in ib_uverbs_write()
618 if (!method_elm->is_ex) { in ib_uverbs_write()
619 size_t in_len = hdr.in_words * 4 - sizeof(hdr); in ib_uverbs_write()
623 if (method_elm->has_udata) { in ib_uverbs_write()
625 in_len - method_elm->req_size; in ib_uverbs_write()
626 in_len = method_elm->req_size; in ib_uverbs_write()
636 if (method_elm->has_resp) { in ib_uverbs_write()
646 if (method_elm->has_udata) { in ib_uverbs_write()
648 out_len - method_elm->resp_size; in ib_uverbs_write()
649 out_len = method_elm->resp_size; in ib_uverbs_write()
680 ret = method_elm->handler(&bundle); in ib_uverbs_write()
685 srcu_read_unlock(&file->device->disassociate_srcu, srcu_key); in ib_uverbs_write()
693 struct ib_uverbs_file *file = filp->private_data; in ib_uverbs_mmap()
698 srcu_key = srcu_read_lock(&file->device->disassociate_srcu); in ib_uverbs_mmap()
705 mutex_lock(&file->disassociation_lock); in ib_uverbs_mmap()
707 vma->vm_ops = &rdma_umap_ops; in ib_uverbs_mmap()
708 ret = ucontext->device->ops.mmap(ucontext, vma); in ib_uverbs_mmap()
710 mutex_unlock(&file->disassociation_lock); in ib_uverbs_mmap()
712 srcu_read_unlock(&file->device->disassociate_srcu, srcu_key); in ib_uverbs_mmap()
722 struct ib_uverbs_file *ufile = vma->vm_file->private_data; in rdma_umap_open()
723 struct rdma_umap_priv *opriv = vma->vm_private_data; in rdma_umap_open()
730 if (!down_read_trylock(&ufile->hw_destroy_rwsem)) in rdma_umap_open()
732 mutex_lock(&ufile->disassociation_lock); in rdma_umap_open()
737 if (!ufile->ucontext) in rdma_umap_open()
743 rdma_umap_priv_init(priv, vma, opriv->entry); in rdma_umap_open()
745 mutex_unlock(&ufile->disassociation_lock); in rdma_umap_open()
746 up_read(&ufile->hw_destroy_rwsem); in rdma_umap_open()
750 mutex_unlock(&ufile->disassociation_lock); in rdma_umap_open()
751 up_read(&ufile->hw_destroy_rwsem); in rdma_umap_open()
758 vma->vm_private_data = NULL; in rdma_umap_open()
759 zap_vma_ptes(vma, vma->vm_start, vma->vm_end - vma->vm_start); in rdma_umap_open()
764 struct ib_uverbs_file *ufile = vma->vm_file->private_data; in rdma_umap_close()
765 struct rdma_umap_priv *priv = vma->vm_private_data; in rdma_umap_close()
775 mutex_lock(&ufile->umap_lock); in rdma_umap_close()
776 if (priv->entry) in rdma_umap_close()
777 rdma_user_mmap_entry_put(priv->entry); in rdma_umap_close()
779 list_del(&priv->list); in rdma_umap_close()
780 mutex_unlock(&ufile->umap_lock); in rdma_umap_close()
790 struct ib_uverbs_file *ufile = vmf->vma->vm_file->private_data; in rdma_umap_fault()
791 struct rdma_umap_priv *priv = vmf->vma->vm_private_data; in rdma_umap_fault()
798 if (!(vmf->vma->vm_flags & (VM_WRITE | VM_MAYWRITE))) { in rdma_umap_fault()
799 vmf->page = ZERO_PAGE(vmf->address); in rdma_umap_fault()
800 get_page(vmf->page); in rdma_umap_fault()
804 mutex_lock(&ufile->umap_lock); in rdma_umap_fault()
805 if (!ufile->disassociate_page) in rdma_umap_fault()
806 ufile->disassociate_page = in rdma_umap_fault()
807 alloc_pages(vmf->gfp_mask | __GFP_ZERO, 0); in rdma_umap_fault()
809 if (ufile->disassociate_page) { in rdma_umap_fault()
814 vmf->page = ufile->disassociate_page; in rdma_umap_fault()
815 get_page(vmf->page); in rdma_umap_fault()
819 mutex_unlock(&ufile->umap_lock); in rdma_umap_fault()
834 mutex_lock(&ufile->disassociation_lock); in uverbs_user_mmap_disassociate()
840 mutex_lock(&ufile->umap_lock); in uverbs_user_mmap_disassociate()
841 while (!list_empty(&ufile->umaps)) { in uverbs_user_mmap_disassociate()
844 priv = list_first_entry(&ufile->umaps, in uverbs_user_mmap_disassociate()
846 mm = priv->vma->vm_mm; in uverbs_user_mmap_disassociate()
849 list_del_init(&priv->list); in uverbs_user_mmap_disassociate()
850 if (priv->entry) { in uverbs_user_mmap_disassociate()
851 rdma_user_mmap_entry_put(priv->entry); in uverbs_user_mmap_disassociate()
852 priv->entry = NULL; in uverbs_user_mmap_disassociate()
859 mutex_unlock(&ufile->umap_lock); in uverbs_user_mmap_disassociate()
861 mutex_unlock(&ufile->disassociation_lock); in uverbs_user_mmap_disassociate()
872 mutex_lock(&ufile->umap_lock); in uverbs_user_mmap_disassociate()
873 list_for_each_entry_safe (priv, next_priv, &ufile->umaps, in uverbs_user_mmap_disassociate()
875 struct vm_area_struct *vma = priv->vma; in uverbs_user_mmap_disassociate()
877 if (vma->vm_mm != mm) in uverbs_user_mmap_disassociate()
879 list_del_init(&priv->list); in uverbs_user_mmap_disassociate()
881 zap_vma_ptes(vma, vma->vm_start, in uverbs_user_mmap_disassociate()
882 vma->vm_end - vma->vm_start); in uverbs_user_mmap_disassociate()
884 if (priv->entry) { in uverbs_user_mmap_disassociate()
885 rdma_user_mmap_entry_put(priv->entry); in uverbs_user_mmap_disassociate()
886 priv->entry = NULL; in uverbs_user_mmap_disassociate()
889 mutex_unlock(&ufile->umap_lock); in uverbs_user_mmap_disassociate()
894 mutex_unlock(&ufile->disassociation_lock); in uverbs_user_mmap_disassociate()
898 * rdma_user_mmap_disassociate() - Revoke mmaps for a device
910 mutex_lock(&uverbs_dev->lists_mutex); in rdma_user_mmap_disassociate()
911 list_for_each_entry(ufile, &uverbs_dev->uverbs_file_list, list) { in rdma_user_mmap_disassociate()
912 if (ufile->ucontext) in rdma_user_mmap_disassociate()
915 mutex_unlock(&uverbs_dev->lists_mutex); in rdma_user_mmap_disassociate()
922 * - the ib_uverbs_device structures are properly reference counted and
925 * - there is no ioctl method to race against;
926 * - the open method will either immediately run -ENXIO, or all
938 dev = container_of(inode->i_cdev, struct ib_uverbs_device, cdev); in ib_uverbs_open()
939 if (!refcount_inc_not_zero(&dev->refcount)) in ib_uverbs_open()
940 return -ENXIO; in ib_uverbs_open()
942 get_device(&dev->dev); in ib_uverbs_open()
943 srcu_key = srcu_read_lock(&dev->disassociate_srcu); in ib_uverbs_open()
944 mutex_lock(&dev->lists_mutex); in ib_uverbs_open()
945 ib_dev = srcu_dereference(dev->ib_dev, in ib_uverbs_open()
946 &dev->disassociate_srcu); in ib_uverbs_open()
948 ret = -EIO; in ib_uverbs_open()
952 if (!rdma_dev_access_netns(ib_dev, current->nsproxy->net_ns)) { in ib_uverbs_open()
953 ret = -EPERM; in ib_uverbs_open()
960 module_dependent = !(ib_dev->ops.disassociate_ucontext); in ib_uverbs_open()
963 if (!try_module_get(ib_dev->ops.owner)) { in ib_uverbs_open()
964 ret = -ENODEV; in ib_uverbs_open()
971 ret = -ENOMEM; in ib_uverbs_open()
978 file->device = dev; in ib_uverbs_open()
979 kref_init(&file->ref); in ib_uverbs_open()
980 mutex_init(&file->ucontext_lock); in ib_uverbs_open()
982 spin_lock_init(&file->uobjects_lock); in ib_uverbs_open()
983 INIT_LIST_HEAD(&file->uobjects); in ib_uverbs_open()
984 init_rwsem(&file->hw_destroy_rwsem); in ib_uverbs_open()
985 mutex_init(&file->umap_lock); in ib_uverbs_open()
986 INIT_LIST_HEAD(&file->umaps); in ib_uverbs_open()
988 mutex_init(&file->disassociation_lock); in ib_uverbs_open()
990 filp->private_data = file; in ib_uverbs_open()
991 list_add_tail(&file->list, &dev->uverbs_file_list); in ib_uverbs_open()
992 mutex_unlock(&dev->lists_mutex); in ib_uverbs_open()
993 srcu_read_unlock(&dev->disassociate_srcu, srcu_key); in ib_uverbs_open()
1000 module_put(ib_dev->ops.owner); in ib_uverbs_open()
1003 mutex_unlock(&dev->lists_mutex); in ib_uverbs_open()
1004 srcu_read_unlock(&dev->disassociate_srcu, srcu_key); in ib_uverbs_open()
1005 if (refcount_dec_and_test(&dev->refcount)) in ib_uverbs_open()
1008 put_device(&dev->dev); in ib_uverbs_open()
1014 struct ib_uverbs_file *file = filp->private_data; in ib_uverbs_close()
1018 mutex_lock(&file->device->lists_mutex); in ib_uverbs_close()
1019 list_del_init(&file->list); in ib_uverbs_close()
1020 mutex_unlock(&file->device->lists_mutex); in ib_uverbs_close()
1022 kref_put(&file->ref, ib_uverbs_release_file); in ib_uverbs_close()
1052 if (res->port != -1) in ib_uverbs_get_nl_info()
1053 return -EINVAL; in ib_uverbs_get_nl_info()
1055 res->abi = ibdev->ops.uverbs_abi_ver; in ib_uverbs_get_nl_info()
1056 res->cdev = &uverbs_dev->dev; in ib_uverbs_get_nl_info()
1064 if (!ibdev->ops.uverbs_no_driver_id_binding) { in ib_uverbs_get_nl_info()
1065 ret = nla_put_u32(res->nl_msg, RDMA_NLDEV_ATTR_UVERBS_DRIVER_ID, in ib_uverbs_get_nl_info()
1066 ibdev->ops.driver_id); in ib_uverbs_get_nl_info()
1087 int ret = -ENODEV; in ibdev_show()
1091 srcu_key = srcu_read_lock(&dev->disassociate_srcu); in ibdev_show()
1092 ib_dev = srcu_dereference(dev->ib_dev, &dev->disassociate_srcu); in ibdev_show()
1094 ret = sysfs_emit(buf, "%s\n", dev_name(&ib_dev->dev)); in ibdev_show()
1095 srcu_read_unlock(&dev->disassociate_srcu, srcu_key); in ibdev_show()
1106 int ret = -ENODEV; in abi_version_show()
1110 srcu_key = srcu_read_lock(&dev->disassociate_srcu); in abi_version_show()
1111 ib_dev = srcu_dereference(dev->ib_dev, &dev->disassociate_srcu); in abi_version_show()
1113 ret = sysfs_emit(buf, "%u\n", ib_dev->ops.uverbs_abi_ver); in abi_version_show()
1114 srcu_read_unlock(&dev->disassociate_srcu, srcu_key); in abi_version_show()
1142 uverbs_dev->uapi = uapi; in ib_uverbs_create_uapi()
1153 if (!device->ops.alloc_ucontext || in ib_uverbs_add_one()
1154 device->type == RDMA_DEVICE_TYPE_SMI) in ib_uverbs_add_one()
1155 return -EOPNOTSUPP; in ib_uverbs_add_one()
1159 return -ENOMEM; in ib_uverbs_add_one()
1161 ret = init_srcu_struct(&uverbs_dev->disassociate_srcu); in ib_uverbs_add_one()
1164 return -ENOMEM; in ib_uverbs_add_one()
1167 device_initialize(&uverbs_dev->dev); in ib_uverbs_add_one()
1168 uverbs_dev->dev.class = &uverbs_class; in ib_uverbs_add_one()
1169 uverbs_dev->dev.parent = device->dev.parent; in ib_uverbs_add_one()
1170 uverbs_dev->dev.release = ib_uverbs_release_dev; in ib_uverbs_add_one()
1171 uverbs_dev->groups[0] = &dev_attr_group; in ib_uverbs_add_one()
1172 uverbs_dev->dev.groups = uverbs_dev->groups; in ib_uverbs_add_one()
1173 refcount_set(&uverbs_dev->refcount, 1); in ib_uverbs_add_one()
1174 init_completion(&uverbs_dev->comp); in ib_uverbs_add_one()
1175 uverbs_dev->xrcd_tree = RB_ROOT; in ib_uverbs_add_one()
1176 mutex_init(&uverbs_dev->xrcd_tree_mutex); in ib_uverbs_add_one()
1177 mutex_init(&uverbs_dev->lists_mutex); in ib_uverbs_add_one()
1178 INIT_LIST_HEAD(&uverbs_dev->uverbs_file_list); in ib_uverbs_add_one()
1179 rcu_assign_pointer(uverbs_dev->ib_dev, device); in ib_uverbs_add_one()
1180 uverbs_dev->num_comp_vectors = device->num_comp_vectors; in ib_uverbs_add_one()
1182 devnum = ida_alloc_max(&uverbs_ida, IB_UVERBS_MAX_DEVICES - 1, in ib_uverbs_add_one()
1185 ret = -ENOMEM; in ib_uverbs_add_one()
1188 uverbs_dev->devnum = devnum; in ib_uverbs_add_one()
1190 base = dynamic_uverbs_dev + devnum - IB_UVERBS_NUM_FIXED_MINOR; in ib_uverbs_add_one()
1198 uverbs_dev->dev.devt = base; in ib_uverbs_add_one()
1199 dev_set_name(&uverbs_dev->dev, "uverbs%d", uverbs_dev->devnum); in ib_uverbs_add_one()
1201 cdev_init(&uverbs_dev->cdev, in ib_uverbs_add_one()
1202 device->ops.mmap ? &uverbs_mmap_fops : &uverbs_fops); in ib_uverbs_add_one()
1203 uverbs_dev->cdev.owner = THIS_MODULE; in ib_uverbs_add_one()
1205 ret = cdev_device_add(&uverbs_dev->cdev, &uverbs_dev->dev); in ib_uverbs_add_one()
1215 if (refcount_dec_and_test(&uverbs_dev->refcount)) in ib_uverbs_add_one()
1217 wait_for_completion(&uverbs_dev->comp); in ib_uverbs_add_one()
1218 put_device(&uverbs_dev->dev); in ib_uverbs_add_one()
1230 mutex_lock(&uverbs_dev->lists_mutex); in ib_uverbs_free_hw_resources()
1231 while (!list_empty(&uverbs_dev->uverbs_file_list)) { in ib_uverbs_free_hw_resources()
1232 file = list_first_entry(&uverbs_dev->uverbs_file_list, in ib_uverbs_free_hw_resources()
1234 list_del_init(&file->list); in ib_uverbs_free_hw_resources()
1235 kref_get(&file->ref); in ib_uverbs_free_hw_resources()
1242 mutex_unlock(&uverbs_dev->lists_mutex); in ib_uverbs_free_hw_resources()
1245 kref_put(&file->ref, ib_uverbs_release_file); in ib_uverbs_free_hw_resources()
1247 mutex_lock(&uverbs_dev->lists_mutex); in ib_uverbs_free_hw_resources()
1249 mutex_unlock(&uverbs_dev->lists_mutex); in ib_uverbs_free_hw_resources()
1251 uverbs_disassociate_api(uverbs_dev->uapi); in ib_uverbs_free_hw_resources()
1259 cdev_device_del(&uverbs_dev->cdev, &uverbs_dev->dev); in ib_uverbs_remove_one()
1260 ida_free(&uverbs_ida, uverbs_dev->devnum); in ib_uverbs_remove_one()
1262 if (device->ops.disassociate_ucontext) { in ib_uverbs_remove_one()
1278 if (refcount_dec_and_test(&uverbs_dev->refcount)) in ib_uverbs_remove_one()
1281 wait_for_completion(&uverbs_dev->comp); in ib_uverbs_remove_one()
1283 put_device(&uverbs_dev->dev); in ib_uverbs_remove_one()