xref: /openbmc/linux/include/rdma/ib_mad.h (revision 03ab8e6297acd1bc0eedaa050e2a1635c576fd11)
16bf9d8f6SLeon Romanovsky /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
2a4d61e84SRoland Dreier /*
3a4d61e84SRoland Dreier  * Copyright (c) 2004 Mellanox Technologies Ltd.  All rights reserved.
4a4d61e84SRoland Dreier  * Copyright (c) 2004 Infinicon Corporation.  All rights reserved.
5a4d61e84SRoland Dreier  * Copyright (c) 2004 Intel Corporation.  All rights reserved.
6a4d61e84SRoland Dreier  * Copyright (c) 2004 Topspin Corporation.  All rights reserved.
7618a3c03SHal Rosenstock  * Copyright (c) 2004-2006 Voltaire Corporation.  All rights reserved.
8a4d61e84SRoland Dreier  */
9a4d61e84SRoland Dreier 
106bf9d8f6SLeon Romanovsky #ifndef IB_MAD_H
11a4d61e84SRoland Dreier #define IB_MAD_H
12a4d61e84SRoland Dreier 
13e8b398deSDotan Barak #include <linux/list.h>
14e8b398deSDotan Barak 
15a4d61e84SRoland Dreier #include <rdma/ib_verbs.h>
161471cb6cSIra Weiny #include <uapi/rdma/ib_user_mad.h>
17a4d61e84SRoland Dreier 
18548ead17SIra Weiny /* Management base versions */
19a4d61e84SRoland Dreier #define IB_MGMT_BASE_VERSION			1
20548ead17SIra Weiny #define OPA_MGMT_BASE_VERSION			0x80
21548ead17SIra Weiny 
229fa240bbSHal Rosenstock #define OPA_SM_CLASS_VERSION			0x80
23a4d61e84SRoland Dreier 
24a4d61e84SRoland Dreier /* Management classes */
25a4d61e84SRoland Dreier #define IB_MGMT_CLASS_SUBN_LID_ROUTED		0x01
26a4d61e84SRoland Dreier #define IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE	0x81
27a4d61e84SRoland Dreier #define IB_MGMT_CLASS_SUBN_ADM			0x03
28a4d61e84SRoland Dreier #define IB_MGMT_CLASS_PERF_MGMT			0x04
29a4d61e84SRoland Dreier #define IB_MGMT_CLASS_BM			0x05
30a4d61e84SRoland Dreier #define IB_MGMT_CLASS_DEVICE_MGMT		0x06
31a4d61e84SRoland Dreier #define IB_MGMT_CLASS_CM			0x07
32a4d61e84SRoland Dreier #define IB_MGMT_CLASS_SNMP			0x08
33618a3c03SHal Rosenstock #define IB_MGMT_CLASS_DEVICE_ADM		0x10
34618a3c03SHal Rosenstock #define IB_MGMT_CLASS_BOOT_MGMT			0x11
35618a3c03SHal Rosenstock #define IB_MGMT_CLASS_BIS			0x12
36618a3c03SHal Rosenstock #define IB_MGMT_CLASS_CONG_MGMT			0x21
37a4d61e84SRoland Dreier #define IB_MGMT_CLASS_VENDOR_RANGE2_START	0x30
38a4d61e84SRoland Dreier #define IB_MGMT_CLASS_VENDOR_RANGE2_END		0x4F
39a4d61e84SRoland Dreier 
40a4d61e84SRoland Dreier #define	IB_OPENIB_OUI				(0x001405)
41a4d61e84SRoland Dreier 
42a4d61e84SRoland Dreier /* Management methods */
43a4d61e84SRoland Dreier #define IB_MGMT_METHOD_GET			0x01
44a4d61e84SRoland Dreier #define IB_MGMT_METHOD_SET			0x02
45a4d61e84SRoland Dreier #define IB_MGMT_METHOD_GET_RESP			0x81
46a4d61e84SRoland Dreier #define IB_MGMT_METHOD_SEND			0x03
47a4d61e84SRoland Dreier #define IB_MGMT_METHOD_TRAP			0x05
48a4d61e84SRoland Dreier #define IB_MGMT_METHOD_REPORT			0x06
49a4d61e84SRoland Dreier #define IB_MGMT_METHOD_REPORT_RESP		0x86
50a4d61e84SRoland Dreier #define IB_MGMT_METHOD_TRAP_REPRESS		0x07
51a4d61e84SRoland Dreier 
52a4d61e84SRoland Dreier #define IB_MGMT_METHOD_RESP			0x80
532527e681SSean Hefty #define IB_BM_ATTR_MOD_RESP			cpu_to_be32(1)
54a4d61e84SRoland Dreier 
55a4d61e84SRoland Dreier #define IB_MGMT_MAX_METHODS			128
56a4d61e84SRoland Dreier 
57d144b650SSwapna Thete /* MAD Status field bit masks */
58d144b650SSwapna Thete #define IB_MGMT_MAD_STATUS_SUCCESS			0x0000
59d144b650SSwapna Thete #define IB_MGMT_MAD_STATUS_BUSY				0x0001
60d144b650SSwapna Thete #define IB_MGMT_MAD_STATUS_REDIRECT_REQD		0x0002
61d144b650SSwapna Thete #define IB_MGMT_MAD_STATUS_BAD_VERSION			0x0004
62d144b650SSwapna Thete #define IB_MGMT_MAD_STATUS_UNSUPPORTED_METHOD		0x0008
63d144b650SSwapna Thete #define IB_MGMT_MAD_STATUS_UNSUPPORTED_METHOD_ATTRIB	0x000c
64d144b650SSwapna Thete #define IB_MGMT_MAD_STATUS_INVALID_ATTRIB_VALUE		0x001c
65d144b650SSwapna Thete 
66a4d61e84SRoland Dreier /* RMPP information */
67a4d61e84SRoland Dreier #define IB_MGMT_RMPP_VERSION			1
68a4d61e84SRoland Dreier 
69a4d61e84SRoland Dreier #define IB_MGMT_RMPP_TYPE_DATA			1
70a4d61e84SRoland Dreier #define IB_MGMT_RMPP_TYPE_ACK			2
71a4d61e84SRoland Dreier #define IB_MGMT_RMPP_TYPE_STOP			3
72a4d61e84SRoland Dreier #define IB_MGMT_RMPP_TYPE_ABORT			4
73a4d61e84SRoland Dreier 
74a4d61e84SRoland Dreier #define IB_MGMT_RMPP_FLAG_ACTIVE		1
75a4d61e84SRoland Dreier #define IB_MGMT_RMPP_FLAG_FIRST			(1<<1)
76a4d61e84SRoland Dreier #define IB_MGMT_RMPP_FLAG_LAST			(1<<2)
77a4d61e84SRoland Dreier 
78a4d61e84SRoland Dreier #define IB_MGMT_RMPP_NO_RESPTIME		0x1F
79a4d61e84SRoland Dreier 
80a4d61e84SRoland Dreier #define	IB_MGMT_RMPP_STATUS_SUCCESS		0
81a4d61e84SRoland Dreier #define	IB_MGMT_RMPP_STATUS_RESX		1
82a4d61e84SRoland Dreier #define	IB_MGMT_RMPP_STATUS_ABORT_MIN		118
83a4d61e84SRoland Dreier #define	IB_MGMT_RMPP_STATUS_T2L			118
84a4d61e84SRoland Dreier #define	IB_MGMT_RMPP_STATUS_BAD_LEN		119
85a4d61e84SRoland Dreier #define	IB_MGMT_RMPP_STATUS_BAD_SEG		120
86a4d61e84SRoland Dreier #define	IB_MGMT_RMPP_STATUS_BADT		121
87a4d61e84SRoland Dreier #define	IB_MGMT_RMPP_STATUS_W2S			122
88a4d61e84SRoland Dreier #define	IB_MGMT_RMPP_STATUS_S2B			123
89a4d61e84SRoland Dreier #define	IB_MGMT_RMPP_STATUS_BAD_STATUS		124
90a4d61e84SRoland Dreier #define	IB_MGMT_RMPP_STATUS_UNV			125
91a4d61e84SRoland Dreier #define	IB_MGMT_RMPP_STATUS_TMR			126
92a4d61e84SRoland Dreier #define	IB_MGMT_RMPP_STATUS_UNSPEC		127
93a4d61e84SRoland Dreier #define	IB_MGMT_RMPP_STATUS_ABORT_MAX		127
94a4d61e84SRoland Dreier 
95a4d61e84SRoland Dreier #define IB_QP0		0
969c3da099SHarvey Harrison #define IB_QP1		cpu_to_be32(1)
97a4d61e84SRoland Dreier #define IB_QP1_QKEY	0x80010000
98a4d61e84SRoland Dreier #define IB_QP_SET_QKEY	0x80000000
99a4d61e84SRoland Dreier 
1002aec5c60SSean Hefty #define IB_DEFAULT_PKEY_PARTIAL 0x7FFF
1012aec5c60SSean Hefty #define IB_DEFAULT_PKEY_FULL	0xFFFF
1022aec5c60SSean Hefty 
103d4ab3470SDennis Dalessandro /*
104d4ab3470SDennis Dalessandro  * Generic trap/notice types
105d4ab3470SDennis Dalessandro  */
106d4ab3470SDennis Dalessandro #define IB_NOTICE_TYPE_FATAL	0x80
107d4ab3470SDennis Dalessandro #define IB_NOTICE_TYPE_URGENT	0x81
108d4ab3470SDennis Dalessandro #define IB_NOTICE_TYPE_SECURITY	0x82
109d4ab3470SDennis Dalessandro #define IB_NOTICE_TYPE_SM	0x83
110d4ab3470SDennis Dalessandro #define IB_NOTICE_TYPE_INFO	0x84
111d4ab3470SDennis Dalessandro 
112d4ab3470SDennis Dalessandro /*
113d4ab3470SDennis Dalessandro  * Generic trap/notice producers
114d4ab3470SDennis Dalessandro  */
115d4ab3470SDennis Dalessandro #define IB_NOTICE_PROD_CA		cpu_to_be16(1)
116d4ab3470SDennis Dalessandro #define IB_NOTICE_PROD_SWITCH		cpu_to_be16(2)
117d4ab3470SDennis Dalessandro #define IB_NOTICE_PROD_ROUTER		cpu_to_be16(3)
118d4ab3470SDennis Dalessandro #define IB_NOTICE_PROD_CLASS_MGR	cpu_to_be16(4)
119d4ab3470SDennis Dalessandro 
120972d512aSSean Hefty enum {
12134816ad9SSean Hefty 	IB_MGMT_MAD_HDR = 24,
122972d512aSSean Hefty 	IB_MGMT_MAD_DATA = 232,
12334816ad9SSean Hefty 	IB_MGMT_RMPP_HDR = 36,
124972d512aSSean Hefty 	IB_MGMT_RMPP_DATA = 220,
12534816ad9SSean Hefty 	IB_MGMT_VENDOR_HDR = 40,
126972d512aSSean Hefty 	IB_MGMT_VENDOR_DATA = 216,
12734816ad9SSean Hefty 	IB_MGMT_SA_HDR = 56,
12834816ad9SSean Hefty 	IB_MGMT_SA_DATA = 200,
129618a3c03SHal Rosenstock 	IB_MGMT_DEVICE_HDR = 64,
130618a3c03SHal Rosenstock 	IB_MGMT_DEVICE_DATA = 192,
131337877a4SIra Weiny 	IB_MGMT_MAD_SIZE = IB_MGMT_MAD_HDR + IB_MGMT_MAD_DATA,
132548ead17SIra Weiny 	OPA_MGMT_MAD_DATA = 2024,
133548ead17SIra Weiny 	OPA_MGMT_RMPP_DATA = 2012,
134548ead17SIra Weiny 	OPA_MGMT_MAD_SIZE = IB_MGMT_MAD_HDR + OPA_MGMT_MAD_DATA,
135972d512aSSean Hefty };
136972d512aSSean Hefty 
137a4d61e84SRoland Dreier struct ib_mad_hdr {
138a4d61e84SRoland Dreier 	u8	base_version;
139a4d61e84SRoland Dreier 	u8	mgmt_class;
140a4d61e84SRoland Dreier 	u8	class_version;
141a4d61e84SRoland Dreier 	u8	method;
142a4d61e84SRoland Dreier 	__be16	status;
143a4d61e84SRoland Dreier 	__be16	class_specific;
144a4d61e84SRoland Dreier 	__be64	tid;
145a4d61e84SRoland Dreier 	__be16	attr_id;
146a4d61e84SRoland Dreier 	__be16	resv;
147a4d61e84SRoland Dreier 	__be32	attr_mod;
148a4d61e84SRoland Dreier };
149a4d61e84SRoland Dreier 
150a4d61e84SRoland Dreier struct ib_rmpp_hdr {
151a4d61e84SRoland Dreier 	u8	rmpp_version;
152a4d61e84SRoland Dreier 	u8	rmpp_type;
153a4d61e84SRoland Dreier 	u8	rmpp_rtime_flags;
154a4d61e84SRoland Dreier 	u8	rmpp_status;
155a4d61e84SRoland Dreier 	__be32	seg_num;
156a4d61e84SRoland Dreier 	__be32	paylen_newwin;
157a4d61e84SRoland Dreier };
158a4d61e84SRoland Dreier 
159a4d61e84SRoland Dreier typedef u64 __bitwise ib_sa_comp_mask;
160a4d61e84SRoland Dreier 
16102daaf27SJack Morgenstein #define IB_SA_COMP_MASK(n) ((__force ib_sa_comp_mask) cpu_to_be64(1ull << (n)))
162a4d61e84SRoland Dreier 
163a4d61e84SRoland Dreier /*
164a4d61e84SRoland Dreier  * ib_sa_hdr and ib_sa_mad structures must be packed because they have
165a4d61e84SRoland Dreier  * 64-bit fields that are only 32-bit aligned. 64-bit architectures will
166a4d61e84SRoland Dreier  * lay them out wrong otherwise.  (And unfortunately they are sent on
167a4d61e84SRoland Dreier  * the wire so we can't change the layout)
168a4d61e84SRoland Dreier  */
169a4d61e84SRoland Dreier struct ib_sa_hdr {
170a4d61e84SRoland Dreier 	__be64			sm_key;
171a4d61e84SRoland Dreier 	__be16			attr_offset;
172a4d61e84SRoland Dreier 	__be16			reserved;
173a4d61e84SRoland Dreier 	ib_sa_comp_mask		comp_mask;
17419b1a294SErez Alfasi } __packed;
175a4d61e84SRoland Dreier 
176a4d61e84SRoland Dreier struct ib_mad {
177a4d61e84SRoland Dreier 	struct ib_mad_hdr	mad_hdr;
178972d512aSSean Hefty 	u8			data[IB_MGMT_MAD_DATA];
179a4d61e84SRoland Dreier };
180a4d61e84SRoland Dreier 
181548ead17SIra Weiny struct opa_mad {
182548ead17SIra Weiny 	struct ib_mad_hdr	mad_hdr;
183548ead17SIra Weiny 	u8			data[OPA_MGMT_MAD_DATA];
184548ead17SIra Weiny };
185548ead17SIra Weiny 
186a4d61e84SRoland Dreier struct ib_rmpp_mad {
187a4d61e84SRoland Dreier 	struct ib_mad_hdr	mad_hdr;
188a4d61e84SRoland Dreier 	struct ib_rmpp_hdr	rmpp_hdr;
189972d512aSSean Hefty 	u8			data[IB_MGMT_RMPP_DATA];
190a4d61e84SRoland Dreier };
191a4d61e84SRoland Dreier 
1928e4349d1SIra Weiny struct opa_rmpp_mad {
1938e4349d1SIra Weiny 	struct ib_mad_hdr	mad_hdr;
1948e4349d1SIra Weiny 	struct ib_rmpp_hdr	rmpp_hdr;
1958e4349d1SIra Weiny 	u8			data[OPA_MGMT_RMPP_DATA];
1968e4349d1SIra Weiny };
1978e4349d1SIra Weiny 
198a4d61e84SRoland Dreier struct ib_sa_mad {
199a4d61e84SRoland Dreier 	struct ib_mad_hdr	mad_hdr;
200a4d61e84SRoland Dreier 	struct ib_rmpp_hdr	rmpp_hdr;
201a4d61e84SRoland Dreier 	struct ib_sa_hdr	sa_hdr;
202972d512aSSean Hefty 	u8			data[IB_MGMT_SA_DATA];
20319b1a294SErez Alfasi } __packed;
204a4d61e84SRoland Dreier 
205a4d61e84SRoland Dreier struct ib_vendor_mad {
206a4d61e84SRoland Dreier 	struct ib_mad_hdr	mad_hdr;
207a4d61e84SRoland Dreier 	struct ib_rmpp_hdr	rmpp_hdr;
208a4d61e84SRoland Dreier 	u8			reserved;
209a4d61e84SRoland Dreier 	u8			oui[3];
210972d512aSSean Hefty 	u8			data[IB_MGMT_VENDOR_DATA];
211a4d61e84SRoland Dreier };
212a4d61e84SRoland Dreier 
21353370886SHal Rosenstock #define IB_MGMT_CLASSPORTINFO_ATTR_ID	cpu_to_be16(0x0001)
21453370886SHal Rosenstock 
215507f6afaSErez Shitrit #define IB_CLASS_PORT_INFO_RESP_TIME_MASK	0x1F
216507f6afaSErez Shitrit #define IB_CLASS_PORT_INFO_RESP_TIME_FIELD_SIZE 5
217507f6afaSErez Shitrit 
2184deccd6dSDotan Barak struct ib_class_port_info {
2192e9f7cb7SRoland Dreier 	u8			base_version;
2202e9f7cb7SRoland Dreier 	u8			class_version;
2212e9f7cb7SRoland Dreier 	__be16			capability_mask;
222507f6afaSErez Shitrit 	  /* 27 bits for cap_mask2, 5 bits for resp_time */
223507f6afaSErez Shitrit 	__be32			cap_mask2_resp_time;
2242e9f7cb7SRoland Dreier 	u8			redirect_gid[16];
2252e9f7cb7SRoland Dreier 	__be32			redirect_tcslfl;
2262e9f7cb7SRoland Dreier 	__be16			redirect_lid;
2272e9f7cb7SRoland Dreier 	__be16			redirect_pkey;
2282e9f7cb7SRoland Dreier 	__be32			redirect_qp;
2292e9f7cb7SRoland Dreier 	__be32			redirect_qkey;
2302e9f7cb7SRoland Dreier 	u8			trap_gid[16];
2312e9f7cb7SRoland Dreier 	__be32			trap_tcslfl;
2322e9f7cb7SRoland Dreier 	__be16			trap_lid;
2332e9f7cb7SRoland Dreier 	__be16			trap_pkey;
2342e9f7cb7SRoland Dreier 	__be32			trap_hlqp;
2352e9f7cb7SRoland Dreier 	__be32			trap_qkey;
2362e9f7cb7SRoland Dreier };
2372e9f7cb7SRoland Dreier 
2382f944c0fSJason Gunthorpe /* PortInfo CapabilityMask */
2392f944c0fSJason Gunthorpe enum ib_port_capability_mask_bits {
2402f944c0fSJason Gunthorpe 	IB_PORT_SM = 1 << 1,
2412f944c0fSJason Gunthorpe 	IB_PORT_NOTICE_SUP = 1 << 2,
2422f944c0fSJason Gunthorpe 	IB_PORT_TRAP_SUP = 1 << 3,
2432f944c0fSJason Gunthorpe 	IB_PORT_OPT_IPD_SUP = 1 << 4,
2442f944c0fSJason Gunthorpe 	IB_PORT_AUTO_MIGR_SUP = 1 << 5,
2452f944c0fSJason Gunthorpe 	IB_PORT_SL_MAP_SUP = 1 << 6,
2462f944c0fSJason Gunthorpe 	IB_PORT_MKEY_NVRAM = 1 << 7,
2472f944c0fSJason Gunthorpe 	IB_PORT_PKEY_NVRAM = 1 << 8,
2482f944c0fSJason Gunthorpe 	IB_PORT_LED_INFO_SUP = 1 << 9,
2492f944c0fSJason Gunthorpe 	IB_PORT_SM_DISABLED = 1 << 10,
2502f944c0fSJason Gunthorpe 	IB_PORT_SYS_IMAGE_GUID_SUP = 1 << 11,
2512f944c0fSJason Gunthorpe 	IB_PORT_PKEY_SW_EXT_PORT_TRAP_SUP = 1 << 12,
2522f944c0fSJason Gunthorpe 	IB_PORT_EXTENDED_SPEEDS_SUP = 1 << 14,
2531e8f43b7SMichael Guralnik 	IB_PORT_CAP_MASK2_SUP = 1 << 15,
2542f944c0fSJason Gunthorpe 	IB_PORT_CM_SUP = 1 << 16,
2552f944c0fSJason Gunthorpe 	IB_PORT_SNMP_TUNNEL_SUP = 1 << 17,
2562f944c0fSJason Gunthorpe 	IB_PORT_REINIT_SUP = 1 << 18,
2572f944c0fSJason Gunthorpe 	IB_PORT_DEVICE_MGMT_SUP = 1 << 19,
2582f944c0fSJason Gunthorpe 	IB_PORT_VENDOR_CLASS_SUP = 1 << 20,
2592f944c0fSJason Gunthorpe 	IB_PORT_DR_NOTICE_SUP = 1 << 21,
2602f944c0fSJason Gunthorpe 	IB_PORT_CAP_MASK_NOTICE_SUP = 1 << 22,
2612f944c0fSJason Gunthorpe 	IB_PORT_BOOT_MGMT_SUP = 1 << 23,
2622f944c0fSJason Gunthorpe 	IB_PORT_LINK_LATENCY_SUP = 1 << 24,
2632f944c0fSJason Gunthorpe 	IB_PORT_CLIENT_REG_SUP = 1 << 25,
2642f944c0fSJason Gunthorpe 	IB_PORT_OTHER_LOCAL_CHANGES_SUP = 1 << 26,
2652f944c0fSJason Gunthorpe 	IB_PORT_LINK_SPEED_WIDTH_TABLE_SUP = 1 << 27,
2662f944c0fSJason Gunthorpe 	IB_PORT_VENDOR_SPECIFIC_MADS_TABLE_SUP = 1 << 28,
2672f944c0fSJason Gunthorpe 	IB_PORT_MCAST_PKEY_TRAP_SUPPRESSION_SUP = 1 << 29,
2682f944c0fSJason Gunthorpe 	IB_PORT_MCAST_FDB_TOP_SUP = 1 << 30,
2692f944c0fSJason Gunthorpe 	IB_PORT_HIERARCHY_INFO_SUP = 1ULL << 31,
2702f944c0fSJason Gunthorpe };
2712f944c0fSJason Gunthorpe 
2721e8f43b7SMichael Guralnik enum ib_port_capability_mask2_bits {
2731e8f43b7SMichael Guralnik 	IB_PORT_SET_NODE_DESC_SUP		= 1 << 0,
2741e8f43b7SMichael Guralnik 	IB_PORT_EX_PORT_INFO_EX_SUP		= 1 << 1,
2751e8f43b7SMichael Guralnik 	IB_PORT_VIRT_SUP			= 1 << 2,
2761e8f43b7SMichael Guralnik 	IB_PORT_SWITCH_PORT_STATE_TABLE_SUP	= 1 << 3,
2771e8f43b7SMichael Guralnik 	IB_PORT_LINK_WIDTH_2X_SUP		= 1 << 4,
2781e8f43b7SMichael Guralnik 	IB_PORT_LINK_SPEED_HDR_SUP		= 1 << 5,
279*fbdb0ba7SMaher Sanalla 	IB_PORT_LINK_SPEED_NDR_SUP		= 1 << 10,
2801e8f43b7SMichael Guralnik };
2811e8f43b7SMichael Guralnik 
2824c33bd19SDasaratharaman Chandramouli #define OPA_CLASS_PORT_INFO_PR_SUPPORT BIT(26)
2834c33bd19SDasaratharaman Chandramouli 
284aa4656d9SDasaratharaman Chandramouli struct opa_class_port_info {
285aa4656d9SDasaratharaman Chandramouli 	u8 base_version;
286aa4656d9SDasaratharaman Chandramouli 	u8 class_version;
287aa4656d9SDasaratharaman Chandramouli 	__be16 cap_mask;
288aa4656d9SDasaratharaman Chandramouli 	__be32 cap_mask2_resp_time;
289aa4656d9SDasaratharaman Chandramouli 
290aa4656d9SDasaratharaman Chandramouli 	u8 redirect_gid[16];
291aa4656d9SDasaratharaman Chandramouli 	__be32 redirect_tc_fl;
292aa4656d9SDasaratharaman Chandramouli 	__be32 redirect_lid;
293aa4656d9SDasaratharaman Chandramouli 	__be32 redirect_sl_qp;
294aa4656d9SDasaratharaman Chandramouli 	__be32 redirect_qkey;
295aa4656d9SDasaratharaman Chandramouli 
296aa4656d9SDasaratharaman Chandramouli 	u8 trap_gid[16];
297aa4656d9SDasaratharaman Chandramouli 	__be32 trap_tc_fl;
298aa4656d9SDasaratharaman Chandramouli 	__be32 trap_lid;
299aa4656d9SDasaratharaman Chandramouli 	__be32 trap_hl_qp;
300aa4656d9SDasaratharaman Chandramouli 	__be32 trap_qkey;
301aa4656d9SDasaratharaman Chandramouli 
302aa4656d9SDasaratharaman Chandramouli 	__be16 trap_pkey;
303aa4656d9SDasaratharaman Chandramouli 	__be16 redirect_pkey;
304aa4656d9SDasaratharaman Chandramouli 
305aa4656d9SDasaratharaman Chandramouli 	u8 trap_sl_rsvd;
306aa4656d9SDasaratharaman Chandramouli 	u8 reserved[3];
307aa4656d9SDasaratharaman Chandramouli } __packed;
308aa4656d9SDasaratharaman Chandramouli 
309507f6afaSErez Shitrit /**
310507f6afaSErez Shitrit  * ib_get_cpi_resp_time - Returns the resp_time value from
311507f6afaSErez Shitrit  * cap_mask2_resp_time in ib_class_port_info.
312507f6afaSErez Shitrit  * @cpi: A struct ib_class_port_info mad.
313507f6afaSErez Shitrit  */
ib_get_cpi_resp_time(struct ib_class_port_info * cpi)314507f6afaSErez Shitrit static inline u8 ib_get_cpi_resp_time(struct ib_class_port_info *cpi)
315507f6afaSErez Shitrit {
316507f6afaSErez Shitrit 	return (u8)(be32_to_cpu(cpi->cap_mask2_resp_time) &
317507f6afaSErez Shitrit 		    IB_CLASS_PORT_INFO_RESP_TIME_MASK);
318507f6afaSErez Shitrit }
319507f6afaSErez Shitrit 
320507f6afaSErez Shitrit /**
321507f6afaSErez Shitrit  * ib_set_cpi_resptime - Sets the response time in an
322507f6afaSErez Shitrit  * ib_class_port_info mad.
323507f6afaSErez Shitrit  * @cpi: A struct ib_class_port_info.
324507f6afaSErez Shitrit  * @rtime: The response time to set.
325507f6afaSErez Shitrit  */
ib_set_cpi_resp_time(struct ib_class_port_info * cpi,u8 rtime)326507f6afaSErez Shitrit static inline void ib_set_cpi_resp_time(struct ib_class_port_info *cpi,
327507f6afaSErez Shitrit 					u8 rtime)
328507f6afaSErez Shitrit {
329507f6afaSErez Shitrit 	cpi->cap_mask2_resp_time =
330507f6afaSErez Shitrit 		(cpi->cap_mask2_resp_time &
331507f6afaSErez Shitrit 		 cpu_to_be32(~IB_CLASS_PORT_INFO_RESP_TIME_MASK)) |
332507f6afaSErez Shitrit 		cpu_to_be32(rtime & IB_CLASS_PORT_INFO_RESP_TIME_MASK);
333507f6afaSErez Shitrit }
334507f6afaSErez Shitrit 
335507f6afaSErez Shitrit /**
336507f6afaSErez Shitrit  * ib_get_cpi_capmask2 - Returns the capmask2 value from
337507f6afaSErez Shitrit  * cap_mask2_resp_time in ib_class_port_info.
338507f6afaSErez Shitrit  * @cpi: A struct ib_class_port_info mad.
339507f6afaSErez Shitrit  */
ib_get_cpi_capmask2(struct ib_class_port_info * cpi)340507f6afaSErez Shitrit static inline u32 ib_get_cpi_capmask2(struct ib_class_port_info *cpi)
341507f6afaSErez Shitrit {
342507f6afaSErez Shitrit 	return (be32_to_cpu(cpi->cap_mask2_resp_time) >>
343507f6afaSErez Shitrit 		IB_CLASS_PORT_INFO_RESP_TIME_FIELD_SIZE);
344507f6afaSErez Shitrit }
345507f6afaSErez Shitrit 
346507f6afaSErez Shitrit /**
347507f6afaSErez Shitrit  * ib_set_cpi_capmask2 - Sets the capmask2 in an
348507f6afaSErez Shitrit  * ib_class_port_info mad.
349507f6afaSErez Shitrit  * @cpi: A struct ib_class_port_info.
350507f6afaSErez Shitrit  * @capmask2: The capmask2 to set.
351507f6afaSErez Shitrit  */
ib_set_cpi_capmask2(struct ib_class_port_info * cpi,u32 capmask2)352507f6afaSErez Shitrit static inline void ib_set_cpi_capmask2(struct ib_class_port_info *cpi,
353507f6afaSErez Shitrit 				       u32 capmask2)
354507f6afaSErez Shitrit {
355507f6afaSErez Shitrit 	cpi->cap_mask2_resp_time =
356507f6afaSErez Shitrit 		(cpi->cap_mask2_resp_time &
357507f6afaSErez Shitrit 		 cpu_to_be32(IB_CLASS_PORT_INFO_RESP_TIME_MASK)) |
358507f6afaSErez Shitrit 		cpu_to_be32(capmask2 <<
359507f6afaSErez Shitrit 			    IB_CLASS_PORT_INFO_RESP_TIME_FIELD_SIZE);
360507f6afaSErez Shitrit }
361507f6afaSErez Shitrit 
3624c33bd19SDasaratharaman Chandramouli /**
3634c33bd19SDasaratharaman Chandramouli  * opa_get_cpi_capmask2 - Returns the capmask2 value from
3644c33bd19SDasaratharaman Chandramouli  * cap_mask2_resp_time in ib_class_port_info.
3654c33bd19SDasaratharaman Chandramouli  * @cpi: A struct opa_class_port_info mad.
3664c33bd19SDasaratharaman Chandramouli  */
opa_get_cpi_capmask2(struct opa_class_port_info * cpi)3674c33bd19SDasaratharaman Chandramouli static inline u32 opa_get_cpi_capmask2(struct opa_class_port_info *cpi)
3684c33bd19SDasaratharaman Chandramouli {
3694c33bd19SDasaratharaman Chandramouli 	return (be32_to_cpu(cpi->cap_mask2_resp_time) >>
3704c33bd19SDasaratharaman Chandramouli 		IB_CLASS_PORT_INFO_RESP_TIME_FIELD_SIZE);
3714c33bd19SDasaratharaman Chandramouli }
3724c33bd19SDasaratharaman Chandramouli 
373d4ab3470SDennis Dalessandro struct ib_mad_notice_attr {
374d4ab3470SDennis Dalessandro 	u8 generic_type;
375d4ab3470SDennis Dalessandro 	u8 prod_type_msb;
376d4ab3470SDennis Dalessandro 	__be16 prod_type_lsb;
377d4ab3470SDennis Dalessandro 	__be16 trap_num;
378d4ab3470SDennis Dalessandro 	__be16 issuer_lid;
379d4ab3470SDennis Dalessandro 	__be16 toggle_count;
380d4ab3470SDennis Dalessandro 
381d4ab3470SDennis Dalessandro 	union {
382d4ab3470SDennis Dalessandro 		struct {
383d4ab3470SDennis Dalessandro 			u8	details[54];
384d4ab3470SDennis Dalessandro 		} raw_data;
385d4ab3470SDennis Dalessandro 
386d4ab3470SDennis Dalessandro 		struct {
387d4ab3470SDennis Dalessandro 			__be16	reserved;
388d4ab3470SDennis Dalessandro 			__be16	lid;		/* where violation happened */
389d4ab3470SDennis Dalessandro 			u8	port_num;	/* where violation happened */
390d4ab3470SDennis Dalessandro 		} __packed ntc_129_131;
391d4ab3470SDennis Dalessandro 
392d4ab3470SDennis Dalessandro 		struct {
393d4ab3470SDennis Dalessandro 			__be16	reserved;
394d4ab3470SDennis Dalessandro 			__be16	lid;		/* LID where change occurred */
395d4ab3470SDennis Dalessandro 			u8	reserved2;
396d4ab3470SDennis Dalessandro 			u8	local_changes;	/* low bit - local changes */
397d4ab3470SDennis Dalessandro 			__be32	new_cap_mask;	/* new capability mask */
398d4ab3470SDennis Dalessandro 			u8	reserved3;
399d4ab3470SDennis Dalessandro 			u8	change_flags;	/* low 3 bits only */
400d4ab3470SDennis Dalessandro 		} __packed ntc_144;
401d4ab3470SDennis Dalessandro 
402d4ab3470SDennis Dalessandro 		struct {
403d4ab3470SDennis Dalessandro 			__be16	reserved;
404d4ab3470SDennis Dalessandro 			__be16	lid;		/* lid where sys guid changed */
405d4ab3470SDennis Dalessandro 			__be16	reserved2;
406d4ab3470SDennis Dalessandro 			__be64	new_sys_guid;
407d4ab3470SDennis Dalessandro 		} __packed ntc_145;
408d4ab3470SDennis Dalessandro 
409d4ab3470SDennis Dalessandro 		struct {
410d4ab3470SDennis Dalessandro 			__be16	reserved;
411d4ab3470SDennis Dalessandro 			__be16	lid;
412d4ab3470SDennis Dalessandro 			__be16	dr_slid;
413d4ab3470SDennis Dalessandro 			u8	method;
414d4ab3470SDennis Dalessandro 			u8	reserved2;
415d4ab3470SDennis Dalessandro 			__be16	attr_id;
416d4ab3470SDennis Dalessandro 			__be32	attr_mod;
417d4ab3470SDennis Dalessandro 			__be64	mkey;
418d4ab3470SDennis Dalessandro 			u8	reserved3;
419d4ab3470SDennis Dalessandro 			u8	dr_trunc_hop;
420d4ab3470SDennis Dalessandro 			u8	dr_rtn_path[30];
421d4ab3470SDennis Dalessandro 		} __packed ntc_256;
422d4ab3470SDennis Dalessandro 
423d4ab3470SDennis Dalessandro 		struct {
424d4ab3470SDennis Dalessandro 			__be16		reserved;
425d4ab3470SDennis Dalessandro 			__be16		lid1;
426d4ab3470SDennis Dalessandro 			__be16		lid2;
427d4ab3470SDennis Dalessandro 			__be32		key;
428d4ab3470SDennis Dalessandro 			__be32		sl_qp1;	/* SL: high 4 bits */
429d4ab3470SDennis Dalessandro 			__be32		qp2;	/* high 8 bits reserved */
430d4ab3470SDennis Dalessandro 			union ib_gid	gid1;
431d4ab3470SDennis Dalessandro 			union ib_gid	gid2;
432d4ab3470SDennis Dalessandro 		} __packed ntc_257_258;
433d4ab3470SDennis Dalessandro 
434d4ab3470SDennis Dalessandro 	} details;
435d4ab3470SDennis Dalessandro };
436d4ab3470SDennis Dalessandro 
437a4d61e84SRoland Dreier /**
438a4d61e84SRoland Dreier  * ib_mad_send_buf - MAD data buffer and work request for sends.
43934816ad9SSean Hefty  * @next: A pointer used to chain together MADs for posting.
440f36e1793SJack Morgenstein  * @mad: References an allocated MAD data buffer for MADs that do not have
441f36e1793SJack Morgenstein  *   RMPP active.  For MADs using RMPP, references the common and management
442f36e1793SJack Morgenstein  *   class specific headers.
443a4d61e84SRoland Dreier  * @mad_agent: MAD agent that allocated the buffer.
44434816ad9SSean Hefty  * @ah: The address handle to use when sending the MAD.
445a4d61e84SRoland Dreier  * @context: User-controlled context fields.
446f36e1793SJack Morgenstein  * @hdr_len: Indicates the size of the data header of the MAD.  This length
447f36e1793SJack Morgenstein  *   includes the common MAD, RMPP, and class specific headers.
448f36e1793SJack Morgenstein  * @data_len: Indicates the total size of user-transferred data.
449f36e1793SJack Morgenstein  * @seg_count: The number of RMPP segments allocated for this send.
450548ead17SIra Weiny  * @seg_size: Size of the data in each RMPP segment.  This does not include
451548ead17SIra Weiny  *   class specific headers.
452548ead17SIra Weiny  * @seg_rmpp_size: Size of each RMPP segment including the class specific
453548ead17SIra Weiny  *   headers.
45434816ad9SSean Hefty  * @timeout_ms: Time to wait for a response.
4554fc8cd49SSean Hefty  * @retries: Number of times to retry a request for a response.  For MADs
4564fc8cd49SSean Hefty  *   using RMPP, this applies per window.  On completion, returns the number
4574fc8cd49SSean Hefty  *   of retries needed to complete the transfer.
458a4d61e84SRoland Dreier  *
459a4d61e84SRoland Dreier  * Users are responsible for initializing the MAD buffer itself, with the
460f36e1793SJack Morgenstein  * exception of any RMPP header.  Additional segment buffer space allocated
461f36e1793SJack Morgenstein  * beyond data_len is padding.
462a4d61e84SRoland Dreier  */
463a4d61e84SRoland Dreier struct ib_mad_send_buf {
46434816ad9SSean Hefty 	struct ib_mad_send_buf	*next;
46534816ad9SSean Hefty 	void			*mad;
466a4d61e84SRoland Dreier 	struct ib_mad_agent	*mad_agent;
46734816ad9SSean Hefty 	struct ib_ah		*ah;
468a4d61e84SRoland Dreier 	void			*context[2];
469f36e1793SJack Morgenstein 	int			hdr_len;
470f36e1793SJack Morgenstein 	int			data_len;
471f36e1793SJack Morgenstein 	int			seg_count;
472f36e1793SJack Morgenstein 	int			seg_size;
473548ead17SIra Weiny 	int			seg_rmpp_size;
47434816ad9SSean Hefty 	int			timeout_ms;
47534816ad9SSean Hefty 	int			retries;
476a4d61e84SRoland Dreier };
477a4d61e84SRoland Dreier 
478a4d61e84SRoland Dreier /**
4792527e681SSean Hefty  * ib_response_mad - Returns if the specified MAD has been generated in
4802527e681SSean Hefty  *   response to a sent request or trap.
4812527e681SSean Hefty  */
48296909308SIra Weiny int ib_response_mad(const struct ib_mad_hdr *hdr);
4832527e681SSean Hefty 
4842527e681SSean Hefty /**
485a4d61e84SRoland Dreier  * ib_get_rmpp_resptime - Returns the RMPP response time.
486a4d61e84SRoland Dreier  * @rmpp_hdr: An RMPP header.
487a4d61e84SRoland Dreier  */
ib_get_rmpp_resptime(struct ib_rmpp_hdr * rmpp_hdr)488a4d61e84SRoland Dreier static inline u8 ib_get_rmpp_resptime(struct ib_rmpp_hdr *rmpp_hdr)
489a4d61e84SRoland Dreier {
490a4d61e84SRoland Dreier 	return rmpp_hdr->rmpp_rtime_flags >> 3;
491a4d61e84SRoland Dreier }
492a4d61e84SRoland Dreier 
493a4d61e84SRoland Dreier /**
494a4d61e84SRoland Dreier  * ib_get_rmpp_flags - Returns the RMPP flags.
495a4d61e84SRoland Dreier  * @rmpp_hdr: An RMPP header.
496a4d61e84SRoland Dreier  */
ib_get_rmpp_flags(struct ib_rmpp_hdr * rmpp_hdr)497a4d61e84SRoland Dreier static inline u8 ib_get_rmpp_flags(struct ib_rmpp_hdr *rmpp_hdr)
498a4d61e84SRoland Dreier {
499a4d61e84SRoland Dreier 	return rmpp_hdr->rmpp_rtime_flags & 0x7;
500a4d61e84SRoland Dreier }
501a4d61e84SRoland Dreier 
502a4d61e84SRoland Dreier /**
503a4d61e84SRoland Dreier  * ib_set_rmpp_resptime - Sets the response time in an RMPP header.
504a4d61e84SRoland Dreier  * @rmpp_hdr: An RMPP header.
505a4d61e84SRoland Dreier  * @rtime: The response time to set.
506a4d61e84SRoland Dreier  */
ib_set_rmpp_resptime(struct ib_rmpp_hdr * rmpp_hdr,u8 rtime)507a4d61e84SRoland Dreier static inline void ib_set_rmpp_resptime(struct ib_rmpp_hdr *rmpp_hdr, u8 rtime)
508a4d61e84SRoland Dreier {
509a4d61e84SRoland Dreier 	rmpp_hdr->rmpp_rtime_flags = ib_get_rmpp_flags(rmpp_hdr) | (rtime << 3);
510a4d61e84SRoland Dreier }
511a4d61e84SRoland Dreier 
512a4d61e84SRoland Dreier /**
513a4d61e84SRoland Dreier  * ib_set_rmpp_flags - Sets the flags in an RMPP header.
514a4d61e84SRoland Dreier  * @rmpp_hdr: An RMPP header.
515a4d61e84SRoland Dreier  * @flags: The flags to set.
516a4d61e84SRoland Dreier  */
ib_set_rmpp_flags(struct ib_rmpp_hdr * rmpp_hdr,u8 flags)517a4d61e84SRoland Dreier static inline void ib_set_rmpp_flags(struct ib_rmpp_hdr *rmpp_hdr, u8 flags)
518a4d61e84SRoland Dreier {
5197020cb0fSRamachandra K 	rmpp_hdr->rmpp_rtime_flags = (rmpp_hdr->rmpp_rtime_flags & 0xF8) |
520a4d61e84SRoland Dreier 				     (flags & 0x7);
521a4d61e84SRoland Dreier }
522a4d61e84SRoland Dreier 
523a4d61e84SRoland Dreier struct ib_mad_agent;
524a4d61e84SRoland Dreier struct ib_mad_send_wc;
525a4d61e84SRoland Dreier struct ib_mad_recv_wc;
526a4d61e84SRoland Dreier 
527a4d61e84SRoland Dreier /**
528a4d61e84SRoland Dreier  * ib_mad_send_handler - callback handler for a sent MAD.
529a4d61e84SRoland Dreier  * @mad_agent: MAD agent that sent the MAD.
530a4d61e84SRoland Dreier  * @mad_send_wc: Send work completion information on the sent MAD.
531a4d61e84SRoland Dreier  */
532a4d61e84SRoland Dreier typedef void (*ib_mad_send_handler)(struct ib_mad_agent *mad_agent,
533a4d61e84SRoland Dreier 				    struct ib_mad_send_wc *mad_send_wc);
534a4d61e84SRoland Dreier 
535a4d61e84SRoland Dreier /**
536a4d61e84SRoland Dreier  * ib_mad_recv_handler - callback handler for a received MAD.
537a4d61e84SRoland Dreier  * @mad_agent: MAD agent requesting the received MAD.
538ca281265SChristoph Hellwig  * @send_buf: Send buffer if found, else NULL
539a4d61e84SRoland Dreier  * @mad_recv_wc: Received work completion information on the received MAD.
540a4d61e84SRoland Dreier  *
541a4d61e84SRoland Dreier  * MADs received in response to a send request operation will be handed to
542f36e1793SJack Morgenstein  * the user before the send operation completes.  All data buffers given
543a4d61e84SRoland Dreier  * to registered agents through this routine are owned by the receiving
54404c349a9SMaor Gottlieb  * client.
545a4d61e84SRoland Dreier  */
546a4d61e84SRoland Dreier typedef void (*ib_mad_recv_handler)(struct ib_mad_agent *mad_agent,
547ca281265SChristoph Hellwig 				    struct ib_mad_send_buf *send_buf,
548a4d61e84SRoland Dreier 				    struct ib_mad_recv_wc *mad_recv_wc);
549a4d61e84SRoland Dreier 
550a4d61e84SRoland Dreier /**
551a4d61e84SRoland Dreier  * ib_mad_agent - Used to track MAD registration with the access layer.
552a4d61e84SRoland Dreier  * @device: Reference to device registration is on.
553a4d61e84SRoland Dreier  * @qp: Reference to QP used for sending and receiving MADs.
554a4d61e84SRoland Dreier  * @mr: Memory region for system memory usable for DMA.
555a4d61e84SRoland Dreier  * @recv_handler: Callback handler for a received MAD.
556a4d61e84SRoland Dreier  * @send_handler: Callback handler for a sent MAD.
557a4d61e84SRoland Dreier  * @context: User-specified context associated with this registration.
558a4d61e84SRoland Dreier  * @hi_tid: Access layer assigned transaction ID for this client.
559a4d61e84SRoland Dreier  *   Unsolicited MADs sent by this client will have the upper 32-bits
560a4d61e84SRoland Dreier  *   of their TID set to this value.
5610f29b46dSIra Weiny  * @flags: registration flags
562a4d61e84SRoland Dreier  * @port_num: Port number on which QP is registered
563a4d61e84SRoland Dreier  * @rmpp_version: If set, indicates the RMPP version used by this agent.
564a4d61e84SRoland Dreier  */
5651471cb6cSIra Weiny enum {
5661471cb6cSIra Weiny 	IB_MAD_USER_RMPP = IB_USER_MAD_USER_RMPP,
5671471cb6cSIra Weiny };
568a4d61e84SRoland Dreier struct ib_mad_agent {
569a4d61e84SRoland Dreier 	struct ib_device	*device;
570a4d61e84SRoland Dreier 	struct ib_qp		*qp;
571a4d61e84SRoland Dreier 	ib_mad_recv_handler	recv_handler;
572a4d61e84SRoland Dreier 	ib_mad_send_handler	send_handler;
573a4d61e84SRoland Dreier 	void			*context;
574a4d61e84SRoland Dreier 	u32			hi_tid;
5750f29b46dSIra Weiny 	u32			flags;
576805b754dSDaniel Jurgens 	void			*security;
577c66f6741SDaniel Jurgens 	struct list_head	mad_agent_sec_list;
578a4d61e84SRoland Dreier 	u8			port_num;
579a4d61e84SRoland Dreier 	u8			rmpp_version;
58047a2b338SDaniel Jurgens 	bool			smp_allowed;
581a4d61e84SRoland Dreier };
582a4d61e84SRoland Dreier 
583a4d61e84SRoland Dreier /**
584a4d61e84SRoland Dreier  * ib_mad_send_wc - MAD send completion information.
58534816ad9SSean Hefty  * @send_buf: Send MAD data buffer associated with the send MAD request.
586a4d61e84SRoland Dreier  * @status: Completion status.
587a4d61e84SRoland Dreier  * @vendor_err: Optional vendor error information returned with a failed
588a4d61e84SRoland Dreier  *   request.
589a4d61e84SRoland Dreier  */
590a4d61e84SRoland Dreier struct ib_mad_send_wc {
59134816ad9SSean Hefty 	struct ib_mad_send_buf	*send_buf;
592a4d61e84SRoland Dreier 	enum ib_wc_status	status;
593a4d61e84SRoland Dreier 	u32			vendor_err;
594a4d61e84SRoland Dreier };
595a4d61e84SRoland Dreier 
596a4d61e84SRoland Dreier /**
597a4d61e84SRoland Dreier  * ib_mad_recv_buf - received MAD buffer information.
598a4d61e84SRoland Dreier  * @list: Reference to next data buffer for a received RMPP MAD.
599a4d61e84SRoland Dreier  * @grh: References a data buffer containing the global route header.
600a4d61e84SRoland Dreier  *   The data refereced by this buffer is only valid if the GRH is
601a4d61e84SRoland Dreier  *   valid.
602a4d61e84SRoland Dreier  * @mad: References the start of the received MAD.
603a4d61e84SRoland Dreier  */
604a4d61e84SRoland Dreier struct ib_mad_recv_buf {
605a4d61e84SRoland Dreier 	struct list_head	list;
606a4d61e84SRoland Dreier 	struct ib_grh		*grh;
607548ead17SIra Weiny 	union {
608a4d61e84SRoland Dreier 		struct ib_mad	*mad;
609548ead17SIra Weiny 		struct opa_mad	*opa_mad;
610548ead17SIra Weiny 	};
611a4d61e84SRoland Dreier };
612a4d61e84SRoland Dreier 
613a4d61e84SRoland Dreier /**
614a4d61e84SRoland Dreier  * ib_mad_recv_wc - received MAD information.
615a4d61e84SRoland Dreier  * @wc: Completion information for the received data.
616a4d61e84SRoland Dreier  * @recv_buf: Specifies the location of the received data buffer(s).
617a4d61e84SRoland Dreier  * @rmpp_list: Specifies a list of RMPP reassembled received MAD buffers.
618a4d61e84SRoland Dreier  * @mad_len: The length of the received MAD, without duplicated headers.
6198e4349d1SIra Weiny  * @mad_seg_size: The size of individual MAD segments
620a4d61e84SRoland Dreier  *
62134816ad9SSean Hefty  * For received response, the wr_id contains a pointer to the ib_mad_send_buf
622a4d61e84SRoland Dreier  *   for the corresponding send request.
623a4d61e84SRoland Dreier  */
624a4d61e84SRoland Dreier struct ib_mad_recv_wc {
625a4d61e84SRoland Dreier 	struct ib_wc		*wc;
626a4d61e84SRoland Dreier 	struct ib_mad_recv_buf	recv_buf;
627a4d61e84SRoland Dreier 	struct list_head	rmpp_list;
628a4d61e84SRoland Dreier 	int			mad_len;
6298e4349d1SIra Weiny 	size_t			mad_seg_size;
630a4d61e84SRoland Dreier };
631a4d61e84SRoland Dreier 
632a4d61e84SRoland Dreier /**
633a4d61e84SRoland Dreier  * ib_mad_reg_req - MAD registration request
634a4d61e84SRoland Dreier  * @mgmt_class: Indicates which management class of MADs should be receive
635a4d61e84SRoland Dreier  *   by the caller.  This field is only required if the user wishes to
636a4d61e84SRoland Dreier  *   receive unsolicited MADs, otherwise it should be 0.
637a4d61e84SRoland Dreier  * @mgmt_class_version: Indicates which version of MADs for the given
638a4d61e84SRoland Dreier  *   management class to receive.
639a4d61e84SRoland Dreier  * @oui: Indicates IEEE OUI when mgmt_class is a vendor class
640a4d61e84SRoland Dreier  *   in the range from 0x30 to 0x4f. Otherwise not used.
641a4d61e84SRoland Dreier  * @method_mask: The caller will receive unsolicited MADs for any method
642a4d61e84SRoland Dreier  *   where @method_mask = 1.
6430f29b46dSIra Weiny  *
644a4d61e84SRoland Dreier  */
645a4d61e84SRoland Dreier struct ib_mad_reg_req {
646a4d61e84SRoland Dreier 	u8	mgmt_class;
647a4d61e84SRoland Dreier 	u8	mgmt_class_version;
648a4d61e84SRoland Dreier 	u8	oui[3];
649a4d61e84SRoland Dreier 	DECLARE_BITMAP(method_mask, IB_MGMT_MAX_METHODS);
650a4d61e84SRoland Dreier };
651a4d61e84SRoland Dreier 
652a4d61e84SRoland Dreier /**
653a4d61e84SRoland Dreier  * ib_register_mad_agent - Register to send/receive MADs.
654a4d61e84SRoland Dreier  * @device: The device to register with.
655a4d61e84SRoland Dreier  * @port_num: The port on the specified device to use.
656a4d61e84SRoland Dreier  * @qp_type: Specifies which QP to access.  Must be either
657a4d61e84SRoland Dreier  *   IB_QPT_SMI or IB_QPT_GSI.
658a4d61e84SRoland Dreier  * @mad_reg_req: Specifies which unsolicited MADs should be received
659a4d61e84SRoland Dreier  *   by the caller.  This parameter may be NULL if the caller only
660a4d61e84SRoland Dreier  *   wishes to receive solicited responses.
661a4d61e84SRoland Dreier  * @rmpp_version: If set, indicates that the client will send
662a4d61e84SRoland Dreier  *   and receive MADs that contain the RMPP header for the given version.
663a4d61e84SRoland Dreier  *   If set to 0, indicates that RMPP is not used by this client.
664a4d61e84SRoland Dreier  * @send_handler: The completion callback routine invoked after a send
665a4d61e84SRoland Dreier  *   request has completed.
666a4d61e84SRoland Dreier  * @recv_handler: The completion callback routine invoked for a received
667a4d61e84SRoland Dreier  *   MAD.
668a4d61e84SRoland Dreier  * @context: User specified context associated with the registration.
6690f29b46dSIra Weiny  * @registration_flags: Registration flags to set for this agent
670a4d61e84SRoland Dreier  */
671a4d61e84SRoland Dreier struct ib_mad_agent *ib_register_mad_agent(struct ib_device *device,
6721fb7f897SMark Bloch 					   u32 port_num,
673a4d61e84SRoland Dreier 					   enum ib_qp_type qp_type,
674a4d61e84SRoland Dreier 					   struct ib_mad_reg_req *mad_reg_req,
675a4d61e84SRoland Dreier 					   u8 rmpp_version,
676a4d61e84SRoland Dreier 					   ib_mad_send_handler send_handler,
677a4d61e84SRoland Dreier 					   ib_mad_recv_handler recv_handler,
6780f29b46dSIra Weiny 					   void *context,
6790f29b46dSIra Weiny 					   u32 registration_flags);
680a4d61e84SRoland Dreier /**
681a4d61e84SRoland Dreier  * ib_unregister_mad_agent - Unregisters a client from using MAD services.
682a4d61e84SRoland Dreier  * @mad_agent: Corresponding MAD registration request to deregister.
683a4d61e84SRoland Dreier  *
684a4d61e84SRoland Dreier  * After invoking this routine, MAD services are no longer usable by the
685a4d61e84SRoland Dreier  * client on the associated QP.
686a4d61e84SRoland Dreier  */
6878d2216beSZhu Yanjun void ib_unregister_mad_agent(struct ib_mad_agent *mad_agent);
688a4d61e84SRoland Dreier 
689a4d61e84SRoland Dreier /**
690a4d61e84SRoland Dreier  * ib_post_send_mad - Posts MAD(s) to the send queue of the QP associated
691a4d61e84SRoland Dreier  *   with the registered client.
69234816ad9SSean Hefty  * @send_buf: Specifies the information needed to send the MAD(s).
69334816ad9SSean Hefty  * @bad_send_buf: Specifies the MAD on which an error was encountered.  This
69434816ad9SSean Hefty  *   parameter is optional if only a single MAD is posted.
695a4d61e84SRoland Dreier  *
696a4d61e84SRoland Dreier  * Sent MADs are not guaranteed to complete in the order that they were posted.
697a4d61e84SRoland Dreier  *
698a4d61e84SRoland Dreier  * If the MAD requires RMPP, the data buffer should contain a single copy
699a4d61e84SRoland Dreier  * of the common MAD, RMPP, and class specific headers, followed by the class
700a4d61e84SRoland Dreier  * defined data.  If the class defined data would not divide evenly into
701a4d61e84SRoland Dreier  * RMPP segments, then space must be allocated at the end of the referenced
702a4d61e84SRoland Dreier  * buffer for any required padding.  To indicate the amount of class defined
703a4d61e84SRoland Dreier  * data being transferred, the paylen_newwin field in the RMPP header should
704a4d61e84SRoland Dreier  * be set to the size of the class specific header plus the amount of class
705a4d61e84SRoland Dreier  * defined data being transferred.  The paylen_newwin field should be
706a4d61e84SRoland Dreier  * specified in network-byte order.
707a4d61e84SRoland Dreier  */
70834816ad9SSean Hefty int ib_post_send_mad(struct ib_mad_send_buf *send_buf,
70934816ad9SSean Hefty 		     struct ib_mad_send_buf **bad_send_buf);
710a4d61e84SRoland Dreier 
711a4d61e84SRoland Dreier 
712a4d61e84SRoland Dreier /**
713a4d61e84SRoland Dreier  * ib_free_recv_mad - Returns data buffers used to receive a MAD.
714a4d61e84SRoland Dreier  * @mad_recv_wc: Work completion information for a received MAD.
715a4d61e84SRoland Dreier  *
716a4d61e84SRoland Dreier  * Clients receiving MADs through their ib_mad_recv_handler must call this
717a4d61e84SRoland Dreier  * routine to return the work completion buffers to the access layer.
718a4d61e84SRoland Dreier  */
719a4d61e84SRoland Dreier void ib_free_recv_mad(struct ib_mad_recv_wc *mad_recv_wc);
720a4d61e84SRoland Dreier 
721a4d61e84SRoland Dreier /**
722a4d61e84SRoland Dreier  * ib_modify_mad - Modifies an outstanding send MAD operation.
72334816ad9SSean Hefty  * @send_buf: Indicates the MAD to modify.
724a4d61e84SRoland Dreier  * @timeout_ms: New timeout value for sent MAD.
725a4d61e84SRoland Dreier  *
726a4d61e84SRoland Dreier  * This call will reset the timeout value for a sent MAD to the specified
727a4d61e84SRoland Dreier  * value.
728a4d61e84SRoland Dreier  */
72970076a41SMark Zhang int ib_modify_mad(struct ib_mad_send_buf *send_buf, u32 timeout_ms);
73070076a41SMark Zhang 
73170076a41SMark Zhang /**
73270076a41SMark Zhang  * ib_cancel_mad - Cancels an outstanding send MAD operation.
73370076a41SMark Zhang  * @send_buf: Indicates the MAD to cancel.
73470076a41SMark Zhang  *
73570076a41SMark Zhang  * MADs will be returned to the user through the corresponding
73670076a41SMark Zhang  * ib_mad_send_handler.
73770076a41SMark Zhang  */
ib_cancel_mad(struct ib_mad_send_buf * send_buf)73870076a41SMark Zhang static inline void ib_cancel_mad(struct ib_mad_send_buf *send_buf)
73970076a41SMark Zhang {
74070076a41SMark Zhang 	ib_modify_mad(send_buf, 0);
74170076a41SMark Zhang }
742a4d61e84SRoland Dreier 
743a4d61e84SRoland Dreier /**
744a4d61e84SRoland Dreier  * ib_create_send_mad - Allocate and initialize a data buffer and work request
745a4d61e84SRoland Dreier  *   for sending a MAD.
746a4d61e84SRoland Dreier  * @mad_agent: Specifies the registered MAD service to associate with the MAD.
747a4d61e84SRoland Dreier  * @remote_qpn: Specifies the QPN of the receiving node.
748a4d61e84SRoland Dreier  * @pkey_index: Specifies which PKey the MAD will be sent using.  This field
749a4d61e84SRoland Dreier  *   is valid only if the remote_qpn is QP 1.
750a4d61e84SRoland Dreier  * @rmpp_active: Indicates if the send will enable RMPP.
751a4d61e84SRoland Dreier  * @hdr_len: Indicates the size of the data header of the MAD.  This length
752a4d61e84SRoland Dreier  *   should include the common MAD header, RMPP header, plus any class
753a4d61e84SRoland Dreier  *   specific header.
754a4d61e84SRoland Dreier  * @data_len: Indicates the size of any user-transferred data.  The call will
755a4d61e84SRoland Dreier  *   automatically adjust the allocated buffer size to account for any
756a4d61e84SRoland Dreier  *   additional padding that may be necessary.
757a4d61e84SRoland Dreier  * @gfp_mask: GFP mask used for the memory allocation.
758da2dfaa3SIra Weiny  * @base_version: Base Version of this MAD
759a4d61e84SRoland Dreier  *
76034816ad9SSean Hefty  * This routine allocates a MAD for sending.  The returned MAD send buffer
76134816ad9SSean Hefty  * will reference a data buffer usable for sending a MAD, along
762a4d61e84SRoland Dreier  * with an initialized work request structure.  Users may modify the returned
76334816ad9SSean Hefty  * MAD data buffer before posting the send.
764a4d61e84SRoland Dreier  *
765f36e1793SJack Morgenstein  * The returned MAD header, class specific headers, and any padding will be
766f36e1793SJack Morgenstein  * cleared.  Users are responsible for initializing the common MAD header,
767f36e1793SJack Morgenstein  * any class specific header, and MAD data area.
768f36e1793SJack Morgenstein  * If @rmpp_active is set, the RMPP header will be initialized for sending.
769a4d61e84SRoland Dreier  */
770a4d61e84SRoland Dreier struct ib_mad_send_buf *ib_create_send_mad(struct ib_mad_agent *mad_agent,
771a4d61e84SRoland Dreier 					   u32 remote_qpn, u16 pkey_index,
77234816ad9SSean Hefty 					   int rmpp_active,
773a4d61e84SRoland Dreier 					   int hdr_len, int data_len,
774da2dfaa3SIra Weiny 					   gfp_t gfp_mask,
775da2dfaa3SIra Weiny 					   u8 base_version);
776a4d61e84SRoland Dreier 
777a4d61e84SRoland Dreier /**
778618a3c03SHal Rosenstock  * ib_is_mad_class_rmpp - returns whether given management class
779618a3c03SHal Rosenstock  * supports RMPP.
780618a3c03SHal Rosenstock  * @mgmt_class: management class
781618a3c03SHal Rosenstock  *
782618a3c03SHal Rosenstock  * This routine returns whether the management class supports RMPP.
783618a3c03SHal Rosenstock  */
784618a3c03SHal Rosenstock int ib_is_mad_class_rmpp(u8 mgmt_class);
785618a3c03SHal Rosenstock 
786618a3c03SHal Rosenstock /**
787618a3c03SHal Rosenstock  * ib_get_mad_data_offset - returns the data offset for a given
788618a3c03SHal Rosenstock  * management class.
789618a3c03SHal Rosenstock  * @mgmt_class: management class
790618a3c03SHal Rosenstock  *
791618a3c03SHal Rosenstock  * This routine returns the data offset in the MAD for the management
792618a3c03SHal Rosenstock  * class requested.
793618a3c03SHal Rosenstock  */
794618a3c03SHal Rosenstock int ib_get_mad_data_offset(u8 mgmt_class);
795618a3c03SHal Rosenstock 
796618a3c03SHal Rosenstock /**
797f36e1793SJack Morgenstein  * ib_get_rmpp_segment - returns the data buffer for a given RMPP segment.
798f36e1793SJack Morgenstein  * @send_buf: Previously allocated send data buffer.
799f36e1793SJack Morgenstein  * @seg_num: number of segment to return
800f36e1793SJack Morgenstein  *
801f36e1793SJack Morgenstein  * This routine returns a pointer to the data buffer of an RMPP MAD.
802f36e1793SJack Morgenstein  * Users must provide synchronization to @send_buf around this call.
803f36e1793SJack Morgenstein  */
804f36e1793SJack Morgenstein void *ib_get_rmpp_segment(struct ib_mad_send_buf *send_buf, int seg_num);
805f36e1793SJack Morgenstein 
806f36e1793SJack Morgenstein /**
807a4d61e84SRoland Dreier  * ib_free_send_mad - Returns data buffers used to send a MAD.
808a4d61e84SRoland Dreier  * @send_buf: Previously allocated send data buffer.
809a4d61e84SRoland Dreier  */
810a4d61e84SRoland Dreier void ib_free_send_mad(struct ib_mad_send_buf *send_buf);
811a4d61e84SRoland Dreier 
8121471cb6cSIra Weiny /**
8131471cb6cSIra Weiny  * ib_mad_kernel_rmpp_agent - Returns if the agent is performing RMPP.
8141471cb6cSIra Weiny  * @agent: the agent in question
8151471cb6cSIra Weiny  * @return: true if agent is performing rmpp, false otherwise.
8161471cb6cSIra Weiny  */
817f766c58fSIra Weiny int ib_mad_kernel_rmpp_agent(const struct ib_mad_agent *agent);
8181471cb6cSIra Weiny 
819a4d61e84SRoland Dreier #endif /* IB_MAD_H */
820