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