blob: 12a1e0572ef208fd341aad093aa45d4a29f0fce0 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.
Roland Dreier2a1d9b72005-08-10 23:03:10 -07003 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
4 * Copyright (c) 2004 Voltaire, Inc. All rights reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
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>
Ingo Molnar95ed6442006-01-13 14:51:39 -080048#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50#include <net/neighbour.h>
51
52#include <asm/atomic.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
Roland Dreiera4d61e82005-08-25 13:40:04 -070054#include <rdma/ib_verbs.h>
55#include <rdma/ib_pack.h>
56#include <rdma/ib_sa.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
58/* constants */
59
60enum {
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,
Shirley Ma0f485252006-04-10 09:43:58 -070068 IPOIB_MAX_QUEUE_SIZE = 8192,
69 IPOIB_MIN_QUEUE_SIZE = 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
71 IPOIB_NUM_WC = 4,
72
73 IPOIB_MAX_PATH_REC_QUEUE = 3,
74 IPOIB_MAX_MCAST_QUEUE = 3,
75
76 IPOIB_FLAG_OPER_UP = 0,
Leonid Arsh7a343d42006-03-23 19:52:51 +020077 IPOIB_FLAG_INITIALIZED = 1,
78 IPOIB_FLAG_ADMIN_UP = 2,
79 IPOIB_PKEY_ASSIGNED = 3,
80 IPOIB_PKEY_STOP = 4,
81 IPOIB_FLAG_SUBINTERFACE = 5,
82 IPOIB_MCAST_RUN = 6,
83 IPOIB_STOP_REAPER = 7,
84 IPOIB_MCAST_STARTED = 8,
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
86 IPOIB_MAX_BACKOFF_SECONDS = 16,
87
88 IPOIB_MCAST_FLAG_FOUND = 0, /* used in set_multicast_list */
89 IPOIB_MCAST_FLAG_SENDONLY = 1,
90 IPOIB_MCAST_FLAG_BUSY = 2, /* joining or already joined */
91 IPOIB_MCAST_FLAG_ATTACHED = 3,
92};
93
94/* structs */
95
96struct ipoib_header {
Sean Hefty97f52eb2005-08-13 21:05:57 -070097 __be16 proto;
98 u16 reserved;
Linus Torvalds1da177e2005-04-16 15:20:36 -070099};
100
101struct ipoib_pseudoheader {
102 u8 hwaddr[INFINIBAND_ALEN];
103};
104
105struct ipoib_mcast;
106
Roland Dreier1993d682005-10-28 15:30:34 -0700107struct ipoib_rx_buf {
108 struct sk_buff *skb;
109 dma_addr_t mapping;
110};
111
112struct ipoib_tx_buf {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 struct sk_buff *skb;
114 DECLARE_PCI_UNMAP_ADDR(mapping)
115};
116
117/*
118 * Device private locking: tx_lock protects members used in TX fast
119 * path (and we use LLTX so upper layers don't do extra locking).
120 * lock protects everything else. lock nests inside of tx_lock (ie
121 * tx_lock must be acquired first if needed).
122 */
123struct ipoib_dev_priv {
124 spinlock_t lock;
125
126 struct net_device *dev;
127
128 unsigned long flags;
129
Ingo Molnar95ed6442006-01-13 14:51:39 -0800130 struct mutex mcast_mutex;
131 struct mutex vlan_mutex;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
133 struct rb_root path_tree;
134 struct list_head path_list;
135
136 struct ipoib_mcast *broadcast;
137 struct list_head multicast_list;
138 struct rb_root multicast_tree;
139
140 struct work_struct pkey_task;
141 struct work_struct mcast_task;
142 struct work_struct flush_task;
143 struct work_struct restart_task;
144 struct work_struct ah_reap_task;
145
146 struct ib_device *ca;
147 u8 port;
148 u16 pkey;
149 struct ib_pd *pd;
150 struct ib_mr *mr;
151 struct ib_cq *cq;
152 struct ib_qp *qp;
153 u32 qkey;
154
155 union ib_gid local_gid;
156 u16 local_lid;
157 u8 local_rate;
158
159 unsigned int admin_mtu;
160 unsigned int mcast_mtu;
161
Roland Dreier1993d682005-10-28 15:30:34 -0700162 struct ipoib_rx_buf *rx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163
Roland Dreier1993d682005-10-28 15:30:34 -0700164 spinlock_t tx_lock;
165 struct ipoib_tx_buf *tx_ring;
166 unsigned tx_head;
167 unsigned tx_tail;
168 struct ib_sge tx_sge;
169 struct ib_send_wr tx_wr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170
171 struct ib_wc ibwc[IPOIB_NUM_WC];
172
173 struct list_head dead_ahs;
174
175 struct ib_event_handler event_handler;
176
177 struct net_device_stats stats;
178
179 struct net_device *parent;
180 struct list_head child_intfs;
181 struct list_head list;
182
183#ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
184 struct list_head fs_list;
185 struct dentry *mcg_dentry;
Roland Dreier1732b0e2005-11-07 10:33:11 -0800186 struct dentry *path_dentry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187#endif
188};
189
190struct ipoib_ah {
191 struct net_device *dev;
192 struct ib_ah *ah;
193 struct list_head list;
194 struct kref ref;
195 unsigned last_send;
196};
197
198struct ipoib_path {
199 struct net_device *dev;
200 struct ib_sa_path_rec pathrec;
201 struct ipoib_ah *ah;
202 struct sk_buff_head queue;
203
204 struct list_head neigh_list;
205
206 int query_id;
207 struct ib_sa_query *query;
208 struct completion done;
209
210 struct rb_node rb_node;
211 struct list_head list;
212};
213
214struct ipoib_neigh {
215 struct ipoib_ah *ah;
216 struct sk_buff_head queue;
217
218 struct neighbour *neighbour;
219
220 struct list_head list;
221};
222
Michael S. Tsirkin44af79f2006-02-20 21:50:39 -0800223/*
224 * We stash a pointer to our private neighbour information after our
225 * hardware address in neigh->ha. The ALIGN() expression here makes
226 * sure that this pointer is stored aligned so that an unaligned
227 * load is not needed to dereference it.
228 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229static inline struct ipoib_neigh **to_ipoib_neigh(struct neighbour *neigh)
230{
Michael S. Tsirkin44af79f2006-02-20 21:50:39 -0800231 return (void*) neigh + ALIGN(offsetof(struct neighbour, ha) +
232 INFINIBAND_ALEN, sizeof(void *));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233}
234
Michael S. Tsirkind2e06552006-04-04 19:59:40 +0300235struct ipoib_neigh *ipoib_neigh_alloc(struct neighbour *neigh);
236void ipoib_neigh_free(struct ipoib_neigh *neigh);
237
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238extern struct workqueue_struct *ipoib_workqueue;
239
240/* functions */
241
242void ipoib_ib_completion(struct ib_cq *cq, void *dev_ptr);
243
244struct ipoib_ah *ipoib_create_ah(struct net_device *dev,
245 struct ib_pd *pd, struct ib_ah_attr *attr);
246void ipoib_free_ah(struct kref *kref);
247static inline void ipoib_put_ah(struct ipoib_ah *ah)
248{
249 kref_put(&ah->ref, ipoib_free_ah);
250}
251
Roland Dreier8ae5a8a2005-11-02 20:51:01 -0800252int ipoib_open(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253int ipoib_add_pkey_attr(struct net_device *dev);
254
255void ipoib_send(struct net_device *dev, struct sk_buff *skb,
256 struct ipoib_ah *address, u32 qpn);
257void ipoib_reap_ah(void *dev_ptr);
258
259void ipoib_flush_paths(struct net_device *dev);
260struct ipoib_dev_priv *ipoib_intf_alloc(const char *format);
261
262int ipoib_ib_dev_init(struct net_device *dev, struct ib_device *ca, int port);
263void ipoib_ib_dev_flush(void *dev);
264void ipoib_ib_dev_cleanup(struct net_device *dev);
265
266int ipoib_ib_dev_open(struct net_device *dev);
267int ipoib_ib_dev_up(struct net_device *dev);
Jack Morgenstein0b3ea082006-03-20 10:08:24 -0800268int ipoib_ib_dev_down(struct net_device *dev, int flush);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269int ipoib_ib_dev_stop(struct net_device *dev);
270
271int ipoib_dev_init(struct net_device *dev, struct ib_device *ca, int port);
272void ipoib_dev_cleanup(struct net_device *dev);
273
274void ipoib_mcast_join_task(void *dev_ptr);
275void ipoib_mcast_send(struct net_device *dev, union ib_gid *mgid,
276 struct sk_buff *skb);
277
278void ipoib_mcast_restart_task(void *dev_ptr);
279int ipoib_mcast_start_thread(struct net_device *dev);
Roland Dreier8d2cae02005-09-20 10:52:04 -0700280int ipoib_mcast_stop_thread(struct net_device *dev, int flush);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281
282void ipoib_mcast_dev_down(struct net_device *dev);
283void ipoib_mcast_dev_flush(struct net_device *dev);
284
Roland Dreier8ae5a8a2005-11-02 20:51:01 -0800285#ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286struct ipoib_mcast_iter *ipoib_mcast_iter_init(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287int ipoib_mcast_iter_next(struct ipoib_mcast_iter *iter);
288void ipoib_mcast_iter_read(struct ipoib_mcast_iter *iter,
289 union ib_gid *gid,
290 unsigned long *created,
291 unsigned int *queuelen,
292 unsigned int *complete,
293 unsigned int *send_only);
Roland Dreier1732b0e2005-11-07 10:33:11 -0800294
295struct ipoib_path_iter *ipoib_path_iter_init(struct net_device *dev);
296int ipoib_path_iter_next(struct ipoib_path_iter *iter);
297void ipoib_path_iter_read(struct ipoib_path_iter *iter,
298 struct ipoib_path *path);
Roland Dreier8ae5a8a2005-11-02 20:51:01 -0800299#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300
301int ipoib_mcast_attach(struct net_device *dev, u16 mlid,
302 union ib_gid *mgid);
303int ipoib_mcast_detach(struct net_device *dev, u16 mlid,
304 union ib_gid *mgid);
305
Roland Dreier5b6810e2005-10-11 11:08:24 -0700306int ipoib_init_qp(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307int ipoib_transport_dev_init(struct net_device *dev, struct ib_device *ca);
308void ipoib_transport_dev_cleanup(struct net_device *dev);
309
310void ipoib_event(struct ib_event_handler *handler,
311 struct ib_event *record);
312
313int ipoib_vlan_add(struct net_device *pdev, unsigned short pkey);
314int ipoib_vlan_delete(struct net_device *pdev, unsigned short pkey);
315
316void ipoib_pkey_poll(void *dev);
317int ipoib_pkey_dev_delay_open(struct net_device *dev);
318
319#ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
Roland Dreier1732b0e2005-11-07 10:33:11 -0800320void ipoib_create_debug_files(struct net_device *dev);
321void ipoib_delete_debug_files(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322int ipoib_register_debugfs(void);
323void ipoib_unregister_debugfs(void);
324#else
Roland Dreier1732b0e2005-11-07 10:33:11 -0800325static inline void ipoib_create_debug_files(struct net_device *dev) { }
326static inline void ipoib_delete_debug_files(struct net_device *dev) { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327static inline int ipoib_register_debugfs(void) { return 0; }
328static inline void ipoib_unregister_debugfs(void) { }
329#endif
330
331
332#define ipoib_printk(level, priv, format, arg...) \
333 printk(level "%s: " format, ((struct ipoib_dev_priv *) priv)->dev->name , ## arg)
334#define ipoib_warn(priv, format, arg...) \
335 ipoib_printk(KERN_WARNING, priv, format , ## arg)
336
Shirley Ma0f485252006-04-10 09:43:58 -0700337extern int ipoib_sendq_size;
338extern int ipoib_recvq_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339
340#ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
341extern int ipoib_debug_level;
342
343#define ipoib_dbg(priv, format, arg...) \
344 do { \
345 if (ipoib_debug_level > 0) \
346 ipoib_printk(KERN_DEBUG, priv, format , ## arg); \
347 } while (0)
348#define ipoib_dbg_mcast(priv, format, arg...) \
349 do { \
350 if (mcast_debug_level > 0) \
351 ipoib_printk(KERN_DEBUG, priv, format , ## arg); \
352 } while (0)
353#else /* CONFIG_INFINIBAND_IPOIB_DEBUG */
354#define ipoib_dbg(priv, format, arg...) \
355 do { (void) (priv); } while (0)
356#define ipoib_dbg_mcast(priv, format, arg...) \
357 do { (void) (priv); } while (0)
358#endif /* CONFIG_INFINIBAND_IPOIB_DEBUG */
359
360#ifdef CONFIG_INFINIBAND_IPOIB_DEBUG_DATA
361#define ipoib_dbg_data(priv, format, arg...) \
362 do { \
363 if (data_debug_level > 0) \
364 ipoib_printk(KERN_DEBUG, priv, format , ## arg); \
365 } while (0)
366#else /* CONFIG_INFINIBAND_IPOIB_DEBUG_DATA */
367#define ipoib_dbg_data(priv, format, arg...) \
368 do { (void) (priv); } while (0)
369#endif /* CONFIG_INFINIBAND_IPOIB_DEBUG_DATA */
370
371
372#define IPOIB_GID_FMT "%x:%x:%x:%x:%x:%x:%x:%x"
373
374#define IPOIB_GID_ARG(gid) be16_to_cpup((__be16 *) ((gid).raw + 0)), \
375 be16_to_cpup((__be16 *) ((gid).raw + 2)), \
376 be16_to_cpup((__be16 *) ((gid).raw + 4)), \
377 be16_to_cpup((__be16 *) ((gid).raw + 6)), \
378 be16_to_cpup((__be16 *) ((gid).raw + 8)), \
379 be16_to_cpup((__be16 *) ((gid).raw + 10)), \
380 be16_to_cpup((__be16 *) ((gid).raw + 12)), \
381 be16_to_cpup((__be16 *) ((gid).raw + 14))
382
383#endif /* _IPOIB_H */