xref: /freebsd/sys/ofed/drivers/infiniband/ulp/ipoib/ipoib.h (revision fe75646a0234a261c0013bf1840fdac4acaf0cec)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0
3  *
4  * Copyright (c) 2004, 2005 Topspin Communications.  All rights reserved.
5  * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
6  * Copyright (c) 2004 Voltaire, Inc. All rights reserved.
7  *
8  * This software is available to you under a choice of one of two
9  * licenses.  You may choose to be licensed under the terms of the GNU
10  * General Public License (GPL) Version 2, available from the file
11  * COPYING in the main directory of this source tree, or the
12  * OpenIB.org BSD license below:
13  *
14  *     Redistribution and use in source and binary forms, with or
15  *     without modification, are permitted provided that the following
16  *     conditions are met:
17  *
18  *      - Redistributions of source code must retain the above
19  *        copyright notice, this list of conditions and the following
20  *        disclaimer.
21  *
22  *      - Redistributions in binary form must reproduce the above
23  *        copyright notice, this list of conditions and the following
24  *        disclaimer in the documentation and/or other materials
25  *        provided with the distribution.
26  *
27  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
28  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
29  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
30  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
31  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
32  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
33  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
34  * SOFTWARE.
35  */
36 
37 #ifndef _IPOIB_H
38 #define _IPOIB_H
39 
40 #define	LINUXKPI_PARAM_PREFIX ipoib_
41 
42 #include "opt_inet.h"
43 #include "opt_inet6.h"
44 #include "opt_ofed.h"
45 
46 #include <sys/param.h>
47 #include <sys/systm.h>
48 #include <sys/kernel.h>
49 #include <sys/lock.h>
50 #include <sys/malloc.h>
51 #include <sys/mbuf.h>
52 #include <sys/random.h>
53 #include <sys/rwlock.h>
54 #include <sys/socket.h>
55 #include <sys/sockio.h>
56 #include <sys/sysctl.h>
57 
58 #include <net/if.h>
59 #include <net/if_var.h>
60 #include <net/if_arp.h>
61 #include <net/netisr.h>
62 #include <net/route.h>
63 #include <net/if_llc.h>
64 #include <net/if_dl.h>
65 #include <net/if_types.h>
66 #include <net/bpf.h>
67 #include <net/if_llatbl.h>
68 #include <net/vnet.h>
69 
70 #if defined(INET) || defined(INET6)
71 #include <netinet/in.h>
72 #include <netinet/in_var.h>
73 #include <netinet/if_ether.h>
74 #include <netinet/ip_var.h>
75 #endif
76 #ifdef INET6
77 #include <netinet6/nd6.h>
78 #endif
79 
80 #include <security/mac/mac_framework.h>
81 
82 #include <linux/list.h>
83 
84 #include <linux/workqueue.h>
85 #include <linux/kref.h>
86 #include <linux/mutex.h>
87 #include <linux/rbtree.h>
88 
89 #include <asm/atomic.h>
90 
91 #include <rdma/ib_verbs.h>
92 #include <rdma/ib_pack.h>
93 #include <rdma/ib_sa.h>
94 
95 /* constants */
96 
97 #define	INFINIBAND_ALEN		20	/* Octets in IPoIB HW addr */
98 
99 #ifdef IPOIB_CM
100 #define	CONFIG_INFINIBAND_IPOIB_CM
101 #endif
102 
103 #ifdef IPOIB_DEBUG
104 #define	CONFIG_INFINIBAND_IPOIB_DEBUG
105 #define CONFIG_INFINIBAND_IPOIB_DEBUG_DATA
106 #endif
107 
108 enum ipoib_flush_level {
109 	IPOIB_FLUSH_LIGHT,
110 	IPOIB_FLUSH_NORMAL,
111 	IPOIB_FLUSH_HEAVY
112 };
113 
114 enum {
115 	IPOIB_ENCAP_LEN		  = 4,
116 	IPOIB_HEADER_LEN	  = IPOIB_ENCAP_LEN + INFINIBAND_ALEN,
117 	IPOIB_UD_MAX_MTU	  = 4 * 1024,
118 	IPOIB_UD_RX_SG		  = 2,	/* packet header and one cluster */
119 	IPOIB_UD_TX_SG		  = (IPOIB_UD_MAX_MTU / MCLBYTES) + 2,
120 	IPOIB_CM_MAX_MTU	  = (64 * 1024),
121 	IPOIB_CM_TX_SG		  = (IPOIB_CM_MAX_MTU / MCLBYTES) + 2,
122 	IPOIB_CM_RX_SG		  = (IPOIB_CM_MAX_MTU / MCLBYTES) + 2,
123 	IPOIB_RX_RING_SIZE	  = 256,
124 	IPOIB_TX_RING_SIZE	  = 128,
125 	IPOIB_MAX_RX_SG		  = MAX(IPOIB_CM_RX_SG, IPOIB_UD_RX_SG),
126 	IPOIB_MAX_TX_SG		  = MAX(IPOIB_CM_TX_SG, IPOIB_UD_TX_SG),
127 	IPOIB_MAX_QUEUE_SIZE	  = 8192,
128 	IPOIB_MIN_QUEUE_SIZE	  = 2,
129 	IPOIB_CM_MAX_CONN_QP	  = 4096,
130 
131 	IPOIB_NUM_WC		  = 4,
132 
133 	IPOIB_MAX_PATH_REC_QUEUE  = 16,
134 	IPOIB_MAX_MCAST_QUEUE	  = 16,
135 
136 	IPOIB_FLAG_OPER_UP	  = 0,
137 	IPOIB_FLAG_INITIALIZED	  = 1,
138 	IPOIB_FLAG_ADMIN_UP	  = 2,
139 	IPOIB_PKEY_ASSIGNED	  = 3,
140 	IPOIB_PKEY_STOP		  = 4,
141 	IPOIB_FLAG_SUBINTERFACE	  = 5,
142 	IPOIB_MCAST_RUN		  = 6,
143 	IPOIB_STOP_REAPER	  = 7,
144 	IPOIB_FLAG_UMCAST	  = 10,
145 	IPOIB_FLAG_CSUM		  = 11,
146 
147 	IPOIB_MAX_BACKOFF_SECONDS = 16,
148 
149 	IPOIB_MCAST_FLAG_FOUND	  = 0,	/* used in set_multicast_list */
150 	IPOIB_MCAST_FLAG_SENDONLY = 1,
151 	IPOIB_MCAST_FLAG_BUSY	  = 2,	/* joining or already joined */
152 	IPOIB_MCAST_FLAG_ATTACHED = 3,
153 
154 	IPOIB_MAX_LRO_DESCRIPTORS = 8,
155 	IPOIB_LRO_MAX_AGGR 	  = 64,
156 
157 	MAX_SEND_CQE		  = 16,
158 	IPOIB_CM_COPYBREAK	  = 256,
159 };
160 
161 #define	IPOIB_OP_RECV   (1ul << 31)
162 #ifdef CONFIG_INFINIBAND_IPOIB_CM
163 #define	IPOIB_OP_CM     (1ul << 30)
164 #else
165 #define	IPOIB_OP_CM     (0)
166 #endif
167 
168 /* structs */
169 
170 struct ipoib_header {
171 	u8  hwaddr[INFINIBAND_ALEN];
172 	__be16	proto;
173 	u16	reserved;
174 };
175 
176 struct ipoib_pseudoheader {
177 	u8  hwaddr[INFINIBAND_ALEN];
178 };
179 
180 /* Used for all multicast joins (broadcast, IPv4 mcast and IPv6 mcast) */
181 struct ipoib_mcast {
182 	struct ib_sa_mcmember_rec mcmember;
183 	struct ib_sa_multicast	 *mc;
184 	struct ipoib_ah		 *ah;
185 
186 	struct rb_node    rb_node;
187 	struct list_head  list;
188 
189 	unsigned long created;
190 	unsigned long backoff;
191 
192 	unsigned long flags;
193 	unsigned char logcount;
194 
195 	struct ifqueue pkt_queue;
196 
197 	struct ipoib_dev_priv *priv;
198 };
199 
200 struct ipoib_cm_rx_buf {
201 	struct mbuf *mb;
202 	u64		mapping[IPOIB_CM_RX_SG];
203 };
204 
205 struct ipoib_cm_tx_buf {
206 	struct mbuf *mb;
207 	u64		mapping[IPOIB_CM_TX_SG];
208 };
209 
210 struct ipoib_rx_buf {
211 	struct mbuf *mb;
212 	u64		mapping[IPOIB_UD_RX_SG];
213 };
214 
215 struct ipoib_tx_buf {
216 	struct mbuf *mb;
217 	u64		mapping[IPOIB_UD_TX_SG];
218 };
219 
220 struct ib_cm_id;
221 
222 struct ipoib_cm_data {
223 	__be32 qpn; /* High byte MUST be ignored on receive */
224 	__be32 mtu;
225 };
226 
227 /*
228  * Quoting 10.3.1 Queue Pair and EE Context States:
229  *
230  * Note, for QPs that are associated with an SRQ, the Consumer should take the
231  * QP through the Error State before invoking a Destroy QP or a Modify QP to the
232  * Reset State.  The Consumer may invoke the Destroy QP without first performing
233  * a Modify QP to the Error State and waiting for the Affiliated Asynchronous
234  * Last WQE Reached Event. However, if the Consumer does not wait for the
235  * Affiliated Asynchronous Last WQE Reached Event, then WQE and Data Segment
236  * leakage may occur. Therefore, it is good programming practice to tear down a
237  * QP that is associated with an SRQ by using the following process:
238  *
239  * - Put the QP in the Error State
240  * - Wait for the Affiliated Asynchronous Last WQE Reached Event;
241  * - either:
242  *       drain the CQ by invoking the Poll CQ verb and either wait for CQ
243  *       to be empty or the number of Poll CQ operations has exceeded
244  *       CQ capacity size;
245  * - or
246  *       post another WR that completes on the same CQ and wait for this
247  *       WR to return as a WC;
248  * - and then invoke a Destroy QP or Reset QP.
249  *
250  * We use the second option and wait for a completion on the
251  * same CQ before destroying QPs attached to our SRQ.
252  */
253 
254 enum ipoib_cm_state {
255 	IPOIB_CM_RX_LIVE,
256 	IPOIB_CM_RX_ERROR, /* Ignored by stale task */
257 	IPOIB_CM_RX_FLUSH  /* Last WQE Reached event observed */
258 };
259 
260 struct ipoib_cm_rx {
261 	struct ib_cm_id	       *id;
262 	struct ib_qp	       *qp;
263 	struct ipoib_cm_rx_buf *rx_ring;
264 	struct list_head	list;
265 	struct ipoib_dev_priv	*priv;
266 	unsigned long		jiffies;
267 	enum ipoib_cm_state	state;
268 	int			recv_count;
269 };
270 
271 struct ipoib_cm_tx {
272 	struct ib_cm_id	    *id;
273 	struct ib_qp	    *qp;
274 	struct list_head     list;
275 	struct ipoib_dev_priv *priv;
276 	struct ipoib_path   *path;
277 	struct ipoib_cm_tx_buf *tx_ring;
278 	unsigned	     tx_head;
279 	unsigned	     tx_tail;
280 	unsigned long	     flags;
281 	u32		     mtu;	/* remote specified mtu, with grh. */
282 };
283 
284 struct ipoib_cm_dev_priv {
285 	struct ib_srq	       *srq;
286 	struct ipoib_cm_rx_buf *srq_ring;
287 	struct ib_cm_id	       *id;
288 	struct list_head	passive_ids;   /* state: LIVE */
289 	struct list_head	rx_error_list; /* state: ERROR */
290 	struct list_head	rx_flush_list; /* state: FLUSH, drain not started */
291 	struct list_head	rx_drain_list; /* state: FLUSH, drain started */
292 	struct list_head	rx_reap_list;  /* state: FLUSH, drain done */
293 	struct work_struct      start_task;
294 	struct work_struct      reap_task;
295 	struct work_struct      mb_task;
296 	struct work_struct      rx_reap_task;
297 	struct delayed_work     stale_task;
298 	struct ifqueue     	mb_queue;
299 	struct list_head	start_list;
300 	struct list_head	reap_list;
301 	struct ib_sge		rx_sge[IPOIB_CM_RX_SG];
302 	struct ib_recv_wr	rx_wr;
303 	int			nonsrq_conn_qp;
304 	int			max_cm_mtu;	/* Actual buf size. */
305 	int			num_frags;
306 };
307 
308 struct ipoib_ethtool_st {
309 	u16     coalesce_usecs;
310 	u16     max_coalesced_frames;
311 };
312 
313 /*
314  * Device private locking: network stack tx_lock protects members used
315  * in TX fast path, lock protects everything else.  lock nests inside
316  * of tx_lock (ie tx_lock must be acquired first if needed).
317  */
318 struct ipoib_dev_priv {
319 	spinlock_t lock;
320 	spinlock_t drain_lock;
321 
322 	if_t dev;
323 
324 	u8 broadcastaddr[INFINIBAND_ALEN];
325 
326 	unsigned long flags;
327 
328 	int gone;
329 	int unit;
330 
331 	struct mutex vlan_mutex;
332 
333 	struct rb_root  path_tree;
334 	struct list_head path_list;
335 
336 	struct ipoib_mcast *broadcast;
337 	struct list_head multicast_list;
338 	struct rb_root multicast_tree;
339 
340 	struct delayed_work pkey_poll_task;
341 	struct delayed_work mcast_task;
342 	struct work_struct carrier_on_task;
343 	struct work_struct flush_light;
344 	struct work_struct flush_normal;
345 	struct work_struct flush_heavy;
346 	struct work_struct restart_task;
347 	struct delayed_work ah_reap_task;
348 
349 	struct ib_device *ca;
350 	u8		  port;
351 	u16		  pkey;
352 	u16		  pkey_index;
353 	struct ib_pd	 *pd;
354 	struct ib_cq	 *recv_cq;
355 	struct ib_cq	 *send_cq;
356 	struct ib_qp	 *qp;
357 	u32		  qkey;
358 
359 	union ib_gid local_gid;
360 	u16	     local_lid;
361 
362 	unsigned int admin_mtu;		/* User selected MTU, no GRH. */
363 	unsigned int mcast_mtu;		/* Minus GRH bytes, from mcast group. */
364 	unsigned int max_ib_mtu;	/* Without header, actual buf size. */
365 
366 	struct ipoib_rx_buf *rx_ring;
367 
368 	struct ipoib_tx_buf *tx_ring;
369 	unsigned	     tx_head;
370 	unsigned	     tx_tail;
371 	struct ib_sge	     tx_sge[IPOIB_MAX_TX_SG];
372 	struct ib_ud_wr      tx_wr;
373 	unsigned	     tx_outstanding;
374 	struct ib_wc	     send_wc[MAX_SEND_CQE];
375 
376 	struct ib_recv_wr    rx_wr;
377 	struct ib_sge	     rx_sge[IPOIB_MAX_RX_SG];
378 
379 	struct ib_wc ibwc[IPOIB_NUM_WC];
380 
381 	struct list_head dead_ahs;
382 
383 	struct ib_event_handler event_handler;
384 
385 	if_t parent;
386 	struct list_head child_intfs;
387 	struct list_head list;
388 
389 #ifdef CONFIG_INFINIBAND_IPOIB_CM
390 	struct ipoib_cm_dev_priv cm;
391 #endif
392 
393 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
394 	struct list_head fs_list;
395 	struct dentry *mcg_dentry;
396 	struct dentry *path_dentry;
397 #endif
398 	int	hca_caps;
399 	struct ipoib_ethtool_st ethtool;
400 	struct timer_list poll_timer;
401 };
402 
403 struct ipoib_ah {
404 	struct ipoib_dev_priv *priv;
405 	struct ib_ah	  *ah;
406 	struct list_head   list;
407 	struct kref	   ref;
408 	unsigned	   last_send;
409 };
410 
411 struct ipoib_path {
412 	struct ipoib_dev_priv *priv;
413 	struct rb_node	      rb_node;
414 	struct list_head      list;
415 #ifdef CONFIG_INFINIBAND_IPOIB_CM
416 	uint8_t		      hwaddr[INFINIBAND_ALEN];
417 	struct ipoib_cm_tx   *cm;
418 #endif
419 	struct ipoib_ah      *ah;
420 	struct ib_sa_path_rec pathrec;
421 	struct ifqueue	      queue;
422 
423 	int		      query_id;
424 	struct ib_sa_query   *query;
425 	struct completion     done;
426 
427 	int  		      valid;
428 };
429 
430 /* UD Only transmits encap len but we want the two sizes to be symmetrical. */
431 #define IPOIB_UD_MTU(ib_mtu)		(ib_mtu - IPOIB_ENCAP_LEN)
432 #define	IPOIB_CM_MTU(ib_mtu)		(ib_mtu - 0x10)
433 
434 #define	IPOIB_IS_MULTICAST(addr)	((addr)[4] == 0xff)
435 
436 extern struct workqueue_struct *ipoib_workqueue;
437 
438 /* functions */
439 void ipoib_ib_completion(struct ib_cq *cq, void *dev_ptr);
440 void ipoib_send_comp_handler(struct ib_cq *cq, void *dev_ptr);
441 
442 struct ipoib_ah *ipoib_create_ah(struct ipoib_dev_priv *,
443 				 struct ib_pd *pd, struct ib_ah_attr *attr);
444 void ipoib_free_ah(struct kref *kref);
445 static inline void ipoib_put_ah(struct ipoib_ah *ah)
446 {
447 	kref_put(&ah->ref, ipoib_free_ah);
448 }
449 
450 int ipoib_open(struct ipoib_dev_priv *priv);
451 int ipoib_add_pkey_attr(struct ipoib_dev_priv *priv);
452 int ipoib_add_umcast_attr(struct ipoib_dev_priv *priv);
453 
454 void ipoib_send(struct ipoib_dev_priv *priv, struct mbuf *mb,
455 		struct ipoib_ah *address, u32 qpn);
456 void ipoib_reap_ah(struct work_struct *work);
457 
458 void ipoib_mark_paths_invalid(struct ipoib_dev_priv *priv);
459 void ipoib_flush_paths(struct ipoib_dev_priv *priv);
460 struct ipoib_dev_priv *ipoib_intf_alloc(const char *format, struct ib_device *ca);
461 
462 int ipoib_ib_dev_init(struct ipoib_dev_priv *priv, struct ib_device *ca,
463     int port);
464 void ipoib_ib_dev_flush_light(struct work_struct *work);
465 void ipoib_ib_dev_flush_normal(struct work_struct *work);
466 void ipoib_ib_dev_flush_heavy(struct work_struct *work);
467 void ipoib_pkey_event(struct work_struct *work);
468 void ipoib_ib_dev_cleanup(struct ipoib_dev_priv *priv);
469 
470 int ipoib_ib_dev_open(struct ipoib_dev_priv *priv);
471 int ipoib_ib_dev_up(struct ipoib_dev_priv *priv);
472 int ipoib_ib_dev_down(struct ipoib_dev_priv *priv, int flush);
473 int ipoib_ib_dev_stop(struct ipoib_dev_priv *priv, int flush);
474 
475 int ipoib_dev_init(struct ipoib_dev_priv *priv, struct ib_device *ca, int port);
476 void ipoib_dev_cleanup(struct ipoib_dev_priv *priv);
477 
478 void ipoib_mcast_join_task(struct work_struct *work);
479 void ipoib_mcast_carrier_on_task(struct work_struct *work);
480 void ipoib_mcast_send(struct ipoib_dev_priv *priv, void *mgid, struct mbuf *mb);
481 
482 void ipoib_mcast_restart_task(struct work_struct *work);
483 void ipoib_mcast_restart(struct ipoib_dev_priv *);
484 int ipoib_mcast_start_thread(struct ipoib_dev_priv *priv);
485 int ipoib_mcast_stop_thread(struct ipoib_dev_priv *priv, int flush);
486 
487 void ipoib_mcast_dev_down(struct ipoib_dev_priv *priv);
488 void ipoib_mcast_dev_flush(struct ipoib_dev_priv *priv);
489 
490 void ipoib_path_free(struct ipoib_dev_priv *priv, struct ipoib_path *path);
491 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
492 struct ipoib_mcast_iter *ipoib_mcast_iter_init(struct ipoib_dev_priv *priv);
493 int ipoib_mcast_iter_next(struct ipoib_mcast_iter *iter);
494 void ipoib_mcast_iter_read(struct ipoib_mcast_iter *iter,
495 				  union ib_gid *gid,
496 				  unsigned long *created,
497 				  unsigned int *queuelen,
498 				  unsigned int *complete,
499 				  unsigned int *send_only);
500 
501 struct ipoib_path_iter *ipoib_path_iter_init(struct ipoib_dev_priv *priv);
502 int ipoib_path_iter_next(struct ipoib_path_iter *iter);
503 void ipoib_path_iter_read(struct ipoib_path_iter *iter,
504 			  struct ipoib_path *path);
505 #endif
506 
507 int ipoib_change_mtu(struct ipoib_dev_priv *priv, int new_mtu, bool propagate);
508 
509 int ipoib_mcast_attach(struct ipoib_dev_priv *priv, u16 mlid,
510 		       union ib_gid *mgid, int set_qkey);
511 
512 int ipoib_init_qp(struct ipoib_dev_priv *priv);
513 int ipoib_transport_dev_init(struct ipoib_dev_priv *priv, struct ib_device *ca);
514 void ipoib_transport_dev_cleanup(struct ipoib_dev_priv *priv);
515 
516 void ipoib_event(struct ib_event_handler *handler,
517 		 struct ib_event *record);
518 
519 void ipoib_pkey_poll(struct work_struct *work);
520 int ipoib_pkey_dev_delay_open(struct ipoib_dev_priv *priv);
521 void ipoib_drain_cq(struct ipoib_dev_priv *priv);
522 
523 int ipoib_dma_map_tx(struct ib_device *ca, struct ipoib_tx_buf *tx_req, int max);
524 void ipoib_dma_unmap_tx(struct ib_device *ca, struct ipoib_tx_buf *tx_req);
525 int ipoib_poll_tx(struct ipoib_dev_priv *priv, bool do_start);
526 
527 void ipoib_dma_unmap_rx(struct ipoib_dev_priv *priv, struct ipoib_rx_buf *rx_req);
528 void ipoib_dma_mb(struct ipoib_dev_priv *priv, struct mbuf *mb, unsigned int length);
529 struct mbuf *ipoib_alloc_map_mb(struct ipoib_dev_priv *priv, struct ipoib_rx_buf *rx_req, int align, int size, int max_frags);
530 
531 
532 void ipoib_set_ethtool_ops(if_t dev);
533 int ipoib_set_dev_features(struct ipoib_dev_priv *priv, struct ib_device *hca);
534 
535 #ifdef CONFIG_INFINIBAND_IPOIB_CM
536 
537 #define IPOIB_FLAGS_RC		0x80
538 #define IPOIB_FLAGS_UC		0x40
539 
540 /* We don't support UC connections at the moment */
541 #define IPOIB_CM_SUPPORTED(ha)   (ha[0] & (IPOIB_FLAGS_RC))
542 
543 extern int ipoib_max_conn_qp;
544 
545 static inline int ipoib_cm_admin_enabled(struct ipoib_dev_priv *priv)
546 {
547 	return IPOIB_CM_SUPPORTED(if_getlladdr(priv->dev));
548 }
549 
550 static inline int ipoib_cm_enabled(struct ipoib_dev_priv *priv, uint8_t *hwaddr)
551 {
552 	return IPOIB_CM_SUPPORTED(hwaddr);
553 }
554 
555 static inline int ipoib_cm_up(struct ipoib_path *path)
556 
557 {
558 	return test_bit(IPOIB_FLAG_OPER_UP, &path->cm->flags);
559 }
560 
561 static inline struct ipoib_cm_tx *ipoib_cm_get(struct ipoib_path *path)
562 {
563 	return path->cm;
564 }
565 
566 static inline void ipoib_cm_set(struct ipoib_path *path, struct ipoib_cm_tx *tx)
567 {
568 	path->cm = tx;
569 }
570 
571 static inline int ipoib_cm_has_srq(struct ipoib_dev_priv *priv)
572 {
573 	return !!priv->cm.srq;
574 }
575 
576 static inline unsigned int ipoib_cm_max_mtu(struct ipoib_dev_priv *priv)
577 {
578 	return priv->cm.max_cm_mtu;
579 }
580 
581 void ipoib_cm_send(struct ipoib_dev_priv *priv, struct mbuf *mb, struct ipoib_cm_tx *tx);
582 int ipoib_cm_dev_open(struct ipoib_dev_priv *priv);
583 void ipoib_cm_dev_stop(struct ipoib_dev_priv *priv);
584 int ipoib_cm_dev_init(struct ipoib_dev_priv *priv);
585 int ipoib_cm_add_mode_attr(struct ipoib_dev_priv *priv);
586 void ipoib_cm_dev_cleanup(struct ipoib_dev_priv *priv);
587 struct ipoib_cm_tx *ipoib_cm_create_tx(struct ipoib_dev_priv *priv,
588     struct ipoib_path *path);
589 void ipoib_cm_destroy_tx(struct ipoib_cm_tx *tx);
590 void ipoib_cm_mb_too_long(struct ipoib_dev_priv *priv, struct mbuf *mb,
591 			   unsigned int mtu);
592 void ipoib_cm_handle_rx_wc(struct ipoib_dev_priv *priv, struct ib_wc *wc);
593 void ipoib_cm_handle_tx_wc(struct ipoib_dev_priv *priv, struct ib_wc *wc);
594 #else
595 
596 struct ipoib_cm_tx;
597 
598 #define ipoib_max_conn_qp 0
599 
600 static inline int ipoib_cm_admin_enabled(struct ipoib_dev_priv *priv)
601 {
602 	return 0;
603 }
604 static inline int ipoib_cm_enabled(struct ipoib_dev_priv *priv, uint8_t *hwaddr)
605 
606 {
607 	return 0;
608 }
609 
610 static inline int ipoib_cm_up(struct ipoib_path *path)
611 
612 {
613 	return 0;
614 }
615 
616 static inline struct ipoib_cm_tx *ipoib_cm_get(struct ipoib_path *path)
617 {
618 	return NULL;
619 }
620 
621 static inline void ipoib_cm_set(struct ipoib_path *path, struct ipoib_cm_tx *tx)
622 {
623 }
624 
625 static inline int ipoib_cm_has_srq(struct ipoib_dev_priv *priv)
626 {
627 	return 0;
628 }
629 
630 static inline unsigned int ipoib_cm_max_mtu(struct ipoib_dev_priv *priv)
631 {
632 	return 0;
633 }
634 
635 static inline
636 void ipoib_cm_send(struct ipoib_dev_priv *priv, struct mbuf *mb, struct ipoib_cm_tx *tx)
637 {
638 	return;
639 }
640 
641 static inline
642 int ipoib_cm_dev_open(struct ipoib_dev_priv *priv)
643 {
644 	return 0;
645 }
646 
647 static inline
648 void ipoib_cm_dev_stop(struct ipoib_dev_priv *priv)
649 {
650 	return;
651 }
652 
653 static inline
654 int ipoib_cm_dev_init(struct ipoib_dev_priv *priv)
655 {
656 	return -ENOSYS;
657 }
658 
659 static inline
660 void ipoib_cm_dev_cleanup(struct ipoib_dev_priv *priv)
661 {
662 	return;
663 }
664 
665 static inline
666 struct ipoib_cm_tx *ipoib_cm_create_tx(struct ipoib_dev_priv *priv, struct ipoib_path *path)
667 {
668 	return NULL;
669 }
670 
671 static inline
672 void ipoib_cm_destroy_tx(struct ipoib_cm_tx *tx)
673 {
674 	return;
675 }
676 
677 static inline
678 int ipoib_cm_add_mode_attr(struct ipoib_dev_priv *priv)
679 {
680 	return 0;
681 }
682 
683 static inline void ipoib_cm_mb_too_long(struct ipoib_dev_priv *priv, struct mbuf *mb,
684 					 unsigned int mtu)
685 {
686 	m_freem(mb);
687 }
688 
689 static inline void ipoib_cm_handle_rx_wc(struct ipoib_dev_priv *priv, struct ib_wc *wc)
690 {
691 }
692 
693 static inline void ipoib_cm_handle_tx_wc(struct ipoib_dev_priv *priv, struct ib_wc *wc)
694 {
695 }
696 #endif
697 
698 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
699 void ipoib_create_debug_files(struct ipoib_dev_priv *priv);
700 void ipoib_delete_debug_files(struct ipoib_dev_priv *priv);
701 int ipoib_register_debugfs(void);
702 void ipoib_unregister_debugfs(void);
703 #else
704 static inline void ipoib_create_debug_files(struct ipoib_dev_priv *priv) { }
705 static inline void ipoib_delete_debug_files(struct ipoib_dev_priv *priv) { }
706 static inline int ipoib_register_debugfs(void) { return 0; }
707 static inline void ipoib_unregister_debugfs(void) { }
708 #endif
709 
710 #define ipoib_printk(level, priv, format, arg...)	\
711 	printk(level "%s: " format, if_name(((struct ipoib_dev_priv *) priv)->dev), ## arg)
712 #define ipoib_warn(priv, format, arg...)		\
713 	ipoib_printk(KERN_WARNING, priv, format , ## arg)
714 
715 extern int ipoib_sendq_size;
716 extern int ipoib_recvq_size;
717 
718 extern struct ib_sa_client ipoib_sa_client;
719 
720 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
721 extern int ipoib_debug_level;
722 
723 #define ipoib_dbg(priv, format, arg...)			\
724 	do {						\
725 		if (ipoib_debug_level > 0)			\
726 			ipoib_printk(KERN_DEBUG, priv, format , ## arg); \
727 	} while (0)
728 #define ipoib_dbg_mcast(priv, format, arg...)		\
729 	do {						\
730 		if (mcast_debug_level > 0)		\
731 			ipoib_printk(KERN_DEBUG, priv, format , ## arg); \
732 	} while (0)
733 #else /* CONFIG_INFINIBAND_IPOIB_DEBUG */
734 #define ipoib_dbg(priv, format, arg...)			\
735 	do { (void) (priv); } while (0)
736 #define ipoib_dbg_mcast(priv, format, arg...)		\
737 	do { (void) (priv); } while (0)
738 #endif /* CONFIG_INFINIBAND_IPOIB_DEBUG */
739 
740 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG_DATA
741 #define ipoib_dbg_data(priv, format, arg...)		\
742 	do {						\
743 		if (data_debug_level > 0)		\
744 			ipoib_printk(KERN_DEBUG, priv, format , ## arg); \
745 	} while (0)
746 #else /* CONFIG_INFINIBAND_IPOIB_DEBUG_DATA */
747 #define ipoib_dbg_data(priv, format, arg...)		\
748 	do { (void) (priv); } while (0)
749 #endif /* CONFIG_INFINIBAND_IPOIB_DEBUG_DATA */
750 
751 #define IPOIB_QPN(ha) (be32_to_cpup((__be32 *) ha) & 0xffffff)
752 
753 void ipoib_start_locked(if_t, struct ipoib_dev_priv *);
754 
755 #endif /* _IPOIB_H */
756