Pull fix-cpu-possible-map into release branch
[sfrench/cifs-2.6.git] / drivers / infiniband / ulp / ipoib / ipoib.h
1 /*
2  * Copyright (c) 2004, 2005 Topspin Communications.  All rights reserved.
3  * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
4  * Copyright (c) 2004 Voltaire, Inc. All rights reserved.
5  *
6  * This software is available to you under a choice of one of two
7  * licenses.  You may choose to be licensed under the terms of the GNU
8  * General Public License (GPL) Version 2, available from the file
9  * COPYING in the main directory of this source tree, or the
10  * OpenIB.org BSD license below:
11  *
12  *     Redistribution and use in source and binary forms, with or
13  *     without modification, are permitted provided that the following
14  *     conditions are met:
15  *
16  *      - Redistributions of source code must retain the above
17  *        copyright notice, this list of conditions and the following
18  *        disclaimer.
19  *
20  *      - Redistributions in binary form must reproduce the above
21  *        copyright notice, this list of conditions and the following
22  *        disclaimer in the documentation and/or other materials
23  *        provided with the distribution.
24  *
25  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32  * SOFTWARE.
33  *
34  * $Id: ipoib.h 1358 2004-12-17 22:00:11Z roland $
35  */
36
37 #ifndef _IPOIB_H
38 #define _IPOIB_H
39
40 #include <linux/list.h>
41 #include <linux/skbuff.h>
42 #include <linux/netdevice.h>
43 #include <linux/workqueue.h>
44 #include <linux/pci.h>
45 #include <linux/config.h>
46 #include <linux/kref.h>
47 #include <linux/if_infiniband.h>
48 #include <linux/mutex.h>
49
50 #include <net/neighbour.h>
51
52 #include <asm/atomic.h>
53
54 #include <rdma/ib_verbs.h>
55 #include <rdma/ib_pack.h>
56 #include <rdma/ib_sa.h>
57
58 /* constants */
59
60 enum {
61         IPOIB_PACKET_SIZE         = 2048,
62         IPOIB_BUF_SIZE            = IPOIB_PACKET_SIZE + IB_GRH_BYTES,
63
64         IPOIB_ENCAP_LEN           = 4,
65
66         IPOIB_RX_RING_SIZE        = 128,
67         IPOIB_TX_RING_SIZE        = 64,
68
69         IPOIB_NUM_WC              = 4,
70
71         IPOIB_MAX_PATH_REC_QUEUE  = 3,
72         IPOIB_MAX_MCAST_QUEUE     = 3,
73
74         IPOIB_FLAG_OPER_UP        = 0,
75         IPOIB_FLAG_ADMIN_UP       = 1,
76         IPOIB_PKEY_ASSIGNED       = 2,
77         IPOIB_PKEY_STOP           = 3,
78         IPOIB_FLAG_SUBINTERFACE   = 4,
79         IPOIB_MCAST_RUN           = 5,
80         IPOIB_STOP_REAPER         = 6,
81         IPOIB_MCAST_STARTED       = 7,
82
83         IPOIB_MAX_BACKOFF_SECONDS = 16,
84
85         IPOIB_MCAST_FLAG_FOUND    = 0,  /* used in set_multicast_list */
86         IPOIB_MCAST_FLAG_SENDONLY = 1,
87         IPOIB_MCAST_FLAG_BUSY     = 2,  /* joining or already joined */
88         IPOIB_MCAST_FLAG_ATTACHED = 3,
89 };
90
91 /* structs */
92
93 struct ipoib_header {
94         __be16  proto;
95         u16     reserved;
96 };
97
98 struct ipoib_pseudoheader {
99         u8  hwaddr[INFINIBAND_ALEN];
100 };
101
102 struct ipoib_mcast;
103
104 struct ipoib_rx_buf {
105         struct sk_buff *skb;
106         dma_addr_t      mapping;
107 };
108
109 struct ipoib_tx_buf {
110         struct sk_buff *skb;
111         DECLARE_PCI_UNMAP_ADDR(mapping)
112 };
113
114 /*
115  * Device private locking: tx_lock protects members used in TX fast
116  * path (and we use LLTX so upper layers don't do extra locking).
117  * lock protects everything else.  lock nests inside of tx_lock (ie
118  * tx_lock must be acquired first if needed).
119  */
120 struct ipoib_dev_priv {
121         spinlock_t lock;
122
123         struct net_device *dev;
124
125         unsigned long flags;
126
127         struct mutex mcast_mutex;
128         struct mutex vlan_mutex;
129
130         struct rb_root  path_tree;
131         struct list_head path_list;
132
133         struct ipoib_mcast *broadcast;
134         struct list_head multicast_list;
135         struct rb_root multicast_tree;
136
137         struct work_struct pkey_task;
138         struct work_struct mcast_task;
139         struct work_struct flush_task;
140         struct work_struct restart_task;
141         struct work_struct ah_reap_task;
142
143         struct ib_device *ca;
144         u8                port;
145         u16               pkey;
146         struct ib_pd     *pd;
147         struct ib_mr     *mr;
148         struct ib_cq     *cq;
149         struct ib_qp     *qp;
150         u32               qkey;
151
152         union ib_gid local_gid;
153         u16          local_lid;
154         u8           local_rate;
155
156         unsigned int admin_mtu;
157         unsigned int mcast_mtu;
158
159         struct ipoib_rx_buf *rx_ring;
160
161         spinlock_t           tx_lock;
162         struct ipoib_tx_buf *tx_ring;
163         unsigned             tx_head;
164         unsigned             tx_tail;
165         struct ib_sge        tx_sge;
166         struct ib_send_wr    tx_wr;
167
168         struct ib_wc ibwc[IPOIB_NUM_WC];
169
170         struct list_head dead_ahs;
171
172         struct ib_event_handler event_handler;
173
174         struct net_device_stats stats;
175
176         struct net_device *parent;
177         struct list_head child_intfs;
178         struct list_head list;
179
180 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
181         struct list_head fs_list;
182         struct dentry *mcg_dentry;
183         struct dentry *path_dentry;
184 #endif
185 };
186
187 struct ipoib_ah {
188         struct net_device *dev;
189         struct ib_ah      *ah;
190         struct list_head   list;
191         struct kref        ref;
192         unsigned           last_send;
193 };
194
195 struct ipoib_path {
196         struct net_device    *dev;
197         struct ib_sa_path_rec pathrec;
198         struct ipoib_ah      *ah;
199         struct sk_buff_head   queue;
200
201         struct list_head      neigh_list;
202
203         int                   query_id;
204         struct ib_sa_query   *query;
205         struct completion     done;
206
207         struct rb_node        rb_node;
208         struct list_head      list;
209 };
210
211 struct ipoib_neigh {
212         struct ipoib_ah    *ah;
213         struct sk_buff_head queue;
214
215         struct neighbour   *neighbour;
216
217         struct list_head    list;
218 };
219
220 static inline struct ipoib_neigh **to_ipoib_neigh(struct neighbour *neigh)
221 {
222         return (struct ipoib_neigh **) (neigh->ha + 24 -
223                                         (offsetof(struct neighbour, ha) & 4));
224 }
225
226 extern struct workqueue_struct *ipoib_workqueue;
227
228 /* functions */
229
230 void ipoib_ib_completion(struct ib_cq *cq, void *dev_ptr);
231
232 struct ipoib_ah *ipoib_create_ah(struct net_device *dev,
233                                  struct ib_pd *pd, struct ib_ah_attr *attr);
234 void ipoib_free_ah(struct kref *kref);
235 static inline void ipoib_put_ah(struct ipoib_ah *ah)
236 {
237         kref_put(&ah->ref, ipoib_free_ah);
238 }
239
240 int ipoib_open(struct net_device *dev);
241 int ipoib_add_pkey_attr(struct net_device *dev);
242
243 void ipoib_send(struct net_device *dev, struct sk_buff *skb,
244                 struct ipoib_ah *address, u32 qpn);
245 void ipoib_reap_ah(void *dev_ptr);
246
247 void ipoib_flush_paths(struct net_device *dev);
248 struct ipoib_dev_priv *ipoib_intf_alloc(const char *format);
249
250 int ipoib_ib_dev_init(struct net_device *dev, struct ib_device *ca, int port);
251 void ipoib_ib_dev_flush(void *dev);
252 void ipoib_ib_dev_cleanup(struct net_device *dev);
253
254 int ipoib_ib_dev_open(struct net_device *dev);
255 int ipoib_ib_dev_up(struct net_device *dev);
256 int ipoib_ib_dev_down(struct net_device *dev);
257 int ipoib_ib_dev_stop(struct net_device *dev);
258
259 int ipoib_dev_init(struct net_device *dev, struct ib_device *ca, int port);
260 void ipoib_dev_cleanup(struct net_device *dev);
261
262 void ipoib_mcast_join_task(void *dev_ptr);
263 void ipoib_mcast_send(struct net_device *dev, union ib_gid *mgid,
264                       struct sk_buff *skb);
265
266 void ipoib_mcast_restart_task(void *dev_ptr);
267 int ipoib_mcast_start_thread(struct net_device *dev);
268 int ipoib_mcast_stop_thread(struct net_device *dev, int flush);
269
270 void ipoib_mcast_dev_down(struct net_device *dev);
271 void ipoib_mcast_dev_flush(struct net_device *dev);
272
273 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
274 struct ipoib_mcast_iter *ipoib_mcast_iter_init(struct net_device *dev);
275 int ipoib_mcast_iter_next(struct ipoib_mcast_iter *iter);
276 void ipoib_mcast_iter_read(struct ipoib_mcast_iter *iter,
277                                   union ib_gid *gid,
278                                   unsigned long *created,
279                                   unsigned int *queuelen,
280                                   unsigned int *complete,
281                                   unsigned int *send_only);
282
283 struct ipoib_path_iter *ipoib_path_iter_init(struct net_device *dev);
284 int ipoib_path_iter_next(struct ipoib_path_iter *iter);
285 void ipoib_path_iter_read(struct ipoib_path_iter *iter,
286                           struct ipoib_path *path);
287 #endif
288
289 int ipoib_mcast_attach(struct net_device *dev, u16 mlid,
290                        union ib_gid *mgid);
291 int ipoib_mcast_detach(struct net_device *dev, u16 mlid,
292                        union ib_gid *mgid);
293
294 int ipoib_init_qp(struct net_device *dev);
295 int ipoib_transport_dev_init(struct net_device *dev, struct ib_device *ca);
296 void ipoib_transport_dev_cleanup(struct net_device *dev);
297
298 void ipoib_event(struct ib_event_handler *handler,
299                  struct ib_event *record);
300
301 int ipoib_vlan_add(struct net_device *pdev, unsigned short pkey);
302 int ipoib_vlan_delete(struct net_device *pdev, unsigned short pkey);
303
304 void ipoib_pkey_poll(void *dev);
305 int ipoib_pkey_dev_delay_open(struct net_device *dev);
306
307 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
308 void ipoib_create_debug_files(struct net_device *dev);
309 void ipoib_delete_debug_files(struct net_device *dev);
310 int ipoib_register_debugfs(void);
311 void ipoib_unregister_debugfs(void);
312 #else
313 static inline void ipoib_create_debug_files(struct net_device *dev) { }
314 static inline void ipoib_delete_debug_files(struct net_device *dev) { }
315 static inline int ipoib_register_debugfs(void) { return 0; }
316 static inline void ipoib_unregister_debugfs(void) { }
317 #endif
318
319
320 #define ipoib_printk(level, priv, format, arg...)       \
321         printk(level "%s: " format, ((struct ipoib_dev_priv *) priv)->dev->name , ## arg)
322 #define ipoib_warn(priv, format, arg...)                \
323         ipoib_printk(KERN_WARNING, priv, format , ## arg)
324
325
326 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
327 extern int ipoib_debug_level;
328
329 #define ipoib_dbg(priv, format, arg...)                 \
330         do {                                            \
331                 if (ipoib_debug_level > 0)                      \
332                         ipoib_printk(KERN_DEBUG, priv, format , ## arg); \
333         } while (0)
334 #define ipoib_dbg_mcast(priv, format, arg...)           \
335         do {                                            \
336                 if (mcast_debug_level > 0)              \
337                         ipoib_printk(KERN_DEBUG, priv, format , ## arg); \
338         } while (0)
339 #else /* CONFIG_INFINIBAND_IPOIB_DEBUG */
340 #define ipoib_dbg(priv, format, arg...)                 \
341         do { (void) (priv); } while (0)
342 #define ipoib_dbg_mcast(priv, format, arg...)           \
343         do { (void) (priv); } while (0)
344 #endif /* CONFIG_INFINIBAND_IPOIB_DEBUG */
345
346 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG_DATA
347 #define ipoib_dbg_data(priv, format, arg...)            \
348         do {                                            \
349                 if (data_debug_level > 0)               \
350                         ipoib_printk(KERN_DEBUG, priv, format , ## arg); \
351         } while (0)
352 #else /* CONFIG_INFINIBAND_IPOIB_DEBUG_DATA */
353 #define ipoib_dbg_data(priv, format, arg...)            \
354         do { (void) (priv); } while (0)
355 #endif /* CONFIG_INFINIBAND_IPOIB_DEBUG_DATA */
356
357
358 #define IPOIB_GID_FMT           "%x:%x:%x:%x:%x:%x:%x:%x"
359
360 #define IPOIB_GID_ARG(gid)      be16_to_cpup((__be16 *) ((gid).raw +  0)), \
361                                 be16_to_cpup((__be16 *) ((gid).raw +  2)), \
362                                 be16_to_cpup((__be16 *) ((gid).raw +  4)), \
363                                 be16_to_cpup((__be16 *) ((gid).raw +  6)), \
364                                 be16_to_cpup((__be16 *) ((gid).raw +  8)), \
365                                 be16_to_cpup((__be16 *) ((gid).raw + 10)), \
366                                 be16_to_cpup((__be16 *) ((gid).raw + 12)), \
367                                 be16_to_cpup((__be16 *) ((gid).raw + 14))
368
369 #endif /* _IPOIB_H */