18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Copyright (c) 2004, 2005 Topspin Communications.  All rights reserved.
38c2ecf20Sopenharmony_ci * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
48c2ecf20Sopenharmony_ci * Copyright (c) 2004 Voltaire, Inc. All rights reserved.
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * This software is available to you under a choice of one of two
78c2ecf20Sopenharmony_ci * licenses.  You may choose to be licensed under the terms of the GNU
88c2ecf20Sopenharmony_ci * General Public License (GPL) Version 2, available from the file
98c2ecf20Sopenharmony_ci * COPYING in the main directory of this source tree, or the
108c2ecf20Sopenharmony_ci * OpenIB.org BSD license below:
118c2ecf20Sopenharmony_ci *
128c2ecf20Sopenharmony_ci *     Redistribution and use in source and binary forms, with or
138c2ecf20Sopenharmony_ci *     without modification, are permitted provided that the following
148c2ecf20Sopenharmony_ci *     conditions are met:
158c2ecf20Sopenharmony_ci *
168c2ecf20Sopenharmony_ci *      - Redistributions of source code must retain the above
178c2ecf20Sopenharmony_ci *        copyright notice, this list of conditions and the following
188c2ecf20Sopenharmony_ci *        disclaimer.
198c2ecf20Sopenharmony_ci *
208c2ecf20Sopenharmony_ci *      - Redistributions in binary form must reproduce the above
218c2ecf20Sopenharmony_ci *        copyright notice, this list of conditions and the following
228c2ecf20Sopenharmony_ci *        disclaimer in the documentation and/or other materials
238c2ecf20Sopenharmony_ci *        provided with the distribution.
248c2ecf20Sopenharmony_ci *
258c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
268c2ecf20Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
278c2ecf20Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
288c2ecf20Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
298c2ecf20Sopenharmony_ci * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
308c2ecf20Sopenharmony_ci * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
318c2ecf20Sopenharmony_ci * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
328c2ecf20Sopenharmony_ci * SOFTWARE.
338c2ecf20Sopenharmony_ci */
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci#ifndef _IPOIB_H
368c2ecf20Sopenharmony_ci#define _IPOIB_H
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci#include <linux/list.h>
398c2ecf20Sopenharmony_ci#include <linux/skbuff.h>
408c2ecf20Sopenharmony_ci#include <linux/netdevice.h>
418c2ecf20Sopenharmony_ci#include <linux/workqueue.h>
428c2ecf20Sopenharmony_ci#include <linux/kref.h>
438c2ecf20Sopenharmony_ci#include <linux/if_infiniband.h>
448c2ecf20Sopenharmony_ci#include <linux/mutex.h>
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci#include <net/neighbour.h>
478c2ecf20Sopenharmony_ci#include <net/sch_generic.h>
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci#include <linux/atomic.h>
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci#include <rdma/ib_verbs.h>
528c2ecf20Sopenharmony_ci#include <rdma/ib_pack.h>
538c2ecf20Sopenharmony_ci#include <rdma/ib_sa.h>
548c2ecf20Sopenharmony_ci#include <linux/sched.h>
558c2ecf20Sopenharmony_ci/* constants */
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_cienum ipoib_flush_level {
588c2ecf20Sopenharmony_ci	IPOIB_FLUSH_LIGHT,
598c2ecf20Sopenharmony_ci	IPOIB_FLUSH_NORMAL,
608c2ecf20Sopenharmony_ci	IPOIB_FLUSH_HEAVY
618c2ecf20Sopenharmony_ci};
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_cienum {
648c2ecf20Sopenharmony_ci	IPOIB_ENCAP_LEN		  = 4,
658c2ecf20Sopenharmony_ci	IPOIB_PSEUDO_LEN	  = 20,
668c2ecf20Sopenharmony_ci	IPOIB_HARD_LEN		  = IPOIB_ENCAP_LEN + IPOIB_PSEUDO_LEN,
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci	IPOIB_UD_HEAD_SIZE	  = IB_GRH_BYTES + IPOIB_ENCAP_LEN,
698c2ecf20Sopenharmony_ci	IPOIB_UD_RX_SG		  = 2, /* max buffer needed for 4K mtu */
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci	IPOIB_CM_MTU		  = 0x10000 - 0x10, /* padding to align header to 16 */
728c2ecf20Sopenharmony_ci	IPOIB_CM_BUF_SIZE	  = IPOIB_CM_MTU  + IPOIB_ENCAP_LEN,
738c2ecf20Sopenharmony_ci	IPOIB_CM_HEAD_SIZE	  = IPOIB_CM_BUF_SIZE % PAGE_SIZE,
748c2ecf20Sopenharmony_ci	IPOIB_CM_RX_SG		  = ALIGN(IPOIB_CM_BUF_SIZE, PAGE_SIZE) / PAGE_SIZE,
758c2ecf20Sopenharmony_ci	IPOIB_RX_RING_SIZE	  = 256,
768c2ecf20Sopenharmony_ci	IPOIB_TX_RING_SIZE	  = 128,
778c2ecf20Sopenharmony_ci	IPOIB_MAX_QUEUE_SIZE	  = 8192,
788c2ecf20Sopenharmony_ci	IPOIB_MIN_QUEUE_SIZE	  = 2,
798c2ecf20Sopenharmony_ci	IPOIB_CM_MAX_CONN_QP	  = 4096,
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci	IPOIB_NUM_WC		  = 4,
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci	IPOIB_MAX_PATH_REC_QUEUE  = 3,
848c2ecf20Sopenharmony_ci	IPOIB_MAX_MCAST_QUEUE	  = 64,
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci	IPOIB_FLAG_OPER_UP	  = 0,
878c2ecf20Sopenharmony_ci	IPOIB_FLAG_INITIALIZED	  = 1,
888c2ecf20Sopenharmony_ci	IPOIB_FLAG_ADMIN_UP	  = 2,
898c2ecf20Sopenharmony_ci	IPOIB_PKEY_ASSIGNED	  = 3,
908c2ecf20Sopenharmony_ci	IPOIB_FLAG_SUBINTERFACE	  = 5,
918c2ecf20Sopenharmony_ci	IPOIB_STOP_REAPER	  = 7,
928c2ecf20Sopenharmony_ci	IPOIB_FLAG_ADMIN_CM	  = 9,
938c2ecf20Sopenharmony_ci	IPOIB_FLAG_UMCAST	  = 10,
948c2ecf20Sopenharmony_ci	IPOIB_NEIGH_TBL_FLUSH	  = 12,
958c2ecf20Sopenharmony_ci	IPOIB_FLAG_DEV_ADDR_SET	  = 13,
968c2ecf20Sopenharmony_ci	IPOIB_FLAG_DEV_ADDR_CTRL  = 14,
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ci	IPOIB_MAX_BACKOFF_SECONDS = 16,
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci	IPOIB_MCAST_FLAG_FOUND	  = 0,	/* used in set_multicast_list */
1018c2ecf20Sopenharmony_ci	IPOIB_MCAST_FLAG_SENDONLY = 1,
1028c2ecf20Sopenharmony_ci	/*
1038c2ecf20Sopenharmony_ci	 * For IPOIB_MCAST_FLAG_BUSY
1048c2ecf20Sopenharmony_ci	 * When set, in flight join and mcast->mc is unreliable
1058c2ecf20Sopenharmony_ci	 * When clear and mcast->mc IS_ERR_OR_NULL, need to restart or
1068c2ecf20Sopenharmony_ci	 *   haven't started yet
1078c2ecf20Sopenharmony_ci	 * When clear and mcast->mc is valid pointer, join was successful
1088c2ecf20Sopenharmony_ci	 */
1098c2ecf20Sopenharmony_ci	IPOIB_MCAST_FLAG_BUSY	  = 2,
1108c2ecf20Sopenharmony_ci	IPOIB_MCAST_FLAG_ATTACHED = 3,
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci	MAX_SEND_CQE		  = 64,
1138c2ecf20Sopenharmony_ci	IPOIB_CM_COPYBREAK	  = 256,
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_ci	IPOIB_NON_CHILD		  = 0,
1168c2ecf20Sopenharmony_ci	IPOIB_LEGACY_CHILD	  = 1,
1178c2ecf20Sopenharmony_ci	IPOIB_RTNL_CHILD	  = 2,
1188c2ecf20Sopenharmony_ci};
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ci#define	IPOIB_OP_RECV   (1ul << 31)
1218c2ecf20Sopenharmony_ci#ifdef CONFIG_INFINIBAND_IPOIB_CM
1228c2ecf20Sopenharmony_ci#define	IPOIB_OP_CM     (1ul << 30)
1238c2ecf20Sopenharmony_ci#else
1248c2ecf20Sopenharmony_ci#define	IPOIB_OP_CM     (0)
1258c2ecf20Sopenharmony_ci#endif
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_ci#define IPOIB_QPN_MASK ((__force u32) cpu_to_be32(0xFFFFFF))
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_ci/* structs */
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_cistruct ipoib_header {
1328c2ecf20Sopenharmony_ci	__be16	proto;
1338c2ecf20Sopenharmony_ci	u16	reserved;
1348c2ecf20Sopenharmony_ci};
1358c2ecf20Sopenharmony_ci
1368c2ecf20Sopenharmony_cistruct ipoib_pseudo_header {
1378c2ecf20Sopenharmony_ci	u8	hwaddr[INFINIBAND_ALEN];
1388c2ecf20Sopenharmony_ci};
1398c2ecf20Sopenharmony_ci
1408c2ecf20Sopenharmony_cistatic inline void skb_add_pseudo_hdr(struct sk_buff *skb)
1418c2ecf20Sopenharmony_ci{
1428c2ecf20Sopenharmony_ci	char *data = skb_push(skb, IPOIB_PSEUDO_LEN);
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_ci	/*
1458c2ecf20Sopenharmony_ci	 * only the ipoib header is present now, make room for a dummy
1468c2ecf20Sopenharmony_ci	 * pseudo header and set skb field accordingly
1478c2ecf20Sopenharmony_ci	 */
1488c2ecf20Sopenharmony_ci	memset(data, 0, IPOIB_PSEUDO_LEN);
1498c2ecf20Sopenharmony_ci	skb_reset_mac_header(skb);
1508c2ecf20Sopenharmony_ci	skb_pull(skb, IPOIB_HARD_LEN);
1518c2ecf20Sopenharmony_ci}
1528c2ecf20Sopenharmony_ci
1538c2ecf20Sopenharmony_cistatic inline struct ipoib_dev_priv *ipoib_priv(const struct net_device *dev)
1548c2ecf20Sopenharmony_ci{
1558c2ecf20Sopenharmony_ci	struct rdma_netdev *rn = netdev_priv(dev);
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_ci	return rn->clnt_priv;
1588c2ecf20Sopenharmony_ci}
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_ci/* Used for all multicast joins (broadcast, IPv4 mcast and IPv6 mcast) */
1618c2ecf20Sopenharmony_cistruct ipoib_mcast {
1628c2ecf20Sopenharmony_ci	struct ib_sa_mcmember_rec mcmember;
1638c2ecf20Sopenharmony_ci	struct ib_sa_multicast	 *mc;
1648c2ecf20Sopenharmony_ci	struct ipoib_ah		 *ah;
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_ci	struct rb_node    rb_node;
1678c2ecf20Sopenharmony_ci	struct list_head  list;
1688c2ecf20Sopenharmony_ci
1698c2ecf20Sopenharmony_ci	unsigned long created;
1708c2ecf20Sopenharmony_ci	unsigned long backoff;
1718c2ecf20Sopenharmony_ci	unsigned long delay_until;
1728c2ecf20Sopenharmony_ci
1738c2ecf20Sopenharmony_ci	unsigned long flags;
1748c2ecf20Sopenharmony_ci	unsigned char logcount;
1758c2ecf20Sopenharmony_ci
1768c2ecf20Sopenharmony_ci	struct list_head  neigh_list;
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_ci	struct sk_buff_head pkt_queue;
1798c2ecf20Sopenharmony_ci
1808c2ecf20Sopenharmony_ci	struct net_device *dev;
1818c2ecf20Sopenharmony_ci	struct completion done;
1828c2ecf20Sopenharmony_ci};
1838c2ecf20Sopenharmony_ci
1848c2ecf20Sopenharmony_cistruct ipoib_rx_buf {
1858c2ecf20Sopenharmony_ci	struct sk_buff *skb;
1868c2ecf20Sopenharmony_ci	u64		mapping[IPOIB_UD_RX_SG];
1878c2ecf20Sopenharmony_ci};
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_cistruct ipoib_tx_buf {
1908c2ecf20Sopenharmony_ci	struct sk_buff *skb;
1918c2ecf20Sopenharmony_ci	u64		mapping[MAX_SKB_FRAGS + 1];
1928c2ecf20Sopenharmony_ci};
1938c2ecf20Sopenharmony_ci
1948c2ecf20Sopenharmony_cistruct ib_cm_id;
1958c2ecf20Sopenharmony_ci
1968c2ecf20Sopenharmony_cistruct ipoib_cm_data {
1978c2ecf20Sopenharmony_ci	__be32 qpn; /* High byte MUST be ignored on receive */
1988c2ecf20Sopenharmony_ci	__be32 mtu;
1998c2ecf20Sopenharmony_ci};
2008c2ecf20Sopenharmony_ci
2018c2ecf20Sopenharmony_ci/*
2028c2ecf20Sopenharmony_ci * Quoting 10.3.1 Queue Pair and EE Context States:
2038c2ecf20Sopenharmony_ci *
2048c2ecf20Sopenharmony_ci * Note, for QPs that are associated with an SRQ, the Consumer should take the
2058c2ecf20Sopenharmony_ci * QP through the Error State before invoking a Destroy QP or a Modify QP to the
2068c2ecf20Sopenharmony_ci * Reset State.  The Consumer may invoke the Destroy QP without first performing
2078c2ecf20Sopenharmony_ci * a Modify QP to the Error State and waiting for the Affiliated Asynchronous
2088c2ecf20Sopenharmony_ci * Last WQE Reached Event. However, if the Consumer does not wait for the
2098c2ecf20Sopenharmony_ci * Affiliated Asynchronous Last WQE Reached Event, then WQE and Data Segment
2108c2ecf20Sopenharmony_ci * leakage may occur. Therefore, it is good programming practice to tear down a
2118c2ecf20Sopenharmony_ci * QP that is associated with an SRQ by using the following process:
2128c2ecf20Sopenharmony_ci *
2138c2ecf20Sopenharmony_ci * - Put the QP in the Error State
2148c2ecf20Sopenharmony_ci * - Wait for the Affiliated Asynchronous Last WQE Reached Event;
2158c2ecf20Sopenharmony_ci * - either:
2168c2ecf20Sopenharmony_ci *       drain the CQ by invoking the Poll CQ verb and either wait for CQ
2178c2ecf20Sopenharmony_ci *       to be empty or the number of Poll CQ operations has exceeded
2188c2ecf20Sopenharmony_ci *       CQ capacity size;
2198c2ecf20Sopenharmony_ci * - or
2208c2ecf20Sopenharmony_ci *       post another WR that completes on the same CQ and wait for this
2218c2ecf20Sopenharmony_ci *       WR to return as a WC;
2228c2ecf20Sopenharmony_ci * - and then invoke a Destroy QP or Reset QP.
2238c2ecf20Sopenharmony_ci *
2248c2ecf20Sopenharmony_ci * We use the second option and wait for a completion on the
2258c2ecf20Sopenharmony_ci * same CQ before destroying QPs attached to our SRQ.
2268c2ecf20Sopenharmony_ci */
2278c2ecf20Sopenharmony_ci
2288c2ecf20Sopenharmony_cienum ipoib_cm_state {
2298c2ecf20Sopenharmony_ci	IPOIB_CM_RX_LIVE,
2308c2ecf20Sopenharmony_ci	IPOIB_CM_RX_ERROR, /* Ignored by stale task */
2318c2ecf20Sopenharmony_ci	IPOIB_CM_RX_FLUSH  /* Last WQE Reached event observed */
2328c2ecf20Sopenharmony_ci};
2338c2ecf20Sopenharmony_ci
2348c2ecf20Sopenharmony_cistruct ipoib_cm_rx {
2358c2ecf20Sopenharmony_ci	struct ib_cm_id	       *id;
2368c2ecf20Sopenharmony_ci	struct ib_qp	       *qp;
2378c2ecf20Sopenharmony_ci	struct ipoib_cm_rx_buf *rx_ring;
2388c2ecf20Sopenharmony_ci	struct list_head	list;
2398c2ecf20Sopenharmony_ci	struct net_device      *dev;
2408c2ecf20Sopenharmony_ci	unsigned long		jiffies;
2418c2ecf20Sopenharmony_ci	enum ipoib_cm_state	state;
2428c2ecf20Sopenharmony_ci	int			recv_count;
2438c2ecf20Sopenharmony_ci};
2448c2ecf20Sopenharmony_ci
2458c2ecf20Sopenharmony_cistruct ipoib_cm_tx {
2468c2ecf20Sopenharmony_ci	struct ib_cm_id	    *id;
2478c2ecf20Sopenharmony_ci	struct ib_qp	    *qp;
2488c2ecf20Sopenharmony_ci	struct list_head     list;
2498c2ecf20Sopenharmony_ci	struct net_device   *dev;
2508c2ecf20Sopenharmony_ci	struct ipoib_neigh  *neigh;
2518c2ecf20Sopenharmony_ci	struct ipoib_tx_buf *tx_ring;
2528c2ecf20Sopenharmony_ci	unsigned int	     tx_head;
2538c2ecf20Sopenharmony_ci	unsigned int	     tx_tail;
2548c2ecf20Sopenharmony_ci	unsigned long	     flags;
2558c2ecf20Sopenharmony_ci	u32		     mtu;
2568c2ecf20Sopenharmony_ci	unsigned int         max_send_sge;
2578c2ecf20Sopenharmony_ci};
2588c2ecf20Sopenharmony_ci
2598c2ecf20Sopenharmony_cistruct ipoib_cm_rx_buf {
2608c2ecf20Sopenharmony_ci	struct sk_buff *skb;
2618c2ecf20Sopenharmony_ci	u64 mapping[IPOIB_CM_RX_SG];
2628c2ecf20Sopenharmony_ci};
2638c2ecf20Sopenharmony_ci
2648c2ecf20Sopenharmony_cistruct ipoib_cm_dev_priv {
2658c2ecf20Sopenharmony_ci	struct ib_srq	       *srq;
2668c2ecf20Sopenharmony_ci	struct ipoib_cm_rx_buf *srq_ring;
2678c2ecf20Sopenharmony_ci	struct ib_cm_id	       *id;
2688c2ecf20Sopenharmony_ci	struct list_head	passive_ids;   /* state: LIVE */
2698c2ecf20Sopenharmony_ci	struct list_head	rx_error_list; /* state: ERROR */
2708c2ecf20Sopenharmony_ci	struct list_head	rx_flush_list; /* state: FLUSH, drain not started */
2718c2ecf20Sopenharmony_ci	struct list_head	rx_drain_list; /* state: FLUSH, drain started */
2728c2ecf20Sopenharmony_ci	struct list_head	rx_reap_list;  /* state: FLUSH, drain done */
2738c2ecf20Sopenharmony_ci	struct work_struct      start_task;
2748c2ecf20Sopenharmony_ci	struct work_struct      reap_task;
2758c2ecf20Sopenharmony_ci	struct work_struct      skb_task;
2768c2ecf20Sopenharmony_ci	struct work_struct      rx_reap_task;
2778c2ecf20Sopenharmony_ci	struct delayed_work     stale_task;
2788c2ecf20Sopenharmony_ci	struct sk_buff_head     skb_queue;
2798c2ecf20Sopenharmony_ci	struct list_head	start_list;
2808c2ecf20Sopenharmony_ci	struct list_head	reap_list;
2818c2ecf20Sopenharmony_ci	struct ib_wc		ibwc[IPOIB_NUM_WC];
2828c2ecf20Sopenharmony_ci	struct ib_sge		rx_sge[IPOIB_CM_RX_SG];
2838c2ecf20Sopenharmony_ci	struct ib_recv_wr       rx_wr;
2848c2ecf20Sopenharmony_ci	int			nonsrq_conn_qp;
2858c2ecf20Sopenharmony_ci	int			max_cm_mtu;
2868c2ecf20Sopenharmony_ci	int			num_frags;
2878c2ecf20Sopenharmony_ci};
2888c2ecf20Sopenharmony_ci
2898c2ecf20Sopenharmony_cistruct ipoib_ethtool_st {
2908c2ecf20Sopenharmony_ci	u16     coalesce_usecs;
2918c2ecf20Sopenharmony_ci	u16     max_coalesced_frames;
2928c2ecf20Sopenharmony_ci};
2938c2ecf20Sopenharmony_ci
2948c2ecf20Sopenharmony_cistruct ipoib_neigh_table;
2958c2ecf20Sopenharmony_ci
2968c2ecf20Sopenharmony_cistruct ipoib_neigh_hash {
2978c2ecf20Sopenharmony_ci	struct ipoib_neigh_table       *ntbl;
2988c2ecf20Sopenharmony_ci	struct ipoib_neigh __rcu      **buckets;
2998c2ecf20Sopenharmony_ci	struct rcu_head			rcu;
3008c2ecf20Sopenharmony_ci	u32				mask;
3018c2ecf20Sopenharmony_ci	u32				size;
3028c2ecf20Sopenharmony_ci};
3038c2ecf20Sopenharmony_ci
3048c2ecf20Sopenharmony_cistruct ipoib_neigh_table {
3058c2ecf20Sopenharmony_ci	struct ipoib_neigh_hash __rcu  *htbl;
3068c2ecf20Sopenharmony_ci	atomic_t			entries;
3078c2ecf20Sopenharmony_ci	struct completion		flushed;
3088c2ecf20Sopenharmony_ci	struct completion		deleted;
3098c2ecf20Sopenharmony_ci};
3108c2ecf20Sopenharmony_ci
3118c2ecf20Sopenharmony_cistruct ipoib_qp_state_validate {
3128c2ecf20Sopenharmony_ci	struct work_struct work;
3138c2ecf20Sopenharmony_ci	struct ipoib_dev_priv   *priv;
3148c2ecf20Sopenharmony_ci};
3158c2ecf20Sopenharmony_ci
3168c2ecf20Sopenharmony_ci/*
3178c2ecf20Sopenharmony_ci * Device private locking: network stack tx_lock protects members used
3188c2ecf20Sopenharmony_ci * in TX fast path, lock protects everything else.  lock nests inside
3198c2ecf20Sopenharmony_ci * of tx_lock (ie tx_lock must be acquired first if needed).
3208c2ecf20Sopenharmony_ci */
3218c2ecf20Sopenharmony_cistruct ipoib_dev_priv {
3228c2ecf20Sopenharmony_ci	spinlock_t lock;
3238c2ecf20Sopenharmony_ci
3248c2ecf20Sopenharmony_ci	struct net_device *dev;
3258c2ecf20Sopenharmony_ci	void (*next_priv_destructor)(struct net_device *dev);
3268c2ecf20Sopenharmony_ci
3278c2ecf20Sopenharmony_ci	struct napi_struct send_napi;
3288c2ecf20Sopenharmony_ci	struct napi_struct recv_napi;
3298c2ecf20Sopenharmony_ci
3308c2ecf20Sopenharmony_ci	unsigned long flags;
3318c2ecf20Sopenharmony_ci
3328c2ecf20Sopenharmony_ci	/*
3338c2ecf20Sopenharmony_ci	 * This protects access to the child_intfs list.
3348c2ecf20Sopenharmony_ci	 * To READ from child_intfs the RTNL or vlan_rwsem read side must be
3358c2ecf20Sopenharmony_ci	 * held.  To WRITE RTNL and the vlan_rwsem write side must be held (in
3368c2ecf20Sopenharmony_ci	 * that order) This lock exists because we have a few contexts where
3378c2ecf20Sopenharmony_ci	 * we need the child_intfs, but do not want to grab the RTNL.
3388c2ecf20Sopenharmony_ci	 */
3398c2ecf20Sopenharmony_ci	struct rw_semaphore vlan_rwsem;
3408c2ecf20Sopenharmony_ci	struct mutex mcast_mutex;
3418c2ecf20Sopenharmony_ci
3428c2ecf20Sopenharmony_ci	struct rb_root  path_tree;
3438c2ecf20Sopenharmony_ci	struct list_head path_list;
3448c2ecf20Sopenharmony_ci
3458c2ecf20Sopenharmony_ci	struct ipoib_neigh_table ntbl;
3468c2ecf20Sopenharmony_ci
3478c2ecf20Sopenharmony_ci	struct ipoib_mcast *broadcast;
3488c2ecf20Sopenharmony_ci	struct list_head multicast_list;
3498c2ecf20Sopenharmony_ci	struct rb_root multicast_tree;
3508c2ecf20Sopenharmony_ci
3518c2ecf20Sopenharmony_ci	struct workqueue_struct *wq;
3528c2ecf20Sopenharmony_ci	struct delayed_work mcast_task;
3538c2ecf20Sopenharmony_ci	struct work_struct carrier_on_task;
3548c2ecf20Sopenharmony_ci	struct work_struct flush_light;
3558c2ecf20Sopenharmony_ci	struct work_struct flush_normal;
3568c2ecf20Sopenharmony_ci	struct work_struct flush_heavy;
3578c2ecf20Sopenharmony_ci	struct work_struct restart_task;
3588c2ecf20Sopenharmony_ci	struct delayed_work ah_reap_task;
3598c2ecf20Sopenharmony_ci	struct delayed_work neigh_reap_task;
3608c2ecf20Sopenharmony_ci	struct ib_device *ca;
3618c2ecf20Sopenharmony_ci	u8		  port;
3628c2ecf20Sopenharmony_ci	u16		  pkey;
3638c2ecf20Sopenharmony_ci	u16		  pkey_index;
3648c2ecf20Sopenharmony_ci	struct ib_pd	 *pd;
3658c2ecf20Sopenharmony_ci	struct ib_cq	 *recv_cq;
3668c2ecf20Sopenharmony_ci	struct ib_cq	 *send_cq;
3678c2ecf20Sopenharmony_ci	struct ib_qp	 *qp;
3688c2ecf20Sopenharmony_ci	u32		  qkey;
3698c2ecf20Sopenharmony_ci
3708c2ecf20Sopenharmony_ci	union ib_gid local_gid;
3718c2ecf20Sopenharmony_ci	u32	     local_lid;
3728c2ecf20Sopenharmony_ci
3738c2ecf20Sopenharmony_ci	unsigned int admin_mtu;
3748c2ecf20Sopenharmony_ci	unsigned int mcast_mtu;
3758c2ecf20Sopenharmony_ci	unsigned int max_ib_mtu;
3768c2ecf20Sopenharmony_ci
3778c2ecf20Sopenharmony_ci	struct ipoib_rx_buf *rx_ring;
3788c2ecf20Sopenharmony_ci
3798c2ecf20Sopenharmony_ci	struct ipoib_tx_buf *tx_ring;
3808c2ecf20Sopenharmony_ci	/* cyclic ring variables for managing tx_ring, for UD only */
3818c2ecf20Sopenharmony_ci	unsigned int	     tx_head;
3828c2ecf20Sopenharmony_ci	unsigned int	     tx_tail;
3838c2ecf20Sopenharmony_ci	/* cyclic ring variables for counting overall outstanding send WRs */
3848c2ecf20Sopenharmony_ci	unsigned int	     global_tx_head;
3858c2ecf20Sopenharmony_ci	unsigned int	     global_tx_tail;
3868c2ecf20Sopenharmony_ci	struct ib_sge	     tx_sge[MAX_SKB_FRAGS + 1];
3878c2ecf20Sopenharmony_ci	struct ib_ud_wr      tx_wr;
3888c2ecf20Sopenharmony_ci	struct ib_wc	     send_wc[MAX_SEND_CQE];
3898c2ecf20Sopenharmony_ci
3908c2ecf20Sopenharmony_ci	struct ib_recv_wr    rx_wr;
3918c2ecf20Sopenharmony_ci	struct ib_sge	     rx_sge[IPOIB_UD_RX_SG];
3928c2ecf20Sopenharmony_ci
3938c2ecf20Sopenharmony_ci	struct ib_wc ibwc[IPOIB_NUM_WC];
3948c2ecf20Sopenharmony_ci
3958c2ecf20Sopenharmony_ci	struct list_head dead_ahs;
3968c2ecf20Sopenharmony_ci
3978c2ecf20Sopenharmony_ci	struct ib_event_handler event_handler;
3988c2ecf20Sopenharmony_ci
3998c2ecf20Sopenharmony_ci	struct net_device *parent;
4008c2ecf20Sopenharmony_ci	struct list_head child_intfs;
4018c2ecf20Sopenharmony_ci	struct list_head list;
4028c2ecf20Sopenharmony_ci	int    child_type;
4038c2ecf20Sopenharmony_ci
4048c2ecf20Sopenharmony_ci#ifdef CONFIG_INFINIBAND_IPOIB_CM
4058c2ecf20Sopenharmony_ci	struct ipoib_cm_dev_priv cm;
4068c2ecf20Sopenharmony_ci#endif
4078c2ecf20Sopenharmony_ci
4088c2ecf20Sopenharmony_ci#ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
4098c2ecf20Sopenharmony_ci	struct list_head fs_list;
4108c2ecf20Sopenharmony_ci	struct dentry *mcg_dentry;
4118c2ecf20Sopenharmony_ci	struct dentry *path_dentry;
4128c2ecf20Sopenharmony_ci#endif
4138c2ecf20Sopenharmony_ci	u64	hca_caps;
4148c2ecf20Sopenharmony_ci	struct ipoib_ethtool_st ethtool;
4158c2ecf20Sopenharmony_ci	unsigned int max_send_sge;
4168c2ecf20Sopenharmony_ci	bool sm_fullmember_sendonly_support;
4178c2ecf20Sopenharmony_ci	const struct net_device_ops	*rn_ops;
4188c2ecf20Sopenharmony_ci};
4198c2ecf20Sopenharmony_ci
4208c2ecf20Sopenharmony_cistruct ipoib_ah {
4218c2ecf20Sopenharmony_ci	struct net_device *dev;
4228c2ecf20Sopenharmony_ci	struct ib_ah	  *ah;
4238c2ecf20Sopenharmony_ci	struct list_head   list;
4248c2ecf20Sopenharmony_ci	struct kref	   ref;
4258c2ecf20Sopenharmony_ci	unsigned int	   last_send;
4268c2ecf20Sopenharmony_ci	int  		   valid;
4278c2ecf20Sopenharmony_ci};
4288c2ecf20Sopenharmony_ci
4298c2ecf20Sopenharmony_cistruct ipoib_path {
4308c2ecf20Sopenharmony_ci	struct net_device    *dev;
4318c2ecf20Sopenharmony_ci	struct sa_path_rec pathrec;
4328c2ecf20Sopenharmony_ci	struct ipoib_ah      *ah;
4338c2ecf20Sopenharmony_ci	struct sk_buff_head   queue;
4348c2ecf20Sopenharmony_ci
4358c2ecf20Sopenharmony_ci	struct list_head      neigh_list;
4368c2ecf20Sopenharmony_ci
4378c2ecf20Sopenharmony_ci	int		      query_id;
4388c2ecf20Sopenharmony_ci	struct ib_sa_query   *query;
4398c2ecf20Sopenharmony_ci	struct completion     done;
4408c2ecf20Sopenharmony_ci
4418c2ecf20Sopenharmony_ci	struct rb_node	      rb_node;
4428c2ecf20Sopenharmony_ci	struct list_head      list;
4438c2ecf20Sopenharmony_ci};
4448c2ecf20Sopenharmony_ci
4458c2ecf20Sopenharmony_cistruct ipoib_neigh {
4468c2ecf20Sopenharmony_ci	struct ipoib_ah    *ah;
4478c2ecf20Sopenharmony_ci#ifdef CONFIG_INFINIBAND_IPOIB_CM
4488c2ecf20Sopenharmony_ci	struct ipoib_cm_tx *cm;
4498c2ecf20Sopenharmony_ci#endif
4508c2ecf20Sopenharmony_ci	u8     daddr[INFINIBAND_ALEN];
4518c2ecf20Sopenharmony_ci	struct sk_buff_head queue;
4528c2ecf20Sopenharmony_ci
4538c2ecf20Sopenharmony_ci	struct net_device *dev;
4548c2ecf20Sopenharmony_ci
4558c2ecf20Sopenharmony_ci	struct list_head    list;
4568c2ecf20Sopenharmony_ci	struct ipoib_neigh __rcu *hnext;
4578c2ecf20Sopenharmony_ci	struct rcu_head     rcu;
4588c2ecf20Sopenharmony_ci	atomic_t	    refcnt;
4598c2ecf20Sopenharmony_ci	unsigned long       alive;
4608c2ecf20Sopenharmony_ci};
4618c2ecf20Sopenharmony_ci
4628c2ecf20Sopenharmony_ci#define IPOIB_UD_MTU(ib_mtu)		(ib_mtu - IPOIB_ENCAP_LEN)
4638c2ecf20Sopenharmony_ci#define IPOIB_UD_BUF_SIZE(ib_mtu)	(ib_mtu + IB_GRH_BYTES)
4648c2ecf20Sopenharmony_ci
4658c2ecf20Sopenharmony_civoid ipoib_neigh_dtor(struct ipoib_neigh *neigh);
4668c2ecf20Sopenharmony_cistatic inline void ipoib_neigh_put(struct ipoib_neigh *neigh)
4678c2ecf20Sopenharmony_ci{
4688c2ecf20Sopenharmony_ci	if (atomic_dec_and_test(&neigh->refcnt))
4698c2ecf20Sopenharmony_ci		ipoib_neigh_dtor(neigh);
4708c2ecf20Sopenharmony_ci}
4718c2ecf20Sopenharmony_cistruct ipoib_neigh *ipoib_neigh_get(struct net_device *dev, u8 *daddr);
4728c2ecf20Sopenharmony_cistruct ipoib_neigh *ipoib_neigh_alloc(u8 *daddr,
4738c2ecf20Sopenharmony_ci				      struct net_device *dev);
4748c2ecf20Sopenharmony_civoid ipoib_neigh_free(struct ipoib_neigh *neigh);
4758c2ecf20Sopenharmony_civoid ipoib_del_neighs_by_gid(struct net_device *dev, u8 *gid);
4768c2ecf20Sopenharmony_ci
4778c2ecf20Sopenharmony_ciextern struct workqueue_struct *ipoib_workqueue;
4788c2ecf20Sopenharmony_ci
4798c2ecf20Sopenharmony_ci/* functions */
4808c2ecf20Sopenharmony_ci
4818c2ecf20Sopenharmony_ciint ipoib_rx_poll(struct napi_struct *napi, int budget);
4828c2ecf20Sopenharmony_ciint ipoib_tx_poll(struct napi_struct *napi, int budget);
4838c2ecf20Sopenharmony_civoid ipoib_ib_rx_completion(struct ib_cq *cq, void *ctx_ptr);
4848c2ecf20Sopenharmony_civoid ipoib_ib_tx_completion(struct ib_cq *cq, void *ctx_ptr);
4858c2ecf20Sopenharmony_ci
4868c2ecf20Sopenharmony_cistruct ipoib_ah *ipoib_create_ah(struct net_device *dev,
4878c2ecf20Sopenharmony_ci				 struct ib_pd *pd, struct rdma_ah_attr *attr);
4888c2ecf20Sopenharmony_civoid ipoib_free_ah(struct kref *kref);
4898c2ecf20Sopenharmony_cistatic inline void ipoib_put_ah(struct ipoib_ah *ah)
4908c2ecf20Sopenharmony_ci{
4918c2ecf20Sopenharmony_ci	kref_put(&ah->ref, ipoib_free_ah);
4928c2ecf20Sopenharmony_ci}
4938c2ecf20Sopenharmony_ciint ipoib_open(struct net_device *dev);
4948c2ecf20Sopenharmony_civoid ipoib_intf_free(struct net_device *dev);
4958c2ecf20Sopenharmony_ciint ipoib_add_pkey_attr(struct net_device *dev);
4968c2ecf20Sopenharmony_ciint ipoib_add_umcast_attr(struct net_device *dev);
4978c2ecf20Sopenharmony_ci
4988c2ecf20Sopenharmony_ciint ipoib_send(struct net_device *dev, struct sk_buff *skb,
4998c2ecf20Sopenharmony_ci	       struct ib_ah *address, u32 dqpn);
5008c2ecf20Sopenharmony_civoid ipoib_reap_ah(struct work_struct *work);
5018c2ecf20Sopenharmony_ci
5028c2ecf20Sopenharmony_cistruct ipoib_path *__path_find(struct net_device *dev, void *gid);
5038c2ecf20Sopenharmony_civoid ipoib_mark_paths_invalid(struct net_device *dev);
5048c2ecf20Sopenharmony_civoid ipoib_flush_paths(struct net_device *dev);
5058c2ecf20Sopenharmony_cistruct net_device *ipoib_intf_alloc(struct ib_device *hca, u8 port,
5068c2ecf20Sopenharmony_ci				    const char *format);
5078c2ecf20Sopenharmony_ciint ipoib_intf_init(struct ib_device *hca, u8 port, const char *format,
5088c2ecf20Sopenharmony_ci		    struct net_device *dev);
5098c2ecf20Sopenharmony_civoid ipoib_ib_tx_timer_func(struct timer_list *t);
5108c2ecf20Sopenharmony_civoid ipoib_ib_dev_flush_light(struct work_struct *work);
5118c2ecf20Sopenharmony_civoid ipoib_ib_dev_flush_normal(struct work_struct *work);
5128c2ecf20Sopenharmony_civoid ipoib_ib_dev_flush_heavy(struct work_struct *work);
5138c2ecf20Sopenharmony_civoid ipoib_pkey_event(struct work_struct *work);
5148c2ecf20Sopenharmony_civoid ipoib_ib_dev_cleanup(struct net_device *dev);
5158c2ecf20Sopenharmony_ci
5168c2ecf20Sopenharmony_ciint ipoib_ib_dev_open_default(struct net_device *dev);
5178c2ecf20Sopenharmony_ciint ipoib_ib_dev_open(struct net_device *dev);
5188c2ecf20Sopenharmony_civoid ipoib_ib_dev_stop(struct net_device *dev);
5198c2ecf20Sopenharmony_civoid ipoib_ib_dev_up(struct net_device *dev);
5208c2ecf20Sopenharmony_civoid ipoib_ib_dev_down(struct net_device *dev);
5218c2ecf20Sopenharmony_ciint ipoib_ib_dev_stop_default(struct net_device *dev);
5228c2ecf20Sopenharmony_civoid ipoib_pkey_dev_check_presence(struct net_device *dev);
5238c2ecf20Sopenharmony_ci
5248c2ecf20Sopenharmony_civoid ipoib_mcast_join_task(struct work_struct *work);
5258c2ecf20Sopenharmony_civoid ipoib_mcast_carrier_on_task(struct work_struct *work);
5268c2ecf20Sopenharmony_civoid ipoib_mcast_send(struct net_device *dev, u8 *daddr, struct sk_buff *skb);
5278c2ecf20Sopenharmony_ci
5288c2ecf20Sopenharmony_civoid ipoib_mcast_restart_task(struct work_struct *work);
5298c2ecf20Sopenharmony_civoid ipoib_mcast_start_thread(struct net_device *dev);
5308c2ecf20Sopenharmony_civoid ipoib_mcast_stop_thread(struct net_device *dev);
5318c2ecf20Sopenharmony_ci
5328c2ecf20Sopenharmony_civoid ipoib_mcast_dev_down(struct net_device *dev);
5338c2ecf20Sopenharmony_civoid ipoib_mcast_dev_flush(struct net_device *dev);
5348c2ecf20Sopenharmony_ci
5358c2ecf20Sopenharmony_ciint ipoib_dma_map_tx(struct ib_device *ca, struct ipoib_tx_buf *tx_req);
5368c2ecf20Sopenharmony_civoid ipoib_dma_unmap_tx(struct ipoib_dev_priv *priv,
5378c2ecf20Sopenharmony_ci			struct ipoib_tx_buf *tx_req);
5388c2ecf20Sopenharmony_ci
5398c2ecf20Sopenharmony_cistruct rtnl_link_ops *ipoib_get_link_ops(void);
5408c2ecf20Sopenharmony_ci
5418c2ecf20Sopenharmony_cistatic inline void ipoib_build_sge(struct ipoib_dev_priv *priv,
5428c2ecf20Sopenharmony_ci				   struct ipoib_tx_buf *tx_req)
5438c2ecf20Sopenharmony_ci{
5448c2ecf20Sopenharmony_ci	int i, off;
5458c2ecf20Sopenharmony_ci	struct sk_buff *skb = tx_req->skb;
5468c2ecf20Sopenharmony_ci	skb_frag_t *frags = skb_shinfo(skb)->frags;
5478c2ecf20Sopenharmony_ci	int nr_frags = skb_shinfo(skb)->nr_frags;
5488c2ecf20Sopenharmony_ci	u64 *mapping = tx_req->mapping;
5498c2ecf20Sopenharmony_ci
5508c2ecf20Sopenharmony_ci	if (skb_headlen(skb)) {
5518c2ecf20Sopenharmony_ci		priv->tx_sge[0].addr         = mapping[0];
5528c2ecf20Sopenharmony_ci		priv->tx_sge[0].length       = skb_headlen(skb);
5538c2ecf20Sopenharmony_ci		off = 1;
5548c2ecf20Sopenharmony_ci	} else
5558c2ecf20Sopenharmony_ci		off = 0;
5568c2ecf20Sopenharmony_ci
5578c2ecf20Sopenharmony_ci	for (i = 0; i < nr_frags; ++i) {
5588c2ecf20Sopenharmony_ci		priv->tx_sge[i + off].addr = mapping[i + off];
5598c2ecf20Sopenharmony_ci		priv->tx_sge[i + off].length = skb_frag_size(&frags[i]);
5608c2ecf20Sopenharmony_ci	}
5618c2ecf20Sopenharmony_ci	priv->tx_wr.wr.num_sge	     = nr_frags + off;
5628c2ecf20Sopenharmony_ci}
5638c2ecf20Sopenharmony_ci
5648c2ecf20Sopenharmony_ci#ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
5658c2ecf20Sopenharmony_cistruct ipoib_mcast_iter *ipoib_mcast_iter_init(struct net_device *dev);
5668c2ecf20Sopenharmony_ciint ipoib_mcast_iter_next(struct ipoib_mcast_iter *iter);
5678c2ecf20Sopenharmony_civoid ipoib_mcast_iter_read(struct ipoib_mcast_iter *iter,
5688c2ecf20Sopenharmony_ci				  union ib_gid *gid,
5698c2ecf20Sopenharmony_ci				  unsigned long *created,
5708c2ecf20Sopenharmony_ci				  unsigned int *queuelen,
5718c2ecf20Sopenharmony_ci				  unsigned int *complete,
5728c2ecf20Sopenharmony_ci				  unsigned int *send_only);
5738c2ecf20Sopenharmony_ci
5748c2ecf20Sopenharmony_cistruct ipoib_path_iter *ipoib_path_iter_init(struct net_device *dev);
5758c2ecf20Sopenharmony_ciint ipoib_path_iter_next(struct ipoib_path_iter *iter);
5768c2ecf20Sopenharmony_civoid ipoib_path_iter_read(struct ipoib_path_iter *iter,
5778c2ecf20Sopenharmony_ci			  struct ipoib_path *path);
5788c2ecf20Sopenharmony_ci#endif
5798c2ecf20Sopenharmony_ci
5808c2ecf20Sopenharmony_ciint ipoib_mcast_attach(struct net_device *dev, struct ib_device *hca,
5818c2ecf20Sopenharmony_ci		       union ib_gid *mgid, u16 mlid, int set_qkey, u32 qkey);
5828c2ecf20Sopenharmony_ciint ipoib_mcast_detach(struct net_device *dev, struct ib_device *hca,
5838c2ecf20Sopenharmony_ci		       union ib_gid *mgid, u16 mlid);
5848c2ecf20Sopenharmony_civoid ipoib_mcast_remove_list(struct list_head *remove_list);
5858c2ecf20Sopenharmony_civoid ipoib_check_and_add_mcast_sendonly(struct ipoib_dev_priv *priv, u8 *mgid,
5868c2ecf20Sopenharmony_ci				struct list_head *remove_list);
5878c2ecf20Sopenharmony_ci
5888c2ecf20Sopenharmony_ciint ipoib_init_qp(struct net_device *dev);
5898c2ecf20Sopenharmony_ciint ipoib_transport_dev_init(struct net_device *dev, struct ib_device *ca);
5908c2ecf20Sopenharmony_civoid ipoib_transport_dev_cleanup(struct net_device *dev);
5918c2ecf20Sopenharmony_ci
5928c2ecf20Sopenharmony_civoid ipoib_event(struct ib_event_handler *handler,
5938c2ecf20Sopenharmony_ci		 struct ib_event *record);
5948c2ecf20Sopenharmony_ci
5958c2ecf20Sopenharmony_ciint ipoib_vlan_add(struct net_device *pdev, unsigned short pkey);
5968c2ecf20Sopenharmony_ciint ipoib_vlan_delete(struct net_device *pdev, unsigned short pkey);
5978c2ecf20Sopenharmony_ci
5988c2ecf20Sopenharmony_ciint __ipoib_vlan_add(struct ipoib_dev_priv *ppriv, struct ipoib_dev_priv *priv,
5998c2ecf20Sopenharmony_ci		     u16 pkey, int child_type);
6008c2ecf20Sopenharmony_ci
6018c2ecf20Sopenharmony_ciint  __init ipoib_netlink_init(void);
6028c2ecf20Sopenharmony_civoid __exit ipoib_netlink_fini(void);
6038c2ecf20Sopenharmony_ci
6048c2ecf20Sopenharmony_civoid ipoib_set_umcast(struct net_device *ndev, int umcast_val);
6058c2ecf20Sopenharmony_ciint  ipoib_set_mode(struct net_device *dev, const char *buf);
6068c2ecf20Sopenharmony_ci
6078c2ecf20Sopenharmony_civoid ipoib_setup_common(struct net_device *dev);
6088c2ecf20Sopenharmony_ci
6098c2ecf20Sopenharmony_civoid ipoib_pkey_open(struct ipoib_dev_priv *priv);
6108c2ecf20Sopenharmony_civoid ipoib_drain_cq(struct net_device *dev);
6118c2ecf20Sopenharmony_ci
6128c2ecf20Sopenharmony_civoid ipoib_set_ethtool_ops(struct net_device *dev);
6138c2ecf20Sopenharmony_ci
6148c2ecf20Sopenharmony_ci#define IPOIB_FLAGS_RC		0x80
6158c2ecf20Sopenharmony_ci#define IPOIB_FLAGS_UC		0x40
6168c2ecf20Sopenharmony_ci
6178c2ecf20Sopenharmony_ci/* We don't support UC connections at the moment */
6188c2ecf20Sopenharmony_ci#define IPOIB_CM_SUPPORTED(ha)   (ha[0] & (IPOIB_FLAGS_RC))
6198c2ecf20Sopenharmony_ci
6208c2ecf20Sopenharmony_ci#ifdef CONFIG_INFINIBAND_IPOIB_CM
6218c2ecf20Sopenharmony_ci
6228c2ecf20Sopenharmony_ciextern int ipoib_max_conn_qp;
6238c2ecf20Sopenharmony_ci
6248c2ecf20Sopenharmony_cistatic inline int ipoib_cm_admin_enabled(struct net_device *dev)
6258c2ecf20Sopenharmony_ci{
6268c2ecf20Sopenharmony_ci	struct ipoib_dev_priv *priv = ipoib_priv(dev);
6278c2ecf20Sopenharmony_ci	return IPOIB_CM_SUPPORTED(dev->dev_addr) &&
6288c2ecf20Sopenharmony_ci		test_bit(IPOIB_FLAG_ADMIN_CM, &priv->flags);
6298c2ecf20Sopenharmony_ci}
6308c2ecf20Sopenharmony_ci
6318c2ecf20Sopenharmony_cistatic inline int ipoib_cm_enabled(struct net_device *dev, u8 *hwaddr)
6328c2ecf20Sopenharmony_ci{
6338c2ecf20Sopenharmony_ci	struct ipoib_dev_priv *priv = ipoib_priv(dev);
6348c2ecf20Sopenharmony_ci	return IPOIB_CM_SUPPORTED(hwaddr) &&
6358c2ecf20Sopenharmony_ci		test_bit(IPOIB_FLAG_ADMIN_CM, &priv->flags);
6368c2ecf20Sopenharmony_ci}
6378c2ecf20Sopenharmony_ci
6388c2ecf20Sopenharmony_cistatic inline int ipoib_cm_up(struct ipoib_neigh *neigh)
6398c2ecf20Sopenharmony_ci
6408c2ecf20Sopenharmony_ci{
6418c2ecf20Sopenharmony_ci	return test_bit(IPOIB_FLAG_OPER_UP, &neigh->cm->flags);
6428c2ecf20Sopenharmony_ci}
6438c2ecf20Sopenharmony_ci
6448c2ecf20Sopenharmony_cistatic inline struct ipoib_cm_tx *ipoib_cm_get(struct ipoib_neigh *neigh)
6458c2ecf20Sopenharmony_ci{
6468c2ecf20Sopenharmony_ci	return neigh->cm;
6478c2ecf20Sopenharmony_ci}
6488c2ecf20Sopenharmony_ci
6498c2ecf20Sopenharmony_cistatic inline void ipoib_cm_set(struct ipoib_neigh *neigh, struct ipoib_cm_tx *tx)
6508c2ecf20Sopenharmony_ci{
6518c2ecf20Sopenharmony_ci	neigh->cm = tx;
6528c2ecf20Sopenharmony_ci}
6538c2ecf20Sopenharmony_ci
6548c2ecf20Sopenharmony_cistatic inline int ipoib_cm_has_srq(struct net_device *dev)
6558c2ecf20Sopenharmony_ci{
6568c2ecf20Sopenharmony_ci	struct ipoib_dev_priv *priv = ipoib_priv(dev);
6578c2ecf20Sopenharmony_ci	return !!priv->cm.srq;
6588c2ecf20Sopenharmony_ci}
6598c2ecf20Sopenharmony_ci
6608c2ecf20Sopenharmony_cistatic inline unsigned int ipoib_cm_max_mtu(struct net_device *dev)
6618c2ecf20Sopenharmony_ci{
6628c2ecf20Sopenharmony_ci	struct ipoib_dev_priv *priv = ipoib_priv(dev);
6638c2ecf20Sopenharmony_ci	return priv->cm.max_cm_mtu;
6648c2ecf20Sopenharmony_ci}
6658c2ecf20Sopenharmony_ci
6668c2ecf20Sopenharmony_civoid ipoib_cm_send(struct net_device *dev, struct sk_buff *skb, struct ipoib_cm_tx *tx);
6678c2ecf20Sopenharmony_ciint ipoib_cm_dev_open(struct net_device *dev);
6688c2ecf20Sopenharmony_civoid ipoib_cm_dev_stop(struct net_device *dev);
6698c2ecf20Sopenharmony_ciint ipoib_cm_dev_init(struct net_device *dev);
6708c2ecf20Sopenharmony_ciint ipoib_cm_add_mode_attr(struct net_device *dev);
6718c2ecf20Sopenharmony_civoid ipoib_cm_dev_cleanup(struct net_device *dev);
6728c2ecf20Sopenharmony_cistruct ipoib_cm_tx *ipoib_cm_create_tx(struct net_device *dev, struct ipoib_path *path,
6738c2ecf20Sopenharmony_ci				    struct ipoib_neigh *neigh);
6748c2ecf20Sopenharmony_civoid ipoib_cm_destroy_tx(struct ipoib_cm_tx *tx);
6758c2ecf20Sopenharmony_civoid ipoib_cm_skb_too_long(struct net_device *dev, struct sk_buff *skb,
6768c2ecf20Sopenharmony_ci			   unsigned int mtu);
6778c2ecf20Sopenharmony_civoid ipoib_cm_handle_rx_wc(struct net_device *dev, struct ib_wc *wc);
6788c2ecf20Sopenharmony_civoid ipoib_cm_handle_tx_wc(struct net_device *dev, struct ib_wc *wc);
6798c2ecf20Sopenharmony_ci#else
6808c2ecf20Sopenharmony_ci
6818c2ecf20Sopenharmony_cistruct ipoib_cm_tx;
6828c2ecf20Sopenharmony_ci
6838c2ecf20Sopenharmony_ci#define ipoib_max_conn_qp 0
6848c2ecf20Sopenharmony_ci
6858c2ecf20Sopenharmony_cistatic inline int ipoib_cm_admin_enabled(struct net_device *dev)
6868c2ecf20Sopenharmony_ci{
6878c2ecf20Sopenharmony_ci	return 0;
6888c2ecf20Sopenharmony_ci}
6898c2ecf20Sopenharmony_cistatic inline int ipoib_cm_enabled(struct net_device *dev, u8 *hwaddr)
6908c2ecf20Sopenharmony_ci
6918c2ecf20Sopenharmony_ci{
6928c2ecf20Sopenharmony_ci	return 0;
6938c2ecf20Sopenharmony_ci}
6948c2ecf20Sopenharmony_ci
6958c2ecf20Sopenharmony_cistatic inline int ipoib_cm_up(struct ipoib_neigh *neigh)
6968c2ecf20Sopenharmony_ci
6978c2ecf20Sopenharmony_ci{
6988c2ecf20Sopenharmony_ci	return 0;
6998c2ecf20Sopenharmony_ci}
7008c2ecf20Sopenharmony_ci
7018c2ecf20Sopenharmony_cistatic inline struct ipoib_cm_tx *ipoib_cm_get(struct ipoib_neigh *neigh)
7028c2ecf20Sopenharmony_ci{
7038c2ecf20Sopenharmony_ci	return NULL;
7048c2ecf20Sopenharmony_ci}
7058c2ecf20Sopenharmony_ci
7068c2ecf20Sopenharmony_cistatic inline void ipoib_cm_set(struct ipoib_neigh *neigh, struct ipoib_cm_tx *tx)
7078c2ecf20Sopenharmony_ci{
7088c2ecf20Sopenharmony_ci}
7098c2ecf20Sopenharmony_ci
7108c2ecf20Sopenharmony_cistatic inline int ipoib_cm_has_srq(struct net_device *dev)
7118c2ecf20Sopenharmony_ci{
7128c2ecf20Sopenharmony_ci	return 0;
7138c2ecf20Sopenharmony_ci}
7148c2ecf20Sopenharmony_ci
7158c2ecf20Sopenharmony_cistatic inline unsigned int ipoib_cm_max_mtu(struct net_device *dev)
7168c2ecf20Sopenharmony_ci{
7178c2ecf20Sopenharmony_ci	return 0;
7188c2ecf20Sopenharmony_ci}
7198c2ecf20Sopenharmony_ci
7208c2ecf20Sopenharmony_cistatic inline
7218c2ecf20Sopenharmony_civoid ipoib_cm_send(struct net_device *dev, struct sk_buff *skb, struct ipoib_cm_tx *tx)
7228c2ecf20Sopenharmony_ci{
7238c2ecf20Sopenharmony_ci	return;
7248c2ecf20Sopenharmony_ci}
7258c2ecf20Sopenharmony_ci
7268c2ecf20Sopenharmony_cistatic inline
7278c2ecf20Sopenharmony_ciint ipoib_cm_dev_open(struct net_device *dev)
7288c2ecf20Sopenharmony_ci{
7298c2ecf20Sopenharmony_ci	return 0;
7308c2ecf20Sopenharmony_ci}
7318c2ecf20Sopenharmony_ci
7328c2ecf20Sopenharmony_cistatic inline
7338c2ecf20Sopenharmony_civoid ipoib_cm_dev_stop(struct net_device *dev)
7348c2ecf20Sopenharmony_ci{
7358c2ecf20Sopenharmony_ci	return;
7368c2ecf20Sopenharmony_ci}
7378c2ecf20Sopenharmony_ci
7388c2ecf20Sopenharmony_cistatic inline
7398c2ecf20Sopenharmony_ciint ipoib_cm_dev_init(struct net_device *dev)
7408c2ecf20Sopenharmony_ci{
7418c2ecf20Sopenharmony_ci	return -EOPNOTSUPP;
7428c2ecf20Sopenharmony_ci}
7438c2ecf20Sopenharmony_ci
7448c2ecf20Sopenharmony_cistatic inline
7458c2ecf20Sopenharmony_civoid ipoib_cm_dev_cleanup(struct net_device *dev)
7468c2ecf20Sopenharmony_ci{
7478c2ecf20Sopenharmony_ci	return;
7488c2ecf20Sopenharmony_ci}
7498c2ecf20Sopenharmony_ci
7508c2ecf20Sopenharmony_cistatic inline
7518c2ecf20Sopenharmony_cistruct ipoib_cm_tx *ipoib_cm_create_tx(struct net_device *dev, struct ipoib_path *path,
7528c2ecf20Sopenharmony_ci				    struct ipoib_neigh *neigh)
7538c2ecf20Sopenharmony_ci{
7548c2ecf20Sopenharmony_ci	return NULL;
7558c2ecf20Sopenharmony_ci}
7568c2ecf20Sopenharmony_ci
7578c2ecf20Sopenharmony_cistatic inline
7588c2ecf20Sopenharmony_civoid ipoib_cm_destroy_tx(struct ipoib_cm_tx *tx)
7598c2ecf20Sopenharmony_ci{
7608c2ecf20Sopenharmony_ci	return;
7618c2ecf20Sopenharmony_ci}
7628c2ecf20Sopenharmony_ci
7638c2ecf20Sopenharmony_cistatic inline
7648c2ecf20Sopenharmony_ciint ipoib_cm_add_mode_attr(struct net_device *dev)
7658c2ecf20Sopenharmony_ci{
7668c2ecf20Sopenharmony_ci	return 0;
7678c2ecf20Sopenharmony_ci}
7688c2ecf20Sopenharmony_ci
7698c2ecf20Sopenharmony_cistatic inline void ipoib_cm_skb_too_long(struct net_device *dev, struct sk_buff *skb,
7708c2ecf20Sopenharmony_ci					 unsigned int mtu)
7718c2ecf20Sopenharmony_ci{
7728c2ecf20Sopenharmony_ci	dev_kfree_skb_any(skb);
7738c2ecf20Sopenharmony_ci}
7748c2ecf20Sopenharmony_ci
7758c2ecf20Sopenharmony_cistatic inline void ipoib_cm_handle_rx_wc(struct net_device *dev, struct ib_wc *wc)
7768c2ecf20Sopenharmony_ci{
7778c2ecf20Sopenharmony_ci}
7788c2ecf20Sopenharmony_ci
7798c2ecf20Sopenharmony_cistatic inline void ipoib_cm_handle_tx_wc(struct net_device *dev, struct ib_wc *wc)
7808c2ecf20Sopenharmony_ci{
7818c2ecf20Sopenharmony_ci}
7828c2ecf20Sopenharmony_ci#endif
7838c2ecf20Sopenharmony_ci
7848c2ecf20Sopenharmony_ci#ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
7858c2ecf20Sopenharmony_civoid ipoib_create_debug_files(struct net_device *dev);
7868c2ecf20Sopenharmony_civoid ipoib_delete_debug_files(struct net_device *dev);
7878c2ecf20Sopenharmony_civoid ipoib_register_debugfs(void);
7888c2ecf20Sopenharmony_civoid ipoib_unregister_debugfs(void);
7898c2ecf20Sopenharmony_ci#else
7908c2ecf20Sopenharmony_cistatic inline void ipoib_create_debug_files(struct net_device *dev) { }
7918c2ecf20Sopenharmony_cistatic inline void ipoib_delete_debug_files(struct net_device *dev) { }
7928c2ecf20Sopenharmony_cistatic inline void ipoib_register_debugfs(void) { }
7938c2ecf20Sopenharmony_cistatic inline void ipoib_unregister_debugfs(void) { }
7948c2ecf20Sopenharmony_ci#endif
7958c2ecf20Sopenharmony_ci
7968c2ecf20Sopenharmony_ci#define ipoib_printk(level, priv, format, arg...)	\
7978c2ecf20Sopenharmony_ci	printk(level "%s: " format, ((struct ipoib_dev_priv *) priv)->dev->name , ## arg)
7988c2ecf20Sopenharmony_ci#define ipoib_warn(priv, format, arg...)		\
7998c2ecf20Sopenharmony_cido {							\
8008c2ecf20Sopenharmony_ci	static DEFINE_RATELIMIT_STATE(_rs,		\
8018c2ecf20Sopenharmony_ci		10 * HZ /*10 seconds */,		\
8028c2ecf20Sopenharmony_ci		100);		\
8038c2ecf20Sopenharmony_ci	if (__ratelimit(&_rs))				\
8048c2ecf20Sopenharmony_ci		ipoib_printk(KERN_WARNING, priv, format , ## arg);\
8058c2ecf20Sopenharmony_ci} while (0)
8068c2ecf20Sopenharmony_ci
8078c2ecf20Sopenharmony_ciextern int ipoib_sendq_size;
8088c2ecf20Sopenharmony_ciextern int ipoib_recvq_size;
8098c2ecf20Sopenharmony_ci
8108c2ecf20Sopenharmony_ciextern struct ib_sa_client ipoib_sa_client;
8118c2ecf20Sopenharmony_ci
8128c2ecf20Sopenharmony_ci#ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
8138c2ecf20Sopenharmony_ciextern int ipoib_debug_level;
8148c2ecf20Sopenharmony_ci
8158c2ecf20Sopenharmony_ci#define ipoib_dbg(priv, format, arg...)			\
8168c2ecf20Sopenharmony_ci	do {						\
8178c2ecf20Sopenharmony_ci		if (ipoib_debug_level > 0)			\
8188c2ecf20Sopenharmony_ci			ipoib_printk(KERN_DEBUG, priv, format , ## arg); \
8198c2ecf20Sopenharmony_ci	} while (0)
8208c2ecf20Sopenharmony_ci#define ipoib_dbg_mcast(priv, format, arg...)		\
8218c2ecf20Sopenharmony_ci	do {						\
8228c2ecf20Sopenharmony_ci		if (mcast_debug_level > 0)		\
8238c2ecf20Sopenharmony_ci			ipoib_printk(KERN_DEBUG, priv, format , ## arg); \
8248c2ecf20Sopenharmony_ci	} while (0)
8258c2ecf20Sopenharmony_ci#else /* CONFIG_INFINIBAND_IPOIB_DEBUG */
8268c2ecf20Sopenharmony_ci#define ipoib_dbg(priv, format, arg...)			\
8278c2ecf20Sopenharmony_ci	do { (void) (priv); } while (0)
8288c2ecf20Sopenharmony_ci#define ipoib_dbg_mcast(priv, format, arg...)		\
8298c2ecf20Sopenharmony_ci	do { (void) (priv); } while (0)
8308c2ecf20Sopenharmony_ci#endif /* CONFIG_INFINIBAND_IPOIB_DEBUG */
8318c2ecf20Sopenharmony_ci
8328c2ecf20Sopenharmony_ci#ifdef CONFIG_INFINIBAND_IPOIB_DEBUG_DATA
8338c2ecf20Sopenharmony_ci#define ipoib_dbg_data(priv, format, arg...)		\
8348c2ecf20Sopenharmony_ci	do {						\
8358c2ecf20Sopenharmony_ci		if (data_debug_level > 0)		\
8368c2ecf20Sopenharmony_ci			ipoib_printk(KERN_DEBUG, priv, format , ## arg); \
8378c2ecf20Sopenharmony_ci	} while (0)
8388c2ecf20Sopenharmony_ci#else /* CONFIG_INFINIBAND_IPOIB_DEBUG_DATA */
8398c2ecf20Sopenharmony_ci#define ipoib_dbg_data(priv, format, arg...)		\
8408c2ecf20Sopenharmony_ci	do { (void) (priv); } while (0)
8418c2ecf20Sopenharmony_ci#endif /* CONFIG_INFINIBAND_IPOIB_DEBUG_DATA */
8428c2ecf20Sopenharmony_ci
8438c2ecf20Sopenharmony_ci#define IPOIB_QPN(ha) (be32_to_cpup((__be32 *) ha) & 0xffffff)
8448c2ecf20Sopenharmony_ci
8458c2ecf20Sopenharmony_ci#endif /* _IPOIB_H */
846