Path: blob/master/drivers/infiniband/core/uverbs.h
37212 views
/*1* Copyright (c) 2005 Topspin Communications. All rights reserved.2* Copyright (c) 2005, 2006 Cisco Systems. All rights reserved.3* Copyright (c) 2005 Mellanox Technologies. All rights reserved.4* Copyright (c) 2005 Voltaire, Inc. All rights reserved.5* Copyright (c) 2005 PathScale, Inc. All rights reserved.6*7* This software is available to you under a choice of one of two8* licenses. You may choose to be licensed under the terms of the GNU9* General Public License (GPL) Version 2, available from the file10* COPYING in the main directory of this source tree, or the11* OpenIB.org BSD license below:12*13* Redistribution and use in source and binary forms, with or14* without modification, are permitted provided that the following15* conditions are met:16*17* - Redistributions of source code must retain the above18* copyright notice, this list of conditions and the following19* disclaimer.20*21* - Redistributions in binary form must reproduce the above22* copyright notice, this list of conditions and the following23* disclaimer in the documentation and/or other materials24* provided with the distribution.25*26* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,27* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF28* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND29* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS30* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN31* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN32* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE33* SOFTWARE.34*/3536#ifndef UVERBS_H37#define UVERBS_H3839#include <linux/kref.h>40#include <linux/idr.h>41#include <linux/mutex.h>42#include <linux/completion.h>43#include <linux/cdev.h>4445#include <rdma/ib_verbs.h>46#include <rdma/ib_umem.h>47#include <rdma/ib_user_verbs.h>4849/*50* Our lifetime rules for these structs are the following:51*52* struct ib_uverbs_device: One reference is held by the module and53* released in ib_uverbs_remove_one(). Another reference is taken by54* ib_uverbs_open() each time the character special file is opened,55* and released in ib_uverbs_release_file() when the file is released.56*57* struct ib_uverbs_file: One reference is held by the VFS and58* released when the file is closed. Another reference is taken when59* an asynchronous event queue file is created and released when the60* event file is closed.61*62* struct ib_uverbs_event_file: One reference is held by the VFS and63* released when the file is closed. For asynchronous event files,64* another reference is held by the corresponding main context file65* and released when that file is closed. For completion event files,66* a reference is taken when a CQ is created that uses the file, and67* released when the CQ is destroyed.68*/6970struct ib_uverbs_device {71struct kref ref;72int num_comp_vectors;73struct completion comp;74struct device *dev;75struct ib_device *ib_dev;76int devnum;77struct cdev cdev;78};7980struct ib_uverbs_event_file {81struct kref ref;82int is_async;83struct ib_uverbs_file *uverbs_file;84spinlock_t lock;85int is_closed;86wait_queue_head_t poll_wait;87struct fasync_struct *async_queue;88struct list_head event_list;89};9091struct ib_uverbs_file {92struct kref ref;93struct mutex mutex;94struct ib_uverbs_device *device;95struct ib_ucontext *ucontext;96struct ib_event_handler event_handler;97struct ib_uverbs_event_file *async_file;98};99100struct ib_uverbs_event {101union {102struct ib_uverbs_async_event_desc async;103struct ib_uverbs_comp_event_desc comp;104} desc;105struct list_head list;106struct list_head obj_list;107u32 *counter;108};109110struct ib_uverbs_mcast_entry {111struct list_head list;112union ib_gid gid;113u16 lid;114};115116struct ib_uevent_object {117struct ib_uobject uobject;118struct list_head event_list;119u32 events_reported;120};121122struct ib_uqp_object {123struct ib_uevent_object uevent;124struct list_head mcast_list;125};126127struct ib_ucq_object {128struct ib_uobject uobject;129struct ib_uverbs_file *uverbs_file;130struct list_head comp_list;131struct list_head async_list;132u32 comp_events_reported;133u32 async_events_reported;134};135136extern spinlock_t ib_uverbs_idr_lock;137extern struct idr ib_uverbs_pd_idr;138extern struct idr ib_uverbs_mr_idr;139extern struct idr ib_uverbs_mw_idr;140extern struct idr ib_uverbs_ah_idr;141extern struct idr ib_uverbs_cq_idr;142extern struct idr ib_uverbs_qp_idr;143extern struct idr ib_uverbs_srq_idr;144145void idr_remove_uobj(struct idr *idp, struct ib_uobject *uobj);146147struct file *ib_uverbs_alloc_event_file(struct ib_uverbs_file *uverbs_file,148int is_async);149struct ib_uverbs_event_file *ib_uverbs_lookup_comp_file(int fd);150151void ib_uverbs_release_ucq(struct ib_uverbs_file *file,152struct ib_uverbs_event_file *ev_file,153struct ib_ucq_object *uobj);154void ib_uverbs_release_uevent(struct ib_uverbs_file *file,155struct ib_uevent_object *uobj);156157void ib_uverbs_comp_handler(struct ib_cq *cq, void *cq_context);158void ib_uverbs_cq_event_handler(struct ib_event *event, void *context_ptr);159void ib_uverbs_qp_event_handler(struct ib_event *event, void *context_ptr);160void ib_uverbs_srq_event_handler(struct ib_event *event, void *context_ptr);161void ib_uverbs_event_handler(struct ib_event_handler *handler,162struct ib_event *event);163164#define IB_UVERBS_DECLARE_CMD(name) \165ssize_t ib_uverbs_##name(struct ib_uverbs_file *file, \166const char __user *buf, int in_len, \167int out_len)168169IB_UVERBS_DECLARE_CMD(get_context);170IB_UVERBS_DECLARE_CMD(query_device);171IB_UVERBS_DECLARE_CMD(query_port);172IB_UVERBS_DECLARE_CMD(alloc_pd);173IB_UVERBS_DECLARE_CMD(dealloc_pd);174IB_UVERBS_DECLARE_CMD(reg_mr);175IB_UVERBS_DECLARE_CMD(dereg_mr);176IB_UVERBS_DECLARE_CMD(create_comp_channel);177IB_UVERBS_DECLARE_CMD(create_cq);178IB_UVERBS_DECLARE_CMD(resize_cq);179IB_UVERBS_DECLARE_CMD(poll_cq);180IB_UVERBS_DECLARE_CMD(req_notify_cq);181IB_UVERBS_DECLARE_CMD(destroy_cq);182IB_UVERBS_DECLARE_CMD(create_qp);183IB_UVERBS_DECLARE_CMD(query_qp);184IB_UVERBS_DECLARE_CMD(modify_qp);185IB_UVERBS_DECLARE_CMD(destroy_qp);186IB_UVERBS_DECLARE_CMD(post_send);187IB_UVERBS_DECLARE_CMD(post_recv);188IB_UVERBS_DECLARE_CMD(post_srq_recv);189IB_UVERBS_DECLARE_CMD(create_ah);190IB_UVERBS_DECLARE_CMD(destroy_ah);191IB_UVERBS_DECLARE_CMD(attach_mcast);192IB_UVERBS_DECLARE_CMD(detach_mcast);193IB_UVERBS_DECLARE_CMD(create_srq);194IB_UVERBS_DECLARE_CMD(modify_srq);195IB_UVERBS_DECLARE_CMD(query_srq);196IB_UVERBS_DECLARE_CMD(destroy_srq);197198#endif /* UVERBS_H */199200201