1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * Copyright (c) 2004 Mellanox Technologies Ltd. All rights reserved.
4*4882a593Smuzhiyun * Copyright (c) 2004 Infinicon Corporation. All rights reserved.
5*4882a593Smuzhiyun * Copyright (c) 2004 Intel Corporation. All rights reserved.
6*4882a593Smuzhiyun * Copyright (c) 2004 Topspin Corporation. All rights reserved.
7*4882a593Smuzhiyun * Copyright (c) 2004-2006 Voltaire Corporation. All rights reserved.
8*4882a593Smuzhiyun */
9*4882a593Smuzhiyun
10*4882a593Smuzhiyun #ifndef IB_MAD_H
11*4882a593Smuzhiyun #define IB_MAD_H
12*4882a593Smuzhiyun
13*4882a593Smuzhiyun #include <linux/list.h>
14*4882a593Smuzhiyun
15*4882a593Smuzhiyun #include <rdma/ib_verbs.h>
16*4882a593Smuzhiyun #include <uapi/rdma/ib_user_mad.h>
17*4882a593Smuzhiyun
18*4882a593Smuzhiyun /* Management base versions */
19*4882a593Smuzhiyun #define IB_MGMT_BASE_VERSION 1
20*4882a593Smuzhiyun #define OPA_MGMT_BASE_VERSION 0x80
21*4882a593Smuzhiyun
22*4882a593Smuzhiyun #define OPA_SM_CLASS_VERSION 0x80
23*4882a593Smuzhiyun
24*4882a593Smuzhiyun /* Management classes */
25*4882a593Smuzhiyun #define IB_MGMT_CLASS_SUBN_LID_ROUTED 0x01
26*4882a593Smuzhiyun #define IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE 0x81
27*4882a593Smuzhiyun #define IB_MGMT_CLASS_SUBN_ADM 0x03
28*4882a593Smuzhiyun #define IB_MGMT_CLASS_PERF_MGMT 0x04
29*4882a593Smuzhiyun #define IB_MGMT_CLASS_BM 0x05
30*4882a593Smuzhiyun #define IB_MGMT_CLASS_DEVICE_MGMT 0x06
31*4882a593Smuzhiyun #define IB_MGMT_CLASS_CM 0x07
32*4882a593Smuzhiyun #define IB_MGMT_CLASS_SNMP 0x08
33*4882a593Smuzhiyun #define IB_MGMT_CLASS_DEVICE_ADM 0x10
34*4882a593Smuzhiyun #define IB_MGMT_CLASS_BOOT_MGMT 0x11
35*4882a593Smuzhiyun #define IB_MGMT_CLASS_BIS 0x12
36*4882a593Smuzhiyun #define IB_MGMT_CLASS_CONG_MGMT 0x21
37*4882a593Smuzhiyun #define IB_MGMT_CLASS_VENDOR_RANGE2_START 0x30
38*4882a593Smuzhiyun #define IB_MGMT_CLASS_VENDOR_RANGE2_END 0x4F
39*4882a593Smuzhiyun
40*4882a593Smuzhiyun #define IB_OPENIB_OUI (0x001405)
41*4882a593Smuzhiyun
42*4882a593Smuzhiyun /* Management methods */
43*4882a593Smuzhiyun #define IB_MGMT_METHOD_GET 0x01
44*4882a593Smuzhiyun #define IB_MGMT_METHOD_SET 0x02
45*4882a593Smuzhiyun #define IB_MGMT_METHOD_GET_RESP 0x81
46*4882a593Smuzhiyun #define IB_MGMT_METHOD_SEND 0x03
47*4882a593Smuzhiyun #define IB_MGMT_METHOD_TRAP 0x05
48*4882a593Smuzhiyun #define IB_MGMT_METHOD_REPORT 0x06
49*4882a593Smuzhiyun #define IB_MGMT_METHOD_REPORT_RESP 0x86
50*4882a593Smuzhiyun #define IB_MGMT_METHOD_TRAP_REPRESS 0x07
51*4882a593Smuzhiyun
52*4882a593Smuzhiyun #define IB_MGMT_METHOD_RESP 0x80
53*4882a593Smuzhiyun #define IB_BM_ATTR_MOD_RESP cpu_to_be32(1)
54*4882a593Smuzhiyun
55*4882a593Smuzhiyun #define IB_MGMT_MAX_METHODS 128
56*4882a593Smuzhiyun
57*4882a593Smuzhiyun /* MAD Status field bit masks */
58*4882a593Smuzhiyun #define IB_MGMT_MAD_STATUS_SUCCESS 0x0000
59*4882a593Smuzhiyun #define IB_MGMT_MAD_STATUS_BUSY 0x0001
60*4882a593Smuzhiyun #define IB_MGMT_MAD_STATUS_REDIRECT_REQD 0x0002
61*4882a593Smuzhiyun #define IB_MGMT_MAD_STATUS_BAD_VERSION 0x0004
62*4882a593Smuzhiyun #define IB_MGMT_MAD_STATUS_UNSUPPORTED_METHOD 0x0008
63*4882a593Smuzhiyun #define IB_MGMT_MAD_STATUS_UNSUPPORTED_METHOD_ATTRIB 0x000c
64*4882a593Smuzhiyun #define IB_MGMT_MAD_STATUS_INVALID_ATTRIB_VALUE 0x001c
65*4882a593Smuzhiyun
66*4882a593Smuzhiyun /* RMPP information */
67*4882a593Smuzhiyun #define IB_MGMT_RMPP_VERSION 1
68*4882a593Smuzhiyun
69*4882a593Smuzhiyun #define IB_MGMT_RMPP_TYPE_DATA 1
70*4882a593Smuzhiyun #define IB_MGMT_RMPP_TYPE_ACK 2
71*4882a593Smuzhiyun #define IB_MGMT_RMPP_TYPE_STOP 3
72*4882a593Smuzhiyun #define IB_MGMT_RMPP_TYPE_ABORT 4
73*4882a593Smuzhiyun
74*4882a593Smuzhiyun #define IB_MGMT_RMPP_FLAG_ACTIVE 1
75*4882a593Smuzhiyun #define IB_MGMT_RMPP_FLAG_FIRST (1<<1)
76*4882a593Smuzhiyun #define IB_MGMT_RMPP_FLAG_LAST (1<<2)
77*4882a593Smuzhiyun
78*4882a593Smuzhiyun #define IB_MGMT_RMPP_NO_RESPTIME 0x1F
79*4882a593Smuzhiyun
80*4882a593Smuzhiyun #define IB_MGMT_RMPP_STATUS_SUCCESS 0
81*4882a593Smuzhiyun #define IB_MGMT_RMPP_STATUS_RESX 1
82*4882a593Smuzhiyun #define IB_MGMT_RMPP_STATUS_ABORT_MIN 118
83*4882a593Smuzhiyun #define IB_MGMT_RMPP_STATUS_T2L 118
84*4882a593Smuzhiyun #define IB_MGMT_RMPP_STATUS_BAD_LEN 119
85*4882a593Smuzhiyun #define IB_MGMT_RMPP_STATUS_BAD_SEG 120
86*4882a593Smuzhiyun #define IB_MGMT_RMPP_STATUS_BADT 121
87*4882a593Smuzhiyun #define IB_MGMT_RMPP_STATUS_W2S 122
88*4882a593Smuzhiyun #define IB_MGMT_RMPP_STATUS_S2B 123
89*4882a593Smuzhiyun #define IB_MGMT_RMPP_STATUS_BAD_STATUS 124
90*4882a593Smuzhiyun #define IB_MGMT_RMPP_STATUS_UNV 125
91*4882a593Smuzhiyun #define IB_MGMT_RMPP_STATUS_TMR 126
92*4882a593Smuzhiyun #define IB_MGMT_RMPP_STATUS_UNSPEC 127
93*4882a593Smuzhiyun #define IB_MGMT_RMPP_STATUS_ABORT_MAX 127
94*4882a593Smuzhiyun
95*4882a593Smuzhiyun #define IB_QP0 0
96*4882a593Smuzhiyun #define IB_QP1 cpu_to_be32(1)
97*4882a593Smuzhiyun #define IB_QP1_QKEY 0x80010000
98*4882a593Smuzhiyun #define IB_QP_SET_QKEY 0x80000000
99*4882a593Smuzhiyun
100*4882a593Smuzhiyun #define IB_DEFAULT_PKEY_PARTIAL 0x7FFF
101*4882a593Smuzhiyun #define IB_DEFAULT_PKEY_FULL 0xFFFF
102*4882a593Smuzhiyun
103*4882a593Smuzhiyun /*
104*4882a593Smuzhiyun * Generic trap/notice types
105*4882a593Smuzhiyun */
106*4882a593Smuzhiyun #define IB_NOTICE_TYPE_FATAL 0x80
107*4882a593Smuzhiyun #define IB_NOTICE_TYPE_URGENT 0x81
108*4882a593Smuzhiyun #define IB_NOTICE_TYPE_SECURITY 0x82
109*4882a593Smuzhiyun #define IB_NOTICE_TYPE_SM 0x83
110*4882a593Smuzhiyun #define IB_NOTICE_TYPE_INFO 0x84
111*4882a593Smuzhiyun
112*4882a593Smuzhiyun /*
113*4882a593Smuzhiyun * Generic trap/notice producers
114*4882a593Smuzhiyun */
115*4882a593Smuzhiyun #define IB_NOTICE_PROD_CA cpu_to_be16(1)
116*4882a593Smuzhiyun #define IB_NOTICE_PROD_SWITCH cpu_to_be16(2)
117*4882a593Smuzhiyun #define IB_NOTICE_PROD_ROUTER cpu_to_be16(3)
118*4882a593Smuzhiyun #define IB_NOTICE_PROD_CLASS_MGR cpu_to_be16(4)
119*4882a593Smuzhiyun
120*4882a593Smuzhiyun enum {
121*4882a593Smuzhiyun IB_MGMT_MAD_HDR = 24,
122*4882a593Smuzhiyun IB_MGMT_MAD_DATA = 232,
123*4882a593Smuzhiyun IB_MGMT_RMPP_HDR = 36,
124*4882a593Smuzhiyun IB_MGMT_RMPP_DATA = 220,
125*4882a593Smuzhiyun IB_MGMT_VENDOR_HDR = 40,
126*4882a593Smuzhiyun IB_MGMT_VENDOR_DATA = 216,
127*4882a593Smuzhiyun IB_MGMT_SA_HDR = 56,
128*4882a593Smuzhiyun IB_MGMT_SA_DATA = 200,
129*4882a593Smuzhiyun IB_MGMT_DEVICE_HDR = 64,
130*4882a593Smuzhiyun IB_MGMT_DEVICE_DATA = 192,
131*4882a593Smuzhiyun IB_MGMT_MAD_SIZE = IB_MGMT_MAD_HDR + IB_MGMT_MAD_DATA,
132*4882a593Smuzhiyun OPA_MGMT_MAD_DATA = 2024,
133*4882a593Smuzhiyun OPA_MGMT_RMPP_DATA = 2012,
134*4882a593Smuzhiyun OPA_MGMT_MAD_SIZE = IB_MGMT_MAD_HDR + OPA_MGMT_MAD_DATA,
135*4882a593Smuzhiyun };
136*4882a593Smuzhiyun
137*4882a593Smuzhiyun struct ib_mad_hdr {
138*4882a593Smuzhiyun u8 base_version;
139*4882a593Smuzhiyun u8 mgmt_class;
140*4882a593Smuzhiyun u8 class_version;
141*4882a593Smuzhiyun u8 method;
142*4882a593Smuzhiyun __be16 status;
143*4882a593Smuzhiyun __be16 class_specific;
144*4882a593Smuzhiyun __be64 tid;
145*4882a593Smuzhiyun __be16 attr_id;
146*4882a593Smuzhiyun __be16 resv;
147*4882a593Smuzhiyun __be32 attr_mod;
148*4882a593Smuzhiyun };
149*4882a593Smuzhiyun
150*4882a593Smuzhiyun struct ib_rmpp_hdr {
151*4882a593Smuzhiyun u8 rmpp_version;
152*4882a593Smuzhiyun u8 rmpp_type;
153*4882a593Smuzhiyun u8 rmpp_rtime_flags;
154*4882a593Smuzhiyun u8 rmpp_status;
155*4882a593Smuzhiyun __be32 seg_num;
156*4882a593Smuzhiyun __be32 paylen_newwin;
157*4882a593Smuzhiyun };
158*4882a593Smuzhiyun
159*4882a593Smuzhiyun typedef u64 __bitwise ib_sa_comp_mask;
160*4882a593Smuzhiyun
161*4882a593Smuzhiyun #define IB_SA_COMP_MASK(n) ((__force ib_sa_comp_mask) cpu_to_be64(1ull << (n)))
162*4882a593Smuzhiyun
163*4882a593Smuzhiyun /*
164*4882a593Smuzhiyun * ib_sa_hdr and ib_sa_mad structures must be packed because they have
165*4882a593Smuzhiyun * 64-bit fields that are only 32-bit aligned. 64-bit architectures will
166*4882a593Smuzhiyun * lay them out wrong otherwise. (And unfortunately they are sent on
167*4882a593Smuzhiyun * the wire so we can't change the layout)
168*4882a593Smuzhiyun */
169*4882a593Smuzhiyun struct ib_sa_hdr {
170*4882a593Smuzhiyun __be64 sm_key;
171*4882a593Smuzhiyun __be16 attr_offset;
172*4882a593Smuzhiyun __be16 reserved;
173*4882a593Smuzhiyun ib_sa_comp_mask comp_mask;
174*4882a593Smuzhiyun } __packed;
175*4882a593Smuzhiyun
176*4882a593Smuzhiyun struct ib_mad {
177*4882a593Smuzhiyun struct ib_mad_hdr mad_hdr;
178*4882a593Smuzhiyun u8 data[IB_MGMT_MAD_DATA];
179*4882a593Smuzhiyun };
180*4882a593Smuzhiyun
181*4882a593Smuzhiyun struct opa_mad {
182*4882a593Smuzhiyun struct ib_mad_hdr mad_hdr;
183*4882a593Smuzhiyun u8 data[OPA_MGMT_MAD_DATA];
184*4882a593Smuzhiyun };
185*4882a593Smuzhiyun
186*4882a593Smuzhiyun struct ib_rmpp_mad {
187*4882a593Smuzhiyun struct ib_mad_hdr mad_hdr;
188*4882a593Smuzhiyun struct ib_rmpp_hdr rmpp_hdr;
189*4882a593Smuzhiyun u8 data[IB_MGMT_RMPP_DATA];
190*4882a593Smuzhiyun };
191*4882a593Smuzhiyun
192*4882a593Smuzhiyun struct opa_rmpp_mad {
193*4882a593Smuzhiyun struct ib_mad_hdr mad_hdr;
194*4882a593Smuzhiyun struct ib_rmpp_hdr rmpp_hdr;
195*4882a593Smuzhiyun u8 data[OPA_MGMT_RMPP_DATA];
196*4882a593Smuzhiyun };
197*4882a593Smuzhiyun
198*4882a593Smuzhiyun struct ib_sa_mad {
199*4882a593Smuzhiyun struct ib_mad_hdr mad_hdr;
200*4882a593Smuzhiyun struct ib_rmpp_hdr rmpp_hdr;
201*4882a593Smuzhiyun struct ib_sa_hdr sa_hdr;
202*4882a593Smuzhiyun u8 data[IB_MGMT_SA_DATA];
203*4882a593Smuzhiyun } __packed;
204*4882a593Smuzhiyun
205*4882a593Smuzhiyun struct ib_vendor_mad {
206*4882a593Smuzhiyun struct ib_mad_hdr mad_hdr;
207*4882a593Smuzhiyun struct ib_rmpp_hdr rmpp_hdr;
208*4882a593Smuzhiyun u8 reserved;
209*4882a593Smuzhiyun u8 oui[3];
210*4882a593Smuzhiyun u8 data[IB_MGMT_VENDOR_DATA];
211*4882a593Smuzhiyun };
212*4882a593Smuzhiyun
213*4882a593Smuzhiyun #define IB_MGMT_CLASSPORTINFO_ATTR_ID cpu_to_be16(0x0001)
214*4882a593Smuzhiyun
215*4882a593Smuzhiyun #define IB_CLASS_PORT_INFO_RESP_TIME_MASK 0x1F
216*4882a593Smuzhiyun #define IB_CLASS_PORT_INFO_RESP_TIME_FIELD_SIZE 5
217*4882a593Smuzhiyun
218*4882a593Smuzhiyun struct ib_class_port_info {
219*4882a593Smuzhiyun u8 base_version;
220*4882a593Smuzhiyun u8 class_version;
221*4882a593Smuzhiyun __be16 capability_mask;
222*4882a593Smuzhiyun /* 27 bits for cap_mask2, 5 bits for resp_time */
223*4882a593Smuzhiyun __be32 cap_mask2_resp_time;
224*4882a593Smuzhiyun u8 redirect_gid[16];
225*4882a593Smuzhiyun __be32 redirect_tcslfl;
226*4882a593Smuzhiyun __be16 redirect_lid;
227*4882a593Smuzhiyun __be16 redirect_pkey;
228*4882a593Smuzhiyun __be32 redirect_qp;
229*4882a593Smuzhiyun __be32 redirect_qkey;
230*4882a593Smuzhiyun u8 trap_gid[16];
231*4882a593Smuzhiyun __be32 trap_tcslfl;
232*4882a593Smuzhiyun __be16 trap_lid;
233*4882a593Smuzhiyun __be16 trap_pkey;
234*4882a593Smuzhiyun __be32 trap_hlqp;
235*4882a593Smuzhiyun __be32 trap_qkey;
236*4882a593Smuzhiyun };
237*4882a593Smuzhiyun
238*4882a593Smuzhiyun /* PortInfo CapabilityMask */
239*4882a593Smuzhiyun enum ib_port_capability_mask_bits {
240*4882a593Smuzhiyun IB_PORT_SM = 1 << 1,
241*4882a593Smuzhiyun IB_PORT_NOTICE_SUP = 1 << 2,
242*4882a593Smuzhiyun IB_PORT_TRAP_SUP = 1 << 3,
243*4882a593Smuzhiyun IB_PORT_OPT_IPD_SUP = 1 << 4,
244*4882a593Smuzhiyun IB_PORT_AUTO_MIGR_SUP = 1 << 5,
245*4882a593Smuzhiyun IB_PORT_SL_MAP_SUP = 1 << 6,
246*4882a593Smuzhiyun IB_PORT_MKEY_NVRAM = 1 << 7,
247*4882a593Smuzhiyun IB_PORT_PKEY_NVRAM = 1 << 8,
248*4882a593Smuzhiyun IB_PORT_LED_INFO_SUP = 1 << 9,
249*4882a593Smuzhiyun IB_PORT_SM_DISABLED = 1 << 10,
250*4882a593Smuzhiyun IB_PORT_SYS_IMAGE_GUID_SUP = 1 << 11,
251*4882a593Smuzhiyun IB_PORT_PKEY_SW_EXT_PORT_TRAP_SUP = 1 << 12,
252*4882a593Smuzhiyun IB_PORT_EXTENDED_SPEEDS_SUP = 1 << 14,
253*4882a593Smuzhiyun IB_PORT_CAP_MASK2_SUP = 1 << 15,
254*4882a593Smuzhiyun IB_PORT_CM_SUP = 1 << 16,
255*4882a593Smuzhiyun IB_PORT_SNMP_TUNNEL_SUP = 1 << 17,
256*4882a593Smuzhiyun IB_PORT_REINIT_SUP = 1 << 18,
257*4882a593Smuzhiyun IB_PORT_DEVICE_MGMT_SUP = 1 << 19,
258*4882a593Smuzhiyun IB_PORT_VENDOR_CLASS_SUP = 1 << 20,
259*4882a593Smuzhiyun IB_PORT_DR_NOTICE_SUP = 1 << 21,
260*4882a593Smuzhiyun IB_PORT_CAP_MASK_NOTICE_SUP = 1 << 22,
261*4882a593Smuzhiyun IB_PORT_BOOT_MGMT_SUP = 1 << 23,
262*4882a593Smuzhiyun IB_PORT_LINK_LATENCY_SUP = 1 << 24,
263*4882a593Smuzhiyun IB_PORT_CLIENT_REG_SUP = 1 << 25,
264*4882a593Smuzhiyun IB_PORT_OTHER_LOCAL_CHANGES_SUP = 1 << 26,
265*4882a593Smuzhiyun IB_PORT_LINK_SPEED_WIDTH_TABLE_SUP = 1 << 27,
266*4882a593Smuzhiyun IB_PORT_VENDOR_SPECIFIC_MADS_TABLE_SUP = 1 << 28,
267*4882a593Smuzhiyun IB_PORT_MCAST_PKEY_TRAP_SUPPRESSION_SUP = 1 << 29,
268*4882a593Smuzhiyun IB_PORT_MCAST_FDB_TOP_SUP = 1 << 30,
269*4882a593Smuzhiyun IB_PORT_HIERARCHY_INFO_SUP = 1ULL << 31,
270*4882a593Smuzhiyun };
271*4882a593Smuzhiyun
272*4882a593Smuzhiyun enum ib_port_capability_mask2_bits {
273*4882a593Smuzhiyun IB_PORT_SET_NODE_DESC_SUP = 1 << 0,
274*4882a593Smuzhiyun IB_PORT_EX_PORT_INFO_EX_SUP = 1 << 1,
275*4882a593Smuzhiyun IB_PORT_VIRT_SUP = 1 << 2,
276*4882a593Smuzhiyun IB_PORT_SWITCH_PORT_STATE_TABLE_SUP = 1 << 3,
277*4882a593Smuzhiyun IB_PORT_LINK_WIDTH_2X_SUP = 1 << 4,
278*4882a593Smuzhiyun IB_PORT_LINK_SPEED_HDR_SUP = 1 << 5,
279*4882a593Smuzhiyun };
280*4882a593Smuzhiyun
281*4882a593Smuzhiyun #define OPA_CLASS_PORT_INFO_PR_SUPPORT BIT(26)
282*4882a593Smuzhiyun
283*4882a593Smuzhiyun struct opa_class_port_info {
284*4882a593Smuzhiyun u8 base_version;
285*4882a593Smuzhiyun u8 class_version;
286*4882a593Smuzhiyun __be16 cap_mask;
287*4882a593Smuzhiyun __be32 cap_mask2_resp_time;
288*4882a593Smuzhiyun
289*4882a593Smuzhiyun u8 redirect_gid[16];
290*4882a593Smuzhiyun __be32 redirect_tc_fl;
291*4882a593Smuzhiyun __be32 redirect_lid;
292*4882a593Smuzhiyun __be32 redirect_sl_qp;
293*4882a593Smuzhiyun __be32 redirect_qkey;
294*4882a593Smuzhiyun
295*4882a593Smuzhiyun u8 trap_gid[16];
296*4882a593Smuzhiyun __be32 trap_tc_fl;
297*4882a593Smuzhiyun __be32 trap_lid;
298*4882a593Smuzhiyun __be32 trap_hl_qp;
299*4882a593Smuzhiyun __be32 trap_qkey;
300*4882a593Smuzhiyun
301*4882a593Smuzhiyun __be16 trap_pkey;
302*4882a593Smuzhiyun __be16 redirect_pkey;
303*4882a593Smuzhiyun
304*4882a593Smuzhiyun u8 trap_sl_rsvd;
305*4882a593Smuzhiyun u8 reserved[3];
306*4882a593Smuzhiyun } __packed;
307*4882a593Smuzhiyun
308*4882a593Smuzhiyun /**
309*4882a593Smuzhiyun * ib_get_cpi_resp_time - Returns the resp_time value from
310*4882a593Smuzhiyun * cap_mask2_resp_time in ib_class_port_info.
311*4882a593Smuzhiyun * @cpi: A struct ib_class_port_info mad.
312*4882a593Smuzhiyun */
ib_get_cpi_resp_time(struct ib_class_port_info * cpi)313*4882a593Smuzhiyun static inline u8 ib_get_cpi_resp_time(struct ib_class_port_info *cpi)
314*4882a593Smuzhiyun {
315*4882a593Smuzhiyun return (u8)(be32_to_cpu(cpi->cap_mask2_resp_time) &
316*4882a593Smuzhiyun IB_CLASS_PORT_INFO_RESP_TIME_MASK);
317*4882a593Smuzhiyun }
318*4882a593Smuzhiyun
319*4882a593Smuzhiyun /**
320*4882a593Smuzhiyun * ib_set_cpi_resptime - Sets the response time in an
321*4882a593Smuzhiyun * ib_class_port_info mad.
322*4882a593Smuzhiyun * @cpi: A struct ib_class_port_info.
323*4882a593Smuzhiyun * @rtime: The response time to set.
324*4882a593Smuzhiyun */
ib_set_cpi_resp_time(struct ib_class_port_info * cpi,u8 rtime)325*4882a593Smuzhiyun static inline void ib_set_cpi_resp_time(struct ib_class_port_info *cpi,
326*4882a593Smuzhiyun u8 rtime)
327*4882a593Smuzhiyun {
328*4882a593Smuzhiyun cpi->cap_mask2_resp_time =
329*4882a593Smuzhiyun (cpi->cap_mask2_resp_time &
330*4882a593Smuzhiyun cpu_to_be32(~IB_CLASS_PORT_INFO_RESP_TIME_MASK)) |
331*4882a593Smuzhiyun cpu_to_be32(rtime & IB_CLASS_PORT_INFO_RESP_TIME_MASK);
332*4882a593Smuzhiyun }
333*4882a593Smuzhiyun
334*4882a593Smuzhiyun /**
335*4882a593Smuzhiyun * ib_get_cpi_capmask2 - Returns the capmask2 value from
336*4882a593Smuzhiyun * cap_mask2_resp_time in ib_class_port_info.
337*4882a593Smuzhiyun * @cpi: A struct ib_class_port_info mad.
338*4882a593Smuzhiyun */
ib_get_cpi_capmask2(struct ib_class_port_info * cpi)339*4882a593Smuzhiyun static inline u32 ib_get_cpi_capmask2(struct ib_class_port_info *cpi)
340*4882a593Smuzhiyun {
341*4882a593Smuzhiyun return (be32_to_cpu(cpi->cap_mask2_resp_time) >>
342*4882a593Smuzhiyun IB_CLASS_PORT_INFO_RESP_TIME_FIELD_SIZE);
343*4882a593Smuzhiyun }
344*4882a593Smuzhiyun
345*4882a593Smuzhiyun /**
346*4882a593Smuzhiyun * ib_set_cpi_capmask2 - Sets the capmask2 in an
347*4882a593Smuzhiyun * ib_class_port_info mad.
348*4882a593Smuzhiyun * @cpi: A struct ib_class_port_info.
349*4882a593Smuzhiyun * @capmask2: The capmask2 to set.
350*4882a593Smuzhiyun */
ib_set_cpi_capmask2(struct ib_class_port_info * cpi,u32 capmask2)351*4882a593Smuzhiyun static inline void ib_set_cpi_capmask2(struct ib_class_port_info *cpi,
352*4882a593Smuzhiyun u32 capmask2)
353*4882a593Smuzhiyun {
354*4882a593Smuzhiyun cpi->cap_mask2_resp_time =
355*4882a593Smuzhiyun (cpi->cap_mask2_resp_time &
356*4882a593Smuzhiyun cpu_to_be32(IB_CLASS_PORT_INFO_RESP_TIME_MASK)) |
357*4882a593Smuzhiyun cpu_to_be32(capmask2 <<
358*4882a593Smuzhiyun IB_CLASS_PORT_INFO_RESP_TIME_FIELD_SIZE);
359*4882a593Smuzhiyun }
360*4882a593Smuzhiyun
361*4882a593Smuzhiyun /**
362*4882a593Smuzhiyun * opa_get_cpi_capmask2 - Returns the capmask2 value from
363*4882a593Smuzhiyun * cap_mask2_resp_time in ib_class_port_info.
364*4882a593Smuzhiyun * @cpi: A struct opa_class_port_info mad.
365*4882a593Smuzhiyun */
opa_get_cpi_capmask2(struct opa_class_port_info * cpi)366*4882a593Smuzhiyun static inline u32 opa_get_cpi_capmask2(struct opa_class_port_info *cpi)
367*4882a593Smuzhiyun {
368*4882a593Smuzhiyun return (be32_to_cpu(cpi->cap_mask2_resp_time) >>
369*4882a593Smuzhiyun IB_CLASS_PORT_INFO_RESP_TIME_FIELD_SIZE);
370*4882a593Smuzhiyun }
371*4882a593Smuzhiyun
372*4882a593Smuzhiyun struct ib_mad_notice_attr {
373*4882a593Smuzhiyun u8 generic_type;
374*4882a593Smuzhiyun u8 prod_type_msb;
375*4882a593Smuzhiyun __be16 prod_type_lsb;
376*4882a593Smuzhiyun __be16 trap_num;
377*4882a593Smuzhiyun __be16 issuer_lid;
378*4882a593Smuzhiyun __be16 toggle_count;
379*4882a593Smuzhiyun
380*4882a593Smuzhiyun union {
381*4882a593Smuzhiyun struct {
382*4882a593Smuzhiyun u8 details[54];
383*4882a593Smuzhiyun } raw_data;
384*4882a593Smuzhiyun
385*4882a593Smuzhiyun struct {
386*4882a593Smuzhiyun __be16 reserved;
387*4882a593Smuzhiyun __be16 lid; /* where violation happened */
388*4882a593Smuzhiyun u8 port_num; /* where violation happened */
389*4882a593Smuzhiyun } __packed ntc_129_131;
390*4882a593Smuzhiyun
391*4882a593Smuzhiyun struct {
392*4882a593Smuzhiyun __be16 reserved;
393*4882a593Smuzhiyun __be16 lid; /* LID where change occurred */
394*4882a593Smuzhiyun u8 reserved2;
395*4882a593Smuzhiyun u8 local_changes; /* low bit - local changes */
396*4882a593Smuzhiyun __be32 new_cap_mask; /* new capability mask */
397*4882a593Smuzhiyun u8 reserved3;
398*4882a593Smuzhiyun u8 change_flags; /* low 3 bits only */
399*4882a593Smuzhiyun } __packed ntc_144;
400*4882a593Smuzhiyun
401*4882a593Smuzhiyun struct {
402*4882a593Smuzhiyun __be16 reserved;
403*4882a593Smuzhiyun __be16 lid; /* lid where sys guid changed */
404*4882a593Smuzhiyun __be16 reserved2;
405*4882a593Smuzhiyun __be64 new_sys_guid;
406*4882a593Smuzhiyun } __packed ntc_145;
407*4882a593Smuzhiyun
408*4882a593Smuzhiyun struct {
409*4882a593Smuzhiyun __be16 reserved;
410*4882a593Smuzhiyun __be16 lid;
411*4882a593Smuzhiyun __be16 dr_slid;
412*4882a593Smuzhiyun u8 method;
413*4882a593Smuzhiyun u8 reserved2;
414*4882a593Smuzhiyun __be16 attr_id;
415*4882a593Smuzhiyun __be32 attr_mod;
416*4882a593Smuzhiyun __be64 mkey;
417*4882a593Smuzhiyun u8 reserved3;
418*4882a593Smuzhiyun u8 dr_trunc_hop;
419*4882a593Smuzhiyun u8 dr_rtn_path[30];
420*4882a593Smuzhiyun } __packed ntc_256;
421*4882a593Smuzhiyun
422*4882a593Smuzhiyun struct {
423*4882a593Smuzhiyun __be16 reserved;
424*4882a593Smuzhiyun __be16 lid1;
425*4882a593Smuzhiyun __be16 lid2;
426*4882a593Smuzhiyun __be32 key;
427*4882a593Smuzhiyun __be32 sl_qp1; /* SL: high 4 bits */
428*4882a593Smuzhiyun __be32 qp2; /* high 8 bits reserved */
429*4882a593Smuzhiyun union ib_gid gid1;
430*4882a593Smuzhiyun union ib_gid gid2;
431*4882a593Smuzhiyun } __packed ntc_257_258;
432*4882a593Smuzhiyun
433*4882a593Smuzhiyun } details;
434*4882a593Smuzhiyun };
435*4882a593Smuzhiyun
436*4882a593Smuzhiyun /**
437*4882a593Smuzhiyun * ib_mad_send_buf - MAD data buffer and work request for sends.
438*4882a593Smuzhiyun * @next: A pointer used to chain together MADs for posting.
439*4882a593Smuzhiyun * @mad: References an allocated MAD data buffer for MADs that do not have
440*4882a593Smuzhiyun * RMPP active. For MADs using RMPP, references the common and management
441*4882a593Smuzhiyun * class specific headers.
442*4882a593Smuzhiyun * @mad_agent: MAD agent that allocated the buffer.
443*4882a593Smuzhiyun * @ah: The address handle to use when sending the MAD.
444*4882a593Smuzhiyun * @context: User-controlled context fields.
445*4882a593Smuzhiyun * @hdr_len: Indicates the size of the data header of the MAD. This length
446*4882a593Smuzhiyun * includes the common MAD, RMPP, and class specific headers.
447*4882a593Smuzhiyun * @data_len: Indicates the total size of user-transferred data.
448*4882a593Smuzhiyun * @seg_count: The number of RMPP segments allocated for this send.
449*4882a593Smuzhiyun * @seg_size: Size of the data in each RMPP segment. This does not include
450*4882a593Smuzhiyun * class specific headers.
451*4882a593Smuzhiyun * @seg_rmpp_size: Size of each RMPP segment including the class specific
452*4882a593Smuzhiyun * headers.
453*4882a593Smuzhiyun * @timeout_ms: Time to wait for a response.
454*4882a593Smuzhiyun * @retries: Number of times to retry a request for a response. For MADs
455*4882a593Smuzhiyun * using RMPP, this applies per window. On completion, returns the number
456*4882a593Smuzhiyun * of retries needed to complete the transfer.
457*4882a593Smuzhiyun *
458*4882a593Smuzhiyun * Users are responsible for initializing the MAD buffer itself, with the
459*4882a593Smuzhiyun * exception of any RMPP header. Additional segment buffer space allocated
460*4882a593Smuzhiyun * beyond data_len is padding.
461*4882a593Smuzhiyun */
462*4882a593Smuzhiyun struct ib_mad_send_buf {
463*4882a593Smuzhiyun struct ib_mad_send_buf *next;
464*4882a593Smuzhiyun void *mad;
465*4882a593Smuzhiyun struct ib_mad_agent *mad_agent;
466*4882a593Smuzhiyun struct ib_ah *ah;
467*4882a593Smuzhiyun void *context[2];
468*4882a593Smuzhiyun int hdr_len;
469*4882a593Smuzhiyun int data_len;
470*4882a593Smuzhiyun int seg_count;
471*4882a593Smuzhiyun int seg_size;
472*4882a593Smuzhiyun int seg_rmpp_size;
473*4882a593Smuzhiyun int timeout_ms;
474*4882a593Smuzhiyun int retries;
475*4882a593Smuzhiyun };
476*4882a593Smuzhiyun
477*4882a593Smuzhiyun /**
478*4882a593Smuzhiyun * ib_response_mad - Returns if the specified MAD has been generated in
479*4882a593Smuzhiyun * response to a sent request or trap.
480*4882a593Smuzhiyun */
481*4882a593Smuzhiyun int ib_response_mad(const struct ib_mad_hdr *hdr);
482*4882a593Smuzhiyun
483*4882a593Smuzhiyun /**
484*4882a593Smuzhiyun * ib_get_rmpp_resptime - Returns the RMPP response time.
485*4882a593Smuzhiyun * @rmpp_hdr: An RMPP header.
486*4882a593Smuzhiyun */
ib_get_rmpp_resptime(struct ib_rmpp_hdr * rmpp_hdr)487*4882a593Smuzhiyun static inline u8 ib_get_rmpp_resptime(struct ib_rmpp_hdr *rmpp_hdr)
488*4882a593Smuzhiyun {
489*4882a593Smuzhiyun return rmpp_hdr->rmpp_rtime_flags >> 3;
490*4882a593Smuzhiyun }
491*4882a593Smuzhiyun
492*4882a593Smuzhiyun /**
493*4882a593Smuzhiyun * ib_get_rmpp_flags - Returns the RMPP flags.
494*4882a593Smuzhiyun * @rmpp_hdr: An RMPP header.
495*4882a593Smuzhiyun */
ib_get_rmpp_flags(struct ib_rmpp_hdr * rmpp_hdr)496*4882a593Smuzhiyun static inline u8 ib_get_rmpp_flags(struct ib_rmpp_hdr *rmpp_hdr)
497*4882a593Smuzhiyun {
498*4882a593Smuzhiyun return rmpp_hdr->rmpp_rtime_flags & 0x7;
499*4882a593Smuzhiyun }
500*4882a593Smuzhiyun
501*4882a593Smuzhiyun /**
502*4882a593Smuzhiyun * ib_set_rmpp_resptime - Sets the response time in an RMPP header.
503*4882a593Smuzhiyun * @rmpp_hdr: An RMPP header.
504*4882a593Smuzhiyun * @rtime: The response time to set.
505*4882a593Smuzhiyun */
ib_set_rmpp_resptime(struct ib_rmpp_hdr * rmpp_hdr,u8 rtime)506*4882a593Smuzhiyun static inline void ib_set_rmpp_resptime(struct ib_rmpp_hdr *rmpp_hdr, u8 rtime)
507*4882a593Smuzhiyun {
508*4882a593Smuzhiyun rmpp_hdr->rmpp_rtime_flags = ib_get_rmpp_flags(rmpp_hdr) | (rtime << 3);
509*4882a593Smuzhiyun }
510*4882a593Smuzhiyun
511*4882a593Smuzhiyun /**
512*4882a593Smuzhiyun * ib_set_rmpp_flags - Sets the flags in an RMPP header.
513*4882a593Smuzhiyun * @rmpp_hdr: An RMPP header.
514*4882a593Smuzhiyun * @flags: The flags to set.
515*4882a593Smuzhiyun */
ib_set_rmpp_flags(struct ib_rmpp_hdr * rmpp_hdr,u8 flags)516*4882a593Smuzhiyun static inline void ib_set_rmpp_flags(struct ib_rmpp_hdr *rmpp_hdr, u8 flags)
517*4882a593Smuzhiyun {
518*4882a593Smuzhiyun rmpp_hdr->rmpp_rtime_flags = (rmpp_hdr->rmpp_rtime_flags & 0xF8) |
519*4882a593Smuzhiyun (flags & 0x7);
520*4882a593Smuzhiyun }
521*4882a593Smuzhiyun
522*4882a593Smuzhiyun struct ib_mad_agent;
523*4882a593Smuzhiyun struct ib_mad_send_wc;
524*4882a593Smuzhiyun struct ib_mad_recv_wc;
525*4882a593Smuzhiyun
526*4882a593Smuzhiyun /**
527*4882a593Smuzhiyun * ib_mad_send_handler - callback handler for a sent MAD.
528*4882a593Smuzhiyun * @mad_agent: MAD agent that sent the MAD.
529*4882a593Smuzhiyun * @mad_send_wc: Send work completion information on the sent MAD.
530*4882a593Smuzhiyun */
531*4882a593Smuzhiyun typedef void (*ib_mad_send_handler)(struct ib_mad_agent *mad_agent,
532*4882a593Smuzhiyun struct ib_mad_send_wc *mad_send_wc);
533*4882a593Smuzhiyun
534*4882a593Smuzhiyun /**
535*4882a593Smuzhiyun * ib_mad_recv_handler - callback handler for a received MAD.
536*4882a593Smuzhiyun * @mad_agent: MAD agent requesting the received MAD.
537*4882a593Smuzhiyun * @send_buf: Send buffer if found, else NULL
538*4882a593Smuzhiyun * @mad_recv_wc: Received work completion information on the received MAD.
539*4882a593Smuzhiyun *
540*4882a593Smuzhiyun * MADs received in response to a send request operation will be handed to
541*4882a593Smuzhiyun * the user before the send operation completes. All data buffers given
542*4882a593Smuzhiyun * to registered agents through this routine are owned by the receiving
543*4882a593Smuzhiyun * client.
544*4882a593Smuzhiyun */
545*4882a593Smuzhiyun typedef void (*ib_mad_recv_handler)(struct ib_mad_agent *mad_agent,
546*4882a593Smuzhiyun struct ib_mad_send_buf *send_buf,
547*4882a593Smuzhiyun struct ib_mad_recv_wc *mad_recv_wc);
548*4882a593Smuzhiyun
549*4882a593Smuzhiyun /**
550*4882a593Smuzhiyun * ib_mad_agent - Used to track MAD registration with the access layer.
551*4882a593Smuzhiyun * @device: Reference to device registration is on.
552*4882a593Smuzhiyun * @qp: Reference to QP used for sending and receiving MADs.
553*4882a593Smuzhiyun * @mr: Memory region for system memory usable for DMA.
554*4882a593Smuzhiyun * @recv_handler: Callback handler for a received MAD.
555*4882a593Smuzhiyun * @send_handler: Callback handler for a sent MAD.
556*4882a593Smuzhiyun * @context: User-specified context associated with this registration.
557*4882a593Smuzhiyun * @hi_tid: Access layer assigned transaction ID for this client.
558*4882a593Smuzhiyun * Unsolicited MADs sent by this client will have the upper 32-bits
559*4882a593Smuzhiyun * of their TID set to this value.
560*4882a593Smuzhiyun * @flags: registration flags
561*4882a593Smuzhiyun * @port_num: Port number on which QP is registered
562*4882a593Smuzhiyun * @rmpp_version: If set, indicates the RMPP version used by this agent.
563*4882a593Smuzhiyun */
564*4882a593Smuzhiyun enum {
565*4882a593Smuzhiyun IB_MAD_USER_RMPP = IB_USER_MAD_USER_RMPP,
566*4882a593Smuzhiyun };
567*4882a593Smuzhiyun struct ib_mad_agent {
568*4882a593Smuzhiyun struct ib_device *device;
569*4882a593Smuzhiyun struct ib_qp *qp;
570*4882a593Smuzhiyun ib_mad_recv_handler recv_handler;
571*4882a593Smuzhiyun ib_mad_send_handler send_handler;
572*4882a593Smuzhiyun void *context;
573*4882a593Smuzhiyun u32 hi_tid;
574*4882a593Smuzhiyun u32 flags;
575*4882a593Smuzhiyun void *security;
576*4882a593Smuzhiyun struct list_head mad_agent_sec_list;
577*4882a593Smuzhiyun u8 port_num;
578*4882a593Smuzhiyun u8 rmpp_version;
579*4882a593Smuzhiyun bool smp_allowed;
580*4882a593Smuzhiyun };
581*4882a593Smuzhiyun
582*4882a593Smuzhiyun /**
583*4882a593Smuzhiyun * ib_mad_send_wc - MAD send completion information.
584*4882a593Smuzhiyun * @send_buf: Send MAD data buffer associated with the send MAD request.
585*4882a593Smuzhiyun * @status: Completion status.
586*4882a593Smuzhiyun * @vendor_err: Optional vendor error information returned with a failed
587*4882a593Smuzhiyun * request.
588*4882a593Smuzhiyun */
589*4882a593Smuzhiyun struct ib_mad_send_wc {
590*4882a593Smuzhiyun struct ib_mad_send_buf *send_buf;
591*4882a593Smuzhiyun enum ib_wc_status status;
592*4882a593Smuzhiyun u32 vendor_err;
593*4882a593Smuzhiyun };
594*4882a593Smuzhiyun
595*4882a593Smuzhiyun /**
596*4882a593Smuzhiyun * ib_mad_recv_buf - received MAD buffer information.
597*4882a593Smuzhiyun * @list: Reference to next data buffer for a received RMPP MAD.
598*4882a593Smuzhiyun * @grh: References a data buffer containing the global route header.
599*4882a593Smuzhiyun * The data refereced by this buffer is only valid if the GRH is
600*4882a593Smuzhiyun * valid.
601*4882a593Smuzhiyun * @mad: References the start of the received MAD.
602*4882a593Smuzhiyun */
603*4882a593Smuzhiyun struct ib_mad_recv_buf {
604*4882a593Smuzhiyun struct list_head list;
605*4882a593Smuzhiyun struct ib_grh *grh;
606*4882a593Smuzhiyun union {
607*4882a593Smuzhiyun struct ib_mad *mad;
608*4882a593Smuzhiyun struct opa_mad *opa_mad;
609*4882a593Smuzhiyun };
610*4882a593Smuzhiyun };
611*4882a593Smuzhiyun
612*4882a593Smuzhiyun /**
613*4882a593Smuzhiyun * ib_mad_recv_wc - received MAD information.
614*4882a593Smuzhiyun * @wc: Completion information for the received data.
615*4882a593Smuzhiyun * @recv_buf: Specifies the location of the received data buffer(s).
616*4882a593Smuzhiyun * @rmpp_list: Specifies a list of RMPP reassembled received MAD buffers.
617*4882a593Smuzhiyun * @mad_len: The length of the received MAD, without duplicated headers.
618*4882a593Smuzhiyun * @mad_seg_size: The size of individual MAD segments
619*4882a593Smuzhiyun *
620*4882a593Smuzhiyun * For received response, the wr_id contains a pointer to the ib_mad_send_buf
621*4882a593Smuzhiyun * for the corresponding send request.
622*4882a593Smuzhiyun */
623*4882a593Smuzhiyun struct ib_mad_recv_wc {
624*4882a593Smuzhiyun struct ib_wc *wc;
625*4882a593Smuzhiyun struct ib_mad_recv_buf recv_buf;
626*4882a593Smuzhiyun struct list_head rmpp_list;
627*4882a593Smuzhiyun int mad_len;
628*4882a593Smuzhiyun size_t mad_seg_size;
629*4882a593Smuzhiyun };
630*4882a593Smuzhiyun
631*4882a593Smuzhiyun /**
632*4882a593Smuzhiyun * ib_mad_reg_req - MAD registration request
633*4882a593Smuzhiyun * @mgmt_class: Indicates which management class of MADs should be receive
634*4882a593Smuzhiyun * by the caller. This field is only required if the user wishes to
635*4882a593Smuzhiyun * receive unsolicited MADs, otherwise it should be 0.
636*4882a593Smuzhiyun * @mgmt_class_version: Indicates which version of MADs for the given
637*4882a593Smuzhiyun * management class to receive.
638*4882a593Smuzhiyun * @oui: Indicates IEEE OUI when mgmt_class is a vendor class
639*4882a593Smuzhiyun * in the range from 0x30 to 0x4f. Otherwise not used.
640*4882a593Smuzhiyun * @method_mask: The caller will receive unsolicited MADs for any method
641*4882a593Smuzhiyun * where @method_mask = 1.
642*4882a593Smuzhiyun *
643*4882a593Smuzhiyun */
644*4882a593Smuzhiyun struct ib_mad_reg_req {
645*4882a593Smuzhiyun u8 mgmt_class;
646*4882a593Smuzhiyun u8 mgmt_class_version;
647*4882a593Smuzhiyun u8 oui[3];
648*4882a593Smuzhiyun DECLARE_BITMAP(method_mask, IB_MGMT_MAX_METHODS);
649*4882a593Smuzhiyun };
650*4882a593Smuzhiyun
651*4882a593Smuzhiyun /**
652*4882a593Smuzhiyun * ib_register_mad_agent - Register to send/receive MADs.
653*4882a593Smuzhiyun * @device: The device to register with.
654*4882a593Smuzhiyun * @port_num: The port on the specified device to use.
655*4882a593Smuzhiyun * @qp_type: Specifies which QP to access. Must be either
656*4882a593Smuzhiyun * IB_QPT_SMI or IB_QPT_GSI.
657*4882a593Smuzhiyun * @mad_reg_req: Specifies which unsolicited MADs should be received
658*4882a593Smuzhiyun * by the caller. This parameter may be NULL if the caller only
659*4882a593Smuzhiyun * wishes to receive solicited responses.
660*4882a593Smuzhiyun * @rmpp_version: If set, indicates that the client will send
661*4882a593Smuzhiyun * and receive MADs that contain the RMPP header for the given version.
662*4882a593Smuzhiyun * If set to 0, indicates that RMPP is not used by this client.
663*4882a593Smuzhiyun * @send_handler: The completion callback routine invoked after a send
664*4882a593Smuzhiyun * request has completed.
665*4882a593Smuzhiyun * @recv_handler: The completion callback routine invoked for a received
666*4882a593Smuzhiyun * MAD.
667*4882a593Smuzhiyun * @context: User specified context associated with the registration.
668*4882a593Smuzhiyun * @registration_flags: Registration flags to set for this agent
669*4882a593Smuzhiyun */
670*4882a593Smuzhiyun struct ib_mad_agent *ib_register_mad_agent(struct ib_device *device,
671*4882a593Smuzhiyun u8 port_num,
672*4882a593Smuzhiyun enum ib_qp_type qp_type,
673*4882a593Smuzhiyun struct ib_mad_reg_req *mad_reg_req,
674*4882a593Smuzhiyun u8 rmpp_version,
675*4882a593Smuzhiyun ib_mad_send_handler send_handler,
676*4882a593Smuzhiyun ib_mad_recv_handler recv_handler,
677*4882a593Smuzhiyun void *context,
678*4882a593Smuzhiyun u32 registration_flags);
679*4882a593Smuzhiyun /**
680*4882a593Smuzhiyun * ib_unregister_mad_agent - Unregisters a client from using MAD services.
681*4882a593Smuzhiyun * @mad_agent: Corresponding MAD registration request to deregister.
682*4882a593Smuzhiyun *
683*4882a593Smuzhiyun * After invoking this routine, MAD services are no longer usable by the
684*4882a593Smuzhiyun * client on the associated QP.
685*4882a593Smuzhiyun */
686*4882a593Smuzhiyun void ib_unregister_mad_agent(struct ib_mad_agent *mad_agent);
687*4882a593Smuzhiyun
688*4882a593Smuzhiyun /**
689*4882a593Smuzhiyun * ib_post_send_mad - Posts MAD(s) to the send queue of the QP associated
690*4882a593Smuzhiyun * with the registered client.
691*4882a593Smuzhiyun * @send_buf: Specifies the information needed to send the MAD(s).
692*4882a593Smuzhiyun * @bad_send_buf: Specifies the MAD on which an error was encountered. This
693*4882a593Smuzhiyun * parameter is optional if only a single MAD is posted.
694*4882a593Smuzhiyun *
695*4882a593Smuzhiyun * Sent MADs are not guaranteed to complete in the order that they were posted.
696*4882a593Smuzhiyun *
697*4882a593Smuzhiyun * If the MAD requires RMPP, the data buffer should contain a single copy
698*4882a593Smuzhiyun * of the common MAD, RMPP, and class specific headers, followed by the class
699*4882a593Smuzhiyun * defined data. If the class defined data would not divide evenly into
700*4882a593Smuzhiyun * RMPP segments, then space must be allocated at the end of the referenced
701*4882a593Smuzhiyun * buffer for any required padding. To indicate the amount of class defined
702*4882a593Smuzhiyun * data being transferred, the paylen_newwin field in the RMPP header should
703*4882a593Smuzhiyun * be set to the size of the class specific header plus the amount of class
704*4882a593Smuzhiyun * defined data being transferred. The paylen_newwin field should be
705*4882a593Smuzhiyun * specified in network-byte order.
706*4882a593Smuzhiyun */
707*4882a593Smuzhiyun int ib_post_send_mad(struct ib_mad_send_buf *send_buf,
708*4882a593Smuzhiyun struct ib_mad_send_buf **bad_send_buf);
709*4882a593Smuzhiyun
710*4882a593Smuzhiyun
711*4882a593Smuzhiyun /**
712*4882a593Smuzhiyun * ib_free_recv_mad - Returns data buffers used to receive a MAD.
713*4882a593Smuzhiyun * @mad_recv_wc: Work completion information for a received MAD.
714*4882a593Smuzhiyun *
715*4882a593Smuzhiyun * Clients receiving MADs through their ib_mad_recv_handler must call this
716*4882a593Smuzhiyun * routine to return the work completion buffers to the access layer.
717*4882a593Smuzhiyun */
718*4882a593Smuzhiyun void ib_free_recv_mad(struct ib_mad_recv_wc *mad_recv_wc);
719*4882a593Smuzhiyun
720*4882a593Smuzhiyun /**
721*4882a593Smuzhiyun * ib_cancel_mad - Cancels an outstanding send MAD operation.
722*4882a593Smuzhiyun * @mad_agent: Specifies the registration associated with sent MAD.
723*4882a593Smuzhiyun * @send_buf: Indicates the MAD to cancel.
724*4882a593Smuzhiyun *
725*4882a593Smuzhiyun * MADs will be returned to the user through the corresponding
726*4882a593Smuzhiyun * ib_mad_send_handler.
727*4882a593Smuzhiyun */
728*4882a593Smuzhiyun void ib_cancel_mad(struct ib_mad_agent *mad_agent,
729*4882a593Smuzhiyun struct ib_mad_send_buf *send_buf);
730*4882a593Smuzhiyun
731*4882a593Smuzhiyun /**
732*4882a593Smuzhiyun * ib_modify_mad - Modifies an outstanding send MAD operation.
733*4882a593Smuzhiyun * @mad_agent: Specifies the registration associated with sent MAD.
734*4882a593Smuzhiyun * @send_buf: Indicates the MAD to modify.
735*4882a593Smuzhiyun * @timeout_ms: New timeout value for sent MAD.
736*4882a593Smuzhiyun *
737*4882a593Smuzhiyun * This call will reset the timeout value for a sent MAD to the specified
738*4882a593Smuzhiyun * value.
739*4882a593Smuzhiyun */
740*4882a593Smuzhiyun int ib_modify_mad(struct ib_mad_agent *mad_agent,
741*4882a593Smuzhiyun struct ib_mad_send_buf *send_buf, u32 timeout_ms);
742*4882a593Smuzhiyun
743*4882a593Smuzhiyun /**
744*4882a593Smuzhiyun * ib_create_send_mad - Allocate and initialize a data buffer and work request
745*4882a593Smuzhiyun * for sending a MAD.
746*4882a593Smuzhiyun * @mad_agent: Specifies the registered MAD service to associate with the MAD.
747*4882a593Smuzhiyun * @remote_qpn: Specifies the QPN of the receiving node.
748*4882a593Smuzhiyun * @pkey_index: Specifies which PKey the MAD will be sent using. This field
749*4882a593Smuzhiyun * is valid only if the remote_qpn is QP 1.
750*4882a593Smuzhiyun * @rmpp_active: Indicates if the send will enable RMPP.
751*4882a593Smuzhiyun * @hdr_len: Indicates the size of the data header of the MAD. This length
752*4882a593Smuzhiyun * should include the common MAD header, RMPP header, plus any class
753*4882a593Smuzhiyun * specific header.
754*4882a593Smuzhiyun * @data_len: Indicates the size of any user-transferred data. The call will
755*4882a593Smuzhiyun * automatically adjust the allocated buffer size to account for any
756*4882a593Smuzhiyun * additional padding that may be necessary.
757*4882a593Smuzhiyun * @gfp_mask: GFP mask used for the memory allocation.
758*4882a593Smuzhiyun * @base_version: Base Version of this MAD
759*4882a593Smuzhiyun *
760*4882a593Smuzhiyun * This routine allocates a MAD for sending. The returned MAD send buffer
761*4882a593Smuzhiyun * will reference a data buffer usable for sending a MAD, along
762*4882a593Smuzhiyun * with an initialized work request structure. Users may modify the returned
763*4882a593Smuzhiyun * MAD data buffer before posting the send.
764*4882a593Smuzhiyun *
765*4882a593Smuzhiyun * The returned MAD header, class specific headers, and any padding will be
766*4882a593Smuzhiyun * cleared. Users are responsible for initializing the common MAD header,
767*4882a593Smuzhiyun * any class specific header, and MAD data area.
768*4882a593Smuzhiyun * If @rmpp_active is set, the RMPP header will be initialized for sending.
769*4882a593Smuzhiyun */
770*4882a593Smuzhiyun struct ib_mad_send_buf *ib_create_send_mad(struct ib_mad_agent *mad_agent,
771*4882a593Smuzhiyun u32 remote_qpn, u16 pkey_index,
772*4882a593Smuzhiyun int rmpp_active,
773*4882a593Smuzhiyun int hdr_len, int data_len,
774*4882a593Smuzhiyun gfp_t gfp_mask,
775*4882a593Smuzhiyun u8 base_version);
776*4882a593Smuzhiyun
777*4882a593Smuzhiyun /**
778*4882a593Smuzhiyun * ib_is_mad_class_rmpp - returns whether given management class
779*4882a593Smuzhiyun * supports RMPP.
780*4882a593Smuzhiyun * @mgmt_class: management class
781*4882a593Smuzhiyun *
782*4882a593Smuzhiyun * This routine returns whether the management class supports RMPP.
783*4882a593Smuzhiyun */
784*4882a593Smuzhiyun int ib_is_mad_class_rmpp(u8 mgmt_class);
785*4882a593Smuzhiyun
786*4882a593Smuzhiyun /**
787*4882a593Smuzhiyun * ib_get_mad_data_offset - returns the data offset for a given
788*4882a593Smuzhiyun * management class.
789*4882a593Smuzhiyun * @mgmt_class: management class
790*4882a593Smuzhiyun *
791*4882a593Smuzhiyun * This routine returns the data offset in the MAD for the management
792*4882a593Smuzhiyun * class requested.
793*4882a593Smuzhiyun */
794*4882a593Smuzhiyun int ib_get_mad_data_offset(u8 mgmt_class);
795*4882a593Smuzhiyun
796*4882a593Smuzhiyun /**
797*4882a593Smuzhiyun * ib_get_rmpp_segment - returns the data buffer for a given RMPP segment.
798*4882a593Smuzhiyun * @send_buf: Previously allocated send data buffer.
799*4882a593Smuzhiyun * @seg_num: number of segment to return
800*4882a593Smuzhiyun *
801*4882a593Smuzhiyun * This routine returns a pointer to the data buffer of an RMPP MAD.
802*4882a593Smuzhiyun * Users must provide synchronization to @send_buf around this call.
803*4882a593Smuzhiyun */
804*4882a593Smuzhiyun void *ib_get_rmpp_segment(struct ib_mad_send_buf *send_buf, int seg_num);
805*4882a593Smuzhiyun
806*4882a593Smuzhiyun /**
807*4882a593Smuzhiyun * ib_free_send_mad - Returns data buffers used to send a MAD.
808*4882a593Smuzhiyun * @send_buf: Previously allocated send data buffer.
809*4882a593Smuzhiyun */
810*4882a593Smuzhiyun void ib_free_send_mad(struct ib_mad_send_buf *send_buf);
811*4882a593Smuzhiyun
812*4882a593Smuzhiyun /**
813*4882a593Smuzhiyun * ib_mad_kernel_rmpp_agent - Returns if the agent is performing RMPP.
814*4882a593Smuzhiyun * @agent: the agent in question
815*4882a593Smuzhiyun * @return: true if agent is performing rmpp, false otherwise.
816*4882a593Smuzhiyun */
817*4882a593Smuzhiyun int ib_mad_kernel_rmpp_agent(const struct ib_mad_agent *agent);
818*4882a593Smuzhiyun
819*4882a593Smuzhiyun #endif /* IB_MAD_H */
820