xref: /freebsd/sys/dev/mlx5/port.h (revision 89e0e3814e8ca205db7523f6ce6c63cebe4bfb0d)
1d9142151SHans Petter Selasky /*-
2a888087fSHans Petter Selasky  * Copyright (c) 2016-2021, Mellanox Technologies, Ltd.  All rights reserved.
3d9142151SHans Petter Selasky  *
4d9142151SHans Petter Selasky  * Redistribution and use in source and binary forms, with or without
5d9142151SHans Petter Selasky  * modification, are permitted provided that the following conditions
6d9142151SHans Petter Selasky  * are met:
7d9142151SHans Petter Selasky  * 1. Redistributions of source code must retain the above copyright
8d9142151SHans Petter Selasky  *    notice, this list of conditions and the following disclaimer.
9d9142151SHans Petter Selasky  * 2. Redistributions in binary form must reproduce the above copyright
10d9142151SHans Petter Selasky  *    notice, this list of conditions and the following disclaimer in the
11d9142151SHans Petter Selasky  *    documentation and/or other materials provided with the distribution.
12d9142151SHans Petter Selasky  *
13d9142151SHans Petter Selasky  * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS `AS IS' AND
14d9142151SHans Petter Selasky  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15d9142151SHans Petter Selasky  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16d9142151SHans Petter Selasky  * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
17d9142151SHans Petter Selasky  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18d9142151SHans Petter Selasky  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19d9142151SHans Petter Selasky  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20d9142151SHans Petter Selasky  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21d9142151SHans Petter Selasky  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22d9142151SHans Petter Selasky  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23d9142151SHans Petter Selasky  * SUCH DAMAGE.
24d9142151SHans Petter Selasky  */
25d9142151SHans Petter Selasky 
26d9142151SHans Petter Selasky #ifndef __MLX5_PORT_H__
27d9142151SHans Petter Selasky #define	__MLX5_PORT_H__
28d9142151SHans Petter Selasky 
29d9142151SHans Petter Selasky #include <dev/mlx5/driver.h>
30d9142151SHans Petter Selasky 
31d9142151SHans Petter Selasky enum mlx5_beacon_duration {
32d9142151SHans Petter Selasky 	MLX5_BEACON_DURATION_OFF = 0x0,
33d9142151SHans Petter Selasky 	MLX5_BEACON_DURATION_INF = 0xffff,
34d9142151SHans Petter Selasky };
35d9142151SHans Petter Selasky 
36d9142151SHans Petter Selasky enum mlx5_module_id {
37d9142151SHans Petter Selasky 	MLX5_MODULE_ID_SFP              = 0x3,
38d9142151SHans Petter Selasky 	MLX5_MODULE_ID_QSFP             = 0xC,
39d9142151SHans Petter Selasky 	MLX5_MODULE_ID_QSFP_PLUS        = 0xD,
40d9142151SHans Petter Selasky 	MLX5_MODULE_ID_QSFP28           = 0x11,
41d9142151SHans Petter Selasky };
42d9142151SHans Petter Selasky 
43d9142151SHans Petter Selasky enum mlx5_an_status {
44d9142151SHans Petter Selasky 	MLX5_AN_UNAVAILABLE = 0,
45d9142151SHans Petter Selasky 	MLX5_AN_COMPLETE    = 1,
46d9142151SHans Petter Selasky 	MLX5_AN_FAILED      = 2,
47d9142151SHans Petter Selasky 	MLX5_AN_LINK_UP     = 3,
48d9142151SHans Petter Selasky 	MLX5_AN_LINK_DOWN   = 4,
49d9142151SHans Petter Selasky };
50d9142151SHans Petter Selasky 
51048ddb58SHans Petter Selasky /* EEPROM I2C Addresses */
52048ddb58SHans Petter Selasky #define	MLX5_I2C_ADDR_LOW			0x50
53048ddb58SHans Petter Selasky #define	MLX5_I2C_ADDR_HIGH			0x51
54048ddb58SHans Petter Selasky #define	MLX5_EEPROM_PAGE_LENGTH			256
55d9142151SHans Petter Selasky #define	MLX5_EEPROM_MAX_BYTES			32
56d9142151SHans Petter Selasky #define	MLX5_EEPROM_IDENTIFIER_BYTE_MASK	0x000000ff
57d9142151SHans Petter Selasky #define	MLX5_EEPROM_REVISION_ID_BYTE_MASK       0x0000ff00
58d9142151SHans Petter Selasky #define	MLX5_EEPROM_PAGE_3_VALID_BIT_MASK       0x00040000
59048ddb58SHans Petter Selasky #define	MLX5_EEPROM_LOW_PAGE			0x0
60048ddb58SHans Petter Selasky #define	MLX5_EEPROM_HIGH_PAGE			0x3
61048ddb58SHans Petter Selasky #define	MLX5_EEPROM_HIGH_PAGE_OFFSET		128
62048ddb58SHans Petter Selasky #define	MLX5_EEPROM_INFO_BYTES			0x3
63048ddb58SHans Petter Selasky 
64048ddb58SHans Petter Selasky /* EEPROM Standards for plug in modules */
65048ddb58SHans Petter Selasky #ifndef MLX5_ETH_MODULE_SFF_8472
66048ddb58SHans Petter Selasky #define	MLX5_ETH_MODULE_SFF_8472	0x1
67048ddb58SHans Petter Selasky #define	MLX5_ETH_MODULE_SFF_8472_LEN	128
68048ddb58SHans Petter Selasky #endif
69048ddb58SHans Petter Selasky 
70048ddb58SHans Petter Selasky #ifndef MLX5_ETH_MODULE_SFF_8636
71048ddb58SHans Petter Selasky #define	MLX5_ETH_MODULE_SFF_8636	0x2
72048ddb58SHans Petter Selasky #define	MLX5_ETH_MODULE_SFF_8636_LEN	256
73048ddb58SHans Petter Selasky #endif
74048ddb58SHans Petter Selasky 
75048ddb58SHans Petter Selasky #ifndef MLX5_ETH_MODULE_SFF_8436
76048ddb58SHans Petter Selasky #define	MLX5_ETH_MODULE_SFF_8436	0x3
77048ddb58SHans Petter Selasky #define	MLX5_ETH_MODULE_SFF_8436_LEN	256
78048ddb58SHans Petter Selasky #endif
79d9142151SHans Petter Selasky 
80ac87880aSHans Petter Selasky enum mlx5e_link_speed {
81d9142151SHans Petter Selasky 	MLX5E_1000BASE_CX_SGMII	 = 0,
82d9142151SHans Petter Selasky 	MLX5E_1000BASE_KX	 = 1,
83d9142151SHans Petter Selasky 	MLX5E_10GBASE_CX4	 = 2,
84d9142151SHans Petter Selasky 	MLX5E_10GBASE_KX4	 = 3,
85d9142151SHans Petter Selasky 	MLX5E_10GBASE_KR	 = 4,
86d9142151SHans Petter Selasky 	MLX5E_20GBASE_KR2	 = 5,
87d9142151SHans Petter Selasky 	MLX5E_40GBASE_CR4	 = 6,
88d9142151SHans Petter Selasky 	MLX5E_40GBASE_KR4	 = 7,
89d9142151SHans Petter Selasky 	MLX5E_56GBASE_R4	 = 8,
90d9142151SHans Petter Selasky 	MLX5E_10GBASE_CR	 = 12,
91d9142151SHans Petter Selasky 	MLX5E_10GBASE_SR	 = 13,
92ac87880aSHans Petter Selasky 	MLX5E_10GBASE_ER_LR	 = 14,
93d9142151SHans Petter Selasky 	MLX5E_40GBASE_SR4	 = 15,
94ac87880aSHans Petter Selasky 	MLX5E_40GBASE_LR4_ER4	 = 16,
95d9142151SHans Petter Selasky 	MLX5E_50GBASE_SR2	 = 18,
9696dad2b7SKonstantin Belousov 	MLX5E_50GBASE_KR4	 = 19,
97d9142151SHans Petter Selasky 	MLX5E_100GBASE_CR4	 = 20,
98d9142151SHans Petter Selasky 	MLX5E_100GBASE_SR4	 = 21,
99d9142151SHans Petter Selasky 	MLX5E_100GBASE_KR4	 = 22,
100d9142151SHans Petter Selasky 	MLX5E_100GBASE_LR4	 = 23,
101d9142151SHans Petter Selasky 	MLX5E_100BASE_TX	 = 24,
102d9142151SHans Petter Selasky 	MLX5E_1000BASE_T	 = 25,
103d9142151SHans Petter Selasky 	MLX5E_10GBASE_T		 = 26,
104d9142151SHans Petter Selasky 	MLX5E_25GBASE_CR	 = 27,
105d9142151SHans Petter Selasky 	MLX5E_25GBASE_KR	 = 28,
106d9142151SHans Petter Selasky 	MLX5E_25GBASE_SR	 = 29,
107d9142151SHans Petter Selasky 	MLX5E_50GBASE_CR2	 = 30,
108d9142151SHans Petter Selasky 	MLX5E_50GBASE_KR2	 = 31,
109a888087fSHans Petter Selasky 	MLX5E_LINK_SPEEDS_NUMBER = 32,
110ac87880aSHans Petter Selasky };
111ac87880aSHans Petter Selasky 
112ac87880aSHans Petter Selasky enum mlx5e_ext_link_speed {
113ac87880aSHans Petter Selasky 	MLX5E_SGMII_100M			= 0,
114ac87880aSHans Petter Selasky 	MLX5E_1000BASE_X_SGMII			= 1,
115ac87880aSHans Petter Selasky 	MLX5E_5GBASE_R				= 3,
116ac87880aSHans Petter Selasky 	MLX5E_10GBASE_XFI_XAUI_1		= 4,
117ac87880aSHans Petter Selasky 	MLX5E_40GBASE_XLAUI_4_XLPPI_4		= 5,
118ac87880aSHans Petter Selasky 	MLX5E_25GAUI_1_25GBASE_CR_KR		= 6,
119ac87880aSHans Petter Selasky 	MLX5E_50GAUI_2_LAUI_2_50GBASE_CR2_KR2	= 7,
120ac87880aSHans Petter Selasky 	MLX5E_50GAUI_1_LAUI_1_50GBASE_CR_KR	= 8,
121ac87880aSHans Petter Selasky 	MLX5E_CAUI_4_100GBASE_CR4_KR4		= 9,
122ac87880aSHans Petter Selasky 	MLX5E_100GAUI_2_100GBASE_CR2_KR2	= 10,
123a888087fSHans Petter Selasky 	MLX5E_100GAUI_1_100GBASE_CR_KR		= 11,
124ac87880aSHans Petter Selasky 	MLX5E_200GAUI_4_200GBASE_CR4_KR4	= 12,
125a888087fSHans Petter Selasky 	MLX5E_200GAUI_2_200GBASE_CR2_KR2	= 13,
126ac87880aSHans Petter Selasky 	MLX5E_400GAUI_8				= 15,
127a888087fSHans Petter Selasky 	MLX5E_400GAUI_4_400GBASE_CR4_KR4	= 16,
128a888087fSHans Petter Selasky 	MLX5E_EXT_LINK_SPEEDS_NUMBER		= 32,
129ac87880aSHans Petter Selasky };
130ac87880aSHans Petter Selasky 
131*89e0e381SAriel Ehrenberg enum mlx5e_connector_type {
132*89e0e381SAriel Ehrenberg 	MLX5E_PORT_UNKNOWN			= 0,
133*89e0e381SAriel Ehrenberg 	MLX5E_PORT_NONE				= 1,
134*89e0e381SAriel Ehrenberg 	MLX5E_PORT_TP				= 2,
135*89e0e381SAriel Ehrenberg 	MLX5E_PORT_AUI				= 3,
136*89e0e381SAriel Ehrenberg 	MLX5E_PORT_BNC				= 4,
137*89e0e381SAriel Ehrenberg 	MLX5E_PORT_MII				= 5,
138*89e0e381SAriel Ehrenberg 	MLX5E_PORT_FIBRE			= 6,
139*89e0e381SAriel Ehrenberg 	MLX5E_PORT_DA				= 7,
140*89e0e381SAriel Ehrenberg 	MLX5E_PORT_OTHER			= 8,
141*89e0e381SAriel Ehrenberg 	MLX5E_CONNECTOR_TYPE_NUMBER = 9,
142*89e0e381SAriel Ehrenberg };
143*89e0e381SAriel Ehrenberg 
144a888087fSHans Petter Selasky enum mlx5e_cable_type {
145a888087fSHans Petter Selasky 	MLX5E_CABLE_TYPE_UNKNOWN		= 0,
146a888087fSHans Petter Selasky 	MLX5E_CABLE_TYPE_ACTIVE_CABLE		= 1,
147a888087fSHans Petter Selasky 	MLX5E_CABLE_TYPE_OPTICAL_MODULE 	= 2,
148a888087fSHans Petter Selasky 	MLX5E_CABLE_TYPE_PASSIVE_COPPER		= 3,
149a888087fSHans Petter Selasky 	MLX5E_CABLE_TYPE_CABLE_UNPLUGGED	= 4,
150a888087fSHans Petter Selasky 	MLX5E_CABLE_TYPE_TWISTED_PAIR		= 5,
151a888087fSHans Petter Selasky 	MLX5E_CABLE_TYPE_NUMBER			= 8,
152d9142151SHans Petter Selasky };
153d9142151SHans Petter Selasky 
154ed0cee0bSHans Petter Selasky enum mlx5_qpts_trust_state {
155ed0cee0bSHans Petter Selasky 	MLX5_QPTS_TRUST_PCP = 1,
156ed0cee0bSHans Petter Selasky 	MLX5_QPTS_TRUST_DSCP = 2,
157ed0cee0bSHans Petter Selasky 	MLX5_QPTS_TRUST_BOTH = 3,
158ed0cee0bSHans Petter Selasky };
159c28ef249SHans Petter Selasky struct mlx5e_port_eth_proto {
160c28ef249SHans Petter Selasky 	u32 cap;
161c28ef249SHans Petter Selasky 	u32 admin;
162c28ef249SHans Petter Selasky 	u32 oper;
163c28ef249SHans Petter Selasky };
164c28ef249SHans Petter Selasky 
165c28ef249SHans Petter Selasky #ifndef SPEED_40000
166c28ef249SHans Petter Selasky #define SPEED_40000 40000
167c28ef249SHans Petter Selasky #endif
168ed0cee0bSHans Petter Selasky 
169d9142151SHans Petter Selasky #define	MLX5E_PROT_MASK(link_mode) (1 << (link_mode))
170d9142151SHans Petter Selasky 
171d9142151SHans Petter Selasky #define	PORT_MODULE_EVENT_MODULE_STATUS_MASK 0xF
172d9142151SHans Petter Selasky #define	PORT_MODULE_EVENT_ERROR_TYPE_MASK 0xF
173d9142151SHans Petter Selasky 
174ac87880aSHans Petter Selasky #define MLX5_GET_ETH_PROTO(reg, out, ext, field)    \
175ac87880aSHans Petter Selasky     ((ext) ? MLX5_GET(reg, out, ext_##field) :        \
176ac87880aSHans Petter Selasky     MLX5_GET(reg, out, field))
177ac87880aSHans Petter Selasky 
178d9142151SHans Petter Selasky int mlx5_set_port_caps(struct mlx5_core_dev *dev, u8 port_num, u32 caps);
179d9142151SHans Petter Selasky int mlx5_query_port_ptys(struct mlx5_core_dev *dev, u32 *ptys,
180d9142151SHans Petter Selasky 			 int ptys_size, int proto_mask, u8 local_port);
181d9142151SHans Petter Selasky int mlx5_query_port_proto_cap(struct mlx5_core_dev *dev,
182d9142151SHans Petter Selasky 			      u32 *proto_cap, int proto_mask);
183d9142151SHans Petter Selasky int mlx5_query_port_autoneg(struct mlx5_core_dev *dev, int proto_mask,
184d9142151SHans Petter Selasky 			    u8 *an_disable_cap, u8 *an_disable_status);
185d9142151SHans Petter Selasky int mlx5_set_port_autoneg(struct mlx5_core_dev *dev, bool disable,
186d9142151SHans Petter Selasky 			  u32 eth_proto_admin, int proto_mask);
187d9142151SHans Petter Selasky int mlx5_query_port_proto_admin(struct mlx5_core_dev *dev,
188d9142151SHans Petter Selasky 				u32 *proto_admin, int proto_mask);
189d9142151SHans Petter Selasky int mlx5_query_port_eth_proto_oper(struct mlx5_core_dev *dev,
190d9142151SHans Petter Selasky 				   u32 *proto_oper, u8 local_port);
191d9142151SHans Petter Selasky int mlx5_set_port_proto(struct mlx5_core_dev *dev, u32 proto_admin,
192ac87880aSHans Petter Selasky 			int proto_mask, bool ext);
193d9142151SHans Petter Selasky int mlx5_set_port_status(struct mlx5_core_dev *dev,
194d9142151SHans Petter Selasky 			 enum mlx5_port_status status);
195d9142151SHans Petter Selasky int mlx5_query_port_status(struct mlx5_core_dev *dev, u8 *status);
196d9142151SHans Petter Selasky int mlx5_query_port_admin_status(struct mlx5_core_dev *dev,
197d9142151SHans Petter Selasky 				 enum mlx5_port_status *status);
19810b08045SHans Petter Selasky int mlx5_set_port_pause_and_pfc(struct mlx5_core_dev *dev, u32 port,
19910b08045SHans Petter Selasky 				u8 rx_pause, u8 tx_pause,
20010b08045SHans Petter Selasky 				u8 pfc_en_rx, u8 pfc_en_tx);
201d9142151SHans Petter Selasky int mlx5_query_port_pause(struct mlx5_core_dev *dev, u32 port,
202d9142151SHans Petter Selasky 			  u32 *rx_pause, u32 *tx_pause);
203d9142151SHans Petter Selasky int mlx5_query_port_pfc(struct mlx5_core_dev *dev, u8 *pfc_en_tx, u8 *pfc_en_rx);
204d9142151SHans Petter Selasky 
205d9142151SHans Petter Selasky int mlx5_set_port_mtu(struct mlx5_core_dev *dev, int mtu);
206d9142151SHans Petter Selasky int mlx5_query_port_max_mtu(struct mlx5_core_dev *dev, int *max_mtu);
207d9142151SHans Petter Selasky int mlx5_query_port_oper_mtu(struct mlx5_core_dev *dev, int *oper_mtu);
208d9142151SHans Petter Selasky 
209d9142151SHans Petter Selasky unsigned int mlx5_query_module_status(struct mlx5_core_dev *dev, int module_num);
210d9142151SHans Petter Selasky int mlx5_query_module_num(struct mlx5_core_dev *dev, int *module_num);
211d9142151SHans Petter Selasky int mlx5_query_eeprom(struct mlx5_core_dev *dev, int i2c_addr, int page_num,
212d9142151SHans Petter Selasky 		      int device_addr, int size, int module_num, u32 *data,
213d9142151SHans Petter Selasky 		      int *size_read);
214d9142151SHans Petter Selasky 
215cfc9c386SHans Petter Selasky int mlx5_max_tc(struct mlx5_core_dev *mdev);
216cfc9c386SHans Petter Selasky int mlx5_query_port_tc_rate_limit(struct mlx5_core_dev *mdev,
217cfc9c386SHans Petter Selasky 				   u8 *max_bw_value,
218cfc9c386SHans Petter Selasky 				   u8 *max_bw_units);
219cfc9c386SHans Petter Selasky int mlx5_modify_port_tc_rate_limit(struct mlx5_core_dev *mdev,
220cfc9c386SHans Petter Selasky 				   const u8 *max_bw_value,
221cfc9c386SHans Petter Selasky 				   const u8 *max_bw_units);
2222e9c3a4fSHans Petter Selasky int mlx5_query_port_prio_tc(struct mlx5_core_dev *mdev,
2232e9c3a4fSHans Petter Selasky 			    u8 prio, u8 *tc);
2242e9c3a4fSHans Petter Selasky int mlx5_set_port_prio_tc(struct mlx5_core_dev *mdev, int prio_index,
2252e9c3a4fSHans Petter Selasky 			  const u8 prio_tc);
226e870c0abSSlava Shwartsman int mlx5_set_port_tc_group(struct mlx5_core_dev *mdev, const u8 *tc_group);
227e870c0abSSlava Shwartsman int mlx5_query_port_tc_group(struct mlx5_core_dev *mdev,
228e870c0abSSlava Shwartsman 			     u8 tc, u8 *tc_group);
229e870c0abSSlava Shwartsman int mlx5_set_port_tc_bw_alloc(struct mlx5_core_dev *mdev, const u8 *tc_bw);
230e870c0abSSlava Shwartsman int mlx5_query_port_tc_bw_alloc(struct mlx5_core_dev *mdev, u8 *bw_pct);
231e870c0abSSlava Shwartsman 
232ed0cee0bSHans Petter Selasky int mlx5_set_trust_state(struct mlx5_core_dev *mdev, u8 trust_state);
233ed0cee0bSHans Petter Selasky int mlx5_query_trust_state(struct mlx5_core_dev *mdev, u8 *trust_state);
234ed0cee0bSHans Petter Selasky 
235ed0cee0bSHans Petter Selasky #define	MLX5_MAX_SUPPORTED_DSCP 64
236ed0cee0bSHans Petter Selasky int mlx5_set_dscp2prio(struct mlx5_core_dev *mdev, const u8 *dscp2prio);
237ed0cee0bSHans Petter Selasky int mlx5_query_dscp2prio(struct mlx5_core_dev *mdev, u8 *dscp2prio);
238ed0cee0bSHans Petter Selasky 
23942390bb8SSlava Shwartsman int mlx5_query_pddr_range_info(struct mlx5_core_dev *mdev, u8 local_port, u8 *is_er_type);
240a888087fSHans Petter Selasky int mlx5_query_pddr_cable_type(struct mlx5_core_dev *mdev, u8 local_port, u8 *cable_type);
24142390bb8SSlava Shwartsman 
242c28ef249SHans Petter Selasky u32 mlx5e_port_ptys2speed(struct mlx5_core_dev *mdev, u32 eth_proto_oper);
243c28ef249SHans Petter Selasky int mlx5e_port_linkspeed(struct mlx5_core_dev *mdev, u32 *speed);
244c28ef249SHans Petter Selasky int mlx5_port_query_eth_proto(struct mlx5_core_dev *dev, u8 port, bool ext,
245c28ef249SHans Petter Selasky 			      struct mlx5e_port_eth_proto *eproto);
246c28ef249SHans Petter Selasky 
247c28ef249SHans Petter Selasky int mlx5e_port_query_pbmc(struct mlx5_core_dev *mdev, void *out);
248c28ef249SHans Petter Selasky int mlx5e_port_set_pbmc(struct mlx5_core_dev *mdev, void *in);
249c28ef249SHans Petter Selasky int mlx5e_port_query_priority2buffer(struct mlx5_core_dev *mdev, u8 *buffer);
250c28ef249SHans Petter Selasky int mlx5e_port_set_priority2buffer(struct mlx5_core_dev *mdev, u8 *buffer);
251c28ef249SHans Petter Selasky 
252d9142151SHans Petter Selasky #endif /* __MLX5_PORT_H__ */
253