2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32 * $Id: ipoib.h 1358 2004-12-17 22:00:11Z roland $
38 #include <linux/list.h>
39 #include <linux/skbuff.h>
40 #include <linux/netdevice.h>
41 #include <linux/workqueue.h>
42 #include <linux/pci.h>
43 #include <linux/config.h>
44 #include <linux/kref.h>
45 #include <linux/if_infiniband.h>
47 #include <net/neighbour.h>
49 #include <asm/atomic.h>
50 #include <asm/semaphore.h>
59 IPOIB_PACKET_SIZE
= 2048,
60 IPOIB_BUF_SIZE
= IPOIB_PACKET_SIZE
+ IB_GRH_BYTES
,
64 IPOIB_RX_RING_SIZE
= 128,
65 IPOIB_TX_RING_SIZE
= 64,
69 IPOIB_MAX_PATH_REC_QUEUE
= 3,
70 IPOIB_MAX_MCAST_QUEUE
= 3,
72 IPOIB_FLAG_OPER_UP
= 0,
73 IPOIB_FLAG_ADMIN_UP
= 1,
74 IPOIB_PKEY_ASSIGNED
= 2,
76 IPOIB_FLAG_SUBINTERFACE
= 4,
78 IPOIB_STOP_REAPER
= 6,
80 IPOIB_MAX_BACKOFF_SECONDS
= 16,
82 IPOIB_MCAST_FLAG_FOUND
= 0, /* used in set_multicast_list */
83 IPOIB_MCAST_FLAG_SENDONLY
= 1,
84 IPOIB_MCAST_FLAG_BUSY
= 2, /* joining or already joined */
85 IPOIB_MCAST_FLAG_ATTACHED
= 3,
95 struct ipoib_pseudoheader
{
96 u8 hwaddr
[INFINIBAND_ALEN
];
103 DECLARE_PCI_UNMAP_ADDR(mapping
)
107 * Device private locking: tx_lock protects members used in TX fast
108 * path (and we use LLTX so upper layers don't do extra locking).
109 * lock protects everything else. lock nests inside of tx_lock (ie
110 * tx_lock must be acquired first if needed).
112 struct ipoib_dev_priv
{
115 struct net_device
*dev
;
119 struct semaphore mcast_mutex
;
120 struct semaphore vlan_mutex
;
122 struct rb_root path_tree
;
123 struct list_head path_list
;
125 struct ipoib_mcast
*broadcast
;
126 struct list_head multicast_list
;
127 struct rb_root multicast_tree
;
129 struct work_struct pkey_task
;
130 struct work_struct mcast_task
;
131 struct work_struct flush_task
;
132 struct work_struct restart_task
;
133 struct work_struct ah_reap_task
;
135 struct ib_device
*ca
;
144 union ib_gid local_gid
;
148 unsigned int admin_mtu
;
149 unsigned int mcast_mtu
;
151 struct ipoib_buf
*rx_ring
;
154 struct ipoib_buf
*tx_ring
;
157 struct ib_sge tx_sge
;
158 struct ib_send_wr tx_wr
;
160 struct ib_wc ibwc
[IPOIB_NUM_WC
];
162 struct list_head dead_ahs
;
164 struct ib_event_handler event_handler
;
166 struct net_device_stats stats
;
168 struct net_device
*parent
;
169 struct list_head child_intfs
;
170 struct list_head list
;
172 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
173 struct list_head fs_list
;
174 struct dentry
*mcg_dentry
;
179 struct net_device
*dev
;
181 struct list_head list
;
187 struct net_device
*dev
;
188 struct ib_sa_path_rec pathrec
;
190 struct sk_buff_head queue
;
192 struct list_head neigh_list
;
195 struct ib_sa_query
*query
;
196 struct completion done
;
198 struct rb_node rb_node
;
199 struct list_head list
;
204 struct sk_buff_head queue
;
206 struct neighbour
*neighbour
;
208 struct list_head list
;
211 static inline struct ipoib_neigh
**to_ipoib_neigh(struct neighbour
*neigh
)
213 return (struct ipoib_neigh
**) (neigh
->ha
+ 24 -
214 (offsetof(struct neighbour
, ha
) & 4));
217 extern struct workqueue_struct
*ipoib_workqueue
;
221 void ipoib_ib_completion(struct ib_cq
*cq
, void *dev_ptr
);
223 struct ipoib_ah
*ipoib_create_ah(struct net_device
*dev
,
224 struct ib_pd
*pd
, struct ib_ah_attr
*attr
);
225 void ipoib_free_ah(struct kref
*kref
);
226 static inline void ipoib_put_ah(struct ipoib_ah
*ah
)
228 kref_put(&ah
->ref
, ipoib_free_ah
);
231 int ipoib_add_pkey_attr(struct net_device
*dev
);
233 void ipoib_send(struct net_device
*dev
, struct sk_buff
*skb
,
234 struct ipoib_ah
*address
, u32 qpn
);
235 void ipoib_reap_ah(void *dev_ptr
);
237 void ipoib_flush_paths(struct net_device
*dev
);
238 struct ipoib_dev_priv
*ipoib_intf_alloc(const char *format
);
240 int ipoib_ib_dev_init(struct net_device
*dev
, struct ib_device
*ca
, int port
);
241 void ipoib_ib_dev_flush(void *dev
);
242 void ipoib_ib_dev_cleanup(struct net_device
*dev
);
244 int ipoib_ib_dev_open(struct net_device
*dev
);
245 int ipoib_ib_dev_up(struct net_device
*dev
);
246 int ipoib_ib_dev_down(struct net_device
*dev
);
247 int ipoib_ib_dev_stop(struct net_device
*dev
);
249 int ipoib_dev_init(struct net_device
*dev
, struct ib_device
*ca
, int port
);
250 void ipoib_dev_cleanup(struct net_device
*dev
);
252 void ipoib_mcast_join_task(void *dev_ptr
);
253 void ipoib_mcast_send(struct net_device
*dev
, union ib_gid
*mgid
,
254 struct sk_buff
*skb
);
256 void ipoib_mcast_restart_task(void *dev_ptr
);
257 int ipoib_mcast_start_thread(struct net_device
*dev
);
258 int ipoib_mcast_stop_thread(struct net_device
*dev
);
260 void ipoib_mcast_dev_down(struct net_device
*dev
);
261 void ipoib_mcast_dev_flush(struct net_device
*dev
);
263 struct ipoib_mcast_iter
*ipoib_mcast_iter_init(struct net_device
*dev
);
264 void ipoib_mcast_iter_free(struct ipoib_mcast_iter
*iter
);
265 int ipoib_mcast_iter_next(struct ipoib_mcast_iter
*iter
);
266 void ipoib_mcast_iter_read(struct ipoib_mcast_iter
*iter
,
268 unsigned long *created
,
269 unsigned int *queuelen
,
270 unsigned int *complete
,
271 unsigned int *send_only
);
273 int ipoib_mcast_attach(struct net_device
*dev
, u16 mlid
,
275 int ipoib_mcast_detach(struct net_device
*dev
, u16 mlid
,
278 int ipoib_qp_create(struct net_device
*dev
);
279 int ipoib_transport_dev_init(struct net_device
*dev
, struct ib_device
*ca
);
280 void ipoib_transport_dev_cleanup(struct net_device
*dev
);
282 void ipoib_event(struct ib_event_handler
*handler
,
283 struct ib_event
*record
);
285 int ipoib_vlan_add(struct net_device
*pdev
, unsigned short pkey
);
286 int ipoib_vlan_delete(struct net_device
*pdev
, unsigned short pkey
);
288 void ipoib_pkey_poll(void *dev
);
289 int ipoib_pkey_dev_delay_open(struct net_device
*dev
);
291 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
292 int ipoib_create_debug_file(struct net_device
*dev
);
293 void ipoib_delete_debug_file(struct net_device
*dev
);
294 int ipoib_register_debugfs(void);
295 void ipoib_unregister_debugfs(void);
297 static inline int ipoib_create_debug_file(struct net_device
*dev
) { return 0; }
298 static inline void ipoib_delete_debug_file(struct net_device
*dev
) { }
299 static inline int ipoib_register_debugfs(void) { return 0; }
300 static inline void ipoib_unregister_debugfs(void) { }
304 #define ipoib_printk(level, priv, format, arg...) \
305 printk(level "%s: " format, ((struct ipoib_dev_priv *) priv)->dev->name , ## arg)
306 #define ipoib_warn(priv, format, arg...) \
307 ipoib_printk(KERN_WARNING, priv, format , ## arg)
310 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
311 extern int ipoib_debug_level
;
313 #define ipoib_dbg(priv, format, arg...) \
315 if (ipoib_debug_level > 0) \
316 ipoib_printk(KERN_DEBUG, priv, format , ## arg); \
318 #define ipoib_dbg_mcast(priv, format, arg...) \
320 if (mcast_debug_level > 0) \
321 ipoib_printk(KERN_DEBUG, priv, format , ## arg); \
323 #else /* CONFIG_INFINIBAND_IPOIB_DEBUG */
324 #define ipoib_dbg(priv, format, arg...) \
325 do { (void) (priv); } while (0)
326 #define ipoib_dbg_mcast(priv, format, arg...) \
327 do { (void) (priv); } while (0)
328 #endif /* CONFIG_INFINIBAND_IPOIB_DEBUG */
330 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG_DATA
331 #define ipoib_dbg_data(priv, format, arg...) \
333 if (data_debug_level > 0) \
334 ipoib_printk(KERN_DEBUG, priv, format , ## arg); \
336 #else /* CONFIG_INFINIBAND_IPOIB_DEBUG_DATA */
337 #define ipoib_dbg_data(priv, format, arg...) \
338 do { (void) (priv); } while (0)
339 #endif /* CONFIG_INFINIBAND_IPOIB_DEBUG_DATA */
342 #define IPOIB_GID_FMT "%x:%x:%x:%x:%x:%x:%x:%x"
344 #define IPOIB_GID_ARG(gid) be16_to_cpup((__be16 *) ((gid).raw + 0)), \
345 be16_to_cpup((__be16 *) ((gid).raw + 2)), \
346 be16_to_cpup((__be16 *) ((gid).raw + 4)), \
347 be16_to_cpup((__be16 *) ((gid).raw + 6)), \
348 be16_to_cpup((__be16 *) ((gid).raw + 8)), \
349 be16_to_cpup((__be16 *) ((gid).raw + 10)), \
350 be16_to_cpup((__be16 *) ((gid).raw + 12)), \
351 be16_to_cpup((__be16 *) ((gid).raw + 14))
353 #endif /* _IPOIB_H */