162306a36Sopenharmony_ci/*
262306a36Sopenharmony_ci * Copyright (c) 2016, Mellanox Technologies. All rights reserved.
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci * This software is available to you under a choice of one of two
562306a36Sopenharmony_ci * licenses.  You may choose to be licensed under the terms of the GNU
662306a36Sopenharmony_ci * General Public License (GPL) Version 2, available from the file
762306a36Sopenharmony_ci * COPYING in the main directory of this source tree, or the
862306a36Sopenharmony_ci * OpenIB.org BSD license below:
962306a36Sopenharmony_ci *
1062306a36Sopenharmony_ci *     Redistribution and use in source and binary forms, with or
1162306a36Sopenharmony_ci *     without modification, are permitted provided that the following
1262306a36Sopenharmony_ci *     conditions are met:
1362306a36Sopenharmony_ci *
1462306a36Sopenharmony_ci *      - Redistributions of source code must retain the above
1562306a36Sopenharmony_ci *        copyright notice, this list of conditions and the following
1662306a36Sopenharmony_ci *        disclaimer.
1762306a36Sopenharmony_ci *
1862306a36Sopenharmony_ci *      - Redistributions in binary form must reproduce the above
1962306a36Sopenharmony_ci *        copyright notice, this list of conditions and the following
2062306a36Sopenharmony_ci *        disclaimer in the documentation and/or other materials
2162306a36Sopenharmony_ci *        provided with the distribution.
2262306a36Sopenharmony_ci *
2362306a36Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
2462306a36Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2562306a36Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
2662306a36Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
2762306a36Sopenharmony_ci * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
2862306a36Sopenharmony_ci * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
2962306a36Sopenharmony_ci * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3062306a36Sopenharmony_ci * SOFTWARE.
3162306a36Sopenharmony_ci */
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_ci#ifndef __MLX5_PORT_H__
3462306a36Sopenharmony_ci#define __MLX5_PORT_H__
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_ci#include <linux/mlx5/driver.h>
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_cienum mlx5_beacon_duration {
3962306a36Sopenharmony_ci	MLX5_BEACON_DURATION_OFF = 0x0,
4062306a36Sopenharmony_ci	MLX5_BEACON_DURATION_INF = 0xffff,
4162306a36Sopenharmony_ci};
4262306a36Sopenharmony_ci
4362306a36Sopenharmony_cienum mlx5_module_id {
4462306a36Sopenharmony_ci	MLX5_MODULE_ID_SFP              = 0x3,
4562306a36Sopenharmony_ci	MLX5_MODULE_ID_QSFP             = 0xC,
4662306a36Sopenharmony_ci	MLX5_MODULE_ID_QSFP_PLUS        = 0xD,
4762306a36Sopenharmony_ci	MLX5_MODULE_ID_QSFP28           = 0x11,
4862306a36Sopenharmony_ci	MLX5_MODULE_ID_DSFP		= 0x1B,
4962306a36Sopenharmony_ci};
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_cienum mlx5_an_status {
5262306a36Sopenharmony_ci	MLX5_AN_UNAVAILABLE = 0,
5362306a36Sopenharmony_ci	MLX5_AN_COMPLETE    = 1,
5462306a36Sopenharmony_ci	MLX5_AN_FAILED      = 2,
5562306a36Sopenharmony_ci	MLX5_AN_LINK_UP     = 3,
5662306a36Sopenharmony_ci	MLX5_AN_LINK_DOWN   = 4,
5762306a36Sopenharmony_ci};
5862306a36Sopenharmony_ci
5962306a36Sopenharmony_ci#define MLX5_I2C_ADDR_LOW		0x50
6062306a36Sopenharmony_ci#define MLX5_I2C_ADDR_HIGH		0x51
6162306a36Sopenharmony_ci#define MLX5_EEPROM_PAGE_LENGTH		256
6262306a36Sopenharmony_ci#define MLX5_EEPROM_HIGH_PAGE_LENGTH	128
6362306a36Sopenharmony_ci
6462306a36Sopenharmony_cistruct mlx5_module_eeprom_query_params {
6562306a36Sopenharmony_ci	u16 size;
6662306a36Sopenharmony_ci	u16 offset;
6762306a36Sopenharmony_ci	u16 i2c_address;
6862306a36Sopenharmony_ci	u32 page;
6962306a36Sopenharmony_ci	u32 bank;
7062306a36Sopenharmony_ci	u32 module_number;
7162306a36Sopenharmony_ci};
7262306a36Sopenharmony_ci
7362306a36Sopenharmony_cienum mlx5e_link_mode {
7462306a36Sopenharmony_ci	MLX5E_1000BASE_CX_SGMII	 = 0,
7562306a36Sopenharmony_ci	MLX5E_1000BASE_KX	 = 1,
7662306a36Sopenharmony_ci	MLX5E_10GBASE_CX4	 = 2,
7762306a36Sopenharmony_ci	MLX5E_10GBASE_KX4	 = 3,
7862306a36Sopenharmony_ci	MLX5E_10GBASE_KR	 = 4,
7962306a36Sopenharmony_ci	MLX5E_20GBASE_KR2	 = 5,
8062306a36Sopenharmony_ci	MLX5E_40GBASE_CR4	 = 6,
8162306a36Sopenharmony_ci	MLX5E_40GBASE_KR4	 = 7,
8262306a36Sopenharmony_ci	MLX5E_56GBASE_R4	 = 8,
8362306a36Sopenharmony_ci	MLX5E_10GBASE_CR	 = 12,
8462306a36Sopenharmony_ci	MLX5E_10GBASE_SR	 = 13,
8562306a36Sopenharmony_ci	MLX5E_10GBASE_ER	 = 14,
8662306a36Sopenharmony_ci	MLX5E_40GBASE_SR4	 = 15,
8762306a36Sopenharmony_ci	MLX5E_40GBASE_LR4	 = 16,
8862306a36Sopenharmony_ci	MLX5E_50GBASE_SR2	 = 18,
8962306a36Sopenharmony_ci	MLX5E_100GBASE_CR4	 = 20,
9062306a36Sopenharmony_ci	MLX5E_100GBASE_SR4	 = 21,
9162306a36Sopenharmony_ci	MLX5E_100GBASE_KR4	 = 22,
9262306a36Sopenharmony_ci	MLX5E_100GBASE_LR4	 = 23,
9362306a36Sopenharmony_ci	MLX5E_100BASE_TX	 = 24,
9462306a36Sopenharmony_ci	MLX5E_1000BASE_T	 = 25,
9562306a36Sopenharmony_ci	MLX5E_10GBASE_T		 = 26,
9662306a36Sopenharmony_ci	MLX5E_25GBASE_CR	 = 27,
9762306a36Sopenharmony_ci	MLX5E_25GBASE_KR	 = 28,
9862306a36Sopenharmony_ci	MLX5E_25GBASE_SR	 = 29,
9962306a36Sopenharmony_ci	MLX5E_50GBASE_CR2	 = 30,
10062306a36Sopenharmony_ci	MLX5E_50GBASE_KR2	 = 31,
10162306a36Sopenharmony_ci	MLX5E_LINK_MODES_NUMBER,
10262306a36Sopenharmony_ci};
10362306a36Sopenharmony_ci
10462306a36Sopenharmony_cienum mlx5e_ext_link_mode {
10562306a36Sopenharmony_ci	MLX5E_SGMII_100M			= 0,
10662306a36Sopenharmony_ci	MLX5E_1000BASE_X_SGMII			= 1,
10762306a36Sopenharmony_ci	MLX5E_5GBASE_R				= 3,
10862306a36Sopenharmony_ci	MLX5E_10GBASE_XFI_XAUI_1		= 4,
10962306a36Sopenharmony_ci	MLX5E_40GBASE_XLAUI_4_XLPPI_4		= 5,
11062306a36Sopenharmony_ci	MLX5E_25GAUI_1_25GBASE_CR_KR		= 6,
11162306a36Sopenharmony_ci	MLX5E_50GAUI_2_LAUI_2_50GBASE_CR2_KR2	= 7,
11262306a36Sopenharmony_ci	MLX5E_50GAUI_1_LAUI_1_50GBASE_CR_KR	= 8,
11362306a36Sopenharmony_ci	MLX5E_CAUI_4_100GBASE_CR4_KR4		= 9,
11462306a36Sopenharmony_ci	MLX5E_100GAUI_2_100GBASE_CR2_KR2	= 10,
11562306a36Sopenharmony_ci	MLX5E_100GAUI_1_100GBASE_CR_KR		= 11,
11662306a36Sopenharmony_ci	MLX5E_200GAUI_4_200GBASE_CR4_KR4	= 12,
11762306a36Sopenharmony_ci	MLX5E_200GAUI_2_200GBASE_CR2_KR2	= 13,
11862306a36Sopenharmony_ci	MLX5E_400GAUI_8				= 15,
11962306a36Sopenharmony_ci	MLX5E_400GAUI_4_400GBASE_CR4_KR4	= 16,
12062306a36Sopenharmony_ci	MLX5E_EXT_LINK_MODES_NUMBER,
12162306a36Sopenharmony_ci};
12262306a36Sopenharmony_ci
12362306a36Sopenharmony_cienum mlx5e_connector_type {
12462306a36Sopenharmony_ci	MLX5E_PORT_UNKNOWN	= 0,
12562306a36Sopenharmony_ci	MLX5E_PORT_NONE			= 1,
12662306a36Sopenharmony_ci	MLX5E_PORT_TP			= 2,
12762306a36Sopenharmony_ci	MLX5E_PORT_AUI			= 3,
12862306a36Sopenharmony_ci	MLX5E_PORT_BNC			= 4,
12962306a36Sopenharmony_ci	MLX5E_PORT_MII			= 5,
13062306a36Sopenharmony_ci	MLX5E_PORT_FIBRE		= 6,
13162306a36Sopenharmony_ci	MLX5E_PORT_DA			= 7,
13262306a36Sopenharmony_ci	MLX5E_PORT_OTHER		= 8,
13362306a36Sopenharmony_ci	MLX5E_CONNECTOR_TYPE_NUMBER,
13462306a36Sopenharmony_ci};
13562306a36Sopenharmony_ci
13662306a36Sopenharmony_cienum mlx5_ptys_width {
13762306a36Sopenharmony_ci	MLX5_PTYS_WIDTH_1X	= 1 << 0,
13862306a36Sopenharmony_ci	MLX5_PTYS_WIDTH_2X	= 1 << 1,
13962306a36Sopenharmony_ci	MLX5_PTYS_WIDTH_4X	= 1 << 2,
14062306a36Sopenharmony_ci	MLX5_PTYS_WIDTH_8X	= 1 << 3,
14162306a36Sopenharmony_ci	MLX5_PTYS_WIDTH_12X	= 1 << 4,
14262306a36Sopenharmony_ci};
14362306a36Sopenharmony_ci
14462306a36Sopenharmony_cistruct mlx5_port_eth_proto {
14562306a36Sopenharmony_ci	u32 cap;
14662306a36Sopenharmony_ci	u32 admin;
14762306a36Sopenharmony_ci	u32 oper;
14862306a36Sopenharmony_ci};
14962306a36Sopenharmony_ci
15062306a36Sopenharmony_ci#define MLX5E_PROT_MASK(link_mode) (1U << link_mode)
15162306a36Sopenharmony_ci#define MLX5_GET_ETH_PROTO(reg, out, ext, field)	\
15262306a36Sopenharmony_ci	(ext ? MLX5_GET(reg, out, ext_##field) :	\
15362306a36Sopenharmony_ci	MLX5_GET(reg, out, field))
15462306a36Sopenharmony_ci
15562306a36Sopenharmony_ciint mlx5_set_port_caps(struct mlx5_core_dev *dev, u8 port_num, u32 caps);
15662306a36Sopenharmony_ciint mlx5_query_port_ptys(struct mlx5_core_dev *dev, u32 *ptys,
15762306a36Sopenharmony_ci			 int ptys_size, int proto_mask, u8 local_port);
15862306a36Sopenharmony_ci
15962306a36Sopenharmony_ciint mlx5_query_ib_port_oper(struct mlx5_core_dev *dev, u16 *link_width_oper,
16062306a36Sopenharmony_ci			    u16 *proto_oper, u8 local_port);
16162306a36Sopenharmony_civoid mlx5_toggle_port_link(struct mlx5_core_dev *dev);
16262306a36Sopenharmony_ciint mlx5_set_port_admin_status(struct mlx5_core_dev *dev,
16362306a36Sopenharmony_ci			       enum mlx5_port_status status);
16462306a36Sopenharmony_ciint mlx5_query_port_admin_status(struct mlx5_core_dev *dev,
16562306a36Sopenharmony_ci				 enum mlx5_port_status *status);
16662306a36Sopenharmony_ciint mlx5_set_port_beacon(struct mlx5_core_dev *dev, u16 beacon_duration);
16762306a36Sopenharmony_ci
16862306a36Sopenharmony_ciint mlx5_set_port_mtu(struct mlx5_core_dev *dev, u16 mtu, u8 port);
16962306a36Sopenharmony_civoid mlx5_query_port_max_mtu(struct mlx5_core_dev *dev, u16 *max_mtu, u8 port);
17062306a36Sopenharmony_civoid mlx5_query_port_oper_mtu(struct mlx5_core_dev *dev, u16 *oper_mtu,
17162306a36Sopenharmony_ci			      u8 port);
17262306a36Sopenharmony_ci
17362306a36Sopenharmony_ciint mlx5_query_port_vl_hw_cap(struct mlx5_core_dev *dev,
17462306a36Sopenharmony_ci			      u8 *vl_hw_cap, u8 local_port);
17562306a36Sopenharmony_ci
17662306a36Sopenharmony_ciint mlx5_set_port_pause(struct mlx5_core_dev *dev, u32 rx_pause, u32 tx_pause);
17762306a36Sopenharmony_ciint mlx5_query_port_pause(struct mlx5_core_dev *dev,
17862306a36Sopenharmony_ci			  u32 *rx_pause, u32 *tx_pause);
17962306a36Sopenharmony_ci
18062306a36Sopenharmony_ciint mlx5_set_port_pfc(struct mlx5_core_dev *dev, u8 pfc_en_tx, u8 pfc_en_rx);
18162306a36Sopenharmony_ciint mlx5_query_port_pfc(struct mlx5_core_dev *dev, u8 *pfc_en_tx,
18262306a36Sopenharmony_ci			u8 *pfc_en_rx);
18362306a36Sopenharmony_ci
18462306a36Sopenharmony_ciint mlx5_set_port_stall_watermark(struct mlx5_core_dev *dev,
18562306a36Sopenharmony_ci				  u16 stall_critical_watermark,
18662306a36Sopenharmony_ci				  u16 stall_minor_watermark);
18762306a36Sopenharmony_ciint mlx5_query_port_stall_watermark(struct mlx5_core_dev *dev,
18862306a36Sopenharmony_ci				    u16 *stall_critical_watermark, u16 *stall_minor_watermark);
18962306a36Sopenharmony_ci
19062306a36Sopenharmony_ciint mlx5_max_tc(struct mlx5_core_dev *mdev);
19162306a36Sopenharmony_ci
19262306a36Sopenharmony_ciint mlx5_set_port_prio_tc(struct mlx5_core_dev *mdev, u8 *prio_tc);
19362306a36Sopenharmony_ciint mlx5_query_port_prio_tc(struct mlx5_core_dev *mdev,
19462306a36Sopenharmony_ci			    u8 prio, u8 *tc);
19562306a36Sopenharmony_ciint mlx5_set_port_tc_group(struct mlx5_core_dev *mdev, u8 *tc_group);
19662306a36Sopenharmony_ciint mlx5_query_port_tc_group(struct mlx5_core_dev *mdev,
19762306a36Sopenharmony_ci			     u8 tc, u8 *tc_group);
19862306a36Sopenharmony_ciint mlx5_set_port_tc_bw_alloc(struct mlx5_core_dev *mdev, u8 *tc_bw);
19962306a36Sopenharmony_ciint mlx5_query_port_tc_bw_alloc(struct mlx5_core_dev *mdev,
20062306a36Sopenharmony_ci				u8 tc, u8 *bw_pct);
20162306a36Sopenharmony_ciint mlx5_modify_port_ets_rate_limit(struct mlx5_core_dev *mdev,
20262306a36Sopenharmony_ci				    u8 *max_bw_value,
20362306a36Sopenharmony_ci				    u8 *max_bw_unit);
20462306a36Sopenharmony_ciint mlx5_query_port_ets_rate_limit(struct mlx5_core_dev *mdev,
20562306a36Sopenharmony_ci				   u8 *max_bw_value,
20662306a36Sopenharmony_ci				   u8 *max_bw_unit);
20762306a36Sopenharmony_ciint mlx5_set_port_wol(struct mlx5_core_dev *mdev, u8 wol_mode);
20862306a36Sopenharmony_ciint mlx5_query_port_wol(struct mlx5_core_dev *mdev, u8 *wol_mode);
20962306a36Sopenharmony_ci
21062306a36Sopenharmony_ciint mlx5_query_ports_check(struct mlx5_core_dev *mdev, u32 *out, int outlen);
21162306a36Sopenharmony_ciint mlx5_set_ports_check(struct mlx5_core_dev *mdev, u32 *in, int inlen);
21262306a36Sopenharmony_ciint mlx5_set_port_fcs(struct mlx5_core_dev *mdev, u8 enable);
21362306a36Sopenharmony_civoid mlx5_query_port_fcs(struct mlx5_core_dev *mdev, bool *supported,
21462306a36Sopenharmony_ci			 bool *enabled);
21562306a36Sopenharmony_ciint mlx5_query_module_eeprom(struct mlx5_core_dev *dev,
21662306a36Sopenharmony_ci			     u16 offset, u16 size, u8 *data);
21762306a36Sopenharmony_ciint mlx5_query_module_eeprom_by_page(struct mlx5_core_dev *dev,
21862306a36Sopenharmony_ci				     struct mlx5_module_eeprom_query_params *params, u8 *data);
21962306a36Sopenharmony_ci
22062306a36Sopenharmony_ciint mlx5_query_port_dcbx_param(struct mlx5_core_dev *mdev, u32 *out);
22162306a36Sopenharmony_ciint mlx5_set_port_dcbx_param(struct mlx5_core_dev *mdev, u32 *in);
22262306a36Sopenharmony_ci
22362306a36Sopenharmony_ciint mlx5_set_trust_state(struct mlx5_core_dev *mdev, u8 trust_state);
22462306a36Sopenharmony_ciint mlx5_query_trust_state(struct mlx5_core_dev *mdev, u8 *trust_state);
22562306a36Sopenharmony_ciint mlx5_set_dscp2prio(struct mlx5_core_dev *mdev, u8 dscp, u8 prio);
22662306a36Sopenharmony_ciint mlx5_query_dscp2prio(struct mlx5_core_dev *mdev, u8 *dscp2prio);
22762306a36Sopenharmony_ci
22862306a36Sopenharmony_ciint mlx5_port_query_eth_proto(struct mlx5_core_dev *dev, u8 port, bool ext,
22962306a36Sopenharmony_ci			      struct mlx5_port_eth_proto *eproto);
23062306a36Sopenharmony_cibool mlx5_ptys_ext_supported(struct mlx5_core_dev *mdev);
23162306a36Sopenharmony_ciu32 mlx5_port_ptys2speed(struct mlx5_core_dev *mdev, u32 eth_proto_oper,
23262306a36Sopenharmony_ci			 bool force_legacy);
23362306a36Sopenharmony_ciu32 mlx5_port_speed2linkmodes(struct mlx5_core_dev *mdev, u32 speed,
23462306a36Sopenharmony_ci			      bool force_legacy);
23562306a36Sopenharmony_ciint mlx5_port_max_linkspeed(struct mlx5_core_dev *mdev, u32 *speed);
23662306a36Sopenharmony_ci
23762306a36Sopenharmony_ci#endif /* __MLX5_PORT_H__ */
238