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.
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:
12 * Redistribution and use in source and binary forms, with or
13 * without modification, are permitted provided that the following
16 * - Redistributions of source code must retain the above
17 * copyright notice, this list of conditions and the following
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.
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
34 * $Id: ipoib.h 1358 2004-12-17 22:00:11Z roland $
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>
50 #include <net/neighbour.h>
52 #include <asm/atomic.h>
54 #include <rdma/ib_verbs.h>
55 #include <rdma/ib_pack.h>
56 #include <rdma/ib_sa.h>
61 IPOIB_PACKET_SIZE
= 2048,
62 IPOIB_BUF_SIZE
= IPOIB_PACKET_SIZE
+ IB_GRH_BYTES
,
66 IPOIB_RX_RING_SIZE
= 128,
67 IPOIB_TX_RING_SIZE
= 64,
71 IPOIB_MAX_PATH_REC_QUEUE
= 3,
72 IPOIB_MAX_MCAST_QUEUE
= 3,
74 IPOIB_FLAG_OPER_UP
= 0,
75 IPOIB_FLAG_ADMIN_UP
= 1,
76 IPOIB_PKEY_ASSIGNED
= 2,
78 IPOIB_FLAG_SUBINTERFACE
= 4,
80 IPOIB_STOP_REAPER
= 6,
81 IPOIB_MCAST_STARTED
= 7,
83 IPOIB_MAX_BACKOFF_SECONDS
= 16,
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,
98 struct ipoib_pseudoheader
{
99 u8 hwaddr
[INFINIBAND_ALEN
];
104 struct ipoib_rx_buf
{
109 struct ipoib_tx_buf
{
111 DECLARE_PCI_UNMAP_ADDR(mapping
)
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).
120 struct ipoib_dev_priv
{
123 struct net_device
*dev
;
127 struct mutex mcast_mutex
;
128 struct mutex vlan_mutex
;
130 struct rb_root path_tree
;
131 struct list_head path_list
;
133 struct ipoib_mcast
*broadcast
;
134 struct list_head multicast_list
;
135 struct rb_root multicast_tree
;
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
;
143 struct ib_device
*ca
;
152 union ib_gid local_gid
;
156 unsigned int admin_mtu
;
157 unsigned int mcast_mtu
;
159 struct ipoib_rx_buf
*rx_ring
;
162 struct ipoib_tx_buf
*tx_ring
;
165 struct ib_sge tx_sge
;
166 struct ib_send_wr tx_wr
;
168 struct ib_wc ibwc
[IPOIB_NUM_WC
];
170 struct list_head dead_ahs
;
172 struct ib_event_handler event_handler
;
174 struct net_device_stats stats
;
176 struct net_device
*parent
;
177 struct list_head child_intfs
;
178 struct list_head list
;
180 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
181 struct list_head fs_list
;
182 struct dentry
*mcg_dentry
;
183 struct dentry
*path_dentry
;
188 struct net_device
*dev
;
190 struct list_head list
;
196 struct net_device
*dev
;
197 struct ib_sa_path_rec pathrec
;
199 struct sk_buff_head queue
;
201 struct list_head neigh_list
;
204 struct ib_sa_query
*query
;
205 struct completion done
;
207 struct rb_node rb_node
;
208 struct list_head list
;
213 struct sk_buff_head queue
;
215 struct neighbour
*neighbour
;
217 struct list_head list
;
221 * We stash a pointer to our private neighbour information after our
222 * hardware address in neigh->ha. The ALIGN() expression here makes
223 * sure that this pointer is stored aligned so that an unaligned
224 * load is not needed to dereference it.
226 static inline struct ipoib_neigh
**to_ipoib_neigh(struct neighbour
*neigh
)
228 return (void*) neigh
+ ALIGN(offsetof(struct neighbour
, ha
) +
229 INFINIBAND_ALEN
, sizeof(void *));
232 extern struct workqueue_struct
*ipoib_workqueue
;
236 void ipoib_ib_completion(struct ib_cq
*cq
, void *dev_ptr
);
238 struct ipoib_ah
*ipoib_create_ah(struct net_device
*dev
,
239 struct ib_pd
*pd
, struct ib_ah_attr
*attr
);
240 void ipoib_free_ah(struct kref
*kref
);
241 static inline void ipoib_put_ah(struct ipoib_ah
*ah
)
243 kref_put(&ah
->ref
, ipoib_free_ah
);
246 int ipoib_open(struct net_device
*dev
);
247 int ipoib_add_pkey_attr(struct net_device
*dev
);
249 void ipoib_send(struct net_device
*dev
, struct sk_buff
*skb
,
250 struct ipoib_ah
*address
, u32 qpn
);
251 void ipoib_reap_ah(void *dev_ptr
);
253 void ipoib_flush_paths(struct net_device
*dev
);
254 struct ipoib_dev_priv
*ipoib_intf_alloc(const char *format
);
256 int ipoib_ib_dev_init(struct net_device
*dev
, struct ib_device
*ca
, int port
);
257 void ipoib_ib_dev_flush(void *dev
);
258 void ipoib_ib_dev_cleanup(struct net_device
*dev
);
260 int ipoib_ib_dev_open(struct net_device
*dev
);
261 int ipoib_ib_dev_up(struct net_device
*dev
);
262 int ipoib_ib_dev_down(struct net_device
*dev
, int flush
);
263 int ipoib_ib_dev_stop(struct net_device
*dev
);
265 int ipoib_dev_init(struct net_device
*dev
, struct ib_device
*ca
, int port
);
266 void ipoib_dev_cleanup(struct net_device
*dev
);
268 void ipoib_mcast_join_task(void *dev_ptr
);
269 void ipoib_mcast_send(struct net_device
*dev
, union ib_gid
*mgid
,
270 struct sk_buff
*skb
);
272 void ipoib_mcast_restart_task(void *dev_ptr
);
273 int ipoib_mcast_start_thread(struct net_device
*dev
);
274 int ipoib_mcast_stop_thread(struct net_device
*dev
, int flush
);
276 void ipoib_mcast_dev_down(struct net_device
*dev
);
277 void ipoib_mcast_dev_flush(struct net_device
*dev
);
279 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
280 struct ipoib_mcast_iter
*ipoib_mcast_iter_init(struct net_device
*dev
);
281 int ipoib_mcast_iter_next(struct ipoib_mcast_iter
*iter
);
282 void ipoib_mcast_iter_read(struct ipoib_mcast_iter
*iter
,
284 unsigned long *created
,
285 unsigned int *queuelen
,
286 unsigned int *complete
,
287 unsigned int *send_only
);
289 struct ipoib_path_iter
*ipoib_path_iter_init(struct net_device
*dev
);
290 int ipoib_path_iter_next(struct ipoib_path_iter
*iter
);
291 void ipoib_path_iter_read(struct ipoib_path_iter
*iter
,
292 struct ipoib_path
*path
);
295 int ipoib_mcast_attach(struct net_device
*dev
, u16 mlid
,
297 int ipoib_mcast_detach(struct net_device
*dev
, u16 mlid
,
300 int ipoib_init_qp(struct net_device
*dev
);
301 int ipoib_transport_dev_init(struct net_device
*dev
, struct ib_device
*ca
);
302 void ipoib_transport_dev_cleanup(struct net_device
*dev
);
304 void ipoib_event(struct ib_event_handler
*handler
,
305 struct ib_event
*record
);
307 int ipoib_vlan_add(struct net_device
*pdev
, unsigned short pkey
);
308 int ipoib_vlan_delete(struct net_device
*pdev
, unsigned short pkey
);
310 void ipoib_pkey_poll(void *dev
);
311 int ipoib_pkey_dev_delay_open(struct net_device
*dev
);
313 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
314 void ipoib_create_debug_files(struct net_device
*dev
);
315 void ipoib_delete_debug_files(struct net_device
*dev
);
316 int ipoib_register_debugfs(void);
317 void ipoib_unregister_debugfs(void);
319 static inline void ipoib_create_debug_files(struct net_device
*dev
) { }
320 static inline void ipoib_delete_debug_files(struct net_device
*dev
) { }
321 static inline int ipoib_register_debugfs(void) { return 0; }
322 static inline void ipoib_unregister_debugfs(void) { }
326 #define ipoib_printk(level, priv, format, arg...) \
327 printk(level "%s: " format, ((struct ipoib_dev_priv *) priv)->dev->name , ## arg)
328 #define ipoib_warn(priv, format, arg...) \
329 ipoib_printk(KERN_WARNING, priv, format , ## arg)
332 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
333 extern int ipoib_debug_level
;
335 #define ipoib_dbg(priv, format, arg...) \
337 if (ipoib_debug_level > 0) \
338 ipoib_printk(KERN_DEBUG, priv, format , ## arg); \
340 #define ipoib_dbg_mcast(priv, format, arg...) \
342 if (mcast_debug_level > 0) \
343 ipoib_printk(KERN_DEBUG, priv, format , ## arg); \
345 #else /* CONFIG_INFINIBAND_IPOIB_DEBUG */
346 #define ipoib_dbg(priv, format, arg...) \
347 do { (void) (priv); } while (0)
348 #define ipoib_dbg_mcast(priv, format, arg...) \
349 do { (void) (priv); } while (0)
350 #endif /* CONFIG_INFINIBAND_IPOIB_DEBUG */
352 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG_DATA
353 #define ipoib_dbg_data(priv, format, arg...) \
355 if (data_debug_level > 0) \
356 ipoib_printk(KERN_DEBUG, priv, format , ## arg); \
358 #else /* CONFIG_INFINIBAND_IPOIB_DEBUG_DATA */
359 #define ipoib_dbg_data(priv, format, arg...) \
360 do { (void) (priv); } while (0)
361 #endif /* CONFIG_INFINIBAND_IPOIB_DEBUG_DATA */
364 #define IPOIB_GID_FMT "%x:%x:%x:%x:%x:%x:%x:%x"
366 #define IPOIB_GID_ARG(gid) be16_to_cpup((__be16 *) ((gid).raw + 0)), \
367 be16_to_cpup((__be16 *) ((gid).raw + 2)), \
368 be16_to_cpup((__be16 *) ((gid).raw + 4)), \
369 be16_to_cpup((__be16 *) ((gid).raw + 6)), \
370 be16_to_cpup((__be16 *) ((gid).raw + 8)), \
371 be16_to_cpup((__be16 *) ((gid).raw + 10)), \
372 be16_to_cpup((__be16 *) ((gid).raw + 12)), \
373 be16_to_cpup((__be16 *) ((gid).raw + 14))
375 #endif /* _IPOIB_H */