]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved. | |
2a1d9b7f RD |
3 | * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved. |
4 | * Copyright (c) 2004 Voltaire, Inc. All rights reserved. | |
1da177e4 LT |
5 | * |
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> | |
48 | ||
49 | #include <net/neighbour.h> | |
50 | ||
51 | #include <asm/atomic.h> | |
52 | #include <asm/semaphore.h> | |
53 | ||
a4d61e84 RD |
54 | #include <rdma/ib_verbs.h> |
55 | #include <rdma/ib_pack.h> | |
56 | #include <rdma/ib_sa.h> | |
1da177e4 LT |
57 | |
58 | /* constants */ | |
59 | ||
60 | enum { | |
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, | |
68 | ||
69 | IPOIB_NUM_WC = 4, | |
70 | ||
71 | IPOIB_MAX_PATH_REC_QUEUE = 3, | |
72 | IPOIB_MAX_MCAST_QUEUE = 3, | |
73 | ||
74 | IPOIB_FLAG_OPER_UP = 0, | |
75 | IPOIB_FLAG_ADMIN_UP = 1, | |
76 | IPOIB_PKEY_ASSIGNED = 2, | |
77 | IPOIB_PKEY_STOP = 3, | |
78 | IPOIB_FLAG_SUBINTERFACE = 4, | |
79 | IPOIB_MCAST_RUN = 5, | |
80 | IPOIB_STOP_REAPER = 6, | |
81 | ||
82 | IPOIB_MAX_BACKOFF_SECONDS = 16, | |
83 | ||
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, | |
88 | }; | |
89 | ||
90 | /* structs */ | |
91 | ||
92 | struct ipoib_header { | |
97f52eb4 SH |
93 | __be16 proto; |
94 | u16 reserved; | |
1da177e4 LT |
95 | }; |
96 | ||
97 | struct ipoib_pseudoheader { | |
98 | u8 hwaddr[INFINIBAND_ALEN]; | |
99 | }; | |
100 | ||
101 | struct ipoib_mcast; | |
102 | ||
103 | struct ipoib_buf { | |
104 | struct sk_buff *skb; | |
105 | DECLARE_PCI_UNMAP_ADDR(mapping) | |
106 | }; | |
107 | ||
108 | /* | |
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). | |
113 | */ | |
114 | struct ipoib_dev_priv { | |
115 | spinlock_t lock; | |
116 | ||
117 | struct net_device *dev; | |
118 | ||
119 | unsigned long flags; | |
120 | ||
121 | struct semaphore mcast_mutex; | |
122 | struct semaphore vlan_mutex; | |
123 | ||
124 | struct rb_root path_tree; | |
125 | struct list_head path_list; | |
126 | ||
127 | struct ipoib_mcast *broadcast; | |
128 | struct list_head multicast_list; | |
129 | struct rb_root multicast_tree; | |
130 | ||
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; | |
136 | ||
137 | struct ib_device *ca; | |
138 | u8 port; | |
139 | u16 pkey; | |
140 | struct ib_pd *pd; | |
141 | struct ib_mr *mr; | |
142 | struct ib_cq *cq; | |
143 | struct ib_qp *qp; | |
144 | u32 qkey; | |
145 | ||
146 | union ib_gid local_gid; | |
147 | u16 local_lid; | |
148 | u8 local_rate; | |
149 | ||
150 | unsigned int admin_mtu; | |
151 | unsigned int mcast_mtu; | |
152 | ||
153 | struct ipoib_buf *rx_ring; | |
154 | ||
155 | spinlock_t tx_lock; | |
156 | struct ipoib_buf *tx_ring; | |
157 | unsigned tx_head; | |
158 | unsigned tx_tail; | |
159 | struct ib_sge tx_sge; | |
160 | struct ib_send_wr tx_wr; | |
161 | ||
162 | struct ib_wc ibwc[IPOIB_NUM_WC]; | |
163 | ||
164 | struct list_head dead_ahs; | |
165 | ||
166 | struct ib_event_handler event_handler; | |
167 | ||
168 | struct net_device_stats stats; | |
169 | ||
170 | struct net_device *parent; | |
171 | struct list_head child_intfs; | |
172 | struct list_head list; | |
173 | ||
174 | #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG | |
175 | struct list_head fs_list; | |
176 | struct dentry *mcg_dentry; | |
177 | #endif | |
178 | }; | |
179 | ||
180 | struct ipoib_ah { | |
181 | struct net_device *dev; | |
182 | struct ib_ah *ah; | |
183 | struct list_head list; | |
184 | struct kref ref; | |
185 | unsigned last_send; | |
186 | }; | |
187 | ||
188 | struct ipoib_path { | |
189 | struct net_device *dev; | |
190 | struct ib_sa_path_rec pathrec; | |
191 | struct ipoib_ah *ah; | |
192 | struct sk_buff_head queue; | |
193 | ||
194 | struct list_head neigh_list; | |
195 | ||
196 | int query_id; | |
197 | struct ib_sa_query *query; | |
198 | struct completion done; | |
199 | ||
200 | struct rb_node rb_node; | |
201 | struct list_head list; | |
202 | }; | |
203 | ||
204 | struct ipoib_neigh { | |
205 | struct ipoib_ah *ah; | |
206 | struct sk_buff_head queue; | |
207 | ||
208 | struct neighbour *neighbour; | |
209 | ||
210 | struct list_head list; | |
211 | }; | |
212 | ||
213 | static inline struct ipoib_neigh **to_ipoib_neigh(struct neighbour *neigh) | |
214 | { | |
215 | return (struct ipoib_neigh **) (neigh->ha + 24 - | |
216 | (offsetof(struct neighbour, ha) & 4)); | |
217 | } | |
218 | ||
219 | extern struct workqueue_struct *ipoib_workqueue; | |
220 | ||
221 | /* functions */ | |
222 | ||
223 | void ipoib_ib_completion(struct ib_cq *cq, void *dev_ptr); | |
224 | ||
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) | |
229 | { | |
230 | kref_put(&ah->ref, ipoib_free_ah); | |
231 | } | |
232 | ||
233 | int ipoib_add_pkey_attr(struct net_device *dev); | |
234 | ||
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); | |
238 | ||
239 | void ipoib_flush_paths(struct net_device *dev); | |
240 | struct ipoib_dev_priv *ipoib_intf_alloc(const char *format); | |
241 | ||
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); | |
245 | ||
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); | |
250 | ||
251 | int ipoib_dev_init(struct net_device *dev, struct ib_device *ca, int port); | |
252 | void ipoib_dev_cleanup(struct net_device *dev); | |
253 | ||
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); | |
257 | ||
258 | void ipoib_mcast_restart_task(void *dev_ptr); | |
259 | int ipoib_mcast_start_thread(struct net_device *dev); | |
8d2cae06 | 260 | int ipoib_mcast_stop_thread(struct net_device *dev, int flush); |
1da177e4 LT |
261 | |
262 | void ipoib_mcast_dev_down(struct net_device *dev); | |
263 | void ipoib_mcast_dev_flush(struct net_device *dev); | |
264 | ||
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, | |
269 | union ib_gid *gid, | |
270 | unsigned long *created, | |
271 | unsigned int *queuelen, | |
272 | unsigned int *complete, | |
273 | unsigned int *send_only); | |
274 | ||
275 | int ipoib_mcast_attach(struct net_device *dev, u16 mlid, | |
276 | union ib_gid *mgid); | |
277 | int ipoib_mcast_detach(struct net_device *dev, u16 mlid, | |
278 | union ib_gid *mgid); | |
279 | ||
5b6810e0 | 280 | int ipoib_init_qp(struct net_device *dev); |
1da177e4 LT |
281 | int ipoib_transport_dev_init(struct net_device *dev, struct ib_device *ca); |
282 | void ipoib_transport_dev_cleanup(struct net_device *dev); | |
283 | ||
284 | void ipoib_event(struct ib_event_handler *handler, | |
285 | struct ib_event *record); | |
286 | ||
287 | int ipoib_vlan_add(struct net_device *pdev, unsigned short pkey); | |
288 | int ipoib_vlan_delete(struct net_device *pdev, unsigned short pkey); | |
289 | ||
290 | void ipoib_pkey_poll(void *dev); | |
291 | int ipoib_pkey_dev_delay_open(struct net_device *dev); | |
292 | ||
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); | |
298 | #else | |
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) { } | |
303 | #endif | |
304 | ||
305 | ||
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) | |
310 | ||
311 | ||
312 | #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG | |
313 | extern int ipoib_debug_level; | |
314 | ||
315 | #define ipoib_dbg(priv, format, arg...) \ | |
316 | do { \ | |
317 | if (ipoib_debug_level > 0) \ | |
318 | ipoib_printk(KERN_DEBUG, priv, format , ## arg); \ | |
319 | } while (0) | |
320 | #define ipoib_dbg_mcast(priv, format, arg...) \ | |
321 | do { \ | |
322 | if (mcast_debug_level > 0) \ | |
323 | ipoib_printk(KERN_DEBUG, priv, format , ## arg); \ | |
324 | } while (0) | |
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 */ | |
331 | ||
332 | #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG_DATA | |
333 | #define ipoib_dbg_data(priv, format, arg...) \ | |
334 | do { \ | |
335 | if (data_debug_level > 0) \ | |
336 | ipoib_printk(KERN_DEBUG, priv, format , ## arg); \ | |
337 | } while (0) | |
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 */ | |
342 | ||
343 | ||
344 | #define IPOIB_GID_FMT "%x:%x:%x:%x:%x:%x:%x:%x" | |
345 | ||
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)) | |
354 | ||
355 | #endif /* _IPOIB_H */ |