blob: bcc112b82831253a5d85af99a60a18df688c6402 [file] [log] [blame]
Ariel Elior85b26ea2012-01-26 06:01:54 +00001/* Copyright 2008-2012 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/********************************************************/
Eilon Greenstein3196a882008-08-13 15:58:49 -070031#define ETH_HLEN 14
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000032/* L2 header size + 2*VLANs (8 bytes) + LLC SNAP (8 bytes) */
33#define ETH_OVREHEAD (ETH_HLEN + 8 + 8)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -070034#define ETH_MIN_PACKET_SIZE 60
35#define ETH_MAX_PACKET_SIZE 1500
36#define ETH_MAX_JUMBO_PACKET_SIZE 9600
37#define MDIO_ACCESS_TIMEOUT 1000
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000038#define WC_LANE_MAX 4
39#define I2C_SWITCH_WIDTH 2
40#define I2C_BSC0 0
41#define I2C_BSC1 1
42#define I2C_WA_RETRY_CNT 3
Yuval Mintz50a29842012-06-16 20:27:14 +000043#define I2C_WA_PWR_ITER (I2C_WA_RETRY_CNT - 1)
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000044#define MCPR_IMC_COMMAND_READ_OP 1
45#define MCPR_IMC_COMMAND_WRITE_OP 2
Yaniv Rosnerea4e0402008-06-23 20:27:26 -070046
Yaniv Rosner26ffaf32011-10-27 05:09:45 +000047/* LED Blink rate that will achieve ~15.9Hz */
48#define LED_BLINK_RATE_VAL_E3 354
49#define LED_BLINK_RATE_VAL_E1X_E2 480
Yaniv Rosnerea4e0402008-06-23 20:27:26 -070050/***********************************************************/
Eilon Greenstein3196a882008-08-13 15:58:49 -070051/* Shortcut definitions */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -070052/***********************************************************/
53
Eilon Greenstein2f904462009-08-12 08:22:16 +000054#define NIG_LATCH_BC_ENABLE_MI_INT 0
55
56#define NIG_STATUS_EMAC0_MI_INT \
57 NIG_STATUS_INTERRUPT_PORT0_REG_STATUS_EMAC0_MISC_MI_INT
Yaniv Rosnerea4e0402008-06-23 20:27:26 -070058#define NIG_STATUS_XGXS0_LINK10G \
59 NIG_STATUS_INTERRUPT_PORT0_REG_STATUS_XGXS0_LINK10G
60#define NIG_STATUS_XGXS0_LINK_STATUS \
61 NIG_STATUS_INTERRUPT_PORT0_REG_STATUS_XGXS0_LINK_STATUS
62#define NIG_STATUS_XGXS0_LINK_STATUS_SIZE \
63 NIG_STATUS_INTERRUPT_PORT0_REG_STATUS_XGXS0_LINK_STATUS_SIZE
64#define NIG_STATUS_SERDES0_LINK_STATUS \
65 NIG_STATUS_INTERRUPT_PORT0_REG_STATUS_SERDES0_LINK_STATUS
66#define NIG_MASK_MI_INT \
67 NIG_MASK_INTERRUPT_PORT0_REG_MASK_EMAC0_MISC_MI_INT
68#define NIG_MASK_XGXS0_LINK10G \
69 NIG_MASK_INTERRUPT_PORT0_REG_MASK_XGXS0_LINK10G
70#define NIG_MASK_XGXS0_LINK_STATUS \
71 NIG_MASK_INTERRUPT_PORT0_REG_MASK_XGXS0_LINK_STATUS
72#define NIG_MASK_SERDES0_LINK_STATUS \
73 NIG_MASK_INTERRUPT_PORT0_REG_MASK_SERDES0_LINK_STATUS
74
75#define MDIO_AN_CL73_OR_37_COMPLETE \
76 (MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_AUTONEG_COMPLETE | \
77 MDIO_GP_STATUS_TOP_AN_STATUS1_CL37_AUTONEG_COMPLETE)
78
79#define XGXS_RESET_BITS \
80 (MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_XGXS0_RSTB_HW | \
81 MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_XGXS0_IDDQ | \
82 MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_XGXS0_PWRDWN | \
83 MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_XGXS0_PWRDWN_SD | \
84 MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_XGXS0_TXD_FIFO_RSTB)
85
86#define SERDES_RESET_BITS \
87 (MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_SERDES0_RSTB_HW | \
88 MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_SERDES0_IDDQ | \
89 MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_SERDES0_PWRDWN | \
90 MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_SERDES0_PWRDWN_SD)
91
92#define AUTONEG_CL37 SHARED_HW_CFG_AN_ENABLE_CL37
93#define AUTONEG_CL73 SHARED_HW_CFG_AN_ENABLE_CL73
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000094#define AUTONEG_BAM SHARED_HW_CFG_AN_ENABLE_BAM
Eilon Greenstein3196a882008-08-13 15:58:49 -070095#define AUTONEG_PARALLEL \
Yaniv Rosnerea4e0402008-06-23 20:27:26 -070096 SHARED_HW_CFG_AN_ENABLE_PARALLEL_DETECTION
Eilon Greenstein3196a882008-08-13 15:58:49 -070097#define AUTONEG_SGMII_FIBER_AUTODET \
Yaniv Rosnerea4e0402008-06-23 20:27:26 -070098 SHARED_HW_CFG_AN_EN_SGMII_FIBER_AUTO_DETECT
Eilon Greenstein3196a882008-08-13 15:58:49 -070099#define AUTONEG_REMOTE_PHY SHARED_HW_CFG_AN_ENABLE_REMOTE_PHY
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700100
101#define GP_STATUS_PAUSE_RSOLUTION_TXSIDE \
102 MDIO_GP_STATUS_TOP_AN_STATUS1_PAUSE_RSOLUTION_TXSIDE
103#define GP_STATUS_PAUSE_RSOLUTION_RXSIDE \
104 MDIO_GP_STATUS_TOP_AN_STATUS1_PAUSE_RSOLUTION_RXSIDE
105#define GP_STATUS_SPEED_MASK \
106 MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_MASK
107#define GP_STATUS_10M MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10M
108#define GP_STATUS_100M MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_100M
109#define GP_STATUS_1G MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_1G
110#define GP_STATUS_2_5G MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_2_5G
111#define GP_STATUS_5G MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_5G
112#define GP_STATUS_6G MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_6G
113#define GP_STATUS_10G_HIG \
114 MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10G_HIG
115#define GP_STATUS_10G_CX4 \
116 MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10G_CX4
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700117#define GP_STATUS_1G_KX MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_1G_KX
118#define GP_STATUS_10G_KX4 \
119 MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10G_KX4
Yaniv Rosner3c9ada22011-06-14 01:34:12 +0000120#define GP_STATUS_10G_KR MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10G_KR
121#define GP_STATUS_10G_XFI MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10G_XFI
122#define GP_STATUS_20G_DXGXS MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_20G_DXGXS
123#define GP_STATUS_10G_SFI MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10G_SFI
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000124#define LINK_10THD LINK_STATUS_SPEED_AND_DUPLEX_10THD
125#define LINK_10TFD LINK_STATUS_SPEED_AND_DUPLEX_10TFD
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700126#define LINK_100TXHD LINK_STATUS_SPEED_AND_DUPLEX_100TXHD
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000127#define LINK_100T4 LINK_STATUS_SPEED_AND_DUPLEX_100T4
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700128#define LINK_100TXFD LINK_STATUS_SPEED_AND_DUPLEX_100TXFD
129#define LINK_1000THD LINK_STATUS_SPEED_AND_DUPLEX_1000THD
130#define LINK_1000TFD LINK_STATUS_SPEED_AND_DUPLEX_1000TFD
131#define LINK_1000XFD LINK_STATUS_SPEED_AND_DUPLEX_1000XFD
132#define LINK_2500THD LINK_STATUS_SPEED_AND_DUPLEX_2500THD
133#define LINK_2500TFD LINK_STATUS_SPEED_AND_DUPLEX_2500TFD
134#define LINK_2500XFD LINK_STATUS_SPEED_AND_DUPLEX_2500XFD
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000135#define LINK_10GTFD LINK_STATUS_SPEED_AND_DUPLEX_10GTFD
136#define LINK_10GXFD LINK_STATUS_SPEED_AND_DUPLEX_10GXFD
Yaniv Rosner3c9ada22011-06-14 01:34:12 +0000137#define LINK_20GTFD LINK_STATUS_SPEED_AND_DUPLEX_20GTFD
138#define LINK_20GXFD LINK_STATUS_SPEED_AND_DUPLEX_20GXFD
Yaniv Rosner6583e332011-06-14 01:34:17 +0000139
140
141
Eilon Greenstein589abe32009-02-12 08:36:55 +0000142#define SFP_EEPROM_CON_TYPE_ADDR 0x2
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000143 #define SFP_EEPROM_CON_TYPE_VAL_LC 0x7
Eilon Greenstein589abe32009-02-12 08:36:55 +0000144 #define SFP_EEPROM_CON_TYPE_VAL_COPPER 0x21
145
Eilon Greenstein4d295db2009-07-21 05:47:47 +0000146
147#define SFP_EEPROM_COMP_CODE_ADDR 0x3
148 #define SFP_EEPROM_COMP_CODE_SR_MASK (1<<4)
149 #define SFP_EEPROM_COMP_CODE_LR_MASK (1<<5)
150 #define SFP_EEPROM_COMP_CODE_LRM_MASK (1<<6)
151
Eilon Greenstein589abe32009-02-12 08:36:55 +0000152#define SFP_EEPROM_FC_TX_TECH_ADDR 0x8
153 #define SFP_EEPROM_FC_TX_TECH_BITMASK_COPPER_PASSIVE 0x4
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000154 #define SFP_EEPROM_FC_TX_TECH_BITMASK_COPPER_ACTIVE 0x8
Eilon Greenstein4d295db2009-07-21 05:47:47 +0000155
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000156#define SFP_EEPROM_OPTIONS_ADDR 0x40
Eilon Greenstein589abe32009-02-12 08:36:55 +0000157 #define SFP_EEPROM_OPTIONS_LINEAR_RX_OUT_MASK 0x1
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000158#define SFP_EEPROM_OPTIONS_SIZE 2
Eilon Greenstein589abe32009-02-12 08:36:55 +0000159
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000160#define EDC_MODE_LINEAR 0x0022
161#define EDC_MODE_LIMITING 0x0044
162#define EDC_MODE_PASSIVE_DAC 0x0055
Eilon Greenstein589abe32009-02-12 08:36:55 +0000163
Yaniv Rosner866ceda2011-11-28 00:49:45 +0000164/* BRB default for class 0 E2 */
165#define DEFAULT0_E2_BRB_MAC_PAUSE_XOFF_THR 170
166#define DEFAULT0_E2_BRB_MAC_PAUSE_XON_THR 250
167#define DEFAULT0_E2_BRB_MAC_FULL_XOFF_THR 10
168#define DEFAULT0_E2_BRB_MAC_FULL_XON_THR 50
Eilon Greenstein4d295db2009-07-21 05:47:47 +0000169
Yaniv Rosner9380bb92011-06-14 01:34:07 +0000170/* BRB thresholds for E2*/
171#define PFC_E2_BRB_MAC_PAUSE_XOFF_THR_PAUSE 170
172#define PFC_E2_BRB_MAC_PAUSE_XOFF_THR_NON_PAUSE 0
173
174#define PFC_E2_BRB_MAC_PAUSE_XON_THR_PAUSE 250
175#define PFC_E2_BRB_MAC_PAUSE_XON_THR_NON_PAUSE 0
176
177#define PFC_E2_BRB_MAC_FULL_XOFF_THR_PAUSE 10
178#define PFC_E2_BRB_MAC_FULL_XOFF_THR_NON_PAUSE 90
179
180#define PFC_E2_BRB_MAC_FULL_XON_THR_PAUSE 50
181#define PFC_E2_BRB_MAC_FULL_XON_THR_NON_PAUSE 250
182
Yaniv Rosner866ceda2011-11-28 00:49:45 +0000183/* BRB default for class 0 E3A0 */
184#define DEFAULT0_E3A0_BRB_MAC_PAUSE_XOFF_THR 290
185#define DEFAULT0_E3A0_BRB_MAC_PAUSE_XON_THR 410
186#define DEFAULT0_E3A0_BRB_MAC_FULL_XOFF_THR 10
187#define DEFAULT0_E3A0_BRB_MAC_FULL_XON_THR 50
188
Yaniv Rosner9380bb92011-06-14 01:34:07 +0000189/* BRB thresholds for E3A0 */
190#define PFC_E3A0_BRB_MAC_PAUSE_XOFF_THR_PAUSE 290
191#define PFC_E3A0_BRB_MAC_PAUSE_XOFF_THR_NON_PAUSE 0
192
193#define PFC_E3A0_BRB_MAC_PAUSE_XON_THR_PAUSE 410
194#define PFC_E3A0_BRB_MAC_PAUSE_XON_THR_NON_PAUSE 0
195
196#define PFC_E3A0_BRB_MAC_FULL_XOFF_THR_PAUSE 10
197#define PFC_E3A0_BRB_MAC_FULL_XOFF_THR_NON_PAUSE 170
198
199#define PFC_E3A0_BRB_MAC_FULL_XON_THR_PAUSE 50
200#define PFC_E3A0_BRB_MAC_FULL_XON_THR_NON_PAUSE 410
201
Yaniv Rosner866ceda2011-11-28 00:49:45 +0000202/* BRB default for E3B0 */
203#define DEFAULT0_E3B0_BRB_MAC_PAUSE_XOFF_THR 330
204#define DEFAULT0_E3B0_BRB_MAC_PAUSE_XON_THR 490
205#define DEFAULT0_E3B0_BRB_MAC_FULL_XOFF_THR 15
206#define DEFAULT0_E3B0_BRB_MAC_FULL_XON_THR 55
Yaniv Rosner9380bb92011-06-14 01:34:07 +0000207
208/* BRB thresholds for E3B0 2 port mode*/
209#define PFC_E3B0_2P_BRB_MAC_PAUSE_XOFF_THR_PAUSE 1025
210#define PFC_E3B0_2P_BRB_MAC_PAUSE_XOFF_THR_NON_PAUSE 0
211
212#define PFC_E3B0_2P_BRB_MAC_PAUSE_XON_THR_PAUSE 1025
213#define PFC_E3B0_2P_BRB_MAC_PAUSE_XON_THR_NON_PAUSE 0
214
215#define PFC_E3B0_2P_BRB_MAC_FULL_XOFF_THR_PAUSE 10
216#define PFC_E3B0_2P_BRB_MAC_FULL_XOFF_THR_NON_PAUSE 1025
217
218#define PFC_E3B0_2P_BRB_MAC_FULL_XON_THR_PAUSE 50
219#define PFC_E3B0_2P_BRB_MAC_FULL_XON_THR_NON_PAUSE 1025
220
221/* only for E3B0*/
222#define PFC_E3B0_2P_BRB_FULL_LB_XOFF_THR 1025
223#define PFC_E3B0_2P_BRB_FULL_LB_XON_THR 1025
224
225/* Lossy +Lossless GUARANTIED == GUART */
226#define PFC_E3B0_2P_MIX_PAUSE_LB_GUART 284
227/* Lossless +Lossless*/
228#define PFC_E3B0_2P_PAUSE_LB_GUART 236
229/* Lossy +Lossy*/
230#define PFC_E3B0_2P_NON_PAUSE_LB_GUART 342
231
232/* Lossy +Lossless*/
233#define PFC_E3B0_2P_MIX_PAUSE_MAC_0_CLASS_T_GUART 284
234/* Lossless +Lossless*/
235#define PFC_E3B0_2P_PAUSE_MAC_0_CLASS_T_GUART 236
236/* Lossy +Lossy*/
237#define PFC_E3B0_2P_NON_PAUSE_MAC_0_CLASS_T_GUART 336
238#define PFC_E3B0_2P_BRB_MAC_0_CLASS_T_GUART_HYST 80
239
240#define PFC_E3B0_2P_BRB_MAC_1_CLASS_T_GUART 0
241#define PFC_E3B0_2P_BRB_MAC_1_CLASS_T_GUART_HYST 0
242
243/* BRB thresholds for E3B0 4 port mode */
244#define PFC_E3B0_4P_BRB_MAC_PAUSE_XOFF_THR_PAUSE 304
245#define PFC_E3B0_4P_BRB_MAC_PAUSE_XOFF_THR_NON_PAUSE 0
246
247#define PFC_E3B0_4P_BRB_MAC_PAUSE_XON_THR_PAUSE 384
248#define PFC_E3B0_4P_BRB_MAC_PAUSE_XON_THR_NON_PAUSE 0
249
250#define PFC_E3B0_4P_BRB_MAC_FULL_XOFF_THR_PAUSE 10
251#define PFC_E3B0_4P_BRB_MAC_FULL_XOFF_THR_NON_PAUSE 304
252
253#define PFC_E3B0_4P_BRB_MAC_FULL_XON_THR_PAUSE 50
254#define PFC_E3B0_4P_BRB_MAC_FULL_XON_THR_NON_PAUSE 384
255
Yaniv Rosner9380bb92011-06-14 01:34:07 +0000256/* only for E3B0*/
257#define PFC_E3B0_4P_BRB_FULL_LB_XOFF_THR 304
258#define PFC_E3B0_4P_BRB_FULL_LB_XON_THR 384
Yaniv Rosner2f751a82011-11-28 00:49:52 +0000259#define PFC_E3B0_4P_LB_GUART 120
Yaniv Rosner9380bb92011-06-14 01:34:07 +0000260
261#define PFC_E3B0_4P_BRB_MAC_0_CLASS_T_GUART 120
Yaniv Rosner2f751a82011-11-28 00:49:52 +0000262#define PFC_E3B0_4P_BRB_MAC_0_CLASS_T_GUART_HYST 80
Yaniv Rosner9380bb92011-06-14 01:34:07 +0000263
264#define PFC_E3B0_4P_BRB_MAC_1_CLASS_T_GUART 80
Yaniv Rosner2f751a82011-11-28 00:49:52 +0000265#define PFC_E3B0_4P_BRB_MAC_1_CLASS_T_GUART_HYST 120
Yaniv Rosner9380bb92011-06-14 01:34:07 +0000266
Yaniv Rosner866ceda2011-11-28 00:49:45 +0000267/* Pause defines*/
268#define DEFAULT_E3B0_BRB_FULL_LB_XOFF_THR 330
269#define DEFAULT_E3B0_BRB_FULL_LB_XON_THR 490
270#define DEFAULT_E3B0_LB_GUART 40
271
272#define DEFAULT_E3B0_BRB_MAC_0_CLASS_T_GUART 40
273#define DEFAULT_E3B0_BRB_MAC_0_CLASS_T_GUART_HYST 0
274
275#define DEFAULT_E3B0_BRB_MAC_1_CLASS_T_GUART 40
276#define DEFAULT_E3B0_BRB_MAC_1_CLASS_T_GUART_HYST 0
277
278/* ETS defines*/
Yaniv Rosner9380bb92011-06-14 01:34:07 +0000279#define DCBX_INVALID_COS (0xFF)
280
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000281#define ETS_BW_LIMIT_CREDIT_UPPER_BOUND (0x5000)
282#define ETS_BW_LIMIT_CREDIT_WEIGHT (0x5000)
Yaniv Rosner9380bb92011-06-14 01:34:07 +0000283#define ETS_E3B0_NIG_MIN_W_VAL_UP_TO_10GBPS (1360)
284#define ETS_E3B0_NIG_MIN_W_VAL_20GBPS (2720)
285#define ETS_E3B0_PBF_MIN_W_VAL (10000)
286
287#define MAX_PACKET_SIZE (9700)
Yaniv Rosnera9077bf2011-10-27 05:09:46 +0000288#define MAX_KR_LINK_RETRY 4
Yaniv Rosner9380bb92011-06-14 01:34:07 +0000289
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700290/**********************************************************/
291/* INTERFACE */
292/**********************************************************/
Yaniv Rosnere10bc842010-09-07 11:40:50 +0000293
Yaniv Rosnercd2be892011-01-31 04:21:45 +0000294#define CL22_WR_OVER_CL45(_bp, _phy, _bank, _addr, _val) \
Yaniv Rosnere10bc842010-09-07 11:40:50 +0000295 bnx2x_cl45_write(_bp, _phy, \
Yaniv Rosner7aa07112010-09-07 11:41:01 +0000296 (_phy)->def_md_devad, \
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700297 (_bank + (_addr & 0xf)), \
298 _val)
299
Yaniv Rosnercd2be892011-01-31 04:21:45 +0000300#define CL22_RD_OVER_CL45(_bp, _phy, _bank, _addr, _val) \
Yaniv Rosnere10bc842010-09-07 11:40:50 +0000301 bnx2x_cl45_read(_bp, _phy, \
Yaniv Rosner7aa07112010-09-07 11:41:01 +0000302 (_phy)->def_md_devad, \
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700303 (_bank + (_addr & 0xf)), \
304 _val)
305
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700306static u32 bnx2x_bits_en(struct bnx2x *bp, u32 reg, u32 bits)
307{
308 u32 val = REG_RD(bp, reg);
309
310 val |= bits;
311 REG_WR(bp, reg, val);
312 return val;
313}
314
315static u32 bnx2x_bits_dis(struct bnx2x *bp, u32 reg, u32 bits)
316{
317 u32 val = REG_RD(bp, reg);
318
319 val &= ~bits;
320 REG_WR(bp, reg, val);
321 return val;
322}
323
Yaniv Rosnerd3a8f132012-09-13 02:56:20 +0000324/*
325 * bnx2x_check_lfa - This function checks if link reinitialization is required,
326 * or link flap can be avoided.
327 *
328 * @params: link parameters
329 * Returns 0 if Link Flap Avoidance conditions are met otherwise, the failed
330 * condition code.
331 */
332static int bnx2x_check_lfa(struct link_params *params)
333{
334 u32 link_status, cfg_idx, lfa_mask, cfg_size;
335 u32 cur_speed_cap_mask, cur_req_fc_auto_adv, additional_config;
336 u32 saved_val, req_val, eee_status;
337 struct bnx2x *bp = params->bp;
338
339 additional_config =
340 REG_RD(bp, params->lfa_base +
341 offsetof(struct shmem_lfa, additional_config));
342
343 /* NOTE: must be first condition checked -
344 * to verify DCC bit is cleared in any case!
345 */
346 if (additional_config & NO_LFA_DUE_TO_DCC_MASK) {
347 DP(NETIF_MSG_LINK, "No LFA due to DCC flap after clp exit\n");
348 REG_WR(bp, params->lfa_base +
349 offsetof(struct shmem_lfa, additional_config),
350 additional_config & ~NO_LFA_DUE_TO_DCC_MASK);
351 return LFA_DCC_LFA_DISABLED;
352 }
353
354 /* Verify that link is up */
355 link_status = REG_RD(bp, params->shmem_base +
356 offsetof(struct shmem_region,
357 port_mb[params->port].link_status));
358 if (!(link_status & LINK_STATUS_LINK_UP))
359 return LFA_LINK_DOWN;
360
361 /* Verify that loopback mode is not set */
362 if (params->loopback_mode)
363 return LFA_LOOPBACK_ENABLED;
364
365 /* Verify that MFW supports LFA */
366 if (!params->lfa_base)
367 return LFA_MFW_IS_TOO_OLD;
368
369 if (params->num_phys == 3) {
370 cfg_size = 2;
371 lfa_mask = 0xffffffff;
372 } else {
373 cfg_size = 1;
374 lfa_mask = 0xffff;
375 }
376
377 /* Compare Duplex */
378 saved_val = REG_RD(bp, params->lfa_base +
379 offsetof(struct shmem_lfa, req_duplex));
380 req_val = params->req_duplex[0] | (params->req_duplex[1] << 16);
381 if ((saved_val & lfa_mask) != (req_val & lfa_mask)) {
382 DP(NETIF_MSG_LINK, "Duplex mismatch %x vs. %x\n",
383 (saved_val & lfa_mask), (req_val & lfa_mask));
384 return LFA_DUPLEX_MISMATCH;
385 }
386 /* Compare Flow Control */
387 saved_val = REG_RD(bp, params->lfa_base +
388 offsetof(struct shmem_lfa, req_flow_ctrl));
389 req_val = params->req_flow_ctrl[0] | (params->req_flow_ctrl[1] << 16);
390 if ((saved_val & lfa_mask) != (req_val & lfa_mask)) {
391 DP(NETIF_MSG_LINK, "Flow control mismatch %x vs. %x\n",
392 (saved_val & lfa_mask), (req_val & lfa_mask));
393 return LFA_FLOW_CTRL_MISMATCH;
394 }
395 /* Compare Link Speed */
396 saved_val = REG_RD(bp, params->lfa_base +
397 offsetof(struct shmem_lfa, req_line_speed));
398 req_val = params->req_line_speed[0] | (params->req_line_speed[1] << 16);
399 if ((saved_val & lfa_mask) != (req_val & lfa_mask)) {
400 DP(NETIF_MSG_LINK, "Link speed mismatch %x vs. %x\n",
401 (saved_val & lfa_mask), (req_val & lfa_mask));
402 return LFA_LINK_SPEED_MISMATCH;
403 }
404
405 for (cfg_idx = 0; cfg_idx < cfg_size; cfg_idx++) {
406 cur_speed_cap_mask = REG_RD(bp, params->lfa_base +
407 offsetof(struct shmem_lfa,
408 speed_cap_mask[cfg_idx]));
409
410 if (cur_speed_cap_mask != params->speed_cap_mask[cfg_idx]) {
411 DP(NETIF_MSG_LINK, "Speed Cap mismatch %x vs. %x\n",
412 cur_speed_cap_mask,
413 params->speed_cap_mask[cfg_idx]);
414 return LFA_SPEED_CAP_MISMATCH;
415 }
416 }
417
418 cur_req_fc_auto_adv =
419 REG_RD(bp, params->lfa_base +
420 offsetof(struct shmem_lfa, additional_config)) &
421 REQ_FC_AUTO_ADV_MASK;
422
423 if ((u16)cur_req_fc_auto_adv != params->req_fc_auto_adv) {
424 DP(NETIF_MSG_LINK, "Flow Ctrl AN mismatch %x vs. %x\n",
425 cur_req_fc_auto_adv, params->req_fc_auto_adv);
426 return LFA_FLOW_CTRL_MISMATCH;
427 }
428
429 eee_status = REG_RD(bp, params->shmem2_base +
430 offsetof(struct shmem2_region,
431 eee_status[params->port]));
432
433 if (((eee_status & SHMEM_EEE_LPI_REQUESTED_BIT) ^
434 (params->eee_mode & EEE_MODE_ENABLE_LPI)) ||
435 ((eee_status & SHMEM_EEE_REQUESTED_BIT) ^
436 (params->eee_mode & EEE_MODE_ADV_LPI))) {
437 DP(NETIF_MSG_LINK, "EEE mismatch %x vs. %x\n", params->eee_mode,
438 eee_status);
439 return LFA_EEE_MISMATCH;
440 }
441
442 /* LFA conditions are met */
443 return 0;
444}
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000445/******************************************************************/
Yaniv Rosner3c9ada22011-06-14 01:34:12 +0000446/* EPIO/GPIO section */
447/******************************************************************/
Yaniv Rosner3deb8162011-06-14 01:34:33 +0000448static void bnx2x_get_epio(struct bnx2x *bp, u32 epio_pin, u32 *en)
449{
450 u32 epio_mask, gp_oenable;
451 *en = 0;
452 /* Sanity check */
453 if (epio_pin > 31) {
454 DP(NETIF_MSG_LINK, "Invalid EPIO pin %d to get\n", epio_pin);
455 return;
456 }
457
458 epio_mask = 1 << epio_pin;
459 /* Set this EPIO to output */
460 gp_oenable = REG_RD(bp, MCP_REG_MCPR_GP_OENABLE);
461 REG_WR(bp, MCP_REG_MCPR_GP_OENABLE, gp_oenable & ~epio_mask);
462
463 *en = (REG_RD(bp, MCP_REG_MCPR_GP_INPUTS) & epio_mask) >> epio_pin;
464}
Yaniv Rosner3c9ada22011-06-14 01:34:12 +0000465static void bnx2x_set_epio(struct bnx2x *bp, u32 epio_pin, u32 en)
466{
467 u32 epio_mask, gp_output, gp_oenable;
468
469 /* Sanity check */
470 if (epio_pin > 31) {
471 DP(NETIF_MSG_LINK, "Invalid EPIO pin %d to set\n", epio_pin);
472 return;
473 }
474 DP(NETIF_MSG_LINK, "Setting EPIO pin %d to %d\n", epio_pin, en);
475 epio_mask = 1 << epio_pin;
476 /* Set this EPIO to output */
477 gp_output = REG_RD(bp, MCP_REG_MCPR_GP_OUTPUTS);
478 if (en)
479 gp_output |= epio_mask;
480 else
481 gp_output &= ~epio_mask;
482
483 REG_WR(bp, MCP_REG_MCPR_GP_OUTPUTS, gp_output);
484
485 /* Set the value for this EPIO */
486 gp_oenable = REG_RD(bp, MCP_REG_MCPR_GP_OENABLE);
487 REG_WR(bp, MCP_REG_MCPR_GP_OENABLE, gp_oenable | epio_mask);
488}
489
490static void bnx2x_set_cfg_pin(struct bnx2x *bp, u32 pin_cfg, u32 val)
491{
492 if (pin_cfg == PIN_CFG_NA)
493 return;
494 if (pin_cfg >= PIN_CFG_EPIO0) {
495 bnx2x_set_epio(bp, pin_cfg - PIN_CFG_EPIO0, val);
496 } else {
497 u8 gpio_num = (pin_cfg - PIN_CFG_GPIO0_P0) & 0x3;
498 u8 gpio_port = (pin_cfg - PIN_CFG_GPIO0_P0) >> 2;
499 bnx2x_set_gpio(bp, gpio_num, (u8)val, gpio_port);
500 }
501}
502
Yaniv Rosner3deb8162011-06-14 01:34:33 +0000503static u32 bnx2x_get_cfg_pin(struct bnx2x *bp, u32 pin_cfg, u32 *val)
504{
505 if (pin_cfg == PIN_CFG_NA)
506 return -EINVAL;
507 if (pin_cfg >= PIN_CFG_EPIO0) {
508 bnx2x_get_epio(bp, pin_cfg - PIN_CFG_EPIO0, val);
509 } else {
510 u8 gpio_num = (pin_cfg - PIN_CFG_GPIO0_P0) & 0x3;
511 u8 gpio_port = (pin_cfg - PIN_CFG_GPIO0_P0) >> 2;
512 *val = bnx2x_get_gpio(bp, gpio_num, gpio_port);
513 }
514 return 0;
515
516}
Yaniv Rosner3c9ada22011-06-14 01:34:12 +0000517/******************************************************************/
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000518/* ETS section */
519/******************************************************************/
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000520static void bnx2x_ets_e2e3a0_disabled(struct link_params *params)
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000521{
522 /* ETS disabled configuration*/
523 struct bnx2x *bp = params->bp;
524
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000525 DP(NETIF_MSG_LINK, "ETS E2E3 disabled configuration\n");
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000526
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000527 /* mapping between entry priority to client number (0,1,2 -debug and
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000528 * management clients, 3 - COS0 client, 4 - COS client)(HIGHEST)
529 * 3bits client num.
530 * PRI4 | PRI3 | PRI2 | PRI1 | PRI0
531 * cos1-100 cos0-011 dbg1-010 dbg0-001 MCP-000
532 */
533
534 REG_WR(bp, NIG_REG_P0_TX_ARB_PRIORITY_CLIENT, 0x4688);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000535 /* Bitmap of 5bits length. Each bit specifies whether the entry behaves
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000536 * as strict. Bits 0,1,2 - debug and management entries, 3 -
537 * COS0 entry, 4 - COS1 entry.
538 * COS1 | COS0 | DEBUG1 | DEBUG0 | MGMT
539 * bit4 bit3 bit2 bit1 bit0
540 * MCP and debug are strict
541 */
542
543 REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_IS_STRICT, 0x7);
544 /* defines which entries (clients) are subjected to WFQ arbitration */
545 REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_IS_SUBJECT2WFQ, 0);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000546 /* For strict priority entries defines the number of consecutive
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000547 * slots for the highest priority.
548 */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000549 REG_WR(bp, NIG_REG_P0_TX_ARB_NUM_STRICT_ARB_SLOTS, 0x100);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000550 /* mapping between the CREDIT_WEIGHT registers and actual client
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000551 * numbers
552 */
553 REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_CREDIT_MAP, 0);
554 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_0, 0);
555 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_1, 0);
556
557 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_0, 0);
558 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_1, 0);
559 REG_WR(bp, PBF_REG_HIGH_PRIORITY_COS_NUM, 0);
560 /* ETS mode disable */
561 REG_WR(bp, PBF_REG_ETS_ENABLED, 0);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000562 /* If ETS mode is enabled (there is no strict priority) defines a WFQ
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000563 * weight for COS0/COS1.
564 */
565 REG_WR(bp, PBF_REG_COS0_WEIGHT, 0x2710);
566 REG_WR(bp, PBF_REG_COS1_WEIGHT, 0x2710);
567 /* Upper bound that COS0_WEIGHT can reach in the WFQ arbiter */
568 REG_WR(bp, PBF_REG_COS0_UPPER_BOUND, 0x989680);
569 REG_WR(bp, PBF_REG_COS1_UPPER_BOUND, 0x989680);
570 /* Defines the number of consecutive slots for the strict priority */
571 REG_WR(bp, PBF_REG_NUM_STRICT_ARB_SLOTS, 0);
572}
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000573/******************************************************************************
574* Description:
575* Getting min_w_val will be set according to line speed .
576*.
577******************************************************************************/
578static u32 bnx2x_ets_get_min_w_val_nig(const struct link_vars *vars)
579{
580 u32 min_w_val = 0;
581 /* Calculate min_w_val.*/
582 if (vars->link_up) {
Yaniv Rosnerde0396f2011-11-28 00:49:53 +0000583 if (vars->line_speed == SPEED_20000)
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000584 min_w_val = ETS_E3B0_NIG_MIN_W_VAL_20GBPS;
585 else
586 min_w_val = ETS_E3B0_NIG_MIN_W_VAL_UP_TO_10GBPS;
587 } else
588 min_w_val = ETS_E3B0_NIG_MIN_W_VAL_20GBPS;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000589 /* If the link isn't up (static configuration for example ) The
590 * link will be according to 20GBPS.
591 */
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000592 return min_w_val;
593}
594/******************************************************************************
595* Description:
596* Getting credit upper bound form min_w_val.
597*.
598******************************************************************************/
599static u32 bnx2x_ets_get_credit_upper_bound(const u32 min_w_val)
600{
601 const u32 credit_upper_bound = (u32)MAXVAL((150 * min_w_val),
602 MAX_PACKET_SIZE);
603 return credit_upper_bound;
604}
605/******************************************************************************
606* Description:
607* Set credit upper bound for NIG.
608*.
609******************************************************************************/
610static void bnx2x_ets_e3b0_set_credit_upper_bound_nig(
611 const struct link_params *params,
612 const u32 min_w_val)
613{
614 struct bnx2x *bp = params->bp;
615 const u8 port = params->port;
616 const u32 credit_upper_bound =
617 bnx2x_ets_get_credit_upper_bound(min_w_val);
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000618
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000619 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_UPPER_BOUND_0 :
620 NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_0, credit_upper_bound);
621 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_UPPER_BOUND_1 :
622 NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_1, credit_upper_bound);
623 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_UPPER_BOUND_2 :
624 NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_2, credit_upper_bound);
625 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_UPPER_BOUND_3 :
626 NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_3, credit_upper_bound);
627 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_UPPER_BOUND_4 :
628 NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_4, credit_upper_bound);
629 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_UPPER_BOUND_5 :
630 NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_5, credit_upper_bound);
631
Yaniv Rosnerde0396f2011-11-28 00:49:53 +0000632 if (!port) {
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000633 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_6,
634 credit_upper_bound);
635 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_7,
636 credit_upper_bound);
637 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_8,
638 credit_upper_bound);
639 }
640}
641/******************************************************************************
642* Description:
643* Will return the NIG ETS registers to init values.Except
644* credit_upper_bound.
645* That isn't used in this configuration (No WFQ is enabled) and will be
646* configured acording to spec
647*.
648******************************************************************************/
649static void bnx2x_ets_e3b0_nig_disabled(const struct link_params *params,
650 const struct link_vars *vars)
651{
652 struct bnx2x *bp = params->bp;
653 const u8 port = params->port;
654 const u32 min_w_val = bnx2x_ets_get_min_w_val_nig(vars);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000655 /* Mapping between entry priority to client number (0,1,2 -debug and
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000656 * management clients, 3 - COS0 client, 4 - COS1, ... 8 -
657 * COS5)(HIGHEST) 4bits client num.TODO_ETS - Should be done by
658 * reset value or init tool
659 */
660 if (port) {
661 REG_WR(bp, NIG_REG_P1_TX_ARB_PRIORITY_CLIENT2_LSB, 0x543210);
662 REG_WR(bp, NIG_REG_P1_TX_ARB_PRIORITY_CLIENT2_MSB, 0x0);
663 } else {
664 REG_WR(bp, NIG_REG_P0_TX_ARB_PRIORITY_CLIENT2_LSB, 0x76543210);
665 REG_WR(bp, NIG_REG_P0_TX_ARB_PRIORITY_CLIENT2_MSB, 0x8);
666 }
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000667 /* For strict priority entries defines the number of consecutive
668 * slots for the highest priority.
669 */
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000670 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_NUM_STRICT_ARB_SLOTS :
671 NIG_REG_P1_TX_ARB_NUM_STRICT_ARB_SLOTS, 0x100);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000672 /* Mapping between the CREDIT_WEIGHT registers and actual client
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000673 * numbers
674 */
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000675 if (port) {
676 /*Port 1 has 6 COS*/
677 REG_WR(bp, NIG_REG_P1_TX_ARB_CLIENT_CREDIT_MAP2_LSB, 0x210543);
678 REG_WR(bp, NIG_REG_P1_TX_ARB_CLIENT_CREDIT_MAP2_MSB, 0x0);
679 } else {
680 /*Port 0 has 9 COS*/
681 REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_CREDIT_MAP2_LSB,
682 0x43210876);
683 REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_CREDIT_MAP2_MSB, 0x5);
684 }
685
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000686 /* Bitmap of 5bits length. Each bit specifies whether the entry behaves
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000687 * as strict. Bits 0,1,2 - debug and management entries, 3 -
688 * COS0 entry, 4 - COS1 entry.
689 * COS1 | COS0 | DEBUG1 | DEBUG0 | MGMT
690 * bit4 bit3 bit2 bit1 bit0
691 * MCP and debug are strict
692 */
693 if (port)
694 REG_WR(bp, NIG_REG_P1_TX_ARB_CLIENT_IS_STRICT, 0x3f);
695 else
696 REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_IS_STRICT, 0x1ff);
697 /* defines which entries (clients) are subjected to WFQ arbitration */
698 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CLIENT_IS_SUBJECT2WFQ :
699 NIG_REG_P0_TX_ARB_CLIENT_IS_SUBJECT2WFQ, 0);
700
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000701 /* Please notice the register address are note continuous and a
702 * for here is note appropriate.In 2 port mode port0 only COS0-5
703 * can be used. DEBUG1,DEBUG1,MGMT are never used for WFQ* In 4
704 * port mode port1 only COS0-2 can be used. DEBUG1,DEBUG1,MGMT
705 * are never used for WFQ
706 */
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000707 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_WEIGHT_0 :
708 NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_0, 0x0);
709 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_WEIGHT_1 :
710 NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_1, 0x0);
711 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_WEIGHT_2 :
712 NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_2, 0x0);
713 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_WEIGHT_3 :
714 NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_3, 0x0);
715 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_WEIGHT_4 :
716 NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_4, 0x0);
717 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_WEIGHT_5 :
718 NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_5, 0x0);
Yaniv Rosnerde0396f2011-11-28 00:49:53 +0000719 if (!port) {
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000720 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_6, 0x0);
721 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_7, 0x0);
722 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_8, 0x0);
723 }
724
725 bnx2x_ets_e3b0_set_credit_upper_bound_nig(params, min_w_val);
726}
727/******************************************************************************
728* Description:
729* Set credit upper bound for PBF.
730*.
731******************************************************************************/
732static void bnx2x_ets_e3b0_set_credit_upper_bound_pbf(
733 const struct link_params *params,
734 const u32 min_w_val)
735{
736 struct bnx2x *bp = params->bp;
737 const u32 credit_upper_bound =
738 bnx2x_ets_get_credit_upper_bound(min_w_val);
739 const u8 port = params->port;
740 u32 base_upper_bound = 0;
741 u8 max_cos = 0;
742 u8 i = 0;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000743 /* In 2 port mode port0 has COS0-5 that can be used for WFQ.In 4
744 * port mode port1 has COS0-2 that can be used for WFQ.
745 */
Yaniv Rosnerde0396f2011-11-28 00:49:53 +0000746 if (!port) {
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000747 base_upper_bound = PBF_REG_COS0_UPPER_BOUND_P0;
748 max_cos = DCBX_E3B0_MAX_NUM_COS_PORT0;
749 } else {
750 base_upper_bound = PBF_REG_COS0_UPPER_BOUND_P1;
751 max_cos = DCBX_E3B0_MAX_NUM_COS_PORT1;
752 }
753
754 for (i = 0; i < max_cos; i++)
755 REG_WR(bp, base_upper_bound + (i << 2), credit_upper_bound);
756}
757
758/******************************************************************************
759* Description:
760* Will return the PBF ETS registers to init values.Except
761* credit_upper_bound.
762* That isn't used in this configuration (No WFQ is enabled) and will be
763* configured acording to spec
764*.
765******************************************************************************/
766static void bnx2x_ets_e3b0_pbf_disabled(const struct link_params *params)
767{
768 struct bnx2x *bp = params->bp;
769 const u8 port = params->port;
770 const u32 min_w_val_pbf = ETS_E3B0_PBF_MIN_W_VAL;
771 u8 i = 0;
772 u32 base_weight = 0;
773 u8 max_cos = 0;
774
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000775 /* Mapping between entry priority to client number 0 - COS0
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000776 * client, 2 - COS1, ... 5 - COS5)(HIGHEST) 4bits client num.
777 * TODO_ETS - Should be done by reset value or init tool
778 */
779 if (port)
780 /* 0x688 (|011|0 10|00 1|000) */
781 REG_WR(bp, PBF_REG_ETS_ARB_PRIORITY_CLIENT_P1 , 0x688);
782 else
783 /* (10 1|100 |011|0 10|00 1|000) */
784 REG_WR(bp, PBF_REG_ETS_ARB_PRIORITY_CLIENT_P0 , 0x2C688);
785
786 /* TODO_ETS - Should be done by reset value or init tool */
787 if (port)
788 /* 0x688 (|011|0 10|00 1|000)*/
789 REG_WR(bp, PBF_REG_ETS_ARB_CLIENT_CREDIT_MAP_P1, 0x688);
790 else
791 /* 0x2C688 (10 1|100 |011|0 10|00 1|000) */
792 REG_WR(bp, PBF_REG_ETS_ARB_CLIENT_CREDIT_MAP_P0, 0x2C688);
793
794 REG_WR(bp, (port) ? PBF_REG_ETS_ARB_NUM_STRICT_ARB_SLOTS_P1 :
795 PBF_REG_ETS_ARB_NUM_STRICT_ARB_SLOTS_P0 , 0x100);
796
797
798 REG_WR(bp, (port) ? PBF_REG_ETS_ARB_CLIENT_IS_STRICT_P1 :
799 PBF_REG_ETS_ARB_CLIENT_IS_STRICT_P0 , 0);
800
801 REG_WR(bp, (port) ? PBF_REG_ETS_ARB_CLIENT_IS_SUBJECT2WFQ_P1 :
802 PBF_REG_ETS_ARB_CLIENT_IS_SUBJECT2WFQ_P0 , 0);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000803 /* In 2 port mode port0 has COS0-5 that can be used for WFQ.
804 * In 4 port mode port1 has COS0-2 that can be used for WFQ.
805 */
Yaniv Rosnerde0396f2011-11-28 00:49:53 +0000806 if (!port) {
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000807 base_weight = PBF_REG_COS0_WEIGHT_P0;
808 max_cos = DCBX_E3B0_MAX_NUM_COS_PORT0;
809 } else {
810 base_weight = PBF_REG_COS0_WEIGHT_P1;
811 max_cos = DCBX_E3B0_MAX_NUM_COS_PORT1;
812 }
813
814 for (i = 0; i < max_cos; i++)
815 REG_WR(bp, base_weight + (0x4 * i), 0);
816
817 bnx2x_ets_e3b0_set_credit_upper_bound_pbf(params, min_w_val_pbf);
818}
819/******************************************************************************
820* Description:
821* E3B0 disable will return basicly the values to init values.
822*.
823******************************************************************************/
824static int bnx2x_ets_e3b0_disabled(const struct link_params *params,
825 const struct link_vars *vars)
826{
827 struct bnx2x *bp = params->bp;
828
829 if (!CHIP_IS_E3B0(bp)) {
Joe Perches94f05b02011-08-14 12:16:20 +0000830 DP(NETIF_MSG_LINK,
831 "bnx2x_ets_e3b0_disabled the chip isn't E3B0\n");
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000832 return -EINVAL;
833 }
834
835 bnx2x_ets_e3b0_nig_disabled(params, vars);
836
837 bnx2x_ets_e3b0_pbf_disabled(params);
838
839 return 0;
840}
841
842/******************************************************************************
843* Description:
844* Disable will return basicly the values to init values.
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000845*
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000846******************************************************************************/
847int bnx2x_ets_disabled(struct link_params *params,
848 struct link_vars *vars)
849{
850 struct bnx2x *bp = params->bp;
851 int bnx2x_status = 0;
852
853 if ((CHIP_IS_E2(bp)) || (CHIP_IS_E3A0(bp)))
854 bnx2x_ets_e2e3a0_disabled(params);
855 else if (CHIP_IS_E3B0(bp))
856 bnx2x_status = bnx2x_ets_e3b0_disabled(params, vars);
857 else {
858 DP(NETIF_MSG_LINK, "bnx2x_ets_disabled - chip not supported\n");
859 return -EINVAL;
860 }
861
862 return bnx2x_status;
863}
864
865/******************************************************************************
866* Description
867* Set the COS mappimg to SP and BW until this point all the COS are not
868* set as SP or BW.
869******************************************************************************/
870static int bnx2x_ets_e3b0_cli_map(const struct link_params *params,
871 const struct bnx2x_ets_params *ets_params,
872 const u8 cos_sp_bitmap,
873 const u8 cos_bw_bitmap)
874{
875 struct bnx2x *bp = params->bp;
876 const u8 port = params->port;
877 const u8 nig_cli_sp_bitmap = 0x7 | (cos_sp_bitmap << 3);
878 const u8 pbf_cli_sp_bitmap = cos_sp_bitmap;
879 const u8 nig_cli_subject2wfq_bitmap = cos_bw_bitmap << 3;
880 const u8 pbf_cli_subject2wfq_bitmap = cos_bw_bitmap;
881
882 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CLIENT_IS_STRICT :
883 NIG_REG_P0_TX_ARB_CLIENT_IS_STRICT, nig_cli_sp_bitmap);
884
885 REG_WR(bp, (port) ? PBF_REG_ETS_ARB_CLIENT_IS_STRICT_P1 :
886 PBF_REG_ETS_ARB_CLIENT_IS_STRICT_P0 , pbf_cli_sp_bitmap);
887
888 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CLIENT_IS_SUBJECT2WFQ :
889 NIG_REG_P0_TX_ARB_CLIENT_IS_SUBJECT2WFQ,
890 nig_cli_subject2wfq_bitmap);
891
892 REG_WR(bp, (port) ? PBF_REG_ETS_ARB_CLIENT_IS_SUBJECT2WFQ_P1 :
893 PBF_REG_ETS_ARB_CLIENT_IS_SUBJECT2WFQ_P0,
894 pbf_cli_subject2wfq_bitmap);
895
896 return 0;
897}
898
899/******************************************************************************
900* Description:
901* This function is needed because NIG ARB_CREDIT_WEIGHT_X are
902* not continues and ARB_CREDIT_WEIGHT_0 + offset is suitable.
903******************************************************************************/
904static int bnx2x_ets_e3b0_set_cos_bw(struct bnx2x *bp,
905 const u8 cos_entry,
906 const u32 min_w_val_nig,
907 const u32 min_w_val_pbf,
908 const u16 total_bw,
909 const u8 bw,
910 const u8 port)
911{
912 u32 nig_reg_adress_crd_weight = 0;
913 u32 pbf_reg_adress_crd_weight = 0;
David S. Miller8decf862011-09-22 03:23:13 -0400914 /* Calculate and set BW for this COS - use 1 instead of 0 for BW */
915 const u32 cos_bw_nig = ((bw ? bw : 1) * min_w_val_nig) / total_bw;
916 const u32 cos_bw_pbf = ((bw ? bw : 1) * min_w_val_pbf) / total_bw;
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000917
918 switch (cos_entry) {
919 case 0:
920 nig_reg_adress_crd_weight =
921 (port) ? NIG_REG_P1_TX_ARB_CREDIT_WEIGHT_0 :
922 NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_0;
923 pbf_reg_adress_crd_weight = (port) ?
924 PBF_REG_COS0_WEIGHT_P1 : PBF_REG_COS0_WEIGHT_P0;
925 break;
926 case 1:
927 nig_reg_adress_crd_weight = (port) ?
928 NIG_REG_P1_TX_ARB_CREDIT_WEIGHT_1 :
929 NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_1;
930 pbf_reg_adress_crd_weight = (port) ?
931 PBF_REG_COS1_WEIGHT_P1 : PBF_REG_COS1_WEIGHT_P0;
932 break;
933 case 2:
934 nig_reg_adress_crd_weight = (port) ?
935 NIG_REG_P1_TX_ARB_CREDIT_WEIGHT_2 :
936 NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_2;
937
938 pbf_reg_adress_crd_weight = (port) ?
939 PBF_REG_COS2_WEIGHT_P1 : PBF_REG_COS2_WEIGHT_P0;
940 break;
941 case 3:
942 if (port)
943 return -EINVAL;
944 nig_reg_adress_crd_weight =
945 NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_3;
946 pbf_reg_adress_crd_weight =
947 PBF_REG_COS3_WEIGHT_P0;
948 break;
949 case 4:
950 if (port)
951 return -EINVAL;
952 nig_reg_adress_crd_weight =
953 NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_4;
954 pbf_reg_adress_crd_weight = PBF_REG_COS4_WEIGHT_P0;
955 break;
956 case 5:
957 if (port)
958 return -EINVAL;
959 nig_reg_adress_crd_weight =
960 NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_5;
961 pbf_reg_adress_crd_weight = PBF_REG_COS5_WEIGHT_P0;
962 break;
963 }
964
965 REG_WR(bp, nig_reg_adress_crd_weight, cos_bw_nig);
966
967 REG_WR(bp, pbf_reg_adress_crd_weight, cos_bw_pbf);
968
969 return 0;
970}
971/******************************************************************************
972* Description:
973* Calculate the total BW.A value of 0 isn't legal.
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000974*
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000975******************************************************************************/
976static int bnx2x_ets_e3b0_get_total_bw(
977 const struct link_params *params,
Yaniv Rosner870516e12011-11-28 00:49:46 +0000978 struct bnx2x_ets_params *ets_params,
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000979 u16 *total_bw)
980{
981 struct bnx2x *bp = params->bp;
982 u8 cos_idx = 0;
Yaniv Rosner870516e12011-11-28 00:49:46 +0000983 u8 is_bw_cos_exist = 0;
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000984
985 *total_bw = 0 ;
986 /* Calculate total BW requested */
987 for (cos_idx = 0; cos_idx < ets_params->num_of_cos; cos_idx++) {
Yaniv Rosnerde0396f2011-11-28 00:49:53 +0000988 if (ets_params->cos[cos_idx].state == bnx2x_cos_state_bw) {
Yaniv Rosner870516e12011-11-28 00:49:46 +0000989 is_bw_cos_exist = 1;
990 if (!ets_params->cos[cos_idx].params.bw_params.bw) {
991 DP(NETIF_MSG_LINK, "bnx2x_ets_E3B0_config BW"
992 "was set to 0\n");
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000993 /* This is to prevent a state when ramrods
Yaniv Rosner870516e12011-11-28 00:49:46 +0000994 * can't be sent
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000995 */
Yaniv Rosner870516e12011-11-28 00:49:46 +0000996 ets_params->cos[cos_idx].params.bw_params.bw
997 = 1;
998 }
David S. Miller8decf862011-09-22 03:23:13 -0400999 *total_bw +=
1000 ets_params->cos[cos_idx].params.bw_params.bw;
Yaniv Rosner6c3218c2011-06-14 01:34:23 +00001001 }
Yaniv Rosner6c3218c2011-06-14 01:34:23 +00001002 }
1003
David S. Miller8decf862011-09-22 03:23:13 -04001004 /* Check total BW is valid */
Yaniv Rosnerde0396f2011-11-28 00:49:53 +00001005 if ((is_bw_cos_exist == 1) && (*total_bw != 100)) {
1006 if (*total_bw == 0) {
Joe Perches94f05b02011-08-14 12:16:20 +00001007 DP(NETIF_MSG_LINK,
Yaniv Rosner2f751a82011-11-28 00:49:52 +00001008 "bnx2x_ets_E3B0_config total BW shouldn't be 0\n");
Yaniv Rosner6c3218c2011-06-14 01:34:23 +00001009 return -EINVAL;
1010 }
Joe Perches94f05b02011-08-14 12:16:20 +00001011 DP(NETIF_MSG_LINK,
Yaniv Rosner2f751a82011-11-28 00:49:52 +00001012 "bnx2x_ets_E3B0_config total BW should be 100\n");
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001013 /* We can handle a case whre the BW isn't 100 this can happen
Yaniv Rosner2f751a82011-11-28 00:49:52 +00001014 * if the TC are joined.
1015 */
Yaniv Rosner6c3218c2011-06-14 01:34:23 +00001016 }
1017 return 0;
1018}
1019
1020/******************************************************************************
1021* Description:
1022* Invalidate all the sp_pri_to_cos.
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001023*
Yaniv Rosner6c3218c2011-06-14 01:34:23 +00001024******************************************************************************/
1025static void bnx2x_ets_e3b0_sp_pri_to_cos_init(u8 *sp_pri_to_cos)
1026{
1027 u8 pri = 0;
1028 for (pri = 0; pri < DCBX_MAX_NUM_COS; pri++)
1029 sp_pri_to_cos[pri] = DCBX_INVALID_COS;
1030}
1031/******************************************************************************
1032* Description:
1033* Calculate and set the SP (ARB_PRIORITY_CLIENT) NIG and PBF registers
1034* according to sp_pri_to_cos.
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001035*
Yaniv Rosner6c3218c2011-06-14 01:34:23 +00001036******************************************************************************/
1037static int bnx2x_ets_e3b0_sp_pri_to_cos_set(const struct link_params *params,
1038 u8 *sp_pri_to_cos, const u8 pri,
1039 const u8 cos_entry)
1040{
1041 struct bnx2x *bp = params->bp;
1042 const u8 port = params->port;
1043 const u8 max_num_of_cos = (port) ? DCBX_E3B0_MAX_NUM_COS_PORT1 :
1044 DCBX_E3B0_MAX_NUM_COS_PORT0;
1045
Dan Carpenter7e5998a2012-04-17 20:53:42 +00001046 if (pri >= max_num_of_cos) {
1047 DP(NETIF_MSG_LINK, "bnx2x_ets_e3b0_sp_pri_to_cos_set invalid "
1048 "parameter Illegal strict priority\n");
1049 return -EINVAL;
1050 }
1051
Yaniv Rosnerde0396f2011-11-28 00:49:53 +00001052 if (sp_pri_to_cos[pri] != DCBX_INVALID_COS) {
Yaniv Rosner6c3218c2011-06-14 01:34:23 +00001053 DP(NETIF_MSG_LINK, "bnx2x_ets_e3b0_sp_pri_to_cos_set invalid "
Joe Perches94f05b02011-08-14 12:16:20 +00001054 "parameter There can't be two COS's with "
Yaniv Rosner6c3218c2011-06-14 01:34:23 +00001055 "the same strict pri\n");
1056 return -EINVAL;
1057 }
1058
Yaniv Rosner6c3218c2011-06-14 01:34:23 +00001059 sp_pri_to_cos[pri] = cos_entry;
1060 return 0;
1061
1062}
1063
1064/******************************************************************************
1065* Description:
1066* Returns the correct value according to COS and priority in
1067* the sp_pri_cli register.
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001068*
Yaniv Rosner6c3218c2011-06-14 01:34:23 +00001069******************************************************************************/
1070static u64 bnx2x_e3b0_sp_get_pri_cli_reg(const u8 cos, const u8 cos_offset,
1071 const u8 pri_set,
1072 const u8 pri_offset,
1073 const u8 entry_size)
1074{
1075 u64 pri_cli_nig = 0;
1076 pri_cli_nig = ((u64)(cos + cos_offset)) << (entry_size *
1077 (pri_set + pri_offset));
1078
1079 return pri_cli_nig;
1080}
1081/******************************************************************************
1082* Description:
1083* Returns the correct value according to COS and priority in the
1084* sp_pri_cli register for NIG.
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001085*
Yaniv Rosner6c3218c2011-06-14 01:34:23 +00001086******************************************************************************/
1087static u64 bnx2x_e3b0_sp_get_pri_cli_reg_nig(const u8 cos, const u8 pri_set)
1088{
1089 /* MCP Dbg0 and dbg1 are always with higher strict pri*/
1090 const u8 nig_cos_offset = 3;
1091 const u8 nig_pri_offset = 3;
1092
1093 return bnx2x_e3b0_sp_get_pri_cli_reg(cos, nig_cos_offset, pri_set,
1094 nig_pri_offset, 4);
1095
1096}
1097/******************************************************************************
1098* Description:
1099* Returns the correct value according to COS and priority in the
1100* sp_pri_cli register for PBF.
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001101*
Yaniv Rosner6c3218c2011-06-14 01:34:23 +00001102******************************************************************************/
1103static u64 bnx2x_e3b0_sp_get_pri_cli_reg_pbf(const u8 cos, const u8 pri_set)
1104{
1105 const u8 pbf_cos_offset = 0;
1106 const u8 pbf_pri_offset = 0;
1107
1108 return bnx2x_e3b0_sp_get_pri_cli_reg(cos, pbf_cos_offset, pri_set,
1109 pbf_pri_offset, 3);
1110
1111}
1112
1113/******************************************************************************
1114* Description:
1115* Calculate and set the SP (ARB_PRIORITY_CLIENT) NIG and PBF registers
1116* according to sp_pri_to_cos.(which COS has higher priority)
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001117*
Yaniv Rosner6c3218c2011-06-14 01:34:23 +00001118******************************************************************************/
1119static int bnx2x_ets_e3b0_sp_set_pri_cli_reg(const struct link_params *params,
1120 u8 *sp_pri_to_cos)
1121{
1122 struct bnx2x *bp = params->bp;
1123 u8 i = 0;
1124 const u8 port = params->port;
1125 /* MCP Dbg0 and dbg1 are always with higher strict pri*/
1126 u64 pri_cli_nig = 0x210;
1127 u32 pri_cli_pbf = 0x0;
1128 u8 pri_set = 0;
1129 u8 pri_bitmask = 0;
1130 const u8 max_num_of_cos = (port) ? DCBX_E3B0_MAX_NUM_COS_PORT1 :
1131 DCBX_E3B0_MAX_NUM_COS_PORT0;
1132
1133 u8 cos_bit_to_set = (1 << max_num_of_cos) - 1;
1134
1135 /* Set all the strict priority first */
1136 for (i = 0; i < max_num_of_cos; i++) {
Yaniv Rosnerde0396f2011-11-28 00:49:53 +00001137 if (sp_pri_to_cos[i] != DCBX_INVALID_COS) {
1138 if (sp_pri_to_cos[i] >= DCBX_MAX_NUM_COS) {
Yaniv Rosner6c3218c2011-06-14 01:34:23 +00001139 DP(NETIF_MSG_LINK,
1140 "bnx2x_ets_e3b0_sp_set_pri_cli_reg "
1141 "invalid cos entry\n");
1142 return -EINVAL;
1143 }
1144
1145 pri_cli_nig |= bnx2x_e3b0_sp_get_pri_cli_reg_nig(
1146 sp_pri_to_cos[i], pri_set);
1147
1148 pri_cli_pbf |= bnx2x_e3b0_sp_get_pri_cli_reg_pbf(
1149 sp_pri_to_cos[i], pri_set);
1150 pri_bitmask = 1 << sp_pri_to_cos[i];
1151 /* COS is used remove it from bitmap.*/
Yaniv Rosnerde0396f2011-11-28 00:49:53 +00001152 if (!(pri_bitmask & cos_bit_to_set)) {
Yaniv Rosner6c3218c2011-06-14 01:34:23 +00001153 DP(NETIF_MSG_LINK,
1154 "bnx2x_ets_e3b0_sp_set_pri_cli_reg "
1155 "invalid There can't be two COS's with"
1156 " the same strict pri\n");
1157 return -EINVAL;
1158 }
1159 cos_bit_to_set &= ~pri_bitmask;
1160 pri_set++;
1161 }
1162 }
1163
1164 /* Set all the Non strict priority i= COS*/
1165 for (i = 0; i < max_num_of_cos; i++) {
1166 pri_bitmask = 1 << i;
1167 /* Check if COS was already used for SP */
1168 if (pri_bitmask & cos_bit_to_set) {
1169 /* COS wasn't used for SP */
1170 pri_cli_nig |= bnx2x_e3b0_sp_get_pri_cli_reg_nig(
1171 i, pri_set);
1172
1173 pri_cli_pbf |= bnx2x_e3b0_sp_get_pri_cli_reg_pbf(
1174 i, pri_set);
1175 /* COS is used remove it from bitmap.*/
1176 cos_bit_to_set &= ~pri_bitmask;
1177 pri_set++;
1178 }
1179 }
1180
1181 if (pri_set != max_num_of_cos) {
1182 DP(NETIF_MSG_LINK, "bnx2x_ets_e3b0_sp_set_pri_cli_reg not all "
1183 "entries were set\n");
1184 return -EINVAL;
1185 }
1186
1187 if (port) {
1188 /* Only 6 usable clients*/
1189 REG_WR(bp, NIG_REG_P1_TX_ARB_PRIORITY_CLIENT2_LSB,
1190 (u32)pri_cli_nig);
1191
1192 REG_WR(bp, PBF_REG_ETS_ARB_PRIORITY_CLIENT_P1 , pri_cli_pbf);
1193 } else {
1194 /* Only 9 usable clients*/
1195 const u32 pri_cli_nig_lsb = (u32) (pri_cli_nig);
1196 const u32 pri_cli_nig_msb = (u32) ((pri_cli_nig >> 32) & 0xF);
1197
1198 REG_WR(bp, NIG_REG_P0_TX_ARB_PRIORITY_CLIENT2_LSB,
1199 pri_cli_nig_lsb);
1200 REG_WR(bp, NIG_REG_P0_TX_ARB_PRIORITY_CLIENT2_MSB,
1201 pri_cli_nig_msb);
1202
1203 REG_WR(bp, PBF_REG_ETS_ARB_PRIORITY_CLIENT_P0 , pri_cli_pbf);
1204 }
1205 return 0;
1206}
1207
1208/******************************************************************************
1209* Description:
1210* Configure the COS to ETS according to BW and SP settings.
1211******************************************************************************/
1212int bnx2x_ets_e3b0_config(const struct link_params *params,
1213 const struct link_vars *vars,
Yaniv Rosner870516e12011-11-28 00:49:46 +00001214 struct bnx2x_ets_params *ets_params)
Yaniv Rosner6c3218c2011-06-14 01:34:23 +00001215{
1216 struct bnx2x *bp = params->bp;
1217 int bnx2x_status = 0;
1218 const u8 port = params->port;
1219 u16 total_bw = 0;
1220 const u32 min_w_val_nig = bnx2x_ets_get_min_w_val_nig(vars);
1221 const u32 min_w_val_pbf = ETS_E3B0_PBF_MIN_W_VAL;
1222 u8 cos_bw_bitmap = 0;
1223 u8 cos_sp_bitmap = 0;
1224 u8 sp_pri_to_cos[DCBX_MAX_NUM_COS] = {0};
1225 const u8 max_num_of_cos = (port) ? DCBX_E3B0_MAX_NUM_COS_PORT1 :
1226 DCBX_E3B0_MAX_NUM_COS_PORT0;
1227 u8 cos_entry = 0;
1228
1229 if (!CHIP_IS_E3B0(bp)) {
Joe Perches94f05b02011-08-14 12:16:20 +00001230 DP(NETIF_MSG_LINK,
1231 "bnx2x_ets_e3b0_disabled the chip isn't E3B0\n");
Yaniv Rosner6c3218c2011-06-14 01:34:23 +00001232 return -EINVAL;
1233 }
1234
1235 if ((ets_params->num_of_cos > max_num_of_cos)) {
1236 DP(NETIF_MSG_LINK, "bnx2x_ets_E3B0_config the number of COS "
1237 "isn't supported\n");
1238 return -EINVAL;
1239 }
1240
1241 /* Prepare sp strict priority parameters*/
1242 bnx2x_ets_e3b0_sp_pri_to_cos_init(sp_pri_to_cos);
1243
1244 /* Prepare BW parameters*/
1245 bnx2x_status = bnx2x_ets_e3b0_get_total_bw(params, ets_params,
1246 &total_bw);
Yaniv Rosnerde0396f2011-11-28 00:49:53 +00001247 if (bnx2x_status) {
Joe Perches94f05b02011-08-14 12:16:20 +00001248 DP(NETIF_MSG_LINK,
1249 "bnx2x_ets_E3B0_config get_total_bw failed\n");
Yaniv Rosner6c3218c2011-06-14 01:34:23 +00001250 return -EINVAL;
1251 }
1252
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001253 /* Upper bound is set according to current link speed (min_w_val
Yaniv Rosner2f751a82011-11-28 00:49:52 +00001254 * should be the same for upper bound and COS credit val).
Yaniv Rosner6c3218c2011-06-14 01:34:23 +00001255 */
1256 bnx2x_ets_e3b0_set_credit_upper_bound_nig(params, min_w_val_nig);
1257 bnx2x_ets_e3b0_set_credit_upper_bound_pbf(params, min_w_val_pbf);
1258
1259
1260 for (cos_entry = 0; cos_entry < ets_params->num_of_cos; cos_entry++) {
1261 if (bnx2x_cos_state_bw == ets_params->cos[cos_entry].state) {
1262 cos_bw_bitmap |= (1 << cos_entry);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001263 /* The function also sets the BW in HW(not the mappin
Yaniv Rosner6c3218c2011-06-14 01:34:23 +00001264 * yet)
1265 */
1266 bnx2x_status = bnx2x_ets_e3b0_set_cos_bw(
1267 bp, cos_entry, min_w_val_nig, min_w_val_pbf,
1268 total_bw,
1269 ets_params->cos[cos_entry].params.bw_params.bw,
1270 port);
1271 } else if (bnx2x_cos_state_strict ==
1272 ets_params->cos[cos_entry].state){
1273 cos_sp_bitmap |= (1 << cos_entry);
1274
1275 bnx2x_status = bnx2x_ets_e3b0_sp_pri_to_cos_set(
1276 params,
1277 sp_pri_to_cos,
1278 ets_params->cos[cos_entry].params.sp_params.pri,
1279 cos_entry);
1280
1281 } else {
Joe Perches94f05b02011-08-14 12:16:20 +00001282 DP(NETIF_MSG_LINK,
1283 "bnx2x_ets_e3b0_config cos state not valid\n");
Yaniv Rosner6c3218c2011-06-14 01:34:23 +00001284 return -EINVAL;
1285 }
Yaniv Rosnerde0396f2011-11-28 00:49:53 +00001286 if (bnx2x_status) {
Joe Perches94f05b02011-08-14 12:16:20 +00001287 DP(NETIF_MSG_LINK,
1288 "bnx2x_ets_e3b0_config set cos bw failed\n");
Yaniv Rosner6c3218c2011-06-14 01:34:23 +00001289 return bnx2x_status;
1290 }
1291 }
1292
1293 /* Set SP register (which COS has higher priority) */
1294 bnx2x_status = bnx2x_ets_e3b0_sp_set_pri_cli_reg(params,
1295 sp_pri_to_cos);
1296
Yaniv Rosnerde0396f2011-11-28 00:49:53 +00001297 if (bnx2x_status) {
Joe Perches94f05b02011-08-14 12:16:20 +00001298 DP(NETIF_MSG_LINK,
1299 "bnx2x_ets_E3B0_config set_pri_cli_reg failed\n");
Yaniv Rosner6c3218c2011-06-14 01:34:23 +00001300 return bnx2x_status;
1301 }
1302
1303 /* Set client mapping of BW and strict */
1304 bnx2x_status = bnx2x_ets_e3b0_cli_map(params, ets_params,
1305 cos_sp_bitmap,
1306 cos_bw_bitmap);
1307
Yaniv Rosnerde0396f2011-11-28 00:49:53 +00001308 if (bnx2x_status) {
Yaniv Rosner6c3218c2011-06-14 01:34:23 +00001309 DP(NETIF_MSG_LINK, "bnx2x_ets_E3B0_config SP failed\n");
1310 return bnx2x_status;
1311 }
1312 return 0;
1313}
Yaniv Rosner65a001b2011-01-31 04:22:03 +00001314static void bnx2x_ets_bw_limit_common(const struct link_params *params)
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001315{
1316 /* ETS disabled configuration */
1317 struct bnx2x *bp = params->bp;
1318 DP(NETIF_MSG_LINK, "ETS enabled BW limit configuration\n");
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001319 /* Defines which entries (clients) are subjected to WFQ arbitration
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00001320 * COS0 0x8
1321 * COS1 0x10
1322 */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001323 REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_IS_SUBJECT2WFQ, 0x18);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001324 /* Mapping between the ARB_CREDIT_WEIGHT registers and actual
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00001325 * client numbers (WEIGHT_0 does not actually have to represent
1326 * client 0)
1327 * PRI4 | PRI3 | PRI2 | PRI1 | PRI0
1328 * cos1-001 cos0-000 dbg1-100 dbg0-011 MCP-010
1329 */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001330 REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_CREDIT_MAP, 0x111A);
1331
1332 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_0,
1333 ETS_BW_LIMIT_CREDIT_UPPER_BOUND);
1334 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_1,
1335 ETS_BW_LIMIT_CREDIT_UPPER_BOUND);
1336
1337 /* ETS mode enabled*/
1338 REG_WR(bp, PBF_REG_ETS_ENABLED, 1);
1339
1340 /* Defines the number of consecutive slots for the strict priority */
1341 REG_WR(bp, PBF_REG_NUM_STRICT_ARB_SLOTS, 0);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001342 /* Bitmap of 5bits length. Each bit specifies whether the entry behaves
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00001343 * as strict. Bits 0,1,2 - debug and management entries, 3 - COS0
1344 * entry, 4 - COS1 entry.
1345 * COS1 | COS0 | DEBUG21 | DEBUG0 | MGMT
1346 * bit4 bit3 bit2 bit1 bit0
1347 * MCP and debug are strict
1348 */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001349 REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_IS_STRICT, 0x7);
1350
1351 /* Upper bound that COS0_WEIGHT can reach in the WFQ arbiter.*/
1352 REG_WR(bp, PBF_REG_COS0_UPPER_BOUND,
1353 ETS_BW_LIMIT_CREDIT_UPPER_BOUND);
1354 REG_WR(bp, PBF_REG_COS1_UPPER_BOUND,
1355 ETS_BW_LIMIT_CREDIT_UPPER_BOUND);
1356}
1357
1358void bnx2x_ets_bw_limit(const struct link_params *params, const u32 cos0_bw,
1359 const u32 cos1_bw)
1360{
1361 /* ETS disabled configuration*/
1362 struct bnx2x *bp = params->bp;
1363 const u32 total_bw = cos0_bw + cos1_bw;
1364 u32 cos0_credit_weight = 0;
1365 u32 cos1_credit_weight = 0;
1366
1367 DP(NETIF_MSG_LINK, "ETS enabled BW limit configuration\n");
1368
Yaniv Rosnerde0396f2011-11-28 00:49:53 +00001369 if ((!total_bw) ||
1370 (!cos0_bw) ||
1371 (!cos1_bw)) {
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001372 DP(NETIF_MSG_LINK, "Total BW can't be zero\n");
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001373 return;
1374 }
1375
1376 cos0_credit_weight = (cos0_bw * ETS_BW_LIMIT_CREDIT_WEIGHT)/
1377 total_bw;
1378 cos1_credit_weight = (cos1_bw * ETS_BW_LIMIT_CREDIT_WEIGHT)/
1379 total_bw;
1380
1381 bnx2x_ets_bw_limit_common(params);
1382
1383 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_0, cos0_credit_weight);
1384 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_1, cos1_credit_weight);
1385
1386 REG_WR(bp, PBF_REG_COS0_WEIGHT, cos0_credit_weight);
1387 REG_WR(bp, PBF_REG_COS1_WEIGHT, cos1_credit_weight);
1388}
1389
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00001390int bnx2x_ets_strict(const struct link_params *params, const u8 strict_cos)
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001391{
1392 /* ETS disabled configuration*/
1393 struct bnx2x *bp = params->bp;
1394 u32 val = 0;
1395
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001396 DP(NETIF_MSG_LINK, "ETS enabled strict configuration\n");
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001397 /* Bitmap of 5bits length. Each bit specifies whether the entry behaves
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001398 * as strict. Bits 0,1,2 - debug and management entries,
1399 * 3 - COS0 entry, 4 - COS1 entry.
1400 * COS1 | COS0 | DEBUG21 | DEBUG0 | MGMT
1401 * bit4 bit3 bit2 bit1 bit0
1402 * MCP and debug are strict
1403 */
1404 REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_IS_STRICT, 0x1F);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001405 /* For strict priority entries defines the number of consecutive slots
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001406 * for the highest priority.
1407 */
1408 REG_WR(bp, NIG_REG_P0_TX_ARB_NUM_STRICT_ARB_SLOTS, 0x100);
1409 /* ETS mode disable */
1410 REG_WR(bp, PBF_REG_ETS_ENABLED, 0);
1411 /* Defines the number of consecutive slots for the strict priority */
1412 REG_WR(bp, PBF_REG_NUM_STRICT_ARB_SLOTS, 0x100);
1413
1414 /* Defines the number of consecutive slots for the strict priority */
1415 REG_WR(bp, PBF_REG_HIGH_PRIORITY_COS_NUM, strict_cos);
1416
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001417 /* Mapping between entry priority to client number (0,1,2 -debug and
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00001418 * management clients, 3 - COS0 client, 4 - COS client)(HIGHEST)
1419 * 3bits client num.
1420 * PRI4 | PRI3 | PRI2 | PRI1 | PRI0
1421 * dbg0-010 dbg1-001 cos1-100 cos0-011 MCP-000
1422 * dbg0-010 dbg1-001 cos0-011 cos1-100 MCP-000
1423 */
Yaniv Rosnerde0396f2011-11-28 00:49:53 +00001424 val = (!strict_cos) ? 0x2318 : 0x22E0;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001425 REG_WR(bp, NIG_REG_P0_TX_ARB_PRIORITY_CLIENT, val);
1426
1427 return 0;
1428}
Yuval Mintzc8c60d82012-06-06 17:13:07 +00001429
1430/******************************************************************/
Dmitry Kravkove8920672011-05-04 23:52:40 +00001431/* PFC section */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001432/******************************************************************/
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001433static void bnx2x_update_pfc_xmac(struct link_params *params,
1434 struct link_vars *vars,
1435 u8 is_lb)
1436{
1437 struct bnx2x *bp = params->bp;
1438 u32 xmac_base;
1439 u32 pause_val, pfc0_val, pfc1_val;
1440
1441 /* XMAC base adrr */
1442 xmac_base = (params->port) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
1443
1444 /* Initialize pause and pfc registers */
1445 pause_val = 0x18000;
1446 pfc0_val = 0xFFFF8000;
1447 pfc1_val = 0x2;
1448
1449 /* No PFC support */
1450 if (!(params->feature_config_flags &
1451 FEATURE_CONFIG_PFC_ENABLED)) {
1452
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001453 /* RX flow control - Process pause frame in receive direction
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001454 */
1455 if (vars->flow_ctrl & BNX2X_FLOW_CTRL_RX)
1456 pause_val |= XMAC_PAUSE_CTRL_REG_RX_PAUSE_EN;
1457
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001458 /* TX flow control - Send pause packet when buffer is full */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001459 if (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX)
1460 pause_val |= XMAC_PAUSE_CTRL_REG_TX_PAUSE_EN;
1461 } else {/* PFC support */
1462 pfc1_val |= XMAC_PFC_CTRL_HI_REG_PFC_REFRESH_EN |
1463 XMAC_PFC_CTRL_HI_REG_PFC_STATS_EN |
1464 XMAC_PFC_CTRL_HI_REG_RX_PFC_EN |
Yaniv Rosner27d91292012-04-04 01:28:54 +00001465 XMAC_PFC_CTRL_HI_REG_TX_PFC_EN |
1466 XMAC_PFC_CTRL_HI_REG_FORCE_PFC_XON;
1467 /* Write pause and PFC registers */
1468 REG_WR(bp, xmac_base + XMAC_REG_PAUSE_CTRL, pause_val);
1469 REG_WR(bp, xmac_base + XMAC_REG_PFC_CTRL, pfc0_val);
1470 REG_WR(bp, xmac_base + XMAC_REG_PFC_CTRL_HI, pfc1_val);
1471 pfc1_val &= ~XMAC_PFC_CTRL_HI_REG_FORCE_PFC_XON;
1472
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001473 }
1474
1475 /* Write pause and PFC registers */
1476 REG_WR(bp, xmac_base + XMAC_REG_PAUSE_CTRL, pause_val);
1477 REG_WR(bp, xmac_base + XMAC_REG_PFC_CTRL, pfc0_val);
1478 REG_WR(bp, xmac_base + XMAC_REG_PFC_CTRL_HI, pfc1_val);
1479
Yaniv Rosnerb8d6d082011-07-05 01:06:27 +00001480
1481 /* Set MAC address for source TX Pause/PFC frames */
1482 REG_WR(bp, xmac_base + XMAC_REG_CTRL_SA_LO,
1483 ((params->mac_addr[2] << 24) |
1484 (params->mac_addr[3] << 16) |
1485 (params->mac_addr[4] << 8) |
1486 (params->mac_addr[5])));
1487 REG_WR(bp, xmac_base + XMAC_REG_CTRL_SA_HI,
1488 ((params->mac_addr[0] << 8) |
1489 (params->mac_addr[1])));
1490
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001491 udelay(30);
1492}
1493
1494
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001495static void bnx2x_emac_get_pfc_stat(struct link_params *params,
1496 u32 pfc_frames_sent[2],
1497 u32 pfc_frames_received[2])
1498{
1499 /* Read pfc statistic */
1500 struct bnx2x *bp = params->bp;
1501 u32 emac_base = params->port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
1502 u32 val_xon = 0;
1503 u32 val_xoff = 0;
1504
1505 DP(NETIF_MSG_LINK, "pfc statistic read from EMAC\n");
1506
1507 /* PFC received frames */
1508 val_xoff = REG_RD(bp, emac_base +
1509 EMAC_REG_RX_PFC_STATS_XOFF_RCVD);
1510 val_xoff &= EMAC_REG_RX_PFC_STATS_XOFF_RCVD_COUNT;
1511 val_xon = REG_RD(bp, emac_base + EMAC_REG_RX_PFC_STATS_XON_RCVD);
1512 val_xon &= EMAC_REG_RX_PFC_STATS_XON_RCVD_COUNT;
1513
1514 pfc_frames_received[0] = val_xon + val_xoff;
1515
1516 /* PFC received sent */
1517 val_xoff = REG_RD(bp, emac_base +
1518 EMAC_REG_RX_PFC_STATS_XOFF_SENT);
1519 val_xoff &= EMAC_REG_RX_PFC_STATS_XOFF_SENT_COUNT;
1520 val_xon = REG_RD(bp, emac_base + EMAC_REG_RX_PFC_STATS_XON_SENT);
1521 val_xon &= EMAC_REG_RX_PFC_STATS_XON_SENT_COUNT;
1522
1523 pfc_frames_sent[0] = val_xon + val_xoff;
1524}
1525
Yaniv Rosnerb8d6d082011-07-05 01:06:27 +00001526/* Read pfc statistic*/
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001527void bnx2x_pfc_statistic(struct link_params *params, struct link_vars *vars,
1528 u32 pfc_frames_sent[2],
1529 u32 pfc_frames_received[2])
1530{
1531 /* Read pfc statistic */
1532 struct bnx2x *bp = params->bp;
Yaniv Rosnerb8d6d082011-07-05 01:06:27 +00001533
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001534 DP(NETIF_MSG_LINK, "pfc statistic\n");
1535
1536 if (!vars->link_up)
1537 return;
1538
Yaniv Rosnerde0396f2011-11-28 00:49:53 +00001539 if (vars->mac_type == MAC_TYPE_EMAC) {
Yaniv Rosnerb8d6d082011-07-05 01:06:27 +00001540 DP(NETIF_MSG_LINK, "About to read PFC stats from EMAC\n");
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001541 bnx2x_emac_get_pfc_stat(params, pfc_frames_sent,
1542 pfc_frames_received);
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001543 }
1544}
1545/******************************************************************/
1546/* MAC/PBF section */
1547/******************************************************************/
Yaniv Rosnera198c142011-05-31 21:29:42 +00001548static void bnx2x_set_mdio_clk(struct bnx2x *bp, u32 chip_id, u8 port)
1549{
1550 u32 mode, emac_base;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001551 /* Set clause 45 mode, slow down the MDIO clock to 2.5MHz
Yaniv Rosnera198c142011-05-31 21:29:42 +00001552 * (a value of 49==0x31) and make sure that the AUTO poll is off
1553 */
1554
1555 if (CHIP_IS_E2(bp))
1556 emac_base = GRCBASE_EMAC0;
1557 else
1558 emac_base = (port) ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
1559 mode = REG_RD(bp, emac_base + EMAC_REG_EMAC_MDIO_MODE);
1560 mode &= ~(EMAC_MDIO_MODE_AUTO_POLL |
1561 EMAC_MDIO_MODE_CLOCK_CNT);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00001562 if (USES_WARPCORE(bp))
1563 mode |= (74L << EMAC_MDIO_MODE_CLOCK_CNT_BITSHIFT);
1564 else
1565 mode |= (49L << EMAC_MDIO_MODE_CLOCK_CNT_BITSHIFT);
Yaniv Rosnera198c142011-05-31 21:29:42 +00001566
1567 mode |= (EMAC_MDIO_MODE_CLAUSE_45);
1568 REG_WR(bp, emac_base + EMAC_REG_EMAC_MDIO_MODE, mode);
1569
1570 udelay(40);
1571}
Yaniv Rosner2f751a82011-11-28 00:49:52 +00001572static u8 bnx2x_is_4_port_mode(struct bnx2x *bp)
1573{
1574 u32 port4mode_ovwr_val;
1575 /* Check 4-port override enabled */
1576 port4mode_ovwr_val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
1577 if (port4mode_ovwr_val & (1<<0)) {
1578 /* Return 4-port mode override value */
1579 return ((port4mode_ovwr_val & (1<<1)) == (1<<1));
1580 }
1581 /* Return 4-port mode from input pin */
1582 return (u8)REG_RD(bp, MISC_REG_PORT4MODE_EN);
1583}
Yaniv Rosnera198c142011-05-31 21:29:42 +00001584
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001585static void bnx2x_emac_init(struct link_params *params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001586 struct link_vars *vars)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001587{
1588 /* reset and unreset the emac core */
1589 struct bnx2x *bp = params->bp;
1590 u8 port = params->port;
1591 u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
1592 u32 val;
1593 u16 timeout;
1594
1595 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001596 (MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE << port));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001597 udelay(5);
1598 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001599 (MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE << port));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001600
1601 /* init emac - use read-modify-write */
1602 /* self clear reset */
1603 val = REG_RD(bp, emac_base + EMAC_REG_EMAC_MODE);
Eilon Greenstein3196a882008-08-13 15:58:49 -07001604 EMAC_WR(bp, EMAC_REG_EMAC_MODE, (val | EMAC_MODE_RESET));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001605
1606 timeout = 200;
Eilon Greenstein3196a882008-08-13 15:58:49 -07001607 do {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001608 val = REG_RD(bp, emac_base + EMAC_REG_EMAC_MODE);
1609 DP(NETIF_MSG_LINK, "EMAC reset reg is %u\n", val);
1610 if (!timeout) {
1611 DP(NETIF_MSG_LINK, "EMAC timeout!\n");
1612 return;
1613 }
1614 timeout--;
Eilon Greenstein3196a882008-08-13 15:58:49 -07001615 } while (val & EMAC_MODE_RESET);
Yaniv Rosnera198c142011-05-31 21:29:42 +00001616 bnx2x_set_mdio_clk(bp, params->chip_id, port);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001617 /* Set mac address */
1618 val = ((params->mac_addr[0] << 8) |
1619 params->mac_addr[1]);
Eilon Greenstein3196a882008-08-13 15:58:49 -07001620 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001621
1622 val = ((params->mac_addr[2] << 24) |
1623 (params->mac_addr[3] << 16) |
1624 (params->mac_addr[4] << 8) |
1625 params->mac_addr[5]);
Eilon Greenstein3196a882008-08-13 15:58:49 -07001626 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + 4, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001627}
1628
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001629static void bnx2x_set_xumac_nig(struct link_params *params,
1630 u16 tx_pause_en,
1631 u8 enable)
1632{
1633 struct bnx2x *bp = params->bp;
1634
1635 REG_WR(bp, params->port ? NIG_REG_P1_MAC_IN_EN : NIG_REG_P0_MAC_IN_EN,
1636 enable);
1637 REG_WR(bp, params->port ? NIG_REG_P1_MAC_OUT_EN : NIG_REG_P0_MAC_OUT_EN,
1638 enable);
1639 REG_WR(bp, params->port ? NIG_REG_P1_MAC_PAUSE_OUT_EN :
1640 NIG_REG_P0_MAC_PAUSE_OUT_EN, tx_pause_en);
1641}
1642
Yaniv Rosnerd3a8f132012-09-13 02:56:20 +00001643static void bnx2x_set_umac_rxtx(struct link_params *params, u8 en)
Yaniv Rosnerce7c0482011-10-27 05:09:47 +00001644{
1645 u32 umac_base = params->port ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
Yaniv Rosnerd3a8f132012-09-13 02:56:20 +00001646 u32 val;
Yaniv Rosnerce7c0482011-10-27 05:09:47 +00001647 struct bnx2x *bp = params->bp;
1648 if (!(REG_RD(bp, MISC_REG_RESET_REG_2) &
1649 (MISC_REGISTERS_RESET_REG_2_UMAC0 << params->port)))
1650 return;
Yaniv Rosnerd3a8f132012-09-13 02:56:20 +00001651 val = REG_RD(bp, umac_base + UMAC_REG_COMMAND_CONFIG);
1652 if (en)
1653 val |= (UMAC_COMMAND_CONFIG_REG_TX_ENA |
1654 UMAC_COMMAND_CONFIG_REG_RX_ENA);
1655 else
1656 val &= ~(UMAC_COMMAND_CONFIG_REG_TX_ENA |
1657 UMAC_COMMAND_CONFIG_REG_RX_ENA);
Yaniv Rosnerce7c0482011-10-27 05:09:47 +00001658 /* Disable RX and TX */
Yaniv Rosnerd3a8f132012-09-13 02:56:20 +00001659 REG_WR(bp, umac_base + UMAC_REG_COMMAND_CONFIG, val);
Yaniv Rosnerce7c0482011-10-27 05:09:47 +00001660}
1661
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001662static void bnx2x_umac_enable(struct link_params *params,
1663 struct link_vars *vars, u8 lb)
1664{
1665 u32 val;
1666 u32 umac_base = params->port ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
1667 struct bnx2x *bp = params->bp;
1668 /* Reset UMAC */
1669 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
1670 (MISC_REGISTERS_RESET_REG_2_UMAC0 << params->port));
Yuval Mintzd2310232012-06-20 19:05:19 +00001671 usleep_range(1000, 2000);
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001672
1673 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
1674 (MISC_REGISTERS_RESET_REG_2_UMAC0 << params->port));
1675
1676 DP(NETIF_MSG_LINK, "enabling UMAC\n");
1677
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001678 /* This register opens the gate for the UMAC despite its name */
1679 REG_WR(bp, NIG_REG_EGRESS_EMAC0_PORT + params->port*4, 1);
1680
1681 val = UMAC_COMMAND_CONFIG_REG_PROMIS_EN |
1682 UMAC_COMMAND_CONFIG_REG_PAD_EN |
1683 UMAC_COMMAND_CONFIG_REG_SW_RESET |
1684 UMAC_COMMAND_CONFIG_REG_NO_LGTH_CHECK;
1685 switch (vars->line_speed) {
1686 case SPEED_10:
1687 val |= (0<<2);
1688 break;
1689 case SPEED_100:
1690 val |= (1<<2);
1691 break;
1692 case SPEED_1000:
1693 val |= (2<<2);
1694 break;
1695 case SPEED_2500:
1696 val |= (3<<2);
1697 break;
1698 default:
1699 DP(NETIF_MSG_LINK, "Invalid speed for UMAC %d\n",
1700 vars->line_speed);
1701 break;
1702 }
Yaniv Rosner9d5b36b2011-08-02 22:59:10 +00001703 if (!(vars->flow_ctrl & BNX2X_FLOW_CTRL_TX))
1704 val |= UMAC_COMMAND_CONFIG_REG_IGNORE_TX_PAUSE;
1705
1706 if (!(vars->flow_ctrl & BNX2X_FLOW_CTRL_RX))
1707 val |= UMAC_COMMAND_CONFIG_REG_PAUSE_IGNORE;
1708
Mintz Yuvale18c56b2012-02-15 02:10:23 +00001709 if (vars->duplex == DUPLEX_HALF)
1710 val |= UMAC_COMMAND_CONFIG_REG_HD_ENA;
1711
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001712 REG_WR(bp, umac_base + UMAC_REG_COMMAND_CONFIG, val);
1713 udelay(50);
1714
Yuval Mintz26964bb2012-09-10 05:51:08 +00001715 /* Configure UMAC for EEE */
1716 if (vars->eee_status & SHMEM_EEE_ADV_STATUS_MASK) {
1717 DP(NETIF_MSG_LINK, "configured UMAC for EEE\n");
1718 REG_WR(bp, umac_base + UMAC_REG_UMAC_EEE_CTRL,
1719 UMAC_UMAC_EEE_CTRL_REG_EEE_EN);
1720 REG_WR(bp, umac_base + UMAC_REG_EEE_WAKE_TIMER, 0x11);
1721 } else {
1722 REG_WR(bp, umac_base + UMAC_REG_UMAC_EEE_CTRL, 0x0);
1723 }
1724
Yaniv Rosnerb8d6d082011-07-05 01:06:27 +00001725 /* Set MAC address for source TX Pause/PFC frames (under SW reset) */
1726 REG_WR(bp, umac_base + UMAC_REG_MAC_ADDR0,
1727 ((params->mac_addr[2] << 24) |
1728 (params->mac_addr[3] << 16) |
1729 (params->mac_addr[4] << 8) |
1730 (params->mac_addr[5])));
1731 REG_WR(bp, umac_base + UMAC_REG_MAC_ADDR1,
1732 ((params->mac_addr[0] << 8) |
1733 (params->mac_addr[1])));
1734
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001735 /* Enable RX and TX */
1736 val &= ~UMAC_COMMAND_CONFIG_REG_PAD_EN;
1737 val |= UMAC_COMMAND_CONFIG_REG_TX_ENA |
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00001738 UMAC_COMMAND_CONFIG_REG_RX_ENA;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001739 REG_WR(bp, umac_base + UMAC_REG_COMMAND_CONFIG, val);
1740 udelay(50);
1741
1742 /* Remove SW Reset */
1743 val &= ~UMAC_COMMAND_CONFIG_REG_SW_RESET;
1744
1745 /* Check loopback mode */
1746 if (lb)
1747 val |= UMAC_COMMAND_CONFIG_REG_LOOP_ENA;
1748 REG_WR(bp, umac_base + UMAC_REG_COMMAND_CONFIG, val);
1749
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001750 /* Maximum Frame Length (RW). Defines a 14-Bit maximum frame
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001751 * length used by the MAC receive logic to check frames.
1752 */
1753 REG_WR(bp, umac_base + UMAC_REG_MAXFR, 0x2710);
1754 bnx2x_set_xumac_nig(params,
1755 ((vars->flow_ctrl & BNX2X_FLOW_CTRL_TX) != 0), 1);
1756 vars->mac_type = MAC_TYPE_UMAC;
1757
1758}
1759
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001760/* Define the XMAC mode */
Yaniv Rosnerce7c0482011-10-27 05:09:47 +00001761static void bnx2x_xmac_init(struct link_params *params, u32 max_speed)
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001762{
Yaniv Rosnerce7c0482011-10-27 05:09:47 +00001763 struct bnx2x *bp = params->bp;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001764 u32 is_port4mode = bnx2x_is_4_port_mode(bp);
1765
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001766 /* In 4-port mode, need to set the mode only once, so if XMAC is
Yaniv Rosner2f751a82011-11-28 00:49:52 +00001767 * already out of reset, it means the mode has already been set,
1768 * and it must not* reset the XMAC again, since it controls both
1769 * ports of the path
1770 */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001771
Yuval Mintzc3def942012-07-23 10:25:43 +03001772 if ((CHIP_NUM(bp) == CHIP_NUM_57840_4_10) &&
Yaniv Rosnerce7c0482011-10-27 05:09:47 +00001773 (REG_RD(bp, MISC_REG_RESET_REG_2) &
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001774 MISC_REGISTERS_RESET_REG_2_XMAC)) {
Joe Perches94f05b02011-08-14 12:16:20 +00001775 DP(NETIF_MSG_LINK,
1776 "XMAC already out of reset in 4-port mode\n");
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001777 return;
1778 }
1779
1780 /* Hard reset */
1781 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
1782 MISC_REGISTERS_RESET_REG_2_XMAC);
Yuval Mintzd2310232012-06-20 19:05:19 +00001783 usleep_range(1000, 2000);
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001784
1785 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
1786 MISC_REGISTERS_RESET_REG_2_XMAC);
1787 if (is_port4mode) {
1788 DP(NETIF_MSG_LINK, "Init XMAC to 2 ports x 10G per path\n");
1789
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001790 /* Set the number of ports on the system side to up to 2 */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001791 REG_WR(bp, MISC_REG_XMAC_CORE_PORT_MODE, 1);
1792
1793 /* Set the number of ports on the Warp Core to 10G */
1794 REG_WR(bp, MISC_REG_XMAC_PHY_PORT_MODE, 3);
1795 } else {
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001796 /* Set the number of ports on the system side to 1 */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001797 REG_WR(bp, MISC_REG_XMAC_CORE_PORT_MODE, 0);
1798 if (max_speed == SPEED_10000) {
Joe Perches94f05b02011-08-14 12:16:20 +00001799 DP(NETIF_MSG_LINK,
1800 "Init XMAC to 10G x 1 port per path\n");
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001801 /* Set the number of ports on the Warp Core to 10G */
1802 REG_WR(bp, MISC_REG_XMAC_PHY_PORT_MODE, 3);
1803 } else {
Joe Perches94f05b02011-08-14 12:16:20 +00001804 DP(NETIF_MSG_LINK,
1805 "Init XMAC to 20G x 2 ports per path\n");
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001806 /* Set the number of ports on the Warp Core to 20G */
1807 REG_WR(bp, MISC_REG_XMAC_PHY_PORT_MODE, 1);
1808 }
1809 }
1810 /* Soft reset */
1811 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
1812 MISC_REGISTERS_RESET_REG_2_XMAC_SOFT);
Yuval Mintzd2310232012-06-20 19:05:19 +00001813 usleep_range(1000, 2000);
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001814
1815 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
1816 MISC_REGISTERS_RESET_REG_2_XMAC_SOFT);
1817
1818}
1819
Yaniv Rosnerd3a8f132012-09-13 02:56:20 +00001820static void bnx2x_set_xmac_rxtx(struct link_params *params, u8 en)
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001821{
1822 u8 port = params->port;
1823 struct bnx2x *bp = params->bp;
Yaniv Rosnerb5077662011-08-02 22:59:18 +00001824 u32 pfc_ctrl, xmac_base = (port) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
Yaniv Rosnerd3a8f132012-09-13 02:56:20 +00001825 u32 val;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001826
1827 if (REG_RD(bp, MISC_REG_RESET_REG_2) &
1828 MISC_REGISTERS_RESET_REG_2_XMAC) {
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001829 /* Send an indication to change the state in the NIG back to XON
Yaniv Rosnerb5077662011-08-02 22:59:18 +00001830 * Clearing this bit enables the next set of this bit to get
1831 * rising edge
1832 */
1833 pfc_ctrl = REG_RD(bp, xmac_base + XMAC_REG_PFC_CTRL_HI);
1834 REG_WR(bp, xmac_base + XMAC_REG_PFC_CTRL_HI,
1835 (pfc_ctrl & ~(1<<1)));
1836 REG_WR(bp, xmac_base + XMAC_REG_PFC_CTRL_HI,
1837 (pfc_ctrl | (1<<1)));
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001838 DP(NETIF_MSG_LINK, "Disable XMAC on port %x\n", port);
Yaniv Rosnerd3a8f132012-09-13 02:56:20 +00001839 val = REG_RD(bp, xmac_base + XMAC_REG_CTRL);
1840 if (en)
1841 val |= (XMAC_CTRL_REG_TX_EN | XMAC_CTRL_REG_RX_EN);
1842 else
1843 val &= ~(XMAC_CTRL_REG_TX_EN | XMAC_CTRL_REG_RX_EN);
1844 REG_WR(bp, xmac_base + XMAC_REG_CTRL, val);
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001845 }
1846}
1847
1848static int bnx2x_xmac_enable(struct link_params *params,
1849 struct link_vars *vars, u8 lb)
1850{
1851 u32 val, xmac_base;
1852 struct bnx2x *bp = params->bp;
1853 DP(NETIF_MSG_LINK, "enabling XMAC\n");
1854
1855 xmac_base = (params->port) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
1856
Yaniv Rosnerce7c0482011-10-27 05:09:47 +00001857 bnx2x_xmac_init(params, vars->line_speed);
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001858
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001859 /* This register determines on which events the MAC will assert
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001860 * error on the i/f to the NIG along w/ EOP.
1861 */
1862
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001863 /* This register tells the NIG whether to send traffic to UMAC
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001864 * or XMAC
1865 */
1866 REG_WR(bp, NIG_REG_EGRESS_EMAC0_PORT + params->port*4, 0);
1867
1868 /* Set Max packet size */
1869 REG_WR(bp, xmac_base + XMAC_REG_RX_MAX_SIZE, 0x2710);
1870
1871 /* CRC append for Tx packets */
1872 REG_WR(bp, xmac_base + XMAC_REG_TX_CTRL, 0xC800);
1873
1874 /* update PFC */
1875 bnx2x_update_pfc_xmac(params, vars, 0);
1876
Yuval Mintzc8c60d82012-06-06 17:13:07 +00001877 if (vars->eee_status & SHMEM_EEE_ADV_STATUS_MASK) {
1878 DP(NETIF_MSG_LINK, "Setting XMAC for EEE\n");
1879 REG_WR(bp, xmac_base + XMAC_REG_EEE_TIMERS_HI, 0x1380008);
1880 REG_WR(bp, xmac_base + XMAC_REG_EEE_CTRL, 0x1);
1881 } else {
1882 REG_WR(bp, xmac_base + XMAC_REG_EEE_CTRL, 0x0);
1883 }
1884
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001885 /* Enable TX and RX */
1886 val = XMAC_CTRL_REG_TX_EN | XMAC_CTRL_REG_RX_EN;
1887
1888 /* Check loopback mode */
1889 if (lb)
David S. Miller8decf862011-09-22 03:23:13 -04001890 val |= XMAC_CTRL_REG_LINE_LOCAL_LPBK;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001891 REG_WR(bp, xmac_base + XMAC_REG_CTRL, val);
1892 bnx2x_set_xumac_nig(params,
1893 ((vars->flow_ctrl & BNX2X_FLOW_CTRL_TX) != 0), 1);
1894
1895 vars->mac_type = MAC_TYPE_XMAC;
1896
1897 return 0;
1898}
Yaniv Rosner2f751a82011-11-28 00:49:52 +00001899
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00001900static int bnx2x_emac_enable(struct link_params *params,
Yaniv Rosner9045f6b42011-05-31 21:28:27 +00001901 struct link_vars *vars, u8 lb)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001902{
1903 struct bnx2x *bp = params->bp;
1904 u8 port = params->port;
1905 u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
1906 u32 val;
1907
1908 DP(NETIF_MSG_LINK, "enabling EMAC\n");
1909
Yaniv Rosnerde6f3372011-08-02 22:59:25 +00001910 /* Disable BMAC */
1911 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
1912 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port));
1913
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001914 /* enable emac and not bmac */
1915 REG_WR(bp, NIG_REG_EGRESS_EMAC0_PORT + port*4, 1);
1916
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001917 /* ASIC */
1918 if (vars->phy_flags & PHY_XGXS_FLAG) {
1919 u32 ser_lane = ((params->lane_config &
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001920 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_MASK) >>
1921 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_SHIFT);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001922
1923 DP(NETIF_MSG_LINK, "XGXS\n");
1924 /* select the master lanes (out of 0-3) */
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001925 REG_WR(bp, NIG_REG_XGXS_LANE_SEL_P0 + port*4, ser_lane);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001926 /* select XGXS */
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001927 REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001928
1929 } else { /* SerDes */
1930 DP(NETIF_MSG_LINK, "SerDes\n");
1931 /* select SerDes */
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001932 REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001933 }
1934
Eilon Greenstein811a2f22009-02-12 08:37:04 +00001935 bnx2x_bits_en(bp, emac_base + EMAC_REG_EMAC_RX_MODE,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001936 EMAC_RX_MODE_RESET);
Eilon Greenstein811a2f22009-02-12 08:37:04 +00001937 bnx2x_bits_en(bp, emac_base + EMAC_REG_EMAC_TX_MODE,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001938 EMAC_TX_MODE_RESET);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001939
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001940 /* pause enable/disable */
1941 bnx2x_bits_dis(bp, emac_base + EMAC_REG_EMAC_RX_MODE,
1942 EMAC_RX_MODE_FLOW_EN);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001943
1944 bnx2x_bits_dis(bp, emac_base + EMAC_REG_EMAC_TX_MODE,
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001945 (EMAC_TX_MODE_EXT_PAUSE_EN |
1946 EMAC_TX_MODE_FLOW_EN));
1947 if (!(params->feature_config_flags &
1948 FEATURE_CONFIG_PFC_ENABLED)) {
1949 if (vars->flow_ctrl & BNX2X_FLOW_CTRL_RX)
1950 bnx2x_bits_en(bp, emac_base +
1951 EMAC_REG_EMAC_RX_MODE,
1952 EMAC_RX_MODE_FLOW_EN);
1953
1954 if (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX)
1955 bnx2x_bits_en(bp, emac_base +
1956 EMAC_REG_EMAC_TX_MODE,
1957 (EMAC_TX_MODE_EXT_PAUSE_EN |
1958 EMAC_TX_MODE_FLOW_EN));
1959 } else
1960 bnx2x_bits_en(bp, emac_base + EMAC_REG_EMAC_TX_MODE,
1961 EMAC_TX_MODE_FLOW_EN);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001962
1963 /* KEEP_VLAN_TAG, promiscuous */
1964 val = REG_RD(bp, emac_base + EMAC_REG_EMAC_RX_MODE);
1965 val |= EMAC_RX_MODE_KEEP_VLAN_TAG | EMAC_RX_MODE_PROMISCUOUS;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001966
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001967 /* Setting this bit causes MAC control frames (except for pause
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00001968 * frames) to be passed on for processing. This setting has no
1969 * affect on the operation of the pause frames. This bit effects
1970 * all packets regardless of RX Parser packet sorting logic.
1971 * Turn the PFC off to make sure we are in Xon state before
1972 * enabling it.
1973 */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001974 EMAC_WR(bp, EMAC_REG_RX_PFC_MODE, 0);
1975 if (params->feature_config_flags & FEATURE_CONFIG_PFC_ENABLED) {
1976 DP(NETIF_MSG_LINK, "PFC is enabled\n");
1977 /* Enable PFC again */
1978 EMAC_WR(bp, EMAC_REG_RX_PFC_MODE,
1979 EMAC_REG_RX_PFC_MODE_RX_EN |
1980 EMAC_REG_RX_PFC_MODE_TX_EN |
1981 EMAC_REG_RX_PFC_MODE_PRIORITIES);
1982
1983 EMAC_WR(bp, EMAC_REG_RX_PFC_PARAM,
1984 ((0x0101 <<
1985 EMAC_REG_RX_PFC_PARAM_OPCODE_BITSHIFT) |
1986 (0x00ff <<
1987 EMAC_REG_RX_PFC_PARAM_PRIORITY_EN_BITSHIFT)));
1988 val |= EMAC_RX_MODE_KEEP_MAC_CONTROL;
1989 }
Eilon Greenstein3196a882008-08-13 15:58:49 -07001990 EMAC_WR(bp, EMAC_REG_EMAC_RX_MODE, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001991
1992 /* Set Loopback */
1993 val = REG_RD(bp, emac_base + EMAC_REG_EMAC_MODE);
1994 if (lb)
1995 val |= 0x810;
1996 else
1997 val &= ~0x810;
Eilon Greenstein3196a882008-08-13 15:58:49 -07001998 EMAC_WR(bp, EMAC_REG_EMAC_MODE, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001999
Yuval Mintzd2310232012-06-20 19:05:19 +00002000 /* Enable emac */
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00002001 REG_WR(bp, NIG_REG_NIG_EMAC0_EN + port*4, 1);
2002
Yuval Mintzd2310232012-06-20 19:05:19 +00002003 /* Enable emac for jumbo packets */
Eilon Greenstein3196a882008-08-13 15:58:49 -07002004 EMAC_WR(bp, EMAC_REG_EMAC_RX_MTU_SIZE,
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002005 (EMAC_RX_MTU_SIZE_JUMBO_ENA |
2006 (ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD)));
2007
Yuval Mintzd2310232012-06-20 19:05:19 +00002008 /* Strip CRC */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002009 REG_WR(bp, NIG_REG_NIG_INGRESS_EMAC0_NO_CRC + port*4, 0x1);
2010
Yuval Mintzd2310232012-06-20 19:05:19 +00002011 /* Disable the NIG in/out to the bmac */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002012 REG_WR(bp, NIG_REG_BMAC0_IN_EN + port*4, 0x0);
2013 REG_WR(bp, NIG_REG_BMAC0_PAUSE_OUT_EN + port*4, 0x0);
2014 REG_WR(bp, NIG_REG_BMAC0_OUT_EN + port*4, 0x0);
2015
Yuval Mintzd2310232012-06-20 19:05:19 +00002016 /* Enable the NIG in/out to the emac */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002017 REG_WR(bp, NIG_REG_EMAC0_IN_EN + port*4, 0x1);
2018 val = 0;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002019 if ((params->feature_config_flags &
2020 FEATURE_CONFIG_PFC_ENABLED) ||
2021 (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX))
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002022 val = 1;
2023
2024 REG_WR(bp, NIG_REG_EMAC0_PAUSE_OUT_EN + port*4, val);
2025 REG_WR(bp, NIG_REG_EGRESS_EMAC0_OUT_EN + port*4, 0x1);
2026
Yaniv Rosner02a23162011-01-31 04:22:53 +00002027 REG_WR(bp, NIG_REG_BMAC0_REGS_OUT_EN + port*4, 0x0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002028
2029 vars->mac_type = MAC_TYPE_EMAC;
2030 return 0;
2031}
2032
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002033static void bnx2x_update_pfc_bmac1(struct link_params *params,
2034 struct link_vars *vars)
2035{
2036 u32 wb_data[2];
2037 struct bnx2x *bp = params->bp;
2038 u32 bmac_addr = params->port ? NIG_REG_INGRESS_BMAC1_MEM :
2039 NIG_REG_INGRESS_BMAC0_MEM;
2040
2041 u32 val = 0x14;
2042 if ((!(params->feature_config_flags &
2043 FEATURE_CONFIG_PFC_ENABLED)) &&
2044 (vars->flow_ctrl & BNX2X_FLOW_CTRL_RX))
2045 /* Enable BigMAC to react on received Pause packets */
2046 val |= (1<<5);
2047 wb_data[0] = val;
2048 wb_data[1] = 0;
2049 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_RX_CONTROL, wb_data, 2);
2050
Yuval Mintzd2310232012-06-20 19:05:19 +00002051 /* TX control */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002052 val = 0xc0;
2053 if (!(params->feature_config_flags &
2054 FEATURE_CONFIG_PFC_ENABLED) &&
2055 (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX))
2056 val |= 0x800000;
2057 wb_data[0] = val;
2058 wb_data[1] = 0;
2059 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_TX_CONTROL, wb_data, 2);
2060}
2061
2062static void bnx2x_update_pfc_bmac2(struct link_params *params,
2063 struct link_vars *vars,
2064 u8 is_lb)
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002065{
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002066 /* Set rx control: Strip CRC and enable BigMAC to relay
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002067 * control packets to the system as well
2068 */
2069 u32 wb_data[2];
2070 struct bnx2x *bp = params->bp;
2071 u32 bmac_addr = params->port ? NIG_REG_INGRESS_BMAC1_MEM :
2072 NIG_REG_INGRESS_BMAC0_MEM;
2073 u32 val = 0x14;
2074
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002075 if ((!(params->feature_config_flags &
2076 FEATURE_CONFIG_PFC_ENABLED)) &&
2077 (vars->flow_ctrl & BNX2X_FLOW_CTRL_RX))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002078 /* Enable BigMAC to react on received Pause packets */
2079 val |= (1<<5);
2080 wb_data[0] = val;
2081 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002082 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_RX_CONTROL, wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002083 udelay(30);
2084
2085 /* Tx control */
2086 val = 0xc0;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002087 if (!(params->feature_config_flags &
2088 FEATURE_CONFIG_PFC_ENABLED) &&
2089 (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002090 val |= 0x800000;
2091 wb_data[0] = val;
2092 wb_data[1] = 0;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002093 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_TX_CONTROL, wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002094
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002095 if (params->feature_config_flags & FEATURE_CONFIG_PFC_ENABLED) {
2096 DP(NETIF_MSG_LINK, "PFC is enabled\n");
2097 /* Enable PFC RX & TX & STATS and set 8 COS */
2098 wb_data[0] = 0x0;
2099 wb_data[0] |= (1<<0); /* RX */
2100 wb_data[0] |= (1<<1); /* TX */
2101 wb_data[0] |= (1<<2); /* Force initial Xon */
2102 wb_data[0] |= (1<<3); /* 8 cos */
2103 wb_data[0] |= (1<<5); /* STATS */
2104 wb_data[1] = 0;
2105 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_PFC_CONTROL,
2106 wb_data, 2);
2107 /* Clear the force Xon */
2108 wb_data[0] &= ~(1<<2);
2109 } else {
2110 DP(NETIF_MSG_LINK, "PFC is disabled\n");
Yuval Mintzd2310232012-06-20 19:05:19 +00002111 /* Disable PFC RX & TX & STATS and set 8 COS */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002112 wb_data[0] = 0x8;
2113 wb_data[1] = 0;
2114 }
2115
2116 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_PFC_CONTROL, wb_data, 2);
2117
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002118 /* Set Time (based unit is 512 bit time) between automatic
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002119 * re-sending of PP packets amd enable automatic re-send of
2120 * Per-Priroity Packet as long as pp_gen is asserted and
2121 * pp_disable is low.
2122 */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002123 val = 0x8000;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002124 if (params->feature_config_flags & FEATURE_CONFIG_PFC_ENABLED)
2125 val |= (1<<16); /* enable automatic re-send */
2126
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002127 wb_data[0] = val;
2128 wb_data[1] = 0;
2129 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_TX_PAUSE_CONTROL,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002130 wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002131
2132 /* mac control */
2133 val = 0x3; /* Enable RX and TX */
2134 if (is_lb) {
2135 val |= 0x4; /* Local loopback */
2136 DP(NETIF_MSG_LINK, "enable bmac loopback\n");
2137 }
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002138 /* When PFC enabled, Pass pause frames towards the NIG. */
2139 if (params->feature_config_flags & FEATURE_CONFIG_PFC_ENABLED)
2140 val |= ((1<<6)|(1<<5));
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002141
2142 wb_data[0] = val;
2143 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002144 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_BMAC_CONTROL, wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002145}
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002146
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002147/* PFC BRB internal port configuration params */
2148struct bnx2x_pfc_brb_threshold_val {
2149 u32 pause_xoff;
2150 u32 pause_xon;
2151 u32 full_xoff;
2152 u32 full_xon;
2153};
2154
2155struct bnx2x_pfc_brb_e3b0_val {
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002156 u32 per_class_guaranty_mode;
2157 u32 lb_guarantied_hyst;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002158 u32 full_lb_xoff_th;
2159 u32 full_lb_xon_threshold;
2160 u32 lb_guarantied;
2161 u32 mac_0_class_t_guarantied;
2162 u32 mac_0_class_t_guarantied_hyst;
2163 u32 mac_1_class_t_guarantied;
2164 u32 mac_1_class_t_guarantied_hyst;
2165};
2166
2167struct bnx2x_pfc_brb_th_val {
2168 struct bnx2x_pfc_brb_threshold_val pauseable_th;
2169 struct bnx2x_pfc_brb_threshold_val non_pauseable_th;
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002170 struct bnx2x_pfc_brb_threshold_val default_class0;
2171 struct bnx2x_pfc_brb_threshold_val default_class1;
2172
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002173};
2174static int bnx2x_pfc_brb_get_config_params(
2175 struct link_params *params,
2176 struct bnx2x_pfc_brb_th_val *config_val)
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002177{
2178 struct bnx2x *bp = params->bp;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002179 DP(NETIF_MSG_LINK, "Setting PFC BRB configuration\n");
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002180
2181 config_val->default_class1.pause_xoff = 0;
2182 config_val->default_class1.pause_xon = 0;
2183 config_val->default_class1.full_xoff = 0;
2184 config_val->default_class1.full_xon = 0;
2185
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002186 if (CHIP_IS_E2(bp)) {
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002187 /* Class0 defaults */
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002188 config_val->default_class0.pause_xoff =
2189 DEFAULT0_E2_BRB_MAC_PAUSE_XOFF_THR;
2190 config_val->default_class0.pause_xon =
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002191 DEFAULT0_E2_BRB_MAC_PAUSE_XON_THR;
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002192 config_val->default_class0.full_xoff =
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002193 DEFAULT0_E2_BRB_MAC_FULL_XOFF_THR;
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002194 config_val->default_class0.full_xon =
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002195 DEFAULT0_E2_BRB_MAC_FULL_XON_THR;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002196 /* Pause able*/
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002197 config_val->pauseable_th.pause_xoff =
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002198 PFC_E2_BRB_MAC_PAUSE_XOFF_THR_PAUSE;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002199 config_val->pauseable_th.pause_xon =
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002200 PFC_E2_BRB_MAC_PAUSE_XON_THR_PAUSE;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002201 config_val->pauseable_th.full_xoff =
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002202 PFC_E2_BRB_MAC_FULL_XOFF_THR_PAUSE;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002203 config_val->pauseable_th.full_xon =
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002204 PFC_E2_BRB_MAC_FULL_XON_THR_PAUSE;
Yuval Mintzd2310232012-06-20 19:05:19 +00002205 /* Non pause able*/
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002206 config_val->non_pauseable_th.pause_xoff =
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002207 PFC_E2_BRB_MAC_PAUSE_XOFF_THR_NON_PAUSE;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002208 config_val->non_pauseable_th.pause_xon =
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002209 PFC_E2_BRB_MAC_PAUSE_XON_THR_NON_PAUSE;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002210 config_val->non_pauseable_th.full_xoff =
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002211 PFC_E2_BRB_MAC_FULL_XOFF_THR_NON_PAUSE;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002212 config_val->non_pauseable_th.full_xon =
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002213 PFC_E2_BRB_MAC_FULL_XON_THR_NON_PAUSE;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002214 } else if (CHIP_IS_E3A0(bp)) {
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002215 /* Class0 defaults */
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002216 config_val->default_class0.pause_xoff =
2217 DEFAULT0_E3A0_BRB_MAC_PAUSE_XOFF_THR;
2218 config_val->default_class0.pause_xon =
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002219 DEFAULT0_E3A0_BRB_MAC_PAUSE_XON_THR;
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002220 config_val->default_class0.full_xoff =
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002221 DEFAULT0_E3A0_BRB_MAC_FULL_XOFF_THR;
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002222 config_val->default_class0.full_xon =
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002223 DEFAULT0_E3A0_BRB_MAC_FULL_XON_THR;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002224 /* Pause able */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002225 config_val->pauseable_th.pause_xoff =
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002226 PFC_E3A0_BRB_MAC_PAUSE_XOFF_THR_PAUSE;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002227 config_val->pauseable_th.pause_xon =
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002228 PFC_E3A0_BRB_MAC_PAUSE_XON_THR_PAUSE;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002229 config_val->pauseable_th.full_xoff =
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002230 PFC_E3A0_BRB_MAC_FULL_XOFF_THR_PAUSE;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002231 config_val->pauseable_th.full_xon =
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002232 PFC_E3A0_BRB_MAC_FULL_XON_THR_PAUSE;
Yuval Mintzd2310232012-06-20 19:05:19 +00002233 /* Non pause able*/
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002234 config_val->non_pauseable_th.pause_xoff =
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002235 PFC_E3A0_BRB_MAC_PAUSE_XOFF_THR_NON_PAUSE;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002236 config_val->non_pauseable_th.pause_xon =
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002237 PFC_E3A0_BRB_MAC_PAUSE_XON_THR_NON_PAUSE;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002238 config_val->non_pauseable_th.full_xoff =
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002239 PFC_E3A0_BRB_MAC_FULL_XOFF_THR_NON_PAUSE;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002240 config_val->non_pauseable_th.full_xon =
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002241 PFC_E3A0_BRB_MAC_FULL_XON_THR_NON_PAUSE;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002242 } else if (CHIP_IS_E3B0(bp)) {
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002243 /* Class0 defaults */
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002244 config_val->default_class0.pause_xoff =
2245 DEFAULT0_E3B0_BRB_MAC_PAUSE_XOFF_THR;
2246 config_val->default_class0.pause_xon =
2247 DEFAULT0_E3B0_BRB_MAC_PAUSE_XON_THR;
2248 config_val->default_class0.full_xoff =
2249 DEFAULT0_E3B0_BRB_MAC_FULL_XOFF_THR;
2250 config_val->default_class0.full_xon =
2251 DEFAULT0_E3B0_BRB_MAC_FULL_XON_THR;
2252
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002253 if (params->phy[INT_PHY].flags &
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002254 FLAGS_4_PORT_MODE) {
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002255 config_val->pauseable_th.pause_xoff =
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002256 PFC_E3B0_4P_BRB_MAC_PAUSE_XOFF_THR_PAUSE;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002257 config_val->pauseable_th.pause_xon =
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002258 PFC_E3B0_4P_BRB_MAC_PAUSE_XON_THR_PAUSE;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002259 config_val->pauseable_th.full_xoff =
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002260 PFC_E3B0_4P_BRB_MAC_FULL_XOFF_THR_PAUSE;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002261 config_val->pauseable_th.full_xon =
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002262 PFC_E3B0_4P_BRB_MAC_FULL_XON_THR_PAUSE;
Yuval Mintzd2310232012-06-20 19:05:19 +00002263 /* Non pause able*/
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002264 config_val->non_pauseable_th.pause_xoff =
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002265 PFC_E3B0_4P_BRB_MAC_PAUSE_XOFF_THR_NON_PAUSE;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002266 config_val->non_pauseable_th.pause_xon =
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002267 PFC_E3B0_4P_BRB_MAC_PAUSE_XON_THR_NON_PAUSE;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002268 config_val->non_pauseable_th.full_xoff =
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002269 PFC_E3B0_4P_BRB_MAC_FULL_XOFF_THR_NON_PAUSE;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002270 config_val->non_pauseable_th.full_xon =
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002271 PFC_E3B0_4P_BRB_MAC_FULL_XON_THR_NON_PAUSE;
2272 } else {
2273 config_val->pauseable_th.pause_xoff =
2274 PFC_E3B0_2P_BRB_MAC_PAUSE_XOFF_THR_PAUSE;
2275 config_val->pauseable_th.pause_xon =
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002276 PFC_E3B0_2P_BRB_MAC_PAUSE_XON_THR_PAUSE;
2277 config_val->pauseable_th.full_xoff =
2278 PFC_E3B0_2P_BRB_MAC_FULL_XOFF_THR_PAUSE;
2279 config_val->pauseable_th.full_xon =
2280 PFC_E3B0_2P_BRB_MAC_FULL_XON_THR_PAUSE;
Yuval Mintzd2310232012-06-20 19:05:19 +00002281 /* Non pause able*/
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002282 config_val->non_pauseable_th.pause_xoff =
2283 PFC_E3B0_2P_BRB_MAC_PAUSE_XOFF_THR_NON_PAUSE;
2284 config_val->non_pauseable_th.pause_xon =
2285 PFC_E3B0_2P_BRB_MAC_PAUSE_XON_THR_NON_PAUSE;
2286 config_val->non_pauseable_th.full_xoff =
2287 PFC_E3B0_2P_BRB_MAC_FULL_XOFF_THR_NON_PAUSE;
2288 config_val->non_pauseable_th.full_xon =
2289 PFC_E3B0_2P_BRB_MAC_FULL_XON_THR_NON_PAUSE;
2290 }
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002291 } else
2292 return -EINVAL;
2293
2294 return 0;
2295}
2296
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002297static void bnx2x_pfc_brb_get_e3b0_config_params(
2298 struct link_params *params,
2299 struct bnx2x_pfc_brb_e3b0_val
2300 *e3b0_val,
2301 struct bnx2x_nig_brb_pfc_port_params *pfc_params,
2302 const u8 pfc_enabled)
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002303{
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002304 if (pfc_enabled && pfc_params) {
2305 e3b0_val->per_class_guaranty_mode = 1;
2306 e3b0_val->lb_guarantied_hyst = 80;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002307
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002308 if (params->phy[INT_PHY].flags &
2309 FLAGS_4_PORT_MODE) {
2310 e3b0_val->full_lb_xoff_th =
2311 PFC_E3B0_4P_BRB_FULL_LB_XOFF_THR;
2312 e3b0_val->full_lb_xon_threshold =
2313 PFC_E3B0_4P_BRB_FULL_LB_XON_THR;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002314 e3b0_val->lb_guarantied =
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002315 PFC_E3B0_4P_LB_GUART;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002316 e3b0_val->mac_0_class_t_guarantied =
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002317 PFC_E3B0_4P_BRB_MAC_0_CLASS_T_GUART;
2318 e3b0_val->mac_0_class_t_guarantied_hyst =
2319 PFC_E3B0_4P_BRB_MAC_0_CLASS_T_GUART_HYST;
2320 e3b0_val->mac_1_class_t_guarantied =
2321 PFC_E3B0_4P_BRB_MAC_1_CLASS_T_GUART;
2322 e3b0_val->mac_1_class_t_guarantied_hyst =
2323 PFC_E3B0_4P_BRB_MAC_1_CLASS_T_GUART_HYST;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002324 } else {
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002325 e3b0_val->full_lb_xoff_th =
2326 PFC_E3B0_2P_BRB_FULL_LB_XOFF_THR;
2327 e3b0_val->full_lb_xon_threshold =
2328 PFC_E3B0_2P_BRB_FULL_LB_XON_THR;
2329 e3b0_val->mac_0_class_t_guarantied_hyst =
2330 PFC_E3B0_2P_BRB_MAC_0_CLASS_T_GUART_HYST;
2331 e3b0_val->mac_1_class_t_guarantied =
2332 PFC_E3B0_2P_BRB_MAC_1_CLASS_T_GUART;
2333 e3b0_val->mac_1_class_t_guarantied_hyst =
2334 PFC_E3B0_2P_BRB_MAC_1_CLASS_T_GUART_HYST;
2335
2336 if (pfc_params->cos0_pauseable !=
2337 pfc_params->cos1_pauseable) {
Yuval Mintzd2310232012-06-20 19:05:19 +00002338 /* Nonpauseable= Lossy + pauseable = Lossless*/
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002339 e3b0_val->lb_guarantied =
2340 PFC_E3B0_2P_MIX_PAUSE_LB_GUART;
2341 e3b0_val->mac_0_class_t_guarantied =
2342 PFC_E3B0_2P_MIX_PAUSE_MAC_0_CLASS_T_GUART;
2343 } else if (pfc_params->cos0_pauseable) {
2344 /* Lossless +Lossless*/
2345 e3b0_val->lb_guarantied =
2346 PFC_E3B0_2P_PAUSE_LB_GUART;
2347 e3b0_val->mac_0_class_t_guarantied =
2348 PFC_E3B0_2P_PAUSE_MAC_0_CLASS_T_GUART;
2349 } else {
2350 /* Lossy +Lossy*/
2351 e3b0_val->lb_guarantied =
2352 PFC_E3B0_2P_NON_PAUSE_LB_GUART;
2353 e3b0_val->mac_0_class_t_guarantied =
2354 PFC_E3B0_2P_NON_PAUSE_MAC_0_CLASS_T_GUART;
2355 }
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002356 }
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002357 } else {
2358 e3b0_val->per_class_guaranty_mode = 0;
2359 e3b0_val->lb_guarantied_hyst = 0;
2360 e3b0_val->full_lb_xoff_th =
2361 DEFAULT_E3B0_BRB_FULL_LB_XOFF_THR;
2362 e3b0_val->full_lb_xon_threshold =
2363 DEFAULT_E3B0_BRB_FULL_LB_XON_THR;
2364 e3b0_val->lb_guarantied =
2365 DEFAULT_E3B0_LB_GUART;
2366 e3b0_val->mac_0_class_t_guarantied =
2367 DEFAULT_E3B0_BRB_MAC_0_CLASS_T_GUART;
2368 e3b0_val->mac_0_class_t_guarantied_hyst =
2369 DEFAULT_E3B0_BRB_MAC_0_CLASS_T_GUART_HYST;
2370 e3b0_val->mac_1_class_t_guarantied =
2371 DEFAULT_E3B0_BRB_MAC_1_CLASS_T_GUART;
2372 e3b0_val->mac_1_class_t_guarantied_hyst =
2373 DEFAULT_E3B0_BRB_MAC_1_CLASS_T_GUART_HYST;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002374 }
2375}
2376static int bnx2x_update_pfc_brb(struct link_params *params,
2377 struct link_vars *vars,
2378 struct bnx2x_nig_brb_pfc_port_params
2379 *pfc_params)
2380{
2381 struct bnx2x *bp = params->bp;
2382 struct bnx2x_pfc_brb_th_val config_val = { {0} };
2383 struct bnx2x_pfc_brb_threshold_val *reg_th_config =
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002384 &config_val.pauseable_th;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002385 struct bnx2x_pfc_brb_e3b0_val e3b0_val = {0};
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002386 const int set_pfc = params->feature_config_flags &
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002387 FEATURE_CONFIG_PFC_ENABLED;
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002388 const u8 pfc_enabled = (set_pfc && pfc_params);
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002389 int bnx2x_status = 0;
2390 u8 port = params->port;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002391
2392 /* default - pause configuration */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002393 reg_th_config = &config_val.pauseable_th;
2394 bnx2x_status = bnx2x_pfc_brb_get_config_params(params, &config_val);
Yaniv Rosnerde0396f2011-11-28 00:49:53 +00002395 if (bnx2x_status)
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002396 return bnx2x_status;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002397
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002398 if (pfc_enabled) {
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002399 /* First COS */
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002400 if (pfc_params->cos0_pauseable)
2401 reg_th_config = &config_val.pauseable_th;
2402 else
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002403 reg_th_config = &config_val.non_pauseable_th;
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002404 } else
2405 reg_th_config = &config_val.default_class0;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002406 /* The number of free blocks below which the pause signal to class 0
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002407 * of MAC #n is asserted. n=0,1
2408 */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002409 REG_WR(bp, (port) ? BRB1_REG_PAUSE_0_XOFF_THRESHOLD_1 :
2410 BRB1_REG_PAUSE_0_XOFF_THRESHOLD_0 ,
2411 reg_th_config->pause_xoff);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002412 /* The number of free blocks above which the pause signal to class 0
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002413 * of MAC #n is de-asserted. n=0,1
2414 */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002415 REG_WR(bp, (port) ? BRB1_REG_PAUSE_0_XON_THRESHOLD_1 :
2416 BRB1_REG_PAUSE_0_XON_THRESHOLD_0 , reg_th_config->pause_xon);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002417 /* The number of free blocks below which the full signal to class 0
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002418 * of MAC #n is asserted. n=0,1
2419 */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002420 REG_WR(bp, (port) ? BRB1_REG_FULL_0_XOFF_THRESHOLD_1 :
2421 BRB1_REG_FULL_0_XOFF_THRESHOLD_0 , reg_th_config->full_xoff);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002422 /* The number of free blocks above which the full signal to class 0
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002423 * of MAC #n is de-asserted. n=0,1
2424 */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002425 REG_WR(bp, (port) ? BRB1_REG_FULL_0_XON_THRESHOLD_1 :
2426 BRB1_REG_FULL_0_XON_THRESHOLD_0 , reg_th_config->full_xon);
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002427
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002428 if (pfc_enabled) {
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002429 /* Second COS */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002430 if (pfc_params->cos1_pauseable)
2431 reg_th_config = &config_val.pauseable_th;
2432 else
2433 reg_th_config = &config_val.non_pauseable_th;
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002434 } else
2435 reg_th_config = &config_val.default_class1;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002436 /* The number of free blocks below which the pause signal to
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002437 * class 1 of MAC #n is asserted. n=0,1
2438 */
2439 REG_WR(bp, (port) ? BRB1_REG_PAUSE_1_XOFF_THRESHOLD_1 :
2440 BRB1_REG_PAUSE_1_XOFF_THRESHOLD_0,
2441 reg_th_config->pause_xoff);
2442
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002443 /* The number of free blocks above which the pause signal to
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002444 * class 1 of MAC #n is de-asserted. n=0,1
2445 */
2446 REG_WR(bp, (port) ? BRB1_REG_PAUSE_1_XON_THRESHOLD_1 :
2447 BRB1_REG_PAUSE_1_XON_THRESHOLD_0,
2448 reg_th_config->pause_xon);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002449 /* The number of free blocks below which the full signal to
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002450 * class 1 of MAC #n is asserted. n=0,1
2451 */
2452 REG_WR(bp, (port) ? BRB1_REG_FULL_1_XOFF_THRESHOLD_1 :
2453 BRB1_REG_FULL_1_XOFF_THRESHOLD_0,
2454 reg_th_config->full_xoff);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002455 /* The number of free blocks above which the full signal to
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002456 * class 1 of MAC #n is de-asserted. n=0,1
2457 */
2458 REG_WR(bp, (port) ? BRB1_REG_FULL_1_XON_THRESHOLD_1 :
2459 BRB1_REG_FULL_1_XON_THRESHOLD_0,
2460 reg_th_config->full_xon);
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002461
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002462 if (CHIP_IS_E3B0(bp)) {
2463 bnx2x_pfc_brb_get_e3b0_config_params(
2464 params,
2465 &e3b0_val,
2466 pfc_params,
2467 pfc_enabled);
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002468
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002469 REG_WR(bp, BRB1_REG_PER_CLASS_GUARANTY_MODE,
2470 e3b0_val.per_class_guaranty_mode);
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002471
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002472 /* The hysteresis on the guarantied buffer space for the Lb
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002473 * port before signaling XON.
2474 */
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002475 REG_WR(bp, BRB1_REG_LB_GUARANTIED_HYST,
2476 e3b0_val.lb_guarantied_hyst);
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002477
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002478 /* The number of free blocks below which the full signal to the
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002479 * LB port is asserted.
2480 */
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002481 REG_WR(bp, BRB1_REG_FULL_LB_XOFF_THRESHOLD,
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002482 e3b0_val.full_lb_xoff_th);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002483 /* The number of free blocks above which the full signal to the
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002484 * LB port is de-asserted.
2485 */
2486 REG_WR(bp, BRB1_REG_FULL_LB_XON_THRESHOLD,
2487 e3b0_val.full_lb_xon_threshold);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002488 /* The number of blocks guarantied for the MAC #n port. n=0,1
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002489 */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002490
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002491 /* The number of blocks guarantied for the LB port. */
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002492 REG_WR(bp, BRB1_REG_LB_GUARANTIED,
2493 e3b0_val.lb_guarantied);
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002494
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002495 /* The number of blocks guarantied for the MAC #n port. */
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002496 REG_WR(bp, BRB1_REG_MAC_GUARANTIED_0,
2497 2 * e3b0_val.mac_0_class_t_guarantied);
2498 REG_WR(bp, BRB1_REG_MAC_GUARANTIED_1,
2499 2 * e3b0_val.mac_1_class_t_guarantied);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002500 /* The number of blocks guarantied for class #t in MAC0. t=0,1
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002501 */
2502 REG_WR(bp, BRB1_REG_MAC_0_CLASS_0_GUARANTIED,
2503 e3b0_val.mac_0_class_t_guarantied);
2504 REG_WR(bp, BRB1_REG_MAC_0_CLASS_1_GUARANTIED,
2505 e3b0_val.mac_0_class_t_guarantied);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002506 /* The hysteresis on the guarantied buffer space for class in
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002507 * MAC0. t=0,1
2508 */
2509 REG_WR(bp, BRB1_REG_MAC_0_CLASS_0_GUARANTIED_HYST,
2510 e3b0_val.mac_0_class_t_guarantied_hyst);
2511 REG_WR(bp, BRB1_REG_MAC_0_CLASS_1_GUARANTIED_HYST,
2512 e3b0_val.mac_0_class_t_guarantied_hyst);
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002513
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002514 /* The number of blocks guarantied for class #t in MAC1.t=0,1
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002515 */
2516 REG_WR(bp, BRB1_REG_MAC_1_CLASS_0_GUARANTIED,
2517 e3b0_val.mac_1_class_t_guarantied);
2518 REG_WR(bp, BRB1_REG_MAC_1_CLASS_1_GUARANTIED,
2519 e3b0_val.mac_1_class_t_guarantied);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002520 /* The hysteresis on the guarantied buffer space for class #t
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002521 * in MAC1. t=0,1
2522 */
2523 REG_WR(bp, BRB1_REG_MAC_1_CLASS_0_GUARANTIED_HYST,
2524 e3b0_val.mac_1_class_t_guarantied_hyst);
2525 REG_WR(bp, BRB1_REG_MAC_1_CLASS_1_GUARANTIED_HYST,
2526 e3b0_val.mac_1_class_t_guarantied_hyst);
2527 }
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002528
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002529 return bnx2x_status;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002530}
2531
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002532/******************************************************************************
2533* Description:
2534* This function is needed because NIG ARB_CREDIT_WEIGHT_X are
2535* not continues and ARB_CREDIT_WEIGHT_0 + offset is suitable.
2536******************************************************************************/
Yuval Mintzd2310232012-06-20 19:05:19 +00002537static int bnx2x_pfc_nig_rx_priority_mask(struct bnx2x *bp,
2538 u8 cos_entry,
2539 u32 priority_mask, u8 port)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002540{
2541 u32 nig_reg_rx_priority_mask_add = 0;
2542
2543 switch (cos_entry) {
2544 case 0:
2545 nig_reg_rx_priority_mask_add = (port) ?
2546 NIG_REG_P1_RX_COS0_PRIORITY_MASK :
2547 NIG_REG_P0_RX_COS0_PRIORITY_MASK;
2548 break;
2549 case 1:
2550 nig_reg_rx_priority_mask_add = (port) ?
2551 NIG_REG_P1_RX_COS1_PRIORITY_MASK :
2552 NIG_REG_P0_RX_COS1_PRIORITY_MASK;
2553 break;
2554 case 2:
2555 nig_reg_rx_priority_mask_add = (port) ?
2556 NIG_REG_P1_RX_COS2_PRIORITY_MASK :
2557 NIG_REG_P0_RX_COS2_PRIORITY_MASK;
2558 break;
2559 case 3:
2560 if (port)
2561 return -EINVAL;
2562 nig_reg_rx_priority_mask_add = NIG_REG_P0_RX_COS3_PRIORITY_MASK;
2563 break;
2564 case 4:
2565 if (port)
2566 return -EINVAL;
2567 nig_reg_rx_priority_mask_add = NIG_REG_P0_RX_COS4_PRIORITY_MASK;
2568 break;
2569 case 5:
2570 if (port)
2571 return -EINVAL;
2572 nig_reg_rx_priority_mask_add = NIG_REG_P0_RX_COS5_PRIORITY_MASK;
2573 break;
2574 }
2575
2576 REG_WR(bp, nig_reg_rx_priority_mask_add, priority_mask);
2577
2578 return 0;
2579}
Yaniv Rosnerb8d6d082011-07-05 01:06:27 +00002580static void bnx2x_update_mng(struct link_params *params, u32 link_status)
2581{
2582 struct bnx2x *bp = params->bp;
2583
2584 REG_WR(bp, params->shmem_base +
2585 offsetof(struct shmem_region,
2586 port_mb[params->port].link_status), link_status);
2587}
2588
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002589static void bnx2x_update_pfc_nig(struct link_params *params,
2590 struct link_vars *vars,
2591 struct bnx2x_nig_brb_pfc_port_params *nig_params)
2592{
2593 u32 xcm_mask = 0, ppp_enable = 0, pause_enable = 0, llfc_out_en = 0;
Yaniv Rosner127302b2012-01-17 02:33:26 +00002594 u32 llfc_enable = 0, xcm_out_en = 0, hwpfc_enable = 0;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002595 u32 pkt_priority_to_cos = 0;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002596 struct bnx2x *bp = params->bp;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002597 u8 port = params->port;
2598
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002599 int set_pfc = params->feature_config_flags &
2600 FEATURE_CONFIG_PFC_ENABLED;
2601 DP(NETIF_MSG_LINK, "updating pfc nig parameters\n");
2602
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002603 /* When NIG_LLH0_XCM_MASK_REG_LLHX_XCM_MASK_BCN bit is set
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002604 * MAC control frames (that are not pause packets)
2605 * will be forwarded to the XCM.
2606 */
Yaniv Rosner127302b2012-01-17 02:33:26 +00002607 xcm_mask = REG_RD(bp, port ? NIG_REG_LLH1_XCM_MASK :
2608 NIG_REG_LLH0_XCM_MASK);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002609 /* NIG params will override non PFC params, since it's possible to
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002610 * do transition from PFC to SAFC
2611 */
2612 if (set_pfc) {
2613 pause_enable = 0;
2614 llfc_out_en = 0;
2615 llfc_enable = 0;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002616 if (CHIP_IS_E3(bp))
2617 ppp_enable = 0;
2618 else
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002619 ppp_enable = 1;
2620 xcm_mask &= ~(port ? NIG_LLH1_XCM_MASK_REG_LLH1_XCM_MASK_BCN :
2621 NIG_LLH0_XCM_MASK_REG_LLH0_XCM_MASK_BCN);
Yaniv Rosner127302b2012-01-17 02:33:26 +00002622 xcm_out_en = 0;
2623 hwpfc_enable = 1;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002624 } else {
2625 if (nig_params) {
2626 llfc_out_en = nig_params->llfc_out_en;
2627 llfc_enable = nig_params->llfc_enable;
2628 pause_enable = nig_params->pause_enable;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002629 } else /* Default non PFC mode - PAUSE */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002630 pause_enable = 1;
2631
2632 xcm_mask |= (port ? NIG_LLH1_XCM_MASK_REG_LLH1_XCM_MASK_BCN :
2633 NIG_LLH0_XCM_MASK_REG_LLH0_XCM_MASK_BCN);
Yaniv Rosner127302b2012-01-17 02:33:26 +00002634 xcm_out_en = 1;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002635 }
2636
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002637 if (CHIP_IS_E3(bp))
2638 REG_WR(bp, port ? NIG_REG_BRB1_PAUSE_IN_EN :
2639 NIG_REG_BRB0_PAUSE_IN_EN, pause_enable);
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002640 REG_WR(bp, port ? NIG_REG_LLFC_OUT_EN_1 :
2641 NIG_REG_LLFC_OUT_EN_0, llfc_out_en);
2642 REG_WR(bp, port ? NIG_REG_LLFC_ENABLE_1 :
2643 NIG_REG_LLFC_ENABLE_0, llfc_enable);
2644 REG_WR(bp, port ? NIG_REG_PAUSE_ENABLE_1 :
2645 NIG_REG_PAUSE_ENABLE_0, pause_enable);
2646
2647 REG_WR(bp, port ? NIG_REG_PPP_ENABLE_1 :
2648 NIG_REG_PPP_ENABLE_0, ppp_enable);
2649
2650 REG_WR(bp, port ? NIG_REG_LLH1_XCM_MASK :
2651 NIG_REG_LLH0_XCM_MASK, xcm_mask);
2652
Yaniv Rosner127302b2012-01-17 02:33:26 +00002653 REG_WR(bp, port ? NIG_REG_LLFC_EGRESS_SRC_ENABLE_1 :
2654 NIG_REG_LLFC_EGRESS_SRC_ENABLE_0, 0x7);
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002655
Yuval Mintzd2310232012-06-20 19:05:19 +00002656 /* Output enable for RX_XCM # IF */
Yaniv Rosner127302b2012-01-17 02:33:26 +00002657 REG_WR(bp, port ? NIG_REG_XCM1_OUT_EN :
2658 NIG_REG_XCM0_OUT_EN, xcm_out_en);
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002659
2660 /* HW PFC TX enable */
Yaniv Rosner127302b2012-01-17 02:33:26 +00002661 REG_WR(bp, port ? NIG_REG_P1_HWPFC_ENABLE :
2662 NIG_REG_P0_HWPFC_ENABLE, hwpfc_enable);
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002663
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002664 if (nig_params) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002665 u8 i = 0;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002666 pkt_priority_to_cos = nig_params->pkt_priority_to_cos;
2667
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002668 for (i = 0; i < nig_params->num_of_rx_cos_priority_mask; i++)
2669 bnx2x_pfc_nig_rx_priority_mask(bp, i,
2670 nig_params->rx_cos_priority_mask[i], port);
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002671
2672 REG_WR(bp, port ? NIG_REG_LLFC_HIGH_PRIORITY_CLASSES_1 :
2673 NIG_REG_LLFC_HIGH_PRIORITY_CLASSES_0,
2674 nig_params->llfc_high_priority_classes);
2675
2676 REG_WR(bp, port ? NIG_REG_LLFC_LOW_PRIORITY_CLASSES_1 :
2677 NIG_REG_LLFC_LOW_PRIORITY_CLASSES_0,
2678 nig_params->llfc_low_priority_classes);
2679 }
2680 REG_WR(bp, port ? NIG_REG_P1_PKT_PRIORITY_TO_COS :
2681 NIG_REG_P0_PKT_PRIORITY_TO_COS,
2682 pkt_priority_to_cos);
2683}
2684
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002685int bnx2x_update_pfc(struct link_params *params,
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002686 struct link_vars *vars,
2687 struct bnx2x_nig_brb_pfc_port_params *pfc_params)
2688{
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002689 /* The PFC and pause are orthogonal to one another, meaning when
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002690 * PFC is enabled, the pause are disabled, and when PFC is
2691 * disabled, pause are set according to the pause result.
2692 */
2693 u32 val;
2694 struct bnx2x *bp = params->bp;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002695 int bnx2x_status = 0;
2696 u8 bmac_loopback = (params->loopback_mode == LOOPBACK_BMAC);
Yaniv Rosnerb8d6d082011-07-05 01:06:27 +00002697
2698 if (params->feature_config_flags & FEATURE_CONFIG_PFC_ENABLED)
2699 vars->link_status |= LINK_STATUS_PFC_ENABLED;
2700 else
2701 vars->link_status &= ~LINK_STATUS_PFC_ENABLED;
2702
2703 bnx2x_update_mng(params, vars->link_status);
2704
Yuval Mintzd2310232012-06-20 19:05:19 +00002705 /* Update NIG params */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002706 bnx2x_update_pfc_nig(params, vars, pfc_params);
2707
Yuval Mintzd2310232012-06-20 19:05:19 +00002708 /* Update BRB params */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002709 bnx2x_status = bnx2x_update_pfc_brb(params, vars, pfc_params);
Yaniv Rosnerde0396f2011-11-28 00:49:53 +00002710 if (bnx2x_status)
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002711 return bnx2x_status;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002712
2713 if (!vars->link_up)
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002714 return bnx2x_status;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002715
2716 DP(NETIF_MSG_LINK, "About to update PFC in BMAC\n");
Yaniv Rosner375944c2012-09-11 04:34:10 +00002717
2718 if (CHIP_IS_E3(bp)) {
2719 if (vars->mac_type == MAC_TYPE_XMAC)
2720 bnx2x_update_pfc_xmac(params, vars, 0);
2721 } else {
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002722 val = REG_RD(bp, MISC_REG_RESET_REG_2);
2723 if ((val &
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00002724 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << params->port))
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002725 == 0) {
2726 DP(NETIF_MSG_LINK, "About to update PFC in EMAC\n");
2727 bnx2x_emac_enable(params, vars, 0);
2728 return bnx2x_status;
2729 }
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002730 if (CHIP_IS_E2(bp))
2731 bnx2x_update_pfc_bmac2(params, vars, bmac_loopback);
2732 else
2733 bnx2x_update_pfc_bmac1(params, vars);
2734
2735 val = 0;
2736 if ((params->feature_config_flags &
2737 FEATURE_CONFIG_PFC_ENABLED) ||
2738 (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX))
2739 val = 1;
2740 REG_WR(bp, NIG_REG_BMAC0_PAUSE_OUT_EN + params->port*4, val);
2741 }
2742 return bnx2x_status;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002743}
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002744
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002745
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00002746static int bnx2x_bmac1_enable(struct link_params *params,
2747 struct link_vars *vars,
2748 u8 is_lb)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002749{
2750 struct bnx2x *bp = params->bp;
2751 u8 port = params->port;
2752 u32 bmac_addr = port ? NIG_REG_INGRESS_BMAC1_MEM :
2753 NIG_REG_INGRESS_BMAC0_MEM;
2754 u32 wb_data[2];
2755 u32 val;
2756
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002757 DP(NETIF_MSG_LINK, "Enabling BigMAC1\n");
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002758
2759 /* XGXS control */
2760 wb_data[0] = 0x3c;
2761 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002762 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_BMAC_XGXS_CONTROL,
2763 wb_data, 2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002764
Yuval Mintzd2310232012-06-20 19:05:19 +00002765 /* TX MAC SA */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002766 wb_data[0] = ((params->mac_addr[2] << 24) |
2767 (params->mac_addr[3] << 16) |
2768 (params->mac_addr[4] << 8) |
2769 params->mac_addr[5]);
2770 wb_data[1] = ((params->mac_addr[0] << 8) |
2771 params->mac_addr[1]);
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002772 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_TX_SOURCE_ADDR, wb_data, 2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002773
Yuval Mintzd2310232012-06-20 19:05:19 +00002774 /* MAC control */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002775 val = 0x3;
2776 if (is_lb) {
2777 val |= 0x4;
2778 DP(NETIF_MSG_LINK, "enable bmac loopback\n");
2779 }
2780 wb_data[0] = val;
2781 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002782 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_BMAC_CONTROL, wb_data, 2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002783
Yuval Mintzd2310232012-06-20 19:05:19 +00002784 /* Set rx mtu */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002785 wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD;
2786 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002787 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_RX_MAX_SIZE, wb_data, 2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002788
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002789 bnx2x_update_pfc_bmac1(params, vars);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002790
Yuval Mintzd2310232012-06-20 19:05:19 +00002791 /* Set tx mtu */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002792 wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD;
2793 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002794 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_TX_MAX_SIZE, wb_data, 2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002795
Yuval Mintzd2310232012-06-20 19:05:19 +00002796 /* Set cnt max size */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002797 wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD;
2798 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002799 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_CNT_MAX_SIZE, wb_data, 2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002800
Yuval Mintzd2310232012-06-20 19:05:19 +00002801 /* Configure SAFC */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002802 wb_data[0] = 0x1000200;
2803 wb_data[1] = 0;
2804 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_RX_LLFC_MSG_FLDS,
2805 wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002806
2807 return 0;
2808}
2809
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00002810static int bnx2x_bmac2_enable(struct link_params *params,
2811 struct link_vars *vars,
2812 u8 is_lb)
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002813{
2814 struct bnx2x *bp = params->bp;
2815 u8 port = params->port;
2816 u32 bmac_addr = port ? NIG_REG_INGRESS_BMAC1_MEM :
2817 NIG_REG_INGRESS_BMAC0_MEM;
2818 u32 wb_data[2];
2819
2820 DP(NETIF_MSG_LINK, "Enabling BigMAC2\n");
2821
2822 wb_data[0] = 0;
2823 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002824 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_BMAC_CONTROL, wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002825 udelay(30);
2826
2827 /* XGXS control: Reset phy HW, MDIO registers, PHY PLL and BMAC */
2828 wb_data[0] = 0x3c;
2829 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002830 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_BMAC_XGXS_CONTROL,
2831 wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002832
2833 udelay(30);
2834
Yuval Mintzd2310232012-06-20 19:05:19 +00002835 /* TX MAC SA */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002836 wb_data[0] = ((params->mac_addr[2] << 24) |
2837 (params->mac_addr[3] << 16) |
2838 (params->mac_addr[4] << 8) |
2839 params->mac_addr[5]);
2840 wb_data[1] = ((params->mac_addr[0] << 8) |
2841 params->mac_addr[1]);
2842 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_TX_SOURCE_ADDR,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002843 wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002844
2845 udelay(30);
2846
2847 /* Configure SAFC */
2848 wb_data[0] = 0x1000200;
2849 wb_data[1] = 0;
2850 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_RX_LLFC_MSG_FLDS,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002851 wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002852 udelay(30);
2853
Yuval Mintzd2310232012-06-20 19:05:19 +00002854 /* Set RX MTU */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002855 wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD;
2856 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002857 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_RX_MAX_SIZE, wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002858 udelay(30);
2859
Yuval Mintzd2310232012-06-20 19:05:19 +00002860 /* Set TX MTU */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002861 wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD;
2862 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002863 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_TX_MAX_SIZE, wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002864 udelay(30);
Yuval Mintzd2310232012-06-20 19:05:19 +00002865 /* Set cnt max size */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002866 wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD - 2;
2867 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002868 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_CNT_MAX_SIZE, wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002869 udelay(30);
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002870 bnx2x_update_pfc_bmac2(params, vars, is_lb);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002871
2872 return 0;
2873}
2874
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00002875static int bnx2x_bmac_enable(struct link_params *params,
2876 struct link_vars *vars,
Yaniv Rosnerd3a8f132012-09-13 02:56:20 +00002877 u8 is_lb, u8 reset_bmac)
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002878{
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00002879 int rc = 0;
2880 u8 port = params->port;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002881 struct bnx2x *bp = params->bp;
2882 u32 val;
Yuval Mintzd2310232012-06-20 19:05:19 +00002883 /* Reset and unreset the BigMac */
Yaniv Rosnerd3a8f132012-09-13 02:56:20 +00002884 if (reset_bmac) {
2885 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
2886 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port));
2887 usleep_range(1000, 2000);
2888 }
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002889
2890 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002891 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port));
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002892
Yuval Mintzd2310232012-06-20 19:05:19 +00002893 /* Enable access for bmac registers */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002894 REG_WR(bp, NIG_REG_BMAC0_REGS_OUT_EN + port*4, 0x1);
2895
2896 /* Enable BMAC according to BMAC type*/
2897 if (CHIP_IS_E2(bp))
2898 rc = bnx2x_bmac2_enable(params, vars, is_lb);
2899 else
2900 rc = bnx2x_bmac1_enable(params, vars, is_lb);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002901 REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 0x1);
2902 REG_WR(bp, NIG_REG_XGXS_LANE_SEL_P0 + port*4, 0x0);
2903 REG_WR(bp, NIG_REG_EGRESS_EMAC0_PORT + port*4, 0x0);
2904 val = 0;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002905 if ((params->feature_config_flags &
2906 FEATURE_CONFIG_PFC_ENABLED) ||
2907 (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX))
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002908 val = 1;
2909 REG_WR(bp, NIG_REG_BMAC0_PAUSE_OUT_EN + port*4, val);
2910 REG_WR(bp, NIG_REG_EGRESS_EMAC0_OUT_EN + port*4, 0x0);
2911 REG_WR(bp, NIG_REG_EMAC0_IN_EN + port*4, 0x0);
2912 REG_WR(bp, NIG_REG_EMAC0_PAUSE_OUT_EN + port*4, 0x0);
2913 REG_WR(bp, NIG_REG_BMAC0_IN_EN + port*4, 0x1);
2914 REG_WR(bp, NIG_REG_BMAC0_OUT_EN + port*4, 0x1);
2915
2916 vars->mac_type = MAC_TYPE_BMAC;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002917 return rc;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002918}
2919
Yaniv Rosnerd3a8f132012-09-13 02:56:20 +00002920static void bnx2x_set_bmac_rx(struct bnx2x *bp, u32 chip_id, u8 port, u8 en)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002921{
2922 u32 bmac_addr = port ? NIG_REG_INGRESS_BMAC1_MEM :
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002923 NIG_REG_INGRESS_BMAC0_MEM;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002924 u32 wb_data[2];
Eilon Greenstein3196a882008-08-13 15:58:49 -07002925 u32 nig_bmac_enable = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port*4);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002926
Yaniv Rosnerd3a8f132012-09-13 02:56:20 +00002927 if (CHIP_IS_E2(bp))
2928 bmac_addr += BIGMAC2_REGISTER_BMAC_CONTROL;
2929 else
2930 bmac_addr += BIGMAC_REGISTER_BMAC_CONTROL;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002931 /* Only if the bmac is out of reset */
2932 if (REG_RD(bp, MISC_REG_RESET_REG_2) &
2933 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port) &&
2934 nig_bmac_enable) {
Yaniv Rosnerd3a8f132012-09-13 02:56:20 +00002935 /* Clear Rx Enable bit in BMAC_CONTROL register */
2936 REG_RD_DMAE(bp, bmac_addr, wb_data, 2);
2937 if (en)
2938 wb_data[0] |= BMAC_CONTROL_RX_ENABLE;
2939 else
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002940 wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
Yaniv Rosnerd3a8f132012-09-13 02:56:20 +00002941 REG_WR_DMAE(bp, bmac_addr, wb_data, 2);
Yuval Mintzd2310232012-06-20 19:05:19 +00002942 usleep_range(1000, 2000);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002943 }
2944}
2945
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00002946static int bnx2x_pbf_update(struct link_params *params, u32 flow_ctrl,
2947 u32 line_speed)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002948{
2949 struct bnx2x *bp = params->bp;
2950 u8 port = params->port;
2951 u32 init_crd, crd;
2952 u32 count = 1000;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002953
Yuval Mintzd2310232012-06-20 19:05:19 +00002954 /* Disable port */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002955 REG_WR(bp, PBF_REG_DISABLE_NEW_TASK_PROC_P0 + port*4, 0x1);
2956
Yuval Mintzd2310232012-06-20 19:05:19 +00002957 /* Wait for init credit */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002958 init_crd = REG_RD(bp, PBF_REG_P0_INIT_CRD + port*4);
2959 crd = REG_RD(bp, PBF_REG_P0_CREDIT + port*8);
2960 DP(NETIF_MSG_LINK, "init_crd 0x%x crd 0x%x\n", init_crd, crd);
2961
2962 while ((init_crd != crd) && count) {
Yuval Mintzd2310232012-06-20 19:05:19 +00002963 usleep_range(5000, 10000);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002964 crd = REG_RD(bp, PBF_REG_P0_CREDIT + port*8);
2965 count--;
2966 }
2967 crd = REG_RD(bp, PBF_REG_P0_CREDIT + port*8);
2968 if (init_crd != crd) {
2969 DP(NETIF_MSG_LINK, "BUG! init_crd 0x%x != crd 0x%x\n",
2970 init_crd, crd);
2971 return -EINVAL;
2972 }
2973
David S. Millerc0700f92008-12-16 23:53:20 -08002974 if (flow_ctrl & BNX2X_FLOW_CTRL_RX ||
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002975 line_speed == SPEED_10 ||
2976 line_speed == SPEED_100 ||
2977 line_speed == SPEED_1000 ||
2978 line_speed == SPEED_2500) {
2979 REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 1);
Yuval Mintzd2310232012-06-20 19:05:19 +00002980 /* Update threshold */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002981 REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, 0);
Yuval Mintzd2310232012-06-20 19:05:19 +00002982 /* Update init credit */
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002983 init_crd = 778; /* (800-18-4) */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002984
2985 } else {
2986 u32 thresh = (ETH_MAX_JUMBO_PACKET_SIZE +
2987 ETH_OVREHEAD)/16;
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002988 REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
Yuval Mintzd2310232012-06-20 19:05:19 +00002989 /* Update threshold */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002990 REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, thresh);
Yuval Mintzd2310232012-06-20 19:05:19 +00002991 /* Update init credit */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002992 switch (line_speed) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002993 case SPEED_10000:
2994 init_crd = thresh + 553 - 22;
2995 break;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002996 default:
2997 DP(NETIF_MSG_LINK, "Invalid line_speed 0x%x\n",
2998 line_speed);
2999 return -EINVAL;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003000 }
3001 }
3002 REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, init_crd);
3003 DP(NETIF_MSG_LINK, "PBF updated to speed %d credit %d\n",
3004 line_speed, init_crd);
3005
Yuval Mintzd2310232012-06-20 19:05:19 +00003006 /* Probe the credit changes */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003007 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0x1);
Yuval Mintzd2310232012-06-20 19:05:19 +00003008 usleep_range(5000, 10000);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003009 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0x0);
3010
Yuval Mintzd2310232012-06-20 19:05:19 +00003011 /* Enable port */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003012 REG_WR(bp, PBF_REG_DISABLE_NEW_TASK_PROC_P0 + port*4, 0x0);
3013 return 0;
3014}
3015
Dmitry Kravkove8920672011-05-04 23:52:40 +00003016/**
3017 * bnx2x_get_emac_base - retrive emac base address
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003018 *
Dmitry Kravkove8920672011-05-04 23:52:40 +00003019 * @bp: driver handle
3020 * @mdc_mdio_access: access type
3021 * @port: port id
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003022 *
3023 * This function selects the MDC/MDIO access (through emac0 or
3024 * emac1) depend on the mdc_mdio_access, port, port swapped. Each
3025 * phy has a default access mode, which could also be overridden
3026 * by nvram configuration. This parameter, whether this is the
3027 * default phy configuration, or the nvram overrun
3028 * configuration, is passed here as mdc_mdio_access and selects
3029 * the emac_base for the CL45 read/writes operations
3030 */
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00003031static u32 bnx2x_get_emac_base(struct bnx2x *bp,
3032 u32 mdc_mdio_access, u8 port)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003033{
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00003034 u32 emac_base = 0;
3035 switch (mdc_mdio_access) {
3036 case SHARED_HW_CFG_MDC_MDIO_ACCESS1_PHY_TYPE:
3037 break;
3038 case SHARED_HW_CFG_MDC_MDIO_ACCESS1_EMAC0:
3039 if (REG_RD(bp, NIG_REG_PORT_SWAP))
3040 emac_base = GRCBASE_EMAC1;
3041 else
3042 emac_base = GRCBASE_EMAC0;
3043 break;
3044 case SHARED_HW_CFG_MDC_MDIO_ACCESS1_EMAC1:
Eilon Greenstein589abe32009-02-12 08:36:55 +00003045 if (REG_RD(bp, NIG_REG_PORT_SWAP))
3046 emac_base = GRCBASE_EMAC0;
3047 else
3048 emac_base = GRCBASE_EMAC1;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003049 break;
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00003050 case SHARED_HW_CFG_MDC_MDIO_ACCESS1_BOTH:
3051 emac_base = (port) ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
3052 break;
3053 case SHARED_HW_CFG_MDC_MDIO_ACCESS1_SWAPPED:
Eilon Greenstein6378c022008-08-13 15:59:25 -07003054 emac_base = (port) ? GRCBASE_EMAC0 : GRCBASE_EMAC1;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003055 break;
3056 default:
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003057 break;
3058 }
3059 return emac_base;
3060
3061}
3062
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003063/******************************************************************/
Yaniv Rosner6583e332011-06-14 01:34:17 +00003064/* CL22 access functions */
3065/******************************************************************/
3066static int bnx2x_cl22_write(struct bnx2x *bp,
3067 struct bnx2x_phy *phy,
3068 u16 reg, u16 val)
3069{
3070 u32 tmp, mode;
3071 u8 i;
3072 int rc = 0;
3073 /* Switch to CL22 */
3074 mode = REG_RD(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE);
3075 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE,
3076 mode & ~EMAC_MDIO_MODE_CLAUSE_45);
3077
Yuval Mintzd2310232012-06-20 19:05:19 +00003078 /* Address */
Yaniv Rosner6583e332011-06-14 01:34:17 +00003079 tmp = ((phy->addr << 21) | (reg << 16) | val |
3080 EMAC_MDIO_COMM_COMMAND_WRITE_22 |
3081 EMAC_MDIO_COMM_START_BUSY);
3082 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, tmp);
3083
3084 for (i = 0; i < 50; i++) {
3085 udelay(10);
3086
3087 tmp = REG_RD(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM);
3088 if (!(tmp & EMAC_MDIO_COMM_START_BUSY)) {
3089 udelay(5);
3090 break;
3091 }
3092 }
3093 if (tmp & EMAC_MDIO_COMM_START_BUSY) {
3094 DP(NETIF_MSG_LINK, "write phy register failed\n");
3095 rc = -EFAULT;
3096 }
3097 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE, mode);
3098 return rc;
3099}
3100
3101static int bnx2x_cl22_read(struct bnx2x *bp,
3102 struct bnx2x_phy *phy,
3103 u16 reg, u16 *ret_val)
3104{
3105 u32 val, mode;
3106 u16 i;
3107 int rc = 0;
3108
3109 /* Switch to CL22 */
3110 mode = REG_RD(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE);
3111 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE,
3112 mode & ~EMAC_MDIO_MODE_CLAUSE_45);
3113
Yuval Mintzd2310232012-06-20 19:05:19 +00003114 /* Address */
Yaniv Rosner6583e332011-06-14 01:34:17 +00003115 val = ((phy->addr << 21) | (reg << 16) |
3116 EMAC_MDIO_COMM_COMMAND_READ_22 |
3117 EMAC_MDIO_COMM_START_BUSY);
3118 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, val);
3119
3120 for (i = 0; i < 50; i++) {
3121 udelay(10);
3122
3123 val = REG_RD(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM);
3124 if (!(val & EMAC_MDIO_COMM_START_BUSY)) {
3125 *ret_val = (u16)(val & EMAC_MDIO_COMM_DATA);
3126 udelay(5);
3127 break;
3128 }
3129 }
3130 if (val & EMAC_MDIO_COMM_START_BUSY) {
3131 DP(NETIF_MSG_LINK, "read phy register failed\n");
3132
3133 *ret_val = 0;
3134 rc = -EFAULT;
3135 }
3136 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE, mode);
3137 return rc;
3138}
3139
3140/******************************************************************/
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003141/* CL45 access functions */
3142/******************************************************************/
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00003143static int bnx2x_cl45_read(struct bnx2x *bp, struct bnx2x_phy *phy,
3144 u8 devad, u16 reg, u16 *ret_val)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003145{
Yaniv Rosnera198c142011-05-31 21:29:42 +00003146 u32 val;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003147 u16 i;
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00003148 int rc = 0;
Yaniv Rosner157fa282011-08-02 22:59:32 +00003149 if (phy->flags & FLAGS_MDC_MDIO_WA_B0)
3150 bnx2x_bits_en(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_STATUS,
3151 EMAC_MDIO_STATUS_10MB);
Yuval Mintzd2310232012-06-20 19:05:19 +00003152 /* Address */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003153 val = ((phy->addr << 21) | (devad << 16) | reg |
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003154 EMAC_MDIO_COMM_COMMAND_ADDRESS |
3155 EMAC_MDIO_COMM_START_BUSY);
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003156 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003157
3158 for (i = 0; i < 50; i++) {
3159 udelay(10);
3160
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003161 val = REG_RD(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003162 if (!(val & EMAC_MDIO_COMM_START_BUSY)) {
3163 udelay(5);
3164 break;
3165 }
3166 }
3167 if (val & EMAC_MDIO_COMM_START_BUSY) {
3168 DP(NETIF_MSG_LINK, "read phy register failed\n");
Yaniv Rosner6d870c32011-01-31 04:22:20 +00003169 netdev_err(bp->dev, "MDC/MDIO access timeout\n");
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003170 *ret_val = 0;
3171 rc = -EFAULT;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003172 } else {
Yuval Mintzd2310232012-06-20 19:05:19 +00003173 /* Data */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003174 val = ((phy->addr << 21) | (devad << 16) |
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003175 EMAC_MDIO_COMM_COMMAND_READ_45 |
3176 EMAC_MDIO_COMM_START_BUSY);
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003177 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003178
3179 for (i = 0; i < 50; i++) {
3180 udelay(10);
3181
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003182 val = REG_RD(bp, phy->mdio_ctrl +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003183 EMAC_REG_EMAC_MDIO_COMM);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003184 if (!(val & EMAC_MDIO_COMM_START_BUSY)) {
3185 *ret_val = (u16)(val & EMAC_MDIO_COMM_DATA);
3186 break;
3187 }
3188 }
3189 if (val & EMAC_MDIO_COMM_START_BUSY) {
3190 DP(NETIF_MSG_LINK, "read phy register failed\n");
Yaniv Rosner6d870c32011-01-31 04:22:20 +00003191 netdev_err(bp->dev, "MDC/MDIO access timeout\n");
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003192 *ret_val = 0;
3193 rc = -EFAULT;
3194 }
3195 }
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003196 /* Work around for E3 A0 */
3197 if (phy->flags & FLAGS_MDC_MDIO_WA) {
3198 phy->flags ^= FLAGS_DUMMY_READ;
3199 if (phy->flags & FLAGS_DUMMY_READ) {
3200 u16 temp_val;
3201 bnx2x_cl45_read(bp, phy, devad, 0xf, &temp_val);
3202 }
3203 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003204
Yaniv Rosner157fa282011-08-02 22:59:32 +00003205 if (phy->flags & FLAGS_MDC_MDIO_WA_B0)
3206 bnx2x_bits_dis(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_STATUS,
3207 EMAC_MDIO_STATUS_10MB);
Yaniv Rosnera198c142011-05-31 21:29:42 +00003208 return rc;
3209}
3210
3211static int bnx2x_cl45_write(struct bnx2x *bp, struct bnx2x_phy *phy,
3212 u8 devad, u16 reg, u16 val)
3213{
3214 u32 tmp;
3215 u8 i;
3216 int rc = 0;
Yaniv Rosner157fa282011-08-02 22:59:32 +00003217 if (phy->flags & FLAGS_MDC_MDIO_WA_B0)
3218 bnx2x_bits_en(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_STATUS,
3219 EMAC_MDIO_STATUS_10MB);
Yaniv Rosnera198c142011-05-31 21:29:42 +00003220
Yuval Mintzd2310232012-06-20 19:05:19 +00003221 /* Address */
Yaniv Rosnera198c142011-05-31 21:29:42 +00003222 tmp = ((phy->addr << 21) | (devad << 16) | reg |
3223 EMAC_MDIO_COMM_COMMAND_ADDRESS |
3224 EMAC_MDIO_COMM_START_BUSY);
3225 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, tmp);
3226
3227 for (i = 0; i < 50; i++) {
3228 udelay(10);
3229
3230 tmp = REG_RD(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM);
3231 if (!(tmp & EMAC_MDIO_COMM_START_BUSY)) {
3232 udelay(5);
3233 break;
3234 }
3235 }
3236 if (tmp & EMAC_MDIO_COMM_START_BUSY) {
3237 DP(NETIF_MSG_LINK, "write phy register failed\n");
3238 netdev_err(bp->dev, "MDC/MDIO access timeout\n");
3239 rc = -EFAULT;
Yaniv Rosnera198c142011-05-31 21:29:42 +00003240 } else {
Yuval Mintzd2310232012-06-20 19:05:19 +00003241 /* Data */
Yaniv Rosnera198c142011-05-31 21:29:42 +00003242 tmp = ((phy->addr << 21) | (devad << 16) | val |
3243 EMAC_MDIO_COMM_COMMAND_WRITE_45 |
3244 EMAC_MDIO_COMM_START_BUSY);
3245 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, tmp);
3246
3247 for (i = 0; i < 50; i++) {
3248 udelay(10);
3249
3250 tmp = REG_RD(bp, phy->mdio_ctrl +
3251 EMAC_REG_EMAC_MDIO_COMM);
3252 if (!(tmp & EMAC_MDIO_COMM_START_BUSY)) {
3253 udelay(5);
3254 break;
3255 }
3256 }
3257 if (tmp & EMAC_MDIO_COMM_START_BUSY) {
3258 DP(NETIF_MSG_LINK, "write phy register failed\n");
3259 netdev_err(bp->dev, "MDC/MDIO access timeout\n");
3260 rc = -EFAULT;
3261 }
3262 }
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003263 /* Work around for E3 A0 */
3264 if (phy->flags & FLAGS_MDC_MDIO_WA) {
3265 phy->flags ^= FLAGS_DUMMY_READ;
3266 if (phy->flags & FLAGS_DUMMY_READ) {
3267 u16 temp_val;
3268 bnx2x_cl45_read(bp, phy, devad, 0xf, &temp_val);
3269 }
3270 }
Yaniv Rosner157fa282011-08-02 22:59:32 +00003271 if (phy->flags & FLAGS_MDC_MDIO_WA_B0)
3272 bnx2x_bits_dis(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_STATUS,
3273 EMAC_MDIO_STATUS_10MB);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003274 return rc;
3275}
Yuval Mintzec4010e2012-09-10 05:51:06 +00003276
3277/******************************************************************/
3278/* EEE section */
3279/******************************************************************/
3280static u8 bnx2x_eee_has_cap(struct link_params *params)
3281{
3282 struct bnx2x *bp = params->bp;
3283
3284 if (REG_RD(bp, params->shmem2_base) <=
3285 offsetof(struct shmem2_region, eee_status[params->port]))
3286 return 0;
3287
3288 return 1;
3289}
3290
3291static int bnx2x_eee_nvram_to_time(u32 nvram_mode, u32 *idle_timer)
3292{
3293 switch (nvram_mode) {
3294 case PORT_FEAT_CFG_EEE_POWER_MODE_BALANCED:
3295 *idle_timer = EEE_MODE_NVRAM_BALANCED_TIME;
3296 break;
3297 case PORT_FEAT_CFG_EEE_POWER_MODE_AGGRESSIVE:
3298 *idle_timer = EEE_MODE_NVRAM_AGGRESSIVE_TIME;
3299 break;
3300 case PORT_FEAT_CFG_EEE_POWER_MODE_LOW_LATENCY:
3301 *idle_timer = EEE_MODE_NVRAM_LATENCY_TIME;
3302 break;
3303 default:
3304 *idle_timer = 0;
3305 break;
3306 }
3307
3308 return 0;
3309}
3310
3311static int bnx2x_eee_time_to_nvram(u32 idle_timer, u32 *nvram_mode)
3312{
3313 switch (idle_timer) {
3314 case EEE_MODE_NVRAM_BALANCED_TIME:
3315 *nvram_mode = PORT_FEAT_CFG_EEE_POWER_MODE_BALANCED;
3316 break;
3317 case EEE_MODE_NVRAM_AGGRESSIVE_TIME:
3318 *nvram_mode = PORT_FEAT_CFG_EEE_POWER_MODE_AGGRESSIVE;
3319 break;
3320 case EEE_MODE_NVRAM_LATENCY_TIME:
3321 *nvram_mode = PORT_FEAT_CFG_EEE_POWER_MODE_LOW_LATENCY;
3322 break;
3323 default:
3324 *nvram_mode = PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED;
3325 break;
3326 }
3327
3328 return 0;
3329}
3330
3331static u32 bnx2x_eee_calc_timer(struct link_params *params)
3332{
3333 u32 eee_mode, eee_idle;
3334 struct bnx2x *bp = params->bp;
3335
3336 if (params->eee_mode & EEE_MODE_OVERRIDE_NVRAM) {
3337 if (params->eee_mode & EEE_MODE_OUTPUT_TIME) {
3338 /* time value in eee_mode --> used directly*/
3339 eee_idle = params->eee_mode & EEE_MODE_TIMER_MASK;
3340 } else {
3341 /* hsi value in eee_mode --> time */
3342 if (bnx2x_eee_nvram_to_time(params->eee_mode &
3343 EEE_MODE_NVRAM_MASK,
3344 &eee_idle))
3345 return 0;
3346 }
3347 } else {
3348 /* hsi values in nvram --> time*/
3349 eee_mode = ((REG_RD(bp, params->shmem_base +
3350 offsetof(struct shmem_region, dev_info.
3351 port_feature_config[params->port].
3352 eee_power_mode)) &
3353 PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >>
3354 PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT);
3355
3356 if (bnx2x_eee_nvram_to_time(eee_mode, &eee_idle))
3357 return 0;
3358 }
3359
3360 return eee_idle;
3361}
3362
3363static int bnx2x_eee_set_timers(struct link_params *params,
3364 struct link_vars *vars)
3365{
3366 u32 eee_idle = 0, eee_mode;
3367 struct bnx2x *bp = params->bp;
3368
3369 eee_idle = bnx2x_eee_calc_timer(params);
3370
3371 if (eee_idle) {
3372 REG_WR(bp, MISC_REG_CPMU_LP_IDLE_THR_P0 + (params->port << 2),
3373 eee_idle);
3374 } else if ((params->eee_mode & EEE_MODE_ENABLE_LPI) &&
3375 (params->eee_mode & EEE_MODE_OVERRIDE_NVRAM) &&
3376 (params->eee_mode & EEE_MODE_OUTPUT_TIME)) {
3377 DP(NETIF_MSG_LINK, "Error: Tx LPI is enabled with timer 0\n");
3378 return -EINVAL;
3379 }
3380
3381 vars->eee_status &= ~(SHMEM_EEE_TIMER_MASK | SHMEM_EEE_TIME_OUTPUT_BIT);
3382 if (params->eee_mode & EEE_MODE_OUTPUT_TIME) {
3383 /* eee_idle in 1u --> eee_status in 16u */
3384 eee_idle >>= 4;
3385 vars->eee_status |= (eee_idle & SHMEM_EEE_TIMER_MASK) |
3386 SHMEM_EEE_TIME_OUTPUT_BIT;
3387 } else {
3388 if (bnx2x_eee_time_to_nvram(eee_idle, &eee_mode))
3389 return -EINVAL;
3390 vars->eee_status |= eee_mode;
3391 }
3392
3393 return 0;
3394}
3395
3396static int bnx2x_eee_initial_config(struct link_params *params,
3397 struct link_vars *vars, u8 mode)
3398{
3399 vars->eee_status |= ((u32) mode) << SHMEM_EEE_SUPPORTED_SHIFT;
3400
3401 /* Propogate params' bits --> vars (for migration exposure) */
3402 if (params->eee_mode & EEE_MODE_ENABLE_LPI)
3403 vars->eee_status |= SHMEM_EEE_LPI_REQUESTED_BIT;
3404 else
3405 vars->eee_status &= ~SHMEM_EEE_LPI_REQUESTED_BIT;
3406
3407 if (params->eee_mode & EEE_MODE_ADV_LPI)
3408 vars->eee_status |= SHMEM_EEE_REQUESTED_BIT;
3409 else
3410 vars->eee_status &= ~SHMEM_EEE_REQUESTED_BIT;
3411
3412 return bnx2x_eee_set_timers(params, vars);
3413}
3414
3415static int bnx2x_eee_disable(struct bnx2x_phy *phy,
3416 struct link_params *params,
3417 struct link_vars *vars)
3418{
3419 struct bnx2x *bp = params->bp;
3420
3421 /* Make Certain LPI is disabled */
3422 REG_WR(bp, MISC_REG_CPMU_LP_FW_ENABLE_P0 + (params->port << 2), 0);
3423
3424 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_EEE_ADV, 0x0);
3425
3426 vars->eee_status &= ~SHMEM_EEE_ADV_STATUS_MASK;
3427
3428 return 0;
3429}
3430
3431static int bnx2x_eee_advertise(struct bnx2x_phy *phy,
3432 struct link_params *params,
3433 struct link_vars *vars, u8 modes)
3434{
3435 struct bnx2x *bp = params->bp;
3436 u16 val = 0;
3437
3438 /* Mask events preventing LPI generation */
3439 REG_WR(bp, MISC_REG_CPMU_LP_MASK_EXT_P0 + (params->port << 2), 0xfc20);
3440
3441 if (modes & SHMEM_EEE_10G_ADV) {
3442 DP(NETIF_MSG_LINK, "Advertise 10GBase-T EEE\n");
3443 val |= 0x8;
3444 }
3445 if (modes & SHMEM_EEE_1G_ADV) {
3446 DP(NETIF_MSG_LINK, "Advertise 1GBase-T EEE\n");
3447 val |= 0x4;
3448 }
3449
3450 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_EEE_ADV, val);
3451
3452 vars->eee_status &= ~SHMEM_EEE_ADV_STATUS_MASK;
3453 vars->eee_status |= (modes << SHMEM_EEE_ADV_STATUS_SHIFT);
3454
3455 return 0;
3456}
3457
3458static void bnx2x_update_mng_eee(struct link_params *params, u32 eee_status)
3459{
3460 struct bnx2x *bp = params->bp;
3461
3462 if (bnx2x_eee_has_cap(params))
3463 REG_WR(bp, params->shmem2_base +
3464 offsetof(struct shmem2_region,
3465 eee_status[params->port]), eee_status);
3466}
3467
3468static void bnx2x_eee_an_resolve(struct bnx2x_phy *phy,
3469 struct link_params *params,
3470 struct link_vars *vars)
3471{
3472 struct bnx2x *bp = params->bp;
3473 u16 adv = 0, lp = 0;
3474 u32 lp_adv = 0;
3475 u8 neg = 0;
3476
3477 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_EEE_ADV, &adv);
3478 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_LP_EEE_ADV, &lp);
3479
3480 if (lp & 0x2) {
3481 lp_adv |= SHMEM_EEE_100M_ADV;
3482 if (adv & 0x2) {
3483 if (vars->line_speed == SPEED_100)
3484 neg = 1;
3485 DP(NETIF_MSG_LINK, "EEE negotiated - 100M\n");
3486 }
3487 }
3488 if (lp & 0x14) {
3489 lp_adv |= SHMEM_EEE_1G_ADV;
3490 if (adv & 0x14) {
3491 if (vars->line_speed == SPEED_1000)
3492 neg = 1;
3493 DP(NETIF_MSG_LINK, "EEE negotiated - 1G\n");
3494 }
3495 }
3496 if (lp & 0x68) {
3497 lp_adv |= SHMEM_EEE_10G_ADV;
3498 if (adv & 0x68) {
3499 if (vars->line_speed == SPEED_10000)
3500 neg = 1;
3501 DP(NETIF_MSG_LINK, "EEE negotiated - 10G\n");
3502 }
3503 }
3504
3505 vars->eee_status &= ~SHMEM_EEE_LP_ADV_STATUS_MASK;
3506 vars->eee_status |= (lp_adv << SHMEM_EEE_LP_ADV_STATUS_SHIFT);
3507
3508 if (neg) {
3509 DP(NETIF_MSG_LINK, "EEE is active\n");
3510 vars->eee_status |= SHMEM_EEE_ACTIVE_BIT;
3511 }
3512
3513}
3514
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003515/******************************************************************/
3516/* BSC access functions from E3 */
3517/******************************************************************/
3518static void bnx2x_bsc_module_sel(struct link_params *params)
3519{
3520 int idx;
3521 u32 board_cfg, sfp_ctrl;
3522 u32 i2c_pins[I2C_SWITCH_WIDTH], i2c_val[I2C_SWITCH_WIDTH];
3523 struct bnx2x *bp = params->bp;
3524 u8 port = params->port;
3525 /* Read I2C output PINs */
3526 board_cfg = REG_RD(bp, params->shmem_base +
3527 offsetof(struct shmem_region,
3528 dev_info.shared_hw_config.board));
3529 i2c_pins[I2C_BSC0] = board_cfg & SHARED_HW_CFG_E3_I2C_MUX0_MASK;
3530 i2c_pins[I2C_BSC1] = (board_cfg & SHARED_HW_CFG_E3_I2C_MUX1_MASK) >>
3531 SHARED_HW_CFG_E3_I2C_MUX1_SHIFT;
3532
3533 /* Read I2C output value */
3534 sfp_ctrl = REG_RD(bp, params->shmem_base +
3535 offsetof(struct shmem_region,
3536 dev_info.port_hw_config[port].e3_cmn_pin_cfg));
3537 i2c_val[I2C_BSC0] = (sfp_ctrl & PORT_HW_CFG_E3_I2C_MUX0_MASK) > 0;
3538 i2c_val[I2C_BSC1] = (sfp_ctrl & PORT_HW_CFG_E3_I2C_MUX1_MASK) > 0;
3539 DP(NETIF_MSG_LINK, "Setting BSC switch\n");
3540 for (idx = 0; idx < I2C_SWITCH_WIDTH; idx++)
3541 bnx2x_set_cfg_pin(bp, i2c_pins[idx], i2c_val[idx]);
3542}
3543
3544static int bnx2x_bsc_read(struct link_params *params,
3545 struct bnx2x_phy *phy,
3546 u8 sl_devid,
3547 u16 sl_addr,
3548 u8 lc_addr,
3549 u8 xfer_cnt,
3550 u32 *data_array)
3551{
3552 u32 val, i;
3553 int rc = 0;
3554 struct bnx2x *bp = params->bp;
3555
3556 if ((sl_devid != 0xa0) && (sl_devid != 0xa2)) {
3557 DP(NETIF_MSG_LINK, "invalid sl_devid 0x%x\n", sl_devid);
3558 return -EINVAL;
3559 }
3560
3561 if (xfer_cnt > 16) {
3562 DP(NETIF_MSG_LINK, "invalid xfer_cnt %d. Max is 16 bytes\n",
3563 xfer_cnt);
3564 return -EINVAL;
3565 }
3566 bnx2x_bsc_module_sel(params);
3567
3568 xfer_cnt = 16 - lc_addr;
3569
Yuval Mintzd2310232012-06-20 19:05:19 +00003570 /* Enable the engine */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003571 val = REG_RD(bp, MCP_REG_MCPR_IMC_COMMAND);
3572 val |= MCPR_IMC_COMMAND_ENABLE;
3573 REG_WR(bp, MCP_REG_MCPR_IMC_COMMAND, val);
3574
Yuval Mintzd2310232012-06-20 19:05:19 +00003575 /* Program slave device ID */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003576 val = (sl_devid << 16) | sl_addr;
3577 REG_WR(bp, MCP_REG_MCPR_IMC_SLAVE_CONTROL, val);
3578
Yuval Mintzd2310232012-06-20 19:05:19 +00003579 /* Start xfer with 0 byte to update the address pointer ???*/
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003580 val = (MCPR_IMC_COMMAND_ENABLE) |
3581 (MCPR_IMC_COMMAND_WRITE_OP <<
3582 MCPR_IMC_COMMAND_OPERATION_BITSHIFT) |
3583 (lc_addr << MCPR_IMC_COMMAND_TRANSFER_ADDRESS_BITSHIFT) | (0);
3584 REG_WR(bp, MCP_REG_MCPR_IMC_COMMAND, val);
3585
Yuval Mintzd2310232012-06-20 19:05:19 +00003586 /* Poll for completion */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003587 i = 0;
3588 val = REG_RD(bp, MCP_REG_MCPR_IMC_COMMAND);
3589 while (((val >> MCPR_IMC_COMMAND_IMC_STATUS_BITSHIFT) & 0x3) != 1) {
3590 udelay(10);
3591 val = REG_RD(bp, MCP_REG_MCPR_IMC_COMMAND);
3592 if (i++ > 1000) {
3593 DP(NETIF_MSG_LINK, "wr 0 byte timed out after %d try\n",
3594 i);
3595 rc = -EFAULT;
3596 break;
3597 }
3598 }
3599 if (rc == -EFAULT)
3600 return rc;
3601
Yuval Mintzd2310232012-06-20 19:05:19 +00003602 /* Start xfer with read op */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003603 val = (MCPR_IMC_COMMAND_ENABLE) |
3604 (MCPR_IMC_COMMAND_READ_OP <<
3605 MCPR_IMC_COMMAND_OPERATION_BITSHIFT) |
3606 (lc_addr << MCPR_IMC_COMMAND_TRANSFER_ADDRESS_BITSHIFT) |
3607 (xfer_cnt);
3608 REG_WR(bp, MCP_REG_MCPR_IMC_COMMAND, val);
3609
Yuval Mintzd2310232012-06-20 19:05:19 +00003610 /* Poll for completion */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003611 i = 0;
3612 val = REG_RD(bp, MCP_REG_MCPR_IMC_COMMAND);
3613 while (((val >> MCPR_IMC_COMMAND_IMC_STATUS_BITSHIFT) & 0x3) != 1) {
3614 udelay(10);
3615 val = REG_RD(bp, MCP_REG_MCPR_IMC_COMMAND);
3616 if (i++ > 1000) {
3617 DP(NETIF_MSG_LINK, "rd op timed out after %d try\n", i);
3618 rc = -EFAULT;
3619 break;
3620 }
3621 }
3622 if (rc == -EFAULT)
3623 return rc;
3624
3625 for (i = (lc_addr >> 2); i < 4; i++) {
3626 data_array[i] = REG_RD(bp, (MCP_REG_MCPR_IMC_DATAREG0 + i*4));
3627#ifdef __BIG_ENDIAN
3628 data_array[i] = ((data_array[i] & 0x000000ff) << 24) |
3629 ((data_array[i] & 0x0000ff00) << 8) |
3630 ((data_array[i] & 0x00ff0000) >> 8) |
3631 ((data_array[i] & 0xff000000) >> 24);
3632#endif
3633 }
3634 return rc;
3635}
3636
3637static void bnx2x_cl45_read_or_write(struct bnx2x *bp, struct bnx2x_phy *phy,
3638 u8 devad, u16 reg, u16 or_val)
3639{
3640 u16 val;
3641 bnx2x_cl45_read(bp, phy, devad, reg, &val);
3642 bnx2x_cl45_write(bp, phy, devad, reg, val | or_val);
3643}
3644
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00003645int bnx2x_phy_read(struct link_params *params, u8 phy_addr,
3646 u8 devad, u16 reg, u16 *ret_val)
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003647{
3648 u8 phy_index;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00003649 /* Probe for the phy according to the given phy_addr, and execute
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003650 * the read request on it
3651 */
3652 for (phy_index = 0; phy_index < params->num_phys; phy_index++) {
3653 if (params->phy[phy_index].addr == phy_addr) {
3654 return bnx2x_cl45_read(params->bp,
3655 &params->phy[phy_index], devad,
3656 reg, ret_val);
3657 }
3658 }
3659 return -EINVAL;
3660}
3661
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00003662int bnx2x_phy_write(struct link_params *params, u8 phy_addr,
3663 u8 devad, u16 reg, u16 val)
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003664{
3665 u8 phy_index;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00003666 /* Probe for the phy according to the given phy_addr, and execute
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003667 * the write request on it
3668 */
3669 for (phy_index = 0; phy_index < params->num_phys; phy_index++) {
3670 if (params->phy[phy_index].addr == phy_addr) {
3671 return bnx2x_cl45_write(params->bp,
3672 &params->phy[phy_index], devad,
3673 reg, val);
3674 }
3675 }
3676 return -EINVAL;
3677}
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003678static u8 bnx2x_get_warpcore_lane(struct bnx2x_phy *phy,
3679 struct link_params *params)
3680{
3681 u8 lane = 0;
3682 struct bnx2x *bp = params->bp;
3683 u32 path_swap, path_swap_ovr;
3684 u8 path, port;
3685
3686 path = BP_PATH(bp);
3687 port = params->port;
3688
3689 if (bnx2x_is_4_port_mode(bp)) {
3690 u32 port_swap, port_swap_ovr;
3691
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00003692 /* Figure out path swap value */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003693 path_swap_ovr = REG_RD(bp, MISC_REG_FOUR_PORT_PATH_SWAP_OVWR);
3694 if (path_swap_ovr & 0x1)
3695 path_swap = (path_swap_ovr & 0x2);
3696 else
3697 path_swap = REG_RD(bp, MISC_REG_FOUR_PORT_PATH_SWAP);
3698
3699 if (path_swap)
3700 path = path ^ 1;
3701
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00003702 /* Figure out port swap value */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003703 port_swap_ovr = REG_RD(bp, MISC_REG_FOUR_PORT_PORT_SWAP_OVWR);
3704 if (port_swap_ovr & 0x1)
3705 port_swap = (port_swap_ovr & 0x2);
3706 else
3707 port_swap = REG_RD(bp, MISC_REG_FOUR_PORT_PORT_SWAP);
3708
3709 if (port_swap)
3710 port = port ^ 1;
3711
3712 lane = (port<<1) + path;
Yuval Mintzd2310232012-06-20 19:05:19 +00003713 } else { /* Two port mode - no port swap */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003714
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00003715 /* Figure out path swap value */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003716 path_swap_ovr =
3717 REG_RD(bp, MISC_REG_TWO_PORT_PATH_SWAP_OVWR);
3718 if (path_swap_ovr & 0x1) {
3719 path_swap = (path_swap_ovr & 0x2);
3720 } else {
3721 path_swap =
3722 REG_RD(bp, MISC_REG_TWO_PORT_PATH_SWAP);
3723 }
3724 if (path_swap)
3725 path = path ^ 1;
3726
3727 lane = path << 1 ;
3728 }
3729 return lane;
3730}
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003731
Yaniv Rosnerec146a62011-05-31 21:29:27 +00003732static void bnx2x_set_aer_mmd(struct link_params *params,
3733 struct bnx2x_phy *phy)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003734{
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003735 u32 ser_lane;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00003736 u16 offset, aer_val;
3737 struct bnx2x *bp = params->bp;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003738 ser_lane = ((params->lane_config &
3739 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_MASK) >>
3740 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_SHIFT);
3741
Yaniv Rosnerec146a62011-05-31 21:29:27 +00003742 offset = (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT) ?
3743 (phy->addr + ser_lane) : 0;
3744
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003745 if (USES_WARPCORE(bp)) {
3746 aer_val = bnx2x_get_warpcore_lane(phy, params);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00003747 /* In Dual-lane mode, two lanes are joined together,
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003748 * so in order to configure them, the AER broadcast method is
3749 * used here.
3750 * 0x200 is the broadcast address for lanes 0,1
3751 * 0x201 is the broadcast address for lanes 2,3
3752 */
3753 if (phy->flags & FLAGS_WC_DUAL_MODE)
3754 aer_val = (aer_val >> 1) | 0x200;
3755 } else if (CHIP_IS_E2(bp))
Yaniv Rosner82a0d472011-01-18 04:33:52 +00003756 aer_val = 0x3800 + offset - 1;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00003757 else
3758 aer_val = 0x3800 + offset;
Yaniv Rosner2f751a82011-11-28 00:49:52 +00003759
Yaniv Rosnercd2be892011-01-31 04:21:45 +00003760 CL22_WR_OVER_CL45(bp, phy, MDIO_REG_BANK_AER_BLOCK,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003761 MDIO_AER_BLOCK_AER_REG, aer_val);
Yaniv Rosnerec146a62011-05-31 21:29:27 +00003762
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003763}
3764
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003765/******************************************************************/
3766/* Internal phy section */
3767/******************************************************************/
3768
3769static void bnx2x_set_serdes_access(struct bnx2x *bp, u8 port)
3770{
3771 u32 emac_base = (port) ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
3772
3773 /* Set Clause 22 */
3774 REG_WR(bp, NIG_REG_SERDES0_CTRL_MD_ST + port*0x10, 1);
3775 REG_WR(bp, emac_base + EMAC_REG_EMAC_MDIO_COMM, 0x245f8000);
3776 udelay(500);
3777 REG_WR(bp, emac_base + EMAC_REG_EMAC_MDIO_COMM, 0x245d000f);
3778 udelay(500);
3779 /* Set Clause 45 */
3780 REG_WR(bp, NIG_REG_SERDES0_CTRL_MD_ST + port*0x10, 0);
3781}
3782
3783static void bnx2x_serdes_deassert(struct bnx2x *bp, u8 port)
3784{
3785 u32 val;
3786
3787 DP(NETIF_MSG_LINK, "bnx2x_serdes_deassert\n");
3788
3789 val = SERDES_RESET_BITS << (port*16);
3790
Yuval Mintzd2310232012-06-20 19:05:19 +00003791 /* Reset and unreset the SerDes/XGXS */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003792 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_CLEAR, val);
3793 udelay(500);
3794 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_SET, val);
3795
3796 bnx2x_set_serdes_access(bp, port);
3797
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003798 REG_WR(bp, NIG_REG_SERDES0_CTRL_MD_DEVAD + port*0x10,
3799 DEFAULT_PHY_DEV_ADDR);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003800}
3801
3802static void bnx2x_xgxs_deassert(struct link_params *params)
3803{
3804 struct bnx2x *bp = params->bp;
3805 u8 port;
3806 u32 val;
3807 DP(NETIF_MSG_LINK, "bnx2x_xgxs_deassert\n");
3808 port = params->port;
3809
3810 val = XGXS_RESET_BITS << (port*16);
3811
Yuval Mintzd2310232012-06-20 19:05:19 +00003812 /* Reset and unreset the SerDes/XGXS */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003813 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_CLEAR, val);
3814 udelay(500);
3815 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_SET, val);
3816
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003817 REG_WR(bp, NIG_REG_XGXS0_CTRL_MD_ST + port*0x18, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003818 REG_WR(bp, NIG_REG_XGXS0_CTRL_MD_DEVAD + port*0x18,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003819 params->phy[INT_PHY].def_md_devad);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003820}
3821
Yaniv Rosner9045f6b42011-05-31 21:28:27 +00003822static void bnx2x_calc_ieee_aneg_adv(struct bnx2x_phy *phy,
3823 struct link_params *params, u16 *ieee_fc)
3824{
3825 struct bnx2x *bp = params->bp;
3826 *ieee_fc = MDIO_COMBO_IEEE0_AUTO_NEG_ADV_FULL_DUPLEX;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00003827 /* Resolve pause mode and advertisement Please refer to Table
Yaniv Rosner9045f6b42011-05-31 21:28:27 +00003828 * 28B-3 of the 802.3ab-1999 spec
3829 */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003830
Yaniv Rosner9045f6b42011-05-31 21:28:27 +00003831 switch (phy->req_flow_ctrl) {
3832 case BNX2X_FLOW_CTRL_AUTO:
3833 if (params->req_fc_auto_adv == BNX2X_FLOW_CTRL_BOTH)
3834 *ieee_fc |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH;
3835 else
3836 *ieee_fc |=
3837 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC;
3838 break;
3839
3840 case BNX2X_FLOW_CTRL_TX:
3841 *ieee_fc |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC;
3842 break;
3843
3844 case BNX2X_FLOW_CTRL_RX:
3845 case BNX2X_FLOW_CTRL_BOTH:
3846 *ieee_fc |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH;
3847 break;
3848
3849 case BNX2X_FLOW_CTRL_NONE:
3850 default:
3851 *ieee_fc |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE;
3852 break;
3853 }
3854 DP(NETIF_MSG_LINK, "ieee_fc = 0x%x\n", *ieee_fc);
3855}
3856
3857static void set_phy_vars(struct link_params *params,
3858 struct link_vars *vars)
3859{
3860 struct bnx2x *bp = params->bp;
3861 u8 actual_phy_idx, phy_index, link_cfg_idx;
3862 u8 phy_config_swapped = params->multi_phy_config &
3863 PORT_HW_CFG_PHY_SWAPPED_ENABLED;
3864 for (phy_index = INT_PHY; phy_index < params->num_phys;
3865 phy_index++) {
3866 link_cfg_idx = LINK_CONFIG_IDX(phy_index);
3867 actual_phy_idx = phy_index;
3868 if (phy_config_swapped) {
3869 if (phy_index == EXT_PHY1)
3870 actual_phy_idx = EXT_PHY2;
3871 else if (phy_index == EXT_PHY2)
3872 actual_phy_idx = EXT_PHY1;
3873 }
3874 params->phy[actual_phy_idx].req_flow_ctrl =
3875 params->req_flow_ctrl[link_cfg_idx];
3876
3877 params->phy[actual_phy_idx].req_line_speed =
3878 params->req_line_speed[link_cfg_idx];
3879
3880 params->phy[actual_phy_idx].speed_cap_mask =
3881 params->speed_cap_mask[link_cfg_idx];
3882
3883 params->phy[actual_phy_idx].req_duplex =
3884 params->req_duplex[link_cfg_idx];
3885
3886 if (params->req_line_speed[link_cfg_idx] ==
3887 SPEED_AUTO_NEG)
3888 vars->link_status |= LINK_STATUS_AUTO_NEGOTIATE_ENABLED;
3889
3890 DP(NETIF_MSG_LINK, "req_flow_ctrl %x, req_line_speed %x,"
3891 " speed_cap_mask %x\n",
3892 params->phy[actual_phy_idx].req_flow_ctrl,
3893 params->phy[actual_phy_idx].req_line_speed,
3894 params->phy[actual_phy_idx].speed_cap_mask);
3895 }
3896}
3897
3898static void bnx2x_ext_phy_set_pause(struct link_params *params,
3899 struct bnx2x_phy *phy,
3900 struct link_vars *vars)
3901{
3902 u16 val;
3903 struct bnx2x *bp = params->bp;
Yuval Mintzd2310232012-06-20 19:05:19 +00003904 /* Read modify write pause advertizing */
Yaniv Rosner9045f6b42011-05-31 21:28:27 +00003905 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV_PAUSE, &val);
3906
3907 val &= ~MDIO_AN_REG_ADV_PAUSE_BOTH;
3908
3909 /* Please refer to Table 28B-3 of 802.3ab-1999 spec. */
3910 bnx2x_calc_ieee_aneg_adv(phy, params, &vars->ieee_fc);
3911 if ((vars->ieee_fc &
3912 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC) ==
3913 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC) {
3914 val |= MDIO_AN_REG_ADV_PAUSE_ASYMMETRIC;
3915 }
3916 if ((vars->ieee_fc &
3917 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) ==
3918 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) {
3919 val |= MDIO_AN_REG_ADV_PAUSE_PAUSE;
3920 }
3921 DP(NETIF_MSG_LINK, "Ext phy AN advertize 0x%x\n", val);
3922 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV_PAUSE, val);
3923}
3924
3925static void bnx2x_pause_resolve(struct link_vars *vars, u32 pause_result)
3926{ /* LD LP */
3927 switch (pause_result) { /* ASYM P ASYM P */
3928 case 0xb: /* 1 0 1 1 */
3929 vars->flow_ctrl = BNX2X_FLOW_CTRL_TX;
3930 break;
3931
3932 case 0xe: /* 1 1 1 0 */
3933 vars->flow_ctrl = BNX2X_FLOW_CTRL_RX;
3934 break;
3935
3936 case 0x5: /* 0 1 0 1 */
3937 case 0x7: /* 0 1 1 1 */
3938 case 0xd: /* 1 1 0 1 */
3939 case 0xf: /* 1 1 1 1 */
3940 vars->flow_ctrl = BNX2X_FLOW_CTRL_BOTH;
3941 break;
3942
3943 default:
3944 break;
3945 }
3946 if (pause_result & (1<<0))
3947 vars->link_status |= LINK_STATUS_LINK_PARTNER_SYMMETRIC_PAUSE;
3948 if (pause_result & (1<<1))
3949 vars->link_status |= LINK_STATUS_LINK_PARTNER_ASYMMETRIC_PAUSE;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00003950
Yaniv Rosner9045f6b42011-05-31 21:28:27 +00003951}
3952
Mintz Yuval9e7e8392012-02-15 02:10:24 +00003953static void bnx2x_ext_phy_update_adv_fc(struct bnx2x_phy *phy,
3954 struct link_params *params,
3955 struct link_vars *vars)
3956{
3957 u16 ld_pause; /* local */
3958 u16 lp_pause; /* link partner */
3959 u16 pause_result;
3960 struct bnx2x *bp = params->bp;
3961 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54618SE) {
3962 bnx2x_cl22_read(bp, phy, 0x4, &ld_pause);
3963 bnx2x_cl22_read(bp, phy, 0x5, &lp_pause);
Yaniv Rosnerca05f292012-04-04 01:28:55 +00003964 } else if (CHIP_IS_E3(bp) &&
3965 SINGLE_MEDIA_DIRECT(params)) {
3966 u8 lane = bnx2x_get_warpcore_lane(phy, params);
3967 u16 gp_status, gp_mask;
3968 bnx2x_cl45_read(bp, phy,
3969 MDIO_AN_DEVAD, MDIO_WC_REG_GP2_STATUS_GP_2_4,
3970 &gp_status);
3971 gp_mask = (MDIO_WC_REG_GP2_STATUS_GP_2_4_CL73_AN_CMPL |
3972 MDIO_WC_REG_GP2_STATUS_GP_2_4_CL37_LP_AN_CAP) <<
3973 lane;
3974 if ((gp_status & gp_mask) == gp_mask) {
3975 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
3976 MDIO_AN_REG_ADV_PAUSE, &ld_pause);
3977 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
3978 MDIO_AN_REG_LP_AUTO_NEG, &lp_pause);
3979 } else {
3980 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
3981 MDIO_AN_REG_CL37_FC_LD, &ld_pause);
3982 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
3983 MDIO_AN_REG_CL37_FC_LP, &lp_pause);
3984 ld_pause = ((ld_pause &
3985 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH)
3986 << 3);
3987 lp_pause = ((lp_pause &
3988 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH)
3989 << 3);
3990 }
Mintz Yuval9e7e8392012-02-15 02:10:24 +00003991 } else {
3992 bnx2x_cl45_read(bp, phy,
3993 MDIO_AN_DEVAD,
3994 MDIO_AN_REG_ADV_PAUSE, &ld_pause);
3995 bnx2x_cl45_read(bp, phy,
3996 MDIO_AN_DEVAD,
3997 MDIO_AN_REG_LP_AUTO_NEG, &lp_pause);
3998 }
3999 pause_result = (ld_pause &
4000 MDIO_AN_REG_ADV_PAUSE_MASK) >> 8;
4001 pause_result |= (lp_pause &
4002 MDIO_AN_REG_ADV_PAUSE_MASK) >> 10;
4003 DP(NETIF_MSG_LINK, "Ext PHY pause result 0x%x\n", pause_result);
4004 bnx2x_pause_resolve(vars, pause_result);
4005
4006}
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00004007
Yaniv Rosner9045f6b42011-05-31 21:28:27 +00004008static u8 bnx2x_ext_phy_resolve_fc(struct bnx2x_phy *phy,
4009 struct link_params *params,
4010 struct link_vars *vars)
4011{
Yaniv Rosner9045f6b42011-05-31 21:28:27 +00004012 u8 ret = 0;
Yaniv Rosner9045f6b42011-05-31 21:28:27 +00004013 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
Mintz Yuval9e7e8392012-02-15 02:10:24 +00004014 if (phy->req_flow_ctrl != BNX2X_FLOW_CTRL_AUTO) {
4015 /* Update the advertised flow-controled of LD/LP in AN */
4016 if (phy->req_line_speed == SPEED_AUTO_NEG)
4017 bnx2x_ext_phy_update_adv_fc(phy, params, vars);
4018 /* But set the flow-control result as the requested one */
Yaniv Rosner9045f6b42011-05-31 21:28:27 +00004019 vars->flow_ctrl = phy->req_flow_ctrl;
Mintz Yuval9e7e8392012-02-15 02:10:24 +00004020 } else if (phy->req_line_speed != SPEED_AUTO_NEG)
Yaniv Rosner9045f6b42011-05-31 21:28:27 +00004021 vars->flow_ctrl = params->req_fc_auto_adv;
4022 else if (vars->link_status & LINK_STATUS_AUTO_NEGOTIATE_COMPLETE) {
4023 ret = 1;
Mintz Yuval9e7e8392012-02-15 02:10:24 +00004024 bnx2x_ext_phy_update_adv_fc(phy, params, vars);
Yaniv Rosner9045f6b42011-05-31 21:28:27 +00004025 }
4026 return ret;
4027}
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004028/******************************************************************/
4029/* Warpcore section */
4030/******************************************************************/
4031/* The init_internal_warpcore should mirror the xgxs,
4032 * i.e. reset the lane (if needed), set aer for the
4033 * init configuration, and set/clear SGMII flag. Internal
4034 * phy init is done purely in phy_init stage.
4035 */
Yuval Mintzec4010e2012-09-10 05:51:06 +00004036
4037static void bnx2x_warpcore_set_lpi_passthrough(struct bnx2x_phy *phy,
4038 struct link_params *params)
4039{
4040 struct bnx2x *bp = params->bp;
4041
4042 DP(NETIF_MSG_LINK, "Configure WC for LPI pass through\n");
4043 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4044 MDIO_WC_REG_EEE_COMBO_CONTROL0, 0x7c);
4045 bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
4046 MDIO_WC_REG_DIGITAL4_MISC5, 0xc000);
4047}
4048
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004049static void bnx2x_warpcore_enable_AN_KR(struct bnx2x_phy *phy,
4050 struct link_params *params,
4051 struct link_vars *vars) {
Yuval Mintza351d492012-06-20 19:05:21 +00004052 u16 val16 = 0, lane, i;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004053 struct bnx2x *bp = params->bp;
Yuval Mintza351d492012-06-20 19:05:21 +00004054 static struct bnx2x_reg_set reg_set[] = {
4055 {MDIO_WC_DEVAD, MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2, 0x7},
4056 {MDIO_AN_DEVAD, MDIO_WC_REG_PAR_DET_10G_CTRL, 0},
4057 {MDIO_WC_DEVAD, MDIO_WC_REG_CL72_USERB0_CL72_MISC1_CONTROL, 0},
4058 {MDIO_WC_DEVAD, MDIO_WC_REG_XGXSBLK1_LANECTRL0, 0xff},
4059 {MDIO_WC_DEVAD, MDIO_WC_REG_XGXSBLK1_LANECTRL1, 0x5555},
4060 {MDIO_PMA_DEVAD, MDIO_WC_REG_IEEE0BLK_AUTONEGNP, 0x0},
4061 {MDIO_WC_DEVAD, MDIO_WC_REG_RX66_CONTROL, 0x7415},
4062 {MDIO_WC_DEVAD, MDIO_WC_REG_SERDESDIGITAL_MISC2, 0x6190},
4063 /* Disable Autoneg: re-enable it after adv is done. */
4064 {MDIO_AN_DEVAD, MDIO_WC_REG_IEEE0BLK_MIICNTL, 0}
4065 };
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004066 DP(NETIF_MSG_LINK, "Enable Auto Negotiation for KR\n");
Yaniv Rosner6a51c0d2012-04-04 01:28:56 +00004067 /* Set to default registers that may be overriden by 10G force */
Yuval Mintza351d492012-06-20 19:05:21 +00004068 for (i = 0; i < sizeof(reg_set)/sizeof(struct bnx2x_reg_set); i++)
4069 bnx2x_cl45_write(bp, phy, reg_set[i].devad, reg_set[i].reg,
4070 reg_set[i].val);
Yaniv Rosnera9077bf2011-10-27 05:09:46 +00004071
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004072 /* Check adding advertisement for 1G KX */
4073 if (((vars->line_speed == SPEED_AUTO_NEG) &&
4074 (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) ||
4075 (vars->line_speed == SPEED_1000)) {
Yuval Mintza351d492012-06-20 19:05:21 +00004076 u32 addr = MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004077 val16 |= (1<<5);
4078
4079 /* Enable CL37 1G Parallel Detect */
Yuval Mintza351d492012-06-20 19:05:21 +00004080 bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD, addr, 0x1);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004081 DP(NETIF_MSG_LINK, "Advertize 1G\n");
4082 }
4083 if (((vars->line_speed == SPEED_AUTO_NEG) &&
4084 (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) ||
4085 (vars->line_speed == SPEED_10000)) {
4086 /* Check adding advertisement for 10G KR */
4087 val16 |= (1<<7);
4088 /* Enable 10G Parallel Detect */
4089 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
Yuval Mintza351d492012-06-20 19:05:21 +00004090 MDIO_WC_REG_PAR_DET_10G_CTRL, 1);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004091
4092 DP(NETIF_MSG_LINK, "Advertize 10G\n");
4093 }
4094
4095 /* Set Transmit PMD settings */
4096 lane = bnx2x_get_warpcore_lane(phy, params);
4097 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4098 MDIO_WC_REG_TX0_TX_DRIVER + 0x10*lane,
4099 ((0x02 << MDIO_WC_REG_TX0_TX_DRIVER_POST2_COEFF_OFFSET) |
4100 (0x06 << MDIO_WC_REG_TX0_TX_DRIVER_IDRIVER_OFFSET) |
4101 (0x09 << MDIO_WC_REG_TX0_TX_DRIVER_IPRE_DRIVER_OFFSET)));
4102 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4103 MDIO_WC_REG_CL72_USERB0_CL72_OS_DEF_CTRL,
4104 0x03f0);
4105 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4106 MDIO_WC_REG_CL72_USERB0_CL72_2P5_DEF_CTRL,
4107 0x03f0);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004108
4109 /* Advertised speeds */
4110 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
4111 MDIO_WC_REG_AN_IEEE1BLK_AN_ADVERTISEMENT1, val16);
4112
David S. Miller8decf862011-09-22 03:23:13 -04004113 /* Advertised and set FEC (Forward Error Correction) */
4114 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
4115 MDIO_WC_REG_AN_IEEE1BLK_AN_ADVERTISEMENT2,
4116 (MDIO_WC_REG_AN_IEEE1BLK_AN_ADV2_FEC_ABILITY |
4117 MDIO_WC_REG_AN_IEEE1BLK_AN_ADV2_FEC_REQ));
4118
Yaniv Rosnera34bc962011-07-05 01:06:41 +00004119 /* Enable CL37 BAM */
4120 if (REG_RD(bp, params->shmem_base +
4121 offsetof(struct shmem_region, dev_info.
4122 port_hw_config[params->port].default_cfg)) &
4123 PORT_HW_CFG_ENABLE_BAM_ON_KR_ENABLED) {
Yuval Mintza351d492012-06-20 19:05:21 +00004124 bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
4125 MDIO_WC_REG_DIGITAL6_MP5_NEXTPAGECTRL,
4126 1);
Yaniv Rosnera34bc962011-07-05 01:06:41 +00004127 DP(NETIF_MSG_LINK, "Enable CL37 BAM on KR\n");
4128 }
4129
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004130 /* Advertise pause */
4131 bnx2x_ext_phy_set_pause(params, phy, vars);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00004132 /* Set KR Autoneg Work-Around flag for Warpcore version older than D108
Yaniv Rosner6ab48a52012-01-17 02:33:29 +00004133 */
4134 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4135 MDIO_WC_REG_UC_INFO_B1_VERSION, &val16);
4136 if (val16 < 0xd108) {
4137 DP(NETIF_MSG_LINK, "Enable AN KR work-around\n");
4138 vars->rx_tx_asic_rst = MAX_KR_LINK_RETRY;
4139 }
Yuval Mintza351d492012-06-20 19:05:21 +00004140 bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
4141 MDIO_WC_REG_DIGITAL5_MISC7, 0x100);
Yaniv Rosnera9077bf2011-10-27 05:09:46 +00004142
4143 /* Over 1G - AN local device user page 1 */
4144 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4145 MDIO_WC_REG_DIGITAL3_UP1, 0x1f);
4146
4147 /* Enable Autoneg */
4148 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
Mintz Yuval1b85ae52012-02-15 02:10:25 +00004149 MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x1200);
Yaniv Rosnera9077bf2011-10-27 05:09:46 +00004150
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004151}
4152
4153static void bnx2x_warpcore_set_10G_KR(struct bnx2x_phy *phy,
4154 struct link_params *params,
4155 struct link_vars *vars)
4156{
4157 struct bnx2x *bp = params->bp;
Yuval Mintza351d492012-06-20 19:05:21 +00004158 u16 i;
4159 static struct bnx2x_reg_set reg_set[] = {
4160 /* Disable Autoneg */
4161 {MDIO_WC_DEVAD, MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2, 0x7},
4162 {MDIO_AN_DEVAD, MDIO_WC_REG_PAR_DET_10G_CTRL, 0},
4163 {MDIO_WC_DEVAD, MDIO_WC_REG_CL72_USERB0_CL72_MISC1_CONTROL,
4164 0x3f00},
4165 {MDIO_AN_DEVAD, MDIO_WC_REG_AN_IEEE1BLK_AN_ADVERTISEMENT1, 0},
4166 {MDIO_AN_DEVAD, MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x0},
4167 {MDIO_WC_DEVAD, MDIO_WC_REG_DIGITAL3_UP1, 0x1},
4168 {MDIO_WC_DEVAD, MDIO_WC_REG_DIGITAL5_MISC7, 0xa},
4169 /* Disable CL36 PCS Tx */
4170 {MDIO_WC_DEVAD, MDIO_WC_REG_XGXSBLK1_LANECTRL0, 0x0},
4171 /* Double Wide Single Data Rate @ pll rate */
4172 {MDIO_WC_DEVAD, MDIO_WC_REG_XGXSBLK1_LANECTRL1, 0xFFFF},
4173 /* Leave cl72 training enable, needed for KR */
4174 {MDIO_PMA_DEVAD,
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004175 MDIO_WC_REG_PMD_IEEE9BLK_TENGBASE_KR_PMD_CONTROL_REGISTER_150,
Yuval Mintza351d492012-06-20 19:05:21 +00004176 0x2}
4177 };
4178
4179 for (i = 0; i < sizeof(reg_set)/sizeof(struct bnx2x_reg_set); i++)
4180 bnx2x_cl45_write(bp, phy, reg_set[i].devad, reg_set[i].reg,
4181 reg_set[i].val);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004182
4183 /* Leave CL72 enabled */
Yuval Mintza351d492012-06-20 19:05:21 +00004184 bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
4185 MDIO_WC_REG_CL72_USERB0_CL72_MISC1_CONTROL,
4186 0x3800);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004187
4188 /* Set speed via PMA/PMD register */
4189 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD,
4190 MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x2040);
4191
4192 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD,
4193 MDIO_WC_REG_IEEE0BLK_AUTONEGNP, 0xB);
4194
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00004195 /* Enable encoded forced speed */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004196 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4197 MDIO_WC_REG_SERDESDIGITAL_MISC2, 0x30);
4198
4199 /* Turn TX scramble payload only the 64/66 scrambler */
4200 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4201 MDIO_WC_REG_TX66_CONTROL, 0x9);
4202
4203 /* Turn RX scramble payload only the 64/66 scrambler */
4204 bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
4205 MDIO_WC_REG_RX66_CONTROL, 0xF9);
4206
Yuval Mintzd2310232012-06-20 19:05:19 +00004207 /* Set and clear loopback to cause a reset to 64/66 decoder */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004208 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4209 MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x4000);
4210 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4211 MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x0);
4212
4213}
4214
4215static void bnx2x_warpcore_set_10G_XFI(struct bnx2x_phy *phy,
4216 struct link_params *params,
4217 u8 is_xfi)
4218{
4219 struct bnx2x *bp = params->bp;
4220 u16 misc1_val, tap_val, tx_driver_val, lane, val;
4221 /* Hold rxSeqStart */
Yuval Mintza351d492012-06-20 19:05:21 +00004222 bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
4223 MDIO_WC_REG_DSC2B0_DSC_MISC_CTRL0, 0x8000);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004224
4225 /* Hold tx_fifo_reset */
Yuval Mintza351d492012-06-20 19:05:21 +00004226 bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
4227 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X3, 0x1);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004228
4229 /* Disable CL73 AN */
4230 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0);
4231
4232 /* Disable 100FX Enable and Auto-Detect */
4233 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4234 MDIO_WC_REG_FX100_CTRL1, &val);
4235 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4236 MDIO_WC_REG_FX100_CTRL1, (val & 0xFFFA));
4237
4238 /* Disable 100FX Idle detect */
Yuval Mintza351d492012-06-20 19:05:21 +00004239 bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
4240 MDIO_WC_REG_FX100_CTRL3, 0x0080);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004241
4242 /* Set Block address to Remote PHY & Clear forced_speed[5] */
4243 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4244 MDIO_WC_REG_DIGITAL4_MISC3, &val);
4245 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4246 MDIO_WC_REG_DIGITAL4_MISC3, (val & 0xFF7F));
4247
4248 /* Turn off auto-detect & fiber mode */
4249 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4250 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X1, &val);
4251 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4252 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X1,
4253 (val & 0xFFEE));
4254
4255 /* Set filter_force_link, disable_false_link and parallel_detect */
4256 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4257 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2, &val);
4258 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4259 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2,
4260 ((val | 0x0006) & 0xFFFE));
4261
4262 /* Set XFI / SFI */
4263 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4264 MDIO_WC_REG_SERDESDIGITAL_MISC1, &misc1_val);
4265
4266 misc1_val &= ~(0x1f);
4267
4268 if (is_xfi) {
4269 misc1_val |= 0x5;
4270 tap_val = ((0x08 << MDIO_WC_REG_TX_FIR_TAP_POST_TAP_OFFSET) |
4271 (0x37 << MDIO_WC_REG_TX_FIR_TAP_MAIN_TAP_OFFSET) |
4272 (0x00 << MDIO_WC_REG_TX_FIR_TAP_PRE_TAP_OFFSET));
4273 tx_driver_val =
4274 ((0x00 << MDIO_WC_REG_TX0_TX_DRIVER_POST2_COEFF_OFFSET) |
4275 (0x02 << MDIO_WC_REG_TX0_TX_DRIVER_IDRIVER_OFFSET) |
4276 (0x03 << MDIO_WC_REG_TX0_TX_DRIVER_IPRE_DRIVER_OFFSET));
4277
4278 } else {
4279 misc1_val |= 0x9;
Yaniv Rosner25182fc2012-04-04 01:28:57 +00004280 tap_val = ((0x0f << MDIO_WC_REG_TX_FIR_TAP_POST_TAP_OFFSET) |
4281 (0x2b << MDIO_WC_REG_TX_FIR_TAP_MAIN_TAP_OFFSET) |
4282 (0x02 << MDIO_WC_REG_TX_FIR_TAP_PRE_TAP_OFFSET));
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004283 tx_driver_val =
Yaniv Rosner25182fc2012-04-04 01:28:57 +00004284 ((0x03 << MDIO_WC_REG_TX0_TX_DRIVER_POST2_COEFF_OFFSET) |
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004285 (0x02 << MDIO_WC_REG_TX0_TX_DRIVER_IDRIVER_OFFSET) |
Yaniv Rosner25182fc2012-04-04 01:28:57 +00004286 (0x06 << MDIO_WC_REG_TX0_TX_DRIVER_IPRE_DRIVER_OFFSET));
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004287 }
4288 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4289 MDIO_WC_REG_SERDESDIGITAL_MISC1, misc1_val);
4290
4291 /* Set Transmit PMD settings */
4292 lane = bnx2x_get_warpcore_lane(phy, params);
4293 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4294 MDIO_WC_REG_TX_FIR_TAP,
4295 tap_val | MDIO_WC_REG_TX_FIR_TAP_ENABLE);
4296 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4297 MDIO_WC_REG_TX0_TX_DRIVER + 0x10*lane,
4298 tx_driver_val);
4299
4300 /* Enable fiber mode, enable and invert sig_det */
Yuval Mintza351d492012-06-20 19:05:21 +00004301 bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
4302 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X1, 0xd);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004303
4304 /* Set Block address to Remote PHY & Set forced_speed[5], 40bit mode */
Yuval Mintza351d492012-06-20 19:05:21 +00004305 bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
4306 MDIO_WC_REG_DIGITAL4_MISC3, 0x8080);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004307
Yuval Mintzec4010e2012-09-10 05:51:06 +00004308 bnx2x_warpcore_set_lpi_passthrough(phy, params);
Yuval Mintzc8c60d82012-06-06 17:13:07 +00004309
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004310 /* 10G XFI Full Duplex */
4311 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4312 MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x100);
4313
4314 /* Release tx_fifo_reset */
4315 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4316 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X3, &val);
4317 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4318 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X3, val & 0xFFFE);
4319
4320 /* Release rxSeqStart */
4321 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4322 MDIO_WC_REG_DSC2B0_DSC_MISC_CTRL0, &val);
4323 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4324 MDIO_WC_REG_DSC2B0_DSC_MISC_CTRL0, (val & 0x7FFF));
4325}
4326
4327static void bnx2x_warpcore_set_20G_KR2(struct bnx2x *bp,
4328 struct bnx2x_phy *phy)
4329{
4330 DP(NETIF_MSG_LINK, "KR2 still not supported !!!\n");
4331}
4332
4333static void bnx2x_warpcore_set_20G_DXGXS(struct bnx2x *bp,
4334 struct bnx2x_phy *phy,
4335 u16 lane)
4336{
4337 /* Rx0 anaRxControl1G */
4338 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4339 MDIO_WC_REG_RX0_ANARXCONTROL1G, 0x90);
4340
4341 /* Rx2 anaRxControl1G */
4342 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4343 MDIO_WC_REG_RX2_ANARXCONTROL1G, 0x90);
4344
4345 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4346 MDIO_WC_REG_RX66_SCW0, 0xE070);
4347
4348 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4349 MDIO_WC_REG_RX66_SCW1, 0xC0D0);
4350
4351 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4352 MDIO_WC_REG_RX66_SCW2, 0xA0B0);
4353
4354 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4355 MDIO_WC_REG_RX66_SCW3, 0x8090);
4356
4357 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4358 MDIO_WC_REG_RX66_SCW0_MASK, 0xF0F0);
4359
4360 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4361 MDIO_WC_REG_RX66_SCW1_MASK, 0xF0F0);
4362
4363 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4364 MDIO_WC_REG_RX66_SCW2_MASK, 0xF0F0);
4365
4366 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4367 MDIO_WC_REG_RX66_SCW3_MASK, 0xF0F0);
4368
4369 /* Serdes Digital Misc1 */
4370 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4371 MDIO_WC_REG_SERDESDIGITAL_MISC1, 0x6008);
4372
4373 /* Serdes Digital4 Misc3 */
4374 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4375 MDIO_WC_REG_DIGITAL4_MISC3, 0x8088);
4376
4377 /* Set Transmit PMD settings */
4378 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4379 MDIO_WC_REG_TX_FIR_TAP,
4380 ((0x12 << MDIO_WC_REG_TX_FIR_TAP_POST_TAP_OFFSET) |
4381 (0x2d << MDIO_WC_REG_TX_FIR_TAP_MAIN_TAP_OFFSET) |
4382 (0x00 << MDIO_WC_REG_TX_FIR_TAP_PRE_TAP_OFFSET) |
4383 MDIO_WC_REG_TX_FIR_TAP_ENABLE));
4384 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4385 MDIO_WC_REG_TX0_TX_DRIVER + 0x10*lane,
4386 ((0x02 << MDIO_WC_REG_TX0_TX_DRIVER_POST2_COEFF_OFFSET) |
4387 (0x02 << MDIO_WC_REG_TX0_TX_DRIVER_IDRIVER_OFFSET) |
4388 (0x02 << MDIO_WC_REG_TX0_TX_DRIVER_IPRE_DRIVER_OFFSET)));
4389}
4390
4391static void bnx2x_warpcore_set_sgmii_speed(struct bnx2x_phy *phy,
4392 struct link_params *params,
Yaniv Rosner521683d2011-11-28 00:49:48 +00004393 u8 fiber_mode,
4394 u8 always_autoneg)
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004395{
4396 struct bnx2x *bp = params->bp;
4397 u16 val16, digctrl_kx1, digctrl_kx2;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004398
4399 /* Clear XFI clock comp in non-10G single lane mode. */
4400 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4401 MDIO_WC_REG_RX66_CONTROL, &val16);
4402 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4403 MDIO_WC_REG_RX66_CONTROL, val16 & ~(3<<13));
4404
Yuval Mintz26964bb2012-09-10 05:51:08 +00004405 bnx2x_warpcore_set_lpi_passthrough(phy, params);
4406
Yaniv Rosner521683d2011-11-28 00:49:48 +00004407 if (always_autoneg || phy->req_line_speed == SPEED_AUTO_NEG) {
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004408 /* SGMII Autoneg */
4409 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4410 MDIO_WC_REG_COMBO_IEEE0_MIICTRL, &val16);
4411 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4412 MDIO_WC_REG_COMBO_IEEE0_MIICTRL,
4413 val16 | 0x1000);
4414 DP(NETIF_MSG_LINK, "set SGMII AUTONEG\n");
4415 } else {
4416 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4417 MDIO_WC_REG_COMBO_IEEE0_MIICTRL, &val16);
Yaniv Rosner521683d2011-11-28 00:49:48 +00004418 val16 &= 0xcebf;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004419 switch (phy->req_line_speed) {
4420 case SPEED_10:
4421 break;
4422 case SPEED_100:
4423 val16 |= 0x2000;
4424 break;
4425 case SPEED_1000:
4426 val16 |= 0x0040;
4427 break;
4428 default:
Joe Perches94f05b02011-08-14 12:16:20 +00004429 DP(NETIF_MSG_LINK,
4430 "Speed not supported: 0x%x\n", phy->req_line_speed);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004431 return;
4432 }
4433
4434 if (phy->req_duplex == DUPLEX_FULL)
4435 val16 |= 0x0100;
4436
4437 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4438 MDIO_WC_REG_COMBO_IEEE0_MIICTRL, val16);
4439
4440 DP(NETIF_MSG_LINK, "set SGMII force speed %d\n",
4441 phy->req_line_speed);
4442 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4443 MDIO_WC_REG_COMBO_IEEE0_MIICTRL, &val16);
4444 DP(NETIF_MSG_LINK, " (readback) %x\n", val16);
4445 }
4446
4447 /* SGMII Slave mode and disable signal detect */
4448 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4449 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X1, &digctrl_kx1);
4450 if (fiber_mode)
4451 digctrl_kx1 = 1;
4452 else
4453 digctrl_kx1 &= 0xff4a;
4454
4455 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4456 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X1,
4457 digctrl_kx1);
4458
4459 /* Turn off parallel detect */
4460 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4461 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2, &digctrl_kx2);
4462 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4463 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2,
4464 (digctrl_kx2 & ~(1<<2)));
4465
4466 /* Re-enable parallel detect */
4467 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4468 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2,
4469 (digctrl_kx2 | (1<<2)));
4470
4471 /* Enable autodet */
4472 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4473 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X1,
4474 (digctrl_kx1 | 0x10));
4475}
4476
4477static void bnx2x_warpcore_reset_lane(struct bnx2x *bp,
4478 struct bnx2x_phy *phy,
4479 u8 reset)
4480{
4481 u16 val;
4482 /* Take lane out of reset after configuration is finished */
4483 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4484 MDIO_WC_REG_DIGITAL5_MISC6, &val);
4485 if (reset)
4486 val |= 0xC000;
4487 else
4488 val &= 0x3FFF;
4489 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4490 MDIO_WC_REG_DIGITAL5_MISC6, val);
4491 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4492 MDIO_WC_REG_DIGITAL5_MISC6, &val);
4493}
Yaniv Rosner2f751a82011-11-28 00:49:52 +00004494/* Clear SFI/XFI link settings registers */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004495static void bnx2x_warpcore_clear_regs(struct bnx2x_phy *phy,
4496 struct link_params *params,
4497 u16 lane)
4498{
4499 struct bnx2x *bp = params->bp;
Yuval Mintza351d492012-06-20 19:05:21 +00004500 u16 i;
4501 static struct bnx2x_reg_set wc_regs[] = {
4502 {MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0},
4503 {MDIO_WC_DEVAD, MDIO_WC_REG_FX100_CTRL1, 0x014a},
4504 {MDIO_WC_DEVAD, MDIO_WC_REG_FX100_CTRL3, 0x0800},
4505 {MDIO_WC_DEVAD, MDIO_WC_REG_DIGITAL4_MISC3, 0x8008},
4506 {MDIO_WC_DEVAD, MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X1,
4507 0x0195},
4508 {MDIO_WC_DEVAD, MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2,
4509 0x0007},
4510 {MDIO_WC_DEVAD, MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X3,
4511 0x0002},
4512 {MDIO_WC_DEVAD, MDIO_WC_REG_SERDESDIGITAL_MISC1, 0x6000},
4513 {MDIO_WC_DEVAD, MDIO_WC_REG_TX_FIR_TAP, 0x0000},
4514 {MDIO_WC_DEVAD, MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x2040},
4515 {MDIO_WC_DEVAD, MDIO_WC_REG_COMBO_IEEE0_MIICTRL, 0x0140}
4516 };
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004517 /* Set XFI clock comp as default. */
Yuval Mintza351d492012-06-20 19:05:21 +00004518 bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
4519 MDIO_WC_REG_RX66_CONTROL, (3<<13));
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004520
Yuval Mintza351d492012-06-20 19:05:21 +00004521 for (i = 0; i < sizeof(wc_regs)/sizeof(struct bnx2x_reg_set); i++)
4522 bnx2x_cl45_write(bp, phy, wc_regs[i].devad, wc_regs[i].reg,
4523 wc_regs[i].val);
4524
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004525 lane = bnx2x_get_warpcore_lane(phy, params);
4526 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004527 MDIO_WC_REG_TX0_TX_DRIVER + 0x10*lane, 0x0990);
Yuval Mintza351d492012-06-20 19:05:21 +00004528
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004529}
4530
4531static int bnx2x_get_mod_abs_int_cfg(struct bnx2x *bp,
4532 u32 chip_id,
4533 u32 shmem_base, u8 port,
4534 u8 *gpio_num, u8 *gpio_port)
4535{
4536 u32 cfg_pin;
4537 *gpio_num = 0;
4538 *gpio_port = 0;
4539 if (CHIP_IS_E3(bp)) {
4540 cfg_pin = (REG_RD(bp, shmem_base +
4541 offsetof(struct shmem_region,
4542 dev_info.port_hw_config[port].e3_sfp_ctrl)) &
4543 PORT_HW_CFG_E3_MOD_ABS_MASK) >>
4544 PORT_HW_CFG_E3_MOD_ABS_SHIFT;
4545
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00004546 /* Should not happen. This function called upon interrupt
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004547 * triggered by GPIO ( since EPIO can only generate interrupts
4548 * to MCP).
4549 * So if this function was called and none of the GPIOs was set,
4550 * it means the shit hit the fan.
4551 */
4552 if ((cfg_pin < PIN_CFG_GPIO0_P0) ||
4553 (cfg_pin > PIN_CFG_GPIO3_P1)) {
Joe Perches94f05b02011-08-14 12:16:20 +00004554 DP(NETIF_MSG_LINK,
4555 "ERROR: Invalid cfg pin %x for module detect indication\n",
4556 cfg_pin);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004557 return -EINVAL;
4558 }
4559
4560 *gpio_num = (cfg_pin - PIN_CFG_GPIO0_P0) & 0x3;
4561 *gpio_port = (cfg_pin - PIN_CFG_GPIO0_P0) >> 2;
4562 } else {
4563 *gpio_num = MISC_REGISTERS_GPIO_3;
4564 *gpio_port = port;
4565 }
4566 DP(NETIF_MSG_LINK, "MOD_ABS int GPIO%d_P%d\n", *gpio_num, *gpio_port);
4567 return 0;
4568}
4569
4570static int bnx2x_is_sfp_module_plugged(struct bnx2x_phy *phy,
4571 struct link_params *params)
4572{
4573 struct bnx2x *bp = params->bp;
4574 u8 gpio_num, gpio_port;
4575 u32 gpio_val;
4576 if (bnx2x_get_mod_abs_int_cfg(bp, params->chip_id,
4577 params->shmem_base, params->port,
4578 &gpio_num, &gpio_port) != 0)
4579 return 0;
4580 gpio_val = bnx2x_get_gpio(bp, gpio_num, gpio_port);
4581
4582 /* Call the handling function in case module is detected */
4583 if (gpio_val == 0)
4584 return 1;
4585 else
4586 return 0;
4587}
Yaniv Rosnera9077bf2011-10-27 05:09:46 +00004588static int bnx2x_warpcore_get_sigdet(struct bnx2x_phy *phy,
4589 struct link_params *params)
4590{
4591 u16 gp2_status_reg0, lane;
4592 struct bnx2x *bp = params->bp;
4593
4594 lane = bnx2x_get_warpcore_lane(phy, params);
4595
4596 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD, MDIO_WC_REG_GP2_STATUS_GP_2_0,
4597 &gp2_status_reg0);
4598
4599 return (gp2_status_reg0 >> (8+lane)) & 0x1;
4600}
4601
4602static void bnx2x_warpcore_config_runtime(struct bnx2x_phy *phy,
4603 struct link_params *params,
4604 struct link_vars *vars)
4605{
4606 struct bnx2x *bp = params->bp;
4607 u32 serdes_net_if;
4608 u16 gp_status1 = 0, lnkup = 0, lnkup_kr = 0;
4609 u16 lane = bnx2x_get_warpcore_lane(phy, params);
4610
4611 vars->turn_to_run_wc_rt = vars->turn_to_run_wc_rt ? 0 : 1;
4612
4613 if (!vars->turn_to_run_wc_rt)
4614 return;
4615
Yuval Mintzd2310232012-06-20 19:05:19 +00004616 /* Return if there is no link partner */
Yaniv Rosnera9077bf2011-10-27 05:09:46 +00004617 if (!(bnx2x_warpcore_get_sigdet(phy, params))) {
4618 DP(NETIF_MSG_LINK, "bnx2x_warpcore_get_sigdet false\n");
4619 return;
4620 }
4621
4622 if (vars->rx_tx_asic_rst) {
4623 serdes_net_if = (REG_RD(bp, params->shmem_base +
4624 offsetof(struct shmem_region, dev_info.
4625 port_hw_config[params->port].default_cfg)) &
4626 PORT_HW_CFG_NET_SERDES_IF_MASK);
4627
4628 switch (serdes_net_if) {
4629 case PORT_HW_CFG_NET_SERDES_IF_KR:
4630 /* Do we get link yet? */
4631 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD, 0x81d1,
4632 &gp_status1);
4633 lnkup = (gp_status1 >> (8+lane)) & 0x1;/* 1G */
4634 /*10G KR*/
4635 lnkup_kr = (gp_status1 >> (12+lane)) & 0x1;
4636
4637 DP(NETIF_MSG_LINK,
4638 "gp_status1 0x%x\n", gp_status1);
4639
4640 if (lnkup_kr || lnkup) {
4641 vars->rx_tx_asic_rst = 0;
4642 DP(NETIF_MSG_LINK,
4643 "link up, rx_tx_asic_rst 0x%x\n",
4644 vars->rx_tx_asic_rst);
4645 } else {
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00004646 /* Reset the lane to see if link comes up.*/
Yaniv Rosnera9077bf2011-10-27 05:09:46 +00004647 bnx2x_warpcore_reset_lane(bp, phy, 1);
4648 bnx2x_warpcore_reset_lane(bp, phy, 0);
4649
Yuval Mintzd2310232012-06-20 19:05:19 +00004650 /* Restart Autoneg */
Yaniv Rosnera9077bf2011-10-27 05:09:46 +00004651 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
4652 MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x1200);
4653
4654 vars->rx_tx_asic_rst--;
4655 DP(NETIF_MSG_LINK, "0x%x retry left\n",
4656 vars->rx_tx_asic_rst);
4657 }
4658 break;
4659
4660 default:
4661 break;
4662 }
4663
4664 } /*params->rx_tx_asic_rst*/
4665
4666}
Yuval Mintzdbef8072012-06-20 19:05:22 +00004667static void bnx2x_warpcore_config_sfi(struct bnx2x_phy *phy,
4668 struct link_params *params)
4669{
4670 u16 lane = bnx2x_get_warpcore_lane(phy, params);
4671 struct bnx2x *bp = params->bp;
4672 bnx2x_warpcore_clear_regs(phy, params, lane);
4673 if ((params->req_line_speed[LINK_CONFIG_IDX(INT_PHY)] ==
4674 SPEED_10000) &&
4675 (phy->media_type != ETH_PHY_SFP_1G_FIBER)) {
4676 DP(NETIF_MSG_LINK, "Setting 10G SFI\n");
4677 bnx2x_warpcore_set_10G_XFI(phy, params, 0);
4678 } else {
4679 DP(NETIF_MSG_LINK, "Setting 1G Fiber\n");
4680 bnx2x_warpcore_set_sgmii_speed(phy, params, 1, 0);
4681 }
4682}
4683
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004684static void bnx2x_warpcore_config_init(struct bnx2x_phy *phy,
4685 struct link_params *params,
4686 struct link_vars *vars)
4687{
4688 struct bnx2x *bp = params->bp;
4689 u32 serdes_net_if;
4690 u8 fiber_mode;
4691 u16 lane = bnx2x_get_warpcore_lane(phy, params);
4692 serdes_net_if = (REG_RD(bp, params->shmem_base +
4693 offsetof(struct shmem_region, dev_info.
4694 port_hw_config[params->port].default_cfg)) &
4695 PORT_HW_CFG_NET_SERDES_IF_MASK);
4696 DP(NETIF_MSG_LINK, "Begin Warpcore init, link_speed %d, "
4697 "serdes_net_if = 0x%x\n",
4698 vars->line_speed, serdes_net_if);
4699 bnx2x_set_aer_mmd(params, phy);
Yaniv Rosnerd3a8f132012-09-13 02:56:20 +00004700 bnx2x_warpcore_reset_lane(bp, phy, 1);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004701 vars->phy_flags |= PHY_XGXS_FLAG;
4702 if ((serdes_net_if == PORT_HW_CFG_NET_SERDES_IF_SGMII) ||
4703 (phy->req_line_speed &&
4704 ((phy->req_line_speed == SPEED_100) ||
4705 (phy->req_line_speed == SPEED_10)))) {
4706 vars->phy_flags |= PHY_SGMII_FLAG;
4707 DP(NETIF_MSG_LINK, "Setting SGMII mode\n");
4708 bnx2x_warpcore_clear_regs(phy, params, lane);
Yaniv Rosner521683d2011-11-28 00:49:48 +00004709 bnx2x_warpcore_set_sgmii_speed(phy, params, 0, 1);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004710 } else {
4711 switch (serdes_net_if) {
4712 case PORT_HW_CFG_NET_SERDES_IF_KR:
4713 /* Enable KR Auto Neg */
Yaniv Rosner6a51c0d2012-04-04 01:28:56 +00004714 if (params->loopback_mode != LOOPBACK_EXT)
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004715 bnx2x_warpcore_enable_AN_KR(phy, params, vars);
4716 else {
4717 DP(NETIF_MSG_LINK, "Setting KR 10G-Force\n");
4718 bnx2x_warpcore_set_10G_KR(phy, params, vars);
4719 }
4720 break;
4721
4722 case PORT_HW_CFG_NET_SERDES_IF_XFI:
4723 bnx2x_warpcore_clear_regs(phy, params, lane);
4724 if (vars->line_speed == SPEED_10000) {
4725 DP(NETIF_MSG_LINK, "Setting 10G XFI\n");
4726 bnx2x_warpcore_set_10G_XFI(phy, params, 1);
4727 } else {
4728 if (SINGLE_MEDIA_DIRECT(params)) {
4729 DP(NETIF_MSG_LINK, "1G Fiber\n");
4730 fiber_mode = 1;
4731 } else {
4732 DP(NETIF_MSG_LINK, "10/100/1G SGMII\n");
4733 fiber_mode = 0;
4734 }
4735 bnx2x_warpcore_set_sgmii_speed(phy,
4736 params,
Yaniv Rosner521683d2011-11-28 00:49:48 +00004737 fiber_mode,
4738 0);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004739 }
4740
4741 break;
4742
4743 case PORT_HW_CFG_NET_SERDES_IF_SFI:
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004744 /* Issue Module detection */
4745 if (bnx2x_is_sfp_module_plugged(phy, params))
4746 bnx2x_sfp_module_detection(phy, params);
Yuval Mintzdbef8072012-06-20 19:05:22 +00004747
4748 bnx2x_warpcore_config_sfi(phy, params);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004749 break;
4750
4751 case PORT_HW_CFG_NET_SERDES_IF_DXGXS:
4752 if (vars->line_speed != SPEED_20000) {
4753 DP(NETIF_MSG_LINK, "Speed not supported yet\n");
4754 return;
4755 }
4756 DP(NETIF_MSG_LINK, "Setting 20G DXGXS\n");
4757 bnx2x_warpcore_set_20G_DXGXS(bp, phy, lane);
4758 /* Issue Module detection */
4759
4760 bnx2x_sfp_module_detection(phy, params);
4761 break;
4762
4763 case PORT_HW_CFG_NET_SERDES_IF_KR2:
4764 if (vars->line_speed != SPEED_20000) {
4765 DP(NETIF_MSG_LINK, "Speed not supported yet\n");
4766 return;
4767 }
4768 DP(NETIF_MSG_LINK, "Setting 20G KR2\n");
4769 bnx2x_warpcore_set_20G_KR2(bp, phy);
4770 break;
4771
4772 default:
Joe Perches94f05b02011-08-14 12:16:20 +00004773 DP(NETIF_MSG_LINK,
4774 "Unsupported Serdes Net Interface 0x%x\n",
4775 serdes_net_if);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004776 return;
4777 }
4778 }
4779
4780 /* Take lane out of reset after configuration is finished */
4781 bnx2x_warpcore_reset_lane(bp, phy, 0);
4782 DP(NETIF_MSG_LINK, "Exit config init\n");
4783}
4784
4785static void bnx2x_sfp_e3_set_transmitter(struct link_params *params,
4786 struct bnx2x_phy *phy,
4787 u8 tx_en)
4788{
4789 struct bnx2x *bp = params->bp;
4790 u32 cfg_pin;
4791 u8 port = params->port;
4792
4793 cfg_pin = REG_RD(bp, params->shmem_base +
4794 offsetof(struct shmem_region,
4795 dev_info.port_hw_config[port].e3_sfp_ctrl)) &
4796 PORT_HW_CFG_TX_LASER_MASK;
4797 /* Set the !tx_en since this pin is DISABLE_TX_LASER */
4798 DP(NETIF_MSG_LINK, "Setting WC TX to %d\n", tx_en);
4799 /* For 20G, the expected pin to be used is 3 pins after the current */
4800
4801 bnx2x_set_cfg_pin(bp, cfg_pin, tx_en ^ 1);
4802 if (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_20G)
4803 bnx2x_set_cfg_pin(bp, cfg_pin + 3, tx_en ^ 1);
4804}
4805
4806static void bnx2x_warpcore_link_reset(struct bnx2x_phy *phy,
4807 struct link_params *params)
4808{
4809 struct bnx2x *bp = params->bp;
4810 u16 val16;
4811 bnx2x_sfp_e3_set_transmitter(params, phy, 0);
4812 bnx2x_set_mdio_clk(bp, params->chip_id, params->port);
4813 bnx2x_set_aer_mmd(params, phy);
4814 /* Global register */
4815 bnx2x_warpcore_reset_lane(bp, phy, 1);
4816
4817 /* Clear loopback settings (if any) */
4818 /* 10G & 20G */
4819 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4820 MDIO_WC_REG_COMBO_IEEE0_MIICTRL, &val16);
4821 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4822 MDIO_WC_REG_COMBO_IEEE0_MIICTRL, val16 &
4823 0xBFFF);
4824
4825 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4826 MDIO_WC_REG_IEEE0BLK_MIICNTL, &val16);
4827 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4828 MDIO_WC_REG_IEEE0BLK_MIICNTL, val16 & 0xfffe);
4829
4830 /* Update those 1-copy registers */
4831 CL22_WR_OVER_CL45(bp, phy, MDIO_REG_BANK_AER_BLOCK,
4832 MDIO_AER_BLOCK_AER_REG, 0);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00004833 /* Enable 1G MDIO (1-copy) */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004834 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4835 MDIO_WC_REG_XGXSBLK0_XGXSCONTROL,
4836 &val16);
4837 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4838 MDIO_WC_REG_XGXSBLK0_XGXSCONTROL,
4839 val16 & ~0x10);
4840
4841 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4842 MDIO_WC_REG_XGXSBLK1_LANECTRL2, &val16);
4843 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4844 MDIO_WC_REG_XGXSBLK1_LANECTRL2,
4845 val16 & 0xff00);
4846
4847}
4848
4849static void bnx2x_set_warpcore_loopback(struct bnx2x_phy *phy,
4850 struct link_params *params)
4851{
4852 struct bnx2x *bp = params->bp;
4853 u16 val16;
4854 u32 lane;
4855 DP(NETIF_MSG_LINK, "Setting Warpcore loopback type %x, speed %d\n",
4856 params->loopback_mode, phy->req_line_speed);
4857
4858 if (phy->req_line_speed < SPEED_10000) {
4859 /* 10/100/1000 */
4860
4861 /* Update those 1-copy registers */
4862 CL22_WR_OVER_CL45(bp, phy, MDIO_REG_BANK_AER_BLOCK,
4863 MDIO_AER_BLOCK_AER_REG, 0);
4864 /* Enable 1G MDIO (1-copy) */
Yuval Mintza351d492012-06-20 19:05:21 +00004865 bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
4866 MDIO_WC_REG_XGXSBLK0_XGXSCONTROL,
4867 0x10);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004868 /* Set 1G loopback based on lane (1-copy) */
4869 lane = bnx2x_get_warpcore_lane(phy, params);
4870 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4871 MDIO_WC_REG_XGXSBLK1_LANECTRL2, &val16);
4872 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4873 MDIO_WC_REG_XGXSBLK1_LANECTRL2,
4874 val16 | (1<<lane));
4875
4876 /* Switch back to 4-copy registers */
4877 bnx2x_set_aer_mmd(params, phy);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004878 } else {
4879 /* 10G & 20G */
Yuval Mintza351d492012-06-20 19:05:21 +00004880 bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
4881 MDIO_WC_REG_COMBO_IEEE0_MIICTRL,
4882 0x4000);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004883
Yuval Mintza351d492012-06-20 19:05:21 +00004884 bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
4885 MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x1);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004886 }
4887}
4888
4889
Yuval Mintzd2310232012-06-20 19:05:19 +00004890
4891static void bnx2x_sync_link(struct link_params *params,
4892 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004893{
4894 struct bnx2x *bp = params->bp;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00004895 u8 link_10g_plus;
Yaniv Rosnerde6f3372011-08-02 22:59:25 +00004896 if (vars->link_status & LINK_STATUS_PHYSICAL_LINK_FLAG)
4897 vars->phy_flags |= PHY_PHYSICAL_LINK_FLAG;
Yaniv Rosner2f751a82011-11-28 00:49:52 +00004898 vars->link_up = (vars->link_status & LINK_STATUS_LINK_UP);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004899 if (vars->link_up) {
4900 DP(NETIF_MSG_LINK, "phy link up\n");
4901
4902 vars->phy_link_up = 1;
4903 vars->duplex = DUPLEX_FULL;
4904 switch (vars->link_status &
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004905 LINK_STATUS_SPEED_AND_DUPLEX_MASK) {
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00004906 case LINK_10THD:
4907 vars->duplex = DUPLEX_HALF;
4908 /* Fall thru */
4909 case LINK_10TFD:
4910 vars->line_speed = SPEED_10;
4911 break;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004912
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00004913 case LINK_100TXHD:
4914 vars->duplex = DUPLEX_HALF;
4915 /* Fall thru */
4916 case LINK_100T4:
4917 case LINK_100TXFD:
4918 vars->line_speed = SPEED_100;
4919 break;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004920
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00004921 case LINK_1000THD:
4922 vars->duplex = DUPLEX_HALF;
4923 /* Fall thru */
4924 case LINK_1000TFD:
4925 vars->line_speed = SPEED_1000;
4926 break;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004927
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00004928 case LINK_2500THD:
4929 vars->duplex = DUPLEX_HALF;
4930 /* Fall thru */
4931 case LINK_2500TFD:
4932 vars->line_speed = SPEED_2500;
4933 break;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004934
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00004935 case LINK_10GTFD:
4936 vars->line_speed = SPEED_10000;
4937 break;
4938 case LINK_20GTFD:
4939 vars->line_speed = SPEED_20000;
4940 break;
4941 default:
4942 break;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004943 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004944 vars->flow_ctrl = 0;
4945 if (vars->link_status & LINK_STATUS_TX_FLOW_CONTROL_ENABLED)
4946 vars->flow_ctrl |= BNX2X_FLOW_CTRL_TX;
4947
4948 if (vars->link_status & LINK_STATUS_RX_FLOW_CONTROL_ENABLED)
4949 vars->flow_ctrl |= BNX2X_FLOW_CTRL_RX;
4950
4951 if (!vars->flow_ctrl)
4952 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
4953
4954 if (vars->line_speed &&
4955 ((vars->line_speed == SPEED_10) ||
4956 (vars->line_speed == SPEED_100))) {
4957 vars->phy_flags |= PHY_SGMII_FLAG;
4958 } else {
4959 vars->phy_flags &= ~PHY_SGMII_FLAG;
4960 }
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004961 if (vars->line_speed &&
4962 USES_WARPCORE(bp) &&
4963 (vars->line_speed == SPEED_1000))
4964 vars->phy_flags |= PHY_SGMII_FLAG;
Yuval Mintzd2310232012-06-20 19:05:19 +00004965 /* Anything 10 and over uses the bmac */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00004966 link_10g_plus = (vars->line_speed >= SPEED_10000);
4967
4968 if (link_10g_plus) {
4969 if (USES_WARPCORE(bp))
4970 vars->mac_type = MAC_TYPE_XMAC;
4971 else
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004972 vars->mac_type = MAC_TYPE_BMAC;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00004973 } else {
4974 if (USES_WARPCORE(bp))
4975 vars->mac_type = MAC_TYPE_UMAC;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004976 else
4977 vars->mac_type = MAC_TYPE_EMAC;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00004978 }
Yuval Mintzd2310232012-06-20 19:05:19 +00004979 } else { /* Link down */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004980 DP(NETIF_MSG_LINK, "phy link down\n");
4981
4982 vars->phy_link_up = 0;
4983
4984 vars->line_speed = 0;
4985 vars->duplex = DUPLEX_FULL;
4986 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
4987
Yuval Mintzd2310232012-06-20 19:05:19 +00004988 /* Indicate no mac active */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004989 vars->mac_type = MAC_TYPE_NONE;
Yaniv Rosnerde6f3372011-08-02 22:59:25 +00004990 if (vars->link_status & LINK_STATUS_PHYSICAL_LINK_FLAG)
4991 vars->phy_flags |= PHY_HALF_OPEN_CONN_FLAG;
Yuval Mintzd0b8a6f2012-06-20 19:05:18 +00004992 if (vars->link_status & LINK_STATUS_SFP_TX_FAULT)
4993 vars->phy_flags |= PHY_SFP_TX_FAULT_FLAG;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004994 }
Yaniv Rosner2f751a82011-11-28 00:49:52 +00004995}
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004996
Yaniv Rosner2f751a82011-11-28 00:49:52 +00004997void bnx2x_link_status_update(struct link_params *params,
4998 struct link_vars *vars)
4999{
5000 struct bnx2x *bp = params->bp;
5001 u8 port = params->port;
5002 u32 sync_offset, media_types;
5003 /* Update PHY configuration */
5004 set_phy_vars(params, vars);
5005
5006 vars->link_status = REG_RD(bp, params->shmem_base +
5007 offsetof(struct shmem_region,
5008 port_mb[port].link_status));
Yuval Mintz08e9acc2012-09-10 05:51:04 +00005009 if (bnx2x_eee_has_cap(params))
5010 vars->eee_status = REG_RD(bp, params->shmem2_base +
5011 offsetof(struct shmem2_region,
5012 eee_status[params->port]));
Yaniv Rosner2f751a82011-11-28 00:49:52 +00005013
5014 vars->phy_flags = PHY_XGXS_FLAG;
5015 bnx2x_sync_link(params, vars);
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00005016 /* Sync media type */
5017 sync_offset = params->shmem_base +
5018 offsetof(struct shmem_region,
5019 dev_info.port_hw_config[port].media_type);
5020 media_types = REG_RD(bp, sync_offset);
5021
5022 params->phy[INT_PHY].media_type =
5023 (media_types & PORT_HW_CFG_MEDIA_TYPE_PHY0_MASK) >>
5024 PORT_HW_CFG_MEDIA_TYPE_PHY0_SHIFT;
5025 params->phy[EXT_PHY1].media_type =
5026 (media_types & PORT_HW_CFG_MEDIA_TYPE_PHY1_MASK) >>
5027 PORT_HW_CFG_MEDIA_TYPE_PHY1_SHIFT;
5028 params->phy[EXT_PHY2].media_type =
5029 (media_types & PORT_HW_CFG_MEDIA_TYPE_PHY2_MASK) >>
5030 PORT_HW_CFG_MEDIA_TYPE_PHY2_SHIFT;
5031 DP(NETIF_MSG_LINK, "media_types = 0x%x\n", media_types);
5032
Yaniv Rosner020c7e32011-05-31 21:28:43 +00005033 /* Sync AEU offset */
5034 sync_offset = params->shmem_base +
5035 offsetof(struct shmem_region,
5036 dev_info.port_hw_config[port].aeu_int_mask);
5037
5038 vars->aeu_int_mask = REG_RD(bp, sync_offset);
5039
Yaniv Rosnerb8d6d082011-07-05 01:06:27 +00005040 /* Sync PFC status */
5041 if (vars->link_status & LINK_STATUS_PFC_ENABLED)
5042 params->feature_config_flags |=
5043 FEATURE_CONFIG_PFC_ENABLED;
5044 else
5045 params->feature_config_flags &=
5046 ~FEATURE_CONFIG_PFC_ENABLED;
5047
Yaniv Rosner020c7e32011-05-31 21:28:43 +00005048 DP(NETIF_MSG_LINK, "link_status 0x%x phy_link_up %x int_mask 0x%x\n",
5049 vars->link_status, vars->phy_link_up, vars->aeu_int_mask);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005050 DP(NETIF_MSG_LINK, "line_speed %x duplex %x flow_ctrl 0x%x\n",
5051 vars->line_speed, vars->duplex, vars->flow_ctrl);
5052}
5053
Yaniv Rosnere10bc842010-09-07 11:40:50 +00005054static void bnx2x_set_master_ln(struct link_params *params,
5055 struct bnx2x_phy *phy)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005056{
5057 struct bnx2x *bp = params->bp;
5058 u16 new_master_ln, ser_lane;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005059 ser_lane = ((params->lane_config &
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005060 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_MASK) >>
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005061 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_SHIFT);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005062
Yuval Mintzd2310232012-06-20 19:05:19 +00005063 /* Set the master_ln for AN */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005064 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005065 MDIO_REG_BANK_XGXS_BLOCK2,
5066 MDIO_XGXS_BLOCK2_TEST_MODE_LANE,
5067 &new_master_ln);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005068
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005069 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005070 MDIO_REG_BANK_XGXS_BLOCK2 ,
5071 MDIO_XGXS_BLOCK2_TEST_MODE_LANE,
5072 (new_master_ln | ser_lane));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005073}
5074
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00005075static int bnx2x_reset_unicore(struct link_params *params,
5076 struct bnx2x_phy *phy,
5077 u8 set_serdes)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005078{
5079 struct bnx2x *bp = params->bp;
5080 u16 mii_control;
5081 u16 i;
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005082 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005083 MDIO_REG_BANK_COMBO_IEEE0,
5084 MDIO_COMBO_IEEE0_MII_CONTROL, &mii_control);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005085
Yuval Mintzd2310232012-06-20 19:05:19 +00005086 /* Reset the unicore */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005087 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005088 MDIO_REG_BANK_COMBO_IEEE0,
5089 MDIO_COMBO_IEEE0_MII_CONTROL,
5090 (mii_control |
5091 MDIO_COMBO_IEEO_MII_CONTROL_RESET));
Yaniv Rosnere10bc842010-09-07 11:40:50 +00005092 if (set_serdes)
5093 bnx2x_set_serdes_access(bp, params->port);
Eilon Greensteinc1b73992009-02-12 08:37:07 +00005094
Yuval Mintzd2310232012-06-20 19:05:19 +00005095 /* Wait for the reset to self clear */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005096 for (i = 0; i < MDIO_ACCESS_TIMEOUT; i++) {
5097 udelay(5);
5098
Yuval Mintzd2310232012-06-20 19:05:19 +00005099 /* The reset erased the previous bank value */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005100 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005101 MDIO_REG_BANK_COMBO_IEEE0,
5102 MDIO_COMBO_IEEE0_MII_CONTROL,
5103 &mii_control);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005104
5105 if (!(mii_control & MDIO_COMBO_IEEO_MII_CONTROL_RESET)) {
5106 udelay(5);
5107 return 0;
5108 }
5109 }
5110
Yaniv Rosner6d870c32011-01-31 04:22:20 +00005111 netdev_err(bp->dev, "Warning: PHY was not initialized,"
5112 " Port %d\n",
5113 params->port);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005114 DP(NETIF_MSG_LINK, "BUG! XGXS is still in reset!\n");
5115 return -EINVAL;
5116
5117}
5118
Yaniv Rosnere10bc842010-09-07 11:40:50 +00005119static void bnx2x_set_swap_lanes(struct link_params *params,
5120 struct bnx2x_phy *phy)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005121{
5122 struct bnx2x *bp = params->bp;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00005123 /* Each two bits represents a lane number:
5124 * No swap is 0123 => 0x1b no need to enable the swap
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005125 */
Yaniv Rosner2f751a82011-11-28 00:49:52 +00005126 u16 rx_lane_swap, tx_lane_swap;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005127
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005128 rx_lane_swap = ((params->lane_config &
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005129 PORT_HW_CFG_LANE_SWAP_CFG_RX_MASK) >>
5130 PORT_HW_CFG_LANE_SWAP_CFG_RX_SHIFT);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005131 tx_lane_swap = ((params->lane_config &
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005132 PORT_HW_CFG_LANE_SWAP_CFG_TX_MASK) >>
5133 PORT_HW_CFG_LANE_SWAP_CFG_TX_SHIFT);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005134
5135 if (rx_lane_swap != 0x1b) {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005136 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005137 MDIO_REG_BANK_XGXS_BLOCK2,
5138 MDIO_XGXS_BLOCK2_RX_LN_SWAP,
5139 (rx_lane_swap |
5140 MDIO_XGXS_BLOCK2_RX_LN_SWAP_ENABLE |
5141 MDIO_XGXS_BLOCK2_RX_LN_SWAP_FORCE_ENABLE));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005142 } else {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005143 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005144 MDIO_REG_BANK_XGXS_BLOCK2,
5145 MDIO_XGXS_BLOCK2_RX_LN_SWAP, 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005146 }
5147
5148 if (tx_lane_swap != 0x1b) {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005149 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005150 MDIO_REG_BANK_XGXS_BLOCK2,
5151 MDIO_XGXS_BLOCK2_TX_LN_SWAP,
5152 (tx_lane_swap |
5153 MDIO_XGXS_BLOCK2_TX_LN_SWAP_ENABLE));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005154 } else {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005155 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005156 MDIO_REG_BANK_XGXS_BLOCK2,
5157 MDIO_XGXS_BLOCK2_TX_LN_SWAP, 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005158 }
5159}
5160
Yaniv Rosnere10bc842010-09-07 11:40:50 +00005161static void bnx2x_set_parallel_detection(struct bnx2x_phy *phy,
5162 struct link_params *params)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005163{
5164 struct bnx2x *bp = params->bp;
5165 u16 control2;
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005166 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005167 MDIO_REG_BANK_SERDES_DIGITAL,
5168 MDIO_SERDES_DIGITAL_A_1000X_CONTROL2,
5169 &control2);
Yaniv Rosner7aa07112010-09-07 11:41:01 +00005170 if (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)
Yaniv Rosner18afb0a2009-11-05 19:18:04 +02005171 control2 |= MDIO_SERDES_DIGITAL_A_1000X_CONTROL2_PRL_DT_EN;
5172 else
5173 control2 &= ~MDIO_SERDES_DIGITAL_A_1000X_CONTROL2_PRL_DT_EN;
Yaniv Rosner7aa07112010-09-07 11:41:01 +00005174 DP(NETIF_MSG_LINK, "phy->speed_cap_mask = 0x%x, control2 = 0x%x\n",
5175 phy->speed_cap_mask, control2);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005176 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005177 MDIO_REG_BANK_SERDES_DIGITAL,
5178 MDIO_SERDES_DIGITAL_A_1000X_CONTROL2,
5179 control2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005180
Yaniv Rosnere10bc842010-09-07 11:40:50 +00005181 if ((phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT) &&
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00005182 (phy->speed_cap_mask &
Yaniv Rosner18afb0a2009-11-05 19:18:04 +02005183 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005184 DP(NETIF_MSG_LINK, "XGXS\n");
5185
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005186 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005187 MDIO_REG_BANK_10G_PARALLEL_DETECT,
5188 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_LINK,
5189 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_LINK_CNT);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005190
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005191 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005192 MDIO_REG_BANK_10G_PARALLEL_DETECT,
5193 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_CONTROL,
5194 &control2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005195
5196
5197 control2 |=
5198 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_CONTROL_PARDET10G_EN;
5199
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005200 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005201 MDIO_REG_BANK_10G_PARALLEL_DETECT,
5202 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_CONTROL,
5203 control2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005204
5205 /* Disable parallel detection of HiG */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005206 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005207 MDIO_REG_BANK_XGXS_BLOCK2,
5208 MDIO_XGXS_BLOCK2_UNICORE_MODE_10G,
5209 MDIO_XGXS_BLOCK2_UNICORE_MODE_10G_CX4_XGXS |
5210 MDIO_XGXS_BLOCK2_UNICORE_MODE_10G_HIGIG_XGXS);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005211 }
5212}
5213
Yaniv Rosnere10bc842010-09-07 11:40:50 +00005214static void bnx2x_set_autoneg(struct bnx2x_phy *phy,
5215 struct link_params *params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005216 struct link_vars *vars,
5217 u8 enable_cl73)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005218{
5219 struct bnx2x *bp = params->bp;
5220 u16 reg_val;
5221
5222 /* CL37 Autoneg */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005223 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005224 MDIO_REG_BANK_COMBO_IEEE0,
5225 MDIO_COMBO_IEEE0_MII_CONTROL, &reg_val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005226
5227 /* CL37 Autoneg Enabled */
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07005228 if (vars->line_speed == SPEED_AUTO_NEG)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005229 reg_val |= MDIO_COMBO_IEEO_MII_CONTROL_AN_EN;
5230 else /* CL37 Autoneg Disabled */
5231 reg_val &= ~(MDIO_COMBO_IEEO_MII_CONTROL_AN_EN |
5232 MDIO_COMBO_IEEO_MII_CONTROL_RESTART_AN);
5233
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005234 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005235 MDIO_REG_BANK_COMBO_IEEE0,
5236 MDIO_COMBO_IEEE0_MII_CONTROL, reg_val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005237
5238 /* Enable/Disable Autodetection */
5239
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005240 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005241 MDIO_REG_BANK_SERDES_DIGITAL,
5242 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1, &reg_val);
Eilon Greenstein239d6862009-08-12 08:23:04 +00005243 reg_val &= ~(MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_SIGNAL_DETECT_EN |
5244 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_INVERT_SIGNAL_DETECT);
5245 reg_val |= MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_FIBER_MODE;
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07005246 if (vars->line_speed == SPEED_AUTO_NEG)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005247 reg_val |= MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_AUTODET;
5248 else
5249 reg_val &= ~MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_AUTODET;
5250
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005251 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005252 MDIO_REG_BANK_SERDES_DIGITAL,
5253 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1, reg_val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005254
5255 /* Enable TetonII and BAM autoneg */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005256 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005257 MDIO_REG_BANK_BAM_NEXT_PAGE,
5258 MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL,
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005259 &reg_val);
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07005260 if (vars->line_speed == SPEED_AUTO_NEG) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005261 /* Enable BAM aneg Mode and TetonII aneg Mode */
5262 reg_val |= (MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL_BAM_MODE |
5263 MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL_TETON_AN);
5264 } else {
5265 /* TetonII and BAM Autoneg Disabled */
5266 reg_val &= ~(MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL_BAM_MODE |
5267 MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL_TETON_AN);
5268 }
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005269 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005270 MDIO_REG_BANK_BAM_NEXT_PAGE,
5271 MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL,
5272 reg_val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005273
Eilon Greenstein239d6862009-08-12 08:23:04 +00005274 if (enable_cl73) {
5275 /* Enable Cl73 FSM status bits */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005276 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005277 MDIO_REG_BANK_CL73_USERB0,
5278 MDIO_CL73_USERB0_CL73_UCTRL,
5279 0xe);
Eilon Greenstein239d6862009-08-12 08:23:04 +00005280
5281 /* Enable BAM Station Manager*/
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005282 CL22_WR_OVER_CL45(bp, phy,
Eilon Greenstein239d6862009-08-12 08:23:04 +00005283 MDIO_REG_BANK_CL73_USERB0,
5284 MDIO_CL73_USERB0_CL73_BAM_CTRL1,
5285 MDIO_CL73_USERB0_CL73_BAM_CTRL1_BAM_EN |
5286 MDIO_CL73_USERB0_CL73_BAM_CTRL1_BAM_STATION_MNGR_EN |
5287 MDIO_CL73_USERB0_CL73_BAM_CTRL1_BAM_NP_AFTER_BP_EN);
5288
Yaniv Rosner7846e472009-11-05 19:18:07 +02005289 /* Advertise CL73 link speeds */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005290 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005291 MDIO_REG_BANK_CL73_IEEEB1,
5292 MDIO_CL73_IEEEB1_AN_ADV2,
5293 &reg_val);
Yaniv Rosner7aa07112010-09-07 11:41:01 +00005294 if (phy->speed_cap_mask &
Yaniv Rosner7846e472009-11-05 19:18:07 +02005295 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
5296 reg_val |= MDIO_CL73_IEEEB1_AN_ADV2_ADVR_10G_KX4;
Yaniv Rosner7aa07112010-09-07 11:41:01 +00005297 if (phy->speed_cap_mask &
Yaniv Rosner7846e472009-11-05 19:18:07 +02005298 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)
5299 reg_val |= MDIO_CL73_IEEEB1_AN_ADV2_ADVR_1000M_KX;
Eilon Greenstein239d6862009-08-12 08:23:04 +00005300
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005301 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005302 MDIO_REG_BANK_CL73_IEEEB1,
5303 MDIO_CL73_IEEEB1_AN_ADV2,
5304 reg_val);
Eilon Greenstein239d6862009-08-12 08:23:04 +00005305
Eilon Greenstein239d6862009-08-12 08:23:04 +00005306 /* CL73 Autoneg Enabled */
5307 reg_val = MDIO_CL73_IEEEB0_CL73_AN_CONTROL_AN_EN;
5308
5309 } else /* CL73 Autoneg Disabled */
5310 reg_val = 0;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005311
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005312 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005313 MDIO_REG_BANK_CL73_IEEEB0,
5314 MDIO_CL73_IEEEB0_CL73_AN_CONTROL, reg_val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005315}
5316
Yuval Mintzd2310232012-06-20 19:05:19 +00005317/* Program SerDes, forced speed */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00005318static void bnx2x_program_serdes(struct bnx2x_phy *phy,
5319 struct link_params *params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005320 struct link_vars *vars)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005321{
5322 struct bnx2x *bp = params->bp;
5323 u16 reg_val;
5324
Yuval Mintzd2310232012-06-20 19:05:19 +00005325 /* Program duplex, disable autoneg and sgmii*/
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005326 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005327 MDIO_REG_BANK_COMBO_IEEE0,
5328 MDIO_COMBO_IEEE0_MII_CONTROL, &reg_val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005329 reg_val &= ~(MDIO_COMBO_IEEO_MII_CONTROL_FULL_DUPLEX |
Eilon Greenstein57937202009-08-12 08:23:53 +00005330 MDIO_COMBO_IEEO_MII_CONTROL_AN_EN |
5331 MDIO_COMBO_IEEO_MII_CONTROL_MAN_SGMII_SP_MASK);
Yaniv Rosner7aa07112010-09-07 11:41:01 +00005332 if (phy->req_duplex == DUPLEX_FULL)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005333 reg_val |= MDIO_COMBO_IEEO_MII_CONTROL_FULL_DUPLEX;
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005334 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005335 MDIO_REG_BANK_COMBO_IEEE0,
5336 MDIO_COMBO_IEEE0_MII_CONTROL, reg_val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005337
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00005338 /* Program speed
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005339 * - needed only if the speed is greater than 1G (2.5G or 10G)
5340 */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005341 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005342 MDIO_REG_BANK_SERDES_DIGITAL,
5343 MDIO_SERDES_DIGITAL_MISC1, &reg_val);
Yuval Mintzd2310232012-06-20 19:05:19 +00005344 /* Clearing the speed value before setting the right speed */
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07005345 DP(NETIF_MSG_LINK, "MDIO_REG_BANK_SERDES_DIGITAL = 0x%x\n", reg_val);
5346
5347 reg_val &= ~(MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_MASK |
5348 MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_SEL);
5349
5350 if (!((vars->line_speed == SPEED_1000) ||
5351 (vars->line_speed == SPEED_100) ||
5352 (vars->line_speed == SPEED_10))) {
5353
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005354 reg_val |= (MDIO_SERDES_DIGITAL_MISC1_REFCLK_SEL_156_25M |
5355 MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_SEL);
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07005356 if (vars->line_speed == SPEED_10000)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005357 reg_val |=
5358 MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_10G_CX4;
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07005359 }
5360
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005361 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005362 MDIO_REG_BANK_SERDES_DIGITAL,
5363 MDIO_SERDES_DIGITAL_MISC1, reg_val);
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07005364
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005365}
5366
Yaniv Rosner9045f6b42011-05-31 21:28:27 +00005367static void bnx2x_set_brcm_cl37_advertisement(struct bnx2x_phy *phy,
5368 struct link_params *params)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005369{
5370 struct bnx2x *bp = params->bp;
5371 u16 val = 0;
5372
Yuval Mintzd2310232012-06-20 19:05:19 +00005373 /* Set extended capabilities */
Yaniv Rosner7aa07112010-09-07 11:41:01 +00005374 if (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005375 val |= MDIO_OVER_1G_UP1_2_5G;
Yaniv Rosner7aa07112010-09-07 11:41:01 +00005376 if (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005377 val |= MDIO_OVER_1G_UP1_10G;
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005378 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005379 MDIO_REG_BANK_OVER_1G,
5380 MDIO_OVER_1G_UP1, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005381
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005382 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005383 MDIO_REG_BANK_OVER_1G,
5384 MDIO_OVER_1G_UP3, 0x400);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005385}
5386
Yaniv Rosner9045f6b42011-05-31 21:28:27 +00005387static void bnx2x_set_ieee_aneg_advertisement(struct bnx2x_phy *phy,
5388 struct link_params *params,
5389 u16 ieee_fc)
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07005390{
5391 struct bnx2x *bp = params->bp;
Yaniv Rosner7846e472009-11-05 19:18:07 +02005392 u16 val;
Yuval Mintzd2310232012-06-20 19:05:19 +00005393 /* For AN, we are always publishing full duplex */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005394
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005395 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005396 MDIO_REG_BANK_COMBO_IEEE0,
5397 MDIO_COMBO_IEEE0_AUTO_NEG_ADV, ieee_fc);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005398 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005399 MDIO_REG_BANK_CL73_IEEEB1,
5400 MDIO_CL73_IEEEB1_AN_ADV1, &val);
Yaniv Rosner7846e472009-11-05 19:18:07 +02005401 val &= ~MDIO_CL73_IEEEB1_AN_ADV1_PAUSE_BOTH;
5402 val |= ((ieee_fc<<3) & MDIO_CL73_IEEEB1_AN_ADV1_PAUSE_MASK);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005403 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005404 MDIO_REG_BANK_CL73_IEEEB1,
5405 MDIO_CL73_IEEEB1_AN_ADV1, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005406}
5407
Yaniv Rosnere10bc842010-09-07 11:40:50 +00005408static void bnx2x_restart_autoneg(struct bnx2x_phy *phy,
5409 struct link_params *params,
5410 u8 enable_cl73)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005411{
5412 struct bnx2x *bp = params->bp;
Eilon Greenstein3a36f2e2009-02-12 08:37:09 +00005413 u16 mii_control;
Eilon Greenstein239d6862009-08-12 08:23:04 +00005414
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005415 DP(NETIF_MSG_LINK, "bnx2x_restart_autoneg\n");
Eilon Greenstein3a36f2e2009-02-12 08:37:09 +00005416 /* Enable and restart BAM/CL37 aneg */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005417
Eilon Greenstein239d6862009-08-12 08:23:04 +00005418 if (enable_cl73) {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005419 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005420 MDIO_REG_BANK_CL73_IEEEB0,
5421 MDIO_CL73_IEEEB0_CL73_AN_CONTROL,
5422 &mii_control);
Eilon Greenstein239d6862009-08-12 08:23:04 +00005423
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005424 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005425 MDIO_REG_BANK_CL73_IEEEB0,
5426 MDIO_CL73_IEEEB0_CL73_AN_CONTROL,
5427 (mii_control |
5428 MDIO_CL73_IEEEB0_CL73_AN_CONTROL_AN_EN |
5429 MDIO_CL73_IEEEB0_CL73_AN_CONTROL_RESTART_AN));
Eilon Greenstein239d6862009-08-12 08:23:04 +00005430 } else {
5431
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005432 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005433 MDIO_REG_BANK_COMBO_IEEE0,
5434 MDIO_COMBO_IEEE0_MII_CONTROL,
5435 &mii_control);
Eilon Greenstein239d6862009-08-12 08:23:04 +00005436 DP(NETIF_MSG_LINK,
5437 "bnx2x_restart_autoneg mii_control before = 0x%x\n",
5438 mii_control);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005439 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005440 MDIO_REG_BANK_COMBO_IEEE0,
5441 MDIO_COMBO_IEEE0_MII_CONTROL,
5442 (mii_control |
5443 MDIO_COMBO_IEEO_MII_CONTROL_AN_EN |
5444 MDIO_COMBO_IEEO_MII_CONTROL_RESTART_AN));
Eilon Greenstein239d6862009-08-12 08:23:04 +00005445 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005446}
5447
Yaniv Rosnere10bc842010-09-07 11:40:50 +00005448static void bnx2x_initialize_sgmii_process(struct bnx2x_phy *phy,
5449 struct link_params *params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005450 struct link_vars *vars)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005451{
5452 struct bnx2x *bp = params->bp;
5453 u16 control1;
5454
Yuval Mintzd2310232012-06-20 19:05:19 +00005455 /* In SGMII mode, the unicore is always slave */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005456
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005457 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005458 MDIO_REG_BANK_SERDES_DIGITAL,
5459 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1,
5460 &control1);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005461 control1 |= MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_INVERT_SIGNAL_DETECT;
Yuval Mintzd2310232012-06-20 19:05:19 +00005462 /* Set sgmii mode (and not fiber) */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005463 control1 &= ~(MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_FIBER_MODE |
5464 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_AUTODET |
5465 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_MSTR_MODE);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005466 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005467 MDIO_REG_BANK_SERDES_DIGITAL,
5468 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1,
5469 control1);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005470
Yuval Mintzd2310232012-06-20 19:05:19 +00005471 /* If forced speed */
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07005472 if (!(vars->line_speed == SPEED_AUTO_NEG)) {
Yuval Mintzd2310232012-06-20 19:05:19 +00005473 /* Set speed, disable autoneg */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005474 u16 mii_control;
5475
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005476 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005477 MDIO_REG_BANK_COMBO_IEEE0,
5478 MDIO_COMBO_IEEE0_MII_CONTROL,
5479 &mii_control);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005480 mii_control &= ~(MDIO_COMBO_IEEO_MII_CONTROL_AN_EN |
5481 MDIO_COMBO_IEEO_MII_CONTROL_MAN_SGMII_SP_MASK|
5482 MDIO_COMBO_IEEO_MII_CONTROL_FULL_DUPLEX);
5483
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07005484 switch (vars->line_speed) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005485 case SPEED_100:
5486 mii_control |=
5487 MDIO_COMBO_IEEO_MII_CONTROL_MAN_SGMII_SP_100;
5488 break;
5489 case SPEED_1000:
5490 mii_control |=
5491 MDIO_COMBO_IEEO_MII_CONTROL_MAN_SGMII_SP_1000;
5492 break;
5493 case SPEED_10:
Yuval Mintzd2310232012-06-20 19:05:19 +00005494 /* There is nothing to set for 10M */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005495 break;
5496 default:
Yuval Mintzd2310232012-06-20 19:05:19 +00005497 /* Invalid speed for SGMII */
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07005498 DP(NETIF_MSG_LINK, "Invalid line_speed 0x%x\n",
5499 vars->line_speed);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005500 break;
5501 }
5502
Yuval Mintzd2310232012-06-20 19:05:19 +00005503 /* Setting the full duplex */
Yaniv Rosner7aa07112010-09-07 11:41:01 +00005504 if (phy->req_duplex == DUPLEX_FULL)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005505 mii_control |=
5506 MDIO_COMBO_IEEO_MII_CONTROL_FULL_DUPLEX;
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005507 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005508 MDIO_REG_BANK_COMBO_IEEE0,
5509 MDIO_COMBO_IEEE0_MII_CONTROL,
5510 mii_control);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005511
5512 } else { /* AN mode */
Yuval Mintzd2310232012-06-20 19:05:19 +00005513 /* Enable and restart AN */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00005514 bnx2x_restart_autoneg(phy, params, 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005515 }
5516}
5517
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00005518/* Link management
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005519 */
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00005520static int bnx2x_direct_parallel_detect_used(struct bnx2x_phy *phy,
5521 struct link_params *params)
Yaniv Rosner15ddd2d2009-11-05 19:18:12 +02005522{
5523 struct bnx2x *bp = params->bp;
5524 u16 pd_10g, status2_1000x;
Yaniv Rosner7aa07112010-09-07 11:41:01 +00005525 if (phy->req_line_speed != SPEED_AUTO_NEG)
5526 return 0;
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005527 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005528 MDIO_REG_BANK_SERDES_DIGITAL,
5529 MDIO_SERDES_DIGITAL_A_1000X_STATUS2,
5530 &status2_1000x);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005531 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005532 MDIO_REG_BANK_SERDES_DIGITAL,
5533 MDIO_SERDES_DIGITAL_A_1000X_STATUS2,
5534 &status2_1000x);
Yaniv Rosner15ddd2d2009-11-05 19:18:12 +02005535 if (status2_1000x & MDIO_SERDES_DIGITAL_A_1000X_STATUS2_AN_DISABLED) {
5536 DP(NETIF_MSG_LINK, "1G parallel detect link on port %d\n",
5537 params->port);
5538 return 1;
5539 }
5540
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005541 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005542 MDIO_REG_BANK_10G_PARALLEL_DETECT,
5543 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_STATUS,
5544 &pd_10g);
Yaniv Rosner15ddd2d2009-11-05 19:18:12 +02005545
5546 if (pd_10g & MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_STATUS_PD_LINK) {
5547 DP(NETIF_MSG_LINK, "10G parallel detect link on port %d\n",
5548 params->port);
5549 return 1;
5550 }
5551 return 0;
5552}
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005553
Mintz Yuval9e7e8392012-02-15 02:10:24 +00005554static void bnx2x_update_adv_fc(struct bnx2x_phy *phy,
5555 struct link_params *params,
5556 struct link_vars *vars,
5557 u32 gp_status)
5558{
5559 u16 ld_pause; /* local driver */
5560 u16 lp_pause; /* link partner */
5561 u16 pause_result;
5562 struct bnx2x *bp = params->bp;
5563 if ((gp_status &
5564 (MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_AUTONEG_COMPLETE |
5565 MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_MR_LP_NP_AN_ABLE)) ==
5566 (MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_AUTONEG_COMPLETE |
5567 MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_MR_LP_NP_AN_ABLE)) {
5568
5569 CL22_RD_OVER_CL45(bp, phy,
5570 MDIO_REG_BANK_CL73_IEEEB1,
5571 MDIO_CL73_IEEEB1_AN_ADV1,
5572 &ld_pause);
5573 CL22_RD_OVER_CL45(bp, phy,
5574 MDIO_REG_BANK_CL73_IEEEB1,
5575 MDIO_CL73_IEEEB1_AN_LP_ADV1,
5576 &lp_pause);
5577 pause_result = (ld_pause &
5578 MDIO_CL73_IEEEB1_AN_ADV1_PAUSE_MASK) >> 8;
5579 pause_result |= (lp_pause &
5580 MDIO_CL73_IEEEB1_AN_LP_ADV1_PAUSE_MASK) >> 10;
5581 DP(NETIF_MSG_LINK, "pause_result CL73 0x%x\n", pause_result);
5582 } else {
5583 CL22_RD_OVER_CL45(bp, phy,
5584 MDIO_REG_BANK_COMBO_IEEE0,
5585 MDIO_COMBO_IEEE0_AUTO_NEG_ADV,
5586 &ld_pause);
5587 CL22_RD_OVER_CL45(bp, phy,
5588 MDIO_REG_BANK_COMBO_IEEE0,
5589 MDIO_COMBO_IEEE0_AUTO_NEG_LINK_PARTNER_ABILITY1,
5590 &lp_pause);
5591 pause_result = (ld_pause &
5592 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK)>>5;
5593 pause_result |= (lp_pause &
5594 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK)>>7;
5595 DP(NETIF_MSG_LINK, "pause_result CL37 0x%x\n", pause_result);
5596 }
5597 bnx2x_pause_resolve(vars, pause_result);
5598
5599}
5600
Yaniv Rosnere10bc842010-09-07 11:40:50 +00005601static void bnx2x_flow_ctrl_resolve(struct bnx2x_phy *phy,
5602 struct link_params *params,
5603 struct link_vars *vars,
5604 u32 gp_status)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005605{
5606 struct bnx2x *bp = params->bp;
David S. Millerc0700f92008-12-16 23:53:20 -08005607 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005608
Yuval Mintzd2310232012-06-20 19:05:19 +00005609 /* Resolve from gp_status in case of AN complete and not sgmii */
Mintz Yuval9e7e8392012-02-15 02:10:24 +00005610 if (phy->req_flow_ctrl != BNX2X_FLOW_CTRL_AUTO) {
5611 /* Update the advertised flow-controled of LD/LP in AN */
5612 if (phy->req_line_speed == SPEED_AUTO_NEG)
5613 bnx2x_update_adv_fc(phy, params, vars, gp_status);
5614 /* But set the flow-control result as the requested one */
Yaniv Rosner7aa07112010-09-07 11:41:01 +00005615 vars->flow_ctrl = phy->req_flow_ctrl;
Mintz Yuval9e7e8392012-02-15 02:10:24 +00005616 } else if (phy->req_line_speed != SPEED_AUTO_NEG)
Yaniv Rosner7aa07112010-09-07 11:41:01 +00005617 vars->flow_ctrl = params->req_fc_auto_adv;
5618 else if ((gp_status & MDIO_AN_CL73_OR_37_COMPLETE) &&
5619 (!(vars->phy_flags & PHY_SGMII_FLAG))) {
Yaniv Rosnere10bc842010-09-07 11:40:50 +00005620 if (bnx2x_direct_parallel_detect_used(phy, params)) {
Yaniv Rosner15ddd2d2009-11-05 19:18:12 +02005621 vars->flow_ctrl = params->req_fc_auto_adv;
5622 return;
5623 }
Mintz Yuval9e7e8392012-02-15 02:10:24 +00005624 bnx2x_update_adv_fc(phy, params, vars, gp_status);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005625 }
5626 DP(NETIF_MSG_LINK, "flow_ctrl 0x%x\n", vars->flow_ctrl);
5627}
5628
Yaniv Rosnere10bc842010-09-07 11:40:50 +00005629static void bnx2x_check_fallback_to_cl37(struct bnx2x_phy *phy,
5630 struct link_params *params)
Eilon Greenstein239d6862009-08-12 08:23:04 +00005631{
5632 struct bnx2x *bp = params->bp;
Yaniv Rosner9045f6b42011-05-31 21:28:27 +00005633 u16 rx_status, ustat_val, cl37_fsm_received;
Eilon Greenstein239d6862009-08-12 08:23:04 +00005634 DP(NETIF_MSG_LINK, "bnx2x_check_fallback_to_cl37\n");
5635 /* Step 1: Make sure signal is detected */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005636 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005637 MDIO_REG_BANK_RX0,
5638 MDIO_RX0_RX_STATUS,
5639 &rx_status);
Eilon Greenstein239d6862009-08-12 08:23:04 +00005640 if ((rx_status & MDIO_RX0_RX_STATUS_SIGDET) !=
5641 (MDIO_RX0_RX_STATUS_SIGDET)) {
5642 DP(NETIF_MSG_LINK, "Signal is not detected. Restoring CL73."
5643 "rx_status(0x80b0) = 0x%x\n", rx_status);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005644 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005645 MDIO_REG_BANK_CL73_IEEEB0,
5646 MDIO_CL73_IEEEB0_CL73_AN_CONTROL,
5647 MDIO_CL73_IEEEB0_CL73_AN_CONTROL_AN_EN);
Eilon Greenstein239d6862009-08-12 08:23:04 +00005648 return;
5649 }
5650 /* Step 2: Check CL73 state machine */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005651 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005652 MDIO_REG_BANK_CL73_USERB0,
5653 MDIO_CL73_USERB0_CL73_USTAT1,
5654 &ustat_val);
Eilon Greenstein239d6862009-08-12 08:23:04 +00005655 if ((ustat_val &
5656 (MDIO_CL73_USERB0_CL73_USTAT1_LINK_STATUS_CHECK |
5657 MDIO_CL73_USERB0_CL73_USTAT1_AN_GOOD_CHECK_BAM37)) !=
5658 (MDIO_CL73_USERB0_CL73_USTAT1_LINK_STATUS_CHECK |
5659 MDIO_CL73_USERB0_CL73_USTAT1_AN_GOOD_CHECK_BAM37)) {
5660 DP(NETIF_MSG_LINK, "CL73 state-machine is not stable. "
5661 "ustat_val(0x8371) = 0x%x\n", ustat_val);
5662 return;
5663 }
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00005664 /* Step 3: Check CL37 Message Pages received to indicate LP
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005665 * supports only CL37
5666 */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005667 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005668 MDIO_REG_BANK_REMOTE_PHY,
5669 MDIO_REMOTE_PHY_MISC_RX_STATUS,
Yaniv Rosner9045f6b42011-05-31 21:28:27 +00005670 &cl37_fsm_received);
5671 if ((cl37_fsm_received &
Eilon Greenstein239d6862009-08-12 08:23:04 +00005672 (MDIO_REMOTE_PHY_MISC_RX_STATUS_CL37_FSM_RECEIVED_OVER1G_MSG |
5673 MDIO_REMOTE_PHY_MISC_RX_STATUS_CL37_FSM_RECEIVED_BRCM_OUI_MSG)) !=
5674 (MDIO_REMOTE_PHY_MISC_RX_STATUS_CL37_FSM_RECEIVED_OVER1G_MSG |
5675 MDIO_REMOTE_PHY_MISC_RX_STATUS_CL37_FSM_RECEIVED_BRCM_OUI_MSG)) {
5676 DP(NETIF_MSG_LINK, "No CL37 FSM were received. "
5677 "misc_rx_status(0x8330) = 0x%x\n",
Yaniv Rosner9045f6b42011-05-31 21:28:27 +00005678 cl37_fsm_received);
Eilon Greenstein239d6862009-08-12 08:23:04 +00005679 return;
5680 }
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00005681 /* The combined cl37/cl73 fsm state information indicating that
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005682 * we are connected to a device which does not support cl73, but
5683 * does support cl37 BAM. In this case we disable cl73 and
5684 * restart cl37 auto-neg
5685 */
5686
Eilon Greenstein239d6862009-08-12 08:23:04 +00005687 /* Disable CL73 */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005688 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005689 MDIO_REG_BANK_CL73_IEEEB0,
5690 MDIO_CL73_IEEEB0_CL73_AN_CONTROL,
5691 0);
Eilon Greenstein239d6862009-08-12 08:23:04 +00005692 /* Restart CL37 autoneg */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00005693 bnx2x_restart_autoneg(phy, params, 0);
Eilon Greenstein239d6862009-08-12 08:23:04 +00005694 DP(NETIF_MSG_LINK, "Disabling CL73, and restarting CL37 autoneg\n");
5695}
Yaniv Rosner7aa07112010-09-07 11:41:01 +00005696
5697static void bnx2x_xgxs_an_resolve(struct bnx2x_phy *phy,
5698 struct link_params *params,
5699 struct link_vars *vars,
5700 u32 gp_status)
5701{
5702 if (gp_status & MDIO_AN_CL73_OR_37_COMPLETE)
5703 vars->link_status |=
5704 LINK_STATUS_AUTO_NEGOTIATE_COMPLETE;
5705
5706 if (bnx2x_direct_parallel_detect_used(phy, params))
5707 vars->link_status |=
5708 LINK_STATUS_PARALLEL_DETECTION_USED;
5709}
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005710static int bnx2x_get_link_speed_duplex(struct bnx2x_phy *phy,
5711 struct link_params *params,
5712 struct link_vars *vars,
5713 u16 is_link_up,
5714 u16 speed_mask,
5715 u16 is_duplex)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005716{
5717 struct bnx2x *bp = params->bp;
Yaniv Rosner7aa07112010-09-07 11:41:01 +00005718 if (phy->req_line_speed == SPEED_AUTO_NEG)
5719 vars->link_status |= LINK_STATUS_AUTO_NEGOTIATE_ENABLED;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005720 if (is_link_up) {
5721 DP(NETIF_MSG_LINK, "phy link up\n");
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005722
5723 vars->phy_link_up = 1;
5724 vars->link_status |= LINK_STATUS_LINK_UP;
5725
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005726 switch (speed_mask) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005727 case GP_STATUS_10M:
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005728 vars->line_speed = SPEED_10;
Yaniv Rosner430d1722012-09-11 04:34:11 +00005729 if (is_duplex == DUPLEX_FULL)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005730 vars->link_status |= LINK_10TFD;
5731 else
5732 vars->link_status |= LINK_10THD;
5733 break;
5734
5735 case GP_STATUS_100M:
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005736 vars->line_speed = SPEED_100;
Yaniv Rosner430d1722012-09-11 04:34:11 +00005737 if (is_duplex == DUPLEX_FULL)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005738 vars->link_status |= LINK_100TXFD;
5739 else
5740 vars->link_status |= LINK_100TXHD;
5741 break;
5742
5743 case GP_STATUS_1G:
5744 case GP_STATUS_1G_KX:
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005745 vars->line_speed = SPEED_1000;
Yaniv Rosner430d1722012-09-11 04:34:11 +00005746 if (is_duplex == DUPLEX_FULL)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005747 vars->link_status |= LINK_1000TFD;
5748 else
5749 vars->link_status |= LINK_1000THD;
5750 break;
5751
5752 case GP_STATUS_2_5G:
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005753 vars->line_speed = SPEED_2500;
Yaniv Rosner430d1722012-09-11 04:34:11 +00005754 if (is_duplex == DUPLEX_FULL)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005755 vars->link_status |= LINK_2500TFD;
5756 else
5757 vars->link_status |= LINK_2500THD;
5758 break;
5759
5760 case GP_STATUS_5G:
5761 case GP_STATUS_6G:
5762 DP(NETIF_MSG_LINK,
5763 "link speed unsupported gp_status 0x%x\n",
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005764 speed_mask);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005765 return -EINVAL;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00005766
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005767 case GP_STATUS_10G_KX4:
5768 case GP_STATUS_10G_HIG:
5769 case GP_STATUS_10G_CX4:
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005770 case GP_STATUS_10G_KR:
5771 case GP_STATUS_10G_SFI:
5772 case GP_STATUS_10G_XFI:
5773 vars->line_speed = SPEED_10000;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005774 vars->link_status |= LINK_10GTFD;
5775 break;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005776 case GP_STATUS_20G_DXGXS:
5777 vars->line_speed = SPEED_20000;
5778 vars->link_status |= LINK_20GTFD;
5779 break;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005780 default:
5781 DP(NETIF_MSG_LINK,
5782 "link speed unsupported gp_status 0x%x\n",
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005783 speed_mask);
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00005784 return -EINVAL;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005785 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005786 } else { /* link_down */
5787 DP(NETIF_MSG_LINK, "phy link down\n");
5788
5789 vars->phy_link_up = 0;
Yaniv Rosner57963ed2008-08-13 15:55:28 -07005790
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005791 vars->duplex = DUPLEX_FULL;
David S. Millerc0700f92008-12-16 23:53:20 -08005792 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005793 vars->mac_type = MAC_TYPE_NONE;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005794 }
5795 DP(NETIF_MSG_LINK, " phy_link_up %x line_speed %d\n",
5796 vars->phy_link_up, vars->line_speed);
5797 return 0;
5798}
Eilon Greenstein239d6862009-08-12 08:23:04 +00005799
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005800static int bnx2x_link_settings_status(struct bnx2x_phy *phy,
5801 struct link_params *params,
5802 struct link_vars *vars)
5803{
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005804 struct bnx2x *bp = params->bp;
5805
5806 u16 gp_status, duplex = DUPLEX_HALF, link_up = 0, speed_mask;
5807 int rc = 0;
5808
5809 /* Read gp_status */
5810 CL22_RD_OVER_CL45(bp, phy,
5811 MDIO_REG_BANK_GP_STATUS,
5812 MDIO_GP_STATUS_TOP_AN_STATUS1,
5813 &gp_status);
5814 if (gp_status & MDIO_GP_STATUS_TOP_AN_STATUS1_DUPLEX_STATUS)
5815 duplex = DUPLEX_FULL;
5816 if (gp_status & MDIO_GP_STATUS_TOP_AN_STATUS1_LINK_STATUS)
5817 link_up = 1;
5818 speed_mask = gp_status & GP_STATUS_SPEED_MASK;
5819 DP(NETIF_MSG_LINK, "gp_status 0x%x, is_link_up %d, speed_mask 0x%x\n",
5820 gp_status, link_up, speed_mask);
5821 rc = bnx2x_get_link_speed_duplex(phy, params, vars, link_up, speed_mask,
5822 duplex);
5823 if (rc == -EINVAL)
5824 return rc;
5825
5826 if (gp_status & MDIO_GP_STATUS_TOP_AN_STATUS1_LINK_STATUS) {
5827 if (SINGLE_MEDIA_DIRECT(params)) {
Yaniv Rosner430d1722012-09-11 04:34:11 +00005828 vars->duplex = duplex;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005829 bnx2x_flow_ctrl_resolve(phy, params, vars, gp_status);
5830 if (phy->req_line_speed == SPEED_AUTO_NEG)
5831 bnx2x_xgxs_an_resolve(phy, params, vars,
5832 gp_status);
5833 }
Yuval Mintzd2310232012-06-20 19:05:19 +00005834 } else { /* Link_down */
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00005835 if ((phy->req_line_speed == SPEED_AUTO_NEG) &&
5836 SINGLE_MEDIA_DIRECT(params)) {
Eilon Greenstein239d6862009-08-12 08:23:04 +00005837 /* Check signal is detected */
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00005838 bnx2x_check_fallback_to_cl37(phy, params);
Eilon Greenstein239d6862009-08-12 08:23:04 +00005839 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005840 }
5841
Mintz Yuval9e7e8392012-02-15 02:10:24 +00005842 /* Read LP advertised speeds*/
5843 if (SINGLE_MEDIA_DIRECT(params) &&
5844 (vars->link_status & LINK_STATUS_AUTO_NEGOTIATE_COMPLETE)) {
5845 u16 val;
5846
5847 CL22_RD_OVER_CL45(bp, phy, MDIO_REG_BANK_CL73_IEEEB1,
5848 MDIO_CL73_IEEEB1_AN_LP_ADV2, &val);
5849
5850 if (val & MDIO_CL73_IEEEB1_AN_ADV2_ADVR_1000M_KX)
5851 vars->link_status |=
5852 LINK_STATUS_LINK_PARTNER_1000TFD_CAPABLE;
5853 if (val & (MDIO_CL73_IEEEB1_AN_ADV2_ADVR_10G_KX4 |
5854 MDIO_CL73_IEEEB1_AN_ADV2_ADVR_10G_KR))
5855 vars->link_status |=
5856 LINK_STATUS_LINK_PARTNER_10GXFD_CAPABLE;
5857
5858 CL22_RD_OVER_CL45(bp, phy, MDIO_REG_BANK_OVER_1G,
5859 MDIO_OVER_1G_LP_UP1, &val);
5860
5861 if (val & MDIO_OVER_1G_UP1_2_5G)
5862 vars->link_status |=
5863 LINK_STATUS_LINK_PARTNER_2500XFD_CAPABLE;
5864 if (val & (MDIO_OVER_1G_UP1_10G | MDIO_OVER_1G_UP1_10GH))
5865 vars->link_status |=
5866 LINK_STATUS_LINK_PARTNER_10GXFD_CAPABLE;
5867 }
5868
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005869 DP(NETIF_MSG_LINK, "duplex %x flow_ctrl 0x%x link_status 0x%x\n",
5870 vars->duplex, vars->flow_ctrl, vars->link_status);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005871 return rc;
5872}
5873
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005874static int bnx2x_warpcore_read_status(struct bnx2x_phy *phy,
5875 struct link_params *params,
5876 struct link_vars *vars)
5877{
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005878 struct bnx2x *bp = params->bp;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005879 u8 lane;
5880 u16 gp_status1, gp_speed, link_up, duplex = DUPLEX_FULL;
5881 int rc = 0;
5882 lane = bnx2x_get_warpcore_lane(phy, params);
5883 /* Read gp_status */
5884 if (phy->req_line_speed > SPEED_10000) {
5885 u16 temp_link_up;
5886 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
5887 1, &temp_link_up);
5888 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
5889 1, &link_up);
5890 DP(NETIF_MSG_LINK, "PCS RX link status = 0x%x-->0x%x\n",
5891 temp_link_up, link_up);
5892 link_up &= (1<<2);
5893 if (link_up)
5894 bnx2x_ext_phy_resolve_fc(phy, params, vars);
5895 } else {
5896 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
5897 MDIO_WC_REG_GP2_STATUS_GP_2_1, &gp_status1);
5898 DP(NETIF_MSG_LINK, "0x81d1 = 0x%x\n", gp_status1);
5899 /* Check for either KR or generic link up. */
5900 gp_status1 = ((gp_status1 >> 8) & 0xf) |
5901 ((gp_status1 >> 12) & 0xf);
5902 link_up = gp_status1 & (1 << lane);
5903 if (link_up && SINGLE_MEDIA_DIRECT(params)) {
5904 u16 pd, gp_status4;
5905 if (phy->req_line_speed == SPEED_AUTO_NEG) {
5906 /* Check Autoneg complete */
5907 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
5908 MDIO_WC_REG_GP2_STATUS_GP_2_4,
5909 &gp_status4);
5910 if (gp_status4 & ((1<<12)<<lane))
5911 vars->link_status |=
5912 LINK_STATUS_AUTO_NEGOTIATE_COMPLETE;
5913
5914 /* Check parallel detect used */
5915 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
5916 MDIO_WC_REG_PAR_DET_10G_STATUS,
5917 &pd);
5918 if (pd & (1<<15))
5919 vars->link_status |=
5920 LINK_STATUS_PARALLEL_DETECTION_USED;
5921 }
5922 bnx2x_ext_phy_resolve_fc(phy, params, vars);
Yaniv Rosner430d1722012-09-11 04:34:11 +00005923 vars->duplex = duplex;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005924 }
5925 }
5926
Mintz Yuval9e7e8392012-02-15 02:10:24 +00005927 if ((vars->link_status & LINK_STATUS_AUTO_NEGOTIATE_COMPLETE) &&
5928 SINGLE_MEDIA_DIRECT(params)) {
5929 u16 val;
5930
5931 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
5932 MDIO_AN_REG_LP_AUTO_NEG2, &val);
5933
5934 if (val & MDIO_CL73_IEEEB1_AN_ADV2_ADVR_1000M_KX)
5935 vars->link_status |=
5936 LINK_STATUS_LINK_PARTNER_1000TFD_CAPABLE;
5937 if (val & (MDIO_CL73_IEEEB1_AN_ADV2_ADVR_10G_KX4 |
5938 MDIO_CL73_IEEEB1_AN_ADV2_ADVR_10G_KR))
5939 vars->link_status |=
5940 LINK_STATUS_LINK_PARTNER_10GXFD_CAPABLE;
5941
5942 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
5943 MDIO_WC_REG_DIGITAL3_LP_UP1, &val);
5944
5945 if (val & MDIO_OVER_1G_UP1_2_5G)
5946 vars->link_status |=
5947 LINK_STATUS_LINK_PARTNER_2500XFD_CAPABLE;
5948 if (val & (MDIO_OVER_1G_UP1_10G | MDIO_OVER_1G_UP1_10GH))
5949 vars->link_status |=
5950 LINK_STATUS_LINK_PARTNER_10GXFD_CAPABLE;
5951
5952 }
5953
5954
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005955 if (lane < 2) {
5956 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
5957 MDIO_WC_REG_GP2_STATUS_GP_2_2, &gp_speed);
5958 } else {
5959 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
5960 MDIO_WC_REG_GP2_STATUS_GP_2_3, &gp_speed);
5961 }
5962 DP(NETIF_MSG_LINK, "lane %d gp_speed 0x%x\n", lane, gp_speed);
5963
5964 if ((lane & 1) == 0)
5965 gp_speed <<= 8;
5966 gp_speed &= 0x3f00;
5967
5968
5969 rc = bnx2x_get_link_speed_duplex(phy, params, vars, link_up, gp_speed,
5970 duplex);
5971
5972 DP(NETIF_MSG_LINK, "duplex %x flow_ctrl 0x%x link_status 0x%x\n",
5973 vars->duplex, vars->flow_ctrl, vars->link_status);
5974 return rc;
5975}
Eilon Greensteined8680a2009-02-12 08:37:12 +00005976static void bnx2x_set_gmii_tx_driver(struct link_params *params)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005977{
5978 struct bnx2x *bp = params->bp;
Yaniv Rosnere10bc842010-09-07 11:40:50 +00005979 struct bnx2x_phy *phy = &params->phy[INT_PHY];
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005980 u16 lp_up2;
5981 u16 tx_driver;
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00005982 u16 bank;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005983
Yuval Mintzd2310232012-06-20 19:05:19 +00005984 /* Read precomp */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005985 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005986 MDIO_REG_BANK_OVER_1G,
5987 MDIO_OVER_1G_LP_UP2, &lp_up2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005988
Yuval Mintzd2310232012-06-20 19:05:19 +00005989 /* Bits [10:7] at lp_up2, positioned at [15:12] */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005990 lp_up2 = (((lp_up2 & MDIO_OVER_1G_LP_UP2_PREEMPHASIS_MASK) >>
5991 MDIO_OVER_1G_LP_UP2_PREEMPHASIS_SHIFT) <<
5992 MDIO_TX0_TX_DRIVER_PREEMPHASIS_SHIFT);
5993
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00005994 if (lp_up2 == 0)
5995 return;
5996
5997 for (bank = MDIO_REG_BANK_TX0; bank <= MDIO_REG_BANK_TX3;
5998 bank += (MDIO_REG_BANK_TX1 - MDIO_REG_BANK_TX0)) {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005999 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006000 bank,
6001 MDIO_TX0_TX_DRIVER, &tx_driver);
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00006002
Yuval Mintzd2310232012-06-20 19:05:19 +00006003 /* Replace tx_driver bits [15:12] */
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00006004 if (lp_up2 !=
6005 (tx_driver & MDIO_TX0_TX_DRIVER_PREEMPHASIS_MASK)) {
6006 tx_driver &= ~MDIO_TX0_TX_DRIVER_PREEMPHASIS_MASK;
6007 tx_driver |= lp_up2;
Yaniv Rosnercd2be892011-01-31 04:21:45 +00006008 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006009 bank,
6010 MDIO_TX0_TX_DRIVER, tx_driver);
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00006011 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006012 }
6013}
6014
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006015static int bnx2x_emac_program(struct link_params *params,
6016 struct link_vars *vars)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006017{
6018 struct bnx2x *bp = params->bp;
6019 u8 port = params->port;
6020 u16 mode = 0;
6021
6022 DP(NETIF_MSG_LINK, "setting link speed & duplex\n");
6023 bnx2x_bits_dis(bp, GRCBASE_EMAC0 + port*0x400 +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006024 EMAC_REG_EMAC_MODE,
6025 (EMAC_MODE_25G_MODE |
6026 EMAC_MODE_PORT_MII_10M |
6027 EMAC_MODE_HALF_DUPLEX));
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006028 switch (vars->line_speed) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006029 case SPEED_10:
6030 mode |= EMAC_MODE_PORT_MII_10M;
6031 break;
6032
6033 case SPEED_100:
6034 mode |= EMAC_MODE_PORT_MII;
6035 break;
6036
6037 case SPEED_1000:
6038 mode |= EMAC_MODE_PORT_GMII;
6039 break;
6040
6041 case SPEED_2500:
6042 mode |= (EMAC_MODE_25G_MODE | EMAC_MODE_PORT_GMII);
6043 break;
6044
6045 default:
6046 /* 10G not valid for EMAC */
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006047 DP(NETIF_MSG_LINK, "Invalid line_speed 0x%x\n",
6048 vars->line_speed);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006049 return -EINVAL;
6050 }
6051
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006052 if (vars->duplex == DUPLEX_HALF)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006053 mode |= EMAC_MODE_HALF_DUPLEX;
6054 bnx2x_bits_en(bp,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006055 GRCBASE_EMAC0 + port*0x400 + EMAC_REG_EMAC_MODE,
6056 mode);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006057
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006058 bnx2x_set_led(params, vars, LED_MODE_OPER, vars->line_speed);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006059 return 0;
6060}
6061
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006062static void bnx2x_set_preemphasis(struct bnx2x_phy *phy,
6063 struct link_params *params)
6064{
6065
6066 u16 bank, i = 0;
6067 struct bnx2x *bp = params->bp;
6068
6069 for (bank = MDIO_REG_BANK_RX0, i = 0; bank <= MDIO_REG_BANK_RX3;
6070 bank += (MDIO_REG_BANK_RX1-MDIO_REG_BANK_RX0), i++) {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00006071 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006072 bank,
6073 MDIO_RX0_RX_EQ_BOOST,
6074 phy->rx_preemphasis[i]);
6075 }
6076
6077 for (bank = MDIO_REG_BANK_TX0, i = 0; bank <= MDIO_REG_BANK_TX3;
6078 bank += (MDIO_REG_BANK_TX1 - MDIO_REG_BANK_TX0), i++) {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00006079 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006080 bank,
6081 MDIO_TX0_TX_DRIVER,
6082 phy->tx_preemphasis[i]);
6083 }
6084}
6085
Yaniv Rosnerec146a62011-05-31 21:29:27 +00006086static void bnx2x_xgxs_config_init(struct bnx2x_phy *phy,
6087 struct link_params *params,
6088 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006089{
6090 struct bnx2x *bp = params->bp;
6091 u8 enable_cl73 = (SINGLE_MEDIA_DIRECT(params) ||
6092 (params->loopback_mode == LOOPBACK_XGXS));
6093 if (!(vars->phy_flags & PHY_SGMII_FLAG)) {
6094 if (SINGLE_MEDIA_DIRECT(params) &&
6095 (params->feature_config_flags &
6096 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED))
6097 bnx2x_set_preemphasis(phy, params);
6098
Yuval Mintzd2310232012-06-20 19:05:19 +00006099 /* Forced speed requested? */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006100 if (vars->line_speed != SPEED_AUTO_NEG ||
6101 (SINGLE_MEDIA_DIRECT(params) &&
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006102 params->loopback_mode == LOOPBACK_EXT)) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006103 DP(NETIF_MSG_LINK, "not SGMII, no AN\n");
6104
Yuval Mintzd2310232012-06-20 19:05:19 +00006105 /* Disable autoneg */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006106 bnx2x_set_autoneg(phy, params, vars, 0);
6107
Yuval Mintzd2310232012-06-20 19:05:19 +00006108 /* Program speed and duplex */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006109 bnx2x_program_serdes(phy, params, vars);
6110
6111 } else { /* AN_mode */
6112 DP(NETIF_MSG_LINK, "not SGMII, AN\n");
6113
6114 /* AN enabled */
Yaniv Rosner9045f6b42011-05-31 21:28:27 +00006115 bnx2x_set_brcm_cl37_advertisement(phy, params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006116
Yuval Mintzd2310232012-06-20 19:05:19 +00006117 /* Program duplex & pause advertisement (for aneg) */
Yaniv Rosner9045f6b42011-05-31 21:28:27 +00006118 bnx2x_set_ieee_aneg_advertisement(phy, params,
6119 vars->ieee_fc);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006120
Yuval Mintzd2310232012-06-20 19:05:19 +00006121 /* Enable autoneg */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006122 bnx2x_set_autoneg(phy, params, vars, enable_cl73);
6123
Yuval Mintzd2310232012-06-20 19:05:19 +00006124 /* Enable and restart AN */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006125 bnx2x_restart_autoneg(phy, params, enable_cl73);
6126 }
6127
6128 } else { /* SGMII mode */
6129 DP(NETIF_MSG_LINK, "SGMII\n");
6130
6131 bnx2x_initialize_sgmii_process(phy, params, vars);
6132 }
6133}
6134
Yaniv Rosnerec146a62011-05-31 21:29:27 +00006135static int bnx2x_prepare_xgxs(struct bnx2x_phy *phy,
6136 struct link_params *params,
6137 struct link_vars *vars)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006138{
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006139 int rc;
Yaniv Rosnerec146a62011-05-31 21:29:27 +00006140 vars->phy_flags |= PHY_XGXS_FLAG;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006141 if ((phy->req_line_speed &&
6142 ((phy->req_line_speed == SPEED_100) ||
6143 (phy->req_line_speed == SPEED_10))) ||
6144 (!phy->req_line_speed &&
6145 (phy->speed_cap_mask >=
6146 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL) &&
6147 (phy->speed_cap_mask <
Yaniv Rosnerec146a62011-05-31 21:29:27 +00006148 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) ||
6149 (phy->type == PORT_HW_CFG_SERDES_EXT_PHY_TYPE_DIRECT_SD))
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006150 vars->phy_flags |= PHY_SGMII_FLAG;
6151 else
6152 vars->phy_flags &= ~PHY_SGMII_FLAG;
6153
6154 bnx2x_calc_ieee_aneg_adv(phy, params, &vars->ieee_fc);
Yaniv Rosnerec146a62011-05-31 21:29:27 +00006155 bnx2x_set_aer_mmd(params, phy);
6156 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
6157 bnx2x_set_master_ln(params, phy);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006158
6159 rc = bnx2x_reset_unicore(params, phy, 0);
Yuval Mintzd2310232012-06-20 19:05:19 +00006160 /* Reset the SerDes and wait for reset bit return low */
6161 if (rc)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006162 return rc;
6163
Yaniv Rosnerec146a62011-05-31 21:29:27 +00006164 bnx2x_set_aer_mmd(params, phy);
Yuval Mintzd2310232012-06-20 19:05:19 +00006165 /* Setting the masterLn_def again after the reset */
Yaniv Rosnerec146a62011-05-31 21:29:27 +00006166 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT) {
6167 bnx2x_set_master_ln(params, phy);
6168 bnx2x_set_swap_lanes(params, phy);
6169 }
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006170
6171 return rc;
6172}
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00006173
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006174static u16 bnx2x_wait_reset_complete(struct bnx2x *bp,
Yaniv Rosner6d870c32011-01-31 04:22:20 +00006175 struct bnx2x_phy *phy,
6176 struct link_params *params)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006177{
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006178 u16 cnt, ctrl;
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006179 /* Wait for soft reset to get cleared up to 1 sec */
Yaniv Rosner62b29a52010-09-07 11:40:58 +00006180 for (cnt = 0; cnt < 1000; cnt++) {
Yaniv Rosner52c4d6c2011-07-05 01:06:34 +00006181 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54618SE)
Yaniv Rosner6583e332011-06-14 01:34:17 +00006182 bnx2x_cl22_read(bp, phy,
6183 MDIO_PMA_REG_CTRL, &ctrl);
6184 else
6185 bnx2x_cl45_read(bp, phy,
6186 MDIO_PMA_DEVAD,
6187 MDIO_PMA_REG_CTRL, &ctrl);
Yaniv Rosner62b29a52010-09-07 11:40:58 +00006188 if (!(ctrl & (1<<15)))
6189 break;
Yuval Mintzd2310232012-06-20 19:05:19 +00006190 usleep_range(1000, 2000);
Yaniv Rosner62b29a52010-09-07 11:40:58 +00006191 }
Yaniv Rosner6d870c32011-01-31 04:22:20 +00006192
6193 if (cnt == 1000)
6194 netdev_err(bp->dev, "Warning: PHY was not initialized,"
6195 " Port %d\n",
6196 params->port);
Yaniv Rosner62b29a52010-09-07 11:40:58 +00006197 DP(NETIF_MSG_LINK, "control reg 0x%x (after %d ms)\n", ctrl, cnt);
6198 return cnt;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006199}
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006200
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006201static void bnx2x_link_int_enable(struct link_params *params)
6202{
6203 u8 port = params->port;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006204 u32 mask;
6205 struct bnx2x *bp = params->bp;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00006206
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006207 /* Setting the status to report on link up for either XGXS or SerDes */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006208 if (CHIP_IS_E3(bp)) {
6209 mask = NIG_MASK_XGXS0_LINK_STATUS;
6210 if (!(SINGLE_MEDIA_DIRECT(params)))
6211 mask |= NIG_MASK_MI_INT;
6212 } else if (params->switch_cfg == SWITCH_CFG_10G) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006213 mask = (NIG_MASK_XGXS0_LINK10G |
6214 NIG_MASK_XGXS0_LINK_STATUS);
6215 DP(NETIF_MSG_LINK, "enabled XGXS interrupt\n");
Yaniv Rosnere10bc842010-09-07 11:40:50 +00006216 if (!(SINGLE_MEDIA_DIRECT(params)) &&
6217 params->phy[INT_PHY].type !=
6218 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006219 mask |= NIG_MASK_MI_INT;
6220 DP(NETIF_MSG_LINK, "enabled external phy int\n");
6221 }
6222
6223 } else { /* SerDes */
6224 mask = NIG_MASK_SERDES0_LINK_STATUS;
6225 DP(NETIF_MSG_LINK, "enabled SerDes interrupt\n");
Yaniv Rosnere10bc842010-09-07 11:40:50 +00006226 if (!(SINGLE_MEDIA_DIRECT(params)) &&
6227 params->phy[INT_PHY].type !=
6228 PORT_HW_CFG_SERDES_EXT_PHY_TYPE_NOT_CONN) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006229 mask |= NIG_MASK_MI_INT;
6230 DP(NETIF_MSG_LINK, "enabled external phy int\n");
6231 }
6232 }
6233 bnx2x_bits_en(bp,
6234 NIG_REG_MASK_INTERRUPT_PORT0 + port*4,
6235 mask);
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00006236
6237 DP(NETIF_MSG_LINK, "port %x, is_xgxs %x, int_status 0x%x\n", port,
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006238 (params->switch_cfg == SWITCH_CFG_10G),
6239 REG_RD(bp, NIG_REG_STATUS_INTERRUPT_PORT0 + port*4));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006240 DP(NETIF_MSG_LINK, " int_mask 0x%x, MI_INT %x, SERDES_LINK %x\n",
6241 REG_RD(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4),
6242 REG_RD(bp, NIG_REG_EMAC0_STATUS_MISC_MI_INT + port*0x18),
6243 REG_RD(bp, NIG_REG_SERDES0_STATUS_LINK_STATUS+port*0x3c));
6244 DP(NETIF_MSG_LINK, " 10G %x, XGXS_LINK %x\n",
6245 REG_RD(bp, NIG_REG_XGXS0_STATUS_LINK10G + port*0x68),
6246 REG_RD(bp, NIG_REG_XGXS0_STATUS_LINK_STATUS + port*0x68));
6247}
6248
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006249static void bnx2x_rearm_latch_signal(struct bnx2x *bp, u8 port,
6250 u8 exp_mi_int)
Eilon Greenstein2f904462009-08-12 08:22:16 +00006251{
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006252 u32 latch_status = 0;
6253
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00006254 /* Disable the MI INT ( external phy int ) by writing 1 to the
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006255 * status register. Link down indication is high-active-signal,
6256 * so in this case we need to write the status to clear the XOR
Eilon Greenstein2f904462009-08-12 08:22:16 +00006257 */
6258 /* Read Latched signals */
6259 latch_status = REG_RD(bp,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006260 NIG_REG_LATCH_STATUS_0 + port*8);
6261 DP(NETIF_MSG_LINK, "latch_status = 0x%x\n", latch_status);
Eilon Greenstein2f904462009-08-12 08:22:16 +00006262 /* Handle only those with latched-signal=up.*/
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006263 if (exp_mi_int)
6264 bnx2x_bits_en(bp,
6265 NIG_REG_STATUS_INTERRUPT_PORT0
6266 + port*4,
6267 NIG_STATUS_EMAC0_MI_INT);
6268 else
6269 bnx2x_bits_dis(bp,
6270 NIG_REG_STATUS_INTERRUPT_PORT0
6271 + port*4,
6272 NIG_STATUS_EMAC0_MI_INT);
6273
Eilon Greenstein2f904462009-08-12 08:22:16 +00006274 if (latch_status & 1) {
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006275
Eilon Greenstein2f904462009-08-12 08:22:16 +00006276 /* For all latched-signal=up : Re-Arm Latch signals */
6277 REG_WR(bp, NIG_REG_LATCH_STATUS_0 + port*8,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006278 (latch_status & 0xfffe) | (latch_status & 1));
Eilon Greenstein2f904462009-08-12 08:22:16 +00006279 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006280 /* For all latched-signal=up,Write original_signal to status */
Eilon Greenstein2f904462009-08-12 08:22:16 +00006281}
Yaniv Rosnere10bc842010-09-07 11:40:50 +00006282
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006283static void bnx2x_link_int_ack(struct link_params *params,
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006284 struct link_vars *vars, u8 is_10g_plus)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006285{
6286 struct bnx2x *bp = params->bp;
6287 u8 port = params->port;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006288 u32 mask;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00006289 /* First reset all status we assume only one line will be
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006290 * change at a time
6291 */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006292 bnx2x_bits_dis(bp, NIG_REG_STATUS_INTERRUPT_PORT0 + port*4,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006293 (NIG_STATUS_XGXS0_LINK10G |
6294 NIG_STATUS_XGXS0_LINK_STATUS |
6295 NIG_STATUS_SERDES0_LINK_STATUS));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006296 if (vars->phy_link_up) {
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006297 if (USES_WARPCORE(bp))
6298 mask = NIG_STATUS_XGXS0_LINK_STATUS;
6299 else {
6300 if (is_10g_plus)
6301 mask = NIG_STATUS_XGXS0_LINK10G;
6302 else if (params->switch_cfg == SWITCH_CFG_10G) {
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00006303 /* Disable the link interrupt by writing 1 to
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006304 * the relevant lane in the status register
6305 */
6306 u32 ser_lane =
6307 ((params->lane_config &
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006308 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_MASK) >>
6309 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_SHIFT);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006310 mask = ((1 << ser_lane) <<
6311 NIG_STATUS_XGXS0_LINK_STATUS_SIZE);
6312 } else
6313 mask = NIG_STATUS_SERDES0_LINK_STATUS;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006314 }
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006315 DP(NETIF_MSG_LINK, "Ack link up interrupt with mask 0x%x\n",
6316 mask);
6317 bnx2x_bits_en(bp,
6318 NIG_REG_STATUS_INTERRUPT_PORT0 + port*4,
6319 mask);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006320 }
6321}
6322
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006323static int bnx2x_format_ver(u32 num, u8 *str, u16 *len)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006324{
6325 u8 *str_ptr = str;
6326 u32 mask = 0xf0000000;
6327 u8 shift = 8*4;
6328 u8 digit;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006329 u8 remove_leading_zeros = 1;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006330 if (*len < 10) {
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02006331 /* Need more than 10chars for this format */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006332 *str_ptr = '\0';
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006333 (*len)--;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006334 return -EINVAL;
6335 }
6336 while (shift > 0) {
6337
6338 shift -= 4;
6339 digit = ((num & mask) >> shift);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006340 if (digit == 0 && remove_leading_zeros) {
6341 mask = mask >> 4;
6342 continue;
6343 } else if (digit < 0xa)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006344 *str_ptr = digit + '0';
6345 else
6346 *str_ptr = digit - 0xa + 'a';
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006347 remove_leading_zeros = 0;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006348 str_ptr++;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006349 (*len)--;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006350 mask = mask >> 4;
6351 if (shift == 4*4) {
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006352 *str_ptr = '.';
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006353 str_ptr++;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006354 (*len)--;
6355 remove_leading_zeros = 1;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006356 }
6357 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006358 return 0;
6359}
6360
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006361
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006362static int bnx2x_null_format_ver(u32 spirom_ver, u8 *str, u16 *len)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006363{
6364 str[0] = '\0';
6365 (*len)--;
6366 return 0;
6367}
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006368
Mintz Yuvala1e785e2012-02-15 02:10:32 +00006369int bnx2x_get_ext_phy_fw_version(struct link_params *params, u8 *version,
6370 u16 len)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006371{
Julia Lawall0376d5b2009-07-19 05:26:35 +00006372 struct bnx2x *bp;
Eilon Greensteina35da8d2009-02-12 08:37:02 +00006373 u32 spirom_ver = 0;
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006374 int status = 0;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006375 u8 *ver_p = version;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006376 u16 remain_len = len;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006377 if (version == NULL || params == NULL)
6378 return -EINVAL;
Julia Lawall0376d5b2009-07-19 05:26:35 +00006379 bp = params->bp;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006380
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006381 /* Extract first external phy*/
6382 version[0] = '\0';
6383 spirom_ver = REG_RD(bp, params->phy[EXT_PHY1].ver_addr);
Eilon Greensteina35da8d2009-02-12 08:37:02 +00006384
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006385 if (params->phy[EXT_PHY1].format_fw_ver) {
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006386 status |= params->phy[EXT_PHY1].format_fw_ver(spirom_ver,
6387 ver_p,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006388 &remain_len);
6389 ver_p += (len - remain_len);
6390 }
6391 if ((params->num_phys == MAX_PHYS) &&
6392 (params->phy[EXT_PHY2].ver_addr != 0)) {
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006393 spirom_ver = REG_RD(bp, params->phy[EXT_PHY2].ver_addr);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006394 if (params->phy[EXT_PHY2].format_fw_ver) {
6395 *ver_p = '/';
6396 ver_p++;
6397 remain_len--;
6398 status |= params->phy[EXT_PHY2].format_fw_ver(
6399 spirom_ver,
6400 ver_p,
6401 &remain_len);
6402 ver_p = version + (len - remain_len);
6403 }
6404 }
6405 *ver_p = '\0';
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006406 return status;
6407}
6408
Yaniv Rosnere10bc842010-09-07 11:40:50 +00006409static void bnx2x_set_xgxs_loopback(struct bnx2x_phy *phy,
Yaniv Rosner62b29a52010-09-07 11:40:58 +00006410 struct link_params *params)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006411{
6412 u8 port = params->port;
6413 struct bnx2x *bp = params->bp;
6414
Yaniv Rosner62b29a52010-09-07 11:40:58 +00006415 if (phy->req_line_speed != SPEED_1000) {
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006416 u32 md_devad = 0;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006417
6418 DP(NETIF_MSG_LINK, "XGXS 10G loopback enable\n");
6419
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006420 if (!CHIP_IS_E3(bp)) {
Yuval Mintzd2310232012-06-20 19:05:19 +00006421 /* Change the uni_phy_addr in the nig */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006422 md_devad = REG_RD(bp, (NIG_REG_XGXS0_CTRL_MD_DEVAD +
6423 port*0x18));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006424
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006425 REG_WR(bp, NIG_REG_XGXS0_CTRL_MD_DEVAD + port*0x18,
6426 0x5);
6427 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006428
Yaniv Rosnere10bc842010-09-07 11:40:50 +00006429 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006430 5,
6431 (MDIO_REG_BANK_AER_BLOCK +
6432 (MDIO_AER_BLOCK_AER_REG & 0xf)),
6433 0x2800);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006434
Yaniv Rosnere10bc842010-09-07 11:40:50 +00006435 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006436 5,
6437 (MDIO_REG_BANK_CL73_IEEEB0 +
6438 (MDIO_CL73_IEEEB0_CL73_AN_CONTROL & 0xf)),
6439 0x6041);
Eilon Greenstein38582762009-01-14 06:44:16 +00006440 msleep(200);
Yuval Mintzd2310232012-06-20 19:05:19 +00006441 /* Set aer mmd back */
Yaniv Rosnerec146a62011-05-31 21:29:27 +00006442 bnx2x_set_aer_mmd(params, phy);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006443
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006444 if (!CHIP_IS_E3(bp)) {
Yuval Mintzd2310232012-06-20 19:05:19 +00006445 /* And md_devad */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006446 REG_WR(bp, NIG_REG_XGXS0_CTRL_MD_DEVAD + port*0x18,
6447 md_devad);
6448 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006449 } else {
Yaniv Rosnere10bc842010-09-07 11:40:50 +00006450 u16 mii_ctrl;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006451 DP(NETIF_MSG_LINK, "XGXS 1G loopback enable\n");
Yaniv Rosnere10bc842010-09-07 11:40:50 +00006452 bnx2x_cl45_read(bp, phy, 5,
6453 (MDIO_REG_BANK_COMBO_IEEE0 +
6454 (MDIO_COMBO_IEEE0_MII_CONTROL & 0xf)),
6455 &mii_ctrl);
6456 bnx2x_cl45_write(bp, phy, 5,
6457 (MDIO_REG_BANK_COMBO_IEEE0 +
6458 (MDIO_COMBO_IEEE0_MII_CONTROL & 0xf)),
6459 mii_ctrl |
6460 MDIO_COMBO_IEEO_MII_CONTROL_LOOPBACK);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006461 }
6462}
6463
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006464int bnx2x_set_led(struct link_params *params,
6465 struct link_vars *vars, u8 mode, u32 speed)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006466{
Yaniv Rosner7846e472009-11-05 19:18:07 +02006467 u8 port = params->port;
6468 u16 hw_led_mode = params->hw_led_mode;
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006469 int rc = 0;
6470 u8 phy_idx;
Eilon Greenstein345b5d52008-08-13 15:58:12 -07006471 u32 tmp;
6472 u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
Yaniv Rosner7846e472009-11-05 19:18:07 +02006473 struct bnx2x *bp = params->bp;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006474 DP(NETIF_MSG_LINK, "bnx2x_set_led: port %x, mode %d\n", port, mode);
6475 DP(NETIF_MSG_LINK, "speed 0x%x, hw_led_mode 0x%x\n",
6476 speed, hw_led_mode);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006477 /* In case */
6478 for (phy_idx = EXT_PHY1; phy_idx < MAX_PHYS; phy_idx++) {
6479 if (params->phy[phy_idx].set_link_led) {
6480 params->phy[phy_idx].set_link_led(
6481 &params->phy[phy_idx], params, mode);
6482 }
6483 }
6484
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006485 switch (mode) {
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006486 case LED_MODE_FRONT_PANEL_OFF:
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006487 case LED_MODE_OFF:
6488 REG_WR(bp, NIG_REG_LED_10G_P0 + port*4, 0);
6489 REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006490 SHARED_HW_CFG_LED_MAC1);
Eilon Greenstein345b5d52008-08-13 15:58:12 -07006491
6492 tmp = EMAC_RD(bp, EMAC_REG_EMAC_LED);
Yaniv Rosner001cea72011-10-27 05:09:48 +00006493 if (params->phy[EXT_PHY1].type ==
Yaniv Rosner9379c9b2012-04-04 01:28:58 +00006494 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54618SE)
6495 tmp &= ~(EMAC_LED_1000MB_OVERRIDE |
6496 EMAC_LED_100MB_OVERRIDE |
6497 EMAC_LED_10MB_OVERRIDE);
6498 else
6499 tmp |= EMAC_LED_OVERRIDE;
6500
6501 EMAC_WR(bp, EMAC_REG_EMAC_LED, tmp);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006502 break;
6503
6504 case LED_MODE_OPER:
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00006505 /* For all other phys, OPER mode is same as ON, so in case
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006506 * link is down, do nothing
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006507 */
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006508 if (!vars->link_up)
6509 break;
6510 case LED_MODE_ON:
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00006511 if (((params->phy[EXT_PHY1].type ==
6512 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727) ||
6513 (params->phy[EXT_PHY1].type ==
6514 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8722)) &&
Yaniv Rosner1f483532011-01-18 04:33:31 +00006515 CHIP_IS_E2(bp) && params->num_phys == 2) {
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00006516 /* This is a work-around for E2+8727 Configurations */
Yaniv Rosner1f483532011-01-18 04:33:31 +00006517 if (mode == LED_MODE_ON ||
6518 speed == SPEED_10000){
6519 REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4, 0);
6520 REG_WR(bp, NIG_REG_LED_10G_P0 + port*4, 1);
6521
6522 tmp = EMAC_RD(bp, EMAC_REG_EMAC_LED);
6523 EMAC_WR(bp, EMAC_REG_EMAC_LED,
6524 (tmp | EMAC_LED_OVERRIDE));
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00006525 /* Return here without enabling traffic
David S. Miller8decf862011-09-22 03:23:13 -04006526 * LED blink and setting rate in ON mode.
Yaniv Rosner793bd452011-08-02 22:59:40 +00006527 * In oper mode, enabling LED blink
6528 * and setting rate is needed.
6529 */
6530 if (mode == LED_MODE_ON)
6531 return rc;
Yaniv Rosner1f483532011-01-18 04:33:31 +00006532 }
Yaniv Rosner793bd452011-08-02 22:59:40 +00006533 } else if (SINGLE_MEDIA_DIRECT(params)) {
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00006534 /* This is a work-around for HW issue found when link
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006535 * is up in CL73
6536 */
David S. Miller8decf862011-09-22 03:23:13 -04006537 if ((!CHIP_IS_E3(bp)) ||
6538 (CHIP_IS_E3(bp) &&
6539 mode == LED_MODE_ON))
6540 REG_WR(bp, NIG_REG_LED_10G_P0 + port*4, 1);
6541
Yaniv Rosner793bd452011-08-02 22:59:40 +00006542 if (CHIP_IS_E1x(bp) ||
6543 CHIP_IS_E2(bp) ||
6544 (mode == LED_MODE_ON))
6545 REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4, 0);
6546 else
6547 REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4,
6548 hw_led_mode);
Yaniv Rosner001cea72011-10-27 05:09:48 +00006549 } else if ((params->phy[EXT_PHY1].type ==
6550 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54618SE) &&
Yaniv Rosner9379c9b2012-04-04 01:28:58 +00006551 (mode == LED_MODE_ON)) {
Yaniv Rosner001cea72011-10-27 05:09:48 +00006552 REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4, 0);
6553 tmp = EMAC_RD(bp, EMAC_REG_EMAC_LED);
Yaniv Rosner9379c9b2012-04-04 01:28:58 +00006554 EMAC_WR(bp, EMAC_REG_EMAC_LED, tmp |
6555 EMAC_LED_OVERRIDE | EMAC_LED_1000MB_OVERRIDE);
6556 /* Break here; otherwise, it'll disable the
6557 * intended override.
6558 */
6559 break;
Yaniv Rosner793bd452011-08-02 22:59:40 +00006560 } else
Yaniv Rosner001cea72011-10-27 05:09:48 +00006561 REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4,
6562 hw_led_mode);
Yaniv Rosner7846e472009-11-05 19:18:07 +02006563
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006564 REG_WR(bp, NIG_REG_LED_CONTROL_OVERRIDE_TRAFFIC_P0 + port*4, 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006565 /* Set blinking rate to ~15.9Hz */
Yaniv Rosner26ffaf32011-10-27 05:09:45 +00006566 if (CHIP_IS_E3(bp))
6567 REG_WR(bp, NIG_REG_LED_CONTROL_BLINK_RATE_P0 + port*4,
6568 LED_BLINK_RATE_VAL_E3);
6569 else
6570 REG_WR(bp, NIG_REG_LED_CONTROL_BLINK_RATE_P0 + port*4,
6571 LED_BLINK_RATE_VAL_E1X_E2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006572 REG_WR(bp, NIG_REG_LED_CONTROL_BLINK_RATE_ENA_P0 +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006573 port*4, 1);
Yaniv Rosner9379c9b2012-04-04 01:28:58 +00006574 tmp = EMAC_RD(bp, EMAC_REG_EMAC_LED);
6575 EMAC_WR(bp, EMAC_REG_EMAC_LED,
6576 (tmp & (~EMAC_LED_OVERRIDE)));
Eilon Greenstein345b5d52008-08-13 15:58:12 -07006577
Yaniv Rosner7846e472009-11-05 19:18:07 +02006578 if (CHIP_IS_E1(bp) &&
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006579 ((speed == SPEED_2500) ||
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006580 (speed == SPEED_1000) ||
6581 (speed == SPEED_100) ||
6582 (speed == SPEED_10))) {
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00006583 /* For speeds less than 10G LED scheme is different */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006584 REG_WR(bp, NIG_REG_LED_CONTROL_OVERRIDE_TRAFFIC_P0
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006585 + port*4, 1);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006586 REG_WR(bp, NIG_REG_LED_CONTROL_TRAFFIC_P0 +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006587 port*4, 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006588 REG_WR(bp, NIG_REG_LED_CONTROL_BLINK_TRAFFIC_P0 +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006589 port*4, 1);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006590 }
6591 break;
6592
6593 default:
6594 rc = -EINVAL;
6595 DP(NETIF_MSG_LINK, "bnx2x_set_led: Invalid led mode %d\n",
6596 mode);
6597 break;
6598 }
6599 return rc;
6600
6601}
6602
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00006603/* This function comes to reflect the actual link state read DIRECTLY from the
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006604 * HW
6605 */
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006606int bnx2x_test_link(struct link_params *params, struct link_vars *vars,
6607 u8 is_serdes)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006608{
6609 struct bnx2x *bp = params->bp;
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00006610 u16 gp_status = 0, phy_index = 0;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006611 u8 ext_phy_link_up = 0, serdes_phy_type;
6612 struct link_vars temp_vars;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006613 struct bnx2x_phy *int_phy = &params->phy[INT_PHY];
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006614
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006615 if (CHIP_IS_E3(bp)) {
6616 u16 link_up;
6617 if (params->req_line_speed[LINK_CONFIG_IDX(INT_PHY)]
6618 > SPEED_10000) {
6619 /* Check 20G link */
6620 bnx2x_cl45_read(bp, int_phy, MDIO_WC_DEVAD,
6621 1, &link_up);
6622 bnx2x_cl45_read(bp, int_phy, MDIO_WC_DEVAD,
6623 1, &link_up);
6624 link_up &= (1<<2);
6625 } else {
6626 /* Check 10G link and below*/
6627 u8 lane = bnx2x_get_warpcore_lane(int_phy, params);
6628 bnx2x_cl45_read(bp, int_phy, MDIO_WC_DEVAD,
6629 MDIO_WC_REG_GP2_STATUS_GP_2_1,
6630 &gp_status);
6631 gp_status = ((gp_status >> 8) & 0xf) |
6632 ((gp_status >> 12) & 0xf);
6633 link_up = gp_status & (1 << lane);
6634 }
6635 if (!link_up)
6636 return -ESRCH;
6637 } else {
6638 CL22_RD_OVER_CL45(bp, int_phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006639 MDIO_REG_BANK_GP_STATUS,
6640 MDIO_GP_STATUS_TOP_AN_STATUS1,
6641 &gp_status);
Yuval Mintzd2310232012-06-20 19:05:19 +00006642 /* Link is up only if both local phy and external phy are up */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006643 if (!(gp_status & MDIO_GP_STATUS_TOP_AN_STATUS1_LINK_STATUS))
6644 return -ESRCH;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006645 }
6646 /* In XGXS loopback mode, do not check external PHY */
6647 if (params->loopback_mode == LOOPBACK_XGXS)
6648 return 0;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006649
6650 switch (params->num_phys) {
6651 case 1:
6652 /* No external PHY */
6653 return 0;
6654 case 2:
6655 ext_phy_link_up = params->phy[EXT_PHY1].read_status(
6656 &params->phy[EXT_PHY1],
6657 params, &temp_vars);
6658 break;
6659 case 3: /* Dual Media */
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00006660 for (phy_index = EXT_PHY1; phy_index < params->num_phys;
6661 phy_index++) {
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006662 serdes_phy_type = ((params->phy[phy_index].media_type ==
Yuval Mintzdbef8072012-06-20 19:05:22 +00006663 ETH_PHY_SFPP_10G_FIBER) ||
6664 (params->phy[phy_index].media_type ==
6665 ETH_PHY_SFP_1G_FIBER) ||
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006666 (params->phy[phy_index].media_type ==
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00006667 ETH_PHY_XFP_FIBER) ||
6668 (params->phy[phy_index].media_type ==
6669 ETH_PHY_DA_TWINAX));
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006670
6671 if (is_serdes != serdes_phy_type)
6672 continue;
6673 if (params->phy[phy_index].read_status) {
6674 ext_phy_link_up |=
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00006675 params->phy[phy_index].read_status(
6676 &params->phy[phy_index],
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006677 params, &temp_vars);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006678 }
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00006679 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006680 break;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006681 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006682 if (ext_phy_link_up)
6683 return 0;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006684 return -ESRCH;
6685}
6686
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006687static int bnx2x_link_initialize(struct link_params *params,
6688 struct link_vars *vars)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006689{
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006690 int rc = 0;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006691 u8 phy_index, non_ext_phy;
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00006692 struct bnx2x *bp = params->bp;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00006693 /* In case of external phy existence, the line speed would be the
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006694 * line speed linked up by the external phy. In case it is direct
6695 * only, then the line_speed during initialization will be
6696 * equal to the req_line_speed
6697 */
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00006698 vars->line_speed = params->phy[INT_PHY].req_line_speed;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006699
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00006700 /* Initialize the internal phy in case this is a direct board
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00006701 * (no external phys), or this board has external phy which requires
6702 * to first.
6703 */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006704 if (!USES_WARPCORE(bp))
6705 bnx2x_prepare_xgxs(&params->phy[INT_PHY], params, vars);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006706 /* init ext phy and enable link state int */
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00006707 non_ext_phy = (SINGLE_MEDIA_DIRECT(params) ||
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006708 (params->loopback_mode == LOOPBACK_XGXS));
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006709
6710 if (non_ext_phy ||
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00006711 (params->phy[EXT_PHY1].flags & FLAGS_INIT_XGXS_FIRST) ||
Eilon Greenstein8660d8c2009-03-02 08:01:02 +00006712 (params->loopback_mode == LOOPBACK_EXT_PHY)) {
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00006713 struct bnx2x_phy *phy = &params->phy[INT_PHY];
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006714 if (vars->line_speed == SPEED_AUTO_NEG &&
6715 (CHIP_IS_E1x(bp) ||
6716 CHIP_IS_E2(bp)))
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00006717 bnx2x_set_parallel_detection(phy, params);
Yaniv Rosnerec146a62011-05-31 21:29:27 +00006718 if (params->phy[INT_PHY].config_init)
6719 params->phy[INT_PHY].config_init(phy,
6720 params,
6721 vars);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006722 }
6723
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00006724 /* Init external phy*/
Yaniv Rosnerfd36a2e2011-05-31 21:29:05 +00006725 if (non_ext_phy) {
6726 if (params->phy[INT_PHY].supported &
6727 SUPPORTED_FIBRE)
6728 vars->link_status |= LINK_STATUS_SERDES_LINK;
6729 } else {
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006730 for (phy_index = EXT_PHY1; phy_index < params->num_phys;
6731 phy_index++) {
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00006732 /* No need to initialize second phy in case of first
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006733 * phy only selection. In case of second phy, we do
6734 * need to initialize the first phy, since they are
6735 * connected.
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006736 */
Yaniv Rosnerfd36a2e2011-05-31 21:29:05 +00006737 if (params->phy[phy_index].supported &
6738 SUPPORTED_FIBRE)
6739 vars->link_status |= LINK_STATUS_SERDES_LINK;
6740
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006741 if (phy_index == EXT_PHY2 &&
6742 (bnx2x_phy_selection(params) ==
6743 PORT_HW_CFG_PHY_SELECTION_FIRST_PHY)) {
Joe Perches94f05b02011-08-14 12:16:20 +00006744 DP(NETIF_MSG_LINK,
6745 "Not initializing second phy\n");
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006746 continue;
6747 }
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006748 params->phy[phy_index].config_init(
6749 &params->phy[phy_index],
6750 params, vars);
6751 }
Yaniv Rosnerfd36a2e2011-05-31 21:29:05 +00006752 }
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +00006753 /* Reset the interrupt indication after phy was initialized */
6754 bnx2x_bits_dis(bp, NIG_REG_STATUS_INTERRUPT_PORT0 +
6755 params->port*4,
6756 (NIG_STATUS_XGXS0_LINK10G |
6757 NIG_STATUS_XGXS0_LINK_STATUS |
6758 NIG_STATUS_SERDES0_LINK_STATUS |
6759 NIG_MASK_MI_INT));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006760 return rc;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006761}
6762
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006763static void bnx2x_int_link_reset(struct bnx2x_phy *phy,
6764 struct link_params *params)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006765{
Yuval Mintzd2310232012-06-20 19:05:19 +00006766 /* Reset the SerDes/XGXS */
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006767 REG_WR(params->bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_CLEAR,
6768 (0x1ff << (params->port*16)));
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006769}
6770
6771static void bnx2x_common_ext_link_reset(struct bnx2x_phy *phy,
6772 struct link_params *params)
6773{
6774 struct bnx2x *bp = params->bp;
6775 u8 gpio_port;
6776 /* HW reset */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006777 if (CHIP_IS_E2(bp))
6778 gpio_port = BP_PATH(bp);
6779 else
6780 gpio_port = params->port;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006781 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006782 MISC_REGISTERS_GPIO_OUTPUT_LOW,
6783 gpio_port);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006784 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006785 MISC_REGISTERS_GPIO_OUTPUT_LOW,
6786 gpio_port);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006787 DP(NETIF_MSG_LINK, "reset external PHY\n");
6788}
6789
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006790static int bnx2x_update_link_down(struct link_params *params,
6791 struct link_vars *vars)
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006792{
6793 struct bnx2x *bp = params->bp;
6794 u8 port = params->port;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00006795
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006796 DP(NETIF_MSG_LINK, "Port %x: Link is down\n", port);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006797 bnx2x_set_led(params, vars, LED_MODE_OFF, 0);
Yaniv Rosner3deb8162011-06-14 01:34:33 +00006798 vars->phy_flags &= ~PHY_PHYSICAL_LINK_FLAG;
Yuval Mintzd2310232012-06-20 19:05:19 +00006799 /* Indicate no mac active */
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006800 vars->mac_type = MAC_TYPE_NONE;
6801
Yuval Mintzd2310232012-06-20 19:05:19 +00006802 /* Update shared memory */
Yaniv Rosnerfd36a2e2011-05-31 21:29:05 +00006803 vars->link_status &= ~(LINK_STATUS_SPEED_AND_DUPLEX_MASK |
6804 LINK_STATUS_LINK_UP |
Yaniv Rosnerde6f3372011-08-02 22:59:25 +00006805 LINK_STATUS_PHYSICAL_LINK_FLAG |
Yaniv Rosnerfd36a2e2011-05-31 21:29:05 +00006806 LINK_STATUS_AUTO_NEGOTIATE_COMPLETE |
6807 LINK_STATUS_RX_FLOW_CONTROL_FLAG_MASK |
6808 LINK_STATUS_TX_FLOW_CONTROL_FLAG_MASK |
Mintz Yuval9e7e8392012-02-15 02:10:24 +00006809 LINK_STATUS_PARALLEL_DETECTION_FLAG_MASK |
6810 LINK_STATUS_LINK_PARTNER_SYMMETRIC_PAUSE |
6811 LINK_STATUS_LINK_PARTNER_ASYMMETRIC_PAUSE);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006812 vars->line_speed = 0;
6813 bnx2x_update_mng(params, vars->link_status);
6814
Yuval Mintzd2310232012-06-20 19:05:19 +00006815 /* Activate nig drain */
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006816 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + port*4, 1);
6817
Yuval Mintzd2310232012-06-20 19:05:19 +00006818 /* Disable emac */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00006819 if (!CHIP_IS_E3(bp))
6820 REG_WR(bp, NIG_REG_NIG_EMAC0_EN + port*4, 0);
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00006821
Yuval Mintzd2310232012-06-20 19:05:19 +00006822 usleep_range(10000, 20000);
6823 /* Reset BigMac/Xmac */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00006824 if (CHIP_IS_E1x(bp) ||
Yaniv Rosnerd3a8f132012-09-13 02:56:20 +00006825 CHIP_IS_E2(bp))
6826 bnx2x_set_bmac_rx(bp, params->chip_id, params->port, 0);
6827
Yaniv Rosnerce7c0482011-10-27 05:09:47 +00006828 if (CHIP_IS_E3(bp)) {
Yuval Mintzd2310232012-06-20 19:05:19 +00006829 /* Prevent LPI Generation by chip */
Yuval Mintzc8c60d82012-06-06 17:13:07 +00006830 REG_WR(bp, MISC_REG_CPMU_LP_FW_ENABLE_P0 + (params->port << 2),
6831 0);
Yuval Mintzc8c60d82012-06-06 17:13:07 +00006832 REG_WR(bp, MISC_REG_CPMU_LP_MASK_ENT_P0 + (params->port << 2),
6833 0);
6834 vars->eee_status &= ~(SHMEM_EEE_LP_ADV_STATUS_MASK |
6835 SHMEM_EEE_ACTIVE_BIT);
6836
6837 bnx2x_update_mng_eee(params, vars->eee_status);
Yaniv Rosnerd3a8f132012-09-13 02:56:20 +00006838 bnx2x_set_xmac_rxtx(params, 0);
6839 bnx2x_set_umac_rxtx(params, 0);
Yaniv Rosnerce7c0482011-10-27 05:09:47 +00006840 }
Yaniv Rosner9380bb92011-06-14 01:34:07 +00006841
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006842 return 0;
6843}
6844
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006845static int bnx2x_update_link_up(struct link_params *params,
6846 struct link_vars *vars,
6847 u8 link_10g)
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006848{
6849 struct bnx2x *bp = params->bp;
Yaniv Rosner55098c52012-04-03 18:41:27 +00006850 u8 phy_idx, port = params->port;
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006851 int rc = 0;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00006852
Yaniv Rosnerde6f3372011-08-02 22:59:25 +00006853 vars->link_status |= (LINK_STATUS_LINK_UP |
6854 LINK_STATUS_PHYSICAL_LINK_FLAG);
Yaniv Rosner3deb8162011-06-14 01:34:33 +00006855 vars->phy_flags |= PHY_PHYSICAL_LINK_FLAG;
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006856
Yaniv Rosner7aa07112010-09-07 11:41:01 +00006857 if (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX)
6858 vars->link_status |=
6859 LINK_STATUS_TX_FLOW_CONTROL_ENABLED;
6860
6861 if (vars->flow_ctrl & BNX2X_FLOW_CTRL_RX)
6862 vars->link_status |=
6863 LINK_STATUS_RX_FLOW_CONTROL_ENABLED;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00006864 if (USES_WARPCORE(bp)) {
Yaniv Rosner3deb8162011-06-14 01:34:33 +00006865 if (link_10g) {
6866 if (bnx2x_xmac_enable(params, vars, 0) ==
6867 -ESRCH) {
6868 DP(NETIF_MSG_LINK, "Found errors on XMAC\n");
6869 vars->link_up = 0;
6870 vars->phy_flags |= PHY_HALF_OPEN_CONN_FLAG;
6871 vars->link_status &= ~LINK_STATUS_LINK_UP;
6872 }
6873 } else
Yaniv Rosner9380bb92011-06-14 01:34:07 +00006874 bnx2x_umac_enable(params, vars, 0);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006875 bnx2x_set_led(params, vars,
Yaniv Rosner9380bb92011-06-14 01:34:07 +00006876 LED_MODE_OPER, vars->line_speed);
Yuval Mintzc8c60d82012-06-06 17:13:07 +00006877
6878 if ((vars->eee_status & SHMEM_EEE_ACTIVE_BIT) &&
6879 (vars->eee_status & SHMEM_EEE_LPI_REQUESTED_BIT)) {
6880 DP(NETIF_MSG_LINK, "Enabling LPI assertion\n");
6881 REG_WR(bp, MISC_REG_CPMU_LP_FW_ENABLE_P0 +
6882 (params->port << 2), 1);
6883 REG_WR(bp, MISC_REG_CPMU_LP_DR_ENABLE, 1);
6884 REG_WR(bp, MISC_REG_CPMU_LP_MASK_ENT_P0 +
6885 (params->port << 2), 0xfc20);
6886 }
Yaniv Rosner9380bb92011-06-14 01:34:07 +00006887 }
6888 if ((CHIP_IS_E1x(bp) ||
6889 CHIP_IS_E2(bp))) {
6890 if (link_10g) {
Yaniv Rosnerd3a8f132012-09-13 02:56:20 +00006891 if (bnx2x_bmac_enable(params, vars, 0, 1) ==
Yaniv Rosner3deb8162011-06-14 01:34:33 +00006892 -ESRCH) {
6893 DP(NETIF_MSG_LINK, "Found errors on BMAC\n");
6894 vars->link_up = 0;
6895 vars->phy_flags |= PHY_HALF_OPEN_CONN_FLAG;
6896 vars->link_status &= ~LINK_STATUS_LINK_UP;
6897 }
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006898
Yaniv Rosner9380bb92011-06-14 01:34:07 +00006899 bnx2x_set_led(params, vars,
6900 LED_MODE_OPER, SPEED_10000);
6901 } else {
6902 rc = bnx2x_emac_program(params, vars);
6903 bnx2x_emac_enable(params, vars, 0);
Yaniv Rosner0c786f02009-11-05 19:18:32 +02006904
Yaniv Rosner9380bb92011-06-14 01:34:07 +00006905 /* AN complete? */
6906 if ((vars->link_status &
6907 LINK_STATUS_AUTO_NEGOTIATE_COMPLETE)
6908 && (!(vars->phy_flags & PHY_SGMII_FLAG)) &&
6909 SINGLE_MEDIA_DIRECT(params))
6910 bnx2x_set_gmii_tx_driver(params);
6911 }
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006912 }
6913
6914 /* PBF - link up */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00006915 if (CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006916 rc |= bnx2x_pbf_update(params, vars->flow_ctrl,
6917 vars->line_speed);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006918
Yuval Mintzd2310232012-06-20 19:05:19 +00006919 /* Disable drain */
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006920 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + port*4, 0);
6921
Yuval Mintzd2310232012-06-20 19:05:19 +00006922 /* Update shared memory */
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006923 bnx2x_update_mng(params, vars->link_status);
Yuval Mintzc8c60d82012-06-06 17:13:07 +00006924 bnx2x_update_mng_eee(params, vars->eee_status);
Yaniv Rosner55098c52012-04-03 18:41:27 +00006925 /* Check remote fault */
6926 for (phy_idx = INT_PHY; phy_idx < MAX_PHYS; phy_idx++) {
6927 if (params->phy[phy_idx].flags & FLAGS_TX_ERROR_CHECK) {
6928 bnx2x_check_half_open_conn(params, vars, 0);
6929 break;
6930 }
6931 }
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00006932 msleep(20);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006933 return rc;
6934}
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00006935/* The bnx2x_link_update function should be called upon link
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006936 * interrupt.
6937 * Link is considered up as follows:
6938 * - DIRECT_SINGLE_MEDIA - Only XGXS link (internal link) needs
6939 * to be up
6940 * - SINGLE_MEDIA - The link between the 577xx and the external
6941 * phy (XGXS) need to up as well as the external link of the
6942 * phy (PHY_EXT1)
6943 * - DUAL_MEDIA - The link between the 577xx and the first
6944 * external phy needs to be up, and at least one of the 2
6945 * external phy link must be up.
Yaniv Rosner62b29a52010-09-07 11:40:58 +00006946 */
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006947int bnx2x_link_update(struct link_params *params, struct link_vars *vars)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006948{
6949 struct bnx2x *bp = params->bp;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006950 struct link_vars phy_vars[MAX_PHYS];
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006951 u8 port = params->port;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006952 u8 link_10g_plus, phy_index;
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006953 u8 ext_phy_link_up = 0, cur_link_up;
6954 int rc = 0;
Eilon Greenstein2f904462009-08-12 08:22:16 +00006955 u8 is_mi_int = 0;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006956 u16 ext_phy_line_speed = 0, prev_line_speed = vars->line_speed;
6957 u8 active_external_phy = INT_PHY;
Yaniv Rosner3deb8162011-06-14 01:34:33 +00006958 vars->phy_flags &= ~PHY_HALF_OPEN_CONN_FLAG;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006959 for (phy_index = INT_PHY; phy_index < params->num_phys;
6960 phy_index++) {
6961 phy_vars[phy_index].flow_ctrl = 0;
6962 phy_vars[phy_index].link_status = 0;
6963 phy_vars[phy_index].line_speed = 0;
6964 phy_vars[phy_index].duplex = DUPLEX_FULL;
6965 phy_vars[phy_index].phy_link_up = 0;
6966 phy_vars[phy_index].link_up = 0;
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00006967 phy_vars[phy_index].fault_detected = 0;
Yuval Mintzc8c60d82012-06-06 17:13:07 +00006968 /* different consideration, since vars holds inner state */
6969 phy_vars[phy_index].eee_status = vars->eee_status;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006970 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006971
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006972 if (USES_WARPCORE(bp))
6973 bnx2x_set_aer_mmd(params, &params->phy[INT_PHY]);
6974
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006975 DP(NETIF_MSG_LINK, "port %x, XGXS?%x, int_status 0x%x\n",
Eilon Greenstein2f904462009-08-12 08:22:16 +00006976 port, (vars->phy_flags & PHY_XGXS_FLAG),
6977 REG_RD(bp, NIG_REG_STATUS_INTERRUPT_PORT0 + port*4));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006978
Eilon Greenstein2f904462009-08-12 08:22:16 +00006979 is_mi_int = (u8)(REG_RD(bp, NIG_REG_EMAC0_STATUS_MISC_MI_INT +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006980 port*0x18) > 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006981 DP(NETIF_MSG_LINK, "int_mask 0x%x MI_INT %x, SERDES_LINK %x\n",
Eilon Greenstein2f904462009-08-12 08:22:16 +00006982 REG_RD(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4),
6983 is_mi_int,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006984 REG_RD(bp, NIG_REG_SERDES0_STATUS_LINK_STATUS + port*0x3c));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006985
6986 DP(NETIF_MSG_LINK, " 10G %x, XGXS_LINK %x\n",
6987 REG_RD(bp, NIG_REG_XGXS0_STATUS_LINK10G + port*0x68),
6988 REG_RD(bp, NIG_REG_XGXS0_STATUS_LINK_STATUS + port*0x68));
6989
Yuval Mintzd2310232012-06-20 19:05:19 +00006990 /* Disable emac */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00006991 if (!CHIP_IS_E3(bp))
6992 REG_WR(bp, NIG_REG_NIG_EMAC0_EN + port*4, 0);
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00006993
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00006994 /* Step 1:
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006995 * Check external link change only for external phys, and apply
6996 * priority selection between them in case the link on both phys
Yaniv Rosner9045f6b42011-05-31 21:28:27 +00006997 * is up. Note that instead of the common vars, a temporary
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006998 * vars argument is used since each phy may have different link/
6999 * speed/duplex result
7000 */
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007001 for (phy_index = EXT_PHY1; phy_index < params->num_phys;
7002 phy_index++) {
7003 struct bnx2x_phy *phy = &params->phy[phy_index];
7004 if (!phy->read_status)
7005 continue;
7006 /* Read link status and params of this ext phy */
7007 cur_link_up = phy->read_status(phy, params,
7008 &phy_vars[phy_index]);
7009 if (cur_link_up) {
7010 DP(NETIF_MSG_LINK, "phy in index %d link is up\n",
7011 phy_index);
7012 } else {
7013 DP(NETIF_MSG_LINK, "phy in index %d link is down\n",
7014 phy_index);
7015 continue;
7016 }
Yaniv Rosner57963ed2008-08-13 15:55:28 -07007017
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007018 if (!ext_phy_link_up) {
7019 ext_phy_link_up = 1;
7020 active_external_phy = phy_index;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007021 } else {
7022 switch (bnx2x_phy_selection(params)) {
7023 case PORT_HW_CFG_PHY_SELECTION_HARDWARE_DEFAULT:
7024 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY_PRIORITY:
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00007025 /* In this option, the first PHY makes sure to pass the
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007026 * traffic through itself only.
7027 * Its not clear how to reset the link on the second phy
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007028 */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007029 active_external_phy = EXT_PHY1;
7030 break;
7031 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY_PRIORITY:
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00007032 /* In this option, the first PHY makes sure to pass the
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007033 * traffic through the second PHY.
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007034 */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007035 active_external_phy = EXT_PHY2;
7036 break;
7037 default:
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00007038 /* Link indication on both PHYs with the following cases
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007039 * is invalid:
7040 * - FIRST_PHY means that second phy wasn't initialized,
7041 * hence its link is expected to be down
7042 * - SECOND_PHY means that first phy should not be able
7043 * to link up by itself (using configuration)
7044 * - DEFAULT should be overriden during initialiazation
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007045 */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007046 DP(NETIF_MSG_LINK, "Invalid link indication"
7047 "mpc=0x%x. DISABLING LINK !!!\n",
7048 params->multi_phy_config);
7049 ext_phy_link_up = 0;
7050 break;
7051 }
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007052 }
7053 }
7054 prev_line_speed = vars->line_speed;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00007055 /* Step 2:
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007056 * Read the status of the internal phy. In case of
7057 * DIRECT_SINGLE_MEDIA board, this link is the external link,
7058 * otherwise this is the link between the 577xx and the first
7059 * external phy
7060 */
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007061 if (params->phy[INT_PHY].read_status)
7062 params->phy[INT_PHY].read_status(
7063 &params->phy[INT_PHY],
7064 params, vars);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00007065 /* The INT_PHY flow control reside in the vars. This include the
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007066 * case where the speed or flow control are not set to AUTO.
7067 * Otherwise, the active external phy flow control result is set
7068 * to the vars. The ext_phy_line_speed is needed to check if the
7069 * speed is different between the internal phy and external phy.
7070 * This case may be result of intermediate link speed change.
7071 */
7072 if (active_external_phy > INT_PHY) {
7073 vars->flow_ctrl = phy_vars[active_external_phy].flow_ctrl;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00007074 /* Link speed is taken from the XGXS. AN and FC result from
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007075 * the external phy.
7076 */
7077 vars->link_status |= phy_vars[active_external_phy].link_status;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007078
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00007079 /* if active_external_phy is first PHY and link is up - disable
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007080 * disable TX on second external PHY
7081 */
7082 if (active_external_phy == EXT_PHY1) {
7083 if (params->phy[EXT_PHY2].phy_specific_func) {
Joe Perches94f05b02011-08-14 12:16:20 +00007084 DP(NETIF_MSG_LINK,
7085 "Disabling TX on EXT_PHY2\n");
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007086 params->phy[EXT_PHY2].phy_specific_func(
7087 &params->phy[EXT_PHY2],
7088 params, DISABLE_TX);
7089 }
7090 }
7091
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007092 ext_phy_line_speed = phy_vars[active_external_phy].line_speed;
7093 vars->duplex = phy_vars[active_external_phy].duplex;
7094 if (params->phy[active_external_phy].supported &
7095 SUPPORTED_FIBRE)
7096 vars->link_status |= LINK_STATUS_SERDES_LINK;
Yaniv Rosnerfd36a2e2011-05-31 21:29:05 +00007097 else
7098 vars->link_status &= ~LINK_STATUS_SERDES_LINK;
Yuval Mintzc8c60d82012-06-06 17:13:07 +00007099
7100 vars->eee_status = phy_vars[active_external_phy].eee_status;
7101
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007102 DP(NETIF_MSG_LINK, "Active external phy selected: %x\n",
7103 active_external_phy);
7104 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007105
7106 for (phy_index = EXT_PHY1; phy_index < params->num_phys;
7107 phy_index++) {
7108 if (params->phy[phy_index].flags &
7109 FLAGS_REARM_LATCH_SIGNAL) {
7110 bnx2x_rearm_latch_signal(bp, port,
7111 phy_index ==
7112 active_external_phy);
7113 break;
7114 }
7115 }
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007116 DP(NETIF_MSG_LINK, "vars->flow_ctrl = 0x%x, vars->link_status = 0x%x,"
7117 " ext_phy_line_speed = %d\n", vars->flow_ctrl,
7118 vars->link_status, ext_phy_line_speed);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00007119 /* Upon link speed change set the NIG into drain mode. Comes to
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007120 * deals with possible FIFO glitch due to clk change when speed
7121 * is decreased without link down indicator
7122 */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07007123
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007124 if (vars->phy_link_up) {
7125 if (!(SINGLE_MEDIA_DIRECT(params)) && ext_phy_link_up &&
7126 (ext_phy_line_speed != vars->line_speed)) {
7127 DP(NETIF_MSG_LINK, "Internal link speed %d is"
7128 " different than the external"
7129 " link speed %d\n", vars->line_speed,
7130 ext_phy_line_speed);
7131 vars->phy_link_up = 0;
7132 } else if (prev_line_speed != vars->line_speed) {
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007133 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4,
7134 0);
Yuval Mintzd2310232012-06-20 19:05:19 +00007135 usleep_range(1000, 2000);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007136 }
7137 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07007138
Yuval Mintzd2310232012-06-20 19:05:19 +00007139 /* Anything 10 and over uses the bmac */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00007140 link_10g_plus = (vars->line_speed >= SPEED_10000);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07007141
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00007142 bnx2x_link_int_ack(params, vars, link_10g_plus);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07007143
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00007144 /* In case external phy link is up, and internal link is down
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007145 * (not initialized yet probably after link initialization, it
7146 * needs to be initialized.
7147 * Note that after link down-up as result of cable plug, the xgxs
7148 * link would probably become up again without the need
7149 * initialize it
7150 */
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007151 if (!(SINGLE_MEDIA_DIRECT(params))) {
7152 DP(NETIF_MSG_LINK, "ext_phy_link_up = %d, int_link_up = %d,"
7153 " init_preceding = %d\n", ext_phy_link_up,
7154 vars->phy_link_up,
7155 params->phy[EXT_PHY1].flags &
7156 FLAGS_INIT_XGXS_FIRST);
7157 if (!(params->phy[EXT_PHY1].flags &
7158 FLAGS_INIT_XGXS_FIRST)
7159 && ext_phy_link_up && !vars->phy_link_up) {
7160 vars->line_speed = ext_phy_line_speed;
7161 if (vars->line_speed < SPEED_1000)
7162 vars->phy_flags |= PHY_SGMII_FLAG;
7163 else
7164 vars->phy_flags &= ~PHY_SGMII_FLAG;
Yaniv Rosnerec146a62011-05-31 21:29:27 +00007165
7166 if (params->phy[INT_PHY].config_init)
7167 params->phy[INT_PHY].config_init(
7168 &params->phy[INT_PHY], params,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007169 vars);
7170 }
7171 }
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00007172 /* Link is up only if both local phy and external phy (in case of
Yaniv Rosner9045f6b42011-05-31 21:28:27 +00007173 * non-direct board) are up and no fault detected on active PHY.
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007174 */
7175 vars->link_up = (vars->phy_link_up &&
7176 (ext_phy_link_up ||
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00007177 SINGLE_MEDIA_DIRECT(params)) &&
7178 (phy_vars[active_external_phy].fault_detected == 0));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07007179
Yaniv Rosner27d91292012-04-04 01:28:54 +00007180 /* Update the PFC configuration in case it was changed */
7181 if (params->feature_config_flags & FEATURE_CONFIG_PFC_ENABLED)
7182 vars->link_status |= LINK_STATUS_PFC_ENABLED;
7183 else
7184 vars->link_status &= ~LINK_STATUS_PFC_ENABLED;
7185
Yaniv Rosner57963ed2008-08-13 15:55:28 -07007186 if (vars->link_up)
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00007187 rc = bnx2x_update_link_up(params, vars, link_10g_plus);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07007188 else
7189 rc = bnx2x_update_link_down(params, vars);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07007190
Barak Witkowskia3348722012-04-23 03:04:46 +00007191 /* Update MCP link status was changed */
7192 if (params->feature_config_flags & FEATURE_CONFIG_BC_SUPPORTS_AFEX)
7193 bnx2x_fw_command(bp, DRV_MSG_CODE_LINK_STATUS_CHANGED, 0);
7194
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07007195 return rc;
7196}
7197
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007198/*****************************************************************************/
7199/* External Phy section */
7200/*****************************************************************************/
7201void bnx2x_ext_phy_hw_reset(struct bnx2x *bp, u8 port)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007202{
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007203 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007204 MISC_REGISTERS_GPIO_OUTPUT_LOW, port);
Yuval Mintzd2310232012-06-20 19:05:19 +00007205 usleep_range(1000, 2000);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007206 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007207 MISC_REGISTERS_GPIO_OUTPUT_HIGH, port);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007208}
7209
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007210static void bnx2x_save_spirom_version(struct bnx2x *bp, u8 port,
7211 u32 spirom_ver, u32 ver_addr)
7212{
7213 DP(NETIF_MSG_LINK, "FW version 0x%x:0x%x for port %d\n",
7214 (u16)(spirom_ver>>16), (u16)spirom_ver, port);
7215
7216 if (ver_addr)
7217 REG_WR(bp, ver_addr, spirom_ver);
7218}
7219
7220static void bnx2x_save_bcm_spirom_ver(struct bnx2x *bp,
7221 struct bnx2x_phy *phy,
7222 u8 port)
7223{
7224 u16 fw_ver1, fw_ver2;
7225
7226 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007227 MDIO_PMA_REG_ROM_VER1, &fw_ver1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007228 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007229 MDIO_PMA_REG_ROM_VER2, &fw_ver2);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007230 bnx2x_save_spirom_version(bp, port, (u32)(fw_ver1<<16 | fw_ver2),
7231 phy->ver_addr);
7232}
7233
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007234static void bnx2x_ext_phy_10G_an_resolve(struct bnx2x *bp,
7235 struct bnx2x_phy *phy,
7236 struct link_vars *vars)
7237{
7238 u16 val;
7239 bnx2x_cl45_read(bp, phy,
7240 MDIO_AN_DEVAD,
7241 MDIO_AN_REG_STATUS, &val);
7242 bnx2x_cl45_read(bp, phy,
7243 MDIO_AN_DEVAD,
7244 MDIO_AN_REG_STATUS, &val);
7245 if (val & (1<<5))
7246 vars->link_status |= LINK_STATUS_AUTO_NEGOTIATE_COMPLETE;
7247 if ((val & (1<<0)) == 0)
7248 vars->link_status |= LINK_STATUS_PARALLEL_DETECTION_USED;
7249}
7250
7251/******************************************************************/
7252/* common BCM8073/BCM8727 PHY SECTION */
7253/******************************************************************/
7254static void bnx2x_8073_resolve_fc(struct bnx2x_phy *phy,
7255 struct link_params *params,
7256 struct link_vars *vars)
7257{
7258 struct bnx2x *bp = params->bp;
7259 if (phy->req_line_speed == SPEED_10 ||
7260 phy->req_line_speed == SPEED_100) {
7261 vars->flow_ctrl = phy->req_flow_ctrl;
7262 return;
7263 }
7264
7265 if (bnx2x_ext_phy_resolve_fc(phy, params, vars) &&
7266 (vars->flow_ctrl == BNX2X_FLOW_CTRL_NONE)) {
7267 u16 pause_result;
7268 u16 ld_pause; /* local */
7269 u16 lp_pause; /* link partner */
7270 bnx2x_cl45_read(bp, phy,
7271 MDIO_AN_DEVAD,
7272 MDIO_AN_REG_CL37_FC_LD, &ld_pause);
7273
7274 bnx2x_cl45_read(bp, phy,
7275 MDIO_AN_DEVAD,
7276 MDIO_AN_REG_CL37_FC_LP, &lp_pause);
7277 pause_result = (ld_pause &
7278 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) >> 5;
7279 pause_result |= (lp_pause &
7280 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) >> 7;
7281
7282 bnx2x_pause_resolve(vars, pause_result);
7283 DP(NETIF_MSG_LINK, "Ext PHY CL37 pause result 0x%x\n",
7284 pause_result);
7285 }
7286}
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00007287static int bnx2x_8073_8727_external_rom_boot(struct bnx2x *bp,
7288 struct bnx2x_phy *phy,
7289 u8 port)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007290{
Yaniv Rosner5c99274b2011-01-18 04:33:36 +00007291 u32 count = 0;
7292 u16 fw_ver1, fw_msgout;
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00007293 int rc = 0;
Yaniv Rosner5c99274b2011-01-18 04:33:36 +00007294
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007295 /* Boot port from external ROM */
7296 /* EDC grst */
7297 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007298 MDIO_PMA_DEVAD,
7299 MDIO_PMA_REG_GEN_CTRL,
7300 0x0001);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007301
Yuval Mintzd2310232012-06-20 19:05:19 +00007302 /* Ucode reboot and rst */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007303 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007304 MDIO_PMA_DEVAD,
7305 MDIO_PMA_REG_GEN_CTRL,
7306 0x008c);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007307
7308 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007309 MDIO_PMA_DEVAD,
7310 MDIO_PMA_REG_MISC_CTRL1, 0x0001);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007311
7312 /* Reset internal microprocessor */
7313 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007314 MDIO_PMA_DEVAD,
7315 MDIO_PMA_REG_GEN_CTRL,
7316 MDIO_PMA_REG_GEN_CTRL_ROM_MICRO_RESET);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007317
7318 /* Release srst bit */
7319 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007320 MDIO_PMA_DEVAD,
7321 MDIO_PMA_REG_GEN_CTRL,
7322 MDIO_PMA_REG_GEN_CTRL_ROM_RESET_INTERNAL_MP);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007323
Yaniv Rosner5c99274b2011-01-18 04:33:36 +00007324 /* Delay 100ms per the PHY specifications */
7325 msleep(100);
7326
7327 /* 8073 sometimes taking longer to download */
7328 do {
7329 count++;
7330 if (count > 300) {
7331 DP(NETIF_MSG_LINK,
7332 "bnx2x_8073_8727_external_rom_boot port %x:"
7333 "Download failed. fw version = 0x%x\n",
7334 port, fw_ver1);
7335 rc = -EINVAL;
7336 break;
7337 }
7338
7339 bnx2x_cl45_read(bp, phy,
7340 MDIO_PMA_DEVAD,
7341 MDIO_PMA_REG_ROM_VER1, &fw_ver1);
7342 bnx2x_cl45_read(bp, phy,
7343 MDIO_PMA_DEVAD,
7344 MDIO_PMA_REG_M8051_MSGOUT_REG, &fw_msgout);
7345
Yuval Mintzd2310232012-06-20 19:05:19 +00007346 usleep_range(1000, 2000);
Yaniv Rosner5c99274b2011-01-18 04:33:36 +00007347 } while (fw_ver1 == 0 || fw_ver1 == 0x4321 ||
7348 ((fw_msgout & 0xff) != 0x03 && (phy->type ==
7349 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073)));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007350
7351 /* Clear ser_boot_ctl bit */
7352 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007353 MDIO_PMA_DEVAD,
7354 MDIO_PMA_REG_MISC_CTRL1, 0x0000);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007355 bnx2x_save_bcm_spirom_ver(bp, phy, port);
Yaniv Rosner5c99274b2011-01-18 04:33:36 +00007356
7357 DP(NETIF_MSG_LINK,
7358 "bnx2x_8073_8727_external_rom_boot port %x:"
7359 "Download complete. fw version = 0x%x\n",
7360 port, fw_ver1);
7361
7362 return rc;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007363}
7364
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007365/******************************************************************/
7366/* BCM8073 PHY SECTION */
7367/******************************************************************/
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00007368static int bnx2x_8073_is_snr_needed(struct bnx2x *bp, struct bnx2x_phy *phy)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007369{
7370 /* This is only required for 8073A1, version 102 only */
7371 u16 val;
7372
7373 /* Read 8073 HW revision*/
7374 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007375 MDIO_PMA_DEVAD,
7376 MDIO_PMA_REG_8073_CHIP_REV, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007377
7378 if (val != 1) {
7379 /* No need to workaround in 8073 A1 */
7380 return 0;
7381 }
7382
7383 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007384 MDIO_PMA_DEVAD,
7385 MDIO_PMA_REG_ROM_VER2, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007386
7387 /* SNR should be applied only for version 0x102 */
7388 if (val != 0x102)
7389 return 0;
7390
7391 return 1;
7392}
7393
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00007394static int bnx2x_8073_xaui_wa(struct bnx2x *bp, struct bnx2x_phy *phy)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007395{
7396 u16 val, cnt, cnt1 ;
7397
7398 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007399 MDIO_PMA_DEVAD,
7400 MDIO_PMA_REG_8073_CHIP_REV, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007401
7402 if (val > 0) {
7403 /* No need to workaround in 8073 A1 */
7404 return 0;
7405 }
7406 /* XAUI workaround in 8073 A0: */
7407
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00007408 /* After loading the boot ROM and restarting Autoneg, poll
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007409 * Dev1, Reg $C820:
7410 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007411
7412 for (cnt = 0; cnt < 1000; cnt++) {
7413 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007414 MDIO_PMA_DEVAD,
7415 MDIO_PMA_REG_8073_SPEED_LINK_STATUS,
7416 &val);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00007417 /* If bit [14] = 0 or bit [13] = 0, continue on with
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007418 * system initialization (XAUI work-around not required, as
7419 * these bits indicate 2.5G or 1G link up).
7420 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007421 if (!(val & (1<<14)) || !(val & (1<<13))) {
7422 DP(NETIF_MSG_LINK, "XAUI work-around not required\n");
7423 return 0;
7424 } else if (!(val & (1<<15))) {
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007425 DP(NETIF_MSG_LINK, "bit 15 went off\n");
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00007426 /* If bit 15 is 0, then poll Dev1, Reg $C841 until it's
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007427 * MSB (bit15) goes to 1 (indicating that the XAUI
7428 * workaround has completed), then continue on with
7429 * system initialization.
7430 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007431 for (cnt1 = 0; cnt1 < 1000; cnt1++) {
7432 bnx2x_cl45_read(bp, phy,
7433 MDIO_PMA_DEVAD,
7434 MDIO_PMA_REG_8073_XAUI_WA, &val);
7435 if (val & (1<<15)) {
7436 DP(NETIF_MSG_LINK,
7437 "XAUI workaround has completed\n");
7438 return 0;
7439 }
Yuval Mintzd2310232012-06-20 19:05:19 +00007440 usleep_range(3000, 6000);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007441 }
7442 break;
7443 }
Yuval Mintzd2310232012-06-20 19:05:19 +00007444 usleep_range(3000, 6000);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007445 }
7446 DP(NETIF_MSG_LINK, "Warning: XAUI work-around timeout !!!\n");
7447 return -EINVAL;
7448}
7449
7450static void bnx2x_807x_force_10G(struct bnx2x *bp, struct bnx2x_phy *phy)
7451{
7452 /* Force KR or KX */
7453 bnx2x_cl45_write(bp, phy,
7454 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x2040);
7455 bnx2x_cl45_write(bp, phy,
7456 MDIO_PMA_DEVAD, MDIO_PMA_REG_10G_CTRL2, 0x000b);
7457 bnx2x_cl45_write(bp, phy,
7458 MDIO_PMA_DEVAD, MDIO_PMA_REG_BCM_CTRL, 0x0000);
7459 bnx2x_cl45_write(bp, phy,
7460 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x0000);
7461}
7462
7463static void bnx2x_8073_set_pause_cl37(struct link_params *params,
7464 struct bnx2x_phy *phy,
7465 struct link_vars *vars)
7466{
7467 u16 cl37_val;
7468 struct bnx2x *bp = params->bp;
7469 bnx2x_cl45_read(bp, phy,
7470 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LD, &cl37_val);
7471
7472 cl37_val &= ~MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH;
7473 /* Please refer to Table 28B-3 of 802.3ab-1999 spec. */
7474 bnx2x_calc_ieee_aneg_adv(phy, params, &vars->ieee_fc);
7475 if ((vars->ieee_fc &
7476 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_SYMMETRIC) ==
7477 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_SYMMETRIC) {
7478 cl37_val |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_SYMMETRIC;
7479 }
7480 if ((vars->ieee_fc &
7481 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC) ==
7482 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC) {
7483 cl37_val |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC;
7484 }
7485 if ((vars->ieee_fc &
7486 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) ==
7487 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) {
7488 cl37_val |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH;
7489 }
7490 DP(NETIF_MSG_LINK,
7491 "Ext phy AN advertize cl37 0x%x\n", cl37_val);
7492
7493 bnx2x_cl45_write(bp, phy,
7494 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LD, cl37_val);
7495 msleep(500);
7496}
7497
Yaniv Rosner5c107fd2012-09-13 02:56:19 +00007498static void bnx2x_8073_specific_func(struct bnx2x_phy *phy,
7499 struct link_params *params,
7500 u32 action)
7501{
7502 struct bnx2x *bp = params->bp;
7503 switch (action) {
7504 case PHY_INIT:
7505 /* Enable LASI */
7506 bnx2x_cl45_write(bp, phy,
7507 MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXCTRL, (1<<2));
7508 bnx2x_cl45_write(bp, phy,
7509 MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL, 0x0004);
7510 break;
7511 }
7512}
7513
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00007514static int bnx2x_8073_config_init(struct bnx2x_phy *phy,
7515 struct link_params *params,
7516 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007517{
7518 struct bnx2x *bp = params->bp;
7519 u16 val = 0, tmp1;
7520 u8 gpio_port;
7521 DP(NETIF_MSG_LINK, "Init 8073\n");
7522
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007523 if (CHIP_IS_E2(bp))
7524 gpio_port = BP_PATH(bp);
7525 else
7526 gpio_port = params->port;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007527 /* Restore normal power mode*/
7528 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007529 MISC_REGISTERS_GPIO_OUTPUT_HIGH, gpio_port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007530
7531 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007532 MISC_REGISTERS_GPIO_OUTPUT_HIGH, gpio_port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007533
Yaniv Rosner5c107fd2012-09-13 02:56:19 +00007534 bnx2x_8073_specific_func(phy, params, PHY_INIT);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007535 bnx2x_8073_set_pause_cl37(params, phy, vars);
7536
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007537 bnx2x_cl45_read(bp, phy,
7538 MDIO_PMA_DEVAD, MDIO_PMA_REG_M8051_MSGOUT_REG, &tmp1);
7539
7540 bnx2x_cl45_read(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00007541 MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXSTAT, &tmp1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007542
7543 DP(NETIF_MSG_LINK, "Before rom RX_ALARM(port1): 0x%x\n", tmp1);
7544
Yaniv Rosner74d7a112011-01-18 04:33:18 +00007545 /* Swap polarity if required - Must be done only in non-1G mode */
7546 if (params->lane_config & PORT_HW_CFG_SWAP_PHY_POLARITY_ENABLED) {
7547 /* Configure the 8073 to swap _P and _N of the KR lines */
7548 DP(NETIF_MSG_LINK, "Swapping polarity for the 8073\n");
7549 /* 10G Rx/Tx and 1G Tx signal polarity swap */
7550 bnx2x_cl45_read(bp, phy,
7551 MDIO_PMA_DEVAD,
7552 MDIO_PMA_REG_8073_OPT_DIGITAL_CTRL, &val);
7553 bnx2x_cl45_write(bp, phy,
7554 MDIO_PMA_DEVAD,
7555 MDIO_PMA_REG_8073_OPT_DIGITAL_CTRL,
7556 (val | (3<<9)));
7557 }
7558
7559
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007560 /* Enable CL37 BAM */
Yaniv Rosner121839b2010-11-01 05:32:38 +00007561 if (REG_RD(bp, params->shmem_base +
7562 offsetof(struct shmem_region, dev_info.
7563 port_hw_config[params->port].default_cfg)) &
7564 PORT_HW_CFG_ENABLE_BAM_ON_KR_ENABLED) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007565
Yaniv Rosner121839b2010-11-01 05:32:38 +00007566 bnx2x_cl45_read(bp, phy,
7567 MDIO_AN_DEVAD,
7568 MDIO_AN_REG_8073_BAM, &val);
7569 bnx2x_cl45_write(bp, phy,
7570 MDIO_AN_DEVAD,
7571 MDIO_AN_REG_8073_BAM, val | 1);
7572 DP(NETIF_MSG_LINK, "Enable CL37 BAM on KR\n");
7573 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007574 if (params->loopback_mode == LOOPBACK_EXT) {
7575 bnx2x_807x_force_10G(bp, phy);
7576 DP(NETIF_MSG_LINK, "Forced speed 10G on 807X\n");
7577 return 0;
7578 } else {
7579 bnx2x_cl45_write(bp, phy,
7580 MDIO_PMA_DEVAD, MDIO_PMA_REG_BCM_CTRL, 0x0002);
7581 }
7582 if (phy->req_line_speed != SPEED_AUTO_NEG) {
7583 if (phy->req_line_speed == SPEED_10000) {
7584 val = (1<<7);
7585 } else if (phy->req_line_speed == SPEED_2500) {
7586 val = (1<<5);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00007587 /* Note that 2.5G works only when used with 1G
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007588 * advertisement
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007589 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007590 } else
7591 val = (1<<5);
7592 } else {
7593 val = 0;
7594 if (phy->speed_cap_mask &
7595 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
7596 val |= (1<<7);
7597
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007598 /* Note that 2.5G works only when used with 1G advertisement */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007599 if (phy->speed_cap_mask &
7600 (PORT_HW_CFG_SPEED_CAPABILITY_D0_1G |
7601 PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
7602 val |= (1<<5);
7603 DP(NETIF_MSG_LINK, "807x autoneg val = 0x%x\n", val);
7604 }
7605
7606 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV, val);
7607 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_8073_2_5G, &tmp1);
7608
7609 if (((phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G) &&
7610 (phy->req_line_speed == SPEED_AUTO_NEG)) ||
7611 (phy->req_line_speed == SPEED_2500)) {
7612 u16 phy_ver;
7613 /* Allow 2.5G for A1 and above */
7614 bnx2x_cl45_read(bp, phy,
7615 MDIO_PMA_DEVAD, MDIO_PMA_REG_8073_CHIP_REV,
7616 &phy_ver);
7617 DP(NETIF_MSG_LINK, "Add 2.5G\n");
7618 if (phy_ver > 0)
7619 tmp1 |= 1;
7620 else
7621 tmp1 &= 0xfffe;
7622 } else {
7623 DP(NETIF_MSG_LINK, "Disable 2.5G\n");
7624 tmp1 &= 0xfffe;
7625 }
7626
7627 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_8073_2_5G, tmp1);
7628 /* Add support for CL37 (passive mode) II */
7629
7630 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LD, &tmp1);
7631 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LD,
7632 (tmp1 | ((phy->req_duplex == DUPLEX_FULL) ?
7633 0x20 : 0x40)));
7634
7635 /* Add support for CL37 (passive mode) III */
7636 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CL37_AN, 0x1000);
7637
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00007638 /* The SNR will improve about 2db by changing BW and FEE main
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007639 * tap. Rest commands are executed after link is up
7640 * Change FFE main cursor to 5 in EDC register
7641 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007642 if (bnx2x_8073_is_snr_needed(bp, phy))
7643 bnx2x_cl45_write(bp, phy,
7644 MDIO_PMA_DEVAD, MDIO_PMA_REG_EDC_FFE_MAIN,
7645 0xFB0C);
7646
7647 /* Enable FEC (Forware Error Correction) Request in the AN */
7648 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV2, &tmp1);
7649 tmp1 |= (1<<15);
7650 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV2, tmp1);
7651
7652 bnx2x_ext_phy_set_pause(params, phy, vars);
7653
7654 /* Restart autoneg */
7655 msleep(500);
7656 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x1200);
7657 DP(NETIF_MSG_LINK, "807x Autoneg Restart: Advertise 1G=%x, 10G=%x\n",
7658 ((val & (1<<5)) > 0), ((val & (1<<7)) > 0));
7659 return 0;
7660}
7661
7662static u8 bnx2x_8073_read_status(struct bnx2x_phy *phy,
7663 struct link_params *params,
7664 struct link_vars *vars)
7665{
7666 struct bnx2x *bp = params->bp;
7667 u8 link_up = 0;
7668 u16 val1, val2;
7669 u16 link_status = 0;
7670 u16 an1000_status = 0;
7671
7672 bnx2x_cl45_read(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00007673 MDIO_PMA_DEVAD, MDIO_PMA_LASI_STAT, &val1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007674
7675 DP(NETIF_MSG_LINK, "8703 LASI status 0x%x\n", val1);
7676
Yuval Mintzd2310232012-06-20 19:05:19 +00007677 /* Clear the interrupt LASI status register */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007678 bnx2x_cl45_read(bp, phy,
7679 MDIO_PCS_DEVAD, MDIO_PCS_REG_STATUS, &val2);
7680 bnx2x_cl45_read(bp, phy,
7681 MDIO_PCS_DEVAD, MDIO_PCS_REG_STATUS, &val1);
7682 DP(NETIF_MSG_LINK, "807x PCS status 0x%x->0x%x\n", val2, val1);
7683 /* Clear MSG-OUT */
7684 bnx2x_cl45_read(bp, phy,
7685 MDIO_PMA_DEVAD, MDIO_PMA_REG_M8051_MSGOUT_REG, &val1);
7686
7687 /* Check the LASI */
7688 bnx2x_cl45_read(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00007689 MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXSTAT, &val2);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007690
7691 DP(NETIF_MSG_LINK, "KR 0x9003 0x%x\n", val2);
7692
7693 /* Check the link status */
7694 bnx2x_cl45_read(bp, phy,
7695 MDIO_PCS_DEVAD, MDIO_PCS_REG_STATUS, &val2);
7696 DP(NETIF_MSG_LINK, "KR PCS status 0x%x\n", val2);
7697
7698 bnx2x_cl45_read(bp, phy,
7699 MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val2);
7700 bnx2x_cl45_read(bp, phy,
7701 MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val1);
7702 link_up = ((val1 & 4) == 4);
7703 DP(NETIF_MSG_LINK, "PMA_REG_STATUS=0x%x\n", val1);
7704
7705 if (link_up &&
7706 ((phy->req_line_speed != SPEED_10000))) {
7707 if (bnx2x_8073_xaui_wa(bp, phy) != 0)
7708 return 0;
7709 }
7710 bnx2x_cl45_read(bp, phy,
7711 MDIO_AN_DEVAD, MDIO_AN_REG_LINK_STATUS, &an1000_status);
7712 bnx2x_cl45_read(bp, phy,
7713 MDIO_AN_DEVAD, MDIO_AN_REG_LINK_STATUS, &an1000_status);
7714
7715 /* Check the link status on 1.1.2 */
7716 bnx2x_cl45_read(bp, phy,
7717 MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val2);
7718 bnx2x_cl45_read(bp, phy,
7719 MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val1);
7720 DP(NETIF_MSG_LINK, "KR PMA status 0x%x->0x%x,"
7721 "an_link_status=0x%x\n", val2, val1, an1000_status);
7722
7723 link_up = (((val1 & 4) == 4) || (an1000_status & (1<<1)));
7724 if (link_up && bnx2x_8073_is_snr_needed(bp, phy)) {
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00007725 /* The SNR will improve about 2dbby changing the BW and FEE main
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007726 * tap. The 1st write to change FFE main tap is set before
7727 * restart AN. Change PLL Bandwidth in EDC register
7728 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007729 bnx2x_cl45_write(bp, phy,
7730 MDIO_PMA_DEVAD, MDIO_PMA_REG_PLL_BANDWIDTH,
7731 0x26BC);
7732
7733 /* Change CDR Bandwidth in EDC register */
7734 bnx2x_cl45_write(bp, phy,
7735 MDIO_PMA_DEVAD, MDIO_PMA_REG_CDR_BANDWIDTH,
7736 0x0333);
7737 }
7738 bnx2x_cl45_read(bp, phy,
7739 MDIO_PMA_DEVAD, MDIO_PMA_REG_8073_SPEED_LINK_STATUS,
7740 &link_status);
7741
7742 /* Bits 0..2 --> speed detected, bits 13..15--> link is down */
7743 if ((link_status & (1<<2)) && (!(link_status & (1<<15)))) {
7744 link_up = 1;
7745 vars->line_speed = SPEED_10000;
7746 DP(NETIF_MSG_LINK, "port %x: External link up in 10G\n",
7747 params->port);
7748 } else if ((link_status & (1<<1)) && (!(link_status & (1<<14)))) {
7749 link_up = 1;
7750 vars->line_speed = SPEED_2500;
7751 DP(NETIF_MSG_LINK, "port %x: External link up in 2.5G\n",
7752 params->port);
7753 } else if ((link_status & (1<<0)) && (!(link_status & (1<<13)))) {
7754 link_up = 1;
7755 vars->line_speed = SPEED_1000;
7756 DP(NETIF_MSG_LINK, "port %x: External link up in 1G\n",
7757 params->port);
7758 } else {
7759 link_up = 0;
7760 DP(NETIF_MSG_LINK, "port %x: External link is down\n",
7761 params->port);
7762 }
7763
7764 if (link_up) {
Yaniv Rosner74d7a112011-01-18 04:33:18 +00007765 /* Swap polarity if required */
7766 if (params->lane_config &
7767 PORT_HW_CFG_SWAP_PHY_POLARITY_ENABLED) {
7768 /* Configure the 8073 to swap P and N of the KR lines */
7769 bnx2x_cl45_read(bp, phy,
7770 MDIO_XS_DEVAD,
7771 MDIO_XS_REG_8073_RX_CTRL_PCIE, &val1);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00007772 /* Set bit 3 to invert Rx in 1G mode and clear this bit
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007773 * when it`s in 10G mode.
7774 */
Yaniv Rosner74d7a112011-01-18 04:33:18 +00007775 if (vars->line_speed == SPEED_1000) {
7776 DP(NETIF_MSG_LINK, "Swapping 1G polarity for"
7777 "the 8073\n");
7778 val1 |= (1<<3);
7779 } else
7780 val1 &= ~(1<<3);
7781
7782 bnx2x_cl45_write(bp, phy,
7783 MDIO_XS_DEVAD,
7784 MDIO_XS_REG_8073_RX_CTRL_PCIE,
7785 val1);
7786 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007787 bnx2x_ext_phy_10G_an_resolve(bp, phy, vars);
7788 bnx2x_8073_resolve_fc(phy, params, vars);
Yaniv Rosner791f18c2011-01-18 04:33:42 +00007789 vars->duplex = DUPLEX_FULL;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007790 }
Mintz Yuval9e7e8392012-02-15 02:10:24 +00007791
7792 if (vars->link_status & LINK_STATUS_AUTO_NEGOTIATE_COMPLETE) {
7793 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
7794 MDIO_AN_REG_LP_AUTO_NEG2, &val1);
7795
7796 if (val1 & (1<<5))
7797 vars->link_status |=
7798 LINK_STATUS_LINK_PARTNER_1000TFD_CAPABLE;
7799 if (val1 & (1<<7))
7800 vars->link_status |=
7801 LINK_STATUS_LINK_PARTNER_10GXFD_CAPABLE;
7802 }
7803
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007804 return link_up;
7805}
7806
7807static void bnx2x_8073_link_reset(struct bnx2x_phy *phy,
7808 struct link_params *params)
7809{
7810 struct bnx2x *bp = params->bp;
7811 u8 gpio_port;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007812 if (CHIP_IS_E2(bp))
7813 gpio_port = BP_PATH(bp);
7814 else
7815 gpio_port = params->port;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007816 DP(NETIF_MSG_LINK, "Setting 8073 port %d into low power mode\n",
7817 gpio_port);
7818 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007819 MISC_REGISTERS_GPIO_OUTPUT_LOW,
7820 gpio_port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007821}
7822
7823/******************************************************************/
7824/* BCM8705 PHY SECTION */
7825/******************************************************************/
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00007826static int bnx2x_8705_config_init(struct bnx2x_phy *phy,
7827 struct link_params *params,
7828 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007829{
7830 struct bnx2x *bp = params->bp;
7831 DP(NETIF_MSG_LINK, "init 8705\n");
7832 /* Restore normal power mode*/
7833 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007834 MISC_REGISTERS_GPIO_OUTPUT_HIGH, params->port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007835 /* HW reset */
7836 bnx2x_ext_phy_hw_reset(bp, params->port);
7837 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0xa040);
Yaniv Rosner6d870c32011-01-31 04:22:20 +00007838 bnx2x_wait_reset_complete(bp, phy, params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007839
7840 bnx2x_cl45_write(bp, phy,
7841 MDIO_PMA_DEVAD, MDIO_PMA_REG_MISC_CTRL, 0x8288);
7842 bnx2x_cl45_write(bp, phy,
7843 MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER, 0x7fbf);
7844 bnx2x_cl45_write(bp, phy,
7845 MDIO_PMA_DEVAD, MDIO_PMA_REG_CMU_PLL_BYPASS, 0x0100);
7846 bnx2x_cl45_write(bp, phy,
7847 MDIO_WIS_DEVAD, MDIO_WIS_REG_LASI_CNTL, 0x1);
7848 /* BCM8705 doesn't have microcode, hence the 0 */
7849 bnx2x_save_spirom_version(bp, params->port, params->shmem_base, 0);
7850 return 0;
7851}
7852
7853static u8 bnx2x_8705_read_status(struct bnx2x_phy *phy,
7854 struct link_params *params,
7855 struct link_vars *vars)
7856{
7857 u8 link_up = 0;
7858 u16 val1, rx_sd;
7859 struct bnx2x *bp = params->bp;
7860 DP(NETIF_MSG_LINK, "read status 8705\n");
7861 bnx2x_cl45_read(bp, phy,
7862 MDIO_WIS_DEVAD, MDIO_WIS_REG_LASI_STATUS, &val1);
7863 DP(NETIF_MSG_LINK, "8705 LASI status 0x%x\n", val1);
7864
7865 bnx2x_cl45_read(bp, phy,
7866 MDIO_WIS_DEVAD, MDIO_WIS_REG_LASI_STATUS, &val1);
7867 DP(NETIF_MSG_LINK, "8705 LASI status 0x%x\n", val1);
7868
7869 bnx2x_cl45_read(bp, phy,
7870 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_SD, &rx_sd);
7871
7872 bnx2x_cl45_read(bp, phy,
7873 MDIO_PMA_DEVAD, 0xc809, &val1);
7874 bnx2x_cl45_read(bp, phy,
7875 MDIO_PMA_DEVAD, 0xc809, &val1);
7876
7877 DP(NETIF_MSG_LINK, "8705 1.c809 val=0x%x\n", val1);
7878 link_up = ((rx_sd & 0x1) && (val1 & (1<<9)) && ((val1 & (1<<8)) == 0));
7879 if (link_up) {
7880 vars->line_speed = SPEED_10000;
7881 bnx2x_ext_phy_resolve_fc(phy, params, vars);
7882 }
7883 return link_up;
7884}
7885
7886/******************************************************************/
7887/* SFP+ module Section */
7888/******************************************************************/
Yaniv Rosner85242ee2011-07-05 01:06:53 +00007889static void bnx2x_set_disable_pmd_transmit(struct link_params *params,
7890 struct bnx2x_phy *phy,
7891 u8 pmd_dis)
7892{
7893 struct bnx2x *bp = params->bp;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00007894 /* Disable transmitter only for bootcodes which can enable it afterwards
Yaniv Rosner85242ee2011-07-05 01:06:53 +00007895 * (for D3 link)
7896 */
7897 if (pmd_dis) {
7898 if (params->feature_config_flags &
7899 FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED)
7900 DP(NETIF_MSG_LINK, "Disabling PMD transmitter\n");
7901 else {
7902 DP(NETIF_MSG_LINK, "NOT disabling PMD transmitter\n");
7903 return;
7904 }
7905 } else
7906 DP(NETIF_MSG_LINK, "Enabling PMD transmitter\n");
7907 bnx2x_cl45_write(bp, phy,
7908 MDIO_PMA_DEVAD,
7909 MDIO_PMA_REG_TX_DISABLE, pmd_dis);
7910}
7911
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00007912static u8 bnx2x_get_gpio_port(struct link_params *params)
7913{
7914 u8 gpio_port;
7915 u32 swap_val, swap_override;
7916 struct bnx2x *bp = params->bp;
7917 if (CHIP_IS_E2(bp))
7918 gpio_port = BP_PATH(bp);
7919 else
7920 gpio_port = params->port;
7921 swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
7922 swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
7923 return gpio_port ^ (swap_val && swap_override);
7924}
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00007925
7926static void bnx2x_sfp_e1e2_set_transmitter(struct link_params *params,
7927 struct bnx2x_phy *phy,
7928 u8 tx_en)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007929{
7930 u16 val;
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00007931 u8 port = params->port;
7932 struct bnx2x *bp = params->bp;
7933 u32 tx_en_mode;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007934
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007935 /* Disable/Enable transmitter ( TX laser of the SFP+ module.)*/
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00007936 tx_en_mode = REG_RD(bp, params->shmem_base +
7937 offsetof(struct shmem_region,
7938 dev_info.port_hw_config[port].sfp_ctrl)) &
7939 PORT_HW_CFG_TX_LASER_MASK;
7940 DP(NETIF_MSG_LINK, "Setting transmitter tx_en=%x for port %x "
7941 "mode = %x\n", tx_en, port, tx_en_mode);
7942 switch (tx_en_mode) {
7943 case PORT_HW_CFG_TX_LASER_MDIO:
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007944
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00007945 bnx2x_cl45_read(bp, phy,
7946 MDIO_PMA_DEVAD,
7947 MDIO_PMA_REG_PHY_IDENTIFIER,
7948 &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007949
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00007950 if (tx_en)
7951 val &= ~(1<<15);
7952 else
7953 val |= (1<<15);
7954
7955 bnx2x_cl45_write(bp, phy,
7956 MDIO_PMA_DEVAD,
7957 MDIO_PMA_REG_PHY_IDENTIFIER,
7958 val);
7959 break;
7960 case PORT_HW_CFG_TX_LASER_GPIO0:
7961 case PORT_HW_CFG_TX_LASER_GPIO1:
7962 case PORT_HW_CFG_TX_LASER_GPIO2:
7963 case PORT_HW_CFG_TX_LASER_GPIO3:
7964 {
7965 u16 gpio_pin;
7966 u8 gpio_port, gpio_mode;
7967 if (tx_en)
7968 gpio_mode = MISC_REGISTERS_GPIO_OUTPUT_HIGH;
7969 else
7970 gpio_mode = MISC_REGISTERS_GPIO_OUTPUT_LOW;
7971
7972 gpio_pin = tx_en_mode - PORT_HW_CFG_TX_LASER_GPIO0;
7973 gpio_port = bnx2x_get_gpio_port(params);
7974 bnx2x_set_gpio(bp, gpio_pin, gpio_mode, gpio_port);
7975 break;
7976 }
7977 default:
7978 DP(NETIF_MSG_LINK, "Invalid TX_LASER_MDIO 0x%x\n", tx_en_mode);
7979 break;
7980 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007981}
7982
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00007983static void bnx2x_sfp_set_transmitter(struct link_params *params,
7984 struct bnx2x_phy *phy,
7985 u8 tx_en)
7986{
7987 struct bnx2x *bp = params->bp;
7988 DP(NETIF_MSG_LINK, "Setting SFP+ transmitter to %d\n", tx_en);
7989 if (CHIP_IS_E3(bp))
7990 bnx2x_sfp_e3_set_transmitter(params, phy, tx_en);
7991 else
7992 bnx2x_sfp_e1e2_set_transmitter(params, phy, tx_en);
7993}
7994
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00007995static int bnx2x_8726_read_sfp_module_eeprom(struct bnx2x_phy *phy,
7996 struct link_params *params,
7997 u16 addr, u8 byte_cnt, u8 *o_buf)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007998{
7999 struct bnx2x *bp = params->bp;
8000 u16 val = 0;
8001 u16 i;
Yuval Mintz24ea8182012-06-20 19:05:23 +00008002 if (byte_cnt > SFP_EEPROM_PAGE_SIZE) {
Joe Perches94f05b02011-08-14 12:16:20 +00008003 DP(NETIF_MSG_LINK,
8004 "Reading from eeprom is limited to 0xf\n");
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008005 return -EINVAL;
8006 }
8007 /* Set the read command byte count */
8008 bnx2x_cl45_write(bp, phy,
8009 MDIO_PMA_DEVAD, MDIO_PMA_REG_SFP_TWO_WIRE_BYTE_CNT,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008010 (byte_cnt | 0xa000));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008011
8012 /* Set the read command address */
8013 bnx2x_cl45_write(bp, phy,
8014 MDIO_PMA_DEVAD, MDIO_PMA_REG_SFP_TWO_WIRE_MEM_ADDR,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008015 addr);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008016
8017 /* Activate read command */
8018 bnx2x_cl45_write(bp, phy,
8019 MDIO_PMA_DEVAD, MDIO_PMA_REG_SFP_TWO_WIRE_CTRL,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008020 0x2c0f);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008021
8022 /* Wait up to 500us for command complete status */
8023 for (i = 0; i < 100; i++) {
8024 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008025 MDIO_PMA_DEVAD,
8026 MDIO_PMA_REG_SFP_TWO_WIRE_CTRL, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008027 if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) ==
8028 MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_COMPLETE)
8029 break;
8030 udelay(5);
8031 }
8032
8033 if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) !=
8034 MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_COMPLETE) {
8035 DP(NETIF_MSG_LINK,
8036 "Got bad status 0x%x when reading from SFP+ EEPROM\n",
8037 (val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK));
8038 return -EINVAL;
8039 }
8040
8041 /* Read the buffer */
8042 for (i = 0; i < byte_cnt; i++) {
8043 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008044 MDIO_PMA_DEVAD,
8045 MDIO_PMA_REG_8726_TWO_WIRE_DATA_BUF + i, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008046 o_buf[i] = (u8)(val & MDIO_PMA_REG_8726_TWO_WIRE_DATA_MASK);
8047 }
8048
8049 for (i = 0; i < 100; i++) {
8050 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008051 MDIO_PMA_DEVAD,
8052 MDIO_PMA_REG_SFP_TWO_WIRE_CTRL, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008053 if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) ==
8054 MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_IDLE)
Joe Perches6f38ad92010-11-14 17:04:31 +00008055 return 0;
Yuval Mintzd2310232012-06-20 19:05:19 +00008056 usleep_range(1000, 2000);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008057 }
8058 return -EINVAL;
8059}
8060
Yuval Mintz50a29842012-06-16 20:27:14 +00008061static void bnx2x_warpcore_power_module(struct link_params *params,
8062 struct bnx2x_phy *phy,
8063 u8 power)
8064{
8065 u32 pin_cfg;
8066 struct bnx2x *bp = params->bp;
8067
8068 pin_cfg = (REG_RD(bp, params->shmem_base +
8069 offsetof(struct shmem_region,
8070 dev_info.port_hw_config[params->port].e3_sfp_ctrl)) &
8071 PORT_HW_CFG_E3_PWR_DIS_MASK) >>
8072 PORT_HW_CFG_E3_PWR_DIS_SHIFT;
8073
8074 if (pin_cfg == PIN_CFG_NA)
8075 return;
8076 DP(NETIF_MSG_LINK, "Setting SFP+ module power to %d using pin cfg %d\n",
8077 power, pin_cfg);
8078 /* Low ==> corresponding SFP+ module is powered
8079 * high ==> the SFP+ module is powered down
8080 */
8081 bnx2x_set_cfg_pin(bp, pin_cfg, power ^ 1);
8082}
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008083static int bnx2x_warpcore_read_sfp_module_eeprom(struct bnx2x_phy *phy,
8084 struct link_params *params,
8085 u16 addr, u8 byte_cnt,
8086 u8 *o_buf)
8087{
8088 int rc = 0;
8089 u8 i, j = 0, cnt = 0;
8090 u32 data_array[4];
8091 u16 addr32;
8092 struct bnx2x *bp = params->bp;
Yuval Mintz24ea8182012-06-20 19:05:23 +00008093
8094 if (byte_cnt > SFP_EEPROM_PAGE_SIZE) {
Joe Perches94f05b02011-08-14 12:16:20 +00008095 DP(NETIF_MSG_LINK,
8096 "Reading from eeprom is limited to 16 bytes\n");
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008097 return -EINVAL;
8098 }
8099
8100 /* 4 byte aligned address */
8101 addr32 = addr & (~0x3);
8102 do {
Yuval Mintz50a29842012-06-16 20:27:14 +00008103 if (cnt == I2C_WA_PWR_ITER) {
8104 bnx2x_warpcore_power_module(params, phy, 0);
8105 /* Note that 100us are not enough here */
8106 usleep_range(1000,1000);
8107 bnx2x_warpcore_power_module(params, phy, 1);
8108 }
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008109 rc = bnx2x_bsc_read(params, phy, 0xa0, addr32, 0, byte_cnt,
8110 data_array);
8111 } while ((rc != 0) && (++cnt < I2C_WA_RETRY_CNT));
8112
8113 if (rc == 0) {
8114 for (i = (addr - addr32); i < byte_cnt + (addr - addr32); i++) {
8115 o_buf[j] = *((u8 *)data_array + i);
8116 j++;
8117 }
8118 }
8119
8120 return rc;
8121}
8122
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00008123static int bnx2x_8727_read_sfp_module_eeprom(struct bnx2x_phy *phy,
8124 struct link_params *params,
8125 u16 addr, u8 byte_cnt, u8 *o_buf)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008126{
8127 struct bnx2x *bp = params->bp;
8128 u16 val, i;
8129
Yuval Mintz24ea8182012-06-20 19:05:23 +00008130 if (byte_cnt > SFP_EEPROM_PAGE_SIZE) {
Joe Perches94f05b02011-08-14 12:16:20 +00008131 DP(NETIF_MSG_LINK,
8132 "Reading from eeprom is limited to 0xf\n");
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008133 return -EINVAL;
8134 }
8135
8136 /* Need to read from 1.8000 to clear it */
8137 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008138 MDIO_PMA_DEVAD,
8139 MDIO_PMA_REG_SFP_TWO_WIRE_CTRL,
8140 &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008141
8142 /* Set the read command byte count */
8143 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008144 MDIO_PMA_DEVAD,
8145 MDIO_PMA_REG_SFP_TWO_WIRE_BYTE_CNT,
8146 ((byte_cnt < 2) ? 2 : byte_cnt));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008147
8148 /* Set the read command address */
8149 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008150 MDIO_PMA_DEVAD,
8151 MDIO_PMA_REG_SFP_TWO_WIRE_MEM_ADDR,
8152 addr);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008153 /* Set the destination address */
8154 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008155 MDIO_PMA_DEVAD,
8156 0x8004,
8157 MDIO_PMA_REG_8727_TWO_WIRE_DATA_BUF);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008158
8159 /* Activate read command */
8160 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008161 MDIO_PMA_DEVAD,
8162 MDIO_PMA_REG_SFP_TWO_WIRE_CTRL,
8163 0x8002);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00008164 /* Wait appropriate time for two-wire command to finish before
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008165 * polling the status register
8166 */
Yuval Mintzd2310232012-06-20 19:05:19 +00008167 usleep_range(1000, 2000);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008168
8169 /* Wait up to 500us for command complete status */
8170 for (i = 0; i < 100; i++) {
8171 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008172 MDIO_PMA_DEVAD,
8173 MDIO_PMA_REG_SFP_TWO_WIRE_CTRL, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008174 if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) ==
8175 MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_COMPLETE)
8176 break;
8177 udelay(5);
8178 }
8179
8180 if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) !=
8181 MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_COMPLETE) {
8182 DP(NETIF_MSG_LINK,
8183 "Got bad status 0x%x when reading from SFP+ EEPROM\n",
8184 (val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK));
Yaniv Rosner65a001b2011-01-31 04:22:03 +00008185 return -EFAULT;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008186 }
8187
8188 /* Read the buffer */
8189 for (i = 0; i < byte_cnt; i++) {
8190 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008191 MDIO_PMA_DEVAD,
8192 MDIO_PMA_REG_8727_TWO_WIRE_DATA_BUF + i, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008193 o_buf[i] = (u8)(val & MDIO_PMA_REG_8727_TWO_WIRE_DATA_MASK);
8194 }
8195
8196 for (i = 0; i < 100; i++) {
8197 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008198 MDIO_PMA_DEVAD,
8199 MDIO_PMA_REG_SFP_TWO_WIRE_CTRL, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008200 if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) ==
8201 MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_IDLE)
Joe Perches6f38ad92010-11-14 17:04:31 +00008202 return 0;
Yuval Mintzd2310232012-06-20 19:05:19 +00008203 usleep_range(1000, 2000);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008204 }
8205
8206 return -EINVAL;
8207}
8208
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00008209int bnx2x_read_sfp_module_eeprom(struct bnx2x_phy *phy,
8210 struct link_params *params, u16 addr,
8211 u8 byte_cnt, u8 *o_buf)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008212{
Yuval Mintz24ea8182012-06-20 19:05:23 +00008213 int rc = -EOPNOTSUPP;
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00008214 switch (phy->type) {
8215 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
8216 rc = bnx2x_8726_read_sfp_module_eeprom(phy, params, addr,
8217 byte_cnt, o_buf);
8218 break;
8219 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
8220 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8722:
8221 rc = bnx2x_8727_read_sfp_module_eeprom(phy, params, addr,
8222 byte_cnt, o_buf);
8223 break;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008224 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT:
8225 rc = bnx2x_warpcore_read_sfp_module_eeprom(phy, params, addr,
8226 byte_cnt, o_buf);
8227 break;
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00008228 }
8229 return rc;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008230}
8231
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00008232static int bnx2x_get_edc_mode(struct bnx2x_phy *phy,
8233 struct link_params *params,
8234 u16 *edc_mode)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008235{
8236 struct bnx2x *bp = params->bp;
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00008237 u32 sync_offset = 0, phy_idx, media_types;
Yuval Mintzdbef8072012-06-20 19:05:22 +00008238 u8 val[2], check_limiting_mode = 0;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008239 *edc_mode = EDC_MODE_LIMITING;
8240
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00008241 phy->media_type = ETH_PHY_UNSPECIFIED;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008242 /* First check for copper cable */
8243 if (bnx2x_read_sfp_module_eeprom(phy,
8244 params,
8245 SFP_EEPROM_CON_TYPE_ADDR,
Yuval Mintzdbef8072012-06-20 19:05:22 +00008246 2,
8247 (u8 *)val) != 0) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008248 DP(NETIF_MSG_LINK, "Failed to read from SFP+ module EEPROM\n");
8249 return -EINVAL;
8250 }
8251
Yuval Mintzdbef8072012-06-20 19:05:22 +00008252 switch (val[0]) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008253 case SFP_EEPROM_CON_TYPE_VAL_COPPER:
8254 {
8255 u8 copper_module_type;
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00008256 phy->media_type = ETH_PHY_DA_TWINAX;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00008257 /* Check if its active cable (includes SFP+ module)
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008258 * of passive cable
8259 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008260 if (bnx2x_read_sfp_module_eeprom(phy,
8261 params,
8262 SFP_EEPROM_FC_TX_TECH_ADDR,
8263 1,
Yaniv Rosner9045f6b42011-05-31 21:28:27 +00008264 &copper_module_type) != 0) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008265 DP(NETIF_MSG_LINK,
8266 "Failed to read copper-cable-type"
8267 " from SFP+ EEPROM\n");
8268 return -EINVAL;
8269 }
8270
8271 if (copper_module_type &
8272 SFP_EEPROM_FC_TX_TECH_BITMASK_COPPER_ACTIVE) {
8273 DP(NETIF_MSG_LINK, "Active Copper cable detected\n");
8274 check_limiting_mode = 1;
8275 } else if (copper_module_type &
8276 SFP_EEPROM_FC_TX_TECH_BITMASK_COPPER_PASSIVE) {
Joe Perches94f05b02011-08-14 12:16:20 +00008277 DP(NETIF_MSG_LINK,
8278 "Passive Copper cable detected\n");
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008279 *edc_mode =
8280 EDC_MODE_PASSIVE_DAC;
8281 } else {
Joe Perches94f05b02011-08-14 12:16:20 +00008282 DP(NETIF_MSG_LINK,
8283 "Unknown copper-cable-type 0x%x !!!\n",
8284 copper_module_type);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008285 return -EINVAL;
8286 }
8287 break;
8288 }
8289 case SFP_EEPROM_CON_TYPE_VAL_LC:
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008290 check_limiting_mode = 1;
Yuval Mintzdbef8072012-06-20 19:05:22 +00008291 if ((val[1] & (SFP_EEPROM_COMP_CODE_SR_MASK |
8292 SFP_EEPROM_COMP_CODE_LR_MASK |
8293 SFP_EEPROM_COMP_CODE_LRM_MASK)) == 0) {
8294 DP(NETIF_MSG_LINK, "1G Optic module detected\n");
8295 phy->media_type = ETH_PHY_SFP_1G_FIBER;
8296 phy->req_line_speed = SPEED_1000;
8297 } else {
8298 int idx, cfg_idx = 0;
8299 DP(NETIF_MSG_LINK, "10G Optic module detected\n");
8300 for (idx = INT_PHY; idx < MAX_PHYS; idx++) {
8301 if (params->phy[idx].type == phy->type) {
8302 cfg_idx = LINK_CONFIG_IDX(idx);
8303 break;
8304 }
8305 }
8306 phy->media_type = ETH_PHY_SFPP_10G_FIBER;
8307 phy->req_line_speed = params->req_line_speed[cfg_idx];
8308 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008309 break;
8310 default:
8311 DP(NETIF_MSG_LINK, "Unable to determine module type 0x%x !!!\n",
Yuval Mintzdbef8072012-06-20 19:05:22 +00008312 val[0]);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008313 return -EINVAL;
8314 }
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00008315 sync_offset = params->shmem_base +
8316 offsetof(struct shmem_region,
8317 dev_info.port_hw_config[params->port].media_type);
8318 media_types = REG_RD(bp, sync_offset);
8319 /* Update media type for non-PMF sync */
8320 for (phy_idx = INT_PHY; phy_idx < MAX_PHYS; phy_idx++) {
8321 if (&(params->phy[phy_idx]) == phy) {
8322 media_types &= ~(PORT_HW_CFG_MEDIA_TYPE_PHY0_MASK <<
8323 (PORT_HW_CFG_MEDIA_TYPE_PHY1_SHIFT * phy_idx));
8324 media_types |= ((phy->media_type &
8325 PORT_HW_CFG_MEDIA_TYPE_PHY0_MASK) <<
8326 (PORT_HW_CFG_MEDIA_TYPE_PHY1_SHIFT * phy_idx));
8327 break;
8328 }
8329 }
8330 REG_WR(bp, sync_offset, media_types);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008331 if (check_limiting_mode) {
8332 u8 options[SFP_EEPROM_OPTIONS_SIZE];
8333 if (bnx2x_read_sfp_module_eeprom(phy,
8334 params,
8335 SFP_EEPROM_OPTIONS_ADDR,
8336 SFP_EEPROM_OPTIONS_SIZE,
8337 options) != 0) {
Joe Perches94f05b02011-08-14 12:16:20 +00008338 DP(NETIF_MSG_LINK,
8339 "Failed to read Option field from module EEPROM\n");
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008340 return -EINVAL;
8341 }
8342 if ((options[0] & SFP_EEPROM_OPTIONS_LINEAR_RX_OUT_MASK))
8343 *edc_mode = EDC_MODE_LINEAR;
8344 else
8345 *edc_mode = EDC_MODE_LIMITING;
8346 }
8347 DP(NETIF_MSG_LINK, "EDC mode is set to 0x%x\n", *edc_mode);
8348 return 0;
8349}
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00008350/* This function read the relevant field from the module (SFP+), and verify it
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008351 * is compliant with this board
8352 */
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00008353static int bnx2x_verify_sfp_module(struct bnx2x_phy *phy,
8354 struct link_params *params)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008355{
8356 struct bnx2x *bp = params->bp;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008357 u32 val, cmd;
8358 u32 fw_resp, fw_cmd_param;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008359 char vendor_name[SFP_EEPROM_VENDOR_NAME_SIZE+1];
8360 char vendor_pn[SFP_EEPROM_PART_NO_SIZE+1];
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008361 phy->flags &= ~FLAGS_SFP_NOT_APPROVED;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008362 val = REG_RD(bp, params->shmem_base +
8363 offsetof(struct shmem_region, dev_info.
8364 port_feature_config[params->port].config));
8365 if ((val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) ==
8366 PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_NO_ENFORCEMENT) {
8367 DP(NETIF_MSG_LINK, "NOT enforcing module verification\n");
8368 return 0;
8369 }
8370
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008371 if (params->feature_config_flags &
8372 FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY) {
8373 /* Use specific phy request */
8374 cmd = DRV_MSG_CODE_VRFY_SPECIFIC_PHY_OPT_MDL;
8375 } else if (params->feature_config_flags &
8376 FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY) {
8377 /* Use first phy request only in case of non-dual media*/
8378 if (DUAL_MEDIA(params)) {
Joe Perches94f05b02011-08-14 12:16:20 +00008379 DP(NETIF_MSG_LINK,
8380 "FW does not support OPT MDL verification\n");
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008381 return -EINVAL;
8382 }
8383 cmd = DRV_MSG_CODE_VRFY_FIRST_PHY_OPT_MDL;
8384 } else {
8385 /* No support in OPT MDL detection */
Joe Perches94f05b02011-08-14 12:16:20 +00008386 DP(NETIF_MSG_LINK,
8387 "FW does not support OPT MDL verification\n");
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008388 return -EINVAL;
8389 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008390
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008391 fw_cmd_param = FW_PARAM_SET(phy->addr, phy->type, phy->mdio_ctrl);
8392 fw_resp = bnx2x_fw_command(bp, cmd, fw_cmd_param);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008393 if (fw_resp == FW_MSG_CODE_VRFY_OPT_MDL_SUCCESS) {
8394 DP(NETIF_MSG_LINK, "Approved module\n");
8395 return 0;
8396 }
8397
Yuval Mintzd2310232012-06-20 19:05:19 +00008398 /* Format the warning message */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008399 if (bnx2x_read_sfp_module_eeprom(phy,
8400 params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008401 SFP_EEPROM_VENDOR_NAME_ADDR,
8402 SFP_EEPROM_VENDOR_NAME_SIZE,
8403 (u8 *)vendor_name))
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008404 vendor_name[0] = '\0';
8405 else
8406 vendor_name[SFP_EEPROM_VENDOR_NAME_SIZE] = '\0';
8407 if (bnx2x_read_sfp_module_eeprom(phy,
8408 params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008409 SFP_EEPROM_PART_NO_ADDR,
8410 SFP_EEPROM_PART_NO_SIZE,
8411 (u8 *)vendor_pn))
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008412 vendor_pn[0] = '\0';
8413 else
8414 vendor_pn[SFP_EEPROM_PART_NO_SIZE] = '\0';
8415
Yaniv Rosner6d870c32011-01-31 04:22:20 +00008416 netdev_err(bp->dev, "Warning: Unqualified SFP+ module detected,"
8417 " Port %d from %s part number %s\n",
8418 params->port, vendor_name, vendor_pn);
Yaniv Rosner59a2e532012-04-04 01:28:59 +00008419 if ((val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) !=
8420 PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_WARNING_MSG)
8421 phy->flags |= FLAGS_SFP_NOT_APPROVED;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008422 return -EINVAL;
8423}
8424
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00008425static int bnx2x_wait_for_sfp_module_initialized(struct bnx2x_phy *phy,
8426 struct link_params *params)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008427
8428{
8429 u8 val;
8430 struct bnx2x *bp = params->bp;
8431 u16 timeout;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00008432 /* Initialization time after hot-plug may take up to 300ms for
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008433 * some phys type ( e.g. JDSU )
8434 */
8435
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008436 for (timeout = 0; timeout < 60; timeout++) {
8437 if (bnx2x_read_sfp_module_eeprom(phy, params, 1, 1, &val)
8438 == 0) {
Joe Perches94f05b02011-08-14 12:16:20 +00008439 DP(NETIF_MSG_LINK,
8440 "SFP+ module initialization took %d ms\n",
8441 timeout * 5);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008442 return 0;
8443 }
Yuval Mintzd2310232012-06-20 19:05:19 +00008444 usleep_range(5000, 10000);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008445 }
8446 return -EINVAL;
8447}
8448
8449static void bnx2x_8727_power_module(struct bnx2x *bp,
8450 struct bnx2x_phy *phy,
8451 u8 is_power_up) {
8452 /* Make sure GPIOs are not using for LED mode */
8453 u16 val;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00008454 /* In the GPIO register, bit 4 is use to determine if the GPIOs are
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008455 * operating as INPUT or as OUTPUT. Bit 1 is for input, and 0 for
8456 * output
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008457 * Bits 0-1 determine the GPIOs value for OUTPUT in case bit 4 val is 0
8458 * Bits 8-9 determine the GPIOs value for INPUT in case bit 4 val is 1
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008459 * where the 1st bit is the over-current(only input), and 2nd bit is
8460 * for power( only output )
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008461 *
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008462 * In case of NOC feature is disabled and power is up, set GPIO control
8463 * as input to enable listening of over-current indication
8464 */
8465 if (phy->flags & FLAGS_NOC)
8466 return;
Yaniv Rosner27d02432011-05-31 21:27:48 +00008467 if (is_power_up)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008468 val = (1<<4);
8469 else
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00008470 /* Set GPIO control to OUTPUT, and set the power bit
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008471 * to according to the is_power_up
8472 */
Yaniv Rosner27d02432011-05-31 21:27:48 +00008473 val = (1<<1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008474
8475 bnx2x_cl45_write(bp, phy,
8476 MDIO_PMA_DEVAD,
8477 MDIO_PMA_REG_8727_GPIO_CTRL,
8478 val);
8479}
8480
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00008481static int bnx2x_8726_set_limiting_mode(struct bnx2x *bp,
8482 struct bnx2x_phy *phy,
8483 u16 edc_mode)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008484{
8485 u16 cur_limiting_mode;
8486
8487 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008488 MDIO_PMA_DEVAD,
8489 MDIO_PMA_REG_ROM_VER2,
8490 &cur_limiting_mode);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008491 DP(NETIF_MSG_LINK, "Current Limiting mode is 0x%x\n",
8492 cur_limiting_mode);
8493
8494 if (edc_mode == EDC_MODE_LIMITING) {
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008495 DP(NETIF_MSG_LINK, "Setting LIMITING MODE\n");
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008496 bnx2x_cl45_write(bp, phy,
8497 MDIO_PMA_DEVAD,
8498 MDIO_PMA_REG_ROM_VER2,
8499 EDC_MODE_LIMITING);
8500 } else { /* LRM mode ( default )*/
8501
8502 DP(NETIF_MSG_LINK, "Setting LRM MODE\n");
8503
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00008504 /* Changing to LRM mode takes quite few seconds. So do it only
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008505 * if current mode is limiting (default is LRM)
8506 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008507 if (cur_limiting_mode != EDC_MODE_LIMITING)
8508 return 0;
8509
8510 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008511 MDIO_PMA_DEVAD,
8512 MDIO_PMA_REG_LRM_MODE,
8513 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008514 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008515 MDIO_PMA_DEVAD,
8516 MDIO_PMA_REG_ROM_VER2,
8517 0x128);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008518 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008519 MDIO_PMA_DEVAD,
8520 MDIO_PMA_REG_MISC_CTRL0,
8521 0x4008);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008522 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008523 MDIO_PMA_DEVAD,
8524 MDIO_PMA_REG_LRM_MODE,
8525 0xaaaa);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008526 }
8527 return 0;
8528}
8529
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00008530static int bnx2x_8727_set_limiting_mode(struct bnx2x *bp,
8531 struct bnx2x_phy *phy,
8532 u16 edc_mode)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008533{
8534 u16 phy_identifier;
8535 u16 rom_ver2_val;
8536 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008537 MDIO_PMA_DEVAD,
8538 MDIO_PMA_REG_PHY_IDENTIFIER,
8539 &phy_identifier);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008540
8541 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008542 MDIO_PMA_DEVAD,
8543 MDIO_PMA_REG_PHY_IDENTIFIER,
8544 (phy_identifier & ~(1<<9)));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008545
8546 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008547 MDIO_PMA_DEVAD,
8548 MDIO_PMA_REG_ROM_VER2,
8549 &rom_ver2_val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008550 /* Keep the MSB 8-bits, and set the LSB 8-bits with the edc_mode */
8551 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008552 MDIO_PMA_DEVAD,
8553 MDIO_PMA_REG_ROM_VER2,
8554 (rom_ver2_val & 0xff00) | (edc_mode & 0x00ff));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008555
8556 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008557 MDIO_PMA_DEVAD,
8558 MDIO_PMA_REG_PHY_IDENTIFIER,
8559 (phy_identifier | (1<<9)));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008560
8561 return 0;
8562}
8563
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008564static void bnx2x_8727_specific_func(struct bnx2x_phy *phy,
8565 struct link_params *params,
8566 u32 action)
8567{
8568 struct bnx2x *bp = params->bp;
Yaniv Rosner5c107fd2012-09-13 02:56:19 +00008569 u16 val;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008570 switch (action) {
8571 case DISABLE_TX:
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008572 bnx2x_sfp_set_transmitter(params, phy, 0);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008573 break;
8574 case ENABLE_TX:
8575 if (!(phy->flags & FLAGS_SFP_NOT_APPROVED))
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008576 bnx2x_sfp_set_transmitter(params, phy, 1);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008577 break;
Yaniv Rosner5c107fd2012-09-13 02:56:19 +00008578 case PHY_INIT:
8579 bnx2x_cl45_write(bp, phy,
8580 MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXCTRL,
8581 (1<<2) | (1<<5));
8582 bnx2x_cl45_write(bp, phy,
8583 MDIO_PMA_DEVAD, MDIO_PMA_LASI_TXCTRL,
8584 0);
8585 bnx2x_cl45_write(bp, phy,
8586 MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL, 0x0006);
8587 /* Make MOD_ABS give interrupt on change */
8588 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
8589 MDIO_PMA_REG_8727_PCS_OPT_CTRL,
8590 &val);
8591 val |= (1<<12);
8592 if (phy->flags & FLAGS_NOC)
8593 val |= (3<<5);
8594 /* Set 8727 GPIOs to input to allow reading from the 8727 GPIO0
8595 * status which reflect SFP+ module over-current
8596 */
8597 if (!(phy->flags & FLAGS_NOC))
8598 val &= 0xff8f; /* Reset bits 4-6 */
8599 bnx2x_cl45_write(bp, phy,
8600 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_PCS_OPT_CTRL,
8601 val);
8602
8603 /* Set 2-wire transfer rate of SFP+ module EEPROM
8604 * to 100Khz since some DACs(direct attached cables) do
8605 * not work at 400Khz.
8606 */
8607 bnx2x_cl45_write(bp, phy,
8608 MDIO_PMA_DEVAD,
8609 MDIO_PMA_REG_8727_TWO_WIRE_SLAVE_ADDR,
8610 0xa001);
8611 break;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008612 default:
8613 DP(NETIF_MSG_LINK, "Function 0x%x not supported by 8727\n",
8614 action);
8615 return;
8616 }
8617}
8618
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008619static void bnx2x_set_e1e2_module_fault_led(struct link_params *params,
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008620 u8 gpio_mode)
8621{
8622 struct bnx2x *bp = params->bp;
8623
8624 u32 fault_led_gpio = REG_RD(bp, params->shmem_base +
8625 offsetof(struct shmem_region,
8626 dev_info.port_hw_config[params->port].sfp_ctrl)) &
8627 PORT_HW_CFG_FAULT_MODULE_LED_MASK;
8628 switch (fault_led_gpio) {
8629 case PORT_HW_CFG_FAULT_MODULE_LED_DISABLED:
8630 return;
8631 case PORT_HW_CFG_FAULT_MODULE_LED_GPIO0:
8632 case PORT_HW_CFG_FAULT_MODULE_LED_GPIO1:
8633 case PORT_HW_CFG_FAULT_MODULE_LED_GPIO2:
8634 case PORT_HW_CFG_FAULT_MODULE_LED_GPIO3:
8635 {
8636 u8 gpio_port = bnx2x_get_gpio_port(params);
8637 u16 gpio_pin = fault_led_gpio -
8638 PORT_HW_CFG_FAULT_MODULE_LED_GPIO0;
8639 DP(NETIF_MSG_LINK, "Set fault module-detected led "
8640 "pin %x port %x mode %x\n",
8641 gpio_pin, gpio_port, gpio_mode);
8642 bnx2x_set_gpio(bp, gpio_pin, gpio_mode, gpio_port);
8643 }
8644 break;
8645 default:
8646 DP(NETIF_MSG_LINK, "Error: Invalid fault led mode 0x%x\n",
8647 fault_led_gpio);
8648 }
8649}
8650
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008651static void bnx2x_set_e3_module_fault_led(struct link_params *params,
8652 u8 gpio_mode)
8653{
8654 u32 pin_cfg;
8655 u8 port = params->port;
8656 struct bnx2x *bp = params->bp;
8657 pin_cfg = (REG_RD(bp, params->shmem_base +
8658 offsetof(struct shmem_region,
8659 dev_info.port_hw_config[port].e3_sfp_ctrl)) &
8660 PORT_HW_CFG_E3_FAULT_MDL_LED_MASK) >>
8661 PORT_HW_CFG_E3_FAULT_MDL_LED_SHIFT;
8662 DP(NETIF_MSG_LINK, "Setting Fault LED to %d using pin cfg %d\n",
8663 gpio_mode, pin_cfg);
8664 bnx2x_set_cfg_pin(bp, pin_cfg, gpio_mode);
8665}
8666
8667static void bnx2x_set_sfp_module_fault_led(struct link_params *params,
8668 u8 gpio_mode)
8669{
8670 struct bnx2x *bp = params->bp;
8671 DP(NETIF_MSG_LINK, "Setting SFP+ module fault LED to %d\n", gpio_mode);
8672 if (CHIP_IS_E3(bp)) {
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00008673 /* Low ==> if SFP+ module is supported otherwise
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008674 * High ==> if SFP+ module is not on the approved vendor list
8675 */
8676 bnx2x_set_e3_module_fault_led(params, gpio_mode);
8677 } else
8678 bnx2x_set_e1e2_module_fault_led(params, gpio_mode);
8679}
8680
Yaniv Rosner985848f2011-07-05 01:06:48 +00008681static void bnx2x_warpcore_hw_reset(struct bnx2x_phy *phy,
8682 struct link_params *params)
8683{
Yaniv Rosnerb76070b2011-11-28 00:49:47 +00008684 struct bnx2x *bp = params->bp;
Yaniv Rosner985848f2011-07-05 01:06:48 +00008685 bnx2x_warpcore_power_module(params, phy, 0);
Yaniv Rosnerb76070b2011-11-28 00:49:47 +00008686 /* Put Warpcore in low power mode */
8687 REG_WR(bp, MISC_REG_WC0_RESET, 0x0c0e);
8688
8689 /* Put LCPLL in low power mode */
8690 REG_WR(bp, MISC_REG_LCPLL_E40_PWRDWN, 1);
8691 REG_WR(bp, MISC_REG_LCPLL_E40_RESETB_ANA, 0);
8692 REG_WR(bp, MISC_REG_LCPLL_E40_RESETB_DIG, 0);
Yaniv Rosner985848f2011-07-05 01:06:48 +00008693}
8694
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00008695static void bnx2x_power_sfp_module(struct link_params *params,
8696 struct bnx2x_phy *phy,
8697 u8 power)
8698{
8699 struct bnx2x *bp = params->bp;
8700 DP(NETIF_MSG_LINK, "Setting SFP+ power to %x\n", power);
8701
8702 switch (phy->type) {
8703 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
8704 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8722:
8705 bnx2x_8727_power_module(params->bp, phy, power);
8706 break;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008707 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT:
8708 bnx2x_warpcore_power_module(params, phy, power);
8709 break;
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00008710 default:
8711 break;
8712 }
8713}
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008714static void bnx2x_warpcore_set_limiting_mode(struct link_params *params,
8715 struct bnx2x_phy *phy,
8716 u16 edc_mode)
8717{
8718 u16 val = 0;
8719 u16 mode = MDIO_WC_REG_UC_INFO_B1_FIRMWARE_MODE_DEFAULT;
8720 struct bnx2x *bp = params->bp;
8721
8722 u8 lane = bnx2x_get_warpcore_lane(phy, params);
8723 /* This is a global register which controls all lanes */
8724 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
8725 MDIO_WC_REG_UC_INFO_B1_FIRMWARE_MODE, &val);
8726 val &= ~(0xf << (lane << 2));
8727
8728 switch (edc_mode) {
8729 case EDC_MODE_LINEAR:
8730 case EDC_MODE_LIMITING:
8731 mode = MDIO_WC_REG_UC_INFO_B1_FIRMWARE_MODE_DEFAULT;
8732 break;
8733 case EDC_MODE_PASSIVE_DAC:
8734 mode = MDIO_WC_REG_UC_INFO_B1_FIRMWARE_MODE_SFP_DAC;
8735 break;
8736 default:
8737 break;
8738 }
8739
8740 val |= (mode << (lane << 2));
8741 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
8742 MDIO_WC_REG_UC_INFO_B1_FIRMWARE_MODE, val);
8743 /* A must read */
8744 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
8745 MDIO_WC_REG_UC_INFO_B1_FIRMWARE_MODE, &val);
8746
Yaniv Rosner19af03a2011-08-02 22:59:47 +00008747 /* Restart microcode to re-read the new mode */
8748 bnx2x_warpcore_reset_lane(bp, phy, 1);
8749 bnx2x_warpcore_reset_lane(bp, phy, 0);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008750
8751}
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00008752
8753static void bnx2x_set_limiting_mode(struct link_params *params,
8754 struct bnx2x_phy *phy,
8755 u16 edc_mode)
8756{
8757 switch (phy->type) {
8758 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
8759 bnx2x_8726_set_limiting_mode(params->bp, phy, edc_mode);
8760 break;
8761 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
8762 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8722:
8763 bnx2x_8727_set_limiting_mode(params->bp, phy, edc_mode);
8764 break;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008765 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT:
8766 bnx2x_warpcore_set_limiting_mode(params, phy, edc_mode);
8767 break;
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00008768 }
8769}
8770
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00008771int bnx2x_sfp_module_detection(struct bnx2x_phy *phy,
8772 struct link_params *params)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008773{
8774 struct bnx2x *bp = params->bp;
8775 u16 edc_mode;
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00008776 int rc = 0;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008777
8778 u32 val = REG_RD(bp, params->shmem_base +
8779 offsetof(struct shmem_region, dev_info.
8780 port_feature_config[params->port].config));
8781
8782 DP(NETIF_MSG_LINK, "SFP+ module plugged in/out detected on port %d\n",
8783 params->port);
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00008784 /* Power up module */
8785 bnx2x_power_sfp_module(params, phy, 1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008786 if (bnx2x_get_edc_mode(phy, params, &edc_mode) != 0) {
8787 DP(NETIF_MSG_LINK, "Failed to get valid module type\n");
8788 return -EINVAL;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008789 } else if (bnx2x_verify_sfp_module(phy, params) != 0) {
Yuval Mintzd2310232012-06-20 19:05:19 +00008790 /* Check SFP+ module compatibility */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008791 DP(NETIF_MSG_LINK, "Module verification failed!!\n");
8792 rc = -EINVAL;
8793 /* Turn on fault module-detected led */
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008794 bnx2x_set_sfp_module_fault_led(params,
8795 MISC_REGISTERS_GPIO_HIGH);
8796
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00008797 /* Check if need to power down the SFP+ module */
8798 if ((val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) ==
8799 PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_POWER_DOWN) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008800 DP(NETIF_MSG_LINK, "Shutdown SFP+ module!!\n");
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00008801 bnx2x_power_sfp_module(params, phy, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008802 return rc;
8803 }
8804 } else {
8805 /* Turn off fault module-detected led */
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008806 bnx2x_set_sfp_module_fault_led(params, MISC_REGISTERS_GPIO_LOW);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008807 }
8808
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00008809 /* Check and set limiting mode / LRM mode on 8726. On 8727 it
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008810 * is done automatically
8811 */
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00008812 bnx2x_set_limiting_mode(params, phy, edc_mode);
8813
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00008814 /* Enable transmit for this module if the module is approved, or
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008815 * if unapproved modules should also enable the Tx laser
8816 */
8817 if (rc == 0 ||
8818 (val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) !=
8819 PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_DISABLE_TX_LASER)
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008820 bnx2x_sfp_set_transmitter(params, phy, 1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008821 else
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008822 bnx2x_sfp_set_transmitter(params, phy, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008823
8824 return rc;
8825}
8826
8827void bnx2x_handle_module_detect_int(struct link_params *params)
8828{
8829 struct bnx2x *bp = params->bp;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008830 struct bnx2x_phy *phy;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008831 u32 gpio_val;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008832 u8 gpio_num, gpio_port;
8833 if (CHIP_IS_E3(bp))
8834 phy = &params->phy[INT_PHY];
8835 else
8836 phy = &params->phy[EXT_PHY1];
8837
8838 if (bnx2x_get_mod_abs_int_cfg(bp, params->chip_id, params->shmem_base,
8839 params->port, &gpio_num, &gpio_port) ==
8840 -EINVAL) {
8841 DP(NETIF_MSG_LINK, "Failed to get MOD_ABS interrupt config\n");
8842 return;
8843 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008844
8845 /* Set valid module led off */
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008846 bnx2x_set_sfp_module_fault_led(params, MISC_REGISTERS_GPIO_HIGH);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008847
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008848 /* Get current gpio val reflecting module plugged in / out*/
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008849 gpio_val = bnx2x_get_gpio(bp, gpio_num, gpio_port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008850
8851 /* Call the handling function in case module is detected */
8852 if (gpio_val == 0) {
Yuval Mintzdbef8072012-06-20 19:05:22 +00008853 bnx2x_set_mdio_clk(bp, params->chip_id, params->port);
8854 bnx2x_set_aer_mmd(params, phy);
8855
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00008856 bnx2x_power_sfp_module(params, phy, 1);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008857 bnx2x_set_gpio_int(bp, gpio_num,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008858 MISC_REGISTERS_GPIO_INT_OUTPUT_CLR,
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008859 gpio_port);
Yuval Mintzdbef8072012-06-20 19:05:22 +00008860 if (bnx2x_wait_for_sfp_module_initialized(phy, params) == 0) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008861 bnx2x_sfp_module_detection(phy, params);
Yuval Mintzdbef8072012-06-20 19:05:22 +00008862 if (CHIP_IS_E3(bp)) {
8863 u16 rx_tx_in_reset;
8864 /* In case WC is out of reset, reconfigure the
8865 * link speed while taking into account 1G
8866 * module limitation.
8867 */
8868 bnx2x_cl45_read(bp, phy,
8869 MDIO_WC_DEVAD,
8870 MDIO_WC_REG_DIGITAL5_MISC6,
8871 &rx_tx_in_reset);
8872 if (!rx_tx_in_reset) {
8873 bnx2x_warpcore_reset_lane(bp, phy, 1);
8874 bnx2x_warpcore_config_sfi(phy, params);
8875 bnx2x_warpcore_reset_lane(bp, phy, 0);
8876 }
8877 }
8878 } else {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008879 DP(NETIF_MSG_LINK, "SFP+ module is not initialized\n");
Yuval Mintzdbef8072012-06-20 19:05:22 +00008880 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008881 } else {
8882 u32 val = REG_RD(bp, params->shmem_base +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008883 offsetof(struct shmem_region, dev_info.
8884 port_feature_config[params->port].
8885 config));
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008886 bnx2x_set_gpio_int(bp, gpio_num,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008887 MISC_REGISTERS_GPIO_INT_OUTPUT_SET,
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008888 gpio_port);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00008889 /* Module was plugged out.
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008890 * Disable transmit for this module
8891 */
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00008892 phy->media_type = ETH_PHY_NOT_PRESENT;
Yaniv Rosnerde6f3372011-08-02 22:59:25 +00008893 if (((val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) ==
8894 PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_DISABLE_TX_LASER) ||
8895 CHIP_IS_E3(bp))
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008896 bnx2x_sfp_set_transmitter(params, phy, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008897 }
8898}
8899
8900/******************************************************************/
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00008901/* Used by 8706 and 8727 */
8902/******************************************************************/
8903static void bnx2x_sfp_mask_fault(struct bnx2x *bp,
8904 struct bnx2x_phy *phy,
8905 u16 alarm_status_offset,
8906 u16 alarm_ctrl_offset)
8907{
8908 u16 alarm_status, val;
8909 bnx2x_cl45_read(bp, phy,
8910 MDIO_PMA_DEVAD, alarm_status_offset,
8911 &alarm_status);
8912 bnx2x_cl45_read(bp, phy,
8913 MDIO_PMA_DEVAD, alarm_status_offset,
8914 &alarm_status);
8915 /* Mask or enable the fault event. */
8916 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD, alarm_ctrl_offset, &val);
8917 if (alarm_status & (1<<0))
8918 val &= ~(1<<0);
8919 else
8920 val |= (1<<0);
8921 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, alarm_ctrl_offset, val);
8922}
8923/******************************************************************/
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008924/* common BCM8706/BCM8726 PHY SECTION */
8925/******************************************************************/
8926static u8 bnx2x_8706_8726_read_status(struct bnx2x_phy *phy,
8927 struct link_params *params,
8928 struct link_vars *vars)
8929{
8930 u8 link_up = 0;
8931 u16 val1, val2, rx_sd, pcs_status;
8932 struct bnx2x *bp = params->bp;
8933 DP(NETIF_MSG_LINK, "XGXS 8706/8726\n");
8934 /* Clear RX Alarm*/
8935 bnx2x_cl45_read(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00008936 MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXSTAT, &val2);
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00008937
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00008938 bnx2x_sfp_mask_fault(bp, phy, MDIO_PMA_LASI_TXSTAT,
8939 MDIO_PMA_LASI_TXCTRL);
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00008940
Yuval Mintzd2310232012-06-20 19:05:19 +00008941 /* Clear LASI indication*/
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008942 bnx2x_cl45_read(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00008943 MDIO_PMA_DEVAD, MDIO_PMA_LASI_STAT, &val1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008944 bnx2x_cl45_read(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00008945 MDIO_PMA_DEVAD, MDIO_PMA_LASI_STAT, &val2);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008946 DP(NETIF_MSG_LINK, "8706/8726 LASI status 0x%x--> 0x%x\n", val1, val2);
8947
8948 bnx2x_cl45_read(bp, phy,
8949 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_SD, &rx_sd);
8950 bnx2x_cl45_read(bp, phy,
8951 MDIO_PCS_DEVAD, MDIO_PCS_REG_STATUS, &pcs_status);
8952 bnx2x_cl45_read(bp, phy,
8953 MDIO_AN_DEVAD, MDIO_AN_REG_LINK_STATUS, &val2);
8954 bnx2x_cl45_read(bp, phy,
8955 MDIO_AN_DEVAD, MDIO_AN_REG_LINK_STATUS, &val2);
8956
8957 DP(NETIF_MSG_LINK, "8706/8726 rx_sd 0x%x pcs_status 0x%x 1Gbps"
8958 " link_status 0x%x\n", rx_sd, pcs_status, val2);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00008959 /* Link is up if both bit 0 of pmd_rx_sd and bit 0 of pcs_status
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008960 * are set, or if the autoneg bit 1 is set
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008961 */
8962 link_up = ((rx_sd & pcs_status & 0x1) || (val2 & (1<<1)));
8963 if (link_up) {
8964 if (val2 & (1<<1))
8965 vars->line_speed = SPEED_1000;
8966 else
8967 vars->line_speed = SPEED_10000;
8968 bnx2x_ext_phy_resolve_fc(phy, params, vars);
Yaniv Rosner791f18c2011-01-18 04:33:42 +00008969 vars->duplex = DUPLEX_FULL;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008970 }
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00008971
8972 /* Capture 10G link fault. Read twice to clear stale value. */
8973 if (vars->line_speed == SPEED_10000) {
8974 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00008975 MDIO_PMA_LASI_TXSTAT, &val1);
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00008976 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00008977 MDIO_PMA_LASI_TXSTAT, &val1);
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00008978 if (val1 & (1<<0))
8979 vars->fault_detected = 1;
8980 }
8981
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008982 return link_up;
8983}
8984
8985/******************************************************************/
8986/* BCM8706 PHY SECTION */
8987/******************************************************************/
8988static u8 bnx2x_8706_config_init(struct bnx2x_phy *phy,
8989 struct link_params *params,
8990 struct link_vars *vars)
8991{
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008992 u32 tx_en_mode;
8993 u16 cnt, val, tmp1;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008994 struct bnx2x *bp = params->bp;
Yaniv Rosner3deb8162011-06-14 01:34:33 +00008995
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008996 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008997 MISC_REGISTERS_GPIO_OUTPUT_HIGH, params->port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008998 /* HW reset */
8999 bnx2x_ext_phy_hw_reset(bp, params->port);
9000 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0xa040);
Yaniv Rosner6d870c32011-01-31 04:22:20 +00009001 bnx2x_wait_reset_complete(bp, phy, params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009002
9003 /* Wait until fw is loaded */
9004 for (cnt = 0; cnt < 100; cnt++) {
9005 bnx2x_cl45_read(bp, phy,
9006 MDIO_PMA_DEVAD, MDIO_PMA_REG_ROM_VER1, &val);
9007 if (val)
9008 break;
Yuval Mintzd2310232012-06-20 19:05:19 +00009009 usleep_range(10000, 20000);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009010 }
9011 DP(NETIF_MSG_LINK, "XGXS 8706 is initialized after %d ms\n", cnt);
9012 if ((params->feature_config_flags &
9013 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED)) {
9014 u8 i;
9015 u16 reg;
9016 for (i = 0; i < 4; i++) {
9017 reg = MDIO_XS_8706_REG_BANK_RX0 +
9018 i*(MDIO_XS_8706_REG_BANK_RX1 -
9019 MDIO_XS_8706_REG_BANK_RX0);
9020 bnx2x_cl45_read(bp, phy, MDIO_XS_DEVAD, reg, &val);
9021 /* Clear first 3 bits of the control */
9022 val &= ~0x7;
9023 /* Set control bits according to configuration */
9024 val |= (phy->rx_preemphasis[i] & 0x7);
9025 DP(NETIF_MSG_LINK, "Setting RX Equalizer to BCM8706"
9026 " reg 0x%x <-- val 0x%x\n", reg, val);
9027 bnx2x_cl45_write(bp, phy, MDIO_XS_DEVAD, reg, val);
9028 }
9029 }
9030 /* Force speed */
9031 if (phy->req_line_speed == SPEED_10000) {
9032 DP(NETIF_MSG_LINK, "XGXS 8706 force 10Gbps\n");
9033
9034 bnx2x_cl45_write(bp, phy,
9035 MDIO_PMA_DEVAD,
9036 MDIO_PMA_REG_DIGITAL_CTRL, 0x400);
9037 bnx2x_cl45_write(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009038 MDIO_PMA_DEVAD, MDIO_PMA_LASI_TXCTRL,
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00009039 0);
9040 /* Arm LASI for link and Tx fault. */
9041 bnx2x_cl45_write(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009042 MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL, 3);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009043 } else {
Lucas De Marchi25985ed2011-03-30 22:57:33 -03009044 /* Force 1Gbps using autoneg with 1G advertisement */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009045
9046 /* Allow CL37 through CL73 */
9047 DP(NETIF_MSG_LINK, "XGXS 8706 AutoNeg\n");
9048 bnx2x_cl45_write(bp, phy,
9049 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_CL73, 0x040c);
9050
Lucas De Marchi25985ed2011-03-30 22:57:33 -03009051 /* Enable Full-Duplex advertisement on CL37 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009052 bnx2x_cl45_write(bp, phy,
9053 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LP, 0x0020);
9054 /* Enable CL37 AN */
9055 bnx2x_cl45_write(bp, phy,
9056 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_AN, 0x1000);
9057 /* 1G support */
9058 bnx2x_cl45_write(bp, phy,
9059 MDIO_AN_DEVAD, MDIO_AN_REG_ADV, (1<<5));
9060
9061 /* Enable clause 73 AN */
9062 bnx2x_cl45_write(bp, phy,
9063 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x1200);
9064 bnx2x_cl45_write(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009065 MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXCTRL,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009066 0x0400);
9067 bnx2x_cl45_write(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009068 MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009069 0x0004);
9070 }
9071 bnx2x_save_bcm_spirom_ver(bp, phy, params->port);
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00009072
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00009073 /* If TX Laser is controlled by GPIO_0, do not let PHY go into low
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00009074 * power mode, if TX Laser is disabled
9075 */
9076
9077 tx_en_mode = REG_RD(bp, params->shmem_base +
9078 offsetof(struct shmem_region,
9079 dev_info.port_hw_config[params->port].sfp_ctrl))
9080 & PORT_HW_CFG_TX_LASER_MASK;
9081
9082 if (tx_en_mode == PORT_HW_CFG_TX_LASER_GPIO0) {
9083 DP(NETIF_MSG_LINK, "Enabling TXONOFF_PWRDN_DIS\n");
9084 bnx2x_cl45_read(bp, phy,
9085 MDIO_PMA_DEVAD, MDIO_PMA_REG_DIGITAL_CTRL, &tmp1);
9086 tmp1 |= 0x1;
9087 bnx2x_cl45_write(bp, phy,
9088 MDIO_PMA_DEVAD, MDIO_PMA_REG_DIGITAL_CTRL, tmp1);
9089 }
9090
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009091 return 0;
9092}
9093
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00009094static int bnx2x_8706_read_status(struct bnx2x_phy *phy,
9095 struct link_params *params,
9096 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009097{
9098 return bnx2x_8706_8726_read_status(phy, params, vars);
9099}
9100
9101/******************************************************************/
9102/* BCM8726 PHY SECTION */
9103/******************************************************************/
9104static void bnx2x_8726_config_loopback(struct bnx2x_phy *phy,
9105 struct link_params *params)
9106{
9107 struct bnx2x *bp = params->bp;
9108 DP(NETIF_MSG_LINK, "PMA/PMD ext_phy_loopback: 8726\n");
9109 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x0001);
9110}
9111
9112static void bnx2x_8726_external_rom_boot(struct bnx2x_phy *phy,
9113 struct link_params *params)
9114{
9115 struct bnx2x *bp = params->bp;
9116 /* Need to wait 100ms after reset */
9117 msleep(100);
9118
9119 /* Micro controller re-boot */
9120 bnx2x_cl45_write(bp, phy,
9121 MDIO_PMA_DEVAD, MDIO_PMA_REG_GEN_CTRL, 0x018B);
9122
9123 /* Set soft reset */
9124 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00009125 MDIO_PMA_DEVAD,
9126 MDIO_PMA_REG_GEN_CTRL,
9127 MDIO_PMA_REG_GEN_CTRL_ROM_MICRO_RESET);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009128
9129 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00009130 MDIO_PMA_DEVAD,
9131 MDIO_PMA_REG_MISC_CTRL1, 0x0001);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009132
9133 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00009134 MDIO_PMA_DEVAD,
9135 MDIO_PMA_REG_GEN_CTRL,
9136 MDIO_PMA_REG_GEN_CTRL_ROM_RESET_INTERNAL_MP);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009137
Yuval Mintzd2310232012-06-20 19:05:19 +00009138 /* Wait for 150ms for microcode load */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009139 msleep(150);
9140
9141 /* Disable serial boot control, tristates pins SS_N, SCK, MOSI, MISO */
9142 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00009143 MDIO_PMA_DEVAD,
9144 MDIO_PMA_REG_MISC_CTRL1, 0x0000);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009145
9146 msleep(200);
9147 bnx2x_save_bcm_spirom_ver(bp, phy, params->port);
9148}
9149
9150static u8 bnx2x_8726_read_status(struct bnx2x_phy *phy,
9151 struct link_params *params,
9152 struct link_vars *vars)
9153{
9154 struct bnx2x *bp = params->bp;
9155 u16 val1;
9156 u8 link_up = bnx2x_8706_8726_read_status(phy, params, vars);
9157 if (link_up) {
9158 bnx2x_cl45_read(bp, phy,
9159 MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER,
9160 &val1);
9161 if (val1 & (1<<15)) {
9162 DP(NETIF_MSG_LINK, "Tx is disabled\n");
9163 link_up = 0;
9164 vars->line_speed = 0;
9165 }
9166 }
9167 return link_up;
9168}
9169
9170
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00009171static int bnx2x_8726_config_init(struct bnx2x_phy *phy,
9172 struct link_params *params,
9173 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009174{
9175 struct bnx2x *bp = params->bp;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009176 DP(NETIF_MSG_LINK, "Initializing BCM8726\n");
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009177
9178 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 1<<15);
Yaniv Rosner6d870c32011-01-31 04:22:20 +00009179 bnx2x_wait_reset_complete(bp, phy, params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009180
9181 bnx2x_8726_external_rom_boot(phy, params);
9182
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00009183 /* Need to call module detected on initialization since the module
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00009184 * detection triggered by actual module insertion might occur before
9185 * driver is loaded, and when driver is loaded, it reset all
9186 * registers, including the transmitter
9187 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009188 bnx2x_sfp_module_detection(phy, params);
9189
9190 if (phy->req_line_speed == SPEED_1000) {
9191 DP(NETIF_MSG_LINK, "Setting 1G force\n");
9192 bnx2x_cl45_write(bp, phy,
9193 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x40);
9194 bnx2x_cl45_write(bp, phy,
9195 MDIO_PMA_DEVAD, MDIO_PMA_REG_10G_CTRL2, 0xD);
9196 bnx2x_cl45_write(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009197 MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL, 0x5);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009198 bnx2x_cl45_write(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009199 MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXCTRL,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009200 0x400);
9201 } else if ((phy->req_line_speed == SPEED_AUTO_NEG) &&
9202 (phy->speed_cap_mask &
9203 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G) &&
9204 ((phy->speed_cap_mask &
9205 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G) !=
9206 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) {
9207 DP(NETIF_MSG_LINK, "Setting 1G clause37\n");
9208 /* Set Flow control */
9209 bnx2x_ext_phy_set_pause(params, phy, vars);
9210 bnx2x_cl45_write(bp, phy,
9211 MDIO_AN_DEVAD, MDIO_AN_REG_ADV, 0x20);
9212 bnx2x_cl45_write(bp, phy,
9213 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_CL73, 0x040c);
9214 bnx2x_cl45_write(bp, phy,
9215 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LD, 0x0020);
9216 bnx2x_cl45_write(bp, phy,
9217 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_AN, 0x1000);
9218 bnx2x_cl45_write(bp, phy,
9219 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x1200);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00009220 /* Enable RX-ALARM control to receive interrupt for 1G speed
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00009221 * change
9222 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009223 bnx2x_cl45_write(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009224 MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL, 0x4);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009225 bnx2x_cl45_write(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009226 MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXCTRL,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009227 0x400);
9228
9229 } else { /* Default 10G. Set only LASI control */
9230 bnx2x_cl45_write(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009231 MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL, 1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009232 }
9233
9234 /* Set TX PreEmphasis if needed */
9235 if ((params->feature_config_flags &
9236 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED)) {
Joe Perches94f05b02011-08-14 12:16:20 +00009237 DP(NETIF_MSG_LINK,
9238 "Setting TX_CTRL1 0x%x, TX_CTRL2 0x%x\n",
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009239 phy->tx_preemphasis[0],
9240 phy->tx_preemphasis[1]);
9241 bnx2x_cl45_write(bp, phy,
9242 MDIO_PMA_DEVAD,
9243 MDIO_PMA_REG_8726_TX_CTRL1,
9244 phy->tx_preemphasis[0]);
9245
9246 bnx2x_cl45_write(bp, phy,
9247 MDIO_PMA_DEVAD,
9248 MDIO_PMA_REG_8726_TX_CTRL2,
9249 phy->tx_preemphasis[1]);
9250 }
9251
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009252 return 0;
9253
9254}
9255
9256static void bnx2x_8726_link_reset(struct bnx2x_phy *phy,
9257 struct link_params *params)
9258{
9259 struct bnx2x *bp = params->bp;
9260 DP(NETIF_MSG_LINK, "bnx2x_8726_link_reset port %d\n", params->port);
9261 /* Set serial boot control for external load */
9262 bnx2x_cl45_write(bp, phy,
9263 MDIO_PMA_DEVAD,
9264 MDIO_PMA_REG_GEN_CTRL, 0x0001);
9265}
9266
9267/******************************************************************/
9268/* BCM8727 PHY SECTION */
9269/******************************************************************/
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00009270
9271static void bnx2x_8727_set_link_led(struct bnx2x_phy *phy,
9272 struct link_params *params, u8 mode)
9273{
9274 struct bnx2x *bp = params->bp;
9275 u16 led_mode_bitmask = 0;
9276 u16 gpio_pins_bitmask = 0;
9277 u16 val;
9278 /* Only NOC flavor requires to set the LED specifically */
9279 if (!(phy->flags & FLAGS_NOC))
9280 return;
9281 switch (mode) {
9282 case LED_MODE_FRONT_PANEL_OFF:
9283 case LED_MODE_OFF:
9284 led_mode_bitmask = 0;
9285 gpio_pins_bitmask = 0x03;
9286 break;
9287 case LED_MODE_ON:
9288 led_mode_bitmask = 0;
9289 gpio_pins_bitmask = 0x02;
9290 break;
9291 case LED_MODE_OPER:
9292 led_mode_bitmask = 0x60;
9293 gpio_pins_bitmask = 0x11;
9294 break;
9295 }
9296 bnx2x_cl45_read(bp, phy,
9297 MDIO_PMA_DEVAD,
9298 MDIO_PMA_REG_8727_PCS_OPT_CTRL,
9299 &val);
9300 val &= 0xff8f;
9301 val |= led_mode_bitmask;
9302 bnx2x_cl45_write(bp, phy,
9303 MDIO_PMA_DEVAD,
9304 MDIO_PMA_REG_8727_PCS_OPT_CTRL,
9305 val);
9306 bnx2x_cl45_read(bp, phy,
9307 MDIO_PMA_DEVAD,
9308 MDIO_PMA_REG_8727_GPIO_CTRL,
9309 &val);
9310 val &= 0xffe0;
9311 val |= gpio_pins_bitmask;
9312 bnx2x_cl45_write(bp, phy,
9313 MDIO_PMA_DEVAD,
9314 MDIO_PMA_REG_8727_GPIO_CTRL,
9315 val);
9316}
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009317static void bnx2x_8727_hw_reset(struct bnx2x_phy *phy,
9318 struct link_params *params) {
9319 u32 swap_val, swap_override;
9320 u8 port;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00009321 /* The PHY reset is controlled by GPIO 1. Fake the port number
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009322 * to cancel the swap done in set_gpio()
9323 */
9324 struct bnx2x *bp = params->bp;
9325 swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
9326 swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
9327 port = (swap_val && swap_override) ^ 1;
9328 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00009329 MISC_REGISTERS_GPIO_OUTPUT_LOW, port);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009330}
9331
Yuval Mintzdbef8072012-06-20 19:05:22 +00009332static void bnx2x_8727_config_speed(struct bnx2x_phy *phy,
9333 struct link_params *params)
9334{
9335 struct bnx2x *bp = params->bp;
9336 u16 tmp1, val;
9337 /* Set option 1G speed */
9338 if ((phy->req_line_speed == SPEED_1000) ||
9339 (phy->media_type == ETH_PHY_SFP_1G_FIBER)) {
9340 DP(NETIF_MSG_LINK, "Setting 1G force\n");
9341 bnx2x_cl45_write(bp, phy,
9342 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x40);
9343 bnx2x_cl45_write(bp, phy,
9344 MDIO_PMA_DEVAD, MDIO_PMA_REG_10G_CTRL2, 0xD);
9345 bnx2x_cl45_read(bp, phy,
9346 MDIO_PMA_DEVAD, MDIO_PMA_REG_10G_CTRL2, &tmp1);
9347 DP(NETIF_MSG_LINK, "1.7 = 0x%x\n", tmp1);
9348 /* Power down the XAUI until link is up in case of dual-media
9349 * and 1G
9350 */
9351 if (DUAL_MEDIA(params)) {
9352 bnx2x_cl45_read(bp, phy,
9353 MDIO_PMA_DEVAD,
9354 MDIO_PMA_REG_8727_PCS_GP, &val);
9355 val |= (3<<10);
9356 bnx2x_cl45_write(bp, phy,
9357 MDIO_PMA_DEVAD,
9358 MDIO_PMA_REG_8727_PCS_GP, val);
9359 }
9360 } else if ((phy->req_line_speed == SPEED_AUTO_NEG) &&
9361 ((phy->speed_cap_mask &
9362 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) &&
9363 ((phy->speed_cap_mask &
9364 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G) !=
9365 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) {
9366
9367 DP(NETIF_MSG_LINK, "Setting 1G clause37\n");
9368 bnx2x_cl45_write(bp, phy,
9369 MDIO_AN_DEVAD, MDIO_AN_REG_8727_MISC_CTRL, 0);
9370 bnx2x_cl45_write(bp, phy,
9371 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_AN, 0x1300);
9372 } else {
9373 /* Since the 8727 has only single reset pin, need to set the 10G
9374 * registers although it is default
9375 */
9376 bnx2x_cl45_write(bp, phy,
9377 MDIO_AN_DEVAD, MDIO_AN_REG_8727_MISC_CTRL,
9378 0x0020);
9379 bnx2x_cl45_write(bp, phy,
9380 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_AN, 0x0100);
9381 bnx2x_cl45_write(bp, phy,
9382 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x2040);
9383 bnx2x_cl45_write(bp, phy,
9384 MDIO_PMA_DEVAD, MDIO_PMA_REG_10G_CTRL2,
9385 0x0008);
9386 }
9387}
9388
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00009389static int bnx2x_8727_config_init(struct bnx2x_phy *phy,
9390 struct link_params *params,
9391 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009392{
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00009393 u32 tx_en_mode;
Yaniv Rosner5c107fd2012-09-13 02:56:19 +00009394 u16 tmp1, mod_abs, tmp2;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009395 struct bnx2x *bp = params->bp;
9396 /* Enable PMD link, MOD_ABS_FLT, and 1G link alarm */
9397
Yaniv Rosner6d870c32011-01-31 04:22:20 +00009398 bnx2x_wait_reset_complete(bp, phy, params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009399
9400 DP(NETIF_MSG_LINK, "Initializing BCM8727\n");
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009401
Yaniv Rosner5c107fd2012-09-13 02:56:19 +00009402 bnx2x_8727_specific_func(phy, params, PHY_INIT);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00009403 /* Initially configure MOD_ABS to interrupt when module is
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00009404 * presence( bit 8)
9405 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009406 bnx2x_cl45_read(bp, phy,
9407 MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER, &mod_abs);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00009408 /* Set EDC off by setting OPTXLOS signal input to low (bit 9).
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00009409 * When the EDC is off it locks onto a reference clock and avoids
9410 * becoming 'lost'
9411 */
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00009412 mod_abs &= ~(1<<8);
9413 if (!(phy->flags & FLAGS_NOC))
9414 mod_abs &= ~(1<<9);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009415 bnx2x_cl45_write(bp, phy,
9416 MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER, mod_abs);
9417
Yaniv Rosner85242ee2011-07-05 01:06:53 +00009418 /* Enable/Disable PHY transmitter output */
9419 bnx2x_set_disable_pmd_transmit(params, phy, 0);
9420
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009421 bnx2x_8727_power_module(bp, phy, 1);
9422
9423 bnx2x_cl45_read(bp, phy,
9424 MDIO_PMA_DEVAD, MDIO_PMA_REG_M8051_MSGOUT_REG, &tmp1);
9425
9426 bnx2x_cl45_read(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009427 MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXSTAT, &tmp1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009428
Yuval Mintzdbef8072012-06-20 19:05:22 +00009429 bnx2x_8727_config_speed(phy, params);
Yaniv Rosner5c107fd2012-09-13 02:56:19 +00009430
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009431
9432 /* Set TX PreEmphasis if needed */
9433 if ((params->feature_config_flags &
9434 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED)) {
9435 DP(NETIF_MSG_LINK, "Setting TX_CTRL1 0x%x, TX_CTRL2 0x%x\n",
9436 phy->tx_preemphasis[0],
9437 phy->tx_preemphasis[1]);
9438 bnx2x_cl45_write(bp, phy,
9439 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_TX_CTRL1,
9440 phy->tx_preemphasis[0]);
9441
9442 bnx2x_cl45_write(bp, phy,
9443 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_TX_CTRL2,
9444 phy->tx_preemphasis[1]);
9445 }
9446
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00009447 /* If TX Laser is controlled by GPIO_0, do not let PHY go into low
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00009448 * power mode, if TX Laser is disabled
9449 */
9450 tx_en_mode = REG_RD(bp, params->shmem_base +
9451 offsetof(struct shmem_region,
9452 dev_info.port_hw_config[params->port].sfp_ctrl))
9453 & PORT_HW_CFG_TX_LASER_MASK;
9454
9455 if (tx_en_mode == PORT_HW_CFG_TX_LASER_GPIO0) {
9456
9457 DP(NETIF_MSG_LINK, "Enabling TXONOFF_PWRDN_DIS\n");
9458 bnx2x_cl45_read(bp, phy,
9459 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_OPT_CFG_REG, &tmp2);
9460 tmp2 |= 0x1000;
9461 tmp2 &= 0xFFEF;
9462 bnx2x_cl45_write(bp, phy,
9463 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_OPT_CFG_REG, tmp2);
Yaniv Rosner59a2e532012-04-04 01:28:59 +00009464 bnx2x_cl45_read(bp, phy,
9465 MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER,
9466 &tmp2);
9467 bnx2x_cl45_write(bp, phy,
9468 MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER,
9469 (tmp2 & 0x7fff));
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00009470 }
9471
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009472 return 0;
9473}
9474
9475static void bnx2x_8727_handle_mod_abs(struct bnx2x_phy *phy,
9476 struct link_params *params)
9477{
9478 struct bnx2x *bp = params->bp;
9479 u16 mod_abs, rx_alarm_status;
9480 u32 val = REG_RD(bp, params->shmem_base +
9481 offsetof(struct shmem_region, dev_info.
9482 port_feature_config[params->port].
9483 config));
9484 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00009485 MDIO_PMA_DEVAD,
9486 MDIO_PMA_REG_PHY_IDENTIFIER, &mod_abs);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009487 if (mod_abs & (1<<8)) {
9488
9489 /* Module is absent */
Joe Perches94f05b02011-08-14 12:16:20 +00009490 DP(NETIF_MSG_LINK,
9491 "MOD_ABS indication show module is absent\n");
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00009492 phy->media_type = ETH_PHY_NOT_PRESENT;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00009493 /* 1. Set mod_abs to detect next module
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00009494 * presence event
9495 * 2. Set EDC off by setting OPTXLOS signal input to low
9496 * (bit 9).
9497 * When the EDC is off it locks onto a reference clock and
9498 * avoids becoming 'lost'.
9499 */
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00009500 mod_abs &= ~(1<<8);
9501 if (!(phy->flags & FLAGS_NOC))
9502 mod_abs &= ~(1<<9);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009503 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00009504 MDIO_PMA_DEVAD,
9505 MDIO_PMA_REG_PHY_IDENTIFIER, mod_abs);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009506
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00009507 /* Clear RX alarm since it stays up as long as
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00009508 * the mod_abs wasn't changed
9509 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009510 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00009511 MDIO_PMA_DEVAD,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009512 MDIO_PMA_LASI_RXSTAT, &rx_alarm_status);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009513
9514 } else {
9515 /* Module is present */
Joe Perches94f05b02011-08-14 12:16:20 +00009516 DP(NETIF_MSG_LINK,
9517 "MOD_ABS indication show module is present\n");
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00009518 /* First disable transmitter, and if the module is ok, the
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00009519 * module_detection will enable it
9520 * 1. Set mod_abs to detect next module absent event ( bit 8)
9521 * 2. Restore the default polarity of the OPRXLOS signal and
9522 * this signal will then correctly indicate the presence or
9523 * absence of the Rx signal. (bit 9)
9524 */
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00009525 mod_abs |= (1<<8);
9526 if (!(phy->flags & FLAGS_NOC))
9527 mod_abs |= (1<<9);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009528 bnx2x_cl45_write(bp, phy,
9529 MDIO_PMA_DEVAD,
9530 MDIO_PMA_REG_PHY_IDENTIFIER, mod_abs);
9531
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00009532 /* Clear RX alarm since it stays up as long as the mod_abs
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00009533 * wasn't changed. This is need to be done before calling the
9534 * module detection, otherwise it will clear* the link update
9535 * alarm
9536 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009537 bnx2x_cl45_read(bp, phy,
9538 MDIO_PMA_DEVAD,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009539 MDIO_PMA_LASI_RXSTAT, &rx_alarm_status);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009540
9541
9542 if ((val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) ==
9543 PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_DISABLE_TX_LASER)
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00009544 bnx2x_sfp_set_transmitter(params, phy, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009545
9546 if (bnx2x_wait_for_sfp_module_initialized(phy, params) == 0)
9547 bnx2x_sfp_module_detection(phy, params);
9548 else
9549 DP(NETIF_MSG_LINK, "SFP+ module is not initialized\n");
Yuval Mintzdbef8072012-06-20 19:05:22 +00009550
9551 /* Reconfigure link speed based on module type limitations */
9552 bnx2x_8727_config_speed(phy, params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009553 }
9554
9555 DP(NETIF_MSG_LINK, "8727 RX_ALARM_STATUS 0x%x\n",
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00009556 rx_alarm_status);
9557 /* No need to check link status in case of module plugged in/out */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009558}
9559
9560static u8 bnx2x_8727_read_status(struct bnx2x_phy *phy,
9561 struct link_params *params,
9562 struct link_vars *vars)
9563
9564{
9565 struct bnx2x *bp = params->bp;
Yaniv Rosner27d02432011-05-31 21:27:48 +00009566 u8 link_up = 0, oc_port = params->port;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009567 u16 link_status = 0;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00009568 u16 rx_alarm_status, lasi_ctrl, val1;
9569
9570 /* If PHY is not initialized, do not check link status */
9571 bnx2x_cl45_read(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009572 MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00009573 &lasi_ctrl);
9574 if (!lasi_ctrl)
9575 return 0;
9576
Yaniv Rosner9045f6b42011-05-31 21:28:27 +00009577 /* Check the LASI on Rx */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009578 bnx2x_cl45_read(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009579 MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXSTAT,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009580 &rx_alarm_status);
9581 vars->line_speed = 0;
9582 DP(NETIF_MSG_LINK, "8727 RX_ALARM_STATUS 0x%x\n", rx_alarm_status);
9583
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009584 bnx2x_sfp_mask_fault(bp, phy, MDIO_PMA_LASI_TXSTAT,
9585 MDIO_PMA_LASI_TXCTRL);
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00009586
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009587 bnx2x_cl45_read(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009588 MDIO_PMA_DEVAD, MDIO_PMA_LASI_STAT, &val1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009589
9590 DP(NETIF_MSG_LINK, "8727 LASI status 0x%x\n", val1);
9591
9592 /* Clear MSG-OUT */
9593 bnx2x_cl45_read(bp, phy,
9594 MDIO_PMA_DEVAD, MDIO_PMA_REG_M8051_MSGOUT_REG, &val1);
9595
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00009596 /* If a module is present and there is need to check
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009597 * for over current
9598 */
9599 if (!(phy->flags & FLAGS_NOC) && !(rx_alarm_status & (1<<5))) {
9600 /* Check over-current using 8727 GPIO0 input*/
9601 bnx2x_cl45_read(bp, phy,
9602 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_GPIO_CTRL,
9603 &val1);
9604
9605 if ((val1 & (1<<8)) == 0) {
Yaniv Rosner27d02432011-05-31 21:27:48 +00009606 if (!CHIP_IS_E1x(bp))
9607 oc_port = BP_PATH(bp) + (params->port << 1);
Joe Perches94f05b02011-08-14 12:16:20 +00009608 DP(NETIF_MSG_LINK,
9609 "8727 Power fault has been detected on port %d\n",
9610 oc_port);
Yaniv Rosner2f751a82011-11-28 00:49:52 +00009611 netdev_err(bp->dev, "Error: Power fault on Port %d has "
9612 "been detected and the power to "
9613 "that SFP+ module has been removed "
9614 "to prevent failure of the card. "
9615 "Please remove the SFP+ module and "
9616 "restart the system to clear this "
9617 "error.\n",
Yaniv Rosner27d02432011-05-31 21:27:48 +00009618 oc_port);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00009619 /* Disable all RX_ALARMs except for mod_abs */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009620 bnx2x_cl45_write(bp, phy,
9621 MDIO_PMA_DEVAD,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009622 MDIO_PMA_LASI_RXCTRL, (1<<5));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009623
9624 bnx2x_cl45_read(bp, phy,
9625 MDIO_PMA_DEVAD,
9626 MDIO_PMA_REG_PHY_IDENTIFIER, &val1);
9627 /* Wait for module_absent_event */
9628 val1 |= (1<<8);
9629 bnx2x_cl45_write(bp, phy,
9630 MDIO_PMA_DEVAD,
9631 MDIO_PMA_REG_PHY_IDENTIFIER, val1);
9632 /* Clear RX alarm */
9633 bnx2x_cl45_read(bp, phy,
9634 MDIO_PMA_DEVAD,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009635 MDIO_PMA_LASI_RXSTAT, &rx_alarm_status);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009636 return 0;
9637 }
9638 } /* Over current check */
9639
9640 /* When module absent bit is set, check module */
9641 if (rx_alarm_status & (1<<5)) {
9642 bnx2x_8727_handle_mod_abs(phy, params);
9643 /* Enable all mod_abs and link detection bits */
9644 bnx2x_cl45_write(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009645 MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXCTRL,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009646 ((1<<5) | (1<<2)));
9647 }
Yaniv Rosner59a2e532012-04-04 01:28:59 +00009648
9649 if (!(phy->flags & FLAGS_SFP_NOT_APPROVED)) {
9650 DP(NETIF_MSG_LINK, "Enabling 8727 TX laser\n");
9651 bnx2x_sfp_set_transmitter(params, phy, 1);
9652 } else {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009653 DP(NETIF_MSG_LINK, "Tx is disabled\n");
9654 return 0;
9655 }
9656
9657 bnx2x_cl45_read(bp, phy,
9658 MDIO_PMA_DEVAD,
9659 MDIO_PMA_REG_8073_SPEED_LINK_STATUS, &link_status);
9660
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00009661 /* Bits 0..2 --> speed detected,
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00009662 * Bits 13..15--> link is down
9663 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009664 if ((link_status & (1<<2)) && (!(link_status & (1<<15)))) {
9665 link_up = 1;
9666 vars->line_speed = SPEED_10000;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00009667 DP(NETIF_MSG_LINK, "port %x: External link up in 10G\n",
9668 params->port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009669 } else if ((link_status & (1<<0)) && (!(link_status & (1<<13)))) {
9670 link_up = 1;
9671 vars->line_speed = SPEED_1000;
9672 DP(NETIF_MSG_LINK, "port %x: External link up in 1G\n",
9673 params->port);
9674 } else {
9675 link_up = 0;
9676 DP(NETIF_MSG_LINK, "port %x: External link is down\n",
9677 params->port);
9678 }
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00009679
9680 /* Capture 10G link fault. */
9681 if (vars->line_speed == SPEED_10000) {
9682 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009683 MDIO_PMA_LASI_TXSTAT, &val1);
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00009684
9685 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009686 MDIO_PMA_LASI_TXSTAT, &val1);
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00009687
9688 if (val1 & (1<<0)) {
9689 vars->fault_detected = 1;
9690 }
9691 }
9692
Yaniv Rosner791f18c2011-01-18 04:33:42 +00009693 if (link_up) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009694 bnx2x_ext_phy_resolve_fc(phy, params, vars);
Yaniv Rosner791f18c2011-01-18 04:33:42 +00009695 vars->duplex = DUPLEX_FULL;
9696 DP(NETIF_MSG_LINK, "duplex = 0x%x\n", vars->duplex);
9697 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +00009698
9699 if ((DUAL_MEDIA(params)) &&
9700 (phy->req_line_speed == SPEED_1000)) {
9701 bnx2x_cl45_read(bp, phy,
9702 MDIO_PMA_DEVAD,
9703 MDIO_PMA_REG_8727_PCS_GP, &val1);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00009704 /* In case of dual-media board and 1G, power up the XAUI side,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00009705 * otherwise power it down. For 10G it is done automatically
9706 */
9707 if (link_up)
9708 val1 &= ~(3<<10);
9709 else
9710 val1 |= (3<<10);
9711 bnx2x_cl45_write(bp, phy,
9712 MDIO_PMA_DEVAD,
9713 MDIO_PMA_REG_8727_PCS_GP, val1);
9714 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009715 return link_up;
9716}
9717
9718static void bnx2x_8727_link_reset(struct bnx2x_phy *phy,
9719 struct link_params *params)
9720{
9721 struct bnx2x *bp = params->bp;
Yaniv Rosner85242ee2011-07-05 01:06:53 +00009722
9723 /* Enable/Disable PHY transmitter output */
9724 bnx2x_set_disable_pmd_transmit(params, phy, 1);
9725
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009726 /* Disable Transmitter */
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00009727 bnx2x_sfp_set_transmitter(params, phy, 0);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00009728 /* Clear LASI */
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009729 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL, 0);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00009730
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009731}
9732
9733/******************************************************************/
9734/* BCM8481/BCM84823/BCM84833 PHY SECTION */
9735/******************************************************************/
9736static void bnx2x_save_848xx_spirom_version(struct bnx2x_phy *phy,
Yaniv Rosner11b2ec62012-01-17 02:33:25 +00009737 struct bnx2x *bp,
9738 u8 port)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009739{
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009740 u16 val, fw_ver1, fw_ver2, cnt;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009741
Yaniv Rosner11b2ec62012-01-17 02:33:25 +00009742 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833) {
9743 bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD, 0x400f, &fw_ver1);
Yaniv Rosner8267bbb02012-04-04 01:29:00 +00009744 bnx2x_save_spirom_version(bp, port, fw_ver1 & 0xfff,
Yaniv Rosner11b2ec62012-01-17 02:33:25 +00009745 phy->ver_addr);
9746 } else {
9747 /* For 32-bit registers in 848xx, access via MDIO2ARM i/f. */
9748 /* (1) set reg 0xc200_0014(SPI_BRIDGE_CTRL_2) to 0x03000000 */
9749 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA819, 0x0014);
9750 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA81A, 0xc200);
9751 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA81B, 0x0000);
9752 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA81C, 0x0300);
9753 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA817, 0x0009);
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00009754
Yaniv Rosner11b2ec62012-01-17 02:33:25 +00009755 for (cnt = 0; cnt < 100; cnt++) {
9756 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD, 0xA818, &val);
9757 if (val & 1)
9758 break;
9759 udelay(5);
9760 }
9761 if (cnt == 100) {
9762 DP(NETIF_MSG_LINK, "Unable to read 848xx "
9763 "phy fw version(1)\n");
9764 bnx2x_save_spirom_version(bp, port, 0,
9765 phy->ver_addr);
9766 return;
9767 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009768
Yaniv Rosner11b2ec62012-01-17 02:33:25 +00009769
9770 /* 2) read register 0xc200_0000 (SPI_FW_STATUS) */
9771 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA819, 0x0000);
9772 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA81A, 0xc200);
9773 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA817, 0x000A);
9774 for (cnt = 0; cnt < 100; cnt++) {
9775 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD, 0xA818, &val);
9776 if (val & 1)
9777 break;
9778 udelay(5);
9779 }
9780 if (cnt == 100) {
9781 DP(NETIF_MSG_LINK, "Unable to read 848xx phy fw "
9782 "version(2)\n");
9783 bnx2x_save_spirom_version(bp, port, 0,
9784 phy->ver_addr);
9785 return;
9786 }
9787
9788 /* lower 16 bits of the register SPI_FW_STATUS */
9789 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD, 0xA81B, &fw_ver1);
9790 /* upper 16 bits of register SPI_FW_STATUS */
9791 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD, 0xA81C, &fw_ver2);
9792
9793 bnx2x_save_spirom_version(bp, port, (fw_ver2<<16) | fw_ver1,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009794 phy->ver_addr);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009795 }
9796
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009797}
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009798static void bnx2x_848xx_set_led(struct bnx2x *bp,
9799 struct bnx2x_phy *phy)
9800{
Yaniv Rosner521683d2011-11-28 00:49:48 +00009801 u16 val, offset;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009802
9803 /* PHYC_CTL_LED_CTL */
9804 bnx2x_cl45_read(bp, phy,
9805 MDIO_PMA_DEVAD,
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009806 MDIO_PMA_REG_8481_LINK_SIGNAL, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009807 val &= 0xFE00;
9808 val |= 0x0092;
9809
9810 bnx2x_cl45_write(bp, phy,
9811 MDIO_PMA_DEVAD,
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009812 MDIO_PMA_REG_8481_LINK_SIGNAL, val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009813
9814 bnx2x_cl45_write(bp, phy,
9815 MDIO_PMA_DEVAD,
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009816 MDIO_PMA_REG_8481_LED1_MASK,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009817 0x80);
9818
9819 bnx2x_cl45_write(bp, phy,
9820 MDIO_PMA_DEVAD,
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009821 MDIO_PMA_REG_8481_LED2_MASK,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009822 0x18);
9823
Yaniv Rosnerf25b3c82011-01-18 04:33:47 +00009824 /* Select activity source by Tx and Rx, as suggested by PHY AE */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009825 bnx2x_cl45_write(bp, phy,
9826 MDIO_PMA_DEVAD,
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009827 MDIO_PMA_REG_8481_LED3_MASK,
Yaniv Rosnerf25b3c82011-01-18 04:33:47 +00009828 0x0006);
9829
9830 /* Select the closest activity blink rate to that in 10/100/1000 */
9831 bnx2x_cl45_write(bp, phy,
9832 MDIO_PMA_DEVAD,
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009833 MDIO_PMA_REG_8481_LED3_BLINK,
Yaniv Rosnerf25b3c82011-01-18 04:33:47 +00009834 0);
9835
Yaniv Rosner521683d2011-11-28 00:49:48 +00009836 /* Configure the blink rate to ~15.9 Hz */
Yaniv Rosnerf25b3c82011-01-18 04:33:47 +00009837 bnx2x_cl45_write(bp, phy,
Yaniv Rosner521683d2011-11-28 00:49:48 +00009838 MDIO_PMA_DEVAD,
9839 MDIO_PMA_REG_84823_CTL_SLOW_CLK_CNT_HIGH,
9840 MDIO_PMA_REG_84823_BLINK_RATE_VAL_15P9HZ);
9841
9842 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
9843 offset = MDIO_PMA_REG_84833_CTL_LED_CTL_1;
9844 else
9845 offset = MDIO_PMA_REG_84823_CTL_LED_CTL_1;
9846
9847 bnx2x_cl45_read(bp, phy,
9848 MDIO_PMA_DEVAD, offset, &val);
9849 val |= MDIO_PMA_REG_84823_LED3_STRETCH_EN; /* stretch_en for LED3*/
9850 bnx2x_cl45_write(bp, phy,
9851 MDIO_PMA_DEVAD, offset, val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009852
9853 /* 'Interrupt Mask' */
9854 bnx2x_cl45_write(bp, phy,
9855 MDIO_AN_DEVAD,
9856 0xFFFB, 0xFFFD);
9857}
9858
Yaniv Rosner5c107fd2012-09-13 02:56:19 +00009859static void bnx2x_848xx_specific_func(struct bnx2x_phy *phy,
9860 struct link_params *params,
9861 u32 action)
9862{
9863 struct bnx2x *bp = params->bp;
9864 switch (action) {
9865 case PHY_INIT:
9866 if (phy->type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833) {
9867 /* Save spirom version */
9868 bnx2x_save_848xx_spirom_version(phy, bp, params->port);
9869 }
9870 /* This phy uses the NIG latch mechanism since link indication
9871 * arrives through its LED4 and not via its LASI signal, so we
9872 * get steady signal instead of clear on read
9873 */
9874 bnx2x_bits_en(bp, NIG_REG_LATCH_BC_0 + params->port*4,
9875 1 << NIG_LATCH_BC_ENABLE_MI_INT);
9876
9877 bnx2x_848xx_set_led(bp, phy);
9878 break;
9879 }
9880}
9881
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00009882static int bnx2x_848xx_cmn_config_init(struct bnx2x_phy *phy,
9883 struct link_params *params,
9884 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009885{
9886 struct bnx2x *bp = params->bp;
Yaniv Rosner521683d2011-11-28 00:49:48 +00009887 u16 autoneg_val, an_1000_val, an_10_100_val, an_10g_val;
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009888
Yaniv Rosner5c107fd2012-09-13 02:56:19 +00009889 bnx2x_848xx_specific_func(phy, params, PHY_INIT);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009890 bnx2x_cl45_write(bp, phy,
9891 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x0000);
9892
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009893 /* set 1000 speed advertisement */
9894 bnx2x_cl45_read(bp, phy,
9895 MDIO_AN_DEVAD, MDIO_AN_REG_8481_1000T_CTRL,
9896 &an_1000_val);
9897
9898 bnx2x_ext_phy_set_pause(params, phy, vars);
9899 bnx2x_cl45_read(bp, phy,
9900 MDIO_AN_DEVAD,
9901 MDIO_AN_REG_8481_LEGACY_AN_ADV,
9902 &an_10_100_val);
9903 bnx2x_cl45_read(bp, phy,
9904 MDIO_AN_DEVAD, MDIO_AN_REG_8481_LEGACY_MII_CTRL,
9905 &autoneg_val);
9906 /* Disable forced speed */
9907 autoneg_val &= ~((1<<6) | (1<<8) | (1<<9) | (1<<12) | (1<<13));
9908 an_10_100_val &= ~((1<<5) | (1<<6) | (1<<7) | (1<<8));
9909
9910 if (((phy->req_line_speed == SPEED_AUTO_NEG) &&
9911 (phy->speed_cap_mask &
9912 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) ||
9913 (phy->req_line_speed == SPEED_1000)) {
9914 an_1000_val |= (1<<8);
9915 autoneg_val |= (1<<9 | 1<<12);
9916 if (phy->req_duplex == DUPLEX_FULL)
9917 an_1000_val |= (1<<9);
9918 DP(NETIF_MSG_LINK, "Advertising 1G\n");
9919 } else
9920 an_1000_val &= ~((1<<8) | (1<<9));
9921
9922 bnx2x_cl45_write(bp, phy,
9923 MDIO_AN_DEVAD, MDIO_AN_REG_8481_1000T_CTRL,
9924 an_1000_val);
9925
Yaniv Rosner0520e632011-07-05 01:06:59 +00009926 /* set 100 speed advertisement */
Yaniv Rosner75318322012-01-17 02:33:27 +00009927 if ((phy->req_line_speed == SPEED_AUTO_NEG) &&
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009928 (phy->speed_cap_mask &
Yaniv Rosner0520e632011-07-05 01:06:59 +00009929 (PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL |
Yaniv Rosner75318322012-01-17 02:33:27 +00009930 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009931 an_10_100_val |= (1<<7);
9932 /* Enable autoneg and restart autoneg for legacy speeds */
9933 autoneg_val |= (1<<9 | 1<<12);
9934
9935 if (phy->req_duplex == DUPLEX_FULL)
9936 an_10_100_val |= (1<<8);
9937 DP(NETIF_MSG_LINK, "Advertising 100M\n");
9938 }
9939 /* set 10 speed advertisement */
9940 if (((phy->req_line_speed == SPEED_AUTO_NEG) &&
Yaniv Rosner0520e632011-07-05 01:06:59 +00009941 (phy->speed_cap_mask &
9942 (PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL |
9943 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF)) &&
9944 (phy->supported &
9945 (SUPPORTED_10baseT_Half |
9946 SUPPORTED_10baseT_Full)))) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009947 an_10_100_val |= (1<<5);
9948 autoneg_val |= (1<<9 | 1<<12);
9949 if (phy->req_duplex == DUPLEX_FULL)
9950 an_10_100_val |= (1<<6);
9951 DP(NETIF_MSG_LINK, "Advertising 10M\n");
9952 }
9953
9954 /* Only 10/100 are allowed to work in FORCE mode */
Yaniv Rosner0520e632011-07-05 01:06:59 +00009955 if ((phy->req_line_speed == SPEED_100) &&
9956 (phy->supported &
9957 (SUPPORTED_100baseT_Half |
9958 SUPPORTED_100baseT_Full))) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009959 autoneg_val |= (1<<13);
9960 /* Enabled AUTO-MDIX when autoneg is disabled */
9961 bnx2x_cl45_write(bp, phy,
9962 MDIO_AN_DEVAD, MDIO_AN_REG_8481_AUX_CTRL,
9963 (1<<15 | 1<<9 | 7<<0));
Yaniv Rosner521683d2011-11-28 00:49:48 +00009964 /* The PHY needs this set even for forced link. */
9965 an_10_100_val |= (1<<8) | (1<<7);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009966 DP(NETIF_MSG_LINK, "Setting 100M force\n");
9967 }
Yaniv Rosner0520e632011-07-05 01:06:59 +00009968 if ((phy->req_line_speed == SPEED_10) &&
9969 (phy->supported &
9970 (SUPPORTED_10baseT_Half |
9971 SUPPORTED_10baseT_Full))) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009972 /* Enabled AUTO-MDIX when autoneg is disabled */
9973 bnx2x_cl45_write(bp, phy,
9974 MDIO_AN_DEVAD, MDIO_AN_REG_8481_AUX_CTRL,
9975 (1<<15 | 1<<9 | 7<<0));
9976 DP(NETIF_MSG_LINK, "Setting 10M force\n");
9977 }
9978
9979 bnx2x_cl45_write(bp, phy,
9980 MDIO_AN_DEVAD, MDIO_AN_REG_8481_LEGACY_AN_ADV,
9981 an_10_100_val);
9982
9983 if (phy->req_duplex == DUPLEX_FULL)
9984 autoneg_val |= (1<<8);
9985
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00009986 /* Always write this if this is not 84833.
Yaniv Rosnerfd38f73e2011-08-02 22:59:53 +00009987 * For 84833, write it only when it's a forced speed.
9988 */
9989 if ((phy->type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833) ||
9990 ((autoneg_val & (1<<12)) == 0))
9991 bnx2x_cl45_write(bp, phy,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009992 MDIO_AN_DEVAD,
9993 MDIO_AN_REG_8481_LEGACY_MII_CTRL, autoneg_val);
9994
9995 if (((phy->req_line_speed == SPEED_AUTO_NEG) &&
9996 (phy->speed_cap_mask &
9997 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) ||
9998 (phy->req_line_speed == SPEED_10000)) {
Yaniv Rosner9045f6b42011-05-31 21:28:27 +00009999 DP(NETIF_MSG_LINK, "Advertising 10G\n");
10000 /* Restart autoneg for 10G*/
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010001
Yaniv Rosner521683d2011-11-28 00:49:48 +000010002 bnx2x_cl45_read(bp, phy,
10003 MDIO_AN_DEVAD,
10004 MDIO_AN_REG_8481_10GBASE_T_AN_CTRL,
10005 &an_10g_val);
Yaniv Rosner9045f6b42011-05-31 21:28:27 +000010006 bnx2x_cl45_write(bp, phy,
Yaniv Rosner521683d2011-11-28 00:49:48 +000010007 MDIO_AN_DEVAD,
10008 MDIO_AN_REG_8481_10GBASE_T_AN_CTRL,
10009 an_10g_val | 0x1000);
10010 bnx2x_cl45_write(bp, phy,
10011 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL,
10012 0x3200);
Yaniv Rosnerfd38f73e2011-08-02 22:59:53 +000010013 } else
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010014 bnx2x_cl45_write(bp, phy,
10015 MDIO_AN_DEVAD,
10016 MDIO_AN_REG_8481_10GBASE_T_AN_CTRL,
10017 1);
Yaniv Rosnerfd38f73e2011-08-02 22:59:53 +000010018
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010019 return 0;
10020}
10021
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000010022static int bnx2x_8481_config_init(struct bnx2x_phy *phy,
10023 struct link_params *params,
10024 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010025{
10026 struct bnx2x *bp = params->bp;
10027 /* Restore normal power mode*/
10028 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010029 MISC_REGISTERS_GPIO_OUTPUT_HIGH, params->port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010030
10031 /* HW reset */
10032 bnx2x_ext_phy_hw_reset(bp, params->port);
Yaniv Rosner6d870c32011-01-31 04:22:20 +000010033 bnx2x_wait_reset_complete(bp, phy, params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010034
10035 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 1<<15);
10036 return bnx2x_848xx_cmn_config_init(phy, params, vars);
10037}
10038
Yaniv Rosner521683d2011-11-28 00:49:48 +000010039#define PHY84833_CMDHDLR_WAIT 300
10040#define PHY84833_CMDHDLR_MAX_ARGS 5
10041static int bnx2x_84833_cmd_hdlr(struct bnx2x_phy *phy,
10042 struct link_params *params,
10043 u16 fw_cmd,
Yuval Mintzc8c60d82012-06-06 17:13:07 +000010044 u16 cmd_args[], int argc)
Yaniv Rosner521683d2011-11-28 00:49:48 +000010045{
Yuval Mintzc8c60d82012-06-06 17:13:07 +000010046 int idx;
Yaniv Rosner521683d2011-11-28 00:49:48 +000010047 u16 val;
10048 struct bnx2x *bp = params->bp;
10049 /* Write CMD_OPEN_OVERRIDE to STATUS reg */
10050 bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
10051 MDIO_84833_CMD_HDLR_STATUS,
10052 PHY84833_STATUS_CMD_OPEN_OVERRIDE);
10053 for (idx = 0; idx < PHY84833_CMDHDLR_WAIT; idx++) {
10054 bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD,
10055 MDIO_84833_CMD_HDLR_STATUS, &val);
10056 if (val == PHY84833_STATUS_CMD_OPEN_FOR_CMDS)
10057 break;
Yuval Mintzd2310232012-06-20 19:05:19 +000010058 usleep_range(1000, 2000);
Yaniv Rosner521683d2011-11-28 00:49:48 +000010059 }
10060 if (idx >= PHY84833_CMDHDLR_WAIT) {
10061 DP(NETIF_MSG_LINK, "FW cmd: FW not ready.\n");
10062 return -EINVAL;
10063 }
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010064
Yaniv Rosner521683d2011-11-28 00:49:48 +000010065 /* Prepare argument(s) and issue command */
Yuval Mintzc8c60d82012-06-06 17:13:07 +000010066 for (idx = 0; idx < argc; idx++) {
Yaniv Rosner521683d2011-11-28 00:49:48 +000010067 bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
10068 MDIO_84833_CMD_HDLR_DATA1 + idx,
10069 cmd_args[idx]);
10070 }
10071 bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
10072 MDIO_84833_CMD_HDLR_COMMAND, fw_cmd);
10073 for (idx = 0; idx < PHY84833_CMDHDLR_WAIT; idx++) {
10074 bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD,
10075 MDIO_84833_CMD_HDLR_STATUS, &val);
10076 if ((val == PHY84833_STATUS_CMD_COMPLETE_PASS) ||
10077 (val == PHY84833_STATUS_CMD_COMPLETE_ERROR))
10078 break;
Yuval Mintzd2310232012-06-20 19:05:19 +000010079 usleep_range(1000, 2000);
Yaniv Rosner521683d2011-11-28 00:49:48 +000010080 }
10081 if ((idx >= PHY84833_CMDHDLR_WAIT) ||
10082 (val == PHY84833_STATUS_CMD_COMPLETE_ERROR)) {
10083 DP(NETIF_MSG_LINK, "FW cmd failed.\n");
10084 return -EINVAL;
10085 }
10086 /* Gather returning data */
Yuval Mintzc8c60d82012-06-06 17:13:07 +000010087 for (idx = 0; idx < argc; idx++) {
Yaniv Rosner521683d2011-11-28 00:49:48 +000010088 bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD,
10089 MDIO_84833_CMD_HDLR_DATA1 + idx,
10090 &cmd_args[idx]);
10091 }
10092 bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
10093 MDIO_84833_CMD_HDLR_STATUS,
10094 PHY84833_STATUS_CMD_CLEAR_COMPLETE);
10095 return 0;
10096}
10097
10098
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010099static int bnx2x_84833_pair_swap_cfg(struct bnx2x_phy *phy,
10100 struct link_params *params,
10101 struct link_vars *vars)
10102{
Yaniv Rosner0520e632011-07-05 01:06:59 +000010103 u32 pair_swap;
Yaniv Rosner521683d2011-11-28 00:49:48 +000010104 u16 data[PHY84833_CMDHDLR_MAX_ARGS];
10105 int status;
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010106 struct bnx2x *bp = params->bp;
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010107
Yaniv Rosner0520e632011-07-05 01:06:59 +000010108 /* Check for configuration. */
10109 pair_swap = REG_RD(bp, params->shmem_base +
10110 offsetof(struct shmem_region,
10111 dev_info.port_hw_config[params->port].xgbt_phy_cfg)) &
10112 PORT_HW_CFG_RJ45_PAIR_SWAP_MASK;
10113
10114 if (pair_swap == 0)
10115 return 0;
10116
Yaniv Rosner521683d2011-11-28 00:49:48 +000010117 /* Only the second argument is used for this command */
10118 data[1] = (u16)pair_swap;
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010119
Yaniv Rosner521683d2011-11-28 00:49:48 +000010120 status = bnx2x_84833_cmd_hdlr(phy, params,
Yuval Mintzc8c60d82012-06-06 17:13:07 +000010121 PHY84833_CMD_SET_PAIR_SWAP, data, PHY84833_CMDHDLR_MAX_ARGS);
Yaniv Rosner521683d2011-11-28 00:49:48 +000010122 if (status == 0)
10123 DP(NETIF_MSG_LINK, "Pairswap OK, val=0x%x\n", data[1]);
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010124
Yaniv Rosner521683d2011-11-28 00:49:48 +000010125 return status;
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010126}
10127
Yaniv Rosner985848f2011-07-05 01:06:48 +000010128static u8 bnx2x_84833_get_reset_gpios(struct bnx2x *bp,
10129 u32 shmem_base_path[],
10130 u32 chip_id)
Yaniv Rosner0d40f0d2011-06-14 01:34:27 +000010131{
10132 u32 reset_pin[2];
10133 u32 idx;
10134 u8 reset_gpios;
10135 if (CHIP_IS_E3(bp)) {
10136 /* Assume that these will be GPIOs, not EPIOs. */
10137 for (idx = 0; idx < 2; idx++) {
10138 /* Map config param to register bit. */
10139 reset_pin[idx] = REG_RD(bp, shmem_base_path[idx] +
10140 offsetof(struct shmem_region,
10141 dev_info.port_hw_config[0].e3_cmn_pin_cfg));
10142 reset_pin[idx] = (reset_pin[idx] &
10143 PORT_HW_CFG_E3_PHY_RESET_MASK) >>
10144 PORT_HW_CFG_E3_PHY_RESET_SHIFT;
10145 reset_pin[idx] -= PIN_CFG_GPIO0_P0;
10146 reset_pin[idx] = (1 << reset_pin[idx]);
10147 }
10148 reset_gpios = (u8)(reset_pin[0] | reset_pin[1]);
10149 } else {
10150 /* E2, look from diff place of shmem. */
10151 for (idx = 0; idx < 2; idx++) {
10152 reset_pin[idx] = REG_RD(bp, shmem_base_path[idx] +
10153 offsetof(struct shmem_region,
10154 dev_info.port_hw_config[0].default_cfg));
10155 reset_pin[idx] &= PORT_HW_CFG_EXT_PHY_GPIO_RST_MASK;
10156 reset_pin[idx] -= PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO0_P0;
10157 reset_pin[idx] >>= PORT_HW_CFG_EXT_PHY_GPIO_RST_SHIFT;
10158 reset_pin[idx] = (1 << reset_pin[idx]);
10159 }
10160 reset_gpios = (u8)(reset_pin[0] | reset_pin[1]);
10161 }
10162
Yaniv Rosner985848f2011-07-05 01:06:48 +000010163 return reset_gpios;
10164}
10165
10166static int bnx2x_84833_hw_reset_phy(struct bnx2x_phy *phy,
10167 struct link_params *params)
10168{
10169 struct bnx2x *bp = params->bp;
10170 u8 reset_gpios;
10171 u32 other_shmem_base_addr = REG_RD(bp, params->shmem2_base +
10172 offsetof(struct shmem2_region,
10173 other_shmem_base_addr));
10174
10175 u32 shmem_base_path[2];
Yaniv Rosner99bf7f32012-04-04 01:29:01 +000010176
10177 /* Work around for 84833 LED failure inside RESET status */
10178 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
10179 MDIO_AN_REG_8481_LEGACY_MII_CTRL,
10180 MDIO_AN_REG_8481_MII_CTRL_FORCE_1G);
10181 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
10182 MDIO_AN_REG_8481_1G_100T_EXT_CTRL,
10183 MIDO_AN_REG_8481_EXT_CTRL_FORCE_LEDS_OFF);
10184
Yaniv Rosner985848f2011-07-05 01:06:48 +000010185 shmem_base_path[0] = params->shmem_base;
10186 shmem_base_path[1] = other_shmem_base_addr;
10187
10188 reset_gpios = bnx2x_84833_get_reset_gpios(bp, shmem_base_path,
10189 params->chip_id);
10190
10191 bnx2x_set_mult_gpio(bp, reset_gpios, MISC_REGISTERS_GPIO_OUTPUT_LOW);
10192 udelay(10);
10193 DP(NETIF_MSG_LINK, "84833 hw reset on pin values 0x%x\n",
10194 reset_gpios);
10195
10196 return 0;
10197}
10198
Yuval Mintzc8c60d82012-06-06 17:13:07 +000010199static int bnx2x_8483x_disable_eee(struct bnx2x_phy *phy,
10200 struct link_params *params,
10201 struct link_vars *vars)
10202{
10203 int rc;
10204 struct bnx2x *bp = params->bp;
10205 u16 cmd_args = 0;
10206
10207 DP(NETIF_MSG_LINK, "Don't Advertise 10GBase-T EEE\n");
10208
Yuval Mintzc8c60d82012-06-06 17:13:07 +000010209 /* Prevent Phy from working in EEE and advertising it */
10210 rc = bnx2x_84833_cmd_hdlr(phy, params,
10211 PHY84833_CMD_SET_EEE_MODE, &cmd_args, 1);
Yuval Mintzd2310232012-06-20 19:05:19 +000010212 if (rc) {
Yuval Mintzc8c60d82012-06-06 17:13:07 +000010213 DP(NETIF_MSG_LINK, "EEE disable failed.\n");
10214 return rc;
10215 }
10216
Yuval Mintzec4010e2012-09-10 05:51:06 +000010217 return bnx2x_eee_disable(phy, params, vars);
Yuval Mintzc8c60d82012-06-06 17:13:07 +000010218}
10219
10220static int bnx2x_8483x_enable_eee(struct bnx2x_phy *phy,
10221 struct link_params *params,
10222 struct link_vars *vars)
10223{
10224 int rc;
10225 struct bnx2x *bp = params->bp;
10226 u16 cmd_args = 1;
10227
Yuval Mintzc8c60d82012-06-06 17:13:07 +000010228 rc = bnx2x_84833_cmd_hdlr(phy, params,
10229 PHY84833_CMD_SET_EEE_MODE, &cmd_args, 1);
Yuval Mintzd2310232012-06-20 19:05:19 +000010230 if (rc) {
Yuval Mintzc8c60d82012-06-06 17:13:07 +000010231 DP(NETIF_MSG_LINK, "EEE enable failed.\n");
10232 return rc;
10233 }
10234
Yuval Mintzec4010e2012-09-10 05:51:06 +000010235 return bnx2x_eee_advertise(phy, params, vars, SHMEM_EEE_10G_ADV);
Yuval Mintzc8c60d82012-06-06 17:13:07 +000010236}
10237
Yaniv Rosnera89a1d42011-07-05 01:07:05 +000010238#define PHY84833_CONSTANT_LATENCY 1193
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000010239static int bnx2x_848x3_config_init(struct bnx2x_phy *phy,
10240 struct link_params *params,
10241 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010242{
10243 struct bnx2x *bp = params->bp;
Yaniv Rosner6a71bbe2010-11-01 05:32:31 +000010244 u8 port, initialize = 1;
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010245 u16 val;
Yaniv Rosner521683d2011-11-28 00:49:48 +000010246 u32 actual_phy_selection, cms_enable;
10247 u16 cmd_args[PHY84833_CMDHDLR_MAX_ARGS];
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000010248 int rc = 0;
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010249
Yuval Mintzd2310232012-06-20 19:05:19 +000010250 usleep_range(1000, 2000);
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010251
Yuval Mintz54813882012-06-16 20:27:15 +000010252 if (!(CHIP_IS_E1x(bp)))
Yaniv Rosner6a71bbe2010-11-01 05:32:31 +000010253 port = BP_PATH(bp);
10254 else
10255 port = params->port;
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010256
10257 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84823) {
10258 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_3,
10259 MISC_REGISTERS_GPIO_OUTPUT_HIGH,
10260 port);
10261 } else {
Yaniv Rosner985848f2011-07-05 01:06:48 +000010262 /* MDIO reset */
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010263 bnx2x_cl45_write(bp, phy,
10264 MDIO_PMA_DEVAD,
10265 MDIO_PMA_REG_CTRL, 0x8000);
Yaniv Rosner521683d2011-11-28 00:49:48 +000010266 }
10267
10268 bnx2x_wait_reset_complete(bp, phy, params);
10269
10270 /* Wait for GPHY to come out of reset */
10271 msleep(50);
Yaniv Rosner11b2ec62012-01-17 02:33:25 +000010272 if (phy->type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833) {
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000010273 /* BCM84823 requires that XGXS links up first @ 10G for normal
Yaniv Rosner521683d2011-11-28 00:49:48 +000010274 * behavior.
10275 */
10276 u16 temp;
10277 temp = vars->line_speed;
10278 vars->line_speed = SPEED_10000;
10279 bnx2x_set_autoneg(&params->phy[INT_PHY], params, vars, 0);
10280 bnx2x_program_serdes(&params->phy[INT_PHY], params, vars);
10281 vars->line_speed = temp;
10282 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010283
10284 bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD,
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010285 MDIO_CTL_REG_84823_MEDIA, &val);
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010286 val &= ~(MDIO_CTL_REG_84823_MEDIA_MAC_MASK |
10287 MDIO_CTL_REG_84823_MEDIA_LINE_MASK |
10288 MDIO_CTL_REG_84823_MEDIA_COPPER_CORE_DOWN |
10289 MDIO_CTL_REG_84823_MEDIA_PRIORITY_MASK |
10290 MDIO_CTL_REG_84823_MEDIA_FIBER_1G);
Yaniv Rosner0d40f0d2011-06-14 01:34:27 +000010291
10292 if (CHIP_IS_E3(bp)) {
10293 val &= ~(MDIO_CTL_REG_84823_MEDIA_MAC_MASK |
10294 MDIO_CTL_REG_84823_MEDIA_LINE_MASK);
10295 } else {
10296 val |= (MDIO_CTL_REG_84823_CTRL_MAC_XFI |
10297 MDIO_CTL_REG_84823_MEDIA_LINE_XAUI_L);
10298 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010299
10300 actual_phy_selection = bnx2x_phy_selection(params);
10301
10302 switch (actual_phy_selection) {
10303 case PORT_HW_CFG_PHY_SELECTION_HARDWARE_DEFAULT:
Lucas De Marchi25985ed2011-03-30 22:57:33 -030010304 /* Do nothing. Essentially this is like the priority copper */
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010305 break;
10306 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY_PRIORITY:
10307 val |= MDIO_CTL_REG_84823_MEDIA_PRIORITY_COPPER;
10308 break;
10309 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY_PRIORITY:
10310 val |= MDIO_CTL_REG_84823_MEDIA_PRIORITY_FIBER;
10311 break;
10312 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY:
10313 /* Do nothing here. The first PHY won't be initialized at all */
10314 break;
10315 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY:
10316 val |= MDIO_CTL_REG_84823_MEDIA_COPPER_CORE_DOWN;
10317 initialize = 0;
10318 break;
10319 }
10320 if (params->phy[EXT_PHY2].req_line_speed == SPEED_1000)
10321 val |= MDIO_CTL_REG_84823_MEDIA_FIBER_1G;
10322
10323 bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010324 MDIO_CTL_REG_84823_MEDIA, val);
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010325 DP(NETIF_MSG_LINK, "Multi_phy config = 0x%x, Media control = 0x%x\n",
10326 params->multi_phy_config, val);
10327
Yaniv Rosner11b2ec62012-01-17 02:33:25 +000010328 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833) {
10329 bnx2x_84833_pair_swap_cfg(phy, params, vars);
Yaniv Rosnera89a1d42011-07-05 01:07:05 +000010330
Yaniv Rosner096b9522012-01-17 02:33:28 +000010331 /* Keep AutogrEEEn disabled. */
10332 cmd_args[0] = 0x0;
Yaniv Rosner11b2ec62012-01-17 02:33:25 +000010333 cmd_args[1] = 0x0;
10334 cmd_args[2] = PHY84833_CONSTANT_LATENCY + 1;
10335 cmd_args[3] = PHY84833_CONSTANT_LATENCY;
10336 rc = bnx2x_84833_cmd_hdlr(phy, params,
Yuval Mintzc8c60d82012-06-06 17:13:07 +000010337 PHY84833_CMD_SET_EEE_MODE, cmd_args,
10338 PHY84833_CMDHDLR_MAX_ARGS);
Yuval Mintzd2310232012-06-20 19:05:19 +000010339 if (rc)
Yaniv Rosner11b2ec62012-01-17 02:33:25 +000010340 DP(NETIF_MSG_LINK, "Cfg AutogrEEEn failed.\n");
10341 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010342 if (initialize)
10343 rc = bnx2x_848xx_cmn_config_init(phy, params, vars);
10344 else
Yaniv Rosner11b2ec62012-01-17 02:33:25 +000010345 bnx2x_save_848xx_spirom_version(phy, bp, params->port);
Yaniv Rosnera89a1d42011-07-05 01:07:05 +000010346 /* 84833 PHY has a better feature and doesn't need to support this. */
10347 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84823) {
10348 cms_enable = REG_RD(bp, params->shmem_base +
Yaniv Rosner1bef68e2011-01-31 04:22:46 +000010349 offsetof(struct shmem_region,
10350 dev_info.port_hw_config[params->port].default_cfg)) &
10351 PORT_HW_CFG_ENABLE_CMS_MASK;
10352
Yaniv Rosnera89a1d42011-07-05 01:07:05 +000010353 bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD,
10354 MDIO_CTL_REG_84823_USER_CTRL_REG, &val);
10355 if (cms_enable)
10356 val |= MDIO_CTL_REG_84823_USER_CTRL_CMS;
10357 else
10358 val &= ~MDIO_CTL_REG_84823_USER_CTRL_CMS;
10359 bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
10360 MDIO_CTL_REG_84823_USER_CTRL_REG, val);
10361 }
Yaniv Rosner1bef68e2011-01-31 04:22:46 +000010362
Yuval Mintzc8c60d82012-06-06 17:13:07 +000010363 bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD,
10364 MDIO_84833_TOP_CFG_FW_REV, &val);
10365
10366 /* Configure EEE support */
Yuval Mintzf6b6eb62012-09-10 05:51:07 +000010367 if ((val >= MDIO_84833_TOP_CFG_FW_EEE) &&
10368 (val != MDIO_84833_TOP_CFG_FW_NO_EEE) &&
10369 bnx2x_eee_has_cap(params)) {
Yuval Mintzec4010e2012-09-10 05:51:06 +000010370 rc = bnx2x_eee_initial_config(params, vars, SHMEM_EEE_10G_ADV);
Yuval Mintzd2310232012-06-20 19:05:19 +000010371 if (rc) {
Yuval Mintzc8c60d82012-06-06 17:13:07 +000010372 DP(NETIF_MSG_LINK, "Failed to configure EEE timers\n");
10373 bnx2x_8483x_disable_eee(phy, params, vars);
10374 return rc;
10375 }
10376
10377 if ((params->req_duplex[actual_phy_selection] == DUPLEX_FULL) &&
10378 (params->eee_mode & EEE_MODE_ADV_LPI) &&
10379 (bnx2x_eee_calc_timer(params) ||
10380 !(params->eee_mode & EEE_MODE_ENABLE_LPI)))
10381 rc = bnx2x_8483x_enable_eee(phy, params, vars);
10382 else
10383 rc = bnx2x_8483x_disable_eee(phy, params, vars);
Yuval Mintzd2310232012-06-20 19:05:19 +000010384 if (rc) {
Yuval Mintzc8c60d82012-06-06 17:13:07 +000010385 DP(NETIF_MSG_LINK, "Failed to set EEE advertisment\n");
10386 return rc;
10387 }
10388 } else {
Yuval Mintzc8c60d82012-06-06 17:13:07 +000010389 vars->eee_status &= ~SHMEM_EEE_SUPPORTED_MASK;
10390 }
10391
Yaniv Rosner11b2ec62012-01-17 02:33:25 +000010392 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833) {
10393 /* Bring PHY out of super isolate mode as the final step. */
10394 bnx2x_cl45_read(bp, phy,
10395 MDIO_CTL_DEVAD,
10396 MDIO_84833_TOP_CFG_XGPHY_STRAP1, &val);
10397 val &= ~MDIO_84833_SUPER_ISOLATE;
10398 bnx2x_cl45_write(bp, phy,
10399 MDIO_CTL_DEVAD,
10400 MDIO_84833_TOP_CFG_XGPHY_STRAP1, val);
10401 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010402 return rc;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010403}
10404
10405static u8 bnx2x_848xx_read_status(struct bnx2x_phy *phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010406 struct link_params *params,
10407 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010408{
10409 struct bnx2x *bp = params->bp;
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010410 u16 val, val1, val2;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010411 u8 link_up = 0;
10412
Yaniv Rosnerc87bca12011-01-31 04:22:41 +000010413
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010414 /* Check 10G-BaseT link status */
10415 /* Check PMD signal ok */
10416 bnx2x_cl45_read(bp, phy,
10417 MDIO_AN_DEVAD, 0xFFFA, &val1);
10418 bnx2x_cl45_read(bp, phy,
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010419 MDIO_PMA_DEVAD, MDIO_PMA_REG_8481_PMD_SIGNAL,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010420 &val2);
10421 DP(NETIF_MSG_LINK, "BCM848xx: PMD_SIGNAL 1.a811 = 0x%x\n", val2);
10422
10423 /* Check link 10G */
10424 if (val2 & (1<<11)) {
10425 vars->line_speed = SPEED_10000;
Yaniv Rosner791f18c2011-01-18 04:33:42 +000010426 vars->duplex = DUPLEX_FULL;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010427 link_up = 1;
10428 bnx2x_ext_phy_10G_an_resolve(bp, phy, vars);
10429 } else { /* Check Legacy speed link */
10430 u16 legacy_status, legacy_speed;
10431
10432 /* Enable expansion register 0x42 (Operation mode status) */
10433 bnx2x_cl45_write(bp, phy,
10434 MDIO_AN_DEVAD,
10435 MDIO_AN_REG_8481_EXPANSION_REG_ACCESS, 0xf42);
10436
10437 /* Get legacy speed operation status */
10438 bnx2x_cl45_read(bp, phy,
10439 MDIO_AN_DEVAD,
10440 MDIO_AN_REG_8481_EXPANSION_REG_RD_RW,
10441 &legacy_status);
10442
Joe Perches94f05b02011-08-14 12:16:20 +000010443 DP(NETIF_MSG_LINK, "Legacy speed status = 0x%x\n",
10444 legacy_status);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010445 link_up = ((legacy_status & (1<<11)) == (1<<11));
Yuval Mintz14400902012-06-20 19:05:20 +000010446 legacy_speed = (legacy_status & (3<<9));
10447 if (legacy_speed == (0<<9))
10448 vars->line_speed = SPEED_10;
10449 else if (legacy_speed == (1<<9))
10450 vars->line_speed = SPEED_100;
10451 else if (legacy_speed == (2<<9))
10452 vars->line_speed = SPEED_1000;
10453 else { /* Should not happen: Treat as link down */
10454 vars->line_speed = 0;
10455 link_up = 0;
10456 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010457
Yuval Mintz14400902012-06-20 19:05:20 +000010458 if (link_up) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010459 if (legacy_status & (1<<8))
10460 vars->duplex = DUPLEX_FULL;
10461 else
10462 vars->duplex = DUPLEX_HALF;
10463
Joe Perches94f05b02011-08-14 12:16:20 +000010464 DP(NETIF_MSG_LINK,
10465 "Link is up in %dMbps, is_duplex_full= %d\n",
10466 vars->line_speed,
10467 (vars->duplex == DUPLEX_FULL));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010468 /* Check legacy speed AN resolution */
10469 bnx2x_cl45_read(bp, phy,
10470 MDIO_AN_DEVAD,
10471 MDIO_AN_REG_8481_LEGACY_MII_STATUS,
10472 &val);
10473 if (val & (1<<5))
10474 vars->link_status |=
10475 LINK_STATUS_AUTO_NEGOTIATE_COMPLETE;
10476 bnx2x_cl45_read(bp, phy,
10477 MDIO_AN_DEVAD,
10478 MDIO_AN_REG_8481_LEGACY_AN_EXPANSION,
10479 &val);
10480 if ((val & (1<<0)) == 0)
10481 vars->link_status |=
10482 LINK_STATUS_PARALLEL_DETECTION_USED;
10483 }
10484 }
10485 if (link_up) {
Yuval Mintzd2310232012-06-20 19:05:19 +000010486 DP(NETIF_MSG_LINK, "BCM848x3: link speed is %d\n",
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010487 vars->line_speed);
10488 bnx2x_ext_phy_resolve_fc(phy, params, vars);
Mintz Yuval9e7e8392012-02-15 02:10:24 +000010489
10490 /* Read LP advertised speeds */
10491 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
10492 MDIO_AN_REG_CL37_FC_LP, &val);
10493 if (val & (1<<5))
10494 vars->link_status |=
10495 LINK_STATUS_LINK_PARTNER_10THD_CAPABLE;
10496 if (val & (1<<6))
10497 vars->link_status |=
10498 LINK_STATUS_LINK_PARTNER_10TFD_CAPABLE;
10499 if (val & (1<<7))
10500 vars->link_status |=
10501 LINK_STATUS_LINK_PARTNER_100TXHD_CAPABLE;
10502 if (val & (1<<8))
10503 vars->link_status |=
10504 LINK_STATUS_LINK_PARTNER_100TXFD_CAPABLE;
10505 if (val & (1<<9))
10506 vars->link_status |=
10507 LINK_STATUS_LINK_PARTNER_100T4_CAPABLE;
10508
10509 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
10510 MDIO_AN_REG_1000T_STATUS, &val);
10511
10512 if (val & (1<<10))
10513 vars->link_status |=
10514 LINK_STATUS_LINK_PARTNER_1000THD_CAPABLE;
10515 if (val & (1<<11))
10516 vars->link_status |=
10517 LINK_STATUS_LINK_PARTNER_1000TFD_CAPABLE;
10518
10519 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
10520 MDIO_AN_REG_MASTER_STATUS, &val);
10521
10522 if (val & (1<<11))
10523 vars->link_status |=
10524 LINK_STATUS_LINK_PARTNER_10GXFD_CAPABLE;
Yuval Mintzc8c60d82012-06-06 17:13:07 +000010525
10526 /* Determine if EEE was negotiated */
Yuval Mintzec4010e2012-09-10 05:51:06 +000010527 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
10528 bnx2x_eee_an_resolve(phy, params, vars);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010529 }
10530
10531 return link_up;
10532}
10533
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000010534
10535static int bnx2x_848xx_format_ver(u32 raw_ver, u8 *str, u16 *len)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010536{
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000010537 int status = 0;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010538 u32 spirom_ver;
10539 spirom_ver = ((raw_ver & 0xF80) >> 7) << 16 | (raw_ver & 0x7F);
10540 status = bnx2x_format_ver(spirom_ver, str, len);
10541 return status;
10542}
10543
10544static void bnx2x_8481_hw_reset(struct bnx2x_phy *phy,
10545 struct link_params *params)
10546{
10547 bnx2x_set_gpio(params->bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010548 MISC_REGISTERS_GPIO_OUTPUT_LOW, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010549 bnx2x_set_gpio(params->bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010550 MISC_REGISTERS_GPIO_OUTPUT_LOW, 1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010551}
10552
10553static void bnx2x_8481_link_reset(struct bnx2x_phy *phy,
10554 struct link_params *params)
10555{
10556 bnx2x_cl45_write(params->bp, phy,
10557 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x0000);
10558 bnx2x_cl45_write(params->bp, phy,
10559 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 1);
10560}
10561
10562static void bnx2x_848x3_link_reset(struct bnx2x_phy *phy,
10563 struct link_params *params)
10564{
10565 struct bnx2x *bp = params->bp;
Yaniv Rosner6a71bbe2010-11-01 05:32:31 +000010566 u8 port;
Yaniv Rosner0d40f0d2011-06-14 01:34:27 +000010567 u16 val16;
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010568
Yaniv Rosnerf93fb012012-04-04 01:29:02 +000010569 if (!(CHIP_IS_E1x(bp)))
Yaniv Rosner6a71bbe2010-11-01 05:32:31 +000010570 port = BP_PATH(bp);
10571 else
10572 port = params->port;
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010573
10574 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84823) {
10575 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_3,
10576 MISC_REGISTERS_GPIO_OUTPUT_LOW,
10577 port);
10578 } else {
Yaniv Rosner0d40f0d2011-06-14 01:34:27 +000010579 bnx2x_cl45_read(bp, phy,
10580 MDIO_CTL_DEVAD,
Yaniv Rosner11b2ec62012-01-17 02:33:25 +000010581 MDIO_84833_TOP_CFG_XGPHY_STRAP1, &val16);
10582 val16 |= MDIO_84833_SUPER_ISOLATE;
Yaniv Rosnerfd38f73e2011-08-02 22:59:53 +000010583 bnx2x_cl45_write(bp, phy,
Yaniv Rosner11b2ec62012-01-17 02:33:25 +000010584 MDIO_CTL_DEVAD,
10585 MDIO_84833_TOP_CFG_XGPHY_STRAP1, val16);
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010586 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010587}
10588
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010589static void bnx2x_848xx_set_link_led(struct bnx2x_phy *phy,
10590 struct link_params *params, u8 mode)
10591{
10592 struct bnx2x *bp = params->bp;
10593 u16 val;
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010594 u8 port;
10595
Yaniv Rosnerf93fb012012-04-04 01:29:02 +000010596 if (!(CHIP_IS_E1x(bp)))
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010597 port = BP_PATH(bp);
10598 else
10599 port = params->port;
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010600
10601 switch (mode) {
10602 case LED_MODE_OFF:
10603
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010604 DP(NETIF_MSG_LINK, "Port 0x%x: LED MODE OFF\n", port);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010605
10606 if ((params->hw_led_mode << SHARED_HW_CFG_LED_MODE_SHIFT) ==
10607 SHARED_HW_CFG_LED_EXTPHY1) {
10608
10609 /* Set LED masks */
10610 bnx2x_cl45_write(bp, phy,
10611 MDIO_PMA_DEVAD,
10612 MDIO_PMA_REG_8481_LED1_MASK,
10613 0x0);
10614
10615 bnx2x_cl45_write(bp, phy,
10616 MDIO_PMA_DEVAD,
10617 MDIO_PMA_REG_8481_LED2_MASK,
10618 0x0);
10619
10620 bnx2x_cl45_write(bp, phy,
10621 MDIO_PMA_DEVAD,
10622 MDIO_PMA_REG_8481_LED3_MASK,
10623 0x0);
10624
10625 bnx2x_cl45_write(bp, phy,
10626 MDIO_PMA_DEVAD,
10627 MDIO_PMA_REG_8481_LED5_MASK,
10628 0x0);
10629
10630 } else {
10631 bnx2x_cl45_write(bp, phy,
10632 MDIO_PMA_DEVAD,
10633 MDIO_PMA_REG_8481_LED1_MASK,
10634 0x0);
10635 }
10636 break;
10637 case LED_MODE_FRONT_PANEL_OFF:
10638
10639 DP(NETIF_MSG_LINK, "Port 0x%x: LED MODE FRONT PANEL OFF\n",
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010640 port);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010641
10642 if ((params->hw_led_mode << SHARED_HW_CFG_LED_MODE_SHIFT) ==
10643 SHARED_HW_CFG_LED_EXTPHY1) {
10644
10645 /* Set LED masks */
10646 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010647 MDIO_PMA_DEVAD,
10648 MDIO_PMA_REG_8481_LED1_MASK,
10649 0x0);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010650
10651 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010652 MDIO_PMA_DEVAD,
10653 MDIO_PMA_REG_8481_LED2_MASK,
10654 0x0);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010655
10656 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010657 MDIO_PMA_DEVAD,
10658 MDIO_PMA_REG_8481_LED3_MASK,
10659 0x0);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010660
10661 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010662 MDIO_PMA_DEVAD,
10663 MDIO_PMA_REG_8481_LED5_MASK,
10664 0x20);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010665
10666 } else {
10667 bnx2x_cl45_write(bp, phy,
10668 MDIO_PMA_DEVAD,
10669 MDIO_PMA_REG_8481_LED1_MASK,
10670 0x0);
10671 }
10672 break;
10673 case LED_MODE_ON:
10674
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010675 DP(NETIF_MSG_LINK, "Port 0x%x: LED MODE ON\n", port);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010676
10677 if ((params->hw_led_mode << SHARED_HW_CFG_LED_MODE_SHIFT) ==
10678 SHARED_HW_CFG_LED_EXTPHY1) {
10679 /* Set control reg */
10680 bnx2x_cl45_read(bp, phy,
10681 MDIO_PMA_DEVAD,
10682 MDIO_PMA_REG_8481_LINK_SIGNAL,
10683 &val);
10684 val &= 0x8000;
10685 val |= 0x2492;
10686
10687 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010688 MDIO_PMA_DEVAD,
10689 MDIO_PMA_REG_8481_LINK_SIGNAL,
10690 val);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010691
10692 /* Set LED masks */
10693 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010694 MDIO_PMA_DEVAD,
10695 MDIO_PMA_REG_8481_LED1_MASK,
10696 0x0);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010697
10698 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010699 MDIO_PMA_DEVAD,
10700 MDIO_PMA_REG_8481_LED2_MASK,
10701 0x20);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010702
10703 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010704 MDIO_PMA_DEVAD,
10705 MDIO_PMA_REG_8481_LED3_MASK,
10706 0x20);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010707
10708 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010709 MDIO_PMA_DEVAD,
10710 MDIO_PMA_REG_8481_LED5_MASK,
10711 0x0);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010712 } else {
10713 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010714 MDIO_PMA_DEVAD,
10715 MDIO_PMA_REG_8481_LED1_MASK,
10716 0x20);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010717 }
10718 break;
10719
10720 case LED_MODE_OPER:
10721
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010722 DP(NETIF_MSG_LINK, "Port 0x%x: LED MODE OPER\n", port);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010723
10724 if ((params->hw_led_mode << SHARED_HW_CFG_LED_MODE_SHIFT) ==
10725 SHARED_HW_CFG_LED_EXTPHY1) {
10726
10727 /* Set control reg */
10728 bnx2x_cl45_read(bp, phy,
10729 MDIO_PMA_DEVAD,
10730 MDIO_PMA_REG_8481_LINK_SIGNAL,
10731 &val);
10732
10733 if (!((val &
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010734 MDIO_PMA_REG_8481_LINK_SIGNAL_LED4_ENABLE_MASK)
10735 >> MDIO_PMA_REG_8481_LINK_SIGNAL_LED4_ENABLE_SHIFT)) {
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +000010736 DP(NETIF_MSG_LINK, "Setting LINK_SIGNAL\n");
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010737 bnx2x_cl45_write(bp, phy,
10738 MDIO_PMA_DEVAD,
10739 MDIO_PMA_REG_8481_LINK_SIGNAL,
10740 0xa492);
10741 }
10742
10743 /* Set LED masks */
10744 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010745 MDIO_PMA_DEVAD,
10746 MDIO_PMA_REG_8481_LED1_MASK,
10747 0x10);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010748
10749 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010750 MDIO_PMA_DEVAD,
10751 MDIO_PMA_REG_8481_LED2_MASK,
10752 0x80);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010753
10754 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010755 MDIO_PMA_DEVAD,
10756 MDIO_PMA_REG_8481_LED3_MASK,
10757 0x98);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010758
10759 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010760 MDIO_PMA_DEVAD,
10761 MDIO_PMA_REG_8481_LED5_MASK,
10762 0x40);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010763
10764 } else {
10765 bnx2x_cl45_write(bp, phy,
10766 MDIO_PMA_DEVAD,
10767 MDIO_PMA_REG_8481_LED1_MASK,
10768 0x80);
Yaniv Rosner53eda062011-01-30 04:14:55 +000010769
10770 /* Tell LED3 to blink on source */
10771 bnx2x_cl45_read(bp, phy,
10772 MDIO_PMA_DEVAD,
10773 MDIO_PMA_REG_8481_LINK_SIGNAL,
10774 &val);
10775 val &= ~(7<<6);
10776 val |= (1<<6); /* A83B[8:6]= 1 */
10777 bnx2x_cl45_write(bp, phy,
10778 MDIO_PMA_DEVAD,
10779 MDIO_PMA_REG_8481_LINK_SIGNAL,
10780 val);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010781 }
10782 break;
10783 }
Yaniv Rosner0d40f0d2011-06-14 01:34:27 +000010784
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000010785 /* This is a workaround for E3+84833 until autoneg
Yaniv Rosner0d40f0d2011-06-14 01:34:27 +000010786 * restart is fixed in f/w
10787 */
10788 if (CHIP_IS_E3(bp)) {
10789 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
10790 MDIO_WC_REG_GP2_STATUS_GP_2_1, &val);
10791 }
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010792}
Yaniv Rosner0d40f0d2011-06-14 01:34:27 +000010793
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010794/******************************************************************/
Yaniv Rosner52c4d6c2011-07-05 01:06:34 +000010795/* 54618SE PHY SECTION */
Yaniv Rosner6583e332011-06-14 01:34:17 +000010796/******************************************************************/
Yaniv Rosner5c107fd2012-09-13 02:56:19 +000010797static void bnx2x_54618se_specific_func(struct bnx2x_phy *phy,
10798 struct link_params *params,
10799 u32 action)
10800{
10801 struct bnx2x *bp = params->bp;
10802 u16 temp;
10803 switch (action) {
10804 case PHY_INIT:
10805 /* Configure LED4: set to INTR (0x6). */
10806 /* Accessing shadow register 0xe. */
10807 bnx2x_cl22_write(bp, phy,
10808 MDIO_REG_GPHY_SHADOW,
10809 MDIO_REG_GPHY_SHADOW_LED_SEL2);
10810 bnx2x_cl22_read(bp, phy,
10811 MDIO_REG_GPHY_SHADOW,
10812 &temp);
10813 temp &= ~(0xf << 4);
10814 temp |= (0x6 << 4);
10815 bnx2x_cl22_write(bp, phy,
10816 MDIO_REG_GPHY_SHADOW,
10817 MDIO_REG_GPHY_SHADOW_WR_ENA | temp);
10818 /* Configure INTR based on link status change. */
10819 bnx2x_cl22_write(bp, phy,
10820 MDIO_REG_INTR_MASK,
10821 ~MDIO_REG_INTR_MASK_LINK_STATUS);
10822 break;
10823 }
10824}
10825
Yaniv Rosner52c4d6c2011-07-05 01:06:34 +000010826static int bnx2x_54618se_config_init(struct bnx2x_phy *phy,
Yaniv Rosner6583e332011-06-14 01:34:17 +000010827 struct link_params *params,
10828 struct link_vars *vars)
10829{
10830 struct bnx2x *bp = params->bp;
10831 u8 port;
10832 u16 autoneg_val, an_1000_val, an_10_100_val, fc_val, temp;
10833 u32 cfg_pin;
10834
Yaniv Rosner52c4d6c2011-07-05 01:06:34 +000010835 DP(NETIF_MSG_LINK, "54618SE cfg init\n");
Yuval Mintzd2310232012-06-20 19:05:19 +000010836 usleep_range(1000, 2000);
Yaniv Rosner6583e332011-06-14 01:34:17 +000010837
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000010838 /* This works with E3 only, no need to check the chip
Yaniv Rosner2f751a82011-11-28 00:49:52 +000010839 * before determining the port.
10840 */
Yaniv Rosner6583e332011-06-14 01:34:17 +000010841 port = params->port;
10842
10843 cfg_pin = (REG_RD(bp, params->shmem_base +
10844 offsetof(struct shmem_region,
10845 dev_info.port_hw_config[port].e3_cmn_pin_cfg)) &
10846 PORT_HW_CFG_E3_PHY_RESET_MASK) >>
10847 PORT_HW_CFG_E3_PHY_RESET_SHIFT;
10848
10849 /* Drive pin high to bring the GPHY out of reset. */
10850 bnx2x_set_cfg_pin(bp, cfg_pin, 1);
10851
10852 /* wait for GPHY to reset */
10853 msleep(50);
10854
10855 /* reset phy */
10856 bnx2x_cl22_write(bp, phy,
10857 MDIO_PMA_REG_CTRL, 0x8000);
10858 bnx2x_wait_reset_complete(bp, phy, params);
10859
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000010860 /* Wait for GPHY to reset */
Yaniv Rosner6583e332011-06-14 01:34:17 +000010861 msleep(50);
10862
Yaniv Rosner6583e332011-06-14 01:34:17 +000010863
Yaniv Rosner5c107fd2012-09-13 02:56:19 +000010864 bnx2x_54618se_specific_func(phy, params, PHY_INIT);
Yaniv Rosner6583e332011-06-14 01:34:17 +000010865 /* Flip the signal detect polarity (set 0x1c.0x1e[8]). */
10866 bnx2x_cl22_write(bp, phy,
10867 MDIO_REG_GPHY_SHADOW,
10868 MDIO_REG_GPHY_SHADOW_AUTO_DET_MED);
10869 bnx2x_cl22_read(bp, phy,
10870 MDIO_REG_GPHY_SHADOW,
10871 &temp);
10872 temp |= MDIO_REG_GPHY_SHADOW_INVERT_FIB_SD;
10873 bnx2x_cl22_write(bp, phy,
10874 MDIO_REG_GPHY_SHADOW,
10875 MDIO_REG_GPHY_SHADOW_WR_ENA | temp);
10876
10877 /* Set up fc */
10878 /* Please refer to Table 28B-3 of 802.3ab-1999 spec. */
10879 bnx2x_calc_ieee_aneg_adv(phy, params, &vars->ieee_fc);
10880 fc_val = 0;
10881 if ((vars->ieee_fc & MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC) ==
10882 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC)
10883 fc_val |= MDIO_AN_REG_ADV_PAUSE_ASYMMETRIC;
10884
10885 if ((vars->ieee_fc & MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) ==
10886 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH)
10887 fc_val |= MDIO_AN_REG_ADV_PAUSE_PAUSE;
10888
Yuval Mintzd2310232012-06-20 19:05:19 +000010889 /* Read all advertisement */
Yaniv Rosner6583e332011-06-14 01:34:17 +000010890 bnx2x_cl22_read(bp, phy,
10891 0x09,
10892 &an_1000_val);
10893
10894 bnx2x_cl22_read(bp, phy,
10895 0x04,
10896 &an_10_100_val);
10897
10898 bnx2x_cl22_read(bp, phy,
10899 MDIO_PMA_REG_CTRL,
10900 &autoneg_val);
10901
10902 /* Disable forced speed */
10903 autoneg_val &= ~((1<<6) | (1<<8) | (1<<9) | (1<<12) | (1<<13));
10904 an_10_100_val &= ~((1<<5) | (1<<6) | (1<<7) | (1<<8) | (1<<10) |
10905 (1<<11));
10906
10907 if (((phy->req_line_speed == SPEED_AUTO_NEG) &&
10908 (phy->speed_cap_mask &
10909 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) ||
10910 (phy->req_line_speed == SPEED_1000)) {
10911 an_1000_val |= (1<<8);
10912 autoneg_val |= (1<<9 | 1<<12);
10913 if (phy->req_duplex == DUPLEX_FULL)
10914 an_1000_val |= (1<<9);
10915 DP(NETIF_MSG_LINK, "Advertising 1G\n");
10916 } else
10917 an_1000_val &= ~((1<<8) | (1<<9));
10918
10919 bnx2x_cl22_write(bp, phy,
10920 0x09,
10921 an_1000_val);
10922 bnx2x_cl22_read(bp, phy,
10923 0x09,
10924 &an_1000_val);
10925
Yuval Mintzd2310232012-06-20 19:05:19 +000010926 /* Set 100 speed advertisement */
Yaniv Rosner6583e332011-06-14 01:34:17 +000010927 if (((phy->req_line_speed == SPEED_AUTO_NEG) &&
10928 (phy->speed_cap_mask &
10929 (PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL |
10930 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF)))) {
10931 an_10_100_val |= (1<<7);
10932 /* Enable autoneg and restart autoneg for legacy speeds */
10933 autoneg_val |= (1<<9 | 1<<12);
10934
10935 if (phy->req_duplex == DUPLEX_FULL)
10936 an_10_100_val |= (1<<8);
10937 DP(NETIF_MSG_LINK, "Advertising 100M\n");
10938 }
10939
Yuval Mintzd2310232012-06-20 19:05:19 +000010940 /* Set 10 speed advertisement */
Yaniv Rosner6583e332011-06-14 01:34:17 +000010941 if (((phy->req_line_speed == SPEED_AUTO_NEG) &&
10942 (phy->speed_cap_mask &
10943 (PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL |
10944 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF)))) {
10945 an_10_100_val |= (1<<5);
10946 autoneg_val |= (1<<9 | 1<<12);
10947 if (phy->req_duplex == DUPLEX_FULL)
10948 an_10_100_val |= (1<<6);
10949 DP(NETIF_MSG_LINK, "Advertising 10M\n");
10950 }
10951
10952 /* Only 10/100 are allowed to work in FORCE mode */
10953 if (phy->req_line_speed == SPEED_100) {
10954 autoneg_val |= (1<<13);
10955 /* Enabled AUTO-MDIX when autoneg is disabled */
10956 bnx2x_cl22_write(bp, phy,
10957 0x18,
10958 (1<<15 | 1<<9 | 7<<0));
10959 DP(NETIF_MSG_LINK, "Setting 100M force\n");
10960 }
10961 if (phy->req_line_speed == SPEED_10) {
10962 /* Enabled AUTO-MDIX when autoneg is disabled */
10963 bnx2x_cl22_write(bp, phy,
10964 0x18,
10965 (1<<15 | 1<<9 | 7<<0));
10966 DP(NETIF_MSG_LINK, "Setting 10M force\n");
10967 }
10968
Yuval Mintz26964bb2012-09-10 05:51:08 +000010969 if ((phy->flags & FLAGS_EEE) && bnx2x_eee_has_cap(params)) {
10970 int rc;
10971
10972 bnx2x_cl22_write(bp, phy, MDIO_REG_GPHY_EXP_ACCESS,
10973 MDIO_REG_GPHY_EXP_ACCESS_TOP |
10974 MDIO_REG_GPHY_EXP_TOP_2K_BUF);
10975 bnx2x_cl22_read(bp, phy, MDIO_REG_GPHY_EXP_ACCESS_GATE, &temp);
10976 temp &= 0xfffe;
10977 bnx2x_cl22_write(bp, phy, MDIO_REG_GPHY_EXP_ACCESS_GATE, temp);
10978
10979 rc = bnx2x_eee_initial_config(params, vars, SHMEM_EEE_1G_ADV);
10980 if (rc) {
10981 DP(NETIF_MSG_LINK, "Failed to configure EEE timers\n");
10982 bnx2x_eee_disable(phy, params, vars);
10983 } else if ((params->eee_mode & EEE_MODE_ADV_LPI) &&
10984 (phy->req_duplex == DUPLEX_FULL) &&
10985 (bnx2x_eee_calc_timer(params) ||
10986 !(params->eee_mode & EEE_MODE_ENABLE_LPI))) {
10987 /* Need to advertise EEE only when requested,
10988 * and either no LPI assertion was requested,
10989 * or it was requested and a valid timer was set.
10990 * Also notice full duplex is required for EEE.
10991 */
10992 bnx2x_eee_advertise(phy, params, vars,
10993 SHMEM_EEE_1G_ADV);
Yaniv Rosnera89a1d42011-07-05 01:07:05 +000010994 } else {
Yuval Mintz26964bb2012-09-10 05:51:08 +000010995 DP(NETIF_MSG_LINK, "Don't Advertise 1GBase-T EEE\n");
10996 bnx2x_eee_disable(phy, params, vars);
Yaniv Rosnera89a1d42011-07-05 01:07:05 +000010997 }
Yuval Mintz26964bb2012-09-10 05:51:08 +000010998 } else {
10999 vars->eee_status &= ~SHMEM_EEE_1G_ADV <<
11000 SHMEM_EEE_SUPPORTED_SHIFT;
11001
11002 if (phy->flags & FLAGS_EEE) {
11003 /* Handle legacy auto-grEEEn */
11004 if (params->feature_config_flags &
11005 FEATURE_CONFIG_AUTOGREEEN_ENABLED) {
11006 temp = 6;
11007 DP(NETIF_MSG_LINK, "Enabling Auto-GrEEEn\n");
11008 } else {
11009 temp = 0;
11010 DP(NETIF_MSG_LINK, "Don't Adv. EEE\n");
11011 }
11012 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
11013 MDIO_AN_REG_EEE_ADV, temp);
11014 }
Yaniv Rosnera89a1d42011-07-05 01:07:05 +000011015 }
11016
Yaniv Rosner6583e332011-06-14 01:34:17 +000011017 bnx2x_cl22_write(bp, phy,
11018 0x04,
11019 an_10_100_val | fc_val);
11020
11021 if (phy->req_duplex == DUPLEX_FULL)
11022 autoneg_val |= (1<<8);
11023
11024 bnx2x_cl22_write(bp, phy,
11025 MDIO_PMA_REG_CTRL, autoneg_val);
11026
11027 return 0;
11028}
11029
Yaniv Rosner1d125bd2011-11-23 03:54:08 +000011030
11031static void bnx2x_5461x_set_link_led(struct bnx2x_phy *phy,
11032 struct link_params *params, u8 mode)
11033{
11034 struct bnx2x *bp = params->bp;
11035 u16 temp;
11036
11037 bnx2x_cl22_write(bp, phy,
11038 MDIO_REG_GPHY_SHADOW,
11039 MDIO_REG_GPHY_SHADOW_LED_SEL1);
11040 bnx2x_cl22_read(bp, phy,
11041 MDIO_REG_GPHY_SHADOW,
11042 &temp);
11043 temp &= 0xff00;
11044
11045 DP(NETIF_MSG_LINK, "54618x set link led (mode=%x)\n", mode);
11046 switch (mode) {
11047 case LED_MODE_FRONT_PANEL_OFF:
11048 case LED_MODE_OFF:
11049 temp |= 0x00ee;
11050 break;
11051 case LED_MODE_OPER:
11052 temp |= 0x0001;
11053 break;
11054 case LED_MODE_ON:
11055 temp |= 0x00ff;
11056 break;
11057 default:
11058 break;
11059 }
11060 bnx2x_cl22_write(bp, phy,
11061 MDIO_REG_GPHY_SHADOW,
11062 MDIO_REG_GPHY_SHADOW_WR_ENA | temp);
11063 return;
11064}
11065
11066
Yaniv Rosner52c4d6c2011-07-05 01:06:34 +000011067static void bnx2x_54618se_link_reset(struct bnx2x_phy *phy,
11068 struct link_params *params)
Yaniv Rosner6583e332011-06-14 01:34:17 +000011069{
11070 struct bnx2x *bp = params->bp;
11071 u32 cfg_pin;
11072 u8 port;
11073
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000011074 /* In case of no EPIO routed to reset the GPHY, put it
Yaniv Rosnerd2059a02011-08-02 23:00:00 +000011075 * in low power mode.
11076 */
11077 bnx2x_cl22_write(bp, phy, MDIO_PMA_REG_CTRL, 0x800);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000011078 /* This works with E3 only, no need to check the chip
Yaniv Rosnerd2059a02011-08-02 23:00:00 +000011079 * before determining the port.
11080 */
Yaniv Rosner6583e332011-06-14 01:34:17 +000011081 port = params->port;
11082 cfg_pin = (REG_RD(bp, params->shmem_base +
11083 offsetof(struct shmem_region,
11084 dev_info.port_hw_config[port].e3_cmn_pin_cfg)) &
11085 PORT_HW_CFG_E3_PHY_RESET_MASK) >>
11086 PORT_HW_CFG_E3_PHY_RESET_SHIFT;
11087
11088 /* Drive pin low to put GPHY in reset. */
11089 bnx2x_set_cfg_pin(bp, cfg_pin, 0);
11090}
11091
Yaniv Rosner52c4d6c2011-07-05 01:06:34 +000011092static u8 bnx2x_54618se_read_status(struct bnx2x_phy *phy,
11093 struct link_params *params,
11094 struct link_vars *vars)
Yaniv Rosner6583e332011-06-14 01:34:17 +000011095{
11096 struct bnx2x *bp = params->bp;
11097 u16 val;
11098 u8 link_up = 0;
11099 u16 legacy_status, legacy_speed;
11100
11101 /* Get speed operation status */
11102 bnx2x_cl22_read(bp, phy,
Yuval Mintza351d492012-06-20 19:05:21 +000011103 MDIO_REG_GPHY_AUX_STATUS,
Yaniv Rosner6583e332011-06-14 01:34:17 +000011104 &legacy_status);
Yaniv Rosner52c4d6c2011-07-05 01:06:34 +000011105 DP(NETIF_MSG_LINK, "54618SE read_status: 0x%x\n", legacy_status);
Yaniv Rosner6583e332011-06-14 01:34:17 +000011106
11107 /* Read status to clear the PHY interrupt. */
11108 bnx2x_cl22_read(bp, phy,
11109 MDIO_REG_INTR_STATUS,
11110 &val);
11111
11112 link_up = ((legacy_status & (1<<2)) == (1<<2));
11113
11114 if (link_up) {
11115 legacy_speed = (legacy_status & (7<<8));
11116 if (legacy_speed == (7<<8)) {
11117 vars->line_speed = SPEED_1000;
11118 vars->duplex = DUPLEX_FULL;
11119 } else if (legacy_speed == (6<<8)) {
11120 vars->line_speed = SPEED_1000;
11121 vars->duplex = DUPLEX_HALF;
11122 } else if (legacy_speed == (5<<8)) {
11123 vars->line_speed = SPEED_100;
11124 vars->duplex = DUPLEX_FULL;
11125 }
11126 /* Omitting 100Base-T4 for now */
11127 else if (legacy_speed == (3<<8)) {
11128 vars->line_speed = SPEED_100;
11129 vars->duplex = DUPLEX_HALF;
11130 } else if (legacy_speed == (2<<8)) {
11131 vars->line_speed = SPEED_10;
11132 vars->duplex = DUPLEX_FULL;
11133 } else if (legacy_speed == (1<<8)) {
11134 vars->line_speed = SPEED_10;
11135 vars->duplex = DUPLEX_HALF;
11136 } else /* Should not happen */
11137 vars->line_speed = 0;
11138
Joe Perches94f05b02011-08-14 12:16:20 +000011139 DP(NETIF_MSG_LINK,
11140 "Link is up in %dMbps, is_duplex_full= %d\n",
11141 vars->line_speed,
11142 (vars->duplex == DUPLEX_FULL));
Yaniv Rosner6583e332011-06-14 01:34:17 +000011143
11144 /* Check legacy speed AN resolution */
11145 bnx2x_cl22_read(bp, phy,
11146 0x01,
11147 &val);
11148 if (val & (1<<5))
11149 vars->link_status |=
11150 LINK_STATUS_AUTO_NEGOTIATE_COMPLETE;
11151 bnx2x_cl22_read(bp, phy,
11152 0x06,
11153 &val);
11154 if ((val & (1<<0)) == 0)
11155 vars->link_status |=
11156 LINK_STATUS_PARALLEL_DETECTION_USED;
11157
Yaniv Rosner52c4d6c2011-07-05 01:06:34 +000011158 DP(NETIF_MSG_LINK, "BCM54618SE: link speed is %d\n",
Yaniv Rosner6583e332011-06-14 01:34:17 +000011159 vars->line_speed);
Yaniv Rosner52c4d6c2011-07-05 01:06:34 +000011160
Yaniv Rosner6583e332011-06-14 01:34:17 +000011161 bnx2x_ext_phy_resolve_fc(phy, params, vars);
Mintz Yuval9e7e8392012-02-15 02:10:24 +000011162
11163 if (vars->link_status & LINK_STATUS_AUTO_NEGOTIATE_COMPLETE) {
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000011164 /* Report LP advertised speeds */
Mintz Yuval9e7e8392012-02-15 02:10:24 +000011165 bnx2x_cl22_read(bp, phy, 0x5, &val);
11166
11167 if (val & (1<<5))
11168 vars->link_status |=
11169 LINK_STATUS_LINK_PARTNER_10THD_CAPABLE;
11170 if (val & (1<<6))
11171 vars->link_status |=
11172 LINK_STATUS_LINK_PARTNER_10TFD_CAPABLE;
11173 if (val & (1<<7))
11174 vars->link_status |=
11175 LINK_STATUS_LINK_PARTNER_100TXHD_CAPABLE;
11176 if (val & (1<<8))
11177 vars->link_status |=
11178 LINK_STATUS_LINK_PARTNER_100TXFD_CAPABLE;
11179 if (val & (1<<9))
11180 vars->link_status |=
11181 LINK_STATUS_LINK_PARTNER_100T4_CAPABLE;
11182
11183 bnx2x_cl22_read(bp, phy, 0xa, &val);
11184 if (val & (1<<10))
11185 vars->link_status |=
11186 LINK_STATUS_LINK_PARTNER_1000THD_CAPABLE;
11187 if (val & (1<<11))
11188 vars->link_status |=
11189 LINK_STATUS_LINK_PARTNER_1000TFD_CAPABLE;
Yuval Mintz26964bb2012-09-10 05:51:08 +000011190
11191 if ((phy->flags & FLAGS_EEE) &&
11192 bnx2x_eee_has_cap(params))
11193 bnx2x_eee_an_resolve(phy, params, vars);
Mintz Yuval9e7e8392012-02-15 02:10:24 +000011194 }
Yaniv Rosner6583e332011-06-14 01:34:17 +000011195 }
11196 return link_up;
11197}
11198
Yaniv Rosner52c4d6c2011-07-05 01:06:34 +000011199static void bnx2x_54618se_config_loopback(struct bnx2x_phy *phy,
11200 struct link_params *params)
Yaniv Rosner6583e332011-06-14 01:34:17 +000011201{
11202 struct bnx2x *bp = params->bp;
11203 u16 val;
11204 u32 umac_base = params->port ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
11205
Yaniv Rosner52c4d6c2011-07-05 01:06:34 +000011206 DP(NETIF_MSG_LINK, "2PMA/PMD ext_phy_loopback: 54618se\n");
Yaniv Rosner6583e332011-06-14 01:34:17 +000011207
11208 /* Enable master/slave manual mmode and set to master */
11209 /* mii write 9 [bits set 11 12] */
11210 bnx2x_cl22_write(bp, phy, 0x09, 3<<11);
11211
11212 /* forced 1G and disable autoneg */
11213 /* set val [mii read 0] */
11214 /* set val [expr $val & [bits clear 6 12 13]] */
11215 /* set val [expr $val | [bits set 6 8]] */
11216 /* mii write 0 $val */
11217 bnx2x_cl22_read(bp, phy, 0x00, &val);
11218 val &= ~((1<<6) | (1<<12) | (1<<13));
11219 val |= (1<<6) | (1<<8);
11220 bnx2x_cl22_write(bp, phy, 0x00, val);
11221
11222 /* Set external loopback and Tx using 6dB coding */
11223 /* mii write 0x18 7 */
11224 /* set val [mii read 0x18] */
11225 /* mii write 0x18 [expr $val | [bits set 10 15]] */
11226 bnx2x_cl22_write(bp, phy, 0x18, 7);
11227 bnx2x_cl22_read(bp, phy, 0x18, &val);
11228 bnx2x_cl22_write(bp, phy, 0x18, val | (1<<10) | (1<<15));
11229
11230 /* This register opens the gate for the UMAC despite its name */
11231 REG_WR(bp, NIG_REG_EGRESS_EMAC0_PORT + params->port*4, 1);
11232
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000011233 /* Maximum Frame Length (RW). Defines a 14-Bit maximum frame
Yaniv Rosner6583e332011-06-14 01:34:17 +000011234 * length used by the MAC receive logic to check frames.
11235 */
11236 REG_WR(bp, umac_base + UMAC_REG_MAXFR, 0x2710);
11237}
11238
11239/******************************************************************/
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011240/* SFX7101 PHY SECTION */
11241/******************************************************************/
11242static void bnx2x_7101_config_loopback(struct bnx2x_phy *phy,
11243 struct link_params *params)
11244{
11245 struct bnx2x *bp = params->bp;
11246 /* SFX7101_XGXS_TEST1 */
11247 bnx2x_cl45_write(bp, phy,
11248 MDIO_XS_DEVAD, MDIO_XS_SFX7101_XGXS_TEST1, 0x100);
11249}
11250
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000011251static int bnx2x_7101_config_init(struct bnx2x_phy *phy,
11252 struct link_params *params,
11253 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011254{
11255 u16 fw_ver1, fw_ver2, val;
11256 struct bnx2x *bp = params->bp;
11257 DP(NETIF_MSG_LINK, "Setting the SFX7101 LASI indication\n");
11258
11259 /* Restore normal power mode*/
11260 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000011261 MISC_REGISTERS_GPIO_OUTPUT_HIGH, params->port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011262 /* HW reset */
11263 bnx2x_ext_phy_hw_reset(bp, params->port);
Yaniv Rosner6d870c32011-01-31 04:22:20 +000011264 bnx2x_wait_reset_complete(bp, phy, params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011265
11266 bnx2x_cl45_write(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +000011267 MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL, 0x1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011268 DP(NETIF_MSG_LINK, "Setting the SFX7101 LED to blink on traffic\n");
11269 bnx2x_cl45_write(bp, phy,
11270 MDIO_PMA_DEVAD, MDIO_PMA_REG_7107_LED_CNTL, (1<<3));
11271
11272 bnx2x_ext_phy_set_pause(params, phy, vars);
11273 /* Restart autoneg */
11274 bnx2x_cl45_read(bp, phy,
11275 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, &val);
11276 val |= 0x200;
11277 bnx2x_cl45_write(bp, phy,
11278 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, val);
11279
11280 /* Save spirom version */
11281 bnx2x_cl45_read(bp, phy,
11282 MDIO_PMA_DEVAD, MDIO_PMA_REG_7101_VER1, &fw_ver1);
11283
11284 bnx2x_cl45_read(bp, phy,
11285 MDIO_PMA_DEVAD, MDIO_PMA_REG_7101_VER2, &fw_ver2);
11286 bnx2x_save_spirom_version(bp, params->port,
11287 (u32)(fw_ver1<<16 | fw_ver2), phy->ver_addr);
11288 return 0;
11289}
11290
11291static u8 bnx2x_7101_read_status(struct bnx2x_phy *phy,
11292 struct link_params *params,
11293 struct link_vars *vars)
11294{
11295 struct bnx2x *bp = params->bp;
11296 u8 link_up;
11297 u16 val1, val2;
11298 bnx2x_cl45_read(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +000011299 MDIO_PMA_DEVAD, MDIO_PMA_LASI_STAT, &val2);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011300 bnx2x_cl45_read(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +000011301 MDIO_PMA_DEVAD, MDIO_PMA_LASI_STAT, &val1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011302 DP(NETIF_MSG_LINK, "10G-base-T LASI status 0x%x->0x%x\n",
11303 val2, val1);
11304 bnx2x_cl45_read(bp, phy,
11305 MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val2);
11306 bnx2x_cl45_read(bp, phy,
11307 MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val1);
11308 DP(NETIF_MSG_LINK, "10G-base-T PMA status 0x%x->0x%x\n",
11309 val2, val1);
11310 link_up = ((val1 & 4) == 4);
Yuval Mintzd2310232012-06-20 19:05:19 +000011311 /* If link is up print the AN outcome of the SFX7101 PHY */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011312 if (link_up) {
11313 bnx2x_cl45_read(bp, phy,
11314 MDIO_AN_DEVAD, MDIO_AN_REG_MASTER_STATUS,
11315 &val2);
11316 vars->line_speed = SPEED_10000;
Yaniv Rosner791f18c2011-01-18 04:33:42 +000011317 vars->duplex = DUPLEX_FULL;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011318 DP(NETIF_MSG_LINK, "SFX7101 AN status 0x%x->Master=%x\n",
11319 val2, (val2 & (1<<14)));
11320 bnx2x_ext_phy_10G_an_resolve(bp, phy, vars);
11321 bnx2x_ext_phy_resolve_fc(phy, params, vars);
Mintz Yuval9e7e8392012-02-15 02:10:24 +000011322
Yuval Mintzd2310232012-06-20 19:05:19 +000011323 /* Read LP advertised speeds */
Mintz Yuval9e7e8392012-02-15 02:10:24 +000011324 if (val2 & (1<<11))
11325 vars->link_status |=
11326 LINK_STATUS_LINK_PARTNER_10GXFD_CAPABLE;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011327 }
11328 return link_up;
11329}
11330
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000011331static int bnx2x_7101_format_ver(u32 spirom_ver, u8 *str, u16 *len)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011332{
11333 if (*len < 5)
11334 return -EINVAL;
11335 str[0] = (spirom_ver & 0xFF);
11336 str[1] = (spirom_ver & 0xFF00) >> 8;
11337 str[2] = (spirom_ver & 0xFF0000) >> 16;
11338 str[3] = (spirom_ver & 0xFF000000) >> 24;
11339 str[4] = '\0';
11340 *len -= 5;
11341 return 0;
11342}
11343
11344void bnx2x_sfx7101_sp_sw_reset(struct bnx2x *bp, struct bnx2x_phy *phy)
11345{
11346 u16 val, cnt;
11347
11348 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000011349 MDIO_PMA_DEVAD,
11350 MDIO_PMA_REG_7101_RESET, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011351
11352 for (cnt = 0; cnt < 10; cnt++) {
11353 msleep(50);
11354 /* Writes a self-clearing reset */
11355 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000011356 MDIO_PMA_DEVAD,
11357 MDIO_PMA_REG_7101_RESET,
11358 (val | (1<<15)));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011359 /* Wait for clear */
11360 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000011361 MDIO_PMA_DEVAD,
11362 MDIO_PMA_REG_7101_RESET, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011363
11364 if ((val & (1<<15)) == 0)
11365 break;
11366 }
11367}
11368
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011369static void bnx2x_7101_hw_reset(struct bnx2x_phy *phy,
11370 struct link_params *params) {
11371 /* Low power mode is controlled by GPIO 2 */
11372 bnx2x_set_gpio(params->bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000011373 MISC_REGISTERS_GPIO_OUTPUT_LOW, params->port);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011374 /* The PHY reset is controlled by GPIO 1 */
11375 bnx2x_set_gpio(params->bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000011376 MISC_REGISTERS_GPIO_OUTPUT_LOW, params->port);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011377}
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011378
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000011379static void bnx2x_7101_set_link_led(struct bnx2x_phy *phy,
11380 struct link_params *params, u8 mode)
11381{
11382 u16 val = 0;
11383 struct bnx2x *bp = params->bp;
11384 switch (mode) {
11385 case LED_MODE_FRONT_PANEL_OFF:
11386 case LED_MODE_OFF:
11387 val = 2;
11388 break;
11389 case LED_MODE_ON:
11390 val = 1;
11391 break;
11392 case LED_MODE_OPER:
11393 val = 0;
11394 break;
11395 }
11396 bnx2x_cl45_write(bp, phy,
11397 MDIO_PMA_DEVAD,
11398 MDIO_PMA_REG_7107_LINK_LED_CNTL,
11399 val);
11400}
11401
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011402/******************************************************************/
11403/* STATIC PHY DECLARATION */
11404/******************************************************************/
11405
11406static struct bnx2x_phy phy_null = {
11407 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN,
11408 .addr = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011409 .def_md_devad = 0,
Yaniv Rosner9045f6b42011-05-31 21:28:27 +000011410 .flags = FLAGS_INIT_XGXS_FIRST,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011411 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11412 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11413 .mdio_ctrl = 0,
11414 .supported = 0,
11415 .media_type = ETH_PHY_NOT_PRESENT,
11416 .ver_addr = 0,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000011417 .req_flow_ctrl = 0,
11418 .req_line_speed = 0,
11419 .speed_cap_mask = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011420 .req_duplex = 0,
11421 .rsrv = 0,
11422 .config_init = (config_init_t)NULL,
11423 .read_status = (read_status_t)NULL,
11424 .link_reset = (link_reset_t)NULL,
11425 .config_loopback = (config_loopback_t)NULL,
11426 .format_fw_ver = (format_fw_ver_t)NULL,
11427 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011428 .set_link_led = (set_link_led_t)NULL,
11429 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011430};
11431
11432static struct bnx2x_phy phy_serdes = {
11433 .type = PORT_HW_CFG_SERDES_EXT_PHY_TYPE_DIRECT,
11434 .addr = 0xff,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011435 .def_md_devad = 0,
Yaniv Rosner9045f6b42011-05-31 21:28:27 +000011436 .flags = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011437 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11438 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11439 .mdio_ctrl = 0,
11440 .supported = (SUPPORTED_10baseT_Half |
11441 SUPPORTED_10baseT_Full |
11442 SUPPORTED_100baseT_Half |
11443 SUPPORTED_100baseT_Full |
11444 SUPPORTED_1000baseT_Full |
11445 SUPPORTED_2500baseX_Full |
11446 SUPPORTED_TP |
11447 SUPPORTED_Autoneg |
11448 SUPPORTED_Pause |
11449 SUPPORTED_Asym_Pause),
Yaniv Rosner1ac9e422011-05-31 21:26:11 +000011450 .media_type = ETH_PHY_BASE_T,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011451 .ver_addr = 0,
11452 .req_flow_ctrl = 0,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000011453 .req_line_speed = 0,
11454 .speed_cap_mask = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011455 .req_duplex = 0,
11456 .rsrv = 0,
Yaniv Rosnerec146a62011-05-31 21:29:27 +000011457 .config_init = (config_init_t)bnx2x_xgxs_config_init,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011458 .read_status = (read_status_t)bnx2x_link_settings_status,
11459 .link_reset = (link_reset_t)bnx2x_int_link_reset,
11460 .config_loopback = (config_loopback_t)NULL,
11461 .format_fw_ver = (format_fw_ver_t)NULL,
11462 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011463 .set_link_led = (set_link_led_t)NULL,
11464 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011465};
11466
11467static struct bnx2x_phy phy_xgxs = {
11468 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT,
11469 .addr = 0xff,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011470 .def_md_devad = 0,
Yaniv Rosner9045f6b42011-05-31 21:28:27 +000011471 .flags = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011472 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11473 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11474 .mdio_ctrl = 0,
11475 .supported = (SUPPORTED_10baseT_Half |
11476 SUPPORTED_10baseT_Full |
11477 SUPPORTED_100baseT_Half |
11478 SUPPORTED_100baseT_Full |
11479 SUPPORTED_1000baseT_Full |
11480 SUPPORTED_2500baseX_Full |
11481 SUPPORTED_10000baseT_Full |
11482 SUPPORTED_FIBRE |
11483 SUPPORTED_Autoneg |
11484 SUPPORTED_Pause |
11485 SUPPORTED_Asym_Pause),
Yaniv Rosner1ac9e422011-05-31 21:26:11 +000011486 .media_type = ETH_PHY_CX4,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011487 .ver_addr = 0,
11488 .req_flow_ctrl = 0,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000011489 .req_line_speed = 0,
11490 .speed_cap_mask = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011491 .req_duplex = 0,
11492 .rsrv = 0,
Yaniv Rosnerec146a62011-05-31 21:29:27 +000011493 .config_init = (config_init_t)bnx2x_xgxs_config_init,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011494 .read_status = (read_status_t)bnx2x_link_settings_status,
11495 .link_reset = (link_reset_t)bnx2x_int_link_reset,
11496 .config_loopback = (config_loopback_t)bnx2x_set_xgxs_loopback,
11497 .format_fw_ver = (format_fw_ver_t)NULL,
11498 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011499 .set_link_led = (set_link_led_t)NULL,
11500 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011501};
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000011502static struct bnx2x_phy phy_warpcore = {
11503 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT,
11504 .addr = 0xff,
11505 .def_md_devad = 0,
Yaniv Rosner55098c52012-04-03 18:41:27 +000011506 .flags = (FLAGS_HW_LOCK_REQUIRED |
11507 FLAGS_TX_ERROR_CHECK),
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000011508 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11509 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11510 .mdio_ctrl = 0,
11511 .supported = (SUPPORTED_10baseT_Half |
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000011512 SUPPORTED_10baseT_Full |
11513 SUPPORTED_100baseT_Half |
11514 SUPPORTED_100baseT_Full |
11515 SUPPORTED_1000baseT_Full |
11516 SUPPORTED_10000baseT_Full |
11517 SUPPORTED_20000baseKR2_Full |
11518 SUPPORTED_20000baseMLD2_Full |
11519 SUPPORTED_FIBRE |
11520 SUPPORTED_Autoneg |
11521 SUPPORTED_Pause |
11522 SUPPORTED_Asym_Pause),
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000011523 .media_type = ETH_PHY_UNSPECIFIED,
11524 .ver_addr = 0,
11525 .req_flow_ctrl = 0,
11526 .req_line_speed = 0,
11527 .speed_cap_mask = 0,
11528 /* req_duplex = */0,
11529 /* rsrv = */0,
11530 .config_init = (config_init_t)bnx2x_warpcore_config_init,
11531 .read_status = (read_status_t)bnx2x_warpcore_read_status,
11532 .link_reset = (link_reset_t)bnx2x_warpcore_link_reset,
11533 .config_loopback = (config_loopback_t)bnx2x_set_warpcore_loopback,
11534 .format_fw_ver = (format_fw_ver_t)NULL,
Yaniv Rosner985848f2011-07-05 01:06:48 +000011535 .hw_reset = (hw_reset_t)bnx2x_warpcore_hw_reset,
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000011536 .set_link_led = (set_link_led_t)NULL,
11537 .phy_specific_func = (phy_specific_func_t)NULL
11538};
11539
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011540
11541static struct bnx2x_phy phy_7101 = {
11542 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101,
11543 .addr = 0xff,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011544 .def_md_devad = 0,
Yaniv Rosner9045f6b42011-05-31 21:28:27 +000011545 .flags = FLAGS_FAN_FAILURE_DET_REQ,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011546 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11547 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11548 .mdio_ctrl = 0,
11549 .supported = (SUPPORTED_10000baseT_Full |
11550 SUPPORTED_TP |
11551 SUPPORTED_Autoneg |
11552 SUPPORTED_Pause |
11553 SUPPORTED_Asym_Pause),
11554 .media_type = ETH_PHY_BASE_T,
11555 .ver_addr = 0,
11556 .req_flow_ctrl = 0,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000011557 .req_line_speed = 0,
11558 .speed_cap_mask = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011559 .req_duplex = 0,
11560 .rsrv = 0,
11561 .config_init = (config_init_t)bnx2x_7101_config_init,
11562 .read_status = (read_status_t)bnx2x_7101_read_status,
11563 .link_reset = (link_reset_t)bnx2x_common_ext_link_reset,
11564 .config_loopback = (config_loopback_t)bnx2x_7101_config_loopback,
11565 .format_fw_ver = (format_fw_ver_t)bnx2x_7101_format_ver,
11566 .hw_reset = (hw_reset_t)bnx2x_7101_hw_reset,
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000011567 .set_link_led = (set_link_led_t)bnx2x_7101_set_link_led,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011568 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011569};
11570static struct bnx2x_phy phy_8073 = {
11571 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073,
11572 .addr = 0xff,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011573 .def_md_devad = 0,
Yaniv Rosner9045f6b42011-05-31 21:28:27 +000011574 .flags = FLAGS_HW_LOCK_REQUIRED,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011575 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11576 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11577 .mdio_ctrl = 0,
11578 .supported = (SUPPORTED_10000baseT_Full |
11579 SUPPORTED_2500baseX_Full |
11580 SUPPORTED_1000baseT_Full |
11581 SUPPORTED_FIBRE |
11582 SUPPORTED_Autoneg |
11583 SUPPORTED_Pause |
11584 SUPPORTED_Asym_Pause),
Yaniv Rosner1ac9e422011-05-31 21:26:11 +000011585 .media_type = ETH_PHY_KR,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011586 .ver_addr = 0,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000011587 .req_flow_ctrl = 0,
11588 .req_line_speed = 0,
11589 .speed_cap_mask = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011590 .req_duplex = 0,
11591 .rsrv = 0,
Yaniv Rosner62b29a52010-09-07 11:40:58 +000011592 .config_init = (config_init_t)bnx2x_8073_config_init,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011593 .read_status = (read_status_t)bnx2x_8073_read_status,
11594 .link_reset = (link_reset_t)bnx2x_8073_link_reset,
11595 .config_loopback = (config_loopback_t)NULL,
11596 .format_fw_ver = (format_fw_ver_t)bnx2x_format_ver,
11597 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011598 .set_link_led = (set_link_led_t)NULL,
Yaniv Rosner5c107fd2012-09-13 02:56:19 +000011599 .phy_specific_func = (phy_specific_func_t)bnx2x_8073_specific_func
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011600};
11601static struct bnx2x_phy phy_8705 = {
11602 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705,
11603 .addr = 0xff,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011604 .def_md_devad = 0,
Yaniv Rosner9045f6b42011-05-31 21:28:27 +000011605 .flags = FLAGS_INIT_XGXS_FIRST,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011606 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11607 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11608 .mdio_ctrl = 0,
11609 .supported = (SUPPORTED_10000baseT_Full |
11610 SUPPORTED_FIBRE |
11611 SUPPORTED_Pause |
11612 SUPPORTED_Asym_Pause),
11613 .media_type = ETH_PHY_XFP_FIBER,
11614 .ver_addr = 0,
11615 .req_flow_ctrl = 0,
11616 .req_line_speed = 0,
11617 .speed_cap_mask = 0,
11618 .req_duplex = 0,
11619 .rsrv = 0,
11620 .config_init = (config_init_t)bnx2x_8705_config_init,
11621 .read_status = (read_status_t)bnx2x_8705_read_status,
11622 .link_reset = (link_reset_t)bnx2x_common_ext_link_reset,
11623 .config_loopback = (config_loopback_t)NULL,
11624 .format_fw_ver = (format_fw_ver_t)bnx2x_null_format_ver,
11625 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011626 .set_link_led = (set_link_led_t)NULL,
11627 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011628};
11629static struct bnx2x_phy phy_8706 = {
11630 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706,
11631 .addr = 0xff,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011632 .def_md_devad = 0,
David S. Miller8decf862011-09-22 03:23:13 -040011633 .flags = FLAGS_INIT_XGXS_FIRST,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011634 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11635 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11636 .mdio_ctrl = 0,
11637 .supported = (SUPPORTED_10000baseT_Full |
11638 SUPPORTED_1000baseT_Full |
11639 SUPPORTED_FIBRE |
11640 SUPPORTED_Pause |
11641 SUPPORTED_Asym_Pause),
Yuval Mintzdbef8072012-06-20 19:05:22 +000011642 .media_type = ETH_PHY_SFPP_10G_FIBER,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011643 .ver_addr = 0,
11644 .req_flow_ctrl = 0,
11645 .req_line_speed = 0,
11646 .speed_cap_mask = 0,
11647 .req_duplex = 0,
11648 .rsrv = 0,
11649 .config_init = (config_init_t)bnx2x_8706_config_init,
11650 .read_status = (read_status_t)bnx2x_8706_read_status,
11651 .link_reset = (link_reset_t)bnx2x_common_ext_link_reset,
11652 .config_loopback = (config_loopback_t)NULL,
11653 .format_fw_ver = (format_fw_ver_t)bnx2x_format_ver,
11654 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011655 .set_link_led = (set_link_led_t)NULL,
11656 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011657};
11658
11659static struct bnx2x_phy phy_8726 = {
11660 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726,
11661 .addr = 0xff,
Yaniv Rosner9045f6b42011-05-31 21:28:27 +000011662 .def_md_devad = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011663 .flags = (FLAGS_HW_LOCK_REQUIRED |
Yaniv Rosner55098c52012-04-03 18:41:27 +000011664 FLAGS_INIT_XGXS_FIRST |
11665 FLAGS_TX_ERROR_CHECK),
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011666 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11667 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11668 .mdio_ctrl = 0,
11669 .supported = (SUPPORTED_10000baseT_Full |
11670 SUPPORTED_1000baseT_Full |
11671 SUPPORTED_Autoneg |
11672 SUPPORTED_FIBRE |
11673 SUPPORTED_Pause |
11674 SUPPORTED_Asym_Pause),
Yaniv Rosner1ac9e422011-05-31 21:26:11 +000011675 .media_type = ETH_PHY_NOT_PRESENT,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011676 .ver_addr = 0,
11677 .req_flow_ctrl = 0,
11678 .req_line_speed = 0,
11679 .speed_cap_mask = 0,
11680 .req_duplex = 0,
11681 .rsrv = 0,
11682 .config_init = (config_init_t)bnx2x_8726_config_init,
11683 .read_status = (read_status_t)bnx2x_8726_read_status,
11684 .link_reset = (link_reset_t)bnx2x_8726_link_reset,
11685 .config_loopback = (config_loopback_t)bnx2x_8726_config_loopback,
11686 .format_fw_ver = (format_fw_ver_t)bnx2x_format_ver,
11687 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011688 .set_link_led = (set_link_led_t)NULL,
11689 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011690};
11691
11692static struct bnx2x_phy phy_8727 = {
11693 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727,
11694 .addr = 0xff,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011695 .def_md_devad = 0,
Yaniv Rosner55098c52012-04-03 18:41:27 +000011696 .flags = (FLAGS_FAN_FAILURE_DET_REQ |
11697 FLAGS_TX_ERROR_CHECK),
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011698 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11699 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11700 .mdio_ctrl = 0,
11701 .supported = (SUPPORTED_10000baseT_Full |
11702 SUPPORTED_1000baseT_Full |
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011703 SUPPORTED_FIBRE |
11704 SUPPORTED_Pause |
11705 SUPPORTED_Asym_Pause),
Yaniv Rosner1ac9e422011-05-31 21:26:11 +000011706 .media_type = ETH_PHY_NOT_PRESENT,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011707 .ver_addr = 0,
11708 .req_flow_ctrl = 0,
11709 .req_line_speed = 0,
11710 .speed_cap_mask = 0,
11711 .req_duplex = 0,
11712 .rsrv = 0,
11713 .config_init = (config_init_t)bnx2x_8727_config_init,
11714 .read_status = (read_status_t)bnx2x_8727_read_status,
11715 .link_reset = (link_reset_t)bnx2x_8727_link_reset,
11716 .config_loopback = (config_loopback_t)NULL,
11717 .format_fw_ver = (format_fw_ver_t)bnx2x_format_ver,
11718 .hw_reset = (hw_reset_t)bnx2x_8727_hw_reset,
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000011719 .set_link_led = (set_link_led_t)bnx2x_8727_set_link_led,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011720 .phy_specific_func = (phy_specific_func_t)bnx2x_8727_specific_func
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011721};
11722static struct bnx2x_phy phy_8481 = {
11723 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8481,
11724 .addr = 0xff,
Yaniv Rosner9045f6b42011-05-31 21:28:27 +000011725 .def_md_devad = 0,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011726 .flags = FLAGS_FAN_FAILURE_DET_REQ |
11727 FLAGS_REARM_LATCH_SIGNAL,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011728 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11729 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11730 .mdio_ctrl = 0,
11731 .supported = (SUPPORTED_10baseT_Half |
11732 SUPPORTED_10baseT_Full |
11733 SUPPORTED_100baseT_Half |
11734 SUPPORTED_100baseT_Full |
11735 SUPPORTED_1000baseT_Full |
11736 SUPPORTED_10000baseT_Full |
11737 SUPPORTED_TP |
11738 SUPPORTED_Autoneg |
11739 SUPPORTED_Pause |
11740 SUPPORTED_Asym_Pause),
11741 .media_type = ETH_PHY_BASE_T,
11742 .ver_addr = 0,
11743 .req_flow_ctrl = 0,
11744 .req_line_speed = 0,
11745 .speed_cap_mask = 0,
11746 .req_duplex = 0,
11747 .rsrv = 0,
11748 .config_init = (config_init_t)bnx2x_8481_config_init,
11749 .read_status = (read_status_t)bnx2x_848xx_read_status,
11750 .link_reset = (link_reset_t)bnx2x_8481_link_reset,
11751 .config_loopback = (config_loopback_t)NULL,
11752 .format_fw_ver = (format_fw_ver_t)bnx2x_848xx_format_ver,
11753 .hw_reset = (hw_reset_t)bnx2x_8481_hw_reset,
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000011754 .set_link_led = (set_link_led_t)bnx2x_848xx_set_link_led,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011755 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011756};
11757
11758static struct bnx2x_phy phy_84823 = {
11759 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84823,
11760 .addr = 0xff,
Yaniv Rosner9045f6b42011-05-31 21:28:27 +000011761 .def_md_devad = 0,
Yaniv Rosner55098c52012-04-03 18:41:27 +000011762 .flags = (FLAGS_FAN_FAILURE_DET_REQ |
11763 FLAGS_REARM_LATCH_SIGNAL |
11764 FLAGS_TX_ERROR_CHECK),
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011765 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11766 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11767 .mdio_ctrl = 0,
11768 .supported = (SUPPORTED_10baseT_Half |
11769 SUPPORTED_10baseT_Full |
11770 SUPPORTED_100baseT_Half |
11771 SUPPORTED_100baseT_Full |
11772 SUPPORTED_1000baseT_Full |
11773 SUPPORTED_10000baseT_Full |
11774 SUPPORTED_TP |
11775 SUPPORTED_Autoneg |
11776 SUPPORTED_Pause |
11777 SUPPORTED_Asym_Pause),
11778 .media_type = ETH_PHY_BASE_T,
11779 .ver_addr = 0,
11780 .req_flow_ctrl = 0,
11781 .req_line_speed = 0,
11782 .speed_cap_mask = 0,
11783 .req_duplex = 0,
11784 .rsrv = 0,
11785 .config_init = (config_init_t)bnx2x_848x3_config_init,
11786 .read_status = (read_status_t)bnx2x_848xx_read_status,
11787 .link_reset = (link_reset_t)bnx2x_848x3_link_reset,
11788 .config_loopback = (config_loopback_t)NULL,
11789 .format_fw_ver = (format_fw_ver_t)bnx2x_848xx_format_ver,
11790 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000011791 .set_link_led = (set_link_led_t)bnx2x_848xx_set_link_led,
Yaniv Rosner5c107fd2012-09-13 02:56:19 +000011792 .phy_specific_func = (phy_specific_func_t)bnx2x_848xx_specific_func
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011793};
11794
Yaniv Rosnerc87bca12011-01-31 04:22:41 +000011795static struct bnx2x_phy phy_84833 = {
11796 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833,
11797 .addr = 0xff,
Yaniv Rosner9045f6b42011-05-31 21:28:27 +000011798 .def_md_devad = 0,
Yaniv Rosner55098c52012-04-03 18:41:27 +000011799 .flags = (FLAGS_FAN_FAILURE_DET_REQ |
11800 FLAGS_REARM_LATCH_SIGNAL |
Yuval Mintzf6b6eb62012-09-10 05:51:07 +000011801 FLAGS_TX_ERROR_CHECK),
Yaniv Rosnerc87bca12011-01-31 04:22:41 +000011802 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11803 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11804 .mdio_ctrl = 0,
Yaniv Rosner0520e632011-07-05 01:06:59 +000011805 .supported = (SUPPORTED_100baseT_Half |
Yaniv Rosnerc87bca12011-01-31 04:22:41 +000011806 SUPPORTED_100baseT_Full |
11807 SUPPORTED_1000baseT_Full |
11808 SUPPORTED_10000baseT_Full |
11809 SUPPORTED_TP |
11810 SUPPORTED_Autoneg |
11811 SUPPORTED_Pause |
11812 SUPPORTED_Asym_Pause),
11813 .media_type = ETH_PHY_BASE_T,
11814 .ver_addr = 0,
11815 .req_flow_ctrl = 0,
11816 .req_line_speed = 0,
11817 .speed_cap_mask = 0,
11818 .req_duplex = 0,
11819 .rsrv = 0,
11820 .config_init = (config_init_t)bnx2x_848x3_config_init,
11821 .read_status = (read_status_t)bnx2x_848xx_read_status,
11822 .link_reset = (link_reset_t)bnx2x_848x3_link_reset,
11823 .config_loopback = (config_loopback_t)NULL,
11824 .format_fw_ver = (format_fw_ver_t)bnx2x_848xx_format_ver,
Yaniv Rosner985848f2011-07-05 01:06:48 +000011825 .hw_reset = (hw_reset_t)bnx2x_84833_hw_reset_phy,
Yaniv Rosnerc87bca12011-01-31 04:22:41 +000011826 .set_link_led = (set_link_led_t)bnx2x_848xx_set_link_led,
Yaniv Rosner5c107fd2012-09-13 02:56:19 +000011827 .phy_specific_func = (phy_specific_func_t)bnx2x_848xx_specific_func
Yaniv Rosnerc87bca12011-01-31 04:22:41 +000011828};
11829
Yaniv Rosner52c4d6c2011-07-05 01:06:34 +000011830static struct bnx2x_phy phy_54618se = {
11831 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54618SE,
Yaniv Rosner6583e332011-06-14 01:34:17 +000011832 .addr = 0xff,
11833 .def_md_devad = 0,
11834 .flags = FLAGS_INIT_XGXS_FIRST,
11835 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11836 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11837 .mdio_ctrl = 0,
11838 .supported = (SUPPORTED_10baseT_Half |
11839 SUPPORTED_10baseT_Full |
11840 SUPPORTED_100baseT_Half |
11841 SUPPORTED_100baseT_Full |
11842 SUPPORTED_1000baseT_Full |
11843 SUPPORTED_TP |
11844 SUPPORTED_Autoneg |
11845 SUPPORTED_Pause |
11846 SUPPORTED_Asym_Pause),
11847 .media_type = ETH_PHY_BASE_T,
11848 .ver_addr = 0,
11849 .req_flow_ctrl = 0,
11850 .req_line_speed = 0,
11851 .speed_cap_mask = 0,
11852 /* req_duplex = */0,
11853 /* rsrv = */0,
Yaniv Rosner52c4d6c2011-07-05 01:06:34 +000011854 .config_init = (config_init_t)bnx2x_54618se_config_init,
11855 .read_status = (read_status_t)bnx2x_54618se_read_status,
11856 .link_reset = (link_reset_t)bnx2x_54618se_link_reset,
11857 .config_loopback = (config_loopback_t)bnx2x_54618se_config_loopback,
Yaniv Rosner6583e332011-06-14 01:34:17 +000011858 .format_fw_ver = (format_fw_ver_t)NULL,
11859 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosner1d125bd2011-11-23 03:54:08 +000011860 .set_link_led = (set_link_led_t)bnx2x_5461x_set_link_led,
Yaniv Rosner5c107fd2012-09-13 02:56:19 +000011861 .phy_specific_func = (phy_specific_func_t)bnx2x_54618se_specific_func
Yaniv Rosner6583e332011-06-14 01:34:17 +000011862};
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011863/*****************************************************************/
11864/* */
11865/* Populate the phy according. Main function: bnx2x_populate_phy */
11866/* */
11867/*****************************************************************/
11868
11869static void bnx2x_populate_preemphasis(struct bnx2x *bp, u32 shmem_base,
11870 struct bnx2x_phy *phy, u8 port,
11871 u8 phy_index)
11872{
11873 /* Get the 4 lanes xgxs config rx and tx */
11874 u32 rx = 0, tx = 0, i;
11875 for (i = 0; i < 2; i++) {
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000011876 /* INT_PHY and EXT_PHY1 share the same value location in
11877 * the shmem. When num_phys is greater than 1, than this value
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011878 * applies only to EXT_PHY1
11879 */
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011880 if (phy_index == INT_PHY || phy_index == EXT_PHY1) {
11881 rx = REG_RD(bp, shmem_base +
11882 offsetof(struct shmem_region,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000011883 dev_info.port_hw_config[port].xgxs_config_rx[i<<1]));
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011884
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011885 tx = REG_RD(bp, shmem_base +
11886 offsetof(struct shmem_region,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000011887 dev_info.port_hw_config[port].xgxs_config_tx[i<<1]));
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011888 } else {
11889 rx = REG_RD(bp, shmem_base +
11890 offsetof(struct shmem_region,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000011891 dev_info.port_hw_config[port].xgxs_config2_rx[i<<1]));
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011892
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011893 tx = REG_RD(bp, shmem_base +
11894 offsetof(struct shmem_region,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000011895 dev_info.port_hw_config[port].xgxs_config2_rx[i<<1]));
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011896 }
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011897
11898 phy->rx_preemphasis[i << 1] = ((rx>>16) & 0xffff);
11899 phy->rx_preemphasis[(i << 1) + 1] = (rx & 0xffff);
11900
11901 phy->tx_preemphasis[i << 1] = ((tx>>16) & 0xffff);
11902 phy->tx_preemphasis[(i << 1) + 1] = (tx & 0xffff);
11903 }
11904}
11905
Yaniv Rosnere10bc842010-09-07 11:40:50 +000011906static u32 bnx2x_get_ext_phy_config(struct bnx2x *bp, u32 shmem_base,
11907 u8 phy_index, u8 port)
11908{
11909 u32 ext_phy_config = 0;
11910 switch (phy_index) {
11911 case EXT_PHY1:
11912 ext_phy_config = REG_RD(bp, shmem_base +
11913 offsetof(struct shmem_region,
11914 dev_info.port_hw_config[port].external_phy_config));
11915 break;
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011916 case EXT_PHY2:
11917 ext_phy_config = REG_RD(bp, shmem_base +
11918 offsetof(struct shmem_region,
11919 dev_info.port_hw_config[port].external_phy_config2));
11920 break;
Yaniv Rosnere10bc842010-09-07 11:40:50 +000011921 default:
11922 DP(NETIF_MSG_LINK, "Invalid phy_index %d\n", phy_index);
11923 return -EINVAL;
11924 }
11925
11926 return ext_phy_config;
11927}
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000011928static int bnx2x_populate_int_phy(struct bnx2x *bp, u32 shmem_base, u8 port,
11929 struct bnx2x_phy *phy)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011930{
11931 u32 phy_addr;
11932 u32 chip_id;
11933 u32 switch_cfg = (REG_RD(bp, shmem_base +
11934 offsetof(struct shmem_region,
11935 dev_info.port_feature_config[port].link_config)) &
11936 PORT_FEATURE_CONNECTED_SWITCH_MASK);
Yaniv Rosnerec15b892011-11-28 00:49:49 +000011937 chip_id = (REG_RD(bp, MISC_REG_CHIP_NUM) << 16) |
11938 ((REG_RD(bp, MISC_REG_CHIP_REV) & 0xf) << 12);
11939
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000011940 DP(NETIF_MSG_LINK, ":chip_id = 0x%x\n", chip_id);
11941 if (USES_WARPCORE(bp)) {
11942 u32 serdes_net_if;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011943 phy_addr = REG_RD(bp,
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000011944 MISC_REG_WC0_CTRL_PHY_ADDR);
11945 *phy = phy_warpcore;
11946 if (REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR) == 0x3)
11947 phy->flags |= FLAGS_4_PORT_MODE;
11948 else
11949 phy->flags &= ~FLAGS_4_PORT_MODE;
11950 /* Check Dual mode */
11951 serdes_net_if = (REG_RD(bp, shmem_base +
11952 offsetof(struct shmem_region, dev_info.
11953 port_hw_config[port].default_cfg)) &
11954 PORT_HW_CFG_NET_SERDES_IF_MASK);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000011955 /* Set the appropriate supported and flags indications per
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000011956 * interface type of the chip
11957 */
11958 switch (serdes_net_if) {
11959 case PORT_HW_CFG_NET_SERDES_IF_SGMII:
11960 phy->supported &= (SUPPORTED_10baseT_Half |
11961 SUPPORTED_10baseT_Full |
11962 SUPPORTED_100baseT_Half |
11963 SUPPORTED_100baseT_Full |
11964 SUPPORTED_1000baseT_Full |
11965 SUPPORTED_FIBRE |
11966 SUPPORTED_Autoneg |
11967 SUPPORTED_Pause |
11968 SUPPORTED_Asym_Pause);
11969 phy->media_type = ETH_PHY_BASE_T;
11970 break;
11971 case PORT_HW_CFG_NET_SERDES_IF_XFI:
11972 phy->media_type = ETH_PHY_XFP_FIBER;
11973 break;
11974 case PORT_HW_CFG_NET_SERDES_IF_SFI:
11975 phy->supported &= (SUPPORTED_1000baseT_Full |
11976 SUPPORTED_10000baseT_Full |
11977 SUPPORTED_FIBRE |
11978 SUPPORTED_Pause |
11979 SUPPORTED_Asym_Pause);
Yuval Mintzdbef8072012-06-20 19:05:22 +000011980 phy->media_type = ETH_PHY_SFPP_10G_FIBER;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000011981 break;
11982 case PORT_HW_CFG_NET_SERDES_IF_KR:
11983 phy->media_type = ETH_PHY_KR;
11984 phy->supported &= (SUPPORTED_1000baseT_Full |
11985 SUPPORTED_10000baseT_Full |
11986 SUPPORTED_FIBRE |
11987 SUPPORTED_Autoneg |
11988 SUPPORTED_Pause |
11989 SUPPORTED_Asym_Pause);
11990 break;
11991 case PORT_HW_CFG_NET_SERDES_IF_DXGXS:
11992 phy->media_type = ETH_PHY_KR;
11993 phy->flags |= FLAGS_WC_DUAL_MODE;
11994 phy->supported &= (SUPPORTED_20000baseMLD2_Full |
11995 SUPPORTED_FIBRE |
11996 SUPPORTED_Pause |
11997 SUPPORTED_Asym_Pause);
11998 break;
11999 case PORT_HW_CFG_NET_SERDES_IF_KR2:
12000 phy->media_type = ETH_PHY_KR;
12001 phy->flags |= FLAGS_WC_DUAL_MODE;
12002 phy->supported &= (SUPPORTED_20000baseKR2_Full |
12003 SUPPORTED_FIBRE |
12004 SUPPORTED_Pause |
12005 SUPPORTED_Asym_Pause);
12006 break;
12007 default:
12008 DP(NETIF_MSG_LINK, "Unknown WC interface type 0x%x\n",
12009 serdes_net_if);
12010 break;
12011 }
12012
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000012013 /* Enable MDC/MDIO work-around for E3 A0 since free running MDC
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000012014 * was not set as expected. For B0, ECO will be enabled so there
12015 * won't be an issue there
12016 */
12017 if (CHIP_REV(bp) == CHIP_REV_Ax)
12018 phy->flags |= FLAGS_MDC_MDIO_WA;
Yaniv Rosner157fa282011-08-02 22:59:32 +000012019 else
12020 phy->flags |= FLAGS_MDC_MDIO_WA_B0;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000012021 } else {
12022 switch (switch_cfg) {
12023 case SWITCH_CFG_1G:
12024 phy_addr = REG_RD(bp,
12025 NIG_REG_SERDES0_CTRL_PHY_ADDR +
12026 port * 0x10);
12027 *phy = phy_serdes;
12028 break;
12029 case SWITCH_CFG_10G:
12030 phy_addr = REG_RD(bp,
12031 NIG_REG_XGXS0_CTRL_PHY_ADDR +
12032 port * 0x18);
12033 *phy = phy_xgxs;
12034 break;
12035 default:
12036 DP(NETIF_MSG_LINK, "Invalid switch_cfg\n");
12037 return -EINVAL;
12038 }
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000012039 }
12040 phy->addr = (u8)phy_addr;
12041 phy->mdio_ctrl = bnx2x_get_emac_base(bp,
Yaniv Rosnerc18aa152010-09-07 11:41:07 +000012042 SHARED_HW_CFG_MDC_MDIO_ACCESS1_BOTH,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000012043 port);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012044 if (CHIP_IS_E2(bp))
12045 phy->def_md_devad = E2_DEFAULT_PHY_DEV_ADDR;
12046 else
12047 phy->def_md_devad = DEFAULT_PHY_DEV_ADDR;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000012048
12049 DP(NETIF_MSG_LINK, "Internal phy port=%d, addr=0x%x, mdio_ctl=0x%x\n",
12050 port, phy->addr, phy->mdio_ctrl);
12051
12052 bnx2x_populate_preemphasis(bp, shmem_base, phy, port, INT_PHY);
12053 return 0;
12054}
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012055
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000012056static int bnx2x_populate_ext_phy(struct bnx2x *bp,
12057 u8 phy_index,
12058 u32 shmem_base,
12059 u32 shmem2_base,
12060 u8 port,
12061 struct bnx2x_phy *phy)
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012062{
Yaniv Rosnerc18aa152010-09-07 11:41:07 +000012063 u32 ext_phy_config, phy_type, config2;
12064 u32 mdc_mdio_access = SHARED_HW_CFG_MDC_MDIO_ACCESS1_BOTH;
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012065 ext_phy_config = bnx2x_get_ext_phy_config(bp, shmem_base,
12066 phy_index, port);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000012067 phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
12068 /* Select the phy type */
12069 switch (phy_type) {
12070 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073:
Yaniv Rosnerc18aa152010-09-07 11:41:07 +000012071 mdc_mdio_access = SHARED_HW_CFG_MDC_MDIO_ACCESS1_SWAPPED;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000012072 *phy = phy_8073;
12073 break;
12074 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705:
12075 *phy = phy_8705;
12076 break;
12077 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706:
12078 *phy = phy_8706;
12079 break;
12080 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
Yaniv Rosnerc18aa152010-09-07 11:41:07 +000012081 mdc_mdio_access = SHARED_HW_CFG_MDC_MDIO_ACCESS1_EMAC1;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000012082 *phy = phy_8726;
12083 break;
12084 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727_NOC:
12085 /* BCM8727_NOC => BCM8727 no over current */
Yaniv Rosnerc18aa152010-09-07 11:41:07 +000012086 mdc_mdio_access = SHARED_HW_CFG_MDC_MDIO_ACCESS1_EMAC1;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000012087 *phy = phy_8727;
12088 phy->flags |= FLAGS_NOC;
12089 break;
Yaniv Rosnere4d78f12011-05-31 21:25:55 +000012090 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8722:
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000012091 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
Yaniv Rosnerc18aa152010-09-07 11:41:07 +000012092 mdc_mdio_access = SHARED_HW_CFG_MDC_MDIO_ACCESS1_EMAC1;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000012093 *phy = phy_8727;
12094 break;
12095 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8481:
12096 *phy = phy_8481;
12097 break;
12098 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84823:
12099 *phy = phy_84823;
12100 break;
Yaniv Rosnerc87bca12011-01-31 04:22:41 +000012101 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833:
12102 *phy = phy_84833;
12103 break;
Yaniv Rosner3756a892011-08-23 06:33:24 +000012104 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54616:
Yaniv Rosner52c4d6c2011-07-05 01:06:34 +000012105 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54618SE:
12106 *phy = phy_54618se;
Yuval Mintz26964bb2012-09-10 05:51:08 +000012107 if (phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54618SE)
12108 phy->flags |= FLAGS_EEE;
Yaniv Rosner6583e332011-06-14 01:34:17 +000012109 break;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000012110 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101:
12111 *phy = phy_7101;
12112 break;
12113 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE:
12114 *phy = phy_null;
12115 return -EINVAL;
12116 default:
12117 *phy = phy_null;
Yaniv Rosner6db51932011-11-28 00:49:50 +000012118 /* In case external PHY wasn't found */
12119 if ((phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT) &&
12120 (phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
12121 return -EINVAL;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000012122 return 0;
12123 }
12124
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012125 phy->addr = XGXS_EXT_PHY_ADDR(ext_phy_config);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000012126 bnx2x_populate_preemphasis(bp, shmem_base, phy, port, phy_index);
Yaniv Rosner62b29a52010-09-07 11:40:58 +000012127
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000012128 /* The shmem address of the phy version is located on different
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +000012129 * structures. In case this structure is too old, do not set
12130 * the address
12131 */
Yaniv Rosnerc18aa152010-09-07 11:41:07 +000012132 config2 = REG_RD(bp, shmem_base + offsetof(struct shmem_region,
12133 dev_info.shared_hw_config.config2));
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012134 if (phy_index == EXT_PHY1) {
12135 phy->ver_addr = shmem_base + offsetof(struct shmem_region,
12136 port_mb[port].ext_phy_fw_version);
Yaniv Rosnerc18aa152010-09-07 11:41:07 +000012137
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012138 /* Check specific mdc mdio settings */
12139 if (config2 & SHARED_HW_CFG_MDC_MDIO_ACCESS1_MASK)
12140 mdc_mdio_access = config2 &
12141 SHARED_HW_CFG_MDC_MDIO_ACCESS1_MASK;
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012142 } else {
12143 u32 size = REG_RD(bp, shmem2_base);
Yaniv Rosnerc18aa152010-09-07 11:41:07 +000012144
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012145 if (size >
12146 offsetof(struct shmem2_region, ext_phy_fw_version2)) {
12147 phy->ver_addr = shmem2_base +
12148 offsetof(struct shmem2_region,
12149 ext_phy_fw_version2[port]);
12150 }
12151 /* Check specific mdc mdio settings */
12152 if (config2 & SHARED_HW_CFG_MDC_MDIO_ACCESS2_MASK)
12153 mdc_mdio_access = (config2 &
12154 SHARED_HW_CFG_MDC_MDIO_ACCESS2_MASK) >>
12155 (SHARED_HW_CFG_MDC_MDIO_ACCESS2_SHIFT -
12156 SHARED_HW_CFG_MDC_MDIO_ACCESS1_SHIFT);
12157 }
Yaniv Rosnerc18aa152010-09-07 11:41:07 +000012158 phy->mdio_ctrl = bnx2x_get_emac_base(bp, mdc_mdio_access, port);
12159
Yaniv Rosner75318322012-01-17 02:33:27 +000012160 if ((phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833) &&
12161 (phy->ver_addr)) {
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000012162 /* Remove 100Mb link supported for BCM84833 when phy fw
Yaniv Rosner75318322012-01-17 02:33:27 +000012163 * version lower than or equal to 1.39
12164 */
12165 u32 raw_ver = REG_RD(bp, phy->ver_addr);
12166 if (((raw_ver & 0x7F) <= 39) &&
12167 (((raw_ver & 0xF80) >> 7) <= 1))
12168 phy->supported &= ~(SUPPORTED_100baseT_Half |
12169 SUPPORTED_100baseT_Full);
12170 }
12171
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000012172 /* In case mdc/mdio_access of the external phy is different than the
Yaniv Rosnerc18aa152010-09-07 11:41:07 +000012173 * mdc/mdio access of the XGXS, a HW lock must be taken in each access
12174 * to prevent one port interfere with another port's CL45 operations.
12175 */
12176 if (mdc_mdio_access != SHARED_HW_CFG_MDC_MDIO_ACCESS1_BOTH)
12177 phy->flags |= FLAGS_HW_LOCK_REQUIRED;
12178 DP(NETIF_MSG_LINK, "phy_type 0x%x port %d found in index %d\n",
12179 phy_type, port, phy_index);
12180 DP(NETIF_MSG_LINK, " addr=0x%x, mdio_ctl=0x%x\n",
12181 phy->addr, phy->mdio_ctrl);
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012182 return 0;
12183}
12184
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000012185static int bnx2x_populate_phy(struct bnx2x *bp, u8 phy_index, u32 shmem_base,
12186 u32 shmem2_base, u8 port, struct bnx2x_phy *phy)
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012187{
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000012188 int status = 0;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000012189 phy->type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN;
12190 if (phy_index == INT_PHY)
12191 return bnx2x_populate_int_phy(bp, shmem_base, port, phy);
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012192 status = bnx2x_populate_ext_phy(bp, phy_index, shmem_base, shmem2_base,
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012193 port, phy);
12194 return status;
12195}
12196
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000012197static void bnx2x_phy_def_cfg(struct link_params *params,
12198 struct bnx2x_phy *phy,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012199 u8 phy_index)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000012200{
12201 struct bnx2x *bp = params->bp;
12202 u32 link_config;
12203 /* Populate the default phy configuration for MF mode */
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012204 if (phy_index == EXT_PHY2) {
12205 link_config = REG_RD(bp, params->shmem_base +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012206 offsetof(struct shmem_region, dev_info.
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012207 port_feature_config[params->port].link_config2));
12208 phy->speed_cap_mask = REG_RD(bp, params->shmem_base +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012209 offsetof(struct shmem_region,
12210 dev_info.
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012211 port_hw_config[params->port].speed_capability_mask2));
12212 } else {
12213 link_config = REG_RD(bp, params->shmem_base +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012214 offsetof(struct shmem_region, dev_info.
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012215 port_feature_config[params->port].link_config));
12216 phy->speed_cap_mask = REG_RD(bp, params->shmem_base +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012217 offsetof(struct shmem_region,
12218 dev_info.
12219 port_hw_config[params->port].speed_capability_mask));
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012220 }
Joe Perches94f05b02011-08-14 12:16:20 +000012221 DP(NETIF_MSG_LINK,
12222 "Default config phy idx %x cfg 0x%x speed_cap_mask 0x%x\n",
12223 phy_index, link_config, phy->speed_cap_mask);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000012224
12225 phy->req_duplex = DUPLEX_FULL;
12226 switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
12227 case PORT_FEATURE_LINK_SPEED_10M_HALF:
12228 phy->req_duplex = DUPLEX_HALF;
12229 case PORT_FEATURE_LINK_SPEED_10M_FULL:
12230 phy->req_line_speed = SPEED_10;
12231 break;
12232 case PORT_FEATURE_LINK_SPEED_100M_HALF:
12233 phy->req_duplex = DUPLEX_HALF;
12234 case PORT_FEATURE_LINK_SPEED_100M_FULL:
12235 phy->req_line_speed = SPEED_100;
12236 break;
12237 case PORT_FEATURE_LINK_SPEED_1G:
12238 phy->req_line_speed = SPEED_1000;
12239 break;
12240 case PORT_FEATURE_LINK_SPEED_2_5G:
12241 phy->req_line_speed = SPEED_2500;
12242 break;
12243 case PORT_FEATURE_LINK_SPEED_10G_CX4:
12244 phy->req_line_speed = SPEED_10000;
12245 break;
12246 default:
12247 phy->req_line_speed = SPEED_AUTO_NEG;
12248 break;
12249 }
12250
12251 switch (link_config & PORT_FEATURE_FLOW_CONTROL_MASK) {
12252 case PORT_FEATURE_FLOW_CONTROL_AUTO:
12253 phy->req_flow_ctrl = BNX2X_FLOW_CTRL_AUTO;
12254 break;
12255 case PORT_FEATURE_FLOW_CONTROL_TX:
12256 phy->req_flow_ctrl = BNX2X_FLOW_CTRL_TX;
12257 break;
12258 case PORT_FEATURE_FLOW_CONTROL_RX:
12259 phy->req_flow_ctrl = BNX2X_FLOW_CTRL_RX;
12260 break;
12261 case PORT_FEATURE_FLOW_CONTROL_BOTH:
12262 phy->req_flow_ctrl = BNX2X_FLOW_CTRL_BOTH;
12263 break;
12264 default:
12265 phy->req_flow_ctrl = BNX2X_FLOW_CTRL_NONE;
12266 break;
12267 }
12268}
12269
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012270u32 bnx2x_phy_selection(struct link_params *params)
12271{
12272 u32 phy_config_swapped, prio_cfg;
12273 u32 return_cfg = PORT_HW_CFG_PHY_SELECTION_HARDWARE_DEFAULT;
12274
12275 phy_config_swapped = params->multi_phy_config &
12276 PORT_HW_CFG_PHY_SWAPPED_ENABLED;
12277
12278 prio_cfg = params->multi_phy_config &
12279 PORT_HW_CFG_PHY_SELECTION_MASK;
12280
12281 if (phy_config_swapped) {
12282 switch (prio_cfg) {
12283 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY_PRIORITY:
12284 return_cfg = PORT_HW_CFG_PHY_SELECTION_SECOND_PHY_PRIORITY;
12285 break;
12286 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY_PRIORITY:
12287 return_cfg = PORT_HW_CFG_PHY_SELECTION_FIRST_PHY_PRIORITY;
12288 break;
12289 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY:
12290 return_cfg = PORT_HW_CFG_PHY_SELECTION_FIRST_PHY;
12291 break;
12292 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY:
12293 return_cfg = PORT_HW_CFG_PHY_SELECTION_SECOND_PHY;
12294 break;
12295 }
12296 } else
12297 return_cfg = prio_cfg;
12298
12299 return return_cfg;
12300}
12301
12302
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000012303int bnx2x_phy_probe(struct link_params *params)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000012304{
Yaniv Rosner2f751a82011-11-28 00:49:52 +000012305 u8 phy_index, actual_phy_idx;
Yaniv Rosner1ac9e422011-05-31 21:26:11 +000012306 u32 phy_config_swapped, sync_offset, media_types;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000012307 struct bnx2x *bp = params->bp;
12308 struct bnx2x_phy *phy;
12309 params->num_phys = 0;
12310 DP(NETIF_MSG_LINK, "Begin phy probe\n");
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012311 phy_config_swapped = params->multi_phy_config &
12312 PORT_HW_CFG_PHY_SWAPPED_ENABLED;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000012313
12314 for (phy_index = INT_PHY; phy_index < MAX_PHYS;
12315 phy_index++) {
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000012316 actual_phy_idx = phy_index;
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012317 if (phy_config_swapped) {
12318 if (phy_index == EXT_PHY1)
12319 actual_phy_idx = EXT_PHY2;
12320 else if (phy_index == EXT_PHY2)
12321 actual_phy_idx = EXT_PHY1;
12322 }
12323 DP(NETIF_MSG_LINK, "phy_config_swapped %x, phy_index %x,"
12324 " actual_phy_idx %x\n", phy_config_swapped,
12325 phy_index, actual_phy_idx);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000012326 phy = &params->phy[actual_phy_idx];
12327 if (bnx2x_populate_phy(bp, phy_index, params->shmem_base,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012328 params->shmem2_base, params->port,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000012329 phy) != 0) {
12330 params->num_phys = 0;
12331 DP(NETIF_MSG_LINK, "phy probe failed in phy index %d\n",
12332 phy_index);
12333 for (phy_index = INT_PHY;
12334 phy_index < MAX_PHYS;
12335 phy_index++)
12336 *phy = phy_null;
12337 return -EINVAL;
12338 }
12339 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN)
12340 break;
12341
Yaniv Rosner55098c52012-04-03 18:41:27 +000012342 if (params->feature_config_flags &
12343 FEATURE_CONFIG_DISABLE_REMOTE_FAULT_DET)
12344 phy->flags &= ~FLAGS_TX_ERROR_CHECK;
12345
Yaniv Rosner1ac9e422011-05-31 21:26:11 +000012346 sync_offset = params->shmem_base +
12347 offsetof(struct shmem_region,
12348 dev_info.port_hw_config[params->port].media_type);
12349 media_types = REG_RD(bp, sync_offset);
12350
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000012351 /* Update media type for non-PMF sync only for the first time
Yaniv Rosner1ac9e422011-05-31 21:26:11 +000012352 * In case the media type changes afterwards, it will be updated
12353 * using the update_status function
12354 */
12355 if ((media_types & (PORT_HW_CFG_MEDIA_TYPE_PHY0_MASK <<
12356 (PORT_HW_CFG_MEDIA_TYPE_PHY1_SHIFT *
12357 actual_phy_idx))) == 0) {
12358 media_types |= ((phy->media_type &
12359 PORT_HW_CFG_MEDIA_TYPE_PHY0_MASK) <<
12360 (PORT_HW_CFG_MEDIA_TYPE_PHY1_SHIFT *
12361 actual_phy_idx));
12362 }
12363 REG_WR(bp, sync_offset, media_types);
12364
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012365 bnx2x_phy_def_cfg(params, phy, phy_index);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000012366 params->num_phys++;
12367 }
12368
12369 DP(NETIF_MSG_LINK, "End phy probe. #phys found %x\n", params->num_phys);
12370 return 0;
12371}
12372
Yaniv Rosner9045f6b42011-05-31 21:28:27 +000012373void bnx2x_init_bmac_loopback(struct link_params *params,
12374 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012375{
12376 struct bnx2x *bp = params->bp;
Yaniv Rosner9045f6b42011-05-31 21:28:27 +000012377 vars->link_up = 1;
12378 vars->line_speed = SPEED_10000;
12379 vars->duplex = DUPLEX_FULL;
12380 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
12381 vars->mac_type = MAC_TYPE_BMAC;
12382
12383 vars->phy_flags = PHY_XGXS_FLAG;
12384
12385 bnx2x_xgxs_deassert(params);
12386
12387 /* set bmac loopback */
Yaniv Rosnerd3a8f132012-09-13 02:56:20 +000012388 bnx2x_bmac_enable(params, vars, 1, 1);
Yaniv Rosner9045f6b42011-05-31 21:28:27 +000012389
12390 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 0);
12391}
12392
12393void bnx2x_init_emac_loopback(struct link_params *params,
12394 struct link_vars *vars)
12395{
12396 struct bnx2x *bp = params->bp;
12397 vars->link_up = 1;
12398 vars->line_speed = SPEED_1000;
12399 vars->duplex = DUPLEX_FULL;
12400 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
12401 vars->mac_type = MAC_TYPE_EMAC;
12402
12403 vars->phy_flags = PHY_XGXS_FLAG;
12404
12405 bnx2x_xgxs_deassert(params);
12406 /* set bmac loopback */
12407 bnx2x_emac_enable(params, vars, 1);
12408 bnx2x_emac_program(params, vars);
12409 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 0);
12410}
12411
Yaniv Rosner9380bb92011-06-14 01:34:07 +000012412void bnx2x_init_xmac_loopback(struct link_params *params,
12413 struct link_vars *vars)
12414{
12415 struct bnx2x *bp = params->bp;
12416 vars->link_up = 1;
12417 if (!params->req_line_speed[0])
12418 vars->line_speed = SPEED_10000;
12419 else
12420 vars->line_speed = params->req_line_speed[0];
12421 vars->duplex = DUPLEX_FULL;
12422 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
12423 vars->mac_type = MAC_TYPE_XMAC;
12424 vars->phy_flags = PHY_XGXS_FLAG;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000012425 /* Set WC to loopback mode since link is required to provide clock
Yaniv Rosner9380bb92011-06-14 01:34:07 +000012426 * to the XMAC in 20G mode
12427 */
Yaniv Rosnerafad0092011-08-02 23:00:06 +000012428 bnx2x_set_aer_mmd(params, &params->phy[0]);
12429 bnx2x_warpcore_reset_lane(bp, &params->phy[0], 0);
12430 params->phy[INT_PHY].config_loopback(
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000012431 &params->phy[INT_PHY],
12432 params);
Yaniv Rosnerafad0092011-08-02 23:00:06 +000012433
Yaniv Rosner9380bb92011-06-14 01:34:07 +000012434 bnx2x_xmac_enable(params, vars, 1);
12435 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 0);
12436}
12437
12438void bnx2x_init_umac_loopback(struct link_params *params,
12439 struct link_vars *vars)
12440{
12441 struct bnx2x *bp = params->bp;
12442 vars->link_up = 1;
12443 vars->line_speed = SPEED_1000;
12444 vars->duplex = DUPLEX_FULL;
12445 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
12446 vars->mac_type = MAC_TYPE_UMAC;
12447 vars->phy_flags = PHY_XGXS_FLAG;
12448 bnx2x_umac_enable(params, vars, 1);
12449
12450 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 0);
12451}
12452
Yaniv Rosner9045f6b42011-05-31 21:28:27 +000012453void bnx2x_init_xgxs_loopback(struct link_params *params,
12454 struct link_vars *vars)
12455{
12456 struct bnx2x *bp = params->bp;
12457 vars->link_up = 1;
12458 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
12459 vars->duplex = DUPLEX_FULL;
12460 if (params->req_line_speed[0] == SPEED_1000)
12461 vars->line_speed = SPEED_1000;
12462 else
12463 vars->line_speed = SPEED_10000;
12464
Yaniv Rosner9380bb92011-06-14 01:34:07 +000012465 if (!USES_WARPCORE(bp))
12466 bnx2x_xgxs_deassert(params);
Yaniv Rosner9045f6b42011-05-31 21:28:27 +000012467 bnx2x_link_initialize(params, vars);
12468
12469 if (params->req_line_speed[0] == SPEED_1000) {
Yaniv Rosner9380bb92011-06-14 01:34:07 +000012470 if (USES_WARPCORE(bp))
12471 bnx2x_umac_enable(params, vars, 0);
12472 else {
12473 bnx2x_emac_program(params, vars);
12474 bnx2x_emac_enable(params, vars, 0);
12475 }
12476 } else {
12477 if (USES_WARPCORE(bp))
12478 bnx2x_xmac_enable(params, vars, 0);
12479 else
Yaniv Rosnerd3a8f132012-09-13 02:56:20 +000012480 bnx2x_bmac_enable(params, vars, 0, 1);
Yaniv Rosner9380bb92011-06-14 01:34:07 +000012481 }
Yaniv Rosner9045f6b42011-05-31 21:28:27 +000012482
12483 if (params->loopback_mode == LOOPBACK_XGXS) {
12484 /* set 10G XGXS loopback */
12485 params->phy[INT_PHY].config_loopback(
12486 &params->phy[INT_PHY],
12487 params);
12488
12489 } else {
12490 /* set external phy loopback */
12491 u8 phy_index;
12492 for (phy_index = EXT_PHY1;
12493 phy_index < params->num_phys; phy_index++) {
12494 if (params->phy[phy_index].config_loopback)
12495 params->phy[phy_index].config_loopback(
12496 &params->phy[phy_index],
12497 params);
12498 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012499 }
Yaniv Rosner9045f6b42011-05-31 21:28:27 +000012500 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012501
Yaniv Rosner9045f6b42011-05-31 21:28:27 +000012502 bnx2x_set_led(params, vars, LED_MODE_OPER, vars->line_speed);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012503}
12504
Yaniv Rosnerd3a8f132012-09-13 02:56:20 +000012505static void bnx2x_set_rx_filter(struct link_params *params, u8 en)
12506{
12507 struct bnx2x *bp = params->bp;
12508 u8 val = en * 0x1F;
12509
12510 /* Open the gate between the NIG to the BRB */
12511 if (!CHIP_IS_E1x(bp))
12512 val |= en * 0x20;
12513 REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + params->port*4, val);
12514
12515 if (!CHIP_IS_E1(bp)) {
12516 REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + params->port*4,
12517 en*0x3);
12518 }
12519
12520 REG_WR(bp, (params->port ? NIG_REG_LLH1_BRB1_NOT_MCP :
12521 NIG_REG_LLH0_BRB1_NOT_MCP), en);
12522}
12523static int bnx2x_avoid_link_flap(struct link_params *params,
12524 struct link_vars *vars)
12525{
12526 u32 phy_idx;
12527 u32 dont_clear_stat, lfa_sts;
12528 struct bnx2x *bp = params->bp;
12529
12530 /* Sync the link parameters */
12531 bnx2x_link_status_update(params, vars);
12532
12533 /*
12534 * The module verification was already done by previous link owner,
12535 * so this call is meant only to get warning message
12536 */
12537
12538 for (phy_idx = INT_PHY; phy_idx < params->num_phys; phy_idx++) {
12539 struct bnx2x_phy *phy = &params->phy[phy_idx];
12540 if (phy->phy_specific_func) {
12541 DP(NETIF_MSG_LINK, "Calling PHY specific func\n");
12542 phy->phy_specific_func(phy, params, PHY_INIT);
12543 }
12544 if ((phy->media_type == ETH_PHY_SFPP_10G_FIBER) ||
12545 (phy->media_type == ETH_PHY_SFP_1G_FIBER) ||
12546 (phy->media_type == ETH_PHY_DA_TWINAX))
12547 bnx2x_verify_sfp_module(phy, params);
12548 }
12549 lfa_sts = REG_RD(bp, params->lfa_base +
12550 offsetof(struct shmem_lfa,
12551 lfa_sts));
12552
12553 dont_clear_stat = lfa_sts & SHMEM_LFA_DONT_CLEAR_STAT;
12554
12555 /* Re-enable the NIG/MAC */
12556 if (CHIP_IS_E3(bp)) {
12557 if (!dont_clear_stat) {
12558 REG_WR(bp, GRCBASE_MISC +
12559 MISC_REGISTERS_RESET_REG_2_CLEAR,
12560 (MISC_REGISTERS_RESET_REG_2_MSTAT0 <<
12561 params->port));
12562 REG_WR(bp, GRCBASE_MISC +
12563 MISC_REGISTERS_RESET_REG_2_SET,
12564 (MISC_REGISTERS_RESET_REG_2_MSTAT0 <<
12565 params->port));
12566 }
12567 if (vars->line_speed < SPEED_10000)
12568 bnx2x_umac_enable(params, vars, 0);
12569 else
12570 bnx2x_xmac_enable(params, vars, 0);
12571 } else {
12572 if (vars->line_speed < SPEED_10000)
12573 bnx2x_emac_enable(params, vars, 0);
12574 else
12575 bnx2x_bmac_enable(params, vars, 0, !dont_clear_stat);
12576 }
12577
12578 /* Increment LFA count */
12579 lfa_sts = ((lfa_sts & ~LINK_FLAP_AVOIDANCE_COUNT_MASK) |
12580 (((((lfa_sts & LINK_FLAP_AVOIDANCE_COUNT_MASK) >>
12581 LINK_FLAP_AVOIDANCE_COUNT_OFFSET) + 1) & 0xff)
12582 << LINK_FLAP_AVOIDANCE_COUNT_OFFSET));
12583 /* Clear link flap reason */
12584 lfa_sts &= ~LFA_LINK_FLAP_REASON_MASK;
12585
12586 REG_WR(bp, params->lfa_base +
12587 offsetof(struct shmem_lfa, lfa_sts), lfa_sts);
12588
12589 /* Disable NIG DRAIN */
12590 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 0);
12591
12592 /* Enable interrupts */
12593 bnx2x_link_int_enable(params);
12594 return 0;
12595}
12596
12597static void bnx2x_cannot_avoid_link_flap(struct link_params *params,
12598 struct link_vars *vars,
12599 int lfa_status)
12600{
12601 u32 lfa_sts, cfg_idx, tmp_val;
12602 struct bnx2x *bp = params->bp;
12603
12604 bnx2x_link_reset(params, vars, 1);
12605
12606 if (!params->lfa_base)
12607 return;
12608 /* Store the new link parameters */
12609 REG_WR(bp, params->lfa_base +
12610 offsetof(struct shmem_lfa, req_duplex),
12611 params->req_duplex[0] | (params->req_duplex[1] << 16));
12612
12613 REG_WR(bp, params->lfa_base +
12614 offsetof(struct shmem_lfa, req_flow_ctrl),
12615 params->req_flow_ctrl[0] | (params->req_flow_ctrl[1] << 16));
12616
12617 REG_WR(bp, params->lfa_base +
12618 offsetof(struct shmem_lfa, req_line_speed),
12619 params->req_line_speed[0] | (params->req_line_speed[1] << 16));
12620
12621 for (cfg_idx = 0; cfg_idx < SHMEM_LINK_CONFIG_SIZE; cfg_idx++) {
12622 REG_WR(bp, params->lfa_base +
12623 offsetof(struct shmem_lfa,
12624 speed_cap_mask[cfg_idx]),
12625 params->speed_cap_mask[cfg_idx]);
12626 }
12627
12628 tmp_val = REG_RD(bp, params->lfa_base +
12629 offsetof(struct shmem_lfa, additional_config));
12630 tmp_val &= ~REQ_FC_AUTO_ADV_MASK;
12631 tmp_val |= params->req_fc_auto_adv;
12632
12633 REG_WR(bp, params->lfa_base +
12634 offsetof(struct shmem_lfa, additional_config), tmp_val);
12635
12636 lfa_sts = REG_RD(bp, params->lfa_base +
12637 offsetof(struct shmem_lfa, lfa_sts));
12638
12639 /* Clear the "Don't Clear Statistics" bit, and set reason */
12640 lfa_sts &= ~SHMEM_LFA_DONT_CLEAR_STAT;
12641
12642 /* Set link flap reason */
12643 lfa_sts &= ~LFA_LINK_FLAP_REASON_MASK;
12644 lfa_sts |= ((lfa_status & LFA_LINK_FLAP_REASON_MASK) <<
12645 LFA_LINK_FLAP_REASON_OFFSET);
12646
12647 /* Increment link flap counter */
12648 lfa_sts = ((lfa_sts & ~LINK_FLAP_COUNT_MASK) |
12649 (((((lfa_sts & LINK_FLAP_COUNT_MASK) >>
12650 LINK_FLAP_COUNT_OFFSET) + 1) & 0xff)
12651 << LINK_FLAP_COUNT_OFFSET));
12652 REG_WR(bp, params->lfa_base +
12653 offsetof(struct shmem_lfa, lfa_sts), lfa_sts);
12654 /* Proceed with regular link initialization */
12655}
12656
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000012657int bnx2x_phy_init(struct link_params *params, struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012658{
Yaniv Rosnerd3a8f132012-09-13 02:56:20 +000012659 int lfa_status;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012660 struct bnx2x *bp = params->bp;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012661 DP(NETIF_MSG_LINK, "Phy Initialization started\n");
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012662 DP(NETIF_MSG_LINK, "(1) req_speed %d, req_flowctrl %d\n",
12663 params->req_line_speed[0], params->req_flow_ctrl[0]);
12664 DP(NETIF_MSG_LINK, "(2) req_speed %d, req_flowctrl %d\n",
12665 params->req_line_speed[1], params->req_flow_ctrl[1]);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012666 vars->link_status = 0;
12667 vars->phy_link_up = 0;
12668 vars->link_up = 0;
12669 vars->line_speed = 0;
12670 vars->duplex = DUPLEX_FULL;
12671 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
12672 vars->mac_type = MAC_TYPE_NONE;
12673 vars->phy_flags = 0;
Yaniv Rosnerd3a8f132012-09-13 02:56:20 +000012674 /* Driver opens NIG-BRB filters */
12675 bnx2x_set_rx_filter(params, 1);
12676 /* Check if link flap can be avoided */
12677 lfa_status = bnx2x_check_lfa(params);
12678
12679 if (lfa_status == 0) {
12680 DP(NETIF_MSG_LINK, "Link Flap Avoidance in progress\n");
12681 return bnx2x_avoid_link_flap(params, vars);
12682 }
12683
12684 DP(NETIF_MSG_LINK, "Cannot avoid link flap lfa_sta=0x%x\n",
12685 lfa_status);
12686 bnx2x_cannot_avoid_link_flap(params, vars, lfa_status);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012687
Yuval Mintzd2310232012-06-20 19:05:19 +000012688 /* Disable attentions */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012689 bnx2x_bits_dis(bp, NIG_REG_MASK_INTERRUPT_PORT0 + params->port*4,
12690 (NIG_MASK_XGXS0_LINK_STATUS |
12691 NIG_MASK_XGXS0_LINK10G |
12692 NIG_MASK_SERDES0_LINK_STATUS |
12693 NIG_MASK_MI_INT));
12694
12695 bnx2x_emac_init(params, vars);
12696
Yaniv Rosner27d91292012-04-04 01:28:54 +000012697 if (params->feature_config_flags & FEATURE_CONFIG_PFC_ENABLED)
12698 vars->link_status |= LINK_STATUS_PFC_ENABLED;
12699
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012700 if (params->num_phys == 0) {
12701 DP(NETIF_MSG_LINK, "No phy found for initialization !!\n");
12702 return -EINVAL;
12703 }
Yaniv Rosner9045f6b42011-05-31 21:28:27 +000012704 set_phy_vars(params, vars);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012705
12706 DP(NETIF_MSG_LINK, "Num of phys on board: %d\n", params->num_phys);
Yaniv Rosner9045f6b42011-05-31 21:28:27 +000012707 switch (params->loopback_mode) {
12708 case LOOPBACK_BMAC:
12709 bnx2x_init_bmac_loopback(params, vars);
12710 break;
12711 case LOOPBACK_EMAC:
12712 bnx2x_init_emac_loopback(params, vars);
12713 break;
Yaniv Rosner9380bb92011-06-14 01:34:07 +000012714 case LOOPBACK_XMAC:
12715 bnx2x_init_xmac_loopback(params, vars);
12716 break;
12717 case LOOPBACK_UMAC:
12718 bnx2x_init_umac_loopback(params, vars);
12719 break;
Yaniv Rosner9045f6b42011-05-31 21:28:27 +000012720 case LOOPBACK_XGXS:
12721 case LOOPBACK_EXT_PHY:
12722 bnx2x_init_xgxs_loopback(params, vars);
12723 break;
12724 default:
Yaniv Rosner9380bb92011-06-14 01:34:07 +000012725 if (!CHIP_IS_E3(bp)) {
12726 if (params->switch_cfg == SWITCH_CFG_10G)
12727 bnx2x_xgxs_deassert(params);
12728 else
12729 bnx2x_serdes_deassert(bp, params->port);
12730 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012731 bnx2x_link_initialize(params, vars);
12732 msleep(30);
12733 bnx2x_link_int_enable(params);
Yaniv Rosner9045f6b42011-05-31 21:28:27 +000012734 break;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012735 }
Yaniv Rosner55098c52012-04-03 18:41:27 +000012736 bnx2x_update_mng(params, vars->link_status);
Yuval Mintzc8c60d82012-06-06 17:13:07 +000012737
12738 bnx2x_update_mng_eee(params, vars->eee_status);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012739 return 0;
12740}
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000012741
12742int bnx2x_link_reset(struct link_params *params, struct link_vars *vars,
12743 u8 reset_ext_phy)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012744{
12745 struct bnx2x *bp = params->bp;
Yaniv Rosnercf1d9722010-11-01 05:32:34 +000012746 u8 phy_index, port = params->port, clear_latch_ind = 0;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012747 DP(NETIF_MSG_LINK, "Resetting the link of port %d\n", port);
Yuval Mintzd2310232012-06-20 19:05:19 +000012748 /* Disable attentions */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012749 vars->link_status = 0;
12750 bnx2x_update_mng(params, vars->link_status);
Yuval Mintzc8c60d82012-06-06 17:13:07 +000012751 vars->eee_status &= ~(SHMEM_EEE_LP_ADV_STATUS_MASK |
12752 SHMEM_EEE_ACTIVE_BIT);
12753 bnx2x_update_mng_eee(params, vars->eee_status);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012754 bnx2x_bits_dis(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012755 (NIG_MASK_XGXS0_LINK_STATUS |
12756 NIG_MASK_XGXS0_LINK10G |
12757 NIG_MASK_SERDES0_LINK_STATUS |
12758 NIG_MASK_MI_INT));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012759
Yuval Mintzd2310232012-06-20 19:05:19 +000012760 /* Activate nig drain */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012761 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + port*4, 1);
12762
Yuval Mintzd2310232012-06-20 19:05:19 +000012763 /* Disable nig egress interface */
Yaniv Rosner9380bb92011-06-14 01:34:07 +000012764 if (!CHIP_IS_E3(bp)) {
12765 REG_WR(bp, NIG_REG_BMAC0_OUT_EN + port*4, 0);
12766 REG_WR(bp, NIG_REG_EGRESS_EMAC0_OUT_EN + port*4, 0);
12767 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012768
Yaniv Rosnerd3a8f132012-09-13 02:56:20 +000012769 if (!CHIP_IS_E3(bp)) {
12770 bnx2x_set_bmac_rx(bp, params->chip_id, port, 0);
12771 } else {
12772 bnx2x_set_xmac_rxtx(params, 0);
12773 bnx2x_set_umac_rxtx(params, 0);
12774 }
Yuval Mintzd2310232012-06-20 19:05:19 +000012775 /* Disable emac */
Yaniv Rosner9380bb92011-06-14 01:34:07 +000012776 if (!CHIP_IS_E3(bp))
12777 REG_WR(bp, NIG_REG_NIG_EMAC0_EN + port*4, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012778
Yuval Mintzd2310232012-06-20 19:05:19 +000012779 usleep_range(10000, 20000);
Lucas De Marchi25985ed2011-03-30 22:57:33 -030012780 /* The PHY reset is controlled by GPIO 1
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012781 * Hold it as vars low
12782 */
Yuval Mintzd2310232012-06-20 19:05:19 +000012783 /* Clear link led */
Yaniv Rosnerca7b91b2012-04-04 01:40:02 +000012784 bnx2x_set_mdio_clk(bp, params->chip_id, port);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000012785 bnx2x_set_led(params, vars, LED_MODE_OFF, 0);
12786
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012787 if (reset_ext_phy) {
12788 for (phy_index = EXT_PHY1; phy_index < params->num_phys;
12789 phy_index++) {
Yaniv Rosner28f48812011-08-02 23:00:12 +000012790 if (params->phy[phy_index].link_reset) {
12791 bnx2x_set_aer_mmd(params,
12792 &params->phy[phy_index]);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012793 params->phy[phy_index].link_reset(
12794 &params->phy[phy_index],
12795 params);
Yaniv Rosner28f48812011-08-02 23:00:12 +000012796 }
Yaniv Rosnercf1d9722010-11-01 05:32:34 +000012797 if (params->phy[phy_index].flags &
12798 FLAGS_REARM_LATCH_SIGNAL)
12799 clear_latch_ind = 1;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012800 }
12801 }
12802
Yaniv Rosnercf1d9722010-11-01 05:32:34 +000012803 if (clear_latch_ind) {
12804 /* Clear latching indication */
12805 bnx2x_rearm_latch_signal(bp, port, 0);
12806 bnx2x_bits_dis(bp, NIG_REG_LATCH_BC_0 + port*4,
12807 1 << NIG_LATCH_BC_ENABLE_MI_INT);
12808 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012809 if (params->phy[INT_PHY].link_reset)
12810 params->phy[INT_PHY].link_reset(
12811 &params->phy[INT_PHY], params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012812
Yuval Mintzd2310232012-06-20 19:05:19 +000012813 /* Disable nig ingress interface */
Yaniv Rosner9380bb92011-06-14 01:34:07 +000012814 if (!CHIP_IS_E3(bp)) {
Yuval Mintzd2310232012-06-20 19:05:19 +000012815 /* Reset BigMac */
Yaniv Rosnerce7c0482011-10-27 05:09:47 +000012816 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
12817 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port));
Yaniv Rosner9380bb92011-06-14 01:34:07 +000012818 REG_WR(bp, NIG_REG_BMAC0_IN_EN + port*4, 0);
12819 REG_WR(bp, NIG_REG_EMAC0_IN_EN + port*4, 0);
Yaniv Rosnerce7c0482011-10-27 05:09:47 +000012820 } else {
12821 u32 xmac_base = (params->port) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
12822 bnx2x_set_xumac_nig(params, 0, 0);
12823 if (REG_RD(bp, MISC_REG_RESET_REG_2) &
12824 MISC_REGISTERS_RESET_REG_2_XMAC)
12825 REG_WR(bp, xmac_base + XMAC_REG_CTRL,
12826 XMAC_CTRL_REG_SOFT_RESET);
Yaniv Rosner9380bb92011-06-14 01:34:07 +000012827 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012828 vars->link_up = 0;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000012829 vars->phy_flags = 0;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012830 return 0;
12831}
Yaniv Rosnerd3a8f132012-09-13 02:56:20 +000012832int bnx2x_lfa_reset(struct link_params *params,
12833 struct link_vars *vars)
12834{
12835 struct bnx2x *bp = params->bp;
12836 vars->link_up = 0;
12837 vars->phy_flags = 0;
12838 if (!params->lfa_base)
12839 return bnx2x_link_reset(params, vars, 1);
12840 /*
12841 * Activate NIG drain so that during this time the device won't send
12842 * anything while it is unable to response.
12843 */
12844 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 1);
12845
12846 /*
12847 * Close gracefully the gate from BMAC to NIG such that no half packets
12848 * are passed.
12849 */
12850 if (!CHIP_IS_E3(bp))
12851 bnx2x_set_bmac_rx(bp, params->chip_id, params->port, 0);
12852
12853 if (CHIP_IS_E3(bp)) {
12854 bnx2x_set_xmac_rxtx(params, 0);
12855 bnx2x_set_umac_rxtx(params, 0);
12856 }
12857 /* Wait 10ms for the pipe to clean up*/
12858 usleep_range(10000, 20000);
12859
12860 /* Clean the NIG-BRB using the network filters in a way that will
12861 * not cut a packet in the middle.
12862 */
12863 bnx2x_set_rx_filter(params, 0);
12864
12865 /*
12866 * Re-open the gate between the BMAC and the NIG, after verifying the
12867 * gate to the BRB is closed, otherwise packets may arrive to the
12868 * firmware before driver had initialized it. The target is to achieve
12869 * minimum management protocol down time.
12870 */
12871 if (!CHIP_IS_E3(bp))
12872 bnx2x_set_bmac_rx(bp, params->chip_id, params->port, 1);
12873
12874 if (CHIP_IS_E3(bp)) {
12875 bnx2x_set_xmac_rxtx(params, 1);
12876 bnx2x_set_umac_rxtx(params, 1);
12877 }
12878 /* Disable NIG drain */
12879 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 0);
12880 return 0;
12881}
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012882
12883/****************************************************************************/
12884/* Common function */
12885/****************************************************************************/
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000012886static int bnx2x_8073_common_init_phy(struct bnx2x *bp,
12887 u32 shmem_base_path[],
12888 u32 shmem2_base_path[], u8 phy_index,
12889 u32 chip_id)
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012890{
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012891 struct bnx2x_phy phy[PORT_MAX];
12892 struct bnx2x_phy *phy_blk[PORT_MAX];
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012893 u16 val;
Yaniv Rosnerc8e64df2011-01-30 04:15:00 +000012894 s8 port = 0;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012895 s8 port_of_path = 0;
Yaniv Rosnerc8e64df2011-01-30 04:15:00 +000012896 u32 swap_val, swap_override;
12897 swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
12898 swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
12899 port ^= (swap_val && swap_override);
12900 bnx2x_ext_phy_hw_reset(bp, port);
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012901 /* PART1 - Reset both phys */
12902 for (port = PORT_MAX - 1; port >= PORT_0; port--) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012903 u32 shmem_base, shmem2_base;
12904 /* In E2, same phy is using for port0 of the two paths */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000012905 if (CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012906 shmem_base = shmem_base_path[0];
12907 shmem2_base = shmem2_base_path[0];
12908 port_of_path = port;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000012909 } else {
12910 shmem_base = shmem_base_path[port];
12911 shmem2_base = shmem2_base_path[port];
12912 port_of_path = 0;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012913 }
12914
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012915 /* Extract the ext phy address for the port */
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012916 if (bnx2x_populate_phy(bp, phy_index, shmem_base, shmem2_base,
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012917 port_of_path, &phy[port]) !=
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012918 0) {
12919 DP(NETIF_MSG_LINK, "populate_phy failed\n");
12920 return -EINVAL;
12921 }
Yuval Mintzd2310232012-06-20 19:05:19 +000012922 /* Disable attentions */
Yaniv Rosner6a71bbe2010-11-01 05:32:31 +000012923 bnx2x_bits_dis(bp, NIG_REG_MASK_INTERRUPT_PORT0 +
12924 port_of_path*4,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012925 (NIG_MASK_XGXS0_LINK_STATUS |
12926 NIG_MASK_XGXS0_LINK10G |
12927 NIG_MASK_SERDES0_LINK_STATUS |
12928 NIG_MASK_MI_INT));
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012929
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012930 /* Need to take the phy out of low power mode in order
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000012931 * to write to access its registers
12932 */
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012933 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012934 MISC_REGISTERS_GPIO_OUTPUT_HIGH,
12935 port);
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012936
12937 /* Reset the phy */
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012938 bnx2x_cl45_write(bp, &phy[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012939 MDIO_PMA_DEVAD,
12940 MDIO_PMA_REG_CTRL,
12941 1<<15);
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012942 }
12943
12944 /* Add delay of 150ms after reset */
12945 msleep(150);
12946
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012947 if (phy[PORT_0].addr & 0x1) {
12948 phy_blk[PORT_0] = &(phy[PORT_1]);
12949 phy_blk[PORT_1] = &(phy[PORT_0]);
12950 } else {
12951 phy_blk[PORT_0] = &(phy[PORT_0]);
12952 phy_blk[PORT_1] = &(phy[PORT_1]);
12953 }
12954
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012955 /* PART2 - Download firmware to both phys */
12956 for (port = PORT_MAX - 1; port >= PORT_0; port--) {
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000012957 if (CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012958 port_of_path = port;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000012959 else
12960 port_of_path = 0;
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012961
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012962 DP(NETIF_MSG_LINK, "Loading spirom for phy address 0x%x\n",
12963 phy_blk[port]->addr);
Yaniv Rosner5c99274b2011-01-18 04:33:36 +000012964 if (bnx2x_8073_8727_external_rom_boot(bp, phy_blk[port],
12965 port_of_path))
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012966 return -EINVAL;
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012967
12968 /* Only set bit 10 = 1 (Tx power down) */
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012969 bnx2x_cl45_read(bp, phy_blk[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012970 MDIO_PMA_DEVAD,
12971 MDIO_PMA_REG_TX_POWER_DOWN, &val);
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012972
12973 /* Phase1 of TX_POWER_DOWN reset */
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012974 bnx2x_cl45_write(bp, phy_blk[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012975 MDIO_PMA_DEVAD,
12976 MDIO_PMA_REG_TX_POWER_DOWN,
12977 (val | 1<<10));
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012978 }
12979
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000012980 /* Toggle Transmitter: Power down and then up with 600ms delay
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +000012981 * between
12982 */
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012983 msleep(600);
12984
12985 /* PART3 - complete TX_POWER_DOWN process, and set GPIO2 back to low */
12986 for (port = PORT_MAX - 1; port >= PORT_0; port--) {
Eilon Greensteinf5372252009-02-12 08:38:30 +000012987 /* Phase2 of POWER_DOWN_RESET */
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012988 /* Release bit 10 (Release Tx power down) */
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012989 bnx2x_cl45_read(bp, phy_blk[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012990 MDIO_PMA_DEVAD,
12991 MDIO_PMA_REG_TX_POWER_DOWN, &val);
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012992
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012993 bnx2x_cl45_write(bp, phy_blk[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012994 MDIO_PMA_DEVAD,
12995 MDIO_PMA_REG_TX_POWER_DOWN, (val & (~(1<<10))));
Yuval Mintzd2310232012-06-20 19:05:19 +000012996 usleep_range(15000, 30000);
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012997
12998 /* Read modify write the SPI-ROM version select register */
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012999 bnx2x_cl45_read(bp, phy_blk[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000013000 MDIO_PMA_DEVAD,
13001 MDIO_PMA_REG_EDC_FFE_MAIN, &val);
Yaniv Rosnere10bc842010-09-07 11:40:50 +000013002 bnx2x_cl45_write(bp, phy_blk[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000013003 MDIO_PMA_DEVAD,
13004 MDIO_PMA_REG_EDC_FFE_MAIN, (val | (1<<12)));
Yaniv Rosner6bbca912008-08-13 15:57:28 -070013005
13006 /* set GPIO2 back to LOW */
13007 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000013008 MISC_REGISTERS_GPIO_OUTPUT_LOW, port);
Yaniv Rosner6bbca912008-08-13 15:57:28 -070013009 }
13010 return 0;
Yaniv Rosner6bbca912008-08-13 15:57:28 -070013011}
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000013012static int bnx2x_8726_common_init_phy(struct bnx2x *bp,
13013 u32 shmem_base_path[],
13014 u32 shmem2_base_path[], u8 phy_index,
13015 u32 chip_id)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000013016{
13017 u32 val;
13018 s8 port;
13019 struct bnx2x_phy phy;
13020 /* Use port1 because of the static port-swap */
13021 /* Enable the module detection interrupt */
13022 val = REG_RD(bp, MISC_REG_GPIO_EVENT_EN);
13023 val |= ((1<<MISC_REGISTERS_GPIO_3)|
13024 (1<<(MISC_REGISTERS_GPIO_3 + MISC_REGISTERS_GPIO_PORT_SHIFT)));
13025 REG_WR(bp, MISC_REG_GPIO_EVENT_EN, val);
13026
Yaniv Rosner650154b2010-11-01 05:32:36 +000013027 bnx2x_ext_phy_hw_reset(bp, 0);
Yuval Mintzd2310232012-06-20 19:05:19 +000013028 usleep_range(5000, 10000);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000013029 for (port = 0; port < PORT_MAX; port++) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000013030 u32 shmem_base, shmem2_base;
13031
13032 /* In E2, same phy is using for port0 of the two paths */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000013033 if (CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000013034 shmem_base = shmem_base_path[0];
13035 shmem2_base = shmem2_base_path[0];
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000013036 } else {
13037 shmem_base = shmem_base_path[port];
13038 shmem2_base = shmem2_base_path[port];
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000013039 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000013040 /* Extract the ext phy address for the port */
Yaniv Rosnera22f0782010-09-07 11:41:20 +000013041 if (bnx2x_populate_phy(bp, phy_index, shmem_base, shmem2_base,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000013042 port, &phy) !=
13043 0) {
13044 DP(NETIF_MSG_LINK, "populate phy failed\n");
13045 return -EINVAL;
13046 }
13047
13048 /* Reset phy*/
13049 bnx2x_cl45_write(bp, &phy,
13050 MDIO_PMA_DEVAD, MDIO_PMA_REG_GEN_CTRL, 0x0001);
13051
13052
13053 /* Set fault module detected LED on */
13054 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_0,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000013055 MISC_REGISTERS_GPIO_HIGH,
13056 port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000013057 }
13058
13059 return 0;
13060}
Yaniv Rosnera8db5b42011-01-31 04:22:28 +000013061static void bnx2x_get_ext_phy_reset_gpio(struct bnx2x *bp, u32 shmem_base,
13062 u8 *io_gpio, u8 *io_port)
13063{
13064
13065 u32 phy_gpio_reset = REG_RD(bp, shmem_base +
13066 offsetof(struct shmem_region,
13067 dev_info.port_hw_config[PORT_0].default_cfg));
13068 switch (phy_gpio_reset) {
13069 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO0_P0:
13070 *io_gpio = 0;
13071 *io_port = 0;
13072 break;
13073 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO1_P0:
13074 *io_gpio = 1;
13075 *io_port = 0;
13076 break;
13077 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO2_P0:
13078 *io_gpio = 2;
13079 *io_port = 0;
13080 break;
13081 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO3_P0:
13082 *io_gpio = 3;
13083 *io_port = 0;
13084 break;
13085 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO0_P1:
13086 *io_gpio = 0;
13087 *io_port = 1;
13088 break;
13089 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO1_P1:
13090 *io_gpio = 1;
13091 *io_port = 1;
13092 break;
13093 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO2_P1:
13094 *io_gpio = 2;
13095 *io_port = 1;
13096 break;
13097 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO3_P1:
13098 *io_gpio = 3;
13099 *io_port = 1;
13100 break;
13101 default:
13102 /* Don't override the io_gpio and io_port */
13103 break;
13104 }
13105}
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000013106
13107static int bnx2x_8727_common_init_phy(struct bnx2x *bp,
13108 u32 shmem_base_path[],
13109 u32 shmem2_base_path[], u8 phy_index,
13110 u32 chip_id)
Eilon Greenstein4d295db2009-07-21 05:47:47 +000013111{
Yaniv Rosnera8db5b42011-01-31 04:22:28 +000013112 s8 port, reset_gpio;
Eilon Greenstein4d295db2009-07-21 05:47:47 +000013113 u32 swap_val, swap_override;
Yaniv Rosnere10bc842010-09-07 11:40:50 +000013114 struct bnx2x_phy phy[PORT_MAX];
13115 struct bnx2x_phy *phy_blk[PORT_MAX];
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000013116 s8 port_of_path;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000013117 swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
13118 swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
Eilon Greenstein4d295db2009-07-21 05:47:47 +000013119
Yaniv Rosnera8db5b42011-01-31 04:22:28 +000013120 reset_gpio = MISC_REGISTERS_GPIO_1;
Yaniv Rosnera22f0782010-09-07 11:41:20 +000013121 port = 1;
13122
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000013123 /* Retrieve the reset gpio/port which control the reset.
Yaniv Rosnera8db5b42011-01-31 04:22:28 +000013124 * Default is GPIO1, PORT1
13125 */
13126 bnx2x_get_ext_phy_reset_gpio(bp, shmem_base_path[0],
13127 (u8 *)&reset_gpio, (u8 *)&port);
Yaniv Rosnera22f0782010-09-07 11:41:20 +000013128
13129 /* Calculate the port based on port swap */
13130 port ^= (swap_val && swap_override);
13131
Yaniv Rosnera8db5b42011-01-31 04:22:28 +000013132 /* Initiate PHY reset*/
13133 bnx2x_set_gpio(bp, reset_gpio, MISC_REGISTERS_GPIO_OUTPUT_LOW,
13134 port);
Yuval Mintzd2310232012-06-20 19:05:19 +000013135 usleep_range(1000, 2000);
Yaniv Rosnera8db5b42011-01-31 04:22:28 +000013136 bnx2x_set_gpio(bp, reset_gpio, MISC_REGISTERS_GPIO_OUTPUT_HIGH,
13137 port);
13138
Yuval Mintzd2310232012-06-20 19:05:19 +000013139 usleep_range(5000, 10000);
Eilon Greenstein4d295db2009-07-21 05:47:47 +000013140
13141 /* PART1 - Reset both phys */
Yaniv Rosnera22f0782010-09-07 11:41:20 +000013142 for (port = PORT_MAX - 1; port >= PORT_0; port--) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000013143 u32 shmem_base, shmem2_base;
13144
13145 /* In E2, same phy is using for port0 of the two paths */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000013146 if (CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000013147 shmem_base = shmem_base_path[0];
13148 shmem2_base = shmem2_base_path[0];
13149 port_of_path = port;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000013150 } else {
13151 shmem_base = shmem_base_path[port];
13152 shmem2_base = shmem2_base_path[port];
13153 port_of_path = 0;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000013154 }
13155
Eilon Greenstein4d295db2009-07-21 05:47:47 +000013156 /* Extract the ext phy address for the port */
Yaniv Rosnera22f0782010-09-07 11:41:20 +000013157 if (bnx2x_populate_phy(bp, phy_index, shmem_base, shmem2_base,
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000013158 port_of_path, &phy[port]) !=
Yaniv Rosnere10bc842010-09-07 11:40:50 +000013159 0) {
13160 DP(NETIF_MSG_LINK, "populate phy failed\n");
13161 return -EINVAL;
13162 }
Eilon Greenstein4d295db2009-07-21 05:47:47 +000013163 /* disable attentions */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000013164 bnx2x_bits_dis(bp, NIG_REG_MASK_INTERRUPT_PORT0 +
13165 port_of_path*4,
13166 (NIG_MASK_XGXS0_LINK_STATUS |
13167 NIG_MASK_XGXS0_LINK10G |
13168 NIG_MASK_SERDES0_LINK_STATUS |
13169 NIG_MASK_MI_INT));
Eilon Greenstein4d295db2009-07-21 05:47:47 +000013170
Eilon Greenstein4d295db2009-07-21 05:47:47 +000013171
13172 /* Reset the phy */
Yaniv Rosnere10bc842010-09-07 11:40:50 +000013173 bnx2x_cl45_write(bp, &phy[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000013174 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 1<<15);
Eilon Greenstein4d295db2009-07-21 05:47:47 +000013175 }
13176
13177 /* Add delay of 150ms after reset */
13178 msleep(150);
Yaniv Rosnere10bc842010-09-07 11:40:50 +000013179 if (phy[PORT_0].addr & 0x1) {
13180 phy_blk[PORT_0] = &(phy[PORT_1]);
13181 phy_blk[PORT_1] = &(phy[PORT_0]);
13182 } else {
13183 phy_blk[PORT_0] = &(phy[PORT_0]);
13184 phy_blk[PORT_1] = &(phy[PORT_1]);
13185 }
Eilon Greenstein4d295db2009-07-21 05:47:47 +000013186 /* PART2 - Download firmware to both phys */
Yaniv Rosnere10bc842010-09-07 11:40:50 +000013187 for (port = PORT_MAX - 1; port >= PORT_0; port--) {
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000013188 if (CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000013189 port_of_path = port;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000013190 else
13191 port_of_path = 0;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000013192 DP(NETIF_MSG_LINK, "Loading spirom for phy address 0x%x\n",
13193 phy_blk[port]->addr);
Yaniv Rosner5c99274b2011-01-18 04:33:36 +000013194 if (bnx2x_8073_8727_external_rom_boot(bp, phy_blk[port],
13195 port_of_path))
Eilon Greenstein4d295db2009-07-21 05:47:47 +000013196 return -EINVAL;
Yaniv Rosner85242ee2011-07-05 01:06:53 +000013197 /* Disable PHY transmitter output */
13198 bnx2x_cl45_write(bp, phy_blk[port],
13199 MDIO_PMA_DEVAD,
13200 MDIO_PMA_REG_TX_DISABLE, 1);
Eilon Greenstein4d295db2009-07-21 05:47:47 +000013201
Yaniv Rosner5c99274b2011-01-18 04:33:36 +000013202 }
Eilon Greenstein4d295db2009-07-21 05:47:47 +000013203 return 0;
13204}
13205
Yaniv Rosner521683d2011-11-28 00:49:48 +000013206static int bnx2x_84833_common_init_phy(struct bnx2x *bp,
13207 u32 shmem_base_path[],
13208 u32 shmem2_base_path[],
13209 u8 phy_index,
13210 u32 chip_id)
13211{
13212 u8 reset_gpios;
Yaniv Rosner521683d2011-11-28 00:49:48 +000013213 reset_gpios = bnx2x_84833_get_reset_gpios(bp, shmem_base_path, chip_id);
13214 bnx2x_set_mult_gpio(bp, reset_gpios, MISC_REGISTERS_GPIO_OUTPUT_LOW);
13215 udelay(10);
13216 bnx2x_set_mult_gpio(bp, reset_gpios, MISC_REGISTERS_GPIO_OUTPUT_HIGH);
13217 DP(NETIF_MSG_LINK, "84833 reset pulse on pin values 0x%x\n",
13218 reset_gpios);
Yaniv Rosner521683d2011-11-28 00:49:48 +000013219 return 0;
13220}
13221
Yaniv Rosner11b2ec62012-01-17 02:33:25 +000013222static int bnx2x_84833_pre_init_phy(struct bnx2x *bp,
13223 struct bnx2x_phy *phy)
13224{
13225 u16 val, cnt;
13226 /* Wait for FW completing its initialization. */
13227 for (cnt = 0; cnt < 1500; cnt++) {
13228 bnx2x_cl45_read(bp, phy,
13229 MDIO_PMA_DEVAD,
13230 MDIO_PMA_REG_CTRL, &val);
13231 if (!(val & (1<<15)))
13232 break;
Yuval Mintzd2310232012-06-20 19:05:19 +000013233 usleep_range(1000, 2000);
Yaniv Rosner11b2ec62012-01-17 02:33:25 +000013234 }
13235 if (cnt >= 1500) {
13236 DP(NETIF_MSG_LINK, "84833 reset timeout\n");
13237 return -EINVAL;
13238 }
13239
13240 /* Put the port in super isolate mode. */
13241 bnx2x_cl45_read(bp, phy,
13242 MDIO_CTL_DEVAD,
13243 MDIO_84833_TOP_CFG_XGPHY_STRAP1, &val);
13244 val |= MDIO_84833_SUPER_ISOLATE;
13245 bnx2x_cl45_write(bp, phy,
13246 MDIO_CTL_DEVAD,
13247 MDIO_84833_TOP_CFG_XGPHY_STRAP1, val);
13248
13249 /* Save spirom version */
13250 bnx2x_save_848xx_spirom_version(phy, bp, PORT_0);
13251 return 0;
13252}
13253
13254int bnx2x_pre_init_phy(struct bnx2x *bp,
13255 u32 shmem_base,
13256 u32 shmem2_base,
13257 u32 chip_id)
13258{
13259 int rc = 0;
13260 struct bnx2x_phy phy;
13261 bnx2x_set_mdio_clk(bp, chip_id, PORT_0);
13262 if (bnx2x_populate_phy(bp, EXT_PHY1, shmem_base, shmem2_base,
13263 PORT_0, &phy)) {
13264 DP(NETIF_MSG_LINK, "populate_phy failed\n");
13265 return -EINVAL;
13266 }
13267 switch (phy.type) {
13268 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833:
13269 rc = bnx2x_84833_pre_init_phy(bp, &phy);
13270 break;
13271 default:
13272 break;
13273 }
13274 return rc;
13275}
Yaniv Rosner521683d2011-11-28 00:49:48 +000013276
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000013277static int bnx2x_ext_phy_common_init(struct bnx2x *bp, u32 shmem_base_path[],
13278 u32 shmem2_base_path[], u8 phy_index,
13279 u32 ext_phy_type, u32 chip_id)
Yaniv Rosner6bbca912008-08-13 15:57:28 -070013280{
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000013281 int rc = 0;
Yaniv Rosner6bbca912008-08-13 15:57:28 -070013282
13283 switch (ext_phy_type) {
13284 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073:
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000013285 rc = bnx2x_8073_common_init_phy(bp, shmem_base_path,
13286 shmem2_base_path,
13287 phy_index, chip_id);
Yaniv Rosner6bbca912008-08-13 15:57:28 -070013288 break;
Yaniv Rosnere4d78f12011-05-31 21:25:55 +000013289 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8722:
Eilon Greenstein4d295db2009-07-21 05:47:47 +000013290 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
13291 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727_NOC:
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000013292 rc = bnx2x_8727_common_init_phy(bp, shmem_base_path,
13293 shmem2_base_path,
13294 phy_index, chip_id);
Eilon Greenstein4d295db2009-07-21 05:47:47 +000013295 break;
13296
Eilon Greenstein589abe32009-02-12 08:36:55 +000013297 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000013298 /* GPIO1 affects both ports, so there's need to pull
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +000013299 * it for single port alone
13300 */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000013301 rc = bnx2x_8726_common_init_phy(bp, shmem_base_path,
13302 shmem2_base_path,
13303 phy_index, chip_id);
Yaniv Rosnera22f0782010-09-07 11:41:20 +000013304 break;
Yaniv Rosner0d40f0d2011-06-14 01:34:27 +000013305 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833:
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000013306 /* GPIO3's are linked, and so both need to be toggled
Yaniv Rosner0d40f0d2011-06-14 01:34:27 +000013307 * to obtain required 2us pulse.
13308 */
Yaniv Rosner521683d2011-11-28 00:49:48 +000013309 rc = bnx2x_84833_common_init_phy(bp, shmem_base_path,
13310 shmem2_base_path,
13311 phy_index, chip_id);
Yaniv Rosner0d40f0d2011-06-14 01:34:27 +000013312 break;
Yaniv Rosnera22f0782010-09-07 11:41:20 +000013313 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE:
13314 rc = -EINVAL;
Yaniv Rosner4f60dab2009-11-05 19:18:23 +020013315 break;
Yaniv Rosner6bbca912008-08-13 15:57:28 -070013316 default:
13317 DP(NETIF_MSG_LINK,
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +000013318 "ext_phy 0x%x common init not required\n",
13319 ext_phy_type);
Yaniv Rosner6bbca912008-08-13 15:57:28 -070013320 break;
13321 }
13322
Yuval Mintzd2310232012-06-20 19:05:19 +000013323 if (rc)
Yaniv Rosner6d870c32011-01-31 04:22:20 +000013324 netdev_err(bp->dev, "Warning: PHY was not initialized,"
13325 " Port %d\n",
13326 0);
Yaniv Rosner6bbca912008-08-13 15:57:28 -070013327 return rc;
13328}
13329
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000013330int bnx2x_common_init_phy(struct bnx2x *bp, u32 shmem_base_path[],
13331 u32 shmem2_base_path[], u32 chip_id)
Yaniv Rosnera22f0782010-09-07 11:41:20 +000013332{
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000013333 int rc = 0;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000013334 u32 phy_ver, val;
13335 u8 phy_index = 0;
Yaniv Rosnera22f0782010-09-07 11:41:20 +000013336 u32 ext_phy_type, ext_phy_config;
Yaniv Rosnera198c142011-05-31 21:29:42 +000013337 bnx2x_set_mdio_clk(bp, chip_id, PORT_0);
13338 bnx2x_set_mdio_clk(bp, chip_id, PORT_1);
Yaniv Rosnera22f0782010-09-07 11:41:20 +000013339 DP(NETIF_MSG_LINK, "Begin common phy init\n");
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000013340 if (CHIP_IS_E3(bp)) {
13341 /* Enable EPIO */
13342 val = REG_RD(bp, MISC_REG_GEN_PURP_HWG);
13343 REG_WR(bp, MISC_REG_GEN_PURP_HWG, val | 1);
13344 }
Yaniv Rosnerb21a3422011-01-18 04:33:24 +000013345 /* Check if common init was already done */
13346 phy_ver = REG_RD(bp, shmem_base_path[0] +
13347 offsetof(struct shmem_region,
13348 port_mb[PORT_0].ext_phy_fw_version));
13349 if (phy_ver) {
13350 DP(NETIF_MSG_LINK, "Not doing common init; phy ver is 0x%x\n",
13351 phy_ver);
13352 return 0;
13353 }
13354
Yaniv Rosnera22f0782010-09-07 11:41:20 +000013355 /* Read the ext_phy_type for arbitrary port(0) */
13356 for (phy_index = EXT_PHY1; phy_index < MAX_PHYS;
13357 phy_index++) {
13358 ext_phy_config = bnx2x_get_ext_phy_config(bp,
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000013359 shmem_base_path[0],
Yaniv Rosnera22f0782010-09-07 11:41:20 +000013360 phy_index, 0);
13361 ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000013362 rc |= bnx2x_ext_phy_common_init(bp, shmem_base_path,
13363 shmem2_base_path,
13364 phy_index, ext_phy_type,
13365 chip_id);
Yaniv Rosnera22f0782010-09-07 11:41:20 +000013366 }
13367 return rc;
13368}
13369
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013370static void bnx2x_check_over_curr(struct link_params *params,
13371 struct link_vars *vars)
13372{
13373 struct bnx2x *bp = params->bp;
13374 u32 cfg_pin;
13375 u8 port = params->port;
13376 u32 pin_val;
13377
13378 cfg_pin = (REG_RD(bp, params->shmem_base +
13379 offsetof(struct shmem_region,
13380 dev_info.port_hw_config[port].e3_cmn_pin_cfg1)) &
13381 PORT_HW_CFG_E3_OVER_CURRENT_MASK) >>
13382 PORT_HW_CFG_E3_OVER_CURRENT_SHIFT;
13383
13384 /* Ignore check if no external input PIN available */
13385 if (bnx2x_get_cfg_pin(bp, cfg_pin, &pin_val) != 0)
13386 return;
13387
13388 if (!pin_val) {
13389 if ((vars->phy_flags & PHY_OVER_CURRENT_FLAG) == 0) {
13390 netdev_err(bp->dev, "Error: Power fault on Port %d has"
13391 " been detected and the power to "
13392 "that SFP+ module has been removed"
13393 " to prevent failure of the card."
13394 " Please remove the SFP+ module and"
13395 " restart the system to clear this"
13396 " error.\n",
13397 params->port);
13398 vars->phy_flags |= PHY_OVER_CURRENT_FLAG;
13399 }
13400 } else
13401 vars->phy_flags &= ~PHY_OVER_CURRENT_FLAG;
13402}
13403
Yuval Mintzd0b8a6f2012-06-20 19:05:18 +000013404/* Returns 0 if no change occured since last check; 1 otherwise. */
13405static u8 bnx2x_analyze_link_error(struct link_params *params,
13406 struct link_vars *vars, u32 status,
13407 u32 phy_flag, u32 link_flag, u8 notify)
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013408{
13409 struct bnx2x *bp = params->bp;
13410 /* Compare new value with previous value */
13411 u8 led_mode;
Yuval Mintzd0b8a6f2012-06-20 19:05:18 +000013412 u32 old_status = (vars->phy_flags & phy_flag) ? 1 : 0;
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013413
Yuval Mintzd0b8a6f2012-06-20 19:05:18 +000013414 if ((status ^ old_status) == 0)
13415 return 0;
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013416
13417 /* If values differ */
Yuval Mintzd0b8a6f2012-06-20 19:05:18 +000013418 switch (phy_flag) {
13419 case PHY_HALF_OPEN_CONN_FLAG:
13420 DP(NETIF_MSG_LINK, "Analyze Remote Fault\n");
13421 break;
13422 case PHY_SFP_TX_FAULT_FLAG:
13423 DP(NETIF_MSG_LINK, "Analyze TX Fault\n");
13424 break;
13425 default:
13426 DP(NETIF_MSG_LINK, "Analyze UNKOWN\n");
13427 }
13428 DP(NETIF_MSG_LINK, "Link changed:[%x %x]->%x\n", vars->link_up,
13429 old_status, status);
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013430
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000013431 /* a. Update shmem->link_status accordingly
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013432 * b. Update link_vars->link_up
13433 */
Yuval Mintzd0b8a6f2012-06-20 19:05:18 +000013434 if (status) {
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013435 vars->link_status &= ~LINK_STATUS_LINK_UP;
Yuval Mintzd0b8a6f2012-06-20 19:05:18 +000013436 vars->link_status |= link_flag;
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013437 vars->link_up = 0;
Yuval Mintzd0b8a6f2012-06-20 19:05:18 +000013438 vars->phy_flags |= phy_flag;
Yaniv Rosner55098c52012-04-03 18:41:27 +000013439
13440 /* activate nig drain */
13441 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 1);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000013442 /* Set LED mode to off since the PHY doesn't know about these
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013443 * errors
13444 */
13445 led_mode = LED_MODE_OFF;
13446 } else {
13447 vars->link_status |= LINK_STATUS_LINK_UP;
Yuval Mintzd0b8a6f2012-06-20 19:05:18 +000013448 vars->link_status &= ~link_flag;
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013449 vars->link_up = 1;
Yuval Mintzd0b8a6f2012-06-20 19:05:18 +000013450 vars->phy_flags &= ~phy_flag;
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013451 led_mode = LED_MODE_OPER;
Yaniv Rosner55098c52012-04-03 18:41:27 +000013452
13453 /* Clear nig drain */
13454 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 0);
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013455 }
Yaniv Rosner55098c52012-04-03 18:41:27 +000013456 bnx2x_sync_link(params, vars);
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013457 /* Update the LED according to the link state */
13458 bnx2x_set_led(params, vars, led_mode, SPEED_10000);
13459
13460 /* Update link status in the shared memory */
13461 bnx2x_update_mng(params, vars->link_status);
13462
13463 /* C. Trigger General Attention */
13464 vars->periodic_flags |= PERIODIC_FLAGS_LINK_EVENT;
Yaniv Rosner55098c52012-04-03 18:41:27 +000013465 if (notify)
13466 bnx2x_notify_link_changed(bp);
Yuval Mintzd0b8a6f2012-06-20 19:05:18 +000013467
13468 return 1;
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013469}
13470
Yaniv Rosnerde6f3372011-08-02 22:59:25 +000013471/******************************************************************************
13472* Description:
13473* This function checks for half opened connection change indication.
13474* When such change occurs, it calls the bnx2x_analyze_link_error
13475* to check if Remote Fault is set or cleared. Reception of remote fault
13476* status message in the MAC indicates that the peer's MAC has detected
13477* a fault, for example, due to break in the TX side of fiber.
13478*
13479******************************************************************************/
Yaniv Rosner55098c52012-04-03 18:41:27 +000013480int bnx2x_check_half_open_conn(struct link_params *params,
13481 struct link_vars *vars,
13482 u8 notify)
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013483{
13484 struct bnx2x *bp = params->bp;
13485 u32 lss_status = 0;
13486 u32 mac_base;
13487 /* In case link status is physically up @ 10G do */
Yaniv Rosner55098c52012-04-03 18:41:27 +000013488 if (((vars->phy_flags & PHY_PHYSICAL_LINK_FLAG) == 0) ||
13489 (REG_RD(bp, NIG_REG_EGRESS_EMAC0_PORT + params->port*4)))
13490 return 0;
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013491
Yaniv Rosnerde6f3372011-08-02 22:59:25 +000013492 if (CHIP_IS_E3(bp) &&
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013493 (REG_RD(bp, MISC_REG_RESET_REG_2) &
Yaniv Rosnerde6f3372011-08-02 22:59:25 +000013494 (MISC_REGISTERS_RESET_REG_2_XMAC))) {
13495 /* Check E3 XMAC */
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000013496 /* Note that link speed cannot be queried here, since it may be
Yaniv Rosnerde6f3372011-08-02 22:59:25 +000013497 * zero while link is down. In case UMAC is active, LSS will
13498 * simply not be set
13499 */
13500 mac_base = (params->port) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
13501
13502 /* Clear stick bits (Requires rising edge) */
13503 REG_WR(bp, mac_base + XMAC_REG_CLEAR_RX_LSS_STATUS, 0);
13504 REG_WR(bp, mac_base + XMAC_REG_CLEAR_RX_LSS_STATUS,
13505 XMAC_CLEAR_RX_LSS_STATUS_REG_CLEAR_LOCAL_FAULT_STATUS |
13506 XMAC_CLEAR_RX_LSS_STATUS_REG_CLEAR_REMOTE_FAULT_STATUS);
13507 if (REG_RD(bp, mac_base + XMAC_REG_RX_LSS_STATUS))
13508 lss_status = 1;
13509
Yuval Mintzd0b8a6f2012-06-20 19:05:18 +000013510 bnx2x_analyze_link_error(params, vars, lss_status,
13511 PHY_HALF_OPEN_CONN_FLAG,
13512 LINK_STATUS_NONE, notify);
Yaniv Rosnerde6f3372011-08-02 22:59:25 +000013513 } else if (REG_RD(bp, MISC_REG_RESET_REG_2) &
13514 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << params->port)) {
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013515 /* Check E1X / E2 BMAC */
13516 u32 lss_status_reg;
13517 u32 wb_data[2];
13518 mac_base = params->port ? NIG_REG_INGRESS_BMAC1_MEM :
13519 NIG_REG_INGRESS_BMAC0_MEM;
13520 /* Read BIGMAC_REGISTER_RX_LSS_STATUS */
13521 if (CHIP_IS_E2(bp))
13522 lss_status_reg = BIGMAC2_REGISTER_RX_LSS_STAT;
13523 else
13524 lss_status_reg = BIGMAC_REGISTER_RX_LSS_STATUS;
13525
13526 REG_RD_DMAE(bp, mac_base + lss_status_reg, wb_data, 2);
13527 lss_status = (wb_data[0] > 0);
13528
Yuval Mintzd0b8a6f2012-06-20 19:05:18 +000013529 bnx2x_analyze_link_error(params, vars, lss_status,
13530 PHY_HALF_OPEN_CONN_FLAG,
13531 LINK_STATUS_NONE, notify);
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013532 }
Yaniv Rosner55098c52012-04-03 18:41:27 +000013533 return 0;
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013534}
Yuval Mintzd0b8a6f2012-06-20 19:05:18 +000013535static void bnx2x_sfp_tx_fault_detection(struct bnx2x_phy *phy,
13536 struct link_params *params,
13537 struct link_vars *vars)
13538{
13539 struct bnx2x *bp = params->bp;
13540 u32 cfg_pin, value = 0;
13541 u8 led_change, port = params->port;
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013542
Yuval Mintzd0b8a6f2012-06-20 19:05:18 +000013543 /* Get The SFP+ TX_Fault controlling pin ([eg]pio) */
13544 cfg_pin = (REG_RD(bp, params->shmem_base + offsetof(struct shmem_region,
13545 dev_info.port_hw_config[port].e3_cmn_pin_cfg)) &
13546 PORT_HW_CFG_E3_TX_FAULT_MASK) >>
13547 PORT_HW_CFG_E3_TX_FAULT_SHIFT;
13548
13549 if (bnx2x_get_cfg_pin(bp, cfg_pin, &value)) {
13550 DP(NETIF_MSG_LINK, "Failed to read pin 0x%02x\n", cfg_pin);
13551 return;
13552 }
13553
13554 led_change = bnx2x_analyze_link_error(params, vars, value,
13555 PHY_SFP_TX_FAULT_FLAG,
13556 LINK_STATUS_SFP_TX_FAULT, 1);
13557
13558 if (led_change) {
13559 /* Change TX_Fault led, set link status for further syncs */
13560 u8 led_mode;
13561
13562 if (vars->phy_flags & PHY_SFP_TX_FAULT_FLAG) {
13563 led_mode = MISC_REGISTERS_GPIO_HIGH;
13564 vars->link_status |= LINK_STATUS_SFP_TX_FAULT;
13565 } else {
13566 led_mode = MISC_REGISTERS_GPIO_LOW;
13567 vars->link_status &= ~LINK_STATUS_SFP_TX_FAULT;
13568 }
13569
13570 /* If module is unapproved, led should be on regardless */
13571 if (!(phy->flags & FLAGS_SFP_NOT_APPROVED)) {
13572 DP(NETIF_MSG_LINK, "Change TX_Fault LED: ->%x\n",
13573 led_mode);
13574 bnx2x_set_e3_module_fault_led(params, led_mode);
13575 }
13576 }
13577}
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013578void bnx2x_period_func(struct link_params *params, struct link_vars *vars)
13579{
Yaniv Rosnerde6f3372011-08-02 22:59:25 +000013580 u16 phy_idx;
Yaniv Rosner55098c52012-04-03 18:41:27 +000013581 struct bnx2x *bp = params->bp;
Yaniv Rosnerde6f3372011-08-02 22:59:25 +000013582 for (phy_idx = INT_PHY; phy_idx < MAX_PHYS; phy_idx++) {
13583 if (params->phy[phy_idx].flags & FLAGS_TX_ERROR_CHECK) {
13584 bnx2x_set_aer_mmd(params, &params->phy[phy_idx]);
Yaniv Rosner55098c52012-04-03 18:41:27 +000013585 if (bnx2x_check_half_open_conn(params, vars, 1) !=
13586 0)
13587 DP(NETIF_MSG_LINK, "Fault detection failed\n");
Yaniv Rosnerde6f3372011-08-02 22:59:25 +000013588 break;
13589 }
13590 }
13591
Yaniv Rosnera9077bf2011-10-27 05:09:46 +000013592 if (CHIP_IS_E3(bp)) {
13593 struct bnx2x_phy *phy = &params->phy[INT_PHY];
13594 bnx2x_set_aer_mmd(params, phy);
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013595 bnx2x_check_over_curr(params, vars);
Yuval Mintzd0b8a6f2012-06-20 19:05:18 +000013596 if (vars->rx_tx_asic_rst)
13597 bnx2x_warpcore_config_runtime(phy, params, vars);
13598
13599 if ((REG_RD(bp, params->shmem_base +
13600 offsetof(struct shmem_region, dev_info.
13601 port_hw_config[params->port].default_cfg))
13602 & PORT_HW_CFG_NET_SERDES_IF_MASK) ==
13603 PORT_HW_CFG_NET_SERDES_IF_SFI) {
13604 if (bnx2x_is_sfp_module_plugged(phy, params)) {
13605 bnx2x_sfp_tx_fault_detection(phy, params, vars);
13606 } else if (vars->link_status &
13607 LINK_STATUS_SFP_TX_FAULT) {
13608 /* Clean trail, interrupt corrects the leds */
13609 vars->link_status &= ~LINK_STATUS_SFP_TX_FAULT;
13610 vars->phy_flags &= ~PHY_SFP_TX_FAULT_FLAG;
13611 /* Update link status in the shared memory */
13612 bnx2x_update_mng(params, vars->link_status);
13613 }
13614 }
13615
Yaniv Rosnera9077bf2011-10-27 05:09:46 +000013616 }
13617
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013618}
13619
Yaniv Rosnera22f0782010-09-07 11:41:20 +000013620u8 bnx2x_hw_lock_required(struct bnx2x *bp, u32 shmem_base, u32 shmem2_base)
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +000013621{
13622 u8 phy_index;
13623 struct bnx2x_phy phy;
13624 for (phy_index = INT_PHY; phy_index < MAX_PHYS;
13625 phy_index++) {
Yaniv Rosnera22f0782010-09-07 11:41:20 +000013626 if (bnx2x_populate_phy(bp, phy_index, shmem_base, shmem2_base,
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +000013627 0, &phy) != 0) {
13628 DP(NETIF_MSG_LINK, "populate phy failed\n");
13629 return 0;
13630 }
13631
13632 if (phy.flags & FLAGS_HW_LOCK_REQUIRED)
13633 return 1;
13634 }
13635 return 0;
13636}
13637
13638u8 bnx2x_fan_failure_det_req(struct bnx2x *bp,
13639 u32 shmem_base,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000013640 u32 shmem2_base,
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +000013641 u8 port)
13642{
13643 u8 phy_index, fan_failure_det_req = 0;
13644 struct bnx2x_phy phy;
13645 for (phy_index = EXT_PHY1; phy_index < MAX_PHYS;
13646 phy_index++) {
Yaniv Rosnera22f0782010-09-07 11:41:20 +000013647 if (bnx2x_populate_phy(bp, phy_index, shmem_base, shmem2_base,
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +000013648 port, &phy)
13649 != 0) {
13650 DP(NETIF_MSG_LINK, "populate phy failed\n");
13651 return 0;
13652 }
13653 fan_failure_det_req |= (phy.flags &
13654 FLAGS_FAN_FAILURE_DET_REQ);
13655 }
13656 return fan_failure_det_req;
13657}
13658
13659void bnx2x_hw_reset_phy(struct link_params *params)
13660{
13661 u8 phy_index;
Yaniv Rosner985848f2011-07-05 01:06:48 +000013662 struct bnx2x *bp = params->bp;
13663 bnx2x_update_mng(params, 0);
13664 bnx2x_bits_dis(bp, NIG_REG_MASK_INTERRUPT_PORT0 + params->port*4,
13665 (NIG_MASK_XGXS0_LINK_STATUS |
13666 NIG_MASK_XGXS0_LINK10G |
13667 NIG_MASK_SERDES0_LINK_STATUS |
13668 NIG_MASK_MI_INT));
13669
13670 for (phy_index = INT_PHY; phy_index < MAX_PHYS;
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +000013671 phy_index++) {
13672 if (params->phy[phy_index].hw_reset) {
13673 params->phy[phy_index].hw_reset(
13674 &params->phy[phy_index],
13675 params);
13676 params->phy[phy_index] = phy_null;
13677 }
13678 }
13679}
Yaniv Rosner020c7e32011-05-31 21:28:43 +000013680
13681void bnx2x_init_mod_abs_int(struct bnx2x *bp, struct link_vars *vars,
13682 u32 chip_id, u32 shmem_base, u32 shmem2_base,
13683 u8 port)
13684{
13685 u8 gpio_num = 0xff, gpio_port = 0xff, phy_index;
13686 u32 val;
13687 u32 offset, aeu_mask, swap_val, swap_override, sync_offset;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000013688 if (CHIP_IS_E3(bp)) {
13689 if (bnx2x_get_mod_abs_int_cfg(bp, chip_id,
13690 shmem_base,
13691 port,
13692 &gpio_num,
13693 &gpio_port) != 0)
13694 return;
13695 } else {
Yaniv Rosner020c7e32011-05-31 21:28:43 +000013696 struct bnx2x_phy phy;
13697 for (phy_index = EXT_PHY1; phy_index < MAX_PHYS;
13698 phy_index++) {
13699 if (bnx2x_populate_phy(bp, phy_index, shmem_base,
13700 shmem2_base, port, &phy)
13701 != 0) {
13702 DP(NETIF_MSG_LINK, "populate phy failed\n");
13703 return;
13704 }
13705 if (phy.type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726) {
13706 gpio_num = MISC_REGISTERS_GPIO_3;
13707 gpio_port = port;
13708 break;
13709 }
13710 }
13711 }
13712
13713 if (gpio_num == 0xff)
13714 return;
13715
13716 /* Set GPIO3 to trigger SFP+ module insertion/removal */
13717 bnx2x_set_gpio(bp, gpio_num, MISC_REGISTERS_GPIO_INPUT_HI_Z, gpio_port);
13718
13719 swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
13720 swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
13721 gpio_port ^= (swap_val && swap_override);
13722
13723 vars->aeu_int_mask = AEU_INPUTS_ATTN_BITS_GPIO0_FUNCTION_0 <<
13724 (gpio_num + (gpio_port << 2));
13725
13726 sync_offset = shmem_base +
13727 offsetof(struct shmem_region,
13728 dev_info.port_hw_config[port].aeu_int_mask);
13729 REG_WR(bp, sync_offset, vars->aeu_int_mask);
13730
13731 DP(NETIF_MSG_LINK, "Setting MOD_ABS (GPIO%d_P%d) AEU to 0x%x\n",
13732 gpio_num, gpio_port, vars->aeu_int_mask);
13733
13734 if (port == 0)
13735 offset = MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0;
13736 else
13737 offset = MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0;
13738
13739 /* Open appropriate AEU for interrupts */
13740 aeu_mask = REG_RD(bp, offset);
13741 aeu_mask |= vars->aeu_int_mask;
13742 REG_WR(bp, offset, aeu_mask);
13743
13744 /* Enable the GPIO to trigger interrupt */
13745 val = REG_RD(bp, MISC_REG_GPIO_EVENT_EN);
13746 val |= 1 << (gpio_num + (gpio_port << 2));
13747 REG_WR(bp, MISC_REG_GPIO_EVENT_EN, val);
13748}