18c2ecf20Sopenharmony_ci#ifndef _LINUX_H
28c2ecf20Sopenharmony_ci#define _LINUX_H
38c2ecf20Sopenharmony_ci/*
48c2ecf20Sopenharmony_ci * Copyright(c) 2015, 2016 Intel Corporation.
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * This file is provided under a dual BSD/GPLv2 license.  When using or
78c2ecf20Sopenharmony_ci * redistributing this file, you may do so under either license.
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci * GPL LICENSE SUMMARY
108c2ecf20Sopenharmony_ci *
118c2ecf20Sopenharmony_ci * This program is free software; you can redistribute it and/or modify
128c2ecf20Sopenharmony_ci * it under the terms of version 2 of the GNU General Public License as
138c2ecf20Sopenharmony_ci * published by the Free Software Foundation.
148c2ecf20Sopenharmony_ci *
158c2ecf20Sopenharmony_ci * This program is distributed in the hope that it will be useful, but
168c2ecf20Sopenharmony_ci * WITHOUT ANY WARRANTY; without even the implied warranty of
178c2ecf20Sopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
188c2ecf20Sopenharmony_ci * General Public License for more details.
198c2ecf20Sopenharmony_ci *
208c2ecf20Sopenharmony_ci * BSD LICENSE
218c2ecf20Sopenharmony_ci *
228c2ecf20Sopenharmony_ci * Redistribution and use in source and binary forms, with or without
238c2ecf20Sopenharmony_ci * modification, are permitted provided that the following conditions
248c2ecf20Sopenharmony_ci * are met:
258c2ecf20Sopenharmony_ci *
268c2ecf20Sopenharmony_ci *  - Redistributions of source code must retain the above copyright
278c2ecf20Sopenharmony_ci *    notice, this list of conditions and the following disclaimer.
288c2ecf20Sopenharmony_ci *  - Redistributions in binary form must reproduce the above copyright
298c2ecf20Sopenharmony_ci *    notice, this list of conditions and the following disclaimer in
308c2ecf20Sopenharmony_ci *    the documentation and/or other materials provided with the
318c2ecf20Sopenharmony_ci *    distribution.
328c2ecf20Sopenharmony_ci *  - Neither the name of Intel Corporation nor the names of its
338c2ecf20Sopenharmony_ci *    contributors may be used to endorse or promote products derived
348c2ecf20Sopenharmony_ci *    from this software without specific prior written permission.
358c2ecf20Sopenharmony_ci *
368c2ecf20Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
378c2ecf20Sopenharmony_ci * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
388c2ecf20Sopenharmony_ci * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
398c2ecf20Sopenharmony_ci * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
408c2ecf20Sopenharmony_ci * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
418c2ecf20Sopenharmony_ci * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
428c2ecf20Sopenharmony_ci * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
438c2ecf20Sopenharmony_ci * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
448c2ecf20Sopenharmony_ci * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
458c2ecf20Sopenharmony_ci * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
468c2ecf20Sopenharmony_ci * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
478c2ecf20Sopenharmony_ci *
488c2ecf20Sopenharmony_ci */
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci/*
518c2ecf20Sopenharmony_ci * This header file is for OPA-specific definitions which are
528c2ecf20Sopenharmony_ci * required by the HFI driver, and which aren't yet in the Linux
538c2ecf20Sopenharmony_ci * IB core. We'll collect these all here, then merge them into
548c2ecf20Sopenharmony_ci * the kernel when that's convenient.
558c2ecf20Sopenharmony_ci */
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci/* OPA SMA attribute IDs */
588c2ecf20Sopenharmony_ci#define OPA_ATTRIB_ID_CONGESTION_INFO		cpu_to_be16(0x008b)
598c2ecf20Sopenharmony_ci#define OPA_ATTRIB_ID_HFI_CONGESTION_LOG	cpu_to_be16(0x008f)
608c2ecf20Sopenharmony_ci#define OPA_ATTRIB_ID_HFI_CONGESTION_SETTING	cpu_to_be16(0x0090)
618c2ecf20Sopenharmony_ci#define OPA_ATTRIB_ID_CONGESTION_CONTROL_TABLE	cpu_to_be16(0x0091)
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci/* OPA PMA attribute IDs */
648c2ecf20Sopenharmony_ci#define OPA_PM_ATTRIB_ID_PORT_STATUS		cpu_to_be16(0x0040)
658c2ecf20Sopenharmony_ci#define OPA_PM_ATTRIB_ID_CLEAR_PORT_STATUS	cpu_to_be16(0x0041)
668c2ecf20Sopenharmony_ci#define OPA_PM_ATTRIB_ID_DATA_PORT_COUNTERS	cpu_to_be16(0x0042)
678c2ecf20Sopenharmony_ci#define OPA_PM_ATTRIB_ID_ERROR_PORT_COUNTERS	cpu_to_be16(0x0043)
688c2ecf20Sopenharmony_ci#define OPA_PM_ATTRIB_ID_ERROR_INFO		cpu_to_be16(0x0044)
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ci/* OPA status codes */
718c2ecf20Sopenharmony_ci#define OPA_PM_STATUS_REQUEST_TOO_LARGE		cpu_to_be16(0x100)
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_cistatic inline u8 port_states_to_logical_state(struct opa_port_states *ps)
748c2ecf20Sopenharmony_ci{
758c2ecf20Sopenharmony_ci	return ps->portphysstate_portstate & OPA_PI_MASK_PORT_STATE;
768c2ecf20Sopenharmony_ci}
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_cistatic inline u8 port_states_to_phys_state(struct opa_port_states *ps)
798c2ecf20Sopenharmony_ci{
808c2ecf20Sopenharmony_ci	return ((ps->portphysstate_portstate &
818c2ecf20Sopenharmony_ci		  OPA_PI_MASK_PORT_PHYSICAL_STATE) >> 4) & 0xf;
828c2ecf20Sopenharmony_ci}
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci/*
858c2ecf20Sopenharmony_ci * OPA port physical states
868c2ecf20Sopenharmony_ci * IB Volume 1, Table 146 PortInfo/IB Volume 2 Section 5.4.2(1) PortPhysState
878c2ecf20Sopenharmony_ci * values are the same in OmniPath Architecture. OPA leverages some of the same
888c2ecf20Sopenharmony_ci * concepts as InfiniBand, but has a few other states as well.
898c2ecf20Sopenharmony_ci *
908c2ecf20Sopenharmony_ci * When writing, only values 0-3 are valid, other values are ignored.
918c2ecf20Sopenharmony_ci * When reading, 0 is reserved.
928c2ecf20Sopenharmony_ci *
938c2ecf20Sopenharmony_ci * Returned by the ibphys_portstate() routine.
948c2ecf20Sopenharmony_ci */
958c2ecf20Sopenharmony_cienum opa_port_phys_state {
968c2ecf20Sopenharmony_ci	/* Values 0-7 have the same meaning in OPA as in InfiniBand. */
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ci	IB_PORTPHYSSTATE_NOP = 0,
998c2ecf20Sopenharmony_ci	/* 1 is reserved */
1008c2ecf20Sopenharmony_ci	IB_PORTPHYSSTATE_POLLING = 2,
1018c2ecf20Sopenharmony_ci	IB_PORTPHYSSTATE_DISABLED = 3,
1028c2ecf20Sopenharmony_ci	IB_PORTPHYSSTATE_TRAINING = 4,
1038c2ecf20Sopenharmony_ci	IB_PORTPHYSSTATE_LINKUP = 5,
1048c2ecf20Sopenharmony_ci	IB_PORTPHYSSTATE_LINK_ERROR_RECOVERY = 6,
1058c2ecf20Sopenharmony_ci	IB_PORTPHYSSTATE_PHY_TEST = 7,
1068c2ecf20Sopenharmony_ci	/* 8 is reserved */
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ci	/*
1098c2ecf20Sopenharmony_ci	 * Offline: Port is quiet (transmitters disabled) due to lack of
1108c2ecf20Sopenharmony_ci	 * physical media, unsupported media, or transition between link up
1118c2ecf20Sopenharmony_ci	 * and next link up attempt
1128c2ecf20Sopenharmony_ci	 */
1138c2ecf20Sopenharmony_ci	OPA_PORTPHYSSTATE_OFFLINE = 9,
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_ci	/* 10 is reserved */
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ci	/*
1188c2ecf20Sopenharmony_ci	 * Phy_Test: Specific test patterns are transmitted, and receiver BER
1198c2ecf20Sopenharmony_ci	 * can be monitored. This facilitates signal integrity testing for the
1208c2ecf20Sopenharmony_ci	 * physical layer of the port.
1218c2ecf20Sopenharmony_ci	 */
1228c2ecf20Sopenharmony_ci	OPA_PORTPHYSSTATE_TEST = 11,
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_ci	OPA_PORTPHYSSTATE_MAX = 11,
1258c2ecf20Sopenharmony_ci	/* values 12-15 are reserved/ignored */
1268c2ecf20Sopenharmony_ci};
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci#endif /* _LINUX_H */
129