blob: 35f665f97be6664c4075c4754f4cddad951dfc1b [file] [log] [blame]
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001/* Copyright 2008-2010 Broadcom Corporation
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002 *
3 * Unless you and Broadcom execute a separate written software license
4 * agreement governing use of this software, this software is licensed to you
5 * under the terms of the GNU General Public License version 2, available
6 * at http://www.gnu.org/licenses/old-licenses/gpl-2.0.html (the "GPL").
7 *
8 * Notwithstanding the above, under no circumstances may you combine this
9 * software in any way with any other Broadcom software provided under a
10 * license other than the GPL, without Broadcom's express prior written
11 * consent.
12 *
13 * Written by Yaniv Rosner
14 *
15 */
16
17#ifndef BNX2X_LINK_H
18#define BNX2X_LINK_H
19
20
21
22/***********************************************************/
23/* Defines */
24/***********************************************************/
25#define DEFAULT_PHY_DEV_ADDR 3
26
27
28
David S. Millerc0700f92008-12-16 23:53:20 -080029#define BNX2X_FLOW_CTRL_AUTO PORT_FEATURE_FLOW_CONTROL_AUTO
30#define BNX2X_FLOW_CTRL_TX PORT_FEATURE_FLOW_CONTROL_TX
31#define BNX2X_FLOW_CTRL_RX PORT_FEATURE_FLOW_CONTROL_RX
32#define BNX2X_FLOW_CTRL_BOTH PORT_FEATURE_FLOW_CONTROL_BOTH
33#define BNX2X_FLOW_CTRL_NONE PORT_FEATURE_FLOW_CONTROL_NONE
Yaniv Rosnerea4e0402008-06-23 20:27:26 -070034
35#define SPEED_AUTO_NEG 0
36#define SPEED_12000 12000
37#define SPEED_12500 12500
38#define SPEED_13000 13000
39#define SPEED_15000 15000
40#define SPEED_16000 16000
41
Eilon Greenstein4d295db2009-07-21 05:47:47 +000042#define SFP_EEPROM_VENDOR_NAME_ADDR 0x14
43#define SFP_EEPROM_VENDOR_NAME_SIZE 16
44#define SFP_EEPROM_VENDOR_OUI_ADDR 0x25
45#define SFP_EEPROM_VENDOR_OUI_SIZE 3
46#define SFP_EEPROM_PART_NO_ADDR 0x28
47#define SFP_EEPROM_PART_NO_SIZE 16
48#define PWR_FLT_ERR_MSG_LEN 250
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000049
50#define XGXS_EXT_PHY_TYPE(ext_phy_config) \
51 ((ext_phy_config) & PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK)
52#define XGXS_EXT_PHY_ADDR(ext_phy_config) \
53 (((ext_phy_config) & PORT_HW_CFG_XGXS_EXT_PHY_ADDR_MASK) >> \
54 PORT_HW_CFG_XGXS_EXT_PHY_ADDR_SHIFT)
55#define SERDES_EXT_PHY_TYPE(ext_phy_config) \
56 ((ext_phy_config) & PORT_HW_CFG_SERDES_EXT_PHY_TYPE_MASK)
57
Yaniv Rosnere10bc842010-09-07 11:40:50 +000058/* Single Media Direct board is the plain 577xx board with CX4/RJ45 jacks */
59#define SINGLE_MEDIA_DIRECT(params) (params->num_phys == 1)
60/* Single Media board contains single external phy */
61#define SINGLE_MEDIA(params) (params->num_phys == 2)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -070062/***********************************************************/
63/* Structs */
64/***********************************************************/
Yaniv Rosnere10bc842010-09-07 11:40:50 +000065#define INT_PHY 0
66#define EXT_PHY1 1
67
68#define MAX_PHYS 2
69
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000070/* Same configuration is shared between the XGXS and the first external phy */
71#define LINK_CONFIG_SIZE (MAX_PHYS - 1)
72#define LINK_CONFIG_IDX(_phy_idx) ((_phy_idx == INT_PHY) ? \
73 0 : (_phy_idx - 1))
Yaniv Rosnere10bc842010-09-07 11:40:50 +000074/***********************************************************/
75/* bnx2x_phy struct */
76/* Defines the required arguments and function per phy */
77/***********************************************************/
78struct link_vars;
79struct link_params;
80struct bnx2x_phy;
81
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000082typedef u8 (*config_init_t)(struct bnx2x_phy *phy, struct link_params *params,
83 struct link_vars *vars);
84typedef u8 (*read_status_t)(struct bnx2x_phy *phy, struct link_params *params,
85 struct link_vars *vars);
86typedef void (*link_reset_t)(struct bnx2x_phy *phy,
87 struct link_params *params);
88typedef void (*config_loopback_t)(struct bnx2x_phy *phy,
89 struct link_params *params);
90typedef u8 (*format_fw_ver_t)(u32 raw, u8 *str, u16 *len);
91typedef void (*hw_reset_t)(struct bnx2x_phy *phy, struct link_params *params);
92typedef void (*set_link_led_t)(struct bnx2x_phy *phy,
93 struct link_params *params, u8 mode);
94
Yaniv Rosnere10bc842010-09-07 11:40:50 +000095struct bnx2x_phy {
96 u32 type;
97
98 /* Loaded during init */
99 u8 addr;
100
Yaniv Rosnerb7737c92010-09-07 11:40:54 +0000101 u8 flags;
102 /* Require HW lock */
103#define FLAGS_HW_LOCK_REQUIRED (1<<0)
104 /* No Over-Current detection */
105#define FLAGS_NOC (1<<1)
106 /* Fan failure detection required */
107#define FLAGS_FAN_FAILURE_DET_REQ (1<<2)
108 /* Initialize first the XGXS and only then the phy itself */
109#define FLAGS_INIT_XGXS_FIRST (1<<3)
110
111 u8 def_md_devad;
112 u8 reserved;
113 /* preemphasis values for the rx side */
114 u16 rx_preemphasis[4];
115
116 /* preemphasis values for the tx side */
117 u16 tx_preemphasis[4];
118
119 /* EMAC address for access MDIO */
Yaniv Rosnere10bc842010-09-07 11:40:50 +0000120 u32 mdio_ctrl;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +0000121
122 u32 supported;
123
124 u32 media_type;
125#define ETH_PHY_UNSPECIFIED 0x0
126#define ETH_PHY_SFP_FIBER 0x1
127#define ETH_PHY_XFP_FIBER 0x2
128#define ETH_PHY_DA_TWINAX 0x3
129#define ETH_PHY_BASE_T 0x4
130#define ETH_PHY_NOT_PRESENT 0xff
131
132 /* The address in which version is located*/
133 u32 ver_addr;
134
135 u16 req_flow_ctrl;
136
137 u16 req_line_speed;
138
139 u32 speed_cap_mask;
140
141 u16 req_duplex;
142 u16 rsrv;
143 /* Called per phy/port init, and it configures LASI, speed, autoneg,
144 duplex, flow control negotiation, etc. */
145 config_init_t config_init;
146
147 /* Called due to interrupt. It determines the link, speed */
148 read_status_t read_status;
149
150 /* Called when driver is unloading. Should reset the phy */
151 link_reset_t link_reset;
152
153 /* Set the loopback configuration for the phy */
154 config_loopback_t config_loopback;
155
156 /* Format the given raw number into str up to len */
157 format_fw_ver_t format_fw_ver;
158
159 /* Reset the phy (both ports) */
160 hw_reset_t hw_reset;
161
162 /* Set link led mode (on/off/oper)*/
163 set_link_led_t set_link_led;
Yaniv Rosnere10bc842010-09-07 11:40:50 +0000164};
165
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700166/* Inputs parameters to the CLC */
167struct link_params {
168
169 u8 port;
170
171 /* Default / User Configuration */
172 u8 loopback_mode;
173#define LOOPBACK_NONE 0
174#define LOOPBACK_EMAC 1
175#define LOOPBACK_BMAC 2
Yaniv Rosnerde6eae12010-09-07 11:41:13 +0000176#define LOOPBACK_XGXS 3
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700177#define LOOPBACK_EXT_PHY 4
Yaniv Rosner6bbca912008-08-13 15:57:28 -0700178#define LOOPBACK_EXT 5
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700179
180 u16 req_duplex;
181 u16 req_flow_ctrl;
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -0700182 u16 req_fc_auto_adv; /* Should be set to TX / BOTH when
183 req_flow_ctrl is set to AUTO */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700184 u16 req_line_speed; /* Also determine AutoNeg */
185
186 /* Device parameters */
187 u8 mac_addr[6];
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -0700188
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700189 /* shmem parameters */
190 u32 shmem_base;
191 u32 speed_cap_mask;
192 u32 switch_cfg;
193#define SWITCH_CFG_1G PORT_FEATURE_CON_SWITCH_1G_SWITCH
194#define SWITCH_CFG_10G PORT_FEATURE_CON_SWITCH_10G_SWITCH
195#define SWITCH_CFG_AUTO_DETECT PORT_FEATURE_CON_SWITCH_AUTO_DETECT
196
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700197 u32 lane_config;
Eilon Greenstein659bc5c2009-08-12 08:24:02 +0000198
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700199 /* Phy register parameter */
200 u32 chip_id;
201
Eilon Greenstein589abe32009-02-12 08:36:55 +0000202 u32 feature_config_flags;
203#define FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED (1<<0)
Eilon Greenstein4d295db2009-07-21 05:47:47 +0000204#define FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY (1<<2)
Yaniv Rosnere10bc842010-09-07 11:40:50 +0000205 /* Will be populated during common init */
206 struct bnx2x_phy phy[MAX_PHYS];
207
208 /* Will be populated during common init */
209 u8 num_phys;
Eilon Greenstein1ef70b92009-08-12 08:23:59 +0000210
Yaniv Rosnerb7737c92010-09-07 11:40:54 +0000211 u8 rsrv;
212 u16 hw_led_mode; /* part of the hw_config read from the shmem */
213
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700214 /* Device pointer passed to all callback functions */
215 struct bnx2x *bp;
216};
217
218/* Output parameters */
219struct link_vars {
Eilon Greenstein1ef70b92009-08-12 08:23:59 +0000220 u8 phy_flags;
221
222 u8 mac_type;
223#define MAC_TYPE_NONE 0
224#define MAC_TYPE_EMAC 1
225#define MAC_TYPE_BMAC 2
226
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700227 u8 phy_link_up; /* internal phy link indication */
228 u8 link_up;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700229
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700230 u16 line_speed;
Eilon Greenstein1ef70b92009-08-12 08:23:59 +0000231 u16 duplex;
232
233 u16 flow_ctrl;
234 u16 ieee_fc;
235
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700236 u32 autoneg;
237#define AUTO_NEG_DISABLED 0x0
238#define AUTO_NEG_ENABLED 0x1
239#define AUTO_NEG_COMPLETE 0x2
Eilon Greenstein1ef70b92009-08-12 08:23:59 +0000240#define AUTO_NEG_PARALLEL_DETECTION_USED 0x3
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700241
242 /* The same definitions as the shmem parameter */
243 u32 link_status;
244};
245
246/***********************************************************/
247/* Functions */
248/***********************************************************/
249
250/* Initialize the phy */
251u8 bnx2x_phy_init(struct link_params *input, struct link_vars *output);
252
Eilon Greenstein589abe32009-02-12 08:36:55 +0000253/* Reset the link. Should be called when driver or interface goes down
254 Before calling phy firmware upgrade, the reset_ext_phy should be set
255 to 0 */
256u8 bnx2x_link_reset(struct link_params *params, struct link_vars *vars,
257 u8 reset_ext_phy);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700258
259/* bnx2x_link_update should be called upon link interrupt */
260u8 bnx2x_link_update(struct link_params *input, struct link_vars *output);
261
Yaniv Rosnere10bc842010-09-07 11:40:50 +0000262/* use the following phy functions to read/write from external_phy
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700263 In order to use it to read/write internal phy registers, use
264 DEFAULT_PHY_DEV_ADDR as devad, and (_bank + (_addr & 0xf)) as
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700265 the register */
Yaniv Rosnere10bc842010-09-07 11:40:50 +0000266u8 bnx2x_phy_read(struct link_params *params, u8 phy_addr,
267 u8 devad, u16 reg, u16 *ret_val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700268
Yaniv Rosnere10bc842010-09-07 11:40:50 +0000269u8 bnx2x_phy_write(struct link_params *params, u8 phy_addr,
270 u8 devad, u16 reg, u16 val);
Yaniv Rosnerc18aa152010-09-07 11:41:07 +0000271
Yaniv Rosnere10bc842010-09-07 11:40:50 +0000272u8 bnx2x_cl45_read(struct bnx2x *bp, struct bnx2x_phy *phy,
273 u8 devad, u16 reg, u16 *ret_val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700274
Yaniv Rosnere10bc842010-09-07 11:40:50 +0000275u8 bnx2x_cl45_write(struct bnx2x *bp, struct bnx2x_phy *phy,
276 u8 devad, u16 reg, u16 val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700277/* Reads the link_status from the shmem,
Eilon Greenstein33471622008-08-13 15:59:08 -0700278 and update the link vars accordingly */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700279void bnx2x_link_status_update(struct link_params *input,
280 struct link_vars *output);
281/* returns string representing the fw_version of the external phy */
282u8 bnx2x_get_ext_phy_fw_version(struct link_params *params, u8 driver_loaded,
283 u8 *version, u16 len);
284
285/* Set/Unset the led
286 Basically, the CLC takes care of the led for the link, but in case one needs
Eilon Greenstein33471622008-08-13 15:59:08 -0700287 to set/unset the led unnaturally, set the "mode" to LED_MODE_OPER to
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700288 blink the led, and LED_MODE_OFF to set the led off.*/
Yaniv Rosner7846e472009-11-05 19:18:07 +0200289u8 bnx2x_set_led(struct link_params *params, u8 mode, u32 speed);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700290#define LED_MODE_OFF 0
291#define LED_MODE_OPER 2
292
293u8 bnx2x_override_led_value(struct bnx2x *bp, u8 port, u32 led_idx, u32 value);
294
Eilon Greenstein589abe32009-02-12 08:36:55 +0000295/* bnx2x_handle_module_detect_int should be called upon module detection
296 interrupt */
297void bnx2x_handle_module_detect_int(struct link_params *params);
298
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700299/* Get the actual link status. In case it returns 0, link is up,
300 otherwise link is down*/
301u8 bnx2x_test_link(struct link_params *input, struct link_vars *vars);
302
Yaniv Rosner6bbca912008-08-13 15:57:28 -0700303/* One-time initialization for external phy after power up */
304u8 bnx2x_common_init_phy(struct bnx2x *bp, u32 shmem_base);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700305
Eilon Greensteinf57a6022009-08-12 08:23:11 +0000306/* Reset the external PHY using GPIO */
307void bnx2x_ext_phy_hw_reset(struct bnx2x *bp, u8 port);
308
Yaniv Rosnere10bc842010-09-07 11:40:50 +0000309/* Reset the external of SFX7101 */
310void bnx2x_sfx7101_sp_sw_reset(struct bnx2x *bp, struct bnx2x_phy *phy);
Eilon Greenstein356e2382009-02-12 08:38:32 +0000311
Yaniv Rosnere10bc842010-09-07 11:40:50 +0000312u8 bnx2x_read_sfp_module_eeprom(struct bnx2x_phy *phy,
313 struct link_params *params, u16 addr,
Eilon Greenstein4d295db2009-07-21 05:47:47 +0000314 u8 byte_cnt, u8 *o_buf);
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +0000315
316void bnx2x_hw_reset_phy(struct link_params *params);
317
318/* Checks if HW lock is required for this phy/board type */
319u8 bnx2x_hw_lock_required(struct bnx2x *bp, u32 shmem_base);
Yaniv Rosnere10bc842010-09-07 11:40:50 +0000320/* Returns the aggregative supported attributes of the phys on board */
321u32 bnx2x_supported_attr(struct link_params *params, u8 phy_idx);
322/* Probe the phys on board, and populate them in "params" */
323u8 bnx2x_phy_probe(struct link_params *params);
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +0000324/* Checks if fan failure detection is required on one of the phys on board */
325u8 bnx2x_fan_failure_det_req(struct bnx2x *bp, u32 shmem_base, u8 port);
326
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700327#endif /* BNX2X_LINK_H */