blob: 8e6909a6a2c6bfa299fa1191fcc280159a90b8e4 [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
Yaniv Rosner26ffaf32011-10-27 05:09:45 +000048/* LED Blink rate that will achieve ~15.9Hz */
49#define LED_BLINK_RATE_VAL_E3 354
50#define LED_BLINK_RATE_VAL_E1X_E2 480
Yaniv Rosnerea4e0402008-06-23 20:27:26 -070051/***********************************************************/
Eilon Greenstein3196a882008-08-13 15:58:49 -070052/* Shortcut definitions */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -070053/***********************************************************/
54
Eilon Greenstein2f904462009-08-12 08:22:16 +000055#define NIG_LATCH_BC_ENABLE_MI_INT 0
56
57#define NIG_STATUS_EMAC0_MI_INT \
58 NIG_STATUS_INTERRUPT_PORT0_REG_STATUS_EMAC0_MISC_MI_INT
Yaniv Rosnerea4e0402008-06-23 20:27:26 -070059#define NIG_STATUS_XGXS0_LINK10G \
60 NIG_STATUS_INTERRUPT_PORT0_REG_STATUS_XGXS0_LINK10G
61#define NIG_STATUS_XGXS0_LINK_STATUS \
62 NIG_STATUS_INTERRUPT_PORT0_REG_STATUS_XGXS0_LINK_STATUS
63#define NIG_STATUS_XGXS0_LINK_STATUS_SIZE \
64 NIG_STATUS_INTERRUPT_PORT0_REG_STATUS_XGXS0_LINK_STATUS_SIZE
65#define NIG_STATUS_SERDES0_LINK_STATUS \
66 NIG_STATUS_INTERRUPT_PORT0_REG_STATUS_SERDES0_LINK_STATUS
67#define NIG_MASK_MI_INT \
68 NIG_MASK_INTERRUPT_PORT0_REG_MASK_EMAC0_MISC_MI_INT
69#define NIG_MASK_XGXS0_LINK10G \
70 NIG_MASK_INTERRUPT_PORT0_REG_MASK_XGXS0_LINK10G
71#define NIG_MASK_XGXS0_LINK_STATUS \
72 NIG_MASK_INTERRUPT_PORT0_REG_MASK_XGXS0_LINK_STATUS
73#define NIG_MASK_SERDES0_LINK_STATUS \
74 NIG_MASK_INTERRUPT_PORT0_REG_MASK_SERDES0_LINK_STATUS
75
76#define MDIO_AN_CL73_OR_37_COMPLETE \
77 (MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_AUTONEG_COMPLETE | \
78 MDIO_GP_STATUS_TOP_AN_STATUS1_CL37_AUTONEG_COMPLETE)
79
80#define XGXS_RESET_BITS \
81 (MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_XGXS0_RSTB_HW | \
82 MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_XGXS0_IDDQ | \
83 MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_XGXS0_PWRDWN | \
84 MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_XGXS0_PWRDWN_SD | \
85 MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_XGXS0_TXD_FIFO_RSTB)
86
87#define SERDES_RESET_BITS \
88 (MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_SERDES0_RSTB_HW | \
89 MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_SERDES0_IDDQ | \
90 MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_SERDES0_PWRDWN | \
91 MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_SERDES0_PWRDWN_SD)
92
93#define AUTONEG_CL37 SHARED_HW_CFG_AN_ENABLE_CL37
94#define AUTONEG_CL73 SHARED_HW_CFG_AN_ENABLE_CL73
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000095#define AUTONEG_BAM SHARED_HW_CFG_AN_ENABLE_BAM
Eilon Greenstein3196a882008-08-13 15:58:49 -070096#define AUTONEG_PARALLEL \
Yaniv Rosnerea4e0402008-06-23 20:27:26 -070097 SHARED_HW_CFG_AN_ENABLE_PARALLEL_DETECTION
Eilon Greenstein3196a882008-08-13 15:58:49 -070098#define AUTONEG_SGMII_FIBER_AUTODET \
Yaniv Rosnerea4e0402008-06-23 20:27:26 -070099 SHARED_HW_CFG_AN_EN_SGMII_FIBER_AUTO_DETECT
Eilon Greenstein3196a882008-08-13 15:58:49 -0700100#define AUTONEG_REMOTE_PHY SHARED_HW_CFG_AN_ENABLE_REMOTE_PHY
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700101
102#define GP_STATUS_PAUSE_RSOLUTION_TXSIDE \
103 MDIO_GP_STATUS_TOP_AN_STATUS1_PAUSE_RSOLUTION_TXSIDE
104#define GP_STATUS_PAUSE_RSOLUTION_RXSIDE \
105 MDIO_GP_STATUS_TOP_AN_STATUS1_PAUSE_RSOLUTION_RXSIDE
106#define GP_STATUS_SPEED_MASK \
107 MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_MASK
108#define GP_STATUS_10M MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10M
109#define GP_STATUS_100M MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_100M
110#define GP_STATUS_1G MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_1G
111#define GP_STATUS_2_5G MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_2_5G
112#define GP_STATUS_5G MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_5G
113#define GP_STATUS_6G MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_6G
114#define GP_STATUS_10G_HIG \
115 MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10G_HIG
116#define GP_STATUS_10G_CX4 \
117 MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10G_CX4
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700118#define GP_STATUS_1G_KX MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_1G_KX
119#define GP_STATUS_10G_KX4 \
120 MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10G_KX4
Yaniv Rosner3c9ada22011-06-14 01:34:12 +0000121#define GP_STATUS_10G_KR MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10G_KR
122#define GP_STATUS_10G_XFI MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10G_XFI
123#define GP_STATUS_20G_DXGXS MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_20G_DXGXS
124#define GP_STATUS_10G_SFI MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10G_SFI
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000125#define LINK_10THD LINK_STATUS_SPEED_AND_DUPLEX_10THD
126#define LINK_10TFD LINK_STATUS_SPEED_AND_DUPLEX_10TFD
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700127#define LINK_100TXHD LINK_STATUS_SPEED_AND_DUPLEX_100TXHD
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000128#define LINK_100T4 LINK_STATUS_SPEED_AND_DUPLEX_100T4
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700129#define LINK_100TXFD LINK_STATUS_SPEED_AND_DUPLEX_100TXFD
130#define LINK_1000THD LINK_STATUS_SPEED_AND_DUPLEX_1000THD
131#define LINK_1000TFD LINK_STATUS_SPEED_AND_DUPLEX_1000TFD
132#define LINK_1000XFD LINK_STATUS_SPEED_AND_DUPLEX_1000XFD
133#define LINK_2500THD LINK_STATUS_SPEED_AND_DUPLEX_2500THD
134#define LINK_2500TFD LINK_STATUS_SPEED_AND_DUPLEX_2500TFD
135#define LINK_2500XFD LINK_STATUS_SPEED_AND_DUPLEX_2500XFD
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000136#define LINK_10GTFD LINK_STATUS_SPEED_AND_DUPLEX_10GTFD
137#define LINK_10GXFD LINK_STATUS_SPEED_AND_DUPLEX_10GXFD
Yaniv Rosner3c9ada22011-06-14 01:34:12 +0000138#define LINK_20GTFD LINK_STATUS_SPEED_AND_DUPLEX_20GTFD
139#define LINK_20GXFD LINK_STATUS_SPEED_AND_DUPLEX_20GXFD
Yaniv Rosner6583e332011-06-14 01:34:17 +0000140
141
142
Eilon Greenstein589abe32009-02-12 08:36:55 +0000143/* */
144#define SFP_EEPROM_CON_TYPE_ADDR 0x2
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000145 #define SFP_EEPROM_CON_TYPE_VAL_LC 0x7
Eilon Greenstein589abe32009-02-12 08:36:55 +0000146 #define SFP_EEPROM_CON_TYPE_VAL_COPPER 0x21
147
Eilon Greenstein4d295db2009-07-21 05:47:47 +0000148
149#define SFP_EEPROM_COMP_CODE_ADDR 0x3
150 #define SFP_EEPROM_COMP_CODE_SR_MASK (1<<4)
151 #define SFP_EEPROM_COMP_CODE_LR_MASK (1<<5)
152 #define SFP_EEPROM_COMP_CODE_LRM_MASK (1<<6)
153
Eilon Greenstein589abe32009-02-12 08:36:55 +0000154#define SFP_EEPROM_FC_TX_TECH_ADDR 0x8
155 #define SFP_EEPROM_FC_TX_TECH_BITMASK_COPPER_PASSIVE 0x4
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000156 #define SFP_EEPROM_FC_TX_TECH_BITMASK_COPPER_ACTIVE 0x8
Eilon Greenstein4d295db2009-07-21 05:47:47 +0000157
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000158#define SFP_EEPROM_OPTIONS_ADDR 0x40
Eilon Greenstein589abe32009-02-12 08:36:55 +0000159 #define SFP_EEPROM_OPTIONS_LINEAR_RX_OUT_MASK 0x1
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000160#define SFP_EEPROM_OPTIONS_SIZE 2
Eilon Greenstein589abe32009-02-12 08:36:55 +0000161
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000162#define EDC_MODE_LINEAR 0x0022
163#define EDC_MODE_LIMITING 0x0044
164#define EDC_MODE_PASSIVE_DAC 0x0055
Eilon Greenstein589abe32009-02-12 08:36:55 +0000165
Yaniv Rosner866ceda2011-11-28 00:49:45 +0000166/* BRB default for class 0 E2 */
167#define DEFAULT0_E2_BRB_MAC_PAUSE_XOFF_THR 170
168#define DEFAULT0_E2_BRB_MAC_PAUSE_XON_THR 250
169#define DEFAULT0_E2_BRB_MAC_FULL_XOFF_THR 10
170#define DEFAULT0_E2_BRB_MAC_FULL_XON_THR 50
Eilon Greenstein4d295db2009-07-21 05:47:47 +0000171
Yaniv Rosner9380bb92011-06-14 01:34:07 +0000172/* BRB thresholds for E2*/
173#define PFC_E2_BRB_MAC_PAUSE_XOFF_THR_PAUSE 170
174#define PFC_E2_BRB_MAC_PAUSE_XOFF_THR_NON_PAUSE 0
175
176#define PFC_E2_BRB_MAC_PAUSE_XON_THR_PAUSE 250
177#define PFC_E2_BRB_MAC_PAUSE_XON_THR_NON_PAUSE 0
178
179#define PFC_E2_BRB_MAC_FULL_XOFF_THR_PAUSE 10
180#define PFC_E2_BRB_MAC_FULL_XOFF_THR_NON_PAUSE 90
181
182#define PFC_E2_BRB_MAC_FULL_XON_THR_PAUSE 50
183#define PFC_E2_BRB_MAC_FULL_XON_THR_NON_PAUSE 250
184
Yaniv Rosner866ceda2011-11-28 00:49:45 +0000185/* BRB default for class 0 E3A0 */
186#define DEFAULT0_E3A0_BRB_MAC_PAUSE_XOFF_THR 290
187#define DEFAULT0_E3A0_BRB_MAC_PAUSE_XON_THR 410
188#define DEFAULT0_E3A0_BRB_MAC_FULL_XOFF_THR 10
189#define DEFAULT0_E3A0_BRB_MAC_FULL_XON_THR 50
190
Yaniv Rosner9380bb92011-06-14 01:34:07 +0000191/* BRB thresholds for E3A0 */
192#define PFC_E3A0_BRB_MAC_PAUSE_XOFF_THR_PAUSE 290
193#define PFC_E3A0_BRB_MAC_PAUSE_XOFF_THR_NON_PAUSE 0
194
195#define PFC_E3A0_BRB_MAC_PAUSE_XON_THR_PAUSE 410
196#define PFC_E3A0_BRB_MAC_PAUSE_XON_THR_NON_PAUSE 0
197
198#define PFC_E3A0_BRB_MAC_FULL_XOFF_THR_PAUSE 10
199#define PFC_E3A0_BRB_MAC_FULL_XOFF_THR_NON_PAUSE 170
200
201#define PFC_E3A0_BRB_MAC_FULL_XON_THR_PAUSE 50
202#define PFC_E3A0_BRB_MAC_FULL_XON_THR_NON_PAUSE 410
203
Yaniv Rosner866ceda2011-11-28 00:49:45 +0000204/* BRB default for E3B0 */
205#define DEFAULT0_E3B0_BRB_MAC_PAUSE_XOFF_THR 330
206#define DEFAULT0_E3B0_BRB_MAC_PAUSE_XON_THR 490
207#define DEFAULT0_E3B0_BRB_MAC_FULL_XOFF_THR 15
208#define DEFAULT0_E3B0_BRB_MAC_FULL_XON_THR 55
Yaniv Rosner9380bb92011-06-14 01:34:07 +0000209
210/* BRB thresholds for E3B0 2 port mode*/
211#define PFC_E3B0_2P_BRB_MAC_PAUSE_XOFF_THR_PAUSE 1025
212#define PFC_E3B0_2P_BRB_MAC_PAUSE_XOFF_THR_NON_PAUSE 0
213
214#define PFC_E3B0_2P_BRB_MAC_PAUSE_XON_THR_PAUSE 1025
215#define PFC_E3B0_2P_BRB_MAC_PAUSE_XON_THR_NON_PAUSE 0
216
217#define PFC_E3B0_2P_BRB_MAC_FULL_XOFF_THR_PAUSE 10
218#define PFC_E3B0_2P_BRB_MAC_FULL_XOFF_THR_NON_PAUSE 1025
219
220#define PFC_E3B0_2P_BRB_MAC_FULL_XON_THR_PAUSE 50
221#define PFC_E3B0_2P_BRB_MAC_FULL_XON_THR_NON_PAUSE 1025
222
223/* only for E3B0*/
224#define PFC_E3B0_2P_BRB_FULL_LB_XOFF_THR 1025
225#define PFC_E3B0_2P_BRB_FULL_LB_XON_THR 1025
226
227/* Lossy +Lossless GUARANTIED == GUART */
228#define PFC_E3B0_2P_MIX_PAUSE_LB_GUART 284
229/* Lossless +Lossless*/
230#define PFC_E3B0_2P_PAUSE_LB_GUART 236
231/* Lossy +Lossy*/
232#define PFC_E3B0_2P_NON_PAUSE_LB_GUART 342
233
234/* Lossy +Lossless*/
235#define PFC_E3B0_2P_MIX_PAUSE_MAC_0_CLASS_T_GUART 284
236/* Lossless +Lossless*/
237#define PFC_E3B0_2P_PAUSE_MAC_0_CLASS_T_GUART 236
238/* Lossy +Lossy*/
239#define PFC_E3B0_2P_NON_PAUSE_MAC_0_CLASS_T_GUART 336
240#define PFC_E3B0_2P_BRB_MAC_0_CLASS_T_GUART_HYST 80
241
242#define PFC_E3B0_2P_BRB_MAC_1_CLASS_T_GUART 0
243#define PFC_E3B0_2P_BRB_MAC_1_CLASS_T_GUART_HYST 0
244
245/* BRB thresholds for E3B0 4 port mode */
246#define PFC_E3B0_4P_BRB_MAC_PAUSE_XOFF_THR_PAUSE 304
247#define PFC_E3B0_4P_BRB_MAC_PAUSE_XOFF_THR_NON_PAUSE 0
248
249#define PFC_E3B0_4P_BRB_MAC_PAUSE_XON_THR_PAUSE 384
250#define PFC_E3B0_4P_BRB_MAC_PAUSE_XON_THR_NON_PAUSE 0
251
252#define PFC_E3B0_4P_BRB_MAC_FULL_XOFF_THR_PAUSE 10
253#define PFC_E3B0_4P_BRB_MAC_FULL_XOFF_THR_NON_PAUSE 304
254
255#define PFC_E3B0_4P_BRB_MAC_FULL_XON_THR_PAUSE 50
256#define PFC_E3B0_4P_BRB_MAC_FULL_XON_THR_NON_PAUSE 384
257
258
259/* only for E3B0*/
260#define PFC_E3B0_4P_BRB_FULL_LB_XOFF_THR 304
261#define PFC_E3B0_4P_BRB_FULL_LB_XON_THR 384
262#define PFC_E3B0_4P_LB_GUART 120
263
264#define PFC_E3B0_4P_BRB_MAC_0_CLASS_T_GUART 120
265#define PFC_E3B0_4P_BRB_MAC_0_CLASS_T_GUART_HYST 80
266
267#define PFC_E3B0_4P_BRB_MAC_1_CLASS_T_GUART 80
268#define PFC_E3B0_4P_BRB_MAC_1_CLASS_T_GUART_HYST 120
269
Yaniv Rosner866ceda2011-11-28 00:49:45 +0000270/* Pause defines*/
271#define DEFAULT_E3B0_BRB_FULL_LB_XOFF_THR 330
272#define DEFAULT_E3B0_BRB_FULL_LB_XON_THR 490
273#define DEFAULT_E3B0_LB_GUART 40
274
275#define DEFAULT_E3B0_BRB_MAC_0_CLASS_T_GUART 40
276#define DEFAULT_E3B0_BRB_MAC_0_CLASS_T_GUART_HYST 0
277
278#define DEFAULT_E3B0_BRB_MAC_1_CLASS_T_GUART 40
279#define DEFAULT_E3B0_BRB_MAC_1_CLASS_T_GUART_HYST 0
280
281/* ETS defines*/
Yaniv Rosner9380bb92011-06-14 01:34:07 +0000282#define DCBX_INVALID_COS (0xFF)
283
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000284#define ETS_BW_LIMIT_CREDIT_UPPER_BOUND (0x5000)
285#define ETS_BW_LIMIT_CREDIT_WEIGHT (0x5000)
Yaniv Rosner9380bb92011-06-14 01:34:07 +0000286#define ETS_E3B0_NIG_MIN_W_VAL_UP_TO_10GBPS (1360)
287#define ETS_E3B0_NIG_MIN_W_VAL_20GBPS (2720)
288#define ETS_E3B0_PBF_MIN_W_VAL (10000)
289
290#define MAX_PACKET_SIZE (9700)
Yaniv Rosner3c9ada22011-06-14 01:34:12 +0000291#define WC_UC_TIMEOUT 100
Yaniv Rosnera9077bf2011-10-27 05:09:46 +0000292#define MAX_KR_LINK_RETRY 4
Yaniv Rosner9380bb92011-06-14 01:34:07 +0000293
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700294/**********************************************************/
295/* INTERFACE */
296/**********************************************************/
Yaniv Rosnere10bc842010-09-07 11:40:50 +0000297
Yaniv Rosnercd2be892011-01-31 04:21:45 +0000298#define CL22_WR_OVER_CL45(_bp, _phy, _bank, _addr, _val) \
Yaniv Rosnere10bc842010-09-07 11:40:50 +0000299 bnx2x_cl45_write(_bp, _phy, \
Yaniv Rosner7aa07112010-09-07 11:41:01 +0000300 (_phy)->def_md_devad, \
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700301 (_bank + (_addr & 0xf)), \
302 _val)
303
Yaniv Rosnercd2be892011-01-31 04:21:45 +0000304#define CL22_RD_OVER_CL45(_bp, _phy, _bank, _addr, _val) \
Yaniv Rosnere10bc842010-09-07 11:40:50 +0000305 bnx2x_cl45_read(_bp, _phy, \
Yaniv Rosner7aa07112010-09-07 11:41:01 +0000306 (_phy)->def_md_devad, \
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700307 (_bank + (_addr & 0xf)), \
308 _val)
309
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700310static u32 bnx2x_bits_en(struct bnx2x *bp, u32 reg, u32 bits)
311{
312 u32 val = REG_RD(bp, reg);
313
314 val |= bits;
315 REG_WR(bp, reg, val);
316 return val;
317}
318
319static u32 bnx2x_bits_dis(struct bnx2x *bp, u32 reg, u32 bits)
320{
321 u32 val = REG_RD(bp, reg);
322
323 val &= ~bits;
324 REG_WR(bp, reg, val);
325 return val;
326}
327
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000328/******************************************************************/
Yaniv Rosner3c9ada22011-06-14 01:34:12 +0000329/* EPIO/GPIO section */
330/******************************************************************/
Yaniv Rosner3deb8162011-06-14 01:34:33 +0000331static void bnx2x_get_epio(struct bnx2x *bp, u32 epio_pin, u32 *en)
332{
333 u32 epio_mask, gp_oenable;
334 *en = 0;
335 /* Sanity check */
336 if (epio_pin > 31) {
337 DP(NETIF_MSG_LINK, "Invalid EPIO pin %d to get\n", epio_pin);
338 return;
339 }
340
341 epio_mask = 1 << epio_pin;
342 /* Set this EPIO to output */
343 gp_oenable = REG_RD(bp, MCP_REG_MCPR_GP_OENABLE);
344 REG_WR(bp, MCP_REG_MCPR_GP_OENABLE, gp_oenable & ~epio_mask);
345
346 *en = (REG_RD(bp, MCP_REG_MCPR_GP_INPUTS) & epio_mask) >> epio_pin;
347}
Yaniv Rosner3c9ada22011-06-14 01:34:12 +0000348static void bnx2x_set_epio(struct bnx2x *bp, u32 epio_pin, u32 en)
349{
350 u32 epio_mask, gp_output, gp_oenable;
351
352 /* Sanity check */
353 if (epio_pin > 31) {
354 DP(NETIF_MSG_LINK, "Invalid EPIO pin %d to set\n", epio_pin);
355 return;
356 }
357 DP(NETIF_MSG_LINK, "Setting EPIO pin %d to %d\n", epio_pin, en);
358 epio_mask = 1 << epio_pin;
359 /* Set this EPIO to output */
360 gp_output = REG_RD(bp, MCP_REG_MCPR_GP_OUTPUTS);
361 if (en)
362 gp_output |= epio_mask;
363 else
364 gp_output &= ~epio_mask;
365
366 REG_WR(bp, MCP_REG_MCPR_GP_OUTPUTS, gp_output);
367
368 /* Set the value for this EPIO */
369 gp_oenable = REG_RD(bp, MCP_REG_MCPR_GP_OENABLE);
370 REG_WR(bp, MCP_REG_MCPR_GP_OENABLE, gp_oenable | epio_mask);
371}
372
373static void bnx2x_set_cfg_pin(struct bnx2x *bp, u32 pin_cfg, u32 val)
374{
375 if (pin_cfg == PIN_CFG_NA)
376 return;
377 if (pin_cfg >= PIN_CFG_EPIO0) {
378 bnx2x_set_epio(bp, pin_cfg - PIN_CFG_EPIO0, val);
379 } else {
380 u8 gpio_num = (pin_cfg - PIN_CFG_GPIO0_P0) & 0x3;
381 u8 gpio_port = (pin_cfg - PIN_CFG_GPIO0_P0) >> 2;
382 bnx2x_set_gpio(bp, gpio_num, (u8)val, gpio_port);
383 }
384}
385
Yaniv Rosner3deb8162011-06-14 01:34:33 +0000386static u32 bnx2x_get_cfg_pin(struct bnx2x *bp, u32 pin_cfg, u32 *val)
387{
388 if (pin_cfg == PIN_CFG_NA)
389 return -EINVAL;
390 if (pin_cfg >= PIN_CFG_EPIO0) {
391 bnx2x_get_epio(bp, pin_cfg - PIN_CFG_EPIO0, val);
392 } else {
393 u8 gpio_num = (pin_cfg - PIN_CFG_GPIO0_P0) & 0x3;
394 u8 gpio_port = (pin_cfg - PIN_CFG_GPIO0_P0) >> 2;
395 *val = bnx2x_get_gpio(bp, gpio_num, gpio_port);
396 }
397 return 0;
398
399}
Yaniv Rosner3c9ada22011-06-14 01:34:12 +0000400/******************************************************************/
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000401/* ETS section */
402/******************************************************************/
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000403static void bnx2x_ets_e2e3a0_disabled(struct link_params *params)
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000404{
405 /* ETS disabled configuration*/
406 struct bnx2x *bp = params->bp;
407
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000408 DP(NETIF_MSG_LINK, "ETS E2E3 disabled configuration\n");
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000409
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000410 /*
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000411 * mapping between entry priority to client number (0,1,2 -debug and
412 * management clients, 3 - COS0 client, 4 - COS client)(HIGHEST)
413 * 3bits client num.
414 * PRI4 | PRI3 | PRI2 | PRI1 | PRI0
415 * cos1-100 cos0-011 dbg1-010 dbg0-001 MCP-000
416 */
417
418 REG_WR(bp, NIG_REG_P0_TX_ARB_PRIORITY_CLIENT, 0x4688);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000419 /*
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000420 * Bitmap of 5bits length. Each bit specifies whether the entry behaves
421 * as strict. Bits 0,1,2 - debug and management entries, 3 -
422 * COS0 entry, 4 - COS1 entry.
423 * COS1 | COS0 | DEBUG1 | DEBUG0 | MGMT
424 * bit4 bit3 bit2 bit1 bit0
425 * MCP and debug are strict
426 */
427
428 REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_IS_STRICT, 0x7);
429 /* defines which entries (clients) are subjected to WFQ arbitration */
430 REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_IS_SUBJECT2WFQ, 0);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000431 /*
432 * For strict priority entries defines the number of consecutive
433 * slots for the highest priority.
434 */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000435 REG_WR(bp, NIG_REG_P0_TX_ARB_NUM_STRICT_ARB_SLOTS, 0x100);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000436 /*
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000437 * mapping between the CREDIT_WEIGHT registers and actual client
438 * numbers
439 */
440 REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_CREDIT_MAP, 0);
441 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_0, 0);
442 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_1, 0);
443
444 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_0, 0);
445 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_1, 0);
446 REG_WR(bp, PBF_REG_HIGH_PRIORITY_COS_NUM, 0);
447 /* ETS mode disable */
448 REG_WR(bp, PBF_REG_ETS_ENABLED, 0);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000449 /*
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000450 * If ETS mode is enabled (there is no strict priority) defines a WFQ
451 * weight for COS0/COS1.
452 */
453 REG_WR(bp, PBF_REG_COS0_WEIGHT, 0x2710);
454 REG_WR(bp, PBF_REG_COS1_WEIGHT, 0x2710);
455 /* Upper bound that COS0_WEIGHT can reach in the WFQ arbiter */
456 REG_WR(bp, PBF_REG_COS0_UPPER_BOUND, 0x989680);
457 REG_WR(bp, PBF_REG_COS1_UPPER_BOUND, 0x989680);
458 /* Defines the number of consecutive slots for the strict priority */
459 REG_WR(bp, PBF_REG_NUM_STRICT_ARB_SLOTS, 0);
460}
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000461/******************************************************************************
462* Description:
463* Getting min_w_val will be set according to line speed .
464*.
465******************************************************************************/
466static u32 bnx2x_ets_get_min_w_val_nig(const struct link_vars *vars)
467{
468 u32 min_w_val = 0;
469 /* Calculate min_w_val.*/
470 if (vars->link_up) {
471 if (SPEED_20000 == vars->line_speed)
472 min_w_val = ETS_E3B0_NIG_MIN_W_VAL_20GBPS;
473 else
474 min_w_val = ETS_E3B0_NIG_MIN_W_VAL_UP_TO_10GBPS;
475 } else
476 min_w_val = ETS_E3B0_NIG_MIN_W_VAL_20GBPS;
477 /**
478 * If the link isn't up (static configuration for example ) The
479 * link will be according to 20GBPS.
480 */
481 return min_w_val;
482}
483/******************************************************************************
484* Description:
485* Getting credit upper bound form min_w_val.
486*.
487******************************************************************************/
488static u32 bnx2x_ets_get_credit_upper_bound(const u32 min_w_val)
489{
490 const u32 credit_upper_bound = (u32)MAXVAL((150 * min_w_val),
491 MAX_PACKET_SIZE);
492 return credit_upper_bound;
493}
494/******************************************************************************
495* Description:
496* Set credit upper bound for NIG.
497*.
498******************************************************************************/
499static void bnx2x_ets_e3b0_set_credit_upper_bound_nig(
500 const struct link_params *params,
501 const u32 min_w_val)
502{
503 struct bnx2x *bp = params->bp;
504 const u8 port = params->port;
505 const u32 credit_upper_bound =
506 bnx2x_ets_get_credit_upper_bound(min_w_val);
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000507
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000508 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_UPPER_BOUND_0 :
509 NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_0, credit_upper_bound);
510 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_UPPER_BOUND_1 :
511 NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_1, credit_upper_bound);
512 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_UPPER_BOUND_2 :
513 NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_2, credit_upper_bound);
514 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_UPPER_BOUND_3 :
515 NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_3, credit_upper_bound);
516 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_UPPER_BOUND_4 :
517 NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_4, credit_upper_bound);
518 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_UPPER_BOUND_5 :
519 NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_5, credit_upper_bound);
520
521 if (0 == port) {
522 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_6,
523 credit_upper_bound);
524 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_7,
525 credit_upper_bound);
526 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_8,
527 credit_upper_bound);
528 }
529}
530/******************************************************************************
531* Description:
532* Will return the NIG ETS registers to init values.Except
533* credit_upper_bound.
534* That isn't used in this configuration (No WFQ is enabled) and will be
535* configured acording to spec
536*.
537******************************************************************************/
538static void bnx2x_ets_e3b0_nig_disabled(const struct link_params *params,
539 const struct link_vars *vars)
540{
541 struct bnx2x *bp = params->bp;
542 const u8 port = params->port;
543 const u32 min_w_val = bnx2x_ets_get_min_w_val_nig(vars);
544 /**
545 * mapping between entry priority to client number (0,1,2 -debug and
546 * management clients, 3 - COS0 client, 4 - COS1, ... 8 -
547 * COS5)(HIGHEST) 4bits client num.TODO_ETS - Should be done by
548 * reset value or init tool
549 */
550 if (port) {
551 REG_WR(bp, NIG_REG_P1_TX_ARB_PRIORITY_CLIENT2_LSB, 0x543210);
552 REG_WR(bp, NIG_REG_P1_TX_ARB_PRIORITY_CLIENT2_MSB, 0x0);
553 } else {
554 REG_WR(bp, NIG_REG_P0_TX_ARB_PRIORITY_CLIENT2_LSB, 0x76543210);
555 REG_WR(bp, NIG_REG_P0_TX_ARB_PRIORITY_CLIENT2_MSB, 0x8);
556 }
557 /**
558 * For strict priority entries defines the number of consecutive
559 * slots for the highest priority.
560 */
561 /* TODO_ETS - Should be done by reset value or init tool */
562 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_NUM_STRICT_ARB_SLOTS :
563 NIG_REG_P1_TX_ARB_NUM_STRICT_ARB_SLOTS, 0x100);
564 /**
565 * mapping between the CREDIT_WEIGHT registers and actual client
566 * numbers
567 */
568 /* TODO_ETS - Should be done by reset value or init tool */
569 if (port) {
570 /*Port 1 has 6 COS*/
571 REG_WR(bp, NIG_REG_P1_TX_ARB_CLIENT_CREDIT_MAP2_LSB, 0x210543);
572 REG_WR(bp, NIG_REG_P1_TX_ARB_CLIENT_CREDIT_MAP2_MSB, 0x0);
573 } else {
574 /*Port 0 has 9 COS*/
575 REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_CREDIT_MAP2_LSB,
576 0x43210876);
577 REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_CREDIT_MAP2_MSB, 0x5);
578 }
579
580 /**
581 * Bitmap of 5bits length. Each bit specifies whether the entry behaves
582 * as strict. Bits 0,1,2 - debug and management entries, 3 -
583 * COS0 entry, 4 - COS1 entry.
584 * COS1 | COS0 | DEBUG1 | DEBUG0 | MGMT
585 * bit4 bit3 bit2 bit1 bit0
586 * MCP and debug are strict
587 */
588 if (port)
589 REG_WR(bp, NIG_REG_P1_TX_ARB_CLIENT_IS_STRICT, 0x3f);
590 else
591 REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_IS_STRICT, 0x1ff);
592 /* defines which entries (clients) are subjected to WFQ arbitration */
593 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CLIENT_IS_SUBJECT2WFQ :
594 NIG_REG_P0_TX_ARB_CLIENT_IS_SUBJECT2WFQ, 0);
595
596 /**
597 * Please notice the register address are note continuous and a
598 * for here is note appropriate.In 2 port mode port0 only COS0-5
599 * can be used. DEBUG1,DEBUG1,MGMT are never used for WFQ* In 4
600 * port mode port1 only COS0-2 can be used. DEBUG1,DEBUG1,MGMT
601 * are never used for WFQ
602 */
603 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_WEIGHT_0 :
604 NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_0, 0x0);
605 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_WEIGHT_1 :
606 NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_1, 0x0);
607 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_WEIGHT_2 :
608 NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_2, 0x0);
609 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_WEIGHT_3 :
610 NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_3, 0x0);
611 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_WEIGHT_4 :
612 NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_4, 0x0);
613 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_WEIGHT_5 :
614 NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_5, 0x0);
615 if (0 == port) {
616 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_6, 0x0);
617 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_7, 0x0);
618 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_8, 0x0);
619 }
620
621 bnx2x_ets_e3b0_set_credit_upper_bound_nig(params, min_w_val);
622}
623/******************************************************************************
624* Description:
625* Set credit upper bound for PBF.
626*.
627******************************************************************************/
628static void bnx2x_ets_e3b0_set_credit_upper_bound_pbf(
629 const struct link_params *params,
630 const u32 min_w_val)
631{
632 struct bnx2x *bp = params->bp;
633 const u32 credit_upper_bound =
634 bnx2x_ets_get_credit_upper_bound(min_w_val);
635 const u8 port = params->port;
636 u32 base_upper_bound = 0;
637 u8 max_cos = 0;
638 u8 i = 0;
639 /**
640 * In 2 port mode port0 has COS0-5 that can be used for WFQ.In 4
641 * port mode port1 has COS0-2 that can be used for WFQ.
642 */
643 if (0 == port) {
644 base_upper_bound = PBF_REG_COS0_UPPER_BOUND_P0;
645 max_cos = DCBX_E3B0_MAX_NUM_COS_PORT0;
646 } else {
647 base_upper_bound = PBF_REG_COS0_UPPER_BOUND_P1;
648 max_cos = DCBX_E3B0_MAX_NUM_COS_PORT1;
649 }
650
651 for (i = 0; i < max_cos; i++)
652 REG_WR(bp, base_upper_bound + (i << 2), credit_upper_bound);
653}
654
655/******************************************************************************
656* Description:
657* Will return the PBF ETS registers to init values.Except
658* credit_upper_bound.
659* That isn't used in this configuration (No WFQ is enabled) and will be
660* configured acording to spec
661*.
662******************************************************************************/
663static void bnx2x_ets_e3b0_pbf_disabled(const struct link_params *params)
664{
665 struct bnx2x *bp = params->bp;
666 const u8 port = params->port;
667 const u32 min_w_val_pbf = ETS_E3B0_PBF_MIN_W_VAL;
668 u8 i = 0;
669 u32 base_weight = 0;
670 u8 max_cos = 0;
671
672 /**
673 * mapping between entry priority to client number 0 - COS0
674 * client, 2 - COS1, ... 5 - COS5)(HIGHEST) 4bits client num.
675 * TODO_ETS - Should be done by reset value or init tool
676 */
677 if (port)
678 /* 0x688 (|011|0 10|00 1|000) */
679 REG_WR(bp, PBF_REG_ETS_ARB_PRIORITY_CLIENT_P1 , 0x688);
680 else
681 /* (10 1|100 |011|0 10|00 1|000) */
682 REG_WR(bp, PBF_REG_ETS_ARB_PRIORITY_CLIENT_P0 , 0x2C688);
683
684 /* TODO_ETS - Should be done by reset value or init tool */
685 if (port)
686 /* 0x688 (|011|0 10|00 1|000)*/
687 REG_WR(bp, PBF_REG_ETS_ARB_CLIENT_CREDIT_MAP_P1, 0x688);
688 else
689 /* 0x2C688 (10 1|100 |011|0 10|00 1|000) */
690 REG_WR(bp, PBF_REG_ETS_ARB_CLIENT_CREDIT_MAP_P0, 0x2C688);
691
692 REG_WR(bp, (port) ? PBF_REG_ETS_ARB_NUM_STRICT_ARB_SLOTS_P1 :
693 PBF_REG_ETS_ARB_NUM_STRICT_ARB_SLOTS_P0 , 0x100);
694
695
696 REG_WR(bp, (port) ? PBF_REG_ETS_ARB_CLIENT_IS_STRICT_P1 :
697 PBF_REG_ETS_ARB_CLIENT_IS_STRICT_P0 , 0);
698
699 REG_WR(bp, (port) ? PBF_REG_ETS_ARB_CLIENT_IS_SUBJECT2WFQ_P1 :
700 PBF_REG_ETS_ARB_CLIENT_IS_SUBJECT2WFQ_P0 , 0);
701 /**
702 * In 2 port mode port0 has COS0-5 that can be used for WFQ.
703 * In 4 port mode port1 has COS0-2 that can be used for WFQ.
704 */
705 if (0 == port) {
706 base_weight = PBF_REG_COS0_WEIGHT_P0;
707 max_cos = DCBX_E3B0_MAX_NUM_COS_PORT0;
708 } else {
709 base_weight = PBF_REG_COS0_WEIGHT_P1;
710 max_cos = DCBX_E3B0_MAX_NUM_COS_PORT1;
711 }
712
713 for (i = 0; i < max_cos; i++)
714 REG_WR(bp, base_weight + (0x4 * i), 0);
715
716 bnx2x_ets_e3b0_set_credit_upper_bound_pbf(params, min_w_val_pbf);
717}
718/******************************************************************************
719* Description:
720* E3B0 disable will return basicly the values to init values.
721*.
722******************************************************************************/
723static int bnx2x_ets_e3b0_disabled(const struct link_params *params,
724 const struct link_vars *vars)
725{
726 struct bnx2x *bp = params->bp;
727
728 if (!CHIP_IS_E3B0(bp)) {
Joe Perches94f05b02011-08-14 12:16:20 +0000729 DP(NETIF_MSG_LINK,
730 "bnx2x_ets_e3b0_disabled the chip isn't E3B0\n");
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000731 return -EINVAL;
732 }
733
734 bnx2x_ets_e3b0_nig_disabled(params, vars);
735
736 bnx2x_ets_e3b0_pbf_disabled(params);
737
738 return 0;
739}
740
741/******************************************************************************
742* Description:
743* Disable will return basicly the values to init values.
744*.
745******************************************************************************/
746int bnx2x_ets_disabled(struct link_params *params,
747 struct link_vars *vars)
748{
749 struct bnx2x *bp = params->bp;
750 int bnx2x_status = 0;
751
752 if ((CHIP_IS_E2(bp)) || (CHIP_IS_E3A0(bp)))
753 bnx2x_ets_e2e3a0_disabled(params);
754 else if (CHIP_IS_E3B0(bp))
755 bnx2x_status = bnx2x_ets_e3b0_disabled(params, vars);
756 else {
757 DP(NETIF_MSG_LINK, "bnx2x_ets_disabled - chip not supported\n");
758 return -EINVAL;
759 }
760
761 return bnx2x_status;
762}
763
764/******************************************************************************
765* Description
766* Set the COS mappimg to SP and BW until this point all the COS are not
767* set as SP or BW.
768******************************************************************************/
769static int bnx2x_ets_e3b0_cli_map(const struct link_params *params,
770 const struct bnx2x_ets_params *ets_params,
771 const u8 cos_sp_bitmap,
772 const u8 cos_bw_bitmap)
773{
774 struct bnx2x *bp = params->bp;
775 const u8 port = params->port;
776 const u8 nig_cli_sp_bitmap = 0x7 | (cos_sp_bitmap << 3);
777 const u8 pbf_cli_sp_bitmap = cos_sp_bitmap;
778 const u8 nig_cli_subject2wfq_bitmap = cos_bw_bitmap << 3;
779 const u8 pbf_cli_subject2wfq_bitmap = cos_bw_bitmap;
780
781 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CLIENT_IS_STRICT :
782 NIG_REG_P0_TX_ARB_CLIENT_IS_STRICT, nig_cli_sp_bitmap);
783
784 REG_WR(bp, (port) ? PBF_REG_ETS_ARB_CLIENT_IS_STRICT_P1 :
785 PBF_REG_ETS_ARB_CLIENT_IS_STRICT_P0 , pbf_cli_sp_bitmap);
786
787 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CLIENT_IS_SUBJECT2WFQ :
788 NIG_REG_P0_TX_ARB_CLIENT_IS_SUBJECT2WFQ,
789 nig_cli_subject2wfq_bitmap);
790
791 REG_WR(bp, (port) ? PBF_REG_ETS_ARB_CLIENT_IS_SUBJECT2WFQ_P1 :
792 PBF_REG_ETS_ARB_CLIENT_IS_SUBJECT2WFQ_P0,
793 pbf_cli_subject2wfq_bitmap);
794
795 return 0;
796}
797
798/******************************************************************************
799* Description:
800* This function is needed because NIG ARB_CREDIT_WEIGHT_X are
801* not continues and ARB_CREDIT_WEIGHT_0 + offset is suitable.
802******************************************************************************/
803static int bnx2x_ets_e3b0_set_cos_bw(struct bnx2x *bp,
804 const u8 cos_entry,
805 const u32 min_w_val_nig,
806 const u32 min_w_val_pbf,
807 const u16 total_bw,
808 const u8 bw,
809 const u8 port)
810{
811 u32 nig_reg_adress_crd_weight = 0;
812 u32 pbf_reg_adress_crd_weight = 0;
David S. Miller8decf862011-09-22 03:23:13 -0400813 /* Calculate and set BW for this COS - use 1 instead of 0 for BW */
814 const u32 cos_bw_nig = ((bw ? bw : 1) * min_w_val_nig) / total_bw;
815 const u32 cos_bw_pbf = ((bw ? bw : 1) * min_w_val_pbf) / total_bw;
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000816
817 switch (cos_entry) {
818 case 0:
819 nig_reg_adress_crd_weight =
820 (port) ? NIG_REG_P1_TX_ARB_CREDIT_WEIGHT_0 :
821 NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_0;
822 pbf_reg_adress_crd_weight = (port) ?
823 PBF_REG_COS0_WEIGHT_P1 : PBF_REG_COS0_WEIGHT_P0;
824 break;
825 case 1:
826 nig_reg_adress_crd_weight = (port) ?
827 NIG_REG_P1_TX_ARB_CREDIT_WEIGHT_1 :
828 NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_1;
829 pbf_reg_adress_crd_weight = (port) ?
830 PBF_REG_COS1_WEIGHT_P1 : PBF_REG_COS1_WEIGHT_P0;
831 break;
832 case 2:
833 nig_reg_adress_crd_weight = (port) ?
834 NIG_REG_P1_TX_ARB_CREDIT_WEIGHT_2 :
835 NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_2;
836
837 pbf_reg_adress_crd_weight = (port) ?
838 PBF_REG_COS2_WEIGHT_P1 : PBF_REG_COS2_WEIGHT_P0;
839 break;
840 case 3:
841 if (port)
842 return -EINVAL;
843 nig_reg_adress_crd_weight =
844 NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_3;
845 pbf_reg_adress_crd_weight =
846 PBF_REG_COS3_WEIGHT_P0;
847 break;
848 case 4:
849 if (port)
850 return -EINVAL;
851 nig_reg_adress_crd_weight =
852 NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_4;
853 pbf_reg_adress_crd_weight = PBF_REG_COS4_WEIGHT_P0;
854 break;
855 case 5:
856 if (port)
857 return -EINVAL;
858 nig_reg_adress_crd_weight =
859 NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_5;
860 pbf_reg_adress_crd_weight = PBF_REG_COS5_WEIGHT_P0;
861 break;
862 }
863
864 REG_WR(bp, nig_reg_adress_crd_weight, cos_bw_nig);
865
866 REG_WR(bp, pbf_reg_adress_crd_weight, cos_bw_pbf);
867
868 return 0;
869}
870/******************************************************************************
871* Description:
872* Calculate the total BW.A value of 0 isn't legal.
873*.
874******************************************************************************/
875static int bnx2x_ets_e3b0_get_total_bw(
876 const struct link_params *params,
877 const struct bnx2x_ets_params *ets_params,
878 u16 *total_bw)
879{
880 struct bnx2x *bp = params->bp;
881 u8 cos_idx = 0;
882
883 *total_bw = 0 ;
884 /* Calculate total BW requested */
885 for (cos_idx = 0; cos_idx < ets_params->num_of_cos; cos_idx++) {
886 if (bnx2x_cos_state_bw == ets_params->cos[cos_idx].state) {
David S. Miller8decf862011-09-22 03:23:13 -0400887 *total_bw +=
888 ets_params->cos[cos_idx].params.bw_params.bw;
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000889 }
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000890 }
891
David S. Miller8decf862011-09-22 03:23:13 -0400892 /* Check total BW is valid */
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000893 if ((100 != *total_bw) || (0 == *total_bw)) {
894 if (0 == *total_bw) {
Joe Perches94f05b02011-08-14 12:16:20 +0000895 DP(NETIF_MSG_LINK,
896 "bnx2x_ets_E3B0_config toatl BW shouldn't be 0\n");
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000897 return -EINVAL;
898 }
Joe Perches94f05b02011-08-14 12:16:20 +0000899 DP(NETIF_MSG_LINK,
900 "bnx2x_ets_E3B0_config toatl BW should be 100\n");
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000901 /**
902 * We can handle a case whre the BW isn't 100 this can happen
903 * if the TC are joined.
904 */
905 }
906 return 0;
907}
908
909/******************************************************************************
910* Description:
911* Invalidate all the sp_pri_to_cos.
912*.
913******************************************************************************/
914static void bnx2x_ets_e3b0_sp_pri_to_cos_init(u8 *sp_pri_to_cos)
915{
916 u8 pri = 0;
917 for (pri = 0; pri < DCBX_MAX_NUM_COS; pri++)
918 sp_pri_to_cos[pri] = DCBX_INVALID_COS;
919}
920/******************************************************************************
921* Description:
922* Calculate and set the SP (ARB_PRIORITY_CLIENT) NIG and PBF registers
923* according to sp_pri_to_cos.
924*.
925******************************************************************************/
926static int bnx2x_ets_e3b0_sp_pri_to_cos_set(const struct link_params *params,
927 u8 *sp_pri_to_cos, const u8 pri,
928 const u8 cos_entry)
929{
930 struct bnx2x *bp = params->bp;
931 const u8 port = params->port;
932 const u8 max_num_of_cos = (port) ? DCBX_E3B0_MAX_NUM_COS_PORT1 :
933 DCBX_E3B0_MAX_NUM_COS_PORT0;
934
935 if (DCBX_INVALID_COS != sp_pri_to_cos[pri]) {
936 DP(NETIF_MSG_LINK, "bnx2x_ets_e3b0_sp_pri_to_cos_set invalid "
Joe Perches94f05b02011-08-14 12:16:20 +0000937 "parameter There can't be two COS's with "
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000938 "the same strict pri\n");
939 return -EINVAL;
940 }
941
942 if (pri > max_num_of_cos) {
Joe Perches94f05b02011-08-14 12:16:20 +0000943 DP(NETIF_MSG_LINK, "bnx2x_ets_e3b0_sp_pri_to_cos_set invalid "
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000944 "parameter Illegal strict priority\n");
945 return -EINVAL;
946 }
947
948 sp_pri_to_cos[pri] = cos_entry;
949 return 0;
950
951}
952
953/******************************************************************************
954* Description:
955* Returns the correct value according to COS and priority in
956* the sp_pri_cli register.
957*.
958******************************************************************************/
959static u64 bnx2x_e3b0_sp_get_pri_cli_reg(const u8 cos, const u8 cos_offset,
960 const u8 pri_set,
961 const u8 pri_offset,
962 const u8 entry_size)
963{
964 u64 pri_cli_nig = 0;
965 pri_cli_nig = ((u64)(cos + cos_offset)) << (entry_size *
966 (pri_set + pri_offset));
967
968 return pri_cli_nig;
969}
970/******************************************************************************
971* Description:
972* Returns the correct value according to COS and priority in the
973* sp_pri_cli register for NIG.
974*.
975******************************************************************************/
976static u64 bnx2x_e3b0_sp_get_pri_cli_reg_nig(const u8 cos, const u8 pri_set)
977{
978 /* MCP Dbg0 and dbg1 are always with higher strict pri*/
979 const u8 nig_cos_offset = 3;
980 const u8 nig_pri_offset = 3;
981
982 return bnx2x_e3b0_sp_get_pri_cli_reg(cos, nig_cos_offset, pri_set,
983 nig_pri_offset, 4);
984
985}
986/******************************************************************************
987* Description:
988* Returns the correct value according to COS and priority in the
989* sp_pri_cli register for PBF.
990*.
991******************************************************************************/
992static u64 bnx2x_e3b0_sp_get_pri_cli_reg_pbf(const u8 cos, const u8 pri_set)
993{
994 const u8 pbf_cos_offset = 0;
995 const u8 pbf_pri_offset = 0;
996
997 return bnx2x_e3b0_sp_get_pri_cli_reg(cos, pbf_cos_offset, pri_set,
998 pbf_pri_offset, 3);
999
1000}
1001
1002/******************************************************************************
1003* Description:
1004* Calculate and set the SP (ARB_PRIORITY_CLIENT) NIG and PBF registers
1005* according to sp_pri_to_cos.(which COS has higher priority)
1006*.
1007******************************************************************************/
1008static int bnx2x_ets_e3b0_sp_set_pri_cli_reg(const struct link_params *params,
1009 u8 *sp_pri_to_cos)
1010{
1011 struct bnx2x *bp = params->bp;
1012 u8 i = 0;
1013 const u8 port = params->port;
1014 /* MCP Dbg0 and dbg1 are always with higher strict pri*/
1015 u64 pri_cli_nig = 0x210;
1016 u32 pri_cli_pbf = 0x0;
1017 u8 pri_set = 0;
1018 u8 pri_bitmask = 0;
1019 const u8 max_num_of_cos = (port) ? DCBX_E3B0_MAX_NUM_COS_PORT1 :
1020 DCBX_E3B0_MAX_NUM_COS_PORT0;
1021
1022 u8 cos_bit_to_set = (1 << max_num_of_cos) - 1;
1023
1024 /* Set all the strict priority first */
1025 for (i = 0; i < max_num_of_cos; i++) {
1026 if (DCBX_INVALID_COS != sp_pri_to_cos[i]) {
1027 if (DCBX_MAX_NUM_COS <= sp_pri_to_cos[i]) {
1028 DP(NETIF_MSG_LINK,
1029 "bnx2x_ets_e3b0_sp_set_pri_cli_reg "
1030 "invalid cos entry\n");
1031 return -EINVAL;
1032 }
1033
1034 pri_cli_nig |= bnx2x_e3b0_sp_get_pri_cli_reg_nig(
1035 sp_pri_to_cos[i], pri_set);
1036
1037 pri_cli_pbf |= bnx2x_e3b0_sp_get_pri_cli_reg_pbf(
1038 sp_pri_to_cos[i], pri_set);
1039 pri_bitmask = 1 << sp_pri_to_cos[i];
1040 /* COS is used remove it from bitmap.*/
1041 if (0 == (pri_bitmask & cos_bit_to_set)) {
1042 DP(NETIF_MSG_LINK,
1043 "bnx2x_ets_e3b0_sp_set_pri_cli_reg "
1044 "invalid There can't be two COS's with"
1045 " the same strict pri\n");
1046 return -EINVAL;
1047 }
1048 cos_bit_to_set &= ~pri_bitmask;
1049 pri_set++;
1050 }
1051 }
1052
1053 /* Set all the Non strict priority i= COS*/
1054 for (i = 0; i < max_num_of_cos; i++) {
1055 pri_bitmask = 1 << i;
1056 /* Check if COS was already used for SP */
1057 if (pri_bitmask & cos_bit_to_set) {
1058 /* COS wasn't used for SP */
1059 pri_cli_nig |= bnx2x_e3b0_sp_get_pri_cli_reg_nig(
1060 i, pri_set);
1061
1062 pri_cli_pbf |= bnx2x_e3b0_sp_get_pri_cli_reg_pbf(
1063 i, pri_set);
1064 /* COS is used remove it from bitmap.*/
1065 cos_bit_to_set &= ~pri_bitmask;
1066 pri_set++;
1067 }
1068 }
1069
1070 if (pri_set != max_num_of_cos) {
1071 DP(NETIF_MSG_LINK, "bnx2x_ets_e3b0_sp_set_pri_cli_reg not all "
1072 "entries were set\n");
1073 return -EINVAL;
1074 }
1075
1076 if (port) {
1077 /* Only 6 usable clients*/
1078 REG_WR(bp, NIG_REG_P1_TX_ARB_PRIORITY_CLIENT2_LSB,
1079 (u32)pri_cli_nig);
1080
1081 REG_WR(bp, PBF_REG_ETS_ARB_PRIORITY_CLIENT_P1 , pri_cli_pbf);
1082 } else {
1083 /* Only 9 usable clients*/
1084 const u32 pri_cli_nig_lsb = (u32) (pri_cli_nig);
1085 const u32 pri_cli_nig_msb = (u32) ((pri_cli_nig >> 32) & 0xF);
1086
1087 REG_WR(bp, NIG_REG_P0_TX_ARB_PRIORITY_CLIENT2_LSB,
1088 pri_cli_nig_lsb);
1089 REG_WR(bp, NIG_REG_P0_TX_ARB_PRIORITY_CLIENT2_MSB,
1090 pri_cli_nig_msb);
1091
1092 REG_WR(bp, PBF_REG_ETS_ARB_PRIORITY_CLIENT_P0 , pri_cli_pbf);
1093 }
1094 return 0;
1095}
1096
1097/******************************************************************************
1098* Description:
1099* Configure the COS to ETS according to BW and SP settings.
1100******************************************************************************/
1101int bnx2x_ets_e3b0_config(const struct link_params *params,
1102 const struct link_vars *vars,
1103 const struct bnx2x_ets_params *ets_params)
1104{
1105 struct bnx2x *bp = params->bp;
1106 int bnx2x_status = 0;
1107 const u8 port = params->port;
1108 u16 total_bw = 0;
1109 const u32 min_w_val_nig = bnx2x_ets_get_min_w_val_nig(vars);
1110 const u32 min_w_val_pbf = ETS_E3B0_PBF_MIN_W_VAL;
1111 u8 cos_bw_bitmap = 0;
1112 u8 cos_sp_bitmap = 0;
1113 u8 sp_pri_to_cos[DCBX_MAX_NUM_COS] = {0};
1114 const u8 max_num_of_cos = (port) ? DCBX_E3B0_MAX_NUM_COS_PORT1 :
1115 DCBX_E3B0_MAX_NUM_COS_PORT0;
1116 u8 cos_entry = 0;
1117
1118 if (!CHIP_IS_E3B0(bp)) {
Joe Perches94f05b02011-08-14 12:16:20 +00001119 DP(NETIF_MSG_LINK,
1120 "bnx2x_ets_e3b0_disabled the chip isn't E3B0\n");
Yaniv Rosner6c3218c2011-06-14 01:34:23 +00001121 return -EINVAL;
1122 }
1123
1124 if ((ets_params->num_of_cos > max_num_of_cos)) {
1125 DP(NETIF_MSG_LINK, "bnx2x_ets_E3B0_config the number of COS "
1126 "isn't supported\n");
1127 return -EINVAL;
1128 }
1129
1130 /* Prepare sp strict priority parameters*/
1131 bnx2x_ets_e3b0_sp_pri_to_cos_init(sp_pri_to_cos);
1132
1133 /* Prepare BW parameters*/
1134 bnx2x_status = bnx2x_ets_e3b0_get_total_bw(params, ets_params,
1135 &total_bw);
1136 if (0 != bnx2x_status) {
Joe Perches94f05b02011-08-14 12:16:20 +00001137 DP(NETIF_MSG_LINK,
1138 "bnx2x_ets_E3B0_config get_total_bw failed\n");
Yaniv Rosner6c3218c2011-06-14 01:34:23 +00001139 return -EINVAL;
1140 }
1141
1142 /**
1143 * Upper bound is set according to current link speed (min_w_val
1144 * should be the same for upper bound and COS credit val).
1145 */
1146 bnx2x_ets_e3b0_set_credit_upper_bound_nig(params, min_w_val_nig);
1147 bnx2x_ets_e3b0_set_credit_upper_bound_pbf(params, min_w_val_pbf);
1148
1149
1150 for (cos_entry = 0; cos_entry < ets_params->num_of_cos; cos_entry++) {
1151 if (bnx2x_cos_state_bw == ets_params->cos[cos_entry].state) {
1152 cos_bw_bitmap |= (1 << cos_entry);
1153 /**
1154 * The function also sets the BW in HW(not the mappin
1155 * yet)
1156 */
1157 bnx2x_status = bnx2x_ets_e3b0_set_cos_bw(
1158 bp, cos_entry, min_w_val_nig, min_w_val_pbf,
1159 total_bw,
1160 ets_params->cos[cos_entry].params.bw_params.bw,
1161 port);
1162 } else if (bnx2x_cos_state_strict ==
1163 ets_params->cos[cos_entry].state){
1164 cos_sp_bitmap |= (1 << cos_entry);
1165
1166 bnx2x_status = bnx2x_ets_e3b0_sp_pri_to_cos_set(
1167 params,
1168 sp_pri_to_cos,
1169 ets_params->cos[cos_entry].params.sp_params.pri,
1170 cos_entry);
1171
1172 } else {
Joe Perches94f05b02011-08-14 12:16:20 +00001173 DP(NETIF_MSG_LINK,
1174 "bnx2x_ets_e3b0_config cos state not valid\n");
Yaniv Rosner6c3218c2011-06-14 01:34:23 +00001175 return -EINVAL;
1176 }
1177 if (0 != bnx2x_status) {
Joe Perches94f05b02011-08-14 12:16:20 +00001178 DP(NETIF_MSG_LINK,
1179 "bnx2x_ets_e3b0_config set cos bw failed\n");
Yaniv Rosner6c3218c2011-06-14 01:34:23 +00001180 return bnx2x_status;
1181 }
1182 }
1183
1184 /* Set SP register (which COS has higher priority) */
1185 bnx2x_status = bnx2x_ets_e3b0_sp_set_pri_cli_reg(params,
1186 sp_pri_to_cos);
1187
1188 if (0 != bnx2x_status) {
Joe Perches94f05b02011-08-14 12:16:20 +00001189 DP(NETIF_MSG_LINK,
1190 "bnx2x_ets_E3B0_config set_pri_cli_reg failed\n");
Yaniv Rosner6c3218c2011-06-14 01:34:23 +00001191 return bnx2x_status;
1192 }
1193
1194 /* Set client mapping of BW and strict */
1195 bnx2x_status = bnx2x_ets_e3b0_cli_map(params, ets_params,
1196 cos_sp_bitmap,
1197 cos_bw_bitmap);
1198
1199 if (0 != bnx2x_status) {
1200 DP(NETIF_MSG_LINK, "bnx2x_ets_E3B0_config SP failed\n");
1201 return bnx2x_status;
1202 }
1203 return 0;
1204}
Yaniv Rosner65a001b2011-01-31 04:22:03 +00001205static void bnx2x_ets_bw_limit_common(const struct link_params *params)
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001206{
1207 /* ETS disabled configuration */
1208 struct bnx2x *bp = params->bp;
1209 DP(NETIF_MSG_LINK, "ETS enabled BW limit configuration\n");
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00001210 /*
1211 * defines which entries (clients) are subjected to WFQ arbitration
1212 * COS0 0x8
1213 * COS1 0x10
1214 */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001215 REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_IS_SUBJECT2WFQ, 0x18);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00001216 /*
1217 * mapping between the ARB_CREDIT_WEIGHT registers and actual
1218 * client numbers (WEIGHT_0 does not actually have to represent
1219 * client 0)
1220 * PRI4 | PRI3 | PRI2 | PRI1 | PRI0
1221 * cos1-001 cos0-000 dbg1-100 dbg0-011 MCP-010
1222 */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001223 REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_CREDIT_MAP, 0x111A);
1224
1225 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_0,
1226 ETS_BW_LIMIT_CREDIT_UPPER_BOUND);
1227 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_1,
1228 ETS_BW_LIMIT_CREDIT_UPPER_BOUND);
1229
1230 /* ETS mode enabled*/
1231 REG_WR(bp, PBF_REG_ETS_ENABLED, 1);
1232
1233 /* Defines the number of consecutive slots for the strict priority */
1234 REG_WR(bp, PBF_REG_NUM_STRICT_ARB_SLOTS, 0);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00001235 /*
1236 * Bitmap of 5bits length. Each bit specifies whether the entry behaves
1237 * as strict. Bits 0,1,2 - debug and management entries, 3 - COS0
1238 * entry, 4 - COS1 entry.
1239 * COS1 | COS0 | DEBUG21 | DEBUG0 | MGMT
1240 * bit4 bit3 bit2 bit1 bit0
1241 * MCP and debug are strict
1242 */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001243 REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_IS_STRICT, 0x7);
1244
1245 /* Upper bound that COS0_WEIGHT can reach in the WFQ arbiter.*/
1246 REG_WR(bp, PBF_REG_COS0_UPPER_BOUND,
1247 ETS_BW_LIMIT_CREDIT_UPPER_BOUND);
1248 REG_WR(bp, PBF_REG_COS1_UPPER_BOUND,
1249 ETS_BW_LIMIT_CREDIT_UPPER_BOUND);
1250}
1251
1252void bnx2x_ets_bw_limit(const struct link_params *params, const u32 cos0_bw,
1253 const u32 cos1_bw)
1254{
1255 /* ETS disabled configuration*/
1256 struct bnx2x *bp = params->bp;
1257 const u32 total_bw = cos0_bw + cos1_bw;
1258 u32 cos0_credit_weight = 0;
1259 u32 cos1_credit_weight = 0;
1260
1261 DP(NETIF_MSG_LINK, "ETS enabled BW limit configuration\n");
1262
1263 if ((0 == total_bw) ||
1264 (0 == cos0_bw) ||
1265 (0 == cos1_bw)) {
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001266 DP(NETIF_MSG_LINK, "Total BW can't be zero\n");
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001267 return;
1268 }
1269
1270 cos0_credit_weight = (cos0_bw * ETS_BW_LIMIT_CREDIT_WEIGHT)/
1271 total_bw;
1272 cos1_credit_weight = (cos1_bw * ETS_BW_LIMIT_CREDIT_WEIGHT)/
1273 total_bw;
1274
1275 bnx2x_ets_bw_limit_common(params);
1276
1277 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_0, cos0_credit_weight);
1278 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_1, cos1_credit_weight);
1279
1280 REG_WR(bp, PBF_REG_COS0_WEIGHT, cos0_credit_weight);
1281 REG_WR(bp, PBF_REG_COS1_WEIGHT, cos1_credit_weight);
1282}
1283
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00001284int bnx2x_ets_strict(const struct link_params *params, const u8 strict_cos)
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001285{
1286 /* ETS disabled configuration*/
1287 struct bnx2x *bp = params->bp;
1288 u32 val = 0;
1289
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001290 DP(NETIF_MSG_LINK, "ETS enabled strict configuration\n");
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00001291 /*
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001292 * Bitmap of 5bits length. Each bit specifies whether the entry behaves
1293 * as strict. Bits 0,1,2 - debug and management entries,
1294 * 3 - COS0 entry, 4 - COS1 entry.
1295 * COS1 | COS0 | DEBUG21 | DEBUG0 | MGMT
1296 * bit4 bit3 bit2 bit1 bit0
1297 * MCP and debug are strict
1298 */
1299 REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_IS_STRICT, 0x1F);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00001300 /*
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001301 * For strict priority entries defines the number of consecutive slots
1302 * for the highest priority.
1303 */
1304 REG_WR(bp, NIG_REG_P0_TX_ARB_NUM_STRICT_ARB_SLOTS, 0x100);
1305 /* ETS mode disable */
1306 REG_WR(bp, PBF_REG_ETS_ENABLED, 0);
1307 /* Defines the number of consecutive slots for the strict priority */
1308 REG_WR(bp, PBF_REG_NUM_STRICT_ARB_SLOTS, 0x100);
1309
1310 /* Defines the number of consecutive slots for the strict priority */
1311 REG_WR(bp, PBF_REG_HIGH_PRIORITY_COS_NUM, strict_cos);
1312
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00001313 /*
1314 * mapping between entry priority to client number (0,1,2 -debug and
1315 * management clients, 3 - COS0 client, 4 - COS client)(HIGHEST)
1316 * 3bits client num.
1317 * PRI4 | PRI3 | PRI2 | PRI1 | PRI0
1318 * dbg0-010 dbg1-001 cos1-100 cos0-011 MCP-000
1319 * dbg0-010 dbg1-001 cos0-011 cos1-100 MCP-000
1320 */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001321 val = (0 == strict_cos) ? 0x2318 : 0x22E0;
1322 REG_WR(bp, NIG_REG_P0_TX_ARB_PRIORITY_CLIENT, val);
1323
1324 return 0;
1325}
1326/******************************************************************/
Dmitry Kravkove8920672011-05-04 23:52:40 +00001327/* PFC section */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001328/******************************************************************/
1329
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001330static void bnx2x_update_pfc_xmac(struct link_params *params,
1331 struct link_vars *vars,
1332 u8 is_lb)
1333{
1334 struct bnx2x *bp = params->bp;
1335 u32 xmac_base;
1336 u32 pause_val, pfc0_val, pfc1_val;
1337
1338 /* XMAC base adrr */
1339 xmac_base = (params->port) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
1340
1341 /* Initialize pause and pfc registers */
1342 pause_val = 0x18000;
1343 pfc0_val = 0xFFFF8000;
1344 pfc1_val = 0x2;
1345
1346 /* No PFC support */
1347 if (!(params->feature_config_flags &
1348 FEATURE_CONFIG_PFC_ENABLED)) {
1349
1350 /*
1351 * RX flow control - Process pause frame in receive direction
1352 */
1353 if (vars->flow_ctrl & BNX2X_FLOW_CTRL_RX)
1354 pause_val |= XMAC_PAUSE_CTRL_REG_RX_PAUSE_EN;
1355
1356 /*
1357 * TX flow control - Send pause packet when buffer is full
1358 */
1359 if (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX)
1360 pause_val |= XMAC_PAUSE_CTRL_REG_TX_PAUSE_EN;
1361 } else {/* PFC support */
1362 pfc1_val |= XMAC_PFC_CTRL_HI_REG_PFC_REFRESH_EN |
1363 XMAC_PFC_CTRL_HI_REG_PFC_STATS_EN |
1364 XMAC_PFC_CTRL_HI_REG_RX_PFC_EN |
1365 XMAC_PFC_CTRL_HI_REG_TX_PFC_EN;
1366 }
1367
1368 /* Write pause and PFC registers */
1369 REG_WR(bp, xmac_base + XMAC_REG_PAUSE_CTRL, pause_val);
1370 REG_WR(bp, xmac_base + XMAC_REG_PFC_CTRL, pfc0_val);
1371 REG_WR(bp, xmac_base + XMAC_REG_PFC_CTRL_HI, pfc1_val);
1372
Yaniv Rosnerb8d6d082011-07-05 01:06:27 +00001373
1374 /* Set MAC address for source TX Pause/PFC frames */
1375 REG_WR(bp, xmac_base + XMAC_REG_CTRL_SA_LO,
1376 ((params->mac_addr[2] << 24) |
1377 (params->mac_addr[3] << 16) |
1378 (params->mac_addr[4] << 8) |
1379 (params->mac_addr[5])));
1380 REG_WR(bp, xmac_base + XMAC_REG_CTRL_SA_HI,
1381 ((params->mac_addr[0] << 8) |
1382 (params->mac_addr[1])));
1383
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001384 udelay(30);
1385}
1386
1387
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001388static void bnx2x_emac_get_pfc_stat(struct link_params *params,
1389 u32 pfc_frames_sent[2],
1390 u32 pfc_frames_received[2])
1391{
1392 /* Read pfc statistic */
1393 struct bnx2x *bp = params->bp;
1394 u32 emac_base = params->port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
1395 u32 val_xon = 0;
1396 u32 val_xoff = 0;
1397
1398 DP(NETIF_MSG_LINK, "pfc statistic read from EMAC\n");
1399
1400 /* PFC received frames */
1401 val_xoff = REG_RD(bp, emac_base +
1402 EMAC_REG_RX_PFC_STATS_XOFF_RCVD);
1403 val_xoff &= EMAC_REG_RX_PFC_STATS_XOFF_RCVD_COUNT;
1404 val_xon = REG_RD(bp, emac_base + EMAC_REG_RX_PFC_STATS_XON_RCVD);
1405 val_xon &= EMAC_REG_RX_PFC_STATS_XON_RCVD_COUNT;
1406
1407 pfc_frames_received[0] = val_xon + val_xoff;
1408
1409 /* PFC received sent */
1410 val_xoff = REG_RD(bp, emac_base +
1411 EMAC_REG_RX_PFC_STATS_XOFF_SENT);
1412 val_xoff &= EMAC_REG_RX_PFC_STATS_XOFF_SENT_COUNT;
1413 val_xon = REG_RD(bp, emac_base + EMAC_REG_RX_PFC_STATS_XON_SENT);
1414 val_xon &= EMAC_REG_RX_PFC_STATS_XON_SENT_COUNT;
1415
1416 pfc_frames_sent[0] = val_xon + val_xoff;
1417}
1418
Yaniv Rosnerb8d6d082011-07-05 01:06:27 +00001419/* Read pfc statistic*/
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001420void bnx2x_pfc_statistic(struct link_params *params, struct link_vars *vars,
1421 u32 pfc_frames_sent[2],
1422 u32 pfc_frames_received[2])
1423{
1424 /* Read pfc statistic */
1425 struct bnx2x *bp = params->bp;
Yaniv Rosnerb8d6d082011-07-05 01:06:27 +00001426
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001427 DP(NETIF_MSG_LINK, "pfc statistic\n");
1428
1429 if (!vars->link_up)
1430 return;
1431
Yaniv Rosnerb8d6d082011-07-05 01:06:27 +00001432 if (MAC_TYPE_EMAC == vars->mac_type) {
1433 DP(NETIF_MSG_LINK, "About to read PFC stats from EMAC\n");
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001434 bnx2x_emac_get_pfc_stat(params, pfc_frames_sent,
1435 pfc_frames_received);
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001436 }
1437}
1438/******************************************************************/
1439/* MAC/PBF section */
1440/******************************************************************/
Yaniv Rosnera198c142011-05-31 21:29:42 +00001441static void bnx2x_set_mdio_clk(struct bnx2x *bp, u32 chip_id, u8 port)
1442{
1443 u32 mode, emac_base;
1444 /**
1445 * Set clause 45 mode, slow down the MDIO clock to 2.5MHz
1446 * (a value of 49==0x31) and make sure that the AUTO poll is off
1447 */
1448
1449 if (CHIP_IS_E2(bp))
1450 emac_base = GRCBASE_EMAC0;
1451 else
1452 emac_base = (port) ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
1453 mode = REG_RD(bp, emac_base + EMAC_REG_EMAC_MDIO_MODE);
1454 mode &= ~(EMAC_MDIO_MODE_AUTO_POLL |
1455 EMAC_MDIO_MODE_CLOCK_CNT);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00001456 if (USES_WARPCORE(bp))
1457 mode |= (74L << EMAC_MDIO_MODE_CLOCK_CNT_BITSHIFT);
1458 else
1459 mode |= (49L << EMAC_MDIO_MODE_CLOCK_CNT_BITSHIFT);
Yaniv Rosnera198c142011-05-31 21:29:42 +00001460
1461 mode |= (EMAC_MDIO_MODE_CLAUSE_45);
1462 REG_WR(bp, emac_base + EMAC_REG_EMAC_MDIO_MODE, mode);
1463
1464 udelay(40);
1465}
1466
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001467static void bnx2x_emac_init(struct link_params *params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001468 struct link_vars *vars)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001469{
1470 /* reset and unreset the emac core */
1471 struct bnx2x *bp = params->bp;
1472 u8 port = params->port;
1473 u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
1474 u32 val;
1475 u16 timeout;
1476
1477 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001478 (MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE << port));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001479 udelay(5);
1480 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001481 (MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE << port));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001482
1483 /* init emac - use read-modify-write */
1484 /* self clear reset */
1485 val = REG_RD(bp, emac_base + EMAC_REG_EMAC_MODE);
Eilon Greenstein3196a882008-08-13 15:58:49 -07001486 EMAC_WR(bp, EMAC_REG_EMAC_MODE, (val | EMAC_MODE_RESET));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001487
1488 timeout = 200;
Eilon Greenstein3196a882008-08-13 15:58:49 -07001489 do {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001490 val = REG_RD(bp, emac_base + EMAC_REG_EMAC_MODE);
1491 DP(NETIF_MSG_LINK, "EMAC reset reg is %u\n", val);
1492 if (!timeout) {
1493 DP(NETIF_MSG_LINK, "EMAC timeout!\n");
1494 return;
1495 }
1496 timeout--;
Eilon Greenstein3196a882008-08-13 15:58:49 -07001497 } while (val & EMAC_MODE_RESET);
Yaniv Rosnera198c142011-05-31 21:29:42 +00001498 bnx2x_set_mdio_clk(bp, params->chip_id, port);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001499 /* Set mac address */
1500 val = ((params->mac_addr[0] << 8) |
1501 params->mac_addr[1]);
Eilon Greenstein3196a882008-08-13 15:58:49 -07001502 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001503
1504 val = ((params->mac_addr[2] << 24) |
1505 (params->mac_addr[3] << 16) |
1506 (params->mac_addr[4] << 8) |
1507 params->mac_addr[5]);
Eilon Greenstein3196a882008-08-13 15:58:49 -07001508 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + 4, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001509}
1510
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001511static void bnx2x_set_xumac_nig(struct link_params *params,
1512 u16 tx_pause_en,
1513 u8 enable)
1514{
1515 struct bnx2x *bp = params->bp;
1516
1517 REG_WR(bp, params->port ? NIG_REG_P1_MAC_IN_EN : NIG_REG_P0_MAC_IN_EN,
1518 enable);
1519 REG_WR(bp, params->port ? NIG_REG_P1_MAC_OUT_EN : NIG_REG_P0_MAC_OUT_EN,
1520 enable);
1521 REG_WR(bp, params->port ? NIG_REG_P1_MAC_PAUSE_OUT_EN :
1522 NIG_REG_P0_MAC_PAUSE_OUT_EN, tx_pause_en);
1523}
1524
Yaniv Rosnerce7c0482011-10-27 05:09:47 +00001525static void bnx2x_umac_disable(struct link_params *params)
1526{
1527 u32 umac_base = params->port ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
1528 struct bnx2x *bp = params->bp;
1529 if (!(REG_RD(bp, MISC_REG_RESET_REG_2) &
1530 (MISC_REGISTERS_RESET_REG_2_UMAC0 << params->port)))
1531 return;
1532
1533 /* Disable RX and TX */
1534 REG_WR(bp, umac_base + UMAC_REG_COMMAND_CONFIG, 0);
1535}
1536
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001537static void bnx2x_umac_enable(struct link_params *params,
1538 struct link_vars *vars, u8 lb)
1539{
1540 u32 val;
1541 u32 umac_base = params->port ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
1542 struct bnx2x *bp = params->bp;
1543 /* Reset UMAC */
1544 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
1545 (MISC_REGISTERS_RESET_REG_2_UMAC0 << params->port));
1546 usleep_range(1000, 1000);
1547
1548 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
1549 (MISC_REGISTERS_RESET_REG_2_UMAC0 << params->port));
1550
1551 DP(NETIF_MSG_LINK, "enabling UMAC\n");
1552
1553 /**
1554 * This register determines on which events the MAC will assert
1555 * error on the i/f to the NIG along w/ EOP.
1556 */
1557
1558 /**
1559 * BD REG_WR(bp, NIG_REG_P0_MAC_RSV_ERR_MASK +
1560 * params->port*0x14, 0xfffff.
1561 */
1562 /* This register opens the gate for the UMAC despite its name */
1563 REG_WR(bp, NIG_REG_EGRESS_EMAC0_PORT + params->port*4, 1);
1564
1565 val = UMAC_COMMAND_CONFIG_REG_PROMIS_EN |
1566 UMAC_COMMAND_CONFIG_REG_PAD_EN |
1567 UMAC_COMMAND_CONFIG_REG_SW_RESET |
1568 UMAC_COMMAND_CONFIG_REG_NO_LGTH_CHECK;
1569 switch (vars->line_speed) {
1570 case SPEED_10:
1571 val |= (0<<2);
1572 break;
1573 case SPEED_100:
1574 val |= (1<<2);
1575 break;
1576 case SPEED_1000:
1577 val |= (2<<2);
1578 break;
1579 case SPEED_2500:
1580 val |= (3<<2);
1581 break;
1582 default:
1583 DP(NETIF_MSG_LINK, "Invalid speed for UMAC %d\n",
1584 vars->line_speed);
1585 break;
1586 }
Yaniv Rosner9d5b36b2011-08-02 22:59:10 +00001587 if (!(vars->flow_ctrl & BNX2X_FLOW_CTRL_TX))
1588 val |= UMAC_COMMAND_CONFIG_REG_IGNORE_TX_PAUSE;
1589
1590 if (!(vars->flow_ctrl & BNX2X_FLOW_CTRL_RX))
1591 val |= UMAC_COMMAND_CONFIG_REG_PAUSE_IGNORE;
1592
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001593 REG_WR(bp, umac_base + UMAC_REG_COMMAND_CONFIG, val);
1594 udelay(50);
1595
Yaniv Rosnerb8d6d082011-07-05 01:06:27 +00001596 /* Set MAC address for source TX Pause/PFC frames (under SW reset) */
1597 REG_WR(bp, umac_base + UMAC_REG_MAC_ADDR0,
1598 ((params->mac_addr[2] << 24) |
1599 (params->mac_addr[3] << 16) |
1600 (params->mac_addr[4] << 8) |
1601 (params->mac_addr[5])));
1602 REG_WR(bp, umac_base + UMAC_REG_MAC_ADDR1,
1603 ((params->mac_addr[0] << 8) |
1604 (params->mac_addr[1])));
1605
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001606 /* Enable RX and TX */
1607 val &= ~UMAC_COMMAND_CONFIG_REG_PAD_EN;
1608 val |= UMAC_COMMAND_CONFIG_REG_TX_ENA |
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00001609 UMAC_COMMAND_CONFIG_REG_RX_ENA;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001610 REG_WR(bp, umac_base + UMAC_REG_COMMAND_CONFIG, val);
1611 udelay(50);
1612
1613 /* Remove SW Reset */
1614 val &= ~UMAC_COMMAND_CONFIG_REG_SW_RESET;
1615
1616 /* Check loopback mode */
1617 if (lb)
1618 val |= UMAC_COMMAND_CONFIG_REG_LOOP_ENA;
1619 REG_WR(bp, umac_base + UMAC_REG_COMMAND_CONFIG, val);
1620
1621 /*
1622 * Maximum Frame Length (RW). Defines a 14-Bit maximum frame
1623 * length used by the MAC receive logic to check frames.
1624 */
1625 REG_WR(bp, umac_base + UMAC_REG_MAXFR, 0x2710);
1626 bnx2x_set_xumac_nig(params,
1627 ((vars->flow_ctrl & BNX2X_FLOW_CTRL_TX) != 0), 1);
1628 vars->mac_type = MAC_TYPE_UMAC;
1629
1630}
1631
1632static u8 bnx2x_is_4_port_mode(struct bnx2x *bp)
1633{
1634 u32 port4mode_ovwr_val;
1635 /* Check 4-port override enabled */
1636 port4mode_ovwr_val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
1637 if (port4mode_ovwr_val & (1<<0)) {
1638 /* Return 4-port mode override value */
1639 return ((port4mode_ovwr_val & (1<<1)) == (1<<1));
1640 }
1641 /* Return 4-port mode from input pin */
1642 return (u8)REG_RD(bp, MISC_REG_PORT4MODE_EN);
1643}
1644
1645/* Define the XMAC mode */
Yaniv Rosnerce7c0482011-10-27 05:09:47 +00001646static void bnx2x_xmac_init(struct link_params *params, u32 max_speed)
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001647{
Yaniv Rosnerce7c0482011-10-27 05:09:47 +00001648 struct bnx2x *bp = params->bp;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001649 u32 is_port4mode = bnx2x_is_4_port_mode(bp);
1650
1651 /**
1652 * In 4-port mode, need to set the mode only once, so if XMAC is
1653 * already out of reset, it means the mode has already been set,
1654 * and it must not* reset the XMAC again, since it controls both
1655 * ports of the path
1656 **/
1657
Yaniv Rosnerce7c0482011-10-27 05:09:47 +00001658 if ((CHIP_NUM(bp) == CHIP_NUM_57840) &&
1659 (REG_RD(bp, MISC_REG_RESET_REG_2) &
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001660 MISC_REGISTERS_RESET_REG_2_XMAC)) {
Joe Perches94f05b02011-08-14 12:16:20 +00001661 DP(NETIF_MSG_LINK,
1662 "XMAC already out of reset in 4-port mode\n");
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001663 return;
1664 }
1665
1666 /* Hard reset */
1667 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
1668 MISC_REGISTERS_RESET_REG_2_XMAC);
1669 usleep_range(1000, 1000);
1670
1671 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
1672 MISC_REGISTERS_RESET_REG_2_XMAC);
1673 if (is_port4mode) {
1674 DP(NETIF_MSG_LINK, "Init XMAC to 2 ports x 10G per path\n");
1675
1676 /* Set the number of ports on the system side to up to 2 */
1677 REG_WR(bp, MISC_REG_XMAC_CORE_PORT_MODE, 1);
1678
1679 /* Set the number of ports on the Warp Core to 10G */
1680 REG_WR(bp, MISC_REG_XMAC_PHY_PORT_MODE, 3);
1681 } else {
1682 /* Set the number of ports on the system side to 1 */
1683 REG_WR(bp, MISC_REG_XMAC_CORE_PORT_MODE, 0);
1684 if (max_speed == SPEED_10000) {
Joe Perches94f05b02011-08-14 12:16:20 +00001685 DP(NETIF_MSG_LINK,
1686 "Init XMAC to 10G x 1 port per path\n");
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001687 /* Set the number of ports on the Warp Core to 10G */
1688 REG_WR(bp, MISC_REG_XMAC_PHY_PORT_MODE, 3);
1689 } else {
Joe Perches94f05b02011-08-14 12:16:20 +00001690 DP(NETIF_MSG_LINK,
1691 "Init XMAC to 20G x 2 ports per path\n");
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001692 /* Set the number of ports on the Warp Core to 20G */
1693 REG_WR(bp, MISC_REG_XMAC_PHY_PORT_MODE, 1);
1694 }
1695 }
1696 /* Soft reset */
1697 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
1698 MISC_REGISTERS_RESET_REG_2_XMAC_SOFT);
1699 usleep_range(1000, 1000);
1700
1701 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
1702 MISC_REGISTERS_RESET_REG_2_XMAC_SOFT);
1703
1704}
1705
1706static void bnx2x_xmac_disable(struct link_params *params)
1707{
1708 u8 port = params->port;
1709 struct bnx2x *bp = params->bp;
Yaniv Rosnerb5077662011-08-02 22:59:18 +00001710 u32 pfc_ctrl, xmac_base = (port) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001711
1712 if (REG_RD(bp, MISC_REG_RESET_REG_2) &
1713 MISC_REGISTERS_RESET_REG_2_XMAC) {
Yaniv Rosnerb5077662011-08-02 22:59:18 +00001714 /*
1715 * Send an indication to change the state in the NIG back to XON
1716 * Clearing this bit enables the next set of this bit to get
1717 * rising edge
1718 */
1719 pfc_ctrl = REG_RD(bp, xmac_base + XMAC_REG_PFC_CTRL_HI);
1720 REG_WR(bp, xmac_base + XMAC_REG_PFC_CTRL_HI,
1721 (pfc_ctrl & ~(1<<1)));
1722 REG_WR(bp, xmac_base + XMAC_REG_PFC_CTRL_HI,
1723 (pfc_ctrl | (1<<1)));
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001724 DP(NETIF_MSG_LINK, "Disable XMAC on port %x\n", port);
1725 REG_WR(bp, xmac_base + XMAC_REG_CTRL, 0);
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001726 }
1727}
1728
1729static int bnx2x_xmac_enable(struct link_params *params,
1730 struct link_vars *vars, u8 lb)
1731{
1732 u32 val, xmac_base;
1733 struct bnx2x *bp = params->bp;
1734 DP(NETIF_MSG_LINK, "enabling XMAC\n");
1735
1736 xmac_base = (params->port) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
1737
Yaniv Rosnerce7c0482011-10-27 05:09:47 +00001738 bnx2x_xmac_init(params, vars->line_speed);
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001739
1740 /*
1741 * This register determines on which events the MAC will assert
1742 * error on the i/f to the NIG along w/ EOP.
1743 */
1744
1745 /*
1746 * This register tells the NIG whether to send traffic to UMAC
1747 * or XMAC
1748 */
1749 REG_WR(bp, NIG_REG_EGRESS_EMAC0_PORT + params->port*4, 0);
1750
1751 /* Set Max packet size */
1752 REG_WR(bp, xmac_base + XMAC_REG_RX_MAX_SIZE, 0x2710);
1753
1754 /* CRC append for Tx packets */
1755 REG_WR(bp, xmac_base + XMAC_REG_TX_CTRL, 0xC800);
1756
1757 /* update PFC */
1758 bnx2x_update_pfc_xmac(params, vars, 0);
1759
1760 /* Enable TX and RX */
1761 val = XMAC_CTRL_REG_TX_EN | XMAC_CTRL_REG_RX_EN;
1762
1763 /* Check loopback mode */
1764 if (lb)
David S. Miller8decf862011-09-22 03:23:13 -04001765 val |= XMAC_CTRL_REG_LINE_LOCAL_LPBK;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001766 REG_WR(bp, xmac_base + XMAC_REG_CTRL, val);
1767 bnx2x_set_xumac_nig(params,
1768 ((vars->flow_ctrl & BNX2X_FLOW_CTRL_TX) != 0), 1);
1769
1770 vars->mac_type = MAC_TYPE_XMAC;
1771
1772 return 0;
1773}
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00001774static int bnx2x_emac_enable(struct link_params *params,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00001775 struct link_vars *vars, u8 lb)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001776{
1777 struct bnx2x *bp = params->bp;
1778 u8 port = params->port;
1779 u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
1780 u32 val;
1781
1782 DP(NETIF_MSG_LINK, "enabling EMAC\n");
1783
Yaniv Rosnerde6f3372011-08-02 22:59:25 +00001784 /* Disable BMAC */
1785 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
1786 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port));
1787
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001788 /* enable emac and not bmac */
1789 REG_WR(bp, NIG_REG_EGRESS_EMAC0_PORT + port*4, 1);
1790
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001791 /* ASIC */
1792 if (vars->phy_flags & PHY_XGXS_FLAG) {
1793 u32 ser_lane = ((params->lane_config &
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001794 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_MASK) >>
1795 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_SHIFT);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001796
1797 DP(NETIF_MSG_LINK, "XGXS\n");
1798 /* select the master lanes (out of 0-3) */
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001799 REG_WR(bp, NIG_REG_XGXS_LANE_SEL_P0 + port*4, ser_lane);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001800 /* select XGXS */
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001801 REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001802
1803 } else { /* SerDes */
1804 DP(NETIF_MSG_LINK, "SerDes\n");
1805 /* select SerDes */
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001806 REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001807 }
1808
Eilon Greenstein811a2f22009-02-12 08:37:04 +00001809 bnx2x_bits_en(bp, emac_base + EMAC_REG_EMAC_RX_MODE,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001810 EMAC_RX_MODE_RESET);
Eilon Greenstein811a2f22009-02-12 08:37:04 +00001811 bnx2x_bits_en(bp, emac_base + EMAC_REG_EMAC_TX_MODE,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001812 EMAC_TX_MODE_RESET);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001813
1814 if (CHIP_REV_IS_SLOW(bp)) {
1815 /* config GMII mode */
1816 val = REG_RD(bp, emac_base + EMAC_REG_EMAC_MODE);
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001817 EMAC_WR(bp, EMAC_REG_EMAC_MODE, (val | EMAC_MODE_PORT_GMII));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001818 } else { /* ASIC */
1819 /* pause enable/disable */
1820 bnx2x_bits_dis(bp, emac_base + EMAC_REG_EMAC_RX_MODE,
1821 EMAC_RX_MODE_FLOW_EN);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001822
1823 bnx2x_bits_dis(bp, emac_base + EMAC_REG_EMAC_TX_MODE,
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001824 (EMAC_TX_MODE_EXT_PAUSE_EN |
1825 EMAC_TX_MODE_FLOW_EN));
1826 if (!(params->feature_config_flags &
1827 FEATURE_CONFIG_PFC_ENABLED)) {
1828 if (vars->flow_ctrl & BNX2X_FLOW_CTRL_RX)
1829 bnx2x_bits_en(bp, emac_base +
1830 EMAC_REG_EMAC_RX_MODE,
1831 EMAC_RX_MODE_FLOW_EN);
1832
1833 if (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX)
1834 bnx2x_bits_en(bp, emac_base +
1835 EMAC_REG_EMAC_TX_MODE,
1836 (EMAC_TX_MODE_EXT_PAUSE_EN |
1837 EMAC_TX_MODE_FLOW_EN));
1838 } else
1839 bnx2x_bits_en(bp, emac_base + EMAC_REG_EMAC_TX_MODE,
1840 EMAC_TX_MODE_FLOW_EN);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001841 }
1842
1843 /* KEEP_VLAN_TAG, promiscuous */
1844 val = REG_RD(bp, emac_base + EMAC_REG_EMAC_RX_MODE);
1845 val |= EMAC_RX_MODE_KEEP_VLAN_TAG | EMAC_RX_MODE_PROMISCUOUS;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001846
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00001847 /*
1848 * Setting this bit causes MAC control frames (except for pause
1849 * frames) to be passed on for processing. This setting has no
1850 * affect on the operation of the pause frames. This bit effects
1851 * all packets regardless of RX Parser packet sorting logic.
1852 * Turn the PFC off to make sure we are in Xon state before
1853 * enabling it.
1854 */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001855 EMAC_WR(bp, EMAC_REG_RX_PFC_MODE, 0);
1856 if (params->feature_config_flags & FEATURE_CONFIG_PFC_ENABLED) {
1857 DP(NETIF_MSG_LINK, "PFC is enabled\n");
1858 /* Enable PFC again */
1859 EMAC_WR(bp, EMAC_REG_RX_PFC_MODE,
1860 EMAC_REG_RX_PFC_MODE_RX_EN |
1861 EMAC_REG_RX_PFC_MODE_TX_EN |
1862 EMAC_REG_RX_PFC_MODE_PRIORITIES);
1863
1864 EMAC_WR(bp, EMAC_REG_RX_PFC_PARAM,
1865 ((0x0101 <<
1866 EMAC_REG_RX_PFC_PARAM_OPCODE_BITSHIFT) |
1867 (0x00ff <<
1868 EMAC_REG_RX_PFC_PARAM_PRIORITY_EN_BITSHIFT)));
1869 val |= EMAC_RX_MODE_KEEP_MAC_CONTROL;
1870 }
Eilon Greenstein3196a882008-08-13 15:58:49 -07001871 EMAC_WR(bp, EMAC_REG_EMAC_RX_MODE, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001872
1873 /* Set Loopback */
1874 val = REG_RD(bp, emac_base + EMAC_REG_EMAC_MODE);
1875 if (lb)
1876 val |= 0x810;
1877 else
1878 val &= ~0x810;
Eilon Greenstein3196a882008-08-13 15:58:49 -07001879 EMAC_WR(bp, EMAC_REG_EMAC_MODE, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001880
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00001881 /* enable emac */
1882 REG_WR(bp, NIG_REG_NIG_EMAC0_EN + port*4, 1);
1883
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001884 /* enable emac for jumbo packets */
Eilon Greenstein3196a882008-08-13 15:58:49 -07001885 EMAC_WR(bp, EMAC_REG_EMAC_RX_MTU_SIZE,
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001886 (EMAC_RX_MTU_SIZE_JUMBO_ENA |
1887 (ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD)));
1888
1889 /* strip CRC */
1890 REG_WR(bp, NIG_REG_NIG_INGRESS_EMAC0_NO_CRC + port*4, 0x1);
1891
1892 /* disable the NIG in/out to the bmac */
1893 REG_WR(bp, NIG_REG_BMAC0_IN_EN + port*4, 0x0);
1894 REG_WR(bp, NIG_REG_BMAC0_PAUSE_OUT_EN + port*4, 0x0);
1895 REG_WR(bp, NIG_REG_BMAC0_OUT_EN + port*4, 0x0);
1896
1897 /* enable the NIG in/out to the emac */
1898 REG_WR(bp, NIG_REG_EMAC0_IN_EN + port*4, 0x1);
1899 val = 0;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001900 if ((params->feature_config_flags &
1901 FEATURE_CONFIG_PFC_ENABLED) ||
1902 (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX))
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001903 val = 1;
1904
1905 REG_WR(bp, NIG_REG_EMAC0_PAUSE_OUT_EN + port*4, val);
1906 REG_WR(bp, NIG_REG_EGRESS_EMAC0_OUT_EN + port*4, 0x1);
1907
Yaniv Rosner02a23162011-01-31 04:22:53 +00001908 REG_WR(bp, NIG_REG_BMAC0_REGS_OUT_EN + port*4, 0x0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001909
1910 vars->mac_type = MAC_TYPE_EMAC;
1911 return 0;
1912}
1913
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001914static void bnx2x_update_pfc_bmac1(struct link_params *params,
1915 struct link_vars *vars)
1916{
1917 u32 wb_data[2];
1918 struct bnx2x *bp = params->bp;
1919 u32 bmac_addr = params->port ? NIG_REG_INGRESS_BMAC1_MEM :
1920 NIG_REG_INGRESS_BMAC0_MEM;
1921
1922 u32 val = 0x14;
1923 if ((!(params->feature_config_flags &
1924 FEATURE_CONFIG_PFC_ENABLED)) &&
1925 (vars->flow_ctrl & BNX2X_FLOW_CTRL_RX))
1926 /* Enable BigMAC to react on received Pause packets */
1927 val |= (1<<5);
1928 wb_data[0] = val;
1929 wb_data[1] = 0;
1930 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_RX_CONTROL, wb_data, 2);
1931
1932 /* tx control */
1933 val = 0xc0;
1934 if (!(params->feature_config_flags &
1935 FEATURE_CONFIG_PFC_ENABLED) &&
1936 (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX))
1937 val |= 0x800000;
1938 wb_data[0] = val;
1939 wb_data[1] = 0;
1940 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_TX_CONTROL, wb_data, 2);
1941}
1942
1943static void bnx2x_update_pfc_bmac2(struct link_params *params,
1944 struct link_vars *vars,
1945 u8 is_lb)
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001946{
1947 /*
1948 * Set rx control: Strip CRC and enable BigMAC to relay
1949 * control packets to the system as well
1950 */
1951 u32 wb_data[2];
1952 struct bnx2x *bp = params->bp;
1953 u32 bmac_addr = params->port ? NIG_REG_INGRESS_BMAC1_MEM :
1954 NIG_REG_INGRESS_BMAC0_MEM;
1955 u32 val = 0x14;
1956
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001957 if ((!(params->feature_config_flags &
1958 FEATURE_CONFIG_PFC_ENABLED)) &&
1959 (vars->flow_ctrl & BNX2X_FLOW_CTRL_RX))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001960 /* Enable BigMAC to react on received Pause packets */
1961 val |= (1<<5);
1962 wb_data[0] = val;
1963 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001964 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_RX_CONTROL, wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001965 udelay(30);
1966
1967 /* Tx control */
1968 val = 0xc0;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001969 if (!(params->feature_config_flags &
1970 FEATURE_CONFIG_PFC_ENABLED) &&
1971 (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001972 val |= 0x800000;
1973 wb_data[0] = val;
1974 wb_data[1] = 0;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001975 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_TX_CONTROL, wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001976
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001977 if (params->feature_config_flags & FEATURE_CONFIG_PFC_ENABLED) {
1978 DP(NETIF_MSG_LINK, "PFC is enabled\n");
1979 /* Enable PFC RX & TX & STATS and set 8 COS */
1980 wb_data[0] = 0x0;
1981 wb_data[0] |= (1<<0); /* RX */
1982 wb_data[0] |= (1<<1); /* TX */
1983 wb_data[0] |= (1<<2); /* Force initial Xon */
1984 wb_data[0] |= (1<<3); /* 8 cos */
1985 wb_data[0] |= (1<<5); /* STATS */
1986 wb_data[1] = 0;
1987 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_PFC_CONTROL,
1988 wb_data, 2);
1989 /* Clear the force Xon */
1990 wb_data[0] &= ~(1<<2);
1991 } else {
1992 DP(NETIF_MSG_LINK, "PFC is disabled\n");
1993 /* disable PFC RX & TX & STATS and set 8 COS */
1994 wb_data[0] = 0x8;
1995 wb_data[1] = 0;
1996 }
1997
1998 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_PFC_CONTROL, wb_data, 2);
1999
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002000 /*
2001 * Set Time (based unit is 512 bit time) between automatic
2002 * re-sending of PP packets amd enable automatic re-send of
2003 * Per-Priroity Packet as long as pp_gen is asserted and
2004 * pp_disable is low.
2005 */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002006 val = 0x8000;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002007 if (params->feature_config_flags & FEATURE_CONFIG_PFC_ENABLED)
2008 val |= (1<<16); /* enable automatic re-send */
2009
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002010 wb_data[0] = val;
2011 wb_data[1] = 0;
2012 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_TX_PAUSE_CONTROL,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002013 wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002014
2015 /* mac control */
2016 val = 0x3; /* Enable RX and TX */
2017 if (is_lb) {
2018 val |= 0x4; /* Local loopback */
2019 DP(NETIF_MSG_LINK, "enable bmac loopback\n");
2020 }
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002021 /* When PFC enabled, Pass pause frames towards the NIG. */
2022 if (params->feature_config_flags & FEATURE_CONFIG_PFC_ENABLED)
2023 val |= ((1<<6)|(1<<5));
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002024
2025 wb_data[0] = val;
2026 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002027 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_BMAC_CONTROL, wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002028}
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002029
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002030
2031/* PFC BRB internal port configuration params */
2032struct bnx2x_pfc_brb_threshold_val {
2033 u32 pause_xoff;
2034 u32 pause_xon;
2035 u32 full_xoff;
2036 u32 full_xon;
2037};
2038
2039struct bnx2x_pfc_brb_e3b0_val {
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002040 u32 per_class_guaranty_mode;
2041 u32 lb_guarantied_hyst;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002042 u32 full_lb_xoff_th;
2043 u32 full_lb_xon_threshold;
2044 u32 lb_guarantied;
2045 u32 mac_0_class_t_guarantied;
2046 u32 mac_0_class_t_guarantied_hyst;
2047 u32 mac_1_class_t_guarantied;
2048 u32 mac_1_class_t_guarantied_hyst;
2049};
2050
2051struct bnx2x_pfc_brb_th_val {
2052 struct bnx2x_pfc_brb_threshold_val pauseable_th;
2053 struct bnx2x_pfc_brb_threshold_val non_pauseable_th;
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002054 struct bnx2x_pfc_brb_threshold_val default_class0;
2055 struct bnx2x_pfc_brb_threshold_val default_class1;
2056
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002057};
2058static int bnx2x_pfc_brb_get_config_params(
2059 struct link_params *params,
2060 struct bnx2x_pfc_brb_th_val *config_val)
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002061{
2062 struct bnx2x *bp = params->bp;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002063 DP(NETIF_MSG_LINK, "Setting PFC BRB configuration\n");
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002064
2065 config_val->default_class1.pause_xoff = 0;
2066 config_val->default_class1.pause_xon = 0;
2067 config_val->default_class1.full_xoff = 0;
2068 config_val->default_class1.full_xon = 0;
2069
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002070 if (CHIP_IS_E2(bp)) {
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002071 /* class0 defaults */
2072 config_val->default_class0.pause_xoff =
2073 DEFAULT0_E2_BRB_MAC_PAUSE_XOFF_THR;
2074 config_val->default_class0.pause_xon =
2075 DEFAULT0_E2_BRB_MAC_PAUSE_XON_THR;
2076 config_val->default_class0.full_xoff =
2077 DEFAULT0_E2_BRB_MAC_FULL_XOFF_THR;
2078 config_val->default_class0.full_xon =
2079 DEFAULT0_E2_BRB_MAC_FULL_XON_THR;
2080 /* pause able*/
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002081 config_val->pauseable_th.pause_xoff =
2082 PFC_E2_BRB_MAC_PAUSE_XOFF_THR_PAUSE;
2083 config_val->pauseable_th.pause_xon =
2084 PFC_E2_BRB_MAC_PAUSE_XON_THR_PAUSE;
2085 config_val->pauseable_th.full_xoff =
2086 PFC_E2_BRB_MAC_FULL_XOFF_THR_PAUSE;
2087 config_val->pauseable_th.full_xon =
2088 PFC_E2_BRB_MAC_FULL_XON_THR_PAUSE;
2089 /* non pause able*/
2090 config_val->non_pauseable_th.pause_xoff =
2091 PFC_E2_BRB_MAC_PAUSE_XOFF_THR_NON_PAUSE;
2092 config_val->non_pauseable_th.pause_xon =
2093 PFC_E2_BRB_MAC_PAUSE_XON_THR_NON_PAUSE;
2094 config_val->non_pauseable_th.full_xoff =
2095 PFC_E2_BRB_MAC_FULL_XOFF_THR_NON_PAUSE;
2096 config_val->non_pauseable_th.full_xon =
2097 PFC_E2_BRB_MAC_FULL_XON_THR_NON_PAUSE;
2098 } else if (CHIP_IS_E3A0(bp)) {
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002099 /* class0 defaults */
2100 config_val->default_class0.pause_xoff =
2101 DEFAULT0_E3A0_BRB_MAC_PAUSE_XOFF_THR;
2102 config_val->default_class0.pause_xon =
2103 DEFAULT0_E3A0_BRB_MAC_PAUSE_XON_THR;
2104 config_val->default_class0.full_xoff =
2105 DEFAULT0_E3A0_BRB_MAC_FULL_XOFF_THR;
2106 config_val->default_class0.full_xon =
2107 DEFAULT0_E3A0_BRB_MAC_FULL_XON_THR;
2108 /* pause able */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002109 config_val->pauseable_th.pause_xoff =
2110 PFC_E3A0_BRB_MAC_PAUSE_XOFF_THR_PAUSE;
2111 config_val->pauseable_th.pause_xon =
2112 PFC_E3A0_BRB_MAC_PAUSE_XON_THR_PAUSE;
2113 config_val->pauseable_th.full_xoff =
2114 PFC_E3A0_BRB_MAC_FULL_XOFF_THR_PAUSE;
2115 config_val->pauseable_th.full_xon =
2116 PFC_E3A0_BRB_MAC_FULL_XON_THR_PAUSE;
2117 /* non pause able*/
2118 config_val->non_pauseable_th.pause_xoff =
2119 PFC_E3A0_BRB_MAC_PAUSE_XOFF_THR_NON_PAUSE;
2120 config_val->non_pauseable_th.pause_xon =
2121 PFC_E3A0_BRB_MAC_PAUSE_XON_THR_NON_PAUSE;
2122 config_val->non_pauseable_th.full_xoff =
2123 PFC_E3A0_BRB_MAC_FULL_XOFF_THR_NON_PAUSE;
2124 config_val->non_pauseable_th.full_xon =
2125 PFC_E3A0_BRB_MAC_FULL_XON_THR_NON_PAUSE;
2126 } else if (CHIP_IS_E3B0(bp)) {
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002127 /* class0 defaults */
2128 config_val->default_class0.pause_xoff =
2129 DEFAULT0_E3B0_BRB_MAC_PAUSE_XOFF_THR;
2130 config_val->default_class0.pause_xon =
2131 DEFAULT0_E3B0_BRB_MAC_PAUSE_XON_THR;
2132 config_val->default_class0.full_xoff =
2133 DEFAULT0_E3B0_BRB_MAC_FULL_XOFF_THR;
2134 config_val->default_class0.full_xon =
2135 DEFAULT0_E3B0_BRB_MAC_FULL_XON_THR;
2136
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002137 if (params->phy[INT_PHY].flags &
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002138 FLAGS_4_PORT_MODE) {
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002139 config_val->pauseable_th.pause_xoff =
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002140 PFC_E3B0_4P_BRB_MAC_PAUSE_XOFF_THR_PAUSE;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002141 config_val->pauseable_th.pause_xon =
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002142 PFC_E3B0_4P_BRB_MAC_PAUSE_XON_THR_PAUSE;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002143 config_val->pauseable_th.full_xoff =
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002144 PFC_E3B0_4P_BRB_MAC_FULL_XOFF_THR_PAUSE;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002145 config_val->pauseable_th.full_xon =
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002146 PFC_E3B0_4P_BRB_MAC_FULL_XON_THR_PAUSE;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002147 /* non pause able*/
2148 config_val->non_pauseable_th.pause_xoff =
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002149 PFC_E3B0_4P_BRB_MAC_PAUSE_XOFF_THR_NON_PAUSE;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002150 config_val->non_pauseable_th.pause_xon =
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002151 PFC_E3B0_4P_BRB_MAC_PAUSE_XON_THR_NON_PAUSE;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002152 config_val->non_pauseable_th.full_xoff =
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002153 PFC_E3B0_4P_BRB_MAC_FULL_XOFF_THR_NON_PAUSE;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002154 config_val->non_pauseable_th.full_xon =
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002155 PFC_E3B0_4P_BRB_MAC_FULL_XON_THR_NON_PAUSE;
2156 } else {
2157 config_val->pauseable_th.pause_xoff =
2158 PFC_E3B0_2P_BRB_MAC_PAUSE_XOFF_THR_PAUSE;
2159 config_val->pauseable_th.pause_xon =
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002160 PFC_E3B0_2P_BRB_MAC_PAUSE_XON_THR_PAUSE;
2161 config_val->pauseable_th.full_xoff =
2162 PFC_E3B0_2P_BRB_MAC_FULL_XOFF_THR_PAUSE;
2163 config_val->pauseable_th.full_xon =
2164 PFC_E3B0_2P_BRB_MAC_FULL_XON_THR_PAUSE;
2165 /* non pause able*/
2166 config_val->non_pauseable_th.pause_xoff =
2167 PFC_E3B0_2P_BRB_MAC_PAUSE_XOFF_THR_NON_PAUSE;
2168 config_val->non_pauseable_th.pause_xon =
2169 PFC_E3B0_2P_BRB_MAC_PAUSE_XON_THR_NON_PAUSE;
2170 config_val->non_pauseable_th.full_xoff =
2171 PFC_E3B0_2P_BRB_MAC_FULL_XOFF_THR_NON_PAUSE;
2172 config_val->non_pauseable_th.full_xon =
2173 PFC_E3B0_2P_BRB_MAC_FULL_XON_THR_NON_PAUSE;
2174 }
2175 } else
2176 return -EINVAL;
2177
2178 return 0;
2179}
2180
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002181static void bnx2x_pfc_brb_get_e3b0_config_params(
2182 struct link_params *params,
2183 struct bnx2x_pfc_brb_e3b0_val
2184 *e3b0_val,
2185 struct bnx2x_nig_brb_pfc_port_params *pfc_params,
2186 const u8 pfc_enabled)
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002187{
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002188 if (pfc_enabled && pfc_params) {
2189 e3b0_val->per_class_guaranty_mode = 1;
2190 e3b0_val->lb_guarantied_hyst = 80;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002191
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002192 if (params->phy[INT_PHY].flags &
2193 FLAGS_4_PORT_MODE) {
2194 e3b0_val->full_lb_xoff_th =
2195 PFC_E3B0_4P_BRB_FULL_LB_XOFF_THR;
2196 e3b0_val->full_lb_xon_threshold =
2197 PFC_E3B0_4P_BRB_FULL_LB_XON_THR;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002198 e3b0_val->lb_guarantied =
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002199 PFC_E3B0_4P_LB_GUART;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002200 e3b0_val->mac_0_class_t_guarantied =
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002201 PFC_E3B0_4P_BRB_MAC_0_CLASS_T_GUART;
2202 e3b0_val->mac_0_class_t_guarantied_hyst =
2203 PFC_E3B0_4P_BRB_MAC_0_CLASS_T_GUART_HYST;
2204 e3b0_val->mac_1_class_t_guarantied =
2205 PFC_E3B0_4P_BRB_MAC_1_CLASS_T_GUART;
2206 e3b0_val->mac_1_class_t_guarantied_hyst =
2207 PFC_E3B0_4P_BRB_MAC_1_CLASS_T_GUART_HYST;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002208 } else {
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002209 e3b0_val->full_lb_xoff_th =
2210 PFC_E3B0_2P_BRB_FULL_LB_XOFF_THR;
2211 e3b0_val->full_lb_xon_threshold =
2212 PFC_E3B0_2P_BRB_FULL_LB_XON_THR;
2213 e3b0_val->mac_0_class_t_guarantied_hyst =
2214 PFC_E3B0_2P_BRB_MAC_0_CLASS_T_GUART_HYST;
2215 e3b0_val->mac_1_class_t_guarantied =
2216 PFC_E3B0_2P_BRB_MAC_1_CLASS_T_GUART;
2217 e3b0_val->mac_1_class_t_guarantied_hyst =
2218 PFC_E3B0_2P_BRB_MAC_1_CLASS_T_GUART_HYST;
2219
2220 if (pfc_params->cos0_pauseable !=
2221 pfc_params->cos1_pauseable) {
2222 /* nonpauseable= Lossy + pauseable = Lossless*/
2223 e3b0_val->lb_guarantied =
2224 PFC_E3B0_2P_MIX_PAUSE_LB_GUART;
2225 e3b0_val->mac_0_class_t_guarantied =
2226 PFC_E3B0_2P_MIX_PAUSE_MAC_0_CLASS_T_GUART;
2227 } else if (pfc_params->cos0_pauseable) {
2228 /* Lossless +Lossless*/
2229 e3b0_val->lb_guarantied =
2230 PFC_E3B0_2P_PAUSE_LB_GUART;
2231 e3b0_val->mac_0_class_t_guarantied =
2232 PFC_E3B0_2P_PAUSE_MAC_0_CLASS_T_GUART;
2233 } else {
2234 /* Lossy +Lossy*/
2235 e3b0_val->lb_guarantied =
2236 PFC_E3B0_2P_NON_PAUSE_LB_GUART;
2237 e3b0_val->mac_0_class_t_guarantied =
2238 PFC_E3B0_2P_NON_PAUSE_MAC_0_CLASS_T_GUART;
2239 }
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002240 }
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002241 } else {
2242 e3b0_val->per_class_guaranty_mode = 0;
2243 e3b0_val->lb_guarantied_hyst = 0;
2244 e3b0_val->full_lb_xoff_th =
2245 DEFAULT_E3B0_BRB_FULL_LB_XOFF_THR;
2246 e3b0_val->full_lb_xon_threshold =
2247 DEFAULT_E3B0_BRB_FULL_LB_XON_THR;
2248 e3b0_val->lb_guarantied =
2249 DEFAULT_E3B0_LB_GUART;
2250 e3b0_val->mac_0_class_t_guarantied =
2251 DEFAULT_E3B0_BRB_MAC_0_CLASS_T_GUART;
2252 e3b0_val->mac_0_class_t_guarantied_hyst =
2253 DEFAULT_E3B0_BRB_MAC_0_CLASS_T_GUART_HYST;
2254 e3b0_val->mac_1_class_t_guarantied =
2255 DEFAULT_E3B0_BRB_MAC_1_CLASS_T_GUART;
2256 e3b0_val->mac_1_class_t_guarantied_hyst =
2257 DEFAULT_E3B0_BRB_MAC_1_CLASS_T_GUART_HYST;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002258 }
2259}
2260static int bnx2x_update_pfc_brb(struct link_params *params,
2261 struct link_vars *vars,
2262 struct bnx2x_nig_brb_pfc_port_params
2263 *pfc_params)
2264{
2265 struct bnx2x *bp = params->bp;
2266 struct bnx2x_pfc_brb_th_val config_val = { {0} };
2267 struct bnx2x_pfc_brb_threshold_val *reg_th_config =
2268 &config_val.pauseable_th;
2269 struct bnx2x_pfc_brb_e3b0_val e3b0_val = {0};
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002270 const int set_pfc = params->feature_config_flags &
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002271 FEATURE_CONFIG_PFC_ENABLED;
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002272 const u8 pfc_enabled = (set_pfc && pfc_params);
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002273 int bnx2x_status = 0;
2274 u8 port = params->port;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002275
2276 /* default - pause configuration */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002277 reg_th_config = &config_val.pauseable_th;
2278 bnx2x_status = bnx2x_pfc_brb_get_config_params(params, &config_val);
2279 if (0 != bnx2x_status)
2280 return bnx2x_status;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002281
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002282 if (pfc_enabled) {
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002283 /* First COS */
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002284 if (pfc_params->cos0_pauseable)
2285 reg_th_config = &config_val.pauseable_th;
2286 else
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002287 reg_th_config = &config_val.non_pauseable_th;
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002288 } else
2289 reg_th_config = &config_val.default_class0;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002290 /*
2291 * The number of free blocks below which the pause signal to class 0
2292 * of MAC #n is asserted. n=0,1
2293 */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002294 REG_WR(bp, (port) ? BRB1_REG_PAUSE_0_XOFF_THRESHOLD_1 :
2295 BRB1_REG_PAUSE_0_XOFF_THRESHOLD_0 ,
2296 reg_th_config->pause_xoff);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002297 /*
2298 * The number of free blocks above which the pause signal to class 0
2299 * of MAC #n is de-asserted. n=0,1
2300 */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002301 REG_WR(bp, (port) ? BRB1_REG_PAUSE_0_XON_THRESHOLD_1 :
2302 BRB1_REG_PAUSE_0_XON_THRESHOLD_0 , reg_th_config->pause_xon);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002303 /*
2304 * The number of free blocks below which the full signal to class 0
2305 * of MAC #n is asserted. n=0,1
2306 */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002307 REG_WR(bp, (port) ? BRB1_REG_FULL_0_XOFF_THRESHOLD_1 :
2308 BRB1_REG_FULL_0_XOFF_THRESHOLD_0 , reg_th_config->full_xoff);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002309 /*
2310 * The number of free blocks above which the full signal to class 0
2311 * of MAC #n is de-asserted. n=0,1
2312 */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002313 REG_WR(bp, (port) ? BRB1_REG_FULL_0_XON_THRESHOLD_1 :
2314 BRB1_REG_FULL_0_XON_THRESHOLD_0 , reg_th_config->full_xon);
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002315
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002316 if (pfc_enabled) {
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002317 /* Second COS */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002318 if (pfc_params->cos1_pauseable)
2319 reg_th_config = &config_val.pauseable_th;
2320 else
2321 reg_th_config = &config_val.non_pauseable_th;
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002322 } else
2323 reg_th_config = &config_val.default_class1;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002324 /*
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002325 * The number of free blocks below which the pause signal to
2326 * class 1 of MAC #n is asserted. n=0,1
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002327 **/
2328 REG_WR(bp, (port) ? BRB1_REG_PAUSE_1_XOFF_THRESHOLD_1 :
2329 BRB1_REG_PAUSE_1_XOFF_THRESHOLD_0,
2330 reg_th_config->pause_xoff);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002331 /*
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002332 * The number of free blocks above which the pause signal to
2333 * class 1 of MAC #n is de-asserted. n=0,1
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002334 */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002335 REG_WR(bp, (port) ? BRB1_REG_PAUSE_1_XON_THRESHOLD_1 :
2336 BRB1_REG_PAUSE_1_XON_THRESHOLD_0,
2337 reg_th_config->pause_xon);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002338 /*
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002339 * The number of free blocks below which the full signal to
2340 * class 1 of MAC #n is asserted. n=0,1
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002341 */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002342 REG_WR(bp, (port) ? BRB1_REG_FULL_1_XOFF_THRESHOLD_1 :
2343 BRB1_REG_FULL_1_XOFF_THRESHOLD_0,
2344 reg_th_config->full_xoff);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002345 /*
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002346 * The number of free blocks above which the full signal to
2347 * class 1 of MAC #n is de-asserted. n=0,1
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002348 */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002349 REG_WR(bp, (port) ? BRB1_REG_FULL_1_XON_THRESHOLD_1 :
2350 BRB1_REG_FULL_1_XON_THRESHOLD_0,
2351 reg_th_config->full_xon);
2352
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002353 if (CHIP_IS_E3B0(bp)) {
2354 bnx2x_pfc_brb_get_e3b0_config_params(
2355 params,
2356 &e3b0_val,
2357 pfc_params,
2358 pfc_enabled);
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002359
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002360 /*Should be done by init tool */
2361 /*
2362 * BRB_empty_for_dup = BRB1_REG_BRB_EMPTY_THRESHOLD
2363 * reset value
2364 * 944
2365 */
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002366 REG_WR(bp, BRB1_REG_PER_CLASS_GUARANTY_MODE,
2367 e3b0_val.per_class_guaranty_mode);
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002368
2369 /**
2370 * The hysteresis on the guarantied buffer space for the Lb port
2371 * before signaling XON.
2372 **/
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002373 REG_WR(bp, BRB1_REG_LB_GUARANTIED_HYST,
2374 e3b0_val.lb_guarantied_hyst);
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002375 /**
2376 * The number of free blocks below which the full signal to the
2377 * LB port is asserted.
2378 */
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002379 REG_WR(bp, BRB1_REG_FULL_LB_XOFF_THRESHOLD,
2380 e3b0_val.full_lb_xoff_th);
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002381 /**
2382 * The number of free blocks above which the full signal to the
2383 * LB port is de-asserted.
2384 */
2385 REG_WR(bp, BRB1_REG_FULL_LB_XON_THRESHOLD,
2386 e3b0_val.full_lb_xon_threshold);
2387 /**
2388 * The number of blocks guarantied for the MAC #n port. n=0,1
2389 */
2390
2391 /*The number of blocks guarantied for the LB port.*/
2392 REG_WR(bp, BRB1_REG_LB_GUARANTIED,
2393 e3b0_val.lb_guarantied);
2394
2395 /**
2396 * The number of blocks guarantied for the MAC #n port.
2397 */
2398 REG_WR(bp, BRB1_REG_MAC_GUARANTIED_0,
2399 2 * e3b0_val.mac_0_class_t_guarantied);
2400 REG_WR(bp, BRB1_REG_MAC_GUARANTIED_1,
2401 2 * e3b0_val.mac_1_class_t_guarantied);
2402 /**
2403 * The number of blocks guarantied for class #t in MAC0. t=0,1
2404 */
2405 REG_WR(bp, BRB1_REG_MAC_0_CLASS_0_GUARANTIED,
2406 e3b0_val.mac_0_class_t_guarantied);
2407 REG_WR(bp, BRB1_REG_MAC_0_CLASS_1_GUARANTIED,
2408 e3b0_val.mac_0_class_t_guarantied);
2409 /**
2410 * The hysteresis on the guarantied buffer space for class in
2411 * MAC0. t=0,1
2412 */
2413 REG_WR(bp, BRB1_REG_MAC_0_CLASS_0_GUARANTIED_HYST,
2414 e3b0_val.mac_0_class_t_guarantied_hyst);
2415 REG_WR(bp, BRB1_REG_MAC_0_CLASS_1_GUARANTIED_HYST,
2416 e3b0_val.mac_0_class_t_guarantied_hyst);
2417
2418 /**
2419 * The number of blocks guarantied for class #t in MAC1.t=0,1
2420 */
2421 REG_WR(bp, BRB1_REG_MAC_1_CLASS_0_GUARANTIED,
2422 e3b0_val.mac_1_class_t_guarantied);
2423 REG_WR(bp, BRB1_REG_MAC_1_CLASS_1_GUARANTIED,
2424 e3b0_val.mac_1_class_t_guarantied);
2425 /**
2426 * The hysteresis on the guarantied buffer space for class #t
2427 * in MAC1. t=0,1
2428 */
2429 REG_WR(bp, BRB1_REG_MAC_1_CLASS_0_GUARANTIED_HYST,
2430 e3b0_val.mac_1_class_t_guarantied_hyst);
2431 REG_WR(bp, BRB1_REG_MAC_1_CLASS_1_GUARANTIED_HYST,
2432 e3b0_val.mac_1_class_t_guarantied_hyst);
2433
2434 }
2435
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002436 return bnx2x_status;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002437}
2438
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002439/******************************************************************************
2440* Description:
2441* This function is needed because NIG ARB_CREDIT_WEIGHT_X are
2442* not continues and ARB_CREDIT_WEIGHT_0 + offset is suitable.
2443******************************************************************************/
2444int bnx2x_pfc_nig_rx_priority_mask(struct bnx2x *bp,
2445 u8 cos_entry,
2446 u32 priority_mask, u8 port)
2447{
2448 u32 nig_reg_rx_priority_mask_add = 0;
2449
2450 switch (cos_entry) {
2451 case 0:
2452 nig_reg_rx_priority_mask_add = (port) ?
2453 NIG_REG_P1_RX_COS0_PRIORITY_MASK :
2454 NIG_REG_P0_RX_COS0_PRIORITY_MASK;
2455 break;
2456 case 1:
2457 nig_reg_rx_priority_mask_add = (port) ?
2458 NIG_REG_P1_RX_COS1_PRIORITY_MASK :
2459 NIG_REG_P0_RX_COS1_PRIORITY_MASK;
2460 break;
2461 case 2:
2462 nig_reg_rx_priority_mask_add = (port) ?
2463 NIG_REG_P1_RX_COS2_PRIORITY_MASK :
2464 NIG_REG_P0_RX_COS2_PRIORITY_MASK;
2465 break;
2466 case 3:
2467 if (port)
2468 return -EINVAL;
2469 nig_reg_rx_priority_mask_add = NIG_REG_P0_RX_COS3_PRIORITY_MASK;
2470 break;
2471 case 4:
2472 if (port)
2473 return -EINVAL;
2474 nig_reg_rx_priority_mask_add = NIG_REG_P0_RX_COS4_PRIORITY_MASK;
2475 break;
2476 case 5:
2477 if (port)
2478 return -EINVAL;
2479 nig_reg_rx_priority_mask_add = NIG_REG_P0_RX_COS5_PRIORITY_MASK;
2480 break;
2481 }
2482
2483 REG_WR(bp, nig_reg_rx_priority_mask_add, priority_mask);
2484
2485 return 0;
2486}
Yaniv Rosnerb8d6d082011-07-05 01:06:27 +00002487static void bnx2x_update_mng(struct link_params *params, u32 link_status)
2488{
2489 struct bnx2x *bp = params->bp;
2490
2491 REG_WR(bp, params->shmem_base +
2492 offsetof(struct shmem_region,
2493 port_mb[params->port].link_status), link_status);
2494}
2495
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002496static void bnx2x_update_pfc_nig(struct link_params *params,
2497 struct link_vars *vars,
2498 struct bnx2x_nig_brb_pfc_port_params *nig_params)
2499{
2500 u32 xcm_mask = 0, ppp_enable = 0, pause_enable = 0, llfc_out_en = 0;
2501 u32 llfc_enable = 0, xcm0_out_en = 0, p0_hwpfc_enable = 0;
2502 u32 pkt_priority_to_cos = 0;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002503 struct bnx2x *bp = params->bp;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002504 u8 port = params->port;
2505
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002506 int set_pfc = params->feature_config_flags &
2507 FEATURE_CONFIG_PFC_ENABLED;
2508 DP(NETIF_MSG_LINK, "updating pfc nig parameters\n");
2509
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002510 /*
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002511 * When NIG_LLH0_XCM_MASK_REG_LLHX_XCM_MASK_BCN bit is set
2512 * MAC control frames (that are not pause packets)
2513 * will be forwarded to the XCM.
2514 */
2515 xcm_mask = REG_RD(bp,
2516 port ? NIG_REG_LLH1_XCM_MASK :
2517 NIG_REG_LLH0_XCM_MASK);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002518 /*
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002519 * nig params will override non PFC params, since it's possible to
2520 * do transition from PFC to SAFC
2521 */
2522 if (set_pfc) {
2523 pause_enable = 0;
2524 llfc_out_en = 0;
2525 llfc_enable = 0;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002526 if (CHIP_IS_E3(bp))
2527 ppp_enable = 0;
2528 else
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002529 ppp_enable = 1;
2530 xcm_mask &= ~(port ? NIG_LLH1_XCM_MASK_REG_LLH1_XCM_MASK_BCN :
2531 NIG_LLH0_XCM_MASK_REG_LLH0_XCM_MASK_BCN);
2532 xcm0_out_en = 0;
2533 p0_hwpfc_enable = 1;
2534 } else {
2535 if (nig_params) {
2536 llfc_out_en = nig_params->llfc_out_en;
2537 llfc_enable = nig_params->llfc_enable;
2538 pause_enable = nig_params->pause_enable;
2539 } else /*defaul non PFC mode - PAUSE */
2540 pause_enable = 1;
2541
2542 xcm_mask |= (port ? NIG_LLH1_XCM_MASK_REG_LLH1_XCM_MASK_BCN :
2543 NIG_LLH0_XCM_MASK_REG_LLH0_XCM_MASK_BCN);
2544 xcm0_out_en = 1;
2545 }
2546
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002547 if (CHIP_IS_E3(bp))
2548 REG_WR(bp, port ? NIG_REG_BRB1_PAUSE_IN_EN :
2549 NIG_REG_BRB0_PAUSE_IN_EN, pause_enable);
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002550 REG_WR(bp, port ? NIG_REG_LLFC_OUT_EN_1 :
2551 NIG_REG_LLFC_OUT_EN_0, llfc_out_en);
2552 REG_WR(bp, port ? NIG_REG_LLFC_ENABLE_1 :
2553 NIG_REG_LLFC_ENABLE_0, llfc_enable);
2554 REG_WR(bp, port ? NIG_REG_PAUSE_ENABLE_1 :
2555 NIG_REG_PAUSE_ENABLE_0, pause_enable);
2556
2557 REG_WR(bp, port ? NIG_REG_PPP_ENABLE_1 :
2558 NIG_REG_PPP_ENABLE_0, ppp_enable);
2559
2560 REG_WR(bp, port ? NIG_REG_LLH1_XCM_MASK :
2561 NIG_REG_LLH0_XCM_MASK, xcm_mask);
2562
2563 REG_WR(bp, NIG_REG_LLFC_EGRESS_SRC_ENABLE_0, 0x7);
2564
2565 /* output enable for RX_XCM # IF */
2566 REG_WR(bp, NIG_REG_XCM0_OUT_EN, xcm0_out_en);
2567
2568 /* HW PFC TX enable */
2569 REG_WR(bp, NIG_REG_P0_HWPFC_ENABLE, p0_hwpfc_enable);
2570
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002571 if (nig_params) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002572 u8 i = 0;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002573 pkt_priority_to_cos = nig_params->pkt_priority_to_cos;
2574
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002575 for (i = 0; i < nig_params->num_of_rx_cos_priority_mask; i++)
2576 bnx2x_pfc_nig_rx_priority_mask(bp, i,
2577 nig_params->rx_cos_priority_mask[i], port);
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002578
2579 REG_WR(bp, port ? NIG_REG_LLFC_HIGH_PRIORITY_CLASSES_1 :
2580 NIG_REG_LLFC_HIGH_PRIORITY_CLASSES_0,
2581 nig_params->llfc_high_priority_classes);
2582
2583 REG_WR(bp, port ? NIG_REG_LLFC_LOW_PRIORITY_CLASSES_1 :
2584 NIG_REG_LLFC_LOW_PRIORITY_CLASSES_0,
2585 nig_params->llfc_low_priority_classes);
2586 }
2587 REG_WR(bp, port ? NIG_REG_P1_PKT_PRIORITY_TO_COS :
2588 NIG_REG_P0_PKT_PRIORITY_TO_COS,
2589 pkt_priority_to_cos);
2590}
2591
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002592int bnx2x_update_pfc(struct link_params *params,
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002593 struct link_vars *vars,
2594 struct bnx2x_nig_brb_pfc_port_params *pfc_params)
2595{
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002596 /*
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002597 * The PFC and pause are orthogonal to one another, meaning when
2598 * PFC is enabled, the pause are disabled, and when PFC is
2599 * disabled, pause are set according to the pause result.
2600 */
2601 u32 val;
2602 struct bnx2x *bp = params->bp;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002603 int bnx2x_status = 0;
2604 u8 bmac_loopback = (params->loopback_mode == LOOPBACK_BMAC);
Yaniv Rosnerb8d6d082011-07-05 01:06:27 +00002605
2606 if (params->feature_config_flags & FEATURE_CONFIG_PFC_ENABLED)
2607 vars->link_status |= LINK_STATUS_PFC_ENABLED;
2608 else
2609 vars->link_status &= ~LINK_STATUS_PFC_ENABLED;
2610
2611 bnx2x_update_mng(params, vars->link_status);
2612
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002613 /* update NIG params */
2614 bnx2x_update_pfc_nig(params, vars, pfc_params);
2615
2616 /* update BRB params */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002617 bnx2x_status = bnx2x_update_pfc_brb(params, vars, pfc_params);
2618 if (0 != bnx2x_status)
2619 return bnx2x_status;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002620
2621 if (!vars->link_up)
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002622 return bnx2x_status;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002623
2624 DP(NETIF_MSG_LINK, "About to update PFC in BMAC\n");
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002625 if (CHIP_IS_E3(bp))
2626 bnx2x_update_pfc_xmac(params, vars, 0);
2627 else {
2628 val = REG_RD(bp, MISC_REG_RESET_REG_2);
2629 if ((val &
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00002630 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << params->port))
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002631 == 0) {
2632 DP(NETIF_MSG_LINK, "About to update PFC in EMAC\n");
2633 bnx2x_emac_enable(params, vars, 0);
2634 return bnx2x_status;
2635 }
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002636
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002637 if (CHIP_IS_E2(bp))
2638 bnx2x_update_pfc_bmac2(params, vars, bmac_loopback);
2639 else
2640 bnx2x_update_pfc_bmac1(params, vars);
2641
2642 val = 0;
2643 if ((params->feature_config_flags &
2644 FEATURE_CONFIG_PFC_ENABLED) ||
2645 (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX))
2646 val = 1;
2647 REG_WR(bp, NIG_REG_BMAC0_PAUSE_OUT_EN + params->port*4, val);
2648 }
2649 return bnx2x_status;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002650}
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002651
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002652
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00002653static int bnx2x_bmac1_enable(struct link_params *params,
2654 struct link_vars *vars,
2655 u8 is_lb)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002656{
2657 struct bnx2x *bp = params->bp;
2658 u8 port = params->port;
2659 u32 bmac_addr = port ? NIG_REG_INGRESS_BMAC1_MEM :
2660 NIG_REG_INGRESS_BMAC0_MEM;
2661 u32 wb_data[2];
2662 u32 val;
2663
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002664 DP(NETIF_MSG_LINK, "Enabling BigMAC1\n");
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002665
2666 /* XGXS control */
2667 wb_data[0] = 0x3c;
2668 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002669 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_BMAC_XGXS_CONTROL,
2670 wb_data, 2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002671
2672 /* tx MAC SA */
2673 wb_data[0] = ((params->mac_addr[2] << 24) |
2674 (params->mac_addr[3] << 16) |
2675 (params->mac_addr[4] << 8) |
2676 params->mac_addr[5]);
2677 wb_data[1] = ((params->mac_addr[0] << 8) |
2678 params->mac_addr[1]);
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002679 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_TX_SOURCE_ADDR, wb_data, 2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002680
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002681 /* mac control */
2682 val = 0x3;
2683 if (is_lb) {
2684 val |= 0x4;
2685 DP(NETIF_MSG_LINK, "enable bmac loopback\n");
2686 }
2687 wb_data[0] = val;
2688 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002689 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_BMAC_CONTROL, wb_data, 2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002690
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002691 /* set rx mtu */
2692 wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD;
2693 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002694 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_RX_MAX_SIZE, wb_data, 2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002695
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002696 bnx2x_update_pfc_bmac1(params, vars);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002697
2698 /* set tx mtu */
2699 wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD;
2700 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002701 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_TX_MAX_SIZE, wb_data, 2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002702
2703 /* set cnt max size */
2704 wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD;
2705 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002706 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_CNT_MAX_SIZE, wb_data, 2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002707
2708 /* configure safc */
2709 wb_data[0] = 0x1000200;
2710 wb_data[1] = 0;
2711 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_RX_LLFC_MSG_FLDS,
2712 wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002713
2714 return 0;
2715}
2716
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00002717static int bnx2x_bmac2_enable(struct link_params *params,
2718 struct link_vars *vars,
2719 u8 is_lb)
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002720{
2721 struct bnx2x *bp = params->bp;
2722 u8 port = params->port;
2723 u32 bmac_addr = port ? NIG_REG_INGRESS_BMAC1_MEM :
2724 NIG_REG_INGRESS_BMAC0_MEM;
2725 u32 wb_data[2];
2726
2727 DP(NETIF_MSG_LINK, "Enabling BigMAC2\n");
2728
2729 wb_data[0] = 0;
2730 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002731 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_BMAC_CONTROL, wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002732 udelay(30);
2733
2734 /* XGXS control: Reset phy HW, MDIO registers, PHY PLL and BMAC */
2735 wb_data[0] = 0x3c;
2736 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002737 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_BMAC_XGXS_CONTROL,
2738 wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002739
2740 udelay(30);
2741
2742 /* tx MAC SA */
2743 wb_data[0] = ((params->mac_addr[2] << 24) |
2744 (params->mac_addr[3] << 16) |
2745 (params->mac_addr[4] << 8) |
2746 params->mac_addr[5]);
2747 wb_data[1] = ((params->mac_addr[0] << 8) |
2748 params->mac_addr[1]);
2749 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_TX_SOURCE_ADDR,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002750 wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002751
2752 udelay(30);
2753
2754 /* Configure SAFC */
2755 wb_data[0] = 0x1000200;
2756 wb_data[1] = 0;
2757 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_RX_LLFC_MSG_FLDS,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002758 wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002759 udelay(30);
2760
2761 /* set rx mtu */
2762 wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD;
2763 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002764 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_RX_MAX_SIZE, wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002765 udelay(30);
2766
2767 /* set tx mtu */
2768 wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD;
2769 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002770 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_TX_MAX_SIZE, wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002771 udelay(30);
2772 /* set cnt max size */
2773 wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD - 2;
2774 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002775 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_CNT_MAX_SIZE, wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002776 udelay(30);
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002777 bnx2x_update_pfc_bmac2(params, vars, is_lb);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002778
2779 return 0;
2780}
2781
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00002782static int bnx2x_bmac_enable(struct link_params *params,
2783 struct link_vars *vars,
2784 u8 is_lb)
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002785{
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00002786 int rc = 0;
2787 u8 port = params->port;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002788 struct bnx2x *bp = params->bp;
2789 u32 val;
2790 /* reset and unreset the BigMac */
2791 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002792 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port));
Yaniv Rosner1d9c05d2010-11-01 05:32:25 +00002793 msleep(1);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002794
2795 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002796 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port));
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002797
2798 /* enable access for bmac registers */
2799 REG_WR(bp, NIG_REG_BMAC0_REGS_OUT_EN + port*4, 0x1);
2800
2801 /* Enable BMAC according to BMAC type*/
2802 if (CHIP_IS_E2(bp))
2803 rc = bnx2x_bmac2_enable(params, vars, is_lb);
2804 else
2805 rc = bnx2x_bmac1_enable(params, vars, is_lb);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002806 REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 0x1);
2807 REG_WR(bp, NIG_REG_XGXS_LANE_SEL_P0 + port*4, 0x0);
2808 REG_WR(bp, NIG_REG_EGRESS_EMAC0_PORT + port*4, 0x0);
2809 val = 0;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002810 if ((params->feature_config_flags &
2811 FEATURE_CONFIG_PFC_ENABLED) ||
2812 (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX))
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002813 val = 1;
2814 REG_WR(bp, NIG_REG_BMAC0_PAUSE_OUT_EN + port*4, val);
2815 REG_WR(bp, NIG_REG_EGRESS_EMAC0_OUT_EN + port*4, 0x0);
2816 REG_WR(bp, NIG_REG_EMAC0_IN_EN + port*4, 0x0);
2817 REG_WR(bp, NIG_REG_EMAC0_PAUSE_OUT_EN + port*4, 0x0);
2818 REG_WR(bp, NIG_REG_BMAC0_IN_EN + port*4, 0x1);
2819 REG_WR(bp, NIG_REG_BMAC0_OUT_EN + port*4, 0x1);
2820
2821 vars->mac_type = MAC_TYPE_BMAC;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002822 return rc;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002823}
2824
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002825static void bnx2x_bmac_rx_disable(struct bnx2x *bp, u8 port)
2826{
2827 u32 bmac_addr = port ? NIG_REG_INGRESS_BMAC1_MEM :
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002828 NIG_REG_INGRESS_BMAC0_MEM;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002829 u32 wb_data[2];
Eilon Greenstein3196a882008-08-13 15:58:49 -07002830 u32 nig_bmac_enable = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port*4);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002831
2832 /* Only if the bmac is out of reset */
2833 if (REG_RD(bp, MISC_REG_RESET_REG_2) &
2834 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port) &&
2835 nig_bmac_enable) {
2836
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002837 if (CHIP_IS_E2(bp)) {
2838 /* Clear Rx Enable bit in BMAC_CONTROL register */
2839 REG_RD_DMAE(bp, bmac_addr +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002840 BIGMAC2_REGISTER_BMAC_CONTROL,
2841 wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002842 wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
2843 REG_WR_DMAE(bp, bmac_addr +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002844 BIGMAC2_REGISTER_BMAC_CONTROL,
2845 wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002846 } else {
2847 /* Clear Rx Enable bit in BMAC_CONTROL register */
2848 REG_RD_DMAE(bp, bmac_addr +
2849 BIGMAC_REGISTER_BMAC_CONTROL,
2850 wb_data, 2);
2851 wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
2852 REG_WR_DMAE(bp, bmac_addr +
2853 BIGMAC_REGISTER_BMAC_CONTROL,
2854 wb_data, 2);
2855 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002856 msleep(1);
2857 }
2858}
2859
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00002860static int bnx2x_pbf_update(struct link_params *params, u32 flow_ctrl,
2861 u32 line_speed)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002862{
2863 struct bnx2x *bp = params->bp;
2864 u8 port = params->port;
2865 u32 init_crd, crd;
2866 u32 count = 1000;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002867
2868 /* disable port */
2869 REG_WR(bp, PBF_REG_DISABLE_NEW_TASK_PROC_P0 + port*4, 0x1);
2870
2871 /* wait for init credit */
2872 init_crd = REG_RD(bp, PBF_REG_P0_INIT_CRD + port*4);
2873 crd = REG_RD(bp, PBF_REG_P0_CREDIT + port*8);
2874 DP(NETIF_MSG_LINK, "init_crd 0x%x crd 0x%x\n", init_crd, crd);
2875
2876 while ((init_crd != crd) && count) {
2877 msleep(5);
2878
2879 crd = REG_RD(bp, PBF_REG_P0_CREDIT + port*8);
2880 count--;
2881 }
2882 crd = REG_RD(bp, PBF_REG_P0_CREDIT + port*8);
2883 if (init_crd != crd) {
2884 DP(NETIF_MSG_LINK, "BUG! init_crd 0x%x != crd 0x%x\n",
2885 init_crd, crd);
2886 return -EINVAL;
2887 }
2888
David S. Millerc0700f92008-12-16 23:53:20 -08002889 if (flow_ctrl & BNX2X_FLOW_CTRL_RX ||
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002890 line_speed == SPEED_10 ||
2891 line_speed == SPEED_100 ||
2892 line_speed == SPEED_1000 ||
2893 line_speed == SPEED_2500) {
2894 REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 1);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002895 /* update threshold */
2896 REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, 0);
2897 /* update init credit */
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002898 init_crd = 778; /* (800-18-4) */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002899
2900 } else {
2901 u32 thresh = (ETH_MAX_JUMBO_PACKET_SIZE +
2902 ETH_OVREHEAD)/16;
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002903 REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002904 /* update threshold */
2905 REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, thresh);
2906 /* update init credit */
2907 switch (line_speed) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002908 case SPEED_10000:
2909 init_crd = thresh + 553 - 22;
2910 break;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002911 default:
2912 DP(NETIF_MSG_LINK, "Invalid line_speed 0x%x\n",
2913 line_speed);
2914 return -EINVAL;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002915 }
2916 }
2917 REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, init_crd);
2918 DP(NETIF_MSG_LINK, "PBF updated to speed %d credit %d\n",
2919 line_speed, init_crd);
2920
2921 /* probe the credit changes */
2922 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0x1);
2923 msleep(5);
2924 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0x0);
2925
2926 /* enable port */
2927 REG_WR(bp, PBF_REG_DISABLE_NEW_TASK_PROC_P0 + port*4, 0x0);
2928 return 0;
2929}
2930
Dmitry Kravkove8920672011-05-04 23:52:40 +00002931/**
2932 * bnx2x_get_emac_base - retrive emac base address
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002933 *
Dmitry Kravkove8920672011-05-04 23:52:40 +00002934 * @bp: driver handle
2935 * @mdc_mdio_access: access type
2936 * @port: port id
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002937 *
2938 * This function selects the MDC/MDIO access (through emac0 or
2939 * emac1) depend on the mdc_mdio_access, port, port swapped. Each
2940 * phy has a default access mode, which could also be overridden
2941 * by nvram configuration. This parameter, whether this is the
2942 * default phy configuration, or the nvram overrun
2943 * configuration, is passed here as mdc_mdio_access and selects
2944 * the emac_base for the CL45 read/writes operations
2945 */
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00002946static u32 bnx2x_get_emac_base(struct bnx2x *bp,
2947 u32 mdc_mdio_access, u8 port)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002948{
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00002949 u32 emac_base = 0;
2950 switch (mdc_mdio_access) {
2951 case SHARED_HW_CFG_MDC_MDIO_ACCESS1_PHY_TYPE:
2952 break;
2953 case SHARED_HW_CFG_MDC_MDIO_ACCESS1_EMAC0:
2954 if (REG_RD(bp, NIG_REG_PORT_SWAP))
2955 emac_base = GRCBASE_EMAC1;
2956 else
2957 emac_base = GRCBASE_EMAC0;
2958 break;
2959 case SHARED_HW_CFG_MDC_MDIO_ACCESS1_EMAC1:
Eilon Greenstein589abe32009-02-12 08:36:55 +00002960 if (REG_RD(bp, NIG_REG_PORT_SWAP))
2961 emac_base = GRCBASE_EMAC0;
2962 else
2963 emac_base = GRCBASE_EMAC1;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002964 break;
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00002965 case SHARED_HW_CFG_MDC_MDIO_ACCESS1_BOTH:
2966 emac_base = (port) ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
2967 break;
2968 case SHARED_HW_CFG_MDC_MDIO_ACCESS1_SWAPPED:
Eilon Greenstein6378c022008-08-13 15:59:25 -07002969 emac_base = (port) ? GRCBASE_EMAC0 : GRCBASE_EMAC1;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002970 break;
2971 default:
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002972 break;
2973 }
2974 return emac_base;
2975
2976}
2977
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002978/******************************************************************/
Yaniv Rosner6583e332011-06-14 01:34:17 +00002979/* CL22 access functions */
2980/******************************************************************/
2981static int bnx2x_cl22_write(struct bnx2x *bp,
2982 struct bnx2x_phy *phy,
2983 u16 reg, u16 val)
2984{
2985 u32 tmp, mode;
2986 u8 i;
2987 int rc = 0;
2988 /* Switch to CL22 */
2989 mode = REG_RD(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE);
2990 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE,
2991 mode & ~EMAC_MDIO_MODE_CLAUSE_45);
2992
2993 /* address */
2994 tmp = ((phy->addr << 21) | (reg << 16) | val |
2995 EMAC_MDIO_COMM_COMMAND_WRITE_22 |
2996 EMAC_MDIO_COMM_START_BUSY);
2997 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, tmp);
2998
2999 for (i = 0; i < 50; i++) {
3000 udelay(10);
3001
3002 tmp = REG_RD(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM);
3003 if (!(tmp & EMAC_MDIO_COMM_START_BUSY)) {
3004 udelay(5);
3005 break;
3006 }
3007 }
3008 if (tmp & EMAC_MDIO_COMM_START_BUSY) {
3009 DP(NETIF_MSG_LINK, "write phy register failed\n");
3010 rc = -EFAULT;
3011 }
3012 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE, mode);
3013 return rc;
3014}
3015
3016static int bnx2x_cl22_read(struct bnx2x *bp,
3017 struct bnx2x_phy *phy,
3018 u16 reg, u16 *ret_val)
3019{
3020 u32 val, mode;
3021 u16 i;
3022 int rc = 0;
3023
3024 /* Switch to CL22 */
3025 mode = REG_RD(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE);
3026 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE,
3027 mode & ~EMAC_MDIO_MODE_CLAUSE_45);
3028
3029 /* address */
3030 val = ((phy->addr << 21) | (reg << 16) |
3031 EMAC_MDIO_COMM_COMMAND_READ_22 |
3032 EMAC_MDIO_COMM_START_BUSY);
3033 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, val);
3034
3035 for (i = 0; i < 50; i++) {
3036 udelay(10);
3037
3038 val = REG_RD(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM);
3039 if (!(val & EMAC_MDIO_COMM_START_BUSY)) {
3040 *ret_val = (u16)(val & EMAC_MDIO_COMM_DATA);
3041 udelay(5);
3042 break;
3043 }
3044 }
3045 if (val & EMAC_MDIO_COMM_START_BUSY) {
3046 DP(NETIF_MSG_LINK, "read phy register failed\n");
3047
3048 *ret_val = 0;
3049 rc = -EFAULT;
3050 }
3051 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE, mode);
3052 return rc;
3053}
3054
3055/******************************************************************/
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003056/* CL45 access functions */
3057/******************************************************************/
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00003058static int bnx2x_cl45_read(struct bnx2x *bp, struct bnx2x_phy *phy,
3059 u8 devad, u16 reg, u16 *ret_val)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003060{
Yaniv Rosnera198c142011-05-31 21:29:42 +00003061 u32 val;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003062 u16 i;
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00003063 int rc = 0;
Yaniv Rosner157fa282011-08-02 22:59:32 +00003064 if (phy->flags & FLAGS_MDC_MDIO_WA_B0)
3065 bnx2x_bits_en(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_STATUS,
3066 EMAC_MDIO_STATUS_10MB);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003067 /* address */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003068 val = ((phy->addr << 21) | (devad << 16) | reg |
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003069 EMAC_MDIO_COMM_COMMAND_ADDRESS |
3070 EMAC_MDIO_COMM_START_BUSY);
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003071 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003072
3073 for (i = 0; i < 50; i++) {
3074 udelay(10);
3075
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003076 val = REG_RD(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003077 if (!(val & EMAC_MDIO_COMM_START_BUSY)) {
3078 udelay(5);
3079 break;
3080 }
3081 }
3082 if (val & EMAC_MDIO_COMM_START_BUSY) {
3083 DP(NETIF_MSG_LINK, "read phy register failed\n");
Yaniv Rosner6d870c32011-01-31 04:22:20 +00003084 netdev_err(bp->dev, "MDC/MDIO access timeout\n");
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003085 *ret_val = 0;
3086 rc = -EFAULT;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003087 } else {
3088 /* data */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003089 val = ((phy->addr << 21) | (devad << 16) |
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003090 EMAC_MDIO_COMM_COMMAND_READ_45 |
3091 EMAC_MDIO_COMM_START_BUSY);
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003092 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003093
3094 for (i = 0; i < 50; i++) {
3095 udelay(10);
3096
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003097 val = REG_RD(bp, phy->mdio_ctrl +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003098 EMAC_REG_EMAC_MDIO_COMM);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003099 if (!(val & EMAC_MDIO_COMM_START_BUSY)) {
3100 *ret_val = (u16)(val & EMAC_MDIO_COMM_DATA);
3101 break;
3102 }
3103 }
3104 if (val & EMAC_MDIO_COMM_START_BUSY) {
3105 DP(NETIF_MSG_LINK, "read phy register failed\n");
Yaniv Rosner6d870c32011-01-31 04:22:20 +00003106 netdev_err(bp->dev, "MDC/MDIO access timeout\n");
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003107 *ret_val = 0;
3108 rc = -EFAULT;
3109 }
3110 }
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003111 /* Work around for E3 A0 */
3112 if (phy->flags & FLAGS_MDC_MDIO_WA) {
3113 phy->flags ^= FLAGS_DUMMY_READ;
3114 if (phy->flags & FLAGS_DUMMY_READ) {
3115 u16 temp_val;
3116 bnx2x_cl45_read(bp, phy, devad, 0xf, &temp_val);
3117 }
3118 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003119
Yaniv Rosner157fa282011-08-02 22:59:32 +00003120 if (phy->flags & FLAGS_MDC_MDIO_WA_B0)
3121 bnx2x_bits_dis(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_STATUS,
3122 EMAC_MDIO_STATUS_10MB);
Yaniv Rosnera198c142011-05-31 21:29:42 +00003123 return rc;
3124}
3125
3126static int bnx2x_cl45_write(struct bnx2x *bp, struct bnx2x_phy *phy,
3127 u8 devad, u16 reg, u16 val)
3128{
3129 u32 tmp;
3130 u8 i;
3131 int rc = 0;
Yaniv Rosner157fa282011-08-02 22:59:32 +00003132 if (phy->flags & FLAGS_MDC_MDIO_WA_B0)
3133 bnx2x_bits_en(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_STATUS,
3134 EMAC_MDIO_STATUS_10MB);
Yaniv Rosnera198c142011-05-31 21:29:42 +00003135
3136 /* address */
3137
3138 tmp = ((phy->addr << 21) | (devad << 16) | reg |
3139 EMAC_MDIO_COMM_COMMAND_ADDRESS |
3140 EMAC_MDIO_COMM_START_BUSY);
3141 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, tmp);
3142
3143 for (i = 0; i < 50; i++) {
3144 udelay(10);
3145
3146 tmp = REG_RD(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM);
3147 if (!(tmp & EMAC_MDIO_COMM_START_BUSY)) {
3148 udelay(5);
3149 break;
3150 }
3151 }
3152 if (tmp & EMAC_MDIO_COMM_START_BUSY) {
3153 DP(NETIF_MSG_LINK, "write phy register failed\n");
3154 netdev_err(bp->dev, "MDC/MDIO access timeout\n");
3155 rc = -EFAULT;
3156
3157 } else {
3158 /* data */
3159 tmp = ((phy->addr << 21) | (devad << 16) | val |
3160 EMAC_MDIO_COMM_COMMAND_WRITE_45 |
3161 EMAC_MDIO_COMM_START_BUSY);
3162 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, tmp);
3163
3164 for (i = 0; i < 50; i++) {
3165 udelay(10);
3166
3167 tmp = REG_RD(bp, phy->mdio_ctrl +
3168 EMAC_REG_EMAC_MDIO_COMM);
3169 if (!(tmp & EMAC_MDIO_COMM_START_BUSY)) {
3170 udelay(5);
3171 break;
3172 }
3173 }
3174 if (tmp & EMAC_MDIO_COMM_START_BUSY) {
3175 DP(NETIF_MSG_LINK, "write phy register failed\n");
3176 netdev_err(bp->dev, "MDC/MDIO access timeout\n");
3177 rc = -EFAULT;
3178 }
3179 }
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003180 /* Work around for E3 A0 */
3181 if (phy->flags & FLAGS_MDC_MDIO_WA) {
3182 phy->flags ^= FLAGS_DUMMY_READ;
3183 if (phy->flags & FLAGS_DUMMY_READ) {
3184 u16 temp_val;
3185 bnx2x_cl45_read(bp, phy, devad, 0xf, &temp_val);
3186 }
3187 }
Yaniv Rosner157fa282011-08-02 22:59:32 +00003188 if (phy->flags & FLAGS_MDC_MDIO_WA_B0)
3189 bnx2x_bits_dis(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_STATUS,
3190 EMAC_MDIO_STATUS_10MB);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003191 return rc;
3192}
3193
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003194
3195/******************************************************************/
3196/* BSC access functions from E3 */
3197/******************************************************************/
3198static void bnx2x_bsc_module_sel(struct link_params *params)
3199{
3200 int idx;
3201 u32 board_cfg, sfp_ctrl;
3202 u32 i2c_pins[I2C_SWITCH_WIDTH], i2c_val[I2C_SWITCH_WIDTH];
3203 struct bnx2x *bp = params->bp;
3204 u8 port = params->port;
3205 /* Read I2C output PINs */
3206 board_cfg = REG_RD(bp, params->shmem_base +
3207 offsetof(struct shmem_region,
3208 dev_info.shared_hw_config.board));
3209 i2c_pins[I2C_BSC0] = board_cfg & SHARED_HW_CFG_E3_I2C_MUX0_MASK;
3210 i2c_pins[I2C_BSC1] = (board_cfg & SHARED_HW_CFG_E3_I2C_MUX1_MASK) >>
3211 SHARED_HW_CFG_E3_I2C_MUX1_SHIFT;
3212
3213 /* Read I2C output value */
3214 sfp_ctrl = REG_RD(bp, params->shmem_base +
3215 offsetof(struct shmem_region,
3216 dev_info.port_hw_config[port].e3_cmn_pin_cfg));
3217 i2c_val[I2C_BSC0] = (sfp_ctrl & PORT_HW_CFG_E3_I2C_MUX0_MASK) > 0;
3218 i2c_val[I2C_BSC1] = (sfp_ctrl & PORT_HW_CFG_E3_I2C_MUX1_MASK) > 0;
3219 DP(NETIF_MSG_LINK, "Setting BSC switch\n");
3220 for (idx = 0; idx < I2C_SWITCH_WIDTH; idx++)
3221 bnx2x_set_cfg_pin(bp, i2c_pins[idx], i2c_val[idx]);
3222}
3223
3224static int bnx2x_bsc_read(struct link_params *params,
3225 struct bnx2x_phy *phy,
3226 u8 sl_devid,
3227 u16 sl_addr,
3228 u8 lc_addr,
3229 u8 xfer_cnt,
3230 u32 *data_array)
3231{
3232 u32 val, i;
3233 int rc = 0;
3234 struct bnx2x *bp = params->bp;
3235
3236 if ((sl_devid != 0xa0) && (sl_devid != 0xa2)) {
3237 DP(NETIF_MSG_LINK, "invalid sl_devid 0x%x\n", sl_devid);
3238 return -EINVAL;
3239 }
3240
3241 if (xfer_cnt > 16) {
3242 DP(NETIF_MSG_LINK, "invalid xfer_cnt %d. Max is 16 bytes\n",
3243 xfer_cnt);
3244 return -EINVAL;
3245 }
3246 bnx2x_bsc_module_sel(params);
3247
3248 xfer_cnt = 16 - lc_addr;
3249
3250 /* enable the engine */
3251 val = REG_RD(bp, MCP_REG_MCPR_IMC_COMMAND);
3252 val |= MCPR_IMC_COMMAND_ENABLE;
3253 REG_WR(bp, MCP_REG_MCPR_IMC_COMMAND, val);
3254
3255 /* program slave device ID */
3256 val = (sl_devid << 16) | sl_addr;
3257 REG_WR(bp, MCP_REG_MCPR_IMC_SLAVE_CONTROL, val);
3258
3259 /* start xfer with 0 byte to update the address pointer ???*/
3260 val = (MCPR_IMC_COMMAND_ENABLE) |
3261 (MCPR_IMC_COMMAND_WRITE_OP <<
3262 MCPR_IMC_COMMAND_OPERATION_BITSHIFT) |
3263 (lc_addr << MCPR_IMC_COMMAND_TRANSFER_ADDRESS_BITSHIFT) | (0);
3264 REG_WR(bp, MCP_REG_MCPR_IMC_COMMAND, val);
3265
3266 /* poll for completion */
3267 i = 0;
3268 val = REG_RD(bp, MCP_REG_MCPR_IMC_COMMAND);
3269 while (((val >> MCPR_IMC_COMMAND_IMC_STATUS_BITSHIFT) & 0x3) != 1) {
3270 udelay(10);
3271 val = REG_RD(bp, MCP_REG_MCPR_IMC_COMMAND);
3272 if (i++ > 1000) {
3273 DP(NETIF_MSG_LINK, "wr 0 byte timed out after %d try\n",
3274 i);
3275 rc = -EFAULT;
3276 break;
3277 }
3278 }
3279 if (rc == -EFAULT)
3280 return rc;
3281
3282 /* start xfer with read op */
3283 val = (MCPR_IMC_COMMAND_ENABLE) |
3284 (MCPR_IMC_COMMAND_READ_OP <<
3285 MCPR_IMC_COMMAND_OPERATION_BITSHIFT) |
3286 (lc_addr << MCPR_IMC_COMMAND_TRANSFER_ADDRESS_BITSHIFT) |
3287 (xfer_cnt);
3288 REG_WR(bp, MCP_REG_MCPR_IMC_COMMAND, val);
3289
3290 /* poll for completion */
3291 i = 0;
3292 val = REG_RD(bp, MCP_REG_MCPR_IMC_COMMAND);
3293 while (((val >> MCPR_IMC_COMMAND_IMC_STATUS_BITSHIFT) & 0x3) != 1) {
3294 udelay(10);
3295 val = REG_RD(bp, MCP_REG_MCPR_IMC_COMMAND);
3296 if (i++ > 1000) {
3297 DP(NETIF_MSG_LINK, "rd op timed out after %d try\n", i);
3298 rc = -EFAULT;
3299 break;
3300 }
3301 }
3302 if (rc == -EFAULT)
3303 return rc;
3304
3305 for (i = (lc_addr >> 2); i < 4; i++) {
3306 data_array[i] = REG_RD(bp, (MCP_REG_MCPR_IMC_DATAREG0 + i*4));
3307#ifdef __BIG_ENDIAN
3308 data_array[i] = ((data_array[i] & 0x000000ff) << 24) |
3309 ((data_array[i] & 0x0000ff00) << 8) |
3310 ((data_array[i] & 0x00ff0000) >> 8) |
3311 ((data_array[i] & 0xff000000) >> 24);
3312#endif
3313 }
3314 return rc;
3315}
3316
3317static void bnx2x_cl45_read_or_write(struct bnx2x *bp, struct bnx2x_phy *phy,
3318 u8 devad, u16 reg, u16 or_val)
3319{
3320 u16 val;
3321 bnx2x_cl45_read(bp, phy, devad, reg, &val);
3322 bnx2x_cl45_write(bp, phy, devad, reg, val | or_val);
3323}
3324
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00003325int bnx2x_phy_read(struct link_params *params, u8 phy_addr,
3326 u8 devad, u16 reg, u16 *ret_val)
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003327{
3328 u8 phy_index;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003329 /*
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003330 * Probe for the phy according to the given phy_addr, and execute
3331 * the read request on it
3332 */
3333 for (phy_index = 0; phy_index < params->num_phys; phy_index++) {
3334 if (params->phy[phy_index].addr == phy_addr) {
3335 return bnx2x_cl45_read(params->bp,
3336 &params->phy[phy_index], devad,
3337 reg, ret_val);
3338 }
3339 }
3340 return -EINVAL;
3341}
3342
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00003343int bnx2x_phy_write(struct link_params *params, u8 phy_addr,
3344 u8 devad, u16 reg, u16 val)
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003345{
3346 u8 phy_index;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003347 /*
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003348 * Probe for the phy according to the given phy_addr, and execute
3349 * the write request on it
3350 */
3351 for (phy_index = 0; phy_index < params->num_phys; phy_index++) {
3352 if (params->phy[phy_index].addr == phy_addr) {
3353 return bnx2x_cl45_write(params->bp,
3354 &params->phy[phy_index], devad,
3355 reg, val);
3356 }
3357 }
3358 return -EINVAL;
3359}
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003360static u8 bnx2x_get_warpcore_lane(struct bnx2x_phy *phy,
3361 struct link_params *params)
3362{
3363 u8 lane = 0;
3364 struct bnx2x *bp = params->bp;
3365 u32 path_swap, path_swap_ovr;
3366 u8 path, port;
3367
3368 path = BP_PATH(bp);
3369 port = params->port;
3370
3371 if (bnx2x_is_4_port_mode(bp)) {
3372 u32 port_swap, port_swap_ovr;
3373
3374 /*figure out path swap value */
3375 path_swap_ovr = REG_RD(bp, MISC_REG_FOUR_PORT_PATH_SWAP_OVWR);
3376 if (path_swap_ovr & 0x1)
3377 path_swap = (path_swap_ovr & 0x2);
3378 else
3379 path_swap = REG_RD(bp, MISC_REG_FOUR_PORT_PATH_SWAP);
3380
3381 if (path_swap)
3382 path = path ^ 1;
3383
3384 /*figure out port swap value */
3385 port_swap_ovr = REG_RD(bp, MISC_REG_FOUR_PORT_PORT_SWAP_OVWR);
3386 if (port_swap_ovr & 0x1)
3387 port_swap = (port_swap_ovr & 0x2);
3388 else
3389 port_swap = REG_RD(bp, MISC_REG_FOUR_PORT_PORT_SWAP);
3390
3391 if (port_swap)
3392 port = port ^ 1;
3393
3394 lane = (port<<1) + path;
3395 } else { /* two port mode - no port swap */
3396
3397 /*figure out path swap value */
3398 path_swap_ovr =
3399 REG_RD(bp, MISC_REG_TWO_PORT_PATH_SWAP_OVWR);
3400 if (path_swap_ovr & 0x1) {
3401 path_swap = (path_swap_ovr & 0x2);
3402 } else {
3403 path_swap =
3404 REG_RD(bp, MISC_REG_TWO_PORT_PATH_SWAP);
3405 }
3406 if (path_swap)
3407 path = path ^ 1;
3408
3409 lane = path << 1 ;
3410 }
3411 return lane;
3412}
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003413
Yaniv Rosnerec146a62011-05-31 21:29:27 +00003414static void bnx2x_set_aer_mmd(struct link_params *params,
3415 struct bnx2x_phy *phy)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003416{
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003417 u32 ser_lane;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00003418 u16 offset, aer_val;
3419 struct bnx2x *bp = params->bp;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003420 ser_lane = ((params->lane_config &
3421 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_MASK) >>
3422 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_SHIFT);
3423
Yaniv Rosnerec146a62011-05-31 21:29:27 +00003424 offset = (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT) ?
3425 (phy->addr + ser_lane) : 0;
3426
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003427 if (USES_WARPCORE(bp)) {
3428 aer_val = bnx2x_get_warpcore_lane(phy, params);
3429 /*
3430 * In Dual-lane mode, two lanes are joined together,
3431 * so in order to configure them, the AER broadcast method is
3432 * used here.
3433 * 0x200 is the broadcast address for lanes 0,1
3434 * 0x201 is the broadcast address for lanes 2,3
3435 */
3436 if (phy->flags & FLAGS_WC_DUAL_MODE)
3437 aer_val = (aer_val >> 1) | 0x200;
3438 } else if (CHIP_IS_E2(bp))
Yaniv Rosner82a0d472011-01-18 04:33:52 +00003439 aer_val = 0x3800 + offset - 1;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00003440 else
3441 aer_val = 0x3800 + offset;
Yaniv Rosnerec146a62011-05-31 21:29:27 +00003442 DP(NETIF_MSG_LINK, "Set AER to 0x%x\n", aer_val);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00003443 CL22_WR_OVER_CL45(bp, phy, MDIO_REG_BANK_AER_BLOCK,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003444 MDIO_AER_BLOCK_AER_REG, aer_val);
Yaniv Rosnerec146a62011-05-31 21:29:27 +00003445
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003446}
3447
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003448/******************************************************************/
3449/* Internal phy section */
3450/******************************************************************/
3451
3452static void bnx2x_set_serdes_access(struct bnx2x *bp, u8 port)
3453{
3454 u32 emac_base = (port) ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
3455
3456 /* Set Clause 22 */
3457 REG_WR(bp, NIG_REG_SERDES0_CTRL_MD_ST + port*0x10, 1);
3458 REG_WR(bp, emac_base + EMAC_REG_EMAC_MDIO_COMM, 0x245f8000);
3459 udelay(500);
3460 REG_WR(bp, emac_base + EMAC_REG_EMAC_MDIO_COMM, 0x245d000f);
3461 udelay(500);
3462 /* Set Clause 45 */
3463 REG_WR(bp, NIG_REG_SERDES0_CTRL_MD_ST + port*0x10, 0);
3464}
3465
3466static void bnx2x_serdes_deassert(struct bnx2x *bp, u8 port)
3467{
3468 u32 val;
3469
3470 DP(NETIF_MSG_LINK, "bnx2x_serdes_deassert\n");
3471
3472 val = SERDES_RESET_BITS << (port*16);
3473
3474 /* reset and unreset the SerDes/XGXS */
3475 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_CLEAR, val);
3476 udelay(500);
3477 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_SET, val);
3478
3479 bnx2x_set_serdes_access(bp, port);
3480
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003481 REG_WR(bp, NIG_REG_SERDES0_CTRL_MD_DEVAD + port*0x10,
3482 DEFAULT_PHY_DEV_ADDR);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003483}
3484
3485static void bnx2x_xgxs_deassert(struct link_params *params)
3486{
3487 struct bnx2x *bp = params->bp;
3488 u8 port;
3489 u32 val;
3490 DP(NETIF_MSG_LINK, "bnx2x_xgxs_deassert\n");
3491 port = params->port;
3492
3493 val = XGXS_RESET_BITS << (port*16);
3494
3495 /* reset and unreset the SerDes/XGXS */
3496 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_CLEAR, val);
3497 udelay(500);
3498 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_SET, val);
3499
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003500 REG_WR(bp, NIG_REG_XGXS0_CTRL_MD_ST + port*0x18, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003501 REG_WR(bp, NIG_REG_XGXS0_CTRL_MD_DEVAD + port*0x18,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003502 params->phy[INT_PHY].def_md_devad);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003503}
3504
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00003505static void bnx2x_calc_ieee_aneg_adv(struct bnx2x_phy *phy,
3506 struct link_params *params, u16 *ieee_fc)
3507{
3508 struct bnx2x *bp = params->bp;
3509 *ieee_fc = MDIO_COMBO_IEEE0_AUTO_NEG_ADV_FULL_DUPLEX;
3510 /**
3511 * resolve pause mode and advertisement Please refer to Table
3512 * 28B-3 of the 802.3ab-1999 spec
3513 */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003514
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00003515 switch (phy->req_flow_ctrl) {
3516 case BNX2X_FLOW_CTRL_AUTO:
3517 if (params->req_fc_auto_adv == BNX2X_FLOW_CTRL_BOTH)
3518 *ieee_fc |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH;
3519 else
3520 *ieee_fc |=
3521 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC;
3522 break;
3523
3524 case BNX2X_FLOW_CTRL_TX:
3525 *ieee_fc |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC;
3526 break;
3527
3528 case BNX2X_FLOW_CTRL_RX:
3529 case BNX2X_FLOW_CTRL_BOTH:
3530 *ieee_fc |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH;
3531 break;
3532
3533 case BNX2X_FLOW_CTRL_NONE:
3534 default:
3535 *ieee_fc |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE;
3536 break;
3537 }
3538 DP(NETIF_MSG_LINK, "ieee_fc = 0x%x\n", *ieee_fc);
3539}
3540
3541static void set_phy_vars(struct link_params *params,
3542 struct link_vars *vars)
3543{
3544 struct bnx2x *bp = params->bp;
3545 u8 actual_phy_idx, phy_index, link_cfg_idx;
3546 u8 phy_config_swapped = params->multi_phy_config &
3547 PORT_HW_CFG_PHY_SWAPPED_ENABLED;
3548 for (phy_index = INT_PHY; phy_index < params->num_phys;
3549 phy_index++) {
3550 link_cfg_idx = LINK_CONFIG_IDX(phy_index);
3551 actual_phy_idx = phy_index;
3552 if (phy_config_swapped) {
3553 if (phy_index == EXT_PHY1)
3554 actual_phy_idx = EXT_PHY2;
3555 else if (phy_index == EXT_PHY2)
3556 actual_phy_idx = EXT_PHY1;
3557 }
3558 params->phy[actual_phy_idx].req_flow_ctrl =
3559 params->req_flow_ctrl[link_cfg_idx];
3560
3561 params->phy[actual_phy_idx].req_line_speed =
3562 params->req_line_speed[link_cfg_idx];
3563
3564 params->phy[actual_phy_idx].speed_cap_mask =
3565 params->speed_cap_mask[link_cfg_idx];
3566
3567 params->phy[actual_phy_idx].req_duplex =
3568 params->req_duplex[link_cfg_idx];
3569
3570 if (params->req_line_speed[link_cfg_idx] ==
3571 SPEED_AUTO_NEG)
3572 vars->link_status |= LINK_STATUS_AUTO_NEGOTIATE_ENABLED;
3573
3574 DP(NETIF_MSG_LINK, "req_flow_ctrl %x, req_line_speed %x,"
3575 " speed_cap_mask %x\n",
3576 params->phy[actual_phy_idx].req_flow_ctrl,
3577 params->phy[actual_phy_idx].req_line_speed,
3578 params->phy[actual_phy_idx].speed_cap_mask);
3579 }
3580}
3581
3582static void bnx2x_ext_phy_set_pause(struct link_params *params,
3583 struct bnx2x_phy *phy,
3584 struct link_vars *vars)
3585{
3586 u16 val;
3587 struct bnx2x *bp = params->bp;
3588 /* read modify write pause advertizing */
3589 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV_PAUSE, &val);
3590
3591 val &= ~MDIO_AN_REG_ADV_PAUSE_BOTH;
3592
3593 /* Please refer to Table 28B-3 of 802.3ab-1999 spec. */
3594 bnx2x_calc_ieee_aneg_adv(phy, params, &vars->ieee_fc);
3595 if ((vars->ieee_fc &
3596 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC) ==
3597 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC) {
3598 val |= MDIO_AN_REG_ADV_PAUSE_ASYMMETRIC;
3599 }
3600 if ((vars->ieee_fc &
3601 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) ==
3602 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) {
3603 val |= MDIO_AN_REG_ADV_PAUSE_PAUSE;
3604 }
3605 DP(NETIF_MSG_LINK, "Ext phy AN advertize 0x%x\n", val);
3606 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV_PAUSE, val);
3607}
3608
3609static void bnx2x_pause_resolve(struct link_vars *vars, u32 pause_result)
3610{ /* LD LP */
3611 switch (pause_result) { /* ASYM P ASYM P */
3612 case 0xb: /* 1 0 1 1 */
3613 vars->flow_ctrl = BNX2X_FLOW_CTRL_TX;
3614 break;
3615
3616 case 0xe: /* 1 1 1 0 */
3617 vars->flow_ctrl = BNX2X_FLOW_CTRL_RX;
3618 break;
3619
3620 case 0x5: /* 0 1 0 1 */
3621 case 0x7: /* 0 1 1 1 */
3622 case 0xd: /* 1 1 0 1 */
3623 case 0xf: /* 1 1 1 1 */
3624 vars->flow_ctrl = BNX2X_FLOW_CTRL_BOTH;
3625 break;
3626
3627 default:
3628 break;
3629 }
3630 if (pause_result & (1<<0))
3631 vars->link_status |= LINK_STATUS_LINK_PARTNER_SYMMETRIC_PAUSE;
3632 if (pause_result & (1<<1))
3633 vars->link_status |= LINK_STATUS_LINK_PARTNER_ASYMMETRIC_PAUSE;
3634}
3635
3636static u8 bnx2x_ext_phy_resolve_fc(struct bnx2x_phy *phy,
3637 struct link_params *params,
3638 struct link_vars *vars)
3639{
3640 struct bnx2x *bp = params->bp;
3641 u16 ld_pause; /* local */
3642 u16 lp_pause; /* link partner */
3643 u16 pause_result;
3644 u8 ret = 0;
3645 /* read twice */
3646
3647 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
3648
3649 if (phy->req_flow_ctrl != BNX2X_FLOW_CTRL_AUTO)
3650 vars->flow_ctrl = phy->req_flow_ctrl;
3651 else if (phy->req_line_speed != SPEED_AUTO_NEG)
3652 vars->flow_ctrl = params->req_fc_auto_adv;
3653 else if (vars->link_status & LINK_STATUS_AUTO_NEGOTIATE_COMPLETE) {
3654 ret = 1;
Yaniv Rosner52c4d6c2011-07-05 01:06:34 +00003655 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54618SE) {
Yaniv Rosner6583e332011-06-14 01:34:17 +00003656 bnx2x_cl22_read(bp, phy,
3657 0x4, &ld_pause);
3658 bnx2x_cl22_read(bp, phy,
3659 0x5, &lp_pause);
3660 } else {
3661 bnx2x_cl45_read(bp, phy,
3662 MDIO_AN_DEVAD,
3663 MDIO_AN_REG_ADV_PAUSE, &ld_pause);
3664 bnx2x_cl45_read(bp, phy,
3665 MDIO_AN_DEVAD,
3666 MDIO_AN_REG_LP_AUTO_NEG, &lp_pause);
3667 }
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00003668 pause_result = (ld_pause &
3669 MDIO_AN_REG_ADV_PAUSE_MASK) >> 8;
3670 pause_result |= (lp_pause &
3671 MDIO_AN_REG_ADV_PAUSE_MASK) >> 10;
3672 DP(NETIF_MSG_LINK, "Ext PHY pause result 0x%x\n",
3673 pause_result);
3674 bnx2x_pause_resolve(vars, pause_result);
3675 }
3676 return ret;
3677}
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003678/******************************************************************/
3679/* Warpcore section */
3680/******************************************************************/
3681/* The init_internal_warpcore should mirror the xgxs,
3682 * i.e. reset the lane (if needed), set aer for the
3683 * init configuration, and set/clear SGMII flag. Internal
3684 * phy init is done purely in phy_init stage.
3685 */
3686static void bnx2x_warpcore_enable_AN_KR(struct bnx2x_phy *phy,
3687 struct link_params *params,
3688 struct link_vars *vars) {
Yaniv Rosnera34bc962011-07-05 01:06:41 +00003689 u16 val16 = 0, lane, bam37 = 0;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003690 struct bnx2x *bp = params->bp;
3691 DP(NETIF_MSG_LINK, "Enable Auto Negotiation for KR\n");
Yaniv Rosnera9077bf2011-10-27 05:09:46 +00003692
3693 /* Disable Autoneg: re-enable it after adv is done. */
3694 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
3695 MDIO_WC_REG_IEEE0BLK_MIICNTL, 0);
3696
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003697 /* Check adding advertisement for 1G KX */
3698 if (((vars->line_speed == SPEED_AUTO_NEG) &&
3699 (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) ||
3700 (vars->line_speed == SPEED_1000)) {
3701 u16 sd_digital;
3702 val16 |= (1<<5);
3703
3704 /* Enable CL37 1G Parallel Detect */
3705 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
3706 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2, &sd_digital);
3707 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3708 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2,
3709 (sd_digital | 0x1));
3710
3711 DP(NETIF_MSG_LINK, "Advertize 1G\n");
3712 }
3713 if (((vars->line_speed == SPEED_AUTO_NEG) &&
3714 (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) ||
3715 (vars->line_speed == SPEED_10000)) {
3716 /* Check adding advertisement for 10G KR */
3717 val16 |= (1<<7);
3718 /* Enable 10G Parallel Detect */
3719 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
3720 MDIO_WC_REG_PAR_DET_10G_CTRL, 1);
3721
3722 DP(NETIF_MSG_LINK, "Advertize 10G\n");
3723 }
3724
3725 /* Set Transmit PMD settings */
3726 lane = bnx2x_get_warpcore_lane(phy, params);
3727 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3728 MDIO_WC_REG_TX0_TX_DRIVER + 0x10*lane,
3729 ((0x02 << MDIO_WC_REG_TX0_TX_DRIVER_POST2_COEFF_OFFSET) |
3730 (0x06 << MDIO_WC_REG_TX0_TX_DRIVER_IDRIVER_OFFSET) |
3731 (0x09 << MDIO_WC_REG_TX0_TX_DRIVER_IPRE_DRIVER_OFFSET)));
3732 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3733 MDIO_WC_REG_CL72_USERB0_CL72_OS_DEF_CTRL,
3734 0x03f0);
3735 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3736 MDIO_WC_REG_CL72_USERB0_CL72_2P5_DEF_CTRL,
3737 0x03f0);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003738
3739 /* Advertised speeds */
3740 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
3741 MDIO_WC_REG_AN_IEEE1BLK_AN_ADVERTISEMENT1, val16);
3742
David S. Miller8decf862011-09-22 03:23:13 -04003743 /* Advertised and set FEC (Forward Error Correction) */
3744 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
3745 MDIO_WC_REG_AN_IEEE1BLK_AN_ADVERTISEMENT2,
3746 (MDIO_WC_REG_AN_IEEE1BLK_AN_ADV2_FEC_ABILITY |
3747 MDIO_WC_REG_AN_IEEE1BLK_AN_ADV2_FEC_REQ));
3748
Yaniv Rosnera34bc962011-07-05 01:06:41 +00003749 /* Enable CL37 BAM */
3750 if (REG_RD(bp, params->shmem_base +
3751 offsetof(struct shmem_region, dev_info.
3752 port_hw_config[params->port].default_cfg)) &
3753 PORT_HW_CFG_ENABLE_BAM_ON_KR_ENABLED) {
3754 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
3755 MDIO_WC_REG_DIGITAL6_MP5_NEXTPAGECTRL, &bam37);
3756 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3757 MDIO_WC_REG_DIGITAL6_MP5_NEXTPAGECTRL, bam37 | 1);
3758 DP(NETIF_MSG_LINK, "Enable CL37 BAM on KR\n");
3759 }
3760
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003761 /* Advertise pause */
3762 bnx2x_ext_phy_set_pause(params, phy, vars);
3763
Yaniv Rosnera9077bf2011-10-27 05:09:46 +00003764 vars->rx_tx_asic_rst = MAX_KR_LINK_RETRY;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003765
3766 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
3767 MDIO_WC_REG_DIGITAL5_MISC7, &val16);
3768
3769 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3770 MDIO_WC_REG_DIGITAL5_MISC7, val16 | 0x100);
Yaniv Rosnera9077bf2011-10-27 05:09:46 +00003771
3772 /* Over 1G - AN local device user page 1 */
3773 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3774 MDIO_WC_REG_DIGITAL3_UP1, 0x1f);
3775
3776 /* Enable Autoneg */
3777 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
3778 MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x1000);
3779
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003780}
3781
3782static void bnx2x_warpcore_set_10G_KR(struct bnx2x_phy *phy,
3783 struct link_params *params,
3784 struct link_vars *vars)
3785{
3786 struct bnx2x *bp = params->bp;
3787 u16 val;
3788
3789 /* Disable Autoneg */
3790 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3791 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2, 0x7);
3792
3793 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
3794 MDIO_WC_REG_PAR_DET_10G_CTRL, 0);
3795
3796 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3797 MDIO_WC_REG_CL72_USERB0_CL72_MISC1_CONTROL, 0x3f00);
3798
3799 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
3800 MDIO_WC_REG_AN_IEEE1BLK_AN_ADVERTISEMENT1, 0);
3801
3802 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
3803 MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x0);
3804
3805 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3806 MDIO_WC_REG_DIGITAL3_UP1, 0x1);
3807
3808 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3809 MDIO_WC_REG_DIGITAL5_MISC7, 0xa);
3810
3811 /* Disable CL36 PCS Tx */
3812 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3813 MDIO_WC_REG_XGXSBLK1_LANECTRL0, 0x0);
3814
3815 /* Double Wide Single Data Rate @ pll rate */
3816 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3817 MDIO_WC_REG_XGXSBLK1_LANECTRL1, 0xFFFF);
3818
3819 /* Leave cl72 training enable, needed for KR */
3820 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD,
3821 MDIO_WC_REG_PMD_IEEE9BLK_TENGBASE_KR_PMD_CONTROL_REGISTER_150,
3822 0x2);
3823
3824 /* Leave CL72 enabled */
3825 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
3826 MDIO_WC_REG_CL72_USERB0_CL72_MISC1_CONTROL,
3827 &val);
3828 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3829 MDIO_WC_REG_CL72_USERB0_CL72_MISC1_CONTROL,
3830 val | 0x3800);
3831
3832 /* Set speed via PMA/PMD register */
3833 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD,
3834 MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x2040);
3835
3836 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD,
3837 MDIO_WC_REG_IEEE0BLK_AUTONEGNP, 0xB);
3838
3839 /*Enable encoded forced speed */
3840 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3841 MDIO_WC_REG_SERDESDIGITAL_MISC2, 0x30);
3842
3843 /* Turn TX scramble payload only the 64/66 scrambler */
3844 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3845 MDIO_WC_REG_TX66_CONTROL, 0x9);
3846
3847 /* Turn RX scramble payload only the 64/66 scrambler */
3848 bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
3849 MDIO_WC_REG_RX66_CONTROL, 0xF9);
3850
3851 /* set and clear loopback to cause a reset to 64/66 decoder */
3852 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3853 MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x4000);
3854 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3855 MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x0);
3856
3857}
3858
3859static void bnx2x_warpcore_set_10G_XFI(struct bnx2x_phy *phy,
3860 struct link_params *params,
3861 u8 is_xfi)
3862{
3863 struct bnx2x *bp = params->bp;
3864 u16 misc1_val, tap_val, tx_driver_val, lane, val;
3865 /* Hold rxSeqStart */
3866 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
3867 MDIO_WC_REG_DSC2B0_DSC_MISC_CTRL0, &val);
3868 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3869 MDIO_WC_REG_DSC2B0_DSC_MISC_CTRL0, (val | 0x8000));
3870
3871 /* Hold tx_fifo_reset */
3872 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
3873 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X3, &val);
3874 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3875 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X3, (val | 0x1));
3876
3877 /* Disable CL73 AN */
3878 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0);
3879
3880 /* Disable 100FX Enable and Auto-Detect */
3881 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
3882 MDIO_WC_REG_FX100_CTRL1, &val);
3883 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3884 MDIO_WC_REG_FX100_CTRL1, (val & 0xFFFA));
3885
3886 /* Disable 100FX Idle detect */
3887 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
3888 MDIO_WC_REG_FX100_CTRL3, &val);
3889 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3890 MDIO_WC_REG_FX100_CTRL3, (val | 0x0080));
3891
3892 /* Set Block address to Remote PHY & Clear forced_speed[5] */
3893 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
3894 MDIO_WC_REG_DIGITAL4_MISC3, &val);
3895 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3896 MDIO_WC_REG_DIGITAL4_MISC3, (val & 0xFF7F));
3897
3898 /* Turn off auto-detect & fiber mode */
3899 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
3900 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X1, &val);
3901 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3902 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X1,
3903 (val & 0xFFEE));
3904
3905 /* Set filter_force_link, disable_false_link and parallel_detect */
3906 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
3907 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2, &val);
3908 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3909 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2,
3910 ((val | 0x0006) & 0xFFFE));
3911
3912 /* Set XFI / SFI */
3913 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
3914 MDIO_WC_REG_SERDESDIGITAL_MISC1, &misc1_val);
3915
3916 misc1_val &= ~(0x1f);
3917
3918 if (is_xfi) {
3919 misc1_val |= 0x5;
3920 tap_val = ((0x08 << MDIO_WC_REG_TX_FIR_TAP_POST_TAP_OFFSET) |
3921 (0x37 << MDIO_WC_REG_TX_FIR_TAP_MAIN_TAP_OFFSET) |
3922 (0x00 << MDIO_WC_REG_TX_FIR_TAP_PRE_TAP_OFFSET));
3923 tx_driver_val =
3924 ((0x00 << MDIO_WC_REG_TX0_TX_DRIVER_POST2_COEFF_OFFSET) |
3925 (0x02 << MDIO_WC_REG_TX0_TX_DRIVER_IDRIVER_OFFSET) |
3926 (0x03 << MDIO_WC_REG_TX0_TX_DRIVER_IPRE_DRIVER_OFFSET));
3927
3928 } else {
3929 misc1_val |= 0x9;
3930 tap_val = ((0x12 << MDIO_WC_REG_TX_FIR_TAP_POST_TAP_OFFSET) |
3931 (0x2d << MDIO_WC_REG_TX_FIR_TAP_MAIN_TAP_OFFSET) |
3932 (0x00 << MDIO_WC_REG_TX_FIR_TAP_PRE_TAP_OFFSET));
3933 tx_driver_val =
3934 ((0x02 << MDIO_WC_REG_TX0_TX_DRIVER_POST2_COEFF_OFFSET) |
3935 (0x02 << MDIO_WC_REG_TX0_TX_DRIVER_IDRIVER_OFFSET) |
3936 (0x02 << MDIO_WC_REG_TX0_TX_DRIVER_IPRE_DRIVER_OFFSET));
3937 }
3938 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3939 MDIO_WC_REG_SERDESDIGITAL_MISC1, misc1_val);
3940
3941 /* Set Transmit PMD settings */
3942 lane = bnx2x_get_warpcore_lane(phy, params);
3943 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3944 MDIO_WC_REG_TX_FIR_TAP,
3945 tap_val | MDIO_WC_REG_TX_FIR_TAP_ENABLE);
3946 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3947 MDIO_WC_REG_TX0_TX_DRIVER + 0x10*lane,
3948 tx_driver_val);
3949
3950 /* Enable fiber mode, enable and invert sig_det */
3951 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
3952 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X1, &val);
3953 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3954 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X1, val | 0xd);
3955
3956 /* Set Block address to Remote PHY & Set forced_speed[5], 40bit mode */
3957 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
3958 MDIO_WC_REG_DIGITAL4_MISC3, &val);
3959 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3960 MDIO_WC_REG_DIGITAL4_MISC3, val | 0x8080);
3961
3962 /* 10G XFI Full Duplex */
3963 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3964 MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x100);
3965
3966 /* Release tx_fifo_reset */
3967 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
3968 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X3, &val);
3969 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3970 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X3, val & 0xFFFE);
3971
3972 /* Release rxSeqStart */
3973 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
3974 MDIO_WC_REG_DSC2B0_DSC_MISC_CTRL0, &val);
3975 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3976 MDIO_WC_REG_DSC2B0_DSC_MISC_CTRL0, (val & 0x7FFF));
3977}
3978
3979static void bnx2x_warpcore_set_20G_KR2(struct bnx2x *bp,
3980 struct bnx2x_phy *phy)
3981{
3982 DP(NETIF_MSG_LINK, "KR2 still not supported !!!\n");
3983}
3984
3985static void bnx2x_warpcore_set_20G_DXGXS(struct bnx2x *bp,
3986 struct bnx2x_phy *phy,
3987 u16 lane)
3988{
3989 /* Rx0 anaRxControl1G */
3990 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3991 MDIO_WC_REG_RX0_ANARXCONTROL1G, 0x90);
3992
3993 /* Rx2 anaRxControl1G */
3994 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3995 MDIO_WC_REG_RX2_ANARXCONTROL1G, 0x90);
3996
3997 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3998 MDIO_WC_REG_RX66_SCW0, 0xE070);
3999
4000 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4001 MDIO_WC_REG_RX66_SCW1, 0xC0D0);
4002
4003 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4004 MDIO_WC_REG_RX66_SCW2, 0xA0B0);
4005
4006 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4007 MDIO_WC_REG_RX66_SCW3, 0x8090);
4008
4009 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4010 MDIO_WC_REG_RX66_SCW0_MASK, 0xF0F0);
4011
4012 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4013 MDIO_WC_REG_RX66_SCW1_MASK, 0xF0F0);
4014
4015 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4016 MDIO_WC_REG_RX66_SCW2_MASK, 0xF0F0);
4017
4018 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4019 MDIO_WC_REG_RX66_SCW3_MASK, 0xF0F0);
4020
4021 /* Serdes Digital Misc1 */
4022 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4023 MDIO_WC_REG_SERDESDIGITAL_MISC1, 0x6008);
4024
4025 /* Serdes Digital4 Misc3 */
4026 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4027 MDIO_WC_REG_DIGITAL4_MISC3, 0x8088);
4028
4029 /* Set Transmit PMD settings */
4030 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4031 MDIO_WC_REG_TX_FIR_TAP,
4032 ((0x12 << MDIO_WC_REG_TX_FIR_TAP_POST_TAP_OFFSET) |
4033 (0x2d << MDIO_WC_REG_TX_FIR_TAP_MAIN_TAP_OFFSET) |
4034 (0x00 << MDIO_WC_REG_TX_FIR_TAP_PRE_TAP_OFFSET) |
4035 MDIO_WC_REG_TX_FIR_TAP_ENABLE));
4036 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4037 MDIO_WC_REG_TX0_TX_DRIVER + 0x10*lane,
4038 ((0x02 << MDIO_WC_REG_TX0_TX_DRIVER_POST2_COEFF_OFFSET) |
4039 (0x02 << MDIO_WC_REG_TX0_TX_DRIVER_IDRIVER_OFFSET) |
4040 (0x02 << MDIO_WC_REG_TX0_TX_DRIVER_IPRE_DRIVER_OFFSET)));
4041}
4042
4043static void bnx2x_warpcore_set_sgmii_speed(struct bnx2x_phy *phy,
4044 struct link_params *params,
4045 u8 fiber_mode)
4046{
4047 struct bnx2x *bp = params->bp;
4048 u16 val16, digctrl_kx1, digctrl_kx2;
4049 u8 lane;
4050
4051 lane = bnx2x_get_warpcore_lane(phy, params);
4052
4053 /* Clear XFI clock comp in non-10G single lane mode. */
4054 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4055 MDIO_WC_REG_RX66_CONTROL, &val16);
4056 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4057 MDIO_WC_REG_RX66_CONTROL, val16 & ~(3<<13));
4058
4059 if (phy->req_line_speed == SPEED_AUTO_NEG) {
4060 /* SGMII Autoneg */
4061 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4062 MDIO_WC_REG_COMBO_IEEE0_MIICTRL, &val16);
4063 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4064 MDIO_WC_REG_COMBO_IEEE0_MIICTRL,
4065 val16 | 0x1000);
4066 DP(NETIF_MSG_LINK, "set SGMII AUTONEG\n");
4067 } else {
4068 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4069 MDIO_WC_REG_COMBO_IEEE0_MIICTRL, &val16);
4070 val16 &= 0xcfbf;
4071 switch (phy->req_line_speed) {
4072 case SPEED_10:
4073 break;
4074 case SPEED_100:
4075 val16 |= 0x2000;
4076 break;
4077 case SPEED_1000:
4078 val16 |= 0x0040;
4079 break;
4080 default:
Joe Perches94f05b02011-08-14 12:16:20 +00004081 DP(NETIF_MSG_LINK,
4082 "Speed not supported: 0x%x\n", phy->req_line_speed);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004083 return;
4084 }
4085
4086 if (phy->req_duplex == DUPLEX_FULL)
4087 val16 |= 0x0100;
4088
4089 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4090 MDIO_WC_REG_COMBO_IEEE0_MIICTRL, val16);
4091
4092 DP(NETIF_MSG_LINK, "set SGMII force speed %d\n",
4093 phy->req_line_speed);
4094 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4095 MDIO_WC_REG_COMBO_IEEE0_MIICTRL, &val16);
4096 DP(NETIF_MSG_LINK, " (readback) %x\n", val16);
4097 }
4098
4099 /* SGMII Slave mode and disable signal detect */
4100 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4101 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X1, &digctrl_kx1);
4102 if (fiber_mode)
4103 digctrl_kx1 = 1;
4104 else
4105 digctrl_kx1 &= 0xff4a;
4106
4107 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4108 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X1,
4109 digctrl_kx1);
4110
4111 /* Turn off parallel detect */
4112 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4113 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2, &digctrl_kx2);
4114 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4115 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2,
4116 (digctrl_kx2 & ~(1<<2)));
4117
4118 /* Re-enable parallel detect */
4119 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4120 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2,
4121 (digctrl_kx2 | (1<<2)));
4122
4123 /* Enable autodet */
4124 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4125 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X1,
4126 (digctrl_kx1 | 0x10));
4127}
4128
4129static void bnx2x_warpcore_reset_lane(struct bnx2x *bp,
4130 struct bnx2x_phy *phy,
4131 u8 reset)
4132{
4133 u16 val;
4134 /* Take lane out of reset after configuration is finished */
4135 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4136 MDIO_WC_REG_DIGITAL5_MISC6, &val);
4137 if (reset)
4138 val |= 0xC000;
4139 else
4140 val &= 0x3FFF;
4141 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4142 MDIO_WC_REG_DIGITAL5_MISC6, val);
4143 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4144 MDIO_WC_REG_DIGITAL5_MISC6, &val);
4145}
4146
4147
4148 /* Clear SFI/XFI link settings registers */
4149static void bnx2x_warpcore_clear_regs(struct bnx2x_phy *phy,
4150 struct link_params *params,
4151 u16 lane)
4152{
4153 struct bnx2x *bp = params->bp;
4154 u16 val16;
4155
4156 /* Set XFI clock comp as default. */
4157 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4158 MDIO_WC_REG_RX66_CONTROL, &val16);
4159 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4160 MDIO_WC_REG_RX66_CONTROL, val16 | (3<<13));
4161
4162 bnx2x_warpcore_reset_lane(bp, phy, 1);
4163 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0);
4164 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4165 MDIO_WC_REG_FX100_CTRL1, 0x014a);
4166 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4167 MDIO_WC_REG_FX100_CTRL3, 0x0800);
4168 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4169 MDIO_WC_REG_DIGITAL4_MISC3, 0x8008);
4170 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4171 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X1, 0x0195);
4172 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4173 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2, 0x0007);
4174 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4175 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X3, 0x0002);
4176 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4177 MDIO_WC_REG_SERDESDIGITAL_MISC1, 0x6000);
4178 lane = bnx2x_get_warpcore_lane(phy, params);
4179 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4180 MDIO_WC_REG_TX_FIR_TAP, 0x0000);
4181 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4182 MDIO_WC_REG_TX0_TX_DRIVER + 0x10*lane, 0x0990);
4183 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4184 MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x2040);
4185 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4186 MDIO_WC_REG_COMBO_IEEE0_MIICTRL, 0x0140);
4187 bnx2x_warpcore_reset_lane(bp, phy, 0);
4188}
4189
4190static int bnx2x_get_mod_abs_int_cfg(struct bnx2x *bp,
4191 u32 chip_id,
4192 u32 shmem_base, u8 port,
4193 u8 *gpio_num, u8 *gpio_port)
4194{
4195 u32 cfg_pin;
4196 *gpio_num = 0;
4197 *gpio_port = 0;
4198 if (CHIP_IS_E3(bp)) {
4199 cfg_pin = (REG_RD(bp, shmem_base +
4200 offsetof(struct shmem_region,
4201 dev_info.port_hw_config[port].e3_sfp_ctrl)) &
4202 PORT_HW_CFG_E3_MOD_ABS_MASK) >>
4203 PORT_HW_CFG_E3_MOD_ABS_SHIFT;
4204
4205 /*
4206 * Should not happen. This function called upon interrupt
4207 * triggered by GPIO ( since EPIO can only generate interrupts
4208 * to MCP).
4209 * So if this function was called and none of the GPIOs was set,
4210 * it means the shit hit the fan.
4211 */
4212 if ((cfg_pin < PIN_CFG_GPIO0_P0) ||
4213 (cfg_pin > PIN_CFG_GPIO3_P1)) {
Joe Perches94f05b02011-08-14 12:16:20 +00004214 DP(NETIF_MSG_LINK,
4215 "ERROR: Invalid cfg pin %x for module detect indication\n",
4216 cfg_pin);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004217 return -EINVAL;
4218 }
4219
4220 *gpio_num = (cfg_pin - PIN_CFG_GPIO0_P0) & 0x3;
4221 *gpio_port = (cfg_pin - PIN_CFG_GPIO0_P0) >> 2;
4222 } else {
4223 *gpio_num = MISC_REGISTERS_GPIO_3;
4224 *gpio_port = port;
4225 }
4226 DP(NETIF_MSG_LINK, "MOD_ABS int GPIO%d_P%d\n", *gpio_num, *gpio_port);
4227 return 0;
4228}
4229
4230static int bnx2x_is_sfp_module_plugged(struct bnx2x_phy *phy,
4231 struct link_params *params)
4232{
4233 struct bnx2x *bp = params->bp;
4234 u8 gpio_num, gpio_port;
4235 u32 gpio_val;
4236 if (bnx2x_get_mod_abs_int_cfg(bp, params->chip_id,
4237 params->shmem_base, params->port,
4238 &gpio_num, &gpio_port) != 0)
4239 return 0;
4240 gpio_val = bnx2x_get_gpio(bp, gpio_num, gpio_port);
4241
4242 /* Call the handling function in case module is detected */
4243 if (gpio_val == 0)
4244 return 1;
4245 else
4246 return 0;
4247}
Yaniv Rosnera9077bf2011-10-27 05:09:46 +00004248static int bnx2x_warpcore_get_sigdet(struct bnx2x_phy *phy,
4249 struct link_params *params)
4250{
4251 u16 gp2_status_reg0, lane;
4252 struct bnx2x *bp = params->bp;
4253
4254 lane = bnx2x_get_warpcore_lane(phy, params);
4255
4256 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD, MDIO_WC_REG_GP2_STATUS_GP_2_0,
4257 &gp2_status_reg0);
4258
4259 return (gp2_status_reg0 >> (8+lane)) & 0x1;
4260}
4261
4262static void bnx2x_warpcore_config_runtime(struct bnx2x_phy *phy,
4263 struct link_params *params,
4264 struct link_vars *vars)
4265{
4266 struct bnx2x *bp = params->bp;
4267 u32 serdes_net_if;
4268 u16 gp_status1 = 0, lnkup = 0, lnkup_kr = 0;
4269 u16 lane = bnx2x_get_warpcore_lane(phy, params);
4270
4271 vars->turn_to_run_wc_rt = vars->turn_to_run_wc_rt ? 0 : 1;
4272
4273 if (!vars->turn_to_run_wc_rt)
4274 return;
4275
4276 /* return if there is no link partner */
4277 if (!(bnx2x_warpcore_get_sigdet(phy, params))) {
4278 DP(NETIF_MSG_LINK, "bnx2x_warpcore_get_sigdet false\n");
4279 return;
4280 }
4281
4282 if (vars->rx_tx_asic_rst) {
4283 serdes_net_if = (REG_RD(bp, params->shmem_base +
4284 offsetof(struct shmem_region, dev_info.
4285 port_hw_config[params->port].default_cfg)) &
4286 PORT_HW_CFG_NET_SERDES_IF_MASK);
4287
4288 switch (serdes_net_if) {
4289 case PORT_HW_CFG_NET_SERDES_IF_KR:
4290 /* Do we get link yet? */
4291 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD, 0x81d1,
4292 &gp_status1);
4293 lnkup = (gp_status1 >> (8+lane)) & 0x1;/* 1G */
4294 /*10G KR*/
4295 lnkup_kr = (gp_status1 >> (12+lane)) & 0x1;
4296
4297 DP(NETIF_MSG_LINK,
4298 "gp_status1 0x%x\n", gp_status1);
4299
4300 if (lnkup_kr || lnkup) {
4301 vars->rx_tx_asic_rst = 0;
4302 DP(NETIF_MSG_LINK,
4303 "link up, rx_tx_asic_rst 0x%x\n",
4304 vars->rx_tx_asic_rst);
4305 } else {
4306 /*reset the lane to see if link comes up.*/
4307 bnx2x_warpcore_reset_lane(bp, phy, 1);
4308 bnx2x_warpcore_reset_lane(bp, phy, 0);
4309
4310 /* restart Autoneg */
4311 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
4312 MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x1200);
4313
4314 vars->rx_tx_asic_rst--;
4315 DP(NETIF_MSG_LINK, "0x%x retry left\n",
4316 vars->rx_tx_asic_rst);
4317 }
4318 break;
4319
4320 default:
4321 break;
4322 }
4323
4324 } /*params->rx_tx_asic_rst*/
4325
4326}
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004327
4328static void bnx2x_warpcore_config_init(struct bnx2x_phy *phy,
4329 struct link_params *params,
4330 struct link_vars *vars)
4331{
4332 struct bnx2x *bp = params->bp;
4333 u32 serdes_net_if;
4334 u8 fiber_mode;
4335 u16 lane = bnx2x_get_warpcore_lane(phy, params);
4336 serdes_net_if = (REG_RD(bp, params->shmem_base +
4337 offsetof(struct shmem_region, dev_info.
4338 port_hw_config[params->port].default_cfg)) &
4339 PORT_HW_CFG_NET_SERDES_IF_MASK);
4340 DP(NETIF_MSG_LINK, "Begin Warpcore init, link_speed %d, "
4341 "serdes_net_if = 0x%x\n",
4342 vars->line_speed, serdes_net_if);
4343 bnx2x_set_aer_mmd(params, phy);
4344
4345 vars->phy_flags |= PHY_XGXS_FLAG;
4346 if ((serdes_net_if == PORT_HW_CFG_NET_SERDES_IF_SGMII) ||
4347 (phy->req_line_speed &&
4348 ((phy->req_line_speed == SPEED_100) ||
4349 (phy->req_line_speed == SPEED_10)))) {
4350 vars->phy_flags |= PHY_SGMII_FLAG;
4351 DP(NETIF_MSG_LINK, "Setting SGMII mode\n");
4352 bnx2x_warpcore_clear_regs(phy, params, lane);
4353 bnx2x_warpcore_set_sgmii_speed(phy, params, 0);
4354 } else {
4355 switch (serdes_net_if) {
4356 case PORT_HW_CFG_NET_SERDES_IF_KR:
4357 /* Enable KR Auto Neg */
4358 if (params->loopback_mode == LOOPBACK_NONE)
4359 bnx2x_warpcore_enable_AN_KR(phy, params, vars);
4360 else {
4361 DP(NETIF_MSG_LINK, "Setting KR 10G-Force\n");
4362 bnx2x_warpcore_set_10G_KR(phy, params, vars);
4363 }
4364 break;
4365
4366 case PORT_HW_CFG_NET_SERDES_IF_XFI:
4367 bnx2x_warpcore_clear_regs(phy, params, lane);
4368 if (vars->line_speed == SPEED_10000) {
4369 DP(NETIF_MSG_LINK, "Setting 10G XFI\n");
4370 bnx2x_warpcore_set_10G_XFI(phy, params, 1);
4371 } else {
4372 if (SINGLE_MEDIA_DIRECT(params)) {
4373 DP(NETIF_MSG_LINK, "1G Fiber\n");
4374 fiber_mode = 1;
4375 } else {
4376 DP(NETIF_MSG_LINK, "10/100/1G SGMII\n");
4377 fiber_mode = 0;
4378 }
4379 bnx2x_warpcore_set_sgmii_speed(phy,
4380 params,
4381 fiber_mode);
4382 }
4383
4384 break;
4385
4386 case PORT_HW_CFG_NET_SERDES_IF_SFI:
4387
4388 bnx2x_warpcore_clear_regs(phy, params, lane);
4389 if (vars->line_speed == SPEED_10000) {
4390 DP(NETIF_MSG_LINK, "Setting 10G SFI\n");
4391 bnx2x_warpcore_set_10G_XFI(phy, params, 0);
4392 } else if (vars->line_speed == SPEED_1000) {
4393 DP(NETIF_MSG_LINK, "Setting 1G Fiber\n");
4394 bnx2x_warpcore_set_sgmii_speed(phy, params, 1);
4395 }
4396 /* Issue Module detection */
4397 if (bnx2x_is_sfp_module_plugged(phy, params))
4398 bnx2x_sfp_module_detection(phy, params);
4399 break;
4400
4401 case PORT_HW_CFG_NET_SERDES_IF_DXGXS:
4402 if (vars->line_speed != SPEED_20000) {
4403 DP(NETIF_MSG_LINK, "Speed not supported yet\n");
4404 return;
4405 }
4406 DP(NETIF_MSG_LINK, "Setting 20G DXGXS\n");
4407 bnx2x_warpcore_set_20G_DXGXS(bp, phy, lane);
4408 /* Issue Module detection */
4409
4410 bnx2x_sfp_module_detection(phy, params);
4411 break;
4412
4413 case PORT_HW_CFG_NET_SERDES_IF_KR2:
4414 if (vars->line_speed != SPEED_20000) {
4415 DP(NETIF_MSG_LINK, "Speed not supported yet\n");
4416 return;
4417 }
4418 DP(NETIF_MSG_LINK, "Setting 20G KR2\n");
4419 bnx2x_warpcore_set_20G_KR2(bp, phy);
4420 break;
4421
4422 default:
Joe Perches94f05b02011-08-14 12:16:20 +00004423 DP(NETIF_MSG_LINK,
4424 "Unsupported Serdes Net Interface 0x%x\n",
4425 serdes_net_if);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004426 return;
4427 }
4428 }
4429
4430 /* Take lane out of reset after configuration is finished */
4431 bnx2x_warpcore_reset_lane(bp, phy, 0);
4432 DP(NETIF_MSG_LINK, "Exit config init\n");
4433}
4434
4435static void bnx2x_sfp_e3_set_transmitter(struct link_params *params,
4436 struct bnx2x_phy *phy,
4437 u8 tx_en)
4438{
4439 struct bnx2x *bp = params->bp;
4440 u32 cfg_pin;
4441 u8 port = params->port;
4442
4443 cfg_pin = REG_RD(bp, params->shmem_base +
4444 offsetof(struct shmem_region,
4445 dev_info.port_hw_config[port].e3_sfp_ctrl)) &
4446 PORT_HW_CFG_TX_LASER_MASK;
4447 /* Set the !tx_en since this pin is DISABLE_TX_LASER */
4448 DP(NETIF_MSG_LINK, "Setting WC TX to %d\n", tx_en);
4449 /* For 20G, the expected pin to be used is 3 pins after the current */
4450
4451 bnx2x_set_cfg_pin(bp, cfg_pin, tx_en ^ 1);
4452 if (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_20G)
4453 bnx2x_set_cfg_pin(bp, cfg_pin + 3, tx_en ^ 1);
4454}
4455
4456static void bnx2x_warpcore_link_reset(struct bnx2x_phy *phy,
4457 struct link_params *params)
4458{
4459 struct bnx2x *bp = params->bp;
4460 u16 val16;
4461 bnx2x_sfp_e3_set_transmitter(params, phy, 0);
4462 bnx2x_set_mdio_clk(bp, params->chip_id, params->port);
4463 bnx2x_set_aer_mmd(params, phy);
4464 /* Global register */
4465 bnx2x_warpcore_reset_lane(bp, phy, 1);
4466
4467 /* Clear loopback settings (if any) */
4468 /* 10G & 20G */
4469 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4470 MDIO_WC_REG_COMBO_IEEE0_MIICTRL, &val16);
4471 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4472 MDIO_WC_REG_COMBO_IEEE0_MIICTRL, val16 &
4473 0xBFFF);
4474
4475 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4476 MDIO_WC_REG_IEEE0BLK_MIICNTL, &val16);
4477 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4478 MDIO_WC_REG_IEEE0BLK_MIICNTL, val16 & 0xfffe);
4479
4480 /* Update those 1-copy registers */
4481 CL22_WR_OVER_CL45(bp, phy, MDIO_REG_BANK_AER_BLOCK,
4482 MDIO_AER_BLOCK_AER_REG, 0);
4483 /* Enable 1G MDIO (1-copy) */
4484 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4485 MDIO_WC_REG_XGXSBLK0_XGXSCONTROL,
4486 &val16);
4487 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4488 MDIO_WC_REG_XGXSBLK0_XGXSCONTROL,
4489 val16 & ~0x10);
4490
4491 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4492 MDIO_WC_REG_XGXSBLK1_LANECTRL2, &val16);
4493 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4494 MDIO_WC_REG_XGXSBLK1_LANECTRL2,
4495 val16 & 0xff00);
4496
4497}
4498
4499static void bnx2x_set_warpcore_loopback(struct bnx2x_phy *phy,
4500 struct link_params *params)
4501{
4502 struct bnx2x *bp = params->bp;
4503 u16 val16;
4504 u32 lane;
4505 DP(NETIF_MSG_LINK, "Setting Warpcore loopback type %x, speed %d\n",
4506 params->loopback_mode, phy->req_line_speed);
4507
4508 if (phy->req_line_speed < SPEED_10000) {
4509 /* 10/100/1000 */
4510
4511 /* Update those 1-copy registers */
4512 CL22_WR_OVER_CL45(bp, phy, MDIO_REG_BANK_AER_BLOCK,
4513 MDIO_AER_BLOCK_AER_REG, 0);
4514 /* Enable 1G MDIO (1-copy) */
4515 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4516 MDIO_WC_REG_XGXSBLK0_XGXSCONTROL,
4517 &val16);
4518 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4519 MDIO_WC_REG_XGXSBLK0_XGXSCONTROL,
4520 val16 | 0x10);
4521 /* Set 1G loopback based on lane (1-copy) */
4522 lane = bnx2x_get_warpcore_lane(phy, params);
4523 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4524 MDIO_WC_REG_XGXSBLK1_LANECTRL2, &val16);
4525 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4526 MDIO_WC_REG_XGXSBLK1_LANECTRL2,
4527 val16 | (1<<lane));
4528
4529 /* Switch back to 4-copy registers */
4530 bnx2x_set_aer_mmd(params, phy);
4531 /* Global loopback, not recommended. */
4532 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4533 MDIO_WC_REG_COMBO_IEEE0_MIICTRL, &val16);
4534 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4535 MDIO_WC_REG_COMBO_IEEE0_MIICTRL, val16 |
4536 0x4000);
4537 } else {
4538 /* 10G & 20G */
4539 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4540 MDIO_WC_REG_COMBO_IEEE0_MIICTRL, &val16);
4541 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4542 MDIO_WC_REG_COMBO_IEEE0_MIICTRL, val16 |
4543 0x4000);
4544
4545 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4546 MDIO_WC_REG_IEEE0BLK_MIICNTL, &val16);
4547 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4548 MDIO_WC_REG_IEEE0BLK_MIICNTL, val16 | 0x1);
4549 }
4550}
4551
4552
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004553void bnx2x_link_status_update(struct link_params *params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004554 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004555{
4556 struct bnx2x *bp = params->bp;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00004557 u8 link_10g_plus;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004558 u8 port = params->port;
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00004559 u32 sync_offset, media_types;
Yaniv Rosnerfd36a2e2011-05-31 21:29:05 +00004560 /* Update PHY configuration */
4561 set_phy_vars(params, vars);
4562
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004563 vars->link_status = REG_RD(bp, params->shmem_base +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004564 offsetof(struct shmem_region,
4565 port_mb[port].link_status));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004566
4567 vars->link_up = (vars->link_status & LINK_STATUS_LINK_UP);
Yaniv Rosnerfd36a2e2011-05-31 21:29:05 +00004568 vars->phy_flags = PHY_XGXS_FLAG;
Yaniv Rosnerde6f3372011-08-02 22:59:25 +00004569 if (vars->link_status & LINK_STATUS_PHYSICAL_LINK_FLAG)
4570 vars->phy_flags |= PHY_PHYSICAL_LINK_FLAG;
4571
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004572 if (vars->link_up) {
4573 DP(NETIF_MSG_LINK, "phy link up\n");
4574
4575 vars->phy_link_up = 1;
4576 vars->duplex = DUPLEX_FULL;
4577 switch (vars->link_status &
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004578 LINK_STATUS_SPEED_AND_DUPLEX_MASK) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004579 case LINK_10THD:
4580 vars->duplex = DUPLEX_HALF;
4581 /* fall thru */
4582 case LINK_10TFD:
4583 vars->line_speed = SPEED_10;
4584 break;
4585
4586 case LINK_100TXHD:
4587 vars->duplex = DUPLEX_HALF;
4588 /* fall thru */
4589 case LINK_100T4:
4590 case LINK_100TXFD:
4591 vars->line_speed = SPEED_100;
4592 break;
4593
4594 case LINK_1000THD:
4595 vars->duplex = DUPLEX_HALF;
4596 /* fall thru */
4597 case LINK_1000TFD:
4598 vars->line_speed = SPEED_1000;
4599 break;
4600
4601 case LINK_2500THD:
4602 vars->duplex = DUPLEX_HALF;
4603 /* fall thru */
4604 case LINK_2500TFD:
4605 vars->line_speed = SPEED_2500;
4606 break;
4607
4608 case LINK_10GTFD:
4609 vars->line_speed = SPEED_10000;
4610 break;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004611 case LINK_20GTFD:
4612 vars->line_speed = SPEED_20000;
4613 break;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004614 default:
4615 break;
4616 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004617 vars->flow_ctrl = 0;
4618 if (vars->link_status & LINK_STATUS_TX_FLOW_CONTROL_ENABLED)
4619 vars->flow_ctrl |= BNX2X_FLOW_CTRL_TX;
4620
4621 if (vars->link_status & LINK_STATUS_RX_FLOW_CONTROL_ENABLED)
4622 vars->flow_ctrl |= BNX2X_FLOW_CTRL_RX;
4623
4624 if (!vars->flow_ctrl)
4625 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
4626
4627 if (vars->line_speed &&
4628 ((vars->line_speed == SPEED_10) ||
4629 (vars->line_speed == SPEED_100))) {
4630 vars->phy_flags |= PHY_SGMII_FLAG;
4631 } else {
4632 vars->phy_flags &= ~PHY_SGMII_FLAG;
4633 }
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004634 if (vars->line_speed &&
4635 USES_WARPCORE(bp) &&
4636 (vars->line_speed == SPEED_1000))
4637 vars->phy_flags |= PHY_SGMII_FLAG;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004638 /* anything 10 and over uses the bmac */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00004639 link_10g_plus = (vars->line_speed >= SPEED_10000);
4640
4641 if (link_10g_plus) {
4642 if (USES_WARPCORE(bp))
4643 vars->mac_type = MAC_TYPE_XMAC;
4644 else
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004645 vars->mac_type = MAC_TYPE_BMAC;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00004646 } else {
4647 if (USES_WARPCORE(bp))
4648 vars->mac_type = MAC_TYPE_UMAC;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004649 else
4650 vars->mac_type = MAC_TYPE_EMAC;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00004651 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004652 } else { /* link down */
4653 DP(NETIF_MSG_LINK, "phy link down\n");
4654
4655 vars->phy_link_up = 0;
4656
4657 vars->line_speed = 0;
4658 vars->duplex = DUPLEX_FULL;
4659 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
4660
4661 /* indicate no mac active */
4662 vars->mac_type = MAC_TYPE_NONE;
Yaniv Rosnerde6f3372011-08-02 22:59:25 +00004663 if (vars->link_status & LINK_STATUS_PHYSICAL_LINK_FLAG)
4664 vars->phy_flags |= PHY_HALF_OPEN_CONN_FLAG;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004665 }
4666
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00004667 /* Sync media type */
4668 sync_offset = params->shmem_base +
4669 offsetof(struct shmem_region,
4670 dev_info.port_hw_config[port].media_type);
4671 media_types = REG_RD(bp, sync_offset);
4672
4673 params->phy[INT_PHY].media_type =
4674 (media_types & PORT_HW_CFG_MEDIA_TYPE_PHY0_MASK) >>
4675 PORT_HW_CFG_MEDIA_TYPE_PHY0_SHIFT;
4676 params->phy[EXT_PHY1].media_type =
4677 (media_types & PORT_HW_CFG_MEDIA_TYPE_PHY1_MASK) >>
4678 PORT_HW_CFG_MEDIA_TYPE_PHY1_SHIFT;
4679 params->phy[EXT_PHY2].media_type =
4680 (media_types & PORT_HW_CFG_MEDIA_TYPE_PHY2_MASK) >>
4681 PORT_HW_CFG_MEDIA_TYPE_PHY2_SHIFT;
4682 DP(NETIF_MSG_LINK, "media_types = 0x%x\n", media_types);
4683
Yaniv Rosner020c7e32011-05-31 21:28:43 +00004684 /* Sync AEU offset */
4685 sync_offset = params->shmem_base +
4686 offsetof(struct shmem_region,
4687 dev_info.port_hw_config[port].aeu_int_mask);
4688
4689 vars->aeu_int_mask = REG_RD(bp, sync_offset);
4690
Yaniv Rosnerb8d6d082011-07-05 01:06:27 +00004691 /* Sync PFC status */
4692 if (vars->link_status & LINK_STATUS_PFC_ENABLED)
4693 params->feature_config_flags |=
4694 FEATURE_CONFIG_PFC_ENABLED;
4695 else
4696 params->feature_config_flags &=
4697 ~FEATURE_CONFIG_PFC_ENABLED;
4698
Yaniv Rosner020c7e32011-05-31 21:28:43 +00004699 DP(NETIF_MSG_LINK, "link_status 0x%x phy_link_up %x int_mask 0x%x\n",
4700 vars->link_status, vars->phy_link_up, vars->aeu_int_mask);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004701 DP(NETIF_MSG_LINK, "line_speed %x duplex %x flow_ctrl 0x%x\n",
4702 vars->line_speed, vars->duplex, vars->flow_ctrl);
4703}
4704
4705
Yaniv Rosnere10bc842010-09-07 11:40:50 +00004706static void bnx2x_set_master_ln(struct link_params *params,
4707 struct bnx2x_phy *phy)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004708{
4709 struct bnx2x *bp = params->bp;
4710 u16 new_master_ln, ser_lane;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004711 ser_lane = ((params->lane_config &
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004712 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_MASK) >>
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004713 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_SHIFT);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004714
4715 /* set the master_ln for AN */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004716 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004717 MDIO_REG_BANK_XGXS_BLOCK2,
4718 MDIO_XGXS_BLOCK2_TEST_MODE_LANE,
4719 &new_master_ln);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004720
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004721 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004722 MDIO_REG_BANK_XGXS_BLOCK2 ,
4723 MDIO_XGXS_BLOCK2_TEST_MODE_LANE,
4724 (new_master_ln | ser_lane));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004725}
4726
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00004727static int bnx2x_reset_unicore(struct link_params *params,
4728 struct bnx2x_phy *phy,
4729 u8 set_serdes)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004730{
4731 struct bnx2x *bp = params->bp;
4732 u16 mii_control;
4733 u16 i;
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004734 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004735 MDIO_REG_BANK_COMBO_IEEE0,
4736 MDIO_COMBO_IEEE0_MII_CONTROL, &mii_control);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004737
4738 /* reset the unicore */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004739 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004740 MDIO_REG_BANK_COMBO_IEEE0,
4741 MDIO_COMBO_IEEE0_MII_CONTROL,
4742 (mii_control |
4743 MDIO_COMBO_IEEO_MII_CONTROL_RESET));
Yaniv Rosnere10bc842010-09-07 11:40:50 +00004744 if (set_serdes)
4745 bnx2x_set_serdes_access(bp, params->port);
Eilon Greensteinc1b73992009-02-12 08:37:07 +00004746
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004747 /* wait for the reset to self clear */
4748 for (i = 0; i < MDIO_ACCESS_TIMEOUT; i++) {
4749 udelay(5);
4750
4751 /* the reset erased the previous bank value */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004752 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004753 MDIO_REG_BANK_COMBO_IEEE0,
4754 MDIO_COMBO_IEEE0_MII_CONTROL,
4755 &mii_control);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004756
4757 if (!(mii_control & MDIO_COMBO_IEEO_MII_CONTROL_RESET)) {
4758 udelay(5);
4759 return 0;
4760 }
4761 }
4762
Yaniv Rosner6d870c32011-01-31 04:22:20 +00004763 netdev_err(bp->dev, "Warning: PHY was not initialized,"
4764 " Port %d\n",
4765 params->port);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004766 DP(NETIF_MSG_LINK, "BUG! XGXS is still in reset!\n");
4767 return -EINVAL;
4768
4769}
4770
Yaniv Rosnere10bc842010-09-07 11:40:50 +00004771static void bnx2x_set_swap_lanes(struct link_params *params,
4772 struct bnx2x_phy *phy)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004773{
4774 struct bnx2x *bp = params->bp;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00004775 /*
4776 * Each two bits represents a lane number:
4777 * No swap is 0123 => 0x1b no need to enable the swap
4778 */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004779 u16 ser_lane, rx_lane_swap, tx_lane_swap;
4780
4781 ser_lane = ((params->lane_config &
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004782 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_MASK) >>
4783 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_SHIFT);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004784 rx_lane_swap = ((params->lane_config &
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004785 PORT_HW_CFG_LANE_SWAP_CFG_RX_MASK) >>
4786 PORT_HW_CFG_LANE_SWAP_CFG_RX_SHIFT);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004787 tx_lane_swap = ((params->lane_config &
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004788 PORT_HW_CFG_LANE_SWAP_CFG_TX_MASK) >>
4789 PORT_HW_CFG_LANE_SWAP_CFG_TX_SHIFT);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004790
4791 if (rx_lane_swap != 0x1b) {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004792 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004793 MDIO_REG_BANK_XGXS_BLOCK2,
4794 MDIO_XGXS_BLOCK2_RX_LN_SWAP,
4795 (rx_lane_swap |
4796 MDIO_XGXS_BLOCK2_RX_LN_SWAP_ENABLE |
4797 MDIO_XGXS_BLOCK2_RX_LN_SWAP_FORCE_ENABLE));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004798 } else {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004799 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004800 MDIO_REG_BANK_XGXS_BLOCK2,
4801 MDIO_XGXS_BLOCK2_RX_LN_SWAP, 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004802 }
4803
4804 if (tx_lane_swap != 0x1b) {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004805 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004806 MDIO_REG_BANK_XGXS_BLOCK2,
4807 MDIO_XGXS_BLOCK2_TX_LN_SWAP,
4808 (tx_lane_swap |
4809 MDIO_XGXS_BLOCK2_TX_LN_SWAP_ENABLE));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004810 } else {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004811 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004812 MDIO_REG_BANK_XGXS_BLOCK2,
4813 MDIO_XGXS_BLOCK2_TX_LN_SWAP, 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004814 }
4815}
4816
Yaniv Rosnere10bc842010-09-07 11:40:50 +00004817static void bnx2x_set_parallel_detection(struct bnx2x_phy *phy,
4818 struct link_params *params)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004819{
4820 struct bnx2x *bp = params->bp;
4821 u16 control2;
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004822 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004823 MDIO_REG_BANK_SERDES_DIGITAL,
4824 MDIO_SERDES_DIGITAL_A_1000X_CONTROL2,
4825 &control2);
Yaniv Rosner7aa07112010-09-07 11:41:01 +00004826 if (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)
Yaniv Rosner18afb0a2009-11-05 19:18:04 +02004827 control2 |= MDIO_SERDES_DIGITAL_A_1000X_CONTROL2_PRL_DT_EN;
4828 else
4829 control2 &= ~MDIO_SERDES_DIGITAL_A_1000X_CONTROL2_PRL_DT_EN;
Yaniv Rosner7aa07112010-09-07 11:41:01 +00004830 DP(NETIF_MSG_LINK, "phy->speed_cap_mask = 0x%x, control2 = 0x%x\n",
4831 phy->speed_cap_mask, control2);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004832 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004833 MDIO_REG_BANK_SERDES_DIGITAL,
4834 MDIO_SERDES_DIGITAL_A_1000X_CONTROL2,
4835 control2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004836
Yaniv Rosnere10bc842010-09-07 11:40:50 +00004837 if ((phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT) &&
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00004838 (phy->speed_cap_mask &
Yaniv Rosner18afb0a2009-11-05 19:18:04 +02004839 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004840 DP(NETIF_MSG_LINK, "XGXS\n");
4841
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004842 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004843 MDIO_REG_BANK_10G_PARALLEL_DETECT,
4844 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_LINK,
4845 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_LINK_CNT);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004846
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004847 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004848 MDIO_REG_BANK_10G_PARALLEL_DETECT,
4849 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_CONTROL,
4850 &control2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004851
4852
4853 control2 |=
4854 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_CONTROL_PARDET10G_EN;
4855
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004856 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004857 MDIO_REG_BANK_10G_PARALLEL_DETECT,
4858 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_CONTROL,
4859 control2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004860
4861 /* Disable parallel detection of HiG */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004862 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004863 MDIO_REG_BANK_XGXS_BLOCK2,
4864 MDIO_XGXS_BLOCK2_UNICORE_MODE_10G,
4865 MDIO_XGXS_BLOCK2_UNICORE_MODE_10G_CX4_XGXS |
4866 MDIO_XGXS_BLOCK2_UNICORE_MODE_10G_HIGIG_XGXS);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004867 }
4868}
4869
Yaniv Rosnere10bc842010-09-07 11:40:50 +00004870static void bnx2x_set_autoneg(struct bnx2x_phy *phy,
4871 struct link_params *params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004872 struct link_vars *vars,
4873 u8 enable_cl73)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004874{
4875 struct bnx2x *bp = params->bp;
4876 u16 reg_val;
4877
4878 /* CL37 Autoneg */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004879 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004880 MDIO_REG_BANK_COMBO_IEEE0,
4881 MDIO_COMBO_IEEE0_MII_CONTROL, &reg_val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004882
4883 /* CL37 Autoneg Enabled */
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07004884 if (vars->line_speed == SPEED_AUTO_NEG)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004885 reg_val |= MDIO_COMBO_IEEO_MII_CONTROL_AN_EN;
4886 else /* CL37 Autoneg Disabled */
4887 reg_val &= ~(MDIO_COMBO_IEEO_MII_CONTROL_AN_EN |
4888 MDIO_COMBO_IEEO_MII_CONTROL_RESTART_AN);
4889
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004890 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004891 MDIO_REG_BANK_COMBO_IEEE0,
4892 MDIO_COMBO_IEEE0_MII_CONTROL, reg_val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004893
4894 /* Enable/Disable Autodetection */
4895
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004896 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004897 MDIO_REG_BANK_SERDES_DIGITAL,
4898 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1, &reg_val);
Eilon Greenstein239d6862009-08-12 08:23:04 +00004899 reg_val &= ~(MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_SIGNAL_DETECT_EN |
4900 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_INVERT_SIGNAL_DETECT);
4901 reg_val |= MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_FIBER_MODE;
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07004902 if (vars->line_speed == SPEED_AUTO_NEG)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004903 reg_val |= MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_AUTODET;
4904 else
4905 reg_val &= ~MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_AUTODET;
4906
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004907 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004908 MDIO_REG_BANK_SERDES_DIGITAL,
4909 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1, reg_val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004910
4911 /* Enable TetonII and BAM autoneg */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004912 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004913 MDIO_REG_BANK_BAM_NEXT_PAGE,
4914 MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL,
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004915 &reg_val);
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07004916 if (vars->line_speed == SPEED_AUTO_NEG) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004917 /* Enable BAM aneg Mode and TetonII aneg Mode */
4918 reg_val |= (MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL_BAM_MODE |
4919 MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL_TETON_AN);
4920 } else {
4921 /* TetonII and BAM Autoneg Disabled */
4922 reg_val &= ~(MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL_BAM_MODE |
4923 MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL_TETON_AN);
4924 }
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004925 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004926 MDIO_REG_BANK_BAM_NEXT_PAGE,
4927 MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL,
4928 reg_val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004929
Eilon Greenstein239d6862009-08-12 08:23:04 +00004930 if (enable_cl73) {
4931 /* Enable Cl73 FSM status bits */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004932 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004933 MDIO_REG_BANK_CL73_USERB0,
4934 MDIO_CL73_USERB0_CL73_UCTRL,
4935 0xe);
Eilon Greenstein239d6862009-08-12 08:23:04 +00004936
4937 /* Enable BAM Station Manager*/
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004938 CL22_WR_OVER_CL45(bp, phy,
Eilon Greenstein239d6862009-08-12 08:23:04 +00004939 MDIO_REG_BANK_CL73_USERB0,
4940 MDIO_CL73_USERB0_CL73_BAM_CTRL1,
4941 MDIO_CL73_USERB0_CL73_BAM_CTRL1_BAM_EN |
4942 MDIO_CL73_USERB0_CL73_BAM_CTRL1_BAM_STATION_MNGR_EN |
4943 MDIO_CL73_USERB0_CL73_BAM_CTRL1_BAM_NP_AFTER_BP_EN);
4944
Yaniv Rosner7846e472009-11-05 19:18:07 +02004945 /* Advertise CL73 link speeds */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004946 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004947 MDIO_REG_BANK_CL73_IEEEB1,
4948 MDIO_CL73_IEEEB1_AN_ADV2,
4949 &reg_val);
Yaniv Rosner7aa07112010-09-07 11:41:01 +00004950 if (phy->speed_cap_mask &
Yaniv Rosner7846e472009-11-05 19:18:07 +02004951 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
4952 reg_val |= MDIO_CL73_IEEEB1_AN_ADV2_ADVR_10G_KX4;
Yaniv Rosner7aa07112010-09-07 11:41:01 +00004953 if (phy->speed_cap_mask &
Yaniv Rosner7846e472009-11-05 19:18:07 +02004954 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)
4955 reg_val |= MDIO_CL73_IEEEB1_AN_ADV2_ADVR_1000M_KX;
Eilon Greenstein239d6862009-08-12 08:23:04 +00004956
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004957 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004958 MDIO_REG_BANK_CL73_IEEEB1,
4959 MDIO_CL73_IEEEB1_AN_ADV2,
4960 reg_val);
Eilon Greenstein239d6862009-08-12 08:23:04 +00004961
Eilon Greenstein239d6862009-08-12 08:23:04 +00004962 /* CL73 Autoneg Enabled */
4963 reg_val = MDIO_CL73_IEEEB0_CL73_AN_CONTROL_AN_EN;
4964
4965 } else /* CL73 Autoneg Disabled */
4966 reg_val = 0;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004967
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004968 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004969 MDIO_REG_BANK_CL73_IEEEB0,
4970 MDIO_CL73_IEEEB0_CL73_AN_CONTROL, reg_val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004971}
4972
4973/* program SerDes, forced speed */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00004974static void bnx2x_program_serdes(struct bnx2x_phy *phy,
4975 struct link_params *params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004976 struct link_vars *vars)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004977{
4978 struct bnx2x *bp = params->bp;
4979 u16 reg_val;
4980
Eilon Greenstein57937202009-08-12 08:23:53 +00004981 /* program duplex, disable autoneg and sgmii*/
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004982 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004983 MDIO_REG_BANK_COMBO_IEEE0,
4984 MDIO_COMBO_IEEE0_MII_CONTROL, &reg_val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004985 reg_val &= ~(MDIO_COMBO_IEEO_MII_CONTROL_FULL_DUPLEX |
Eilon Greenstein57937202009-08-12 08:23:53 +00004986 MDIO_COMBO_IEEO_MII_CONTROL_AN_EN |
4987 MDIO_COMBO_IEEO_MII_CONTROL_MAN_SGMII_SP_MASK);
Yaniv Rosner7aa07112010-09-07 11:41:01 +00004988 if (phy->req_duplex == DUPLEX_FULL)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004989 reg_val |= MDIO_COMBO_IEEO_MII_CONTROL_FULL_DUPLEX;
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004990 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004991 MDIO_REG_BANK_COMBO_IEEE0,
4992 MDIO_COMBO_IEEE0_MII_CONTROL, reg_val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004993
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00004994 /*
4995 * program speed
4996 * - needed only if the speed is greater than 1G (2.5G or 10G)
4997 */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004998 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004999 MDIO_REG_BANK_SERDES_DIGITAL,
5000 MDIO_SERDES_DIGITAL_MISC1, &reg_val);
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07005001 /* clearing the speed value before setting the right speed */
5002 DP(NETIF_MSG_LINK, "MDIO_REG_BANK_SERDES_DIGITAL = 0x%x\n", reg_val);
5003
5004 reg_val &= ~(MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_MASK |
5005 MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_SEL);
5006
5007 if (!((vars->line_speed == SPEED_1000) ||
5008 (vars->line_speed == SPEED_100) ||
5009 (vars->line_speed == SPEED_10))) {
5010
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005011 reg_val |= (MDIO_SERDES_DIGITAL_MISC1_REFCLK_SEL_156_25M |
5012 MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_SEL);
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07005013 if (vars->line_speed == SPEED_10000)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005014 reg_val |=
5015 MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_10G_CX4;
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07005016 }
5017
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005018 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005019 MDIO_REG_BANK_SERDES_DIGITAL,
5020 MDIO_SERDES_DIGITAL_MISC1, reg_val);
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07005021
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005022}
5023
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00005024static void bnx2x_set_brcm_cl37_advertisement(struct bnx2x_phy *phy,
5025 struct link_params *params)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005026{
5027 struct bnx2x *bp = params->bp;
5028 u16 val = 0;
5029
5030 /* configure the 48 bits for BAM AN */
5031
5032 /* set extended capabilities */
Yaniv Rosner7aa07112010-09-07 11:41:01 +00005033 if (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005034 val |= MDIO_OVER_1G_UP1_2_5G;
Yaniv Rosner7aa07112010-09-07 11:41:01 +00005035 if (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005036 val |= MDIO_OVER_1G_UP1_10G;
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005037 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005038 MDIO_REG_BANK_OVER_1G,
5039 MDIO_OVER_1G_UP1, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005040
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005041 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005042 MDIO_REG_BANK_OVER_1G,
5043 MDIO_OVER_1G_UP3, 0x400);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005044}
5045
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00005046static void bnx2x_set_ieee_aneg_advertisement(struct bnx2x_phy *phy,
5047 struct link_params *params,
5048 u16 ieee_fc)
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07005049{
5050 struct bnx2x *bp = params->bp;
Yaniv Rosner7846e472009-11-05 19:18:07 +02005051 u16 val;
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07005052 /* for AN, we are always publishing full duplex */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005053
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005054 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005055 MDIO_REG_BANK_COMBO_IEEE0,
5056 MDIO_COMBO_IEEE0_AUTO_NEG_ADV, ieee_fc);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005057 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005058 MDIO_REG_BANK_CL73_IEEEB1,
5059 MDIO_CL73_IEEEB1_AN_ADV1, &val);
Yaniv Rosner7846e472009-11-05 19:18:07 +02005060 val &= ~MDIO_CL73_IEEEB1_AN_ADV1_PAUSE_BOTH;
5061 val |= ((ieee_fc<<3) & MDIO_CL73_IEEEB1_AN_ADV1_PAUSE_MASK);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005062 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005063 MDIO_REG_BANK_CL73_IEEEB1,
5064 MDIO_CL73_IEEEB1_AN_ADV1, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005065}
5066
Yaniv Rosnere10bc842010-09-07 11:40:50 +00005067static void bnx2x_restart_autoneg(struct bnx2x_phy *phy,
5068 struct link_params *params,
5069 u8 enable_cl73)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005070{
5071 struct bnx2x *bp = params->bp;
Eilon Greenstein3a36f2e2009-02-12 08:37:09 +00005072 u16 mii_control;
Eilon Greenstein239d6862009-08-12 08:23:04 +00005073
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005074 DP(NETIF_MSG_LINK, "bnx2x_restart_autoneg\n");
Eilon Greenstein3a36f2e2009-02-12 08:37:09 +00005075 /* Enable and restart BAM/CL37 aneg */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005076
Eilon Greenstein239d6862009-08-12 08:23:04 +00005077 if (enable_cl73) {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005078 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005079 MDIO_REG_BANK_CL73_IEEEB0,
5080 MDIO_CL73_IEEEB0_CL73_AN_CONTROL,
5081 &mii_control);
Eilon Greenstein239d6862009-08-12 08:23:04 +00005082
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005083 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005084 MDIO_REG_BANK_CL73_IEEEB0,
5085 MDIO_CL73_IEEEB0_CL73_AN_CONTROL,
5086 (mii_control |
5087 MDIO_CL73_IEEEB0_CL73_AN_CONTROL_AN_EN |
5088 MDIO_CL73_IEEEB0_CL73_AN_CONTROL_RESTART_AN));
Eilon Greenstein239d6862009-08-12 08:23:04 +00005089 } else {
5090
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005091 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005092 MDIO_REG_BANK_COMBO_IEEE0,
5093 MDIO_COMBO_IEEE0_MII_CONTROL,
5094 &mii_control);
Eilon Greenstein239d6862009-08-12 08:23:04 +00005095 DP(NETIF_MSG_LINK,
5096 "bnx2x_restart_autoneg mii_control before = 0x%x\n",
5097 mii_control);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005098 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005099 MDIO_REG_BANK_COMBO_IEEE0,
5100 MDIO_COMBO_IEEE0_MII_CONTROL,
5101 (mii_control |
5102 MDIO_COMBO_IEEO_MII_CONTROL_AN_EN |
5103 MDIO_COMBO_IEEO_MII_CONTROL_RESTART_AN));
Eilon Greenstein239d6862009-08-12 08:23:04 +00005104 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005105}
5106
Yaniv Rosnere10bc842010-09-07 11:40:50 +00005107static void bnx2x_initialize_sgmii_process(struct bnx2x_phy *phy,
5108 struct link_params *params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005109 struct link_vars *vars)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005110{
5111 struct bnx2x *bp = params->bp;
5112 u16 control1;
5113
5114 /* in SGMII mode, the unicore is always slave */
5115
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005116 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005117 MDIO_REG_BANK_SERDES_DIGITAL,
5118 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1,
5119 &control1);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005120 control1 |= MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_INVERT_SIGNAL_DETECT;
5121 /* set sgmii mode (and not fiber) */
5122 control1 &= ~(MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_FIBER_MODE |
5123 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_AUTODET |
5124 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_MSTR_MODE);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005125 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005126 MDIO_REG_BANK_SERDES_DIGITAL,
5127 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1,
5128 control1);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005129
5130 /* if forced speed */
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07005131 if (!(vars->line_speed == SPEED_AUTO_NEG)) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005132 /* set speed, disable autoneg */
5133 u16 mii_control;
5134
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005135 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005136 MDIO_REG_BANK_COMBO_IEEE0,
5137 MDIO_COMBO_IEEE0_MII_CONTROL,
5138 &mii_control);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005139 mii_control &= ~(MDIO_COMBO_IEEO_MII_CONTROL_AN_EN |
5140 MDIO_COMBO_IEEO_MII_CONTROL_MAN_SGMII_SP_MASK|
5141 MDIO_COMBO_IEEO_MII_CONTROL_FULL_DUPLEX);
5142
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07005143 switch (vars->line_speed) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005144 case SPEED_100:
5145 mii_control |=
5146 MDIO_COMBO_IEEO_MII_CONTROL_MAN_SGMII_SP_100;
5147 break;
5148 case SPEED_1000:
5149 mii_control |=
5150 MDIO_COMBO_IEEO_MII_CONTROL_MAN_SGMII_SP_1000;
5151 break;
5152 case SPEED_10:
5153 /* there is nothing to set for 10M */
5154 break;
5155 default:
5156 /* invalid speed for SGMII */
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07005157 DP(NETIF_MSG_LINK, "Invalid line_speed 0x%x\n",
5158 vars->line_speed);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005159 break;
5160 }
5161
5162 /* setting the full duplex */
Yaniv Rosner7aa07112010-09-07 11:41:01 +00005163 if (phy->req_duplex == DUPLEX_FULL)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005164 mii_control |=
5165 MDIO_COMBO_IEEO_MII_CONTROL_FULL_DUPLEX;
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005166 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005167 MDIO_REG_BANK_COMBO_IEEE0,
5168 MDIO_COMBO_IEEE0_MII_CONTROL,
5169 mii_control);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005170
5171 } else { /* AN mode */
5172 /* enable and restart AN */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00005173 bnx2x_restart_autoneg(phy, params, 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005174 }
5175}
5176
5177
5178/*
5179 * link management
5180 */
5181
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00005182static int bnx2x_direct_parallel_detect_used(struct bnx2x_phy *phy,
5183 struct link_params *params)
Yaniv Rosner15ddd2d2009-11-05 19:18:12 +02005184{
5185 struct bnx2x *bp = params->bp;
5186 u16 pd_10g, status2_1000x;
Yaniv Rosner7aa07112010-09-07 11:41:01 +00005187 if (phy->req_line_speed != SPEED_AUTO_NEG)
5188 return 0;
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005189 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005190 MDIO_REG_BANK_SERDES_DIGITAL,
5191 MDIO_SERDES_DIGITAL_A_1000X_STATUS2,
5192 &status2_1000x);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005193 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005194 MDIO_REG_BANK_SERDES_DIGITAL,
5195 MDIO_SERDES_DIGITAL_A_1000X_STATUS2,
5196 &status2_1000x);
Yaniv Rosner15ddd2d2009-11-05 19:18:12 +02005197 if (status2_1000x & MDIO_SERDES_DIGITAL_A_1000X_STATUS2_AN_DISABLED) {
5198 DP(NETIF_MSG_LINK, "1G parallel detect link on port %d\n",
5199 params->port);
5200 return 1;
5201 }
5202
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005203 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005204 MDIO_REG_BANK_10G_PARALLEL_DETECT,
5205 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_STATUS,
5206 &pd_10g);
Yaniv Rosner15ddd2d2009-11-05 19:18:12 +02005207
5208 if (pd_10g & MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_STATUS_PD_LINK) {
5209 DP(NETIF_MSG_LINK, "10G parallel detect link on port %d\n",
5210 params->port);
5211 return 1;
5212 }
5213 return 0;
5214}
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005215
Yaniv Rosnere10bc842010-09-07 11:40:50 +00005216static void bnx2x_flow_ctrl_resolve(struct bnx2x_phy *phy,
5217 struct link_params *params,
5218 struct link_vars *vars,
5219 u32 gp_status)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005220{
5221 struct bnx2x *bp = params->bp;
Eilon Greenstein3196a882008-08-13 15:58:49 -07005222 u16 ld_pause; /* local driver */
5223 u16 lp_pause; /* link partner */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005224 u16 pause_result;
5225
David S. Millerc0700f92008-12-16 23:53:20 -08005226 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005227
5228 /* resolve from gp_status in case of AN complete and not sgmii */
Yaniv Rosner7aa07112010-09-07 11:41:01 +00005229 if (phy->req_flow_ctrl != BNX2X_FLOW_CTRL_AUTO)
5230 vars->flow_ctrl = phy->req_flow_ctrl;
5231 else if (phy->req_line_speed != SPEED_AUTO_NEG)
5232 vars->flow_ctrl = params->req_fc_auto_adv;
5233 else if ((gp_status & MDIO_AN_CL73_OR_37_COMPLETE) &&
5234 (!(vars->phy_flags & PHY_SGMII_FLAG))) {
Yaniv Rosnere10bc842010-09-07 11:40:50 +00005235 if (bnx2x_direct_parallel_detect_used(phy, params)) {
Yaniv Rosner15ddd2d2009-11-05 19:18:12 +02005236 vars->flow_ctrl = params->req_fc_auto_adv;
5237 return;
5238 }
Yaniv Rosner7846e472009-11-05 19:18:07 +02005239 if ((gp_status &
5240 (MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_AUTONEG_COMPLETE |
5241 MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_MR_LP_NP_AN_ABLE)) ==
5242 (MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_AUTONEG_COMPLETE |
5243 MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_MR_LP_NP_AN_ABLE)) {
5244
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005245 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005246 MDIO_REG_BANK_CL73_IEEEB1,
5247 MDIO_CL73_IEEEB1_AN_ADV1,
5248 &ld_pause);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005249 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005250 MDIO_REG_BANK_CL73_IEEEB1,
5251 MDIO_CL73_IEEEB1_AN_LP_ADV1,
5252 &lp_pause);
Yaniv Rosner7846e472009-11-05 19:18:07 +02005253 pause_result = (ld_pause &
5254 MDIO_CL73_IEEEB1_AN_ADV1_PAUSE_MASK)
5255 >> 8;
5256 pause_result |= (lp_pause &
5257 MDIO_CL73_IEEEB1_AN_LP_ADV1_PAUSE_MASK)
5258 >> 10;
5259 DP(NETIF_MSG_LINK, "pause_result CL73 0x%x\n",
5260 pause_result);
5261 } else {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005262 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005263 MDIO_REG_BANK_COMBO_IEEE0,
5264 MDIO_COMBO_IEEE0_AUTO_NEG_ADV,
5265 &ld_pause);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005266 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005267 MDIO_REG_BANK_COMBO_IEEE0,
5268 MDIO_COMBO_IEEE0_AUTO_NEG_LINK_PARTNER_ABILITY1,
5269 &lp_pause);
Yaniv Rosner7846e472009-11-05 19:18:07 +02005270 pause_result = (ld_pause &
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005271 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK)>>5;
Yaniv Rosner7846e472009-11-05 19:18:07 +02005272 pause_result |= (lp_pause &
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005273 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK)>>7;
Yaniv Rosner7846e472009-11-05 19:18:07 +02005274 DP(NETIF_MSG_LINK, "pause_result CL37 0x%x\n",
5275 pause_result);
5276 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005277 bnx2x_pause_resolve(vars, pause_result);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005278 }
5279 DP(NETIF_MSG_LINK, "flow_ctrl 0x%x\n", vars->flow_ctrl);
5280}
5281
Yaniv Rosnere10bc842010-09-07 11:40:50 +00005282static void bnx2x_check_fallback_to_cl37(struct bnx2x_phy *phy,
5283 struct link_params *params)
Eilon Greenstein239d6862009-08-12 08:23:04 +00005284{
5285 struct bnx2x *bp = params->bp;
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00005286 u16 rx_status, ustat_val, cl37_fsm_received;
Eilon Greenstein239d6862009-08-12 08:23:04 +00005287 DP(NETIF_MSG_LINK, "bnx2x_check_fallback_to_cl37\n");
5288 /* Step 1: Make sure signal is detected */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005289 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005290 MDIO_REG_BANK_RX0,
5291 MDIO_RX0_RX_STATUS,
5292 &rx_status);
Eilon Greenstein239d6862009-08-12 08:23:04 +00005293 if ((rx_status & MDIO_RX0_RX_STATUS_SIGDET) !=
5294 (MDIO_RX0_RX_STATUS_SIGDET)) {
5295 DP(NETIF_MSG_LINK, "Signal is not detected. Restoring CL73."
5296 "rx_status(0x80b0) = 0x%x\n", rx_status);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005297 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005298 MDIO_REG_BANK_CL73_IEEEB0,
5299 MDIO_CL73_IEEEB0_CL73_AN_CONTROL,
5300 MDIO_CL73_IEEEB0_CL73_AN_CONTROL_AN_EN);
Eilon Greenstein239d6862009-08-12 08:23:04 +00005301 return;
5302 }
5303 /* Step 2: Check CL73 state machine */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005304 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005305 MDIO_REG_BANK_CL73_USERB0,
5306 MDIO_CL73_USERB0_CL73_USTAT1,
5307 &ustat_val);
Eilon Greenstein239d6862009-08-12 08:23:04 +00005308 if ((ustat_val &
5309 (MDIO_CL73_USERB0_CL73_USTAT1_LINK_STATUS_CHECK |
5310 MDIO_CL73_USERB0_CL73_USTAT1_AN_GOOD_CHECK_BAM37)) !=
5311 (MDIO_CL73_USERB0_CL73_USTAT1_LINK_STATUS_CHECK |
5312 MDIO_CL73_USERB0_CL73_USTAT1_AN_GOOD_CHECK_BAM37)) {
5313 DP(NETIF_MSG_LINK, "CL73 state-machine is not stable. "
5314 "ustat_val(0x8371) = 0x%x\n", ustat_val);
5315 return;
5316 }
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005317 /*
5318 * Step 3: Check CL37 Message Pages received to indicate LP
5319 * supports only CL37
5320 */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005321 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005322 MDIO_REG_BANK_REMOTE_PHY,
5323 MDIO_REMOTE_PHY_MISC_RX_STATUS,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00005324 &cl37_fsm_received);
5325 if ((cl37_fsm_received &
Eilon Greenstein239d6862009-08-12 08:23:04 +00005326 (MDIO_REMOTE_PHY_MISC_RX_STATUS_CL37_FSM_RECEIVED_OVER1G_MSG |
5327 MDIO_REMOTE_PHY_MISC_RX_STATUS_CL37_FSM_RECEIVED_BRCM_OUI_MSG)) !=
5328 (MDIO_REMOTE_PHY_MISC_RX_STATUS_CL37_FSM_RECEIVED_OVER1G_MSG |
5329 MDIO_REMOTE_PHY_MISC_RX_STATUS_CL37_FSM_RECEIVED_BRCM_OUI_MSG)) {
5330 DP(NETIF_MSG_LINK, "No CL37 FSM were received. "
5331 "misc_rx_status(0x8330) = 0x%x\n",
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00005332 cl37_fsm_received);
Eilon Greenstein239d6862009-08-12 08:23:04 +00005333 return;
5334 }
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005335 /*
5336 * The combined cl37/cl73 fsm state information indicating that
5337 * we are connected to a device which does not support cl73, but
5338 * does support cl37 BAM. In this case we disable cl73 and
5339 * restart cl37 auto-neg
5340 */
5341
Eilon Greenstein239d6862009-08-12 08:23:04 +00005342 /* Disable CL73 */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005343 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005344 MDIO_REG_BANK_CL73_IEEEB0,
5345 MDIO_CL73_IEEEB0_CL73_AN_CONTROL,
5346 0);
Eilon Greenstein239d6862009-08-12 08:23:04 +00005347 /* Restart CL37 autoneg */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00005348 bnx2x_restart_autoneg(phy, params, 0);
Eilon Greenstein239d6862009-08-12 08:23:04 +00005349 DP(NETIF_MSG_LINK, "Disabling CL73, and restarting CL37 autoneg\n");
5350}
Yaniv Rosner7aa07112010-09-07 11:41:01 +00005351
5352static void bnx2x_xgxs_an_resolve(struct bnx2x_phy *phy,
5353 struct link_params *params,
5354 struct link_vars *vars,
5355 u32 gp_status)
5356{
5357 if (gp_status & MDIO_AN_CL73_OR_37_COMPLETE)
5358 vars->link_status |=
5359 LINK_STATUS_AUTO_NEGOTIATE_COMPLETE;
5360
5361 if (bnx2x_direct_parallel_detect_used(phy, params))
5362 vars->link_status |=
5363 LINK_STATUS_PARALLEL_DETECTION_USED;
5364}
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005365static int bnx2x_get_link_speed_duplex(struct bnx2x_phy *phy,
5366 struct link_params *params,
5367 struct link_vars *vars,
5368 u16 is_link_up,
5369 u16 speed_mask,
5370 u16 is_duplex)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005371{
5372 struct bnx2x *bp = params->bp;
Yaniv Rosner7aa07112010-09-07 11:41:01 +00005373 if (phy->req_line_speed == SPEED_AUTO_NEG)
5374 vars->link_status |= LINK_STATUS_AUTO_NEGOTIATE_ENABLED;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005375 if (is_link_up) {
5376 DP(NETIF_MSG_LINK, "phy link up\n");
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005377
5378 vars->phy_link_up = 1;
5379 vars->link_status |= LINK_STATUS_LINK_UP;
5380
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005381 switch (speed_mask) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005382 case GP_STATUS_10M:
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005383 vars->line_speed = SPEED_10;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005384 if (vars->duplex == DUPLEX_FULL)
5385 vars->link_status |= LINK_10TFD;
5386 else
5387 vars->link_status |= LINK_10THD;
5388 break;
5389
5390 case GP_STATUS_100M:
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005391 vars->line_speed = SPEED_100;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005392 if (vars->duplex == DUPLEX_FULL)
5393 vars->link_status |= LINK_100TXFD;
5394 else
5395 vars->link_status |= LINK_100TXHD;
5396 break;
5397
5398 case GP_STATUS_1G:
5399 case GP_STATUS_1G_KX:
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005400 vars->line_speed = SPEED_1000;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005401 if (vars->duplex == DUPLEX_FULL)
5402 vars->link_status |= LINK_1000TFD;
5403 else
5404 vars->link_status |= LINK_1000THD;
5405 break;
5406
5407 case GP_STATUS_2_5G:
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005408 vars->line_speed = SPEED_2500;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005409 if (vars->duplex == DUPLEX_FULL)
5410 vars->link_status |= LINK_2500TFD;
5411 else
5412 vars->link_status |= LINK_2500THD;
5413 break;
5414
5415 case GP_STATUS_5G:
5416 case GP_STATUS_6G:
5417 DP(NETIF_MSG_LINK,
5418 "link speed unsupported gp_status 0x%x\n",
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005419 speed_mask);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005420 return -EINVAL;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00005421
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005422 case GP_STATUS_10G_KX4:
5423 case GP_STATUS_10G_HIG:
5424 case GP_STATUS_10G_CX4:
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005425 case GP_STATUS_10G_KR:
5426 case GP_STATUS_10G_SFI:
5427 case GP_STATUS_10G_XFI:
5428 vars->line_speed = SPEED_10000;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005429 vars->link_status |= LINK_10GTFD;
5430 break;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005431 case GP_STATUS_20G_DXGXS:
5432 vars->line_speed = SPEED_20000;
5433 vars->link_status |= LINK_20GTFD;
5434 break;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005435 default:
5436 DP(NETIF_MSG_LINK,
5437 "link speed unsupported gp_status 0x%x\n",
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005438 speed_mask);
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00005439 return -EINVAL;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005440 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005441 } else { /* link_down */
5442 DP(NETIF_MSG_LINK, "phy link down\n");
5443
5444 vars->phy_link_up = 0;
Yaniv Rosner57963ed2008-08-13 15:55:28 -07005445
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005446 vars->duplex = DUPLEX_FULL;
David S. Millerc0700f92008-12-16 23:53:20 -08005447 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005448 vars->mac_type = MAC_TYPE_NONE;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005449 }
5450 DP(NETIF_MSG_LINK, " phy_link_up %x line_speed %d\n",
5451 vars->phy_link_up, vars->line_speed);
5452 return 0;
5453}
Eilon Greenstein239d6862009-08-12 08:23:04 +00005454
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005455static int bnx2x_link_settings_status(struct bnx2x_phy *phy,
5456 struct link_params *params,
5457 struct link_vars *vars)
5458{
5459
5460 struct bnx2x *bp = params->bp;
5461
5462 u16 gp_status, duplex = DUPLEX_HALF, link_up = 0, speed_mask;
5463 int rc = 0;
5464
5465 /* Read gp_status */
5466 CL22_RD_OVER_CL45(bp, phy,
5467 MDIO_REG_BANK_GP_STATUS,
5468 MDIO_GP_STATUS_TOP_AN_STATUS1,
5469 &gp_status);
5470 if (gp_status & MDIO_GP_STATUS_TOP_AN_STATUS1_DUPLEX_STATUS)
5471 duplex = DUPLEX_FULL;
5472 if (gp_status & MDIO_GP_STATUS_TOP_AN_STATUS1_LINK_STATUS)
5473 link_up = 1;
5474 speed_mask = gp_status & GP_STATUS_SPEED_MASK;
5475 DP(NETIF_MSG_LINK, "gp_status 0x%x, is_link_up %d, speed_mask 0x%x\n",
5476 gp_status, link_up, speed_mask);
5477 rc = bnx2x_get_link_speed_duplex(phy, params, vars, link_up, speed_mask,
5478 duplex);
5479 if (rc == -EINVAL)
5480 return rc;
5481
5482 if (gp_status & MDIO_GP_STATUS_TOP_AN_STATUS1_LINK_STATUS) {
5483 if (SINGLE_MEDIA_DIRECT(params)) {
5484 bnx2x_flow_ctrl_resolve(phy, params, vars, gp_status);
5485 if (phy->req_line_speed == SPEED_AUTO_NEG)
5486 bnx2x_xgxs_an_resolve(phy, params, vars,
5487 gp_status);
5488 }
5489 } else { /* link_down */
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00005490 if ((phy->req_line_speed == SPEED_AUTO_NEG) &&
5491 SINGLE_MEDIA_DIRECT(params)) {
Eilon Greenstein239d6862009-08-12 08:23:04 +00005492 /* Check signal is detected */
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00005493 bnx2x_check_fallback_to_cl37(phy, params);
Eilon Greenstein239d6862009-08-12 08:23:04 +00005494 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005495 }
5496
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005497 DP(NETIF_MSG_LINK, "duplex %x flow_ctrl 0x%x link_status 0x%x\n",
5498 vars->duplex, vars->flow_ctrl, vars->link_status);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005499 return rc;
5500}
5501
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005502static int bnx2x_warpcore_read_status(struct bnx2x_phy *phy,
5503 struct link_params *params,
5504 struct link_vars *vars)
5505{
5506
5507 struct bnx2x *bp = params->bp;
5508
5509 u8 lane;
5510 u16 gp_status1, gp_speed, link_up, duplex = DUPLEX_FULL;
5511 int rc = 0;
5512 lane = bnx2x_get_warpcore_lane(phy, params);
5513 /* Read gp_status */
5514 if (phy->req_line_speed > SPEED_10000) {
5515 u16 temp_link_up;
5516 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
5517 1, &temp_link_up);
5518 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
5519 1, &link_up);
5520 DP(NETIF_MSG_LINK, "PCS RX link status = 0x%x-->0x%x\n",
5521 temp_link_up, link_up);
5522 link_up &= (1<<2);
5523 if (link_up)
5524 bnx2x_ext_phy_resolve_fc(phy, params, vars);
5525 } else {
5526 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
5527 MDIO_WC_REG_GP2_STATUS_GP_2_1, &gp_status1);
5528 DP(NETIF_MSG_LINK, "0x81d1 = 0x%x\n", gp_status1);
5529 /* Check for either KR or generic link up. */
5530 gp_status1 = ((gp_status1 >> 8) & 0xf) |
5531 ((gp_status1 >> 12) & 0xf);
5532 link_up = gp_status1 & (1 << lane);
5533 if (link_up && SINGLE_MEDIA_DIRECT(params)) {
5534 u16 pd, gp_status4;
5535 if (phy->req_line_speed == SPEED_AUTO_NEG) {
5536 /* Check Autoneg complete */
5537 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
5538 MDIO_WC_REG_GP2_STATUS_GP_2_4,
5539 &gp_status4);
5540 if (gp_status4 & ((1<<12)<<lane))
5541 vars->link_status |=
5542 LINK_STATUS_AUTO_NEGOTIATE_COMPLETE;
5543
5544 /* Check parallel detect used */
5545 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
5546 MDIO_WC_REG_PAR_DET_10G_STATUS,
5547 &pd);
5548 if (pd & (1<<15))
5549 vars->link_status |=
5550 LINK_STATUS_PARALLEL_DETECTION_USED;
5551 }
5552 bnx2x_ext_phy_resolve_fc(phy, params, vars);
5553 }
5554 }
5555
5556 if (lane < 2) {
5557 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
5558 MDIO_WC_REG_GP2_STATUS_GP_2_2, &gp_speed);
5559 } else {
5560 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
5561 MDIO_WC_REG_GP2_STATUS_GP_2_3, &gp_speed);
5562 }
5563 DP(NETIF_MSG_LINK, "lane %d gp_speed 0x%x\n", lane, gp_speed);
5564
5565 if ((lane & 1) == 0)
5566 gp_speed <<= 8;
5567 gp_speed &= 0x3f00;
5568
5569
5570 rc = bnx2x_get_link_speed_duplex(phy, params, vars, link_up, gp_speed,
5571 duplex);
5572
5573 DP(NETIF_MSG_LINK, "duplex %x flow_ctrl 0x%x link_status 0x%x\n",
5574 vars->duplex, vars->flow_ctrl, vars->link_status);
5575 return rc;
5576}
Eilon Greensteined8680a2009-02-12 08:37:12 +00005577static void bnx2x_set_gmii_tx_driver(struct link_params *params)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005578{
5579 struct bnx2x *bp = params->bp;
Yaniv Rosnere10bc842010-09-07 11:40:50 +00005580 struct bnx2x_phy *phy = &params->phy[INT_PHY];
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005581 u16 lp_up2;
5582 u16 tx_driver;
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00005583 u16 bank;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005584
5585 /* read precomp */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005586 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005587 MDIO_REG_BANK_OVER_1G,
5588 MDIO_OVER_1G_LP_UP2, &lp_up2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005589
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005590 /* bits [10:7] at lp_up2, positioned at [15:12] */
5591 lp_up2 = (((lp_up2 & MDIO_OVER_1G_LP_UP2_PREEMPHASIS_MASK) >>
5592 MDIO_OVER_1G_LP_UP2_PREEMPHASIS_SHIFT) <<
5593 MDIO_TX0_TX_DRIVER_PREEMPHASIS_SHIFT);
5594
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00005595 if (lp_up2 == 0)
5596 return;
5597
5598 for (bank = MDIO_REG_BANK_TX0; bank <= MDIO_REG_BANK_TX3;
5599 bank += (MDIO_REG_BANK_TX1 - MDIO_REG_BANK_TX0)) {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005600 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005601 bank,
5602 MDIO_TX0_TX_DRIVER, &tx_driver);
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00005603
5604 /* replace tx_driver bits [15:12] */
5605 if (lp_up2 !=
5606 (tx_driver & MDIO_TX0_TX_DRIVER_PREEMPHASIS_MASK)) {
5607 tx_driver &= ~MDIO_TX0_TX_DRIVER_PREEMPHASIS_MASK;
5608 tx_driver |= lp_up2;
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005609 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005610 bank,
5611 MDIO_TX0_TX_DRIVER, tx_driver);
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00005612 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005613 }
5614}
5615
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00005616static int bnx2x_emac_program(struct link_params *params,
5617 struct link_vars *vars)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005618{
5619 struct bnx2x *bp = params->bp;
5620 u8 port = params->port;
5621 u16 mode = 0;
5622
5623 DP(NETIF_MSG_LINK, "setting link speed & duplex\n");
5624 bnx2x_bits_dis(bp, GRCBASE_EMAC0 + port*0x400 +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005625 EMAC_REG_EMAC_MODE,
5626 (EMAC_MODE_25G_MODE |
5627 EMAC_MODE_PORT_MII_10M |
5628 EMAC_MODE_HALF_DUPLEX));
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005629 switch (vars->line_speed) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005630 case SPEED_10:
5631 mode |= EMAC_MODE_PORT_MII_10M;
5632 break;
5633
5634 case SPEED_100:
5635 mode |= EMAC_MODE_PORT_MII;
5636 break;
5637
5638 case SPEED_1000:
5639 mode |= EMAC_MODE_PORT_GMII;
5640 break;
5641
5642 case SPEED_2500:
5643 mode |= (EMAC_MODE_25G_MODE | EMAC_MODE_PORT_GMII);
5644 break;
5645
5646 default:
5647 /* 10G not valid for EMAC */
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005648 DP(NETIF_MSG_LINK, "Invalid line_speed 0x%x\n",
5649 vars->line_speed);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005650 return -EINVAL;
5651 }
5652
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005653 if (vars->duplex == DUPLEX_HALF)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005654 mode |= EMAC_MODE_HALF_DUPLEX;
5655 bnx2x_bits_en(bp,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005656 GRCBASE_EMAC0 + port*0x400 + EMAC_REG_EMAC_MODE,
5657 mode);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005658
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00005659 bnx2x_set_led(params, vars, LED_MODE_OPER, vars->line_speed);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005660 return 0;
5661}
5662
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005663static void bnx2x_set_preemphasis(struct bnx2x_phy *phy,
5664 struct link_params *params)
5665{
5666
5667 u16 bank, i = 0;
5668 struct bnx2x *bp = params->bp;
5669
5670 for (bank = MDIO_REG_BANK_RX0, i = 0; bank <= MDIO_REG_BANK_RX3;
5671 bank += (MDIO_REG_BANK_RX1-MDIO_REG_BANK_RX0), i++) {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005672 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005673 bank,
5674 MDIO_RX0_RX_EQ_BOOST,
5675 phy->rx_preemphasis[i]);
5676 }
5677
5678 for (bank = MDIO_REG_BANK_TX0, i = 0; bank <= MDIO_REG_BANK_TX3;
5679 bank += (MDIO_REG_BANK_TX1 - MDIO_REG_BANK_TX0), i++) {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005680 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005681 bank,
5682 MDIO_TX0_TX_DRIVER,
5683 phy->tx_preemphasis[i]);
5684 }
5685}
5686
Yaniv Rosnerec146a62011-05-31 21:29:27 +00005687static void bnx2x_xgxs_config_init(struct bnx2x_phy *phy,
5688 struct link_params *params,
5689 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005690{
5691 struct bnx2x *bp = params->bp;
5692 u8 enable_cl73 = (SINGLE_MEDIA_DIRECT(params) ||
5693 (params->loopback_mode == LOOPBACK_XGXS));
5694 if (!(vars->phy_flags & PHY_SGMII_FLAG)) {
5695 if (SINGLE_MEDIA_DIRECT(params) &&
5696 (params->feature_config_flags &
5697 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED))
5698 bnx2x_set_preemphasis(phy, params);
5699
5700 /* forced speed requested? */
5701 if (vars->line_speed != SPEED_AUTO_NEG ||
5702 (SINGLE_MEDIA_DIRECT(params) &&
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005703 params->loopback_mode == LOOPBACK_EXT)) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005704 DP(NETIF_MSG_LINK, "not SGMII, no AN\n");
5705
5706 /* disable autoneg */
5707 bnx2x_set_autoneg(phy, params, vars, 0);
5708
5709 /* program speed and duplex */
5710 bnx2x_program_serdes(phy, params, vars);
5711
5712 } else { /* AN_mode */
5713 DP(NETIF_MSG_LINK, "not SGMII, AN\n");
5714
5715 /* AN enabled */
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00005716 bnx2x_set_brcm_cl37_advertisement(phy, params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005717
5718 /* program duplex & pause advertisement (for aneg) */
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00005719 bnx2x_set_ieee_aneg_advertisement(phy, params,
5720 vars->ieee_fc);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005721
5722 /* enable autoneg */
5723 bnx2x_set_autoneg(phy, params, vars, enable_cl73);
5724
5725 /* enable and restart AN */
5726 bnx2x_restart_autoneg(phy, params, enable_cl73);
5727 }
5728
5729 } else { /* SGMII mode */
5730 DP(NETIF_MSG_LINK, "SGMII\n");
5731
5732 bnx2x_initialize_sgmii_process(phy, params, vars);
5733 }
5734}
5735
Yaniv Rosnerec146a62011-05-31 21:29:27 +00005736static int bnx2x_prepare_xgxs(struct bnx2x_phy *phy,
5737 struct link_params *params,
5738 struct link_vars *vars)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005739{
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00005740 int rc;
Yaniv Rosnerec146a62011-05-31 21:29:27 +00005741 vars->phy_flags |= PHY_XGXS_FLAG;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005742 if ((phy->req_line_speed &&
5743 ((phy->req_line_speed == SPEED_100) ||
5744 (phy->req_line_speed == SPEED_10))) ||
5745 (!phy->req_line_speed &&
5746 (phy->speed_cap_mask >=
5747 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL) &&
5748 (phy->speed_cap_mask <
Yaniv Rosnerec146a62011-05-31 21:29:27 +00005749 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) ||
5750 (phy->type == PORT_HW_CFG_SERDES_EXT_PHY_TYPE_DIRECT_SD))
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005751 vars->phy_flags |= PHY_SGMII_FLAG;
5752 else
5753 vars->phy_flags &= ~PHY_SGMII_FLAG;
5754
5755 bnx2x_calc_ieee_aneg_adv(phy, params, &vars->ieee_fc);
Yaniv Rosnerec146a62011-05-31 21:29:27 +00005756 bnx2x_set_aer_mmd(params, phy);
5757 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
5758 bnx2x_set_master_ln(params, phy);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005759
5760 rc = bnx2x_reset_unicore(params, phy, 0);
5761 /* reset the SerDes and wait for reset bit return low */
5762 if (rc != 0)
5763 return rc;
5764
Yaniv Rosnerec146a62011-05-31 21:29:27 +00005765 bnx2x_set_aer_mmd(params, phy);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005766 /* setting the masterLn_def again after the reset */
Yaniv Rosnerec146a62011-05-31 21:29:27 +00005767 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT) {
5768 bnx2x_set_master_ln(params, phy);
5769 bnx2x_set_swap_lanes(params, phy);
5770 }
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005771
5772 return rc;
5773}
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00005774
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005775static u16 bnx2x_wait_reset_complete(struct bnx2x *bp,
Yaniv Rosner6d870c32011-01-31 04:22:20 +00005776 struct bnx2x_phy *phy,
5777 struct link_params *params)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005778{
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005779 u16 cnt, ctrl;
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005780 /* Wait for soft reset to get cleared up to 1 sec */
Yaniv Rosner62b29a52010-09-07 11:40:58 +00005781 for (cnt = 0; cnt < 1000; cnt++) {
Yaniv Rosner52c4d6c2011-07-05 01:06:34 +00005782 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54618SE)
Yaniv Rosner6583e332011-06-14 01:34:17 +00005783 bnx2x_cl22_read(bp, phy,
5784 MDIO_PMA_REG_CTRL, &ctrl);
5785 else
5786 bnx2x_cl45_read(bp, phy,
5787 MDIO_PMA_DEVAD,
5788 MDIO_PMA_REG_CTRL, &ctrl);
Yaniv Rosner62b29a52010-09-07 11:40:58 +00005789 if (!(ctrl & (1<<15)))
5790 break;
5791 msleep(1);
5792 }
Yaniv Rosner6d870c32011-01-31 04:22:20 +00005793
5794 if (cnt == 1000)
5795 netdev_err(bp->dev, "Warning: PHY was not initialized,"
5796 " Port %d\n",
5797 params->port);
Yaniv Rosner62b29a52010-09-07 11:40:58 +00005798 DP(NETIF_MSG_LINK, "control reg 0x%x (after %d ms)\n", ctrl, cnt);
5799 return cnt;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005800}
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005801
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005802static void bnx2x_link_int_enable(struct link_params *params)
5803{
5804 u8 port = params->port;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005805 u32 mask;
5806 struct bnx2x *bp = params->bp;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00005807
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005808 /* Setting the status to report on link up for either XGXS or SerDes */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005809 if (CHIP_IS_E3(bp)) {
5810 mask = NIG_MASK_XGXS0_LINK_STATUS;
5811 if (!(SINGLE_MEDIA_DIRECT(params)))
5812 mask |= NIG_MASK_MI_INT;
5813 } else if (params->switch_cfg == SWITCH_CFG_10G) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005814 mask = (NIG_MASK_XGXS0_LINK10G |
5815 NIG_MASK_XGXS0_LINK_STATUS);
5816 DP(NETIF_MSG_LINK, "enabled XGXS interrupt\n");
Yaniv Rosnere10bc842010-09-07 11:40:50 +00005817 if (!(SINGLE_MEDIA_DIRECT(params)) &&
5818 params->phy[INT_PHY].type !=
5819 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005820 mask |= NIG_MASK_MI_INT;
5821 DP(NETIF_MSG_LINK, "enabled external phy int\n");
5822 }
5823
5824 } else { /* SerDes */
5825 mask = NIG_MASK_SERDES0_LINK_STATUS;
5826 DP(NETIF_MSG_LINK, "enabled SerDes interrupt\n");
Yaniv Rosnere10bc842010-09-07 11:40:50 +00005827 if (!(SINGLE_MEDIA_DIRECT(params)) &&
5828 params->phy[INT_PHY].type !=
5829 PORT_HW_CFG_SERDES_EXT_PHY_TYPE_NOT_CONN) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005830 mask |= NIG_MASK_MI_INT;
5831 DP(NETIF_MSG_LINK, "enabled external phy int\n");
5832 }
5833 }
5834 bnx2x_bits_en(bp,
5835 NIG_REG_MASK_INTERRUPT_PORT0 + port*4,
5836 mask);
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00005837
5838 DP(NETIF_MSG_LINK, "port %x, is_xgxs %x, int_status 0x%x\n", port,
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005839 (params->switch_cfg == SWITCH_CFG_10G),
5840 REG_RD(bp, NIG_REG_STATUS_INTERRUPT_PORT0 + port*4));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005841 DP(NETIF_MSG_LINK, " int_mask 0x%x, MI_INT %x, SERDES_LINK %x\n",
5842 REG_RD(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4),
5843 REG_RD(bp, NIG_REG_EMAC0_STATUS_MISC_MI_INT + port*0x18),
5844 REG_RD(bp, NIG_REG_SERDES0_STATUS_LINK_STATUS+port*0x3c));
5845 DP(NETIF_MSG_LINK, " 10G %x, XGXS_LINK %x\n",
5846 REG_RD(bp, NIG_REG_XGXS0_STATUS_LINK10G + port*0x68),
5847 REG_RD(bp, NIG_REG_XGXS0_STATUS_LINK_STATUS + port*0x68));
5848}
5849
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005850static void bnx2x_rearm_latch_signal(struct bnx2x *bp, u8 port,
5851 u8 exp_mi_int)
Eilon Greenstein2f904462009-08-12 08:22:16 +00005852{
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005853 u32 latch_status = 0;
5854
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005855 /*
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005856 * Disable the MI INT ( external phy int ) by writing 1 to the
5857 * status register. Link down indication is high-active-signal,
5858 * so in this case we need to write the status to clear the XOR
Eilon Greenstein2f904462009-08-12 08:22:16 +00005859 */
5860 /* Read Latched signals */
5861 latch_status = REG_RD(bp,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005862 NIG_REG_LATCH_STATUS_0 + port*8);
5863 DP(NETIF_MSG_LINK, "latch_status = 0x%x\n", latch_status);
Eilon Greenstein2f904462009-08-12 08:22:16 +00005864 /* Handle only those with latched-signal=up.*/
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005865 if (exp_mi_int)
5866 bnx2x_bits_en(bp,
5867 NIG_REG_STATUS_INTERRUPT_PORT0
5868 + port*4,
5869 NIG_STATUS_EMAC0_MI_INT);
5870 else
5871 bnx2x_bits_dis(bp,
5872 NIG_REG_STATUS_INTERRUPT_PORT0
5873 + port*4,
5874 NIG_STATUS_EMAC0_MI_INT);
5875
Eilon Greenstein2f904462009-08-12 08:22:16 +00005876 if (latch_status & 1) {
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005877
Eilon Greenstein2f904462009-08-12 08:22:16 +00005878 /* For all latched-signal=up : Re-Arm Latch signals */
5879 REG_WR(bp, NIG_REG_LATCH_STATUS_0 + port*8,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005880 (latch_status & 0xfffe) | (latch_status & 1));
Eilon Greenstein2f904462009-08-12 08:22:16 +00005881 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005882 /* For all latched-signal=up,Write original_signal to status */
Eilon Greenstein2f904462009-08-12 08:22:16 +00005883}
Yaniv Rosnere10bc842010-09-07 11:40:50 +00005884
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005885static void bnx2x_link_int_ack(struct link_params *params,
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005886 struct link_vars *vars, u8 is_10g_plus)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005887{
5888 struct bnx2x *bp = params->bp;
5889 u8 port = params->port;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005890 u32 mask;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005891 /*
5892 * First reset all status we assume only one line will be
5893 * change at a time
5894 */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005895 bnx2x_bits_dis(bp, NIG_REG_STATUS_INTERRUPT_PORT0 + port*4,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005896 (NIG_STATUS_XGXS0_LINK10G |
5897 NIG_STATUS_XGXS0_LINK_STATUS |
5898 NIG_STATUS_SERDES0_LINK_STATUS));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005899 if (vars->phy_link_up) {
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005900 if (USES_WARPCORE(bp))
5901 mask = NIG_STATUS_XGXS0_LINK_STATUS;
5902 else {
5903 if (is_10g_plus)
5904 mask = NIG_STATUS_XGXS0_LINK10G;
5905 else if (params->switch_cfg == SWITCH_CFG_10G) {
5906 /*
5907 * Disable the link interrupt by writing 1 to
5908 * the relevant lane in the status register
5909 */
5910 u32 ser_lane =
5911 ((params->lane_config &
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005912 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_MASK) >>
5913 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_SHIFT);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005914 mask = ((1 << ser_lane) <<
5915 NIG_STATUS_XGXS0_LINK_STATUS_SIZE);
5916 } else
5917 mask = NIG_STATUS_SERDES0_LINK_STATUS;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005918 }
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005919 DP(NETIF_MSG_LINK, "Ack link up interrupt with mask 0x%x\n",
5920 mask);
5921 bnx2x_bits_en(bp,
5922 NIG_REG_STATUS_INTERRUPT_PORT0 + port*4,
5923 mask);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005924 }
5925}
5926
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00005927static int bnx2x_format_ver(u32 num, u8 *str, u16 *len)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005928{
5929 u8 *str_ptr = str;
5930 u32 mask = 0xf0000000;
5931 u8 shift = 8*4;
5932 u8 digit;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005933 u8 remove_leading_zeros = 1;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005934 if (*len < 10) {
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02005935 /* Need more than 10chars for this format */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005936 *str_ptr = '\0';
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005937 (*len)--;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005938 return -EINVAL;
5939 }
5940 while (shift > 0) {
5941
5942 shift -= 4;
5943 digit = ((num & mask) >> shift);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005944 if (digit == 0 && remove_leading_zeros) {
5945 mask = mask >> 4;
5946 continue;
5947 } else if (digit < 0xa)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005948 *str_ptr = digit + '0';
5949 else
5950 *str_ptr = digit - 0xa + 'a';
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005951 remove_leading_zeros = 0;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005952 str_ptr++;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005953 (*len)--;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005954 mask = mask >> 4;
5955 if (shift == 4*4) {
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005956 *str_ptr = '.';
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005957 str_ptr++;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005958 (*len)--;
5959 remove_leading_zeros = 1;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005960 }
5961 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005962 return 0;
5963}
5964
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005965
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00005966static int bnx2x_null_format_ver(u32 spirom_ver, u8 *str, u16 *len)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005967{
5968 str[0] = '\0';
5969 (*len)--;
5970 return 0;
5971}
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005972
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00005973int bnx2x_get_ext_phy_fw_version(struct link_params *params, u8 driver_loaded,
5974 u8 *version, u16 len)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005975{
Julia Lawall0376d5b2009-07-19 05:26:35 +00005976 struct bnx2x *bp;
Eilon Greensteina35da8d2009-02-12 08:37:02 +00005977 u32 spirom_ver = 0;
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00005978 int status = 0;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005979 u8 *ver_p = version;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005980 u16 remain_len = len;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005981 if (version == NULL || params == NULL)
5982 return -EINVAL;
Julia Lawall0376d5b2009-07-19 05:26:35 +00005983 bp = params->bp;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005984
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005985 /* Extract first external phy*/
5986 version[0] = '\0';
5987 spirom_ver = REG_RD(bp, params->phy[EXT_PHY1].ver_addr);
Eilon Greensteina35da8d2009-02-12 08:37:02 +00005988
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005989 if (params->phy[EXT_PHY1].format_fw_ver) {
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005990 status |= params->phy[EXT_PHY1].format_fw_ver(spirom_ver,
5991 ver_p,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005992 &remain_len);
5993 ver_p += (len - remain_len);
5994 }
5995 if ((params->num_phys == MAX_PHYS) &&
5996 (params->phy[EXT_PHY2].ver_addr != 0)) {
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005997 spirom_ver = REG_RD(bp, params->phy[EXT_PHY2].ver_addr);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005998 if (params->phy[EXT_PHY2].format_fw_ver) {
5999 *ver_p = '/';
6000 ver_p++;
6001 remain_len--;
6002 status |= params->phy[EXT_PHY2].format_fw_ver(
6003 spirom_ver,
6004 ver_p,
6005 &remain_len);
6006 ver_p = version + (len - remain_len);
6007 }
6008 }
6009 *ver_p = '\0';
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006010 return status;
6011}
6012
Yaniv Rosnere10bc842010-09-07 11:40:50 +00006013static void bnx2x_set_xgxs_loopback(struct bnx2x_phy *phy,
Yaniv Rosner62b29a52010-09-07 11:40:58 +00006014 struct link_params *params)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006015{
6016 u8 port = params->port;
6017 struct bnx2x *bp = params->bp;
6018
Yaniv Rosner62b29a52010-09-07 11:40:58 +00006019 if (phy->req_line_speed != SPEED_1000) {
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006020 u32 md_devad = 0;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006021
6022 DP(NETIF_MSG_LINK, "XGXS 10G loopback enable\n");
6023
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006024 if (!CHIP_IS_E3(bp)) {
6025 /* change the uni_phy_addr in the nig */
6026 md_devad = REG_RD(bp, (NIG_REG_XGXS0_CTRL_MD_DEVAD +
6027 port*0x18));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006028
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006029 REG_WR(bp, NIG_REG_XGXS0_CTRL_MD_DEVAD + port*0x18,
6030 0x5);
6031 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006032
Yaniv Rosnere10bc842010-09-07 11:40:50 +00006033 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006034 5,
6035 (MDIO_REG_BANK_AER_BLOCK +
6036 (MDIO_AER_BLOCK_AER_REG & 0xf)),
6037 0x2800);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006038
Yaniv Rosnere10bc842010-09-07 11:40:50 +00006039 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006040 5,
6041 (MDIO_REG_BANK_CL73_IEEEB0 +
6042 (MDIO_CL73_IEEEB0_CL73_AN_CONTROL & 0xf)),
6043 0x6041);
Eilon Greenstein38582762009-01-14 06:44:16 +00006044 msleep(200);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006045 /* set aer mmd back */
Yaniv Rosnerec146a62011-05-31 21:29:27 +00006046 bnx2x_set_aer_mmd(params, phy);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006047
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006048 if (!CHIP_IS_E3(bp)) {
6049 /* and md_devad */
6050 REG_WR(bp, NIG_REG_XGXS0_CTRL_MD_DEVAD + port*0x18,
6051 md_devad);
6052 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006053 } else {
Yaniv Rosnere10bc842010-09-07 11:40:50 +00006054 u16 mii_ctrl;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006055 DP(NETIF_MSG_LINK, "XGXS 1G loopback enable\n");
Yaniv Rosnere10bc842010-09-07 11:40:50 +00006056 bnx2x_cl45_read(bp, phy, 5,
6057 (MDIO_REG_BANK_COMBO_IEEE0 +
6058 (MDIO_COMBO_IEEE0_MII_CONTROL & 0xf)),
6059 &mii_ctrl);
6060 bnx2x_cl45_write(bp, phy, 5,
6061 (MDIO_REG_BANK_COMBO_IEEE0 +
6062 (MDIO_COMBO_IEEE0_MII_CONTROL & 0xf)),
6063 mii_ctrl |
6064 MDIO_COMBO_IEEO_MII_CONTROL_LOOPBACK);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006065 }
6066}
6067
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006068int bnx2x_set_led(struct link_params *params,
6069 struct link_vars *vars, u8 mode, u32 speed)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006070{
Yaniv Rosner7846e472009-11-05 19:18:07 +02006071 u8 port = params->port;
6072 u16 hw_led_mode = params->hw_led_mode;
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006073 int rc = 0;
6074 u8 phy_idx;
Eilon Greenstein345b5d52008-08-13 15:58:12 -07006075 u32 tmp;
6076 u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
Yaniv Rosner7846e472009-11-05 19:18:07 +02006077 struct bnx2x *bp = params->bp;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006078 DP(NETIF_MSG_LINK, "bnx2x_set_led: port %x, mode %d\n", port, mode);
6079 DP(NETIF_MSG_LINK, "speed 0x%x, hw_led_mode 0x%x\n",
6080 speed, hw_led_mode);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006081 /* In case */
6082 for (phy_idx = EXT_PHY1; phy_idx < MAX_PHYS; phy_idx++) {
6083 if (params->phy[phy_idx].set_link_led) {
6084 params->phy[phy_idx].set_link_led(
6085 &params->phy[phy_idx], params, mode);
6086 }
6087 }
6088
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006089 switch (mode) {
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006090 case LED_MODE_FRONT_PANEL_OFF:
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006091 case LED_MODE_OFF:
6092 REG_WR(bp, NIG_REG_LED_10G_P0 + port*4, 0);
6093 REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006094 SHARED_HW_CFG_LED_MAC1);
Eilon Greenstein345b5d52008-08-13 15:58:12 -07006095
6096 tmp = EMAC_RD(bp, EMAC_REG_EMAC_LED);
Yaniv Rosner001cea72011-10-27 05:09:48 +00006097 if (params->phy[EXT_PHY1].type ==
6098 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54618SE)
6099 EMAC_WR(bp, EMAC_REG_EMAC_LED, tmp & 0xfff1);
6100 else {
6101 EMAC_WR(bp, EMAC_REG_EMAC_LED,
6102 (tmp | EMAC_LED_OVERRIDE));
6103 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006104 break;
6105
6106 case LED_MODE_OPER:
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006107 /*
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006108 * For all other phys, OPER mode is same as ON, so in case
6109 * link is down, do nothing
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006110 */
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006111 if (!vars->link_up)
6112 break;
6113 case LED_MODE_ON:
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00006114 if (((params->phy[EXT_PHY1].type ==
6115 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727) ||
6116 (params->phy[EXT_PHY1].type ==
6117 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8722)) &&
Yaniv Rosner1f483532011-01-18 04:33:31 +00006118 CHIP_IS_E2(bp) && params->num_phys == 2) {
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006119 /*
6120 * This is a work-around for E2+8727 Configurations
6121 */
Yaniv Rosner1f483532011-01-18 04:33:31 +00006122 if (mode == LED_MODE_ON ||
6123 speed == SPEED_10000){
6124 REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4, 0);
6125 REG_WR(bp, NIG_REG_LED_10G_P0 + port*4, 1);
6126
6127 tmp = EMAC_RD(bp, EMAC_REG_EMAC_LED);
6128 EMAC_WR(bp, EMAC_REG_EMAC_LED,
6129 (tmp | EMAC_LED_OVERRIDE));
Yaniv Rosner793bd452011-08-02 22:59:40 +00006130 /*
6131 * return here without enabling traffic
David S. Miller8decf862011-09-22 03:23:13 -04006132 * LED blink and setting rate in ON mode.
Yaniv Rosner793bd452011-08-02 22:59:40 +00006133 * In oper mode, enabling LED blink
6134 * and setting rate is needed.
6135 */
6136 if (mode == LED_MODE_ON)
6137 return rc;
Yaniv Rosner1f483532011-01-18 04:33:31 +00006138 }
Yaniv Rosner793bd452011-08-02 22:59:40 +00006139 } else if (SINGLE_MEDIA_DIRECT(params)) {
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006140 /*
6141 * This is a work-around for HW issue found when link
6142 * is up in CL73
6143 */
David S. Miller8decf862011-09-22 03:23:13 -04006144 if ((!CHIP_IS_E3(bp)) ||
6145 (CHIP_IS_E3(bp) &&
6146 mode == LED_MODE_ON))
6147 REG_WR(bp, NIG_REG_LED_10G_P0 + port*4, 1);
6148
Yaniv Rosner793bd452011-08-02 22:59:40 +00006149 if (CHIP_IS_E1x(bp) ||
6150 CHIP_IS_E2(bp) ||
6151 (mode == LED_MODE_ON))
6152 REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4, 0);
6153 else
6154 REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4,
6155 hw_led_mode);
Yaniv Rosner001cea72011-10-27 05:09:48 +00006156 } else if ((params->phy[EXT_PHY1].type ==
6157 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54618SE) &&
6158 (mode != LED_MODE_OPER)) {
6159 REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4, 0);
6160 tmp = EMAC_RD(bp, EMAC_REG_EMAC_LED);
6161 EMAC_WR(bp, EMAC_REG_EMAC_LED, tmp | 0x3);
Yaniv Rosner793bd452011-08-02 22:59:40 +00006162 } else
Yaniv Rosner001cea72011-10-27 05:09:48 +00006163 REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4,
6164 hw_led_mode);
Yaniv Rosner7846e472009-11-05 19:18:07 +02006165
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006166 REG_WR(bp, NIG_REG_LED_CONTROL_OVERRIDE_TRAFFIC_P0 + port*4, 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006167 /* Set blinking rate to ~15.9Hz */
Yaniv Rosner26ffaf32011-10-27 05:09:45 +00006168 if (CHIP_IS_E3(bp))
6169 REG_WR(bp, NIG_REG_LED_CONTROL_BLINK_RATE_P0 + port*4,
6170 LED_BLINK_RATE_VAL_E3);
6171 else
6172 REG_WR(bp, NIG_REG_LED_CONTROL_BLINK_RATE_P0 + port*4,
6173 LED_BLINK_RATE_VAL_E1X_E2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006174 REG_WR(bp, NIG_REG_LED_CONTROL_BLINK_RATE_ENA_P0 +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006175 port*4, 1);
Yaniv Rosner001cea72011-10-27 05:09:48 +00006176 if ((params->phy[EXT_PHY1].type !=
6177 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54618SE) &&
6178 (mode != LED_MODE_OPER)) {
6179 tmp = EMAC_RD(bp, EMAC_REG_EMAC_LED);
6180 EMAC_WR(bp, EMAC_REG_EMAC_LED,
6181 (tmp & (~EMAC_LED_OVERRIDE)));
6182 }
Eilon Greenstein345b5d52008-08-13 15:58:12 -07006183
Yaniv Rosner7846e472009-11-05 19:18:07 +02006184 if (CHIP_IS_E1(bp) &&
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006185 ((speed == SPEED_2500) ||
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006186 (speed == SPEED_1000) ||
6187 (speed == SPEED_100) ||
6188 (speed == SPEED_10))) {
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006189 /*
6190 * On Everest 1 Ax chip versions for speeds less than
6191 * 10G LED scheme is different
6192 */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006193 REG_WR(bp, NIG_REG_LED_CONTROL_OVERRIDE_TRAFFIC_P0
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006194 + port*4, 1);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006195 REG_WR(bp, NIG_REG_LED_CONTROL_TRAFFIC_P0 +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006196 port*4, 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006197 REG_WR(bp, NIG_REG_LED_CONTROL_BLINK_TRAFFIC_P0 +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006198 port*4, 1);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006199 }
6200 break;
6201
6202 default:
6203 rc = -EINVAL;
6204 DP(NETIF_MSG_LINK, "bnx2x_set_led: Invalid led mode %d\n",
6205 mode);
6206 break;
6207 }
6208 return rc;
6209
6210}
6211
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006212/*
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006213 * This function comes to reflect the actual link state read DIRECTLY from the
6214 * HW
6215 */
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006216int bnx2x_test_link(struct link_params *params, struct link_vars *vars,
6217 u8 is_serdes)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006218{
6219 struct bnx2x *bp = params->bp;
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00006220 u16 gp_status = 0, phy_index = 0;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006221 u8 ext_phy_link_up = 0, serdes_phy_type;
6222 struct link_vars temp_vars;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006223 struct bnx2x_phy *int_phy = &params->phy[INT_PHY];
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006224
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006225 if (CHIP_IS_E3(bp)) {
6226 u16 link_up;
6227 if (params->req_line_speed[LINK_CONFIG_IDX(INT_PHY)]
6228 > SPEED_10000) {
6229 /* Check 20G link */
6230 bnx2x_cl45_read(bp, int_phy, MDIO_WC_DEVAD,
6231 1, &link_up);
6232 bnx2x_cl45_read(bp, int_phy, MDIO_WC_DEVAD,
6233 1, &link_up);
6234 link_up &= (1<<2);
6235 } else {
6236 /* Check 10G link and below*/
6237 u8 lane = bnx2x_get_warpcore_lane(int_phy, params);
6238 bnx2x_cl45_read(bp, int_phy, MDIO_WC_DEVAD,
6239 MDIO_WC_REG_GP2_STATUS_GP_2_1,
6240 &gp_status);
6241 gp_status = ((gp_status >> 8) & 0xf) |
6242 ((gp_status >> 12) & 0xf);
6243 link_up = gp_status & (1 << lane);
6244 }
6245 if (!link_up)
6246 return -ESRCH;
6247 } else {
6248 CL22_RD_OVER_CL45(bp, int_phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006249 MDIO_REG_BANK_GP_STATUS,
6250 MDIO_GP_STATUS_TOP_AN_STATUS1,
6251 &gp_status);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006252 /* link is up only if both local phy and external phy are up */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006253 if (!(gp_status & MDIO_GP_STATUS_TOP_AN_STATUS1_LINK_STATUS))
6254 return -ESRCH;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006255 }
6256 /* In XGXS loopback mode, do not check external PHY */
6257 if (params->loopback_mode == LOOPBACK_XGXS)
6258 return 0;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006259
6260 switch (params->num_phys) {
6261 case 1:
6262 /* No external PHY */
6263 return 0;
6264 case 2:
6265 ext_phy_link_up = params->phy[EXT_PHY1].read_status(
6266 &params->phy[EXT_PHY1],
6267 params, &temp_vars);
6268 break;
6269 case 3: /* Dual Media */
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00006270 for (phy_index = EXT_PHY1; phy_index < params->num_phys;
6271 phy_index++) {
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006272 serdes_phy_type = ((params->phy[phy_index].media_type ==
6273 ETH_PHY_SFP_FIBER) ||
6274 (params->phy[phy_index].media_type ==
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00006275 ETH_PHY_XFP_FIBER) ||
6276 (params->phy[phy_index].media_type ==
6277 ETH_PHY_DA_TWINAX));
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006278
6279 if (is_serdes != serdes_phy_type)
6280 continue;
6281 if (params->phy[phy_index].read_status) {
6282 ext_phy_link_up |=
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00006283 params->phy[phy_index].read_status(
6284 &params->phy[phy_index],
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006285 params, &temp_vars);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006286 }
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00006287 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006288 break;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006289 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006290 if (ext_phy_link_up)
6291 return 0;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006292 return -ESRCH;
6293}
6294
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006295static int bnx2x_link_initialize(struct link_params *params,
6296 struct link_vars *vars)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006297{
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006298 int rc = 0;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006299 u8 phy_index, non_ext_phy;
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00006300 struct bnx2x *bp = params->bp;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006301 /*
6302 * In case of external phy existence, the line speed would be the
6303 * line speed linked up by the external phy. In case it is direct
6304 * only, then the line_speed during initialization will be
6305 * equal to the req_line_speed
6306 */
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00006307 vars->line_speed = params->phy[INT_PHY].req_line_speed;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006308
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006309 /*
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00006310 * Initialize the internal phy in case this is a direct board
6311 * (no external phys), or this board has external phy which requires
6312 * to first.
6313 */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006314 if (!USES_WARPCORE(bp))
6315 bnx2x_prepare_xgxs(&params->phy[INT_PHY], params, vars);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006316 /* init ext phy and enable link state int */
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00006317 non_ext_phy = (SINGLE_MEDIA_DIRECT(params) ||
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006318 (params->loopback_mode == LOOPBACK_XGXS));
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006319
6320 if (non_ext_phy ||
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00006321 (params->phy[EXT_PHY1].flags & FLAGS_INIT_XGXS_FIRST) ||
Eilon Greenstein8660d8c2009-03-02 08:01:02 +00006322 (params->loopback_mode == LOOPBACK_EXT_PHY)) {
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00006323 struct bnx2x_phy *phy = &params->phy[INT_PHY];
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006324 if (vars->line_speed == SPEED_AUTO_NEG &&
6325 (CHIP_IS_E1x(bp) ||
6326 CHIP_IS_E2(bp)))
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00006327 bnx2x_set_parallel_detection(phy, params);
Yaniv Rosnerec146a62011-05-31 21:29:27 +00006328 if (params->phy[INT_PHY].config_init)
6329 params->phy[INT_PHY].config_init(phy,
6330 params,
6331 vars);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006332 }
6333
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00006334 /* Init external phy*/
Yaniv Rosnerfd36a2e2011-05-31 21:29:05 +00006335 if (non_ext_phy) {
6336 if (params->phy[INT_PHY].supported &
6337 SUPPORTED_FIBRE)
6338 vars->link_status |= LINK_STATUS_SERDES_LINK;
6339 } else {
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006340 for (phy_index = EXT_PHY1; phy_index < params->num_phys;
6341 phy_index++) {
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006342 /*
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006343 * No need to initialize second phy in case of first
6344 * phy only selection. In case of second phy, we do
6345 * need to initialize the first phy, since they are
6346 * connected.
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006347 */
Yaniv Rosnerfd36a2e2011-05-31 21:29:05 +00006348 if (params->phy[phy_index].supported &
6349 SUPPORTED_FIBRE)
6350 vars->link_status |= LINK_STATUS_SERDES_LINK;
6351
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006352 if (phy_index == EXT_PHY2 &&
6353 (bnx2x_phy_selection(params) ==
6354 PORT_HW_CFG_PHY_SELECTION_FIRST_PHY)) {
Joe Perches94f05b02011-08-14 12:16:20 +00006355 DP(NETIF_MSG_LINK,
6356 "Not initializing second phy\n");
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006357 continue;
6358 }
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006359 params->phy[phy_index].config_init(
6360 &params->phy[phy_index],
6361 params, vars);
6362 }
Yaniv Rosnerfd36a2e2011-05-31 21:29:05 +00006363 }
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +00006364 /* Reset the interrupt indication after phy was initialized */
6365 bnx2x_bits_dis(bp, NIG_REG_STATUS_INTERRUPT_PORT0 +
6366 params->port*4,
6367 (NIG_STATUS_XGXS0_LINK10G |
6368 NIG_STATUS_XGXS0_LINK_STATUS |
6369 NIG_STATUS_SERDES0_LINK_STATUS |
6370 NIG_MASK_MI_INT));
Yaniv Rosnerfd36a2e2011-05-31 21:29:05 +00006371 bnx2x_update_mng(params, vars->link_status);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006372 return rc;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006373}
6374
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006375static void bnx2x_int_link_reset(struct bnx2x_phy *phy,
6376 struct link_params *params)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006377{
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006378 /* reset the SerDes/XGXS */
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006379 REG_WR(params->bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_CLEAR,
6380 (0x1ff << (params->port*16)));
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006381}
6382
6383static void bnx2x_common_ext_link_reset(struct bnx2x_phy *phy,
6384 struct link_params *params)
6385{
6386 struct bnx2x *bp = params->bp;
6387 u8 gpio_port;
6388 /* HW reset */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006389 if (CHIP_IS_E2(bp))
6390 gpio_port = BP_PATH(bp);
6391 else
6392 gpio_port = params->port;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006393 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006394 MISC_REGISTERS_GPIO_OUTPUT_LOW,
6395 gpio_port);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006396 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006397 MISC_REGISTERS_GPIO_OUTPUT_LOW,
6398 gpio_port);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006399 DP(NETIF_MSG_LINK, "reset external PHY\n");
6400}
6401
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006402static int bnx2x_update_link_down(struct link_params *params,
6403 struct link_vars *vars)
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006404{
6405 struct bnx2x *bp = params->bp;
6406 u8 port = params->port;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00006407
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006408 DP(NETIF_MSG_LINK, "Port %x: Link is down\n", port);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006409 bnx2x_set_led(params, vars, LED_MODE_OFF, 0);
Yaniv Rosner3deb8162011-06-14 01:34:33 +00006410 vars->phy_flags &= ~PHY_PHYSICAL_LINK_FLAG;
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006411 /* indicate no mac active */
6412 vars->mac_type = MAC_TYPE_NONE;
6413
6414 /* update shared memory */
Yaniv Rosnerfd36a2e2011-05-31 21:29:05 +00006415 vars->link_status &= ~(LINK_STATUS_SPEED_AND_DUPLEX_MASK |
6416 LINK_STATUS_LINK_UP |
Yaniv Rosnerde6f3372011-08-02 22:59:25 +00006417 LINK_STATUS_PHYSICAL_LINK_FLAG |
Yaniv Rosnerfd36a2e2011-05-31 21:29:05 +00006418 LINK_STATUS_AUTO_NEGOTIATE_COMPLETE |
6419 LINK_STATUS_RX_FLOW_CONTROL_FLAG_MASK |
6420 LINK_STATUS_TX_FLOW_CONTROL_FLAG_MASK |
6421 LINK_STATUS_PARALLEL_DETECTION_FLAG_MASK);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006422 vars->line_speed = 0;
6423 bnx2x_update_mng(params, vars->link_status);
6424
6425 /* activate nig drain */
6426 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + port*4, 1);
6427
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00006428 /* disable emac */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00006429 if (!CHIP_IS_E3(bp))
6430 REG_WR(bp, NIG_REG_NIG_EMAC0_EN + port*4, 0);
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00006431
6432 msleep(10);
Yaniv Rosner9380bb92011-06-14 01:34:07 +00006433 /* reset BigMac/Xmac */
6434 if (CHIP_IS_E1x(bp) ||
6435 CHIP_IS_E2(bp)) {
6436 bnx2x_bmac_rx_disable(bp, params->port);
6437 REG_WR(bp, GRCBASE_MISC +
6438 MISC_REGISTERS_RESET_REG_2_CLEAR,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006439 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port));
Yaniv Rosner9380bb92011-06-14 01:34:07 +00006440 }
Yaniv Rosnerce7c0482011-10-27 05:09:47 +00006441 if (CHIP_IS_E3(bp)) {
Yaniv Rosner9380bb92011-06-14 01:34:07 +00006442 bnx2x_xmac_disable(params);
Yaniv Rosnerce7c0482011-10-27 05:09:47 +00006443 bnx2x_umac_disable(params);
6444 }
Yaniv Rosner9380bb92011-06-14 01:34:07 +00006445
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006446 return 0;
6447}
6448
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006449static int bnx2x_update_link_up(struct link_params *params,
6450 struct link_vars *vars,
6451 u8 link_10g)
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006452{
6453 struct bnx2x *bp = params->bp;
6454 u8 port = params->port;
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006455 int rc = 0;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00006456
Yaniv Rosnerde6f3372011-08-02 22:59:25 +00006457 vars->link_status |= (LINK_STATUS_LINK_UP |
6458 LINK_STATUS_PHYSICAL_LINK_FLAG);
Yaniv Rosner3deb8162011-06-14 01:34:33 +00006459 vars->phy_flags |= PHY_PHYSICAL_LINK_FLAG;
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006460
Yaniv Rosner7aa07112010-09-07 11:41:01 +00006461 if (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX)
6462 vars->link_status |=
6463 LINK_STATUS_TX_FLOW_CONTROL_ENABLED;
6464
6465 if (vars->flow_ctrl & BNX2X_FLOW_CTRL_RX)
6466 vars->link_status |=
6467 LINK_STATUS_RX_FLOW_CONTROL_ENABLED;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00006468 if (USES_WARPCORE(bp)) {
Yaniv Rosner3deb8162011-06-14 01:34:33 +00006469 if (link_10g) {
6470 if (bnx2x_xmac_enable(params, vars, 0) ==
6471 -ESRCH) {
6472 DP(NETIF_MSG_LINK, "Found errors on XMAC\n");
6473 vars->link_up = 0;
6474 vars->phy_flags |= PHY_HALF_OPEN_CONN_FLAG;
6475 vars->link_status &= ~LINK_STATUS_LINK_UP;
6476 }
6477 } else
Yaniv Rosner9380bb92011-06-14 01:34:07 +00006478 bnx2x_umac_enable(params, vars, 0);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006479 bnx2x_set_led(params, vars,
Yaniv Rosner9380bb92011-06-14 01:34:07 +00006480 LED_MODE_OPER, vars->line_speed);
6481 }
6482 if ((CHIP_IS_E1x(bp) ||
6483 CHIP_IS_E2(bp))) {
6484 if (link_10g) {
Yaniv Rosner3deb8162011-06-14 01:34:33 +00006485 if (bnx2x_bmac_enable(params, vars, 0) ==
6486 -ESRCH) {
6487 DP(NETIF_MSG_LINK, "Found errors on BMAC\n");
6488 vars->link_up = 0;
6489 vars->phy_flags |= PHY_HALF_OPEN_CONN_FLAG;
6490 vars->link_status &= ~LINK_STATUS_LINK_UP;
6491 }
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006492
Yaniv Rosner9380bb92011-06-14 01:34:07 +00006493 bnx2x_set_led(params, vars,
6494 LED_MODE_OPER, SPEED_10000);
6495 } else {
6496 rc = bnx2x_emac_program(params, vars);
6497 bnx2x_emac_enable(params, vars, 0);
Yaniv Rosner0c786f02009-11-05 19:18:32 +02006498
Yaniv Rosner9380bb92011-06-14 01:34:07 +00006499 /* AN complete? */
6500 if ((vars->link_status &
6501 LINK_STATUS_AUTO_NEGOTIATE_COMPLETE)
6502 && (!(vars->phy_flags & PHY_SGMII_FLAG)) &&
6503 SINGLE_MEDIA_DIRECT(params))
6504 bnx2x_set_gmii_tx_driver(params);
6505 }
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006506 }
6507
6508 /* PBF - link up */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00006509 if (CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006510 rc |= bnx2x_pbf_update(params, vars->flow_ctrl,
6511 vars->line_speed);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006512
6513 /* disable drain */
6514 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + port*4, 0);
6515
6516 /* update shared memory */
6517 bnx2x_update_mng(params, vars->link_status);
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00006518 msleep(20);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006519 return rc;
6520}
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006521/*
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006522 * The bnx2x_link_update function should be called upon link
6523 * interrupt.
6524 * Link is considered up as follows:
6525 * - DIRECT_SINGLE_MEDIA - Only XGXS link (internal link) needs
6526 * to be up
6527 * - SINGLE_MEDIA - The link between the 577xx and the external
6528 * phy (XGXS) need to up as well as the external link of the
6529 * phy (PHY_EXT1)
6530 * - DUAL_MEDIA - The link between the 577xx and the first
6531 * external phy needs to be up, and at least one of the 2
6532 * external phy link must be up.
Yaniv Rosner62b29a52010-09-07 11:40:58 +00006533 */
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006534int bnx2x_link_update(struct link_params *params, struct link_vars *vars)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006535{
6536 struct bnx2x *bp = params->bp;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006537 struct link_vars phy_vars[MAX_PHYS];
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006538 u8 port = params->port;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006539 u8 link_10g_plus, phy_index;
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006540 u8 ext_phy_link_up = 0, cur_link_up;
6541 int rc = 0;
Eilon Greenstein2f904462009-08-12 08:22:16 +00006542 u8 is_mi_int = 0;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006543 u16 ext_phy_line_speed = 0, prev_line_speed = vars->line_speed;
6544 u8 active_external_phy = INT_PHY;
Yaniv Rosner3deb8162011-06-14 01:34:33 +00006545 vars->phy_flags &= ~PHY_HALF_OPEN_CONN_FLAG;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006546 for (phy_index = INT_PHY; phy_index < params->num_phys;
6547 phy_index++) {
6548 phy_vars[phy_index].flow_ctrl = 0;
6549 phy_vars[phy_index].link_status = 0;
6550 phy_vars[phy_index].line_speed = 0;
6551 phy_vars[phy_index].duplex = DUPLEX_FULL;
6552 phy_vars[phy_index].phy_link_up = 0;
6553 phy_vars[phy_index].link_up = 0;
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00006554 phy_vars[phy_index].fault_detected = 0;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006555 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006556
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006557 if (USES_WARPCORE(bp))
6558 bnx2x_set_aer_mmd(params, &params->phy[INT_PHY]);
6559
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006560 DP(NETIF_MSG_LINK, "port %x, XGXS?%x, int_status 0x%x\n",
Eilon Greenstein2f904462009-08-12 08:22:16 +00006561 port, (vars->phy_flags & PHY_XGXS_FLAG),
6562 REG_RD(bp, NIG_REG_STATUS_INTERRUPT_PORT0 + port*4));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006563
Eilon Greenstein2f904462009-08-12 08:22:16 +00006564 is_mi_int = (u8)(REG_RD(bp, NIG_REG_EMAC0_STATUS_MISC_MI_INT +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006565 port*0x18) > 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006566 DP(NETIF_MSG_LINK, "int_mask 0x%x MI_INT %x, SERDES_LINK %x\n",
Eilon Greenstein2f904462009-08-12 08:22:16 +00006567 REG_RD(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4),
6568 is_mi_int,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006569 REG_RD(bp, NIG_REG_SERDES0_STATUS_LINK_STATUS + port*0x3c));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006570
6571 DP(NETIF_MSG_LINK, " 10G %x, XGXS_LINK %x\n",
6572 REG_RD(bp, NIG_REG_XGXS0_STATUS_LINK10G + port*0x68),
6573 REG_RD(bp, NIG_REG_XGXS0_STATUS_LINK_STATUS + port*0x68));
6574
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00006575 /* disable emac */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00006576 if (!CHIP_IS_E3(bp))
6577 REG_WR(bp, NIG_REG_NIG_EMAC0_EN + port*4, 0);
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00006578
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006579 /*
6580 * Step 1:
6581 * Check external link change only for external phys, and apply
6582 * priority selection between them in case the link on both phys
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00006583 * is up. Note that instead of the common vars, a temporary
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006584 * vars argument is used since each phy may have different link/
6585 * speed/duplex result
6586 */
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006587 for (phy_index = EXT_PHY1; phy_index < params->num_phys;
6588 phy_index++) {
6589 struct bnx2x_phy *phy = &params->phy[phy_index];
6590 if (!phy->read_status)
6591 continue;
6592 /* Read link status and params of this ext phy */
6593 cur_link_up = phy->read_status(phy, params,
6594 &phy_vars[phy_index]);
6595 if (cur_link_up) {
6596 DP(NETIF_MSG_LINK, "phy in index %d link is up\n",
6597 phy_index);
6598 } else {
6599 DP(NETIF_MSG_LINK, "phy in index %d link is down\n",
6600 phy_index);
6601 continue;
6602 }
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006603
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006604 if (!ext_phy_link_up) {
6605 ext_phy_link_up = 1;
6606 active_external_phy = phy_index;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006607 } else {
6608 switch (bnx2x_phy_selection(params)) {
6609 case PORT_HW_CFG_PHY_SELECTION_HARDWARE_DEFAULT:
6610 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY_PRIORITY:
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006611 /*
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006612 * In this option, the first PHY makes sure to pass the
6613 * traffic through itself only.
6614 * Its not clear how to reset the link on the second phy
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006615 */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006616 active_external_phy = EXT_PHY1;
6617 break;
6618 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY_PRIORITY:
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006619 /*
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006620 * In this option, the first PHY makes sure to pass the
6621 * traffic through the second PHY.
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006622 */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006623 active_external_phy = EXT_PHY2;
6624 break;
6625 default:
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006626 /*
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006627 * Link indication on both PHYs with the following cases
6628 * is invalid:
6629 * - FIRST_PHY means that second phy wasn't initialized,
6630 * hence its link is expected to be down
6631 * - SECOND_PHY means that first phy should not be able
6632 * to link up by itself (using configuration)
6633 * - DEFAULT should be overriden during initialiazation
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006634 */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006635 DP(NETIF_MSG_LINK, "Invalid link indication"
6636 "mpc=0x%x. DISABLING LINK !!!\n",
6637 params->multi_phy_config);
6638 ext_phy_link_up = 0;
6639 break;
6640 }
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006641 }
6642 }
6643 prev_line_speed = vars->line_speed;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006644 /*
6645 * Step 2:
6646 * Read the status of the internal phy. In case of
6647 * DIRECT_SINGLE_MEDIA board, this link is the external link,
6648 * otherwise this is the link between the 577xx and the first
6649 * external phy
6650 */
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006651 if (params->phy[INT_PHY].read_status)
6652 params->phy[INT_PHY].read_status(
6653 &params->phy[INT_PHY],
6654 params, vars);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006655 /*
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006656 * The INT_PHY flow control reside in the vars. This include the
6657 * case where the speed or flow control are not set to AUTO.
6658 * Otherwise, the active external phy flow control result is set
6659 * to the vars. The ext_phy_line_speed is needed to check if the
6660 * speed is different between the internal phy and external phy.
6661 * This case may be result of intermediate link speed change.
6662 */
6663 if (active_external_phy > INT_PHY) {
6664 vars->flow_ctrl = phy_vars[active_external_phy].flow_ctrl;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006665 /*
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006666 * Link speed is taken from the XGXS. AN and FC result from
6667 * the external phy.
6668 */
6669 vars->link_status |= phy_vars[active_external_phy].link_status;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006670
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006671 /*
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006672 * if active_external_phy is first PHY and link is up - disable
6673 * disable TX on second external PHY
6674 */
6675 if (active_external_phy == EXT_PHY1) {
6676 if (params->phy[EXT_PHY2].phy_specific_func) {
Joe Perches94f05b02011-08-14 12:16:20 +00006677 DP(NETIF_MSG_LINK,
6678 "Disabling TX on EXT_PHY2\n");
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006679 params->phy[EXT_PHY2].phy_specific_func(
6680 &params->phy[EXT_PHY2],
6681 params, DISABLE_TX);
6682 }
6683 }
6684
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006685 ext_phy_line_speed = phy_vars[active_external_phy].line_speed;
6686 vars->duplex = phy_vars[active_external_phy].duplex;
6687 if (params->phy[active_external_phy].supported &
6688 SUPPORTED_FIBRE)
6689 vars->link_status |= LINK_STATUS_SERDES_LINK;
Yaniv Rosnerfd36a2e2011-05-31 21:29:05 +00006690 else
6691 vars->link_status &= ~LINK_STATUS_SERDES_LINK;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006692 DP(NETIF_MSG_LINK, "Active external phy selected: %x\n",
6693 active_external_phy);
6694 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006695
6696 for (phy_index = EXT_PHY1; phy_index < params->num_phys;
6697 phy_index++) {
6698 if (params->phy[phy_index].flags &
6699 FLAGS_REARM_LATCH_SIGNAL) {
6700 bnx2x_rearm_latch_signal(bp, port,
6701 phy_index ==
6702 active_external_phy);
6703 break;
6704 }
6705 }
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006706 DP(NETIF_MSG_LINK, "vars->flow_ctrl = 0x%x, vars->link_status = 0x%x,"
6707 " ext_phy_line_speed = %d\n", vars->flow_ctrl,
6708 vars->link_status, ext_phy_line_speed);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006709 /*
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006710 * Upon link speed change set the NIG into drain mode. Comes to
6711 * deals with possible FIFO glitch due to clk change when speed
6712 * is decreased without link down indicator
6713 */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006714
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006715 if (vars->phy_link_up) {
6716 if (!(SINGLE_MEDIA_DIRECT(params)) && ext_phy_link_up &&
6717 (ext_phy_line_speed != vars->line_speed)) {
6718 DP(NETIF_MSG_LINK, "Internal link speed %d is"
6719 " different than the external"
6720 " link speed %d\n", vars->line_speed,
6721 ext_phy_line_speed);
6722 vars->phy_link_up = 0;
6723 } else if (prev_line_speed != vars->line_speed) {
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006724 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4,
6725 0);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006726 msleep(1);
6727 }
6728 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006729
6730 /* anything 10 and over uses the bmac */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006731 link_10g_plus = (vars->line_speed >= SPEED_10000);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006732
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006733 bnx2x_link_int_ack(params, vars, link_10g_plus);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006734
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006735 /*
6736 * In case external phy link is up, and internal link is down
6737 * (not initialized yet probably after link initialization, it
6738 * needs to be initialized.
6739 * Note that after link down-up as result of cable plug, the xgxs
6740 * link would probably become up again without the need
6741 * initialize it
6742 */
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006743 if (!(SINGLE_MEDIA_DIRECT(params))) {
6744 DP(NETIF_MSG_LINK, "ext_phy_link_up = %d, int_link_up = %d,"
6745 " init_preceding = %d\n", ext_phy_link_up,
6746 vars->phy_link_up,
6747 params->phy[EXT_PHY1].flags &
6748 FLAGS_INIT_XGXS_FIRST);
6749 if (!(params->phy[EXT_PHY1].flags &
6750 FLAGS_INIT_XGXS_FIRST)
6751 && ext_phy_link_up && !vars->phy_link_up) {
6752 vars->line_speed = ext_phy_line_speed;
6753 if (vars->line_speed < SPEED_1000)
6754 vars->phy_flags |= PHY_SGMII_FLAG;
6755 else
6756 vars->phy_flags &= ~PHY_SGMII_FLAG;
Yaniv Rosnerec146a62011-05-31 21:29:27 +00006757
6758 if (params->phy[INT_PHY].config_init)
6759 params->phy[INT_PHY].config_init(
6760 &params->phy[INT_PHY], params,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006761 vars);
6762 }
6763 }
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006764 /*
6765 * Link is up only if both local phy and external phy (in case of
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00006766 * non-direct board) are up and no fault detected on active PHY.
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006767 */
6768 vars->link_up = (vars->phy_link_up &&
6769 (ext_phy_link_up ||
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00006770 SINGLE_MEDIA_DIRECT(params)) &&
6771 (phy_vars[active_external_phy].fault_detected == 0));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006772
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006773 if (vars->link_up)
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006774 rc = bnx2x_update_link_up(params, vars, link_10g_plus);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006775 else
6776 rc = bnx2x_update_link_down(params, vars);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006777
6778 return rc;
6779}
6780
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006781
6782/*****************************************************************************/
6783/* External Phy section */
6784/*****************************************************************************/
6785void bnx2x_ext_phy_hw_reset(struct bnx2x *bp, u8 port)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006786{
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006787 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006788 MISC_REGISTERS_GPIO_OUTPUT_LOW, port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006789 msleep(1);
6790 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006791 MISC_REGISTERS_GPIO_OUTPUT_HIGH, port);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006792}
6793
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006794static void bnx2x_save_spirom_version(struct bnx2x *bp, u8 port,
6795 u32 spirom_ver, u32 ver_addr)
6796{
6797 DP(NETIF_MSG_LINK, "FW version 0x%x:0x%x for port %d\n",
6798 (u16)(spirom_ver>>16), (u16)spirom_ver, port);
6799
6800 if (ver_addr)
6801 REG_WR(bp, ver_addr, spirom_ver);
6802}
6803
6804static void bnx2x_save_bcm_spirom_ver(struct bnx2x *bp,
6805 struct bnx2x_phy *phy,
6806 u8 port)
6807{
6808 u16 fw_ver1, fw_ver2;
6809
6810 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006811 MDIO_PMA_REG_ROM_VER1, &fw_ver1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006812 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006813 MDIO_PMA_REG_ROM_VER2, &fw_ver2);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006814 bnx2x_save_spirom_version(bp, port, (u32)(fw_ver1<<16 | fw_ver2),
6815 phy->ver_addr);
6816}
6817
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006818static void bnx2x_ext_phy_10G_an_resolve(struct bnx2x *bp,
6819 struct bnx2x_phy *phy,
6820 struct link_vars *vars)
6821{
6822 u16 val;
6823 bnx2x_cl45_read(bp, phy,
6824 MDIO_AN_DEVAD,
6825 MDIO_AN_REG_STATUS, &val);
6826 bnx2x_cl45_read(bp, phy,
6827 MDIO_AN_DEVAD,
6828 MDIO_AN_REG_STATUS, &val);
6829 if (val & (1<<5))
6830 vars->link_status |= LINK_STATUS_AUTO_NEGOTIATE_COMPLETE;
6831 if ((val & (1<<0)) == 0)
6832 vars->link_status |= LINK_STATUS_PARALLEL_DETECTION_USED;
6833}
6834
6835/******************************************************************/
6836/* common BCM8073/BCM8727 PHY SECTION */
6837/******************************************************************/
6838static void bnx2x_8073_resolve_fc(struct bnx2x_phy *phy,
6839 struct link_params *params,
6840 struct link_vars *vars)
6841{
6842 struct bnx2x *bp = params->bp;
6843 if (phy->req_line_speed == SPEED_10 ||
6844 phy->req_line_speed == SPEED_100) {
6845 vars->flow_ctrl = phy->req_flow_ctrl;
6846 return;
6847 }
6848
6849 if (bnx2x_ext_phy_resolve_fc(phy, params, vars) &&
6850 (vars->flow_ctrl == BNX2X_FLOW_CTRL_NONE)) {
6851 u16 pause_result;
6852 u16 ld_pause; /* local */
6853 u16 lp_pause; /* link partner */
6854 bnx2x_cl45_read(bp, phy,
6855 MDIO_AN_DEVAD,
6856 MDIO_AN_REG_CL37_FC_LD, &ld_pause);
6857
6858 bnx2x_cl45_read(bp, phy,
6859 MDIO_AN_DEVAD,
6860 MDIO_AN_REG_CL37_FC_LP, &lp_pause);
6861 pause_result = (ld_pause &
6862 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) >> 5;
6863 pause_result |= (lp_pause &
6864 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) >> 7;
6865
6866 bnx2x_pause_resolve(vars, pause_result);
6867 DP(NETIF_MSG_LINK, "Ext PHY CL37 pause result 0x%x\n",
6868 pause_result);
6869 }
6870}
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006871static int bnx2x_8073_8727_external_rom_boot(struct bnx2x *bp,
6872 struct bnx2x_phy *phy,
6873 u8 port)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006874{
Yaniv Rosner5c99274b2011-01-18 04:33:36 +00006875 u32 count = 0;
6876 u16 fw_ver1, fw_msgout;
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006877 int rc = 0;
Yaniv Rosner5c99274b2011-01-18 04:33:36 +00006878
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006879 /* Boot port from external ROM */
6880 /* EDC grst */
6881 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006882 MDIO_PMA_DEVAD,
6883 MDIO_PMA_REG_GEN_CTRL,
6884 0x0001);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006885
6886 /* ucode reboot and rst */
6887 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006888 MDIO_PMA_DEVAD,
6889 MDIO_PMA_REG_GEN_CTRL,
6890 0x008c);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006891
6892 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006893 MDIO_PMA_DEVAD,
6894 MDIO_PMA_REG_MISC_CTRL1, 0x0001);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006895
6896 /* Reset internal microprocessor */
6897 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006898 MDIO_PMA_DEVAD,
6899 MDIO_PMA_REG_GEN_CTRL,
6900 MDIO_PMA_REG_GEN_CTRL_ROM_MICRO_RESET);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006901
6902 /* Release srst bit */
6903 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006904 MDIO_PMA_DEVAD,
6905 MDIO_PMA_REG_GEN_CTRL,
6906 MDIO_PMA_REG_GEN_CTRL_ROM_RESET_INTERNAL_MP);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006907
Yaniv Rosner5c99274b2011-01-18 04:33:36 +00006908 /* Delay 100ms per the PHY specifications */
6909 msleep(100);
6910
6911 /* 8073 sometimes taking longer to download */
6912 do {
6913 count++;
6914 if (count > 300) {
6915 DP(NETIF_MSG_LINK,
6916 "bnx2x_8073_8727_external_rom_boot port %x:"
6917 "Download failed. fw version = 0x%x\n",
6918 port, fw_ver1);
6919 rc = -EINVAL;
6920 break;
6921 }
6922
6923 bnx2x_cl45_read(bp, phy,
6924 MDIO_PMA_DEVAD,
6925 MDIO_PMA_REG_ROM_VER1, &fw_ver1);
6926 bnx2x_cl45_read(bp, phy,
6927 MDIO_PMA_DEVAD,
6928 MDIO_PMA_REG_M8051_MSGOUT_REG, &fw_msgout);
6929
6930 msleep(1);
6931 } while (fw_ver1 == 0 || fw_ver1 == 0x4321 ||
6932 ((fw_msgout & 0xff) != 0x03 && (phy->type ==
6933 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073)));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006934
6935 /* Clear ser_boot_ctl bit */
6936 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006937 MDIO_PMA_DEVAD,
6938 MDIO_PMA_REG_MISC_CTRL1, 0x0000);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006939 bnx2x_save_bcm_spirom_ver(bp, phy, port);
Yaniv Rosner5c99274b2011-01-18 04:33:36 +00006940
6941 DP(NETIF_MSG_LINK,
6942 "bnx2x_8073_8727_external_rom_boot port %x:"
6943 "Download complete. fw version = 0x%x\n",
6944 port, fw_ver1);
6945
6946 return rc;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006947}
6948
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006949/******************************************************************/
6950/* BCM8073 PHY SECTION */
6951/******************************************************************/
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006952static int bnx2x_8073_is_snr_needed(struct bnx2x *bp, struct bnx2x_phy *phy)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006953{
6954 /* This is only required for 8073A1, version 102 only */
6955 u16 val;
6956
6957 /* Read 8073 HW revision*/
6958 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006959 MDIO_PMA_DEVAD,
6960 MDIO_PMA_REG_8073_CHIP_REV, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006961
6962 if (val != 1) {
6963 /* No need to workaround in 8073 A1 */
6964 return 0;
6965 }
6966
6967 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006968 MDIO_PMA_DEVAD,
6969 MDIO_PMA_REG_ROM_VER2, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006970
6971 /* SNR should be applied only for version 0x102 */
6972 if (val != 0x102)
6973 return 0;
6974
6975 return 1;
6976}
6977
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006978static int bnx2x_8073_xaui_wa(struct bnx2x *bp, struct bnx2x_phy *phy)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006979{
6980 u16 val, cnt, cnt1 ;
6981
6982 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006983 MDIO_PMA_DEVAD,
6984 MDIO_PMA_REG_8073_CHIP_REV, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006985
6986 if (val > 0) {
6987 /* No need to workaround in 8073 A1 */
6988 return 0;
6989 }
6990 /* XAUI workaround in 8073 A0: */
6991
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006992 /*
6993 * After loading the boot ROM and restarting Autoneg, poll
6994 * Dev1, Reg $C820:
6995 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006996
6997 for (cnt = 0; cnt < 1000; cnt++) {
6998 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006999 MDIO_PMA_DEVAD,
7000 MDIO_PMA_REG_8073_SPEED_LINK_STATUS,
7001 &val);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007002 /*
7003 * If bit [14] = 0 or bit [13] = 0, continue on with
7004 * system initialization (XAUI work-around not required, as
7005 * these bits indicate 2.5G or 1G link up).
7006 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007007 if (!(val & (1<<14)) || !(val & (1<<13))) {
7008 DP(NETIF_MSG_LINK, "XAUI work-around not required\n");
7009 return 0;
7010 } else if (!(val & (1<<15))) {
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007011 DP(NETIF_MSG_LINK, "bit 15 went off\n");
7012 /*
7013 * If bit 15 is 0, then poll Dev1, Reg $C841 until it's
7014 * MSB (bit15) goes to 1 (indicating that the XAUI
7015 * workaround has completed), then continue on with
7016 * system initialization.
7017 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007018 for (cnt1 = 0; cnt1 < 1000; cnt1++) {
7019 bnx2x_cl45_read(bp, phy,
7020 MDIO_PMA_DEVAD,
7021 MDIO_PMA_REG_8073_XAUI_WA, &val);
7022 if (val & (1<<15)) {
7023 DP(NETIF_MSG_LINK,
7024 "XAUI workaround has completed\n");
7025 return 0;
7026 }
7027 msleep(3);
7028 }
7029 break;
7030 }
7031 msleep(3);
7032 }
7033 DP(NETIF_MSG_LINK, "Warning: XAUI work-around timeout !!!\n");
7034 return -EINVAL;
7035}
7036
7037static void bnx2x_807x_force_10G(struct bnx2x *bp, struct bnx2x_phy *phy)
7038{
7039 /* Force KR or KX */
7040 bnx2x_cl45_write(bp, phy,
7041 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x2040);
7042 bnx2x_cl45_write(bp, phy,
7043 MDIO_PMA_DEVAD, MDIO_PMA_REG_10G_CTRL2, 0x000b);
7044 bnx2x_cl45_write(bp, phy,
7045 MDIO_PMA_DEVAD, MDIO_PMA_REG_BCM_CTRL, 0x0000);
7046 bnx2x_cl45_write(bp, phy,
7047 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x0000);
7048}
7049
7050static void bnx2x_8073_set_pause_cl37(struct link_params *params,
7051 struct bnx2x_phy *phy,
7052 struct link_vars *vars)
7053{
7054 u16 cl37_val;
7055 struct bnx2x *bp = params->bp;
7056 bnx2x_cl45_read(bp, phy,
7057 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LD, &cl37_val);
7058
7059 cl37_val &= ~MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH;
7060 /* Please refer to Table 28B-3 of 802.3ab-1999 spec. */
7061 bnx2x_calc_ieee_aneg_adv(phy, params, &vars->ieee_fc);
7062 if ((vars->ieee_fc &
7063 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_SYMMETRIC) ==
7064 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_SYMMETRIC) {
7065 cl37_val |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_SYMMETRIC;
7066 }
7067 if ((vars->ieee_fc &
7068 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC) ==
7069 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC) {
7070 cl37_val |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC;
7071 }
7072 if ((vars->ieee_fc &
7073 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) ==
7074 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) {
7075 cl37_val |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH;
7076 }
7077 DP(NETIF_MSG_LINK,
7078 "Ext phy AN advertize cl37 0x%x\n", cl37_val);
7079
7080 bnx2x_cl45_write(bp, phy,
7081 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LD, cl37_val);
7082 msleep(500);
7083}
7084
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00007085static int bnx2x_8073_config_init(struct bnx2x_phy *phy,
7086 struct link_params *params,
7087 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007088{
7089 struct bnx2x *bp = params->bp;
7090 u16 val = 0, tmp1;
7091 u8 gpio_port;
7092 DP(NETIF_MSG_LINK, "Init 8073\n");
7093
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007094 if (CHIP_IS_E2(bp))
7095 gpio_port = BP_PATH(bp);
7096 else
7097 gpio_port = params->port;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007098 /* Restore normal power mode*/
7099 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007100 MISC_REGISTERS_GPIO_OUTPUT_HIGH, gpio_port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007101
7102 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007103 MISC_REGISTERS_GPIO_OUTPUT_HIGH, gpio_port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007104
7105 /* enable LASI */
7106 bnx2x_cl45_write(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00007107 MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXCTRL, (1<<2));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007108 bnx2x_cl45_write(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00007109 MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL, 0x0004);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007110
7111 bnx2x_8073_set_pause_cl37(params, phy, vars);
7112
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007113 bnx2x_cl45_read(bp, phy,
7114 MDIO_PMA_DEVAD, MDIO_PMA_REG_M8051_MSGOUT_REG, &tmp1);
7115
7116 bnx2x_cl45_read(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00007117 MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXSTAT, &tmp1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007118
7119 DP(NETIF_MSG_LINK, "Before rom RX_ALARM(port1): 0x%x\n", tmp1);
7120
Yaniv Rosner74d7a112011-01-18 04:33:18 +00007121 /* Swap polarity if required - Must be done only in non-1G mode */
7122 if (params->lane_config & PORT_HW_CFG_SWAP_PHY_POLARITY_ENABLED) {
7123 /* Configure the 8073 to swap _P and _N of the KR lines */
7124 DP(NETIF_MSG_LINK, "Swapping polarity for the 8073\n");
7125 /* 10G Rx/Tx and 1G Tx signal polarity swap */
7126 bnx2x_cl45_read(bp, phy,
7127 MDIO_PMA_DEVAD,
7128 MDIO_PMA_REG_8073_OPT_DIGITAL_CTRL, &val);
7129 bnx2x_cl45_write(bp, phy,
7130 MDIO_PMA_DEVAD,
7131 MDIO_PMA_REG_8073_OPT_DIGITAL_CTRL,
7132 (val | (3<<9)));
7133 }
7134
7135
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007136 /* Enable CL37 BAM */
Yaniv Rosner121839b2010-11-01 05:32:38 +00007137 if (REG_RD(bp, params->shmem_base +
7138 offsetof(struct shmem_region, dev_info.
7139 port_hw_config[params->port].default_cfg)) &
7140 PORT_HW_CFG_ENABLE_BAM_ON_KR_ENABLED) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007141
Yaniv Rosner121839b2010-11-01 05:32:38 +00007142 bnx2x_cl45_read(bp, phy,
7143 MDIO_AN_DEVAD,
7144 MDIO_AN_REG_8073_BAM, &val);
7145 bnx2x_cl45_write(bp, phy,
7146 MDIO_AN_DEVAD,
7147 MDIO_AN_REG_8073_BAM, val | 1);
7148 DP(NETIF_MSG_LINK, "Enable CL37 BAM on KR\n");
7149 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007150 if (params->loopback_mode == LOOPBACK_EXT) {
7151 bnx2x_807x_force_10G(bp, phy);
7152 DP(NETIF_MSG_LINK, "Forced speed 10G on 807X\n");
7153 return 0;
7154 } else {
7155 bnx2x_cl45_write(bp, phy,
7156 MDIO_PMA_DEVAD, MDIO_PMA_REG_BCM_CTRL, 0x0002);
7157 }
7158 if (phy->req_line_speed != SPEED_AUTO_NEG) {
7159 if (phy->req_line_speed == SPEED_10000) {
7160 val = (1<<7);
7161 } else if (phy->req_line_speed == SPEED_2500) {
7162 val = (1<<5);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007163 /*
7164 * Note that 2.5G works only when used with 1G
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007165 * advertisement
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007166 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007167 } else
7168 val = (1<<5);
7169 } else {
7170 val = 0;
7171 if (phy->speed_cap_mask &
7172 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
7173 val |= (1<<7);
7174
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007175 /* Note that 2.5G works only when used with 1G advertisement */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007176 if (phy->speed_cap_mask &
7177 (PORT_HW_CFG_SPEED_CAPABILITY_D0_1G |
7178 PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
7179 val |= (1<<5);
7180 DP(NETIF_MSG_LINK, "807x autoneg val = 0x%x\n", val);
7181 }
7182
7183 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV, val);
7184 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_8073_2_5G, &tmp1);
7185
7186 if (((phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G) &&
7187 (phy->req_line_speed == SPEED_AUTO_NEG)) ||
7188 (phy->req_line_speed == SPEED_2500)) {
7189 u16 phy_ver;
7190 /* Allow 2.5G for A1 and above */
7191 bnx2x_cl45_read(bp, phy,
7192 MDIO_PMA_DEVAD, MDIO_PMA_REG_8073_CHIP_REV,
7193 &phy_ver);
7194 DP(NETIF_MSG_LINK, "Add 2.5G\n");
7195 if (phy_ver > 0)
7196 tmp1 |= 1;
7197 else
7198 tmp1 &= 0xfffe;
7199 } else {
7200 DP(NETIF_MSG_LINK, "Disable 2.5G\n");
7201 tmp1 &= 0xfffe;
7202 }
7203
7204 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_8073_2_5G, tmp1);
7205 /* Add support for CL37 (passive mode) II */
7206
7207 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LD, &tmp1);
7208 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LD,
7209 (tmp1 | ((phy->req_duplex == DUPLEX_FULL) ?
7210 0x20 : 0x40)));
7211
7212 /* Add support for CL37 (passive mode) III */
7213 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CL37_AN, 0x1000);
7214
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007215 /*
7216 * The SNR will improve about 2db by changing BW and FEE main
7217 * tap. Rest commands are executed after link is up
7218 * Change FFE main cursor to 5 in EDC register
7219 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007220 if (bnx2x_8073_is_snr_needed(bp, phy))
7221 bnx2x_cl45_write(bp, phy,
7222 MDIO_PMA_DEVAD, MDIO_PMA_REG_EDC_FFE_MAIN,
7223 0xFB0C);
7224
7225 /* Enable FEC (Forware Error Correction) Request in the AN */
7226 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV2, &tmp1);
7227 tmp1 |= (1<<15);
7228 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV2, tmp1);
7229
7230 bnx2x_ext_phy_set_pause(params, phy, vars);
7231
7232 /* Restart autoneg */
7233 msleep(500);
7234 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x1200);
7235 DP(NETIF_MSG_LINK, "807x Autoneg Restart: Advertise 1G=%x, 10G=%x\n",
7236 ((val & (1<<5)) > 0), ((val & (1<<7)) > 0));
7237 return 0;
7238}
7239
7240static u8 bnx2x_8073_read_status(struct bnx2x_phy *phy,
7241 struct link_params *params,
7242 struct link_vars *vars)
7243{
7244 struct bnx2x *bp = params->bp;
7245 u8 link_up = 0;
7246 u16 val1, val2;
7247 u16 link_status = 0;
7248 u16 an1000_status = 0;
7249
7250 bnx2x_cl45_read(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00007251 MDIO_PMA_DEVAD, MDIO_PMA_LASI_STAT, &val1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007252
7253 DP(NETIF_MSG_LINK, "8703 LASI status 0x%x\n", val1);
7254
7255 /* clear the interrupt LASI status register */
7256 bnx2x_cl45_read(bp, phy,
7257 MDIO_PCS_DEVAD, MDIO_PCS_REG_STATUS, &val2);
7258 bnx2x_cl45_read(bp, phy,
7259 MDIO_PCS_DEVAD, MDIO_PCS_REG_STATUS, &val1);
7260 DP(NETIF_MSG_LINK, "807x PCS status 0x%x->0x%x\n", val2, val1);
7261 /* Clear MSG-OUT */
7262 bnx2x_cl45_read(bp, phy,
7263 MDIO_PMA_DEVAD, MDIO_PMA_REG_M8051_MSGOUT_REG, &val1);
7264
7265 /* Check the LASI */
7266 bnx2x_cl45_read(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00007267 MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXSTAT, &val2);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007268
7269 DP(NETIF_MSG_LINK, "KR 0x9003 0x%x\n", val2);
7270
7271 /* Check the link status */
7272 bnx2x_cl45_read(bp, phy,
7273 MDIO_PCS_DEVAD, MDIO_PCS_REG_STATUS, &val2);
7274 DP(NETIF_MSG_LINK, "KR PCS status 0x%x\n", val2);
7275
7276 bnx2x_cl45_read(bp, phy,
7277 MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val2);
7278 bnx2x_cl45_read(bp, phy,
7279 MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val1);
7280 link_up = ((val1 & 4) == 4);
7281 DP(NETIF_MSG_LINK, "PMA_REG_STATUS=0x%x\n", val1);
7282
7283 if (link_up &&
7284 ((phy->req_line_speed != SPEED_10000))) {
7285 if (bnx2x_8073_xaui_wa(bp, phy) != 0)
7286 return 0;
7287 }
7288 bnx2x_cl45_read(bp, phy,
7289 MDIO_AN_DEVAD, MDIO_AN_REG_LINK_STATUS, &an1000_status);
7290 bnx2x_cl45_read(bp, phy,
7291 MDIO_AN_DEVAD, MDIO_AN_REG_LINK_STATUS, &an1000_status);
7292
7293 /* Check the link status on 1.1.2 */
7294 bnx2x_cl45_read(bp, phy,
7295 MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val2);
7296 bnx2x_cl45_read(bp, phy,
7297 MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val1);
7298 DP(NETIF_MSG_LINK, "KR PMA status 0x%x->0x%x,"
7299 "an_link_status=0x%x\n", val2, val1, an1000_status);
7300
7301 link_up = (((val1 & 4) == 4) || (an1000_status & (1<<1)));
7302 if (link_up && bnx2x_8073_is_snr_needed(bp, phy)) {
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007303 /*
7304 * The SNR will improve about 2dbby changing the BW and FEE main
7305 * tap. The 1st write to change FFE main tap is set before
7306 * restart AN. Change PLL Bandwidth in EDC register
7307 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007308 bnx2x_cl45_write(bp, phy,
7309 MDIO_PMA_DEVAD, MDIO_PMA_REG_PLL_BANDWIDTH,
7310 0x26BC);
7311
7312 /* Change CDR Bandwidth in EDC register */
7313 bnx2x_cl45_write(bp, phy,
7314 MDIO_PMA_DEVAD, MDIO_PMA_REG_CDR_BANDWIDTH,
7315 0x0333);
7316 }
7317 bnx2x_cl45_read(bp, phy,
7318 MDIO_PMA_DEVAD, MDIO_PMA_REG_8073_SPEED_LINK_STATUS,
7319 &link_status);
7320
7321 /* Bits 0..2 --> speed detected, bits 13..15--> link is down */
7322 if ((link_status & (1<<2)) && (!(link_status & (1<<15)))) {
7323 link_up = 1;
7324 vars->line_speed = SPEED_10000;
7325 DP(NETIF_MSG_LINK, "port %x: External link up in 10G\n",
7326 params->port);
7327 } else if ((link_status & (1<<1)) && (!(link_status & (1<<14)))) {
7328 link_up = 1;
7329 vars->line_speed = SPEED_2500;
7330 DP(NETIF_MSG_LINK, "port %x: External link up in 2.5G\n",
7331 params->port);
7332 } else if ((link_status & (1<<0)) && (!(link_status & (1<<13)))) {
7333 link_up = 1;
7334 vars->line_speed = SPEED_1000;
7335 DP(NETIF_MSG_LINK, "port %x: External link up in 1G\n",
7336 params->port);
7337 } else {
7338 link_up = 0;
7339 DP(NETIF_MSG_LINK, "port %x: External link is down\n",
7340 params->port);
7341 }
7342
7343 if (link_up) {
Yaniv Rosner74d7a112011-01-18 04:33:18 +00007344 /* Swap polarity if required */
7345 if (params->lane_config &
7346 PORT_HW_CFG_SWAP_PHY_POLARITY_ENABLED) {
7347 /* Configure the 8073 to swap P and N of the KR lines */
7348 bnx2x_cl45_read(bp, phy,
7349 MDIO_XS_DEVAD,
7350 MDIO_XS_REG_8073_RX_CTRL_PCIE, &val1);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007351 /*
7352 * Set bit 3 to invert Rx in 1G mode and clear this bit
7353 * when it`s in 10G mode.
7354 */
Yaniv Rosner74d7a112011-01-18 04:33:18 +00007355 if (vars->line_speed == SPEED_1000) {
7356 DP(NETIF_MSG_LINK, "Swapping 1G polarity for"
7357 "the 8073\n");
7358 val1 |= (1<<3);
7359 } else
7360 val1 &= ~(1<<3);
7361
7362 bnx2x_cl45_write(bp, phy,
7363 MDIO_XS_DEVAD,
7364 MDIO_XS_REG_8073_RX_CTRL_PCIE,
7365 val1);
7366 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007367 bnx2x_ext_phy_10G_an_resolve(bp, phy, vars);
7368 bnx2x_8073_resolve_fc(phy, params, vars);
Yaniv Rosner791f18c2011-01-18 04:33:42 +00007369 vars->duplex = DUPLEX_FULL;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007370 }
7371 return link_up;
7372}
7373
7374static void bnx2x_8073_link_reset(struct bnx2x_phy *phy,
7375 struct link_params *params)
7376{
7377 struct bnx2x *bp = params->bp;
7378 u8 gpio_port;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007379 if (CHIP_IS_E2(bp))
7380 gpio_port = BP_PATH(bp);
7381 else
7382 gpio_port = params->port;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007383 DP(NETIF_MSG_LINK, "Setting 8073 port %d into low power mode\n",
7384 gpio_port);
7385 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007386 MISC_REGISTERS_GPIO_OUTPUT_LOW,
7387 gpio_port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007388}
7389
7390/******************************************************************/
7391/* BCM8705 PHY SECTION */
7392/******************************************************************/
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00007393static int bnx2x_8705_config_init(struct bnx2x_phy *phy,
7394 struct link_params *params,
7395 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007396{
7397 struct bnx2x *bp = params->bp;
7398 DP(NETIF_MSG_LINK, "init 8705\n");
7399 /* Restore normal power mode*/
7400 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007401 MISC_REGISTERS_GPIO_OUTPUT_HIGH, params->port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007402 /* HW reset */
7403 bnx2x_ext_phy_hw_reset(bp, params->port);
7404 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0xa040);
Yaniv Rosner6d870c32011-01-31 04:22:20 +00007405 bnx2x_wait_reset_complete(bp, phy, params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007406
7407 bnx2x_cl45_write(bp, phy,
7408 MDIO_PMA_DEVAD, MDIO_PMA_REG_MISC_CTRL, 0x8288);
7409 bnx2x_cl45_write(bp, phy,
7410 MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER, 0x7fbf);
7411 bnx2x_cl45_write(bp, phy,
7412 MDIO_PMA_DEVAD, MDIO_PMA_REG_CMU_PLL_BYPASS, 0x0100);
7413 bnx2x_cl45_write(bp, phy,
7414 MDIO_WIS_DEVAD, MDIO_WIS_REG_LASI_CNTL, 0x1);
7415 /* BCM8705 doesn't have microcode, hence the 0 */
7416 bnx2x_save_spirom_version(bp, params->port, params->shmem_base, 0);
7417 return 0;
7418}
7419
7420static u8 bnx2x_8705_read_status(struct bnx2x_phy *phy,
7421 struct link_params *params,
7422 struct link_vars *vars)
7423{
7424 u8 link_up = 0;
7425 u16 val1, rx_sd;
7426 struct bnx2x *bp = params->bp;
7427 DP(NETIF_MSG_LINK, "read status 8705\n");
7428 bnx2x_cl45_read(bp, phy,
7429 MDIO_WIS_DEVAD, MDIO_WIS_REG_LASI_STATUS, &val1);
7430 DP(NETIF_MSG_LINK, "8705 LASI status 0x%x\n", val1);
7431
7432 bnx2x_cl45_read(bp, phy,
7433 MDIO_WIS_DEVAD, MDIO_WIS_REG_LASI_STATUS, &val1);
7434 DP(NETIF_MSG_LINK, "8705 LASI status 0x%x\n", val1);
7435
7436 bnx2x_cl45_read(bp, phy,
7437 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_SD, &rx_sd);
7438
7439 bnx2x_cl45_read(bp, phy,
7440 MDIO_PMA_DEVAD, 0xc809, &val1);
7441 bnx2x_cl45_read(bp, phy,
7442 MDIO_PMA_DEVAD, 0xc809, &val1);
7443
7444 DP(NETIF_MSG_LINK, "8705 1.c809 val=0x%x\n", val1);
7445 link_up = ((rx_sd & 0x1) && (val1 & (1<<9)) && ((val1 & (1<<8)) == 0));
7446 if (link_up) {
7447 vars->line_speed = SPEED_10000;
7448 bnx2x_ext_phy_resolve_fc(phy, params, vars);
7449 }
7450 return link_up;
7451}
7452
7453/******************************************************************/
7454/* SFP+ module Section */
7455/******************************************************************/
Yaniv Rosner85242ee2011-07-05 01:06:53 +00007456static void bnx2x_set_disable_pmd_transmit(struct link_params *params,
7457 struct bnx2x_phy *phy,
7458 u8 pmd_dis)
7459{
7460 struct bnx2x *bp = params->bp;
7461 /*
7462 * Disable transmitter only for bootcodes which can enable it afterwards
7463 * (for D3 link)
7464 */
7465 if (pmd_dis) {
7466 if (params->feature_config_flags &
7467 FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED)
7468 DP(NETIF_MSG_LINK, "Disabling PMD transmitter\n");
7469 else {
7470 DP(NETIF_MSG_LINK, "NOT disabling PMD transmitter\n");
7471 return;
7472 }
7473 } else
7474 DP(NETIF_MSG_LINK, "Enabling PMD transmitter\n");
7475 bnx2x_cl45_write(bp, phy,
7476 MDIO_PMA_DEVAD,
7477 MDIO_PMA_REG_TX_DISABLE, pmd_dis);
7478}
7479
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00007480static u8 bnx2x_get_gpio_port(struct link_params *params)
7481{
7482 u8 gpio_port;
7483 u32 swap_val, swap_override;
7484 struct bnx2x *bp = params->bp;
7485 if (CHIP_IS_E2(bp))
7486 gpio_port = BP_PATH(bp);
7487 else
7488 gpio_port = params->port;
7489 swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
7490 swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
7491 return gpio_port ^ (swap_val && swap_override);
7492}
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00007493
7494static void bnx2x_sfp_e1e2_set_transmitter(struct link_params *params,
7495 struct bnx2x_phy *phy,
7496 u8 tx_en)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007497{
7498 u16 val;
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00007499 u8 port = params->port;
7500 struct bnx2x *bp = params->bp;
7501 u32 tx_en_mode;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007502
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007503 /* Disable/Enable transmitter ( TX laser of the SFP+ module.)*/
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00007504 tx_en_mode = REG_RD(bp, params->shmem_base +
7505 offsetof(struct shmem_region,
7506 dev_info.port_hw_config[port].sfp_ctrl)) &
7507 PORT_HW_CFG_TX_LASER_MASK;
7508 DP(NETIF_MSG_LINK, "Setting transmitter tx_en=%x for port %x "
7509 "mode = %x\n", tx_en, port, tx_en_mode);
7510 switch (tx_en_mode) {
7511 case PORT_HW_CFG_TX_LASER_MDIO:
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007512
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00007513 bnx2x_cl45_read(bp, phy,
7514 MDIO_PMA_DEVAD,
7515 MDIO_PMA_REG_PHY_IDENTIFIER,
7516 &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007517
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00007518 if (tx_en)
7519 val &= ~(1<<15);
7520 else
7521 val |= (1<<15);
7522
7523 bnx2x_cl45_write(bp, phy,
7524 MDIO_PMA_DEVAD,
7525 MDIO_PMA_REG_PHY_IDENTIFIER,
7526 val);
7527 break;
7528 case PORT_HW_CFG_TX_LASER_GPIO0:
7529 case PORT_HW_CFG_TX_LASER_GPIO1:
7530 case PORT_HW_CFG_TX_LASER_GPIO2:
7531 case PORT_HW_CFG_TX_LASER_GPIO3:
7532 {
7533 u16 gpio_pin;
7534 u8 gpio_port, gpio_mode;
7535 if (tx_en)
7536 gpio_mode = MISC_REGISTERS_GPIO_OUTPUT_HIGH;
7537 else
7538 gpio_mode = MISC_REGISTERS_GPIO_OUTPUT_LOW;
7539
7540 gpio_pin = tx_en_mode - PORT_HW_CFG_TX_LASER_GPIO0;
7541 gpio_port = bnx2x_get_gpio_port(params);
7542 bnx2x_set_gpio(bp, gpio_pin, gpio_mode, gpio_port);
7543 break;
7544 }
7545 default:
7546 DP(NETIF_MSG_LINK, "Invalid TX_LASER_MDIO 0x%x\n", tx_en_mode);
7547 break;
7548 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007549}
7550
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00007551static void bnx2x_sfp_set_transmitter(struct link_params *params,
7552 struct bnx2x_phy *phy,
7553 u8 tx_en)
7554{
7555 struct bnx2x *bp = params->bp;
7556 DP(NETIF_MSG_LINK, "Setting SFP+ transmitter to %d\n", tx_en);
7557 if (CHIP_IS_E3(bp))
7558 bnx2x_sfp_e3_set_transmitter(params, phy, tx_en);
7559 else
7560 bnx2x_sfp_e1e2_set_transmitter(params, phy, tx_en);
7561}
7562
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00007563static int bnx2x_8726_read_sfp_module_eeprom(struct bnx2x_phy *phy,
7564 struct link_params *params,
7565 u16 addr, u8 byte_cnt, u8 *o_buf)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007566{
7567 struct bnx2x *bp = params->bp;
7568 u16 val = 0;
7569 u16 i;
7570 if (byte_cnt > 16) {
Joe Perches94f05b02011-08-14 12:16:20 +00007571 DP(NETIF_MSG_LINK,
7572 "Reading from eeprom is limited to 0xf\n");
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007573 return -EINVAL;
7574 }
7575 /* Set the read command byte count */
7576 bnx2x_cl45_write(bp, phy,
7577 MDIO_PMA_DEVAD, MDIO_PMA_REG_SFP_TWO_WIRE_BYTE_CNT,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007578 (byte_cnt | 0xa000));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007579
7580 /* Set the read command address */
7581 bnx2x_cl45_write(bp, phy,
7582 MDIO_PMA_DEVAD, MDIO_PMA_REG_SFP_TWO_WIRE_MEM_ADDR,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007583 addr);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007584
7585 /* Activate read command */
7586 bnx2x_cl45_write(bp, phy,
7587 MDIO_PMA_DEVAD, MDIO_PMA_REG_SFP_TWO_WIRE_CTRL,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007588 0x2c0f);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007589
7590 /* Wait up to 500us for command complete status */
7591 for (i = 0; i < 100; i++) {
7592 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007593 MDIO_PMA_DEVAD,
7594 MDIO_PMA_REG_SFP_TWO_WIRE_CTRL, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007595 if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) ==
7596 MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_COMPLETE)
7597 break;
7598 udelay(5);
7599 }
7600
7601 if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) !=
7602 MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_COMPLETE) {
7603 DP(NETIF_MSG_LINK,
7604 "Got bad status 0x%x when reading from SFP+ EEPROM\n",
7605 (val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK));
7606 return -EINVAL;
7607 }
7608
7609 /* Read the buffer */
7610 for (i = 0; i < byte_cnt; i++) {
7611 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007612 MDIO_PMA_DEVAD,
7613 MDIO_PMA_REG_8726_TWO_WIRE_DATA_BUF + i, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007614 o_buf[i] = (u8)(val & MDIO_PMA_REG_8726_TWO_WIRE_DATA_MASK);
7615 }
7616
7617 for (i = 0; i < 100; i++) {
7618 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007619 MDIO_PMA_DEVAD,
7620 MDIO_PMA_REG_SFP_TWO_WIRE_CTRL, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007621 if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) ==
7622 MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_IDLE)
Joe Perches6f38ad92010-11-14 17:04:31 +00007623 return 0;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007624 msleep(1);
7625 }
7626 return -EINVAL;
7627}
7628
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00007629static int bnx2x_warpcore_read_sfp_module_eeprom(struct bnx2x_phy *phy,
7630 struct link_params *params,
7631 u16 addr, u8 byte_cnt,
7632 u8 *o_buf)
7633{
7634 int rc = 0;
7635 u8 i, j = 0, cnt = 0;
7636 u32 data_array[4];
7637 u16 addr32;
7638 struct bnx2x *bp = params->bp;
7639 /*DP(NETIF_MSG_LINK, "bnx2x_direct_read_sfp_module_eeprom:"
7640 " addr %d, cnt %d\n",
7641 addr, byte_cnt);*/
7642 if (byte_cnt > 16) {
Joe Perches94f05b02011-08-14 12:16:20 +00007643 DP(NETIF_MSG_LINK,
7644 "Reading from eeprom is limited to 16 bytes\n");
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00007645 return -EINVAL;
7646 }
7647
7648 /* 4 byte aligned address */
7649 addr32 = addr & (~0x3);
7650 do {
7651 rc = bnx2x_bsc_read(params, phy, 0xa0, addr32, 0, byte_cnt,
7652 data_array);
7653 } while ((rc != 0) && (++cnt < I2C_WA_RETRY_CNT));
7654
7655 if (rc == 0) {
7656 for (i = (addr - addr32); i < byte_cnt + (addr - addr32); i++) {
7657 o_buf[j] = *((u8 *)data_array + i);
7658 j++;
7659 }
7660 }
7661
7662 return rc;
7663}
7664
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00007665static int bnx2x_8727_read_sfp_module_eeprom(struct bnx2x_phy *phy,
7666 struct link_params *params,
7667 u16 addr, u8 byte_cnt, u8 *o_buf)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007668{
7669 struct bnx2x *bp = params->bp;
7670 u16 val, i;
7671
7672 if (byte_cnt > 16) {
Joe Perches94f05b02011-08-14 12:16:20 +00007673 DP(NETIF_MSG_LINK,
7674 "Reading from eeprom is limited to 0xf\n");
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007675 return -EINVAL;
7676 }
7677
7678 /* Need to read from 1.8000 to clear it */
7679 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007680 MDIO_PMA_DEVAD,
7681 MDIO_PMA_REG_SFP_TWO_WIRE_CTRL,
7682 &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007683
7684 /* Set the read command byte count */
7685 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007686 MDIO_PMA_DEVAD,
7687 MDIO_PMA_REG_SFP_TWO_WIRE_BYTE_CNT,
7688 ((byte_cnt < 2) ? 2 : byte_cnt));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007689
7690 /* Set the read command address */
7691 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007692 MDIO_PMA_DEVAD,
7693 MDIO_PMA_REG_SFP_TWO_WIRE_MEM_ADDR,
7694 addr);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007695 /* Set the destination address */
7696 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007697 MDIO_PMA_DEVAD,
7698 0x8004,
7699 MDIO_PMA_REG_8727_TWO_WIRE_DATA_BUF);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007700
7701 /* Activate read command */
7702 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007703 MDIO_PMA_DEVAD,
7704 MDIO_PMA_REG_SFP_TWO_WIRE_CTRL,
7705 0x8002);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007706 /*
7707 * Wait appropriate time for two-wire command to finish before
7708 * polling the status register
7709 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007710 msleep(1);
7711
7712 /* Wait up to 500us for command complete status */
7713 for (i = 0; i < 100; i++) {
7714 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007715 MDIO_PMA_DEVAD,
7716 MDIO_PMA_REG_SFP_TWO_WIRE_CTRL, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007717 if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) ==
7718 MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_COMPLETE)
7719 break;
7720 udelay(5);
7721 }
7722
7723 if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) !=
7724 MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_COMPLETE) {
7725 DP(NETIF_MSG_LINK,
7726 "Got bad status 0x%x when reading from SFP+ EEPROM\n",
7727 (val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK));
Yaniv Rosner65a001b2011-01-31 04:22:03 +00007728 return -EFAULT;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007729 }
7730
7731 /* Read the buffer */
7732 for (i = 0; i < byte_cnt; i++) {
7733 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007734 MDIO_PMA_DEVAD,
7735 MDIO_PMA_REG_8727_TWO_WIRE_DATA_BUF + i, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007736 o_buf[i] = (u8)(val & MDIO_PMA_REG_8727_TWO_WIRE_DATA_MASK);
7737 }
7738
7739 for (i = 0; i < 100; i++) {
7740 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007741 MDIO_PMA_DEVAD,
7742 MDIO_PMA_REG_SFP_TWO_WIRE_CTRL, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007743 if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) ==
7744 MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_IDLE)
Joe Perches6f38ad92010-11-14 17:04:31 +00007745 return 0;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007746 msleep(1);
7747 }
7748
7749 return -EINVAL;
7750}
7751
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00007752int bnx2x_read_sfp_module_eeprom(struct bnx2x_phy *phy,
7753 struct link_params *params, u16 addr,
7754 u8 byte_cnt, u8 *o_buf)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007755{
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00007756 int rc = -EINVAL;
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00007757 switch (phy->type) {
7758 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
7759 rc = bnx2x_8726_read_sfp_module_eeprom(phy, params, addr,
7760 byte_cnt, o_buf);
7761 break;
7762 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
7763 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8722:
7764 rc = bnx2x_8727_read_sfp_module_eeprom(phy, params, addr,
7765 byte_cnt, o_buf);
7766 break;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00007767 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT:
7768 rc = bnx2x_warpcore_read_sfp_module_eeprom(phy, params, addr,
7769 byte_cnt, o_buf);
7770 break;
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00007771 }
7772 return rc;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007773}
7774
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00007775static int bnx2x_get_edc_mode(struct bnx2x_phy *phy,
7776 struct link_params *params,
7777 u16 *edc_mode)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007778{
7779 struct bnx2x *bp = params->bp;
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00007780 u32 sync_offset = 0, phy_idx, media_types;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007781 u8 val, check_limiting_mode = 0;
7782 *edc_mode = EDC_MODE_LIMITING;
7783
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00007784 phy->media_type = ETH_PHY_UNSPECIFIED;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007785 /* First check for copper cable */
7786 if (bnx2x_read_sfp_module_eeprom(phy,
7787 params,
7788 SFP_EEPROM_CON_TYPE_ADDR,
7789 1,
7790 &val) != 0) {
7791 DP(NETIF_MSG_LINK, "Failed to read from SFP+ module EEPROM\n");
7792 return -EINVAL;
7793 }
7794
7795 switch (val) {
7796 case SFP_EEPROM_CON_TYPE_VAL_COPPER:
7797 {
7798 u8 copper_module_type;
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00007799 phy->media_type = ETH_PHY_DA_TWINAX;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007800 /*
7801 * Check if its active cable (includes SFP+ module)
7802 * of passive cable
7803 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007804 if (bnx2x_read_sfp_module_eeprom(phy,
7805 params,
7806 SFP_EEPROM_FC_TX_TECH_ADDR,
7807 1,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00007808 &copper_module_type) != 0) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007809 DP(NETIF_MSG_LINK,
7810 "Failed to read copper-cable-type"
7811 " from SFP+ EEPROM\n");
7812 return -EINVAL;
7813 }
7814
7815 if (copper_module_type &
7816 SFP_EEPROM_FC_TX_TECH_BITMASK_COPPER_ACTIVE) {
7817 DP(NETIF_MSG_LINK, "Active Copper cable detected\n");
7818 check_limiting_mode = 1;
7819 } else if (copper_module_type &
7820 SFP_EEPROM_FC_TX_TECH_BITMASK_COPPER_PASSIVE) {
Joe Perches94f05b02011-08-14 12:16:20 +00007821 DP(NETIF_MSG_LINK,
7822 "Passive Copper cable detected\n");
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007823 *edc_mode =
7824 EDC_MODE_PASSIVE_DAC;
7825 } else {
Joe Perches94f05b02011-08-14 12:16:20 +00007826 DP(NETIF_MSG_LINK,
7827 "Unknown copper-cable-type 0x%x !!!\n",
7828 copper_module_type);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007829 return -EINVAL;
7830 }
7831 break;
7832 }
7833 case SFP_EEPROM_CON_TYPE_VAL_LC:
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00007834 phy->media_type = ETH_PHY_SFP_FIBER;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007835 DP(NETIF_MSG_LINK, "Optic module detected\n");
7836 check_limiting_mode = 1;
7837 break;
7838 default:
7839 DP(NETIF_MSG_LINK, "Unable to determine module type 0x%x !!!\n",
7840 val);
7841 return -EINVAL;
7842 }
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00007843 sync_offset = params->shmem_base +
7844 offsetof(struct shmem_region,
7845 dev_info.port_hw_config[params->port].media_type);
7846 media_types = REG_RD(bp, sync_offset);
7847 /* Update media type for non-PMF sync */
7848 for (phy_idx = INT_PHY; phy_idx < MAX_PHYS; phy_idx++) {
7849 if (&(params->phy[phy_idx]) == phy) {
7850 media_types &= ~(PORT_HW_CFG_MEDIA_TYPE_PHY0_MASK <<
7851 (PORT_HW_CFG_MEDIA_TYPE_PHY1_SHIFT * phy_idx));
7852 media_types |= ((phy->media_type &
7853 PORT_HW_CFG_MEDIA_TYPE_PHY0_MASK) <<
7854 (PORT_HW_CFG_MEDIA_TYPE_PHY1_SHIFT * phy_idx));
7855 break;
7856 }
7857 }
7858 REG_WR(bp, sync_offset, media_types);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007859 if (check_limiting_mode) {
7860 u8 options[SFP_EEPROM_OPTIONS_SIZE];
7861 if (bnx2x_read_sfp_module_eeprom(phy,
7862 params,
7863 SFP_EEPROM_OPTIONS_ADDR,
7864 SFP_EEPROM_OPTIONS_SIZE,
7865 options) != 0) {
Joe Perches94f05b02011-08-14 12:16:20 +00007866 DP(NETIF_MSG_LINK,
7867 "Failed to read Option field from module EEPROM\n");
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007868 return -EINVAL;
7869 }
7870 if ((options[0] & SFP_EEPROM_OPTIONS_LINEAR_RX_OUT_MASK))
7871 *edc_mode = EDC_MODE_LINEAR;
7872 else
7873 *edc_mode = EDC_MODE_LIMITING;
7874 }
7875 DP(NETIF_MSG_LINK, "EDC mode is set to 0x%x\n", *edc_mode);
7876 return 0;
7877}
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007878/*
7879 * This function read the relevant field from the module (SFP+), and verify it
7880 * is compliant with this board
7881 */
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00007882static int bnx2x_verify_sfp_module(struct bnx2x_phy *phy,
7883 struct link_params *params)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007884{
7885 struct bnx2x *bp = params->bp;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007886 u32 val, cmd;
7887 u32 fw_resp, fw_cmd_param;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007888 char vendor_name[SFP_EEPROM_VENDOR_NAME_SIZE+1];
7889 char vendor_pn[SFP_EEPROM_PART_NO_SIZE+1];
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007890 phy->flags &= ~FLAGS_SFP_NOT_APPROVED;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007891 val = REG_RD(bp, params->shmem_base +
7892 offsetof(struct shmem_region, dev_info.
7893 port_feature_config[params->port].config));
7894 if ((val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) ==
7895 PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_NO_ENFORCEMENT) {
7896 DP(NETIF_MSG_LINK, "NOT enforcing module verification\n");
7897 return 0;
7898 }
7899
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007900 if (params->feature_config_flags &
7901 FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY) {
7902 /* Use specific phy request */
7903 cmd = DRV_MSG_CODE_VRFY_SPECIFIC_PHY_OPT_MDL;
7904 } else if (params->feature_config_flags &
7905 FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY) {
7906 /* Use first phy request only in case of non-dual media*/
7907 if (DUAL_MEDIA(params)) {
Joe Perches94f05b02011-08-14 12:16:20 +00007908 DP(NETIF_MSG_LINK,
7909 "FW does not support OPT MDL verification\n");
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007910 return -EINVAL;
7911 }
7912 cmd = DRV_MSG_CODE_VRFY_FIRST_PHY_OPT_MDL;
7913 } else {
7914 /* No support in OPT MDL detection */
Joe Perches94f05b02011-08-14 12:16:20 +00007915 DP(NETIF_MSG_LINK,
7916 "FW does not support OPT MDL verification\n");
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007917 return -EINVAL;
7918 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00007919
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007920 fw_cmd_param = FW_PARAM_SET(phy->addr, phy->type, phy->mdio_ctrl);
7921 fw_resp = bnx2x_fw_command(bp, cmd, fw_cmd_param);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007922 if (fw_resp == FW_MSG_CODE_VRFY_OPT_MDL_SUCCESS) {
7923 DP(NETIF_MSG_LINK, "Approved module\n");
7924 return 0;
7925 }
7926
7927 /* format the warning message */
7928 if (bnx2x_read_sfp_module_eeprom(phy,
7929 params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007930 SFP_EEPROM_VENDOR_NAME_ADDR,
7931 SFP_EEPROM_VENDOR_NAME_SIZE,
7932 (u8 *)vendor_name))
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007933 vendor_name[0] = '\0';
7934 else
7935 vendor_name[SFP_EEPROM_VENDOR_NAME_SIZE] = '\0';
7936 if (bnx2x_read_sfp_module_eeprom(phy,
7937 params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007938 SFP_EEPROM_PART_NO_ADDR,
7939 SFP_EEPROM_PART_NO_SIZE,
7940 (u8 *)vendor_pn))
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007941 vendor_pn[0] = '\0';
7942 else
7943 vendor_pn[SFP_EEPROM_PART_NO_SIZE] = '\0';
7944
Yaniv Rosner6d870c32011-01-31 04:22:20 +00007945 netdev_err(bp->dev, "Warning: Unqualified SFP+ module detected,"
7946 " Port %d from %s part number %s\n",
7947 params->port, vendor_name, vendor_pn);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007948 phy->flags |= FLAGS_SFP_NOT_APPROVED;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007949 return -EINVAL;
7950}
7951
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00007952static int bnx2x_wait_for_sfp_module_initialized(struct bnx2x_phy *phy,
7953 struct link_params *params)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007954
7955{
7956 u8 val;
7957 struct bnx2x *bp = params->bp;
7958 u16 timeout;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007959 /*
7960 * Initialization time after hot-plug may take up to 300ms for
7961 * some phys type ( e.g. JDSU )
7962 */
7963
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007964 for (timeout = 0; timeout < 60; timeout++) {
7965 if (bnx2x_read_sfp_module_eeprom(phy, params, 1, 1, &val)
7966 == 0) {
Joe Perches94f05b02011-08-14 12:16:20 +00007967 DP(NETIF_MSG_LINK,
7968 "SFP+ module initialization took %d ms\n",
7969 timeout * 5);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007970 return 0;
7971 }
7972 msleep(5);
7973 }
7974 return -EINVAL;
7975}
7976
7977static void bnx2x_8727_power_module(struct bnx2x *bp,
7978 struct bnx2x_phy *phy,
7979 u8 is_power_up) {
7980 /* Make sure GPIOs are not using for LED mode */
7981 u16 val;
7982 /*
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007983 * In the GPIO register, bit 4 is use to determine if the GPIOs are
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007984 * operating as INPUT or as OUTPUT. Bit 1 is for input, and 0 for
7985 * output
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00007986 * Bits 0-1 determine the GPIOs value for OUTPUT in case bit 4 val is 0
7987 * Bits 8-9 determine the GPIOs value for INPUT in case bit 4 val is 1
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007988 * where the 1st bit is the over-current(only input), and 2nd bit is
7989 * for power( only output )
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007990 *
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007991 * In case of NOC feature is disabled and power is up, set GPIO control
7992 * as input to enable listening of over-current indication
7993 */
7994 if (phy->flags & FLAGS_NOC)
7995 return;
Yaniv Rosner27d02432011-05-31 21:27:48 +00007996 if (is_power_up)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007997 val = (1<<4);
7998 else
7999 /*
8000 * Set GPIO control to OUTPUT, and set the power bit
8001 * to according to the is_power_up
8002 */
Yaniv Rosner27d02432011-05-31 21:27:48 +00008003 val = (1<<1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008004
8005 bnx2x_cl45_write(bp, phy,
8006 MDIO_PMA_DEVAD,
8007 MDIO_PMA_REG_8727_GPIO_CTRL,
8008 val);
8009}
8010
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00008011static int bnx2x_8726_set_limiting_mode(struct bnx2x *bp,
8012 struct bnx2x_phy *phy,
8013 u16 edc_mode)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008014{
8015 u16 cur_limiting_mode;
8016
8017 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008018 MDIO_PMA_DEVAD,
8019 MDIO_PMA_REG_ROM_VER2,
8020 &cur_limiting_mode);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008021 DP(NETIF_MSG_LINK, "Current Limiting mode is 0x%x\n",
8022 cur_limiting_mode);
8023
8024 if (edc_mode == EDC_MODE_LIMITING) {
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008025 DP(NETIF_MSG_LINK, "Setting LIMITING MODE\n");
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008026 bnx2x_cl45_write(bp, phy,
8027 MDIO_PMA_DEVAD,
8028 MDIO_PMA_REG_ROM_VER2,
8029 EDC_MODE_LIMITING);
8030 } else { /* LRM mode ( default )*/
8031
8032 DP(NETIF_MSG_LINK, "Setting LRM MODE\n");
8033
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008034 /*
8035 * Changing to LRM mode takes quite few seconds. So do it only
8036 * if current mode is limiting (default is LRM)
8037 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008038 if (cur_limiting_mode != EDC_MODE_LIMITING)
8039 return 0;
8040
8041 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008042 MDIO_PMA_DEVAD,
8043 MDIO_PMA_REG_LRM_MODE,
8044 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008045 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008046 MDIO_PMA_DEVAD,
8047 MDIO_PMA_REG_ROM_VER2,
8048 0x128);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008049 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008050 MDIO_PMA_DEVAD,
8051 MDIO_PMA_REG_MISC_CTRL0,
8052 0x4008);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008053 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008054 MDIO_PMA_DEVAD,
8055 MDIO_PMA_REG_LRM_MODE,
8056 0xaaaa);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008057 }
8058 return 0;
8059}
8060
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00008061static int bnx2x_8727_set_limiting_mode(struct bnx2x *bp,
8062 struct bnx2x_phy *phy,
8063 u16 edc_mode)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008064{
8065 u16 phy_identifier;
8066 u16 rom_ver2_val;
8067 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008068 MDIO_PMA_DEVAD,
8069 MDIO_PMA_REG_PHY_IDENTIFIER,
8070 &phy_identifier);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008071
8072 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008073 MDIO_PMA_DEVAD,
8074 MDIO_PMA_REG_PHY_IDENTIFIER,
8075 (phy_identifier & ~(1<<9)));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008076
8077 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008078 MDIO_PMA_DEVAD,
8079 MDIO_PMA_REG_ROM_VER2,
8080 &rom_ver2_val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008081 /* Keep the MSB 8-bits, and set the LSB 8-bits with the edc_mode */
8082 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008083 MDIO_PMA_DEVAD,
8084 MDIO_PMA_REG_ROM_VER2,
8085 (rom_ver2_val & 0xff00) | (edc_mode & 0x00ff));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008086
8087 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008088 MDIO_PMA_DEVAD,
8089 MDIO_PMA_REG_PHY_IDENTIFIER,
8090 (phy_identifier | (1<<9)));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008091
8092 return 0;
8093}
8094
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008095static void bnx2x_8727_specific_func(struct bnx2x_phy *phy,
8096 struct link_params *params,
8097 u32 action)
8098{
8099 struct bnx2x *bp = params->bp;
8100
8101 switch (action) {
8102 case DISABLE_TX:
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008103 bnx2x_sfp_set_transmitter(params, phy, 0);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008104 break;
8105 case ENABLE_TX:
8106 if (!(phy->flags & FLAGS_SFP_NOT_APPROVED))
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008107 bnx2x_sfp_set_transmitter(params, phy, 1);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008108 break;
8109 default:
8110 DP(NETIF_MSG_LINK, "Function 0x%x not supported by 8727\n",
8111 action);
8112 return;
8113 }
8114}
8115
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008116static void bnx2x_set_e1e2_module_fault_led(struct link_params *params,
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008117 u8 gpio_mode)
8118{
8119 struct bnx2x *bp = params->bp;
8120
8121 u32 fault_led_gpio = REG_RD(bp, params->shmem_base +
8122 offsetof(struct shmem_region,
8123 dev_info.port_hw_config[params->port].sfp_ctrl)) &
8124 PORT_HW_CFG_FAULT_MODULE_LED_MASK;
8125 switch (fault_led_gpio) {
8126 case PORT_HW_CFG_FAULT_MODULE_LED_DISABLED:
8127 return;
8128 case PORT_HW_CFG_FAULT_MODULE_LED_GPIO0:
8129 case PORT_HW_CFG_FAULT_MODULE_LED_GPIO1:
8130 case PORT_HW_CFG_FAULT_MODULE_LED_GPIO2:
8131 case PORT_HW_CFG_FAULT_MODULE_LED_GPIO3:
8132 {
8133 u8 gpio_port = bnx2x_get_gpio_port(params);
8134 u16 gpio_pin = fault_led_gpio -
8135 PORT_HW_CFG_FAULT_MODULE_LED_GPIO0;
8136 DP(NETIF_MSG_LINK, "Set fault module-detected led "
8137 "pin %x port %x mode %x\n",
8138 gpio_pin, gpio_port, gpio_mode);
8139 bnx2x_set_gpio(bp, gpio_pin, gpio_mode, gpio_port);
8140 }
8141 break;
8142 default:
8143 DP(NETIF_MSG_LINK, "Error: Invalid fault led mode 0x%x\n",
8144 fault_led_gpio);
8145 }
8146}
8147
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008148static void bnx2x_set_e3_module_fault_led(struct link_params *params,
8149 u8 gpio_mode)
8150{
8151 u32 pin_cfg;
8152 u8 port = params->port;
8153 struct bnx2x *bp = params->bp;
8154 pin_cfg = (REG_RD(bp, params->shmem_base +
8155 offsetof(struct shmem_region,
8156 dev_info.port_hw_config[port].e3_sfp_ctrl)) &
8157 PORT_HW_CFG_E3_FAULT_MDL_LED_MASK) >>
8158 PORT_HW_CFG_E3_FAULT_MDL_LED_SHIFT;
8159 DP(NETIF_MSG_LINK, "Setting Fault LED to %d using pin cfg %d\n",
8160 gpio_mode, pin_cfg);
8161 bnx2x_set_cfg_pin(bp, pin_cfg, gpio_mode);
8162}
8163
8164static void bnx2x_set_sfp_module_fault_led(struct link_params *params,
8165 u8 gpio_mode)
8166{
8167 struct bnx2x *bp = params->bp;
8168 DP(NETIF_MSG_LINK, "Setting SFP+ module fault LED to %d\n", gpio_mode);
8169 if (CHIP_IS_E3(bp)) {
8170 /*
8171 * Low ==> if SFP+ module is supported otherwise
8172 * High ==> if SFP+ module is not on the approved vendor list
8173 */
8174 bnx2x_set_e3_module_fault_led(params, gpio_mode);
8175 } else
8176 bnx2x_set_e1e2_module_fault_led(params, gpio_mode);
8177}
8178
8179static void bnx2x_warpcore_power_module(struct link_params *params,
8180 struct bnx2x_phy *phy,
8181 u8 power)
8182{
8183 u32 pin_cfg;
8184 struct bnx2x *bp = params->bp;
8185
8186 pin_cfg = (REG_RD(bp, params->shmem_base +
8187 offsetof(struct shmem_region,
8188 dev_info.port_hw_config[params->port].e3_sfp_ctrl)) &
8189 PORT_HW_CFG_E3_PWR_DIS_MASK) >>
8190 PORT_HW_CFG_E3_PWR_DIS_SHIFT;
Yaniv Rosner985848f2011-07-05 01:06:48 +00008191
8192 if (pin_cfg == PIN_CFG_NA)
8193 return;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008194 DP(NETIF_MSG_LINK, "Setting SFP+ module power to %d using pin cfg %d\n",
8195 power, pin_cfg);
8196 /*
8197 * Low ==> corresponding SFP+ module is powered
8198 * high ==> the SFP+ module is powered down
8199 */
8200 bnx2x_set_cfg_pin(bp, pin_cfg, power ^ 1);
8201}
8202
Yaniv Rosner985848f2011-07-05 01:06:48 +00008203static void bnx2x_warpcore_hw_reset(struct bnx2x_phy *phy,
8204 struct link_params *params)
8205{
8206 bnx2x_warpcore_power_module(params, phy, 0);
8207}
8208
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00008209static void bnx2x_power_sfp_module(struct link_params *params,
8210 struct bnx2x_phy *phy,
8211 u8 power)
8212{
8213 struct bnx2x *bp = params->bp;
8214 DP(NETIF_MSG_LINK, "Setting SFP+ power to %x\n", power);
8215
8216 switch (phy->type) {
8217 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
8218 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8722:
8219 bnx2x_8727_power_module(params->bp, phy, power);
8220 break;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008221 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT:
8222 bnx2x_warpcore_power_module(params, phy, power);
8223 break;
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00008224 default:
8225 break;
8226 }
8227}
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008228static void bnx2x_warpcore_set_limiting_mode(struct link_params *params,
8229 struct bnx2x_phy *phy,
8230 u16 edc_mode)
8231{
8232 u16 val = 0;
8233 u16 mode = MDIO_WC_REG_UC_INFO_B1_FIRMWARE_MODE_DEFAULT;
8234 struct bnx2x *bp = params->bp;
8235
8236 u8 lane = bnx2x_get_warpcore_lane(phy, params);
8237 /* This is a global register which controls all lanes */
8238 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
8239 MDIO_WC_REG_UC_INFO_B1_FIRMWARE_MODE, &val);
8240 val &= ~(0xf << (lane << 2));
8241
8242 switch (edc_mode) {
8243 case EDC_MODE_LINEAR:
8244 case EDC_MODE_LIMITING:
8245 mode = MDIO_WC_REG_UC_INFO_B1_FIRMWARE_MODE_DEFAULT;
8246 break;
8247 case EDC_MODE_PASSIVE_DAC:
8248 mode = MDIO_WC_REG_UC_INFO_B1_FIRMWARE_MODE_SFP_DAC;
8249 break;
8250 default:
8251 break;
8252 }
8253
8254 val |= (mode << (lane << 2));
8255 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
8256 MDIO_WC_REG_UC_INFO_B1_FIRMWARE_MODE, val);
8257 /* A must read */
8258 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
8259 MDIO_WC_REG_UC_INFO_B1_FIRMWARE_MODE, &val);
8260
Yaniv Rosner19af03a2011-08-02 22:59:47 +00008261 /* Restart microcode to re-read the new mode */
8262 bnx2x_warpcore_reset_lane(bp, phy, 1);
8263 bnx2x_warpcore_reset_lane(bp, phy, 0);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008264
8265}
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00008266
8267static void bnx2x_set_limiting_mode(struct link_params *params,
8268 struct bnx2x_phy *phy,
8269 u16 edc_mode)
8270{
8271 switch (phy->type) {
8272 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
8273 bnx2x_8726_set_limiting_mode(params->bp, phy, edc_mode);
8274 break;
8275 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
8276 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8722:
8277 bnx2x_8727_set_limiting_mode(params->bp, phy, edc_mode);
8278 break;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008279 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT:
8280 bnx2x_warpcore_set_limiting_mode(params, phy, edc_mode);
8281 break;
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00008282 }
8283}
8284
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00008285int bnx2x_sfp_module_detection(struct bnx2x_phy *phy,
8286 struct link_params *params)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008287{
8288 struct bnx2x *bp = params->bp;
8289 u16 edc_mode;
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00008290 int rc = 0;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008291
8292 u32 val = REG_RD(bp, params->shmem_base +
8293 offsetof(struct shmem_region, dev_info.
8294 port_feature_config[params->port].config));
8295
8296 DP(NETIF_MSG_LINK, "SFP+ module plugged in/out detected on port %d\n",
8297 params->port);
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00008298 /* Power up module */
8299 bnx2x_power_sfp_module(params, phy, 1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008300 if (bnx2x_get_edc_mode(phy, params, &edc_mode) != 0) {
8301 DP(NETIF_MSG_LINK, "Failed to get valid module type\n");
8302 return -EINVAL;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008303 } else if (bnx2x_verify_sfp_module(phy, params) != 0) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008304 /* check SFP+ module compatibility */
8305 DP(NETIF_MSG_LINK, "Module verification failed!!\n");
8306 rc = -EINVAL;
8307 /* Turn on fault module-detected led */
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008308 bnx2x_set_sfp_module_fault_led(params,
8309 MISC_REGISTERS_GPIO_HIGH);
8310
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00008311 /* Check if need to power down the SFP+ module */
8312 if ((val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) ==
8313 PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_POWER_DOWN) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008314 DP(NETIF_MSG_LINK, "Shutdown SFP+ module!!\n");
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00008315 bnx2x_power_sfp_module(params, phy, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008316 return rc;
8317 }
8318 } else {
8319 /* Turn off fault module-detected led */
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008320 bnx2x_set_sfp_module_fault_led(params, MISC_REGISTERS_GPIO_LOW);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008321 }
8322
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008323 /*
8324 * Check and set limiting mode / LRM mode on 8726. On 8727 it
8325 * is done automatically
8326 */
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00008327 bnx2x_set_limiting_mode(params, phy, edc_mode);
8328
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008329 /*
8330 * Enable transmit for this module if the module is approved, or
8331 * if unapproved modules should also enable the Tx laser
8332 */
8333 if (rc == 0 ||
8334 (val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) !=
8335 PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_DISABLE_TX_LASER)
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008336 bnx2x_sfp_set_transmitter(params, phy, 1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008337 else
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008338 bnx2x_sfp_set_transmitter(params, phy, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008339
8340 return rc;
8341}
8342
8343void bnx2x_handle_module_detect_int(struct link_params *params)
8344{
8345 struct bnx2x *bp = params->bp;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008346 struct bnx2x_phy *phy;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008347 u32 gpio_val;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008348 u8 gpio_num, gpio_port;
8349 if (CHIP_IS_E3(bp))
8350 phy = &params->phy[INT_PHY];
8351 else
8352 phy = &params->phy[EXT_PHY1];
8353
8354 if (bnx2x_get_mod_abs_int_cfg(bp, params->chip_id, params->shmem_base,
8355 params->port, &gpio_num, &gpio_port) ==
8356 -EINVAL) {
8357 DP(NETIF_MSG_LINK, "Failed to get MOD_ABS interrupt config\n");
8358 return;
8359 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008360
8361 /* Set valid module led off */
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008362 bnx2x_set_sfp_module_fault_led(params, MISC_REGISTERS_GPIO_HIGH);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008363
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008364 /* Get current gpio val reflecting module plugged in / out*/
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008365 gpio_val = bnx2x_get_gpio(bp, gpio_num, gpio_port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008366
8367 /* Call the handling function in case module is detected */
8368 if (gpio_val == 0) {
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00008369 bnx2x_power_sfp_module(params, phy, 1);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008370 bnx2x_set_gpio_int(bp, gpio_num,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008371 MISC_REGISTERS_GPIO_INT_OUTPUT_CLR,
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008372 gpio_port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008373 if (bnx2x_wait_for_sfp_module_initialized(phy, params) == 0)
8374 bnx2x_sfp_module_detection(phy, params);
8375 else
8376 DP(NETIF_MSG_LINK, "SFP+ module is not initialized\n");
8377 } else {
8378 u32 val = REG_RD(bp, params->shmem_base +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008379 offsetof(struct shmem_region, dev_info.
8380 port_feature_config[params->port].
8381 config));
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008382 bnx2x_set_gpio_int(bp, gpio_num,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008383 MISC_REGISTERS_GPIO_INT_OUTPUT_SET,
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008384 gpio_port);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008385 /*
8386 * Module was plugged out.
8387 * Disable transmit for this module
8388 */
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00008389 phy->media_type = ETH_PHY_NOT_PRESENT;
Yaniv Rosnerde6f3372011-08-02 22:59:25 +00008390 if (((val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) ==
8391 PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_DISABLE_TX_LASER) ||
8392 CHIP_IS_E3(bp))
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008393 bnx2x_sfp_set_transmitter(params, phy, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008394 }
8395}
8396
8397/******************************************************************/
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00008398/* Used by 8706 and 8727 */
8399/******************************************************************/
8400static void bnx2x_sfp_mask_fault(struct bnx2x *bp,
8401 struct bnx2x_phy *phy,
8402 u16 alarm_status_offset,
8403 u16 alarm_ctrl_offset)
8404{
8405 u16 alarm_status, val;
8406 bnx2x_cl45_read(bp, phy,
8407 MDIO_PMA_DEVAD, alarm_status_offset,
8408 &alarm_status);
8409 bnx2x_cl45_read(bp, phy,
8410 MDIO_PMA_DEVAD, alarm_status_offset,
8411 &alarm_status);
8412 /* Mask or enable the fault event. */
8413 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD, alarm_ctrl_offset, &val);
8414 if (alarm_status & (1<<0))
8415 val &= ~(1<<0);
8416 else
8417 val |= (1<<0);
8418 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, alarm_ctrl_offset, val);
8419}
8420/******************************************************************/
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008421/* common BCM8706/BCM8726 PHY SECTION */
8422/******************************************************************/
8423static u8 bnx2x_8706_8726_read_status(struct bnx2x_phy *phy,
8424 struct link_params *params,
8425 struct link_vars *vars)
8426{
8427 u8 link_up = 0;
8428 u16 val1, val2, rx_sd, pcs_status;
8429 struct bnx2x *bp = params->bp;
8430 DP(NETIF_MSG_LINK, "XGXS 8706/8726\n");
8431 /* Clear RX Alarm*/
8432 bnx2x_cl45_read(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00008433 MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXSTAT, &val2);
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00008434
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00008435 bnx2x_sfp_mask_fault(bp, phy, MDIO_PMA_LASI_TXSTAT,
8436 MDIO_PMA_LASI_TXCTRL);
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00008437
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008438 /* clear LASI indication*/
8439 bnx2x_cl45_read(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00008440 MDIO_PMA_DEVAD, MDIO_PMA_LASI_STAT, &val1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008441 bnx2x_cl45_read(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00008442 MDIO_PMA_DEVAD, MDIO_PMA_LASI_STAT, &val2);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008443 DP(NETIF_MSG_LINK, "8706/8726 LASI status 0x%x--> 0x%x\n", val1, val2);
8444
8445 bnx2x_cl45_read(bp, phy,
8446 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_SD, &rx_sd);
8447 bnx2x_cl45_read(bp, phy,
8448 MDIO_PCS_DEVAD, MDIO_PCS_REG_STATUS, &pcs_status);
8449 bnx2x_cl45_read(bp, phy,
8450 MDIO_AN_DEVAD, MDIO_AN_REG_LINK_STATUS, &val2);
8451 bnx2x_cl45_read(bp, phy,
8452 MDIO_AN_DEVAD, MDIO_AN_REG_LINK_STATUS, &val2);
8453
8454 DP(NETIF_MSG_LINK, "8706/8726 rx_sd 0x%x pcs_status 0x%x 1Gbps"
8455 " link_status 0x%x\n", rx_sd, pcs_status, val2);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008456 /*
8457 * link is up if both bit 0 of pmd_rx_sd and bit 0 of pcs_status
8458 * are set, or if the autoneg bit 1 is set
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008459 */
8460 link_up = ((rx_sd & pcs_status & 0x1) || (val2 & (1<<1)));
8461 if (link_up) {
8462 if (val2 & (1<<1))
8463 vars->line_speed = SPEED_1000;
8464 else
8465 vars->line_speed = SPEED_10000;
8466 bnx2x_ext_phy_resolve_fc(phy, params, vars);
Yaniv Rosner791f18c2011-01-18 04:33:42 +00008467 vars->duplex = DUPLEX_FULL;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008468 }
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00008469
8470 /* Capture 10G link fault. Read twice to clear stale value. */
8471 if (vars->line_speed == SPEED_10000) {
8472 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00008473 MDIO_PMA_LASI_TXSTAT, &val1);
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00008474 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00008475 MDIO_PMA_LASI_TXSTAT, &val1);
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00008476 if (val1 & (1<<0))
8477 vars->fault_detected = 1;
8478 }
8479
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008480 return link_up;
8481}
8482
8483/******************************************************************/
8484/* BCM8706 PHY SECTION */
8485/******************************************************************/
8486static u8 bnx2x_8706_config_init(struct bnx2x_phy *phy,
8487 struct link_params *params,
8488 struct link_vars *vars)
8489{
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008490 u32 tx_en_mode;
8491 u16 cnt, val, tmp1;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008492 struct bnx2x *bp = params->bp;
Yaniv Rosner3deb8162011-06-14 01:34:33 +00008493
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008494 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008495 MISC_REGISTERS_GPIO_OUTPUT_HIGH, params->port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008496 /* HW reset */
8497 bnx2x_ext_phy_hw_reset(bp, params->port);
8498 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0xa040);
Yaniv Rosner6d870c32011-01-31 04:22:20 +00008499 bnx2x_wait_reset_complete(bp, phy, params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008500
8501 /* Wait until fw is loaded */
8502 for (cnt = 0; cnt < 100; cnt++) {
8503 bnx2x_cl45_read(bp, phy,
8504 MDIO_PMA_DEVAD, MDIO_PMA_REG_ROM_VER1, &val);
8505 if (val)
8506 break;
8507 msleep(10);
8508 }
8509 DP(NETIF_MSG_LINK, "XGXS 8706 is initialized after %d ms\n", cnt);
8510 if ((params->feature_config_flags &
8511 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED)) {
8512 u8 i;
8513 u16 reg;
8514 for (i = 0; i < 4; i++) {
8515 reg = MDIO_XS_8706_REG_BANK_RX0 +
8516 i*(MDIO_XS_8706_REG_BANK_RX1 -
8517 MDIO_XS_8706_REG_BANK_RX0);
8518 bnx2x_cl45_read(bp, phy, MDIO_XS_DEVAD, reg, &val);
8519 /* Clear first 3 bits of the control */
8520 val &= ~0x7;
8521 /* Set control bits according to configuration */
8522 val |= (phy->rx_preemphasis[i] & 0x7);
8523 DP(NETIF_MSG_LINK, "Setting RX Equalizer to BCM8706"
8524 " reg 0x%x <-- val 0x%x\n", reg, val);
8525 bnx2x_cl45_write(bp, phy, MDIO_XS_DEVAD, reg, val);
8526 }
8527 }
8528 /* Force speed */
8529 if (phy->req_line_speed == SPEED_10000) {
8530 DP(NETIF_MSG_LINK, "XGXS 8706 force 10Gbps\n");
8531
8532 bnx2x_cl45_write(bp, phy,
8533 MDIO_PMA_DEVAD,
8534 MDIO_PMA_REG_DIGITAL_CTRL, 0x400);
8535 bnx2x_cl45_write(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00008536 MDIO_PMA_DEVAD, MDIO_PMA_LASI_TXCTRL,
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00008537 0);
8538 /* Arm LASI for link and Tx fault. */
8539 bnx2x_cl45_write(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00008540 MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL, 3);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008541 } else {
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008542 /* Force 1Gbps using autoneg with 1G advertisement */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008543
8544 /* Allow CL37 through CL73 */
8545 DP(NETIF_MSG_LINK, "XGXS 8706 AutoNeg\n");
8546 bnx2x_cl45_write(bp, phy,
8547 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_CL73, 0x040c);
8548
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008549 /* Enable Full-Duplex advertisement on CL37 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008550 bnx2x_cl45_write(bp, phy,
8551 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LP, 0x0020);
8552 /* Enable CL37 AN */
8553 bnx2x_cl45_write(bp, phy,
8554 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_AN, 0x1000);
8555 /* 1G support */
8556 bnx2x_cl45_write(bp, phy,
8557 MDIO_AN_DEVAD, MDIO_AN_REG_ADV, (1<<5));
8558
8559 /* Enable clause 73 AN */
8560 bnx2x_cl45_write(bp, phy,
8561 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x1200);
8562 bnx2x_cl45_write(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00008563 MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXCTRL,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008564 0x0400);
8565 bnx2x_cl45_write(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00008566 MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008567 0x0004);
8568 }
8569 bnx2x_save_bcm_spirom_ver(bp, phy, params->port);
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008570
8571 /*
8572 * If TX Laser is controlled by GPIO_0, do not let PHY go into low
8573 * power mode, if TX Laser is disabled
8574 */
8575
8576 tx_en_mode = REG_RD(bp, params->shmem_base +
8577 offsetof(struct shmem_region,
8578 dev_info.port_hw_config[params->port].sfp_ctrl))
8579 & PORT_HW_CFG_TX_LASER_MASK;
8580
8581 if (tx_en_mode == PORT_HW_CFG_TX_LASER_GPIO0) {
8582 DP(NETIF_MSG_LINK, "Enabling TXONOFF_PWRDN_DIS\n");
8583 bnx2x_cl45_read(bp, phy,
8584 MDIO_PMA_DEVAD, MDIO_PMA_REG_DIGITAL_CTRL, &tmp1);
8585 tmp1 |= 0x1;
8586 bnx2x_cl45_write(bp, phy,
8587 MDIO_PMA_DEVAD, MDIO_PMA_REG_DIGITAL_CTRL, tmp1);
8588 }
8589
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008590 return 0;
8591}
8592
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00008593static int bnx2x_8706_read_status(struct bnx2x_phy *phy,
8594 struct link_params *params,
8595 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008596{
8597 return bnx2x_8706_8726_read_status(phy, params, vars);
8598}
8599
8600/******************************************************************/
8601/* BCM8726 PHY SECTION */
8602/******************************************************************/
8603static void bnx2x_8726_config_loopback(struct bnx2x_phy *phy,
8604 struct link_params *params)
8605{
8606 struct bnx2x *bp = params->bp;
8607 DP(NETIF_MSG_LINK, "PMA/PMD ext_phy_loopback: 8726\n");
8608 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x0001);
8609}
8610
8611static void bnx2x_8726_external_rom_boot(struct bnx2x_phy *phy,
8612 struct link_params *params)
8613{
8614 struct bnx2x *bp = params->bp;
8615 /* Need to wait 100ms after reset */
8616 msleep(100);
8617
8618 /* Micro controller re-boot */
8619 bnx2x_cl45_write(bp, phy,
8620 MDIO_PMA_DEVAD, MDIO_PMA_REG_GEN_CTRL, 0x018B);
8621
8622 /* Set soft reset */
8623 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008624 MDIO_PMA_DEVAD,
8625 MDIO_PMA_REG_GEN_CTRL,
8626 MDIO_PMA_REG_GEN_CTRL_ROM_MICRO_RESET);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008627
8628 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008629 MDIO_PMA_DEVAD,
8630 MDIO_PMA_REG_MISC_CTRL1, 0x0001);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008631
8632 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008633 MDIO_PMA_DEVAD,
8634 MDIO_PMA_REG_GEN_CTRL,
8635 MDIO_PMA_REG_GEN_CTRL_ROM_RESET_INTERNAL_MP);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008636
8637 /* wait for 150ms for microcode load */
8638 msleep(150);
8639
8640 /* Disable serial boot control, tristates pins SS_N, SCK, MOSI, MISO */
8641 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008642 MDIO_PMA_DEVAD,
8643 MDIO_PMA_REG_MISC_CTRL1, 0x0000);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008644
8645 msleep(200);
8646 bnx2x_save_bcm_spirom_ver(bp, phy, params->port);
8647}
8648
8649static u8 bnx2x_8726_read_status(struct bnx2x_phy *phy,
8650 struct link_params *params,
8651 struct link_vars *vars)
8652{
8653 struct bnx2x *bp = params->bp;
8654 u16 val1;
8655 u8 link_up = bnx2x_8706_8726_read_status(phy, params, vars);
8656 if (link_up) {
8657 bnx2x_cl45_read(bp, phy,
8658 MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER,
8659 &val1);
8660 if (val1 & (1<<15)) {
8661 DP(NETIF_MSG_LINK, "Tx is disabled\n");
8662 link_up = 0;
8663 vars->line_speed = 0;
8664 }
8665 }
8666 return link_up;
8667}
8668
8669
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00008670static int bnx2x_8726_config_init(struct bnx2x_phy *phy,
8671 struct link_params *params,
8672 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008673{
8674 struct bnx2x *bp = params->bp;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008675 DP(NETIF_MSG_LINK, "Initializing BCM8726\n");
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008676
8677 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 1<<15);
Yaniv Rosner6d870c32011-01-31 04:22:20 +00008678 bnx2x_wait_reset_complete(bp, phy, params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008679
8680 bnx2x_8726_external_rom_boot(phy, params);
8681
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008682 /*
8683 * Need to call module detected on initialization since the module
8684 * detection triggered by actual module insertion might occur before
8685 * driver is loaded, and when driver is loaded, it reset all
8686 * registers, including the transmitter
8687 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008688 bnx2x_sfp_module_detection(phy, params);
8689
8690 if (phy->req_line_speed == SPEED_1000) {
8691 DP(NETIF_MSG_LINK, "Setting 1G force\n");
8692 bnx2x_cl45_write(bp, phy,
8693 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x40);
8694 bnx2x_cl45_write(bp, phy,
8695 MDIO_PMA_DEVAD, MDIO_PMA_REG_10G_CTRL2, 0xD);
8696 bnx2x_cl45_write(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00008697 MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL, 0x5);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008698 bnx2x_cl45_write(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00008699 MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXCTRL,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008700 0x400);
8701 } else if ((phy->req_line_speed == SPEED_AUTO_NEG) &&
8702 (phy->speed_cap_mask &
8703 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G) &&
8704 ((phy->speed_cap_mask &
8705 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G) !=
8706 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) {
8707 DP(NETIF_MSG_LINK, "Setting 1G clause37\n");
8708 /* Set Flow control */
8709 bnx2x_ext_phy_set_pause(params, phy, vars);
8710 bnx2x_cl45_write(bp, phy,
8711 MDIO_AN_DEVAD, MDIO_AN_REG_ADV, 0x20);
8712 bnx2x_cl45_write(bp, phy,
8713 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_CL73, 0x040c);
8714 bnx2x_cl45_write(bp, phy,
8715 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LD, 0x0020);
8716 bnx2x_cl45_write(bp, phy,
8717 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_AN, 0x1000);
8718 bnx2x_cl45_write(bp, phy,
8719 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x1200);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008720 /*
8721 * Enable RX-ALARM control to receive interrupt for 1G speed
8722 * change
8723 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008724 bnx2x_cl45_write(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00008725 MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL, 0x4);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008726 bnx2x_cl45_write(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00008727 MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXCTRL,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008728 0x400);
8729
8730 } else { /* Default 10G. Set only LASI control */
8731 bnx2x_cl45_write(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00008732 MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL, 1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008733 }
8734
8735 /* Set TX PreEmphasis if needed */
8736 if ((params->feature_config_flags &
8737 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED)) {
Joe Perches94f05b02011-08-14 12:16:20 +00008738 DP(NETIF_MSG_LINK,
8739 "Setting TX_CTRL1 0x%x, TX_CTRL2 0x%x\n",
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008740 phy->tx_preemphasis[0],
8741 phy->tx_preemphasis[1]);
8742 bnx2x_cl45_write(bp, phy,
8743 MDIO_PMA_DEVAD,
8744 MDIO_PMA_REG_8726_TX_CTRL1,
8745 phy->tx_preemphasis[0]);
8746
8747 bnx2x_cl45_write(bp, phy,
8748 MDIO_PMA_DEVAD,
8749 MDIO_PMA_REG_8726_TX_CTRL2,
8750 phy->tx_preemphasis[1]);
8751 }
8752
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008753 return 0;
8754
8755}
8756
8757static void bnx2x_8726_link_reset(struct bnx2x_phy *phy,
8758 struct link_params *params)
8759{
8760 struct bnx2x *bp = params->bp;
8761 DP(NETIF_MSG_LINK, "bnx2x_8726_link_reset port %d\n", params->port);
8762 /* Set serial boot control for external load */
8763 bnx2x_cl45_write(bp, phy,
8764 MDIO_PMA_DEVAD,
8765 MDIO_PMA_REG_GEN_CTRL, 0x0001);
8766}
8767
8768/******************************************************************/
8769/* BCM8727 PHY SECTION */
8770/******************************************************************/
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00008771
8772static void bnx2x_8727_set_link_led(struct bnx2x_phy *phy,
8773 struct link_params *params, u8 mode)
8774{
8775 struct bnx2x *bp = params->bp;
8776 u16 led_mode_bitmask = 0;
8777 u16 gpio_pins_bitmask = 0;
8778 u16 val;
8779 /* Only NOC flavor requires to set the LED specifically */
8780 if (!(phy->flags & FLAGS_NOC))
8781 return;
8782 switch (mode) {
8783 case LED_MODE_FRONT_PANEL_OFF:
8784 case LED_MODE_OFF:
8785 led_mode_bitmask = 0;
8786 gpio_pins_bitmask = 0x03;
8787 break;
8788 case LED_MODE_ON:
8789 led_mode_bitmask = 0;
8790 gpio_pins_bitmask = 0x02;
8791 break;
8792 case LED_MODE_OPER:
8793 led_mode_bitmask = 0x60;
8794 gpio_pins_bitmask = 0x11;
8795 break;
8796 }
8797 bnx2x_cl45_read(bp, phy,
8798 MDIO_PMA_DEVAD,
8799 MDIO_PMA_REG_8727_PCS_OPT_CTRL,
8800 &val);
8801 val &= 0xff8f;
8802 val |= led_mode_bitmask;
8803 bnx2x_cl45_write(bp, phy,
8804 MDIO_PMA_DEVAD,
8805 MDIO_PMA_REG_8727_PCS_OPT_CTRL,
8806 val);
8807 bnx2x_cl45_read(bp, phy,
8808 MDIO_PMA_DEVAD,
8809 MDIO_PMA_REG_8727_GPIO_CTRL,
8810 &val);
8811 val &= 0xffe0;
8812 val |= gpio_pins_bitmask;
8813 bnx2x_cl45_write(bp, phy,
8814 MDIO_PMA_DEVAD,
8815 MDIO_PMA_REG_8727_GPIO_CTRL,
8816 val);
8817}
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00008818static void bnx2x_8727_hw_reset(struct bnx2x_phy *phy,
8819 struct link_params *params) {
8820 u32 swap_val, swap_override;
8821 u8 port;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008822 /*
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00008823 * The PHY reset is controlled by GPIO 1. Fake the port number
8824 * to cancel the swap done in set_gpio()
8825 */
8826 struct bnx2x *bp = params->bp;
8827 swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
8828 swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
8829 port = (swap_val && swap_override) ^ 1;
8830 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008831 MISC_REGISTERS_GPIO_OUTPUT_LOW, port);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00008832}
8833
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00008834static int bnx2x_8727_config_init(struct bnx2x_phy *phy,
8835 struct link_params *params,
8836 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008837{
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008838 u32 tx_en_mode;
8839 u16 tmp1, val, mod_abs, tmp2;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008840 u16 rx_alarm_ctrl_val;
8841 u16 lasi_ctrl_val;
8842 struct bnx2x *bp = params->bp;
8843 /* Enable PMD link, MOD_ABS_FLT, and 1G link alarm */
8844
Yaniv Rosner6d870c32011-01-31 04:22:20 +00008845 bnx2x_wait_reset_complete(bp, phy, params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008846 rx_alarm_ctrl_val = (1<<2) | (1<<5) ;
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00008847 /* Should be 0x6 to enable XS on Tx side. */
8848 lasi_ctrl_val = 0x0006;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008849
8850 DP(NETIF_MSG_LINK, "Initializing BCM8727\n");
8851 /* enable LASI */
8852 bnx2x_cl45_write(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00008853 MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXCTRL,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008854 rx_alarm_ctrl_val);
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00008855 bnx2x_cl45_write(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00008856 MDIO_PMA_DEVAD, MDIO_PMA_LASI_TXCTRL,
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00008857 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008858 bnx2x_cl45_write(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00008859 MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL, lasi_ctrl_val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008860
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008861 /*
8862 * Initially configure MOD_ABS to interrupt when module is
8863 * presence( bit 8)
8864 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008865 bnx2x_cl45_read(bp, phy,
8866 MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER, &mod_abs);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008867 /*
8868 * Set EDC off by setting OPTXLOS signal input to low (bit 9).
8869 * When the EDC is off it locks onto a reference clock and avoids
8870 * becoming 'lost'
8871 */
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00008872 mod_abs &= ~(1<<8);
8873 if (!(phy->flags & FLAGS_NOC))
8874 mod_abs &= ~(1<<9);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008875 bnx2x_cl45_write(bp, phy,
8876 MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER, mod_abs);
8877
8878
Yaniv Rosner85242ee2011-07-05 01:06:53 +00008879 /* Enable/Disable PHY transmitter output */
8880 bnx2x_set_disable_pmd_transmit(params, phy, 0);
8881
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008882 /* Make MOD_ABS give interrupt on change */
8883 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_PCS_OPT_CTRL,
8884 &val);
8885 val |= (1<<12);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00008886 if (phy->flags & FLAGS_NOC)
8887 val |= (3<<5);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008888
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008889 /*
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00008890 * Set 8727 GPIOs to input to allow reading from the 8727 GPIO0
8891 * status which reflect SFP+ module over-current
8892 */
8893 if (!(phy->flags & FLAGS_NOC))
8894 val &= 0xff8f; /* Reset bits 4-6 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008895 bnx2x_cl45_write(bp, phy,
8896 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_PCS_OPT_CTRL, val);
8897
8898 bnx2x_8727_power_module(bp, phy, 1);
8899
8900 bnx2x_cl45_read(bp, phy,
8901 MDIO_PMA_DEVAD, MDIO_PMA_REG_M8051_MSGOUT_REG, &tmp1);
8902
8903 bnx2x_cl45_read(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00008904 MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXSTAT, &tmp1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008905
8906 /* Set option 1G speed */
8907 if (phy->req_line_speed == SPEED_1000) {
8908 DP(NETIF_MSG_LINK, "Setting 1G force\n");
8909 bnx2x_cl45_write(bp, phy,
8910 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x40);
8911 bnx2x_cl45_write(bp, phy,
8912 MDIO_PMA_DEVAD, MDIO_PMA_REG_10G_CTRL2, 0xD);
8913 bnx2x_cl45_read(bp, phy,
8914 MDIO_PMA_DEVAD, MDIO_PMA_REG_10G_CTRL2, &tmp1);
8915 DP(NETIF_MSG_LINK, "1.7 = 0x%x\n", tmp1);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008916 /*
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008917 * Power down the XAUI until link is up in case of dual-media
8918 * and 1G
8919 */
8920 if (DUAL_MEDIA(params)) {
8921 bnx2x_cl45_read(bp, phy,
8922 MDIO_PMA_DEVAD,
8923 MDIO_PMA_REG_8727_PCS_GP, &val);
8924 val |= (3<<10);
8925 bnx2x_cl45_write(bp, phy,
8926 MDIO_PMA_DEVAD,
8927 MDIO_PMA_REG_8727_PCS_GP, val);
8928 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008929 } else if ((phy->req_line_speed == SPEED_AUTO_NEG) &&
8930 ((phy->speed_cap_mask &
8931 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) &&
8932 ((phy->speed_cap_mask &
8933 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G) !=
8934 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) {
8935
8936 DP(NETIF_MSG_LINK, "Setting 1G clause37\n");
8937 bnx2x_cl45_write(bp, phy,
8938 MDIO_AN_DEVAD, MDIO_AN_REG_8727_MISC_CTRL, 0);
8939 bnx2x_cl45_write(bp, phy,
8940 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_AN, 0x1300);
8941 } else {
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008942 /*
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008943 * Since the 8727 has only single reset pin, need to set the 10G
8944 * registers although it is default
8945 */
8946 bnx2x_cl45_write(bp, phy,
8947 MDIO_AN_DEVAD, MDIO_AN_REG_8727_MISC_CTRL,
8948 0x0020);
8949 bnx2x_cl45_write(bp, phy,
8950 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_AN, 0x0100);
8951 bnx2x_cl45_write(bp, phy,
8952 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x2040);
8953 bnx2x_cl45_write(bp, phy,
8954 MDIO_PMA_DEVAD, MDIO_PMA_REG_10G_CTRL2,
8955 0x0008);
8956 }
8957
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008958 /*
8959 * Set 2-wire transfer rate of SFP+ module EEPROM
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008960 * to 100Khz since some DACs(direct attached cables) do
8961 * not work at 400Khz.
8962 */
8963 bnx2x_cl45_write(bp, phy,
8964 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_TWO_WIRE_SLAVE_ADDR,
8965 0xa001);
8966
8967 /* Set TX PreEmphasis if needed */
8968 if ((params->feature_config_flags &
8969 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED)) {
8970 DP(NETIF_MSG_LINK, "Setting TX_CTRL1 0x%x, TX_CTRL2 0x%x\n",
8971 phy->tx_preemphasis[0],
8972 phy->tx_preemphasis[1]);
8973 bnx2x_cl45_write(bp, phy,
8974 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_TX_CTRL1,
8975 phy->tx_preemphasis[0]);
8976
8977 bnx2x_cl45_write(bp, phy,
8978 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_TX_CTRL2,
8979 phy->tx_preemphasis[1]);
8980 }
8981
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008982 /*
8983 * If TX Laser is controlled by GPIO_0, do not let PHY go into low
8984 * power mode, if TX Laser is disabled
8985 */
8986 tx_en_mode = REG_RD(bp, params->shmem_base +
8987 offsetof(struct shmem_region,
8988 dev_info.port_hw_config[params->port].sfp_ctrl))
8989 & PORT_HW_CFG_TX_LASER_MASK;
8990
8991 if (tx_en_mode == PORT_HW_CFG_TX_LASER_GPIO0) {
8992
8993 DP(NETIF_MSG_LINK, "Enabling TXONOFF_PWRDN_DIS\n");
8994 bnx2x_cl45_read(bp, phy,
8995 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_OPT_CFG_REG, &tmp2);
8996 tmp2 |= 0x1000;
8997 tmp2 &= 0xFFEF;
8998 bnx2x_cl45_write(bp, phy,
8999 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_OPT_CFG_REG, tmp2);
9000 }
9001
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009002 return 0;
9003}
9004
9005static void bnx2x_8727_handle_mod_abs(struct bnx2x_phy *phy,
9006 struct link_params *params)
9007{
9008 struct bnx2x *bp = params->bp;
9009 u16 mod_abs, rx_alarm_status;
9010 u32 val = REG_RD(bp, params->shmem_base +
9011 offsetof(struct shmem_region, dev_info.
9012 port_feature_config[params->port].
9013 config));
9014 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00009015 MDIO_PMA_DEVAD,
9016 MDIO_PMA_REG_PHY_IDENTIFIER, &mod_abs);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009017 if (mod_abs & (1<<8)) {
9018
9019 /* Module is absent */
Joe Perches94f05b02011-08-14 12:16:20 +00009020 DP(NETIF_MSG_LINK,
9021 "MOD_ABS indication show module is absent\n");
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00009022 phy->media_type = ETH_PHY_NOT_PRESENT;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00009023 /*
9024 * 1. Set mod_abs to detect next module
9025 * presence event
9026 * 2. Set EDC off by setting OPTXLOS signal input to low
9027 * (bit 9).
9028 * When the EDC is off it locks onto a reference clock and
9029 * avoids becoming 'lost'.
9030 */
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00009031 mod_abs &= ~(1<<8);
9032 if (!(phy->flags & FLAGS_NOC))
9033 mod_abs &= ~(1<<9);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009034 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00009035 MDIO_PMA_DEVAD,
9036 MDIO_PMA_REG_PHY_IDENTIFIER, mod_abs);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009037
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00009038 /*
9039 * Clear RX alarm since it stays up as long as
9040 * the mod_abs wasn't changed
9041 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009042 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00009043 MDIO_PMA_DEVAD,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009044 MDIO_PMA_LASI_RXSTAT, &rx_alarm_status);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009045
9046 } else {
9047 /* Module is present */
Joe Perches94f05b02011-08-14 12:16:20 +00009048 DP(NETIF_MSG_LINK,
9049 "MOD_ABS indication show module is present\n");
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00009050 /*
9051 * First disable transmitter, and if the module is ok, the
9052 * module_detection will enable it
9053 * 1. Set mod_abs to detect next module absent event ( bit 8)
9054 * 2. Restore the default polarity of the OPRXLOS signal and
9055 * this signal will then correctly indicate the presence or
9056 * absence of the Rx signal. (bit 9)
9057 */
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00009058 mod_abs |= (1<<8);
9059 if (!(phy->flags & FLAGS_NOC))
9060 mod_abs |= (1<<9);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009061 bnx2x_cl45_write(bp, phy,
9062 MDIO_PMA_DEVAD,
9063 MDIO_PMA_REG_PHY_IDENTIFIER, mod_abs);
9064
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00009065 /*
9066 * Clear RX alarm since it stays up as long as the mod_abs
9067 * wasn't changed. This is need to be done before calling the
9068 * module detection, otherwise it will clear* the link update
9069 * alarm
9070 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009071 bnx2x_cl45_read(bp, phy,
9072 MDIO_PMA_DEVAD,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009073 MDIO_PMA_LASI_RXSTAT, &rx_alarm_status);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009074
9075
9076 if ((val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) ==
9077 PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_DISABLE_TX_LASER)
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00009078 bnx2x_sfp_set_transmitter(params, phy, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009079
9080 if (bnx2x_wait_for_sfp_module_initialized(phy, params) == 0)
9081 bnx2x_sfp_module_detection(phy, params);
9082 else
9083 DP(NETIF_MSG_LINK, "SFP+ module is not initialized\n");
9084 }
9085
9086 DP(NETIF_MSG_LINK, "8727 RX_ALARM_STATUS 0x%x\n",
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00009087 rx_alarm_status);
9088 /* No need to check link status in case of module plugged in/out */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009089}
9090
9091static u8 bnx2x_8727_read_status(struct bnx2x_phy *phy,
9092 struct link_params *params,
9093 struct link_vars *vars)
9094
9095{
9096 struct bnx2x *bp = params->bp;
Yaniv Rosner27d02432011-05-31 21:27:48 +00009097 u8 link_up = 0, oc_port = params->port;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009098 u16 link_status = 0;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00009099 u16 rx_alarm_status, lasi_ctrl, val1;
9100
9101 /* If PHY is not initialized, do not check link status */
9102 bnx2x_cl45_read(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009103 MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00009104 &lasi_ctrl);
9105 if (!lasi_ctrl)
9106 return 0;
9107
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00009108 /* Check the LASI on Rx */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009109 bnx2x_cl45_read(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009110 MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXSTAT,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009111 &rx_alarm_status);
9112 vars->line_speed = 0;
9113 DP(NETIF_MSG_LINK, "8727 RX_ALARM_STATUS 0x%x\n", rx_alarm_status);
9114
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009115 bnx2x_sfp_mask_fault(bp, phy, MDIO_PMA_LASI_TXSTAT,
9116 MDIO_PMA_LASI_TXCTRL);
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00009117
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009118 bnx2x_cl45_read(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009119 MDIO_PMA_DEVAD, MDIO_PMA_LASI_STAT, &val1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009120
9121 DP(NETIF_MSG_LINK, "8727 LASI status 0x%x\n", val1);
9122
9123 /* Clear MSG-OUT */
9124 bnx2x_cl45_read(bp, phy,
9125 MDIO_PMA_DEVAD, MDIO_PMA_REG_M8051_MSGOUT_REG, &val1);
9126
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00009127 /*
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009128 * If a module is present and there is need to check
9129 * for over current
9130 */
9131 if (!(phy->flags & FLAGS_NOC) && !(rx_alarm_status & (1<<5))) {
9132 /* Check over-current using 8727 GPIO0 input*/
9133 bnx2x_cl45_read(bp, phy,
9134 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_GPIO_CTRL,
9135 &val1);
9136
9137 if ((val1 & (1<<8)) == 0) {
Yaniv Rosner27d02432011-05-31 21:27:48 +00009138 if (!CHIP_IS_E1x(bp))
9139 oc_port = BP_PATH(bp) + (params->port << 1);
Joe Perches94f05b02011-08-14 12:16:20 +00009140 DP(NETIF_MSG_LINK,
9141 "8727 Power fault has been detected on port %d\n",
9142 oc_port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009143 netdev_err(bp->dev, "Error: Power fault on Port %d has"
9144 " been detected and the power to "
9145 "that SFP+ module has been removed"
9146 " to prevent failure of the card."
9147 " Please remove the SFP+ module and"
9148 " restart the system to clear this"
9149 " error.\n",
Yaniv Rosner27d02432011-05-31 21:27:48 +00009150 oc_port);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00009151 /* Disable all RX_ALARMs except for mod_abs */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009152 bnx2x_cl45_write(bp, phy,
9153 MDIO_PMA_DEVAD,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009154 MDIO_PMA_LASI_RXCTRL, (1<<5));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009155
9156 bnx2x_cl45_read(bp, phy,
9157 MDIO_PMA_DEVAD,
9158 MDIO_PMA_REG_PHY_IDENTIFIER, &val1);
9159 /* Wait for module_absent_event */
9160 val1 |= (1<<8);
9161 bnx2x_cl45_write(bp, phy,
9162 MDIO_PMA_DEVAD,
9163 MDIO_PMA_REG_PHY_IDENTIFIER, val1);
9164 /* Clear RX alarm */
9165 bnx2x_cl45_read(bp, phy,
9166 MDIO_PMA_DEVAD,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009167 MDIO_PMA_LASI_RXSTAT, &rx_alarm_status);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009168 return 0;
9169 }
9170 } /* Over current check */
9171
9172 /* When module absent bit is set, check module */
9173 if (rx_alarm_status & (1<<5)) {
9174 bnx2x_8727_handle_mod_abs(phy, params);
9175 /* Enable all mod_abs and link detection bits */
9176 bnx2x_cl45_write(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009177 MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXCTRL,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009178 ((1<<5) | (1<<2)));
9179 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +00009180 DP(NETIF_MSG_LINK, "Enabling 8727 TX laser if SFP is approved\n");
9181 bnx2x_8727_specific_func(phy, params, ENABLE_TX);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009182 /* If transmitter is disabled, ignore false link up indication */
9183 bnx2x_cl45_read(bp, phy,
9184 MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER, &val1);
9185 if (val1 & (1<<15)) {
9186 DP(NETIF_MSG_LINK, "Tx is disabled\n");
9187 return 0;
9188 }
9189
9190 bnx2x_cl45_read(bp, phy,
9191 MDIO_PMA_DEVAD,
9192 MDIO_PMA_REG_8073_SPEED_LINK_STATUS, &link_status);
9193
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00009194 /*
9195 * Bits 0..2 --> speed detected,
9196 * Bits 13..15--> link is down
9197 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009198 if ((link_status & (1<<2)) && (!(link_status & (1<<15)))) {
9199 link_up = 1;
9200 vars->line_speed = SPEED_10000;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00009201 DP(NETIF_MSG_LINK, "port %x: External link up in 10G\n",
9202 params->port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009203 } else if ((link_status & (1<<0)) && (!(link_status & (1<<13)))) {
9204 link_up = 1;
9205 vars->line_speed = SPEED_1000;
9206 DP(NETIF_MSG_LINK, "port %x: External link up in 1G\n",
9207 params->port);
9208 } else {
9209 link_up = 0;
9210 DP(NETIF_MSG_LINK, "port %x: External link is down\n",
9211 params->port);
9212 }
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00009213
9214 /* Capture 10G link fault. */
9215 if (vars->line_speed == SPEED_10000) {
9216 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009217 MDIO_PMA_LASI_TXSTAT, &val1);
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00009218
9219 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009220 MDIO_PMA_LASI_TXSTAT, &val1);
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00009221
9222 if (val1 & (1<<0)) {
9223 vars->fault_detected = 1;
9224 }
9225 }
9226
Yaniv Rosner791f18c2011-01-18 04:33:42 +00009227 if (link_up) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009228 bnx2x_ext_phy_resolve_fc(phy, params, vars);
Yaniv Rosner791f18c2011-01-18 04:33:42 +00009229 vars->duplex = DUPLEX_FULL;
9230 DP(NETIF_MSG_LINK, "duplex = 0x%x\n", vars->duplex);
9231 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +00009232
9233 if ((DUAL_MEDIA(params)) &&
9234 (phy->req_line_speed == SPEED_1000)) {
9235 bnx2x_cl45_read(bp, phy,
9236 MDIO_PMA_DEVAD,
9237 MDIO_PMA_REG_8727_PCS_GP, &val1);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00009238 /*
Yaniv Rosnera22f0782010-09-07 11:41:20 +00009239 * In case of dual-media board and 1G, power up the XAUI side,
9240 * otherwise power it down. For 10G it is done automatically
9241 */
9242 if (link_up)
9243 val1 &= ~(3<<10);
9244 else
9245 val1 |= (3<<10);
9246 bnx2x_cl45_write(bp, phy,
9247 MDIO_PMA_DEVAD,
9248 MDIO_PMA_REG_8727_PCS_GP, val1);
9249 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009250 return link_up;
9251}
9252
9253static void bnx2x_8727_link_reset(struct bnx2x_phy *phy,
9254 struct link_params *params)
9255{
9256 struct bnx2x *bp = params->bp;
Yaniv Rosner85242ee2011-07-05 01:06:53 +00009257
9258 /* Enable/Disable PHY transmitter output */
9259 bnx2x_set_disable_pmd_transmit(params, phy, 1);
9260
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009261 /* Disable Transmitter */
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00009262 bnx2x_sfp_set_transmitter(params, phy, 0);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00009263 /* Clear LASI */
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009264 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL, 0);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00009265
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009266}
9267
9268/******************************************************************/
9269/* BCM8481/BCM84823/BCM84833 PHY SECTION */
9270/******************************************************************/
9271static void bnx2x_save_848xx_spirom_version(struct bnx2x_phy *phy,
9272 struct link_params *params)
9273{
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009274 u16 val, fw_ver1, fw_ver2, cnt;
9275 u8 port;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009276 struct bnx2x *bp = params->bp;
9277
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009278 port = params->port;
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00009279
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009280 /* For the 32 bits registers in 848xx, access via MDIO2ARM interface.*/
9281 /* (1) set register 0xc200_0014(SPI_BRIDGE_CTRL_2) to 0x03000000 */
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009282 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA819, 0x0014);
9283 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA81A, 0xc200);
9284 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA81B, 0x0000);
9285 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA81C, 0x0300);
9286 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA817, 0x0009);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009287
9288 for (cnt = 0; cnt < 100; cnt++) {
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009289 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD, 0xA818, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009290 if (val & 1)
9291 break;
9292 udelay(5);
9293 }
9294 if (cnt == 100) {
9295 DP(NETIF_MSG_LINK, "Unable to read 848xx phy fw version(1)\n");
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009296 bnx2x_save_spirom_version(bp, port, 0,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009297 phy->ver_addr);
9298 return;
9299 }
9300
9301
9302 /* 2) read register 0xc200_0000 (SPI_FW_STATUS) */
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009303 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA819, 0x0000);
9304 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA81A, 0xc200);
9305 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA817, 0x000A);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009306 for (cnt = 0; cnt < 100; cnt++) {
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009307 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD, 0xA818, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009308 if (val & 1)
9309 break;
9310 udelay(5);
9311 }
9312 if (cnt == 100) {
9313 DP(NETIF_MSG_LINK, "Unable to read 848xx phy fw version(2)\n");
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009314 bnx2x_save_spirom_version(bp, port, 0,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009315 phy->ver_addr);
9316 return;
9317 }
9318
9319 /* lower 16 bits of the register SPI_FW_STATUS */
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009320 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD, 0xA81B, &fw_ver1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009321 /* upper 16 bits of register SPI_FW_STATUS */
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009322 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD, 0xA81C, &fw_ver2);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009323
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009324 bnx2x_save_spirom_version(bp, port, (fw_ver2<<16) | fw_ver1,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009325 phy->ver_addr);
9326}
9327
9328static void bnx2x_848xx_set_led(struct bnx2x *bp,
9329 struct bnx2x_phy *phy)
9330{
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009331 u16 val;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009332
9333 /* PHYC_CTL_LED_CTL */
9334 bnx2x_cl45_read(bp, phy,
9335 MDIO_PMA_DEVAD,
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009336 MDIO_PMA_REG_8481_LINK_SIGNAL, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009337 val &= 0xFE00;
9338 val |= 0x0092;
9339
9340 bnx2x_cl45_write(bp, phy,
9341 MDIO_PMA_DEVAD,
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009342 MDIO_PMA_REG_8481_LINK_SIGNAL, val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009343
9344 bnx2x_cl45_write(bp, phy,
9345 MDIO_PMA_DEVAD,
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009346 MDIO_PMA_REG_8481_LED1_MASK,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009347 0x80);
9348
9349 bnx2x_cl45_write(bp, phy,
9350 MDIO_PMA_DEVAD,
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009351 MDIO_PMA_REG_8481_LED2_MASK,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009352 0x18);
9353
Yaniv Rosnerf25b3c82011-01-18 04:33:47 +00009354 /* Select activity source by Tx and Rx, as suggested by PHY AE */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009355 bnx2x_cl45_write(bp, phy,
9356 MDIO_PMA_DEVAD,
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009357 MDIO_PMA_REG_8481_LED3_MASK,
Yaniv Rosnerf25b3c82011-01-18 04:33:47 +00009358 0x0006);
9359
9360 /* Select the closest activity blink rate to that in 10/100/1000 */
9361 bnx2x_cl45_write(bp, phy,
9362 MDIO_PMA_DEVAD,
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009363 MDIO_PMA_REG_8481_LED3_BLINK,
Yaniv Rosnerf25b3c82011-01-18 04:33:47 +00009364 0);
9365
9366 bnx2x_cl45_read(bp, phy,
9367 MDIO_PMA_DEVAD,
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009368 MDIO_PMA_REG_84823_CTL_LED_CTL_1, &val);
Yaniv Rosnerf25b3c82011-01-18 04:33:47 +00009369 val |= MDIO_PMA_REG_84823_LED3_STRETCH_EN; /* stretch_en for LED3*/
9370
9371 bnx2x_cl45_write(bp, phy,
9372 MDIO_PMA_DEVAD,
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009373 MDIO_PMA_REG_84823_CTL_LED_CTL_1, val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009374
9375 /* 'Interrupt Mask' */
9376 bnx2x_cl45_write(bp, phy,
9377 MDIO_AN_DEVAD,
9378 0xFFFB, 0xFFFD);
9379}
9380
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00009381static int bnx2x_848xx_cmn_config_init(struct bnx2x_phy *phy,
9382 struct link_params *params,
9383 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009384{
9385 struct bnx2x *bp = params->bp;
9386 u16 autoneg_val, an_1000_val, an_10_100_val;
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009387 u16 tmp_req_line_speed;
9388
9389 tmp_req_line_speed = phy->req_line_speed;
9390 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
9391 if (phy->req_line_speed == SPEED_10000)
9392 phy->req_line_speed = SPEED_AUTO_NEG;
9393
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00009394 /*
9395 * This phy uses the NIG latch mechanism since link indication
9396 * arrives through its LED4 and not via its LASI signal, so we
9397 * get steady signal instead of clear on read
9398 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009399 bnx2x_bits_en(bp, NIG_REG_LATCH_BC_0 + params->port*4,
9400 1 << NIG_LATCH_BC_ENABLE_MI_INT);
9401
9402 bnx2x_cl45_write(bp, phy,
9403 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x0000);
9404
9405 bnx2x_848xx_set_led(bp, phy);
9406
9407 /* set 1000 speed advertisement */
9408 bnx2x_cl45_read(bp, phy,
9409 MDIO_AN_DEVAD, MDIO_AN_REG_8481_1000T_CTRL,
9410 &an_1000_val);
9411
9412 bnx2x_ext_phy_set_pause(params, phy, vars);
9413 bnx2x_cl45_read(bp, phy,
9414 MDIO_AN_DEVAD,
9415 MDIO_AN_REG_8481_LEGACY_AN_ADV,
9416 &an_10_100_val);
9417 bnx2x_cl45_read(bp, phy,
9418 MDIO_AN_DEVAD, MDIO_AN_REG_8481_LEGACY_MII_CTRL,
9419 &autoneg_val);
9420 /* Disable forced speed */
9421 autoneg_val &= ~((1<<6) | (1<<8) | (1<<9) | (1<<12) | (1<<13));
9422 an_10_100_val &= ~((1<<5) | (1<<6) | (1<<7) | (1<<8));
9423
9424 if (((phy->req_line_speed == SPEED_AUTO_NEG) &&
9425 (phy->speed_cap_mask &
9426 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) ||
9427 (phy->req_line_speed == SPEED_1000)) {
9428 an_1000_val |= (1<<8);
9429 autoneg_val |= (1<<9 | 1<<12);
9430 if (phy->req_duplex == DUPLEX_FULL)
9431 an_1000_val |= (1<<9);
9432 DP(NETIF_MSG_LINK, "Advertising 1G\n");
9433 } else
9434 an_1000_val &= ~((1<<8) | (1<<9));
9435
9436 bnx2x_cl45_write(bp, phy,
9437 MDIO_AN_DEVAD, MDIO_AN_REG_8481_1000T_CTRL,
9438 an_1000_val);
9439
Yaniv Rosner0520e632011-07-05 01:06:59 +00009440 /* set 100 speed advertisement */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009441 if (((phy->req_line_speed == SPEED_AUTO_NEG) &&
9442 (phy->speed_cap_mask &
Yaniv Rosner0520e632011-07-05 01:06:59 +00009443 (PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL |
9444 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF)) &&
9445 (phy->supported &
9446 (SUPPORTED_100baseT_Half |
9447 SUPPORTED_100baseT_Full)))) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009448 an_10_100_val |= (1<<7);
9449 /* Enable autoneg and restart autoneg for legacy speeds */
9450 autoneg_val |= (1<<9 | 1<<12);
9451
9452 if (phy->req_duplex == DUPLEX_FULL)
9453 an_10_100_val |= (1<<8);
9454 DP(NETIF_MSG_LINK, "Advertising 100M\n");
9455 }
9456 /* set 10 speed advertisement */
9457 if (((phy->req_line_speed == SPEED_AUTO_NEG) &&
Yaniv Rosner0520e632011-07-05 01:06:59 +00009458 (phy->speed_cap_mask &
9459 (PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL |
9460 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF)) &&
9461 (phy->supported &
9462 (SUPPORTED_10baseT_Half |
9463 SUPPORTED_10baseT_Full)))) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009464 an_10_100_val |= (1<<5);
9465 autoneg_val |= (1<<9 | 1<<12);
9466 if (phy->req_duplex == DUPLEX_FULL)
9467 an_10_100_val |= (1<<6);
9468 DP(NETIF_MSG_LINK, "Advertising 10M\n");
9469 }
9470
9471 /* Only 10/100 are allowed to work in FORCE mode */
Yaniv Rosner0520e632011-07-05 01:06:59 +00009472 if ((phy->req_line_speed == SPEED_100) &&
9473 (phy->supported &
9474 (SUPPORTED_100baseT_Half |
9475 SUPPORTED_100baseT_Full))) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009476 autoneg_val |= (1<<13);
9477 /* Enabled AUTO-MDIX when autoneg is disabled */
9478 bnx2x_cl45_write(bp, phy,
9479 MDIO_AN_DEVAD, MDIO_AN_REG_8481_AUX_CTRL,
9480 (1<<15 | 1<<9 | 7<<0));
9481 DP(NETIF_MSG_LINK, "Setting 100M force\n");
9482 }
Yaniv Rosner0520e632011-07-05 01:06:59 +00009483 if ((phy->req_line_speed == SPEED_10) &&
9484 (phy->supported &
9485 (SUPPORTED_10baseT_Half |
9486 SUPPORTED_10baseT_Full))) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009487 /* Enabled AUTO-MDIX when autoneg is disabled */
9488 bnx2x_cl45_write(bp, phy,
9489 MDIO_AN_DEVAD, MDIO_AN_REG_8481_AUX_CTRL,
9490 (1<<15 | 1<<9 | 7<<0));
9491 DP(NETIF_MSG_LINK, "Setting 10M force\n");
9492 }
9493
9494 bnx2x_cl45_write(bp, phy,
9495 MDIO_AN_DEVAD, MDIO_AN_REG_8481_LEGACY_AN_ADV,
9496 an_10_100_val);
9497
9498 if (phy->req_duplex == DUPLEX_FULL)
9499 autoneg_val |= (1<<8);
9500
Yaniv Rosnerfd38f73e2011-08-02 22:59:53 +00009501 /*
9502 * Always write this if this is not 84833.
9503 * For 84833, write it only when it's a forced speed.
9504 */
9505 if ((phy->type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833) ||
9506 ((autoneg_val & (1<<12)) == 0))
9507 bnx2x_cl45_write(bp, phy,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009508 MDIO_AN_DEVAD,
9509 MDIO_AN_REG_8481_LEGACY_MII_CTRL, autoneg_val);
9510
9511 if (((phy->req_line_speed == SPEED_AUTO_NEG) &&
9512 (phy->speed_cap_mask &
9513 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) ||
9514 (phy->req_line_speed == SPEED_10000)) {
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00009515 DP(NETIF_MSG_LINK, "Advertising 10G\n");
9516 /* Restart autoneg for 10G*/
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009517
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00009518 bnx2x_cl45_write(bp, phy,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009519 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL,
9520 0x3200);
Yaniv Rosnerfd38f73e2011-08-02 22:59:53 +00009521 } else
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009522 bnx2x_cl45_write(bp, phy,
9523 MDIO_AN_DEVAD,
9524 MDIO_AN_REG_8481_10GBASE_T_AN_CTRL,
9525 1);
Yaniv Rosnerfd38f73e2011-08-02 22:59:53 +00009526
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009527 /* Save spirom version */
9528 bnx2x_save_848xx_spirom_version(phy, params);
9529
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009530 phy->req_line_speed = tmp_req_line_speed;
9531
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009532 return 0;
9533}
9534
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00009535static int bnx2x_8481_config_init(struct bnx2x_phy *phy,
9536 struct link_params *params,
9537 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009538{
9539 struct bnx2x *bp = params->bp;
9540 /* Restore normal power mode*/
9541 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00009542 MISC_REGISTERS_GPIO_OUTPUT_HIGH, params->port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009543
9544 /* HW reset */
9545 bnx2x_ext_phy_hw_reset(bp, params->port);
Yaniv Rosner6d870c32011-01-31 04:22:20 +00009546 bnx2x_wait_reset_complete(bp, phy, params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009547
9548 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 1<<15);
9549 return bnx2x_848xx_cmn_config_init(phy, params, vars);
9550}
9551
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009552
9553#define PHY84833_HDSHK_WAIT 300
9554static int bnx2x_84833_pair_swap_cfg(struct bnx2x_phy *phy,
9555 struct link_params *params,
9556 struct link_vars *vars)
9557{
9558 u32 idx;
Yaniv Rosner0520e632011-07-05 01:06:59 +00009559 u32 pair_swap;
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009560 u16 val;
Yaniv Rosner0520e632011-07-05 01:06:59 +00009561 u16 data;
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009562 struct bnx2x *bp = params->bp;
9563 /* Do pair swap */
9564
Yaniv Rosner0520e632011-07-05 01:06:59 +00009565 /* Check for configuration. */
9566 pair_swap = REG_RD(bp, params->shmem_base +
9567 offsetof(struct shmem_region,
9568 dev_info.port_hw_config[params->port].xgbt_phy_cfg)) &
9569 PORT_HW_CFG_RJ45_PAIR_SWAP_MASK;
9570
9571 if (pair_swap == 0)
9572 return 0;
9573
9574 data = (u16)pair_swap;
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009575
9576 /* Write CMD_OPEN_OVERRIDE to STATUS reg */
9577 bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
9578 MDIO_84833_TOP_CFG_SCRATCH_REG2,
9579 PHY84833_CMD_OPEN_OVERRIDE);
9580 for (idx = 0; idx < PHY84833_HDSHK_WAIT; idx++) {
9581 bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD,
9582 MDIO_84833_TOP_CFG_SCRATCH_REG2, &val);
9583 if (val == PHY84833_CMD_OPEN_FOR_CMDS)
9584 break;
9585 msleep(1);
9586 }
9587 if (idx >= PHY84833_HDSHK_WAIT) {
9588 DP(NETIF_MSG_LINK, "Pairswap: FW not ready.\n");
9589 return -EINVAL;
9590 }
9591
9592 bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
9593 MDIO_84833_TOP_CFG_SCRATCH_REG4,
9594 data);
9595 /* Issue pair swap command */
9596 bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
9597 MDIO_84833_TOP_CFG_SCRATCH_REG0,
9598 PHY84833_DIAG_CMD_PAIR_SWAP_CHANGE);
9599 for (idx = 0; idx < PHY84833_HDSHK_WAIT; idx++) {
9600 bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD,
9601 MDIO_84833_TOP_CFG_SCRATCH_REG2, &val);
9602 if ((val == PHY84833_CMD_COMPLETE_PASS) ||
9603 (val == PHY84833_CMD_COMPLETE_ERROR))
9604 break;
9605 msleep(1);
9606 }
9607 if ((idx >= PHY84833_HDSHK_WAIT) ||
9608 (val == PHY84833_CMD_COMPLETE_ERROR)) {
9609 DP(NETIF_MSG_LINK, "Pairswap: override failed.\n");
9610 return -EINVAL;
9611 }
9612 bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
9613 MDIO_84833_TOP_CFG_SCRATCH_REG2,
9614 PHY84833_CMD_CLEAR_COMPLETE);
9615 DP(NETIF_MSG_LINK, "Pairswap OK, val=0x%x\n", data);
9616 return 0;
9617}
9618
Yaniv Rosner0d40f0d2011-06-14 01:34:27 +00009619
Yaniv Rosner985848f2011-07-05 01:06:48 +00009620static u8 bnx2x_84833_get_reset_gpios(struct bnx2x *bp,
9621 u32 shmem_base_path[],
9622 u32 chip_id)
Yaniv Rosner0d40f0d2011-06-14 01:34:27 +00009623{
9624 u32 reset_pin[2];
9625 u32 idx;
9626 u8 reset_gpios;
9627 if (CHIP_IS_E3(bp)) {
9628 /* Assume that these will be GPIOs, not EPIOs. */
9629 for (idx = 0; idx < 2; idx++) {
9630 /* Map config param to register bit. */
9631 reset_pin[idx] = REG_RD(bp, shmem_base_path[idx] +
9632 offsetof(struct shmem_region,
9633 dev_info.port_hw_config[0].e3_cmn_pin_cfg));
9634 reset_pin[idx] = (reset_pin[idx] &
9635 PORT_HW_CFG_E3_PHY_RESET_MASK) >>
9636 PORT_HW_CFG_E3_PHY_RESET_SHIFT;
9637 reset_pin[idx] -= PIN_CFG_GPIO0_P0;
9638 reset_pin[idx] = (1 << reset_pin[idx]);
9639 }
9640 reset_gpios = (u8)(reset_pin[0] | reset_pin[1]);
9641 } else {
9642 /* E2, look from diff place of shmem. */
9643 for (idx = 0; idx < 2; idx++) {
9644 reset_pin[idx] = REG_RD(bp, shmem_base_path[idx] +
9645 offsetof(struct shmem_region,
9646 dev_info.port_hw_config[0].default_cfg));
9647 reset_pin[idx] &= PORT_HW_CFG_EXT_PHY_GPIO_RST_MASK;
9648 reset_pin[idx] -= PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO0_P0;
9649 reset_pin[idx] >>= PORT_HW_CFG_EXT_PHY_GPIO_RST_SHIFT;
9650 reset_pin[idx] = (1 << reset_pin[idx]);
9651 }
9652 reset_gpios = (u8)(reset_pin[0] | reset_pin[1]);
9653 }
9654
Yaniv Rosner985848f2011-07-05 01:06:48 +00009655 return reset_gpios;
9656}
9657
9658static int bnx2x_84833_hw_reset_phy(struct bnx2x_phy *phy,
9659 struct link_params *params)
9660{
9661 struct bnx2x *bp = params->bp;
9662 u8 reset_gpios;
9663 u32 other_shmem_base_addr = REG_RD(bp, params->shmem2_base +
9664 offsetof(struct shmem2_region,
9665 other_shmem_base_addr));
9666
9667 u32 shmem_base_path[2];
9668 shmem_base_path[0] = params->shmem_base;
9669 shmem_base_path[1] = other_shmem_base_addr;
9670
9671 reset_gpios = bnx2x_84833_get_reset_gpios(bp, shmem_base_path,
9672 params->chip_id);
9673
9674 bnx2x_set_mult_gpio(bp, reset_gpios, MISC_REGISTERS_GPIO_OUTPUT_LOW);
9675 udelay(10);
9676 DP(NETIF_MSG_LINK, "84833 hw reset on pin values 0x%x\n",
9677 reset_gpios);
9678
9679 return 0;
9680}
9681
9682static int bnx2x_84833_common_init_phy(struct bnx2x *bp,
9683 u32 shmem_base_path[],
9684 u32 chip_id)
9685{
9686 u8 reset_gpios;
9687
9688 reset_gpios = bnx2x_84833_get_reset_gpios(bp, shmem_base_path, chip_id);
9689
Yaniv Rosner0d40f0d2011-06-14 01:34:27 +00009690 bnx2x_set_mult_gpio(bp, reset_gpios, MISC_REGISTERS_GPIO_OUTPUT_LOW);
9691 udelay(10);
9692 bnx2x_set_mult_gpio(bp, reset_gpios, MISC_REGISTERS_GPIO_OUTPUT_HIGH);
9693 msleep(800);
9694 DP(NETIF_MSG_LINK, "84833 reset pulse on pin values 0x%x\n",
9695 reset_gpios);
9696
9697 return 0;
9698}
9699
Yaniv Rosnera89a1d42011-07-05 01:07:05 +00009700#define PHY84833_CONSTANT_LATENCY 1193
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00009701static int bnx2x_848x3_config_init(struct bnx2x_phy *phy,
9702 struct link_params *params,
9703 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009704{
9705 struct bnx2x *bp = params->bp;
Yaniv Rosner6a71bbe2010-11-01 05:32:31 +00009706 u8 port, initialize = 1;
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009707 u16 val;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009708 u16 temp;
Yaniv Rosnera89a1d42011-07-05 01:07:05 +00009709 u32 actual_phy_selection, cms_enable, idx;
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00009710 int rc = 0;
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00009711
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009712 msleep(1);
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009713
9714 if (!(CHIP_IS_E1(bp)))
Yaniv Rosner6a71bbe2010-11-01 05:32:31 +00009715 port = BP_PATH(bp);
9716 else
9717 port = params->port;
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009718
9719 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84823) {
9720 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_3,
9721 MISC_REGISTERS_GPIO_OUTPUT_HIGH,
9722 port);
9723 } else {
Yaniv Rosner985848f2011-07-05 01:06:48 +00009724 /* MDIO reset */
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009725 bnx2x_cl45_write(bp, phy,
9726 MDIO_PMA_DEVAD,
9727 MDIO_PMA_REG_CTRL, 0x8000);
Yaniv Rosner985848f2011-07-05 01:06:48 +00009728 /* Bring PHY out of super isolate mode */
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009729 bnx2x_cl45_read(bp, phy,
9730 MDIO_CTL_DEVAD,
9731 MDIO_84833_TOP_CFG_XGPHY_STRAP1, &val);
9732 val &= ~MDIO_84833_SUPER_ISOLATE;
9733 bnx2x_cl45_write(bp, phy,
9734 MDIO_CTL_DEVAD,
9735 MDIO_84833_TOP_CFG_XGPHY_STRAP1, val);
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009736 }
9737
Yaniv Rosner985848f2011-07-05 01:06:48 +00009738 bnx2x_wait_reset_complete(bp, phy, params);
9739
9740 /* Wait for GPHY to come out of reset */
9741 msleep(50);
9742
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009743 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
9744 bnx2x_84833_pair_swap_cfg(phy, params, vars);
9745
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00009746 /*
9747 * BCM84823 requires that XGXS links up first @ 10G for normal behavior
9748 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009749 temp = vars->line_speed;
9750 vars->line_speed = SPEED_10000;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00009751 bnx2x_set_autoneg(&params->phy[INT_PHY], params, vars, 0);
9752 bnx2x_program_serdes(&params->phy[INT_PHY], params, vars);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009753 vars->line_speed = temp;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00009754
9755 /* Set dual-media configuration according to configuration */
9756
9757 bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD,
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009758 MDIO_CTL_REG_84823_MEDIA, &val);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00009759 val &= ~(MDIO_CTL_REG_84823_MEDIA_MAC_MASK |
9760 MDIO_CTL_REG_84823_MEDIA_LINE_MASK |
9761 MDIO_CTL_REG_84823_MEDIA_COPPER_CORE_DOWN |
9762 MDIO_CTL_REG_84823_MEDIA_PRIORITY_MASK |
9763 MDIO_CTL_REG_84823_MEDIA_FIBER_1G);
Yaniv Rosner0d40f0d2011-06-14 01:34:27 +00009764
9765 if (CHIP_IS_E3(bp)) {
9766 val &= ~(MDIO_CTL_REG_84823_MEDIA_MAC_MASK |
9767 MDIO_CTL_REG_84823_MEDIA_LINE_MASK);
9768 } else {
9769 val |= (MDIO_CTL_REG_84823_CTRL_MAC_XFI |
9770 MDIO_CTL_REG_84823_MEDIA_LINE_XAUI_L);
9771 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +00009772
9773 actual_phy_selection = bnx2x_phy_selection(params);
9774
9775 switch (actual_phy_selection) {
9776 case PORT_HW_CFG_PHY_SELECTION_HARDWARE_DEFAULT:
Lucas De Marchi25985ed2011-03-30 22:57:33 -03009777 /* Do nothing. Essentially this is like the priority copper */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00009778 break;
9779 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY_PRIORITY:
9780 val |= MDIO_CTL_REG_84823_MEDIA_PRIORITY_COPPER;
9781 break;
9782 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY_PRIORITY:
9783 val |= MDIO_CTL_REG_84823_MEDIA_PRIORITY_FIBER;
9784 break;
9785 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY:
9786 /* Do nothing here. The first PHY won't be initialized at all */
9787 break;
9788 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY:
9789 val |= MDIO_CTL_REG_84823_MEDIA_COPPER_CORE_DOWN;
9790 initialize = 0;
9791 break;
9792 }
9793 if (params->phy[EXT_PHY2].req_line_speed == SPEED_1000)
9794 val |= MDIO_CTL_REG_84823_MEDIA_FIBER_1G;
9795
9796 bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009797 MDIO_CTL_REG_84823_MEDIA, val);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00009798 DP(NETIF_MSG_LINK, "Multi_phy config = 0x%x, Media control = 0x%x\n",
9799 params->multi_phy_config, val);
9800
Yaniv Rosnera89a1d42011-07-05 01:07:05 +00009801 /* AutogrEEEn */
9802 if (params->feature_config_flags &
9803 FEATURE_CONFIG_AUTOGREEEN_ENABLED) {
9804 /* Ensure that f/w is ready */
9805 for (idx = 0; idx < PHY84833_HDSHK_WAIT; idx++) {
9806 bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD,
9807 MDIO_84833_TOP_CFG_SCRATCH_REG2, &val);
9808 if (val == PHY84833_CMD_OPEN_FOR_CMDS)
9809 break;
9810 usleep_range(1000, 1000);
9811 }
9812 if (idx >= PHY84833_HDSHK_WAIT) {
9813 DP(NETIF_MSG_LINK, "AutogrEEEn: FW not ready.\n");
9814 return -EINVAL;
9815 }
9816
9817 /* Select EEE mode */
9818 bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
9819 MDIO_84833_TOP_CFG_SCRATCH_REG3,
9820 0x2);
9821
9822 /* Set Idle and Latency */
9823 bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
9824 MDIO_84833_TOP_CFG_SCRATCH_REG4,
9825 PHY84833_CONSTANT_LATENCY + 1);
9826
9827 bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
9828 MDIO_84833_TOP_CFG_DATA3_REG,
9829 PHY84833_CONSTANT_LATENCY + 1);
9830
9831 bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
9832 MDIO_84833_TOP_CFG_DATA4_REG,
9833 PHY84833_CONSTANT_LATENCY);
9834
9835 /* Send EEE instruction to command register */
9836 bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
9837 MDIO_84833_TOP_CFG_SCRATCH_REG0,
9838 PHY84833_DIAG_CMD_SET_EEE_MODE);
9839
9840 /* Ensure that the command has completed */
9841 for (idx = 0; idx < PHY84833_HDSHK_WAIT; idx++) {
9842 bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD,
9843 MDIO_84833_TOP_CFG_SCRATCH_REG2, &val);
9844 if ((val == PHY84833_CMD_COMPLETE_PASS) ||
9845 (val == PHY84833_CMD_COMPLETE_ERROR))
9846 break;
9847 usleep_range(1000, 1000);
9848 }
9849 if ((idx >= PHY84833_HDSHK_WAIT) ||
9850 (val == PHY84833_CMD_COMPLETE_ERROR)) {
9851 DP(NETIF_MSG_LINK, "AutogrEEEn: command failed.\n");
9852 return -EINVAL;
9853 }
9854
9855 /* Reset command handler */
9856 bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
9857 MDIO_84833_TOP_CFG_SCRATCH_REG2,
9858 PHY84833_CMD_CLEAR_COMPLETE);
9859 }
9860
Yaniv Rosnera22f0782010-09-07 11:41:20 +00009861 if (initialize)
9862 rc = bnx2x_848xx_cmn_config_init(phy, params, vars);
9863 else
9864 bnx2x_save_848xx_spirom_version(phy, params);
Yaniv Rosnera89a1d42011-07-05 01:07:05 +00009865 /* 84833 PHY has a better feature and doesn't need to support this. */
9866 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84823) {
9867 cms_enable = REG_RD(bp, params->shmem_base +
Yaniv Rosner1bef68e2011-01-31 04:22:46 +00009868 offsetof(struct shmem_region,
9869 dev_info.port_hw_config[params->port].default_cfg)) &
9870 PORT_HW_CFG_ENABLE_CMS_MASK;
9871
Yaniv Rosnera89a1d42011-07-05 01:07:05 +00009872 bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD,
9873 MDIO_CTL_REG_84823_USER_CTRL_REG, &val);
9874 if (cms_enable)
9875 val |= MDIO_CTL_REG_84823_USER_CTRL_CMS;
9876 else
9877 val &= ~MDIO_CTL_REG_84823_USER_CTRL_CMS;
9878 bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
9879 MDIO_CTL_REG_84823_USER_CTRL_REG, val);
9880 }
Yaniv Rosner1bef68e2011-01-31 04:22:46 +00009881
Yaniv Rosnera22f0782010-09-07 11:41:20 +00009882 return rc;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009883}
9884
9885static u8 bnx2x_848xx_read_status(struct bnx2x_phy *phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00009886 struct link_params *params,
9887 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009888{
9889 struct bnx2x *bp = params->bp;
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009890 u16 val, val1, val2;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009891 u8 link_up = 0;
9892
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00009893
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009894 /* Check 10G-BaseT link status */
9895 /* Check PMD signal ok */
9896 bnx2x_cl45_read(bp, phy,
9897 MDIO_AN_DEVAD, 0xFFFA, &val1);
9898 bnx2x_cl45_read(bp, phy,
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009899 MDIO_PMA_DEVAD, MDIO_PMA_REG_8481_PMD_SIGNAL,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009900 &val2);
9901 DP(NETIF_MSG_LINK, "BCM848xx: PMD_SIGNAL 1.a811 = 0x%x\n", val2);
9902
9903 /* Check link 10G */
9904 if (val2 & (1<<11)) {
9905 vars->line_speed = SPEED_10000;
Yaniv Rosner791f18c2011-01-18 04:33:42 +00009906 vars->duplex = DUPLEX_FULL;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009907 link_up = 1;
9908 bnx2x_ext_phy_10G_an_resolve(bp, phy, vars);
9909 } else { /* Check Legacy speed link */
9910 u16 legacy_status, legacy_speed;
9911
9912 /* Enable expansion register 0x42 (Operation mode status) */
9913 bnx2x_cl45_write(bp, phy,
9914 MDIO_AN_DEVAD,
9915 MDIO_AN_REG_8481_EXPANSION_REG_ACCESS, 0xf42);
9916
9917 /* Get legacy speed operation status */
9918 bnx2x_cl45_read(bp, phy,
9919 MDIO_AN_DEVAD,
9920 MDIO_AN_REG_8481_EXPANSION_REG_RD_RW,
9921 &legacy_status);
9922
Joe Perches94f05b02011-08-14 12:16:20 +00009923 DP(NETIF_MSG_LINK, "Legacy speed status = 0x%x\n",
9924 legacy_status);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009925 link_up = ((legacy_status & (1<<11)) == (1<<11));
9926 if (link_up) {
9927 legacy_speed = (legacy_status & (3<<9));
9928 if (legacy_speed == (0<<9))
9929 vars->line_speed = SPEED_10;
9930 else if (legacy_speed == (1<<9))
9931 vars->line_speed = SPEED_100;
9932 else if (legacy_speed == (2<<9))
9933 vars->line_speed = SPEED_1000;
9934 else /* Should not happen */
9935 vars->line_speed = 0;
9936
9937 if (legacy_status & (1<<8))
9938 vars->duplex = DUPLEX_FULL;
9939 else
9940 vars->duplex = DUPLEX_HALF;
9941
Joe Perches94f05b02011-08-14 12:16:20 +00009942 DP(NETIF_MSG_LINK,
9943 "Link is up in %dMbps, is_duplex_full= %d\n",
9944 vars->line_speed,
9945 (vars->duplex == DUPLEX_FULL));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009946 /* Check legacy speed AN resolution */
9947 bnx2x_cl45_read(bp, phy,
9948 MDIO_AN_DEVAD,
9949 MDIO_AN_REG_8481_LEGACY_MII_STATUS,
9950 &val);
9951 if (val & (1<<5))
9952 vars->link_status |=
9953 LINK_STATUS_AUTO_NEGOTIATE_COMPLETE;
9954 bnx2x_cl45_read(bp, phy,
9955 MDIO_AN_DEVAD,
9956 MDIO_AN_REG_8481_LEGACY_AN_EXPANSION,
9957 &val);
9958 if ((val & (1<<0)) == 0)
9959 vars->link_status |=
9960 LINK_STATUS_PARALLEL_DETECTION_USED;
9961 }
9962 }
9963 if (link_up) {
9964 DP(NETIF_MSG_LINK, "BCM84823: link speed is %d\n",
9965 vars->line_speed);
9966 bnx2x_ext_phy_resolve_fc(phy, params, vars);
9967 }
9968
9969 return link_up;
9970}
9971
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00009972
9973static int bnx2x_848xx_format_ver(u32 raw_ver, u8 *str, u16 *len)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009974{
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00009975 int status = 0;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009976 u32 spirom_ver;
9977 spirom_ver = ((raw_ver & 0xF80) >> 7) << 16 | (raw_ver & 0x7F);
9978 status = bnx2x_format_ver(spirom_ver, str, len);
9979 return status;
9980}
9981
9982static void bnx2x_8481_hw_reset(struct bnx2x_phy *phy,
9983 struct link_params *params)
9984{
9985 bnx2x_set_gpio(params->bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00009986 MISC_REGISTERS_GPIO_OUTPUT_LOW, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009987 bnx2x_set_gpio(params->bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00009988 MISC_REGISTERS_GPIO_OUTPUT_LOW, 1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009989}
9990
9991static void bnx2x_8481_link_reset(struct bnx2x_phy *phy,
9992 struct link_params *params)
9993{
9994 bnx2x_cl45_write(params->bp, phy,
9995 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x0000);
9996 bnx2x_cl45_write(params->bp, phy,
9997 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 1);
9998}
9999
10000static void bnx2x_848x3_link_reset(struct bnx2x_phy *phy,
10001 struct link_params *params)
10002{
10003 struct bnx2x *bp = params->bp;
Yaniv Rosner6a71bbe2010-11-01 05:32:31 +000010004 u8 port;
Yaniv Rosner0d40f0d2011-06-14 01:34:27 +000010005 u16 val16;
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010006
10007 if (!(CHIP_IS_E1(bp)))
Yaniv Rosner6a71bbe2010-11-01 05:32:31 +000010008 port = BP_PATH(bp);
10009 else
10010 port = params->port;
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010011
10012 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84823) {
10013 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_3,
10014 MISC_REGISTERS_GPIO_OUTPUT_LOW,
10015 port);
10016 } else {
Yaniv Rosner0d40f0d2011-06-14 01:34:27 +000010017 bnx2x_cl45_read(bp, phy,
10018 MDIO_CTL_DEVAD,
10019 0x400f, &val16);
Yaniv Rosnerfd38f73e2011-08-02 22:59:53 +000010020 bnx2x_cl45_write(bp, phy,
10021 MDIO_PMA_DEVAD,
10022 MDIO_PMA_REG_CTRL, 0x800);
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010023 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010024}
10025
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010026static void bnx2x_848xx_set_link_led(struct bnx2x_phy *phy,
10027 struct link_params *params, u8 mode)
10028{
10029 struct bnx2x *bp = params->bp;
10030 u16 val;
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010031 u8 port;
10032
10033 if (!(CHIP_IS_E1(bp)))
10034 port = BP_PATH(bp);
10035 else
10036 port = params->port;
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010037
10038 switch (mode) {
10039 case LED_MODE_OFF:
10040
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010041 DP(NETIF_MSG_LINK, "Port 0x%x: LED MODE OFF\n", port);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010042
10043 if ((params->hw_led_mode << SHARED_HW_CFG_LED_MODE_SHIFT) ==
10044 SHARED_HW_CFG_LED_EXTPHY1) {
10045
10046 /* Set LED masks */
10047 bnx2x_cl45_write(bp, phy,
10048 MDIO_PMA_DEVAD,
10049 MDIO_PMA_REG_8481_LED1_MASK,
10050 0x0);
10051
10052 bnx2x_cl45_write(bp, phy,
10053 MDIO_PMA_DEVAD,
10054 MDIO_PMA_REG_8481_LED2_MASK,
10055 0x0);
10056
10057 bnx2x_cl45_write(bp, phy,
10058 MDIO_PMA_DEVAD,
10059 MDIO_PMA_REG_8481_LED3_MASK,
10060 0x0);
10061
10062 bnx2x_cl45_write(bp, phy,
10063 MDIO_PMA_DEVAD,
10064 MDIO_PMA_REG_8481_LED5_MASK,
10065 0x0);
10066
10067 } else {
10068 bnx2x_cl45_write(bp, phy,
10069 MDIO_PMA_DEVAD,
10070 MDIO_PMA_REG_8481_LED1_MASK,
10071 0x0);
10072 }
10073 break;
10074 case LED_MODE_FRONT_PANEL_OFF:
10075
10076 DP(NETIF_MSG_LINK, "Port 0x%x: LED MODE FRONT PANEL OFF\n",
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010077 port);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010078
10079 if ((params->hw_led_mode << SHARED_HW_CFG_LED_MODE_SHIFT) ==
10080 SHARED_HW_CFG_LED_EXTPHY1) {
10081
10082 /* Set LED masks */
10083 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010084 MDIO_PMA_DEVAD,
10085 MDIO_PMA_REG_8481_LED1_MASK,
10086 0x0);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010087
10088 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010089 MDIO_PMA_DEVAD,
10090 MDIO_PMA_REG_8481_LED2_MASK,
10091 0x0);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010092
10093 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010094 MDIO_PMA_DEVAD,
10095 MDIO_PMA_REG_8481_LED3_MASK,
10096 0x0);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010097
10098 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010099 MDIO_PMA_DEVAD,
10100 MDIO_PMA_REG_8481_LED5_MASK,
10101 0x20);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010102
10103 } else {
10104 bnx2x_cl45_write(bp, phy,
10105 MDIO_PMA_DEVAD,
10106 MDIO_PMA_REG_8481_LED1_MASK,
10107 0x0);
10108 }
10109 break;
10110 case LED_MODE_ON:
10111
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010112 DP(NETIF_MSG_LINK, "Port 0x%x: LED MODE ON\n", port);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010113
10114 if ((params->hw_led_mode << SHARED_HW_CFG_LED_MODE_SHIFT) ==
10115 SHARED_HW_CFG_LED_EXTPHY1) {
10116 /* Set control reg */
10117 bnx2x_cl45_read(bp, phy,
10118 MDIO_PMA_DEVAD,
10119 MDIO_PMA_REG_8481_LINK_SIGNAL,
10120 &val);
10121 val &= 0x8000;
10122 val |= 0x2492;
10123
10124 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010125 MDIO_PMA_DEVAD,
10126 MDIO_PMA_REG_8481_LINK_SIGNAL,
10127 val);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010128
10129 /* Set LED masks */
10130 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010131 MDIO_PMA_DEVAD,
10132 MDIO_PMA_REG_8481_LED1_MASK,
10133 0x0);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010134
10135 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010136 MDIO_PMA_DEVAD,
10137 MDIO_PMA_REG_8481_LED2_MASK,
10138 0x20);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010139
10140 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010141 MDIO_PMA_DEVAD,
10142 MDIO_PMA_REG_8481_LED3_MASK,
10143 0x20);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010144
10145 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010146 MDIO_PMA_DEVAD,
10147 MDIO_PMA_REG_8481_LED5_MASK,
10148 0x0);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010149 } else {
10150 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010151 MDIO_PMA_DEVAD,
10152 MDIO_PMA_REG_8481_LED1_MASK,
10153 0x20);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010154 }
10155 break;
10156
10157 case LED_MODE_OPER:
10158
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010159 DP(NETIF_MSG_LINK, "Port 0x%x: LED MODE OPER\n", port);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010160
10161 if ((params->hw_led_mode << SHARED_HW_CFG_LED_MODE_SHIFT) ==
10162 SHARED_HW_CFG_LED_EXTPHY1) {
10163
10164 /* Set control reg */
10165 bnx2x_cl45_read(bp, phy,
10166 MDIO_PMA_DEVAD,
10167 MDIO_PMA_REG_8481_LINK_SIGNAL,
10168 &val);
10169
10170 if (!((val &
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010171 MDIO_PMA_REG_8481_LINK_SIGNAL_LED4_ENABLE_MASK)
10172 >> MDIO_PMA_REG_8481_LINK_SIGNAL_LED4_ENABLE_SHIFT)) {
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +000010173 DP(NETIF_MSG_LINK, "Setting LINK_SIGNAL\n");
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010174 bnx2x_cl45_write(bp, phy,
10175 MDIO_PMA_DEVAD,
10176 MDIO_PMA_REG_8481_LINK_SIGNAL,
10177 0xa492);
10178 }
10179
10180 /* Set LED masks */
10181 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010182 MDIO_PMA_DEVAD,
10183 MDIO_PMA_REG_8481_LED1_MASK,
10184 0x10);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010185
10186 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010187 MDIO_PMA_DEVAD,
10188 MDIO_PMA_REG_8481_LED2_MASK,
10189 0x80);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010190
10191 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010192 MDIO_PMA_DEVAD,
10193 MDIO_PMA_REG_8481_LED3_MASK,
10194 0x98);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010195
10196 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010197 MDIO_PMA_DEVAD,
10198 MDIO_PMA_REG_8481_LED5_MASK,
10199 0x40);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010200
10201 } else {
10202 bnx2x_cl45_write(bp, phy,
10203 MDIO_PMA_DEVAD,
10204 MDIO_PMA_REG_8481_LED1_MASK,
10205 0x80);
Yaniv Rosner53eda062011-01-30 04:14:55 +000010206
10207 /* Tell LED3 to blink on source */
10208 bnx2x_cl45_read(bp, phy,
10209 MDIO_PMA_DEVAD,
10210 MDIO_PMA_REG_8481_LINK_SIGNAL,
10211 &val);
10212 val &= ~(7<<6);
10213 val |= (1<<6); /* A83B[8:6]= 1 */
10214 bnx2x_cl45_write(bp, phy,
10215 MDIO_PMA_DEVAD,
10216 MDIO_PMA_REG_8481_LINK_SIGNAL,
10217 val);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010218 }
10219 break;
10220 }
Yaniv Rosner0d40f0d2011-06-14 01:34:27 +000010221
10222 /*
10223 * This is a workaround for E3+84833 until autoneg
10224 * restart is fixed in f/w
10225 */
10226 if (CHIP_IS_E3(bp)) {
10227 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
10228 MDIO_WC_REG_GP2_STATUS_GP_2_1, &val);
10229 }
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010230}
Yaniv Rosner0d40f0d2011-06-14 01:34:27 +000010231
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010232/******************************************************************/
Yaniv Rosner52c4d6c2011-07-05 01:06:34 +000010233/* 54618SE PHY SECTION */
Yaniv Rosner6583e332011-06-14 01:34:17 +000010234/******************************************************************/
Yaniv Rosner52c4d6c2011-07-05 01:06:34 +000010235static int bnx2x_54618se_config_init(struct bnx2x_phy *phy,
Yaniv Rosner6583e332011-06-14 01:34:17 +000010236 struct link_params *params,
10237 struct link_vars *vars)
10238{
10239 struct bnx2x *bp = params->bp;
10240 u8 port;
10241 u16 autoneg_val, an_1000_val, an_10_100_val, fc_val, temp;
10242 u32 cfg_pin;
10243
Yaniv Rosner52c4d6c2011-07-05 01:06:34 +000010244 DP(NETIF_MSG_LINK, "54618SE cfg init\n");
Yaniv Rosner6583e332011-06-14 01:34:17 +000010245 usleep_range(1000, 1000);
10246
10247 /* This works with E3 only, no need to check the chip
10248 before determining the port. */
10249 port = params->port;
10250
10251 cfg_pin = (REG_RD(bp, params->shmem_base +
10252 offsetof(struct shmem_region,
10253 dev_info.port_hw_config[port].e3_cmn_pin_cfg)) &
10254 PORT_HW_CFG_E3_PHY_RESET_MASK) >>
10255 PORT_HW_CFG_E3_PHY_RESET_SHIFT;
10256
10257 /* Drive pin high to bring the GPHY out of reset. */
10258 bnx2x_set_cfg_pin(bp, cfg_pin, 1);
10259
10260 /* wait for GPHY to reset */
10261 msleep(50);
10262
10263 /* reset phy */
10264 bnx2x_cl22_write(bp, phy,
10265 MDIO_PMA_REG_CTRL, 0x8000);
10266 bnx2x_wait_reset_complete(bp, phy, params);
10267
10268 /*wait for GPHY to reset */
10269 msleep(50);
10270
10271 /* Configure LED4: set to INTR (0x6). */
10272 /* Accessing shadow register 0xe. */
10273 bnx2x_cl22_write(bp, phy,
10274 MDIO_REG_GPHY_SHADOW,
10275 MDIO_REG_GPHY_SHADOW_LED_SEL2);
10276 bnx2x_cl22_read(bp, phy,
10277 MDIO_REG_GPHY_SHADOW,
10278 &temp);
10279 temp &= ~(0xf << 4);
10280 temp |= (0x6 << 4);
10281 bnx2x_cl22_write(bp, phy,
10282 MDIO_REG_GPHY_SHADOW,
10283 MDIO_REG_GPHY_SHADOW_WR_ENA | temp);
10284 /* Configure INTR based on link status change. */
10285 bnx2x_cl22_write(bp, phy,
10286 MDIO_REG_INTR_MASK,
10287 ~MDIO_REG_INTR_MASK_LINK_STATUS);
10288
10289 /* Flip the signal detect polarity (set 0x1c.0x1e[8]). */
10290 bnx2x_cl22_write(bp, phy,
10291 MDIO_REG_GPHY_SHADOW,
10292 MDIO_REG_GPHY_SHADOW_AUTO_DET_MED);
10293 bnx2x_cl22_read(bp, phy,
10294 MDIO_REG_GPHY_SHADOW,
10295 &temp);
10296 temp |= MDIO_REG_GPHY_SHADOW_INVERT_FIB_SD;
10297 bnx2x_cl22_write(bp, phy,
10298 MDIO_REG_GPHY_SHADOW,
10299 MDIO_REG_GPHY_SHADOW_WR_ENA | temp);
10300
10301 /* Set up fc */
10302 /* Please refer to Table 28B-3 of 802.3ab-1999 spec. */
10303 bnx2x_calc_ieee_aneg_adv(phy, params, &vars->ieee_fc);
10304 fc_val = 0;
10305 if ((vars->ieee_fc & MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC) ==
10306 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC)
10307 fc_val |= MDIO_AN_REG_ADV_PAUSE_ASYMMETRIC;
10308
10309 if ((vars->ieee_fc & MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) ==
10310 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH)
10311 fc_val |= MDIO_AN_REG_ADV_PAUSE_PAUSE;
10312
10313 /* read all advertisement */
10314 bnx2x_cl22_read(bp, phy,
10315 0x09,
10316 &an_1000_val);
10317
10318 bnx2x_cl22_read(bp, phy,
10319 0x04,
10320 &an_10_100_val);
10321
10322 bnx2x_cl22_read(bp, phy,
10323 MDIO_PMA_REG_CTRL,
10324 &autoneg_val);
10325
10326 /* Disable forced speed */
10327 autoneg_val &= ~((1<<6) | (1<<8) | (1<<9) | (1<<12) | (1<<13));
10328 an_10_100_val &= ~((1<<5) | (1<<6) | (1<<7) | (1<<8) | (1<<10) |
10329 (1<<11));
10330
10331 if (((phy->req_line_speed == SPEED_AUTO_NEG) &&
10332 (phy->speed_cap_mask &
10333 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) ||
10334 (phy->req_line_speed == SPEED_1000)) {
10335 an_1000_val |= (1<<8);
10336 autoneg_val |= (1<<9 | 1<<12);
10337 if (phy->req_duplex == DUPLEX_FULL)
10338 an_1000_val |= (1<<9);
10339 DP(NETIF_MSG_LINK, "Advertising 1G\n");
10340 } else
10341 an_1000_val &= ~((1<<8) | (1<<9));
10342
10343 bnx2x_cl22_write(bp, phy,
10344 0x09,
10345 an_1000_val);
10346 bnx2x_cl22_read(bp, phy,
10347 0x09,
10348 &an_1000_val);
10349
10350 /* set 100 speed advertisement */
10351 if (((phy->req_line_speed == SPEED_AUTO_NEG) &&
10352 (phy->speed_cap_mask &
10353 (PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL |
10354 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF)))) {
10355 an_10_100_val |= (1<<7);
10356 /* Enable autoneg and restart autoneg for legacy speeds */
10357 autoneg_val |= (1<<9 | 1<<12);
10358
10359 if (phy->req_duplex == DUPLEX_FULL)
10360 an_10_100_val |= (1<<8);
10361 DP(NETIF_MSG_LINK, "Advertising 100M\n");
10362 }
10363
10364 /* set 10 speed advertisement */
10365 if (((phy->req_line_speed == SPEED_AUTO_NEG) &&
10366 (phy->speed_cap_mask &
10367 (PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL |
10368 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF)))) {
10369 an_10_100_val |= (1<<5);
10370 autoneg_val |= (1<<9 | 1<<12);
10371 if (phy->req_duplex == DUPLEX_FULL)
10372 an_10_100_val |= (1<<6);
10373 DP(NETIF_MSG_LINK, "Advertising 10M\n");
10374 }
10375
10376 /* Only 10/100 are allowed to work in FORCE mode */
10377 if (phy->req_line_speed == SPEED_100) {
10378 autoneg_val |= (1<<13);
10379 /* Enabled AUTO-MDIX when autoneg is disabled */
10380 bnx2x_cl22_write(bp, phy,
10381 0x18,
10382 (1<<15 | 1<<9 | 7<<0));
10383 DP(NETIF_MSG_LINK, "Setting 100M force\n");
10384 }
10385 if (phy->req_line_speed == SPEED_10) {
10386 /* Enabled AUTO-MDIX when autoneg is disabled */
10387 bnx2x_cl22_write(bp, phy,
10388 0x18,
10389 (1<<15 | 1<<9 | 7<<0));
10390 DP(NETIF_MSG_LINK, "Setting 10M force\n");
10391 }
10392
Yaniv Rosnera89a1d42011-07-05 01:07:05 +000010393 /* Check if we should turn on Auto-GrEEEn */
10394 bnx2x_cl22_read(bp, phy, MDIO_REG_GPHY_PHYID_LSB, &temp);
10395 if (temp == MDIO_REG_GPHY_ID_54618SE) {
10396 if (params->feature_config_flags &
10397 FEATURE_CONFIG_AUTOGREEEN_ENABLED) {
10398 temp = 6;
10399 DP(NETIF_MSG_LINK, "Enabling Auto-GrEEEn\n");
10400 } else {
10401 temp = 0;
10402 DP(NETIF_MSG_LINK, "Disabling Auto-GrEEEn\n");
10403 }
10404 bnx2x_cl22_write(bp, phy,
10405 MDIO_REG_GPHY_CL45_ADDR_REG, MDIO_AN_DEVAD);
10406 bnx2x_cl22_write(bp, phy,
10407 MDIO_REG_GPHY_CL45_DATA_REG,
10408 MDIO_REG_GPHY_EEE_ADV);
10409 bnx2x_cl22_write(bp, phy,
10410 MDIO_REG_GPHY_CL45_ADDR_REG,
10411 (0x1 << 14) | MDIO_AN_DEVAD);
10412 bnx2x_cl22_write(bp, phy,
10413 MDIO_REG_GPHY_CL45_DATA_REG,
10414 temp);
10415 }
10416
Yaniv Rosner6583e332011-06-14 01:34:17 +000010417 bnx2x_cl22_write(bp, phy,
10418 0x04,
10419 an_10_100_val | fc_val);
10420
10421 if (phy->req_duplex == DUPLEX_FULL)
10422 autoneg_val |= (1<<8);
10423
10424 bnx2x_cl22_write(bp, phy,
10425 MDIO_PMA_REG_CTRL, autoneg_val);
10426
10427 return 0;
10428}
10429
Yaniv Rosner1d125bd2011-11-23 03:54:08 +000010430
10431static void bnx2x_5461x_set_link_led(struct bnx2x_phy *phy,
10432 struct link_params *params, u8 mode)
10433{
10434 struct bnx2x *bp = params->bp;
10435 u16 temp;
10436
10437 bnx2x_cl22_write(bp, phy,
10438 MDIO_REG_GPHY_SHADOW,
10439 MDIO_REG_GPHY_SHADOW_LED_SEL1);
10440 bnx2x_cl22_read(bp, phy,
10441 MDIO_REG_GPHY_SHADOW,
10442 &temp);
10443 temp &= 0xff00;
10444
10445 DP(NETIF_MSG_LINK, "54618x set link led (mode=%x)\n", mode);
10446 switch (mode) {
10447 case LED_MODE_FRONT_PANEL_OFF:
10448 case LED_MODE_OFF:
10449 temp |= 0x00ee;
10450 break;
10451 case LED_MODE_OPER:
10452 temp |= 0x0001;
10453 break;
10454 case LED_MODE_ON:
10455 temp |= 0x00ff;
10456 break;
10457 default:
10458 break;
10459 }
10460 bnx2x_cl22_write(bp, phy,
10461 MDIO_REG_GPHY_SHADOW,
10462 MDIO_REG_GPHY_SHADOW_WR_ENA | temp);
10463 return;
10464}
10465
10466
Yaniv Rosner52c4d6c2011-07-05 01:06:34 +000010467static void bnx2x_54618se_link_reset(struct bnx2x_phy *phy,
10468 struct link_params *params)
Yaniv Rosner6583e332011-06-14 01:34:17 +000010469{
10470 struct bnx2x *bp = params->bp;
10471 u32 cfg_pin;
10472 u8 port;
10473
Yaniv Rosnerd2059a02011-08-02 23:00:00 +000010474 /*
10475 * In case of no EPIO routed to reset the GPHY, put it
10476 * in low power mode.
10477 */
10478 bnx2x_cl22_write(bp, phy, MDIO_PMA_REG_CTRL, 0x800);
10479 /*
10480 * This works with E3 only, no need to check the chip
10481 * before determining the port.
10482 */
Yaniv Rosner6583e332011-06-14 01:34:17 +000010483 port = params->port;
10484 cfg_pin = (REG_RD(bp, params->shmem_base +
10485 offsetof(struct shmem_region,
10486 dev_info.port_hw_config[port].e3_cmn_pin_cfg)) &
10487 PORT_HW_CFG_E3_PHY_RESET_MASK) >>
10488 PORT_HW_CFG_E3_PHY_RESET_SHIFT;
10489
10490 /* Drive pin low to put GPHY in reset. */
10491 bnx2x_set_cfg_pin(bp, cfg_pin, 0);
10492}
10493
Yaniv Rosner52c4d6c2011-07-05 01:06:34 +000010494static u8 bnx2x_54618se_read_status(struct bnx2x_phy *phy,
10495 struct link_params *params,
10496 struct link_vars *vars)
Yaniv Rosner6583e332011-06-14 01:34:17 +000010497{
10498 struct bnx2x *bp = params->bp;
10499 u16 val;
10500 u8 link_up = 0;
10501 u16 legacy_status, legacy_speed;
10502
10503 /* Get speed operation status */
10504 bnx2x_cl22_read(bp, phy,
10505 0x19,
10506 &legacy_status);
Yaniv Rosner52c4d6c2011-07-05 01:06:34 +000010507 DP(NETIF_MSG_LINK, "54618SE read_status: 0x%x\n", legacy_status);
Yaniv Rosner6583e332011-06-14 01:34:17 +000010508
10509 /* Read status to clear the PHY interrupt. */
10510 bnx2x_cl22_read(bp, phy,
10511 MDIO_REG_INTR_STATUS,
10512 &val);
10513
10514 link_up = ((legacy_status & (1<<2)) == (1<<2));
10515
10516 if (link_up) {
10517 legacy_speed = (legacy_status & (7<<8));
10518 if (legacy_speed == (7<<8)) {
10519 vars->line_speed = SPEED_1000;
10520 vars->duplex = DUPLEX_FULL;
10521 } else if (legacy_speed == (6<<8)) {
10522 vars->line_speed = SPEED_1000;
10523 vars->duplex = DUPLEX_HALF;
10524 } else if (legacy_speed == (5<<8)) {
10525 vars->line_speed = SPEED_100;
10526 vars->duplex = DUPLEX_FULL;
10527 }
10528 /* Omitting 100Base-T4 for now */
10529 else if (legacy_speed == (3<<8)) {
10530 vars->line_speed = SPEED_100;
10531 vars->duplex = DUPLEX_HALF;
10532 } else if (legacy_speed == (2<<8)) {
10533 vars->line_speed = SPEED_10;
10534 vars->duplex = DUPLEX_FULL;
10535 } else if (legacy_speed == (1<<8)) {
10536 vars->line_speed = SPEED_10;
10537 vars->duplex = DUPLEX_HALF;
10538 } else /* Should not happen */
10539 vars->line_speed = 0;
10540
Joe Perches94f05b02011-08-14 12:16:20 +000010541 DP(NETIF_MSG_LINK,
10542 "Link is up in %dMbps, is_duplex_full= %d\n",
10543 vars->line_speed,
10544 (vars->duplex == DUPLEX_FULL));
Yaniv Rosner6583e332011-06-14 01:34:17 +000010545
10546 /* Check legacy speed AN resolution */
10547 bnx2x_cl22_read(bp, phy,
10548 0x01,
10549 &val);
10550 if (val & (1<<5))
10551 vars->link_status |=
10552 LINK_STATUS_AUTO_NEGOTIATE_COMPLETE;
10553 bnx2x_cl22_read(bp, phy,
10554 0x06,
10555 &val);
10556 if ((val & (1<<0)) == 0)
10557 vars->link_status |=
10558 LINK_STATUS_PARALLEL_DETECTION_USED;
10559
Yaniv Rosner52c4d6c2011-07-05 01:06:34 +000010560 DP(NETIF_MSG_LINK, "BCM54618SE: link speed is %d\n",
Yaniv Rosner6583e332011-06-14 01:34:17 +000010561 vars->line_speed);
Yaniv Rosner52c4d6c2011-07-05 01:06:34 +000010562
10563 /* Report whether EEE is resolved. */
10564 bnx2x_cl22_read(bp, phy, MDIO_REG_GPHY_PHYID_LSB, &val);
10565 if (val == MDIO_REG_GPHY_ID_54618SE) {
10566 if (vars->link_status &
10567 LINK_STATUS_AUTO_NEGOTIATE_COMPLETE)
10568 val = 0;
10569 else {
10570 bnx2x_cl22_write(bp, phy,
10571 MDIO_REG_GPHY_CL45_ADDR_REG,
10572 MDIO_AN_DEVAD);
10573 bnx2x_cl22_write(bp, phy,
10574 MDIO_REG_GPHY_CL45_DATA_REG,
10575 MDIO_REG_GPHY_EEE_RESOLVED);
10576 bnx2x_cl22_write(bp, phy,
10577 MDIO_REG_GPHY_CL45_ADDR_REG,
10578 (0x1 << 14) | MDIO_AN_DEVAD);
10579 bnx2x_cl22_read(bp, phy,
10580 MDIO_REG_GPHY_CL45_DATA_REG,
10581 &val);
10582 }
10583 DP(NETIF_MSG_LINK, "EEE resolution: 0x%x\n", val);
10584 }
10585
Yaniv Rosner6583e332011-06-14 01:34:17 +000010586 bnx2x_ext_phy_resolve_fc(phy, params, vars);
10587 }
10588 return link_up;
10589}
10590
Yaniv Rosner52c4d6c2011-07-05 01:06:34 +000010591static void bnx2x_54618se_config_loopback(struct bnx2x_phy *phy,
10592 struct link_params *params)
Yaniv Rosner6583e332011-06-14 01:34:17 +000010593{
10594 struct bnx2x *bp = params->bp;
10595 u16 val;
10596 u32 umac_base = params->port ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
10597
Yaniv Rosner52c4d6c2011-07-05 01:06:34 +000010598 DP(NETIF_MSG_LINK, "2PMA/PMD ext_phy_loopback: 54618se\n");
Yaniv Rosner6583e332011-06-14 01:34:17 +000010599
10600 /* Enable master/slave manual mmode and set to master */
10601 /* mii write 9 [bits set 11 12] */
10602 bnx2x_cl22_write(bp, phy, 0x09, 3<<11);
10603
10604 /* forced 1G and disable autoneg */
10605 /* set val [mii read 0] */
10606 /* set val [expr $val & [bits clear 6 12 13]] */
10607 /* set val [expr $val | [bits set 6 8]] */
10608 /* mii write 0 $val */
10609 bnx2x_cl22_read(bp, phy, 0x00, &val);
10610 val &= ~((1<<6) | (1<<12) | (1<<13));
10611 val |= (1<<6) | (1<<8);
10612 bnx2x_cl22_write(bp, phy, 0x00, val);
10613
10614 /* Set external loopback and Tx using 6dB coding */
10615 /* mii write 0x18 7 */
10616 /* set val [mii read 0x18] */
10617 /* mii write 0x18 [expr $val | [bits set 10 15]] */
10618 bnx2x_cl22_write(bp, phy, 0x18, 7);
10619 bnx2x_cl22_read(bp, phy, 0x18, &val);
10620 bnx2x_cl22_write(bp, phy, 0x18, val | (1<<10) | (1<<15));
10621
10622 /* This register opens the gate for the UMAC despite its name */
10623 REG_WR(bp, NIG_REG_EGRESS_EMAC0_PORT + params->port*4, 1);
10624
10625 /*
10626 * Maximum Frame Length (RW). Defines a 14-Bit maximum frame
10627 * length used by the MAC receive logic to check frames.
10628 */
10629 REG_WR(bp, umac_base + UMAC_REG_MAXFR, 0x2710);
10630}
10631
10632/******************************************************************/
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010633/* SFX7101 PHY SECTION */
10634/******************************************************************/
10635static void bnx2x_7101_config_loopback(struct bnx2x_phy *phy,
10636 struct link_params *params)
10637{
10638 struct bnx2x *bp = params->bp;
10639 /* SFX7101_XGXS_TEST1 */
10640 bnx2x_cl45_write(bp, phy,
10641 MDIO_XS_DEVAD, MDIO_XS_SFX7101_XGXS_TEST1, 0x100);
10642}
10643
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000010644static int bnx2x_7101_config_init(struct bnx2x_phy *phy,
10645 struct link_params *params,
10646 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010647{
10648 u16 fw_ver1, fw_ver2, val;
10649 struct bnx2x *bp = params->bp;
10650 DP(NETIF_MSG_LINK, "Setting the SFX7101 LASI indication\n");
10651
10652 /* Restore normal power mode*/
10653 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010654 MISC_REGISTERS_GPIO_OUTPUT_HIGH, params->port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010655 /* HW reset */
10656 bnx2x_ext_phy_hw_reset(bp, params->port);
Yaniv Rosner6d870c32011-01-31 04:22:20 +000010657 bnx2x_wait_reset_complete(bp, phy, params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010658
10659 bnx2x_cl45_write(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +000010660 MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL, 0x1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010661 DP(NETIF_MSG_LINK, "Setting the SFX7101 LED to blink on traffic\n");
10662 bnx2x_cl45_write(bp, phy,
10663 MDIO_PMA_DEVAD, MDIO_PMA_REG_7107_LED_CNTL, (1<<3));
10664
10665 bnx2x_ext_phy_set_pause(params, phy, vars);
10666 /* Restart autoneg */
10667 bnx2x_cl45_read(bp, phy,
10668 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, &val);
10669 val |= 0x200;
10670 bnx2x_cl45_write(bp, phy,
10671 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, val);
10672
10673 /* Save spirom version */
10674 bnx2x_cl45_read(bp, phy,
10675 MDIO_PMA_DEVAD, MDIO_PMA_REG_7101_VER1, &fw_ver1);
10676
10677 bnx2x_cl45_read(bp, phy,
10678 MDIO_PMA_DEVAD, MDIO_PMA_REG_7101_VER2, &fw_ver2);
10679 bnx2x_save_spirom_version(bp, params->port,
10680 (u32)(fw_ver1<<16 | fw_ver2), phy->ver_addr);
10681 return 0;
10682}
10683
10684static u8 bnx2x_7101_read_status(struct bnx2x_phy *phy,
10685 struct link_params *params,
10686 struct link_vars *vars)
10687{
10688 struct bnx2x *bp = params->bp;
10689 u8 link_up;
10690 u16 val1, val2;
10691 bnx2x_cl45_read(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +000010692 MDIO_PMA_DEVAD, MDIO_PMA_LASI_STAT, &val2);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010693 bnx2x_cl45_read(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +000010694 MDIO_PMA_DEVAD, MDIO_PMA_LASI_STAT, &val1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010695 DP(NETIF_MSG_LINK, "10G-base-T LASI status 0x%x->0x%x\n",
10696 val2, val1);
10697 bnx2x_cl45_read(bp, phy,
10698 MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val2);
10699 bnx2x_cl45_read(bp, phy,
10700 MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val1);
10701 DP(NETIF_MSG_LINK, "10G-base-T PMA status 0x%x->0x%x\n",
10702 val2, val1);
10703 link_up = ((val1 & 4) == 4);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +000010704 /* if link is up print the AN outcome of the SFX7101 PHY */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010705 if (link_up) {
10706 bnx2x_cl45_read(bp, phy,
10707 MDIO_AN_DEVAD, MDIO_AN_REG_MASTER_STATUS,
10708 &val2);
10709 vars->line_speed = SPEED_10000;
Yaniv Rosner791f18c2011-01-18 04:33:42 +000010710 vars->duplex = DUPLEX_FULL;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010711 DP(NETIF_MSG_LINK, "SFX7101 AN status 0x%x->Master=%x\n",
10712 val2, (val2 & (1<<14)));
10713 bnx2x_ext_phy_10G_an_resolve(bp, phy, vars);
10714 bnx2x_ext_phy_resolve_fc(phy, params, vars);
10715 }
10716 return link_up;
10717}
10718
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000010719static int bnx2x_7101_format_ver(u32 spirom_ver, u8 *str, u16 *len)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010720{
10721 if (*len < 5)
10722 return -EINVAL;
10723 str[0] = (spirom_ver & 0xFF);
10724 str[1] = (spirom_ver & 0xFF00) >> 8;
10725 str[2] = (spirom_ver & 0xFF0000) >> 16;
10726 str[3] = (spirom_ver & 0xFF000000) >> 24;
10727 str[4] = '\0';
10728 *len -= 5;
10729 return 0;
10730}
10731
10732void bnx2x_sfx7101_sp_sw_reset(struct bnx2x *bp, struct bnx2x_phy *phy)
10733{
10734 u16 val, cnt;
10735
10736 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010737 MDIO_PMA_DEVAD,
10738 MDIO_PMA_REG_7101_RESET, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010739
10740 for (cnt = 0; cnt < 10; cnt++) {
10741 msleep(50);
10742 /* Writes a self-clearing reset */
10743 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010744 MDIO_PMA_DEVAD,
10745 MDIO_PMA_REG_7101_RESET,
10746 (val | (1<<15)));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010747 /* Wait for clear */
10748 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010749 MDIO_PMA_DEVAD,
10750 MDIO_PMA_REG_7101_RESET, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010751
10752 if ((val & (1<<15)) == 0)
10753 break;
10754 }
10755}
10756
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010757static void bnx2x_7101_hw_reset(struct bnx2x_phy *phy,
10758 struct link_params *params) {
10759 /* Low power mode is controlled by GPIO 2 */
10760 bnx2x_set_gpio(params->bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010761 MISC_REGISTERS_GPIO_OUTPUT_LOW, params->port);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010762 /* The PHY reset is controlled by GPIO 1 */
10763 bnx2x_set_gpio(params->bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010764 MISC_REGISTERS_GPIO_OUTPUT_LOW, params->port);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010765}
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010766
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010767static void bnx2x_7101_set_link_led(struct bnx2x_phy *phy,
10768 struct link_params *params, u8 mode)
10769{
10770 u16 val = 0;
10771 struct bnx2x *bp = params->bp;
10772 switch (mode) {
10773 case LED_MODE_FRONT_PANEL_OFF:
10774 case LED_MODE_OFF:
10775 val = 2;
10776 break;
10777 case LED_MODE_ON:
10778 val = 1;
10779 break;
10780 case LED_MODE_OPER:
10781 val = 0;
10782 break;
10783 }
10784 bnx2x_cl45_write(bp, phy,
10785 MDIO_PMA_DEVAD,
10786 MDIO_PMA_REG_7107_LINK_LED_CNTL,
10787 val);
10788}
10789
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010790/******************************************************************/
10791/* STATIC PHY DECLARATION */
10792/******************************************************************/
10793
10794static struct bnx2x_phy phy_null = {
10795 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN,
10796 .addr = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010797 .def_md_devad = 0,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000010798 .flags = FLAGS_INIT_XGXS_FIRST,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010799 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
10800 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
10801 .mdio_ctrl = 0,
10802 .supported = 0,
10803 .media_type = ETH_PHY_NOT_PRESENT,
10804 .ver_addr = 0,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010805 .req_flow_ctrl = 0,
10806 .req_line_speed = 0,
10807 .speed_cap_mask = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010808 .req_duplex = 0,
10809 .rsrv = 0,
10810 .config_init = (config_init_t)NULL,
10811 .read_status = (read_status_t)NULL,
10812 .link_reset = (link_reset_t)NULL,
10813 .config_loopback = (config_loopback_t)NULL,
10814 .format_fw_ver = (format_fw_ver_t)NULL,
10815 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010816 .set_link_led = (set_link_led_t)NULL,
10817 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010818};
10819
10820static struct bnx2x_phy phy_serdes = {
10821 .type = PORT_HW_CFG_SERDES_EXT_PHY_TYPE_DIRECT,
10822 .addr = 0xff,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010823 .def_md_devad = 0,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000010824 .flags = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010825 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
10826 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
10827 .mdio_ctrl = 0,
10828 .supported = (SUPPORTED_10baseT_Half |
10829 SUPPORTED_10baseT_Full |
10830 SUPPORTED_100baseT_Half |
10831 SUPPORTED_100baseT_Full |
10832 SUPPORTED_1000baseT_Full |
10833 SUPPORTED_2500baseX_Full |
10834 SUPPORTED_TP |
10835 SUPPORTED_Autoneg |
10836 SUPPORTED_Pause |
10837 SUPPORTED_Asym_Pause),
Yaniv Rosner1ac9e422011-05-31 21:26:11 +000010838 .media_type = ETH_PHY_BASE_T,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010839 .ver_addr = 0,
10840 .req_flow_ctrl = 0,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010841 .req_line_speed = 0,
10842 .speed_cap_mask = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010843 .req_duplex = 0,
10844 .rsrv = 0,
Yaniv Rosnerec146a62011-05-31 21:29:27 +000010845 .config_init = (config_init_t)bnx2x_xgxs_config_init,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010846 .read_status = (read_status_t)bnx2x_link_settings_status,
10847 .link_reset = (link_reset_t)bnx2x_int_link_reset,
10848 .config_loopback = (config_loopback_t)NULL,
10849 .format_fw_ver = (format_fw_ver_t)NULL,
10850 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010851 .set_link_led = (set_link_led_t)NULL,
10852 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010853};
10854
10855static struct bnx2x_phy phy_xgxs = {
10856 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT,
10857 .addr = 0xff,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010858 .def_md_devad = 0,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000010859 .flags = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010860 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
10861 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
10862 .mdio_ctrl = 0,
10863 .supported = (SUPPORTED_10baseT_Half |
10864 SUPPORTED_10baseT_Full |
10865 SUPPORTED_100baseT_Half |
10866 SUPPORTED_100baseT_Full |
10867 SUPPORTED_1000baseT_Full |
10868 SUPPORTED_2500baseX_Full |
10869 SUPPORTED_10000baseT_Full |
10870 SUPPORTED_FIBRE |
10871 SUPPORTED_Autoneg |
10872 SUPPORTED_Pause |
10873 SUPPORTED_Asym_Pause),
Yaniv Rosner1ac9e422011-05-31 21:26:11 +000010874 .media_type = ETH_PHY_CX4,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010875 .ver_addr = 0,
10876 .req_flow_ctrl = 0,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010877 .req_line_speed = 0,
10878 .speed_cap_mask = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010879 .req_duplex = 0,
10880 .rsrv = 0,
Yaniv Rosnerec146a62011-05-31 21:29:27 +000010881 .config_init = (config_init_t)bnx2x_xgxs_config_init,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010882 .read_status = (read_status_t)bnx2x_link_settings_status,
10883 .link_reset = (link_reset_t)bnx2x_int_link_reset,
10884 .config_loopback = (config_loopback_t)bnx2x_set_xgxs_loopback,
10885 .format_fw_ver = (format_fw_ver_t)NULL,
10886 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010887 .set_link_led = (set_link_led_t)NULL,
10888 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010889};
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000010890static struct bnx2x_phy phy_warpcore = {
10891 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT,
10892 .addr = 0xff,
10893 .def_md_devad = 0,
David S. Miller8decf862011-09-22 03:23:13 -040010894 .flags = FLAGS_HW_LOCK_REQUIRED,
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000010895 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
10896 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
10897 .mdio_ctrl = 0,
10898 .supported = (SUPPORTED_10baseT_Half |
10899 SUPPORTED_10baseT_Full |
10900 SUPPORTED_100baseT_Half |
10901 SUPPORTED_100baseT_Full |
10902 SUPPORTED_1000baseT_Full |
10903 SUPPORTED_10000baseT_Full |
10904 SUPPORTED_20000baseKR2_Full |
10905 SUPPORTED_20000baseMLD2_Full |
10906 SUPPORTED_FIBRE |
10907 SUPPORTED_Autoneg |
10908 SUPPORTED_Pause |
10909 SUPPORTED_Asym_Pause),
10910 .media_type = ETH_PHY_UNSPECIFIED,
10911 .ver_addr = 0,
10912 .req_flow_ctrl = 0,
10913 .req_line_speed = 0,
10914 .speed_cap_mask = 0,
10915 /* req_duplex = */0,
10916 /* rsrv = */0,
10917 .config_init = (config_init_t)bnx2x_warpcore_config_init,
10918 .read_status = (read_status_t)bnx2x_warpcore_read_status,
10919 .link_reset = (link_reset_t)bnx2x_warpcore_link_reset,
10920 .config_loopback = (config_loopback_t)bnx2x_set_warpcore_loopback,
10921 .format_fw_ver = (format_fw_ver_t)NULL,
Yaniv Rosner985848f2011-07-05 01:06:48 +000010922 .hw_reset = (hw_reset_t)bnx2x_warpcore_hw_reset,
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000010923 .set_link_led = (set_link_led_t)NULL,
10924 .phy_specific_func = (phy_specific_func_t)NULL
10925};
10926
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010927
10928static struct bnx2x_phy phy_7101 = {
10929 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101,
10930 .addr = 0xff,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010931 .def_md_devad = 0,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000010932 .flags = FLAGS_FAN_FAILURE_DET_REQ,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010933 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
10934 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
10935 .mdio_ctrl = 0,
10936 .supported = (SUPPORTED_10000baseT_Full |
10937 SUPPORTED_TP |
10938 SUPPORTED_Autoneg |
10939 SUPPORTED_Pause |
10940 SUPPORTED_Asym_Pause),
10941 .media_type = ETH_PHY_BASE_T,
10942 .ver_addr = 0,
10943 .req_flow_ctrl = 0,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010944 .req_line_speed = 0,
10945 .speed_cap_mask = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010946 .req_duplex = 0,
10947 .rsrv = 0,
10948 .config_init = (config_init_t)bnx2x_7101_config_init,
10949 .read_status = (read_status_t)bnx2x_7101_read_status,
10950 .link_reset = (link_reset_t)bnx2x_common_ext_link_reset,
10951 .config_loopback = (config_loopback_t)bnx2x_7101_config_loopback,
10952 .format_fw_ver = (format_fw_ver_t)bnx2x_7101_format_ver,
10953 .hw_reset = (hw_reset_t)bnx2x_7101_hw_reset,
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010954 .set_link_led = (set_link_led_t)bnx2x_7101_set_link_led,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010955 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010956};
10957static struct bnx2x_phy phy_8073 = {
10958 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073,
10959 .addr = 0xff,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010960 .def_md_devad = 0,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000010961 .flags = FLAGS_HW_LOCK_REQUIRED,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010962 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
10963 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
10964 .mdio_ctrl = 0,
10965 .supported = (SUPPORTED_10000baseT_Full |
10966 SUPPORTED_2500baseX_Full |
10967 SUPPORTED_1000baseT_Full |
10968 SUPPORTED_FIBRE |
10969 SUPPORTED_Autoneg |
10970 SUPPORTED_Pause |
10971 SUPPORTED_Asym_Pause),
Yaniv Rosner1ac9e422011-05-31 21:26:11 +000010972 .media_type = ETH_PHY_KR,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010973 .ver_addr = 0,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010974 .req_flow_ctrl = 0,
10975 .req_line_speed = 0,
10976 .speed_cap_mask = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010977 .req_duplex = 0,
10978 .rsrv = 0,
Yaniv Rosner62b29a52010-09-07 11:40:58 +000010979 .config_init = (config_init_t)bnx2x_8073_config_init,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010980 .read_status = (read_status_t)bnx2x_8073_read_status,
10981 .link_reset = (link_reset_t)bnx2x_8073_link_reset,
10982 .config_loopback = (config_loopback_t)NULL,
10983 .format_fw_ver = (format_fw_ver_t)bnx2x_format_ver,
10984 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010985 .set_link_led = (set_link_led_t)NULL,
10986 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010987};
10988static struct bnx2x_phy phy_8705 = {
10989 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705,
10990 .addr = 0xff,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010991 .def_md_devad = 0,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000010992 .flags = FLAGS_INIT_XGXS_FIRST,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000010993 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
10994 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
10995 .mdio_ctrl = 0,
10996 .supported = (SUPPORTED_10000baseT_Full |
10997 SUPPORTED_FIBRE |
10998 SUPPORTED_Pause |
10999 SUPPORTED_Asym_Pause),
11000 .media_type = ETH_PHY_XFP_FIBER,
11001 .ver_addr = 0,
11002 .req_flow_ctrl = 0,
11003 .req_line_speed = 0,
11004 .speed_cap_mask = 0,
11005 .req_duplex = 0,
11006 .rsrv = 0,
11007 .config_init = (config_init_t)bnx2x_8705_config_init,
11008 .read_status = (read_status_t)bnx2x_8705_read_status,
11009 .link_reset = (link_reset_t)bnx2x_common_ext_link_reset,
11010 .config_loopback = (config_loopback_t)NULL,
11011 .format_fw_ver = (format_fw_ver_t)bnx2x_null_format_ver,
11012 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011013 .set_link_led = (set_link_led_t)NULL,
11014 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011015};
11016static struct bnx2x_phy phy_8706 = {
11017 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706,
11018 .addr = 0xff,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011019 .def_md_devad = 0,
David S. Miller8decf862011-09-22 03:23:13 -040011020 .flags = FLAGS_INIT_XGXS_FIRST,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011021 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11022 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11023 .mdio_ctrl = 0,
11024 .supported = (SUPPORTED_10000baseT_Full |
11025 SUPPORTED_1000baseT_Full |
11026 SUPPORTED_FIBRE |
11027 SUPPORTED_Pause |
11028 SUPPORTED_Asym_Pause),
11029 .media_type = ETH_PHY_SFP_FIBER,
11030 .ver_addr = 0,
11031 .req_flow_ctrl = 0,
11032 .req_line_speed = 0,
11033 .speed_cap_mask = 0,
11034 .req_duplex = 0,
11035 .rsrv = 0,
11036 .config_init = (config_init_t)bnx2x_8706_config_init,
11037 .read_status = (read_status_t)bnx2x_8706_read_status,
11038 .link_reset = (link_reset_t)bnx2x_common_ext_link_reset,
11039 .config_loopback = (config_loopback_t)NULL,
11040 .format_fw_ver = (format_fw_ver_t)bnx2x_format_ver,
11041 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011042 .set_link_led = (set_link_led_t)NULL,
11043 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011044};
11045
11046static struct bnx2x_phy phy_8726 = {
11047 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726,
11048 .addr = 0xff,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000011049 .def_md_devad = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011050 .flags = (FLAGS_HW_LOCK_REQUIRED |
David S. Miller8decf862011-09-22 03:23:13 -040011051 FLAGS_INIT_XGXS_FIRST),
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011052 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11053 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11054 .mdio_ctrl = 0,
11055 .supported = (SUPPORTED_10000baseT_Full |
11056 SUPPORTED_1000baseT_Full |
11057 SUPPORTED_Autoneg |
11058 SUPPORTED_FIBRE |
11059 SUPPORTED_Pause |
11060 SUPPORTED_Asym_Pause),
Yaniv Rosner1ac9e422011-05-31 21:26:11 +000011061 .media_type = ETH_PHY_NOT_PRESENT,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011062 .ver_addr = 0,
11063 .req_flow_ctrl = 0,
11064 .req_line_speed = 0,
11065 .speed_cap_mask = 0,
11066 .req_duplex = 0,
11067 .rsrv = 0,
11068 .config_init = (config_init_t)bnx2x_8726_config_init,
11069 .read_status = (read_status_t)bnx2x_8726_read_status,
11070 .link_reset = (link_reset_t)bnx2x_8726_link_reset,
11071 .config_loopback = (config_loopback_t)bnx2x_8726_config_loopback,
11072 .format_fw_ver = (format_fw_ver_t)bnx2x_format_ver,
11073 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011074 .set_link_led = (set_link_led_t)NULL,
11075 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011076};
11077
11078static struct bnx2x_phy phy_8727 = {
11079 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727,
11080 .addr = 0xff,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011081 .def_md_devad = 0,
David S. Miller8decf862011-09-22 03:23:13 -040011082 .flags = FLAGS_FAN_FAILURE_DET_REQ,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011083 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11084 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11085 .mdio_ctrl = 0,
11086 .supported = (SUPPORTED_10000baseT_Full |
11087 SUPPORTED_1000baseT_Full |
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011088 SUPPORTED_FIBRE |
11089 SUPPORTED_Pause |
11090 SUPPORTED_Asym_Pause),
Yaniv Rosner1ac9e422011-05-31 21:26:11 +000011091 .media_type = ETH_PHY_NOT_PRESENT,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011092 .ver_addr = 0,
11093 .req_flow_ctrl = 0,
11094 .req_line_speed = 0,
11095 .speed_cap_mask = 0,
11096 .req_duplex = 0,
11097 .rsrv = 0,
11098 .config_init = (config_init_t)bnx2x_8727_config_init,
11099 .read_status = (read_status_t)bnx2x_8727_read_status,
11100 .link_reset = (link_reset_t)bnx2x_8727_link_reset,
11101 .config_loopback = (config_loopback_t)NULL,
11102 .format_fw_ver = (format_fw_ver_t)bnx2x_format_ver,
11103 .hw_reset = (hw_reset_t)bnx2x_8727_hw_reset,
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000011104 .set_link_led = (set_link_led_t)bnx2x_8727_set_link_led,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011105 .phy_specific_func = (phy_specific_func_t)bnx2x_8727_specific_func
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011106};
11107static struct bnx2x_phy phy_8481 = {
11108 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8481,
11109 .addr = 0xff,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000011110 .def_md_devad = 0,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011111 .flags = FLAGS_FAN_FAILURE_DET_REQ |
11112 FLAGS_REARM_LATCH_SIGNAL,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011113 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11114 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11115 .mdio_ctrl = 0,
11116 .supported = (SUPPORTED_10baseT_Half |
11117 SUPPORTED_10baseT_Full |
11118 SUPPORTED_100baseT_Half |
11119 SUPPORTED_100baseT_Full |
11120 SUPPORTED_1000baseT_Full |
11121 SUPPORTED_10000baseT_Full |
11122 SUPPORTED_TP |
11123 SUPPORTED_Autoneg |
11124 SUPPORTED_Pause |
11125 SUPPORTED_Asym_Pause),
11126 .media_type = ETH_PHY_BASE_T,
11127 .ver_addr = 0,
11128 .req_flow_ctrl = 0,
11129 .req_line_speed = 0,
11130 .speed_cap_mask = 0,
11131 .req_duplex = 0,
11132 .rsrv = 0,
11133 .config_init = (config_init_t)bnx2x_8481_config_init,
11134 .read_status = (read_status_t)bnx2x_848xx_read_status,
11135 .link_reset = (link_reset_t)bnx2x_8481_link_reset,
11136 .config_loopback = (config_loopback_t)NULL,
11137 .format_fw_ver = (format_fw_ver_t)bnx2x_848xx_format_ver,
11138 .hw_reset = (hw_reset_t)bnx2x_8481_hw_reset,
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000011139 .set_link_led = (set_link_led_t)bnx2x_848xx_set_link_led,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011140 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011141};
11142
11143static struct bnx2x_phy phy_84823 = {
11144 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84823,
11145 .addr = 0xff,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000011146 .def_md_devad = 0,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011147 .flags = FLAGS_FAN_FAILURE_DET_REQ |
11148 FLAGS_REARM_LATCH_SIGNAL,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011149 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11150 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11151 .mdio_ctrl = 0,
11152 .supported = (SUPPORTED_10baseT_Half |
11153 SUPPORTED_10baseT_Full |
11154 SUPPORTED_100baseT_Half |
11155 SUPPORTED_100baseT_Full |
11156 SUPPORTED_1000baseT_Full |
11157 SUPPORTED_10000baseT_Full |
11158 SUPPORTED_TP |
11159 SUPPORTED_Autoneg |
11160 SUPPORTED_Pause |
11161 SUPPORTED_Asym_Pause),
11162 .media_type = ETH_PHY_BASE_T,
11163 .ver_addr = 0,
11164 .req_flow_ctrl = 0,
11165 .req_line_speed = 0,
11166 .speed_cap_mask = 0,
11167 .req_duplex = 0,
11168 .rsrv = 0,
11169 .config_init = (config_init_t)bnx2x_848x3_config_init,
11170 .read_status = (read_status_t)bnx2x_848xx_read_status,
11171 .link_reset = (link_reset_t)bnx2x_848x3_link_reset,
11172 .config_loopback = (config_loopback_t)NULL,
11173 .format_fw_ver = (format_fw_ver_t)bnx2x_848xx_format_ver,
11174 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000011175 .set_link_led = (set_link_led_t)bnx2x_848xx_set_link_led,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011176 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011177};
11178
Yaniv Rosnerc87bca12011-01-31 04:22:41 +000011179static struct bnx2x_phy phy_84833 = {
11180 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833,
11181 .addr = 0xff,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000011182 .def_md_devad = 0,
Yaniv Rosnerc87bca12011-01-31 04:22:41 +000011183 .flags = FLAGS_FAN_FAILURE_DET_REQ |
11184 FLAGS_REARM_LATCH_SIGNAL,
Yaniv Rosnerc87bca12011-01-31 04:22:41 +000011185 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11186 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11187 .mdio_ctrl = 0,
Yaniv Rosner0520e632011-07-05 01:06:59 +000011188 .supported = (SUPPORTED_100baseT_Half |
Yaniv Rosnerc87bca12011-01-31 04:22:41 +000011189 SUPPORTED_100baseT_Full |
11190 SUPPORTED_1000baseT_Full |
11191 SUPPORTED_10000baseT_Full |
11192 SUPPORTED_TP |
11193 SUPPORTED_Autoneg |
11194 SUPPORTED_Pause |
11195 SUPPORTED_Asym_Pause),
11196 .media_type = ETH_PHY_BASE_T,
11197 .ver_addr = 0,
11198 .req_flow_ctrl = 0,
11199 .req_line_speed = 0,
11200 .speed_cap_mask = 0,
11201 .req_duplex = 0,
11202 .rsrv = 0,
11203 .config_init = (config_init_t)bnx2x_848x3_config_init,
11204 .read_status = (read_status_t)bnx2x_848xx_read_status,
11205 .link_reset = (link_reset_t)bnx2x_848x3_link_reset,
11206 .config_loopback = (config_loopback_t)NULL,
11207 .format_fw_ver = (format_fw_ver_t)bnx2x_848xx_format_ver,
Yaniv Rosner985848f2011-07-05 01:06:48 +000011208 .hw_reset = (hw_reset_t)bnx2x_84833_hw_reset_phy,
Yaniv Rosnerc87bca12011-01-31 04:22:41 +000011209 .set_link_led = (set_link_led_t)bnx2x_848xx_set_link_led,
11210 .phy_specific_func = (phy_specific_func_t)NULL
11211};
11212
Yaniv Rosner52c4d6c2011-07-05 01:06:34 +000011213static struct bnx2x_phy phy_54618se = {
11214 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54618SE,
Yaniv Rosner6583e332011-06-14 01:34:17 +000011215 .addr = 0xff,
11216 .def_md_devad = 0,
11217 .flags = FLAGS_INIT_XGXS_FIRST,
11218 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11219 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11220 .mdio_ctrl = 0,
11221 .supported = (SUPPORTED_10baseT_Half |
11222 SUPPORTED_10baseT_Full |
11223 SUPPORTED_100baseT_Half |
11224 SUPPORTED_100baseT_Full |
11225 SUPPORTED_1000baseT_Full |
11226 SUPPORTED_TP |
11227 SUPPORTED_Autoneg |
11228 SUPPORTED_Pause |
11229 SUPPORTED_Asym_Pause),
11230 .media_type = ETH_PHY_BASE_T,
11231 .ver_addr = 0,
11232 .req_flow_ctrl = 0,
11233 .req_line_speed = 0,
11234 .speed_cap_mask = 0,
11235 /* req_duplex = */0,
11236 /* rsrv = */0,
Yaniv Rosner52c4d6c2011-07-05 01:06:34 +000011237 .config_init = (config_init_t)bnx2x_54618se_config_init,
11238 .read_status = (read_status_t)bnx2x_54618se_read_status,
11239 .link_reset = (link_reset_t)bnx2x_54618se_link_reset,
11240 .config_loopback = (config_loopback_t)bnx2x_54618se_config_loopback,
Yaniv Rosner6583e332011-06-14 01:34:17 +000011241 .format_fw_ver = (format_fw_ver_t)NULL,
11242 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosner1d125bd2011-11-23 03:54:08 +000011243 .set_link_led = (set_link_led_t)bnx2x_5461x_set_link_led,
Yaniv Rosner6583e332011-06-14 01:34:17 +000011244 .phy_specific_func = (phy_specific_func_t)NULL
11245};
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011246/*****************************************************************/
11247/* */
11248/* Populate the phy according. Main function: bnx2x_populate_phy */
11249/* */
11250/*****************************************************************/
11251
11252static void bnx2x_populate_preemphasis(struct bnx2x *bp, u32 shmem_base,
11253 struct bnx2x_phy *phy, u8 port,
11254 u8 phy_index)
11255{
11256 /* Get the 4 lanes xgxs config rx and tx */
11257 u32 rx = 0, tx = 0, i;
11258 for (i = 0; i < 2; i++) {
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +000011259 /*
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011260 * INT_PHY and EXT_PHY1 share the same value location in the
11261 * shmem. When num_phys is greater than 1, than this value
11262 * applies only to EXT_PHY1
11263 */
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011264 if (phy_index == INT_PHY || phy_index == EXT_PHY1) {
11265 rx = REG_RD(bp, shmem_base +
11266 offsetof(struct shmem_region,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000011267 dev_info.port_hw_config[port].xgxs_config_rx[i<<1]));
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011268
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011269 tx = REG_RD(bp, shmem_base +
11270 offsetof(struct shmem_region,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000011271 dev_info.port_hw_config[port].xgxs_config_tx[i<<1]));
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011272 } else {
11273 rx = REG_RD(bp, shmem_base +
11274 offsetof(struct shmem_region,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000011275 dev_info.port_hw_config[port].xgxs_config2_rx[i<<1]));
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011276
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011277 tx = REG_RD(bp, shmem_base +
11278 offsetof(struct shmem_region,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000011279 dev_info.port_hw_config[port].xgxs_config2_rx[i<<1]));
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011280 }
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011281
11282 phy->rx_preemphasis[i << 1] = ((rx>>16) & 0xffff);
11283 phy->rx_preemphasis[(i << 1) + 1] = (rx & 0xffff);
11284
11285 phy->tx_preemphasis[i << 1] = ((tx>>16) & 0xffff);
11286 phy->tx_preemphasis[(i << 1) + 1] = (tx & 0xffff);
11287 }
11288}
11289
Yaniv Rosnere10bc842010-09-07 11:40:50 +000011290static u32 bnx2x_get_ext_phy_config(struct bnx2x *bp, u32 shmem_base,
11291 u8 phy_index, u8 port)
11292{
11293 u32 ext_phy_config = 0;
11294 switch (phy_index) {
11295 case EXT_PHY1:
11296 ext_phy_config = REG_RD(bp, shmem_base +
11297 offsetof(struct shmem_region,
11298 dev_info.port_hw_config[port].external_phy_config));
11299 break;
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011300 case EXT_PHY2:
11301 ext_phy_config = REG_RD(bp, shmem_base +
11302 offsetof(struct shmem_region,
11303 dev_info.port_hw_config[port].external_phy_config2));
11304 break;
Yaniv Rosnere10bc842010-09-07 11:40:50 +000011305 default:
11306 DP(NETIF_MSG_LINK, "Invalid phy_index %d\n", phy_index);
11307 return -EINVAL;
11308 }
11309
11310 return ext_phy_config;
11311}
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000011312static int bnx2x_populate_int_phy(struct bnx2x *bp, u32 shmem_base, u8 port,
11313 struct bnx2x_phy *phy)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011314{
11315 u32 phy_addr;
11316 u32 chip_id;
11317 u32 switch_cfg = (REG_RD(bp, shmem_base +
11318 offsetof(struct shmem_region,
11319 dev_info.port_feature_config[port].link_config)) &
11320 PORT_FEATURE_CONNECTED_SWITCH_MASK);
11321 chip_id = REG_RD(bp, MISC_REG_CHIP_NUM) << 16;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000011322 DP(NETIF_MSG_LINK, ":chip_id = 0x%x\n", chip_id);
11323 if (USES_WARPCORE(bp)) {
11324 u32 serdes_net_if;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011325 phy_addr = REG_RD(bp,
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000011326 MISC_REG_WC0_CTRL_PHY_ADDR);
11327 *phy = phy_warpcore;
11328 if (REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR) == 0x3)
11329 phy->flags |= FLAGS_4_PORT_MODE;
11330 else
11331 phy->flags &= ~FLAGS_4_PORT_MODE;
11332 /* Check Dual mode */
11333 serdes_net_if = (REG_RD(bp, shmem_base +
11334 offsetof(struct shmem_region, dev_info.
11335 port_hw_config[port].default_cfg)) &
11336 PORT_HW_CFG_NET_SERDES_IF_MASK);
11337 /*
11338 * Set the appropriate supported and flags indications per
11339 * interface type of the chip
11340 */
11341 switch (serdes_net_if) {
11342 case PORT_HW_CFG_NET_SERDES_IF_SGMII:
11343 phy->supported &= (SUPPORTED_10baseT_Half |
11344 SUPPORTED_10baseT_Full |
11345 SUPPORTED_100baseT_Half |
11346 SUPPORTED_100baseT_Full |
11347 SUPPORTED_1000baseT_Full |
11348 SUPPORTED_FIBRE |
11349 SUPPORTED_Autoneg |
11350 SUPPORTED_Pause |
11351 SUPPORTED_Asym_Pause);
11352 phy->media_type = ETH_PHY_BASE_T;
11353 break;
11354 case PORT_HW_CFG_NET_SERDES_IF_XFI:
11355 phy->media_type = ETH_PHY_XFP_FIBER;
11356 break;
11357 case PORT_HW_CFG_NET_SERDES_IF_SFI:
11358 phy->supported &= (SUPPORTED_1000baseT_Full |
11359 SUPPORTED_10000baseT_Full |
11360 SUPPORTED_FIBRE |
11361 SUPPORTED_Pause |
11362 SUPPORTED_Asym_Pause);
11363 phy->media_type = ETH_PHY_SFP_FIBER;
11364 break;
11365 case PORT_HW_CFG_NET_SERDES_IF_KR:
11366 phy->media_type = ETH_PHY_KR;
11367 phy->supported &= (SUPPORTED_1000baseT_Full |
11368 SUPPORTED_10000baseT_Full |
11369 SUPPORTED_FIBRE |
11370 SUPPORTED_Autoneg |
11371 SUPPORTED_Pause |
11372 SUPPORTED_Asym_Pause);
11373 break;
11374 case PORT_HW_CFG_NET_SERDES_IF_DXGXS:
11375 phy->media_type = ETH_PHY_KR;
11376 phy->flags |= FLAGS_WC_DUAL_MODE;
11377 phy->supported &= (SUPPORTED_20000baseMLD2_Full |
11378 SUPPORTED_FIBRE |
11379 SUPPORTED_Pause |
11380 SUPPORTED_Asym_Pause);
11381 break;
11382 case PORT_HW_CFG_NET_SERDES_IF_KR2:
11383 phy->media_type = ETH_PHY_KR;
11384 phy->flags |= FLAGS_WC_DUAL_MODE;
11385 phy->supported &= (SUPPORTED_20000baseKR2_Full |
11386 SUPPORTED_FIBRE |
11387 SUPPORTED_Pause |
11388 SUPPORTED_Asym_Pause);
11389 break;
11390 default:
11391 DP(NETIF_MSG_LINK, "Unknown WC interface type 0x%x\n",
11392 serdes_net_if);
11393 break;
11394 }
11395
11396 /*
11397 * Enable MDC/MDIO work-around for E3 A0 since free running MDC
11398 * was not set as expected. For B0, ECO will be enabled so there
11399 * won't be an issue there
11400 */
11401 if (CHIP_REV(bp) == CHIP_REV_Ax)
11402 phy->flags |= FLAGS_MDC_MDIO_WA;
Yaniv Rosner157fa282011-08-02 22:59:32 +000011403 else
11404 phy->flags |= FLAGS_MDC_MDIO_WA_B0;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000011405 } else {
11406 switch (switch_cfg) {
11407 case SWITCH_CFG_1G:
11408 phy_addr = REG_RD(bp,
11409 NIG_REG_SERDES0_CTRL_PHY_ADDR +
11410 port * 0x10);
11411 *phy = phy_serdes;
11412 break;
11413 case SWITCH_CFG_10G:
11414 phy_addr = REG_RD(bp,
11415 NIG_REG_XGXS0_CTRL_PHY_ADDR +
11416 port * 0x18);
11417 *phy = phy_xgxs;
11418 break;
11419 default:
11420 DP(NETIF_MSG_LINK, "Invalid switch_cfg\n");
11421 return -EINVAL;
11422 }
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011423 }
11424 phy->addr = (u8)phy_addr;
11425 phy->mdio_ctrl = bnx2x_get_emac_base(bp,
Yaniv Rosnerc18aa152010-09-07 11:41:07 +000011426 SHARED_HW_CFG_MDC_MDIO_ACCESS1_BOTH,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011427 port);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000011428 if (CHIP_IS_E2(bp))
11429 phy->def_md_devad = E2_DEFAULT_PHY_DEV_ADDR;
11430 else
11431 phy->def_md_devad = DEFAULT_PHY_DEV_ADDR;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011432
11433 DP(NETIF_MSG_LINK, "Internal phy port=%d, addr=0x%x, mdio_ctl=0x%x\n",
11434 port, phy->addr, phy->mdio_ctrl);
11435
11436 bnx2x_populate_preemphasis(bp, shmem_base, phy, port, INT_PHY);
11437 return 0;
11438}
Yaniv Rosnere10bc842010-09-07 11:40:50 +000011439
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000011440static int bnx2x_populate_ext_phy(struct bnx2x *bp,
11441 u8 phy_index,
11442 u32 shmem_base,
11443 u32 shmem2_base,
11444 u8 port,
11445 struct bnx2x_phy *phy)
Yaniv Rosnere10bc842010-09-07 11:40:50 +000011446{
Yaniv Rosnerc18aa152010-09-07 11:41:07 +000011447 u32 ext_phy_config, phy_type, config2;
11448 u32 mdc_mdio_access = SHARED_HW_CFG_MDC_MDIO_ACCESS1_BOTH;
Yaniv Rosnere10bc842010-09-07 11:40:50 +000011449 ext_phy_config = bnx2x_get_ext_phy_config(bp, shmem_base,
11450 phy_index, port);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011451 phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
11452 /* Select the phy type */
11453 switch (phy_type) {
11454 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073:
Yaniv Rosnerc18aa152010-09-07 11:41:07 +000011455 mdc_mdio_access = SHARED_HW_CFG_MDC_MDIO_ACCESS1_SWAPPED;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011456 *phy = phy_8073;
11457 break;
11458 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705:
11459 *phy = phy_8705;
11460 break;
11461 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706:
11462 *phy = phy_8706;
11463 break;
11464 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
Yaniv Rosnerc18aa152010-09-07 11:41:07 +000011465 mdc_mdio_access = SHARED_HW_CFG_MDC_MDIO_ACCESS1_EMAC1;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011466 *phy = phy_8726;
11467 break;
11468 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727_NOC:
11469 /* BCM8727_NOC => BCM8727 no over current */
Yaniv Rosnerc18aa152010-09-07 11:41:07 +000011470 mdc_mdio_access = SHARED_HW_CFG_MDC_MDIO_ACCESS1_EMAC1;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011471 *phy = phy_8727;
11472 phy->flags |= FLAGS_NOC;
11473 break;
Yaniv Rosnere4d78f12011-05-31 21:25:55 +000011474 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8722:
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011475 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
Yaniv Rosnerc18aa152010-09-07 11:41:07 +000011476 mdc_mdio_access = SHARED_HW_CFG_MDC_MDIO_ACCESS1_EMAC1;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011477 *phy = phy_8727;
11478 break;
11479 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8481:
11480 *phy = phy_8481;
11481 break;
11482 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84823:
11483 *phy = phy_84823;
11484 break;
Yaniv Rosnerc87bca12011-01-31 04:22:41 +000011485 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833:
11486 *phy = phy_84833;
11487 break;
Yaniv Rosner3756a892011-08-23 06:33:24 +000011488 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54616:
Yaniv Rosner52c4d6c2011-07-05 01:06:34 +000011489 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54618SE:
11490 *phy = phy_54618se;
Yaniv Rosner6583e332011-06-14 01:34:17 +000011491 break;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011492 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101:
11493 *phy = phy_7101;
11494 break;
11495 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE:
11496 *phy = phy_null;
11497 return -EINVAL;
11498 default:
11499 *phy = phy_null;
11500 return 0;
11501 }
11502
Yaniv Rosnere10bc842010-09-07 11:40:50 +000011503 phy->addr = XGXS_EXT_PHY_ADDR(ext_phy_config);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011504 bnx2x_populate_preemphasis(bp, shmem_base, phy, port, phy_index);
Yaniv Rosner62b29a52010-09-07 11:40:58 +000011505
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +000011506 /*
11507 * The shmem address of the phy version is located on different
11508 * structures. In case this structure is too old, do not set
11509 * the address
11510 */
Yaniv Rosnerc18aa152010-09-07 11:41:07 +000011511 config2 = REG_RD(bp, shmem_base + offsetof(struct shmem_region,
11512 dev_info.shared_hw_config.config2));
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011513 if (phy_index == EXT_PHY1) {
11514 phy->ver_addr = shmem_base + offsetof(struct shmem_region,
11515 port_mb[port].ext_phy_fw_version);
Yaniv Rosnerc18aa152010-09-07 11:41:07 +000011516
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000011517 /* Check specific mdc mdio settings */
11518 if (config2 & SHARED_HW_CFG_MDC_MDIO_ACCESS1_MASK)
11519 mdc_mdio_access = config2 &
11520 SHARED_HW_CFG_MDC_MDIO_ACCESS1_MASK;
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011521 } else {
11522 u32 size = REG_RD(bp, shmem2_base);
Yaniv Rosnerc18aa152010-09-07 11:41:07 +000011523
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011524 if (size >
11525 offsetof(struct shmem2_region, ext_phy_fw_version2)) {
11526 phy->ver_addr = shmem2_base +
11527 offsetof(struct shmem2_region,
11528 ext_phy_fw_version2[port]);
11529 }
11530 /* Check specific mdc mdio settings */
11531 if (config2 & SHARED_HW_CFG_MDC_MDIO_ACCESS2_MASK)
11532 mdc_mdio_access = (config2 &
11533 SHARED_HW_CFG_MDC_MDIO_ACCESS2_MASK) >>
11534 (SHARED_HW_CFG_MDC_MDIO_ACCESS2_SHIFT -
11535 SHARED_HW_CFG_MDC_MDIO_ACCESS1_SHIFT);
11536 }
Yaniv Rosnerc18aa152010-09-07 11:41:07 +000011537 phy->mdio_ctrl = bnx2x_get_emac_base(bp, mdc_mdio_access, port);
11538
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +000011539 /*
Yaniv Rosnerc18aa152010-09-07 11:41:07 +000011540 * In case mdc/mdio_access of the external phy is different than the
11541 * mdc/mdio access of the XGXS, a HW lock must be taken in each access
11542 * to prevent one port interfere with another port's CL45 operations.
11543 */
11544 if (mdc_mdio_access != SHARED_HW_CFG_MDC_MDIO_ACCESS1_BOTH)
11545 phy->flags |= FLAGS_HW_LOCK_REQUIRED;
11546 DP(NETIF_MSG_LINK, "phy_type 0x%x port %d found in index %d\n",
11547 phy_type, port, phy_index);
11548 DP(NETIF_MSG_LINK, " addr=0x%x, mdio_ctl=0x%x\n",
11549 phy->addr, phy->mdio_ctrl);
Yaniv Rosnere10bc842010-09-07 11:40:50 +000011550 return 0;
11551}
11552
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000011553static int bnx2x_populate_phy(struct bnx2x *bp, u8 phy_index, u32 shmem_base,
11554 u32 shmem2_base, u8 port, struct bnx2x_phy *phy)
Yaniv Rosnere10bc842010-09-07 11:40:50 +000011555{
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000011556 int status = 0;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011557 phy->type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN;
11558 if (phy_index == INT_PHY)
11559 return bnx2x_populate_int_phy(bp, shmem_base, port, phy);
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011560 status = bnx2x_populate_ext_phy(bp, phy_index, shmem_base, shmem2_base,
Yaniv Rosnere10bc842010-09-07 11:40:50 +000011561 port, phy);
11562 return status;
11563}
11564
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011565static void bnx2x_phy_def_cfg(struct link_params *params,
11566 struct bnx2x_phy *phy,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011567 u8 phy_index)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011568{
11569 struct bnx2x *bp = params->bp;
11570 u32 link_config;
11571 /* Populate the default phy configuration for MF mode */
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011572 if (phy_index == EXT_PHY2) {
11573 link_config = REG_RD(bp, params->shmem_base +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000011574 offsetof(struct shmem_region, dev_info.
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011575 port_feature_config[params->port].link_config2));
11576 phy->speed_cap_mask = REG_RD(bp, params->shmem_base +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000011577 offsetof(struct shmem_region,
11578 dev_info.
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011579 port_hw_config[params->port].speed_capability_mask2));
11580 } else {
11581 link_config = REG_RD(bp, params->shmem_base +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000011582 offsetof(struct shmem_region, dev_info.
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011583 port_feature_config[params->port].link_config));
11584 phy->speed_cap_mask = REG_RD(bp, params->shmem_base +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000011585 offsetof(struct shmem_region,
11586 dev_info.
11587 port_hw_config[params->port].speed_capability_mask));
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011588 }
Joe Perches94f05b02011-08-14 12:16:20 +000011589 DP(NETIF_MSG_LINK,
11590 "Default config phy idx %x cfg 0x%x speed_cap_mask 0x%x\n",
11591 phy_index, link_config, phy->speed_cap_mask);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011592
11593 phy->req_duplex = DUPLEX_FULL;
11594 switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
11595 case PORT_FEATURE_LINK_SPEED_10M_HALF:
11596 phy->req_duplex = DUPLEX_HALF;
11597 case PORT_FEATURE_LINK_SPEED_10M_FULL:
11598 phy->req_line_speed = SPEED_10;
11599 break;
11600 case PORT_FEATURE_LINK_SPEED_100M_HALF:
11601 phy->req_duplex = DUPLEX_HALF;
11602 case PORT_FEATURE_LINK_SPEED_100M_FULL:
11603 phy->req_line_speed = SPEED_100;
11604 break;
11605 case PORT_FEATURE_LINK_SPEED_1G:
11606 phy->req_line_speed = SPEED_1000;
11607 break;
11608 case PORT_FEATURE_LINK_SPEED_2_5G:
11609 phy->req_line_speed = SPEED_2500;
11610 break;
11611 case PORT_FEATURE_LINK_SPEED_10G_CX4:
11612 phy->req_line_speed = SPEED_10000;
11613 break;
11614 default:
11615 phy->req_line_speed = SPEED_AUTO_NEG;
11616 break;
11617 }
11618
11619 switch (link_config & PORT_FEATURE_FLOW_CONTROL_MASK) {
11620 case PORT_FEATURE_FLOW_CONTROL_AUTO:
11621 phy->req_flow_ctrl = BNX2X_FLOW_CTRL_AUTO;
11622 break;
11623 case PORT_FEATURE_FLOW_CONTROL_TX:
11624 phy->req_flow_ctrl = BNX2X_FLOW_CTRL_TX;
11625 break;
11626 case PORT_FEATURE_FLOW_CONTROL_RX:
11627 phy->req_flow_ctrl = BNX2X_FLOW_CTRL_RX;
11628 break;
11629 case PORT_FEATURE_FLOW_CONTROL_BOTH:
11630 phy->req_flow_ctrl = BNX2X_FLOW_CTRL_BOTH;
11631 break;
11632 default:
11633 phy->req_flow_ctrl = BNX2X_FLOW_CTRL_NONE;
11634 break;
11635 }
11636}
11637
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011638u32 bnx2x_phy_selection(struct link_params *params)
11639{
11640 u32 phy_config_swapped, prio_cfg;
11641 u32 return_cfg = PORT_HW_CFG_PHY_SELECTION_HARDWARE_DEFAULT;
11642
11643 phy_config_swapped = params->multi_phy_config &
11644 PORT_HW_CFG_PHY_SWAPPED_ENABLED;
11645
11646 prio_cfg = params->multi_phy_config &
11647 PORT_HW_CFG_PHY_SELECTION_MASK;
11648
11649 if (phy_config_swapped) {
11650 switch (prio_cfg) {
11651 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY_PRIORITY:
11652 return_cfg = PORT_HW_CFG_PHY_SELECTION_SECOND_PHY_PRIORITY;
11653 break;
11654 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY_PRIORITY:
11655 return_cfg = PORT_HW_CFG_PHY_SELECTION_FIRST_PHY_PRIORITY;
11656 break;
11657 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY:
11658 return_cfg = PORT_HW_CFG_PHY_SELECTION_FIRST_PHY;
11659 break;
11660 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY:
11661 return_cfg = PORT_HW_CFG_PHY_SELECTION_SECOND_PHY;
11662 break;
11663 }
11664 } else
11665 return_cfg = prio_cfg;
11666
11667 return return_cfg;
11668}
11669
11670
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000011671int bnx2x_phy_probe(struct link_params *params)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011672{
11673 u8 phy_index, actual_phy_idx, link_cfg_idx;
Yaniv Rosner1ac9e422011-05-31 21:26:11 +000011674 u32 phy_config_swapped, sync_offset, media_types;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011675 struct bnx2x *bp = params->bp;
11676 struct bnx2x_phy *phy;
11677 params->num_phys = 0;
11678 DP(NETIF_MSG_LINK, "Begin phy probe\n");
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011679 phy_config_swapped = params->multi_phy_config &
11680 PORT_HW_CFG_PHY_SWAPPED_ENABLED;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011681
11682 for (phy_index = INT_PHY; phy_index < MAX_PHYS;
11683 phy_index++) {
11684 link_cfg_idx = LINK_CONFIG_IDX(phy_index);
11685 actual_phy_idx = phy_index;
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011686 if (phy_config_swapped) {
11687 if (phy_index == EXT_PHY1)
11688 actual_phy_idx = EXT_PHY2;
11689 else if (phy_index == EXT_PHY2)
11690 actual_phy_idx = EXT_PHY1;
11691 }
11692 DP(NETIF_MSG_LINK, "phy_config_swapped %x, phy_index %x,"
11693 " actual_phy_idx %x\n", phy_config_swapped,
11694 phy_index, actual_phy_idx);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011695 phy = &params->phy[actual_phy_idx];
11696 if (bnx2x_populate_phy(bp, phy_index, params->shmem_base,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011697 params->shmem2_base, params->port,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011698 phy) != 0) {
11699 params->num_phys = 0;
11700 DP(NETIF_MSG_LINK, "phy probe failed in phy index %d\n",
11701 phy_index);
11702 for (phy_index = INT_PHY;
11703 phy_index < MAX_PHYS;
11704 phy_index++)
11705 *phy = phy_null;
11706 return -EINVAL;
11707 }
11708 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN)
11709 break;
11710
Yaniv Rosner1ac9e422011-05-31 21:26:11 +000011711 sync_offset = params->shmem_base +
11712 offsetof(struct shmem_region,
11713 dev_info.port_hw_config[params->port].media_type);
11714 media_types = REG_RD(bp, sync_offset);
11715
11716 /*
11717 * Update media type for non-PMF sync only for the first time
11718 * In case the media type changes afterwards, it will be updated
11719 * using the update_status function
11720 */
11721 if ((media_types & (PORT_HW_CFG_MEDIA_TYPE_PHY0_MASK <<
11722 (PORT_HW_CFG_MEDIA_TYPE_PHY1_SHIFT *
11723 actual_phy_idx))) == 0) {
11724 media_types |= ((phy->media_type &
11725 PORT_HW_CFG_MEDIA_TYPE_PHY0_MASK) <<
11726 (PORT_HW_CFG_MEDIA_TYPE_PHY1_SHIFT *
11727 actual_phy_idx));
11728 }
11729 REG_WR(bp, sync_offset, media_types);
11730
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011731 bnx2x_phy_def_cfg(params, phy, phy_index);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011732 params->num_phys++;
11733 }
11734
11735 DP(NETIF_MSG_LINK, "End phy probe. #phys found %x\n", params->num_phys);
11736 return 0;
11737}
11738
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000011739void bnx2x_init_bmac_loopback(struct link_params *params,
11740 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011741{
11742 struct bnx2x *bp = params->bp;
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000011743 vars->link_up = 1;
11744 vars->line_speed = SPEED_10000;
11745 vars->duplex = DUPLEX_FULL;
11746 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
11747 vars->mac_type = MAC_TYPE_BMAC;
11748
11749 vars->phy_flags = PHY_XGXS_FLAG;
11750
11751 bnx2x_xgxs_deassert(params);
11752
11753 /* set bmac loopback */
11754 bnx2x_bmac_enable(params, vars, 1);
11755
11756 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 0);
11757}
11758
11759void bnx2x_init_emac_loopback(struct link_params *params,
11760 struct link_vars *vars)
11761{
11762 struct bnx2x *bp = params->bp;
11763 vars->link_up = 1;
11764 vars->line_speed = SPEED_1000;
11765 vars->duplex = DUPLEX_FULL;
11766 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
11767 vars->mac_type = MAC_TYPE_EMAC;
11768
11769 vars->phy_flags = PHY_XGXS_FLAG;
11770
11771 bnx2x_xgxs_deassert(params);
11772 /* set bmac loopback */
11773 bnx2x_emac_enable(params, vars, 1);
11774 bnx2x_emac_program(params, vars);
11775 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 0);
11776}
11777
Yaniv Rosner9380bb92011-06-14 01:34:07 +000011778void bnx2x_init_xmac_loopback(struct link_params *params,
11779 struct link_vars *vars)
11780{
11781 struct bnx2x *bp = params->bp;
11782 vars->link_up = 1;
11783 if (!params->req_line_speed[0])
11784 vars->line_speed = SPEED_10000;
11785 else
11786 vars->line_speed = params->req_line_speed[0];
11787 vars->duplex = DUPLEX_FULL;
11788 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
11789 vars->mac_type = MAC_TYPE_XMAC;
11790 vars->phy_flags = PHY_XGXS_FLAG;
11791 /*
11792 * Set WC to loopback mode since link is required to provide clock
11793 * to the XMAC in 20G mode
11794 */
Yaniv Rosnerafad0092011-08-02 23:00:06 +000011795 bnx2x_set_aer_mmd(params, &params->phy[0]);
11796 bnx2x_warpcore_reset_lane(bp, &params->phy[0], 0);
11797 params->phy[INT_PHY].config_loopback(
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000011798 &params->phy[INT_PHY],
11799 params);
Yaniv Rosnerafad0092011-08-02 23:00:06 +000011800
Yaniv Rosner9380bb92011-06-14 01:34:07 +000011801 bnx2x_xmac_enable(params, vars, 1);
11802 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 0);
11803}
11804
11805void bnx2x_init_umac_loopback(struct link_params *params,
11806 struct link_vars *vars)
11807{
11808 struct bnx2x *bp = params->bp;
11809 vars->link_up = 1;
11810 vars->line_speed = SPEED_1000;
11811 vars->duplex = DUPLEX_FULL;
11812 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
11813 vars->mac_type = MAC_TYPE_UMAC;
11814 vars->phy_flags = PHY_XGXS_FLAG;
11815 bnx2x_umac_enable(params, vars, 1);
11816
11817 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 0);
11818}
11819
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000011820void bnx2x_init_xgxs_loopback(struct link_params *params,
11821 struct link_vars *vars)
11822{
11823 struct bnx2x *bp = params->bp;
11824 vars->link_up = 1;
11825 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
11826 vars->duplex = DUPLEX_FULL;
11827 if (params->req_line_speed[0] == SPEED_1000)
11828 vars->line_speed = SPEED_1000;
11829 else
11830 vars->line_speed = SPEED_10000;
11831
Yaniv Rosner9380bb92011-06-14 01:34:07 +000011832 if (!USES_WARPCORE(bp))
11833 bnx2x_xgxs_deassert(params);
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000011834 bnx2x_link_initialize(params, vars);
11835
11836 if (params->req_line_speed[0] == SPEED_1000) {
Yaniv Rosner9380bb92011-06-14 01:34:07 +000011837 if (USES_WARPCORE(bp))
11838 bnx2x_umac_enable(params, vars, 0);
11839 else {
11840 bnx2x_emac_program(params, vars);
11841 bnx2x_emac_enable(params, vars, 0);
11842 }
11843 } else {
11844 if (USES_WARPCORE(bp))
11845 bnx2x_xmac_enable(params, vars, 0);
11846 else
11847 bnx2x_bmac_enable(params, vars, 0);
11848 }
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000011849
11850 if (params->loopback_mode == LOOPBACK_XGXS) {
11851 /* set 10G XGXS loopback */
11852 params->phy[INT_PHY].config_loopback(
11853 &params->phy[INT_PHY],
11854 params);
11855
11856 } else {
11857 /* set external phy loopback */
11858 u8 phy_index;
11859 for (phy_index = EXT_PHY1;
11860 phy_index < params->num_phys; phy_index++) {
11861 if (params->phy[phy_index].config_loopback)
11862 params->phy[phy_index].config_loopback(
11863 &params->phy[phy_index],
11864 params);
11865 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011866 }
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000011867 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011868
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000011869 bnx2x_set_led(params, vars, LED_MODE_OPER, vars->line_speed);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011870}
11871
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000011872int bnx2x_phy_init(struct link_params *params, struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011873{
11874 struct bnx2x *bp = params->bp;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011875 DP(NETIF_MSG_LINK, "Phy Initialization started\n");
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011876 DP(NETIF_MSG_LINK, "(1) req_speed %d, req_flowctrl %d\n",
11877 params->req_line_speed[0], params->req_flow_ctrl[0]);
11878 DP(NETIF_MSG_LINK, "(2) req_speed %d, req_flowctrl %d\n",
11879 params->req_line_speed[1], params->req_flow_ctrl[1]);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011880 vars->link_status = 0;
11881 vars->phy_link_up = 0;
11882 vars->link_up = 0;
11883 vars->line_speed = 0;
11884 vars->duplex = DUPLEX_FULL;
11885 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
11886 vars->mac_type = MAC_TYPE_NONE;
11887 vars->phy_flags = 0;
11888
11889 /* disable attentions */
11890 bnx2x_bits_dis(bp, NIG_REG_MASK_INTERRUPT_PORT0 + params->port*4,
11891 (NIG_MASK_XGXS0_LINK_STATUS |
11892 NIG_MASK_XGXS0_LINK10G |
11893 NIG_MASK_SERDES0_LINK_STATUS |
11894 NIG_MASK_MI_INT));
11895
11896 bnx2x_emac_init(params, vars);
11897
11898 if (params->num_phys == 0) {
11899 DP(NETIF_MSG_LINK, "No phy found for initialization !!\n");
11900 return -EINVAL;
11901 }
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000011902 set_phy_vars(params, vars);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011903
11904 DP(NETIF_MSG_LINK, "Num of phys on board: %d\n", params->num_phys);
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000011905 switch (params->loopback_mode) {
11906 case LOOPBACK_BMAC:
11907 bnx2x_init_bmac_loopback(params, vars);
11908 break;
11909 case LOOPBACK_EMAC:
11910 bnx2x_init_emac_loopback(params, vars);
11911 break;
Yaniv Rosner9380bb92011-06-14 01:34:07 +000011912 case LOOPBACK_XMAC:
11913 bnx2x_init_xmac_loopback(params, vars);
11914 break;
11915 case LOOPBACK_UMAC:
11916 bnx2x_init_umac_loopback(params, vars);
11917 break;
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000011918 case LOOPBACK_XGXS:
11919 case LOOPBACK_EXT_PHY:
11920 bnx2x_init_xgxs_loopback(params, vars);
11921 break;
11922 default:
Yaniv Rosner9380bb92011-06-14 01:34:07 +000011923 if (!CHIP_IS_E3(bp)) {
11924 if (params->switch_cfg == SWITCH_CFG_10G)
11925 bnx2x_xgxs_deassert(params);
11926 else
11927 bnx2x_serdes_deassert(bp, params->port);
11928 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011929 bnx2x_link_initialize(params, vars);
11930 msleep(30);
11931 bnx2x_link_int_enable(params);
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000011932 break;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011933 }
11934 return 0;
11935}
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000011936
11937int bnx2x_link_reset(struct link_params *params, struct link_vars *vars,
11938 u8 reset_ext_phy)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011939{
11940 struct bnx2x *bp = params->bp;
Yaniv Rosnercf1d9722010-11-01 05:32:34 +000011941 u8 phy_index, port = params->port, clear_latch_ind = 0;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011942 DP(NETIF_MSG_LINK, "Resetting the link of port %d\n", port);
11943 /* disable attentions */
11944 vars->link_status = 0;
11945 bnx2x_update_mng(params, vars->link_status);
11946 bnx2x_bits_dis(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000011947 (NIG_MASK_XGXS0_LINK_STATUS |
11948 NIG_MASK_XGXS0_LINK10G |
11949 NIG_MASK_SERDES0_LINK_STATUS |
11950 NIG_MASK_MI_INT));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011951
11952 /* activate nig drain */
11953 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + port*4, 1);
11954
11955 /* disable nig egress interface */
Yaniv Rosner9380bb92011-06-14 01:34:07 +000011956 if (!CHIP_IS_E3(bp)) {
11957 REG_WR(bp, NIG_REG_BMAC0_OUT_EN + port*4, 0);
11958 REG_WR(bp, NIG_REG_EGRESS_EMAC0_OUT_EN + port*4, 0);
11959 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011960
11961 /* Stop BigMac rx */
Yaniv Rosner9380bb92011-06-14 01:34:07 +000011962 if (!CHIP_IS_E3(bp))
11963 bnx2x_bmac_rx_disable(bp, port);
Yaniv Rosnerce7c0482011-10-27 05:09:47 +000011964 else {
Yaniv Rosner9380bb92011-06-14 01:34:07 +000011965 bnx2x_xmac_disable(params);
Yaniv Rosnerce7c0482011-10-27 05:09:47 +000011966 bnx2x_umac_disable(params);
11967 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011968 /* disable emac */
Yaniv Rosner9380bb92011-06-14 01:34:07 +000011969 if (!CHIP_IS_E3(bp))
11970 REG_WR(bp, NIG_REG_NIG_EMAC0_EN + port*4, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011971
11972 msleep(10);
Lucas De Marchi25985ed2011-03-30 22:57:33 -030011973 /* The PHY reset is controlled by GPIO 1
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011974 * Hold it as vars low
11975 */
11976 /* clear link led */
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000011977 bnx2x_set_led(params, vars, LED_MODE_OFF, 0);
11978
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011979 if (reset_ext_phy) {
Yaniv Rosner28f48812011-08-02 23:00:12 +000011980 bnx2x_set_mdio_clk(bp, params->chip_id, port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011981 for (phy_index = EXT_PHY1; phy_index < params->num_phys;
11982 phy_index++) {
Yaniv Rosner28f48812011-08-02 23:00:12 +000011983 if (params->phy[phy_index].link_reset) {
11984 bnx2x_set_aer_mmd(params,
11985 &params->phy[phy_index]);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011986 params->phy[phy_index].link_reset(
11987 &params->phy[phy_index],
11988 params);
Yaniv Rosner28f48812011-08-02 23:00:12 +000011989 }
Yaniv Rosnercf1d9722010-11-01 05:32:34 +000011990 if (params->phy[phy_index].flags &
11991 FLAGS_REARM_LATCH_SIGNAL)
11992 clear_latch_ind = 1;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011993 }
11994 }
11995
Yaniv Rosnercf1d9722010-11-01 05:32:34 +000011996 if (clear_latch_ind) {
11997 /* Clear latching indication */
11998 bnx2x_rearm_latch_signal(bp, port, 0);
11999 bnx2x_bits_dis(bp, NIG_REG_LATCH_BC_0 + port*4,
12000 1 << NIG_LATCH_BC_ENABLE_MI_INT);
12001 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012002 if (params->phy[INT_PHY].link_reset)
12003 params->phy[INT_PHY].link_reset(
12004 &params->phy[INT_PHY], params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012005
12006 /* disable nig ingress interface */
Yaniv Rosner9380bb92011-06-14 01:34:07 +000012007 if (!CHIP_IS_E3(bp)) {
Yaniv Rosnerce7c0482011-10-27 05:09:47 +000012008 /* reset BigMac */
12009 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
12010 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port));
Yaniv Rosner9380bb92011-06-14 01:34:07 +000012011 REG_WR(bp, NIG_REG_BMAC0_IN_EN + port*4, 0);
12012 REG_WR(bp, NIG_REG_EMAC0_IN_EN + port*4, 0);
Yaniv Rosnerce7c0482011-10-27 05:09:47 +000012013 } else {
12014 u32 xmac_base = (params->port) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
12015 bnx2x_set_xumac_nig(params, 0, 0);
12016 if (REG_RD(bp, MISC_REG_RESET_REG_2) &
12017 MISC_REGISTERS_RESET_REG_2_XMAC)
12018 REG_WR(bp, xmac_base + XMAC_REG_CTRL,
12019 XMAC_CTRL_REG_SOFT_RESET);
Yaniv Rosner9380bb92011-06-14 01:34:07 +000012020 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012021 vars->link_up = 0;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000012022 vars->phy_flags = 0;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012023 return 0;
12024}
12025
12026/****************************************************************************/
12027/* Common function */
12028/****************************************************************************/
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000012029static int bnx2x_8073_common_init_phy(struct bnx2x *bp,
12030 u32 shmem_base_path[],
12031 u32 shmem2_base_path[], u8 phy_index,
12032 u32 chip_id)
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012033{
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012034 struct bnx2x_phy phy[PORT_MAX];
12035 struct bnx2x_phy *phy_blk[PORT_MAX];
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012036 u16 val;
Yaniv Rosnerc8e64df2011-01-30 04:15:00 +000012037 s8 port = 0;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012038 s8 port_of_path = 0;
Yaniv Rosnerc8e64df2011-01-30 04:15:00 +000012039 u32 swap_val, swap_override;
12040 swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
12041 swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
12042 port ^= (swap_val && swap_override);
12043 bnx2x_ext_phy_hw_reset(bp, port);
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012044 /* PART1 - Reset both phys */
12045 for (port = PORT_MAX - 1; port >= PORT_0; port--) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012046 u32 shmem_base, shmem2_base;
12047 /* In E2, same phy is using for port0 of the two paths */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000012048 if (CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012049 shmem_base = shmem_base_path[0];
12050 shmem2_base = shmem2_base_path[0];
12051 port_of_path = port;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000012052 } else {
12053 shmem_base = shmem_base_path[port];
12054 shmem2_base = shmem2_base_path[port];
12055 port_of_path = 0;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012056 }
12057
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012058 /* Extract the ext phy address for the port */
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012059 if (bnx2x_populate_phy(bp, phy_index, shmem_base, shmem2_base,
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012060 port_of_path, &phy[port]) !=
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012061 0) {
12062 DP(NETIF_MSG_LINK, "populate_phy failed\n");
12063 return -EINVAL;
12064 }
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012065 /* disable attentions */
Yaniv Rosner6a71bbe2010-11-01 05:32:31 +000012066 bnx2x_bits_dis(bp, NIG_REG_MASK_INTERRUPT_PORT0 +
12067 port_of_path*4,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012068 (NIG_MASK_XGXS0_LINK_STATUS |
12069 NIG_MASK_XGXS0_LINK10G |
12070 NIG_MASK_SERDES0_LINK_STATUS |
12071 NIG_MASK_MI_INT));
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012072
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012073 /* Need to take the phy out of low power mode in order
12074 to write to access its registers */
12075 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012076 MISC_REGISTERS_GPIO_OUTPUT_HIGH,
12077 port);
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012078
12079 /* Reset the phy */
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012080 bnx2x_cl45_write(bp, &phy[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012081 MDIO_PMA_DEVAD,
12082 MDIO_PMA_REG_CTRL,
12083 1<<15);
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012084 }
12085
12086 /* Add delay of 150ms after reset */
12087 msleep(150);
12088
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012089 if (phy[PORT_0].addr & 0x1) {
12090 phy_blk[PORT_0] = &(phy[PORT_1]);
12091 phy_blk[PORT_1] = &(phy[PORT_0]);
12092 } else {
12093 phy_blk[PORT_0] = &(phy[PORT_0]);
12094 phy_blk[PORT_1] = &(phy[PORT_1]);
12095 }
12096
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012097 /* PART2 - Download firmware to both phys */
12098 for (port = PORT_MAX - 1; port >= PORT_0; port--) {
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000012099 if (CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012100 port_of_path = port;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000012101 else
12102 port_of_path = 0;
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012103
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012104 DP(NETIF_MSG_LINK, "Loading spirom for phy address 0x%x\n",
12105 phy_blk[port]->addr);
Yaniv Rosner5c99274b2011-01-18 04:33:36 +000012106 if (bnx2x_8073_8727_external_rom_boot(bp, phy_blk[port],
12107 port_of_path))
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012108 return -EINVAL;
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012109
12110 /* Only set bit 10 = 1 (Tx power down) */
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012111 bnx2x_cl45_read(bp, phy_blk[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012112 MDIO_PMA_DEVAD,
12113 MDIO_PMA_REG_TX_POWER_DOWN, &val);
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012114
12115 /* Phase1 of TX_POWER_DOWN reset */
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012116 bnx2x_cl45_write(bp, phy_blk[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012117 MDIO_PMA_DEVAD,
12118 MDIO_PMA_REG_TX_POWER_DOWN,
12119 (val | 1<<10));
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012120 }
12121
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +000012122 /*
12123 * Toggle Transmitter: Power down and then up with 600ms delay
12124 * between
12125 */
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012126 msleep(600);
12127
12128 /* PART3 - complete TX_POWER_DOWN process, and set GPIO2 back to low */
12129 for (port = PORT_MAX - 1; port >= PORT_0; port--) {
Eilon Greensteinf5372252009-02-12 08:38:30 +000012130 /* Phase2 of POWER_DOWN_RESET */
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012131 /* Release bit 10 (Release Tx power down) */
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012132 bnx2x_cl45_read(bp, phy_blk[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012133 MDIO_PMA_DEVAD,
12134 MDIO_PMA_REG_TX_POWER_DOWN, &val);
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012135
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012136 bnx2x_cl45_write(bp, phy_blk[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012137 MDIO_PMA_DEVAD,
12138 MDIO_PMA_REG_TX_POWER_DOWN, (val & (~(1<<10))));
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012139 msleep(15);
12140
12141 /* Read modify write the SPI-ROM version select register */
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012142 bnx2x_cl45_read(bp, phy_blk[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012143 MDIO_PMA_DEVAD,
12144 MDIO_PMA_REG_EDC_FFE_MAIN, &val);
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012145 bnx2x_cl45_write(bp, phy_blk[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012146 MDIO_PMA_DEVAD,
12147 MDIO_PMA_REG_EDC_FFE_MAIN, (val | (1<<12)));
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012148
12149 /* set GPIO2 back to LOW */
12150 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012151 MISC_REGISTERS_GPIO_OUTPUT_LOW, port);
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012152 }
12153 return 0;
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012154}
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000012155static int bnx2x_8726_common_init_phy(struct bnx2x *bp,
12156 u32 shmem_base_path[],
12157 u32 shmem2_base_path[], u8 phy_index,
12158 u32 chip_id)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012159{
12160 u32 val;
12161 s8 port;
12162 struct bnx2x_phy phy;
12163 /* Use port1 because of the static port-swap */
12164 /* Enable the module detection interrupt */
12165 val = REG_RD(bp, MISC_REG_GPIO_EVENT_EN);
12166 val |= ((1<<MISC_REGISTERS_GPIO_3)|
12167 (1<<(MISC_REGISTERS_GPIO_3 + MISC_REGISTERS_GPIO_PORT_SHIFT)));
12168 REG_WR(bp, MISC_REG_GPIO_EVENT_EN, val);
12169
Yaniv Rosner650154b2010-11-01 05:32:36 +000012170 bnx2x_ext_phy_hw_reset(bp, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012171 msleep(5);
12172 for (port = 0; port < PORT_MAX; port++) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012173 u32 shmem_base, shmem2_base;
12174
12175 /* In E2, same phy is using for port0 of the two paths */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000012176 if (CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012177 shmem_base = shmem_base_path[0];
12178 shmem2_base = shmem2_base_path[0];
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000012179 } else {
12180 shmem_base = shmem_base_path[port];
12181 shmem2_base = shmem2_base_path[port];
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012182 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012183 /* Extract the ext phy address for the port */
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012184 if (bnx2x_populate_phy(bp, phy_index, shmem_base, shmem2_base,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012185 port, &phy) !=
12186 0) {
12187 DP(NETIF_MSG_LINK, "populate phy failed\n");
12188 return -EINVAL;
12189 }
12190
12191 /* Reset phy*/
12192 bnx2x_cl45_write(bp, &phy,
12193 MDIO_PMA_DEVAD, MDIO_PMA_REG_GEN_CTRL, 0x0001);
12194
12195
12196 /* Set fault module detected LED on */
12197 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_0,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012198 MISC_REGISTERS_GPIO_HIGH,
12199 port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012200 }
12201
12202 return 0;
12203}
Yaniv Rosnera8db5b42011-01-31 04:22:28 +000012204static void bnx2x_get_ext_phy_reset_gpio(struct bnx2x *bp, u32 shmem_base,
12205 u8 *io_gpio, u8 *io_port)
12206{
12207
12208 u32 phy_gpio_reset = REG_RD(bp, shmem_base +
12209 offsetof(struct shmem_region,
12210 dev_info.port_hw_config[PORT_0].default_cfg));
12211 switch (phy_gpio_reset) {
12212 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO0_P0:
12213 *io_gpio = 0;
12214 *io_port = 0;
12215 break;
12216 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO1_P0:
12217 *io_gpio = 1;
12218 *io_port = 0;
12219 break;
12220 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO2_P0:
12221 *io_gpio = 2;
12222 *io_port = 0;
12223 break;
12224 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO3_P0:
12225 *io_gpio = 3;
12226 *io_port = 0;
12227 break;
12228 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO0_P1:
12229 *io_gpio = 0;
12230 *io_port = 1;
12231 break;
12232 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO1_P1:
12233 *io_gpio = 1;
12234 *io_port = 1;
12235 break;
12236 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO2_P1:
12237 *io_gpio = 2;
12238 *io_port = 1;
12239 break;
12240 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO3_P1:
12241 *io_gpio = 3;
12242 *io_port = 1;
12243 break;
12244 default:
12245 /* Don't override the io_gpio and io_port */
12246 break;
12247 }
12248}
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000012249
12250static int bnx2x_8727_common_init_phy(struct bnx2x *bp,
12251 u32 shmem_base_path[],
12252 u32 shmem2_base_path[], u8 phy_index,
12253 u32 chip_id)
Eilon Greenstein4d295db2009-07-21 05:47:47 +000012254{
Yaniv Rosnera8db5b42011-01-31 04:22:28 +000012255 s8 port, reset_gpio;
Eilon Greenstein4d295db2009-07-21 05:47:47 +000012256 u32 swap_val, swap_override;
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012257 struct bnx2x_phy phy[PORT_MAX];
12258 struct bnx2x_phy *phy_blk[PORT_MAX];
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012259 s8 port_of_path;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012260 swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
12261 swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
Eilon Greenstein4d295db2009-07-21 05:47:47 +000012262
Yaniv Rosnera8db5b42011-01-31 04:22:28 +000012263 reset_gpio = MISC_REGISTERS_GPIO_1;
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012264 port = 1;
12265
Yaniv Rosnera8db5b42011-01-31 04:22:28 +000012266 /*
12267 * Retrieve the reset gpio/port which control the reset.
12268 * Default is GPIO1, PORT1
12269 */
12270 bnx2x_get_ext_phy_reset_gpio(bp, shmem_base_path[0],
12271 (u8 *)&reset_gpio, (u8 *)&port);
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012272
12273 /* Calculate the port based on port swap */
12274 port ^= (swap_val && swap_override);
12275
Yaniv Rosnera8db5b42011-01-31 04:22:28 +000012276 /* Initiate PHY reset*/
12277 bnx2x_set_gpio(bp, reset_gpio, MISC_REGISTERS_GPIO_OUTPUT_LOW,
12278 port);
12279 msleep(1);
12280 bnx2x_set_gpio(bp, reset_gpio, MISC_REGISTERS_GPIO_OUTPUT_HIGH,
12281 port);
12282
Eilon Greenstein4d295db2009-07-21 05:47:47 +000012283 msleep(5);
12284
12285 /* PART1 - Reset both phys */
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012286 for (port = PORT_MAX - 1; port >= PORT_0; port--) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012287 u32 shmem_base, shmem2_base;
12288
12289 /* In E2, same phy is using for port0 of the two paths */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000012290 if (CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012291 shmem_base = shmem_base_path[0];
12292 shmem2_base = shmem2_base_path[0];
12293 port_of_path = port;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000012294 } else {
12295 shmem_base = shmem_base_path[port];
12296 shmem2_base = shmem2_base_path[port];
12297 port_of_path = 0;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012298 }
12299
Eilon Greenstein4d295db2009-07-21 05:47:47 +000012300 /* Extract the ext phy address for the port */
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012301 if (bnx2x_populate_phy(bp, phy_index, shmem_base, shmem2_base,
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012302 port_of_path, &phy[port]) !=
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012303 0) {
12304 DP(NETIF_MSG_LINK, "populate phy failed\n");
12305 return -EINVAL;
12306 }
Eilon Greenstein4d295db2009-07-21 05:47:47 +000012307 /* disable attentions */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012308 bnx2x_bits_dis(bp, NIG_REG_MASK_INTERRUPT_PORT0 +
12309 port_of_path*4,
12310 (NIG_MASK_XGXS0_LINK_STATUS |
12311 NIG_MASK_XGXS0_LINK10G |
12312 NIG_MASK_SERDES0_LINK_STATUS |
12313 NIG_MASK_MI_INT));
Eilon Greenstein4d295db2009-07-21 05:47:47 +000012314
Eilon Greenstein4d295db2009-07-21 05:47:47 +000012315
12316 /* Reset the phy */
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012317 bnx2x_cl45_write(bp, &phy[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012318 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 1<<15);
Eilon Greenstein4d295db2009-07-21 05:47:47 +000012319 }
12320
12321 /* Add delay of 150ms after reset */
12322 msleep(150);
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012323 if (phy[PORT_0].addr & 0x1) {
12324 phy_blk[PORT_0] = &(phy[PORT_1]);
12325 phy_blk[PORT_1] = &(phy[PORT_0]);
12326 } else {
12327 phy_blk[PORT_0] = &(phy[PORT_0]);
12328 phy_blk[PORT_1] = &(phy[PORT_1]);
12329 }
Eilon Greenstein4d295db2009-07-21 05:47:47 +000012330 /* PART2 - Download firmware to both phys */
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012331 for (port = PORT_MAX - 1; port >= PORT_0; port--) {
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000012332 if (CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012333 port_of_path = port;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000012334 else
12335 port_of_path = 0;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012336 DP(NETIF_MSG_LINK, "Loading spirom for phy address 0x%x\n",
12337 phy_blk[port]->addr);
Yaniv Rosner5c99274b2011-01-18 04:33:36 +000012338 if (bnx2x_8073_8727_external_rom_boot(bp, phy_blk[port],
12339 port_of_path))
Eilon Greenstein4d295db2009-07-21 05:47:47 +000012340 return -EINVAL;
Yaniv Rosner85242ee2011-07-05 01:06:53 +000012341 /* Disable PHY transmitter output */
12342 bnx2x_cl45_write(bp, phy_blk[port],
12343 MDIO_PMA_DEVAD,
12344 MDIO_PMA_REG_TX_DISABLE, 1);
Eilon Greenstein4d295db2009-07-21 05:47:47 +000012345
Yaniv Rosner5c99274b2011-01-18 04:33:36 +000012346 }
Eilon Greenstein4d295db2009-07-21 05:47:47 +000012347 return 0;
12348}
12349
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000012350static int bnx2x_ext_phy_common_init(struct bnx2x *bp, u32 shmem_base_path[],
12351 u32 shmem2_base_path[], u8 phy_index,
12352 u32 ext_phy_type, u32 chip_id)
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012353{
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000012354 int rc = 0;
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012355
12356 switch (ext_phy_type) {
12357 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073:
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012358 rc = bnx2x_8073_common_init_phy(bp, shmem_base_path,
12359 shmem2_base_path,
12360 phy_index, chip_id);
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012361 break;
Yaniv Rosnere4d78f12011-05-31 21:25:55 +000012362 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8722:
Eilon Greenstein4d295db2009-07-21 05:47:47 +000012363 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
12364 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727_NOC:
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012365 rc = bnx2x_8727_common_init_phy(bp, shmem_base_path,
12366 shmem2_base_path,
12367 phy_index, chip_id);
Eilon Greenstein4d295db2009-07-21 05:47:47 +000012368 break;
12369
Eilon Greenstein589abe32009-02-12 08:36:55 +000012370 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +000012371 /*
12372 * GPIO1 affects both ports, so there's need to pull
12373 * it for single port alone
12374 */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012375 rc = bnx2x_8726_common_init_phy(bp, shmem_base_path,
12376 shmem2_base_path,
12377 phy_index, chip_id);
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012378 break;
Yaniv Rosner0d40f0d2011-06-14 01:34:27 +000012379 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833:
12380 /*
12381 * GPIO3's are linked, and so both need to be toggled
12382 * to obtain required 2us pulse.
12383 */
12384 rc = bnx2x_84833_common_init_phy(bp, shmem_base_path, chip_id);
12385 break;
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012386 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE:
12387 rc = -EINVAL;
Yaniv Rosner4f60dab2009-11-05 19:18:23 +020012388 break;
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012389 default:
12390 DP(NETIF_MSG_LINK,
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +000012391 "ext_phy 0x%x common init not required\n",
12392 ext_phy_type);
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012393 break;
12394 }
12395
Yaniv Rosner6d870c32011-01-31 04:22:20 +000012396 if (rc != 0)
12397 netdev_err(bp->dev, "Warning: PHY was not initialized,"
12398 " Port %d\n",
12399 0);
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012400 return rc;
12401}
12402
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000012403int bnx2x_common_init_phy(struct bnx2x *bp, u32 shmem_base_path[],
12404 u32 shmem2_base_path[], u32 chip_id)
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012405{
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000012406 int rc = 0;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000012407 u32 phy_ver, val;
12408 u8 phy_index = 0;
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012409 u32 ext_phy_type, ext_phy_config;
Yaniv Rosnera198c142011-05-31 21:29:42 +000012410 bnx2x_set_mdio_clk(bp, chip_id, PORT_0);
12411 bnx2x_set_mdio_clk(bp, chip_id, PORT_1);
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012412 DP(NETIF_MSG_LINK, "Begin common phy init\n");
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000012413 if (CHIP_IS_E3(bp)) {
12414 /* Enable EPIO */
12415 val = REG_RD(bp, MISC_REG_GEN_PURP_HWG);
12416 REG_WR(bp, MISC_REG_GEN_PURP_HWG, val | 1);
12417 }
Yaniv Rosnerb21a3422011-01-18 04:33:24 +000012418 /* Check if common init was already done */
12419 phy_ver = REG_RD(bp, shmem_base_path[0] +
12420 offsetof(struct shmem_region,
12421 port_mb[PORT_0].ext_phy_fw_version));
12422 if (phy_ver) {
12423 DP(NETIF_MSG_LINK, "Not doing common init; phy ver is 0x%x\n",
12424 phy_ver);
12425 return 0;
12426 }
12427
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012428 /* Read the ext_phy_type for arbitrary port(0) */
12429 for (phy_index = EXT_PHY1; phy_index < MAX_PHYS;
12430 phy_index++) {
12431 ext_phy_config = bnx2x_get_ext_phy_config(bp,
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012432 shmem_base_path[0],
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012433 phy_index, 0);
12434 ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012435 rc |= bnx2x_ext_phy_common_init(bp, shmem_base_path,
12436 shmem2_base_path,
12437 phy_index, ext_phy_type,
12438 chip_id);
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012439 }
12440 return rc;
12441}
12442
Yaniv Rosner3deb8162011-06-14 01:34:33 +000012443static void bnx2x_check_over_curr(struct link_params *params,
12444 struct link_vars *vars)
12445{
12446 struct bnx2x *bp = params->bp;
12447 u32 cfg_pin;
12448 u8 port = params->port;
12449 u32 pin_val;
12450
12451 cfg_pin = (REG_RD(bp, params->shmem_base +
12452 offsetof(struct shmem_region,
12453 dev_info.port_hw_config[port].e3_cmn_pin_cfg1)) &
12454 PORT_HW_CFG_E3_OVER_CURRENT_MASK) >>
12455 PORT_HW_CFG_E3_OVER_CURRENT_SHIFT;
12456
12457 /* Ignore check if no external input PIN available */
12458 if (bnx2x_get_cfg_pin(bp, cfg_pin, &pin_val) != 0)
12459 return;
12460
12461 if (!pin_val) {
12462 if ((vars->phy_flags & PHY_OVER_CURRENT_FLAG) == 0) {
12463 netdev_err(bp->dev, "Error: Power fault on Port %d has"
12464 " been detected and the power to "
12465 "that SFP+ module has been removed"
12466 " to prevent failure of the card."
12467 " Please remove the SFP+ module and"
12468 " restart the system to clear this"
12469 " error.\n",
12470 params->port);
12471 vars->phy_flags |= PHY_OVER_CURRENT_FLAG;
12472 }
12473 } else
12474 vars->phy_flags &= ~PHY_OVER_CURRENT_FLAG;
12475}
12476
12477static void bnx2x_analyze_link_error(struct link_params *params,
12478 struct link_vars *vars, u32 lss_status)
12479{
12480 struct bnx2x *bp = params->bp;
12481 /* Compare new value with previous value */
12482 u8 led_mode;
12483 u32 half_open_conn = (vars->phy_flags & PHY_HALF_OPEN_CONN_FLAG) > 0;
12484
Yaniv Rosner3deb8162011-06-14 01:34:33 +000012485 if ((lss_status ^ half_open_conn) == 0)
12486 return;
12487
12488 /* If values differ */
12489 DP(NETIF_MSG_LINK, "Link changed:%x %x->%x\n", vars->link_up,
12490 half_open_conn, lss_status);
12491
12492 /*
12493 * a. Update shmem->link_status accordingly
12494 * b. Update link_vars->link_up
12495 */
12496 if (lss_status) {
Yaniv Rosnerde6f3372011-08-02 22:59:25 +000012497 DP(NETIF_MSG_LINK, "Remote Fault detected !!!\n");
Yaniv Rosner3deb8162011-06-14 01:34:33 +000012498 vars->link_status &= ~LINK_STATUS_LINK_UP;
12499 vars->link_up = 0;
12500 vars->phy_flags |= PHY_HALF_OPEN_CONN_FLAG;
12501 /*
12502 * Set LED mode to off since the PHY doesn't know about these
12503 * errors
12504 */
12505 led_mode = LED_MODE_OFF;
12506 } else {
Yaniv Rosnerde6f3372011-08-02 22:59:25 +000012507 DP(NETIF_MSG_LINK, "Remote Fault cleared\n");
Yaniv Rosner3deb8162011-06-14 01:34:33 +000012508 vars->link_status |= LINK_STATUS_LINK_UP;
12509 vars->link_up = 1;
12510 vars->phy_flags &= ~PHY_HALF_OPEN_CONN_FLAG;
12511 led_mode = LED_MODE_OPER;
12512 }
12513 /* Update the LED according to the link state */
12514 bnx2x_set_led(params, vars, led_mode, SPEED_10000);
12515
12516 /* Update link status in the shared memory */
12517 bnx2x_update_mng(params, vars->link_status);
12518
12519 /* C. Trigger General Attention */
12520 vars->periodic_flags |= PERIODIC_FLAGS_LINK_EVENT;
12521 bnx2x_notify_link_changed(bp);
12522}
12523
Yaniv Rosnerde6f3372011-08-02 22:59:25 +000012524/******************************************************************************
12525* Description:
12526* This function checks for half opened connection change indication.
12527* When such change occurs, it calls the bnx2x_analyze_link_error
12528* to check if Remote Fault is set or cleared. Reception of remote fault
12529* status message in the MAC indicates that the peer's MAC has detected
12530* a fault, for example, due to break in the TX side of fiber.
12531*
12532******************************************************************************/
Yaniv Rosner3deb8162011-06-14 01:34:33 +000012533static void bnx2x_check_half_open_conn(struct link_params *params,
12534 struct link_vars *vars)
12535{
12536 struct bnx2x *bp = params->bp;
12537 u32 lss_status = 0;
12538 u32 mac_base;
12539 /* In case link status is physically up @ 10G do */
12540 if ((vars->phy_flags & PHY_PHYSICAL_LINK_FLAG) == 0)
12541 return;
12542
Yaniv Rosnerde6f3372011-08-02 22:59:25 +000012543 if (CHIP_IS_E3(bp) &&
Yaniv Rosner3deb8162011-06-14 01:34:33 +000012544 (REG_RD(bp, MISC_REG_RESET_REG_2) &
Yaniv Rosnerde6f3372011-08-02 22:59:25 +000012545 (MISC_REGISTERS_RESET_REG_2_XMAC))) {
12546 /* Check E3 XMAC */
12547 /*
12548 * Note that link speed cannot be queried here, since it may be
12549 * zero while link is down. In case UMAC is active, LSS will
12550 * simply not be set
12551 */
12552 mac_base = (params->port) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
12553
12554 /* Clear stick bits (Requires rising edge) */
12555 REG_WR(bp, mac_base + XMAC_REG_CLEAR_RX_LSS_STATUS, 0);
12556 REG_WR(bp, mac_base + XMAC_REG_CLEAR_RX_LSS_STATUS,
12557 XMAC_CLEAR_RX_LSS_STATUS_REG_CLEAR_LOCAL_FAULT_STATUS |
12558 XMAC_CLEAR_RX_LSS_STATUS_REG_CLEAR_REMOTE_FAULT_STATUS);
12559 if (REG_RD(bp, mac_base + XMAC_REG_RX_LSS_STATUS))
12560 lss_status = 1;
12561
12562 bnx2x_analyze_link_error(params, vars, lss_status);
12563 } else if (REG_RD(bp, MISC_REG_RESET_REG_2) &
12564 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << params->port)) {
Yaniv Rosner3deb8162011-06-14 01:34:33 +000012565 /* Check E1X / E2 BMAC */
12566 u32 lss_status_reg;
12567 u32 wb_data[2];
12568 mac_base = params->port ? NIG_REG_INGRESS_BMAC1_MEM :
12569 NIG_REG_INGRESS_BMAC0_MEM;
12570 /* Read BIGMAC_REGISTER_RX_LSS_STATUS */
12571 if (CHIP_IS_E2(bp))
12572 lss_status_reg = BIGMAC2_REGISTER_RX_LSS_STAT;
12573 else
12574 lss_status_reg = BIGMAC_REGISTER_RX_LSS_STATUS;
12575
12576 REG_RD_DMAE(bp, mac_base + lss_status_reg, wb_data, 2);
12577 lss_status = (wb_data[0] > 0);
12578
12579 bnx2x_analyze_link_error(params, vars, lss_status);
12580 }
12581}
12582
12583void bnx2x_period_func(struct link_params *params, struct link_vars *vars)
12584{
12585 struct bnx2x *bp = params->bp;
Yaniv Rosnerde6f3372011-08-02 22:59:25 +000012586 u16 phy_idx;
Yaniv Rosnerde6f3372011-08-02 22:59:25 +000012587 for (phy_idx = INT_PHY; phy_idx < MAX_PHYS; phy_idx++) {
12588 if (params->phy[phy_idx].flags & FLAGS_TX_ERROR_CHECK) {
12589 bnx2x_set_aer_mmd(params, &params->phy[phy_idx]);
12590 bnx2x_check_half_open_conn(params, vars);
12591 break;
12592 }
12593 }
12594
Yaniv Rosnera9077bf2011-10-27 05:09:46 +000012595 if (CHIP_IS_E3(bp)) {
12596 struct bnx2x_phy *phy = &params->phy[INT_PHY];
12597 bnx2x_set_aer_mmd(params, phy);
Yaniv Rosner3deb8162011-06-14 01:34:33 +000012598 bnx2x_check_over_curr(params, vars);
Yaniv Rosnera9077bf2011-10-27 05:09:46 +000012599 bnx2x_warpcore_config_runtime(phy, params, vars);
12600 }
12601
Yaniv Rosner3deb8162011-06-14 01:34:33 +000012602}
12603
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012604u8 bnx2x_hw_lock_required(struct bnx2x *bp, u32 shmem_base, u32 shmem2_base)
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +000012605{
12606 u8 phy_index;
12607 struct bnx2x_phy phy;
12608 for (phy_index = INT_PHY; phy_index < MAX_PHYS;
12609 phy_index++) {
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012610 if (bnx2x_populate_phy(bp, phy_index, shmem_base, shmem2_base,
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +000012611 0, &phy) != 0) {
12612 DP(NETIF_MSG_LINK, "populate phy failed\n");
12613 return 0;
12614 }
12615
12616 if (phy.flags & FLAGS_HW_LOCK_REQUIRED)
12617 return 1;
12618 }
12619 return 0;
12620}
12621
12622u8 bnx2x_fan_failure_det_req(struct bnx2x *bp,
12623 u32 shmem_base,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012624 u32 shmem2_base,
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +000012625 u8 port)
12626{
12627 u8 phy_index, fan_failure_det_req = 0;
12628 struct bnx2x_phy phy;
12629 for (phy_index = EXT_PHY1; phy_index < MAX_PHYS;
12630 phy_index++) {
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012631 if (bnx2x_populate_phy(bp, phy_index, shmem_base, shmem2_base,
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +000012632 port, &phy)
12633 != 0) {
12634 DP(NETIF_MSG_LINK, "populate phy failed\n");
12635 return 0;
12636 }
12637 fan_failure_det_req |= (phy.flags &
12638 FLAGS_FAN_FAILURE_DET_REQ);
12639 }
12640 return fan_failure_det_req;
12641}
12642
12643void bnx2x_hw_reset_phy(struct link_params *params)
12644{
12645 u8 phy_index;
Yaniv Rosner985848f2011-07-05 01:06:48 +000012646 struct bnx2x *bp = params->bp;
12647 bnx2x_update_mng(params, 0);
12648 bnx2x_bits_dis(bp, NIG_REG_MASK_INTERRUPT_PORT0 + params->port*4,
12649 (NIG_MASK_XGXS0_LINK_STATUS |
12650 NIG_MASK_XGXS0_LINK10G |
12651 NIG_MASK_SERDES0_LINK_STATUS |
12652 NIG_MASK_MI_INT));
12653
12654 for (phy_index = INT_PHY; phy_index < MAX_PHYS;
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +000012655 phy_index++) {
12656 if (params->phy[phy_index].hw_reset) {
12657 params->phy[phy_index].hw_reset(
12658 &params->phy[phy_index],
12659 params);
12660 params->phy[phy_index] = phy_null;
12661 }
12662 }
12663}
Yaniv Rosner020c7e32011-05-31 21:28:43 +000012664
12665void bnx2x_init_mod_abs_int(struct bnx2x *bp, struct link_vars *vars,
12666 u32 chip_id, u32 shmem_base, u32 shmem2_base,
12667 u8 port)
12668{
12669 u8 gpio_num = 0xff, gpio_port = 0xff, phy_index;
12670 u32 val;
12671 u32 offset, aeu_mask, swap_val, swap_override, sync_offset;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000012672 if (CHIP_IS_E3(bp)) {
12673 if (bnx2x_get_mod_abs_int_cfg(bp, chip_id,
12674 shmem_base,
12675 port,
12676 &gpio_num,
12677 &gpio_port) != 0)
12678 return;
12679 } else {
Yaniv Rosner020c7e32011-05-31 21:28:43 +000012680 struct bnx2x_phy phy;
12681 for (phy_index = EXT_PHY1; phy_index < MAX_PHYS;
12682 phy_index++) {
12683 if (bnx2x_populate_phy(bp, phy_index, shmem_base,
12684 shmem2_base, port, &phy)
12685 != 0) {
12686 DP(NETIF_MSG_LINK, "populate phy failed\n");
12687 return;
12688 }
12689 if (phy.type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726) {
12690 gpio_num = MISC_REGISTERS_GPIO_3;
12691 gpio_port = port;
12692 break;
12693 }
12694 }
12695 }
12696
12697 if (gpio_num == 0xff)
12698 return;
12699
12700 /* Set GPIO3 to trigger SFP+ module insertion/removal */
12701 bnx2x_set_gpio(bp, gpio_num, MISC_REGISTERS_GPIO_INPUT_HI_Z, gpio_port);
12702
12703 swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
12704 swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
12705 gpio_port ^= (swap_val && swap_override);
12706
12707 vars->aeu_int_mask = AEU_INPUTS_ATTN_BITS_GPIO0_FUNCTION_0 <<
12708 (gpio_num + (gpio_port << 2));
12709
12710 sync_offset = shmem_base +
12711 offsetof(struct shmem_region,
12712 dev_info.port_hw_config[port].aeu_int_mask);
12713 REG_WR(bp, sync_offset, vars->aeu_int_mask);
12714
12715 DP(NETIF_MSG_LINK, "Setting MOD_ABS (GPIO%d_P%d) AEU to 0x%x\n",
12716 gpio_num, gpio_port, vars->aeu_int_mask);
12717
12718 if (port == 0)
12719 offset = MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0;
12720 else
12721 offset = MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0;
12722
12723 /* Open appropriate AEU for interrupts */
12724 aeu_mask = REG_RD(bp, offset);
12725 aeu_mask |= vars->aeu_int_mask;
12726 REG_WR(bp, offset, aeu_mask);
12727
12728 /* Enable the GPIO to trigger interrupt */
12729 val = REG_RD(bp, MISC_REG_GPIO_EVENT_EN);
12730 val |= 1 << (gpio_num + (gpio_port << 2));
12731 REG_WR(bp, MISC_REG_GPIO_EVENT_EN, val);
12732}