blob: 73938f9201a94ab124fb68568def72c5341063d2 [file] [log] [blame]
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001/* Copyright 2008-2011 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
Joe Perches7995c642010-02-17 15:01:52 +000017#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
18
Yaniv Rosnerea4e0402008-06-23 20:27:26 -070019#include <linux/kernel.h>
20#include <linux/errno.h>
21#include <linux/pci.h>
22#include <linux/netdevice.h>
23#include <linux/delay.h>
24#include <linux/ethtool.h>
25#include <linux/mutex.h>
Yaniv Rosnerea4e0402008-06-23 20:27:26 -070026
Yaniv Rosnerea4e0402008-06-23 20:27:26 -070027#include "bnx2x.h"
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030028#include "bnx2x_cmn.h"
29
Yaniv Rosnerea4e0402008-06-23 20:27:26 -070030
31/********************************************************/
Eilon Greenstein3196a882008-08-13 15:58:49 -070032#define ETH_HLEN 14
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000033/* L2 header size + 2*VLANs (8 bytes) + LLC SNAP (8 bytes) */
34#define ETH_OVREHEAD (ETH_HLEN + 8 + 8)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -070035#define ETH_MIN_PACKET_SIZE 60
36#define ETH_MAX_PACKET_SIZE 1500
37#define ETH_MAX_JUMBO_PACKET_SIZE 9600
38#define MDIO_ACCESS_TIMEOUT 1000
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000039#define BMAC_CONTROL_RX_ENABLE 2
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000040#define WC_LANE_MAX 4
41#define I2C_SWITCH_WIDTH 2
42#define I2C_BSC0 0
43#define I2C_BSC1 1
44#define I2C_WA_RETRY_CNT 3
45#define MCPR_IMC_COMMAND_READ_OP 1
46#define MCPR_IMC_COMMAND_WRITE_OP 2
Yaniv Rosnerea4e0402008-06-23 20:27:26 -070047
48/***********************************************************/
Eilon Greenstein3196a882008-08-13 15:58:49 -070049/* Shortcut definitions */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -070050/***********************************************************/
51
Eilon Greenstein2f904462009-08-12 08:22:16 +000052#define NIG_LATCH_BC_ENABLE_MI_INT 0
53
54#define NIG_STATUS_EMAC0_MI_INT \
55 NIG_STATUS_INTERRUPT_PORT0_REG_STATUS_EMAC0_MISC_MI_INT
Yaniv Rosnerea4e0402008-06-23 20:27:26 -070056#define NIG_STATUS_XGXS0_LINK10G \
57 NIG_STATUS_INTERRUPT_PORT0_REG_STATUS_XGXS0_LINK10G
58#define NIG_STATUS_XGXS0_LINK_STATUS \
59 NIG_STATUS_INTERRUPT_PORT0_REG_STATUS_XGXS0_LINK_STATUS
60#define NIG_STATUS_XGXS0_LINK_STATUS_SIZE \
61 NIG_STATUS_INTERRUPT_PORT0_REG_STATUS_XGXS0_LINK_STATUS_SIZE
62#define NIG_STATUS_SERDES0_LINK_STATUS \
63 NIG_STATUS_INTERRUPT_PORT0_REG_STATUS_SERDES0_LINK_STATUS
64#define NIG_MASK_MI_INT \
65 NIG_MASK_INTERRUPT_PORT0_REG_MASK_EMAC0_MISC_MI_INT
66#define NIG_MASK_XGXS0_LINK10G \
67 NIG_MASK_INTERRUPT_PORT0_REG_MASK_XGXS0_LINK10G
68#define NIG_MASK_XGXS0_LINK_STATUS \
69 NIG_MASK_INTERRUPT_PORT0_REG_MASK_XGXS0_LINK_STATUS
70#define NIG_MASK_SERDES0_LINK_STATUS \
71 NIG_MASK_INTERRUPT_PORT0_REG_MASK_SERDES0_LINK_STATUS
72
73#define MDIO_AN_CL73_OR_37_COMPLETE \
74 (MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_AUTONEG_COMPLETE | \
75 MDIO_GP_STATUS_TOP_AN_STATUS1_CL37_AUTONEG_COMPLETE)
76
77#define XGXS_RESET_BITS \
78 (MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_XGXS0_RSTB_HW | \
79 MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_XGXS0_IDDQ | \
80 MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_XGXS0_PWRDWN | \
81 MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_XGXS0_PWRDWN_SD | \
82 MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_XGXS0_TXD_FIFO_RSTB)
83
84#define SERDES_RESET_BITS \
85 (MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_SERDES0_RSTB_HW | \
86 MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_SERDES0_IDDQ | \
87 MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_SERDES0_PWRDWN | \
88 MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_SERDES0_PWRDWN_SD)
89
90#define AUTONEG_CL37 SHARED_HW_CFG_AN_ENABLE_CL37
91#define AUTONEG_CL73 SHARED_HW_CFG_AN_ENABLE_CL73
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000092#define AUTONEG_BAM SHARED_HW_CFG_AN_ENABLE_BAM
Eilon Greenstein3196a882008-08-13 15:58:49 -070093#define AUTONEG_PARALLEL \
Yaniv Rosnerea4e0402008-06-23 20:27:26 -070094 SHARED_HW_CFG_AN_ENABLE_PARALLEL_DETECTION
Eilon Greenstein3196a882008-08-13 15:58:49 -070095#define AUTONEG_SGMII_FIBER_AUTODET \
Yaniv Rosnerea4e0402008-06-23 20:27:26 -070096 SHARED_HW_CFG_AN_EN_SGMII_FIBER_AUTO_DETECT
Eilon Greenstein3196a882008-08-13 15:58:49 -070097#define AUTONEG_REMOTE_PHY SHARED_HW_CFG_AN_ENABLE_REMOTE_PHY
Yaniv Rosnerea4e0402008-06-23 20:27:26 -070098
99#define GP_STATUS_PAUSE_RSOLUTION_TXSIDE \
100 MDIO_GP_STATUS_TOP_AN_STATUS1_PAUSE_RSOLUTION_TXSIDE
101#define GP_STATUS_PAUSE_RSOLUTION_RXSIDE \
102 MDIO_GP_STATUS_TOP_AN_STATUS1_PAUSE_RSOLUTION_RXSIDE
103#define GP_STATUS_SPEED_MASK \
104 MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_MASK
105#define GP_STATUS_10M MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10M
106#define GP_STATUS_100M MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_100M
107#define GP_STATUS_1G MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_1G
108#define GP_STATUS_2_5G MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_2_5G
109#define GP_STATUS_5G MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_5G
110#define GP_STATUS_6G MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_6G
111#define GP_STATUS_10G_HIG \
112 MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10G_HIG
113#define GP_STATUS_10G_CX4 \
114 MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10G_CX4
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700115#define GP_STATUS_1G_KX MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_1G_KX
116#define GP_STATUS_10G_KX4 \
117 MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10G_KX4
Yaniv Rosner3c9ada22011-06-14 01:34:12 +0000118#define GP_STATUS_10G_KR MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10G_KR
119#define GP_STATUS_10G_XFI MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10G_XFI
120#define GP_STATUS_20G_DXGXS MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_20G_DXGXS
121#define GP_STATUS_10G_SFI MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10G_SFI
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000122#define LINK_10THD LINK_STATUS_SPEED_AND_DUPLEX_10THD
123#define LINK_10TFD LINK_STATUS_SPEED_AND_DUPLEX_10TFD
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700124#define LINK_100TXHD LINK_STATUS_SPEED_AND_DUPLEX_100TXHD
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000125#define LINK_100T4 LINK_STATUS_SPEED_AND_DUPLEX_100T4
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700126#define LINK_100TXFD LINK_STATUS_SPEED_AND_DUPLEX_100TXFD
127#define LINK_1000THD LINK_STATUS_SPEED_AND_DUPLEX_1000THD
128#define LINK_1000TFD LINK_STATUS_SPEED_AND_DUPLEX_1000TFD
129#define LINK_1000XFD LINK_STATUS_SPEED_AND_DUPLEX_1000XFD
130#define LINK_2500THD LINK_STATUS_SPEED_AND_DUPLEX_2500THD
131#define LINK_2500TFD LINK_STATUS_SPEED_AND_DUPLEX_2500TFD
132#define LINK_2500XFD LINK_STATUS_SPEED_AND_DUPLEX_2500XFD
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000133#define LINK_10GTFD LINK_STATUS_SPEED_AND_DUPLEX_10GTFD
134#define LINK_10GXFD LINK_STATUS_SPEED_AND_DUPLEX_10GXFD
Yaniv Rosner3c9ada22011-06-14 01:34:12 +0000135#define LINK_20GTFD LINK_STATUS_SPEED_AND_DUPLEX_20GTFD
136#define LINK_20GXFD LINK_STATUS_SPEED_AND_DUPLEX_20GXFD
Yaniv Rosner6583e332011-06-14 01:34:17 +0000137
138
139
Eilon Greenstein589abe32009-02-12 08:36:55 +0000140/* */
141#define SFP_EEPROM_CON_TYPE_ADDR 0x2
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000142 #define SFP_EEPROM_CON_TYPE_VAL_LC 0x7
Eilon Greenstein589abe32009-02-12 08:36:55 +0000143 #define SFP_EEPROM_CON_TYPE_VAL_COPPER 0x21
144
Eilon Greenstein4d295db2009-07-21 05:47:47 +0000145
146#define SFP_EEPROM_COMP_CODE_ADDR 0x3
147 #define SFP_EEPROM_COMP_CODE_SR_MASK (1<<4)
148 #define SFP_EEPROM_COMP_CODE_LR_MASK (1<<5)
149 #define SFP_EEPROM_COMP_CODE_LRM_MASK (1<<6)
150
Eilon Greenstein589abe32009-02-12 08:36:55 +0000151#define SFP_EEPROM_FC_TX_TECH_ADDR 0x8
152 #define SFP_EEPROM_FC_TX_TECH_BITMASK_COPPER_PASSIVE 0x4
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000153 #define SFP_EEPROM_FC_TX_TECH_BITMASK_COPPER_ACTIVE 0x8
Eilon Greenstein4d295db2009-07-21 05:47:47 +0000154
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000155#define SFP_EEPROM_OPTIONS_ADDR 0x40
Eilon Greenstein589abe32009-02-12 08:36:55 +0000156 #define SFP_EEPROM_OPTIONS_LINEAR_RX_OUT_MASK 0x1
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000157#define SFP_EEPROM_OPTIONS_SIZE 2
Eilon Greenstein589abe32009-02-12 08:36:55 +0000158
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000159#define EDC_MODE_LINEAR 0x0022
160#define EDC_MODE_LIMITING 0x0044
161#define EDC_MODE_PASSIVE_DAC 0x0055
Eilon Greenstein589abe32009-02-12 08:36:55 +0000162
Eilon Greenstein4d295db2009-07-21 05:47:47 +0000163
Yaniv Rosner9380bb92011-06-14 01:34:07 +0000164/* BRB thresholds for E2*/
165#define PFC_E2_BRB_MAC_PAUSE_XOFF_THR_PAUSE 170
166#define PFC_E2_BRB_MAC_PAUSE_XOFF_THR_NON_PAUSE 0
167
168#define PFC_E2_BRB_MAC_PAUSE_XON_THR_PAUSE 250
169#define PFC_E2_BRB_MAC_PAUSE_XON_THR_NON_PAUSE 0
170
171#define PFC_E2_BRB_MAC_FULL_XOFF_THR_PAUSE 10
172#define PFC_E2_BRB_MAC_FULL_XOFF_THR_NON_PAUSE 90
173
174#define PFC_E2_BRB_MAC_FULL_XON_THR_PAUSE 50
175#define PFC_E2_BRB_MAC_FULL_XON_THR_NON_PAUSE 250
176
177/* BRB thresholds for E3A0 */
178#define PFC_E3A0_BRB_MAC_PAUSE_XOFF_THR_PAUSE 290
179#define PFC_E3A0_BRB_MAC_PAUSE_XOFF_THR_NON_PAUSE 0
180
181#define PFC_E3A0_BRB_MAC_PAUSE_XON_THR_PAUSE 410
182#define PFC_E3A0_BRB_MAC_PAUSE_XON_THR_NON_PAUSE 0
183
184#define PFC_E3A0_BRB_MAC_FULL_XOFF_THR_PAUSE 10
185#define PFC_E3A0_BRB_MAC_FULL_XOFF_THR_NON_PAUSE 170
186
187#define PFC_E3A0_BRB_MAC_FULL_XON_THR_PAUSE 50
188#define PFC_E3A0_BRB_MAC_FULL_XON_THR_NON_PAUSE 410
189
190
191/* BRB thresholds for E3B0 2 port mode*/
192#define PFC_E3B0_2P_BRB_MAC_PAUSE_XOFF_THR_PAUSE 1025
193#define PFC_E3B0_2P_BRB_MAC_PAUSE_XOFF_THR_NON_PAUSE 0
194
195#define PFC_E3B0_2P_BRB_MAC_PAUSE_XON_THR_PAUSE 1025
196#define PFC_E3B0_2P_BRB_MAC_PAUSE_XON_THR_NON_PAUSE 0
197
198#define PFC_E3B0_2P_BRB_MAC_FULL_XOFF_THR_PAUSE 10
199#define PFC_E3B0_2P_BRB_MAC_FULL_XOFF_THR_NON_PAUSE 1025
200
201#define PFC_E3B0_2P_BRB_MAC_FULL_XON_THR_PAUSE 50
202#define PFC_E3B0_2P_BRB_MAC_FULL_XON_THR_NON_PAUSE 1025
203
204/* only for E3B0*/
205#define PFC_E3B0_2P_BRB_FULL_LB_XOFF_THR 1025
206#define PFC_E3B0_2P_BRB_FULL_LB_XON_THR 1025
207
208/* Lossy +Lossless GUARANTIED == GUART */
209#define PFC_E3B0_2P_MIX_PAUSE_LB_GUART 284
210/* Lossless +Lossless*/
211#define PFC_E3B0_2P_PAUSE_LB_GUART 236
212/* Lossy +Lossy*/
213#define PFC_E3B0_2P_NON_PAUSE_LB_GUART 342
214
215/* Lossy +Lossless*/
216#define PFC_E3B0_2P_MIX_PAUSE_MAC_0_CLASS_T_GUART 284
217/* Lossless +Lossless*/
218#define PFC_E3B0_2P_PAUSE_MAC_0_CLASS_T_GUART 236
219/* Lossy +Lossy*/
220#define PFC_E3B0_2P_NON_PAUSE_MAC_0_CLASS_T_GUART 336
221#define PFC_E3B0_2P_BRB_MAC_0_CLASS_T_GUART_HYST 80
222
223#define PFC_E3B0_2P_BRB_MAC_1_CLASS_T_GUART 0
224#define PFC_E3B0_2P_BRB_MAC_1_CLASS_T_GUART_HYST 0
225
226/* BRB thresholds for E3B0 4 port mode */
227#define PFC_E3B0_4P_BRB_MAC_PAUSE_XOFF_THR_PAUSE 304
228#define PFC_E3B0_4P_BRB_MAC_PAUSE_XOFF_THR_NON_PAUSE 0
229
230#define PFC_E3B0_4P_BRB_MAC_PAUSE_XON_THR_PAUSE 384
231#define PFC_E3B0_4P_BRB_MAC_PAUSE_XON_THR_NON_PAUSE 0
232
233#define PFC_E3B0_4P_BRB_MAC_FULL_XOFF_THR_PAUSE 10
234#define PFC_E3B0_4P_BRB_MAC_FULL_XOFF_THR_NON_PAUSE 304
235
236#define PFC_E3B0_4P_BRB_MAC_FULL_XON_THR_PAUSE 50
237#define PFC_E3B0_4P_BRB_MAC_FULL_XON_THR_NON_PAUSE 384
238
239
240/* only for E3B0*/
241#define PFC_E3B0_4P_BRB_FULL_LB_XOFF_THR 304
242#define PFC_E3B0_4P_BRB_FULL_LB_XON_THR 384
243#define PFC_E3B0_4P_LB_GUART 120
244
245#define PFC_E3B0_4P_BRB_MAC_0_CLASS_T_GUART 120
246#define PFC_E3B0_4P_BRB_MAC_0_CLASS_T_GUART_HYST 80
247
248#define PFC_E3B0_4P_BRB_MAC_1_CLASS_T_GUART 80
249#define PFC_E3B0_4P_BRB_MAC_1_CLASS_T_GUART_HYST 120
250
251#define DCBX_INVALID_COS (0xFF)
252
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000253#define ETS_BW_LIMIT_CREDIT_UPPER_BOUND (0x5000)
254#define ETS_BW_LIMIT_CREDIT_WEIGHT (0x5000)
Yaniv Rosner9380bb92011-06-14 01:34:07 +0000255#define ETS_E3B0_NIG_MIN_W_VAL_UP_TO_10GBPS (1360)
256#define ETS_E3B0_NIG_MIN_W_VAL_20GBPS (2720)
257#define ETS_E3B0_PBF_MIN_W_VAL (10000)
258
259#define MAX_PACKET_SIZE (9700)
Yaniv Rosner3c9ada22011-06-14 01:34:12 +0000260#define WC_UC_TIMEOUT 100
Yaniv Rosner9380bb92011-06-14 01:34:07 +0000261
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700262/**********************************************************/
263/* INTERFACE */
264/**********************************************************/
Yaniv Rosnere10bc842010-09-07 11:40:50 +0000265
Yaniv Rosnercd2be892011-01-31 04:21:45 +0000266#define CL22_WR_OVER_CL45(_bp, _phy, _bank, _addr, _val) \
Yaniv Rosnere10bc842010-09-07 11:40:50 +0000267 bnx2x_cl45_write(_bp, _phy, \
Yaniv Rosner7aa07112010-09-07 11:41:01 +0000268 (_phy)->def_md_devad, \
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700269 (_bank + (_addr & 0xf)), \
270 _val)
271
Yaniv Rosnercd2be892011-01-31 04:21:45 +0000272#define CL22_RD_OVER_CL45(_bp, _phy, _bank, _addr, _val) \
Yaniv Rosnere10bc842010-09-07 11:40:50 +0000273 bnx2x_cl45_read(_bp, _phy, \
Yaniv Rosner7aa07112010-09-07 11:41:01 +0000274 (_phy)->def_md_devad, \
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700275 (_bank + (_addr & 0xf)), \
276 _val)
277
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700278static u32 bnx2x_bits_en(struct bnx2x *bp, u32 reg, u32 bits)
279{
280 u32 val = REG_RD(bp, reg);
281
282 val |= bits;
283 REG_WR(bp, reg, val);
284 return val;
285}
286
287static u32 bnx2x_bits_dis(struct bnx2x *bp, u32 reg, u32 bits)
288{
289 u32 val = REG_RD(bp, reg);
290
291 val &= ~bits;
292 REG_WR(bp, reg, val);
293 return val;
294}
295
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000296/******************************************************************/
Yaniv Rosner3c9ada22011-06-14 01:34:12 +0000297/* EPIO/GPIO section */
298/******************************************************************/
299static void bnx2x_set_epio(struct bnx2x *bp, u32 epio_pin, u32 en)
300{
301 u32 epio_mask, gp_output, gp_oenable;
302
303 /* Sanity check */
304 if (epio_pin > 31) {
305 DP(NETIF_MSG_LINK, "Invalid EPIO pin %d to set\n", epio_pin);
306 return;
307 }
308 DP(NETIF_MSG_LINK, "Setting EPIO pin %d to %d\n", epio_pin, en);
309 epio_mask = 1 << epio_pin;
310 /* Set this EPIO to output */
311 gp_output = REG_RD(bp, MCP_REG_MCPR_GP_OUTPUTS);
312 if (en)
313 gp_output |= epio_mask;
314 else
315 gp_output &= ~epio_mask;
316
317 REG_WR(bp, MCP_REG_MCPR_GP_OUTPUTS, gp_output);
318
319 /* Set the value for this EPIO */
320 gp_oenable = REG_RD(bp, MCP_REG_MCPR_GP_OENABLE);
321 REG_WR(bp, MCP_REG_MCPR_GP_OENABLE, gp_oenable | epio_mask);
322}
323
324static void bnx2x_set_cfg_pin(struct bnx2x *bp, u32 pin_cfg, u32 val)
325{
326 if (pin_cfg == PIN_CFG_NA)
327 return;
328 if (pin_cfg >= PIN_CFG_EPIO0) {
329 bnx2x_set_epio(bp, pin_cfg - PIN_CFG_EPIO0, val);
330 } else {
331 u8 gpio_num = (pin_cfg - PIN_CFG_GPIO0_P0) & 0x3;
332 u8 gpio_port = (pin_cfg - PIN_CFG_GPIO0_P0) >> 2;
333 bnx2x_set_gpio(bp, gpio_num, (u8)val, gpio_port);
334 }
335}
336
337/******************************************************************/
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000338/* ETS section */
339/******************************************************************/
340void bnx2x_ets_disabled(struct link_params *params)
341{
342 /* ETS disabled configuration*/
343 struct bnx2x *bp = params->bp;
344
345 DP(NETIF_MSG_LINK, "ETS disabled configuration\n");
346
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000347 /*
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000348 * mapping between entry priority to client number (0,1,2 -debug and
349 * management clients, 3 - COS0 client, 4 - COS client)(HIGHEST)
350 * 3bits client num.
351 * PRI4 | PRI3 | PRI2 | PRI1 | PRI0
352 * cos1-100 cos0-011 dbg1-010 dbg0-001 MCP-000
353 */
354
355 REG_WR(bp, NIG_REG_P0_TX_ARB_PRIORITY_CLIENT, 0x4688);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000356 /*
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000357 * Bitmap of 5bits length. Each bit specifies whether the entry behaves
358 * as strict. Bits 0,1,2 - debug and management entries, 3 -
359 * COS0 entry, 4 - COS1 entry.
360 * COS1 | COS0 | DEBUG1 | DEBUG0 | MGMT
361 * bit4 bit3 bit2 bit1 bit0
362 * MCP and debug are strict
363 */
364
365 REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_IS_STRICT, 0x7);
366 /* defines which entries (clients) are subjected to WFQ arbitration */
367 REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_IS_SUBJECT2WFQ, 0);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000368 /*
369 * For strict priority entries defines the number of consecutive
370 * slots for the highest priority.
371 */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000372 REG_WR(bp, NIG_REG_P0_TX_ARB_NUM_STRICT_ARB_SLOTS, 0x100);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000373 /*
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000374 * mapping between the CREDIT_WEIGHT registers and actual client
375 * numbers
376 */
377 REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_CREDIT_MAP, 0);
378 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_0, 0);
379 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_1, 0);
380
381 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_0, 0);
382 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_1, 0);
383 REG_WR(bp, PBF_REG_HIGH_PRIORITY_COS_NUM, 0);
384 /* ETS mode disable */
385 REG_WR(bp, PBF_REG_ETS_ENABLED, 0);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000386 /*
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000387 * If ETS mode is enabled (there is no strict priority) defines a WFQ
388 * weight for COS0/COS1.
389 */
390 REG_WR(bp, PBF_REG_COS0_WEIGHT, 0x2710);
391 REG_WR(bp, PBF_REG_COS1_WEIGHT, 0x2710);
392 /* Upper bound that COS0_WEIGHT can reach in the WFQ arbiter */
393 REG_WR(bp, PBF_REG_COS0_UPPER_BOUND, 0x989680);
394 REG_WR(bp, PBF_REG_COS1_UPPER_BOUND, 0x989680);
395 /* Defines the number of consecutive slots for the strict priority */
396 REG_WR(bp, PBF_REG_NUM_STRICT_ARB_SLOTS, 0);
397}
398
Yaniv Rosner65a001b2011-01-31 04:22:03 +0000399static void bnx2x_ets_bw_limit_common(const struct link_params *params)
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000400{
401 /* ETS disabled configuration */
402 struct bnx2x *bp = params->bp;
403 DP(NETIF_MSG_LINK, "ETS enabled BW limit configuration\n");
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000404 /*
405 * defines which entries (clients) are subjected to WFQ arbitration
406 * COS0 0x8
407 * COS1 0x10
408 */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000409 REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_IS_SUBJECT2WFQ, 0x18);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000410 /*
411 * mapping between the ARB_CREDIT_WEIGHT registers and actual
412 * client numbers (WEIGHT_0 does not actually have to represent
413 * client 0)
414 * PRI4 | PRI3 | PRI2 | PRI1 | PRI0
415 * cos1-001 cos0-000 dbg1-100 dbg0-011 MCP-010
416 */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000417 REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_CREDIT_MAP, 0x111A);
418
419 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_0,
420 ETS_BW_LIMIT_CREDIT_UPPER_BOUND);
421 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_1,
422 ETS_BW_LIMIT_CREDIT_UPPER_BOUND);
423
424 /* ETS mode enabled*/
425 REG_WR(bp, PBF_REG_ETS_ENABLED, 1);
426
427 /* Defines the number of consecutive slots for the strict priority */
428 REG_WR(bp, PBF_REG_NUM_STRICT_ARB_SLOTS, 0);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000429 /*
430 * Bitmap of 5bits length. Each bit specifies whether the entry behaves
431 * as strict. Bits 0,1,2 - debug and management entries, 3 - COS0
432 * entry, 4 - COS1 entry.
433 * COS1 | COS0 | DEBUG21 | DEBUG0 | MGMT
434 * bit4 bit3 bit2 bit1 bit0
435 * MCP and debug are strict
436 */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000437 REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_IS_STRICT, 0x7);
438
439 /* Upper bound that COS0_WEIGHT can reach in the WFQ arbiter.*/
440 REG_WR(bp, PBF_REG_COS0_UPPER_BOUND,
441 ETS_BW_LIMIT_CREDIT_UPPER_BOUND);
442 REG_WR(bp, PBF_REG_COS1_UPPER_BOUND,
443 ETS_BW_LIMIT_CREDIT_UPPER_BOUND);
444}
445
446void bnx2x_ets_bw_limit(const struct link_params *params, const u32 cos0_bw,
447 const u32 cos1_bw)
448{
449 /* ETS disabled configuration*/
450 struct bnx2x *bp = params->bp;
451 const u32 total_bw = cos0_bw + cos1_bw;
452 u32 cos0_credit_weight = 0;
453 u32 cos1_credit_weight = 0;
454
455 DP(NETIF_MSG_LINK, "ETS enabled BW limit configuration\n");
456
457 if ((0 == total_bw) ||
458 (0 == cos0_bw) ||
459 (0 == cos1_bw)) {
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000460 DP(NETIF_MSG_LINK, "Total BW can't be zero\n");
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000461 return;
462 }
463
464 cos0_credit_weight = (cos0_bw * ETS_BW_LIMIT_CREDIT_WEIGHT)/
465 total_bw;
466 cos1_credit_weight = (cos1_bw * ETS_BW_LIMIT_CREDIT_WEIGHT)/
467 total_bw;
468
469 bnx2x_ets_bw_limit_common(params);
470
471 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_0, cos0_credit_weight);
472 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_1, cos1_credit_weight);
473
474 REG_WR(bp, PBF_REG_COS0_WEIGHT, cos0_credit_weight);
475 REG_WR(bp, PBF_REG_COS1_WEIGHT, cos1_credit_weight);
476}
477
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +0000478int bnx2x_ets_strict(const struct link_params *params, const u8 strict_cos)
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000479{
480 /* ETS disabled configuration*/
481 struct bnx2x *bp = params->bp;
482 u32 val = 0;
483
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000484 DP(NETIF_MSG_LINK, "ETS enabled strict configuration\n");
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000485 /*
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000486 * Bitmap of 5bits length. Each bit specifies whether the entry behaves
487 * as strict. Bits 0,1,2 - debug and management entries,
488 * 3 - COS0 entry, 4 - COS1 entry.
489 * COS1 | COS0 | DEBUG21 | DEBUG0 | MGMT
490 * bit4 bit3 bit2 bit1 bit0
491 * MCP and debug are strict
492 */
493 REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_IS_STRICT, 0x1F);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000494 /*
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000495 * For strict priority entries defines the number of consecutive slots
496 * for the highest priority.
497 */
498 REG_WR(bp, NIG_REG_P0_TX_ARB_NUM_STRICT_ARB_SLOTS, 0x100);
499 /* ETS mode disable */
500 REG_WR(bp, PBF_REG_ETS_ENABLED, 0);
501 /* Defines the number of consecutive slots for the strict priority */
502 REG_WR(bp, PBF_REG_NUM_STRICT_ARB_SLOTS, 0x100);
503
504 /* Defines the number of consecutive slots for the strict priority */
505 REG_WR(bp, PBF_REG_HIGH_PRIORITY_COS_NUM, strict_cos);
506
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000507 /*
508 * mapping between entry priority to client number (0,1,2 -debug and
509 * management clients, 3 - COS0 client, 4 - COS client)(HIGHEST)
510 * 3bits client num.
511 * PRI4 | PRI3 | PRI2 | PRI1 | PRI0
512 * dbg0-010 dbg1-001 cos1-100 cos0-011 MCP-000
513 * dbg0-010 dbg1-001 cos0-011 cos1-100 MCP-000
514 */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000515 val = (0 == strict_cos) ? 0x2318 : 0x22E0;
516 REG_WR(bp, NIG_REG_P0_TX_ARB_PRIORITY_CLIENT, val);
517
518 return 0;
519}
520/******************************************************************/
Dmitry Kravkove8920672011-05-04 23:52:40 +0000521/* PFC section */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000522/******************************************************************/
523
Yaniv Rosner9380bb92011-06-14 01:34:07 +0000524static void bnx2x_update_pfc_xmac(struct link_params *params,
525 struct link_vars *vars,
526 u8 is_lb)
527{
528 struct bnx2x *bp = params->bp;
529 u32 xmac_base;
530 u32 pause_val, pfc0_val, pfc1_val;
531
532 /* XMAC base adrr */
533 xmac_base = (params->port) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
534
535 /* Initialize pause and pfc registers */
536 pause_val = 0x18000;
537 pfc0_val = 0xFFFF8000;
538 pfc1_val = 0x2;
539
540 /* No PFC support */
541 if (!(params->feature_config_flags &
542 FEATURE_CONFIG_PFC_ENABLED)) {
543
544 /*
545 * RX flow control - Process pause frame in receive direction
546 */
547 if (vars->flow_ctrl & BNX2X_FLOW_CTRL_RX)
548 pause_val |= XMAC_PAUSE_CTRL_REG_RX_PAUSE_EN;
549
550 /*
551 * TX flow control - Send pause packet when buffer is full
552 */
553 if (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX)
554 pause_val |= XMAC_PAUSE_CTRL_REG_TX_PAUSE_EN;
555 } else {/* PFC support */
556 pfc1_val |= XMAC_PFC_CTRL_HI_REG_PFC_REFRESH_EN |
557 XMAC_PFC_CTRL_HI_REG_PFC_STATS_EN |
558 XMAC_PFC_CTRL_HI_REG_RX_PFC_EN |
559 XMAC_PFC_CTRL_HI_REG_TX_PFC_EN;
560 }
561
562 /* Write pause and PFC registers */
563 REG_WR(bp, xmac_base + XMAC_REG_PAUSE_CTRL, pause_val);
564 REG_WR(bp, xmac_base + XMAC_REG_PFC_CTRL, pfc0_val);
565 REG_WR(bp, xmac_base + XMAC_REG_PFC_CTRL_HI, pfc1_val);
566
567 udelay(30);
568}
569
570
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000571static void bnx2x_bmac2_get_pfc_stat(struct link_params *params,
572 u32 pfc_frames_sent[2],
573 u32 pfc_frames_received[2])
574{
575 /* Read pfc statistic */
576 struct bnx2x *bp = params->bp;
577 u32 bmac_addr = params->port ? NIG_REG_INGRESS_BMAC1_MEM :
578 NIG_REG_INGRESS_BMAC0_MEM;
579
580 DP(NETIF_MSG_LINK, "pfc statistic read from BMAC\n");
581
582 REG_RD_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_TX_STAT_GTPP,
583 pfc_frames_sent, 2);
584
585 REG_RD_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_RX_STAT_GRPP,
586 pfc_frames_received, 2);
587
588}
589static void bnx2x_emac_get_pfc_stat(struct link_params *params,
590 u32 pfc_frames_sent[2],
591 u32 pfc_frames_received[2])
592{
593 /* Read pfc statistic */
594 struct bnx2x *bp = params->bp;
595 u32 emac_base = params->port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
596 u32 val_xon = 0;
597 u32 val_xoff = 0;
598
599 DP(NETIF_MSG_LINK, "pfc statistic read from EMAC\n");
600
601 /* PFC received frames */
602 val_xoff = REG_RD(bp, emac_base +
603 EMAC_REG_RX_PFC_STATS_XOFF_RCVD);
604 val_xoff &= EMAC_REG_RX_PFC_STATS_XOFF_RCVD_COUNT;
605 val_xon = REG_RD(bp, emac_base + EMAC_REG_RX_PFC_STATS_XON_RCVD);
606 val_xon &= EMAC_REG_RX_PFC_STATS_XON_RCVD_COUNT;
607
608 pfc_frames_received[0] = val_xon + val_xoff;
609
610 /* PFC received sent */
611 val_xoff = REG_RD(bp, emac_base +
612 EMAC_REG_RX_PFC_STATS_XOFF_SENT);
613 val_xoff &= EMAC_REG_RX_PFC_STATS_XOFF_SENT_COUNT;
614 val_xon = REG_RD(bp, emac_base + EMAC_REG_RX_PFC_STATS_XON_SENT);
615 val_xon &= EMAC_REG_RX_PFC_STATS_XON_SENT_COUNT;
616
617 pfc_frames_sent[0] = val_xon + val_xoff;
618}
619
620void bnx2x_pfc_statistic(struct link_params *params, struct link_vars *vars,
621 u32 pfc_frames_sent[2],
622 u32 pfc_frames_received[2])
623{
624 /* Read pfc statistic */
625 struct bnx2x *bp = params->bp;
626 u32 val = 0;
627 DP(NETIF_MSG_LINK, "pfc statistic\n");
628
629 if (!vars->link_up)
630 return;
631
632 val = REG_RD(bp, MISC_REG_RESET_REG_2);
633 if ((val & (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << params->port))
634 == 0) {
635 DP(NETIF_MSG_LINK, "About to read stats from EMAC\n");
636 bnx2x_emac_get_pfc_stat(params, pfc_frames_sent,
637 pfc_frames_received);
638 } else {
639 DP(NETIF_MSG_LINK, "About to read stats from BMAC\n");
640 bnx2x_bmac2_get_pfc_stat(params, pfc_frames_sent,
641 pfc_frames_received);
642 }
643}
644/******************************************************************/
645/* MAC/PBF section */
646/******************************************************************/
Yaniv Rosnera198c142011-05-31 21:29:42 +0000647static void bnx2x_set_mdio_clk(struct bnx2x *bp, u32 chip_id, u8 port)
648{
649 u32 mode, emac_base;
650 /**
651 * Set clause 45 mode, slow down the MDIO clock to 2.5MHz
652 * (a value of 49==0x31) and make sure that the AUTO poll is off
653 */
654
655 if (CHIP_IS_E2(bp))
656 emac_base = GRCBASE_EMAC0;
657 else
658 emac_base = (port) ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
659 mode = REG_RD(bp, emac_base + EMAC_REG_EMAC_MDIO_MODE);
660 mode &= ~(EMAC_MDIO_MODE_AUTO_POLL |
661 EMAC_MDIO_MODE_CLOCK_CNT);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +0000662 if (USES_WARPCORE(bp))
663 mode |= (74L << EMAC_MDIO_MODE_CLOCK_CNT_BITSHIFT);
664 else
665 mode |= (49L << EMAC_MDIO_MODE_CLOCK_CNT_BITSHIFT);
Yaniv Rosnera198c142011-05-31 21:29:42 +0000666
667 mode |= (EMAC_MDIO_MODE_CLAUSE_45);
668 REG_WR(bp, emac_base + EMAC_REG_EMAC_MDIO_MODE, mode);
669
670 udelay(40);
671}
672
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700673static void bnx2x_emac_init(struct link_params *params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000674 struct link_vars *vars)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700675{
676 /* reset and unreset the emac core */
677 struct bnx2x *bp = params->bp;
678 u8 port = params->port;
679 u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
680 u32 val;
681 u16 timeout;
682
683 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000684 (MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE << port));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700685 udelay(5);
686 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000687 (MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE << port));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700688
689 /* init emac - use read-modify-write */
690 /* self clear reset */
691 val = REG_RD(bp, emac_base + EMAC_REG_EMAC_MODE);
Eilon Greenstein3196a882008-08-13 15:58:49 -0700692 EMAC_WR(bp, EMAC_REG_EMAC_MODE, (val | EMAC_MODE_RESET));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700693
694 timeout = 200;
Eilon Greenstein3196a882008-08-13 15:58:49 -0700695 do {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700696 val = REG_RD(bp, emac_base + EMAC_REG_EMAC_MODE);
697 DP(NETIF_MSG_LINK, "EMAC reset reg is %u\n", val);
698 if (!timeout) {
699 DP(NETIF_MSG_LINK, "EMAC timeout!\n");
700 return;
701 }
702 timeout--;
Eilon Greenstein3196a882008-08-13 15:58:49 -0700703 } while (val & EMAC_MODE_RESET);
Yaniv Rosnera198c142011-05-31 21:29:42 +0000704 bnx2x_set_mdio_clk(bp, params->chip_id, port);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700705 /* Set mac address */
706 val = ((params->mac_addr[0] << 8) |
707 params->mac_addr[1]);
Eilon Greenstein3196a882008-08-13 15:58:49 -0700708 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700709
710 val = ((params->mac_addr[2] << 24) |
711 (params->mac_addr[3] << 16) |
712 (params->mac_addr[4] << 8) |
713 params->mac_addr[5]);
Eilon Greenstein3196a882008-08-13 15:58:49 -0700714 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + 4, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700715}
716
Yaniv Rosner9380bb92011-06-14 01:34:07 +0000717static void bnx2x_set_xumac_nig(struct link_params *params,
718 u16 tx_pause_en,
719 u8 enable)
720{
721 struct bnx2x *bp = params->bp;
722
723 REG_WR(bp, params->port ? NIG_REG_P1_MAC_IN_EN : NIG_REG_P0_MAC_IN_EN,
724 enable);
725 REG_WR(bp, params->port ? NIG_REG_P1_MAC_OUT_EN : NIG_REG_P0_MAC_OUT_EN,
726 enable);
727 REG_WR(bp, params->port ? NIG_REG_P1_MAC_PAUSE_OUT_EN :
728 NIG_REG_P0_MAC_PAUSE_OUT_EN, tx_pause_en);
729}
730
731static void bnx2x_umac_enable(struct link_params *params,
732 struct link_vars *vars, u8 lb)
733{
734 u32 val;
735 u32 umac_base = params->port ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
736 struct bnx2x *bp = params->bp;
737 /* Reset UMAC */
738 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
739 (MISC_REGISTERS_RESET_REG_2_UMAC0 << params->port));
740 usleep_range(1000, 1000);
741
742 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
743 (MISC_REGISTERS_RESET_REG_2_UMAC0 << params->port));
744
745 DP(NETIF_MSG_LINK, "enabling UMAC\n");
746
747 /**
748 * This register determines on which events the MAC will assert
749 * error on the i/f to the NIG along w/ EOP.
750 */
751
752 /**
753 * BD REG_WR(bp, NIG_REG_P0_MAC_RSV_ERR_MASK +
754 * params->port*0x14, 0xfffff.
755 */
756 /* This register opens the gate for the UMAC despite its name */
757 REG_WR(bp, NIG_REG_EGRESS_EMAC0_PORT + params->port*4, 1);
758
759 val = UMAC_COMMAND_CONFIG_REG_PROMIS_EN |
760 UMAC_COMMAND_CONFIG_REG_PAD_EN |
761 UMAC_COMMAND_CONFIG_REG_SW_RESET |
762 UMAC_COMMAND_CONFIG_REG_NO_LGTH_CHECK;
763 switch (vars->line_speed) {
764 case SPEED_10:
765 val |= (0<<2);
766 break;
767 case SPEED_100:
768 val |= (1<<2);
769 break;
770 case SPEED_1000:
771 val |= (2<<2);
772 break;
773 case SPEED_2500:
774 val |= (3<<2);
775 break;
776 default:
777 DP(NETIF_MSG_LINK, "Invalid speed for UMAC %d\n",
778 vars->line_speed);
779 break;
780 }
781 REG_WR(bp, umac_base + UMAC_REG_COMMAND_CONFIG, val);
782 udelay(50);
783
784 /* Enable RX and TX */
785 val &= ~UMAC_COMMAND_CONFIG_REG_PAD_EN;
786 val |= UMAC_COMMAND_CONFIG_REG_TX_ENA |
Yaniv Rosner3c9ada22011-06-14 01:34:12 +0000787 UMAC_COMMAND_CONFIG_REG_RX_ENA;
Yaniv Rosner9380bb92011-06-14 01:34:07 +0000788 REG_WR(bp, umac_base + UMAC_REG_COMMAND_CONFIG, val);
789 udelay(50);
790
791 /* Remove SW Reset */
792 val &= ~UMAC_COMMAND_CONFIG_REG_SW_RESET;
793
794 /* Check loopback mode */
795 if (lb)
796 val |= UMAC_COMMAND_CONFIG_REG_LOOP_ENA;
797 REG_WR(bp, umac_base + UMAC_REG_COMMAND_CONFIG, val);
798
799 /*
800 * Maximum Frame Length (RW). Defines a 14-Bit maximum frame
801 * length used by the MAC receive logic to check frames.
802 */
803 REG_WR(bp, umac_base + UMAC_REG_MAXFR, 0x2710);
804 bnx2x_set_xumac_nig(params,
805 ((vars->flow_ctrl & BNX2X_FLOW_CTRL_TX) != 0), 1);
806 vars->mac_type = MAC_TYPE_UMAC;
807
808}
809
810static u8 bnx2x_is_4_port_mode(struct bnx2x *bp)
811{
812 u32 port4mode_ovwr_val;
813 /* Check 4-port override enabled */
814 port4mode_ovwr_val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
815 if (port4mode_ovwr_val & (1<<0)) {
816 /* Return 4-port mode override value */
817 return ((port4mode_ovwr_val & (1<<1)) == (1<<1));
818 }
819 /* Return 4-port mode from input pin */
820 return (u8)REG_RD(bp, MISC_REG_PORT4MODE_EN);
821}
822
823/* Define the XMAC mode */
824static void bnx2x_xmac_init(struct bnx2x *bp, u32 max_speed)
825{
826 u32 is_port4mode = bnx2x_is_4_port_mode(bp);
827
828 /**
829 * In 4-port mode, need to set the mode only once, so if XMAC is
830 * already out of reset, it means the mode has already been set,
831 * and it must not* reset the XMAC again, since it controls both
832 * ports of the path
833 **/
834
835 if (is_port4mode && (REG_RD(bp, MISC_REG_RESET_REG_2) &
836 MISC_REGISTERS_RESET_REG_2_XMAC)) {
837 DP(NETIF_MSG_LINK, "XMAC already out of reset"
838 " in 4-port mode\n");
839 return;
840 }
841
842 /* Hard reset */
843 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
844 MISC_REGISTERS_RESET_REG_2_XMAC);
845 usleep_range(1000, 1000);
846
847 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
848 MISC_REGISTERS_RESET_REG_2_XMAC);
849 if (is_port4mode) {
850 DP(NETIF_MSG_LINK, "Init XMAC to 2 ports x 10G per path\n");
851
852 /* Set the number of ports on the system side to up to 2 */
853 REG_WR(bp, MISC_REG_XMAC_CORE_PORT_MODE, 1);
854
855 /* Set the number of ports on the Warp Core to 10G */
856 REG_WR(bp, MISC_REG_XMAC_PHY_PORT_MODE, 3);
857 } else {
858 /* Set the number of ports on the system side to 1 */
859 REG_WR(bp, MISC_REG_XMAC_CORE_PORT_MODE, 0);
860 if (max_speed == SPEED_10000) {
861 DP(NETIF_MSG_LINK, "Init XMAC to 10G x 1"
862 " port per path\n");
863 /* Set the number of ports on the Warp Core to 10G */
864 REG_WR(bp, MISC_REG_XMAC_PHY_PORT_MODE, 3);
865 } else {
866 DP(NETIF_MSG_LINK, "Init XMAC to 20G x 2 ports"
867 " per path\n");
868 /* Set the number of ports on the Warp Core to 20G */
869 REG_WR(bp, MISC_REG_XMAC_PHY_PORT_MODE, 1);
870 }
871 }
872 /* Soft reset */
873 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
874 MISC_REGISTERS_RESET_REG_2_XMAC_SOFT);
875 usleep_range(1000, 1000);
876
877 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
878 MISC_REGISTERS_RESET_REG_2_XMAC_SOFT);
879
880}
881
882static void bnx2x_xmac_disable(struct link_params *params)
883{
884 u8 port = params->port;
885 struct bnx2x *bp = params->bp;
886 u32 xmac_base = (port) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
887
888 if (REG_RD(bp, MISC_REG_RESET_REG_2) &
889 MISC_REGISTERS_RESET_REG_2_XMAC) {
890 DP(NETIF_MSG_LINK, "Disable XMAC on port %x\n", port);
891 REG_WR(bp, xmac_base + XMAC_REG_CTRL, 0);
892 usleep_range(1000, 1000);
893 bnx2x_set_xumac_nig(params, 0, 0);
894 REG_WR(bp, xmac_base + XMAC_REG_CTRL,
895 XMAC_CTRL_REG_SOFT_RESET);
896 }
897}
898
899static int bnx2x_xmac_enable(struct link_params *params,
900 struct link_vars *vars, u8 lb)
901{
902 u32 val, xmac_base;
903 struct bnx2x *bp = params->bp;
904 DP(NETIF_MSG_LINK, "enabling XMAC\n");
905
906 xmac_base = (params->port) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
907
908 bnx2x_xmac_init(bp, vars->line_speed);
909
910 /*
911 * This register determines on which events the MAC will assert
912 * error on the i/f to the NIG along w/ EOP.
913 */
914
915 /*
916 * This register tells the NIG whether to send traffic to UMAC
917 * or XMAC
918 */
919 REG_WR(bp, NIG_REG_EGRESS_EMAC0_PORT + params->port*4, 0);
920
921 /* Set Max packet size */
922 REG_WR(bp, xmac_base + XMAC_REG_RX_MAX_SIZE, 0x2710);
923
924 /* CRC append for Tx packets */
925 REG_WR(bp, xmac_base + XMAC_REG_TX_CTRL, 0xC800);
926
927 /* update PFC */
928 bnx2x_update_pfc_xmac(params, vars, 0);
929
930 /* Enable TX and RX */
931 val = XMAC_CTRL_REG_TX_EN | XMAC_CTRL_REG_RX_EN;
932
933 /* Check loopback mode */
934 if (lb)
935 val |= XMAC_CTRL_REG_CORE_LOCAL_LPBK;
936 REG_WR(bp, xmac_base + XMAC_REG_CTRL, val);
937 bnx2x_set_xumac_nig(params,
938 ((vars->flow_ctrl & BNX2X_FLOW_CTRL_TX) != 0), 1);
939
940 vars->mac_type = MAC_TYPE_XMAC;
941
942 return 0;
943}
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +0000944static int bnx2x_emac_enable(struct link_params *params,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +0000945 struct link_vars *vars, u8 lb)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700946{
947 struct bnx2x *bp = params->bp;
948 u8 port = params->port;
949 u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
950 u32 val;
951
952 DP(NETIF_MSG_LINK, "enabling EMAC\n");
953
954 /* enable emac and not bmac */
955 REG_WR(bp, NIG_REG_EGRESS_EMAC0_PORT + port*4, 1);
956
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700957 /* ASIC */
958 if (vars->phy_flags & PHY_XGXS_FLAG) {
959 u32 ser_lane = ((params->lane_config &
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000960 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_MASK) >>
961 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_SHIFT);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700962
963 DP(NETIF_MSG_LINK, "XGXS\n");
964 /* select the master lanes (out of 0-3) */
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000965 REG_WR(bp, NIG_REG_XGXS_LANE_SEL_P0 + port*4, ser_lane);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700966 /* select XGXS */
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000967 REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700968
969 } else { /* SerDes */
970 DP(NETIF_MSG_LINK, "SerDes\n");
971 /* select SerDes */
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000972 REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700973 }
974
Eilon Greenstein811a2f22009-02-12 08:37:04 +0000975 bnx2x_bits_en(bp, emac_base + EMAC_REG_EMAC_RX_MODE,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000976 EMAC_RX_MODE_RESET);
Eilon Greenstein811a2f22009-02-12 08:37:04 +0000977 bnx2x_bits_en(bp, emac_base + EMAC_REG_EMAC_TX_MODE,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000978 EMAC_TX_MODE_RESET);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700979
980 if (CHIP_REV_IS_SLOW(bp)) {
981 /* config GMII mode */
982 val = REG_RD(bp, emac_base + EMAC_REG_EMAC_MODE);
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000983 EMAC_WR(bp, EMAC_REG_EMAC_MODE, (val | EMAC_MODE_PORT_GMII));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700984 } else { /* ASIC */
985 /* pause enable/disable */
986 bnx2x_bits_dis(bp, emac_base + EMAC_REG_EMAC_RX_MODE,
987 EMAC_RX_MODE_FLOW_EN);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700988
989 bnx2x_bits_dis(bp, emac_base + EMAC_REG_EMAC_TX_MODE,
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000990 (EMAC_TX_MODE_EXT_PAUSE_EN |
991 EMAC_TX_MODE_FLOW_EN));
992 if (!(params->feature_config_flags &
993 FEATURE_CONFIG_PFC_ENABLED)) {
994 if (vars->flow_ctrl & BNX2X_FLOW_CTRL_RX)
995 bnx2x_bits_en(bp, emac_base +
996 EMAC_REG_EMAC_RX_MODE,
997 EMAC_RX_MODE_FLOW_EN);
998
999 if (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX)
1000 bnx2x_bits_en(bp, emac_base +
1001 EMAC_REG_EMAC_TX_MODE,
1002 (EMAC_TX_MODE_EXT_PAUSE_EN |
1003 EMAC_TX_MODE_FLOW_EN));
1004 } else
1005 bnx2x_bits_en(bp, emac_base + EMAC_REG_EMAC_TX_MODE,
1006 EMAC_TX_MODE_FLOW_EN);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001007 }
1008
1009 /* KEEP_VLAN_TAG, promiscuous */
1010 val = REG_RD(bp, emac_base + EMAC_REG_EMAC_RX_MODE);
1011 val |= EMAC_RX_MODE_KEEP_VLAN_TAG | EMAC_RX_MODE_PROMISCUOUS;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001012
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00001013 /*
1014 * Setting this bit causes MAC control frames (except for pause
1015 * frames) to be passed on for processing. This setting has no
1016 * affect on the operation of the pause frames. This bit effects
1017 * all packets regardless of RX Parser packet sorting logic.
1018 * Turn the PFC off to make sure we are in Xon state before
1019 * enabling it.
1020 */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001021 EMAC_WR(bp, EMAC_REG_RX_PFC_MODE, 0);
1022 if (params->feature_config_flags & FEATURE_CONFIG_PFC_ENABLED) {
1023 DP(NETIF_MSG_LINK, "PFC is enabled\n");
1024 /* Enable PFC again */
1025 EMAC_WR(bp, EMAC_REG_RX_PFC_MODE,
1026 EMAC_REG_RX_PFC_MODE_RX_EN |
1027 EMAC_REG_RX_PFC_MODE_TX_EN |
1028 EMAC_REG_RX_PFC_MODE_PRIORITIES);
1029
1030 EMAC_WR(bp, EMAC_REG_RX_PFC_PARAM,
1031 ((0x0101 <<
1032 EMAC_REG_RX_PFC_PARAM_OPCODE_BITSHIFT) |
1033 (0x00ff <<
1034 EMAC_REG_RX_PFC_PARAM_PRIORITY_EN_BITSHIFT)));
1035 val |= EMAC_RX_MODE_KEEP_MAC_CONTROL;
1036 }
Eilon Greenstein3196a882008-08-13 15:58:49 -07001037 EMAC_WR(bp, EMAC_REG_EMAC_RX_MODE, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001038
1039 /* Set Loopback */
1040 val = REG_RD(bp, emac_base + EMAC_REG_EMAC_MODE);
1041 if (lb)
1042 val |= 0x810;
1043 else
1044 val &= ~0x810;
Eilon Greenstein3196a882008-08-13 15:58:49 -07001045 EMAC_WR(bp, EMAC_REG_EMAC_MODE, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001046
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00001047 /* enable emac */
1048 REG_WR(bp, NIG_REG_NIG_EMAC0_EN + port*4, 1);
1049
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001050 /* enable emac for jumbo packets */
Eilon Greenstein3196a882008-08-13 15:58:49 -07001051 EMAC_WR(bp, EMAC_REG_EMAC_RX_MTU_SIZE,
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001052 (EMAC_RX_MTU_SIZE_JUMBO_ENA |
1053 (ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD)));
1054
1055 /* strip CRC */
1056 REG_WR(bp, NIG_REG_NIG_INGRESS_EMAC0_NO_CRC + port*4, 0x1);
1057
1058 /* disable the NIG in/out to the bmac */
1059 REG_WR(bp, NIG_REG_BMAC0_IN_EN + port*4, 0x0);
1060 REG_WR(bp, NIG_REG_BMAC0_PAUSE_OUT_EN + port*4, 0x0);
1061 REG_WR(bp, NIG_REG_BMAC0_OUT_EN + port*4, 0x0);
1062
1063 /* enable the NIG in/out to the emac */
1064 REG_WR(bp, NIG_REG_EMAC0_IN_EN + port*4, 0x1);
1065 val = 0;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001066 if ((params->feature_config_flags &
1067 FEATURE_CONFIG_PFC_ENABLED) ||
1068 (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX))
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001069 val = 1;
1070
1071 REG_WR(bp, NIG_REG_EMAC0_PAUSE_OUT_EN + port*4, val);
1072 REG_WR(bp, NIG_REG_EGRESS_EMAC0_OUT_EN + port*4, 0x1);
1073
Yaniv Rosner02a23162011-01-31 04:22:53 +00001074 REG_WR(bp, NIG_REG_BMAC0_REGS_OUT_EN + port*4, 0x0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001075
1076 vars->mac_type = MAC_TYPE_EMAC;
1077 return 0;
1078}
1079
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001080static void bnx2x_update_pfc_bmac1(struct link_params *params,
1081 struct link_vars *vars)
1082{
1083 u32 wb_data[2];
1084 struct bnx2x *bp = params->bp;
1085 u32 bmac_addr = params->port ? NIG_REG_INGRESS_BMAC1_MEM :
1086 NIG_REG_INGRESS_BMAC0_MEM;
1087
1088 u32 val = 0x14;
1089 if ((!(params->feature_config_flags &
1090 FEATURE_CONFIG_PFC_ENABLED)) &&
1091 (vars->flow_ctrl & BNX2X_FLOW_CTRL_RX))
1092 /* Enable BigMAC to react on received Pause packets */
1093 val |= (1<<5);
1094 wb_data[0] = val;
1095 wb_data[1] = 0;
1096 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_RX_CONTROL, wb_data, 2);
1097
1098 /* tx control */
1099 val = 0xc0;
1100 if (!(params->feature_config_flags &
1101 FEATURE_CONFIG_PFC_ENABLED) &&
1102 (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX))
1103 val |= 0x800000;
1104 wb_data[0] = val;
1105 wb_data[1] = 0;
1106 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_TX_CONTROL, wb_data, 2);
1107}
1108
1109static void bnx2x_update_pfc_bmac2(struct link_params *params,
1110 struct link_vars *vars,
1111 u8 is_lb)
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001112{
1113 /*
1114 * Set rx control: Strip CRC and enable BigMAC to relay
1115 * control packets to the system as well
1116 */
1117 u32 wb_data[2];
1118 struct bnx2x *bp = params->bp;
1119 u32 bmac_addr = params->port ? NIG_REG_INGRESS_BMAC1_MEM :
1120 NIG_REG_INGRESS_BMAC0_MEM;
1121 u32 val = 0x14;
1122
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001123 if ((!(params->feature_config_flags &
1124 FEATURE_CONFIG_PFC_ENABLED)) &&
1125 (vars->flow_ctrl & BNX2X_FLOW_CTRL_RX))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001126 /* Enable BigMAC to react on received Pause packets */
1127 val |= (1<<5);
1128 wb_data[0] = val;
1129 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001130 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_RX_CONTROL, wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001131 udelay(30);
1132
1133 /* Tx control */
1134 val = 0xc0;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001135 if (!(params->feature_config_flags &
1136 FEATURE_CONFIG_PFC_ENABLED) &&
1137 (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001138 val |= 0x800000;
1139 wb_data[0] = val;
1140 wb_data[1] = 0;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001141 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_TX_CONTROL, wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001142
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001143 if (params->feature_config_flags & FEATURE_CONFIG_PFC_ENABLED) {
1144 DP(NETIF_MSG_LINK, "PFC is enabled\n");
1145 /* Enable PFC RX & TX & STATS and set 8 COS */
1146 wb_data[0] = 0x0;
1147 wb_data[0] |= (1<<0); /* RX */
1148 wb_data[0] |= (1<<1); /* TX */
1149 wb_data[0] |= (1<<2); /* Force initial Xon */
1150 wb_data[0] |= (1<<3); /* 8 cos */
1151 wb_data[0] |= (1<<5); /* STATS */
1152 wb_data[1] = 0;
1153 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_PFC_CONTROL,
1154 wb_data, 2);
1155 /* Clear the force Xon */
1156 wb_data[0] &= ~(1<<2);
1157 } else {
1158 DP(NETIF_MSG_LINK, "PFC is disabled\n");
1159 /* disable PFC RX & TX & STATS and set 8 COS */
1160 wb_data[0] = 0x8;
1161 wb_data[1] = 0;
1162 }
1163
1164 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_PFC_CONTROL, wb_data, 2);
1165
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00001166 /*
1167 * Set Time (based unit is 512 bit time) between automatic
1168 * re-sending of PP packets amd enable automatic re-send of
1169 * Per-Priroity Packet as long as pp_gen is asserted and
1170 * pp_disable is low.
1171 */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001172 val = 0x8000;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001173 if (params->feature_config_flags & FEATURE_CONFIG_PFC_ENABLED)
1174 val |= (1<<16); /* enable automatic re-send */
1175
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001176 wb_data[0] = val;
1177 wb_data[1] = 0;
1178 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_TX_PAUSE_CONTROL,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001179 wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001180
1181 /* mac control */
1182 val = 0x3; /* Enable RX and TX */
1183 if (is_lb) {
1184 val |= 0x4; /* Local loopback */
1185 DP(NETIF_MSG_LINK, "enable bmac loopback\n");
1186 }
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001187 /* When PFC enabled, Pass pause frames towards the NIG. */
1188 if (params->feature_config_flags & FEATURE_CONFIG_PFC_ENABLED)
1189 val |= ((1<<6)|(1<<5));
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001190
1191 wb_data[0] = val;
1192 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001193 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_BMAC_CONTROL, wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001194}
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001195
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001196
1197/* PFC BRB internal port configuration params */
1198struct bnx2x_pfc_brb_threshold_val {
1199 u32 pause_xoff;
1200 u32 pause_xon;
1201 u32 full_xoff;
1202 u32 full_xon;
1203};
1204
1205struct bnx2x_pfc_brb_e3b0_val {
1206 u32 full_lb_xoff_th;
1207 u32 full_lb_xon_threshold;
1208 u32 lb_guarantied;
1209 u32 mac_0_class_t_guarantied;
1210 u32 mac_0_class_t_guarantied_hyst;
1211 u32 mac_1_class_t_guarantied;
1212 u32 mac_1_class_t_guarantied_hyst;
1213};
1214
1215struct bnx2x_pfc_brb_th_val {
1216 struct bnx2x_pfc_brb_threshold_val pauseable_th;
1217 struct bnx2x_pfc_brb_threshold_val non_pauseable_th;
1218};
1219static int bnx2x_pfc_brb_get_config_params(
1220 struct link_params *params,
1221 struct bnx2x_pfc_brb_th_val *config_val)
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001222{
1223 struct bnx2x *bp = params->bp;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001224 DP(NETIF_MSG_LINK, "Setting PFC BRB configuration\n");
1225 if (CHIP_IS_E2(bp)) {
1226 config_val->pauseable_th.pause_xoff =
1227 PFC_E2_BRB_MAC_PAUSE_XOFF_THR_PAUSE;
1228 config_val->pauseable_th.pause_xon =
1229 PFC_E2_BRB_MAC_PAUSE_XON_THR_PAUSE;
1230 config_val->pauseable_th.full_xoff =
1231 PFC_E2_BRB_MAC_FULL_XOFF_THR_PAUSE;
1232 config_val->pauseable_th.full_xon =
1233 PFC_E2_BRB_MAC_FULL_XON_THR_PAUSE;
1234 /* non pause able*/
1235 config_val->non_pauseable_th.pause_xoff =
1236 PFC_E2_BRB_MAC_PAUSE_XOFF_THR_NON_PAUSE;
1237 config_val->non_pauseable_th.pause_xon =
1238 PFC_E2_BRB_MAC_PAUSE_XON_THR_NON_PAUSE;
1239 config_val->non_pauseable_th.full_xoff =
1240 PFC_E2_BRB_MAC_FULL_XOFF_THR_NON_PAUSE;
1241 config_val->non_pauseable_th.full_xon =
1242 PFC_E2_BRB_MAC_FULL_XON_THR_NON_PAUSE;
1243 } else if (CHIP_IS_E3A0(bp)) {
1244 config_val->pauseable_th.pause_xoff =
1245 PFC_E3A0_BRB_MAC_PAUSE_XOFF_THR_PAUSE;
1246 config_val->pauseable_th.pause_xon =
1247 PFC_E3A0_BRB_MAC_PAUSE_XON_THR_PAUSE;
1248 config_val->pauseable_th.full_xoff =
1249 PFC_E3A0_BRB_MAC_FULL_XOFF_THR_PAUSE;
1250 config_val->pauseable_th.full_xon =
1251 PFC_E3A0_BRB_MAC_FULL_XON_THR_PAUSE;
1252 /* non pause able*/
1253 config_val->non_pauseable_th.pause_xoff =
1254 PFC_E3A0_BRB_MAC_PAUSE_XOFF_THR_NON_PAUSE;
1255 config_val->non_pauseable_th.pause_xon =
1256 PFC_E3A0_BRB_MAC_PAUSE_XON_THR_NON_PAUSE;
1257 config_val->non_pauseable_th.full_xoff =
1258 PFC_E3A0_BRB_MAC_FULL_XOFF_THR_NON_PAUSE;
1259 config_val->non_pauseable_th.full_xon =
1260 PFC_E3A0_BRB_MAC_FULL_XON_THR_NON_PAUSE;
1261 } else if (CHIP_IS_E3B0(bp)) {
1262 if (params->phy[INT_PHY].flags &
1263 FLAGS_4_PORT_MODE) {
1264 config_val->pauseable_th.pause_xoff =
1265 PFC_E3B0_4P_BRB_MAC_PAUSE_XOFF_THR_PAUSE;
1266 config_val->pauseable_th.pause_xon =
1267 PFC_E3B0_4P_BRB_MAC_PAUSE_XON_THR_PAUSE;
1268 config_val->pauseable_th.full_xoff =
1269 PFC_E3B0_4P_BRB_MAC_FULL_XOFF_THR_PAUSE;
1270 config_val->pauseable_th.full_xon =
1271 PFC_E3B0_4P_BRB_MAC_FULL_XON_THR_PAUSE;
1272 /* non pause able*/
1273 config_val->non_pauseable_th.pause_xoff =
1274 PFC_E3B0_4P_BRB_MAC_PAUSE_XOFF_THR_NON_PAUSE;
1275 config_val->non_pauseable_th.pause_xon =
1276 PFC_E3B0_4P_BRB_MAC_PAUSE_XON_THR_NON_PAUSE;
1277 config_val->non_pauseable_th.full_xoff =
1278 PFC_E3B0_4P_BRB_MAC_FULL_XOFF_THR_NON_PAUSE;
1279 config_val->non_pauseable_th.full_xon =
1280 PFC_E3B0_4P_BRB_MAC_FULL_XON_THR_NON_PAUSE;
1281 } else {
1282 config_val->pauseable_th.pause_xoff =
1283 PFC_E3B0_2P_BRB_MAC_PAUSE_XOFF_THR_PAUSE;
1284 config_val->pauseable_th.pause_xon =
1285 PFC_E3B0_2P_BRB_MAC_PAUSE_XON_THR_PAUSE;
1286 config_val->pauseable_th.full_xoff =
1287 PFC_E3B0_2P_BRB_MAC_FULL_XOFF_THR_PAUSE;
1288 config_val->pauseable_th.full_xon =
1289 PFC_E3B0_2P_BRB_MAC_FULL_XON_THR_PAUSE;
1290 /* non pause able*/
1291 config_val->non_pauseable_th.pause_xoff =
1292 PFC_E3B0_2P_BRB_MAC_PAUSE_XOFF_THR_NON_PAUSE;
1293 config_val->non_pauseable_th.pause_xon =
1294 PFC_E3B0_2P_BRB_MAC_PAUSE_XON_THR_NON_PAUSE;
1295 config_val->non_pauseable_th.full_xoff =
1296 PFC_E3B0_2P_BRB_MAC_FULL_XOFF_THR_NON_PAUSE;
1297 config_val->non_pauseable_th.full_xon =
1298 PFC_E3B0_2P_BRB_MAC_FULL_XON_THR_NON_PAUSE;
1299 }
1300 } else
1301 return -EINVAL;
1302
1303 return 0;
1304}
1305
1306
1307static void bnx2x_pfc_brb_get_e3b0_config_params(struct link_params *params,
1308 struct bnx2x_pfc_brb_e3b0_val
1309 *e3b0_val,
1310 u32 cos0_pauseable,
1311 u32 cos1_pauseable)
1312{
1313 if (params->phy[INT_PHY].flags & FLAGS_4_PORT_MODE) {
1314 e3b0_val->full_lb_xoff_th =
1315 PFC_E3B0_4P_BRB_FULL_LB_XOFF_THR;
1316 e3b0_val->full_lb_xon_threshold =
1317 PFC_E3B0_4P_BRB_FULL_LB_XON_THR;
1318 e3b0_val->lb_guarantied =
1319 PFC_E3B0_4P_LB_GUART;
1320 e3b0_val->mac_0_class_t_guarantied =
1321 PFC_E3B0_4P_BRB_MAC_0_CLASS_T_GUART;
1322 e3b0_val->mac_0_class_t_guarantied_hyst =
1323 PFC_E3B0_4P_BRB_MAC_0_CLASS_T_GUART_HYST;
1324 e3b0_val->mac_1_class_t_guarantied =
1325 PFC_E3B0_4P_BRB_MAC_1_CLASS_T_GUART;
1326 e3b0_val->mac_1_class_t_guarantied_hyst =
1327 PFC_E3B0_4P_BRB_MAC_1_CLASS_T_GUART_HYST;
1328 } else {
1329 e3b0_val->full_lb_xoff_th =
1330 PFC_E3B0_2P_BRB_FULL_LB_XOFF_THR;
1331 e3b0_val->full_lb_xon_threshold =
1332 PFC_E3B0_2P_BRB_FULL_LB_XON_THR;
1333 e3b0_val->mac_0_class_t_guarantied_hyst =
1334 PFC_E3B0_2P_BRB_MAC_0_CLASS_T_GUART_HYST;
1335 e3b0_val->mac_1_class_t_guarantied =
1336 PFC_E3B0_2P_BRB_MAC_1_CLASS_T_GUART;
1337 e3b0_val->mac_1_class_t_guarantied_hyst =
1338 PFC_E3B0_2P_BRB_MAC_1_CLASS_T_GUART_HYST;
1339
1340 if (cos0_pauseable != cos1_pauseable) {
1341 /* nonpauseable= Lossy + pauseable = Lossless*/
1342 e3b0_val->lb_guarantied =
1343 PFC_E3B0_2P_MIX_PAUSE_LB_GUART;
1344 e3b0_val->mac_0_class_t_guarantied =
1345 PFC_E3B0_2P_MIX_PAUSE_MAC_0_CLASS_T_GUART;
1346 } else if (cos0_pauseable) {
1347 /* Lossless +Lossless*/
1348 e3b0_val->lb_guarantied =
1349 PFC_E3B0_2P_PAUSE_LB_GUART;
1350 e3b0_val->mac_0_class_t_guarantied =
1351 PFC_E3B0_2P_PAUSE_MAC_0_CLASS_T_GUART;
1352 } else {
1353 /* Lossy +Lossy*/
1354 e3b0_val->lb_guarantied =
1355 PFC_E3B0_2P_NON_PAUSE_LB_GUART;
1356 e3b0_val->mac_0_class_t_guarantied =
1357 PFC_E3B0_2P_NON_PAUSE_MAC_0_CLASS_T_GUART;
1358 }
1359 }
1360}
1361static int bnx2x_update_pfc_brb(struct link_params *params,
1362 struct link_vars *vars,
1363 struct bnx2x_nig_brb_pfc_port_params
1364 *pfc_params)
1365{
1366 struct bnx2x *bp = params->bp;
1367 struct bnx2x_pfc_brb_th_val config_val = { {0} };
1368 struct bnx2x_pfc_brb_threshold_val *reg_th_config =
1369 &config_val.pauseable_th;
1370 struct bnx2x_pfc_brb_e3b0_val e3b0_val = {0};
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001371 int set_pfc = params->feature_config_flags &
1372 FEATURE_CONFIG_PFC_ENABLED;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001373 int bnx2x_status = 0;
1374 u8 port = params->port;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001375
1376 /* default - pause configuration */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001377 reg_th_config = &config_val.pauseable_th;
1378 bnx2x_status = bnx2x_pfc_brb_get_config_params(params, &config_val);
1379 if (0 != bnx2x_status)
1380 return bnx2x_status;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001381
1382 if (set_pfc && pfc_params)
1383 /* First COS */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001384 if (!pfc_params->cos0_pauseable)
1385 reg_th_config = &config_val.non_pauseable_th;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00001386 /*
1387 * The number of free blocks below which the pause signal to class 0
1388 * of MAC #n is asserted. n=0,1
1389 */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001390 REG_WR(bp, (port) ? BRB1_REG_PAUSE_0_XOFF_THRESHOLD_1 :
1391 BRB1_REG_PAUSE_0_XOFF_THRESHOLD_0 ,
1392 reg_th_config->pause_xoff);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00001393 /*
1394 * The number of free blocks above which the pause signal to class 0
1395 * of MAC #n is de-asserted. n=0,1
1396 */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001397 REG_WR(bp, (port) ? BRB1_REG_PAUSE_0_XON_THRESHOLD_1 :
1398 BRB1_REG_PAUSE_0_XON_THRESHOLD_0 , reg_th_config->pause_xon);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00001399 /*
1400 * The number of free blocks below which the full signal to class 0
1401 * of MAC #n is asserted. n=0,1
1402 */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001403 REG_WR(bp, (port) ? BRB1_REG_FULL_0_XOFF_THRESHOLD_1 :
1404 BRB1_REG_FULL_0_XOFF_THRESHOLD_0 , reg_th_config->full_xoff);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00001405 /*
1406 * The number of free blocks above which the full signal to class 0
1407 * of MAC #n is de-asserted. n=0,1
1408 */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001409 REG_WR(bp, (port) ? BRB1_REG_FULL_0_XON_THRESHOLD_1 :
1410 BRB1_REG_FULL_0_XON_THRESHOLD_0 , reg_th_config->full_xon);
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001411
1412 if (set_pfc && pfc_params) {
1413 /* Second COS */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001414 if (pfc_params->cos1_pauseable)
1415 reg_th_config = &config_val.pauseable_th;
1416 else
1417 reg_th_config = &config_val.non_pauseable_th;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00001418 /*
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001419 * The number of free blocks below which the pause signal to
1420 * class 1 of MAC #n is asserted. n=0,1
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001421 **/
1422 REG_WR(bp, (port) ? BRB1_REG_PAUSE_1_XOFF_THRESHOLD_1 :
1423 BRB1_REG_PAUSE_1_XOFF_THRESHOLD_0,
1424 reg_th_config->pause_xoff);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00001425 /*
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001426 * The number of free blocks above which the pause signal to
1427 * class 1 of MAC #n is de-asserted. n=0,1
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00001428 */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001429 REG_WR(bp, (port) ? BRB1_REG_PAUSE_1_XON_THRESHOLD_1 :
1430 BRB1_REG_PAUSE_1_XON_THRESHOLD_0,
1431 reg_th_config->pause_xon);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00001432 /*
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001433 * The number of free blocks below which the full signal to
1434 * class 1 of MAC #n is asserted. n=0,1
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00001435 */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001436 REG_WR(bp, (port) ? BRB1_REG_FULL_1_XOFF_THRESHOLD_1 :
1437 BRB1_REG_FULL_1_XOFF_THRESHOLD_0,
1438 reg_th_config->full_xoff);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00001439 /*
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001440 * The number of free blocks above which the full signal to
1441 * class 1 of MAC #n is de-asserted. n=0,1
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00001442 */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001443 REG_WR(bp, (port) ? BRB1_REG_FULL_1_XON_THRESHOLD_1 :
1444 BRB1_REG_FULL_1_XON_THRESHOLD_0,
1445 reg_th_config->full_xon);
1446
1447
1448 if (CHIP_IS_E3B0(bp)) {
1449 /*Should be done by init tool */
1450 /*
1451 * BRB_empty_for_dup = BRB1_REG_BRB_EMPTY_THRESHOLD
1452 * reset value
1453 * 944
1454 */
1455
1456 /**
1457 * The hysteresis on the guarantied buffer space for the Lb port
1458 * before signaling XON.
1459 **/
1460 REG_WR(bp, BRB1_REG_LB_GUARANTIED_HYST, 80);
1461
1462 bnx2x_pfc_brb_get_e3b0_config_params(
1463 params,
1464 &e3b0_val,
1465 pfc_params->cos0_pauseable,
1466 pfc_params->cos1_pauseable);
1467 /**
1468 * The number of free blocks below which the full signal to the
1469 * LB port is asserted.
1470 */
1471 REG_WR(bp, BRB1_REG_FULL_LB_XOFF_THRESHOLD,
1472 e3b0_val.full_lb_xoff_th);
1473 /**
1474 * The number of free blocks above which the full signal to the
1475 * LB port is de-asserted.
1476 */
1477 REG_WR(bp, BRB1_REG_FULL_LB_XON_THRESHOLD,
1478 e3b0_val.full_lb_xon_threshold);
1479 /**
1480 * The number of blocks guarantied for the MAC #n port. n=0,1
1481 */
1482
1483 /*The number of blocks guarantied for the LB port.*/
1484 REG_WR(bp, BRB1_REG_LB_GUARANTIED,
1485 e3b0_val.lb_guarantied);
1486
1487 /**
1488 * The number of blocks guarantied for the MAC #n port.
1489 */
1490 REG_WR(bp, BRB1_REG_MAC_GUARANTIED_0,
1491 2 * e3b0_val.mac_0_class_t_guarantied);
1492 REG_WR(bp, BRB1_REG_MAC_GUARANTIED_1,
1493 2 * e3b0_val.mac_1_class_t_guarantied);
1494 /**
1495 * The number of blocks guarantied for class #t in MAC0. t=0,1
1496 */
1497 REG_WR(bp, BRB1_REG_MAC_0_CLASS_0_GUARANTIED,
1498 e3b0_val.mac_0_class_t_guarantied);
1499 REG_WR(bp, BRB1_REG_MAC_0_CLASS_1_GUARANTIED,
1500 e3b0_val.mac_0_class_t_guarantied);
1501 /**
1502 * The hysteresis on the guarantied buffer space for class in
1503 * MAC0. t=0,1
1504 */
1505 REG_WR(bp, BRB1_REG_MAC_0_CLASS_0_GUARANTIED_HYST,
1506 e3b0_val.mac_0_class_t_guarantied_hyst);
1507 REG_WR(bp, BRB1_REG_MAC_0_CLASS_1_GUARANTIED_HYST,
1508 e3b0_val.mac_0_class_t_guarantied_hyst);
1509
1510 /**
1511 * The number of blocks guarantied for class #t in MAC1.t=0,1
1512 */
1513 REG_WR(bp, BRB1_REG_MAC_1_CLASS_0_GUARANTIED,
1514 e3b0_val.mac_1_class_t_guarantied);
1515 REG_WR(bp, BRB1_REG_MAC_1_CLASS_1_GUARANTIED,
1516 e3b0_val.mac_1_class_t_guarantied);
1517 /**
1518 * The hysteresis on the guarantied buffer space for class #t
1519 * in MAC1. t=0,1
1520 */
1521 REG_WR(bp, BRB1_REG_MAC_1_CLASS_0_GUARANTIED_HYST,
1522 e3b0_val.mac_1_class_t_guarantied_hyst);
1523 REG_WR(bp, BRB1_REG_MAC_1_CLASS_1_GUARANTIED_HYST,
1524 e3b0_val.mac_1_class_t_guarantied_hyst);
1525
1526 }
1527
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001528 }
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001529
1530 return bnx2x_status;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001531}
1532
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001533/******************************************************************************
1534* Description:
1535* This function is needed because NIG ARB_CREDIT_WEIGHT_X are
1536* not continues and ARB_CREDIT_WEIGHT_0 + offset is suitable.
1537******************************************************************************/
1538int bnx2x_pfc_nig_rx_priority_mask(struct bnx2x *bp,
1539 u8 cos_entry,
1540 u32 priority_mask, u8 port)
1541{
1542 u32 nig_reg_rx_priority_mask_add = 0;
1543
1544 switch (cos_entry) {
1545 case 0:
1546 nig_reg_rx_priority_mask_add = (port) ?
1547 NIG_REG_P1_RX_COS0_PRIORITY_MASK :
1548 NIG_REG_P0_RX_COS0_PRIORITY_MASK;
1549 break;
1550 case 1:
1551 nig_reg_rx_priority_mask_add = (port) ?
1552 NIG_REG_P1_RX_COS1_PRIORITY_MASK :
1553 NIG_REG_P0_RX_COS1_PRIORITY_MASK;
1554 break;
1555 case 2:
1556 nig_reg_rx_priority_mask_add = (port) ?
1557 NIG_REG_P1_RX_COS2_PRIORITY_MASK :
1558 NIG_REG_P0_RX_COS2_PRIORITY_MASK;
1559 break;
1560 case 3:
1561 if (port)
1562 return -EINVAL;
1563 nig_reg_rx_priority_mask_add = NIG_REG_P0_RX_COS3_PRIORITY_MASK;
1564 break;
1565 case 4:
1566 if (port)
1567 return -EINVAL;
1568 nig_reg_rx_priority_mask_add = NIG_REG_P0_RX_COS4_PRIORITY_MASK;
1569 break;
1570 case 5:
1571 if (port)
1572 return -EINVAL;
1573 nig_reg_rx_priority_mask_add = NIG_REG_P0_RX_COS5_PRIORITY_MASK;
1574 break;
1575 }
1576
1577 REG_WR(bp, nig_reg_rx_priority_mask_add, priority_mask);
1578
1579 return 0;
1580}
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001581static void bnx2x_update_pfc_nig(struct link_params *params,
1582 struct link_vars *vars,
1583 struct bnx2x_nig_brb_pfc_port_params *nig_params)
1584{
1585 u32 xcm_mask = 0, ppp_enable = 0, pause_enable = 0, llfc_out_en = 0;
1586 u32 llfc_enable = 0, xcm0_out_en = 0, p0_hwpfc_enable = 0;
1587 u32 pkt_priority_to_cos = 0;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001588 struct bnx2x *bp = params->bp;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001589 u8 port = params->port;
1590
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001591 int set_pfc = params->feature_config_flags &
1592 FEATURE_CONFIG_PFC_ENABLED;
1593 DP(NETIF_MSG_LINK, "updating pfc nig parameters\n");
1594
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00001595 /*
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001596 * When NIG_LLH0_XCM_MASK_REG_LLHX_XCM_MASK_BCN bit is set
1597 * MAC control frames (that are not pause packets)
1598 * will be forwarded to the XCM.
1599 */
1600 xcm_mask = REG_RD(bp,
1601 port ? NIG_REG_LLH1_XCM_MASK :
1602 NIG_REG_LLH0_XCM_MASK);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00001603 /*
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001604 * nig params will override non PFC params, since it's possible to
1605 * do transition from PFC to SAFC
1606 */
1607 if (set_pfc) {
1608 pause_enable = 0;
1609 llfc_out_en = 0;
1610 llfc_enable = 0;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001611 if (CHIP_IS_E3(bp))
1612 ppp_enable = 0;
1613 else
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001614 ppp_enable = 1;
1615 xcm_mask &= ~(port ? NIG_LLH1_XCM_MASK_REG_LLH1_XCM_MASK_BCN :
1616 NIG_LLH0_XCM_MASK_REG_LLH0_XCM_MASK_BCN);
1617 xcm0_out_en = 0;
1618 p0_hwpfc_enable = 1;
1619 } else {
1620 if (nig_params) {
1621 llfc_out_en = nig_params->llfc_out_en;
1622 llfc_enable = nig_params->llfc_enable;
1623 pause_enable = nig_params->pause_enable;
1624 } else /*defaul non PFC mode - PAUSE */
1625 pause_enable = 1;
1626
1627 xcm_mask |= (port ? NIG_LLH1_XCM_MASK_REG_LLH1_XCM_MASK_BCN :
1628 NIG_LLH0_XCM_MASK_REG_LLH0_XCM_MASK_BCN);
1629 xcm0_out_en = 1;
1630 }
1631
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001632 if (CHIP_IS_E3(bp))
1633 REG_WR(bp, port ? NIG_REG_BRB1_PAUSE_IN_EN :
1634 NIG_REG_BRB0_PAUSE_IN_EN, pause_enable);
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001635 REG_WR(bp, port ? NIG_REG_LLFC_OUT_EN_1 :
1636 NIG_REG_LLFC_OUT_EN_0, llfc_out_en);
1637 REG_WR(bp, port ? NIG_REG_LLFC_ENABLE_1 :
1638 NIG_REG_LLFC_ENABLE_0, llfc_enable);
1639 REG_WR(bp, port ? NIG_REG_PAUSE_ENABLE_1 :
1640 NIG_REG_PAUSE_ENABLE_0, pause_enable);
1641
1642 REG_WR(bp, port ? NIG_REG_PPP_ENABLE_1 :
1643 NIG_REG_PPP_ENABLE_0, ppp_enable);
1644
1645 REG_WR(bp, port ? NIG_REG_LLH1_XCM_MASK :
1646 NIG_REG_LLH0_XCM_MASK, xcm_mask);
1647
1648 REG_WR(bp, NIG_REG_LLFC_EGRESS_SRC_ENABLE_0, 0x7);
1649
1650 /* output enable for RX_XCM # IF */
1651 REG_WR(bp, NIG_REG_XCM0_OUT_EN, xcm0_out_en);
1652
1653 /* HW PFC TX enable */
1654 REG_WR(bp, NIG_REG_P0_HWPFC_ENABLE, p0_hwpfc_enable);
1655
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001656 if (nig_params) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001657 u8 i = 0;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001658 pkt_priority_to_cos = nig_params->pkt_priority_to_cos;
1659
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001660 for (i = 0; i < nig_params->num_of_rx_cos_priority_mask; i++)
1661 bnx2x_pfc_nig_rx_priority_mask(bp, i,
1662 nig_params->rx_cos_priority_mask[i], port);
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001663
1664 REG_WR(bp, port ? NIG_REG_LLFC_HIGH_PRIORITY_CLASSES_1 :
1665 NIG_REG_LLFC_HIGH_PRIORITY_CLASSES_0,
1666 nig_params->llfc_high_priority_classes);
1667
1668 REG_WR(bp, port ? NIG_REG_LLFC_LOW_PRIORITY_CLASSES_1 :
1669 NIG_REG_LLFC_LOW_PRIORITY_CLASSES_0,
1670 nig_params->llfc_low_priority_classes);
1671 }
1672 REG_WR(bp, port ? NIG_REG_P1_PKT_PRIORITY_TO_COS :
1673 NIG_REG_P0_PKT_PRIORITY_TO_COS,
1674 pkt_priority_to_cos);
1675}
1676
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001677int bnx2x_update_pfc(struct link_params *params,
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001678 struct link_vars *vars,
1679 struct bnx2x_nig_brb_pfc_port_params *pfc_params)
1680{
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00001681 /*
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001682 * The PFC and pause are orthogonal to one another, meaning when
1683 * PFC is enabled, the pause are disabled, and when PFC is
1684 * disabled, pause are set according to the pause result.
1685 */
1686 u32 val;
1687 struct bnx2x *bp = params->bp;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001688 int bnx2x_status = 0;
1689 u8 bmac_loopback = (params->loopback_mode == LOOPBACK_BMAC);
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001690 /* update NIG params */
1691 bnx2x_update_pfc_nig(params, vars, pfc_params);
1692
1693 /* update BRB params */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001694 bnx2x_status = bnx2x_update_pfc_brb(params, vars, pfc_params);
1695 if (0 != bnx2x_status)
1696 return bnx2x_status;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001697
1698 if (!vars->link_up)
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001699 return bnx2x_status;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001700
1701 DP(NETIF_MSG_LINK, "About to update PFC in BMAC\n");
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001702 if (CHIP_IS_E3(bp))
1703 bnx2x_update_pfc_xmac(params, vars, 0);
1704 else {
1705 val = REG_RD(bp, MISC_REG_RESET_REG_2);
1706 if ((val &
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00001707 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << params->port))
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001708 == 0) {
1709 DP(NETIF_MSG_LINK, "About to update PFC in EMAC\n");
1710 bnx2x_emac_enable(params, vars, 0);
1711 return bnx2x_status;
1712 }
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001713
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001714 if (CHIP_IS_E2(bp))
1715 bnx2x_update_pfc_bmac2(params, vars, bmac_loopback);
1716 else
1717 bnx2x_update_pfc_bmac1(params, vars);
1718
1719 val = 0;
1720 if ((params->feature_config_flags &
1721 FEATURE_CONFIG_PFC_ENABLED) ||
1722 (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX))
1723 val = 1;
1724 REG_WR(bp, NIG_REG_BMAC0_PAUSE_OUT_EN + params->port*4, val);
1725 }
1726 return bnx2x_status;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001727}
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001728
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001729
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00001730static int bnx2x_bmac1_enable(struct link_params *params,
1731 struct link_vars *vars,
1732 u8 is_lb)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001733{
1734 struct bnx2x *bp = params->bp;
1735 u8 port = params->port;
1736 u32 bmac_addr = port ? NIG_REG_INGRESS_BMAC1_MEM :
1737 NIG_REG_INGRESS_BMAC0_MEM;
1738 u32 wb_data[2];
1739 u32 val;
1740
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001741 DP(NETIF_MSG_LINK, "Enabling BigMAC1\n");
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001742
1743 /* XGXS control */
1744 wb_data[0] = 0x3c;
1745 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001746 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_BMAC_XGXS_CONTROL,
1747 wb_data, 2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001748
1749 /* tx MAC SA */
1750 wb_data[0] = ((params->mac_addr[2] << 24) |
1751 (params->mac_addr[3] << 16) |
1752 (params->mac_addr[4] << 8) |
1753 params->mac_addr[5]);
1754 wb_data[1] = ((params->mac_addr[0] << 8) |
1755 params->mac_addr[1]);
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001756 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_TX_SOURCE_ADDR, wb_data, 2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001757
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001758 /* mac control */
1759 val = 0x3;
1760 if (is_lb) {
1761 val |= 0x4;
1762 DP(NETIF_MSG_LINK, "enable bmac loopback\n");
1763 }
1764 wb_data[0] = val;
1765 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001766 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_BMAC_CONTROL, wb_data, 2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001767
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001768 /* set rx mtu */
1769 wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD;
1770 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001771 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_RX_MAX_SIZE, wb_data, 2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001772
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001773 bnx2x_update_pfc_bmac1(params, vars);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001774
1775 /* set tx mtu */
1776 wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD;
1777 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001778 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_TX_MAX_SIZE, wb_data, 2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001779
1780 /* set cnt max size */
1781 wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD;
1782 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001783 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_CNT_MAX_SIZE, wb_data, 2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001784
1785 /* configure safc */
1786 wb_data[0] = 0x1000200;
1787 wb_data[1] = 0;
1788 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_RX_LLFC_MSG_FLDS,
1789 wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001790
1791 return 0;
1792}
1793
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00001794static int bnx2x_bmac2_enable(struct link_params *params,
1795 struct link_vars *vars,
1796 u8 is_lb)
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001797{
1798 struct bnx2x *bp = params->bp;
1799 u8 port = params->port;
1800 u32 bmac_addr = port ? NIG_REG_INGRESS_BMAC1_MEM :
1801 NIG_REG_INGRESS_BMAC0_MEM;
1802 u32 wb_data[2];
1803
1804 DP(NETIF_MSG_LINK, "Enabling BigMAC2\n");
1805
1806 wb_data[0] = 0;
1807 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001808 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_BMAC_CONTROL, wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001809 udelay(30);
1810
1811 /* XGXS control: Reset phy HW, MDIO registers, PHY PLL and BMAC */
1812 wb_data[0] = 0x3c;
1813 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001814 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_BMAC_XGXS_CONTROL,
1815 wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001816
1817 udelay(30);
1818
1819 /* tx MAC SA */
1820 wb_data[0] = ((params->mac_addr[2] << 24) |
1821 (params->mac_addr[3] << 16) |
1822 (params->mac_addr[4] << 8) |
1823 params->mac_addr[5]);
1824 wb_data[1] = ((params->mac_addr[0] << 8) |
1825 params->mac_addr[1]);
1826 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_TX_SOURCE_ADDR,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001827 wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001828
1829 udelay(30);
1830
1831 /* Configure SAFC */
1832 wb_data[0] = 0x1000200;
1833 wb_data[1] = 0;
1834 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_RX_LLFC_MSG_FLDS,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001835 wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001836 udelay(30);
1837
1838 /* set rx mtu */
1839 wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD;
1840 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001841 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_RX_MAX_SIZE, wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001842 udelay(30);
1843
1844 /* set tx mtu */
1845 wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD;
1846 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001847 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_TX_MAX_SIZE, wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001848 udelay(30);
1849 /* set cnt max size */
1850 wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD - 2;
1851 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001852 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_CNT_MAX_SIZE, wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001853 udelay(30);
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001854 bnx2x_update_pfc_bmac2(params, vars, is_lb);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001855
1856 return 0;
1857}
1858
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00001859static int bnx2x_bmac_enable(struct link_params *params,
1860 struct link_vars *vars,
1861 u8 is_lb)
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001862{
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00001863 int rc = 0;
1864 u8 port = params->port;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001865 struct bnx2x *bp = params->bp;
1866 u32 val;
1867 /* reset and unreset the BigMac */
1868 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001869 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port));
Yaniv Rosner1d9c05d2010-11-01 05:32:25 +00001870 msleep(1);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001871
1872 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001873 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port));
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001874
1875 /* enable access for bmac registers */
1876 REG_WR(bp, NIG_REG_BMAC0_REGS_OUT_EN + port*4, 0x1);
1877
1878 /* Enable BMAC according to BMAC type*/
1879 if (CHIP_IS_E2(bp))
1880 rc = bnx2x_bmac2_enable(params, vars, is_lb);
1881 else
1882 rc = bnx2x_bmac1_enable(params, vars, is_lb);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001883 REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 0x1);
1884 REG_WR(bp, NIG_REG_XGXS_LANE_SEL_P0 + port*4, 0x0);
1885 REG_WR(bp, NIG_REG_EGRESS_EMAC0_PORT + port*4, 0x0);
1886 val = 0;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001887 if ((params->feature_config_flags &
1888 FEATURE_CONFIG_PFC_ENABLED) ||
1889 (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX))
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001890 val = 1;
1891 REG_WR(bp, NIG_REG_BMAC0_PAUSE_OUT_EN + port*4, val);
1892 REG_WR(bp, NIG_REG_EGRESS_EMAC0_OUT_EN + port*4, 0x0);
1893 REG_WR(bp, NIG_REG_EMAC0_IN_EN + port*4, 0x0);
1894 REG_WR(bp, NIG_REG_EMAC0_PAUSE_OUT_EN + port*4, 0x0);
1895 REG_WR(bp, NIG_REG_BMAC0_IN_EN + port*4, 0x1);
1896 REG_WR(bp, NIG_REG_BMAC0_OUT_EN + port*4, 0x1);
1897
1898 vars->mac_type = MAC_TYPE_BMAC;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001899 return rc;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001900}
1901
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001902
1903static void bnx2x_update_mng(struct link_params *params, u32 link_status)
1904{
1905 struct bnx2x *bp = params->bp;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00001906
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001907 REG_WR(bp, params->shmem_base +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001908 offsetof(struct shmem_region,
1909 port_mb[params->port].link_status), link_status);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001910}
1911
1912static void bnx2x_bmac_rx_disable(struct bnx2x *bp, u8 port)
1913{
1914 u32 bmac_addr = port ? NIG_REG_INGRESS_BMAC1_MEM :
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001915 NIG_REG_INGRESS_BMAC0_MEM;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001916 u32 wb_data[2];
Eilon Greenstein3196a882008-08-13 15:58:49 -07001917 u32 nig_bmac_enable = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port*4);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001918
1919 /* Only if the bmac is out of reset */
1920 if (REG_RD(bp, MISC_REG_RESET_REG_2) &
1921 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port) &&
1922 nig_bmac_enable) {
1923
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001924 if (CHIP_IS_E2(bp)) {
1925 /* Clear Rx Enable bit in BMAC_CONTROL register */
1926 REG_RD_DMAE(bp, bmac_addr +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001927 BIGMAC2_REGISTER_BMAC_CONTROL,
1928 wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001929 wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
1930 REG_WR_DMAE(bp, bmac_addr +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001931 BIGMAC2_REGISTER_BMAC_CONTROL,
1932 wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001933 } else {
1934 /* Clear Rx Enable bit in BMAC_CONTROL register */
1935 REG_RD_DMAE(bp, bmac_addr +
1936 BIGMAC_REGISTER_BMAC_CONTROL,
1937 wb_data, 2);
1938 wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
1939 REG_WR_DMAE(bp, bmac_addr +
1940 BIGMAC_REGISTER_BMAC_CONTROL,
1941 wb_data, 2);
1942 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001943 msleep(1);
1944 }
1945}
1946
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00001947static int bnx2x_pbf_update(struct link_params *params, u32 flow_ctrl,
1948 u32 line_speed)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001949{
1950 struct bnx2x *bp = params->bp;
1951 u8 port = params->port;
1952 u32 init_crd, crd;
1953 u32 count = 1000;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001954
1955 /* disable port */
1956 REG_WR(bp, PBF_REG_DISABLE_NEW_TASK_PROC_P0 + port*4, 0x1);
1957
1958 /* wait for init credit */
1959 init_crd = REG_RD(bp, PBF_REG_P0_INIT_CRD + port*4);
1960 crd = REG_RD(bp, PBF_REG_P0_CREDIT + port*8);
1961 DP(NETIF_MSG_LINK, "init_crd 0x%x crd 0x%x\n", init_crd, crd);
1962
1963 while ((init_crd != crd) && count) {
1964 msleep(5);
1965
1966 crd = REG_RD(bp, PBF_REG_P0_CREDIT + port*8);
1967 count--;
1968 }
1969 crd = REG_RD(bp, PBF_REG_P0_CREDIT + port*8);
1970 if (init_crd != crd) {
1971 DP(NETIF_MSG_LINK, "BUG! init_crd 0x%x != crd 0x%x\n",
1972 init_crd, crd);
1973 return -EINVAL;
1974 }
1975
David S. Millerc0700f92008-12-16 23:53:20 -08001976 if (flow_ctrl & BNX2X_FLOW_CTRL_RX ||
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07001977 line_speed == SPEED_10 ||
1978 line_speed == SPEED_100 ||
1979 line_speed == SPEED_1000 ||
1980 line_speed == SPEED_2500) {
1981 REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 1);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001982 /* update threshold */
1983 REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, 0);
1984 /* update init credit */
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001985 init_crd = 778; /* (800-18-4) */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001986
1987 } else {
1988 u32 thresh = (ETH_MAX_JUMBO_PACKET_SIZE +
1989 ETH_OVREHEAD)/16;
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07001990 REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001991 /* update threshold */
1992 REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, thresh);
1993 /* update init credit */
1994 switch (line_speed) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001995 case SPEED_10000:
1996 init_crd = thresh + 553 - 22;
1997 break;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001998 default:
1999 DP(NETIF_MSG_LINK, "Invalid line_speed 0x%x\n",
2000 line_speed);
2001 return -EINVAL;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002002 }
2003 }
2004 REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, init_crd);
2005 DP(NETIF_MSG_LINK, "PBF updated to speed %d credit %d\n",
2006 line_speed, init_crd);
2007
2008 /* probe the credit changes */
2009 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0x1);
2010 msleep(5);
2011 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0x0);
2012
2013 /* enable port */
2014 REG_WR(bp, PBF_REG_DISABLE_NEW_TASK_PROC_P0 + port*4, 0x0);
2015 return 0;
2016}
2017
Dmitry Kravkove8920672011-05-04 23:52:40 +00002018/**
2019 * bnx2x_get_emac_base - retrive emac base address
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002020 *
Dmitry Kravkove8920672011-05-04 23:52:40 +00002021 * @bp: driver handle
2022 * @mdc_mdio_access: access type
2023 * @port: port id
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002024 *
2025 * This function selects the MDC/MDIO access (through emac0 or
2026 * emac1) depend on the mdc_mdio_access, port, port swapped. Each
2027 * phy has a default access mode, which could also be overridden
2028 * by nvram configuration. This parameter, whether this is the
2029 * default phy configuration, or the nvram overrun
2030 * configuration, is passed here as mdc_mdio_access and selects
2031 * the emac_base for the CL45 read/writes operations
2032 */
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00002033static u32 bnx2x_get_emac_base(struct bnx2x *bp,
2034 u32 mdc_mdio_access, u8 port)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002035{
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00002036 u32 emac_base = 0;
2037 switch (mdc_mdio_access) {
2038 case SHARED_HW_CFG_MDC_MDIO_ACCESS1_PHY_TYPE:
2039 break;
2040 case SHARED_HW_CFG_MDC_MDIO_ACCESS1_EMAC0:
2041 if (REG_RD(bp, NIG_REG_PORT_SWAP))
2042 emac_base = GRCBASE_EMAC1;
2043 else
2044 emac_base = GRCBASE_EMAC0;
2045 break;
2046 case SHARED_HW_CFG_MDC_MDIO_ACCESS1_EMAC1:
Eilon Greenstein589abe32009-02-12 08:36:55 +00002047 if (REG_RD(bp, NIG_REG_PORT_SWAP))
2048 emac_base = GRCBASE_EMAC0;
2049 else
2050 emac_base = GRCBASE_EMAC1;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002051 break;
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00002052 case SHARED_HW_CFG_MDC_MDIO_ACCESS1_BOTH:
2053 emac_base = (port) ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
2054 break;
2055 case SHARED_HW_CFG_MDC_MDIO_ACCESS1_SWAPPED:
Eilon Greenstein6378c022008-08-13 15:59:25 -07002056 emac_base = (port) ? GRCBASE_EMAC0 : GRCBASE_EMAC1;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002057 break;
2058 default:
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002059 break;
2060 }
2061 return emac_base;
2062
2063}
2064
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002065/******************************************************************/
Yaniv Rosner6583e332011-06-14 01:34:17 +00002066/* CL22 access functions */
2067/******************************************************************/
2068static int bnx2x_cl22_write(struct bnx2x *bp,
2069 struct bnx2x_phy *phy,
2070 u16 reg, u16 val)
2071{
2072 u32 tmp, mode;
2073 u8 i;
2074 int rc = 0;
2075 /* Switch to CL22 */
2076 mode = REG_RD(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE);
2077 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE,
2078 mode & ~EMAC_MDIO_MODE_CLAUSE_45);
2079
2080 /* address */
2081 tmp = ((phy->addr << 21) | (reg << 16) | val |
2082 EMAC_MDIO_COMM_COMMAND_WRITE_22 |
2083 EMAC_MDIO_COMM_START_BUSY);
2084 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, tmp);
2085
2086 for (i = 0; i < 50; i++) {
2087 udelay(10);
2088
2089 tmp = REG_RD(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM);
2090 if (!(tmp & EMAC_MDIO_COMM_START_BUSY)) {
2091 udelay(5);
2092 break;
2093 }
2094 }
2095 if (tmp & EMAC_MDIO_COMM_START_BUSY) {
2096 DP(NETIF_MSG_LINK, "write phy register failed\n");
2097 rc = -EFAULT;
2098 }
2099 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE, mode);
2100 return rc;
2101}
2102
2103static int bnx2x_cl22_read(struct bnx2x *bp,
2104 struct bnx2x_phy *phy,
2105 u16 reg, u16 *ret_val)
2106{
2107 u32 val, mode;
2108 u16 i;
2109 int rc = 0;
2110
2111 /* Switch to CL22 */
2112 mode = REG_RD(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE);
2113 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE,
2114 mode & ~EMAC_MDIO_MODE_CLAUSE_45);
2115
2116 /* address */
2117 val = ((phy->addr << 21) | (reg << 16) |
2118 EMAC_MDIO_COMM_COMMAND_READ_22 |
2119 EMAC_MDIO_COMM_START_BUSY);
2120 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, val);
2121
2122 for (i = 0; i < 50; i++) {
2123 udelay(10);
2124
2125 val = REG_RD(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM);
2126 if (!(val & EMAC_MDIO_COMM_START_BUSY)) {
2127 *ret_val = (u16)(val & EMAC_MDIO_COMM_DATA);
2128 udelay(5);
2129 break;
2130 }
2131 }
2132 if (val & EMAC_MDIO_COMM_START_BUSY) {
2133 DP(NETIF_MSG_LINK, "read phy register failed\n");
2134
2135 *ret_val = 0;
2136 rc = -EFAULT;
2137 }
2138 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE, mode);
2139 return rc;
2140}
2141
2142/******************************************************************/
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002143/* CL45 access functions */
2144/******************************************************************/
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00002145static int bnx2x_cl45_read(struct bnx2x *bp, struct bnx2x_phy *phy,
2146 u8 devad, u16 reg, u16 *ret_val)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002147{
Yaniv Rosnera198c142011-05-31 21:29:42 +00002148 u32 val;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002149 u16 i;
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00002150 int rc = 0;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002151
2152 /* address */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002153 val = ((phy->addr << 21) | (devad << 16) | reg |
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002154 EMAC_MDIO_COMM_COMMAND_ADDRESS |
2155 EMAC_MDIO_COMM_START_BUSY);
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002156 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002157
2158 for (i = 0; i < 50; i++) {
2159 udelay(10);
2160
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002161 val = REG_RD(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002162 if (!(val & EMAC_MDIO_COMM_START_BUSY)) {
2163 udelay(5);
2164 break;
2165 }
2166 }
2167 if (val & EMAC_MDIO_COMM_START_BUSY) {
2168 DP(NETIF_MSG_LINK, "read phy register failed\n");
Yaniv Rosner6d870c32011-01-31 04:22:20 +00002169 netdev_err(bp->dev, "MDC/MDIO access timeout\n");
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002170 *ret_val = 0;
2171 rc = -EFAULT;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002172 } else {
2173 /* data */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002174 val = ((phy->addr << 21) | (devad << 16) |
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002175 EMAC_MDIO_COMM_COMMAND_READ_45 |
2176 EMAC_MDIO_COMM_START_BUSY);
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002177 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002178
2179 for (i = 0; i < 50; i++) {
2180 udelay(10);
2181
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002182 val = REG_RD(bp, phy->mdio_ctrl +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002183 EMAC_REG_EMAC_MDIO_COMM);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002184 if (!(val & EMAC_MDIO_COMM_START_BUSY)) {
2185 *ret_val = (u16)(val & EMAC_MDIO_COMM_DATA);
2186 break;
2187 }
2188 }
2189 if (val & EMAC_MDIO_COMM_START_BUSY) {
2190 DP(NETIF_MSG_LINK, "read phy register failed\n");
Yaniv Rosner6d870c32011-01-31 04:22:20 +00002191 netdev_err(bp->dev, "MDC/MDIO access timeout\n");
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002192 *ret_val = 0;
2193 rc = -EFAULT;
2194 }
2195 }
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00002196 /* Work around for E3 A0 */
2197 if (phy->flags & FLAGS_MDC_MDIO_WA) {
2198 phy->flags ^= FLAGS_DUMMY_READ;
2199 if (phy->flags & FLAGS_DUMMY_READ) {
2200 u16 temp_val;
2201 bnx2x_cl45_read(bp, phy, devad, 0xf, &temp_val);
2202 }
2203 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002204
Yaniv Rosnera198c142011-05-31 21:29:42 +00002205 return rc;
2206}
2207
2208static int bnx2x_cl45_write(struct bnx2x *bp, struct bnx2x_phy *phy,
2209 u8 devad, u16 reg, u16 val)
2210{
2211 u32 tmp;
2212 u8 i;
2213 int rc = 0;
2214
2215 /* address */
2216
2217 tmp = ((phy->addr << 21) | (devad << 16) | reg |
2218 EMAC_MDIO_COMM_COMMAND_ADDRESS |
2219 EMAC_MDIO_COMM_START_BUSY);
2220 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, tmp);
2221
2222 for (i = 0; i < 50; i++) {
2223 udelay(10);
2224
2225 tmp = REG_RD(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM);
2226 if (!(tmp & EMAC_MDIO_COMM_START_BUSY)) {
2227 udelay(5);
2228 break;
2229 }
2230 }
2231 if (tmp & EMAC_MDIO_COMM_START_BUSY) {
2232 DP(NETIF_MSG_LINK, "write phy register failed\n");
2233 netdev_err(bp->dev, "MDC/MDIO access timeout\n");
2234 rc = -EFAULT;
2235
2236 } else {
2237 /* data */
2238 tmp = ((phy->addr << 21) | (devad << 16) | val |
2239 EMAC_MDIO_COMM_COMMAND_WRITE_45 |
2240 EMAC_MDIO_COMM_START_BUSY);
2241 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, tmp);
2242
2243 for (i = 0; i < 50; i++) {
2244 udelay(10);
2245
2246 tmp = REG_RD(bp, phy->mdio_ctrl +
2247 EMAC_REG_EMAC_MDIO_COMM);
2248 if (!(tmp & EMAC_MDIO_COMM_START_BUSY)) {
2249 udelay(5);
2250 break;
2251 }
2252 }
2253 if (tmp & EMAC_MDIO_COMM_START_BUSY) {
2254 DP(NETIF_MSG_LINK, "write phy register failed\n");
2255 netdev_err(bp->dev, "MDC/MDIO access timeout\n");
2256 rc = -EFAULT;
2257 }
2258 }
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00002259 /* Work around for E3 A0 */
2260 if (phy->flags & FLAGS_MDC_MDIO_WA) {
2261 phy->flags ^= FLAGS_DUMMY_READ;
2262 if (phy->flags & FLAGS_DUMMY_READ) {
2263 u16 temp_val;
2264 bnx2x_cl45_read(bp, phy, devad, 0xf, &temp_val);
2265 }
2266 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002267
2268 return rc;
2269}
2270
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00002271
2272/******************************************************************/
2273/* BSC access functions from E3 */
2274/******************************************************************/
2275static void bnx2x_bsc_module_sel(struct link_params *params)
2276{
2277 int idx;
2278 u32 board_cfg, sfp_ctrl;
2279 u32 i2c_pins[I2C_SWITCH_WIDTH], i2c_val[I2C_SWITCH_WIDTH];
2280 struct bnx2x *bp = params->bp;
2281 u8 port = params->port;
2282 /* Read I2C output PINs */
2283 board_cfg = REG_RD(bp, params->shmem_base +
2284 offsetof(struct shmem_region,
2285 dev_info.shared_hw_config.board));
2286 i2c_pins[I2C_BSC0] = board_cfg & SHARED_HW_CFG_E3_I2C_MUX0_MASK;
2287 i2c_pins[I2C_BSC1] = (board_cfg & SHARED_HW_CFG_E3_I2C_MUX1_MASK) >>
2288 SHARED_HW_CFG_E3_I2C_MUX1_SHIFT;
2289
2290 /* Read I2C output value */
2291 sfp_ctrl = REG_RD(bp, params->shmem_base +
2292 offsetof(struct shmem_region,
2293 dev_info.port_hw_config[port].e3_cmn_pin_cfg));
2294 i2c_val[I2C_BSC0] = (sfp_ctrl & PORT_HW_CFG_E3_I2C_MUX0_MASK) > 0;
2295 i2c_val[I2C_BSC1] = (sfp_ctrl & PORT_HW_CFG_E3_I2C_MUX1_MASK) > 0;
2296 DP(NETIF_MSG_LINK, "Setting BSC switch\n");
2297 for (idx = 0; idx < I2C_SWITCH_WIDTH; idx++)
2298 bnx2x_set_cfg_pin(bp, i2c_pins[idx], i2c_val[idx]);
2299}
2300
2301static int bnx2x_bsc_read(struct link_params *params,
2302 struct bnx2x_phy *phy,
2303 u8 sl_devid,
2304 u16 sl_addr,
2305 u8 lc_addr,
2306 u8 xfer_cnt,
2307 u32 *data_array)
2308{
2309 u32 val, i;
2310 int rc = 0;
2311 struct bnx2x *bp = params->bp;
2312
2313 if ((sl_devid != 0xa0) && (sl_devid != 0xa2)) {
2314 DP(NETIF_MSG_LINK, "invalid sl_devid 0x%x\n", sl_devid);
2315 return -EINVAL;
2316 }
2317
2318 if (xfer_cnt > 16) {
2319 DP(NETIF_MSG_LINK, "invalid xfer_cnt %d. Max is 16 bytes\n",
2320 xfer_cnt);
2321 return -EINVAL;
2322 }
2323 bnx2x_bsc_module_sel(params);
2324
2325 xfer_cnt = 16 - lc_addr;
2326
2327 /* enable the engine */
2328 val = REG_RD(bp, MCP_REG_MCPR_IMC_COMMAND);
2329 val |= MCPR_IMC_COMMAND_ENABLE;
2330 REG_WR(bp, MCP_REG_MCPR_IMC_COMMAND, val);
2331
2332 /* program slave device ID */
2333 val = (sl_devid << 16) | sl_addr;
2334 REG_WR(bp, MCP_REG_MCPR_IMC_SLAVE_CONTROL, val);
2335
2336 /* start xfer with 0 byte to update the address pointer ???*/
2337 val = (MCPR_IMC_COMMAND_ENABLE) |
2338 (MCPR_IMC_COMMAND_WRITE_OP <<
2339 MCPR_IMC_COMMAND_OPERATION_BITSHIFT) |
2340 (lc_addr << MCPR_IMC_COMMAND_TRANSFER_ADDRESS_BITSHIFT) | (0);
2341 REG_WR(bp, MCP_REG_MCPR_IMC_COMMAND, val);
2342
2343 /* poll for completion */
2344 i = 0;
2345 val = REG_RD(bp, MCP_REG_MCPR_IMC_COMMAND);
2346 while (((val >> MCPR_IMC_COMMAND_IMC_STATUS_BITSHIFT) & 0x3) != 1) {
2347 udelay(10);
2348 val = REG_RD(bp, MCP_REG_MCPR_IMC_COMMAND);
2349 if (i++ > 1000) {
2350 DP(NETIF_MSG_LINK, "wr 0 byte timed out after %d try\n",
2351 i);
2352 rc = -EFAULT;
2353 break;
2354 }
2355 }
2356 if (rc == -EFAULT)
2357 return rc;
2358
2359 /* start xfer with read op */
2360 val = (MCPR_IMC_COMMAND_ENABLE) |
2361 (MCPR_IMC_COMMAND_READ_OP <<
2362 MCPR_IMC_COMMAND_OPERATION_BITSHIFT) |
2363 (lc_addr << MCPR_IMC_COMMAND_TRANSFER_ADDRESS_BITSHIFT) |
2364 (xfer_cnt);
2365 REG_WR(bp, MCP_REG_MCPR_IMC_COMMAND, val);
2366
2367 /* poll for completion */
2368 i = 0;
2369 val = REG_RD(bp, MCP_REG_MCPR_IMC_COMMAND);
2370 while (((val >> MCPR_IMC_COMMAND_IMC_STATUS_BITSHIFT) & 0x3) != 1) {
2371 udelay(10);
2372 val = REG_RD(bp, MCP_REG_MCPR_IMC_COMMAND);
2373 if (i++ > 1000) {
2374 DP(NETIF_MSG_LINK, "rd op timed out after %d try\n", i);
2375 rc = -EFAULT;
2376 break;
2377 }
2378 }
2379 if (rc == -EFAULT)
2380 return rc;
2381
2382 for (i = (lc_addr >> 2); i < 4; i++) {
2383 data_array[i] = REG_RD(bp, (MCP_REG_MCPR_IMC_DATAREG0 + i*4));
2384#ifdef __BIG_ENDIAN
2385 data_array[i] = ((data_array[i] & 0x000000ff) << 24) |
2386 ((data_array[i] & 0x0000ff00) << 8) |
2387 ((data_array[i] & 0x00ff0000) >> 8) |
2388 ((data_array[i] & 0xff000000) >> 24);
2389#endif
2390 }
2391 return rc;
2392}
2393
2394static void bnx2x_cl45_read_or_write(struct bnx2x *bp, struct bnx2x_phy *phy,
2395 u8 devad, u16 reg, u16 or_val)
2396{
2397 u16 val;
2398 bnx2x_cl45_read(bp, phy, devad, reg, &val);
2399 bnx2x_cl45_write(bp, phy, devad, reg, val | or_val);
2400}
2401
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00002402int bnx2x_phy_read(struct link_params *params, u8 phy_addr,
2403 u8 devad, u16 reg, u16 *ret_val)
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002404{
2405 u8 phy_index;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002406 /*
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002407 * Probe for the phy according to the given phy_addr, and execute
2408 * the read request on it
2409 */
2410 for (phy_index = 0; phy_index < params->num_phys; phy_index++) {
2411 if (params->phy[phy_index].addr == phy_addr) {
2412 return bnx2x_cl45_read(params->bp,
2413 &params->phy[phy_index], devad,
2414 reg, ret_val);
2415 }
2416 }
2417 return -EINVAL;
2418}
2419
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00002420int bnx2x_phy_write(struct link_params *params, u8 phy_addr,
2421 u8 devad, u16 reg, u16 val)
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002422{
2423 u8 phy_index;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002424 /*
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002425 * Probe for the phy according to the given phy_addr, and execute
2426 * the write request on it
2427 */
2428 for (phy_index = 0; phy_index < params->num_phys; phy_index++) {
2429 if (params->phy[phy_index].addr == phy_addr) {
2430 return bnx2x_cl45_write(params->bp,
2431 &params->phy[phy_index], devad,
2432 reg, val);
2433 }
2434 }
2435 return -EINVAL;
2436}
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00002437static u8 bnx2x_get_warpcore_lane(struct bnx2x_phy *phy,
2438 struct link_params *params)
2439{
2440 u8 lane = 0;
2441 struct bnx2x *bp = params->bp;
2442 u32 path_swap, path_swap_ovr;
2443 u8 path, port;
2444
2445 path = BP_PATH(bp);
2446 port = params->port;
2447
2448 if (bnx2x_is_4_port_mode(bp)) {
2449 u32 port_swap, port_swap_ovr;
2450
2451 /*figure out path swap value */
2452 path_swap_ovr = REG_RD(bp, MISC_REG_FOUR_PORT_PATH_SWAP_OVWR);
2453 if (path_swap_ovr & 0x1)
2454 path_swap = (path_swap_ovr & 0x2);
2455 else
2456 path_swap = REG_RD(bp, MISC_REG_FOUR_PORT_PATH_SWAP);
2457
2458 if (path_swap)
2459 path = path ^ 1;
2460
2461 /*figure out port swap value */
2462 port_swap_ovr = REG_RD(bp, MISC_REG_FOUR_PORT_PORT_SWAP_OVWR);
2463 if (port_swap_ovr & 0x1)
2464 port_swap = (port_swap_ovr & 0x2);
2465 else
2466 port_swap = REG_RD(bp, MISC_REG_FOUR_PORT_PORT_SWAP);
2467
2468 if (port_swap)
2469 port = port ^ 1;
2470
2471 lane = (port<<1) + path;
2472 } else { /* two port mode - no port swap */
2473
2474 /*figure out path swap value */
2475 path_swap_ovr =
2476 REG_RD(bp, MISC_REG_TWO_PORT_PATH_SWAP_OVWR);
2477 if (path_swap_ovr & 0x1) {
2478 path_swap = (path_swap_ovr & 0x2);
2479 } else {
2480 path_swap =
2481 REG_RD(bp, MISC_REG_TWO_PORT_PATH_SWAP);
2482 }
2483 if (path_swap)
2484 path = path ^ 1;
2485
2486 lane = path << 1 ;
2487 }
2488 return lane;
2489}
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002490
Yaniv Rosnerec146a62011-05-31 21:29:27 +00002491static void bnx2x_set_aer_mmd(struct link_params *params,
2492 struct bnx2x_phy *phy)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002493{
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002494 u32 ser_lane;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002495 u16 offset, aer_val;
2496 struct bnx2x *bp = params->bp;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002497 ser_lane = ((params->lane_config &
2498 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_MASK) >>
2499 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_SHIFT);
2500
Yaniv Rosnerec146a62011-05-31 21:29:27 +00002501 offset = (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT) ?
2502 (phy->addr + ser_lane) : 0;
2503
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00002504 if (USES_WARPCORE(bp)) {
2505 aer_val = bnx2x_get_warpcore_lane(phy, params);
2506 /*
2507 * In Dual-lane mode, two lanes are joined together,
2508 * so in order to configure them, the AER broadcast method is
2509 * used here.
2510 * 0x200 is the broadcast address for lanes 0,1
2511 * 0x201 is the broadcast address for lanes 2,3
2512 */
2513 if (phy->flags & FLAGS_WC_DUAL_MODE)
2514 aer_val = (aer_val >> 1) | 0x200;
2515 } else if (CHIP_IS_E2(bp))
Yaniv Rosner82a0d472011-01-18 04:33:52 +00002516 aer_val = 0x3800 + offset - 1;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002517 else
2518 aer_val = 0x3800 + offset;
Yaniv Rosnerec146a62011-05-31 21:29:27 +00002519 DP(NETIF_MSG_LINK, "Set AER to 0x%x\n", aer_val);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002520 CL22_WR_OVER_CL45(bp, phy, MDIO_REG_BANK_AER_BLOCK,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002521 MDIO_AER_BLOCK_AER_REG, aer_val);
Yaniv Rosnerec146a62011-05-31 21:29:27 +00002522
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002523}
2524
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00002525/******************************************************************/
2526/* Internal phy section */
2527/******************************************************************/
2528
2529static void bnx2x_set_serdes_access(struct bnx2x *bp, u8 port)
2530{
2531 u32 emac_base = (port) ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
2532
2533 /* Set Clause 22 */
2534 REG_WR(bp, NIG_REG_SERDES0_CTRL_MD_ST + port*0x10, 1);
2535 REG_WR(bp, emac_base + EMAC_REG_EMAC_MDIO_COMM, 0x245f8000);
2536 udelay(500);
2537 REG_WR(bp, emac_base + EMAC_REG_EMAC_MDIO_COMM, 0x245d000f);
2538 udelay(500);
2539 /* Set Clause 45 */
2540 REG_WR(bp, NIG_REG_SERDES0_CTRL_MD_ST + port*0x10, 0);
2541}
2542
2543static void bnx2x_serdes_deassert(struct bnx2x *bp, u8 port)
2544{
2545 u32 val;
2546
2547 DP(NETIF_MSG_LINK, "bnx2x_serdes_deassert\n");
2548
2549 val = SERDES_RESET_BITS << (port*16);
2550
2551 /* reset and unreset the SerDes/XGXS */
2552 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_CLEAR, val);
2553 udelay(500);
2554 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_SET, val);
2555
2556 bnx2x_set_serdes_access(bp, port);
2557
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002558 REG_WR(bp, NIG_REG_SERDES0_CTRL_MD_DEVAD + port*0x10,
2559 DEFAULT_PHY_DEV_ADDR);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00002560}
2561
2562static void bnx2x_xgxs_deassert(struct link_params *params)
2563{
2564 struct bnx2x *bp = params->bp;
2565 u8 port;
2566 u32 val;
2567 DP(NETIF_MSG_LINK, "bnx2x_xgxs_deassert\n");
2568 port = params->port;
2569
2570 val = XGXS_RESET_BITS << (port*16);
2571
2572 /* reset and unreset the SerDes/XGXS */
2573 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_CLEAR, val);
2574 udelay(500);
2575 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_SET, val);
2576
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002577 REG_WR(bp, NIG_REG_XGXS0_CTRL_MD_ST + port*0x18, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00002578 REG_WR(bp, NIG_REG_XGXS0_CTRL_MD_DEVAD + port*0x18,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002579 params->phy[INT_PHY].def_md_devad);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00002580}
2581
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00002582static void bnx2x_calc_ieee_aneg_adv(struct bnx2x_phy *phy,
2583 struct link_params *params, u16 *ieee_fc)
2584{
2585 struct bnx2x *bp = params->bp;
2586 *ieee_fc = MDIO_COMBO_IEEE0_AUTO_NEG_ADV_FULL_DUPLEX;
2587 /**
2588 * resolve pause mode and advertisement Please refer to Table
2589 * 28B-3 of the 802.3ab-1999 spec
2590 */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002591
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00002592 switch (phy->req_flow_ctrl) {
2593 case BNX2X_FLOW_CTRL_AUTO:
2594 if (params->req_fc_auto_adv == BNX2X_FLOW_CTRL_BOTH)
2595 *ieee_fc |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH;
2596 else
2597 *ieee_fc |=
2598 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC;
2599 break;
2600
2601 case BNX2X_FLOW_CTRL_TX:
2602 *ieee_fc |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC;
2603 break;
2604
2605 case BNX2X_FLOW_CTRL_RX:
2606 case BNX2X_FLOW_CTRL_BOTH:
2607 *ieee_fc |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH;
2608 break;
2609
2610 case BNX2X_FLOW_CTRL_NONE:
2611 default:
2612 *ieee_fc |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE;
2613 break;
2614 }
2615 DP(NETIF_MSG_LINK, "ieee_fc = 0x%x\n", *ieee_fc);
2616}
2617
2618static void set_phy_vars(struct link_params *params,
2619 struct link_vars *vars)
2620{
2621 struct bnx2x *bp = params->bp;
2622 u8 actual_phy_idx, phy_index, link_cfg_idx;
2623 u8 phy_config_swapped = params->multi_phy_config &
2624 PORT_HW_CFG_PHY_SWAPPED_ENABLED;
2625 for (phy_index = INT_PHY; phy_index < params->num_phys;
2626 phy_index++) {
2627 link_cfg_idx = LINK_CONFIG_IDX(phy_index);
2628 actual_phy_idx = phy_index;
2629 if (phy_config_swapped) {
2630 if (phy_index == EXT_PHY1)
2631 actual_phy_idx = EXT_PHY2;
2632 else if (phy_index == EXT_PHY2)
2633 actual_phy_idx = EXT_PHY1;
2634 }
2635 params->phy[actual_phy_idx].req_flow_ctrl =
2636 params->req_flow_ctrl[link_cfg_idx];
2637
2638 params->phy[actual_phy_idx].req_line_speed =
2639 params->req_line_speed[link_cfg_idx];
2640
2641 params->phy[actual_phy_idx].speed_cap_mask =
2642 params->speed_cap_mask[link_cfg_idx];
2643
2644 params->phy[actual_phy_idx].req_duplex =
2645 params->req_duplex[link_cfg_idx];
2646
2647 if (params->req_line_speed[link_cfg_idx] ==
2648 SPEED_AUTO_NEG)
2649 vars->link_status |= LINK_STATUS_AUTO_NEGOTIATE_ENABLED;
2650
2651 DP(NETIF_MSG_LINK, "req_flow_ctrl %x, req_line_speed %x,"
2652 " speed_cap_mask %x\n",
2653 params->phy[actual_phy_idx].req_flow_ctrl,
2654 params->phy[actual_phy_idx].req_line_speed,
2655 params->phy[actual_phy_idx].speed_cap_mask);
2656 }
2657}
2658
2659static void bnx2x_ext_phy_set_pause(struct link_params *params,
2660 struct bnx2x_phy *phy,
2661 struct link_vars *vars)
2662{
2663 u16 val;
2664 struct bnx2x *bp = params->bp;
2665 /* read modify write pause advertizing */
2666 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV_PAUSE, &val);
2667
2668 val &= ~MDIO_AN_REG_ADV_PAUSE_BOTH;
2669
2670 /* Please refer to Table 28B-3 of 802.3ab-1999 spec. */
2671 bnx2x_calc_ieee_aneg_adv(phy, params, &vars->ieee_fc);
2672 if ((vars->ieee_fc &
2673 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC) ==
2674 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC) {
2675 val |= MDIO_AN_REG_ADV_PAUSE_ASYMMETRIC;
2676 }
2677 if ((vars->ieee_fc &
2678 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) ==
2679 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) {
2680 val |= MDIO_AN_REG_ADV_PAUSE_PAUSE;
2681 }
2682 DP(NETIF_MSG_LINK, "Ext phy AN advertize 0x%x\n", val);
2683 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV_PAUSE, val);
2684}
2685
2686static void bnx2x_pause_resolve(struct link_vars *vars, u32 pause_result)
2687{ /* LD LP */
2688 switch (pause_result) { /* ASYM P ASYM P */
2689 case 0xb: /* 1 0 1 1 */
2690 vars->flow_ctrl = BNX2X_FLOW_CTRL_TX;
2691 break;
2692
2693 case 0xe: /* 1 1 1 0 */
2694 vars->flow_ctrl = BNX2X_FLOW_CTRL_RX;
2695 break;
2696
2697 case 0x5: /* 0 1 0 1 */
2698 case 0x7: /* 0 1 1 1 */
2699 case 0xd: /* 1 1 0 1 */
2700 case 0xf: /* 1 1 1 1 */
2701 vars->flow_ctrl = BNX2X_FLOW_CTRL_BOTH;
2702 break;
2703
2704 default:
2705 break;
2706 }
2707 if (pause_result & (1<<0))
2708 vars->link_status |= LINK_STATUS_LINK_PARTNER_SYMMETRIC_PAUSE;
2709 if (pause_result & (1<<1))
2710 vars->link_status |= LINK_STATUS_LINK_PARTNER_ASYMMETRIC_PAUSE;
2711}
2712
2713static u8 bnx2x_ext_phy_resolve_fc(struct bnx2x_phy *phy,
2714 struct link_params *params,
2715 struct link_vars *vars)
2716{
2717 struct bnx2x *bp = params->bp;
2718 u16 ld_pause; /* local */
2719 u16 lp_pause; /* link partner */
2720 u16 pause_result;
2721 u8 ret = 0;
2722 /* read twice */
2723
2724 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
2725
2726 if (phy->req_flow_ctrl != BNX2X_FLOW_CTRL_AUTO)
2727 vars->flow_ctrl = phy->req_flow_ctrl;
2728 else if (phy->req_line_speed != SPEED_AUTO_NEG)
2729 vars->flow_ctrl = params->req_fc_auto_adv;
2730 else if (vars->link_status & LINK_STATUS_AUTO_NEGOTIATE_COMPLETE) {
2731 ret = 1;
Yaniv Rosner6583e332011-06-14 01:34:17 +00002732 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54616) {
2733 bnx2x_cl22_read(bp, phy,
2734 0x4, &ld_pause);
2735 bnx2x_cl22_read(bp, phy,
2736 0x5, &lp_pause);
2737 } else {
2738 bnx2x_cl45_read(bp, phy,
2739 MDIO_AN_DEVAD,
2740 MDIO_AN_REG_ADV_PAUSE, &ld_pause);
2741 bnx2x_cl45_read(bp, phy,
2742 MDIO_AN_DEVAD,
2743 MDIO_AN_REG_LP_AUTO_NEG, &lp_pause);
2744 }
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00002745 pause_result = (ld_pause &
2746 MDIO_AN_REG_ADV_PAUSE_MASK) >> 8;
2747 pause_result |= (lp_pause &
2748 MDIO_AN_REG_ADV_PAUSE_MASK) >> 10;
2749 DP(NETIF_MSG_LINK, "Ext PHY pause result 0x%x\n",
2750 pause_result);
2751 bnx2x_pause_resolve(vars, pause_result);
2752 }
2753 return ret;
2754}
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00002755/******************************************************************/
2756/* Warpcore section */
2757/******************************************************************/
2758/* The init_internal_warpcore should mirror the xgxs,
2759 * i.e. reset the lane (if needed), set aer for the
2760 * init configuration, and set/clear SGMII flag. Internal
2761 * phy init is done purely in phy_init stage.
2762 */
2763static void bnx2x_warpcore_enable_AN_KR(struct bnx2x_phy *phy,
2764 struct link_params *params,
2765 struct link_vars *vars) {
2766 u16 val16 = 0, lane;
2767 struct bnx2x *bp = params->bp;
2768 DP(NETIF_MSG_LINK, "Enable Auto Negotiation for KR\n");
2769 /* Check adding advertisement for 1G KX */
2770 if (((vars->line_speed == SPEED_AUTO_NEG) &&
2771 (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) ||
2772 (vars->line_speed == SPEED_1000)) {
2773 u16 sd_digital;
2774 val16 |= (1<<5);
2775
2776 /* Enable CL37 1G Parallel Detect */
2777 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
2778 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2, &sd_digital);
2779 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
2780 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2,
2781 (sd_digital | 0x1));
2782
2783 DP(NETIF_MSG_LINK, "Advertize 1G\n");
2784 }
2785 if (((vars->line_speed == SPEED_AUTO_NEG) &&
2786 (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) ||
2787 (vars->line_speed == SPEED_10000)) {
2788 /* Check adding advertisement for 10G KR */
2789 val16 |= (1<<7);
2790 /* Enable 10G Parallel Detect */
2791 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
2792 MDIO_WC_REG_PAR_DET_10G_CTRL, 1);
2793
2794 DP(NETIF_MSG_LINK, "Advertize 10G\n");
2795 }
2796
2797 /* Set Transmit PMD settings */
2798 lane = bnx2x_get_warpcore_lane(phy, params);
2799 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
2800 MDIO_WC_REG_TX0_TX_DRIVER + 0x10*lane,
2801 ((0x02 << MDIO_WC_REG_TX0_TX_DRIVER_POST2_COEFF_OFFSET) |
2802 (0x06 << MDIO_WC_REG_TX0_TX_DRIVER_IDRIVER_OFFSET) |
2803 (0x09 << MDIO_WC_REG_TX0_TX_DRIVER_IPRE_DRIVER_OFFSET)));
2804 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
2805 MDIO_WC_REG_CL72_USERB0_CL72_OS_DEF_CTRL,
2806 0x03f0);
2807 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
2808 MDIO_WC_REG_CL72_USERB0_CL72_2P5_DEF_CTRL,
2809 0x03f0);
2810 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
2811 MDIO_WC_REG_CL72_USERB0_CL72_MISC1_CONTROL,
2812 0x383f);
2813
2814 /* Advertised speeds */
2815 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
2816 MDIO_WC_REG_AN_IEEE1BLK_AN_ADVERTISEMENT1, val16);
2817
2818 /* Advertise pause */
2819 bnx2x_ext_phy_set_pause(params, phy, vars);
2820
2821 /* Enable Autoneg */
2822 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
2823 MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x1000);
2824
2825 /* Over 1G - AN local device user page 1 */
2826 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
2827 MDIO_WC_REG_DIGITAL3_UP1, 0x1f);
2828
2829 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
2830 MDIO_WC_REG_DIGITAL5_MISC7, &val16);
2831
2832 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
2833 MDIO_WC_REG_DIGITAL5_MISC7, val16 | 0x100);
2834}
2835
2836static void bnx2x_warpcore_set_10G_KR(struct bnx2x_phy *phy,
2837 struct link_params *params,
2838 struct link_vars *vars)
2839{
2840 struct bnx2x *bp = params->bp;
2841 u16 val;
2842
2843 /* Disable Autoneg */
2844 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
2845 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2, 0x7);
2846
2847 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
2848 MDIO_WC_REG_PAR_DET_10G_CTRL, 0);
2849
2850 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
2851 MDIO_WC_REG_CL72_USERB0_CL72_MISC1_CONTROL, 0x3f00);
2852
2853 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
2854 MDIO_WC_REG_AN_IEEE1BLK_AN_ADVERTISEMENT1, 0);
2855
2856 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
2857 MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x0);
2858
2859 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
2860 MDIO_WC_REG_DIGITAL3_UP1, 0x1);
2861
2862 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
2863 MDIO_WC_REG_DIGITAL5_MISC7, 0xa);
2864
2865 /* Disable CL36 PCS Tx */
2866 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
2867 MDIO_WC_REG_XGXSBLK1_LANECTRL0, 0x0);
2868
2869 /* Double Wide Single Data Rate @ pll rate */
2870 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
2871 MDIO_WC_REG_XGXSBLK1_LANECTRL1, 0xFFFF);
2872
2873 /* Leave cl72 training enable, needed for KR */
2874 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD,
2875 MDIO_WC_REG_PMD_IEEE9BLK_TENGBASE_KR_PMD_CONTROL_REGISTER_150,
2876 0x2);
2877
2878 /* Leave CL72 enabled */
2879 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
2880 MDIO_WC_REG_CL72_USERB0_CL72_MISC1_CONTROL,
2881 &val);
2882 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
2883 MDIO_WC_REG_CL72_USERB0_CL72_MISC1_CONTROL,
2884 val | 0x3800);
2885
2886 /* Set speed via PMA/PMD register */
2887 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD,
2888 MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x2040);
2889
2890 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD,
2891 MDIO_WC_REG_IEEE0BLK_AUTONEGNP, 0xB);
2892
2893 /*Enable encoded forced speed */
2894 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
2895 MDIO_WC_REG_SERDESDIGITAL_MISC2, 0x30);
2896
2897 /* Turn TX scramble payload only the 64/66 scrambler */
2898 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
2899 MDIO_WC_REG_TX66_CONTROL, 0x9);
2900
2901 /* Turn RX scramble payload only the 64/66 scrambler */
2902 bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
2903 MDIO_WC_REG_RX66_CONTROL, 0xF9);
2904
2905 /* set and clear loopback to cause a reset to 64/66 decoder */
2906 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
2907 MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x4000);
2908 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
2909 MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x0);
2910
2911}
2912
2913static void bnx2x_warpcore_set_10G_XFI(struct bnx2x_phy *phy,
2914 struct link_params *params,
2915 u8 is_xfi)
2916{
2917 struct bnx2x *bp = params->bp;
2918 u16 misc1_val, tap_val, tx_driver_val, lane, val;
2919 /* Hold rxSeqStart */
2920 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
2921 MDIO_WC_REG_DSC2B0_DSC_MISC_CTRL0, &val);
2922 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
2923 MDIO_WC_REG_DSC2B0_DSC_MISC_CTRL0, (val | 0x8000));
2924
2925 /* Hold tx_fifo_reset */
2926 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
2927 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X3, &val);
2928 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
2929 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X3, (val | 0x1));
2930
2931 /* Disable CL73 AN */
2932 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0);
2933
2934 /* Disable 100FX Enable and Auto-Detect */
2935 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
2936 MDIO_WC_REG_FX100_CTRL1, &val);
2937 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
2938 MDIO_WC_REG_FX100_CTRL1, (val & 0xFFFA));
2939
2940 /* Disable 100FX Idle detect */
2941 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
2942 MDIO_WC_REG_FX100_CTRL3, &val);
2943 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
2944 MDIO_WC_REG_FX100_CTRL3, (val | 0x0080));
2945
2946 /* Set Block address to Remote PHY & Clear forced_speed[5] */
2947 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
2948 MDIO_WC_REG_DIGITAL4_MISC3, &val);
2949 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
2950 MDIO_WC_REG_DIGITAL4_MISC3, (val & 0xFF7F));
2951
2952 /* Turn off auto-detect & fiber mode */
2953 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
2954 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X1, &val);
2955 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
2956 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X1,
2957 (val & 0xFFEE));
2958
2959 /* Set filter_force_link, disable_false_link and parallel_detect */
2960 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
2961 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2, &val);
2962 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
2963 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2,
2964 ((val | 0x0006) & 0xFFFE));
2965
2966 /* Set XFI / SFI */
2967 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
2968 MDIO_WC_REG_SERDESDIGITAL_MISC1, &misc1_val);
2969
2970 misc1_val &= ~(0x1f);
2971
2972 if (is_xfi) {
2973 misc1_val |= 0x5;
2974 tap_val = ((0x08 << MDIO_WC_REG_TX_FIR_TAP_POST_TAP_OFFSET) |
2975 (0x37 << MDIO_WC_REG_TX_FIR_TAP_MAIN_TAP_OFFSET) |
2976 (0x00 << MDIO_WC_REG_TX_FIR_TAP_PRE_TAP_OFFSET));
2977 tx_driver_val =
2978 ((0x00 << MDIO_WC_REG_TX0_TX_DRIVER_POST2_COEFF_OFFSET) |
2979 (0x02 << MDIO_WC_REG_TX0_TX_DRIVER_IDRIVER_OFFSET) |
2980 (0x03 << MDIO_WC_REG_TX0_TX_DRIVER_IPRE_DRIVER_OFFSET));
2981
2982 } else {
2983 misc1_val |= 0x9;
2984 tap_val = ((0x12 << MDIO_WC_REG_TX_FIR_TAP_POST_TAP_OFFSET) |
2985 (0x2d << MDIO_WC_REG_TX_FIR_TAP_MAIN_TAP_OFFSET) |
2986 (0x00 << MDIO_WC_REG_TX_FIR_TAP_PRE_TAP_OFFSET));
2987 tx_driver_val =
2988 ((0x02 << MDIO_WC_REG_TX0_TX_DRIVER_POST2_COEFF_OFFSET) |
2989 (0x02 << MDIO_WC_REG_TX0_TX_DRIVER_IDRIVER_OFFSET) |
2990 (0x02 << MDIO_WC_REG_TX0_TX_DRIVER_IPRE_DRIVER_OFFSET));
2991 }
2992 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
2993 MDIO_WC_REG_SERDESDIGITAL_MISC1, misc1_val);
2994
2995 /* Set Transmit PMD settings */
2996 lane = bnx2x_get_warpcore_lane(phy, params);
2997 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
2998 MDIO_WC_REG_TX_FIR_TAP,
2999 tap_val | MDIO_WC_REG_TX_FIR_TAP_ENABLE);
3000 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3001 MDIO_WC_REG_TX0_TX_DRIVER + 0x10*lane,
3002 tx_driver_val);
3003
3004 /* Enable fiber mode, enable and invert sig_det */
3005 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
3006 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X1, &val);
3007 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3008 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X1, val | 0xd);
3009
3010 /* Set Block address to Remote PHY & Set forced_speed[5], 40bit mode */
3011 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
3012 MDIO_WC_REG_DIGITAL4_MISC3, &val);
3013 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3014 MDIO_WC_REG_DIGITAL4_MISC3, val | 0x8080);
3015
3016 /* 10G XFI Full Duplex */
3017 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3018 MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x100);
3019
3020 /* Release tx_fifo_reset */
3021 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
3022 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X3, &val);
3023 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3024 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X3, val & 0xFFFE);
3025
3026 /* Release rxSeqStart */
3027 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
3028 MDIO_WC_REG_DSC2B0_DSC_MISC_CTRL0, &val);
3029 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3030 MDIO_WC_REG_DSC2B0_DSC_MISC_CTRL0, (val & 0x7FFF));
3031}
3032
3033static void bnx2x_warpcore_set_20G_KR2(struct bnx2x *bp,
3034 struct bnx2x_phy *phy)
3035{
3036 DP(NETIF_MSG_LINK, "KR2 still not supported !!!\n");
3037}
3038
3039static void bnx2x_warpcore_set_20G_DXGXS(struct bnx2x *bp,
3040 struct bnx2x_phy *phy,
3041 u16 lane)
3042{
3043 /* Rx0 anaRxControl1G */
3044 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3045 MDIO_WC_REG_RX0_ANARXCONTROL1G, 0x90);
3046
3047 /* Rx2 anaRxControl1G */
3048 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3049 MDIO_WC_REG_RX2_ANARXCONTROL1G, 0x90);
3050
3051 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3052 MDIO_WC_REG_RX66_SCW0, 0xE070);
3053
3054 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3055 MDIO_WC_REG_RX66_SCW1, 0xC0D0);
3056
3057 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3058 MDIO_WC_REG_RX66_SCW2, 0xA0B0);
3059
3060 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3061 MDIO_WC_REG_RX66_SCW3, 0x8090);
3062
3063 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3064 MDIO_WC_REG_RX66_SCW0_MASK, 0xF0F0);
3065
3066 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3067 MDIO_WC_REG_RX66_SCW1_MASK, 0xF0F0);
3068
3069 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3070 MDIO_WC_REG_RX66_SCW2_MASK, 0xF0F0);
3071
3072 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3073 MDIO_WC_REG_RX66_SCW3_MASK, 0xF0F0);
3074
3075 /* Serdes Digital Misc1 */
3076 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3077 MDIO_WC_REG_SERDESDIGITAL_MISC1, 0x6008);
3078
3079 /* Serdes Digital4 Misc3 */
3080 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3081 MDIO_WC_REG_DIGITAL4_MISC3, 0x8088);
3082
3083 /* Set Transmit PMD settings */
3084 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3085 MDIO_WC_REG_TX_FIR_TAP,
3086 ((0x12 << MDIO_WC_REG_TX_FIR_TAP_POST_TAP_OFFSET) |
3087 (0x2d << MDIO_WC_REG_TX_FIR_TAP_MAIN_TAP_OFFSET) |
3088 (0x00 << MDIO_WC_REG_TX_FIR_TAP_PRE_TAP_OFFSET) |
3089 MDIO_WC_REG_TX_FIR_TAP_ENABLE));
3090 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3091 MDIO_WC_REG_TX0_TX_DRIVER + 0x10*lane,
3092 ((0x02 << MDIO_WC_REG_TX0_TX_DRIVER_POST2_COEFF_OFFSET) |
3093 (0x02 << MDIO_WC_REG_TX0_TX_DRIVER_IDRIVER_OFFSET) |
3094 (0x02 << MDIO_WC_REG_TX0_TX_DRIVER_IPRE_DRIVER_OFFSET)));
3095}
3096
3097static void bnx2x_warpcore_set_sgmii_speed(struct bnx2x_phy *phy,
3098 struct link_params *params,
3099 u8 fiber_mode)
3100{
3101 struct bnx2x *bp = params->bp;
3102 u16 val16, digctrl_kx1, digctrl_kx2;
3103 u8 lane;
3104
3105 lane = bnx2x_get_warpcore_lane(phy, params);
3106
3107 /* Clear XFI clock comp in non-10G single lane mode. */
3108 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
3109 MDIO_WC_REG_RX66_CONTROL, &val16);
3110 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3111 MDIO_WC_REG_RX66_CONTROL, val16 & ~(3<<13));
3112
3113 if (phy->req_line_speed == SPEED_AUTO_NEG) {
3114 /* SGMII Autoneg */
3115 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
3116 MDIO_WC_REG_COMBO_IEEE0_MIICTRL, &val16);
3117 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3118 MDIO_WC_REG_COMBO_IEEE0_MIICTRL,
3119 val16 | 0x1000);
3120 DP(NETIF_MSG_LINK, "set SGMII AUTONEG\n");
3121 } else {
3122 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
3123 MDIO_WC_REG_COMBO_IEEE0_MIICTRL, &val16);
3124 val16 &= 0xcfbf;
3125 switch (phy->req_line_speed) {
3126 case SPEED_10:
3127 break;
3128 case SPEED_100:
3129 val16 |= 0x2000;
3130 break;
3131 case SPEED_1000:
3132 val16 |= 0x0040;
3133 break;
3134 default:
3135 DP(NETIF_MSG_LINK, "Speed not supported: 0x%x"
3136 "\n", phy->req_line_speed);
3137 return;
3138 }
3139
3140 if (phy->req_duplex == DUPLEX_FULL)
3141 val16 |= 0x0100;
3142
3143 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3144 MDIO_WC_REG_COMBO_IEEE0_MIICTRL, val16);
3145
3146 DP(NETIF_MSG_LINK, "set SGMII force speed %d\n",
3147 phy->req_line_speed);
3148 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
3149 MDIO_WC_REG_COMBO_IEEE0_MIICTRL, &val16);
3150 DP(NETIF_MSG_LINK, " (readback) %x\n", val16);
3151 }
3152
3153 /* SGMII Slave mode and disable signal detect */
3154 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
3155 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X1, &digctrl_kx1);
3156 if (fiber_mode)
3157 digctrl_kx1 = 1;
3158 else
3159 digctrl_kx1 &= 0xff4a;
3160
3161 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3162 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X1,
3163 digctrl_kx1);
3164
3165 /* Turn off parallel detect */
3166 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
3167 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2, &digctrl_kx2);
3168 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3169 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2,
3170 (digctrl_kx2 & ~(1<<2)));
3171
3172 /* Re-enable parallel detect */
3173 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3174 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2,
3175 (digctrl_kx2 | (1<<2)));
3176
3177 /* Enable autodet */
3178 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3179 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X1,
3180 (digctrl_kx1 | 0x10));
3181}
3182
3183static void bnx2x_warpcore_reset_lane(struct bnx2x *bp,
3184 struct bnx2x_phy *phy,
3185 u8 reset)
3186{
3187 u16 val;
3188 /* Take lane out of reset after configuration is finished */
3189 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
3190 MDIO_WC_REG_DIGITAL5_MISC6, &val);
3191 if (reset)
3192 val |= 0xC000;
3193 else
3194 val &= 0x3FFF;
3195 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3196 MDIO_WC_REG_DIGITAL5_MISC6, val);
3197 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
3198 MDIO_WC_REG_DIGITAL5_MISC6, &val);
3199}
3200
3201
3202 /* Clear SFI/XFI link settings registers */
3203static void bnx2x_warpcore_clear_regs(struct bnx2x_phy *phy,
3204 struct link_params *params,
3205 u16 lane)
3206{
3207 struct bnx2x *bp = params->bp;
3208 u16 val16;
3209
3210 /* Set XFI clock comp as default. */
3211 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
3212 MDIO_WC_REG_RX66_CONTROL, &val16);
3213 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3214 MDIO_WC_REG_RX66_CONTROL, val16 | (3<<13));
3215
3216 bnx2x_warpcore_reset_lane(bp, phy, 1);
3217 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0);
3218 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3219 MDIO_WC_REG_FX100_CTRL1, 0x014a);
3220 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3221 MDIO_WC_REG_FX100_CTRL3, 0x0800);
3222 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3223 MDIO_WC_REG_DIGITAL4_MISC3, 0x8008);
3224 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3225 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X1, 0x0195);
3226 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3227 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2, 0x0007);
3228 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3229 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X3, 0x0002);
3230 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3231 MDIO_WC_REG_SERDESDIGITAL_MISC1, 0x6000);
3232 lane = bnx2x_get_warpcore_lane(phy, params);
3233 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3234 MDIO_WC_REG_TX_FIR_TAP, 0x0000);
3235 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3236 MDIO_WC_REG_TX0_TX_DRIVER + 0x10*lane, 0x0990);
3237 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3238 MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x2040);
3239 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3240 MDIO_WC_REG_COMBO_IEEE0_MIICTRL, 0x0140);
3241 bnx2x_warpcore_reset_lane(bp, phy, 0);
3242}
3243
3244static int bnx2x_get_mod_abs_int_cfg(struct bnx2x *bp,
3245 u32 chip_id,
3246 u32 shmem_base, u8 port,
3247 u8 *gpio_num, u8 *gpio_port)
3248{
3249 u32 cfg_pin;
3250 *gpio_num = 0;
3251 *gpio_port = 0;
3252 if (CHIP_IS_E3(bp)) {
3253 cfg_pin = (REG_RD(bp, shmem_base +
3254 offsetof(struct shmem_region,
3255 dev_info.port_hw_config[port].e3_sfp_ctrl)) &
3256 PORT_HW_CFG_E3_MOD_ABS_MASK) >>
3257 PORT_HW_CFG_E3_MOD_ABS_SHIFT;
3258
3259 /*
3260 * Should not happen. This function called upon interrupt
3261 * triggered by GPIO ( since EPIO can only generate interrupts
3262 * to MCP).
3263 * So if this function was called and none of the GPIOs was set,
3264 * it means the shit hit the fan.
3265 */
3266 if ((cfg_pin < PIN_CFG_GPIO0_P0) ||
3267 (cfg_pin > PIN_CFG_GPIO3_P1)) {
3268 DP(NETIF_MSG_LINK, "ERROR: Invalid cfg pin %x for "
3269 "module detect indication\n",
3270 cfg_pin);
3271 return -EINVAL;
3272 }
3273
3274 *gpio_num = (cfg_pin - PIN_CFG_GPIO0_P0) & 0x3;
3275 *gpio_port = (cfg_pin - PIN_CFG_GPIO0_P0) >> 2;
3276 } else {
3277 *gpio_num = MISC_REGISTERS_GPIO_3;
3278 *gpio_port = port;
3279 }
3280 DP(NETIF_MSG_LINK, "MOD_ABS int GPIO%d_P%d\n", *gpio_num, *gpio_port);
3281 return 0;
3282}
3283
3284static int bnx2x_is_sfp_module_plugged(struct bnx2x_phy *phy,
3285 struct link_params *params)
3286{
3287 struct bnx2x *bp = params->bp;
3288 u8 gpio_num, gpio_port;
3289 u32 gpio_val;
3290 if (bnx2x_get_mod_abs_int_cfg(bp, params->chip_id,
3291 params->shmem_base, params->port,
3292 &gpio_num, &gpio_port) != 0)
3293 return 0;
3294 gpio_val = bnx2x_get_gpio(bp, gpio_num, gpio_port);
3295
3296 /* Call the handling function in case module is detected */
3297 if (gpio_val == 0)
3298 return 1;
3299 else
3300 return 0;
3301}
3302
3303static void bnx2x_warpcore_config_init(struct bnx2x_phy *phy,
3304 struct link_params *params,
3305 struct link_vars *vars)
3306{
3307 struct bnx2x *bp = params->bp;
3308 u32 serdes_net_if;
3309 u8 fiber_mode;
3310 u16 lane = bnx2x_get_warpcore_lane(phy, params);
3311 serdes_net_if = (REG_RD(bp, params->shmem_base +
3312 offsetof(struct shmem_region, dev_info.
3313 port_hw_config[params->port].default_cfg)) &
3314 PORT_HW_CFG_NET_SERDES_IF_MASK);
3315 DP(NETIF_MSG_LINK, "Begin Warpcore init, link_speed %d, "
3316 "serdes_net_if = 0x%x\n",
3317 vars->line_speed, serdes_net_if);
3318 bnx2x_set_aer_mmd(params, phy);
3319
3320 vars->phy_flags |= PHY_XGXS_FLAG;
3321 if ((serdes_net_if == PORT_HW_CFG_NET_SERDES_IF_SGMII) ||
3322 (phy->req_line_speed &&
3323 ((phy->req_line_speed == SPEED_100) ||
3324 (phy->req_line_speed == SPEED_10)))) {
3325 vars->phy_flags |= PHY_SGMII_FLAG;
3326 DP(NETIF_MSG_LINK, "Setting SGMII mode\n");
3327 bnx2x_warpcore_clear_regs(phy, params, lane);
3328 bnx2x_warpcore_set_sgmii_speed(phy, params, 0);
3329 } else {
3330 switch (serdes_net_if) {
3331 case PORT_HW_CFG_NET_SERDES_IF_KR:
3332 /* Enable KR Auto Neg */
3333 if (params->loopback_mode == LOOPBACK_NONE)
3334 bnx2x_warpcore_enable_AN_KR(phy, params, vars);
3335 else {
3336 DP(NETIF_MSG_LINK, "Setting KR 10G-Force\n");
3337 bnx2x_warpcore_set_10G_KR(phy, params, vars);
3338 }
3339 break;
3340
3341 case PORT_HW_CFG_NET_SERDES_IF_XFI:
3342 bnx2x_warpcore_clear_regs(phy, params, lane);
3343 if (vars->line_speed == SPEED_10000) {
3344 DP(NETIF_MSG_LINK, "Setting 10G XFI\n");
3345 bnx2x_warpcore_set_10G_XFI(phy, params, 1);
3346 } else {
3347 if (SINGLE_MEDIA_DIRECT(params)) {
3348 DP(NETIF_MSG_LINK, "1G Fiber\n");
3349 fiber_mode = 1;
3350 } else {
3351 DP(NETIF_MSG_LINK, "10/100/1G SGMII\n");
3352 fiber_mode = 0;
3353 }
3354 bnx2x_warpcore_set_sgmii_speed(phy,
3355 params,
3356 fiber_mode);
3357 }
3358
3359 break;
3360
3361 case PORT_HW_CFG_NET_SERDES_IF_SFI:
3362
3363 bnx2x_warpcore_clear_regs(phy, params, lane);
3364 if (vars->line_speed == SPEED_10000) {
3365 DP(NETIF_MSG_LINK, "Setting 10G SFI\n");
3366 bnx2x_warpcore_set_10G_XFI(phy, params, 0);
3367 } else if (vars->line_speed == SPEED_1000) {
3368 DP(NETIF_MSG_LINK, "Setting 1G Fiber\n");
3369 bnx2x_warpcore_set_sgmii_speed(phy, params, 1);
3370 }
3371 /* Issue Module detection */
3372 if (bnx2x_is_sfp_module_plugged(phy, params))
3373 bnx2x_sfp_module_detection(phy, params);
3374 break;
3375
3376 case PORT_HW_CFG_NET_SERDES_IF_DXGXS:
3377 if (vars->line_speed != SPEED_20000) {
3378 DP(NETIF_MSG_LINK, "Speed not supported yet\n");
3379 return;
3380 }
3381 DP(NETIF_MSG_LINK, "Setting 20G DXGXS\n");
3382 bnx2x_warpcore_set_20G_DXGXS(bp, phy, lane);
3383 /* Issue Module detection */
3384
3385 bnx2x_sfp_module_detection(phy, params);
3386 break;
3387
3388 case PORT_HW_CFG_NET_SERDES_IF_KR2:
3389 if (vars->line_speed != SPEED_20000) {
3390 DP(NETIF_MSG_LINK, "Speed not supported yet\n");
3391 return;
3392 }
3393 DP(NETIF_MSG_LINK, "Setting 20G KR2\n");
3394 bnx2x_warpcore_set_20G_KR2(bp, phy);
3395 break;
3396
3397 default:
3398 DP(NETIF_MSG_LINK, "Unsupported Serdes Net Interface "
3399 "0x%x\n", serdes_net_if);
3400 return;
3401 }
3402 }
3403
3404 /* Take lane out of reset after configuration is finished */
3405 bnx2x_warpcore_reset_lane(bp, phy, 0);
3406 DP(NETIF_MSG_LINK, "Exit config init\n");
3407}
3408
3409static void bnx2x_sfp_e3_set_transmitter(struct link_params *params,
3410 struct bnx2x_phy *phy,
3411 u8 tx_en)
3412{
3413 struct bnx2x *bp = params->bp;
3414 u32 cfg_pin;
3415 u8 port = params->port;
3416
3417 cfg_pin = REG_RD(bp, params->shmem_base +
3418 offsetof(struct shmem_region,
3419 dev_info.port_hw_config[port].e3_sfp_ctrl)) &
3420 PORT_HW_CFG_TX_LASER_MASK;
3421 /* Set the !tx_en since this pin is DISABLE_TX_LASER */
3422 DP(NETIF_MSG_LINK, "Setting WC TX to %d\n", tx_en);
3423 /* For 20G, the expected pin to be used is 3 pins after the current */
3424
3425 bnx2x_set_cfg_pin(bp, cfg_pin, tx_en ^ 1);
3426 if (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_20G)
3427 bnx2x_set_cfg_pin(bp, cfg_pin + 3, tx_en ^ 1);
3428}
3429
3430static void bnx2x_warpcore_link_reset(struct bnx2x_phy *phy,
3431 struct link_params *params)
3432{
3433 struct bnx2x *bp = params->bp;
3434 u16 val16;
3435 bnx2x_sfp_e3_set_transmitter(params, phy, 0);
3436 bnx2x_set_mdio_clk(bp, params->chip_id, params->port);
3437 bnx2x_set_aer_mmd(params, phy);
3438 /* Global register */
3439 bnx2x_warpcore_reset_lane(bp, phy, 1);
3440
3441 /* Clear loopback settings (if any) */
3442 /* 10G & 20G */
3443 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
3444 MDIO_WC_REG_COMBO_IEEE0_MIICTRL, &val16);
3445 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3446 MDIO_WC_REG_COMBO_IEEE0_MIICTRL, val16 &
3447 0xBFFF);
3448
3449 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
3450 MDIO_WC_REG_IEEE0BLK_MIICNTL, &val16);
3451 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3452 MDIO_WC_REG_IEEE0BLK_MIICNTL, val16 & 0xfffe);
3453
3454 /* Update those 1-copy registers */
3455 CL22_WR_OVER_CL45(bp, phy, MDIO_REG_BANK_AER_BLOCK,
3456 MDIO_AER_BLOCK_AER_REG, 0);
3457 /* Enable 1G MDIO (1-copy) */
3458 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
3459 MDIO_WC_REG_XGXSBLK0_XGXSCONTROL,
3460 &val16);
3461 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3462 MDIO_WC_REG_XGXSBLK0_XGXSCONTROL,
3463 val16 & ~0x10);
3464
3465 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
3466 MDIO_WC_REG_XGXSBLK1_LANECTRL2, &val16);
3467 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3468 MDIO_WC_REG_XGXSBLK1_LANECTRL2,
3469 val16 & 0xff00);
3470
3471}
3472
3473static void bnx2x_set_warpcore_loopback(struct bnx2x_phy *phy,
3474 struct link_params *params)
3475{
3476 struct bnx2x *bp = params->bp;
3477 u16 val16;
3478 u32 lane;
3479 DP(NETIF_MSG_LINK, "Setting Warpcore loopback type %x, speed %d\n",
3480 params->loopback_mode, phy->req_line_speed);
3481
3482 if (phy->req_line_speed < SPEED_10000) {
3483 /* 10/100/1000 */
3484
3485 /* Update those 1-copy registers */
3486 CL22_WR_OVER_CL45(bp, phy, MDIO_REG_BANK_AER_BLOCK,
3487 MDIO_AER_BLOCK_AER_REG, 0);
3488 /* Enable 1G MDIO (1-copy) */
3489 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
3490 MDIO_WC_REG_XGXSBLK0_XGXSCONTROL,
3491 &val16);
3492 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3493 MDIO_WC_REG_XGXSBLK0_XGXSCONTROL,
3494 val16 | 0x10);
3495 /* Set 1G loopback based on lane (1-copy) */
3496 lane = bnx2x_get_warpcore_lane(phy, params);
3497 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
3498 MDIO_WC_REG_XGXSBLK1_LANECTRL2, &val16);
3499 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3500 MDIO_WC_REG_XGXSBLK1_LANECTRL2,
3501 val16 | (1<<lane));
3502
3503 /* Switch back to 4-copy registers */
3504 bnx2x_set_aer_mmd(params, phy);
3505 /* Global loopback, not recommended. */
3506 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
3507 MDIO_WC_REG_COMBO_IEEE0_MIICTRL, &val16);
3508 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3509 MDIO_WC_REG_COMBO_IEEE0_MIICTRL, val16 |
3510 0x4000);
3511 } else {
3512 /* 10G & 20G */
3513 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
3514 MDIO_WC_REG_COMBO_IEEE0_MIICTRL, &val16);
3515 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3516 MDIO_WC_REG_COMBO_IEEE0_MIICTRL, val16 |
3517 0x4000);
3518
3519 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
3520 MDIO_WC_REG_IEEE0BLK_MIICNTL, &val16);
3521 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3522 MDIO_WC_REG_IEEE0BLK_MIICNTL, val16 | 0x1);
3523 }
3524}
3525
3526
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003527void bnx2x_link_status_update(struct link_params *params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003528 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003529{
3530 struct bnx2x *bp = params->bp;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00003531 u8 link_10g_plus;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003532 u8 port = params->port;
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00003533 u32 sync_offset, media_types;
Yaniv Rosnerfd36a2e2011-05-31 21:29:05 +00003534 /* Update PHY configuration */
3535 set_phy_vars(params, vars);
3536
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003537 vars->link_status = REG_RD(bp, params->shmem_base +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003538 offsetof(struct shmem_region,
3539 port_mb[port].link_status));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003540
3541 vars->link_up = (vars->link_status & LINK_STATUS_LINK_UP);
Yaniv Rosnerfd36a2e2011-05-31 21:29:05 +00003542 vars->phy_flags = PHY_XGXS_FLAG;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003543 if (vars->link_up) {
3544 DP(NETIF_MSG_LINK, "phy link up\n");
3545
3546 vars->phy_link_up = 1;
3547 vars->duplex = DUPLEX_FULL;
3548 switch (vars->link_status &
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003549 LINK_STATUS_SPEED_AND_DUPLEX_MASK) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003550 case LINK_10THD:
3551 vars->duplex = DUPLEX_HALF;
3552 /* fall thru */
3553 case LINK_10TFD:
3554 vars->line_speed = SPEED_10;
3555 break;
3556
3557 case LINK_100TXHD:
3558 vars->duplex = DUPLEX_HALF;
3559 /* fall thru */
3560 case LINK_100T4:
3561 case LINK_100TXFD:
3562 vars->line_speed = SPEED_100;
3563 break;
3564
3565 case LINK_1000THD:
3566 vars->duplex = DUPLEX_HALF;
3567 /* fall thru */
3568 case LINK_1000TFD:
3569 vars->line_speed = SPEED_1000;
3570 break;
3571
3572 case LINK_2500THD:
3573 vars->duplex = DUPLEX_HALF;
3574 /* fall thru */
3575 case LINK_2500TFD:
3576 vars->line_speed = SPEED_2500;
3577 break;
3578
3579 case LINK_10GTFD:
3580 vars->line_speed = SPEED_10000;
3581 break;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003582 case LINK_20GTFD:
3583 vars->line_speed = SPEED_20000;
3584 break;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003585 default:
3586 break;
3587 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003588 vars->flow_ctrl = 0;
3589 if (vars->link_status & LINK_STATUS_TX_FLOW_CONTROL_ENABLED)
3590 vars->flow_ctrl |= BNX2X_FLOW_CTRL_TX;
3591
3592 if (vars->link_status & LINK_STATUS_RX_FLOW_CONTROL_ENABLED)
3593 vars->flow_ctrl |= BNX2X_FLOW_CTRL_RX;
3594
3595 if (!vars->flow_ctrl)
3596 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
3597
3598 if (vars->line_speed &&
3599 ((vars->line_speed == SPEED_10) ||
3600 (vars->line_speed == SPEED_100))) {
3601 vars->phy_flags |= PHY_SGMII_FLAG;
3602 } else {
3603 vars->phy_flags &= ~PHY_SGMII_FLAG;
3604 }
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003605 if (vars->line_speed &&
3606 USES_WARPCORE(bp) &&
3607 (vars->line_speed == SPEED_1000))
3608 vars->phy_flags |= PHY_SGMII_FLAG;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003609 /* anything 10 and over uses the bmac */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00003610 link_10g_plus = (vars->line_speed >= SPEED_10000);
3611
3612 if (link_10g_plus) {
3613 if (USES_WARPCORE(bp))
3614 vars->mac_type = MAC_TYPE_XMAC;
3615 else
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003616 vars->mac_type = MAC_TYPE_BMAC;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00003617 } else {
3618 if (USES_WARPCORE(bp))
3619 vars->mac_type = MAC_TYPE_UMAC;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003620 else
3621 vars->mac_type = MAC_TYPE_EMAC;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00003622 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003623 } else { /* link down */
3624 DP(NETIF_MSG_LINK, "phy link down\n");
3625
3626 vars->phy_link_up = 0;
3627
3628 vars->line_speed = 0;
3629 vars->duplex = DUPLEX_FULL;
3630 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
3631
3632 /* indicate no mac active */
3633 vars->mac_type = MAC_TYPE_NONE;
3634 }
3635
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00003636 /* Sync media type */
3637 sync_offset = params->shmem_base +
3638 offsetof(struct shmem_region,
3639 dev_info.port_hw_config[port].media_type);
3640 media_types = REG_RD(bp, sync_offset);
3641
3642 params->phy[INT_PHY].media_type =
3643 (media_types & PORT_HW_CFG_MEDIA_TYPE_PHY0_MASK) >>
3644 PORT_HW_CFG_MEDIA_TYPE_PHY0_SHIFT;
3645 params->phy[EXT_PHY1].media_type =
3646 (media_types & PORT_HW_CFG_MEDIA_TYPE_PHY1_MASK) >>
3647 PORT_HW_CFG_MEDIA_TYPE_PHY1_SHIFT;
3648 params->phy[EXT_PHY2].media_type =
3649 (media_types & PORT_HW_CFG_MEDIA_TYPE_PHY2_MASK) >>
3650 PORT_HW_CFG_MEDIA_TYPE_PHY2_SHIFT;
3651 DP(NETIF_MSG_LINK, "media_types = 0x%x\n", media_types);
3652
Yaniv Rosner020c7e32011-05-31 21:28:43 +00003653 /* Sync AEU offset */
3654 sync_offset = params->shmem_base +
3655 offsetof(struct shmem_region,
3656 dev_info.port_hw_config[port].aeu_int_mask);
3657
3658 vars->aeu_int_mask = REG_RD(bp, sync_offset);
3659
3660 DP(NETIF_MSG_LINK, "link_status 0x%x phy_link_up %x int_mask 0x%x\n",
3661 vars->link_status, vars->phy_link_up, vars->aeu_int_mask);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003662 DP(NETIF_MSG_LINK, "line_speed %x duplex %x flow_ctrl 0x%x\n",
3663 vars->line_speed, vars->duplex, vars->flow_ctrl);
3664}
3665
3666
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003667static void bnx2x_set_master_ln(struct link_params *params,
3668 struct bnx2x_phy *phy)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003669{
3670 struct bnx2x *bp = params->bp;
3671 u16 new_master_ln, ser_lane;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003672 ser_lane = ((params->lane_config &
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003673 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_MASK) >>
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003674 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_SHIFT);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003675
3676 /* set the master_ln for AN */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00003677 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003678 MDIO_REG_BANK_XGXS_BLOCK2,
3679 MDIO_XGXS_BLOCK2_TEST_MODE_LANE,
3680 &new_master_ln);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003681
Yaniv Rosnercd2be892011-01-31 04:21:45 +00003682 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003683 MDIO_REG_BANK_XGXS_BLOCK2 ,
3684 MDIO_XGXS_BLOCK2_TEST_MODE_LANE,
3685 (new_master_ln | ser_lane));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003686}
3687
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00003688static int bnx2x_reset_unicore(struct link_params *params,
3689 struct bnx2x_phy *phy,
3690 u8 set_serdes)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003691{
3692 struct bnx2x *bp = params->bp;
3693 u16 mii_control;
3694 u16 i;
Yaniv Rosnercd2be892011-01-31 04:21:45 +00003695 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003696 MDIO_REG_BANK_COMBO_IEEE0,
3697 MDIO_COMBO_IEEE0_MII_CONTROL, &mii_control);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003698
3699 /* reset the unicore */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00003700 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003701 MDIO_REG_BANK_COMBO_IEEE0,
3702 MDIO_COMBO_IEEE0_MII_CONTROL,
3703 (mii_control |
3704 MDIO_COMBO_IEEO_MII_CONTROL_RESET));
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003705 if (set_serdes)
3706 bnx2x_set_serdes_access(bp, params->port);
Eilon Greensteinc1b73992009-02-12 08:37:07 +00003707
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003708 /* wait for the reset to self clear */
3709 for (i = 0; i < MDIO_ACCESS_TIMEOUT; i++) {
3710 udelay(5);
3711
3712 /* the reset erased the previous bank value */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00003713 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003714 MDIO_REG_BANK_COMBO_IEEE0,
3715 MDIO_COMBO_IEEE0_MII_CONTROL,
3716 &mii_control);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003717
3718 if (!(mii_control & MDIO_COMBO_IEEO_MII_CONTROL_RESET)) {
3719 udelay(5);
3720 return 0;
3721 }
3722 }
3723
Yaniv Rosner6d870c32011-01-31 04:22:20 +00003724 netdev_err(bp->dev, "Warning: PHY was not initialized,"
3725 " Port %d\n",
3726 params->port);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003727 DP(NETIF_MSG_LINK, "BUG! XGXS is still in reset!\n");
3728 return -EINVAL;
3729
3730}
3731
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003732static void bnx2x_set_swap_lanes(struct link_params *params,
3733 struct bnx2x_phy *phy)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003734{
3735 struct bnx2x *bp = params->bp;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003736 /*
3737 * Each two bits represents a lane number:
3738 * No swap is 0123 => 0x1b no need to enable the swap
3739 */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003740 u16 ser_lane, rx_lane_swap, tx_lane_swap;
3741
3742 ser_lane = ((params->lane_config &
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003743 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_MASK) >>
3744 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_SHIFT);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003745 rx_lane_swap = ((params->lane_config &
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003746 PORT_HW_CFG_LANE_SWAP_CFG_RX_MASK) >>
3747 PORT_HW_CFG_LANE_SWAP_CFG_RX_SHIFT);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003748 tx_lane_swap = ((params->lane_config &
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003749 PORT_HW_CFG_LANE_SWAP_CFG_TX_MASK) >>
3750 PORT_HW_CFG_LANE_SWAP_CFG_TX_SHIFT);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003751
3752 if (rx_lane_swap != 0x1b) {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00003753 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003754 MDIO_REG_BANK_XGXS_BLOCK2,
3755 MDIO_XGXS_BLOCK2_RX_LN_SWAP,
3756 (rx_lane_swap |
3757 MDIO_XGXS_BLOCK2_RX_LN_SWAP_ENABLE |
3758 MDIO_XGXS_BLOCK2_RX_LN_SWAP_FORCE_ENABLE));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003759 } else {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00003760 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003761 MDIO_REG_BANK_XGXS_BLOCK2,
3762 MDIO_XGXS_BLOCK2_RX_LN_SWAP, 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003763 }
3764
3765 if (tx_lane_swap != 0x1b) {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00003766 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003767 MDIO_REG_BANK_XGXS_BLOCK2,
3768 MDIO_XGXS_BLOCK2_TX_LN_SWAP,
3769 (tx_lane_swap |
3770 MDIO_XGXS_BLOCK2_TX_LN_SWAP_ENABLE));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003771 } else {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00003772 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003773 MDIO_REG_BANK_XGXS_BLOCK2,
3774 MDIO_XGXS_BLOCK2_TX_LN_SWAP, 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003775 }
3776}
3777
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003778static void bnx2x_set_parallel_detection(struct bnx2x_phy *phy,
3779 struct link_params *params)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003780{
3781 struct bnx2x *bp = params->bp;
3782 u16 control2;
Yaniv Rosnercd2be892011-01-31 04:21:45 +00003783 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003784 MDIO_REG_BANK_SERDES_DIGITAL,
3785 MDIO_SERDES_DIGITAL_A_1000X_CONTROL2,
3786 &control2);
Yaniv Rosner7aa07112010-09-07 11:41:01 +00003787 if (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)
Yaniv Rosner18afb0a2009-11-05 19:18:04 +02003788 control2 |= MDIO_SERDES_DIGITAL_A_1000X_CONTROL2_PRL_DT_EN;
3789 else
3790 control2 &= ~MDIO_SERDES_DIGITAL_A_1000X_CONTROL2_PRL_DT_EN;
Yaniv Rosner7aa07112010-09-07 11:41:01 +00003791 DP(NETIF_MSG_LINK, "phy->speed_cap_mask = 0x%x, control2 = 0x%x\n",
3792 phy->speed_cap_mask, control2);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00003793 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003794 MDIO_REG_BANK_SERDES_DIGITAL,
3795 MDIO_SERDES_DIGITAL_A_1000X_CONTROL2,
3796 control2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003797
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003798 if ((phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT) &&
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00003799 (phy->speed_cap_mask &
Yaniv Rosner18afb0a2009-11-05 19:18:04 +02003800 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003801 DP(NETIF_MSG_LINK, "XGXS\n");
3802
Yaniv Rosnercd2be892011-01-31 04:21:45 +00003803 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003804 MDIO_REG_BANK_10G_PARALLEL_DETECT,
3805 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_LINK,
3806 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_LINK_CNT);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003807
Yaniv Rosnercd2be892011-01-31 04:21:45 +00003808 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003809 MDIO_REG_BANK_10G_PARALLEL_DETECT,
3810 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_CONTROL,
3811 &control2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003812
3813
3814 control2 |=
3815 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_CONTROL_PARDET10G_EN;
3816
Yaniv Rosnercd2be892011-01-31 04:21:45 +00003817 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003818 MDIO_REG_BANK_10G_PARALLEL_DETECT,
3819 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_CONTROL,
3820 control2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003821
3822 /* Disable parallel detection of HiG */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00003823 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003824 MDIO_REG_BANK_XGXS_BLOCK2,
3825 MDIO_XGXS_BLOCK2_UNICORE_MODE_10G,
3826 MDIO_XGXS_BLOCK2_UNICORE_MODE_10G_CX4_XGXS |
3827 MDIO_XGXS_BLOCK2_UNICORE_MODE_10G_HIGIG_XGXS);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003828 }
3829}
3830
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003831static void bnx2x_set_autoneg(struct bnx2x_phy *phy,
3832 struct link_params *params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003833 struct link_vars *vars,
3834 u8 enable_cl73)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003835{
3836 struct bnx2x *bp = params->bp;
3837 u16 reg_val;
3838
3839 /* CL37 Autoneg */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00003840 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003841 MDIO_REG_BANK_COMBO_IEEE0,
3842 MDIO_COMBO_IEEE0_MII_CONTROL, &reg_val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003843
3844 /* CL37 Autoneg Enabled */
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07003845 if (vars->line_speed == SPEED_AUTO_NEG)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003846 reg_val |= MDIO_COMBO_IEEO_MII_CONTROL_AN_EN;
3847 else /* CL37 Autoneg Disabled */
3848 reg_val &= ~(MDIO_COMBO_IEEO_MII_CONTROL_AN_EN |
3849 MDIO_COMBO_IEEO_MII_CONTROL_RESTART_AN);
3850
Yaniv Rosnercd2be892011-01-31 04:21:45 +00003851 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003852 MDIO_REG_BANK_COMBO_IEEE0,
3853 MDIO_COMBO_IEEE0_MII_CONTROL, reg_val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003854
3855 /* Enable/Disable Autodetection */
3856
Yaniv Rosnercd2be892011-01-31 04:21:45 +00003857 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003858 MDIO_REG_BANK_SERDES_DIGITAL,
3859 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1, &reg_val);
Eilon Greenstein239d6862009-08-12 08:23:04 +00003860 reg_val &= ~(MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_SIGNAL_DETECT_EN |
3861 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_INVERT_SIGNAL_DETECT);
3862 reg_val |= MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_FIBER_MODE;
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07003863 if (vars->line_speed == SPEED_AUTO_NEG)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003864 reg_val |= MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_AUTODET;
3865 else
3866 reg_val &= ~MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_AUTODET;
3867
Yaniv Rosnercd2be892011-01-31 04:21:45 +00003868 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003869 MDIO_REG_BANK_SERDES_DIGITAL,
3870 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1, reg_val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003871
3872 /* Enable TetonII and BAM autoneg */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00003873 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003874 MDIO_REG_BANK_BAM_NEXT_PAGE,
3875 MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL,
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003876 &reg_val);
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07003877 if (vars->line_speed == SPEED_AUTO_NEG) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003878 /* Enable BAM aneg Mode and TetonII aneg Mode */
3879 reg_val |= (MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL_BAM_MODE |
3880 MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL_TETON_AN);
3881 } else {
3882 /* TetonII and BAM Autoneg Disabled */
3883 reg_val &= ~(MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL_BAM_MODE |
3884 MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL_TETON_AN);
3885 }
Yaniv Rosnercd2be892011-01-31 04:21:45 +00003886 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003887 MDIO_REG_BANK_BAM_NEXT_PAGE,
3888 MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL,
3889 reg_val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003890
Eilon Greenstein239d6862009-08-12 08:23:04 +00003891 if (enable_cl73) {
3892 /* Enable Cl73 FSM status bits */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00003893 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003894 MDIO_REG_BANK_CL73_USERB0,
3895 MDIO_CL73_USERB0_CL73_UCTRL,
3896 0xe);
Eilon Greenstein239d6862009-08-12 08:23:04 +00003897
3898 /* Enable BAM Station Manager*/
Yaniv Rosnercd2be892011-01-31 04:21:45 +00003899 CL22_WR_OVER_CL45(bp, phy,
Eilon Greenstein239d6862009-08-12 08:23:04 +00003900 MDIO_REG_BANK_CL73_USERB0,
3901 MDIO_CL73_USERB0_CL73_BAM_CTRL1,
3902 MDIO_CL73_USERB0_CL73_BAM_CTRL1_BAM_EN |
3903 MDIO_CL73_USERB0_CL73_BAM_CTRL1_BAM_STATION_MNGR_EN |
3904 MDIO_CL73_USERB0_CL73_BAM_CTRL1_BAM_NP_AFTER_BP_EN);
3905
Yaniv Rosner7846e472009-11-05 19:18:07 +02003906 /* Advertise CL73 link speeds */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00003907 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003908 MDIO_REG_BANK_CL73_IEEEB1,
3909 MDIO_CL73_IEEEB1_AN_ADV2,
3910 &reg_val);
Yaniv Rosner7aa07112010-09-07 11:41:01 +00003911 if (phy->speed_cap_mask &
Yaniv Rosner7846e472009-11-05 19:18:07 +02003912 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
3913 reg_val |= MDIO_CL73_IEEEB1_AN_ADV2_ADVR_10G_KX4;
Yaniv Rosner7aa07112010-09-07 11:41:01 +00003914 if (phy->speed_cap_mask &
Yaniv Rosner7846e472009-11-05 19:18:07 +02003915 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)
3916 reg_val |= MDIO_CL73_IEEEB1_AN_ADV2_ADVR_1000M_KX;
Eilon Greenstein239d6862009-08-12 08:23:04 +00003917
Yaniv Rosnercd2be892011-01-31 04:21:45 +00003918 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003919 MDIO_REG_BANK_CL73_IEEEB1,
3920 MDIO_CL73_IEEEB1_AN_ADV2,
3921 reg_val);
Eilon Greenstein239d6862009-08-12 08:23:04 +00003922
Eilon Greenstein239d6862009-08-12 08:23:04 +00003923 /* CL73 Autoneg Enabled */
3924 reg_val = MDIO_CL73_IEEEB0_CL73_AN_CONTROL_AN_EN;
3925
3926 } else /* CL73 Autoneg Disabled */
3927 reg_val = 0;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003928
Yaniv Rosnercd2be892011-01-31 04:21:45 +00003929 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003930 MDIO_REG_BANK_CL73_IEEEB0,
3931 MDIO_CL73_IEEEB0_CL73_AN_CONTROL, reg_val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003932}
3933
3934/* program SerDes, forced speed */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003935static void bnx2x_program_serdes(struct bnx2x_phy *phy,
3936 struct link_params *params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003937 struct link_vars *vars)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003938{
3939 struct bnx2x *bp = params->bp;
3940 u16 reg_val;
3941
Eilon Greenstein57937202009-08-12 08:23:53 +00003942 /* program duplex, disable autoneg and sgmii*/
Yaniv Rosnercd2be892011-01-31 04:21:45 +00003943 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003944 MDIO_REG_BANK_COMBO_IEEE0,
3945 MDIO_COMBO_IEEE0_MII_CONTROL, &reg_val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003946 reg_val &= ~(MDIO_COMBO_IEEO_MII_CONTROL_FULL_DUPLEX |
Eilon Greenstein57937202009-08-12 08:23:53 +00003947 MDIO_COMBO_IEEO_MII_CONTROL_AN_EN |
3948 MDIO_COMBO_IEEO_MII_CONTROL_MAN_SGMII_SP_MASK);
Yaniv Rosner7aa07112010-09-07 11:41:01 +00003949 if (phy->req_duplex == DUPLEX_FULL)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003950 reg_val |= MDIO_COMBO_IEEO_MII_CONTROL_FULL_DUPLEX;
Yaniv Rosnercd2be892011-01-31 04:21:45 +00003951 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003952 MDIO_REG_BANK_COMBO_IEEE0,
3953 MDIO_COMBO_IEEE0_MII_CONTROL, reg_val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003954
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003955 /*
3956 * program speed
3957 * - needed only if the speed is greater than 1G (2.5G or 10G)
3958 */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00003959 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003960 MDIO_REG_BANK_SERDES_DIGITAL,
3961 MDIO_SERDES_DIGITAL_MISC1, &reg_val);
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07003962 /* clearing the speed value before setting the right speed */
3963 DP(NETIF_MSG_LINK, "MDIO_REG_BANK_SERDES_DIGITAL = 0x%x\n", reg_val);
3964
3965 reg_val &= ~(MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_MASK |
3966 MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_SEL);
3967
3968 if (!((vars->line_speed == SPEED_1000) ||
3969 (vars->line_speed == SPEED_100) ||
3970 (vars->line_speed == SPEED_10))) {
3971
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003972 reg_val |= (MDIO_SERDES_DIGITAL_MISC1_REFCLK_SEL_156_25M |
3973 MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_SEL);
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07003974 if (vars->line_speed == SPEED_10000)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003975 reg_val |=
3976 MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_10G_CX4;
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07003977 }
3978
Yaniv Rosnercd2be892011-01-31 04:21:45 +00003979 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003980 MDIO_REG_BANK_SERDES_DIGITAL,
3981 MDIO_SERDES_DIGITAL_MISC1, reg_val);
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07003982
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003983}
3984
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00003985static void bnx2x_set_brcm_cl37_advertisement(struct bnx2x_phy *phy,
3986 struct link_params *params)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003987{
3988 struct bnx2x *bp = params->bp;
3989 u16 val = 0;
3990
3991 /* configure the 48 bits for BAM AN */
3992
3993 /* set extended capabilities */
Yaniv Rosner7aa07112010-09-07 11:41:01 +00003994 if (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003995 val |= MDIO_OVER_1G_UP1_2_5G;
Yaniv Rosner7aa07112010-09-07 11:41:01 +00003996 if (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003997 val |= MDIO_OVER_1G_UP1_10G;
Yaniv Rosnercd2be892011-01-31 04:21:45 +00003998 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003999 MDIO_REG_BANK_OVER_1G,
4000 MDIO_OVER_1G_UP1, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004001
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004002 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004003 MDIO_REG_BANK_OVER_1G,
4004 MDIO_OVER_1G_UP3, 0x400);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004005}
4006
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00004007static void bnx2x_set_ieee_aneg_advertisement(struct bnx2x_phy *phy,
4008 struct link_params *params,
4009 u16 ieee_fc)
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07004010{
4011 struct bnx2x *bp = params->bp;
Yaniv Rosner7846e472009-11-05 19:18:07 +02004012 u16 val;
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07004013 /* for AN, we are always publishing full duplex */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004014
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004015 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004016 MDIO_REG_BANK_COMBO_IEEE0,
4017 MDIO_COMBO_IEEE0_AUTO_NEG_ADV, ieee_fc);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004018 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004019 MDIO_REG_BANK_CL73_IEEEB1,
4020 MDIO_CL73_IEEEB1_AN_ADV1, &val);
Yaniv Rosner7846e472009-11-05 19:18:07 +02004021 val &= ~MDIO_CL73_IEEEB1_AN_ADV1_PAUSE_BOTH;
4022 val |= ((ieee_fc<<3) & MDIO_CL73_IEEEB1_AN_ADV1_PAUSE_MASK);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004023 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004024 MDIO_REG_BANK_CL73_IEEEB1,
4025 MDIO_CL73_IEEEB1_AN_ADV1, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004026}
4027
Yaniv Rosnere10bc842010-09-07 11:40:50 +00004028static void bnx2x_restart_autoneg(struct bnx2x_phy *phy,
4029 struct link_params *params,
4030 u8 enable_cl73)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004031{
4032 struct bnx2x *bp = params->bp;
Eilon Greenstein3a36f2e2009-02-12 08:37:09 +00004033 u16 mii_control;
Eilon Greenstein239d6862009-08-12 08:23:04 +00004034
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004035 DP(NETIF_MSG_LINK, "bnx2x_restart_autoneg\n");
Eilon Greenstein3a36f2e2009-02-12 08:37:09 +00004036 /* Enable and restart BAM/CL37 aneg */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004037
Eilon Greenstein239d6862009-08-12 08:23:04 +00004038 if (enable_cl73) {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004039 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004040 MDIO_REG_BANK_CL73_IEEEB0,
4041 MDIO_CL73_IEEEB0_CL73_AN_CONTROL,
4042 &mii_control);
Eilon Greenstein239d6862009-08-12 08:23:04 +00004043
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004044 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004045 MDIO_REG_BANK_CL73_IEEEB0,
4046 MDIO_CL73_IEEEB0_CL73_AN_CONTROL,
4047 (mii_control |
4048 MDIO_CL73_IEEEB0_CL73_AN_CONTROL_AN_EN |
4049 MDIO_CL73_IEEEB0_CL73_AN_CONTROL_RESTART_AN));
Eilon Greenstein239d6862009-08-12 08:23:04 +00004050 } else {
4051
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004052 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004053 MDIO_REG_BANK_COMBO_IEEE0,
4054 MDIO_COMBO_IEEE0_MII_CONTROL,
4055 &mii_control);
Eilon Greenstein239d6862009-08-12 08:23:04 +00004056 DP(NETIF_MSG_LINK,
4057 "bnx2x_restart_autoneg mii_control before = 0x%x\n",
4058 mii_control);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004059 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004060 MDIO_REG_BANK_COMBO_IEEE0,
4061 MDIO_COMBO_IEEE0_MII_CONTROL,
4062 (mii_control |
4063 MDIO_COMBO_IEEO_MII_CONTROL_AN_EN |
4064 MDIO_COMBO_IEEO_MII_CONTROL_RESTART_AN));
Eilon Greenstein239d6862009-08-12 08:23:04 +00004065 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004066}
4067
Yaniv Rosnere10bc842010-09-07 11:40:50 +00004068static void bnx2x_initialize_sgmii_process(struct bnx2x_phy *phy,
4069 struct link_params *params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004070 struct link_vars *vars)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004071{
4072 struct bnx2x *bp = params->bp;
4073 u16 control1;
4074
4075 /* in SGMII mode, the unicore is always slave */
4076
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004077 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004078 MDIO_REG_BANK_SERDES_DIGITAL,
4079 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1,
4080 &control1);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004081 control1 |= MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_INVERT_SIGNAL_DETECT;
4082 /* set sgmii mode (and not fiber) */
4083 control1 &= ~(MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_FIBER_MODE |
4084 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_AUTODET |
4085 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_MSTR_MODE);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004086 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004087 MDIO_REG_BANK_SERDES_DIGITAL,
4088 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1,
4089 control1);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004090
4091 /* if forced speed */
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07004092 if (!(vars->line_speed == SPEED_AUTO_NEG)) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004093 /* set speed, disable autoneg */
4094 u16 mii_control;
4095
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004096 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004097 MDIO_REG_BANK_COMBO_IEEE0,
4098 MDIO_COMBO_IEEE0_MII_CONTROL,
4099 &mii_control);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004100 mii_control &= ~(MDIO_COMBO_IEEO_MII_CONTROL_AN_EN |
4101 MDIO_COMBO_IEEO_MII_CONTROL_MAN_SGMII_SP_MASK|
4102 MDIO_COMBO_IEEO_MII_CONTROL_FULL_DUPLEX);
4103
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07004104 switch (vars->line_speed) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004105 case SPEED_100:
4106 mii_control |=
4107 MDIO_COMBO_IEEO_MII_CONTROL_MAN_SGMII_SP_100;
4108 break;
4109 case SPEED_1000:
4110 mii_control |=
4111 MDIO_COMBO_IEEO_MII_CONTROL_MAN_SGMII_SP_1000;
4112 break;
4113 case SPEED_10:
4114 /* there is nothing to set for 10M */
4115 break;
4116 default:
4117 /* invalid speed for SGMII */
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07004118 DP(NETIF_MSG_LINK, "Invalid line_speed 0x%x\n",
4119 vars->line_speed);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004120 break;
4121 }
4122
4123 /* setting the full duplex */
Yaniv Rosner7aa07112010-09-07 11:41:01 +00004124 if (phy->req_duplex == DUPLEX_FULL)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004125 mii_control |=
4126 MDIO_COMBO_IEEO_MII_CONTROL_FULL_DUPLEX;
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004127 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004128 MDIO_REG_BANK_COMBO_IEEE0,
4129 MDIO_COMBO_IEEE0_MII_CONTROL,
4130 mii_control);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004131
4132 } else { /* AN mode */
4133 /* enable and restart AN */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00004134 bnx2x_restart_autoneg(phy, params, 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004135 }
4136}
4137
4138
4139/*
4140 * link management
4141 */
4142
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00004143static int bnx2x_direct_parallel_detect_used(struct bnx2x_phy *phy,
4144 struct link_params *params)
Yaniv Rosner15ddd2d2009-11-05 19:18:12 +02004145{
4146 struct bnx2x *bp = params->bp;
4147 u16 pd_10g, status2_1000x;
Yaniv Rosner7aa07112010-09-07 11:41:01 +00004148 if (phy->req_line_speed != SPEED_AUTO_NEG)
4149 return 0;
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004150 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004151 MDIO_REG_BANK_SERDES_DIGITAL,
4152 MDIO_SERDES_DIGITAL_A_1000X_STATUS2,
4153 &status2_1000x);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004154 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004155 MDIO_REG_BANK_SERDES_DIGITAL,
4156 MDIO_SERDES_DIGITAL_A_1000X_STATUS2,
4157 &status2_1000x);
Yaniv Rosner15ddd2d2009-11-05 19:18:12 +02004158 if (status2_1000x & MDIO_SERDES_DIGITAL_A_1000X_STATUS2_AN_DISABLED) {
4159 DP(NETIF_MSG_LINK, "1G parallel detect link on port %d\n",
4160 params->port);
4161 return 1;
4162 }
4163
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004164 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004165 MDIO_REG_BANK_10G_PARALLEL_DETECT,
4166 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_STATUS,
4167 &pd_10g);
Yaniv Rosner15ddd2d2009-11-05 19:18:12 +02004168
4169 if (pd_10g & MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_STATUS_PD_LINK) {
4170 DP(NETIF_MSG_LINK, "10G parallel detect link on port %d\n",
4171 params->port);
4172 return 1;
4173 }
4174 return 0;
4175}
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004176
Yaniv Rosnere10bc842010-09-07 11:40:50 +00004177static void bnx2x_flow_ctrl_resolve(struct bnx2x_phy *phy,
4178 struct link_params *params,
4179 struct link_vars *vars,
4180 u32 gp_status)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004181{
4182 struct bnx2x *bp = params->bp;
Eilon Greenstein3196a882008-08-13 15:58:49 -07004183 u16 ld_pause; /* local driver */
4184 u16 lp_pause; /* link partner */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004185 u16 pause_result;
4186
David S. Millerc0700f92008-12-16 23:53:20 -08004187 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004188
4189 /* resolve from gp_status in case of AN complete and not sgmii */
Yaniv Rosner7aa07112010-09-07 11:41:01 +00004190 if (phy->req_flow_ctrl != BNX2X_FLOW_CTRL_AUTO)
4191 vars->flow_ctrl = phy->req_flow_ctrl;
4192 else if (phy->req_line_speed != SPEED_AUTO_NEG)
4193 vars->flow_ctrl = params->req_fc_auto_adv;
4194 else if ((gp_status & MDIO_AN_CL73_OR_37_COMPLETE) &&
4195 (!(vars->phy_flags & PHY_SGMII_FLAG))) {
Yaniv Rosnere10bc842010-09-07 11:40:50 +00004196 if (bnx2x_direct_parallel_detect_used(phy, params)) {
Yaniv Rosner15ddd2d2009-11-05 19:18:12 +02004197 vars->flow_ctrl = params->req_fc_auto_adv;
4198 return;
4199 }
Yaniv Rosner7846e472009-11-05 19:18:07 +02004200 if ((gp_status &
4201 (MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_AUTONEG_COMPLETE |
4202 MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_MR_LP_NP_AN_ABLE)) ==
4203 (MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_AUTONEG_COMPLETE |
4204 MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_MR_LP_NP_AN_ABLE)) {
4205
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004206 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004207 MDIO_REG_BANK_CL73_IEEEB1,
4208 MDIO_CL73_IEEEB1_AN_ADV1,
4209 &ld_pause);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004210 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004211 MDIO_REG_BANK_CL73_IEEEB1,
4212 MDIO_CL73_IEEEB1_AN_LP_ADV1,
4213 &lp_pause);
Yaniv Rosner7846e472009-11-05 19:18:07 +02004214 pause_result = (ld_pause &
4215 MDIO_CL73_IEEEB1_AN_ADV1_PAUSE_MASK)
4216 >> 8;
4217 pause_result |= (lp_pause &
4218 MDIO_CL73_IEEEB1_AN_LP_ADV1_PAUSE_MASK)
4219 >> 10;
4220 DP(NETIF_MSG_LINK, "pause_result CL73 0x%x\n",
4221 pause_result);
4222 } else {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004223 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004224 MDIO_REG_BANK_COMBO_IEEE0,
4225 MDIO_COMBO_IEEE0_AUTO_NEG_ADV,
4226 &ld_pause);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004227 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004228 MDIO_REG_BANK_COMBO_IEEE0,
4229 MDIO_COMBO_IEEE0_AUTO_NEG_LINK_PARTNER_ABILITY1,
4230 &lp_pause);
Yaniv Rosner7846e472009-11-05 19:18:07 +02004231 pause_result = (ld_pause &
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004232 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK)>>5;
Yaniv Rosner7846e472009-11-05 19:18:07 +02004233 pause_result |= (lp_pause &
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004234 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK)>>7;
Yaniv Rosner7846e472009-11-05 19:18:07 +02004235 DP(NETIF_MSG_LINK, "pause_result CL37 0x%x\n",
4236 pause_result);
4237 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004238 bnx2x_pause_resolve(vars, pause_result);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004239 }
4240 DP(NETIF_MSG_LINK, "flow_ctrl 0x%x\n", vars->flow_ctrl);
4241}
4242
Yaniv Rosnere10bc842010-09-07 11:40:50 +00004243static void bnx2x_check_fallback_to_cl37(struct bnx2x_phy *phy,
4244 struct link_params *params)
Eilon Greenstein239d6862009-08-12 08:23:04 +00004245{
4246 struct bnx2x *bp = params->bp;
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00004247 u16 rx_status, ustat_val, cl37_fsm_received;
Eilon Greenstein239d6862009-08-12 08:23:04 +00004248 DP(NETIF_MSG_LINK, "bnx2x_check_fallback_to_cl37\n");
4249 /* Step 1: Make sure signal is detected */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004250 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004251 MDIO_REG_BANK_RX0,
4252 MDIO_RX0_RX_STATUS,
4253 &rx_status);
Eilon Greenstein239d6862009-08-12 08:23:04 +00004254 if ((rx_status & MDIO_RX0_RX_STATUS_SIGDET) !=
4255 (MDIO_RX0_RX_STATUS_SIGDET)) {
4256 DP(NETIF_MSG_LINK, "Signal is not detected. Restoring CL73."
4257 "rx_status(0x80b0) = 0x%x\n", rx_status);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004258 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004259 MDIO_REG_BANK_CL73_IEEEB0,
4260 MDIO_CL73_IEEEB0_CL73_AN_CONTROL,
4261 MDIO_CL73_IEEEB0_CL73_AN_CONTROL_AN_EN);
Eilon Greenstein239d6862009-08-12 08:23:04 +00004262 return;
4263 }
4264 /* Step 2: Check CL73 state machine */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004265 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004266 MDIO_REG_BANK_CL73_USERB0,
4267 MDIO_CL73_USERB0_CL73_USTAT1,
4268 &ustat_val);
Eilon Greenstein239d6862009-08-12 08:23:04 +00004269 if ((ustat_val &
4270 (MDIO_CL73_USERB0_CL73_USTAT1_LINK_STATUS_CHECK |
4271 MDIO_CL73_USERB0_CL73_USTAT1_AN_GOOD_CHECK_BAM37)) !=
4272 (MDIO_CL73_USERB0_CL73_USTAT1_LINK_STATUS_CHECK |
4273 MDIO_CL73_USERB0_CL73_USTAT1_AN_GOOD_CHECK_BAM37)) {
4274 DP(NETIF_MSG_LINK, "CL73 state-machine is not stable. "
4275 "ustat_val(0x8371) = 0x%x\n", ustat_val);
4276 return;
4277 }
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00004278 /*
4279 * Step 3: Check CL37 Message Pages received to indicate LP
4280 * supports only CL37
4281 */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004282 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004283 MDIO_REG_BANK_REMOTE_PHY,
4284 MDIO_REMOTE_PHY_MISC_RX_STATUS,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00004285 &cl37_fsm_received);
4286 if ((cl37_fsm_received &
Eilon Greenstein239d6862009-08-12 08:23:04 +00004287 (MDIO_REMOTE_PHY_MISC_RX_STATUS_CL37_FSM_RECEIVED_OVER1G_MSG |
4288 MDIO_REMOTE_PHY_MISC_RX_STATUS_CL37_FSM_RECEIVED_BRCM_OUI_MSG)) !=
4289 (MDIO_REMOTE_PHY_MISC_RX_STATUS_CL37_FSM_RECEIVED_OVER1G_MSG |
4290 MDIO_REMOTE_PHY_MISC_RX_STATUS_CL37_FSM_RECEIVED_BRCM_OUI_MSG)) {
4291 DP(NETIF_MSG_LINK, "No CL37 FSM were received. "
4292 "misc_rx_status(0x8330) = 0x%x\n",
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00004293 cl37_fsm_received);
Eilon Greenstein239d6862009-08-12 08:23:04 +00004294 return;
4295 }
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00004296 /*
4297 * The combined cl37/cl73 fsm state information indicating that
4298 * we are connected to a device which does not support cl73, but
4299 * does support cl37 BAM. In this case we disable cl73 and
4300 * restart cl37 auto-neg
4301 */
4302
Eilon Greenstein239d6862009-08-12 08:23:04 +00004303 /* Disable CL73 */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004304 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004305 MDIO_REG_BANK_CL73_IEEEB0,
4306 MDIO_CL73_IEEEB0_CL73_AN_CONTROL,
4307 0);
Eilon Greenstein239d6862009-08-12 08:23:04 +00004308 /* Restart CL37 autoneg */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00004309 bnx2x_restart_autoneg(phy, params, 0);
Eilon Greenstein239d6862009-08-12 08:23:04 +00004310 DP(NETIF_MSG_LINK, "Disabling CL73, and restarting CL37 autoneg\n");
4311}
Yaniv Rosner7aa07112010-09-07 11:41:01 +00004312
4313static void bnx2x_xgxs_an_resolve(struct bnx2x_phy *phy,
4314 struct link_params *params,
4315 struct link_vars *vars,
4316 u32 gp_status)
4317{
4318 if (gp_status & MDIO_AN_CL73_OR_37_COMPLETE)
4319 vars->link_status |=
4320 LINK_STATUS_AUTO_NEGOTIATE_COMPLETE;
4321
4322 if (bnx2x_direct_parallel_detect_used(phy, params))
4323 vars->link_status |=
4324 LINK_STATUS_PARALLEL_DETECTION_USED;
4325}
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004326static int bnx2x_get_link_speed_duplex(struct bnx2x_phy *phy,
4327 struct link_params *params,
4328 struct link_vars *vars,
4329 u16 is_link_up,
4330 u16 speed_mask,
4331 u16 is_duplex)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004332{
4333 struct bnx2x *bp = params->bp;
Yaniv Rosner7aa07112010-09-07 11:41:01 +00004334 if (phy->req_line_speed == SPEED_AUTO_NEG)
4335 vars->link_status |= LINK_STATUS_AUTO_NEGOTIATE_ENABLED;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004336 if (is_link_up) {
4337 DP(NETIF_MSG_LINK, "phy link up\n");
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004338
4339 vars->phy_link_up = 1;
4340 vars->link_status |= LINK_STATUS_LINK_UP;
4341
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004342 switch (speed_mask) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004343 case GP_STATUS_10M:
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004344 vars->line_speed = SPEED_10;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004345 if (vars->duplex == DUPLEX_FULL)
4346 vars->link_status |= LINK_10TFD;
4347 else
4348 vars->link_status |= LINK_10THD;
4349 break;
4350
4351 case GP_STATUS_100M:
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004352 vars->line_speed = SPEED_100;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004353 if (vars->duplex == DUPLEX_FULL)
4354 vars->link_status |= LINK_100TXFD;
4355 else
4356 vars->link_status |= LINK_100TXHD;
4357 break;
4358
4359 case GP_STATUS_1G:
4360 case GP_STATUS_1G_KX:
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004361 vars->line_speed = SPEED_1000;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004362 if (vars->duplex == DUPLEX_FULL)
4363 vars->link_status |= LINK_1000TFD;
4364 else
4365 vars->link_status |= LINK_1000THD;
4366 break;
4367
4368 case GP_STATUS_2_5G:
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004369 vars->line_speed = SPEED_2500;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004370 if (vars->duplex == DUPLEX_FULL)
4371 vars->link_status |= LINK_2500TFD;
4372 else
4373 vars->link_status |= LINK_2500THD;
4374 break;
4375
4376 case GP_STATUS_5G:
4377 case GP_STATUS_6G:
4378 DP(NETIF_MSG_LINK,
4379 "link speed unsupported gp_status 0x%x\n",
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004380 speed_mask);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004381 return -EINVAL;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00004382
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004383 case GP_STATUS_10G_KX4:
4384 case GP_STATUS_10G_HIG:
4385 case GP_STATUS_10G_CX4:
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004386 case GP_STATUS_10G_KR:
4387 case GP_STATUS_10G_SFI:
4388 case GP_STATUS_10G_XFI:
4389 vars->line_speed = SPEED_10000;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004390 vars->link_status |= LINK_10GTFD;
4391 break;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004392 case GP_STATUS_20G_DXGXS:
4393 vars->line_speed = SPEED_20000;
4394 vars->link_status |= LINK_20GTFD;
4395 break;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004396 default:
4397 DP(NETIF_MSG_LINK,
4398 "link speed unsupported gp_status 0x%x\n",
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004399 speed_mask);
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00004400 return -EINVAL;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004401 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004402 } else { /* link_down */
4403 DP(NETIF_MSG_LINK, "phy link down\n");
4404
4405 vars->phy_link_up = 0;
Yaniv Rosner57963ed2008-08-13 15:55:28 -07004406
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004407 vars->duplex = DUPLEX_FULL;
David S. Millerc0700f92008-12-16 23:53:20 -08004408 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004409 vars->mac_type = MAC_TYPE_NONE;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004410 }
4411 DP(NETIF_MSG_LINK, " phy_link_up %x line_speed %d\n",
4412 vars->phy_link_up, vars->line_speed);
4413 return 0;
4414}
Eilon Greenstein239d6862009-08-12 08:23:04 +00004415
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004416static int bnx2x_link_settings_status(struct bnx2x_phy *phy,
4417 struct link_params *params,
4418 struct link_vars *vars)
4419{
4420
4421 struct bnx2x *bp = params->bp;
4422
4423 u16 gp_status, duplex = DUPLEX_HALF, link_up = 0, speed_mask;
4424 int rc = 0;
4425
4426 /* Read gp_status */
4427 CL22_RD_OVER_CL45(bp, phy,
4428 MDIO_REG_BANK_GP_STATUS,
4429 MDIO_GP_STATUS_TOP_AN_STATUS1,
4430 &gp_status);
4431 if (gp_status & MDIO_GP_STATUS_TOP_AN_STATUS1_DUPLEX_STATUS)
4432 duplex = DUPLEX_FULL;
4433 if (gp_status & MDIO_GP_STATUS_TOP_AN_STATUS1_LINK_STATUS)
4434 link_up = 1;
4435 speed_mask = gp_status & GP_STATUS_SPEED_MASK;
4436 DP(NETIF_MSG_LINK, "gp_status 0x%x, is_link_up %d, speed_mask 0x%x\n",
4437 gp_status, link_up, speed_mask);
4438 rc = bnx2x_get_link_speed_duplex(phy, params, vars, link_up, speed_mask,
4439 duplex);
4440 if (rc == -EINVAL)
4441 return rc;
4442
4443 if (gp_status & MDIO_GP_STATUS_TOP_AN_STATUS1_LINK_STATUS) {
4444 if (SINGLE_MEDIA_DIRECT(params)) {
4445 bnx2x_flow_ctrl_resolve(phy, params, vars, gp_status);
4446 if (phy->req_line_speed == SPEED_AUTO_NEG)
4447 bnx2x_xgxs_an_resolve(phy, params, vars,
4448 gp_status);
4449 }
4450 } else { /* link_down */
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00004451 if ((phy->req_line_speed == SPEED_AUTO_NEG) &&
4452 SINGLE_MEDIA_DIRECT(params)) {
Eilon Greenstein239d6862009-08-12 08:23:04 +00004453 /* Check signal is detected */
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00004454 bnx2x_check_fallback_to_cl37(phy, params);
Eilon Greenstein239d6862009-08-12 08:23:04 +00004455 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004456 }
4457
Yaniv Rosnera22f0782010-09-07 11:41:20 +00004458 DP(NETIF_MSG_LINK, "duplex %x flow_ctrl 0x%x link_status 0x%x\n",
4459 vars->duplex, vars->flow_ctrl, vars->link_status);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004460 return rc;
4461}
4462
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004463static int bnx2x_warpcore_read_status(struct bnx2x_phy *phy,
4464 struct link_params *params,
4465 struct link_vars *vars)
4466{
4467
4468 struct bnx2x *bp = params->bp;
4469
4470 u8 lane;
4471 u16 gp_status1, gp_speed, link_up, duplex = DUPLEX_FULL;
4472 int rc = 0;
4473 lane = bnx2x_get_warpcore_lane(phy, params);
4474 /* Read gp_status */
4475 if (phy->req_line_speed > SPEED_10000) {
4476 u16 temp_link_up;
4477 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4478 1, &temp_link_up);
4479 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4480 1, &link_up);
4481 DP(NETIF_MSG_LINK, "PCS RX link status = 0x%x-->0x%x\n",
4482 temp_link_up, link_up);
4483 link_up &= (1<<2);
4484 if (link_up)
4485 bnx2x_ext_phy_resolve_fc(phy, params, vars);
4486 } else {
4487 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4488 MDIO_WC_REG_GP2_STATUS_GP_2_1, &gp_status1);
4489 DP(NETIF_MSG_LINK, "0x81d1 = 0x%x\n", gp_status1);
4490 /* Check for either KR or generic link up. */
4491 gp_status1 = ((gp_status1 >> 8) & 0xf) |
4492 ((gp_status1 >> 12) & 0xf);
4493 link_up = gp_status1 & (1 << lane);
4494 if (link_up && SINGLE_MEDIA_DIRECT(params)) {
4495 u16 pd, gp_status4;
4496 if (phy->req_line_speed == SPEED_AUTO_NEG) {
4497 /* Check Autoneg complete */
4498 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4499 MDIO_WC_REG_GP2_STATUS_GP_2_4,
4500 &gp_status4);
4501 if (gp_status4 & ((1<<12)<<lane))
4502 vars->link_status |=
4503 LINK_STATUS_AUTO_NEGOTIATE_COMPLETE;
4504
4505 /* Check parallel detect used */
4506 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4507 MDIO_WC_REG_PAR_DET_10G_STATUS,
4508 &pd);
4509 if (pd & (1<<15))
4510 vars->link_status |=
4511 LINK_STATUS_PARALLEL_DETECTION_USED;
4512 }
4513 bnx2x_ext_phy_resolve_fc(phy, params, vars);
4514 }
4515 }
4516
4517 if (lane < 2) {
4518 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4519 MDIO_WC_REG_GP2_STATUS_GP_2_2, &gp_speed);
4520 } else {
4521 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4522 MDIO_WC_REG_GP2_STATUS_GP_2_3, &gp_speed);
4523 }
4524 DP(NETIF_MSG_LINK, "lane %d gp_speed 0x%x\n", lane, gp_speed);
4525
4526 if ((lane & 1) == 0)
4527 gp_speed <<= 8;
4528 gp_speed &= 0x3f00;
4529
4530
4531 rc = bnx2x_get_link_speed_duplex(phy, params, vars, link_up, gp_speed,
4532 duplex);
4533
4534 DP(NETIF_MSG_LINK, "duplex %x flow_ctrl 0x%x link_status 0x%x\n",
4535 vars->duplex, vars->flow_ctrl, vars->link_status);
4536 return rc;
4537}
Eilon Greensteined8680a2009-02-12 08:37:12 +00004538static void bnx2x_set_gmii_tx_driver(struct link_params *params)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004539{
4540 struct bnx2x *bp = params->bp;
Yaniv Rosnere10bc842010-09-07 11:40:50 +00004541 struct bnx2x_phy *phy = &params->phy[INT_PHY];
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004542 u16 lp_up2;
4543 u16 tx_driver;
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00004544 u16 bank;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004545
4546 /* read precomp */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004547 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004548 MDIO_REG_BANK_OVER_1G,
4549 MDIO_OVER_1G_LP_UP2, &lp_up2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004550
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004551 /* bits [10:7] at lp_up2, positioned at [15:12] */
4552 lp_up2 = (((lp_up2 & MDIO_OVER_1G_LP_UP2_PREEMPHASIS_MASK) >>
4553 MDIO_OVER_1G_LP_UP2_PREEMPHASIS_SHIFT) <<
4554 MDIO_TX0_TX_DRIVER_PREEMPHASIS_SHIFT);
4555
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00004556 if (lp_up2 == 0)
4557 return;
4558
4559 for (bank = MDIO_REG_BANK_TX0; bank <= MDIO_REG_BANK_TX3;
4560 bank += (MDIO_REG_BANK_TX1 - MDIO_REG_BANK_TX0)) {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004561 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004562 bank,
4563 MDIO_TX0_TX_DRIVER, &tx_driver);
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00004564
4565 /* replace tx_driver bits [15:12] */
4566 if (lp_up2 !=
4567 (tx_driver & MDIO_TX0_TX_DRIVER_PREEMPHASIS_MASK)) {
4568 tx_driver &= ~MDIO_TX0_TX_DRIVER_PREEMPHASIS_MASK;
4569 tx_driver |= lp_up2;
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004570 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004571 bank,
4572 MDIO_TX0_TX_DRIVER, tx_driver);
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00004573 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004574 }
4575}
4576
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00004577static int bnx2x_emac_program(struct link_params *params,
4578 struct link_vars *vars)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004579{
4580 struct bnx2x *bp = params->bp;
4581 u8 port = params->port;
4582 u16 mode = 0;
4583
4584 DP(NETIF_MSG_LINK, "setting link speed & duplex\n");
4585 bnx2x_bits_dis(bp, GRCBASE_EMAC0 + port*0x400 +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004586 EMAC_REG_EMAC_MODE,
4587 (EMAC_MODE_25G_MODE |
4588 EMAC_MODE_PORT_MII_10M |
4589 EMAC_MODE_HALF_DUPLEX));
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00004590 switch (vars->line_speed) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004591 case SPEED_10:
4592 mode |= EMAC_MODE_PORT_MII_10M;
4593 break;
4594
4595 case SPEED_100:
4596 mode |= EMAC_MODE_PORT_MII;
4597 break;
4598
4599 case SPEED_1000:
4600 mode |= EMAC_MODE_PORT_GMII;
4601 break;
4602
4603 case SPEED_2500:
4604 mode |= (EMAC_MODE_25G_MODE | EMAC_MODE_PORT_GMII);
4605 break;
4606
4607 default:
4608 /* 10G not valid for EMAC */
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00004609 DP(NETIF_MSG_LINK, "Invalid line_speed 0x%x\n",
4610 vars->line_speed);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004611 return -EINVAL;
4612 }
4613
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00004614 if (vars->duplex == DUPLEX_HALF)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004615 mode |= EMAC_MODE_HALF_DUPLEX;
4616 bnx2x_bits_en(bp,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004617 GRCBASE_EMAC0 + port*0x400 + EMAC_REG_EMAC_MODE,
4618 mode);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004619
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00004620 bnx2x_set_led(params, vars, LED_MODE_OPER, vars->line_speed);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004621 return 0;
4622}
4623
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004624static void bnx2x_set_preemphasis(struct bnx2x_phy *phy,
4625 struct link_params *params)
4626{
4627
4628 u16 bank, i = 0;
4629 struct bnx2x *bp = params->bp;
4630
4631 for (bank = MDIO_REG_BANK_RX0, i = 0; bank <= MDIO_REG_BANK_RX3;
4632 bank += (MDIO_REG_BANK_RX1-MDIO_REG_BANK_RX0), i++) {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004633 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004634 bank,
4635 MDIO_RX0_RX_EQ_BOOST,
4636 phy->rx_preemphasis[i]);
4637 }
4638
4639 for (bank = MDIO_REG_BANK_TX0, i = 0; bank <= MDIO_REG_BANK_TX3;
4640 bank += (MDIO_REG_BANK_TX1 - MDIO_REG_BANK_TX0), i++) {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004641 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004642 bank,
4643 MDIO_TX0_TX_DRIVER,
4644 phy->tx_preemphasis[i]);
4645 }
4646}
4647
Yaniv Rosnerec146a62011-05-31 21:29:27 +00004648static void bnx2x_xgxs_config_init(struct bnx2x_phy *phy,
4649 struct link_params *params,
4650 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004651{
4652 struct bnx2x *bp = params->bp;
4653 u8 enable_cl73 = (SINGLE_MEDIA_DIRECT(params) ||
4654 (params->loopback_mode == LOOPBACK_XGXS));
4655 if (!(vars->phy_flags & PHY_SGMII_FLAG)) {
4656 if (SINGLE_MEDIA_DIRECT(params) &&
4657 (params->feature_config_flags &
4658 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED))
4659 bnx2x_set_preemphasis(phy, params);
4660
4661 /* forced speed requested? */
4662 if (vars->line_speed != SPEED_AUTO_NEG ||
4663 (SINGLE_MEDIA_DIRECT(params) &&
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004664 params->loopback_mode == LOOPBACK_EXT)) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004665 DP(NETIF_MSG_LINK, "not SGMII, no AN\n");
4666
4667 /* disable autoneg */
4668 bnx2x_set_autoneg(phy, params, vars, 0);
4669
4670 /* program speed and duplex */
4671 bnx2x_program_serdes(phy, params, vars);
4672
4673 } else { /* AN_mode */
4674 DP(NETIF_MSG_LINK, "not SGMII, AN\n");
4675
4676 /* AN enabled */
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00004677 bnx2x_set_brcm_cl37_advertisement(phy, params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004678
4679 /* program duplex & pause advertisement (for aneg) */
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00004680 bnx2x_set_ieee_aneg_advertisement(phy, params,
4681 vars->ieee_fc);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004682
4683 /* enable autoneg */
4684 bnx2x_set_autoneg(phy, params, vars, enable_cl73);
4685
4686 /* enable and restart AN */
4687 bnx2x_restart_autoneg(phy, params, enable_cl73);
4688 }
4689
4690 } else { /* SGMII mode */
4691 DP(NETIF_MSG_LINK, "SGMII\n");
4692
4693 bnx2x_initialize_sgmii_process(phy, params, vars);
4694 }
4695}
4696
Yaniv Rosnerec146a62011-05-31 21:29:27 +00004697static int bnx2x_prepare_xgxs(struct bnx2x_phy *phy,
4698 struct link_params *params,
4699 struct link_vars *vars)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00004700{
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00004701 int rc;
Yaniv Rosnerec146a62011-05-31 21:29:27 +00004702 vars->phy_flags |= PHY_XGXS_FLAG;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00004703 if ((phy->req_line_speed &&
4704 ((phy->req_line_speed == SPEED_100) ||
4705 (phy->req_line_speed == SPEED_10))) ||
4706 (!phy->req_line_speed &&
4707 (phy->speed_cap_mask >=
4708 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL) &&
4709 (phy->speed_cap_mask <
Yaniv Rosnerec146a62011-05-31 21:29:27 +00004710 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) ||
4711 (phy->type == PORT_HW_CFG_SERDES_EXT_PHY_TYPE_DIRECT_SD))
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00004712 vars->phy_flags |= PHY_SGMII_FLAG;
4713 else
4714 vars->phy_flags &= ~PHY_SGMII_FLAG;
4715
4716 bnx2x_calc_ieee_aneg_adv(phy, params, &vars->ieee_fc);
Yaniv Rosnerec146a62011-05-31 21:29:27 +00004717 bnx2x_set_aer_mmd(params, phy);
4718 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
4719 bnx2x_set_master_ln(params, phy);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00004720
4721 rc = bnx2x_reset_unicore(params, phy, 0);
4722 /* reset the SerDes and wait for reset bit return low */
4723 if (rc != 0)
4724 return rc;
4725
Yaniv Rosnerec146a62011-05-31 21:29:27 +00004726 bnx2x_set_aer_mmd(params, phy);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00004727 /* setting the masterLn_def again after the reset */
Yaniv Rosnerec146a62011-05-31 21:29:27 +00004728 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT) {
4729 bnx2x_set_master_ln(params, phy);
4730 bnx2x_set_swap_lanes(params, phy);
4731 }
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00004732
4733 return rc;
4734}
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00004735
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00004736static u16 bnx2x_wait_reset_complete(struct bnx2x *bp,
Yaniv Rosner6d870c32011-01-31 04:22:20 +00004737 struct bnx2x_phy *phy,
4738 struct link_params *params)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004739{
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00004740 u16 cnt, ctrl;
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004741 /* Wait for soft reset to get cleared up to 1 sec */
Yaniv Rosner62b29a52010-09-07 11:40:58 +00004742 for (cnt = 0; cnt < 1000; cnt++) {
Yaniv Rosner6583e332011-06-14 01:34:17 +00004743 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54616)
4744 bnx2x_cl22_read(bp, phy,
4745 MDIO_PMA_REG_CTRL, &ctrl);
4746 else
4747 bnx2x_cl45_read(bp, phy,
4748 MDIO_PMA_DEVAD,
4749 MDIO_PMA_REG_CTRL, &ctrl);
Yaniv Rosner62b29a52010-09-07 11:40:58 +00004750 if (!(ctrl & (1<<15)))
4751 break;
4752 msleep(1);
4753 }
Yaniv Rosner6d870c32011-01-31 04:22:20 +00004754
4755 if (cnt == 1000)
4756 netdev_err(bp->dev, "Warning: PHY was not initialized,"
4757 " Port %d\n",
4758 params->port);
Yaniv Rosner62b29a52010-09-07 11:40:58 +00004759 DP(NETIF_MSG_LINK, "control reg 0x%x (after %d ms)\n", ctrl, cnt);
4760 return cnt;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00004761}
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004762
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004763static void bnx2x_link_int_enable(struct link_params *params)
4764{
4765 u8 port = params->port;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004766 u32 mask;
4767 struct bnx2x *bp = params->bp;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00004768
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00004769 /* Setting the status to report on link up for either XGXS or SerDes */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004770 if (CHIP_IS_E3(bp)) {
4771 mask = NIG_MASK_XGXS0_LINK_STATUS;
4772 if (!(SINGLE_MEDIA_DIRECT(params)))
4773 mask |= NIG_MASK_MI_INT;
4774 } else if (params->switch_cfg == SWITCH_CFG_10G) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004775 mask = (NIG_MASK_XGXS0_LINK10G |
4776 NIG_MASK_XGXS0_LINK_STATUS);
4777 DP(NETIF_MSG_LINK, "enabled XGXS interrupt\n");
Yaniv Rosnere10bc842010-09-07 11:40:50 +00004778 if (!(SINGLE_MEDIA_DIRECT(params)) &&
4779 params->phy[INT_PHY].type !=
4780 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004781 mask |= NIG_MASK_MI_INT;
4782 DP(NETIF_MSG_LINK, "enabled external phy int\n");
4783 }
4784
4785 } else { /* SerDes */
4786 mask = NIG_MASK_SERDES0_LINK_STATUS;
4787 DP(NETIF_MSG_LINK, "enabled SerDes interrupt\n");
Yaniv Rosnere10bc842010-09-07 11:40:50 +00004788 if (!(SINGLE_MEDIA_DIRECT(params)) &&
4789 params->phy[INT_PHY].type !=
4790 PORT_HW_CFG_SERDES_EXT_PHY_TYPE_NOT_CONN) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004791 mask |= NIG_MASK_MI_INT;
4792 DP(NETIF_MSG_LINK, "enabled external phy int\n");
4793 }
4794 }
4795 bnx2x_bits_en(bp,
4796 NIG_REG_MASK_INTERRUPT_PORT0 + port*4,
4797 mask);
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00004798
4799 DP(NETIF_MSG_LINK, "port %x, is_xgxs %x, int_status 0x%x\n", port,
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004800 (params->switch_cfg == SWITCH_CFG_10G),
4801 REG_RD(bp, NIG_REG_STATUS_INTERRUPT_PORT0 + port*4));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004802 DP(NETIF_MSG_LINK, " int_mask 0x%x, MI_INT %x, SERDES_LINK %x\n",
4803 REG_RD(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4),
4804 REG_RD(bp, NIG_REG_EMAC0_STATUS_MISC_MI_INT + port*0x18),
4805 REG_RD(bp, NIG_REG_SERDES0_STATUS_LINK_STATUS+port*0x3c));
4806 DP(NETIF_MSG_LINK, " 10G %x, XGXS_LINK %x\n",
4807 REG_RD(bp, NIG_REG_XGXS0_STATUS_LINK10G + port*0x68),
4808 REG_RD(bp, NIG_REG_XGXS0_STATUS_LINK_STATUS + port*0x68));
4809}
4810
Yaniv Rosnera22f0782010-09-07 11:41:20 +00004811static void bnx2x_rearm_latch_signal(struct bnx2x *bp, u8 port,
4812 u8 exp_mi_int)
Eilon Greenstein2f904462009-08-12 08:22:16 +00004813{
Yaniv Rosnera22f0782010-09-07 11:41:20 +00004814 u32 latch_status = 0;
4815
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00004816 /*
Yaniv Rosnera22f0782010-09-07 11:41:20 +00004817 * Disable the MI INT ( external phy int ) by writing 1 to the
4818 * status register. Link down indication is high-active-signal,
4819 * so in this case we need to write the status to clear the XOR
Eilon Greenstein2f904462009-08-12 08:22:16 +00004820 */
4821 /* Read Latched signals */
4822 latch_status = REG_RD(bp,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00004823 NIG_REG_LATCH_STATUS_0 + port*8);
4824 DP(NETIF_MSG_LINK, "latch_status = 0x%x\n", latch_status);
Eilon Greenstein2f904462009-08-12 08:22:16 +00004825 /* Handle only those with latched-signal=up.*/
Yaniv Rosnera22f0782010-09-07 11:41:20 +00004826 if (exp_mi_int)
4827 bnx2x_bits_en(bp,
4828 NIG_REG_STATUS_INTERRUPT_PORT0
4829 + port*4,
4830 NIG_STATUS_EMAC0_MI_INT);
4831 else
4832 bnx2x_bits_dis(bp,
4833 NIG_REG_STATUS_INTERRUPT_PORT0
4834 + port*4,
4835 NIG_STATUS_EMAC0_MI_INT);
4836
Eilon Greenstein2f904462009-08-12 08:22:16 +00004837 if (latch_status & 1) {
Yaniv Rosnera22f0782010-09-07 11:41:20 +00004838
Eilon Greenstein2f904462009-08-12 08:22:16 +00004839 /* For all latched-signal=up : Re-Arm Latch signals */
4840 REG_WR(bp, NIG_REG_LATCH_STATUS_0 + port*8,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004841 (latch_status & 0xfffe) | (latch_status & 1));
Eilon Greenstein2f904462009-08-12 08:22:16 +00004842 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +00004843 /* For all latched-signal=up,Write original_signal to status */
Eilon Greenstein2f904462009-08-12 08:22:16 +00004844}
Yaniv Rosnere10bc842010-09-07 11:40:50 +00004845
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004846static void bnx2x_link_int_ack(struct link_params *params,
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004847 struct link_vars *vars, u8 is_10g_plus)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004848{
4849 struct bnx2x *bp = params->bp;
4850 u8 port = params->port;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004851 u32 mask;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00004852 /*
4853 * First reset all status we assume only one line will be
4854 * change at a time
4855 */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004856 bnx2x_bits_dis(bp, NIG_REG_STATUS_INTERRUPT_PORT0 + port*4,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004857 (NIG_STATUS_XGXS0_LINK10G |
4858 NIG_STATUS_XGXS0_LINK_STATUS |
4859 NIG_STATUS_SERDES0_LINK_STATUS));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004860 if (vars->phy_link_up) {
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004861 if (USES_WARPCORE(bp))
4862 mask = NIG_STATUS_XGXS0_LINK_STATUS;
4863 else {
4864 if (is_10g_plus)
4865 mask = NIG_STATUS_XGXS0_LINK10G;
4866 else if (params->switch_cfg == SWITCH_CFG_10G) {
4867 /*
4868 * Disable the link interrupt by writing 1 to
4869 * the relevant lane in the status register
4870 */
4871 u32 ser_lane =
4872 ((params->lane_config &
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004873 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_MASK) >>
4874 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_SHIFT);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004875 mask = ((1 << ser_lane) <<
4876 NIG_STATUS_XGXS0_LINK_STATUS_SIZE);
4877 } else
4878 mask = NIG_STATUS_SERDES0_LINK_STATUS;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004879 }
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004880 DP(NETIF_MSG_LINK, "Ack link up interrupt with mask 0x%x\n",
4881 mask);
4882 bnx2x_bits_en(bp,
4883 NIG_REG_STATUS_INTERRUPT_PORT0 + port*4,
4884 mask);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004885 }
4886}
4887
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00004888static int bnx2x_format_ver(u32 num, u8 *str, u16 *len)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004889{
4890 u8 *str_ptr = str;
4891 u32 mask = 0xf0000000;
4892 u8 shift = 8*4;
4893 u8 digit;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00004894 u8 remove_leading_zeros = 1;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00004895 if (*len < 10) {
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02004896 /* Need more than 10chars for this format */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004897 *str_ptr = '\0';
Yaniv Rosnera22f0782010-09-07 11:41:20 +00004898 (*len)--;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004899 return -EINVAL;
4900 }
4901 while (shift > 0) {
4902
4903 shift -= 4;
4904 digit = ((num & mask) >> shift);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00004905 if (digit == 0 && remove_leading_zeros) {
4906 mask = mask >> 4;
4907 continue;
4908 } else if (digit < 0xa)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004909 *str_ptr = digit + '0';
4910 else
4911 *str_ptr = digit - 0xa + 'a';
Yaniv Rosnera22f0782010-09-07 11:41:20 +00004912 remove_leading_zeros = 0;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004913 str_ptr++;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00004914 (*len)--;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004915 mask = mask >> 4;
4916 if (shift == 4*4) {
Yaniv Rosnera22f0782010-09-07 11:41:20 +00004917 *str_ptr = '.';
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004918 str_ptr++;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00004919 (*len)--;
4920 remove_leading_zeros = 1;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004921 }
4922 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004923 return 0;
4924}
4925
Yaniv Rosnera22f0782010-09-07 11:41:20 +00004926
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00004927static int bnx2x_null_format_ver(u32 spirom_ver, u8 *str, u16 *len)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00004928{
4929 str[0] = '\0';
4930 (*len)--;
4931 return 0;
4932}
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004933
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00004934int bnx2x_get_ext_phy_fw_version(struct link_params *params, u8 driver_loaded,
4935 u8 *version, u16 len)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004936{
Julia Lawall0376d5b2009-07-19 05:26:35 +00004937 struct bnx2x *bp;
Eilon Greensteina35da8d2009-02-12 08:37:02 +00004938 u32 spirom_ver = 0;
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00004939 int status = 0;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00004940 u8 *ver_p = version;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00004941 u16 remain_len = len;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004942 if (version == NULL || params == NULL)
4943 return -EINVAL;
Julia Lawall0376d5b2009-07-19 05:26:35 +00004944 bp = params->bp;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004945
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00004946 /* Extract first external phy*/
4947 version[0] = '\0';
4948 spirom_ver = REG_RD(bp, params->phy[EXT_PHY1].ver_addr);
Eilon Greensteina35da8d2009-02-12 08:37:02 +00004949
Yaniv Rosnera22f0782010-09-07 11:41:20 +00004950 if (params->phy[EXT_PHY1].format_fw_ver) {
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00004951 status |= params->phy[EXT_PHY1].format_fw_ver(spirom_ver,
4952 ver_p,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00004953 &remain_len);
4954 ver_p += (len - remain_len);
4955 }
4956 if ((params->num_phys == MAX_PHYS) &&
4957 (params->phy[EXT_PHY2].ver_addr != 0)) {
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004958 spirom_ver = REG_RD(bp, params->phy[EXT_PHY2].ver_addr);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00004959 if (params->phy[EXT_PHY2].format_fw_ver) {
4960 *ver_p = '/';
4961 ver_p++;
4962 remain_len--;
4963 status |= params->phy[EXT_PHY2].format_fw_ver(
4964 spirom_ver,
4965 ver_p,
4966 &remain_len);
4967 ver_p = version + (len - remain_len);
4968 }
4969 }
4970 *ver_p = '\0';
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004971 return status;
4972}
4973
Yaniv Rosnere10bc842010-09-07 11:40:50 +00004974static void bnx2x_set_xgxs_loopback(struct bnx2x_phy *phy,
Yaniv Rosner62b29a52010-09-07 11:40:58 +00004975 struct link_params *params)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004976{
4977 u8 port = params->port;
4978 struct bnx2x *bp = params->bp;
4979
Yaniv Rosner62b29a52010-09-07 11:40:58 +00004980 if (phy->req_line_speed != SPEED_1000) {
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004981 u32 md_devad = 0;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004982
4983 DP(NETIF_MSG_LINK, "XGXS 10G loopback enable\n");
4984
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004985 if (!CHIP_IS_E3(bp)) {
4986 /* change the uni_phy_addr in the nig */
4987 md_devad = REG_RD(bp, (NIG_REG_XGXS0_CTRL_MD_DEVAD +
4988 port*0x18));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004989
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004990 REG_WR(bp, NIG_REG_XGXS0_CTRL_MD_DEVAD + port*0x18,
4991 0x5);
4992 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004993
Yaniv Rosnere10bc842010-09-07 11:40:50 +00004994 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004995 5,
4996 (MDIO_REG_BANK_AER_BLOCK +
4997 (MDIO_AER_BLOCK_AER_REG & 0xf)),
4998 0x2800);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004999
Yaniv Rosnere10bc842010-09-07 11:40:50 +00005000 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005001 5,
5002 (MDIO_REG_BANK_CL73_IEEEB0 +
5003 (MDIO_CL73_IEEEB0_CL73_AN_CONTROL & 0xf)),
5004 0x6041);
Eilon Greenstein38582762009-01-14 06:44:16 +00005005 msleep(200);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005006 /* set aer mmd back */
Yaniv Rosnerec146a62011-05-31 21:29:27 +00005007 bnx2x_set_aer_mmd(params, phy);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005008
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005009 if (!CHIP_IS_E3(bp)) {
5010 /* and md_devad */
5011 REG_WR(bp, NIG_REG_XGXS0_CTRL_MD_DEVAD + port*0x18,
5012 md_devad);
5013 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005014 } else {
Yaniv Rosnere10bc842010-09-07 11:40:50 +00005015 u16 mii_ctrl;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005016 DP(NETIF_MSG_LINK, "XGXS 1G loopback enable\n");
Yaniv Rosnere10bc842010-09-07 11:40:50 +00005017 bnx2x_cl45_read(bp, phy, 5,
5018 (MDIO_REG_BANK_COMBO_IEEE0 +
5019 (MDIO_COMBO_IEEE0_MII_CONTROL & 0xf)),
5020 &mii_ctrl);
5021 bnx2x_cl45_write(bp, phy, 5,
5022 (MDIO_REG_BANK_COMBO_IEEE0 +
5023 (MDIO_COMBO_IEEE0_MII_CONTROL & 0xf)),
5024 mii_ctrl |
5025 MDIO_COMBO_IEEO_MII_CONTROL_LOOPBACK);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005026 }
5027}
5028
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00005029int bnx2x_set_led(struct link_params *params,
5030 struct link_vars *vars, u8 mode, u32 speed)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005031{
Yaniv Rosner7846e472009-11-05 19:18:07 +02005032 u8 port = params->port;
5033 u16 hw_led_mode = params->hw_led_mode;
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00005034 int rc = 0;
5035 u8 phy_idx;
Eilon Greenstein345b5d52008-08-13 15:58:12 -07005036 u32 tmp;
5037 u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
Yaniv Rosner7846e472009-11-05 19:18:07 +02005038 struct bnx2x *bp = params->bp;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005039 DP(NETIF_MSG_LINK, "bnx2x_set_led: port %x, mode %d\n", port, mode);
5040 DP(NETIF_MSG_LINK, "speed 0x%x, hw_led_mode 0x%x\n",
5041 speed, hw_led_mode);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00005042 /* In case */
5043 for (phy_idx = EXT_PHY1; phy_idx < MAX_PHYS; phy_idx++) {
5044 if (params->phy[phy_idx].set_link_led) {
5045 params->phy[phy_idx].set_link_led(
5046 &params->phy[phy_idx], params, mode);
5047 }
5048 }
5049
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005050 switch (mode) {
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00005051 case LED_MODE_FRONT_PANEL_OFF:
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005052 case LED_MODE_OFF:
5053 REG_WR(bp, NIG_REG_LED_10G_P0 + port*4, 0);
5054 REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005055 SHARED_HW_CFG_LED_MAC1);
Eilon Greenstein345b5d52008-08-13 15:58:12 -07005056
5057 tmp = EMAC_RD(bp, EMAC_REG_EMAC_LED);
Eilon Greenstein3196a882008-08-13 15:58:49 -07005058 EMAC_WR(bp, EMAC_REG_EMAC_LED, (tmp | EMAC_LED_OVERRIDE));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005059 break;
5060
5061 case LED_MODE_OPER:
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005062 /*
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00005063 * For all other phys, OPER mode is same as ON, so in case
5064 * link is down, do nothing
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005065 */
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00005066 if (!vars->link_up)
5067 break;
5068 case LED_MODE_ON:
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00005069 if (((params->phy[EXT_PHY1].type ==
5070 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727) ||
5071 (params->phy[EXT_PHY1].type ==
5072 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8722)) &&
Yaniv Rosner1f483532011-01-18 04:33:31 +00005073 CHIP_IS_E2(bp) && params->num_phys == 2) {
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005074 /*
5075 * This is a work-around for E2+8727 Configurations
5076 */
Yaniv Rosner1f483532011-01-18 04:33:31 +00005077 if (mode == LED_MODE_ON ||
5078 speed == SPEED_10000){
5079 REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4, 0);
5080 REG_WR(bp, NIG_REG_LED_10G_P0 + port*4, 1);
5081
5082 tmp = EMAC_RD(bp, EMAC_REG_EMAC_LED);
5083 EMAC_WR(bp, EMAC_REG_EMAC_LED,
5084 (tmp | EMAC_LED_OVERRIDE));
5085 return rc;
5086 }
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005087 } else if (SINGLE_MEDIA_DIRECT(params) &&
5088 (CHIP_IS_E1x(bp) ||
5089 CHIP_IS_E2(bp))) {
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005090 /*
5091 * This is a work-around for HW issue found when link
5092 * is up in CL73
5093 */
Yaniv Rosner7846e472009-11-05 19:18:07 +02005094 REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4, 0);
5095 REG_WR(bp, NIG_REG_LED_10G_P0 + port*4, 1);
5096 } else {
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005097 REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4, hw_led_mode);
Yaniv Rosner7846e472009-11-05 19:18:07 +02005098 }
5099
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005100 REG_WR(bp, NIG_REG_LED_CONTROL_OVERRIDE_TRAFFIC_P0 + port*4, 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005101 /* Set blinking rate to ~15.9Hz */
5102 REG_WR(bp, NIG_REG_LED_CONTROL_BLINK_RATE_P0 + port*4,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005103 LED_BLINK_RATE_VAL);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005104 REG_WR(bp, NIG_REG_LED_CONTROL_BLINK_RATE_ENA_P0 +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005105 port*4, 1);
Eilon Greenstein345b5d52008-08-13 15:58:12 -07005106 tmp = EMAC_RD(bp, EMAC_REG_EMAC_LED);
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005107 EMAC_WR(bp, EMAC_REG_EMAC_LED, (tmp & (~EMAC_LED_OVERRIDE)));
Eilon Greenstein345b5d52008-08-13 15:58:12 -07005108
Yaniv Rosner7846e472009-11-05 19:18:07 +02005109 if (CHIP_IS_E1(bp) &&
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005110 ((speed == SPEED_2500) ||
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005111 (speed == SPEED_1000) ||
5112 (speed == SPEED_100) ||
5113 (speed == SPEED_10))) {
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005114 /*
5115 * On Everest 1 Ax chip versions for speeds less than
5116 * 10G LED scheme is different
5117 */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005118 REG_WR(bp, NIG_REG_LED_CONTROL_OVERRIDE_TRAFFIC_P0
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005119 + port*4, 1);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005120 REG_WR(bp, NIG_REG_LED_CONTROL_TRAFFIC_P0 +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005121 port*4, 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005122 REG_WR(bp, NIG_REG_LED_CONTROL_BLINK_TRAFFIC_P0 +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005123 port*4, 1);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005124 }
5125 break;
5126
5127 default:
5128 rc = -EINVAL;
5129 DP(NETIF_MSG_LINK, "bnx2x_set_led: Invalid led mode %d\n",
5130 mode);
5131 break;
5132 }
5133 return rc;
5134
5135}
5136
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005137/*
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005138 * This function comes to reflect the actual link state read DIRECTLY from the
5139 * HW
5140 */
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00005141int bnx2x_test_link(struct link_params *params, struct link_vars *vars,
5142 u8 is_serdes)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005143{
5144 struct bnx2x *bp = params->bp;
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00005145 u16 gp_status = 0, phy_index = 0;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005146 u8 ext_phy_link_up = 0, serdes_phy_type;
5147 struct link_vars temp_vars;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005148 struct bnx2x_phy *int_phy = &params->phy[INT_PHY];
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005149
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005150 if (CHIP_IS_E3(bp)) {
5151 u16 link_up;
5152 if (params->req_line_speed[LINK_CONFIG_IDX(INT_PHY)]
5153 > SPEED_10000) {
5154 /* Check 20G link */
5155 bnx2x_cl45_read(bp, int_phy, MDIO_WC_DEVAD,
5156 1, &link_up);
5157 bnx2x_cl45_read(bp, int_phy, MDIO_WC_DEVAD,
5158 1, &link_up);
5159 link_up &= (1<<2);
5160 } else {
5161 /* Check 10G link and below*/
5162 u8 lane = bnx2x_get_warpcore_lane(int_phy, params);
5163 bnx2x_cl45_read(bp, int_phy, MDIO_WC_DEVAD,
5164 MDIO_WC_REG_GP2_STATUS_GP_2_1,
5165 &gp_status);
5166 gp_status = ((gp_status >> 8) & 0xf) |
5167 ((gp_status >> 12) & 0xf);
5168 link_up = gp_status & (1 << lane);
5169 }
5170 if (!link_up)
5171 return -ESRCH;
5172 } else {
5173 CL22_RD_OVER_CL45(bp, int_phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005174 MDIO_REG_BANK_GP_STATUS,
5175 MDIO_GP_STATUS_TOP_AN_STATUS1,
5176 &gp_status);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005177 /* link is up only if both local phy and external phy are up */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005178 if (!(gp_status & MDIO_GP_STATUS_TOP_AN_STATUS1_LINK_STATUS))
5179 return -ESRCH;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005180 }
5181 /* In XGXS loopback mode, do not check external PHY */
5182 if (params->loopback_mode == LOOPBACK_XGXS)
5183 return 0;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005184
5185 switch (params->num_phys) {
5186 case 1:
5187 /* No external PHY */
5188 return 0;
5189 case 2:
5190 ext_phy_link_up = params->phy[EXT_PHY1].read_status(
5191 &params->phy[EXT_PHY1],
5192 params, &temp_vars);
5193 break;
5194 case 3: /* Dual Media */
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00005195 for (phy_index = EXT_PHY1; phy_index < params->num_phys;
5196 phy_index++) {
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005197 serdes_phy_type = ((params->phy[phy_index].media_type ==
5198 ETH_PHY_SFP_FIBER) ||
5199 (params->phy[phy_index].media_type ==
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00005200 ETH_PHY_XFP_FIBER) ||
5201 (params->phy[phy_index].media_type ==
5202 ETH_PHY_DA_TWINAX));
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005203
5204 if (is_serdes != serdes_phy_type)
5205 continue;
5206 if (params->phy[phy_index].read_status) {
5207 ext_phy_link_up |=
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00005208 params->phy[phy_index].read_status(
5209 &params->phy[phy_index],
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005210 params, &temp_vars);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005211 }
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00005212 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005213 break;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005214 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005215 if (ext_phy_link_up)
5216 return 0;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005217 return -ESRCH;
5218}
5219
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00005220static int bnx2x_link_initialize(struct link_params *params,
5221 struct link_vars *vars)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005222{
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00005223 int rc = 0;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005224 u8 phy_index, non_ext_phy;
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00005225 struct bnx2x *bp = params->bp;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005226 /*
5227 * In case of external phy existence, the line speed would be the
5228 * line speed linked up by the external phy. In case it is direct
5229 * only, then the line_speed during initialization will be
5230 * equal to the req_line_speed
5231 */
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00005232 vars->line_speed = params->phy[INT_PHY].req_line_speed;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005233
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005234 /*
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00005235 * Initialize the internal phy in case this is a direct board
5236 * (no external phys), or this board has external phy which requires
5237 * to first.
5238 */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005239 if (!USES_WARPCORE(bp))
5240 bnx2x_prepare_xgxs(&params->phy[INT_PHY], params, vars);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005241 /* init ext phy and enable link state int */
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00005242 non_ext_phy = (SINGLE_MEDIA_DIRECT(params) ||
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005243 (params->loopback_mode == LOOPBACK_XGXS));
Yaniv Rosner57963ed2008-08-13 15:55:28 -07005244
5245 if (non_ext_phy ||
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00005246 (params->phy[EXT_PHY1].flags & FLAGS_INIT_XGXS_FIRST) ||
Eilon Greenstein8660d8c2009-03-02 08:01:02 +00005247 (params->loopback_mode == LOOPBACK_EXT_PHY)) {
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00005248 struct bnx2x_phy *phy = &params->phy[INT_PHY];
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005249 if (vars->line_speed == SPEED_AUTO_NEG &&
5250 (CHIP_IS_E1x(bp) ||
5251 CHIP_IS_E2(bp)))
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00005252 bnx2x_set_parallel_detection(phy, params);
Yaniv Rosnerec146a62011-05-31 21:29:27 +00005253 if (params->phy[INT_PHY].config_init)
5254 params->phy[INT_PHY].config_init(phy,
5255 params,
5256 vars);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07005257 }
5258
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00005259 /* Init external phy*/
Yaniv Rosnerfd36a2e2011-05-31 21:29:05 +00005260 if (non_ext_phy) {
5261 if (params->phy[INT_PHY].supported &
5262 SUPPORTED_FIBRE)
5263 vars->link_status |= LINK_STATUS_SERDES_LINK;
5264 } else {
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005265 for (phy_index = EXT_PHY1; phy_index < params->num_phys;
5266 phy_index++) {
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005267 /*
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005268 * No need to initialize second phy in case of first
5269 * phy only selection. In case of second phy, we do
5270 * need to initialize the first phy, since they are
5271 * connected.
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005272 */
Yaniv Rosnerfd36a2e2011-05-31 21:29:05 +00005273 if (params->phy[phy_index].supported &
5274 SUPPORTED_FIBRE)
5275 vars->link_status |= LINK_STATUS_SERDES_LINK;
5276
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005277 if (phy_index == EXT_PHY2 &&
5278 (bnx2x_phy_selection(params) ==
5279 PORT_HW_CFG_PHY_SELECTION_FIRST_PHY)) {
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00005280 DP(NETIF_MSG_LINK, "Not initializing"
5281 " second phy\n");
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005282 continue;
5283 }
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005284 params->phy[phy_index].config_init(
5285 &params->phy[phy_index],
5286 params, vars);
5287 }
Yaniv Rosnerfd36a2e2011-05-31 21:29:05 +00005288 }
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +00005289 /* Reset the interrupt indication after phy was initialized */
5290 bnx2x_bits_dis(bp, NIG_REG_STATUS_INTERRUPT_PORT0 +
5291 params->port*4,
5292 (NIG_STATUS_XGXS0_LINK10G |
5293 NIG_STATUS_XGXS0_LINK_STATUS |
5294 NIG_STATUS_SERDES0_LINK_STATUS |
5295 NIG_MASK_MI_INT));
Yaniv Rosnerfd36a2e2011-05-31 21:29:05 +00005296 bnx2x_update_mng(params, vars->link_status);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005297 return rc;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005298}
5299
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005300static void bnx2x_int_link_reset(struct bnx2x_phy *phy,
5301 struct link_params *params)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005302{
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005303 /* reset the SerDes/XGXS */
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005304 REG_WR(params->bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_CLEAR,
5305 (0x1ff << (params->port*16)));
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005306}
5307
5308static void bnx2x_common_ext_link_reset(struct bnx2x_phy *phy,
5309 struct link_params *params)
5310{
5311 struct bnx2x *bp = params->bp;
5312 u8 gpio_port;
5313 /* HW reset */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005314 if (CHIP_IS_E2(bp))
5315 gpio_port = BP_PATH(bp);
5316 else
5317 gpio_port = params->port;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005318 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005319 MISC_REGISTERS_GPIO_OUTPUT_LOW,
5320 gpio_port);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005321 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005322 MISC_REGISTERS_GPIO_OUTPUT_LOW,
5323 gpio_port);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005324 DP(NETIF_MSG_LINK, "reset external PHY\n");
5325}
5326
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00005327static int bnx2x_update_link_down(struct link_params *params,
5328 struct link_vars *vars)
Yaniv Rosner57963ed2008-08-13 15:55:28 -07005329{
5330 struct bnx2x *bp = params->bp;
5331 u8 port = params->port;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00005332
Yaniv Rosner57963ed2008-08-13 15:55:28 -07005333 DP(NETIF_MSG_LINK, "Port %x: Link is down\n", port);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00005334 bnx2x_set_led(params, vars, LED_MODE_OFF, 0);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07005335
5336 /* indicate no mac active */
5337 vars->mac_type = MAC_TYPE_NONE;
5338
5339 /* update shared memory */
Yaniv Rosnerfd36a2e2011-05-31 21:29:05 +00005340 vars->link_status &= ~(LINK_STATUS_SPEED_AND_DUPLEX_MASK |
5341 LINK_STATUS_LINK_UP |
5342 LINK_STATUS_AUTO_NEGOTIATE_COMPLETE |
5343 LINK_STATUS_RX_FLOW_CONTROL_FLAG_MASK |
5344 LINK_STATUS_TX_FLOW_CONTROL_FLAG_MASK |
5345 LINK_STATUS_PARALLEL_DETECTION_FLAG_MASK);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07005346 vars->line_speed = 0;
5347 bnx2x_update_mng(params, vars->link_status);
5348
5349 /* activate nig drain */
5350 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + port*4, 1);
5351
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00005352 /* disable emac */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00005353 if (!CHIP_IS_E3(bp))
5354 REG_WR(bp, NIG_REG_NIG_EMAC0_EN + port*4, 0);
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00005355
5356 msleep(10);
Yaniv Rosner9380bb92011-06-14 01:34:07 +00005357 /* reset BigMac/Xmac */
5358 if (CHIP_IS_E1x(bp) ||
5359 CHIP_IS_E2(bp)) {
5360 bnx2x_bmac_rx_disable(bp, params->port);
5361 REG_WR(bp, GRCBASE_MISC +
5362 MISC_REGISTERS_RESET_REG_2_CLEAR,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005363 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port));
Yaniv Rosner9380bb92011-06-14 01:34:07 +00005364 }
5365 if (CHIP_IS_E3(bp))
5366 bnx2x_xmac_disable(params);
5367
Yaniv Rosner57963ed2008-08-13 15:55:28 -07005368 return 0;
5369}
5370
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00005371static int bnx2x_update_link_up(struct link_params *params,
5372 struct link_vars *vars,
5373 u8 link_10g)
Yaniv Rosner57963ed2008-08-13 15:55:28 -07005374{
5375 struct bnx2x *bp = params->bp;
5376 u8 port = params->port;
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00005377 int rc = 0;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00005378
Yaniv Rosner57963ed2008-08-13 15:55:28 -07005379 vars->link_status |= LINK_STATUS_LINK_UP;
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00005380
Yaniv Rosner7aa07112010-09-07 11:41:01 +00005381 if (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX)
5382 vars->link_status |=
5383 LINK_STATUS_TX_FLOW_CONTROL_ENABLED;
5384
5385 if (vars->flow_ctrl & BNX2X_FLOW_CTRL_RX)
5386 vars->link_status |=
5387 LINK_STATUS_RX_FLOW_CONTROL_ENABLED;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00005388 if (USES_WARPCORE(bp)) {
5389 if (link_10g)
5390 bnx2x_xmac_enable(params, vars, 0);
5391 else
5392 bnx2x_umac_enable(params, vars, 0);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00005393 bnx2x_set_led(params, vars,
Yaniv Rosner9380bb92011-06-14 01:34:07 +00005394 LED_MODE_OPER, vars->line_speed);
5395 }
5396 if ((CHIP_IS_E1x(bp) ||
5397 CHIP_IS_E2(bp))) {
5398 if (link_10g) {
5399 bnx2x_bmac_enable(params, vars, 0);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07005400
Yaniv Rosner9380bb92011-06-14 01:34:07 +00005401 bnx2x_set_led(params, vars,
5402 LED_MODE_OPER, SPEED_10000);
5403 } else {
5404 rc = bnx2x_emac_program(params, vars);
5405 bnx2x_emac_enable(params, vars, 0);
Yaniv Rosner0c786f02009-11-05 19:18:32 +02005406
Yaniv Rosner9380bb92011-06-14 01:34:07 +00005407 /* AN complete? */
5408 if ((vars->link_status &
5409 LINK_STATUS_AUTO_NEGOTIATE_COMPLETE)
5410 && (!(vars->phy_flags & PHY_SGMII_FLAG)) &&
5411 SINGLE_MEDIA_DIRECT(params))
5412 bnx2x_set_gmii_tx_driver(params);
5413 }
Yaniv Rosner57963ed2008-08-13 15:55:28 -07005414 }
5415
5416 /* PBF - link up */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00005417 if (CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00005418 rc |= bnx2x_pbf_update(params, vars->flow_ctrl,
5419 vars->line_speed);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07005420
5421 /* disable drain */
5422 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + port*4, 0);
5423
5424 /* update shared memory */
5425 bnx2x_update_mng(params, vars->link_status);
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00005426 msleep(20);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07005427 return rc;
5428}
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005429/*
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005430 * The bnx2x_link_update function should be called upon link
5431 * interrupt.
5432 * Link is considered up as follows:
5433 * - DIRECT_SINGLE_MEDIA - Only XGXS link (internal link) needs
5434 * to be up
5435 * - SINGLE_MEDIA - The link between the 577xx and the external
5436 * phy (XGXS) need to up as well as the external link of the
5437 * phy (PHY_EXT1)
5438 * - DUAL_MEDIA - The link between the 577xx and the first
5439 * external phy needs to be up, and at least one of the 2
5440 * external phy link must be up.
Yaniv Rosner62b29a52010-09-07 11:40:58 +00005441 */
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00005442int bnx2x_link_update(struct link_params *params, struct link_vars *vars)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005443{
5444 struct bnx2x *bp = params->bp;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005445 struct link_vars phy_vars[MAX_PHYS];
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005446 u8 port = params->port;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005447 u8 link_10g_plus, phy_index;
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00005448 u8 ext_phy_link_up = 0, cur_link_up;
5449 int rc = 0;
Eilon Greenstein2f904462009-08-12 08:22:16 +00005450 u8 is_mi_int = 0;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005451 u16 ext_phy_line_speed = 0, prev_line_speed = vars->line_speed;
5452 u8 active_external_phy = INT_PHY;
Yaniv Rosnerfd36a2e2011-05-31 21:29:05 +00005453
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005454 for (phy_index = INT_PHY; phy_index < params->num_phys;
5455 phy_index++) {
5456 phy_vars[phy_index].flow_ctrl = 0;
5457 phy_vars[phy_index].link_status = 0;
5458 phy_vars[phy_index].line_speed = 0;
5459 phy_vars[phy_index].duplex = DUPLEX_FULL;
5460 phy_vars[phy_index].phy_link_up = 0;
5461 phy_vars[phy_index].link_up = 0;
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00005462 phy_vars[phy_index].fault_detected = 0;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005463 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005464
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005465 if (USES_WARPCORE(bp))
5466 bnx2x_set_aer_mmd(params, &params->phy[INT_PHY]);
5467
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005468 DP(NETIF_MSG_LINK, "port %x, XGXS?%x, int_status 0x%x\n",
Eilon Greenstein2f904462009-08-12 08:22:16 +00005469 port, (vars->phy_flags & PHY_XGXS_FLAG),
5470 REG_RD(bp, NIG_REG_STATUS_INTERRUPT_PORT0 + port*4));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005471
Eilon Greenstein2f904462009-08-12 08:22:16 +00005472 is_mi_int = (u8)(REG_RD(bp, NIG_REG_EMAC0_STATUS_MISC_MI_INT +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005473 port*0x18) > 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005474 DP(NETIF_MSG_LINK, "int_mask 0x%x MI_INT %x, SERDES_LINK %x\n",
Eilon Greenstein2f904462009-08-12 08:22:16 +00005475 REG_RD(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4),
5476 is_mi_int,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005477 REG_RD(bp, NIG_REG_SERDES0_STATUS_LINK_STATUS + port*0x3c));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005478
5479 DP(NETIF_MSG_LINK, " 10G %x, XGXS_LINK %x\n",
5480 REG_RD(bp, NIG_REG_XGXS0_STATUS_LINK10G + port*0x68),
5481 REG_RD(bp, NIG_REG_XGXS0_STATUS_LINK_STATUS + port*0x68));
5482
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00005483 /* disable emac */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00005484 if (!CHIP_IS_E3(bp))
5485 REG_WR(bp, NIG_REG_NIG_EMAC0_EN + port*4, 0);
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00005486
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005487 /*
5488 * Step 1:
5489 * Check external link change only for external phys, and apply
5490 * priority selection between them in case the link on both phys
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00005491 * is up. Note that instead of the common vars, a temporary
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005492 * vars argument is used since each phy may have different link/
5493 * speed/duplex result
5494 */
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005495 for (phy_index = EXT_PHY1; phy_index < params->num_phys;
5496 phy_index++) {
5497 struct bnx2x_phy *phy = &params->phy[phy_index];
5498 if (!phy->read_status)
5499 continue;
5500 /* Read link status and params of this ext phy */
5501 cur_link_up = phy->read_status(phy, params,
5502 &phy_vars[phy_index]);
5503 if (cur_link_up) {
5504 DP(NETIF_MSG_LINK, "phy in index %d link is up\n",
5505 phy_index);
5506 } else {
5507 DP(NETIF_MSG_LINK, "phy in index %d link is down\n",
5508 phy_index);
5509 continue;
5510 }
Yaniv Rosner57963ed2008-08-13 15:55:28 -07005511
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005512 if (!ext_phy_link_up) {
5513 ext_phy_link_up = 1;
5514 active_external_phy = phy_index;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005515 } else {
5516 switch (bnx2x_phy_selection(params)) {
5517 case PORT_HW_CFG_PHY_SELECTION_HARDWARE_DEFAULT:
5518 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY_PRIORITY:
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005519 /*
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005520 * In this option, the first PHY makes sure to pass the
5521 * traffic through itself only.
5522 * Its not clear how to reset the link on the second phy
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005523 */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005524 active_external_phy = EXT_PHY1;
5525 break;
5526 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY_PRIORITY:
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005527 /*
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005528 * In this option, the first PHY makes sure to pass the
5529 * traffic through the second PHY.
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005530 */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005531 active_external_phy = EXT_PHY2;
5532 break;
5533 default:
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005534 /*
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005535 * Link indication on both PHYs with the following cases
5536 * is invalid:
5537 * - FIRST_PHY means that second phy wasn't initialized,
5538 * hence its link is expected to be down
5539 * - SECOND_PHY means that first phy should not be able
5540 * to link up by itself (using configuration)
5541 * - DEFAULT should be overriden during initialiazation
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005542 */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005543 DP(NETIF_MSG_LINK, "Invalid link indication"
5544 "mpc=0x%x. DISABLING LINK !!!\n",
5545 params->multi_phy_config);
5546 ext_phy_link_up = 0;
5547 break;
5548 }
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005549 }
5550 }
5551 prev_line_speed = vars->line_speed;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005552 /*
5553 * Step 2:
5554 * Read the status of the internal phy. In case of
5555 * DIRECT_SINGLE_MEDIA board, this link is the external link,
5556 * otherwise this is the link between the 577xx and the first
5557 * external phy
5558 */
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005559 if (params->phy[INT_PHY].read_status)
5560 params->phy[INT_PHY].read_status(
5561 &params->phy[INT_PHY],
5562 params, vars);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005563 /*
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005564 * The INT_PHY flow control reside in the vars. This include the
5565 * case where the speed or flow control are not set to AUTO.
5566 * Otherwise, the active external phy flow control result is set
5567 * to the vars. The ext_phy_line_speed is needed to check if the
5568 * speed is different between the internal phy and external phy.
5569 * This case may be result of intermediate link speed change.
5570 */
5571 if (active_external_phy > INT_PHY) {
5572 vars->flow_ctrl = phy_vars[active_external_phy].flow_ctrl;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005573 /*
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005574 * Link speed is taken from the XGXS. AN and FC result from
5575 * the external phy.
5576 */
5577 vars->link_status |= phy_vars[active_external_phy].link_status;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005578
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005579 /*
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005580 * if active_external_phy is first PHY and link is up - disable
5581 * disable TX on second external PHY
5582 */
5583 if (active_external_phy == EXT_PHY1) {
5584 if (params->phy[EXT_PHY2].phy_specific_func) {
5585 DP(NETIF_MSG_LINK, "Disabling TX on"
5586 " EXT_PHY2\n");
5587 params->phy[EXT_PHY2].phy_specific_func(
5588 &params->phy[EXT_PHY2],
5589 params, DISABLE_TX);
5590 }
5591 }
5592
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005593 ext_phy_line_speed = phy_vars[active_external_phy].line_speed;
5594 vars->duplex = phy_vars[active_external_phy].duplex;
5595 if (params->phy[active_external_phy].supported &
5596 SUPPORTED_FIBRE)
5597 vars->link_status |= LINK_STATUS_SERDES_LINK;
Yaniv Rosnerfd36a2e2011-05-31 21:29:05 +00005598 else
5599 vars->link_status &= ~LINK_STATUS_SERDES_LINK;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005600 DP(NETIF_MSG_LINK, "Active external phy selected: %x\n",
5601 active_external_phy);
5602 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005603
5604 for (phy_index = EXT_PHY1; phy_index < params->num_phys;
5605 phy_index++) {
5606 if (params->phy[phy_index].flags &
5607 FLAGS_REARM_LATCH_SIGNAL) {
5608 bnx2x_rearm_latch_signal(bp, port,
5609 phy_index ==
5610 active_external_phy);
5611 break;
5612 }
5613 }
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005614 DP(NETIF_MSG_LINK, "vars->flow_ctrl = 0x%x, vars->link_status = 0x%x,"
5615 " ext_phy_line_speed = %d\n", vars->flow_ctrl,
5616 vars->link_status, ext_phy_line_speed);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005617 /*
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005618 * Upon link speed change set the NIG into drain mode. Comes to
5619 * deals with possible FIFO glitch due to clk change when speed
5620 * is decreased without link down indicator
5621 */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005622
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005623 if (vars->phy_link_up) {
5624 if (!(SINGLE_MEDIA_DIRECT(params)) && ext_phy_link_up &&
5625 (ext_phy_line_speed != vars->line_speed)) {
5626 DP(NETIF_MSG_LINK, "Internal link speed %d is"
5627 " different than the external"
5628 " link speed %d\n", vars->line_speed,
5629 ext_phy_line_speed);
5630 vars->phy_link_up = 0;
5631 } else if (prev_line_speed != vars->line_speed) {
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005632 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4,
5633 0);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005634 msleep(1);
5635 }
5636 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005637
5638 /* anything 10 and over uses the bmac */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005639 link_10g_plus = (vars->line_speed >= SPEED_10000);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005640
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005641 bnx2x_link_int_ack(params, vars, link_10g_plus);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005642
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005643 /*
5644 * In case external phy link is up, and internal link is down
5645 * (not initialized yet probably after link initialization, it
5646 * needs to be initialized.
5647 * Note that after link down-up as result of cable plug, the xgxs
5648 * link would probably become up again without the need
5649 * initialize it
5650 */
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005651 if (!(SINGLE_MEDIA_DIRECT(params))) {
5652 DP(NETIF_MSG_LINK, "ext_phy_link_up = %d, int_link_up = %d,"
5653 " init_preceding = %d\n", ext_phy_link_up,
5654 vars->phy_link_up,
5655 params->phy[EXT_PHY1].flags &
5656 FLAGS_INIT_XGXS_FIRST);
5657 if (!(params->phy[EXT_PHY1].flags &
5658 FLAGS_INIT_XGXS_FIRST)
5659 && ext_phy_link_up && !vars->phy_link_up) {
5660 vars->line_speed = ext_phy_line_speed;
5661 if (vars->line_speed < SPEED_1000)
5662 vars->phy_flags |= PHY_SGMII_FLAG;
5663 else
5664 vars->phy_flags &= ~PHY_SGMII_FLAG;
Yaniv Rosnerec146a62011-05-31 21:29:27 +00005665
5666 if (params->phy[INT_PHY].config_init)
5667 params->phy[INT_PHY].config_init(
5668 &params->phy[INT_PHY], params,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005669 vars);
5670 }
5671 }
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005672 /*
5673 * Link is up only if both local phy and external phy (in case of
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00005674 * non-direct board) are up and no fault detected on active PHY.
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005675 */
5676 vars->link_up = (vars->phy_link_up &&
5677 (ext_phy_link_up ||
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00005678 SINGLE_MEDIA_DIRECT(params)) &&
5679 (phy_vars[active_external_phy].fault_detected == 0));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005680
Yaniv Rosner57963ed2008-08-13 15:55:28 -07005681 if (vars->link_up)
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005682 rc = bnx2x_update_link_up(params, vars, link_10g_plus);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07005683 else
5684 rc = bnx2x_update_link_down(params, vars);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005685
5686 return rc;
5687}
5688
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005689
5690/*****************************************************************************/
5691/* External Phy section */
5692/*****************************************************************************/
5693void bnx2x_ext_phy_hw_reset(struct bnx2x *bp, u8 port)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005694{
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005695 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005696 MISC_REGISTERS_GPIO_OUTPUT_LOW, port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005697 msleep(1);
5698 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005699 MISC_REGISTERS_GPIO_OUTPUT_HIGH, port);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005700}
5701
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005702static void bnx2x_save_spirom_version(struct bnx2x *bp, u8 port,
5703 u32 spirom_ver, u32 ver_addr)
5704{
5705 DP(NETIF_MSG_LINK, "FW version 0x%x:0x%x for port %d\n",
5706 (u16)(spirom_ver>>16), (u16)spirom_ver, port);
5707
5708 if (ver_addr)
5709 REG_WR(bp, ver_addr, spirom_ver);
5710}
5711
5712static void bnx2x_save_bcm_spirom_ver(struct bnx2x *bp,
5713 struct bnx2x_phy *phy,
5714 u8 port)
5715{
5716 u16 fw_ver1, fw_ver2;
5717
5718 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005719 MDIO_PMA_REG_ROM_VER1, &fw_ver1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005720 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005721 MDIO_PMA_REG_ROM_VER2, &fw_ver2);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005722 bnx2x_save_spirom_version(bp, port, (u32)(fw_ver1<<16 | fw_ver2),
5723 phy->ver_addr);
5724}
5725
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005726static void bnx2x_ext_phy_10G_an_resolve(struct bnx2x *bp,
5727 struct bnx2x_phy *phy,
5728 struct link_vars *vars)
5729{
5730 u16 val;
5731 bnx2x_cl45_read(bp, phy,
5732 MDIO_AN_DEVAD,
5733 MDIO_AN_REG_STATUS, &val);
5734 bnx2x_cl45_read(bp, phy,
5735 MDIO_AN_DEVAD,
5736 MDIO_AN_REG_STATUS, &val);
5737 if (val & (1<<5))
5738 vars->link_status |= LINK_STATUS_AUTO_NEGOTIATE_COMPLETE;
5739 if ((val & (1<<0)) == 0)
5740 vars->link_status |= LINK_STATUS_PARALLEL_DETECTION_USED;
5741}
5742
5743/******************************************************************/
5744/* common BCM8073/BCM8727 PHY SECTION */
5745/******************************************************************/
5746static void bnx2x_8073_resolve_fc(struct bnx2x_phy *phy,
5747 struct link_params *params,
5748 struct link_vars *vars)
5749{
5750 struct bnx2x *bp = params->bp;
5751 if (phy->req_line_speed == SPEED_10 ||
5752 phy->req_line_speed == SPEED_100) {
5753 vars->flow_ctrl = phy->req_flow_ctrl;
5754 return;
5755 }
5756
5757 if (bnx2x_ext_phy_resolve_fc(phy, params, vars) &&
5758 (vars->flow_ctrl == BNX2X_FLOW_CTRL_NONE)) {
5759 u16 pause_result;
5760 u16 ld_pause; /* local */
5761 u16 lp_pause; /* link partner */
5762 bnx2x_cl45_read(bp, phy,
5763 MDIO_AN_DEVAD,
5764 MDIO_AN_REG_CL37_FC_LD, &ld_pause);
5765
5766 bnx2x_cl45_read(bp, phy,
5767 MDIO_AN_DEVAD,
5768 MDIO_AN_REG_CL37_FC_LP, &lp_pause);
5769 pause_result = (ld_pause &
5770 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) >> 5;
5771 pause_result |= (lp_pause &
5772 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) >> 7;
5773
5774 bnx2x_pause_resolve(vars, pause_result);
5775 DP(NETIF_MSG_LINK, "Ext PHY CL37 pause result 0x%x\n",
5776 pause_result);
5777 }
5778}
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00005779static int bnx2x_8073_8727_external_rom_boot(struct bnx2x *bp,
5780 struct bnx2x_phy *phy,
5781 u8 port)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005782{
Yaniv Rosner5c99274b2011-01-18 04:33:36 +00005783 u32 count = 0;
5784 u16 fw_ver1, fw_msgout;
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00005785 int rc = 0;
Yaniv Rosner5c99274b2011-01-18 04:33:36 +00005786
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005787 /* Boot port from external ROM */
5788 /* EDC grst */
5789 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005790 MDIO_PMA_DEVAD,
5791 MDIO_PMA_REG_GEN_CTRL,
5792 0x0001);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005793
5794 /* ucode reboot and rst */
5795 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005796 MDIO_PMA_DEVAD,
5797 MDIO_PMA_REG_GEN_CTRL,
5798 0x008c);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005799
5800 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005801 MDIO_PMA_DEVAD,
5802 MDIO_PMA_REG_MISC_CTRL1, 0x0001);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005803
5804 /* Reset internal microprocessor */
5805 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005806 MDIO_PMA_DEVAD,
5807 MDIO_PMA_REG_GEN_CTRL,
5808 MDIO_PMA_REG_GEN_CTRL_ROM_MICRO_RESET);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005809
5810 /* Release srst bit */
5811 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005812 MDIO_PMA_DEVAD,
5813 MDIO_PMA_REG_GEN_CTRL,
5814 MDIO_PMA_REG_GEN_CTRL_ROM_RESET_INTERNAL_MP);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005815
Yaniv Rosner5c99274b2011-01-18 04:33:36 +00005816 /* Delay 100ms per the PHY specifications */
5817 msleep(100);
5818
5819 /* 8073 sometimes taking longer to download */
5820 do {
5821 count++;
5822 if (count > 300) {
5823 DP(NETIF_MSG_LINK,
5824 "bnx2x_8073_8727_external_rom_boot port %x:"
5825 "Download failed. fw version = 0x%x\n",
5826 port, fw_ver1);
5827 rc = -EINVAL;
5828 break;
5829 }
5830
5831 bnx2x_cl45_read(bp, phy,
5832 MDIO_PMA_DEVAD,
5833 MDIO_PMA_REG_ROM_VER1, &fw_ver1);
5834 bnx2x_cl45_read(bp, phy,
5835 MDIO_PMA_DEVAD,
5836 MDIO_PMA_REG_M8051_MSGOUT_REG, &fw_msgout);
5837
5838 msleep(1);
5839 } while (fw_ver1 == 0 || fw_ver1 == 0x4321 ||
5840 ((fw_msgout & 0xff) != 0x03 && (phy->type ==
5841 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073)));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005842
5843 /* Clear ser_boot_ctl bit */
5844 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005845 MDIO_PMA_DEVAD,
5846 MDIO_PMA_REG_MISC_CTRL1, 0x0000);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005847 bnx2x_save_bcm_spirom_ver(bp, phy, port);
Yaniv Rosner5c99274b2011-01-18 04:33:36 +00005848
5849 DP(NETIF_MSG_LINK,
5850 "bnx2x_8073_8727_external_rom_boot port %x:"
5851 "Download complete. fw version = 0x%x\n",
5852 port, fw_ver1);
5853
5854 return rc;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005855}
5856
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005857/******************************************************************/
5858/* BCM8073 PHY SECTION */
5859/******************************************************************/
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00005860static int bnx2x_8073_is_snr_needed(struct bnx2x *bp, struct bnx2x_phy *phy)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005861{
5862 /* This is only required for 8073A1, version 102 only */
5863 u16 val;
5864
5865 /* Read 8073 HW revision*/
5866 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005867 MDIO_PMA_DEVAD,
5868 MDIO_PMA_REG_8073_CHIP_REV, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005869
5870 if (val != 1) {
5871 /* No need to workaround in 8073 A1 */
5872 return 0;
5873 }
5874
5875 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005876 MDIO_PMA_DEVAD,
5877 MDIO_PMA_REG_ROM_VER2, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005878
5879 /* SNR should be applied only for version 0x102 */
5880 if (val != 0x102)
5881 return 0;
5882
5883 return 1;
5884}
5885
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00005886static int bnx2x_8073_xaui_wa(struct bnx2x *bp, struct bnx2x_phy *phy)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005887{
5888 u16 val, cnt, cnt1 ;
5889
5890 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005891 MDIO_PMA_DEVAD,
5892 MDIO_PMA_REG_8073_CHIP_REV, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005893
5894 if (val > 0) {
5895 /* No need to workaround in 8073 A1 */
5896 return 0;
5897 }
5898 /* XAUI workaround in 8073 A0: */
5899
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005900 /*
5901 * After loading the boot ROM and restarting Autoneg, poll
5902 * Dev1, Reg $C820:
5903 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005904
5905 for (cnt = 0; cnt < 1000; cnt++) {
5906 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005907 MDIO_PMA_DEVAD,
5908 MDIO_PMA_REG_8073_SPEED_LINK_STATUS,
5909 &val);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005910 /*
5911 * If bit [14] = 0 or bit [13] = 0, continue on with
5912 * system initialization (XAUI work-around not required, as
5913 * these bits indicate 2.5G or 1G link up).
5914 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005915 if (!(val & (1<<14)) || !(val & (1<<13))) {
5916 DP(NETIF_MSG_LINK, "XAUI work-around not required\n");
5917 return 0;
5918 } else if (!(val & (1<<15))) {
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005919 DP(NETIF_MSG_LINK, "bit 15 went off\n");
5920 /*
5921 * If bit 15 is 0, then poll Dev1, Reg $C841 until it's
5922 * MSB (bit15) goes to 1 (indicating that the XAUI
5923 * workaround has completed), then continue on with
5924 * system initialization.
5925 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005926 for (cnt1 = 0; cnt1 < 1000; cnt1++) {
5927 bnx2x_cl45_read(bp, phy,
5928 MDIO_PMA_DEVAD,
5929 MDIO_PMA_REG_8073_XAUI_WA, &val);
5930 if (val & (1<<15)) {
5931 DP(NETIF_MSG_LINK,
5932 "XAUI workaround has completed\n");
5933 return 0;
5934 }
5935 msleep(3);
5936 }
5937 break;
5938 }
5939 msleep(3);
5940 }
5941 DP(NETIF_MSG_LINK, "Warning: XAUI work-around timeout !!!\n");
5942 return -EINVAL;
5943}
5944
5945static void bnx2x_807x_force_10G(struct bnx2x *bp, struct bnx2x_phy *phy)
5946{
5947 /* Force KR or KX */
5948 bnx2x_cl45_write(bp, phy,
5949 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x2040);
5950 bnx2x_cl45_write(bp, phy,
5951 MDIO_PMA_DEVAD, MDIO_PMA_REG_10G_CTRL2, 0x000b);
5952 bnx2x_cl45_write(bp, phy,
5953 MDIO_PMA_DEVAD, MDIO_PMA_REG_BCM_CTRL, 0x0000);
5954 bnx2x_cl45_write(bp, phy,
5955 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x0000);
5956}
5957
5958static void bnx2x_8073_set_pause_cl37(struct link_params *params,
5959 struct bnx2x_phy *phy,
5960 struct link_vars *vars)
5961{
5962 u16 cl37_val;
5963 struct bnx2x *bp = params->bp;
5964 bnx2x_cl45_read(bp, phy,
5965 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LD, &cl37_val);
5966
5967 cl37_val &= ~MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH;
5968 /* Please refer to Table 28B-3 of 802.3ab-1999 spec. */
5969 bnx2x_calc_ieee_aneg_adv(phy, params, &vars->ieee_fc);
5970 if ((vars->ieee_fc &
5971 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_SYMMETRIC) ==
5972 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_SYMMETRIC) {
5973 cl37_val |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_SYMMETRIC;
5974 }
5975 if ((vars->ieee_fc &
5976 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC) ==
5977 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC) {
5978 cl37_val |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC;
5979 }
5980 if ((vars->ieee_fc &
5981 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) ==
5982 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) {
5983 cl37_val |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH;
5984 }
5985 DP(NETIF_MSG_LINK,
5986 "Ext phy AN advertize cl37 0x%x\n", cl37_val);
5987
5988 bnx2x_cl45_write(bp, phy,
5989 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LD, cl37_val);
5990 msleep(500);
5991}
5992
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00005993static int bnx2x_8073_config_init(struct bnx2x_phy *phy,
5994 struct link_params *params,
5995 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005996{
5997 struct bnx2x *bp = params->bp;
5998 u16 val = 0, tmp1;
5999 u8 gpio_port;
6000 DP(NETIF_MSG_LINK, "Init 8073\n");
6001
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006002 if (CHIP_IS_E2(bp))
6003 gpio_port = BP_PATH(bp);
6004 else
6005 gpio_port = params->port;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006006 /* Restore normal power mode*/
6007 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006008 MISC_REGISTERS_GPIO_OUTPUT_HIGH, gpio_port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006009
6010 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006011 MISC_REGISTERS_GPIO_OUTPUT_HIGH, gpio_port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006012
6013 /* enable LASI */
6014 bnx2x_cl45_write(bp, phy,
6015 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_ALARM_CTRL, (1<<2));
6016 bnx2x_cl45_write(bp, phy,
6017 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_CTRL, 0x0004);
6018
6019 bnx2x_8073_set_pause_cl37(params, phy, vars);
6020
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006021 bnx2x_cl45_read(bp, phy,
6022 MDIO_PMA_DEVAD, MDIO_PMA_REG_M8051_MSGOUT_REG, &tmp1);
6023
6024 bnx2x_cl45_read(bp, phy,
6025 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_ALARM, &tmp1);
6026
6027 DP(NETIF_MSG_LINK, "Before rom RX_ALARM(port1): 0x%x\n", tmp1);
6028
Yaniv Rosner74d7a112011-01-18 04:33:18 +00006029 /* Swap polarity if required - Must be done only in non-1G mode */
6030 if (params->lane_config & PORT_HW_CFG_SWAP_PHY_POLARITY_ENABLED) {
6031 /* Configure the 8073 to swap _P and _N of the KR lines */
6032 DP(NETIF_MSG_LINK, "Swapping polarity for the 8073\n");
6033 /* 10G Rx/Tx and 1G Tx signal polarity swap */
6034 bnx2x_cl45_read(bp, phy,
6035 MDIO_PMA_DEVAD,
6036 MDIO_PMA_REG_8073_OPT_DIGITAL_CTRL, &val);
6037 bnx2x_cl45_write(bp, phy,
6038 MDIO_PMA_DEVAD,
6039 MDIO_PMA_REG_8073_OPT_DIGITAL_CTRL,
6040 (val | (3<<9)));
6041 }
6042
6043
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006044 /* Enable CL37 BAM */
Yaniv Rosner121839b2010-11-01 05:32:38 +00006045 if (REG_RD(bp, params->shmem_base +
6046 offsetof(struct shmem_region, dev_info.
6047 port_hw_config[params->port].default_cfg)) &
6048 PORT_HW_CFG_ENABLE_BAM_ON_KR_ENABLED) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006049
Yaniv Rosner121839b2010-11-01 05:32:38 +00006050 bnx2x_cl45_read(bp, phy,
6051 MDIO_AN_DEVAD,
6052 MDIO_AN_REG_8073_BAM, &val);
6053 bnx2x_cl45_write(bp, phy,
6054 MDIO_AN_DEVAD,
6055 MDIO_AN_REG_8073_BAM, val | 1);
6056 DP(NETIF_MSG_LINK, "Enable CL37 BAM on KR\n");
6057 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006058 if (params->loopback_mode == LOOPBACK_EXT) {
6059 bnx2x_807x_force_10G(bp, phy);
6060 DP(NETIF_MSG_LINK, "Forced speed 10G on 807X\n");
6061 return 0;
6062 } else {
6063 bnx2x_cl45_write(bp, phy,
6064 MDIO_PMA_DEVAD, MDIO_PMA_REG_BCM_CTRL, 0x0002);
6065 }
6066 if (phy->req_line_speed != SPEED_AUTO_NEG) {
6067 if (phy->req_line_speed == SPEED_10000) {
6068 val = (1<<7);
6069 } else if (phy->req_line_speed == SPEED_2500) {
6070 val = (1<<5);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006071 /*
6072 * Note that 2.5G works only when used with 1G
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006073 * advertisement
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006074 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006075 } else
6076 val = (1<<5);
6077 } else {
6078 val = 0;
6079 if (phy->speed_cap_mask &
6080 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
6081 val |= (1<<7);
6082
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006083 /* Note that 2.5G works only when used with 1G advertisement */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006084 if (phy->speed_cap_mask &
6085 (PORT_HW_CFG_SPEED_CAPABILITY_D0_1G |
6086 PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
6087 val |= (1<<5);
6088 DP(NETIF_MSG_LINK, "807x autoneg val = 0x%x\n", val);
6089 }
6090
6091 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV, val);
6092 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_8073_2_5G, &tmp1);
6093
6094 if (((phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G) &&
6095 (phy->req_line_speed == SPEED_AUTO_NEG)) ||
6096 (phy->req_line_speed == SPEED_2500)) {
6097 u16 phy_ver;
6098 /* Allow 2.5G for A1 and above */
6099 bnx2x_cl45_read(bp, phy,
6100 MDIO_PMA_DEVAD, MDIO_PMA_REG_8073_CHIP_REV,
6101 &phy_ver);
6102 DP(NETIF_MSG_LINK, "Add 2.5G\n");
6103 if (phy_ver > 0)
6104 tmp1 |= 1;
6105 else
6106 tmp1 &= 0xfffe;
6107 } else {
6108 DP(NETIF_MSG_LINK, "Disable 2.5G\n");
6109 tmp1 &= 0xfffe;
6110 }
6111
6112 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_8073_2_5G, tmp1);
6113 /* Add support for CL37 (passive mode) II */
6114
6115 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LD, &tmp1);
6116 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LD,
6117 (tmp1 | ((phy->req_duplex == DUPLEX_FULL) ?
6118 0x20 : 0x40)));
6119
6120 /* Add support for CL37 (passive mode) III */
6121 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CL37_AN, 0x1000);
6122
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006123 /*
6124 * The SNR will improve about 2db by changing BW and FEE main
6125 * tap. Rest commands are executed after link is up
6126 * Change FFE main cursor to 5 in EDC register
6127 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006128 if (bnx2x_8073_is_snr_needed(bp, phy))
6129 bnx2x_cl45_write(bp, phy,
6130 MDIO_PMA_DEVAD, MDIO_PMA_REG_EDC_FFE_MAIN,
6131 0xFB0C);
6132
6133 /* Enable FEC (Forware Error Correction) Request in the AN */
6134 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV2, &tmp1);
6135 tmp1 |= (1<<15);
6136 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV2, tmp1);
6137
6138 bnx2x_ext_phy_set_pause(params, phy, vars);
6139
6140 /* Restart autoneg */
6141 msleep(500);
6142 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x1200);
6143 DP(NETIF_MSG_LINK, "807x Autoneg Restart: Advertise 1G=%x, 10G=%x\n",
6144 ((val & (1<<5)) > 0), ((val & (1<<7)) > 0));
6145 return 0;
6146}
6147
6148static u8 bnx2x_8073_read_status(struct bnx2x_phy *phy,
6149 struct link_params *params,
6150 struct link_vars *vars)
6151{
6152 struct bnx2x *bp = params->bp;
6153 u8 link_up = 0;
6154 u16 val1, val2;
6155 u16 link_status = 0;
6156 u16 an1000_status = 0;
6157
6158 bnx2x_cl45_read(bp, phy,
6159 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_STATUS, &val1);
6160
6161 DP(NETIF_MSG_LINK, "8703 LASI status 0x%x\n", val1);
6162
6163 /* clear the interrupt LASI status register */
6164 bnx2x_cl45_read(bp, phy,
6165 MDIO_PCS_DEVAD, MDIO_PCS_REG_STATUS, &val2);
6166 bnx2x_cl45_read(bp, phy,
6167 MDIO_PCS_DEVAD, MDIO_PCS_REG_STATUS, &val1);
6168 DP(NETIF_MSG_LINK, "807x PCS status 0x%x->0x%x\n", val2, val1);
6169 /* Clear MSG-OUT */
6170 bnx2x_cl45_read(bp, phy,
6171 MDIO_PMA_DEVAD, MDIO_PMA_REG_M8051_MSGOUT_REG, &val1);
6172
6173 /* Check the LASI */
6174 bnx2x_cl45_read(bp, phy,
6175 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_ALARM, &val2);
6176
6177 DP(NETIF_MSG_LINK, "KR 0x9003 0x%x\n", val2);
6178
6179 /* Check the link status */
6180 bnx2x_cl45_read(bp, phy,
6181 MDIO_PCS_DEVAD, MDIO_PCS_REG_STATUS, &val2);
6182 DP(NETIF_MSG_LINK, "KR PCS status 0x%x\n", val2);
6183
6184 bnx2x_cl45_read(bp, phy,
6185 MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val2);
6186 bnx2x_cl45_read(bp, phy,
6187 MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val1);
6188 link_up = ((val1 & 4) == 4);
6189 DP(NETIF_MSG_LINK, "PMA_REG_STATUS=0x%x\n", val1);
6190
6191 if (link_up &&
6192 ((phy->req_line_speed != SPEED_10000))) {
6193 if (bnx2x_8073_xaui_wa(bp, phy) != 0)
6194 return 0;
6195 }
6196 bnx2x_cl45_read(bp, phy,
6197 MDIO_AN_DEVAD, MDIO_AN_REG_LINK_STATUS, &an1000_status);
6198 bnx2x_cl45_read(bp, phy,
6199 MDIO_AN_DEVAD, MDIO_AN_REG_LINK_STATUS, &an1000_status);
6200
6201 /* Check the link status on 1.1.2 */
6202 bnx2x_cl45_read(bp, phy,
6203 MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val2);
6204 bnx2x_cl45_read(bp, phy,
6205 MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val1);
6206 DP(NETIF_MSG_LINK, "KR PMA status 0x%x->0x%x,"
6207 "an_link_status=0x%x\n", val2, val1, an1000_status);
6208
6209 link_up = (((val1 & 4) == 4) || (an1000_status & (1<<1)));
6210 if (link_up && bnx2x_8073_is_snr_needed(bp, phy)) {
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006211 /*
6212 * The SNR will improve about 2dbby changing the BW and FEE main
6213 * tap. The 1st write to change FFE main tap is set before
6214 * restart AN. Change PLL Bandwidth in EDC register
6215 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006216 bnx2x_cl45_write(bp, phy,
6217 MDIO_PMA_DEVAD, MDIO_PMA_REG_PLL_BANDWIDTH,
6218 0x26BC);
6219
6220 /* Change CDR Bandwidth in EDC register */
6221 bnx2x_cl45_write(bp, phy,
6222 MDIO_PMA_DEVAD, MDIO_PMA_REG_CDR_BANDWIDTH,
6223 0x0333);
6224 }
6225 bnx2x_cl45_read(bp, phy,
6226 MDIO_PMA_DEVAD, MDIO_PMA_REG_8073_SPEED_LINK_STATUS,
6227 &link_status);
6228
6229 /* Bits 0..2 --> speed detected, bits 13..15--> link is down */
6230 if ((link_status & (1<<2)) && (!(link_status & (1<<15)))) {
6231 link_up = 1;
6232 vars->line_speed = SPEED_10000;
6233 DP(NETIF_MSG_LINK, "port %x: External link up in 10G\n",
6234 params->port);
6235 } else if ((link_status & (1<<1)) && (!(link_status & (1<<14)))) {
6236 link_up = 1;
6237 vars->line_speed = SPEED_2500;
6238 DP(NETIF_MSG_LINK, "port %x: External link up in 2.5G\n",
6239 params->port);
6240 } else if ((link_status & (1<<0)) && (!(link_status & (1<<13)))) {
6241 link_up = 1;
6242 vars->line_speed = SPEED_1000;
6243 DP(NETIF_MSG_LINK, "port %x: External link up in 1G\n",
6244 params->port);
6245 } else {
6246 link_up = 0;
6247 DP(NETIF_MSG_LINK, "port %x: External link is down\n",
6248 params->port);
6249 }
6250
6251 if (link_up) {
Yaniv Rosner74d7a112011-01-18 04:33:18 +00006252 /* Swap polarity if required */
6253 if (params->lane_config &
6254 PORT_HW_CFG_SWAP_PHY_POLARITY_ENABLED) {
6255 /* Configure the 8073 to swap P and N of the KR lines */
6256 bnx2x_cl45_read(bp, phy,
6257 MDIO_XS_DEVAD,
6258 MDIO_XS_REG_8073_RX_CTRL_PCIE, &val1);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006259 /*
6260 * Set bit 3 to invert Rx in 1G mode and clear this bit
6261 * when it`s in 10G mode.
6262 */
Yaniv Rosner74d7a112011-01-18 04:33:18 +00006263 if (vars->line_speed == SPEED_1000) {
6264 DP(NETIF_MSG_LINK, "Swapping 1G polarity for"
6265 "the 8073\n");
6266 val1 |= (1<<3);
6267 } else
6268 val1 &= ~(1<<3);
6269
6270 bnx2x_cl45_write(bp, phy,
6271 MDIO_XS_DEVAD,
6272 MDIO_XS_REG_8073_RX_CTRL_PCIE,
6273 val1);
6274 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006275 bnx2x_ext_phy_10G_an_resolve(bp, phy, vars);
6276 bnx2x_8073_resolve_fc(phy, params, vars);
Yaniv Rosner791f18c2011-01-18 04:33:42 +00006277 vars->duplex = DUPLEX_FULL;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006278 }
6279 return link_up;
6280}
6281
6282static void bnx2x_8073_link_reset(struct bnx2x_phy *phy,
6283 struct link_params *params)
6284{
6285 struct bnx2x *bp = params->bp;
6286 u8 gpio_port;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006287 if (CHIP_IS_E2(bp))
6288 gpio_port = BP_PATH(bp);
6289 else
6290 gpio_port = params->port;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006291 DP(NETIF_MSG_LINK, "Setting 8073 port %d into low power mode\n",
6292 gpio_port);
6293 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006294 MISC_REGISTERS_GPIO_OUTPUT_LOW,
6295 gpio_port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006296}
6297
6298/******************************************************************/
6299/* BCM8705 PHY SECTION */
6300/******************************************************************/
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006301static int bnx2x_8705_config_init(struct bnx2x_phy *phy,
6302 struct link_params *params,
6303 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006304{
6305 struct bnx2x *bp = params->bp;
6306 DP(NETIF_MSG_LINK, "init 8705\n");
6307 /* Restore normal power mode*/
6308 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006309 MISC_REGISTERS_GPIO_OUTPUT_HIGH, params->port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006310 /* HW reset */
6311 bnx2x_ext_phy_hw_reset(bp, params->port);
6312 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0xa040);
Yaniv Rosner6d870c32011-01-31 04:22:20 +00006313 bnx2x_wait_reset_complete(bp, phy, params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006314
6315 bnx2x_cl45_write(bp, phy,
6316 MDIO_PMA_DEVAD, MDIO_PMA_REG_MISC_CTRL, 0x8288);
6317 bnx2x_cl45_write(bp, phy,
6318 MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER, 0x7fbf);
6319 bnx2x_cl45_write(bp, phy,
6320 MDIO_PMA_DEVAD, MDIO_PMA_REG_CMU_PLL_BYPASS, 0x0100);
6321 bnx2x_cl45_write(bp, phy,
6322 MDIO_WIS_DEVAD, MDIO_WIS_REG_LASI_CNTL, 0x1);
6323 /* BCM8705 doesn't have microcode, hence the 0 */
6324 bnx2x_save_spirom_version(bp, params->port, params->shmem_base, 0);
6325 return 0;
6326}
6327
6328static u8 bnx2x_8705_read_status(struct bnx2x_phy *phy,
6329 struct link_params *params,
6330 struct link_vars *vars)
6331{
6332 u8 link_up = 0;
6333 u16 val1, rx_sd;
6334 struct bnx2x *bp = params->bp;
6335 DP(NETIF_MSG_LINK, "read status 8705\n");
6336 bnx2x_cl45_read(bp, phy,
6337 MDIO_WIS_DEVAD, MDIO_WIS_REG_LASI_STATUS, &val1);
6338 DP(NETIF_MSG_LINK, "8705 LASI status 0x%x\n", val1);
6339
6340 bnx2x_cl45_read(bp, phy,
6341 MDIO_WIS_DEVAD, MDIO_WIS_REG_LASI_STATUS, &val1);
6342 DP(NETIF_MSG_LINK, "8705 LASI status 0x%x\n", val1);
6343
6344 bnx2x_cl45_read(bp, phy,
6345 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_SD, &rx_sd);
6346
6347 bnx2x_cl45_read(bp, phy,
6348 MDIO_PMA_DEVAD, 0xc809, &val1);
6349 bnx2x_cl45_read(bp, phy,
6350 MDIO_PMA_DEVAD, 0xc809, &val1);
6351
6352 DP(NETIF_MSG_LINK, "8705 1.c809 val=0x%x\n", val1);
6353 link_up = ((rx_sd & 0x1) && (val1 & (1<<9)) && ((val1 & (1<<8)) == 0));
6354 if (link_up) {
6355 vars->line_speed = SPEED_10000;
6356 bnx2x_ext_phy_resolve_fc(phy, params, vars);
6357 }
6358 return link_up;
6359}
6360
6361/******************************************************************/
6362/* SFP+ module Section */
6363/******************************************************************/
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00006364static u8 bnx2x_get_gpio_port(struct link_params *params)
6365{
6366 u8 gpio_port;
6367 u32 swap_val, swap_override;
6368 struct bnx2x *bp = params->bp;
6369 if (CHIP_IS_E2(bp))
6370 gpio_port = BP_PATH(bp);
6371 else
6372 gpio_port = params->port;
6373 swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
6374 swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
6375 return gpio_port ^ (swap_val && swap_override);
6376}
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006377
6378static void bnx2x_sfp_e1e2_set_transmitter(struct link_params *params,
6379 struct bnx2x_phy *phy,
6380 u8 tx_en)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006381{
6382 u16 val;
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00006383 u8 port = params->port;
6384 struct bnx2x *bp = params->bp;
6385 u32 tx_en_mode;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006386
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006387 /* Disable/Enable transmitter ( TX laser of the SFP+ module.)*/
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00006388 tx_en_mode = REG_RD(bp, params->shmem_base +
6389 offsetof(struct shmem_region,
6390 dev_info.port_hw_config[port].sfp_ctrl)) &
6391 PORT_HW_CFG_TX_LASER_MASK;
6392 DP(NETIF_MSG_LINK, "Setting transmitter tx_en=%x for port %x "
6393 "mode = %x\n", tx_en, port, tx_en_mode);
6394 switch (tx_en_mode) {
6395 case PORT_HW_CFG_TX_LASER_MDIO:
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006396
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00006397 bnx2x_cl45_read(bp, phy,
6398 MDIO_PMA_DEVAD,
6399 MDIO_PMA_REG_PHY_IDENTIFIER,
6400 &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006401
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00006402 if (tx_en)
6403 val &= ~(1<<15);
6404 else
6405 val |= (1<<15);
6406
6407 bnx2x_cl45_write(bp, phy,
6408 MDIO_PMA_DEVAD,
6409 MDIO_PMA_REG_PHY_IDENTIFIER,
6410 val);
6411 break;
6412 case PORT_HW_CFG_TX_LASER_GPIO0:
6413 case PORT_HW_CFG_TX_LASER_GPIO1:
6414 case PORT_HW_CFG_TX_LASER_GPIO2:
6415 case PORT_HW_CFG_TX_LASER_GPIO3:
6416 {
6417 u16 gpio_pin;
6418 u8 gpio_port, gpio_mode;
6419 if (tx_en)
6420 gpio_mode = MISC_REGISTERS_GPIO_OUTPUT_HIGH;
6421 else
6422 gpio_mode = MISC_REGISTERS_GPIO_OUTPUT_LOW;
6423
6424 gpio_pin = tx_en_mode - PORT_HW_CFG_TX_LASER_GPIO0;
6425 gpio_port = bnx2x_get_gpio_port(params);
6426 bnx2x_set_gpio(bp, gpio_pin, gpio_mode, gpio_port);
6427 break;
6428 }
6429 default:
6430 DP(NETIF_MSG_LINK, "Invalid TX_LASER_MDIO 0x%x\n", tx_en_mode);
6431 break;
6432 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006433}
6434
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006435static void bnx2x_sfp_set_transmitter(struct link_params *params,
6436 struct bnx2x_phy *phy,
6437 u8 tx_en)
6438{
6439 struct bnx2x *bp = params->bp;
6440 DP(NETIF_MSG_LINK, "Setting SFP+ transmitter to %d\n", tx_en);
6441 if (CHIP_IS_E3(bp))
6442 bnx2x_sfp_e3_set_transmitter(params, phy, tx_en);
6443 else
6444 bnx2x_sfp_e1e2_set_transmitter(params, phy, tx_en);
6445}
6446
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006447static int bnx2x_8726_read_sfp_module_eeprom(struct bnx2x_phy *phy,
6448 struct link_params *params,
6449 u16 addr, u8 byte_cnt, u8 *o_buf)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006450{
6451 struct bnx2x *bp = params->bp;
6452 u16 val = 0;
6453 u16 i;
6454 if (byte_cnt > 16) {
6455 DP(NETIF_MSG_LINK, "Reading from eeprom is"
6456 " is limited to 0xf\n");
6457 return -EINVAL;
6458 }
6459 /* Set the read command byte count */
6460 bnx2x_cl45_write(bp, phy,
6461 MDIO_PMA_DEVAD, MDIO_PMA_REG_SFP_TWO_WIRE_BYTE_CNT,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006462 (byte_cnt | 0xa000));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006463
6464 /* Set the read command address */
6465 bnx2x_cl45_write(bp, phy,
6466 MDIO_PMA_DEVAD, MDIO_PMA_REG_SFP_TWO_WIRE_MEM_ADDR,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006467 addr);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006468
6469 /* Activate read command */
6470 bnx2x_cl45_write(bp, phy,
6471 MDIO_PMA_DEVAD, MDIO_PMA_REG_SFP_TWO_WIRE_CTRL,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006472 0x2c0f);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006473
6474 /* Wait up to 500us for command complete status */
6475 for (i = 0; i < 100; i++) {
6476 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006477 MDIO_PMA_DEVAD,
6478 MDIO_PMA_REG_SFP_TWO_WIRE_CTRL, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006479 if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) ==
6480 MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_COMPLETE)
6481 break;
6482 udelay(5);
6483 }
6484
6485 if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) !=
6486 MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_COMPLETE) {
6487 DP(NETIF_MSG_LINK,
6488 "Got bad status 0x%x when reading from SFP+ EEPROM\n",
6489 (val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK));
6490 return -EINVAL;
6491 }
6492
6493 /* Read the buffer */
6494 for (i = 0; i < byte_cnt; i++) {
6495 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006496 MDIO_PMA_DEVAD,
6497 MDIO_PMA_REG_8726_TWO_WIRE_DATA_BUF + i, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006498 o_buf[i] = (u8)(val & MDIO_PMA_REG_8726_TWO_WIRE_DATA_MASK);
6499 }
6500
6501 for (i = 0; i < 100; i++) {
6502 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006503 MDIO_PMA_DEVAD,
6504 MDIO_PMA_REG_SFP_TWO_WIRE_CTRL, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006505 if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) ==
6506 MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_IDLE)
Joe Perches6f38ad92010-11-14 17:04:31 +00006507 return 0;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006508 msleep(1);
6509 }
6510 return -EINVAL;
6511}
6512
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006513static int bnx2x_warpcore_read_sfp_module_eeprom(struct bnx2x_phy *phy,
6514 struct link_params *params,
6515 u16 addr, u8 byte_cnt,
6516 u8 *o_buf)
6517{
6518 int rc = 0;
6519 u8 i, j = 0, cnt = 0;
6520 u32 data_array[4];
6521 u16 addr32;
6522 struct bnx2x *bp = params->bp;
6523 /*DP(NETIF_MSG_LINK, "bnx2x_direct_read_sfp_module_eeprom:"
6524 " addr %d, cnt %d\n",
6525 addr, byte_cnt);*/
6526 if (byte_cnt > 16) {
6527 DP(NETIF_MSG_LINK, "Reading from eeprom is"
6528 " is limited to 16 bytes\n");
6529 return -EINVAL;
6530 }
6531
6532 /* 4 byte aligned address */
6533 addr32 = addr & (~0x3);
6534 do {
6535 rc = bnx2x_bsc_read(params, phy, 0xa0, addr32, 0, byte_cnt,
6536 data_array);
6537 } while ((rc != 0) && (++cnt < I2C_WA_RETRY_CNT));
6538
6539 if (rc == 0) {
6540 for (i = (addr - addr32); i < byte_cnt + (addr - addr32); i++) {
6541 o_buf[j] = *((u8 *)data_array + i);
6542 j++;
6543 }
6544 }
6545
6546 return rc;
6547}
6548
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006549static int bnx2x_8727_read_sfp_module_eeprom(struct bnx2x_phy *phy,
6550 struct link_params *params,
6551 u16 addr, u8 byte_cnt, u8 *o_buf)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006552{
6553 struct bnx2x *bp = params->bp;
6554 u16 val, i;
6555
6556 if (byte_cnt > 16) {
6557 DP(NETIF_MSG_LINK, "Reading from eeprom is"
6558 " is limited to 0xf\n");
6559 return -EINVAL;
6560 }
6561
6562 /* Need to read from 1.8000 to clear it */
6563 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006564 MDIO_PMA_DEVAD,
6565 MDIO_PMA_REG_SFP_TWO_WIRE_CTRL,
6566 &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006567
6568 /* Set the read command byte count */
6569 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006570 MDIO_PMA_DEVAD,
6571 MDIO_PMA_REG_SFP_TWO_WIRE_BYTE_CNT,
6572 ((byte_cnt < 2) ? 2 : byte_cnt));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006573
6574 /* Set the read command address */
6575 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006576 MDIO_PMA_DEVAD,
6577 MDIO_PMA_REG_SFP_TWO_WIRE_MEM_ADDR,
6578 addr);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006579 /* Set the destination address */
6580 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006581 MDIO_PMA_DEVAD,
6582 0x8004,
6583 MDIO_PMA_REG_8727_TWO_WIRE_DATA_BUF);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006584
6585 /* Activate read command */
6586 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006587 MDIO_PMA_DEVAD,
6588 MDIO_PMA_REG_SFP_TWO_WIRE_CTRL,
6589 0x8002);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006590 /*
6591 * Wait appropriate time for two-wire command to finish before
6592 * polling the status register
6593 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006594 msleep(1);
6595
6596 /* Wait up to 500us for command complete status */
6597 for (i = 0; i < 100; i++) {
6598 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006599 MDIO_PMA_DEVAD,
6600 MDIO_PMA_REG_SFP_TWO_WIRE_CTRL, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006601 if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) ==
6602 MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_COMPLETE)
6603 break;
6604 udelay(5);
6605 }
6606
6607 if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) !=
6608 MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_COMPLETE) {
6609 DP(NETIF_MSG_LINK,
6610 "Got bad status 0x%x when reading from SFP+ EEPROM\n",
6611 (val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK));
Yaniv Rosner65a001b2011-01-31 04:22:03 +00006612 return -EFAULT;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006613 }
6614
6615 /* Read the buffer */
6616 for (i = 0; i < byte_cnt; i++) {
6617 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006618 MDIO_PMA_DEVAD,
6619 MDIO_PMA_REG_8727_TWO_WIRE_DATA_BUF + i, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006620 o_buf[i] = (u8)(val & MDIO_PMA_REG_8727_TWO_WIRE_DATA_MASK);
6621 }
6622
6623 for (i = 0; i < 100; i++) {
6624 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006625 MDIO_PMA_DEVAD,
6626 MDIO_PMA_REG_SFP_TWO_WIRE_CTRL, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006627 if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) ==
6628 MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_IDLE)
Joe Perches6f38ad92010-11-14 17:04:31 +00006629 return 0;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006630 msleep(1);
6631 }
6632
6633 return -EINVAL;
6634}
6635
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006636int bnx2x_read_sfp_module_eeprom(struct bnx2x_phy *phy,
6637 struct link_params *params, u16 addr,
6638 u8 byte_cnt, u8 *o_buf)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006639{
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006640 int rc = -EINVAL;
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00006641 switch (phy->type) {
6642 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
6643 rc = bnx2x_8726_read_sfp_module_eeprom(phy, params, addr,
6644 byte_cnt, o_buf);
6645 break;
6646 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
6647 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8722:
6648 rc = bnx2x_8727_read_sfp_module_eeprom(phy, params, addr,
6649 byte_cnt, o_buf);
6650 break;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006651 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT:
6652 rc = bnx2x_warpcore_read_sfp_module_eeprom(phy, params, addr,
6653 byte_cnt, o_buf);
6654 break;
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00006655 }
6656 return rc;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006657}
6658
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006659static int bnx2x_get_edc_mode(struct bnx2x_phy *phy,
6660 struct link_params *params,
6661 u16 *edc_mode)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006662{
6663 struct bnx2x *bp = params->bp;
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00006664 u32 sync_offset = 0, phy_idx, media_types;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006665 u8 val, check_limiting_mode = 0;
6666 *edc_mode = EDC_MODE_LIMITING;
6667
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00006668 phy->media_type = ETH_PHY_UNSPECIFIED;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006669 /* First check for copper cable */
6670 if (bnx2x_read_sfp_module_eeprom(phy,
6671 params,
6672 SFP_EEPROM_CON_TYPE_ADDR,
6673 1,
6674 &val) != 0) {
6675 DP(NETIF_MSG_LINK, "Failed to read from SFP+ module EEPROM\n");
6676 return -EINVAL;
6677 }
6678
6679 switch (val) {
6680 case SFP_EEPROM_CON_TYPE_VAL_COPPER:
6681 {
6682 u8 copper_module_type;
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00006683 phy->media_type = ETH_PHY_DA_TWINAX;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006684 /*
6685 * Check if its active cable (includes SFP+ module)
6686 * of passive cable
6687 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006688 if (bnx2x_read_sfp_module_eeprom(phy,
6689 params,
6690 SFP_EEPROM_FC_TX_TECH_ADDR,
6691 1,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00006692 &copper_module_type) != 0) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006693 DP(NETIF_MSG_LINK,
6694 "Failed to read copper-cable-type"
6695 " from SFP+ EEPROM\n");
6696 return -EINVAL;
6697 }
6698
6699 if (copper_module_type &
6700 SFP_EEPROM_FC_TX_TECH_BITMASK_COPPER_ACTIVE) {
6701 DP(NETIF_MSG_LINK, "Active Copper cable detected\n");
6702 check_limiting_mode = 1;
6703 } else if (copper_module_type &
6704 SFP_EEPROM_FC_TX_TECH_BITMASK_COPPER_PASSIVE) {
6705 DP(NETIF_MSG_LINK, "Passive Copper"
6706 " cable detected\n");
6707 *edc_mode =
6708 EDC_MODE_PASSIVE_DAC;
6709 } else {
6710 DP(NETIF_MSG_LINK, "Unknown copper-cable-"
6711 "type 0x%x !!!\n", copper_module_type);
6712 return -EINVAL;
6713 }
6714 break;
6715 }
6716 case SFP_EEPROM_CON_TYPE_VAL_LC:
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00006717 phy->media_type = ETH_PHY_SFP_FIBER;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006718 DP(NETIF_MSG_LINK, "Optic module detected\n");
6719 check_limiting_mode = 1;
6720 break;
6721 default:
6722 DP(NETIF_MSG_LINK, "Unable to determine module type 0x%x !!!\n",
6723 val);
6724 return -EINVAL;
6725 }
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00006726 sync_offset = params->shmem_base +
6727 offsetof(struct shmem_region,
6728 dev_info.port_hw_config[params->port].media_type);
6729 media_types = REG_RD(bp, sync_offset);
6730 /* Update media type for non-PMF sync */
6731 for (phy_idx = INT_PHY; phy_idx < MAX_PHYS; phy_idx++) {
6732 if (&(params->phy[phy_idx]) == phy) {
6733 media_types &= ~(PORT_HW_CFG_MEDIA_TYPE_PHY0_MASK <<
6734 (PORT_HW_CFG_MEDIA_TYPE_PHY1_SHIFT * phy_idx));
6735 media_types |= ((phy->media_type &
6736 PORT_HW_CFG_MEDIA_TYPE_PHY0_MASK) <<
6737 (PORT_HW_CFG_MEDIA_TYPE_PHY1_SHIFT * phy_idx));
6738 break;
6739 }
6740 }
6741 REG_WR(bp, sync_offset, media_types);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006742 if (check_limiting_mode) {
6743 u8 options[SFP_EEPROM_OPTIONS_SIZE];
6744 if (bnx2x_read_sfp_module_eeprom(phy,
6745 params,
6746 SFP_EEPROM_OPTIONS_ADDR,
6747 SFP_EEPROM_OPTIONS_SIZE,
6748 options) != 0) {
6749 DP(NETIF_MSG_LINK, "Failed to read Option"
6750 " field from module EEPROM\n");
6751 return -EINVAL;
6752 }
6753 if ((options[0] & SFP_EEPROM_OPTIONS_LINEAR_RX_OUT_MASK))
6754 *edc_mode = EDC_MODE_LINEAR;
6755 else
6756 *edc_mode = EDC_MODE_LIMITING;
6757 }
6758 DP(NETIF_MSG_LINK, "EDC mode is set to 0x%x\n", *edc_mode);
6759 return 0;
6760}
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006761/*
6762 * This function read the relevant field from the module (SFP+), and verify it
6763 * is compliant with this board
6764 */
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006765static int bnx2x_verify_sfp_module(struct bnx2x_phy *phy,
6766 struct link_params *params)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006767{
6768 struct bnx2x *bp = params->bp;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006769 u32 val, cmd;
6770 u32 fw_resp, fw_cmd_param;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006771 char vendor_name[SFP_EEPROM_VENDOR_NAME_SIZE+1];
6772 char vendor_pn[SFP_EEPROM_PART_NO_SIZE+1];
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006773 phy->flags &= ~FLAGS_SFP_NOT_APPROVED;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006774 val = REG_RD(bp, params->shmem_base +
6775 offsetof(struct shmem_region, dev_info.
6776 port_feature_config[params->port].config));
6777 if ((val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) ==
6778 PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_NO_ENFORCEMENT) {
6779 DP(NETIF_MSG_LINK, "NOT enforcing module verification\n");
6780 return 0;
6781 }
6782
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006783 if (params->feature_config_flags &
6784 FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY) {
6785 /* Use specific phy request */
6786 cmd = DRV_MSG_CODE_VRFY_SPECIFIC_PHY_OPT_MDL;
6787 } else if (params->feature_config_flags &
6788 FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY) {
6789 /* Use first phy request only in case of non-dual media*/
6790 if (DUAL_MEDIA(params)) {
6791 DP(NETIF_MSG_LINK, "FW does not support OPT MDL "
6792 "verification\n");
6793 return -EINVAL;
6794 }
6795 cmd = DRV_MSG_CODE_VRFY_FIRST_PHY_OPT_MDL;
6796 } else {
6797 /* No support in OPT MDL detection */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006798 DP(NETIF_MSG_LINK, "FW does not support OPT MDL "
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006799 "verification\n");
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006800 return -EINVAL;
6801 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00006802
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006803 fw_cmd_param = FW_PARAM_SET(phy->addr, phy->type, phy->mdio_ctrl);
6804 fw_resp = bnx2x_fw_command(bp, cmd, fw_cmd_param);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006805 if (fw_resp == FW_MSG_CODE_VRFY_OPT_MDL_SUCCESS) {
6806 DP(NETIF_MSG_LINK, "Approved module\n");
6807 return 0;
6808 }
6809
6810 /* format the warning message */
6811 if (bnx2x_read_sfp_module_eeprom(phy,
6812 params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006813 SFP_EEPROM_VENDOR_NAME_ADDR,
6814 SFP_EEPROM_VENDOR_NAME_SIZE,
6815 (u8 *)vendor_name))
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006816 vendor_name[0] = '\0';
6817 else
6818 vendor_name[SFP_EEPROM_VENDOR_NAME_SIZE] = '\0';
6819 if (bnx2x_read_sfp_module_eeprom(phy,
6820 params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006821 SFP_EEPROM_PART_NO_ADDR,
6822 SFP_EEPROM_PART_NO_SIZE,
6823 (u8 *)vendor_pn))
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006824 vendor_pn[0] = '\0';
6825 else
6826 vendor_pn[SFP_EEPROM_PART_NO_SIZE] = '\0';
6827
Yaniv Rosner6d870c32011-01-31 04:22:20 +00006828 netdev_err(bp->dev, "Warning: Unqualified SFP+ module detected,"
6829 " Port %d from %s part number %s\n",
6830 params->port, vendor_name, vendor_pn);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006831 phy->flags |= FLAGS_SFP_NOT_APPROVED;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006832 return -EINVAL;
6833}
6834
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006835static int bnx2x_wait_for_sfp_module_initialized(struct bnx2x_phy *phy,
6836 struct link_params *params)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006837
6838{
6839 u8 val;
6840 struct bnx2x *bp = params->bp;
6841 u16 timeout;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006842 /*
6843 * Initialization time after hot-plug may take up to 300ms for
6844 * some phys type ( e.g. JDSU )
6845 */
6846
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006847 for (timeout = 0; timeout < 60; timeout++) {
6848 if (bnx2x_read_sfp_module_eeprom(phy, params, 1, 1, &val)
6849 == 0) {
6850 DP(NETIF_MSG_LINK, "SFP+ module initialization "
6851 "took %d ms\n", timeout * 5);
6852 return 0;
6853 }
6854 msleep(5);
6855 }
6856 return -EINVAL;
6857}
6858
6859static void bnx2x_8727_power_module(struct bnx2x *bp,
6860 struct bnx2x_phy *phy,
6861 u8 is_power_up) {
6862 /* Make sure GPIOs are not using for LED mode */
6863 u16 val;
6864 /*
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006865 * In the GPIO register, bit 4 is use to determine if the GPIOs are
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006866 * operating as INPUT or as OUTPUT. Bit 1 is for input, and 0 for
6867 * output
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006868 * Bits 0-1 determine the GPIOs value for OUTPUT in case bit 4 val is 0
6869 * Bits 8-9 determine the GPIOs value for INPUT in case bit 4 val is 1
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006870 * where the 1st bit is the over-current(only input), and 2nd bit is
6871 * for power( only output )
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006872 *
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006873 * In case of NOC feature is disabled and power is up, set GPIO control
6874 * as input to enable listening of over-current indication
6875 */
6876 if (phy->flags & FLAGS_NOC)
6877 return;
Yaniv Rosner27d02432011-05-31 21:27:48 +00006878 if (is_power_up)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006879 val = (1<<4);
6880 else
6881 /*
6882 * Set GPIO control to OUTPUT, and set the power bit
6883 * to according to the is_power_up
6884 */
Yaniv Rosner27d02432011-05-31 21:27:48 +00006885 val = (1<<1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006886
6887 bnx2x_cl45_write(bp, phy,
6888 MDIO_PMA_DEVAD,
6889 MDIO_PMA_REG_8727_GPIO_CTRL,
6890 val);
6891}
6892
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006893static int bnx2x_8726_set_limiting_mode(struct bnx2x *bp,
6894 struct bnx2x_phy *phy,
6895 u16 edc_mode)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006896{
6897 u16 cur_limiting_mode;
6898
6899 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006900 MDIO_PMA_DEVAD,
6901 MDIO_PMA_REG_ROM_VER2,
6902 &cur_limiting_mode);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006903 DP(NETIF_MSG_LINK, "Current Limiting mode is 0x%x\n",
6904 cur_limiting_mode);
6905
6906 if (edc_mode == EDC_MODE_LIMITING) {
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006907 DP(NETIF_MSG_LINK, "Setting LIMITING MODE\n");
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006908 bnx2x_cl45_write(bp, phy,
6909 MDIO_PMA_DEVAD,
6910 MDIO_PMA_REG_ROM_VER2,
6911 EDC_MODE_LIMITING);
6912 } else { /* LRM mode ( default )*/
6913
6914 DP(NETIF_MSG_LINK, "Setting LRM MODE\n");
6915
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006916 /*
6917 * Changing to LRM mode takes quite few seconds. So do it only
6918 * if current mode is limiting (default is LRM)
6919 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006920 if (cur_limiting_mode != EDC_MODE_LIMITING)
6921 return 0;
6922
6923 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006924 MDIO_PMA_DEVAD,
6925 MDIO_PMA_REG_LRM_MODE,
6926 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006927 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006928 MDIO_PMA_DEVAD,
6929 MDIO_PMA_REG_ROM_VER2,
6930 0x128);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006931 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006932 MDIO_PMA_DEVAD,
6933 MDIO_PMA_REG_MISC_CTRL0,
6934 0x4008);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006935 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006936 MDIO_PMA_DEVAD,
6937 MDIO_PMA_REG_LRM_MODE,
6938 0xaaaa);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006939 }
6940 return 0;
6941}
6942
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006943static int bnx2x_8727_set_limiting_mode(struct bnx2x *bp,
6944 struct bnx2x_phy *phy,
6945 u16 edc_mode)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006946{
6947 u16 phy_identifier;
6948 u16 rom_ver2_val;
6949 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006950 MDIO_PMA_DEVAD,
6951 MDIO_PMA_REG_PHY_IDENTIFIER,
6952 &phy_identifier);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006953
6954 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006955 MDIO_PMA_DEVAD,
6956 MDIO_PMA_REG_PHY_IDENTIFIER,
6957 (phy_identifier & ~(1<<9)));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006958
6959 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006960 MDIO_PMA_DEVAD,
6961 MDIO_PMA_REG_ROM_VER2,
6962 &rom_ver2_val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006963 /* Keep the MSB 8-bits, and set the LSB 8-bits with the edc_mode */
6964 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006965 MDIO_PMA_DEVAD,
6966 MDIO_PMA_REG_ROM_VER2,
6967 (rom_ver2_val & 0xff00) | (edc_mode & 0x00ff));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006968
6969 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006970 MDIO_PMA_DEVAD,
6971 MDIO_PMA_REG_PHY_IDENTIFIER,
6972 (phy_identifier | (1<<9)));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006973
6974 return 0;
6975}
6976
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006977static void bnx2x_8727_specific_func(struct bnx2x_phy *phy,
6978 struct link_params *params,
6979 u32 action)
6980{
6981 struct bnx2x *bp = params->bp;
6982
6983 switch (action) {
6984 case DISABLE_TX:
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00006985 bnx2x_sfp_set_transmitter(params, phy, 0);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006986 break;
6987 case ENABLE_TX:
6988 if (!(phy->flags & FLAGS_SFP_NOT_APPROVED))
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00006989 bnx2x_sfp_set_transmitter(params, phy, 1);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006990 break;
6991 default:
6992 DP(NETIF_MSG_LINK, "Function 0x%x not supported by 8727\n",
6993 action);
6994 return;
6995 }
6996}
6997
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006998static void bnx2x_set_e1e2_module_fault_led(struct link_params *params,
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00006999 u8 gpio_mode)
7000{
7001 struct bnx2x *bp = params->bp;
7002
7003 u32 fault_led_gpio = REG_RD(bp, params->shmem_base +
7004 offsetof(struct shmem_region,
7005 dev_info.port_hw_config[params->port].sfp_ctrl)) &
7006 PORT_HW_CFG_FAULT_MODULE_LED_MASK;
7007 switch (fault_led_gpio) {
7008 case PORT_HW_CFG_FAULT_MODULE_LED_DISABLED:
7009 return;
7010 case PORT_HW_CFG_FAULT_MODULE_LED_GPIO0:
7011 case PORT_HW_CFG_FAULT_MODULE_LED_GPIO1:
7012 case PORT_HW_CFG_FAULT_MODULE_LED_GPIO2:
7013 case PORT_HW_CFG_FAULT_MODULE_LED_GPIO3:
7014 {
7015 u8 gpio_port = bnx2x_get_gpio_port(params);
7016 u16 gpio_pin = fault_led_gpio -
7017 PORT_HW_CFG_FAULT_MODULE_LED_GPIO0;
7018 DP(NETIF_MSG_LINK, "Set fault module-detected led "
7019 "pin %x port %x mode %x\n",
7020 gpio_pin, gpio_port, gpio_mode);
7021 bnx2x_set_gpio(bp, gpio_pin, gpio_mode, gpio_port);
7022 }
7023 break;
7024 default:
7025 DP(NETIF_MSG_LINK, "Error: Invalid fault led mode 0x%x\n",
7026 fault_led_gpio);
7027 }
7028}
7029
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00007030static void bnx2x_set_e3_module_fault_led(struct link_params *params,
7031 u8 gpio_mode)
7032{
7033 u32 pin_cfg;
7034 u8 port = params->port;
7035 struct bnx2x *bp = params->bp;
7036 pin_cfg = (REG_RD(bp, params->shmem_base +
7037 offsetof(struct shmem_region,
7038 dev_info.port_hw_config[port].e3_sfp_ctrl)) &
7039 PORT_HW_CFG_E3_FAULT_MDL_LED_MASK) >>
7040 PORT_HW_CFG_E3_FAULT_MDL_LED_SHIFT;
7041 DP(NETIF_MSG_LINK, "Setting Fault LED to %d using pin cfg %d\n",
7042 gpio_mode, pin_cfg);
7043 bnx2x_set_cfg_pin(bp, pin_cfg, gpio_mode);
7044}
7045
7046static void bnx2x_set_sfp_module_fault_led(struct link_params *params,
7047 u8 gpio_mode)
7048{
7049 struct bnx2x *bp = params->bp;
7050 DP(NETIF_MSG_LINK, "Setting SFP+ module fault LED to %d\n", gpio_mode);
7051 if (CHIP_IS_E3(bp)) {
7052 /*
7053 * Low ==> if SFP+ module is supported otherwise
7054 * High ==> if SFP+ module is not on the approved vendor list
7055 */
7056 bnx2x_set_e3_module_fault_led(params, gpio_mode);
7057 } else
7058 bnx2x_set_e1e2_module_fault_led(params, gpio_mode);
7059}
7060
7061static void bnx2x_warpcore_power_module(struct link_params *params,
7062 struct bnx2x_phy *phy,
7063 u8 power)
7064{
7065 u32 pin_cfg;
7066 struct bnx2x *bp = params->bp;
7067
7068 pin_cfg = (REG_RD(bp, params->shmem_base +
7069 offsetof(struct shmem_region,
7070 dev_info.port_hw_config[params->port].e3_sfp_ctrl)) &
7071 PORT_HW_CFG_E3_PWR_DIS_MASK) >>
7072 PORT_HW_CFG_E3_PWR_DIS_SHIFT;
7073 DP(NETIF_MSG_LINK, "Setting SFP+ module power to %d using pin cfg %d\n",
7074 power, pin_cfg);
7075 /*
7076 * Low ==> corresponding SFP+ module is powered
7077 * high ==> the SFP+ module is powered down
7078 */
7079 bnx2x_set_cfg_pin(bp, pin_cfg, power ^ 1);
7080}
7081
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00007082static void bnx2x_power_sfp_module(struct link_params *params,
7083 struct bnx2x_phy *phy,
7084 u8 power)
7085{
7086 struct bnx2x *bp = params->bp;
7087 DP(NETIF_MSG_LINK, "Setting SFP+ power to %x\n", power);
7088
7089 switch (phy->type) {
7090 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
7091 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8722:
7092 bnx2x_8727_power_module(params->bp, phy, power);
7093 break;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00007094 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT:
7095 bnx2x_warpcore_power_module(params, phy, power);
7096 break;
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00007097 default:
7098 break;
7099 }
7100}
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00007101static void bnx2x_warpcore_set_limiting_mode(struct link_params *params,
7102 struct bnx2x_phy *phy,
7103 u16 edc_mode)
7104{
7105 u16 val = 0;
7106 u16 mode = MDIO_WC_REG_UC_INFO_B1_FIRMWARE_MODE_DEFAULT;
7107 struct bnx2x *bp = params->bp;
7108
7109 u8 lane = bnx2x_get_warpcore_lane(phy, params);
7110 /* This is a global register which controls all lanes */
7111 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
7112 MDIO_WC_REG_UC_INFO_B1_FIRMWARE_MODE, &val);
7113 val &= ~(0xf << (lane << 2));
7114
7115 switch (edc_mode) {
7116 case EDC_MODE_LINEAR:
7117 case EDC_MODE_LIMITING:
7118 mode = MDIO_WC_REG_UC_INFO_B1_FIRMWARE_MODE_DEFAULT;
7119 break;
7120 case EDC_MODE_PASSIVE_DAC:
7121 mode = MDIO_WC_REG_UC_INFO_B1_FIRMWARE_MODE_SFP_DAC;
7122 break;
7123 default:
7124 break;
7125 }
7126
7127 val |= (mode << (lane << 2));
7128 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
7129 MDIO_WC_REG_UC_INFO_B1_FIRMWARE_MODE, val);
7130 /* A must read */
7131 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
7132 MDIO_WC_REG_UC_INFO_B1_FIRMWARE_MODE, &val);
7133
7134
7135}
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00007136
7137static void bnx2x_set_limiting_mode(struct link_params *params,
7138 struct bnx2x_phy *phy,
7139 u16 edc_mode)
7140{
7141 switch (phy->type) {
7142 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
7143 bnx2x_8726_set_limiting_mode(params->bp, phy, edc_mode);
7144 break;
7145 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
7146 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8722:
7147 bnx2x_8727_set_limiting_mode(params->bp, phy, edc_mode);
7148 break;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00007149 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT:
7150 bnx2x_warpcore_set_limiting_mode(params, phy, edc_mode);
7151 break;
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00007152 }
7153}
7154
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00007155int bnx2x_sfp_module_detection(struct bnx2x_phy *phy,
7156 struct link_params *params)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007157{
7158 struct bnx2x *bp = params->bp;
7159 u16 edc_mode;
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00007160 int rc = 0;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007161
7162 u32 val = REG_RD(bp, params->shmem_base +
7163 offsetof(struct shmem_region, dev_info.
7164 port_feature_config[params->port].config));
7165
7166 DP(NETIF_MSG_LINK, "SFP+ module plugged in/out detected on port %d\n",
7167 params->port);
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00007168 /* Power up module */
7169 bnx2x_power_sfp_module(params, phy, 1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007170 if (bnx2x_get_edc_mode(phy, params, &edc_mode) != 0) {
7171 DP(NETIF_MSG_LINK, "Failed to get valid module type\n");
7172 return -EINVAL;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007173 } else if (bnx2x_verify_sfp_module(phy, params) != 0) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007174 /* check SFP+ module compatibility */
7175 DP(NETIF_MSG_LINK, "Module verification failed!!\n");
7176 rc = -EINVAL;
7177 /* Turn on fault module-detected led */
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00007178 bnx2x_set_sfp_module_fault_led(params,
7179 MISC_REGISTERS_GPIO_HIGH);
7180
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00007181 /* Check if need to power down the SFP+ module */
7182 if ((val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) ==
7183 PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_POWER_DOWN) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007184 DP(NETIF_MSG_LINK, "Shutdown SFP+ module!!\n");
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00007185 bnx2x_power_sfp_module(params, phy, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007186 return rc;
7187 }
7188 } else {
7189 /* Turn off fault module-detected led */
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00007190 bnx2x_set_sfp_module_fault_led(params, MISC_REGISTERS_GPIO_LOW);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007191 }
7192
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007193 /*
7194 * Check and set limiting mode / LRM mode on 8726. On 8727 it
7195 * is done automatically
7196 */
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00007197 bnx2x_set_limiting_mode(params, phy, edc_mode);
7198
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007199 /*
7200 * Enable transmit for this module if the module is approved, or
7201 * if unapproved modules should also enable the Tx laser
7202 */
7203 if (rc == 0 ||
7204 (val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) !=
7205 PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_DISABLE_TX_LASER)
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00007206 bnx2x_sfp_set_transmitter(params, phy, 1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007207 else
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00007208 bnx2x_sfp_set_transmitter(params, phy, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007209
7210 return rc;
7211}
7212
7213void bnx2x_handle_module_detect_int(struct link_params *params)
7214{
7215 struct bnx2x *bp = params->bp;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00007216 struct bnx2x_phy *phy;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007217 u32 gpio_val;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00007218 u8 gpio_num, gpio_port;
7219 if (CHIP_IS_E3(bp))
7220 phy = &params->phy[INT_PHY];
7221 else
7222 phy = &params->phy[EXT_PHY1];
7223
7224 if (bnx2x_get_mod_abs_int_cfg(bp, params->chip_id, params->shmem_base,
7225 params->port, &gpio_num, &gpio_port) ==
7226 -EINVAL) {
7227 DP(NETIF_MSG_LINK, "Failed to get MOD_ABS interrupt config\n");
7228 return;
7229 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007230
7231 /* Set valid module led off */
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00007232 bnx2x_set_sfp_module_fault_led(params, MISC_REGISTERS_GPIO_HIGH);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007233
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007234 /* Get current gpio val reflecting module plugged in / out*/
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00007235 gpio_val = bnx2x_get_gpio(bp, gpio_num, gpio_port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007236
7237 /* Call the handling function in case module is detected */
7238 if (gpio_val == 0) {
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00007239 bnx2x_power_sfp_module(params, phy, 1);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00007240 bnx2x_set_gpio_int(bp, gpio_num,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007241 MISC_REGISTERS_GPIO_INT_OUTPUT_CLR,
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00007242 gpio_port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007243 if (bnx2x_wait_for_sfp_module_initialized(phy, params) == 0)
7244 bnx2x_sfp_module_detection(phy, params);
7245 else
7246 DP(NETIF_MSG_LINK, "SFP+ module is not initialized\n");
7247 } else {
7248 u32 val = REG_RD(bp, params->shmem_base +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007249 offsetof(struct shmem_region, dev_info.
7250 port_feature_config[params->port].
7251 config));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007252
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00007253 bnx2x_set_gpio_int(bp, gpio_num,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007254 MISC_REGISTERS_GPIO_INT_OUTPUT_SET,
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00007255 gpio_port);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007256 /*
7257 * Module was plugged out.
7258 * Disable transmit for this module
7259 */
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00007260 phy->media_type = ETH_PHY_NOT_PRESENT;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007261 if ((val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) ==
7262 PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_DISABLE_TX_LASER)
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00007263 bnx2x_sfp_set_transmitter(params, phy, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007264 }
7265}
7266
7267/******************************************************************/
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00007268/* Used by 8706 and 8727 */
7269/******************************************************************/
7270static void bnx2x_sfp_mask_fault(struct bnx2x *bp,
7271 struct bnx2x_phy *phy,
7272 u16 alarm_status_offset,
7273 u16 alarm_ctrl_offset)
7274{
7275 u16 alarm_status, val;
7276 bnx2x_cl45_read(bp, phy,
7277 MDIO_PMA_DEVAD, alarm_status_offset,
7278 &alarm_status);
7279 bnx2x_cl45_read(bp, phy,
7280 MDIO_PMA_DEVAD, alarm_status_offset,
7281 &alarm_status);
7282 /* Mask or enable the fault event. */
7283 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD, alarm_ctrl_offset, &val);
7284 if (alarm_status & (1<<0))
7285 val &= ~(1<<0);
7286 else
7287 val |= (1<<0);
7288 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, alarm_ctrl_offset, val);
7289}
7290/******************************************************************/
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007291/* common BCM8706/BCM8726 PHY SECTION */
7292/******************************************************************/
7293static u8 bnx2x_8706_8726_read_status(struct bnx2x_phy *phy,
7294 struct link_params *params,
7295 struct link_vars *vars)
7296{
7297 u8 link_up = 0;
7298 u16 val1, val2, rx_sd, pcs_status;
7299 struct bnx2x *bp = params->bp;
7300 DP(NETIF_MSG_LINK, "XGXS 8706/8726\n");
7301 /* Clear RX Alarm*/
7302 bnx2x_cl45_read(bp, phy,
7303 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_ALARM, &val2);
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00007304
7305 bnx2x_sfp_mask_fault(bp, phy, MDIO_PMA_REG_TX_ALARM,
7306 MDIO_PMA_REG_TX_ALARM_CTRL);
7307
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007308 /* clear LASI indication*/
7309 bnx2x_cl45_read(bp, phy,
7310 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_STATUS, &val1);
7311 bnx2x_cl45_read(bp, phy,
7312 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_STATUS, &val2);
7313 DP(NETIF_MSG_LINK, "8706/8726 LASI status 0x%x--> 0x%x\n", val1, val2);
7314
7315 bnx2x_cl45_read(bp, phy,
7316 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_SD, &rx_sd);
7317 bnx2x_cl45_read(bp, phy,
7318 MDIO_PCS_DEVAD, MDIO_PCS_REG_STATUS, &pcs_status);
7319 bnx2x_cl45_read(bp, phy,
7320 MDIO_AN_DEVAD, MDIO_AN_REG_LINK_STATUS, &val2);
7321 bnx2x_cl45_read(bp, phy,
7322 MDIO_AN_DEVAD, MDIO_AN_REG_LINK_STATUS, &val2);
7323
7324 DP(NETIF_MSG_LINK, "8706/8726 rx_sd 0x%x pcs_status 0x%x 1Gbps"
7325 " link_status 0x%x\n", rx_sd, pcs_status, val2);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007326 /*
7327 * link is up if both bit 0 of pmd_rx_sd and bit 0 of pcs_status
7328 * are set, or if the autoneg bit 1 is set
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007329 */
7330 link_up = ((rx_sd & pcs_status & 0x1) || (val2 & (1<<1)));
7331 if (link_up) {
7332 if (val2 & (1<<1))
7333 vars->line_speed = SPEED_1000;
7334 else
7335 vars->line_speed = SPEED_10000;
7336 bnx2x_ext_phy_resolve_fc(phy, params, vars);
Yaniv Rosner791f18c2011-01-18 04:33:42 +00007337 vars->duplex = DUPLEX_FULL;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007338 }
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00007339
7340 /* Capture 10G link fault. Read twice to clear stale value. */
7341 if (vars->line_speed == SPEED_10000) {
7342 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
7343 MDIO_PMA_REG_TX_ALARM, &val1);
7344 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
7345 MDIO_PMA_REG_TX_ALARM, &val1);
7346 if (val1 & (1<<0))
7347 vars->fault_detected = 1;
7348 }
7349
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007350 return link_up;
7351}
7352
7353/******************************************************************/
7354/* BCM8706 PHY SECTION */
7355/******************************************************************/
7356static u8 bnx2x_8706_config_init(struct bnx2x_phy *phy,
7357 struct link_params *params,
7358 struct link_vars *vars)
7359{
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00007360 u32 tx_en_mode;
7361 u16 cnt, val, tmp1;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007362 struct bnx2x *bp = params->bp;
7363 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007364 MISC_REGISTERS_GPIO_OUTPUT_HIGH, params->port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007365 /* HW reset */
7366 bnx2x_ext_phy_hw_reset(bp, params->port);
7367 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0xa040);
Yaniv Rosner6d870c32011-01-31 04:22:20 +00007368 bnx2x_wait_reset_complete(bp, phy, params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007369
7370 /* Wait until fw is loaded */
7371 for (cnt = 0; cnt < 100; cnt++) {
7372 bnx2x_cl45_read(bp, phy,
7373 MDIO_PMA_DEVAD, MDIO_PMA_REG_ROM_VER1, &val);
7374 if (val)
7375 break;
7376 msleep(10);
7377 }
7378 DP(NETIF_MSG_LINK, "XGXS 8706 is initialized after %d ms\n", cnt);
7379 if ((params->feature_config_flags &
7380 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED)) {
7381 u8 i;
7382 u16 reg;
7383 for (i = 0; i < 4; i++) {
7384 reg = MDIO_XS_8706_REG_BANK_RX0 +
7385 i*(MDIO_XS_8706_REG_BANK_RX1 -
7386 MDIO_XS_8706_REG_BANK_RX0);
7387 bnx2x_cl45_read(bp, phy, MDIO_XS_DEVAD, reg, &val);
7388 /* Clear first 3 bits of the control */
7389 val &= ~0x7;
7390 /* Set control bits according to configuration */
7391 val |= (phy->rx_preemphasis[i] & 0x7);
7392 DP(NETIF_MSG_LINK, "Setting RX Equalizer to BCM8706"
7393 " reg 0x%x <-- val 0x%x\n", reg, val);
7394 bnx2x_cl45_write(bp, phy, MDIO_XS_DEVAD, reg, val);
7395 }
7396 }
7397 /* Force speed */
7398 if (phy->req_line_speed == SPEED_10000) {
7399 DP(NETIF_MSG_LINK, "XGXS 8706 force 10Gbps\n");
7400
7401 bnx2x_cl45_write(bp, phy,
7402 MDIO_PMA_DEVAD,
7403 MDIO_PMA_REG_DIGITAL_CTRL, 0x400);
7404 bnx2x_cl45_write(bp, phy,
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00007405 MDIO_PMA_DEVAD, MDIO_PMA_REG_TX_ALARM_CTRL,
7406 0);
7407 /* Arm LASI for link and Tx fault. */
7408 bnx2x_cl45_write(bp, phy,
7409 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_CTRL, 3);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007410 } else {
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007411 /* Force 1Gbps using autoneg with 1G advertisement */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007412
7413 /* Allow CL37 through CL73 */
7414 DP(NETIF_MSG_LINK, "XGXS 8706 AutoNeg\n");
7415 bnx2x_cl45_write(bp, phy,
7416 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_CL73, 0x040c);
7417
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007418 /* Enable Full-Duplex advertisement on CL37 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007419 bnx2x_cl45_write(bp, phy,
7420 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LP, 0x0020);
7421 /* Enable CL37 AN */
7422 bnx2x_cl45_write(bp, phy,
7423 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_AN, 0x1000);
7424 /* 1G support */
7425 bnx2x_cl45_write(bp, phy,
7426 MDIO_AN_DEVAD, MDIO_AN_REG_ADV, (1<<5));
7427
7428 /* Enable clause 73 AN */
7429 bnx2x_cl45_write(bp, phy,
7430 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x1200);
7431 bnx2x_cl45_write(bp, phy,
7432 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_ALARM_CTRL,
7433 0x0400);
7434 bnx2x_cl45_write(bp, phy,
7435 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_CTRL,
7436 0x0004);
7437 }
7438 bnx2x_save_bcm_spirom_ver(bp, phy, params->port);
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00007439
7440 /*
7441 * If TX Laser is controlled by GPIO_0, do not let PHY go into low
7442 * power mode, if TX Laser is disabled
7443 */
7444
7445 tx_en_mode = REG_RD(bp, params->shmem_base +
7446 offsetof(struct shmem_region,
7447 dev_info.port_hw_config[params->port].sfp_ctrl))
7448 & PORT_HW_CFG_TX_LASER_MASK;
7449
7450 if (tx_en_mode == PORT_HW_CFG_TX_LASER_GPIO0) {
7451 DP(NETIF_MSG_LINK, "Enabling TXONOFF_PWRDN_DIS\n");
7452 bnx2x_cl45_read(bp, phy,
7453 MDIO_PMA_DEVAD, MDIO_PMA_REG_DIGITAL_CTRL, &tmp1);
7454 tmp1 |= 0x1;
7455 bnx2x_cl45_write(bp, phy,
7456 MDIO_PMA_DEVAD, MDIO_PMA_REG_DIGITAL_CTRL, tmp1);
7457 }
7458
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007459 return 0;
7460}
7461
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00007462static int bnx2x_8706_read_status(struct bnx2x_phy *phy,
7463 struct link_params *params,
7464 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007465{
7466 return bnx2x_8706_8726_read_status(phy, params, vars);
7467}
7468
7469/******************************************************************/
7470/* BCM8726 PHY SECTION */
7471/******************************************************************/
7472static void bnx2x_8726_config_loopback(struct bnx2x_phy *phy,
7473 struct link_params *params)
7474{
7475 struct bnx2x *bp = params->bp;
7476 DP(NETIF_MSG_LINK, "PMA/PMD ext_phy_loopback: 8726\n");
7477 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x0001);
7478}
7479
7480static void bnx2x_8726_external_rom_boot(struct bnx2x_phy *phy,
7481 struct link_params *params)
7482{
7483 struct bnx2x *bp = params->bp;
7484 /* Need to wait 100ms after reset */
7485 msleep(100);
7486
7487 /* Micro controller re-boot */
7488 bnx2x_cl45_write(bp, phy,
7489 MDIO_PMA_DEVAD, MDIO_PMA_REG_GEN_CTRL, 0x018B);
7490
7491 /* Set soft reset */
7492 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007493 MDIO_PMA_DEVAD,
7494 MDIO_PMA_REG_GEN_CTRL,
7495 MDIO_PMA_REG_GEN_CTRL_ROM_MICRO_RESET);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007496
7497 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007498 MDIO_PMA_DEVAD,
7499 MDIO_PMA_REG_MISC_CTRL1, 0x0001);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007500
7501 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007502 MDIO_PMA_DEVAD,
7503 MDIO_PMA_REG_GEN_CTRL,
7504 MDIO_PMA_REG_GEN_CTRL_ROM_RESET_INTERNAL_MP);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007505
7506 /* wait for 150ms for microcode load */
7507 msleep(150);
7508
7509 /* Disable serial boot control, tristates pins SS_N, SCK, MOSI, MISO */
7510 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007511 MDIO_PMA_DEVAD,
7512 MDIO_PMA_REG_MISC_CTRL1, 0x0000);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007513
7514 msleep(200);
7515 bnx2x_save_bcm_spirom_ver(bp, phy, params->port);
7516}
7517
7518static u8 bnx2x_8726_read_status(struct bnx2x_phy *phy,
7519 struct link_params *params,
7520 struct link_vars *vars)
7521{
7522 struct bnx2x *bp = params->bp;
7523 u16 val1;
7524 u8 link_up = bnx2x_8706_8726_read_status(phy, params, vars);
7525 if (link_up) {
7526 bnx2x_cl45_read(bp, phy,
7527 MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER,
7528 &val1);
7529 if (val1 & (1<<15)) {
7530 DP(NETIF_MSG_LINK, "Tx is disabled\n");
7531 link_up = 0;
7532 vars->line_speed = 0;
7533 }
7534 }
7535 return link_up;
7536}
7537
7538
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00007539static int bnx2x_8726_config_init(struct bnx2x_phy *phy,
7540 struct link_params *params,
7541 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007542{
7543 struct bnx2x *bp = params->bp;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007544 DP(NETIF_MSG_LINK, "Initializing BCM8726\n");
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007545
7546 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 1<<15);
Yaniv Rosner6d870c32011-01-31 04:22:20 +00007547 bnx2x_wait_reset_complete(bp, phy, params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007548
7549 bnx2x_8726_external_rom_boot(phy, params);
7550
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007551 /*
7552 * Need to call module detected on initialization since the module
7553 * detection triggered by actual module insertion might occur before
7554 * driver is loaded, and when driver is loaded, it reset all
7555 * registers, including the transmitter
7556 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007557 bnx2x_sfp_module_detection(phy, params);
7558
7559 if (phy->req_line_speed == SPEED_1000) {
7560 DP(NETIF_MSG_LINK, "Setting 1G force\n");
7561 bnx2x_cl45_write(bp, phy,
7562 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x40);
7563 bnx2x_cl45_write(bp, phy,
7564 MDIO_PMA_DEVAD, MDIO_PMA_REG_10G_CTRL2, 0xD);
7565 bnx2x_cl45_write(bp, phy,
7566 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_CTRL, 0x5);
7567 bnx2x_cl45_write(bp, phy,
7568 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_ALARM_CTRL,
7569 0x400);
7570 } else if ((phy->req_line_speed == SPEED_AUTO_NEG) &&
7571 (phy->speed_cap_mask &
7572 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G) &&
7573 ((phy->speed_cap_mask &
7574 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G) !=
7575 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) {
7576 DP(NETIF_MSG_LINK, "Setting 1G clause37\n");
7577 /* Set Flow control */
7578 bnx2x_ext_phy_set_pause(params, phy, vars);
7579 bnx2x_cl45_write(bp, phy,
7580 MDIO_AN_DEVAD, MDIO_AN_REG_ADV, 0x20);
7581 bnx2x_cl45_write(bp, phy,
7582 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_CL73, 0x040c);
7583 bnx2x_cl45_write(bp, phy,
7584 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LD, 0x0020);
7585 bnx2x_cl45_write(bp, phy,
7586 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_AN, 0x1000);
7587 bnx2x_cl45_write(bp, phy,
7588 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x1200);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007589 /*
7590 * Enable RX-ALARM control to receive interrupt for 1G speed
7591 * change
7592 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007593 bnx2x_cl45_write(bp, phy,
7594 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_CTRL, 0x4);
7595 bnx2x_cl45_write(bp, phy,
7596 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_ALARM_CTRL,
7597 0x400);
7598
7599 } else { /* Default 10G. Set only LASI control */
7600 bnx2x_cl45_write(bp, phy,
7601 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_CTRL, 1);
7602 }
7603
7604 /* Set TX PreEmphasis if needed */
7605 if ((params->feature_config_flags &
7606 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED)) {
7607 DP(NETIF_MSG_LINK, "Setting TX_CTRL1 0x%x,"
7608 "TX_CTRL2 0x%x\n",
7609 phy->tx_preemphasis[0],
7610 phy->tx_preemphasis[1]);
7611 bnx2x_cl45_write(bp, phy,
7612 MDIO_PMA_DEVAD,
7613 MDIO_PMA_REG_8726_TX_CTRL1,
7614 phy->tx_preemphasis[0]);
7615
7616 bnx2x_cl45_write(bp, phy,
7617 MDIO_PMA_DEVAD,
7618 MDIO_PMA_REG_8726_TX_CTRL2,
7619 phy->tx_preemphasis[1]);
7620 }
7621
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007622 return 0;
7623
7624}
7625
7626static void bnx2x_8726_link_reset(struct bnx2x_phy *phy,
7627 struct link_params *params)
7628{
7629 struct bnx2x *bp = params->bp;
7630 DP(NETIF_MSG_LINK, "bnx2x_8726_link_reset port %d\n", params->port);
7631 /* Set serial boot control for external load */
7632 bnx2x_cl45_write(bp, phy,
7633 MDIO_PMA_DEVAD,
7634 MDIO_PMA_REG_GEN_CTRL, 0x0001);
7635}
7636
7637/******************************************************************/
7638/* BCM8727 PHY SECTION */
7639/******************************************************************/
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00007640
7641static void bnx2x_8727_set_link_led(struct bnx2x_phy *phy,
7642 struct link_params *params, u8 mode)
7643{
7644 struct bnx2x *bp = params->bp;
7645 u16 led_mode_bitmask = 0;
7646 u16 gpio_pins_bitmask = 0;
7647 u16 val;
7648 /* Only NOC flavor requires to set the LED specifically */
7649 if (!(phy->flags & FLAGS_NOC))
7650 return;
7651 switch (mode) {
7652 case LED_MODE_FRONT_PANEL_OFF:
7653 case LED_MODE_OFF:
7654 led_mode_bitmask = 0;
7655 gpio_pins_bitmask = 0x03;
7656 break;
7657 case LED_MODE_ON:
7658 led_mode_bitmask = 0;
7659 gpio_pins_bitmask = 0x02;
7660 break;
7661 case LED_MODE_OPER:
7662 led_mode_bitmask = 0x60;
7663 gpio_pins_bitmask = 0x11;
7664 break;
7665 }
7666 bnx2x_cl45_read(bp, phy,
7667 MDIO_PMA_DEVAD,
7668 MDIO_PMA_REG_8727_PCS_OPT_CTRL,
7669 &val);
7670 val &= 0xff8f;
7671 val |= led_mode_bitmask;
7672 bnx2x_cl45_write(bp, phy,
7673 MDIO_PMA_DEVAD,
7674 MDIO_PMA_REG_8727_PCS_OPT_CTRL,
7675 val);
7676 bnx2x_cl45_read(bp, phy,
7677 MDIO_PMA_DEVAD,
7678 MDIO_PMA_REG_8727_GPIO_CTRL,
7679 &val);
7680 val &= 0xffe0;
7681 val |= gpio_pins_bitmask;
7682 bnx2x_cl45_write(bp, phy,
7683 MDIO_PMA_DEVAD,
7684 MDIO_PMA_REG_8727_GPIO_CTRL,
7685 val);
7686}
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007687static void bnx2x_8727_hw_reset(struct bnx2x_phy *phy,
7688 struct link_params *params) {
7689 u32 swap_val, swap_override;
7690 u8 port;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007691 /*
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007692 * The PHY reset is controlled by GPIO 1. Fake the port number
7693 * to cancel the swap done in set_gpio()
7694 */
7695 struct bnx2x *bp = params->bp;
7696 swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
7697 swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
7698 port = (swap_val && swap_override) ^ 1;
7699 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007700 MISC_REGISTERS_GPIO_OUTPUT_LOW, port);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007701}
7702
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00007703static int bnx2x_8727_config_init(struct bnx2x_phy *phy,
7704 struct link_params *params,
7705 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007706{
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00007707 u32 tx_en_mode;
7708 u16 tmp1, val, mod_abs, tmp2;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007709 u16 rx_alarm_ctrl_val;
7710 u16 lasi_ctrl_val;
7711 struct bnx2x *bp = params->bp;
7712 /* Enable PMD link, MOD_ABS_FLT, and 1G link alarm */
7713
Yaniv Rosner6d870c32011-01-31 04:22:20 +00007714 bnx2x_wait_reset_complete(bp, phy, params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007715 rx_alarm_ctrl_val = (1<<2) | (1<<5) ;
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00007716 /* Should be 0x6 to enable XS on Tx side. */
7717 lasi_ctrl_val = 0x0006;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007718
7719 DP(NETIF_MSG_LINK, "Initializing BCM8727\n");
7720 /* enable LASI */
7721 bnx2x_cl45_write(bp, phy,
7722 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_ALARM_CTRL,
7723 rx_alarm_ctrl_val);
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00007724 bnx2x_cl45_write(bp, phy,
7725 MDIO_PMA_DEVAD, MDIO_PMA_REG_TX_ALARM_CTRL,
7726 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007727 bnx2x_cl45_write(bp, phy,
7728 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_CTRL, lasi_ctrl_val);
7729
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007730 /*
7731 * Initially configure MOD_ABS to interrupt when module is
7732 * presence( bit 8)
7733 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007734 bnx2x_cl45_read(bp, phy,
7735 MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER, &mod_abs);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007736 /*
7737 * Set EDC off by setting OPTXLOS signal input to low (bit 9).
7738 * When the EDC is off it locks onto a reference clock and avoids
7739 * becoming 'lost'
7740 */
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00007741 mod_abs &= ~(1<<8);
7742 if (!(phy->flags & FLAGS_NOC))
7743 mod_abs &= ~(1<<9);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007744 bnx2x_cl45_write(bp, phy,
7745 MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER, mod_abs);
7746
7747
7748 /* Make MOD_ABS give interrupt on change */
7749 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_PCS_OPT_CTRL,
7750 &val);
7751 val |= (1<<12);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00007752 if (phy->flags & FLAGS_NOC)
7753 val |= (3<<5);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007754
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007755 /*
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00007756 * Set 8727 GPIOs to input to allow reading from the 8727 GPIO0
7757 * status which reflect SFP+ module over-current
7758 */
7759 if (!(phy->flags & FLAGS_NOC))
7760 val &= 0xff8f; /* Reset bits 4-6 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007761 bnx2x_cl45_write(bp, phy,
7762 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_PCS_OPT_CTRL, val);
7763
7764 bnx2x_8727_power_module(bp, phy, 1);
7765
7766 bnx2x_cl45_read(bp, phy,
7767 MDIO_PMA_DEVAD, MDIO_PMA_REG_M8051_MSGOUT_REG, &tmp1);
7768
7769 bnx2x_cl45_read(bp, phy,
7770 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_ALARM, &tmp1);
7771
7772 /* Set option 1G speed */
7773 if (phy->req_line_speed == SPEED_1000) {
7774 DP(NETIF_MSG_LINK, "Setting 1G force\n");
7775 bnx2x_cl45_write(bp, phy,
7776 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x40);
7777 bnx2x_cl45_write(bp, phy,
7778 MDIO_PMA_DEVAD, MDIO_PMA_REG_10G_CTRL2, 0xD);
7779 bnx2x_cl45_read(bp, phy,
7780 MDIO_PMA_DEVAD, MDIO_PMA_REG_10G_CTRL2, &tmp1);
7781 DP(NETIF_MSG_LINK, "1.7 = 0x%x\n", tmp1);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007782 /*
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007783 * Power down the XAUI until link is up in case of dual-media
7784 * and 1G
7785 */
7786 if (DUAL_MEDIA(params)) {
7787 bnx2x_cl45_read(bp, phy,
7788 MDIO_PMA_DEVAD,
7789 MDIO_PMA_REG_8727_PCS_GP, &val);
7790 val |= (3<<10);
7791 bnx2x_cl45_write(bp, phy,
7792 MDIO_PMA_DEVAD,
7793 MDIO_PMA_REG_8727_PCS_GP, val);
7794 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007795 } else if ((phy->req_line_speed == SPEED_AUTO_NEG) &&
7796 ((phy->speed_cap_mask &
7797 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) &&
7798 ((phy->speed_cap_mask &
7799 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G) !=
7800 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) {
7801
7802 DP(NETIF_MSG_LINK, "Setting 1G clause37\n");
7803 bnx2x_cl45_write(bp, phy,
7804 MDIO_AN_DEVAD, MDIO_AN_REG_8727_MISC_CTRL, 0);
7805 bnx2x_cl45_write(bp, phy,
7806 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_AN, 0x1300);
7807 } else {
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007808 /*
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007809 * Since the 8727 has only single reset pin, need to set the 10G
7810 * registers although it is default
7811 */
7812 bnx2x_cl45_write(bp, phy,
7813 MDIO_AN_DEVAD, MDIO_AN_REG_8727_MISC_CTRL,
7814 0x0020);
7815 bnx2x_cl45_write(bp, phy,
7816 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_AN, 0x0100);
7817 bnx2x_cl45_write(bp, phy,
7818 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x2040);
7819 bnx2x_cl45_write(bp, phy,
7820 MDIO_PMA_DEVAD, MDIO_PMA_REG_10G_CTRL2,
7821 0x0008);
7822 }
7823
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007824 /*
7825 * Set 2-wire transfer rate of SFP+ module EEPROM
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007826 * to 100Khz since some DACs(direct attached cables) do
7827 * not work at 400Khz.
7828 */
7829 bnx2x_cl45_write(bp, phy,
7830 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_TWO_WIRE_SLAVE_ADDR,
7831 0xa001);
7832
7833 /* Set TX PreEmphasis if needed */
7834 if ((params->feature_config_flags &
7835 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED)) {
7836 DP(NETIF_MSG_LINK, "Setting TX_CTRL1 0x%x, TX_CTRL2 0x%x\n",
7837 phy->tx_preemphasis[0],
7838 phy->tx_preemphasis[1]);
7839 bnx2x_cl45_write(bp, phy,
7840 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_TX_CTRL1,
7841 phy->tx_preemphasis[0]);
7842
7843 bnx2x_cl45_write(bp, phy,
7844 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_TX_CTRL2,
7845 phy->tx_preemphasis[1]);
7846 }
7847
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00007848 /*
7849 * If TX Laser is controlled by GPIO_0, do not let PHY go into low
7850 * power mode, if TX Laser is disabled
7851 */
7852 tx_en_mode = REG_RD(bp, params->shmem_base +
7853 offsetof(struct shmem_region,
7854 dev_info.port_hw_config[params->port].sfp_ctrl))
7855 & PORT_HW_CFG_TX_LASER_MASK;
7856
7857 if (tx_en_mode == PORT_HW_CFG_TX_LASER_GPIO0) {
7858
7859 DP(NETIF_MSG_LINK, "Enabling TXONOFF_PWRDN_DIS\n");
7860 bnx2x_cl45_read(bp, phy,
7861 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_OPT_CFG_REG, &tmp2);
7862 tmp2 |= 0x1000;
7863 tmp2 &= 0xFFEF;
7864 bnx2x_cl45_write(bp, phy,
7865 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_OPT_CFG_REG, tmp2);
7866 }
7867
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007868 return 0;
7869}
7870
7871static void bnx2x_8727_handle_mod_abs(struct bnx2x_phy *phy,
7872 struct link_params *params)
7873{
7874 struct bnx2x *bp = params->bp;
7875 u16 mod_abs, rx_alarm_status;
7876 u32 val = REG_RD(bp, params->shmem_base +
7877 offsetof(struct shmem_region, dev_info.
7878 port_feature_config[params->port].
7879 config));
7880 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007881 MDIO_PMA_DEVAD,
7882 MDIO_PMA_REG_PHY_IDENTIFIER, &mod_abs);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007883 if (mod_abs & (1<<8)) {
7884
7885 /* Module is absent */
7886 DP(NETIF_MSG_LINK, "MOD_ABS indication "
7887 "show module is absent\n");
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00007888 phy->media_type = ETH_PHY_NOT_PRESENT;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007889 /*
7890 * 1. Set mod_abs to detect next module
7891 * presence event
7892 * 2. Set EDC off by setting OPTXLOS signal input to low
7893 * (bit 9).
7894 * When the EDC is off it locks onto a reference clock and
7895 * avoids becoming 'lost'.
7896 */
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00007897 mod_abs &= ~(1<<8);
7898 if (!(phy->flags & FLAGS_NOC))
7899 mod_abs &= ~(1<<9);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007900 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007901 MDIO_PMA_DEVAD,
7902 MDIO_PMA_REG_PHY_IDENTIFIER, mod_abs);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007903
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007904 /*
7905 * Clear RX alarm since it stays up as long as
7906 * the mod_abs wasn't changed
7907 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007908 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007909 MDIO_PMA_DEVAD,
7910 MDIO_PMA_REG_RX_ALARM, &rx_alarm_status);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007911
7912 } else {
7913 /* Module is present */
7914 DP(NETIF_MSG_LINK, "MOD_ABS indication "
7915 "show module is present\n");
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007916 /*
7917 * First disable transmitter, and if the module is ok, the
7918 * module_detection will enable it
7919 * 1. Set mod_abs to detect next module absent event ( bit 8)
7920 * 2. Restore the default polarity of the OPRXLOS signal and
7921 * this signal will then correctly indicate the presence or
7922 * absence of the Rx signal. (bit 9)
7923 */
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00007924 mod_abs |= (1<<8);
7925 if (!(phy->flags & FLAGS_NOC))
7926 mod_abs |= (1<<9);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007927 bnx2x_cl45_write(bp, phy,
7928 MDIO_PMA_DEVAD,
7929 MDIO_PMA_REG_PHY_IDENTIFIER, mod_abs);
7930
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007931 /*
7932 * Clear RX alarm since it stays up as long as the mod_abs
7933 * wasn't changed. This is need to be done before calling the
7934 * module detection, otherwise it will clear* the link update
7935 * alarm
7936 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007937 bnx2x_cl45_read(bp, phy,
7938 MDIO_PMA_DEVAD,
7939 MDIO_PMA_REG_RX_ALARM, &rx_alarm_status);
7940
7941
7942 if ((val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) ==
7943 PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_DISABLE_TX_LASER)
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00007944 bnx2x_sfp_set_transmitter(params, phy, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007945
7946 if (bnx2x_wait_for_sfp_module_initialized(phy, params) == 0)
7947 bnx2x_sfp_module_detection(phy, params);
7948 else
7949 DP(NETIF_MSG_LINK, "SFP+ module is not initialized\n");
7950 }
7951
7952 DP(NETIF_MSG_LINK, "8727 RX_ALARM_STATUS 0x%x\n",
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007953 rx_alarm_status);
7954 /* No need to check link status in case of module plugged in/out */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007955}
7956
7957static u8 bnx2x_8727_read_status(struct bnx2x_phy *phy,
7958 struct link_params *params,
7959 struct link_vars *vars)
7960
7961{
7962 struct bnx2x *bp = params->bp;
Yaniv Rosner27d02432011-05-31 21:27:48 +00007963 u8 link_up = 0, oc_port = params->port;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007964 u16 link_status = 0;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007965 u16 rx_alarm_status, lasi_ctrl, val1;
7966
7967 /* If PHY is not initialized, do not check link status */
7968 bnx2x_cl45_read(bp, phy,
7969 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_CTRL,
7970 &lasi_ctrl);
7971 if (!lasi_ctrl)
7972 return 0;
7973
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00007974 /* Check the LASI on Rx */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007975 bnx2x_cl45_read(bp, phy,
7976 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_ALARM,
7977 &rx_alarm_status);
7978 vars->line_speed = 0;
7979 DP(NETIF_MSG_LINK, "8727 RX_ALARM_STATUS 0x%x\n", rx_alarm_status);
7980
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00007981 bnx2x_sfp_mask_fault(bp, phy, MDIO_PMA_REG_TX_ALARM,
7982 MDIO_PMA_REG_TX_ALARM_CTRL);
7983
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007984 bnx2x_cl45_read(bp, phy,
7985 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_STATUS, &val1);
7986
7987 DP(NETIF_MSG_LINK, "8727 LASI status 0x%x\n", val1);
7988
7989 /* Clear MSG-OUT */
7990 bnx2x_cl45_read(bp, phy,
7991 MDIO_PMA_DEVAD, MDIO_PMA_REG_M8051_MSGOUT_REG, &val1);
7992
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007993 /*
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007994 * If a module is present and there is need to check
7995 * for over current
7996 */
7997 if (!(phy->flags & FLAGS_NOC) && !(rx_alarm_status & (1<<5))) {
7998 /* Check over-current using 8727 GPIO0 input*/
7999 bnx2x_cl45_read(bp, phy,
8000 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_GPIO_CTRL,
8001 &val1);
8002
8003 if ((val1 & (1<<8)) == 0) {
Yaniv Rosner27d02432011-05-31 21:27:48 +00008004 if (!CHIP_IS_E1x(bp))
8005 oc_port = BP_PATH(bp) + (params->port << 1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008006 DP(NETIF_MSG_LINK, "8727 Power fault has been detected"
Yaniv Rosner27d02432011-05-31 21:27:48 +00008007 " on port %d\n", oc_port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008008 netdev_err(bp->dev, "Error: Power fault on Port %d has"
8009 " been detected and the power to "
8010 "that SFP+ module has been removed"
8011 " to prevent failure of the card."
8012 " Please remove the SFP+ module and"
8013 " restart the system to clear this"
8014 " error.\n",
Yaniv Rosner27d02432011-05-31 21:27:48 +00008015 oc_port);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008016 /* Disable all RX_ALARMs except for mod_abs */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008017 bnx2x_cl45_write(bp, phy,
8018 MDIO_PMA_DEVAD,
8019 MDIO_PMA_REG_RX_ALARM_CTRL, (1<<5));
8020
8021 bnx2x_cl45_read(bp, phy,
8022 MDIO_PMA_DEVAD,
8023 MDIO_PMA_REG_PHY_IDENTIFIER, &val1);
8024 /* Wait for module_absent_event */
8025 val1 |= (1<<8);
8026 bnx2x_cl45_write(bp, phy,
8027 MDIO_PMA_DEVAD,
8028 MDIO_PMA_REG_PHY_IDENTIFIER, val1);
8029 /* Clear RX alarm */
8030 bnx2x_cl45_read(bp, phy,
8031 MDIO_PMA_DEVAD,
8032 MDIO_PMA_REG_RX_ALARM, &rx_alarm_status);
8033 return 0;
8034 }
8035 } /* Over current check */
8036
8037 /* When module absent bit is set, check module */
8038 if (rx_alarm_status & (1<<5)) {
8039 bnx2x_8727_handle_mod_abs(phy, params);
8040 /* Enable all mod_abs and link detection bits */
8041 bnx2x_cl45_write(bp, phy,
8042 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_ALARM_CTRL,
8043 ((1<<5) | (1<<2)));
8044 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008045 DP(NETIF_MSG_LINK, "Enabling 8727 TX laser if SFP is approved\n");
8046 bnx2x_8727_specific_func(phy, params, ENABLE_TX);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008047 /* If transmitter is disabled, ignore false link up indication */
8048 bnx2x_cl45_read(bp, phy,
8049 MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER, &val1);
8050 if (val1 & (1<<15)) {
8051 DP(NETIF_MSG_LINK, "Tx is disabled\n");
8052 return 0;
8053 }
8054
8055 bnx2x_cl45_read(bp, phy,
8056 MDIO_PMA_DEVAD,
8057 MDIO_PMA_REG_8073_SPEED_LINK_STATUS, &link_status);
8058
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008059 /*
8060 * Bits 0..2 --> speed detected,
8061 * Bits 13..15--> link is down
8062 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008063 if ((link_status & (1<<2)) && (!(link_status & (1<<15)))) {
8064 link_up = 1;
8065 vars->line_speed = SPEED_10000;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008066 DP(NETIF_MSG_LINK, "port %x: External link up in 10G\n",
8067 params->port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008068 } else if ((link_status & (1<<0)) && (!(link_status & (1<<13)))) {
8069 link_up = 1;
8070 vars->line_speed = SPEED_1000;
8071 DP(NETIF_MSG_LINK, "port %x: External link up in 1G\n",
8072 params->port);
8073 } else {
8074 link_up = 0;
8075 DP(NETIF_MSG_LINK, "port %x: External link is down\n",
8076 params->port);
8077 }
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00008078
8079 /* Capture 10G link fault. */
8080 if (vars->line_speed == SPEED_10000) {
8081 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
8082 MDIO_PMA_REG_TX_ALARM, &val1);
8083
8084 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
8085 MDIO_PMA_REG_TX_ALARM, &val1);
8086
8087 if (val1 & (1<<0)) {
8088 vars->fault_detected = 1;
8089 }
8090 }
8091
Yaniv Rosner791f18c2011-01-18 04:33:42 +00008092 if (link_up) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008093 bnx2x_ext_phy_resolve_fc(phy, params, vars);
Yaniv Rosner791f18c2011-01-18 04:33:42 +00008094 vars->duplex = DUPLEX_FULL;
8095 DP(NETIF_MSG_LINK, "duplex = 0x%x\n", vars->duplex);
8096 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008097
8098 if ((DUAL_MEDIA(params)) &&
8099 (phy->req_line_speed == SPEED_1000)) {
8100 bnx2x_cl45_read(bp, phy,
8101 MDIO_PMA_DEVAD,
8102 MDIO_PMA_REG_8727_PCS_GP, &val1);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008103 /*
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008104 * In case of dual-media board and 1G, power up the XAUI side,
8105 * otherwise power it down. For 10G it is done automatically
8106 */
8107 if (link_up)
8108 val1 &= ~(3<<10);
8109 else
8110 val1 |= (3<<10);
8111 bnx2x_cl45_write(bp, phy,
8112 MDIO_PMA_DEVAD,
8113 MDIO_PMA_REG_8727_PCS_GP, val1);
8114 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008115 return link_up;
8116}
8117
8118static void bnx2x_8727_link_reset(struct bnx2x_phy *phy,
8119 struct link_params *params)
8120{
8121 struct bnx2x *bp = params->bp;
8122 /* Disable Transmitter */
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008123 bnx2x_sfp_set_transmitter(params, phy, 0);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008124 /* Clear LASI */
8125 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_CTRL, 0);
8126
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008127}
8128
8129/******************************************************************/
8130/* BCM8481/BCM84823/BCM84833 PHY SECTION */
8131/******************************************************************/
8132static void bnx2x_save_848xx_spirom_version(struct bnx2x_phy *phy,
8133 struct link_params *params)
8134{
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00008135 u16 val, fw_ver1, fw_ver2, cnt;
8136 u8 port;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008137 struct bnx2x *bp = params->bp;
8138
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00008139 port = params->port;
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00008140
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008141 /* For the 32 bits registers in 848xx, access via MDIO2ARM interface.*/
8142 /* (1) set register 0xc200_0014(SPI_BRIDGE_CTRL_2) to 0x03000000 */
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00008143 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA819, 0x0014);
8144 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA81A, 0xc200);
8145 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA81B, 0x0000);
8146 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA81C, 0x0300);
8147 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA817, 0x0009);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008148
8149 for (cnt = 0; cnt < 100; cnt++) {
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00008150 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD, 0xA818, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008151 if (val & 1)
8152 break;
8153 udelay(5);
8154 }
8155 if (cnt == 100) {
8156 DP(NETIF_MSG_LINK, "Unable to read 848xx phy fw version(1)\n");
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00008157 bnx2x_save_spirom_version(bp, port, 0,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008158 phy->ver_addr);
8159 return;
8160 }
8161
8162
8163 /* 2) read register 0xc200_0000 (SPI_FW_STATUS) */
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00008164 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA819, 0x0000);
8165 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA81A, 0xc200);
8166 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA817, 0x000A);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008167 for (cnt = 0; cnt < 100; cnt++) {
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00008168 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD, 0xA818, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008169 if (val & 1)
8170 break;
8171 udelay(5);
8172 }
8173 if (cnt == 100) {
8174 DP(NETIF_MSG_LINK, "Unable to read 848xx phy fw version(2)\n");
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00008175 bnx2x_save_spirom_version(bp, port, 0,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008176 phy->ver_addr);
8177 return;
8178 }
8179
8180 /* lower 16 bits of the register SPI_FW_STATUS */
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00008181 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD, 0xA81B, &fw_ver1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008182 /* upper 16 bits of register SPI_FW_STATUS */
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00008183 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD, 0xA81C, &fw_ver2);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008184
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00008185 bnx2x_save_spirom_version(bp, port, (fw_ver2<<16) | fw_ver1,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008186 phy->ver_addr);
8187}
8188
8189static void bnx2x_848xx_set_led(struct bnx2x *bp,
8190 struct bnx2x_phy *phy)
8191{
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00008192 u16 val;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008193
8194 /* PHYC_CTL_LED_CTL */
8195 bnx2x_cl45_read(bp, phy,
8196 MDIO_PMA_DEVAD,
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00008197 MDIO_PMA_REG_8481_LINK_SIGNAL, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008198 val &= 0xFE00;
8199 val |= 0x0092;
8200
8201 bnx2x_cl45_write(bp, phy,
8202 MDIO_PMA_DEVAD,
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00008203 MDIO_PMA_REG_8481_LINK_SIGNAL, val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008204
8205 bnx2x_cl45_write(bp, phy,
8206 MDIO_PMA_DEVAD,
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00008207 MDIO_PMA_REG_8481_LED1_MASK,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008208 0x80);
8209
8210 bnx2x_cl45_write(bp, phy,
8211 MDIO_PMA_DEVAD,
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00008212 MDIO_PMA_REG_8481_LED2_MASK,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008213 0x18);
8214
Yaniv Rosnerf25b3c82011-01-18 04:33:47 +00008215 /* Select activity source by Tx and Rx, as suggested by PHY AE */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008216 bnx2x_cl45_write(bp, phy,
8217 MDIO_PMA_DEVAD,
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00008218 MDIO_PMA_REG_8481_LED3_MASK,
Yaniv Rosnerf25b3c82011-01-18 04:33:47 +00008219 0x0006);
8220
8221 /* Select the closest activity blink rate to that in 10/100/1000 */
8222 bnx2x_cl45_write(bp, phy,
8223 MDIO_PMA_DEVAD,
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00008224 MDIO_PMA_REG_8481_LED3_BLINK,
Yaniv Rosnerf25b3c82011-01-18 04:33:47 +00008225 0);
8226
8227 bnx2x_cl45_read(bp, phy,
8228 MDIO_PMA_DEVAD,
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00008229 MDIO_PMA_REG_84823_CTL_LED_CTL_1, &val);
Yaniv Rosnerf25b3c82011-01-18 04:33:47 +00008230 val |= MDIO_PMA_REG_84823_LED3_STRETCH_EN; /* stretch_en for LED3*/
8231
8232 bnx2x_cl45_write(bp, phy,
8233 MDIO_PMA_DEVAD,
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00008234 MDIO_PMA_REG_84823_CTL_LED_CTL_1, val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008235
8236 /* 'Interrupt Mask' */
8237 bnx2x_cl45_write(bp, phy,
8238 MDIO_AN_DEVAD,
8239 0xFFFB, 0xFFFD);
8240}
8241
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00008242static int bnx2x_848xx_cmn_config_init(struct bnx2x_phy *phy,
8243 struct link_params *params,
8244 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008245{
8246 struct bnx2x *bp = params->bp;
8247 u16 autoneg_val, an_1000_val, an_10_100_val;
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00008248 u16 tmp_req_line_speed;
8249
8250 tmp_req_line_speed = phy->req_line_speed;
8251 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
8252 if (phy->req_line_speed == SPEED_10000)
8253 phy->req_line_speed = SPEED_AUTO_NEG;
8254
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008255 /*
8256 * This phy uses the NIG latch mechanism since link indication
8257 * arrives through its LED4 and not via its LASI signal, so we
8258 * get steady signal instead of clear on read
8259 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008260 bnx2x_bits_en(bp, NIG_REG_LATCH_BC_0 + params->port*4,
8261 1 << NIG_LATCH_BC_ENABLE_MI_INT);
8262
8263 bnx2x_cl45_write(bp, phy,
8264 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x0000);
8265
8266 bnx2x_848xx_set_led(bp, phy);
8267
8268 /* set 1000 speed advertisement */
8269 bnx2x_cl45_read(bp, phy,
8270 MDIO_AN_DEVAD, MDIO_AN_REG_8481_1000T_CTRL,
8271 &an_1000_val);
8272
8273 bnx2x_ext_phy_set_pause(params, phy, vars);
8274 bnx2x_cl45_read(bp, phy,
8275 MDIO_AN_DEVAD,
8276 MDIO_AN_REG_8481_LEGACY_AN_ADV,
8277 &an_10_100_val);
8278 bnx2x_cl45_read(bp, phy,
8279 MDIO_AN_DEVAD, MDIO_AN_REG_8481_LEGACY_MII_CTRL,
8280 &autoneg_val);
8281 /* Disable forced speed */
8282 autoneg_val &= ~((1<<6) | (1<<8) | (1<<9) | (1<<12) | (1<<13));
8283 an_10_100_val &= ~((1<<5) | (1<<6) | (1<<7) | (1<<8));
8284
8285 if (((phy->req_line_speed == SPEED_AUTO_NEG) &&
8286 (phy->speed_cap_mask &
8287 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) ||
8288 (phy->req_line_speed == SPEED_1000)) {
8289 an_1000_val |= (1<<8);
8290 autoneg_val |= (1<<9 | 1<<12);
8291 if (phy->req_duplex == DUPLEX_FULL)
8292 an_1000_val |= (1<<9);
8293 DP(NETIF_MSG_LINK, "Advertising 1G\n");
8294 } else
8295 an_1000_val &= ~((1<<8) | (1<<9));
8296
8297 bnx2x_cl45_write(bp, phy,
8298 MDIO_AN_DEVAD, MDIO_AN_REG_8481_1000T_CTRL,
8299 an_1000_val);
8300
8301 /* set 10 speed advertisement */
8302 if (((phy->req_line_speed == SPEED_AUTO_NEG) &&
8303 (phy->speed_cap_mask &
8304 (PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL |
8305 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF)))) {
8306 an_10_100_val |= (1<<7);
8307 /* Enable autoneg and restart autoneg for legacy speeds */
8308 autoneg_val |= (1<<9 | 1<<12);
8309
8310 if (phy->req_duplex == DUPLEX_FULL)
8311 an_10_100_val |= (1<<8);
8312 DP(NETIF_MSG_LINK, "Advertising 100M\n");
8313 }
8314 /* set 10 speed advertisement */
8315 if (((phy->req_line_speed == SPEED_AUTO_NEG) &&
8316 (phy->speed_cap_mask &
8317 (PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL |
8318 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF)))) {
8319 an_10_100_val |= (1<<5);
8320 autoneg_val |= (1<<9 | 1<<12);
8321 if (phy->req_duplex == DUPLEX_FULL)
8322 an_10_100_val |= (1<<6);
8323 DP(NETIF_MSG_LINK, "Advertising 10M\n");
8324 }
8325
8326 /* Only 10/100 are allowed to work in FORCE mode */
8327 if (phy->req_line_speed == SPEED_100) {
8328 autoneg_val |= (1<<13);
8329 /* Enabled AUTO-MDIX when autoneg is disabled */
8330 bnx2x_cl45_write(bp, phy,
8331 MDIO_AN_DEVAD, MDIO_AN_REG_8481_AUX_CTRL,
8332 (1<<15 | 1<<9 | 7<<0));
8333 DP(NETIF_MSG_LINK, "Setting 100M force\n");
8334 }
8335 if (phy->req_line_speed == SPEED_10) {
8336 /* Enabled AUTO-MDIX when autoneg is disabled */
8337 bnx2x_cl45_write(bp, phy,
8338 MDIO_AN_DEVAD, MDIO_AN_REG_8481_AUX_CTRL,
8339 (1<<15 | 1<<9 | 7<<0));
8340 DP(NETIF_MSG_LINK, "Setting 10M force\n");
8341 }
8342
8343 bnx2x_cl45_write(bp, phy,
8344 MDIO_AN_DEVAD, MDIO_AN_REG_8481_LEGACY_AN_ADV,
8345 an_10_100_val);
8346
8347 if (phy->req_duplex == DUPLEX_FULL)
8348 autoneg_val |= (1<<8);
8349
8350 bnx2x_cl45_write(bp, phy,
8351 MDIO_AN_DEVAD,
8352 MDIO_AN_REG_8481_LEGACY_MII_CTRL, autoneg_val);
8353
8354 if (((phy->req_line_speed == SPEED_AUTO_NEG) &&
8355 (phy->speed_cap_mask &
8356 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) ||
8357 (phy->req_line_speed == SPEED_10000)) {
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00008358 DP(NETIF_MSG_LINK, "Advertising 10G\n");
8359 /* Restart autoneg for 10G*/
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008360
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00008361 bnx2x_cl45_write(bp, phy,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008362 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL,
8363 0x3200);
8364 } else if (phy->req_line_speed != SPEED_10 &&
8365 phy->req_line_speed != SPEED_100) {
8366 bnx2x_cl45_write(bp, phy,
8367 MDIO_AN_DEVAD,
8368 MDIO_AN_REG_8481_10GBASE_T_AN_CTRL,
8369 1);
8370 }
8371 /* Save spirom version */
8372 bnx2x_save_848xx_spirom_version(phy, params);
8373
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00008374 phy->req_line_speed = tmp_req_line_speed;
8375
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008376 return 0;
8377}
8378
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00008379static int bnx2x_8481_config_init(struct bnx2x_phy *phy,
8380 struct link_params *params,
8381 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008382{
8383 struct bnx2x *bp = params->bp;
8384 /* Restore normal power mode*/
8385 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008386 MISC_REGISTERS_GPIO_OUTPUT_HIGH, params->port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008387
8388 /* HW reset */
8389 bnx2x_ext_phy_hw_reset(bp, params->port);
Yaniv Rosner6d870c32011-01-31 04:22:20 +00008390 bnx2x_wait_reset_complete(bp, phy, params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008391
8392 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 1<<15);
8393 return bnx2x_848xx_cmn_config_init(phy, params, vars);
8394}
8395
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00008396
8397#define PHY84833_HDSHK_WAIT 300
8398static int bnx2x_84833_pair_swap_cfg(struct bnx2x_phy *phy,
8399 struct link_params *params,
8400 struct link_vars *vars)
8401{
8402 u32 idx;
8403 u16 val;
8404 u16 data = 0x01b1;
8405 struct bnx2x *bp = params->bp;
8406 /* Do pair swap */
8407
8408
8409 /* Write CMD_OPEN_OVERRIDE to STATUS reg */
8410 bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
8411 MDIO_84833_TOP_CFG_SCRATCH_REG2,
8412 PHY84833_CMD_OPEN_OVERRIDE);
8413 for (idx = 0; idx < PHY84833_HDSHK_WAIT; idx++) {
8414 bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD,
8415 MDIO_84833_TOP_CFG_SCRATCH_REG2, &val);
8416 if (val == PHY84833_CMD_OPEN_FOR_CMDS)
8417 break;
8418 msleep(1);
8419 }
8420 if (idx >= PHY84833_HDSHK_WAIT) {
8421 DP(NETIF_MSG_LINK, "Pairswap: FW not ready.\n");
8422 return -EINVAL;
8423 }
8424
8425 bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
8426 MDIO_84833_TOP_CFG_SCRATCH_REG4,
8427 data);
8428 /* Issue pair swap command */
8429 bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
8430 MDIO_84833_TOP_CFG_SCRATCH_REG0,
8431 PHY84833_DIAG_CMD_PAIR_SWAP_CHANGE);
8432 for (idx = 0; idx < PHY84833_HDSHK_WAIT; idx++) {
8433 bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD,
8434 MDIO_84833_TOP_CFG_SCRATCH_REG2, &val);
8435 if ((val == PHY84833_CMD_COMPLETE_PASS) ||
8436 (val == PHY84833_CMD_COMPLETE_ERROR))
8437 break;
8438 msleep(1);
8439 }
8440 if ((idx >= PHY84833_HDSHK_WAIT) ||
8441 (val == PHY84833_CMD_COMPLETE_ERROR)) {
8442 DP(NETIF_MSG_LINK, "Pairswap: override failed.\n");
8443 return -EINVAL;
8444 }
8445 bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
8446 MDIO_84833_TOP_CFG_SCRATCH_REG2,
8447 PHY84833_CMD_CLEAR_COMPLETE);
8448 DP(NETIF_MSG_LINK, "Pairswap OK, val=0x%x\n", data);
8449 return 0;
8450}
8451
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00008452static int bnx2x_848x3_config_init(struct bnx2x_phy *phy,
8453 struct link_params *params,
8454 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008455{
8456 struct bnx2x *bp = params->bp;
Yaniv Rosner6a71bbe2010-11-01 05:32:31 +00008457 u8 port, initialize = 1;
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00008458 u16 val;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008459 u16 temp;
Yaniv Rosner1bef68e2011-01-31 04:22:46 +00008460 u32 actual_phy_selection, cms_enable;
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00008461 int rc = 0;
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00008462
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008463 msleep(1);
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00008464
8465 if (!(CHIP_IS_E1(bp)))
Yaniv Rosner6a71bbe2010-11-01 05:32:31 +00008466 port = BP_PATH(bp);
8467 else
8468 port = params->port;
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00008469
8470 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84823) {
8471 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_3,
8472 MISC_REGISTERS_GPIO_OUTPUT_HIGH,
8473 port);
8474 } else {
8475 bnx2x_cl45_write(bp, phy,
8476 MDIO_PMA_DEVAD,
8477 MDIO_PMA_REG_CTRL, 0x8000);
8478 }
8479
Yaniv Rosner6d870c32011-01-31 04:22:20 +00008480 bnx2x_wait_reset_complete(bp, phy, params);
Yaniv Rosner9bffeac2010-11-01 05:32:27 +00008481 /* Wait for GPHY to come out of reset */
8482 msleep(50);
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00008483
8484 /* Bring PHY out of super isolate mode */
8485 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833) {
8486 bnx2x_cl45_read(bp, phy,
8487 MDIO_CTL_DEVAD,
8488 MDIO_84833_TOP_CFG_XGPHY_STRAP1, &val);
8489 val &= ~MDIO_84833_SUPER_ISOLATE;
8490 bnx2x_cl45_write(bp, phy,
8491 MDIO_CTL_DEVAD,
8492 MDIO_84833_TOP_CFG_XGPHY_STRAP1, val);
8493 bnx2x_wait_reset_complete(bp, phy, params);
8494 }
8495
8496 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
8497 bnx2x_84833_pair_swap_cfg(phy, params, vars);
8498
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008499 /*
8500 * BCM84823 requires that XGXS links up first @ 10G for normal behavior
8501 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008502 temp = vars->line_speed;
8503 vars->line_speed = SPEED_10000;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008504 bnx2x_set_autoneg(&params->phy[INT_PHY], params, vars, 0);
8505 bnx2x_program_serdes(&params->phy[INT_PHY], params, vars);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008506 vars->line_speed = temp;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008507
8508 /* Set dual-media configuration according to configuration */
8509
8510 bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD,
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00008511 MDIO_CTL_REG_84823_MEDIA, &val);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008512 val &= ~(MDIO_CTL_REG_84823_MEDIA_MAC_MASK |
8513 MDIO_CTL_REG_84823_MEDIA_LINE_MASK |
8514 MDIO_CTL_REG_84823_MEDIA_COPPER_CORE_DOWN |
8515 MDIO_CTL_REG_84823_MEDIA_PRIORITY_MASK |
8516 MDIO_CTL_REG_84823_MEDIA_FIBER_1G);
8517 val |= MDIO_CTL_REG_84823_CTRL_MAC_XFI |
8518 MDIO_CTL_REG_84823_MEDIA_LINE_XAUI_L;
8519
8520 actual_phy_selection = bnx2x_phy_selection(params);
8521
8522 switch (actual_phy_selection) {
8523 case PORT_HW_CFG_PHY_SELECTION_HARDWARE_DEFAULT:
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008524 /* Do nothing. Essentially this is like the priority copper */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008525 break;
8526 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY_PRIORITY:
8527 val |= MDIO_CTL_REG_84823_MEDIA_PRIORITY_COPPER;
8528 break;
8529 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY_PRIORITY:
8530 val |= MDIO_CTL_REG_84823_MEDIA_PRIORITY_FIBER;
8531 break;
8532 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY:
8533 /* Do nothing here. The first PHY won't be initialized at all */
8534 break;
8535 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY:
8536 val |= MDIO_CTL_REG_84823_MEDIA_COPPER_CORE_DOWN;
8537 initialize = 0;
8538 break;
8539 }
8540 if (params->phy[EXT_PHY2].req_line_speed == SPEED_1000)
8541 val |= MDIO_CTL_REG_84823_MEDIA_FIBER_1G;
8542
8543 bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00008544 MDIO_CTL_REG_84823_MEDIA, val);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008545 DP(NETIF_MSG_LINK, "Multi_phy config = 0x%x, Media control = 0x%x\n",
8546 params->multi_phy_config, val);
8547
8548 if (initialize)
8549 rc = bnx2x_848xx_cmn_config_init(phy, params, vars);
8550 else
8551 bnx2x_save_848xx_spirom_version(phy, params);
Yaniv Rosner1bef68e2011-01-31 04:22:46 +00008552 cms_enable = REG_RD(bp, params->shmem_base +
8553 offsetof(struct shmem_region,
8554 dev_info.port_hw_config[params->port].default_cfg)) &
8555 PORT_HW_CFG_ENABLE_CMS_MASK;
8556
8557 bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD,
8558 MDIO_CTL_REG_84823_USER_CTRL_REG, &val);
8559 if (cms_enable)
8560 val |= MDIO_CTL_REG_84823_USER_CTRL_CMS;
8561 else
8562 val &= ~MDIO_CTL_REG_84823_USER_CTRL_CMS;
8563 bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
8564 MDIO_CTL_REG_84823_USER_CTRL_REG, val);
8565
8566
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008567 return rc;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008568}
8569
8570static u8 bnx2x_848xx_read_status(struct bnx2x_phy *phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008571 struct link_params *params,
8572 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008573{
8574 struct bnx2x *bp = params->bp;
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00008575 u16 val, val1, val2;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008576 u8 link_up = 0;
8577
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00008578
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008579 /* Check 10G-BaseT link status */
8580 /* Check PMD signal ok */
8581 bnx2x_cl45_read(bp, phy,
8582 MDIO_AN_DEVAD, 0xFFFA, &val1);
8583 bnx2x_cl45_read(bp, phy,
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00008584 MDIO_PMA_DEVAD, MDIO_PMA_REG_8481_PMD_SIGNAL,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008585 &val2);
8586 DP(NETIF_MSG_LINK, "BCM848xx: PMD_SIGNAL 1.a811 = 0x%x\n", val2);
8587
8588 /* Check link 10G */
8589 if (val2 & (1<<11)) {
8590 vars->line_speed = SPEED_10000;
Yaniv Rosner791f18c2011-01-18 04:33:42 +00008591 vars->duplex = DUPLEX_FULL;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008592 link_up = 1;
8593 bnx2x_ext_phy_10G_an_resolve(bp, phy, vars);
8594 } else { /* Check Legacy speed link */
8595 u16 legacy_status, legacy_speed;
8596
8597 /* Enable expansion register 0x42 (Operation mode status) */
8598 bnx2x_cl45_write(bp, phy,
8599 MDIO_AN_DEVAD,
8600 MDIO_AN_REG_8481_EXPANSION_REG_ACCESS, 0xf42);
8601
8602 /* Get legacy speed operation status */
8603 bnx2x_cl45_read(bp, phy,
8604 MDIO_AN_DEVAD,
8605 MDIO_AN_REG_8481_EXPANSION_REG_RD_RW,
8606 &legacy_status);
8607
8608 DP(NETIF_MSG_LINK, "Legacy speed status"
8609 " = 0x%x\n", legacy_status);
8610 link_up = ((legacy_status & (1<<11)) == (1<<11));
8611 if (link_up) {
8612 legacy_speed = (legacy_status & (3<<9));
8613 if (legacy_speed == (0<<9))
8614 vars->line_speed = SPEED_10;
8615 else if (legacy_speed == (1<<9))
8616 vars->line_speed = SPEED_100;
8617 else if (legacy_speed == (2<<9))
8618 vars->line_speed = SPEED_1000;
8619 else /* Should not happen */
8620 vars->line_speed = 0;
8621
8622 if (legacy_status & (1<<8))
8623 vars->duplex = DUPLEX_FULL;
8624 else
8625 vars->duplex = DUPLEX_HALF;
8626
8627 DP(NETIF_MSG_LINK, "Link is up in %dMbps,"
8628 " is_duplex_full= %d\n", vars->line_speed,
8629 (vars->duplex == DUPLEX_FULL));
8630 /* Check legacy speed AN resolution */
8631 bnx2x_cl45_read(bp, phy,
8632 MDIO_AN_DEVAD,
8633 MDIO_AN_REG_8481_LEGACY_MII_STATUS,
8634 &val);
8635 if (val & (1<<5))
8636 vars->link_status |=
8637 LINK_STATUS_AUTO_NEGOTIATE_COMPLETE;
8638 bnx2x_cl45_read(bp, phy,
8639 MDIO_AN_DEVAD,
8640 MDIO_AN_REG_8481_LEGACY_AN_EXPANSION,
8641 &val);
8642 if ((val & (1<<0)) == 0)
8643 vars->link_status |=
8644 LINK_STATUS_PARALLEL_DETECTION_USED;
8645 }
8646 }
8647 if (link_up) {
8648 DP(NETIF_MSG_LINK, "BCM84823: link speed is %d\n",
8649 vars->line_speed);
8650 bnx2x_ext_phy_resolve_fc(phy, params, vars);
8651 }
8652
8653 return link_up;
8654}
8655
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00008656
8657static int bnx2x_848xx_format_ver(u32 raw_ver, u8 *str, u16 *len)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008658{
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00008659 int status = 0;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008660 u32 spirom_ver;
8661 spirom_ver = ((raw_ver & 0xF80) >> 7) << 16 | (raw_ver & 0x7F);
8662 status = bnx2x_format_ver(spirom_ver, str, len);
8663 return status;
8664}
8665
8666static void bnx2x_8481_hw_reset(struct bnx2x_phy *phy,
8667 struct link_params *params)
8668{
8669 bnx2x_set_gpio(params->bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008670 MISC_REGISTERS_GPIO_OUTPUT_LOW, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008671 bnx2x_set_gpio(params->bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008672 MISC_REGISTERS_GPIO_OUTPUT_LOW, 1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008673}
8674
8675static void bnx2x_8481_link_reset(struct bnx2x_phy *phy,
8676 struct link_params *params)
8677{
8678 bnx2x_cl45_write(params->bp, phy,
8679 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x0000);
8680 bnx2x_cl45_write(params->bp, phy,
8681 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 1);
8682}
8683
8684static void bnx2x_848x3_link_reset(struct bnx2x_phy *phy,
8685 struct link_params *params)
8686{
8687 struct bnx2x *bp = params->bp;
Yaniv Rosner6a71bbe2010-11-01 05:32:31 +00008688 u8 port;
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00008689
8690 if (!(CHIP_IS_E1(bp)))
Yaniv Rosner6a71bbe2010-11-01 05:32:31 +00008691 port = BP_PATH(bp);
8692 else
8693 port = params->port;
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00008694
8695 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84823) {
8696 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_3,
8697 MISC_REGISTERS_GPIO_OUTPUT_LOW,
8698 port);
8699 } else {
8700 bnx2x_cl45_write(bp, phy,
8701 MDIO_PMA_DEVAD,
8702 MDIO_PMA_REG_CTRL, 0x800);
8703 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008704}
8705
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00008706static void bnx2x_848xx_set_link_led(struct bnx2x_phy *phy,
8707 struct link_params *params, u8 mode)
8708{
8709 struct bnx2x *bp = params->bp;
8710 u16 val;
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00008711 u8 port;
8712
8713 if (!(CHIP_IS_E1(bp)))
8714 port = BP_PATH(bp);
8715 else
8716 port = params->port;
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00008717
8718 switch (mode) {
8719 case LED_MODE_OFF:
8720
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00008721 DP(NETIF_MSG_LINK, "Port 0x%x: LED MODE OFF\n", port);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00008722
8723 if ((params->hw_led_mode << SHARED_HW_CFG_LED_MODE_SHIFT) ==
8724 SHARED_HW_CFG_LED_EXTPHY1) {
8725
8726 /* Set LED masks */
8727 bnx2x_cl45_write(bp, phy,
8728 MDIO_PMA_DEVAD,
8729 MDIO_PMA_REG_8481_LED1_MASK,
8730 0x0);
8731
8732 bnx2x_cl45_write(bp, phy,
8733 MDIO_PMA_DEVAD,
8734 MDIO_PMA_REG_8481_LED2_MASK,
8735 0x0);
8736
8737 bnx2x_cl45_write(bp, phy,
8738 MDIO_PMA_DEVAD,
8739 MDIO_PMA_REG_8481_LED3_MASK,
8740 0x0);
8741
8742 bnx2x_cl45_write(bp, phy,
8743 MDIO_PMA_DEVAD,
8744 MDIO_PMA_REG_8481_LED5_MASK,
8745 0x0);
8746
8747 } else {
8748 bnx2x_cl45_write(bp, phy,
8749 MDIO_PMA_DEVAD,
8750 MDIO_PMA_REG_8481_LED1_MASK,
8751 0x0);
8752 }
8753 break;
8754 case LED_MODE_FRONT_PANEL_OFF:
8755
8756 DP(NETIF_MSG_LINK, "Port 0x%x: LED MODE FRONT PANEL OFF\n",
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00008757 port);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00008758
8759 if ((params->hw_led_mode << SHARED_HW_CFG_LED_MODE_SHIFT) ==
8760 SHARED_HW_CFG_LED_EXTPHY1) {
8761
8762 /* Set LED masks */
8763 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008764 MDIO_PMA_DEVAD,
8765 MDIO_PMA_REG_8481_LED1_MASK,
8766 0x0);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00008767
8768 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008769 MDIO_PMA_DEVAD,
8770 MDIO_PMA_REG_8481_LED2_MASK,
8771 0x0);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00008772
8773 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008774 MDIO_PMA_DEVAD,
8775 MDIO_PMA_REG_8481_LED3_MASK,
8776 0x0);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00008777
8778 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008779 MDIO_PMA_DEVAD,
8780 MDIO_PMA_REG_8481_LED5_MASK,
8781 0x20);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00008782
8783 } else {
8784 bnx2x_cl45_write(bp, phy,
8785 MDIO_PMA_DEVAD,
8786 MDIO_PMA_REG_8481_LED1_MASK,
8787 0x0);
8788 }
8789 break;
8790 case LED_MODE_ON:
8791
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00008792 DP(NETIF_MSG_LINK, "Port 0x%x: LED MODE ON\n", port);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00008793
8794 if ((params->hw_led_mode << SHARED_HW_CFG_LED_MODE_SHIFT) ==
8795 SHARED_HW_CFG_LED_EXTPHY1) {
8796 /* Set control reg */
8797 bnx2x_cl45_read(bp, phy,
8798 MDIO_PMA_DEVAD,
8799 MDIO_PMA_REG_8481_LINK_SIGNAL,
8800 &val);
8801 val &= 0x8000;
8802 val |= 0x2492;
8803
8804 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008805 MDIO_PMA_DEVAD,
8806 MDIO_PMA_REG_8481_LINK_SIGNAL,
8807 val);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00008808
8809 /* Set LED masks */
8810 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008811 MDIO_PMA_DEVAD,
8812 MDIO_PMA_REG_8481_LED1_MASK,
8813 0x0);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00008814
8815 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008816 MDIO_PMA_DEVAD,
8817 MDIO_PMA_REG_8481_LED2_MASK,
8818 0x20);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00008819
8820 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008821 MDIO_PMA_DEVAD,
8822 MDIO_PMA_REG_8481_LED3_MASK,
8823 0x20);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00008824
8825 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008826 MDIO_PMA_DEVAD,
8827 MDIO_PMA_REG_8481_LED5_MASK,
8828 0x0);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00008829 } else {
8830 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008831 MDIO_PMA_DEVAD,
8832 MDIO_PMA_REG_8481_LED1_MASK,
8833 0x20);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00008834 }
8835 break;
8836
8837 case LED_MODE_OPER:
8838
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00008839 DP(NETIF_MSG_LINK, "Port 0x%x: LED MODE OPER\n", port);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00008840
8841 if ((params->hw_led_mode << SHARED_HW_CFG_LED_MODE_SHIFT) ==
8842 SHARED_HW_CFG_LED_EXTPHY1) {
8843
8844 /* Set control reg */
8845 bnx2x_cl45_read(bp, phy,
8846 MDIO_PMA_DEVAD,
8847 MDIO_PMA_REG_8481_LINK_SIGNAL,
8848 &val);
8849
8850 if (!((val &
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008851 MDIO_PMA_REG_8481_LINK_SIGNAL_LED4_ENABLE_MASK)
8852 >> MDIO_PMA_REG_8481_LINK_SIGNAL_LED4_ENABLE_SHIFT)) {
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008853 DP(NETIF_MSG_LINK, "Setting LINK_SIGNAL\n");
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00008854 bnx2x_cl45_write(bp, phy,
8855 MDIO_PMA_DEVAD,
8856 MDIO_PMA_REG_8481_LINK_SIGNAL,
8857 0xa492);
8858 }
8859
8860 /* Set LED masks */
8861 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008862 MDIO_PMA_DEVAD,
8863 MDIO_PMA_REG_8481_LED1_MASK,
8864 0x10);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00008865
8866 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008867 MDIO_PMA_DEVAD,
8868 MDIO_PMA_REG_8481_LED2_MASK,
8869 0x80);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00008870
8871 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008872 MDIO_PMA_DEVAD,
8873 MDIO_PMA_REG_8481_LED3_MASK,
8874 0x98);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00008875
8876 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008877 MDIO_PMA_DEVAD,
8878 MDIO_PMA_REG_8481_LED5_MASK,
8879 0x40);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00008880
8881 } else {
8882 bnx2x_cl45_write(bp, phy,
8883 MDIO_PMA_DEVAD,
8884 MDIO_PMA_REG_8481_LED1_MASK,
8885 0x80);
Yaniv Rosner53eda062011-01-30 04:14:55 +00008886
8887 /* Tell LED3 to blink on source */
8888 bnx2x_cl45_read(bp, phy,
8889 MDIO_PMA_DEVAD,
8890 MDIO_PMA_REG_8481_LINK_SIGNAL,
8891 &val);
8892 val &= ~(7<<6);
8893 val |= (1<<6); /* A83B[8:6]= 1 */
8894 bnx2x_cl45_write(bp, phy,
8895 MDIO_PMA_DEVAD,
8896 MDIO_PMA_REG_8481_LINK_SIGNAL,
8897 val);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00008898 }
8899 break;
8900 }
8901}
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008902/******************************************************************/
Yaniv Rosner6583e332011-06-14 01:34:17 +00008903/* 54616S PHY SECTION */
8904/******************************************************************/
8905static int bnx2x_54616s_config_init(struct bnx2x_phy *phy,
8906 struct link_params *params,
8907 struct link_vars *vars)
8908{
8909 struct bnx2x *bp = params->bp;
8910 u8 port;
8911 u16 autoneg_val, an_1000_val, an_10_100_val, fc_val, temp;
8912 u32 cfg_pin;
8913
8914 DP(NETIF_MSG_LINK, "54616S cfg init\n");
8915 usleep_range(1000, 1000);
8916
8917 /* This works with E3 only, no need to check the chip
8918 before determining the port. */
8919 port = params->port;
8920
8921 cfg_pin = (REG_RD(bp, params->shmem_base +
8922 offsetof(struct shmem_region,
8923 dev_info.port_hw_config[port].e3_cmn_pin_cfg)) &
8924 PORT_HW_CFG_E3_PHY_RESET_MASK) >>
8925 PORT_HW_CFG_E3_PHY_RESET_SHIFT;
8926
8927 /* Drive pin high to bring the GPHY out of reset. */
8928 bnx2x_set_cfg_pin(bp, cfg_pin, 1);
8929
8930 /* wait for GPHY to reset */
8931 msleep(50);
8932
8933 /* reset phy */
8934 bnx2x_cl22_write(bp, phy,
8935 MDIO_PMA_REG_CTRL, 0x8000);
8936 bnx2x_wait_reset_complete(bp, phy, params);
8937
8938 /*wait for GPHY to reset */
8939 msleep(50);
8940
8941 /* Configure LED4: set to INTR (0x6). */
8942 /* Accessing shadow register 0xe. */
8943 bnx2x_cl22_write(bp, phy,
8944 MDIO_REG_GPHY_SHADOW,
8945 MDIO_REG_GPHY_SHADOW_LED_SEL2);
8946 bnx2x_cl22_read(bp, phy,
8947 MDIO_REG_GPHY_SHADOW,
8948 &temp);
8949 temp &= ~(0xf << 4);
8950 temp |= (0x6 << 4);
8951 bnx2x_cl22_write(bp, phy,
8952 MDIO_REG_GPHY_SHADOW,
8953 MDIO_REG_GPHY_SHADOW_WR_ENA | temp);
8954 /* Configure INTR based on link status change. */
8955 bnx2x_cl22_write(bp, phy,
8956 MDIO_REG_INTR_MASK,
8957 ~MDIO_REG_INTR_MASK_LINK_STATUS);
8958
8959 /* Flip the signal detect polarity (set 0x1c.0x1e[8]). */
8960 bnx2x_cl22_write(bp, phy,
8961 MDIO_REG_GPHY_SHADOW,
8962 MDIO_REG_GPHY_SHADOW_AUTO_DET_MED);
8963 bnx2x_cl22_read(bp, phy,
8964 MDIO_REG_GPHY_SHADOW,
8965 &temp);
8966 temp |= MDIO_REG_GPHY_SHADOW_INVERT_FIB_SD;
8967 bnx2x_cl22_write(bp, phy,
8968 MDIO_REG_GPHY_SHADOW,
8969 MDIO_REG_GPHY_SHADOW_WR_ENA | temp);
8970
8971 /* Set up fc */
8972 /* Please refer to Table 28B-3 of 802.3ab-1999 spec. */
8973 bnx2x_calc_ieee_aneg_adv(phy, params, &vars->ieee_fc);
8974 fc_val = 0;
8975 if ((vars->ieee_fc & MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC) ==
8976 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC)
8977 fc_val |= MDIO_AN_REG_ADV_PAUSE_ASYMMETRIC;
8978
8979 if ((vars->ieee_fc & MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) ==
8980 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH)
8981 fc_val |= MDIO_AN_REG_ADV_PAUSE_PAUSE;
8982
8983 /* read all advertisement */
8984 bnx2x_cl22_read(bp, phy,
8985 0x09,
8986 &an_1000_val);
8987
8988 bnx2x_cl22_read(bp, phy,
8989 0x04,
8990 &an_10_100_val);
8991
8992 bnx2x_cl22_read(bp, phy,
8993 MDIO_PMA_REG_CTRL,
8994 &autoneg_val);
8995
8996 /* Disable forced speed */
8997 autoneg_val &= ~((1<<6) | (1<<8) | (1<<9) | (1<<12) | (1<<13));
8998 an_10_100_val &= ~((1<<5) | (1<<6) | (1<<7) | (1<<8) | (1<<10) |
8999 (1<<11));
9000
9001 if (((phy->req_line_speed == SPEED_AUTO_NEG) &&
9002 (phy->speed_cap_mask &
9003 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) ||
9004 (phy->req_line_speed == SPEED_1000)) {
9005 an_1000_val |= (1<<8);
9006 autoneg_val |= (1<<9 | 1<<12);
9007 if (phy->req_duplex == DUPLEX_FULL)
9008 an_1000_val |= (1<<9);
9009 DP(NETIF_MSG_LINK, "Advertising 1G\n");
9010 } else
9011 an_1000_val &= ~((1<<8) | (1<<9));
9012
9013 bnx2x_cl22_write(bp, phy,
9014 0x09,
9015 an_1000_val);
9016 bnx2x_cl22_read(bp, phy,
9017 0x09,
9018 &an_1000_val);
9019
9020 /* set 100 speed advertisement */
9021 if (((phy->req_line_speed == SPEED_AUTO_NEG) &&
9022 (phy->speed_cap_mask &
9023 (PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL |
9024 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF)))) {
9025 an_10_100_val |= (1<<7);
9026 /* Enable autoneg and restart autoneg for legacy speeds */
9027 autoneg_val |= (1<<9 | 1<<12);
9028
9029 if (phy->req_duplex == DUPLEX_FULL)
9030 an_10_100_val |= (1<<8);
9031 DP(NETIF_MSG_LINK, "Advertising 100M\n");
9032 }
9033
9034 /* set 10 speed advertisement */
9035 if (((phy->req_line_speed == SPEED_AUTO_NEG) &&
9036 (phy->speed_cap_mask &
9037 (PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL |
9038 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF)))) {
9039 an_10_100_val |= (1<<5);
9040 autoneg_val |= (1<<9 | 1<<12);
9041 if (phy->req_duplex == DUPLEX_FULL)
9042 an_10_100_val |= (1<<6);
9043 DP(NETIF_MSG_LINK, "Advertising 10M\n");
9044 }
9045
9046 /* Only 10/100 are allowed to work in FORCE mode */
9047 if (phy->req_line_speed == SPEED_100) {
9048 autoneg_val |= (1<<13);
9049 /* Enabled AUTO-MDIX when autoneg is disabled */
9050 bnx2x_cl22_write(bp, phy,
9051 0x18,
9052 (1<<15 | 1<<9 | 7<<0));
9053 DP(NETIF_MSG_LINK, "Setting 100M force\n");
9054 }
9055 if (phy->req_line_speed == SPEED_10) {
9056 /* Enabled AUTO-MDIX when autoneg is disabled */
9057 bnx2x_cl22_write(bp, phy,
9058 0x18,
9059 (1<<15 | 1<<9 | 7<<0));
9060 DP(NETIF_MSG_LINK, "Setting 10M force\n");
9061 }
9062
9063 bnx2x_cl22_write(bp, phy,
9064 0x04,
9065 an_10_100_val | fc_val);
9066
9067 if (phy->req_duplex == DUPLEX_FULL)
9068 autoneg_val |= (1<<8);
9069
9070 bnx2x_cl22_write(bp, phy,
9071 MDIO_PMA_REG_CTRL, autoneg_val);
9072
9073 return 0;
9074}
9075
9076static void bnx2x_54616s_set_link_led(struct bnx2x_phy *phy,
9077 struct link_params *params, u8 mode)
9078{
9079 struct bnx2x *bp = params->bp;
9080 DP(NETIF_MSG_LINK, "54616S set link led (mode=%x)\n", mode);
9081 switch (mode) {
9082 case LED_MODE_FRONT_PANEL_OFF:
9083 case LED_MODE_OFF:
9084 case LED_MODE_OPER:
9085 case LED_MODE_ON:
9086 default:
9087 break;
9088 }
9089 return;
9090}
9091
9092static void bnx2x_54616s_link_reset(struct bnx2x_phy *phy,
9093 struct link_params *params)
9094{
9095 struct bnx2x *bp = params->bp;
9096 u32 cfg_pin;
9097 u8 port;
9098
9099 /* This works with E3 only, no need to check the chip
9100 before determining the port. */
9101 port = params->port;
9102 cfg_pin = (REG_RD(bp, params->shmem_base +
9103 offsetof(struct shmem_region,
9104 dev_info.port_hw_config[port].e3_cmn_pin_cfg)) &
9105 PORT_HW_CFG_E3_PHY_RESET_MASK) >>
9106 PORT_HW_CFG_E3_PHY_RESET_SHIFT;
9107
9108 /* Drive pin low to put GPHY in reset. */
9109 bnx2x_set_cfg_pin(bp, cfg_pin, 0);
9110}
9111
9112static u8 bnx2x_54616s_read_status(struct bnx2x_phy *phy,
9113 struct link_params *params,
9114 struct link_vars *vars)
9115{
9116 struct bnx2x *bp = params->bp;
9117 u16 val;
9118 u8 link_up = 0;
9119 u16 legacy_status, legacy_speed;
9120
9121 /* Get speed operation status */
9122 bnx2x_cl22_read(bp, phy,
9123 0x19,
9124 &legacy_status);
9125 DP(NETIF_MSG_LINK, "54616S read_status: 0x%x\n", legacy_status);
9126
9127 /* Read status to clear the PHY interrupt. */
9128 bnx2x_cl22_read(bp, phy,
9129 MDIO_REG_INTR_STATUS,
9130 &val);
9131
9132 link_up = ((legacy_status & (1<<2)) == (1<<2));
9133
9134 if (link_up) {
9135 legacy_speed = (legacy_status & (7<<8));
9136 if (legacy_speed == (7<<8)) {
9137 vars->line_speed = SPEED_1000;
9138 vars->duplex = DUPLEX_FULL;
9139 } else if (legacy_speed == (6<<8)) {
9140 vars->line_speed = SPEED_1000;
9141 vars->duplex = DUPLEX_HALF;
9142 } else if (legacy_speed == (5<<8)) {
9143 vars->line_speed = SPEED_100;
9144 vars->duplex = DUPLEX_FULL;
9145 }
9146 /* Omitting 100Base-T4 for now */
9147 else if (legacy_speed == (3<<8)) {
9148 vars->line_speed = SPEED_100;
9149 vars->duplex = DUPLEX_HALF;
9150 } else if (legacy_speed == (2<<8)) {
9151 vars->line_speed = SPEED_10;
9152 vars->duplex = DUPLEX_FULL;
9153 } else if (legacy_speed == (1<<8)) {
9154 vars->line_speed = SPEED_10;
9155 vars->duplex = DUPLEX_HALF;
9156 } else /* Should not happen */
9157 vars->line_speed = 0;
9158
9159 DP(NETIF_MSG_LINK, "Link is up in %dMbps,"
9160 " is_duplex_full= %d\n", vars->line_speed,
9161 (vars->duplex == DUPLEX_FULL));
9162
9163 /* Check legacy speed AN resolution */
9164 bnx2x_cl22_read(bp, phy,
9165 0x01,
9166 &val);
9167 if (val & (1<<5))
9168 vars->link_status |=
9169 LINK_STATUS_AUTO_NEGOTIATE_COMPLETE;
9170 bnx2x_cl22_read(bp, phy,
9171 0x06,
9172 &val);
9173 if ((val & (1<<0)) == 0)
9174 vars->link_status |=
9175 LINK_STATUS_PARALLEL_DETECTION_USED;
9176
9177 DP(NETIF_MSG_LINK, "BCM54616S: link speed is %d\n",
9178 vars->line_speed);
9179 bnx2x_ext_phy_resolve_fc(phy, params, vars);
9180 }
9181 return link_up;
9182}
9183
9184static void bnx2x_54616s_config_loopback(struct bnx2x_phy *phy,
9185 struct link_params *params)
9186{
9187 struct bnx2x *bp = params->bp;
9188 u16 val;
9189 u32 umac_base = params->port ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
9190
9191 DP(NETIF_MSG_LINK, "2PMA/PMD ext_phy_loopback: 54616s\n");
9192
9193 /* Enable master/slave manual mmode and set to master */
9194 /* mii write 9 [bits set 11 12] */
9195 bnx2x_cl22_write(bp, phy, 0x09, 3<<11);
9196
9197 /* forced 1G and disable autoneg */
9198 /* set val [mii read 0] */
9199 /* set val [expr $val & [bits clear 6 12 13]] */
9200 /* set val [expr $val | [bits set 6 8]] */
9201 /* mii write 0 $val */
9202 bnx2x_cl22_read(bp, phy, 0x00, &val);
9203 val &= ~((1<<6) | (1<<12) | (1<<13));
9204 val |= (1<<6) | (1<<8);
9205 bnx2x_cl22_write(bp, phy, 0x00, val);
9206
9207 /* Set external loopback and Tx using 6dB coding */
9208 /* mii write 0x18 7 */
9209 /* set val [mii read 0x18] */
9210 /* mii write 0x18 [expr $val | [bits set 10 15]] */
9211 bnx2x_cl22_write(bp, phy, 0x18, 7);
9212 bnx2x_cl22_read(bp, phy, 0x18, &val);
9213 bnx2x_cl22_write(bp, phy, 0x18, val | (1<<10) | (1<<15));
9214
9215 /* This register opens the gate for the UMAC despite its name */
9216 REG_WR(bp, NIG_REG_EGRESS_EMAC0_PORT + params->port*4, 1);
9217
9218 /*
9219 * Maximum Frame Length (RW). Defines a 14-Bit maximum frame
9220 * length used by the MAC receive logic to check frames.
9221 */
9222 REG_WR(bp, umac_base + UMAC_REG_MAXFR, 0x2710);
9223}
9224
9225/******************************************************************/
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009226/* SFX7101 PHY SECTION */
9227/******************************************************************/
9228static void bnx2x_7101_config_loopback(struct bnx2x_phy *phy,
9229 struct link_params *params)
9230{
9231 struct bnx2x *bp = params->bp;
9232 /* SFX7101_XGXS_TEST1 */
9233 bnx2x_cl45_write(bp, phy,
9234 MDIO_XS_DEVAD, MDIO_XS_SFX7101_XGXS_TEST1, 0x100);
9235}
9236
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00009237static int bnx2x_7101_config_init(struct bnx2x_phy *phy,
9238 struct link_params *params,
9239 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009240{
9241 u16 fw_ver1, fw_ver2, val;
9242 struct bnx2x *bp = params->bp;
9243 DP(NETIF_MSG_LINK, "Setting the SFX7101 LASI indication\n");
9244
9245 /* Restore normal power mode*/
9246 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00009247 MISC_REGISTERS_GPIO_OUTPUT_HIGH, params->port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009248 /* HW reset */
9249 bnx2x_ext_phy_hw_reset(bp, params->port);
Yaniv Rosner6d870c32011-01-31 04:22:20 +00009250 bnx2x_wait_reset_complete(bp, phy, params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009251
9252 bnx2x_cl45_write(bp, phy,
9253 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_CTRL, 0x1);
9254 DP(NETIF_MSG_LINK, "Setting the SFX7101 LED to blink on traffic\n");
9255 bnx2x_cl45_write(bp, phy,
9256 MDIO_PMA_DEVAD, MDIO_PMA_REG_7107_LED_CNTL, (1<<3));
9257
9258 bnx2x_ext_phy_set_pause(params, phy, vars);
9259 /* Restart autoneg */
9260 bnx2x_cl45_read(bp, phy,
9261 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, &val);
9262 val |= 0x200;
9263 bnx2x_cl45_write(bp, phy,
9264 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, val);
9265
9266 /* Save spirom version */
9267 bnx2x_cl45_read(bp, phy,
9268 MDIO_PMA_DEVAD, MDIO_PMA_REG_7101_VER1, &fw_ver1);
9269
9270 bnx2x_cl45_read(bp, phy,
9271 MDIO_PMA_DEVAD, MDIO_PMA_REG_7101_VER2, &fw_ver2);
9272 bnx2x_save_spirom_version(bp, params->port,
9273 (u32)(fw_ver1<<16 | fw_ver2), phy->ver_addr);
9274 return 0;
9275}
9276
9277static u8 bnx2x_7101_read_status(struct bnx2x_phy *phy,
9278 struct link_params *params,
9279 struct link_vars *vars)
9280{
9281 struct bnx2x *bp = params->bp;
9282 u8 link_up;
9283 u16 val1, val2;
9284 bnx2x_cl45_read(bp, phy,
9285 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_STATUS, &val2);
9286 bnx2x_cl45_read(bp, phy,
9287 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_STATUS, &val1);
9288 DP(NETIF_MSG_LINK, "10G-base-T LASI status 0x%x->0x%x\n",
9289 val2, val1);
9290 bnx2x_cl45_read(bp, phy,
9291 MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val2);
9292 bnx2x_cl45_read(bp, phy,
9293 MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val1);
9294 DP(NETIF_MSG_LINK, "10G-base-T PMA status 0x%x->0x%x\n",
9295 val2, val1);
9296 link_up = ((val1 & 4) == 4);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00009297 /* if link is up print the AN outcome of the SFX7101 PHY */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009298 if (link_up) {
9299 bnx2x_cl45_read(bp, phy,
9300 MDIO_AN_DEVAD, MDIO_AN_REG_MASTER_STATUS,
9301 &val2);
9302 vars->line_speed = SPEED_10000;
Yaniv Rosner791f18c2011-01-18 04:33:42 +00009303 vars->duplex = DUPLEX_FULL;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009304 DP(NETIF_MSG_LINK, "SFX7101 AN status 0x%x->Master=%x\n",
9305 val2, (val2 & (1<<14)));
9306 bnx2x_ext_phy_10G_an_resolve(bp, phy, vars);
9307 bnx2x_ext_phy_resolve_fc(phy, params, vars);
9308 }
9309 return link_up;
9310}
9311
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00009312static int bnx2x_7101_format_ver(u32 spirom_ver, u8 *str, u16 *len)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009313{
9314 if (*len < 5)
9315 return -EINVAL;
9316 str[0] = (spirom_ver & 0xFF);
9317 str[1] = (spirom_ver & 0xFF00) >> 8;
9318 str[2] = (spirom_ver & 0xFF0000) >> 16;
9319 str[3] = (spirom_ver & 0xFF000000) >> 24;
9320 str[4] = '\0';
9321 *len -= 5;
9322 return 0;
9323}
9324
9325void bnx2x_sfx7101_sp_sw_reset(struct bnx2x *bp, struct bnx2x_phy *phy)
9326{
9327 u16 val, cnt;
9328
9329 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00009330 MDIO_PMA_DEVAD,
9331 MDIO_PMA_REG_7101_RESET, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009332
9333 for (cnt = 0; cnt < 10; cnt++) {
9334 msleep(50);
9335 /* Writes a self-clearing reset */
9336 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00009337 MDIO_PMA_DEVAD,
9338 MDIO_PMA_REG_7101_RESET,
9339 (val | (1<<15)));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009340 /* Wait for clear */
9341 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00009342 MDIO_PMA_DEVAD,
9343 MDIO_PMA_REG_7101_RESET, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009344
9345 if ((val & (1<<15)) == 0)
9346 break;
9347 }
9348}
9349
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009350static void bnx2x_7101_hw_reset(struct bnx2x_phy *phy,
9351 struct link_params *params) {
9352 /* Low power mode is controlled by GPIO 2 */
9353 bnx2x_set_gpio(params->bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00009354 MISC_REGISTERS_GPIO_OUTPUT_LOW, params->port);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009355 /* The PHY reset is controlled by GPIO 1 */
9356 bnx2x_set_gpio(params->bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00009357 MISC_REGISTERS_GPIO_OUTPUT_LOW, params->port);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009358}
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009359
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00009360static void bnx2x_7101_set_link_led(struct bnx2x_phy *phy,
9361 struct link_params *params, u8 mode)
9362{
9363 u16 val = 0;
9364 struct bnx2x *bp = params->bp;
9365 switch (mode) {
9366 case LED_MODE_FRONT_PANEL_OFF:
9367 case LED_MODE_OFF:
9368 val = 2;
9369 break;
9370 case LED_MODE_ON:
9371 val = 1;
9372 break;
9373 case LED_MODE_OPER:
9374 val = 0;
9375 break;
9376 }
9377 bnx2x_cl45_write(bp, phy,
9378 MDIO_PMA_DEVAD,
9379 MDIO_PMA_REG_7107_LINK_LED_CNTL,
9380 val);
9381}
9382
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009383/******************************************************************/
9384/* STATIC PHY DECLARATION */
9385/******************************************************************/
9386
9387static struct bnx2x_phy phy_null = {
9388 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN,
9389 .addr = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009390 .def_md_devad = 0,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00009391 .flags = FLAGS_INIT_XGXS_FIRST,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009392 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
9393 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
9394 .mdio_ctrl = 0,
9395 .supported = 0,
9396 .media_type = ETH_PHY_NOT_PRESENT,
9397 .ver_addr = 0,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00009398 .req_flow_ctrl = 0,
9399 .req_line_speed = 0,
9400 .speed_cap_mask = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009401 .req_duplex = 0,
9402 .rsrv = 0,
9403 .config_init = (config_init_t)NULL,
9404 .read_status = (read_status_t)NULL,
9405 .link_reset = (link_reset_t)NULL,
9406 .config_loopback = (config_loopback_t)NULL,
9407 .format_fw_ver = (format_fw_ver_t)NULL,
9408 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00009409 .set_link_led = (set_link_led_t)NULL,
9410 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009411};
9412
9413static struct bnx2x_phy phy_serdes = {
9414 .type = PORT_HW_CFG_SERDES_EXT_PHY_TYPE_DIRECT,
9415 .addr = 0xff,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009416 .def_md_devad = 0,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00009417 .flags = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009418 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
9419 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
9420 .mdio_ctrl = 0,
9421 .supported = (SUPPORTED_10baseT_Half |
9422 SUPPORTED_10baseT_Full |
9423 SUPPORTED_100baseT_Half |
9424 SUPPORTED_100baseT_Full |
9425 SUPPORTED_1000baseT_Full |
9426 SUPPORTED_2500baseX_Full |
9427 SUPPORTED_TP |
9428 SUPPORTED_Autoneg |
9429 SUPPORTED_Pause |
9430 SUPPORTED_Asym_Pause),
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00009431 .media_type = ETH_PHY_BASE_T,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009432 .ver_addr = 0,
9433 .req_flow_ctrl = 0,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00009434 .req_line_speed = 0,
9435 .speed_cap_mask = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009436 .req_duplex = 0,
9437 .rsrv = 0,
Yaniv Rosnerec146a62011-05-31 21:29:27 +00009438 .config_init = (config_init_t)bnx2x_xgxs_config_init,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009439 .read_status = (read_status_t)bnx2x_link_settings_status,
9440 .link_reset = (link_reset_t)bnx2x_int_link_reset,
9441 .config_loopback = (config_loopback_t)NULL,
9442 .format_fw_ver = (format_fw_ver_t)NULL,
9443 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00009444 .set_link_led = (set_link_led_t)NULL,
9445 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009446};
9447
9448static struct bnx2x_phy phy_xgxs = {
9449 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT,
9450 .addr = 0xff,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009451 .def_md_devad = 0,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00009452 .flags = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009453 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
9454 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
9455 .mdio_ctrl = 0,
9456 .supported = (SUPPORTED_10baseT_Half |
9457 SUPPORTED_10baseT_Full |
9458 SUPPORTED_100baseT_Half |
9459 SUPPORTED_100baseT_Full |
9460 SUPPORTED_1000baseT_Full |
9461 SUPPORTED_2500baseX_Full |
9462 SUPPORTED_10000baseT_Full |
9463 SUPPORTED_FIBRE |
9464 SUPPORTED_Autoneg |
9465 SUPPORTED_Pause |
9466 SUPPORTED_Asym_Pause),
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00009467 .media_type = ETH_PHY_CX4,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009468 .ver_addr = 0,
9469 .req_flow_ctrl = 0,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00009470 .req_line_speed = 0,
9471 .speed_cap_mask = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009472 .req_duplex = 0,
9473 .rsrv = 0,
Yaniv Rosnerec146a62011-05-31 21:29:27 +00009474 .config_init = (config_init_t)bnx2x_xgxs_config_init,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009475 .read_status = (read_status_t)bnx2x_link_settings_status,
9476 .link_reset = (link_reset_t)bnx2x_int_link_reset,
9477 .config_loopback = (config_loopback_t)bnx2x_set_xgxs_loopback,
9478 .format_fw_ver = (format_fw_ver_t)NULL,
9479 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00009480 .set_link_led = (set_link_led_t)NULL,
9481 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009482};
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00009483static struct bnx2x_phy phy_warpcore = {
9484 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT,
9485 .addr = 0xff,
9486 .def_md_devad = 0,
9487 .flags = FLAGS_HW_LOCK_REQUIRED,
9488 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
9489 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
9490 .mdio_ctrl = 0,
9491 .supported = (SUPPORTED_10baseT_Half |
9492 SUPPORTED_10baseT_Full |
9493 SUPPORTED_100baseT_Half |
9494 SUPPORTED_100baseT_Full |
9495 SUPPORTED_1000baseT_Full |
9496 SUPPORTED_10000baseT_Full |
9497 SUPPORTED_20000baseKR2_Full |
9498 SUPPORTED_20000baseMLD2_Full |
9499 SUPPORTED_FIBRE |
9500 SUPPORTED_Autoneg |
9501 SUPPORTED_Pause |
9502 SUPPORTED_Asym_Pause),
9503 .media_type = ETH_PHY_UNSPECIFIED,
9504 .ver_addr = 0,
9505 .req_flow_ctrl = 0,
9506 .req_line_speed = 0,
9507 .speed_cap_mask = 0,
9508 /* req_duplex = */0,
9509 /* rsrv = */0,
9510 .config_init = (config_init_t)bnx2x_warpcore_config_init,
9511 .read_status = (read_status_t)bnx2x_warpcore_read_status,
9512 .link_reset = (link_reset_t)bnx2x_warpcore_link_reset,
9513 .config_loopback = (config_loopback_t)bnx2x_set_warpcore_loopback,
9514 .format_fw_ver = (format_fw_ver_t)NULL,
9515 .hw_reset = (hw_reset_t)NULL,
9516 .set_link_led = (set_link_led_t)NULL,
9517 .phy_specific_func = (phy_specific_func_t)NULL
9518};
9519
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009520
9521static struct bnx2x_phy phy_7101 = {
9522 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101,
9523 .addr = 0xff,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009524 .def_md_devad = 0,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00009525 .flags = FLAGS_FAN_FAILURE_DET_REQ,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009526 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
9527 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
9528 .mdio_ctrl = 0,
9529 .supported = (SUPPORTED_10000baseT_Full |
9530 SUPPORTED_TP |
9531 SUPPORTED_Autoneg |
9532 SUPPORTED_Pause |
9533 SUPPORTED_Asym_Pause),
9534 .media_type = ETH_PHY_BASE_T,
9535 .ver_addr = 0,
9536 .req_flow_ctrl = 0,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00009537 .req_line_speed = 0,
9538 .speed_cap_mask = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009539 .req_duplex = 0,
9540 .rsrv = 0,
9541 .config_init = (config_init_t)bnx2x_7101_config_init,
9542 .read_status = (read_status_t)bnx2x_7101_read_status,
9543 .link_reset = (link_reset_t)bnx2x_common_ext_link_reset,
9544 .config_loopback = (config_loopback_t)bnx2x_7101_config_loopback,
9545 .format_fw_ver = (format_fw_ver_t)bnx2x_7101_format_ver,
9546 .hw_reset = (hw_reset_t)bnx2x_7101_hw_reset,
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00009547 .set_link_led = (set_link_led_t)bnx2x_7101_set_link_led,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00009548 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009549};
9550static struct bnx2x_phy phy_8073 = {
9551 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073,
9552 .addr = 0xff,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009553 .def_md_devad = 0,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00009554 .flags = FLAGS_HW_LOCK_REQUIRED,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009555 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
9556 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
9557 .mdio_ctrl = 0,
9558 .supported = (SUPPORTED_10000baseT_Full |
9559 SUPPORTED_2500baseX_Full |
9560 SUPPORTED_1000baseT_Full |
9561 SUPPORTED_FIBRE |
9562 SUPPORTED_Autoneg |
9563 SUPPORTED_Pause |
9564 SUPPORTED_Asym_Pause),
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00009565 .media_type = ETH_PHY_KR,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009566 .ver_addr = 0,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00009567 .req_flow_ctrl = 0,
9568 .req_line_speed = 0,
9569 .speed_cap_mask = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009570 .req_duplex = 0,
9571 .rsrv = 0,
Yaniv Rosner62b29a52010-09-07 11:40:58 +00009572 .config_init = (config_init_t)bnx2x_8073_config_init,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009573 .read_status = (read_status_t)bnx2x_8073_read_status,
9574 .link_reset = (link_reset_t)bnx2x_8073_link_reset,
9575 .config_loopback = (config_loopback_t)NULL,
9576 .format_fw_ver = (format_fw_ver_t)bnx2x_format_ver,
9577 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00009578 .set_link_led = (set_link_led_t)NULL,
9579 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009580};
9581static struct bnx2x_phy phy_8705 = {
9582 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705,
9583 .addr = 0xff,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009584 .def_md_devad = 0,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00009585 .flags = FLAGS_INIT_XGXS_FIRST,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009586 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
9587 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
9588 .mdio_ctrl = 0,
9589 .supported = (SUPPORTED_10000baseT_Full |
9590 SUPPORTED_FIBRE |
9591 SUPPORTED_Pause |
9592 SUPPORTED_Asym_Pause),
9593 .media_type = ETH_PHY_XFP_FIBER,
9594 .ver_addr = 0,
9595 .req_flow_ctrl = 0,
9596 .req_line_speed = 0,
9597 .speed_cap_mask = 0,
9598 .req_duplex = 0,
9599 .rsrv = 0,
9600 .config_init = (config_init_t)bnx2x_8705_config_init,
9601 .read_status = (read_status_t)bnx2x_8705_read_status,
9602 .link_reset = (link_reset_t)bnx2x_common_ext_link_reset,
9603 .config_loopback = (config_loopback_t)NULL,
9604 .format_fw_ver = (format_fw_ver_t)bnx2x_null_format_ver,
9605 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00009606 .set_link_led = (set_link_led_t)NULL,
9607 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009608};
9609static struct bnx2x_phy phy_8706 = {
9610 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706,
9611 .addr = 0xff,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009612 .def_md_devad = 0,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00009613 .flags = FLAGS_INIT_XGXS_FIRST,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009614 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
9615 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
9616 .mdio_ctrl = 0,
9617 .supported = (SUPPORTED_10000baseT_Full |
9618 SUPPORTED_1000baseT_Full |
9619 SUPPORTED_FIBRE |
9620 SUPPORTED_Pause |
9621 SUPPORTED_Asym_Pause),
9622 .media_type = ETH_PHY_SFP_FIBER,
9623 .ver_addr = 0,
9624 .req_flow_ctrl = 0,
9625 .req_line_speed = 0,
9626 .speed_cap_mask = 0,
9627 .req_duplex = 0,
9628 .rsrv = 0,
9629 .config_init = (config_init_t)bnx2x_8706_config_init,
9630 .read_status = (read_status_t)bnx2x_8706_read_status,
9631 .link_reset = (link_reset_t)bnx2x_common_ext_link_reset,
9632 .config_loopback = (config_loopback_t)NULL,
9633 .format_fw_ver = (format_fw_ver_t)bnx2x_format_ver,
9634 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00009635 .set_link_led = (set_link_led_t)NULL,
9636 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009637};
9638
9639static struct bnx2x_phy phy_8726 = {
9640 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726,
9641 .addr = 0xff,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00009642 .def_md_devad = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009643 .flags = (FLAGS_HW_LOCK_REQUIRED |
9644 FLAGS_INIT_XGXS_FIRST),
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009645 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
9646 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
9647 .mdio_ctrl = 0,
9648 .supported = (SUPPORTED_10000baseT_Full |
9649 SUPPORTED_1000baseT_Full |
9650 SUPPORTED_Autoneg |
9651 SUPPORTED_FIBRE |
9652 SUPPORTED_Pause |
9653 SUPPORTED_Asym_Pause),
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00009654 .media_type = ETH_PHY_NOT_PRESENT,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009655 .ver_addr = 0,
9656 .req_flow_ctrl = 0,
9657 .req_line_speed = 0,
9658 .speed_cap_mask = 0,
9659 .req_duplex = 0,
9660 .rsrv = 0,
9661 .config_init = (config_init_t)bnx2x_8726_config_init,
9662 .read_status = (read_status_t)bnx2x_8726_read_status,
9663 .link_reset = (link_reset_t)bnx2x_8726_link_reset,
9664 .config_loopback = (config_loopback_t)bnx2x_8726_config_loopback,
9665 .format_fw_ver = (format_fw_ver_t)bnx2x_format_ver,
9666 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00009667 .set_link_led = (set_link_led_t)NULL,
9668 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009669};
9670
9671static struct bnx2x_phy phy_8727 = {
9672 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727,
9673 .addr = 0xff,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009674 .def_md_devad = 0,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00009675 .flags = FLAGS_FAN_FAILURE_DET_REQ,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009676 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
9677 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
9678 .mdio_ctrl = 0,
9679 .supported = (SUPPORTED_10000baseT_Full |
9680 SUPPORTED_1000baseT_Full |
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009681 SUPPORTED_FIBRE |
9682 SUPPORTED_Pause |
9683 SUPPORTED_Asym_Pause),
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00009684 .media_type = ETH_PHY_NOT_PRESENT,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009685 .ver_addr = 0,
9686 .req_flow_ctrl = 0,
9687 .req_line_speed = 0,
9688 .speed_cap_mask = 0,
9689 .req_duplex = 0,
9690 .rsrv = 0,
9691 .config_init = (config_init_t)bnx2x_8727_config_init,
9692 .read_status = (read_status_t)bnx2x_8727_read_status,
9693 .link_reset = (link_reset_t)bnx2x_8727_link_reset,
9694 .config_loopback = (config_loopback_t)NULL,
9695 .format_fw_ver = (format_fw_ver_t)bnx2x_format_ver,
9696 .hw_reset = (hw_reset_t)bnx2x_8727_hw_reset,
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00009697 .set_link_led = (set_link_led_t)bnx2x_8727_set_link_led,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00009698 .phy_specific_func = (phy_specific_func_t)bnx2x_8727_specific_func
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009699};
9700static struct bnx2x_phy phy_8481 = {
9701 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8481,
9702 .addr = 0xff,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00009703 .def_md_devad = 0,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00009704 .flags = FLAGS_FAN_FAILURE_DET_REQ |
9705 FLAGS_REARM_LATCH_SIGNAL,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009706 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
9707 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
9708 .mdio_ctrl = 0,
9709 .supported = (SUPPORTED_10baseT_Half |
9710 SUPPORTED_10baseT_Full |
9711 SUPPORTED_100baseT_Half |
9712 SUPPORTED_100baseT_Full |
9713 SUPPORTED_1000baseT_Full |
9714 SUPPORTED_10000baseT_Full |
9715 SUPPORTED_TP |
9716 SUPPORTED_Autoneg |
9717 SUPPORTED_Pause |
9718 SUPPORTED_Asym_Pause),
9719 .media_type = ETH_PHY_BASE_T,
9720 .ver_addr = 0,
9721 .req_flow_ctrl = 0,
9722 .req_line_speed = 0,
9723 .speed_cap_mask = 0,
9724 .req_duplex = 0,
9725 .rsrv = 0,
9726 .config_init = (config_init_t)bnx2x_8481_config_init,
9727 .read_status = (read_status_t)bnx2x_848xx_read_status,
9728 .link_reset = (link_reset_t)bnx2x_8481_link_reset,
9729 .config_loopback = (config_loopback_t)NULL,
9730 .format_fw_ver = (format_fw_ver_t)bnx2x_848xx_format_ver,
9731 .hw_reset = (hw_reset_t)bnx2x_8481_hw_reset,
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00009732 .set_link_led = (set_link_led_t)bnx2x_848xx_set_link_led,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00009733 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009734};
9735
9736static struct bnx2x_phy phy_84823 = {
9737 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84823,
9738 .addr = 0xff,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00009739 .def_md_devad = 0,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00009740 .flags = FLAGS_FAN_FAILURE_DET_REQ |
9741 FLAGS_REARM_LATCH_SIGNAL,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009742 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
9743 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
9744 .mdio_ctrl = 0,
9745 .supported = (SUPPORTED_10baseT_Half |
9746 SUPPORTED_10baseT_Full |
9747 SUPPORTED_100baseT_Half |
9748 SUPPORTED_100baseT_Full |
9749 SUPPORTED_1000baseT_Full |
9750 SUPPORTED_10000baseT_Full |
9751 SUPPORTED_TP |
9752 SUPPORTED_Autoneg |
9753 SUPPORTED_Pause |
9754 SUPPORTED_Asym_Pause),
9755 .media_type = ETH_PHY_BASE_T,
9756 .ver_addr = 0,
9757 .req_flow_ctrl = 0,
9758 .req_line_speed = 0,
9759 .speed_cap_mask = 0,
9760 .req_duplex = 0,
9761 .rsrv = 0,
9762 .config_init = (config_init_t)bnx2x_848x3_config_init,
9763 .read_status = (read_status_t)bnx2x_848xx_read_status,
9764 .link_reset = (link_reset_t)bnx2x_848x3_link_reset,
9765 .config_loopback = (config_loopback_t)NULL,
9766 .format_fw_ver = (format_fw_ver_t)bnx2x_848xx_format_ver,
9767 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00009768 .set_link_led = (set_link_led_t)bnx2x_848xx_set_link_led,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00009769 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009770};
9771
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00009772static struct bnx2x_phy phy_84833 = {
9773 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833,
9774 .addr = 0xff,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00009775 .def_md_devad = 0,
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00009776 .flags = FLAGS_FAN_FAILURE_DET_REQ |
9777 FLAGS_REARM_LATCH_SIGNAL,
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00009778 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
9779 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
9780 .mdio_ctrl = 0,
9781 .supported = (SUPPORTED_10baseT_Half |
9782 SUPPORTED_10baseT_Full |
9783 SUPPORTED_100baseT_Half |
9784 SUPPORTED_100baseT_Full |
9785 SUPPORTED_1000baseT_Full |
9786 SUPPORTED_10000baseT_Full |
9787 SUPPORTED_TP |
9788 SUPPORTED_Autoneg |
9789 SUPPORTED_Pause |
9790 SUPPORTED_Asym_Pause),
9791 .media_type = ETH_PHY_BASE_T,
9792 .ver_addr = 0,
9793 .req_flow_ctrl = 0,
9794 .req_line_speed = 0,
9795 .speed_cap_mask = 0,
9796 .req_duplex = 0,
9797 .rsrv = 0,
9798 .config_init = (config_init_t)bnx2x_848x3_config_init,
9799 .read_status = (read_status_t)bnx2x_848xx_read_status,
9800 .link_reset = (link_reset_t)bnx2x_848x3_link_reset,
9801 .config_loopback = (config_loopback_t)NULL,
9802 .format_fw_ver = (format_fw_ver_t)bnx2x_848xx_format_ver,
9803 .hw_reset = (hw_reset_t)NULL,
9804 .set_link_led = (set_link_led_t)bnx2x_848xx_set_link_led,
9805 .phy_specific_func = (phy_specific_func_t)NULL
9806};
9807
Yaniv Rosner6583e332011-06-14 01:34:17 +00009808static struct bnx2x_phy phy_54616s = {
9809 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54616,
9810 .addr = 0xff,
9811 .def_md_devad = 0,
9812 .flags = FLAGS_INIT_XGXS_FIRST,
9813 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
9814 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
9815 .mdio_ctrl = 0,
9816 .supported = (SUPPORTED_10baseT_Half |
9817 SUPPORTED_10baseT_Full |
9818 SUPPORTED_100baseT_Half |
9819 SUPPORTED_100baseT_Full |
9820 SUPPORTED_1000baseT_Full |
9821 SUPPORTED_TP |
9822 SUPPORTED_Autoneg |
9823 SUPPORTED_Pause |
9824 SUPPORTED_Asym_Pause),
9825 .media_type = ETH_PHY_BASE_T,
9826 .ver_addr = 0,
9827 .req_flow_ctrl = 0,
9828 .req_line_speed = 0,
9829 .speed_cap_mask = 0,
9830 /* req_duplex = */0,
9831 /* rsrv = */0,
9832 .config_init = (config_init_t)bnx2x_54616s_config_init,
9833 .read_status = (read_status_t)bnx2x_54616s_read_status,
9834 .link_reset = (link_reset_t)bnx2x_54616s_link_reset,
9835 .config_loopback = (config_loopback_t)bnx2x_54616s_config_loopback,
9836 .format_fw_ver = (format_fw_ver_t)NULL,
9837 .hw_reset = (hw_reset_t)NULL,
9838 .set_link_led = (set_link_led_t)bnx2x_54616s_set_link_led,
9839 .phy_specific_func = (phy_specific_func_t)NULL
9840};
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009841/*****************************************************************/
9842/* */
9843/* Populate the phy according. Main function: bnx2x_populate_phy */
9844/* */
9845/*****************************************************************/
9846
9847static void bnx2x_populate_preemphasis(struct bnx2x *bp, u32 shmem_base,
9848 struct bnx2x_phy *phy, u8 port,
9849 u8 phy_index)
9850{
9851 /* Get the 4 lanes xgxs config rx and tx */
9852 u32 rx = 0, tx = 0, i;
9853 for (i = 0; i < 2; i++) {
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00009854 /*
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009855 * INT_PHY and EXT_PHY1 share the same value location in the
9856 * shmem. When num_phys is greater than 1, than this value
9857 * applies only to EXT_PHY1
9858 */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00009859 if (phy_index == INT_PHY || phy_index == EXT_PHY1) {
9860 rx = REG_RD(bp, shmem_base +
9861 offsetof(struct shmem_region,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00009862 dev_info.port_hw_config[port].xgxs_config_rx[i<<1]));
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009863
Yaniv Rosnera22f0782010-09-07 11:41:20 +00009864 tx = REG_RD(bp, shmem_base +
9865 offsetof(struct shmem_region,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00009866 dev_info.port_hw_config[port].xgxs_config_tx[i<<1]));
Yaniv Rosnera22f0782010-09-07 11:41:20 +00009867 } else {
9868 rx = REG_RD(bp, shmem_base +
9869 offsetof(struct shmem_region,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00009870 dev_info.port_hw_config[port].xgxs_config2_rx[i<<1]));
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009871
Yaniv Rosnera22f0782010-09-07 11:41:20 +00009872 tx = REG_RD(bp, shmem_base +
9873 offsetof(struct shmem_region,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00009874 dev_info.port_hw_config[port].xgxs_config2_rx[i<<1]));
Yaniv Rosnera22f0782010-09-07 11:41:20 +00009875 }
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009876
9877 phy->rx_preemphasis[i << 1] = ((rx>>16) & 0xffff);
9878 phy->rx_preemphasis[(i << 1) + 1] = (rx & 0xffff);
9879
9880 phy->tx_preemphasis[i << 1] = ((tx>>16) & 0xffff);
9881 phy->tx_preemphasis[(i << 1) + 1] = (tx & 0xffff);
9882 }
9883}
9884
Yaniv Rosnere10bc842010-09-07 11:40:50 +00009885static u32 bnx2x_get_ext_phy_config(struct bnx2x *bp, u32 shmem_base,
9886 u8 phy_index, u8 port)
9887{
9888 u32 ext_phy_config = 0;
9889 switch (phy_index) {
9890 case EXT_PHY1:
9891 ext_phy_config = REG_RD(bp, shmem_base +
9892 offsetof(struct shmem_region,
9893 dev_info.port_hw_config[port].external_phy_config));
9894 break;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00009895 case EXT_PHY2:
9896 ext_phy_config = REG_RD(bp, shmem_base +
9897 offsetof(struct shmem_region,
9898 dev_info.port_hw_config[port].external_phy_config2));
9899 break;
Yaniv Rosnere10bc842010-09-07 11:40:50 +00009900 default:
9901 DP(NETIF_MSG_LINK, "Invalid phy_index %d\n", phy_index);
9902 return -EINVAL;
9903 }
9904
9905 return ext_phy_config;
9906}
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00009907static int bnx2x_populate_int_phy(struct bnx2x *bp, u32 shmem_base, u8 port,
9908 struct bnx2x_phy *phy)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009909{
9910 u32 phy_addr;
9911 u32 chip_id;
9912 u32 switch_cfg = (REG_RD(bp, shmem_base +
9913 offsetof(struct shmem_region,
9914 dev_info.port_feature_config[port].link_config)) &
9915 PORT_FEATURE_CONNECTED_SWITCH_MASK);
9916 chip_id = REG_RD(bp, MISC_REG_CHIP_NUM) << 16;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00009917 DP(NETIF_MSG_LINK, ":chip_id = 0x%x\n", chip_id);
9918 if (USES_WARPCORE(bp)) {
9919 u32 serdes_net_if;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009920 phy_addr = REG_RD(bp,
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00009921 MISC_REG_WC0_CTRL_PHY_ADDR);
9922 *phy = phy_warpcore;
9923 if (REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR) == 0x3)
9924 phy->flags |= FLAGS_4_PORT_MODE;
9925 else
9926 phy->flags &= ~FLAGS_4_PORT_MODE;
9927 /* Check Dual mode */
9928 serdes_net_if = (REG_RD(bp, shmem_base +
9929 offsetof(struct shmem_region, dev_info.
9930 port_hw_config[port].default_cfg)) &
9931 PORT_HW_CFG_NET_SERDES_IF_MASK);
9932 /*
9933 * Set the appropriate supported and flags indications per
9934 * interface type of the chip
9935 */
9936 switch (serdes_net_if) {
9937 case PORT_HW_CFG_NET_SERDES_IF_SGMII:
9938 phy->supported &= (SUPPORTED_10baseT_Half |
9939 SUPPORTED_10baseT_Full |
9940 SUPPORTED_100baseT_Half |
9941 SUPPORTED_100baseT_Full |
9942 SUPPORTED_1000baseT_Full |
9943 SUPPORTED_FIBRE |
9944 SUPPORTED_Autoneg |
9945 SUPPORTED_Pause |
9946 SUPPORTED_Asym_Pause);
9947 phy->media_type = ETH_PHY_BASE_T;
9948 break;
9949 case PORT_HW_CFG_NET_SERDES_IF_XFI:
9950 phy->media_type = ETH_PHY_XFP_FIBER;
9951 break;
9952 case PORT_HW_CFG_NET_SERDES_IF_SFI:
9953 phy->supported &= (SUPPORTED_1000baseT_Full |
9954 SUPPORTED_10000baseT_Full |
9955 SUPPORTED_FIBRE |
9956 SUPPORTED_Pause |
9957 SUPPORTED_Asym_Pause);
9958 phy->media_type = ETH_PHY_SFP_FIBER;
9959 break;
9960 case PORT_HW_CFG_NET_SERDES_IF_KR:
9961 phy->media_type = ETH_PHY_KR;
9962 phy->supported &= (SUPPORTED_1000baseT_Full |
9963 SUPPORTED_10000baseT_Full |
9964 SUPPORTED_FIBRE |
9965 SUPPORTED_Autoneg |
9966 SUPPORTED_Pause |
9967 SUPPORTED_Asym_Pause);
9968 break;
9969 case PORT_HW_CFG_NET_SERDES_IF_DXGXS:
9970 phy->media_type = ETH_PHY_KR;
9971 phy->flags |= FLAGS_WC_DUAL_MODE;
9972 phy->supported &= (SUPPORTED_20000baseMLD2_Full |
9973 SUPPORTED_FIBRE |
9974 SUPPORTED_Pause |
9975 SUPPORTED_Asym_Pause);
9976 break;
9977 case PORT_HW_CFG_NET_SERDES_IF_KR2:
9978 phy->media_type = ETH_PHY_KR;
9979 phy->flags |= FLAGS_WC_DUAL_MODE;
9980 phy->supported &= (SUPPORTED_20000baseKR2_Full |
9981 SUPPORTED_FIBRE |
9982 SUPPORTED_Pause |
9983 SUPPORTED_Asym_Pause);
9984 break;
9985 default:
9986 DP(NETIF_MSG_LINK, "Unknown WC interface type 0x%x\n",
9987 serdes_net_if);
9988 break;
9989 }
9990
9991 /*
9992 * Enable MDC/MDIO work-around for E3 A0 since free running MDC
9993 * was not set as expected. For B0, ECO will be enabled so there
9994 * won't be an issue there
9995 */
9996 if (CHIP_REV(bp) == CHIP_REV_Ax)
9997 phy->flags |= FLAGS_MDC_MDIO_WA;
9998 } else {
9999 switch (switch_cfg) {
10000 case SWITCH_CFG_1G:
10001 phy_addr = REG_RD(bp,
10002 NIG_REG_SERDES0_CTRL_PHY_ADDR +
10003 port * 0x10);
10004 *phy = phy_serdes;
10005 break;
10006 case SWITCH_CFG_10G:
10007 phy_addr = REG_RD(bp,
10008 NIG_REG_XGXS0_CTRL_PHY_ADDR +
10009 port * 0x18);
10010 *phy = phy_xgxs;
10011 break;
10012 default:
10013 DP(NETIF_MSG_LINK, "Invalid switch_cfg\n");
10014 return -EINVAL;
10015 }
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010016 }
10017 phy->addr = (u8)phy_addr;
10018 phy->mdio_ctrl = bnx2x_get_emac_base(bp,
Yaniv Rosnerc18aa152010-09-07 11:41:07 +000010019 SHARED_HW_CFG_MDC_MDIO_ACCESS1_BOTH,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010020 port);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010021 if (CHIP_IS_E2(bp))
10022 phy->def_md_devad = E2_DEFAULT_PHY_DEV_ADDR;
10023 else
10024 phy->def_md_devad = DEFAULT_PHY_DEV_ADDR;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010025
10026 DP(NETIF_MSG_LINK, "Internal phy port=%d, addr=0x%x, mdio_ctl=0x%x\n",
10027 port, phy->addr, phy->mdio_ctrl);
10028
10029 bnx2x_populate_preemphasis(bp, shmem_base, phy, port, INT_PHY);
10030 return 0;
10031}
Yaniv Rosnere10bc842010-09-07 11:40:50 +000010032
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000010033static int bnx2x_populate_ext_phy(struct bnx2x *bp,
10034 u8 phy_index,
10035 u32 shmem_base,
10036 u32 shmem2_base,
10037 u8 port,
10038 struct bnx2x_phy *phy)
Yaniv Rosnere10bc842010-09-07 11:40:50 +000010039{
Yaniv Rosnerc18aa152010-09-07 11:41:07 +000010040 u32 ext_phy_config, phy_type, config2;
10041 u32 mdc_mdio_access = SHARED_HW_CFG_MDC_MDIO_ACCESS1_BOTH;
Yaniv Rosnere10bc842010-09-07 11:40:50 +000010042 ext_phy_config = bnx2x_get_ext_phy_config(bp, shmem_base,
10043 phy_index, port);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010044 phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
10045 /* Select the phy type */
10046 switch (phy_type) {
10047 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073:
Yaniv Rosnerc18aa152010-09-07 11:41:07 +000010048 mdc_mdio_access = SHARED_HW_CFG_MDC_MDIO_ACCESS1_SWAPPED;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010049 *phy = phy_8073;
10050 break;
10051 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705:
10052 *phy = phy_8705;
10053 break;
10054 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706:
10055 *phy = phy_8706;
10056 break;
10057 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
Yaniv Rosnerc18aa152010-09-07 11:41:07 +000010058 mdc_mdio_access = SHARED_HW_CFG_MDC_MDIO_ACCESS1_EMAC1;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010059 *phy = phy_8726;
10060 break;
10061 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727_NOC:
10062 /* BCM8727_NOC => BCM8727 no over current */
Yaniv Rosnerc18aa152010-09-07 11:41:07 +000010063 mdc_mdio_access = SHARED_HW_CFG_MDC_MDIO_ACCESS1_EMAC1;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010064 *phy = phy_8727;
10065 phy->flags |= FLAGS_NOC;
10066 break;
Yaniv Rosnere4d78f12011-05-31 21:25:55 +000010067 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8722:
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010068 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
Yaniv Rosnerc18aa152010-09-07 11:41:07 +000010069 mdc_mdio_access = SHARED_HW_CFG_MDC_MDIO_ACCESS1_EMAC1;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010070 *phy = phy_8727;
10071 break;
10072 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8481:
10073 *phy = phy_8481;
10074 break;
10075 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84823:
10076 *phy = phy_84823;
10077 break;
Yaniv Rosnerc87bca12011-01-31 04:22:41 +000010078 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833:
10079 *phy = phy_84833;
10080 break;
Yaniv Rosner6583e332011-06-14 01:34:17 +000010081 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54616:
10082 *phy = phy_54616s;
10083 break;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010084 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101:
10085 *phy = phy_7101;
10086 break;
10087 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE:
10088 *phy = phy_null;
10089 return -EINVAL;
10090 default:
10091 *phy = phy_null;
10092 return 0;
10093 }
10094
Yaniv Rosnere10bc842010-09-07 11:40:50 +000010095 phy->addr = XGXS_EXT_PHY_ADDR(ext_phy_config);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010096 bnx2x_populate_preemphasis(bp, shmem_base, phy, port, phy_index);
Yaniv Rosner62b29a52010-09-07 11:40:58 +000010097
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +000010098 /*
10099 * The shmem address of the phy version is located on different
10100 * structures. In case this structure is too old, do not set
10101 * the address
10102 */
Yaniv Rosnerc18aa152010-09-07 11:41:07 +000010103 config2 = REG_RD(bp, shmem_base + offsetof(struct shmem_region,
10104 dev_info.shared_hw_config.config2));
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010105 if (phy_index == EXT_PHY1) {
10106 phy->ver_addr = shmem_base + offsetof(struct shmem_region,
10107 port_mb[port].ext_phy_fw_version);
Yaniv Rosnerc18aa152010-09-07 11:41:07 +000010108
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010109 /* Check specific mdc mdio settings */
10110 if (config2 & SHARED_HW_CFG_MDC_MDIO_ACCESS1_MASK)
10111 mdc_mdio_access = config2 &
10112 SHARED_HW_CFG_MDC_MDIO_ACCESS1_MASK;
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010113 } else {
10114 u32 size = REG_RD(bp, shmem2_base);
Yaniv Rosnerc18aa152010-09-07 11:41:07 +000010115
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010116 if (size >
10117 offsetof(struct shmem2_region, ext_phy_fw_version2)) {
10118 phy->ver_addr = shmem2_base +
10119 offsetof(struct shmem2_region,
10120 ext_phy_fw_version2[port]);
10121 }
10122 /* Check specific mdc mdio settings */
10123 if (config2 & SHARED_HW_CFG_MDC_MDIO_ACCESS2_MASK)
10124 mdc_mdio_access = (config2 &
10125 SHARED_HW_CFG_MDC_MDIO_ACCESS2_MASK) >>
10126 (SHARED_HW_CFG_MDC_MDIO_ACCESS2_SHIFT -
10127 SHARED_HW_CFG_MDC_MDIO_ACCESS1_SHIFT);
10128 }
Yaniv Rosnerc18aa152010-09-07 11:41:07 +000010129 phy->mdio_ctrl = bnx2x_get_emac_base(bp, mdc_mdio_access, port);
10130
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +000010131 /*
Yaniv Rosnerc18aa152010-09-07 11:41:07 +000010132 * In case mdc/mdio_access of the external phy is different than the
10133 * mdc/mdio access of the XGXS, a HW lock must be taken in each access
10134 * to prevent one port interfere with another port's CL45 operations.
10135 */
10136 if (mdc_mdio_access != SHARED_HW_CFG_MDC_MDIO_ACCESS1_BOTH)
10137 phy->flags |= FLAGS_HW_LOCK_REQUIRED;
10138 DP(NETIF_MSG_LINK, "phy_type 0x%x port %d found in index %d\n",
10139 phy_type, port, phy_index);
10140 DP(NETIF_MSG_LINK, " addr=0x%x, mdio_ctl=0x%x\n",
10141 phy->addr, phy->mdio_ctrl);
Yaniv Rosnere10bc842010-09-07 11:40:50 +000010142 return 0;
10143}
10144
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000010145static int bnx2x_populate_phy(struct bnx2x *bp, u8 phy_index, u32 shmem_base,
10146 u32 shmem2_base, u8 port, struct bnx2x_phy *phy)
Yaniv Rosnere10bc842010-09-07 11:40:50 +000010147{
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000010148 int status = 0;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010149 phy->type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN;
10150 if (phy_index == INT_PHY)
10151 return bnx2x_populate_int_phy(bp, shmem_base, port, phy);
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010152 status = bnx2x_populate_ext_phy(bp, phy_index, shmem_base, shmem2_base,
Yaniv Rosnere10bc842010-09-07 11:40:50 +000010153 port, phy);
10154 return status;
10155}
10156
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010157static void bnx2x_phy_def_cfg(struct link_params *params,
10158 struct bnx2x_phy *phy,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010159 u8 phy_index)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010160{
10161 struct bnx2x *bp = params->bp;
10162 u32 link_config;
10163 /* Populate the default phy configuration for MF mode */
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010164 if (phy_index == EXT_PHY2) {
10165 link_config = REG_RD(bp, params->shmem_base +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010166 offsetof(struct shmem_region, dev_info.
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010167 port_feature_config[params->port].link_config2));
10168 phy->speed_cap_mask = REG_RD(bp, params->shmem_base +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010169 offsetof(struct shmem_region,
10170 dev_info.
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010171 port_hw_config[params->port].speed_capability_mask2));
10172 } else {
10173 link_config = REG_RD(bp, params->shmem_base +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010174 offsetof(struct shmem_region, dev_info.
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010175 port_feature_config[params->port].link_config));
10176 phy->speed_cap_mask = REG_RD(bp, params->shmem_base +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010177 offsetof(struct shmem_region,
10178 dev_info.
10179 port_hw_config[params->port].speed_capability_mask));
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010180 }
10181 DP(NETIF_MSG_LINK, "Default config phy idx %x cfg 0x%x speed_cap_mask"
10182 " 0x%x\n", phy_index, link_config, phy->speed_cap_mask);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010183
10184 phy->req_duplex = DUPLEX_FULL;
10185 switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
10186 case PORT_FEATURE_LINK_SPEED_10M_HALF:
10187 phy->req_duplex = DUPLEX_HALF;
10188 case PORT_FEATURE_LINK_SPEED_10M_FULL:
10189 phy->req_line_speed = SPEED_10;
10190 break;
10191 case PORT_FEATURE_LINK_SPEED_100M_HALF:
10192 phy->req_duplex = DUPLEX_HALF;
10193 case PORT_FEATURE_LINK_SPEED_100M_FULL:
10194 phy->req_line_speed = SPEED_100;
10195 break;
10196 case PORT_FEATURE_LINK_SPEED_1G:
10197 phy->req_line_speed = SPEED_1000;
10198 break;
10199 case PORT_FEATURE_LINK_SPEED_2_5G:
10200 phy->req_line_speed = SPEED_2500;
10201 break;
10202 case PORT_FEATURE_LINK_SPEED_10G_CX4:
10203 phy->req_line_speed = SPEED_10000;
10204 break;
10205 default:
10206 phy->req_line_speed = SPEED_AUTO_NEG;
10207 break;
10208 }
10209
10210 switch (link_config & PORT_FEATURE_FLOW_CONTROL_MASK) {
10211 case PORT_FEATURE_FLOW_CONTROL_AUTO:
10212 phy->req_flow_ctrl = BNX2X_FLOW_CTRL_AUTO;
10213 break;
10214 case PORT_FEATURE_FLOW_CONTROL_TX:
10215 phy->req_flow_ctrl = BNX2X_FLOW_CTRL_TX;
10216 break;
10217 case PORT_FEATURE_FLOW_CONTROL_RX:
10218 phy->req_flow_ctrl = BNX2X_FLOW_CTRL_RX;
10219 break;
10220 case PORT_FEATURE_FLOW_CONTROL_BOTH:
10221 phy->req_flow_ctrl = BNX2X_FLOW_CTRL_BOTH;
10222 break;
10223 default:
10224 phy->req_flow_ctrl = BNX2X_FLOW_CTRL_NONE;
10225 break;
10226 }
10227}
10228
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010229u32 bnx2x_phy_selection(struct link_params *params)
10230{
10231 u32 phy_config_swapped, prio_cfg;
10232 u32 return_cfg = PORT_HW_CFG_PHY_SELECTION_HARDWARE_DEFAULT;
10233
10234 phy_config_swapped = params->multi_phy_config &
10235 PORT_HW_CFG_PHY_SWAPPED_ENABLED;
10236
10237 prio_cfg = params->multi_phy_config &
10238 PORT_HW_CFG_PHY_SELECTION_MASK;
10239
10240 if (phy_config_swapped) {
10241 switch (prio_cfg) {
10242 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY_PRIORITY:
10243 return_cfg = PORT_HW_CFG_PHY_SELECTION_SECOND_PHY_PRIORITY;
10244 break;
10245 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY_PRIORITY:
10246 return_cfg = PORT_HW_CFG_PHY_SELECTION_FIRST_PHY_PRIORITY;
10247 break;
10248 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY:
10249 return_cfg = PORT_HW_CFG_PHY_SELECTION_FIRST_PHY;
10250 break;
10251 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY:
10252 return_cfg = PORT_HW_CFG_PHY_SELECTION_SECOND_PHY;
10253 break;
10254 }
10255 } else
10256 return_cfg = prio_cfg;
10257
10258 return return_cfg;
10259}
10260
10261
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000010262int bnx2x_phy_probe(struct link_params *params)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010263{
10264 u8 phy_index, actual_phy_idx, link_cfg_idx;
Yaniv Rosner1ac9e422011-05-31 21:26:11 +000010265 u32 phy_config_swapped, sync_offset, media_types;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010266 struct bnx2x *bp = params->bp;
10267 struct bnx2x_phy *phy;
10268 params->num_phys = 0;
10269 DP(NETIF_MSG_LINK, "Begin phy probe\n");
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010270 phy_config_swapped = params->multi_phy_config &
10271 PORT_HW_CFG_PHY_SWAPPED_ENABLED;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010272
10273 for (phy_index = INT_PHY; phy_index < MAX_PHYS;
10274 phy_index++) {
10275 link_cfg_idx = LINK_CONFIG_IDX(phy_index);
10276 actual_phy_idx = phy_index;
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010277 if (phy_config_swapped) {
10278 if (phy_index == EXT_PHY1)
10279 actual_phy_idx = EXT_PHY2;
10280 else if (phy_index == EXT_PHY2)
10281 actual_phy_idx = EXT_PHY1;
10282 }
10283 DP(NETIF_MSG_LINK, "phy_config_swapped %x, phy_index %x,"
10284 " actual_phy_idx %x\n", phy_config_swapped,
10285 phy_index, actual_phy_idx);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010286 phy = &params->phy[actual_phy_idx];
10287 if (bnx2x_populate_phy(bp, phy_index, params->shmem_base,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010288 params->shmem2_base, params->port,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010289 phy) != 0) {
10290 params->num_phys = 0;
10291 DP(NETIF_MSG_LINK, "phy probe failed in phy index %d\n",
10292 phy_index);
10293 for (phy_index = INT_PHY;
10294 phy_index < MAX_PHYS;
10295 phy_index++)
10296 *phy = phy_null;
10297 return -EINVAL;
10298 }
10299 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN)
10300 break;
10301
Yaniv Rosner1ac9e422011-05-31 21:26:11 +000010302 sync_offset = params->shmem_base +
10303 offsetof(struct shmem_region,
10304 dev_info.port_hw_config[params->port].media_type);
10305 media_types = REG_RD(bp, sync_offset);
10306
10307 /*
10308 * Update media type for non-PMF sync only for the first time
10309 * In case the media type changes afterwards, it will be updated
10310 * using the update_status function
10311 */
10312 if ((media_types & (PORT_HW_CFG_MEDIA_TYPE_PHY0_MASK <<
10313 (PORT_HW_CFG_MEDIA_TYPE_PHY1_SHIFT *
10314 actual_phy_idx))) == 0) {
10315 media_types |= ((phy->media_type &
10316 PORT_HW_CFG_MEDIA_TYPE_PHY0_MASK) <<
10317 (PORT_HW_CFG_MEDIA_TYPE_PHY1_SHIFT *
10318 actual_phy_idx));
10319 }
10320 REG_WR(bp, sync_offset, media_types);
10321
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010322 bnx2x_phy_def_cfg(params, phy, phy_index);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010323 params->num_phys++;
10324 }
10325
10326 DP(NETIF_MSG_LINK, "End phy probe. #phys found %x\n", params->num_phys);
10327 return 0;
10328}
10329
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000010330void bnx2x_init_bmac_loopback(struct link_params *params,
10331 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010332{
10333 struct bnx2x *bp = params->bp;
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000010334 vars->link_up = 1;
10335 vars->line_speed = SPEED_10000;
10336 vars->duplex = DUPLEX_FULL;
10337 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
10338 vars->mac_type = MAC_TYPE_BMAC;
10339
10340 vars->phy_flags = PHY_XGXS_FLAG;
10341
10342 bnx2x_xgxs_deassert(params);
10343
10344 /* set bmac loopback */
10345 bnx2x_bmac_enable(params, vars, 1);
10346
10347 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 0);
10348}
10349
10350void bnx2x_init_emac_loopback(struct link_params *params,
10351 struct link_vars *vars)
10352{
10353 struct bnx2x *bp = params->bp;
10354 vars->link_up = 1;
10355 vars->line_speed = SPEED_1000;
10356 vars->duplex = DUPLEX_FULL;
10357 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
10358 vars->mac_type = MAC_TYPE_EMAC;
10359
10360 vars->phy_flags = PHY_XGXS_FLAG;
10361
10362 bnx2x_xgxs_deassert(params);
10363 /* set bmac loopback */
10364 bnx2x_emac_enable(params, vars, 1);
10365 bnx2x_emac_program(params, vars);
10366 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 0);
10367}
10368
Yaniv Rosner9380bb92011-06-14 01:34:07 +000010369void bnx2x_init_xmac_loopback(struct link_params *params,
10370 struct link_vars *vars)
10371{
10372 struct bnx2x *bp = params->bp;
10373 vars->link_up = 1;
10374 if (!params->req_line_speed[0])
10375 vars->line_speed = SPEED_10000;
10376 else
10377 vars->line_speed = params->req_line_speed[0];
10378 vars->duplex = DUPLEX_FULL;
10379 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
10380 vars->mac_type = MAC_TYPE_XMAC;
10381 vars->phy_flags = PHY_XGXS_FLAG;
10382 /*
10383 * Set WC to loopback mode since link is required to provide clock
10384 * to the XMAC in 20G mode
10385 */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000010386 if (vars->line_speed == SPEED_20000) {
10387 bnx2x_set_aer_mmd(params, &params->phy[0]);
10388 bnx2x_warpcore_reset_lane(bp, &params->phy[0], 0);
10389 params->phy[INT_PHY].config_loopback(
10390 &params->phy[INT_PHY],
10391 params);
10392 }
Yaniv Rosner9380bb92011-06-14 01:34:07 +000010393 bnx2x_xmac_enable(params, vars, 1);
10394 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 0);
10395}
10396
10397void bnx2x_init_umac_loopback(struct link_params *params,
10398 struct link_vars *vars)
10399{
10400 struct bnx2x *bp = params->bp;
10401 vars->link_up = 1;
10402 vars->line_speed = SPEED_1000;
10403 vars->duplex = DUPLEX_FULL;
10404 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
10405 vars->mac_type = MAC_TYPE_UMAC;
10406 vars->phy_flags = PHY_XGXS_FLAG;
10407 bnx2x_umac_enable(params, vars, 1);
10408
10409 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 0);
10410}
10411
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000010412void bnx2x_init_xgxs_loopback(struct link_params *params,
10413 struct link_vars *vars)
10414{
10415 struct bnx2x *bp = params->bp;
10416 vars->link_up = 1;
10417 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
10418 vars->duplex = DUPLEX_FULL;
10419 if (params->req_line_speed[0] == SPEED_1000)
10420 vars->line_speed = SPEED_1000;
10421 else
10422 vars->line_speed = SPEED_10000;
10423
Yaniv Rosner9380bb92011-06-14 01:34:07 +000010424 if (!USES_WARPCORE(bp))
10425 bnx2x_xgxs_deassert(params);
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000010426 bnx2x_link_initialize(params, vars);
10427
10428 if (params->req_line_speed[0] == SPEED_1000) {
Yaniv Rosner9380bb92011-06-14 01:34:07 +000010429 if (USES_WARPCORE(bp))
10430 bnx2x_umac_enable(params, vars, 0);
10431 else {
10432 bnx2x_emac_program(params, vars);
10433 bnx2x_emac_enable(params, vars, 0);
10434 }
10435 } else {
10436 if (USES_WARPCORE(bp))
10437 bnx2x_xmac_enable(params, vars, 0);
10438 else
10439 bnx2x_bmac_enable(params, vars, 0);
10440 }
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000010441
10442 if (params->loopback_mode == LOOPBACK_XGXS) {
10443 /* set 10G XGXS loopback */
10444 params->phy[INT_PHY].config_loopback(
10445 &params->phy[INT_PHY],
10446 params);
10447
10448 } else {
10449 /* set external phy loopback */
10450 u8 phy_index;
10451 for (phy_index = EXT_PHY1;
10452 phy_index < params->num_phys; phy_index++) {
10453 if (params->phy[phy_index].config_loopback)
10454 params->phy[phy_index].config_loopback(
10455 &params->phy[phy_index],
10456 params);
10457 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010458 }
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000010459 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010460
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000010461 bnx2x_set_led(params, vars, LED_MODE_OPER, vars->line_speed);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010462}
10463
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000010464int bnx2x_phy_init(struct link_params *params, struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010465{
10466 struct bnx2x *bp = params->bp;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010467 DP(NETIF_MSG_LINK, "Phy Initialization started\n");
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010468 DP(NETIF_MSG_LINK, "(1) req_speed %d, req_flowctrl %d\n",
10469 params->req_line_speed[0], params->req_flow_ctrl[0]);
10470 DP(NETIF_MSG_LINK, "(2) req_speed %d, req_flowctrl %d\n",
10471 params->req_line_speed[1], params->req_flow_ctrl[1]);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010472 vars->link_status = 0;
10473 vars->phy_link_up = 0;
10474 vars->link_up = 0;
10475 vars->line_speed = 0;
10476 vars->duplex = DUPLEX_FULL;
10477 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
10478 vars->mac_type = MAC_TYPE_NONE;
10479 vars->phy_flags = 0;
10480
10481 /* disable attentions */
10482 bnx2x_bits_dis(bp, NIG_REG_MASK_INTERRUPT_PORT0 + params->port*4,
10483 (NIG_MASK_XGXS0_LINK_STATUS |
10484 NIG_MASK_XGXS0_LINK10G |
10485 NIG_MASK_SERDES0_LINK_STATUS |
10486 NIG_MASK_MI_INT));
10487
10488 bnx2x_emac_init(params, vars);
10489
10490 if (params->num_phys == 0) {
10491 DP(NETIF_MSG_LINK, "No phy found for initialization !!\n");
10492 return -EINVAL;
10493 }
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000010494 set_phy_vars(params, vars);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010495
10496 DP(NETIF_MSG_LINK, "Num of phys on board: %d\n", params->num_phys);
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000010497 switch (params->loopback_mode) {
10498 case LOOPBACK_BMAC:
10499 bnx2x_init_bmac_loopback(params, vars);
10500 break;
10501 case LOOPBACK_EMAC:
10502 bnx2x_init_emac_loopback(params, vars);
10503 break;
Yaniv Rosner9380bb92011-06-14 01:34:07 +000010504 case LOOPBACK_XMAC:
10505 bnx2x_init_xmac_loopback(params, vars);
10506 break;
10507 case LOOPBACK_UMAC:
10508 bnx2x_init_umac_loopback(params, vars);
10509 break;
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000010510 case LOOPBACK_XGXS:
10511 case LOOPBACK_EXT_PHY:
10512 bnx2x_init_xgxs_loopback(params, vars);
10513 break;
10514 default:
Yaniv Rosner9380bb92011-06-14 01:34:07 +000010515 if (!CHIP_IS_E3(bp)) {
10516 if (params->switch_cfg == SWITCH_CFG_10G)
10517 bnx2x_xgxs_deassert(params);
10518 else
10519 bnx2x_serdes_deassert(bp, params->port);
10520 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010521 bnx2x_link_initialize(params, vars);
10522 msleep(30);
10523 bnx2x_link_int_enable(params);
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000010524 break;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010525 }
10526 return 0;
10527}
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000010528
10529int bnx2x_link_reset(struct link_params *params, struct link_vars *vars,
10530 u8 reset_ext_phy)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010531{
10532 struct bnx2x *bp = params->bp;
Yaniv Rosnercf1d9722010-11-01 05:32:34 +000010533 u8 phy_index, port = params->port, clear_latch_ind = 0;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010534 DP(NETIF_MSG_LINK, "Resetting the link of port %d\n", port);
10535 /* disable attentions */
10536 vars->link_status = 0;
10537 bnx2x_update_mng(params, vars->link_status);
10538 bnx2x_bits_dis(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010539 (NIG_MASK_XGXS0_LINK_STATUS |
10540 NIG_MASK_XGXS0_LINK10G |
10541 NIG_MASK_SERDES0_LINK_STATUS |
10542 NIG_MASK_MI_INT));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010543
10544 /* activate nig drain */
10545 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + port*4, 1);
10546
10547 /* disable nig egress interface */
Yaniv Rosner9380bb92011-06-14 01:34:07 +000010548 if (!CHIP_IS_E3(bp)) {
10549 REG_WR(bp, NIG_REG_BMAC0_OUT_EN + port*4, 0);
10550 REG_WR(bp, NIG_REG_EGRESS_EMAC0_OUT_EN + port*4, 0);
10551 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010552
10553 /* Stop BigMac rx */
Yaniv Rosner9380bb92011-06-14 01:34:07 +000010554 if (!CHIP_IS_E3(bp))
10555 bnx2x_bmac_rx_disable(bp, port);
10556 else
10557 bnx2x_xmac_disable(params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010558 /* disable emac */
Yaniv Rosner9380bb92011-06-14 01:34:07 +000010559 if (!CHIP_IS_E3(bp))
10560 REG_WR(bp, NIG_REG_NIG_EMAC0_EN + port*4, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010561
10562 msleep(10);
Lucas De Marchi25985ed2011-03-30 22:57:33 -030010563 /* The PHY reset is controlled by GPIO 1
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010564 * Hold it as vars low
10565 */
10566 /* clear link led */
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010567 bnx2x_set_led(params, vars, LED_MODE_OFF, 0);
10568
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010569 if (reset_ext_phy) {
10570 for (phy_index = EXT_PHY1; phy_index < params->num_phys;
10571 phy_index++) {
10572 if (params->phy[phy_index].link_reset)
10573 params->phy[phy_index].link_reset(
10574 &params->phy[phy_index],
10575 params);
Yaniv Rosnercf1d9722010-11-01 05:32:34 +000010576 if (params->phy[phy_index].flags &
10577 FLAGS_REARM_LATCH_SIGNAL)
10578 clear_latch_ind = 1;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010579 }
10580 }
10581
Yaniv Rosnercf1d9722010-11-01 05:32:34 +000010582 if (clear_latch_ind) {
10583 /* Clear latching indication */
10584 bnx2x_rearm_latch_signal(bp, port, 0);
10585 bnx2x_bits_dis(bp, NIG_REG_LATCH_BC_0 + port*4,
10586 1 << NIG_LATCH_BC_ENABLE_MI_INT);
10587 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010588 if (params->phy[INT_PHY].link_reset)
10589 params->phy[INT_PHY].link_reset(
10590 &params->phy[INT_PHY], params);
10591 /* reset BigMac */
10592 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
10593 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port));
10594
10595 /* disable nig ingress interface */
Yaniv Rosner9380bb92011-06-14 01:34:07 +000010596 if (!CHIP_IS_E3(bp)) {
10597 REG_WR(bp, NIG_REG_BMAC0_IN_EN + port*4, 0);
10598 REG_WR(bp, NIG_REG_EMAC0_IN_EN + port*4, 0);
10599 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010600 vars->link_up = 0;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000010601 vars->phy_flags = 0;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010602 return 0;
10603}
10604
10605/****************************************************************************/
10606/* Common function */
10607/****************************************************************************/
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000010608static int bnx2x_8073_common_init_phy(struct bnx2x *bp,
10609 u32 shmem_base_path[],
10610 u32 shmem2_base_path[], u8 phy_index,
10611 u32 chip_id)
Yaniv Rosner6bbca912008-08-13 15:57:28 -070010612{
Yaniv Rosnere10bc842010-09-07 11:40:50 +000010613 struct bnx2x_phy phy[PORT_MAX];
10614 struct bnx2x_phy *phy_blk[PORT_MAX];
Yaniv Rosner6bbca912008-08-13 15:57:28 -070010615 u16 val;
Yaniv Rosnerc8e64df2011-01-30 04:15:00 +000010616 s8 port = 0;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010617 s8 port_of_path = 0;
Yaniv Rosnerc8e64df2011-01-30 04:15:00 +000010618 u32 swap_val, swap_override;
10619 swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
10620 swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
10621 port ^= (swap_val && swap_override);
10622 bnx2x_ext_phy_hw_reset(bp, port);
Yaniv Rosner6bbca912008-08-13 15:57:28 -070010623 /* PART1 - Reset both phys */
10624 for (port = PORT_MAX - 1; port >= PORT_0; port--) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010625 u32 shmem_base, shmem2_base;
10626 /* In E2, same phy is using for port0 of the two paths */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000010627 if (CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010628 shmem_base = shmem_base_path[0];
10629 shmem2_base = shmem2_base_path[0];
10630 port_of_path = port;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000010631 } else {
10632 shmem_base = shmem_base_path[port];
10633 shmem2_base = shmem2_base_path[port];
10634 port_of_path = 0;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010635 }
10636
Yaniv Rosner6bbca912008-08-13 15:57:28 -070010637 /* Extract the ext phy address for the port */
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010638 if (bnx2x_populate_phy(bp, phy_index, shmem_base, shmem2_base,
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010639 port_of_path, &phy[port]) !=
Yaniv Rosnere10bc842010-09-07 11:40:50 +000010640 0) {
10641 DP(NETIF_MSG_LINK, "populate_phy failed\n");
10642 return -EINVAL;
10643 }
Yaniv Rosner6bbca912008-08-13 15:57:28 -070010644 /* disable attentions */
Yaniv Rosner6a71bbe2010-11-01 05:32:31 +000010645 bnx2x_bits_dis(bp, NIG_REG_MASK_INTERRUPT_PORT0 +
10646 port_of_path*4,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010647 (NIG_MASK_XGXS0_LINK_STATUS |
10648 NIG_MASK_XGXS0_LINK10G |
10649 NIG_MASK_SERDES0_LINK_STATUS |
10650 NIG_MASK_MI_INT));
Yaniv Rosner6bbca912008-08-13 15:57:28 -070010651
Yaniv Rosner6bbca912008-08-13 15:57:28 -070010652 /* Need to take the phy out of low power mode in order
10653 to write to access its registers */
10654 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010655 MISC_REGISTERS_GPIO_OUTPUT_HIGH,
10656 port);
Yaniv Rosner6bbca912008-08-13 15:57:28 -070010657
10658 /* Reset the phy */
Yaniv Rosnere10bc842010-09-07 11:40:50 +000010659 bnx2x_cl45_write(bp, &phy[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010660 MDIO_PMA_DEVAD,
10661 MDIO_PMA_REG_CTRL,
10662 1<<15);
Yaniv Rosner6bbca912008-08-13 15:57:28 -070010663 }
10664
10665 /* Add delay of 150ms after reset */
10666 msleep(150);
10667
Yaniv Rosnere10bc842010-09-07 11:40:50 +000010668 if (phy[PORT_0].addr & 0x1) {
10669 phy_blk[PORT_0] = &(phy[PORT_1]);
10670 phy_blk[PORT_1] = &(phy[PORT_0]);
10671 } else {
10672 phy_blk[PORT_0] = &(phy[PORT_0]);
10673 phy_blk[PORT_1] = &(phy[PORT_1]);
10674 }
10675
Yaniv Rosner6bbca912008-08-13 15:57:28 -070010676 /* PART2 - Download firmware to both phys */
10677 for (port = PORT_MAX - 1; port >= PORT_0; port--) {
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000010678 if (CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010679 port_of_path = port;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000010680 else
10681 port_of_path = 0;
Yaniv Rosner6bbca912008-08-13 15:57:28 -070010682
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010683 DP(NETIF_MSG_LINK, "Loading spirom for phy address 0x%x\n",
10684 phy_blk[port]->addr);
Yaniv Rosner5c99274b2011-01-18 04:33:36 +000010685 if (bnx2x_8073_8727_external_rom_boot(bp, phy_blk[port],
10686 port_of_path))
Yaniv Rosner6bbca912008-08-13 15:57:28 -070010687 return -EINVAL;
Yaniv Rosner6bbca912008-08-13 15:57:28 -070010688
10689 /* Only set bit 10 = 1 (Tx power down) */
Yaniv Rosnere10bc842010-09-07 11:40:50 +000010690 bnx2x_cl45_read(bp, phy_blk[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010691 MDIO_PMA_DEVAD,
10692 MDIO_PMA_REG_TX_POWER_DOWN, &val);
Yaniv Rosner6bbca912008-08-13 15:57:28 -070010693
10694 /* Phase1 of TX_POWER_DOWN reset */
Yaniv Rosnere10bc842010-09-07 11:40:50 +000010695 bnx2x_cl45_write(bp, phy_blk[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010696 MDIO_PMA_DEVAD,
10697 MDIO_PMA_REG_TX_POWER_DOWN,
10698 (val | 1<<10));
Yaniv Rosner6bbca912008-08-13 15:57:28 -070010699 }
10700
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +000010701 /*
10702 * Toggle Transmitter: Power down and then up with 600ms delay
10703 * between
10704 */
Yaniv Rosner6bbca912008-08-13 15:57:28 -070010705 msleep(600);
10706
10707 /* PART3 - complete TX_POWER_DOWN process, and set GPIO2 back to low */
10708 for (port = PORT_MAX - 1; port >= PORT_0; port--) {
Eilon Greensteinf5372252009-02-12 08:38:30 +000010709 /* Phase2 of POWER_DOWN_RESET */
Yaniv Rosner6bbca912008-08-13 15:57:28 -070010710 /* Release bit 10 (Release Tx power down) */
Yaniv Rosnere10bc842010-09-07 11:40:50 +000010711 bnx2x_cl45_read(bp, phy_blk[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010712 MDIO_PMA_DEVAD,
10713 MDIO_PMA_REG_TX_POWER_DOWN, &val);
Yaniv Rosner6bbca912008-08-13 15:57:28 -070010714
Yaniv Rosnere10bc842010-09-07 11:40:50 +000010715 bnx2x_cl45_write(bp, phy_blk[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010716 MDIO_PMA_DEVAD,
10717 MDIO_PMA_REG_TX_POWER_DOWN, (val & (~(1<<10))));
Yaniv Rosner6bbca912008-08-13 15:57:28 -070010718 msleep(15);
10719
10720 /* Read modify write the SPI-ROM version select register */
Yaniv Rosnere10bc842010-09-07 11:40:50 +000010721 bnx2x_cl45_read(bp, phy_blk[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010722 MDIO_PMA_DEVAD,
10723 MDIO_PMA_REG_EDC_FFE_MAIN, &val);
Yaniv Rosnere10bc842010-09-07 11:40:50 +000010724 bnx2x_cl45_write(bp, phy_blk[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010725 MDIO_PMA_DEVAD,
10726 MDIO_PMA_REG_EDC_FFE_MAIN, (val | (1<<12)));
Yaniv Rosner6bbca912008-08-13 15:57:28 -070010727
10728 /* set GPIO2 back to LOW */
10729 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010730 MISC_REGISTERS_GPIO_OUTPUT_LOW, port);
Yaniv Rosner6bbca912008-08-13 15:57:28 -070010731 }
10732 return 0;
Yaniv Rosner6bbca912008-08-13 15:57:28 -070010733}
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000010734static int bnx2x_8726_common_init_phy(struct bnx2x *bp,
10735 u32 shmem_base_path[],
10736 u32 shmem2_base_path[], u8 phy_index,
10737 u32 chip_id)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010738{
10739 u32 val;
10740 s8 port;
10741 struct bnx2x_phy phy;
10742 /* Use port1 because of the static port-swap */
10743 /* Enable the module detection interrupt */
10744 val = REG_RD(bp, MISC_REG_GPIO_EVENT_EN);
10745 val |= ((1<<MISC_REGISTERS_GPIO_3)|
10746 (1<<(MISC_REGISTERS_GPIO_3 + MISC_REGISTERS_GPIO_PORT_SHIFT)));
10747 REG_WR(bp, MISC_REG_GPIO_EVENT_EN, val);
10748
Yaniv Rosner650154b2010-11-01 05:32:36 +000010749 bnx2x_ext_phy_hw_reset(bp, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010750 msleep(5);
10751 for (port = 0; port < PORT_MAX; port++) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010752 u32 shmem_base, shmem2_base;
10753
10754 /* In E2, same phy is using for port0 of the two paths */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000010755 if (CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010756 shmem_base = shmem_base_path[0];
10757 shmem2_base = shmem2_base_path[0];
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000010758 } else {
10759 shmem_base = shmem_base_path[port];
10760 shmem2_base = shmem2_base_path[port];
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010761 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010762 /* Extract the ext phy address for the port */
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010763 if (bnx2x_populate_phy(bp, phy_index, shmem_base, shmem2_base,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010764 port, &phy) !=
10765 0) {
10766 DP(NETIF_MSG_LINK, "populate phy failed\n");
10767 return -EINVAL;
10768 }
10769
10770 /* Reset phy*/
10771 bnx2x_cl45_write(bp, &phy,
10772 MDIO_PMA_DEVAD, MDIO_PMA_REG_GEN_CTRL, 0x0001);
10773
10774
10775 /* Set fault module detected LED on */
10776 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_0,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010777 MISC_REGISTERS_GPIO_HIGH,
10778 port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010779 }
10780
10781 return 0;
10782}
Yaniv Rosnera8db5b42011-01-31 04:22:28 +000010783static void bnx2x_get_ext_phy_reset_gpio(struct bnx2x *bp, u32 shmem_base,
10784 u8 *io_gpio, u8 *io_port)
10785{
10786
10787 u32 phy_gpio_reset = REG_RD(bp, shmem_base +
10788 offsetof(struct shmem_region,
10789 dev_info.port_hw_config[PORT_0].default_cfg));
10790 switch (phy_gpio_reset) {
10791 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO0_P0:
10792 *io_gpio = 0;
10793 *io_port = 0;
10794 break;
10795 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO1_P0:
10796 *io_gpio = 1;
10797 *io_port = 0;
10798 break;
10799 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO2_P0:
10800 *io_gpio = 2;
10801 *io_port = 0;
10802 break;
10803 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO3_P0:
10804 *io_gpio = 3;
10805 *io_port = 0;
10806 break;
10807 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO0_P1:
10808 *io_gpio = 0;
10809 *io_port = 1;
10810 break;
10811 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO1_P1:
10812 *io_gpio = 1;
10813 *io_port = 1;
10814 break;
10815 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO2_P1:
10816 *io_gpio = 2;
10817 *io_port = 1;
10818 break;
10819 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO3_P1:
10820 *io_gpio = 3;
10821 *io_port = 1;
10822 break;
10823 default:
10824 /* Don't override the io_gpio and io_port */
10825 break;
10826 }
10827}
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000010828
10829static int bnx2x_8727_common_init_phy(struct bnx2x *bp,
10830 u32 shmem_base_path[],
10831 u32 shmem2_base_path[], u8 phy_index,
10832 u32 chip_id)
Eilon Greenstein4d295db2009-07-21 05:47:47 +000010833{
Yaniv Rosnera8db5b42011-01-31 04:22:28 +000010834 s8 port, reset_gpio;
Eilon Greenstein4d295db2009-07-21 05:47:47 +000010835 u32 swap_val, swap_override;
Yaniv Rosnere10bc842010-09-07 11:40:50 +000010836 struct bnx2x_phy phy[PORT_MAX];
10837 struct bnx2x_phy *phy_blk[PORT_MAX];
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010838 s8 port_of_path;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010839 swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
10840 swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
Eilon Greenstein4d295db2009-07-21 05:47:47 +000010841
Yaniv Rosnera8db5b42011-01-31 04:22:28 +000010842 reset_gpio = MISC_REGISTERS_GPIO_1;
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010843 port = 1;
10844
Yaniv Rosnera8db5b42011-01-31 04:22:28 +000010845 /*
10846 * Retrieve the reset gpio/port which control the reset.
10847 * Default is GPIO1, PORT1
10848 */
10849 bnx2x_get_ext_phy_reset_gpio(bp, shmem_base_path[0],
10850 (u8 *)&reset_gpio, (u8 *)&port);
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010851
10852 /* Calculate the port based on port swap */
10853 port ^= (swap_val && swap_override);
10854
Yaniv Rosnera8db5b42011-01-31 04:22:28 +000010855 /* Initiate PHY reset*/
10856 bnx2x_set_gpio(bp, reset_gpio, MISC_REGISTERS_GPIO_OUTPUT_LOW,
10857 port);
10858 msleep(1);
10859 bnx2x_set_gpio(bp, reset_gpio, MISC_REGISTERS_GPIO_OUTPUT_HIGH,
10860 port);
10861
Eilon Greenstein4d295db2009-07-21 05:47:47 +000010862 msleep(5);
10863
10864 /* PART1 - Reset both phys */
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010865 for (port = PORT_MAX - 1; port >= PORT_0; port--) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010866 u32 shmem_base, shmem2_base;
10867
10868 /* In E2, same phy is using for port0 of the two paths */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000010869 if (CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010870 shmem_base = shmem_base_path[0];
10871 shmem2_base = shmem2_base_path[0];
10872 port_of_path = port;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000010873 } else {
10874 shmem_base = shmem_base_path[port];
10875 shmem2_base = shmem2_base_path[port];
10876 port_of_path = 0;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010877 }
10878
Eilon Greenstein4d295db2009-07-21 05:47:47 +000010879 /* Extract the ext phy address for the port */
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010880 if (bnx2x_populate_phy(bp, phy_index, shmem_base, shmem2_base,
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010881 port_of_path, &phy[port]) !=
Yaniv Rosnere10bc842010-09-07 11:40:50 +000010882 0) {
10883 DP(NETIF_MSG_LINK, "populate phy failed\n");
10884 return -EINVAL;
10885 }
Eilon Greenstein4d295db2009-07-21 05:47:47 +000010886 /* disable attentions */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010887 bnx2x_bits_dis(bp, NIG_REG_MASK_INTERRUPT_PORT0 +
10888 port_of_path*4,
10889 (NIG_MASK_XGXS0_LINK_STATUS |
10890 NIG_MASK_XGXS0_LINK10G |
10891 NIG_MASK_SERDES0_LINK_STATUS |
10892 NIG_MASK_MI_INT));
Eilon Greenstein4d295db2009-07-21 05:47:47 +000010893
Eilon Greenstein4d295db2009-07-21 05:47:47 +000010894
10895 /* Reset the phy */
Yaniv Rosnere10bc842010-09-07 11:40:50 +000010896 bnx2x_cl45_write(bp, &phy[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010897 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 1<<15);
Eilon Greenstein4d295db2009-07-21 05:47:47 +000010898 }
10899
10900 /* Add delay of 150ms after reset */
10901 msleep(150);
Yaniv Rosnere10bc842010-09-07 11:40:50 +000010902 if (phy[PORT_0].addr & 0x1) {
10903 phy_blk[PORT_0] = &(phy[PORT_1]);
10904 phy_blk[PORT_1] = &(phy[PORT_0]);
10905 } else {
10906 phy_blk[PORT_0] = &(phy[PORT_0]);
10907 phy_blk[PORT_1] = &(phy[PORT_1]);
10908 }
Eilon Greenstein4d295db2009-07-21 05:47:47 +000010909 /* PART2 - Download firmware to both phys */
Yaniv Rosnere10bc842010-09-07 11:40:50 +000010910 for (port = PORT_MAX - 1; port >= PORT_0; port--) {
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000010911 if (CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010912 port_of_path = port;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000010913 else
10914 port_of_path = 0;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010915 DP(NETIF_MSG_LINK, "Loading spirom for phy address 0x%x\n",
10916 phy_blk[port]->addr);
Yaniv Rosner5c99274b2011-01-18 04:33:36 +000010917 if (bnx2x_8073_8727_external_rom_boot(bp, phy_blk[port],
10918 port_of_path))
Eilon Greenstein4d295db2009-07-21 05:47:47 +000010919 return -EINVAL;
Eilon Greenstein4d295db2009-07-21 05:47:47 +000010920
Yaniv Rosner5c99274b2011-01-18 04:33:36 +000010921 }
Eilon Greenstein4d295db2009-07-21 05:47:47 +000010922 return 0;
10923}
10924
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000010925static int bnx2x_ext_phy_common_init(struct bnx2x *bp, u32 shmem_base_path[],
10926 u32 shmem2_base_path[], u8 phy_index,
10927 u32 ext_phy_type, u32 chip_id)
Yaniv Rosner6bbca912008-08-13 15:57:28 -070010928{
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000010929 int rc = 0;
Yaniv Rosner6bbca912008-08-13 15:57:28 -070010930
10931 switch (ext_phy_type) {
10932 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073:
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010933 rc = bnx2x_8073_common_init_phy(bp, shmem_base_path,
10934 shmem2_base_path,
10935 phy_index, chip_id);
Yaniv Rosner6bbca912008-08-13 15:57:28 -070010936 break;
Yaniv Rosnere4d78f12011-05-31 21:25:55 +000010937 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8722:
Eilon Greenstein4d295db2009-07-21 05:47:47 +000010938 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
10939 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727_NOC:
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010940 rc = bnx2x_8727_common_init_phy(bp, shmem_base_path,
10941 shmem2_base_path,
10942 phy_index, chip_id);
Eilon Greenstein4d295db2009-07-21 05:47:47 +000010943 break;
10944
Eilon Greenstein589abe32009-02-12 08:36:55 +000010945 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +000010946 /*
10947 * GPIO1 affects both ports, so there's need to pull
10948 * it for single port alone
10949 */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000010950 rc = bnx2x_8726_common_init_phy(bp, shmem_base_path,
10951 shmem2_base_path,
10952 phy_index, chip_id);
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010953 break;
10954 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE:
10955 rc = -EINVAL;
Yaniv Rosner4f60dab2009-11-05 19:18:23 +020010956 break;
Yaniv Rosner6bbca912008-08-13 15:57:28 -070010957 default:
10958 DP(NETIF_MSG_LINK,
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +000010959 "ext_phy 0x%x common init not required\n",
10960 ext_phy_type);
Yaniv Rosner6bbca912008-08-13 15:57:28 -070010961 break;
10962 }
10963
Yaniv Rosner6d870c32011-01-31 04:22:20 +000010964 if (rc != 0)
10965 netdev_err(bp->dev, "Warning: PHY was not initialized,"
10966 " Port %d\n",
10967 0);
Yaniv Rosner6bbca912008-08-13 15:57:28 -070010968 return rc;
10969}
10970
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000010971int bnx2x_common_init_phy(struct bnx2x *bp, u32 shmem_base_path[],
10972 u32 shmem2_base_path[], u32 chip_id)
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010973{
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000010974 int rc = 0;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000010975 u32 phy_ver, val;
10976 u8 phy_index = 0;
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010977 u32 ext_phy_type, ext_phy_config;
Yaniv Rosnera198c142011-05-31 21:29:42 +000010978 bnx2x_set_mdio_clk(bp, chip_id, PORT_0);
10979 bnx2x_set_mdio_clk(bp, chip_id, PORT_1);
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010980 DP(NETIF_MSG_LINK, "Begin common phy init\n");
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000010981 if (CHIP_IS_E3(bp)) {
10982 /* Enable EPIO */
10983 val = REG_RD(bp, MISC_REG_GEN_PURP_HWG);
10984 REG_WR(bp, MISC_REG_GEN_PURP_HWG, val | 1);
10985 }
Yaniv Rosnerb21a3422011-01-18 04:33:24 +000010986 /* Check if common init was already done */
10987 phy_ver = REG_RD(bp, shmem_base_path[0] +
10988 offsetof(struct shmem_region,
10989 port_mb[PORT_0].ext_phy_fw_version));
10990 if (phy_ver) {
10991 DP(NETIF_MSG_LINK, "Not doing common init; phy ver is 0x%x\n",
10992 phy_ver);
10993 return 0;
10994 }
10995
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010996 /* Read the ext_phy_type for arbitrary port(0) */
10997 for (phy_index = EXT_PHY1; phy_index < MAX_PHYS;
10998 phy_index++) {
10999 ext_phy_config = bnx2x_get_ext_phy_config(bp,
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000011000 shmem_base_path[0],
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011001 phy_index, 0);
11002 ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000011003 rc |= bnx2x_ext_phy_common_init(bp, shmem_base_path,
11004 shmem2_base_path,
11005 phy_index, ext_phy_type,
11006 chip_id);
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011007 }
11008 return rc;
11009}
11010
11011u8 bnx2x_hw_lock_required(struct bnx2x *bp, u32 shmem_base, u32 shmem2_base)
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +000011012{
11013 u8 phy_index;
11014 struct bnx2x_phy phy;
11015 for (phy_index = INT_PHY; phy_index < MAX_PHYS;
11016 phy_index++) {
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011017 if (bnx2x_populate_phy(bp, phy_index, shmem_base, shmem2_base,
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +000011018 0, &phy) != 0) {
11019 DP(NETIF_MSG_LINK, "populate phy failed\n");
11020 return 0;
11021 }
11022
11023 if (phy.flags & FLAGS_HW_LOCK_REQUIRED)
11024 return 1;
11025 }
11026 return 0;
11027}
11028
11029u8 bnx2x_fan_failure_det_req(struct bnx2x *bp,
11030 u32 shmem_base,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011031 u32 shmem2_base,
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +000011032 u8 port)
11033{
11034 u8 phy_index, fan_failure_det_req = 0;
11035 struct bnx2x_phy phy;
11036 for (phy_index = EXT_PHY1; phy_index < MAX_PHYS;
11037 phy_index++) {
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011038 if (bnx2x_populate_phy(bp, phy_index, shmem_base, shmem2_base,
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +000011039 port, &phy)
11040 != 0) {
11041 DP(NETIF_MSG_LINK, "populate phy failed\n");
11042 return 0;
11043 }
11044 fan_failure_det_req |= (phy.flags &
11045 FLAGS_FAN_FAILURE_DET_REQ);
11046 }
11047 return fan_failure_det_req;
11048}
11049
11050void bnx2x_hw_reset_phy(struct link_params *params)
11051{
11052 u8 phy_index;
11053 for (phy_index = EXT_PHY1; phy_index < MAX_PHYS;
11054 phy_index++) {
11055 if (params->phy[phy_index].hw_reset) {
11056 params->phy[phy_index].hw_reset(
11057 &params->phy[phy_index],
11058 params);
11059 params->phy[phy_index] = phy_null;
11060 }
11061 }
11062}
Yaniv Rosner020c7e32011-05-31 21:28:43 +000011063
11064void bnx2x_init_mod_abs_int(struct bnx2x *bp, struct link_vars *vars,
11065 u32 chip_id, u32 shmem_base, u32 shmem2_base,
11066 u8 port)
11067{
11068 u8 gpio_num = 0xff, gpio_port = 0xff, phy_index;
11069 u32 val;
11070 u32 offset, aeu_mask, swap_val, swap_override, sync_offset;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000011071 if (CHIP_IS_E3(bp)) {
11072 if (bnx2x_get_mod_abs_int_cfg(bp, chip_id,
11073 shmem_base,
11074 port,
11075 &gpio_num,
11076 &gpio_port) != 0)
11077 return;
11078 } else {
Yaniv Rosner020c7e32011-05-31 21:28:43 +000011079 struct bnx2x_phy phy;
11080 for (phy_index = EXT_PHY1; phy_index < MAX_PHYS;
11081 phy_index++) {
11082 if (bnx2x_populate_phy(bp, phy_index, shmem_base,
11083 shmem2_base, port, &phy)
11084 != 0) {
11085 DP(NETIF_MSG_LINK, "populate phy failed\n");
11086 return;
11087 }
11088 if (phy.type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726) {
11089 gpio_num = MISC_REGISTERS_GPIO_3;
11090 gpio_port = port;
11091 break;
11092 }
11093 }
11094 }
11095
11096 if (gpio_num == 0xff)
11097 return;
11098
11099 /* Set GPIO3 to trigger SFP+ module insertion/removal */
11100 bnx2x_set_gpio(bp, gpio_num, MISC_REGISTERS_GPIO_INPUT_HI_Z, gpio_port);
11101
11102 swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
11103 swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
11104 gpio_port ^= (swap_val && swap_override);
11105
11106 vars->aeu_int_mask = AEU_INPUTS_ATTN_BITS_GPIO0_FUNCTION_0 <<
11107 (gpio_num + (gpio_port << 2));
11108
11109 sync_offset = shmem_base +
11110 offsetof(struct shmem_region,
11111 dev_info.port_hw_config[port].aeu_int_mask);
11112 REG_WR(bp, sync_offset, vars->aeu_int_mask);
11113
11114 DP(NETIF_MSG_LINK, "Setting MOD_ABS (GPIO%d_P%d) AEU to 0x%x\n",
11115 gpio_num, gpio_port, vars->aeu_int_mask);
11116
11117 if (port == 0)
11118 offset = MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0;
11119 else
11120 offset = MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0;
11121
11122 /* Open appropriate AEU for interrupts */
11123 aeu_mask = REG_RD(bp, offset);
11124 aeu_mask |= vars->aeu_int_mask;
11125 REG_WR(bp, offset, aeu_mask);
11126
11127 /* Enable the GPIO to trigger interrupt */
11128 val = REG_RD(bp, MISC_REG_GPIO_EVENT_EN);
11129 val |= 1 << (gpio_num + (gpio_port << 2));
11130 REG_WR(bp, MISC_REG_GPIO_EVENT_EN, val);
11131}