1255932Salfred/*
2255932Salfred * Copyright (c) 2006, 2007, 2008, 2009, 2010 QLogic Corporation.
3255932Salfred * All rights reserved.
4255932Salfred * Copyright (c) 2005, 2006 PathScale, Inc. All rights reserved.
5255932Salfred *
6255932Salfred * This software is available to you under a choice of one of two
7255932Salfred * licenses.  You may choose to be licensed under the terms of the GNU
8255932Salfred * General Public License (GPL) Version 2, available from the file
9255932Salfred * COPYING in the main directory of this source tree, or the
10255932Salfred * OpenIB.org BSD license below:
11255932Salfred *
12255932Salfred *     Redistribution and use in source and binary forms, with or
13255932Salfred *     without modification, are permitted provided that the following
14255932Salfred *     conditions are met:
15255932Salfred *
16255932Salfred *      - Redistributions of source code must retain the above
17255932Salfred *        copyright notice, this list of conditions and the following
18255932Salfred *        disclaimer.
19255932Salfred *
20255932Salfred *      - Redistributions in binary form must reproduce the above
21255932Salfred *        copyright notice, this list of conditions and the following
22255932Salfred *        disclaimer in the documentation and/or other materials
23255932Salfred *        provided with the distribution.
24255932Salfred *
25255932Salfred * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26255932Salfred * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27255932Salfred * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28255932Salfred * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29255932Salfred * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30255932Salfred * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31255932Salfred * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32255932Salfred * SOFTWARE.
33255932Salfred */
34255932Salfred
35255932Salfred#if !defined(IB_PMA_H)
36255932Salfred#define IB_PMA_H
37255932Salfred
38255932Salfred#include <rdma/ib_mad.h>
39255932Salfred
40291249Shselasky#define MAX_U32 0xffffffffULL
41291249Shselasky#define MAX_U16 0xffffUL
42291249Shselasky
43291249Shselasky/* Counters should be saturate once they reach their maximum value */
44291249Shselasky#define ASSIGN_32BIT_COUNTER(counter, value) do {	\
45291249Shselasky	if ((value) > MAX_U32)				\
46291249Shselasky		counter = cpu_to_be32(MAX_U32);		\
47291249Shselasky	else						\
48291249Shselasky		counter = cpu_to_be32(value);		\
49291249Shselasky} while (0)
50291249Shselasky
51291249Shselasky/* Counters should be saturate once they reach their maximum value */
52291249Shselasky#define ASSIGN_16BIT_COUNTER(counter, value) do {	\
53291249Shselasky	if ((value) > MAX_U16)				\
54291249Shselasky		counter = cpu_to_be16(MAX_U16);		\
55291249Shselasky	else						\
56291249Shselasky		counter = cpu_to_be16(value);		\
57291249Shselasky} while (0)
58291249Shselasky
59255932Salfred/*
60255932Salfred * PMA class portinfo capability mask bits
61255932Salfred */
62255932Salfred#define IB_PMA_CLASS_CAP_ALLPORTSELECT  cpu_to_be16(1 << 8)
63255932Salfred#define IB_PMA_CLASS_CAP_EXT_WIDTH      cpu_to_be16(1 << 9)
64255932Salfred#define IB_PMA_CLASS_CAP_XMIT_WAIT      cpu_to_be16(1 << 12)
65255932Salfred
66255932Salfred#define IB_PMA_CLASS_PORT_INFO          cpu_to_be16(0x0001)
67255932Salfred#define IB_PMA_PORT_SAMPLES_CONTROL     cpu_to_be16(0x0010)
68255932Salfred#define IB_PMA_PORT_SAMPLES_RESULT      cpu_to_be16(0x0011)
69255932Salfred#define IB_PMA_PORT_COUNTERS            cpu_to_be16(0x0012)
70255932Salfred#define IB_PMA_PORT_COUNTERS_EXT        cpu_to_be16(0x001D)
71255932Salfred#define IB_PMA_PORT_SAMPLES_RESULT_EXT  cpu_to_be16(0x001E)
72255932Salfred
73255932Salfredstruct ib_pma_mad {
74255932Salfred	struct ib_mad_hdr mad_hdr;
75255932Salfred	u8 reserved[40];
76255932Salfred	u8 data[192];
77255932Salfred} __packed;
78255932Salfred
79255932Salfredstruct ib_pma_portsamplescontrol {
80255932Salfred	u8 opcode;
81255932Salfred	u8 port_select;
82255932Salfred	u8 tick;
83255932Salfred	u8 counter_width;		/* resv: 7:3, counter width: 2:0 */
84255932Salfred	__be32 counter_mask0_9;		/* 2, 10 3-bit fields */
85255932Salfred	__be16 counter_mask10_14;	/* 1, 5 3-bit fields */
86255932Salfred	u8 sample_mechanisms;
87255932Salfred	u8 sample_status;		/* only lower 2 bits */
88255932Salfred	__be64 option_mask;
89255932Salfred	__be64 vendor_mask;
90255932Salfred	__be32 sample_start;
91255932Salfred	__be32 sample_interval;
92255932Salfred	__be16 tag;
93255932Salfred	__be16 counter_select[15];
94255932Salfred	__be32 reserved1;
95255932Salfred	__be64 samples_only_option_mask;
96255932Salfred	__be32 reserved2[28];
97255932Salfred};
98255932Salfred
99255932Salfredstruct ib_pma_portsamplesresult {
100255932Salfred	__be16 tag;
101255932Salfred	__be16 sample_status;   /* only lower 2 bits */
102255932Salfred	__be32 counter[15];
103255932Salfred};
104255932Salfred
105255932Salfredstruct ib_pma_portsamplesresult_ext {
106255932Salfred	__be16 tag;
107255932Salfred	__be16 sample_status;   /* only lower 2 bits */
108255932Salfred	__be32 extended_width;  /* only upper 2 bits */
109255932Salfred	__be64 counter[15];
110255932Salfred};
111255932Salfred
112255932Salfredstruct ib_pma_portcounters {
113255932Salfred	u8 reserved;
114255932Salfred	u8 port_select;
115255932Salfred	__be16 counter_select;
116255932Salfred	__be16 symbol_error_counter;
117255932Salfred	u8 link_error_recovery_counter;
118255932Salfred	u8 link_downed_counter;
119255932Salfred	__be16 port_rcv_errors;
120255932Salfred	__be16 port_rcv_remphys_errors;
121255932Salfred	__be16 port_rcv_switch_relay_errors;
122255932Salfred	__be16 port_xmit_discards;
123255932Salfred	u8 port_xmit_constraint_errors;
124255932Salfred	u8 port_rcv_constraint_errors;
125255932Salfred	u8 reserved1;
126255932Salfred	u8 link_overrun_errors; /* LocalLink: 7:4, BufferOverrun: 3:0 */
127255932Salfred	__be16 reserved2;
128255932Salfred	__be16 vl15_dropped;
129255932Salfred	__be32 port_xmit_data;
130255932Salfred	__be32 port_rcv_data;
131255932Salfred	__be32 port_xmit_packets;
132255932Salfred	__be32 port_rcv_packets;
133255932Salfred	__be32 port_xmit_wait;
134255932Salfred} __packed;
135255932Salfred
136255932Salfred
137255932Salfred#define IB_PMA_SEL_SYMBOL_ERROR                 cpu_to_be16(0x0001)
138255932Salfred#define IB_PMA_SEL_LINK_ERROR_RECOVERY          cpu_to_be16(0x0002)
139255932Salfred#define IB_PMA_SEL_LINK_DOWNED                  cpu_to_be16(0x0004)
140255932Salfred#define IB_PMA_SEL_PORT_RCV_ERRORS              cpu_to_be16(0x0008)
141255932Salfred#define IB_PMA_SEL_PORT_RCV_REMPHYS_ERRORS      cpu_to_be16(0x0010)
142255932Salfred#define IB_PMA_SEL_PORT_XMIT_DISCARDS           cpu_to_be16(0x0040)
143255932Salfred#define IB_PMA_SEL_LOCAL_LINK_INTEGRITY_ERRORS  cpu_to_be16(0x0200)
144255932Salfred#define IB_PMA_SEL_EXCESSIVE_BUFFER_OVERRUNS    cpu_to_be16(0x0400)
145255932Salfred#define IB_PMA_SEL_PORT_VL15_DROPPED            cpu_to_be16(0x0800)
146255932Salfred#define IB_PMA_SEL_PORT_XMIT_DATA               cpu_to_be16(0x1000)
147255932Salfred#define IB_PMA_SEL_PORT_RCV_DATA                cpu_to_be16(0x2000)
148255932Salfred#define IB_PMA_SEL_PORT_XMIT_PACKETS            cpu_to_be16(0x4000)
149255932Salfred#define IB_PMA_SEL_PORT_RCV_PACKETS             cpu_to_be16(0x8000)
150255932Salfred
151255932Salfredstruct ib_pma_portcounters_ext {
152255932Salfred	u8 reserved;
153255932Salfred	u8 port_select;
154255932Salfred	__be16 counter_select;
155255932Salfred	__be32 reserved1;
156255932Salfred	__be64 port_xmit_data;
157255932Salfred	__be64 port_rcv_data;
158255932Salfred	__be64 port_xmit_packets;
159255932Salfred	__be64 port_rcv_packets;
160255932Salfred	__be64 port_unicast_xmit_packets;
161255932Salfred	__be64 port_unicast_rcv_packets;
162255932Salfred	__be64 port_multicast_xmit_packets;
163255932Salfred	__be64 port_multicast_rcv_packets;
164255932Salfred} __packed;
165255932Salfred
166255932Salfred#define IB_PMA_SELX_PORT_XMIT_DATA              cpu_to_be16(0x0001)
167255932Salfred#define IB_PMA_SELX_PORT_RCV_DATA               cpu_to_be16(0x0002)
168255932Salfred#define IB_PMA_SELX_PORT_XMIT_PACKETS           cpu_to_be16(0x0004)
169255932Salfred#define IB_PMA_SELX_PORT_RCV_PACKETS            cpu_to_be16(0x0008)
170255932Salfred#define IB_PMA_SELX_PORT_UNI_XMIT_PACKETS       cpu_to_be16(0x0010)
171255932Salfred#define IB_PMA_SELX_PORT_UNI_RCV_PACKETS        cpu_to_be16(0x0020)
172255932Salfred#define IB_PMA_SELX_PORT_MULTI_XMIT_PACKETS     cpu_to_be16(0x0040)
173255932Salfred#define IB_PMA_SELX_PORT_MULTI_RCV_PACKETS      cpu_to_be16(0x0080)
174255932Salfred
175255932Salfred#endif /* IB_PMA_H */
176