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