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/kref.h>
46 #include <linux/if_infiniband.h>
47 #include <linux/mutex.h>
49 #include <net/neighbour.h>
51 #include <asm/atomic.h>
53 #include <rdma/ib_verbs.h>
54 #include <rdma/ib_pack.h>
55 #include <rdma/ib_sa.h>
60 IPOIB_PACKET_SIZE
= 2048,
61 IPOIB_BUF_SIZE
= IPOIB_PACKET_SIZE
+ IB_GRH_BYTES
,
65 IPOIB_RX_RING_SIZE
= 128,
66 IPOIB_TX_RING_SIZE
= 64,
67 IPOIB_MAX_QUEUE_SIZE
= 8192,
68 IPOIB_MIN_QUEUE_SIZE
= 2,
72 IPOIB_MAX_PATH_REC_QUEUE
= 3,
73 IPOIB_MAX_MCAST_QUEUE
= 3,
75 IPOIB_FLAG_OPER_UP
= 0,
76 IPOIB_FLAG_INITIALIZED
= 1,
77 IPOIB_FLAG_ADMIN_UP
= 2,
78 IPOIB_PKEY_ASSIGNED
= 3,
80 IPOIB_FLAG_SUBINTERFACE
= 5,
82 IPOIB_STOP_REAPER
= 7,
83 IPOIB_MCAST_STARTED
= 8,
85 IPOIB_MAX_BACKOFF_SECONDS
= 16,
87 IPOIB_MCAST_FLAG_FOUND
= 0, /* used in set_multicast_list */
88 IPOIB_MCAST_FLAG_SENDONLY
= 1,
89 IPOIB_MCAST_FLAG_BUSY
= 2, /* joining or already joined */
90 IPOIB_MCAST_FLAG_ATTACHED
= 3,
100 struct ipoib_pseudoheader
{
101 u8 hwaddr
[INFINIBAND_ALEN
];
106 struct ipoib_rx_buf
{
111 struct ipoib_tx_buf
{
113 DECLARE_PCI_UNMAP_ADDR(mapping
)
117 * Device private locking: tx_lock protects members used in TX fast
118 * path (and we use LLTX so upper layers don't do extra locking).
119 * lock protects everything else. lock nests inside of tx_lock (ie
120 * tx_lock must be acquired first if needed).
122 struct ipoib_dev_priv
{
125 struct net_device
*dev
;
129 struct mutex mcast_mutex
;
130 struct mutex vlan_mutex
;
132 struct rb_root path_tree
;
133 struct list_head path_list
;
135 struct ipoib_mcast
*broadcast
;
136 struct list_head multicast_list
;
137 struct rb_root multicast_tree
;
139 struct delayed_work pkey_task
;
140 struct delayed_work mcast_task
;
141 struct work_struct flush_task
;
142 struct work_struct restart_task
;
143 struct delayed_work ah_reap_task
;
145 struct ib_device
*ca
;
154 union ib_gid local_gid
;
158 unsigned int admin_mtu
;
159 unsigned int mcast_mtu
;
161 struct ipoib_rx_buf
*rx_ring
;
164 struct ipoib_tx_buf
*tx_ring
;
167 struct ib_sge tx_sge
;
168 struct ib_send_wr tx_wr
;
170 struct ib_wc ibwc
[IPOIB_NUM_WC
];
172 struct list_head dead_ahs
;
174 struct ib_event_handler event_handler
;
176 struct net_device_stats stats
;
178 struct net_device
*parent
;
179 struct list_head child_intfs
;
180 struct list_head list
;
182 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
183 struct list_head fs_list
;
184 struct dentry
*mcg_dentry
;
185 struct dentry
*path_dentry
;
190 struct net_device
*dev
;
192 struct list_head list
;
198 struct net_device
*dev
;
199 struct ib_sa_path_rec pathrec
;
201 struct sk_buff_head queue
;
203 struct list_head neigh_list
;
206 struct ib_sa_query
*query
;
207 struct completion done
;
209 struct rb_node rb_node
;
210 struct list_head list
;
216 struct sk_buff_head queue
;
218 struct neighbour
*neighbour
;
220 struct list_head list
;
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.
229 static inline struct ipoib_neigh
**to_ipoib_neigh(struct neighbour
*neigh
)
231 return (void*) neigh
+ ALIGN(offsetof(struct neighbour
, ha
) +
232 INFINIBAND_ALEN
, sizeof(void *));
235 struct ipoib_neigh
*ipoib_neigh_alloc(struct neighbour
*neigh
);
236 void ipoib_neigh_free(struct ipoib_neigh
*neigh
);
238 extern struct workqueue_struct
*ipoib_workqueue
;
242 void ipoib_ib_completion(struct ib_cq
*cq
, void *dev_ptr
);
244 struct ipoib_ah
*ipoib_create_ah(struct net_device
*dev
,
245 struct ib_pd
*pd
, struct ib_ah_attr
*attr
);
246 void ipoib_free_ah(struct kref
*kref
);
247 static inline void ipoib_put_ah(struct ipoib_ah
*ah
)
249 kref_put(&ah
->ref
, ipoib_free_ah
);
252 int ipoib_open(struct net_device
*dev
);
253 int ipoib_add_pkey_attr(struct net_device
*dev
);
255 void ipoib_send(struct net_device
*dev
, struct sk_buff
*skb
,
256 struct ipoib_ah
*address
, u32 qpn
);
257 void ipoib_reap_ah(struct work_struct
*work
);
259 void ipoib_flush_paths(struct net_device
*dev
);
260 struct ipoib_dev_priv
*ipoib_intf_alloc(const char *format
);
262 int ipoib_ib_dev_init(struct net_device
*dev
, struct ib_device
*ca
, int port
);
263 void ipoib_ib_dev_flush(struct work_struct
*work
);
264 void ipoib_ib_dev_cleanup(struct net_device
*dev
);
266 int ipoib_ib_dev_open(struct net_device
*dev
);
267 int ipoib_ib_dev_up(struct net_device
*dev
);
268 int ipoib_ib_dev_down(struct net_device
*dev
, int flush
);
269 int ipoib_ib_dev_stop(struct net_device
*dev
);
271 int ipoib_dev_init(struct net_device
*dev
, struct ib_device
*ca
, int port
);
272 void ipoib_dev_cleanup(struct net_device
*dev
);
274 void ipoib_mcast_join_task(struct work_struct
*work
);
275 void ipoib_mcast_send(struct net_device
*dev
, void *mgid
, struct sk_buff
*skb
);
277 void ipoib_mcast_restart_task(struct work_struct
*work
);
278 int ipoib_mcast_start_thread(struct net_device
*dev
);
279 int ipoib_mcast_stop_thread(struct net_device
*dev
, int flush
);
281 void ipoib_mcast_dev_down(struct net_device
*dev
);
282 void ipoib_mcast_dev_flush(struct net_device
*dev
);
284 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
285 struct ipoib_mcast_iter
*ipoib_mcast_iter_init(struct net_device
*dev
);
286 int ipoib_mcast_iter_next(struct ipoib_mcast_iter
*iter
);
287 void ipoib_mcast_iter_read(struct ipoib_mcast_iter
*iter
,
289 unsigned long *created
,
290 unsigned int *queuelen
,
291 unsigned int *complete
,
292 unsigned int *send_only
);
294 struct ipoib_path_iter
*ipoib_path_iter_init(struct net_device
*dev
);
295 int ipoib_path_iter_next(struct ipoib_path_iter
*iter
);
296 void ipoib_path_iter_read(struct ipoib_path_iter
*iter
,
297 struct ipoib_path
*path
);
300 int ipoib_mcast_attach(struct net_device
*dev
, u16 mlid
,
302 int ipoib_mcast_detach(struct net_device
*dev
, u16 mlid
,
305 int ipoib_init_qp(struct net_device
*dev
);
306 int ipoib_transport_dev_init(struct net_device
*dev
, struct ib_device
*ca
);
307 void ipoib_transport_dev_cleanup(struct net_device
*dev
);
309 void ipoib_event(struct ib_event_handler
*handler
,
310 struct ib_event
*record
);
312 int ipoib_vlan_add(struct net_device
*pdev
, unsigned short pkey
);
313 int ipoib_vlan_delete(struct net_device
*pdev
, unsigned short pkey
);
315 void ipoib_pkey_poll(struct work_struct
*work
);
316 int ipoib_pkey_dev_delay_open(struct net_device
*dev
);
318 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
319 void ipoib_create_debug_files(struct net_device
*dev
);
320 void ipoib_delete_debug_files(struct net_device
*dev
);
321 int ipoib_register_debugfs(void);
322 void ipoib_unregister_debugfs(void);
324 static inline void ipoib_create_debug_files(struct net_device
*dev
) { }
325 static inline void ipoib_delete_debug_files(struct net_device
*dev
) { }
326 static inline int ipoib_register_debugfs(void) { return 0; }
327 static inline void ipoib_unregister_debugfs(void) { }
331 #define ipoib_printk(level, priv, format, arg...) \
332 printk(level "%s: " format, ((struct ipoib_dev_priv *) priv)->dev->name , ## arg)
333 #define ipoib_warn(priv, format, arg...) \
334 ipoib_printk(KERN_WARNING, priv, format , ## arg)
336 extern int ipoib_sendq_size
;
337 extern int ipoib_recvq_size
;
339 extern struct ib_sa_client ipoib_sa_client
;
341 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
342 extern int ipoib_debug_level
;
344 #define ipoib_dbg(priv, format, arg...) \
346 if (ipoib_debug_level > 0) \
347 ipoib_printk(KERN_DEBUG, priv, format , ## arg); \
349 #define ipoib_dbg_mcast(priv, format, arg...) \
351 if (mcast_debug_level > 0) \
352 ipoib_printk(KERN_DEBUG, priv, format , ## arg); \
354 #else /* CONFIG_INFINIBAND_IPOIB_DEBUG */
355 #define ipoib_dbg(priv, format, arg...) \
356 do { (void) (priv); } while (0)
357 #define ipoib_dbg_mcast(priv, format, arg...) \
358 do { (void) (priv); } while (0)
359 #endif /* CONFIG_INFINIBAND_IPOIB_DEBUG */
361 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG_DATA
362 #define ipoib_dbg_data(priv, format, arg...) \
364 if (data_debug_level > 0) \
365 ipoib_printk(KERN_DEBUG, priv, format , ## arg); \
367 #else /* CONFIG_INFINIBAND_IPOIB_DEBUG_DATA */
368 #define ipoib_dbg_data(priv, format, arg...) \
369 do { (void) (priv); } while (0)
370 #endif /* CONFIG_INFINIBAND_IPOIB_DEBUG_DATA */
373 #define IPOIB_GID_FMT "%2.2x%2.2x:%2.2x%2.2x:%2.2x%2.2x:%2.2x%2.2x:" \
374 "%2.2x%2.2x:%2.2x%2.2x:%2.2x%2.2x:%2.2x%2.2x"
376 #define IPOIB_GID_RAW_ARG(gid) ((u8 *)(gid))[0], \
393 #define IPOIB_GID_ARG(gid) IPOIB_GID_RAW_ARG((gid).raw)
395 #endif /* _IPOIB_H */