1fe267a55SPedro F. Giffuni /*-
2fe267a55SPedro F. Giffuni * SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0
3fe267a55SPedro F. Giffuni *
4aa0a1e58SJeff Roberson * Copyright (c) 2004 Mellanox Technologies Ltd. All rights reserved.
5aa0a1e58SJeff Roberson * Copyright (c) 2004 Infinicon Corporation. All rights reserved.
6aa0a1e58SJeff Roberson * Copyright (c) 2004 Intel Corporation. All rights reserved.
7aa0a1e58SJeff Roberson * Copyright (c) 2004 Topspin Corporation. All rights reserved.
8aa0a1e58SJeff Roberson * Copyright (c) 2004-2006 Voltaire Corporation. All rights reserved.
9aa0a1e58SJeff Roberson *
10aa0a1e58SJeff Roberson * This software is available to you under a choice of one of two
11aa0a1e58SJeff Roberson * licenses. You may choose to be licensed under the terms of the GNU
12aa0a1e58SJeff Roberson * General Public License (GPL) Version 2, available from the file
13aa0a1e58SJeff Roberson * COPYING in the main directory of this source tree, or the
14aa0a1e58SJeff Roberson * OpenIB.org BSD license below:
15aa0a1e58SJeff Roberson *
16aa0a1e58SJeff Roberson * Redistribution and use in source and binary forms, with or
17aa0a1e58SJeff Roberson * without modification, are permitted provided that the following
18aa0a1e58SJeff Roberson * conditions are met:
19aa0a1e58SJeff Roberson *
20aa0a1e58SJeff Roberson * - Redistributions of source code must retain the above
21aa0a1e58SJeff Roberson * copyright notice, this list of conditions and the following
22aa0a1e58SJeff Roberson * disclaimer.
23aa0a1e58SJeff Roberson *
24aa0a1e58SJeff Roberson * - Redistributions in binary form must reproduce the above
25aa0a1e58SJeff Roberson * copyright notice, this list of conditions and the following
26aa0a1e58SJeff Roberson * disclaimer in the documentation and/or other materials
27aa0a1e58SJeff Roberson * provided with the distribution.
28aa0a1e58SJeff Roberson *
29aa0a1e58SJeff Roberson * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
30aa0a1e58SJeff Roberson * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
31aa0a1e58SJeff Roberson * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
32aa0a1e58SJeff Roberson * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
33aa0a1e58SJeff Roberson * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
34aa0a1e58SJeff Roberson * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
35aa0a1e58SJeff Roberson * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36aa0a1e58SJeff Roberson * SOFTWARE.
37aa0a1e58SJeff Roberson */
38aa0a1e58SJeff Roberson
39aa0a1e58SJeff Roberson #if !defined(IB_MAD_H)
40aa0a1e58SJeff Roberson #define IB_MAD_H
41aa0a1e58SJeff Roberson
42aa0a1e58SJeff Roberson #include <linux/list.h>
43aa0a1e58SJeff Roberson
44aa0a1e58SJeff Roberson #include <rdma/ib_verbs.h>
45*14f19c6bSConrad Meyer #include <uapi/rdma/ib_user_mad.h>
46aa0a1e58SJeff Roberson
47478d3005SHans Petter Selasky /* Management base versions */
48aa0a1e58SJeff Roberson #define IB_MGMT_BASE_VERSION 1
49478d3005SHans Petter Selasky #define OPA_MGMT_BASE_VERSION 0x80
50478d3005SHans Petter Selasky
51478d3005SHans Petter Selasky #define OPA_SMP_CLASS_VERSION 0x80
52aa0a1e58SJeff Roberson
53aa0a1e58SJeff Roberson /* Management classes */
54aa0a1e58SJeff Roberson #define IB_MGMT_CLASS_SUBN_LID_ROUTED 0x01
55aa0a1e58SJeff Roberson #define IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE 0x81
56aa0a1e58SJeff Roberson #define IB_MGMT_CLASS_SUBN_ADM 0x03
57aa0a1e58SJeff Roberson #define IB_MGMT_CLASS_PERF_MGMT 0x04
58aa0a1e58SJeff Roberson #define IB_MGMT_CLASS_BM 0x05
59aa0a1e58SJeff Roberson #define IB_MGMT_CLASS_DEVICE_MGMT 0x06
60aa0a1e58SJeff Roberson #define IB_MGMT_CLASS_CM 0x07
61aa0a1e58SJeff Roberson #define IB_MGMT_CLASS_SNMP 0x08
62aa0a1e58SJeff Roberson #define IB_MGMT_CLASS_DEVICE_ADM 0x10
63aa0a1e58SJeff Roberson #define IB_MGMT_CLASS_BOOT_MGMT 0x11
64aa0a1e58SJeff Roberson #define IB_MGMT_CLASS_BIS 0x12
65aa0a1e58SJeff Roberson #define IB_MGMT_CLASS_CONG_MGMT 0x21
66aa0a1e58SJeff Roberson #define IB_MGMT_CLASS_VENDOR_RANGE2_START 0x30
67aa0a1e58SJeff Roberson #define IB_MGMT_CLASS_VENDOR_RANGE2_END 0x4F
68aa0a1e58SJeff Roberson
69aa0a1e58SJeff Roberson #define IB_OPENIB_OUI (0x001405)
70aa0a1e58SJeff Roberson
71aa0a1e58SJeff Roberson /* Management methods */
72aa0a1e58SJeff Roberson #define IB_MGMT_METHOD_GET 0x01
73aa0a1e58SJeff Roberson #define IB_MGMT_METHOD_SET 0x02
74aa0a1e58SJeff Roberson #define IB_MGMT_METHOD_GET_RESP 0x81
75aa0a1e58SJeff Roberson #define IB_MGMT_METHOD_SEND 0x03
76aa0a1e58SJeff Roberson #define IB_MGMT_METHOD_TRAP 0x05
77aa0a1e58SJeff Roberson #define IB_MGMT_METHOD_REPORT 0x06
78aa0a1e58SJeff Roberson #define IB_MGMT_METHOD_REPORT_RESP 0x86
79aa0a1e58SJeff Roberson #define IB_MGMT_METHOD_TRAP_REPRESS 0x07
80aa0a1e58SJeff Roberson
81aa0a1e58SJeff Roberson #define IB_MGMT_METHOD_RESP 0x80
82aa0a1e58SJeff Roberson #define IB_BM_ATTR_MOD_RESP cpu_to_be32(1)
83aa0a1e58SJeff Roberson
84aa0a1e58SJeff Roberson #define IB_MGMT_MAX_METHODS 128
85aa0a1e58SJeff Roberson
86b5c1e0cbSHans Petter Selasky /* MAD Status field bit masks */
87b5c1e0cbSHans Petter Selasky #define IB_MGMT_MAD_STATUS_SUCCESS 0x0000
88b5c1e0cbSHans Petter Selasky #define IB_MGMT_MAD_STATUS_BUSY 0x0001
89b5c1e0cbSHans Petter Selasky #define IB_MGMT_MAD_STATUS_REDIRECT_REQD 0x0002
90b5c1e0cbSHans Petter Selasky #define IB_MGMT_MAD_STATUS_BAD_VERSION 0x0004
91b5c1e0cbSHans Petter Selasky #define IB_MGMT_MAD_STATUS_UNSUPPORTED_METHOD 0x0008
92b5c1e0cbSHans Petter Selasky #define IB_MGMT_MAD_STATUS_UNSUPPORTED_METHOD_ATTRIB 0x000c
93b5c1e0cbSHans Petter Selasky #define IB_MGMT_MAD_STATUS_INVALID_ATTRIB_VALUE 0x001c
94b5c1e0cbSHans Petter Selasky
95aa0a1e58SJeff Roberson /* RMPP information */
96aa0a1e58SJeff Roberson #define IB_MGMT_RMPP_VERSION 1
97aa0a1e58SJeff Roberson
98aa0a1e58SJeff Roberson #define IB_MGMT_RMPP_TYPE_DATA 1
99aa0a1e58SJeff Roberson #define IB_MGMT_RMPP_TYPE_ACK 2
100aa0a1e58SJeff Roberson #define IB_MGMT_RMPP_TYPE_STOP 3
101aa0a1e58SJeff Roberson #define IB_MGMT_RMPP_TYPE_ABORT 4
102aa0a1e58SJeff Roberson
103aa0a1e58SJeff Roberson #define IB_MGMT_RMPP_FLAG_ACTIVE 1
104aa0a1e58SJeff Roberson #define IB_MGMT_RMPP_FLAG_FIRST (1<<1)
105aa0a1e58SJeff Roberson #define IB_MGMT_RMPP_FLAG_LAST (1<<2)
106aa0a1e58SJeff Roberson
107aa0a1e58SJeff Roberson #define IB_MGMT_RMPP_NO_RESPTIME 0x1F
108aa0a1e58SJeff Roberson
109aa0a1e58SJeff Roberson #define IB_MGMT_RMPP_STATUS_SUCCESS 0
110aa0a1e58SJeff Roberson #define IB_MGMT_RMPP_STATUS_RESX 1
111aa0a1e58SJeff Roberson #define IB_MGMT_RMPP_STATUS_ABORT_MIN 118
112aa0a1e58SJeff Roberson #define IB_MGMT_RMPP_STATUS_T2L 118
113aa0a1e58SJeff Roberson #define IB_MGMT_RMPP_STATUS_BAD_LEN 119
114aa0a1e58SJeff Roberson #define IB_MGMT_RMPP_STATUS_BAD_SEG 120
115aa0a1e58SJeff Roberson #define IB_MGMT_RMPP_STATUS_BADT 121
116aa0a1e58SJeff Roberson #define IB_MGMT_RMPP_STATUS_W2S 122
117aa0a1e58SJeff Roberson #define IB_MGMT_RMPP_STATUS_S2B 123
118aa0a1e58SJeff Roberson #define IB_MGMT_RMPP_STATUS_BAD_STATUS 124
119aa0a1e58SJeff Roberson #define IB_MGMT_RMPP_STATUS_UNV 125
120aa0a1e58SJeff Roberson #define IB_MGMT_RMPP_STATUS_TMR 126
121aa0a1e58SJeff Roberson #define IB_MGMT_RMPP_STATUS_UNSPEC 127
122aa0a1e58SJeff Roberson #define IB_MGMT_RMPP_STATUS_ABORT_MAX 127
123aa0a1e58SJeff Roberson
124aa0a1e58SJeff Roberson #define IB_QP0 0
125aa0a1e58SJeff Roberson #define IB_QP1 cpu_to_be32(1)
126aa0a1e58SJeff Roberson #define IB_QP1_QKEY 0x80010000
127aa0a1e58SJeff Roberson #define IB_QP_SET_QKEY 0x80000000
128aa0a1e58SJeff Roberson
129aa0a1e58SJeff Roberson #define IB_DEFAULT_PKEY_PARTIAL 0x7FFF
130aa0a1e58SJeff Roberson #define IB_DEFAULT_PKEY_FULL 0xFFFF
131aa0a1e58SJeff Roberson
132478d3005SHans Petter Selasky /*
133478d3005SHans Petter Selasky * Generic trap/notice types
134478d3005SHans Petter Selasky */
135478d3005SHans Petter Selasky #define IB_NOTICE_TYPE_FATAL 0x80
136478d3005SHans Petter Selasky #define IB_NOTICE_TYPE_URGENT 0x81
137478d3005SHans Petter Selasky #define IB_NOTICE_TYPE_SECURITY 0x82
138478d3005SHans Petter Selasky #define IB_NOTICE_TYPE_SM 0x83
139478d3005SHans Petter Selasky #define IB_NOTICE_TYPE_INFO 0x84
140478d3005SHans Petter Selasky
141478d3005SHans Petter Selasky /*
142478d3005SHans Petter Selasky * Generic trap/notice producers
143478d3005SHans Petter Selasky */
144478d3005SHans Petter Selasky #define IB_NOTICE_PROD_CA cpu_to_be16(1)
145478d3005SHans Petter Selasky #define IB_NOTICE_PROD_SWITCH cpu_to_be16(2)
146478d3005SHans Petter Selasky #define IB_NOTICE_PROD_ROUTER cpu_to_be16(3)
147478d3005SHans Petter Selasky #define IB_NOTICE_PROD_CLASS_MGR cpu_to_be16(4)
148478d3005SHans Petter Selasky
149aa0a1e58SJeff Roberson enum {
150aa0a1e58SJeff Roberson IB_MGMT_MAD_HDR = 24,
151aa0a1e58SJeff Roberson IB_MGMT_MAD_DATA = 232,
152aa0a1e58SJeff Roberson IB_MGMT_RMPP_HDR = 36,
153aa0a1e58SJeff Roberson IB_MGMT_RMPP_DATA = 220,
154aa0a1e58SJeff Roberson IB_MGMT_VENDOR_HDR = 40,
155aa0a1e58SJeff Roberson IB_MGMT_VENDOR_DATA = 216,
156aa0a1e58SJeff Roberson IB_MGMT_SA_HDR = 56,
157aa0a1e58SJeff Roberson IB_MGMT_SA_DATA = 200,
158aa0a1e58SJeff Roberson IB_MGMT_DEVICE_HDR = 64,
159aa0a1e58SJeff Roberson IB_MGMT_DEVICE_DATA = 192,
160478d3005SHans Petter Selasky IB_MGMT_MAD_SIZE = IB_MGMT_MAD_HDR + IB_MGMT_MAD_DATA,
161478d3005SHans Petter Selasky OPA_MGMT_MAD_DATA = 2024,
162478d3005SHans Petter Selasky OPA_MGMT_RMPP_DATA = 2012,
163478d3005SHans Petter Selasky OPA_MGMT_MAD_SIZE = IB_MGMT_MAD_HDR + OPA_MGMT_MAD_DATA,
164aa0a1e58SJeff Roberson };
165aa0a1e58SJeff Roberson
166aa0a1e58SJeff Roberson struct ib_mad_hdr {
167aa0a1e58SJeff Roberson u8 base_version;
168aa0a1e58SJeff Roberson u8 mgmt_class;
169aa0a1e58SJeff Roberson u8 class_version;
170aa0a1e58SJeff Roberson u8 method;
171aa0a1e58SJeff Roberson __be16 status;
172aa0a1e58SJeff Roberson __be16 class_specific;
173aa0a1e58SJeff Roberson __be64 tid;
174aa0a1e58SJeff Roberson __be16 attr_id;
175aa0a1e58SJeff Roberson __be16 resv;
176aa0a1e58SJeff Roberson __be32 attr_mod;
177aa0a1e58SJeff Roberson };
178aa0a1e58SJeff Roberson
179aa0a1e58SJeff Roberson struct ib_rmpp_hdr {
180aa0a1e58SJeff Roberson u8 rmpp_version;
181aa0a1e58SJeff Roberson u8 rmpp_type;
182aa0a1e58SJeff Roberson u8 rmpp_rtime_flags;
183aa0a1e58SJeff Roberson u8 rmpp_status;
184aa0a1e58SJeff Roberson __be32 seg_num;
185aa0a1e58SJeff Roberson __be32 paylen_newwin;
186aa0a1e58SJeff Roberson };
187aa0a1e58SJeff Roberson
188aa0a1e58SJeff Roberson typedef u64 __bitwise ib_sa_comp_mask;
189aa0a1e58SJeff Roberson
190c9f432b7SAlfred Perlstein #define IB_SA_COMP_MASK(n) ((__force ib_sa_comp_mask) cpu_to_be64(1ull << (n)))
191aa0a1e58SJeff Roberson
192aa0a1e58SJeff Roberson /*
193aa0a1e58SJeff Roberson * ib_sa_hdr and ib_sa_mad structures must be packed because they have
194aa0a1e58SJeff Roberson * 64-bit fields that are only 32-bit aligned. 64-bit architectures will
195aa0a1e58SJeff Roberson * lay them out wrong otherwise. (And unfortunately they are sent on
196aa0a1e58SJeff Roberson * the wire so we can't change the layout)
197aa0a1e58SJeff Roberson */
198aa0a1e58SJeff Roberson struct ib_sa_hdr {
199aa0a1e58SJeff Roberson __be64 sm_key;
200aa0a1e58SJeff Roberson __be16 attr_offset;
201aa0a1e58SJeff Roberson __be16 reserved;
202aa0a1e58SJeff Roberson ib_sa_comp_mask comp_mask;
203aa0a1e58SJeff Roberson } __attribute__ ((packed));
204aa0a1e58SJeff Roberson
205aa0a1e58SJeff Roberson struct ib_mad {
206aa0a1e58SJeff Roberson struct ib_mad_hdr mad_hdr;
207aa0a1e58SJeff Roberson u8 data[IB_MGMT_MAD_DATA];
208aa0a1e58SJeff Roberson };
209aa0a1e58SJeff Roberson
210478d3005SHans Petter Selasky struct opa_mad {
211478d3005SHans Petter Selasky struct ib_mad_hdr mad_hdr;
212478d3005SHans Petter Selasky u8 data[OPA_MGMT_MAD_DATA];
213478d3005SHans Petter Selasky };
214478d3005SHans Petter Selasky
215aa0a1e58SJeff Roberson struct ib_rmpp_mad {
216aa0a1e58SJeff Roberson struct ib_mad_hdr mad_hdr;
217aa0a1e58SJeff Roberson struct ib_rmpp_hdr rmpp_hdr;
218aa0a1e58SJeff Roberson u8 data[IB_MGMT_RMPP_DATA];
219aa0a1e58SJeff Roberson };
220aa0a1e58SJeff Roberson
221478d3005SHans Petter Selasky struct opa_rmpp_mad {
222478d3005SHans Petter Selasky struct ib_mad_hdr mad_hdr;
223478d3005SHans Petter Selasky struct ib_rmpp_hdr rmpp_hdr;
224478d3005SHans Petter Selasky u8 data[OPA_MGMT_RMPP_DATA];
225478d3005SHans Petter Selasky };
226478d3005SHans Petter Selasky
227aa0a1e58SJeff Roberson struct ib_sa_mad {
228aa0a1e58SJeff Roberson struct ib_mad_hdr mad_hdr;
229aa0a1e58SJeff Roberson struct ib_rmpp_hdr rmpp_hdr;
230aa0a1e58SJeff Roberson struct ib_sa_hdr sa_hdr;
231aa0a1e58SJeff Roberson u8 data[IB_MGMT_SA_DATA];
232aa0a1e58SJeff Roberson } __attribute__ ((packed));
233aa0a1e58SJeff Roberson
234aa0a1e58SJeff Roberson struct ib_vendor_mad {
235aa0a1e58SJeff Roberson struct ib_mad_hdr mad_hdr;
236aa0a1e58SJeff Roberson struct ib_rmpp_hdr rmpp_hdr;
237aa0a1e58SJeff Roberson u8 reserved;
238aa0a1e58SJeff Roberson u8 oui[3];
239aa0a1e58SJeff Roberson u8 data[IB_MGMT_VENDOR_DATA];
240aa0a1e58SJeff Roberson };
241aa0a1e58SJeff Roberson
242478d3005SHans Petter Selasky #define IB_MGMT_CLASSPORTINFO_ATTR_ID cpu_to_be16(0x0001)
243478d3005SHans Petter Selasky
244478d3005SHans Petter Selasky #define IB_CLASS_PORT_INFO_RESP_TIME_MASK 0x1F
245478d3005SHans Petter Selasky #define IB_CLASS_PORT_INFO_RESP_TIME_FIELD_SIZE 5
246478d3005SHans Petter Selasky
247aa0a1e58SJeff Roberson struct ib_class_port_info {
248aa0a1e58SJeff Roberson u8 base_version;
249aa0a1e58SJeff Roberson u8 class_version;
250aa0a1e58SJeff Roberson __be16 capability_mask;
251478d3005SHans Petter Selasky /* 27 bits for cap_mask2, 5 bits for resp_time */
252478d3005SHans Petter Selasky __be32 cap_mask2_resp_time;
253aa0a1e58SJeff Roberson u8 redirect_gid[16];
254aa0a1e58SJeff Roberson __be32 redirect_tcslfl;
255aa0a1e58SJeff Roberson __be16 redirect_lid;
256aa0a1e58SJeff Roberson __be16 redirect_pkey;
257aa0a1e58SJeff Roberson __be32 redirect_qp;
258aa0a1e58SJeff Roberson __be32 redirect_qkey;
259aa0a1e58SJeff Roberson u8 trap_gid[16];
260aa0a1e58SJeff Roberson __be32 trap_tcslfl;
261aa0a1e58SJeff Roberson __be16 trap_lid;
262aa0a1e58SJeff Roberson __be16 trap_pkey;
263aa0a1e58SJeff Roberson __be32 trap_hlqp;
264aa0a1e58SJeff Roberson __be32 trap_qkey;
265aa0a1e58SJeff Roberson };
266aa0a1e58SJeff Roberson
267aa0a1e58SJeff Roberson /**
268478d3005SHans Petter Selasky * ib_get_cpi_resp_time - Returns the resp_time value from
269478d3005SHans Petter Selasky * cap_mask2_resp_time in ib_class_port_info.
270478d3005SHans Petter Selasky * @cpi: A struct ib_class_port_info mad.
271478d3005SHans Petter Selasky */
ib_get_cpi_resp_time(struct ib_class_port_info * cpi)272478d3005SHans Petter Selasky static inline u8 ib_get_cpi_resp_time(struct ib_class_port_info *cpi)
273478d3005SHans Petter Selasky {
274478d3005SHans Petter Selasky return (u8)(be32_to_cpu(cpi->cap_mask2_resp_time) &
275478d3005SHans Petter Selasky IB_CLASS_PORT_INFO_RESP_TIME_MASK);
276478d3005SHans Petter Selasky }
277478d3005SHans Petter Selasky
278478d3005SHans Petter Selasky /**
279478d3005SHans Petter Selasky * ib_set_cpi_resptime - Sets the response time in an
280478d3005SHans Petter Selasky * ib_class_port_info mad.
281478d3005SHans Petter Selasky * @cpi: A struct ib_class_port_info.
282478d3005SHans Petter Selasky * @rtime: The response time to set.
283478d3005SHans Petter Selasky */
ib_set_cpi_resp_time(struct ib_class_port_info * cpi,u8 rtime)284478d3005SHans Petter Selasky static inline void ib_set_cpi_resp_time(struct ib_class_port_info *cpi,
285478d3005SHans Petter Selasky u8 rtime)
286478d3005SHans Petter Selasky {
287478d3005SHans Petter Selasky cpi->cap_mask2_resp_time =
288478d3005SHans Petter Selasky (cpi->cap_mask2_resp_time &
289478d3005SHans Petter Selasky cpu_to_be32(~IB_CLASS_PORT_INFO_RESP_TIME_MASK)) |
290478d3005SHans Petter Selasky cpu_to_be32(rtime & IB_CLASS_PORT_INFO_RESP_TIME_MASK);
291478d3005SHans Petter Selasky }
292478d3005SHans Petter Selasky
293478d3005SHans Petter Selasky /**
294478d3005SHans Petter Selasky * ib_get_cpi_capmask2 - Returns the capmask2 value from
295478d3005SHans Petter Selasky * cap_mask2_resp_time in ib_class_port_info.
296478d3005SHans Petter Selasky * @cpi: A struct ib_class_port_info mad.
297478d3005SHans Petter Selasky */
ib_get_cpi_capmask2(struct ib_class_port_info * cpi)298478d3005SHans Petter Selasky static inline u32 ib_get_cpi_capmask2(struct ib_class_port_info *cpi)
299478d3005SHans Petter Selasky {
300478d3005SHans Petter Selasky return (be32_to_cpu(cpi->cap_mask2_resp_time) >>
301478d3005SHans Petter Selasky IB_CLASS_PORT_INFO_RESP_TIME_FIELD_SIZE);
302478d3005SHans Petter Selasky }
303478d3005SHans Petter Selasky
304478d3005SHans Petter Selasky /**
305478d3005SHans Petter Selasky * ib_set_cpi_capmask2 - Sets the capmask2 in an
306478d3005SHans Petter Selasky * ib_class_port_info mad.
307478d3005SHans Petter Selasky * @cpi: A struct ib_class_port_info.
308478d3005SHans Petter Selasky * @capmask2: The capmask2 to set.
309478d3005SHans Petter Selasky */
ib_set_cpi_capmask2(struct ib_class_port_info * cpi,u32 capmask2)310478d3005SHans Petter Selasky static inline void ib_set_cpi_capmask2(struct ib_class_port_info *cpi,
311478d3005SHans Petter Selasky u32 capmask2)
312478d3005SHans Petter Selasky {
313478d3005SHans Petter Selasky cpi->cap_mask2_resp_time =
314478d3005SHans Petter Selasky (cpi->cap_mask2_resp_time &
315478d3005SHans Petter Selasky cpu_to_be32(IB_CLASS_PORT_INFO_RESP_TIME_MASK)) |
316478d3005SHans Petter Selasky cpu_to_be32(capmask2 <<
317478d3005SHans Petter Selasky IB_CLASS_PORT_INFO_RESP_TIME_FIELD_SIZE);
318478d3005SHans Petter Selasky }
319478d3005SHans Petter Selasky
320478d3005SHans Petter Selasky struct ib_mad_notice_attr {
321478d3005SHans Petter Selasky u8 generic_type;
322478d3005SHans Petter Selasky u8 prod_type_msb;
323478d3005SHans Petter Selasky __be16 prod_type_lsb;
324478d3005SHans Petter Selasky __be16 trap_num;
325478d3005SHans Petter Selasky __be16 issuer_lid;
326478d3005SHans Petter Selasky __be16 toggle_count;
327478d3005SHans Petter Selasky
328478d3005SHans Petter Selasky union {
329478d3005SHans Petter Selasky struct {
330478d3005SHans Petter Selasky u8 details[54];
331478d3005SHans Petter Selasky } raw_data;
332478d3005SHans Petter Selasky
333478d3005SHans Petter Selasky struct {
334478d3005SHans Petter Selasky __be16 reserved;
335478d3005SHans Petter Selasky __be16 lid; /* where violation happened */
336478d3005SHans Petter Selasky u8 port_num; /* where violation happened */
337478d3005SHans Petter Selasky } __packed ntc_129_131;
338478d3005SHans Petter Selasky
339478d3005SHans Petter Selasky struct {
340478d3005SHans Petter Selasky __be16 reserved;
341478d3005SHans Petter Selasky __be16 lid; /* LID where change occurred */
342478d3005SHans Petter Selasky u8 reserved2;
343478d3005SHans Petter Selasky u8 local_changes; /* low bit - local changes */
344478d3005SHans Petter Selasky __be32 new_cap_mask; /* new capability mask */
345478d3005SHans Petter Selasky u8 reserved3;
346478d3005SHans Petter Selasky u8 change_flags; /* low 3 bits only */
347478d3005SHans Petter Selasky } __packed ntc_144;
348478d3005SHans Petter Selasky
349478d3005SHans Petter Selasky struct {
350478d3005SHans Petter Selasky __be16 reserved;
351478d3005SHans Petter Selasky __be16 lid; /* lid where sys guid changed */
352478d3005SHans Petter Selasky __be16 reserved2;
353478d3005SHans Petter Selasky __be64 new_sys_guid;
354478d3005SHans Petter Selasky } __packed ntc_145;
355478d3005SHans Petter Selasky
356478d3005SHans Petter Selasky struct {
357478d3005SHans Petter Selasky __be16 reserved;
358478d3005SHans Petter Selasky __be16 lid;
359478d3005SHans Petter Selasky __be16 dr_slid;
360478d3005SHans Petter Selasky u8 method;
361478d3005SHans Petter Selasky u8 reserved2;
362478d3005SHans Petter Selasky __be16 attr_id;
363478d3005SHans Petter Selasky __be32 attr_mod;
364478d3005SHans Petter Selasky __be64 mkey;
365478d3005SHans Petter Selasky u8 reserved3;
366478d3005SHans Petter Selasky u8 dr_trunc_hop;
367478d3005SHans Petter Selasky u8 dr_rtn_path[30];
368478d3005SHans Petter Selasky } __packed ntc_256;
369478d3005SHans Petter Selasky
370478d3005SHans Petter Selasky struct {
371478d3005SHans Petter Selasky __be16 reserved;
372478d3005SHans Petter Selasky __be16 lid1;
373478d3005SHans Petter Selasky __be16 lid2;
374478d3005SHans Petter Selasky __be32 key;
375478d3005SHans Petter Selasky __be32 sl_qp1; /* SL: high 4 bits */
376478d3005SHans Petter Selasky __be32 qp2; /* high 8 bits reserved */
377478d3005SHans Petter Selasky union ib_gid gid1;
378478d3005SHans Petter Selasky union ib_gid gid2;
379478d3005SHans Petter Selasky } __packed ntc_257_258;
380478d3005SHans Petter Selasky
381478d3005SHans Petter Selasky } details;
382478d3005SHans Petter Selasky };
383478d3005SHans Petter Selasky
384478d3005SHans Petter Selasky /**
385aa0a1e58SJeff Roberson * ib_mad_send_buf - MAD data buffer and work request for sends.
386aa0a1e58SJeff Roberson * @next: A pointer used to chain together MADs for posting.
387aa0a1e58SJeff Roberson * @mad: References an allocated MAD data buffer for MADs that do not have
388aa0a1e58SJeff Roberson * RMPP active. For MADs using RMPP, references the common and management
389aa0a1e58SJeff Roberson * class specific headers.
390aa0a1e58SJeff Roberson * @mad_agent: MAD agent that allocated the buffer.
391aa0a1e58SJeff Roberson * @ah: The address handle to use when sending the MAD.
392aa0a1e58SJeff Roberson * @context: User-controlled context fields.
393aa0a1e58SJeff Roberson * @hdr_len: Indicates the size of the data header of the MAD. This length
394aa0a1e58SJeff Roberson * includes the common MAD, RMPP, and class specific headers.
395aa0a1e58SJeff Roberson * @data_len: Indicates the total size of user-transferred data.
396aa0a1e58SJeff Roberson * @seg_count: The number of RMPP segments allocated for this send.
397478d3005SHans Petter Selasky * @seg_size: Size of the data in each RMPP segment. This does not include
398478d3005SHans Petter Selasky * class specific headers.
399478d3005SHans Petter Selasky * @seg_rmpp_size: Size of each RMPP segment including the class specific
400478d3005SHans Petter Selasky * headers.
401aa0a1e58SJeff Roberson * @timeout_ms: Time to wait for a response.
402aa0a1e58SJeff Roberson * @retries: Number of times to retry a request for a response. For MADs
403aa0a1e58SJeff Roberson * using RMPP, this applies per window. On completion, returns the number
404aa0a1e58SJeff Roberson * of retries needed to complete the transfer.
405aa0a1e58SJeff Roberson *
406aa0a1e58SJeff Roberson * Users are responsible for initializing the MAD buffer itself, with the
407aa0a1e58SJeff Roberson * exception of any RMPP header. Additional segment buffer space allocated
408aa0a1e58SJeff Roberson * beyond data_len is padding.
409aa0a1e58SJeff Roberson */
410aa0a1e58SJeff Roberson struct ib_mad_send_buf {
411aa0a1e58SJeff Roberson struct ib_mad_send_buf *next;
412aa0a1e58SJeff Roberson void *mad;
413aa0a1e58SJeff Roberson struct ib_mad_agent *mad_agent;
414aa0a1e58SJeff Roberson struct ib_ah *ah;
415aa0a1e58SJeff Roberson void *context[2];
416aa0a1e58SJeff Roberson int hdr_len;
417aa0a1e58SJeff Roberson int data_len;
418aa0a1e58SJeff Roberson int seg_count;
419aa0a1e58SJeff Roberson int seg_size;
420478d3005SHans Petter Selasky int seg_rmpp_size;
421aa0a1e58SJeff Roberson int timeout_ms;
422aa0a1e58SJeff Roberson int retries;
423aa0a1e58SJeff Roberson };
424aa0a1e58SJeff Roberson
425aa0a1e58SJeff Roberson /**
426aa0a1e58SJeff Roberson * ib_response_mad - Returns if the specified MAD has been generated in
427aa0a1e58SJeff Roberson * response to a sent request or trap.
428aa0a1e58SJeff Roberson */
429478d3005SHans Petter Selasky int ib_response_mad(const struct ib_mad_hdr *hdr);
430aa0a1e58SJeff Roberson
431aa0a1e58SJeff Roberson /**
432aa0a1e58SJeff Roberson * ib_get_rmpp_resptime - Returns the RMPP response time.
433aa0a1e58SJeff Roberson * @rmpp_hdr: An RMPP header.
434aa0a1e58SJeff Roberson */
ib_get_rmpp_resptime(struct ib_rmpp_hdr * rmpp_hdr)435aa0a1e58SJeff Roberson static inline u8 ib_get_rmpp_resptime(struct ib_rmpp_hdr *rmpp_hdr)
436aa0a1e58SJeff Roberson {
437aa0a1e58SJeff Roberson return rmpp_hdr->rmpp_rtime_flags >> 3;
438aa0a1e58SJeff Roberson }
439aa0a1e58SJeff Roberson
440aa0a1e58SJeff Roberson /**
441aa0a1e58SJeff Roberson * ib_get_rmpp_flags - Returns the RMPP flags.
442aa0a1e58SJeff Roberson * @rmpp_hdr: An RMPP header.
443aa0a1e58SJeff Roberson */
ib_get_rmpp_flags(const struct ib_rmpp_hdr * rmpp_hdr)444478d3005SHans Petter Selasky static inline u8 ib_get_rmpp_flags(const struct ib_rmpp_hdr *rmpp_hdr)
445aa0a1e58SJeff Roberson {
446aa0a1e58SJeff Roberson return rmpp_hdr->rmpp_rtime_flags & 0x7;
447aa0a1e58SJeff Roberson }
448aa0a1e58SJeff Roberson
449aa0a1e58SJeff Roberson /**
450aa0a1e58SJeff Roberson * ib_set_rmpp_resptime - Sets the response time in an RMPP header.
451aa0a1e58SJeff Roberson * @rmpp_hdr: An RMPP header.
452aa0a1e58SJeff Roberson * @rtime: The response time to set.
453aa0a1e58SJeff Roberson */
ib_set_rmpp_resptime(struct ib_rmpp_hdr * rmpp_hdr,u8 rtime)454aa0a1e58SJeff Roberson static inline void ib_set_rmpp_resptime(struct ib_rmpp_hdr *rmpp_hdr, u8 rtime)
455aa0a1e58SJeff Roberson {
456aa0a1e58SJeff Roberson rmpp_hdr->rmpp_rtime_flags = ib_get_rmpp_flags(rmpp_hdr) | (rtime << 3);
457aa0a1e58SJeff Roberson }
458aa0a1e58SJeff Roberson
459aa0a1e58SJeff Roberson /**
460aa0a1e58SJeff Roberson * ib_set_rmpp_flags - Sets the flags in an RMPP header.
461aa0a1e58SJeff Roberson * @rmpp_hdr: An RMPP header.
462aa0a1e58SJeff Roberson * @flags: The flags to set.
463aa0a1e58SJeff Roberson */
ib_set_rmpp_flags(struct ib_rmpp_hdr * rmpp_hdr,u8 flags)464aa0a1e58SJeff Roberson static inline void ib_set_rmpp_flags(struct ib_rmpp_hdr *rmpp_hdr, u8 flags)
465aa0a1e58SJeff Roberson {
466aa0a1e58SJeff Roberson rmpp_hdr->rmpp_rtime_flags = (rmpp_hdr->rmpp_rtime_flags & 0xF8) |
467aa0a1e58SJeff Roberson (flags & 0x7);
468aa0a1e58SJeff Roberson }
469aa0a1e58SJeff Roberson
470aa0a1e58SJeff Roberson struct ib_mad_agent;
471aa0a1e58SJeff Roberson struct ib_mad_send_wc;
472aa0a1e58SJeff Roberson struct ib_mad_recv_wc;
473aa0a1e58SJeff Roberson
474aa0a1e58SJeff Roberson /**
475aa0a1e58SJeff Roberson * ib_mad_send_handler - callback handler for a sent MAD.
476aa0a1e58SJeff Roberson * @mad_agent: MAD agent that sent the MAD.
477aa0a1e58SJeff Roberson * @mad_send_wc: Send work completion information on the sent MAD.
478aa0a1e58SJeff Roberson */
479aa0a1e58SJeff Roberson typedef void (*ib_mad_send_handler)(struct ib_mad_agent *mad_agent,
480aa0a1e58SJeff Roberson struct ib_mad_send_wc *mad_send_wc);
481aa0a1e58SJeff Roberson
482aa0a1e58SJeff Roberson /**
483aa0a1e58SJeff Roberson * ib_mad_snoop_handler - Callback handler for snooping sent MADs.
484aa0a1e58SJeff Roberson * @mad_agent: MAD agent that snooped the MAD.
485478d3005SHans Petter Selasky * @send_buf: send MAD data buffer.
486aa0a1e58SJeff Roberson * @mad_send_wc: Work completion information on the sent MAD. Valid
487aa0a1e58SJeff Roberson * only for snooping that occurs on a send completion.
488aa0a1e58SJeff Roberson *
489478d3005SHans Petter Selasky * Clients snooping MADs should not modify data referenced by the @send_buf
490aa0a1e58SJeff Roberson * or @mad_send_wc.
491aa0a1e58SJeff Roberson */
492aa0a1e58SJeff Roberson typedef void (*ib_mad_snoop_handler)(struct ib_mad_agent *mad_agent,
493aa0a1e58SJeff Roberson struct ib_mad_send_buf *send_buf,
494aa0a1e58SJeff Roberson struct ib_mad_send_wc *mad_send_wc);
495aa0a1e58SJeff Roberson
496aa0a1e58SJeff Roberson /**
497aa0a1e58SJeff Roberson * ib_mad_recv_handler - callback handler for a received MAD.
498aa0a1e58SJeff Roberson * @mad_agent: MAD agent requesting the received MAD.
499478d3005SHans Petter Selasky * @send_buf: Send buffer if found, else NULL
500aa0a1e58SJeff Roberson * @mad_recv_wc: Received work completion information on the received MAD.
501aa0a1e58SJeff Roberson *
502aa0a1e58SJeff Roberson * MADs received in response to a send request operation will be handed to
503aa0a1e58SJeff Roberson * the user before the send operation completes. All data buffers given
504aa0a1e58SJeff Roberson * to registered agents through this routine are owned by the receiving
505aa0a1e58SJeff Roberson * client, except for snooping agents. Clients snooping MADs should not
506aa0a1e58SJeff Roberson * modify the data referenced by @mad_recv_wc.
507aa0a1e58SJeff Roberson */
508aa0a1e58SJeff Roberson typedef void (*ib_mad_recv_handler)(struct ib_mad_agent *mad_agent,
509478d3005SHans Petter Selasky struct ib_mad_send_buf *send_buf,
510aa0a1e58SJeff Roberson struct ib_mad_recv_wc *mad_recv_wc);
511aa0a1e58SJeff Roberson
512aa0a1e58SJeff Roberson /**
513aa0a1e58SJeff Roberson * ib_mad_agent - Used to track MAD registration with the access layer.
514aa0a1e58SJeff Roberson * @device: Reference to device registration is on.
515aa0a1e58SJeff Roberson * @qp: Reference to QP used for sending and receiving MADs.
516aa0a1e58SJeff Roberson * @mr: Memory region for system memory usable for DMA.
517aa0a1e58SJeff Roberson * @recv_handler: Callback handler for a received MAD.
518aa0a1e58SJeff Roberson * @send_handler: Callback handler for a sent MAD.
519aa0a1e58SJeff Roberson * @snoop_handler: Callback handler for snooped sent MADs.
520aa0a1e58SJeff Roberson * @context: User-specified context associated with this registration.
521aa0a1e58SJeff Roberson * @hi_tid: Access layer assigned transaction ID for this client.
522aa0a1e58SJeff Roberson * Unsolicited MADs sent by this client will have the upper 32-bits
523aa0a1e58SJeff Roberson * of their TID set to this value.
524478d3005SHans Petter Selasky * @flags: registration flags
525aa0a1e58SJeff Roberson * @port_num: Port number on which QP is registered
526aa0a1e58SJeff Roberson * @rmpp_version: If set, indicates the RMPP version used by this agent.
527aa0a1e58SJeff Roberson */
528478d3005SHans Petter Selasky enum {
529478d3005SHans Petter Selasky IB_MAD_USER_RMPP = IB_USER_MAD_USER_RMPP,
530478d3005SHans Petter Selasky };
531aa0a1e58SJeff Roberson struct ib_mad_agent {
532aa0a1e58SJeff Roberson struct ib_device *device;
533aa0a1e58SJeff Roberson struct ib_qp *qp;
534aa0a1e58SJeff Roberson ib_mad_recv_handler recv_handler;
535aa0a1e58SJeff Roberson ib_mad_send_handler send_handler;
536aa0a1e58SJeff Roberson ib_mad_snoop_handler snoop_handler;
537aa0a1e58SJeff Roberson void *context;
538aa0a1e58SJeff Roberson u32 hi_tid;
539478d3005SHans Petter Selasky u32 flags;
540aa0a1e58SJeff Roberson u8 port_num;
541aa0a1e58SJeff Roberson u8 rmpp_version;
542aa0a1e58SJeff Roberson };
543aa0a1e58SJeff Roberson
544aa0a1e58SJeff Roberson /**
545aa0a1e58SJeff Roberson * ib_mad_send_wc - MAD send completion information.
546aa0a1e58SJeff Roberson * @send_buf: Send MAD data buffer associated with the send MAD request.
547aa0a1e58SJeff Roberson * @status: Completion status.
548aa0a1e58SJeff Roberson * @vendor_err: Optional vendor error information returned with a failed
549aa0a1e58SJeff Roberson * request.
550aa0a1e58SJeff Roberson */
551aa0a1e58SJeff Roberson struct ib_mad_send_wc {
552aa0a1e58SJeff Roberson struct ib_mad_send_buf *send_buf;
553aa0a1e58SJeff Roberson enum ib_wc_status status;
554aa0a1e58SJeff Roberson u32 vendor_err;
555aa0a1e58SJeff Roberson };
556aa0a1e58SJeff Roberson
557aa0a1e58SJeff Roberson /**
558aa0a1e58SJeff Roberson * ib_mad_recv_buf - received MAD buffer information.
559aa0a1e58SJeff Roberson * @list: Reference to next data buffer for a received RMPP MAD.
560aa0a1e58SJeff Roberson * @grh: References a data buffer containing the global route header.
561aa0a1e58SJeff Roberson * The data refereced by this buffer is only valid if the GRH is
562aa0a1e58SJeff Roberson * valid.
563aa0a1e58SJeff Roberson * @mad: References the start of the received MAD.
564aa0a1e58SJeff Roberson */
565aa0a1e58SJeff Roberson struct ib_mad_recv_buf {
566aa0a1e58SJeff Roberson struct list_head list;
567aa0a1e58SJeff Roberson struct ib_grh *grh;
568478d3005SHans Petter Selasky union {
569aa0a1e58SJeff Roberson struct ib_mad *mad;
570478d3005SHans Petter Selasky struct opa_mad *opa_mad;
571478d3005SHans Petter Selasky };
572aa0a1e58SJeff Roberson };
573aa0a1e58SJeff Roberson
574aa0a1e58SJeff Roberson /**
575aa0a1e58SJeff Roberson * ib_mad_recv_wc - received MAD information.
576aa0a1e58SJeff Roberson * @wc: Completion information for the received data.
577aa0a1e58SJeff Roberson * @recv_buf: Specifies the location of the received data buffer(s).
578aa0a1e58SJeff Roberson * @rmpp_list: Specifies a list of RMPP reassembled received MAD buffers.
579aa0a1e58SJeff Roberson * @mad_len: The length of the received MAD, without duplicated headers.
580478d3005SHans Petter Selasky * @mad_seg_size: The size of individual MAD segments
581aa0a1e58SJeff Roberson *
582aa0a1e58SJeff Roberson * For received response, the wr_id contains a pointer to the ib_mad_send_buf
583aa0a1e58SJeff Roberson * for the corresponding send request.
584aa0a1e58SJeff Roberson */
585aa0a1e58SJeff Roberson struct ib_mad_recv_wc {
586aa0a1e58SJeff Roberson struct ib_wc *wc;
587aa0a1e58SJeff Roberson struct ib_mad_recv_buf recv_buf;
588aa0a1e58SJeff Roberson struct list_head rmpp_list;
589aa0a1e58SJeff Roberson int mad_len;
590478d3005SHans Petter Selasky size_t mad_seg_size;
591aa0a1e58SJeff Roberson };
592aa0a1e58SJeff Roberson
593aa0a1e58SJeff Roberson /**
594aa0a1e58SJeff Roberson * ib_mad_reg_req - MAD registration request
595aa0a1e58SJeff Roberson * @mgmt_class: Indicates which management class of MADs should be receive
596aa0a1e58SJeff Roberson * by the caller. This field is only required if the user wishes to
597aa0a1e58SJeff Roberson * receive unsolicited MADs, otherwise it should be 0.
598aa0a1e58SJeff Roberson * @mgmt_class_version: Indicates which version of MADs for the given
599aa0a1e58SJeff Roberson * management class to receive.
600aa0a1e58SJeff Roberson * @oui: Indicates IEEE OUI when mgmt_class is a vendor class
601aa0a1e58SJeff Roberson * in the range from 0x30 to 0x4f. Otherwise not used.
602aa0a1e58SJeff Roberson * @method_mask: The caller will receive unsolicited MADs for any method
603aa0a1e58SJeff Roberson * where @method_mask = 1.
604478d3005SHans Petter Selasky *
605aa0a1e58SJeff Roberson */
606aa0a1e58SJeff Roberson struct ib_mad_reg_req {
607aa0a1e58SJeff Roberson u8 mgmt_class;
608aa0a1e58SJeff Roberson u8 mgmt_class_version;
609aa0a1e58SJeff Roberson u8 oui[3];
610aa0a1e58SJeff Roberson DECLARE_BITMAP(method_mask, IB_MGMT_MAX_METHODS);
611aa0a1e58SJeff Roberson };
612aa0a1e58SJeff Roberson
613aa0a1e58SJeff Roberson /**
614aa0a1e58SJeff Roberson * ib_register_mad_agent - Register to send/receive MADs.
615aa0a1e58SJeff Roberson * @device: The device to register with.
616aa0a1e58SJeff Roberson * @port_num: The port on the specified device to use.
617aa0a1e58SJeff Roberson * @qp_type: Specifies which QP to access. Must be either
618aa0a1e58SJeff Roberson * IB_QPT_SMI or IB_QPT_GSI.
619aa0a1e58SJeff Roberson * @mad_reg_req: Specifies which unsolicited MADs should be received
620aa0a1e58SJeff Roberson * by the caller. This parameter may be NULL if the caller only
621aa0a1e58SJeff Roberson * wishes to receive solicited responses.
622aa0a1e58SJeff Roberson * @rmpp_version: If set, indicates that the client will send
623aa0a1e58SJeff Roberson * and receive MADs that contain the RMPP header for the given version.
624aa0a1e58SJeff Roberson * If set to 0, indicates that RMPP is not used by this client.
625aa0a1e58SJeff Roberson * @send_handler: The completion callback routine invoked after a send
626aa0a1e58SJeff Roberson * request has completed.
627aa0a1e58SJeff Roberson * @recv_handler: The completion callback routine invoked for a received
628aa0a1e58SJeff Roberson * MAD.
629aa0a1e58SJeff Roberson * @context: User specified context associated with the registration.
630478d3005SHans Petter Selasky * @registration_flags: Registration flags to set for this agent
631aa0a1e58SJeff Roberson */
632aa0a1e58SJeff Roberson struct ib_mad_agent *ib_register_mad_agent(struct ib_device *device,
633aa0a1e58SJeff Roberson u8 port_num,
634aa0a1e58SJeff Roberson enum ib_qp_type qp_type,
635aa0a1e58SJeff Roberson struct ib_mad_reg_req *mad_reg_req,
636aa0a1e58SJeff Roberson u8 rmpp_version,
637aa0a1e58SJeff Roberson ib_mad_send_handler send_handler,
638aa0a1e58SJeff Roberson ib_mad_recv_handler recv_handler,
639478d3005SHans Petter Selasky void *context,
640478d3005SHans Petter Selasky u32 registration_flags);
641aa0a1e58SJeff Roberson
642aa0a1e58SJeff Roberson enum ib_mad_snoop_flags {
643aa0a1e58SJeff Roberson /*IB_MAD_SNOOP_POSTED_SENDS = 1,*/
644aa0a1e58SJeff Roberson /*IB_MAD_SNOOP_RMPP_SENDS = (1<<1),*/
645aa0a1e58SJeff Roberson IB_MAD_SNOOP_SEND_COMPLETIONS = (1<<2),
646aa0a1e58SJeff Roberson /*IB_MAD_SNOOP_RMPP_SEND_COMPLETIONS = (1<<3),*/
647aa0a1e58SJeff Roberson IB_MAD_SNOOP_RECVS = (1<<4)
648aa0a1e58SJeff Roberson /*IB_MAD_SNOOP_RMPP_RECVS = (1<<5),*/
649aa0a1e58SJeff Roberson /*IB_MAD_SNOOP_REDIRECTED_QPS = (1<<6)*/
650aa0a1e58SJeff Roberson };
651aa0a1e58SJeff Roberson
652aa0a1e58SJeff Roberson /**
653aa0a1e58SJeff Roberson * ib_register_mad_snoop - Register to snoop sent and received MADs.
654aa0a1e58SJeff Roberson * @device: The device to register with.
655aa0a1e58SJeff Roberson * @port_num: The port on the specified device to use.
656aa0a1e58SJeff Roberson * @qp_type: Specifies which QP traffic to snoop. Must be either
657aa0a1e58SJeff Roberson * IB_QPT_SMI or IB_QPT_GSI.
658aa0a1e58SJeff Roberson * @mad_snoop_flags: Specifies information where snooping occurs.
659aa0a1e58SJeff Roberson * @send_handler: The callback routine invoked for a snooped send.
660aa0a1e58SJeff Roberson * @recv_handler: The callback routine invoked for a snooped receive.
661aa0a1e58SJeff Roberson * @context: User specified context associated with the registration.
662aa0a1e58SJeff Roberson */
663aa0a1e58SJeff Roberson struct ib_mad_agent *ib_register_mad_snoop(struct ib_device *device,
664aa0a1e58SJeff Roberson u8 port_num,
665aa0a1e58SJeff Roberson enum ib_qp_type qp_type,
666aa0a1e58SJeff Roberson int mad_snoop_flags,
667aa0a1e58SJeff Roberson ib_mad_snoop_handler snoop_handler,
668aa0a1e58SJeff Roberson ib_mad_recv_handler recv_handler,
669aa0a1e58SJeff Roberson void *context);
670aa0a1e58SJeff Roberson
671aa0a1e58SJeff Roberson /**
672aa0a1e58SJeff Roberson * ib_unregister_mad_agent - Unregisters a client from using MAD services.
673aa0a1e58SJeff Roberson * @mad_agent: Corresponding MAD registration request to deregister.
674aa0a1e58SJeff Roberson *
675aa0a1e58SJeff Roberson * After invoking this routine, MAD services are no longer usable by the
676aa0a1e58SJeff Roberson * client on the associated QP.
677aa0a1e58SJeff Roberson */
678aa0a1e58SJeff Roberson int ib_unregister_mad_agent(struct ib_mad_agent *mad_agent);
679aa0a1e58SJeff Roberson
680aa0a1e58SJeff Roberson /**
681aa0a1e58SJeff Roberson * ib_post_send_mad - Posts MAD(s) to the send queue of the QP associated
682aa0a1e58SJeff Roberson * with the registered client.
683aa0a1e58SJeff Roberson * @send_buf: Specifies the information needed to send the MAD(s).
684aa0a1e58SJeff Roberson * @bad_send_buf: Specifies the MAD on which an error was encountered. This
685aa0a1e58SJeff Roberson * parameter is optional if only a single MAD is posted.
686aa0a1e58SJeff Roberson *
687aa0a1e58SJeff Roberson * Sent MADs are not guaranteed to complete in the order that they were posted.
688aa0a1e58SJeff Roberson *
689aa0a1e58SJeff Roberson * If the MAD requires RMPP, the data buffer should contain a single copy
690aa0a1e58SJeff Roberson * of the common MAD, RMPP, and class specific headers, followed by the class
691aa0a1e58SJeff Roberson * defined data. If the class defined data would not divide evenly into
692aa0a1e58SJeff Roberson * RMPP segments, then space must be allocated at the end of the referenced
693aa0a1e58SJeff Roberson * buffer for any required padding. To indicate the amount of class defined
694aa0a1e58SJeff Roberson * data being transferred, the paylen_newwin field in the RMPP header should
695aa0a1e58SJeff Roberson * be set to the size of the class specific header plus the amount of class
696aa0a1e58SJeff Roberson * defined data being transferred. The paylen_newwin field should be
697aa0a1e58SJeff Roberson * specified in network-byte order.
698aa0a1e58SJeff Roberson */
699aa0a1e58SJeff Roberson int ib_post_send_mad(struct ib_mad_send_buf *send_buf,
700aa0a1e58SJeff Roberson struct ib_mad_send_buf **bad_send_buf);
701aa0a1e58SJeff Roberson
702aa0a1e58SJeff Roberson
703aa0a1e58SJeff Roberson /**
704aa0a1e58SJeff Roberson * ib_free_recv_mad - Returns data buffers used to receive a MAD.
705aa0a1e58SJeff Roberson * @mad_recv_wc: Work completion information for a received MAD.
706aa0a1e58SJeff Roberson *
707aa0a1e58SJeff Roberson * Clients receiving MADs through their ib_mad_recv_handler must call this
708aa0a1e58SJeff Roberson * routine to return the work completion buffers to the access layer.
709aa0a1e58SJeff Roberson */
710aa0a1e58SJeff Roberson void ib_free_recv_mad(struct ib_mad_recv_wc *mad_recv_wc);
711aa0a1e58SJeff Roberson
712aa0a1e58SJeff Roberson /**
713aa0a1e58SJeff Roberson * ib_cancel_mad - Cancels an outstanding send MAD operation.
714aa0a1e58SJeff Roberson * @mad_agent: Specifies the registration associated with sent MAD.
715aa0a1e58SJeff Roberson * @send_buf: Indicates the MAD to cancel.
716aa0a1e58SJeff Roberson *
717aa0a1e58SJeff Roberson * MADs will be returned to the user through the corresponding
718aa0a1e58SJeff Roberson * ib_mad_send_handler.
719aa0a1e58SJeff Roberson */
720aa0a1e58SJeff Roberson void ib_cancel_mad(struct ib_mad_agent *mad_agent,
721aa0a1e58SJeff Roberson struct ib_mad_send_buf *send_buf);
722aa0a1e58SJeff Roberson
723aa0a1e58SJeff Roberson /**
724aa0a1e58SJeff Roberson * ib_modify_mad - Modifies an outstanding send MAD operation.
725aa0a1e58SJeff Roberson * @mad_agent: Specifies the registration associated with sent MAD.
726aa0a1e58SJeff Roberson * @send_buf: Indicates the MAD to modify.
727aa0a1e58SJeff Roberson * @timeout_ms: New timeout value for sent MAD.
728aa0a1e58SJeff Roberson *
729aa0a1e58SJeff Roberson * This call will reset the timeout value for a sent MAD to the specified
730aa0a1e58SJeff Roberson * value.
731aa0a1e58SJeff Roberson */
732aa0a1e58SJeff Roberson int ib_modify_mad(struct ib_mad_agent *mad_agent,
733aa0a1e58SJeff Roberson struct ib_mad_send_buf *send_buf, u32 timeout_ms);
734aa0a1e58SJeff Roberson
735aa0a1e58SJeff Roberson /**
736aa0a1e58SJeff Roberson * ib_redirect_mad_qp - Registers a QP for MAD services.
737aa0a1e58SJeff Roberson * @qp: Reference to a QP that requires MAD services.
738aa0a1e58SJeff Roberson * @rmpp_version: If set, indicates that the client will send
739aa0a1e58SJeff Roberson * and receive MADs that contain the RMPP header for the given version.
740aa0a1e58SJeff Roberson * If set to 0, indicates that RMPP is not used by this client.
741aa0a1e58SJeff Roberson * @send_handler: The completion callback routine invoked after a send
742aa0a1e58SJeff Roberson * request has completed.
743aa0a1e58SJeff Roberson * @recv_handler: The completion callback routine invoked for a received
744aa0a1e58SJeff Roberson * MAD.
745aa0a1e58SJeff Roberson * @context: User specified context associated with the registration.
746aa0a1e58SJeff Roberson *
747aa0a1e58SJeff Roberson * Use of this call allows clients to use MAD services, such as RMPP,
748aa0a1e58SJeff Roberson * on user-owned QPs. After calling this routine, users may send
749aa0a1e58SJeff Roberson * MADs on the specified QP by calling ib_mad_post_send.
750aa0a1e58SJeff Roberson */
751aa0a1e58SJeff Roberson struct ib_mad_agent *ib_redirect_mad_qp(struct ib_qp *qp,
752aa0a1e58SJeff Roberson u8 rmpp_version,
753aa0a1e58SJeff Roberson ib_mad_send_handler send_handler,
754aa0a1e58SJeff Roberson ib_mad_recv_handler recv_handler,
755aa0a1e58SJeff Roberson void *context);
756aa0a1e58SJeff Roberson
757aa0a1e58SJeff Roberson /**
758aa0a1e58SJeff Roberson * ib_process_mad_wc - Processes a work completion associated with a
759aa0a1e58SJeff Roberson * MAD sent or received on a redirected QP.
760aa0a1e58SJeff Roberson * @mad_agent: Specifies the registered MAD service using the redirected QP.
761aa0a1e58SJeff Roberson * @wc: References a work completion associated with a sent or received
762aa0a1e58SJeff Roberson * MAD segment.
763aa0a1e58SJeff Roberson *
764aa0a1e58SJeff Roberson * This routine is used to complete or continue processing on a MAD request.
765aa0a1e58SJeff Roberson * If the work completion is associated with a send operation, calling
766aa0a1e58SJeff Roberson * this routine is required to continue an RMPP transfer or to wait for a
767aa0a1e58SJeff Roberson * corresponding response, if it is a request. If the work completion is
768aa0a1e58SJeff Roberson * associated with a receive operation, calling this routine is required to
769aa0a1e58SJeff Roberson * process an inbound or outbound RMPP transfer, or to match a response MAD
770aa0a1e58SJeff Roberson * with its corresponding request.
771aa0a1e58SJeff Roberson */
772aa0a1e58SJeff Roberson int ib_process_mad_wc(struct ib_mad_agent *mad_agent,
773aa0a1e58SJeff Roberson struct ib_wc *wc);
774aa0a1e58SJeff Roberson
775aa0a1e58SJeff Roberson /**
776aa0a1e58SJeff Roberson * ib_create_send_mad - Allocate and initialize a data buffer and work request
777aa0a1e58SJeff Roberson * for sending a MAD.
778aa0a1e58SJeff Roberson * @mad_agent: Specifies the registered MAD service to associate with the MAD.
779aa0a1e58SJeff Roberson * @remote_qpn: Specifies the QPN of the receiving node.
780aa0a1e58SJeff Roberson * @pkey_index: Specifies which PKey the MAD will be sent using. This field
781aa0a1e58SJeff Roberson * is valid only if the remote_qpn is QP 1.
782aa0a1e58SJeff Roberson * @rmpp_active: Indicates if the send will enable RMPP.
783aa0a1e58SJeff Roberson * @hdr_len: Indicates the size of the data header of the MAD. This length
784aa0a1e58SJeff Roberson * should include the common MAD header, RMPP header, plus any class
785aa0a1e58SJeff Roberson * specific header.
786aa0a1e58SJeff Roberson * @data_len: Indicates the size of any user-transferred data. The call will
787aa0a1e58SJeff Roberson * automatically adjust the allocated buffer size to account for any
788aa0a1e58SJeff Roberson * additional padding that may be necessary.
789aa0a1e58SJeff Roberson * @gfp_mask: GFP mask used for the memory allocation.
790478d3005SHans Petter Selasky * @base_version: Base Version of this MAD
791aa0a1e58SJeff Roberson *
792aa0a1e58SJeff Roberson * This routine allocates a MAD for sending. The returned MAD send buffer
793aa0a1e58SJeff Roberson * will reference a data buffer usable for sending a MAD, along
794aa0a1e58SJeff Roberson * with an initialized work request structure. Users may modify the returned
795aa0a1e58SJeff Roberson * MAD data buffer before posting the send.
796aa0a1e58SJeff Roberson *
797aa0a1e58SJeff Roberson * The returned MAD header, class specific headers, and any padding will be
798aa0a1e58SJeff Roberson * cleared. Users are responsible for initializing the common MAD header,
799aa0a1e58SJeff Roberson * any class specific header, and MAD data area.
800aa0a1e58SJeff Roberson * If @rmpp_active is set, the RMPP header will be initialized for sending.
801aa0a1e58SJeff Roberson */
802aa0a1e58SJeff Roberson struct ib_mad_send_buf *ib_create_send_mad(struct ib_mad_agent *mad_agent,
803aa0a1e58SJeff Roberson u32 remote_qpn, u16 pkey_index,
804aa0a1e58SJeff Roberson int rmpp_active,
805aa0a1e58SJeff Roberson int hdr_len, int data_len,
806478d3005SHans Petter Selasky gfp_t gfp_mask,
807478d3005SHans Petter Selasky u8 base_version);
808aa0a1e58SJeff Roberson
809aa0a1e58SJeff Roberson /**
810aa0a1e58SJeff Roberson * ib_is_mad_class_rmpp - returns whether given management class
811aa0a1e58SJeff Roberson * supports RMPP.
812aa0a1e58SJeff Roberson * @mgmt_class: management class
813aa0a1e58SJeff Roberson *
814aa0a1e58SJeff Roberson * This routine returns whether the management class supports RMPP.
815aa0a1e58SJeff Roberson */
816aa0a1e58SJeff Roberson int ib_is_mad_class_rmpp(u8 mgmt_class);
817aa0a1e58SJeff Roberson
818aa0a1e58SJeff Roberson /**
819aa0a1e58SJeff Roberson * ib_get_mad_data_offset - returns the data offset for a given
820aa0a1e58SJeff Roberson * management class.
821aa0a1e58SJeff Roberson * @mgmt_class: management class
822aa0a1e58SJeff Roberson *
823aa0a1e58SJeff Roberson * This routine returns the data offset in the MAD for the management
824aa0a1e58SJeff Roberson * class requested.
825aa0a1e58SJeff Roberson */
826aa0a1e58SJeff Roberson int ib_get_mad_data_offset(u8 mgmt_class);
827aa0a1e58SJeff Roberson
828aa0a1e58SJeff Roberson /**
829aa0a1e58SJeff Roberson * ib_get_rmpp_segment - returns the data buffer for a given RMPP segment.
830aa0a1e58SJeff Roberson * @send_buf: Previously allocated send data buffer.
831aa0a1e58SJeff Roberson * @seg_num: number of segment to return
832aa0a1e58SJeff Roberson *
833aa0a1e58SJeff Roberson * This routine returns a pointer to the data buffer of an RMPP MAD.
834aa0a1e58SJeff Roberson * Users must provide synchronization to @send_buf around this call.
835aa0a1e58SJeff Roberson */
836aa0a1e58SJeff Roberson void *ib_get_rmpp_segment(struct ib_mad_send_buf *send_buf, int seg_num);
837aa0a1e58SJeff Roberson
838aa0a1e58SJeff Roberson /**
839aa0a1e58SJeff Roberson * ib_free_send_mad - Returns data buffers used to send a MAD.
840aa0a1e58SJeff Roberson * @send_buf: Previously allocated send data buffer.
841aa0a1e58SJeff Roberson */
842aa0a1e58SJeff Roberson void ib_free_send_mad(struct ib_mad_send_buf *send_buf);
843aa0a1e58SJeff Roberson
844478d3005SHans Petter Selasky /**
845478d3005SHans Petter Selasky * ib_mad_kernel_rmpp_agent - Returns if the agent is performing RMPP.
846478d3005SHans Petter Selasky * @agent: the agent in question
847478d3005SHans Petter Selasky * @return: true if agent is performing rmpp, false otherwise.
848478d3005SHans Petter Selasky */
849478d3005SHans Petter Selasky int ib_mad_kernel_rmpp_agent(const struct ib_mad_agent *agent);
850478d3005SHans Petter Selasky
851aa0a1e58SJeff Roberson #endif /* IB_MAD_H */
852