]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/infiniband/ulp/ipoib/ipoib.h
WorkStruct: make allyesconfig
[mirror_ubuntu-bionic-kernel.git] / drivers / infiniband / ulp / ipoib / ipoib.h
CommitLineData
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>
1da177e4
LT
45#include <linux/kref.h>
46#include <linux/if_infiniband.h>
95ed644f 47#include <linux/mutex.h>
1da177e4
LT
48
49#include <net/neighbour.h>
50
51#include <asm/atomic.h>
1da177e4 52
a4d61e84
RD
53#include <rdma/ib_verbs.h>
54#include <rdma/ib_pack.h>
55#include <rdma/ib_sa.h>
1da177e4
LT
56
57/* constants */
58
59enum {
60 IPOIB_PACKET_SIZE = 2048,
61 IPOIB_BUF_SIZE = IPOIB_PACKET_SIZE + IB_GRH_BYTES,
62
63 IPOIB_ENCAP_LEN = 4,
64
65 IPOIB_RX_RING_SIZE = 128,
66 IPOIB_TX_RING_SIZE = 64,
0f485251
SM
67 IPOIB_MAX_QUEUE_SIZE = 8192,
68 IPOIB_MIN_QUEUE_SIZE = 2,
1da177e4
LT
69
70 IPOIB_NUM_WC = 4,
71
72 IPOIB_MAX_PATH_REC_QUEUE = 3,
73 IPOIB_MAX_MCAST_QUEUE = 3,
74
75 IPOIB_FLAG_OPER_UP = 0,
7a343d4c
LA
76 IPOIB_FLAG_INITIALIZED = 1,
77 IPOIB_FLAG_ADMIN_UP = 2,
78 IPOIB_PKEY_ASSIGNED = 3,
79 IPOIB_PKEY_STOP = 4,
80 IPOIB_FLAG_SUBINTERFACE = 5,
81 IPOIB_MCAST_RUN = 6,
82 IPOIB_STOP_REAPER = 7,
83 IPOIB_MCAST_STARTED = 8,
1da177e4
LT
84
85 IPOIB_MAX_BACKOFF_SECONDS = 16,
86
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,
91};
92
93/* structs */
94
95struct ipoib_header {
97f52eb4
SH
96 __be16 proto;
97 u16 reserved;
1da177e4
LT
98};
99
100struct ipoib_pseudoheader {
101 u8 hwaddr[INFINIBAND_ALEN];
102};
103
104struct ipoib_mcast;
105
1993d683
RD
106struct ipoib_rx_buf {
107 struct sk_buff *skb;
108 dma_addr_t mapping;
109};
110
111struct ipoib_tx_buf {
1da177e4
LT
112 struct sk_buff *skb;
113 DECLARE_PCI_UNMAP_ADDR(mapping)
114};
115
116/*
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).
121 */
122struct ipoib_dev_priv {
123 spinlock_t lock;
124
125 struct net_device *dev;
126
127 unsigned long flags;
128
95ed644f
IM
129 struct mutex mcast_mutex;
130 struct mutex vlan_mutex;
1da177e4
LT
131
132 struct rb_root path_tree;
133 struct list_head path_list;
134
135 struct ipoib_mcast *broadcast;
136 struct list_head multicast_list;
137 struct rb_root multicast_tree;
138
c4028958
DH
139 struct delayed_work pkey_task;
140 struct delayed_work mcast_task;
1da177e4
LT
141 struct work_struct flush_task;
142 struct work_struct restart_task;
c4028958 143 struct delayed_work ah_reap_task;
1da177e4
LT
144
145 struct ib_device *ca;
146 u8 port;
147 u16 pkey;
148 struct ib_pd *pd;
149 struct ib_mr *mr;
150 struct ib_cq *cq;
151 struct ib_qp *qp;
152 u32 qkey;
153
154 union ib_gid local_gid;
155 u16 local_lid;
156 u8 local_rate;
157
158 unsigned int admin_mtu;
159 unsigned int mcast_mtu;
160
1993d683 161 struct ipoib_rx_buf *rx_ring;
1da177e4 162
1993d683
RD
163 spinlock_t tx_lock;
164 struct ipoib_tx_buf *tx_ring;
165 unsigned tx_head;
166 unsigned tx_tail;
167 struct ib_sge tx_sge;
168 struct ib_send_wr tx_wr;
1da177e4
LT
169
170 struct ib_wc ibwc[IPOIB_NUM_WC];
171
172 struct list_head dead_ahs;
173
174 struct ib_event_handler event_handler;
175
176 struct net_device_stats stats;
177
178 struct net_device *parent;
179 struct list_head child_intfs;
180 struct list_head list;
181
182#ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
183 struct list_head fs_list;
184 struct dentry *mcg_dentry;
1732b0ef 185 struct dentry *path_dentry;
1da177e4
LT
186#endif
187};
188
189struct ipoib_ah {
190 struct net_device *dev;
191 struct ib_ah *ah;
192 struct list_head list;
193 struct kref ref;
194 unsigned last_send;
195};
196
197struct ipoib_path {
198 struct net_device *dev;
199 struct ib_sa_path_rec pathrec;
200 struct ipoib_ah *ah;
201 struct sk_buff_head queue;
202
203 struct list_head neigh_list;
204
205 int query_id;
206 struct ib_sa_query *query;
207 struct completion done;
208
209 struct rb_node rb_node;
210 struct list_head list;
211};
212
213struct ipoib_neigh {
214 struct ipoib_ah *ah;
8a7f7521 215 union ib_gid dgid;
1da177e4
LT
216 struct sk_buff_head queue;
217
218 struct neighbour *neighbour;
219
220 struct list_head list;
221};
222
44af79f9
MT
223/*
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.
228 */
1da177e4
LT
229static inline struct ipoib_neigh **to_ipoib_neigh(struct neighbour *neigh)
230{
44af79f9
MT
231 return (void*) neigh + ALIGN(offsetof(struct neighbour, ha) +
232 INFINIBAND_ALEN, sizeof(void *));
1da177e4
LT
233}
234
d2e0655e
MT
235struct ipoib_neigh *ipoib_neigh_alloc(struct neighbour *neigh);
236void ipoib_neigh_free(struct ipoib_neigh *neigh);
237
1da177e4
LT
238extern struct workqueue_struct *ipoib_workqueue;
239
240/* functions */
241
242void ipoib_ib_completion(struct ib_cq *cq, void *dev_ptr);
243
244struct ipoib_ah *ipoib_create_ah(struct net_device *dev,
245 struct ib_pd *pd, struct ib_ah_attr *attr);
246void ipoib_free_ah(struct kref *kref);
247static inline void ipoib_put_ah(struct ipoib_ah *ah)
248{
249 kref_put(&ah->ref, ipoib_free_ah);
250}
251
8ae5a8a2 252int ipoib_open(struct net_device *dev);
1da177e4
LT
253int ipoib_add_pkey_attr(struct net_device *dev);
254
255void ipoib_send(struct net_device *dev, struct sk_buff *skb,
256 struct ipoib_ah *address, u32 qpn);
c4028958 257void ipoib_reap_ah(struct work_struct *work);
1da177e4
LT
258
259void ipoib_flush_paths(struct net_device *dev);
260struct ipoib_dev_priv *ipoib_intf_alloc(const char *format);
261
262int ipoib_ib_dev_init(struct net_device *dev, struct ib_device *ca, int port);
c4028958 263void ipoib_ib_dev_flush(struct work_struct *work);
1da177e4
LT
264void ipoib_ib_dev_cleanup(struct net_device *dev);
265
266int ipoib_ib_dev_open(struct net_device *dev);
267int ipoib_ib_dev_up(struct net_device *dev);
0b3ea082 268int ipoib_ib_dev_down(struct net_device *dev, int flush);
1da177e4
LT
269int ipoib_ib_dev_stop(struct net_device *dev);
270
271int ipoib_dev_init(struct net_device *dev, struct ib_device *ca, int port);
272void ipoib_dev_cleanup(struct net_device *dev);
273
c4028958 274void ipoib_mcast_join_task(struct work_struct *work);
37c22a77 275void ipoib_mcast_send(struct net_device *dev, void *mgid, struct sk_buff *skb);
1da177e4 276
c4028958 277void ipoib_mcast_restart_task(struct work_struct *work);
1da177e4 278int ipoib_mcast_start_thread(struct net_device *dev);
8d2cae06 279int ipoib_mcast_stop_thread(struct net_device *dev, int flush);
1da177e4
LT
280
281void ipoib_mcast_dev_down(struct net_device *dev);
282void ipoib_mcast_dev_flush(struct net_device *dev);
283
8ae5a8a2 284#ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
1da177e4 285struct ipoib_mcast_iter *ipoib_mcast_iter_init(struct net_device *dev);
1da177e4
LT
286int ipoib_mcast_iter_next(struct ipoib_mcast_iter *iter);
287void ipoib_mcast_iter_read(struct ipoib_mcast_iter *iter,
288 union ib_gid *gid,
289 unsigned long *created,
290 unsigned int *queuelen,
291 unsigned int *complete,
292 unsigned int *send_only);
1732b0ef
RD
293
294struct ipoib_path_iter *ipoib_path_iter_init(struct net_device *dev);
295int ipoib_path_iter_next(struct ipoib_path_iter *iter);
296void ipoib_path_iter_read(struct ipoib_path_iter *iter,
297 struct ipoib_path *path);
8ae5a8a2 298#endif
1da177e4
LT
299
300int ipoib_mcast_attach(struct net_device *dev, u16 mlid,
301 union ib_gid *mgid);
302int ipoib_mcast_detach(struct net_device *dev, u16 mlid,
303 union ib_gid *mgid);
304
5b6810e0 305int ipoib_init_qp(struct net_device *dev);
1da177e4
LT
306int ipoib_transport_dev_init(struct net_device *dev, struct ib_device *ca);
307void ipoib_transport_dev_cleanup(struct net_device *dev);
308
309void ipoib_event(struct ib_event_handler *handler,
310 struct ib_event *record);
311
312int ipoib_vlan_add(struct net_device *pdev, unsigned short pkey);
313int ipoib_vlan_delete(struct net_device *pdev, unsigned short pkey);
314
c4028958 315void ipoib_pkey_poll(struct work_struct *work);
1da177e4
LT
316int ipoib_pkey_dev_delay_open(struct net_device *dev);
317
318#ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
1732b0ef
RD
319void ipoib_create_debug_files(struct net_device *dev);
320void ipoib_delete_debug_files(struct net_device *dev);
1da177e4
LT
321int ipoib_register_debugfs(void);
322void ipoib_unregister_debugfs(void);
323#else
1732b0ef
RD
324static inline void ipoib_create_debug_files(struct net_device *dev) { }
325static inline void ipoib_delete_debug_files(struct net_device *dev) { }
1da177e4
LT
326static inline int ipoib_register_debugfs(void) { return 0; }
327static inline void ipoib_unregister_debugfs(void) { }
328#endif
329
330
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)
335
0f485251
SM
336extern int ipoib_sendq_size;
337extern int ipoib_recvq_size;
1da177e4 338
c1a0b23b
MT
339extern struct ib_sa_client ipoib_sa_client;
340
1da177e4
LT
341#ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
342extern int ipoib_debug_level;
343
344#define ipoib_dbg(priv, format, arg...) \
345 do { \
346 if (ipoib_debug_level > 0) \
347 ipoib_printk(KERN_DEBUG, priv, format , ## arg); \
348 } while (0)
349#define ipoib_dbg_mcast(priv, format, arg...) \
350 do { \
351 if (mcast_debug_level > 0) \
352 ipoib_printk(KERN_DEBUG, priv, format , ## arg); \
353 } while (0)
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 */
360
361#ifdef CONFIG_INFINIBAND_IPOIB_DEBUG_DATA
362#define ipoib_dbg_data(priv, format, arg...) \
363 do { \
364 if (data_debug_level > 0) \
365 ipoib_printk(KERN_DEBUG, priv, format , ## arg); \
366 } while (0)
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 */
371
372
37c22a77
JM
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"
375
376#define IPOIB_GID_RAW_ARG(gid) ((u8 *)(gid))[0], \
377 ((u8 *)(gid))[1], \
378 ((u8 *)(gid))[2], \
379 ((u8 *)(gid))[3], \
380 ((u8 *)(gid))[4], \
381 ((u8 *)(gid))[5], \
382 ((u8 *)(gid))[6], \
383 ((u8 *)(gid))[7], \
384 ((u8 *)(gid))[8], \
385 ((u8 *)(gid))[9], \
386 ((u8 *)(gid))[10],\
387 ((u8 *)(gid))[11],\
388 ((u8 *)(gid))[12],\
389 ((u8 *)(gid))[13],\
390 ((u8 *)(gid))[14],\
391 ((u8 *)(gid))[15]
392
393#define IPOIB_GID_ARG(gid) IPOIB_GID_RAW_ARG((gid).raw)
1da177e4
LT
394
395#endif /* _IPOIB_H */