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