18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (c) 2004 Mellanox Technologies Ltd.  All rights reserved.
48c2ecf20Sopenharmony_ci * Copyright (c) 2004 Infinicon Corporation.  All rights reserved.
58c2ecf20Sopenharmony_ci * Copyright (c) 2004 Intel Corporation.  All rights reserved.
68c2ecf20Sopenharmony_ci * Copyright (c) 2004 Topspin Corporation.  All rights reserved.
78c2ecf20Sopenharmony_ci * Copyright (c) 2004 Voltaire Corporation.  All rights reserved.
88c2ecf20Sopenharmony_ci * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
98c2ecf20Sopenharmony_ci * Copyright (c) 2005, 2006, 2007 Cisco Systems.  All rights reserved.
108c2ecf20Sopenharmony_ci */
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#ifndef IB_VERBS_H
138c2ecf20Sopenharmony_ci#define IB_VERBS_H
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#include <linux/types.h>
168c2ecf20Sopenharmony_ci#include <linux/device.h>
178c2ecf20Sopenharmony_ci#include <linux/dma-mapping.h>
188c2ecf20Sopenharmony_ci#include <linux/kref.h>
198c2ecf20Sopenharmony_ci#include <linux/list.h>
208c2ecf20Sopenharmony_ci#include <linux/rwsem.h>
218c2ecf20Sopenharmony_ci#include <linux/workqueue.h>
228c2ecf20Sopenharmony_ci#include <linux/irq_poll.h>
238c2ecf20Sopenharmony_ci#include <uapi/linux/if_ether.h>
248c2ecf20Sopenharmony_ci#include <net/ipv6.h>
258c2ecf20Sopenharmony_ci#include <net/ip.h>
268c2ecf20Sopenharmony_ci#include <linux/string.h>
278c2ecf20Sopenharmony_ci#include <linux/slab.h>
288c2ecf20Sopenharmony_ci#include <linux/netdevice.h>
298c2ecf20Sopenharmony_ci#include <linux/refcount.h>
308c2ecf20Sopenharmony_ci#include <linux/if_link.h>
318c2ecf20Sopenharmony_ci#include <linux/atomic.h>
328c2ecf20Sopenharmony_ci#include <linux/mmu_notifier.h>
338c2ecf20Sopenharmony_ci#include <linux/uaccess.h>
348c2ecf20Sopenharmony_ci#include <linux/cgroup_rdma.h>
358c2ecf20Sopenharmony_ci#include <linux/irqflags.h>
368c2ecf20Sopenharmony_ci#include <linux/preempt.h>
378c2ecf20Sopenharmony_ci#include <linux/dim.h>
388c2ecf20Sopenharmony_ci#include <uapi/rdma/ib_user_verbs.h>
398c2ecf20Sopenharmony_ci#include <rdma/rdma_counter.h>
408c2ecf20Sopenharmony_ci#include <rdma/restrack.h>
418c2ecf20Sopenharmony_ci#include <rdma/signature.h>
428c2ecf20Sopenharmony_ci#include <uapi/rdma/rdma_user_ioctl.h>
438c2ecf20Sopenharmony_ci#include <uapi/rdma/ib_user_ioctl_verbs.h>
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci#define IB_FW_VERSION_NAME_MAX	ETHTOOL_FWVERS_LEN
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_cistruct ib_umem_odp;
488c2ecf20Sopenharmony_cistruct ib_uqp_object;
498c2ecf20Sopenharmony_cistruct ib_usrq_object;
508c2ecf20Sopenharmony_cistruct ib_uwq_object;
518c2ecf20Sopenharmony_cistruct rdma_cm_id;
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ciextern struct workqueue_struct *ib_wq;
548c2ecf20Sopenharmony_ciextern struct workqueue_struct *ib_comp_wq;
558c2ecf20Sopenharmony_ciextern struct workqueue_struct *ib_comp_unbound_wq;
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_cistruct ib_ucq_object;
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci__printf(3, 4) __cold
608c2ecf20Sopenharmony_civoid ibdev_printk(const char *level, const struct ib_device *ibdev,
618c2ecf20Sopenharmony_ci		  const char *format, ...);
628c2ecf20Sopenharmony_ci__printf(2, 3) __cold
638c2ecf20Sopenharmony_civoid ibdev_emerg(const struct ib_device *ibdev, const char *format, ...);
648c2ecf20Sopenharmony_ci__printf(2, 3) __cold
658c2ecf20Sopenharmony_civoid ibdev_alert(const struct ib_device *ibdev, const char *format, ...);
668c2ecf20Sopenharmony_ci__printf(2, 3) __cold
678c2ecf20Sopenharmony_civoid ibdev_crit(const struct ib_device *ibdev, const char *format, ...);
688c2ecf20Sopenharmony_ci__printf(2, 3) __cold
698c2ecf20Sopenharmony_civoid ibdev_err(const struct ib_device *ibdev, const char *format, ...);
708c2ecf20Sopenharmony_ci__printf(2, 3) __cold
718c2ecf20Sopenharmony_civoid ibdev_warn(const struct ib_device *ibdev, const char *format, ...);
728c2ecf20Sopenharmony_ci__printf(2, 3) __cold
738c2ecf20Sopenharmony_civoid ibdev_notice(const struct ib_device *ibdev, const char *format, ...);
748c2ecf20Sopenharmony_ci__printf(2, 3) __cold
758c2ecf20Sopenharmony_civoid ibdev_info(const struct ib_device *ibdev, const char *format, ...);
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci#if defined(CONFIG_DYNAMIC_DEBUG) || \
788c2ecf20Sopenharmony_ci	(defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
798c2ecf20Sopenharmony_ci#define ibdev_dbg(__dev, format, args...)                       \
808c2ecf20Sopenharmony_ci	dynamic_ibdev_dbg(__dev, format, ##args)
818c2ecf20Sopenharmony_ci#else
828c2ecf20Sopenharmony_ci__printf(2, 3) __cold
838c2ecf20Sopenharmony_cistatic inline
848c2ecf20Sopenharmony_civoid ibdev_dbg(const struct ib_device *ibdev, const char *format, ...) {}
858c2ecf20Sopenharmony_ci#endif
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci#define ibdev_level_ratelimited(ibdev_level, ibdev, fmt, ...)           \
888c2ecf20Sopenharmony_cido {                                                                    \
898c2ecf20Sopenharmony_ci	static DEFINE_RATELIMIT_STATE(_rs,                              \
908c2ecf20Sopenharmony_ci				      DEFAULT_RATELIMIT_INTERVAL,       \
918c2ecf20Sopenharmony_ci				      DEFAULT_RATELIMIT_BURST);         \
928c2ecf20Sopenharmony_ci	if (__ratelimit(&_rs))                                          \
938c2ecf20Sopenharmony_ci		ibdev_level(ibdev, fmt, ##__VA_ARGS__);                 \
948c2ecf20Sopenharmony_ci} while (0)
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_ci#define ibdev_emerg_ratelimited(ibdev, fmt, ...) \
978c2ecf20Sopenharmony_ci	ibdev_level_ratelimited(ibdev_emerg, ibdev, fmt, ##__VA_ARGS__)
988c2ecf20Sopenharmony_ci#define ibdev_alert_ratelimited(ibdev, fmt, ...) \
998c2ecf20Sopenharmony_ci	ibdev_level_ratelimited(ibdev_alert, ibdev, fmt, ##__VA_ARGS__)
1008c2ecf20Sopenharmony_ci#define ibdev_crit_ratelimited(ibdev, fmt, ...) \
1018c2ecf20Sopenharmony_ci	ibdev_level_ratelimited(ibdev_crit, ibdev, fmt, ##__VA_ARGS__)
1028c2ecf20Sopenharmony_ci#define ibdev_err_ratelimited(ibdev, fmt, ...) \
1038c2ecf20Sopenharmony_ci	ibdev_level_ratelimited(ibdev_err, ibdev, fmt, ##__VA_ARGS__)
1048c2ecf20Sopenharmony_ci#define ibdev_warn_ratelimited(ibdev, fmt, ...) \
1058c2ecf20Sopenharmony_ci	ibdev_level_ratelimited(ibdev_warn, ibdev, fmt, ##__VA_ARGS__)
1068c2ecf20Sopenharmony_ci#define ibdev_notice_ratelimited(ibdev, fmt, ...) \
1078c2ecf20Sopenharmony_ci	ibdev_level_ratelimited(ibdev_notice, ibdev, fmt, ##__VA_ARGS__)
1088c2ecf20Sopenharmony_ci#define ibdev_info_ratelimited(ibdev, fmt, ...) \
1098c2ecf20Sopenharmony_ci	ibdev_level_ratelimited(ibdev_info, ibdev, fmt, ##__VA_ARGS__)
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_ci#if defined(CONFIG_DYNAMIC_DEBUG) || \
1128c2ecf20Sopenharmony_ci	(defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
1138c2ecf20Sopenharmony_ci/* descriptor check is first to prevent flooding with "callbacks suppressed" */
1148c2ecf20Sopenharmony_ci#define ibdev_dbg_ratelimited(ibdev, fmt, ...)                          \
1158c2ecf20Sopenharmony_cido {                                                                    \
1168c2ecf20Sopenharmony_ci	static DEFINE_RATELIMIT_STATE(_rs,                              \
1178c2ecf20Sopenharmony_ci				      DEFAULT_RATELIMIT_INTERVAL,       \
1188c2ecf20Sopenharmony_ci				      DEFAULT_RATELIMIT_BURST);         \
1198c2ecf20Sopenharmony_ci	DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt);                 \
1208c2ecf20Sopenharmony_ci	if (DYNAMIC_DEBUG_BRANCH(descriptor) && __ratelimit(&_rs))      \
1218c2ecf20Sopenharmony_ci		__dynamic_ibdev_dbg(&descriptor, ibdev, fmt,            \
1228c2ecf20Sopenharmony_ci				    ##__VA_ARGS__);                     \
1238c2ecf20Sopenharmony_ci} while (0)
1248c2ecf20Sopenharmony_ci#else
1258c2ecf20Sopenharmony_ci__printf(2, 3) __cold
1268c2ecf20Sopenharmony_cistatic inline
1278c2ecf20Sopenharmony_civoid ibdev_dbg_ratelimited(const struct ib_device *ibdev, const char *format, ...) {}
1288c2ecf20Sopenharmony_ci#endif
1298c2ecf20Sopenharmony_ci
1308c2ecf20Sopenharmony_ciunion ib_gid {
1318c2ecf20Sopenharmony_ci	u8	raw[16];
1328c2ecf20Sopenharmony_ci	struct {
1338c2ecf20Sopenharmony_ci		__be64	subnet_prefix;
1348c2ecf20Sopenharmony_ci		__be64	interface_id;
1358c2ecf20Sopenharmony_ci	} global;
1368c2ecf20Sopenharmony_ci};
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ciextern union ib_gid zgid;
1398c2ecf20Sopenharmony_ci
1408c2ecf20Sopenharmony_cienum ib_gid_type {
1418c2ecf20Sopenharmony_ci	IB_GID_TYPE_IB = IB_UVERBS_GID_TYPE_IB,
1428c2ecf20Sopenharmony_ci	IB_GID_TYPE_ROCE = IB_UVERBS_GID_TYPE_ROCE_V1,
1438c2ecf20Sopenharmony_ci	IB_GID_TYPE_ROCE_UDP_ENCAP = IB_UVERBS_GID_TYPE_ROCE_V2,
1448c2ecf20Sopenharmony_ci	IB_GID_TYPE_SIZE
1458c2ecf20Sopenharmony_ci};
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_ci#define ROCE_V2_UDP_DPORT      4791
1488c2ecf20Sopenharmony_cistruct ib_gid_attr {
1498c2ecf20Sopenharmony_ci	struct net_device __rcu	*ndev;
1508c2ecf20Sopenharmony_ci	struct ib_device	*device;
1518c2ecf20Sopenharmony_ci	union ib_gid		gid;
1528c2ecf20Sopenharmony_ci	enum ib_gid_type	gid_type;
1538c2ecf20Sopenharmony_ci	u16			index;
1548c2ecf20Sopenharmony_ci	u8			port_num;
1558c2ecf20Sopenharmony_ci};
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_cienum {
1588c2ecf20Sopenharmony_ci	/* set the local administered indication */
1598c2ecf20Sopenharmony_ci	IB_SA_WELL_KNOWN_GUID	= BIT_ULL(57) | 2,
1608c2ecf20Sopenharmony_ci};
1618c2ecf20Sopenharmony_ci
1628c2ecf20Sopenharmony_cienum rdma_transport_type {
1638c2ecf20Sopenharmony_ci	RDMA_TRANSPORT_IB,
1648c2ecf20Sopenharmony_ci	RDMA_TRANSPORT_IWARP,
1658c2ecf20Sopenharmony_ci	RDMA_TRANSPORT_USNIC,
1668c2ecf20Sopenharmony_ci	RDMA_TRANSPORT_USNIC_UDP,
1678c2ecf20Sopenharmony_ci	RDMA_TRANSPORT_UNSPECIFIED,
1688c2ecf20Sopenharmony_ci};
1698c2ecf20Sopenharmony_ci
1708c2ecf20Sopenharmony_cienum rdma_protocol_type {
1718c2ecf20Sopenharmony_ci	RDMA_PROTOCOL_IB,
1728c2ecf20Sopenharmony_ci	RDMA_PROTOCOL_IBOE,
1738c2ecf20Sopenharmony_ci	RDMA_PROTOCOL_IWARP,
1748c2ecf20Sopenharmony_ci	RDMA_PROTOCOL_USNIC_UDP
1758c2ecf20Sopenharmony_ci};
1768c2ecf20Sopenharmony_ci
1778c2ecf20Sopenharmony_ci__attribute_const__ enum rdma_transport_type
1788c2ecf20Sopenharmony_cirdma_node_get_transport(unsigned int node_type);
1798c2ecf20Sopenharmony_ci
1808c2ecf20Sopenharmony_cienum rdma_network_type {
1818c2ecf20Sopenharmony_ci	RDMA_NETWORK_IB,
1828c2ecf20Sopenharmony_ci	RDMA_NETWORK_ROCE_V1,
1838c2ecf20Sopenharmony_ci	RDMA_NETWORK_IPV4,
1848c2ecf20Sopenharmony_ci	RDMA_NETWORK_IPV6
1858c2ecf20Sopenharmony_ci};
1868c2ecf20Sopenharmony_ci
1878c2ecf20Sopenharmony_cistatic inline enum ib_gid_type ib_network_to_gid_type(enum rdma_network_type network_type)
1888c2ecf20Sopenharmony_ci{
1898c2ecf20Sopenharmony_ci	if (network_type == RDMA_NETWORK_IPV4 ||
1908c2ecf20Sopenharmony_ci	    network_type == RDMA_NETWORK_IPV6)
1918c2ecf20Sopenharmony_ci		return IB_GID_TYPE_ROCE_UDP_ENCAP;
1928c2ecf20Sopenharmony_ci	else if (network_type == RDMA_NETWORK_ROCE_V1)
1938c2ecf20Sopenharmony_ci		return IB_GID_TYPE_ROCE;
1948c2ecf20Sopenharmony_ci	else
1958c2ecf20Sopenharmony_ci		return IB_GID_TYPE_IB;
1968c2ecf20Sopenharmony_ci}
1978c2ecf20Sopenharmony_ci
1988c2ecf20Sopenharmony_cistatic inline enum rdma_network_type
1998c2ecf20Sopenharmony_cirdma_gid_attr_network_type(const struct ib_gid_attr *attr)
2008c2ecf20Sopenharmony_ci{
2018c2ecf20Sopenharmony_ci	if (attr->gid_type == IB_GID_TYPE_IB)
2028c2ecf20Sopenharmony_ci		return RDMA_NETWORK_IB;
2038c2ecf20Sopenharmony_ci
2048c2ecf20Sopenharmony_ci	if (attr->gid_type == IB_GID_TYPE_ROCE)
2058c2ecf20Sopenharmony_ci		return RDMA_NETWORK_ROCE_V1;
2068c2ecf20Sopenharmony_ci
2078c2ecf20Sopenharmony_ci	if (ipv6_addr_v4mapped((struct in6_addr *)&attr->gid))
2088c2ecf20Sopenharmony_ci		return RDMA_NETWORK_IPV4;
2098c2ecf20Sopenharmony_ci	else
2108c2ecf20Sopenharmony_ci		return RDMA_NETWORK_IPV6;
2118c2ecf20Sopenharmony_ci}
2128c2ecf20Sopenharmony_ci
2138c2ecf20Sopenharmony_cienum rdma_link_layer {
2148c2ecf20Sopenharmony_ci	IB_LINK_LAYER_UNSPECIFIED,
2158c2ecf20Sopenharmony_ci	IB_LINK_LAYER_INFINIBAND,
2168c2ecf20Sopenharmony_ci	IB_LINK_LAYER_ETHERNET,
2178c2ecf20Sopenharmony_ci};
2188c2ecf20Sopenharmony_ci
2198c2ecf20Sopenharmony_cienum ib_device_cap_flags {
2208c2ecf20Sopenharmony_ci	IB_DEVICE_RESIZE_MAX_WR			= (1 << 0),
2218c2ecf20Sopenharmony_ci	IB_DEVICE_BAD_PKEY_CNTR			= (1 << 1),
2228c2ecf20Sopenharmony_ci	IB_DEVICE_BAD_QKEY_CNTR			= (1 << 2),
2238c2ecf20Sopenharmony_ci	IB_DEVICE_RAW_MULTI			= (1 << 3),
2248c2ecf20Sopenharmony_ci	IB_DEVICE_AUTO_PATH_MIG			= (1 << 4),
2258c2ecf20Sopenharmony_ci	IB_DEVICE_CHANGE_PHY_PORT		= (1 << 5),
2268c2ecf20Sopenharmony_ci	IB_DEVICE_UD_AV_PORT_ENFORCE		= (1 << 6),
2278c2ecf20Sopenharmony_ci	IB_DEVICE_CURR_QP_STATE_MOD		= (1 << 7),
2288c2ecf20Sopenharmony_ci	IB_DEVICE_SHUTDOWN_PORT			= (1 << 8),
2298c2ecf20Sopenharmony_ci	/* Not in use, former INIT_TYPE		= (1 << 9),*/
2308c2ecf20Sopenharmony_ci	IB_DEVICE_PORT_ACTIVE_EVENT		= (1 << 10),
2318c2ecf20Sopenharmony_ci	IB_DEVICE_SYS_IMAGE_GUID		= (1 << 11),
2328c2ecf20Sopenharmony_ci	IB_DEVICE_RC_RNR_NAK_GEN		= (1 << 12),
2338c2ecf20Sopenharmony_ci	IB_DEVICE_SRQ_RESIZE			= (1 << 13),
2348c2ecf20Sopenharmony_ci	IB_DEVICE_N_NOTIFY_CQ			= (1 << 14),
2358c2ecf20Sopenharmony_ci
2368c2ecf20Sopenharmony_ci	/*
2378c2ecf20Sopenharmony_ci	 * This device supports a per-device lkey or stag that can be
2388c2ecf20Sopenharmony_ci	 * used without performing a memory registration for the local
2398c2ecf20Sopenharmony_ci	 * memory.  Note that ULPs should never check this flag, but
2408c2ecf20Sopenharmony_ci	 * instead of use the local_dma_lkey flag in the ib_pd structure,
2418c2ecf20Sopenharmony_ci	 * which will always contain a usable lkey.
2428c2ecf20Sopenharmony_ci	 */
2438c2ecf20Sopenharmony_ci	IB_DEVICE_LOCAL_DMA_LKEY		= (1 << 15),
2448c2ecf20Sopenharmony_ci	/* Reserved, old SEND_W_INV		= (1 << 16),*/
2458c2ecf20Sopenharmony_ci	IB_DEVICE_MEM_WINDOW			= (1 << 17),
2468c2ecf20Sopenharmony_ci	/*
2478c2ecf20Sopenharmony_ci	 * Devices should set IB_DEVICE_UD_IP_SUM if they support
2488c2ecf20Sopenharmony_ci	 * insertion of UDP and TCP checksum on outgoing UD IPoIB
2498c2ecf20Sopenharmony_ci	 * messages and can verify the validity of checksum for
2508c2ecf20Sopenharmony_ci	 * incoming messages.  Setting this flag implies that the
2518c2ecf20Sopenharmony_ci	 * IPoIB driver may set NETIF_F_IP_CSUM for datagram mode.
2528c2ecf20Sopenharmony_ci	 */
2538c2ecf20Sopenharmony_ci	IB_DEVICE_UD_IP_CSUM			= (1 << 18),
2548c2ecf20Sopenharmony_ci	IB_DEVICE_UD_TSO			= (1 << 19),
2558c2ecf20Sopenharmony_ci	IB_DEVICE_XRC				= (1 << 20),
2568c2ecf20Sopenharmony_ci
2578c2ecf20Sopenharmony_ci	/*
2588c2ecf20Sopenharmony_ci	 * This device supports the IB "base memory management extension",
2598c2ecf20Sopenharmony_ci	 * which includes support for fast registrations (IB_WR_REG_MR,
2608c2ecf20Sopenharmony_ci	 * IB_WR_LOCAL_INV and IB_WR_SEND_WITH_INV verbs).  This flag should
2618c2ecf20Sopenharmony_ci	 * also be set by any iWarp device which must support FRs to comply
2628c2ecf20Sopenharmony_ci	 * to the iWarp verbs spec.  iWarp devices also support the
2638c2ecf20Sopenharmony_ci	 * IB_WR_RDMA_READ_WITH_INV verb for RDMA READs that invalidate the
2648c2ecf20Sopenharmony_ci	 * stag.
2658c2ecf20Sopenharmony_ci	 */
2668c2ecf20Sopenharmony_ci	IB_DEVICE_MEM_MGT_EXTENSIONS		= (1 << 21),
2678c2ecf20Sopenharmony_ci	IB_DEVICE_BLOCK_MULTICAST_LOOPBACK	= (1 << 22),
2688c2ecf20Sopenharmony_ci	IB_DEVICE_MEM_WINDOW_TYPE_2A		= (1 << 23),
2698c2ecf20Sopenharmony_ci	IB_DEVICE_MEM_WINDOW_TYPE_2B		= (1 << 24),
2708c2ecf20Sopenharmony_ci	IB_DEVICE_RC_IP_CSUM			= (1 << 25),
2718c2ecf20Sopenharmony_ci	/* Deprecated. Please use IB_RAW_PACKET_CAP_IP_CSUM. */
2728c2ecf20Sopenharmony_ci	IB_DEVICE_RAW_IP_CSUM			= (1 << 26),
2738c2ecf20Sopenharmony_ci	/*
2748c2ecf20Sopenharmony_ci	 * Devices should set IB_DEVICE_CROSS_CHANNEL if they
2758c2ecf20Sopenharmony_ci	 * support execution of WQEs that involve synchronization
2768c2ecf20Sopenharmony_ci	 * of I/O operations with single completion queue managed
2778c2ecf20Sopenharmony_ci	 * by hardware.
2788c2ecf20Sopenharmony_ci	 */
2798c2ecf20Sopenharmony_ci	IB_DEVICE_CROSS_CHANNEL			= (1 << 27),
2808c2ecf20Sopenharmony_ci	IB_DEVICE_MANAGED_FLOW_STEERING		= (1 << 29),
2818c2ecf20Sopenharmony_ci	IB_DEVICE_INTEGRITY_HANDOVER		= (1 << 30),
2828c2ecf20Sopenharmony_ci	IB_DEVICE_ON_DEMAND_PAGING		= (1ULL << 31),
2838c2ecf20Sopenharmony_ci	IB_DEVICE_SG_GAPS_REG			= (1ULL << 32),
2848c2ecf20Sopenharmony_ci	IB_DEVICE_VIRTUAL_FUNCTION		= (1ULL << 33),
2858c2ecf20Sopenharmony_ci	/* Deprecated. Please use IB_RAW_PACKET_CAP_SCATTER_FCS. */
2868c2ecf20Sopenharmony_ci	IB_DEVICE_RAW_SCATTER_FCS		= (1ULL << 34),
2878c2ecf20Sopenharmony_ci	IB_DEVICE_RDMA_NETDEV_OPA		= (1ULL << 35),
2888c2ecf20Sopenharmony_ci	/* The device supports padding incoming writes to cacheline. */
2898c2ecf20Sopenharmony_ci	IB_DEVICE_PCI_WRITE_END_PADDING		= (1ULL << 36),
2908c2ecf20Sopenharmony_ci	IB_DEVICE_ALLOW_USER_UNREG		= (1ULL << 37),
2918c2ecf20Sopenharmony_ci};
2928c2ecf20Sopenharmony_ci
2938c2ecf20Sopenharmony_cienum ib_atomic_cap {
2948c2ecf20Sopenharmony_ci	IB_ATOMIC_NONE,
2958c2ecf20Sopenharmony_ci	IB_ATOMIC_HCA,
2968c2ecf20Sopenharmony_ci	IB_ATOMIC_GLOB
2978c2ecf20Sopenharmony_ci};
2988c2ecf20Sopenharmony_ci
2998c2ecf20Sopenharmony_cienum ib_odp_general_cap_bits {
3008c2ecf20Sopenharmony_ci	IB_ODP_SUPPORT		= 1 << 0,
3018c2ecf20Sopenharmony_ci	IB_ODP_SUPPORT_IMPLICIT = 1 << 1,
3028c2ecf20Sopenharmony_ci};
3038c2ecf20Sopenharmony_ci
3048c2ecf20Sopenharmony_cienum ib_odp_transport_cap_bits {
3058c2ecf20Sopenharmony_ci	IB_ODP_SUPPORT_SEND	= 1 << 0,
3068c2ecf20Sopenharmony_ci	IB_ODP_SUPPORT_RECV	= 1 << 1,
3078c2ecf20Sopenharmony_ci	IB_ODP_SUPPORT_WRITE	= 1 << 2,
3088c2ecf20Sopenharmony_ci	IB_ODP_SUPPORT_READ	= 1 << 3,
3098c2ecf20Sopenharmony_ci	IB_ODP_SUPPORT_ATOMIC	= 1 << 4,
3108c2ecf20Sopenharmony_ci	IB_ODP_SUPPORT_SRQ_RECV	= 1 << 5,
3118c2ecf20Sopenharmony_ci};
3128c2ecf20Sopenharmony_ci
3138c2ecf20Sopenharmony_cistruct ib_odp_caps {
3148c2ecf20Sopenharmony_ci	uint64_t general_caps;
3158c2ecf20Sopenharmony_ci	struct {
3168c2ecf20Sopenharmony_ci		uint32_t  rc_odp_caps;
3178c2ecf20Sopenharmony_ci		uint32_t  uc_odp_caps;
3188c2ecf20Sopenharmony_ci		uint32_t  ud_odp_caps;
3198c2ecf20Sopenharmony_ci		uint32_t  xrc_odp_caps;
3208c2ecf20Sopenharmony_ci	} per_transport_caps;
3218c2ecf20Sopenharmony_ci};
3228c2ecf20Sopenharmony_ci
3238c2ecf20Sopenharmony_cistruct ib_rss_caps {
3248c2ecf20Sopenharmony_ci	/* Corresponding bit will be set if qp type from
3258c2ecf20Sopenharmony_ci	 * 'enum ib_qp_type' is supported, e.g.
3268c2ecf20Sopenharmony_ci	 * supported_qpts |= 1 << IB_QPT_UD
3278c2ecf20Sopenharmony_ci	 */
3288c2ecf20Sopenharmony_ci	u32 supported_qpts;
3298c2ecf20Sopenharmony_ci	u32 max_rwq_indirection_tables;
3308c2ecf20Sopenharmony_ci	u32 max_rwq_indirection_table_size;
3318c2ecf20Sopenharmony_ci};
3328c2ecf20Sopenharmony_ci
3338c2ecf20Sopenharmony_cienum ib_tm_cap_flags {
3348c2ecf20Sopenharmony_ci	/*  Support tag matching with rendezvous offload for RC transport */
3358c2ecf20Sopenharmony_ci	IB_TM_CAP_RNDV_RC = 1 << 0,
3368c2ecf20Sopenharmony_ci};
3378c2ecf20Sopenharmony_ci
3388c2ecf20Sopenharmony_cistruct ib_tm_caps {
3398c2ecf20Sopenharmony_ci	/* Max size of RNDV header */
3408c2ecf20Sopenharmony_ci	u32 max_rndv_hdr_size;
3418c2ecf20Sopenharmony_ci	/* Max number of entries in tag matching list */
3428c2ecf20Sopenharmony_ci	u32 max_num_tags;
3438c2ecf20Sopenharmony_ci	/* From enum ib_tm_cap_flags */
3448c2ecf20Sopenharmony_ci	u32 flags;
3458c2ecf20Sopenharmony_ci	/* Max number of outstanding list operations */
3468c2ecf20Sopenharmony_ci	u32 max_ops;
3478c2ecf20Sopenharmony_ci	/* Max number of SGE in tag matching entry */
3488c2ecf20Sopenharmony_ci	u32 max_sge;
3498c2ecf20Sopenharmony_ci};
3508c2ecf20Sopenharmony_ci
3518c2ecf20Sopenharmony_cistruct ib_cq_init_attr {
3528c2ecf20Sopenharmony_ci	unsigned int	cqe;
3538c2ecf20Sopenharmony_ci	u32		comp_vector;
3548c2ecf20Sopenharmony_ci	u32		flags;
3558c2ecf20Sopenharmony_ci};
3568c2ecf20Sopenharmony_ci
3578c2ecf20Sopenharmony_cienum ib_cq_attr_mask {
3588c2ecf20Sopenharmony_ci	IB_CQ_MODERATE = 1 << 0,
3598c2ecf20Sopenharmony_ci};
3608c2ecf20Sopenharmony_ci
3618c2ecf20Sopenharmony_cistruct ib_cq_caps {
3628c2ecf20Sopenharmony_ci	u16     max_cq_moderation_count;
3638c2ecf20Sopenharmony_ci	u16     max_cq_moderation_period;
3648c2ecf20Sopenharmony_ci};
3658c2ecf20Sopenharmony_ci
3668c2ecf20Sopenharmony_cistruct ib_dm_mr_attr {
3678c2ecf20Sopenharmony_ci	u64		length;
3688c2ecf20Sopenharmony_ci	u64		offset;
3698c2ecf20Sopenharmony_ci	u32		access_flags;
3708c2ecf20Sopenharmony_ci};
3718c2ecf20Sopenharmony_ci
3728c2ecf20Sopenharmony_cistruct ib_dm_alloc_attr {
3738c2ecf20Sopenharmony_ci	u64	length;
3748c2ecf20Sopenharmony_ci	u32	alignment;
3758c2ecf20Sopenharmony_ci	u32	flags;
3768c2ecf20Sopenharmony_ci};
3778c2ecf20Sopenharmony_ci
3788c2ecf20Sopenharmony_cistruct ib_device_attr {
3798c2ecf20Sopenharmony_ci	u64			fw_ver;
3808c2ecf20Sopenharmony_ci	__be64			sys_image_guid;
3818c2ecf20Sopenharmony_ci	u64			max_mr_size;
3828c2ecf20Sopenharmony_ci	u64			page_size_cap;
3838c2ecf20Sopenharmony_ci	u32			vendor_id;
3848c2ecf20Sopenharmony_ci	u32			vendor_part_id;
3858c2ecf20Sopenharmony_ci	u32			hw_ver;
3868c2ecf20Sopenharmony_ci	int			max_qp;
3878c2ecf20Sopenharmony_ci	int			max_qp_wr;
3888c2ecf20Sopenharmony_ci	u64			device_cap_flags;
3898c2ecf20Sopenharmony_ci	int			max_send_sge;
3908c2ecf20Sopenharmony_ci	int			max_recv_sge;
3918c2ecf20Sopenharmony_ci	int			max_sge_rd;
3928c2ecf20Sopenharmony_ci	int			max_cq;
3938c2ecf20Sopenharmony_ci	int			max_cqe;
3948c2ecf20Sopenharmony_ci	int			max_mr;
3958c2ecf20Sopenharmony_ci	int			max_pd;
3968c2ecf20Sopenharmony_ci	int			max_qp_rd_atom;
3978c2ecf20Sopenharmony_ci	int			max_ee_rd_atom;
3988c2ecf20Sopenharmony_ci	int			max_res_rd_atom;
3998c2ecf20Sopenharmony_ci	int			max_qp_init_rd_atom;
4008c2ecf20Sopenharmony_ci	int			max_ee_init_rd_atom;
4018c2ecf20Sopenharmony_ci	enum ib_atomic_cap	atomic_cap;
4028c2ecf20Sopenharmony_ci	enum ib_atomic_cap	masked_atomic_cap;
4038c2ecf20Sopenharmony_ci	int			max_ee;
4048c2ecf20Sopenharmony_ci	int			max_rdd;
4058c2ecf20Sopenharmony_ci	int			max_mw;
4068c2ecf20Sopenharmony_ci	int			max_raw_ipv6_qp;
4078c2ecf20Sopenharmony_ci	int			max_raw_ethy_qp;
4088c2ecf20Sopenharmony_ci	int			max_mcast_grp;
4098c2ecf20Sopenharmony_ci	int			max_mcast_qp_attach;
4108c2ecf20Sopenharmony_ci	int			max_total_mcast_qp_attach;
4118c2ecf20Sopenharmony_ci	int			max_ah;
4128c2ecf20Sopenharmony_ci	int			max_srq;
4138c2ecf20Sopenharmony_ci	int			max_srq_wr;
4148c2ecf20Sopenharmony_ci	int			max_srq_sge;
4158c2ecf20Sopenharmony_ci	unsigned int		max_fast_reg_page_list_len;
4168c2ecf20Sopenharmony_ci	unsigned int		max_pi_fast_reg_page_list_len;
4178c2ecf20Sopenharmony_ci	u16			max_pkeys;
4188c2ecf20Sopenharmony_ci	u8			local_ca_ack_delay;
4198c2ecf20Sopenharmony_ci	int			sig_prot_cap;
4208c2ecf20Sopenharmony_ci	int			sig_guard_cap;
4218c2ecf20Sopenharmony_ci	struct ib_odp_caps	odp_caps;
4228c2ecf20Sopenharmony_ci	uint64_t		timestamp_mask;
4238c2ecf20Sopenharmony_ci	uint64_t		hca_core_clock; /* in KHZ */
4248c2ecf20Sopenharmony_ci	struct ib_rss_caps	rss_caps;
4258c2ecf20Sopenharmony_ci	u32			max_wq_type_rq;
4268c2ecf20Sopenharmony_ci	u32			raw_packet_caps; /* Use ib_raw_packet_caps enum */
4278c2ecf20Sopenharmony_ci	struct ib_tm_caps	tm_caps;
4288c2ecf20Sopenharmony_ci	struct ib_cq_caps       cq_caps;
4298c2ecf20Sopenharmony_ci	u64			max_dm_size;
4308c2ecf20Sopenharmony_ci	/* Max entries for sgl for optimized performance per READ */
4318c2ecf20Sopenharmony_ci	u32			max_sgl_rd;
4328c2ecf20Sopenharmony_ci};
4338c2ecf20Sopenharmony_ci
4348c2ecf20Sopenharmony_cienum ib_mtu {
4358c2ecf20Sopenharmony_ci	IB_MTU_256  = 1,
4368c2ecf20Sopenharmony_ci	IB_MTU_512  = 2,
4378c2ecf20Sopenharmony_ci	IB_MTU_1024 = 3,
4388c2ecf20Sopenharmony_ci	IB_MTU_2048 = 4,
4398c2ecf20Sopenharmony_ci	IB_MTU_4096 = 5
4408c2ecf20Sopenharmony_ci};
4418c2ecf20Sopenharmony_ci
4428c2ecf20Sopenharmony_cienum opa_mtu {
4438c2ecf20Sopenharmony_ci	OPA_MTU_8192 = 6,
4448c2ecf20Sopenharmony_ci	OPA_MTU_10240 = 7
4458c2ecf20Sopenharmony_ci};
4468c2ecf20Sopenharmony_ci
4478c2ecf20Sopenharmony_cistatic inline int ib_mtu_enum_to_int(enum ib_mtu mtu)
4488c2ecf20Sopenharmony_ci{
4498c2ecf20Sopenharmony_ci	switch (mtu) {
4508c2ecf20Sopenharmony_ci	case IB_MTU_256:  return  256;
4518c2ecf20Sopenharmony_ci	case IB_MTU_512:  return  512;
4528c2ecf20Sopenharmony_ci	case IB_MTU_1024: return 1024;
4538c2ecf20Sopenharmony_ci	case IB_MTU_2048: return 2048;
4548c2ecf20Sopenharmony_ci	case IB_MTU_4096: return 4096;
4558c2ecf20Sopenharmony_ci	default: 	  return -1;
4568c2ecf20Sopenharmony_ci	}
4578c2ecf20Sopenharmony_ci}
4588c2ecf20Sopenharmony_ci
4598c2ecf20Sopenharmony_cistatic inline enum ib_mtu ib_mtu_int_to_enum(int mtu)
4608c2ecf20Sopenharmony_ci{
4618c2ecf20Sopenharmony_ci	if (mtu >= 4096)
4628c2ecf20Sopenharmony_ci		return IB_MTU_4096;
4638c2ecf20Sopenharmony_ci	else if (mtu >= 2048)
4648c2ecf20Sopenharmony_ci		return IB_MTU_2048;
4658c2ecf20Sopenharmony_ci	else if (mtu >= 1024)
4668c2ecf20Sopenharmony_ci		return IB_MTU_1024;
4678c2ecf20Sopenharmony_ci	else if (mtu >= 512)
4688c2ecf20Sopenharmony_ci		return IB_MTU_512;
4698c2ecf20Sopenharmony_ci	else
4708c2ecf20Sopenharmony_ci		return IB_MTU_256;
4718c2ecf20Sopenharmony_ci}
4728c2ecf20Sopenharmony_ci
4738c2ecf20Sopenharmony_cistatic inline int opa_mtu_enum_to_int(enum opa_mtu mtu)
4748c2ecf20Sopenharmony_ci{
4758c2ecf20Sopenharmony_ci	switch (mtu) {
4768c2ecf20Sopenharmony_ci	case OPA_MTU_8192:
4778c2ecf20Sopenharmony_ci		return 8192;
4788c2ecf20Sopenharmony_ci	case OPA_MTU_10240:
4798c2ecf20Sopenharmony_ci		return 10240;
4808c2ecf20Sopenharmony_ci	default:
4818c2ecf20Sopenharmony_ci		return(ib_mtu_enum_to_int((enum ib_mtu)mtu));
4828c2ecf20Sopenharmony_ci	}
4838c2ecf20Sopenharmony_ci}
4848c2ecf20Sopenharmony_ci
4858c2ecf20Sopenharmony_cistatic inline enum opa_mtu opa_mtu_int_to_enum(int mtu)
4868c2ecf20Sopenharmony_ci{
4878c2ecf20Sopenharmony_ci	if (mtu >= 10240)
4888c2ecf20Sopenharmony_ci		return OPA_MTU_10240;
4898c2ecf20Sopenharmony_ci	else if (mtu >= 8192)
4908c2ecf20Sopenharmony_ci		return OPA_MTU_8192;
4918c2ecf20Sopenharmony_ci	else
4928c2ecf20Sopenharmony_ci		return ((enum opa_mtu)ib_mtu_int_to_enum(mtu));
4938c2ecf20Sopenharmony_ci}
4948c2ecf20Sopenharmony_ci
4958c2ecf20Sopenharmony_cienum ib_port_state {
4968c2ecf20Sopenharmony_ci	IB_PORT_NOP		= 0,
4978c2ecf20Sopenharmony_ci	IB_PORT_DOWN		= 1,
4988c2ecf20Sopenharmony_ci	IB_PORT_INIT		= 2,
4998c2ecf20Sopenharmony_ci	IB_PORT_ARMED		= 3,
5008c2ecf20Sopenharmony_ci	IB_PORT_ACTIVE		= 4,
5018c2ecf20Sopenharmony_ci	IB_PORT_ACTIVE_DEFER	= 5
5028c2ecf20Sopenharmony_ci};
5038c2ecf20Sopenharmony_ci
5048c2ecf20Sopenharmony_cienum ib_port_phys_state {
5058c2ecf20Sopenharmony_ci	IB_PORT_PHYS_STATE_SLEEP = 1,
5068c2ecf20Sopenharmony_ci	IB_PORT_PHYS_STATE_POLLING = 2,
5078c2ecf20Sopenharmony_ci	IB_PORT_PHYS_STATE_DISABLED = 3,
5088c2ecf20Sopenharmony_ci	IB_PORT_PHYS_STATE_PORT_CONFIGURATION_TRAINING = 4,
5098c2ecf20Sopenharmony_ci	IB_PORT_PHYS_STATE_LINK_UP = 5,
5108c2ecf20Sopenharmony_ci	IB_PORT_PHYS_STATE_LINK_ERROR_RECOVERY = 6,
5118c2ecf20Sopenharmony_ci	IB_PORT_PHYS_STATE_PHY_TEST = 7,
5128c2ecf20Sopenharmony_ci};
5138c2ecf20Sopenharmony_ci
5148c2ecf20Sopenharmony_cienum ib_port_width {
5158c2ecf20Sopenharmony_ci	IB_WIDTH_1X	= 1,
5168c2ecf20Sopenharmony_ci	IB_WIDTH_2X	= 16,
5178c2ecf20Sopenharmony_ci	IB_WIDTH_4X	= 2,
5188c2ecf20Sopenharmony_ci	IB_WIDTH_8X	= 4,
5198c2ecf20Sopenharmony_ci	IB_WIDTH_12X	= 8
5208c2ecf20Sopenharmony_ci};
5218c2ecf20Sopenharmony_ci
5228c2ecf20Sopenharmony_cistatic inline int ib_width_enum_to_int(enum ib_port_width width)
5238c2ecf20Sopenharmony_ci{
5248c2ecf20Sopenharmony_ci	switch (width) {
5258c2ecf20Sopenharmony_ci	case IB_WIDTH_1X:  return  1;
5268c2ecf20Sopenharmony_ci	case IB_WIDTH_2X:  return  2;
5278c2ecf20Sopenharmony_ci	case IB_WIDTH_4X:  return  4;
5288c2ecf20Sopenharmony_ci	case IB_WIDTH_8X:  return  8;
5298c2ecf20Sopenharmony_ci	case IB_WIDTH_12X: return 12;
5308c2ecf20Sopenharmony_ci	default: 	  return -1;
5318c2ecf20Sopenharmony_ci	}
5328c2ecf20Sopenharmony_ci}
5338c2ecf20Sopenharmony_ci
5348c2ecf20Sopenharmony_cienum ib_port_speed {
5358c2ecf20Sopenharmony_ci	IB_SPEED_SDR	= 1,
5368c2ecf20Sopenharmony_ci	IB_SPEED_DDR	= 2,
5378c2ecf20Sopenharmony_ci	IB_SPEED_QDR	= 4,
5388c2ecf20Sopenharmony_ci	IB_SPEED_FDR10	= 8,
5398c2ecf20Sopenharmony_ci	IB_SPEED_FDR	= 16,
5408c2ecf20Sopenharmony_ci	IB_SPEED_EDR	= 32,
5418c2ecf20Sopenharmony_ci	IB_SPEED_HDR	= 64,
5428c2ecf20Sopenharmony_ci	IB_SPEED_NDR	= 128,
5438c2ecf20Sopenharmony_ci};
5448c2ecf20Sopenharmony_ci
5458c2ecf20Sopenharmony_ci/**
5468c2ecf20Sopenharmony_ci * struct rdma_hw_stats
5478c2ecf20Sopenharmony_ci * @lock - Mutex to protect parallel write access to lifespan and values
5488c2ecf20Sopenharmony_ci *    of counters, which are 64bits and not guaranteeed to be written
5498c2ecf20Sopenharmony_ci *    atomicaly on 32bits systems.
5508c2ecf20Sopenharmony_ci * @timestamp - Used by the core code to track when the last update was
5518c2ecf20Sopenharmony_ci * @lifespan - Used by the core code to determine how old the counters
5528c2ecf20Sopenharmony_ci *   should be before being updated again.  Stored in jiffies, defaults
5538c2ecf20Sopenharmony_ci *   to 10 milliseconds, drivers can override the default be specifying
5548c2ecf20Sopenharmony_ci *   their own value during their allocation routine.
5558c2ecf20Sopenharmony_ci * @name - Array of pointers to static names used for the counters in
5568c2ecf20Sopenharmony_ci *   directory.
5578c2ecf20Sopenharmony_ci * @num_counters - How many hardware counters there are.  If name is
5588c2ecf20Sopenharmony_ci *   shorter than this number, a kernel oops will result.  Driver authors
5598c2ecf20Sopenharmony_ci *   are encouraged to leave BUILD_BUG_ON(ARRAY_SIZE(@name) < num_counters)
5608c2ecf20Sopenharmony_ci *   in their code to prevent this.
5618c2ecf20Sopenharmony_ci * @value - Array of u64 counters that are accessed by the sysfs code and
5628c2ecf20Sopenharmony_ci *   filled in by the drivers get_stats routine
5638c2ecf20Sopenharmony_ci */
5648c2ecf20Sopenharmony_cistruct rdma_hw_stats {
5658c2ecf20Sopenharmony_ci	struct mutex	lock; /* Protect lifespan and values[] */
5668c2ecf20Sopenharmony_ci	unsigned long	timestamp;
5678c2ecf20Sopenharmony_ci	unsigned long	lifespan;
5688c2ecf20Sopenharmony_ci	const char * const *names;
5698c2ecf20Sopenharmony_ci	int		num_counters;
5708c2ecf20Sopenharmony_ci	u64		value[];
5718c2ecf20Sopenharmony_ci};
5728c2ecf20Sopenharmony_ci
5738c2ecf20Sopenharmony_ci#define RDMA_HW_STATS_DEFAULT_LIFESPAN 10
5748c2ecf20Sopenharmony_ci/**
5758c2ecf20Sopenharmony_ci * rdma_alloc_hw_stats_struct - Helper function to allocate dynamic struct
5768c2ecf20Sopenharmony_ci *   for drivers.
5778c2ecf20Sopenharmony_ci * @names - Array of static const char *
5788c2ecf20Sopenharmony_ci * @num_counters - How many elements in array
5798c2ecf20Sopenharmony_ci * @lifespan - How many milliseconds between updates
5808c2ecf20Sopenharmony_ci */
5818c2ecf20Sopenharmony_cistatic inline struct rdma_hw_stats *rdma_alloc_hw_stats_struct(
5828c2ecf20Sopenharmony_ci		const char * const *names, int num_counters,
5838c2ecf20Sopenharmony_ci		unsigned long lifespan)
5848c2ecf20Sopenharmony_ci{
5858c2ecf20Sopenharmony_ci	struct rdma_hw_stats *stats;
5868c2ecf20Sopenharmony_ci
5878c2ecf20Sopenharmony_ci	stats = kzalloc(sizeof(*stats) + num_counters * sizeof(u64),
5888c2ecf20Sopenharmony_ci			GFP_KERNEL);
5898c2ecf20Sopenharmony_ci	if (!stats)
5908c2ecf20Sopenharmony_ci		return NULL;
5918c2ecf20Sopenharmony_ci	stats->names = names;
5928c2ecf20Sopenharmony_ci	stats->num_counters = num_counters;
5938c2ecf20Sopenharmony_ci	stats->lifespan = msecs_to_jiffies(lifespan);
5948c2ecf20Sopenharmony_ci
5958c2ecf20Sopenharmony_ci	return stats;
5968c2ecf20Sopenharmony_ci}
5978c2ecf20Sopenharmony_ci
5988c2ecf20Sopenharmony_ci
5998c2ecf20Sopenharmony_ci/* Define bits for the various functionality this port needs to be supported by
6008c2ecf20Sopenharmony_ci * the core.
6018c2ecf20Sopenharmony_ci */
6028c2ecf20Sopenharmony_ci/* Management                           0x00000FFF */
6038c2ecf20Sopenharmony_ci#define RDMA_CORE_CAP_IB_MAD            0x00000001
6048c2ecf20Sopenharmony_ci#define RDMA_CORE_CAP_IB_SMI            0x00000002
6058c2ecf20Sopenharmony_ci#define RDMA_CORE_CAP_IB_CM             0x00000004
6068c2ecf20Sopenharmony_ci#define RDMA_CORE_CAP_IW_CM             0x00000008
6078c2ecf20Sopenharmony_ci#define RDMA_CORE_CAP_IB_SA             0x00000010
6088c2ecf20Sopenharmony_ci#define RDMA_CORE_CAP_OPA_MAD           0x00000020
6098c2ecf20Sopenharmony_ci
6108c2ecf20Sopenharmony_ci/* Address format                       0x000FF000 */
6118c2ecf20Sopenharmony_ci#define RDMA_CORE_CAP_AF_IB             0x00001000
6128c2ecf20Sopenharmony_ci#define RDMA_CORE_CAP_ETH_AH            0x00002000
6138c2ecf20Sopenharmony_ci#define RDMA_CORE_CAP_OPA_AH            0x00004000
6148c2ecf20Sopenharmony_ci#define RDMA_CORE_CAP_IB_GRH_REQUIRED   0x00008000
6158c2ecf20Sopenharmony_ci
6168c2ecf20Sopenharmony_ci/* Protocol                             0xFFF00000 */
6178c2ecf20Sopenharmony_ci#define RDMA_CORE_CAP_PROT_IB           0x00100000
6188c2ecf20Sopenharmony_ci#define RDMA_CORE_CAP_PROT_ROCE         0x00200000
6198c2ecf20Sopenharmony_ci#define RDMA_CORE_CAP_PROT_IWARP        0x00400000
6208c2ecf20Sopenharmony_ci#define RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP 0x00800000
6218c2ecf20Sopenharmony_ci#define RDMA_CORE_CAP_PROT_RAW_PACKET   0x01000000
6228c2ecf20Sopenharmony_ci#define RDMA_CORE_CAP_PROT_USNIC        0x02000000
6238c2ecf20Sopenharmony_ci
6248c2ecf20Sopenharmony_ci#define RDMA_CORE_PORT_IB_GRH_REQUIRED (RDMA_CORE_CAP_IB_GRH_REQUIRED \
6258c2ecf20Sopenharmony_ci					| RDMA_CORE_CAP_PROT_ROCE     \
6268c2ecf20Sopenharmony_ci					| RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP)
6278c2ecf20Sopenharmony_ci
6288c2ecf20Sopenharmony_ci#define RDMA_CORE_PORT_IBA_IB          (RDMA_CORE_CAP_PROT_IB  \
6298c2ecf20Sopenharmony_ci					| RDMA_CORE_CAP_IB_MAD \
6308c2ecf20Sopenharmony_ci					| RDMA_CORE_CAP_IB_SMI \
6318c2ecf20Sopenharmony_ci					| RDMA_CORE_CAP_IB_CM  \
6328c2ecf20Sopenharmony_ci					| RDMA_CORE_CAP_IB_SA  \
6338c2ecf20Sopenharmony_ci					| RDMA_CORE_CAP_AF_IB)
6348c2ecf20Sopenharmony_ci#define RDMA_CORE_PORT_IBA_ROCE        (RDMA_CORE_CAP_PROT_ROCE \
6358c2ecf20Sopenharmony_ci					| RDMA_CORE_CAP_IB_MAD  \
6368c2ecf20Sopenharmony_ci					| RDMA_CORE_CAP_IB_CM   \
6378c2ecf20Sopenharmony_ci					| RDMA_CORE_CAP_AF_IB   \
6388c2ecf20Sopenharmony_ci					| RDMA_CORE_CAP_ETH_AH)
6398c2ecf20Sopenharmony_ci#define RDMA_CORE_PORT_IBA_ROCE_UDP_ENCAP			\
6408c2ecf20Sopenharmony_ci					(RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP \
6418c2ecf20Sopenharmony_ci					| RDMA_CORE_CAP_IB_MAD  \
6428c2ecf20Sopenharmony_ci					| RDMA_CORE_CAP_IB_CM   \
6438c2ecf20Sopenharmony_ci					| RDMA_CORE_CAP_AF_IB   \
6448c2ecf20Sopenharmony_ci					| RDMA_CORE_CAP_ETH_AH)
6458c2ecf20Sopenharmony_ci#define RDMA_CORE_PORT_IWARP           (RDMA_CORE_CAP_PROT_IWARP \
6468c2ecf20Sopenharmony_ci					| RDMA_CORE_CAP_IW_CM)
6478c2ecf20Sopenharmony_ci#define RDMA_CORE_PORT_INTEL_OPA       (RDMA_CORE_PORT_IBA_IB  \
6488c2ecf20Sopenharmony_ci					| RDMA_CORE_CAP_OPA_MAD)
6498c2ecf20Sopenharmony_ci
6508c2ecf20Sopenharmony_ci#define RDMA_CORE_PORT_RAW_PACKET	(RDMA_CORE_CAP_PROT_RAW_PACKET)
6518c2ecf20Sopenharmony_ci
6528c2ecf20Sopenharmony_ci#define RDMA_CORE_PORT_USNIC		(RDMA_CORE_CAP_PROT_USNIC)
6538c2ecf20Sopenharmony_ci
6548c2ecf20Sopenharmony_cistruct ib_port_attr {
6558c2ecf20Sopenharmony_ci	u64			subnet_prefix;
6568c2ecf20Sopenharmony_ci	enum ib_port_state	state;
6578c2ecf20Sopenharmony_ci	enum ib_mtu		max_mtu;
6588c2ecf20Sopenharmony_ci	enum ib_mtu		active_mtu;
6598c2ecf20Sopenharmony_ci	u32                     phys_mtu;
6608c2ecf20Sopenharmony_ci	int			gid_tbl_len;
6618c2ecf20Sopenharmony_ci	unsigned int		ip_gids:1;
6628c2ecf20Sopenharmony_ci	/* This is the value from PortInfo CapabilityMask, defined by IBA */
6638c2ecf20Sopenharmony_ci	u32			port_cap_flags;
6648c2ecf20Sopenharmony_ci	u32			max_msg_sz;
6658c2ecf20Sopenharmony_ci	u32			bad_pkey_cntr;
6668c2ecf20Sopenharmony_ci	u32			qkey_viol_cntr;
6678c2ecf20Sopenharmony_ci	u16			pkey_tbl_len;
6688c2ecf20Sopenharmony_ci	u32			sm_lid;
6698c2ecf20Sopenharmony_ci	u32			lid;
6708c2ecf20Sopenharmony_ci	u8			lmc;
6718c2ecf20Sopenharmony_ci	u8			max_vl_num;
6728c2ecf20Sopenharmony_ci	u8			sm_sl;
6738c2ecf20Sopenharmony_ci	u8			subnet_timeout;
6748c2ecf20Sopenharmony_ci	u8			init_type_reply;
6758c2ecf20Sopenharmony_ci	u8			active_width;
6768c2ecf20Sopenharmony_ci	u16			active_speed;
6778c2ecf20Sopenharmony_ci	u8                      phys_state;
6788c2ecf20Sopenharmony_ci	u16			port_cap_flags2;
6798c2ecf20Sopenharmony_ci};
6808c2ecf20Sopenharmony_ci
6818c2ecf20Sopenharmony_cienum ib_device_modify_flags {
6828c2ecf20Sopenharmony_ci	IB_DEVICE_MODIFY_SYS_IMAGE_GUID	= 1 << 0,
6838c2ecf20Sopenharmony_ci	IB_DEVICE_MODIFY_NODE_DESC	= 1 << 1
6848c2ecf20Sopenharmony_ci};
6858c2ecf20Sopenharmony_ci
6868c2ecf20Sopenharmony_ci#define IB_DEVICE_NODE_DESC_MAX 64
6878c2ecf20Sopenharmony_ci
6888c2ecf20Sopenharmony_cistruct ib_device_modify {
6898c2ecf20Sopenharmony_ci	u64	sys_image_guid;
6908c2ecf20Sopenharmony_ci	char	node_desc[IB_DEVICE_NODE_DESC_MAX];
6918c2ecf20Sopenharmony_ci};
6928c2ecf20Sopenharmony_ci
6938c2ecf20Sopenharmony_cienum ib_port_modify_flags {
6948c2ecf20Sopenharmony_ci	IB_PORT_SHUTDOWN		= 1,
6958c2ecf20Sopenharmony_ci	IB_PORT_INIT_TYPE		= (1<<2),
6968c2ecf20Sopenharmony_ci	IB_PORT_RESET_QKEY_CNTR		= (1<<3),
6978c2ecf20Sopenharmony_ci	IB_PORT_OPA_MASK_CHG		= (1<<4)
6988c2ecf20Sopenharmony_ci};
6998c2ecf20Sopenharmony_ci
7008c2ecf20Sopenharmony_cistruct ib_port_modify {
7018c2ecf20Sopenharmony_ci	u32	set_port_cap_mask;
7028c2ecf20Sopenharmony_ci	u32	clr_port_cap_mask;
7038c2ecf20Sopenharmony_ci	u8	init_type;
7048c2ecf20Sopenharmony_ci};
7058c2ecf20Sopenharmony_ci
7068c2ecf20Sopenharmony_cienum ib_event_type {
7078c2ecf20Sopenharmony_ci	IB_EVENT_CQ_ERR,
7088c2ecf20Sopenharmony_ci	IB_EVENT_QP_FATAL,
7098c2ecf20Sopenharmony_ci	IB_EVENT_QP_REQ_ERR,
7108c2ecf20Sopenharmony_ci	IB_EVENT_QP_ACCESS_ERR,
7118c2ecf20Sopenharmony_ci	IB_EVENT_COMM_EST,
7128c2ecf20Sopenharmony_ci	IB_EVENT_SQ_DRAINED,
7138c2ecf20Sopenharmony_ci	IB_EVENT_PATH_MIG,
7148c2ecf20Sopenharmony_ci	IB_EVENT_PATH_MIG_ERR,
7158c2ecf20Sopenharmony_ci	IB_EVENT_DEVICE_FATAL,
7168c2ecf20Sopenharmony_ci	IB_EVENT_PORT_ACTIVE,
7178c2ecf20Sopenharmony_ci	IB_EVENT_PORT_ERR,
7188c2ecf20Sopenharmony_ci	IB_EVENT_LID_CHANGE,
7198c2ecf20Sopenharmony_ci	IB_EVENT_PKEY_CHANGE,
7208c2ecf20Sopenharmony_ci	IB_EVENT_SM_CHANGE,
7218c2ecf20Sopenharmony_ci	IB_EVENT_SRQ_ERR,
7228c2ecf20Sopenharmony_ci	IB_EVENT_SRQ_LIMIT_REACHED,
7238c2ecf20Sopenharmony_ci	IB_EVENT_QP_LAST_WQE_REACHED,
7248c2ecf20Sopenharmony_ci	IB_EVENT_CLIENT_REREGISTER,
7258c2ecf20Sopenharmony_ci	IB_EVENT_GID_CHANGE,
7268c2ecf20Sopenharmony_ci	IB_EVENT_WQ_FATAL,
7278c2ecf20Sopenharmony_ci};
7288c2ecf20Sopenharmony_ci
7298c2ecf20Sopenharmony_ciconst char *__attribute_const__ ib_event_msg(enum ib_event_type event);
7308c2ecf20Sopenharmony_ci
7318c2ecf20Sopenharmony_cistruct ib_event {
7328c2ecf20Sopenharmony_ci	struct ib_device	*device;
7338c2ecf20Sopenharmony_ci	union {
7348c2ecf20Sopenharmony_ci		struct ib_cq	*cq;
7358c2ecf20Sopenharmony_ci		struct ib_qp	*qp;
7368c2ecf20Sopenharmony_ci		struct ib_srq	*srq;
7378c2ecf20Sopenharmony_ci		struct ib_wq	*wq;
7388c2ecf20Sopenharmony_ci		u8		port_num;
7398c2ecf20Sopenharmony_ci	} element;
7408c2ecf20Sopenharmony_ci	enum ib_event_type	event;
7418c2ecf20Sopenharmony_ci};
7428c2ecf20Sopenharmony_ci
7438c2ecf20Sopenharmony_cistruct ib_event_handler {
7448c2ecf20Sopenharmony_ci	struct ib_device *device;
7458c2ecf20Sopenharmony_ci	void            (*handler)(struct ib_event_handler *, struct ib_event *);
7468c2ecf20Sopenharmony_ci	struct list_head  list;
7478c2ecf20Sopenharmony_ci};
7488c2ecf20Sopenharmony_ci
7498c2ecf20Sopenharmony_ci#define INIT_IB_EVENT_HANDLER(_ptr, _device, _handler)		\
7508c2ecf20Sopenharmony_ci	do {							\
7518c2ecf20Sopenharmony_ci		(_ptr)->device  = _device;			\
7528c2ecf20Sopenharmony_ci		(_ptr)->handler = _handler;			\
7538c2ecf20Sopenharmony_ci		INIT_LIST_HEAD(&(_ptr)->list);			\
7548c2ecf20Sopenharmony_ci	} while (0)
7558c2ecf20Sopenharmony_ci
7568c2ecf20Sopenharmony_cistruct ib_global_route {
7578c2ecf20Sopenharmony_ci	const struct ib_gid_attr *sgid_attr;
7588c2ecf20Sopenharmony_ci	union ib_gid	dgid;
7598c2ecf20Sopenharmony_ci	u32		flow_label;
7608c2ecf20Sopenharmony_ci	u8		sgid_index;
7618c2ecf20Sopenharmony_ci	u8		hop_limit;
7628c2ecf20Sopenharmony_ci	u8		traffic_class;
7638c2ecf20Sopenharmony_ci};
7648c2ecf20Sopenharmony_ci
7658c2ecf20Sopenharmony_cistruct ib_grh {
7668c2ecf20Sopenharmony_ci	__be32		version_tclass_flow;
7678c2ecf20Sopenharmony_ci	__be16		paylen;
7688c2ecf20Sopenharmony_ci	u8		next_hdr;
7698c2ecf20Sopenharmony_ci	u8		hop_limit;
7708c2ecf20Sopenharmony_ci	union ib_gid	sgid;
7718c2ecf20Sopenharmony_ci	union ib_gid	dgid;
7728c2ecf20Sopenharmony_ci};
7738c2ecf20Sopenharmony_ci
7748c2ecf20Sopenharmony_ciunion rdma_network_hdr {
7758c2ecf20Sopenharmony_ci	struct ib_grh ibgrh;
7768c2ecf20Sopenharmony_ci	struct {
7778c2ecf20Sopenharmony_ci		/* The IB spec states that if it's IPv4, the header
7788c2ecf20Sopenharmony_ci		 * is located in the last 20 bytes of the header.
7798c2ecf20Sopenharmony_ci		 */
7808c2ecf20Sopenharmony_ci		u8		reserved[20];
7818c2ecf20Sopenharmony_ci		struct iphdr	roce4grh;
7828c2ecf20Sopenharmony_ci	};
7838c2ecf20Sopenharmony_ci};
7848c2ecf20Sopenharmony_ci
7858c2ecf20Sopenharmony_ci#define IB_QPN_MASK		0xFFFFFF
7868c2ecf20Sopenharmony_ci
7878c2ecf20Sopenharmony_cienum {
7888c2ecf20Sopenharmony_ci	IB_MULTICAST_QPN = 0xffffff
7898c2ecf20Sopenharmony_ci};
7908c2ecf20Sopenharmony_ci
7918c2ecf20Sopenharmony_ci#define IB_LID_PERMISSIVE	cpu_to_be16(0xFFFF)
7928c2ecf20Sopenharmony_ci#define IB_MULTICAST_LID_BASE	cpu_to_be16(0xC000)
7938c2ecf20Sopenharmony_ci
7948c2ecf20Sopenharmony_cienum ib_ah_flags {
7958c2ecf20Sopenharmony_ci	IB_AH_GRH	= 1
7968c2ecf20Sopenharmony_ci};
7978c2ecf20Sopenharmony_ci
7988c2ecf20Sopenharmony_cienum ib_rate {
7998c2ecf20Sopenharmony_ci	IB_RATE_PORT_CURRENT = 0,
8008c2ecf20Sopenharmony_ci	IB_RATE_2_5_GBPS = 2,
8018c2ecf20Sopenharmony_ci	IB_RATE_5_GBPS   = 5,
8028c2ecf20Sopenharmony_ci	IB_RATE_10_GBPS  = 3,
8038c2ecf20Sopenharmony_ci	IB_RATE_20_GBPS  = 6,
8048c2ecf20Sopenharmony_ci	IB_RATE_30_GBPS  = 4,
8058c2ecf20Sopenharmony_ci	IB_RATE_40_GBPS  = 7,
8068c2ecf20Sopenharmony_ci	IB_RATE_60_GBPS  = 8,
8078c2ecf20Sopenharmony_ci	IB_RATE_80_GBPS  = 9,
8088c2ecf20Sopenharmony_ci	IB_RATE_120_GBPS = 10,
8098c2ecf20Sopenharmony_ci	IB_RATE_14_GBPS  = 11,
8108c2ecf20Sopenharmony_ci	IB_RATE_56_GBPS  = 12,
8118c2ecf20Sopenharmony_ci	IB_RATE_112_GBPS = 13,
8128c2ecf20Sopenharmony_ci	IB_RATE_168_GBPS = 14,
8138c2ecf20Sopenharmony_ci	IB_RATE_25_GBPS  = 15,
8148c2ecf20Sopenharmony_ci	IB_RATE_100_GBPS = 16,
8158c2ecf20Sopenharmony_ci	IB_RATE_200_GBPS = 17,
8168c2ecf20Sopenharmony_ci	IB_RATE_300_GBPS = 18,
8178c2ecf20Sopenharmony_ci	IB_RATE_28_GBPS  = 19,
8188c2ecf20Sopenharmony_ci	IB_RATE_50_GBPS  = 20,
8198c2ecf20Sopenharmony_ci	IB_RATE_400_GBPS = 21,
8208c2ecf20Sopenharmony_ci	IB_RATE_600_GBPS = 22,
8218c2ecf20Sopenharmony_ci};
8228c2ecf20Sopenharmony_ci
8238c2ecf20Sopenharmony_ci/**
8248c2ecf20Sopenharmony_ci * ib_rate_to_mult - Convert the IB rate enum to a multiple of the
8258c2ecf20Sopenharmony_ci * base rate of 2.5 Gbit/sec.  For example, IB_RATE_5_GBPS will be
8268c2ecf20Sopenharmony_ci * converted to 2, since 5 Gbit/sec is 2 * 2.5 Gbit/sec.
8278c2ecf20Sopenharmony_ci * @rate: rate to convert.
8288c2ecf20Sopenharmony_ci */
8298c2ecf20Sopenharmony_ci__attribute_const__ int ib_rate_to_mult(enum ib_rate rate);
8308c2ecf20Sopenharmony_ci
8318c2ecf20Sopenharmony_ci/**
8328c2ecf20Sopenharmony_ci * ib_rate_to_mbps - Convert the IB rate enum to Mbps.
8338c2ecf20Sopenharmony_ci * For example, IB_RATE_2_5_GBPS will be converted to 2500.
8348c2ecf20Sopenharmony_ci * @rate: rate to convert.
8358c2ecf20Sopenharmony_ci */
8368c2ecf20Sopenharmony_ci__attribute_const__ int ib_rate_to_mbps(enum ib_rate rate);
8378c2ecf20Sopenharmony_ci
8388c2ecf20Sopenharmony_ci
8398c2ecf20Sopenharmony_ci/**
8408c2ecf20Sopenharmony_ci * enum ib_mr_type - memory region type
8418c2ecf20Sopenharmony_ci * @IB_MR_TYPE_MEM_REG:       memory region that is used for
8428c2ecf20Sopenharmony_ci *                            normal registration
8438c2ecf20Sopenharmony_ci * @IB_MR_TYPE_SG_GAPS:       memory region that is capable to
8448c2ecf20Sopenharmony_ci *                            register any arbitrary sg lists (without
8458c2ecf20Sopenharmony_ci *                            the normal mr constraints - see
8468c2ecf20Sopenharmony_ci *                            ib_map_mr_sg)
8478c2ecf20Sopenharmony_ci * @IB_MR_TYPE_DM:            memory region that is used for device
8488c2ecf20Sopenharmony_ci *                            memory registration
8498c2ecf20Sopenharmony_ci * @IB_MR_TYPE_USER:          memory region that is used for the user-space
8508c2ecf20Sopenharmony_ci *                            application
8518c2ecf20Sopenharmony_ci * @IB_MR_TYPE_DMA:           memory region that is used for DMA operations
8528c2ecf20Sopenharmony_ci *                            without address translations (VA=PA)
8538c2ecf20Sopenharmony_ci * @IB_MR_TYPE_INTEGRITY:     memory region that is used for
8548c2ecf20Sopenharmony_ci *                            data integrity operations
8558c2ecf20Sopenharmony_ci */
8568c2ecf20Sopenharmony_cienum ib_mr_type {
8578c2ecf20Sopenharmony_ci	IB_MR_TYPE_MEM_REG,
8588c2ecf20Sopenharmony_ci	IB_MR_TYPE_SG_GAPS,
8598c2ecf20Sopenharmony_ci	IB_MR_TYPE_DM,
8608c2ecf20Sopenharmony_ci	IB_MR_TYPE_USER,
8618c2ecf20Sopenharmony_ci	IB_MR_TYPE_DMA,
8628c2ecf20Sopenharmony_ci	IB_MR_TYPE_INTEGRITY,
8638c2ecf20Sopenharmony_ci};
8648c2ecf20Sopenharmony_ci
8658c2ecf20Sopenharmony_cienum ib_mr_status_check {
8668c2ecf20Sopenharmony_ci	IB_MR_CHECK_SIG_STATUS = 1,
8678c2ecf20Sopenharmony_ci};
8688c2ecf20Sopenharmony_ci
8698c2ecf20Sopenharmony_ci/**
8708c2ecf20Sopenharmony_ci * struct ib_mr_status - Memory region status container
8718c2ecf20Sopenharmony_ci *
8728c2ecf20Sopenharmony_ci * @fail_status: Bitmask of MR checks status. For each
8738c2ecf20Sopenharmony_ci *     failed check a corresponding status bit is set.
8748c2ecf20Sopenharmony_ci * @sig_err: Additional info for IB_MR_CEHCK_SIG_STATUS
8758c2ecf20Sopenharmony_ci *     failure.
8768c2ecf20Sopenharmony_ci */
8778c2ecf20Sopenharmony_cistruct ib_mr_status {
8788c2ecf20Sopenharmony_ci	u32		    fail_status;
8798c2ecf20Sopenharmony_ci	struct ib_sig_err   sig_err;
8808c2ecf20Sopenharmony_ci};
8818c2ecf20Sopenharmony_ci
8828c2ecf20Sopenharmony_ci/**
8838c2ecf20Sopenharmony_ci * mult_to_ib_rate - Convert a multiple of 2.5 Gbit/sec to an IB rate
8848c2ecf20Sopenharmony_ci * enum.
8858c2ecf20Sopenharmony_ci * @mult: multiple to convert.
8868c2ecf20Sopenharmony_ci */
8878c2ecf20Sopenharmony_ci__attribute_const__ enum ib_rate mult_to_ib_rate(int mult);
8888c2ecf20Sopenharmony_ci
8898c2ecf20Sopenharmony_cistruct rdma_ah_init_attr {
8908c2ecf20Sopenharmony_ci	struct rdma_ah_attr *ah_attr;
8918c2ecf20Sopenharmony_ci	u32 flags;
8928c2ecf20Sopenharmony_ci	struct net_device *xmit_slave;
8938c2ecf20Sopenharmony_ci};
8948c2ecf20Sopenharmony_ci
8958c2ecf20Sopenharmony_cienum rdma_ah_attr_type {
8968c2ecf20Sopenharmony_ci	RDMA_AH_ATTR_TYPE_UNDEFINED,
8978c2ecf20Sopenharmony_ci	RDMA_AH_ATTR_TYPE_IB,
8988c2ecf20Sopenharmony_ci	RDMA_AH_ATTR_TYPE_ROCE,
8998c2ecf20Sopenharmony_ci	RDMA_AH_ATTR_TYPE_OPA,
9008c2ecf20Sopenharmony_ci};
9018c2ecf20Sopenharmony_ci
9028c2ecf20Sopenharmony_cistruct ib_ah_attr {
9038c2ecf20Sopenharmony_ci	u16			dlid;
9048c2ecf20Sopenharmony_ci	u8			src_path_bits;
9058c2ecf20Sopenharmony_ci};
9068c2ecf20Sopenharmony_ci
9078c2ecf20Sopenharmony_cistruct roce_ah_attr {
9088c2ecf20Sopenharmony_ci	u8			dmac[ETH_ALEN];
9098c2ecf20Sopenharmony_ci};
9108c2ecf20Sopenharmony_ci
9118c2ecf20Sopenharmony_cistruct opa_ah_attr {
9128c2ecf20Sopenharmony_ci	u32			dlid;
9138c2ecf20Sopenharmony_ci	u8			src_path_bits;
9148c2ecf20Sopenharmony_ci	bool			make_grd;
9158c2ecf20Sopenharmony_ci};
9168c2ecf20Sopenharmony_ci
9178c2ecf20Sopenharmony_cistruct rdma_ah_attr {
9188c2ecf20Sopenharmony_ci	struct ib_global_route	grh;
9198c2ecf20Sopenharmony_ci	u8			sl;
9208c2ecf20Sopenharmony_ci	u8			static_rate;
9218c2ecf20Sopenharmony_ci	u8			port_num;
9228c2ecf20Sopenharmony_ci	u8			ah_flags;
9238c2ecf20Sopenharmony_ci	enum rdma_ah_attr_type type;
9248c2ecf20Sopenharmony_ci	union {
9258c2ecf20Sopenharmony_ci		struct ib_ah_attr ib;
9268c2ecf20Sopenharmony_ci		struct roce_ah_attr roce;
9278c2ecf20Sopenharmony_ci		struct opa_ah_attr opa;
9288c2ecf20Sopenharmony_ci	};
9298c2ecf20Sopenharmony_ci};
9308c2ecf20Sopenharmony_ci
9318c2ecf20Sopenharmony_cienum ib_wc_status {
9328c2ecf20Sopenharmony_ci	IB_WC_SUCCESS,
9338c2ecf20Sopenharmony_ci	IB_WC_LOC_LEN_ERR,
9348c2ecf20Sopenharmony_ci	IB_WC_LOC_QP_OP_ERR,
9358c2ecf20Sopenharmony_ci	IB_WC_LOC_EEC_OP_ERR,
9368c2ecf20Sopenharmony_ci	IB_WC_LOC_PROT_ERR,
9378c2ecf20Sopenharmony_ci	IB_WC_WR_FLUSH_ERR,
9388c2ecf20Sopenharmony_ci	IB_WC_MW_BIND_ERR,
9398c2ecf20Sopenharmony_ci	IB_WC_BAD_RESP_ERR,
9408c2ecf20Sopenharmony_ci	IB_WC_LOC_ACCESS_ERR,
9418c2ecf20Sopenharmony_ci	IB_WC_REM_INV_REQ_ERR,
9428c2ecf20Sopenharmony_ci	IB_WC_REM_ACCESS_ERR,
9438c2ecf20Sopenharmony_ci	IB_WC_REM_OP_ERR,
9448c2ecf20Sopenharmony_ci	IB_WC_RETRY_EXC_ERR,
9458c2ecf20Sopenharmony_ci	IB_WC_RNR_RETRY_EXC_ERR,
9468c2ecf20Sopenharmony_ci	IB_WC_LOC_RDD_VIOL_ERR,
9478c2ecf20Sopenharmony_ci	IB_WC_REM_INV_RD_REQ_ERR,
9488c2ecf20Sopenharmony_ci	IB_WC_REM_ABORT_ERR,
9498c2ecf20Sopenharmony_ci	IB_WC_INV_EECN_ERR,
9508c2ecf20Sopenharmony_ci	IB_WC_INV_EEC_STATE_ERR,
9518c2ecf20Sopenharmony_ci	IB_WC_FATAL_ERR,
9528c2ecf20Sopenharmony_ci	IB_WC_RESP_TIMEOUT_ERR,
9538c2ecf20Sopenharmony_ci	IB_WC_GENERAL_ERR
9548c2ecf20Sopenharmony_ci};
9558c2ecf20Sopenharmony_ci
9568c2ecf20Sopenharmony_ciconst char *__attribute_const__ ib_wc_status_msg(enum ib_wc_status status);
9578c2ecf20Sopenharmony_ci
9588c2ecf20Sopenharmony_cienum ib_wc_opcode {
9598c2ecf20Sopenharmony_ci	IB_WC_SEND = IB_UVERBS_WC_SEND,
9608c2ecf20Sopenharmony_ci	IB_WC_RDMA_WRITE = IB_UVERBS_WC_RDMA_WRITE,
9618c2ecf20Sopenharmony_ci	IB_WC_RDMA_READ = IB_UVERBS_WC_RDMA_READ,
9628c2ecf20Sopenharmony_ci	IB_WC_COMP_SWAP = IB_UVERBS_WC_COMP_SWAP,
9638c2ecf20Sopenharmony_ci	IB_WC_FETCH_ADD = IB_UVERBS_WC_FETCH_ADD,
9648c2ecf20Sopenharmony_ci	IB_WC_BIND_MW = IB_UVERBS_WC_BIND_MW,
9658c2ecf20Sopenharmony_ci	IB_WC_LOCAL_INV = IB_UVERBS_WC_LOCAL_INV,
9668c2ecf20Sopenharmony_ci	IB_WC_LSO = IB_UVERBS_WC_TSO,
9678c2ecf20Sopenharmony_ci	IB_WC_REG_MR,
9688c2ecf20Sopenharmony_ci	IB_WC_MASKED_COMP_SWAP,
9698c2ecf20Sopenharmony_ci	IB_WC_MASKED_FETCH_ADD,
9708c2ecf20Sopenharmony_ci/*
9718c2ecf20Sopenharmony_ci * Set value of IB_WC_RECV so consumers can test if a completion is a
9728c2ecf20Sopenharmony_ci * receive by testing (opcode & IB_WC_RECV).
9738c2ecf20Sopenharmony_ci */
9748c2ecf20Sopenharmony_ci	IB_WC_RECV			= 1 << 7,
9758c2ecf20Sopenharmony_ci	IB_WC_RECV_RDMA_WITH_IMM
9768c2ecf20Sopenharmony_ci};
9778c2ecf20Sopenharmony_ci
9788c2ecf20Sopenharmony_cienum ib_wc_flags {
9798c2ecf20Sopenharmony_ci	IB_WC_GRH		= 1,
9808c2ecf20Sopenharmony_ci	IB_WC_WITH_IMM		= (1<<1),
9818c2ecf20Sopenharmony_ci	IB_WC_WITH_INVALIDATE	= (1<<2),
9828c2ecf20Sopenharmony_ci	IB_WC_IP_CSUM_OK	= (1<<3),
9838c2ecf20Sopenharmony_ci	IB_WC_WITH_SMAC		= (1<<4),
9848c2ecf20Sopenharmony_ci	IB_WC_WITH_VLAN		= (1<<5),
9858c2ecf20Sopenharmony_ci	IB_WC_WITH_NETWORK_HDR_TYPE	= (1<<6),
9868c2ecf20Sopenharmony_ci};
9878c2ecf20Sopenharmony_ci
9888c2ecf20Sopenharmony_cistruct ib_wc {
9898c2ecf20Sopenharmony_ci	union {
9908c2ecf20Sopenharmony_ci		u64		wr_id;
9918c2ecf20Sopenharmony_ci		struct ib_cqe	*wr_cqe;
9928c2ecf20Sopenharmony_ci	};
9938c2ecf20Sopenharmony_ci	enum ib_wc_status	status;
9948c2ecf20Sopenharmony_ci	enum ib_wc_opcode	opcode;
9958c2ecf20Sopenharmony_ci	u32			vendor_err;
9968c2ecf20Sopenharmony_ci	u32			byte_len;
9978c2ecf20Sopenharmony_ci	struct ib_qp	       *qp;
9988c2ecf20Sopenharmony_ci	union {
9998c2ecf20Sopenharmony_ci		__be32		imm_data;
10008c2ecf20Sopenharmony_ci		u32		invalidate_rkey;
10018c2ecf20Sopenharmony_ci	} ex;
10028c2ecf20Sopenharmony_ci	u32			src_qp;
10038c2ecf20Sopenharmony_ci	u32			slid;
10048c2ecf20Sopenharmony_ci	int			wc_flags;
10058c2ecf20Sopenharmony_ci	u16			pkey_index;
10068c2ecf20Sopenharmony_ci	u8			sl;
10078c2ecf20Sopenharmony_ci	u8			dlid_path_bits;
10088c2ecf20Sopenharmony_ci	u8			port_num;	/* valid only for DR SMPs on switches */
10098c2ecf20Sopenharmony_ci	u8			smac[ETH_ALEN];
10108c2ecf20Sopenharmony_ci	u16			vlan_id;
10118c2ecf20Sopenharmony_ci	u8			network_hdr_type;
10128c2ecf20Sopenharmony_ci};
10138c2ecf20Sopenharmony_ci
10148c2ecf20Sopenharmony_cienum ib_cq_notify_flags {
10158c2ecf20Sopenharmony_ci	IB_CQ_SOLICITED			= 1 << 0,
10168c2ecf20Sopenharmony_ci	IB_CQ_NEXT_COMP			= 1 << 1,
10178c2ecf20Sopenharmony_ci	IB_CQ_SOLICITED_MASK		= IB_CQ_SOLICITED | IB_CQ_NEXT_COMP,
10188c2ecf20Sopenharmony_ci	IB_CQ_REPORT_MISSED_EVENTS	= 1 << 2,
10198c2ecf20Sopenharmony_ci};
10208c2ecf20Sopenharmony_ci
10218c2ecf20Sopenharmony_cienum ib_srq_type {
10228c2ecf20Sopenharmony_ci	IB_SRQT_BASIC = IB_UVERBS_SRQT_BASIC,
10238c2ecf20Sopenharmony_ci	IB_SRQT_XRC = IB_UVERBS_SRQT_XRC,
10248c2ecf20Sopenharmony_ci	IB_SRQT_TM = IB_UVERBS_SRQT_TM,
10258c2ecf20Sopenharmony_ci};
10268c2ecf20Sopenharmony_ci
10278c2ecf20Sopenharmony_cistatic inline bool ib_srq_has_cq(enum ib_srq_type srq_type)
10288c2ecf20Sopenharmony_ci{
10298c2ecf20Sopenharmony_ci	return srq_type == IB_SRQT_XRC ||
10308c2ecf20Sopenharmony_ci	       srq_type == IB_SRQT_TM;
10318c2ecf20Sopenharmony_ci}
10328c2ecf20Sopenharmony_ci
10338c2ecf20Sopenharmony_cienum ib_srq_attr_mask {
10348c2ecf20Sopenharmony_ci	IB_SRQ_MAX_WR	= 1 << 0,
10358c2ecf20Sopenharmony_ci	IB_SRQ_LIMIT	= 1 << 1,
10368c2ecf20Sopenharmony_ci};
10378c2ecf20Sopenharmony_ci
10388c2ecf20Sopenharmony_cistruct ib_srq_attr {
10398c2ecf20Sopenharmony_ci	u32	max_wr;
10408c2ecf20Sopenharmony_ci	u32	max_sge;
10418c2ecf20Sopenharmony_ci	u32	srq_limit;
10428c2ecf20Sopenharmony_ci};
10438c2ecf20Sopenharmony_ci
10448c2ecf20Sopenharmony_cistruct ib_srq_init_attr {
10458c2ecf20Sopenharmony_ci	void		      (*event_handler)(struct ib_event *, void *);
10468c2ecf20Sopenharmony_ci	void		       *srq_context;
10478c2ecf20Sopenharmony_ci	struct ib_srq_attr	attr;
10488c2ecf20Sopenharmony_ci	enum ib_srq_type	srq_type;
10498c2ecf20Sopenharmony_ci
10508c2ecf20Sopenharmony_ci	struct {
10518c2ecf20Sopenharmony_ci		struct ib_cq   *cq;
10528c2ecf20Sopenharmony_ci		union {
10538c2ecf20Sopenharmony_ci			struct {
10548c2ecf20Sopenharmony_ci				struct ib_xrcd *xrcd;
10558c2ecf20Sopenharmony_ci			} xrc;
10568c2ecf20Sopenharmony_ci
10578c2ecf20Sopenharmony_ci			struct {
10588c2ecf20Sopenharmony_ci				u32		max_num_tags;
10598c2ecf20Sopenharmony_ci			} tag_matching;
10608c2ecf20Sopenharmony_ci		};
10618c2ecf20Sopenharmony_ci	} ext;
10628c2ecf20Sopenharmony_ci};
10638c2ecf20Sopenharmony_ci
10648c2ecf20Sopenharmony_cistruct ib_qp_cap {
10658c2ecf20Sopenharmony_ci	u32	max_send_wr;
10668c2ecf20Sopenharmony_ci	u32	max_recv_wr;
10678c2ecf20Sopenharmony_ci	u32	max_send_sge;
10688c2ecf20Sopenharmony_ci	u32	max_recv_sge;
10698c2ecf20Sopenharmony_ci	u32	max_inline_data;
10708c2ecf20Sopenharmony_ci
10718c2ecf20Sopenharmony_ci	/*
10728c2ecf20Sopenharmony_ci	 * Maximum number of rdma_rw_ctx structures in flight at a time.
10738c2ecf20Sopenharmony_ci	 * ib_create_qp() will calculate the right amount of neededed WRs
10748c2ecf20Sopenharmony_ci	 * and MRs based on this.
10758c2ecf20Sopenharmony_ci	 */
10768c2ecf20Sopenharmony_ci	u32	max_rdma_ctxs;
10778c2ecf20Sopenharmony_ci};
10788c2ecf20Sopenharmony_ci
10798c2ecf20Sopenharmony_cienum ib_sig_type {
10808c2ecf20Sopenharmony_ci	IB_SIGNAL_ALL_WR,
10818c2ecf20Sopenharmony_ci	IB_SIGNAL_REQ_WR
10828c2ecf20Sopenharmony_ci};
10838c2ecf20Sopenharmony_ci
10848c2ecf20Sopenharmony_cienum ib_qp_type {
10858c2ecf20Sopenharmony_ci	/*
10868c2ecf20Sopenharmony_ci	 * IB_QPT_SMI and IB_QPT_GSI have to be the first two entries
10878c2ecf20Sopenharmony_ci	 * here (and in that order) since the MAD layer uses them as
10888c2ecf20Sopenharmony_ci	 * indices into a 2-entry table.
10898c2ecf20Sopenharmony_ci	 */
10908c2ecf20Sopenharmony_ci	IB_QPT_SMI,
10918c2ecf20Sopenharmony_ci	IB_QPT_GSI,
10928c2ecf20Sopenharmony_ci
10938c2ecf20Sopenharmony_ci	IB_QPT_RC = IB_UVERBS_QPT_RC,
10948c2ecf20Sopenharmony_ci	IB_QPT_UC = IB_UVERBS_QPT_UC,
10958c2ecf20Sopenharmony_ci	IB_QPT_UD = IB_UVERBS_QPT_UD,
10968c2ecf20Sopenharmony_ci	IB_QPT_RAW_IPV6,
10978c2ecf20Sopenharmony_ci	IB_QPT_RAW_ETHERTYPE,
10988c2ecf20Sopenharmony_ci	IB_QPT_RAW_PACKET = IB_UVERBS_QPT_RAW_PACKET,
10998c2ecf20Sopenharmony_ci	IB_QPT_XRC_INI = IB_UVERBS_QPT_XRC_INI,
11008c2ecf20Sopenharmony_ci	IB_QPT_XRC_TGT = IB_UVERBS_QPT_XRC_TGT,
11018c2ecf20Sopenharmony_ci	IB_QPT_MAX,
11028c2ecf20Sopenharmony_ci	IB_QPT_DRIVER = IB_UVERBS_QPT_DRIVER,
11038c2ecf20Sopenharmony_ci	/* Reserve a range for qp types internal to the low level driver.
11048c2ecf20Sopenharmony_ci	 * These qp types will not be visible at the IB core layer, so the
11058c2ecf20Sopenharmony_ci	 * IB_QPT_MAX usages should not be affected in the core layer
11068c2ecf20Sopenharmony_ci	 */
11078c2ecf20Sopenharmony_ci	IB_QPT_RESERVED1 = 0x1000,
11088c2ecf20Sopenharmony_ci	IB_QPT_RESERVED2,
11098c2ecf20Sopenharmony_ci	IB_QPT_RESERVED3,
11108c2ecf20Sopenharmony_ci	IB_QPT_RESERVED4,
11118c2ecf20Sopenharmony_ci	IB_QPT_RESERVED5,
11128c2ecf20Sopenharmony_ci	IB_QPT_RESERVED6,
11138c2ecf20Sopenharmony_ci	IB_QPT_RESERVED7,
11148c2ecf20Sopenharmony_ci	IB_QPT_RESERVED8,
11158c2ecf20Sopenharmony_ci	IB_QPT_RESERVED9,
11168c2ecf20Sopenharmony_ci	IB_QPT_RESERVED10,
11178c2ecf20Sopenharmony_ci};
11188c2ecf20Sopenharmony_ci
11198c2ecf20Sopenharmony_cienum ib_qp_create_flags {
11208c2ecf20Sopenharmony_ci	IB_QP_CREATE_IPOIB_UD_LSO		= 1 << 0,
11218c2ecf20Sopenharmony_ci	IB_QP_CREATE_BLOCK_MULTICAST_LOOPBACK	=
11228c2ecf20Sopenharmony_ci		IB_UVERBS_QP_CREATE_BLOCK_MULTICAST_LOOPBACK,
11238c2ecf20Sopenharmony_ci	IB_QP_CREATE_CROSS_CHANNEL              = 1 << 2,
11248c2ecf20Sopenharmony_ci	IB_QP_CREATE_MANAGED_SEND               = 1 << 3,
11258c2ecf20Sopenharmony_ci	IB_QP_CREATE_MANAGED_RECV               = 1 << 4,
11268c2ecf20Sopenharmony_ci	IB_QP_CREATE_NETIF_QP			= 1 << 5,
11278c2ecf20Sopenharmony_ci	IB_QP_CREATE_INTEGRITY_EN		= 1 << 6,
11288c2ecf20Sopenharmony_ci	IB_QP_CREATE_NETDEV_USE			= 1 << 7,
11298c2ecf20Sopenharmony_ci	IB_QP_CREATE_SCATTER_FCS		=
11308c2ecf20Sopenharmony_ci		IB_UVERBS_QP_CREATE_SCATTER_FCS,
11318c2ecf20Sopenharmony_ci	IB_QP_CREATE_CVLAN_STRIPPING		=
11328c2ecf20Sopenharmony_ci		IB_UVERBS_QP_CREATE_CVLAN_STRIPPING,
11338c2ecf20Sopenharmony_ci	IB_QP_CREATE_SOURCE_QPN			= 1 << 10,
11348c2ecf20Sopenharmony_ci	IB_QP_CREATE_PCI_WRITE_END_PADDING	=
11358c2ecf20Sopenharmony_ci		IB_UVERBS_QP_CREATE_PCI_WRITE_END_PADDING,
11368c2ecf20Sopenharmony_ci	/* reserve bits 26-31 for low level drivers' internal use */
11378c2ecf20Sopenharmony_ci	IB_QP_CREATE_RESERVED_START		= 1 << 26,
11388c2ecf20Sopenharmony_ci	IB_QP_CREATE_RESERVED_END		= 1 << 31,
11398c2ecf20Sopenharmony_ci};
11408c2ecf20Sopenharmony_ci
11418c2ecf20Sopenharmony_ci/*
11428c2ecf20Sopenharmony_ci * Note: users may not call ib_close_qp or ib_destroy_qp from the event_handler
11438c2ecf20Sopenharmony_ci * callback to destroy the passed in QP.
11448c2ecf20Sopenharmony_ci */
11458c2ecf20Sopenharmony_ci
11468c2ecf20Sopenharmony_cistruct ib_qp_init_attr {
11478c2ecf20Sopenharmony_ci	/* Consumer's event_handler callback must not block */
11488c2ecf20Sopenharmony_ci	void                  (*event_handler)(struct ib_event *, void *);
11498c2ecf20Sopenharmony_ci
11508c2ecf20Sopenharmony_ci	void		       *qp_context;
11518c2ecf20Sopenharmony_ci	struct ib_cq	       *send_cq;
11528c2ecf20Sopenharmony_ci	struct ib_cq	       *recv_cq;
11538c2ecf20Sopenharmony_ci	struct ib_srq	       *srq;
11548c2ecf20Sopenharmony_ci	struct ib_xrcd	       *xrcd;     /* XRC TGT QPs only */
11558c2ecf20Sopenharmony_ci	struct ib_qp_cap	cap;
11568c2ecf20Sopenharmony_ci	enum ib_sig_type	sq_sig_type;
11578c2ecf20Sopenharmony_ci	enum ib_qp_type		qp_type;
11588c2ecf20Sopenharmony_ci	u32			create_flags;
11598c2ecf20Sopenharmony_ci
11608c2ecf20Sopenharmony_ci	/*
11618c2ecf20Sopenharmony_ci	 * Only needed for special QP types, or when using the RW API.
11628c2ecf20Sopenharmony_ci	 */
11638c2ecf20Sopenharmony_ci	u8			port_num;
11648c2ecf20Sopenharmony_ci	struct ib_rwq_ind_table *rwq_ind_tbl;
11658c2ecf20Sopenharmony_ci	u32			source_qpn;
11668c2ecf20Sopenharmony_ci};
11678c2ecf20Sopenharmony_ci
11688c2ecf20Sopenharmony_cistruct ib_qp_open_attr {
11698c2ecf20Sopenharmony_ci	void                  (*event_handler)(struct ib_event *, void *);
11708c2ecf20Sopenharmony_ci	void		       *qp_context;
11718c2ecf20Sopenharmony_ci	u32			qp_num;
11728c2ecf20Sopenharmony_ci	enum ib_qp_type		qp_type;
11738c2ecf20Sopenharmony_ci};
11748c2ecf20Sopenharmony_ci
11758c2ecf20Sopenharmony_cienum ib_rnr_timeout {
11768c2ecf20Sopenharmony_ci	IB_RNR_TIMER_655_36 =  0,
11778c2ecf20Sopenharmony_ci	IB_RNR_TIMER_000_01 =  1,
11788c2ecf20Sopenharmony_ci	IB_RNR_TIMER_000_02 =  2,
11798c2ecf20Sopenharmony_ci	IB_RNR_TIMER_000_03 =  3,
11808c2ecf20Sopenharmony_ci	IB_RNR_TIMER_000_04 =  4,
11818c2ecf20Sopenharmony_ci	IB_RNR_TIMER_000_06 =  5,
11828c2ecf20Sopenharmony_ci	IB_RNR_TIMER_000_08 =  6,
11838c2ecf20Sopenharmony_ci	IB_RNR_TIMER_000_12 =  7,
11848c2ecf20Sopenharmony_ci	IB_RNR_TIMER_000_16 =  8,
11858c2ecf20Sopenharmony_ci	IB_RNR_TIMER_000_24 =  9,
11868c2ecf20Sopenharmony_ci	IB_RNR_TIMER_000_32 = 10,
11878c2ecf20Sopenharmony_ci	IB_RNR_TIMER_000_48 = 11,
11888c2ecf20Sopenharmony_ci	IB_RNR_TIMER_000_64 = 12,
11898c2ecf20Sopenharmony_ci	IB_RNR_TIMER_000_96 = 13,
11908c2ecf20Sopenharmony_ci	IB_RNR_TIMER_001_28 = 14,
11918c2ecf20Sopenharmony_ci	IB_RNR_TIMER_001_92 = 15,
11928c2ecf20Sopenharmony_ci	IB_RNR_TIMER_002_56 = 16,
11938c2ecf20Sopenharmony_ci	IB_RNR_TIMER_003_84 = 17,
11948c2ecf20Sopenharmony_ci	IB_RNR_TIMER_005_12 = 18,
11958c2ecf20Sopenharmony_ci	IB_RNR_TIMER_007_68 = 19,
11968c2ecf20Sopenharmony_ci	IB_RNR_TIMER_010_24 = 20,
11978c2ecf20Sopenharmony_ci	IB_RNR_TIMER_015_36 = 21,
11988c2ecf20Sopenharmony_ci	IB_RNR_TIMER_020_48 = 22,
11998c2ecf20Sopenharmony_ci	IB_RNR_TIMER_030_72 = 23,
12008c2ecf20Sopenharmony_ci	IB_RNR_TIMER_040_96 = 24,
12018c2ecf20Sopenharmony_ci	IB_RNR_TIMER_061_44 = 25,
12028c2ecf20Sopenharmony_ci	IB_RNR_TIMER_081_92 = 26,
12038c2ecf20Sopenharmony_ci	IB_RNR_TIMER_122_88 = 27,
12048c2ecf20Sopenharmony_ci	IB_RNR_TIMER_163_84 = 28,
12058c2ecf20Sopenharmony_ci	IB_RNR_TIMER_245_76 = 29,
12068c2ecf20Sopenharmony_ci	IB_RNR_TIMER_327_68 = 30,
12078c2ecf20Sopenharmony_ci	IB_RNR_TIMER_491_52 = 31
12088c2ecf20Sopenharmony_ci};
12098c2ecf20Sopenharmony_ci
12108c2ecf20Sopenharmony_cienum ib_qp_attr_mask {
12118c2ecf20Sopenharmony_ci	IB_QP_STATE			= 1,
12128c2ecf20Sopenharmony_ci	IB_QP_CUR_STATE			= (1<<1),
12138c2ecf20Sopenharmony_ci	IB_QP_EN_SQD_ASYNC_NOTIFY	= (1<<2),
12148c2ecf20Sopenharmony_ci	IB_QP_ACCESS_FLAGS		= (1<<3),
12158c2ecf20Sopenharmony_ci	IB_QP_PKEY_INDEX		= (1<<4),
12168c2ecf20Sopenharmony_ci	IB_QP_PORT			= (1<<5),
12178c2ecf20Sopenharmony_ci	IB_QP_QKEY			= (1<<6),
12188c2ecf20Sopenharmony_ci	IB_QP_AV			= (1<<7),
12198c2ecf20Sopenharmony_ci	IB_QP_PATH_MTU			= (1<<8),
12208c2ecf20Sopenharmony_ci	IB_QP_TIMEOUT			= (1<<9),
12218c2ecf20Sopenharmony_ci	IB_QP_RETRY_CNT			= (1<<10),
12228c2ecf20Sopenharmony_ci	IB_QP_RNR_RETRY			= (1<<11),
12238c2ecf20Sopenharmony_ci	IB_QP_RQ_PSN			= (1<<12),
12248c2ecf20Sopenharmony_ci	IB_QP_MAX_QP_RD_ATOMIC		= (1<<13),
12258c2ecf20Sopenharmony_ci	IB_QP_ALT_PATH			= (1<<14),
12268c2ecf20Sopenharmony_ci	IB_QP_MIN_RNR_TIMER		= (1<<15),
12278c2ecf20Sopenharmony_ci	IB_QP_SQ_PSN			= (1<<16),
12288c2ecf20Sopenharmony_ci	IB_QP_MAX_DEST_RD_ATOMIC	= (1<<17),
12298c2ecf20Sopenharmony_ci	IB_QP_PATH_MIG_STATE		= (1<<18),
12308c2ecf20Sopenharmony_ci	IB_QP_CAP			= (1<<19),
12318c2ecf20Sopenharmony_ci	IB_QP_DEST_QPN			= (1<<20),
12328c2ecf20Sopenharmony_ci	IB_QP_RESERVED1			= (1<<21),
12338c2ecf20Sopenharmony_ci	IB_QP_RESERVED2			= (1<<22),
12348c2ecf20Sopenharmony_ci	IB_QP_RESERVED3			= (1<<23),
12358c2ecf20Sopenharmony_ci	IB_QP_RESERVED4			= (1<<24),
12368c2ecf20Sopenharmony_ci	IB_QP_RATE_LIMIT		= (1<<25),
12378c2ecf20Sopenharmony_ci};
12388c2ecf20Sopenharmony_ci
12398c2ecf20Sopenharmony_cienum ib_qp_state {
12408c2ecf20Sopenharmony_ci	IB_QPS_RESET,
12418c2ecf20Sopenharmony_ci	IB_QPS_INIT,
12428c2ecf20Sopenharmony_ci	IB_QPS_RTR,
12438c2ecf20Sopenharmony_ci	IB_QPS_RTS,
12448c2ecf20Sopenharmony_ci	IB_QPS_SQD,
12458c2ecf20Sopenharmony_ci	IB_QPS_SQE,
12468c2ecf20Sopenharmony_ci	IB_QPS_ERR
12478c2ecf20Sopenharmony_ci};
12488c2ecf20Sopenharmony_ci
12498c2ecf20Sopenharmony_cienum ib_mig_state {
12508c2ecf20Sopenharmony_ci	IB_MIG_MIGRATED,
12518c2ecf20Sopenharmony_ci	IB_MIG_REARM,
12528c2ecf20Sopenharmony_ci	IB_MIG_ARMED
12538c2ecf20Sopenharmony_ci};
12548c2ecf20Sopenharmony_ci
12558c2ecf20Sopenharmony_cienum ib_mw_type {
12568c2ecf20Sopenharmony_ci	IB_MW_TYPE_1 = 1,
12578c2ecf20Sopenharmony_ci	IB_MW_TYPE_2 = 2
12588c2ecf20Sopenharmony_ci};
12598c2ecf20Sopenharmony_ci
12608c2ecf20Sopenharmony_cistruct ib_qp_attr {
12618c2ecf20Sopenharmony_ci	enum ib_qp_state	qp_state;
12628c2ecf20Sopenharmony_ci	enum ib_qp_state	cur_qp_state;
12638c2ecf20Sopenharmony_ci	enum ib_mtu		path_mtu;
12648c2ecf20Sopenharmony_ci	enum ib_mig_state	path_mig_state;
12658c2ecf20Sopenharmony_ci	u32			qkey;
12668c2ecf20Sopenharmony_ci	u32			rq_psn;
12678c2ecf20Sopenharmony_ci	u32			sq_psn;
12688c2ecf20Sopenharmony_ci	u32			dest_qp_num;
12698c2ecf20Sopenharmony_ci	int			qp_access_flags;
12708c2ecf20Sopenharmony_ci	struct ib_qp_cap	cap;
12718c2ecf20Sopenharmony_ci	struct rdma_ah_attr	ah_attr;
12728c2ecf20Sopenharmony_ci	struct rdma_ah_attr	alt_ah_attr;
12738c2ecf20Sopenharmony_ci	u16			pkey_index;
12748c2ecf20Sopenharmony_ci	u16			alt_pkey_index;
12758c2ecf20Sopenharmony_ci	u8			en_sqd_async_notify;
12768c2ecf20Sopenharmony_ci	u8			sq_draining;
12778c2ecf20Sopenharmony_ci	u8			max_rd_atomic;
12788c2ecf20Sopenharmony_ci	u8			max_dest_rd_atomic;
12798c2ecf20Sopenharmony_ci	u8			min_rnr_timer;
12808c2ecf20Sopenharmony_ci	u8			port_num;
12818c2ecf20Sopenharmony_ci	u8			timeout;
12828c2ecf20Sopenharmony_ci	u8			retry_cnt;
12838c2ecf20Sopenharmony_ci	u8			rnr_retry;
12848c2ecf20Sopenharmony_ci	u8			alt_port_num;
12858c2ecf20Sopenharmony_ci	u8			alt_timeout;
12868c2ecf20Sopenharmony_ci	u32			rate_limit;
12878c2ecf20Sopenharmony_ci	struct net_device	*xmit_slave;
12888c2ecf20Sopenharmony_ci};
12898c2ecf20Sopenharmony_ci
12908c2ecf20Sopenharmony_cienum ib_wr_opcode {
12918c2ecf20Sopenharmony_ci	/* These are shared with userspace */
12928c2ecf20Sopenharmony_ci	IB_WR_RDMA_WRITE = IB_UVERBS_WR_RDMA_WRITE,
12938c2ecf20Sopenharmony_ci	IB_WR_RDMA_WRITE_WITH_IMM = IB_UVERBS_WR_RDMA_WRITE_WITH_IMM,
12948c2ecf20Sopenharmony_ci	IB_WR_SEND = IB_UVERBS_WR_SEND,
12958c2ecf20Sopenharmony_ci	IB_WR_SEND_WITH_IMM = IB_UVERBS_WR_SEND_WITH_IMM,
12968c2ecf20Sopenharmony_ci	IB_WR_RDMA_READ = IB_UVERBS_WR_RDMA_READ,
12978c2ecf20Sopenharmony_ci	IB_WR_ATOMIC_CMP_AND_SWP = IB_UVERBS_WR_ATOMIC_CMP_AND_SWP,
12988c2ecf20Sopenharmony_ci	IB_WR_ATOMIC_FETCH_AND_ADD = IB_UVERBS_WR_ATOMIC_FETCH_AND_ADD,
12998c2ecf20Sopenharmony_ci	IB_WR_BIND_MW = IB_UVERBS_WR_BIND_MW,
13008c2ecf20Sopenharmony_ci	IB_WR_LSO = IB_UVERBS_WR_TSO,
13018c2ecf20Sopenharmony_ci	IB_WR_SEND_WITH_INV = IB_UVERBS_WR_SEND_WITH_INV,
13028c2ecf20Sopenharmony_ci	IB_WR_RDMA_READ_WITH_INV = IB_UVERBS_WR_RDMA_READ_WITH_INV,
13038c2ecf20Sopenharmony_ci	IB_WR_LOCAL_INV = IB_UVERBS_WR_LOCAL_INV,
13048c2ecf20Sopenharmony_ci	IB_WR_MASKED_ATOMIC_CMP_AND_SWP =
13058c2ecf20Sopenharmony_ci		IB_UVERBS_WR_MASKED_ATOMIC_CMP_AND_SWP,
13068c2ecf20Sopenharmony_ci	IB_WR_MASKED_ATOMIC_FETCH_AND_ADD =
13078c2ecf20Sopenharmony_ci		IB_UVERBS_WR_MASKED_ATOMIC_FETCH_AND_ADD,
13088c2ecf20Sopenharmony_ci
13098c2ecf20Sopenharmony_ci	/* These are kernel only and can not be issued by userspace */
13108c2ecf20Sopenharmony_ci	IB_WR_REG_MR = 0x20,
13118c2ecf20Sopenharmony_ci	IB_WR_REG_MR_INTEGRITY,
13128c2ecf20Sopenharmony_ci
13138c2ecf20Sopenharmony_ci	/* reserve values for low level drivers' internal use.
13148c2ecf20Sopenharmony_ci	 * These values will not be used at all in the ib core layer.
13158c2ecf20Sopenharmony_ci	 */
13168c2ecf20Sopenharmony_ci	IB_WR_RESERVED1 = 0xf0,
13178c2ecf20Sopenharmony_ci	IB_WR_RESERVED2,
13188c2ecf20Sopenharmony_ci	IB_WR_RESERVED3,
13198c2ecf20Sopenharmony_ci	IB_WR_RESERVED4,
13208c2ecf20Sopenharmony_ci	IB_WR_RESERVED5,
13218c2ecf20Sopenharmony_ci	IB_WR_RESERVED6,
13228c2ecf20Sopenharmony_ci	IB_WR_RESERVED7,
13238c2ecf20Sopenharmony_ci	IB_WR_RESERVED8,
13248c2ecf20Sopenharmony_ci	IB_WR_RESERVED9,
13258c2ecf20Sopenharmony_ci	IB_WR_RESERVED10,
13268c2ecf20Sopenharmony_ci};
13278c2ecf20Sopenharmony_ci
13288c2ecf20Sopenharmony_cienum ib_send_flags {
13298c2ecf20Sopenharmony_ci	IB_SEND_FENCE		= 1,
13308c2ecf20Sopenharmony_ci	IB_SEND_SIGNALED	= (1<<1),
13318c2ecf20Sopenharmony_ci	IB_SEND_SOLICITED	= (1<<2),
13328c2ecf20Sopenharmony_ci	IB_SEND_INLINE		= (1<<3),
13338c2ecf20Sopenharmony_ci	IB_SEND_IP_CSUM		= (1<<4),
13348c2ecf20Sopenharmony_ci
13358c2ecf20Sopenharmony_ci	/* reserve bits 26-31 for low level drivers' internal use */
13368c2ecf20Sopenharmony_ci	IB_SEND_RESERVED_START	= (1 << 26),
13378c2ecf20Sopenharmony_ci	IB_SEND_RESERVED_END	= (1 << 31),
13388c2ecf20Sopenharmony_ci};
13398c2ecf20Sopenharmony_ci
13408c2ecf20Sopenharmony_cistruct ib_sge {
13418c2ecf20Sopenharmony_ci	u64	addr;
13428c2ecf20Sopenharmony_ci	u32	length;
13438c2ecf20Sopenharmony_ci	u32	lkey;
13448c2ecf20Sopenharmony_ci};
13458c2ecf20Sopenharmony_ci
13468c2ecf20Sopenharmony_cistruct ib_cqe {
13478c2ecf20Sopenharmony_ci	void (*done)(struct ib_cq *cq, struct ib_wc *wc);
13488c2ecf20Sopenharmony_ci};
13498c2ecf20Sopenharmony_ci
13508c2ecf20Sopenharmony_cistruct ib_send_wr {
13518c2ecf20Sopenharmony_ci	struct ib_send_wr      *next;
13528c2ecf20Sopenharmony_ci	union {
13538c2ecf20Sopenharmony_ci		u64		wr_id;
13548c2ecf20Sopenharmony_ci		struct ib_cqe	*wr_cqe;
13558c2ecf20Sopenharmony_ci	};
13568c2ecf20Sopenharmony_ci	struct ib_sge	       *sg_list;
13578c2ecf20Sopenharmony_ci	int			num_sge;
13588c2ecf20Sopenharmony_ci	enum ib_wr_opcode	opcode;
13598c2ecf20Sopenharmony_ci	int			send_flags;
13608c2ecf20Sopenharmony_ci	union {
13618c2ecf20Sopenharmony_ci		__be32		imm_data;
13628c2ecf20Sopenharmony_ci		u32		invalidate_rkey;
13638c2ecf20Sopenharmony_ci	} ex;
13648c2ecf20Sopenharmony_ci};
13658c2ecf20Sopenharmony_ci
13668c2ecf20Sopenharmony_cistruct ib_rdma_wr {
13678c2ecf20Sopenharmony_ci	struct ib_send_wr	wr;
13688c2ecf20Sopenharmony_ci	u64			remote_addr;
13698c2ecf20Sopenharmony_ci	u32			rkey;
13708c2ecf20Sopenharmony_ci};
13718c2ecf20Sopenharmony_ci
13728c2ecf20Sopenharmony_cistatic inline const struct ib_rdma_wr *rdma_wr(const struct ib_send_wr *wr)
13738c2ecf20Sopenharmony_ci{
13748c2ecf20Sopenharmony_ci	return container_of(wr, struct ib_rdma_wr, wr);
13758c2ecf20Sopenharmony_ci}
13768c2ecf20Sopenharmony_ci
13778c2ecf20Sopenharmony_cistruct ib_atomic_wr {
13788c2ecf20Sopenharmony_ci	struct ib_send_wr	wr;
13798c2ecf20Sopenharmony_ci	u64			remote_addr;
13808c2ecf20Sopenharmony_ci	u64			compare_add;
13818c2ecf20Sopenharmony_ci	u64			swap;
13828c2ecf20Sopenharmony_ci	u64			compare_add_mask;
13838c2ecf20Sopenharmony_ci	u64			swap_mask;
13848c2ecf20Sopenharmony_ci	u32			rkey;
13858c2ecf20Sopenharmony_ci};
13868c2ecf20Sopenharmony_ci
13878c2ecf20Sopenharmony_cistatic inline const struct ib_atomic_wr *atomic_wr(const struct ib_send_wr *wr)
13888c2ecf20Sopenharmony_ci{
13898c2ecf20Sopenharmony_ci	return container_of(wr, struct ib_atomic_wr, wr);
13908c2ecf20Sopenharmony_ci}
13918c2ecf20Sopenharmony_ci
13928c2ecf20Sopenharmony_cistruct ib_ud_wr {
13938c2ecf20Sopenharmony_ci	struct ib_send_wr	wr;
13948c2ecf20Sopenharmony_ci	struct ib_ah		*ah;
13958c2ecf20Sopenharmony_ci	void			*header;
13968c2ecf20Sopenharmony_ci	int			hlen;
13978c2ecf20Sopenharmony_ci	int			mss;
13988c2ecf20Sopenharmony_ci	u32			remote_qpn;
13998c2ecf20Sopenharmony_ci	u32			remote_qkey;
14008c2ecf20Sopenharmony_ci	u16			pkey_index; /* valid for GSI only */
14018c2ecf20Sopenharmony_ci	u8			port_num;   /* valid for DR SMPs on switch only */
14028c2ecf20Sopenharmony_ci};
14038c2ecf20Sopenharmony_ci
14048c2ecf20Sopenharmony_cistatic inline const struct ib_ud_wr *ud_wr(const struct ib_send_wr *wr)
14058c2ecf20Sopenharmony_ci{
14068c2ecf20Sopenharmony_ci	return container_of(wr, struct ib_ud_wr, wr);
14078c2ecf20Sopenharmony_ci}
14088c2ecf20Sopenharmony_ci
14098c2ecf20Sopenharmony_cistruct ib_reg_wr {
14108c2ecf20Sopenharmony_ci	struct ib_send_wr	wr;
14118c2ecf20Sopenharmony_ci	struct ib_mr		*mr;
14128c2ecf20Sopenharmony_ci	u32			key;
14138c2ecf20Sopenharmony_ci	int			access;
14148c2ecf20Sopenharmony_ci};
14158c2ecf20Sopenharmony_ci
14168c2ecf20Sopenharmony_cistatic inline const struct ib_reg_wr *reg_wr(const struct ib_send_wr *wr)
14178c2ecf20Sopenharmony_ci{
14188c2ecf20Sopenharmony_ci	return container_of(wr, struct ib_reg_wr, wr);
14198c2ecf20Sopenharmony_ci}
14208c2ecf20Sopenharmony_ci
14218c2ecf20Sopenharmony_cistruct ib_recv_wr {
14228c2ecf20Sopenharmony_ci	struct ib_recv_wr      *next;
14238c2ecf20Sopenharmony_ci	union {
14248c2ecf20Sopenharmony_ci		u64		wr_id;
14258c2ecf20Sopenharmony_ci		struct ib_cqe	*wr_cqe;
14268c2ecf20Sopenharmony_ci	};
14278c2ecf20Sopenharmony_ci	struct ib_sge	       *sg_list;
14288c2ecf20Sopenharmony_ci	int			num_sge;
14298c2ecf20Sopenharmony_ci};
14308c2ecf20Sopenharmony_ci
14318c2ecf20Sopenharmony_cienum ib_access_flags {
14328c2ecf20Sopenharmony_ci	IB_ACCESS_LOCAL_WRITE = IB_UVERBS_ACCESS_LOCAL_WRITE,
14338c2ecf20Sopenharmony_ci	IB_ACCESS_REMOTE_WRITE = IB_UVERBS_ACCESS_REMOTE_WRITE,
14348c2ecf20Sopenharmony_ci	IB_ACCESS_REMOTE_READ = IB_UVERBS_ACCESS_REMOTE_READ,
14358c2ecf20Sopenharmony_ci	IB_ACCESS_REMOTE_ATOMIC = IB_UVERBS_ACCESS_REMOTE_ATOMIC,
14368c2ecf20Sopenharmony_ci	IB_ACCESS_MW_BIND = IB_UVERBS_ACCESS_MW_BIND,
14378c2ecf20Sopenharmony_ci	IB_ZERO_BASED = IB_UVERBS_ACCESS_ZERO_BASED,
14388c2ecf20Sopenharmony_ci	IB_ACCESS_ON_DEMAND = IB_UVERBS_ACCESS_ON_DEMAND,
14398c2ecf20Sopenharmony_ci	IB_ACCESS_HUGETLB = IB_UVERBS_ACCESS_HUGETLB,
14408c2ecf20Sopenharmony_ci	IB_ACCESS_RELAXED_ORDERING = IB_UVERBS_ACCESS_RELAXED_ORDERING,
14418c2ecf20Sopenharmony_ci
14428c2ecf20Sopenharmony_ci	IB_ACCESS_OPTIONAL = IB_UVERBS_ACCESS_OPTIONAL_RANGE,
14438c2ecf20Sopenharmony_ci	IB_ACCESS_SUPPORTED =
14448c2ecf20Sopenharmony_ci		((IB_ACCESS_HUGETLB << 1) - 1) | IB_ACCESS_OPTIONAL,
14458c2ecf20Sopenharmony_ci};
14468c2ecf20Sopenharmony_ci
14478c2ecf20Sopenharmony_ci/*
14488c2ecf20Sopenharmony_ci * XXX: these are apparently used for ->rereg_user_mr, no idea why they
14498c2ecf20Sopenharmony_ci * are hidden here instead of a uapi header!
14508c2ecf20Sopenharmony_ci */
14518c2ecf20Sopenharmony_cienum ib_mr_rereg_flags {
14528c2ecf20Sopenharmony_ci	IB_MR_REREG_TRANS	= 1,
14538c2ecf20Sopenharmony_ci	IB_MR_REREG_PD		= (1<<1),
14548c2ecf20Sopenharmony_ci	IB_MR_REREG_ACCESS	= (1<<2),
14558c2ecf20Sopenharmony_ci	IB_MR_REREG_SUPPORTED	= ((IB_MR_REREG_ACCESS << 1) - 1)
14568c2ecf20Sopenharmony_ci};
14578c2ecf20Sopenharmony_ci
14588c2ecf20Sopenharmony_cistruct ib_umem;
14598c2ecf20Sopenharmony_ci
14608c2ecf20Sopenharmony_cienum rdma_remove_reason {
14618c2ecf20Sopenharmony_ci	/*
14628c2ecf20Sopenharmony_ci	 * Userspace requested uobject deletion or initial try
14638c2ecf20Sopenharmony_ci	 * to remove uobject via cleanup. Call could fail
14648c2ecf20Sopenharmony_ci	 */
14658c2ecf20Sopenharmony_ci	RDMA_REMOVE_DESTROY,
14668c2ecf20Sopenharmony_ci	/* Context deletion. This call should delete the actual object itself */
14678c2ecf20Sopenharmony_ci	RDMA_REMOVE_CLOSE,
14688c2ecf20Sopenharmony_ci	/* Driver is being hot-unplugged. This call should delete the actual object itself */
14698c2ecf20Sopenharmony_ci	RDMA_REMOVE_DRIVER_REMOVE,
14708c2ecf20Sopenharmony_ci	/* uobj is being cleaned-up before being committed */
14718c2ecf20Sopenharmony_ci	RDMA_REMOVE_ABORT,
14728c2ecf20Sopenharmony_ci};
14738c2ecf20Sopenharmony_ci
14748c2ecf20Sopenharmony_cistruct ib_rdmacg_object {
14758c2ecf20Sopenharmony_ci#ifdef CONFIG_CGROUP_RDMA
14768c2ecf20Sopenharmony_ci	struct rdma_cgroup	*cg;		/* owner rdma cgroup */
14778c2ecf20Sopenharmony_ci#endif
14788c2ecf20Sopenharmony_ci};
14798c2ecf20Sopenharmony_ci
14808c2ecf20Sopenharmony_cistruct ib_ucontext {
14818c2ecf20Sopenharmony_ci	struct ib_device       *device;
14828c2ecf20Sopenharmony_ci	struct ib_uverbs_file  *ufile;
14838c2ecf20Sopenharmony_ci
14848c2ecf20Sopenharmony_ci	bool cleanup_retryable;
14858c2ecf20Sopenharmony_ci
14868c2ecf20Sopenharmony_ci	struct ib_rdmacg_object	cg_obj;
14878c2ecf20Sopenharmony_ci	/*
14888c2ecf20Sopenharmony_ci	 * Implementation details of the RDMA core, don't use in drivers:
14898c2ecf20Sopenharmony_ci	 */
14908c2ecf20Sopenharmony_ci	struct rdma_restrack_entry res;
14918c2ecf20Sopenharmony_ci	struct xarray mmap_xa;
14928c2ecf20Sopenharmony_ci};
14938c2ecf20Sopenharmony_ci
14948c2ecf20Sopenharmony_cistruct ib_uobject {
14958c2ecf20Sopenharmony_ci	u64			user_handle;	/* handle given to us by userspace */
14968c2ecf20Sopenharmony_ci	/* ufile & ucontext owning this object */
14978c2ecf20Sopenharmony_ci	struct ib_uverbs_file  *ufile;
14988c2ecf20Sopenharmony_ci	/* FIXME, save memory: ufile->context == context */
14998c2ecf20Sopenharmony_ci	struct ib_ucontext     *context;	/* associated user context */
15008c2ecf20Sopenharmony_ci	void		       *object;		/* containing object */
15018c2ecf20Sopenharmony_ci	struct list_head	list;		/* link to context's list */
15028c2ecf20Sopenharmony_ci	struct ib_rdmacg_object	cg_obj;		/* rdmacg object */
15038c2ecf20Sopenharmony_ci	int			id;		/* index into kernel idr */
15048c2ecf20Sopenharmony_ci	struct kref		ref;
15058c2ecf20Sopenharmony_ci	atomic_t		usecnt;		/* protects exclusive access */
15068c2ecf20Sopenharmony_ci	struct rcu_head		rcu;		/* kfree_rcu() overhead */
15078c2ecf20Sopenharmony_ci
15088c2ecf20Sopenharmony_ci	const struct uverbs_api_object *uapi_object;
15098c2ecf20Sopenharmony_ci};
15108c2ecf20Sopenharmony_ci
15118c2ecf20Sopenharmony_cistruct ib_udata {
15128c2ecf20Sopenharmony_ci	const void __user *inbuf;
15138c2ecf20Sopenharmony_ci	void __user *outbuf;
15148c2ecf20Sopenharmony_ci	size_t       inlen;
15158c2ecf20Sopenharmony_ci	size_t       outlen;
15168c2ecf20Sopenharmony_ci};
15178c2ecf20Sopenharmony_ci
15188c2ecf20Sopenharmony_cistruct ib_pd {
15198c2ecf20Sopenharmony_ci	u32			local_dma_lkey;
15208c2ecf20Sopenharmony_ci	u32			flags;
15218c2ecf20Sopenharmony_ci	struct ib_device       *device;
15228c2ecf20Sopenharmony_ci	struct ib_uobject      *uobject;
15238c2ecf20Sopenharmony_ci	atomic_t          	usecnt; /* count all resources */
15248c2ecf20Sopenharmony_ci
15258c2ecf20Sopenharmony_ci	u32			unsafe_global_rkey;
15268c2ecf20Sopenharmony_ci
15278c2ecf20Sopenharmony_ci	/*
15288c2ecf20Sopenharmony_ci	 * Implementation details of the RDMA core, don't use in drivers:
15298c2ecf20Sopenharmony_ci	 */
15308c2ecf20Sopenharmony_ci	struct ib_mr	       *__internal_mr;
15318c2ecf20Sopenharmony_ci	struct rdma_restrack_entry res;
15328c2ecf20Sopenharmony_ci};
15338c2ecf20Sopenharmony_ci
15348c2ecf20Sopenharmony_cistruct ib_xrcd {
15358c2ecf20Sopenharmony_ci	struct ib_device       *device;
15368c2ecf20Sopenharmony_ci	atomic_t		usecnt; /* count all exposed resources */
15378c2ecf20Sopenharmony_ci	struct inode	       *inode;
15388c2ecf20Sopenharmony_ci	struct rw_semaphore	tgt_qps_rwsem;
15398c2ecf20Sopenharmony_ci	struct xarray		tgt_qps;
15408c2ecf20Sopenharmony_ci};
15418c2ecf20Sopenharmony_ci
15428c2ecf20Sopenharmony_cistruct ib_ah {
15438c2ecf20Sopenharmony_ci	struct ib_device	*device;
15448c2ecf20Sopenharmony_ci	struct ib_pd		*pd;
15458c2ecf20Sopenharmony_ci	struct ib_uobject	*uobject;
15468c2ecf20Sopenharmony_ci	const struct ib_gid_attr *sgid_attr;
15478c2ecf20Sopenharmony_ci	enum rdma_ah_attr_type	type;
15488c2ecf20Sopenharmony_ci};
15498c2ecf20Sopenharmony_ci
15508c2ecf20Sopenharmony_citypedef void (*ib_comp_handler)(struct ib_cq *cq, void *cq_context);
15518c2ecf20Sopenharmony_ci
15528c2ecf20Sopenharmony_cienum ib_poll_context {
15538c2ecf20Sopenharmony_ci	IB_POLL_SOFTIRQ,	   /* poll from softirq context */
15548c2ecf20Sopenharmony_ci	IB_POLL_WORKQUEUE,	   /* poll from workqueue */
15558c2ecf20Sopenharmony_ci	IB_POLL_UNBOUND_WORKQUEUE, /* poll from unbound workqueue */
15568c2ecf20Sopenharmony_ci	IB_POLL_LAST_POOL_TYPE = IB_POLL_UNBOUND_WORKQUEUE,
15578c2ecf20Sopenharmony_ci
15588c2ecf20Sopenharmony_ci	IB_POLL_DIRECT,		   /* caller context, no hw completions */
15598c2ecf20Sopenharmony_ci};
15608c2ecf20Sopenharmony_ci
15618c2ecf20Sopenharmony_cistruct ib_cq {
15628c2ecf20Sopenharmony_ci	struct ib_device       *device;
15638c2ecf20Sopenharmony_ci	struct ib_ucq_object   *uobject;
15648c2ecf20Sopenharmony_ci	ib_comp_handler   	comp_handler;
15658c2ecf20Sopenharmony_ci	void                  (*event_handler)(struct ib_event *, void *);
15668c2ecf20Sopenharmony_ci	void                   *cq_context;
15678c2ecf20Sopenharmony_ci	int               	cqe;
15688c2ecf20Sopenharmony_ci	unsigned int		cqe_used;
15698c2ecf20Sopenharmony_ci	atomic_t          	usecnt; /* count number of work queues */
15708c2ecf20Sopenharmony_ci	enum ib_poll_context	poll_ctx;
15718c2ecf20Sopenharmony_ci	struct ib_wc		*wc;
15728c2ecf20Sopenharmony_ci	struct list_head        pool_entry;
15738c2ecf20Sopenharmony_ci	union {
15748c2ecf20Sopenharmony_ci		struct irq_poll		iop;
15758c2ecf20Sopenharmony_ci		struct work_struct	work;
15768c2ecf20Sopenharmony_ci	};
15778c2ecf20Sopenharmony_ci	struct workqueue_struct *comp_wq;
15788c2ecf20Sopenharmony_ci	struct dim *dim;
15798c2ecf20Sopenharmony_ci
15808c2ecf20Sopenharmony_ci	/* updated only by trace points */
15818c2ecf20Sopenharmony_ci	ktime_t timestamp;
15828c2ecf20Sopenharmony_ci	u8 interrupt:1;
15838c2ecf20Sopenharmony_ci	u8 shared:1;
15848c2ecf20Sopenharmony_ci	unsigned int comp_vector;
15858c2ecf20Sopenharmony_ci
15868c2ecf20Sopenharmony_ci	/*
15878c2ecf20Sopenharmony_ci	 * Implementation details of the RDMA core, don't use in drivers:
15888c2ecf20Sopenharmony_ci	 */
15898c2ecf20Sopenharmony_ci	struct rdma_restrack_entry res;
15908c2ecf20Sopenharmony_ci};
15918c2ecf20Sopenharmony_ci
15928c2ecf20Sopenharmony_cistruct ib_srq {
15938c2ecf20Sopenharmony_ci	struct ib_device       *device;
15948c2ecf20Sopenharmony_ci	struct ib_pd	       *pd;
15958c2ecf20Sopenharmony_ci	struct ib_usrq_object  *uobject;
15968c2ecf20Sopenharmony_ci	void		      (*event_handler)(struct ib_event *, void *);
15978c2ecf20Sopenharmony_ci	void		       *srq_context;
15988c2ecf20Sopenharmony_ci	enum ib_srq_type	srq_type;
15998c2ecf20Sopenharmony_ci	atomic_t		usecnt;
16008c2ecf20Sopenharmony_ci
16018c2ecf20Sopenharmony_ci	struct {
16028c2ecf20Sopenharmony_ci		struct ib_cq   *cq;
16038c2ecf20Sopenharmony_ci		union {
16048c2ecf20Sopenharmony_ci			struct {
16058c2ecf20Sopenharmony_ci				struct ib_xrcd *xrcd;
16068c2ecf20Sopenharmony_ci				u32		srq_num;
16078c2ecf20Sopenharmony_ci			} xrc;
16088c2ecf20Sopenharmony_ci		};
16098c2ecf20Sopenharmony_ci	} ext;
16108c2ecf20Sopenharmony_ci};
16118c2ecf20Sopenharmony_ci
16128c2ecf20Sopenharmony_cienum ib_raw_packet_caps {
16138c2ecf20Sopenharmony_ci	/* Strip cvlan from incoming packet and report it in the matching work
16148c2ecf20Sopenharmony_ci	 * completion is supported.
16158c2ecf20Sopenharmony_ci	 */
16168c2ecf20Sopenharmony_ci	IB_RAW_PACKET_CAP_CVLAN_STRIPPING	= (1 << 0),
16178c2ecf20Sopenharmony_ci	/* Scatter FCS field of an incoming packet to host memory is supported.
16188c2ecf20Sopenharmony_ci	 */
16198c2ecf20Sopenharmony_ci	IB_RAW_PACKET_CAP_SCATTER_FCS		= (1 << 1),
16208c2ecf20Sopenharmony_ci	/* Checksum offloads are supported (for both send and receive). */
16218c2ecf20Sopenharmony_ci	IB_RAW_PACKET_CAP_IP_CSUM		= (1 << 2),
16228c2ecf20Sopenharmony_ci	/* When a packet is received for an RQ with no receive WQEs, the
16238c2ecf20Sopenharmony_ci	 * packet processing is delayed.
16248c2ecf20Sopenharmony_ci	 */
16258c2ecf20Sopenharmony_ci	IB_RAW_PACKET_CAP_DELAY_DROP		= (1 << 3),
16268c2ecf20Sopenharmony_ci};
16278c2ecf20Sopenharmony_ci
16288c2ecf20Sopenharmony_cienum ib_wq_type {
16298c2ecf20Sopenharmony_ci	IB_WQT_RQ = IB_UVERBS_WQT_RQ,
16308c2ecf20Sopenharmony_ci};
16318c2ecf20Sopenharmony_ci
16328c2ecf20Sopenharmony_cienum ib_wq_state {
16338c2ecf20Sopenharmony_ci	IB_WQS_RESET,
16348c2ecf20Sopenharmony_ci	IB_WQS_RDY,
16358c2ecf20Sopenharmony_ci	IB_WQS_ERR
16368c2ecf20Sopenharmony_ci};
16378c2ecf20Sopenharmony_ci
16388c2ecf20Sopenharmony_cistruct ib_wq {
16398c2ecf20Sopenharmony_ci	struct ib_device       *device;
16408c2ecf20Sopenharmony_ci	struct ib_uwq_object   *uobject;
16418c2ecf20Sopenharmony_ci	void		    *wq_context;
16428c2ecf20Sopenharmony_ci	void		    (*event_handler)(struct ib_event *, void *);
16438c2ecf20Sopenharmony_ci	struct ib_pd	       *pd;
16448c2ecf20Sopenharmony_ci	struct ib_cq	       *cq;
16458c2ecf20Sopenharmony_ci	u32		wq_num;
16468c2ecf20Sopenharmony_ci	enum ib_wq_state       state;
16478c2ecf20Sopenharmony_ci	enum ib_wq_type	wq_type;
16488c2ecf20Sopenharmony_ci	atomic_t		usecnt;
16498c2ecf20Sopenharmony_ci};
16508c2ecf20Sopenharmony_ci
16518c2ecf20Sopenharmony_cienum ib_wq_flags {
16528c2ecf20Sopenharmony_ci	IB_WQ_FLAGS_CVLAN_STRIPPING	= IB_UVERBS_WQ_FLAGS_CVLAN_STRIPPING,
16538c2ecf20Sopenharmony_ci	IB_WQ_FLAGS_SCATTER_FCS		= IB_UVERBS_WQ_FLAGS_SCATTER_FCS,
16548c2ecf20Sopenharmony_ci	IB_WQ_FLAGS_DELAY_DROP		= IB_UVERBS_WQ_FLAGS_DELAY_DROP,
16558c2ecf20Sopenharmony_ci	IB_WQ_FLAGS_PCI_WRITE_END_PADDING =
16568c2ecf20Sopenharmony_ci				IB_UVERBS_WQ_FLAGS_PCI_WRITE_END_PADDING,
16578c2ecf20Sopenharmony_ci};
16588c2ecf20Sopenharmony_ci
16598c2ecf20Sopenharmony_cistruct ib_wq_init_attr {
16608c2ecf20Sopenharmony_ci	void		       *wq_context;
16618c2ecf20Sopenharmony_ci	enum ib_wq_type	wq_type;
16628c2ecf20Sopenharmony_ci	u32		max_wr;
16638c2ecf20Sopenharmony_ci	u32		max_sge;
16648c2ecf20Sopenharmony_ci	struct	ib_cq	       *cq;
16658c2ecf20Sopenharmony_ci	void		    (*event_handler)(struct ib_event *, void *);
16668c2ecf20Sopenharmony_ci	u32		create_flags; /* Use enum ib_wq_flags */
16678c2ecf20Sopenharmony_ci};
16688c2ecf20Sopenharmony_ci
16698c2ecf20Sopenharmony_cienum ib_wq_attr_mask {
16708c2ecf20Sopenharmony_ci	IB_WQ_STATE		= 1 << 0,
16718c2ecf20Sopenharmony_ci	IB_WQ_CUR_STATE		= 1 << 1,
16728c2ecf20Sopenharmony_ci	IB_WQ_FLAGS		= 1 << 2,
16738c2ecf20Sopenharmony_ci};
16748c2ecf20Sopenharmony_ci
16758c2ecf20Sopenharmony_cistruct ib_wq_attr {
16768c2ecf20Sopenharmony_ci	enum	ib_wq_state	wq_state;
16778c2ecf20Sopenharmony_ci	enum	ib_wq_state	curr_wq_state;
16788c2ecf20Sopenharmony_ci	u32			flags; /* Use enum ib_wq_flags */
16798c2ecf20Sopenharmony_ci	u32			flags_mask; /* Use enum ib_wq_flags */
16808c2ecf20Sopenharmony_ci};
16818c2ecf20Sopenharmony_ci
16828c2ecf20Sopenharmony_cistruct ib_rwq_ind_table {
16838c2ecf20Sopenharmony_ci	struct ib_device	*device;
16848c2ecf20Sopenharmony_ci	struct ib_uobject      *uobject;
16858c2ecf20Sopenharmony_ci	atomic_t		usecnt;
16868c2ecf20Sopenharmony_ci	u32		ind_tbl_num;
16878c2ecf20Sopenharmony_ci	u32		log_ind_tbl_size;
16888c2ecf20Sopenharmony_ci	struct ib_wq	**ind_tbl;
16898c2ecf20Sopenharmony_ci};
16908c2ecf20Sopenharmony_ci
16918c2ecf20Sopenharmony_cistruct ib_rwq_ind_table_init_attr {
16928c2ecf20Sopenharmony_ci	u32		log_ind_tbl_size;
16938c2ecf20Sopenharmony_ci	/* Each entry is a pointer to Receive Work Queue */
16948c2ecf20Sopenharmony_ci	struct ib_wq	**ind_tbl;
16958c2ecf20Sopenharmony_ci};
16968c2ecf20Sopenharmony_ci
16978c2ecf20Sopenharmony_cienum port_pkey_state {
16988c2ecf20Sopenharmony_ci	IB_PORT_PKEY_NOT_VALID = 0,
16998c2ecf20Sopenharmony_ci	IB_PORT_PKEY_VALID = 1,
17008c2ecf20Sopenharmony_ci	IB_PORT_PKEY_LISTED = 2,
17018c2ecf20Sopenharmony_ci};
17028c2ecf20Sopenharmony_ci
17038c2ecf20Sopenharmony_cistruct ib_qp_security;
17048c2ecf20Sopenharmony_ci
17058c2ecf20Sopenharmony_cistruct ib_port_pkey {
17068c2ecf20Sopenharmony_ci	enum port_pkey_state	state;
17078c2ecf20Sopenharmony_ci	u16			pkey_index;
17088c2ecf20Sopenharmony_ci	u8			port_num;
17098c2ecf20Sopenharmony_ci	struct list_head	qp_list;
17108c2ecf20Sopenharmony_ci	struct list_head	to_error_list;
17118c2ecf20Sopenharmony_ci	struct ib_qp_security  *sec;
17128c2ecf20Sopenharmony_ci};
17138c2ecf20Sopenharmony_ci
17148c2ecf20Sopenharmony_cistruct ib_ports_pkeys {
17158c2ecf20Sopenharmony_ci	struct ib_port_pkey	main;
17168c2ecf20Sopenharmony_ci	struct ib_port_pkey	alt;
17178c2ecf20Sopenharmony_ci};
17188c2ecf20Sopenharmony_ci
17198c2ecf20Sopenharmony_cistruct ib_qp_security {
17208c2ecf20Sopenharmony_ci	struct ib_qp	       *qp;
17218c2ecf20Sopenharmony_ci	struct ib_device       *dev;
17228c2ecf20Sopenharmony_ci	/* Hold this mutex when changing port and pkey settings. */
17238c2ecf20Sopenharmony_ci	struct mutex		mutex;
17248c2ecf20Sopenharmony_ci	struct ib_ports_pkeys  *ports_pkeys;
17258c2ecf20Sopenharmony_ci	/* A list of all open shared QP handles.  Required to enforce security
17268c2ecf20Sopenharmony_ci	 * properly for all users of a shared QP.
17278c2ecf20Sopenharmony_ci	 */
17288c2ecf20Sopenharmony_ci	struct list_head        shared_qp_list;
17298c2ecf20Sopenharmony_ci	void                   *security;
17308c2ecf20Sopenharmony_ci	bool			destroying;
17318c2ecf20Sopenharmony_ci	atomic_t		error_list_count;
17328c2ecf20Sopenharmony_ci	struct completion	error_complete;
17338c2ecf20Sopenharmony_ci	int			error_comps_pending;
17348c2ecf20Sopenharmony_ci};
17358c2ecf20Sopenharmony_ci
17368c2ecf20Sopenharmony_ci/*
17378c2ecf20Sopenharmony_ci * @max_write_sge: Maximum SGE elements per RDMA WRITE request.
17388c2ecf20Sopenharmony_ci * @max_read_sge:  Maximum SGE elements per RDMA READ request.
17398c2ecf20Sopenharmony_ci */
17408c2ecf20Sopenharmony_cistruct ib_qp {
17418c2ecf20Sopenharmony_ci	struct ib_device       *device;
17428c2ecf20Sopenharmony_ci	struct ib_pd	       *pd;
17438c2ecf20Sopenharmony_ci	struct ib_cq	       *send_cq;
17448c2ecf20Sopenharmony_ci	struct ib_cq	       *recv_cq;
17458c2ecf20Sopenharmony_ci	spinlock_t		mr_lock;
17468c2ecf20Sopenharmony_ci	int			mrs_used;
17478c2ecf20Sopenharmony_ci	struct list_head	rdma_mrs;
17488c2ecf20Sopenharmony_ci	struct list_head	sig_mrs;
17498c2ecf20Sopenharmony_ci	struct ib_srq	       *srq;
17508c2ecf20Sopenharmony_ci	struct ib_xrcd	       *xrcd; /* XRC TGT QPs only */
17518c2ecf20Sopenharmony_ci	struct list_head	xrcd_list;
17528c2ecf20Sopenharmony_ci
17538c2ecf20Sopenharmony_ci	/* count times opened, mcast attaches, flow attaches */
17548c2ecf20Sopenharmony_ci	atomic_t		usecnt;
17558c2ecf20Sopenharmony_ci	struct list_head	open_list;
17568c2ecf20Sopenharmony_ci	struct ib_qp           *real_qp;
17578c2ecf20Sopenharmony_ci	struct ib_uqp_object   *uobject;
17588c2ecf20Sopenharmony_ci	void                  (*event_handler)(struct ib_event *, void *);
17598c2ecf20Sopenharmony_ci	void		       *qp_context;
17608c2ecf20Sopenharmony_ci	/* sgid_attrs associated with the AV's */
17618c2ecf20Sopenharmony_ci	const struct ib_gid_attr *av_sgid_attr;
17628c2ecf20Sopenharmony_ci	const struct ib_gid_attr *alt_path_sgid_attr;
17638c2ecf20Sopenharmony_ci	u32			qp_num;
17648c2ecf20Sopenharmony_ci	u32			max_write_sge;
17658c2ecf20Sopenharmony_ci	u32			max_read_sge;
17668c2ecf20Sopenharmony_ci	enum ib_qp_type		qp_type;
17678c2ecf20Sopenharmony_ci	struct ib_rwq_ind_table *rwq_ind_tbl;
17688c2ecf20Sopenharmony_ci	struct ib_qp_security  *qp_sec;
17698c2ecf20Sopenharmony_ci	u8			port;
17708c2ecf20Sopenharmony_ci
17718c2ecf20Sopenharmony_ci	bool			integrity_en;
17728c2ecf20Sopenharmony_ci	/*
17738c2ecf20Sopenharmony_ci	 * Implementation details of the RDMA core, don't use in drivers:
17748c2ecf20Sopenharmony_ci	 */
17758c2ecf20Sopenharmony_ci	struct rdma_restrack_entry     res;
17768c2ecf20Sopenharmony_ci
17778c2ecf20Sopenharmony_ci	/* The counter the qp is bind to */
17788c2ecf20Sopenharmony_ci	struct rdma_counter    *counter;
17798c2ecf20Sopenharmony_ci};
17808c2ecf20Sopenharmony_ci
17818c2ecf20Sopenharmony_cistruct ib_dm {
17828c2ecf20Sopenharmony_ci	struct ib_device  *device;
17838c2ecf20Sopenharmony_ci	u32		   length;
17848c2ecf20Sopenharmony_ci	u32		   flags;
17858c2ecf20Sopenharmony_ci	struct ib_uobject *uobject;
17868c2ecf20Sopenharmony_ci	atomic_t	   usecnt;
17878c2ecf20Sopenharmony_ci};
17888c2ecf20Sopenharmony_ci
17898c2ecf20Sopenharmony_cistruct ib_mr {
17908c2ecf20Sopenharmony_ci	struct ib_device  *device;
17918c2ecf20Sopenharmony_ci	struct ib_pd	  *pd;
17928c2ecf20Sopenharmony_ci	u32		   lkey;
17938c2ecf20Sopenharmony_ci	u32		   rkey;
17948c2ecf20Sopenharmony_ci	u64		   iova;
17958c2ecf20Sopenharmony_ci	u64		   length;
17968c2ecf20Sopenharmony_ci	unsigned int	   page_size;
17978c2ecf20Sopenharmony_ci	enum ib_mr_type	   type;
17988c2ecf20Sopenharmony_ci	bool		   need_inval;
17998c2ecf20Sopenharmony_ci	union {
18008c2ecf20Sopenharmony_ci		struct ib_uobject	*uobject;	/* user */
18018c2ecf20Sopenharmony_ci		struct list_head	qp_entry;	/* FR */
18028c2ecf20Sopenharmony_ci	};
18038c2ecf20Sopenharmony_ci
18048c2ecf20Sopenharmony_ci	struct ib_dm      *dm;
18058c2ecf20Sopenharmony_ci	struct ib_sig_attrs *sig_attrs; /* only for IB_MR_TYPE_INTEGRITY MRs */
18068c2ecf20Sopenharmony_ci	/*
18078c2ecf20Sopenharmony_ci	 * Implementation details of the RDMA core, don't use in drivers:
18088c2ecf20Sopenharmony_ci	 */
18098c2ecf20Sopenharmony_ci	struct rdma_restrack_entry res;
18108c2ecf20Sopenharmony_ci};
18118c2ecf20Sopenharmony_ci
18128c2ecf20Sopenharmony_cistruct ib_mw {
18138c2ecf20Sopenharmony_ci	struct ib_device	*device;
18148c2ecf20Sopenharmony_ci	struct ib_pd		*pd;
18158c2ecf20Sopenharmony_ci	struct ib_uobject	*uobject;
18168c2ecf20Sopenharmony_ci	u32			rkey;
18178c2ecf20Sopenharmony_ci	enum ib_mw_type         type;
18188c2ecf20Sopenharmony_ci};
18198c2ecf20Sopenharmony_ci
18208c2ecf20Sopenharmony_ci/* Supported steering options */
18218c2ecf20Sopenharmony_cienum ib_flow_attr_type {
18228c2ecf20Sopenharmony_ci	/* steering according to rule specifications */
18238c2ecf20Sopenharmony_ci	IB_FLOW_ATTR_NORMAL		= 0x0,
18248c2ecf20Sopenharmony_ci	/* default unicast and multicast rule -
18258c2ecf20Sopenharmony_ci	 * receive all Eth traffic which isn't steered to any QP
18268c2ecf20Sopenharmony_ci	 */
18278c2ecf20Sopenharmony_ci	IB_FLOW_ATTR_ALL_DEFAULT	= 0x1,
18288c2ecf20Sopenharmony_ci	/* default multicast rule -
18298c2ecf20Sopenharmony_ci	 * receive all Eth multicast traffic which isn't steered to any QP
18308c2ecf20Sopenharmony_ci	 */
18318c2ecf20Sopenharmony_ci	IB_FLOW_ATTR_MC_DEFAULT		= 0x2,
18328c2ecf20Sopenharmony_ci	/* sniffer rule - receive all port traffic */
18338c2ecf20Sopenharmony_ci	IB_FLOW_ATTR_SNIFFER		= 0x3
18348c2ecf20Sopenharmony_ci};
18358c2ecf20Sopenharmony_ci
18368c2ecf20Sopenharmony_ci/* Supported steering header types */
18378c2ecf20Sopenharmony_cienum ib_flow_spec_type {
18388c2ecf20Sopenharmony_ci	/* L2 headers*/
18398c2ecf20Sopenharmony_ci	IB_FLOW_SPEC_ETH		= 0x20,
18408c2ecf20Sopenharmony_ci	IB_FLOW_SPEC_IB			= 0x22,
18418c2ecf20Sopenharmony_ci	/* L3 header*/
18428c2ecf20Sopenharmony_ci	IB_FLOW_SPEC_IPV4		= 0x30,
18438c2ecf20Sopenharmony_ci	IB_FLOW_SPEC_IPV6		= 0x31,
18448c2ecf20Sopenharmony_ci	IB_FLOW_SPEC_ESP                = 0x34,
18458c2ecf20Sopenharmony_ci	/* L4 headers*/
18468c2ecf20Sopenharmony_ci	IB_FLOW_SPEC_TCP		= 0x40,
18478c2ecf20Sopenharmony_ci	IB_FLOW_SPEC_UDP		= 0x41,
18488c2ecf20Sopenharmony_ci	IB_FLOW_SPEC_VXLAN_TUNNEL	= 0x50,
18498c2ecf20Sopenharmony_ci	IB_FLOW_SPEC_GRE		= 0x51,
18508c2ecf20Sopenharmony_ci	IB_FLOW_SPEC_MPLS		= 0x60,
18518c2ecf20Sopenharmony_ci	IB_FLOW_SPEC_INNER		= 0x100,
18528c2ecf20Sopenharmony_ci	/* Actions */
18538c2ecf20Sopenharmony_ci	IB_FLOW_SPEC_ACTION_TAG         = 0x1000,
18548c2ecf20Sopenharmony_ci	IB_FLOW_SPEC_ACTION_DROP        = 0x1001,
18558c2ecf20Sopenharmony_ci	IB_FLOW_SPEC_ACTION_HANDLE	= 0x1002,
18568c2ecf20Sopenharmony_ci	IB_FLOW_SPEC_ACTION_COUNT       = 0x1003,
18578c2ecf20Sopenharmony_ci};
18588c2ecf20Sopenharmony_ci#define IB_FLOW_SPEC_LAYER_MASK	0xF0
18598c2ecf20Sopenharmony_ci#define IB_FLOW_SPEC_SUPPORT_LAYERS 10
18608c2ecf20Sopenharmony_ci
18618c2ecf20Sopenharmony_cienum ib_flow_flags {
18628c2ecf20Sopenharmony_ci	IB_FLOW_ATTR_FLAGS_DONT_TRAP = 1UL << 1, /* Continue match, no steal */
18638c2ecf20Sopenharmony_ci	IB_FLOW_ATTR_FLAGS_EGRESS = 1UL << 2, /* Egress flow */
18648c2ecf20Sopenharmony_ci	IB_FLOW_ATTR_FLAGS_RESERVED  = 1UL << 3  /* Must be last */
18658c2ecf20Sopenharmony_ci};
18668c2ecf20Sopenharmony_ci
18678c2ecf20Sopenharmony_cistruct ib_flow_eth_filter {
18688c2ecf20Sopenharmony_ci	u8	dst_mac[6];
18698c2ecf20Sopenharmony_ci	u8	src_mac[6];
18708c2ecf20Sopenharmony_ci	__be16	ether_type;
18718c2ecf20Sopenharmony_ci	__be16	vlan_tag;
18728c2ecf20Sopenharmony_ci	/* Must be last */
18738c2ecf20Sopenharmony_ci	u8	real_sz[];
18748c2ecf20Sopenharmony_ci};
18758c2ecf20Sopenharmony_ci
18768c2ecf20Sopenharmony_cistruct ib_flow_spec_eth {
18778c2ecf20Sopenharmony_ci	u32			  type;
18788c2ecf20Sopenharmony_ci	u16			  size;
18798c2ecf20Sopenharmony_ci	struct ib_flow_eth_filter val;
18808c2ecf20Sopenharmony_ci	struct ib_flow_eth_filter mask;
18818c2ecf20Sopenharmony_ci};
18828c2ecf20Sopenharmony_ci
18838c2ecf20Sopenharmony_cistruct ib_flow_ib_filter {
18848c2ecf20Sopenharmony_ci	__be16 dlid;
18858c2ecf20Sopenharmony_ci	__u8   sl;
18868c2ecf20Sopenharmony_ci	/* Must be last */
18878c2ecf20Sopenharmony_ci	u8	real_sz[];
18888c2ecf20Sopenharmony_ci};
18898c2ecf20Sopenharmony_ci
18908c2ecf20Sopenharmony_cistruct ib_flow_spec_ib {
18918c2ecf20Sopenharmony_ci	u32			 type;
18928c2ecf20Sopenharmony_ci	u16			 size;
18938c2ecf20Sopenharmony_ci	struct ib_flow_ib_filter val;
18948c2ecf20Sopenharmony_ci	struct ib_flow_ib_filter mask;
18958c2ecf20Sopenharmony_ci};
18968c2ecf20Sopenharmony_ci
18978c2ecf20Sopenharmony_ci/* IPv4 header flags */
18988c2ecf20Sopenharmony_cienum ib_ipv4_flags {
18998c2ecf20Sopenharmony_ci	IB_IPV4_DONT_FRAG = 0x2, /* Don't enable packet fragmentation */
19008c2ecf20Sopenharmony_ci	IB_IPV4_MORE_FRAG = 0X4  /* For All fragmented packets except the
19018c2ecf20Sopenharmony_ci				    last have this flag set */
19028c2ecf20Sopenharmony_ci};
19038c2ecf20Sopenharmony_ci
19048c2ecf20Sopenharmony_cistruct ib_flow_ipv4_filter {
19058c2ecf20Sopenharmony_ci	__be32	src_ip;
19068c2ecf20Sopenharmony_ci	__be32	dst_ip;
19078c2ecf20Sopenharmony_ci	u8	proto;
19088c2ecf20Sopenharmony_ci	u8	tos;
19098c2ecf20Sopenharmony_ci	u8	ttl;
19108c2ecf20Sopenharmony_ci	u8	flags;
19118c2ecf20Sopenharmony_ci	/* Must be last */
19128c2ecf20Sopenharmony_ci	u8	real_sz[];
19138c2ecf20Sopenharmony_ci};
19148c2ecf20Sopenharmony_ci
19158c2ecf20Sopenharmony_cistruct ib_flow_spec_ipv4 {
19168c2ecf20Sopenharmony_ci	u32			   type;
19178c2ecf20Sopenharmony_ci	u16			   size;
19188c2ecf20Sopenharmony_ci	struct ib_flow_ipv4_filter val;
19198c2ecf20Sopenharmony_ci	struct ib_flow_ipv4_filter mask;
19208c2ecf20Sopenharmony_ci};
19218c2ecf20Sopenharmony_ci
19228c2ecf20Sopenharmony_cistruct ib_flow_ipv6_filter {
19238c2ecf20Sopenharmony_ci	u8	src_ip[16];
19248c2ecf20Sopenharmony_ci	u8	dst_ip[16];
19258c2ecf20Sopenharmony_ci	__be32	flow_label;
19268c2ecf20Sopenharmony_ci	u8	next_hdr;
19278c2ecf20Sopenharmony_ci	u8	traffic_class;
19288c2ecf20Sopenharmony_ci	u8	hop_limit;
19298c2ecf20Sopenharmony_ci	/* Must be last */
19308c2ecf20Sopenharmony_ci	u8	real_sz[];
19318c2ecf20Sopenharmony_ci};
19328c2ecf20Sopenharmony_ci
19338c2ecf20Sopenharmony_cistruct ib_flow_spec_ipv6 {
19348c2ecf20Sopenharmony_ci	u32			   type;
19358c2ecf20Sopenharmony_ci	u16			   size;
19368c2ecf20Sopenharmony_ci	struct ib_flow_ipv6_filter val;
19378c2ecf20Sopenharmony_ci	struct ib_flow_ipv6_filter mask;
19388c2ecf20Sopenharmony_ci};
19398c2ecf20Sopenharmony_ci
19408c2ecf20Sopenharmony_cistruct ib_flow_tcp_udp_filter {
19418c2ecf20Sopenharmony_ci	__be16	dst_port;
19428c2ecf20Sopenharmony_ci	__be16	src_port;
19438c2ecf20Sopenharmony_ci	/* Must be last */
19448c2ecf20Sopenharmony_ci	u8	real_sz[];
19458c2ecf20Sopenharmony_ci};
19468c2ecf20Sopenharmony_ci
19478c2ecf20Sopenharmony_cistruct ib_flow_spec_tcp_udp {
19488c2ecf20Sopenharmony_ci	u32			      type;
19498c2ecf20Sopenharmony_ci	u16			      size;
19508c2ecf20Sopenharmony_ci	struct ib_flow_tcp_udp_filter val;
19518c2ecf20Sopenharmony_ci	struct ib_flow_tcp_udp_filter mask;
19528c2ecf20Sopenharmony_ci};
19538c2ecf20Sopenharmony_ci
19548c2ecf20Sopenharmony_cistruct ib_flow_tunnel_filter {
19558c2ecf20Sopenharmony_ci	__be32	tunnel_id;
19568c2ecf20Sopenharmony_ci	u8	real_sz[];
19578c2ecf20Sopenharmony_ci};
19588c2ecf20Sopenharmony_ci
19598c2ecf20Sopenharmony_ci/* ib_flow_spec_tunnel describes the Vxlan tunnel
19608c2ecf20Sopenharmony_ci * the tunnel_id from val has the vni value
19618c2ecf20Sopenharmony_ci */
19628c2ecf20Sopenharmony_cistruct ib_flow_spec_tunnel {
19638c2ecf20Sopenharmony_ci	u32			      type;
19648c2ecf20Sopenharmony_ci	u16			      size;
19658c2ecf20Sopenharmony_ci	struct ib_flow_tunnel_filter  val;
19668c2ecf20Sopenharmony_ci	struct ib_flow_tunnel_filter  mask;
19678c2ecf20Sopenharmony_ci};
19688c2ecf20Sopenharmony_ci
19698c2ecf20Sopenharmony_cistruct ib_flow_esp_filter {
19708c2ecf20Sopenharmony_ci	__be32	spi;
19718c2ecf20Sopenharmony_ci	__be32  seq;
19728c2ecf20Sopenharmony_ci	/* Must be last */
19738c2ecf20Sopenharmony_ci	u8	real_sz[];
19748c2ecf20Sopenharmony_ci};
19758c2ecf20Sopenharmony_ci
19768c2ecf20Sopenharmony_cistruct ib_flow_spec_esp {
19778c2ecf20Sopenharmony_ci	u32                           type;
19788c2ecf20Sopenharmony_ci	u16			      size;
19798c2ecf20Sopenharmony_ci	struct ib_flow_esp_filter     val;
19808c2ecf20Sopenharmony_ci	struct ib_flow_esp_filter     mask;
19818c2ecf20Sopenharmony_ci};
19828c2ecf20Sopenharmony_ci
19838c2ecf20Sopenharmony_cistruct ib_flow_gre_filter {
19848c2ecf20Sopenharmony_ci	__be16 c_ks_res0_ver;
19858c2ecf20Sopenharmony_ci	__be16 protocol;
19868c2ecf20Sopenharmony_ci	__be32 key;
19878c2ecf20Sopenharmony_ci	/* Must be last */
19888c2ecf20Sopenharmony_ci	u8	real_sz[];
19898c2ecf20Sopenharmony_ci};
19908c2ecf20Sopenharmony_ci
19918c2ecf20Sopenharmony_cistruct ib_flow_spec_gre {
19928c2ecf20Sopenharmony_ci	u32                           type;
19938c2ecf20Sopenharmony_ci	u16			      size;
19948c2ecf20Sopenharmony_ci	struct ib_flow_gre_filter     val;
19958c2ecf20Sopenharmony_ci	struct ib_flow_gre_filter     mask;
19968c2ecf20Sopenharmony_ci};
19978c2ecf20Sopenharmony_ci
19988c2ecf20Sopenharmony_cistruct ib_flow_mpls_filter {
19998c2ecf20Sopenharmony_ci	__be32 tag;
20008c2ecf20Sopenharmony_ci	/* Must be last */
20018c2ecf20Sopenharmony_ci	u8	real_sz[];
20028c2ecf20Sopenharmony_ci};
20038c2ecf20Sopenharmony_ci
20048c2ecf20Sopenharmony_cistruct ib_flow_spec_mpls {
20058c2ecf20Sopenharmony_ci	u32                           type;
20068c2ecf20Sopenharmony_ci	u16			      size;
20078c2ecf20Sopenharmony_ci	struct ib_flow_mpls_filter     val;
20088c2ecf20Sopenharmony_ci	struct ib_flow_mpls_filter     mask;
20098c2ecf20Sopenharmony_ci};
20108c2ecf20Sopenharmony_ci
20118c2ecf20Sopenharmony_cistruct ib_flow_spec_action_tag {
20128c2ecf20Sopenharmony_ci	enum ib_flow_spec_type	      type;
20138c2ecf20Sopenharmony_ci	u16			      size;
20148c2ecf20Sopenharmony_ci	u32                           tag_id;
20158c2ecf20Sopenharmony_ci};
20168c2ecf20Sopenharmony_ci
20178c2ecf20Sopenharmony_cistruct ib_flow_spec_action_drop {
20188c2ecf20Sopenharmony_ci	enum ib_flow_spec_type	      type;
20198c2ecf20Sopenharmony_ci	u16			      size;
20208c2ecf20Sopenharmony_ci};
20218c2ecf20Sopenharmony_ci
20228c2ecf20Sopenharmony_cistruct ib_flow_spec_action_handle {
20238c2ecf20Sopenharmony_ci	enum ib_flow_spec_type	      type;
20248c2ecf20Sopenharmony_ci	u16			      size;
20258c2ecf20Sopenharmony_ci	struct ib_flow_action	     *act;
20268c2ecf20Sopenharmony_ci};
20278c2ecf20Sopenharmony_ci
20288c2ecf20Sopenharmony_cienum ib_counters_description {
20298c2ecf20Sopenharmony_ci	IB_COUNTER_PACKETS,
20308c2ecf20Sopenharmony_ci	IB_COUNTER_BYTES,
20318c2ecf20Sopenharmony_ci};
20328c2ecf20Sopenharmony_ci
20338c2ecf20Sopenharmony_cistruct ib_flow_spec_action_count {
20348c2ecf20Sopenharmony_ci	enum ib_flow_spec_type type;
20358c2ecf20Sopenharmony_ci	u16 size;
20368c2ecf20Sopenharmony_ci	struct ib_counters *counters;
20378c2ecf20Sopenharmony_ci};
20388c2ecf20Sopenharmony_ci
20398c2ecf20Sopenharmony_ciunion ib_flow_spec {
20408c2ecf20Sopenharmony_ci	struct {
20418c2ecf20Sopenharmony_ci		u32			type;
20428c2ecf20Sopenharmony_ci		u16			size;
20438c2ecf20Sopenharmony_ci	};
20448c2ecf20Sopenharmony_ci	struct ib_flow_spec_eth		eth;
20458c2ecf20Sopenharmony_ci	struct ib_flow_spec_ib		ib;
20468c2ecf20Sopenharmony_ci	struct ib_flow_spec_ipv4        ipv4;
20478c2ecf20Sopenharmony_ci	struct ib_flow_spec_tcp_udp	tcp_udp;
20488c2ecf20Sopenharmony_ci	struct ib_flow_spec_ipv6        ipv6;
20498c2ecf20Sopenharmony_ci	struct ib_flow_spec_tunnel      tunnel;
20508c2ecf20Sopenharmony_ci	struct ib_flow_spec_esp		esp;
20518c2ecf20Sopenharmony_ci	struct ib_flow_spec_gre		gre;
20528c2ecf20Sopenharmony_ci	struct ib_flow_spec_mpls	mpls;
20538c2ecf20Sopenharmony_ci	struct ib_flow_spec_action_tag  flow_tag;
20548c2ecf20Sopenharmony_ci	struct ib_flow_spec_action_drop drop;
20558c2ecf20Sopenharmony_ci	struct ib_flow_spec_action_handle action;
20568c2ecf20Sopenharmony_ci	struct ib_flow_spec_action_count flow_count;
20578c2ecf20Sopenharmony_ci};
20588c2ecf20Sopenharmony_ci
20598c2ecf20Sopenharmony_cistruct ib_flow_attr {
20608c2ecf20Sopenharmony_ci	enum ib_flow_attr_type type;
20618c2ecf20Sopenharmony_ci	u16	     size;
20628c2ecf20Sopenharmony_ci	u16	     priority;
20638c2ecf20Sopenharmony_ci	u32	     flags;
20648c2ecf20Sopenharmony_ci	u8	     num_of_specs;
20658c2ecf20Sopenharmony_ci	u8	     port;
20668c2ecf20Sopenharmony_ci	union ib_flow_spec flows[];
20678c2ecf20Sopenharmony_ci};
20688c2ecf20Sopenharmony_ci
20698c2ecf20Sopenharmony_cistruct ib_flow {
20708c2ecf20Sopenharmony_ci	struct ib_qp		*qp;
20718c2ecf20Sopenharmony_ci	struct ib_device	*device;
20728c2ecf20Sopenharmony_ci	struct ib_uobject	*uobject;
20738c2ecf20Sopenharmony_ci};
20748c2ecf20Sopenharmony_ci
20758c2ecf20Sopenharmony_cienum ib_flow_action_type {
20768c2ecf20Sopenharmony_ci	IB_FLOW_ACTION_UNSPECIFIED,
20778c2ecf20Sopenharmony_ci	IB_FLOW_ACTION_ESP = 1,
20788c2ecf20Sopenharmony_ci};
20798c2ecf20Sopenharmony_ci
20808c2ecf20Sopenharmony_cistruct ib_flow_action_attrs_esp_keymats {
20818c2ecf20Sopenharmony_ci	enum ib_uverbs_flow_action_esp_keymat			protocol;
20828c2ecf20Sopenharmony_ci	union {
20838c2ecf20Sopenharmony_ci		struct ib_uverbs_flow_action_esp_keymat_aes_gcm aes_gcm;
20848c2ecf20Sopenharmony_ci	} keymat;
20858c2ecf20Sopenharmony_ci};
20868c2ecf20Sopenharmony_ci
20878c2ecf20Sopenharmony_cistruct ib_flow_action_attrs_esp_replays {
20888c2ecf20Sopenharmony_ci	enum ib_uverbs_flow_action_esp_replay			protocol;
20898c2ecf20Sopenharmony_ci	union {
20908c2ecf20Sopenharmony_ci		struct ib_uverbs_flow_action_esp_replay_bmp	bmp;
20918c2ecf20Sopenharmony_ci	} replay;
20928c2ecf20Sopenharmony_ci};
20938c2ecf20Sopenharmony_ci
20948c2ecf20Sopenharmony_cienum ib_flow_action_attrs_esp_flags {
20958c2ecf20Sopenharmony_ci	/* All user-space flags at the top: Use enum ib_uverbs_flow_action_esp_flags
20968c2ecf20Sopenharmony_ci	 * This is done in order to share the same flags between user-space and
20978c2ecf20Sopenharmony_ci	 * kernel and spare an unnecessary translation.
20988c2ecf20Sopenharmony_ci	 */
20998c2ecf20Sopenharmony_ci
21008c2ecf20Sopenharmony_ci	/* Kernel flags */
21018c2ecf20Sopenharmony_ci	IB_FLOW_ACTION_ESP_FLAGS_ESN_TRIGGERED	= 1ULL << 32,
21028c2ecf20Sopenharmony_ci	IB_FLOW_ACTION_ESP_FLAGS_MOD_ESP_ATTRS	= 1ULL << 33,
21038c2ecf20Sopenharmony_ci};
21048c2ecf20Sopenharmony_ci
21058c2ecf20Sopenharmony_cistruct ib_flow_spec_list {
21068c2ecf20Sopenharmony_ci	struct ib_flow_spec_list	*next;
21078c2ecf20Sopenharmony_ci	union ib_flow_spec		spec;
21088c2ecf20Sopenharmony_ci};
21098c2ecf20Sopenharmony_ci
21108c2ecf20Sopenharmony_cistruct ib_flow_action_attrs_esp {
21118c2ecf20Sopenharmony_ci	struct ib_flow_action_attrs_esp_keymats		*keymat;
21128c2ecf20Sopenharmony_ci	struct ib_flow_action_attrs_esp_replays		*replay;
21138c2ecf20Sopenharmony_ci	struct ib_flow_spec_list			*encap;
21148c2ecf20Sopenharmony_ci	/* Used only if IB_FLOW_ACTION_ESP_FLAGS_ESN_TRIGGERED is enabled.
21158c2ecf20Sopenharmony_ci	 * Value of 0 is a valid value.
21168c2ecf20Sopenharmony_ci	 */
21178c2ecf20Sopenharmony_ci	u32						esn;
21188c2ecf20Sopenharmony_ci	u32						spi;
21198c2ecf20Sopenharmony_ci	u32						seq;
21208c2ecf20Sopenharmony_ci	u32						tfc_pad;
21218c2ecf20Sopenharmony_ci	/* Use enum ib_flow_action_attrs_esp_flags */
21228c2ecf20Sopenharmony_ci	u64						flags;
21238c2ecf20Sopenharmony_ci	u64						hard_limit_pkts;
21248c2ecf20Sopenharmony_ci};
21258c2ecf20Sopenharmony_ci
21268c2ecf20Sopenharmony_cistruct ib_flow_action {
21278c2ecf20Sopenharmony_ci	struct ib_device		*device;
21288c2ecf20Sopenharmony_ci	struct ib_uobject		*uobject;
21298c2ecf20Sopenharmony_ci	enum ib_flow_action_type	type;
21308c2ecf20Sopenharmony_ci	atomic_t			usecnt;
21318c2ecf20Sopenharmony_ci};
21328c2ecf20Sopenharmony_ci
21338c2ecf20Sopenharmony_cistruct ib_mad;
21348c2ecf20Sopenharmony_cistruct ib_grh;
21358c2ecf20Sopenharmony_ci
21368c2ecf20Sopenharmony_cienum ib_process_mad_flags {
21378c2ecf20Sopenharmony_ci	IB_MAD_IGNORE_MKEY	= 1,
21388c2ecf20Sopenharmony_ci	IB_MAD_IGNORE_BKEY	= 2,
21398c2ecf20Sopenharmony_ci	IB_MAD_IGNORE_ALL	= IB_MAD_IGNORE_MKEY | IB_MAD_IGNORE_BKEY
21408c2ecf20Sopenharmony_ci};
21418c2ecf20Sopenharmony_ci
21428c2ecf20Sopenharmony_cienum ib_mad_result {
21438c2ecf20Sopenharmony_ci	IB_MAD_RESULT_FAILURE  = 0,      /* (!SUCCESS is the important flag) */
21448c2ecf20Sopenharmony_ci	IB_MAD_RESULT_SUCCESS  = 1 << 0, /* MAD was successfully processed   */
21458c2ecf20Sopenharmony_ci	IB_MAD_RESULT_REPLY    = 1 << 1, /* Reply packet needs to be sent    */
21468c2ecf20Sopenharmony_ci	IB_MAD_RESULT_CONSUMED = 1 << 2  /* Packet consumed: stop processing */
21478c2ecf20Sopenharmony_ci};
21488c2ecf20Sopenharmony_ci
21498c2ecf20Sopenharmony_cistruct ib_port_cache {
21508c2ecf20Sopenharmony_ci	u64		      subnet_prefix;
21518c2ecf20Sopenharmony_ci	struct ib_pkey_cache  *pkey;
21528c2ecf20Sopenharmony_ci	struct ib_gid_table   *gid;
21538c2ecf20Sopenharmony_ci	u8                     lmc;
21548c2ecf20Sopenharmony_ci	enum ib_port_state     port_state;
21558c2ecf20Sopenharmony_ci};
21568c2ecf20Sopenharmony_ci
21578c2ecf20Sopenharmony_cistruct ib_port_immutable {
21588c2ecf20Sopenharmony_ci	int                           pkey_tbl_len;
21598c2ecf20Sopenharmony_ci	int                           gid_tbl_len;
21608c2ecf20Sopenharmony_ci	u32                           core_cap_flags;
21618c2ecf20Sopenharmony_ci	u32                           max_mad_size;
21628c2ecf20Sopenharmony_ci};
21638c2ecf20Sopenharmony_ci
21648c2ecf20Sopenharmony_cistruct ib_port_data {
21658c2ecf20Sopenharmony_ci	struct ib_device *ib_dev;
21668c2ecf20Sopenharmony_ci
21678c2ecf20Sopenharmony_ci	struct ib_port_immutable immutable;
21688c2ecf20Sopenharmony_ci
21698c2ecf20Sopenharmony_ci	spinlock_t pkey_list_lock;
21708c2ecf20Sopenharmony_ci	struct list_head pkey_list;
21718c2ecf20Sopenharmony_ci
21728c2ecf20Sopenharmony_ci	struct ib_port_cache cache;
21738c2ecf20Sopenharmony_ci
21748c2ecf20Sopenharmony_ci	spinlock_t netdev_lock;
21758c2ecf20Sopenharmony_ci	struct net_device __rcu *netdev;
21768c2ecf20Sopenharmony_ci	struct hlist_node ndev_hash_link;
21778c2ecf20Sopenharmony_ci	struct rdma_port_counter port_counter;
21788c2ecf20Sopenharmony_ci	struct rdma_hw_stats *hw_stats;
21798c2ecf20Sopenharmony_ci};
21808c2ecf20Sopenharmony_ci
21818c2ecf20Sopenharmony_ci/* rdma netdev type - specifies protocol type */
21828c2ecf20Sopenharmony_cienum rdma_netdev_t {
21838c2ecf20Sopenharmony_ci	RDMA_NETDEV_OPA_VNIC,
21848c2ecf20Sopenharmony_ci	RDMA_NETDEV_IPOIB,
21858c2ecf20Sopenharmony_ci};
21868c2ecf20Sopenharmony_ci
21878c2ecf20Sopenharmony_ci/**
21888c2ecf20Sopenharmony_ci * struct rdma_netdev - rdma netdev
21898c2ecf20Sopenharmony_ci * For cases where netstack interfacing is required.
21908c2ecf20Sopenharmony_ci */
21918c2ecf20Sopenharmony_cistruct rdma_netdev {
21928c2ecf20Sopenharmony_ci	void              *clnt_priv;
21938c2ecf20Sopenharmony_ci	struct ib_device  *hca;
21948c2ecf20Sopenharmony_ci	u8                 port_num;
21958c2ecf20Sopenharmony_ci	int                mtu;
21968c2ecf20Sopenharmony_ci
21978c2ecf20Sopenharmony_ci	/*
21988c2ecf20Sopenharmony_ci	 * cleanup function must be specified.
21998c2ecf20Sopenharmony_ci	 * FIXME: This is only used for OPA_VNIC and that usage should be
22008c2ecf20Sopenharmony_ci	 * removed too.
22018c2ecf20Sopenharmony_ci	 */
22028c2ecf20Sopenharmony_ci	void (*free_rdma_netdev)(struct net_device *netdev);
22038c2ecf20Sopenharmony_ci
22048c2ecf20Sopenharmony_ci	/* control functions */
22058c2ecf20Sopenharmony_ci	void (*set_id)(struct net_device *netdev, int id);
22068c2ecf20Sopenharmony_ci	/* send packet */
22078c2ecf20Sopenharmony_ci	int (*send)(struct net_device *dev, struct sk_buff *skb,
22088c2ecf20Sopenharmony_ci		    struct ib_ah *address, u32 dqpn);
22098c2ecf20Sopenharmony_ci	/* multicast */
22108c2ecf20Sopenharmony_ci	int (*attach_mcast)(struct net_device *dev, struct ib_device *hca,
22118c2ecf20Sopenharmony_ci			    union ib_gid *gid, u16 mlid,
22128c2ecf20Sopenharmony_ci			    int set_qkey, u32 qkey);
22138c2ecf20Sopenharmony_ci	int (*detach_mcast)(struct net_device *dev, struct ib_device *hca,
22148c2ecf20Sopenharmony_ci			    union ib_gid *gid, u16 mlid);
22158c2ecf20Sopenharmony_ci};
22168c2ecf20Sopenharmony_ci
22178c2ecf20Sopenharmony_cistruct rdma_netdev_alloc_params {
22188c2ecf20Sopenharmony_ci	size_t sizeof_priv;
22198c2ecf20Sopenharmony_ci	unsigned int txqs;
22208c2ecf20Sopenharmony_ci	unsigned int rxqs;
22218c2ecf20Sopenharmony_ci	void *param;
22228c2ecf20Sopenharmony_ci
22238c2ecf20Sopenharmony_ci	int (*initialize_rdma_netdev)(struct ib_device *device, u8 port_num,
22248c2ecf20Sopenharmony_ci				      struct net_device *netdev, void *param);
22258c2ecf20Sopenharmony_ci};
22268c2ecf20Sopenharmony_ci
22278c2ecf20Sopenharmony_cistruct ib_odp_counters {
22288c2ecf20Sopenharmony_ci	atomic64_t faults;
22298c2ecf20Sopenharmony_ci	atomic64_t invalidations;
22308c2ecf20Sopenharmony_ci	atomic64_t prefetch;
22318c2ecf20Sopenharmony_ci};
22328c2ecf20Sopenharmony_ci
22338c2ecf20Sopenharmony_cistruct ib_counters {
22348c2ecf20Sopenharmony_ci	struct ib_device	*device;
22358c2ecf20Sopenharmony_ci	struct ib_uobject	*uobject;
22368c2ecf20Sopenharmony_ci	/* num of objects attached */
22378c2ecf20Sopenharmony_ci	atomic_t	usecnt;
22388c2ecf20Sopenharmony_ci};
22398c2ecf20Sopenharmony_ci
22408c2ecf20Sopenharmony_cistruct ib_counters_read_attr {
22418c2ecf20Sopenharmony_ci	u64	*counters_buff;
22428c2ecf20Sopenharmony_ci	u32	ncounters;
22438c2ecf20Sopenharmony_ci	u32	flags; /* use enum ib_read_counters_flags */
22448c2ecf20Sopenharmony_ci};
22458c2ecf20Sopenharmony_ci
22468c2ecf20Sopenharmony_cistruct uverbs_attr_bundle;
22478c2ecf20Sopenharmony_cistruct iw_cm_id;
22488c2ecf20Sopenharmony_cistruct iw_cm_conn_param;
22498c2ecf20Sopenharmony_ci
22508c2ecf20Sopenharmony_ci#define INIT_RDMA_OBJ_SIZE(ib_struct, drv_struct, member)                      \
22518c2ecf20Sopenharmony_ci	.size_##ib_struct =                                                    \
22528c2ecf20Sopenharmony_ci		(sizeof(struct drv_struct) +                                   \
22538c2ecf20Sopenharmony_ci		 BUILD_BUG_ON_ZERO(offsetof(struct drv_struct, member)) +      \
22548c2ecf20Sopenharmony_ci		 BUILD_BUG_ON_ZERO(                                            \
22558c2ecf20Sopenharmony_ci			 !__same_type(((struct drv_struct *)NULL)->member,     \
22568c2ecf20Sopenharmony_ci				      struct ib_struct)))
22578c2ecf20Sopenharmony_ci
22588c2ecf20Sopenharmony_ci#define rdma_zalloc_drv_obj_gfp(ib_dev, ib_type, gfp)                         \
22598c2ecf20Sopenharmony_ci	((struct ib_type *)kzalloc(ib_dev->ops.size_##ib_type, gfp))
22608c2ecf20Sopenharmony_ci
22618c2ecf20Sopenharmony_ci#define rdma_zalloc_drv_obj(ib_dev, ib_type)                                   \
22628c2ecf20Sopenharmony_ci	rdma_zalloc_drv_obj_gfp(ib_dev, ib_type, GFP_KERNEL)
22638c2ecf20Sopenharmony_ci
22648c2ecf20Sopenharmony_ci#define DECLARE_RDMA_OBJ_SIZE(ib_struct) size_t size_##ib_struct
22658c2ecf20Sopenharmony_ci
22668c2ecf20Sopenharmony_cistruct rdma_user_mmap_entry {
22678c2ecf20Sopenharmony_ci	struct kref ref;
22688c2ecf20Sopenharmony_ci	struct ib_ucontext *ucontext;
22698c2ecf20Sopenharmony_ci	unsigned long start_pgoff;
22708c2ecf20Sopenharmony_ci	size_t npages;
22718c2ecf20Sopenharmony_ci	bool driver_removed;
22728c2ecf20Sopenharmony_ci};
22738c2ecf20Sopenharmony_ci
22748c2ecf20Sopenharmony_ci/* Return the offset (in bytes) the user should pass to libc's mmap() */
22758c2ecf20Sopenharmony_cistatic inline u64
22768c2ecf20Sopenharmony_cirdma_user_mmap_get_offset(const struct rdma_user_mmap_entry *entry)
22778c2ecf20Sopenharmony_ci{
22788c2ecf20Sopenharmony_ci	return (u64)entry->start_pgoff << PAGE_SHIFT;
22798c2ecf20Sopenharmony_ci}
22808c2ecf20Sopenharmony_ci
22818c2ecf20Sopenharmony_ci/**
22828c2ecf20Sopenharmony_ci * struct ib_device_ops - InfiniBand device operations
22838c2ecf20Sopenharmony_ci * This structure defines all the InfiniBand device operations, providers will
22848c2ecf20Sopenharmony_ci * need to define the supported operations, otherwise they will be set to null.
22858c2ecf20Sopenharmony_ci */
22868c2ecf20Sopenharmony_cistruct ib_device_ops {
22878c2ecf20Sopenharmony_ci	struct module *owner;
22888c2ecf20Sopenharmony_ci	enum rdma_driver_id driver_id;
22898c2ecf20Sopenharmony_ci	u32 uverbs_abi_ver;
22908c2ecf20Sopenharmony_ci	unsigned int uverbs_no_driver_id_binding:1;
22918c2ecf20Sopenharmony_ci
22928c2ecf20Sopenharmony_ci	int (*post_send)(struct ib_qp *qp, const struct ib_send_wr *send_wr,
22938c2ecf20Sopenharmony_ci			 const struct ib_send_wr **bad_send_wr);
22948c2ecf20Sopenharmony_ci	int (*post_recv)(struct ib_qp *qp, const struct ib_recv_wr *recv_wr,
22958c2ecf20Sopenharmony_ci			 const struct ib_recv_wr **bad_recv_wr);
22968c2ecf20Sopenharmony_ci	void (*drain_rq)(struct ib_qp *qp);
22978c2ecf20Sopenharmony_ci	void (*drain_sq)(struct ib_qp *qp);
22988c2ecf20Sopenharmony_ci	int (*poll_cq)(struct ib_cq *cq, int num_entries, struct ib_wc *wc);
22998c2ecf20Sopenharmony_ci	int (*peek_cq)(struct ib_cq *cq, int wc_cnt);
23008c2ecf20Sopenharmony_ci	int (*req_notify_cq)(struct ib_cq *cq, enum ib_cq_notify_flags flags);
23018c2ecf20Sopenharmony_ci	int (*req_ncomp_notif)(struct ib_cq *cq, int wc_cnt);
23028c2ecf20Sopenharmony_ci	int (*post_srq_recv)(struct ib_srq *srq,
23038c2ecf20Sopenharmony_ci			     const struct ib_recv_wr *recv_wr,
23048c2ecf20Sopenharmony_ci			     const struct ib_recv_wr **bad_recv_wr);
23058c2ecf20Sopenharmony_ci	int (*process_mad)(struct ib_device *device, int process_mad_flags,
23068c2ecf20Sopenharmony_ci			   u8 port_num, const struct ib_wc *in_wc,
23078c2ecf20Sopenharmony_ci			   const struct ib_grh *in_grh,
23088c2ecf20Sopenharmony_ci			   const struct ib_mad *in_mad, struct ib_mad *out_mad,
23098c2ecf20Sopenharmony_ci			   size_t *out_mad_size, u16 *out_mad_pkey_index);
23108c2ecf20Sopenharmony_ci	int (*query_device)(struct ib_device *device,
23118c2ecf20Sopenharmony_ci			    struct ib_device_attr *device_attr,
23128c2ecf20Sopenharmony_ci			    struct ib_udata *udata);
23138c2ecf20Sopenharmony_ci	int (*modify_device)(struct ib_device *device, int device_modify_mask,
23148c2ecf20Sopenharmony_ci			     struct ib_device_modify *device_modify);
23158c2ecf20Sopenharmony_ci	void (*get_dev_fw_str)(struct ib_device *device, char *str);
23168c2ecf20Sopenharmony_ci	const struct cpumask *(*get_vector_affinity)(struct ib_device *ibdev,
23178c2ecf20Sopenharmony_ci						     int comp_vector);
23188c2ecf20Sopenharmony_ci	int (*query_port)(struct ib_device *device, u8 port_num,
23198c2ecf20Sopenharmony_ci			  struct ib_port_attr *port_attr);
23208c2ecf20Sopenharmony_ci	int (*modify_port)(struct ib_device *device, u8 port_num,
23218c2ecf20Sopenharmony_ci			   int port_modify_mask,
23228c2ecf20Sopenharmony_ci			   struct ib_port_modify *port_modify);
23238c2ecf20Sopenharmony_ci	/**
23248c2ecf20Sopenharmony_ci	 * The following mandatory functions are used only at device
23258c2ecf20Sopenharmony_ci	 * registration.  Keep functions such as these at the end of this
23268c2ecf20Sopenharmony_ci	 * structure to avoid cache line misses when accessing struct ib_device
23278c2ecf20Sopenharmony_ci	 * in fast paths.
23288c2ecf20Sopenharmony_ci	 */
23298c2ecf20Sopenharmony_ci	int (*get_port_immutable)(struct ib_device *device, u8 port_num,
23308c2ecf20Sopenharmony_ci				  struct ib_port_immutable *immutable);
23318c2ecf20Sopenharmony_ci	enum rdma_link_layer (*get_link_layer)(struct ib_device *device,
23328c2ecf20Sopenharmony_ci					       u8 port_num);
23338c2ecf20Sopenharmony_ci	/**
23348c2ecf20Sopenharmony_ci	 * When calling get_netdev, the HW vendor's driver should return the
23358c2ecf20Sopenharmony_ci	 * net device of device @device at port @port_num or NULL if such
23368c2ecf20Sopenharmony_ci	 * a net device doesn't exist. The vendor driver should call dev_hold
23378c2ecf20Sopenharmony_ci	 * on this net device. The HW vendor's device driver must guarantee
23388c2ecf20Sopenharmony_ci	 * that this function returns NULL before the net device has finished
23398c2ecf20Sopenharmony_ci	 * NETDEV_UNREGISTER state.
23408c2ecf20Sopenharmony_ci	 */
23418c2ecf20Sopenharmony_ci	struct net_device *(*get_netdev)(struct ib_device *device, u8 port_num);
23428c2ecf20Sopenharmony_ci	/**
23438c2ecf20Sopenharmony_ci	 * rdma netdev operation
23448c2ecf20Sopenharmony_ci	 *
23458c2ecf20Sopenharmony_ci	 * Driver implementing alloc_rdma_netdev or rdma_netdev_get_params
23468c2ecf20Sopenharmony_ci	 * must return -EOPNOTSUPP if it doesn't support the specified type.
23478c2ecf20Sopenharmony_ci	 */
23488c2ecf20Sopenharmony_ci	struct net_device *(*alloc_rdma_netdev)(
23498c2ecf20Sopenharmony_ci		struct ib_device *device, u8 port_num, enum rdma_netdev_t type,
23508c2ecf20Sopenharmony_ci		const char *name, unsigned char name_assign_type,
23518c2ecf20Sopenharmony_ci		void (*setup)(struct net_device *));
23528c2ecf20Sopenharmony_ci
23538c2ecf20Sopenharmony_ci	int (*rdma_netdev_get_params)(struct ib_device *device, u8 port_num,
23548c2ecf20Sopenharmony_ci				      enum rdma_netdev_t type,
23558c2ecf20Sopenharmony_ci				      struct rdma_netdev_alloc_params *params);
23568c2ecf20Sopenharmony_ci	/**
23578c2ecf20Sopenharmony_ci	 * query_gid should be return GID value for @device, when @port_num
23588c2ecf20Sopenharmony_ci	 * link layer is either IB or iWarp. It is no-op if @port_num port
23598c2ecf20Sopenharmony_ci	 * is RoCE link layer.
23608c2ecf20Sopenharmony_ci	 */
23618c2ecf20Sopenharmony_ci	int (*query_gid)(struct ib_device *device, u8 port_num, int index,
23628c2ecf20Sopenharmony_ci			 union ib_gid *gid);
23638c2ecf20Sopenharmony_ci	/**
23648c2ecf20Sopenharmony_ci	 * When calling add_gid, the HW vendor's driver should add the gid
23658c2ecf20Sopenharmony_ci	 * of device of port at gid index available at @attr. Meta-info of
23668c2ecf20Sopenharmony_ci	 * that gid (for example, the network device related to this gid) is
23678c2ecf20Sopenharmony_ci	 * available at @attr. @context allows the HW vendor driver to store
23688c2ecf20Sopenharmony_ci	 * extra information together with a GID entry. The HW vendor driver may
23698c2ecf20Sopenharmony_ci	 * allocate memory to contain this information and store it in @context
23708c2ecf20Sopenharmony_ci	 * when a new GID entry is written to. Params are consistent until the
23718c2ecf20Sopenharmony_ci	 * next call of add_gid or delete_gid. The function should return 0 on
23728c2ecf20Sopenharmony_ci	 * success or error otherwise. The function could be called
23738c2ecf20Sopenharmony_ci	 * concurrently for different ports. This function is only called when
23748c2ecf20Sopenharmony_ci	 * roce_gid_table is used.
23758c2ecf20Sopenharmony_ci	 */
23768c2ecf20Sopenharmony_ci	int (*add_gid)(const struct ib_gid_attr *attr, void **context);
23778c2ecf20Sopenharmony_ci	/**
23788c2ecf20Sopenharmony_ci	 * When calling del_gid, the HW vendor's driver should delete the
23798c2ecf20Sopenharmony_ci	 * gid of device @device at gid index gid_index of port port_num
23808c2ecf20Sopenharmony_ci	 * available in @attr.
23818c2ecf20Sopenharmony_ci	 * Upon the deletion of a GID entry, the HW vendor must free any
23828c2ecf20Sopenharmony_ci	 * allocated memory. The caller will clear @context afterwards.
23838c2ecf20Sopenharmony_ci	 * This function is only called when roce_gid_table is used.
23848c2ecf20Sopenharmony_ci	 */
23858c2ecf20Sopenharmony_ci	int (*del_gid)(const struct ib_gid_attr *attr, void **context);
23868c2ecf20Sopenharmony_ci	int (*query_pkey)(struct ib_device *device, u8 port_num, u16 index,
23878c2ecf20Sopenharmony_ci			  u16 *pkey);
23888c2ecf20Sopenharmony_ci	int (*alloc_ucontext)(struct ib_ucontext *context,
23898c2ecf20Sopenharmony_ci			      struct ib_udata *udata);
23908c2ecf20Sopenharmony_ci	void (*dealloc_ucontext)(struct ib_ucontext *context);
23918c2ecf20Sopenharmony_ci	int (*mmap)(struct ib_ucontext *context, struct vm_area_struct *vma);
23928c2ecf20Sopenharmony_ci	/**
23938c2ecf20Sopenharmony_ci	 * This will be called once refcount of an entry in mmap_xa reaches
23948c2ecf20Sopenharmony_ci	 * zero. The type of the memory that was mapped may differ between
23958c2ecf20Sopenharmony_ci	 * entries and is opaque to the rdma_user_mmap interface.
23968c2ecf20Sopenharmony_ci	 * Therefore needs to be implemented by the driver in mmap_free.
23978c2ecf20Sopenharmony_ci	 */
23988c2ecf20Sopenharmony_ci	void (*mmap_free)(struct rdma_user_mmap_entry *entry);
23998c2ecf20Sopenharmony_ci	void (*disassociate_ucontext)(struct ib_ucontext *ibcontext);
24008c2ecf20Sopenharmony_ci	int (*alloc_pd)(struct ib_pd *pd, struct ib_udata *udata);
24018c2ecf20Sopenharmony_ci	int (*dealloc_pd)(struct ib_pd *pd, struct ib_udata *udata);
24028c2ecf20Sopenharmony_ci	int (*create_ah)(struct ib_ah *ah, struct rdma_ah_init_attr *attr,
24038c2ecf20Sopenharmony_ci			 struct ib_udata *udata);
24048c2ecf20Sopenharmony_ci	int (*modify_ah)(struct ib_ah *ah, struct rdma_ah_attr *ah_attr);
24058c2ecf20Sopenharmony_ci	int (*query_ah)(struct ib_ah *ah, struct rdma_ah_attr *ah_attr);
24068c2ecf20Sopenharmony_ci	int (*destroy_ah)(struct ib_ah *ah, u32 flags);
24078c2ecf20Sopenharmony_ci	int (*create_srq)(struct ib_srq *srq,
24088c2ecf20Sopenharmony_ci			  struct ib_srq_init_attr *srq_init_attr,
24098c2ecf20Sopenharmony_ci			  struct ib_udata *udata);
24108c2ecf20Sopenharmony_ci	int (*modify_srq)(struct ib_srq *srq, struct ib_srq_attr *srq_attr,
24118c2ecf20Sopenharmony_ci			  enum ib_srq_attr_mask srq_attr_mask,
24128c2ecf20Sopenharmony_ci			  struct ib_udata *udata);
24138c2ecf20Sopenharmony_ci	int (*query_srq)(struct ib_srq *srq, struct ib_srq_attr *srq_attr);
24148c2ecf20Sopenharmony_ci	int (*destroy_srq)(struct ib_srq *srq, struct ib_udata *udata);
24158c2ecf20Sopenharmony_ci	struct ib_qp *(*create_qp)(struct ib_pd *pd,
24168c2ecf20Sopenharmony_ci				   struct ib_qp_init_attr *qp_init_attr,
24178c2ecf20Sopenharmony_ci				   struct ib_udata *udata);
24188c2ecf20Sopenharmony_ci	int (*modify_qp)(struct ib_qp *qp, struct ib_qp_attr *qp_attr,
24198c2ecf20Sopenharmony_ci			 int qp_attr_mask, struct ib_udata *udata);
24208c2ecf20Sopenharmony_ci	int (*query_qp)(struct ib_qp *qp, struct ib_qp_attr *qp_attr,
24218c2ecf20Sopenharmony_ci			int qp_attr_mask, struct ib_qp_init_attr *qp_init_attr);
24228c2ecf20Sopenharmony_ci	int (*destroy_qp)(struct ib_qp *qp, struct ib_udata *udata);
24238c2ecf20Sopenharmony_ci	int (*create_cq)(struct ib_cq *cq, const struct ib_cq_init_attr *attr,
24248c2ecf20Sopenharmony_ci			 struct ib_udata *udata);
24258c2ecf20Sopenharmony_ci	int (*modify_cq)(struct ib_cq *cq, u16 cq_count, u16 cq_period);
24268c2ecf20Sopenharmony_ci	int (*destroy_cq)(struct ib_cq *cq, struct ib_udata *udata);
24278c2ecf20Sopenharmony_ci	int (*resize_cq)(struct ib_cq *cq, int cqe, struct ib_udata *udata);
24288c2ecf20Sopenharmony_ci	struct ib_mr *(*get_dma_mr)(struct ib_pd *pd, int mr_access_flags);
24298c2ecf20Sopenharmony_ci	struct ib_mr *(*reg_user_mr)(struct ib_pd *pd, u64 start, u64 length,
24308c2ecf20Sopenharmony_ci				     u64 virt_addr, int mr_access_flags,
24318c2ecf20Sopenharmony_ci				     struct ib_udata *udata);
24328c2ecf20Sopenharmony_ci	int (*rereg_user_mr)(struct ib_mr *mr, int flags, u64 start, u64 length,
24338c2ecf20Sopenharmony_ci			     u64 virt_addr, int mr_access_flags,
24348c2ecf20Sopenharmony_ci			     struct ib_pd *pd, struct ib_udata *udata);
24358c2ecf20Sopenharmony_ci	int (*dereg_mr)(struct ib_mr *mr, struct ib_udata *udata);
24368c2ecf20Sopenharmony_ci	struct ib_mr *(*alloc_mr)(struct ib_pd *pd, enum ib_mr_type mr_type,
24378c2ecf20Sopenharmony_ci				  u32 max_num_sg);
24388c2ecf20Sopenharmony_ci	struct ib_mr *(*alloc_mr_integrity)(struct ib_pd *pd,
24398c2ecf20Sopenharmony_ci					    u32 max_num_data_sg,
24408c2ecf20Sopenharmony_ci					    u32 max_num_meta_sg);
24418c2ecf20Sopenharmony_ci	int (*advise_mr)(struct ib_pd *pd,
24428c2ecf20Sopenharmony_ci			 enum ib_uverbs_advise_mr_advice advice, u32 flags,
24438c2ecf20Sopenharmony_ci			 struct ib_sge *sg_list, u32 num_sge,
24448c2ecf20Sopenharmony_ci			 struct uverbs_attr_bundle *attrs);
24458c2ecf20Sopenharmony_ci	int (*map_mr_sg)(struct ib_mr *mr, struct scatterlist *sg, int sg_nents,
24468c2ecf20Sopenharmony_ci			 unsigned int *sg_offset);
24478c2ecf20Sopenharmony_ci	int (*check_mr_status)(struct ib_mr *mr, u32 check_mask,
24488c2ecf20Sopenharmony_ci			       struct ib_mr_status *mr_status);
24498c2ecf20Sopenharmony_ci	int (*alloc_mw)(struct ib_mw *mw, struct ib_udata *udata);
24508c2ecf20Sopenharmony_ci	int (*dealloc_mw)(struct ib_mw *mw);
24518c2ecf20Sopenharmony_ci	int (*attach_mcast)(struct ib_qp *qp, union ib_gid *gid, u16 lid);
24528c2ecf20Sopenharmony_ci	int (*detach_mcast)(struct ib_qp *qp, union ib_gid *gid, u16 lid);
24538c2ecf20Sopenharmony_ci	int (*alloc_xrcd)(struct ib_xrcd *xrcd, struct ib_udata *udata);
24548c2ecf20Sopenharmony_ci	int (*dealloc_xrcd)(struct ib_xrcd *xrcd, struct ib_udata *udata);
24558c2ecf20Sopenharmony_ci	struct ib_flow *(*create_flow)(struct ib_qp *qp,
24568c2ecf20Sopenharmony_ci				       struct ib_flow_attr *flow_attr,
24578c2ecf20Sopenharmony_ci				       struct ib_udata *udata);
24588c2ecf20Sopenharmony_ci	int (*destroy_flow)(struct ib_flow *flow_id);
24598c2ecf20Sopenharmony_ci	struct ib_flow_action *(*create_flow_action_esp)(
24608c2ecf20Sopenharmony_ci		struct ib_device *device,
24618c2ecf20Sopenharmony_ci		const struct ib_flow_action_attrs_esp *attr,
24628c2ecf20Sopenharmony_ci		struct uverbs_attr_bundle *attrs);
24638c2ecf20Sopenharmony_ci	int (*destroy_flow_action)(struct ib_flow_action *action);
24648c2ecf20Sopenharmony_ci	int (*modify_flow_action_esp)(
24658c2ecf20Sopenharmony_ci		struct ib_flow_action *action,
24668c2ecf20Sopenharmony_ci		const struct ib_flow_action_attrs_esp *attr,
24678c2ecf20Sopenharmony_ci		struct uverbs_attr_bundle *attrs);
24688c2ecf20Sopenharmony_ci	int (*set_vf_link_state)(struct ib_device *device, int vf, u8 port,
24698c2ecf20Sopenharmony_ci				 int state);
24708c2ecf20Sopenharmony_ci	int (*get_vf_config)(struct ib_device *device, int vf, u8 port,
24718c2ecf20Sopenharmony_ci			     struct ifla_vf_info *ivf);
24728c2ecf20Sopenharmony_ci	int (*get_vf_stats)(struct ib_device *device, int vf, u8 port,
24738c2ecf20Sopenharmony_ci			    struct ifla_vf_stats *stats);
24748c2ecf20Sopenharmony_ci	int (*get_vf_guid)(struct ib_device *device, int vf, u8 port,
24758c2ecf20Sopenharmony_ci			    struct ifla_vf_guid *node_guid,
24768c2ecf20Sopenharmony_ci			    struct ifla_vf_guid *port_guid);
24778c2ecf20Sopenharmony_ci	int (*set_vf_guid)(struct ib_device *device, int vf, u8 port, u64 guid,
24788c2ecf20Sopenharmony_ci			   int type);
24798c2ecf20Sopenharmony_ci	struct ib_wq *(*create_wq)(struct ib_pd *pd,
24808c2ecf20Sopenharmony_ci				   struct ib_wq_init_attr *init_attr,
24818c2ecf20Sopenharmony_ci				   struct ib_udata *udata);
24828c2ecf20Sopenharmony_ci	int (*destroy_wq)(struct ib_wq *wq, struct ib_udata *udata);
24838c2ecf20Sopenharmony_ci	int (*modify_wq)(struct ib_wq *wq, struct ib_wq_attr *attr,
24848c2ecf20Sopenharmony_ci			 u32 wq_attr_mask, struct ib_udata *udata);
24858c2ecf20Sopenharmony_ci	int (*create_rwq_ind_table)(struct ib_rwq_ind_table *ib_rwq_ind_table,
24868c2ecf20Sopenharmony_ci				    struct ib_rwq_ind_table_init_attr *init_attr,
24878c2ecf20Sopenharmony_ci				    struct ib_udata *udata);
24888c2ecf20Sopenharmony_ci	int (*destroy_rwq_ind_table)(struct ib_rwq_ind_table *wq_ind_table);
24898c2ecf20Sopenharmony_ci	struct ib_dm *(*alloc_dm)(struct ib_device *device,
24908c2ecf20Sopenharmony_ci				  struct ib_ucontext *context,
24918c2ecf20Sopenharmony_ci				  struct ib_dm_alloc_attr *attr,
24928c2ecf20Sopenharmony_ci				  struct uverbs_attr_bundle *attrs);
24938c2ecf20Sopenharmony_ci	int (*dealloc_dm)(struct ib_dm *dm, struct uverbs_attr_bundle *attrs);
24948c2ecf20Sopenharmony_ci	struct ib_mr *(*reg_dm_mr)(struct ib_pd *pd, struct ib_dm *dm,
24958c2ecf20Sopenharmony_ci				   struct ib_dm_mr_attr *attr,
24968c2ecf20Sopenharmony_ci				   struct uverbs_attr_bundle *attrs);
24978c2ecf20Sopenharmony_ci	int (*create_counters)(struct ib_counters *counters,
24988c2ecf20Sopenharmony_ci			       struct uverbs_attr_bundle *attrs);
24998c2ecf20Sopenharmony_ci	int (*destroy_counters)(struct ib_counters *counters);
25008c2ecf20Sopenharmony_ci	int (*read_counters)(struct ib_counters *counters,
25018c2ecf20Sopenharmony_ci			     struct ib_counters_read_attr *counters_read_attr,
25028c2ecf20Sopenharmony_ci			     struct uverbs_attr_bundle *attrs);
25038c2ecf20Sopenharmony_ci	int (*map_mr_sg_pi)(struct ib_mr *mr, struct scatterlist *data_sg,
25048c2ecf20Sopenharmony_ci			    int data_sg_nents, unsigned int *data_sg_offset,
25058c2ecf20Sopenharmony_ci			    struct scatterlist *meta_sg, int meta_sg_nents,
25068c2ecf20Sopenharmony_ci			    unsigned int *meta_sg_offset);
25078c2ecf20Sopenharmony_ci
25088c2ecf20Sopenharmony_ci	/**
25098c2ecf20Sopenharmony_ci	 * alloc_hw_stats - Allocate a struct rdma_hw_stats and fill in the
25108c2ecf20Sopenharmony_ci	 *   driver initialized data.  The struct is kfree()'ed by the sysfs
25118c2ecf20Sopenharmony_ci	 *   core when the device is removed.  A lifespan of -1 in the return
25128c2ecf20Sopenharmony_ci	 *   struct tells the core to set a default lifespan.
25138c2ecf20Sopenharmony_ci	 */
25148c2ecf20Sopenharmony_ci	struct rdma_hw_stats *(*alloc_hw_stats)(struct ib_device *device,
25158c2ecf20Sopenharmony_ci						u8 port_num);
25168c2ecf20Sopenharmony_ci	/**
25178c2ecf20Sopenharmony_ci	 * get_hw_stats - Fill in the counter value(s) in the stats struct.
25188c2ecf20Sopenharmony_ci	 * @index - The index in the value array we wish to have updated, or
25198c2ecf20Sopenharmony_ci	 *   num_counters if we want all stats updated
25208c2ecf20Sopenharmony_ci	 * Return codes -
25218c2ecf20Sopenharmony_ci	 *   < 0 - Error, no counters updated
25228c2ecf20Sopenharmony_ci	 *   index - Updated the single counter pointed to by index
25238c2ecf20Sopenharmony_ci	 *   num_counters - Updated all counters (will reset the timestamp
25248c2ecf20Sopenharmony_ci	 *     and prevent further calls for lifespan milliseconds)
25258c2ecf20Sopenharmony_ci	 * Drivers are allowed to update all counters in leiu of just the
25268c2ecf20Sopenharmony_ci	 *   one given in index at their option
25278c2ecf20Sopenharmony_ci	 */
25288c2ecf20Sopenharmony_ci	int (*get_hw_stats)(struct ib_device *device,
25298c2ecf20Sopenharmony_ci			    struct rdma_hw_stats *stats, u8 port, int index);
25308c2ecf20Sopenharmony_ci	/*
25318c2ecf20Sopenharmony_ci	 * This function is called once for each port when a ib device is
25328c2ecf20Sopenharmony_ci	 * registered.
25338c2ecf20Sopenharmony_ci	 */
25348c2ecf20Sopenharmony_ci	int (*init_port)(struct ib_device *device, u8 port_num,
25358c2ecf20Sopenharmony_ci			 struct kobject *port_sysfs);
25368c2ecf20Sopenharmony_ci	/**
25378c2ecf20Sopenharmony_ci	 * Allows rdma drivers to add their own restrack attributes.
25388c2ecf20Sopenharmony_ci	 */
25398c2ecf20Sopenharmony_ci	int (*fill_res_mr_entry)(struct sk_buff *msg, struct ib_mr *ibmr);
25408c2ecf20Sopenharmony_ci	int (*fill_res_mr_entry_raw)(struct sk_buff *msg, struct ib_mr *ibmr);
25418c2ecf20Sopenharmony_ci	int (*fill_res_cq_entry)(struct sk_buff *msg, struct ib_cq *ibcq);
25428c2ecf20Sopenharmony_ci	int (*fill_res_cq_entry_raw)(struct sk_buff *msg, struct ib_cq *ibcq);
25438c2ecf20Sopenharmony_ci	int (*fill_res_qp_entry)(struct sk_buff *msg, struct ib_qp *ibqp);
25448c2ecf20Sopenharmony_ci	int (*fill_res_qp_entry_raw)(struct sk_buff *msg, struct ib_qp *ibqp);
25458c2ecf20Sopenharmony_ci	int (*fill_res_cm_id_entry)(struct sk_buff *msg, struct rdma_cm_id *id);
25468c2ecf20Sopenharmony_ci
25478c2ecf20Sopenharmony_ci	/* Device lifecycle callbacks */
25488c2ecf20Sopenharmony_ci	/*
25498c2ecf20Sopenharmony_ci	 * Called after the device becomes registered, before clients are
25508c2ecf20Sopenharmony_ci	 * attached
25518c2ecf20Sopenharmony_ci	 */
25528c2ecf20Sopenharmony_ci	int (*enable_driver)(struct ib_device *dev);
25538c2ecf20Sopenharmony_ci	/*
25548c2ecf20Sopenharmony_ci	 * This is called as part of ib_dealloc_device().
25558c2ecf20Sopenharmony_ci	 */
25568c2ecf20Sopenharmony_ci	void (*dealloc_driver)(struct ib_device *dev);
25578c2ecf20Sopenharmony_ci
25588c2ecf20Sopenharmony_ci	/* iWarp CM callbacks */
25598c2ecf20Sopenharmony_ci	void (*iw_add_ref)(struct ib_qp *qp);
25608c2ecf20Sopenharmony_ci	void (*iw_rem_ref)(struct ib_qp *qp);
25618c2ecf20Sopenharmony_ci	struct ib_qp *(*iw_get_qp)(struct ib_device *device, int qpn);
25628c2ecf20Sopenharmony_ci	int (*iw_connect)(struct iw_cm_id *cm_id,
25638c2ecf20Sopenharmony_ci			  struct iw_cm_conn_param *conn_param);
25648c2ecf20Sopenharmony_ci	int (*iw_accept)(struct iw_cm_id *cm_id,
25658c2ecf20Sopenharmony_ci			 struct iw_cm_conn_param *conn_param);
25668c2ecf20Sopenharmony_ci	int (*iw_reject)(struct iw_cm_id *cm_id, const void *pdata,
25678c2ecf20Sopenharmony_ci			 u8 pdata_len);
25688c2ecf20Sopenharmony_ci	int (*iw_create_listen)(struct iw_cm_id *cm_id, int backlog);
25698c2ecf20Sopenharmony_ci	int (*iw_destroy_listen)(struct iw_cm_id *cm_id);
25708c2ecf20Sopenharmony_ci	/**
25718c2ecf20Sopenharmony_ci	 * counter_bind_qp - Bind a QP to a counter.
25728c2ecf20Sopenharmony_ci	 * @counter - The counter to be bound. If counter->id is zero then
25738c2ecf20Sopenharmony_ci	 *   the driver needs to allocate a new counter and set counter->id
25748c2ecf20Sopenharmony_ci	 */
25758c2ecf20Sopenharmony_ci	int (*counter_bind_qp)(struct rdma_counter *counter, struct ib_qp *qp);
25768c2ecf20Sopenharmony_ci	/**
25778c2ecf20Sopenharmony_ci	 * counter_unbind_qp - Unbind the qp from the dynamically-allocated
25788c2ecf20Sopenharmony_ci	 *   counter and bind it onto the default one
25798c2ecf20Sopenharmony_ci	 */
25808c2ecf20Sopenharmony_ci	int (*counter_unbind_qp)(struct ib_qp *qp);
25818c2ecf20Sopenharmony_ci	/**
25828c2ecf20Sopenharmony_ci	 * counter_dealloc -De-allocate the hw counter
25838c2ecf20Sopenharmony_ci	 */
25848c2ecf20Sopenharmony_ci	int (*counter_dealloc)(struct rdma_counter *counter);
25858c2ecf20Sopenharmony_ci	/**
25868c2ecf20Sopenharmony_ci	 * counter_alloc_stats - Allocate a struct rdma_hw_stats and fill in
25878c2ecf20Sopenharmony_ci	 * the driver initialized data.
25888c2ecf20Sopenharmony_ci	 */
25898c2ecf20Sopenharmony_ci	struct rdma_hw_stats *(*counter_alloc_stats)(
25908c2ecf20Sopenharmony_ci		struct rdma_counter *counter);
25918c2ecf20Sopenharmony_ci	/**
25928c2ecf20Sopenharmony_ci	 * counter_update_stats - Query the stats value of this counter
25938c2ecf20Sopenharmony_ci	 */
25948c2ecf20Sopenharmony_ci	int (*counter_update_stats)(struct rdma_counter *counter);
25958c2ecf20Sopenharmony_ci
25968c2ecf20Sopenharmony_ci	/**
25978c2ecf20Sopenharmony_ci	 * Allows rdma drivers to add their own restrack attributes
25988c2ecf20Sopenharmony_ci	 * dumped via 'rdma stat' iproute2 command.
25998c2ecf20Sopenharmony_ci	 */
26008c2ecf20Sopenharmony_ci	int (*fill_stat_mr_entry)(struct sk_buff *msg, struct ib_mr *ibmr);
26018c2ecf20Sopenharmony_ci
26028c2ecf20Sopenharmony_ci	/* query driver for its ucontext properties */
26038c2ecf20Sopenharmony_ci	int (*query_ucontext)(struct ib_ucontext *context,
26048c2ecf20Sopenharmony_ci			      struct uverbs_attr_bundle *attrs);
26058c2ecf20Sopenharmony_ci
26068c2ecf20Sopenharmony_ci	DECLARE_RDMA_OBJ_SIZE(ib_ah);
26078c2ecf20Sopenharmony_ci	DECLARE_RDMA_OBJ_SIZE(ib_counters);
26088c2ecf20Sopenharmony_ci	DECLARE_RDMA_OBJ_SIZE(ib_cq);
26098c2ecf20Sopenharmony_ci	DECLARE_RDMA_OBJ_SIZE(ib_mw);
26108c2ecf20Sopenharmony_ci	DECLARE_RDMA_OBJ_SIZE(ib_pd);
26118c2ecf20Sopenharmony_ci	DECLARE_RDMA_OBJ_SIZE(ib_rwq_ind_table);
26128c2ecf20Sopenharmony_ci	DECLARE_RDMA_OBJ_SIZE(ib_srq);
26138c2ecf20Sopenharmony_ci	DECLARE_RDMA_OBJ_SIZE(ib_ucontext);
26148c2ecf20Sopenharmony_ci	DECLARE_RDMA_OBJ_SIZE(ib_xrcd);
26158c2ecf20Sopenharmony_ci};
26168c2ecf20Sopenharmony_ci
26178c2ecf20Sopenharmony_cistruct ib_core_device {
26188c2ecf20Sopenharmony_ci	/* device must be the first element in structure until,
26198c2ecf20Sopenharmony_ci	 * union of ib_core_device and device exists in ib_device.
26208c2ecf20Sopenharmony_ci	 */
26218c2ecf20Sopenharmony_ci	struct device dev;
26228c2ecf20Sopenharmony_ci	possible_net_t rdma_net;
26238c2ecf20Sopenharmony_ci	struct kobject *ports_kobj;
26248c2ecf20Sopenharmony_ci	struct list_head port_list;
26258c2ecf20Sopenharmony_ci	struct ib_device *owner; /* reach back to owner ib_device */
26268c2ecf20Sopenharmony_ci};
26278c2ecf20Sopenharmony_ci
26288c2ecf20Sopenharmony_cistruct rdma_restrack_root;
26298c2ecf20Sopenharmony_cistruct ib_device {
26308c2ecf20Sopenharmony_ci	/* Do not access @dma_device directly from ULP nor from HW drivers. */
26318c2ecf20Sopenharmony_ci	struct device                *dma_device;
26328c2ecf20Sopenharmony_ci	struct ib_device_ops	     ops;
26338c2ecf20Sopenharmony_ci	char                          name[IB_DEVICE_NAME_MAX];
26348c2ecf20Sopenharmony_ci	struct rcu_head rcu_head;
26358c2ecf20Sopenharmony_ci
26368c2ecf20Sopenharmony_ci	struct list_head              event_handler_list;
26378c2ecf20Sopenharmony_ci	/* Protects event_handler_list */
26388c2ecf20Sopenharmony_ci	struct rw_semaphore event_handler_rwsem;
26398c2ecf20Sopenharmony_ci
26408c2ecf20Sopenharmony_ci	/* Protects QP's event_handler calls and open_qp list */
26418c2ecf20Sopenharmony_ci	spinlock_t qp_open_list_lock;
26428c2ecf20Sopenharmony_ci
26438c2ecf20Sopenharmony_ci	struct rw_semaphore	      client_data_rwsem;
26448c2ecf20Sopenharmony_ci	struct xarray                 client_data;
26458c2ecf20Sopenharmony_ci	struct mutex                  unregistration_lock;
26468c2ecf20Sopenharmony_ci
26478c2ecf20Sopenharmony_ci	/* Synchronize GID, Pkey cache entries, subnet prefix, LMC */
26488c2ecf20Sopenharmony_ci	rwlock_t cache_lock;
26498c2ecf20Sopenharmony_ci	/**
26508c2ecf20Sopenharmony_ci	 * port_data is indexed by port number
26518c2ecf20Sopenharmony_ci	 */
26528c2ecf20Sopenharmony_ci	struct ib_port_data *port_data;
26538c2ecf20Sopenharmony_ci
26548c2ecf20Sopenharmony_ci	int			      num_comp_vectors;
26558c2ecf20Sopenharmony_ci
26568c2ecf20Sopenharmony_ci	union {
26578c2ecf20Sopenharmony_ci		struct device		dev;
26588c2ecf20Sopenharmony_ci		struct ib_core_device	coredev;
26598c2ecf20Sopenharmony_ci	};
26608c2ecf20Sopenharmony_ci
26618c2ecf20Sopenharmony_ci	/* First group for device attributes,
26628c2ecf20Sopenharmony_ci	 * Second group for driver provided attributes (optional).
26638c2ecf20Sopenharmony_ci	 * It is NULL terminated array.
26648c2ecf20Sopenharmony_ci	 */
26658c2ecf20Sopenharmony_ci	const struct attribute_group	*groups[3];
26668c2ecf20Sopenharmony_ci
26678c2ecf20Sopenharmony_ci	u64			     uverbs_cmd_mask;
26688c2ecf20Sopenharmony_ci	u64			     uverbs_ex_cmd_mask;
26698c2ecf20Sopenharmony_ci
26708c2ecf20Sopenharmony_ci	char			     node_desc[IB_DEVICE_NODE_DESC_MAX];
26718c2ecf20Sopenharmony_ci	__be64			     node_guid;
26728c2ecf20Sopenharmony_ci	u32			     local_dma_lkey;
26738c2ecf20Sopenharmony_ci	u16                          is_switch:1;
26748c2ecf20Sopenharmony_ci	/* Indicates kernel verbs support, should not be used in drivers */
26758c2ecf20Sopenharmony_ci	u16                          kverbs_provider:1;
26768c2ecf20Sopenharmony_ci	/* CQ adaptive moderation (RDMA DIM) */
26778c2ecf20Sopenharmony_ci	u16                          use_cq_dim:1;
26788c2ecf20Sopenharmony_ci	u8                           node_type;
26798c2ecf20Sopenharmony_ci	u8                           phys_port_cnt;
26808c2ecf20Sopenharmony_ci	struct ib_device_attr        attrs;
26818c2ecf20Sopenharmony_ci	struct attribute_group	     *hw_stats_ag;
26828c2ecf20Sopenharmony_ci	struct rdma_hw_stats         *hw_stats;
26838c2ecf20Sopenharmony_ci
26848c2ecf20Sopenharmony_ci#ifdef CONFIG_CGROUP_RDMA
26858c2ecf20Sopenharmony_ci	struct rdmacg_device         cg_device;
26868c2ecf20Sopenharmony_ci#endif
26878c2ecf20Sopenharmony_ci
26888c2ecf20Sopenharmony_ci	u32                          index;
26898c2ecf20Sopenharmony_ci
26908c2ecf20Sopenharmony_ci	spinlock_t                   cq_pools_lock;
26918c2ecf20Sopenharmony_ci	struct list_head             cq_pools[IB_POLL_LAST_POOL_TYPE + 1];
26928c2ecf20Sopenharmony_ci
26938c2ecf20Sopenharmony_ci	struct rdma_restrack_root *res;
26948c2ecf20Sopenharmony_ci
26958c2ecf20Sopenharmony_ci	const struct uapi_definition   *driver_def;
26968c2ecf20Sopenharmony_ci
26978c2ecf20Sopenharmony_ci	/*
26988c2ecf20Sopenharmony_ci	 * Positive refcount indicates that the device is currently
26998c2ecf20Sopenharmony_ci	 * registered and cannot be unregistered.
27008c2ecf20Sopenharmony_ci	 */
27018c2ecf20Sopenharmony_ci	refcount_t refcount;
27028c2ecf20Sopenharmony_ci	struct completion unreg_completion;
27038c2ecf20Sopenharmony_ci	struct work_struct unregistration_work;
27048c2ecf20Sopenharmony_ci
27058c2ecf20Sopenharmony_ci	const struct rdma_link_ops *link_ops;
27068c2ecf20Sopenharmony_ci
27078c2ecf20Sopenharmony_ci	/* Protects compat_devs xarray modifications */
27088c2ecf20Sopenharmony_ci	struct mutex compat_devs_mutex;
27098c2ecf20Sopenharmony_ci	/* Maintains compat devices for each net namespace */
27108c2ecf20Sopenharmony_ci	struct xarray compat_devs;
27118c2ecf20Sopenharmony_ci
27128c2ecf20Sopenharmony_ci	/* Used by iWarp CM */
27138c2ecf20Sopenharmony_ci	char iw_ifname[IFNAMSIZ];
27148c2ecf20Sopenharmony_ci	u32 iw_driver_flags;
27158c2ecf20Sopenharmony_ci	u32 lag_flags;
27168c2ecf20Sopenharmony_ci};
27178c2ecf20Sopenharmony_ci
27188c2ecf20Sopenharmony_cistruct ib_client_nl_info;
27198c2ecf20Sopenharmony_cistruct ib_client {
27208c2ecf20Sopenharmony_ci	const char *name;
27218c2ecf20Sopenharmony_ci	int (*add)(struct ib_device *ibdev);
27228c2ecf20Sopenharmony_ci	void (*remove)(struct ib_device *, void *client_data);
27238c2ecf20Sopenharmony_ci	void (*rename)(struct ib_device *dev, void *client_data);
27248c2ecf20Sopenharmony_ci	int (*get_nl_info)(struct ib_device *ibdev, void *client_data,
27258c2ecf20Sopenharmony_ci			   struct ib_client_nl_info *res);
27268c2ecf20Sopenharmony_ci	int (*get_global_nl_info)(struct ib_client_nl_info *res);
27278c2ecf20Sopenharmony_ci
27288c2ecf20Sopenharmony_ci	/* Returns the net_dev belonging to this ib_client and matching the
27298c2ecf20Sopenharmony_ci	 * given parameters.
27308c2ecf20Sopenharmony_ci	 * @dev:	 An RDMA device that the net_dev use for communication.
27318c2ecf20Sopenharmony_ci	 * @port:	 A physical port number on the RDMA device.
27328c2ecf20Sopenharmony_ci	 * @pkey:	 P_Key that the net_dev uses if applicable.
27338c2ecf20Sopenharmony_ci	 * @gid:	 A GID that the net_dev uses to communicate.
27348c2ecf20Sopenharmony_ci	 * @addr:	 An IP address the net_dev is configured with.
27358c2ecf20Sopenharmony_ci	 * @client_data: The device's client data set by ib_set_client_data().
27368c2ecf20Sopenharmony_ci	 *
27378c2ecf20Sopenharmony_ci	 * An ib_client that implements a net_dev on top of RDMA devices
27388c2ecf20Sopenharmony_ci	 * (such as IP over IB) should implement this callback, allowing the
27398c2ecf20Sopenharmony_ci	 * rdma_cm module to find the right net_dev for a given request.
27408c2ecf20Sopenharmony_ci	 *
27418c2ecf20Sopenharmony_ci	 * The caller is responsible for calling dev_put on the returned
27428c2ecf20Sopenharmony_ci	 * netdev. */
27438c2ecf20Sopenharmony_ci	struct net_device *(*get_net_dev_by_params)(
27448c2ecf20Sopenharmony_ci			struct ib_device *dev,
27458c2ecf20Sopenharmony_ci			u8 port,
27468c2ecf20Sopenharmony_ci			u16 pkey,
27478c2ecf20Sopenharmony_ci			const union ib_gid *gid,
27488c2ecf20Sopenharmony_ci			const struct sockaddr *addr,
27498c2ecf20Sopenharmony_ci			void *client_data);
27508c2ecf20Sopenharmony_ci
27518c2ecf20Sopenharmony_ci	refcount_t uses;
27528c2ecf20Sopenharmony_ci	struct completion uses_zero;
27538c2ecf20Sopenharmony_ci	u32 client_id;
27548c2ecf20Sopenharmony_ci
27558c2ecf20Sopenharmony_ci	/* kverbs are not required by the client */
27568c2ecf20Sopenharmony_ci	u8 no_kverbs_req:1;
27578c2ecf20Sopenharmony_ci};
27588c2ecf20Sopenharmony_ci
27598c2ecf20Sopenharmony_ci/*
27608c2ecf20Sopenharmony_ci * IB block DMA iterator
27618c2ecf20Sopenharmony_ci *
27628c2ecf20Sopenharmony_ci * Iterates the DMA-mapped SGL in contiguous memory blocks aligned
27638c2ecf20Sopenharmony_ci * to a HW supported page size.
27648c2ecf20Sopenharmony_ci */
27658c2ecf20Sopenharmony_cistruct ib_block_iter {
27668c2ecf20Sopenharmony_ci	/* internal states */
27678c2ecf20Sopenharmony_ci	struct scatterlist *__sg;	/* sg holding the current aligned block */
27688c2ecf20Sopenharmony_ci	dma_addr_t __dma_addr;		/* unaligned DMA address of this block */
27698c2ecf20Sopenharmony_ci	unsigned int __sg_nents;	/* number of SG entries */
27708c2ecf20Sopenharmony_ci	unsigned int __sg_advance;	/* number of bytes to advance in sg in next step */
27718c2ecf20Sopenharmony_ci	unsigned int __pg_bit;		/* alignment of current block */
27728c2ecf20Sopenharmony_ci};
27738c2ecf20Sopenharmony_ci
27748c2ecf20Sopenharmony_cistruct ib_device *_ib_alloc_device(size_t size);
27758c2ecf20Sopenharmony_ci#define ib_alloc_device(drv_struct, member)                                    \
27768c2ecf20Sopenharmony_ci	container_of(_ib_alloc_device(sizeof(struct drv_struct) +              \
27778c2ecf20Sopenharmony_ci				      BUILD_BUG_ON_ZERO(offsetof(              \
27788c2ecf20Sopenharmony_ci					      struct drv_struct, member))),    \
27798c2ecf20Sopenharmony_ci		     struct drv_struct, member)
27808c2ecf20Sopenharmony_ci
27818c2ecf20Sopenharmony_civoid ib_dealloc_device(struct ib_device *device);
27828c2ecf20Sopenharmony_ci
27838c2ecf20Sopenharmony_civoid ib_get_device_fw_str(struct ib_device *device, char *str);
27848c2ecf20Sopenharmony_ci
27858c2ecf20Sopenharmony_ciint ib_register_device(struct ib_device *device, const char *name,
27868c2ecf20Sopenharmony_ci		       struct device *dma_device);
27878c2ecf20Sopenharmony_civoid ib_unregister_device(struct ib_device *device);
27888c2ecf20Sopenharmony_civoid ib_unregister_driver(enum rdma_driver_id driver_id);
27898c2ecf20Sopenharmony_civoid ib_unregister_device_and_put(struct ib_device *device);
27908c2ecf20Sopenharmony_civoid ib_unregister_device_queued(struct ib_device *ib_dev);
27918c2ecf20Sopenharmony_ci
27928c2ecf20Sopenharmony_ciint ib_register_client   (struct ib_client *client);
27938c2ecf20Sopenharmony_civoid ib_unregister_client(struct ib_client *client);
27948c2ecf20Sopenharmony_ci
27958c2ecf20Sopenharmony_civoid __rdma_block_iter_start(struct ib_block_iter *biter,
27968c2ecf20Sopenharmony_ci			     struct scatterlist *sglist,
27978c2ecf20Sopenharmony_ci			     unsigned int nents,
27988c2ecf20Sopenharmony_ci			     unsigned long pgsz);
27998c2ecf20Sopenharmony_cibool __rdma_block_iter_next(struct ib_block_iter *biter);
28008c2ecf20Sopenharmony_ci
28018c2ecf20Sopenharmony_ci/**
28028c2ecf20Sopenharmony_ci * rdma_block_iter_dma_address - get the aligned dma address of the current
28038c2ecf20Sopenharmony_ci * block held by the block iterator.
28048c2ecf20Sopenharmony_ci * @biter: block iterator holding the memory block
28058c2ecf20Sopenharmony_ci */
28068c2ecf20Sopenharmony_cistatic inline dma_addr_t
28078c2ecf20Sopenharmony_cirdma_block_iter_dma_address(struct ib_block_iter *biter)
28088c2ecf20Sopenharmony_ci{
28098c2ecf20Sopenharmony_ci	return biter->__dma_addr & ~(BIT_ULL(biter->__pg_bit) - 1);
28108c2ecf20Sopenharmony_ci}
28118c2ecf20Sopenharmony_ci
28128c2ecf20Sopenharmony_ci/**
28138c2ecf20Sopenharmony_ci * rdma_for_each_block - iterate over contiguous memory blocks of the sg list
28148c2ecf20Sopenharmony_ci * @sglist: sglist to iterate over
28158c2ecf20Sopenharmony_ci * @biter: block iterator holding the memory block
28168c2ecf20Sopenharmony_ci * @nents: maximum number of sg entries to iterate over
28178c2ecf20Sopenharmony_ci * @pgsz: best HW supported page size to use
28188c2ecf20Sopenharmony_ci *
28198c2ecf20Sopenharmony_ci * Callers may use rdma_block_iter_dma_address() to get each
28208c2ecf20Sopenharmony_ci * blocks aligned DMA address.
28218c2ecf20Sopenharmony_ci */
28228c2ecf20Sopenharmony_ci#define rdma_for_each_block(sglist, biter, nents, pgsz)		\
28238c2ecf20Sopenharmony_ci	for (__rdma_block_iter_start(biter, sglist, nents,	\
28248c2ecf20Sopenharmony_ci				     pgsz);			\
28258c2ecf20Sopenharmony_ci	     __rdma_block_iter_next(biter);)
28268c2ecf20Sopenharmony_ci
28278c2ecf20Sopenharmony_ci/**
28288c2ecf20Sopenharmony_ci * ib_get_client_data - Get IB client context
28298c2ecf20Sopenharmony_ci * @device:Device to get context for
28308c2ecf20Sopenharmony_ci * @client:Client to get context for
28318c2ecf20Sopenharmony_ci *
28328c2ecf20Sopenharmony_ci * ib_get_client_data() returns the client context data set with
28338c2ecf20Sopenharmony_ci * ib_set_client_data(). This can only be called while the client is
28348c2ecf20Sopenharmony_ci * registered to the device, once the ib_client remove() callback returns this
28358c2ecf20Sopenharmony_ci * cannot be called.
28368c2ecf20Sopenharmony_ci */
28378c2ecf20Sopenharmony_cistatic inline void *ib_get_client_data(struct ib_device *device,
28388c2ecf20Sopenharmony_ci				       struct ib_client *client)
28398c2ecf20Sopenharmony_ci{
28408c2ecf20Sopenharmony_ci	return xa_load(&device->client_data, client->client_id);
28418c2ecf20Sopenharmony_ci}
28428c2ecf20Sopenharmony_civoid  ib_set_client_data(struct ib_device *device, struct ib_client *client,
28438c2ecf20Sopenharmony_ci			 void *data);
28448c2ecf20Sopenharmony_civoid ib_set_device_ops(struct ib_device *device,
28458c2ecf20Sopenharmony_ci		       const struct ib_device_ops *ops);
28468c2ecf20Sopenharmony_ci
28478c2ecf20Sopenharmony_ciint rdma_user_mmap_io(struct ib_ucontext *ucontext, struct vm_area_struct *vma,
28488c2ecf20Sopenharmony_ci		      unsigned long pfn, unsigned long size, pgprot_t prot,
28498c2ecf20Sopenharmony_ci		      struct rdma_user_mmap_entry *entry);
28508c2ecf20Sopenharmony_ciint rdma_user_mmap_entry_insert(struct ib_ucontext *ucontext,
28518c2ecf20Sopenharmony_ci				struct rdma_user_mmap_entry *entry,
28528c2ecf20Sopenharmony_ci				size_t length);
28538c2ecf20Sopenharmony_ciint rdma_user_mmap_entry_insert_range(struct ib_ucontext *ucontext,
28548c2ecf20Sopenharmony_ci				      struct rdma_user_mmap_entry *entry,
28558c2ecf20Sopenharmony_ci				      size_t length, u32 min_pgoff,
28568c2ecf20Sopenharmony_ci				      u32 max_pgoff);
28578c2ecf20Sopenharmony_ci
28588c2ecf20Sopenharmony_cistruct rdma_user_mmap_entry *
28598c2ecf20Sopenharmony_cirdma_user_mmap_entry_get_pgoff(struct ib_ucontext *ucontext,
28608c2ecf20Sopenharmony_ci			       unsigned long pgoff);
28618c2ecf20Sopenharmony_cistruct rdma_user_mmap_entry *
28628c2ecf20Sopenharmony_cirdma_user_mmap_entry_get(struct ib_ucontext *ucontext,
28638c2ecf20Sopenharmony_ci			 struct vm_area_struct *vma);
28648c2ecf20Sopenharmony_civoid rdma_user_mmap_entry_put(struct rdma_user_mmap_entry *entry);
28658c2ecf20Sopenharmony_ci
28668c2ecf20Sopenharmony_civoid rdma_user_mmap_entry_remove(struct rdma_user_mmap_entry *entry);
28678c2ecf20Sopenharmony_ci
28688c2ecf20Sopenharmony_cistatic inline int ib_copy_from_udata(void *dest, struct ib_udata *udata, size_t len)
28698c2ecf20Sopenharmony_ci{
28708c2ecf20Sopenharmony_ci	return copy_from_user(dest, udata->inbuf, len) ? -EFAULT : 0;
28718c2ecf20Sopenharmony_ci}
28728c2ecf20Sopenharmony_ci
28738c2ecf20Sopenharmony_cistatic inline int ib_copy_to_udata(struct ib_udata *udata, void *src, size_t len)
28748c2ecf20Sopenharmony_ci{
28758c2ecf20Sopenharmony_ci	return copy_to_user(udata->outbuf, src, len) ? -EFAULT : 0;
28768c2ecf20Sopenharmony_ci}
28778c2ecf20Sopenharmony_ci
28788c2ecf20Sopenharmony_cistatic inline bool ib_is_buffer_cleared(const void __user *p,
28798c2ecf20Sopenharmony_ci					size_t len)
28808c2ecf20Sopenharmony_ci{
28818c2ecf20Sopenharmony_ci	bool ret;
28828c2ecf20Sopenharmony_ci	u8 *buf;
28838c2ecf20Sopenharmony_ci
28848c2ecf20Sopenharmony_ci	if (len > USHRT_MAX)
28858c2ecf20Sopenharmony_ci		return false;
28868c2ecf20Sopenharmony_ci
28878c2ecf20Sopenharmony_ci	buf = memdup_user(p, len);
28888c2ecf20Sopenharmony_ci	if (IS_ERR(buf))
28898c2ecf20Sopenharmony_ci		return false;
28908c2ecf20Sopenharmony_ci
28918c2ecf20Sopenharmony_ci	ret = !memchr_inv(buf, 0, len);
28928c2ecf20Sopenharmony_ci	kfree(buf);
28938c2ecf20Sopenharmony_ci	return ret;
28948c2ecf20Sopenharmony_ci}
28958c2ecf20Sopenharmony_ci
28968c2ecf20Sopenharmony_cistatic inline bool ib_is_udata_cleared(struct ib_udata *udata,
28978c2ecf20Sopenharmony_ci				       size_t offset,
28988c2ecf20Sopenharmony_ci				       size_t len)
28998c2ecf20Sopenharmony_ci{
29008c2ecf20Sopenharmony_ci	return ib_is_buffer_cleared(udata->inbuf + offset, len);
29018c2ecf20Sopenharmony_ci}
29028c2ecf20Sopenharmony_ci
29038c2ecf20Sopenharmony_ci/**
29048c2ecf20Sopenharmony_ci * ib_is_destroy_retryable - Check whether the uobject destruction
29058c2ecf20Sopenharmony_ci * is retryable.
29068c2ecf20Sopenharmony_ci * @ret: The initial destruction return code
29078c2ecf20Sopenharmony_ci * @why: remove reason
29088c2ecf20Sopenharmony_ci * @uobj: The uobject that is destroyed
29098c2ecf20Sopenharmony_ci *
29108c2ecf20Sopenharmony_ci * This function is a helper function that IB layer and low-level drivers
29118c2ecf20Sopenharmony_ci * can use to consider whether the destruction of the given uobject is
29128c2ecf20Sopenharmony_ci * retry-able.
29138c2ecf20Sopenharmony_ci * It checks the original return code, if it wasn't success the destruction
29148c2ecf20Sopenharmony_ci * is retryable according to the ucontext state (i.e. cleanup_retryable) and
29158c2ecf20Sopenharmony_ci * the remove reason. (i.e. why).
29168c2ecf20Sopenharmony_ci * Must be called with the object locked for destroy.
29178c2ecf20Sopenharmony_ci */
29188c2ecf20Sopenharmony_cistatic inline bool ib_is_destroy_retryable(int ret, enum rdma_remove_reason why,
29198c2ecf20Sopenharmony_ci					   struct ib_uobject *uobj)
29208c2ecf20Sopenharmony_ci{
29218c2ecf20Sopenharmony_ci	return ret && (why == RDMA_REMOVE_DESTROY ||
29228c2ecf20Sopenharmony_ci		       uobj->context->cleanup_retryable);
29238c2ecf20Sopenharmony_ci}
29248c2ecf20Sopenharmony_ci
29258c2ecf20Sopenharmony_ci/**
29268c2ecf20Sopenharmony_ci * ib_destroy_usecnt - Called during destruction to check the usecnt
29278c2ecf20Sopenharmony_ci * @usecnt: The usecnt atomic
29288c2ecf20Sopenharmony_ci * @why: remove reason
29298c2ecf20Sopenharmony_ci * @uobj: The uobject that is destroyed
29308c2ecf20Sopenharmony_ci *
29318c2ecf20Sopenharmony_ci * Non-zero usecnts will block destruction unless destruction was triggered by
29328c2ecf20Sopenharmony_ci * a ucontext cleanup.
29338c2ecf20Sopenharmony_ci */
29348c2ecf20Sopenharmony_cistatic inline int ib_destroy_usecnt(atomic_t *usecnt,
29358c2ecf20Sopenharmony_ci				    enum rdma_remove_reason why,
29368c2ecf20Sopenharmony_ci				    struct ib_uobject *uobj)
29378c2ecf20Sopenharmony_ci{
29388c2ecf20Sopenharmony_ci	if (atomic_read(usecnt) && ib_is_destroy_retryable(-EBUSY, why, uobj))
29398c2ecf20Sopenharmony_ci		return -EBUSY;
29408c2ecf20Sopenharmony_ci	return 0;
29418c2ecf20Sopenharmony_ci}
29428c2ecf20Sopenharmony_ci
29438c2ecf20Sopenharmony_ci/**
29448c2ecf20Sopenharmony_ci * ib_modify_qp_is_ok - Check that the supplied attribute mask
29458c2ecf20Sopenharmony_ci * contains all required attributes and no attributes not allowed for
29468c2ecf20Sopenharmony_ci * the given QP state transition.
29478c2ecf20Sopenharmony_ci * @cur_state: Current QP state
29488c2ecf20Sopenharmony_ci * @next_state: Next QP state
29498c2ecf20Sopenharmony_ci * @type: QP type
29508c2ecf20Sopenharmony_ci * @mask: Mask of supplied QP attributes
29518c2ecf20Sopenharmony_ci *
29528c2ecf20Sopenharmony_ci * This function is a helper function that a low-level driver's
29538c2ecf20Sopenharmony_ci * modify_qp method can use to validate the consumer's input.  It
29548c2ecf20Sopenharmony_ci * checks that cur_state and next_state are valid QP states, that a
29558c2ecf20Sopenharmony_ci * transition from cur_state to next_state is allowed by the IB spec,
29568c2ecf20Sopenharmony_ci * and that the attribute mask supplied is allowed for the transition.
29578c2ecf20Sopenharmony_ci */
29588c2ecf20Sopenharmony_cibool ib_modify_qp_is_ok(enum ib_qp_state cur_state, enum ib_qp_state next_state,
29598c2ecf20Sopenharmony_ci			enum ib_qp_type type, enum ib_qp_attr_mask mask);
29608c2ecf20Sopenharmony_ci
29618c2ecf20Sopenharmony_civoid ib_register_event_handler(struct ib_event_handler *event_handler);
29628c2ecf20Sopenharmony_civoid ib_unregister_event_handler(struct ib_event_handler *event_handler);
29638c2ecf20Sopenharmony_civoid ib_dispatch_event(const struct ib_event *event);
29648c2ecf20Sopenharmony_ci
29658c2ecf20Sopenharmony_ciint ib_query_port(struct ib_device *device,
29668c2ecf20Sopenharmony_ci		  u8 port_num, struct ib_port_attr *port_attr);
29678c2ecf20Sopenharmony_ci
29688c2ecf20Sopenharmony_cienum rdma_link_layer rdma_port_get_link_layer(struct ib_device *device,
29698c2ecf20Sopenharmony_ci					       u8 port_num);
29708c2ecf20Sopenharmony_ci
29718c2ecf20Sopenharmony_ci/**
29728c2ecf20Sopenharmony_ci * rdma_cap_ib_switch - Check if the device is IB switch
29738c2ecf20Sopenharmony_ci * @device: Device to check
29748c2ecf20Sopenharmony_ci *
29758c2ecf20Sopenharmony_ci * Device driver is responsible for setting is_switch bit on
29768c2ecf20Sopenharmony_ci * in ib_device structure at init time.
29778c2ecf20Sopenharmony_ci *
29788c2ecf20Sopenharmony_ci * Return: true if the device is IB switch.
29798c2ecf20Sopenharmony_ci */
29808c2ecf20Sopenharmony_cistatic inline bool rdma_cap_ib_switch(const struct ib_device *device)
29818c2ecf20Sopenharmony_ci{
29828c2ecf20Sopenharmony_ci	return device->is_switch;
29838c2ecf20Sopenharmony_ci}
29848c2ecf20Sopenharmony_ci
29858c2ecf20Sopenharmony_ci/**
29868c2ecf20Sopenharmony_ci * rdma_start_port - Return the first valid port number for the device
29878c2ecf20Sopenharmony_ci * specified
29888c2ecf20Sopenharmony_ci *
29898c2ecf20Sopenharmony_ci * @device: Device to be checked
29908c2ecf20Sopenharmony_ci *
29918c2ecf20Sopenharmony_ci * Return start port number
29928c2ecf20Sopenharmony_ci */
29938c2ecf20Sopenharmony_cistatic inline u8 rdma_start_port(const struct ib_device *device)
29948c2ecf20Sopenharmony_ci{
29958c2ecf20Sopenharmony_ci	return rdma_cap_ib_switch(device) ? 0 : 1;
29968c2ecf20Sopenharmony_ci}
29978c2ecf20Sopenharmony_ci
29988c2ecf20Sopenharmony_ci/**
29998c2ecf20Sopenharmony_ci * rdma_for_each_port - Iterate over all valid port numbers of the IB device
30008c2ecf20Sopenharmony_ci * @device - The struct ib_device * to iterate over
30018c2ecf20Sopenharmony_ci * @iter - The unsigned int to store the port number
30028c2ecf20Sopenharmony_ci */
30038c2ecf20Sopenharmony_ci#define rdma_for_each_port(device, iter)                                       \
30048c2ecf20Sopenharmony_ci	for (iter = rdma_start_port(device + BUILD_BUG_ON_ZERO(!__same_type(   \
30058c2ecf20Sopenharmony_ci						     unsigned int, iter)));    \
30068c2ecf20Sopenharmony_ci	     iter <= rdma_end_port(device); (iter)++)
30078c2ecf20Sopenharmony_ci
30088c2ecf20Sopenharmony_ci/**
30098c2ecf20Sopenharmony_ci * rdma_end_port - Return the last valid port number for the device
30108c2ecf20Sopenharmony_ci * specified
30118c2ecf20Sopenharmony_ci *
30128c2ecf20Sopenharmony_ci * @device: Device to be checked
30138c2ecf20Sopenharmony_ci *
30148c2ecf20Sopenharmony_ci * Return last port number
30158c2ecf20Sopenharmony_ci */
30168c2ecf20Sopenharmony_cistatic inline u8 rdma_end_port(const struct ib_device *device)
30178c2ecf20Sopenharmony_ci{
30188c2ecf20Sopenharmony_ci	return rdma_cap_ib_switch(device) ? 0 : device->phys_port_cnt;
30198c2ecf20Sopenharmony_ci}
30208c2ecf20Sopenharmony_ci
30218c2ecf20Sopenharmony_cistatic inline int rdma_is_port_valid(const struct ib_device *device,
30228c2ecf20Sopenharmony_ci				     unsigned int port)
30238c2ecf20Sopenharmony_ci{
30248c2ecf20Sopenharmony_ci	return (port >= rdma_start_port(device) &&
30258c2ecf20Sopenharmony_ci		port <= rdma_end_port(device));
30268c2ecf20Sopenharmony_ci}
30278c2ecf20Sopenharmony_ci
30288c2ecf20Sopenharmony_cistatic inline bool rdma_is_grh_required(const struct ib_device *device,
30298c2ecf20Sopenharmony_ci					u8 port_num)
30308c2ecf20Sopenharmony_ci{
30318c2ecf20Sopenharmony_ci	return device->port_data[port_num].immutable.core_cap_flags &
30328c2ecf20Sopenharmony_ci	       RDMA_CORE_PORT_IB_GRH_REQUIRED;
30338c2ecf20Sopenharmony_ci}
30348c2ecf20Sopenharmony_ci
30358c2ecf20Sopenharmony_cistatic inline bool rdma_protocol_ib(const struct ib_device *device, u8 port_num)
30368c2ecf20Sopenharmony_ci{
30378c2ecf20Sopenharmony_ci	return device->port_data[port_num].immutable.core_cap_flags &
30388c2ecf20Sopenharmony_ci	       RDMA_CORE_CAP_PROT_IB;
30398c2ecf20Sopenharmony_ci}
30408c2ecf20Sopenharmony_ci
30418c2ecf20Sopenharmony_cistatic inline bool rdma_protocol_roce(const struct ib_device *device, u8 port_num)
30428c2ecf20Sopenharmony_ci{
30438c2ecf20Sopenharmony_ci	return device->port_data[port_num].immutable.core_cap_flags &
30448c2ecf20Sopenharmony_ci	       (RDMA_CORE_CAP_PROT_ROCE | RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP);
30458c2ecf20Sopenharmony_ci}
30468c2ecf20Sopenharmony_ci
30478c2ecf20Sopenharmony_cistatic inline bool rdma_protocol_roce_udp_encap(const struct ib_device *device, u8 port_num)
30488c2ecf20Sopenharmony_ci{
30498c2ecf20Sopenharmony_ci	return device->port_data[port_num].immutable.core_cap_flags &
30508c2ecf20Sopenharmony_ci	       RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP;
30518c2ecf20Sopenharmony_ci}
30528c2ecf20Sopenharmony_ci
30538c2ecf20Sopenharmony_cistatic inline bool rdma_protocol_roce_eth_encap(const struct ib_device *device, u8 port_num)
30548c2ecf20Sopenharmony_ci{
30558c2ecf20Sopenharmony_ci	return device->port_data[port_num].immutable.core_cap_flags &
30568c2ecf20Sopenharmony_ci	       RDMA_CORE_CAP_PROT_ROCE;
30578c2ecf20Sopenharmony_ci}
30588c2ecf20Sopenharmony_ci
30598c2ecf20Sopenharmony_cistatic inline bool rdma_protocol_iwarp(const struct ib_device *device, u8 port_num)
30608c2ecf20Sopenharmony_ci{
30618c2ecf20Sopenharmony_ci	return device->port_data[port_num].immutable.core_cap_flags &
30628c2ecf20Sopenharmony_ci	       RDMA_CORE_CAP_PROT_IWARP;
30638c2ecf20Sopenharmony_ci}
30648c2ecf20Sopenharmony_ci
30658c2ecf20Sopenharmony_cistatic inline bool rdma_ib_or_roce(const struct ib_device *device, u8 port_num)
30668c2ecf20Sopenharmony_ci{
30678c2ecf20Sopenharmony_ci	return rdma_protocol_ib(device, port_num) ||
30688c2ecf20Sopenharmony_ci		rdma_protocol_roce(device, port_num);
30698c2ecf20Sopenharmony_ci}
30708c2ecf20Sopenharmony_ci
30718c2ecf20Sopenharmony_cistatic inline bool rdma_protocol_raw_packet(const struct ib_device *device, u8 port_num)
30728c2ecf20Sopenharmony_ci{
30738c2ecf20Sopenharmony_ci	return device->port_data[port_num].immutable.core_cap_flags &
30748c2ecf20Sopenharmony_ci	       RDMA_CORE_CAP_PROT_RAW_PACKET;
30758c2ecf20Sopenharmony_ci}
30768c2ecf20Sopenharmony_ci
30778c2ecf20Sopenharmony_cistatic inline bool rdma_protocol_usnic(const struct ib_device *device, u8 port_num)
30788c2ecf20Sopenharmony_ci{
30798c2ecf20Sopenharmony_ci	return device->port_data[port_num].immutable.core_cap_flags &
30808c2ecf20Sopenharmony_ci	       RDMA_CORE_CAP_PROT_USNIC;
30818c2ecf20Sopenharmony_ci}
30828c2ecf20Sopenharmony_ci
30838c2ecf20Sopenharmony_ci/**
30848c2ecf20Sopenharmony_ci * rdma_cap_ib_mad - Check if the port of a device supports Infiniband
30858c2ecf20Sopenharmony_ci * Management Datagrams.
30868c2ecf20Sopenharmony_ci * @device: Device to check
30878c2ecf20Sopenharmony_ci * @port_num: Port number to check
30888c2ecf20Sopenharmony_ci *
30898c2ecf20Sopenharmony_ci * Management Datagrams (MAD) are a required part of the InfiniBand
30908c2ecf20Sopenharmony_ci * specification and are supported on all InfiniBand devices.  A slightly
30918c2ecf20Sopenharmony_ci * extended version are also supported on OPA interfaces.
30928c2ecf20Sopenharmony_ci *
30938c2ecf20Sopenharmony_ci * Return: true if the port supports sending/receiving of MAD packets.
30948c2ecf20Sopenharmony_ci */
30958c2ecf20Sopenharmony_cistatic inline bool rdma_cap_ib_mad(const struct ib_device *device, u8 port_num)
30968c2ecf20Sopenharmony_ci{
30978c2ecf20Sopenharmony_ci	return device->port_data[port_num].immutable.core_cap_flags &
30988c2ecf20Sopenharmony_ci	       RDMA_CORE_CAP_IB_MAD;
30998c2ecf20Sopenharmony_ci}
31008c2ecf20Sopenharmony_ci
31018c2ecf20Sopenharmony_ci/**
31028c2ecf20Sopenharmony_ci * rdma_cap_opa_mad - Check if the port of device provides support for OPA
31038c2ecf20Sopenharmony_ci * Management Datagrams.
31048c2ecf20Sopenharmony_ci * @device: Device to check
31058c2ecf20Sopenharmony_ci * @port_num: Port number to check
31068c2ecf20Sopenharmony_ci *
31078c2ecf20Sopenharmony_ci * Intel OmniPath devices extend and/or replace the InfiniBand Management
31088c2ecf20Sopenharmony_ci * datagrams with their own versions.  These OPA MADs share many but not all of
31098c2ecf20Sopenharmony_ci * the characteristics of InfiniBand MADs.
31108c2ecf20Sopenharmony_ci *
31118c2ecf20Sopenharmony_ci * OPA MADs differ in the following ways:
31128c2ecf20Sopenharmony_ci *
31138c2ecf20Sopenharmony_ci *    1) MADs are variable size up to 2K
31148c2ecf20Sopenharmony_ci *       IBTA defined MADs remain fixed at 256 bytes
31158c2ecf20Sopenharmony_ci *    2) OPA SMPs must carry valid PKeys
31168c2ecf20Sopenharmony_ci *    3) OPA SMP packets are a different format
31178c2ecf20Sopenharmony_ci *
31188c2ecf20Sopenharmony_ci * Return: true if the port supports OPA MAD packet formats.
31198c2ecf20Sopenharmony_ci */
31208c2ecf20Sopenharmony_cistatic inline bool rdma_cap_opa_mad(struct ib_device *device, u8 port_num)
31218c2ecf20Sopenharmony_ci{
31228c2ecf20Sopenharmony_ci	return device->port_data[port_num].immutable.core_cap_flags &
31238c2ecf20Sopenharmony_ci		RDMA_CORE_CAP_OPA_MAD;
31248c2ecf20Sopenharmony_ci}
31258c2ecf20Sopenharmony_ci
31268c2ecf20Sopenharmony_ci/**
31278c2ecf20Sopenharmony_ci * rdma_cap_ib_smi - Check if the port of a device provides an Infiniband
31288c2ecf20Sopenharmony_ci * Subnet Management Agent (SMA) on the Subnet Management Interface (SMI).
31298c2ecf20Sopenharmony_ci * @device: Device to check
31308c2ecf20Sopenharmony_ci * @port_num: Port number to check
31318c2ecf20Sopenharmony_ci *
31328c2ecf20Sopenharmony_ci * Each InfiniBand node is required to provide a Subnet Management Agent
31338c2ecf20Sopenharmony_ci * that the subnet manager can access.  Prior to the fabric being fully
31348c2ecf20Sopenharmony_ci * configured by the subnet manager, the SMA is accessed via a well known
31358c2ecf20Sopenharmony_ci * interface called the Subnet Management Interface (SMI).  This interface
31368c2ecf20Sopenharmony_ci * uses directed route packets to communicate with the SM to get around the
31378c2ecf20Sopenharmony_ci * chicken and egg problem of the SM needing to know what's on the fabric
31388c2ecf20Sopenharmony_ci * in order to configure the fabric, and needing to configure the fabric in
31398c2ecf20Sopenharmony_ci * order to send packets to the devices on the fabric.  These directed
31408c2ecf20Sopenharmony_ci * route packets do not need the fabric fully configured in order to reach
31418c2ecf20Sopenharmony_ci * their destination.  The SMI is the only method allowed to send
31428c2ecf20Sopenharmony_ci * directed route packets on an InfiniBand fabric.
31438c2ecf20Sopenharmony_ci *
31448c2ecf20Sopenharmony_ci * Return: true if the port provides an SMI.
31458c2ecf20Sopenharmony_ci */
31468c2ecf20Sopenharmony_cistatic inline bool rdma_cap_ib_smi(const struct ib_device *device, u8 port_num)
31478c2ecf20Sopenharmony_ci{
31488c2ecf20Sopenharmony_ci	return device->port_data[port_num].immutable.core_cap_flags &
31498c2ecf20Sopenharmony_ci	       RDMA_CORE_CAP_IB_SMI;
31508c2ecf20Sopenharmony_ci}
31518c2ecf20Sopenharmony_ci
31528c2ecf20Sopenharmony_ci/**
31538c2ecf20Sopenharmony_ci * rdma_cap_ib_cm - Check if the port of device has the capability Infiniband
31548c2ecf20Sopenharmony_ci * Communication Manager.
31558c2ecf20Sopenharmony_ci * @device: Device to check
31568c2ecf20Sopenharmony_ci * @port_num: Port number to check
31578c2ecf20Sopenharmony_ci *
31588c2ecf20Sopenharmony_ci * The InfiniBand Communication Manager is one of many pre-defined General
31598c2ecf20Sopenharmony_ci * Service Agents (GSA) that are accessed via the General Service
31608c2ecf20Sopenharmony_ci * Interface (GSI).  It's role is to facilitate establishment of connections
31618c2ecf20Sopenharmony_ci * between nodes as well as other management related tasks for established
31628c2ecf20Sopenharmony_ci * connections.
31638c2ecf20Sopenharmony_ci *
31648c2ecf20Sopenharmony_ci * Return: true if the port supports an IB CM (this does not guarantee that
31658c2ecf20Sopenharmony_ci * a CM is actually running however).
31668c2ecf20Sopenharmony_ci */
31678c2ecf20Sopenharmony_cistatic inline bool rdma_cap_ib_cm(const struct ib_device *device, u8 port_num)
31688c2ecf20Sopenharmony_ci{
31698c2ecf20Sopenharmony_ci	return device->port_data[port_num].immutable.core_cap_flags &
31708c2ecf20Sopenharmony_ci	       RDMA_CORE_CAP_IB_CM;
31718c2ecf20Sopenharmony_ci}
31728c2ecf20Sopenharmony_ci
31738c2ecf20Sopenharmony_ci/**
31748c2ecf20Sopenharmony_ci * rdma_cap_iw_cm - Check if the port of device has the capability IWARP
31758c2ecf20Sopenharmony_ci * Communication Manager.
31768c2ecf20Sopenharmony_ci * @device: Device to check
31778c2ecf20Sopenharmony_ci * @port_num: Port number to check
31788c2ecf20Sopenharmony_ci *
31798c2ecf20Sopenharmony_ci * Similar to above, but specific to iWARP connections which have a different
31808c2ecf20Sopenharmony_ci * managment protocol than InfiniBand.
31818c2ecf20Sopenharmony_ci *
31828c2ecf20Sopenharmony_ci * Return: true if the port supports an iWARP CM (this does not guarantee that
31838c2ecf20Sopenharmony_ci * a CM is actually running however).
31848c2ecf20Sopenharmony_ci */
31858c2ecf20Sopenharmony_cistatic inline bool rdma_cap_iw_cm(const struct ib_device *device, u8 port_num)
31868c2ecf20Sopenharmony_ci{
31878c2ecf20Sopenharmony_ci	return device->port_data[port_num].immutable.core_cap_flags &
31888c2ecf20Sopenharmony_ci	       RDMA_CORE_CAP_IW_CM;
31898c2ecf20Sopenharmony_ci}
31908c2ecf20Sopenharmony_ci
31918c2ecf20Sopenharmony_ci/**
31928c2ecf20Sopenharmony_ci * rdma_cap_ib_sa - Check if the port of device has the capability Infiniband
31938c2ecf20Sopenharmony_ci * Subnet Administration.
31948c2ecf20Sopenharmony_ci * @device: Device to check
31958c2ecf20Sopenharmony_ci * @port_num: Port number to check
31968c2ecf20Sopenharmony_ci *
31978c2ecf20Sopenharmony_ci * An InfiniBand Subnet Administration (SA) service is a pre-defined General
31988c2ecf20Sopenharmony_ci * Service Agent (GSA) provided by the Subnet Manager (SM).  On InfiniBand
31998c2ecf20Sopenharmony_ci * fabrics, devices should resolve routes to other hosts by contacting the
32008c2ecf20Sopenharmony_ci * SA to query the proper route.
32018c2ecf20Sopenharmony_ci *
32028c2ecf20Sopenharmony_ci * Return: true if the port should act as a client to the fabric Subnet
32038c2ecf20Sopenharmony_ci * Administration interface.  This does not imply that the SA service is
32048c2ecf20Sopenharmony_ci * running locally.
32058c2ecf20Sopenharmony_ci */
32068c2ecf20Sopenharmony_cistatic inline bool rdma_cap_ib_sa(const struct ib_device *device, u8 port_num)
32078c2ecf20Sopenharmony_ci{
32088c2ecf20Sopenharmony_ci	return device->port_data[port_num].immutable.core_cap_flags &
32098c2ecf20Sopenharmony_ci	       RDMA_CORE_CAP_IB_SA;
32108c2ecf20Sopenharmony_ci}
32118c2ecf20Sopenharmony_ci
32128c2ecf20Sopenharmony_ci/**
32138c2ecf20Sopenharmony_ci * rdma_cap_ib_mcast - Check if the port of device has the capability Infiniband
32148c2ecf20Sopenharmony_ci * Multicast.
32158c2ecf20Sopenharmony_ci * @device: Device to check
32168c2ecf20Sopenharmony_ci * @port_num: Port number to check
32178c2ecf20Sopenharmony_ci *
32188c2ecf20Sopenharmony_ci * InfiniBand multicast registration is more complex than normal IPv4 or
32198c2ecf20Sopenharmony_ci * IPv6 multicast registration.  Each Host Channel Adapter must register
32208c2ecf20Sopenharmony_ci * with the Subnet Manager when it wishes to join a multicast group.  It
32218c2ecf20Sopenharmony_ci * should do so only once regardless of how many queue pairs it subscribes
32228c2ecf20Sopenharmony_ci * to this group.  And it should leave the group only after all queue pairs
32238c2ecf20Sopenharmony_ci * attached to the group have been detached.
32248c2ecf20Sopenharmony_ci *
32258c2ecf20Sopenharmony_ci * Return: true if the port must undertake the additional adminstrative
32268c2ecf20Sopenharmony_ci * overhead of registering/unregistering with the SM and tracking of the
32278c2ecf20Sopenharmony_ci * total number of queue pairs attached to the multicast group.
32288c2ecf20Sopenharmony_ci */
32298c2ecf20Sopenharmony_cistatic inline bool rdma_cap_ib_mcast(const struct ib_device *device, u8 port_num)
32308c2ecf20Sopenharmony_ci{
32318c2ecf20Sopenharmony_ci	return rdma_cap_ib_sa(device, port_num);
32328c2ecf20Sopenharmony_ci}
32338c2ecf20Sopenharmony_ci
32348c2ecf20Sopenharmony_ci/**
32358c2ecf20Sopenharmony_ci * rdma_cap_af_ib - Check if the port of device has the capability
32368c2ecf20Sopenharmony_ci * Native Infiniband Address.
32378c2ecf20Sopenharmony_ci * @device: Device to check
32388c2ecf20Sopenharmony_ci * @port_num: Port number to check
32398c2ecf20Sopenharmony_ci *
32408c2ecf20Sopenharmony_ci * InfiniBand addressing uses a port's GUID + Subnet Prefix to make a default
32418c2ecf20Sopenharmony_ci * GID.  RoCE uses a different mechanism, but still generates a GID via
32428c2ecf20Sopenharmony_ci * a prescribed mechanism and port specific data.
32438c2ecf20Sopenharmony_ci *
32448c2ecf20Sopenharmony_ci * Return: true if the port uses a GID address to identify devices on the
32458c2ecf20Sopenharmony_ci * network.
32468c2ecf20Sopenharmony_ci */
32478c2ecf20Sopenharmony_cistatic inline bool rdma_cap_af_ib(const struct ib_device *device, u8 port_num)
32488c2ecf20Sopenharmony_ci{
32498c2ecf20Sopenharmony_ci	return device->port_data[port_num].immutable.core_cap_flags &
32508c2ecf20Sopenharmony_ci	       RDMA_CORE_CAP_AF_IB;
32518c2ecf20Sopenharmony_ci}
32528c2ecf20Sopenharmony_ci
32538c2ecf20Sopenharmony_ci/**
32548c2ecf20Sopenharmony_ci * rdma_cap_eth_ah - Check if the port of device has the capability
32558c2ecf20Sopenharmony_ci * Ethernet Address Handle.
32568c2ecf20Sopenharmony_ci * @device: Device to check
32578c2ecf20Sopenharmony_ci * @port_num: Port number to check
32588c2ecf20Sopenharmony_ci *
32598c2ecf20Sopenharmony_ci * RoCE is InfiniBand over Ethernet, and it uses a well defined technique
32608c2ecf20Sopenharmony_ci * to fabricate GIDs over Ethernet/IP specific addresses native to the
32618c2ecf20Sopenharmony_ci * port.  Normally, packet headers are generated by the sending host
32628c2ecf20Sopenharmony_ci * adapter, but when sending connectionless datagrams, we must manually
32638c2ecf20Sopenharmony_ci * inject the proper headers for the fabric we are communicating over.
32648c2ecf20Sopenharmony_ci *
32658c2ecf20Sopenharmony_ci * Return: true if we are running as a RoCE port and must force the
32668c2ecf20Sopenharmony_ci * addition of a Global Route Header built from our Ethernet Address
32678c2ecf20Sopenharmony_ci * Handle into our header list for connectionless packets.
32688c2ecf20Sopenharmony_ci */
32698c2ecf20Sopenharmony_cistatic inline bool rdma_cap_eth_ah(const struct ib_device *device, u8 port_num)
32708c2ecf20Sopenharmony_ci{
32718c2ecf20Sopenharmony_ci	return device->port_data[port_num].immutable.core_cap_flags &
32728c2ecf20Sopenharmony_ci	       RDMA_CORE_CAP_ETH_AH;
32738c2ecf20Sopenharmony_ci}
32748c2ecf20Sopenharmony_ci
32758c2ecf20Sopenharmony_ci/**
32768c2ecf20Sopenharmony_ci * rdma_cap_opa_ah - Check if the port of device supports
32778c2ecf20Sopenharmony_ci * OPA Address handles
32788c2ecf20Sopenharmony_ci * @device: Device to check
32798c2ecf20Sopenharmony_ci * @port_num: Port number to check
32808c2ecf20Sopenharmony_ci *
32818c2ecf20Sopenharmony_ci * Return: true if we are running on an OPA device which supports
32828c2ecf20Sopenharmony_ci * the extended OPA addressing.
32838c2ecf20Sopenharmony_ci */
32848c2ecf20Sopenharmony_cistatic inline bool rdma_cap_opa_ah(struct ib_device *device, u8 port_num)
32858c2ecf20Sopenharmony_ci{
32868c2ecf20Sopenharmony_ci	return (device->port_data[port_num].immutable.core_cap_flags &
32878c2ecf20Sopenharmony_ci		RDMA_CORE_CAP_OPA_AH) == RDMA_CORE_CAP_OPA_AH;
32888c2ecf20Sopenharmony_ci}
32898c2ecf20Sopenharmony_ci
32908c2ecf20Sopenharmony_ci/**
32918c2ecf20Sopenharmony_ci * rdma_max_mad_size - Return the max MAD size required by this RDMA Port.
32928c2ecf20Sopenharmony_ci *
32938c2ecf20Sopenharmony_ci * @device: Device
32948c2ecf20Sopenharmony_ci * @port_num: Port number
32958c2ecf20Sopenharmony_ci *
32968c2ecf20Sopenharmony_ci * This MAD size includes the MAD headers and MAD payload.  No other headers
32978c2ecf20Sopenharmony_ci * are included.
32988c2ecf20Sopenharmony_ci *
32998c2ecf20Sopenharmony_ci * Return the max MAD size required by the Port.  Will return 0 if the port
33008c2ecf20Sopenharmony_ci * does not support MADs
33018c2ecf20Sopenharmony_ci */
33028c2ecf20Sopenharmony_cistatic inline size_t rdma_max_mad_size(const struct ib_device *device, u8 port_num)
33038c2ecf20Sopenharmony_ci{
33048c2ecf20Sopenharmony_ci	return device->port_data[port_num].immutable.max_mad_size;
33058c2ecf20Sopenharmony_ci}
33068c2ecf20Sopenharmony_ci
33078c2ecf20Sopenharmony_ci/**
33088c2ecf20Sopenharmony_ci * rdma_cap_roce_gid_table - Check if the port of device uses roce_gid_table
33098c2ecf20Sopenharmony_ci * @device: Device to check
33108c2ecf20Sopenharmony_ci * @port_num: Port number to check
33118c2ecf20Sopenharmony_ci *
33128c2ecf20Sopenharmony_ci * RoCE GID table mechanism manages the various GIDs for a device.
33138c2ecf20Sopenharmony_ci *
33148c2ecf20Sopenharmony_ci * NOTE: if allocating the port's GID table has failed, this call will still
33158c2ecf20Sopenharmony_ci * return true, but any RoCE GID table API will fail.
33168c2ecf20Sopenharmony_ci *
33178c2ecf20Sopenharmony_ci * Return: true if the port uses RoCE GID table mechanism in order to manage
33188c2ecf20Sopenharmony_ci * its GIDs.
33198c2ecf20Sopenharmony_ci */
33208c2ecf20Sopenharmony_cistatic inline bool rdma_cap_roce_gid_table(const struct ib_device *device,
33218c2ecf20Sopenharmony_ci					   u8 port_num)
33228c2ecf20Sopenharmony_ci{
33238c2ecf20Sopenharmony_ci	return rdma_protocol_roce(device, port_num) &&
33248c2ecf20Sopenharmony_ci		device->ops.add_gid && device->ops.del_gid;
33258c2ecf20Sopenharmony_ci}
33268c2ecf20Sopenharmony_ci
33278c2ecf20Sopenharmony_ci/*
33288c2ecf20Sopenharmony_ci * Check if the device supports READ W/ INVALIDATE.
33298c2ecf20Sopenharmony_ci */
33308c2ecf20Sopenharmony_cistatic inline bool rdma_cap_read_inv(struct ib_device *dev, u32 port_num)
33318c2ecf20Sopenharmony_ci{
33328c2ecf20Sopenharmony_ci	/*
33338c2ecf20Sopenharmony_ci	 * iWarp drivers must support READ W/ INVALIDATE.  No other protocol
33348c2ecf20Sopenharmony_ci	 * has support for it yet.
33358c2ecf20Sopenharmony_ci	 */
33368c2ecf20Sopenharmony_ci	return rdma_protocol_iwarp(dev, port_num);
33378c2ecf20Sopenharmony_ci}
33388c2ecf20Sopenharmony_ci
33398c2ecf20Sopenharmony_ci/**
33408c2ecf20Sopenharmony_ci * rdma_core_cap_opa_port - Return whether the RDMA Port is OPA or not.
33418c2ecf20Sopenharmony_ci * @device: Device
33428c2ecf20Sopenharmony_ci * @port_num: 1 based Port number
33438c2ecf20Sopenharmony_ci *
33448c2ecf20Sopenharmony_ci * Return true if port is an Intel OPA port , false if not
33458c2ecf20Sopenharmony_ci */
33468c2ecf20Sopenharmony_cistatic inline bool rdma_core_cap_opa_port(struct ib_device *device,
33478c2ecf20Sopenharmony_ci					  u32 port_num)
33488c2ecf20Sopenharmony_ci{
33498c2ecf20Sopenharmony_ci	return (device->port_data[port_num].immutable.core_cap_flags &
33508c2ecf20Sopenharmony_ci		RDMA_CORE_PORT_INTEL_OPA) == RDMA_CORE_PORT_INTEL_OPA;
33518c2ecf20Sopenharmony_ci}
33528c2ecf20Sopenharmony_ci
33538c2ecf20Sopenharmony_ci/**
33548c2ecf20Sopenharmony_ci * rdma_mtu_enum_to_int - Return the mtu of the port as an integer value.
33558c2ecf20Sopenharmony_ci * @device: Device
33568c2ecf20Sopenharmony_ci * @port_num: Port number
33578c2ecf20Sopenharmony_ci * @mtu: enum value of MTU
33588c2ecf20Sopenharmony_ci *
33598c2ecf20Sopenharmony_ci * Return the MTU size supported by the port as an integer value. Will return
33608c2ecf20Sopenharmony_ci * -1 if enum value of mtu is not supported.
33618c2ecf20Sopenharmony_ci */
33628c2ecf20Sopenharmony_cistatic inline int rdma_mtu_enum_to_int(struct ib_device *device, u8 port,
33638c2ecf20Sopenharmony_ci				       int mtu)
33648c2ecf20Sopenharmony_ci{
33658c2ecf20Sopenharmony_ci	if (rdma_core_cap_opa_port(device, port))
33668c2ecf20Sopenharmony_ci		return opa_mtu_enum_to_int((enum opa_mtu)mtu);
33678c2ecf20Sopenharmony_ci	else
33688c2ecf20Sopenharmony_ci		return ib_mtu_enum_to_int((enum ib_mtu)mtu);
33698c2ecf20Sopenharmony_ci}
33708c2ecf20Sopenharmony_ci
33718c2ecf20Sopenharmony_ci/**
33728c2ecf20Sopenharmony_ci * rdma_mtu_from_attr - Return the mtu of the port from the port attribute.
33738c2ecf20Sopenharmony_ci * @device: Device
33748c2ecf20Sopenharmony_ci * @port_num: Port number
33758c2ecf20Sopenharmony_ci * @attr: port attribute
33768c2ecf20Sopenharmony_ci *
33778c2ecf20Sopenharmony_ci * Return the MTU size supported by the port as an integer value.
33788c2ecf20Sopenharmony_ci */
33798c2ecf20Sopenharmony_cistatic inline int rdma_mtu_from_attr(struct ib_device *device, u8 port,
33808c2ecf20Sopenharmony_ci				     struct ib_port_attr *attr)
33818c2ecf20Sopenharmony_ci{
33828c2ecf20Sopenharmony_ci	if (rdma_core_cap_opa_port(device, port))
33838c2ecf20Sopenharmony_ci		return attr->phys_mtu;
33848c2ecf20Sopenharmony_ci	else
33858c2ecf20Sopenharmony_ci		return ib_mtu_enum_to_int(attr->max_mtu);
33868c2ecf20Sopenharmony_ci}
33878c2ecf20Sopenharmony_ci
33888c2ecf20Sopenharmony_ciint ib_set_vf_link_state(struct ib_device *device, int vf, u8 port,
33898c2ecf20Sopenharmony_ci			 int state);
33908c2ecf20Sopenharmony_ciint ib_get_vf_config(struct ib_device *device, int vf, u8 port,
33918c2ecf20Sopenharmony_ci		     struct ifla_vf_info *info);
33928c2ecf20Sopenharmony_ciint ib_get_vf_stats(struct ib_device *device, int vf, u8 port,
33938c2ecf20Sopenharmony_ci		    struct ifla_vf_stats *stats);
33948c2ecf20Sopenharmony_ciint ib_get_vf_guid(struct ib_device *device, int vf, u8 port,
33958c2ecf20Sopenharmony_ci		    struct ifla_vf_guid *node_guid,
33968c2ecf20Sopenharmony_ci		    struct ifla_vf_guid *port_guid);
33978c2ecf20Sopenharmony_ciint ib_set_vf_guid(struct ib_device *device, int vf, u8 port, u64 guid,
33988c2ecf20Sopenharmony_ci		   int type);
33998c2ecf20Sopenharmony_ci
34008c2ecf20Sopenharmony_ciint ib_query_pkey(struct ib_device *device,
34018c2ecf20Sopenharmony_ci		  u8 port_num, u16 index, u16 *pkey);
34028c2ecf20Sopenharmony_ci
34038c2ecf20Sopenharmony_ciint ib_modify_device(struct ib_device *device,
34048c2ecf20Sopenharmony_ci		     int device_modify_mask,
34058c2ecf20Sopenharmony_ci		     struct ib_device_modify *device_modify);
34068c2ecf20Sopenharmony_ci
34078c2ecf20Sopenharmony_ciint ib_modify_port(struct ib_device *device,
34088c2ecf20Sopenharmony_ci		   u8 port_num, int port_modify_mask,
34098c2ecf20Sopenharmony_ci		   struct ib_port_modify *port_modify);
34108c2ecf20Sopenharmony_ci
34118c2ecf20Sopenharmony_ciint ib_find_gid(struct ib_device *device, union ib_gid *gid,
34128c2ecf20Sopenharmony_ci		u8 *port_num, u16 *index);
34138c2ecf20Sopenharmony_ci
34148c2ecf20Sopenharmony_ciint ib_find_pkey(struct ib_device *device,
34158c2ecf20Sopenharmony_ci		 u8 port_num, u16 pkey, u16 *index);
34168c2ecf20Sopenharmony_ci
34178c2ecf20Sopenharmony_cienum ib_pd_flags {
34188c2ecf20Sopenharmony_ci	/*
34198c2ecf20Sopenharmony_ci	 * Create a memory registration for all memory in the system and place
34208c2ecf20Sopenharmony_ci	 * the rkey for it into pd->unsafe_global_rkey.  This can be used by
34218c2ecf20Sopenharmony_ci	 * ULPs to avoid the overhead of dynamic MRs.
34228c2ecf20Sopenharmony_ci	 *
34238c2ecf20Sopenharmony_ci	 * This flag is generally considered unsafe and must only be used in
34248c2ecf20Sopenharmony_ci	 * extremly trusted environments.  Every use of it will log a warning
34258c2ecf20Sopenharmony_ci	 * in the kernel log.
34268c2ecf20Sopenharmony_ci	 */
34278c2ecf20Sopenharmony_ci	IB_PD_UNSAFE_GLOBAL_RKEY	= 0x01,
34288c2ecf20Sopenharmony_ci};
34298c2ecf20Sopenharmony_ci
34308c2ecf20Sopenharmony_cistruct ib_pd *__ib_alloc_pd(struct ib_device *device, unsigned int flags,
34318c2ecf20Sopenharmony_ci		const char *caller);
34328c2ecf20Sopenharmony_ci
34338c2ecf20Sopenharmony_ci#define ib_alloc_pd(device, flags) \
34348c2ecf20Sopenharmony_ci	__ib_alloc_pd((device), (flags), KBUILD_MODNAME)
34358c2ecf20Sopenharmony_ci
34368c2ecf20Sopenharmony_ciint ib_dealloc_pd_user(struct ib_pd *pd, struct ib_udata *udata);
34378c2ecf20Sopenharmony_ci
34388c2ecf20Sopenharmony_ci/**
34398c2ecf20Sopenharmony_ci * ib_dealloc_pd - Deallocate kernel PD
34408c2ecf20Sopenharmony_ci * @pd: The protection domain
34418c2ecf20Sopenharmony_ci *
34428c2ecf20Sopenharmony_ci * NOTE: for user PD use ib_dealloc_pd_user with valid udata!
34438c2ecf20Sopenharmony_ci */
34448c2ecf20Sopenharmony_cistatic inline void ib_dealloc_pd(struct ib_pd *pd)
34458c2ecf20Sopenharmony_ci{
34468c2ecf20Sopenharmony_ci	int ret = ib_dealloc_pd_user(pd, NULL);
34478c2ecf20Sopenharmony_ci
34488c2ecf20Sopenharmony_ci	WARN_ONCE(ret, "Destroy of kernel PD shouldn't fail");
34498c2ecf20Sopenharmony_ci}
34508c2ecf20Sopenharmony_ci
34518c2ecf20Sopenharmony_cienum rdma_create_ah_flags {
34528c2ecf20Sopenharmony_ci	/* In a sleepable context */
34538c2ecf20Sopenharmony_ci	RDMA_CREATE_AH_SLEEPABLE = BIT(0),
34548c2ecf20Sopenharmony_ci};
34558c2ecf20Sopenharmony_ci
34568c2ecf20Sopenharmony_ci/**
34578c2ecf20Sopenharmony_ci * rdma_create_ah - Creates an address handle for the given address vector.
34588c2ecf20Sopenharmony_ci * @pd: The protection domain associated with the address handle.
34598c2ecf20Sopenharmony_ci * @ah_attr: The attributes of the address vector.
34608c2ecf20Sopenharmony_ci * @flags: Create address handle flags (see enum rdma_create_ah_flags).
34618c2ecf20Sopenharmony_ci *
34628c2ecf20Sopenharmony_ci * The address handle is used to reference a local or global destination
34638c2ecf20Sopenharmony_ci * in all UD QP post sends.
34648c2ecf20Sopenharmony_ci */
34658c2ecf20Sopenharmony_cistruct ib_ah *rdma_create_ah(struct ib_pd *pd, struct rdma_ah_attr *ah_attr,
34668c2ecf20Sopenharmony_ci			     u32 flags);
34678c2ecf20Sopenharmony_ci
34688c2ecf20Sopenharmony_ci/**
34698c2ecf20Sopenharmony_ci * rdma_create_user_ah - Creates an address handle for the given address vector.
34708c2ecf20Sopenharmony_ci * It resolves destination mac address for ah attribute of RoCE type.
34718c2ecf20Sopenharmony_ci * @pd: The protection domain associated with the address handle.
34728c2ecf20Sopenharmony_ci * @ah_attr: The attributes of the address vector.
34738c2ecf20Sopenharmony_ci * @udata: pointer to user's input output buffer information need by
34748c2ecf20Sopenharmony_ci *         provider driver.
34758c2ecf20Sopenharmony_ci *
34768c2ecf20Sopenharmony_ci * It returns 0 on success and returns appropriate error code on error.
34778c2ecf20Sopenharmony_ci * The address handle is used to reference a local or global destination
34788c2ecf20Sopenharmony_ci * in all UD QP post sends.
34798c2ecf20Sopenharmony_ci */
34808c2ecf20Sopenharmony_cistruct ib_ah *rdma_create_user_ah(struct ib_pd *pd,
34818c2ecf20Sopenharmony_ci				  struct rdma_ah_attr *ah_attr,
34828c2ecf20Sopenharmony_ci				  struct ib_udata *udata);
34838c2ecf20Sopenharmony_ci/**
34848c2ecf20Sopenharmony_ci * ib_get_gids_from_rdma_hdr - Get sgid and dgid from GRH or IPv4 header
34858c2ecf20Sopenharmony_ci *   work completion.
34868c2ecf20Sopenharmony_ci * @hdr: the L3 header to parse
34878c2ecf20Sopenharmony_ci * @net_type: type of header to parse
34888c2ecf20Sopenharmony_ci * @sgid: place to store source gid
34898c2ecf20Sopenharmony_ci * @dgid: place to store destination gid
34908c2ecf20Sopenharmony_ci */
34918c2ecf20Sopenharmony_ciint ib_get_gids_from_rdma_hdr(const union rdma_network_hdr *hdr,
34928c2ecf20Sopenharmony_ci			      enum rdma_network_type net_type,
34938c2ecf20Sopenharmony_ci			      union ib_gid *sgid, union ib_gid *dgid);
34948c2ecf20Sopenharmony_ci
34958c2ecf20Sopenharmony_ci/**
34968c2ecf20Sopenharmony_ci * ib_get_rdma_header_version - Get the header version
34978c2ecf20Sopenharmony_ci * @hdr: the L3 header to parse
34988c2ecf20Sopenharmony_ci */
34998c2ecf20Sopenharmony_ciint ib_get_rdma_header_version(const union rdma_network_hdr *hdr);
35008c2ecf20Sopenharmony_ci
35018c2ecf20Sopenharmony_ci/**
35028c2ecf20Sopenharmony_ci * ib_init_ah_attr_from_wc - Initializes address handle attributes from a
35038c2ecf20Sopenharmony_ci *   work completion.
35048c2ecf20Sopenharmony_ci * @device: Device on which the received message arrived.
35058c2ecf20Sopenharmony_ci * @port_num: Port on which the received message arrived.
35068c2ecf20Sopenharmony_ci * @wc: Work completion associated with the received message.
35078c2ecf20Sopenharmony_ci * @grh: References the received global route header.  This parameter is
35088c2ecf20Sopenharmony_ci *   ignored unless the work completion indicates that the GRH is valid.
35098c2ecf20Sopenharmony_ci * @ah_attr: Returned attributes that can be used when creating an address
35108c2ecf20Sopenharmony_ci *   handle for replying to the message.
35118c2ecf20Sopenharmony_ci * When ib_init_ah_attr_from_wc() returns success,
35128c2ecf20Sopenharmony_ci * (a) for IB link layer it optionally contains a reference to SGID attribute
35138c2ecf20Sopenharmony_ci * when GRH is present for IB link layer.
35148c2ecf20Sopenharmony_ci * (b) for RoCE link layer it contains a reference to SGID attribute.
35158c2ecf20Sopenharmony_ci * User must invoke rdma_cleanup_ah_attr_gid_attr() to release reference to SGID
35168c2ecf20Sopenharmony_ci * attributes which are initialized using ib_init_ah_attr_from_wc().
35178c2ecf20Sopenharmony_ci *
35188c2ecf20Sopenharmony_ci */
35198c2ecf20Sopenharmony_ciint ib_init_ah_attr_from_wc(struct ib_device *device, u8 port_num,
35208c2ecf20Sopenharmony_ci			    const struct ib_wc *wc, const struct ib_grh *grh,
35218c2ecf20Sopenharmony_ci			    struct rdma_ah_attr *ah_attr);
35228c2ecf20Sopenharmony_ci
35238c2ecf20Sopenharmony_ci/**
35248c2ecf20Sopenharmony_ci * ib_create_ah_from_wc - Creates an address handle associated with the
35258c2ecf20Sopenharmony_ci *   sender of the specified work completion.
35268c2ecf20Sopenharmony_ci * @pd: The protection domain associated with the address handle.
35278c2ecf20Sopenharmony_ci * @wc: Work completion information associated with a received message.
35288c2ecf20Sopenharmony_ci * @grh: References the received global route header.  This parameter is
35298c2ecf20Sopenharmony_ci *   ignored unless the work completion indicates that the GRH is valid.
35308c2ecf20Sopenharmony_ci * @port_num: The outbound port number to associate with the address.
35318c2ecf20Sopenharmony_ci *
35328c2ecf20Sopenharmony_ci * The address handle is used to reference a local or global destination
35338c2ecf20Sopenharmony_ci * in all UD QP post sends.
35348c2ecf20Sopenharmony_ci */
35358c2ecf20Sopenharmony_cistruct ib_ah *ib_create_ah_from_wc(struct ib_pd *pd, const struct ib_wc *wc,
35368c2ecf20Sopenharmony_ci				   const struct ib_grh *grh, u8 port_num);
35378c2ecf20Sopenharmony_ci
35388c2ecf20Sopenharmony_ci/**
35398c2ecf20Sopenharmony_ci * rdma_modify_ah - Modifies the address vector associated with an address
35408c2ecf20Sopenharmony_ci *   handle.
35418c2ecf20Sopenharmony_ci * @ah: The address handle to modify.
35428c2ecf20Sopenharmony_ci * @ah_attr: The new address vector attributes to associate with the
35438c2ecf20Sopenharmony_ci *   address handle.
35448c2ecf20Sopenharmony_ci */
35458c2ecf20Sopenharmony_ciint rdma_modify_ah(struct ib_ah *ah, struct rdma_ah_attr *ah_attr);
35468c2ecf20Sopenharmony_ci
35478c2ecf20Sopenharmony_ci/**
35488c2ecf20Sopenharmony_ci * rdma_query_ah - Queries the address vector associated with an address
35498c2ecf20Sopenharmony_ci *   handle.
35508c2ecf20Sopenharmony_ci * @ah: The address handle to query.
35518c2ecf20Sopenharmony_ci * @ah_attr: The address vector attributes associated with the address
35528c2ecf20Sopenharmony_ci *   handle.
35538c2ecf20Sopenharmony_ci */
35548c2ecf20Sopenharmony_ciint rdma_query_ah(struct ib_ah *ah, struct rdma_ah_attr *ah_attr);
35558c2ecf20Sopenharmony_ci
35568c2ecf20Sopenharmony_cienum rdma_destroy_ah_flags {
35578c2ecf20Sopenharmony_ci	/* In a sleepable context */
35588c2ecf20Sopenharmony_ci	RDMA_DESTROY_AH_SLEEPABLE = BIT(0),
35598c2ecf20Sopenharmony_ci};
35608c2ecf20Sopenharmony_ci
35618c2ecf20Sopenharmony_ci/**
35628c2ecf20Sopenharmony_ci * rdma_destroy_ah_user - Destroys an address handle.
35638c2ecf20Sopenharmony_ci * @ah: The address handle to destroy.
35648c2ecf20Sopenharmony_ci * @flags: Destroy address handle flags (see enum rdma_destroy_ah_flags).
35658c2ecf20Sopenharmony_ci * @udata: Valid user data or NULL for kernel objects
35668c2ecf20Sopenharmony_ci */
35678c2ecf20Sopenharmony_ciint rdma_destroy_ah_user(struct ib_ah *ah, u32 flags, struct ib_udata *udata);
35688c2ecf20Sopenharmony_ci
35698c2ecf20Sopenharmony_ci/**
35708c2ecf20Sopenharmony_ci * rdma_destroy_ah - Destroys an kernel address handle.
35718c2ecf20Sopenharmony_ci * @ah: The address handle to destroy.
35728c2ecf20Sopenharmony_ci * @flags: Destroy address handle flags (see enum rdma_destroy_ah_flags).
35738c2ecf20Sopenharmony_ci *
35748c2ecf20Sopenharmony_ci * NOTE: for user ah use rdma_destroy_ah_user with valid udata!
35758c2ecf20Sopenharmony_ci */
35768c2ecf20Sopenharmony_cistatic inline void rdma_destroy_ah(struct ib_ah *ah, u32 flags)
35778c2ecf20Sopenharmony_ci{
35788c2ecf20Sopenharmony_ci	int ret = rdma_destroy_ah_user(ah, flags, NULL);
35798c2ecf20Sopenharmony_ci
35808c2ecf20Sopenharmony_ci	WARN_ONCE(ret, "Destroy of kernel AH shouldn't fail");
35818c2ecf20Sopenharmony_ci}
35828c2ecf20Sopenharmony_ci
35838c2ecf20Sopenharmony_cistruct ib_srq *ib_create_srq_user(struct ib_pd *pd,
35848c2ecf20Sopenharmony_ci				  struct ib_srq_init_attr *srq_init_attr,
35858c2ecf20Sopenharmony_ci				  struct ib_usrq_object *uobject,
35868c2ecf20Sopenharmony_ci				  struct ib_udata *udata);
35878c2ecf20Sopenharmony_cistatic inline struct ib_srq *
35888c2ecf20Sopenharmony_ciib_create_srq(struct ib_pd *pd, struct ib_srq_init_attr *srq_init_attr)
35898c2ecf20Sopenharmony_ci{
35908c2ecf20Sopenharmony_ci	if (!pd->device->ops.create_srq)
35918c2ecf20Sopenharmony_ci		return ERR_PTR(-EOPNOTSUPP);
35928c2ecf20Sopenharmony_ci
35938c2ecf20Sopenharmony_ci	return ib_create_srq_user(pd, srq_init_attr, NULL, NULL);
35948c2ecf20Sopenharmony_ci}
35958c2ecf20Sopenharmony_ci
35968c2ecf20Sopenharmony_ci/**
35978c2ecf20Sopenharmony_ci * ib_modify_srq - Modifies the attributes for the specified SRQ.
35988c2ecf20Sopenharmony_ci * @srq: The SRQ to modify.
35998c2ecf20Sopenharmony_ci * @srq_attr: On input, specifies the SRQ attributes to modify.  On output,
36008c2ecf20Sopenharmony_ci *   the current values of selected SRQ attributes are returned.
36018c2ecf20Sopenharmony_ci * @srq_attr_mask: A bit-mask used to specify which attributes of the SRQ
36028c2ecf20Sopenharmony_ci *   are being modified.
36038c2ecf20Sopenharmony_ci *
36048c2ecf20Sopenharmony_ci * The mask may contain IB_SRQ_MAX_WR to resize the SRQ and/or
36058c2ecf20Sopenharmony_ci * IB_SRQ_LIMIT to set the SRQ's limit and request notification when
36068c2ecf20Sopenharmony_ci * the number of receives queued drops below the limit.
36078c2ecf20Sopenharmony_ci */
36088c2ecf20Sopenharmony_ciint ib_modify_srq(struct ib_srq *srq,
36098c2ecf20Sopenharmony_ci		  struct ib_srq_attr *srq_attr,
36108c2ecf20Sopenharmony_ci		  enum ib_srq_attr_mask srq_attr_mask);
36118c2ecf20Sopenharmony_ci
36128c2ecf20Sopenharmony_ci/**
36138c2ecf20Sopenharmony_ci * ib_query_srq - Returns the attribute list and current values for the
36148c2ecf20Sopenharmony_ci *   specified SRQ.
36158c2ecf20Sopenharmony_ci * @srq: The SRQ to query.
36168c2ecf20Sopenharmony_ci * @srq_attr: The attributes of the specified SRQ.
36178c2ecf20Sopenharmony_ci */
36188c2ecf20Sopenharmony_ciint ib_query_srq(struct ib_srq *srq,
36198c2ecf20Sopenharmony_ci		 struct ib_srq_attr *srq_attr);
36208c2ecf20Sopenharmony_ci
36218c2ecf20Sopenharmony_ci/**
36228c2ecf20Sopenharmony_ci * ib_destroy_srq_user - Destroys the specified SRQ.
36238c2ecf20Sopenharmony_ci * @srq: The SRQ to destroy.
36248c2ecf20Sopenharmony_ci * @udata: Valid user data or NULL for kernel objects
36258c2ecf20Sopenharmony_ci */
36268c2ecf20Sopenharmony_ciint ib_destroy_srq_user(struct ib_srq *srq, struct ib_udata *udata);
36278c2ecf20Sopenharmony_ci
36288c2ecf20Sopenharmony_ci/**
36298c2ecf20Sopenharmony_ci * ib_destroy_srq - Destroys the specified kernel SRQ.
36308c2ecf20Sopenharmony_ci * @srq: The SRQ to destroy.
36318c2ecf20Sopenharmony_ci *
36328c2ecf20Sopenharmony_ci * NOTE: for user srq use ib_destroy_srq_user with valid udata!
36338c2ecf20Sopenharmony_ci */
36348c2ecf20Sopenharmony_cistatic inline void ib_destroy_srq(struct ib_srq *srq)
36358c2ecf20Sopenharmony_ci{
36368c2ecf20Sopenharmony_ci	int ret = ib_destroy_srq_user(srq, NULL);
36378c2ecf20Sopenharmony_ci
36388c2ecf20Sopenharmony_ci	WARN_ONCE(ret, "Destroy of kernel SRQ shouldn't fail");
36398c2ecf20Sopenharmony_ci}
36408c2ecf20Sopenharmony_ci
36418c2ecf20Sopenharmony_ci/**
36428c2ecf20Sopenharmony_ci * ib_post_srq_recv - Posts a list of work requests to the specified SRQ.
36438c2ecf20Sopenharmony_ci * @srq: The SRQ to post the work request on.
36448c2ecf20Sopenharmony_ci * @recv_wr: A list of work requests to post on the receive queue.
36458c2ecf20Sopenharmony_ci * @bad_recv_wr: On an immediate failure, this parameter will reference
36468c2ecf20Sopenharmony_ci *   the work request that failed to be posted on the QP.
36478c2ecf20Sopenharmony_ci */
36488c2ecf20Sopenharmony_cistatic inline int ib_post_srq_recv(struct ib_srq *srq,
36498c2ecf20Sopenharmony_ci				   const struct ib_recv_wr *recv_wr,
36508c2ecf20Sopenharmony_ci				   const struct ib_recv_wr **bad_recv_wr)
36518c2ecf20Sopenharmony_ci{
36528c2ecf20Sopenharmony_ci	const struct ib_recv_wr *dummy;
36538c2ecf20Sopenharmony_ci
36548c2ecf20Sopenharmony_ci	return srq->device->ops.post_srq_recv(srq, recv_wr,
36558c2ecf20Sopenharmony_ci					      bad_recv_wr ? : &dummy);
36568c2ecf20Sopenharmony_ci}
36578c2ecf20Sopenharmony_ci
36588c2ecf20Sopenharmony_cistruct ib_qp *ib_create_qp(struct ib_pd *pd,
36598c2ecf20Sopenharmony_ci			   struct ib_qp_init_attr *qp_init_attr);
36608c2ecf20Sopenharmony_ci
36618c2ecf20Sopenharmony_ci/**
36628c2ecf20Sopenharmony_ci * ib_modify_qp_with_udata - Modifies the attributes for the specified QP.
36638c2ecf20Sopenharmony_ci * @qp: The QP to modify.
36648c2ecf20Sopenharmony_ci * @attr: On input, specifies the QP attributes to modify.  On output,
36658c2ecf20Sopenharmony_ci *   the current values of selected QP attributes are returned.
36668c2ecf20Sopenharmony_ci * @attr_mask: A bit-mask used to specify which attributes of the QP
36678c2ecf20Sopenharmony_ci *   are being modified.
36688c2ecf20Sopenharmony_ci * @udata: pointer to user's input output buffer information
36698c2ecf20Sopenharmony_ci *   are being modified.
36708c2ecf20Sopenharmony_ci * It returns 0 on success and returns appropriate error code on error.
36718c2ecf20Sopenharmony_ci */
36728c2ecf20Sopenharmony_ciint ib_modify_qp_with_udata(struct ib_qp *qp,
36738c2ecf20Sopenharmony_ci			    struct ib_qp_attr *attr,
36748c2ecf20Sopenharmony_ci			    int attr_mask,
36758c2ecf20Sopenharmony_ci			    struct ib_udata *udata);
36768c2ecf20Sopenharmony_ci
36778c2ecf20Sopenharmony_ci/**
36788c2ecf20Sopenharmony_ci * ib_modify_qp - Modifies the attributes for the specified QP and then
36798c2ecf20Sopenharmony_ci *   transitions the QP to the given state.
36808c2ecf20Sopenharmony_ci * @qp: The QP to modify.
36818c2ecf20Sopenharmony_ci * @qp_attr: On input, specifies the QP attributes to modify.  On output,
36828c2ecf20Sopenharmony_ci *   the current values of selected QP attributes are returned.
36838c2ecf20Sopenharmony_ci * @qp_attr_mask: A bit-mask used to specify which attributes of the QP
36848c2ecf20Sopenharmony_ci *   are being modified.
36858c2ecf20Sopenharmony_ci */
36868c2ecf20Sopenharmony_ciint ib_modify_qp(struct ib_qp *qp,
36878c2ecf20Sopenharmony_ci		 struct ib_qp_attr *qp_attr,
36888c2ecf20Sopenharmony_ci		 int qp_attr_mask);
36898c2ecf20Sopenharmony_ci
36908c2ecf20Sopenharmony_ci/**
36918c2ecf20Sopenharmony_ci * ib_query_qp - Returns the attribute list and current values for the
36928c2ecf20Sopenharmony_ci *   specified QP.
36938c2ecf20Sopenharmony_ci * @qp: The QP to query.
36948c2ecf20Sopenharmony_ci * @qp_attr: The attributes of the specified QP.
36958c2ecf20Sopenharmony_ci * @qp_attr_mask: A bit-mask used to select specific attributes to query.
36968c2ecf20Sopenharmony_ci * @qp_init_attr: Additional attributes of the selected QP.
36978c2ecf20Sopenharmony_ci *
36988c2ecf20Sopenharmony_ci * The qp_attr_mask may be used to limit the query to gathering only the
36998c2ecf20Sopenharmony_ci * selected attributes.
37008c2ecf20Sopenharmony_ci */
37018c2ecf20Sopenharmony_ciint ib_query_qp(struct ib_qp *qp,
37028c2ecf20Sopenharmony_ci		struct ib_qp_attr *qp_attr,
37038c2ecf20Sopenharmony_ci		int qp_attr_mask,
37048c2ecf20Sopenharmony_ci		struct ib_qp_init_attr *qp_init_attr);
37058c2ecf20Sopenharmony_ci
37068c2ecf20Sopenharmony_ci/**
37078c2ecf20Sopenharmony_ci * ib_destroy_qp - Destroys the specified QP.
37088c2ecf20Sopenharmony_ci * @qp: The QP to destroy.
37098c2ecf20Sopenharmony_ci * @udata: Valid udata or NULL for kernel objects
37108c2ecf20Sopenharmony_ci */
37118c2ecf20Sopenharmony_ciint ib_destroy_qp_user(struct ib_qp *qp, struct ib_udata *udata);
37128c2ecf20Sopenharmony_ci
37138c2ecf20Sopenharmony_ci/**
37148c2ecf20Sopenharmony_ci * ib_destroy_qp - Destroys the specified kernel QP.
37158c2ecf20Sopenharmony_ci * @qp: The QP to destroy.
37168c2ecf20Sopenharmony_ci *
37178c2ecf20Sopenharmony_ci * NOTE: for user qp use ib_destroy_qp_user with valid udata!
37188c2ecf20Sopenharmony_ci */
37198c2ecf20Sopenharmony_cistatic inline int ib_destroy_qp(struct ib_qp *qp)
37208c2ecf20Sopenharmony_ci{
37218c2ecf20Sopenharmony_ci	return ib_destroy_qp_user(qp, NULL);
37228c2ecf20Sopenharmony_ci}
37238c2ecf20Sopenharmony_ci
37248c2ecf20Sopenharmony_ci/**
37258c2ecf20Sopenharmony_ci * ib_open_qp - Obtain a reference to an existing sharable QP.
37268c2ecf20Sopenharmony_ci * @xrcd - XRC domain
37278c2ecf20Sopenharmony_ci * @qp_open_attr: Attributes identifying the QP to open.
37288c2ecf20Sopenharmony_ci *
37298c2ecf20Sopenharmony_ci * Returns a reference to a sharable QP.
37308c2ecf20Sopenharmony_ci */
37318c2ecf20Sopenharmony_cistruct ib_qp *ib_open_qp(struct ib_xrcd *xrcd,
37328c2ecf20Sopenharmony_ci			 struct ib_qp_open_attr *qp_open_attr);
37338c2ecf20Sopenharmony_ci
37348c2ecf20Sopenharmony_ci/**
37358c2ecf20Sopenharmony_ci * ib_close_qp - Release an external reference to a QP.
37368c2ecf20Sopenharmony_ci * @qp: The QP handle to release
37378c2ecf20Sopenharmony_ci *
37388c2ecf20Sopenharmony_ci * The opened QP handle is released by the caller.  The underlying
37398c2ecf20Sopenharmony_ci * shared QP is not destroyed until all internal references are released.
37408c2ecf20Sopenharmony_ci */
37418c2ecf20Sopenharmony_ciint ib_close_qp(struct ib_qp *qp);
37428c2ecf20Sopenharmony_ci
37438c2ecf20Sopenharmony_ci/**
37448c2ecf20Sopenharmony_ci * ib_post_send - Posts a list of work requests to the send queue of
37458c2ecf20Sopenharmony_ci *   the specified QP.
37468c2ecf20Sopenharmony_ci * @qp: The QP to post the work request on.
37478c2ecf20Sopenharmony_ci * @send_wr: A list of work requests to post on the send queue.
37488c2ecf20Sopenharmony_ci * @bad_send_wr: On an immediate failure, this parameter will reference
37498c2ecf20Sopenharmony_ci *   the work request that failed to be posted on the QP.
37508c2ecf20Sopenharmony_ci *
37518c2ecf20Sopenharmony_ci * While IBA Vol. 1 section 11.4.1.1 specifies that if an immediate
37528c2ecf20Sopenharmony_ci * error is returned, the QP state shall not be affected,
37538c2ecf20Sopenharmony_ci * ib_post_send() will return an immediate error after queueing any
37548c2ecf20Sopenharmony_ci * earlier work requests in the list.
37558c2ecf20Sopenharmony_ci */
37568c2ecf20Sopenharmony_cistatic inline int ib_post_send(struct ib_qp *qp,
37578c2ecf20Sopenharmony_ci			       const struct ib_send_wr *send_wr,
37588c2ecf20Sopenharmony_ci			       const struct ib_send_wr **bad_send_wr)
37598c2ecf20Sopenharmony_ci{
37608c2ecf20Sopenharmony_ci	const struct ib_send_wr *dummy;
37618c2ecf20Sopenharmony_ci
37628c2ecf20Sopenharmony_ci	return qp->device->ops.post_send(qp, send_wr, bad_send_wr ? : &dummy);
37638c2ecf20Sopenharmony_ci}
37648c2ecf20Sopenharmony_ci
37658c2ecf20Sopenharmony_ci/**
37668c2ecf20Sopenharmony_ci * ib_post_recv - Posts a list of work requests to the receive queue of
37678c2ecf20Sopenharmony_ci *   the specified QP.
37688c2ecf20Sopenharmony_ci * @qp: The QP to post the work request on.
37698c2ecf20Sopenharmony_ci * @recv_wr: A list of work requests to post on the receive queue.
37708c2ecf20Sopenharmony_ci * @bad_recv_wr: On an immediate failure, this parameter will reference
37718c2ecf20Sopenharmony_ci *   the work request that failed to be posted on the QP.
37728c2ecf20Sopenharmony_ci */
37738c2ecf20Sopenharmony_cistatic inline int ib_post_recv(struct ib_qp *qp,
37748c2ecf20Sopenharmony_ci			       const struct ib_recv_wr *recv_wr,
37758c2ecf20Sopenharmony_ci			       const struct ib_recv_wr **bad_recv_wr)
37768c2ecf20Sopenharmony_ci{
37778c2ecf20Sopenharmony_ci	const struct ib_recv_wr *dummy;
37788c2ecf20Sopenharmony_ci
37798c2ecf20Sopenharmony_ci	return qp->device->ops.post_recv(qp, recv_wr, bad_recv_wr ? : &dummy);
37808c2ecf20Sopenharmony_ci}
37818c2ecf20Sopenharmony_ci
37828c2ecf20Sopenharmony_cistruct ib_cq *__ib_alloc_cq(struct ib_device *dev, void *private, int nr_cqe,
37838c2ecf20Sopenharmony_ci			    int comp_vector, enum ib_poll_context poll_ctx,
37848c2ecf20Sopenharmony_ci			    const char *caller);
37858c2ecf20Sopenharmony_cistatic inline struct ib_cq *ib_alloc_cq(struct ib_device *dev, void *private,
37868c2ecf20Sopenharmony_ci					int nr_cqe, int comp_vector,
37878c2ecf20Sopenharmony_ci					enum ib_poll_context poll_ctx)
37888c2ecf20Sopenharmony_ci{
37898c2ecf20Sopenharmony_ci	return __ib_alloc_cq(dev, private, nr_cqe, comp_vector, poll_ctx,
37908c2ecf20Sopenharmony_ci			     KBUILD_MODNAME);
37918c2ecf20Sopenharmony_ci}
37928c2ecf20Sopenharmony_ci
37938c2ecf20Sopenharmony_cistruct ib_cq *__ib_alloc_cq_any(struct ib_device *dev, void *private,
37948c2ecf20Sopenharmony_ci				int nr_cqe, enum ib_poll_context poll_ctx,
37958c2ecf20Sopenharmony_ci				const char *caller);
37968c2ecf20Sopenharmony_ci
37978c2ecf20Sopenharmony_ci/**
37988c2ecf20Sopenharmony_ci * ib_alloc_cq_any: Allocate kernel CQ
37998c2ecf20Sopenharmony_ci * @dev: The IB device
38008c2ecf20Sopenharmony_ci * @private: Private data attached to the CQE
38018c2ecf20Sopenharmony_ci * @nr_cqe: Number of CQEs in the CQ
38028c2ecf20Sopenharmony_ci * @poll_ctx: Context used for polling the CQ
38038c2ecf20Sopenharmony_ci */
38048c2ecf20Sopenharmony_cistatic inline struct ib_cq *ib_alloc_cq_any(struct ib_device *dev,
38058c2ecf20Sopenharmony_ci					    void *private, int nr_cqe,
38068c2ecf20Sopenharmony_ci					    enum ib_poll_context poll_ctx)
38078c2ecf20Sopenharmony_ci{
38088c2ecf20Sopenharmony_ci	return __ib_alloc_cq_any(dev, private, nr_cqe, poll_ctx,
38098c2ecf20Sopenharmony_ci				 KBUILD_MODNAME);
38108c2ecf20Sopenharmony_ci}
38118c2ecf20Sopenharmony_ci
38128c2ecf20Sopenharmony_civoid ib_free_cq(struct ib_cq *cq);
38138c2ecf20Sopenharmony_ciint ib_process_cq_direct(struct ib_cq *cq, int budget);
38148c2ecf20Sopenharmony_ci
38158c2ecf20Sopenharmony_ci/**
38168c2ecf20Sopenharmony_ci * ib_create_cq - Creates a CQ on the specified device.
38178c2ecf20Sopenharmony_ci * @device: The device on which to create the CQ.
38188c2ecf20Sopenharmony_ci * @comp_handler: A user-specified callback that is invoked when a
38198c2ecf20Sopenharmony_ci *   completion event occurs on the CQ.
38208c2ecf20Sopenharmony_ci * @event_handler: A user-specified callback that is invoked when an
38218c2ecf20Sopenharmony_ci *   asynchronous event not associated with a completion occurs on the CQ.
38228c2ecf20Sopenharmony_ci * @cq_context: Context associated with the CQ returned to the user via
38238c2ecf20Sopenharmony_ci *   the associated completion and event handlers.
38248c2ecf20Sopenharmony_ci * @cq_attr: The attributes the CQ should be created upon.
38258c2ecf20Sopenharmony_ci *
38268c2ecf20Sopenharmony_ci * Users can examine the cq structure to determine the actual CQ size.
38278c2ecf20Sopenharmony_ci */
38288c2ecf20Sopenharmony_cistruct ib_cq *__ib_create_cq(struct ib_device *device,
38298c2ecf20Sopenharmony_ci			     ib_comp_handler comp_handler,
38308c2ecf20Sopenharmony_ci			     void (*event_handler)(struct ib_event *, void *),
38318c2ecf20Sopenharmony_ci			     void *cq_context,
38328c2ecf20Sopenharmony_ci			     const struct ib_cq_init_attr *cq_attr,
38338c2ecf20Sopenharmony_ci			     const char *caller);
38348c2ecf20Sopenharmony_ci#define ib_create_cq(device, cmp_hndlr, evt_hndlr, cq_ctxt, cq_attr) \
38358c2ecf20Sopenharmony_ci	__ib_create_cq((device), (cmp_hndlr), (evt_hndlr), (cq_ctxt), (cq_attr), KBUILD_MODNAME)
38368c2ecf20Sopenharmony_ci
38378c2ecf20Sopenharmony_ci/**
38388c2ecf20Sopenharmony_ci * ib_resize_cq - Modifies the capacity of the CQ.
38398c2ecf20Sopenharmony_ci * @cq: The CQ to resize.
38408c2ecf20Sopenharmony_ci * @cqe: The minimum size of the CQ.
38418c2ecf20Sopenharmony_ci *
38428c2ecf20Sopenharmony_ci * Users can examine the cq structure to determine the actual CQ size.
38438c2ecf20Sopenharmony_ci */
38448c2ecf20Sopenharmony_ciint ib_resize_cq(struct ib_cq *cq, int cqe);
38458c2ecf20Sopenharmony_ci
38468c2ecf20Sopenharmony_ci/**
38478c2ecf20Sopenharmony_ci * rdma_set_cq_moderation - Modifies moderation params of the CQ
38488c2ecf20Sopenharmony_ci * @cq: The CQ to modify.
38498c2ecf20Sopenharmony_ci * @cq_count: number of CQEs that will trigger an event
38508c2ecf20Sopenharmony_ci * @cq_period: max period of time in usec before triggering an event
38518c2ecf20Sopenharmony_ci *
38528c2ecf20Sopenharmony_ci */
38538c2ecf20Sopenharmony_ciint rdma_set_cq_moderation(struct ib_cq *cq, u16 cq_count, u16 cq_period);
38548c2ecf20Sopenharmony_ci
38558c2ecf20Sopenharmony_ci/**
38568c2ecf20Sopenharmony_ci * ib_destroy_cq_user - Destroys the specified CQ.
38578c2ecf20Sopenharmony_ci * @cq: The CQ to destroy.
38588c2ecf20Sopenharmony_ci * @udata: Valid user data or NULL for kernel objects
38598c2ecf20Sopenharmony_ci */
38608c2ecf20Sopenharmony_ciint ib_destroy_cq_user(struct ib_cq *cq, struct ib_udata *udata);
38618c2ecf20Sopenharmony_ci
38628c2ecf20Sopenharmony_ci/**
38638c2ecf20Sopenharmony_ci * ib_destroy_cq - Destroys the specified kernel CQ.
38648c2ecf20Sopenharmony_ci * @cq: The CQ to destroy.
38658c2ecf20Sopenharmony_ci *
38668c2ecf20Sopenharmony_ci * NOTE: for user cq use ib_destroy_cq_user with valid udata!
38678c2ecf20Sopenharmony_ci */
38688c2ecf20Sopenharmony_cistatic inline void ib_destroy_cq(struct ib_cq *cq)
38698c2ecf20Sopenharmony_ci{
38708c2ecf20Sopenharmony_ci	int ret = ib_destroy_cq_user(cq, NULL);
38718c2ecf20Sopenharmony_ci
38728c2ecf20Sopenharmony_ci	WARN_ONCE(ret, "Destroy of kernel CQ shouldn't fail");
38738c2ecf20Sopenharmony_ci}
38748c2ecf20Sopenharmony_ci
38758c2ecf20Sopenharmony_ci/**
38768c2ecf20Sopenharmony_ci * ib_poll_cq - poll a CQ for completion(s)
38778c2ecf20Sopenharmony_ci * @cq:the CQ being polled
38788c2ecf20Sopenharmony_ci * @num_entries:maximum number of completions to return
38798c2ecf20Sopenharmony_ci * @wc:array of at least @num_entries &struct ib_wc where completions
38808c2ecf20Sopenharmony_ci *   will be returned
38818c2ecf20Sopenharmony_ci *
38828c2ecf20Sopenharmony_ci * Poll a CQ for (possibly multiple) completions.  If the return value
38838c2ecf20Sopenharmony_ci * is < 0, an error occurred.  If the return value is >= 0, it is the
38848c2ecf20Sopenharmony_ci * number of completions returned.  If the return value is
38858c2ecf20Sopenharmony_ci * non-negative and < num_entries, then the CQ was emptied.
38868c2ecf20Sopenharmony_ci */
38878c2ecf20Sopenharmony_cistatic inline int ib_poll_cq(struct ib_cq *cq, int num_entries,
38888c2ecf20Sopenharmony_ci			     struct ib_wc *wc)
38898c2ecf20Sopenharmony_ci{
38908c2ecf20Sopenharmony_ci	return cq->device->ops.poll_cq(cq, num_entries, wc);
38918c2ecf20Sopenharmony_ci}
38928c2ecf20Sopenharmony_ci
38938c2ecf20Sopenharmony_ci/**
38948c2ecf20Sopenharmony_ci * ib_req_notify_cq - Request completion notification on a CQ.
38958c2ecf20Sopenharmony_ci * @cq: The CQ to generate an event for.
38968c2ecf20Sopenharmony_ci * @flags:
38978c2ecf20Sopenharmony_ci *   Must contain exactly one of %IB_CQ_SOLICITED or %IB_CQ_NEXT_COMP
38988c2ecf20Sopenharmony_ci *   to request an event on the next solicited event or next work
38998c2ecf20Sopenharmony_ci *   completion at any type, respectively. %IB_CQ_REPORT_MISSED_EVENTS
39008c2ecf20Sopenharmony_ci *   may also be |ed in to request a hint about missed events, as
39018c2ecf20Sopenharmony_ci *   described below.
39028c2ecf20Sopenharmony_ci *
39038c2ecf20Sopenharmony_ci * Return Value:
39048c2ecf20Sopenharmony_ci *    < 0 means an error occurred while requesting notification
39058c2ecf20Sopenharmony_ci *   == 0 means notification was requested successfully, and if
39068c2ecf20Sopenharmony_ci *        IB_CQ_REPORT_MISSED_EVENTS was passed in, then no events
39078c2ecf20Sopenharmony_ci *        were missed and it is safe to wait for another event.  In
39088c2ecf20Sopenharmony_ci *        this case is it guaranteed that any work completions added
39098c2ecf20Sopenharmony_ci *        to the CQ since the last CQ poll will trigger a completion
39108c2ecf20Sopenharmony_ci *        notification event.
39118c2ecf20Sopenharmony_ci *    > 0 is only returned if IB_CQ_REPORT_MISSED_EVENTS was passed
39128c2ecf20Sopenharmony_ci *        in.  It means that the consumer must poll the CQ again to
39138c2ecf20Sopenharmony_ci *        make sure it is empty to avoid missing an event because of a
39148c2ecf20Sopenharmony_ci *        race between requesting notification and an entry being
39158c2ecf20Sopenharmony_ci *        added to the CQ.  This return value means it is possible
39168c2ecf20Sopenharmony_ci *        (but not guaranteed) that a work completion has been added
39178c2ecf20Sopenharmony_ci *        to the CQ since the last poll without triggering a
39188c2ecf20Sopenharmony_ci *        completion notification event.
39198c2ecf20Sopenharmony_ci */
39208c2ecf20Sopenharmony_cistatic inline int ib_req_notify_cq(struct ib_cq *cq,
39218c2ecf20Sopenharmony_ci				   enum ib_cq_notify_flags flags)
39228c2ecf20Sopenharmony_ci{
39238c2ecf20Sopenharmony_ci	return cq->device->ops.req_notify_cq(cq, flags);
39248c2ecf20Sopenharmony_ci}
39258c2ecf20Sopenharmony_ci
39268c2ecf20Sopenharmony_cistruct ib_cq *ib_cq_pool_get(struct ib_device *dev, unsigned int nr_cqe,
39278c2ecf20Sopenharmony_ci			     int comp_vector_hint,
39288c2ecf20Sopenharmony_ci			     enum ib_poll_context poll_ctx);
39298c2ecf20Sopenharmony_ci
39308c2ecf20Sopenharmony_civoid ib_cq_pool_put(struct ib_cq *cq, unsigned int nr_cqe);
39318c2ecf20Sopenharmony_ci
39328c2ecf20Sopenharmony_ci/**
39338c2ecf20Sopenharmony_ci * ib_req_ncomp_notif - Request completion notification when there are
39348c2ecf20Sopenharmony_ci *   at least the specified number of unreaped completions on the CQ.
39358c2ecf20Sopenharmony_ci * @cq: The CQ to generate an event for.
39368c2ecf20Sopenharmony_ci * @wc_cnt: The number of unreaped completions that should be on the
39378c2ecf20Sopenharmony_ci *   CQ before an event is generated.
39388c2ecf20Sopenharmony_ci */
39398c2ecf20Sopenharmony_cistatic inline int ib_req_ncomp_notif(struct ib_cq *cq, int wc_cnt)
39408c2ecf20Sopenharmony_ci{
39418c2ecf20Sopenharmony_ci	return cq->device->ops.req_ncomp_notif ?
39428c2ecf20Sopenharmony_ci		cq->device->ops.req_ncomp_notif(cq, wc_cnt) :
39438c2ecf20Sopenharmony_ci		-ENOSYS;
39448c2ecf20Sopenharmony_ci}
39458c2ecf20Sopenharmony_ci
39468c2ecf20Sopenharmony_ci/*
39478c2ecf20Sopenharmony_ci * Drivers that don't need a DMA mapping at the RDMA layer, set dma_device to
39488c2ecf20Sopenharmony_ci * NULL. This causes the ib_dma* helpers to just stash the kernel virtual
39498c2ecf20Sopenharmony_ci * address into the dma address.
39508c2ecf20Sopenharmony_ci */
39518c2ecf20Sopenharmony_cistatic inline bool ib_uses_virt_dma(struct ib_device *dev)
39528c2ecf20Sopenharmony_ci{
39538c2ecf20Sopenharmony_ci	return IS_ENABLED(CONFIG_INFINIBAND_VIRT_DMA) && !dev->dma_device;
39548c2ecf20Sopenharmony_ci}
39558c2ecf20Sopenharmony_ci
39568c2ecf20Sopenharmony_ci/**
39578c2ecf20Sopenharmony_ci * ib_dma_mapping_error - check a DMA addr for error
39588c2ecf20Sopenharmony_ci * @dev: The device for which the dma_addr was created
39598c2ecf20Sopenharmony_ci * @dma_addr: The DMA address to check
39608c2ecf20Sopenharmony_ci */
39618c2ecf20Sopenharmony_cistatic inline int ib_dma_mapping_error(struct ib_device *dev, u64 dma_addr)
39628c2ecf20Sopenharmony_ci{
39638c2ecf20Sopenharmony_ci	if (ib_uses_virt_dma(dev))
39648c2ecf20Sopenharmony_ci		return 0;
39658c2ecf20Sopenharmony_ci	return dma_mapping_error(dev->dma_device, dma_addr);
39668c2ecf20Sopenharmony_ci}
39678c2ecf20Sopenharmony_ci
39688c2ecf20Sopenharmony_ci/**
39698c2ecf20Sopenharmony_ci * ib_dma_map_single - Map a kernel virtual address to DMA address
39708c2ecf20Sopenharmony_ci * @dev: The device for which the dma_addr is to be created
39718c2ecf20Sopenharmony_ci * @cpu_addr: The kernel virtual address
39728c2ecf20Sopenharmony_ci * @size: The size of the region in bytes
39738c2ecf20Sopenharmony_ci * @direction: The direction of the DMA
39748c2ecf20Sopenharmony_ci */
39758c2ecf20Sopenharmony_cistatic inline u64 ib_dma_map_single(struct ib_device *dev,
39768c2ecf20Sopenharmony_ci				    void *cpu_addr, size_t size,
39778c2ecf20Sopenharmony_ci				    enum dma_data_direction direction)
39788c2ecf20Sopenharmony_ci{
39798c2ecf20Sopenharmony_ci	if (ib_uses_virt_dma(dev))
39808c2ecf20Sopenharmony_ci		return (uintptr_t)cpu_addr;
39818c2ecf20Sopenharmony_ci	return dma_map_single(dev->dma_device, cpu_addr, size, direction);
39828c2ecf20Sopenharmony_ci}
39838c2ecf20Sopenharmony_ci
39848c2ecf20Sopenharmony_ci/**
39858c2ecf20Sopenharmony_ci * ib_dma_unmap_single - Destroy a mapping created by ib_dma_map_single()
39868c2ecf20Sopenharmony_ci * @dev: The device for which the DMA address was created
39878c2ecf20Sopenharmony_ci * @addr: The DMA address
39888c2ecf20Sopenharmony_ci * @size: The size of the region in bytes
39898c2ecf20Sopenharmony_ci * @direction: The direction of the DMA
39908c2ecf20Sopenharmony_ci */
39918c2ecf20Sopenharmony_cistatic inline void ib_dma_unmap_single(struct ib_device *dev,
39928c2ecf20Sopenharmony_ci				       u64 addr, size_t size,
39938c2ecf20Sopenharmony_ci				       enum dma_data_direction direction)
39948c2ecf20Sopenharmony_ci{
39958c2ecf20Sopenharmony_ci	if (!ib_uses_virt_dma(dev))
39968c2ecf20Sopenharmony_ci		dma_unmap_single(dev->dma_device, addr, size, direction);
39978c2ecf20Sopenharmony_ci}
39988c2ecf20Sopenharmony_ci
39998c2ecf20Sopenharmony_ci/**
40008c2ecf20Sopenharmony_ci * ib_dma_map_page - Map a physical page to DMA address
40018c2ecf20Sopenharmony_ci * @dev: The device for which the dma_addr is to be created
40028c2ecf20Sopenharmony_ci * @page: The page to be mapped
40038c2ecf20Sopenharmony_ci * @offset: The offset within the page
40048c2ecf20Sopenharmony_ci * @size: The size of the region in bytes
40058c2ecf20Sopenharmony_ci * @direction: The direction of the DMA
40068c2ecf20Sopenharmony_ci */
40078c2ecf20Sopenharmony_cistatic inline u64 ib_dma_map_page(struct ib_device *dev,
40088c2ecf20Sopenharmony_ci				  struct page *page,
40098c2ecf20Sopenharmony_ci				  unsigned long offset,
40108c2ecf20Sopenharmony_ci				  size_t size,
40118c2ecf20Sopenharmony_ci					 enum dma_data_direction direction)
40128c2ecf20Sopenharmony_ci{
40138c2ecf20Sopenharmony_ci	if (ib_uses_virt_dma(dev))
40148c2ecf20Sopenharmony_ci		return (uintptr_t)(page_address(page) + offset);
40158c2ecf20Sopenharmony_ci	return dma_map_page(dev->dma_device, page, offset, size, direction);
40168c2ecf20Sopenharmony_ci}
40178c2ecf20Sopenharmony_ci
40188c2ecf20Sopenharmony_ci/**
40198c2ecf20Sopenharmony_ci * ib_dma_unmap_page - Destroy a mapping created by ib_dma_map_page()
40208c2ecf20Sopenharmony_ci * @dev: The device for which the DMA address was created
40218c2ecf20Sopenharmony_ci * @addr: The DMA address
40228c2ecf20Sopenharmony_ci * @size: The size of the region in bytes
40238c2ecf20Sopenharmony_ci * @direction: The direction of the DMA
40248c2ecf20Sopenharmony_ci */
40258c2ecf20Sopenharmony_cistatic inline void ib_dma_unmap_page(struct ib_device *dev,
40268c2ecf20Sopenharmony_ci				     u64 addr, size_t size,
40278c2ecf20Sopenharmony_ci				     enum dma_data_direction direction)
40288c2ecf20Sopenharmony_ci{
40298c2ecf20Sopenharmony_ci	if (!ib_uses_virt_dma(dev))
40308c2ecf20Sopenharmony_ci		dma_unmap_page(dev->dma_device, addr, size, direction);
40318c2ecf20Sopenharmony_ci}
40328c2ecf20Sopenharmony_ci
40338c2ecf20Sopenharmony_ciint ib_dma_virt_map_sg(struct ib_device *dev, struct scatterlist *sg, int nents);
40348c2ecf20Sopenharmony_cistatic inline int ib_dma_map_sg_attrs(struct ib_device *dev,
40358c2ecf20Sopenharmony_ci				      struct scatterlist *sg, int nents,
40368c2ecf20Sopenharmony_ci				      enum dma_data_direction direction,
40378c2ecf20Sopenharmony_ci				      unsigned long dma_attrs)
40388c2ecf20Sopenharmony_ci{
40398c2ecf20Sopenharmony_ci	if (ib_uses_virt_dma(dev))
40408c2ecf20Sopenharmony_ci		return ib_dma_virt_map_sg(dev, sg, nents);
40418c2ecf20Sopenharmony_ci	return dma_map_sg_attrs(dev->dma_device, sg, nents, direction,
40428c2ecf20Sopenharmony_ci				dma_attrs);
40438c2ecf20Sopenharmony_ci}
40448c2ecf20Sopenharmony_ci
40458c2ecf20Sopenharmony_cistatic inline void ib_dma_unmap_sg_attrs(struct ib_device *dev,
40468c2ecf20Sopenharmony_ci					 struct scatterlist *sg, int nents,
40478c2ecf20Sopenharmony_ci					 enum dma_data_direction direction,
40488c2ecf20Sopenharmony_ci					 unsigned long dma_attrs)
40498c2ecf20Sopenharmony_ci{
40508c2ecf20Sopenharmony_ci	if (!ib_uses_virt_dma(dev))
40518c2ecf20Sopenharmony_ci		dma_unmap_sg_attrs(dev->dma_device, sg, nents, direction,
40528c2ecf20Sopenharmony_ci				   dma_attrs);
40538c2ecf20Sopenharmony_ci}
40548c2ecf20Sopenharmony_ci
40558c2ecf20Sopenharmony_ci/**
40568c2ecf20Sopenharmony_ci * ib_dma_map_sg - Map a scatter/gather list to DMA addresses
40578c2ecf20Sopenharmony_ci * @dev: The device for which the DMA addresses are to be created
40588c2ecf20Sopenharmony_ci * @sg: The array of scatter/gather entries
40598c2ecf20Sopenharmony_ci * @nents: The number of scatter/gather entries
40608c2ecf20Sopenharmony_ci * @direction: The direction of the DMA
40618c2ecf20Sopenharmony_ci */
40628c2ecf20Sopenharmony_cistatic inline int ib_dma_map_sg(struct ib_device *dev,
40638c2ecf20Sopenharmony_ci				struct scatterlist *sg, int nents,
40648c2ecf20Sopenharmony_ci				enum dma_data_direction direction)
40658c2ecf20Sopenharmony_ci{
40668c2ecf20Sopenharmony_ci	return ib_dma_map_sg_attrs(dev, sg, nents, direction, 0);
40678c2ecf20Sopenharmony_ci}
40688c2ecf20Sopenharmony_ci
40698c2ecf20Sopenharmony_ci/**
40708c2ecf20Sopenharmony_ci * ib_dma_unmap_sg - Unmap a scatter/gather list of DMA addresses
40718c2ecf20Sopenharmony_ci * @dev: The device for which the DMA addresses were created
40728c2ecf20Sopenharmony_ci * @sg: The array of scatter/gather entries
40738c2ecf20Sopenharmony_ci * @nents: The number of scatter/gather entries
40748c2ecf20Sopenharmony_ci * @direction: The direction of the DMA
40758c2ecf20Sopenharmony_ci */
40768c2ecf20Sopenharmony_cistatic inline void ib_dma_unmap_sg(struct ib_device *dev,
40778c2ecf20Sopenharmony_ci				   struct scatterlist *sg, int nents,
40788c2ecf20Sopenharmony_ci				   enum dma_data_direction direction)
40798c2ecf20Sopenharmony_ci{
40808c2ecf20Sopenharmony_ci	ib_dma_unmap_sg_attrs(dev, sg, nents, direction, 0);
40818c2ecf20Sopenharmony_ci}
40828c2ecf20Sopenharmony_ci
40838c2ecf20Sopenharmony_ci/**
40848c2ecf20Sopenharmony_ci * ib_dma_max_seg_size - Return the size limit of a single DMA transfer
40858c2ecf20Sopenharmony_ci * @dev: The device to query
40868c2ecf20Sopenharmony_ci *
40878c2ecf20Sopenharmony_ci * The returned value represents a size in bytes.
40888c2ecf20Sopenharmony_ci */
40898c2ecf20Sopenharmony_cistatic inline unsigned int ib_dma_max_seg_size(struct ib_device *dev)
40908c2ecf20Sopenharmony_ci{
40918c2ecf20Sopenharmony_ci	if (ib_uses_virt_dma(dev))
40928c2ecf20Sopenharmony_ci		return UINT_MAX;
40938c2ecf20Sopenharmony_ci	return dma_get_max_seg_size(dev->dma_device);
40948c2ecf20Sopenharmony_ci}
40958c2ecf20Sopenharmony_ci
40968c2ecf20Sopenharmony_ci/**
40978c2ecf20Sopenharmony_ci * ib_dma_sync_single_for_cpu - Prepare DMA region to be accessed by CPU
40988c2ecf20Sopenharmony_ci * @dev: The device for which the DMA address was created
40998c2ecf20Sopenharmony_ci * @addr: The DMA address
41008c2ecf20Sopenharmony_ci * @size: The size of the region in bytes
41018c2ecf20Sopenharmony_ci * @dir: The direction of the DMA
41028c2ecf20Sopenharmony_ci */
41038c2ecf20Sopenharmony_cistatic inline void ib_dma_sync_single_for_cpu(struct ib_device *dev,
41048c2ecf20Sopenharmony_ci					      u64 addr,
41058c2ecf20Sopenharmony_ci					      size_t size,
41068c2ecf20Sopenharmony_ci					      enum dma_data_direction dir)
41078c2ecf20Sopenharmony_ci{
41088c2ecf20Sopenharmony_ci	if (!ib_uses_virt_dma(dev))
41098c2ecf20Sopenharmony_ci		dma_sync_single_for_cpu(dev->dma_device, addr, size, dir);
41108c2ecf20Sopenharmony_ci}
41118c2ecf20Sopenharmony_ci
41128c2ecf20Sopenharmony_ci/**
41138c2ecf20Sopenharmony_ci * ib_dma_sync_single_for_device - Prepare DMA region to be accessed by device
41148c2ecf20Sopenharmony_ci * @dev: The device for which the DMA address was created
41158c2ecf20Sopenharmony_ci * @addr: The DMA address
41168c2ecf20Sopenharmony_ci * @size: The size of the region in bytes
41178c2ecf20Sopenharmony_ci * @dir: The direction of the DMA
41188c2ecf20Sopenharmony_ci */
41198c2ecf20Sopenharmony_cistatic inline void ib_dma_sync_single_for_device(struct ib_device *dev,
41208c2ecf20Sopenharmony_ci						 u64 addr,
41218c2ecf20Sopenharmony_ci						 size_t size,
41228c2ecf20Sopenharmony_ci						 enum dma_data_direction dir)
41238c2ecf20Sopenharmony_ci{
41248c2ecf20Sopenharmony_ci	if (!ib_uses_virt_dma(dev))
41258c2ecf20Sopenharmony_ci		dma_sync_single_for_device(dev->dma_device, addr, size, dir);
41268c2ecf20Sopenharmony_ci}
41278c2ecf20Sopenharmony_ci
41288c2ecf20Sopenharmony_ci/**
41298c2ecf20Sopenharmony_ci * ib_dma_alloc_coherent - Allocate memory and map it for DMA
41308c2ecf20Sopenharmony_ci * @dev: The device for which the DMA address is requested
41318c2ecf20Sopenharmony_ci * @size: The size of the region to allocate in bytes
41328c2ecf20Sopenharmony_ci * @dma_handle: A pointer for returning the DMA address of the region
41338c2ecf20Sopenharmony_ci * @flag: memory allocator flags
41348c2ecf20Sopenharmony_ci */
41358c2ecf20Sopenharmony_cistatic inline void *ib_dma_alloc_coherent(struct ib_device *dev,
41368c2ecf20Sopenharmony_ci					   size_t size,
41378c2ecf20Sopenharmony_ci					   dma_addr_t *dma_handle,
41388c2ecf20Sopenharmony_ci					   gfp_t flag)
41398c2ecf20Sopenharmony_ci{
41408c2ecf20Sopenharmony_ci	return dma_alloc_coherent(dev->dma_device, size, dma_handle, flag);
41418c2ecf20Sopenharmony_ci}
41428c2ecf20Sopenharmony_ci
41438c2ecf20Sopenharmony_ci/**
41448c2ecf20Sopenharmony_ci * ib_dma_free_coherent - Free memory allocated by ib_dma_alloc_coherent()
41458c2ecf20Sopenharmony_ci * @dev: The device for which the DMA addresses were allocated
41468c2ecf20Sopenharmony_ci * @size: The size of the region
41478c2ecf20Sopenharmony_ci * @cpu_addr: the address returned by ib_dma_alloc_coherent()
41488c2ecf20Sopenharmony_ci * @dma_handle: the DMA address returned by ib_dma_alloc_coherent()
41498c2ecf20Sopenharmony_ci */
41508c2ecf20Sopenharmony_cistatic inline void ib_dma_free_coherent(struct ib_device *dev,
41518c2ecf20Sopenharmony_ci					size_t size, void *cpu_addr,
41528c2ecf20Sopenharmony_ci					dma_addr_t dma_handle)
41538c2ecf20Sopenharmony_ci{
41548c2ecf20Sopenharmony_ci	dma_free_coherent(dev->dma_device, size, cpu_addr, dma_handle);
41558c2ecf20Sopenharmony_ci}
41568c2ecf20Sopenharmony_ci
41578c2ecf20Sopenharmony_ci/* ib_reg_user_mr - register a memory region for virtual addresses from kernel
41588c2ecf20Sopenharmony_ci * space. This function should be called when 'current' is the owning MM.
41598c2ecf20Sopenharmony_ci */
41608c2ecf20Sopenharmony_cistruct ib_mr *ib_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
41618c2ecf20Sopenharmony_ci			     u64 virt_addr, int mr_access_flags);
41628c2ecf20Sopenharmony_ci
41638c2ecf20Sopenharmony_ci/* ib_advise_mr -  give an advice about an address range in a memory region */
41648c2ecf20Sopenharmony_ciint ib_advise_mr(struct ib_pd *pd, enum ib_uverbs_advise_mr_advice advice,
41658c2ecf20Sopenharmony_ci		 u32 flags, struct ib_sge *sg_list, u32 num_sge);
41668c2ecf20Sopenharmony_ci/**
41678c2ecf20Sopenharmony_ci * ib_dereg_mr_user - Deregisters a memory region and removes it from the
41688c2ecf20Sopenharmony_ci *   HCA translation table.
41698c2ecf20Sopenharmony_ci * @mr: The memory region to deregister.
41708c2ecf20Sopenharmony_ci * @udata: Valid user data or NULL for kernel object
41718c2ecf20Sopenharmony_ci *
41728c2ecf20Sopenharmony_ci * This function can fail, if the memory region has memory windows bound to it.
41738c2ecf20Sopenharmony_ci */
41748c2ecf20Sopenharmony_ciint ib_dereg_mr_user(struct ib_mr *mr, struct ib_udata *udata);
41758c2ecf20Sopenharmony_ci
41768c2ecf20Sopenharmony_ci/**
41778c2ecf20Sopenharmony_ci * ib_dereg_mr - Deregisters a kernel memory region and removes it from the
41788c2ecf20Sopenharmony_ci *   HCA translation table.
41798c2ecf20Sopenharmony_ci * @mr: The memory region to deregister.
41808c2ecf20Sopenharmony_ci *
41818c2ecf20Sopenharmony_ci * This function can fail, if the memory region has memory windows bound to it.
41828c2ecf20Sopenharmony_ci *
41838c2ecf20Sopenharmony_ci * NOTE: for user mr use ib_dereg_mr_user with valid udata!
41848c2ecf20Sopenharmony_ci */
41858c2ecf20Sopenharmony_cistatic inline int ib_dereg_mr(struct ib_mr *mr)
41868c2ecf20Sopenharmony_ci{
41878c2ecf20Sopenharmony_ci	return ib_dereg_mr_user(mr, NULL);
41888c2ecf20Sopenharmony_ci}
41898c2ecf20Sopenharmony_ci
41908c2ecf20Sopenharmony_cistruct ib_mr *ib_alloc_mr(struct ib_pd *pd, enum ib_mr_type mr_type,
41918c2ecf20Sopenharmony_ci			  u32 max_num_sg);
41928c2ecf20Sopenharmony_ci
41938c2ecf20Sopenharmony_cistruct ib_mr *ib_alloc_mr_integrity(struct ib_pd *pd,
41948c2ecf20Sopenharmony_ci				    u32 max_num_data_sg,
41958c2ecf20Sopenharmony_ci				    u32 max_num_meta_sg);
41968c2ecf20Sopenharmony_ci
41978c2ecf20Sopenharmony_ci/**
41988c2ecf20Sopenharmony_ci * ib_update_fast_reg_key - updates the key portion of the fast_reg MR
41998c2ecf20Sopenharmony_ci *   R_Key and L_Key.
42008c2ecf20Sopenharmony_ci * @mr - struct ib_mr pointer to be updated.
42018c2ecf20Sopenharmony_ci * @newkey - new key to be used.
42028c2ecf20Sopenharmony_ci */
42038c2ecf20Sopenharmony_cistatic inline void ib_update_fast_reg_key(struct ib_mr *mr, u8 newkey)
42048c2ecf20Sopenharmony_ci{
42058c2ecf20Sopenharmony_ci	mr->lkey = (mr->lkey & 0xffffff00) | newkey;
42068c2ecf20Sopenharmony_ci	mr->rkey = (mr->rkey & 0xffffff00) | newkey;
42078c2ecf20Sopenharmony_ci}
42088c2ecf20Sopenharmony_ci
42098c2ecf20Sopenharmony_ci/**
42108c2ecf20Sopenharmony_ci * ib_inc_rkey - increments the key portion of the given rkey. Can be used
42118c2ecf20Sopenharmony_ci * for calculating a new rkey for type 2 memory windows.
42128c2ecf20Sopenharmony_ci * @rkey - the rkey to increment.
42138c2ecf20Sopenharmony_ci */
42148c2ecf20Sopenharmony_cistatic inline u32 ib_inc_rkey(u32 rkey)
42158c2ecf20Sopenharmony_ci{
42168c2ecf20Sopenharmony_ci	const u32 mask = 0x000000ff;
42178c2ecf20Sopenharmony_ci	return ((rkey + 1) & mask) | (rkey & ~mask);
42188c2ecf20Sopenharmony_ci}
42198c2ecf20Sopenharmony_ci
42208c2ecf20Sopenharmony_ci/**
42218c2ecf20Sopenharmony_ci * ib_attach_mcast - Attaches the specified QP to a multicast group.
42228c2ecf20Sopenharmony_ci * @qp: QP to attach to the multicast group.  The QP must be type
42238c2ecf20Sopenharmony_ci *   IB_QPT_UD.
42248c2ecf20Sopenharmony_ci * @gid: Multicast group GID.
42258c2ecf20Sopenharmony_ci * @lid: Multicast group LID in host byte order.
42268c2ecf20Sopenharmony_ci *
42278c2ecf20Sopenharmony_ci * In order to send and receive multicast packets, subnet
42288c2ecf20Sopenharmony_ci * administration must have created the multicast group and configured
42298c2ecf20Sopenharmony_ci * the fabric appropriately.  The port associated with the specified
42308c2ecf20Sopenharmony_ci * QP must also be a member of the multicast group.
42318c2ecf20Sopenharmony_ci */
42328c2ecf20Sopenharmony_ciint ib_attach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid);
42338c2ecf20Sopenharmony_ci
42348c2ecf20Sopenharmony_ci/**
42358c2ecf20Sopenharmony_ci * ib_detach_mcast - Detaches the specified QP from a multicast group.
42368c2ecf20Sopenharmony_ci * @qp: QP to detach from the multicast group.
42378c2ecf20Sopenharmony_ci * @gid: Multicast group GID.
42388c2ecf20Sopenharmony_ci * @lid: Multicast group LID in host byte order.
42398c2ecf20Sopenharmony_ci */
42408c2ecf20Sopenharmony_ciint ib_detach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid);
42418c2ecf20Sopenharmony_ci
42428c2ecf20Sopenharmony_cistruct ib_xrcd *ib_alloc_xrcd_user(struct ib_device *device,
42438c2ecf20Sopenharmony_ci				   struct inode *inode, struct ib_udata *udata);
42448c2ecf20Sopenharmony_ciint ib_dealloc_xrcd_user(struct ib_xrcd *xrcd, struct ib_udata *udata);
42458c2ecf20Sopenharmony_ci
42468c2ecf20Sopenharmony_cistatic inline int ib_check_mr_access(int flags)
42478c2ecf20Sopenharmony_ci{
42488c2ecf20Sopenharmony_ci	/*
42498c2ecf20Sopenharmony_ci	 * Local write permission is required if remote write or
42508c2ecf20Sopenharmony_ci	 * remote atomic permission is also requested.
42518c2ecf20Sopenharmony_ci	 */
42528c2ecf20Sopenharmony_ci	if (flags & (IB_ACCESS_REMOTE_ATOMIC | IB_ACCESS_REMOTE_WRITE) &&
42538c2ecf20Sopenharmony_ci	    !(flags & IB_ACCESS_LOCAL_WRITE))
42548c2ecf20Sopenharmony_ci		return -EINVAL;
42558c2ecf20Sopenharmony_ci
42568c2ecf20Sopenharmony_ci	if (flags & ~IB_ACCESS_SUPPORTED)
42578c2ecf20Sopenharmony_ci		return -EINVAL;
42588c2ecf20Sopenharmony_ci
42598c2ecf20Sopenharmony_ci	return 0;
42608c2ecf20Sopenharmony_ci}
42618c2ecf20Sopenharmony_ci
42628c2ecf20Sopenharmony_cistatic inline bool ib_access_writable(int access_flags)
42638c2ecf20Sopenharmony_ci{
42648c2ecf20Sopenharmony_ci	/*
42658c2ecf20Sopenharmony_ci	 * We have writable memory backing the MR if any of the following
42668c2ecf20Sopenharmony_ci	 * access flags are set.  "Local write" and "remote write" obviously
42678c2ecf20Sopenharmony_ci	 * require write access.  "Remote atomic" can do things like fetch and
42688c2ecf20Sopenharmony_ci	 * add, which will modify memory, and "MW bind" can change permissions
42698c2ecf20Sopenharmony_ci	 * by binding a window.
42708c2ecf20Sopenharmony_ci	 */
42718c2ecf20Sopenharmony_ci	return access_flags &
42728c2ecf20Sopenharmony_ci		(IB_ACCESS_LOCAL_WRITE   | IB_ACCESS_REMOTE_WRITE |
42738c2ecf20Sopenharmony_ci		 IB_ACCESS_REMOTE_ATOMIC | IB_ACCESS_MW_BIND);
42748c2ecf20Sopenharmony_ci}
42758c2ecf20Sopenharmony_ci
42768c2ecf20Sopenharmony_ci/**
42778c2ecf20Sopenharmony_ci * ib_check_mr_status: lightweight check of MR status.
42788c2ecf20Sopenharmony_ci *     This routine may provide status checks on a selected
42798c2ecf20Sopenharmony_ci *     ib_mr. first use is for signature status check.
42808c2ecf20Sopenharmony_ci *
42818c2ecf20Sopenharmony_ci * @mr: A memory region.
42828c2ecf20Sopenharmony_ci * @check_mask: Bitmask of which checks to perform from
42838c2ecf20Sopenharmony_ci *     ib_mr_status_check enumeration.
42848c2ecf20Sopenharmony_ci * @mr_status: The container of relevant status checks.
42858c2ecf20Sopenharmony_ci *     failed checks will be indicated in the status bitmask
42868c2ecf20Sopenharmony_ci *     and the relevant info shall be in the error item.
42878c2ecf20Sopenharmony_ci */
42888c2ecf20Sopenharmony_ciint ib_check_mr_status(struct ib_mr *mr, u32 check_mask,
42898c2ecf20Sopenharmony_ci		       struct ib_mr_status *mr_status);
42908c2ecf20Sopenharmony_ci
42918c2ecf20Sopenharmony_ci/**
42928c2ecf20Sopenharmony_ci * ib_device_try_get: Hold a registration lock
42938c2ecf20Sopenharmony_ci * device: The device to lock
42948c2ecf20Sopenharmony_ci *
42958c2ecf20Sopenharmony_ci * A device under an active registration lock cannot become unregistered. It
42968c2ecf20Sopenharmony_ci * is only possible to obtain a registration lock on a device that is fully
42978c2ecf20Sopenharmony_ci * registered, otherwise this function returns false.
42988c2ecf20Sopenharmony_ci *
42998c2ecf20Sopenharmony_ci * The registration lock is only necessary for actions which require the
43008c2ecf20Sopenharmony_ci * device to still be registered. Uses that only require the device pointer to
43018c2ecf20Sopenharmony_ci * be valid should use get_device(&ibdev->dev) to hold the memory.
43028c2ecf20Sopenharmony_ci *
43038c2ecf20Sopenharmony_ci */
43048c2ecf20Sopenharmony_cistatic inline bool ib_device_try_get(struct ib_device *dev)
43058c2ecf20Sopenharmony_ci{
43068c2ecf20Sopenharmony_ci	return refcount_inc_not_zero(&dev->refcount);
43078c2ecf20Sopenharmony_ci}
43088c2ecf20Sopenharmony_ci
43098c2ecf20Sopenharmony_civoid ib_device_put(struct ib_device *device);
43108c2ecf20Sopenharmony_cistruct ib_device *ib_device_get_by_netdev(struct net_device *ndev,
43118c2ecf20Sopenharmony_ci					  enum rdma_driver_id driver_id);
43128c2ecf20Sopenharmony_cistruct ib_device *ib_device_get_by_name(const char *name,
43138c2ecf20Sopenharmony_ci					enum rdma_driver_id driver_id);
43148c2ecf20Sopenharmony_cistruct net_device *ib_get_net_dev_by_params(struct ib_device *dev, u8 port,
43158c2ecf20Sopenharmony_ci					    u16 pkey, const union ib_gid *gid,
43168c2ecf20Sopenharmony_ci					    const struct sockaddr *addr);
43178c2ecf20Sopenharmony_ciint ib_device_set_netdev(struct ib_device *ib_dev, struct net_device *ndev,
43188c2ecf20Sopenharmony_ci			 unsigned int port);
43198c2ecf20Sopenharmony_cistruct net_device *ib_device_netdev(struct ib_device *dev, u8 port);
43208c2ecf20Sopenharmony_ci
43218c2ecf20Sopenharmony_cistruct ib_wq *ib_create_wq(struct ib_pd *pd,
43228c2ecf20Sopenharmony_ci			   struct ib_wq_init_attr *init_attr);
43238c2ecf20Sopenharmony_ciint ib_destroy_wq_user(struct ib_wq *wq, struct ib_udata *udata);
43248c2ecf20Sopenharmony_ciint ib_modify_wq(struct ib_wq *wq, struct ib_wq_attr *attr,
43258c2ecf20Sopenharmony_ci		 u32 wq_attr_mask);
43268c2ecf20Sopenharmony_ci
43278c2ecf20Sopenharmony_ciint ib_map_mr_sg(struct ib_mr *mr, struct scatterlist *sg, int sg_nents,
43288c2ecf20Sopenharmony_ci		 unsigned int *sg_offset, unsigned int page_size);
43298c2ecf20Sopenharmony_ciint ib_map_mr_sg_pi(struct ib_mr *mr, struct scatterlist *data_sg,
43308c2ecf20Sopenharmony_ci		    int data_sg_nents, unsigned int *data_sg_offset,
43318c2ecf20Sopenharmony_ci		    struct scatterlist *meta_sg, int meta_sg_nents,
43328c2ecf20Sopenharmony_ci		    unsigned int *meta_sg_offset, unsigned int page_size);
43338c2ecf20Sopenharmony_ci
43348c2ecf20Sopenharmony_cistatic inline int
43358c2ecf20Sopenharmony_ciib_map_mr_sg_zbva(struct ib_mr *mr, struct scatterlist *sg, int sg_nents,
43368c2ecf20Sopenharmony_ci		  unsigned int *sg_offset, unsigned int page_size)
43378c2ecf20Sopenharmony_ci{
43388c2ecf20Sopenharmony_ci	int n;
43398c2ecf20Sopenharmony_ci
43408c2ecf20Sopenharmony_ci	n = ib_map_mr_sg(mr, sg, sg_nents, sg_offset, page_size);
43418c2ecf20Sopenharmony_ci	mr->iova = 0;
43428c2ecf20Sopenharmony_ci
43438c2ecf20Sopenharmony_ci	return n;
43448c2ecf20Sopenharmony_ci}
43458c2ecf20Sopenharmony_ci
43468c2ecf20Sopenharmony_ciint ib_sg_to_pages(struct ib_mr *mr, struct scatterlist *sgl, int sg_nents,
43478c2ecf20Sopenharmony_ci		unsigned int *sg_offset, int (*set_page)(struct ib_mr *, u64));
43488c2ecf20Sopenharmony_ci
43498c2ecf20Sopenharmony_civoid ib_drain_rq(struct ib_qp *qp);
43508c2ecf20Sopenharmony_civoid ib_drain_sq(struct ib_qp *qp);
43518c2ecf20Sopenharmony_civoid ib_drain_qp(struct ib_qp *qp);
43528c2ecf20Sopenharmony_ci
43538c2ecf20Sopenharmony_ciint ib_get_eth_speed(struct ib_device *dev, u8 port_num, u16 *speed, u8 *width);
43548c2ecf20Sopenharmony_ci
43558c2ecf20Sopenharmony_cistatic inline u8 *rdma_ah_retrieve_dmac(struct rdma_ah_attr *attr)
43568c2ecf20Sopenharmony_ci{
43578c2ecf20Sopenharmony_ci	if (attr->type == RDMA_AH_ATTR_TYPE_ROCE)
43588c2ecf20Sopenharmony_ci		return attr->roce.dmac;
43598c2ecf20Sopenharmony_ci	return NULL;
43608c2ecf20Sopenharmony_ci}
43618c2ecf20Sopenharmony_ci
43628c2ecf20Sopenharmony_cistatic inline void rdma_ah_set_dlid(struct rdma_ah_attr *attr, u32 dlid)
43638c2ecf20Sopenharmony_ci{
43648c2ecf20Sopenharmony_ci	if (attr->type == RDMA_AH_ATTR_TYPE_IB)
43658c2ecf20Sopenharmony_ci		attr->ib.dlid = (u16)dlid;
43668c2ecf20Sopenharmony_ci	else if (attr->type == RDMA_AH_ATTR_TYPE_OPA)
43678c2ecf20Sopenharmony_ci		attr->opa.dlid = dlid;
43688c2ecf20Sopenharmony_ci}
43698c2ecf20Sopenharmony_ci
43708c2ecf20Sopenharmony_cistatic inline u32 rdma_ah_get_dlid(const struct rdma_ah_attr *attr)
43718c2ecf20Sopenharmony_ci{
43728c2ecf20Sopenharmony_ci	if (attr->type == RDMA_AH_ATTR_TYPE_IB)
43738c2ecf20Sopenharmony_ci		return attr->ib.dlid;
43748c2ecf20Sopenharmony_ci	else if (attr->type == RDMA_AH_ATTR_TYPE_OPA)
43758c2ecf20Sopenharmony_ci		return attr->opa.dlid;
43768c2ecf20Sopenharmony_ci	return 0;
43778c2ecf20Sopenharmony_ci}
43788c2ecf20Sopenharmony_ci
43798c2ecf20Sopenharmony_cistatic inline void rdma_ah_set_sl(struct rdma_ah_attr *attr, u8 sl)
43808c2ecf20Sopenharmony_ci{
43818c2ecf20Sopenharmony_ci	attr->sl = sl;
43828c2ecf20Sopenharmony_ci}
43838c2ecf20Sopenharmony_ci
43848c2ecf20Sopenharmony_cistatic inline u8 rdma_ah_get_sl(const struct rdma_ah_attr *attr)
43858c2ecf20Sopenharmony_ci{
43868c2ecf20Sopenharmony_ci	return attr->sl;
43878c2ecf20Sopenharmony_ci}
43888c2ecf20Sopenharmony_ci
43898c2ecf20Sopenharmony_cistatic inline void rdma_ah_set_path_bits(struct rdma_ah_attr *attr,
43908c2ecf20Sopenharmony_ci					 u8 src_path_bits)
43918c2ecf20Sopenharmony_ci{
43928c2ecf20Sopenharmony_ci	if (attr->type == RDMA_AH_ATTR_TYPE_IB)
43938c2ecf20Sopenharmony_ci		attr->ib.src_path_bits = src_path_bits;
43948c2ecf20Sopenharmony_ci	else if (attr->type == RDMA_AH_ATTR_TYPE_OPA)
43958c2ecf20Sopenharmony_ci		attr->opa.src_path_bits = src_path_bits;
43968c2ecf20Sopenharmony_ci}
43978c2ecf20Sopenharmony_ci
43988c2ecf20Sopenharmony_cistatic inline u8 rdma_ah_get_path_bits(const struct rdma_ah_attr *attr)
43998c2ecf20Sopenharmony_ci{
44008c2ecf20Sopenharmony_ci	if (attr->type == RDMA_AH_ATTR_TYPE_IB)
44018c2ecf20Sopenharmony_ci		return attr->ib.src_path_bits;
44028c2ecf20Sopenharmony_ci	else if (attr->type == RDMA_AH_ATTR_TYPE_OPA)
44038c2ecf20Sopenharmony_ci		return attr->opa.src_path_bits;
44048c2ecf20Sopenharmony_ci	return 0;
44058c2ecf20Sopenharmony_ci}
44068c2ecf20Sopenharmony_ci
44078c2ecf20Sopenharmony_cistatic inline void rdma_ah_set_make_grd(struct rdma_ah_attr *attr,
44088c2ecf20Sopenharmony_ci					bool make_grd)
44098c2ecf20Sopenharmony_ci{
44108c2ecf20Sopenharmony_ci	if (attr->type == RDMA_AH_ATTR_TYPE_OPA)
44118c2ecf20Sopenharmony_ci		attr->opa.make_grd = make_grd;
44128c2ecf20Sopenharmony_ci}
44138c2ecf20Sopenharmony_ci
44148c2ecf20Sopenharmony_cistatic inline bool rdma_ah_get_make_grd(const struct rdma_ah_attr *attr)
44158c2ecf20Sopenharmony_ci{
44168c2ecf20Sopenharmony_ci	if (attr->type == RDMA_AH_ATTR_TYPE_OPA)
44178c2ecf20Sopenharmony_ci		return attr->opa.make_grd;
44188c2ecf20Sopenharmony_ci	return false;
44198c2ecf20Sopenharmony_ci}
44208c2ecf20Sopenharmony_ci
44218c2ecf20Sopenharmony_cistatic inline void rdma_ah_set_port_num(struct rdma_ah_attr *attr, u8 port_num)
44228c2ecf20Sopenharmony_ci{
44238c2ecf20Sopenharmony_ci	attr->port_num = port_num;
44248c2ecf20Sopenharmony_ci}
44258c2ecf20Sopenharmony_ci
44268c2ecf20Sopenharmony_cistatic inline u8 rdma_ah_get_port_num(const struct rdma_ah_attr *attr)
44278c2ecf20Sopenharmony_ci{
44288c2ecf20Sopenharmony_ci	return attr->port_num;
44298c2ecf20Sopenharmony_ci}
44308c2ecf20Sopenharmony_ci
44318c2ecf20Sopenharmony_cistatic inline void rdma_ah_set_static_rate(struct rdma_ah_attr *attr,
44328c2ecf20Sopenharmony_ci					   u8 static_rate)
44338c2ecf20Sopenharmony_ci{
44348c2ecf20Sopenharmony_ci	attr->static_rate = static_rate;
44358c2ecf20Sopenharmony_ci}
44368c2ecf20Sopenharmony_ci
44378c2ecf20Sopenharmony_cistatic inline u8 rdma_ah_get_static_rate(const struct rdma_ah_attr *attr)
44388c2ecf20Sopenharmony_ci{
44398c2ecf20Sopenharmony_ci	return attr->static_rate;
44408c2ecf20Sopenharmony_ci}
44418c2ecf20Sopenharmony_ci
44428c2ecf20Sopenharmony_cistatic inline void rdma_ah_set_ah_flags(struct rdma_ah_attr *attr,
44438c2ecf20Sopenharmony_ci					enum ib_ah_flags flag)
44448c2ecf20Sopenharmony_ci{
44458c2ecf20Sopenharmony_ci	attr->ah_flags = flag;
44468c2ecf20Sopenharmony_ci}
44478c2ecf20Sopenharmony_ci
44488c2ecf20Sopenharmony_cistatic inline enum ib_ah_flags
44498c2ecf20Sopenharmony_ci		rdma_ah_get_ah_flags(const struct rdma_ah_attr *attr)
44508c2ecf20Sopenharmony_ci{
44518c2ecf20Sopenharmony_ci	return attr->ah_flags;
44528c2ecf20Sopenharmony_ci}
44538c2ecf20Sopenharmony_ci
44548c2ecf20Sopenharmony_cistatic inline const struct ib_global_route
44558c2ecf20Sopenharmony_ci		*rdma_ah_read_grh(const struct rdma_ah_attr *attr)
44568c2ecf20Sopenharmony_ci{
44578c2ecf20Sopenharmony_ci	return &attr->grh;
44588c2ecf20Sopenharmony_ci}
44598c2ecf20Sopenharmony_ci
44608c2ecf20Sopenharmony_ci/*To retrieve and modify the grh */
44618c2ecf20Sopenharmony_cistatic inline struct ib_global_route
44628c2ecf20Sopenharmony_ci		*rdma_ah_retrieve_grh(struct rdma_ah_attr *attr)
44638c2ecf20Sopenharmony_ci{
44648c2ecf20Sopenharmony_ci	return &attr->grh;
44658c2ecf20Sopenharmony_ci}
44668c2ecf20Sopenharmony_ci
44678c2ecf20Sopenharmony_cistatic inline void rdma_ah_set_dgid_raw(struct rdma_ah_attr *attr, void *dgid)
44688c2ecf20Sopenharmony_ci{
44698c2ecf20Sopenharmony_ci	struct ib_global_route *grh = rdma_ah_retrieve_grh(attr);
44708c2ecf20Sopenharmony_ci
44718c2ecf20Sopenharmony_ci	memcpy(grh->dgid.raw, dgid, sizeof(grh->dgid));
44728c2ecf20Sopenharmony_ci}
44738c2ecf20Sopenharmony_ci
44748c2ecf20Sopenharmony_cistatic inline void rdma_ah_set_subnet_prefix(struct rdma_ah_attr *attr,
44758c2ecf20Sopenharmony_ci					     __be64 prefix)
44768c2ecf20Sopenharmony_ci{
44778c2ecf20Sopenharmony_ci	struct ib_global_route *grh = rdma_ah_retrieve_grh(attr);
44788c2ecf20Sopenharmony_ci
44798c2ecf20Sopenharmony_ci	grh->dgid.global.subnet_prefix = prefix;
44808c2ecf20Sopenharmony_ci}
44818c2ecf20Sopenharmony_ci
44828c2ecf20Sopenharmony_cistatic inline void rdma_ah_set_interface_id(struct rdma_ah_attr *attr,
44838c2ecf20Sopenharmony_ci					    __be64 if_id)
44848c2ecf20Sopenharmony_ci{
44858c2ecf20Sopenharmony_ci	struct ib_global_route *grh = rdma_ah_retrieve_grh(attr);
44868c2ecf20Sopenharmony_ci
44878c2ecf20Sopenharmony_ci	grh->dgid.global.interface_id = if_id;
44888c2ecf20Sopenharmony_ci}
44898c2ecf20Sopenharmony_ci
44908c2ecf20Sopenharmony_cistatic inline void rdma_ah_set_grh(struct rdma_ah_attr *attr,
44918c2ecf20Sopenharmony_ci				   union ib_gid *dgid, u32 flow_label,
44928c2ecf20Sopenharmony_ci				   u8 sgid_index, u8 hop_limit,
44938c2ecf20Sopenharmony_ci				   u8 traffic_class)
44948c2ecf20Sopenharmony_ci{
44958c2ecf20Sopenharmony_ci	struct ib_global_route *grh = rdma_ah_retrieve_grh(attr);
44968c2ecf20Sopenharmony_ci
44978c2ecf20Sopenharmony_ci	attr->ah_flags = IB_AH_GRH;
44988c2ecf20Sopenharmony_ci	if (dgid)
44998c2ecf20Sopenharmony_ci		grh->dgid = *dgid;
45008c2ecf20Sopenharmony_ci	grh->flow_label = flow_label;
45018c2ecf20Sopenharmony_ci	grh->sgid_index = sgid_index;
45028c2ecf20Sopenharmony_ci	grh->hop_limit = hop_limit;
45038c2ecf20Sopenharmony_ci	grh->traffic_class = traffic_class;
45048c2ecf20Sopenharmony_ci	grh->sgid_attr = NULL;
45058c2ecf20Sopenharmony_ci}
45068c2ecf20Sopenharmony_ci
45078c2ecf20Sopenharmony_civoid rdma_destroy_ah_attr(struct rdma_ah_attr *ah_attr);
45088c2ecf20Sopenharmony_civoid rdma_move_grh_sgid_attr(struct rdma_ah_attr *attr, union ib_gid *dgid,
45098c2ecf20Sopenharmony_ci			     u32 flow_label, u8 hop_limit, u8 traffic_class,
45108c2ecf20Sopenharmony_ci			     const struct ib_gid_attr *sgid_attr);
45118c2ecf20Sopenharmony_civoid rdma_copy_ah_attr(struct rdma_ah_attr *dest,
45128c2ecf20Sopenharmony_ci		       const struct rdma_ah_attr *src);
45138c2ecf20Sopenharmony_civoid rdma_replace_ah_attr(struct rdma_ah_attr *old,
45148c2ecf20Sopenharmony_ci			  const struct rdma_ah_attr *new);
45158c2ecf20Sopenharmony_civoid rdma_move_ah_attr(struct rdma_ah_attr *dest, struct rdma_ah_attr *src);
45168c2ecf20Sopenharmony_ci
45178c2ecf20Sopenharmony_ci/**
45188c2ecf20Sopenharmony_ci * rdma_ah_find_type - Return address handle type.
45198c2ecf20Sopenharmony_ci *
45208c2ecf20Sopenharmony_ci * @dev: Device to be checked
45218c2ecf20Sopenharmony_ci * @port_num: Port number
45228c2ecf20Sopenharmony_ci */
45238c2ecf20Sopenharmony_cistatic inline enum rdma_ah_attr_type rdma_ah_find_type(struct ib_device *dev,
45248c2ecf20Sopenharmony_ci						       u8 port_num)
45258c2ecf20Sopenharmony_ci{
45268c2ecf20Sopenharmony_ci	if (rdma_protocol_roce(dev, port_num))
45278c2ecf20Sopenharmony_ci		return RDMA_AH_ATTR_TYPE_ROCE;
45288c2ecf20Sopenharmony_ci	if (rdma_protocol_ib(dev, port_num)) {
45298c2ecf20Sopenharmony_ci		if (rdma_cap_opa_ah(dev, port_num))
45308c2ecf20Sopenharmony_ci			return RDMA_AH_ATTR_TYPE_OPA;
45318c2ecf20Sopenharmony_ci		return RDMA_AH_ATTR_TYPE_IB;
45328c2ecf20Sopenharmony_ci	}
45338c2ecf20Sopenharmony_ci
45348c2ecf20Sopenharmony_ci	return RDMA_AH_ATTR_TYPE_UNDEFINED;
45358c2ecf20Sopenharmony_ci}
45368c2ecf20Sopenharmony_ci
45378c2ecf20Sopenharmony_ci/**
45388c2ecf20Sopenharmony_ci * ib_lid_cpu16 - Return lid in 16bit CPU encoding.
45398c2ecf20Sopenharmony_ci *     In the current implementation the only way to get
45408c2ecf20Sopenharmony_ci *     get the 32bit lid is from other sources for OPA.
45418c2ecf20Sopenharmony_ci *     For IB, lids will always be 16bits so cast the
45428c2ecf20Sopenharmony_ci *     value accordingly.
45438c2ecf20Sopenharmony_ci *
45448c2ecf20Sopenharmony_ci * @lid: A 32bit LID
45458c2ecf20Sopenharmony_ci */
45468c2ecf20Sopenharmony_cistatic inline u16 ib_lid_cpu16(u32 lid)
45478c2ecf20Sopenharmony_ci{
45488c2ecf20Sopenharmony_ci	WARN_ON_ONCE(lid & 0xFFFF0000);
45498c2ecf20Sopenharmony_ci	return (u16)lid;
45508c2ecf20Sopenharmony_ci}
45518c2ecf20Sopenharmony_ci
45528c2ecf20Sopenharmony_ci/**
45538c2ecf20Sopenharmony_ci * ib_lid_be16 - Return lid in 16bit BE encoding.
45548c2ecf20Sopenharmony_ci *
45558c2ecf20Sopenharmony_ci * @lid: A 32bit LID
45568c2ecf20Sopenharmony_ci */
45578c2ecf20Sopenharmony_cistatic inline __be16 ib_lid_be16(u32 lid)
45588c2ecf20Sopenharmony_ci{
45598c2ecf20Sopenharmony_ci	WARN_ON_ONCE(lid & 0xFFFF0000);
45608c2ecf20Sopenharmony_ci	return cpu_to_be16((u16)lid);
45618c2ecf20Sopenharmony_ci}
45628c2ecf20Sopenharmony_ci
45638c2ecf20Sopenharmony_ci/**
45648c2ecf20Sopenharmony_ci * ib_get_vector_affinity - Get the affinity mappings of a given completion
45658c2ecf20Sopenharmony_ci *   vector
45668c2ecf20Sopenharmony_ci * @device:         the rdma device
45678c2ecf20Sopenharmony_ci * @comp_vector:    index of completion vector
45688c2ecf20Sopenharmony_ci *
45698c2ecf20Sopenharmony_ci * Returns NULL on failure, otherwise a corresponding cpu map of the
45708c2ecf20Sopenharmony_ci * completion vector (returns all-cpus map if the device driver doesn't
45718c2ecf20Sopenharmony_ci * implement get_vector_affinity).
45728c2ecf20Sopenharmony_ci */
45738c2ecf20Sopenharmony_cistatic inline const struct cpumask *
45748c2ecf20Sopenharmony_ciib_get_vector_affinity(struct ib_device *device, int comp_vector)
45758c2ecf20Sopenharmony_ci{
45768c2ecf20Sopenharmony_ci	if (comp_vector < 0 || comp_vector >= device->num_comp_vectors ||
45778c2ecf20Sopenharmony_ci	    !device->ops.get_vector_affinity)
45788c2ecf20Sopenharmony_ci		return NULL;
45798c2ecf20Sopenharmony_ci
45808c2ecf20Sopenharmony_ci	return device->ops.get_vector_affinity(device, comp_vector);
45818c2ecf20Sopenharmony_ci
45828c2ecf20Sopenharmony_ci}
45838c2ecf20Sopenharmony_ci
45848c2ecf20Sopenharmony_ci/**
45858c2ecf20Sopenharmony_ci * rdma_roce_rescan_device - Rescan all of the network devices in the system
45868c2ecf20Sopenharmony_ci * and add their gids, as needed, to the relevant RoCE devices.
45878c2ecf20Sopenharmony_ci *
45888c2ecf20Sopenharmony_ci * @device:         the rdma device
45898c2ecf20Sopenharmony_ci */
45908c2ecf20Sopenharmony_civoid rdma_roce_rescan_device(struct ib_device *ibdev);
45918c2ecf20Sopenharmony_ci
45928c2ecf20Sopenharmony_cistruct ib_ucontext *ib_uverbs_get_ucontext_file(struct ib_uverbs_file *ufile);
45938c2ecf20Sopenharmony_ci
45948c2ecf20Sopenharmony_ciint uverbs_destroy_def_handler(struct uverbs_attr_bundle *attrs);
45958c2ecf20Sopenharmony_ci
45968c2ecf20Sopenharmony_cistruct net_device *rdma_alloc_netdev(struct ib_device *device, u8 port_num,
45978c2ecf20Sopenharmony_ci				     enum rdma_netdev_t type, const char *name,
45988c2ecf20Sopenharmony_ci				     unsigned char name_assign_type,
45998c2ecf20Sopenharmony_ci				     void (*setup)(struct net_device *));
46008c2ecf20Sopenharmony_ci
46018c2ecf20Sopenharmony_ciint rdma_init_netdev(struct ib_device *device, u8 port_num,
46028c2ecf20Sopenharmony_ci		     enum rdma_netdev_t type, const char *name,
46038c2ecf20Sopenharmony_ci		     unsigned char name_assign_type,
46048c2ecf20Sopenharmony_ci		     void (*setup)(struct net_device *),
46058c2ecf20Sopenharmony_ci		     struct net_device *netdev);
46068c2ecf20Sopenharmony_ci
46078c2ecf20Sopenharmony_ci/**
46088c2ecf20Sopenharmony_ci * rdma_set_device_sysfs_group - Set device attributes group to have
46098c2ecf20Sopenharmony_ci *				 driver specific sysfs entries at
46108c2ecf20Sopenharmony_ci *				 for infiniband class.
46118c2ecf20Sopenharmony_ci *
46128c2ecf20Sopenharmony_ci * @device:	device pointer for which attributes to be created
46138c2ecf20Sopenharmony_ci * @group:	Pointer to group which should be added when device
46148c2ecf20Sopenharmony_ci *		is registered with sysfs.
46158c2ecf20Sopenharmony_ci * rdma_set_device_sysfs_group() allows existing drivers to expose one
46168c2ecf20Sopenharmony_ci * group per device to have sysfs attributes.
46178c2ecf20Sopenharmony_ci *
46188c2ecf20Sopenharmony_ci * NOTE: New drivers should not make use of this API; instead new device
46198c2ecf20Sopenharmony_ci * parameter should be exposed via netlink command. This API and mechanism
46208c2ecf20Sopenharmony_ci * exist only for existing drivers.
46218c2ecf20Sopenharmony_ci */
46228c2ecf20Sopenharmony_cistatic inline void
46238c2ecf20Sopenharmony_cirdma_set_device_sysfs_group(struct ib_device *dev,
46248c2ecf20Sopenharmony_ci			    const struct attribute_group *group)
46258c2ecf20Sopenharmony_ci{
46268c2ecf20Sopenharmony_ci	dev->groups[1] = group;
46278c2ecf20Sopenharmony_ci}
46288c2ecf20Sopenharmony_ci
46298c2ecf20Sopenharmony_ci/**
46308c2ecf20Sopenharmony_ci * rdma_device_to_ibdev - Get ib_device pointer from device pointer
46318c2ecf20Sopenharmony_ci *
46328c2ecf20Sopenharmony_ci * @device:	device pointer for which ib_device pointer to retrieve
46338c2ecf20Sopenharmony_ci *
46348c2ecf20Sopenharmony_ci * rdma_device_to_ibdev() retrieves ib_device pointer from device.
46358c2ecf20Sopenharmony_ci *
46368c2ecf20Sopenharmony_ci */
46378c2ecf20Sopenharmony_cistatic inline struct ib_device *rdma_device_to_ibdev(struct device *device)
46388c2ecf20Sopenharmony_ci{
46398c2ecf20Sopenharmony_ci	struct ib_core_device *coredev =
46408c2ecf20Sopenharmony_ci		container_of(device, struct ib_core_device, dev);
46418c2ecf20Sopenharmony_ci
46428c2ecf20Sopenharmony_ci	return coredev->owner;
46438c2ecf20Sopenharmony_ci}
46448c2ecf20Sopenharmony_ci
46458c2ecf20Sopenharmony_ci/**
46468c2ecf20Sopenharmony_ci * ibdev_to_node - return the NUMA node for a given ib_device
46478c2ecf20Sopenharmony_ci * @dev:	device to get the NUMA node for.
46488c2ecf20Sopenharmony_ci */
46498c2ecf20Sopenharmony_cistatic inline int ibdev_to_node(struct ib_device *ibdev)
46508c2ecf20Sopenharmony_ci{
46518c2ecf20Sopenharmony_ci	struct device *parent = ibdev->dev.parent;
46528c2ecf20Sopenharmony_ci
46538c2ecf20Sopenharmony_ci	if (!parent)
46548c2ecf20Sopenharmony_ci		return NUMA_NO_NODE;
46558c2ecf20Sopenharmony_ci	return dev_to_node(parent);
46568c2ecf20Sopenharmony_ci}
46578c2ecf20Sopenharmony_ci
46588c2ecf20Sopenharmony_ci/**
46598c2ecf20Sopenharmony_ci * rdma_device_to_drv_device - Helper macro to reach back to driver's
46608c2ecf20Sopenharmony_ci *			       ib_device holder structure from device pointer.
46618c2ecf20Sopenharmony_ci *
46628c2ecf20Sopenharmony_ci * NOTE: New drivers should not make use of this API; This API is only for
46638c2ecf20Sopenharmony_ci * existing drivers who have exposed sysfs entries using
46648c2ecf20Sopenharmony_ci * rdma_set_device_sysfs_group().
46658c2ecf20Sopenharmony_ci */
46668c2ecf20Sopenharmony_ci#define rdma_device_to_drv_device(dev, drv_dev_struct, ibdev_member)           \
46678c2ecf20Sopenharmony_ci	container_of(rdma_device_to_ibdev(dev), drv_dev_struct, ibdev_member)
46688c2ecf20Sopenharmony_ci
46698c2ecf20Sopenharmony_cibool rdma_dev_access_netns(const struct ib_device *device,
46708c2ecf20Sopenharmony_ci			   const struct net *net);
46718c2ecf20Sopenharmony_ci
46728c2ecf20Sopenharmony_ci#define IB_ROCE_UDP_ENCAP_VALID_PORT_MIN (0xC000)
46738c2ecf20Sopenharmony_ci#define IB_ROCE_UDP_ENCAP_VALID_PORT_MAX (0xFFFF)
46748c2ecf20Sopenharmony_ci#define IB_GRH_FLOWLABEL_MASK (0x000FFFFF)
46758c2ecf20Sopenharmony_ci
46768c2ecf20Sopenharmony_ci/**
46778c2ecf20Sopenharmony_ci * rdma_flow_label_to_udp_sport - generate a RoCE v2 UDP src port value based
46788c2ecf20Sopenharmony_ci *                               on the flow_label
46798c2ecf20Sopenharmony_ci *
46808c2ecf20Sopenharmony_ci * This function will convert the 20 bit flow_label input to a valid RoCE v2
46818c2ecf20Sopenharmony_ci * UDP src port 14 bit value. All RoCE V2 drivers should use this same
46828c2ecf20Sopenharmony_ci * convention.
46838c2ecf20Sopenharmony_ci */
46848c2ecf20Sopenharmony_cistatic inline u16 rdma_flow_label_to_udp_sport(u32 fl)
46858c2ecf20Sopenharmony_ci{
46868c2ecf20Sopenharmony_ci	u32 fl_low = fl & 0x03fff, fl_high = fl & 0xFC000;
46878c2ecf20Sopenharmony_ci
46888c2ecf20Sopenharmony_ci	fl_low ^= fl_high >> 14;
46898c2ecf20Sopenharmony_ci	return (u16)(fl_low | IB_ROCE_UDP_ENCAP_VALID_PORT_MIN);
46908c2ecf20Sopenharmony_ci}
46918c2ecf20Sopenharmony_ci
46928c2ecf20Sopenharmony_ci/**
46938c2ecf20Sopenharmony_ci * rdma_calc_flow_label - generate a RDMA symmetric flow label value based on
46948c2ecf20Sopenharmony_ci *                        local and remote qpn values
46958c2ecf20Sopenharmony_ci *
46968c2ecf20Sopenharmony_ci * This function folded the multiplication results of two qpns, 24 bit each,
46978c2ecf20Sopenharmony_ci * fields, and converts it to a 20 bit results.
46988c2ecf20Sopenharmony_ci *
46998c2ecf20Sopenharmony_ci * This function will create symmetric flow_label value based on the local
47008c2ecf20Sopenharmony_ci * and remote qpn values. this will allow both the requester and responder
47018c2ecf20Sopenharmony_ci * to calculate the same flow_label for a given connection.
47028c2ecf20Sopenharmony_ci *
47038c2ecf20Sopenharmony_ci * This helper function should be used by driver in case the upper layer
47048c2ecf20Sopenharmony_ci * provide a zero flow_label value. This is to improve entropy of RDMA
47058c2ecf20Sopenharmony_ci * traffic in the network.
47068c2ecf20Sopenharmony_ci */
47078c2ecf20Sopenharmony_cistatic inline u32 rdma_calc_flow_label(u32 lqpn, u32 rqpn)
47088c2ecf20Sopenharmony_ci{
47098c2ecf20Sopenharmony_ci	u64 v = (u64)lqpn * rqpn;
47108c2ecf20Sopenharmony_ci
47118c2ecf20Sopenharmony_ci	v ^= v >> 20;
47128c2ecf20Sopenharmony_ci	v ^= v >> 40;
47138c2ecf20Sopenharmony_ci
47148c2ecf20Sopenharmony_ci	return (u32)(v & IB_GRH_FLOWLABEL_MASK);
47158c2ecf20Sopenharmony_ci}
47168c2ecf20Sopenharmony_ci#endif /* IB_VERBS_H */
4717