1219820Sjeff/*
2219820Sjeff * Copyright (c) 2004 Topspin Communications.  All rights reserved.
3219820Sjeff * Copyright (c) 2005 Voltaire, Inc.  All rights reserved.
4219820Sjeff * Copyright (c) 2006 Intel Corporation.  All rights reserved.
5219820Sjeff *
6219820Sjeff * This software is available to you under a choice of one of two
7219820Sjeff * licenses.  You may choose to be licensed under the terms of the GNU
8219820Sjeff * General Public License (GPL) Version 2, available from the file
9219820Sjeff * COPYING in the main directory of this source tree, or the
10219820Sjeff * OpenIB.org BSD license below:
11219820Sjeff *
12219820Sjeff *     Redistribution and use in source and binary forms, with or
13219820Sjeff *     without modification, are permitted provided that the following
14219820Sjeff *     conditions are met:
15219820Sjeff *
16219820Sjeff *      - Redistributions of source code must retain the above
17219820Sjeff *        copyright notice, this list of conditions and the following
18219820Sjeff *        disclaimer.
19219820Sjeff *
20219820Sjeff *      - Redistributions in binary form must reproduce the above
21219820Sjeff *        copyright notice, this list of conditions and the following
22219820Sjeff *        disclaimer in the documentation and/or other materials
23219820Sjeff *        provided with the distribution.
24219820Sjeff *
25219820Sjeff * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26219820Sjeff * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27219820Sjeff * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28219820Sjeff * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29219820Sjeff * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30219820Sjeff * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31219820Sjeff * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32219820Sjeff * SOFTWARE.
33219820Sjeff */
34219820Sjeff
35219820Sjeff#ifndef IB_SA_H
36219820Sjeff#define IB_SA_H
37219820Sjeff
38219820Sjeff#include <linux/completion.h>
39219820Sjeff#include <linux/compiler.h>
40219820Sjeff
41219820Sjeff#include <asm/atomic.h>
42219820Sjeff
43219820Sjeff#include <rdma/ib_verbs.h>
44219820Sjeff#include <rdma/ib_mad.h>
45219820Sjeff
46219820Sjeffenum {
47219820Sjeff	IB_SA_CLASS_VERSION		= 2,	/* IB spec version 1.1/1.2 */
48219820Sjeff
49219820Sjeff	IB_SA_METHOD_GET_TABLE		= 0x12,
50219820Sjeff	IB_SA_METHOD_GET_TABLE_RESP	= 0x92,
51219820Sjeff	IB_SA_METHOD_DELETE		= 0x15,
52219820Sjeff	IB_SA_METHOD_DELETE_RESP	= 0x95,
53219820Sjeff	IB_SA_METHOD_GET_MULTI		= 0x14,
54219820Sjeff	IB_SA_METHOD_GET_MULTI_RESP	= 0x94,
55219820Sjeff	IB_SA_METHOD_GET_TRACE_TBL	= 0x13
56219820Sjeff};
57219820Sjeff
58219820Sjeffenum {
59219820Sjeff	IB_SA_ATTR_CLASS_PORTINFO    = 0x01,
60219820Sjeff	IB_SA_ATTR_NOTICE	     = 0x02,
61219820Sjeff	IB_SA_ATTR_INFORM_INFO	     = 0x03,
62219820Sjeff	IB_SA_ATTR_NODE_REC	     = 0x11,
63219820Sjeff	IB_SA_ATTR_PORT_INFO_REC     = 0x12,
64219820Sjeff	IB_SA_ATTR_SL2VL_REC	     = 0x13,
65219820Sjeff	IB_SA_ATTR_SWITCH_REC	     = 0x14,
66219820Sjeff	IB_SA_ATTR_LINEAR_FDB_REC    = 0x15,
67219820Sjeff	IB_SA_ATTR_RANDOM_FDB_REC    = 0x16,
68219820Sjeff	IB_SA_ATTR_MCAST_FDB_REC     = 0x17,
69219820Sjeff	IB_SA_ATTR_SM_INFO_REC	     = 0x18,
70219820Sjeff	IB_SA_ATTR_LINK_REC	     = 0x20,
71219820Sjeff	IB_SA_ATTR_GUID_INFO_REC     = 0x30,
72219820Sjeff	IB_SA_ATTR_SERVICE_REC	     = 0x31,
73219820Sjeff	IB_SA_ATTR_PARTITION_REC     = 0x33,
74219820Sjeff	IB_SA_ATTR_PATH_REC	     = 0x35,
75219820Sjeff	IB_SA_ATTR_VL_ARB_REC	     = 0x36,
76219820Sjeff	IB_SA_ATTR_MC_MEMBER_REC     = 0x38,
77219820Sjeff	IB_SA_ATTR_TRACE_REC	     = 0x39,
78219820Sjeff	IB_SA_ATTR_MULTI_PATH_REC    = 0x3a,
79219820Sjeff	IB_SA_ATTR_SERVICE_ASSOC_REC = 0x3b,
80219820Sjeff	IB_SA_ATTR_INFORM_INFO_REC   = 0xf3
81219820Sjeff};
82219820Sjeff
83219820Sjeffenum ib_sa_selector {
84219820Sjeff	IB_SA_GT   = 0,
85219820Sjeff	IB_SA_LT   = 1,
86219820Sjeff	IB_SA_EQ   = 2,
87219820Sjeff	/*
88219820Sjeff	 * The meaning of "best" depends on the attribute: for
89219820Sjeff	 * example, for MTU best will return the largest available
90219820Sjeff	 * MTU, while for packet life time, best will return the
91219820Sjeff	 * smallest available life time.
92219820Sjeff	 */
93219820Sjeff	IB_SA_BEST = 3
94219820Sjeff};
95219820Sjeff
96219820Sjeff/*
97219820Sjeff * Structures for SA records are named "struct ib_sa_xxx_rec."  No
98219820Sjeff * attempt is made to pack structures to match the physical layout of
99219820Sjeff * SA records in SA MADs; all packing and unpacking is handled by the
100219820Sjeff * SA query code.
101219820Sjeff *
102219820Sjeff * For a record with structure ib_sa_xxx_rec, the naming convention
103219820Sjeff * for the component mask value for field yyy is IB_SA_XXX_REC_YYY (we
104219820Sjeff * never use different abbreviations or otherwise change the spelling
105219820Sjeff * of xxx/yyy between ib_sa_xxx_rec.yyy and IB_SA_XXX_REC_YYY).
106219820Sjeff *
107219820Sjeff * Reserved rows are indicated with comments to help maintainability.
108219820Sjeff */
109219820Sjeff
110219820Sjeff#define IB_SA_PATH_REC_SERVICE_ID		       (IB_SA_COMP_MASK( 0) |\
111219820Sjeff							IB_SA_COMP_MASK( 1))
112219820Sjeff#define IB_SA_PATH_REC_DGID				IB_SA_COMP_MASK( 2)
113219820Sjeff#define IB_SA_PATH_REC_SGID				IB_SA_COMP_MASK( 3)
114219820Sjeff#define IB_SA_PATH_REC_DLID				IB_SA_COMP_MASK( 4)
115219820Sjeff#define IB_SA_PATH_REC_SLID				IB_SA_COMP_MASK( 5)
116219820Sjeff#define IB_SA_PATH_REC_RAW_TRAFFIC			IB_SA_COMP_MASK( 6)
117219820Sjeff/* reserved:								 7 */
118219820Sjeff#define IB_SA_PATH_REC_FLOW_LABEL       		IB_SA_COMP_MASK( 8)
119219820Sjeff#define IB_SA_PATH_REC_HOP_LIMIT			IB_SA_COMP_MASK( 9)
120219820Sjeff#define IB_SA_PATH_REC_TRAFFIC_CLASS			IB_SA_COMP_MASK(10)
121219820Sjeff#define IB_SA_PATH_REC_REVERSIBLE			IB_SA_COMP_MASK(11)
122219820Sjeff#define IB_SA_PATH_REC_NUMB_PATH			IB_SA_COMP_MASK(12)
123219820Sjeff#define IB_SA_PATH_REC_PKEY				IB_SA_COMP_MASK(13)
124219820Sjeff#define IB_SA_PATH_REC_QOS_CLASS			IB_SA_COMP_MASK(14)
125219820Sjeff#define IB_SA_PATH_REC_SL				IB_SA_COMP_MASK(15)
126219820Sjeff#define IB_SA_PATH_REC_MTU_SELECTOR			IB_SA_COMP_MASK(16)
127219820Sjeff#define IB_SA_PATH_REC_MTU				IB_SA_COMP_MASK(17)
128219820Sjeff#define IB_SA_PATH_REC_RATE_SELECTOR			IB_SA_COMP_MASK(18)
129219820Sjeff#define IB_SA_PATH_REC_RATE				IB_SA_COMP_MASK(19)
130219820Sjeff#define IB_SA_PATH_REC_PACKET_LIFE_TIME_SELECTOR	IB_SA_COMP_MASK(20)
131219820Sjeff#define IB_SA_PATH_REC_PACKET_LIFE_TIME			IB_SA_COMP_MASK(21)
132219820Sjeff#define IB_SA_PATH_REC_PREFERENCE			IB_SA_COMP_MASK(22)
133219820Sjeff
134219820Sjeffstruct ib_sa_path_rec {
135219820Sjeff	__be64       service_id;
136219820Sjeff	union ib_gid dgid;
137219820Sjeff	union ib_gid sgid;
138219820Sjeff	__be16       dlid;
139219820Sjeff	__be16       slid;
140219820Sjeff	int          raw_traffic;
141219820Sjeff	/* reserved */
142219820Sjeff	__be32       flow_label;
143219820Sjeff	u8           hop_limit;
144219820Sjeff	u8           traffic_class;
145219820Sjeff	int          reversible;
146219820Sjeff	u8           numb_path;
147219820Sjeff	__be16       pkey;
148219820Sjeff	__be16       qos_class;
149219820Sjeff	u8           sl;
150219820Sjeff	u8           mtu_selector;
151219820Sjeff	u8           mtu;
152219820Sjeff	u8           rate_selector;
153219820Sjeff	u8           rate;
154219820Sjeff	u8           packet_life_time_selector;
155219820Sjeff	u8           packet_life_time;
156219820Sjeff	u8           preference;
157219820Sjeff};
158219820Sjeff
159219820Sjeff#define IB_SA_MCMEMBER_REC_MGID				IB_SA_COMP_MASK( 0)
160219820Sjeff#define IB_SA_MCMEMBER_REC_PORT_GID			IB_SA_COMP_MASK( 1)
161219820Sjeff#define IB_SA_MCMEMBER_REC_QKEY				IB_SA_COMP_MASK( 2)
162219820Sjeff#define IB_SA_MCMEMBER_REC_MLID				IB_SA_COMP_MASK( 3)
163219820Sjeff#define IB_SA_MCMEMBER_REC_MTU_SELECTOR			IB_SA_COMP_MASK( 4)
164219820Sjeff#define IB_SA_MCMEMBER_REC_MTU				IB_SA_COMP_MASK( 5)
165219820Sjeff#define IB_SA_MCMEMBER_REC_TRAFFIC_CLASS		IB_SA_COMP_MASK( 6)
166219820Sjeff#define IB_SA_MCMEMBER_REC_PKEY				IB_SA_COMP_MASK( 7)
167219820Sjeff#define IB_SA_MCMEMBER_REC_RATE_SELECTOR		IB_SA_COMP_MASK( 8)
168219820Sjeff#define IB_SA_MCMEMBER_REC_RATE				IB_SA_COMP_MASK( 9)
169219820Sjeff#define IB_SA_MCMEMBER_REC_PACKET_LIFE_TIME_SELECTOR	IB_SA_COMP_MASK(10)
170219820Sjeff#define IB_SA_MCMEMBER_REC_PACKET_LIFE_TIME		IB_SA_COMP_MASK(11)
171219820Sjeff#define IB_SA_MCMEMBER_REC_SL				IB_SA_COMP_MASK(12)
172219820Sjeff#define IB_SA_MCMEMBER_REC_FLOW_LABEL			IB_SA_COMP_MASK(13)
173219820Sjeff#define IB_SA_MCMEMBER_REC_HOP_LIMIT			IB_SA_COMP_MASK(14)
174219820Sjeff#define IB_SA_MCMEMBER_REC_SCOPE			IB_SA_COMP_MASK(15)
175219820Sjeff#define IB_SA_MCMEMBER_REC_JOIN_STATE			IB_SA_COMP_MASK(16)
176219820Sjeff#define IB_SA_MCMEMBER_REC_PROXY_JOIN			IB_SA_COMP_MASK(17)
177219820Sjeff
178219820Sjeffstruct ib_sa_mcmember_rec {
179219820Sjeff	union ib_gid mgid;
180219820Sjeff	union ib_gid port_gid;
181219820Sjeff	__be32       qkey;
182219820Sjeff	__be16       mlid;
183219820Sjeff	u8           mtu_selector;
184219820Sjeff	u8           mtu;
185219820Sjeff	u8           traffic_class;
186219820Sjeff	__be16       pkey;
187219820Sjeff	u8 	     rate_selector;
188219820Sjeff	u8 	     rate;
189219820Sjeff	u8 	     packet_life_time_selector;
190219820Sjeff	u8 	     packet_life_time;
191219820Sjeff	u8           sl;
192219820Sjeff	__be32       flow_label;
193219820Sjeff	u8           hop_limit;
194219820Sjeff	u8           scope;
195219820Sjeff	u8           join_state;
196219820Sjeff	int          proxy_join;
197219820Sjeff};
198219820Sjeff
199219820Sjeff/* Service Record Component Mask Sec 15.2.5.14 Ver 1.1	*/
200219820Sjeff#define IB_SA_SERVICE_REC_SERVICE_ID			IB_SA_COMP_MASK( 0)
201219820Sjeff#define IB_SA_SERVICE_REC_SERVICE_GID			IB_SA_COMP_MASK( 1)
202219820Sjeff#define IB_SA_SERVICE_REC_SERVICE_PKEY			IB_SA_COMP_MASK( 2)
203219820Sjeff/* reserved:								 3 */
204219820Sjeff#define IB_SA_SERVICE_REC_SERVICE_LEASE			IB_SA_COMP_MASK( 4)
205219820Sjeff#define IB_SA_SERVICE_REC_SERVICE_KEY			IB_SA_COMP_MASK( 5)
206219820Sjeff#define IB_SA_SERVICE_REC_SERVICE_NAME			IB_SA_COMP_MASK( 6)
207219820Sjeff#define IB_SA_SERVICE_REC_SERVICE_DATA8_0		IB_SA_COMP_MASK( 7)
208219820Sjeff#define IB_SA_SERVICE_REC_SERVICE_DATA8_1		IB_SA_COMP_MASK( 8)
209219820Sjeff#define IB_SA_SERVICE_REC_SERVICE_DATA8_2		IB_SA_COMP_MASK( 9)
210219820Sjeff#define IB_SA_SERVICE_REC_SERVICE_DATA8_3		IB_SA_COMP_MASK(10)
211219820Sjeff#define IB_SA_SERVICE_REC_SERVICE_DATA8_4		IB_SA_COMP_MASK(11)
212219820Sjeff#define IB_SA_SERVICE_REC_SERVICE_DATA8_5		IB_SA_COMP_MASK(12)
213219820Sjeff#define IB_SA_SERVICE_REC_SERVICE_DATA8_6		IB_SA_COMP_MASK(13)
214219820Sjeff#define IB_SA_SERVICE_REC_SERVICE_DATA8_7		IB_SA_COMP_MASK(14)
215219820Sjeff#define IB_SA_SERVICE_REC_SERVICE_DATA8_8		IB_SA_COMP_MASK(15)
216219820Sjeff#define IB_SA_SERVICE_REC_SERVICE_DATA8_9		IB_SA_COMP_MASK(16)
217219820Sjeff#define IB_SA_SERVICE_REC_SERVICE_DATA8_10		IB_SA_COMP_MASK(17)
218219820Sjeff#define IB_SA_SERVICE_REC_SERVICE_DATA8_11		IB_SA_COMP_MASK(18)
219219820Sjeff#define IB_SA_SERVICE_REC_SERVICE_DATA8_12		IB_SA_COMP_MASK(19)
220219820Sjeff#define IB_SA_SERVICE_REC_SERVICE_DATA8_13		IB_SA_COMP_MASK(20)
221219820Sjeff#define IB_SA_SERVICE_REC_SERVICE_DATA8_14		IB_SA_COMP_MASK(21)
222219820Sjeff#define IB_SA_SERVICE_REC_SERVICE_DATA8_15		IB_SA_COMP_MASK(22)
223219820Sjeff#define IB_SA_SERVICE_REC_SERVICE_DATA16_0		IB_SA_COMP_MASK(23)
224219820Sjeff#define IB_SA_SERVICE_REC_SERVICE_DATA16_1		IB_SA_COMP_MASK(24)
225219820Sjeff#define IB_SA_SERVICE_REC_SERVICE_DATA16_2		IB_SA_COMP_MASK(25)
226219820Sjeff#define IB_SA_SERVICE_REC_SERVICE_DATA16_3		IB_SA_COMP_MASK(26)
227219820Sjeff#define IB_SA_SERVICE_REC_SERVICE_DATA16_4		IB_SA_COMP_MASK(27)
228219820Sjeff#define IB_SA_SERVICE_REC_SERVICE_DATA16_5		IB_SA_COMP_MASK(28)
229219820Sjeff#define IB_SA_SERVICE_REC_SERVICE_DATA16_6		IB_SA_COMP_MASK(29)
230219820Sjeff#define IB_SA_SERVICE_REC_SERVICE_DATA16_7		IB_SA_COMP_MASK(30)
231219820Sjeff#define IB_SA_SERVICE_REC_SERVICE_DATA32_0		IB_SA_COMP_MASK(31)
232219820Sjeff#define IB_SA_SERVICE_REC_SERVICE_DATA32_1		IB_SA_COMP_MASK(32)
233219820Sjeff#define IB_SA_SERVICE_REC_SERVICE_DATA32_2		IB_SA_COMP_MASK(33)
234219820Sjeff#define IB_SA_SERVICE_REC_SERVICE_DATA32_3		IB_SA_COMP_MASK(34)
235219820Sjeff#define IB_SA_SERVICE_REC_SERVICE_DATA64_0		IB_SA_COMP_MASK(35)
236219820Sjeff#define IB_SA_SERVICE_REC_SERVICE_DATA64_1		IB_SA_COMP_MASK(36)
237219820Sjeff
238219820Sjeff#define IB_DEFAULT_SERVICE_LEASE 	0xFFFFFFFF
239219820Sjeff
240219820Sjeffstruct ib_sa_service_rec {
241219820Sjeff	u64		id;
242219820Sjeff	union ib_gid	gid;
243219820Sjeff	__be16 		pkey;
244219820Sjeff	/* reserved */
245219820Sjeff	u32		lease;
246219820Sjeff	u8		key[16];
247219820Sjeff	u8		name[64];
248219820Sjeff	u8		data8[16];
249219820Sjeff	u16		data16[8];
250219820Sjeff	u32		data32[4];
251219820Sjeff	u64		data64[2];
252219820Sjeff};
253219820Sjeff
254219820Sjeffenum {
255219820Sjeff	IB_SA_EVENT_TYPE_FATAL		= 0x0,
256219820Sjeff	IB_SA_EVENT_TYPE_URGENT		= 0x1,
257219820Sjeff	IB_SA_EVENT_TYPE_SECURITY	= 0x2,
258219820Sjeff	IB_SA_EVENT_TYPE_SM		= 0x3,
259219820Sjeff	IB_SA_EVENT_TYPE_INFO		= 0x4,
260219820Sjeff	IB_SA_EVENT_TYPE_EMPTY		= 0x7F,
261219820Sjeff	IB_SA_EVENT_TYPE_ALL		= 0xFFFF
262219820Sjeff};
263219820Sjeff
264219820Sjeffenum {
265219820Sjeff	IB_SA_EVENT_PRODUCER_TYPE_CA		= 0x1,
266219820Sjeff	IB_SA_EVENT_PRODUCER_TYPE_SWITCH	= 0x2,
267219820Sjeff	IB_SA_EVENT_PRODUCER_TYPE_ROUTER	= 0x3,
268219820Sjeff	IB_SA_EVENT_PRODUCER_TYPE_CLASS_MANAGER	= 0x4,
269219820Sjeff	IB_SA_EVENT_PRODUCER_TYPE_ALL		= 0xFFFFFF
270219820Sjeff};
271219820Sjeff
272219820Sjeffenum {
273219820Sjeff	IB_SA_SM_TRAP_GID_IN_SERVICE			= 64,
274219820Sjeff	IB_SA_SM_TRAP_GID_OUT_OF_SERVICE		= 65,
275219820Sjeff	IB_SA_SM_TRAP_CREATE_MC_GROUP			= 66,
276219820Sjeff	IB_SA_SM_TRAP_DELETE_MC_GROUP			= 67,
277219820Sjeff	IB_SA_SM_TRAP_PORT_CHANGE_STATE			= 128,
278219820Sjeff	IB_SA_SM_TRAP_LINK_INTEGRITY			= 129,
279219820Sjeff	IB_SA_SM_TRAP_EXCESSIVE_BUFFER_OVERRUN		= 130,
280219820Sjeff	IB_SA_SM_TRAP_FLOW_CONTROL_UPDATE_EXPIRED	= 131,
281219820Sjeff	IB_SA_SM_TRAP_BAD_M_KEY				= 256,
282219820Sjeff	IB_SA_SM_TRAP_BAD_P_KEY				= 257,
283219820Sjeff	IB_SA_SM_TRAP_BAD_Q_KEY				= 258,
284219820Sjeff	IB_SA_SM_TRAP_SWITCH_BAD_P_KEY			= 259,
285219820Sjeff	IB_SA_SM_TRAP_ALL				= 0xFFFF
286219820Sjeff};
287219820Sjeff
288219820Sjeffstruct ib_sa_inform {
289219820Sjeff	union ib_gid	gid;
290219820Sjeff	__be16		lid_range_begin;
291219820Sjeff	__be16		lid_range_end;
292219820Sjeff	u8		is_generic;
293219820Sjeff	u8		subscribe;
294219820Sjeff	__be16		type;
295219820Sjeff	union {
296219820Sjeff		struct {
297219820Sjeff			__be16	trap_num;
298219820Sjeff			__be32	qpn;
299219820Sjeff			u8	resp_time;
300219820Sjeff			__be32	producer_type;
301219820Sjeff		} generic;
302219820Sjeff		struct {
303219820Sjeff			__be16	device_id;
304219820Sjeff			__be32	qpn;
305219820Sjeff			u8	resp_time;
306219820Sjeff			__be32	vendor_id;
307219820Sjeff		} vendor;
308219820Sjeff	} trap;
309219820Sjeff};
310219820Sjeff
311219820Sjeffstruct ib_sa_notice {
312219820Sjeff	u8		is_generic;
313219820Sjeff	u8		type;
314219820Sjeff	union {
315219820Sjeff		struct {
316219820Sjeff			__be32	producer_type;
317219820Sjeff			__be16	trap_num;
318219820Sjeff		} generic;
319219820Sjeff		struct {
320219820Sjeff			__be32	vendor_id;
321219820Sjeff			__be16	device_id;
322219820Sjeff		} vendor;
323219820Sjeff	} trap;
324219820Sjeff	__be16		issuer_lid;
325219820Sjeff	__be16		notice_count;
326219820Sjeff	u8		notice_toggle;
327219820Sjeff	/*
328219820Sjeff	 * Align data 16 bits off 64 bit field to match InformInfo definition.
329219820Sjeff	 * Data contained within this field will then align properly.
330219820Sjeff	 * See IB spec 1.2, sections 13.4.8.2 and 14.2.5.1.
331219820Sjeff	 */
332219820Sjeff	u8		reserved[5];
333219820Sjeff	u8		data_details[54];
334219820Sjeff	union ib_gid	issuer_gid;
335219820Sjeff};
336219820Sjeff
337219820Sjeff/*
338219820Sjeff * SM notice data details for:
339219820Sjeff *
340219820Sjeff * IB_SA_SM_TRAP_GID_IN_SERVICE		= 64
341219820Sjeff * IB_SA_SM_TRAP_GID_OUT_OF_SERVICE	= 65
342219820Sjeff * IB_SA_SM_TRAP_CREATE_MC_GROUP	= 66
343219820Sjeff * IB_SA_SM_TRAP_DELETE_MC_GROUP	= 67
344219820Sjeff */
345219820Sjeffstruct ib_sa_notice_data_gid {
346219820Sjeff	u8	reserved[6];
347219820Sjeff	u8	gid[16];
348219820Sjeff	u8	padding[32];
349219820Sjeff};
350219820Sjeff
351219820Sjeff/*
352219820Sjeff * SM notice data details for:
353219820Sjeff *
354219820Sjeff * IB_SA_SM_TRAP_PORT_CHANGE_STATE	= 128
355219820Sjeff */
356219820Sjeffstruct ib_sa_notice_data_port_change {
357219820Sjeff	__be16	lid;
358219820Sjeff	u8	padding[52];
359219820Sjeff};
360219820Sjeff
361219820Sjeff/*
362219820Sjeff * SM notice data details for:
363219820Sjeff *
364219820Sjeff * IB_SA_SM_TRAP_LINK_INTEGRITY			= 129
365219820Sjeff * IB_SA_SM_TRAP_EXCESSIVE_BUFFER_OVERRUN	= 130
366219820Sjeff * IB_SA_SM_TRAP_FLOW_CONTROL_UPDATE_EXPIRED	= 131
367219820Sjeff */
368219820Sjeffstruct ib_sa_notice_data_port_error {
369219820Sjeff	u8	reserved[2];
370219820Sjeff	__be16	lid;
371219820Sjeff	u8	port_num;
372219820Sjeff	u8	padding[49];
373219820Sjeff};
374219820Sjeff
375255932Salfred#define IB_SA_GUIDINFO_REC_LID		IB_SA_COMP_MASK(0)
376255932Salfred#define IB_SA_GUIDINFO_REC_BLOCK_NUM	IB_SA_COMP_MASK(1)
377255932Salfred#define IB_SA_GUIDINFO_REC_RES1		IB_SA_COMP_MASK(2)
378255932Salfred#define IB_SA_GUIDINFO_REC_RES2		IB_SA_COMP_MASK(3)
379255932Salfred#define IB_SA_GUIDINFO_REC_GID0		IB_SA_COMP_MASK(4)
380255932Salfred#define IB_SA_GUIDINFO_REC_GID1		IB_SA_COMP_MASK(5)
381255932Salfred#define IB_SA_GUIDINFO_REC_GID2		IB_SA_COMP_MASK(6)
382255932Salfred#define IB_SA_GUIDINFO_REC_GID3		IB_SA_COMP_MASK(7)
383255932Salfred#define IB_SA_GUIDINFO_REC_GID4		IB_SA_COMP_MASK(8)
384255932Salfred#define IB_SA_GUIDINFO_REC_GID5		IB_SA_COMP_MASK(9)
385255932Salfred#define IB_SA_GUIDINFO_REC_GID6		IB_SA_COMP_MASK(10)
386255932Salfred#define IB_SA_GUIDINFO_REC_GID7		IB_SA_COMP_MASK(11)
387255932Salfred
388255932Salfredstruct ib_sa_guidinfo_rec {
389255932Salfred	__be16	lid;
390255932Salfred	u8	block_num;
391255932Salfred	/* reserved */
392255932Salfred	u8	res1;
393255932Salfred	__be32	res2;
394255932Salfred	u8	guid_info_list[64];
395255932Salfred};
396255932Salfred
397219820Sjeffstruct ib_sa_client {
398219820Sjeff	atomic_t users;
399219820Sjeff	struct completion comp;
400219820Sjeff};
401219820Sjeff
402219820Sjeff/**
403219820Sjeff * ib_sa_register_client - Register an SA client.
404219820Sjeff */
405219820Sjeffvoid ib_sa_register_client(struct ib_sa_client *client);
406219820Sjeff
407219820Sjeff/**
408219820Sjeff * ib_sa_unregister_client - Deregister an SA client.
409219820Sjeff * @client: Client object to deregister.
410219820Sjeff */
411219820Sjeffvoid ib_sa_unregister_client(struct ib_sa_client *client);
412219820Sjeff
413219820Sjeffstruct ib_sa_query;
414219820Sjeff
415219820Sjeffvoid ib_sa_cancel_query(int id, struct ib_sa_query *query);
416219820Sjeff
417219820Sjeffint ib_sa_path_rec_get(struct ib_sa_client *client,
418219820Sjeff		       struct ib_device *device, u8 port_num,
419219820Sjeff		       struct ib_sa_path_rec *rec,
420219820Sjeff		       ib_sa_comp_mask comp_mask,
421219820Sjeff		       int timeout_ms, gfp_t gfp_mask,
422219820Sjeff		       void (*callback)(int status,
423219820Sjeff					struct ib_sa_path_rec *resp,
424219820Sjeff					void *context),
425219820Sjeff		       void *context,
426219820Sjeff		       struct ib_sa_query **query);
427219820Sjeff
428219820Sjeffint ib_sa_service_rec_query(struct ib_sa_client *client,
429219820Sjeff			 struct ib_device *device, u8 port_num,
430219820Sjeff			 u8 method,
431219820Sjeff			 struct ib_sa_service_rec *rec,
432219820Sjeff			 ib_sa_comp_mask comp_mask,
433219820Sjeff			 int timeout_ms, gfp_t gfp_mask,
434219820Sjeff			 void (*callback)(int status,
435219820Sjeff					  struct ib_sa_service_rec *resp,
436219820Sjeff					  void *context),
437219820Sjeff			 void *context,
438219820Sjeff			 struct ib_sa_query **sa_query);
439219820Sjeff
440219820Sjeffstruct ib_sa_multicast {
441219820Sjeff	struct ib_sa_mcmember_rec rec;
442219820Sjeff	ib_sa_comp_mask		comp_mask;
443219820Sjeff	int			(*callback)(int status,
444219820Sjeff					    struct ib_sa_multicast *multicast);
445219820Sjeff	void			*context;
446219820Sjeff};
447219820Sjeff
448219820Sjeff/**
449219820Sjeff * ib_sa_join_multicast - Initiates a join request to the specified multicast
450219820Sjeff *   group.
451219820Sjeff * @client: SA client
452219820Sjeff * @device: Device associated with the multicast group.
453219820Sjeff * @port_num: Port on the specified device to associate with the multicast
454219820Sjeff *   group.
455219820Sjeff * @rec: SA multicast member record specifying group attributes.
456219820Sjeff * @comp_mask: Component mask indicating which group attributes of %rec are
457219820Sjeff *   valid.
458219820Sjeff * @gfp_mask: GFP mask for memory allocations.
459219820Sjeff * @callback: User callback invoked once the join operation completes.
460219820Sjeff * @context: User specified context stored with the ib_sa_multicast structure.
461219820Sjeff *
462219820Sjeff * This call initiates a multicast join request with the SA for the specified
463219820Sjeff * multicast group.  If the join operation is started successfully, it returns
464219820Sjeff * an ib_sa_multicast structure that is used to track the multicast operation.
465219820Sjeff * Users must free this structure by calling ib_free_multicast, even if the
466219820Sjeff * join operation later fails.  (The callback status is non-zero.)
467219820Sjeff *
468219820Sjeff * If the join operation fails; status will be non-zero, with the following
469219820Sjeff * failures possible:
470219820Sjeff * -ETIMEDOUT: The request timed out.
471219820Sjeff * -EIO: An error occurred sending the query.
472219820Sjeff * -EINVAL: The MCMemberRecord values differed from the existing group's.
473219820Sjeff * -ENETRESET: Indicates that an fatal error has occurred on the multicast
474219820Sjeff *   group, and the user must rejoin the group to continue using it.
475219820Sjeff */
476219820Sjeffstruct ib_sa_multicast *ib_sa_join_multicast(struct ib_sa_client *client,
477219820Sjeff					     struct ib_device *device, u8 port_num,
478219820Sjeff					     struct ib_sa_mcmember_rec *rec,
479219820Sjeff					     ib_sa_comp_mask comp_mask, gfp_t gfp_mask,
480219820Sjeff					     int (*callback)(int status,
481219820Sjeff							     struct ib_sa_multicast
482219820Sjeff								    *multicast),
483219820Sjeff					     void *context);
484219820Sjeff
485219820Sjeff/**
486219820Sjeff * ib_free_multicast - Frees the multicast tracking structure, and releases
487219820Sjeff *    any reference on the multicast group.
488219820Sjeff * @multicast: Multicast tracking structure allocated by ib_join_multicast.
489219820Sjeff *
490219820Sjeff * This call blocks until the multicast identifier is destroyed.  It may
491219820Sjeff * not be called from within the multicast callback; however, returning a non-
492219820Sjeff * zero value from the callback will result in destroying the multicast
493219820Sjeff * tracking structure.
494219820Sjeff */
495219820Sjeffvoid ib_sa_free_multicast(struct ib_sa_multicast *multicast);
496219820Sjeff
497219820Sjeff/**
498219820Sjeff * ib_get_mcmember_rec - Looks up a multicast member record by its MGID and
499219820Sjeff *   returns it if found.
500219820Sjeff * @device: Device associated with the multicast group.
501219820Sjeff * @port_num: Port on the specified device to associate with the multicast
502219820Sjeff *   group.
503219820Sjeff * @mgid: MGID of multicast group.
504219820Sjeff * @rec: Location to copy SA multicast member record.
505219820Sjeff */
506219820Sjeffint ib_sa_get_mcmember_rec(struct ib_device *device, u8 port_num,
507219820Sjeff			   union ib_gid *mgid, struct ib_sa_mcmember_rec *rec);
508219820Sjeff
509219820Sjeff/**
510219820Sjeff * ib_init_ah_from_mcmember - Initialize address handle attributes based on
511219820Sjeff * an SA multicast member record.
512219820Sjeff */
513219820Sjeffint ib_init_ah_from_mcmember(struct ib_device *device, u8 port_num,
514219820Sjeff			     struct ib_sa_mcmember_rec *rec,
515219820Sjeff			     struct ib_ah_attr *ah_attr);
516219820Sjeff
517219820Sjeff/**
518219820Sjeff * ib_init_ah_from_path - Initialize address handle attributes based on an SA
519219820Sjeff *   path record.
520219820Sjeff */
521219820Sjeffint ib_init_ah_from_path(struct ib_device *device, u8 port_num,
522219820Sjeff			 struct ib_sa_path_rec *rec,
523219820Sjeff			 struct ib_ah_attr *ah_attr);
524219820Sjeff
525219820Sjeff/**
526219820Sjeff * ib_sa_unpack_path - Convert a path record from MAD format to struct
527219820Sjeff * ib_sa_path_rec.
528219820Sjeff */
529219820Sjeffvoid ib_sa_unpack_path(void *attribute, struct ib_sa_path_rec *rec);
530219820Sjeff
531219820Sjeffstruct ib_inform_info {
532219820Sjeff	void		*context;
533219820Sjeff	int		(*callback)(int status,
534219820Sjeff				    struct ib_inform_info *info,
535219820Sjeff				    struct ib_sa_notice *notice);
536219820Sjeff	u16		trap_number;
537219820Sjeff};
538219820Sjeff
539219820Sjeff/**
540219820Sjeff * ib_sa_register_inform_info - Registers to receive notice events.
541219820Sjeff * @device: Device associated with the registration.
542219820Sjeff * @port_num: Port on the specified device to associate with the registration.
543219820Sjeff * @trap_number: InformInfo trap number to register for.
544219820Sjeff * @gfp_mask: GFP mask for memory allocations.
545219820Sjeff * @callback: User callback invoked once the registration completes and to
546219820Sjeff *   report noticed events.
547219820Sjeff * @context: User specified context stored with the ib_inform_reg structure.
548219820Sjeff *
549219820Sjeff * This call initiates a registration request with the SA for the specified
550219820Sjeff * trap number.  If the operation is started successfully, it returns
551219820Sjeff * an ib_inform_info structure that is used to track the registration operation.
552219820Sjeff * Users must free this structure by calling ib_unregister_inform_info,
553219820Sjeff * even if the operation later fails.  (The callback status is non-zero.)
554219820Sjeff *
555219820Sjeff * If the registration fails; status will be non-zero.  If the registration
556219820Sjeff * succeeds, the callback status will be zero, but the notice parameter will
557219820Sjeff * be NULL.  If the notice parameter is not NULL, a trap or notice is being
558219820Sjeff * reported to the user.
559219820Sjeff *
560219820Sjeff * A status of -ENETRESET indicates that an error occurred which requires
561219820Sjeff * reregisteration.
562219820Sjeff */
563219820Sjeffstruct ib_inform_info *
564219820Sjeffib_sa_register_inform_info(struct ib_sa_client *client,
565219820Sjeff			   struct ib_device *device, u8 port_num,
566219820Sjeff			   u16 trap_number, gfp_t gfp_mask,
567219820Sjeff			   int (*callback)(int status,
568219820Sjeff					   struct ib_inform_info *info,
569219820Sjeff					   struct ib_sa_notice *notice),
570219820Sjeff			   void *context);
571219820Sjeff
572219820Sjeff/**
573219820Sjeff * ib_sa_unregister_inform_info - Releases an InformInfo registration.
574219820Sjeff * @info: InformInfo registration tracking structure.
575219820Sjeff *
576219820Sjeff * This call blocks until the registration request is destroyed.  It may
577219820Sjeff * not be called from within the registration callback.
578219820Sjeff */
579219820Sjeffvoid ib_sa_unregister_inform_info(struct ib_inform_info *info);
580219820Sjeff
581255932Salfredint ib_sa_guid_info_rec_query(struct ib_sa_client *client,
582255932Salfred                              struct ib_device *device, u8 port_num,
583255932Salfred                              struct ib_sa_guidinfo_rec *rec,
584255932Salfred                              ib_sa_comp_mask comp_mask, u8 method,
585255932Salfred                              int timeout_ms, gfp_t gfp_mask,
586255932Salfred                              void (*callback)(int status,
587255932Salfred                                               struct ib_sa_guidinfo_rec *resp,
588255932Salfred                                               void *context),
589255932Salfred                              void *context,
590255932Salfred                              struct ib_sa_query **sa_query);
591255932Salfred
592255932Salfred
593219820Sjeff#endif /* IB_SA_H */
594