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>
49 #include <net/neighbour.h>
51 #include <asm/atomic.h>
52 #include <asm/semaphore.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,
82 IPOIB_MAX_BACKOFF_SECONDS
= 16,
84 IPOIB_MCAST_FLAG_FOUND
= 0, /* used in set_multicast_list */
85 IPOIB_MCAST_FLAG_SENDONLY
= 1,
86 IPOIB_MCAST_FLAG_BUSY
= 2, /* joining or already joined */
87 IPOIB_MCAST_FLAG_ATTACHED
= 3,
97 struct ipoib_pseudoheader
{
98 u8 hwaddr
[INFINIBAND_ALEN
];
105 DECLARE_PCI_UNMAP_ADDR(mapping
)
109 * Device private locking: tx_lock protects members used in TX fast
110 * path (and we use LLTX so upper layers don't do extra locking).
111 * lock protects everything else. lock nests inside of tx_lock (ie
112 * tx_lock must be acquired first if needed).
114 struct ipoib_dev_priv
{
117 struct net_device
*dev
;
121 struct semaphore mcast_mutex
;
122 struct semaphore vlan_mutex
;
124 struct rb_root path_tree
;
125 struct list_head path_list
;
127 struct ipoib_mcast
*broadcast
;
128 struct list_head multicast_list
;
129 struct rb_root multicast_tree
;
131 struct work_struct pkey_task
;
132 struct work_struct mcast_task
;
133 struct work_struct flush_task
;
134 struct work_struct restart_task
;
135 struct work_struct ah_reap_task
;
137 struct ib_device
*ca
;
146 union ib_gid local_gid
;
150 unsigned int admin_mtu
;
151 unsigned int mcast_mtu
;
153 struct ipoib_buf
*rx_ring
;
156 struct ipoib_buf
*tx_ring
;
159 struct ib_sge tx_sge
;
160 struct ib_send_wr tx_wr
;
162 struct ib_wc ibwc
[IPOIB_NUM_WC
];
164 struct list_head dead_ahs
;
166 struct ib_event_handler event_handler
;
168 struct net_device_stats stats
;
170 struct net_device
*parent
;
171 struct list_head child_intfs
;
172 struct list_head list
;
174 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
175 struct list_head fs_list
;
176 struct dentry
*mcg_dentry
;
181 struct net_device
*dev
;
183 struct list_head list
;
189 struct net_device
*dev
;
190 struct ib_sa_path_rec pathrec
;
192 struct sk_buff_head queue
;
194 struct list_head neigh_list
;
197 struct ib_sa_query
*query
;
198 struct completion done
;
200 struct rb_node rb_node
;
201 struct list_head list
;
206 struct sk_buff_head queue
;
208 struct neighbour
*neighbour
;
210 struct list_head list
;
213 static inline struct ipoib_neigh
**to_ipoib_neigh(struct neighbour
*neigh
)
215 return (struct ipoib_neigh
**) (neigh
->ha
+ 24 -
216 (offsetof(struct neighbour
, ha
) & 4));
219 extern struct workqueue_struct
*ipoib_workqueue
;
223 void ipoib_ib_completion(struct ib_cq
*cq
, void *dev_ptr
);
225 struct ipoib_ah
*ipoib_create_ah(struct net_device
*dev
,
226 struct ib_pd
*pd
, struct ib_ah_attr
*attr
);
227 void ipoib_free_ah(struct kref
*kref
);
228 static inline void ipoib_put_ah(struct ipoib_ah
*ah
)
230 kref_put(&ah
->ref
, ipoib_free_ah
);
233 int ipoib_add_pkey_attr(struct net_device
*dev
);
235 void ipoib_send(struct net_device
*dev
, struct sk_buff
*skb
,
236 struct ipoib_ah
*address
, u32 qpn
);
237 void ipoib_reap_ah(void *dev_ptr
);
239 void ipoib_flush_paths(struct net_device
*dev
);
240 struct ipoib_dev_priv
*ipoib_intf_alloc(const char *format
);
242 int ipoib_ib_dev_init(struct net_device
*dev
, struct ib_device
*ca
, int port
);
243 void ipoib_ib_dev_flush(void *dev
);
244 void ipoib_ib_dev_cleanup(struct net_device
*dev
);
246 int ipoib_ib_dev_open(struct net_device
*dev
);
247 int ipoib_ib_dev_up(struct net_device
*dev
);
248 int ipoib_ib_dev_down(struct net_device
*dev
);
249 int ipoib_ib_dev_stop(struct net_device
*dev
);
251 int ipoib_dev_init(struct net_device
*dev
, struct ib_device
*ca
, int port
);
252 void ipoib_dev_cleanup(struct net_device
*dev
);
254 void ipoib_mcast_join_task(void *dev_ptr
);
255 void ipoib_mcast_send(struct net_device
*dev
, union ib_gid
*mgid
,
256 struct sk_buff
*skb
);
258 void ipoib_mcast_restart_task(void *dev_ptr
);
259 int ipoib_mcast_start_thread(struct net_device
*dev
);
260 int ipoib_mcast_stop_thread(struct net_device
*dev
);
262 void ipoib_mcast_dev_down(struct net_device
*dev
);
263 void ipoib_mcast_dev_flush(struct net_device
*dev
);
265 struct ipoib_mcast_iter
*ipoib_mcast_iter_init(struct net_device
*dev
);
266 void ipoib_mcast_iter_free(struct ipoib_mcast_iter
*iter
);
267 int ipoib_mcast_iter_next(struct ipoib_mcast_iter
*iter
);
268 void ipoib_mcast_iter_read(struct ipoib_mcast_iter
*iter
,
270 unsigned long *created
,
271 unsigned int *queuelen
,
272 unsigned int *complete
,
273 unsigned int *send_only
);
275 int ipoib_mcast_attach(struct net_device
*dev
, u16 mlid
,
277 int ipoib_mcast_detach(struct net_device
*dev
, u16 mlid
,
280 int ipoib_qp_create(struct net_device
*dev
);
281 int ipoib_transport_dev_init(struct net_device
*dev
, struct ib_device
*ca
);
282 void ipoib_transport_dev_cleanup(struct net_device
*dev
);
284 void ipoib_event(struct ib_event_handler
*handler
,
285 struct ib_event
*record
);
287 int ipoib_vlan_add(struct net_device
*pdev
, unsigned short pkey
);
288 int ipoib_vlan_delete(struct net_device
*pdev
, unsigned short pkey
);
290 void ipoib_pkey_poll(void *dev
);
291 int ipoib_pkey_dev_delay_open(struct net_device
*dev
);
293 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
294 int ipoib_create_debug_file(struct net_device
*dev
);
295 void ipoib_delete_debug_file(struct net_device
*dev
);
296 int ipoib_register_debugfs(void);
297 void ipoib_unregister_debugfs(void);
299 static inline int ipoib_create_debug_file(struct net_device
*dev
) { return 0; }
300 static inline void ipoib_delete_debug_file(struct net_device
*dev
) { }
301 static inline int ipoib_register_debugfs(void) { return 0; }
302 static inline void ipoib_unregister_debugfs(void) { }
306 #define ipoib_printk(level, priv, format, arg...) \
307 printk(level "%s: " format, ((struct ipoib_dev_priv *) priv)->dev->name , ## arg)
308 #define ipoib_warn(priv, format, arg...) \
309 ipoib_printk(KERN_WARNING, priv, format , ## arg)
312 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
313 extern int ipoib_debug_level
;
315 #define ipoib_dbg(priv, format, arg...) \
317 if (ipoib_debug_level > 0) \
318 ipoib_printk(KERN_DEBUG, priv, format , ## arg); \
320 #define ipoib_dbg_mcast(priv, format, arg...) \
322 if (mcast_debug_level > 0) \
323 ipoib_printk(KERN_DEBUG, priv, format , ## arg); \
325 #else /* CONFIG_INFINIBAND_IPOIB_DEBUG */
326 #define ipoib_dbg(priv, format, arg...) \
327 do { (void) (priv); } while (0)
328 #define ipoib_dbg_mcast(priv, format, arg...) \
329 do { (void) (priv); } while (0)
330 #endif /* CONFIG_INFINIBAND_IPOIB_DEBUG */
332 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG_DATA
333 #define ipoib_dbg_data(priv, format, arg...) \
335 if (data_debug_level > 0) \
336 ipoib_printk(KERN_DEBUG, priv, format , ## arg); \
338 #else /* CONFIG_INFINIBAND_IPOIB_DEBUG_DATA */
339 #define ipoib_dbg_data(priv, format, arg...) \
340 do { (void) (priv); } while (0)
341 #endif /* CONFIG_INFINIBAND_IPOIB_DEBUG_DATA */
344 #define IPOIB_GID_FMT "%x:%x:%x:%x:%x:%x:%x:%x"
346 #define IPOIB_GID_ARG(gid) be16_to_cpup((__be16 *) ((gid).raw + 0)), \
347 be16_to_cpup((__be16 *) ((gid).raw + 2)), \
348 be16_to_cpup((__be16 *) ((gid).raw + 4)), \
349 be16_to_cpup((__be16 *) ((gid).raw + 6)), \
350 be16_to_cpup((__be16 *) ((gid).raw + 8)), \
351 be16_to_cpup((__be16 *) ((gid).raw + 10)), \
352 be16_to_cpup((__be16 *) ((gid).raw + 12)), \
353 be16_to_cpup((__be16 *) ((gid).raw + 14))
355 #endif /* _IPOIB_H */