IB/usnic: Use GFP_ATOMIC under spinlock
[cascardo/linux.git] / drivers / infiniband / hw / usnic / usnic_ib.h
1 /*
2  * Copyright (c) 2013, Cisco Systems, Inc. All rights reserved.
3  *
4  * This program is free software; you may redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; version 2 of the License.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
9  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
10  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
11  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
12  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
13  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
14  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
15  * SOFTWARE.
16  *
17  */
18
19 #ifndef USNIC_IB_H_
20 #define USNIC_IB_H_
21
22 #include <linux/iommu.h>
23 #include <linux/netdevice.h>
24 #include <linux/version.h>
25
26 #include <rdma/ib_verbs.h>
27
28
29 #include "usnic.h"
30 #include "usnic_abi.h"
31 #include "usnic_vnic.h"
32
33 #define USNIC_IB_PORT_CNT               1
34 #define USNIC_IB_NUM_COMP_VECTORS       1
35
36 extern unsigned int usnic_ib_share_vf;
37
38 struct usnic_ib_ucontext {
39         struct ib_ucontext              ibucontext;
40         /* Protected by usnic_ib_dev->usdev_lock */
41         struct list_head                qp_grp_list;
42         struct list_head                link;
43 };
44
45 struct usnic_ib_pd {
46         struct ib_pd                    ibpd;
47         struct usnic_uiom_pd            *umem_pd;
48 };
49
50 struct usnic_ib_mr {
51         struct ib_mr                    ibmr;
52         struct usnic_uiom_reg           *umem;
53 };
54
55 struct usnic_ib_dev {
56         struct ib_device                ib_dev;
57         struct pci_dev                  *pdev;
58         struct net_device               *netdev;
59         struct usnic_fwd_dev            *ufdev;
60         struct list_head                ib_dev_link;
61         struct list_head                vf_dev_list;
62         struct list_head                ctx_list;
63         struct mutex                    usdev_lock;
64
65         /* provisioning information */
66         struct kref                     vf_cnt;
67         unsigned int                    vf_res_cnt[USNIC_VNIC_RES_TYPE_MAX];
68
69         /* sysfs vars for QPN reporting */
70         struct kobject *qpn_kobj;
71 };
72
73 struct usnic_ib_vf {
74         struct usnic_ib_dev             *pf;
75         spinlock_t                      lock;
76         struct usnic_vnic               *vnic;
77         unsigned int                    qp_grp_ref_cnt;
78         struct usnic_ib_pd              *pd;
79         struct list_head                link;
80 };
81
82 static inline
83 struct usnic_ib_dev *to_usdev(struct ib_device *ibdev)
84 {
85         return container_of(ibdev, struct usnic_ib_dev, ib_dev);
86 }
87
88 static inline
89 struct usnic_ib_ucontext *to_ucontext(struct ib_ucontext *ibucontext)
90 {
91         return container_of(ibucontext, struct usnic_ib_ucontext, ibucontext);
92 }
93
94 static inline
95 struct usnic_ib_pd *to_upd(struct ib_pd *ibpd)
96 {
97         return container_of(ibpd, struct usnic_ib_pd, ibpd);
98 }
99
100 static inline
101 struct usnic_ib_ucontext *to_uucontext(struct ib_ucontext *ibucontext)
102 {
103         return container_of(ibucontext, struct usnic_ib_ucontext, ibucontext);
104 }
105
106 static inline
107 struct usnic_ib_mr *to_umr(struct ib_mr *ibmr)
108 {
109         return container_of(ibmr, struct usnic_ib_mr, ibmr);
110 }
111 void usnic_ib_log_vf(struct usnic_ib_vf *vf);
112
113 #define UPDATE_PTR_LEFT(N, P, L)                        \
114 do {                                                    \
115         L -= (N);                                       \
116         P += (N);                                       \
117 } while (0)
118
119 #endif /* USNIC_IB_H_ */