sparc: Convert naked unsigned uses to unsigned int
[linux-2.6-block.git] / drivers / staging / rdma / hfi1 / mad.h
1 /*
2  *
3  * This file is provided under a dual BSD/GPLv2 license.  When using or
4  * redistributing this file, you may do so under either license.
5  *
6  * GPL LICENSE SUMMARY
7  *
8  * Copyright(c) 2015 Intel Corporation.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of version 2 of the GNU General Public License as
12  * published by the Free Software Foundation.
13  *
14  * This program is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * General Public License for more details.
18  *
19  * BSD LICENSE
20  *
21  * Copyright(c) 2015 Intel Corporation.
22  *
23  * Redistribution and use in source and binary forms, with or without
24  * modification, are permitted provided that the following conditions
25  * are met:
26  *
27  *  - Redistributions of source code must retain the above copyright
28  *    notice, this list of conditions and the following disclaimer.
29  *  - Redistributions in binary form must reproduce the above copyright
30  *    notice, this list of conditions and the following disclaimer in
31  *    the documentation and/or other materials provided with the
32  *    distribution.
33  *  - Neither the name of Intel Corporation nor the names of its
34  *    contributors may be used to endorse or promote products derived
35  *    from this software without specific prior written permission.
36  *
37  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
38  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
39  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
40  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
41  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
44  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
45  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
46  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
47  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48  *
49  */
50 #ifndef _HFI1_MAD_H
51 #define _HFI1_MAD_H
52
53 #include <rdma/ib_pma.h>
54 #define USE_PI_LED_ENABLE       1 /* use led enabled bit in struct
55                                    * opa_port_states, if available */
56 #include <rdma/opa_smi.h>
57 #include <rdma/opa_port_info.h>
58 #ifndef PI_LED_ENABLE_SUP
59 #define PI_LED_ENABLE_SUP 0
60 #endif
61 #include "opa_compat.h"
62
63 /*
64  * OPA Traps
65  */
66 #define OPA_TRAP_GID_NOW_IN_SERVICE             cpu_to_be16(64)
67 #define OPA_TRAP_GID_OUT_OF_SERVICE             cpu_to_be16(65)
68 #define OPA_TRAP_ADD_MULTICAST_GROUP            cpu_to_be16(66)
69 #define OPA_TRAL_DEL_MULTICAST_GROUP            cpu_to_be16(67)
70 #define OPA_TRAP_UNPATH                         cpu_to_be16(68)
71 #define OPA_TRAP_REPATH                         cpu_to_be16(69)
72 #define OPA_TRAP_PORT_CHANGE_STATE              cpu_to_be16(128)
73 #define OPA_TRAP_LINK_INTEGRITY                 cpu_to_be16(129)
74 #define OPA_TRAP_EXCESSIVE_BUFFER_OVERRUN       cpu_to_be16(130)
75 #define OPA_TRAP_FLOW_WATCHDOG                  cpu_to_be16(131)
76 #define OPA_TRAP_CHANGE_CAPABILITY              cpu_to_be16(144)
77 #define OPA_TRAP_CHANGE_SYSGUID                 cpu_to_be16(145)
78 #define OPA_TRAP_BAD_M_KEY                      cpu_to_be16(256)
79 #define OPA_TRAP_BAD_P_KEY                      cpu_to_be16(257)
80 #define OPA_TRAP_BAD_Q_KEY                      cpu_to_be16(258)
81 #define OPA_TRAP_SWITCH_BAD_PKEY                cpu_to_be16(259)
82 #define OPA_SMA_TRAP_DATA_LINK_WIDTH            cpu_to_be16(2048)
83
84 /*
85  * Generic trap/notice other local changes flags (trap 144).
86  */
87 #define OPA_NOTICE_TRAP_LWDE_CHG        0x08 /* Link Width Downgrade Enable
88                                               * changed
89                                               */
90 #define OPA_NOTICE_TRAP_LSE_CHG         0x04 /* Link Speed Enable changed */
91 #define OPA_NOTICE_TRAP_LWE_CHG         0x02 /* Link Width Enable changed */
92 #define OPA_NOTICE_TRAP_NODE_DESC_CHG   0x01
93
94 struct opa_mad_notice_attr {
95         u8 generic_type;
96         u8 prod_type_msb;
97         __be16 prod_type_lsb;
98         __be16 trap_num;
99         __be16 toggle_count;
100         __be32 issuer_lid;
101         __be32 reserved1;
102         union ib_gid issuer_gid;
103
104         union {
105                 struct {
106                         u8      details[64];
107                 } raw_data;
108
109                 struct {
110                         union ib_gid    gid;
111                 } __packed ntc_64_65_66_67;
112
113                 struct {
114                         __be32  lid;
115                 } __packed ntc_128;
116
117                 struct {
118                         __be32  lid;            /* where violation happened */
119                         u8      port_num;       /* where violation happened */
120                 } __packed ntc_129_130_131;
121
122                 struct {
123                         __be32  lid;            /* LID where change occurred */
124                         __be32  new_cap_mask;   /* new capability mask */
125                         __be16  reserved2;
126                         __be16  cap_mask;
127                         __be16  change_flags;   /* low 4 bits only */
128                 } __packed ntc_144;
129
130                 struct {
131                         __be64  new_sys_guid;
132                         __be32  lid;            /* lid where sys guid changed */
133                 } __packed ntc_145;
134
135                 struct {
136                         __be32  lid;
137                         __be32  dr_slid;
138                         u8      method;
139                         u8      dr_trunc_hop;
140                         __be16  attr_id;
141                         __be32  attr_mod;
142                         __be64  mkey;
143                         u8      dr_rtn_path[30];
144                 } __packed ntc_256;
145
146                 struct {
147                         __be32          lid1;
148                         __be32          lid2;
149                         __be32          key;
150                         u8              sl;     /* SL: high 5 bits */
151                         u8              reserved3[3];
152                         union ib_gid    gid1;
153                         union ib_gid    gid2;
154                         __be32          qp1;    /* high 8 bits reserved */
155                         __be32          qp2;    /* high 8 bits reserved */
156                 } __packed ntc_257_258;
157
158                 struct {
159                         __be16          flags;  /* low 8 bits reserved */
160                         __be16          pkey;
161                         __be32          lid1;
162                         __be32          lid2;
163                         u8              sl;     /* SL: high 5 bits */
164                         u8              reserved4[3];
165                         union ib_gid    gid1;
166                         union ib_gid    gid2;
167                         __be32          qp1;    /* high 8 bits reserved */
168                         __be32          qp2;    /* high 8 bits reserved */
169                 } __packed ntc_259;
170
171                 struct {
172                         __be32  lid;
173                 } __packed ntc_2048;
174
175         };
176         u8      class_data[0];
177 };
178
179 #define IB_VLARB_LOWPRI_0_31    1
180 #define IB_VLARB_LOWPRI_32_63   2
181 #define IB_VLARB_HIGHPRI_0_31   3
182 #define IB_VLARB_HIGHPRI_32_63  4
183
184 #define OPA_MAX_PREEMPT_CAP         32
185 #define OPA_VLARB_LOW_ELEMENTS       0
186 #define OPA_VLARB_HIGH_ELEMENTS      1
187 #define OPA_VLARB_PREEMPT_ELEMENTS   2
188 #define OPA_VLARB_PREEMPT_MATRIX     3
189
190 #define IB_PMA_PORT_COUNTERS_CONG       cpu_to_be16(0xFF00)
191
192 struct ib_pma_portcounters_cong {
193         u8 reserved;
194         u8 reserved1;
195         __be16 port_check_rate;
196         __be16 symbol_error_counter;
197         u8 link_error_recovery_counter;
198         u8 link_downed_counter;
199         __be16 port_rcv_errors;
200         __be16 port_rcv_remphys_errors;
201         __be16 port_rcv_switch_relay_errors;
202         __be16 port_xmit_discards;
203         u8 port_xmit_constraint_errors;
204         u8 port_rcv_constraint_errors;
205         u8 reserved2;
206         u8 link_overrun_errors; /* LocalLink: 7:4, BufferOverrun: 3:0 */
207         __be16 reserved3;
208         __be16 vl15_dropped;
209         __be64 port_xmit_data;
210         __be64 port_rcv_data;
211         __be64 port_xmit_packets;
212         __be64 port_rcv_packets;
213         __be64 port_xmit_wait;
214         __be64 port_adr_events;
215 } __packed;
216
217 #define IB_SMP_UNSUP_VERSION    cpu_to_be16(0x0004)
218 #define IB_SMP_UNSUP_METHOD     cpu_to_be16(0x0008)
219 #define IB_SMP_UNSUP_METH_ATTR  cpu_to_be16(0x000C)
220 #define IB_SMP_INVALID_FIELD    cpu_to_be16(0x001C)
221
222 #define OPA_MAX_PREEMPT_CAP         32
223 #define OPA_VLARB_LOW_ELEMENTS       0
224 #define OPA_VLARB_HIGH_ELEMENTS      1
225 #define OPA_VLARB_PREEMPT_ELEMENTS   2
226 #define OPA_VLARB_PREEMPT_MATRIX     3
227
228 #define HFI1_XMIT_RATE_UNSUPPORTED               0x0
229 #define HFI1_XMIT_RATE_PICO                      0x7
230 /* number of 4nsec cycles equaling 2secs */
231 #define HFI1_CONG_TIMER_PSINTERVAL               0x1DCD64EC
232
233 #define IB_CC_SVCTYPE_RC 0x0
234 #define IB_CC_SVCTYPE_UC 0x1
235 #define IB_CC_SVCTYPE_RD 0x2
236 #define IB_CC_SVCTYPE_UD 0x3
237
238
239 /*
240  * There should be an equivalent IB #define for the following, but
241  * I cannot find it.
242  */
243 #define OPA_CC_LOG_TYPE_HFI     2
244
245 struct opa_hfi1_cong_log_event_internal {
246         u32 lqpn;
247         u32 rqpn;
248         u8 sl;
249         u8 svc_type;
250         u32 rlid;
251         s64 timestamp; /* wider than 32 bits to detect 32 bit rollover */
252 };
253
254 struct opa_hfi1_cong_log_event {
255         u8 local_qp_cn_entry[3];
256         u8 remote_qp_number_cn_entry[3];
257         u8 sl_svc_type_cn_entry; /* 5 bits SL, 3 bits svc type */
258         u8 reserved;
259         __be32 remote_lid_cn_entry;
260         __be32 timestamp_cn_entry;
261 } __packed;
262
263 #define OPA_CONG_LOG_ELEMS      96
264
265 struct opa_hfi1_cong_log {
266         u8 log_type;
267         u8 congestion_flags;
268         __be16 threshold_event_counter;
269         __be32 current_time_stamp;
270         u8 threshold_cong_event_map[OPA_MAX_SLS/8];
271         struct opa_hfi1_cong_log_event events[OPA_CONG_LOG_ELEMS];
272 } __packed;
273
274 #define IB_CC_TABLE_CAP_DEFAULT 31
275
276 /* Port control flags */
277 #define IB_CC_CCS_PC_SL_BASED 0x01
278
279 struct opa_congestion_setting_entry {
280         u8 ccti_increase;
281         u8 reserved;
282         __be16 ccti_timer;
283         u8 trigger_threshold;
284         u8 ccti_min; /* min CCTI for cc table */
285 } __packed;
286
287 struct opa_congestion_setting_entry_shadow {
288         u8 ccti_increase;
289         u8 reserved;
290         u16 ccti_timer;
291         u8 trigger_threshold;
292         u8 ccti_min; /* min CCTI for cc table */
293 } __packed;
294
295 struct opa_congestion_setting_attr {
296         __be32 control_map;
297         __be16 port_control;
298         struct opa_congestion_setting_entry entries[OPA_MAX_SLS];
299 } __packed;
300
301 struct opa_congestion_setting_attr_shadow {
302         u32 control_map;
303         u16 port_control;
304         struct opa_congestion_setting_entry_shadow entries[OPA_MAX_SLS];
305 } __packed;
306
307 #define IB_CC_TABLE_ENTRY_INCREASE_DEFAULT 1
308 #define IB_CC_TABLE_ENTRY_TIMER_DEFAULT 1
309
310 /* 64 Congestion Control table entries in a single MAD */
311 #define IB_CCT_ENTRIES 64
312 #define IB_CCT_MIN_ENTRIES (IB_CCT_ENTRIES * 2)
313
314 struct ib_cc_table_entry {
315         __be16 entry; /* shift:2, multiplier:14 */
316 };
317
318 struct ib_cc_table_entry_shadow {
319         u16 entry; /* shift:2, multiplier:14 */
320 };
321
322 struct ib_cc_table_attr {
323         __be16 ccti_limit; /* max CCTI for cc table */
324         struct ib_cc_table_entry ccti_entries[IB_CCT_ENTRIES];
325 } __packed;
326
327 struct ib_cc_table_attr_shadow {
328         u16 ccti_limit; /* max CCTI for cc table */
329         struct ib_cc_table_entry_shadow ccti_entries[IB_CCT_ENTRIES];
330 } __packed;
331
332 #define CC_TABLE_SHADOW_MAX \
333         (IB_CC_TABLE_CAP_DEFAULT * IB_CCT_ENTRIES)
334
335 struct cc_table_shadow {
336         u16 ccti_limit; /* max CCTI for cc table */
337         struct ib_cc_table_entry_shadow entries[CC_TABLE_SHADOW_MAX];
338 } __packed;
339
340 /*
341  * struct cc_state combines the (active) per-port congestion control
342  * table, and the (active) per-SL congestion settings. cc_state data
343  * may need to be read in code paths that we want to be fast, so it
344  * is an RCU protected structure.
345  */
346 struct cc_state {
347         struct rcu_head rcu;
348         struct cc_table_shadow cct;
349         struct opa_congestion_setting_attr_shadow cong_setting;
350 };
351
352 /*
353  * OPA BufferControl MAD
354  */
355
356 /* attribute modifier macros */
357 #define OPA_AM_NPORT_SHIFT      24
358 #define OPA_AM_NPORT_MASK       0xff
359 #define OPA_AM_NPORT_SMASK      (OPA_AM_NPORT_MASK << OPA_AM_NPORT_SHIFT)
360 #define OPA_AM_NPORT(am)        (((am) >> OPA_AM_NPORT_SHIFT) & \
361                                         OPA_AM_NPORT_MASK)
362
363 #define OPA_AM_NBLK_SHIFT       24
364 #define OPA_AM_NBLK_MASK        0xff
365 #define OPA_AM_NBLK_SMASK       (OPA_AM_NBLK_MASK << OPA_AM_NBLK_SHIFT)
366 #define OPA_AM_NBLK(am)         (((am) >> OPA_AM_NBLK_SHIFT) & \
367                                         OPA_AM_NBLK_MASK)
368
369 #define OPA_AM_START_BLK_SHIFT  0
370 #define OPA_AM_START_BLK_MASK   0xff
371 #define OPA_AM_START_BLK_SMASK  (OPA_AM_START_BLK_MASK << \
372                                         OPA_AM_START_BLK_SHIFT)
373 #define OPA_AM_START_BLK(am)    (((am) >> OPA_AM_START_BLK_SHIFT) & \
374                                         OPA_AM_START_BLK_MASK)
375
376 #define OPA_AM_PORTNUM_SHIFT    0
377 #define OPA_AM_PORTNUM_MASK     0xff
378 #define OPA_AM_PORTNUM_SMASK    (OPA_AM_PORTNUM_MASK << OPA_AM_PORTNUM_SHIFT)
379 #define OPA_AM_PORTNUM(am)      (((am) >> OPA_AM_PORTNUM_SHIFT) & \
380                                         OPA_AM_PORTNUM_MASK)
381
382 #define OPA_AM_ASYNC_SHIFT      12
383 #define OPA_AM_ASYNC_MASK       0x1
384 #define OPA_AM_ASYNC_SMASK      (OPA_AM_ASYNC_MASK << OPA_AM_ASYNC_SHIFT)
385 #define OPA_AM_ASYNC(am)        (((am) >> OPA_AM_ASYNC_SHIFT) & \
386                                         OPA_AM_ASYNC_MASK)
387
388 #define OPA_AM_START_SM_CFG_SHIFT       9
389 #define OPA_AM_START_SM_CFG_MASK        0x1
390 #define OPA_AM_START_SM_CFG_SMASK       (OPA_AM_START_SM_CFG_MASK << \
391                                                 OPA_AM_START_SM_CFG_SHIFT)
392 #define OPA_AM_START_SM_CFG(am)         (((am) >> OPA_AM_START_SM_CFG_SHIFT) \
393                                                 & OPA_AM_START_SM_CFG_MASK)
394
395 #define OPA_AM_CI_ADDR_SHIFT    19
396 #define OPA_AM_CI_ADDR_MASK     0xfff
397 #define OPA_AM_CI_ADDR_SMASK    (OPA_AM_CI_ADDR_MASK << OPA_CI_ADDR_SHIFT)
398 #define OPA_AM_CI_ADDR(am)      (((am) >> OPA_AM_CI_ADDR_SHIFT) & \
399                                         OPA_AM_CI_ADDR_MASK)
400
401 #define OPA_AM_CI_LEN_SHIFT     13
402 #define OPA_AM_CI_LEN_MASK      0x3f
403 #define OPA_AM_CI_LEN_SMASK     (OPA_AM_CI_LEN_MASK << OPA_CI_LEN_SHIFT)
404 #define OPA_AM_CI_LEN(am)       (((am) >> OPA_AM_CI_LEN_SHIFT) & \
405                                         OPA_AM_CI_LEN_MASK)
406
407 /* error info macros */
408 #define OPA_EI_STATUS_SMASK     0x80
409 #define OPA_EI_CODE_SMASK       0x0f
410
411 struct vl_limit {
412         __be16 dedicated;
413         __be16 shared;
414 };
415
416 struct buffer_control {
417         __be16 reserved;
418         __be16 overall_shared_limit;
419         struct vl_limit vl[OPA_MAX_VLS];
420 };
421
422 struct sc2vlnt {
423         u8 vlnt[32]; /* 5 bit VL, 3 bits reserved */
424 };
425
426 /*
427  * The PortSamplesControl.CounterMasks field is an array of 3 bit fields
428  * which specify the N'th counter's capabilities. See ch. 16.1.3.2.
429  * We support 5 counters which only count the mandatory quantities.
430  */
431 #define COUNTER_MASK(q, n) (q << ((9 - n) * 3))
432 #define COUNTER_MASK0_9 \
433         cpu_to_be32(COUNTER_MASK(1, 0) | \
434                     COUNTER_MASK(1, 1) | \
435                     COUNTER_MASK(1, 2) | \
436                     COUNTER_MASK(1, 3) | \
437                     COUNTER_MASK(1, 4))
438
439 #endif                          /* _HFI1_MAD_H */