xref: /OK3568_Linux_fs/kernel/drivers/infiniband/hw/hfi1/opa_compat.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun #ifndef _LINUX_H
2*4882a593Smuzhiyun #define _LINUX_H
3*4882a593Smuzhiyun /*
4*4882a593Smuzhiyun  * Copyright(c) 2015, 2016 Intel Corporation.
5*4882a593Smuzhiyun  *
6*4882a593Smuzhiyun  * This file is provided under a dual BSD/GPLv2 license.  When using or
7*4882a593Smuzhiyun  * redistributing this file, you may do so under either license.
8*4882a593Smuzhiyun  *
9*4882a593Smuzhiyun  * GPL LICENSE SUMMARY
10*4882a593Smuzhiyun  *
11*4882a593Smuzhiyun  * This program is free software; you can redistribute it and/or modify
12*4882a593Smuzhiyun  * it under the terms of version 2 of the GNU General Public License as
13*4882a593Smuzhiyun  * published by the Free Software Foundation.
14*4882a593Smuzhiyun  *
15*4882a593Smuzhiyun  * This program is distributed in the hope that it will be useful, but
16*4882a593Smuzhiyun  * WITHOUT ANY WARRANTY; without even the implied warranty of
17*4882a593Smuzhiyun  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18*4882a593Smuzhiyun  * General Public License for more details.
19*4882a593Smuzhiyun  *
20*4882a593Smuzhiyun  * BSD LICENSE
21*4882a593Smuzhiyun  *
22*4882a593Smuzhiyun  * Redistribution and use in source and binary forms, with or without
23*4882a593Smuzhiyun  * modification, are permitted provided that the following conditions
24*4882a593Smuzhiyun  * are met:
25*4882a593Smuzhiyun  *
26*4882a593Smuzhiyun  *  - Redistributions of source code must retain the above copyright
27*4882a593Smuzhiyun  *    notice, this list of conditions and the following disclaimer.
28*4882a593Smuzhiyun  *  - Redistributions in binary form must reproduce the above copyright
29*4882a593Smuzhiyun  *    notice, this list of conditions and the following disclaimer in
30*4882a593Smuzhiyun  *    the documentation and/or other materials provided with the
31*4882a593Smuzhiyun  *    distribution.
32*4882a593Smuzhiyun  *  - Neither the name of Intel Corporation nor the names of its
33*4882a593Smuzhiyun  *    contributors may be used to endorse or promote products derived
34*4882a593Smuzhiyun  *    from this software without specific prior written permission.
35*4882a593Smuzhiyun  *
36*4882a593Smuzhiyun  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
37*4882a593Smuzhiyun  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
38*4882a593Smuzhiyun  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
39*4882a593Smuzhiyun  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
40*4882a593Smuzhiyun  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41*4882a593Smuzhiyun  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42*4882a593Smuzhiyun  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
43*4882a593Smuzhiyun  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
44*4882a593Smuzhiyun  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
45*4882a593Smuzhiyun  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
46*4882a593Smuzhiyun  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
47*4882a593Smuzhiyun  *
48*4882a593Smuzhiyun  */
49*4882a593Smuzhiyun 
50*4882a593Smuzhiyun /*
51*4882a593Smuzhiyun  * This header file is for OPA-specific definitions which are
52*4882a593Smuzhiyun  * required by the HFI driver, and which aren't yet in the Linux
53*4882a593Smuzhiyun  * IB core. We'll collect these all here, then merge them into
54*4882a593Smuzhiyun  * the kernel when that's convenient.
55*4882a593Smuzhiyun  */
56*4882a593Smuzhiyun 
57*4882a593Smuzhiyun /* OPA SMA attribute IDs */
58*4882a593Smuzhiyun #define OPA_ATTRIB_ID_CONGESTION_INFO		cpu_to_be16(0x008b)
59*4882a593Smuzhiyun #define OPA_ATTRIB_ID_HFI_CONGESTION_LOG	cpu_to_be16(0x008f)
60*4882a593Smuzhiyun #define OPA_ATTRIB_ID_HFI_CONGESTION_SETTING	cpu_to_be16(0x0090)
61*4882a593Smuzhiyun #define OPA_ATTRIB_ID_CONGESTION_CONTROL_TABLE	cpu_to_be16(0x0091)
62*4882a593Smuzhiyun 
63*4882a593Smuzhiyun /* OPA PMA attribute IDs */
64*4882a593Smuzhiyun #define OPA_PM_ATTRIB_ID_PORT_STATUS		cpu_to_be16(0x0040)
65*4882a593Smuzhiyun #define OPA_PM_ATTRIB_ID_CLEAR_PORT_STATUS	cpu_to_be16(0x0041)
66*4882a593Smuzhiyun #define OPA_PM_ATTRIB_ID_DATA_PORT_COUNTERS	cpu_to_be16(0x0042)
67*4882a593Smuzhiyun #define OPA_PM_ATTRIB_ID_ERROR_PORT_COUNTERS	cpu_to_be16(0x0043)
68*4882a593Smuzhiyun #define OPA_PM_ATTRIB_ID_ERROR_INFO		cpu_to_be16(0x0044)
69*4882a593Smuzhiyun 
70*4882a593Smuzhiyun /* OPA status codes */
71*4882a593Smuzhiyun #define OPA_PM_STATUS_REQUEST_TOO_LARGE		cpu_to_be16(0x100)
72*4882a593Smuzhiyun 
port_states_to_logical_state(struct opa_port_states * ps)73*4882a593Smuzhiyun static inline u8 port_states_to_logical_state(struct opa_port_states *ps)
74*4882a593Smuzhiyun {
75*4882a593Smuzhiyun 	return ps->portphysstate_portstate & OPA_PI_MASK_PORT_STATE;
76*4882a593Smuzhiyun }
77*4882a593Smuzhiyun 
port_states_to_phys_state(struct opa_port_states * ps)78*4882a593Smuzhiyun static inline u8 port_states_to_phys_state(struct opa_port_states *ps)
79*4882a593Smuzhiyun {
80*4882a593Smuzhiyun 	return ((ps->portphysstate_portstate &
81*4882a593Smuzhiyun 		  OPA_PI_MASK_PORT_PHYSICAL_STATE) >> 4) & 0xf;
82*4882a593Smuzhiyun }
83*4882a593Smuzhiyun 
84*4882a593Smuzhiyun /*
85*4882a593Smuzhiyun  * OPA port physical states
86*4882a593Smuzhiyun  * IB Volume 1, Table 146 PortInfo/IB Volume 2 Section 5.4.2(1) PortPhysState
87*4882a593Smuzhiyun  * values are the same in OmniPath Architecture. OPA leverages some of the same
88*4882a593Smuzhiyun  * concepts as InfiniBand, but has a few other states as well.
89*4882a593Smuzhiyun  *
90*4882a593Smuzhiyun  * When writing, only values 0-3 are valid, other values are ignored.
91*4882a593Smuzhiyun  * When reading, 0 is reserved.
92*4882a593Smuzhiyun  *
93*4882a593Smuzhiyun  * Returned by the ibphys_portstate() routine.
94*4882a593Smuzhiyun  */
95*4882a593Smuzhiyun enum opa_port_phys_state {
96*4882a593Smuzhiyun 	/* Values 0-7 have the same meaning in OPA as in InfiniBand. */
97*4882a593Smuzhiyun 
98*4882a593Smuzhiyun 	IB_PORTPHYSSTATE_NOP = 0,
99*4882a593Smuzhiyun 	/* 1 is reserved */
100*4882a593Smuzhiyun 	IB_PORTPHYSSTATE_POLLING = 2,
101*4882a593Smuzhiyun 	IB_PORTPHYSSTATE_DISABLED = 3,
102*4882a593Smuzhiyun 	IB_PORTPHYSSTATE_TRAINING = 4,
103*4882a593Smuzhiyun 	IB_PORTPHYSSTATE_LINKUP = 5,
104*4882a593Smuzhiyun 	IB_PORTPHYSSTATE_LINK_ERROR_RECOVERY = 6,
105*4882a593Smuzhiyun 	IB_PORTPHYSSTATE_PHY_TEST = 7,
106*4882a593Smuzhiyun 	/* 8 is reserved */
107*4882a593Smuzhiyun 
108*4882a593Smuzhiyun 	/*
109*4882a593Smuzhiyun 	 * Offline: Port is quiet (transmitters disabled) due to lack of
110*4882a593Smuzhiyun 	 * physical media, unsupported media, or transition between link up
111*4882a593Smuzhiyun 	 * and next link up attempt
112*4882a593Smuzhiyun 	 */
113*4882a593Smuzhiyun 	OPA_PORTPHYSSTATE_OFFLINE = 9,
114*4882a593Smuzhiyun 
115*4882a593Smuzhiyun 	/* 10 is reserved */
116*4882a593Smuzhiyun 
117*4882a593Smuzhiyun 	/*
118*4882a593Smuzhiyun 	 * Phy_Test: Specific test patterns are transmitted, and receiver BER
119*4882a593Smuzhiyun 	 * can be monitored. This facilitates signal integrity testing for the
120*4882a593Smuzhiyun 	 * physical layer of the port.
121*4882a593Smuzhiyun 	 */
122*4882a593Smuzhiyun 	OPA_PORTPHYSSTATE_TEST = 11,
123*4882a593Smuzhiyun 
124*4882a593Smuzhiyun 	OPA_PORTPHYSSTATE_MAX = 11,
125*4882a593Smuzhiyun 	/* values 12-15 are reserved/ignored */
126*4882a593Smuzhiyun };
127*4882a593Smuzhiyun 
128*4882a593Smuzhiyun #endif /* _LINUX_H */
129