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