fc906223220fcafba269028995b86e0df5ab98b1
[safe/jmp/linux-2.6] / drivers / infiniband / hw / amso1100 / c2_provider.h
1 /*
2  * Copyright (c) 2005 Ammasso, Inc. All rights reserved.
3  * Copyright (c) 2005 Open Grid Computing, Inc. All rights reserved.
4  *
5  * This software is available to you under a choice of one of two
6  * licenses.  You may choose to be licensed under the terms of the GNU
7  * General Public License (GPL) Version 2, available from the file
8  * COPYING in the main directory of this source tree, or the
9  * OpenIB.org BSD license below:
10  *
11  *     Redistribution and use in source and binary forms, with or
12  *     without modification, are permitted provided that the following
13  *     conditions are met:
14  *
15  *      - Redistributions of source code must retain the above
16  *        copyright notice, this list of conditions and the following
17  *        disclaimer.
18  *
19  *      - Redistributions in binary form must reproduce the above
20  *        copyright notice, this list of conditions and the following
21  *        disclaimer in the documentation and/or other materials
22  *        provided with the distribution.
23  *
24  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31  * SOFTWARE.
32  *
33  */
34
35 #ifndef C2_PROVIDER_H
36 #define C2_PROVIDER_H
37 #include <linux/inetdevice.h>
38
39 #include <rdma/ib_verbs.h>
40 #include <rdma/ib_pack.h>
41
42 #include "c2_mq.h"
43 #include <rdma/iw_cm.h>
44
45 #define C2_MPT_FLAG_ATOMIC        (1 << 14)
46 #define C2_MPT_FLAG_REMOTE_WRITE  (1 << 13)
47 #define C2_MPT_FLAG_REMOTE_READ   (1 << 12)
48 #define C2_MPT_FLAG_LOCAL_WRITE   (1 << 11)
49 #define C2_MPT_FLAG_LOCAL_READ    (1 << 10)
50
51 struct c2_buf_list {
52         void *buf;
53          DECLARE_PCI_UNMAP_ADDR(mapping)
54 };
55
56
57 /* The user context keeps track of objects allocated for a
58  * particular user-mode client. */
59 struct c2_ucontext {
60         struct ib_ucontext ibucontext;
61 };
62
63 struct c2_mtt;
64
65 /* All objects associated with a PD are kept in the
66  * associated user context if present.
67  */
68 struct c2_pd {
69         struct ib_pd ibpd;
70         u32 pd_id;
71 };
72
73 struct c2_mr {
74         struct ib_mr ibmr;
75         struct c2_pd *pd;
76 };
77
78 struct c2_av;
79
80 enum c2_ah_type {
81         C2_AH_ON_HCA,
82         C2_AH_PCI_POOL,
83         C2_AH_KMALLOC
84 };
85
86 struct c2_ah {
87         struct ib_ah ibah;
88 };
89
90 struct c2_cq {
91         struct ib_cq ibcq;
92         spinlock_t lock;
93         atomic_t refcount;
94         int cqn;
95         int is_kernel;
96         wait_queue_head_t wait;
97
98         u32 adapter_handle;
99         struct c2_mq mq;
100 };
101
102 struct c2_wq {
103         spinlock_t lock;
104 };
105 struct iw_cm_id;
106 struct c2_qp {
107         struct ib_qp ibqp;
108         struct iw_cm_id *cm_id;
109         spinlock_t lock;
110         atomic_t refcount;
111         wait_queue_head_t wait;
112         int qpn;
113
114         u32 adapter_handle;
115         u32 send_sgl_depth;
116         u32 recv_sgl_depth;
117         u32 rdma_write_sgl_depth;
118         u8 state;
119
120         struct c2_mq sq_mq;
121         struct c2_mq rq_mq;
122 };
123
124 struct c2_cr_query_attrs {
125         u32 local_addr;
126         u32 remote_addr;
127         u16 local_port;
128         u16 remote_port;
129 };
130
131 static inline struct c2_pd *to_c2pd(struct ib_pd *ibpd)
132 {
133         return container_of(ibpd, struct c2_pd, ibpd);
134 }
135
136 static inline struct c2_ucontext *to_c2ucontext(struct ib_ucontext *ibucontext)
137 {
138         return container_of(ibucontext, struct c2_ucontext, ibucontext);
139 }
140
141 static inline struct c2_mr *to_c2mr(struct ib_mr *ibmr)
142 {
143         return container_of(ibmr, struct c2_mr, ibmr);
144 }
145
146
147 static inline struct c2_ah *to_c2ah(struct ib_ah *ibah)
148 {
149         return container_of(ibah, struct c2_ah, ibah);
150 }
151
152 static inline struct c2_cq *to_c2cq(struct ib_cq *ibcq)
153 {
154         return container_of(ibcq, struct c2_cq, ibcq);
155 }
156
157 static inline struct c2_qp *to_c2qp(struct ib_qp *ibqp)
158 {
159         return container_of(ibqp, struct c2_qp, ibqp);
160 }
161
162 static inline int is_rnic_addr(struct net_device *netdev, u32 addr)
163 {
164         struct in_device *ind;
165         int ret = 0;
166
167         ind = in_dev_get(netdev);
168         if (!ind)
169                 return 0;
170
171         for_ifa(ind) {
172                 if (ifa->ifa_address == addr) {
173                         ret = 1;
174                         break;
175                 }
176         }
177         endfor_ifa(ind);
178         in_dev_put(ind);
179         return ret;
180 }
181 #endif                          /* C2_PROVIDER_H */