1/*
2 * Copyright (c) 2004 Mellanox Technologies Ltd.  All rights reserved.
3 * Copyright (c) 2004 Infinicon Corporation.  All rights reserved.
4 * Copyright (c) 2004, 2010 Intel Corporation.  All rights reserved.
5 * Copyright (c) 2004 Topspin Corporation.  All rights reserved.
6 * Copyright (c) 2004-2006 Voltaire Corporation.  All rights reserved.
7 *
8 * This software is available to you under a choice of one of two
9 * licenses.  You may choose to be licensed under the terms of the GNU
10 * General Public License (GPL) Version 2, available from the file
11 * COPYING in the main directory of this source tree, or the
12 * OpenIB.org BSD license below:
13 *
14 *     Redistribution and use in source and binary forms, with or
15 *     without modification, are permitted provided that the following
16 *     conditions are met:
17 *
18 *      - Redistributions of source code must retain the above
19 *        copyright notice, this list of conditions and the following
20 *        disclaimer.
21 *
22 *      - Redistributions in binary form must reproduce the above
23 *        copyright notice, this list of conditions and the following
24 *        disclaimer in the documentation and/or other materials
25 *        provided with the distribution.
26 *
27 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
28 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
29 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
30 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
31 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
32 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
33 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
34 * SOFTWARE.
35 *
36 */
37#ifndef _UMAD_TYPES_H
38#define _UMAD_TYPES_H
39
40#include <stdint.h>
41#include <infiniband/umad.h>
42
43#ifdef __cplusplus
44#  define BEGIN_C_DECLS extern "C" {
45#  define END_C_DECLS   }
46#else				/* !__cplusplus */
47#  define BEGIN_C_DECLS
48#  define END_C_DECLS
49#endif				/* __cplusplus */
50
51BEGIN_C_DECLS
52
53#define UMAD_BASE_VERSION		1
54#define UMAD_QKEY			0x80010000
55
56/* Management classes */
57enum {
58	UMAD_CLASS_SUBN_LID_ROUTED	= 0x01,
59	UMAD_CLASS_SUBN_DIRECTED_ROUTE	= 0x81,
60	UMAD_CLASS_SUBN_ADM		= 0x03,
61	UMAD_CLASS_PERF_MGMT		= 0x04,
62	UMAD_CLASS_BM			= 0x05,
63	UMAD_CLASS_DEVICE_MGMT		= 0x06,
64	UMAD_CLASS_CM			= 0x07,
65	UMAD_CLASS_SNMP			= 0x08,
66	UMAD_CLASS_VENDOR_RANGE1_START	= 0x09,
67	UMAD_CLASS_VENDOR_RANGE1_END	= 0x0F,
68	UMAD_CLASS_APPLICATION_START	= 0x10,
69	UMAD_CLASS_DEVICE_ADM		= UMAD_CLASS_APPLICATION_START,
70	UMAD_CLASS_BOOT_MGMT		= 0x11,
71	UMAD_CLASS_BIS			= 0x12,
72	UMAD_CLASS_CONG_MGMT		= 0x21,
73	UMAD_CLASS_APPLICATION_END	= 0x2F,
74	UMAD_CLASS_VENDOR_RANGE2_START	= 0x30,
75	UMAD_CLASS_VENDOR_RANGE2_END	= 0x4F
76};
77
78/* Management methods */
79enum {
80	UMAD_METHOD_GET			= 0x01,
81	UMAD_METHOD_SET			= 0x02,
82	UMAD_METHOD_GET_RESP		= 0x81,
83	UMAD_METHOD_SEND		= 0x03,
84	UMAD_METHOD_TRAP		= 0x05,
85	UMAD_METHOD_REPORT		= 0x06,
86	UMAD_METHOD_REPORT_RESP		= 0x86,
87	UMAD_METHOD_TRAP_REPRESS	= 0x07,
88	UMAD_METHOD_RESP_MASK		= 0x80
89};
90
91enum {
92	UMAD_STATUS_SUCCESS  = 0x0000,
93	UMAD_STATUS_BUSY     = 0x0001,
94	UMAD_STATUS_REDIRECT = 0x0002,
95
96	/* Invalid fields, bits 2-4 */
97	UMAD_STATUS_BAD_VERSION          = (1 << 2),
98	UMAD_STATUS_METHOD_NOT_SUPPORTED = (2 << 2),
99	UMAD_STATUS_ATTR_NOT_SUPPORTED   = (3 << 2),
100	UMAD_STATUS_INVALID_ATTR_VALUE   = (7 << 2),
101
102	UMAD_STATUS_INVALID_FIELD_MASK = 0x001C,
103	UMAD_STATUS_CLASS_MASK         = 0xFF00
104};
105
106/* Attributes common to multiple classes */
107enum {
108	UMAD_ATTR_CLASS_PORT_INFO	= 0x0001,
109	UMAD_ATTR_NOTICE		= 0x0002,
110	UMAD_ATTR_INFORM_INFO		= 0x0003
111};
112
113/* RMPP information */
114#define UMAD_RMPP_VERSION		1
115enum {
116	UMAD_RMPP_FLAG_ACTIVE		= 1,
117};
118
119enum {
120	UMAD_LEN_DATA			= 232,
121	UMAD_LEN_RMPP_DATA		= 220,
122	UMAD_LEN_DM_DATA		= 192,
123	UMAD_LEN_VENDOR_DATA		= 216,
124};
125
126struct umad_hdr {
127	uint8_t	 base_version;
128	uint8_t	 mgmt_class;
129	uint8_t	 class_version;
130	uint8_t	 method;
131	__be16   status;
132	__be16   class_specific;
133	__be64   tid;
134	__be16   attr_id;
135	__be16   resv;
136	__be32   attr_mod;
137};
138
139struct umad_rmpp_hdr {
140	uint8_t	 rmpp_version;
141	uint8_t	 rmpp_type;
142	uint8_t	 rmpp_rtime_flags;
143	uint8_t	 rmpp_status;
144	__be32   seg_num;
145	__be32   paylen_newwin;
146};
147
148struct umad_packet {
149	struct umad_hdr		mad_hdr;
150	uint8_t			data[UMAD_LEN_DATA]; /* network-byte order */
151};
152
153struct umad_rmpp_packet {
154	struct umad_hdr		mad_hdr;
155	struct umad_rmpp_hdr	rmpp_hdr;
156	uint8_t			data[UMAD_LEN_RMPP_DATA]; /* network-byte order */
157};
158
159struct umad_dm_packet {
160	struct umad_hdr		mad_hdr;
161	uint8_t			reserved[40];
162	uint8_t			data[UMAD_LEN_DM_DATA];	/* network-byte order */
163};
164
165struct umad_vendor_packet {
166	struct umad_hdr		mad_hdr;
167	struct umad_rmpp_hdr	rmpp_hdr;
168	uint8_t			reserved;
169	uint8_t			oui[3];	/* network-byte order */
170	uint8_t			data[UMAD_LEN_VENDOR_DATA]; /* network-byte order */
171};
172
173enum {
174	UMAD_OPENIB_OUI		= 0x001405
175};
176
177enum {
178	UMAD_CLASS_RESP_TIME_MASK = 0x1F
179};
180struct umad_class_port_info {
181	uint8_t base_ver;
182	uint8_t class_ver;
183	__be16  cap_mask;
184	__be32  cap_mask2_resp_time;
185	union {
186		uint8_t redir_gid[16] __attribute__((deprecated)); /* network byte order */
187		union umad_gid redirgid;
188	};
189	__be32  redir_tc_sl_fl;
190	__be16  redir_lid;
191	__be16  redir_pkey;
192	__be32  redir_qp;
193	__be32  redir_qkey;
194	union {
195		uint8_t trap_gid[16] __attribute__((deprecated)); /* network byte order */
196		union umad_gid trapgid;
197	};
198	__be32  trap_tc_sl_fl;
199	__be16  trap_lid;
200	__be16  trap_pkey;
201	__be32  trap_hl_qp;
202	__be32  trap_qkey;
203};
204static inline uint32_t
205umad_class_cap_mask2(struct umad_class_port_info *cpi)
206{
207	return (be32toh(cpi->cap_mask2_resp_time) >> 5);
208}
209static inline uint8_t
210umad_class_resp_time(struct umad_class_port_info *cpi)
211{
212	return (uint8_t)(be32toh(cpi->cap_mask2_resp_time)
213			 & UMAD_CLASS_RESP_TIME_MASK);
214}
215
216END_C_DECLS
217#endif				/* _UMAD_TYPES_H */
218