blob: f6178a1684d15e03d24472c9cdfc96ef2887bdf2 [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
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000324/******************************************************************/
Yaniv Rosner3c9ada22011-06-14 01:34:12 +0000325/* EPIO/GPIO section */
326/******************************************************************/
Yaniv Rosner3deb8162011-06-14 01:34:33 +0000327static void bnx2x_get_epio(struct bnx2x *bp, u32 epio_pin, u32 *en)
328{
329 u32 epio_mask, gp_oenable;
330 *en = 0;
331 /* Sanity check */
332 if (epio_pin > 31) {
333 DP(NETIF_MSG_LINK, "Invalid EPIO pin %d to get\n", epio_pin);
334 return;
335 }
336
337 epio_mask = 1 << epio_pin;
338 /* Set this EPIO to output */
339 gp_oenable = REG_RD(bp, MCP_REG_MCPR_GP_OENABLE);
340 REG_WR(bp, MCP_REG_MCPR_GP_OENABLE, gp_oenable & ~epio_mask);
341
342 *en = (REG_RD(bp, MCP_REG_MCPR_GP_INPUTS) & epio_mask) >> epio_pin;
343}
Yaniv Rosner3c9ada22011-06-14 01:34:12 +0000344static void bnx2x_set_epio(struct bnx2x *bp, u32 epio_pin, u32 en)
345{
346 u32 epio_mask, gp_output, gp_oenable;
347
348 /* Sanity check */
349 if (epio_pin > 31) {
350 DP(NETIF_MSG_LINK, "Invalid EPIO pin %d to set\n", epio_pin);
351 return;
352 }
353 DP(NETIF_MSG_LINK, "Setting EPIO pin %d to %d\n", epio_pin, en);
354 epio_mask = 1 << epio_pin;
355 /* Set this EPIO to output */
356 gp_output = REG_RD(bp, MCP_REG_MCPR_GP_OUTPUTS);
357 if (en)
358 gp_output |= epio_mask;
359 else
360 gp_output &= ~epio_mask;
361
362 REG_WR(bp, MCP_REG_MCPR_GP_OUTPUTS, gp_output);
363
364 /* Set the value for this EPIO */
365 gp_oenable = REG_RD(bp, MCP_REG_MCPR_GP_OENABLE);
366 REG_WR(bp, MCP_REG_MCPR_GP_OENABLE, gp_oenable | epio_mask);
367}
368
369static void bnx2x_set_cfg_pin(struct bnx2x *bp, u32 pin_cfg, u32 val)
370{
371 if (pin_cfg == PIN_CFG_NA)
372 return;
373 if (pin_cfg >= PIN_CFG_EPIO0) {
374 bnx2x_set_epio(bp, pin_cfg - PIN_CFG_EPIO0, val);
375 } else {
376 u8 gpio_num = (pin_cfg - PIN_CFG_GPIO0_P0) & 0x3;
377 u8 gpio_port = (pin_cfg - PIN_CFG_GPIO0_P0) >> 2;
378 bnx2x_set_gpio(bp, gpio_num, (u8)val, gpio_port);
379 }
380}
381
Yaniv Rosner3deb8162011-06-14 01:34:33 +0000382static u32 bnx2x_get_cfg_pin(struct bnx2x *bp, u32 pin_cfg, u32 *val)
383{
384 if (pin_cfg == PIN_CFG_NA)
385 return -EINVAL;
386 if (pin_cfg >= PIN_CFG_EPIO0) {
387 bnx2x_get_epio(bp, pin_cfg - PIN_CFG_EPIO0, val);
388 } else {
389 u8 gpio_num = (pin_cfg - PIN_CFG_GPIO0_P0) & 0x3;
390 u8 gpio_port = (pin_cfg - PIN_CFG_GPIO0_P0) >> 2;
391 *val = bnx2x_get_gpio(bp, gpio_num, gpio_port);
392 }
393 return 0;
394
395}
Yaniv Rosner3c9ada22011-06-14 01:34:12 +0000396/******************************************************************/
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000397/* ETS section */
398/******************************************************************/
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000399static void bnx2x_ets_e2e3a0_disabled(struct link_params *params)
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000400{
401 /* ETS disabled configuration*/
402 struct bnx2x *bp = params->bp;
403
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000404 DP(NETIF_MSG_LINK, "ETS E2E3 disabled configuration\n");
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000405
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000406 /* mapping between entry priority to client number (0,1,2 -debug and
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000407 * management clients, 3 - COS0 client, 4 - COS client)(HIGHEST)
408 * 3bits client num.
409 * PRI4 | PRI3 | PRI2 | PRI1 | PRI0
410 * cos1-100 cos0-011 dbg1-010 dbg0-001 MCP-000
411 */
412
413 REG_WR(bp, NIG_REG_P0_TX_ARB_PRIORITY_CLIENT, 0x4688);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000414 /* Bitmap of 5bits length. Each bit specifies whether the entry behaves
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000415 * as strict. Bits 0,1,2 - debug and management entries, 3 -
416 * COS0 entry, 4 - COS1 entry.
417 * COS1 | COS0 | DEBUG1 | DEBUG0 | MGMT
418 * bit4 bit3 bit2 bit1 bit0
419 * MCP and debug are strict
420 */
421
422 REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_IS_STRICT, 0x7);
423 /* defines which entries (clients) are subjected to WFQ arbitration */
424 REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_IS_SUBJECT2WFQ, 0);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000425 /* For strict priority entries defines the number of consecutive
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000426 * slots for the highest priority.
427 */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000428 REG_WR(bp, NIG_REG_P0_TX_ARB_NUM_STRICT_ARB_SLOTS, 0x100);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000429 /* mapping between the CREDIT_WEIGHT registers and actual client
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000430 * numbers
431 */
432 REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_CREDIT_MAP, 0);
433 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_0, 0);
434 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_1, 0);
435
436 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_0, 0);
437 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_1, 0);
438 REG_WR(bp, PBF_REG_HIGH_PRIORITY_COS_NUM, 0);
439 /* ETS mode disable */
440 REG_WR(bp, PBF_REG_ETS_ENABLED, 0);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000441 /* If ETS mode is enabled (there is no strict priority) defines a WFQ
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000442 * weight for COS0/COS1.
443 */
444 REG_WR(bp, PBF_REG_COS0_WEIGHT, 0x2710);
445 REG_WR(bp, PBF_REG_COS1_WEIGHT, 0x2710);
446 /* Upper bound that COS0_WEIGHT can reach in the WFQ arbiter */
447 REG_WR(bp, PBF_REG_COS0_UPPER_BOUND, 0x989680);
448 REG_WR(bp, PBF_REG_COS1_UPPER_BOUND, 0x989680);
449 /* Defines the number of consecutive slots for the strict priority */
450 REG_WR(bp, PBF_REG_NUM_STRICT_ARB_SLOTS, 0);
451}
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000452/******************************************************************************
453* Description:
454* Getting min_w_val will be set according to line speed .
455*.
456******************************************************************************/
457static u32 bnx2x_ets_get_min_w_val_nig(const struct link_vars *vars)
458{
459 u32 min_w_val = 0;
460 /* Calculate min_w_val.*/
461 if (vars->link_up) {
Yaniv Rosnerde0396f2011-11-28 00:49:53 +0000462 if (vars->line_speed == SPEED_20000)
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000463 min_w_val = ETS_E3B0_NIG_MIN_W_VAL_20GBPS;
464 else
465 min_w_val = ETS_E3B0_NIG_MIN_W_VAL_UP_TO_10GBPS;
466 } else
467 min_w_val = ETS_E3B0_NIG_MIN_W_VAL_20GBPS;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000468 /* If the link isn't up (static configuration for example ) The
469 * link will be according to 20GBPS.
470 */
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000471 return min_w_val;
472}
473/******************************************************************************
474* Description:
475* Getting credit upper bound form min_w_val.
476*.
477******************************************************************************/
478static u32 bnx2x_ets_get_credit_upper_bound(const u32 min_w_val)
479{
480 const u32 credit_upper_bound = (u32)MAXVAL((150 * min_w_val),
481 MAX_PACKET_SIZE);
482 return credit_upper_bound;
483}
484/******************************************************************************
485* Description:
486* Set credit upper bound for NIG.
487*.
488******************************************************************************/
489static void bnx2x_ets_e3b0_set_credit_upper_bound_nig(
490 const struct link_params *params,
491 const u32 min_w_val)
492{
493 struct bnx2x *bp = params->bp;
494 const u8 port = params->port;
495 const u32 credit_upper_bound =
496 bnx2x_ets_get_credit_upper_bound(min_w_val);
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000497
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000498 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_UPPER_BOUND_0 :
499 NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_0, credit_upper_bound);
500 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_UPPER_BOUND_1 :
501 NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_1, credit_upper_bound);
502 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_UPPER_BOUND_2 :
503 NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_2, credit_upper_bound);
504 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_UPPER_BOUND_3 :
505 NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_3, credit_upper_bound);
506 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_UPPER_BOUND_4 :
507 NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_4, credit_upper_bound);
508 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_UPPER_BOUND_5 :
509 NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_5, credit_upper_bound);
510
Yaniv Rosnerde0396f2011-11-28 00:49:53 +0000511 if (!port) {
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000512 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_6,
513 credit_upper_bound);
514 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_7,
515 credit_upper_bound);
516 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_8,
517 credit_upper_bound);
518 }
519}
520/******************************************************************************
521* Description:
522* Will return the NIG ETS registers to init values.Except
523* credit_upper_bound.
524* That isn't used in this configuration (No WFQ is enabled) and will be
525* configured acording to spec
526*.
527******************************************************************************/
528static void bnx2x_ets_e3b0_nig_disabled(const struct link_params *params,
529 const struct link_vars *vars)
530{
531 struct bnx2x *bp = params->bp;
532 const u8 port = params->port;
533 const u32 min_w_val = bnx2x_ets_get_min_w_val_nig(vars);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000534 /* Mapping between entry priority to client number (0,1,2 -debug and
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000535 * management clients, 3 - COS0 client, 4 - COS1, ... 8 -
536 * COS5)(HIGHEST) 4bits client num.TODO_ETS - Should be done by
537 * reset value or init tool
538 */
539 if (port) {
540 REG_WR(bp, NIG_REG_P1_TX_ARB_PRIORITY_CLIENT2_LSB, 0x543210);
541 REG_WR(bp, NIG_REG_P1_TX_ARB_PRIORITY_CLIENT2_MSB, 0x0);
542 } else {
543 REG_WR(bp, NIG_REG_P0_TX_ARB_PRIORITY_CLIENT2_LSB, 0x76543210);
544 REG_WR(bp, NIG_REG_P0_TX_ARB_PRIORITY_CLIENT2_MSB, 0x8);
545 }
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000546 /* For strict priority entries defines the number of consecutive
547 * slots for the highest priority.
548 */
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000549 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_NUM_STRICT_ARB_SLOTS :
550 NIG_REG_P1_TX_ARB_NUM_STRICT_ARB_SLOTS, 0x100);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000551 /* Mapping between the CREDIT_WEIGHT registers and actual client
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000552 * numbers
553 */
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000554 if (port) {
555 /*Port 1 has 6 COS*/
556 REG_WR(bp, NIG_REG_P1_TX_ARB_CLIENT_CREDIT_MAP2_LSB, 0x210543);
557 REG_WR(bp, NIG_REG_P1_TX_ARB_CLIENT_CREDIT_MAP2_MSB, 0x0);
558 } else {
559 /*Port 0 has 9 COS*/
560 REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_CREDIT_MAP2_LSB,
561 0x43210876);
562 REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_CREDIT_MAP2_MSB, 0x5);
563 }
564
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000565 /* Bitmap of 5bits length. Each bit specifies whether the entry behaves
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000566 * as strict. Bits 0,1,2 - debug and management entries, 3 -
567 * COS0 entry, 4 - COS1 entry.
568 * COS1 | COS0 | DEBUG1 | DEBUG0 | MGMT
569 * bit4 bit3 bit2 bit1 bit0
570 * MCP and debug are strict
571 */
572 if (port)
573 REG_WR(bp, NIG_REG_P1_TX_ARB_CLIENT_IS_STRICT, 0x3f);
574 else
575 REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_IS_STRICT, 0x1ff);
576 /* defines which entries (clients) are subjected to WFQ arbitration */
577 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CLIENT_IS_SUBJECT2WFQ :
578 NIG_REG_P0_TX_ARB_CLIENT_IS_SUBJECT2WFQ, 0);
579
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000580 /* Please notice the register address are note continuous and a
581 * for here is note appropriate.In 2 port mode port0 only COS0-5
582 * can be used. DEBUG1,DEBUG1,MGMT are never used for WFQ* In 4
583 * port mode port1 only COS0-2 can be used. DEBUG1,DEBUG1,MGMT
584 * are never used for WFQ
585 */
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000586 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_WEIGHT_0 :
587 NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_0, 0x0);
588 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_WEIGHT_1 :
589 NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_1, 0x0);
590 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_WEIGHT_2 :
591 NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_2, 0x0);
592 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_WEIGHT_3 :
593 NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_3, 0x0);
594 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_WEIGHT_4 :
595 NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_4, 0x0);
596 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_WEIGHT_5 :
597 NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_5, 0x0);
Yaniv Rosnerde0396f2011-11-28 00:49:53 +0000598 if (!port) {
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000599 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_6, 0x0);
600 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_7, 0x0);
601 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_8, 0x0);
602 }
603
604 bnx2x_ets_e3b0_set_credit_upper_bound_nig(params, min_w_val);
605}
606/******************************************************************************
607* Description:
608* Set credit upper bound for PBF.
609*.
610******************************************************************************/
611static void bnx2x_ets_e3b0_set_credit_upper_bound_pbf(
612 const struct link_params *params,
613 const u32 min_w_val)
614{
615 struct bnx2x *bp = params->bp;
616 const u32 credit_upper_bound =
617 bnx2x_ets_get_credit_upper_bound(min_w_val);
618 const u8 port = params->port;
619 u32 base_upper_bound = 0;
620 u8 max_cos = 0;
621 u8 i = 0;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000622 /* In 2 port mode port0 has COS0-5 that can be used for WFQ.In 4
623 * port mode port1 has COS0-2 that can be used for WFQ.
624 */
Yaniv Rosnerde0396f2011-11-28 00:49:53 +0000625 if (!port) {
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000626 base_upper_bound = PBF_REG_COS0_UPPER_BOUND_P0;
627 max_cos = DCBX_E3B0_MAX_NUM_COS_PORT0;
628 } else {
629 base_upper_bound = PBF_REG_COS0_UPPER_BOUND_P1;
630 max_cos = DCBX_E3B0_MAX_NUM_COS_PORT1;
631 }
632
633 for (i = 0; i < max_cos; i++)
634 REG_WR(bp, base_upper_bound + (i << 2), credit_upper_bound);
635}
636
637/******************************************************************************
638* Description:
639* Will return the PBF ETS registers to init values.Except
640* credit_upper_bound.
641* That isn't used in this configuration (No WFQ is enabled) and will be
642* configured acording to spec
643*.
644******************************************************************************/
645static void bnx2x_ets_e3b0_pbf_disabled(const struct link_params *params)
646{
647 struct bnx2x *bp = params->bp;
648 const u8 port = params->port;
649 const u32 min_w_val_pbf = ETS_E3B0_PBF_MIN_W_VAL;
650 u8 i = 0;
651 u32 base_weight = 0;
652 u8 max_cos = 0;
653
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000654 /* Mapping between entry priority to client number 0 - COS0
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000655 * client, 2 - COS1, ... 5 - COS5)(HIGHEST) 4bits client num.
656 * TODO_ETS - Should be done by reset value or init tool
657 */
658 if (port)
659 /* 0x688 (|011|0 10|00 1|000) */
660 REG_WR(bp, PBF_REG_ETS_ARB_PRIORITY_CLIENT_P1 , 0x688);
661 else
662 /* (10 1|100 |011|0 10|00 1|000) */
663 REG_WR(bp, PBF_REG_ETS_ARB_PRIORITY_CLIENT_P0 , 0x2C688);
664
665 /* TODO_ETS - Should be done by reset value or init tool */
666 if (port)
667 /* 0x688 (|011|0 10|00 1|000)*/
668 REG_WR(bp, PBF_REG_ETS_ARB_CLIENT_CREDIT_MAP_P1, 0x688);
669 else
670 /* 0x2C688 (10 1|100 |011|0 10|00 1|000) */
671 REG_WR(bp, PBF_REG_ETS_ARB_CLIENT_CREDIT_MAP_P0, 0x2C688);
672
673 REG_WR(bp, (port) ? PBF_REG_ETS_ARB_NUM_STRICT_ARB_SLOTS_P1 :
674 PBF_REG_ETS_ARB_NUM_STRICT_ARB_SLOTS_P0 , 0x100);
675
676
677 REG_WR(bp, (port) ? PBF_REG_ETS_ARB_CLIENT_IS_STRICT_P1 :
678 PBF_REG_ETS_ARB_CLIENT_IS_STRICT_P0 , 0);
679
680 REG_WR(bp, (port) ? PBF_REG_ETS_ARB_CLIENT_IS_SUBJECT2WFQ_P1 :
681 PBF_REG_ETS_ARB_CLIENT_IS_SUBJECT2WFQ_P0 , 0);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000682 /* In 2 port mode port0 has COS0-5 that can be used for WFQ.
683 * In 4 port mode port1 has COS0-2 that can be used for WFQ.
684 */
Yaniv Rosnerde0396f2011-11-28 00:49:53 +0000685 if (!port) {
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000686 base_weight = PBF_REG_COS0_WEIGHT_P0;
687 max_cos = DCBX_E3B0_MAX_NUM_COS_PORT0;
688 } else {
689 base_weight = PBF_REG_COS0_WEIGHT_P1;
690 max_cos = DCBX_E3B0_MAX_NUM_COS_PORT1;
691 }
692
693 for (i = 0; i < max_cos; i++)
694 REG_WR(bp, base_weight + (0x4 * i), 0);
695
696 bnx2x_ets_e3b0_set_credit_upper_bound_pbf(params, min_w_val_pbf);
697}
698/******************************************************************************
699* Description:
700* E3B0 disable will return basicly the values to init values.
701*.
702******************************************************************************/
703static int bnx2x_ets_e3b0_disabled(const struct link_params *params,
704 const struct link_vars *vars)
705{
706 struct bnx2x *bp = params->bp;
707
708 if (!CHIP_IS_E3B0(bp)) {
Joe Perches94f05b02011-08-14 12:16:20 +0000709 DP(NETIF_MSG_LINK,
710 "bnx2x_ets_e3b0_disabled the chip isn't E3B0\n");
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000711 return -EINVAL;
712 }
713
714 bnx2x_ets_e3b0_nig_disabled(params, vars);
715
716 bnx2x_ets_e3b0_pbf_disabled(params);
717
718 return 0;
719}
720
721/******************************************************************************
722* Description:
723* Disable will return basicly the values to init values.
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000724*
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000725******************************************************************************/
726int bnx2x_ets_disabled(struct link_params *params,
727 struct link_vars *vars)
728{
729 struct bnx2x *bp = params->bp;
730 int bnx2x_status = 0;
731
732 if ((CHIP_IS_E2(bp)) || (CHIP_IS_E3A0(bp)))
733 bnx2x_ets_e2e3a0_disabled(params);
734 else if (CHIP_IS_E3B0(bp))
735 bnx2x_status = bnx2x_ets_e3b0_disabled(params, vars);
736 else {
737 DP(NETIF_MSG_LINK, "bnx2x_ets_disabled - chip not supported\n");
738 return -EINVAL;
739 }
740
741 return bnx2x_status;
742}
743
744/******************************************************************************
745* Description
746* Set the COS mappimg to SP and BW until this point all the COS are not
747* set as SP or BW.
748******************************************************************************/
749static int bnx2x_ets_e3b0_cli_map(const struct link_params *params,
750 const struct bnx2x_ets_params *ets_params,
751 const u8 cos_sp_bitmap,
752 const u8 cos_bw_bitmap)
753{
754 struct bnx2x *bp = params->bp;
755 const u8 port = params->port;
756 const u8 nig_cli_sp_bitmap = 0x7 | (cos_sp_bitmap << 3);
757 const u8 pbf_cli_sp_bitmap = cos_sp_bitmap;
758 const u8 nig_cli_subject2wfq_bitmap = cos_bw_bitmap << 3;
759 const u8 pbf_cli_subject2wfq_bitmap = cos_bw_bitmap;
760
761 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CLIENT_IS_STRICT :
762 NIG_REG_P0_TX_ARB_CLIENT_IS_STRICT, nig_cli_sp_bitmap);
763
764 REG_WR(bp, (port) ? PBF_REG_ETS_ARB_CLIENT_IS_STRICT_P1 :
765 PBF_REG_ETS_ARB_CLIENT_IS_STRICT_P0 , pbf_cli_sp_bitmap);
766
767 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CLIENT_IS_SUBJECT2WFQ :
768 NIG_REG_P0_TX_ARB_CLIENT_IS_SUBJECT2WFQ,
769 nig_cli_subject2wfq_bitmap);
770
771 REG_WR(bp, (port) ? PBF_REG_ETS_ARB_CLIENT_IS_SUBJECT2WFQ_P1 :
772 PBF_REG_ETS_ARB_CLIENT_IS_SUBJECT2WFQ_P0,
773 pbf_cli_subject2wfq_bitmap);
774
775 return 0;
776}
777
778/******************************************************************************
779* Description:
780* This function is needed because NIG ARB_CREDIT_WEIGHT_X are
781* not continues and ARB_CREDIT_WEIGHT_0 + offset is suitable.
782******************************************************************************/
783static int bnx2x_ets_e3b0_set_cos_bw(struct bnx2x *bp,
784 const u8 cos_entry,
785 const u32 min_w_val_nig,
786 const u32 min_w_val_pbf,
787 const u16 total_bw,
788 const u8 bw,
789 const u8 port)
790{
791 u32 nig_reg_adress_crd_weight = 0;
792 u32 pbf_reg_adress_crd_weight = 0;
David S. Miller8decf862011-09-22 03:23:13 -0400793 /* Calculate and set BW for this COS - use 1 instead of 0 for BW */
794 const u32 cos_bw_nig = ((bw ? bw : 1) * min_w_val_nig) / total_bw;
795 const u32 cos_bw_pbf = ((bw ? bw : 1) * min_w_val_pbf) / total_bw;
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000796
797 switch (cos_entry) {
798 case 0:
799 nig_reg_adress_crd_weight =
800 (port) ? NIG_REG_P1_TX_ARB_CREDIT_WEIGHT_0 :
801 NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_0;
802 pbf_reg_adress_crd_weight = (port) ?
803 PBF_REG_COS0_WEIGHT_P1 : PBF_REG_COS0_WEIGHT_P0;
804 break;
805 case 1:
806 nig_reg_adress_crd_weight = (port) ?
807 NIG_REG_P1_TX_ARB_CREDIT_WEIGHT_1 :
808 NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_1;
809 pbf_reg_adress_crd_weight = (port) ?
810 PBF_REG_COS1_WEIGHT_P1 : PBF_REG_COS1_WEIGHT_P0;
811 break;
812 case 2:
813 nig_reg_adress_crd_weight = (port) ?
814 NIG_REG_P1_TX_ARB_CREDIT_WEIGHT_2 :
815 NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_2;
816
817 pbf_reg_adress_crd_weight = (port) ?
818 PBF_REG_COS2_WEIGHT_P1 : PBF_REG_COS2_WEIGHT_P0;
819 break;
820 case 3:
821 if (port)
822 return -EINVAL;
823 nig_reg_adress_crd_weight =
824 NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_3;
825 pbf_reg_adress_crd_weight =
826 PBF_REG_COS3_WEIGHT_P0;
827 break;
828 case 4:
829 if (port)
830 return -EINVAL;
831 nig_reg_adress_crd_weight =
832 NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_4;
833 pbf_reg_adress_crd_weight = PBF_REG_COS4_WEIGHT_P0;
834 break;
835 case 5:
836 if (port)
837 return -EINVAL;
838 nig_reg_adress_crd_weight =
839 NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_5;
840 pbf_reg_adress_crd_weight = PBF_REG_COS5_WEIGHT_P0;
841 break;
842 }
843
844 REG_WR(bp, nig_reg_adress_crd_weight, cos_bw_nig);
845
846 REG_WR(bp, pbf_reg_adress_crd_weight, cos_bw_pbf);
847
848 return 0;
849}
850/******************************************************************************
851* Description:
852* Calculate the total BW.A value of 0 isn't legal.
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000853*
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000854******************************************************************************/
855static int bnx2x_ets_e3b0_get_total_bw(
856 const struct link_params *params,
Yaniv Rosner870516e12011-11-28 00:49:46 +0000857 struct bnx2x_ets_params *ets_params,
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000858 u16 *total_bw)
859{
860 struct bnx2x *bp = params->bp;
861 u8 cos_idx = 0;
Yaniv Rosner870516e12011-11-28 00:49:46 +0000862 u8 is_bw_cos_exist = 0;
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000863
864 *total_bw = 0 ;
865 /* Calculate total BW requested */
866 for (cos_idx = 0; cos_idx < ets_params->num_of_cos; cos_idx++) {
Yaniv Rosnerde0396f2011-11-28 00:49:53 +0000867 if (ets_params->cos[cos_idx].state == bnx2x_cos_state_bw) {
Yaniv Rosner870516e12011-11-28 00:49:46 +0000868 is_bw_cos_exist = 1;
869 if (!ets_params->cos[cos_idx].params.bw_params.bw) {
870 DP(NETIF_MSG_LINK, "bnx2x_ets_E3B0_config BW"
871 "was set to 0\n");
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000872 /* This is to prevent a state when ramrods
Yaniv Rosner870516e12011-11-28 00:49:46 +0000873 * can't be sent
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000874 */
Yaniv Rosner870516e12011-11-28 00:49:46 +0000875 ets_params->cos[cos_idx].params.bw_params.bw
876 = 1;
877 }
David S. Miller8decf862011-09-22 03:23:13 -0400878 *total_bw +=
879 ets_params->cos[cos_idx].params.bw_params.bw;
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000880 }
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000881 }
882
David S. Miller8decf862011-09-22 03:23:13 -0400883 /* Check total BW is valid */
Yaniv Rosnerde0396f2011-11-28 00:49:53 +0000884 if ((is_bw_cos_exist == 1) && (*total_bw != 100)) {
885 if (*total_bw == 0) {
Joe Perches94f05b02011-08-14 12:16:20 +0000886 DP(NETIF_MSG_LINK,
Yaniv Rosner2f751a82011-11-28 00:49:52 +0000887 "bnx2x_ets_E3B0_config total BW shouldn't be 0\n");
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000888 return -EINVAL;
889 }
Joe Perches94f05b02011-08-14 12:16:20 +0000890 DP(NETIF_MSG_LINK,
Yaniv Rosner2f751a82011-11-28 00:49:52 +0000891 "bnx2x_ets_E3B0_config total BW should be 100\n");
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000892 /* We can handle a case whre the BW isn't 100 this can happen
Yaniv Rosner2f751a82011-11-28 00:49:52 +0000893 * if the TC are joined.
894 */
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000895 }
896 return 0;
897}
898
899/******************************************************************************
900* Description:
901* Invalidate all the sp_pri_to_cos.
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000902*
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000903******************************************************************************/
904static void bnx2x_ets_e3b0_sp_pri_to_cos_init(u8 *sp_pri_to_cos)
905{
906 u8 pri = 0;
907 for (pri = 0; pri < DCBX_MAX_NUM_COS; pri++)
908 sp_pri_to_cos[pri] = DCBX_INVALID_COS;
909}
910/******************************************************************************
911* Description:
912* Calculate and set the SP (ARB_PRIORITY_CLIENT) NIG and PBF registers
913* according to sp_pri_to_cos.
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000914*
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000915******************************************************************************/
916static int bnx2x_ets_e3b0_sp_pri_to_cos_set(const struct link_params *params,
917 u8 *sp_pri_to_cos, const u8 pri,
918 const u8 cos_entry)
919{
920 struct bnx2x *bp = params->bp;
921 const u8 port = params->port;
922 const u8 max_num_of_cos = (port) ? DCBX_E3B0_MAX_NUM_COS_PORT1 :
923 DCBX_E3B0_MAX_NUM_COS_PORT0;
924
Dan Carpenter7e5998a2012-04-17 20:53:42 +0000925 if (pri >= max_num_of_cos) {
926 DP(NETIF_MSG_LINK, "bnx2x_ets_e3b0_sp_pri_to_cos_set invalid "
927 "parameter Illegal strict priority\n");
928 return -EINVAL;
929 }
930
Yaniv Rosnerde0396f2011-11-28 00:49:53 +0000931 if (sp_pri_to_cos[pri] != DCBX_INVALID_COS) {
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000932 DP(NETIF_MSG_LINK, "bnx2x_ets_e3b0_sp_pri_to_cos_set invalid "
Joe Perches94f05b02011-08-14 12:16:20 +0000933 "parameter There can't be two COS's with "
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000934 "the same strict pri\n");
935 return -EINVAL;
936 }
937
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000938 sp_pri_to_cos[pri] = cos_entry;
939 return 0;
940
941}
942
943/******************************************************************************
944* Description:
945* Returns the correct value according to COS and priority in
946* the sp_pri_cli register.
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000947*
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000948******************************************************************************/
949static u64 bnx2x_e3b0_sp_get_pri_cli_reg(const u8 cos, const u8 cos_offset,
950 const u8 pri_set,
951 const u8 pri_offset,
952 const u8 entry_size)
953{
954 u64 pri_cli_nig = 0;
955 pri_cli_nig = ((u64)(cos + cos_offset)) << (entry_size *
956 (pri_set + pri_offset));
957
958 return pri_cli_nig;
959}
960/******************************************************************************
961* Description:
962* Returns the correct value according to COS and priority in the
963* sp_pri_cli register for NIG.
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000964*
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000965******************************************************************************/
966static u64 bnx2x_e3b0_sp_get_pri_cli_reg_nig(const u8 cos, const u8 pri_set)
967{
968 /* MCP Dbg0 and dbg1 are always with higher strict pri*/
969 const u8 nig_cos_offset = 3;
970 const u8 nig_pri_offset = 3;
971
972 return bnx2x_e3b0_sp_get_pri_cli_reg(cos, nig_cos_offset, pri_set,
973 nig_pri_offset, 4);
974
975}
976/******************************************************************************
977* Description:
978* Returns the correct value according to COS and priority in the
979* sp_pri_cli register for PBF.
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000980*
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000981******************************************************************************/
982static u64 bnx2x_e3b0_sp_get_pri_cli_reg_pbf(const u8 cos, const u8 pri_set)
983{
984 const u8 pbf_cos_offset = 0;
985 const u8 pbf_pri_offset = 0;
986
987 return bnx2x_e3b0_sp_get_pri_cli_reg(cos, pbf_cos_offset, pri_set,
988 pbf_pri_offset, 3);
989
990}
991
992/******************************************************************************
993* Description:
994* Calculate and set the SP (ARB_PRIORITY_CLIENT) NIG and PBF registers
995* according to sp_pri_to_cos.(which COS has higher priority)
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000996*
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000997******************************************************************************/
998static int bnx2x_ets_e3b0_sp_set_pri_cli_reg(const struct link_params *params,
999 u8 *sp_pri_to_cos)
1000{
1001 struct bnx2x *bp = params->bp;
1002 u8 i = 0;
1003 const u8 port = params->port;
1004 /* MCP Dbg0 and dbg1 are always with higher strict pri*/
1005 u64 pri_cli_nig = 0x210;
1006 u32 pri_cli_pbf = 0x0;
1007 u8 pri_set = 0;
1008 u8 pri_bitmask = 0;
1009 const u8 max_num_of_cos = (port) ? DCBX_E3B0_MAX_NUM_COS_PORT1 :
1010 DCBX_E3B0_MAX_NUM_COS_PORT0;
1011
1012 u8 cos_bit_to_set = (1 << max_num_of_cos) - 1;
1013
1014 /* Set all the strict priority first */
1015 for (i = 0; i < max_num_of_cos; i++) {
Yaniv Rosnerde0396f2011-11-28 00:49:53 +00001016 if (sp_pri_to_cos[i] != DCBX_INVALID_COS) {
1017 if (sp_pri_to_cos[i] >= DCBX_MAX_NUM_COS) {
Yaniv Rosner6c3218c2011-06-14 01:34:23 +00001018 DP(NETIF_MSG_LINK,
1019 "bnx2x_ets_e3b0_sp_set_pri_cli_reg "
1020 "invalid cos entry\n");
1021 return -EINVAL;
1022 }
1023
1024 pri_cli_nig |= bnx2x_e3b0_sp_get_pri_cli_reg_nig(
1025 sp_pri_to_cos[i], pri_set);
1026
1027 pri_cli_pbf |= bnx2x_e3b0_sp_get_pri_cli_reg_pbf(
1028 sp_pri_to_cos[i], pri_set);
1029 pri_bitmask = 1 << sp_pri_to_cos[i];
1030 /* COS is used remove it from bitmap.*/
Yaniv Rosnerde0396f2011-11-28 00:49:53 +00001031 if (!(pri_bitmask & cos_bit_to_set)) {
Yaniv Rosner6c3218c2011-06-14 01:34:23 +00001032 DP(NETIF_MSG_LINK,
1033 "bnx2x_ets_e3b0_sp_set_pri_cli_reg "
1034 "invalid There can't be two COS's with"
1035 " the same strict pri\n");
1036 return -EINVAL;
1037 }
1038 cos_bit_to_set &= ~pri_bitmask;
1039 pri_set++;
1040 }
1041 }
1042
1043 /* Set all the Non strict priority i= COS*/
1044 for (i = 0; i < max_num_of_cos; i++) {
1045 pri_bitmask = 1 << i;
1046 /* Check if COS was already used for SP */
1047 if (pri_bitmask & cos_bit_to_set) {
1048 /* COS wasn't used for SP */
1049 pri_cli_nig |= bnx2x_e3b0_sp_get_pri_cli_reg_nig(
1050 i, pri_set);
1051
1052 pri_cli_pbf |= bnx2x_e3b0_sp_get_pri_cli_reg_pbf(
1053 i, pri_set);
1054 /* COS is used remove it from bitmap.*/
1055 cos_bit_to_set &= ~pri_bitmask;
1056 pri_set++;
1057 }
1058 }
1059
1060 if (pri_set != max_num_of_cos) {
1061 DP(NETIF_MSG_LINK, "bnx2x_ets_e3b0_sp_set_pri_cli_reg not all "
1062 "entries were set\n");
1063 return -EINVAL;
1064 }
1065
1066 if (port) {
1067 /* Only 6 usable clients*/
1068 REG_WR(bp, NIG_REG_P1_TX_ARB_PRIORITY_CLIENT2_LSB,
1069 (u32)pri_cli_nig);
1070
1071 REG_WR(bp, PBF_REG_ETS_ARB_PRIORITY_CLIENT_P1 , pri_cli_pbf);
1072 } else {
1073 /* Only 9 usable clients*/
1074 const u32 pri_cli_nig_lsb = (u32) (pri_cli_nig);
1075 const u32 pri_cli_nig_msb = (u32) ((pri_cli_nig >> 32) & 0xF);
1076
1077 REG_WR(bp, NIG_REG_P0_TX_ARB_PRIORITY_CLIENT2_LSB,
1078 pri_cli_nig_lsb);
1079 REG_WR(bp, NIG_REG_P0_TX_ARB_PRIORITY_CLIENT2_MSB,
1080 pri_cli_nig_msb);
1081
1082 REG_WR(bp, PBF_REG_ETS_ARB_PRIORITY_CLIENT_P0 , pri_cli_pbf);
1083 }
1084 return 0;
1085}
1086
1087/******************************************************************************
1088* Description:
1089* Configure the COS to ETS according to BW and SP settings.
1090******************************************************************************/
1091int bnx2x_ets_e3b0_config(const struct link_params *params,
1092 const struct link_vars *vars,
Yaniv Rosner870516e12011-11-28 00:49:46 +00001093 struct bnx2x_ets_params *ets_params)
Yaniv Rosner6c3218c2011-06-14 01:34:23 +00001094{
1095 struct bnx2x *bp = params->bp;
1096 int bnx2x_status = 0;
1097 const u8 port = params->port;
1098 u16 total_bw = 0;
1099 const u32 min_w_val_nig = bnx2x_ets_get_min_w_val_nig(vars);
1100 const u32 min_w_val_pbf = ETS_E3B0_PBF_MIN_W_VAL;
1101 u8 cos_bw_bitmap = 0;
1102 u8 cos_sp_bitmap = 0;
1103 u8 sp_pri_to_cos[DCBX_MAX_NUM_COS] = {0};
1104 const u8 max_num_of_cos = (port) ? DCBX_E3B0_MAX_NUM_COS_PORT1 :
1105 DCBX_E3B0_MAX_NUM_COS_PORT0;
1106 u8 cos_entry = 0;
1107
1108 if (!CHIP_IS_E3B0(bp)) {
Joe Perches94f05b02011-08-14 12:16:20 +00001109 DP(NETIF_MSG_LINK,
1110 "bnx2x_ets_e3b0_disabled the chip isn't E3B0\n");
Yaniv Rosner6c3218c2011-06-14 01:34:23 +00001111 return -EINVAL;
1112 }
1113
1114 if ((ets_params->num_of_cos > max_num_of_cos)) {
1115 DP(NETIF_MSG_LINK, "bnx2x_ets_E3B0_config the number of COS "
1116 "isn't supported\n");
1117 return -EINVAL;
1118 }
1119
1120 /* Prepare sp strict priority parameters*/
1121 bnx2x_ets_e3b0_sp_pri_to_cos_init(sp_pri_to_cos);
1122
1123 /* Prepare BW parameters*/
1124 bnx2x_status = bnx2x_ets_e3b0_get_total_bw(params, ets_params,
1125 &total_bw);
Yaniv Rosnerde0396f2011-11-28 00:49:53 +00001126 if (bnx2x_status) {
Joe Perches94f05b02011-08-14 12:16:20 +00001127 DP(NETIF_MSG_LINK,
1128 "bnx2x_ets_E3B0_config get_total_bw failed\n");
Yaniv Rosner6c3218c2011-06-14 01:34:23 +00001129 return -EINVAL;
1130 }
1131
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001132 /* Upper bound is set according to current link speed (min_w_val
Yaniv Rosner2f751a82011-11-28 00:49:52 +00001133 * should be the same for upper bound and COS credit val).
Yaniv Rosner6c3218c2011-06-14 01:34:23 +00001134 */
1135 bnx2x_ets_e3b0_set_credit_upper_bound_nig(params, min_w_val_nig);
1136 bnx2x_ets_e3b0_set_credit_upper_bound_pbf(params, min_w_val_pbf);
1137
1138
1139 for (cos_entry = 0; cos_entry < ets_params->num_of_cos; cos_entry++) {
1140 if (bnx2x_cos_state_bw == ets_params->cos[cos_entry].state) {
1141 cos_bw_bitmap |= (1 << cos_entry);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001142 /* The function also sets the BW in HW(not the mappin
Yaniv Rosner6c3218c2011-06-14 01:34:23 +00001143 * yet)
1144 */
1145 bnx2x_status = bnx2x_ets_e3b0_set_cos_bw(
1146 bp, cos_entry, min_w_val_nig, min_w_val_pbf,
1147 total_bw,
1148 ets_params->cos[cos_entry].params.bw_params.bw,
1149 port);
1150 } else if (bnx2x_cos_state_strict ==
1151 ets_params->cos[cos_entry].state){
1152 cos_sp_bitmap |= (1 << cos_entry);
1153
1154 bnx2x_status = bnx2x_ets_e3b0_sp_pri_to_cos_set(
1155 params,
1156 sp_pri_to_cos,
1157 ets_params->cos[cos_entry].params.sp_params.pri,
1158 cos_entry);
1159
1160 } else {
Joe Perches94f05b02011-08-14 12:16:20 +00001161 DP(NETIF_MSG_LINK,
1162 "bnx2x_ets_e3b0_config cos state not valid\n");
Yaniv Rosner6c3218c2011-06-14 01:34:23 +00001163 return -EINVAL;
1164 }
Yaniv Rosnerde0396f2011-11-28 00:49:53 +00001165 if (bnx2x_status) {
Joe Perches94f05b02011-08-14 12:16:20 +00001166 DP(NETIF_MSG_LINK,
1167 "bnx2x_ets_e3b0_config set cos bw failed\n");
Yaniv Rosner6c3218c2011-06-14 01:34:23 +00001168 return bnx2x_status;
1169 }
1170 }
1171
1172 /* Set SP register (which COS has higher priority) */
1173 bnx2x_status = bnx2x_ets_e3b0_sp_set_pri_cli_reg(params,
1174 sp_pri_to_cos);
1175
Yaniv Rosnerde0396f2011-11-28 00:49:53 +00001176 if (bnx2x_status) {
Joe Perches94f05b02011-08-14 12:16:20 +00001177 DP(NETIF_MSG_LINK,
1178 "bnx2x_ets_E3B0_config set_pri_cli_reg failed\n");
Yaniv Rosner6c3218c2011-06-14 01:34:23 +00001179 return bnx2x_status;
1180 }
1181
1182 /* Set client mapping of BW and strict */
1183 bnx2x_status = bnx2x_ets_e3b0_cli_map(params, ets_params,
1184 cos_sp_bitmap,
1185 cos_bw_bitmap);
1186
Yaniv Rosnerde0396f2011-11-28 00:49:53 +00001187 if (bnx2x_status) {
Yaniv Rosner6c3218c2011-06-14 01:34:23 +00001188 DP(NETIF_MSG_LINK, "bnx2x_ets_E3B0_config SP failed\n");
1189 return bnx2x_status;
1190 }
1191 return 0;
1192}
Yaniv Rosner65a001b2011-01-31 04:22:03 +00001193static void bnx2x_ets_bw_limit_common(const struct link_params *params)
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001194{
1195 /* ETS disabled configuration */
1196 struct bnx2x *bp = params->bp;
1197 DP(NETIF_MSG_LINK, "ETS enabled BW limit configuration\n");
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001198 /* Defines which entries (clients) are subjected to WFQ arbitration
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00001199 * COS0 0x8
1200 * COS1 0x10
1201 */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001202 REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_IS_SUBJECT2WFQ, 0x18);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001203 /* Mapping between the ARB_CREDIT_WEIGHT registers and actual
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00001204 * client numbers (WEIGHT_0 does not actually have to represent
1205 * client 0)
1206 * PRI4 | PRI3 | PRI2 | PRI1 | PRI0
1207 * cos1-001 cos0-000 dbg1-100 dbg0-011 MCP-010
1208 */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001209 REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_CREDIT_MAP, 0x111A);
1210
1211 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_0,
1212 ETS_BW_LIMIT_CREDIT_UPPER_BOUND);
1213 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_1,
1214 ETS_BW_LIMIT_CREDIT_UPPER_BOUND);
1215
1216 /* ETS mode enabled*/
1217 REG_WR(bp, PBF_REG_ETS_ENABLED, 1);
1218
1219 /* Defines the number of consecutive slots for the strict priority */
1220 REG_WR(bp, PBF_REG_NUM_STRICT_ARB_SLOTS, 0);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001221 /* Bitmap of 5bits length. Each bit specifies whether the entry behaves
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00001222 * as strict. Bits 0,1,2 - debug and management entries, 3 - COS0
1223 * entry, 4 - COS1 entry.
1224 * COS1 | COS0 | DEBUG21 | DEBUG0 | MGMT
1225 * bit4 bit3 bit2 bit1 bit0
1226 * MCP and debug are strict
1227 */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001228 REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_IS_STRICT, 0x7);
1229
1230 /* Upper bound that COS0_WEIGHT can reach in the WFQ arbiter.*/
1231 REG_WR(bp, PBF_REG_COS0_UPPER_BOUND,
1232 ETS_BW_LIMIT_CREDIT_UPPER_BOUND);
1233 REG_WR(bp, PBF_REG_COS1_UPPER_BOUND,
1234 ETS_BW_LIMIT_CREDIT_UPPER_BOUND);
1235}
1236
1237void bnx2x_ets_bw_limit(const struct link_params *params, const u32 cos0_bw,
1238 const u32 cos1_bw)
1239{
1240 /* ETS disabled configuration*/
1241 struct bnx2x *bp = params->bp;
1242 const u32 total_bw = cos0_bw + cos1_bw;
1243 u32 cos0_credit_weight = 0;
1244 u32 cos1_credit_weight = 0;
1245
1246 DP(NETIF_MSG_LINK, "ETS enabled BW limit configuration\n");
1247
Yaniv Rosnerde0396f2011-11-28 00:49:53 +00001248 if ((!total_bw) ||
1249 (!cos0_bw) ||
1250 (!cos1_bw)) {
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001251 DP(NETIF_MSG_LINK, "Total BW can't be zero\n");
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001252 return;
1253 }
1254
1255 cos0_credit_weight = (cos0_bw * ETS_BW_LIMIT_CREDIT_WEIGHT)/
1256 total_bw;
1257 cos1_credit_weight = (cos1_bw * ETS_BW_LIMIT_CREDIT_WEIGHT)/
1258 total_bw;
1259
1260 bnx2x_ets_bw_limit_common(params);
1261
1262 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_0, cos0_credit_weight);
1263 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_1, cos1_credit_weight);
1264
1265 REG_WR(bp, PBF_REG_COS0_WEIGHT, cos0_credit_weight);
1266 REG_WR(bp, PBF_REG_COS1_WEIGHT, cos1_credit_weight);
1267}
1268
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00001269int bnx2x_ets_strict(const struct link_params *params, const u8 strict_cos)
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001270{
1271 /* ETS disabled configuration*/
1272 struct bnx2x *bp = params->bp;
1273 u32 val = 0;
1274
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001275 DP(NETIF_MSG_LINK, "ETS enabled strict configuration\n");
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001276 /* Bitmap of 5bits length. Each bit specifies whether the entry behaves
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001277 * as strict. Bits 0,1,2 - debug and management entries,
1278 * 3 - COS0 entry, 4 - COS1 entry.
1279 * COS1 | COS0 | DEBUG21 | DEBUG0 | MGMT
1280 * bit4 bit3 bit2 bit1 bit0
1281 * MCP and debug are strict
1282 */
1283 REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_IS_STRICT, 0x1F);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001284 /* For strict priority entries defines the number of consecutive slots
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001285 * for the highest priority.
1286 */
1287 REG_WR(bp, NIG_REG_P0_TX_ARB_NUM_STRICT_ARB_SLOTS, 0x100);
1288 /* ETS mode disable */
1289 REG_WR(bp, PBF_REG_ETS_ENABLED, 0);
1290 /* Defines the number of consecutive slots for the strict priority */
1291 REG_WR(bp, PBF_REG_NUM_STRICT_ARB_SLOTS, 0x100);
1292
1293 /* Defines the number of consecutive slots for the strict priority */
1294 REG_WR(bp, PBF_REG_HIGH_PRIORITY_COS_NUM, strict_cos);
1295
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001296 /* Mapping between entry priority to client number (0,1,2 -debug and
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00001297 * management clients, 3 - COS0 client, 4 - COS client)(HIGHEST)
1298 * 3bits client num.
1299 * PRI4 | PRI3 | PRI2 | PRI1 | PRI0
1300 * dbg0-010 dbg1-001 cos1-100 cos0-011 MCP-000
1301 * dbg0-010 dbg1-001 cos0-011 cos1-100 MCP-000
1302 */
Yaniv Rosnerde0396f2011-11-28 00:49:53 +00001303 val = (!strict_cos) ? 0x2318 : 0x22E0;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001304 REG_WR(bp, NIG_REG_P0_TX_ARB_PRIORITY_CLIENT, val);
1305
1306 return 0;
1307}
Yuval Mintzc8c60d82012-06-06 17:13:07 +00001308
1309/******************************************************************/
Dmitry Kravkove8920672011-05-04 23:52:40 +00001310/* PFC section */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001311/******************************************************************/
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001312static void bnx2x_update_pfc_xmac(struct link_params *params,
1313 struct link_vars *vars,
1314 u8 is_lb)
1315{
1316 struct bnx2x *bp = params->bp;
1317 u32 xmac_base;
1318 u32 pause_val, pfc0_val, pfc1_val;
1319
1320 /* XMAC base adrr */
1321 xmac_base = (params->port) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
1322
1323 /* Initialize pause and pfc registers */
1324 pause_val = 0x18000;
1325 pfc0_val = 0xFFFF8000;
1326 pfc1_val = 0x2;
1327
1328 /* No PFC support */
1329 if (!(params->feature_config_flags &
1330 FEATURE_CONFIG_PFC_ENABLED)) {
1331
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001332 /* RX flow control - Process pause frame in receive direction
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001333 */
1334 if (vars->flow_ctrl & BNX2X_FLOW_CTRL_RX)
1335 pause_val |= XMAC_PAUSE_CTRL_REG_RX_PAUSE_EN;
1336
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001337 /* TX flow control - Send pause packet when buffer is full */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001338 if (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX)
1339 pause_val |= XMAC_PAUSE_CTRL_REG_TX_PAUSE_EN;
1340 } else {/* PFC support */
1341 pfc1_val |= XMAC_PFC_CTRL_HI_REG_PFC_REFRESH_EN |
1342 XMAC_PFC_CTRL_HI_REG_PFC_STATS_EN |
1343 XMAC_PFC_CTRL_HI_REG_RX_PFC_EN |
Yaniv Rosner27d91292012-04-04 01:28:54 +00001344 XMAC_PFC_CTRL_HI_REG_TX_PFC_EN |
1345 XMAC_PFC_CTRL_HI_REG_FORCE_PFC_XON;
1346 /* Write pause and PFC registers */
1347 REG_WR(bp, xmac_base + XMAC_REG_PAUSE_CTRL, pause_val);
1348 REG_WR(bp, xmac_base + XMAC_REG_PFC_CTRL, pfc0_val);
1349 REG_WR(bp, xmac_base + XMAC_REG_PFC_CTRL_HI, pfc1_val);
1350 pfc1_val &= ~XMAC_PFC_CTRL_HI_REG_FORCE_PFC_XON;
1351
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001352 }
1353
1354 /* Write pause and PFC registers */
1355 REG_WR(bp, xmac_base + XMAC_REG_PAUSE_CTRL, pause_val);
1356 REG_WR(bp, xmac_base + XMAC_REG_PFC_CTRL, pfc0_val);
1357 REG_WR(bp, xmac_base + XMAC_REG_PFC_CTRL_HI, pfc1_val);
1358
Yaniv Rosnerb8d6d082011-07-05 01:06:27 +00001359
1360 /* Set MAC address for source TX Pause/PFC frames */
1361 REG_WR(bp, xmac_base + XMAC_REG_CTRL_SA_LO,
1362 ((params->mac_addr[2] << 24) |
1363 (params->mac_addr[3] << 16) |
1364 (params->mac_addr[4] << 8) |
1365 (params->mac_addr[5])));
1366 REG_WR(bp, xmac_base + XMAC_REG_CTRL_SA_HI,
1367 ((params->mac_addr[0] << 8) |
1368 (params->mac_addr[1])));
1369
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001370 udelay(30);
1371}
1372
1373
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001374static void bnx2x_emac_get_pfc_stat(struct link_params *params,
1375 u32 pfc_frames_sent[2],
1376 u32 pfc_frames_received[2])
1377{
1378 /* Read pfc statistic */
1379 struct bnx2x *bp = params->bp;
1380 u32 emac_base = params->port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
1381 u32 val_xon = 0;
1382 u32 val_xoff = 0;
1383
1384 DP(NETIF_MSG_LINK, "pfc statistic read from EMAC\n");
1385
1386 /* PFC received frames */
1387 val_xoff = REG_RD(bp, emac_base +
1388 EMAC_REG_RX_PFC_STATS_XOFF_RCVD);
1389 val_xoff &= EMAC_REG_RX_PFC_STATS_XOFF_RCVD_COUNT;
1390 val_xon = REG_RD(bp, emac_base + EMAC_REG_RX_PFC_STATS_XON_RCVD);
1391 val_xon &= EMAC_REG_RX_PFC_STATS_XON_RCVD_COUNT;
1392
1393 pfc_frames_received[0] = val_xon + val_xoff;
1394
1395 /* PFC received sent */
1396 val_xoff = REG_RD(bp, emac_base +
1397 EMAC_REG_RX_PFC_STATS_XOFF_SENT);
1398 val_xoff &= EMAC_REG_RX_PFC_STATS_XOFF_SENT_COUNT;
1399 val_xon = REG_RD(bp, emac_base + EMAC_REG_RX_PFC_STATS_XON_SENT);
1400 val_xon &= EMAC_REG_RX_PFC_STATS_XON_SENT_COUNT;
1401
1402 pfc_frames_sent[0] = val_xon + val_xoff;
1403}
1404
Yaniv Rosnerb8d6d082011-07-05 01:06:27 +00001405/* Read pfc statistic*/
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001406void bnx2x_pfc_statistic(struct link_params *params, struct link_vars *vars,
1407 u32 pfc_frames_sent[2],
1408 u32 pfc_frames_received[2])
1409{
1410 /* Read pfc statistic */
1411 struct bnx2x *bp = params->bp;
Yaniv Rosnerb8d6d082011-07-05 01:06:27 +00001412
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001413 DP(NETIF_MSG_LINK, "pfc statistic\n");
1414
1415 if (!vars->link_up)
1416 return;
1417
Yaniv Rosnerde0396f2011-11-28 00:49:53 +00001418 if (vars->mac_type == MAC_TYPE_EMAC) {
Yaniv Rosnerb8d6d082011-07-05 01:06:27 +00001419 DP(NETIF_MSG_LINK, "About to read PFC stats from EMAC\n");
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001420 bnx2x_emac_get_pfc_stat(params, pfc_frames_sent,
1421 pfc_frames_received);
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001422 }
1423}
1424/******************************************************************/
1425/* MAC/PBF section */
1426/******************************************************************/
Yaniv Rosnera198c142011-05-31 21:29:42 +00001427static void bnx2x_set_mdio_clk(struct bnx2x *bp, u32 chip_id, u8 port)
1428{
1429 u32 mode, emac_base;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001430 /* Set clause 45 mode, slow down the MDIO clock to 2.5MHz
Yaniv Rosnera198c142011-05-31 21:29:42 +00001431 * (a value of 49==0x31) and make sure that the AUTO poll is off
1432 */
1433
1434 if (CHIP_IS_E2(bp))
1435 emac_base = GRCBASE_EMAC0;
1436 else
1437 emac_base = (port) ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
1438 mode = REG_RD(bp, emac_base + EMAC_REG_EMAC_MDIO_MODE);
1439 mode &= ~(EMAC_MDIO_MODE_AUTO_POLL |
1440 EMAC_MDIO_MODE_CLOCK_CNT);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00001441 if (USES_WARPCORE(bp))
1442 mode |= (74L << EMAC_MDIO_MODE_CLOCK_CNT_BITSHIFT);
1443 else
1444 mode |= (49L << EMAC_MDIO_MODE_CLOCK_CNT_BITSHIFT);
Yaniv Rosnera198c142011-05-31 21:29:42 +00001445
1446 mode |= (EMAC_MDIO_MODE_CLAUSE_45);
1447 REG_WR(bp, emac_base + EMAC_REG_EMAC_MDIO_MODE, mode);
1448
1449 udelay(40);
1450}
Yaniv Rosner2f751a82011-11-28 00:49:52 +00001451static u8 bnx2x_is_4_port_mode(struct bnx2x *bp)
1452{
1453 u32 port4mode_ovwr_val;
1454 /* Check 4-port override enabled */
1455 port4mode_ovwr_val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
1456 if (port4mode_ovwr_val & (1<<0)) {
1457 /* Return 4-port mode override value */
1458 return ((port4mode_ovwr_val & (1<<1)) == (1<<1));
1459 }
1460 /* Return 4-port mode from input pin */
1461 return (u8)REG_RD(bp, MISC_REG_PORT4MODE_EN);
1462}
Yaniv Rosnera198c142011-05-31 21:29:42 +00001463
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001464static void bnx2x_emac_init(struct link_params *params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001465 struct link_vars *vars)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001466{
1467 /* reset and unreset the emac core */
1468 struct bnx2x *bp = params->bp;
1469 u8 port = params->port;
1470 u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
1471 u32 val;
1472 u16 timeout;
1473
1474 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001475 (MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE << port));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001476 udelay(5);
1477 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001478 (MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE << port));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001479
1480 /* init emac - use read-modify-write */
1481 /* self clear reset */
1482 val = REG_RD(bp, emac_base + EMAC_REG_EMAC_MODE);
Eilon Greenstein3196a882008-08-13 15:58:49 -07001483 EMAC_WR(bp, EMAC_REG_EMAC_MODE, (val | EMAC_MODE_RESET));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001484
1485 timeout = 200;
Eilon Greenstein3196a882008-08-13 15:58:49 -07001486 do {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001487 val = REG_RD(bp, emac_base + EMAC_REG_EMAC_MODE);
1488 DP(NETIF_MSG_LINK, "EMAC reset reg is %u\n", val);
1489 if (!timeout) {
1490 DP(NETIF_MSG_LINK, "EMAC timeout!\n");
1491 return;
1492 }
1493 timeout--;
Eilon Greenstein3196a882008-08-13 15:58:49 -07001494 } while (val & EMAC_MODE_RESET);
Yaniv Rosnera198c142011-05-31 21:29:42 +00001495 bnx2x_set_mdio_clk(bp, params->chip_id, port);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001496 /* Set mac address */
1497 val = ((params->mac_addr[0] << 8) |
1498 params->mac_addr[1]);
Eilon Greenstein3196a882008-08-13 15:58:49 -07001499 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001500
1501 val = ((params->mac_addr[2] << 24) |
1502 (params->mac_addr[3] << 16) |
1503 (params->mac_addr[4] << 8) |
1504 params->mac_addr[5]);
Eilon Greenstein3196a882008-08-13 15:58:49 -07001505 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + 4, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001506}
1507
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001508static void bnx2x_set_xumac_nig(struct link_params *params,
1509 u16 tx_pause_en,
1510 u8 enable)
1511{
1512 struct bnx2x *bp = params->bp;
1513
1514 REG_WR(bp, params->port ? NIG_REG_P1_MAC_IN_EN : NIG_REG_P0_MAC_IN_EN,
1515 enable);
1516 REG_WR(bp, params->port ? NIG_REG_P1_MAC_OUT_EN : NIG_REG_P0_MAC_OUT_EN,
1517 enable);
1518 REG_WR(bp, params->port ? NIG_REG_P1_MAC_PAUSE_OUT_EN :
1519 NIG_REG_P0_MAC_PAUSE_OUT_EN, tx_pause_en);
1520}
1521
Yaniv Rosnerce7c0482011-10-27 05:09:47 +00001522static void bnx2x_umac_disable(struct link_params *params)
1523{
1524 u32 umac_base = params->port ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
1525 struct bnx2x *bp = params->bp;
1526 if (!(REG_RD(bp, MISC_REG_RESET_REG_2) &
1527 (MISC_REGISTERS_RESET_REG_2_UMAC0 << params->port)))
1528 return;
1529
1530 /* Disable RX and TX */
1531 REG_WR(bp, umac_base + UMAC_REG_COMMAND_CONFIG, 0);
1532}
1533
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001534static void bnx2x_umac_enable(struct link_params *params,
1535 struct link_vars *vars, u8 lb)
1536{
1537 u32 val;
1538 u32 umac_base = params->port ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
1539 struct bnx2x *bp = params->bp;
1540 /* Reset UMAC */
1541 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
1542 (MISC_REGISTERS_RESET_REG_2_UMAC0 << params->port));
Yuval Mintzd2310232012-06-20 19:05:19 +00001543 usleep_range(1000, 2000);
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001544
1545 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
1546 (MISC_REGISTERS_RESET_REG_2_UMAC0 << params->port));
1547
1548 DP(NETIF_MSG_LINK, "enabling UMAC\n");
1549
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001550 /* This register opens the gate for the UMAC despite its name */
1551 REG_WR(bp, NIG_REG_EGRESS_EMAC0_PORT + params->port*4, 1);
1552
1553 val = UMAC_COMMAND_CONFIG_REG_PROMIS_EN |
1554 UMAC_COMMAND_CONFIG_REG_PAD_EN |
1555 UMAC_COMMAND_CONFIG_REG_SW_RESET |
1556 UMAC_COMMAND_CONFIG_REG_NO_LGTH_CHECK;
1557 switch (vars->line_speed) {
1558 case SPEED_10:
1559 val |= (0<<2);
1560 break;
1561 case SPEED_100:
1562 val |= (1<<2);
1563 break;
1564 case SPEED_1000:
1565 val |= (2<<2);
1566 break;
1567 case SPEED_2500:
1568 val |= (3<<2);
1569 break;
1570 default:
1571 DP(NETIF_MSG_LINK, "Invalid speed for UMAC %d\n",
1572 vars->line_speed);
1573 break;
1574 }
Yaniv Rosner9d5b36b2011-08-02 22:59:10 +00001575 if (!(vars->flow_ctrl & BNX2X_FLOW_CTRL_TX))
1576 val |= UMAC_COMMAND_CONFIG_REG_IGNORE_TX_PAUSE;
1577
1578 if (!(vars->flow_ctrl & BNX2X_FLOW_CTRL_RX))
1579 val |= UMAC_COMMAND_CONFIG_REG_PAUSE_IGNORE;
1580
Mintz Yuvale18c56b2012-02-15 02:10:23 +00001581 if (vars->duplex == DUPLEX_HALF)
1582 val |= UMAC_COMMAND_CONFIG_REG_HD_ENA;
1583
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001584 REG_WR(bp, umac_base + UMAC_REG_COMMAND_CONFIG, val);
1585 udelay(50);
1586
Yaniv Rosnerb8d6d082011-07-05 01:06:27 +00001587 /* Set MAC address for source TX Pause/PFC frames (under SW reset) */
1588 REG_WR(bp, umac_base + UMAC_REG_MAC_ADDR0,
1589 ((params->mac_addr[2] << 24) |
1590 (params->mac_addr[3] << 16) |
1591 (params->mac_addr[4] << 8) |
1592 (params->mac_addr[5])));
1593 REG_WR(bp, umac_base + UMAC_REG_MAC_ADDR1,
1594 ((params->mac_addr[0] << 8) |
1595 (params->mac_addr[1])));
1596
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001597 /* Enable RX and TX */
1598 val &= ~UMAC_COMMAND_CONFIG_REG_PAD_EN;
1599 val |= UMAC_COMMAND_CONFIG_REG_TX_ENA |
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00001600 UMAC_COMMAND_CONFIG_REG_RX_ENA;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001601 REG_WR(bp, umac_base + UMAC_REG_COMMAND_CONFIG, val);
1602 udelay(50);
1603
1604 /* Remove SW Reset */
1605 val &= ~UMAC_COMMAND_CONFIG_REG_SW_RESET;
1606
1607 /* Check loopback mode */
1608 if (lb)
1609 val |= UMAC_COMMAND_CONFIG_REG_LOOP_ENA;
1610 REG_WR(bp, umac_base + UMAC_REG_COMMAND_CONFIG, val);
1611
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001612 /* Maximum Frame Length (RW). Defines a 14-Bit maximum frame
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001613 * length used by the MAC receive logic to check frames.
1614 */
1615 REG_WR(bp, umac_base + UMAC_REG_MAXFR, 0x2710);
1616 bnx2x_set_xumac_nig(params,
1617 ((vars->flow_ctrl & BNX2X_FLOW_CTRL_TX) != 0), 1);
1618 vars->mac_type = MAC_TYPE_UMAC;
1619
1620}
1621
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001622/* Define the XMAC mode */
Yaniv Rosnerce7c0482011-10-27 05:09:47 +00001623static void bnx2x_xmac_init(struct link_params *params, u32 max_speed)
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001624{
Yaniv Rosnerce7c0482011-10-27 05:09:47 +00001625 struct bnx2x *bp = params->bp;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001626 u32 is_port4mode = bnx2x_is_4_port_mode(bp);
1627
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001628 /* In 4-port mode, need to set the mode only once, so if XMAC is
Yaniv Rosner2f751a82011-11-28 00:49:52 +00001629 * already out of reset, it means the mode has already been set,
1630 * and it must not* reset the XMAC again, since it controls both
1631 * ports of the path
1632 */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001633
Yuval Mintzc3def942012-07-23 10:25:43 +03001634 if ((CHIP_NUM(bp) == CHIP_NUM_57840_4_10) &&
Yaniv Rosnerce7c0482011-10-27 05:09:47 +00001635 (REG_RD(bp, MISC_REG_RESET_REG_2) &
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001636 MISC_REGISTERS_RESET_REG_2_XMAC)) {
Joe Perches94f05b02011-08-14 12:16:20 +00001637 DP(NETIF_MSG_LINK,
1638 "XMAC already out of reset in 4-port mode\n");
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001639 return;
1640 }
1641
1642 /* Hard reset */
1643 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
1644 MISC_REGISTERS_RESET_REG_2_XMAC);
Yuval Mintzd2310232012-06-20 19:05:19 +00001645 usleep_range(1000, 2000);
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001646
1647 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
1648 MISC_REGISTERS_RESET_REG_2_XMAC);
1649 if (is_port4mode) {
1650 DP(NETIF_MSG_LINK, "Init XMAC to 2 ports x 10G per path\n");
1651
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001652 /* Set the number of ports on the system side to up to 2 */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001653 REG_WR(bp, MISC_REG_XMAC_CORE_PORT_MODE, 1);
1654
1655 /* Set the number of ports on the Warp Core to 10G */
1656 REG_WR(bp, MISC_REG_XMAC_PHY_PORT_MODE, 3);
1657 } else {
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001658 /* Set the number of ports on the system side to 1 */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001659 REG_WR(bp, MISC_REG_XMAC_CORE_PORT_MODE, 0);
1660 if (max_speed == SPEED_10000) {
Joe Perches94f05b02011-08-14 12:16:20 +00001661 DP(NETIF_MSG_LINK,
1662 "Init XMAC to 10G x 1 port per path\n");
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001663 /* Set the number of ports on the Warp Core to 10G */
1664 REG_WR(bp, MISC_REG_XMAC_PHY_PORT_MODE, 3);
1665 } else {
Joe Perches94f05b02011-08-14 12:16:20 +00001666 DP(NETIF_MSG_LINK,
1667 "Init XMAC to 20G x 2 ports per path\n");
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001668 /* Set the number of ports on the Warp Core to 20G */
1669 REG_WR(bp, MISC_REG_XMAC_PHY_PORT_MODE, 1);
1670 }
1671 }
1672 /* Soft reset */
1673 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
1674 MISC_REGISTERS_RESET_REG_2_XMAC_SOFT);
Yuval Mintzd2310232012-06-20 19:05:19 +00001675 usleep_range(1000, 2000);
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001676
1677 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
1678 MISC_REGISTERS_RESET_REG_2_XMAC_SOFT);
1679
1680}
1681
1682static void bnx2x_xmac_disable(struct link_params *params)
1683{
1684 u8 port = params->port;
1685 struct bnx2x *bp = params->bp;
Yaniv Rosnerb5077662011-08-02 22:59:18 +00001686 u32 pfc_ctrl, xmac_base = (port) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001687
1688 if (REG_RD(bp, MISC_REG_RESET_REG_2) &
1689 MISC_REGISTERS_RESET_REG_2_XMAC) {
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001690 /* Send an indication to change the state in the NIG back to XON
Yaniv Rosnerb5077662011-08-02 22:59:18 +00001691 * Clearing this bit enables the next set of this bit to get
1692 * rising edge
1693 */
1694 pfc_ctrl = REG_RD(bp, xmac_base + XMAC_REG_PFC_CTRL_HI);
1695 REG_WR(bp, xmac_base + XMAC_REG_PFC_CTRL_HI,
1696 (pfc_ctrl & ~(1<<1)));
1697 REG_WR(bp, xmac_base + XMAC_REG_PFC_CTRL_HI,
1698 (pfc_ctrl | (1<<1)));
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001699 DP(NETIF_MSG_LINK, "Disable XMAC on port %x\n", port);
1700 REG_WR(bp, xmac_base + XMAC_REG_CTRL, 0);
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001701 }
1702}
1703
1704static int bnx2x_xmac_enable(struct link_params *params,
1705 struct link_vars *vars, u8 lb)
1706{
1707 u32 val, xmac_base;
1708 struct bnx2x *bp = params->bp;
1709 DP(NETIF_MSG_LINK, "enabling XMAC\n");
1710
1711 xmac_base = (params->port) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
1712
Yaniv Rosnerce7c0482011-10-27 05:09:47 +00001713 bnx2x_xmac_init(params, vars->line_speed);
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001714
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001715 /* This register determines on which events the MAC will assert
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001716 * error on the i/f to the NIG along w/ EOP.
1717 */
1718
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001719 /* This register tells the NIG whether to send traffic to UMAC
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001720 * or XMAC
1721 */
1722 REG_WR(bp, NIG_REG_EGRESS_EMAC0_PORT + params->port*4, 0);
1723
1724 /* Set Max packet size */
1725 REG_WR(bp, xmac_base + XMAC_REG_RX_MAX_SIZE, 0x2710);
1726
1727 /* CRC append for Tx packets */
1728 REG_WR(bp, xmac_base + XMAC_REG_TX_CTRL, 0xC800);
1729
1730 /* update PFC */
1731 bnx2x_update_pfc_xmac(params, vars, 0);
1732
Yuval Mintzc8c60d82012-06-06 17:13:07 +00001733 if (vars->eee_status & SHMEM_EEE_ADV_STATUS_MASK) {
1734 DP(NETIF_MSG_LINK, "Setting XMAC for EEE\n");
1735 REG_WR(bp, xmac_base + XMAC_REG_EEE_TIMERS_HI, 0x1380008);
1736 REG_WR(bp, xmac_base + XMAC_REG_EEE_CTRL, 0x1);
1737 } else {
1738 REG_WR(bp, xmac_base + XMAC_REG_EEE_CTRL, 0x0);
1739 }
1740
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001741 /* Enable TX and RX */
1742 val = XMAC_CTRL_REG_TX_EN | XMAC_CTRL_REG_RX_EN;
1743
1744 /* Check loopback mode */
1745 if (lb)
David S. Miller8decf862011-09-22 03:23:13 -04001746 val |= XMAC_CTRL_REG_LINE_LOCAL_LPBK;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001747 REG_WR(bp, xmac_base + XMAC_REG_CTRL, val);
1748 bnx2x_set_xumac_nig(params,
1749 ((vars->flow_ctrl & BNX2X_FLOW_CTRL_TX) != 0), 1);
1750
1751 vars->mac_type = MAC_TYPE_XMAC;
1752
1753 return 0;
1754}
Yaniv Rosner2f751a82011-11-28 00:49:52 +00001755
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00001756static int bnx2x_emac_enable(struct link_params *params,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00001757 struct link_vars *vars, u8 lb)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001758{
1759 struct bnx2x *bp = params->bp;
1760 u8 port = params->port;
1761 u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
1762 u32 val;
1763
1764 DP(NETIF_MSG_LINK, "enabling EMAC\n");
1765
Yaniv Rosnerde6f3372011-08-02 22:59:25 +00001766 /* Disable BMAC */
1767 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
1768 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port));
1769
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001770 /* enable emac and not bmac */
1771 REG_WR(bp, NIG_REG_EGRESS_EMAC0_PORT + port*4, 1);
1772
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001773 /* ASIC */
1774 if (vars->phy_flags & PHY_XGXS_FLAG) {
1775 u32 ser_lane = ((params->lane_config &
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001776 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_MASK) >>
1777 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_SHIFT);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001778
1779 DP(NETIF_MSG_LINK, "XGXS\n");
1780 /* select the master lanes (out of 0-3) */
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001781 REG_WR(bp, NIG_REG_XGXS_LANE_SEL_P0 + port*4, ser_lane);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001782 /* select XGXS */
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001783 REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001784
1785 } else { /* SerDes */
1786 DP(NETIF_MSG_LINK, "SerDes\n");
1787 /* select SerDes */
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001788 REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001789 }
1790
Eilon Greenstein811a2f22009-02-12 08:37:04 +00001791 bnx2x_bits_en(bp, emac_base + EMAC_REG_EMAC_RX_MODE,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001792 EMAC_RX_MODE_RESET);
Eilon Greenstein811a2f22009-02-12 08:37:04 +00001793 bnx2x_bits_en(bp, emac_base + EMAC_REG_EMAC_TX_MODE,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001794 EMAC_TX_MODE_RESET);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001795
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001796 /* pause enable/disable */
1797 bnx2x_bits_dis(bp, emac_base + EMAC_REG_EMAC_RX_MODE,
1798 EMAC_RX_MODE_FLOW_EN);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001799
1800 bnx2x_bits_dis(bp, emac_base + EMAC_REG_EMAC_TX_MODE,
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001801 (EMAC_TX_MODE_EXT_PAUSE_EN |
1802 EMAC_TX_MODE_FLOW_EN));
1803 if (!(params->feature_config_flags &
1804 FEATURE_CONFIG_PFC_ENABLED)) {
1805 if (vars->flow_ctrl & BNX2X_FLOW_CTRL_RX)
1806 bnx2x_bits_en(bp, emac_base +
1807 EMAC_REG_EMAC_RX_MODE,
1808 EMAC_RX_MODE_FLOW_EN);
1809
1810 if (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX)
1811 bnx2x_bits_en(bp, emac_base +
1812 EMAC_REG_EMAC_TX_MODE,
1813 (EMAC_TX_MODE_EXT_PAUSE_EN |
1814 EMAC_TX_MODE_FLOW_EN));
1815 } else
1816 bnx2x_bits_en(bp, emac_base + EMAC_REG_EMAC_TX_MODE,
1817 EMAC_TX_MODE_FLOW_EN);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001818
1819 /* KEEP_VLAN_TAG, promiscuous */
1820 val = REG_RD(bp, emac_base + EMAC_REG_EMAC_RX_MODE);
1821 val |= EMAC_RX_MODE_KEEP_VLAN_TAG | EMAC_RX_MODE_PROMISCUOUS;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001822
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001823 /* Setting this bit causes MAC control frames (except for pause
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00001824 * frames) to be passed on for processing. This setting has no
1825 * affect on the operation of the pause frames. This bit effects
1826 * all packets regardless of RX Parser packet sorting logic.
1827 * Turn the PFC off to make sure we are in Xon state before
1828 * enabling it.
1829 */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001830 EMAC_WR(bp, EMAC_REG_RX_PFC_MODE, 0);
1831 if (params->feature_config_flags & FEATURE_CONFIG_PFC_ENABLED) {
1832 DP(NETIF_MSG_LINK, "PFC is enabled\n");
1833 /* Enable PFC again */
1834 EMAC_WR(bp, EMAC_REG_RX_PFC_MODE,
1835 EMAC_REG_RX_PFC_MODE_RX_EN |
1836 EMAC_REG_RX_PFC_MODE_TX_EN |
1837 EMAC_REG_RX_PFC_MODE_PRIORITIES);
1838
1839 EMAC_WR(bp, EMAC_REG_RX_PFC_PARAM,
1840 ((0x0101 <<
1841 EMAC_REG_RX_PFC_PARAM_OPCODE_BITSHIFT) |
1842 (0x00ff <<
1843 EMAC_REG_RX_PFC_PARAM_PRIORITY_EN_BITSHIFT)));
1844 val |= EMAC_RX_MODE_KEEP_MAC_CONTROL;
1845 }
Eilon Greenstein3196a882008-08-13 15:58:49 -07001846 EMAC_WR(bp, EMAC_REG_EMAC_RX_MODE, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001847
1848 /* Set Loopback */
1849 val = REG_RD(bp, emac_base + EMAC_REG_EMAC_MODE);
1850 if (lb)
1851 val |= 0x810;
1852 else
1853 val &= ~0x810;
Eilon Greenstein3196a882008-08-13 15:58:49 -07001854 EMAC_WR(bp, EMAC_REG_EMAC_MODE, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001855
Yuval Mintzd2310232012-06-20 19:05:19 +00001856 /* Enable emac */
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00001857 REG_WR(bp, NIG_REG_NIG_EMAC0_EN + port*4, 1);
1858
Yuval Mintzd2310232012-06-20 19:05:19 +00001859 /* Enable emac for jumbo packets */
Eilon Greenstein3196a882008-08-13 15:58:49 -07001860 EMAC_WR(bp, EMAC_REG_EMAC_RX_MTU_SIZE,
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001861 (EMAC_RX_MTU_SIZE_JUMBO_ENA |
1862 (ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD)));
1863
Yuval Mintzd2310232012-06-20 19:05:19 +00001864 /* Strip CRC */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001865 REG_WR(bp, NIG_REG_NIG_INGRESS_EMAC0_NO_CRC + port*4, 0x1);
1866
Yuval Mintzd2310232012-06-20 19:05:19 +00001867 /* Disable the NIG in/out to the bmac */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001868 REG_WR(bp, NIG_REG_BMAC0_IN_EN + port*4, 0x0);
1869 REG_WR(bp, NIG_REG_BMAC0_PAUSE_OUT_EN + port*4, 0x0);
1870 REG_WR(bp, NIG_REG_BMAC0_OUT_EN + port*4, 0x0);
1871
Yuval Mintzd2310232012-06-20 19:05:19 +00001872 /* Enable the NIG in/out to the emac */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001873 REG_WR(bp, NIG_REG_EMAC0_IN_EN + port*4, 0x1);
1874 val = 0;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001875 if ((params->feature_config_flags &
1876 FEATURE_CONFIG_PFC_ENABLED) ||
1877 (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX))
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001878 val = 1;
1879
1880 REG_WR(bp, NIG_REG_EMAC0_PAUSE_OUT_EN + port*4, val);
1881 REG_WR(bp, NIG_REG_EGRESS_EMAC0_OUT_EN + port*4, 0x1);
1882
Yaniv Rosner02a23162011-01-31 04:22:53 +00001883 REG_WR(bp, NIG_REG_BMAC0_REGS_OUT_EN + port*4, 0x0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001884
1885 vars->mac_type = MAC_TYPE_EMAC;
1886 return 0;
1887}
1888
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001889static void bnx2x_update_pfc_bmac1(struct link_params *params,
1890 struct link_vars *vars)
1891{
1892 u32 wb_data[2];
1893 struct bnx2x *bp = params->bp;
1894 u32 bmac_addr = params->port ? NIG_REG_INGRESS_BMAC1_MEM :
1895 NIG_REG_INGRESS_BMAC0_MEM;
1896
1897 u32 val = 0x14;
1898 if ((!(params->feature_config_flags &
1899 FEATURE_CONFIG_PFC_ENABLED)) &&
1900 (vars->flow_ctrl & BNX2X_FLOW_CTRL_RX))
1901 /* Enable BigMAC to react on received Pause packets */
1902 val |= (1<<5);
1903 wb_data[0] = val;
1904 wb_data[1] = 0;
1905 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_RX_CONTROL, wb_data, 2);
1906
Yuval Mintzd2310232012-06-20 19:05:19 +00001907 /* TX control */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001908 val = 0xc0;
1909 if (!(params->feature_config_flags &
1910 FEATURE_CONFIG_PFC_ENABLED) &&
1911 (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX))
1912 val |= 0x800000;
1913 wb_data[0] = val;
1914 wb_data[1] = 0;
1915 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_TX_CONTROL, wb_data, 2);
1916}
1917
1918static void bnx2x_update_pfc_bmac2(struct link_params *params,
1919 struct link_vars *vars,
1920 u8 is_lb)
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001921{
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001922 /* Set rx control: Strip CRC and enable BigMAC to relay
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001923 * control packets to the system as well
1924 */
1925 u32 wb_data[2];
1926 struct bnx2x *bp = params->bp;
1927 u32 bmac_addr = params->port ? NIG_REG_INGRESS_BMAC1_MEM :
1928 NIG_REG_INGRESS_BMAC0_MEM;
1929 u32 val = 0x14;
1930
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001931 if ((!(params->feature_config_flags &
1932 FEATURE_CONFIG_PFC_ENABLED)) &&
1933 (vars->flow_ctrl & BNX2X_FLOW_CTRL_RX))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001934 /* Enable BigMAC to react on received Pause packets */
1935 val |= (1<<5);
1936 wb_data[0] = val;
1937 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001938 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_RX_CONTROL, wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001939 udelay(30);
1940
1941 /* Tx control */
1942 val = 0xc0;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001943 if (!(params->feature_config_flags &
1944 FEATURE_CONFIG_PFC_ENABLED) &&
1945 (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001946 val |= 0x800000;
1947 wb_data[0] = val;
1948 wb_data[1] = 0;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001949 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_TX_CONTROL, wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001950
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001951 if (params->feature_config_flags & FEATURE_CONFIG_PFC_ENABLED) {
1952 DP(NETIF_MSG_LINK, "PFC is enabled\n");
1953 /* Enable PFC RX & TX & STATS and set 8 COS */
1954 wb_data[0] = 0x0;
1955 wb_data[0] |= (1<<0); /* RX */
1956 wb_data[0] |= (1<<1); /* TX */
1957 wb_data[0] |= (1<<2); /* Force initial Xon */
1958 wb_data[0] |= (1<<3); /* 8 cos */
1959 wb_data[0] |= (1<<5); /* STATS */
1960 wb_data[1] = 0;
1961 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_PFC_CONTROL,
1962 wb_data, 2);
1963 /* Clear the force Xon */
1964 wb_data[0] &= ~(1<<2);
1965 } else {
1966 DP(NETIF_MSG_LINK, "PFC is disabled\n");
Yuval Mintzd2310232012-06-20 19:05:19 +00001967 /* Disable PFC RX & TX & STATS and set 8 COS */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001968 wb_data[0] = 0x8;
1969 wb_data[1] = 0;
1970 }
1971
1972 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_PFC_CONTROL, wb_data, 2);
1973
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001974 /* Set Time (based unit is 512 bit time) between automatic
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00001975 * re-sending of PP packets amd enable automatic re-send of
1976 * Per-Priroity Packet as long as pp_gen is asserted and
1977 * pp_disable is low.
1978 */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001979 val = 0x8000;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001980 if (params->feature_config_flags & FEATURE_CONFIG_PFC_ENABLED)
1981 val |= (1<<16); /* enable automatic re-send */
1982
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001983 wb_data[0] = val;
1984 wb_data[1] = 0;
1985 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_TX_PAUSE_CONTROL,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001986 wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001987
1988 /* mac control */
1989 val = 0x3; /* Enable RX and TX */
1990 if (is_lb) {
1991 val |= 0x4; /* Local loopback */
1992 DP(NETIF_MSG_LINK, "enable bmac loopback\n");
1993 }
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001994 /* When PFC enabled, Pass pause frames towards the NIG. */
1995 if (params->feature_config_flags & FEATURE_CONFIG_PFC_ENABLED)
1996 val |= ((1<<6)|(1<<5));
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001997
1998 wb_data[0] = val;
1999 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002000 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_BMAC_CONTROL, wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002001}
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002002
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002003/* PFC BRB internal port configuration params */
2004struct bnx2x_pfc_brb_threshold_val {
2005 u32 pause_xoff;
2006 u32 pause_xon;
2007 u32 full_xoff;
2008 u32 full_xon;
2009};
2010
2011struct bnx2x_pfc_brb_e3b0_val {
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002012 u32 per_class_guaranty_mode;
2013 u32 lb_guarantied_hyst;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002014 u32 full_lb_xoff_th;
2015 u32 full_lb_xon_threshold;
2016 u32 lb_guarantied;
2017 u32 mac_0_class_t_guarantied;
2018 u32 mac_0_class_t_guarantied_hyst;
2019 u32 mac_1_class_t_guarantied;
2020 u32 mac_1_class_t_guarantied_hyst;
2021};
2022
2023struct bnx2x_pfc_brb_th_val {
2024 struct bnx2x_pfc_brb_threshold_val pauseable_th;
2025 struct bnx2x_pfc_brb_threshold_val non_pauseable_th;
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002026 struct bnx2x_pfc_brb_threshold_val default_class0;
2027 struct bnx2x_pfc_brb_threshold_val default_class1;
2028
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002029};
2030static int bnx2x_pfc_brb_get_config_params(
2031 struct link_params *params,
2032 struct bnx2x_pfc_brb_th_val *config_val)
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002033{
2034 struct bnx2x *bp = params->bp;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002035 DP(NETIF_MSG_LINK, "Setting PFC BRB configuration\n");
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002036
2037 config_val->default_class1.pause_xoff = 0;
2038 config_val->default_class1.pause_xon = 0;
2039 config_val->default_class1.full_xoff = 0;
2040 config_val->default_class1.full_xon = 0;
2041
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002042 if (CHIP_IS_E2(bp)) {
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002043 /* Class0 defaults */
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002044 config_val->default_class0.pause_xoff =
2045 DEFAULT0_E2_BRB_MAC_PAUSE_XOFF_THR;
2046 config_val->default_class0.pause_xon =
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002047 DEFAULT0_E2_BRB_MAC_PAUSE_XON_THR;
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002048 config_val->default_class0.full_xoff =
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002049 DEFAULT0_E2_BRB_MAC_FULL_XOFF_THR;
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002050 config_val->default_class0.full_xon =
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002051 DEFAULT0_E2_BRB_MAC_FULL_XON_THR;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002052 /* Pause able*/
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002053 config_val->pauseable_th.pause_xoff =
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002054 PFC_E2_BRB_MAC_PAUSE_XOFF_THR_PAUSE;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002055 config_val->pauseable_th.pause_xon =
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002056 PFC_E2_BRB_MAC_PAUSE_XON_THR_PAUSE;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002057 config_val->pauseable_th.full_xoff =
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002058 PFC_E2_BRB_MAC_FULL_XOFF_THR_PAUSE;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002059 config_val->pauseable_th.full_xon =
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002060 PFC_E2_BRB_MAC_FULL_XON_THR_PAUSE;
Yuval Mintzd2310232012-06-20 19:05:19 +00002061 /* Non pause able*/
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002062 config_val->non_pauseable_th.pause_xoff =
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002063 PFC_E2_BRB_MAC_PAUSE_XOFF_THR_NON_PAUSE;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002064 config_val->non_pauseable_th.pause_xon =
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002065 PFC_E2_BRB_MAC_PAUSE_XON_THR_NON_PAUSE;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002066 config_val->non_pauseable_th.full_xoff =
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002067 PFC_E2_BRB_MAC_FULL_XOFF_THR_NON_PAUSE;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002068 config_val->non_pauseable_th.full_xon =
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002069 PFC_E2_BRB_MAC_FULL_XON_THR_NON_PAUSE;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002070 } else if (CHIP_IS_E3A0(bp)) {
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002071 /* Class0 defaults */
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002072 config_val->default_class0.pause_xoff =
2073 DEFAULT0_E3A0_BRB_MAC_PAUSE_XOFF_THR;
2074 config_val->default_class0.pause_xon =
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002075 DEFAULT0_E3A0_BRB_MAC_PAUSE_XON_THR;
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002076 config_val->default_class0.full_xoff =
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002077 DEFAULT0_E3A0_BRB_MAC_FULL_XOFF_THR;
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002078 config_val->default_class0.full_xon =
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002079 DEFAULT0_E3A0_BRB_MAC_FULL_XON_THR;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002080 /* Pause able */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002081 config_val->pauseable_th.pause_xoff =
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002082 PFC_E3A0_BRB_MAC_PAUSE_XOFF_THR_PAUSE;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002083 config_val->pauseable_th.pause_xon =
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002084 PFC_E3A0_BRB_MAC_PAUSE_XON_THR_PAUSE;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002085 config_val->pauseable_th.full_xoff =
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002086 PFC_E3A0_BRB_MAC_FULL_XOFF_THR_PAUSE;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002087 config_val->pauseable_th.full_xon =
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002088 PFC_E3A0_BRB_MAC_FULL_XON_THR_PAUSE;
Yuval Mintzd2310232012-06-20 19:05:19 +00002089 /* Non pause able*/
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002090 config_val->non_pauseable_th.pause_xoff =
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002091 PFC_E3A0_BRB_MAC_PAUSE_XOFF_THR_NON_PAUSE;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002092 config_val->non_pauseable_th.pause_xon =
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002093 PFC_E3A0_BRB_MAC_PAUSE_XON_THR_NON_PAUSE;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002094 config_val->non_pauseable_th.full_xoff =
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002095 PFC_E3A0_BRB_MAC_FULL_XOFF_THR_NON_PAUSE;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002096 config_val->non_pauseable_th.full_xon =
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002097 PFC_E3A0_BRB_MAC_FULL_XON_THR_NON_PAUSE;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002098 } else if (CHIP_IS_E3B0(bp)) {
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002099 /* Class0 defaults */
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002100 config_val->default_class0.pause_xoff =
2101 DEFAULT0_E3B0_BRB_MAC_PAUSE_XOFF_THR;
2102 config_val->default_class0.pause_xon =
2103 DEFAULT0_E3B0_BRB_MAC_PAUSE_XON_THR;
2104 config_val->default_class0.full_xoff =
2105 DEFAULT0_E3B0_BRB_MAC_FULL_XOFF_THR;
2106 config_val->default_class0.full_xon =
2107 DEFAULT0_E3B0_BRB_MAC_FULL_XON_THR;
2108
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002109 if (params->phy[INT_PHY].flags &
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002110 FLAGS_4_PORT_MODE) {
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002111 config_val->pauseable_th.pause_xoff =
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002112 PFC_E3B0_4P_BRB_MAC_PAUSE_XOFF_THR_PAUSE;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002113 config_val->pauseable_th.pause_xon =
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002114 PFC_E3B0_4P_BRB_MAC_PAUSE_XON_THR_PAUSE;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002115 config_val->pauseable_th.full_xoff =
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002116 PFC_E3B0_4P_BRB_MAC_FULL_XOFF_THR_PAUSE;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002117 config_val->pauseable_th.full_xon =
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002118 PFC_E3B0_4P_BRB_MAC_FULL_XON_THR_PAUSE;
Yuval Mintzd2310232012-06-20 19:05:19 +00002119 /* Non pause able*/
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002120 config_val->non_pauseable_th.pause_xoff =
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002121 PFC_E3B0_4P_BRB_MAC_PAUSE_XOFF_THR_NON_PAUSE;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002122 config_val->non_pauseable_th.pause_xon =
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002123 PFC_E3B0_4P_BRB_MAC_PAUSE_XON_THR_NON_PAUSE;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002124 config_val->non_pauseable_th.full_xoff =
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002125 PFC_E3B0_4P_BRB_MAC_FULL_XOFF_THR_NON_PAUSE;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002126 config_val->non_pauseable_th.full_xon =
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002127 PFC_E3B0_4P_BRB_MAC_FULL_XON_THR_NON_PAUSE;
2128 } else {
2129 config_val->pauseable_th.pause_xoff =
2130 PFC_E3B0_2P_BRB_MAC_PAUSE_XOFF_THR_PAUSE;
2131 config_val->pauseable_th.pause_xon =
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002132 PFC_E3B0_2P_BRB_MAC_PAUSE_XON_THR_PAUSE;
2133 config_val->pauseable_th.full_xoff =
2134 PFC_E3B0_2P_BRB_MAC_FULL_XOFF_THR_PAUSE;
2135 config_val->pauseable_th.full_xon =
2136 PFC_E3B0_2P_BRB_MAC_FULL_XON_THR_PAUSE;
Yuval Mintzd2310232012-06-20 19:05:19 +00002137 /* Non pause able*/
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002138 config_val->non_pauseable_th.pause_xoff =
2139 PFC_E3B0_2P_BRB_MAC_PAUSE_XOFF_THR_NON_PAUSE;
2140 config_val->non_pauseable_th.pause_xon =
2141 PFC_E3B0_2P_BRB_MAC_PAUSE_XON_THR_NON_PAUSE;
2142 config_val->non_pauseable_th.full_xoff =
2143 PFC_E3B0_2P_BRB_MAC_FULL_XOFF_THR_NON_PAUSE;
2144 config_val->non_pauseable_th.full_xon =
2145 PFC_E3B0_2P_BRB_MAC_FULL_XON_THR_NON_PAUSE;
2146 }
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002147 } else
2148 return -EINVAL;
2149
2150 return 0;
2151}
2152
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002153static void bnx2x_pfc_brb_get_e3b0_config_params(
2154 struct link_params *params,
2155 struct bnx2x_pfc_brb_e3b0_val
2156 *e3b0_val,
2157 struct bnx2x_nig_brb_pfc_port_params *pfc_params,
2158 const u8 pfc_enabled)
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002159{
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002160 if (pfc_enabled && pfc_params) {
2161 e3b0_val->per_class_guaranty_mode = 1;
2162 e3b0_val->lb_guarantied_hyst = 80;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002163
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002164 if (params->phy[INT_PHY].flags &
2165 FLAGS_4_PORT_MODE) {
2166 e3b0_val->full_lb_xoff_th =
2167 PFC_E3B0_4P_BRB_FULL_LB_XOFF_THR;
2168 e3b0_val->full_lb_xon_threshold =
2169 PFC_E3B0_4P_BRB_FULL_LB_XON_THR;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002170 e3b0_val->lb_guarantied =
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002171 PFC_E3B0_4P_LB_GUART;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002172 e3b0_val->mac_0_class_t_guarantied =
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002173 PFC_E3B0_4P_BRB_MAC_0_CLASS_T_GUART;
2174 e3b0_val->mac_0_class_t_guarantied_hyst =
2175 PFC_E3B0_4P_BRB_MAC_0_CLASS_T_GUART_HYST;
2176 e3b0_val->mac_1_class_t_guarantied =
2177 PFC_E3B0_4P_BRB_MAC_1_CLASS_T_GUART;
2178 e3b0_val->mac_1_class_t_guarantied_hyst =
2179 PFC_E3B0_4P_BRB_MAC_1_CLASS_T_GUART_HYST;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002180 } else {
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002181 e3b0_val->full_lb_xoff_th =
2182 PFC_E3B0_2P_BRB_FULL_LB_XOFF_THR;
2183 e3b0_val->full_lb_xon_threshold =
2184 PFC_E3B0_2P_BRB_FULL_LB_XON_THR;
2185 e3b0_val->mac_0_class_t_guarantied_hyst =
2186 PFC_E3B0_2P_BRB_MAC_0_CLASS_T_GUART_HYST;
2187 e3b0_val->mac_1_class_t_guarantied =
2188 PFC_E3B0_2P_BRB_MAC_1_CLASS_T_GUART;
2189 e3b0_val->mac_1_class_t_guarantied_hyst =
2190 PFC_E3B0_2P_BRB_MAC_1_CLASS_T_GUART_HYST;
2191
2192 if (pfc_params->cos0_pauseable !=
2193 pfc_params->cos1_pauseable) {
Yuval Mintzd2310232012-06-20 19:05:19 +00002194 /* Nonpauseable= Lossy + pauseable = Lossless*/
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002195 e3b0_val->lb_guarantied =
2196 PFC_E3B0_2P_MIX_PAUSE_LB_GUART;
2197 e3b0_val->mac_0_class_t_guarantied =
2198 PFC_E3B0_2P_MIX_PAUSE_MAC_0_CLASS_T_GUART;
2199 } else if (pfc_params->cos0_pauseable) {
2200 /* Lossless +Lossless*/
2201 e3b0_val->lb_guarantied =
2202 PFC_E3B0_2P_PAUSE_LB_GUART;
2203 e3b0_val->mac_0_class_t_guarantied =
2204 PFC_E3B0_2P_PAUSE_MAC_0_CLASS_T_GUART;
2205 } else {
2206 /* Lossy +Lossy*/
2207 e3b0_val->lb_guarantied =
2208 PFC_E3B0_2P_NON_PAUSE_LB_GUART;
2209 e3b0_val->mac_0_class_t_guarantied =
2210 PFC_E3B0_2P_NON_PAUSE_MAC_0_CLASS_T_GUART;
2211 }
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002212 }
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002213 } else {
2214 e3b0_val->per_class_guaranty_mode = 0;
2215 e3b0_val->lb_guarantied_hyst = 0;
2216 e3b0_val->full_lb_xoff_th =
2217 DEFAULT_E3B0_BRB_FULL_LB_XOFF_THR;
2218 e3b0_val->full_lb_xon_threshold =
2219 DEFAULT_E3B0_BRB_FULL_LB_XON_THR;
2220 e3b0_val->lb_guarantied =
2221 DEFAULT_E3B0_LB_GUART;
2222 e3b0_val->mac_0_class_t_guarantied =
2223 DEFAULT_E3B0_BRB_MAC_0_CLASS_T_GUART;
2224 e3b0_val->mac_0_class_t_guarantied_hyst =
2225 DEFAULT_E3B0_BRB_MAC_0_CLASS_T_GUART_HYST;
2226 e3b0_val->mac_1_class_t_guarantied =
2227 DEFAULT_E3B0_BRB_MAC_1_CLASS_T_GUART;
2228 e3b0_val->mac_1_class_t_guarantied_hyst =
2229 DEFAULT_E3B0_BRB_MAC_1_CLASS_T_GUART_HYST;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002230 }
2231}
2232static int bnx2x_update_pfc_brb(struct link_params *params,
2233 struct link_vars *vars,
2234 struct bnx2x_nig_brb_pfc_port_params
2235 *pfc_params)
2236{
2237 struct bnx2x *bp = params->bp;
2238 struct bnx2x_pfc_brb_th_val config_val = { {0} };
2239 struct bnx2x_pfc_brb_threshold_val *reg_th_config =
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002240 &config_val.pauseable_th;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002241 struct bnx2x_pfc_brb_e3b0_val e3b0_val = {0};
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002242 const int set_pfc = params->feature_config_flags &
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002243 FEATURE_CONFIG_PFC_ENABLED;
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002244 const u8 pfc_enabled = (set_pfc && pfc_params);
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002245 int bnx2x_status = 0;
2246 u8 port = params->port;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002247
2248 /* default - pause configuration */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002249 reg_th_config = &config_val.pauseable_th;
2250 bnx2x_status = bnx2x_pfc_brb_get_config_params(params, &config_val);
Yaniv Rosnerde0396f2011-11-28 00:49:53 +00002251 if (bnx2x_status)
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002252 return bnx2x_status;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002253
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002254 if (pfc_enabled) {
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002255 /* First COS */
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002256 if (pfc_params->cos0_pauseable)
2257 reg_th_config = &config_val.pauseable_th;
2258 else
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002259 reg_th_config = &config_val.non_pauseable_th;
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002260 } else
2261 reg_th_config = &config_val.default_class0;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002262 /* The number of free blocks below which the pause signal to class 0
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002263 * of MAC #n is asserted. n=0,1
2264 */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002265 REG_WR(bp, (port) ? BRB1_REG_PAUSE_0_XOFF_THRESHOLD_1 :
2266 BRB1_REG_PAUSE_0_XOFF_THRESHOLD_0 ,
2267 reg_th_config->pause_xoff);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002268 /* The number of free blocks above which the pause signal to class 0
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002269 * of MAC #n is de-asserted. n=0,1
2270 */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002271 REG_WR(bp, (port) ? BRB1_REG_PAUSE_0_XON_THRESHOLD_1 :
2272 BRB1_REG_PAUSE_0_XON_THRESHOLD_0 , reg_th_config->pause_xon);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002273 /* The number of free blocks below which the full signal to class 0
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002274 * of MAC #n is asserted. n=0,1
2275 */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002276 REG_WR(bp, (port) ? BRB1_REG_FULL_0_XOFF_THRESHOLD_1 :
2277 BRB1_REG_FULL_0_XOFF_THRESHOLD_0 , reg_th_config->full_xoff);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002278 /* The number of free blocks above which the full signal to class 0
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002279 * of MAC #n is de-asserted. n=0,1
2280 */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002281 REG_WR(bp, (port) ? BRB1_REG_FULL_0_XON_THRESHOLD_1 :
2282 BRB1_REG_FULL_0_XON_THRESHOLD_0 , reg_th_config->full_xon);
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002283
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002284 if (pfc_enabled) {
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002285 /* Second COS */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002286 if (pfc_params->cos1_pauseable)
2287 reg_th_config = &config_val.pauseable_th;
2288 else
2289 reg_th_config = &config_val.non_pauseable_th;
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002290 } else
2291 reg_th_config = &config_val.default_class1;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002292 /* The number of free blocks below which the pause signal to
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002293 * class 1 of MAC #n is asserted. n=0,1
2294 */
2295 REG_WR(bp, (port) ? BRB1_REG_PAUSE_1_XOFF_THRESHOLD_1 :
2296 BRB1_REG_PAUSE_1_XOFF_THRESHOLD_0,
2297 reg_th_config->pause_xoff);
2298
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002299 /* The number of free blocks above which the pause signal to
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002300 * class 1 of MAC #n is de-asserted. n=0,1
2301 */
2302 REG_WR(bp, (port) ? BRB1_REG_PAUSE_1_XON_THRESHOLD_1 :
2303 BRB1_REG_PAUSE_1_XON_THRESHOLD_0,
2304 reg_th_config->pause_xon);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002305 /* The number of free blocks below which the full signal to
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002306 * class 1 of MAC #n is asserted. n=0,1
2307 */
2308 REG_WR(bp, (port) ? BRB1_REG_FULL_1_XOFF_THRESHOLD_1 :
2309 BRB1_REG_FULL_1_XOFF_THRESHOLD_0,
2310 reg_th_config->full_xoff);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002311 /* The number of free blocks above which the full signal to
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002312 * class 1 of MAC #n is de-asserted. n=0,1
2313 */
2314 REG_WR(bp, (port) ? BRB1_REG_FULL_1_XON_THRESHOLD_1 :
2315 BRB1_REG_FULL_1_XON_THRESHOLD_0,
2316 reg_th_config->full_xon);
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002317
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002318 if (CHIP_IS_E3B0(bp)) {
2319 bnx2x_pfc_brb_get_e3b0_config_params(
2320 params,
2321 &e3b0_val,
2322 pfc_params,
2323 pfc_enabled);
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002324
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002325 REG_WR(bp, BRB1_REG_PER_CLASS_GUARANTY_MODE,
2326 e3b0_val.per_class_guaranty_mode);
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002327
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002328 /* The hysteresis on the guarantied buffer space for the Lb
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002329 * port before signaling XON.
2330 */
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002331 REG_WR(bp, BRB1_REG_LB_GUARANTIED_HYST,
2332 e3b0_val.lb_guarantied_hyst);
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002333
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002334 /* The number of free blocks below which the full signal to the
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002335 * LB port is asserted.
2336 */
Yaniv Rosner866ceda2011-11-28 00:49:45 +00002337 REG_WR(bp, BRB1_REG_FULL_LB_XOFF_THRESHOLD,
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002338 e3b0_val.full_lb_xoff_th);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002339 /* The number of free blocks above which the full signal to the
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002340 * LB port is de-asserted.
2341 */
2342 REG_WR(bp, BRB1_REG_FULL_LB_XON_THRESHOLD,
2343 e3b0_val.full_lb_xon_threshold);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002344 /* The number of blocks guarantied for the MAC #n port. n=0,1
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002345 */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002346
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002347 /* The number of blocks guarantied for the LB port. */
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002348 REG_WR(bp, BRB1_REG_LB_GUARANTIED,
2349 e3b0_val.lb_guarantied);
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002350
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002351 /* The number of blocks guarantied for the MAC #n port. */
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002352 REG_WR(bp, BRB1_REG_MAC_GUARANTIED_0,
2353 2 * e3b0_val.mac_0_class_t_guarantied);
2354 REG_WR(bp, BRB1_REG_MAC_GUARANTIED_1,
2355 2 * e3b0_val.mac_1_class_t_guarantied);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002356 /* The number of blocks guarantied for class #t in MAC0. t=0,1
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002357 */
2358 REG_WR(bp, BRB1_REG_MAC_0_CLASS_0_GUARANTIED,
2359 e3b0_val.mac_0_class_t_guarantied);
2360 REG_WR(bp, BRB1_REG_MAC_0_CLASS_1_GUARANTIED,
2361 e3b0_val.mac_0_class_t_guarantied);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002362 /* The hysteresis on the guarantied buffer space for class in
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002363 * MAC0. t=0,1
2364 */
2365 REG_WR(bp, BRB1_REG_MAC_0_CLASS_0_GUARANTIED_HYST,
2366 e3b0_val.mac_0_class_t_guarantied_hyst);
2367 REG_WR(bp, BRB1_REG_MAC_0_CLASS_1_GUARANTIED_HYST,
2368 e3b0_val.mac_0_class_t_guarantied_hyst);
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002369
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002370 /* The number of blocks guarantied for class #t in MAC1.t=0,1
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002371 */
2372 REG_WR(bp, BRB1_REG_MAC_1_CLASS_0_GUARANTIED,
2373 e3b0_val.mac_1_class_t_guarantied);
2374 REG_WR(bp, BRB1_REG_MAC_1_CLASS_1_GUARANTIED,
2375 e3b0_val.mac_1_class_t_guarantied);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002376 /* The hysteresis on the guarantied buffer space for class #t
Yaniv Rosner2f751a82011-11-28 00:49:52 +00002377 * in MAC1. t=0,1
2378 */
2379 REG_WR(bp, BRB1_REG_MAC_1_CLASS_0_GUARANTIED_HYST,
2380 e3b0_val.mac_1_class_t_guarantied_hyst);
2381 REG_WR(bp, BRB1_REG_MAC_1_CLASS_1_GUARANTIED_HYST,
2382 e3b0_val.mac_1_class_t_guarantied_hyst);
2383 }
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002384
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002385 return bnx2x_status;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002386}
2387
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002388/******************************************************************************
2389* Description:
2390* This function is needed because NIG ARB_CREDIT_WEIGHT_X are
2391* not continues and ARB_CREDIT_WEIGHT_0 + offset is suitable.
2392******************************************************************************/
Yuval Mintzd2310232012-06-20 19:05:19 +00002393static int bnx2x_pfc_nig_rx_priority_mask(struct bnx2x *bp,
2394 u8 cos_entry,
2395 u32 priority_mask, u8 port)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002396{
2397 u32 nig_reg_rx_priority_mask_add = 0;
2398
2399 switch (cos_entry) {
2400 case 0:
2401 nig_reg_rx_priority_mask_add = (port) ?
2402 NIG_REG_P1_RX_COS0_PRIORITY_MASK :
2403 NIG_REG_P0_RX_COS0_PRIORITY_MASK;
2404 break;
2405 case 1:
2406 nig_reg_rx_priority_mask_add = (port) ?
2407 NIG_REG_P1_RX_COS1_PRIORITY_MASK :
2408 NIG_REG_P0_RX_COS1_PRIORITY_MASK;
2409 break;
2410 case 2:
2411 nig_reg_rx_priority_mask_add = (port) ?
2412 NIG_REG_P1_RX_COS2_PRIORITY_MASK :
2413 NIG_REG_P0_RX_COS2_PRIORITY_MASK;
2414 break;
2415 case 3:
2416 if (port)
2417 return -EINVAL;
2418 nig_reg_rx_priority_mask_add = NIG_REG_P0_RX_COS3_PRIORITY_MASK;
2419 break;
2420 case 4:
2421 if (port)
2422 return -EINVAL;
2423 nig_reg_rx_priority_mask_add = NIG_REG_P0_RX_COS4_PRIORITY_MASK;
2424 break;
2425 case 5:
2426 if (port)
2427 return -EINVAL;
2428 nig_reg_rx_priority_mask_add = NIG_REG_P0_RX_COS5_PRIORITY_MASK;
2429 break;
2430 }
2431
2432 REG_WR(bp, nig_reg_rx_priority_mask_add, priority_mask);
2433
2434 return 0;
2435}
Yaniv Rosnerb8d6d082011-07-05 01:06:27 +00002436static void bnx2x_update_mng(struct link_params *params, u32 link_status)
2437{
2438 struct bnx2x *bp = params->bp;
2439
2440 REG_WR(bp, params->shmem_base +
2441 offsetof(struct shmem_region,
2442 port_mb[params->port].link_status), link_status);
2443}
2444
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002445static void bnx2x_update_pfc_nig(struct link_params *params,
2446 struct link_vars *vars,
2447 struct bnx2x_nig_brb_pfc_port_params *nig_params)
2448{
2449 u32 xcm_mask = 0, ppp_enable = 0, pause_enable = 0, llfc_out_en = 0;
Yaniv Rosner127302b2012-01-17 02:33:26 +00002450 u32 llfc_enable = 0, xcm_out_en = 0, hwpfc_enable = 0;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002451 u32 pkt_priority_to_cos = 0;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002452 struct bnx2x *bp = params->bp;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002453 u8 port = params->port;
2454
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002455 int set_pfc = params->feature_config_flags &
2456 FEATURE_CONFIG_PFC_ENABLED;
2457 DP(NETIF_MSG_LINK, "updating pfc nig parameters\n");
2458
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002459 /* When NIG_LLH0_XCM_MASK_REG_LLHX_XCM_MASK_BCN bit is set
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002460 * MAC control frames (that are not pause packets)
2461 * will be forwarded to the XCM.
2462 */
Yaniv Rosner127302b2012-01-17 02:33:26 +00002463 xcm_mask = REG_RD(bp, port ? NIG_REG_LLH1_XCM_MASK :
2464 NIG_REG_LLH0_XCM_MASK);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002465 /* NIG params will override non PFC params, since it's possible to
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002466 * do transition from PFC to SAFC
2467 */
2468 if (set_pfc) {
2469 pause_enable = 0;
2470 llfc_out_en = 0;
2471 llfc_enable = 0;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002472 if (CHIP_IS_E3(bp))
2473 ppp_enable = 0;
2474 else
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002475 ppp_enable = 1;
2476 xcm_mask &= ~(port ? NIG_LLH1_XCM_MASK_REG_LLH1_XCM_MASK_BCN :
2477 NIG_LLH0_XCM_MASK_REG_LLH0_XCM_MASK_BCN);
Yaniv Rosner127302b2012-01-17 02:33:26 +00002478 xcm_out_en = 0;
2479 hwpfc_enable = 1;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002480 } else {
2481 if (nig_params) {
2482 llfc_out_en = nig_params->llfc_out_en;
2483 llfc_enable = nig_params->llfc_enable;
2484 pause_enable = nig_params->pause_enable;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002485 } else /* Default non PFC mode - PAUSE */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002486 pause_enable = 1;
2487
2488 xcm_mask |= (port ? NIG_LLH1_XCM_MASK_REG_LLH1_XCM_MASK_BCN :
2489 NIG_LLH0_XCM_MASK_REG_LLH0_XCM_MASK_BCN);
Yaniv Rosner127302b2012-01-17 02:33:26 +00002490 xcm_out_en = 1;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002491 }
2492
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002493 if (CHIP_IS_E3(bp))
2494 REG_WR(bp, port ? NIG_REG_BRB1_PAUSE_IN_EN :
2495 NIG_REG_BRB0_PAUSE_IN_EN, pause_enable);
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002496 REG_WR(bp, port ? NIG_REG_LLFC_OUT_EN_1 :
2497 NIG_REG_LLFC_OUT_EN_0, llfc_out_en);
2498 REG_WR(bp, port ? NIG_REG_LLFC_ENABLE_1 :
2499 NIG_REG_LLFC_ENABLE_0, llfc_enable);
2500 REG_WR(bp, port ? NIG_REG_PAUSE_ENABLE_1 :
2501 NIG_REG_PAUSE_ENABLE_0, pause_enable);
2502
2503 REG_WR(bp, port ? NIG_REG_PPP_ENABLE_1 :
2504 NIG_REG_PPP_ENABLE_0, ppp_enable);
2505
2506 REG_WR(bp, port ? NIG_REG_LLH1_XCM_MASK :
2507 NIG_REG_LLH0_XCM_MASK, xcm_mask);
2508
Yaniv Rosner127302b2012-01-17 02:33:26 +00002509 REG_WR(bp, port ? NIG_REG_LLFC_EGRESS_SRC_ENABLE_1 :
2510 NIG_REG_LLFC_EGRESS_SRC_ENABLE_0, 0x7);
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002511
Yuval Mintzd2310232012-06-20 19:05:19 +00002512 /* Output enable for RX_XCM # IF */
Yaniv Rosner127302b2012-01-17 02:33:26 +00002513 REG_WR(bp, port ? NIG_REG_XCM1_OUT_EN :
2514 NIG_REG_XCM0_OUT_EN, xcm_out_en);
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002515
2516 /* HW PFC TX enable */
Yaniv Rosner127302b2012-01-17 02:33:26 +00002517 REG_WR(bp, port ? NIG_REG_P1_HWPFC_ENABLE :
2518 NIG_REG_P0_HWPFC_ENABLE, hwpfc_enable);
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002519
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002520 if (nig_params) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002521 u8 i = 0;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002522 pkt_priority_to_cos = nig_params->pkt_priority_to_cos;
2523
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002524 for (i = 0; i < nig_params->num_of_rx_cos_priority_mask; i++)
2525 bnx2x_pfc_nig_rx_priority_mask(bp, i,
2526 nig_params->rx_cos_priority_mask[i], port);
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002527
2528 REG_WR(bp, port ? NIG_REG_LLFC_HIGH_PRIORITY_CLASSES_1 :
2529 NIG_REG_LLFC_HIGH_PRIORITY_CLASSES_0,
2530 nig_params->llfc_high_priority_classes);
2531
2532 REG_WR(bp, port ? NIG_REG_LLFC_LOW_PRIORITY_CLASSES_1 :
2533 NIG_REG_LLFC_LOW_PRIORITY_CLASSES_0,
2534 nig_params->llfc_low_priority_classes);
2535 }
2536 REG_WR(bp, port ? NIG_REG_P1_PKT_PRIORITY_TO_COS :
2537 NIG_REG_P0_PKT_PRIORITY_TO_COS,
2538 pkt_priority_to_cos);
2539}
2540
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002541int bnx2x_update_pfc(struct link_params *params,
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002542 struct link_vars *vars,
2543 struct bnx2x_nig_brb_pfc_port_params *pfc_params)
2544{
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002545 /* The PFC and pause are orthogonal to one another, meaning when
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002546 * PFC is enabled, the pause are disabled, and when PFC is
2547 * disabled, pause are set according to the pause result.
2548 */
2549 u32 val;
2550 struct bnx2x *bp = params->bp;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002551 int bnx2x_status = 0;
2552 u8 bmac_loopback = (params->loopback_mode == LOOPBACK_BMAC);
Yaniv Rosnerb8d6d082011-07-05 01:06:27 +00002553
2554 if (params->feature_config_flags & FEATURE_CONFIG_PFC_ENABLED)
2555 vars->link_status |= LINK_STATUS_PFC_ENABLED;
2556 else
2557 vars->link_status &= ~LINK_STATUS_PFC_ENABLED;
2558
2559 bnx2x_update_mng(params, vars->link_status);
2560
Yuval Mintzd2310232012-06-20 19:05:19 +00002561 /* Update NIG params */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002562 bnx2x_update_pfc_nig(params, vars, pfc_params);
2563
Yuval Mintzd2310232012-06-20 19:05:19 +00002564 /* Update BRB params */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002565 bnx2x_status = bnx2x_update_pfc_brb(params, vars, pfc_params);
Yaniv Rosnerde0396f2011-11-28 00:49:53 +00002566 if (bnx2x_status)
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002567 return bnx2x_status;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002568
2569 if (!vars->link_up)
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002570 return bnx2x_status;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002571
2572 DP(NETIF_MSG_LINK, "About to update PFC in BMAC\n");
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002573 if (CHIP_IS_E3(bp))
2574 bnx2x_update_pfc_xmac(params, vars, 0);
2575 else {
2576 val = REG_RD(bp, MISC_REG_RESET_REG_2);
2577 if ((val &
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00002578 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << params->port))
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002579 == 0) {
2580 DP(NETIF_MSG_LINK, "About to update PFC in EMAC\n");
2581 bnx2x_emac_enable(params, vars, 0);
2582 return bnx2x_status;
2583 }
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002584 if (CHIP_IS_E2(bp))
2585 bnx2x_update_pfc_bmac2(params, vars, bmac_loopback);
2586 else
2587 bnx2x_update_pfc_bmac1(params, vars);
2588
2589 val = 0;
2590 if ((params->feature_config_flags &
2591 FEATURE_CONFIG_PFC_ENABLED) ||
2592 (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX))
2593 val = 1;
2594 REG_WR(bp, NIG_REG_BMAC0_PAUSE_OUT_EN + params->port*4, val);
2595 }
2596 return bnx2x_status;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002597}
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002598
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002599
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00002600static int bnx2x_bmac1_enable(struct link_params *params,
2601 struct link_vars *vars,
2602 u8 is_lb)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002603{
2604 struct bnx2x *bp = params->bp;
2605 u8 port = params->port;
2606 u32 bmac_addr = port ? NIG_REG_INGRESS_BMAC1_MEM :
2607 NIG_REG_INGRESS_BMAC0_MEM;
2608 u32 wb_data[2];
2609 u32 val;
2610
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002611 DP(NETIF_MSG_LINK, "Enabling BigMAC1\n");
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002612
2613 /* XGXS control */
2614 wb_data[0] = 0x3c;
2615 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002616 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_BMAC_XGXS_CONTROL,
2617 wb_data, 2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002618
Yuval Mintzd2310232012-06-20 19:05:19 +00002619 /* TX MAC SA */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002620 wb_data[0] = ((params->mac_addr[2] << 24) |
2621 (params->mac_addr[3] << 16) |
2622 (params->mac_addr[4] << 8) |
2623 params->mac_addr[5]);
2624 wb_data[1] = ((params->mac_addr[0] << 8) |
2625 params->mac_addr[1]);
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002626 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_TX_SOURCE_ADDR, wb_data, 2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002627
Yuval Mintzd2310232012-06-20 19:05:19 +00002628 /* MAC control */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002629 val = 0x3;
2630 if (is_lb) {
2631 val |= 0x4;
2632 DP(NETIF_MSG_LINK, "enable bmac loopback\n");
2633 }
2634 wb_data[0] = val;
2635 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002636 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_BMAC_CONTROL, wb_data, 2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002637
Yuval Mintzd2310232012-06-20 19:05:19 +00002638 /* Set rx mtu */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002639 wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD;
2640 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002641 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_RX_MAX_SIZE, wb_data, 2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002642
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002643 bnx2x_update_pfc_bmac1(params, vars);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002644
Yuval Mintzd2310232012-06-20 19:05:19 +00002645 /* Set tx mtu */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002646 wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD;
2647 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002648 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_TX_MAX_SIZE, wb_data, 2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002649
Yuval Mintzd2310232012-06-20 19:05:19 +00002650 /* Set cnt max size */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002651 wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD;
2652 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002653 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_CNT_MAX_SIZE, wb_data, 2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002654
Yuval Mintzd2310232012-06-20 19:05:19 +00002655 /* Configure SAFC */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002656 wb_data[0] = 0x1000200;
2657 wb_data[1] = 0;
2658 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_RX_LLFC_MSG_FLDS,
2659 wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002660
2661 return 0;
2662}
2663
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00002664static int bnx2x_bmac2_enable(struct link_params *params,
2665 struct link_vars *vars,
2666 u8 is_lb)
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002667{
2668 struct bnx2x *bp = params->bp;
2669 u8 port = params->port;
2670 u32 bmac_addr = port ? NIG_REG_INGRESS_BMAC1_MEM :
2671 NIG_REG_INGRESS_BMAC0_MEM;
2672 u32 wb_data[2];
2673
2674 DP(NETIF_MSG_LINK, "Enabling BigMAC2\n");
2675
2676 wb_data[0] = 0;
2677 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002678 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_BMAC_CONTROL, wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002679 udelay(30);
2680
2681 /* XGXS control: Reset phy HW, MDIO registers, PHY PLL and BMAC */
2682 wb_data[0] = 0x3c;
2683 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002684 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_BMAC_XGXS_CONTROL,
2685 wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002686
2687 udelay(30);
2688
Yuval Mintzd2310232012-06-20 19:05:19 +00002689 /* TX MAC SA */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002690 wb_data[0] = ((params->mac_addr[2] << 24) |
2691 (params->mac_addr[3] << 16) |
2692 (params->mac_addr[4] << 8) |
2693 params->mac_addr[5]);
2694 wb_data[1] = ((params->mac_addr[0] << 8) |
2695 params->mac_addr[1]);
2696 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_TX_SOURCE_ADDR,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002697 wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002698
2699 udelay(30);
2700
2701 /* Configure SAFC */
2702 wb_data[0] = 0x1000200;
2703 wb_data[1] = 0;
2704 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_RX_LLFC_MSG_FLDS,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002705 wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002706 udelay(30);
2707
Yuval Mintzd2310232012-06-20 19:05:19 +00002708 /* Set RX MTU */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002709 wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD;
2710 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002711 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_RX_MAX_SIZE, wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002712 udelay(30);
2713
Yuval Mintzd2310232012-06-20 19:05:19 +00002714 /* Set TX MTU */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002715 wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD;
2716 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002717 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_TX_MAX_SIZE, wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002718 udelay(30);
Yuval Mintzd2310232012-06-20 19:05:19 +00002719 /* Set cnt max size */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002720 wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD - 2;
2721 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002722 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_CNT_MAX_SIZE, wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002723 udelay(30);
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002724 bnx2x_update_pfc_bmac2(params, vars, is_lb);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002725
2726 return 0;
2727}
2728
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00002729static int bnx2x_bmac_enable(struct link_params *params,
2730 struct link_vars *vars,
2731 u8 is_lb)
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002732{
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00002733 int rc = 0;
2734 u8 port = params->port;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002735 struct bnx2x *bp = params->bp;
2736 u32 val;
Yuval Mintzd2310232012-06-20 19:05:19 +00002737 /* Reset and unreset the BigMac */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002738 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002739 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port));
Yuval Mintzd2310232012-06-20 19:05:19 +00002740 usleep_range(1000, 2000);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002741
2742 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002743 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port));
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002744
Yuval Mintzd2310232012-06-20 19:05:19 +00002745 /* Enable access for bmac registers */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002746 REG_WR(bp, NIG_REG_BMAC0_REGS_OUT_EN + port*4, 0x1);
2747
2748 /* Enable BMAC according to BMAC type*/
2749 if (CHIP_IS_E2(bp))
2750 rc = bnx2x_bmac2_enable(params, vars, is_lb);
2751 else
2752 rc = bnx2x_bmac1_enable(params, vars, is_lb);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002753 REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 0x1);
2754 REG_WR(bp, NIG_REG_XGXS_LANE_SEL_P0 + port*4, 0x0);
2755 REG_WR(bp, NIG_REG_EGRESS_EMAC0_PORT + port*4, 0x0);
2756 val = 0;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002757 if ((params->feature_config_flags &
2758 FEATURE_CONFIG_PFC_ENABLED) ||
2759 (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX))
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002760 val = 1;
2761 REG_WR(bp, NIG_REG_BMAC0_PAUSE_OUT_EN + port*4, val);
2762 REG_WR(bp, NIG_REG_EGRESS_EMAC0_OUT_EN + port*4, 0x0);
2763 REG_WR(bp, NIG_REG_EMAC0_IN_EN + port*4, 0x0);
2764 REG_WR(bp, NIG_REG_EMAC0_PAUSE_OUT_EN + port*4, 0x0);
2765 REG_WR(bp, NIG_REG_BMAC0_IN_EN + port*4, 0x1);
2766 REG_WR(bp, NIG_REG_BMAC0_OUT_EN + port*4, 0x1);
2767
2768 vars->mac_type = MAC_TYPE_BMAC;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002769 return rc;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002770}
2771
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002772static void bnx2x_bmac_rx_disable(struct bnx2x *bp, u8 port)
2773{
2774 u32 bmac_addr = port ? NIG_REG_INGRESS_BMAC1_MEM :
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002775 NIG_REG_INGRESS_BMAC0_MEM;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002776 u32 wb_data[2];
Eilon Greenstein3196a882008-08-13 15:58:49 -07002777 u32 nig_bmac_enable = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port*4);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002778
2779 /* Only if the bmac is out of reset */
2780 if (REG_RD(bp, MISC_REG_RESET_REG_2) &
2781 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port) &&
2782 nig_bmac_enable) {
2783
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002784 if (CHIP_IS_E2(bp)) {
2785 /* Clear Rx Enable bit in BMAC_CONTROL register */
2786 REG_RD_DMAE(bp, bmac_addr +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002787 BIGMAC2_REGISTER_BMAC_CONTROL,
2788 wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002789 wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
2790 REG_WR_DMAE(bp, bmac_addr +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002791 BIGMAC2_REGISTER_BMAC_CONTROL,
2792 wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002793 } else {
2794 /* Clear Rx Enable bit in BMAC_CONTROL register */
2795 REG_RD_DMAE(bp, bmac_addr +
2796 BIGMAC_REGISTER_BMAC_CONTROL,
2797 wb_data, 2);
2798 wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
2799 REG_WR_DMAE(bp, bmac_addr +
2800 BIGMAC_REGISTER_BMAC_CONTROL,
2801 wb_data, 2);
2802 }
Yuval Mintzd2310232012-06-20 19:05:19 +00002803 usleep_range(1000, 2000);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002804 }
2805}
2806
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00002807static int bnx2x_pbf_update(struct link_params *params, u32 flow_ctrl,
2808 u32 line_speed)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002809{
2810 struct bnx2x *bp = params->bp;
2811 u8 port = params->port;
2812 u32 init_crd, crd;
2813 u32 count = 1000;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002814
Yuval Mintzd2310232012-06-20 19:05:19 +00002815 /* Disable port */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002816 REG_WR(bp, PBF_REG_DISABLE_NEW_TASK_PROC_P0 + port*4, 0x1);
2817
Yuval Mintzd2310232012-06-20 19:05:19 +00002818 /* Wait for init credit */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002819 init_crd = REG_RD(bp, PBF_REG_P0_INIT_CRD + port*4);
2820 crd = REG_RD(bp, PBF_REG_P0_CREDIT + port*8);
2821 DP(NETIF_MSG_LINK, "init_crd 0x%x crd 0x%x\n", init_crd, crd);
2822
2823 while ((init_crd != crd) && count) {
Yuval Mintzd2310232012-06-20 19:05:19 +00002824 usleep_range(5000, 10000);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002825 crd = REG_RD(bp, PBF_REG_P0_CREDIT + port*8);
2826 count--;
2827 }
2828 crd = REG_RD(bp, PBF_REG_P0_CREDIT + port*8);
2829 if (init_crd != crd) {
2830 DP(NETIF_MSG_LINK, "BUG! init_crd 0x%x != crd 0x%x\n",
2831 init_crd, crd);
2832 return -EINVAL;
2833 }
2834
David S. Millerc0700f92008-12-16 23:53:20 -08002835 if (flow_ctrl & BNX2X_FLOW_CTRL_RX ||
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002836 line_speed == SPEED_10 ||
2837 line_speed == SPEED_100 ||
2838 line_speed == SPEED_1000 ||
2839 line_speed == SPEED_2500) {
2840 REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 1);
Yuval Mintzd2310232012-06-20 19:05:19 +00002841 /* Update threshold */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002842 REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, 0);
Yuval Mintzd2310232012-06-20 19:05:19 +00002843 /* Update init credit */
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002844 init_crd = 778; /* (800-18-4) */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002845
2846 } else {
2847 u32 thresh = (ETH_MAX_JUMBO_PACKET_SIZE +
2848 ETH_OVREHEAD)/16;
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002849 REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
Yuval Mintzd2310232012-06-20 19:05:19 +00002850 /* Update threshold */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002851 REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, thresh);
Yuval Mintzd2310232012-06-20 19:05:19 +00002852 /* Update init credit */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002853 switch (line_speed) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002854 case SPEED_10000:
2855 init_crd = thresh + 553 - 22;
2856 break;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002857 default:
2858 DP(NETIF_MSG_LINK, "Invalid line_speed 0x%x\n",
2859 line_speed);
2860 return -EINVAL;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002861 }
2862 }
2863 REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, init_crd);
2864 DP(NETIF_MSG_LINK, "PBF updated to speed %d credit %d\n",
2865 line_speed, init_crd);
2866
Yuval Mintzd2310232012-06-20 19:05:19 +00002867 /* Probe the credit changes */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002868 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0x1);
Yuval Mintzd2310232012-06-20 19:05:19 +00002869 usleep_range(5000, 10000);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002870 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0x0);
2871
Yuval Mintzd2310232012-06-20 19:05:19 +00002872 /* Enable port */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002873 REG_WR(bp, PBF_REG_DISABLE_NEW_TASK_PROC_P0 + port*4, 0x0);
2874 return 0;
2875}
2876
Dmitry Kravkove8920672011-05-04 23:52:40 +00002877/**
2878 * bnx2x_get_emac_base - retrive emac base address
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002879 *
Dmitry Kravkove8920672011-05-04 23:52:40 +00002880 * @bp: driver handle
2881 * @mdc_mdio_access: access type
2882 * @port: port id
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002883 *
2884 * This function selects the MDC/MDIO access (through emac0 or
2885 * emac1) depend on the mdc_mdio_access, port, port swapped. Each
2886 * phy has a default access mode, which could also be overridden
2887 * by nvram configuration. This parameter, whether this is the
2888 * default phy configuration, or the nvram overrun
2889 * configuration, is passed here as mdc_mdio_access and selects
2890 * the emac_base for the CL45 read/writes operations
2891 */
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00002892static u32 bnx2x_get_emac_base(struct bnx2x *bp,
2893 u32 mdc_mdio_access, u8 port)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002894{
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00002895 u32 emac_base = 0;
2896 switch (mdc_mdio_access) {
2897 case SHARED_HW_CFG_MDC_MDIO_ACCESS1_PHY_TYPE:
2898 break;
2899 case SHARED_HW_CFG_MDC_MDIO_ACCESS1_EMAC0:
2900 if (REG_RD(bp, NIG_REG_PORT_SWAP))
2901 emac_base = GRCBASE_EMAC1;
2902 else
2903 emac_base = GRCBASE_EMAC0;
2904 break;
2905 case SHARED_HW_CFG_MDC_MDIO_ACCESS1_EMAC1:
Eilon Greenstein589abe32009-02-12 08:36:55 +00002906 if (REG_RD(bp, NIG_REG_PORT_SWAP))
2907 emac_base = GRCBASE_EMAC0;
2908 else
2909 emac_base = GRCBASE_EMAC1;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002910 break;
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00002911 case SHARED_HW_CFG_MDC_MDIO_ACCESS1_BOTH:
2912 emac_base = (port) ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
2913 break;
2914 case SHARED_HW_CFG_MDC_MDIO_ACCESS1_SWAPPED:
Eilon Greenstein6378c022008-08-13 15:59:25 -07002915 emac_base = (port) ? GRCBASE_EMAC0 : GRCBASE_EMAC1;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002916 break;
2917 default:
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002918 break;
2919 }
2920 return emac_base;
2921
2922}
2923
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002924/******************************************************************/
Yaniv Rosner6583e332011-06-14 01:34:17 +00002925/* CL22 access functions */
2926/******************************************************************/
2927static int bnx2x_cl22_write(struct bnx2x *bp,
2928 struct bnx2x_phy *phy,
2929 u16 reg, u16 val)
2930{
2931 u32 tmp, mode;
2932 u8 i;
2933 int rc = 0;
2934 /* Switch to CL22 */
2935 mode = REG_RD(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE);
2936 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE,
2937 mode & ~EMAC_MDIO_MODE_CLAUSE_45);
2938
Yuval Mintzd2310232012-06-20 19:05:19 +00002939 /* Address */
Yaniv Rosner6583e332011-06-14 01:34:17 +00002940 tmp = ((phy->addr << 21) | (reg << 16) | val |
2941 EMAC_MDIO_COMM_COMMAND_WRITE_22 |
2942 EMAC_MDIO_COMM_START_BUSY);
2943 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, tmp);
2944
2945 for (i = 0; i < 50; i++) {
2946 udelay(10);
2947
2948 tmp = REG_RD(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM);
2949 if (!(tmp & EMAC_MDIO_COMM_START_BUSY)) {
2950 udelay(5);
2951 break;
2952 }
2953 }
2954 if (tmp & EMAC_MDIO_COMM_START_BUSY) {
2955 DP(NETIF_MSG_LINK, "write phy register failed\n");
2956 rc = -EFAULT;
2957 }
2958 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE, mode);
2959 return rc;
2960}
2961
2962static int bnx2x_cl22_read(struct bnx2x *bp,
2963 struct bnx2x_phy *phy,
2964 u16 reg, u16 *ret_val)
2965{
2966 u32 val, mode;
2967 u16 i;
2968 int rc = 0;
2969
2970 /* Switch to CL22 */
2971 mode = REG_RD(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE);
2972 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE,
2973 mode & ~EMAC_MDIO_MODE_CLAUSE_45);
2974
Yuval Mintzd2310232012-06-20 19:05:19 +00002975 /* Address */
Yaniv Rosner6583e332011-06-14 01:34:17 +00002976 val = ((phy->addr << 21) | (reg << 16) |
2977 EMAC_MDIO_COMM_COMMAND_READ_22 |
2978 EMAC_MDIO_COMM_START_BUSY);
2979 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, val);
2980
2981 for (i = 0; i < 50; i++) {
2982 udelay(10);
2983
2984 val = REG_RD(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM);
2985 if (!(val & EMAC_MDIO_COMM_START_BUSY)) {
2986 *ret_val = (u16)(val & EMAC_MDIO_COMM_DATA);
2987 udelay(5);
2988 break;
2989 }
2990 }
2991 if (val & EMAC_MDIO_COMM_START_BUSY) {
2992 DP(NETIF_MSG_LINK, "read phy register failed\n");
2993
2994 *ret_val = 0;
2995 rc = -EFAULT;
2996 }
2997 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE, mode);
2998 return rc;
2999}
3000
3001/******************************************************************/
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003002/* CL45 access functions */
3003/******************************************************************/
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00003004static int bnx2x_cl45_read(struct bnx2x *bp, struct bnx2x_phy *phy,
3005 u8 devad, u16 reg, u16 *ret_val)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003006{
Yaniv Rosnera198c142011-05-31 21:29:42 +00003007 u32 val;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003008 u16 i;
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00003009 int rc = 0;
Yaniv Rosner157fa282011-08-02 22:59:32 +00003010 if (phy->flags & FLAGS_MDC_MDIO_WA_B0)
3011 bnx2x_bits_en(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_STATUS,
3012 EMAC_MDIO_STATUS_10MB);
Yuval Mintzd2310232012-06-20 19:05:19 +00003013 /* Address */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003014 val = ((phy->addr << 21) | (devad << 16) | reg |
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003015 EMAC_MDIO_COMM_COMMAND_ADDRESS |
3016 EMAC_MDIO_COMM_START_BUSY);
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003017 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003018
3019 for (i = 0; i < 50; i++) {
3020 udelay(10);
3021
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003022 val = REG_RD(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003023 if (!(val & EMAC_MDIO_COMM_START_BUSY)) {
3024 udelay(5);
3025 break;
3026 }
3027 }
3028 if (val & EMAC_MDIO_COMM_START_BUSY) {
3029 DP(NETIF_MSG_LINK, "read phy register failed\n");
Yaniv Rosner6d870c32011-01-31 04:22:20 +00003030 netdev_err(bp->dev, "MDC/MDIO access timeout\n");
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003031 *ret_val = 0;
3032 rc = -EFAULT;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003033 } else {
Yuval Mintzd2310232012-06-20 19:05:19 +00003034 /* Data */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003035 val = ((phy->addr << 21) | (devad << 16) |
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003036 EMAC_MDIO_COMM_COMMAND_READ_45 |
3037 EMAC_MDIO_COMM_START_BUSY);
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003038 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003039
3040 for (i = 0; i < 50; i++) {
3041 udelay(10);
3042
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003043 val = REG_RD(bp, phy->mdio_ctrl +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003044 EMAC_REG_EMAC_MDIO_COMM);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003045 if (!(val & EMAC_MDIO_COMM_START_BUSY)) {
3046 *ret_val = (u16)(val & EMAC_MDIO_COMM_DATA);
3047 break;
3048 }
3049 }
3050 if (val & EMAC_MDIO_COMM_START_BUSY) {
3051 DP(NETIF_MSG_LINK, "read phy register failed\n");
Yaniv Rosner6d870c32011-01-31 04:22:20 +00003052 netdev_err(bp->dev, "MDC/MDIO access timeout\n");
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003053 *ret_val = 0;
3054 rc = -EFAULT;
3055 }
3056 }
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003057 /* Work around for E3 A0 */
3058 if (phy->flags & FLAGS_MDC_MDIO_WA) {
3059 phy->flags ^= FLAGS_DUMMY_READ;
3060 if (phy->flags & FLAGS_DUMMY_READ) {
3061 u16 temp_val;
3062 bnx2x_cl45_read(bp, phy, devad, 0xf, &temp_val);
3063 }
3064 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003065
Yaniv Rosner157fa282011-08-02 22:59:32 +00003066 if (phy->flags & FLAGS_MDC_MDIO_WA_B0)
3067 bnx2x_bits_dis(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_STATUS,
3068 EMAC_MDIO_STATUS_10MB);
Yaniv Rosnera198c142011-05-31 21:29:42 +00003069 return rc;
3070}
3071
3072static int bnx2x_cl45_write(struct bnx2x *bp, struct bnx2x_phy *phy,
3073 u8 devad, u16 reg, u16 val)
3074{
3075 u32 tmp;
3076 u8 i;
3077 int rc = 0;
Yaniv Rosner157fa282011-08-02 22:59:32 +00003078 if (phy->flags & FLAGS_MDC_MDIO_WA_B0)
3079 bnx2x_bits_en(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_STATUS,
3080 EMAC_MDIO_STATUS_10MB);
Yaniv Rosnera198c142011-05-31 21:29:42 +00003081
Yuval Mintzd2310232012-06-20 19:05:19 +00003082 /* Address */
Yaniv Rosnera198c142011-05-31 21:29:42 +00003083 tmp = ((phy->addr << 21) | (devad << 16) | reg |
3084 EMAC_MDIO_COMM_COMMAND_ADDRESS |
3085 EMAC_MDIO_COMM_START_BUSY);
3086 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, tmp);
3087
3088 for (i = 0; i < 50; i++) {
3089 udelay(10);
3090
3091 tmp = REG_RD(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM);
3092 if (!(tmp & EMAC_MDIO_COMM_START_BUSY)) {
3093 udelay(5);
3094 break;
3095 }
3096 }
3097 if (tmp & EMAC_MDIO_COMM_START_BUSY) {
3098 DP(NETIF_MSG_LINK, "write phy register failed\n");
3099 netdev_err(bp->dev, "MDC/MDIO access timeout\n");
3100 rc = -EFAULT;
Yaniv Rosnera198c142011-05-31 21:29:42 +00003101 } else {
Yuval Mintzd2310232012-06-20 19:05:19 +00003102 /* Data */
Yaniv Rosnera198c142011-05-31 21:29:42 +00003103 tmp = ((phy->addr << 21) | (devad << 16) | val |
3104 EMAC_MDIO_COMM_COMMAND_WRITE_45 |
3105 EMAC_MDIO_COMM_START_BUSY);
3106 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, tmp);
3107
3108 for (i = 0; i < 50; i++) {
3109 udelay(10);
3110
3111 tmp = REG_RD(bp, phy->mdio_ctrl +
3112 EMAC_REG_EMAC_MDIO_COMM);
3113 if (!(tmp & EMAC_MDIO_COMM_START_BUSY)) {
3114 udelay(5);
3115 break;
3116 }
3117 }
3118 if (tmp & EMAC_MDIO_COMM_START_BUSY) {
3119 DP(NETIF_MSG_LINK, "write phy register failed\n");
3120 netdev_err(bp->dev, "MDC/MDIO access timeout\n");
3121 rc = -EFAULT;
3122 }
3123 }
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003124 /* Work around for E3 A0 */
3125 if (phy->flags & FLAGS_MDC_MDIO_WA) {
3126 phy->flags ^= FLAGS_DUMMY_READ;
3127 if (phy->flags & FLAGS_DUMMY_READ) {
3128 u16 temp_val;
3129 bnx2x_cl45_read(bp, phy, devad, 0xf, &temp_val);
3130 }
3131 }
Yaniv Rosner157fa282011-08-02 22:59:32 +00003132 if (phy->flags & FLAGS_MDC_MDIO_WA_B0)
3133 bnx2x_bits_dis(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_STATUS,
3134 EMAC_MDIO_STATUS_10MB);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003135 return rc;
3136}
Yuval Mintzec4010e2012-09-10 05:51:06 +00003137
3138/******************************************************************/
3139/* EEE section */
3140/******************************************************************/
3141static u8 bnx2x_eee_has_cap(struct link_params *params)
3142{
3143 struct bnx2x *bp = params->bp;
3144
3145 if (REG_RD(bp, params->shmem2_base) <=
3146 offsetof(struct shmem2_region, eee_status[params->port]))
3147 return 0;
3148
3149 return 1;
3150}
3151
3152static int bnx2x_eee_nvram_to_time(u32 nvram_mode, u32 *idle_timer)
3153{
3154 switch (nvram_mode) {
3155 case PORT_FEAT_CFG_EEE_POWER_MODE_BALANCED:
3156 *idle_timer = EEE_MODE_NVRAM_BALANCED_TIME;
3157 break;
3158 case PORT_FEAT_CFG_EEE_POWER_MODE_AGGRESSIVE:
3159 *idle_timer = EEE_MODE_NVRAM_AGGRESSIVE_TIME;
3160 break;
3161 case PORT_FEAT_CFG_EEE_POWER_MODE_LOW_LATENCY:
3162 *idle_timer = EEE_MODE_NVRAM_LATENCY_TIME;
3163 break;
3164 default:
3165 *idle_timer = 0;
3166 break;
3167 }
3168
3169 return 0;
3170}
3171
3172static int bnx2x_eee_time_to_nvram(u32 idle_timer, u32 *nvram_mode)
3173{
3174 switch (idle_timer) {
3175 case EEE_MODE_NVRAM_BALANCED_TIME:
3176 *nvram_mode = PORT_FEAT_CFG_EEE_POWER_MODE_BALANCED;
3177 break;
3178 case EEE_MODE_NVRAM_AGGRESSIVE_TIME:
3179 *nvram_mode = PORT_FEAT_CFG_EEE_POWER_MODE_AGGRESSIVE;
3180 break;
3181 case EEE_MODE_NVRAM_LATENCY_TIME:
3182 *nvram_mode = PORT_FEAT_CFG_EEE_POWER_MODE_LOW_LATENCY;
3183 break;
3184 default:
3185 *nvram_mode = PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED;
3186 break;
3187 }
3188
3189 return 0;
3190}
3191
3192static u32 bnx2x_eee_calc_timer(struct link_params *params)
3193{
3194 u32 eee_mode, eee_idle;
3195 struct bnx2x *bp = params->bp;
3196
3197 if (params->eee_mode & EEE_MODE_OVERRIDE_NVRAM) {
3198 if (params->eee_mode & EEE_MODE_OUTPUT_TIME) {
3199 /* time value in eee_mode --> used directly*/
3200 eee_idle = params->eee_mode & EEE_MODE_TIMER_MASK;
3201 } else {
3202 /* hsi value in eee_mode --> time */
3203 if (bnx2x_eee_nvram_to_time(params->eee_mode &
3204 EEE_MODE_NVRAM_MASK,
3205 &eee_idle))
3206 return 0;
3207 }
3208 } else {
3209 /* hsi values in nvram --> time*/
3210 eee_mode = ((REG_RD(bp, params->shmem_base +
3211 offsetof(struct shmem_region, dev_info.
3212 port_feature_config[params->port].
3213 eee_power_mode)) &
3214 PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >>
3215 PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT);
3216
3217 if (bnx2x_eee_nvram_to_time(eee_mode, &eee_idle))
3218 return 0;
3219 }
3220
3221 return eee_idle;
3222}
3223
3224static int bnx2x_eee_set_timers(struct link_params *params,
3225 struct link_vars *vars)
3226{
3227 u32 eee_idle = 0, eee_mode;
3228 struct bnx2x *bp = params->bp;
3229
3230 eee_idle = bnx2x_eee_calc_timer(params);
3231
3232 if (eee_idle) {
3233 REG_WR(bp, MISC_REG_CPMU_LP_IDLE_THR_P0 + (params->port << 2),
3234 eee_idle);
3235 } else if ((params->eee_mode & EEE_MODE_ENABLE_LPI) &&
3236 (params->eee_mode & EEE_MODE_OVERRIDE_NVRAM) &&
3237 (params->eee_mode & EEE_MODE_OUTPUT_TIME)) {
3238 DP(NETIF_MSG_LINK, "Error: Tx LPI is enabled with timer 0\n");
3239 return -EINVAL;
3240 }
3241
3242 vars->eee_status &= ~(SHMEM_EEE_TIMER_MASK | SHMEM_EEE_TIME_OUTPUT_BIT);
3243 if (params->eee_mode & EEE_MODE_OUTPUT_TIME) {
3244 /* eee_idle in 1u --> eee_status in 16u */
3245 eee_idle >>= 4;
3246 vars->eee_status |= (eee_idle & SHMEM_EEE_TIMER_MASK) |
3247 SHMEM_EEE_TIME_OUTPUT_BIT;
3248 } else {
3249 if (bnx2x_eee_time_to_nvram(eee_idle, &eee_mode))
3250 return -EINVAL;
3251 vars->eee_status |= eee_mode;
3252 }
3253
3254 return 0;
3255}
3256
3257static int bnx2x_eee_initial_config(struct link_params *params,
3258 struct link_vars *vars, u8 mode)
3259{
3260 vars->eee_status |= ((u32) mode) << SHMEM_EEE_SUPPORTED_SHIFT;
3261
3262 /* Propogate params' bits --> vars (for migration exposure) */
3263 if (params->eee_mode & EEE_MODE_ENABLE_LPI)
3264 vars->eee_status |= SHMEM_EEE_LPI_REQUESTED_BIT;
3265 else
3266 vars->eee_status &= ~SHMEM_EEE_LPI_REQUESTED_BIT;
3267
3268 if (params->eee_mode & EEE_MODE_ADV_LPI)
3269 vars->eee_status |= SHMEM_EEE_REQUESTED_BIT;
3270 else
3271 vars->eee_status &= ~SHMEM_EEE_REQUESTED_BIT;
3272
3273 return bnx2x_eee_set_timers(params, vars);
3274}
3275
3276static int bnx2x_eee_disable(struct bnx2x_phy *phy,
3277 struct link_params *params,
3278 struct link_vars *vars)
3279{
3280 struct bnx2x *bp = params->bp;
3281
3282 /* Make Certain LPI is disabled */
3283 REG_WR(bp, MISC_REG_CPMU_LP_FW_ENABLE_P0 + (params->port << 2), 0);
3284
3285 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_EEE_ADV, 0x0);
3286
3287 vars->eee_status &= ~SHMEM_EEE_ADV_STATUS_MASK;
3288
3289 return 0;
3290}
3291
3292static int bnx2x_eee_advertise(struct bnx2x_phy *phy,
3293 struct link_params *params,
3294 struct link_vars *vars, u8 modes)
3295{
3296 struct bnx2x *bp = params->bp;
3297 u16 val = 0;
3298
3299 /* Mask events preventing LPI generation */
3300 REG_WR(bp, MISC_REG_CPMU_LP_MASK_EXT_P0 + (params->port << 2), 0xfc20);
3301
3302 if (modes & SHMEM_EEE_10G_ADV) {
3303 DP(NETIF_MSG_LINK, "Advertise 10GBase-T EEE\n");
3304 val |= 0x8;
3305 }
3306 if (modes & SHMEM_EEE_1G_ADV) {
3307 DP(NETIF_MSG_LINK, "Advertise 1GBase-T EEE\n");
3308 val |= 0x4;
3309 }
3310
3311 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_EEE_ADV, val);
3312
3313 vars->eee_status &= ~SHMEM_EEE_ADV_STATUS_MASK;
3314 vars->eee_status |= (modes << SHMEM_EEE_ADV_STATUS_SHIFT);
3315
3316 return 0;
3317}
3318
3319static void bnx2x_update_mng_eee(struct link_params *params, u32 eee_status)
3320{
3321 struct bnx2x *bp = params->bp;
3322
3323 if (bnx2x_eee_has_cap(params))
3324 REG_WR(bp, params->shmem2_base +
3325 offsetof(struct shmem2_region,
3326 eee_status[params->port]), eee_status);
3327}
3328
3329static void bnx2x_eee_an_resolve(struct bnx2x_phy *phy,
3330 struct link_params *params,
3331 struct link_vars *vars)
3332{
3333 struct bnx2x *bp = params->bp;
3334 u16 adv = 0, lp = 0;
3335 u32 lp_adv = 0;
3336 u8 neg = 0;
3337
3338 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_EEE_ADV, &adv);
3339 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_LP_EEE_ADV, &lp);
3340
3341 if (lp & 0x2) {
3342 lp_adv |= SHMEM_EEE_100M_ADV;
3343 if (adv & 0x2) {
3344 if (vars->line_speed == SPEED_100)
3345 neg = 1;
3346 DP(NETIF_MSG_LINK, "EEE negotiated - 100M\n");
3347 }
3348 }
3349 if (lp & 0x14) {
3350 lp_adv |= SHMEM_EEE_1G_ADV;
3351 if (adv & 0x14) {
3352 if (vars->line_speed == SPEED_1000)
3353 neg = 1;
3354 DP(NETIF_MSG_LINK, "EEE negotiated - 1G\n");
3355 }
3356 }
3357 if (lp & 0x68) {
3358 lp_adv |= SHMEM_EEE_10G_ADV;
3359 if (adv & 0x68) {
3360 if (vars->line_speed == SPEED_10000)
3361 neg = 1;
3362 DP(NETIF_MSG_LINK, "EEE negotiated - 10G\n");
3363 }
3364 }
3365
3366 vars->eee_status &= ~SHMEM_EEE_LP_ADV_STATUS_MASK;
3367 vars->eee_status |= (lp_adv << SHMEM_EEE_LP_ADV_STATUS_SHIFT);
3368
3369 if (neg) {
3370 DP(NETIF_MSG_LINK, "EEE is active\n");
3371 vars->eee_status |= SHMEM_EEE_ACTIVE_BIT;
3372 }
3373
3374}
3375
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003376/******************************************************************/
3377/* BSC access functions from E3 */
3378/******************************************************************/
3379static void bnx2x_bsc_module_sel(struct link_params *params)
3380{
3381 int idx;
3382 u32 board_cfg, sfp_ctrl;
3383 u32 i2c_pins[I2C_SWITCH_WIDTH], i2c_val[I2C_SWITCH_WIDTH];
3384 struct bnx2x *bp = params->bp;
3385 u8 port = params->port;
3386 /* Read I2C output PINs */
3387 board_cfg = REG_RD(bp, params->shmem_base +
3388 offsetof(struct shmem_region,
3389 dev_info.shared_hw_config.board));
3390 i2c_pins[I2C_BSC0] = board_cfg & SHARED_HW_CFG_E3_I2C_MUX0_MASK;
3391 i2c_pins[I2C_BSC1] = (board_cfg & SHARED_HW_CFG_E3_I2C_MUX1_MASK) >>
3392 SHARED_HW_CFG_E3_I2C_MUX1_SHIFT;
3393
3394 /* Read I2C output value */
3395 sfp_ctrl = REG_RD(bp, params->shmem_base +
3396 offsetof(struct shmem_region,
3397 dev_info.port_hw_config[port].e3_cmn_pin_cfg));
3398 i2c_val[I2C_BSC0] = (sfp_ctrl & PORT_HW_CFG_E3_I2C_MUX0_MASK) > 0;
3399 i2c_val[I2C_BSC1] = (sfp_ctrl & PORT_HW_CFG_E3_I2C_MUX1_MASK) > 0;
3400 DP(NETIF_MSG_LINK, "Setting BSC switch\n");
3401 for (idx = 0; idx < I2C_SWITCH_WIDTH; idx++)
3402 bnx2x_set_cfg_pin(bp, i2c_pins[idx], i2c_val[idx]);
3403}
3404
3405static int bnx2x_bsc_read(struct link_params *params,
3406 struct bnx2x_phy *phy,
3407 u8 sl_devid,
3408 u16 sl_addr,
3409 u8 lc_addr,
3410 u8 xfer_cnt,
3411 u32 *data_array)
3412{
3413 u32 val, i;
3414 int rc = 0;
3415 struct bnx2x *bp = params->bp;
3416
3417 if ((sl_devid != 0xa0) && (sl_devid != 0xa2)) {
3418 DP(NETIF_MSG_LINK, "invalid sl_devid 0x%x\n", sl_devid);
3419 return -EINVAL;
3420 }
3421
3422 if (xfer_cnt > 16) {
3423 DP(NETIF_MSG_LINK, "invalid xfer_cnt %d. Max is 16 bytes\n",
3424 xfer_cnt);
3425 return -EINVAL;
3426 }
3427 bnx2x_bsc_module_sel(params);
3428
3429 xfer_cnt = 16 - lc_addr;
3430
Yuval Mintzd2310232012-06-20 19:05:19 +00003431 /* Enable the engine */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003432 val = REG_RD(bp, MCP_REG_MCPR_IMC_COMMAND);
3433 val |= MCPR_IMC_COMMAND_ENABLE;
3434 REG_WR(bp, MCP_REG_MCPR_IMC_COMMAND, val);
3435
Yuval Mintzd2310232012-06-20 19:05:19 +00003436 /* Program slave device ID */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003437 val = (sl_devid << 16) | sl_addr;
3438 REG_WR(bp, MCP_REG_MCPR_IMC_SLAVE_CONTROL, val);
3439
Yuval Mintzd2310232012-06-20 19:05:19 +00003440 /* Start xfer with 0 byte to update the address pointer ???*/
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003441 val = (MCPR_IMC_COMMAND_ENABLE) |
3442 (MCPR_IMC_COMMAND_WRITE_OP <<
3443 MCPR_IMC_COMMAND_OPERATION_BITSHIFT) |
3444 (lc_addr << MCPR_IMC_COMMAND_TRANSFER_ADDRESS_BITSHIFT) | (0);
3445 REG_WR(bp, MCP_REG_MCPR_IMC_COMMAND, val);
3446
Yuval Mintzd2310232012-06-20 19:05:19 +00003447 /* Poll for completion */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003448 i = 0;
3449 val = REG_RD(bp, MCP_REG_MCPR_IMC_COMMAND);
3450 while (((val >> MCPR_IMC_COMMAND_IMC_STATUS_BITSHIFT) & 0x3) != 1) {
3451 udelay(10);
3452 val = REG_RD(bp, MCP_REG_MCPR_IMC_COMMAND);
3453 if (i++ > 1000) {
3454 DP(NETIF_MSG_LINK, "wr 0 byte timed out after %d try\n",
3455 i);
3456 rc = -EFAULT;
3457 break;
3458 }
3459 }
3460 if (rc == -EFAULT)
3461 return rc;
3462
Yuval Mintzd2310232012-06-20 19:05:19 +00003463 /* Start xfer with read op */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003464 val = (MCPR_IMC_COMMAND_ENABLE) |
3465 (MCPR_IMC_COMMAND_READ_OP <<
3466 MCPR_IMC_COMMAND_OPERATION_BITSHIFT) |
3467 (lc_addr << MCPR_IMC_COMMAND_TRANSFER_ADDRESS_BITSHIFT) |
3468 (xfer_cnt);
3469 REG_WR(bp, MCP_REG_MCPR_IMC_COMMAND, val);
3470
Yuval Mintzd2310232012-06-20 19:05:19 +00003471 /* Poll for completion */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003472 i = 0;
3473 val = REG_RD(bp, MCP_REG_MCPR_IMC_COMMAND);
3474 while (((val >> MCPR_IMC_COMMAND_IMC_STATUS_BITSHIFT) & 0x3) != 1) {
3475 udelay(10);
3476 val = REG_RD(bp, MCP_REG_MCPR_IMC_COMMAND);
3477 if (i++ > 1000) {
3478 DP(NETIF_MSG_LINK, "rd op timed out after %d try\n", i);
3479 rc = -EFAULT;
3480 break;
3481 }
3482 }
3483 if (rc == -EFAULT)
3484 return rc;
3485
3486 for (i = (lc_addr >> 2); i < 4; i++) {
3487 data_array[i] = REG_RD(bp, (MCP_REG_MCPR_IMC_DATAREG0 + i*4));
3488#ifdef __BIG_ENDIAN
3489 data_array[i] = ((data_array[i] & 0x000000ff) << 24) |
3490 ((data_array[i] & 0x0000ff00) << 8) |
3491 ((data_array[i] & 0x00ff0000) >> 8) |
3492 ((data_array[i] & 0xff000000) >> 24);
3493#endif
3494 }
3495 return rc;
3496}
3497
3498static void bnx2x_cl45_read_or_write(struct bnx2x *bp, struct bnx2x_phy *phy,
3499 u8 devad, u16 reg, u16 or_val)
3500{
3501 u16 val;
3502 bnx2x_cl45_read(bp, phy, devad, reg, &val);
3503 bnx2x_cl45_write(bp, phy, devad, reg, val | or_val);
3504}
3505
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00003506int bnx2x_phy_read(struct link_params *params, u8 phy_addr,
3507 u8 devad, u16 reg, u16 *ret_val)
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003508{
3509 u8 phy_index;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00003510 /* Probe for the phy according to the given phy_addr, and execute
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003511 * the read request on it
3512 */
3513 for (phy_index = 0; phy_index < params->num_phys; phy_index++) {
3514 if (params->phy[phy_index].addr == phy_addr) {
3515 return bnx2x_cl45_read(params->bp,
3516 &params->phy[phy_index], devad,
3517 reg, ret_val);
3518 }
3519 }
3520 return -EINVAL;
3521}
3522
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00003523int bnx2x_phy_write(struct link_params *params, u8 phy_addr,
3524 u8 devad, u16 reg, u16 val)
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003525{
3526 u8 phy_index;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00003527 /* Probe for the phy according to the given phy_addr, and execute
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003528 * the write request on it
3529 */
3530 for (phy_index = 0; phy_index < params->num_phys; phy_index++) {
3531 if (params->phy[phy_index].addr == phy_addr) {
3532 return bnx2x_cl45_write(params->bp,
3533 &params->phy[phy_index], devad,
3534 reg, val);
3535 }
3536 }
3537 return -EINVAL;
3538}
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003539static u8 bnx2x_get_warpcore_lane(struct bnx2x_phy *phy,
3540 struct link_params *params)
3541{
3542 u8 lane = 0;
3543 struct bnx2x *bp = params->bp;
3544 u32 path_swap, path_swap_ovr;
3545 u8 path, port;
3546
3547 path = BP_PATH(bp);
3548 port = params->port;
3549
3550 if (bnx2x_is_4_port_mode(bp)) {
3551 u32 port_swap, port_swap_ovr;
3552
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00003553 /* Figure out path swap value */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003554 path_swap_ovr = REG_RD(bp, MISC_REG_FOUR_PORT_PATH_SWAP_OVWR);
3555 if (path_swap_ovr & 0x1)
3556 path_swap = (path_swap_ovr & 0x2);
3557 else
3558 path_swap = REG_RD(bp, MISC_REG_FOUR_PORT_PATH_SWAP);
3559
3560 if (path_swap)
3561 path = path ^ 1;
3562
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00003563 /* Figure out port swap value */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003564 port_swap_ovr = REG_RD(bp, MISC_REG_FOUR_PORT_PORT_SWAP_OVWR);
3565 if (port_swap_ovr & 0x1)
3566 port_swap = (port_swap_ovr & 0x2);
3567 else
3568 port_swap = REG_RD(bp, MISC_REG_FOUR_PORT_PORT_SWAP);
3569
3570 if (port_swap)
3571 port = port ^ 1;
3572
3573 lane = (port<<1) + path;
Yuval Mintzd2310232012-06-20 19:05:19 +00003574 } else { /* Two port mode - no port swap */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003575
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00003576 /* Figure out path swap value */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003577 path_swap_ovr =
3578 REG_RD(bp, MISC_REG_TWO_PORT_PATH_SWAP_OVWR);
3579 if (path_swap_ovr & 0x1) {
3580 path_swap = (path_swap_ovr & 0x2);
3581 } else {
3582 path_swap =
3583 REG_RD(bp, MISC_REG_TWO_PORT_PATH_SWAP);
3584 }
3585 if (path_swap)
3586 path = path ^ 1;
3587
3588 lane = path << 1 ;
3589 }
3590 return lane;
3591}
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003592
Yaniv Rosnerec146a62011-05-31 21:29:27 +00003593static void bnx2x_set_aer_mmd(struct link_params *params,
3594 struct bnx2x_phy *phy)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003595{
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003596 u32 ser_lane;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00003597 u16 offset, aer_val;
3598 struct bnx2x *bp = params->bp;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003599 ser_lane = ((params->lane_config &
3600 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_MASK) >>
3601 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_SHIFT);
3602
Yaniv Rosnerec146a62011-05-31 21:29:27 +00003603 offset = (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT) ?
3604 (phy->addr + ser_lane) : 0;
3605
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003606 if (USES_WARPCORE(bp)) {
3607 aer_val = bnx2x_get_warpcore_lane(phy, params);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00003608 /* In Dual-lane mode, two lanes are joined together,
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003609 * so in order to configure them, the AER broadcast method is
3610 * used here.
3611 * 0x200 is the broadcast address for lanes 0,1
3612 * 0x201 is the broadcast address for lanes 2,3
3613 */
3614 if (phy->flags & FLAGS_WC_DUAL_MODE)
3615 aer_val = (aer_val >> 1) | 0x200;
3616 } else if (CHIP_IS_E2(bp))
Yaniv Rosner82a0d472011-01-18 04:33:52 +00003617 aer_val = 0x3800 + offset - 1;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00003618 else
3619 aer_val = 0x3800 + offset;
Yaniv Rosner2f751a82011-11-28 00:49:52 +00003620
Yaniv Rosnercd2be892011-01-31 04:21:45 +00003621 CL22_WR_OVER_CL45(bp, phy, MDIO_REG_BANK_AER_BLOCK,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003622 MDIO_AER_BLOCK_AER_REG, aer_val);
Yaniv Rosnerec146a62011-05-31 21:29:27 +00003623
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003624}
3625
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003626/******************************************************************/
3627/* Internal phy section */
3628/******************************************************************/
3629
3630static void bnx2x_set_serdes_access(struct bnx2x *bp, u8 port)
3631{
3632 u32 emac_base = (port) ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
3633
3634 /* Set Clause 22 */
3635 REG_WR(bp, NIG_REG_SERDES0_CTRL_MD_ST + port*0x10, 1);
3636 REG_WR(bp, emac_base + EMAC_REG_EMAC_MDIO_COMM, 0x245f8000);
3637 udelay(500);
3638 REG_WR(bp, emac_base + EMAC_REG_EMAC_MDIO_COMM, 0x245d000f);
3639 udelay(500);
3640 /* Set Clause 45 */
3641 REG_WR(bp, NIG_REG_SERDES0_CTRL_MD_ST + port*0x10, 0);
3642}
3643
3644static void bnx2x_serdes_deassert(struct bnx2x *bp, u8 port)
3645{
3646 u32 val;
3647
3648 DP(NETIF_MSG_LINK, "bnx2x_serdes_deassert\n");
3649
3650 val = SERDES_RESET_BITS << (port*16);
3651
Yuval Mintzd2310232012-06-20 19:05:19 +00003652 /* Reset and unreset the SerDes/XGXS */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003653 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_CLEAR, val);
3654 udelay(500);
3655 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_SET, val);
3656
3657 bnx2x_set_serdes_access(bp, port);
3658
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003659 REG_WR(bp, NIG_REG_SERDES0_CTRL_MD_DEVAD + port*0x10,
3660 DEFAULT_PHY_DEV_ADDR);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003661}
3662
3663static void bnx2x_xgxs_deassert(struct link_params *params)
3664{
3665 struct bnx2x *bp = params->bp;
3666 u8 port;
3667 u32 val;
3668 DP(NETIF_MSG_LINK, "bnx2x_xgxs_deassert\n");
3669 port = params->port;
3670
3671 val = XGXS_RESET_BITS << (port*16);
3672
Yuval Mintzd2310232012-06-20 19:05:19 +00003673 /* Reset and unreset the SerDes/XGXS */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003674 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_CLEAR, val);
3675 udelay(500);
3676 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_SET, val);
3677
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003678 REG_WR(bp, NIG_REG_XGXS0_CTRL_MD_ST + port*0x18, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003679 REG_WR(bp, NIG_REG_XGXS0_CTRL_MD_DEVAD + port*0x18,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003680 params->phy[INT_PHY].def_md_devad);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003681}
3682
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00003683static void bnx2x_calc_ieee_aneg_adv(struct bnx2x_phy *phy,
3684 struct link_params *params, u16 *ieee_fc)
3685{
3686 struct bnx2x *bp = params->bp;
3687 *ieee_fc = MDIO_COMBO_IEEE0_AUTO_NEG_ADV_FULL_DUPLEX;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00003688 /* Resolve pause mode and advertisement Please refer to Table
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00003689 * 28B-3 of the 802.3ab-1999 spec
3690 */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003691
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00003692 switch (phy->req_flow_ctrl) {
3693 case BNX2X_FLOW_CTRL_AUTO:
3694 if (params->req_fc_auto_adv == BNX2X_FLOW_CTRL_BOTH)
3695 *ieee_fc |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH;
3696 else
3697 *ieee_fc |=
3698 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC;
3699 break;
3700
3701 case BNX2X_FLOW_CTRL_TX:
3702 *ieee_fc |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC;
3703 break;
3704
3705 case BNX2X_FLOW_CTRL_RX:
3706 case BNX2X_FLOW_CTRL_BOTH:
3707 *ieee_fc |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH;
3708 break;
3709
3710 case BNX2X_FLOW_CTRL_NONE:
3711 default:
3712 *ieee_fc |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE;
3713 break;
3714 }
3715 DP(NETIF_MSG_LINK, "ieee_fc = 0x%x\n", *ieee_fc);
3716}
3717
3718static void set_phy_vars(struct link_params *params,
3719 struct link_vars *vars)
3720{
3721 struct bnx2x *bp = params->bp;
3722 u8 actual_phy_idx, phy_index, link_cfg_idx;
3723 u8 phy_config_swapped = params->multi_phy_config &
3724 PORT_HW_CFG_PHY_SWAPPED_ENABLED;
3725 for (phy_index = INT_PHY; phy_index < params->num_phys;
3726 phy_index++) {
3727 link_cfg_idx = LINK_CONFIG_IDX(phy_index);
3728 actual_phy_idx = phy_index;
3729 if (phy_config_swapped) {
3730 if (phy_index == EXT_PHY1)
3731 actual_phy_idx = EXT_PHY2;
3732 else if (phy_index == EXT_PHY2)
3733 actual_phy_idx = EXT_PHY1;
3734 }
3735 params->phy[actual_phy_idx].req_flow_ctrl =
3736 params->req_flow_ctrl[link_cfg_idx];
3737
3738 params->phy[actual_phy_idx].req_line_speed =
3739 params->req_line_speed[link_cfg_idx];
3740
3741 params->phy[actual_phy_idx].speed_cap_mask =
3742 params->speed_cap_mask[link_cfg_idx];
3743
3744 params->phy[actual_phy_idx].req_duplex =
3745 params->req_duplex[link_cfg_idx];
3746
3747 if (params->req_line_speed[link_cfg_idx] ==
3748 SPEED_AUTO_NEG)
3749 vars->link_status |= LINK_STATUS_AUTO_NEGOTIATE_ENABLED;
3750
3751 DP(NETIF_MSG_LINK, "req_flow_ctrl %x, req_line_speed %x,"
3752 " speed_cap_mask %x\n",
3753 params->phy[actual_phy_idx].req_flow_ctrl,
3754 params->phy[actual_phy_idx].req_line_speed,
3755 params->phy[actual_phy_idx].speed_cap_mask);
3756 }
3757}
3758
3759static void bnx2x_ext_phy_set_pause(struct link_params *params,
3760 struct bnx2x_phy *phy,
3761 struct link_vars *vars)
3762{
3763 u16 val;
3764 struct bnx2x *bp = params->bp;
Yuval Mintzd2310232012-06-20 19:05:19 +00003765 /* Read modify write pause advertizing */
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00003766 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV_PAUSE, &val);
3767
3768 val &= ~MDIO_AN_REG_ADV_PAUSE_BOTH;
3769
3770 /* Please refer to Table 28B-3 of 802.3ab-1999 spec. */
3771 bnx2x_calc_ieee_aneg_adv(phy, params, &vars->ieee_fc);
3772 if ((vars->ieee_fc &
3773 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC) ==
3774 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC) {
3775 val |= MDIO_AN_REG_ADV_PAUSE_ASYMMETRIC;
3776 }
3777 if ((vars->ieee_fc &
3778 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) ==
3779 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) {
3780 val |= MDIO_AN_REG_ADV_PAUSE_PAUSE;
3781 }
3782 DP(NETIF_MSG_LINK, "Ext phy AN advertize 0x%x\n", val);
3783 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV_PAUSE, val);
3784}
3785
3786static void bnx2x_pause_resolve(struct link_vars *vars, u32 pause_result)
3787{ /* LD LP */
3788 switch (pause_result) { /* ASYM P ASYM P */
3789 case 0xb: /* 1 0 1 1 */
3790 vars->flow_ctrl = BNX2X_FLOW_CTRL_TX;
3791 break;
3792
3793 case 0xe: /* 1 1 1 0 */
3794 vars->flow_ctrl = BNX2X_FLOW_CTRL_RX;
3795 break;
3796
3797 case 0x5: /* 0 1 0 1 */
3798 case 0x7: /* 0 1 1 1 */
3799 case 0xd: /* 1 1 0 1 */
3800 case 0xf: /* 1 1 1 1 */
3801 vars->flow_ctrl = BNX2X_FLOW_CTRL_BOTH;
3802 break;
3803
3804 default:
3805 break;
3806 }
3807 if (pause_result & (1<<0))
3808 vars->link_status |= LINK_STATUS_LINK_PARTNER_SYMMETRIC_PAUSE;
3809 if (pause_result & (1<<1))
3810 vars->link_status |= LINK_STATUS_LINK_PARTNER_ASYMMETRIC_PAUSE;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00003811
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00003812}
3813
Mintz Yuval9e7e8392012-02-15 02:10:24 +00003814static void bnx2x_ext_phy_update_adv_fc(struct bnx2x_phy *phy,
3815 struct link_params *params,
3816 struct link_vars *vars)
3817{
3818 u16 ld_pause; /* local */
3819 u16 lp_pause; /* link partner */
3820 u16 pause_result;
3821 struct bnx2x *bp = params->bp;
3822 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54618SE) {
3823 bnx2x_cl22_read(bp, phy, 0x4, &ld_pause);
3824 bnx2x_cl22_read(bp, phy, 0x5, &lp_pause);
Yaniv Rosnerca05f292012-04-04 01:28:55 +00003825 } else if (CHIP_IS_E3(bp) &&
3826 SINGLE_MEDIA_DIRECT(params)) {
3827 u8 lane = bnx2x_get_warpcore_lane(phy, params);
3828 u16 gp_status, gp_mask;
3829 bnx2x_cl45_read(bp, phy,
3830 MDIO_AN_DEVAD, MDIO_WC_REG_GP2_STATUS_GP_2_4,
3831 &gp_status);
3832 gp_mask = (MDIO_WC_REG_GP2_STATUS_GP_2_4_CL73_AN_CMPL |
3833 MDIO_WC_REG_GP2_STATUS_GP_2_4_CL37_LP_AN_CAP) <<
3834 lane;
3835 if ((gp_status & gp_mask) == gp_mask) {
3836 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
3837 MDIO_AN_REG_ADV_PAUSE, &ld_pause);
3838 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
3839 MDIO_AN_REG_LP_AUTO_NEG, &lp_pause);
3840 } else {
3841 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
3842 MDIO_AN_REG_CL37_FC_LD, &ld_pause);
3843 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
3844 MDIO_AN_REG_CL37_FC_LP, &lp_pause);
3845 ld_pause = ((ld_pause &
3846 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH)
3847 << 3);
3848 lp_pause = ((lp_pause &
3849 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH)
3850 << 3);
3851 }
Mintz Yuval9e7e8392012-02-15 02:10:24 +00003852 } else {
3853 bnx2x_cl45_read(bp, phy,
3854 MDIO_AN_DEVAD,
3855 MDIO_AN_REG_ADV_PAUSE, &ld_pause);
3856 bnx2x_cl45_read(bp, phy,
3857 MDIO_AN_DEVAD,
3858 MDIO_AN_REG_LP_AUTO_NEG, &lp_pause);
3859 }
3860 pause_result = (ld_pause &
3861 MDIO_AN_REG_ADV_PAUSE_MASK) >> 8;
3862 pause_result |= (lp_pause &
3863 MDIO_AN_REG_ADV_PAUSE_MASK) >> 10;
3864 DP(NETIF_MSG_LINK, "Ext PHY pause result 0x%x\n", pause_result);
3865 bnx2x_pause_resolve(vars, pause_result);
3866
3867}
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00003868
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00003869static u8 bnx2x_ext_phy_resolve_fc(struct bnx2x_phy *phy,
3870 struct link_params *params,
3871 struct link_vars *vars)
3872{
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00003873 u8 ret = 0;
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00003874 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
Mintz Yuval9e7e8392012-02-15 02:10:24 +00003875 if (phy->req_flow_ctrl != BNX2X_FLOW_CTRL_AUTO) {
3876 /* Update the advertised flow-controled of LD/LP in AN */
3877 if (phy->req_line_speed == SPEED_AUTO_NEG)
3878 bnx2x_ext_phy_update_adv_fc(phy, params, vars);
3879 /* But set the flow-control result as the requested one */
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00003880 vars->flow_ctrl = phy->req_flow_ctrl;
Mintz Yuval9e7e8392012-02-15 02:10:24 +00003881 } else if (phy->req_line_speed != SPEED_AUTO_NEG)
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00003882 vars->flow_ctrl = params->req_fc_auto_adv;
3883 else if (vars->link_status & LINK_STATUS_AUTO_NEGOTIATE_COMPLETE) {
3884 ret = 1;
Mintz Yuval9e7e8392012-02-15 02:10:24 +00003885 bnx2x_ext_phy_update_adv_fc(phy, params, vars);
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00003886 }
3887 return ret;
3888}
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003889/******************************************************************/
3890/* Warpcore section */
3891/******************************************************************/
3892/* The init_internal_warpcore should mirror the xgxs,
3893 * i.e. reset the lane (if needed), set aer for the
3894 * init configuration, and set/clear SGMII flag. Internal
3895 * phy init is done purely in phy_init stage.
3896 */
Yuval Mintzec4010e2012-09-10 05:51:06 +00003897
3898static void bnx2x_warpcore_set_lpi_passthrough(struct bnx2x_phy *phy,
3899 struct link_params *params)
3900{
3901 struct bnx2x *bp = params->bp;
3902
3903 DP(NETIF_MSG_LINK, "Configure WC for LPI pass through\n");
3904 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3905 MDIO_WC_REG_EEE_COMBO_CONTROL0, 0x7c);
3906 bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
3907 MDIO_WC_REG_DIGITAL4_MISC5, 0xc000);
3908}
3909
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003910static void bnx2x_warpcore_enable_AN_KR(struct bnx2x_phy *phy,
3911 struct link_params *params,
3912 struct link_vars *vars) {
Yuval Mintza351d492012-06-20 19:05:21 +00003913 u16 val16 = 0, lane, i;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003914 struct bnx2x *bp = params->bp;
Yuval Mintza351d492012-06-20 19:05:21 +00003915 static struct bnx2x_reg_set reg_set[] = {
3916 {MDIO_WC_DEVAD, MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2, 0x7},
3917 {MDIO_AN_DEVAD, MDIO_WC_REG_PAR_DET_10G_CTRL, 0},
3918 {MDIO_WC_DEVAD, MDIO_WC_REG_CL72_USERB0_CL72_MISC1_CONTROL, 0},
3919 {MDIO_WC_DEVAD, MDIO_WC_REG_XGXSBLK1_LANECTRL0, 0xff},
3920 {MDIO_WC_DEVAD, MDIO_WC_REG_XGXSBLK1_LANECTRL1, 0x5555},
3921 {MDIO_PMA_DEVAD, MDIO_WC_REG_IEEE0BLK_AUTONEGNP, 0x0},
3922 {MDIO_WC_DEVAD, MDIO_WC_REG_RX66_CONTROL, 0x7415},
3923 {MDIO_WC_DEVAD, MDIO_WC_REG_SERDESDIGITAL_MISC2, 0x6190},
3924 /* Disable Autoneg: re-enable it after adv is done. */
3925 {MDIO_AN_DEVAD, MDIO_WC_REG_IEEE0BLK_MIICNTL, 0}
3926 };
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003927 DP(NETIF_MSG_LINK, "Enable Auto Negotiation for KR\n");
Yaniv Rosner6a51c0d2012-04-04 01:28:56 +00003928 /* Set to default registers that may be overriden by 10G force */
Yuval Mintza351d492012-06-20 19:05:21 +00003929 for (i = 0; i < sizeof(reg_set)/sizeof(struct bnx2x_reg_set); i++)
3930 bnx2x_cl45_write(bp, phy, reg_set[i].devad, reg_set[i].reg,
3931 reg_set[i].val);
Yaniv Rosnera9077bf2011-10-27 05:09:46 +00003932
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003933 /* Check adding advertisement for 1G KX */
3934 if (((vars->line_speed == SPEED_AUTO_NEG) &&
3935 (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) ||
3936 (vars->line_speed == SPEED_1000)) {
Yuval Mintza351d492012-06-20 19:05:21 +00003937 u32 addr = MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003938 val16 |= (1<<5);
3939
3940 /* Enable CL37 1G Parallel Detect */
Yuval Mintza351d492012-06-20 19:05:21 +00003941 bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD, addr, 0x1);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003942 DP(NETIF_MSG_LINK, "Advertize 1G\n");
3943 }
3944 if (((vars->line_speed == SPEED_AUTO_NEG) &&
3945 (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) ||
3946 (vars->line_speed == SPEED_10000)) {
3947 /* Check adding advertisement for 10G KR */
3948 val16 |= (1<<7);
3949 /* Enable 10G Parallel Detect */
3950 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
Yuval Mintza351d492012-06-20 19:05:21 +00003951 MDIO_WC_REG_PAR_DET_10G_CTRL, 1);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003952
3953 DP(NETIF_MSG_LINK, "Advertize 10G\n");
3954 }
3955
3956 /* Set Transmit PMD settings */
3957 lane = bnx2x_get_warpcore_lane(phy, params);
3958 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3959 MDIO_WC_REG_TX0_TX_DRIVER + 0x10*lane,
3960 ((0x02 << MDIO_WC_REG_TX0_TX_DRIVER_POST2_COEFF_OFFSET) |
3961 (0x06 << MDIO_WC_REG_TX0_TX_DRIVER_IDRIVER_OFFSET) |
3962 (0x09 << MDIO_WC_REG_TX0_TX_DRIVER_IPRE_DRIVER_OFFSET)));
3963 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3964 MDIO_WC_REG_CL72_USERB0_CL72_OS_DEF_CTRL,
3965 0x03f0);
3966 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3967 MDIO_WC_REG_CL72_USERB0_CL72_2P5_DEF_CTRL,
3968 0x03f0);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003969
3970 /* Advertised speeds */
3971 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
3972 MDIO_WC_REG_AN_IEEE1BLK_AN_ADVERTISEMENT1, val16);
3973
David S. Miller8decf862011-09-22 03:23:13 -04003974 /* Advertised and set FEC (Forward Error Correction) */
3975 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
3976 MDIO_WC_REG_AN_IEEE1BLK_AN_ADVERTISEMENT2,
3977 (MDIO_WC_REG_AN_IEEE1BLK_AN_ADV2_FEC_ABILITY |
3978 MDIO_WC_REG_AN_IEEE1BLK_AN_ADV2_FEC_REQ));
3979
Yaniv Rosnera34bc962011-07-05 01:06:41 +00003980 /* Enable CL37 BAM */
3981 if (REG_RD(bp, params->shmem_base +
3982 offsetof(struct shmem_region, dev_info.
3983 port_hw_config[params->port].default_cfg)) &
3984 PORT_HW_CFG_ENABLE_BAM_ON_KR_ENABLED) {
Yuval Mintza351d492012-06-20 19:05:21 +00003985 bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
3986 MDIO_WC_REG_DIGITAL6_MP5_NEXTPAGECTRL,
3987 1);
Yaniv Rosnera34bc962011-07-05 01:06:41 +00003988 DP(NETIF_MSG_LINK, "Enable CL37 BAM on KR\n");
3989 }
3990
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003991 /* Advertise pause */
3992 bnx2x_ext_phy_set_pause(params, phy, vars);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00003993 /* Set KR Autoneg Work-Around flag for Warpcore version older than D108
Yaniv Rosner6ab48a52012-01-17 02:33:29 +00003994 */
3995 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
3996 MDIO_WC_REG_UC_INFO_B1_VERSION, &val16);
3997 if (val16 < 0xd108) {
3998 DP(NETIF_MSG_LINK, "Enable AN KR work-around\n");
3999 vars->rx_tx_asic_rst = MAX_KR_LINK_RETRY;
4000 }
Yuval Mintza351d492012-06-20 19:05:21 +00004001 bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
4002 MDIO_WC_REG_DIGITAL5_MISC7, 0x100);
Yaniv Rosnera9077bf2011-10-27 05:09:46 +00004003
4004 /* Over 1G - AN local device user page 1 */
4005 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4006 MDIO_WC_REG_DIGITAL3_UP1, 0x1f);
4007
4008 /* Enable Autoneg */
4009 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
Mintz Yuval1b85ae52012-02-15 02:10:25 +00004010 MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x1200);
Yaniv Rosnera9077bf2011-10-27 05:09:46 +00004011
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004012}
4013
4014static void bnx2x_warpcore_set_10G_KR(struct bnx2x_phy *phy,
4015 struct link_params *params,
4016 struct link_vars *vars)
4017{
4018 struct bnx2x *bp = params->bp;
Yuval Mintza351d492012-06-20 19:05:21 +00004019 u16 i;
4020 static struct bnx2x_reg_set reg_set[] = {
4021 /* Disable Autoneg */
4022 {MDIO_WC_DEVAD, MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2, 0x7},
4023 {MDIO_AN_DEVAD, MDIO_WC_REG_PAR_DET_10G_CTRL, 0},
4024 {MDIO_WC_DEVAD, MDIO_WC_REG_CL72_USERB0_CL72_MISC1_CONTROL,
4025 0x3f00},
4026 {MDIO_AN_DEVAD, MDIO_WC_REG_AN_IEEE1BLK_AN_ADVERTISEMENT1, 0},
4027 {MDIO_AN_DEVAD, MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x0},
4028 {MDIO_WC_DEVAD, MDIO_WC_REG_DIGITAL3_UP1, 0x1},
4029 {MDIO_WC_DEVAD, MDIO_WC_REG_DIGITAL5_MISC7, 0xa},
4030 /* Disable CL36 PCS Tx */
4031 {MDIO_WC_DEVAD, MDIO_WC_REG_XGXSBLK1_LANECTRL0, 0x0},
4032 /* Double Wide Single Data Rate @ pll rate */
4033 {MDIO_WC_DEVAD, MDIO_WC_REG_XGXSBLK1_LANECTRL1, 0xFFFF},
4034 /* Leave cl72 training enable, needed for KR */
4035 {MDIO_PMA_DEVAD,
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004036 MDIO_WC_REG_PMD_IEEE9BLK_TENGBASE_KR_PMD_CONTROL_REGISTER_150,
Yuval Mintza351d492012-06-20 19:05:21 +00004037 0x2}
4038 };
4039
4040 for (i = 0; i < sizeof(reg_set)/sizeof(struct bnx2x_reg_set); i++)
4041 bnx2x_cl45_write(bp, phy, reg_set[i].devad, reg_set[i].reg,
4042 reg_set[i].val);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004043
4044 /* Leave CL72 enabled */
Yuval Mintza351d492012-06-20 19:05:21 +00004045 bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
4046 MDIO_WC_REG_CL72_USERB0_CL72_MISC1_CONTROL,
4047 0x3800);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004048
4049 /* Set speed via PMA/PMD register */
4050 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD,
4051 MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x2040);
4052
4053 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD,
4054 MDIO_WC_REG_IEEE0BLK_AUTONEGNP, 0xB);
4055
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00004056 /* Enable encoded forced speed */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004057 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4058 MDIO_WC_REG_SERDESDIGITAL_MISC2, 0x30);
4059
4060 /* Turn TX scramble payload only the 64/66 scrambler */
4061 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4062 MDIO_WC_REG_TX66_CONTROL, 0x9);
4063
4064 /* Turn RX scramble payload only the 64/66 scrambler */
4065 bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
4066 MDIO_WC_REG_RX66_CONTROL, 0xF9);
4067
Yuval Mintzd2310232012-06-20 19:05:19 +00004068 /* Set and clear loopback to cause a reset to 64/66 decoder */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004069 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4070 MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x4000);
4071 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4072 MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x0);
4073
4074}
4075
4076static void bnx2x_warpcore_set_10G_XFI(struct bnx2x_phy *phy,
4077 struct link_params *params,
4078 u8 is_xfi)
4079{
4080 struct bnx2x *bp = params->bp;
4081 u16 misc1_val, tap_val, tx_driver_val, lane, val;
4082 /* Hold rxSeqStart */
Yuval Mintza351d492012-06-20 19:05:21 +00004083 bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
4084 MDIO_WC_REG_DSC2B0_DSC_MISC_CTRL0, 0x8000);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004085
4086 /* Hold tx_fifo_reset */
Yuval Mintza351d492012-06-20 19:05:21 +00004087 bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
4088 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X3, 0x1);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004089
4090 /* Disable CL73 AN */
4091 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0);
4092
4093 /* Disable 100FX Enable and Auto-Detect */
4094 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4095 MDIO_WC_REG_FX100_CTRL1, &val);
4096 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4097 MDIO_WC_REG_FX100_CTRL1, (val & 0xFFFA));
4098
4099 /* Disable 100FX Idle detect */
Yuval Mintza351d492012-06-20 19:05:21 +00004100 bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
4101 MDIO_WC_REG_FX100_CTRL3, 0x0080);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004102
4103 /* Set Block address to Remote PHY & Clear forced_speed[5] */
4104 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4105 MDIO_WC_REG_DIGITAL4_MISC3, &val);
4106 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4107 MDIO_WC_REG_DIGITAL4_MISC3, (val & 0xFF7F));
4108
4109 /* Turn off auto-detect & fiber mode */
4110 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4111 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X1, &val);
4112 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4113 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X1,
4114 (val & 0xFFEE));
4115
4116 /* Set filter_force_link, disable_false_link and parallel_detect */
4117 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4118 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2, &val);
4119 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4120 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2,
4121 ((val | 0x0006) & 0xFFFE));
4122
4123 /* Set XFI / SFI */
4124 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4125 MDIO_WC_REG_SERDESDIGITAL_MISC1, &misc1_val);
4126
4127 misc1_val &= ~(0x1f);
4128
4129 if (is_xfi) {
4130 misc1_val |= 0x5;
4131 tap_val = ((0x08 << MDIO_WC_REG_TX_FIR_TAP_POST_TAP_OFFSET) |
4132 (0x37 << MDIO_WC_REG_TX_FIR_TAP_MAIN_TAP_OFFSET) |
4133 (0x00 << MDIO_WC_REG_TX_FIR_TAP_PRE_TAP_OFFSET));
4134 tx_driver_val =
4135 ((0x00 << MDIO_WC_REG_TX0_TX_DRIVER_POST2_COEFF_OFFSET) |
4136 (0x02 << MDIO_WC_REG_TX0_TX_DRIVER_IDRIVER_OFFSET) |
4137 (0x03 << MDIO_WC_REG_TX0_TX_DRIVER_IPRE_DRIVER_OFFSET));
4138
4139 } else {
4140 misc1_val |= 0x9;
Yaniv Rosner25182fc2012-04-04 01:28:57 +00004141 tap_val = ((0x0f << MDIO_WC_REG_TX_FIR_TAP_POST_TAP_OFFSET) |
4142 (0x2b << MDIO_WC_REG_TX_FIR_TAP_MAIN_TAP_OFFSET) |
4143 (0x02 << MDIO_WC_REG_TX_FIR_TAP_PRE_TAP_OFFSET));
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004144 tx_driver_val =
Yaniv Rosner25182fc2012-04-04 01:28:57 +00004145 ((0x03 << MDIO_WC_REG_TX0_TX_DRIVER_POST2_COEFF_OFFSET) |
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004146 (0x02 << MDIO_WC_REG_TX0_TX_DRIVER_IDRIVER_OFFSET) |
Yaniv Rosner25182fc2012-04-04 01:28:57 +00004147 (0x06 << MDIO_WC_REG_TX0_TX_DRIVER_IPRE_DRIVER_OFFSET));
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004148 }
4149 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4150 MDIO_WC_REG_SERDESDIGITAL_MISC1, misc1_val);
4151
4152 /* Set Transmit PMD settings */
4153 lane = bnx2x_get_warpcore_lane(phy, params);
4154 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4155 MDIO_WC_REG_TX_FIR_TAP,
4156 tap_val | MDIO_WC_REG_TX_FIR_TAP_ENABLE);
4157 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4158 MDIO_WC_REG_TX0_TX_DRIVER + 0x10*lane,
4159 tx_driver_val);
4160
4161 /* Enable fiber mode, enable and invert sig_det */
Yuval Mintza351d492012-06-20 19:05:21 +00004162 bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
4163 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X1, 0xd);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004164
4165 /* Set Block address to Remote PHY & Set forced_speed[5], 40bit mode */
Yuval Mintza351d492012-06-20 19:05:21 +00004166 bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
4167 MDIO_WC_REG_DIGITAL4_MISC3, 0x8080);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004168
Yuval Mintzec4010e2012-09-10 05:51:06 +00004169 bnx2x_warpcore_set_lpi_passthrough(phy, params);
Yuval Mintzc8c60d82012-06-06 17:13:07 +00004170
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004171 /* 10G XFI Full Duplex */
4172 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4173 MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x100);
4174
4175 /* Release tx_fifo_reset */
4176 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4177 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X3, &val);
4178 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4179 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X3, val & 0xFFFE);
4180
4181 /* Release rxSeqStart */
4182 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4183 MDIO_WC_REG_DSC2B0_DSC_MISC_CTRL0, &val);
4184 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4185 MDIO_WC_REG_DSC2B0_DSC_MISC_CTRL0, (val & 0x7FFF));
4186}
4187
4188static void bnx2x_warpcore_set_20G_KR2(struct bnx2x *bp,
4189 struct bnx2x_phy *phy)
4190{
4191 DP(NETIF_MSG_LINK, "KR2 still not supported !!!\n");
4192}
4193
4194static void bnx2x_warpcore_set_20G_DXGXS(struct bnx2x *bp,
4195 struct bnx2x_phy *phy,
4196 u16 lane)
4197{
4198 /* Rx0 anaRxControl1G */
4199 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4200 MDIO_WC_REG_RX0_ANARXCONTROL1G, 0x90);
4201
4202 /* Rx2 anaRxControl1G */
4203 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4204 MDIO_WC_REG_RX2_ANARXCONTROL1G, 0x90);
4205
4206 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4207 MDIO_WC_REG_RX66_SCW0, 0xE070);
4208
4209 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4210 MDIO_WC_REG_RX66_SCW1, 0xC0D0);
4211
4212 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4213 MDIO_WC_REG_RX66_SCW2, 0xA0B0);
4214
4215 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4216 MDIO_WC_REG_RX66_SCW3, 0x8090);
4217
4218 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4219 MDIO_WC_REG_RX66_SCW0_MASK, 0xF0F0);
4220
4221 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4222 MDIO_WC_REG_RX66_SCW1_MASK, 0xF0F0);
4223
4224 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4225 MDIO_WC_REG_RX66_SCW2_MASK, 0xF0F0);
4226
4227 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4228 MDIO_WC_REG_RX66_SCW3_MASK, 0xF0F0);
4229
4230 /* Serdes Digital Misc1 */
4231 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4232 MDIO_WC_REG_SERDESDIGITAL_MISC1, 0x6008);
4233
4234 /* Serdes Digital4 Misc3 */
4235 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4236 MDIO_WC_REG_DIGITAL4_MISC3, 0x8088);
4237
4238 /* Set Transmit PMD settings */
4239 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4240 MDIO_WC_REG_TX_FIR_TAP,
4241 ((0x12 << MDIO_WC_REG_TX_FIR_TAP_POST_TAP_OFFSET) |
4242 (0x2d << MDIO_WC_REG_TX_FIR_TAP_MAIN_TAP_OFFSET) |
4243 (0x00 << MDIO_WC_REG_TX_FIR_TAP_PRE_TAP_OFFSET) |
4244 MDIO_WC_REG_TX_FIR_TAP_ENABLE));
4245 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4246 MDIO_WC_REG_TX0_TX_DRIVER + 0x10*lane,
4247 ((0x02 << MDIO_WC_REG_TX0_TX_DRIVER_POST2_COEFF_OFFSET) |
4248 (0x02 << MDIO_WC_REG_TX0_TX_DRIVER_IDRIVER_OFFSET) |
4249 (0x02 << MDIO_WC_REG_TX0_TX_DRIVER_IPRE_DRIVER_OFFSET)));
4250}
4251
4252static void bnx2x_warpcore_set_sgmii_speed(struct bnx2x_phy *phy,
4253 struct link_params *params,
Yaniv Rosner521683d2011-11-28 00:49:48 +00004254 u8 fiber_mode,
4255 u8 always_autoneg)
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004256{
4257 struct bnx2x *bp = params->bp;
4258 u16 val16, digctrl_kx1, digctrl_kx2;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004259
4260 /* Clear XFI clock comp in non-10G single lane mode. */
4261 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4262 MDIO_WC_REG_RX66_CONTROL, &val16);
4263 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4264 MDIO_WC_REG_RX66_CONTROL, val16 & ~(3<<13));
4265
Yaniv Rosner521683d2011-11-28 00:49:48 +00004266 if (always_autoneg || phy->req_line_speed == SPEED_AUTO_NEG) {
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004267 /* SGMII Autoneg */
4268 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4269 MDIO_WC_REG_COMBO_IEEE0_MIICTRL, &val16);
4270 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4271 MDIO_WC_REG_COMBO_IEEE0_MIICTRL,
4272 val16 | 0x1000);
4273 DP(NETIF_MSG_LINK, "set SGMII AUTONEG\n");
4274 } else {
4275 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4276 MDIO_WC_REG_COMBO_IEEE0_MIICTRL, &val16);
Yaniv Rosner521683d2011-11-28 00:49:48 +00004277 val16 &= 0xcebf;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004278 switch (phy->req_line_speed) {
4279 case SPEED_10:
4280 break;
4281 case SPEED_100:
4282 val16 |= 0x2000;
4283 break;
4284 case SPEED_1000:
4285 val16 |= 0x0040;
4286 break;
4287 default:
Joe Perches94f05b02011-08-14 12:16:20 +00004288 DP(NETIF_MSG_LINK,
4289 "Speed not supported: 0x%x\n", phy->req_line_speed);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004290 return;
4291 }
4292
4293 if (phy->req_duplex == DUPLEX_FULL)
4294 val16 |= 0x0100;
4295
4296 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4297 MDIO_WC_REG_COMBO_IEEE0_MIICTRL, val16);
4298
4299 DP(NETIF_MSG_LINK, "set SGMII force speed %d\n",
4300 phy->req_line_speed);
4301 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4302 MDIO_WC_REG_COMBO_IEEE0_MIICTRL, &val16);
4303 DP(NETIF_MSG_LINK, " (readback) %x\n", val16);
4304 }
4305
4306 /* SGMII Slave mode and disable signal detect */
4307 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4308 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X1, &digctrl_kx1);
4309 if (fiber_mode)
4310 digctrl_kx1 = 1;
4311 else
4312 digctrl_kx1 &= 0xff4a;
4313
4314 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4315 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X1,
4316 digctrl_kx1);
4317
4318 /* Turn off parallel detect */
4319 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4320 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2, &digctrl_kx2);
4321 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4322 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2,
4323 (digctrl_kx2 & ~(1<<2)));
4324
4325 /* Re-enable parallel detect */
4326 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4327 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2,
4328 (digctrl_kx2 | (1<<2)));
4329
4330 /* Enable autodet */
4331 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4332 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X1,
4333 (digctrl_kx1 | 0x10));
4334}
4335
4336static void bnx2x_warpcore_reset_lane(struct bnx2x *bp,
4337 struct bnx2x_phy *phy,
4338 u8 reset)
4339{
4340 u16 val;
4341 /* Take lane out of reset after configuration is finished */
4342 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4343 MDIO_WC_REG_DIGITAL5_MISC6, &val);
4344 if (reset)
4345 val |= 0xC000;
4346 else
4347 val &= 0x3FFF;
4348 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4349 MDIO_WC_REG_DIGITAL5_MISC6, val);
4350 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4351 MDIO_WC_REG_DIGITAL5_MISC6, &val);
4352}
Yaniv Rosner2f751a82011-11-28 00:49:52 +00004353/* Clear SFI/XFI link settings registers */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004354static void bnx2x_warpcore_clear_regs(struct bnx2x_phy *phy,
4355 struct link_params *params,
4356 u16 lane)
4357{
4358 struct bnx2x *bp = params->bp;
Yuval Mintza351d492012-06-20 19:05:21 +00004359 u16 i;
4360 static struct bnx2x_reg_set wc_regs[] = {
4361 {MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0},
4362 {MDIO_WC_DEVAD, MDIO_WC_REG_FX100_CTRL1, 0x014a},
4363 {MDIO_WC_DEVAD, MDIO_WC_REG_FX100_CTRL3, 0x0800},
4364 {MDIO_WC_DEVAD, MDIO_WC_REG_DIGITAL4_MISC3, 0x8008},
4365 {MDIO_WC_DEVAD, MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X1,
4366 0x0195},
4367 {MDIO_WC_DEVAD, MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2,
4368 0x0007},
4369 {MDIO_WC_DEVAD, MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X3,
4370 0x0002},
4371 {MDIO_WC_DEVAD, MDIO_WC_REG_SERDESDIGITAL_MISC1, 0x6000},
4372 {MDIO_WC_DEVAD, MDIO_WC_REG_TX_FIR_TAP, 0x0000},
4373 {MDIO_WC_DEVAD, MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x2040},
4374 {MDIO_WC_DEVAD, MDIO_WC_REG_COMBO_IEEE0_MIICTRL, 0x0140}
4375 };
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004376 /* Set XFI clock comp as default. */
Yuval Mintza351d492012-06-20 19:05:21 +00004377 bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
4378 MDIO_WC_REG_RX66_CONTROL, (3<<13));
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004379
Yuval Mintza351d492012-06-20 19:05:21 +00004380 for (i = 0; i < sizeof(wc_regs)/sizeof(struct bnx2x_reg_set); i++)
4381 bnx2x_cl45_write(bp, phy, wc_regs[i].devad, wc_regs[i].reg,
4382 wc_regs[i].val);
4383
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004384 lane = bnx2x_get_warpcore_lane(phy, params);
4385 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004386 MDIO_WC_REG_TX0_TX_DRIVER + 0x10*lane, 0x0990);
Yuval Mintza351d492012-06-20 19:05:21 +00004387
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004388}
4389
4390static int bnx2x_get_mod_abs_int_cfg(struct bnx2x *bp,
4391 u32 chip_id,
4392 u32 shmem_base, u8 port,
4393 u8 *gpio_num, u8 *gpio_port)
4394{
4395 u32 cfg_pin;
4396 *gpio_num = 0;
4397 *gpio_port = 0;
4398 if (CHIP_IS_E3(bp)) {
4399 cfg_pin = (REG_RD(bp, shmem_base +
4400 offsetof(struct shmem_region,
4401 dev_info.port_hw_config[port].e3_sfp_ctrl)) &
4402 PORT_HW_CFG_E3_MOD_ABS_MASK) >>
4403 PORT_HW_CFG_E3_MOD_ABS_SHIFT;
4404
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00004405 /* Should not happen. This function called upon interrupt
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004406 * triggered by GPIO ( since EPIO can only generate interrupts
4407 * to MCP).
4408 * So if this function was called and none of the GPIOs was set,
4409 * it means the shit hit the fan.
4410 */
4411 if ((cfg_pin < PIN_CFG_GPIO0_P0) ||
4412 (cfg_pin > PIN_CFG_GPIO3_P1)) {
Joe Perches94f05b02011-08-14 12:16:20 +00004413 DP(NETIF_MSG_LINK,
4414 "ERROR: Invalid cfg pin %x for module detect indication\n",
4415 cfg_pin);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004416 return -EINVAL;
4417 }
4418
4419 *gpio_num = (cfg_pin - PIN_CFG_GPIO0_P0) & 0x3;
4420 *gpio_port = (cfg_pin - PIN_CFG_GPIO0_P0) >> 2;
4421 } else {
4422 *gpio_num = MISC_REGISTERS_GPIO_3;
4423 *gpio_port = port;
4424 }
4425 DP(NETIF_MSG_LINK, "MOD_ABS int GPIO%d_P%d\n", *gpio_num, *gpio_port);
4426 return 0;
4427}
4428
4429static int bnx2x_is_sfp_module_plugged(struct bnx2x_phy *phy,
4430 struct link_params *params)
4431{
4432 struct bnx2x *bp = params->bp;
4433 u8 gpio_num, gpio_port;
4434 u32 gpio_val;
4435 if (bnx2x_get_mod_abs_int_cfg(bp, params->chip_id,
4436 params->shmem_base, params->port,
4437 &gpio_num, &gpio_port) != 0)
4438 return 0;
4439 gpio_val = bnx2x_get_gpio(bp, gpio_num, gpio_port);
4440
4441 /* Call the handling function in case module is detected */
4442 if (gpio_val == 0)
4443 return 1;
4444 else
4445 return 0;
4446}
Yaniv Rosnera9077bf2011-10-27 05:09:46 +00004447static int bnx2x_warpcore_get_sigdet(struct bnx2x_phy *phy,
4448 struct link_params *params)
4449{
4450 u16 gp2_status_reg0, lane;
4451 struct bnx2x *bp = params->bp;
4452
4453 lane = bnx2x_get_warpcore_lane(phy, params);
4454
4455 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD, MDIO_WC_REG_GP2_STATUS_GP_2_0,
4456 &gp2_status_reg0);
4457
4458 return (gp2_status_reg0 >> (8+lane)) & 0x1;
4459}
4460
4461static void bnx2x_warpcore_config_runtime(struct bnx2x_phy *phy,
4462 struct link_params *params,
4463 struct link_vars *vars)
4464{
4465 struct bnx2x *bp = params->bp;
4466 u32 serdes_net_if;
4467 u16 gp_status1 = 0, lnkup = 0, lnkup_kr = 0;
4468 u16 lane = bnx2x_get_warpcore_lane(phy, params);
4469
4470 vars->turn_to_run_wc_rt = vars->turn_to_run_wc_rt ? 0 : 1;
4471
4472 if (!vars->turn_to_run_wc_rt)
4473 return;
4474
Yuval Mintzd2310232012-06-20 19:05:19 +00004475 /* Return if there is no link partner */
Yaniv Rosnera9077bf2011-10-27 05:09:46 +00004476 if (!(bnx2x_warpcore_get_sigdet(phy, params))) {
4477 DP(NETIF_MSG_LINK, "bnx2x_warpcore_get_sigdet false\n");
4478 return;
4479 }
4480
4481 if (vars->rx_tx_asic_rst) {
4482 serdes_net_if = (REG_RD(bp, params->shmem_base +
4483 offsetof(struct shmem_region, dev_info.
4484 port_hw_config[params->port].default_cfg)) &
4485 PORT_HW_CFG_NET_SERDES_IF_MASK);
4486
4487 switch (serdes_net_if) {
4488 case PORT_HW_CFG_NET_SERDES_IF_KR:
4489 /* Do we get link yet? */
4490 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD, 0x81d1,
4491 &gp_status1);
4492 lnkup = (gp_status1 >> (8+lane)) & 0x1;/* 1G */
4493 /*10G KR*/
4494 lnkup_kr = (gp_status1 >> (12+lane)) & 0x1;
4495
4496 DP(NETIF_MSG_LINK,
4497 "gp_status1 0x%x\n", gp_status1);
4498
4499 if (lnkup_kr || lnkup) {
4500 vars->rx_tx_asic_rst = 0;
4501 DP(NETIF_MSG_LINK,
4502 "link up, rx_tx_asic_rst 0x%x\n",
4503 vars->rx_tx_asic_rst);
4504 } else {
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00004505 /* Reset the lane to see if link comes up.*/
Yaniv Rosnera9077bf2011-10-27 05:09:46 +00004506 bnx2x_warpcore_reset_lane(bp, phy, 1);
4507 bnx2x_warpcore_reset_lane(bp, phy, 0);
4508
Yuval Mintzd2310232012-06-20 19:05:19 +00004509 /* Restart Autoneg */
Yaniv Rosnera9077bf2011-10-27 05:09:46 +00004510 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
4511 MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x1200);
4512
4513 vars->rx_tx_asic_rst--;
4514 DP(NETIF_MSG_LINK, "0x%x retry left\n",
4515 vars->rx_tx_asic_rst);
4516 }
4517 break;
4518
4519 default:
4520 break;
4521 }
4522
4523 } /*params->rx_tx_asic_rst*/
4524
4525}
Yuval Mintzdbef8072012-06-20 19:05:22 +00004526static void bnx2x_warpcore_config_sfi(struct bnx2x_phy *phy,
4527 struct link_params *params)
4528{
4529 u16 lane = bnx2x_get_warpcore_lane(phy, params);
4530 struct bnx2x *bp = params->bp;
4531 bnx2x_warpcore_clear_regs(phy, params, lane);
4532 if ((params->req_line_speed[LINK_CONFIG_IDX(INT_PHY)] ==
4533 SPEED_10000) &&
4534 (phy->media_type != ETH_PHY_SFP_1G_FIBER)) {
4535 DP(NETIF_MSG_LINK, "Setting 10G SFI\n");
4536 bnx2x_warpcore_set_10G_XFI(phy, params, 0);
4537 } else {
4538 DP(NETIF_MSG_LINK, "Setting 1G Fiber\n");
4539 bnx2x_warpcore_set_sgmii_speed(phy, params, 1, 0);
4540 }
4541}
4542
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004543static void bnx2x_warpcore_config_init(struct bnx2x_phy *phy,
4544 struct link_params *params,
4545 struct link_vars *vars)
4546{
4547 struct bnx2x *bp = params->bp;
4548 u32 serdes_net_if;
4549 u8 fiber_mode;
4550 u16 lane = bnx2x_get_warpcore_lane(phy, params);
4551 serdes_net_if = (REG_RD(bp, params->shmem_base +
4552 offsetof(struct shmem_region, dev_info.
4553 port_hw_config[params->port].default_cfg)) &
4554 PORT_HW_CFG_NET_SERDES_IF_MASK);
4555 DP(NETIF_MSG_LINK, "Begin Warpcore init, link_speed %d, "
4556 "serdes_net_if = 0x%x\n",
4557 vars->line_speed, serdes_net_if);
4558 bnx2x_set_aer_mmd(params, phy);
4559
4560 vars->phy_flags |= PHY_XGXS_FLAG;
4561 if ((serdes_net_if == PORT_HW_CFG_NET_SERDES_IF_SGMII) ||
4562 (phy->req_line_speed &&
4563 ((phy->req_line_speed == SPEED_100) ||
4564 (phy->req_line_speed == SPEED_10)))) {
4565 vars->phy_flags |= PHY_SGMII_FLAG;
4566 DP(NETIF_MSG_LINK, "Setting SGMII mode\n");
4567 bnx2x_warpcore_clear_regs(phy, params, lane);
Yaniv Rosner521683d2011-11-28 00:49:48 +00004568 bnx2x_warpcore_set_sgmii_speed(phy, params, 0, 1);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004569 } else {
4570 switch (serdes_net_if) {
4571 case PORT_HW_CFG_NET_SERDES_IF_KR:
4572 /* Enable KR Auto Neg */
Yaniv Rosner6a51c0d2012-04-04 01:28:56 +00004573 if (params->loopback_mode != LOOPBACK_EXT)
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004574 bnx2x_warpcore_enable_AN_KR(phy, params, vars);
4575 else {
4576 DP(NETIF_MSG_LINK, "Setting KR 10G-Force\n");
4577 bnx2x_warpcore_set_10G_KR(phy, params, vars);
4578 }
4579 break;
4580
4581 case PORT_HW_CFG_NET_SERDES_IF_XFI:
4582 bnx2x_warpcore_clear_regs(phy, params, lane);
4583 if (vars->line_speed == SPEED_10000) {
4584 DP(NETIF_MSG_LINK, "Setting 10G XFI\n");
4585 bnx2x_warpcore_set_10G_XFI(phy, params, 1);
4586 } else {
4587 if (SINGLE_MEDIA_DIRECT(params)) {
4588 DP(NETIF_MSG_LINK, "1G Fiber\n");
4589 fiber_mode = 1;
4590 } else {
4591 DP(NETIF_MSG_LINK, "10/100/1G SGMII\n");
4592 fiber_mode = 0;
4593 }
4594 bnx2x_warpcore_set_sgmii_speed(phy,
4595 params,
Yaniv Rosner521683d2011-11-28 00:49:48 +00004596 fiber_mode,
4597 0);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004598 }
4599
4600 break;
4601
4602 case PORT_HW_CFG_NET_SERDES_IF_SFI:
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004603 /* Issue Module detection */
4604 if (bnx2x_is_sfp_module_plugged(phy, params))
4605 bnx2x_sfp_module_detection(phy, params);
Yuval Mintzdbef8072012-06-20 19:05:22 +00004606
4607 bnx2x_warpcore_config_sfi(phy, params);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004608 break;
4609
4610 case PORT_HW_CFG_NET_SERDES_IF_DXGXS:
4611 if (vars->line_speed != SPEED_20000) {
4612 DP(NETIF_MSG_LINK, "Speed not supported yet\n");
4613 return;
4614 }
4615 DP(NETIF_MSG_LINK, "Setting 20G DXGXS\n");
4616 bnx2x_warpcore_set_20G_DXGXS(bp, phy, lane);
4617 /* Issue Module detection */
4618
4619 bnx2x_sfp_module_detection(phy, params);
4620 break;
4621
4622 case PORT_HW_CFG_NET_SERDES_IF_KR2:
4623 if (vars->line_speed != SPEED_20000) {
4624 DP(NETIF_MSG_LINK, "Speed not supported yet\n");
4625 return;
4626 }
4627 DP(NETIF_MSG_LINK, "Setting 20G KR2\n");
4628 bnx2x_warpcore_set_20G_KR2(bp, phy);
4629 break;
4630
4631 default:
Joe Perches94f05b02011-08-14 12:16:20 +00004632 DP(NETIF_MSG_LINK,
4633 "Unsupported Serdes Net Interface 0x%x\n",
4634 serdes_net_if);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004635 return;
4636 }
4637 }
4638
4639 /* Take lane out of reset after configuration is finished */
4640 bnx2x_warpcore_reset_lane(bp, phy, 0);
4641 DP(NETIF_MSG_LINK, "Exit config init\n");
4642}
4643
4644static void bnx2x_sfp_e3_set_transmitter(struct link_params *params,
4645 struct bnx2x_phy *phy,
4646 u8 tx_en)
4647{
4648 struct bnx2x *bp = params->bp;
4649 u32 cfg_pin;
4650 u8 port = params->port;
4651
4652 cfg_pin = REG_RD(bp, params->shmem_base +
4653 offsetof(struct shmem_region,
4654 dev_info.port_hw_config[port].e3_sfp_ctrl)) &
4655 PORT_HW_CFG_TX_LASER_MASK;
4656 /* Set the !tx_en since this pin is DISABLE_TX_LASER */
4657 DP(NETIF_MSG_LINK, "Setting WC TX to %d\n", tx_en);
4658 /* For 20G, the expected pin to be used is 3 pins after the current */
4659
4660 bnx2x_set_cfg_pin(bp, cfg_pin, tx_en ^ 1);
4661 if (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_20G)
4662 bnx2x_set_cfg_pin(bp, cfg_pin + 3, tx_en ^ 1);
4663}
4664
4665static void bnx2x_warpcore_link_reset(struct bnx2x_phy *phy,
4666 struct link_params *params)
4667{
4668 struct bnx2x *bp = params->bp;
4669 u16 val16;
4670 bnx2x_sfp_e3_set_transmitter(params, phy, 0);
4671 bnx2x_set_mdio_clk(bp, params->chip_id, params->port);
4672 bnx2x_set_aer_mmd(params, phy);
4673 /* Global register */
4674 bnx2x_warpcore_reset_lane(bp, phy, 1);
4675
4676 /* Clear loopback settings (if any) */
4677 /* 10G & 20G */
4678 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4679 MDIO_WC_REG_COMBO_IEEE0_MIICTRL, &val16);
4680 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4681 MDIO_WC_REG_COMBO_IEEE0_MIICTRL, val16 &
4682 0xBFFF);
4683
4684 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4685 MDIO_WC_REG_IEEE0BLK_MIICNTL, &val16);
4686 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4687 MDIO_WC_REG_IEEE0BLK_MIICNTL, val16 & 0xfffe);
4688
4689 /* Update those 1-copy registers */
4690 CL22_WR_OVER_CL45(bp, phy, MDIO_REG_BANK_AER_BLOCK,
4691 MDIO_AER_BLOCK_AER_REG, 0);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00004692 /* Enable 1G MDIO (1-copy) */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004693 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4694 MDIO_WC_REG_XGXSBLK0_XGXSCONTROL,
4695 &val16);
4696 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4697 MDIO_WC_REG_XGXSBLK0_XGXSCONTROL,
4698 val16 & ~0x10);
4699
4700 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4701 MDIO_WC_REG_XGXSBLK1_LANECTRL2, &val16);
4702 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4703 MDIO_WC_REG_XGXSBLK1_LANECTRL2,
4704 val16 & 0xff00);
4705
4706}
4707
4708static void bnx2x_set_warpcore_loopback(struct bnx2x_phy *phy,
4709 struct link_params *params)
4710{
4711 struct bnx2x *bp = params->bp;
4712 u16 val16;
4713 u32 lane;
4714 DP(NETIF_MSG_LINK, "Setting Warpcore loopback type %x, speed %d\n",
4715 params->loopback_mode, phy->req_line_speed);
4716
4717 if (phy->req_line_speed < SPEED_10000) {
4718 /* 10/100/1000 */
4719
4720 /* Update those 1-copy registers */
4721 CL22_WR_OVER_CL45(bp, phy, MDIO_REG_BANK_AER_BLOCK,
4722 MDIO_AER_BLOCK_AER_REG, 0);
4723 /* Enable 1G MDIO (1-copy) */
Yuval Mintza351d492012-06-20 19:05:21 +00004724 bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
4725 MDIO_WC_REG_XGXSBLK0_XGXSCONTROL,
4726 0x10);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004727 /* Set 1G loopback based on lane (1-copy) */
4728 lane = bnx2x_get_warpcore_lane(phy, params);
4729 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4730 MDIO_WC_REG_XGXSBLK1_LANECTRL2, &val16);
4731 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4732 MDIO_WC_REG_XGXSBLK1_LANECTRL2,
4733 val16 | (1<<lane));
4734
4735 /* Switch back to 4-copy registers */
4736 bnx2x_set_aer_mmd(params, phy);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004737 } else {
4738 /* 10G & 20G */
Yuval Mintza351d492012-06-20 19:05:21 +00004739 bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
4740 MDIO_WC_REG_COMBO_IEEE0_MIICTRL,
4741 0x4000);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004742
Yuval Mintza351d492012-06-20 19:05:21 +00004743 bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
4744 MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x1);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004745 }
4746}
4747
4748
Yuval Mintzd2310232012-06-20 19:05:19 +00004749
4750static void bnx2x_sync_link(struct link_params *params,
4751 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004752{
4753 struct bnx2x *bp = params->bp;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00004754 u8 link_10g_plus;
Yaniv Rosnerde6f3372011-08-02 22:59:25 +00004755 if (vars->link_status & LINK_STATUS_PHYSICAL_LINK_FLAG)
4756 vars->phy_flags |= PHY_PHYSICAL_LINK_FLAG;
Yaniv Rosner2f751a82011-11-28 00:49:52 +00004757 vars->link_up = (vars->link_status & LINK_STATUS_LINK_UP);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004758 if (vars->link_up) {
4759 DP(NETIF_MSG_LINK, "phy link up\n");
4760
4761 vars->phy_link_up = 1;
4762 vars->duplex = DUPLEX_FULL;
4763 switch (vars->link_status &
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004764 LINK_STATUS_SPEED_AND_DUPLEX_MASK) {
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00004765 case LINK_10THD:
4766 vars->duplex = DUPLEX_HALF;
4767 /* Fall thru */
4768 case LINK_10TFD:
4769 vars->line_speed = SPEED_10;
4770 break;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004771
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00004772 case LINK_100TXHD:
4773 vars->duplex = DUPLEX_HALF;
4774 /* Fall thru */
4775 case LINK_100T4:
4776 case LINK_100TXFD:
4777 vars->line_speed = SPEED_100;
4778 break;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004779
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00004780 case LINK_1000THD:
4781 vars->duplex = DUPLEX_HALF;
4782 /* Fall thru */
4783 case LINK_1000TFD:
4784 vars->line_speed = SPEED_1000;
4785 break;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004786
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00004787 case LINK_2500THD:
4788 vars->duplex = DUPLEX_HALF;
4789 /* Fall thru */
4790 case LINK_2500TFD:
4791 vars->line_speed = SPEED_2500;
4792 break;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004793
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00004794 case LINK_10GTFD:
4795 vars->line_speed = SPEED_10000;
4796 break;
4797 case LINK_20GTFD:
4798 vars->line_speed = SPEED_20000;
4799 break;
4800 default:
4801 break;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004802 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004803 vars->flow_ctrl = 0;
4804 if (vars->link_status & LINK_STATUS_TX_FLOW_CONTROL_ENABLED)
4805 vars->flow_ctrl |= BNX2X_FLOW_CTRL_TX;
4806
4807 if (vars->link_status & LINK_STATUS_RX_FLOW_CONTROL_ENABLED)
4808 vars->flow_ctrl |= BNX2X_FLOW_CTRL_RX;
4809
4810 if (!vars->flow_ctrl)
4811 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
4812
4813 if (vars->line_speed &&
4814 ((vars->line_speed == SPEED_10) ||
4815 (vars->line_speed == SPEED_100))) {
4816 vars->phy_flags |= PHY_SGMII_FLAG;
4817 } else {
4818 vars->phy_flags &= ~PHY_SGMII_FLAG;
4819 }
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004820 if (vars->line_speed &&
4821 USES_WARPCORE(bp) &&
4822 (vars->line_speed == SPEED_1000))
4823 vars->phy_flags |= PHY_SGMII_FLAG;
Yuval Mintzd2310232012-06-20 19:05:19 +00004824 /* Anything 10 and over uses the bmac */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00004825 link_10g_plus = (vars->line_speed >= SPEED_10000);
4826
4827 if (link_10g_plus) {
4828 if (USES_WARPCORE(bp))
4829 vars->mac_type = MAC_TYPE_XMAC;
4830 else
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004831 vars->mac_type = MAC_TYPE_BMAC;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00004832 } else {
4833 if (USES_WARPCORE(bp))
4834 vars->mac_type = MAC_TYPE_UMAC;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004835 else
4836 vars->mac_type = MAC_TYPE_EMAC;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00004837 }
Yuval Mintzd2310232012-06-20 19:05:19 +00004838 } else { /* Link down */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004839 DP(NETIF_MSG_LINK, "phy link down\n");
4840
4841 vars->phy_link_up = 0;
4842
4843 vars->line_speed = 0;
4844 vars->duplex = DUPLEX_FULL;
4845 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
4846
Yuval Mintzd2310232012-06-20 19:05:19 +00004847 /* Indicate no mac active */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004848 vars->mac_type = MAC_TYPE_NONE;
Yaniv Rosnerde6f3372011-08-02 22:59:25 +00004849 if (vars->link_status & LINK_STATUS_PHYSICAL_LINK_FLAG)
4850 vars->phy_flags |= PHY_HALF_OPEN_CONN_FLAG;
Yuval Mintzd0b8a6f2012-06-20 19:05:18 +00004851 if (vars->link_status & LINK_STATUS_SFP_TX_FAULT)
4852 vars->phy_flags |= PHY_SFP_TX_FAULT_FLAG;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004853 }
Yaniv Rosner2f751a82011-11-28 00:49:52 +00004854}
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004855
Yaniv Rosner2f751a82011-11-28 00:49:52 +00004856void bnx2x_link_status_update(struct link_params *params,
4857 struct link_vars *vars)
4858{
4859 struct bnx2x *bp = params->bp;
4860 u8 port = params->port;
4861 u32 sync_offset, media_types;
4862 /* Update PHY configuration */
4863 set_phy_vars(params, vars);
4864
4865 vars->link_status = REG_RD(bp, params->shmem_base +
4866 offsetof(struct shmem_region,
4867 port_mb[port].link_status));
Yuval Mintz08e9acc2012-09-10 05:51:04 +00004868 if (bnx2x_eee_has_cap(params))
4869 vars->eee_status = REG_RD(bp, params->shmem2_base +
4870 offsetof(struct shmem2_region,
4871 eee_status[params->port]));
Yaniv Rosner2f751a82011-11-28 00:49:52 +00004872
4873 vars->phy_flags = PHY_XGXS_FLAG;
4874 bnx2x_sync_link(params, vars);
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00004875 /* Sync media type */
4876 sync_offset = params->shmem_base +
4877 offsetof(struct shmem_region,
4878 dev_info.port_hw_config[port].media_type);
4879 media_types = REG_RD(bp, sync_offset);
4880
4881 params->phy[INT_PHY].media_type =
4882 (media_types & PORT_HW_CFG_MEDIA_TYPE_PHY0_MASK) >>
4883 PORT_HW_CFG_MEDIA_TYPE_PHY0_SHIFT;
4884 params->phy[EXT_PHY1].media_type =
4885 (media_types & PORT_HW_CFG_MEDIA_TYPE_PHY1_MASK) >>
4886 PORT_HW_CFG_MEDIA_TYPE_PHY1_SHIFT;
4887 params->phy[EXT_PHY2].media_type =
4888 (media_types & PORT_HW_CFG_MEDIA_TYPE_PHY2_MASK) >>
4889 PORT_HW_CFG_MEDIA_TYPE_PHY2_SHIFT;
4890 DP(NETIF_MSG_LINK, "media_types = 0x%x\n", media_types);
4891
Yaniv Rosner020c7e32011-05-31 21:28:43 +00004892 /* Sync AEU offset */
4893 sync_offset = params->shmem_base +
4894 offsetof(struct shmem_region,
4895 dev_info.port_hw_config[port].aeu_int_mask);
4896
4897 vars->aeu_int_mask = REG_RD(bp, sync_offset);
4898
Yaniv Rosnerb8d6d082011-07-05 01:06:27 +00004899 /* Sync PFC status */
4900 if (vars->link_status & LINK_STATUS_PFC_ENABLED)
4901 params->feature_config_flags |=
4902 FEATURE_CONFIG_PFC_ENABLED;
4903 else
4904 params->feature_config_flags &=
4905 ~FEATURE_CONFIG_PFC_ENABLED;
4906
Yaniv Rosner020c7e32011-05-31 21:28:43 +00004907 DP(NETIF_MSG_LINK, "link_status 0x%x phy_link_up %x int_mask 0x%x\n",
4908 vars->link_status, vars->phy_link_up, vars->aeu_int_mask);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004909 DP(NETIF_MSG_LINK, "line_speed %x duplex %x flow_ctrl 0x%x\n",
4910 vars->line_speed, vars->duplex, vars->flow_ctrl);
4911}
4912
Yaniv Rosnere10bc842010-09-07 11:40:50 +00004913static void bnx2x_set_master_ln(struct link_params *params,
4914 struct bnx2x_phy *phy)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004915{
4916 struct bnx2x *bp = params->bp;
4917 u16 new_master_ln, ser_lane;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004918 ser_lane = ((params->lane_config &
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004919 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_MASK) >>
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004920 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_SHIFT);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004921
Yuval Mintzd2310232012-06-20 19:05:19 +00004922 /* Set the master_ln for AN */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004923 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004924 MDIO_REG_BANK_XGXS_BLOCK2,
4925 MDIO_XGXS_BLOCK2_TEST_MODE_LANE,
4926 &new_master_ln);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004927
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004928 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004929 MDIO_REG_BANK_XGXS_BLOCK2 ,
4930 MDIO_XGXS_BLOCK2_TEST_MODE_LANE,
4931 (new_master_ln | ser_lane));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004932}
4933
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00004934static int bnx2x_reset_unicore(struct link_params *params,
4935 struct bnx2x_phy *phy,
4936 u8 set_serdes)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004937{
4938 struct bnx2x *bp = params->bp;
4939 u16 mii_control;
4940 u16 i;
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004941 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004942 MDIO_REG_BANK_COMBO_IEEE0,
4943 MDIO_COMBO_IEEE0_MII_CONTROL, &mii_control);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004944
Yuval Mintzd2310232012-06-20 19:05:19 +00004945 /* Reset the unicore */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004946 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004947 MDIO_REG_BANK_COMBO_IEEE0,
4948 MDIO_COMBO_IEEE0_MII_CONTROL,
4949 (mii_control |
4950 MDIO_COMBO_IEEO_MII_CONTROL_RESET));
Yaniv Rosnere10bc842010-09-07 11:40:50 +00004951 if (set_serdes)
4952 bnx2x_set_serdes_access(bp, params->port);
Eilon Greensteinc1b73992009-02-12 08:37:07 +00004953
Yuval Mintzd2310232012-06-20 19:05:19 +00004954 /* Wait for the reset to self clear */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004955 for (i = 0; i < MDIO_ACCESS_TIMEOUT; i++) {
4956 udelay(5);
4957
Yuval Mintzd2310232012-06-20 19:05:19 +00004958 /* The reset erased the previous bank value */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004959 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004960 MDIO_REG_BANK_COMBO_IEEE0,
4961 MDIO_COMBO_IEEE0_MII_CONTROL,
4962 &mii_control);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004963
4964 if (!(mii_control & MDIO_COMBO_IEEO_MII_CONTROL_RESET)) {
4965 udelay(5);
4966 return 0;
4967 }
4968 }
4969
Yaniv Rosner6d870c32011-01-31 04:22:20 +00004970 netdev_err(bp->dev, "Warning: PHY was not initialized,"
4971 " Port %d\n",
4972 params->port);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004973 DP(NETIF_MSG_LINK, "BUG! XGXS is still in reset!\n");
4974 return -EINVAL;
4975
4976}
4977
Yaniv Rosnere10bc842010-09-07 11:40:50 +00004978static void bnx2x_set_swap_lanes(struct link_params *params,
4979 struct bnx2x_phy *phy)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004980{
4981 struct bnx2x *bp = params->bp;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00004982 /* Each two bits represents a lane number:
4983 * No swap is 0123 => 0x1b no need to enable the swap
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00004984 */
Yaniv Rosner2f751a82011-11-28 00:49:52 +00004985 u16 rx_lane_swap, tx_lane_swap;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004986
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004987 rx_lane_swap = ((params->lane_config &
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004988 PORT_HW_CFG_LANE_SWAP_CFG_RX_MASK) >>
4989 PORT_HW_CFG_LANE_SWAP_CFG_RX_SHIFT);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004990 tx_lane_swap = ((params->lane_config &
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004991 PORT_HW_CFG_LANE_SWAP_CFG_TX_MASK) >>
4992 PORT_HW_CFG_LANE_SWAP_CFG_TX_SHIFT);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004993
4994 if (rx_lane_swap != 0x1b) {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004995 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004996 MDIO_REG_BANK_XGXS_BLOCK2,
4997 MDIO_XGXS_BLOCK2_RX_LN_SWAP,
4998 (rx_lane_swap |
4999 MDIO_XGXS_BLOCK2_RX_LN_SWAP_ENABLE |
5000 MDIO_XGXS_BLOCK2_RX_LN_SWAP_FORCE_ENABLE));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005001 } else {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005002 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005003 MDIO_REG_BANK_XGXS_BLOCK2,
5004 MDIO_XGXS_BLOCK2_RX_LN_SWAP, 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005005 }
5006
5007 if (tx_lane_swap != 0x1b) {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005008 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005009 MDIO_REG_BANK_XGXS_BLOCK2,
5010 MDIO_XGXS_BLOCK2_TX_LN_SWAP,
5011 (tx_lane_swap |
5012 MDIO_XGXS_BLOCK2_TX_LN_SWAP_ENABLE));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005013 } else {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005014 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005015 MDIO_REG_BANK_XGXS_BLOCK2,
5016 MDIO_XGXS_BLOCK2_TX_LN_SWAP, 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005017 }
5018}
5019
Yaniv Rosnere10bc842010-09-07 11:40:50 +00005020static void bnx2x_set_parallel_detection(struct bnx2x_phy *phy,
5021 struct link_params *params)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005022{
5023 struct bnx2x *bp = params->bp;
5024 u16 control2;
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005025 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005026 MDIO_REG_BANK_SERDES_DIGITAL,
5027 MDIO_SERDES_DIGITAL_A_1000X_CONTROL2,
5028 &control2);
Yaniv Rosner7aa07112010-09-07 11:41:01 +00005029 if (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)
Yaniv Rosner18afb0a2009-11-05 19:18:04 +02005030 control2 |= MDIO_SERDES_DIGITAL_A_1000X_CONTROL2_PRL_DT_EN;
5031 else
5032 control2 &= ~MDIO_SERDES_DIGITAL_A_1000X_CONTROL2_PRL_DT_EN;
Yaniv Rosner7aa07112010-09-07 11:41:01 +00005033 DP(NETIF_MSG_LINK, "phy->speed_cap_mask = 0x%x, control2 = 0x%x\n",
5034 phy->speed_cap_mask, control2);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005035 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005036 MDIO_REG_BANK_SERDES_DIGITAL,
5037 MDIO_SERDES_DIGITAL_A_1000X_CONTROL2,
5038 control2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005039
Yaniv Rosnere10bc842010-09-07 11:40:50 +00005040 if ((phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT) &&
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00005041 (phy->speed_cap_mask &
Yaniv Rosner18afb0a2009-11-05 19:18:04 +02005042 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005043 DP(NETIF_MSG_LINK, "XGXS\n");
5044
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005045 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005046 MDIO_REG_BANK_10G_PARALLEL_DETECT,
5047 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_LINK,
5048 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_LINK_CNT);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005049
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005050 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005051 MDIO_REG_BANK_10G_PARALLEL_DETECT,
5052 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_CONTROL,
5053 &control2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005054
5055
5056 control2 |=
5057 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_CONTROL_PARDET10G_EN;
5058
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005059 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005060 MDIO_REG_BANK_10G_PARALLEL_DETECT,
5061 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_CONTROL,
5062 control2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005063
5064 /* Disable parallel detection of HiG */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005065 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005066 MDIO_REG_BANK_XGXS_BLOCK2,
5067 MDIO_XGXS_BLOCK2_UNICORE_MODE_10G,
5068 MDIO_XGXS_BLOCK2_UNICORE_MODE_10G_CX4_XGXS |
5069 MDIO_XGXS_BLOCK2_UNICORE_MODE_10G_HIGIG_XGXS);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005070 }
5071}
5072
Yaniv Rosnere10bc842010-09-07 11:40:50 +00005073static void bnx2x_set_autoneg(struct bnx2x_phy *phy,
5074 struct link_params *params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005075 struct link_vars *vars,
5076 u8 enable_cl73)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005077{
5078 struct bnx2x *bp = params->bp;
5079 u16 reg_val;
5080
5081 /* CL37 Autoneg */
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, &reg_val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005085
5086 /* CL37 Autoneg Enabled */
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07005087 if (vars->line_speed == SPEED_AUTO_NEG)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005088 reg_val |= MDIO_COMBO_IEEO_MII_CONTROL_AN_EN;
5089 else /* CL37 Autoneg Disabled */
5090 reg_val &= ~(MDIO_COMBO_IEEO_MII_CONTROL_AN_EN |
5091 MDIO_COMBO_IEEO_MII_CONTROL_RESTART_AN);
5092
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005093 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005094 MDIO_REG_BANK_COMBO_IEEE0,
5095 MDIO_COMBO_IEEE0_MII_CONTROL, reg_val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005096
5097 /* Enable/Disable Autodetection */
5098
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005099 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005100 MDIO_REG_BANK_SERDES_DIGITAL,
5101 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1, &reg_val);
Eilon Greenstein239d6862009-08-12 08:23:04 +00005102 reg_val &= ~(MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_SIGNAL_DETECT_EN |
5103 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_INVERT_SIGNAL_DETECT);
5104 reg_val |= MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_FIBER_MODE;
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07005105 if (vars->line_speed == SPEED_AUTO_NEG)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005106 reg_val |= MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_AUTODET;
5107 else
5108 reg_val &= ~MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_AUTODET;
5109
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005110 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005111 MDIO_REG_BANK_SERDES_DIGITAL,
5112 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1, reg_val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005113
5114 /* Enable TetonII and BAM autoneg */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005115 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005116 MDIO_REG_BANK_BAM_NEXT_PAGE,
5117 MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL,
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005118 &reg_val);
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07005119 if (vars->line_speed == SPEED_AUTO_NEG) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005120 /* Enable BAM aneg Mode and TetonII aneg Mode */
5121 reg_val |= (MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL_BAM_MODE |
5122 MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL_TETON_AN);
5123 } else {
5124 /* TetonII and BAM Autoneg Disabled */
5125 reg_val &= ~(MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL_BAM_MODE |
5126 MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL_TETON_AN);
5127 }
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005128 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005129 MDIO_REG_BANK_BAM_NEXT_PAGE,
5130 MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL,
5131 reg_val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005132
Eilon Greenstein239d6862009-08-12 08:23:04 +00005133 if (enable_cl73) {
5134 /* Enable Cl73 FSM status bits */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005135 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005136 MDIO_REG_BANK_CL73_USERB0,
5137 MDIO_CL73_USERB0_CL73_UCTRL,
5138 0xe);
Eilon Greenstein239d6862009-08-12 08:23:04 +00005139
5140 /* Enable BAM Station Manager*/
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005141 CL22_WR_OVER_CL45(bp, phy,
Eilon Greenstein239d6862009-08-12 08:23:04 +00005142 MDIO_REG_BANK_CL73_USERB0,
5143 MDIO_CL73_USERB0_CL73_BAM_CTRL1,
5144 MDIO_CL73_USERB0_CL73_BAM_CTRL1_BAM_EN |
5145 MDIO_CL73_USERB0_CL73_BAM_CTRL1_BAM_STATION_MNGR_EN |
5146 MDIO_CL73_USERB0_CL73_BAM_CTRL1_BAM_NP_AFTER_BP_EN);
5147
Yaniv Rosner7846e472009-11-05 19:18:07 +02005148 /* Advertise CL73 link speeds */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005149 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005150 MDIO_REG_BANK_CL73_IEEEB1,
5151 MDIO_CL73_IEEEB1_AN_ADV2,
5152 &reg_val);
Yaniv Rosner7aa07112010-09-07 11:41:01 +00005153 if (phy->speed_cap_mask &
Yaniv Rosner7846e472009-11-05 19:18:07 +02005154 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
5155 reg_val |= MDIO_CL73_IEEEB1_AN_ADV2_ADVR_10G_KX4;
Yaniv Rosner7aa07112010-09-07 11:41:01 +00005156 if (phy->speed_cap_mask &
Yaniv Rosner7846e472009-11-05 19:18:07 +02005157 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)
5158 reg_val |= MDIO_CL73_IEEEB1_AN_ADV2_ADVR_1000M_KX;
Eilon Greenstein239d6862009-08-12 08:23:04 +00005159
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005160 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005161 MDIO_REG_BANK_CL73_IEEEB1,
5162 MDIO_CL73_IEEEB1_AN_ADV2,
5163 reg_val);
Eilon Greenstein239d6862009-08-12 08:23:04 +00005164
Eilon Greenstein239d6862009-08-12 08:23:04 +00005165 /* CL73 Autoneg Enabled */
5166 reg_val = MDIO_CL73_IEEEB0_CL73_AN_CONTROL_AN_EN;
5167
5168 } else /* CL73 Autoneg Disabled */
5169 reg_val = 0;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005170
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005171 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005172 MDIO_REG_BANK_CL73_IEEEB0,
5173 MDIO_CL73_IEEEB0_CL73_AN_CONTROL, reg_val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005174}
5175
Yuval Mintzd2310232012-06-20 19:05:19 +00005176/* Program SerDes, forced speed */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00005177static void bnx2x_program_serdes(struct bnx2x_phy *phy,
5178 struct link_params *params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005179 struct link_vars *vars)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005180{
5181 struct bnx2x *bp = params->bp;
5182 u16 reg_val;
5183
Yuval Mintzd2310232012-06-20 19:05:19 +00005184 /* Program duplex, disable autoneg and sgmii*/
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005185 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005186 MDIO_REG_BANK_COMBO_IEEE0,
5187 MDIO_COMBO_IEEE0_MII_CONTROL, &reg_val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005188 reg_val &= ~(MDIO_COMBO_IEEO_MII_CONTROL_FULL_DUPLEX |
Eilon Greenstein57937202009-08-12 08:23:53 +00005189 MDIO_COMBO_IEEO_MII_CONTROL_AN_EN |
5190 MDIO_COMBO_IEEO_MII_CONTROL_MAN_SGMII_SP_MASK);
Yaniv Rosner7aa07112010-09-07 11:41:01 +00005191 if (phy->req_duplex == DUPLEX_FULL)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005192 reg_val |= MDIO_COMBO_IEEO_MII_CONTROL_FULL_DUPLEX;
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005193 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005194 MDIO_REG_BANK_COMBO_IEEE0,
5195 MDIO_COMBO_IEEE0_MII_CONTROL, reg_val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005196
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00005197 /* Program speed
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005198 * - needed only if the speed is greater than 1G (2.5G or 10G)
5199 */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005200 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005201 MDIO_REG_BANK_SERDES_DIGITAL,
5202 MDIO_SERDES_DIGITAL_MISC1, &reg_val);
Yuval Mintzd2310232012-06-20 19:05:19 +00005203 /* Clearing the speed value before setting the right speed */
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07005204 DP(NETIF_MSG_LINK, "MDIO_REG_BANK_SERDES_DIGITAL = 0x%x\n", reg_val);
5205
5206 reg_val &= ~(MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_MASK |
5207 MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_SEL);
5208
5209 if (!((vars->line_speed == SPEED_1000) ||
5210 (vars->line_speed == SPEED_100) ||
5211 (vars->line_speed == SPEED_10))) {
5212
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005213 reg_val |= (MDIO_SERDES_DIGITAL_MISC1_REFCLK_SEL_156_25M |
5214 MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_SEL);
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07005215 if (vars->line_speed == SPEED_10000)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005216 reg_val |=
5217 MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_10G_CX4;
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07005218 }
5219
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005220 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005221 MDIO_REG_BANK_SERDES_DIGITAL,
5222 MDIO_SERDES_DIGITAL_MISC1, reg_val);
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07005223
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005224}
5225
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00005226static void bnx2x_set_brcm_cl37_advertisement(struct bnx2x_phy *phy,
5227 struct link_params *params)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005228{
5229 struct bnx2x *bp = params->bp;
5230 u16 val = 0;
5231
Yuval Mintzd2310232012-06-20 19:05:19 +00005232 /* Set extended capabilities */
Yaniv Rosner7aa07112010-09-07 11:41:01 +00005233 if (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005234 val |= MDIO_OVER_1G_UP1_2_5G;
Yaniv Rosner7aa07112010-09-07 11:41:01 +00005235 if (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005236 val |= MDIO_OVER_1G_UP1_10G;
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005237 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005238 MDIO_REG_BANK_OVER_1G,
5239 MDIO_OVER_1G_UP1, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005240
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005241 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005242 MDIO_REG_BANK_OVER_1G,
5243 MDIO_OVER_1G_UP3, 0x400);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005244}
5245
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00005246static void bnx2x_set_ieee_aneg_advertisement(struct bnx2x_phy *phy,
5247 struct link_params *params,
5248 u16 ieee_fc)
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07005249{
5250 struct bnx2x *bp = params->bp;
Yaniv Rosner7846e472009-11-05 19:18:07 +02005251 u16 val;
Yuval Mintzd2310232012-06-20 19:05:19 +00005252 /* For AN, we are always publishing full duplex */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005253
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005254 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005255 MDIO_REG_BANK_COMBO_IEEE0,
5256 MDIO_COMBO_IEEE0_AUTO_NEG_ADV, ieee_fc);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005257 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005258 MDIO_REG_BANK_CL73_IEEEB1,
5259 MDIO_CL73_IEEEB1_AN_ADV1, &val);
Yaniv Rosner7846e472009-11-05 19:18:07 +02005260 val &= ~MDIO_CL73_IEEEB1_AN_ADV1_PAUSE_BOTH;
5261 val |= ((ieee_fc<<3) & MDIO_CL73_IEEEB1_AN_ADV1_PAUSE_MASK);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005262 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005263 MDIO_REG_BANK_CL73_IEEEB1,
5264 MDIO_CL73_IEEEB1_AN_ADV1, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005265}
5266
Yaniv Rosnere10bc842010-09-07 11:40:50 +00005267static void bnx2x_restart_autoneg(struct bnx2x_phy *phy,
5268 struct link_params *params,
5269 u8 enable_cl73)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005270{
5271 struct bnx2x *bp = params->bp;
Eilon Greenstein3a36f2e2009-02-12 08:37:09 +00005272 u16 mii_control;
Eilon Greenstein239d6862009-08-12 08:23:04 +00005273
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005274 DP(NETIF_MSG_LINK, "bnx2x_restart_autoneg\n");
Eilon Greenstein3a36f2e2009-02-12 08:37:09 +00005275 /* Enable and restart BAM/CL37 aneg */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005276
Eilon Greenstein239d6862009-08-12 08:23:04 +00005277 if (enable_cl73) {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005278 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005279 MDIO_REG_BANK_CL73_IEEEB0,
5280 MDIO_CL73_IEEEB0_CL73_AN_CONTROL,
5281 &mii_control);
Eilon Greenstein239d6862009-08-12 08:23:04 +00005282
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005283 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005284 MDIO_REG_BANK_CL73_IEEEB0,
5285 MDIO_CL73_IEEEB0_CL73_AN_CONTROL,
5286 (mii_control |
5287 MDIO_CL73_IEEEB0_CL73_AN_CONTROL_AN_EN |
5288 MDIO_CL73_IEEEB0_CL73_AN_CONTROL_RESTART_AN));
Eilon Greenstein239d6862009-08-12 08:23:04 +00005289 } else {
5290
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005291 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005292 MDIO_REG_BANK_COMBO_IEEE0,
5293 MDIO_COMBO_IEEE0_MII_CONTROL,
5294 &mii_control);
Eilon Greenstein239d6862009-08-12 08:23:04 +00005295 DP(NETIF_MSG_LINK,
5296 "bnx2x_restart_autoneg mii_control before = 0x%x\n",
5297 mii_control);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005298 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005299 MDIO_REG_BANK_COMBO_IEEE0,
5300 MDIO_COMBO_IEEE0_MII_CONTROL,
5301 (mii_control |
5302 MDIO_COMBO_IEEO_MII_CONTROL_AN_EN |
5303 MDIO_COMBO_IEEO_MII_CONTROL_RESTART_AN));
Eilon Greenstein239d6862009-08-12 08:23:04 +00005304 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005305}
5306
Yaniv Rosnere10bc842010-09-07 11:40:50 +00005307static void bnx2x_initialize_sgmii_process(struct bnx2x_phy *phy,
5308 struct link_params *params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005309 struct link_vars *vars)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005310{
5311 struct bnx2x *bp = params->bp;
5312 u16 control1;
5313
Yuval Mintzd2310232012-06-20 19:05:19 +00005314 /* In SGMII mode, the unicore is always slave */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005315
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005316 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005317 MDIO_REG_BANK_SERDES_DIGITAL,
5318 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1,
5319 &control1);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005320 control1 |= MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_INVERT_SIGNAL_DETECT;
Yuval Mintzd2310232012-06-20 19:05:19 +00005321 /* Set sgmii mode (and not fiber) */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005322 control1 &= ~(MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_FIBER_MODE |
5323 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_AUTODET |
5324 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_MSTR_MODE);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005325 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005326 MDIO_REG_BANK_SERDES_DIGITAL,
5327 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1,
5328 control1);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005329
Yuval Mintzd2310232012-06-20 19:05:19 +00005330 /* If forced speed */
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07005331 if (!(vars->line_speed == SPEED_AUTO_NEG)) {
Yuval Mintzd2310232012-06-20 19:05:19 +00005332 /* Set speed, disable autoneg */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005333 u16 mii_control;
5334
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005335 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005336 MDIO_REG_BANK_COMBO_IEEE0,
5337 MDIO_COMBO_IEEE0_MII_CONTROL,
5338 &mii_control);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005339 mii_control &= ~(MDIO_COMBO_IEEO_MII_CONTROL_AN_EN |
5340 MDIO_COMBO_IEEO_MII_CONTROL_MAN_SGMII_SP_MASK|
5341 MDIO_COMBO_IEEO_MII_CONTROL_FULL_DUPLEX);
5342
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07005343 switch (vars->line_speed) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005344 case SPEED_100:
5345 mii_control |=
5346 MDIO_COMBO_IEEO_MII_CONTROL_MAN_SGMII_SP_100;
5347 break;
5348 case SPEED_1000:
5349 mii_control |=
5350 MDIO_COMBO_IEEO_MII_CONTROL_MAN_SGMII_SP_1000;
5351 break;
5352 case SPEED_10:
Yuval Mintzd2310232012-06-20 19:05:19 +00005353 /* There is nothing to set for 10M */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005354 break;
5355 default:
Yuval Mintzd2310232012-06-20 19:05:19 +00005356 /* Invalid speed for SGMII */
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07005357 DP(NETIF_MSG_LINK, "Invalid line_speed 0x%x\n",
5358 vars->line_speed);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005359 break;
5360 }
5361
Yuval Mintzd2310232012-06-20 19:05:19 +00005362 /* Setting the full duplex */
Yaniv Rosner7aa07112010-09-07 11:41:01 +00005363 if (phy->req_duplex == DUPLEX_FULL)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005364 mii_control |=
5365 MDIO_COMBO_IEEO_MII_CONTROL_FULL_DUPLEX;
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005366 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005367 MDIO_REG_BANK_COMBO_IEEE0,
5368 MDIO_COMBO_IEEE0_MII_CONTROL,
5369 mii_control);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005370
5371 } else { /* AN mode */
Yuval Mintzd2310232012-06-20 19:05:19 +00005372 /* Enable and restart AN */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00005373 bnx2x_restart_autoneg(phy, params, 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005374 }
5375}
5376
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00005377/* Link management
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005378 */
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00005379static int bnx2x_direct_parallel_detect_used(struct bnx2x_phy *phy,
5380 struct link_params *params)
Yaniv Rosner15ddd2d2009-11-05 19:18:12 +02005381{
5382 struct bnx2x *bp = params->bp;
5383 u16 pd_10g, status2_1000x;
Yaniv Rosner7aa07112010-09-07 11:41:01 +00005384 if (phy->req_line_speed != SPEED_AUTO_NEG)
5385 return 0;
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005386 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005387 MDIO_REG_BANK_SERDES_DIGITAL,
5388 MDIO_SERDES_DIGITAL_A_1000X_STATUS2,
5389 &status2_1000x);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005390 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005391 MDIO_REG_BANK_SERDES_DIGITAL,
5392 MDIO_SERDES_DIGITAL_A_1000X_STATUS2,
5393 &status2_1000x);
Yaniv Rosner15ddd2d2009-11-05 19:18:12 +02005394 if (status2_1000x & MDIO_SERDES_DIGITAL_A_1000X_STATUS2_AN_DISABLED) {
5395 DP(NETIF_MSG_LINK, "1G parallel detect link on port %d\n",
5396 params->port);
5397 return 1;
5398 }
5399
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005400 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005401 MDIO_REG_BANK_10G_PARALLEL_DETECT,
5402 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_STATUS,
5403 &pd_10g);
Yaniv Rosner15ddd2d2009-11-05 19:18:12 +02005404
5405 if (pd_10g & MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_STATUS_PD_LINK) {
5406 DP(NETIF_MSG_LINK, "10G parallel detect link on port %d\n",
5407 params->port);
5408 return 1;
5409 }
5410 return 0;
5411}
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005412
Mintz Yuval9e7e8392012-02-15 02:10:24 +00005413static void bnx2x_update_adv_fc(struct bnx2x_phy *phy,
5414 struct link_params *params,
5415 struct link_vars *vars,
5416 u32 gp_status)
5417{
5418 u16 ld_pause; /* local driver */
5419 u16 lp_pause; /* link partner */
5420 u16 pause_result;
5421 struct bnx2x *bp = params->bp;
5422 if ((gp_status &
5423 (MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_AUTONEG_COMPLETE |
5424 MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_MR_LP_NP_AN_ABLE)) ==
5425 (MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_AUTONEG_COMPLETE |
5426 MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_MR_LP_NP_AN_ABLE)) {
5427
5428 CL22_RD_OVER_CL45(bp, phy,
5429 MDIO_REG_BANK_CL73_IEEEB1,
5430 MDIO_CL73_IEEEB1_AN_ADV1,
5431 &ld_pause);
5432 CL22_RD_OVER_CL45(bp, phy,
5433 MDIO_REG_BANK_CL73_IEEEB1,
5434 MDIO_CL73_IEEEB1_AN_LP_ADV1,
5435 &lp_pause);
5436 pause_result = (ld_pause &
5437 MDIO_CL73_IEEEB1_AN_ADV1_PAUSE_MASK) >> 8;
5438 pause_result |= (lp_pause &
5439 MDIO_CL73_IEEEB1_AN_LP_ADV1_PAUSE_MASK) >> 10;
5440 DP(NETIF_MSG_LINK, "pause_result CL73 0x%x\n", pause_result);
5441 } else {
5442 CL22_RD_OVER_CL45(bp, phy,
5443 MDIO_REG_BANK_COMBO_IEEE0,
5444 MDIO_COMBO_IEEE0_AUTO_NEG_ADV,
5445 &ld_pause);
5446 CL22_RD_OVER_CL45(bp, phy,
5447 MDIO_REG_BANK_COMBO_IEEE0,
5448 MDIO_COMBO_IEEE0_AUTO_NEG_LINK_PARTNER_ABILITY1,
5449 &lp_pause);
5450 pause_result = (ld_pause &
5451 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK)>>5;
5452 pause_result |= (lp_pause &
5453 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK)>>7;
5454 DP(NETIF_MSG_LINK, "pause_result CL37 0x%x\n", pause_result);
5455 }
5456 bnx2x_pause_resolve(vars, pause_result);
5457
5458}
5459
Yaniv Rosnere10bc842010-09-07 11:40:50 +00005460static void bnx2x_flow_ctrl_resolve(struct bnx2x_phy *phy,
5461 struct link_params *params,
5462 struct link_vars *vars,
5463 u32 gp_status)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005464{
5465 struct bnx2x *bp = params->bp;
David S. Millerc0700f92008-12-16 23:53:20 -08005466 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005467
Yuval Mintzd2310232012-06-20 19:05:19 +00005468 /* Resolve from gp_status in case of AN complete and not sgmii */
Mintz Yuval9e7e8392012-02-15 02:10:24 +00005469 if (phy->req_flow_ctrl != BNX2X_FLOW_CTRL_AUTO) {
5470 /* Update the advertised flow-controled of LD/LP in AN */
5471 if (phy->req_line_speed == SPEED_AUTO_NEG)
5472 bnx2x_update_adv_fc(phy, params, vars, gp_status);
5473 /* But set the flow-control result as the requested one */
Yaniv Rosner7aa07112010-09-07 11:41:01 +00005474 vars->flow_ctrl = phy->req_flow_ctrl;
Mintz Yuval9e7e8392012-02-15 02:10:24 +00005475 } else if (phy->req_line_speed != SPEED_AUTO_NEG)
Yaniv Rosner7aa07112010-09-07 11:41:01 +00005476 vars->flow_ctrl = params->req_fc_auto_adv;
5477 else if ((gp_status & MDIO_AN_CL73_OR_37_COMPLETE) &&
5478 (!(vars->phy_flags & PHY_SGMII_FLAG))) {
Yaniv Rosnere10bc842010-09-07 11:40:50 +00005479 if (bnx2x_direct_parallel_detect_used(phy, params)) {
Yaniv Rosner15ddd2d2009-11-05 19:18:12 +02005480 vars->flow_ctrl = params->req_fc_auto_adv;
5481 return;
5482 }
Mintz Yuval9e7e8392012-02-15 02:10:24 +00005483 bnx2x_update_adv_fc(phy, params, vars, gp_status);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005484 }
5485 DP(NETIF_MSG_LINK, "flow_ctrl 0x%x\n", vars->flow_ctrl);
5486}
5487
Yaniv Rosnere10bc842010-09-07 11:40:50 +00005488static void bnx2x_check_fallback_to_cl37(struct bnx2x_phy *phy,
5489 struct link_params *params)
Eilon Greenstein239d6862009-08-12 08:23:04 +00005490{
5491 struct bnx2x *bp = params->bp;
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00005492 u16 rx_status, ustat_val, cl37_fsm_received;
Eilon Greenstein239d6862009-08-12 08:23:04 +00005493 DP(NETIF_MSG_LINK, "bnx2x_check_fallback_to_cl37\n");
5494 /* Step 1: Make sure signal is detected */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005495 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005496 MDIO_REG_BANK_RX0,
5497 MDIO_RX0_RX_STATUS,
5498 &rx_status);
Eilon Greenstein239d6862009-08-12 08:23:04 +00005499 if ((rx_status & MDIO_RX0_RX_STATUS_SIGDET) !=
5500 (MDIO_RX0_RX_STATUS_SIGDET)) {
5501 DP(NETIF_MSG_LINK, "Signal is not detected. Restoring CL73."
5502 "rx_status(0x80b0) = 0x%x\n", rx_status);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005503 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005504 MDIO_REG_BANK_CL73_IEEEB0,
5505 MDIO_CL73_IEEEB0_CL73_AN_CONTROL,
5506 MDIO_CL73_IEEEB0_CL73_AN_CONTROL_AN_EN);
Eilon Greenstein239d6862009-08-12 08:23:04 +00005507 return;
5508 }
5509 /* Step 2: Check CL73 state machine */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005510 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005511 MDIO_REG_BANK_CL73_USERB0,
5512 MDIO_CL73_USERB0_CL73_USTAT1,
5513 &ustat_val);
Eilon Greenstein239d6862009-08-12 08:23:04 +00005514 if ((ustat_val &
5515 (MDIO_CL73_USERB0_CL73_USTAT1_LINK_STATUS_CHECK |
5516 MDIO_CL73_USERB0_CL73_USTAT1_AN_GOOD_CHECK_BAM37)) !=
5517 (MDIO_CL73_USERB0_CL73_USTAT1_LINK_STATUS_CHECK |
5518 MDIO_CL73_USERB0_CL73_USTAT1_AN_GOOD_CHECK_BAM37)) {
5519 DP(NETIF_MSG_LINK, "CL73 state-machine is not stable. "
5520 "ustat_val(0x8371) = 0x%x\n", ustat_val);
5521 return;
5522 }
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00005523 /* Step 3: Check CL37 Message Pages received to indicate LP
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005524 * supports only CL37
5525 */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005526 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005527 MDIO_REG_BANK_REMOTE_PHY,
5528 MDIO_REMOTE_PHY_MISC_RX_STATUS,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00005529 &cl37_fsm_received);
5530 if ((cl37_fsm_received &
Eilon Greenstein239d6862009-08-12 08:23:04 +00005531 (MDIO_REMOTE_PHY_MISC_RX_STATUS_CL37_FSM_RECEIVED_OVER1G_MSG |
5532 MDIO_REMOTE_PHY_MISC_RX_STATUS_CL37_FSM_RECEIVED_BRCM_OUI_MSG)) !=
5533 (MDIO_REMOTE_PHY_MISC_RX_STATUS_CL37_FSM_RECEIVED_OVER1G_MSG |
5534 MDIO_REMOTE_PHY_MISC_RX_STATUS_CL37_FSM_RECEIVED_BRCM_OUI_MSG)) {
5535 DP(NETIF_MSG_LINK, "No CL37 FSM were received. "
5536 "misc_rx_status(0x8330) = 0x%x\n",
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00005537 cl37_fsm_received);
Eilon Greenstein239d6862009-08-12 08:23:04 +00005538 return;
5539 }
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00005540 /* The combined cl37/cl73 fsm state information indicating that
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005541 * we are connected to a device which does not support cl73, but
5542 * does support cl37 BAM. In this case we disable cl73 and
5543 * restart cl37 auto-neg
5544 */
5545
Eilon Greenstein239d6862009-08-12 08:23:04 +00005546 /* Disable CL73 */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005547 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005548 MDIO_REG_BANK_CL73_IEEEB0,
5549 MDIO_CL73_IEEEB0_CL73_AN_CONTROL,
5550 0);
Eilon Greenstein239d6862009-08-12 08:23:04 +00005551 /* Restart CL37 autoneg */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00005552 bnx2x_restart_autoneg(phy, params, 0);
Eilon Greenstein239d6862009-08-12 08:23:04 +00005553 DP(NETIF_MSG_LINK, "Disabling CL73, and restarting CL37 autoneg\n");
5554}
Yaniv Rosner7aa07112010-09-07 11:41:01 +00005555
5556static void bnx2x_xgxs_an_resolve(struct bnx2x_phy *phy,
5557 struct link_params *params,
5558 struct link_vars *vars,
5559 u32 gp_status)
5560{
5561 if (gp_status & MDIO_AN_CL73_OR_37_COMPLETE)
5562 vars->link_status |=
5563 LINK_STATUS_AUTO_NEGOTIATE_COMPLETE;
5564
5565 if (bnx2x_direct_parallel_detect_used(phy, params))
5566 vars->link_status |=
5567 LINK_STATUS_PARALLEL_DETECTION_USED;
5568}
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005569static int bnx2x_get_link_speed_duplex(struct bnx2x_phy *phy,
5570 struct link_params *params,
5571 struct link_vars *vars,
5572 u16 is_link_up,
5573 u16 speed_mask,
5574 u16 is_duplex)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005575{
5576 struct bnx2x *bp = params->bp;
Yaniv Rosner7aa07112010-09-07 11:41:01 +00005577 if (phy->req_line_speed == SPEED_AUTO_NEG)
5578 vars->link_status |= LINK_STATUS_AUTO_NEGOTIATE_ENABLED;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005579 if (is_link_up) {
5580 DP(NETIF_MSG_LINK, "phy link up\n");
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005581
5582 vars->phy_link_up = 1;
5583 vars->link_status |= LINK_STATUS_LINK_UP;
5584
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005585 switch (speed_mask) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005586 case GP_STATUS_10M:
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005587 vars->line_speed = SPEED_10;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005588 if (vars->duplex == DUPLEX_FULL)
5589 vars->link_status |= LINK_10TFD;
5590 else
5591 vars->link_status |= LINK_10THD;
5592 break;
5593
5594 case GP_STATUS_100M:
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005595 vars->line_speed = SPEED_100;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005596 if (vars->duplex == DUPLEX_FULL)
5597 vars->link_status |= LINK_100TXFD;
5598 else
5599 vars->link_status |= LINK_100TXHD;
5600 break;
5601
5602 case GP_STATUS_1G:
5603 case GP_STATUS_1G_KX:
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005604 vars->line_speed = SPEED_1000;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005605 if (vars->duplex == DUPLEX_FULL)
5606 vars->link_status |= LINK_1000TFD;
5607 else
5608 vars->link_status |= LINK_1000THD;
5609 break;
5610
5611 case GP_STATUS_2_5G:
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005612 vars->line_speed = SPEED_2500;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005613 if (vars->duplex == DUPLEX_FULL)
5614 vars->link_status |= LINK_2500TFD;
5615 else
5616 vars->link_status |= LINK_2500THD;
5617 break;
5618
5619 case GP_STATUS_5G:
5620 case GP_STATUS_6G:
5621 DP(NETIF_MSG_LINK,
5622 "link speed unsupported gp_status 0x%x\n",
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005623 speed_mask);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005624 return -EINVAL;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00005625
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005626 case GP_STATUS_10G_KX4:
5627 case GP_STATUS_10G_HIG:
5628 case GP_STATUS_10G_CX4:
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005629 case GP_STATUS_10G_KR:
5630 case GP_STATUS_10G_SFI:
5631 case GP_STATUS_10G_XFI:
5632 vars->line_speed = SPEED_10000;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005633 vars->link_status |= LINK_10GTFD;
5634 break;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005635 case GP_STATUS_20G_DXGXS:
5636 vars->line_speed = SPEED_20000;
5637 vars->link_status |= LINK_20GTFD;
5638 break;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005639 default:
5640 DP(NETIF_MSG_LINK,
5641 "link speed unsupported gp_status 0x%x\n",
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005642 speed_mask);
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00005643 return -EINVAL;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005644 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005645 } else { /* link_down */
5646 DP(NETIF_MSG_LINK, "phy link down\n");
5647
5648 vars->phy_link_up = 0;
Yaniv Rosner57963ed2008-08-13 15:55:28 -07005649
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005650 vars->duplex = DUPLEX_FULL;
David S. Millerc0700f92008-12-16 23:53:20 -08005651 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005652 vars->mac_type = MAC_TYPE_NONE;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005653 }
5654 DP(NETIF_MSG_LINK, " phy_link_up %x line_speed %d\n",
5655 vars->phy_link_up, vars->line_speed);
5656 return 0;
5657}
Eilon Greenstein239d6862009-08-12 08:23:04 +00005658
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005659static int bnx2x_link_settings_status(struct bnx2x_phy *phy,
5660 struct link_params *params,
5661 struct link_vars *vars)
5662{
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005663 struct bnx2x *bp = params->bp;
5664
5665 u16 gp_status, duplex = DUPLEX_HALF, link_up = 0, speed_mask;
5666 int rc = 0;
5667
5668 /* Read gp_status */
5669 CL22_RD_OVER_CL45(bp, phy,
5670 MDIO_REG_BANK_GP_STATUS,
5671 MDIO_GP_STATUS_TOP_AN_STATUS1,
5672 &gp_status);
5673 if (gp_status & MDIO_GP_STATUS_TOP_AN_STATUS1_DUPLEX_STATUS)
5674 duplex = DUPLEX_FULL;
5675 if (gp_status & MDIO_GP_STATUS_TOP_AN_STATUS1_LINK_STATUS)
5676 link_up = 1;
5677 speed_mask = gp_status & GP_STATUS_SPEED_MASK;
5678 DP(NETIF_MSG_LINK, "gp_status 0x%x, is_link_up %d, speed_mask 0x%x\n",
5679 gp_status, link_up, speed_mask);
5680 rc = bnx2x_get_link_speed_duplex(phy, params, vars, link_up, speed_mask,
5681 duplex);
5682 if (rc == -EINVAL)
5683 return rc;
5684
5685 if (gp_status & MDIO_GP_STATUS_TOP_AN_STATUS1_LINK_STATUS) {
5686 if (SINGLE_MEDIA_DIRECT(params)) {
5687 bnx2x_flow_ctrl_resolve(phy, params, vars, gp_status);
5688 if (phy->req_line_speed == SPEED_AUTO_NEG)
5689 bnx2x_xgxs_an_resolve(phy, params, vars,
5690 gp_status);
5691 }
Yuval Mintzd2310232012-06-20 19:05:19 +00005692 } else { /* Link_down */
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00005693 if ((phy->req_line_speed == SPEED_AUTO_NEG) &&
5694 SINGLE_MEDIA_DIRECT(params)) {
Eilon Greenstein239d6862009-08-12 08:23:04 +00005695 /* Check signal is detected */
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00005696 bnx2x_check_fallback_to_cl37(phy, params);
Eilon Greenstein239d6862009-08-12 08:23:04 +00005697 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005698 }
5699
Mintz Yuval9e7e8392012-02-15 02:10:24 +00005700 /* Read LP advertised speeds*/
5701 if (SINGLE_MEDIA_DIRECT(params) &&
5702 (vars->link_status & LINK_STATUS_AUTO_NEGOTIATE_COMPLETE)) {
5703 u16 val;
5704
5705 CL22_RD_OVER_CL45(bp, phy, MDIO_REG_BANK_CL73_IEEEB1,
5706 MDIO_CL73_IEEEB1_AN_LP_ADV2, &val);
5707
5708 if (val & MDIO_CL73_IEEEB1_AN_ADV2_ADVR_1000M_KX)
5709 vars->link_status |=
5710 LINK_STATUS_LINK_PARTNER_1000TFD_CAPABLE;
5711 if (val & (MDIO_CL73_IEEEB1_AN_ADV2_ADVR_10G_KX4 |
5712 MDIO_CL73_IEEEB1_AN_ADV2_ADVR_10G_KR))
5713 vars->link_status |=
5714 LINK_STATUS_LINK_PARTNER_10GXFD_CAPABLE;
5715
5716 CL22_RD_OVER_CL45(bp, phy, MDIO_REG_BANK_OVER_1G,
5717 MDIO_OVER_1G_LP_UP1, &val);
5718
5719 if (val & MDIO_OVER_1G_UP1_2_5G)
5720 vars->link_status |=
5721 LINK_STATUS_LINK_PARTNER_2500XFD_CAPABLE;
5722 if (val & (MDIO_OVER_1G_UP1_10G | MDIO_OVER_1G_UP1_10GH))
5723 vars->link_status |=
5724 LINK_STATUS_LINK_PARTNER_10GXFD_CAPABLE;
5725 }
5726
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005727 DP(NETIF_MSG_LINK, "duplex %x flow_ctrl 0x%x link_status 0x%x\n",
5728 vars->duplex, vars->flow_ctrl, vars->link_status);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005729 return rc;
5730}
5731
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005732static int bnx2x_warpcore_read_status(struct bnx2x_phy *phy,
5733 struct link_params *params,
5734 struct link_vars *vars)
5735{
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005736 struct bnx2x *bp = params->bp;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005737 u8 lane;
5738 u16 gp_status1, gp_speed, link_up, duplex = DUPLEX_FULL;
5739 int rc = 0;
5740 lane = bnx2x_get_warpcore_lane(phy, params);
5741 /* Read gp_status */
5742 if (phy->req_line_speed > SPEED_10000) {
5743 u16 temp_link_up;
5744 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
5745 1, &temp_link_up);
5746 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
5747 1, &link_up);
5748 DP(NETIF_MSG_LINK, "PCS RX link status = 0x%x-->0x%x\n",
5749 temp_link_up, link_up);
5750 link_up &= (1<<2);
5751 if (link_up)
5752 bnx2x_ext_phy_resolve_fc(phy, params, vars);
5753 } else {
5754 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
5755 MDIO_WC_REG_GP2_STATUS_GP_2_1, &gp_status1);
5756 DP(NETIF_MSG_LINK, "0x81d1 = 0x%x\n", gp_status1);
5757 /* Check for either KR or generic link up. */
5758 gp_status1 = ((gp_status1 >> 8) & 0xf) |
5759 ((gp_status1 >> 12) & 0xf);
5760 link_up = gp_status1 & (1 << lane);
5761 if (link_up && SINGLE_MEDIA_DIRECT(params)) {
5762 u16 pd, gp_status4;
5763 if (phy->req_line_speed == SPEED_AUTO_NEG) {
5764 /* Check Autoneg complete */
5765 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
5766 MDIO_WC_REG_GP2_STATUS_GP_2_4,
5767 &gp_status4);
5768 if (gp_status4 & ((1<<12)<<lane))
5769 vars->link_status |=
5770 LINK_STATUS_AUTO_NEGOTIATE_COMPLETE;
5771
5772 /* Check parallel detect used */
5773 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
5774 MDIO_WC_REG_PAR_DET_10G_STATUS,
5775 &pd);
5776 if (pd & (1<<15))
5777 vars->link_status |=
5778 LINK_STATUS_PARALLEL_DETECTION_USED;
5779 }
5780 bnx2x_ext_phy_resolve_fc(phy, params, vars);
5781 }
5782 }
5783
Mintz Yuval9e7e8392012-02-15 02:10:24 +00005784 if ((vars->link_status & LINK_STATUS_AUTO_NEGOTIATE_COMPLETE) &&
5785 SINGLE_MEDIA_DIRECT(params)) {
5786 u16 val;
5787
5788 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
5789 MDIO_AN_REG_LP_AUTO_NEG2, &val);
5790
5791 if (val & MDIO_CL73_IEEEB1_AN_ADV2_ADVR_1000M_KX)
5792 vars->link_status |=
5793 LINK_STATUS_LINK_PARTNER_1000TFD_CAPABLE;
5794 if (val & (MDIO_CL73_IEEEB1_AN_ADV2_ADVR_10G_KX4 |
5795 MDIO_CL73_IEEEB1_AN_ADV2_ADVR_10G_KR))
5796 vars->link_status |=
5797 LINK_STATUS_LINK_PARTNER_10GXFD_CAPABLE;
5798
5799 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
5800 MDIO_WC_REG_DIGITAL3_LP_UP1, &val);
5801
5802 if (val & MDIO_OVER_1G_UP1_2_5G)
5803 vars->link_status |=
5804 LINK_STATUS_LINK_PARTNER_2500XFD_CAPABLE;
5805 if (val & (MDIO_OVER_1G_UP1_10G | MDIO_OVER_1G_UP1_10GH))
5806 vars->link_status |=
5807 LINK_STATUS_LINK_PARTNER_10GXFD_CAPABLE;
5808
5809 }
5810
5811
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005812 if (lane < 2) {
5813 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
5814 MDIO_WC_REG_GP2_STATUS_GP_2_2, &gp_speed);
5815 } else {
5816 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
5817 MDIO_WC_REG_GP2_STATUS_GP_2_3, &gp_speed);
5818 }
5819 DP(NETIF_MSG_LINK, "lane %d gp_speed 0x%x\n", lane, gp_speed);
5820
5821 if ((lane & 1) == 0)
5822 gp_speed <<= 8;
5823 gp_speed &= 0x3f00;
5824
5825
5826 rc = bnx2x_get_link_speed_duplex(phy, params, vars, link_up, gp_speed,
5827 duplex);
5828
5829 DP(NETIF_MSG_LINK, "duplex %x flow_ctrl 0x%x link_status 0x%x\n",
5830 vars->duplex, vars->flow_ctrl, vars->link_status);
5831 return rc;
5832}
Eilon Greensteined8680a2009-02-12 08:37:12 +00005833static void bnx2x_set_gmii_tx_driver(struct link_params *params)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005834{
5835 struct bnx2x *bp = params->bp;
Yaniv Rosnere10bc842010-09-07 11:40:50 +00005836 struct bnx2x_phy *phy = &params->phy[INT_PHY];
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005837 u16 lp_up2;
5838 u16 tx_driver;
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00005839 u16 bank;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005840
Yuval Mintzd2310232012-06-20 19:05:19 +00005841 /* Read precomp */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005842 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005843 MDIO_REG_BANK_OVER_1G,
5844 MDIO_OVER_1G_LP_UP2, &lp_up2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005845
Yuval Mintzd2310232012-06-20 19:05:19 +00005846 /* Bits [10:7] at lp_up2, positioned at [15:12] */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005847 lp_up2 = (((lp_up2 & MDIO_OVER_1G_LP_UP2_PREEMPHASIS_MASK) >>
5848 MDIO_OVER_1G_LP_UP2_PREEMPHASIS_SHIFT) <<
5849 MDIO_TX0_TX_DRIVER_PREEMPHASIS_SHIFT);
5850
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00005851 if (lp_up2 == 0)
5852 return;
5853
5854 for (bank = MDIO_REG_BANK_TX0; bank <= MDIO_REG_BANK_TX3;
5855 bank += (MDIO_REG_BANK_TX1 - MDIO_REG_BANK_TX0)) {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005856 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005857 bank,
5858 MDIO_TX0_TX_DRIVER, &tx_driver);
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00005859
Yuval Mintzd2310232012-06-20 19:05:19 +00005860 /* Replace tx_driver bits [15:12] */
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00005861 if (lp_up2 !=
5862 (tx_driver & MDIO_TX0_TX_DRIVER_PREEMPHASIS_MASK)) {
5863 tx_driver &= ~MDIO_TX0_TX_DRIVER_PREEMPHASIS_MASK;
5864 tx_driver |= lp_up2;
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005865 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005866 bank,
5867 MDIO_TX0_TX_DRIVER, tx_driver);
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00005868 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005869 }
5870}
5871
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00005872static int bnx2x_emac_program(struct link_params *params,
5873 struct link_vars *vars)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005874{
5875 struct bnx2x *bp = params->bp;
5876 u8 port = params->port;
5877 u16 mode = 0;
5878
5879 DP(NETIF_MSG_LINK, "setting link speed & duplex\n");
5880 bnx2x_bits_dis(bp, GRCBASE_EMAC0 + port*0x400 +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005881 EMAC_REG_EMAC_MODE,
5882 (EMAC_MODE_25G_MODE |
5883 EMAC_MODE_PORT_MII_10M |
5884 EMAC_MODE_HALF_DUPLEX));
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005885 switch (vars->line_speed) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005886 case SPEED_10:
5887 mode |= EMAC_MODE_PORT_MII_10M;
5888 break;
5889
5890 case SPEED_100:
5891 mode |= EMAC_MODE_PORT_MII;
5892 break;
5893
5894 case SPEED_1000:
5895 mode |= EMAC_MODE_PORT_GMII;
5896 break;
5897
5898 case SPEED_2500:
5899 mode |= (EMAC_MODE_25G_MODE | EMAC_MODE_PORT_GMII);
5900 break;
5901
5902 default:
5903 /* 10G not valid for EMAC */
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005904 DP(NETIF_MSG_LINK, "Invalid line_speed 0x%x\n",
5905 vars->line_speed);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005906 return -EINVAL;
5907 }
5908
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005909 if (vars->duplex == DUPLEX_HALF)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005910 mode |= EMAC_MODE_HALF_DUPLEX;
5911 bnx2x_bits_en(bp,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005912 GRCBASE_EMAC0 + port*0x400 + EMAC_REG_EMAC_MODE,
5913 mode);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005914
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00005915 bnx2x_set_led(params, vars, LED_MODE_OPER, vars->line_speed);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005916 return 0;
5917}
5918
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005919static void bnx2x_set_preemphasis(struct bnx2x_phy *phy,
5920 struct link_params *params)
5921{
5922
5923 u16 bank, i = 0;
5924 struct bnx2x *bp = params->bp;
5925
5926 for (bank = MDIO_REG_BANK_RX0, i = 0; bank <= MDIO_REG_BANK_RX3;
5927 bank += (MDIO_REG_BANK_RX1-MDIO_REG_BANK_RX0), i++) {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005928 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005929 bank,
5930 MDIO_RX0_RX_EQ_BOOST,
5931 phy->rx_preemphasis[i]);
5932 }
5933
5934 for (bank = MDIO_REG_BANK_TX0, i = 0; bank <= MDIO_REG_BANK_TX3;
5935 bank += (MDIO_REG_BANK_TX1 - MDIO_REG_BANK_TX0), i++) {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005936 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005937 bank,
5938 MDIO_TX0_TX_DRIVER,
5939 phy->tx_preemphasis[i]);
5940 }
5941}
5942
Yaniv Rosnerec146a62011-05-31 21:29:27 +00005943static void bnx2x_xgxs_config_init(struct bnx2x_phy *phy,
5944 struct link_params *params,
5945 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005946{
5947 struct bnx2x *bp = params->bp;
5948 u8 enable_cl73 = (SINGLE_MEDIA_DIRECT(params) ||
5949 (params->loopback_mode == LOOPBACK_XGXS));
5950 if (!(vars->phy_flags & PHY_SGMII_FLAG)) {
5951 if (SINGLE_MEDIA_DIRECT(params) &&
5952 (params->feature_config_flags &
5953 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED))
5954 bnx2x_set_preemphasis(phy, params);
5955
Yuval Mintzd2310232012-06-20 19:05:19 +00005956 /* Forced speed requested? */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005957 if (vars->line_speed != SPEED_AUTO_NEG ||
5958 (SINGLE_MEDIA_DIRECT(params) &&
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005959 params->loopback_mode == LOOPBACK_EXT)) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005960 DP(NETIF_MSG_LINK, "not SGMII, no AN\n");
5961
Yuval Mintzd2310232012-06-20 19:05:19 +00005962 /* Disable autoneg */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005963 bnx2x_set_autoneg(phy, params, vars, 0);
5964
Yuval Mintzd2310232012-06-20 19:05:19 +00005965 /* Program speed and duplex */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005966 bnx2x_program_serdes(phy, params, vars);
5967
5968 } else { /* AN_mode */
5969 DP(NETIF_MSG_LINK, "not SGMII, AN\n");
5970
5971 /* AN enabled */
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00005972 bnx2x_set_brcm_cl37_advertisement(phy, params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005973
Yuval Mintzd2310232012-06-20 19:05:19 +00005974 /* Program duplex & pause advertisement (for aneg) */
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00005975 bnx2x_set_ieee_aneg_advertisement(phy, params,
5976 vars->ieee_fc);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005977
Yuval Mintzd2310232012-06-20 19:05:19 +00005978 /* Enable autoneg */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005979 bnx2x_set_autoneg(phy, params, vars, enable_cl73);
5980
Yuval Mintzd2310232012-06-20 19:05:19 +00005981 /* Enable and restart AN */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005982 bnx2x_restart_autoneg(phy, params, enable_cl73);
5983 }
5984
5985 } else { /* SGMII mode */
5986 DP(NETIF_MSG_LINK, "SGMII\n");
5987
5988 bnx2x_initialize_sgmii_process(phy, params, vars);
5989 }
5990}
5991
Yaniv Rosnerec146a62011-05-31 21:29:27 +00005992static int bnx2x_prepare_xgxs(struct bnx2x_phy *phy,
5993 struct link_params *params,
5994 struct link_vars *vars)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005995{
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00005996 int rc;
Yaniv Rosnerec146a62011-05-31 21:29:27 +00005997 vars->phy_flags |= PHY_XGXS_FLAG;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005998 if ((phy->req_line_speed &&
5999 ((phy->req_line_speed == SPEED_100) ||
6000 (phy->req_line_speed == SPEED_10))) ||
6001 (!phy->req_line_speed &&
6002 (phy->speed_cap_mask >=
6003 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL) &&
6004 (phy->speed_cap_mask <
Yaniv Rosnerec146a62011-05-31 21:29:27 +00006005 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) ||
6006 (phy->type == PORT_HW_CFG_SERDES_EXT_PHY_TYPE_DIRECT_SD))
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006007 vars->phy_flags |= PHY_SGMII_FLAG;
6008 else
6009 vars->phy_flags &= ~PHY_SGMII_FLAG;
6010
6011 bnx2x_calc_ieee_aneg_adv(phy, params, &vars->ieee_fc);
Yaniv Rosnerec146a62011-05-31 21:29:27 +00006012 bnx2x_set_aer_mmd(params, phy);
6013 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
6014 bnx2x_set_master_ln(params, phy);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006015
6016 rc = bnx2x_reset_unicore(params, phy, 0);
Yuval Mintzd2310232012-06-20 19:05:19 +00006017 /* Reset the SerDes and wait for reset bit return low */
6018 if (rc)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006019 return rc;
6020
Yaniv Rosnerec146a62011-05-31 21:29:27 +00006021 bnx2x_set_aer_mmd(params, phy);
Yuval Mintzd2310232012-06-20 19:05:19 +00006022 /* Setting the masterLn_def again after the reset */
Yaniv Rosnerec146a62011-05-31 21:29:27 +00006023 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT) {
6024 bnx2x_set_master_ln(params, phy);
6025 bnx2x_set_swap_lanes(params, phy);
6026 }
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006027
6028 return rc;
6029}
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00006030
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006031static u16 bnx2x_wait_reset_complete(struct bnx2x *bp,
Yaniv Rosner6d870c32011-01-31 04:22:20 +00006032 struct bnx2x_phy *phy,
6033 struct link_params *params)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006034{
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006035 u16 cnt, ctrl;
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006036 /* Wait for soft reset to get cleared up to 1 sec */
Yaniv Rosner62b29a52010-09-07 11:40:58 +00006037 for (cnt = 0; cnt < 1000; cnt++) {
Yaniv Rosner52c4d6c2011-07-05 01:06:34 +00006038 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54618SE)
Yaniv Rosner6583e332011-06-14 01:34:17 +00006039 bnx2x_cl22_read(bp, phy,
6040 MDIO_PMA_REG_CTRL, &ctrl);
6041 else
6042 bnx2x_cl45_read(bp, phy,
6043 MDIO_PMA_DEVAD,
6044 MDIO_PMA_REG_CTRL, &ctrl);
Yaniv Rosner62b29a52010-09-07 11:40:58 +00006045 if (!(ctrl & (1<<15)))
6046 break;
Yuval Mintzd2310232012-06-20 19:05:19 +00006047 usleep_range(1000, 2000);
Yaniv Rosner62b29a52010-09-07 11:40:58 +00006048 }
Yaniv Rosner6d870c32011-01-31 04:22:20 +00006049
6050 if (cnt == 1000)
6051 netdev_err(bp->dev, "Warning: PHY was not initialized,"
6052 " Port %d\n",
6053 params->port);
Yaniv Rosner62b29a52010-09-07 11:40:58 +00006054 DP(NETIF_MSG_LINK, "control reg 0x%x (after %d ms)\n", ctrl, cnt);
6055 return cnt;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006056}
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006057
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006058static void bnx2x_link_int_enable(struct link_params *params)
6059{
6060 u8 port = params->port;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006061 u32 mask;
6062 struct bnx2x *bp = params->bp;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00006063
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006064 /* Setting the status to report on link up for either XGXS or SerDes */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006065 if (CHIP_IS_E3(bp)) {
6066 mask = NIG_MASK_XGXS0_LINK_STATUS;
6067 if (!(SINGLE_MEDIA_DIRECT(params)))
6068 mask |= NIG_MASK_MI_INT;
6069 } else if (params->switch_cfg == SWITCH_CFG_10G) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006070 mask = (NIG_MASK_XGXS0_LINK10G |
6071 NIG_MASK_XGXS0_LINK_STATUS);
6072 DP(NETIF_MSG_LINK, "enabled XGXS interrupt\n");
Yaniv Rosnere10bc842010-09-07 11:40:50 +00006073 if (!(SINGLE_MEDIA_DIRECT(params)) &&
6074 params->phy[INT_PHY].type !=
6075 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006076 mask |= NIG_MASK_MI_INT;
6077 DP(NETIF_MSG_LINK, "enabled external phy int\n");
6078 }
6079
6080 } else { /* SerDes */
6081 mask = NIG_MASK_SERDES0_LINK_STATUS;
6082 DP(NETIF_MSG_LINK, "enabled SerDes interrupt\n");
Yaniv Rosnere10bc842010-09-07 11:40:50 +00006083 if (!(SINGLE_MEDIA_DIRECT(params)) &&
6084 params->phy[INT_PHY].type !=
6085 PORT_HW_CFG_SERDES_EXT_PHY_TYPE_NOT_CONN) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006086 mask |= NIG_MASK_MI_INT;
6087 DP(NETIF_MSG_LINK, "enabled external phy int\n");
6088 }
6089 }
6090 bnx2x_bits_en(bp,
6091 NIG_REG_MASK_INTERRUPT_PORT0 + port*4,
6092 mask);
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00006093
6094 DP(NETIF_MSG_LINK, "port %x, is_xgxs %x, int_status 0x%x\n", port,
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006095 (params->switch_cfg == SWITCH_CFG_10G),
6096 REG_RD(bp, NIG_REG_STATUS_INTERRUPT_PORT0 + port*4));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006097 DP(NETIF_MSG_LINK, " int_mask 0x%x, MI_INT %x, SERDES_LINK %x\n",
6098 REG_RD(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4),
6099 REG_RD(bp, NIG_REG_EMAC0_STATUS_MISC_MI_INT + port*0x18),
6100 REG_RD(bp, NIG_REG_SERDES0_STATUS_LINK_STATUS+port*0x3c));
6101 DP(NETIF_MSG_LINK, " 10G %x, XGXS_LINK %x\n",
6102 REG_RD(bp, NIG_REG_XGXS0_STATUS_LINK10G + port*0x68),
6103 REG_RD(bp, NIG_REG_XGXS0_STATUS_LINK_STATUS + port*0x68));
6104}
6105
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006106static void bnx2x_rearm_latch_signal(struct bnx2x *bp, u8 port,
6107 u8 exp_mi_int)
Eilon Greenstein2f904462009-08-12 08:22:16 +00006108{
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006109 u32 latch_status = 0;
6110
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00006111 /* Disable the MI INT ( external phy int ) by writing 1 to the
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006112 * status register. Link down indication is high-active-signal,
6113 * so in this case we need to write the status to clear the XOR
Eilon Greenstein2f904462009-08-12 08:22:16 +00006114 */
6115 /* Read Latched signals */
6116 latch_status = REG_RD(bp,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006117 NIG_REG_LATCH_STATUS_0 + port*8);
6118 DP(NETIF_MSG_LINK, "latch_status = 0x%x\n", latch_status);
Eilon Greenstein2f904462009-08-12 08:22:16 +00006119 /* Handle only those with latched-signal=up.*/
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006120 if (exp_mi_int)
6121 bnx2x_bits_en(bp,
6122 NIG_REG_STATUS_INTERRUPT_PORT0
6123 + port*4,
6124 NIG_STATUS_EMAC0_MI_INT);
6125 else
6126 bnx2x_bits_dis(bp,
6127 NIG_REG_STATUS_INTERRUPT_PORT0
6128 + port*4,
6129 NIG_STATUS_EMAC0_MI_INT);
6130
Eilon Greenstein2f904462009-08-12 08:22:16 +00006131 if (latch_status & 1) {
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006132
Eilon Greenstein2f904462009-08-12 08:22:16 +00006133 /* For all latched-signal=up : Re-Arm Latch signals */
6134 REG_WR(bp, NIG_REG_LATCH_STATUS_0 + port*8,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006135 (latch_status & 0xfffe) | (latch_status & 1));
Eilon Greenstein2f904462009-08-12 08:22:16 +00006136 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006137 /* For all latched-signal=up,Write original_signal to status */
Eilon Greenstein2f904462009-08-12 08:22:16 +00006138}
Yaniv Rosnere10bc842010-09-07 11:40:50 +00006139
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006140static void bnx2x_link_int_ack(struct link_params *params,
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006141 struct link_vars *vars, u8 is_10g_plus)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006142{
6143 struct bnx2x *bp = params->bp;
6144 u8 port = params->port;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006145 u32 mask;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00006146 /* First reset all status we assume only one line will be
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006147 * change at a time
6148 */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006149 bnx2x_bits_dis(bp, NIG_REG_STATUS_INTERRUPT_PORT0 + port*4,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006150 (NIG_STATUS_XGXS0_LINK10G |
6151 NIG_STATUS_XGXS0_LINK_STATUS |
6152 NIG_STATUS_SERDES0_LINK_STATUS));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006153 if (vars->phy_link_up) {
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006154 if (USES_WARPCORE(bp))
6155 mask = NIG_STATUS_XGXS0_LINK_STATUS;
6156 else {
6157 if (is_10g_plus)
6158 mask = NIG_STATUS_XGXS0_LINK10G;
6159 else if (params->switch_cfg == SWITCH_CFG_10G) {
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00006160 /* Disable the link interrupt by writing 1 to
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006161 * the relevant lane in the status register
6162 */
6163 u32 ser_lane =
6164 ((params->lane_config &
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006165 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_MASK) >>
6166 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_SHIFT);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006167 mask = ((1 << ser_lane) <<
6168 NIG_STATUS_XGXS0_LINK_STATUS_SIZE);
6169 } else
6170 mask = NIG_STATUS_SERDES0_LINK_STATUS;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006171 }
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006172 DP(NETIF_MSG_LINK, "Ack link up interrupt with mask 0x%x\n",
6173 mask);
6174 bnx2x_bits_en(bp,
6175 NIG_REG_STATUS_INTERRUPT_PORT0 + port*4,
6176 mask);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006177 }
6178}
6179
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006180static int bnx2x_format_ver(u32 num, u8 *str, u16 *len)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006181{
6182 u8 *str_ptr = str;
6183 u32 mask = 0xf0000000;
6184 u8 shift = 8*4;
6185 u8 digit;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006186 u8 remove_leading_zeros = 1;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006187 if (*len < 10) {
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02006188 /* Need more than 10chars for this format */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006189 *str_ptr = '\0';
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006190 (*len)--;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006191 return -EINVAL;
6192 }
6193 while (shift > 0) {
6194
6195 shift -= 4;
6196 digit = ((num & mask) >> shift);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006197 if (digit == 0 && remove_leading_zeros) {
6198 mask = mask >> 4;
6199 continue;
6200 } else if (digit < 0xa)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006201 *str_ptr = digit + '0';
6202 else
6203 *str_ptr = digit - 0xa + 'a';
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006204 remove_leading_zeros = 0;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006205 str_ptr++;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006206 (*len)--;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006207 mask = mask >> 4;
6208 if (shift == 4*4) {
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006209 *str_ptr = '.';
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006210 str_ptr++;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006211 (*len)--;
6212 remove_leading_zeros = 1;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006213 }
6214 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006215 return 0;
6216}
6217
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006218
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006219static int bnx2x_null_format_ver(u32 spirom_ver, u8 *str, u16 *len)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006220{
6221 str[0] = '\0';
6222 (*len)--;
6223 return 0;
6224}
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006225
Mintz Yuvala1e785e2012-02-15 02:10:32 +00006226int bnx2x_get_ext_phy_fw_version(struct link_params *params, u8 *version,
6227 u16 len)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006228{
Julia Lawall0376d5b2009-07-19 05:26:35 +00006229 struct bnx2x *bp;
Eilon Greensteina35da8d2009-02-12 08:37:02 +00006230 u32 spirom_ver = 0;
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006231 int status = 0;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006232 u8 *ver_p = version;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006233 u16 remain_len = len;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006234 if (version == NULL || params == NULL)
6235 return -EINVAL;
Julia Lawall0376d5b2009-07-19 05:26:35 +00006236 bp = params->bp;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006237
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006238 /* Extract first external phy*/
6239 version[0] = '\0';
6240 spirom_ver = REG_RD(bp, params->phy[EXT_PHY1].ver_addr);
Eilon Greensteina35da8d2009-02-12 08:37:02 +00006241
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006242 if (params->phy[EXT_PHY1].format_fw_ver) {
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006243 status |= params->phy[EXT_PHY1].format_fw_ver(spirom_ver,
6244 ver_p,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006245 &remain_len);
6246 ver_p += (len - remain_len);
6247 }
6248 if ((params->num_phys == MAX_PHYS) &&
6249 (params->phy[EXT_PHY2].ver_addr != 0)) {
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006250 spirom_ver = REG_RD(bp, params->phy[EXT_PHY2].ver_addr);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006251 if (params->phy[EXT_PHY2].format_fw_ver) {
6252 *ver_p = '/';
6253 ver_p++;
6254 remain_len--;
6255 status |= params->phy[EXT_PHY2].format_fw_ver(
6256 spirom_ver,
6257 ver_p,
6258 &remain_len);
6259 ver_p = version + (len - remain_len);
6260 }
6261 }
6262 *ver_p = '\0';
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006263 return status;
6264}
6265
Yaniv Rosnere10bc842010-09-07 11:40:50 +00006266static void bnx2x_set_xgxs_loopback(struct bnx2x_phy *phy,
Yaniv Rosner62b29a52010-09-07 11:40:58 +00006267 struct link_params *params)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006268{
6269 u8 port = params->port;
6270 struct bnx2x *bp = params->bp;
6271
Yaniv Rosner62b29a52010-09-07 11:40:58 +00006272 if (phy->req_line_speed != SPEED_1000) {
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006273 u32 md_devad = 0;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006274
6275 DP(NETIF_MSG_LINK, "XGXS 10G loopback enable\n");
6276
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006277 if (!CHIP_IS_E3(bp)) {
Yuval Mintzd2310232012-06-20 19:05:19 +00006278 /* Change the uni_phy_addr in the nig */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006279 md_devad = REG_RD(bp, (NIG_REG_XGXS0_CTRL_MD_DEVAD +
6280 port*0x18));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006281
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006282 REG_WR(bp, NIG_REG_XGXS0_CTRL_MD_DEVAD + port*0x18,
6283 0x5);
6284 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006285
Yaniv Rosnere10bc842010-09-07 11:40:50 +00006286 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006287 5,
6288 (MDIO_REG_BANK_AER_BLOCK +
6289 (MDIO_AER_BLOCK_AER_REG & 0xf)),
6290 0x2800);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006291
Yaniv Rosnere10bc842010-09-07 11:40:50 +00006292 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006293 5,
6294 (MDIO_REG_BANK_CL73_IEEEB0 +
6295 (MDIO_CL73_IEEEB0_CL73_AN_CONTROL & 0xf)),
6296 0x6041);
Eilon Greenstein38582762009-01-14 06:44:16 +00006297 msleep(200);
Yuval Mintzd2310232012-06-20 19:05:19 +00006298 /* Set aer mmd back */
Yaniv Rosnerec146a62011-05-31 21:29:27 +00006299 bnx2x_set_aer_mmd(params, phy);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006300
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006301 if (!CHIP_IS_E3(bp)) {
Yuval Mintzd2310232012-06-20 19:05:19 +00006302 /* And md_devad */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006303 REG_WR(bp, NIG_REG_XGXS0_CTRL_MD_DEVAD + port*0x18,
6304 md_devad);
6305 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006306 } else {
Yaniv Rosnere10bc842010-09-07 11:40:50 +00006307 u16 mii_ctrl;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006308 DP(NETIF_MSG_LINK, "XGXS 1G loopback enable\n");
Yaniv Rosnere10bc842010-09-07 11:40:50 +00006309 bnx2x_cl45_read(bp, phy, 5,
6310 (MDIO_REG_BANK_COMBO_IEEE0 +
6311 (MDIO_COMBO_IEEE0_MII_CONTROL & 0xf)),
6312 &mii_ctrl);
6313 bnx2x_cl45_write(bp, phy, 5,
6314 (MDIO_REG_BANK_COMBO_IEEE0 +
6315 (MDIO_COMBO_IEEE0_MII_CONTROL & 0xf)),
6316 mii_ctrl |
6317 MDIO_COMBO_IEEO_MII_CONTROL_LOOPBACK);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006318 }
6319}
6320
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006321int bnx2x_set_led(struct link_params *params,
6322 struct link_vars *vars, u8 mode, u32 speed)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006323{
Yaniv Rosner7846e472009-11-05 19:18:07 +02006324 u8 port = params->port;
6325 u16 hw_led_mode = params->hw_led_mode;
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006326 int rc = 0;
6327 u8 phy_idx;
Eilon Greenstein345b5d52008-08-13 15:58:12 -07006328 u32 tmp;
6329 u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
Yaniv Rosner7846e472009-11-05 19:18:07 +02006330 struct bnx2x *bp = params->bp;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006331 DP(NETIF_MSG_LINK, "bnx2x_set_led: port %x, mode %d\n", port, mode);
6332 DP(NETIF_MSG_LINK, "speed 0x%x, hw_led_mode 0x%x\n",
6333 speed, hw_led_mode);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006334 /* In case */
6335 for (phy_idx = EXT_PHY1; phy_idx < MAX_PHYS; phy_idx++) {
6336 if (params->phy[phy_idx].set_link_led) {
6337 params->phy[phy_idx].set_link_led(
6338 &params->phy[phy_idx], params, mode);
6339 }
6340 }
6341
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006342 switch (mode) {
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006343 case LED_MODE_FRONT_PANEL_OFF:
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006344 case LED_MODE_OFF:
6345 REG_WR(bp, NIG_REG_LED_10G_P0 + port*4, 0);
6346 REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006347 SHARED_HW_CFG_LED_MAC1);
Eilon Greenstein345b5d52008-08-13 15:58:12 -07006348
6349 tmp = EMAC_RD(bp, EMAC_REG_EMAC_LED);
Yaniv Rosner001cea72011-10-27 05:09:48 +00006350 if (params->phy[EXT_PHY1].type ==
Yaniv Rosner9379c9b2012-04-04 01:28:58 +00006351 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54618SE)
6352 tmp &= ~(EMAC_LED_1000MB_OVERRIDE |
6353 EMAC_LED_100MB_OVERRIDE |
6354 EMAC_LED_10MB_OVERRIDE);
6355 else
6356 tmp |= EMAC_LED_OVERRIDE;
6357
6358 EMAC_WR(bp, EMAC_REG_EMAC_LED, tmp);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006359 break;
6360
6361 case LED_MODE_OPER:
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00006362 /* For all other phys, OPER mode is same as ON, so in case
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006363 * link is down, do nothing
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006364 */
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006365 if (!vars->link_up)
6366 break;
6367 case LED_MODE_ON:
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00006368 if (((params->phy[EXT_PHY1].type ==
6369 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727) ||
6370 (params->phy[EXT_PHY1].type ==
6371 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8722)) &&
Yaniv Rosner1f483532011-01-18 04:33:31 +00006372 CHIP_IS_E2(bp) && params->num_phys == 2) {
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00006373 /* This is a work-around for E2+8727 Configurations */
Yaniv Rosner1f483532011-01-18 04:33:31 +00006374 if (mode == LED_MODE_ON ||
6375 speed == SPEED_10000){
6376 REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4, 0);
6377 REG_WR(bp, NIG_REG_LED_10G_P0 + port*4, 1);
6378
6379 tmp = EMAC_RD(bp, EMAC_REG_EMAC_LED);
6380 EMAC_WR(bp, EMAC_REG_EMAC_LED,
6381 (tmp | EMAC_LED_OVERRIDE));
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00006382 /* Return here without enabling traffic
David S. Miller8decf862011-09-22 03:23:13 -04006383 * LED blink and setting rate in ON mode.
Yaniv Rosner793bd452011-08-02 22:59:40 +00006384 * In oper mode, enabling LED blink
6385 * and setting rate is needed.
6386 */
6387 if (mode == LED_MODE_ON)
6388 return rc;
Yaniv Rosner1f483532011-01-18 04:33:31 +00006389 }
Yaniv Rosner793bd452011-08-02 22:59:40 +00006390 } else if (SINGLE_MEDIA_DIRECT(params)) {
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00006391 /* This is a work-around for HW issue found when link
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006392 * is up in CL73
6393 */
David S. Miller8decf862011-09-22 03:23:13 -04006394 if ((!CHIP_IS_E3(bp)) ||
6395 (CHIP_IS_E3(bp) &&
6396 mode == LED_MODE_ON))
6397 REG_WR(bp, NIG_REG_LED_10G_P0 + port*4, 1);
6398
Yaniv Rosner793bd452011-08-02 22:59:40 +00006399 if (CHIP_IS_E1x(bp) ||
6400 CHIP_IS_E2(bp) ||
6401 (mode == LED_MODE_ON))
6402 REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4, 0);
6403 else
6404 REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4,
6405 hw_led_mode);
Yaniv Rosner001cea72011-10-27 05:09:48 +00006406 } else if ((params->phy[EXT_PHY1].type ==
6407 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54618SE) &&
Yaniv Rosner9379c9b2012-04-04 01:28:58 +00006408 (mode == LED_MODE_ON)) {
Yaniv Rosner001cea72011-10-27 05:09:48 +00006409 REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4, 0);
6410 tmp = EMAC_RD(bp, EMAC_REG_EMAC_LED);
Yaniv Rosner9379c9b2012-04-04 01:28:58 +00006411 EMAC_WR(bp, EMAC_REG_EMAC_LED, tmp |
6412 EMAC_LED_OVERRIDE | EMAC_LED_1000MB_OVERRIDE);
6413 /* Break here; otherwise, it'll disable the
6414 * intended override.
6415 */
6416 break;
Yaniv Rosner793bd452011-08-02 22:59:40 +00006417 } else
Yaniv Rosner001cea72011-10-27 05:09:48 +00006418 REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4,
6419 hw_led_mode);
Yaniv Rosner7846e472009-11-05 19:18:07 +02006420
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006421 REG_WR(bp, NIG_REG_LED_CONTROL_OVERRIDE_TRAFFIC_P0 + port*4, 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006422 /* Set blinking rate to ~15.9Hz */
Yaniv Rosner26ffaf32011-10-27 05:09:45 +00006423 if (CHIP_IS_E3(bp))
6424 REG_WR(bp, NIG_REG_LED_CONTROL_BLINK_RATE_P0 + port*4,
6425 LED_BLINK_RATE_VAL_E3);
6426 else
6427 REG_WR(bp, NIG_REG_LED_CONTROL_BLINK_RATE_P0 + port*4,
6428 LED_BLINK_RATE_VAL_E1X_E2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006429 REG_WR(bp, NIG_REG_LED_CONTROL_BLINK_RATE_ENA_P0 +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006430 port*4, 1);
Yaniv Rosner9379c9b2012-04-04 01:28:58 +00006431 tmp = EMAC_RD(bp, EMAC_REG_EMAC_LED);
6432 EMAC_WR(bp, EMAC_REG_EMAC_LED,
6433 (tmp & (~EMAC_LED_OVERRIDE)));
Eilon Greenstein345b5d52008-08-13 15:58:12 -07006434
Yaniv Rosner7846e472009-11-05 19:18:07 +02006435 if (CHIP_IS_E1(bp) &&
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006436 ((speed == SPEED_2500) ||
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006437 (speed == SPEED_1000) ||
6438 (speed == SPEED_100) ||
6439 (speed == SPEED_10))) {
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00006440 /* For speeds less than 10G LED scheme is different */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006441 REG_WR(bp, NIG_REG_LED_CONTROL_OVERRIDE_TRAFFIC_P0
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006442 + port*4, 1);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006443 REG_WR(bp, NIG_REG_LED_CONTROL_TRAFFIC_P0 +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006444 port*4, 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006445 REG_WR(bp, NIG_REG_LED_CONTROL_BLINK_TRAFFIC_P0 +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006446 port*4, 1);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006447 }
6448 break;
6449
6450 default:
6451 rc = -EINVAL;
6452 DP(NETIF_MSG_LINK, "bnx2x_set_led: Invalid led mode %d\n",
6453 mode);
6454 break;
6455 }
6456 return rc;
6457
6458}
6459
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00006460/* This function comes to reflect the actual link state read DIRECTLY from the
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006461 * HW
6462 */
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006463int bnx2x_test_link(struct link_params *params, struct link_vars *vars,
6464 u8 is_serdes)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006465{
6466 struct bnx2x *bp = params->bp;
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00006467 u16 gp_status = 0, phy_index = 0;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006468 u8 ext_phy_link_up = 0, serdes_phy_type;
6469 struct link_vars temp_vars;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006470 struct bnx2x_phy *int_phy = &params->phy[INT_PHY];
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006471
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006472 if (CHIP_IS_E3(bp)) {
6473 u16 link_up;
6474 if (params->req_line_speed[LINK_CONFIG_IDX(INT_PHY)]
6475 > SPEED_10000) {
6476 /* Check 20G link */
6477 bnx2x_cl45_read(bp, int_phy, MDIO_WC_DEVAD,
6478 1, &link_up);
6479 bnx2x_cl45_read(bp, int_phy, MDIO_WC_DEVAD,
6480 1, &link_up);
6481 link_up &= (1<<2);
6482 } else {
6483 /* Check 10G link and below*/
6484 u8 lane = bnx2x_get_warpcore_lane(int_phy, params);
6485 bnx2x_cl45_read(bp, int_phy, MDIO_WC_DEVAD,
6486 MDIO_WC_REG_GP2_STATUS_GP_2_1,
6487 &gp_status);
6488 gp_status = ((gp_status >> 8) & 0xf) |
6489 ((gp_status >> 12) & 0xf);
6490 link_up = gp_status & (1 << lane);
6491 }
6492 if (!link_up)
6493 return -ESRCH;
6494 } else {
6495 CL22_RD_OVER_CL45(bp, int_phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006496 MDIO_REG_BANK_GP_STATUS,
6497 MDIO_GP_STATUS_TOP_AN_STATUS1,
6498 &gp_status);
Yuval Mintzd2310232012-06-20 19:05:19 +00006499 /* Link is up only if both local phy and external phy are up */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006500 if (!(gp_status & MDIO_GP_STATUS_TOP_AN_STATUS1_LINK_STATUS))
6501 return -ESRCH;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006502 }
6503 /* In XGXS loopback mode, do not check external PHY */
6504 if (params->loopback_mode == LOOPBACK_XGXS)
6505 return 0;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006506
6507 switch (params->num_phys) {
6508 case 1:
6509 /* No external PHY */
6510 return 0;
6511 case 2:
6512 ext_phy_link_up = params->phy[EXT_PHY1].read_status(
6513 &params->phy[EXT_PHY1],
6514 params, &temp_vars);
6515 break;
6516 case 3: /* Dual Media */
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00006517 for (phy_index = EXT_PHY1; phy_index < params->num_phys;
6518 phy_index++) {
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006519 serdes_phy_type = ((params->phy[phy_index].media_type ==
Yuval Mintzdbef8072012-06-20 19:05:22 +00006520 ETH_PHY_SFPP_10G_FIBER) ||
6521 (params->phy[phy_index].media_type ==
6522 ETH_PHY_SFP_1G_FIBER) ||
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006523 (params->phy[phy_index].media_type ==
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00006524 ETH_PHY_XFP_FIBER) ||
6525 (params->phy[phy_index].media_type ==
6526 ETH_PHY_DA_TWINAX));
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006527
6528 if (is_serdes != serdes_phy_type)
6529 continue;
6530 if (params->phy[phy_index].read_status) {
6531 ext_phy_link_up |=
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00006532 params->phy[phy_index].read_status(
6533 &params->phy[phy_index],
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006534 params, &temp_vars);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006535 }
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00006536 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006537 break;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006538 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006539 if (ext_phy_link_up)
6540 return 0;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006541 return -ESRCH;
6542}
6543
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006544static int bnx2x_link_initialize(struct link_params *params,
6545 struct link_vars *vars)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006546{
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006547 int rc = 0;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006548 u8 phy_index, non_ext_phy;
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00006549 struct bnx2x *bp = params->bp;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00006550 /* In case of external phy existence, the line speed would be the
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006551 * line speed linked up by the external phy. In case it is direct
6552 * only, then the line_speed during initialization will be
6553 * equal to the req_line_speed
6554 */
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00006555 vars->line_speed = params->phy[INT_PHY].req_line_speed;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006556
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00006557 /* Initialize the internal phy in case this is a direct board
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00006558 * (no external phys), or this board has external phy which requires
6559 * to first.
6560 */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006561 if (!USES_WARPCORE(bp))
6562 bnx2x_prepare_xgxs(&params->phy[INT_PHY], params, vars);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006563 /* init ext phy and enable link state int */
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00006564 non_ext_phy = (SINGLE_MEDIA_DIRECT(params) ||
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006565 (params->loopback_mode == LOOPBACK_XGXS));
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006566
6567 if (non_ext_phy ||
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00006568 (params->phy[EXT_PHY1].flags & FLAGS_INIT_XGXS_FIRST) ||
Eilon Greenstein8660d8c2009-03-02 08:01:02 +00006569 (params->loopback_mode == LOOPBACK_EXT_PHY)) {
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00006570 struct bnx2x_phy *phy = &params->phy[INT_PHY];
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006571 if (vars->line_speed == SPEED_AUTO_NEG &&
6572 (CHIP_IS_E1x(bp) ||
6573 CHIP_IS_E2(bp)))
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00006574 bnx2x_set_parallel_detection(phy, params);
Yaniv Rosnerec146a62011-05-31 21:29:27 +00006575 if (params->phy[INT_PHY].config_init)
6576 params->phy[INT_PHY].config_init(phy,
6577 params,
6578 vars);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006579 }
6580
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00006581 /* Init external phy*/
Yaniv Rosnerfd36a2e2011-05-31 21:29:05 +00006582 if (non_ext_phy) {
6583 if (params->phy[INT_PHY].supported &
6584 SUPPORTED_FIBRE)
6585 vars->link_status |= LINK_STATUS_SERDES_LINK;
6586 } else {
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006587 for (phy_index = EXT_PHY1; phy_index < params->num_phys;
6588 phy_index++) {
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00006589 /* No need to initialize second phy in case of first
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006590 * phy only selection. In case of second phy, we do
6591 * need to initialize the first phy, since they are
6592 * connected.
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006593 */
Yaniv Rosnerfd36a2e2011-05-31 21:29:05 +00006594 if (params->phy[phy_index].supported &
6595 SUPPORTED_FIBRE)
6596 vars->link_status |= LINK_STATUS_SERDES_LINK;
6597
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006598 if (phy_index == EXT_PHY2 &&
6599 (bnx2x_phy_selection(params) ==
6600 PORT_HW_CFG_PHY_SELECTION_FIRST_PHY)) {
Joe Perches94f05b02011-08-14 12:16:20 +00006601 DP(NETIF_MSG_LINK,
6602 "Not initializing second phy\n");
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006603 continue;
6604 }
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006605 params->phy[phy_index].config_init(
6606 &params->phy[phy_index],
6607 params, vars);
6608 }
Yaniv Rosnerfd36a2e2011-05-31 21:29:05 +00006609 }
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +00006610 /* Reset the interrupt indication after phy was initialized */
6611 bnx2x_bits_dis(bp, NIG_REG_STATUS_INTERRUPT_PORT0 +
6612 params->port*4,
6613 (NIG_STATUS_XGXS0_LINK10G |
6614 NIG_STATUS_XGXS0_LINK_STATUS |
6615 NIG_STATUS_SERDES0_LINK_STATUS |
6616 NIG_MASK_MI_INT));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006617 return rc;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006618}
6619
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006620static void bnx2x_int_link_reset(struct bnx2x_phy *phy,
6621 struct link_params *params)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006622{
Yuval Mintzd2310232012-06-20 19:05:19 +00006623 /* Reset the SerDes/XGXS */
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006624 REG_WR(params->bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_CLEAR,
6625 (0x1ff << (params->port*16)));
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006626}
6627
6628static void bnx2x_common_ext_link_reset(struct bnx2x_phy *phy,
6629 struct link_params *params)
6630{
6631 struct bnx2x *bp = params->bp;
6632 u8 gpio_port;
6633 /* HW reset */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006634 if (CHIP_IS_E2(bp))
6635 gpio_port = BP_PATH(bp);
6636 else
6637 gpio_port = params->port;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006638 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006639 MISC_REGISTERS_GPIO_OUTPUT_LOW,
6640 gpio_port);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006641 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006642 MISC_REGISTERS_GPIO_OUTPUT_LOW,
6643 gpio_port);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006644 DP(NETIF_MSG_LINK, "reset external PHY\n");
6645}
6646
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006647static int bnx2x_update_link_down(struct link_params *params,
6648 struct link_vars *vars)
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006649{
6650 struct bnx2x *bp = params->bp;
6651 u8 port = params->port;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00006652
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006653 DP(NETIF_MSG_LINK, "Port %x: Link is down\n", port);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006654 bnx2x_set_led(params, vars, LED_MODE_OFF, 0);
Yaniv Rosner3deb8162011-06-14 01:34:33 +00006655 vars->phy_flags &= ~PHY_PHYSICAL_LINK_FLAG;
Yuval Mintzd2310232012-06-20 19:05:19 +00006656 /* Indicate no mac active */
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006657 vars->mac_type = MAC_TYPE_NONE;
6658
Yuval Mintzd2310232012-06-20 19:05:19 +00006659 /* Update shared memory */
Yaniv Rosnerfd36a2e2011-05-31 21:29:05 +00006660 vars->link_status &= ~(LINK_STATUS_SPEED_AND_DUPLEX_MASK |
6661 LINK_STATUS_LINK_UP |
Yaniv Rosnerde6f3372011-08-02 22:59:25 +00006662 LINK_STATUS_PHYSICAL_LINK_FLAG |
Yaniv Rosnerfd36a2e2011-05-31 21:29:05 +00006663 LINK_STATUS_AUTO_NEGOTIATE_COMPLETE |
6664 LINK_STATUS_RX_FLOW_CONTROL_FLAG_MASK |
6665 LINK_STATUS_TX_FLOW_CONTROL_FLAG_MASK |
Mintz Yuval9e7e8392012-02-15 02:10:24 +00006666 LINK_STATUS_PARALLEL_DETECTION_FLAG_MASK |
6667 LINK_STATUS_LINK_PARTNER_SYMMETRIC_PAUSE |
6668 LINK_STATUS_LINK_PARTNER_ASYMMETRIC_PAUSE);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006669 vars->line_speed = 0;
6670 bnx2x_update_mng(params, vars->link_status);
6671
Yuval Mintzd2310232012-06-20 19:05:19 +00006672 /* Activate nig drain */
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006673 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + port*4, 1);
6674
Yuval Mintzd2310232012-06-20 19:05:19 +00006675 /* Disable emac */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00006676 if (!CHIP_IS_E3(bp))
6677 REG_WR(bp, NIG_REG_NIG_EMAC0_EN + port*4, 0);
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00006678
Yuval Mintzd2310232012-06-20 19:05:19 +00006679 usleep_range(10000, 20000);
6680 /* Reset BigMac/Xmac */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00006681 if (CHIP_IS_E1x(bp) ||
6682 CHIP_IS_E2(bp)) {
6683 bnx2x_bmac_rx_disable(bp, params->port);
6684 REG_WR(bp, GRCBASE_MISC +
6685 MISC_REGISTERS_RESET_REG_2_CLEAR,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006686 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port));
Yaniv Rosner9380bb92011-06-14 01:34:07 +00006687 }
Yaniv Rosnerce7c0482011-10-27 05:09:47 +00006688 if (CHIP_IS_E3(bp)) {
Yuval Mintzd2310232012-06-20 19:05:19 +00006689 /* Prevent LPI Generation by chip */
Yuval Mintzc8c60d82012-06-06 17:13:07 +00006690 REG_WR(bp, MISC_REG_CPMU_LP_FW_ENABLE_P0 + (params->port << 2),
6691 0);
Yuval Mintzc8c60d82012-06-06 17:13:07 +00006692 REG_WR(bp, MISC_REG_CPMU_LP_MASK_ENT_P0 + (params->port << 2),
6693 0);
6694 vars->eee_status &= ~(SHMEM_EEE_LP_ADV_STATUS_MASK |
6695 SHMEM_EEE_ACTIVE_BIT);
6696
6697 bnx2x_update_mng_eee(params, vars->eee_status);
Yaniv Rosner9380bb92011-06-14 01:34:07 +00006698 bnx2x_xmac_disable(params);
Yaniv Rosnerce7c0482011-10-27 05:09:47 +00006699 bnx2x_umac_disable(params);
6700 }
Yaniv Rosner9380bb92011-06-14 01:34:07 +00006701
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006702 return 0;
6703}
6704
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006705static int bnx2x_update_link_up(struct link_params *params,
6706 struct link_vars *vars,
6707 u8 link_10g)
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006708{
6709 struct bnx2x *bp = params->bp;
Yaniv Rosner55098c52012-04-03 18:41:27 +00006710 u8 phy_idx, port = params->port;
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006711 int rc = 0;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00006712
Yaniv Rosnerde6f3372011-08-02 22:59:25 +00006713 vars->link_status |= (LINK_STATUS_LINK_UP |
6714 LINK_STATUS_PHYSICAL_LINK_FLAG);
Yaniv Rosner3deb8162011-06-14 01:34:33 +00006715 vars->phy_flags |= PHY_PHYSICAL_LINK_FLAG;
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006716
Yaniv Rosner7aa07112010-09-07 11:41:01 +00006717 if (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX)
6718 vars->link_status |=
6719 LINK_STATUS_TX_FLOW_CONTROL_ENABLED;
6720
6721 if (vars->flow_ctrl & BNX2X_FLOW_CTRL_RX)
6722 vars->link_status |=
6723 LINK_STATUS_RX_FLOW_CONTROL_ENABLED;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00006724 if (USES_WARPCORE(bp)) {
Yaniv Rosner3deb8162011-06-14 01:34:33 +00006725 if (link_10g) {
6726 if (bnx2x_xmac_enable(params, vars, 0) ==
6727 -ESRCH) {
6728 DP(NETIF_MSG_LINK, "Found errors on XMAC\n");
6729 vars->link_up = 0;
6730 vars->phy_flags |= PHY_HALF_OPEN_CONN_FLAG;
6731 vars->link_status &= ~LINK_STATUS_LINK_UP;
6732 }
6733 } else
Yaniv Rosner9380bb92011-06-14 01:34:07 +00006734 bnx2x_umac_enable(params, vars, 0);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006735 bnx2x_set_led(params, vars,
Yaniv Rosner9380bb92011-06-14 01:34:07 +00006736 LED_MODE_OPER, vars->line_speed);
Yuval Mintzc8c60d82012-06-06 17:13:07 +00006737
6738 if ((vars->eee_status & SHMEM_EEE_ACTIVE_BIT) &&
6739 (vars->eee_status & SHMEM_EEE_LPI_REQUESTED_BIT)) {
6740 DP(NETIF_MSG_LINK, "Enabling LPI assertion\n");
6741 REG_WR(bp, MISC_REG_CPMU_LP_FW_ENABLE_P0 +
6742 (params->port << 2), 1);
6743 REG_WR(bp, MISC_REG_CPMU_LP_DR_ENABLE, 1);
6744 REG_WR(bp, MISC_REG_CPMU_LP_MASK_ENT_P0 +
6745 (params->port << 2), 0xfc20);
6746 }
Yaniv Rosner9380bb92011-06-14 01:34:07 +00006747 }
6748 if ((CHIP_IS_E1x(bp) ||
6749 CHIP_IS_E2(bp))) {
6750 if (link_10g) {
Yaniv Rosner3deb8162011-06-14 01:34:33 +00006751 if (bnx2x_bmac_enable(params, vars, 0) ==
6752 -ESRCH) {
6753 DP(NETIF_MSG_LINK, "Found errors on BMAC\n");
6754 vars->link_up = 0;
6755 vars->phy_flags |= PHY_HALF_OPEN_CONN_FLAG;
6756 vars->link_status &= ~LINK_STATUS_LINK_UP;
6757 }
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006758
Yaniv Rosner9380bb92011-06-14 01:34:07 +00006759 bnx2x_set_led(params, vars,
6760 LED_MODE_OPER, SPEED_10000);
6761 } else {
6762 rc = bnx2x_emac_program(params, vars);
6763 bnx2x_emac_enable(params, vars, 0);
Yaniv Rosner0c786f02009-11-05 19:18:32 +02006764
Yaniv Rosner9380bb92011-06-14 01:34:07 +00006765 /* AN complete? */
6766 if ((vars->link_status &
6767 LINK_STATUS_AUTO_NEGOTIATE_COMPLETE)
6768 && (!(vars->phy_flags & PHY_SGMII_FLAG)) &&
6769 SINGLE_MEDIA_DIRECT(params))
6770 bnx2x_set_gmii_tx_driver(params);
6771 }
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006772 }
6773
6774 /* PBF - link up */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00006775 if (CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006776 rc |= bnx2x_pbf_update(params, vars->flow_ctrl,
6777 vars->line_speed);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006778
Yuval Mintzd2310232012-06-20 19:05:19 +00006779 /* Disable drain */
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006780 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + port*4, 0);
6781
Yuval Mintzd2310232012-06-20 19:05:19 +00006782 /* Update shared memory */
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006783 bnx2x_update_mng(params, vars->link_status);
Yuval Mintzc8c60d82012-06-06 17:13:07 +00006784 bnx2x_update_mng_eee(params, vars->eee_status);
Yaniv Rosner55098c52012-04-03 18:41:27 +00006785 /* Check remote fault */
6786 for (phy_idx = INT_PHY; phy_idx < MAX_PHYS; phy_idx++) {
6787 if (params->phy[phy_idx].flags & FLAGS_TX_ERROR_CHECK) {
6788 bnx2x_check_half_open_conn(params, vars, 0);
6789 break;
6790 }
6791 }
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00006792 msleep(20);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006793 return rc;
6794}
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00006795/* The bnx2x_link_update function should be called upon link
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006796 * interrupt.
6797 * Link is considered up as follows:
6798 * - DIRECT_SINGLE_MEDIA - Only XGXS link (internal link) needs
6799 * to be up
6800 * - SINGLE_MEDIA - The link between the 577xx and the external
6801 * phy (XGXS) need to up as well as the external link of the
6802 * phy (PHY_EXT1)
6803 * - DUAL_MEDIA - The link between the 577xx and the first
6804 * external phy needs to be up, and at least one of the 2
6805 * external phy link must be up.
Yaniv Rosner62b29a52010-09-07 11:40:58 +00006806 */
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006807int bnx2x_link_update(struct link_params *params, struct link_vars *vars)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006808{
6809 struct bnx2x *bp = params->bp;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006810 struct link_vars phy_vars[MAX_PHYS];
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006811 u8 port = params->port;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006812 u8 link_10g_plus, phy_index;
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006813 u8 ext_phy_link_up = 0, cur_link_up;
6814 int rc = 0;
Eilon Greenstein2f904462009-08-12 08:22:16 +00006815 u8 is_mi_int = 0;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006816 u16 ext_phy_line_speed = 0, prev_line_speed = vars->line_speed;
6817 u8 active_external_phy = INT_PHY;
Yaniv Rosner3deb8162011-06-14 01:34:33 +00006818 vars->phy_flags &= ~PHY_HALF_OPEN_CONN_FLAG;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006819 for (phy_index = INT_PHY; phy_index < params->num_phys;
6820 phy_index++) {
6821 phy_vars[phy_index].flow_ctrl = 0;
6822 phy_vars[phy_index].link_status = 0;
6823 phy_vars[phy_index].line_speed = 0;
6824 phy_vars[phy_index].duplex = DUPLEX_FULL;
6825 phy_vars[phy_index].phy_link_up = 0;
6826 phy_vars[phy_index].link_up = 0;
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00006827 phy_vars[phy_index].fault_detected = 0;
Yuval Mintzc8c60d82012-06-06 17:13:07 +00006828 /* different consideration, since vars holds inner state */
6829 phy_vars[phy_index].eee_status = vars->eee_status;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006830 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006831
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006832 if (USES_WARPCORE(bp))
6833 bnx2x_set_aer_mmd(params, &params->phy[INT_PHY]);
6834
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006835 DP(NETIF_MSG_LINK, "port %x, XGXS?%x, int_status 0x%x\n",
Eilon Greenstein2f904462009-08-12 08:22:16 +00006836 port, (vars->phy_flags & PHY_XGXS_FLAG),
6837 REG_RD(bp, NIG_REG_STATUS_INTERRUPT_PORT0 + port*4));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006838
Eilon Greenstein2f904462009-08-12 08:22:16 +00006839 is_mi_int = (u8)(REG_RD(bp, NIG_REG_EMAC0_STATUS_MISC_MI_INT +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006840 port*0x18) > 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006841 DP(NETIF_MSG_LINK, "int_mask 0x%x MI_INT %x, SERDES_LINK %x\n",
Eilon Greenstein2f904462009-08-12 08:22:16 +00006842 REG_RD(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4),
6843 is_mi_int,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006844 REG_RD(bp, NIG_REG_SERDES0_STATUS_LINK_STATUS + port*0x3c));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006845
6846 DP(NETIF_MSG_LINK, " 10G %x, XGXS_LINK %x\n",
6847 REG_RD(bp, NIG_REG_XGXS0_STATUS_LINK10G + port*0x68),
6848 REG_RD(bp, NIG_REG_XGXS0_STATUS_LINK_STATUS + port*0x68));
6849
Yuval Mintzd2310232012-06-20 19:05:19 +00006850 /* Disable emac */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00006851 if (!CHIP_IS_E3(bp))
6852 REG_WR(bp, NIG_REG_NIG_EMAC0_EN + port*4, 0);
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00006853
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00006854 /* Step 1:
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006855 * Check external link change only for external phys, and apply
6856 * priority selection between them in case the link on both phys
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00006857 * is up. Note that instead of the common vars, a temporary
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006858 * vars argument is used since each phy may have different link/
6859 * speed/duplex result
6860 */
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006861 for (phy_index = EXT_PHY1; phy_index < params->num_phys;
6862 phy_index++) {
6863 struct bnx2x_phy *phy = &params->phy[phy_index];
6864 if (!phy->read_status)
6865 continue;
6866 /* Read link status and params of this ext phy */
6867 cur_link_up = phy->read_status(phy, params,
6868 &phy_vars[phy_index]);
6869 if (cur_link_up) {
6870 DP(NETIF_MSG_LINK, "phy in index %d link is up\n",
6871 phy_index);
6872 } else {
6873 DP(NETIF_MSG_LINK, "phy in index %d link is down\n",
6874 phy_index);
6875 continue;
6876 }
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006877
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006878 if (!ext_phy_link_up) {
6879 ext_phy_link_up = 1;
6880 active_external_phy = phy_index;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006881 } else {
6882 switch (bnx2x_phy_selection(params)) {
6883 case PORT_HW_CFG_PHY_SELECTION_HARDWARE_DEFAULT:
6884 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY_PRIORITY:
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00006885 /* In this option, the first PHY makes sure to pass the
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006886 * traffic through itself only.
6887 * Its not clear how to reset the link on the second phy
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006888 */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006889 active_external_phy = EXT_PHY1;
6890 break;
6891 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY_PRIORITY:
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00006892 /* In this option, the first PHY makes sure to pass the
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006893 * traffic through the second PHY.
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006894 */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006895 active_external_phy = EXT_PHY2;
6896 break;
6897 default:
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00006898 /* Link indication on both PHYs with the following cases
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006899 * is invalid:
6900 * - FIRST_PHY means that second phy wasn't initialized,
6901 * hence its link is expected to be down
6902 * - SECOND_PHY means that first phy should not be able
6903 * to link up by itself (using configuration)
6904 * - DEFAULT should be overriden during initialiazation
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006905 */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006906 DP(NETIF_MSG_LINK, "Invalid link indication"
6907 "mpc=0x%x. DISABLING LINK !!!\n",
6908 params->multi_phy_config);
6909 ext_phy_link_up = 0;
6910 break;
6911 }
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006912 }
6913 }
6914 prev_line_speed = vars->line_speed;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00006915 /* Step 2:
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006916 * Read the status of the internal phy. In case of
6917 * DIRECT_SINGLE_MEDIA board, this link is the external link,
6918 * otherwise this is the link between the 577xx and the first
6919 * external phy
6920 */
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006921 if (params->phy[INT_PHY].read_status)
6922 params->phy[INT_PHY].read_status(
6923 &params->phy[INT_PHY],
6924 params, vars);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00006925 /* The INT_PHY flow control reside in the vars. This include the
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006926 * case where the speed or flow control are not set to AUTO.
6927 * Otherwise, the active external phy flow control result is set
6928 * to the vars. The ext_phy_line_speed is needed to check if the
6929 * speed is different between the internal phy and external phy.
6930 * This case may be result of intermediate link speed change.
6931 */
6932 if (active_external_phy > INT_PHY) {
6933 vars->flow_ctrl = phy_vars[active_external_phy].flow_ctrl;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00006934 /* Link speed is taken from the XGXS. AN and FC result from
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006935 * the external phy.
6936 */
6937 vars->link_status |= phy_vars[active_external_phy].link_status;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006938
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00006939 /* if active_external_phy is first PHY and link is up - disable
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006940 * disable TX on second external PHY
6941 */
6942 if (active_external_phy == EXT_PHY1) {
6943 if (params->phy[EXT_PHY2].phy_specific_func) {
Joe Perches94f05b02011-08-14 12:16:20 +00006944 DP(NETIF_MSG_LINK,
6945 "Disabling TX on EXT_PHY2\n");
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006946 params->phy[EXT_PHY2].phy_specific_func(
6947 &params->phy[EXT_PHY2],
6948 params, DISABLE_TX);
6949 }
6950 }
6951
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006952 ext_phy_line_speed = phy_vars[active_external_phy].line_speed;
6953 vars->duplex = phy_vars[active_external_phy].duplex;
6954 if (params->phy[active_external_phy].supported &
6955 SUPPORTED_FIBRE)
6956 vars->link_status |= LINK_STATUS_SERDES_LINK;
Yaniv Rosnerfd36a2e2011-05-31 21:29:05 +00006957 else
6958 vars->link_status &= ~LINK_STATUS_SERDES_LINK;
Yuval Mintzc8c60d82012-06-06 17:13:07 +00006959
6960 vars->eee_status = phy_vars[active_external_phy].eee_status;
6961
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006962 DP(NETIF_MSG_LINK, "Active external phy selected: %x\n",
6963 active_external_phy);
6964 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006965
6966 for (phy_index = EXT_PHY1; phy_index < params->num_phys;
6967 phy_index++) {
6968 if (params->phy[phy_index].flags &
6969 FLAGS_REARM_LATCH_SIGNAL) {
6970 bnx2x_rearm_latch_signal(bp, port,
6971 phy_index ==
6972 active_external_phy);
6973 break;
6974 }
6975 }
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006976 DP(NETIF_MSG_LINK, "vars->flow_ctrl = 0x%x, vars->link_status = 0x%x,"
6977 " ext_phy_line_speed = %d\n", vars->flow_ctrl,
6978 vars->link_status, ext_phy_line_speed);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00006979 /* Upon link speed change set the NIG into drain mode. Comes to
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006980 * deals with possible FIFO glitch due to clk change when speed
6981 * is decreased without link down indicator
6982 */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006983
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006984 if (vars->phy_link_up) {
6985 if (!(SINGLE_MEDIA_DIRECT(params)) && ext_phy_link_up &&
6986 (ext_phy_line_speed != vars->line_speed)) {
6987 DP(NETIF_MSG_LINK, "Internal link speed %d is"
6988 " different than the external"
6989 " link speed %d\n", vars->line_speed,
6990 ext_phy_line_speed);
6991 vars->phy_link_up = 0;
6992 } else if (prev_line_speed != vars->line_speed) {
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006993 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4,
6994 0);
Yuval Mintzd2310232012-06-20 19:05:19 +00006995 usleep_range(1000, 2000);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006996 }
6997 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006998
Yuval Mintzd2310232012-06-20 19:05:19 +00006999 /* Anything 10 and over uses the bmac */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00007000 link_10g_plus = (vars->line_speed >= SPEED_10000);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07007001
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00007002 bnx2x_link_int_ack(params, vars, link_10g_plus);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07007003
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00007004 /* In case external phy link is up, and internal link is down
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007005 * (not initialized yet probably after link initialization, it
7006 * needs to be initialized.
7007 * Note that after link down-up as result of cable plug, the xgxs
7008 * link would probably become up again without the need
7009 * initialize it
7010 */
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007011 if (!(SINGLE_MEDIA_DIRECT(params))) {
7012 DP(NETIF_MSG_LINK, "ext_phy_link_up = %d, int_link_up = %d,"
7013 " init_preceding = %d\n", ext_phy_link_up,
7014 vars->phy_link_up,
7015 params->phy[EXT_PHY1].flags &
7016 FLAGS_INIT_XGXS_FIRST);
7017 if (!(params->phy[EXT_PHY1].flags &
7018 FLAGS_INIT_XGXS_FIRST)
7019 && ext_phy_link_up && !vars->phy_link_up) {
7020 vars->line_speed = ext_phy_line_speed;
7021 if (vars->line_speed < SPEED_1000)
7022 vars->phy_flags |= PHY_SGMII_FLAG;
7023 else
7024 vars->phy_flags &= ~PHY_SGMII_FLAG;
Yaniv Rosnerec146a62011-05-31 21:29:27 +00007025
7026 if (params->phy[INT_PHY].config_init)
7027 params->phy[INT_PHY].config_init(
7028 &params->phy[INT_PHY], params,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007029 vars);
7030 }
7031 }
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00007032 /* Link is up only if both local phy and external phy (in case of
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00007033 * non-direct board) are up and no fault detected on active PHY.
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007034 */
7035 vars->link_up = (vars->phy_link_up &&
7036 (ext_phy_link_up ||
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00007037 SINGLE_MEDIA_DIRECT(params)) &&
7038 (phy_vars[active_external_phy].fault_detected == 0));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07007039
Yaniv Rosner27d91292012-04-04 01:28:54 +00007040 /* Update the PFC configuration in case it was changed */
7041 if (params->feature_config_flags & FEATURE_CONFIG_PFC_ENABLED)
7042 vars->link_status |= LINK_STATUS_PFC_ENABLED;
7043 else
7044 vars->link_status &= ~LINK_STATUS_PFC_ENABLED;
7045
Yaniv Rosner57963ed2008-08-13 15:55:28 -07007046 if (vars->link_up)
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00007047 rc = bnx2x_update_link_up(params, vars, link_10g_plus);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07007048 else
7049 rc = bnx2x_update_link_down(params, vars);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07007050
Barak Witkowskia3348722012-04-23 03:04:46 +00007051 /* Update MCP link status was changed */
7052 if (params->feature_config_flags & FEATURE_CONFIG_BC_SUPPORTS_AFEX)
7053 bnx2x_fw_command(bp, DRV_MSG_CODE_LINK_STATUS_CHANGED, 0);
7054
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07007055 return rc;
7056}
7057
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007058/*****************************************************************************/
7059/* External Phy section */
7060/*****************************************************************************/
7061void bnx2x_ext_phy_hw_reset(struct bnx2x *bp, u8 port)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007062{
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007063 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007064 MISC_REGISTERS_GPIO_OUTPUT_LOW, port);
Yuval Mintzd2310232012-06-20 19:05:19 +00007065 usleep_range(1000, 2000);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007066 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007067 MISC_REGISTERS_GPIO_OUTPUT_HIGH, port);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007068}
7069
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007070static void bnx2x_save_spirom_version(struct bnx2x *bp, u8 port,
7071 u32 spirom_ver, u32 ver_addr)
7072{
7073 DP(NETIF_MSG_LINK, "FW version 0x%x:0x%x for port %d\n",
7074 (u16)(spirom_ver>>16), (u16)spirom_ver, port);
7075
7076 if (ver_addr)
7077 REG_WR(bp, ver_addr, spirom_ver);
7078}
7079
7080static void bnx2x_save_bcm_spirom_ver(struct bnx2x *bp,
7081 struct bnx2x_phy *phy,
7082 u8 port)
7083{
7084 u16 fw_ver1, fw_ver2;
7085
7086 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007087 MDIO_PMA_REG_ROM_VER1, &fw_ver1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007088 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007089 MDIO_PMA_REG_ROM_VER2, &fw_ver2);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007090 bnx2x_save_spirom_version(bp, port, (u32)(fw_ver1<<16 | fw_ver2),
7091 phy->ver_addr);
7092}
7093
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007094static void bnx2x_ext_phy_10G_an_resolve(struct bnx2x *bp,
7095 struct bnx2x_phy *phy,
7096 struct link_vars *vars)
7097{
7098 u16 val;
7099 bnx2x_cl45_read(bp, phy,
7100 MDIO_AN_DEVAD,
7101 MDIO_AN_REG_STATUS, &val);
7102 bnx2x_cl45_read(bp, phy,
7103 MDIO_AN_DEVAD,
7104 MDIO_AN_REG_STATUS, &val);
7105 if (val & (1<<5))
7106 vars->link_status |= LINK_STATUS_AUTO_NEGOTIATE_COMPLETE;
7107 if ((val & (1<<0)) == 0)
7108 vars->link_status |= LINK_STATUS_PARALLEL_DETECTION_USED;
7109}
7110
7111/******************************************************************/
7112/* common BCM8073/BCM8727 PHY SECTION */
7113/******************************************************************/
7114static void bnx2x_8073_resolve_fc(struct bnx2x_phy *phy,
7115 struct link_params *params,
7116 struct link_vars *vars)
7117{
7118 struct bnx2x *bp = params->bp;
7119 if (phy->req_line_speed == SPEED_10 ||
7120 phy->req_line_speed == SPEED_100) {
7121 vars->flow_ctrl = phy->req_flow_ctrl;
7122 return;
7123 }
7124
7125 if (bnx2x_ext_phy_resolve_fc(phy, params, vars) &&
7126 (vars->flow_ctrl == BNX2X_FLOW_CTRL_NONE)) {
7127 u16 pause_result;
7128 u16 ld_pause; /* local */
7129 u16 lp_pause; /* link partner */
7130 bnx2x_cl45_read(bp, phy,
7131 MDIO_AN_DEVAD,
7132 MDIO_AN_REG_CL37_FC_LD, &ld_pause);
7133
7134 bnx2x_cl45_read(bp, phy,
7135 MDIO_AN_DEVAD,
7136 MDIO_AN_REG_CL37_FC_LP, &lp_pause);
7137 pause_result = (ld_pause &
7138 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) >> 5;
7139 pause_result |= (lp_pause &
7140 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) >> 7;
7141
7142 bnx2x_pause_resolve(vars, pause_result);
7143 DP(NETIF_MSG_LINK, "Ext PHY CL37 pause result 0x%x\n",
7144 pause_result);
7145 }
7146}
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00007147static int bnx2x_8073_8727_external_rom_boot(struct bnx2x *bp,
7148 struct bnx2x_phy *phy,
7149 u8 port)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007150{
Yaniv Rosner5c99274b2011-01-18 04:33:36 +00007151 u32 count = 0;
7152 u16 fw_ver1, fw_msgout;
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00007153 int rc = 0;
Yaniv Rosner5c99274b2011-01-18 04:33:36 +00007154
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007155 /* Boot port from external ROM */
7156 /* EDC grst */
7157 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007158 MDIO_PMA_DEVAD,
7159 MDIO_PMA_REG_GEN_CTRL,
7160 0x0001);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007161
Yuval Mintzd2310232012-06-20 19:05:19 +00007162 /* Ucode reboot and rst */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007163 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007164 MDIO_PMA_DEVAD,
7165 MDIO_PMA_REG_GEN_CTRL,
7166 0x008c);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007167
7168 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007169 MDIO_PMA_DEVAD,
7170 MDIO_PMA_REG_MISC_CTRL1, 0x0001);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007171
7172 /* Reset internal microprocessor */
7173 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007174 MDIO_PMA_DEVAD,
7175 MDIO_PMA_REG_GEN_CTRL,
7176 MDIO_PMA_REG_GEN_CTRL_ROM_MICRO_RESET);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007177
7178 /* Release srst bit */
7179 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007180 MDIO_PMA_DEVAD,
7181 MDIO_PMA_REG_GEN_CTRL,
7182 MDIO_PMA_REG_GEN_CTRL_ROM_RESET_INTERNAL_MP);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007183
Yaniv Rosner5c99274b2011-01-18 04:33:36 +00007184 /* Delay 100ms per the PHY specifications */
7185 msleep(100);
7186
7187 /* 8073 sometimes taking longer to download */
7188 do {
7189 count++;
7190 if (count > 300) {
7191 DP(NETIF_MSG_LINK,
7192 "bnx2x_8073_8727_external_rom_boot port %x:"
7193 "Download failed. fw version = 0x%x\n",
7194 port, fw_ver1);
7195 rc = -EINVAL;
7196 break;
7197 }
7198
7199 bnx2x_cl45_read(bp, phy,
7200 MDIO_PMA_DEVAD,
7201 MDIO_PMA_REG_ROM_VER1, &fw_ver1);
7202 bnx2x_cl45_read(bp, phy,
7203 MDIO_PMA_DEVAD,
7204 MDIO_PMA_REG_M8051_MSGOUT_REG, &fw_msgout);
7205
Yuval Mintzd2310232012-06-20 19:05:19 +00007206 usleep_range(1000, 2000);
Yaniv Rosner5c99274b2011-01-18 04:33:36 +00007207 } while (fw_ver1 == 0 || fw_ver1 == 0x4321 ||
7208 ((fw_msgout & 0xff) != 0x03 && (phy->type ==
7209 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073)));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007210
7211 /* Clear ser_boot_ctl bit */
7212 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007213 MDIO_PMA_DEVAD,
7214 MDIO_PMA_REG_MISC_CTRL1, 0x0000);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007215 bnx2x_save_bcm_spirom_ver(bp, phy, port);
Yaniv Rosner5c99274b2011-01-18 04:33:36 +00007216
7217 DP(NETIF_MSG_LINK,
7218 "bnx2x_8073_8727_external_rom_boot port %x:"
7219 "Download complete. fw version = 0x%x\n",
7220 port, fw_ver1);
7221
7222 return rc;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007223}
7224
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007225/******************************************************************/
7226/* BCM8073 PHY SECTION */
7227/******************************************************************/
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00007228static int bnx2x_8073_is_snr_needed(struct bnx2x *bp, struct bnx2x_phy *phy)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007229{
7230 /* This is only required for 8073A1, version 102 only */
7231 u16 val;
7232
7233 /* Read 8073 HW revision*/
7234 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007235 MDIO_PMA_DEVAD,
7236 MDIO_PMA_REG_8073_CHIP_REV, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007237
7238 if (val != 1) {
7239 /* No need to workaround in 8073 A1 */
7240 return 0;
7241 }
7242
7243 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007244 MDIO_PMA_DEVAD,
7245 MDIO_PMA_REG_ROM_VER2, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007246
7247 /* SNR should be applied only for version 0x102 */
7248 if (val != 0x102)
7249 return 0;
7250
7251 return 1;
7252}
7253
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00007254static int bnx2x_8073_xaui_wa(struct bnx2x *bp, struct bnx2x_phy *phy)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007255{
7256 u16 val, cnt, cnt1 ;
7257
7258 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007259 MDIO_PMA_DEVAD,
7260 MDIO_PMA_REG_8073_CHIP_REV, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007261
7262 if (val > 0) {
7263 /* No need to workaround in 8073 A1 */
7264 return 0;
7265 }
7266 /* XAUI workaround in 8073 A0: */
7267
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00007268 /* After loading the boot ROM and restarting Autoneg, poll
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007269 * Dev1, Reg $C820:
7270 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007271
7272 for (cnt = 0; cnt < 1000; cnt++) {
7273 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007274 MDIO_PMA_DEVAD,
7275 MDIO_PMA_REG_8073_SPEED_LINK_STATUS,
7276 &val);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00007277 /* If bit [14] = 0 or bit [13] = 0, continue on with
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007278 * system initialization (XAUI work-around not required, as
7279 * these bits indicate 2.5G or 1G link up).
7280 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007281 if (!(val & (1<<14)) || !(val & (1<<13))) {
7282 DP(NETIF_MSG_LINK, "XAUI work-around not required\n");
7283 return 0;
7284 } else if (!(val & (1<<15))) {
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007285 DP(NETIF_MSG_LINK, "bit 15 went off\n");
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00007286 /* If bit 15 is 0, then poll Dev1, Reg $C841 until it's
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007287 * MSB (bit15) goes to 1 (indicating that the XAUI
7288 * workaround has completed), then continue on with
7289 * system initialization.
7290 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007291 for (cnt1 = 0; cnt1 < 1000; cnt1++) {
7292 bnx2x_cl45_read(bp, phy,
7293 MDIO_PMA_DEVAD,
7294 MDIO_PMA_REG_8073_XAUI_WA, &val);
7295 if (val & (1<<15)) {
7296 DP(NETIF_MSG_LINK,
7297 "XAUI workaround has completed\n");
7298 return 0;
7299 }
Yuval Mintzd2310232012-06-20 19:05:19 +00007300 usleep_range(3000, 6000);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007301 }
7302 break;
7303 }
Yuval Mintzd2310232012-06-20 19:05:19 +00007304 usleep_range(3000, 6000);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007305 }
7306 DP(NETIF_MSG_LINK, "Warning: XAUI work-around timeout !!!\n");
7307 return -EINVAL;
7308}
7309
7310static void bnx2x_807x_force_10G(struct bnx2x *bp, struct bnx2x_phy *phy)
7311{
7312 /* Force KR or KX */
7313 bnx2x_cl45_write(bp, phy,
7314 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x2040);
7315 bnx2x_cl45_write(bp, phy,
7316 MDIO_PMA_DEVAD, MDIO_PMA_REG_10G_CTRL2, 0x000b);
7317 bnx2x_cl45_write(bp, phy,
7318 MDIO_PMA_DEVAD, MDIO_PMA_REG_BCM_CTRL, 0x0000);
7319 bnx2x_cl45_write(bp, phy,
7320 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x0000);
7321}
7322
7323static void bnx2x_8073_set_pause_cl37(struct link_params *params,
7324 struct bnx2x_phy *phy,
7325 struct link_vars *vars)
7326{
7327 u16 cl37_val;
7328 struct bnx2x *bp = params->bp;
7329 bnx2x_cl45_read(bp, phy,
7330 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LD, &cl37_val);
7331
7332 cl37_val &= ~MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH;
7333 /* Please refer to Table 28B-3 of 802.3ab-1999 spec. */
7334 bnx2x_calc_ieee_aneg_adv(phy, params, &vars->ieee_fc);
7335 if ((vars->ieee_fc &
7336 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_SYMMETRIC) ==
7337 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_SYMMETRIC) {
7338 cl37_val |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_SYMMETRIC;
7339 }
7340 if ((vars->ieee_fc &
7341 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC) ==
7342 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC) {
7343 cl37_val |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC;
7344 }
7345 if ((vars->ieee_fc &
7346 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) ==
7347 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) {
7348 cl37_val |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH;
7349 }
7350 DP(NETIF_MSG_LINK,
7351 "Ext phy AN advertize cl37 0x%x\n", cl37_val);
7352
7353 bnx2x_cl45_write(bp, phy,
7354 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LD, cl37_val);
7355 msleep(500);
7356}
7357
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00007358static int bnx2x_8073_config_init(struct bnx2x_phy *phy,
7359 struct link_params *params,
7360 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007361{
7362 struct bnx2x *bp = params->bp;
7363 u16 val = 0, tmp1;
7364 u8 gpio_port;
7365 DP(NETIF_MSG_LINK, "Init 8073\n");
7366
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007367 if (CHIP_IS_E2(bp))
7368 gpio_port = BP_PATH(bp);
7369 else
7370 gpio_port = params->port;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007371 /* Restore normal power mode*/
7372 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007373 MISC_REGISTERS_GPIO_OUTPUT_HIGH, gpio_port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007374
7375 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007376 MISC_REGISTERS_GPIO_OUTPUT_HIGH, gpio_port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007377
Yuval Mintzd2310232012-06-20 19:05:19 +00007378 /* Enable LASI */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007379 bnx2x_cl45_write(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00007380 MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXCTRL, (1<<2));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007381 bnx2x_cl45_write(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00007382 MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL, 0x0004);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007383
7384 bnx2x_8073_set_pause_cl37(params, phy, vars);
7385
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007386 bnx2x_cl45_read(bp, phy,
7387 MDIO_PMA_DEVAD, MDIO_PMA_REG_M8051_MSGOUT_REG, &tmp1);
7388
7389 bnx2x_cl45_read(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00007390 MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXSTAT, &tmp1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007391
7392 DP(NETIF_MSG_LINK, "Before rom RX_ALARM(port1): 0x%x\n", tmp1);
7393
Yaniv Rosner74d7a112011-01-18 04:33:18 +00007394 /* Swap polarity if required - Must be done only in non-1G mode */
7395 if (params->lane_config & PORT_HW_CFG_SWAP_PHY_POLARITY_ENABLED) {
7396 /* Configure the 8073 to swap _P and _N of the KR lines */
7397 DP(NETIF_MSG_LINK, "Swapping polarity for the 8073\n");
7398 /* 10G Rx/Tx and 1G Tx signal polarity swap */
7399 bnx2x_cl45_read(bp, phy,
7400 MDIO_PMA_DEVAD,
7401 MDIO_PMA_REG_8073_OPT_DIGITAL_CTRL, &val);
7402 bnx2x_cl45_write(bp, phy,
7403 MDIO_PMA_DEVAD,
7404 MDIO_PMA_REG_8073_OPT_DIGITAL_CTRL,
7405 (val | (3<<9)));
7406 }
7407
7408
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007409 /* Enable CL37 BAM */
Yaniv Rosner121839b2010-11-01 05:32:38 +00007410 if (REG_RD(bp, params->shmem_base +
7411 offsetof(struct shmem_region, dev_info.
7412 port_hw_config[params->port].default_cfg)) &
7413 PORT_HW_CFG_ENABLE_BAM_ON_KR_ENABLED) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007414
Yaniv Rosner121839b2010-11-01 05:32:38 +00007415 bnx2x_cl45_read(bp, phy,
7416 MDIO_AN_DEVAD,
7417 MDIO_AN_REG_8073_BAM, &val);
7418 bnx2x_cl45_write(bp, phy,
7419 MDIO_AN_DEVAD,
7420 MDIO_AN_REG_8073_BAM, val | 1);
7421 DP(NETIF_MSG_LINK, "Enable CL37 BAM on KR\n");
7422 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007423 if (params->loopback_mode == LOOPBACK_EXT) {
7424 bnx2x_807x_force_10G(bp, phy);
7425 DP(NETIF_MSG_LINK, "Forced speed 10G on 807X\n");
7426 return 0;
7427 } else {
7428 bnx2x_cl45_write(bp, phy,
7429 MDIO_PMA_DEVAD, MDIO_PMA_REG_BCM_CTRL, 0x0002);
7430 }
7431 if (phy->req_line_speed != SPEED_AUTO_NEG) {
7432 if (phy->req_line_speed == SPEED_10000) {
7433 val = (1<<7);
7434 } else if (phy->req_line_speed == SPEED_2500) {
7435 val = (1<<5);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00007436 /* Note that 2.5G works only when used with 1G
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007437 * advertisement
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007438 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007439 } else
7440 val = (1<<5);
7441 } else {
7442 val = 0;
7443 if (phy->speed_cap_mask &
7444 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
7445 val |= (1<<7);
7446
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007447 /* Note that 2.5G works only when used with 1G advertisement */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007448 if (phy->speed_cap_mask &
7449 (PORT_HW_CFG_SPEED_CAPABILITY_D0_1G |
7450 PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
7451 val |= (1<<5);
7452 DP(NETIF_MSG_LINK, "807x autoneg val = 0x%x\n", val);
7453 }
7454
7455 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV, val);
7456 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_8073_2_5G, &tmp1);
7457
7458 if (((phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G) &&
7459 (phy->req_line_speed == SPEED_AUTO_NEG)) ||
7460 (phy->req_line_speed == SPEED_2500)) {
7461 u16 phy_ver;
7462 /* Allow 2.5G for A1 and above */
7463 bnx2x_cl45_read(bp, phy,
7464 MDIO_PMA_DEVAD, MDIO_PMA_REG_8073_CHIP_REV,
7465 &phy_ver);
7466 DP(NETIF_MSG_LINK, "Add 2.5G\n");
7467 if (phy_ver > 0)
7468 tmp1 |= 1;
7469 else
7470 tmp1 &= 0xfffe;
7471 } else {
7472 DP(NETIF_MSG_LINK, "Disable 2.5G\n");
7473 tmp1 &= 0xfffe;
7474 }
7475
7476 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_8073_2_5G, tmp1);
7477 /* Add support for CL37 (passive mode) II */
7478
7479 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LD, &tmp1);
7480 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LD,
7481 (tmp1 | ((phy->req_duplex == DUPLEX_FULL) ?
7482 0x20 : 0x40)));
7483
7484 /* Add support for CL37 (passive mode) III */
7485 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CL37_AN, 0x1000);
7486
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00007487 /* The SNR will improve about 2db by changing BW and FEE main
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007488 * tap. Rest commands are executed after link is up
7489 * Change FFE main cursor to 5 in EDC register
7490 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007491 if (bnx2x_8073_is_snr_needed(bp, phy))
7492 bnx2x_cl45_write(bp, phy,
7493 MDIO_PMA_DEVAD, MDIO_PMA_REG_EDC_FFE_MAIN,
7494 0xFB0C);
7495
7496 /* Enable FEC (Forware Error Correction) Request in the AN */
7497 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV2, &tmp1);
7498 tmp1 |= (1<<15);
7499 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV2, tmp1);
7500
7501 bnx2x_ext_phy_set_pause(params, phy, vars);
7502
7503 /* Restart autoneg */
7504 msleep(500);
7505 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x1200);
7506 DP(NETIF_MSG_LINK, "807x Autoneg Restart: Advertise 1G=%x, 10G=%x\n",
7507 ((val & (1<<5)) > 0), ((val & (1<<7)) > 0));
7508 return 0;
7509}
7510
7511static u8 bnx2x_8073_read_status(struct bnx2x_phy *phy,
7512 struct link_params *params,
7513 struct link_vars *vars)
7514{
7515 struct bnx2x *bp = params->bp;
7516 u8 link_up = 0;
7517 u16 val1, val2;
7518 u16 link_status = 0;
7519 u16 an1000_status = 0;
7520
7521 bnx2x_cl45_read(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00007522 MDIO_PMA_DEVAD, MDIO_PMA_LASI_STAT, &val1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007523
7524 DP(NETIF_MSG_LINK, "8703 LASI status 0x%x\n", val1);
7525
Yuval Mintzd2310232012-06-20 19:05:19 +00007526 /* Clear the interrupt LASI status register */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007527 bnx2x_cl45_read(bp, phy,
7528 MDIO_PCS_DEVAD, MDIO_PCS_REG_STATUS, &val2);
7529 bnx2x_cl45_read(bp, phy,
7530 MDIO_PCS_DEVAD, MDIO_PCS_REG_STATUS, &val1);
7531 DP(NETIF_MSG_LINK, "807x PCS status 0x%x->0x%x\n", val2, val1);
7532 /* Clear MSG-OUT */
7533 bnx2x_cl45_read(bp, phy,
7534 MDIO_PMA_DEVAD, MDIO_PMA_REG_M8051_MSGOUT_REG, &val1);
7535
7536 /* Check the LASI */
7537 bnx2x_cl45_read(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00007538 MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXSTAT, &val2);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007539
7540 DP(NETIF_MSG_LINK, "KR 0x9003 0x%x\n", val2);
7541
7542 /* Check the link status */
7543 bnx2x_cl45_read(bp, phy,
7544 MDIO_PCS_DEVAD, MDIO_PCS_REG_STATUS, &val2);
7545 DP(NETIF_MSG_LINK, "KR PCS status 0x%x\n", val2);
7546
7547 bnx2x_cl45_read(bp, phy,
7548 MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val2);
7549 bnx2x_cl45_read(bp, phy,
7550 MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val1);
7551 link_up = ((val1 & 4) == 4);
7552 DP(NETIF_MSG_LINK, "PMA_REG_STATUS=0x%x\n", val1);
7553
7554 if (link_up &&
7555 ((phy->req_line_speed != SPEED_10000))) {
7556 if (bnx2x_8073_xaui_wa(bp, phy) != 0)
7557 return 0;
7558 }
7559 bnx2x_cl45_read(bp, phy,
7560 MDIO_AN_DEVAD, MDIO_AN_REG_LINK_STATUS, &an1000_status);
7561 bnx2x_cl45_read(bp, phy,
7562 MDIO_AN_DEVAD, MDIO_AN_REG_LINK_STATUS, &an1000_status);
7563
7564 /* Check the link status on 1.1.2 */
7565 bnx2x_cl45_read(bp, phy,
7566 MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val2);
7567 bnx2x_cl45_read(bp, phy,
7568 MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val1);
7569 DP(NETIF_MSG_LINK, "KR PMA status 0x%x->0x%x,"
7570 "an_link_status=0x%x\n", val2, val1, an1000_status);
7571
7572 link_up = (((val1 & 4) == 4) || (an1000_status & (1<<1)));
7573 if (link_up && bnx2x_8073_is_snr_needed(bp, phy)) {
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00007574 /* The SNR will improve about 2dbby changing the BW and FEE main
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007575 * tap. The 1st write to change FFE main tap is set before
7576 * restart AN. Change PLL Bandwidth in EDC register
7577 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007578 bnx2x_cl45_write(bp, phy,
7579 MDIO_PMA_DEVAD, MDIO_PMA_REG_PLL_BANDWIDTH,
7580 0x26BC);
7581
7582 /* Change CDR Bandwidth in EDC register */
7583 bnx2x_cl45_write(bp, phy,
7584 MDIO_PMA_DEVAD, MDIO_PMA_REG_CDR_BANDWIDTH,
7585 0x0333);
7586 }
7587 bnx2x_cl45_read(bp, phy,
7588 MDIO_PMA_DEVAD, MDIO_PMA_REG_8073_SPEED_LINK_STATUS,
7589 &link_status);
7590
7591 /* Bits 0..2 --> speed detected, bits 13..15--> link is down */
7592 if ((link_status & (1<<2)) && (!(link_status & (1<<15)))) {
7593 link_up = 1;
7594 vars->line_speed = SPEED_10000;
7595 DP(NETIF_MSG_LINK, "port %x: External link up in 10G\n",
7596 params->port);
7597 } else if ((link_status & (1<<1)) && (!(link_status & (1<<14)))) {
7598 link_up = 1;
7599 vars->line_speed = SPEED_2500;
7600 DP(NETIF_MSG_LINK, "port %x: External link up in 2.5G\n",
7601 params->port);
7602 } else if ((link_status & (1<<0)) && (!(link_status & (1<<13)))) {
7603 link_up = 1;
7604 vars->line_speed = SPEED_1000;
7605 DP(NETIF_MSG_LINK, "port %x: External link up in 1G\n",
7606 params->port);
7607 } else {
7608 link_up = 0;
7609 DP(NETIF_MSG_LINK, "port %x: External link is down\n",
7610 params->port);
7611 }
7612
7613 if (link_up) {
Yaniv Rosner74d7a112011-01-18 04:33:18 +00007614 /* Swap polarity if required */
7615 if (params->lane_config &
7616 PORT_HW_CFG_SWAP_PHY_POLARITY_ENABLED) {
7617 /* Configure the 8073 to swap P and N of the KR lines */
7618 bnx2x_cl45_read(bp, phy,
7619 MDIO_XS_DEVAD,
7620 MDIO_XS_REG_8073_RX_CTRL_PCIE, &val1);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00007621 /* Set bit 3 to invert Rx in 1G mode and clear this bit
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007622 * when it`s in 10G mode.
7623 */
Yaniv Rosner74d7a112011-01-18 04:33:18 +00007624 if (vars->line_speed == SPEED_1000) {
7625 DP(NETIF_MSG_LINK, "Swapping 1G polarity for"
7626 "the 8073\n");
7627 val1 |= (1<<3);
7628 } else
7629 val1 &= ~(1<<3);
7630
7631 bnx2x_cl45_write(bp, phy,
7632 MDIO_XS_DEVAD,
7633 MDIO_XS_REG_8073_RX_CTRL_PCIE,
7634 val1);
7635 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007636 bnx2x_ext_phy_10G_an_resolve(bp, phy, vars);
7637 bnx2x_8073_resolve_fc(phy, params, vars);
Yaniv Rosner791f18c2011-01-18 04:33:42 +00007638 vars->duplex = DUPLEX_FULL;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007639 }
Mintz Yuval9e7e8392012-02-15 02:10:24 +00007640
7641 if (vars->link_status & LINK_STATUS_AUTO_NEGOTIATE_COMPLETE) {
7642 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
7643 MDIO_AN_REG_LP_AUTO_NEG2, &val1);
7644
7645 if (val1 & (1<<5))
7646 vars->link_status |=
7647 LINK_STATUS_LINK_PARTNER_1000TFD_CAPABLE;
7648 if (val1 & (1<<7))
7649 vars->link_status |=
7650 LINK_STATUS_LINK_PARTNER_10GXFD_CAPABLE;
7651 }
7652
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007653 return link_up;
7654}
7655
7656static void bnx2x_8073_link_reset(struct bnx2x_phy *phy,
7657 struct link_params *params)
7658{
7659 struct bnx2x *bp = params->bp;
7660 u8 gpio_port;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007661 if (CHIP_IS_E2(bp))
7662 gpio_port = BP_PATH(bp);
7663 else
7664 gpio_port = params->port;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007665 DP(NETIF_MSG_LINK, "Setting 8073 port %d into low power mode\n",
7666 gpio_port);
7667 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007668 MISC_REGISTERS_GPIO_OUTPUT_LOW,
7669 gpio_port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007670}
7671
7672/******************************************************************/
7673/* BCM8705 PHY SECTION */
7674/******************************************************************/
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00007675static int bnx2x_8705_config_init(struct bnx2x_phy *phy,
7676 struct link_params *params,
7677 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007678{
7679 struct bnx2x *bp = params->bp;
7680 DP(NETIF_MSG_LINK, "init 8705\n");
7681 /* Restore normal power mode*/
7682 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007683 MISC_REGISTERS_GPIO_OUTPUT_HIGH, params->port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007684 /* HW reset */
7685 bnx2x_ext_phy_hw_reset(bp, params->port);
7686 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0xa040);
Yaniv Rosner6d870c32011-01-31 04:22:20 +00007687 bnx2x_wait_reset_complete(bp, phy, params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007688
7689 bnx2x_cl45_write(bp, phy,
7690 MDIO_PMA_DEVAD, MDIO_PMA_REG_MISC_CTRL, 0x8288);
7691 bnx2x_cl45_write(bp, phy,
7692 MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER, 0x7fbf);
7693 bnx2x_cl45_write(bp, phy,
7694 MDIO_PMA_DEVAD, MDIO_PMA_REG_CMU_PLL_BYPASS, 0x0100);
7695 bnx2x_cl45_write(bp, phy,
7696 MDIO_WIS_DEVAD, MDIO_WIS_REG_LASI_CNTL, 0x1);
7697 /* BCM8705 doesn't have microcode, hence the 0 */
7698 bnx2x_save_spirom_version(bp, params->port, params->shmem_base, 0);
7699 return 0;
7700}
7701
7702static u8 bnx2x_8705_read_status(struct bnx2x_phy *phy,
7703 struct link_params *params,
7704 struct link_vars *vars)
7705{
7706 u8 link_up = 0;
7707 u16 val1, rx_sd;
7708 struct bnx2x *bp = params->bp;
7709 DP(NETIF_MSG_LINK, "read status 8705\n");
7710 bnx2x_cl45_read(bp, phy,
7711 MDIO_WIS_DEVAD, MDIO_WIS_REG_LASI_STATUS, &val1);
7712 DP(NETIF_MSG_LINK, "8705 LASI status 0x%x\n", val1);
7713
7714 bnx2x_cl45_read(bp, phy,
7715 MDIO_WIS_DEVAD, MDIO_WIS_REG_LASI_STATUS, &val1);
7716 DP(NETIF_MSG_LINK, "8705 LASI status 0x%x\n", val1);
7717
7718 bnx2x_cl45_read(bp, phy,
7719 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_SD, &rx_sd);
7720
7721 bnx2x_cl45_read(bp, phy,
7722 MDIO_PMA_DEVAD, 0xc809, &val1);
7723 bnx2x_cl45_read(bp, phy,
7724 MDIO_PMA_DEVAD, 0xc809, &val1);
7725
7726 DP(NETIF_MSG_LINK, "8705 1.c809 val=0x%x\n", val1);
7727 link_up = ((rx_sd & 0x1) && (val1 & (1<<9)) && ((val1 & (1<<8)) == 0));
7728 if (link_up) {
7729 vars->line_speed = SPEED_10000;
7730 bnx2x_ext_phy_resolve_fc(phy, params, vars);
7731 }
7732 return link_up;
7733}
7734
7735/******************************************************************/
7736/* SFP+ module Section */
7737/******************************************************************/
Yaniv Rosner85242ee2011-07-05 01:06:53 +00007738static void bnx2x_set_disable_pmd_transmit(struct link_params *params,
7739 struct bnx2x_phy *phy,
7740 u8 pmd_dis)
7741{
7742 struct bnx2x *bp = params->bp;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00007743 /* Disable transmitter only for bootcodes which can enable it afterwards
Yaniv Rosner85242ee2011-07-05 01:06:53 +00007744 * (for D3 link)
7745 */
7746 if (pmd_dis) {
7747 if (params->feature_config_flags &
7748 FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED)
7749 DP(NETIF_MSG_LINK, "Disabling PMD transmitter\n");
7750 else {
7751 DP(NETIF_MSG_LINK, "NOT disabling PMD transmitter\n");
7752 return;
7753 }
7754 } else
7755 DP(NETIF_MSG_LINK, "Enabling PMD transmitter\n");
7756 bnx2x_cl45_write(bp, phy,
7757 MDIO_PMA_DEVAD,
7758 MDIO_PMA_REG_TX_DISABLE, pmd_dis);
7759}
7760
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00007761static u8 bnx2x_get_gpio_port(struct link_params *params)
7762{
7763 u8 gpio_port;
7764 u32 swap_val, swap_override;
7765 struct bnx2x *bp = params->bp;
7766 if (CHIP_IS_E2(bp))
7767 gpio_port = BP_PATH(bp);
7768 else
7769 gpio_port = params->port;
7770 swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
7771 swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
7772 return gpio_port ^ (swap_val && swap_override);
7773}
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00007774
7775static void bnx2x_sfp_e1e2_set_transmitter(struct link_params *params,
7776 struct bnx2x_phy *phy,
7777 u8 tx_en)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007778{
7779 u16 val;
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00007780 u8 port = params->port;
7781 struct bnx2x *bp = params->bp;
7782 u32 tx_en_mode;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007783
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007784 /* Disable/Enable transmitter ( TX laser of the SFP+ module.)*/
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00007785 tx_en_mode = REG_RD(bp, params->shmem_base +
7786 offsetof(struct shmem_region,
7787 dev_info.port_hw_config[port].sfp_ctrl)) &
7788 PORT_HW_CFG_TX_LASER_MASK;
7789 DP(NETIF_MSG_LINK, "Setting transmitter tx_en=%x for port %x "
7790 "mode = %x\n", tx_en, port, tx_en_mode);
7791 switch (tx_en_mode) {
7792 case PORT_HW_CFG_TX_LASER_MDIO:
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007793
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00007794 bnx2x_cl45_read(bp, phy,
7795 MDIO_PMA_DEVAD,
7796 MDIO_PMA_REG_PHY_IDENTIFIER,
7797 &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007798
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00007799 if (tx_en)
7800 val &= ~(1<<15);
7801 else
7802 val |= (1<<15);
7803
7804 bnx2x_cl45_write(bp, phy,
7805 MDIO_PMA_DEVAD,
7806 MDIO_PMA_REG_PHY_IDENTIFIER,
7807 val);
7808 break;
7809 case PORT_HW_CFG_TX_LASER_GPIO0:
7810 case PORT_HW_CFG_TX_LASER_GPIO1:
7811 case PORT_HW_CFG_TX_LASER_GPIO2:
7812 case PORT_HW_CFG_TX_LASER_GPIO3:
7813 {
7814 u16 gpio_pin;
7815 u8 gpio_port, gpio_mode;
7816 if (tx_en)
7817 gpio_mode = MISC_REGISTERS_GPIO_OUTPUT_HIGH;
7818 else
7819 gpio_mode = MISC_REGISTERS_GPIO_OUTPUT_LOW;
7820
7821 gpio_pin = tx_en_mode - PORT_HW_CFG_TX_LASER_GPIO0;
7822 gpio_port = bnx2x_get_gpio_port(params);
7823 bnx2x_set_gpio(bp, gpio_pin, gpio_mode, gpio_port);
7824 break;
7825 }
7826 default:
7827 DP(NETIF_MSG_LINK, "Invalid TX_LASER_MDIO 0x%x\n", tx_en_mode);
7828 break;
7829 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007830}
7831
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00007832static void bnx2x_sfp_set_transmitter(struct link_params *params,
7833 struct bnx2x_phy *phy,
7834 u8 tx_en)
7835{
7836 struct bnx2x *bp = params->bp;
7837 DP(NETIF_MSG_LINK, "Setting SFP+ transmitter to %d\n", tx_en);
7838 if (CHIP_IS_E3(bp))
7839 bnx2x_sfp_e3_set_transmitter(params, phy, tx_en);
7840 else
7841 bnx2x_sfp_e1e2_set_transmitter(params, phy, tx_en);
7842}
7843
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00007844static int bnx2x_8726_read_sfp_module_eeprom(struct bnx2x_phy *phy,
7845 struct link_params *params,
7846 u16 addr, u8 byte_cnt, u8 *o_buf)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007847{
7848 struct bnx2x *bp = params->bp;
7849 u16 val = 0;
7850 u16 i;
Yuval Mintz24ea8182012-06-20 19:05:23 +00007851 if (byte_cnt > SFP_EEPROM_PAGE_SIZE) {
Joe Perches94f05b02011-08-14 12:16:20 +00007852 DP(NETIF_MSG_LINK,
7853 "Reading from eeprom is limited to 0xf\n");
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007854 return -EINVAL;
7855 }
7856 /* Set the read command byte count */
7857 bnx2x_cl45_write(bp, phy,
7858 MDIO_PMA_DEVAD, MDIO_PMA_REG_SFP_TWO_WIRE_BYTE_CNT,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007859 (byte_cnt | 0xa000));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007860
7861 /* Set the read command address */
7862 bnx2x_cl45_write(bp, phy,
7863 MDIO_PMA_DEVAD, MDIO_PMA_REG_SFP_TWO_WIRE_MEM_ADDR,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007864 addr);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007865
7866 /* Activate read command */
7867 bnx2x_cl45_write(bp, phy,
7868 MDIO_PMA_DEVAD, MDIO_PMA_REG_SFP_TWO_WIRE_CTRL,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007869 0x2c0f);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007870
7871 /* Wait up to 500us for command complete status */
7872 for (i = 0; i < 100; i++) {
7873 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007874 MDIO_PMA_DEVAD,
7875 MDIO_PMA_REG_SFP_TWO_WIRE_CTRL, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007876 if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) ==
7877 MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_COMPLETE)
7878 break;
7879 udelay(5);
7880 }
7881
7882 if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) !=
7883 MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_COMPLETE) {
7884 DP(NETIF_MSG_LINK,
7885 "Got bad status 0x%x when reading from SFP+ EEPROM\n",
7886 (val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK));
7887 return -EINVAL;
7888 }
7889
7890 /* Read the buffer */
7891 for (i = 0; i < byte_cnt; i++) {
7892 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007893 MDIO_PMA_DEVAD,
7894 MDIO_PMA_REG_8726_TWO_WIRE_DATA_BUF + i, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007895 o_buf[i] = (u8)(val & MDIO_PMA_REG_8726_TWO_WIRE_DATA_MASK);
7896 }
7897
7898 for (i = 0; i < 100; i++) {
7899 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007900 MDIO_PMA_DEVAD,
7901 MDIO_PMA_REG_SFP_TWO_WIRE_CTRL, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007902 if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) ==
7903 MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_IDLE)
Joe Perches6f38ad92010-11-14 17:04:31 +00007904 return 0;
Yuval Mintzd2310232012-06-20 19:05:19 +00007905 usleep_range(1000, 2000);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007906 }
7907 return -EINVAL;
7908}
7909
Yuval Mintz50a29842012-06-16 20:27:14 +00007910static void bnx2x_warpcore_power_module(struct link_params *params,
7911 struct bnx2x_phy *phy,
7912 u8 power)
7913{
7914 u32 pin_cfg;
7915 struct bnx2x *bp = params->bp;
7916
7917 pin_cfg = (REG_RD(bp, params->shmem_base +
7918 offsetof(struct shmem_region,
7919 dev_info.port_hw_config[params->port].e3_sfp_ctrl)) &
7920 PORT_HW_CFG_E3_PWR_DIS_MASK) >>
7921 PORT_HW_CFG_E3_PWR_DIS_SHIFT;
7922
7923 if (pin_cfg == PIN_CFG_NA)
7924 return;
7925 DP(NETIF_MSG_LINK, "Setting SFP+ module power to %d using pin cfg %d\n",
7926 power, pin_cfg);
7927 /* Low ==> corresponding SFP+ module is powered
7928 * high ==> the SFP+ module is powered down
7929 */
7930 bnx2x_set_cfg_pin(bp, pin_cfg, power ^ 1);
7931}
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00007932static int bnx2x_warpcore_read_sfp_module_eeprom(struct bnx2x_phy *phy,
7933 struct link_params *params,
7934 u16 addr, u8 byte_cnt,
7935 u8 *o_buf)
7936{
7937 int rc = 0;
7938 u8 i, j = 0, cnt = 0;
7939 u32 data_array[4];
7940 u16 addr32;
7941 struct bnx2x *bp = params->bp;
Yuval Mintz24ea8182012-06-20 19:05:23 +00007942
7943 if (byte_cnt > SFP_EEPROM_PAGE_SIZE) {
Joe Perches94f05b02011-08-14 12:16:20 +00007944 DP(NETIF_MSG_LINK,
7945 "Reading from eeprom is limited to 16 bytes\n");
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00007946 return -EINVAL;
7947 }
7948
7949 /* 4 byte aligned address */
7950 addr32 = addr & (~0x3);
7951 do {
Yuval Mintz50a29842012-06-16 20:27:14 +00007952 if (cnt == I2C_WA_PWR_ITER) {
7953 bnx2x_warpcore_power_module(params, phy, 0);
7954 /* Note that 100us are not enough here */
7955 usleep_range(1000,1000);
7956 bnx2x_warpcore_power_module(params, phy, 1);
7957 }
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00007958 rc = bnx2x_bsc_read(params, phy, 0xa0, addr32, 0, byte_cnt,
7959 data_array);
7960 } while ((rc != 0) && (++cnt < I2C_WA_RETRY_CNT));
7961
7962 if (rc == 0) {
7963 for (i = (addr - addr32); i < byte_cnt + (addr - addr32); i++) {
7964 o_buf[j] = *((u8 *)data_array + i);
7965 j++;
7966 }
7967 }
7968
7969 return rc;
7970}
7971
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00007972static int bnx2x_8727_read_sfp_module_eeprom(struct bnx2x_phy *phy,
7973 struct link_params *params,
7974 u16 addr, u8 byte_cnt, u8 *o_buf)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007975{
7976 struct bnx2x *bp = params->bp;
7977 u16 val, i;
7978
Yuval Mintz24ea8182012-06-20 19:05:23 +00007979 if (byte_cnt > SFP_EEPROM_PAGE_SIZE) {
Joe Perches94f05b02011-08-14 12:16:20 +00007980 DP(NETIF_MSG_LINK,
7981 "Reading from eeprom is limited to 0xf\n");
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007982 return -EINVAL;
7983 }
7984
7985 /* Need to read from 1.8000 to clear it */
7986 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007987 MDIO_PMA_DEVAD,
7988 MDIO_PMA_REG_SFP_TWO_WIRE_CTRL,
7989 &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007990
7991 /* Set the read command byte count */
7992 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007993 MDIO_PMA_DEVAD,
7994 MDIO_PMA_REG_SFP_TWO_WIRE_BYTE_CNT,
7995 ((byte_cnt < 2) ? 2 : byte_cnt));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007996
7997 /* Set the read command address */
7998 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007999 MDIO_PMA_DEVAD,
8000 MDIO_PMA_REG_SFP_TWO_WIRE_MEM_ADDR,
8001 addr);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008002 /* Set the destination address */
8003 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008004 MDIO_PMA_DEVAD,
8005 0x8004,
8006 MDIO_PMA_REG_8727_TWO_WIRE_DATA_BUF);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008007
8008 /* Activate read command */
8009 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008010 MDIO_PMA_DEVAD,
8011 MDIO_PMA_REG_SFP_TWO_WIRE_CTRL,
8012 0x8002);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00008013 /* Wait appropriate time for two-wire command to finish before
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008014 * polling the status register
8015 */
Yuval Mintzd2310232012-06-20 19:05:19 +00008016 usleep_range(1000, 2000);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008017
8018 /* Wait up to 500us for command complete status */
8019 for (i = 0; i < 100; i++) {
8020 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008021 MDIO_PMA_DEVAD,
8022 MDIO_PMA_REG_SFP_TWO_WIRE_CTRL, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008023 if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) ==
8024 MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_COMPLETE)
8025 break;
8026 udelay(5);
8027 }
8028
8029 if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) !=
8030 MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_COMPLETE) {
8031 DP(NETIF_MSG_LINK,
8032 "Got bad status 0x%x when reading from SFP+ EEPROM\n",
8033 (val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK));
Yaniv Rosner65a001b2011-01-31 04:22:03 +00008034 return -EFAULT;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008035 }
8036
8037 /* Read the buffer */
8038 for (i = 0; i < byte_cnt; i++) {
8039 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008040 MDIO_PMA_DEVAD,
8041 MDIO_PMA_REG_8727_TWO_WIRE_DATA_BUF + i, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008042 o_buf[i] = (u8)(val & MDIO_PMA_REG_8727_TWO_WIRE_DATA_MASK);
8043 }
8044
8045 for (i = 0; i < 100; i++) {
8046 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008047 MDIO_PMA_DEVAD,
8048 MDIO_PMA_REG_SFP_TWO_WIRE_CTRL, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008049 if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) ==
8050 MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_IDLE)
Joe Perches6f38ad92010-11-14 17:04:31 +00008051 return 0;
Yuval Mintzd2310232012-06-20 19:05:19 +00008052 usleep_range(1000, 2000);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008053 }
8054
8055 return -EINVAL;
8056}
8057
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00008058int bnx2x_read_sfp_module_eeprom(struct bnx2x_phy *phy,
8059 struct link_params *params, u16 addr,
8060 u8 byte_cnt, u8 *o_buf)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008061{
Yuval Mintz24ea8182012-06-20 19:05:23 +00008062 int rc = -EOPNOTSUPP;
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00008063 switch (phy->type) {
8064 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
8065 rc = bnx2x_8726_read_sfp_module_eeprom(phy, params, addr,
8066 byte_cnt, o_buf);
8067 break;
8068 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
8069 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8722:
8070 rc = bnx2x_8727_read_sfp_module_eeprom(phy, params, addr,
8071 byte_cnt, o_buf);
8072 break;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008073 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT:
8074 rc = bnx2x_warpcore_read_sfp_module_eeprom(phy, params, addr,
8075 byte_cnt, o_buf);
8076 break;
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00008077 }
8078 return rc;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008079}
8080
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00008081static int bnx2x_get_edc_mode(struct bnx2x_phy *phy,
8082 struct link_params *params,
8083 u16 *edc_mode)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008084{
8085 struct bnx2x *bp = params->bp;
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00008086 u32 sync_offset = 0, phy_idx, media_types;
Yuval Mintzdbef8072012-06-20 19:05:22 +00008087 u8 val[2], check_limiting_mode = 0;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008088 *edc_mode = EDC_MODE_LIMITING;
8089
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00008090 phy->media_type = ETH_PHY_UNSPECIFIED;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008091 /* First check for copper cable */
8092 if (bnx2x_read_sfp_module_eeprom(phy,
8093 params,
8094 SFP_EEPROM_CON_TYPE_ADDR,
Yuval Mintzdbef8072012-06-20 19:05:22 +00008095 2,
8096 (u8 *)val) != 0) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008097 DP(NETIF_MSG_LINK, "Failed to read from SFP+ module EEPROM\n");
8098 return -EINVAL;
8099 }
8100
Yuval Mintzdbef8072012-06-20 19:05:22 +00008101 switch (val[0]) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008102 case SFP_EEPROM_CON_TYPE_VAL_COPPER:
8103 {
8104 u8 copper_module_type;
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00008105 phy->media_type = ETH_PHY_DA_TWINAX;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00008106 /* Check if its active cable (includes SFP+ module)
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008107 * of passive cable
8108 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008109 if (bnx2x_read_sfp_module_eeprom(phy,
8110 params,
8111 SFP_EEPROM_FC_TX_TECH_ADDR,
8112 1,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00008113 &copper_module_type) != 0) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008114 DP(NETIF_MSG_LINK,
8115 "Failed to read copper-cable-type"
8116 " from SFP+ EEPROM\n");
8117 return -EINVAL;
8118 }
8119
8120 if (copper_module_type &
8121 SFP_EEPROM_FC_TX_TECH_BITMASK_COPPER_ACTIVE) {
8122 DP(NETIF_MSG_LINK, "Active Copper cable detected\n");
8123 check_limiting_mode = 1;
8124 } else if (copper_module_type &
8125 SFP_EEPROM_FC_TX_TECH_BITMASK_COPPER_PASSIVE) {
Joe Perches94f05b02011-08-14 12:16:20 +00008126 DP(NETIF_MSG_LINK,
8127 "Passive Copper cable detected\n");
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008128 *edc_mode =
8129 EDC_MODE_PASSIVE_DAC;
8130 } else {
Joe Perches94f05b02011-08-14 12:16:20 +00008131 DP(NETIF_MSG_LINK,
8132 "Unknown copper-cable-type 0x%x !!!\n",
8133 copper_module_type);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008134 return -EINVAL;
8135 }
8136 break;
8137 }
8138 case SFP_EEPROM_CON_TYPE_VAL_LC:
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008139 check_limiting_mode = 1;
Yuval Mintzdbef8072012-06-20 19:05:22 +00008140 if ((val[1] & (SFP_EEPROM_COMP_CODE_SR_MASK |
8141 SFP_EEPROM_COMP_CODE_LR_MASK |
8142 SFP_EEPROM_COMP_CODE_LRM_MASK)) == 0) {
8143 DP(NETIF_MSG_LINK, "1G Optic module detected\n");
8144 phy->media_type = ETH_PHY_SFP_1G_FIBER;
8145 phy->req_line_speed = SPEED_1000;
8146 } else {
8147 int idx, cfg_idx = 0;
8148 DP(NETIF_MSG_LINK, "10G Optic module detected\n");
8149 for (idx = INT_PHY; idx < MAX_PHYS; idx++) {
8150 if (params->phy[idx].type == phy->type) {
8151 cfg_idx = LINK_CONFIG_IDX(idx);
8152 break;
8153 }
8154 }
8155 phy->media_type = ETH_PHY_SFPP_10G_FIBER;
8156 phy->req_line_speed = params->req_line_speed[cfg_idx];
8157 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008158 break;
8159 default:
8160 DP(NETIF_MSG_LINK, "Unable to determine module type 0x%x !!!\n",
Yuval Mintzdbef8072012-06-20 19:05:22 +00008161 val[0]);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008162 return -EINVAL;
8163 }
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00008164 sync_offset = params->shmem_base +
8165 offsetof(struct shmem_region,
8166 dev_info.port_hw_config[params->port].media_type);
8167 media_types = REG_RD(bp, sync_offset);
8168 /* Update media type for non-PMF sync */
8169 for (phy_idx = INT_PHY; phy_idx < MAX_PHYS; phy_idx++) {
8170 if (&(params->phy[phy_idx]) == phy) {
8171 media_types &= ~(PORT_HW_CFG_MEDIA_TYPE_PHY0_MASK <<
8172 (PORT_HW_CFG_MEDIA_TYPE_PHY1_SHIFT * phy_idx));
8173 media_types |= ((phy->media_type &
8174 PORT_HW_CFG_MEDIA_TYPE_PHY0_MASK) <<
8175 (PORT_HW_CFG_MEDIA_TYPE_PHY1_SHIFT * phy_idx));
8176 break;
8177 }
8178 }
8179 REG_WR(bp, sync_offset, media_types);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008180 if (check_limiting_mode) {
8181 u8 options[SFP_EEPROM_OPTIONS_SIZE];
8182 if (bnx2x_read_sfp_module_eeprom(phy,
8183 params,
8184 SFP_EEPROM_OPTIONS_ADDR,
8185 SFP_EEPROM_OPTIONS_SIZE,
8186 options) != 0) {
Joe Perches94f05b02011-08-14 12:16:20 +00008187 DP(NETIF_MSG_LINK,
8188 "Failed to read Option field from module EEPROM\n");
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008189 return -EINVAL;
8190 }
8191 if ((options[0] & SFP_EEPROM_OPTIONS_LINEAR_RX_OUT_MASK))
8192 *edc_mode = EDC_MODE_LINEAR;
8193 else
8194 *edc_mode = EDC_MODE_LIMITING;
8195 }
8196 DP(NETIF_MSG_LINK, "EDC mode is set to 0x%x\n", *edc_mode);
8197 return 0;
8198}
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00008199/* This function read the relevant field from the module (SFP+), and verify it
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008200 * is compliant with this board
8201 */
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00008202static int bnx2x_verify_sfp_module(struct bnx2x_phy *phy,
8203 struct link_params *params)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008204{
8205 struct bnx2x *bp = params->bp;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008206 u32 val, cmd;
8207 u32 fw_resp, fw_cmd_param;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008208 char vendor_name[SFP_EEPROM_VENDOR_NAME_SIZE+1];
8209 char vendor_pn[SFP_EEPROM_PART_NO_SIZE+1];
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008210 phy->flags &= ~FLAGS_SFP_NOT_APPROVED;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008211 val = REG_RD(bp, params->shmem_base +
8212 offsetof(struct shmem_region, dev_info.
8213 port_feature_config[params->port].config));
8214 if ((val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) ==
8215 PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_NO_ENFORCEMENT) {
8216 DP(NETIF_MSG_LINK, "NOT enforcing module verification\n");
8217 return 0;
8218 }
8219
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008220 if (params->feature_config_flags &
8221 FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY) {
8222 /* Use specific phy request */
8223 cmd = DRV_MSG_CODE_VRFY_SPECIFIC_PHY_OPT_MDL;
8224 } else if (params->feature_config_flags &
8225 FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY) {
8226 /* Use first phy request only in case of non-dual media*/
8227 if (DUAL_MEDIA(params)) {
Joe Perches94f05b02011-08-14 12:16:20 +00008228 DP(NETIF_MSG_LINK,
8229 "FW does not support OPT MDL verification\n");
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008230 return -EINVAL;
8231 }
8232 cmd = DRV_MSG_CODE_VRFY_FIRST_PHY_OPT_MDL;
8233 } else {
8234 /* No support in OPT MDL detection */
Joe Perches94f05b02011-08-14 12:16:20 +00008235 DP(NETIF_MSG_LINK,
8236 "FW does not support OPT MDL verification\n");
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008237 return -EINVAL;
8238 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008239
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008240 fw_cmd_param = FW_PARAM_SET(phy->addr, phy->type, phy->mdio_ctrl);
8241 fw_resp = bnx2x_fw_command(bp, cmd, fw_cmd_param);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008242 if (fw_resp == FW_MSG_CODE_VRFY_OPT_MDL_SUCCESS) {
8243 DP(NETIF_MSG_LINK, "Approved module\n");
8244 return 0;
8245 }
8246
Yuval Mintzd2310232012-06-20 19:05:19 +00008247 /* Format the warning message */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008248 if (bnx2x_read_sfp_module_eeprom(phy,
8249 params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008250 SFP_EEPROM_VENDOR_NAME_ADDR,
8251 SFP_EEPROM_VENDOR_NAME_SIZE,
8252 (u8 *)vendor_name))
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008253 vendor_name[0] = '\0';
8254 else
8255 vendor_name[SFP_EEPROM_VENDOR_NAME_SIZE] = '\0';
8256 if (bnx2x_read_sfp_module_eeprom(phy,
8257 params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008258 SFP_EEPROM_PART_NO_ADDR,
8259 SFP_EEPROM_PART_NO_SIZE,
8260 (u8 *)vendor_pn))
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008261 vendor_pn[0] = '\0';
8262 else
8263 vendor_pn[SFP_EEPROM_PART_NO_SIZE] = '\0';
8264
Yaniv Rosner6d870c32011-01-31 04:22:20 +00008265 netdev_err(bp->dev, "Warning: Unqualified SFP+ module detected,"
8266 " Port %d from %s part number %s\n",
8267 params->port, vendor_name, vendor_pn);
Yaniv Rosner59a2e532012-04-04 01:28:59 +00008268 if ((val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) !=
8269 PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_WARNING_MSG)
8270 phy->flags |= FLAGS_SFP_NOT_APPROVED;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008271 return -EINVAL;
8272}
8273
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00008274static int bnx2x_wait_for_sfp_module_initialized(struct bnx2x_phy *phy,
8275 struct link_params *params)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008276
8277{
8278 u8 val;
8279 struct bnx2x *bp = params->bp;
8280 u16 timeout;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00008281 /* Initialization time after hot-plug may take up to 300ms for
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008282 * some phys type ( e.g. JDSU )
8283 */
8284
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008285 for (timeout = 0; timeout < 60; timeout++) {
8286 if (bnx2x_read_sfp_module_eeprom(phy, params, 1, 1, &val)
8287 == 0) {
Joe Perches94f05b02011-08-14 12:16:20 +00008288 DP(NETIF_MSG_LINK,
8289 "SFP+ module initialization took %d ms\n",
8290 timeout * 5);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008291 return 0;
8292 }
Yuval Mintzd2310232012-06-20 19:05:19 +00008293 usleep_range(5000, 10000);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008294 }
8295 return -EINVAL;
8296}
8297
8298static void bnx2x_8727_power_module(struct bnx2x *bp,
8299 struct bnx2x_phy *phy,
8300 u8 is_power_up) {
8301 /* Make sure GPIOs are not using for LED mode */
8302 u16 val;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00008303 /* In the GPIO register, bit 4 is use to determine if the GPIOs are
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008304 * operating as INPUT or as OUTPUT. Bit 1 is for input, and 0 for
8305 * output
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008306 * Bits 0-1 determine the GPIOs value for OUTPUT in case bit 4 val is 0
8307 * Bits 8-9 determine the GPIOs value for INPUT in case bit 4 val is 1
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008308 * where the 1st bit is the over-current(only input), and 2nd bit is
8309 * for power( only output )
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008310 *
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008311 * In case of NOC feature is disabled and power is up, set GPIO control
8312 * as input to enable listening of over-current indication
8313 */
8314 if (phy->flags & FLAGS_NOC)
8315 return;
Yaniv Rosner27d02432011-05-31 21:27:48 +00008316 if (is_power_up)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008317 val = (1<<4);
8318 else
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00008319 /* Set GPIO control to OUTPUT, and set the power bit
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008320 * to according to the is_power_up
8321 */
Yaniv Rosner27d02432011-05-31 21:27:48 +00008322 val = (1<<1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008323
8324 bnx2x_cl45_write(bp, phy,
8325 MDIO_PMA_DEVAD,
8326 MDIO_PMA_REG_8727_GPIO_CTRL,
8327 val);
8328}
8329
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00008330static int bnx2x_8726_set_limiting_mode(struct bnx2x *bp,
8331 struct bnx2x_phy *phy,
8332 u16 edc_mode)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008333{
8334 u16 cur_limiting_mode;
8335
8336 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008337 MDIO_PMA_DEVAD,
8338 MDIO_PMA_REG_ROM_VER2,
8339 &cur_limiting_mode);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008340 DP(NETIF_MSG_LINK, "Current Limiting mode is 0x%x\n",
8341 cur_limiting_mode);
8342
8343 if (edc_mode == EDC_MODE_LIMITING) {
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008344 DP(NETIF_MSG_LINK, "Setting LIMITING MODE\n");
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008345 bnx2x_cl45_write(bp, phy,
8346 MDIO_PMA_DEVAD,
8347 MDIO_PMA_REG_ROM_VER2,
8348 EDC_MODE_LIMITING);
8349 } else { /* LRM mode ( default )*/
8350
8351 DP(NETIF_MSG_LINK, "Setting LRM MODE\n");
8352
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00008353 /* Changing to LRM mode takes quite few seconds. So do it only
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008354 * if current mode is limiting (default is LRM)
8355 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008356 if (cur_limiting_mode != EDC_MODE_LIMITING)
8357 return 0;
8358
8359 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008360 MDIO_PMA_DEVAD,
8361 MDIO_PMA_REG_LRM_MODE,
8362 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008363 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008364 MDIO_PMA_DEVAD,
8365 MDIO_PMA_REG_ROM_VER2,
8366 0x128);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008367 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008368 MDIO_PMA_DEVAD,
8369 MDIO_PMA_REG_MISC_CTRL0,
8370 0x4008);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008371 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008372 MDIO_PMA_DEVAD,
8373 MDIO_PMA_REG_LRM_MODE,
8374 0xaaaa);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008375 }
8376 return 0;
8377}
8378
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00008379static int bnx2x_8727_set_limiting_mode(struct bnx2x *bp,
8380 struct bnx2x_phy *phy,
8381 u16 edc_mode)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008382{
8383 u16 phy_identifier;
8384 u16 rom_ver2_val;
8385 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008386 MDIO_PMA_DEVAD,
8387 MDIO_PMA_REG_PHY_IDENTIFIER,
8388 &phy_identifier);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008389
8390 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008391 MDIO_PMA_DEVAD,
8392 MDIO_PMA_REG_PHY_IDENTIFIER,
8393 (phy_identifier & ~(1<<9)));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008394
8395 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008396 MDIO_PMA_DEVAD,
8397 MDIO_PMA_REG_ROM_VER2,
8398 &rom_ver2_val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008399 /* Keep the MSB 8-bits, and set the LSB 8-bits with the edc_mode */
8400 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008401 MDIO_PMA_DEVAD,
8402 MDIO_PMA_REG_ROM_VER2,
8403 (rom_ver2_val & 0xff00) | (edc_mode & 0x00ff));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008404
8405 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008406 MDIO_PMA_DEVAD,
8407 MDIO_PMA_REG_PHY_IDENTIFIER,
8408 (phy_identifier | (1<<9)));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008409
8410 return 0;
8411}
8412
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008413static void bnx2x_8727_specific_func(struct bnx2x_phy *phy,
8414 struct link_params *params,
8415 u32 action)
8416{
8417 struct bnx2x *bp = params->bp;
8418
8419 switch (action) {
8420 case DISABLE_TX:
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008421 bnx2x_sfp_set_transmitter(params, phy, 0);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008422 break;
8423 case ENABLE_TX:
8424 if (!(phy->flags & FLAGS_SFP_NOT_APPROVED))
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008425 bnx2x_sfp_set_transmitter(params, phy, 1);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008426 break;
8427 default:
8428 DP(NETIF_MSG_LINK, "Function 0x%x not supported by 8727\n",
8429 action);
8430 return;
8431 }
8432}
8433
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008434static void bnx2x_set_e1e2_module_fault_led(struct link_params *params,
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008435 u8 gpio_mode)
8436{
8437 struct bnx2x *bp = params->bp;
8438
8439 u32 fault_led_gpio = REG_RD(bp, params->shmem_base +
8440 offsetof(struct shmem_region,
8441 dev_info.port_hw_config[params->port].sfp_ctrl)) &
8442 PORT_HW_CFG_FAULT_MODULE_LED_MASK;
8443 switch (fault_led_gpio) {
8444 case PORT_HW_CFG_FAULT_MODULE_LED_DISABLED:
8445 return;
8446 case PORT_HW_CFG_FAULT_MODULE_LED_GPIO0:
8447 case PORT_HW_CFG_FAULT_MODULE_LED_GPIO1:
8448 case PORT_HW_CFG_FAULT_MODULE_LED_GPIO2:
8449 case PORT_HW_CFG_FAULT_MODULE_LED_GPIO3:
8450 {
8451 u8 gpio_port = bnx2x_get_gpio_port(params);
8452 u16 gpio_pin = fault_led_gpio -
8453 PORT_HW_CFG_FAULT_MODULE_LED_GPIO0;
8454 DP(NETIF_MSG_LINK, "Set fault module-detected led "
8455 "pin %x port %x mode %x\n",
8456 gpio_pin, gpio_port, gpio_mode);
8457 bnx2x_set_gpio(bp, gpio_pin, gpio_mode, gpio_port);
8458 }
8459 break;
8460 default:
8461 DP(NETIF_MSG_LINK, "Error: Invalid fault led mode 0x%x\n",
8462 fault_led_gpio);
8463 }
8464}
8465
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008466static void bnx2x_set_e3_module_fault_led(struct link_params *params,
8467 u8 gpio_mode)
8468{
8469 u32 pin_cfg;
8470 u8 port = params->port;
8471 struct bnx2x *bp = params->bp;
8472 pin_cfg = (REG_RD(bp, params->shmem_base +
8473 offsetof(struct shmem_region,
8474 dev_info.port_hw_config[port].e3_sfp_ctrl)) &
8475 PORT_HW_CFG_E3_FAULT_MDL_LED_MASK) >>
8476 PORT_HW_CFG_E3_FAULT_MDL_LED_SHIFT;
8477 DP(NETIF_MSG_LINK, "Setting Fault LED to %d using pin cfg %d\n",
8478 gpio_mode, pin_cfg);
8479 bnx2x_set_cfg_pin(bp, pin_cfg, gpio_mode);
8480}
8481
8482static void bnx2x_set_sfp_module_fault_led(struct link_params *params,
8483 u8 gpio_mode)
8484{
8485 struct bnx2x *bp = params->bp;
8486 DP(NETIF_MSG_LINK, "Setting SFP+ module fault LED to %d\n", gpio_mode);
8487 if (CHIP_IS_E3(bp)) {
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00008488 /* Low ==> if SFP+ module is supported otherwise
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008489 * High ==> if SFP+ module is not on the approved vendor list
8490 */
8491 bnx2x_set_e3_module_fault_led(params, gpio_mode);
8492 } else
8493 bnx2x_set_e1e2_module_fault_led(params, gpio_mode);
8494}
8495
Yaniv Rosner985848f2011-07-05 01:06:48 +00008496static void bnx2x_warpcore_hw_reset(struct bnx2x_phy *phy,
8497 struct link_params *params)
8498{
Yaniv Rosnerb76070b2011-11-28 00:49:47 +00008499 struct bnx2x *bp = params->bp;
Yaniv Rosner985848f2011-07-05 01:06:48 +00008500 bnx2x_warpcore_power_module(params, phy, 0);
Yaniv Rosnerb76070b2011-11-28 00:49:47 +00008501 /* Put Warpcore in low power mode */
8502 REG_WR(bp, MISC_REG_WC0_RESET, 0x0c0e);
8503
8504 /* Put LCPLL in low power mode */
8505 REG_WR(bp, MISC_REG_LCPLL_E40_PWRDWN, 1);
8506 REG_WR(bp, MISC_REG_LCPLL_E40_RESETB_ANA, 0);
8507 REG_WR(bp, MISC_REG_LCPLL_E40_RESETB_DIG, 0);
Yaniv Rosner985848f2011-07-05 01:06:48 +00008508}
8509
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00008510static void bnx2x_power_sfp_module(struct link_params *params,
8511 struct bnx2x_phy *phy,
8512 u8 power)
8513{
8514 struct bnx2x *bp = params->bp;
8515 DP(NETIF_MSG_LINK, "Setting SFP+ power to %x\n", power);
8516
8517 switch (phy->type) {
8518 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
8519 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8722:
8520 bnx2x_8727_power_module(params->bp, phy, power);
8521 break;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008522 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT:
8523 bnx2x_warpcore_power_module(params, phy, power);
8524 break;
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00008525 default:
8526 break;
8527 }
8528}
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008529static void bnx2x_warpcore_set_limiting_mode(struct link_params *params,
8530 struct bnx2x_phy *phy,
8531 u16 edc_mode)
8532{
8533 u16 val = 0;
8534 u16 mode = MDIO_WC_REG_UC_INFO_B1_FIRMWARE_MODE_DEFAULT;
8535 struct bnx2x *bp = params->bp;
8536
8537 u8 lane = bnx2x_get_warpcore_lane(phy, params);
8538 /* This is a global register which controls all lanes */
8539 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
8540 MDIO_WC_REG_UC_INFO_B1_FIRMWARE_MODE, &val);
8541 val &= ~(0xf << (lane << 2));
8542
8543 switch (edc_mode) {
8544 case EDC_MODE_LINEAR:
8545 case EDC_MODE_LIMITING:
8546 mode = MDIO_WC_REG_UC_INFO_B1_FIRMWARE_MODE_DEFAULT;
8547 break;
8548 case EDC_MODE_PASSIVE_DAC:
8549 mode = MDIO_WC_REG_UC_INFO_B1_FIRMWARE_MODE_SFP_DAC;
8550 break;
8551 default:
8552 break;
8553 }
8554
8555 val |= (mode << (lane << 2));
8556 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
8557 MDIO_WC_REG_UC_INFO_B1_FIRMWARE_MODE, val);
8558 /* A must read */
8559 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
8560 MDIO_WC_REG_UC_INFO_B1_FIRMWARE_MODE, &val);
8561
Yaniv Rosner19af03a2011-08-02 22:59:47 +00008562 /* Restart microcode to re-read the new mode */
8563 bnx2x_warpcore_reset_lane(bp, phy, 1);
8564 bnx2x_warpcore_reset_lane(bp, phy, 0);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008565
8566}
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00008567
8568static void bnx2x_set_limiting_mode(struct link_params *params,
8569 struct bnx2x_phy *phy,
8570 u16 edc_mode)
8571{
8572 switch (phy->type) {
8573 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
8574 bnx2x_8726_set_limiting_mode(params->bp, phy, edc_mode);
8575 break;
8576 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
8577 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8722:
8578 bnx2x_8727_set_limiting_mode(params->bp, phy, edc_mode);
8579 break;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008580 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT:
8581 bnx2x_warpcore_set_limiting_mode(params, phy, edc_mode);
8582 break;
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00008583 }
8584}
8585
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00008586int bnx2x_sfp_module_detection(struct bnx2x_phy *phy,
8587 struct link_params *params)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008588{
8589 struct bnx2x *bp = params->bp;
8590 u16 edc_mode;
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00008591 int rc = 0;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008592
8593 u32 val = REG_RD(bp, params->shmem_base +
8594 offsetof(struct shmem_region, dev_info.
8595 port_feature_config[params->port].config));
8596
8597 DP(NETIF_MSG_LINK, "SFP+ module plugged in/out detected on port %d\n",
8598 params->port);
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00008599 /* Power up module */
8600 bnx2x_power_sfp_module(params, phy, 1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008601 if (bnx2x_get_edc_mode(phy, params, &edc_mode) != 0) {
8602 DP(NETIF_MSG_LINK, "Failed to get valid module type\n");
8603 return -EINVAL;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008604 } else if (bnx2x_verify_sfp_module(phy, params) != 0) {
Yuval Mintzd2310232012-06-20 19:05:19 +00008605 /* Check SFP+ module compatibility */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008606 DP(NETIF_MSG_LINK, "Module verification failed!!\n");
8607 rc = -EINVAL;
8608 /* Turn on fault module-detected led */
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008609 bnx2x_set_sfp_module_fault_led(params,
8610 MISC_REGISTERS_GPIO_HIGH);
8611
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00008612 /* Check if need to power down the SFP+ module */
8613 if ((val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) ==
8614 PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_POWER_DOWN) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008615 DP(NETIF_MSG_LINK, "Shutdown SFP+ module!!\n");
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00008616 bnx2x_power_sfp_module(params, phy, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008617 return rc;
8618 }
8619 } else {
8620 /* Turn off fault module-detected led */
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008621 bnx2x_set_sfp_module_fault_led(params, MISC_REGISTERS_GPIO_LOW);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008622 }
8623
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00008624 /* Check and set limiting mode / LRM mode on 8726. On 8727 it
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008625 * is done automatically
8626 */
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00008627 bnx2x_set_limiting_mode(params, phy, edc_mode);
8628
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00008629 /* Enable transmit for this module if the module is approved, or
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008630 * if unapproved modules should also enable the Tx laser
8631 */
8632 if (rc == 0 ||
8633 (val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) !=
8634 PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_DISABLE_TX_LASER)
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008635 bnx2x_sfp_set_transmitter(params, phy, 1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008636 else
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008637 bnx2x_sfp_set_transmitter(params, phy, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008638
8639 return rc;
8640}
8641
8642void bnx2x_handle_module_detect_int(struct link_params *params)
8643{
8644 struct bnx2x *bp = params->bp;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008645 struct bnx2x_phy *phy;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008646 u32 gpio_val;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008647 u8 gpio_num, gpio_port;
8648 if (CHIP_IS_E3(bp))
8649 phy = &params->phy[INT_PHY];
8650 else
8651 phy = &params->phy[EXT_PHY1];
8652
8653 if (bnx2x_get_mod_abs_int_cfg(bp, params->chip_id, params->shmem_base,
8654 params->port, &gpio_num, &gpio_port) ==
8655 -EINVAL) {
8656 DP(NETIF_MSG_LINK, "Failed to get MOD_ABS interrupt config\n");
8657 return;
8658 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008659
8660 /* Set valid module led off */
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008661 bnx2x_set_sfp_module_fault_led(params, MISC_REGISTERS_GPIO_HIGH);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008662
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008663 /* Get current gpio val reflecting module plugged in / out*/
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008664 gpio_val = bnx2x_get_gpio(bp, gpio_num, gpio_port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008665
8666 /* Call the handling function in case module is detected */
8667 if (gpio_val == 0) {
Yuval Mintzdbef8072012-06-20 19:05:22 +00008668 bnx2x_set_mdio_clk(bp, params->chip_id, params->port);
8669 bnx2x_set_aer_mmd(params, phy);
8670
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00008671 bnx2x_power_sfp_module(params, phy, 1);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008672 bnx2x_set_gpio_int(bp, gpio_num,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008673 MISC_REGISTERS_GPIO_INT_OUTPUT_CLR,
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008674 gpio_port);
Yuval Mintzdbef8072012-06-20 19:05:22 +00008675 if (bnx2x_wait_for_sfp_module_initialized(phy, params) == 0) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008676 bnx2x_sfp_module_detection(phy, params);
Yuval Mintzdbef8072012-06-20 19:05:22 +00008677 if (CHIP_IS_E3(bp)) {
8678 u16 rx_tx_in_reset;
8679 /* In case WC is out of reset, reconfigure the
8680 * link speed while taking into account 1G
8681 * module limitation.
8682 */
8683 bnx2x_cl45_read(bp, phy,
8684 MDIO_WC_DEVAD,
8685 MDIO_WC_REG_DIGITAL5_MISC6,
8686 &rx_tx_in_reset);
8687 if (!rx_tx_in_reset) {
8688 bnx2x_warpcore_reset_lane(bp, phy, 1);
8689 bnx2x_warpcore_config_sfi(phy, params);
8690 bnx2x_warpcore_reset_lane(bp, phy, 0);
8691 }
8692 }
8693 } else {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008694 DP(NETIF_MSG_LINK, "SFP+ module is not initialized\n");
Yuval Mintzdbef8072012-06-20 19:05:22 +00008695 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008696 } else {
8697 u32 val = REG_RD(bp, params->shmem_base +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008698 offsetof(struct shmem_region, dev_info.
8699 port_feature_config[params->port].
8700 config));
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008701 bnx2x_set_gpio_int(bp, gpio_num,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008702 MISC_REGISTERS_GPIO_INT_OUTPUT_SET,
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008703 gpio_port);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00008704 /* Module was plugged out.
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008705 * Disable transmit for this module
8706 */
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00008707 phy->media_type = ETH_PHY_NOT_PRESENT;
Yaniv Rosnerde6f3372011-08-02 22:59:25 +00008708 if (((val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) ==
8709 PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_DISABLE_TX_LASER) ||
8710 CHIP_IS_E3(bp))
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008711 bnx2x_sfp_set_transmitter(params, phy, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008712 }
8713}
8714
8715/******************************************************************/
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00008716/* Used by 8706 and 8727 */
8717/******************************************************************/
8718static void bnx2x_sfp_mask_fault(struct bnx2x *bp,
8719 struct bnx2x_phy *phy,
8720 u16 alarm_status_offset,
8721 u16 alarm_ctrl_offset)
8722{
8723 u16 alarm_status, val;
8724 bnx2x_cl45_read(bp, phy,
8725 MDIO_PMA_DEVAD, alarm_status_offset,
8726 &alarm_status);
8727 bnx2x_cl45_read(bp, phy,
8728 MDIO_PMA_DEVAD, alarm_status_offset,
8729 &alarm_status);
8730 /* Mask or enable the fault event. */
8731 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD, alarm_ctrl_offset, &val);
8732 if (alarm_status & (1<<0))
8733 val &= ~(1<<0);
8734 else
8735 val |= (1<<0);
8736 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, alarm_ctrl_offset, val);
8737}
8738/******************************************************************/
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008739/* common BCM8706/BCM8726 PHY SECTION */
8740/******************************************************************/
8741static u8 bnx2x_8706_8726_read_status(struct bnx2x_phy *phy,
8742 struct link_params *params,
8743 struct link_vars *vars)
8744{
8745 u8 link_up = 0;
8746 u16 val1, val2, rx_sd, pcs_status;
8747 struct bnx2x *bp = params->bp;
8748 DP(NETIF_MSG_LINK, "XGXS 8706/8726\n");
8749 /* Clear RX Alarm*/
8750 bnx2x_cl45_read(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00008751 MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXSTAT, &val2);
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00008752
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00008753 bnx2x_sfp_mask_fault(bp, phy, MDIO_PMA_LASI_TXSTAT,
8754 MDIO_PMA_LASI_TXCTRL);
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00008755
Yuval Mintzd2310232012-06-20 19:05:19 +00008756 /* Clear LASI indication*/
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008757 bnx2x_cl45_read(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00008758 MDIO_PMA_DEVAD, MDIO_PMA_LASI_STAT, &val1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008759 bnx2x_cl45_read(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00008760 MDIO_PMA_DEVAD, MDIO_PMA_LASI_STAT, &val2);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008761 DP(NETIF_MSG_LINK, "8706/8726 LASI status 0x%x--> 0x%x\n", val1, val2);
8762
8763 bnx2x_cl45_read(bp, phy,
8764 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_SD, &rx_sd);
8765 bnx2x_cl45_read(bp, phy,
8766 MDIO_PCS_DEVAD, MDIO_PCS_REG_STATUS, &pcs_status);
8767 bnx2x_cl45_read(bp, phy,
8768 MDIO_AN_DEVAD, MDIO_AN_REG_LINK_STATUS, &val2);
8769 bnx2x_cl45_read(bp, phy,
8770 MDIO_AN_DEVAD, MDIO_AN_REG_LINK_STATUS, &val2);
8771
8772 DP(NETIF_MSG_LINK, "8706/8726 rx_sd 0x%x pcs_status 0x%x 1Gbps"
8773 " link_status 0x%x\n", rx_sd, pcs_status, val2);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00008774 /* Link is up if both bit 0 of pmd_rx_sd and bit 0 of pcs_status
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008775 * are set, or if the autoneg bit 1 is set
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008776 */
8777 link_up = ((rx_sd & pcs_status & 0x1) || (val2 & (1<<1)));
8778 if (link_up) {
8779 if (val2 & (1<<1))
8780 vars->line_speed = SPEED_1000;
8781 else
8782 vars->line_speed = SPEED_10000;
8783 bnx2x_ext_phy_resolve_fc(phy, params, vars);
Yaniv Rosner791f18c2011-01-18 04:33:42 +00008784 vars->duplex = DUPLEX_FULL;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008785 }
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00008786
8787 /* Capture 10G link fault. Read twice to clear stale value. */
8788 if (vars->line_speed == SPEED_10000) {
8789 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00008790 MDIO_PMA_LASI_TXSTAT, &val1);
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00008791 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00008792 MDIO_PMA_LASI_TXSTAT, &val1);
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00008793 if (val1 & (1<<0))
8794 vars->fault_detected = 1;
8795 }
8796
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008797 return link_up;
8798}
8799
8800/******************************************************************/
8801/* BCM8706 PHY SECTION */
8802/******************************************************************/
8803static u8 bnx2x_8706_config_init(struct bnx2x_phy *phy,
8804 struct link_params *params,
8805 struct link_vars *vars)
8806{
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008807 u32 tx_en_mode;
8808 u16 cnt, val, tmp1;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008809 struct bnx2x *bp = params->bp;
Yaniv Rosner3deb8162011-06-14 01:34:33 +00008810
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008811 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008812 MISC_REGISTERS_GPIO_OUTPUT_HIGH, params->port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008813 /* HW reset */
8814 bnx2x_ext_phy_hw_reset(bp, params->port);
8815 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0xa040);
Yaniv Rosner6d870c32011-01-31 04:22:20 +00008816 bnx2x_wait_reset_complete(bp, phy, params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008817
8818 /* Wait until fw is loaded */
8819 for (cnt = 0; cnt < 100; cnt++) {
8820 bnx2x_cl45_read(bp, phy,
8821 MDIO_PMA_DEVAD, MDIO_PMA_REG_ROM_VER1, &val);
8822 if (val)
8823 break;
Yuval Mintzd2310232012-06-20 19:05:19 +00008824 usleep_range(10000, 20000);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008825 }
8826 DP(NETIF_MSG_LINK, "XGXS 8706 is initialized after %d ms\n", cnt);
8827 if ((params->feature_config_flags &
8828 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED)) {
8829 u8 i;
8830 u16 reg;
8831 for (i = 0; i < 4; i++) {
8832 reg = MDIO_XS_8706_REG_BANK_RX0 +
8833 i*(MDIO_XS_8706_REG_BANK_RX1 -
8834 MDIO_XS_8706_REG_BANK_RX0);
8835 bnx2x_cl45_read(bp, phy, MDIO_XS_DEVAD, reg, &val);
8836 /* Clear first 3 bits of the control */
8837 val &= ~0x7;
8838 /* Set control bits according to configuration */
8839 val |= (phy->rx_preemphasis[i] & 0x7);
8840 DP(NETIF_MSG_LINK, "Setting RX Equalizer to BCM8706"
8841 " reg 0x%x <-- val 0x%x\n", reg, val);
8842 bnx2x_cl45_write(bp, phy, MDIO_XS_DEVAD, reg, val);
8843 }
8844 }
8845 /* Force speed */
8846 if (phy->req_line_speed == SPEED_10000) {
8847 DP(NETIF_MSG_LINK, "XGXS 8706 force 10Gbps\n");
8848
8849 bnx2x_cl45_write(bp, phy,
8850 MDIO_PMA_DEVAD,
8851 MDIO_PMA_REG_DIGITAL_CTRL, 0x400);
8852 bnx2x_cl45_write(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00008853 MDIO_PMA_DEVAD, MDIO_PMA_LASI_TXCTRL,
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00008854 0);
8855 /* Arm LASI for link and Tx fault. */
8856 bnx2x_cl45_write(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00008857 MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL, 3);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008858 } else {
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008859 /* Force 1Gbps using autoneg with 1G advertisement */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008860
8861 /* Allow CL37 through CL73 */
8862 DP(NETIF_MSG_LINK, "XGXS 8706 AutoNeg\n");
8863 bnx2x_cl45_write(bp, phy,
8864 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_CL73, 0x040c);
8865
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008866 /* Enable Full-Duplex advertisement on CL37 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008867 bnx2x_cl45_write(bp, phy,
8868 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LP, 0x0020);
8869 /* Enable CL37 AN */
8870 bnx2x_cl45_write(bp, phy,
8871 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_AN, 0x1000);
8872 /* 1G support */
8873 bnx2x_cl45_write(bp, phy,
8874 MDIO_AN_DEVAD, MDIO_AN_REG_ADV, (1<<5));
8875
8876 /* Enable clause 73 AN */
8877 bnx2x_cl45_write(bp, phy,
8878 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x1200);
8879 bnx2x_cl45_write(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00008880 MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXCTRL,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008881 0x0400);
8882 bnx2x_cl45_write(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00008883 MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008884 0x0004);
8885 }
8886 bnx2x_save_bcm_spirom_ver(bp, phy, params->port);
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008887
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00008888 /* If TX Laser is controlled by GPIO_0, do not let PHY go into low
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008889 * power mode, if TX Laser is disabled
8890 */
8891
8892 tx_en_mode = REG_RD(bp, params->shmem_base +
8893 offsetof(struct shmem_region,
8894 dev_info.port_hw_config[params->port].sfp_ctrl))
8895 & PORT_HW_CFG_TX_LASER_MASK;
8896
8897 if (tx_en_mode == PORT_HW_CFG_TX_LASER_GPIO0) {
8898 DP(NETIF_MSG_LINK, "Enabling TXONOFF_PWRDN_DIS\n");
8899 bnx2x_cl45_read(bp, phy,
8900 MDIO_PMA_DEVAD, MDIO_PMA_REG_DIGITAL_CTRL, &tmp1);
8901 tmp1 |= 0x1;
8902 bnx2x_cl45_write(bp, phy,
8903 MDIO_PMA_DEVAD, MDIO_PMA_REG_DIGITAL_CTRL, tmp1);
8904 }
8905
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008906 return 0;
8907}
8908
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00008909static int bnx2x_8706_read_status(struct bnx2x_phy *phy,
8910 struct link_params *params,
8911 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008912{
8913 return bnx2x_8706_8726_read_status(phy, params, vars);
8914}
8915
8916/******************************************************************/
8917/* BCM8726 PHY SECTION */
8918/******************************************************************/
8919static void bnx2x_8726_config_loopback(struct bnx2x_phy *phy,
8920 struct link_params *params)
8921{
8922 struct bnx2x *bp = params->bp;
8923 DP(NETIF_MSG_LINK, "PMA/PMD ext_phy_loopback: 8726\n");
8924 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x0001);
8925}
8926
8927static void bnx2x_8726_external_rom_boot(struct bnx2x_phy *phy,
8928 struct link_params *params)
8929{
8930 struct bnx2x *bp = params->bp;
8931 /* Need to wait 100ms after reset */
8932 msleep(100);
8933
8934 /* Micro controller re-boot */
8935 bnx2x_cl45_write(bp, phy,
8936 MDIO_PMA_DEVAD, MDIO_PMA_REG_GEN_CTRL, 0x018B);
8937
8938 /* Set soft reset */
8939 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008940 MDIO_PMA_DEVAD,
8941 MDIO_PMA_REG_GEN_CTRL,
8942 MDIO_PMA_REG_GEN_CTRL_ROM_MICRO_RESET);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008943
8944 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008945 MDIO_PMA_DEVAD,
8946 MDIO_PMA_REG_MISC_CTRL1, 0x0001);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008947
8948 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008949 MDIO_PMA_DEVAD,
8950 MDIO_PMA_REG_GEN_CTRL,
8951 MDIO_PMA_REG_GEN_CTRL_ROM_RESET_INTERNAL_MP);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008952
Yuval Mintzd2310232012-06-20 19:05:19 +00008953 /* Wait for 150ms for microcode load */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008954 msleep(150);
8955
8956 /* Disable serial boot control, tristates pins SS_N, SCK, MOSI, MISO */
8957 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008958 MDIO_PMA_DEVAD,
8959 MDIO_PMA_REG_MISC_CTRL1, 0x0000);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008960
8961 msleep(200);
8962 bnx2x_save_bcm_spirom_ver(bp, phy, params->port);
8963}
8964
8965static u8 bnx2x_8726_read_status(struct bnx2x_phy *phy,
8966 struct link_params *params,
8967 struct link_vars *vars)
8968{
8969 struct bnx2x *bp = params->bp;
8970 u16 val1;
8971 u8 link_up = bnx2x_8706_8726_read_status(phy, params, vars);
8972 if (link_up) {
8973 bnx2x_cl45_read(bp, phy,
8974 MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER,
8975 &val1);
8976 if (val1 & (1<<15)) {
8977 DP(NETIF_MSG_LINK, "Tx is disabled\n");
8978 link_up = 0;
8979 vars->line_speed = 0;
8980 }
8981 }
8982 return link_up;
8983}
8984
8985
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00008986static int bnx2x_8726_config_init(struct bnx2x_phy *phy,
8987 struct link_params *params,
8988 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008989{
8990 struct bnx2x *bp = params->bp;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008991 DP(NETIF_MSG_LINK, "Initializing BCM8726\n");
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008992
8993 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 1<<15);
Yaniv Rosner6d870c32011-01-31 04:22:20 +00008994 bnx2x_wait_reset_complete(bp, phy, params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008995
8996 bnx2x_8726_external_rom_boot(phy, params);
8997
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00008998 /* Need to call module detected on initialization since the module
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008999 * detection triggered by actual module insertion might occur before
9000 * driver is loaded, and when driver is loaded, it reset all
9001 * registers, including the transmitter
9002 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009003 bnx2x_sfp_module_detection(phy, params);
9004
9005 if (phy->req_line_speed == SPEED_1000) {
9006 DP(NETIF_MSG_LINK, "Setting 1G force\n");
9007 bnx2x_cl45_write(bp, phy,
9008 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x40);
9009 bnx2x_cl45_write(bp, phy,
9010 MDIO_PMA_DEVAD, MDIO_PMA_REG_10G_CTRL2, 0xD);
9011 bnx2x_cl45_write(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009012 MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL, 0x5);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009013 bnx2x_cl45_write(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009014 MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXCTRL,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009015 0x400);
9016 } else if ((phy->req_line_speed == SPEED_AUTO_NEG) &&
9017 (phy->speed_cap_mask &
9018 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G) &&
9019 ((phy->speed_cap_mask &
9020 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G) !=
9021 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) {
9022 DP(NETIF_MSG_LINK, "Setting 1G clause37\n");
9023 /* Set Flow control */
9024 bnx2x_ext_phy_set_pause(params, phy, vars);
9025 bnx2x_cl45_write(bp, phy,
9026 MDIO_AN_DEVAD, MDIO_AN_REG_ADV, 0x20);
9027 bnx2x_cl45_write(bp, phy,
9028 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_CL73, 0x040c);
9029 bnx2x_cl45_write(bp, phy,
9030 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LD, 0x0020);
9031 bnx2x_cl45_write(bp, phy,
9032 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_AN, 0x1000);
9033 bnx2x_cl45_write(bp, phy,
9034 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x1200);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00009035 /* Enable RX-ALARM control to receive interrupt for 1G speed
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00009036 * change
9037 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009038 bnx2x_cl45_write(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009039 MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL, 0x4);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009040 bnx2x_cl45_write(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009041 MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXCTRL,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009042 0x400);
9043
9044 } else { /* Default 10G. Set only LASI control */
9045 bnx2x_cl45_write(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009046 MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL, 1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009047 }
9048
9049 /* Set TX PreEmphasis if needed */
9050 if ((params->feature_config_flags &
9051 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED)) {
Joe Perches94f05b02011-08-14 12:16:20 +00009052 DP(NETIF_MSG_LINK,
9053 "Setting TX_CTRL1 0x%x, TX_CTRL2 0x%x\n",
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009054 phy->tx_preemphasis[0],
9055 phy->tx_preemphasis[1]);
9056 bnx2x_cl45_write(bp, phy,
9057 MDIO_PMA_DEVAD,
9058 MDIO_PMA_REG_8726_TX_CTRL1,
9059 phy->tx_preemphasis[0]);
9060
9061 bnx2x_cl45_write(bp, phy,
9062 MDIO_PMA_DEVAD,
9063 MDIO_PMA_REG_8726_TX_CTRL2,
9064 phy->tx_preemphasis[1]);
9065 }
9066
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009067 return 0;
9068
9069}
9070
9071static void bnx2x_8726_link_reset(struct bnx2x_phy *phy,
9072 struct link_params *params)
9073{
9074 struct bnx2x *bp = params->bp;
9075 DP(NETIF_MSG_LINK, "bnx2x_8726_link_reset port %d\n", params->port);
9076 /* Set serial boot control for external load */
9077 bnx2x_cl45_write(bp, phy,
9078 MDIO_PMA_DEVAD,
9079 MDIO_PMA_REG_GEN_CTRL, 0x0001);
9080}
9081
9082/******************************************************************/
9083/* BCM8727 PHY SECTION */
9084/******************************************************************/
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00009085
9086static void bnx2x_8727_set_link_led(struct bnx2x_phy *phy,
9087 struct link_params *params, u8 mode)
9088{
9089 struct bnx2x *bp = params->bp;
9090 u16 led_mode_bitmask = 0;
9091 u16 gpio_pins_bitmask = 0;
9092 u16 val;
9093 /* Only NOC flavor requires to set the LED specifically */
9094 if (!(phy->flags & FLAGS_NOC))
9095 return;
9096 switch (mode) {
9097 case LED_MODE_FRONT_PANEL_OFF:
9098 case LED_MODE_OFF:
9099 led_mode_bitmask = 0;
9100 gpio_pins_bitmask = 0x03;
9101 break;
9102 case LED_MODE_ON:
9103 led_mode_bitmask = 0;
9104 gpio_pins_bitmask = 0x02;
9105 break;
9106 case LED_MODE_OPER:
9107 led_mode_bitmask = 0x60;
9108 gpio_pins_bitmask = 0x11;
9109 break;
9110 }
9111 bnx2x_cl45_read(bp, phy,
9112 MDIO_PMA_DEVAD,
9113 MDIO_PMA_REG_8727_PCS_OPT_CTRL,
9114 &val);
9115 val &= 0xff8f;
9116 val |= led_mode_bitmask;
9117 bnx2x_cl45_write(bp, phy,
9118 MDIO_PMA_DEVAD,
9119 MDIO_PMA_REG_8727_PCS_OPT_CTRL,
9120 val);
9121 bnx2x_cl45_read(bp, phy,
9122 MDIO_PMA_DEVAD,
9123 MDIO_PMA_REG_8727_GPIO_CTRL,
9124 &val);
9125 val &= 0xffe0;
9126 val |= gpio_pins_bitmask;
9127 bnx2x_cl45_write(bp, phy,
9128 MDIO_PMA_DEVAD,
9129 MDIO_PMA_REG_8727_GPIO_CTRL,
9130 val);
9131}
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009132static void bnx2x_8727_hw_reset(struct bnx2x_phy *phy,
9133 struct link_params *params) {
9134 u32 swap_val, swap_override;
9135 u8 port;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00009136 /* The PHY reset is controlled by GPIO 1. Fake the port number
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009137 * to cancel the swap done in set_gpio()
9138 */
9139 struct bnx2x *bp = params->bp;
9140 swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
9141 swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
9142 port = (swap_val && swap_override) ^ 1;
9143 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00009144 MISC_REGISTERS_GPIO_OUTPUT_LOW, port);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009145}
9146
Yuval Mintzdbef8072012-06-20 19:05:22 +00009147static void bnx2x_8727_config_speed(struct bnx2x_phy *phy,
9148 struct link_params *params)
9149{
9150 struct bnx2x *bp = params->bp;
9151 u16 tmp1, val;
9152 /* Set option 1G speed */
9153 if ((phy->req_line_speed == SPEED_1000) ||
9154 (phy->media_type == ETH_PHY_SFP_1G_FIBER)) {
9155 DP(NETIF_MSG_LINK, "Setting 1G force\n");
9156 bnx2x_cl45_write(bp, phy,
9157 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x40);
9158 bnx2x_cl45_write(bp, phy,
9159 MDIO_PMA_DEVAD, MDIO_PMA_REG_10G_CTRL2, 0xD);
9160 bnx2x_cl45_read(bp, phy,
9161 MDIO_PMA_DEVAD, MDIO_PMA_REG_10G_CTRL2, &tmp1);
9162 DP(NETIF_MSG_LINK, "1.7 = 0x%x\n", tmp1);
9163 /* Power down the XAUI until link is up in case of dual-media
9164 * and 1G
9165 */
9166 if (DUAL_MEDIA(params)) {
9167 bnx2x_cl45_read(bp, phy,
9168 MDIO_PMA_DEVAD,
9169 MDIO_PMA_REG_8727_PCS_GP, &val);
9170 val |= (3<<10);
9171 bnx2x_cl45_write(bp, phy,
9172 MDIO_PMA_DEVAD,
9173 MDIO_PMA_REG_8727_PCS_GP, val);
9174 }
9175 } else if ((phy->req_line_speed == SPEED_AUTO_NEG) &&
9176 ((phy->speed_cap_mask &
9177 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) &&
9178 ((phy->speed_cap_mask &
9179 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G) !=
9180 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) {
9181
9182 DP(NETIF_MSG_LINK, "Setting 1G clause37\n");
9183 bnx2x_cl45_write(bp, phy,
9184 MDIO_AN_DEVAD, MDIO_AN_REG_8727_MISC_CTRL, 0);
9185 bnx2x_cl45_write(bp, phy,
9186 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_AN, 0x1300);
9187 } else {
9188 /* Since the 8727 has only single reset pin, need to set the 10G
9189 * registers although it is default
9190 */
9191 bnx2x_cl45_write(bp, phy,
9192 MDIO_AN_DEVAD, MDIO_AN_REG_8727_MISC_CTRL,
9193 0x0020);
9194 bnx2x_cl45_write(bp, phy,
9195 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_AN, 0x0100);
9196 bnx2x_cl45_write(bp, phy,
9197 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x2040);
9198 bnx2x_cl45_write(bp, phy,
9199 MDIO_PMA_DEVAD, MDIO_PMA_REG_10G_CTRL2,
9200 0x0008);
9201 }
9202}
9203
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00009204static int bnx2x_8727_config_init(struct bnx2x_phy *phy,
9205 struct link_params *params,
9206 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009207{
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00009208 u32 tx_en_mode;
9209 u16 tmp1, val, mod_abs, tmp2;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009210 u16 rx_alarm_ctrl_val;
9211 u16 lasi_ctrl_val;
9212 struct bnx2x *bp = params->bp;
9213 /* Enable PMD link, MOD_ABS_FLT, and 1G link alarm */
9214
Yaniv Rosner6d870c32011-01-31 04:22:20 +00009215 bnx2x_wait_reset_complete(bp, phy, params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009216 rx_alarm_ctrl_val = (1<<2) | (1<<5) ;
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00009217 /* Should be 0x6 to enable XS on Tx side. */
9218 lasi_ctrl_val = 0x0006;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009219
9220 DP(NETIF_MSG_LINK, "Initializing BCM8727\n");
Yuval Mintzd2310232012-06-20 19:05:19 +00009221 /* Enable LASI */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009222 bnx2x_cl45_write(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009223 MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXCTRL,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009224 rx_alarm_ctrl_val);
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00009225 bnx2x_cl45_write(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009226 MDIO_PMA_DEVAD, MDIO_PMA_LASI_TXCTRL,
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00009227 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009228 bnx2x_cl45_write(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009229 MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL, lasi_ctrl_val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009230
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00009231 /* Initially configure MOD_ABS to interrupt when module is
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00009232 * presence( bit 8)
9233 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009234 bnx2x_cl45_read(bp, phy,
9235 MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER, &mod_abs);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00009236 /* Set EDC off by setting OPTXLOS signal input to low (bit 9).
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00009237 * When the EDC is off it locks onto a reference clock and avoids
9238 * becoming 'lost'
9239 */
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00009240 mod_abs &= ~(1<<8);
9241 if (!(phy->flags & FLAGS_NOC))
9242 mod_abs &= ~(1<<9);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009243 bnx2x_cl45_write(bp, phy,
9244 MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER, mod_abs);
9245
9246
Yaniv Rosner85242ee2011-07-05 01:06:53 +00009247 /* Enable/Disable PHY transmitter output */
9248 bnx2x_set_disable_pmd_transmit(params, phy, 0);
9249
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009250 /* Make MOD_ABS give interrupt on change */
9251 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_PCS_OPT_CTRL,
9252 &val);
9253 val |= (1<<12);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00009254 if (phy->flags & FLAGS_NOC)
9255 val |= (3<<5);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009256
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00009257 /* Set 8727 GPIOs to input to allow reading from the 8727 GPIO0
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00009258 * status which reflect SFP+ module over-current
9259 */
9260 if (!(phy->flags & FLAGS_NOC))
9261 val &= 0xff8f; /* Reset bits 4-6 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009262 bnx2x_cl45_write(bp, phy,
9263 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_PCS_OPT_CTRL, val);
9264
9265 bnx2x_8727_power_module(bp, phy, 1);
9266
9267 bnx2x_cl45_read(bp, phy,
9268 MDIO_PMA_DEVAD, MDIO_PMA_REG_M8051_MSGOUT_REG, &tmp1);
9269
9270 bnx2x_cl45_read(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009271 MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXSTAT, &tmp1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009272
Yuval Mintzdbef8072012-06-20 19:05:22 +00009273 bnx2x_8727_config_speed(phy, params);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00009274 /* Set 2-wire transfer rate of SFP+ module EEPROM
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009275 * to 100Khz since some DACs(direct attached cables) do
9276 * not work at 400Khz.
9277 */
9278 bnx2x_cl45_write(bp, phy,
9279 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_TWO_WIRE_SLAVE_ADDR,
9280 0xa001);
9281
9282 /* Set TX PreEmphasis if needed */
9283 if ((params->feature_config_flags &
9284 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED)) {
9285 DP(NETIF_MSG_LINK, "Setting TX_CTRL1 0x%x, TX_CTRL2 0x%x\n",
9286 phy->tx_preemphasis[0],
9287 phy->tx_preemphasis[1]);
9288 bnx2x_cl45_write(bp, phy,
9289 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_TX_CTRL1,
9290 phy->tx_preemphasis[0]);
9291
9292 bnx2x_cl45_write(bp, phy,
9293 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_TX_CTRL2,
9294 phy->tx_preemphasis[1]);
9295 }
9296
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00009297 /* If TX Laser is controlled by GPIO_0, do not let PHY go into low
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00009298 * power mode, if TX Laser is disabled
9299 */
9300 tx_en_mode = REG_RD(bp, params->shmem_base +
9301 offsetof(struct shmem_region,
9302 dev_info.port_hw_config[params->port].sfp_ctrl))
9303 & PORT_HW_CFG_TX_LASER_MASK;
9304
9305 if (tx_en_mode == PORT_HW_CFG_TX_LASER_GPIO0) {
9306
9307 DP(NETIF_MSG_LINK, "Enabling TXONOFF_PWRDN_DIS\n");
9308 bnx2x_cl45_read(bp, phy,
9309 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_OPT_CFG_REG, &tmp2);
9310 tmp2 |= 0x1000;
9311 tmp2 &= 0xFFEF;
9312 bnx2x_cl45_write(bp, phy,
9313 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_OPT_CFG_REG, tmp2);
Yaniv Rosner59a2e532012-04-04 01:28:59 +00009314 bnx2x_cl45_read(bp, phy,
9315 MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER,
9316 &tmp2);
9317 bnx2x_cl45_write(bp, phy,
9318 MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER,
9319 (tmp2 & 0x7fff));
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00009320 }
9321
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009322 return 0;
9323}
9324
9325static void bnx2x_8727_handle_mod_abs(struct bnx2x_phy *phy,
9326 struct link_params *params)
9327{
9328 struct bnx2x *bp = params->bp;
9329 u16 mod_abs, rx_alarm_status;
9330 u32 val = REG_RD(bp, params->shmem_base +
9331 offsetof(struct shmem_region, dev_info.
9332 port_feature_config[params->port].
9333 config));
9334 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00009335 MDIO_PMA_DEVAD,
9336 MDIO_PMA_REG_PHY_IDENTIFIER, &mod_abs);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009337 if (mod_abs & (1<<8)) {
9338
9339 /* Module is absent */
Joe Perches94f05b02011-08-14 12:16:20 +00009340 DP(NETIF_MSG_LINK,
9341 "MOD_ABS indication show module is absent\n");
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00009342 phy->media_type = ETH_PHY_NOT_PRESENT;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00009343 /* 1. Set mod_abs to detect next module
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00009344 * presence event
9345 * 2. Set EDC off by setting OPTXLOS signal input to low
9346 * (bit 9).
9347 * When the EDC is off it locks onto a reference clock and
9348 * avoids becoming 'lost'.
9349 */
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00009350 mod_abs &= ~(1<<8);
9351 if (!(phy->flags & FLAGS_NOC))
9352 mod_abs &= ~(1<<9);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009353 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00009354 MDIO_PMA_DEVAD,
9355 MDIO_PMA_REG_PHY_IDENTIFIER, mod_abs);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009356
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00009357 /* Clear RX alarm since it stays up as long as
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00009358 * the mod_abs wasn't changed
9359 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009360 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00009361 MDIO_PMA_DEVAD,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009362 MDIO_PMA_LASI_RXSTAT, &rx_alarm_status);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009363
9364 } else {
9365 /* Module is present */
Joe Perches94f05b02011-08-14 12:16:20 +00009366 DP(NETIF_MSG_LINK,
9367 "MOD_ABS indication show module is present\n");
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00009368 /* First disable transmitter, and if the module is ok, the
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00009369 * module_detection will enable it
9370 * 1. Set mod_abs to detect next module absent event ( bit 8)
9371 * 2. Restore the default polarity of the OPRXLOS signal and
9372 * this signal will then correctly indicate the presence or
9373 * absence of the Rx signal. (bit 9)
9374 */
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00009375 mod_abs |= (1<<8);
9376 if (!(phy->flags & FLAGS_NOC))
9377 mod_abs |= (1<<9);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009378 bnx2x_cl45_write(bp, phy,
9379 MDIO_PMA_DEVAD,
9380 MDIO_PMA_REG_PHY_IDENTIFIER, mod_abs);
9381
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00009382 /* Clear RX alarm since it stays up as long as the mod_abs
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00009383 * wasn't changed. This is need to be done before calling the
9384 * module detection, otherwise it will clear* the link update
9385 * alarm
9386 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009387 bnx2x_cl45_read(bp, phy,
9388 MDIO_PMA_DEVAD,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009389 MDIO_PMA_LASI_RXSTAT, &rx_alarm_status);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009390
9391
9392 if ((val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) ==
9393 PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_DISABLE_TX_LASER)
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00009394 bnx2x_sfp_set_transmitter(params, phy, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009395
9396 if (bnx2x_wait_for_sfp_module_initialized(phy, params) == 0)
9397 bnx2x_sfp_module_detection(phy, params);
9398 else
9399 DP(NETIF_MSG_LINK, "SFP+ module is not initialized\n");
Yuval Mintzdbef8072012-06-20 19:05:22 +00009400
9401 /* Reconfigure link speed based on module type limitations */
9402 bnx2x_8727_config_speed(phy, params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009403 }
9404
9405 DP(NETIF_MSG_LINK, "8727 RX_ALARM_STATUS 0x%x\n",
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00009406 rx_alarm_status);
9407 /* No need to check link status in case of module plugged in/out */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009408}
9409
9410static u8 bnx2x_8727_read_status(struct bnx2x_phy *phy,
9411 struct link_params *params,
9412 struct link_vars *vars)
9413
9414{
9415 struct bnx2x *bp = params->bp;
Yaniv Rosner27d02432011-05-31 21:27:48 +00009416 u8 link_up = 0, oc_port = params->port;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009417 u16 link_status = 0;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00009418 u16 rx_alarm_status, lasi_ctrl, val1;
9419
9420 /* If PHY is not initialized, do not check link status */
9421 bnx2x_cl45_read(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009422 MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00009423 &lasi_ctrl);
9424 if (!lasi_ctrl)
9425 return 0;
9426
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00009427 /* Check the LASI on Rx */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009428 bnx2x_cl45_read(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009429 MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXSTAT,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009430 &rx_alarm_status);
9431 vars->line_speed = 0;
9432 DP(NETIF_MSG_LINK, "8727 RX_ALARM_STATUS 0x%x\n", rx_alarm_status);
9433
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009434 bnx2x_sfp_mask_fault(bp, phy, MDIO_PMA_LASI_TXSTAT,
9435 MDIO_PMA_LASI_TXCTRL);
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00009436
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009437 bnx2x_cl45_read(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009438 MDIO_PMA_DEVAD, MDIO_PMA_LASI_STAT, &val1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009439
9440 DP(NETIF_MSG_LINK, "8727 LASI status 0x%x\n", val1);
9441
9442 /* Clear MSG-OUT */
9443 bnx2x_cl45_read(bp, phy,
9444 MDIO_PMA_DEVAD, MDIO_PMA_REG_M8051_MSGOUT_REG, &val1);
9445
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00009446 /* If a module is present and there is need to check
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009447 * for over current
9448 */
9449 if (!(phy->flags & FLAGS_NOC) && !(rx_alarm_status & (1<<5))) {
9450 /* Check over-current using 8727 GPIO0 input*/
9451 bnx2x_cl45_read(bp, phy,
9452 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_GPIO_CTRL,
9453 &val1);
9454
9455 if ((val1 & (1<<8)) == 0) {
Yaniv Rosner27d02432011-05-31 21:27:48 +00009456 if (!CHIP_IS_E1x(bp))
9457 oc_port = BP_PATH(bp) + (params->port << 1);
Joe Perches94f05b02011-08-14 12:16:20 +00009458 DP(NETIF_MSG_LINK,
9459 "8727 Power fault has been detected on port %d\n",
9460 oc_port);
Yaniv Rosner2f751a82011-11-28 00:49:52 +00009461 netdev_err(bp->dev, "Error: Power fault on Port %d has "
9462 "been detected and the power to "
9463 "that SFP+ module has been removed "
9464 "to prevent failure of the card. "
9465 "Please remove the SFP+ module and "
9466 "restart the system to clear this "
9467 "error.\n",
Yaniv Rosner27d02432011-05-31 21:27:48 +00009468 oc_port);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00009469 /* Disable all RX_ALARMs except for mod_abs */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009470 bnx2x_cl45_write(bp, phy,
9471 MDIO_PMA_DEVAD,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009472 MDIO_PMA_LASI_RXCTRL, (1<<5));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009473
9474 bnx2x_cl45_read(bp, phy,
9475 MDIO_PMA_DEVAD,
9476 MDIO_PMA_REG_PHY_IDENTIFIER, &val1);
9477 /* Wait for module_absent_event */
9478 val1 |= (1<<8);
9479 bnx2x_cl45_write(bp, phy,
9480 MDIO_PMA_DEVAD,
9481 MDIO_PMA_REG_PHY_IDENTIFIER, val1);
9482 /* Clear RX alarm */
9483 bnx2x_cl45_read(bp, phy,
9484 MDIO_PMA_DEVAD,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009485 MDIO_PMA_LASI_RXSTAT, &rx_alarm_status);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009486 return 0;
9487 }
9488 } /* Over current check */
9489
9490 /* When module absent bit is set, check module */
9491 if (rx_alarm_status & (1<<5)) {
9492 bnx2x_8727_handle_mod_abs(phy, params);
9493 /* Enable all mod_abs and link detection bits */
9494 bnx2x_cl45_write(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009495 MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXCTRL,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009496 ((1<<5) | (1<<2)));
9497 }
Yaniv Rosner59a2e532012-04-04 01:28:59 +00009498
9499 if (!(phy->flags & FLAGS_SFP_NOT_APPROVED)) {
9500 DP(NETIF_MSG_LINK, "Enabling 8727 TX laser\n");
9501 bnx2x_sfp_set_transmitter(params, phy, 1);
9502 } else {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009503 DP(NETIF_MSG_LINK, "Tx is disabled\n");
9504 return 0;
9505 }
9506
9507 bnx2x_cl45_read(bp, phy,
9508 MDIO_PMA_DEVAD,
9509 MDIO_PMA_REG_8073_SPEED_LINK_STATUS, &link_status);
9510
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00009511 /* Bits 0..2 --> speed detected,
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00009512 * Bits 13..15--> link is down
9513 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009514 if ((link_status & (1<<2)) && (!(link_status & (1<<15)))) {
9515 link_up = 1;
9516 vars->line_speed = SPEED_10000;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00009517 DP(NETIF_MSG_LINK, "port %x: External link up in 10G\n",
9518 params->port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009519 } else if ((link_status & (1<<0)) && (!(link_status & (1<<13)))) {
9520 link_up = 1;
9521 vars->line_speed = SPEED_1000;
9522 DP(NETIF_MSG_LINK, "port %x: External link up in 1G\n",
9523 params->port);
9524 } else {
9525 link_up = 0;
9526 DP(NETIF_MSG_LINK, "port %x: External link is down\n",
9527 params->port);
9528 }
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00009529
9530 /* Capture 10G link fault. */
9531 if (vars->line_speed == SPEED_10000) {
9532 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009533 MDIO_PMA_LASI_TXSTAT, &val1);
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00009534
9535 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009536 MDIO_PMA_LASI_TXSTAT, &val1);
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00009537
9538 if (val1 & (1<<0)) {
9539 vars->fault_detected = 1;
9540 }
9541 }
9542
Yaniv Rosner791f18c2011-01-18 04:33:42 +00009543 if (link_up) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009544 bnx2x_ext_phy_resolve_fc(phy, params, vars);
Yaniv Rosner791f18c2011-01-18 04:33:42 +00009545 vars->duplex = DUPLEX_FULL;
9546 DP(NETIF_MSG_LINK, "duplex = 0x%x\n", vars->duplex);
9547 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +00009548
9549 if ((DUAL_MEDIA(params)) &&
9550 (phy->req_line_speed == SPEED_1000)) {
9551 bnx2x_cl45_read(bp, phy,
9552 MDIO_PMA_DEVAD,
9553 MDIO_PMA_REG_8727_PCS_GP, &val1);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00009554 /* In case of dual-media board and 1G, power up the XAUI side,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00009555 * otherwise power it down. For 10G it is done automatically
9556 */
9557 if (link_up)
9558 val1 &= ~(3<<10);
9559 else
9560 val1 |= (3<<10);
9561 bnx2x_cl45_write(bp, phy,
9562 MDIO_PMA_DEVAD,
9563 MDIO_PMA_REG_8727_PCS_GP, val1);
9564 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009565 return link_up;
9566}
9567
9568static void bnx2x_8727_link_reset(struct bnx2x_phy *phy,
9569 struct link_params *params)
9570{
9571 struct bnx2x *bp = params->bp;
Yaniv Rosner85242ee2011-07-05 01:06:53 +00009572
9573 /* Enable/Disable PHY transmitter output */
9574 bnx2x_set_disable_pmd_transmit(params, phy, 1);
9575
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009576 /* Disable Transmitter */
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00009577 bnx2x_sfp_set_transmitter(params, phy, 0);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00009578 /* Clear LASI */
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009579 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL, 0);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00009580
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009581}
9582
9583/******************************************************************/
9584/* BCM8481/BCM84823/BCM84833 PHY SECTION */
9585/******************************************************************/
9586static void bnx2x_save_848xx_spirom_version(struct bnx2x_phy *phy,
Yaniv Rosner11b2ec62012-01-17 02:33:25 +00009587 struct bnx2x *bp,
9588 u8 port)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009589{
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009590 u16 val, fw_ver1, fw_ver2, cnt;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009591
Yaniv Rosner11b2ec62012-01-17 02:33:25 +00009592 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833) {
9593 bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD, 0x400f, &fw_ver1);
Yaniv Rosner8267bbb02012-04-04 01:29:00 +00009594 bnx2x_save_spirom_version(bp, port, fw_ver1 & 0xfff,
Yaniv Rosner11b2ec62012-01-17 02:33:25 +00009595 phy->ver_addr);
9596 } else {
9597 /* For 32-bit registers in 848xx, access via MDIO2ARM i/f. */
9598 /* (1) set reg 0xc200_0014(SPI_BRIDGE_CTRL_2) to 0x03000000 */
9599 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA819, 0x0014);
9600 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA81A, 0xc200);
9601 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA81B, 0x0000);
9602 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA81C, 0x0300);
9603 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA817, 0x0009);
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00009604
Yaniv Rosner11b2ec62012-01-17 02:33:25 +00009605 for (cnt = 0; cnt < 100; cnt++) {
9606 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD, 0xA818, &val);
9607 if (val & 1)
9608 break;
9609 udelay(5);
9610 }
9611 if (cnt == 100) {
9612 DP(NETIF_MSG_LINK, "Unable to read 848xx "
9613 "phy fw version(1)\n");
9614 bnx2x_save_spirom_version(bp, port, 0,
9615 phy->ver_addr);
9616 return;
9617 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009618
Yaniv Rosner11b2ec62012-01-17 02:33:25 +00009619
9620 /* 2) read register 0xc200_0000 (SPI_FW_STATUS) */
9621 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA819, 0x0000);
9622 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA81A, 0xc200);
9623 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA817, 0x000A);
9624 for (cnt = 0; cnt < 100; cnt++) {
9625 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD, 0xA818, &val);
9626 if (val & 1)
9627 break;
9628 udelay(5);
9629 }
9630 if (cnt == 100) {
9631 DP(NETIF_MSG_LINK, "Unable to read 848xx phy fw "
9632 "version(2)\n");
9633 bnx2x_save_spirom_version(bp, port, 0,
9634 phy->ver_addr);
9635 return;
9636 }
9637
9638 /* lower 16 bits of the register SPI_FW_STATUS */
9639 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD, 0xA81B, &fw_ver1);
9640 /* upper 16 bits of register SPI_FW_STATUS */
9641 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD, 0xA81C, &fw_ver2);
9642
9643 bnx2x_save_spirom_version(bp, port, (fw_ver2<<16) | fw_ver1,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009644 phy->ver_addr);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009645 }
9646
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009647}
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009648static void bnx2x_848xx_set_led(struct bnx2x *bp,
9649 struct bnx2x_phy *phy)
9650{
Yaniv Rosner521683d2011-11-28 00:49:48 +00009651 u16 val, offset;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009652
9653 /* PHYC_CTL_LED_CTL */
9654 bnx2x_cl45_read(bp, phy,
9655 MDIO_PMA_DEVAD,
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009656 MDIO_PMA_REG_8481_LINK_SIGNAL, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009657 val &= 0xFE00;
9658 val |= 0x0092;
9659
9660 bnx2x_cl45_write(bp, phy,
9661 MDIO_PMA_DEVAD,
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009662 MDIO_PMA_REG_8481_LINK_SIGNAL, val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009663
9664 bnx2x_cl45_write(bp, phy,
9665 MDIO_PMA_DEVAD,
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009666 MDIO_PMA_REG_8481_LED1_MASK,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009667 0x80);
9668
9669 bnx2x_cl45_write(bp, phy,
9670 MDIO_PMA_DEVAD,
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009671 MDIO_PMA_REG_8481_LED2_MASK,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009672 0x18);
9673
Yaniv Rosnerf25b3c82011-01-18 04:33:47 +00009674 /* Select activity source by Tx and Rx, as suggested by PHY AE */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009675 bnx2x_cl45_write(bp, phy,
9676 MDIO_PMA_DEVAD,
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009677 MDIO_PMA_REG_8481_LED3_MASK,
Yaniv Rosnerf25b3c82011-01-18 04:33:47 +00009678 0x0006);
9679
9680 /* Select the closest activity blink rate to that in 10/100/1000 */
9681 bnx2x_cl45_write(bp, phy,
9682 MDIO_PMA_DEVAD,
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009683 MDIO_PMA_REG_8481_LED3_BLINK,
Yaniv Rosnerf25b3c82011-01-18 04:33:47 +00009684 0);
9685
Yaniv Rosner521683d2011-11-28 00:49:48 +00009686 /* Configure the blink rate to ~15.9 Hz */
Yaniv Rosnerf25b3c82011-01-18 04:33:47 +00009687 bnx2x_cl45_write(bp, phy,
Yaniv Rosner521683d2011-11-28 00:49:48 +00009688 MDIO_PMA_DEVAD,
9689 MDIO_PMA_REG_84823_CTL_SLOW_CLK_CNT_HIGH,
9690 MDIO_PMA_REG_84823_BLINK_RATE_VAL_15P9HZ);
9691
9692 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
9693 offset = MDIO_PMA_REG_84833_CTL_LED_CTL_1;
9694 else
9695 offset = MDIO_PMA_REG_84823_CTL_LED_CTL_1;
9696
9697 bnx2x_cl45_read(bp, phy,
9698 MDIO_PMA_DEVAD, offset, &val);
9699 val |= MDIO_PMA_REG_84823_LED3_STRETCH_EN; /* stretch_en for LED3*/
9700 bnx2x_cl45_write(bp, phy,
9701 MDIO_PMA_DEVAD, offset, val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009702
9703 /* 'Interrupt Mask' */
9704 bnx2x_cl45_write(bp, phy,
9705 MDIO_AN_DEVAD,
9706 0xFFFB, 0xFFFD);
9707}
9708
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00009709static int bnx2x_848xx_cmn_config_init(struct bnx2x_phy *phy,
9710 struct link_params *params,
9711 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009712{
9713 struct bnx2x *bp = params->bp;
Yaniv Rosner521683d2011-11-28 00:49:48 +00009714 u16 autoneg_val, an_1000_val, an_10_100_val, an_10g_val;
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009715
Mintz Yuval817a8aa2012-02-15 02:10:26 +00009716 if (phy->type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833) {
Yaniv Rosner11b2ec62012-01-17 02:33:25 +00009717 /* Save spirom version */
9718 bnx2x_save_848xx_spirom_version(phy, bp, params->port);
9719 }
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00009720 /* This phy uses the NIG latch mechanism since link indication
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00009721 * arrives through its LED4 and not via its LASI signal, so we
9722 * get steady signal instead of clear on read
9723 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009724 bnx2x_bits_en(bp, NIG_REG_LATCH_BC_0 + params->port*4,
9725 1 << NIG_LATCH_BC_ENABLE_MI_INT);
9726
9727 bnx2x_cl45_write(bp, phy,
9728 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x0000);
9729
9730 bnx2x_848xx_set_led(bp, phy);
9731
9732 /* set 1000 speed advertisement */
9733 bnx2x_cl45_read(bp, phy,
9734 MDIO_AN_DEVAD, MDIO_AN_REG_8481_1000T_CTRL,
9735 &an_1000_val);
9736
9737 bnx2x_ext_phy_set_pause(params, phy, vars);
9738 bnx2x_cl45_read(bp, phy,
9739 MDIO_AN_DEVAD,
9740 MDIO_AN_REG_8481_LEGACY_AN_ADV,
9741 &an_10_100_val);
9742 bnx2x_cl45_read(bp, phy,
9743 MDIO_AN_DEVAD, MDIO_AN_REG_8481_LEGACY_MII_CTRL,
9744 &autoneg_val);
9745 /* Disable forced speed */
9746 autoneg_val &= ~((1<<6) | (1<<8) | (1<<9) | (1<<12) | (1<<13));
9747 an_10_100_val &= ~((1<<5) | (1<<6) | (1<<7) | (1<<8));
9748
9749 if (((phy->req_line_speed == SPEED_AUTO_NEG) &&
9750 (phy->speed_cap_mask &
9751 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) ||
9752 (phy->req_line_speed == SPEED_1000)) {
9753 an_1000_val |= (1<<8);
9754 autoneg_val |= (1<<9 | 1<<12);
9755 if (phy->req_duplex == DUPLEX_FULL)
9756 an_1000_val |= (1<<9);
9757 DP(NETIF_MSG_LINK, "Advertising 1G\n");
9758 } else
9759 an_1000_val &= ~((1<<8) | (1<<9));
9760
9761 bnx2x_cl45_write(bp, phy,
9762 MDIO_AN_DEVAD, MDIO_AN_REG_8481_1000T_CTRL,
9763 an_1000_val);
9764
Yaniv Rosner0520e632011-07-05 01:06:59 +00009765 /* set 100 speed advertisement */
Yaniv Rosner75318322012-01-17 02:33:27 +00009766 if ((phy->req_line_speed == SPEED_AUTO_NEG) &&
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009767 (phy->speed_cap_mask &
Yaniv Rosner0520e632011-07-05 01:06:59 +00009768 (PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL |
Yaniv Rosner75318322012-01-17 02:33:27 +00009769 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009770 an_10_100_val |= (1<<7);
9771 /* Enable autoneg and restart autoneg for legacy speeds */
9772 autoneg_val |= (1<<9 | 1<<12);
9773
9774 if (phy->req_duplex == DUPLEX_FULL)
9775 an_10_100_val |= (1<<8);
9776 DP(NETIF_MSG_LINK, "Advertising 100M\n");
9777 }
9778 /* set 10 speed advertisement */
9779 if (((phy->req_line_speed == SPEED_AUTO_NEG) &&
Yaniv Rosner0520e632011-07-05 01:06:59 +00009780 (phy->speed_cap_mask &
9781 (PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL |
9782 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF)) &&
9783 (phy->supported &
9784 (SUPPORTED_10baseT_Half |
9785 SUPPORTED_10baseT_Full)))) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009786 an_10_100_val |= (1<<5);
9787 autoneg_val |= (1<<9 | 1<<12);
9788 if (phy->req_duplex == DUPLEX_FULL)
9789 an_10_100_val |= (1<<6);
9790 DP(NETIF_MSG_LINK, "Advertising 10M\n");
9791 }
9792
9793 /* Only 10/100 are allowed to work in FORCE mode */
Yaniv Rosner0520e632011-07-05 01:06:59 +00009794 if ((phy->req_line_speed == SPEED_100) &&
9795 (phy->supported &
9796 (SUPPORTED_100baseT_Half |
9797 SUPPORTED_100baseT_Full))) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009798 autoneg_val |= (1<<13);
9799 /* Enabled AUTO-MDIX when autoneg is disabled */
9800 bnx2x_cl45_write(bp, phy,
9801 MDIO_AN_DEVAD, MDIO_AN_REG_8481_AUX_CTRL,
9802 (1<<15 | 1<<9 | 7<<0));
Yaniv Rosner521683d2011-11-28 00:49:48 +00009803 /* The PHY needs this set even for forced link. */
9804 an_10_100_val |= (1<<8) | (1<<7);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009805 DP(NETIF_MSG_LINK, "Setting 100M force\n");
9806 }
Yaniv Rosner0520e632011-07-05 01:06:59 +00009807 if ((phy->req_line_speed == SPEED_10) &&
9808 (phy->supported &
9809 (SUPPORTED_10baseT_Half |
9810 SUPPORTED_10baseT_Full))) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009811 /* Enabled AUTO-MDIX when autoneg is disabled */
9812 bnx2x_cl45_write(bp, phy,
9813 MDIO_AN_DEVAD, MDIO_AN_REG_8481_AUX_CTRL,
9814 (1<<15 | 1<<9 | 7<<0));
9815 DP(NETIF_MSG_LINK, "Setting 10M force\n");
9816 }
9817
9818 bnx2x_cl45_write(bp, phy,
9819 MDIO_AN_DEVAD, MDIO_AN_REG_8481_LEGACY_AN_ADV,
9820 an_10_100_val);
9821
9822 if (phy->req_duplex == DUPLEX_FULL)
9823 autoneg_val |= (1<<8);
9824
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00009825 /* Always write this if this is not 84833.
Yaniv Rosnerfd38f73e2011-08-02 22:59:53 +00009826 * For 84833, write it only when it's a forced speed.
9827 */
9828 if ((phy->type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833) ||
9829 ((autoneg_val & (1<<12)) == 0))
9830 bnx2x_cl45_write(bp, phy,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009831 MDIO_AN_DEVAD,
9832 MDIO_AN_REG_8481_LEGACY_MII_CTRL, autoneg_val);
9833
9834 if (((phy->req_line_speed == SPEED_AUTO_NEG) &&
9835 (phy->speed_cap_mask &
9836 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) ||
9837 (phy->req_line_speed == SPEED_10000)) {
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00009838 DP(NETIF_MSG_LINK, "Advertising 10G\n");
9839 /* Restart autoneg for 10G*/
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009840
Yaniv Rosner521683d2011-11-28 00:49:48 +00009841 bnx2x_cl45_read(bp, phy,
9842 MDIO_AN_DEVAD,
9843 MDIO_AN_REG_8481_10GBASE_T_AN_CTRL,
9844 &an_10g_val);
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00009845 bnx2x_cl45_write(bp, phy,
Yaniv Rosner521683d2011-11-28 00:49:48 +00009846 MDIO_AN_DEVAD,
9847 MDIO_AN_REG_8481_10GBASE_T_AN_CTRL,
9848 an_10g_val | 0x1000);
9849 bnx2x_cl45_write(bp, phy,
9850 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL,
9851 0x3200);
Yaniv Rosnerfd38f73e2011-08-02 22:59:53 +00009852 } else
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009853 bnx2x_cl45_write(bp, phy,
9854 MDIO_AN_DEVAD,
9855 MDIO_AN_REG_8481_10GBASE_T_AN_CTRL,
9856 1);
Yaniv Rosnerfd38f73e2011-08-02 22:59:53 +00009857
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009858 return 0;
9859}
9860
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00009861static int bnx2x_8481_config_init(struct bnx2x_phy *phy,
9862 struct link_params *params,
9863 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009864{
9865 struct bnx2x *bp = params->bp;
9866 /* Restore normal power mode*/
9867 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00009868 MISC_REGISTERS_GPIO_OUTPUT_HIGH, params->port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009869
9870 /* HW reset */
9871 bnx2x_ext_phy_hw_reset(bp, params->port);
Yaniv Rosner6d870c32011-01-31 04:22:20 +00009872 bnx2x_wait_reset_complete(bp, phy, params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009873
9874 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 1<<15);
9875 return bnx2x_848xx_cmn_config_init(phy, params, vars);
9876}
9877
Yaniv Rosner521683d2011-11-28 00:49:48 +00009878#define PHY84833_CMDHDLR_WAIT 300
9879#define PHY84833_CMDHDLR_MAX_ARGS 5
9880static int bnx2x_84833_cmd_hdlr(struct bnx2x_phy *phy,
9881 struct link_params *params,
9882 u16 fw_cmd,
Yuval Mintzc8c60d82012-06-06 17:13:07 +00009883 u16 cmd_args[], int argc)
Yaniv Rosner521683d2011-11-28 00:49:48 +00009884{
Yuval Mintzc8c60d82012-06-06 17:13:07 +00009885 int idx;
Yaniv Rosner521683d2011-11-28 00:49:48 +00009886 u16 val;
9887 struct bnx2x *bp = params->bp;
9888 /* Write CMD_OPEN_OVERRIDE to STATUS reg */
9889 bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
9890 MDIO_84833_CMD_HDLR_STATUS,
9891 PHY84833_STATUS_CMD_OPEN_OVERRIDE);
9892 for (idx = 0; idx < PHY84833_CMDHDLR_WAIT; idx++) {
9893 bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD,
9894 MDIO_84833_CMD_HDLR_STATUS, &val);
9895 if (val == PHY84833_STATUS_CMD_OPEN_FOR_CMDS)
9896 break;
Yuval Mintzd2310232012-06-20 19:05:19 +00009897 usleep_range(1000, 2000);
Yaniv Rosner521683d2011-11-28 00:49:48 +00009898 }
9899 if (idx >= PHY84833_CMDHDLR_WAIT) {
9900 DP(NETIF_MSG_LINK, "FW cmd: FW not ready.\n");
9901 return -EINVAL;
9902 }
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009903
Yaniv Rosner521683d2011-11-28 00:49:48 +00009904 /* Prepare argument(s) and issue command */
Yuval Mintzc8c60d82012-06-06 17:13:07 +00009905 for (idx = 0; idx < argc; idx++) {
Yaniv Rosner521683d2011-11-28 00:49:48 +00009906 bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
9907 MDIO_84833_CMD_HDLR_DATA1 + idx,
9908 cmd_args[idx]);
9909 }
9910 bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
9911 MDIO_84833_CMD_HDLR_COMMAND, fw_cmd);
9912 for (idx = 0; idx < PHY84833_CMDHDLR_WAIT; idx++) {
9913 bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD,
9914 MDIO_84833_CMD_HDLR_STATUS, &val);
9915 if ((val == PHY84833_STATUS_CMD_COMPLETE_PASS) ||
9916 (val == PHY84833_STATUS_CMD_COMPLETE_ERROR))
9917 break;
Yuval Mintzd2310232012-06-20 19:05:19 +00009918 usleep_range(1000, 2000);
Yaniv Rosner521683d2011-11-28 00:49:48 +00009919 }
9920 if ((idx >= PHY84833_CMDHDLR_WAIT) ||
9921 (val == PHY84833_STATUS_CMD_COMPLETE_ERROR)) {
9922 DP(NETIF_MSG_LINK, "FW cmd failed.\n");
9923 return -EINVAL;
9924 }
9925 /* Gather returning data */
Yuval Mintzc8c60d82012-06-06 17:13:07 +00009926 for (idx = 0; idx < argc; idx++) {
Yaniv Rosner521683d2011-11-28 00:49:48 +00009927 bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD,
9928 MDIO_84833_CMD_HDLR_DATA1 + idx,
9929 &cmd_args[idx]);
9930 }
9931 bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
9932 MDIO_84833_CMD_HDLR_STATUS,
9933 PHY84833_STATUS_CMD_CLEAR_COMPLETE);
9934 return 0;
9935}
9936
9937
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009938static int bnx2x_84833_pair_swap_cfg(struct bnx2x_phy *phy,
9939 struct link_params *params,
9940 struct link_vars *vars)
9941{
Yaniv Rosner0520e632011-07-05 01:06:59 +00009942 u32 pair_swap;
Yaniv Rosner521683d2011-11-28 00:49:48 +00009943 u16 data[PHY84833_CMDHDLR_MAX_ARGS];
9944 int status;
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009945 struct bnx2x *bp = params->bp;
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009946
Yaniv Rosner0520e632011-07-05 01:06:59 +00009947 /* Check for configuration. */
9948 pair_swap = REG_RD(bp, params->shmem_base +
9949 offsetof(struct shmem_region,
9950 dev_info.port_hw_config[params->port].xgbt_phy_cfg)) &
9951 PORT_HW_CFG_RJ45_PAIR_SWAP_MASK;
9952
9953 if (pair_swap == 0)
9954 return 0;
9955
Yaniv Rosner521683d2011-11-28 00:49:48 +00009956 /* Only the second argument is used for this command */
9957 data[1] = (u16)pair_swap;
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009958
Yaniv Rosner521683d2011-11-28 00:49:48 +00009959 status = bnx2x_84833_cmd_hdlr(phy, params,
Yuval Mintzc8c60d82012-06-06 17:13:07 +00009960 PHY84833_CMD_SET_PAIR_SWAP, data, PHY84833_CMDHDLR_MAX_ARGS);
Yaniv Rosner521683d2011-11-28 00:49:48 +00009961 if (status == 0)
9962 DP(NETIF_MSG_LINK, "Pairswap OK, val=0x%x\n", data[1]);
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009963
Yaniv Rosner521683d2011-11-28 00:49:48 +00009964 return status;
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009965}
9966
Yaniv Rosner985848f2011-07-05 01:06:48 +00009967static u8 bnx2x_84833_get_reset_gpios(struct bnx2x *bp,
9968 u32 shmem_base_path[],
9969 u32 chip_id)
Yaniv Rosner0d40f0d2011-06-14 01:34:27 +00009970{
9971 u32 reset_pin[2];
9972 u32 idx;
9973 u8 reset_gpios;
9974 if (CHIP_IS_E3(bp)) {
9975 /* Assume that these will be GPIOs, not EPIOs. */
9976 for (idx = 0; idx < 2; idx++) {
9977 /* Map config param to register bit. */
9978 reset_pin[idx] = REG_RD(bp, shmem_base_path[idx] +
9979 offsetof(struct shmem_region,
9980 dev_info.port_hw_config[0].e3_cmn_pin_cfg));
9981 reset_pin[idx] = (reset_pin[idx] &
9982 PORT_HW_CFG_E3_PHY_RESET_MASK) >>
9983 PORT_HW_CFG_E3_PHY_RESET_SHIFT;
9984 reset_pin[idx] -= PIN_CFG_GPIO0_P0;
9985 reset_pin[idx] = (1 << reset_pin[idx]);
9986 }
9987 reset_gpios = (u8)(reset_pin[0] | reset_pin[1]);
9988 } else {
9989 /* E2, look from diff place of shmem. */
9990 for (idx = 0; idx < 2; idx++) {
9991 reset_pin[idx] = REG_RD(bp, shmem_base_path[idx] +
9992 offsetof(struct shmem_region,
9993 dev_info.port_hw_config[0].default_cfg));
9994 reset_pin[idx] &= PORT_HW_CFG_EXT_PHY_GPIO_RST_MASK;
9995 reset_pin[idx] -= PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO0_P0;
9996 reset_pin[idx] >>= PORT_HW_CFG_EXT_PHY_GPIO_RST_SHIFT;
9997 reset_pin[idx] = (1 << reset_pin[idx]);
9998 }
9999 reset_gpios = (u8)(reset_pin[0] | reset_pin[1]);
10000 }
10001
Yaniv Rosner985848f2011-07-05 01:06:48 +000010002 return reset_gpios;
10003}
10004
10005static int bnx2x_84833_hw_reset_phy(struct bnx2x_phy *phy,
10006 struct link_params *params)
10007{
10008 struct bnx2x *bp = params->bp;
10009 u8 reset_gpios;
10010 u32 other_shmem_base_addr = REG_RD(bp, params->shmem2_base +
10011 offsetof(struct shmem2_region,
10012 other_shmem_base_addr));
10013
10014 u32 shmem_base_path[2];
Yaniv Rosner99bf7f32012-04-04 01:29:01 +000010015
10016 /* Work around for 84833 LED failure inside RESET status */
10017 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
10018 MDIO_AN_REG_8481_LEGACY_MII_CTRL,
10019 MDIO_AN_REG_8481_MII_CTRL_FORCE_1G);
10020 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
10021 MDIO_AN_REG_8481_1G_100T_EXT_CTRL,
10022 MIDO_AN_REG_8481_EXT_CTRL_FORCE_LEDS_OFF);
10023
Yaniv Rosner985848f2011-07-05 01:06:48 +000010024 shmem_base_path[0] = params->shmem_base;
10025 shmem_base_path[1] = other_shmem_base_addr;
10026
10027 reset_gpios = bnx2x_84833_get_reset_gpios(bp, shmem_base_path,
10028 params->chip_id);
10029
10030 bnx2x_set_mult_gpio(bp, reset_gpios, MISC_REGISTERS_GPIO_OUTPUT_LOW);
10031 udelay(10);
10032 DP(NETIF_MSG_LINK, "84833 hw reset on pin values 0x%x\n",
10033 reset_gpios);
10034
10035 return 0;
10036}
10037
Yuval Mintzc8c60d82012-06-06 17:13:07 +000010038static int bnx2x_8483x_disable_eee(struct bnx2x_phy *phy,
10039 struct link_params *params,
10040 struct link_vars *vars)
10041{
10042 int rc;
10043 struct bnx2x *bp = params->bp;
10044 u16 cmd_args = 0;
10045
10046 DP(NETIF_MSG_LINK, "Don't Advertise 10GBase-T EEE\n");
10047
Yuval Mintzc8c60d82012-06-06 17:13:07 +000010048 /* Prevent Phy from working in EEE and advertising it */
10049 rc = bnx2x_84833_cmd_hdlr(phy, params,
10050 PHY84833_CMD_SET_EEE_MODE, &cmd_args, 1);
Yuval Mintzd2310232012-06-20 19:05:19 +000010051 if (rc) {
Yuval Mintzc8c60d82012-06-06 17:13:07 +000010052 DP(NETIF_MSG_LINK, "EEE disable failed.\n");
10053 return rc;
10054 }
10055
Yuval Mintzec4010e2012-09-10 05:51:06 +000010056 return bnx2x_eee_disable(phy, params, vars);
Yuval Mintzc8c60d82012-06-06 17:13:07 +000010057}
10058
10059static int bnx2x_8483x_enable_eee(struct bnx2x_phy *phy,
10060 struct link_params *params,
10061 struct link_vars *vars)
10062{
10063 int rc;
10064 struct bnx2x *bp = params->bp;
10065 u16 cmd_args = 1;
10066
Yuval Mintzc8c60d82012-06-06 17:13:07 +000010067 rc = bnx2x_84833_cmd_hdlr(phy, params,
10068 PHY84833_CMD_SET_EEE_MODE, &cmd_args, 1);
Yuval Mintzd2310232012-06-20 19:05:19 +000010069 if (rc) {
Yuval Mintzc8c60d82012-06-06 17:13:07 +000010070 DP(NETIF_MSG_LINK, "EEE enable failed.\n");
10071 return rc;
10072 }
10073
Yuval Mintzec4010e2012-09-10 05:51:06 +000010074 return bnx2x_eee_advertise(phy, params, vars, SHMEM_EEE_10G_ADV);
Yuval Mintzc8c60d82012-06-06 17:13:07 +000010075}
10076
Yaniv Rosnera89a1d42011-07-05 01:07:05 +000010077#define PHY84833_CONSTANT_LATENCY 1193
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000010078static int bnx2x_848x3_config_init(struct bnx2x_phy *phy,
10079 struct link_params *params,
10080 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010081{
10082 struct bnx2x *bp = params->bp;
Yaniv Rosner6a71bbe2010-11-01 05:32:31 +000010083 u8 port, initialize = 1;
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010084 u16 val;
Yaniv Rosner521683d2011-11-28 00:49:48 +000010085 u32 actual_phy_selection, cms_enable;
10086 u16 cmd_args[PHY84833_CMDHDLR_MAX_ARGS];
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000010087 int rc = 0;
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010088
Yuval Mintzd2310232012-06-20 19:05:19 +000010089 usleep_range(1000, 2000);
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010090
Yuval Mintz54813882012-06-16 20:27:15 +000010091 if (!(CHIP_IS_E1x(bp)))
Yaniv Rosner6a71bbe2010-11-01 05:32:31 +000010092 port = BP_PATH(bp);
10093 else
10094 port = params->port;
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010095
10096 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84823) {
10097 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_3,
10098 MISC_REGISTERS_GPIO_OUTPUT_HIGH,
10099 port);
10100 } else {
Yaniv Rosner985848f2011-07-05 01:06:48 +000010101 /* MDIO reset */
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010102 bnx2x_cl45_write(bp, phy,
10103 MDIO_PMA_DEVAD,
10104 MDIO_PMA_REG_CTRL, 0x8000);
Yaniv Rosner521683d2011-11-28 00:49:48 +000010105 }
10106
10107 bnx2x_wait_reset_complete(bp, phy, params);
10108
10109 /* Wait for GPHY to come out of reset */
10110 msleep(50);
Yaniv Rosner11b2ec62012-01-17 02:33:25 +000010111 if (phy->type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833) {
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000010112 /* BCM84823 requires that XGXS links up first @ 10G for normal
Yaniv Rosner521683d2011-11-28 00:49:48 +000010113 * behavior.
10114 */
10115 u16 temp;
10116 temp = vars->line_speed;
10117 vars->line_speed = SPEED_10000;
10118 bnx2x_set_autoneg(&params->phy[INT_PHY], params, vars, 0);
10119 bnx2x_program_serdes(&params->phy[INT_PHY], params, vars);
10120 vars->line_speed = temp;
10121 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010122
10123 bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD,
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010124 MDIO_CTL_REG_84823_MEDIA, &val);
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010125 val &= ~(MDIO_CTL_REG_84823_MEDIA_MAC_MASK |
10126 MDIO_CTL_REG_84823_MEDIA_LINE_MASK |
10127 MDIO_CTL_REG_84823_MEDIA_COPPER_CORE_DOWN |
10128 MDIO_CTL_REG_84823_MEDIA_PRIORITY_MASK |
10129 MDIO_CTL_REG_84823_MEDIA_FIBER_1G);
Yaniv Rosner0d40f0d2011-06-14 01:34:27 +000010130
10131 if (CHIP_IS_E3(bp)) {
10132 val &= ~(MDIO_CTL_REG_84823_MEDIA_MAC_MASK |
10133 MDIO_CTL_REG_84823_MEDIA_LINE_MASK);
10134 } else {
10135 val |= (MDIO_CTL_REG_84823_CTRL_MAC_XFI |
10136 MDIO_CTL_REG_84823_MEDIA_LINE_XAUI_L);
10137 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010138
10139 actual_phy_selection = bnx2x_phy_selection(params);
10140
10141 switch (actual_phy_selection) {
10142 case PORT_HW_CFG_PHY_SELECTION_HARDWARE_DEFAULT:
Lucas De Marchi25985ed2011-03-30 22:57:33 -030010143 /* Do nothing. Essentially this is like the priority copper */
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010144 break;
10145 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY_PRIORITY:
10146 val |= MDIO_CTL_REG_84823_MEDIA_PRIORITY_COPPER;
10147 break;
10148 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY_PRIORITY:
10149 val |= MDIO_CTL_REG_84823_MEDIA_PRIORITY_FIBER;
10150 break;
10151 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY:
10152 /* Do nothing here. The first PHY won't be initialized at all */
10153 break;
10154 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY:
10155 val |= MDIO_CTL_REG_84823_MEDIA_COPPER_CORE_DOWN;
10156 initialize = 0;
10157 break;
10158 }
10159 if (params->phy[EXT_PHY2].req_line_speed == SPEED_1000)
10160 val |= MDIO_CTL_REG_84823_MEDIA_FIBER_1G;
10161
10162 bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010163 MDIO_CTL_REG_84823_MEDIA, val);
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010164 DP(NETIF_MSG_LINK, "Multi_phy config = 0x%x, Media control = 0x%x\n",
10165 params->multi_phy_config, val);
10166
Yaniv Rosner11b2ec62012-01-17 02:33:25 +000010167 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833) {
10168 bnx2x_84833_pair_swap_cfg(phy, params, vars);
Yaniv Rosnera89a1d42011-07-05 01:07:05 +000010169
Yaniv Rosner096b9522012-01-17 02:33:28 +000010170 /* Keep AutogrEEEn disabled. */
10171 cmd_args[0] = 0x0;
Yaniv Rosner11b2ec62012-01-17 02:33:25 +000010172 cmd_args[1] = 0x0;
10173 cmd_args[2] = PHY84833_CONSTANT_LATENCY + 1;
10174 cmd_args[3] = PHY84833_CONSTANT_LATENCY;
10175 rc = bnx2x_84833_cmd_hdlr(phy, params,
Yuval Mintzc8c60d82012-06-06 17:13:07 +000010176 PHY84833_CMD_SET_EEE_MODE, cmd_args,
10177 PHY84833_CMDHDLR_MAX_ARGS);
Yuval Mintzd2310232012-06-20 19:05:19 +000010178 if (rc)
Yaniv Rosner11b2ec62012-01-17 02:33:25 +000010179 DP(NETIF_MSG_LINK, "Cfg AutogrEEEn failed.\n");
10180 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010181 if (initialize)
10182 rc = bnx2x_848xx_cmn_config_init(phy, params, vars);
10183 else
Yaniv Rosner11b2ec62012-01-17 02:33:25 +000010184 bnx2x_save_848xx_spirom_version(phy, bp, params->port);
Yaniv Rosnera89a1d42011-07-05 01:07:05 +000010185 /* 84833 PHY has a better feature and doesn't need to support this. */
10186 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84823) {
10187 cms_enable = REG_RD(bp, params->shmem_base +
Yaniv Rosner1bef68e2011-01-31 04:22:46 +000010188 offsetof(struct shmem_region,
10189 dev_info.port_hw_config[params->port].default_cfg)) &
10190 PORT_HW_CFG_ENABLE_CMS_MASK;
10191
Yaniv Rosnera89a1d42011-07-05 01:07:05 +000010192 bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD,
10193 MDIO_CTL_REG_84823_USER_CTRL_REG, &val);
10194 if (cms_enable)
10195 val |= MDIO_CTL_REG_84823_USER_CTRL_CMS;
10196 else
10197 val &= ~MDIO_CTL_REG_84823_USER_CTRL_CMS;
10198 bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
10199 MDIO_CTL_REG_84823_USER_CTRL_REG, val);
10200 }
Yaniv Rosner1bef68e2011-01-31 04:22:46 +000010201
Yuval Mintzc8c60d82012-06-06 17:13:07 +000010202 bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD,
10203 MDIO_84833_TOP_CFG_FW_REV, &val);
10204
10205 /* Configure EEE support */
10206 if ((val >= MDIO_84833_TOP_CFG_FW_EEE) && bnx2x_eee_has_cap(params)) {
10207 phy->flags |= FLAGS_EEE_10GBT;
Yuval Mintzec4010e2012-09-10 05:51:06 +000010208 rc = bnx2x_eee_initial_config(params, vars, SHMEM_EEE_10G_ADV);
Yuval Mintzd2310232012-06-20 19:05:19 +000010209 if (rc) {
Yuval Mintzc8c60d82012-06-06 17:13:07 +000010210 DP(NETIF_MSG_LINK, "Failed to configure EEE timers\n");
10211 bnx2x_8483x_disable_eee(phy, params, vars);
10212 return rc;
10213 }
10214
10215 if ((params->req_duplex[actual_phy_selection] == DUPLEX_FULL) &&
10216 (params->eee_mode & EEE_MODE_ADV_LPI) &&
10217 (bnx2x_eee_calc_timer(params) ||
10218 !(params->eee_mode & EEE_MODE_ENABLE_LPI)))
10219 rc = bnx2x_8483x_enable_eee(phy, params, vars);
10220 else
10221 rc = bnx2x_8483x_disable_eee(phy, params, vars);
Yuval Mintzd2310232012-06-20 19:05:19 +000010222 if (rc) {
Yuval Mintzc8c60d82012-06-06 17:13:07 +000010223 DP(NETIF_MSG_LINK, "Failed to set EEE advertisment\n");
10224 return rc;
10225 }
10226 } else {
10227 phy->flags &= ~FLAGS_EEE_10GBT;
10228 vars->eee_status &= ~SHMEM_EEE_SUPPORTED_MASK;
10229 }
10230
Yaniv Rosner11b2ec62012-01-17 02:33:25 +000010231 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833) {
10232 /* Bring PHY out of super isolate mode as the final step. */
10233 bnx2x_cl45_read(bp, phy,
10234 MDIO_CTL_DEVAD,
10235 MDIO_84833_TOP_CFG_XGPHY_STRAP1, &val);
10236 val &= ~MDIO_84833_SUPER_ISOLATE;
10237 bnx2x_cl45_write(bp, phy,
10238 MDIO_CTL_DEVAD,
10239 MDIO_84833_TOP_CFG_XGPHY_STRAP1, val);
10240 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010241 return rc;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010242}
10243
10244static u8 bnx2x_848xx_read_status(struct bnx2x_phy *phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010245 struct link_params *params,
10246 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010247{
10248 struct bnx2x *bp = params->bp;
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010249 u16 val, val1, val2;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010250 u8 link_up = 0;
10251
Yaniv Rosnerc87bca12011-01-31 04:22:41 +000010252
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010253 /* Check 10G-BaseT link status */
10254 /* Check PMD signal ok */
10255 bnx2x_cl45_read(bp, phy,
10256 MDIO_AN_DEVAD, 0xFFFA, &val1);
10257 bnx2x_cl45_read(bp, phy,
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010258 MDIO_PMA_DEVAD, MDIO_PMA_REG_8481_PMD_SIGNAL,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010259 &val2);
10260 DP(NETIF_MSG_LINK, "BCM848xx: PMD_SIGNAL 1.a811 = 0x%x\n", val2);
10261
10262 /* Check link 10G */
10263 if (val2 & (1<<11)) {
10264 vars->line_speed = SPEED_10000;
Yaniv Rosner791f18c2011-01-18 04:33:42 +000010265 vars->duplex = DUPLEX_FULL;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010266 link_up = 1;
10267 bnx2x_ext_phy_10G_an_resolve(bp, phy, vars);
10268 } else { /* Check Legacy speed link */
10269 u16 legacy_status, legacy_speed;
10270
10271 /* Enable expansion register 0x42 (Operation mode status) */
10272 bnx2x_cl45_write(bp, phy,
10273 MDIO_AN_DEVAD,
10274 MDIO_AN_REG_8481_EXPANSION_REG_ACCESS, 0xf42);
10275
10276 /* Get legacy speed operation status */
10277 bnx2x_cl45_read(bp, phy,
10278 MDIO_AN_DEVAD,
10279 MDIO_AN_REG_8481_EXPANSION_REG_RD_RW,
10280 &legacy_status);
10281
Joe Perches94f05b02011-08-14 12:16:20 +000010282 DP(NETIF_MSG_LINK, "Legacy speed status = 0x%x\n",
10283 legacy_status);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010284 link_up = ((legacy_status & (1<<11)) == (1<<11));
Yuval Mintz14400902012-06-20 19:05:20 +000010285 legacy_speed = (legacy_status & (3<<9));
10286 if (legacy_speed == (0<<9))
10287 vars->line_speed = SPEED_10;
10288 else if (legacy_speed == (1<<9))
10289 vars->line_speed = SPEED_100;
10290 else if (legacy_speed == (2<<9))
10291 vars->line_speed = SPEED_1000;
10292 else { /* Should not happen: Treat as link down */
10293 vars->line_speed = 0;
10294 link_up = 0;
10295 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010296
Yuval Mintz14400902012-06-20 19:05:20 +000010297 if (link_up) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010298 if (legacy_status & (1<<8))
10299 vars->duplex = DUPLEX_FULL;
10300 else
10301 vars->duplex = DUPLEX_HALF;
10302
Joe Perches94f05b02011-08-14 12:16:20 +000010303 DP(NETIF_MSG_LINK,
10304 "Link is up in %dMbps, is_duplex_full= %d\n",
10305 vars->line_speed,
10306 (vars->duplex == DUPLEX_FULL));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010307 /* Check legacy speed AN resolution */
10308 bnx2x_cl45_read(bp, phy,
10309 MDIO_AN_DEVAD,
10310 MDIO_AN_REG_8481_LEGACY_MII_STATUS,
10311 &val);
10312 if (val & (1<<5))
10313 vars->link_status |=
10314 LINK_STATUS_AUTO_NEGOTIATE_COMPLETE;
10315 bnx2x_cl45_read(bp, phy,
10316 MDIO_AN_DEVAD,
10317 MDIO_AN_REG_8481_LEGACY_AN_EXPANSION,
10318 &val);
10319 if ((val & (1<<0)) == 0)
10320 vars->link_status |=
10321 LINK_STATUS_PARALLEL_DETECTION_USED;
10322 }
10323 }
10324 if (link_up) {
Yuval Mintzd2310232012-06-20 19:05:19 +000010325 DP(NETIF_MSG_LINK, "BCM848x3: link speed is %d\n",
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010326 vars->line_speed);
10327 bnx2x_ext_phy_resolve_fc(phy, params, vars);
Mintz Yuval9e7e8392012-02-15 02:10:24 +000010328
10329 /* Read LP advertised speeds */
10330 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
10331 MDIO_AN_REG_CL37_FC_LP, &val);
10332 if (val & (1<<5))
10333 vars->link_status |=
10334 LINK_STATUS_LINK_PARTNER_10THD_CAPABLE;
10335 if (val & (1<<6))
10336 vars->link_status |=
10337 LINK_STATUS_LINK_PARTNER_10TFD_CAPABLE;
10338 if (val & (1<<7))
10339 vars->link_status |=
10340 LINK_STATUS_LINK_PARTNER_100TXHD_CAPABLE;
10341 if (val & (1<<8))
10342 vars->link_status |=
10343 LINK_STATUS_LINK_PARTNER_100TXFD_CAPABLE;
10344 if (val & (1<<9))
10345 vars->link_status |=
10346 LINK_STATUS_LINK_PARTNER_100T4_CAPABLE;
10347
10348 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
10349 MDIO_AN_REG_1000T_STATUS, &val);
10350
10351 if (val & (1<<10))
10352 vars->link_status |=
10353 LINK_STATUS_LINK_PARTNER_1000THD_CAPABLE;
10354 if (val & (1<<11))
10355 vars->link_status |=
10356 LINK_STATUS_LINK_PARTNER_1000TFD_CAPABLE;
10357
10358 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
10359 MDIO_AN_REG_MASTER_STATUS, &val);
10360
10361 if (val & (1<<11))
10362 vars->link_status |=
10363 LINK_STATUS_LINK_PARTNER_10GXFD_CAPABLE;
Yuval Mintzc8c60d82012-06-06 17:13:07 +000010364
10365 /* Determine if EEE was negotiated */
Yuval Mintzec4010e2012-09-10 05:51:06 +000010366 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
10367 bnx2x_eee_an_resolve(phy, params, vars);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010368 }
10369
10370 return link_up;
10371}
10372
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000010373
10374static int bnx2x_848xx_format_ver(u32 raw_ver, u8 *str, u16 *len)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010375{
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000010376 int status = 0;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010377 u32 spirom_ver;
10378 spirom_ver = ((raw_ver & 0xF80) >> 7) << 16 | (raw_ver & 0x7F);
10379 status = bnx2x_format_ver(spirom_ver, str, len);
10380 return status;
10381}
10382
10383static void bnx2x_8481_hw_reset(struct bnx2x_phy *phy,
10384 struct link_params *params)
10385{
10386 bnx2x_set_gpio(params->bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010387 MISC_REGISTERS_GPIO_OUTPUT_LOW, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010388 bnx2x_set_gpio(params->bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010389 MISC_REGISTERS_GPIO_OUTPUT_LOW, 1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010390}
10391
10392static void bnx2x_8481_link_reset(struct bnx2x_phy *phy,
10393 struct link_params *params)
10394{
10395 bnx2x_cl45_write(params->bp, phy,
10396 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x0000);
10397 bnx2x_cl45_write(params->bp, phy,
10398 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 1);
10399}
10400
10401static void bnx2x_848x3_link_reset(struct bnx2x_phy *phy,
10402 struct link_params *params)
10403{
10404 struct bnx2x *bp = params->bp;
Yaniv Rosner6a71bbe2010-11-01 05:32:31 +000010405 u8 port;
Yaniv Rosner0d40f0d2011-06-14 01:34:27 +000010406 u16 val16;
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010407
Yaniv Rosnerf93fb012012-04-04 01:29:02 +000010408 if (!(CHIP_IS_E1x(bp)))
Yaniv Rosner6a71bbe2010-11-01 05:32:31 +000010409 port = BP_PATH(bp);
10410 else
10411 port = params->port;
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010412
10413 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84823) {
10414 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_3,
10415 MISC_REGISTERS_GPIO_OUTPUT_LOW,
10416 port);
10417 } else {
Yaniv Rosner0d40f0d2011-06-14 01:34:27 +000010418 bnx2x_cl45_read(bp, phy,
10419 MDIO_CTL_DEVAD,
Yaniv Rosner11b2ec62012-01-17 02:33:25 +000010420 MDIO_84833_TOP_CFG_XGPHY_STRAP1, &val16);
10421 val16 |= MDIO_84833_SUPER_ISOLATE;
Yaniv Rosnerfd38f73e2011-08-02 22:59:53 +000010422 bnx2x_cl45_write(bp, phy,
Yaniv Rosner11b2ec62012-01-17 02:33:25 +000010423 MDIO_CTL_DEVAD,
10424 MDIO_84833_TOP_CFG_XGPHY_STRAP1, val16);
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010425 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010426}
10427
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010428static void bnx2x_848xx_set_link_led(struct bnx2x_phy *phy,
10429 struct link_params *params, u8 mode)
10430{
10431 struct bnx2x *bp = params->bp;
10432 u16 val;
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010433 u8 port;
10434
Yaniv Rosnerf93fb012012-04-04 01:29:02 +000010435 if (!(CHIP_IS_E1x(bp)))
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010436 port = BP_PATH(bp);
10437 else
10438 port = params->port;
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010439
10440 switch (mode) {
10441 case LED_MODE_OFF:
10442
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010443 DP(NETIF_MSG_LINK, "Port 0x%x: LED MODE OFF\n", port);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010444
10445 if ((params->hw_led_mode << SHARED_HW_CFG_LED_MODE_SHIFT) ==
10446 SHARED_HW_CFG_LED_EXTPHY1) {
10447
10448 /* Set LED masks */
10449 bnx2x_cl45_write(bp, phy,
10450 MDIO_PMA_DEVAD,
10451 MDIO_PMA_REG_8481_LED1_MASK,
10452 0x0);
10453
10454 bnx2x_cl45_write(bp, phy,
10455 MDIO_PMA_DEVAD,
10456 MDIO_PMA_REG_8481_LED2_MASK,
10457 0x0);
10458
10459 bnx2x_cl45_write(bp, phy,
10460 MDIO_PMA_DEVAD,
10461 MDIO_PMA_REG_8481_LED3_MASK,
10462 0x0);
10463
10464 bnx2x_cl45_write(bp, phy,
10465 MDIO_PMA_DEVAD,
10466 MDIO_PMA_REG_8481_LED5_MASK,
10467 0x0);
10468
10469 } else {
10470 bnx2x_cl45_write(bp, phy,
10471 MDIO_PMA_DEVAD,
10472 MDIO_PMA_REG_8481_LED1_MASK,
10473 0x0);
10474 }
10475 break;
10476 case LED_MODE_FRONT_PANEL_OFF:
10477
10478 DP(NETIF_MSG_LINK, "Port 0x%x: LED MODE FRONT PANEL OFF\n",
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010479 port);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010480
10481 if ((params->hw_led_mode << SHARED_HW_CFG_LED_MODE_SHIFT) ==
10482 SHARED_HW_CFG_LED_EXTPHY1) {
10483
10484 /* Set LED masks */
10485 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010486 MDIO_PMA_DEVAD,
10487 MDIO_PMA_REG_8481_LED1_MASK,
10488 0x0);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010489
10490 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010491 MDIO_PMA_DEVAD,
10492 MDIO_PMA_REG_8481_LED2_MASK,
10493 0x0);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010494
10495 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010496 MDIO_PMA_DEVAD,
10497 MDIO_PMA_REG_8481_LED3_MASK,
10498 0x0);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010499
10500 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010501 MDIO_PMA_DEVAD,
10502 MDIO_PMA_REG_8481_LED5_MASK,
10503 0x20);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010504
10505 } else {
10506 bnx2x_cl45_write(bp, phy,
10507 MDIO_PMA_DEVAD,
10508 MDIO_PMA_REG_8481_LED1_MASK,
10509 0x0);
10510 }
10511 break;
10512 case LED_MODE_ON:
10513
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010514 DP(NETIF_MSG_LINK, "Port 0x%x: LED MODE ON\n", port);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010515
10516 if ((params->hw_led_mode << SHARED_HW_CFG_LED_MODE_SHIFT) ==
10517 SHARED_HW_CFG_LED_EXTPHY1) {
10518 /* Set control reg */
10519 bnx2x_cl45_read(bp, phy,
10520 MDIO_PMA_DEVAD,
10521 MDIO_PMA_REG_8481_LINK_SIGNAL,
10522 &val);
10523 val &= 0x8000;
10524 val |= 0x2492;
10525
10526 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010527 MDIO_PMA_DEVAD,
10528 MDIO_PMA_REG_8481_LINK_SIGNAL,
10529 val);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010530
10531 /* Set LED masks */
10532 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010533 MDIO_PMA_DEVAD,
10534 MDIO_PMA_REG_8481_LED1_MASK,
10535 0x0);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010536
10537 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010538 MDIO_PMA_DEVAD,
10539 MDIO_PMA_REG_8481_LED2_MASK,
10540 0x20);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010541
10542 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010543 MDIO_PMA_DEVAD,
10544 MDIO_PMA_REG_8481_LED3_MASK,
10545 0x20);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010546
10547 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010548 MDIO_PMA_DEVAD,
10549 MDIO_PMA_REG_8481_LED5_MASK,
10550 0x0);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010551 } else {
10552 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010553 MDIO_PMA_DEVAD,
10554 MDIO_PMA_REG_8481_LED1_MASK,
10555 0x20);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010556 }
10557 break;
10558
10559 case LED_MODE_OPER:
10560
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010561 DP(NETIF_MSG_LINK, "Port 0x%x: LED MODE OPER\n", port);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010562
10563 if ((params->hw_led_mode << SHARED_HW_CFG_LED_MODE_SHIFT) ==
10564 SHARED_HW_CFG_LED_EXTPHY1) {
10565
10566 /* Set control reg */
10567 bnx2x_cl45_read(bp, phy,
10568 MDIO_PMA_DEVAD,
10569 MDIO_PMA_REG_8481_LINK_SIGNAL,
10570 &val);
10571
10572 if (!((val &
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010573 MDIO_PMA_REG_8481_LINK_SIGNAL_LED4_ENABLE_MASK)
10574 >> MDIO_PMA_REG_8481_LINK_SIGNAL_LED4_ENABLE_SHIFT)) {
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +000010575 DP(NETIF_MSG_LINK, "Setting LINK_SIGNAL\n");
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010576 bnx2x_cl45_write(bp, phy,
10577 MDIO_PMA_DEVAD,
10578 MDIO_PMA_REG_8481_LINK_SIGNAL,
10579 0xa492);
10580 }
10581
10582 /* Set LED masks */
10583 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010584 MDIO_PMA_DEVAD,
10585 MDIO_PMA_REG_8481_LED1_MASK,
10586 0x10);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010587
10588 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010589 MDIO_PMA_DEVAD,
10590 MDIO_PMA_REG_8481_LED2_MASK,
10591 0x80);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010592
10593 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010594 MDIO_PMA_DEVAD,
10595 MDIO_PMA_REG_8481_LED3_MASK,
10596 0x98);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010597
10598 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010599 MDIO_PMA_DEVAD,
10600 MDIO_PMA_REG_8481_LED5_MASK,
10601 0x40);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010602
10603 } else {
10604 bnx2x_cl45_write(bp, phy,
10605 MDIO_PMA_DEVAD,
10606 MDIO_PMA_REG_8481_LED1_MASK,
10607 0x80);
Yaniv Rosner53eda062011-01-30 04:14:55 +000010608
10609 /* Tell LED3 to blink on source */
10610 bnx2x_cl45_read(bp, phy,
10611 MDIO_PMA_DEVAD,
10612 MDIO_PMA_REG_8481_LINK_SIGNAL,
10613 &val);
10614 val &= ~(7<<6);
10615 val |= (1<<6); /* A83B[8:6]= 1 */
10616 bnx2x_cl45_write(bp, phy,
10617 MDIO_PMA_DEVAD,
10618 MDIO_PMA_REG_8481_LINK_SIGNAL,
10619 val);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010620 }
10621 break;
10622 }
Yaniv Rosner0d40f0d2011-06-14 01:34:27 +000010623
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000010624 /* This is a workaround for E3+84833 until autoneg
Yaniv Rosner0d40f0d2011-06-14 01:34:27 +000010625 * restart is fixed in f/w
10626 */
10627 if (CHIP_IS_E3(bp)) {
10628 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
10629 MDIO_WC_REG_GP2_STATUS_GP_2_1, &val);
10630 }
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010631}
Yaniv Rosner0d40f0d2011-06-14 01:34:27 +000010632
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010633/******************************************************************/
Yaniv Rosner52c4d6c2011-07-05 01:06:34 +000010634/* 54618SE PHY SECTION */
Yaniv Rosner6583e332011-06-14 01:34:17 +000010635/******************************************************************/
Yaniv Rosner52c4d6c2011-07-05 01:06:34 +000010636static int bnx2x_54618se_config_init(struct bnx2x_phy *phy,
Yaniv Rosner6583e332011-06-14 01:34:17 +000010637 struct link_params *params,
10638 struct link_vars *vars)
10639{
10640 struct bnx2x *bp = params->bp;
10641 u8 port;
10642 u16 autoneg_val, an_1000_val, an_10_100_val, fc_val, temp;
10643 u32 cfg_pin;
10644
Yaniv Rosner52c4d6c2011-07-05 01:06:34 +000010645 DP(NETIF_MSG_LINK, "54618SE cfg init\n");
Yuval Mintzd2310232012-06-20 19:05:19 +000010646 usleep_range(1000, 2000);
Yaniv Rosner6583e332011-06-14 01:34:17 +000010647
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000010648 /* This works with E3 only, no need to check the chip
Yaniv Rosner2f751a82011-11-28 00:49:52 +000010649 * before determining the port.
10650 */
Yaniv Rosner6583e332011-06-14 01:34:17 +000010651 port = params->port;
10652
10653 cfg_pin = (REG_RD(bp, params->shmem_base +
10654 offsetof(struct shmem_region,
10655 dev_info.port_hw_config[port].e3_cmn_pin_cfg)) &
10656 PORT_HW_CFG_E3_PHY_RESET_MASK) >>
10657 PORT_HW_CFG_E3_PHY_RESET_SHIFT;
10658
10659 /* Drive pin high to bring the GPHY out of reset. */
10660 bnx2x_set_cfg_pin(bp, cfg_pin, 1);
10661
10662 /* wait for GPHY to reset */
10663 msleep(50);
10664
10665 /* reset phy */
10666 bnx2x_cl22_write(bp, phy,
10667 MDIO_PMA_REG_CTRL, 0x8000);
10668 bnx2x_wait_reset_complete(bp, phy, params);
10669
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000010670 /* Wait for GPHY to reset */
Yaniv Rosner6583e332011-06-14 01:34:17 +000010671 msleep(50);
10672
10673 /* Configure LED4: set to INTR (0x6). */
10674 /* Accessing shadow register 0xe. */
10675 bnx2x_cl22_write(bp, phy,
10676 MDIO_REG_GPHY_SHADOW,
10677 MDIO_REG_GPHY_SHADOW_LED_SEL2);
10678 bnx2x_cl22_read(bp, phy,
10679 MDIO_REG_GPHY_SHADOW,
10680 &temp);
10681 temp &= ~(0xf << 4);
10682 temp |= (0x6 << 4);
10683 bnx2x_cl22_write(bp, phy,
10684 MDIO_REG_GPHY_SHADOW,
10685 MDIO_REG_GPHY_SHADOW_WR_ENA | temp);
10686 /* Configure INTR based on link status change. */
10687 bnx2x_cl22_write(bp, phy,
10688 MDIO_REG_INTR_MASK,
10689 ~MDIO_REG_INTR_MASK_LINK_STATUS);
10690
10691 /* Flip the signal detect polarity (set 0x1c.0x1e[8]). */
10692 bnx2x_cl22_write(bp, phy,
10693 MDIO_REG_GPHY_SHADOW,
10694 MDIO_REG_GPHY_SHADOW_AUTO_DET_MED);
10695 bnx2x_cl22_read(bp, phy,
10696 MDIO_REG_GPHY_SHADOW,
10697 &temp);
10698 temp |= MDIO_REG_GPHY_SHADOW_INVERT_FIB_SD;
10699 bnx2x_cl22_write(bp, phy,
10700 MDIO_REG_GPHY_SHADOW,
10701 MDIO_REG_GPHY_SHADOW_WR_ENA | temp);
10702
10703 /* Set up fc */
10704 /* Please refer to Table 28B-3 of 802.3ab-1999 spec. */
10705 bnx2x_calc_ieee_aneg_adv(phy, params, &vars->ieee_fc);
10706 fc_val = 0;
10707 if ((vars->ieee_fc & MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC) ==
10708 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC)
10709 fc_val |= MDIO_AN_REG_ADV_PAUSE_ASYMMETRIC;
10710
10711 if ((vars->ieee_fc & MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) ==
10712 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH)
10713 fc_val |= MDIO_AN_REG_ADV_PAUSE_PAUSE;
10714
Yuval Mintzd2310232012-06-20 19:05:19 +000010715 /* Read all advertisement */
Yaniv Rosner6583e332011-06-14 01:34:17 +000010716 bnx2x_cl22_read(bp, phy,
10717 0x09,
10718 &an_1000_val);
10719
10720 bnx2x_cl22_read(bp, phy,
10721 0x04,
10722 &an_10_100_val);
10723
10724 bnx2x_cl22_read(bp, phy,
10725 MDIO_PMA_REG_CTRL,
10726 &autoneg_val);
10727
10728 /* Disable forced speed */
10729 autoneg_val &= ~((1<<6) | (1<<8) | (1<<9) | (1<<12) | (1<<13));
10730 an_10_100_val &= ~((1<<5) | (1<<6) | (1<<7) | (1<<8) | (1<<10) |
10731 (1<<11));
10732
10733 if (((phy->req_line_speed == SPEED_AUTO_NEG) &&
10734 (phy->speed_cap_mask &
10735 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) ||
10736 (phy->req_line_speed == SPEED_1000)) {
10737 an_1000_val |= (1<<8);
10738 autoneg_val |= (1<<9 | 1<<12);
10739 if (phy->req_duplex == DUPLEX_FULL)
10740 an_1000_val |= (1<<9);
10741 DP(NETIF_MSG_LINK, "Advertising 1G\n");
10742 } else
10743 an_1000_val &= ~((1<<8) | (1<<9));
10744
10745 bnx2x_cl22_write(bp, phy,
10746 0x09,
10747 an_1000_val);
10748 bnx2x_cl22_read(bp, phy,
10749 0x09,
10750 &an_1000_val);
10751
Yuval Mintzd2310232012-06-20 19:05:19 +000010752 /* Set 100 speed advertisement */
Yaniv Rosner6583e332011-06-14 01:34:17 +000010753 if (((phy->req_line_speed == SPEED_AUTO_NEG) &&
10754 (phy->speed_cap_mask &
10755 (PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL |
10756 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF)))) {
10757 an_10_100_val |= (1<<7);
10758 /* Enable autoneg and restart autoneg for legacy speeds */
10759 autoneg_val |= (1<<9 | 1<<12);
10760
10761 if (phy->req_duplex == DUPLEX_FULL)
10762 an_10_100_val |= (1<<8);
10763 DP(NETIF_MSG_LINK, "Advertising 100M\n");
10764 }
10765
Yuval Mintzd2310232012-06-20 19:05:19 +000010766 /* Set 10 speed advertisement */
Yaniv Rosner6583e332011-06-14 01:34:17 +000010767 if (((phy->req_line_speed == SPEED_AUTO_NEG) &&
10768 (phy->speed_cap_mask &
10769 (PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL |
10770 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF)))) {
10771 an_10_100_val |= (1<<5);
10772 autoneg_val |= (1<<9 | 1<<12);
10773 if (phy->req_duplex == DUPLEX_FULL)
10774 an_10_100_val |= (1<<6);
10775 DP(NETIF_MSG_LINK, "Advertising 10M\n");
10776 }
10777
10778 /* Only 10/100 are allowed to work in FORCE mode */
10779 if (phy->req_line_speed == SPEED_100) {
10780 autoneg_val |= (1<<13);
10781 /* Enabled AUTO-MDIX when autoneg is disabled */
10782 bnx2x_cl22_write(bp, phy,
10783 0x18,
10784 (1<<15 | 1<<9 | 7<<0));
10785 DP(NETIF_MSG_LINK, "Setting 100M force\n");
10786 }
10787 if (phy->req_line_speed == SPEED_10) {
10788 /* Enabled AUTO-MDIX when autoneg is disabled */
10789 bnx2x_cl22_write(bp, phy,
10790 0x18,
10791 (1<<15 | 1<<9 | 7<<0));
10792 DP(NETIF_MSG_LINK, "Setting 10M force\n");
10793 }
10794
Yaniv Rosnera89a1d42011-07-05 01:07:05 +000010795 /* Check if we should turn on Auto-GrEEEn */
10796 bnx2x_cl22_read(bp, phy, MDIO_REG_GPHY_PHYID_LSB, &temp);
10797 if (temp == MDIO_REG_GPHY_ID_54618SE) {
10798 if (params->feature_config_flags &
10799 FEATURE_CONFIG_AUTOGREEEN_ENABLED) {
10800 temp = 6;
10801 DP(NETIF_MSG_LINK, "Enabling Auto-GrEEEn\n");
10802 } else {
10803 temp = 0;
10804 DP(NETIF_MSG_LINK, "Disabling Auto-GrEEEn\n");
10805 }
10806 bnx2x_cl22_write(bp, phy,
10807 MDIO_REG_GPHY_CL45_ADDR_REG, MDIO_AN_DEVAD);
10808 bnx2x_cl22_write(bp, phy,
10809 MDIO_REG_GPHY_CL45_DATA_REG,
10810 MDIO_REG_GPHY_EEE_ADV);
10811 bnx2x_cl22_write(bp, phy,
10812 MDIO_REG_GPHY_CL45_ADDR_REG,
10813 (0x1 << 14) | MDIO_AN_DEVAD);
10814 bnx2x_cl22_write(bp, phy,
10815 MDIO_REG_GPHY_CL45_DATA_REG,
10816 temp);
10817 }
10818
Yaniv Rosner6583e332011-06-14 01:34:17 +000010819 bnx2x_cl22_write(bp, phy,
10820 0x04,
10821 an_10_100_val | fc_val);
10822
10823 if (phy->req_duplex == DUPLEX_FULL)
10824 autoneg_val |= (1<<8);
10825
10826 bnx2x_cl22_write(bp, phy,
10827 MDIO_PMA_REG_CTRL, autoneg_val);
10828
10829 return 0;
10830}
10831
Yaniv Rosner1d125bd2011-11-23 03:54:08 +000010832
10833static void bnx2x_5461x_set_link_led(struct bnx2x_phy *phy,
10834 struct link_params *params, u8 mode)
10835{
10836 struct bnx2x *bp = params->bp;
10837 u16 temp;
10838
10839 bnx2x_cl22_write(bp, phy,
10840 MDIO_REG_GPHY_SHADOW,
10841 MDIO_REG_GPHY_SHADOW_LED_SEL1);
10842 bnx2x_cl22_read(bp, phy,
10843 MDIO_REG_GPHY_SHADOW,
10844 &temp);
10845 temp &= 0xff00;
10846
10847 DP(NETIF_MSG_LINK, "54618x set link led (mode=%x)\n", mode);
10848 switch (mode) {
10849 case LED_MODE_FRONT_PANEL_OFF:
10850 case LED_MODE_OFF:
10851 temp |= 0x00ee;
10852 break;
10853 case LED_MODE_OPER:
10854 temp |= 0x0001;
10855 break;
10856 case LED_MODE_ON:
10857 temp |= 0x00ff;
10858 break;
10859 default:
10860 break;
10861 }
10862 bnx2x_cl22_write(bp, phy,
10863 MDIO_REG_GPHY_SHADOW,
10864 MDIO_REG_GPHY_SHADOW_WR_ENA | temp);
10865 return;
10866}
10867
10868
Yaniv Rosner52c4d6c2011-07-05 01:06:34 +000010869static void bnx2x_54618se_link_reset(struct bnx2x_phy *phy,
10870 struct link_params *params)
Yaniv Rosner6583e332011-06-14 01:34:17 +000010871{
10872 struct bnx2x *bp = params->bp;
10873 u32 cfg_pin;
10874 u8 port;
10875
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000010876 /* In case of no EPIO routed to reset the GPHY, put it
Yaniv Rosnerd2059a02011-08-02 23:00:00 +000010877 * in low power mode.
10878 */
10879 bnx2x_cl22_write(bp, phy, MDIO_PMA_REG_CTRL, 0x800);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000010880 /* This works with E3 only, no need to check the chip
Yaniv Rosnerd2059a02011-08-02 23:00:00 +000010881 * before determining the port.
10882 */
Yaniv Rosner6583e332011-06-14 01:34:17 +000010883 port = params->port;
10884 cfg_pin = (REG_RD(bp, params->shmem_base +
10885 offsetof(struct shmem_region,
10886 dev_info.port_hw_config[port].e3_cmn_pin_cfg)) &
10887 PORT_HW_CFG_E3_PHY_RESET_MASK) >>
10888 PORT_HW_CFG_E3_PHY_RESET_SHIFT;
10889
10890 /* Drive pin low to put GPHY in reset. */
10891 bnx2x_set_cfg_pin(bp, cfg_pin, 0);
10892}
10893
Yaniv Rosner52c4d6c2011-07-05 01:06:34 +000010894static u8 bnx2x_54618se_read_status(struct bnx2x_phy *phy,
10895 struct link_params *params,
10896 struct link_vars *vars)
Yaniv Rosner6583e332011-06-14 01:34:17 +000010897{
10898 struct bnx2x *bp = params->bp;
10899 u16 val;
10900 u8 link_up = 0;
10901 u16 legacy_status, legacy_speed;
10902
10903 /* Get speed operation status */
10904 bnx2x_cl22_read(bp, phy,
Yuval Mintza351d492012-06-20 19:05:21 +000010905 MDIO_REG_GPHY_AUX_STATUS,
Yaniv Rosner6583e332011-06-14 01:34:17 +000010906 &legacy_status);
Yaniv Rosner52c4d6c2011-07-05 01:06:34 +000010907 DP(NETIF_MSG_LINK, "54618SE read_status: 0x%x\n", legacy_status);
Yaniv Rosner6583e332011-06-14 01:34:17 +000010908
10909 /* Read status to clear the PHY interrupt. */
10910 bnx2x_cl22_read(bp, phy,
10911 MDIO_REG_INTR_STATUS,
10912 &val);
10913
10914 link_up = ((legacy_status & (1<<2)) == (1<<2));
10915
10916 if (link_up) {
10917 legacy_speed = (legacy_status & (7<<8));
10918 if (legacy_speed == (7<<8)) {
10919 vars->line_speed = SPEED_1000;
10920 vars->duplex = DUPLEX_FULL;
10921 } else if (legacy_speed == (6<<8)) {
10922 vars->line_speed = SPEED_1000;
10923 vars->duplex = DUPLEX_HALF;
10924 } else if (legacy_speed == (5<<8)) {
10925 vars->line_speed = SPEED_100;
10926 vars->duplex = DUPLEX_FULL;
10927 }
10928 /* Omitting 100Base-T4 for now */
10929 else if (legacy_speed == (3<<8)) {
10930 vars->line_speed = SPEED_100;
10931 vars->duplex = DUPLEX_HALF;
10932 } else if (legacy_speed == (2<<8)) {
10933 vars->line_speed = SPEED_10;
10934 vars->duplex = DUPLEX_FULL;
10935 } else if (legacy_speed == (1<<8)) {
10936 vars->line_speed = SPEED_10;
10937 vars->duplex = DUPLEX_HALF;
10938 } else /* Should not happen */
10939 vars->line_speed = 0;
10940
Joe Perches94f05b02011-08-14 12:16:20 +000010941 DP(NETIF_MSG_LINK,
10942 "Link is up in %dMbps, is_duplex_full= %d\n",
10943 vars->line_speed,
10944 (vars->duplex == DUPLEX_FULL));
Yaniv Rosner6583e332011-06-14 01:34:17 +000010945
10946 /* Check legacy speed AN resolution */
10947 bnx2x_cl22_read(bp, phy,
10948 0x01,
10949 &val);
10950 if (val & (1<<5))
10951 vars->link_status |=
10952 LINK_STATUS_AUTO_NEGOTIATE_COMPLETE;
10953 bnx2x_cl22_read(bp, phy,
10954 0x06,
10955 &val);
10956 if ((val & (1<<0)) == 0)
10957 vars->link_status |=
10958 LINK_STATUS_PARALLEL_DETECTION_USED;
10959
Yaniv Rosner52c4d6c2011-07-05 01:06:34 +000010960 DP(NETIF_MSG_LINK, "BCM54618SE: link speed is %d\n",
Yaniv Rosner6583e332011-06-14 01:34:17 +000010961 vars->line_speed);
Yaniv Rosner52c4d6c2011-07-05 01:06:34 +000010962
10963 /* Report whether EEE is resolved. */
10964 bnx2x_cl22_read(bp, phy, MDIO_REG_GPHY_PHYID_LSB, &val);
10965 if (val == MDIO_REG_GPHY_ID_54618SE) {
10966 if (vars->link_status &
10967 LINK_STATUS_AUTO_NEGOTIATE_COMPLETE)
10968 val = 0;
10969 else {
10970 bnx2x_cl22_write(bp, phy,
10971 MDIO_REG_GPHY_CL45_ADDR_REG,
10972 MDIO_AN_DEVAD);
10973 bnx2x_cl22_write(bp, phy,
10974 MDIO_REG_GPHY_CL45_DATA_REG,
10975 MDIO_REG_GPHY_EEE_RESOLVED);
10976 bnx2x_cl22_write(bp, phy,
10977 MDIO_REG_GPHY_CL45_ADDR_REG,
10978 (0x1 << 14) | MDIO_AN_DEVAD);
10979 bnx2x_cl22_read(bp, phy,
10980 MDIO_REG_GPHY_CL45_DATA_REG,
10981 &val);
10982 }
10983 DP(NETIF_MSG_LINK, "EEE resolution: 0x%x\n", val);
10984 }
10985
Yaniv Rosner6583e332011-06-14 01:34:17 +000010986 bnx2x_ext_phy_resolve_fc(phy, params, vars);
Mintz Yuval9e7e8392012-02-15 02:10:24 +000010987
10988 if (vars->link_status & LINK_STATUS_AUTO_NEGOTIATE_COMPLETE) {
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000010989 /* Report LP advertised speeds */
Mintz Yuval9e7e8392012-02-15 02:10:24 +000010990 bnx2x_cl22_read(bp, phy, 0x5, &val);
10991
10992 if (val & (1<<5))
10993 vars->link_status |=
10994 LINK_STATUS_LINK_PARTNER_10THD_CAPABLE;
10995 if (val & (1<<6))
10996 vars->link_status |=
10997 LINK_STATUS_LINK_PARTNER_10TFD_CAPABLE;
10998 if (val & (1<<7))
10999 vars->link_status |=
11000 LINK_STATUS_LINK_PARTNER_100TXHD_CAPABLE;
11001 if (val & (1<<8))
11002 vars->link_status |=
11003 LINK_STATUS_LINK_PARTNER_100TXFD_CAPABLE;
11004 if (val & (1<<9))
11005 vars->link_status |=
11006 LINK_STATUS_LINK_PARTNER_100T4_CAPABLE;
11007
11008 bnx2x_cl22_read(bp, phy, 0xa, &val);
11009 if (val & (1<<10))
11010 vars->link_status |=
11011 LINK_STATUS_LINK_PARTNER_1000THD_CAPABLE;
11012 if (val & (1<<11))
11013 vars->link_status |=
11014 LINK_STATUS_LINK_PARTNER_1000TFD_CAPABLE;
11015 }
Yaniv Rosner6583e332011-06-14 01:34:17 +000011016 }
11017 return link_up;
11018}
11019
Yaniv Rosner52c4d6c2011-07-05 01:06:34 +000011020static void bnx2x_54618se_config_loopback(struct bnx2x_phy *phy,
11021 struct link_params *params)
Yaniv Rosner6583e332011-06-14 01:34:17 +000011022{
11023 struct bnx2x *bp = params->bp;
11024 u16 val;
11025 u32 umac_base = params->port ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
11026
Yaniv Rosner52c4d6c2011-07-05 01:06:34 +000011027 DP(NETIF_MSG_LINK, "2PMA/PMD ext_phy_loopback: 54618se\n");
Yaniv Rosner6583e332011-06-14 01:34:17 +000011028
11029 /* Enable master/slave manual mmode and set to master */
11030 /* mii write 9 [bits set 11 12] */
11031 bnx2x_cl22_write(bp, phy, 0x09, 3<<11);
11032
11033 /* forced 1G and disable autoneg */
11034 /* set val [mii read 0] */
11035 /* set val [expr $val & [bits clear 6 12 13]] */
11036 /* set val [expr $val | [bits set 6 8]] */
11037 /* mii write 0 $val */
11038 bnx2x_cl22_read(bp, phy, 0x00, &val);
11039 val &= ~((1<<6) | (1<<12) | (1<<13));
11040 val |= (1<<6) | (1<<8);
11041 bnx2x_cl22_write(bp, phy, 0x00, val);
11042
11043 /* Set external loopback and Tx using 6dB coding */
11044 /* mii write 0x18 7 */
11045 /* set val [mii read 0x18] */
11046 /* mii write 0x18 [expr $val | [bits set 10 15]] */
11047 bnx2x_cl22_write(bp, phy, 0x18, 7);
11048 bnx2x_cl22_read(bp, phy, 0x18, &val);
11049 bnx2x_cl22_write(bp, phy, 0x18, val | (1<<10) | (1<<15));
11050
11051 /* This register opens the gate for the UMAC despite its name */
11052 REG_WR(bp, NIG_REG_EGRESS_EMAC0_PORT + params->port*4, 1);
11053
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000011054 /* Maximum Frame Length (RW). Defines a 14-Bit maximum frame
Yaniv Rosner6583e332011-06-14 01:34:17 +000011055 * length used by the MAC receive logic to check frames.
11056 */
11057 REG_WR(bp, umac_base + UMAC_REG_MAXFR, 0x2710);
11058}
11059
11060/******************************************************************/
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011061/* SFX7101 PHY SECTION */
11062/******************************************************************/
11063static void bnx2x_7101_config_loopback(struct bnx2x_phy *phy,
11064 struct link_params *params)
11065{
11066 struct bnx2x *bp = params->bp;
11067 /* SFX7101_XGXS_TEST1 */
11068 bnx2x_cl45_write(bp, phy,
11069 MDIO_XS_DEVAD, MDIO_XS_SFX7101_XGXS_TEST1, 0x100);
11070}
11071
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000011072static int bnx2x_7101_config_init(struct bnx2x_phy *phy,
11073 struct link_params *params,
11074 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011075{
11076 u16 fw_ver1, fw_ver2, val;
11077 struct bnx2x *bp = params->bp;
11078 DP(NETIF_MSG_LINK, "Setting the SFX7101 LASI indication\n");
11079
11080 /* Restore normal power mode*/
11081 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000011082 MISC_REGISTERS_GPIO_OUTPUT_HIGH, params->port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011083 /* HW reset */
11084 bnx2x_ext_phy_hw_reset(bp, params->port);
Yaniv Rosner6d870c32011-01-31 04:22:20 +000011085 bnx2x_wait_reset_complete(bp, phy, params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011086
11087 bnx2x_cl45_write(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +000011088 MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL, 0x1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011089 DP(NETIF_MSG_LINK, "Setting the SFX7101 LED to blink on traffic\n");
11090 bnx2x_cl45_write(bp, phy,
11091 MDIO_PMA_DEVAD, MDIO_PMA_REG_7107_LED_CNTL, (1<<3));
11092
11093 bnx2x_ext_phy_set_pause(params, phy, vars);
11094 /* Restart autoneg */
11095 bnx2x_cl45_read(bp, phy,
11096 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, &val);
11097 val |= 0x200;
11098 bnx2x_cl45_write(bp, phy,
11099 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, val);
11100
11101 /* Save spirom version */
11102 bnx2x_cl45_read(bp, phy,
11103 MDIO_PMA_DEVAD, MDIO_PMA_REG_7101_VER1, &fw_ver1);
11104
11105 bnx2x_cl45_read(bp, phy,
11106 MDIO_PMA_DEVAD, MDIO_PMA_REG_7101_VER2, &fw_ver2);
11107 bnx2x_save_spirom_version(bp, params->port,
11108 (u32)(fw_ver1<<16 | fw_ver2), phy->ver_addr);
11109 return 0;
11110}
11111
11112static u8 bnx2x_7101_read_status(struct bnx2x_phy *phy,
11113 struct link_params *params,
11114 struct link_vars *vars)
11115{
11116 struct bnx2x *bp = params->bp;
11117 u8 link_up;
11118 u16 val1, val2;
11119 bnx2x_cl45_read(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +000011120 MDIO_PMA_DEVAD, MDIO_PMA_LASI_STAT, &val2);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011121 bnx2x_cl45_read(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +000011122 MDIO_PMA_DEVAD, MDIO_PMA_LASI_STAT, &val1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011123 DP(NETIF_MSG_LINK, "10G-base-T LASI status 0x%x->0x%x\n",
11124 val2, val1);
11125 bnx2x_cl45_read(bp, phy,
11126 MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val2);
11127 bnx2x_cl45_read(bp, phy,
11128 MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val1);
11129 DP(NETIF_MSG_LINK, "10G-base-T PMA status 0x%x->0x%x\n",
11130 val2, val1);
11131 link_up = ((val1 & 4) == 4);
Yuval Mintzd2310232012-06-20 19:05:19 +000011132 /* If link is up print the AN outcome of the SFX7101 PHY */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011133 if (link_up) {
11134 bnx2x_cl45_read(bp, phy,
11135 MDIO_AN_DEVAD, MDIO_AN_REG_MASTER_STATUS,
11136 &val2);
11137 vars->line_speed = SPEED_10000;
Yaniv Rosner791f18c2011-01-18 04:33:42 +000011138 vars->duplex = DUPLEX_FULL;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011139 DP(NETIF_MSG_LINK, "SFX7101 AN status 0x%x->Master=%x\n",
11140 val2, (val2 & (1<<14)));
11141 bnx2x_ext_phy_10G_an_resolve(bp, phy, vars);
11142 bnx2x_ext_phy_resolve_fc(phy, params, vars);
Mintz Yuval9e7e8392012-02-15 02:10:24 +000011143
Yuval Mintzd2310232012-06-20 19:05:19 +000011144 /* Read LP advertised speeds */
Mintz Yuval9e7e8392012-02-15 02:10:24 +000011145 if (val2 & (1<<11))
11146 vars->link_status |=
11147 LINK_STATUS_LINK_PARTNER_10GXFD_CAPABLE;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011148 }
11149 return link_up;
11150}
11151
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000011152static int bnx2x_7101_format_ver(u32 spirom_ver, u8 *str, u16 *len)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011153{
11154 if (*len < 5)
11155 return -EINVAL;
11156 str[0] = (spirom_ver & 0xFF);
11157 str[1] = (spirom_ver & 0xFF00) >> 8;
11158 str[2] = (spirom_ver & 0xFF0000) >> 16;
11159 str[3] = (spirom_ver & 0xFF000000) >> 24;
11160 str[4] = '\0';
11161 *len -= 5;
11162 return 0;
11163}
11164
11165void bnx2x_sfx7101_sp_sw_reset(struct bnx2x *bp, struct bnx2x_phy *phy)
11166{
11167 u16 val, cnt;
11168
11169 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000011170 MDIO_PMA_DEVAD,
11171 MDIO_PMA_REG_7101_RESET, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011172
11173 for (cnt = 0; cnt < 10; cnt++) {
11174 msleep(50);
11175 /* Writes a self-clearing reset */
11176 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000011177 MDIO_PMA_DEVAD,
11178 MDIO_PMA_REG_7101_RESET,
11179 (val | (1<<15)));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011180 /* Wait for clear */
11181 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000011182 MDIO_PMA_DEVAD,
11183 MDIO_PMA_REG_7101_RESET, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011184
11185 if ((val & (1<<15)) == 0)
11186 break;
11187 }
11188}
11189
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011190static void bnx2x_7101_hw_reset(struct bnx2x_phy *phy,
11191 struct link_params *params) {
11192 /* Low power mode is controlled by GPIO 2 */
11193 bnx2x_set_gpio(params->bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000011194 MISC_REGISTERS_GPIO_OUTPUT_LOW, params->port);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011195 /* The PHY reset is controlled by GPIO 1 */
11196 bnx2x_set_gpio(params->bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000011197 MISC_REGISTERS_GPIO_OUTPUT_LOW, params->port);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011198}
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011199
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000011200static void bnx2x_7101_set_link_led(struct bnx2x_phy *phy,
11201 struct link_params *params, u8 mode)
11202{
11203 u16 val = 0;
11204 struct bnx2x *bp = params->bp;
11205 switch (mode) {
11206 case LED_MODE_FRONT_PANEL_OFF:
11207 case LED_MODE_OFF:
11208 val = 2;
11209 break;
11210 case LED_MODE_ON:
11211 val = 1;
11212 break;
11213 case LED_MODE_OPER:
11214 val = 0;
11215 break;
11216 }
11217 bnx2x_cl45_write(bp, phy,
11218 MDIO_PMA_DEVAD,
11219 MDIO_PMA_REG_7107_LINK_LED_CNTL,
11220 val);
11221}
11222
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011223/******************************************************************/
11224/* STATIC PHY DECLARATION */
11225/******************************************************************/
11226
11227static struct bnx2x_phy phy_null = {
11228 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN,
11229 .addr = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011230 .def_md_devad = 0,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000011231 .flags = FLAGS_INIT_XGXS_FIRST,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011232 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11233 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11234 .mdio_ctrl = 0,
11235 .supported = 0,
11236 .media_type = ETH_PHY_NOT_PRESENT,
11237 .ver_addr = 0,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000011238 .req_flow_ctrl = 0,
11239 .req_line_speed = 0,
11240 .speed_cap_mask = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011241 .req_duplex = 0,
11242 .rsrv = 0,
11243 .config_init = (config_init_t)NULL,
11244 .read_status = (read_status_t)NULL,
11245 .link_reset = (link_reset_t)NULL,
11246 .config_loopback = (config_loopback_t)NULL,
11247 .format_fw_ver = (format_fw_ver_t)NULL,
11248 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011249 .set_link_led = (set_link_led_t)NULL,
11250 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011251};
11252
11253static struct bnx2x_phy phy_serdes = {
11254 .type = PORT_HW_CFG_SERDES_EXT_PHY_TYPE_DIRECT,
11255 .addr = 0xff,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011256 .def_md_devad = 0,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000011257 .flags = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011258 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11259 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11260 .mdio_ctrl = 0,
11261 .supported = (SUPPORTED_10baseT_Half |
11262 SUPPORTED_10baseT_Full |
11263 SUPPORTED_100baseT_Half |
11264 SUPPORTED_100baseT_Full |
11265 SUPPORTED_1000baseT_Full |
11266 SUPPORTED_2500baseX_Full |
11267 SUPPORTED_TP |
11268 SUPPORTED_Autoneg |
11269 SUPPORTED_Pause |
11270 SUPPORTED_Asym_Pause),
Yaniv Rosner1ac9e422011-05-31 21:26:11 +000011271 .media_type = ETH_PHY_BASE_T,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011272 .ver_addr = 0,
11273 .req_flow_ctrl = 0,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000011274 .req_line_speed = 0,
11275 .speed_cap_mask = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011276 .req_duplex = 0,
11277 .rsrv = 0,
Yaniv Rosnerec146a62011-05-31 21:29:27 +000011278 .config_init = (config_init_t)bnx2x_xgxs_config_init,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011279 .read_status = (read_status_t)bnx2x_link_settings_status,
11280 .link_reset = (link_reset_t)bnx2x_int_link_reset,
11281 .config_loopback = (config_loopback_t)NULL,
11282 .format_fw_ver = (format_fw_ver_t)NULL,
11283 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011284 .set_link_led = (set_link_led_t)NULL,
11285 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011286};
11287
11288static struct bnx2x_phy phy_xgxs = {
11289 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT,
11290 .addr = 0xff,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011291 .def_md_devad = 0,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000011292 .flags = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011293 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11294 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11295 .mdio_ctrl = 0,
11296 .supported = (SUPPORTED_10baseT_Half |
11297 SUPPORTED_10baseT_Full |
11298 SUPPORTED_100baseT_Half |
11299 SUPPORTED_100baseT_Full |
11300 SUPPORTED_1000baseT_Full |
11301 SUPPORTED_2500baseX_Full |
11302 SUPPORTED_10000baseT_Full |
11303 SUPPORTED_FIBRE |
11304 SUPPORTED_Autoneg |
11305 SUPPORTED_Pause |
11306 SUPPORTED_Asym_Pause),
Yaniv Rosner1ac9e422011-05-31 21:26:11 +000011307 .media_type = ETH_PHY_CX4,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011308 .ver_addr = 0,
11309 .req_flow_ctrl = 0,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000011310 .req_line_speed = 0,
11311 .speed_cap_mask = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011312 .req_duplex = 0,
11313 .rsrv = 0,
Yaniv Rosnerec146a62011-05-31 21:29:27 +000011314 .config_init = (config_init_t)bnx2x_xgxs_config_init,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011315 .read_status = (read_status_t)bnx2x_link_settings_status,
11316 .link_reset = (link_reset_t)bnx2x_int_link_reset,
11317 .config_loopback = (config_loopback_t)bnx2x_set_xgxs_loopback,
11318 .format_fw_ver = (format_fw_ver_t)NULL,
11319 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011320 .set_link_led = (set_link_led_t)NULL,
11321 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011322};
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000011323static struct bnx2x_phy phy_warpcore = {
11324 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT,
11325 .addr = 0xff,
11326 .def_md_devad = 0,
Yaniv Rosner55098c52012-04-03 18:41:27 +000011327 .flags = (FLAGS_HW_LOCK_REQUIRED |
11328 FLAGS_TX_ERROR_CHECK),
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000011329 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11330 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11331 .mdio_ctrl = 0,
11332 .supported = (SUPPORTED_10baseT_Half |
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000011333 SUPPORTED_10baseT_Full |
11334 SUPPORTED_100baseT_Half |
11335 SUPPORTED_100baseT_Full |
11336 SUPPORTED_1000baseT_Full |
11337 SUPPORTED_10000baseT_Full |
11338 SUPPORTED_20000baseKR2_Full |
11339 SUPPORTED_20000baseMLD2_Full |
11340 SUPPORTED_FIBRE |
11341 SUPPORTED_Autoneg |
11342 SUPPORTED_Pause |
11343 SUPPORTED_Asym_Pause),
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000011344 .media_type = ETH_PHY_UNSPECIFIED,
11345 .ver_addr = 0,
11346 .req_flow_ctrl = 0,
11347 .req_line_speed = 0,
11348 .speed_cap_mask = 0,
11349 /* req_duplex = */0,
11350 /* rsrv = */0,
11351 .config_init = (config_init_t)bnx2x_warpcore_config_init,
11352 .read_status = (read_status_t)bnx2x_warpcore_read_status,
11353 .link_reset = (link_reset_t)bnx2x_warpcore_link_reset,
11354 .config_loopback = (config_loopback_t)bnx2x_set_warpcore_loopback,
11355 .format_fw_ver = (format_fw_ver_t)NULL,
Yaniv Rosner985848f2011-07-05 01:06:48 +000011356 .hw_reset = (hw_reset_t)bnx2x_warpcore_hw_reset,
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000011357 .set_link_led = (set_link_led_t)NULL,
11358 .phy_specific_func = (phy_specific_func_t)NULL
11359};
11360
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011361
11362static struct bnx2x_phy phy_7101 = {
11363 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101,
11364 .addr = 0xff,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011365 .def_md_devad = 0,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000011366 .flags = FLAGS_FAN_FAILURE_DET_REQ,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011367 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11368 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11369 .mdio_ctrl = 0,
11370 .supported = (SUPPORTED_10000baseT_Full |
11371 SUPPORTED_TP |
11372 SUPPORTED_Autoneg |
11373 SUPPORTED_Pause |
11374 SUPPORTED_Asym_Pause),
11375 .media_type = ETH_PHY_BASE_T,
11376 .ver_addr = 0,
11377 .req_flow_ctrl = 0,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000011378 .req_line_speed = 0,
11379 .speed_cap_mask = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011380 .req_duplex = 0,
11381 .rsrv = 0,
11382 .config_init = (config_init_t)bnx2x_7101_config_init,
11383 .read_status = (read_status_t)bnx2x_7101_read_status,
11384 .link_reset = (link_reset_t)bnx2x_common_ext_link_reset,
11385 .config_loopback = (config_loopback_t)bnx2x_7101_config_loopback,
11386 .format_fw_ver = (format_fw_ver_t)bnx2x_7101_format_ver,
11387 .hw_reset = (hw_reset_t)bnx2x_7101_hw_reset,
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000011388 .set_link_led = (set_link_led_t)bnx2x_7101_set_link_led,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011389 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011390};
11391static struct bnx2x_phy phy_8073 = {
11392 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073,
11393 .addr = 0xff,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011394 .def_md_devad = 0,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000011395 .flags = FLAGS_HW_LOCK_REQUIRED,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011396 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11397 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11398 .mdio_ctrl = 0,
11399 .supported = (SUPPORTED_10000baseT_Full |
11400 SUPPORTED_2500baseX_Full |
11401 SUPPORTED_1000baseT_Full |
11402 SUPPORTED_FIBRE |
11403 SUPPORTED_Autoneg |
11404 SUPPORTED_Pause |
11405 SUPPORTED_Asym_Pause),
Yaniv Rosner1ac9e422011-05-31 21:26:11 +000011406 .media_type = ETH_PHY_KR,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011407 .ver_addr = 0,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000011408 .req_flow_ctrl = 0,
11409 .req_line_speed = 0,
11410 .speed_cap_mask = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011411 .req_duplex = 0,
11412 .rsrv = 0,
Yaniv Rosner62b29a52010-09-07 11:40:58 +000011413 .config_init = (config_init_t)bnx2x_8073_config_init,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011414 .read_status = (read_status_t)bnx2x_8073_read_status,
11415 .link_reset = (link_reset_t)bnx2x_8073_link_reset,
11416 .config_loopback = (config_loopback_t)NULL,
11417 .format_fw_ver = (format_fw_ver_t)bnx2x_format_ver,
11418 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011419 .set_link_led = (set_link_led_t)NULL,
11420 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011421};
11422static struct bnx2x_phy phy_8705 = {
11423 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705,
11424 .addr = 0xff,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011425 .def_md_devad = 0,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000011426 .flags = FLAGS_INIT_XGXS_FIRST,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011427 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11428 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11429 .mdio_ctrl = 0,
11430 .supported = (SUPPORTED_10000baseT_Full |
11431 SUPPORTED_FIBRE |
11432 SUPPORTED_Pause |
11433 SUPPORTED_Asym_Pause),
11434 .media_type = ETH_PHY_XFP_FIBER,
11435 .ver_addr = 0,
11436 .req_flow_ctrl = 0,
11437 .req_line_speed = 0,
11438 .speed_cap_mask = 0,
11439 .req_duplex = 0,
11440 .rsrv = 0,
11441 .config_init = (config_init_t)bnx2x_8705_config_init,
11442 .read_status = (read_status_t)bnx2x_8705_read_status,
11443 .link_reset = (link_reset_t)bnx2x_common_ext_link_reset,
11444 .config_loopback = (config_loopback_t)NULL,
11445 .format_fw_ver = (format_fw_ver_t)bnx2x_null_format_ver,
11446 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011447 .set_link_led = (set_link_led_t)NULL,
11448 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011449};
11450static struct bnx2x_phy phy_8706 = {
11451 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706,
11452 .addr = 0xff,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011453 .def_md_devad = 0,
David S. Miller8decf862011-09-22 03:23:13 -040011454 .flags = FLAGS_INIT_XGXS_FIRST,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011455 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11456 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11457 .mdio_ctrl = 0,
11458 .supported = (SUPPORTED_10000baseT_Full |
11459 SUPPORTED_1000baseT_Full |
11460 SUPPORTED_FIBRE |
11461 SUPPORTED_Pause |
11462 SUPPORTED_Asym_Pause),
Yuval Mintzdbef8072012-06-20 19:05:22 +000011463 .media_type = ETH_PHY_SFPP_10G_FIBER,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011464 .ver_addr = 0,
11465 .req_flow_ctrl = 0,
11466 .req_line_speed = 0,
11467 .speed_cap_mask = 0,
11468 .req_duplex = 0,
11469 .rsrv = 0,
11470 .config_init = (config_init_t)bnx2x_8706_config_init,
11471 .read_status = (read_status_t)bnx2x_8706_read_status,
11472 .link_reset = (link_reset_t)bnx2x_common_ext_link_reset,
11473 .config_loopback = (config_loopback_t)NULL,
11474 .format_fw_ver = (format_fw_ver_t)bnx2x_format_ver,
11475 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011476 .set_link_led = (set_link_led_t)NULL,
11477 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011478};
11479
11480static struct bnx2x_phy phy_8726 = {
11481 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726,
11482 .addr = 0xff,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000011483 .def_md_devad = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011484 .flags = (FLAGS_HW_LOCK_REQUIRED |
Yaniv Rosner55098c52012-04-03 18:41:27 +000011485 FLAGS_INIT_XGXS_FIRST |
11486 FLAGS_TX_ERROR_CHECK),
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011487 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11488 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11489 .mdio_ctrl = 0,
11490 .supported = (SUPPORTED_10000baseT_Full |
11491 SUPPORTED_1000baseT_Full |
11492 SUPPORTED_Autoneg |
11493 SUPPORTED_FIBRE |
11494 SUPPORTED_Pause |
11495 SUPPORTED_Asym_Pause),
Yaniv Rosner1ac9e422011-05-31 21:26:11 +000011496 .media_type = ETH_PHY_NOT_PRESENT,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011497 .ver_addr = 0,
11498 .req_flow_ctrl = 0,
11499 .req_line_speed = 0,
11500 .speed_cap_mask = 0,
11501 .req_duplex = 0,
11502 .rsrv = 0,
11503 .config_init = (config_init_t)bnx2x_8726_config_init,
11504 .read_status = (read_status_t)bnx2x_8726_read_status,
11505 .link_reset = (link_reset_t)bnx2x_8726_link_reset,
11506 .config_loopback = (config_loopback_t)bnx2x_8726_config_loopback,
11507 .format_fw_ver = (format_fw_ver_t)bnx2x_format_ver,
11508 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011509 .set_link_led = (set_link_led_t)NULL,
11510 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011511};
11512
11513static struct bnx2x_phy phy_8727 = {
11514 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727,
11515 .addr = 0xff,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011516 .def_md_devad = 0,
Yaniv Rosner55098c52012-04-03 18:41:27 +000011517 .flags = (FLAGS_FAN_FAILURE_DET_REQ |
11518 FLAGS_TX_ERROR_CHECK),
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011519 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11520 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11521 .mdio_ctrl = 0,
11522 .supported = (SUPPORTED_10000baseT_Full |
11523 SUPPORTED_1000baseT_Full |
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011524 SUPPORTED_FIBRE |
11525 SUPPORTED_Pause |
11526 SUPPORTED_Asym_Pause),
Yaniv Rosner1ac9e422011-05-31 21:26:11 +000011527 .media_type = ETH_PHY_NOT_PRESENT,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011528 .ver_addr = 0,
11529 .req_flow_ctrl = 0,
11530 .req_line_speed = 0,
11531 .speed_cap_mask = 0,
11532 .req_duplex = 0,
11533 .rsrv = 0,
11534 .config_init = (config_init_t)bnx2x_8727_config_init,
11535 .read_status = (read_status_t)bnx2x_8727_read_status,
11536 .link_reset = (link_reset_t)bnx2x_8727_link_reset,
11537 .config_loopback = (config_loopback_t)NULL,
11538 .format_fw_ver = (format_fw_ver_t)bnx2x_format_ver,
11539 .hw_reset = (hw_reset_t)bnx2x_8727_hw_reset,
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000011540 .set_link_led = (set_link_led_t)bnx2x_8727_set_link_led,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011541 .phy_specific_func = (phy_specific_func_t)bnx2x_8727_specific_func
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011542};
11543static struct bnx2x_phy phy_8481 = {
11544 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8481,
11545 .addr = 0xff,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000011546 .def_md_devad = 0,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011547 .flags = FLAGS_FAN_FAILURE_DET_REQ |
11548 FLAGS_REARM_LATCH_SIGNAL,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011549 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11550 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11551 .mdio_ctrl = 0,
11552 .supported = (SUPPORTED_10baseT_Half |
11553 SUPPORTED_10baseT_Full |
11554 SUPPORTED_100baseT_Half |
11555 SUPPORTED_100baseT_Full |
11556 SUPPORTED_1000baseT_Full |
11557 SUPPORTED_10000baseT_Full |
11558 SUPPORTED_TP |
11559 SUPPORTED_Autoneg |
11560 SUPPORTED_Pause |
11561 SUPPORTED_Asym_Pause),
11562 .media_type = ETH_PHY_BASE_T,
11563 .ver_addr = 0,
11564 .req_flow_ctrl = 0,
11565 .req_line_speed = 0,
11566 .speed_cap_mask = 0,
11567 .req_duplex = 0,
11568 .rsrv = 0,
11569 .config_init = (config_init_t)bnx2x_8481_config_init,
11570 .read_status = (read_status_t)bnx2x_848xx_read_status,
11571 .link_reset = (link_reset_t)bnx2x_8481_link_reset,
11572 .config_loopback = (config_loopback_t)NULL,
11573 .format_fw_ver = (format_fw_ver_t)bnx2x_848xx_format_ver,
11574 .hw_reset = (hw_reset_t)bnx2x_8481_hw_reset,
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000011575 .set_link_led = (set_link_led_t)bnx2x_848xx_set_link_led,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011576 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011577};
11578
11579static struct bnx2x_phy phy_84823 = {
11580 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84823,
11581 .addr = 0xff,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000011582 .def_md_devad = 0,
Yaniv Rosner55098c52012-04-03 18:41:27 +000011583 .flags = (FLAGS_FAN_FAILURE_DET_REQ |
11584 FLAGS_REARM_LATCH_SIGNAL |
11585 FLAGS_TX_ERROR_CHECK),
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011586 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11587 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11588 .mdio_ctrl = 0,
11589 .supported = (SUPPORTED_10baseT_Half |
11590 SUPPORTED_10baseT_Full |
11591 SUPPORTED_100baseT_Half |
11592 SUPPORTED_100baseT_Full |
11593 SUPPORTED_1000baseT_Full |
11594 SUPPORTED_10000baseT_Full |
11595 SUPPORTED_TP |
11596 SUPPORTED_Autoneg |
11597 SUPPORTED_Pause |
11598 SUPPORTED_Asym_Pause),
11599 .media_type = ETH_PHY_BASE_T,
11600 .ver_addr = 0,
11601 .req_flow_ctrl = 0,
11602 .req_line_speed = 0,
11603 .speed_cap_mask = 0,
11604 .req_duplex = 0,
11605 .rsrv = 0,
11606 .config_init = (config_init_t)bnx2x_848x3_config_init,
11607 .read_status = (read_status_t)bnx2x_848xx_read_status,
11608 .link_reset = (link_reset_t)bnx2x_848x3_link_reset,
11609 .config_loopback = (config_loopback_t)NULL,
11610 .format_fw_ver = (format_fw_ver_t)bnx2x_848xx_format_ver,
11611 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000011612 .set_link_led = (set_link_led_t)bnx2x_848xx_set_link_led,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011613 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011614};
11615
Yaniv Rosnerc87bca12011-01-31 04:22:41 +000011616static struct bnx2x_phy phy_84833 = {
11617 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833,
11618 .addr = 0xff,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000011619 .def_md_devad = 0,
Yaniv Rosner55098c52012-04-03 18:41:27 +000011620 .flags = (FLAGS_FAN_FAILURE_DET_REQ |
11621 FLAGS_REARM_LATCH_SIGNAL |
Yuval Mintzc8c60d82012-06-06 17:13:07 +000011622 FLAGS_TX_ERROR_CHECK |
11623 FLAGS_EEE_10GBT),
Yaniv Rosnerc87bca12011-01-31 04:22:41 +000011624 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11625 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11626 .mdio_ctrl = 0,
Yaniv Rosner0520e632011-07-05 01:06:59 +000011627 .supported = (SUPPORTED_100baseT_Half |
Yaniv Rosnerc87bca12011-01-31 04:22:41 +000011628 SUPPORTED_100baseT_Full |
11629 SUPPORTED_1000baseT_Full |
11630 SUPPORTED_10000baseT_Full |
11631 SUPPORTED_TP |
11632 SUPPORTED_Autoneg |
11633 SUPPORTED_Pause |
11634 SUPPORTED_Asym_Pause),
11635 .media_type = ETH_PHY_BASE_T,
11636 .ver_addr = 0,
11637 .req_flow_ctrl = 0,
11638 .req_line_speed = 0,
11639 .speed_cap_mask = 0,
11640 .req_duplex = 0,
11641 .rsrv = 0,
11642 .config_init = (config_init_t)bnx2x_848x3_config_init,
11643 .read_status = (read_status_t)bnx2x_848xx_read_status,
11644 .link_reset = (link_reset_t)bnx2x_848x3_link_reset,
11645 .config_loopback = (config_loopback_t)NULL,
11646 .format_fw_ver = (format_fw_ver_t)bnx2x_848xx_format_ver,
Yaniv Rosner985848f2011-07-05 01:06:48 +000011647 .hw_reset = (hw_reset_t)bnx2x_84833_hw_reset_phy,
Yaniv Rosnerc87bca12011-01-31 04:22:41 +000011648 .set_link_led = (set_link_led_t)bnx2x_848xx_set_link_led,
11649 .phy_specific_func = (phy_specific_func_t)NULL
11650};
11651
Yaniv Rosner52c4d6c2011-07-05 01:06:34 +000011652static struct bnx2x_phy phy_54618se = {
11653 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54618SE,
Yaniv Rosner6583e332011-06-14 01:34:17 +000011654 .addr = 0xff,
11655 .def_md_devad = 0,
11656 .flags = FLAGS_INIT_XGXS_FIRST,
11657 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11658 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11659 .mdio_ctrl = 0,
11660 .supported = (SUPPORTED_10baseT_Half |
11661 SUPPORTED_10baseT_Full |
11662 SUPPORTED_100baseT_Half |
11663 SUPPORTED_100baseT_Full |
11664 SUPPORTED_1000baseT_Full |
11665 SUPPORTED_TP |
11666 SUPPORTED_Autoneg |
11667 SUPPORTED_Pause |
11668 SUPPORTED_Asym_Pause),
11669 .media_type = ETH_PHY_BASE_T,
11670 .ver_addr = 0,
11671 .req_flow_ctrl = 0,
11672 .req_line_speed = 0,
11673 .speed_cap_mask = 0,
11674 /* req_duplex = */0,
11675 /* rsrv = */0,
Yaniv Rosner52c4d6c2011-07-05 01:06:34 +000011676 .config_init = (config_init_t)bnx2x_54618se_config_init,
11677 .read_status = (read_status_t)bnx2x_54618se_read_status,
11678 .link_reset = (link_reset_t)bnx2x_54618se_link_reset,
11679 .config_loopback = (config_loopback_t)bnx2x_54618se_config_loopback,
Yaniv Rosner6583e332011-06-14 01:34:17 +000011680 .format_fw_ver = (format_fw_ver_t)NULL,
11681 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosner1d125bd2011-11-23 03:54:08 +000011682 .set_link_led = (set_link_led_t)bnx2x_5461x_set_link_led,
Yaniv Rosner6583e332011-06-14 01:34:17 +000011683 .phy_specific_func = (phy_specific_func_t)NULL
11684};
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011685/*****************************************************************/
11686/* */
11687/* Populate the phy according. Main function: bnx2x_populate_phy */
11688/* */
11689/*****************************************************************/
11690
11691static void bnx2x_populate_preemphasis(struct bnx2x *bp, u32 shmem_base,
11692 struct bnx2x_phy *phy, u8 port,
11693 u8 phy_index)
11694{
11695 /* Get the 4 lanes xgxs config rx and tx */
11696 u32 rx = 0, tx = 0, i;
11697 for (i = 0; i < 2; i++) {
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000011698 /* INT_PHY and EXT_PHY1 share the same value location in
11699 * the shmem. When num_phys is greater than 1, than this value
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011700 * applies only to EXT_PHY1
11701 */
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011702 if (phy_index == INT_PHY || phy_index == EXT_PHY1) {
11703 rx = REG_RD(bp, shmem_base +
11704 offsetof(struct shmem_region,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000011705 dev_info.port_hw_config[port].xgxs_config_rx[i<<1]));
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011706
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011707 tx = REG_RD(bp, shmem_base +
11708 offsetof(struct shmem_region,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000011709 dev_info.port_hw_config[port].xgxs_config_tx[i<<1]));
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011710 } else {
11711 rx = REG_RD(bp, shmem_base +
11712 offsetof(struct shmem_region,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000011713 dev_info.port_hw_config[port].xgxs_config2_rx[i<<1]));
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011714
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011715 tx = REG_RD(bp, shmem_base +
11716 offsetof(struct shmem_region,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000011717 dev_info.port_hw_config[port].xgxs_config2_rx[i<<1]));
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011718 }
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011719
11720 phy->rx_preemphasis[i << 1] = ((rx>>16) & 0xffff);
11721 phy->rx_preemphasis[(i << 1) + 1] = (rx & 0xffff);
11722
11723 phy->tx_preemphasis[i << 1] = ((tx>>16) & 0xffff);
11724 phy->tx_preemphasis[(i << 1) + 1] = (tx & 0xffff);
11725 }
11726}
11727
Yaniv Rosnere10bc842010-09-07 11:40:50 +000011728static u32 bnx2x_get_ext_phy_config(struct bnx2x *bp, u32 shmem_base,
11729 u8 phy_index, u8 port)
11730{
11731 u32 ext_phy_config = 0;
11732 switch (phy_index) {
11733 case EXT_PHY1:
11734 ext_phy_config = REG_RD(bp, shmem_base +
11735 offsetof(struct shmem_region,
11736 dev_info.port_hw_config[port].external_phy_config));
11737 break;
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011738 case EXT_PHY2:
11739 ext_phy_config = REG_RD(bp, shmem_base +
11740 offsetof(struct shmem_region,
11741 dev_info.port_hw_config[port].external_phy_config2));
11742 break;
Yaniv Rosnere10bc842010-09-07 11:40:50 +000011743 default:
11744 DP(NETIF_MSG_LINK, "Invalid phy_index %d\n", phy_index);
11745 return -EINVAL;
11746 }
11747
11748 return ext_phy_config;
11749}
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000011750static int bnx2x_populate_int_phy(struct bnx2x *bp, u32 shmem_base, u8 port,
11751 struct bnx2x_phy *phy)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011752{
11753 u32 phy_addr;
11754 u32 chip_id;
11755 u32 switch_cfg = (REG_RD(bp, shmem_base +
11756 offsetof(struct shmem_region,
11757 dev_info.port_feature_config[port].link_config)) &
11758 PORT_FEATURE_CONNECTED_SWITCH_MASK);
Yaniv Rosnerec15b892011-11-28 00:49:49 +000011759 chip_id = (REG_RD(bp, MISC_REG_CHIP_NUM) << 16) |
11760 ((REG_RD(bp, MISC_REG_CHIP_REV) & 0xf) << 12);
11761
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000011762 DP(NETIF_MSG_LINK, ":chip_id = 0x%x\n", chip_id);
11763 if (USES_WARPCORE(bp)) {
11764 u32 serdes_net_if;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011765 phy_addr = REG_RD(bp,
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000011766 MISC_REG_WC0_CTRL_PHY_ADDR);
11767 *phy = phy_warpcore;
11768 if (REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR) == 0x3)
11769 phy->flags |= FLAGS_4_PORT_MODE;
11770 else
11771 phy->flags &= ~FLAGS_4_PORT_MODE;
11772 /* Check Dual mode */
11773 serdes_net_if = (REG_RD(bp, shmem_base +
11774 offsetof(struct shmem_region, dev_info.
11775 port_hw_config[port].default_cfg)) &
11776 PORT_HW_CFG_NET_SERDES_IF_MASK);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000011777 /* Set the appropriate supported and flags indications per
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000011778 * interface type of the chip
11779 */
11780 switch (serdes_net_if) {
11781 case PORT_HW_CFG_NET_SERDES_IF_SGMII:
11782 phy->supported &= (SUPPORTED_10baseT_Half |
11783 SUPPORTED_10baseT_Full |
11784 SUPPORTED_100baseT_Half |
11785 SUPPORTED_100baseT_Full |
11786 SUPPORTED_1000baseT_Full |
11787 SUPPORTED_FIBRE |
11788 SUPPORTED_Autoneg |
11789 SUPPORTED_Pause |
11790 SUPPORTED_Asym_Pause);
11791 phy->media_type = ETH_PHY_BASE_T;
11792 break;
11793 case PORT_HW_CFG_NET_SERDES_IF_XFI:
11794 phy->media_type = ETH_PHY_XFP_FIBER;
11795 break;
11796 case PORT_HW_CFG_NET_SERDES_IF_SFI:
11797 phy->supported &= (SUPPORTED_1000baseT_Full |
11798 SUPPORTED_10000baseT_Full |
11799 SUPPORTED_FIBRE |
11800 SUPPORTED_Pause |
11801 SUPPORTED_Asym_Pause);
Yuval Mintzdbef8072012-06-20 19:05:22 +000011802 phy->media_type = ETH_PHY_SFPP_10G_FIBER;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000011803 break;
11804 case PORT_HW_CFG_NET_SERDES_IF_KR:
11805 phy->media_type = ETH_PHY_KR;
11806 phy->supported &= (SUPPORTED_1000baseT_Full |
11807 SUPPORTED_10000baseT_Full |
11808 SUPPORTED_FIBRE |
11809 SUPPORTED_Autoneg |
11810 SUPPORTED_Pause |
11811 SUPPORTED_Asym_Pause);
11812 break;
11813 case PORT_HW_CFG_NET_SERDES_IF_DXGXS:
11814 phy->media_type = ETH_PHY_KR;
11815 phy->flags |= FLAGS_WC_DUAL_MODE;
11816 phy->supported &= (SUPPORTED_20000baseMLD2_Full |
11817 SUPPORTED_FIBRE |
11818 SUPPORTED_Pause |
11819 SUPPORTED_Asym_Pause);
11820 break;
11821 case PORT_HW_CFG_NET_SERDES_IF_KR2:
11822 phy->media_type = ETH_PHY_KR;
11823 phy->flags |= FLAGS_WC_DUAL_MODE;
11824 phy->supported &= (SUPPORTED_20000baseKR2_Full |
11825 SUPPORTED_FIBRE |
11826 SUPPORTED_Pause |
11827 SUPPORTED_Asym_Pause);
11828 break;
11829 default:
11830 DP(NETIF_MSG_LINK, "Unknown WC interface type 0x%x\n",
11831 serdes_net_if);
11832 break;
11833 }
11834
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000011835 /* Enable MDC/MDIO work-around for E3 A0 since free running MDC
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000011836 * was not set as expected. For B0, ECO will be enabled so there
11837 * won't be an issue there
11838 */
11839 if (CHIP_REV(bp) == CHIP_REV_Ax)
11840 phy->flags |= FLAGS_MDC_MDIO_WA;
Yaniv Rosner157fa282011-08-02 22:59:32 +000011841 else
11842 phy->flags |= FLAGS_MDC_MDIO_WA_B0;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000011843 } else {
11844 switch (switch_cfg) {
11845 case SWITCH_CFG_1G:
11846 phy_addr = REG_RD(bp,
11847 NIG_REG_SERDES0_CTRL_PHY_ADDR +
11848 port * 0x10);
11849 *phy = phy_serdes;
11850 break;
11851 case SWITCH_CFG_10G:
11852 phy_addr = REG_RD(bp,
11853 NIG_REG_XGXS0_CTRL_PHY_ADDR +
11854 port * 0x18);
11855 *phy = phy_xgxs;
11856 break;
11857 default:
11858 DP(NETIF_MSG_LINK, "Invalid switch_cfg\n");
11859 return -EINVAL;
11860 }
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011861 }
11862 phy->addr = (u8)phy_addr;
11863 phy->mdio_ctrl = bnx2x_get_emac_base(bp,
Yaniv Rosnerc18aa152010-09-07 11:41:07 +000011864 SHARED_HW_CFG_MDC_MDIO_ACCESS1_BOTH,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011865 port);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000011866 if (CHIP_IS_E2(bp))
11867 phy->def_md_devad = E2_DEFAULT_PHY_DEV_ADDR;
11868 else
11869 phy->def_md_devad = DEFAULT_PHY_DEV_ADDR;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011870
11871 DP(NETIF_MSG_LINK, "Internal phy port=%d, addr=0x%x, mdio_ctl=0x%x\n",
11872 port, phy->addr, phy->mdio_ctrl);
11873
11874 bnx2x_populate_preemphasis(bp, shmem_base, phy, port, INT_PHY);
11875 return 0;
11876}
Yaniv Rosnere10bc842010-09-07 11:40:50 +000011877
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000011878static int bnx2x_populate_ext_phy(struct bnx2x *bp,
11879 u8 phy_index,
11880 u32 shmem_base,
11881 u32 shmem2_base,
11882 u8 port,
11883 struct bnx2x_phy *phy)
Yaniv Rosnere10bc842010-09-07 11:40:50 +000011884{
Yaniv Rosnerc18aa152010-09-07 11:41:07 +000011885 u32 ext_phy_config, phy_type, config2;
11886 u32 mdc_mdio_access = SHARED_HW_CFG_MDC_MDIO_ACCESS1_BOTH;
Yaniv Rosnere10bc842010-09-07 11:40:50 +000011887 ext_phy_config = bnx2x_get_ext_phy_config(bp, shmem_base,
11888 phy_index, port);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011889 phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
11890 /* Select the phy type */
11891 switch (phy_type) {
11892 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073:
Yaniv Rosnerc18aa152010-09-07 11:41:07 +000011893 mdc_mdio_access = SHARED_HW_CFG_MDC_MDIO_ACCESS1_SWAPPED;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011894 *phy = phy_8073;
11895 break;
11896 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705:
11897 *phy = phy_8705;
11898 break;
11899 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706:
11900 *phy = phy_8706;
11901 break;
11902 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
Yaniv Rosnerc18aa152010-09-07 11:41:07 +000011903 mdc_mdio_access = SHARED_HW_CFG_MDC_MDIO_ACCESS1_EMAC1;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011904 *phy = phy_8726;
11905 break;
11906 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727_NOC:
11907 /* BCM8727_NOC => BCM8727 no over current */
Yaniv Rosnerc18aa152010-09-07 11:41:07 +000011908 mdc_mdio_access = SHARED_HW_CFG_MDC_MDIO_ACCESS1_EMAC1;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011909 *phy = phy_8727;
11910 phy->flags |= FLAGS_NOC;
11911 break;
Yaniv Rosnere4d78f12011-05-31 21:25:55 +000011912 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8722:
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011913 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
Yaniv Rosnerc18aa152010-09-07 11:41:07 +000011914 mdc_mdio_access = SHARED_HW_CFG_MDC_MDIO_ACCESS1_EMAC1;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011915 *phy = phy_8727;
11916 break;
11917 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8481:
11918 *phy = phy_8481;
11919 break;
11920 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84823:
11921 *phy = phy_84823;
11922 break;
Yaniv Rosnerc87bca12011-01-31 04:22:41 +000011923 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833:
11924 *phy = phy_84833;
11925 break;
Yaniv Rosner3756a892011-08-23 06:33:24 +000011926 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54616:
Yaniv Rosner52c4d6c2011-07-05 01:06:34 +000011927 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54618SE:
11928 *phy = phy_54618se;
Yaniv Rosner6583e332011-06-14 01:34:17 +000011929 break;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011930 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101:
11931 *phy = phy_7101;
11932 break;
11933 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE:
11934 *phy = phy_null;
11935 return -EINVAL;
11936 default:
11937 *phy = phy_null;
Yaniv Rosner6db51932011-11-28 00:49:50 +000011938 /* In case external PHY wasn't found */
11939 if ((phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT) &&
11940 (phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
11941 return -EINVAL;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011942 return 0;
11943 }
11944
Yaniv Rosnere10bc842010-09-07 11:40:50 +000011945 phy->addr = XGXS_EXT_PHY_ADDR(ext_phy_config);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011946 bnx2x_populate_preemphasis(bp, shmem_base, phy, port, phy_index);
Yaniv Rosner62b29a52010-09-07 11:40:58 +000011947
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000011948 /* The shmem address of the phy version is located on different
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +000011949 * structures. In case this structure is too old, do not set
11950 * the address
11951 */
Yaniv Rosnerc18aa152010-09-07 11:41:07 +000011952 config2 = REG_RD(bp, shmem_base + offsetof(struct shmem_region,
11953 dev_info.shared_hw_config.config2));
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011954 if (phy_index == EXT_PHY1) {
11955 phy->ver_addr = shmem_base + offsetof(struct shmem_region,
11956 port_mb[port].ext_phy_fw_version);
Yaniv Rosnerc18aa152010-09-07 11:41:07 +000011957
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000011958 /* Check specific mdc mdio settings */
11959 if (config2 & SHARED_HW_CFG_MDC_MDIO_ACCESS1_MASK)
11960 mdc_mdio_access = config2 &
11961 SHARED_HW_CFG_MDC_MDIO_ACCESS1_MASK;
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011962 } else {
11963 u32 size = REG_RD(bp, shmem2_base);
Yaniv Rosnerc18aa152010-09-07 11:41:07 +000011964
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011965 if (size >
11966 offsetof(struct shmem2_region, ext_phy_fw_version2)) {
11967 phy->ver_addr = shmem2_base +
11968 offsetof(struct shmem2_region,
11969 ext_phy_fw_version2[port]);
11970 }
11971 /* Check specific mdc mdio settings */
11972 if (config2 & SHARED_HW_CFG_MDC_MDIO_ACCESS2_MASK)
11973 mdc_mdio_access = (config2 &
11974 SHARED_HW_CFG_MDC_MDIO_ACCESS2_MASK) >>
11975 (SHARED_HW_CFG_MDC_MDIO_ACCESS2_SHIFT -
11976 SHARED_HW_CFG_MDC_MDIO_ACCESS1_SHIFT);
11977 }
Yaniv Rosnerc18aa152010-09-07 11:41:07 +000011978 phy->mdio_ctrl = bnx2x_get_emac_base(bp, mdc_mdio_access, port);
11979
Yaniv Rosner75318322012-01-17 02:33:27 +000011980 if ((phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833) &&
11981 (phy->ver_addr)) {
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000011982 /* Remove 100Mb link supported for BCM84833 when phy fw
Yaniv Rosner75318322012-01-17 02:33:27 +000011983 * version lower than or equal to 1.39
11984 */
11985 u32 raw_ver = REG_RD(bp, phy->ver_addr);
11986 if (((raw_ver & 0x7F) <= 39) &&
11987 (((raw_ver & 0xF80) >> 7) <= 1))
11988 phy->supported &= ~(SUPPORTED_100baseT_Half |
11989 SUPPORTED_100baseT_Full);
11990 }
11991
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000011992 /* In case mdc/mdio_access of the external phy is different than the
Yaniv Rosnerc18aa152010-09-07 11:41:07 +000011993 * mdc/mdio access of the XGXS, a HW lock must be taken in each access
11994 * to prevent one port interfere with another port's CL45 operations.
11995 */
11996 if (mdc_mdio_access != SHARED_HW_CFG_MDC_MDIO_ACCESS1_BOTH)
11997 phy->flags |= FLAGS_HW_LOCK_REQUIRED;
11998 DP(NETIF_MSG_LINK, "phy_type 0x%x port %d found in index %d\n",
11999 phy_type, port, phy_index);
12000 DP(NETIF_MSG_LINK, " addr=0x%x, mdio_ctl=0x%x\n",
12001 phy->addr, phy->mdio_ctrl);
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012002 return 0;
12003}
12004
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000012005static int bnx2x_populate_phy(struct bnx2x *bp, u8 phy_index, u32 shmem_base,
12006 u32 shmem2_base, u8 port, struct bnx2x_phy *phy)
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012007{
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000012008 int status = 0;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000012009 phy->type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN;
12010 if (phy_index == INT_PHY)
12011 return bnx2x_populate_int_phy(bp, shmem_base, port, phy);
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012012 status = bnx2x_populate_ext_phy(bp, phy_index, shmem_base, shmem2_base,
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012013 port, phy);
12014 return status;
12015}
12016
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000012017static void bnx2x_phy_def_cfg(struct link_params *params,
12018 struct bnx2x_phy *phy,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012019 u8 phy_index)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000012020{
12021 struct bnx2x *bp = params->bp;
12022 u32 link_config;
12023 /* Populate the default phy configuration for MF mode */
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012024 if (phy_index == EXT_PHY2) {
12025 link_config = REG_RD(bp, params->shmem_base +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012026 offsetof(struct shmem_region, dev_info.
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012027 port_feature_config[params->port].link_config2));
12028 phy->speed_cap_mask = REG_RD(bp, params->shmem_base +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012029 offsetof(struct shmem_region,
12030 dev_info.
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012031 port_hw_config[params->port].speed_capability_mask2));
12032 } else {
12033 link_config = REG_RD(bp, params->shmem_base +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012034 offsetof(struct shmem_region, dev_info.
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012035 port_feature_config[params->port].link_config));
12036 phy->speed_cap_mask = REG_RD(bp, params->shmem_base +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012037 offsetof(struct shmem_region,
12038 dev_info.
12039 port_hw_config[params->port].speed_capability_mask));
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012040 }
Joe Perches94f05b02011-08-14 12:16:20 +000012041 DP(NETIF_MSG_LINK,
12042 "Default config phy idx %x cfg 0x%x speed_cap_mask 0x%x\n",
12043 phy_index, link_config, phy->speed_cap_mask);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000012044
12045 phy->req_duplex = DUPLEX_FULL;
12046 switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
12047 case PORT_FEATURE_LINK_SPEED_10M_HALF:
12048 phy->req_duplex = DUPLEX_HALF;
12049 case PORT_FEATURE_LINK_SPEED_10M_FULL:
12050 phy->req_line_speed = SPEED_10;
12051 break;
12052 case PORT_FEATURE_LINK_SPEED_100M_HALF:
12053 phy->req_duplex = DUPLEX_HALF;
12054 case PORT_FEATURE_LINK_SPEED_100M_FULL:
12055 phy->req_line_speed = SPEED_100;
12056 break;
12057 case PORT_FEATURE_LINK_SPEED_1G:
12058 phy->req_line_speed = SPEED_1000;
12059 break;
12060 case PORT_FEATURE_LINK_SPEED_2_5G:
12061 phy->req_line_speed = SPEED_2500;
12062 break;
12063 case PORT_FEATURE_LINK_SPEED_10G_CX4:
12064 phy->req_line_speed = SPEED_10000;
12065 break;
12066 default:
12067 phy->req_line_speed = SPEED_AUTO_NEG;
12068 break;
12069 }
12070
12071 switch (link_config & PORT_FEATURE_FLOW_CONTROL_MASK) {
12072 case PORT_FEATURE_FLOW_CONTROL_AUTO:
12073 phy->req_flow_ctrl = BNX2X_FLOW_CTRL_AUTO;
12074 break;
12075 case PORT_FEATURE_FLOW_CONTROL_TX:
12076 phy->req_flow_ctrl = BNX2X_FLOW_CTRL_TX;
12077 break;
12078 case PORT_FEATURE_FLOW_CONTROL_RX:
12079 phy->req_flow_ctrl = BNX2X_FLOW_CTRL_RX;
12080 break;
12081 case PORT_FEATURE_FLOW_CONTROL_BOTH:
12082 phy->req_flow_ctrl = BNX2X_FLOW_CTRL_BOTH;
12083 break;
12084 default:
12085 phy->req_flow_ctrl = BNX2X_FLOW_CTRL_NONE;
12086 break;
12087 }
12088}
12089
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012090u32 bnx2x_phy_selection(struct link_params *params)
12091{
12092 u32 phy_config_swapped, prio_cfg;
12093 u32 return_cfg = PORT_HW_CFG_PHY_SELECTION_HARDWARE_DEFAULT;
12094
12095 phy_config_swapped = params->multi_phy_config &
12096 PORT_HW_CFG_PHY_SWAPPED_ENABLED;
12097
12098 prio_cfg = params->multi_phy_config &
12099 PORT_HW_CFG_PHY_SELECTION_MASK;
12100
12101 if (phy_config_swapped) {
12102 switch (prio_cfg) {
12103 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY_PRIORITY:
12104 return_cfg = PORT_HW_CFG_PHY_SELECTION_SECOND_PHY_PRIORITY;
12105 break;
12106 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY_PRIORITY:
12107 return_cfg = PORT_HW_CFG_PHY_SELECTION_FIRST_PHY_PRIORITY;
12108 break;
12109 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY:
12110 return_cfg = PORT_HW_CFG_PHY_SELECTION_FIRST_PHY;
12111 break;
12112 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY:
12113 return_cfg = PORT_HW_CFG_PHY_SELECTION_SECOND_PHY;
12114 break;
12115 }
12116 } else
12117 return_cfg = prio_cfg;
12118
12119 return return_cfg;
12120}
12121
12122
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000012123int bnx2x_phy_probe(struct link_params *params)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000012124{
Yaniv Rosner2f751a82011-11-28 00:49:52 +000012125 u8 phy_index, actual_phy_idx;
Yaniv Rosner1ac9e422011-05-31 21:26:11 +000012126 u32 phy_config_swapped, sync_offset, media_types;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000012127 struct bnx2x *bp = params->bp;
12128 struct bnx2x_phy *phy;
12129 params->num_phys = 0;
12130 DP(NETIF_MSG_LINK, "Begin phy probe\n");
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012131 phy_config_swapped = params->multi_phy_config &
12132 PORT_HW_CFG_PHY_SWAPPED_ENABLED;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000012133
12134 for (phy_index = INT_PHY; phy_index < MAX_PHYS;
12135 phy_index++) {
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000012136 actual_phy_idx = phy_index;
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012137 if (phy_config_swapped) {
12138 if (phy_index == EXT_PHY1)
12139 actual_phy_idx = EXT_PHY2;
12140 else if (phy_index == EXT_PHY2)
12141 actual_phy_idx = EXT_PHY1;
12142 }
12143 DP(NETIF_MSG_LINK, "phy_config_swapped %x, phy_index %x,"
12144 " actual_phy_idx %x\n", phy_config_swapped,
12145 phy_index, actual_phy_idx);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000012146 phy = &params->phy[actual_phy_idx];
12147 if (bnx2x_populate_phy(bp, phy_index, params->shmem_base,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012148 params->shmem2_base, params->port,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000012149 phy) != 0) {
12150 params->num_phys = 0;
12151 DP(NETIF_MSG_LINK, "phy probe failed in phy index %d\n",
12152 phy_index);
12153 for (phy_index = INT_PHY;
12154 phy_index < MAX_PHYS;
12155 phy_index++)
12156 *phy = phy_null;
12157 return -EINVAL;
12158 }
12159 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN)
12160 break;
12161
Yaniv Rosner55098c52012-04-03 18:41:27 +000012162 if (params->feature_config_flags &
12163 FEATURE_CONFIG_DISABLE_REMOTE_FAULT_DET)
12164 phy->flags &= ~FLAGS_TX_ERROR_CHECK;
12165
Yaniv Rosner1ac9e422011-05-31 21:26:11 +000012166 sync_offset = params->shmem_base +
12167 offsetof(struct shmem_region,
12168 dev_info.port_hw_config[params->port].media_type);
12169 media_types = REG_RD(bp, sync_offset);
12170
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000012171 /* Update media type for non-PMF sync only for the first time
Yaniv Rosner1ac9e422011-05-31 21:26:11 +000012172 * In case the media type changes afterwards, it will be updated
12173 * using the update_status function
12174 */
12175 if ((media_types & (PORT_HW_CFG_MEDIA_TYPE_PHY0_MASK <<
12176 (PORT_HW_CFG_MEDIA_TYPE_PHY1_SHIFT *
12177 actual_phy_idx))) == 0) {
12178 media_types |= ((phy->media_type &
12179 PORT_HW_CFG_MEDIA_TYPE_PHY0_MASK) <<
12180 (PORT_HW_CFG_MEDIA_TYPE_PHY1_SHIFT *
12181 actual_phy_idx));
12182 }
12183 REG_WR(bp, sync_offset, media_types);
12184
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012185 bnx2x_phy_def_cfg(params, phy, phy_index);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000012186 params->num_phys++;
12187 }
12188
12189 DP(NETIF_MSG_LINK, "End phy probe. #phys found %x\n", params->num_phys);
12190 return 0;
12191}
12192
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000012193void bnx2x_init_bmac_loopback(struct link_params *params,
12194 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012195{
12196 struct bnx2x *bp = params->bp;
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000012197 vars->link_up = 1;
12198 vars->line_speed = SPEED_10000;
12199 vars->duplex = DUPLEX_FULL;
12200 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
12201 vars->mac_type = MAC_TYPE_BMAC;
12202
12203 vars->phy_flags = PHY_XGXS_FLAG;
12204
12205 bnx2x_xgxs_deassert(params);
12206
12207 /* set bmac loopback */
12208 bnx2x_bmac_enable(params, vars, 1);
12209
12210 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 0);
12211}
12212
12213void bnx2x_init_emac_loopback(struct link_params *params,
12214 struct link_vars *vars)
12215{
12216 struct bnx2x *bp = params->bp;
12217 vars->link_up = 1;
12218 vars->line_speed = SPEED_1000;
12219 vars->duplex = DUPLEX_FULL;
12220 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
12221 vars->mac_type = MAC_TYPE_EMAC;
12222
12223 vars->phy_flags = PHY_XGXS_FLAG;
12224
12225 bnx2x_xgxs_deassert(params);
12226 /* set bmac loopback */
12227 bnx2x_emac_enable(params, vars, 1);
12228 bnx2x_emac_program(params, vars);
12229 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 0);
12230}
12231
Yaniv Rosner9380bb92011-06-14 01:34:07 +000012232void bnx2x_init_xmac_loopback(struct link_params *params,
12233 struct link_vars *vars)
12234{
12235 struct bnx2x *bp = params->bp;
12236 vars->link_up = 1;
12237 if (!params->req_line_speed[0])
12238 vars->line_speed = SPEED_10000;
12239 else
12240 vars->line_speed = params->req_line_speed[0];
12241 vars->duplex = DUPLEX_FULL;
12242 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
12243 vars->mac_type = MAC_TYPE_XMAC;
12244 vars->phy_flags = PHY_XGXS_FLAG;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000012245 /* Set WC to loopback mode since link is required to provide clock
Yaniv Rosner9380bb92011-06-14 01:34:07 +000012246 * to the XMAC in 20G mode
12247 */
Yaniv Rosnerafad0092011-08-02 23:00:06 +000012248 bnx2x_set_aer_mmd(params, &params->phy[0]);
12249 bnx2x_warpcore_reset_lane(bp, &params->phy[0], 0);
12250 params->phy[INT_PHY].config_loopback(
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000012251 &params->phy[INT_PHY],
12252 params);
Yaniv Rosnerafad0092011-08-02 23:00:06 +000012253
Yaniv Rosner9380bb92011-06-14 01:34:07 +000012254 bnx2x_xmac_enable(params, vars, 1);
12255 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 0);
12256}
12257
12258void bnx2x_init_umac_loopback(struct link_params *params,
12259 struct link_vars *vars)
12260{
12261 struct bnx2x *bp = params->bp;
12262 vars->link_up = 1;
12263 vars->line_speed = SPEED_1000;
12264 vars->duplex = DUPLEX_FULL;
12265 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
12266 vars->mac_type = MAC_TYPE_UMAC;
12267 vars->phy_flags = PHY_XGXS_FLAG;
12268 bnx2x_umac_enable(params, vars, 1);
12269
12270 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 0);
12271}
12272
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000012273void bnx2x_init_xgxs_loopback(struct link_params *params,
12274 struct link_vars *vars)
12275{
12276 struct bnx2x *bp = params->bp;
12277 vars->link_up = 1;
12278 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
12279 vars->duplex = DUPLEX_FULL;
12280 if (params->req_line_speed[0] == SPEED_1000)
12281 vars->line_speed = SPEED_1000;
12282 else
12283 vars->line_speed = SPEED_10000;
12284
Yaniv Rosner9380bb92011-06-14 01:34:07 +000012285 if (!USES_WARPCORE(bp))
12286 bnx2x_xgxs_deassert(params);
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000012287 bnx2x_link_initialize(params, vars);
12288
12289 if (params->req_line_speed[0] == SPEED_1000) {
Yaniv Rosner9380bb92011-06-14 01:34:07 +000012290 if (USES_WARPCORE(bp))
12291 bnx2x_umac_enable(params, vars, 0);
12292 else {
12293 bnx2x_emac_program(params, vars);
12294 bnx2x_emac_enable(params, vars, 0);
12295 }
12296 } else {
12297 if (USES_WARPCORE(bp))
12298 bnx2x_xmac_enable(params, vars, 0);
12299 else
12300 bnx2x_bmac_enable(params, vars, 0);
12301 }
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000012302
12303 if (params->loopback_mode == LOOPBACK_XGXS) {
12304 /* set 10G XGXS loopback */
12305 params->phy[INT_PHY].config_loopback(
12306 &params->phy[INT_PHY],
12307 params);
12308
12309 } else {
12310 /* set external phy loopback */
12311 u8 phy_index;
12312 for (phy_index = EXT_PHY1;
12313 phy_index < params->num_phys; phy_index++) {
12314 if (params->phy[phy_index].config_loopback)
12315 params->phy[phy_index].config_loopback(
12316 &params->phy[phy_index],
12317 params);
12318 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012319 }
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000012320 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012321
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000012322 bnx2x_set_led(params, vars, LED_MODE_OPER, vars->line_speed);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012323}
12324
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000012325int bnx2x_phy_init(struct link_params *params, struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012326{
12327 struct bnx2x *bp = params->bp;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012328 DP(NETIF_MSG_LINK, "Phy Initialization started\n");
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012329 DP(NETIF_MSG_LINK, "(1) req_speed %d, req_flowctrl %d\n",
12330 params->req_line_speed[0], params->req_flow_ctrl[0]);
12331 DP(NETIF_MSG_LINK, "(2) req_speed %d, req_flowctrl %d\n",
12332 params->req_line_speed[1], params->req_flow_ctrl[1]);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012333 vars->link_status = 0;
12334 vars->phy_link_up = 0;
12335 vars->link_up = 0;
12336 vars->line_speed = 0;
12337 vars->duplex = DUPLEX_FULL;
12338 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
12339 vars->mac_type = MAC_TYPE_NONE;
12340 vars->phy_flags = 0;
12341
Yuval Mintzd2310232012-06-20 19:05:19 +000012342 /* Disable attentions */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012343 bnx2x_bits_dis(bp, NIG_REG_MASK_INTERRUPT_PORT0 + params->port*4,
12344 (NIG_MASK_XGXS0_LINK_STATUS |
12345 NIG_MASK_XGXS0_LINK10G |
12346 NIG_MASK_SERDES0_LINK_STATUS |
12347 NIG_MASK_MI_INT));
12348
12349 bnx2x_emac_init(params, vars);
12350
Yaniv Rosner27d91292012-04-04 01:28:54 +000012351 if (params->feature_config_flags & FEATURE_CONFIG_PFC_ENABLED)
12352 vars->link_status |= LINK_STATUS_PFC_ENABLED;
12353
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012354 if (params->num_phys == 0) {
12355 DP(NETIF_MSG_LINK, "No phy found for initialization !!\n");
12356 return -EINVAL;
12357 }
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000012358 set_phy_vars(params, vars);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012359
12360 DP(NETIF_MSG_LINK, "Num of phys on board: %d\n", params->num_phys);
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000012361 switch (params->loopback_mode) {
12362 case LOOPBACK_BMAC:
12363 bnx2x_init_bmac_loopback(params, vars);
12364 break;
12365 case LOOPBACK_EMAC:
12366 bnx2x_init_emac_loopback(params, vars);
12367 break;
Yaniv Rosner9380bb92011-06-14 01:34:07 +000012368 case LOOPBACK_XMAC:
12369 bnx2x_init_xmac_loopback(params, vars);
12370 break;
12371 case LOOPBACK_UMAC:
12372 bnx2x_init_umac_loopback(params, vars);
12373 break;
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000012374 case LOOPBACK_XGXS:
12375 case LOOPBACK_EXT_PHY:
12376 bnx2x_init_xgxs_loopback(params, vars);
12377 break;
12378 default:
Yaniv Rosner9380bb92011-06-14 01:34:07 +000012379 if (!CHIP_IS_E3(bp)) {
12380 if (params->switch_cfg == SWITCH_CFG_10G)
12381 bnx2x_xgxs_deassert(params);
12382 else
12383 bnx2x_serdes_deassert(bp, params->port);
12384 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012385 bnx2x_link_initialize(params, vars);
12386 msleep(30);
12387 bnx2x_link_int_enable(params);
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000012388 break;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012389 }
Yaniv Rosner55098c52012-04-03 18:41:27 +000012390 bnx2x_update_mng(params, vars->link_status);
Yuval Mintzc8c60d82012-06-06 17:13:07 +000012391
12392 bnx2x_update_mng_eee(params, vars->eee_status);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012393 return 0;
12394}
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000012395
12396int bnx2x_link_reset(struct link_params *params, struct link_vars *vars,
12397 u8 reset_ext_phy)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012398{
12399 struct bnx2x *bp = params->bp;
Yaniv Rosnercf1d9722010-11-01 05:32:34 +000012400 u8 phy_index, port = params->port, clear_latch_ind = 0;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012401 DP(NETIF_MSG_LINK, "Resetting the link of port %d\n", port);
Yuval Mintzd2310232012-06-20 19:05:19 +000012402 /* Disable attentions */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012403 vars->link_status = 0;
12404 bnx2x_update_mng(params, vars->link_status);
Yuval Mintzc8c60d82012-06-06 17:13:07 +000012405 vars->eee_status &= ~(SHMEM_EEE_LP_ADV_STATUS_MASK |
12406 SHMEM_EEE_ACTIVE_BIT);
12407 bnx2x_update_mng_eee(params, vars->eee_status);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012408 bnx2x_bits_dis(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012409 (NIG_MASK_XGXS0_LINK_STATUS |
12410 NIG_MASK_XGXS0_LINK10G |
12411 NIG_MASK_SERDES0_LINK_STATUS |
12412 NIG_MASK_MI_INT));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012413
Yuval Mintzd2310232012-06-20 19:05:19 +000012414 /* Activate nig drain */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012415 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + port*4, 1);
12416
Yuval Mintzd2310232012-06-20 19:05:19 +000012417 /* Disable nig egress interface */
Yaniv Rosner9380bb92011-06-14 01:34:07 +000012418 if (!CHIP_IS_E3(bp)) {
12419 REG_WR(bp, NIG_REG_BMAC0_OUT_EN + port*4, 0);
12420 REG_WR(bp, NIG_REG_EGRESS_EMAC0_OUT_EN + port*4, 0);
12421 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012422
12423 /* Stop BigMac rx */
Yaniv Rosner9380bb92011-06-14 01:34:07 +000012424 if (!CHIP_IS_E3(bp))
12425 bnx2x_bmac_rx_disable(bp, port);
Yaniv Rosnerce7c0482011-10-27 05:09:47 +000012426 else {
Yaniv Rosner9380bb92011-06-14 01:34:07 +000012427 bnx2x_xmac_disable(params);
Yaniv Rosnerce7c0482011-10-27 05:09:47 +000012428 bnx2x_umac_disable(params);
12429 }
Yuval Mintzd2310232012-06-20 19:05:19 +000012430 /* Disable emac */
Yaniv Rosner9380bb92011-06-14 01:34:07 +000012431 if (!CHIP_IS_E3(bp))
12432 REG_WR(bp, NIG_REG_NIG_EMAC0_EN + port*4, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012433
Yuval Mintzd2310232012-06-20 19:05:19 +000012434 usleep_range(10000, 20000);
Lucas De Marchi25985ed2011-03-30 22:57:33 -030012435 /* The PHY reset is controlled by GPIO 1
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012436 * Hold it as vars low
12437 */
Yuval Mintzd2310232012-06-20 19:05:19 +000012438 /* Clear link led */
Yaniv Rosnerca7b91b2012-04-04 01:40:02 +000012439 bnx2x_set_mdio_clk(bp, params->chip_id, port);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000012440 bnx2x_set_led(params, vars, LED_MODE_OFF, 0);
12441
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012442 if (reset_ext_phy) {
12443 for (phy_index = EXT_PHY1; phy_index < params->num_phys;
12444 phy_index++) {
Yaniv Rosner28f48812011-08-02 23:00:12 +000012445 if (params->phy[phy_index].link_reset) {
12446 bnx2x_set_aer_mmd(params,
12447 &params->phy[phy_index]);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012448 params->phy[phy_index].link_reset(
12449 &params->phy[phy_index],
12450 params);
Yaniv Rosner28f48812011-08-02 23:00:12 +000012451 }
Yaniv Rosnercf1d9722010-11-01 05:32:34 +000012452 if (params->phy[phy_index].flags &
12453 FLAGS_REARM_LATCH_SIGNAL)
12454 clear_latch_ind = 1;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012455 }
12456 }
12457
Yaniv Rosnercf1d9722010-11-01 05:32:34 +000012458 if (clear_latch_ind) {
12459 /* Clear latching indication */
12460 bnx2x_rearm_latch_signal(bp, port, 0);
12461 bnx2x_bits_dis(bp, NIG_REG_LATCH_BC_0 + port*4,
12462 1 << NIG_LATCH_BC_ENABLE_MI_INT);
12463 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012464 if (params->phy[INT_PHY].link_reset)
12465 params->phy[INT_PHY].link_reset(
12466 &params->phy[INT_PHY], params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012467
Yuval Mintzd2310232012-06-20 19:05:19 +000012468 /* Disable nig ingress interface */
Yaniv Rosner9380bb92011-06-14 01:34:07 +000012469 if (!CHIP_IS_E3(bp)) {
Yuval Mintzd2310232012-06-20 19:05:19 +000012470 /* Reset BigMac */
Yaniv Rosnerce7c0482011-10-27 05:09:47 +000012471 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
12472 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port));
Yaniv Rosner9380bb92011-06-14 01:34:07 +000012473 REG_WR(bp, NIG_REG_BMAC0_IN_EN + port*4, 0);
12474 REG_WR(bp, NIG_REG_EMAC0_IN_EN + port*4, 0);
Yaniv Rosnerce7c0482011-10-27 05:09:47 +000012475 } else {
12476 u32 xmac_base = (params->port) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
12477 bnx2x_set_xumac_nig(params, 0, 0);
12478 if (REG_RD(bp, MISC_REG_RESET_REG_2) &
12479 MISC_REGISTERS_RESET_REG_2_XMAC)
12480 REG_WR(bp, xmac_base + XMAC_REG_CTRL,
12481 XMAC_CTRL_REG_SOFT_RESET);
Yaniv Rosner9380bb92011-06-14 01:34:07 +000012482 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012483 vars->link_up = 0;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000012484 vars->phy_flags = 0;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012485 return 0;
12486}
12487
12488/****************************************************************************/
12489/* Common function */
12490/****************************************************************************/
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000012491static int bnx2x_8073_common_init_phy(struct bnx2x *bp,
12492 u32 shmem_base_path[],
12493 u32 shmem2_base_path[], u8 phy_index,
12494 u32 chip_id)
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012495{
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012496 struct bnx2x_phy phy[PORT_MAX];
12497 struct bnx2x_phy *phy_blk[PORT_MAX];
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012498 u16 val;
Yaniv Rosnerc8e64df2011-01-30 04:15:00 +000012499 s8 port = 0;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012500 s8 port_of_path = 0;
Yaniv Rosnerc8e64df2011-01-30 04:15:00 +000012501 u32 swap_val, swap_override;
12502 swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
12503 swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
12504 port ^= (swap_val && swap_override);
12505 bnx2x_ext_phy_hw_reset(bp, port);
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012506 /* PART1 - Reset both phys */
12507 for (port = PORT_MAX - 1; port >= PORT_0; port--) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012508 u32 shmem_base, shmem2_base;
12509 /* In E2, same phy is using for port0 of the two paths */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000012510 if (CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012511 shmem_base = shmem_base_path[0];
12512 shmem2_base = shmem2_base_path[0];
12513 port_of_path = port;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000012514 } else {
12515 shmem_base = shmem_base_path[port];
12516 shmem2_base = shmem2_base_path[port];
12517 port_of_path = 0;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012518 }
12519
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012520 /* Extract the ext phy address for the port */
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012521 if (bnx2x_populate_phy(bp, phy_index, shmem_base, shmem2_base,
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012522 port_of_path, &phy[port]) !=
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012523 0) {
12524 DP(NETIF_MSG_LINK, "populate_phy failed\n");
12525 return -EINVAL;
12526 }
Yuval Mintzd2310232012-06-20 19:05:19 +000012527 /* Disable attentions */
Yaniv Rosner6a71bbe2010-11-01 05:32:31 +000012528 bnx2x_bits_dis(bp, NIG_REG_MASK_INTERRUPT_PORT0 +
12529 port_of_path*4,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012530 (NIG_MASK_XGXS0_LINK_STATUS |
12531 NIG_MASK_XGXS0_LINK10G |
12532 NIG_MASK_SERDES0_LINK_STATUS |
12533 NIG_MASK_MI_INT));
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012534
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012535 /* Need to take the phy out of low power mode in order
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000012536 * to write to access its registers
12537 */
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012538 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012539 MISC_REGISTERS_GPIO_OUTPUT_HIGH,
12540 port);
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012541
12542 /* Reset the phy */
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012543 bnx2x_cl45_write(bp, &phy[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012544 MDIO_PMA_DEVAD,
12545 MDIO_PMA_REG_CTRL,
12546 1<<15);
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012547 }
12548
12549 /* Add delay of 150ms after reset */
12550 msleep(150);
12551
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012552 if (phy[PORT_0].addr & 0x1) {
12553 phy_blk[PORT_0] = &(phy[PORT_1]);
12554 phy_blk[PORT_1] = &(phy[PORT_0]);
12555 } else {
12556 phy_blk[PORT_0] = &(phy[PORT_0]);
12557 phy_blk[PORT_1] = &(phy[PORT_1]);
12558 }
12559
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012560 /* PART2 - Download firmware to both phys */
12561 for (port = PORT_MAX - 1; port >= PORT_0; port--) {
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000012562 if (CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012563 port_of_path = port;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000012564 else
12565 port_of_path = 0;
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012566
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012567 DP(NETIF_MSG_LINK, "Loading spirom for phy address 0x%x\n",
12568 phy_blk[port]->addr);
Yaniv Rosner5c99274b2011-01-18 04:33:36 +000012569 if (bnx2x_8073_8727_external_rom_boot(bp, phy_blk[port],
12570 port_of_path))
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012571 return -EINVAL;
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012572
12573 /* Only set bit 10 = 1 (Tx power down) */
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012574 bnx2x_cl45_read(bp, phy_blk[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012575 MDIO_PMA_DEVAD,
12576 MDIO_PMA_REG_TX_POWER_DOWN, &val);
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012577
12578 /* Phase1 of TX_POWER_DOWN reset */
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012579 bnx2x_cl45_write(bp, phy_blk[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012580 MDIO_PMA_DEVAD,
12581 MDIO_PMA_REG_TX_POWER_DOWN,
12582 (val | 1<<10));
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012583 }
12584
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000012585 /* Toggle Transmitter: Power down and then up with 600ms delay
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +000012586 * between
12587 */
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012588 msleep(600);
12589
12590 /* PART3 - complete TX_POWER_DOWN process, and set GPIO2 back to low */
12591 for (port = PORT_MAX - 1; port >= PORT_0; port--) {
Eilon Greensteinf5372252009-02-12 08:38:30 +000012592 /* Phase2 of POWER_DOWN_RESET */
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012593 /* Release bit 10 (Release Tx power down) */
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012594 bnx2x_cl45_read(bp, phy_blk[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012595 MDIO_PMA_DEVAD,
12596 MDIO_PMA_REG_TX_POWER_DOWN, &val);
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012597
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012598 bnx2x_cl45_write(bp, phy_blk[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012599 MDIO_PMA_DEVAD,
12600 MDIO_PMA_REG_TX_POWER_DOWN, (val & (~(1<<10))));
Yuval Mintzd2310232012-06-20 19:05:19 +000012601 usleep_range(15000, 30000);
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012602
12603 /* Read modify write the SPI-ROM version select register */
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012604 bnx2x_cl45_read(bp, phy_blk[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012605 MDIO_PMA_DEVAD,
12606 MDIO_PMA_REG_EDC_FFE_MAIN, &val);
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012607 bnx2x_cl45_write(bp, phy_blk[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012608 MDIO_PMA_DEVAD,
12609 MDIO_PMA_REG_EDC_FFE_MAIN, (val | (1<<12)));
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012610
12611 /* set GPIO2 back to LOW */
12612 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012613 MISC_REGISTERS_GPIO_OUTPUT_LOW, port);
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012614 }
12615 return 0;
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012616}
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000012617static int bnx2x_8726_common_init_phy(struct bnx2x *bp,
12618 u32 shmem_base_path[],
12619 u32 shmem2_base_path[], u8 phy_index,
12620 u32 chip_id)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012621{
12622 u32 val;
12623 s8 port;
12624 struct bnx2x_phy phy;
12625 /* Use port1 because of the static port-swap */
12626 /* Enable the module detection interrupt */
12627 val = REG_RD(bp, MISC_REG_GPIO_EVENT_EN);
12628 val |= ((1<<MISC_REGISTERS_GPIO_3)|
12629 (1<<(MISC_REGISTERS_GPIO_3 + MISC_REGISTERS_GPIO_PORT_SHIFT)));
12630 REG_WR(bp, MISC_REG_GPIO_EVENT_EN, val);
12631
Yaniv Rosner650154b2010-11-01 05:32:36 +000012632 bnx2x_ext_phy_hw_reset(bp, 0);
Yuval Mintzd2310232012-06-20 19:05:19 +000012633 usleep_range(5000, 10000);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012634 for (port = 0; port < PORT_MAX; port++) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012635 u32 shmem_base, shmem2_base;
12636
12637 /* In E2, same phy is using for port0 of the two paths */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000012638 if (CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012639 shmem_base = shmem_base_path[0];
12640 shmem2_base = shmem2_base_path[0];
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000012641 } else {
12642 shmem_base = shmem_base_path[port];
12643 shmem2_base = shmem2_base_path[port];
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012644 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012645 /* Extract the ext phy address for the port */
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012646 if (bnx2x_populate_phy(bp, phy_index, shmem_base, shmem2_base,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012647 port, &phy) !=
12648 0) {
12649 DP(NETIF_MSG_LINK, "populate phy failed\n");
12650 return -EINVAL;
12651 }
12652
12653 /* Reset phy*/
12654 bnx2x_cl45_write(bp, &phy,
12655 MDIO_PMA_DEVAD, MDIO_PMA_REG_GEN_CTRL, 0x0001);
12656
12657
12658 /* Set fault module detected LED on */
12659 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_0,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012660 MISC_REGISTERS_GPIO_HIGH,
12661 port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012662 }
12663
12664 return 0;
12665}
Yaniv Rosnera8db5b42011-01-31 04:22:28 +000012666static void bnx2x_get_ext_phy_reset_gpio(struct bnx2x *bp, u32 shmem_base,
12667 u8 *io_gpio, u8 *io_port)
12668{
12669
12670 u32 phy_gpio_reset = REG_RD(bp, shmem_base +
12671 offsetof(struct shmem_region,
12672 dev_info.port_hw_config[PORT_0].default_cfg));
12673 switch (phy_gpio_reset) {
12674 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO0_P0:
12675 *io_gpio = 0;
12676 *io_port = 0;
12677 break;
12678 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO1_P0:
12679 *io_gpio = 1;
12680 *io_port = 0;
12681 break;
12682 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO2_P0:
12683 *io_gpio = 2;
12684 *io_port = 0;
12685 break;
12686 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO3_P0:
12687 *io_gpio = 3;
12688 *io_port = 0;
12689 break;
12690 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO0_P1:
12691 *io_gpio = 0;
12692 *io_port = 1;
12693 break;
12694 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO1_P1:
12695 *io_gpio = 1;
12696 *io_port = 1;
12697 break;
12698 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO2_P1:
12699 *io_gpio = 2;
12700 *io_port = 1;
12701 break;
12702 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO3_P1:
12703 *io_gpio = 3;
12704 *io_port = 1;
12705 break;
12706 default:
12707 /* Don't override the io_gpio and io_port */
12708 break;
12709 }
12710}
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000012711
12712static int bnx2x_8727_common_init_phy(struct bnx2x *bp,
12713 u32 shmem_base_path[],
12714 u32 shmem2_base_path[], u8 phy_index,
12715 u32 chip_id)
Eilon Greenstein4d295db2009-07-21 05:47:47 +000012716{
Yaniv Rosnera8db5b42011-01-31 04:22:28 +000012717 s8 port, reset_gpio;
Eilon Greenstein4d295db2009-07-21 05:47:47 +000012718 u32 swap_val, swap_override;
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012719 struct bnx2x_phy phy[PORT_MAX];
12720 struct bnx2x_phy *phy_blk[PORT_MAX];
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012721 s8 port_of_path;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012722 swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
12723 swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
Eilon Greenstein4d295db2009-07-21 05:47:47 +000012724
Yaniv Rosnera8db5b42011-01-31 04:22:28 +000012725 reset_gpio = MISC_REGISTERS_GPIO_1;
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012726 port = 1;
12727
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000012728 /* Retrieve the reset gpio/port which control the reset.
Yaniv Rosnera8db5b42011-01-31 04:22:28 +000012729 * Default is GPIO1, PORT1
12730 */
12731 bnx2x_get_ext_phy_reset_gpio(bp, shmem_base_path[0],
12732 (u8 *)&reset_gpio, (u8 *)&port);
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012733
12734 /* Calculate the port based on port swap */
12735 port ^= (swap_val && swap_override);
12736
Yaniv Rosnera8db5b42011-01-31 04:22:28 +000012737 /* Initiate PHY reset*/
12738 bnx2x_set_gpio(bp, reset_gpio, MISC_REGISTERS_GPIO_OUTPUT_LOW,
12739 port);
Yuval Mintzd2310232012-06-20 19:05:19 +000012740 usleep_range(1000, 2000);
Yaniv Rosnera8db5b42011-01-31 04:22:28 +000012741 bnx2x_set_gpio(bp, reset_gpio, MISC_REGISTERS_GPIO_OUTPUT_HIGH,
12742 port);
12743
Yuval Mintzd2310232012-06-20 19:05:19 +000012744 usleep_range(5000, 10000);
Eilon Greenstein4d295db2009-07-21 05:47:47 +000012745
12746 /* PART1 - Reset both phys */
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012747 for (port = PORT_MAX - 1; port >= PORT_0; port--) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012748 u32 shmem_base, shmem2_base;
12749
12750 /* In E2, same phy is using for port0 of the two paths */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000012751 if (CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012752 shmem_base = shmem_base_path[0];
12753 shmem2_base = shmem2_base_path[0];
12754 port_of_path = port;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000012755 } else {
12756 shmem_base = shmem_base_path[port];
12757 shmem2_base = shmem2_base_path[port];
12758 port_of_path = 0;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012759 }
12760
Eilon Greenstein4d295db2009-07-21 05:47:47 +000012761 /* Extract the ext phy address for the port */
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012762 if (bnx2x_populate_phy(bp, phy_index, shmem_base, shmem2_base,
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012763 port_of_path, &phy[port]) !=
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012764 0) {
12765 DP(NETIF_MSG_LINK, "populate phy failed\n");
12766 return -EINVAL;
12767 }
Eilon Greenstein4d295db2009-07-21 05:47:47 +000012768 /* disable attentions */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012769 bnx2x_bits_dis(bp, NIG_REG_MASK_INTERRUPT_PORT0 +
12770 port_of_path*4,
12771 (NIG_MASK_XGXS0_LINK_STATUS |
12772 NIG_MASK_XGXS0_LINK10G |
12773 NIG_MASK_SERDES0_LINK_STATUS |
12774 NIG_MASK_MI_INT));
Eilon Greenstein4d295db2009-07-21 05:47:47 +000012775
Eilon Greenstein4d295db2009-07-21 05:47:47 +000012776
12777 /* Reset the phy */
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012778 bnx2x_cl45_write(bp, &phy[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012779 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 1<<15);
Eilon Greenstein4d295db2009-07-21 05:47:47 +000012780 }
12781
12782 /* Add delay of 150ms after reset */
12783 msleep(150);
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012784 if (phy[PORT_0].addr & 0x1) {
12785 phy_blk[PORT_0] = &(phy[PORT_1]);
12786 phy_blk[PORT_1] = &(phy[PORT_0]);
12787 } else {
12788 phy_blk[PORT_0] = &(phy[PORT_0]);
12789 phy_blk[PORT_1] = &(phy[PORT_1]);
12790 }
Eilon Greenstein4d295db2009-07-21 05:47:47 +000012791 /* PART2 - Download firmware to both phys */
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012792 for (port = PORT_MAX - 1; port >= PORT_0; port--) {
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000012793 if (CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012794 port_of_path = port;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000012795 else
12796 port_of_path = 0;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012797 DP(NETIF_MSG_LINK, "Loading spirom for phy address 0x%x\n",
12798 phy_blk[port]->addr);
Yaniv Rosner5c99274b2011-01-18 04:33:36 +000012799 if (bnx2x_8073_8727_external_rom_boot(bp, phy_blk[port],
12800 port_of_path))
Eilon Greenstein4d295db2009-07-21 05:47:47 +000012801 return -EINVAL;
Yaniv Rosner85242ee2011-07-05 01:06:53 +000012802 /* Disable PHY transmitter output */
12803 bnx2x_cl45_write(bp, phy_blk[port],
12804 MDIO_PMA_DEVAD,
12805 MDIO_PMA_REG_TX_DISABLE, 1);
Eilon Greenstein4d295db2009-07-21 05:47:47 +000012806
Yaniv Rosner5c99274b2011-01-18 04:33:36 +000012807 }
Eilon Greenstein4d295db2009-07-21 05:47:47 +000012808 return 0;
12809}
12810
Yaniv Rosner521683d2011-11-28 00:49:48 +000012811static int bnx2x_84833_common_init_phy(struct bnx2x *bp,
12812 u32 shmem_base_path[],
12813 u32 shmem2_base_path[],
12814 u8 phy_index,
12815 u32 chip_id)
12816{
12817 u8 reset_gpios;
Yaniv Rosner521683d2011-11-28 00:49:48 +000012818 reset_gpios = bnx2x_84833_get_reset_gpios(bp, shmem_base_path, chip_id);
12819 bnx2x_set_mult_gpio(bp, reset_gpios, MISC_REGISTERS_GPIO_OUTPUT_LOW);
12820 udelay(10);
12821 bnx2x_set_mult_gpio(bp, reset_gpios, MISC_REGISTERS_GPIO_OUTPUT_HIGH);
12822 DP(NETIF_MSG_LINK, "84833 reset pulse on pin values 0x%x\n",
12823 reset_gpios);
Yaniv Rosner521683d2011-11-28 00:49:48 +000012824 return 0;
12825}
12826
Yaniv Rosner11b2ec62012-01-17 02:33:25 +000012827static int bnx2x_84833_pre_init_phy(struct bnx2x *bp,
12828 struct bnx2x_phy *phy)
12829{
12830 u16 val, cnt;
12831 /* Wait for FW completing its initialization. */
12832 for (cnt = 0; cnt < 1500; cnt++) {
12833 bnx2x_cl45_read(bp, phy,
12834 MDIO_PMA_DEVAD,
12835 MDIO_PMA_REG_CTRL, &val);
12836 if (!(val & (1<<15)))
12837 break;
Yuval Mintzd2310232012-06-20 19:05:19 +000012838 usleep_range(1000, 2000);
Yaniv Rosner11b2ec62012-01-17 02:33:25 +000012839 }
12840 if (cnt >= 1500) {
12841 DP(NETIF_MSG_LINK, "84833 reset timeout\n");
12842 return -EINVAL;
12843 }
12844
12845 /* Put the port in super isolate mode. */
12846 bnx2x_cl45_read(bp, phy,
12847 MDIO_CTL_DEVAD,
12848 MDIO_84833_TOP_CFG_XGPHY_STRAP1, &val);
12849 val |= MDIO_84833_SUPER_ISOLATE;
12850 bnx2x_cl45_write(bp, phy,
12851 MDIO_CTL_DEVAD,
12852 MDIO_84833_TOP_CFG_XGPHY_STRAP1, val);
12853
12854 /* Save spirom version */
12855 bnx2x_save_848xx_spirom_version(phy, bp, PORT_0);
12856 return 0;
12857}
12858
12859int bnx2x_pre_init_phy(struct bnx2x *bp,
12860 u32 shmem_base,
12861 u32 shmem2_base,
12862 u32 chip_id)
12863{
12864 int rc = 0;
12865 struct bnx2x_phy phy;
12866 bnx2x_set_mdio_clk(bp, chip_id, PORT_0);
12867 if (bnx2x_populate_phy(bp, EXT_PHY1, shmem_base, shmem2_base,
12868 PORT_0, &phy)) {
12869 DP(NETIF_MSG_LINK, "populate_phy failed\n");
12870 return -EINVAL;
12871 }
12872 switch (phy.type) {
12873 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833:
12874 rc = bnx2x_84833_pre_init_phy(bp, &phy);
12875 break;
12876 default:
12877 break;
12878 }
12879 return rc;
12880}
Yaniv Rosner521683d2011-11-28 00:49:48 +000012881
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000012882static int bnx2x_ext_phy_common_init(struct bnx2x *bp, u32 shmem_base_path[],
12883 u32 shmem2_base_path[], u8 phy_index,
12884 u32 ext_phy_type, u32 chip_id)
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012885{
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000012886 int rc = 0;
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012887
12888 switch (ext_phy_type) {
12889 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073:
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012890 rc = bnx2x_8073_common_init_phy(bp, shmem_base_path,
12891 shmem2_base_path,
12892 phy_index, chip_id);
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012893 break;
Yaniv Rosnere4d78f12011-05-31 21:25:55 +000012894 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8722:
Eilon Greenstein4d295db2009-07-21 05:47:47 +000012895 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
12896 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727_NOC:
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012897 rc = bnx2x_8727_common_init_phy(bp, shmem_base_path,
12898 shmem2_base_path,
12899 phy_index, chip_id);
Eilon Greenstein4d295db2009-07-21 05:47:47 +000012900 break;
12901
Eilon Greenstein589abe32009-02-12 08:36:55 +000012902 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000012903 /* GPIO1 affects both ports, so there's need to pull
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +000012904 * it for single port alone
12905 */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012906 rc = bnx2x_8726_common_init_phy(bp, shmem_base_path,
12907 shmem2_base_path,
12908 phy_index, chip_id);
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012909 break;
Yaniv Rosner0d40f0d2011-06-14 01:34:27 +000012910 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833:
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000012911 /* GPIO3's are linked, and so both need to be toggled
Yaniv Rosner0d40f0d2011-06-14 01:34:27 +000012912 * to obtain required 2us pulse.
12913 */
Yaniv Rosner521683d2011-11-28 00:49:48 +000012914 rc = bnx2x_84833_common_init_phy(bp, shmem_base_path,
12915 shmem2_base_path,
12916 phy_index, chip_id);
Yaniv Rosner0d40f0d2011-06-14 01:34:27 +000012917 break;
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012918 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE:
12919 rc = -EINVAL;
Yaniv Rosner4f60dab2009-11-05 19:18:23 +020012920 break;
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012921 default:
12922 DP(NETIF_MSG_LINK,
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +000012923 "ext_phy 0x%x common init not required\n",
12924 ext_phy_type);
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012925 break;
12926 }
12927
Yuval Mintzd2310232012-06-20 19:05:19 +000012928 if (rc)
Yaniv Rosner6d870c32011-01-31 04:22:20 +000012929 netdev_err(bp->dev, "Warning: PHY was not initialized,"
12930 " Port %d\n",
12931 0);
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012932 return rc;
12933}
12934
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000012935int bnx2x_common_init_phy(struct bnx2x *bp, u32 shmem_base_path[],
12936 u32 shmem2_base_path[], u32 chip_id)
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012937{
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000012938 int rc = 0;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000012939 u32 phy_ver, val;
12940 u8 phy_index = 0;
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012941 u32 ext_phy_type, ext_phy_config;
Yaniv Rosnera198c142011-05-31 21:29:42 +000012942 bnx2x_set_mdio_clk(bp, chip_id, PORT_0);
12943 bnx2x_set_mdio_clk(bp, chip_id, PORT_1);
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012944 DP(NETIF_MSG_LINK, "Begin common phy init\n");
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000012945 if (CHIP_IS_E3(bp)) {
12946 /* Enable EPIO */
12947 val = REG_RD(bp, MISC_REG_GEN_PURP_HWG);
12948 REG_WR(bp, MISC_REG_GEN_PURP_HWG, val | 1);
12949 }
Yaniv Rosnerb21a3422011-01-18 04:33:24 +000012950 /* Check if common init was already done */
12951 phy_ver = REG_RD(bp, shmem_base_path[0] +
12952 offsetof(struct shmem_region,
12953 port_mb[PORT_0].ext_phy_fw_version));
12954 if (phy_ver) {
12955 DP(NETIF_MSG_LINK, "Not doing common init; phy ver is 0x%x\n",
12956 phy_ver);
12957 return 0;
12958 }
12959
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012960 /* Read the ext_phy_type for arbitrary port(0) */
12961 for (phy_index = EXT_PHY1; phy_index < MAX_PHYS;
12962 phy_index++) {
12963 ext_phy_config = bnx2x_get_ext_phy_config(bp,
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012964 shmem_base_path[0],
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012965 phy_index, 0);
12966 ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012967 rc |= bnx2x_ext_phy_common_init(bp, shmem_base_path,
12968 shmem2_base_path,
12969 phy_index, ext_phy_type,
12970 chip_id);
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012971 }
12972 return rc;
12973}
12974
Yaniv Rosner3deb8162011-06-14 01:34:33 +000012975static void bnx2x_check_over_curr(struct link_params *params,
12976 struct link_vars *vars)
12977{
12978 struct bnx2x *bp = params->bp;
12979 u32 cfg_pin;
12980 u8 port = params->port;
12981 u32 pin_val;
12982
12983 cfg_pin = (REG_RD(bp, params->shmem_base +
12984 offsetof(struct shmem_region,
12985 dev_info.port_hw_config[port].e3_cmn_pin_cfg1)) &
12986 PORT_HW_CFG_E3_OVER_CURRENT_MASK) >>
12987 PORT_HW_CFG_E3_OVER_CURRENT_SHIFT;
12988
12989 /* Ignore check if no external input PIN available */
12990 if (bnx2x_get_cfg_pin(bp, cfg_pin, &pin_val) != 0)
12991 return;
12992
12993 if (!pin_val) {
12994 if ((vars->phy_flags & PHY_OVER_CURRENT_FLAG) == 0) {
12995 netdev_err(bp->dev, "Error: Power fault on Port %d has"
12996 " been detected and the power to "
12997 "that SFP+ module has been removed"
12998 " to prevent failure of the card."
12999 " Please remove the SFP+ module and"
13000 " restart the system to clear this"
13001 " error.\n",
13002 params->port);
13003 vars->phy_flags |= PHY_OVER_CURRENT_FLAG;
13004 }
13005 } else
13006 vars->phy_flags &= ~PHY_OVER_CURRENT_FLAG;
13007}
13008
Yuval Mintzd0b8a6f2012-06-20 19:05:18 +000013009/* Returns 0 if no change occured since last check; 1 otherwise. */
13010static u8 bnx2x_analyze_link_error(struct link_params *params,
13011 struct link_vars *vars, u32 status,
13012 u32 phy_flag, u32 link_flag, u8 notify)
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013013{
13014 struct bnx2x *bp = params->bp;
13015 /* Compare new value with previous value */
13016 u8 led_mode;
Yuval Mintzd0b8a6f2012-06-20 19:05:18 +000013017 u32 old_status = (vars->phy_flags & phy_flag) ? 1 : 0;
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013018
Yuval Mintzd0b8a6f2012-06-20 19:05:18 +000013019 if ((status ^ old_status) == 0)
13020 return 0;
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013021
13022 /* If values differ */
Yuval Mintzd0b8a6f2012-06-20 19:05:18 +000013023 switch (phy_flag) {
13024 case PHY_HALF_OPEN_CONN_FLAG:
13025 DP(NETIF_MSG_LINK, "Analyze Remote Fault\n");
13026 break;
13027 case PHY_SFP_TX_FAULT_FLAG:
13028 DP(NETIF_MSG_LINK, "Analyze TX Fault\n");
13029 break;
13030 default:
13031 DP(NETIF_MSG_LINK, "Analyze UNKOWN\n");
13032 }
13033 DP(NETIF_MSG_LINK, "Link changed:[%x %x]->%x\n", vars->link_up,
13034 old_status, status);
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013035
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000013036 /* a. Update shmem->link_status accordingly
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013037 * b. Update link_vars->link_up
13038 */
Yuval Mintzd0b8a6f2012-06-20 19:05:18 +000013039 if (status) {
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013040 vars->link_status &= ~LINK_STATUS_LINK_UP;
Yuval Mintzd0b8a6f2012-06-20 19:05:18 +000013041 vars->link_status |= link_flag;
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013042 vars->link_up = 0;
Yuval Mintzd0b8a6f2012-06-20 19:05:18 +000013043 vars->phy_flags |= phy_flag;
Yaniv Rosner55098c52012-04-03 18:41:27 +000013044
13045 /* activate nig drain */
13046 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 1);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000013047 /* Set LED mode to off since the PHY doesn't know about these
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013048 * errors
13049 */
13050 led_mode = LED_MODE_OFF;
13051 } else {
13052 vars->link_status |= LINK_STATUS_LINK_UP;
Yuval Mintzd0b8a6f2012-06-20 19:05:18 +000013053 vars->link_status &= ~link_flag;
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013054 vars->link_up = 1;
Yuval Mintzd0b8a6f2012-06-20 19:05:18 +000013055 vars->phy_flags &= ~phy_flag;
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013056 led_mode = LED_MODE_OPER;
Yaniv Rosner55098c52012-04-03 18:41:27 +000013057
13058 /* Clear nig drain */
13059 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 0);
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013060 }
Yaniv Rosner55098c52012-04-03 18:41:27 +000013061 bnx2x_sync_link(params, vars);
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013062 /* Update the LED according to the link state */
13063 bnx2x_set_led(params, vars, led_mode, SPEED_10000);
13064
13065 /* Update link status in the shared memory */
13066 bnx2x_update_mng(params, vars->link_status);
13067
13068 /* C. Trigger General Attention */
13069 vars->periodic_flags |= PERIODIC_FLAGS_LINK_EVENT;
Yaniv Rosner55098c52012-04-03 18:41:27 +000013070 if (notify)
13071 bnx2x_notify_link_changed(bp);
Yuval Mintzd0b8a6f2012-06-20 19:05:18 +000013072
13073 return 1;
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013074}
13075
Yaniv Rosnerde6f3372011-08-02 22:59:25 +000013076/******************************************************************************
13077* Description:
13078* This function checks for half opened connection change indication.
13079* When such change occurs, it calls the bnx2x_analyze_link_error
13080* to check if Remote Fault is set or cleared. Reception of remote fault
13081* status message in the MAC indicates that the peer's MAC has detected
13082* a fault, for example, due to break in the TX side of fiber.
13083*
13084******************************************************************************/
Yaniv Rosner55098c52012-04-03 18:41:27 +000013085int bnx2x_check_half_open_conn(struct link_params *params,
13086 struct link_vars *vars,
13087 u8 notify)
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013088{
13089 struct bnx2x *bp = params->bp;
13090 u32 lss_status = 0;
13091 u32 mac_base;
13092 /* In case link status is physically up @ 10G do */
Yaniv Rosner55098c52012-04-03 18:41:27 +000013093 if (((vars->phy_flags & PHY_PHYSICAL_LINK_FLAG) == 0) ||
13094 (REG_RD(bp, NIG_REG_EGRESS_EMAC0_PORT + params->port*4)))
13095 return 0;
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013096
Yaniv Rosnerde6f3372011-08-02 22:59:25 +000013097 if (CHIP_IS_E3(bp) &&
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013098 (REG_RD(bp, MISC_REG_RESET_REG_2) &
Yaniv Rosnerde6f3372011-08-02 22:59:25 +000013099 (MISC_REGISTERS_RESET_REG_2_XMAC))) {
13100 /* Check E3 XMAC */
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000013101 /* Note that link speed cannot be queried here, since it may be
Yaniv Rosnerde6f3372011-08-02 22:59:25 +000013102 * zero while link is down. In case UMAC is active, LSS will
13103 * simply not be set
13104 */
13105 mac_base = (params->port) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
13106
13107 /* Clear stick bits (Requires rising edge) */
13108 REG_WR(bp, mac_base + XMAC_REG_CLEAR_RX_LSS_STATUS, 0);
13109 REG_WR(bp, mac_base + XMAC_REG_CLEAR_RX_LSS_STATUS,
13110 XMAC_CLEAR_RX_LSS_STATUS_REG_CLEAR_LOCAL_FAULT_STATUS |
13111 XMAC_CLEAR_RX_LSS_STATUS_REG_CLEAR_REMOTE_FAULT_STATUS);
13112 if (REG_RD(bp, mac_base + XMAC_REG_RX_LSS_STATUS))
13113 lss_status = 1;
13114
Yuval Mintzd0b8a6f2012-06-20 19:05:18 +000013115 bnx2x_analyze_link_error(params, vars, lss_status,
13116 PHY_HALF_OPEN_CONN_FLAG,
13117 LINK_STATUS_NONE, notify);
Yaniv Rosnerde6f3372011-08-02 22:59:25 +000013118 } else if (REG_RD(bp, MISC_REG_RESET_REG_2) &
13119 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << params->port)) {
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013120 /* Check E1X / E2 BMAC */
13121 u32 lss_status_reg;
13122 u32 wb_data[2];
13123 mac_base = params->port ? NIG_REG_INGRESS_BMAC1_MEM :
13124 NIG_REG_INGRESS_BMAC0_MEM;
13125 /* Read BIGMAC_REGISTER_RX_LSS_STATUS */
13126 if (CHIP_IS_E2(bp))
13127 lss_status_reg = BIGMAC2_REGISTER_RX_LSS_STAT;
13128 else
13129 lss_status_reg = BIGMAC_REGISTER_RX_LSS_STATUS;
13130
13131 REG_RD_DMAE(bp, mac_base + lss_status_reg, wb_data, 2);
13132 lss_status = (wb_data[0] > 0);
13133
Yuval Mintzd0b8a6f2012-06-20 19:05:18 +000013134 bnx2x_analyze_link_error(params, vars, lss_status,
13135 PHY_HALF_OPEN_CONN_FLAG,
13136 LINK_STATUS_NONE, notify);
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013137 }
Yaniv Rosner55098c52012-04-03 18:41:27 +000013138 return 0;
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013139}
Yuval Mintzd0b8a6f2012-06-20 19:05:18 +000013140static void bnx2x_sfp_tx_fault_detection(struct bnx2x_phy *phy,
13141 struct link_params *params,
13142 struct link_vars *vars)
13143{
13144 struct bnx2x *bp = params->bp;
13145 u32 cfg_pin, value = 0;
13146 u8 led_change, port = params->port;
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013147
Yuval Mintzd0b8a6f2012-06-20 19:05:18 +000013148 /* Get The SFP+ TX_Fault controlling pin ([eg]pio) */
13149 cfg_pin = (REG_RD(bp, params->shmem_base + offsetof(struct shmem_region,
13150 dev_info.port_hw_config[port].e3_cmn_pin_cfg)) &
13151 PORT_HW_CFG_E3_TX_FAULT_MASK) >>
13152 PORT_HW_CFG_E3_TX_FAULT_SHIFT;
13153
13154 if (bnx2x_get_cfg_pin(bp, cfg_pin, &value)) {
13155 DP(NETIF_MSG_LINK, "Failed to read pin 0x%02x\n", cfg_pin);
13156 return;
13157 }
13158
13159 led_change = bnx2x_analyze_link_error(params, vars, value,
13160 PHY_SFP_TX_FAULT_FLAG,
13161 LINK_STATUS_SFP_TX_FAULT, 1);
13162
13163 if (led_change) {
13164 /* Change TX_Fault led, set link status for further syncs */
13165 u8 led_mode;
13166
13167 if (vars->phy_flags & PHY_SFP_TX_FAULT_FLAG) {
13168 led_mode = MISC_REGISTERS_GPIO_HIGH;
13169 vars->link_status |= LINK_STATUS_SFP_TX_FAULT;
13170 } else {
13171 led_mode = MISC_REGISTERS_GPIO_LOW;
13172 vars->link_status &= ~LINK_STATUS_SFP_TX_FAULT;
13173 }
13174
13175 /* If module is unapproved, led should be on regardless */
13176 if (!(phy->flags & FLAGS_SFP_NOT_APPROVED)) {
13177 DP(NETIF_MSG_LINK, "Change TX_Fault LED: ->%x\n",
13178 led_mode);
13179 bnx2x_set_e3_module_fault_led(params, led_mode);
13180 }
13181 }
13182}
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013183void bnx2x_period_func(struct link_params *params, struct link_vars *vars)
13184{
Yaniv Rosnerde6f3372011-08-02 22:59:25 +000013185 u16 phy_idx;
Yaniv Rosner55098c52012-04-03 18:41:27 +000013186 struct bnx2x *bp = params->bp;
Yaniv Rosnerde6f3372011-08-02 22:59:25 +000013187 for (phy_idx = INT_PHY; phy_idx < MAX_PHYS; phy_idx++) {
13188 if (params->phy[phy_idx].flags & FLAGS_TX_ERROR_CHECK) {
13189 bnx2x_set_aer_mmd(params, &params->phy[phy_idx]);
Yaniv Rosner55098c52012-04-03 18:41:27 +000013190 if (bnx2x_check_half_open_conn(params, vars, 1) !=
13191 0)
13192 DP(NETIF_MSG_LINK, "Fault detection failed\n");
Yaniv Rosnerde6f3372011-08-02 22:59:25 +000013193 break;
13194 }
13195 }
13196
Yaniv Rosnera9077bf2011-10-27 05:09:46 +000013197 if (CHIP_IS_E3(bp)) {
13198 struct bnx2x_phy *phy = &params->phy[INT_PHY];
13199 bnx2x_set_aer_mmd(params, phy);
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013200 bnx2x_check_over_curr(params, vars);
Yuval Mintzd0b8a6f2012-06-20 19:05:18 +000013201 if (vars->rx_tx_asic_rst)
13202 bnx2x_warpcore_config_runtime(phy, params, vars);
13203
13204 if ((REG_RD(bp, params->shmem_base +
13205 offsetof(struct shmem_region, dev_info.
13206 port_hw_config[params->port].default_cfg))
13207 & PORT_HW_CFG_NET_SERDES_IF_MASK) ==
13208 PORT_HW_CFG_NET_SERDES_IF_SFI) {
13209 if (bnx2x_is_sfp_module_plugged(phy, params)) {
13210 bnx2x_sfp_tx_fault_detection(phy, params, vars);
13211 } else if (vars->link_status &
13212 LINK_STATUS_SFP_TX_FAULT) {
13213 /* Clean trail, interrupt corrects the leds */
13214 vars->link_status &= ~LINK_STATUS_SFP_TX_FAULT;
13215 vars->phy_flags &= ~PHY_SFP_TX_FAULT_FLAG;
13216 /* Update link status in the shared memory */
13217 bnx2x_update_mng(params, vars->link_status);
13218 }
13219 }
13220
Yaniv Rosnera9077bf2011-10-27 05:09:46 +000013221 }
13222
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013223}
13224
Yaniv Rosnera22f0782010-09-07 11:41:20 +000013225u8 bnx2x_hw_lock_required(struct bnx2x *bp, u32 shmem_base, u32 shmem2_base)
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +000013226{
13227 u8 phy_index;
13228 struct bnx2x_phy phy;
13229 for (phy_index = INT_PHY; phy_index < MAX_PHYS;
13230 phy_index++) {
Yaniv Rosnera22f0782010-09-07 11:41:20 +000013231 if (bnx2x_populate_phy(bp, phy_index, shmem_base, shmem2_base,
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +000013232 0, &phy) != 0) {
13233 DP(NETIF_MSG_LINK, "populate phy failed\n");
13234 return 0;
13235 }
13236
13237 if (phy.flags & FLAGS_HW_LOCK_REQUIRED)
13238 return 1;
13239 }
13240 return 0;
13241}
13242
13243u8 bnx2x_fan_failure_det_req(struct bnx2x *bp,
13244 u32 shmem_base,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000013245 u32 shmem2_base,
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +000013246 u8 port)
13247{
13248 u8 phy_index, fan_failure_det_req = 0;
13249 struct bnx2x_phy phy;
13250 for (phy_index = EXT_PHY1; phy_index < MAX_PHYS;
13251 phy_index++) {
Yaniv Rosnera22f0782010-09-07 11:41:20 +000013252 if (bnx2x_populate_phy(bp, phy_index, shmem_base, shmem2_base,
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +000013253 port, &phy)
13254 != 0) {
13255 DP(NETIF_MSG_LINK, "populate phy failed\n");
13256 return 0;
13257 }
13258 fan_failure_det_req |= (phy.flags &
13259 FLAGS_FAN_FAILURE_DET_REQ);
13260 }
13261 return fan_failure_det_req;
13262}
13263
13264void bnx2x_hw_reset_phy(struct link_params *params)
13265{
13266 u8 phy_index;
Yaniv Rosner985848f2011-07-05 01:06:48 +000013267 struct bnx2x *bp = params->bp;
13268 bnx2x_update_mng(params, 0);
13269 bnx2x_bits_dis(bp, NIG_REG_MASK_INTERRUPT_PORT0 + params->port*4,
13270 (NIG_MASK_XGXS0_LINK_STATUS |
13271 NIG_MASK_XGXS0_LINK10G |
13272 NIG_MASK_SERDES0_LINK_STATUS |
13273 NIG_MASK_MI_INT));
13274
13275 for (phy_index = INT_PHY; phy_index < MAX_PHYS;
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +000013276 phy_index++) {
13277 if (params->phy[phy_index].hw_reset) {
13278 params->phy[phy_index].hw_reset(
13279 &params->phy[phy_index],
13280 params);
13281 params->phy[phy_index] = phy_null;
13282 }
13283 }
13284}
Yaniv Rosner020c7e32011-05-31 21:28:43 +000013285
13286void bnx2x_init_mod_abs_int(struct bnx2x *bp, struct link_vars *vars,
13287 u32 chip_id, u32 shmem_base, u32 shmem2_base,
13288 u8 port)
13289{
13290 u8 gpio_num = 0xff, gpio_port = 0xff, phy_index;
13291 u32 val;
13292 u32 offset, aeu_mask, swap_val, swap_override, sync_offset;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000013293 if (CHIP_IS_E3(bp)) {
13294 if (bnx2x_get_mod_abs_int_cfg(bp, chip_id,
13295 shmem_base,
13296 port,
13297 &gpio_num,
13298 &gpio_port) != 0)
13299 return;
13300 } else {
Yaniv Rosner020c7e32011-05-31 21:28:43 +000013301 struct bnx2x_phy phy;
13302 for (phy_index = EXT_PHY1; phy_index < MAX_PHYS;
13303 phy_index++) {
13304 if (bnx2x_populate_phy(bp, phy_index, shmem_base,
13305 shmem2_base, port, &phy)
13306 != 0) {
13307 DP(NETIF_MSG_LINK, "populate phy failed\n");
13308 return;
13309 }
13310 if (phy.type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726) {
13311 gpio_num = MISC_REGISTERS_GPIO_3;
13312 gpio_port = port;
13313 break;
13314 }
13315 }
13316 }
13317
13318 if (gpio_num == 0xff)
13319 return;
13320
13321 /* Set GPIO3 to trigger SFP+ module insertion/removal */
13322 bnx2x_set_gpio(bp, gpio_num, MISC_REGISTERS_GPIO_INPUT_HI_Z, gpio_port);
13323
13324 swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
13325 swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
13326 gpio_port ^= (swap_val && swap_override);
13327
13328 vars->aeu_int_mask = AEU_INPUTS_ATTN_BITS_GPIO0_FUNCTION_0 <<
13329 (gpio_num + (gpio_port << 2));
13330
13331 sync_offset = shmem_base +
13332 offsetof(struct shmem_region,
13333 dev_info.port_hw_config[port].aeu_int_mask);
13334 REG_WR(bp, sync_offset, vars->aeu_int_mask);
13335
13336 DP(NETIF_MSG_LINK, "Setting MOD_ABS (GPIO%d_P%d) AEU to 0x%x\n",
13337 gpio_num, gpio_port, vars->aeu_int_mask);
13338
13339 if (port == 0)
13340 offset = MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0;
13341 else
13342 offset = MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0;
13343
13344 /* Open appropriate AEU for interrupts */
13345 aeu_mask = REG_RD(bp, offset);
13346 aeu_mask |= vars->aeu_int_mask;
13347 REG_WR(bp, offset, aeu_mask);
13348
13349 /* Enable the GPIO to trigger interrupt */
13350 val = REG_RD(bp, MISC_REG_GPIO_EVENT_EN);
13351 val |= 1 << (gpio_num + (gpio_port << 2));
13352 REG_WR(bp, MISC_REG_GPIO_EVENT_EN, val);
13353}