blob: 43e3663ab33933ecd91e9a32ca2dbe4ba22bf585 [file] [log] [blame]
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001/* Copyright 2008-2011 Broadcom Corporation
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002 *
3 * Unless you and Broadcom execute a separate written software license
4 * agreement governing use of this software, this software is licensed to you
5 * under the terms of the GNU General Public License version 2, available
6 * at http://www.gnu.org/licenses/old-licenses/gpl-2.0.html (the "GPL").
7 *
8 * Notwithstanding the above, under no circumstances may you combine this
9 * software in any way with any other Broadcom software provided under a
10 * license other than the GPL, without Broadcom's express prior written
11 * consent.
12 *
13 * Written by Yaniv Rosner
14 *
15 */
16
Joe Perches7995c642010-02-17 15:01:52 +000017#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
18
Yaniv Rosnerea4e0402008-06-23 20:27:26 -070019#include <linux/kernel.h>
20#include <linux/errno.h>
21#include <linux/pci.h>
22#include <linux/netdevice.h>
23#include <linux/delay.h>
24#include <linux/ethtool.h>
25#include <linux/mutex.h>
Yaniv Rosnerea4e0402008-06-23 20:27:26 -070026
Yaniv Rosnerea4e0402008-06-23 20:27:26 -070027#include "bnx2x.h"
28
29/********************************************************/
Eilon Greenstein3196a882008-08-13 15:58:49 -070030#define ETH_HLEN 14
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000031/* L2 header size + 2*VLANs (8 bytes) + LLC SNAP (8 bytes) */
32#define ETH_OVREHEAD (ETH_HLEN + 8 + 8)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -070033#define ETH_MIN_PACKET_SIZE 60
34#define ETH_MAX_PACKET_SIZE 1500
35#define ETH_MAX_JUMBO_PACKET_SIZE 9600
36#define MDIO_ACCESS_TIMEOUT 1000
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000037#define BMAC_CONTROL_RX_ENABLE 2
Yaniv Rosnerea4e0402008-06-23 20:27:26 -070038
39/***********************************************************/
Eilon Greenstein3196a882008-08-13 15:58:49 -070040/* Shortcut definitions */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -070041/***********************************************************/
42
Eilon Greenstein2f904462009-08-12 08:22:16 +000043#define NIG_LATCH_BC_ENABLE_MI_INT 0
44
45#define NIG_STATUS_EMAC0_MI_INT \
46 NIG_STATUS_INTERRUPT_PORT0_REG_STATUS_EMAC0_MISC_MI_INT
Yaniv Rosnerea4e0402008-06-23 20:27:26 -070047#define NIG_STATUS_XGXS0_LINK10G \
48 NIG_STATUS_INTERRUPT_PORT0_REG_STATUS_XGXS0_LINK10G
49#define NIG_STATUS_XGXS0_LINK_STATUS \
50 NIG_STATUS_INTERRUPT_PORT0_REG_STATUS_XGXS0_LINK_STATUS
51#define NIG_STATUS_XGXS0_LINK_STATUS_SIZE \
52 NIG_STATUS_INTERRUPT_PORT0_REG_STATUS_XGXS0_LINK_STATUS_SIZE
53#define NIG_STATUS_SERDES0_LINK_STATUS \
54 NIG_STATUS_INTERRUPT_PORT0_REG_STATUS_SERDES0_LINK_STATUS
55#define NIG_MASK_MI_INT \
56 NIG_MASK_INTERRUPT_PORT0_REG_MASK_EMAC0_MISC_MI_INT
57#define NIG_MASK_XGXS0_LINK10G \
58 NIG_MASK_INTERRUPT_PORT0_REG_MASK_XGXS0_LINK10G
59#define NIG_MASK_XGXS0_LINK_STATUS \
60 NIG_MASK_INTERRUPT_PORT0_REG_MASK_XGXS0_LINK_STATUS
61#define NIG_MASK_SERDES0_LINK_STATUS \
62 NIG_MASK_INTERRUPT_PORT0_REG_MASK_SERDES0_LINK_STATUS
63
64#define MDIO_AN_CL73_OR_37_COMPLETE \
65 (MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_AUTONEG_COMPLETE | \
66 MDIO_GP_STATUS_TOP_AN_STATUS1_CL37_AUTONEG_COMPLETE)
67
68#define XGXS_RESET_BITS \
69 (MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_XGXS0_RSTB_HW | \
70 MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_XGXS0_IDDQ | \
71 MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_XGXS0_PWRDWN | \
72 MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_XGXS0_PWRDWN_SD | \
73 MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_XGXS0_TXD_FIFO_RSTB)
74
75#define SERDES_RESET_BITS \
76 (MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_SERDES0_RSTB_HW | \
77 MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_SERDES0_IDDQ | \
78 MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_SERDES0_PWRDWN | \
79 MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_SERDES0_PWRDWN_SD)
80
81#define AUTONEG_CL37 SHARED_HW_CFG_AN_ENABLE_CL37
82#define AUTONEG_CL73 SHARED_HW_CFG_AN_ENABLE_CL73
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000083#define AUTONEG_BAM SHARED_HW_CFG_AN_ENABLE_BAM
Eilon Greenstein3196a882008-08-13 15:58:49 -070084#define AUTONEG_PARALLEL \
Yaniv Rosnerea4e0402008-06-23 20:27:26 -070085 SHARED_HW_CFG_AN_ENABLE_PARALLEL_DETECTION
Eilon Greenstein3196a882008-08-13 15:58:49 -070086#define AUTONEG_SGMII_FIBER_AUTODET \
Yaniv Rosnerea4e0402008-06-23 20:27:26 -070087 SHARED_HW_CFG_AN_EN_SGMII_FIBER_AUTO_DETECT
Eilon Greenstein3196a882008-08-13 15:58:49 -070088#define AUTONEG_REMOTE_PHY SHARED_HW_CFG_AN_ENABLE_REMOTE_PHY
Yaniv Rosnerea4e0402008-06-23 20:27:26 -070089
90#define GP_STATUS_PAUSE_RSOLUTION_TXSIDE \
91 MDIO_GP_STATUS_TOP_AN_STATUS1_PAUSE_RSOLUTION_TXSIDE
92#define GP_STATUS_PAUSE_RSOLUTION_RXSIDE \
93 MDIO_GP_STATUS_TOP_AN_STATUS1_PAUSE_RSOLUTION_RXSIDE
94#define GP_STATUS_SPEED_MASK \
95 MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_MASK
96#define GP_STATUS_10M MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10M
97#define GP_STATUS_100M MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_100M
98#define GP_STATUS_1G MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_1G
99#define GP_STATUS_2_5G MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_2_5G
100#define GP_STATUS_5G MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_5G
101#define GP_STATUS_6G MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_6G
102#define GP_STATUS_10G_HIG \
103 MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10G_HIG
104#define GP_STATUS_10G_CX4 \
105 MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10G_CX4
106#define GP_STATUS_12G_HIG \
107 MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_12G_HIG
108#define GP_STATUS_12_5G MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_12_5G
109#define GP_STATUS_13G MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_13G
110#define GP_STATUS_15G MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_15G
111#define GP_STATUS_16G MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_16G
112#define GP_STATUS_1G_KX MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_1G_KX
113#define GP_STATUS_10G_KX4 \
114 MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10G_KX4
115
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000116#define LINK_10THD LINK_STATUS_SPEED_AND_DUPLEX_10THD
117#define LINK_10TFD LINK_STATUS_SPEED_AND_DUPLEX_10TFD
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700118#define LINK_100TXHD LINK_STATUS_SPEED_AND_DUPLEX_100TXHD
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000119#define LINK_100T4 LINK_STATUS_SPEED_AND_DUPLEX_100T4
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700120#define LINK_100TXFD LINK_STATUS_SPEED_AND_DUPLEX_100TXFD
121#define LINK_1000THD LINK_STATUS_SPEED_AND_DUPLEX_1000THD
122#define LINK_1000TFD LINK_STATUS_SPEED_AND_DUPLEX_1000TFD
123#define LINK_1000XFD LINK_STATUS_SPEED_AND_DUPLEX_1000XFD
124#define LINK_2500THD LINK_STATUS_SPEED_AND_DUPLEX_2500THD
125#define LINK_2500TFD LINK_STATUS_SPEED_AND_DUPLEX_2500TFD
126#define LINK_2500XFD LINK_STATUS_SPEED_AND_DUPLEX_2500XFD
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000127#define LINK_10GTFD LINK_STATUS_SPEED_AND_DUPLEX_10GTFD
128#define LINK_10GXFD LINK_STATUS_SPEED_AND_DUPLEX_10GXFD
129#define LINK_12GTFD LINK_STATUS_SPEED_AND_DUPLEX_12GTFD
130#define LINK_12GXFD LINK_STATUS_SPEED_AND_DUPLEX_12GXFD
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700131#define LINK_12_5GTFD LINK_STATUS_SPEED_AND_DUPLEX_12_5GTFD
132#define LINK_12_5GXFD LINK_STATUS_SPEED_AND_DUPLEX_12_5GXFD
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000133#define LINK_13GTFD LINK_STATUS_SPEED_AND_DUPLEX_13GTFD
134#define LINK_13GXFD LINK_STATUS_SPEED_AND_DUPLEX_13GXFD
135#define LINK_15GTFD LINK_STATUS_SPEED_AND_DUPLEX_15GTFD
136#define LINK_15GXFD LINK_STATUS_SPEED_AND_DUPLEX_15GXFD
137#define LINK_16GTFD LINK_STATUS_SPEED_AND_DUPLEX_16GTFD
138#define LINK_16GXFD LINK_STATUS_SPEED_AND_DUPLEX_16GXFD
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700139
140#define PHY_XGXS_FLAG 0x1
141#define PHY_SGMII_FLAG 0x2
142#define PHY_SERDES_FLAG 0x4
143
Eilon Greenstein589abe32009-02-12 08:36:55 +0000144/* */
145#define SFP_EEPROM_CON_TYPE_ADDR 0x2
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000146 #define SFP_EEPROM_CON_TYPE_VAL_LC 0x7
Eilon Greenstein589abe32009-02-12 08:36:55 +0000147 #define SFP_EEPROM_CON_TYPE_VAL_COPPER 0x21
148
Eilon Greenstein4d295db2009-07-21 05:47:47 +0000149
150#define SFP_EEPROM_COMP_CODE_ADDR 0x3
151 #define SFP_EEPROM_COMP_CODE_SR_MASK (1<<4)
152 #define SFP_EEPROM_COMP_CODE_LR_MASK (1<<5)
153 #define SFP_EEPROM_COMP_CODE_LRM_MASK (1<<6)
154
Eilon Greenstein589abe32009-02-12 08:36:55 +0000155#define SFP_EEPROM_FC_TX_TECH_ADDR 0x8
156 #define SFP_EEPROM_FC_TX_TECH_BITMASK_COPPER_PASSIVE 0x4
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000157 #define SFP_EEPROM_FC_TX_TECH_BITMASK_COPPER_ACTIVE 0x8
Eilon Greenstein4d295db2009-07-21 05:47:47 +0000158
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000159#define SFP_EEPROM_OPTIONS_ADDR 0x40
Eilon Greenstein589abe32009-02-12 08:36:55 +0000160 #define SFP_EEPROM_OPTIONS_LINEAR_RX_OUT_MASK 0x1
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000161#define SFP_EEPROM_OPTIONS_SIZE 2
Eilon Greenstein589abe32009-02-12 08:36:55 +0000162
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000163#define EDC_MODE_LINEAR 0x0022
164#define EDC_MODE_LIMITING 0x0044
165#define EDC_MODE_PASSIVE_DAC 0x0055
Eilon Greenstein589abe32009-02-12 08:36:55 +0000166
Eilon Greenstein4d295db2009-07-21 05:47:47 +0000167
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000168#define ETS_BW_LIMIT_CREDIT_UPPER_BOUND (0x5000)
169#define ETS_BW_LIMIT_CREDIT_WEIGHT (0x5000)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700170/**********************************************************/
171/* INTERFACE */
172/**********************************************************/
Yaniv Rosnere10bc842010-09-07 11:40:50 +0000173
Yaniv Rosnercd2be892011-01-31 04:21:45 +0000174#define CL22_WR_OVER_CL45(_bp, _phy, _bank, _addr, _val) \
Yaniv Rosnere10bc842010-09-07 11:40:50 +0000175 bnx2x_cl45_write(_bp, _phy, \
Yaniv Rosner7aa07112010-09-07 11:41:01 +0000176 (_phy)->def_md_devad, \
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700177 (_bank + (_addr & 0xf)), \
178 _val)
179
Yaniv Rosnercd2be892011-01-31 04:21:45 +0000180#define CL22_RD_OVER_CL45(_bp, _phy, _bank, _addr, _val) \
Yaniv Rosnere10bc842010-09-07 11:40:50 +0000181 bnx2x_cl45_read(_bp, _phy, \
Yaniv Rosner7aa07112010-09-07 11:41:01 +0000182 (_phy)->def_md_devad, \
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700183 (_bank + (_addr & 0xf)), \
184 _val)
185
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700186static u32 bnx2x_bits_en(struct bnx2x *bp, u32 reg, u32 bits)
187{
188 u32 val = REG_RD(bp, reg);
189
190 val |= bits;
191 REG_WR(bp, reg, val);
192 return val;
193}
194
195static u32 bnx2x_bits_dis(struct bnx2x *bp, u32 reg, u32 bits)
196{
197 u32 val = REG_RD(bp, reg);
198
199 val &= ~bits;
200 REG_WR(bp, reg, val);
201 return val;
202}
203
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000204/******************************************************************/
205/* ETS section */
206/******************************************************************/
207void bnx2x_ets_disabled(struct link_params *params)
208{
209 /* ETS disabled configuration*/
210 struct bnx2x *bp = params->bp;
211
212 DP(NETIF_MSG_LINK, "ETS disabled configuration\n");
213
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000214 /*
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000215 * mapping between entry priority to client number (0,1,2 -debug and
216 * management clients, 3 - COS0 client, 4 - COS client)(HIGHEST)
217 * 3bits client num.
218 * PRI4 | PRI3 | PRI2 | PRI1 | PRI0
219 * cos1-100 cos0-011 dbg1-010 dbg0-001 MCP-000
220 */
221
222 REG_WR(bp, NIG_REG_P0_TX_ARB_PRIORITY_CLIENT, 0x4688);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000223 /*
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000224 * Bitmap of 5bits length. Each bit specifies whether the entry behaves
225 * as strict. Bits 0,1,2 - debug and management entries, 3 -
226 * COS0 entry, 4 - COS1 entry.
227 * COS1 | COS0 | DEBUG1 | DEBUG0 | MGMT
228 * bit4 bit3 bit2 bit1 bit0
229 * MCP and debug are strict
230 */
231
232 REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_IS_STRICT, 0x7);
233 /* defines which entries (clients) are subjected to WFQ arbitration */
234 REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_IS_SUBJECT2WFQ, 0);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000235 /*
236 * For strict priority entries defines the number of consecutive
237 * slots for the highest priority.
238 */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000239 REG_WR(bp, NIG_REG_P0_TX_ARB_NUM_STRICT_ARB_SLOTS, 0x100);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000240 /*
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000241 * mapping between the CREDIT_WEIGHT registers and actual client
242 * numbers
243 */
244 REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_CREDIT_MAP, 0);
245 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_0, 0);
246 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_1, 0);
247
248 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_0, 0);
249 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_1, 0);
250 REG_WR(bp, PBF_REG_HIGH_PRIORITY_COS_NUM, 0);
251 /* ETS mode disable */
252 REG_WR(bp, PBF_REG_ETS_ENABLED, 0);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000253 /*
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000254 * If ETS mode is enabled (there is no strict priority) defines a WFQ
255 * weight for COS0/COS1.
256 */
257 REG_WR(bp, PBF_REG_COS0_WEIGHT, 0x2710);
258 REG_WR(bp, PBF_REG_COS1_WEIGHT, 0x2710);
259 /* Upper bound that COS0_WEIGHT can reach in the WFQ arbiter */
260 REG_WR(bp, PBF_REG_COS0_UPPER_BOUND, 0x989680);
261 REG_WR(bp, PBF_REG_COS1_UPPER_BOUND, 0x989680);
262 /* Defines the number of consecutive slots for the strict priority */
263 REG_WR(bp, PBF_REG_NUM_STRICT_ARB_SLOTS, 0);
264}
265
Yaniv Rosner65a001b2011-01-31 04:22:03 +0000266static void bnx2x_ets_bw_limit_common(const struct link_params *params)
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000267{
268 /* ETS disabled configuration */
269 struct bnx2x *bp = params->bp;
270 DP(NETIF_MSG_LINK, "ETS enabled BW limit configuration\n");
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000271 /*
272 * defines which entries (clients) are subjected to WFQ arbitration
273 * COS0 0x8
274 * COS1 0x10
275 */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000276 REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_IS_SUBJECT2WFQ, 0x18);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000277 /*
278 * mapping between the ARB_CREDIT_WEIGHT registers and actual
279 * client numbers (WEIGHT_0 does not actually have to represent
280 * client 0)
281 * PRI4 | PRI3 | PRI2 | PRI1 | PRI0
282 * cos1-001 cos0-000 dbg1-100 dbg0-011 MCP-010
283 */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000284 REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_CREDIT_MAP, 0x111A);
285
286 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_0,
287 ETS_BW_LIMIT_CREDIT_UPPER_BOUND);
288 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_1,
289 ETS_BW_LIMIT_CREDIT_UPPER_BOUND);
290
291 /* ETS mode enabled*/
292 REG_WR(bp, PBF_REG_ETS_ENABLED, 1);
293
294 /* Defines the number of consecutive slots for the strict priority */
295 REG_WR(bp, PBF_REG_NUM_STRICT_ARB_SLOTS, 0);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000296 /*
297 * Bitmap of 5bits length. Each bit specifies whether the entry behaves
298 * as strict. Bits 0,1,2 - debug and management entries, 3 - COS0
299 * entry, 4 - COS1 entry.
300 * COS1 | COS0 | DEBUG21 | DEBUG0 | MGMT
301 * bit4 bit3 bit2 bit1 bit0
302 * MCP and debug are strict
303 */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000304 REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_IS_STRICT, 0x7);
305
306 /* Upper bound that COS0_WEIGHT can reach in the WFQ arbiter.*/
307 REG_WR(bp, PBF_REG_COS0_UPPER_BOUND,
308 ETS_BW_LIMIT_CREDIT_UPPER_BOUND);
309 REG_WR(bp, PBF_REG_COS1_UPPER_BOUND,
310 ETS_BW_LIMIT_CREDIT_UPPER_BOUND);
311}
312
313void bnx2x_ets_bw_limit(const struct link_params *params, const u32 cos0_bw,
314 const u32 cos1_bw)
315{
316 /* ETS disabled configuration*/
317 struct bnx2x *bp = params->bp;
318 const u32 total_bw = cos0_bw + cos1_bw;
319 u32 cos0_credit_weight = 0;
320 u32 cos1_credit_weight = 0;
321
322 DP(NETIF_MSG_LINK, "ETS enabled BW limit configuration\n");
323
324 if ((0 == total_bw) ||
325 (0 == cos0_bw) ||
326 (0 == cos1_bw)) {
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000327 DP(NETIF_MSG_LINK, "Total BW can't be zero\n");
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000328 return;
329 }
330
331 cos0_credit_weight = (cos0_bw * ETS_BW_LIMIT_CREDIT_WEIGHT)/
332 total_bw;
333 cos1_credit_weight = (cos1_bw * ETS_BW_LIMIT_CREDIT_WEIGHT)/
334 total_bw;
335
336 bnx2x_ets_bw_limit_common(params);
337
338 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_0, cos0_credit_weight);
339 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_1, cos1_credit_weight);
340
341 REG_WR(bp, PBF_REG_COS0_WEIGHT, cos0_credit_weight);
342 REG_WR(bp, PBF_REG_COS1_WEIGHT, cos1_credit_weight);
343}
344
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +0000345int bnx2x_ets_strict(const struct link_params *params, const u8 strict_cos)
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000346{
347 /* ETS disabled configuration*/
348 struct bnx2x *bp = params->bp;
349 u32 val = 0;
350
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000351 DP(NETIF_MSG_LINK, "ETS enabled strict configuration\n");
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000352 /*
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000353 * Bitmap of 5bits length. Each bit specifies whether the entry behaves
354 * as strict. Bits 0,1,2 - debug and management entries,
355 * 3 - COS0 entry, 4 - COS1 entry.
356 * COS1 | COS0 | DEBUG21 | DEBUG0 | MGMT
357 * bit4 bit3 bit2 bit1 bit0
358 * MCP and debug are strict
359 */
360 REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_IS_STRICT, 0x1F);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000361 /*
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000362 * For strict priority entries defines the number of consecutive slots
363 * for the highest priority.
364 */
365 REG_WR(bp, NIG_REG_P0_TX_ARB_NUM_STRICT_ARB_SLOTS, 0x100);
366 /* ETS mode disable */
367 REG_WR(bp, PBF_REG_ETS_ENABLED, 0);
368 /* Defines the number of consecutive slots for the strict priority */
369 REG_WR(bp, PBF_REG_NUM_STRICT_ARB_SLOTS, 0x100);
370
371 /* Defines the number of consecutive slots for the strict priority */
372 REG_WR(bp, PBF_REG_HIGH_PRIORITY_COS_NUM, strict_cos);
373
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000374 /*
375 * mapping between entry priority to client number (0,1,2 -debug and
376 * management clients, 3 - COS0 client, 4 - COS client)(HIGHEST)
377 * 3bits client num.
378 * PRI4 | PRI3 | PRI2 | PRI1 | PRI0
379 * dbg0-010 dbg1-001 cos1-100 cos0-011 MCP-000
380 * dbg0-010 dbg1-001 cos0-011 cos1-100 MCP-000
381 */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000382 val = (0 == strict_cos) ? 0x2318 : 0x22E0;
383 REG_WR(bp, NIG_REG_P0_TX_ARB_PRIORITY_CLIENT, val);
384
385 return 0;
386}
387/******************************************************************/
Dmitry Kravkove8920672011-05-04 23:52:40 +0000388/* PFC section */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000389/******************************************************************/
390
391static void bnx2x_bmac2_get_pfc_stat(struct link_params *params,
392 u32 pfc_frames_sent[2],
393 u32 pfc_frames_received[2])
394{
395 /* Read pfc statistic */
396 struct bnx2x *bp = params->bp;
397 u32 bmac_addr = params->port ? NIG_REG_INGRESS_BMAC1_MEM :
398 NIG_REG_INGRESS_BMAC0_MEM;
399
400 DP(NETIF_MSG_LINK, "pfc statistic read from BMAC\n");
401
402 REG_RD_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_TX_STAT_GTPP,
403 pfc_frames_sent, 2);
404
405 REG_RD_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_RX_STAT_GRPP,
406 pfc_frames_received, 2);
407
408}
409static void bnx2x_emac_get_pfc_stat(struct link_params *params,
410 u32 pfc_frames_sent[2],
411 u32 pfc_frames_received[2])
412{
413 /* Read pfc statistic */
414 struct bnx2x *bp = params->bp;
415 u32 emac_base = params->port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
416 u32 val_xon = 0;
417 u32 val_xoff = 0;
418
419 DP(NETIF_MSG_LINK, "pfc statistic read from EMAC\n");
420
421 /* PFC received frames */
422 val_xoff = REG_RD(bp, emac_base +
423 EMAC_REG_RX_PFC_STATS_XOFF_RCVD);
424 val_xoff &= EMAC_REG_RX_PFC_STATS_XOFF_RCVD_COUNT;
425 val_xon = REG_RD(bp, emac_base + EMAC_REG_RX_PFC_STATS_XON_RCVD);
426 val_xon &= EMAC_REG_RX_PFC_STATS_XON_RCVD_COUNT;
427
428 pfc_frames_received[0] = val_xon + val_xoff;
429
430 /* PFC received sent */
431 val_xoff = REG_RD(bp, emac_base +
432 EMAC_REG_RX_PFC_STATS_XOFF_SENT);
433 val_xoff &= EMAC_REG_RX_PFC_STATS_XOFF_SENT_COUNT;
434 val_xon = REG_RD(bp, emac_base + EMAC_REG_RX_PFC_STATS_XON_SENT);
435 val_xon &= EMAC_REG_RX_PFC_STATS_XON_SENT_COUNT;
436
437 pfc_frames_sent[0] = val_xon + val_xoff;
438}
439
440void bnx2x_pfc_statistic(struct link_params *params, struct link_vars *vars,
441 u32 pfc_frames_sent[2],
442 u32 pfc_frames_received[2])
443{
444 /* Read pfc statistic */
445 struct bnx2x *bp = params->bp;
446 u32 val = 0;
447 DP(NETIF_MSG_LINK, "pfc statistic\n");
448
449 if (!vars->link_up)
450 return;
451
452 val = REG_RD(bp, MISC_REG_RESET_REG_2);
453 if ((val & (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << params->port))
454 == 0) {
455 DP(NETIF_MSG_LINK, "About to read stats from EMAC\n");
456 bnx2x_emac_get_pfc_stat(params, pfc_frames_sent,
457 pfc_frames_received);
458 } else {
459 DP(NETIF_MSG_LINK, "About to read stats from BMAC\n");
460 bnx2x_bmac2_get_pfc_stat(params, pfc_frames_sent,
461 pfc_frames_received);
462 }
463}
464/******************************************************************/
465/* MAC/PBF section */
466/******************************************************************/
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700467static void bnx2x_emac_init(struct link_params *params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000468 struct link_vars *vars)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700469{
470 /* reset and unreset the emac core */
471 struct bnx2x *bp = params->bp;
472 u8 port = params->port;
473 u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
474 u32 val;
475 u16 timeout;
476
477 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000478 (MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE << port));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700479 udelay(5);
480 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000481 (MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE << port));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700482
483 /* init emac - use read-modify-write */
484 /* self clear reset */
485 val = REG_RD(bp, emac_base + EMAC_REG_EMAC_MODE);
Eilon Greenstein3196a882008-08-13 15:58:49 -0700486 EMAC_WR(bp, EMAC_REG_EMAC_MODE, (val | EMAC_MODE_RESET));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700487
488 timeout = 200;
Eilon Greenstein3196a882008-08-13 15:58:49 -0700489 do {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700490 val = REG_RD(bp, emac_base + EMAC_REG_EMAC_MODE);
491 DP(NETIF_MSG_LINK, "EMAC reset reg is %u\n", val);
492 if (!timeout) {
493 DP(NETIF_MSG_LINK, "EMAC timeout!\n");
494 return;
495 }
496 timeout--;
Eilon Greenstein3196a882008-08-13 15:58:49 -0700497 } while (val & EMAC_MODE_RESET);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700498
499 /* Set mac address */
500 val = ((params->mac_addr[0] << 8) |
501 params->mac_addr[1]);
Eilon Greenstein3196a882008-08-13 15:58:49 -0700502 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700503
504 val = ((params->mac_addr[2] << 24) |
505 (params->mac_addr[3] << 16) |
506 (params->mac_addr[4] << 8) |
507 params->mac_addr[5]);
Eilon Greenstein3196a882008-08-13 15:58:49 -0700508 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + 4, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700509}
510
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +0000511static int bnx2x_emac_enable(struct link_params *params,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +0000512 struct link_vars *vars, u8 lb)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700513{
514 struct bnx2x *bp = params->bp;
515 u8 port = params->port;
516 u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
517 u32 val;
518
519 DP(NETIF_MSG_LINK, "enabling EMAC\n");
520
521 /* enable emac and not bmac */
522 REG_WR(bp, NIG_REG_EGRESS_EMAC0_PORT + port*4, 1);
523
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700524 /* ASIC */
525 if (vars->phy_flags & PHY_XGXS_FLAG) {
526 u32 ser_lane = ((params->lane_config &
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000527 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_MASK) >>
528 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_SHIFT);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700529
530 DP(NETIF_MSG_LINK, "XGXS\n");
531 /* select the master lanes (out of 0-3) */
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000532 REG_WR(bp, NIG_REG_XGXS_LANE_SEL_P0 + port*4, ser_lane);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700533 /* select XGXS */
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000534 REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700535
536 } else { /* SerDes */
537 DP(NETIF_MSG_LINK, "SerDes\n");
538 /* select SerDes */
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000539 REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700540 }
541
Eilon Greenstein811a2f22009-02-12 08:37:04 +0000542 bnx2x_bits_en(bp, emac_base + EMAC_REG_EMAC_RX_MODE,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000543 EMAC_RX_MODE_RESET);
Eilon Greenstein811a2f22009-02-12 08:37:04 +0000544 bnx2x_bits_en(bp, emac_base + EMAC_REG_EMAC_TX_MODE,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000545 EMAC_TX_MODE_RESET);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700546
547 if (CHIP_REV_IS_SLOW(bp)) {
548 /* config GMII mode */
549 val = REG_RD(bp, emac_base + EMAC_REG_EMAC_MODE);
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000550 EMAC_WR(bp, EMAC_REG_EMAC_MODE, (val | EMAC_MODE_PORT_GMII));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700551 } else { /* ASIC */
552 /* pause enable/disable */
553 bnx2x_bits_dis(bp, emac_base + EMAC_REG_EMAC_RX_MODE,
554 EMAC_RX_MODE_FLOW_EN);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700555
556 bnx2x_bits_dis(bp, emac_base + EMAC_REG_EMAC_TX_MODE,
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000557 (EMAC_TX_MODE_EXT_PAUSE_EN |
558 EMAC_TX_MODE_FLOW_EN));
559 if (!(params->feature_config_flags &
560 FEATURE_CONFIG_PFC_ENABLED)) {
561 if (vars->flow_ctrl & BNX2X_FLOW_CTRL_RX)
562 bnx2x_bits_en(bp, emac_base +
563 EMAC_REG_EMAC_RX_MODE,
564 EMAC_RX_MODE_FLOW_EN);
565
566 if (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX)
567 bnx2x_bits_en(bp, emac_base +
568 EMAC_REG_EMAC_TX_MODE,
569 (EMAC_TX_MODE_EXT_PAUSE_EN |
570 EMAC_TX_MODE_FLOW_EN));
571 } else
572 bnx2x_bits_en(bp, emac_base + EMAC_REG_EMAC_TX_MODE,
573 EMAC_TX_MODE_FLOW_EN);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700574 }
575
576 /* KEEP_VLAN_TAG, promiscuous */
577 val = REG_RD(bp, emac_base + EMAC_REG_EMAC_RX_MODE);
578 val |= EMAC_RX_MODE_KEEP_VLAN_TAG | EMAC_RX_MODE_PROMISCUOUS;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000579
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000580 /*
581 * Setting this bit causes MAC control frames (except for pause
582 * frames) to be passed on for processing. This setting has no
583 * affect on the operation of the pause frames. This bit effects
584 * all packets regardless of RX Parser packet sorting logic.
585 * Turn the PFC off to make sure we are in Xon state before
586 * enabling it.
587 */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000588 EMAC_WR(bp, EMAC_REG_RX_PFC_MODE, 0);
589 if (params->feature_config_flags & FEATURE_CONFIG_PFC_ENABLED) {
590 DP(NETIF_MSG_LINK, "PFC is enabled\n");
591 /* Enable PFC again */
592 EMAC_WR(bp, EMAC_REG_RX_PFC_MODE,
593 EMAC_REG_RX_PFC_MODE_RX_EN |
594 EMAC_REG_RX_PFC_MODE_TX_EN |
595 EMAC_REG_RX_PFC_MODE_PRIORITIES);
596
597 EMAC_WR(bp, EMAC_REG_RX_PFC_PARAM,
598 ((0x0101 <<
599 EMAC_REG_RX_PFC_PARAM_OPCODE_BITSHIFT) |
600 (0x00ff <<
601 EMAC_REG_RX_PFC_PARAM_PRIORITY_EN_BITSHIFT)));
602 val |= EMAC_RX_MODE_KEEP_MAC_CONTROL;
603 }
Eilon Greenstein3196a882008-08-13 15:58:49 -0700604 EMAC_WR(bp, EMAC_REG_EMAC_RX_MODE, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700605
606 /* Set Loopback */
607 val = REG_RD(bp, emac_base + EMAC_REG_EMAC_MODE);
608 if (lb)
609 val |= 0x810;
610 else
611 val &= ~0x810;
Eilon Greenstein3196a882008-08-13 15:58:49 -0700612 EMAC_WR(bp, EMAC_REG_EMAC_MODE, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700613
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +0000614 /* enable emac */
615 REG_WR(bp, NIG_REG_NIG_EMAC0_EN + port*4, 1);
616
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700617 /* enable emac for jumbo packets */
Eilon Greenstein3196a882008-08-13 15:58:49 -0700618 EMAC_WR(bp, EMAC_REG_EMAC_RX_MTU_SIZE,
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700619 (EMAC_RX_MTU_SIZE_JUMBO_ENA |
620 (ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD)));
621
622 /* strip CRC */
623 REG_WR(bp, NIG_REG_NIG_INGRESS_EMAC0_NO_CRC + port*4, 0x1);
624
625 /* disable the NIG in/out to the bmac */
626 REG_WR(bp, NIG_REG_BMAC0_IN_EN + port*4, 0x0);
627 REG_WR(bp, NIG_REG_BMAC0_PAUSE_OUT_EN + port*4, 0x0);
628 REG_WR(bp, NIG_REG_BMAC0_OUT_EN + port*4, 0x0);
629
630 /* enable the NIG in/out to the emac */
631 REG_WR(bp, NIG_REG_EMAC0_IN_EN + port*4, 0x1);
632 val = 0;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000633 if ((params->feature_config_flags &
634 FEATURE_CONFIG_PFC_ENABLED) ||
635 (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX))
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700636 val = 1;
637
638 REG_WR(bp, NIG_REG_EMAC0_PAUSE_OUT_EN + port*4, val);
639 REG_WR(bp, NIG_REG_EGRESS_EMAC0_OUT_EN + port*4, 0x1);
640
Yaniv Rosner02a23162011-01-31 04:22:53 +0000641 REG_WR(bp, NIG_REG_BMAC0_REGS_OUT_EN + port*4, 0x0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700642
643 vars->mac_type = MAC_TYPE_EMAC;
644 return 0;
645}
646
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000647static void bnx2x_update_pfc_bmac1(struct link_params *params,
648 struct link_vars *vars)
649{
650 u32 wb_data[2];
651 struct bnx2x *bp = params->bp;
652 u32 bmac_addr = params->port ? NIG_REG_INGRESS_BMAC1_MEM :
653 NIG_REG_INGRESS_BMAC0_MEM;
654
655 u32 val = 0x14;
656 if ((!(params->feature_config_flags &
657 FEATURE_CONFIG_PFC_ENABLED)) &&
658 (vars->flow_ctrl & BNX2X_FLOW_CTRL_RX))
659 /* Enable BigMAC to react on received Pause packets */
660 val |= (1<<5);
661 wb_data[0] = val;
662 wb_data[1] = 0;
663 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_RX_CONTROL, wb_data, 2);
664
665 /* tx control */
666 val = 0xc0;
667 if (!(params->feature_config_flags &
668 FEATURE_CONFIG_PFC_ENABLED) &&
669 (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX))
670 val |= 0x800000;
671 wb_data[0] = val;
672 wb_data[1] = 0;
673 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_TX_CONTROL, wb_data, 2);
674}
675
676static void bnx2x_update_pfc_bmac2(struct link_params *params,
677 struct link_vars *vars,
678 u8 is_lb)
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000679{
680 /*
681 * Set rx control: Strip CRC and enable BigMAC to relay
682 * control packets to the system as well
683 */
684 u32 wb_data[2];
685 struct bnx2x *bp = params->bp;
686 u32 bmac_addr = params->port ? NIG_REG_INGRESS_BMAC1_MEM :
687 NIG_REG_INGRESS_BMAC0_MEM;
688 u32 val = 0x14;
689
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000690 if ((!(params->feature_config_flags &
691 FEATURE_CONFIG_PFC_ENABLED)) &&
692 (vars->flow_ctrl & BNX2X_FLOW_CTRL_RX))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000693 /* Enable BigMAC to react on received Pause packets */
694 val |= (1<<5);
695 wb_data[0] = val;
696 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000697 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_RX_CONTROL, wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000698 udelay(30);
699
700 /* Tx control */
701 val = 0xc0;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000702 if (!(params->feature_config_flags &
703 FEATURE_CONFIG_PFC_ENABLED) &&
704 (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000705 val |= 0x800000;
706 wb_data[0] = val;
707 wb_data[1] = 0;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000708 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_TX_CONTROL, wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000709
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000710 if (params->feature_config_flags & FEATURE_CONFIG_PFC_ENABLED) {
711 DP(NETIF_MSG_LINK, "PFC is enabled\n");
712 /* Enable PFC RX & TX & STATS and set 8 COS */
713 wb_data[0] = 0x0;
714 wb_data[0] |= (1<<0); /* RX */
715 wb_data[0] |= (1<<1); /* TX */
716 wb_data[0] |= (1<<2); /* Force initial Xon */
717 wb_data[0] |= (1<<3); /* 8 cos */
718 wb_data[0] |= (1<<5); /* STATS */
719 wb_data[1] = 0;
720 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_PFC_CONTROL,
721 wb_data, 2);
722 /* Clear the force Xon */
723 wb_data[0] &= ~(1<<2);
724 } else {
725 DP(NETIF_MSG_LINK, "PFC is disabled\n");
726 /* disable PFC RX & TX & STATS and set 8 COS */
727 wb_data[0] = 0x8;
728 wb_data[1] = 0;
729 }
730
731 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_PFC_CONTROL, wb_data, 2);
732
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000733 /*
734 * Set Time (based unit is 512 bit time) between automatic
735 * re-sending of PP packets amd enable automatic re-send of
736 * Per-Priroity Packet as long as pp_gen is asserted and
737 * pp_disable is low.
738 */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000739 val = 0x8000;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000740 if (params->feature_config_flags & FEATURE_CONFIG_PFC_ENABLED)
741 val |= (1<<16); /* enable automatic re-send */
742
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000743 wb_data[0] = val;
744 wb_data[1] = 0;
745 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_TX_PAUSE_CONTROL,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000746 wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000747
748 /* mac control */
749 val = 0x3; /* Enable RX and TX */
750 if (is_lb) {
751 val |= 0x4; /* Local loopback */
752 DP(NETIF_MSG_LINK, "enable bmac loopback\n");
753 }
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000754 /* When PFC enabled, Pass pause frames towards the NIG. */
755 if (params->feature_config_flags & FEATURE_CONFIG_PFC_ENABLED)
756 val |= ((1<<6)|(1<<5));
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000757
758 wb_data[0] = val;
759 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000760 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_BMAC_CONTROL, wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000761}
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700762
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000763static void bnx2x_update_pfc_brb(struct link_params *params,
764 struct link_vars *vars,
765 struct bnx2x_nig_brb_pfc_port_params *pfc_params)
766{
767 struct bnx2x *bp = params->bp;
768 int set_pfc = params->feature_config_flags &
769 FEATURE_CONFIG_PFC_ENABLED;
770
771 /* default - pause configuration */
772 u32 pause_xoff_th = PFC_BRB_MAC_PAUSE_XOFF_THRESHOLD_PAUSEABLE;
773 u32 pause_xon_th = PFC_BRB_MAC_PAUSE_XON_THRESHOLD_PAUSEABLE;
774 u32 full_xoff_th = PFC_BRB_MAC_FULL_XOFF_THRESHOLD_PAUSEABLE;
775 u32 full_xon_th = PFC_BRB_MAC_FULL_XON_THRESHOLD_PAUSEABLE;
776
777 if (set_pfc && pfc_params)
778 /* First COS */
779 if (!pfc_params->cos0_pauseable) {
780 pause_xoff_th =
781 PFC_BRB_MAC_PAUSE_XOFF_THRESHOLD_NON_PAUSEABLE;
782 pause_xon_th =
783 PFC_BRB_MAC_PAUSE_XON_THRESHOLD_NON_PAUSEABLE;
784 full_xoff_th =
785 PFC_BRB_MAC_FULL_XOFF_THRESHOLD_NON_PAUSEABLE;
786 full_xon_th =
787 PFC_BRB_MAC_FULL_XON_THRESHOLD_NON_PAUSEABLE;
788 }
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000789 /*
790 * The number of free blocks below which the pause signal to class 0
791 * of MAC #n is asserted. n=0,1
792 */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000793 REG_WR(bp, BRB1_REG_PAUSE_0_XOFF_THRESHOLD_0 , pause_xoff_th);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000794 /*
795 * The number of free blocks above which the pause signal to class 0
796 * of MAC #n is de-asserted. n=0,1
797 */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000798 REG_WR(bp, BRB1_REG_PAUSE_0_XON_THRESHOLD_0 , pause_xon_th);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000799 /*
800 * The number of free blocks below which the full signal to class 0
801 * of MAC #n is asserted. n=0,1
802 */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000803 REG_WR(bp, BRB1_REG_FULL_0_XOFF_THRESHOLD_0 , full_xoff_th);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000804 /*
805 * The number of free blocks above which the full signal to class 0
806 * of MAC #n is de-asserted. n=0,1
807 */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000808 REG_WR(bp, BRB1_REG_FULL_0_XON_THRESHOLD_0 , full_xon_th);
809
810 if (set_pfc && pfc_params) {
811 /* Second COS */
812 if (pfc_params->cos1_pauseable) {
813 pause_xoff_th =
814 PFC_BRB_MAC_PAUSE_XOFF_THRESHOLD_PAUSEABLE;
815 pause_xon_th =
816 PFC_BRB_MAC_PAUSE_XON_THRESHOLD_PAUSEABLE;
817 full_xoff_th =
818 PFC_BRB_MAC_FULL_XOFF_THRESHOLD_PAUSEABLE;
819 full_xon_th =
820 PFC_BRB_MAC_FULL_XON_THRESHOLD_PAUSEABLE;
821 } else {
822 pause_xoff_th =
823 PFC_BRB_MAC_PAUSE_XOFF_THRESHOLD_NON_PAUSEABLE;
824 pause_xon_th =
825 PFC_BRB_MAC_PAUSE_XON_THRESHOLD_NON_PAUSEABLE;
826 full_xoff_th =
827 PFC_BRB_MAC_FULL_XOFF_THRESHOLD_NON_PAUSEABLE;
828 full_xon_th =
829 PFC_BRB_MAC_FULL_XON_THRESHOLD_NON_PAUSEABLE;
830 }
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000831 /*
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000832 * The number of free blocks below which the pause signal to
833 * class 1 of MAC #n is asserted. n=0,1
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000834 */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000835 REG_WR(bp, BRB1_REG_PAUSE_1_XOFF_THRESHOLD_0, pause_xoff_th);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000836 /*
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000837 * The number of free blocks above which the pause signal to
838 * class 1 of MAC #n is de-asserted. n=0,1
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000839 */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000840 REG_WR(bp, BRB1_REG_PAUSE_1_XON_THRESHOLD_0, pause_xon_th);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000841 /*
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000842 * The number of free blocks below which the full signal to
843 * class 1 of MAC #n is asserted. n=0,1
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000844 */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000845 REG_WR(bp, BRB1_REG_FULL_1_XOFF_THRESHOLD_0, full_xoff_th);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000846 /*
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000847 * The number of free blocks above which the full signal to
848 * class 1 of MAC #n is de-asserted. n=0,1
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000849 */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000850 REG_WR(bp, BRB1_REG_FULL_1_XON_THRESHOLD_0, full_xon_th);
851 }
852}
853
854static void bnx2x_update_pfc_nig(struct link_params *params,
855 struct link_vars *vars,
856 struct bnx2x_nig_brb_pfc_port_params *nig_params)
857{
858 u32 xcm_mask = 0, ppp_enable = 0, pause_enable = 0, llfc_out_en = 0;
859 u32 llfc_enable = 0, xcm0_out_en = 0, p0_hwpfc_enable = 0;
860 u32 pkt_priority_to_cos = 0;
861 u32 val;
862 struct bnx2x *bp = params->bp;
863 int port = params->port;
864 int set_pfc = params->feature_config_flags &
865 FEATURE_CONFIG_PFC_ENABLED;
866 DP(NETIF_MSG_LINK, "updating pfc nig parameters\n");
867
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000868 /*
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000869 * When NIG_LLH0_XCM_MASK_REG_LLHX_XCM_MASK_BCN bit is set
870 * MAC control frames (that are not pause packets)
871 * will be forwarded to the XCM.
872 */
873 xcm_mask = REG_RD(bp,
874 port ? NIG_REG_LLH1_XCM_MASK :
875 NIG_REG_LLH0_XCM_MASK);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000876 /*
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000877 * nig params will override non PFC params, since it's possible to
878 * do transition from PFC to SAFC
879 */
880 if (set_pfc) {
881 pause_enable = 0;
882 llfc_out_en = 0;
883 llfc_enable = 0;
884 ppp_enable = 1;
885 xcm_mask &= ~(port ? NIG_LLH1_XCM_MASK_REG_LLH1_XCM_MASK_BCN :
886 NIG_LLH0_XCM_MASK_REG_LLH0_XCM_MASK_BCN);
887 xcm0_out_en = 0;
888 p0_hwpfc_enable = 1;
889 } else {
890 if (nig_params) {
891 llfc_out_en = nig_params->llfc_out_en;
892 llfc_enable = nig_params->llfc_enable;
893 pause_enable = nig_params->pause_enable;
894 } else /*defaul non PFC mode - PAUSE */
895 pause_enable = 1;
896
897 xcm_mask |= (port ? NIG_LLH1_XCM_MASK_REG_LLH1_XCM_MASK_BCN :
898 NIG_LLH0_XCM_MASK_REG_LLH0_XCM_MASK_BCN);
899 xcm0_out_en = 1;
900 }
901
902 REG_WR(bp, port ? NIG_REG_LLFC_OUT_EN_1 :
903 NIG_REG_LLFC_OUT_EN_0, llfc_out_en);
904 REG_WR(bp, port ? NIG_REG_LLFC_ENABLE_1 :
905 NIG_REG_LLFC_ENABLE_0, llfc_enable);
906 REG_WR(bp, port ? NIG_REG_PAUSE_ENABLE_1 :
907 NIG_REG_PAUSE_ENABLE_0, pause_enable);
908
909 REG_WR(bp, port ? NIG_REG_PPP_ENABLE_1 :
910 NIG_REG_PPP_ENABLE_0, ppp_enable);
911
912 REG_WR(bp, port ? NIG_REG_LLH1_XCM_MASK :
913 NIG_REG_LLH0_XCM_MASK, xcm_mask);
914
915 REG_WR(bp, NIG_REG_LLFC_EGRESS_SRC_ENABLE_0, 0x7);
916
917 /* output enable for RX_XCM # IF */
918 REG_WR(bp, NIG_REG_XCM0_OUT_EN, xcm0_out_en);
919
920 /* HW PFC TX enable */
921 REG_WR(bp, NIG_REG_P0_HWPFC_ENABLE, p0_hwpfc_enable);
922
923 /* 0x2 = BMAC, 0x1= EMAC */
924 switch (vars->mac_type) {
925 case MAC_TYPE_EMAC:
926 val = 1;
927 break;
928 case MAC_TYPE_BMAC:
929 val = 0;
930 break;
931 default:
932 val = 0;
933 break;
934 }
935 REG_WR(bp, NIG_REG_EGRESS_EMAC0_PORT, val);
936
937 if (nig_params) {
938 pkt_priority_to_cos = nig_params->pkt_priority_to_cos;
939
940 REG_WR(bp, port ? NIG_REG_P1_RX_COS0_PRIORITY_MASK :
941 NIG_REG_P0_RX_COS0_PRIORITY_MASK,
942 nig_params->rx_cos0_priority_mask);
943
944 REG_WR(bp, port ? NIG_REG_P1_RX_COS1_PRIORITY_MASK :
945 NIG_REG_P0_RX_COS1_PRIORITY_MASK,
946 nig_params->rx_cos1_priority_mask);
947
948 REG_WR(bp, port ? NIG_REG_LLFC_HIGH_PRIORITY_CLASSES_1 :
949 NIG_REG_LLFC_HIGH_PRIORITY_CLASSES_0,
950 nig_params->llfc_high_priority_classes);
951
952 REG_WR(bp, port ? NIG_REG_LLFC_LOW_PRIORITY_CLASSES_1 :
953 NIG_REG_LLFC_LOW_PRIORITY_CLASSES_0,
954 nig_params->llfc_low_priority_classes);
955 }
956 REG_WR(bp, port ? NIG_REG_P1_PKT_PRIORITY_TO_COS :
957 NIG_REG_P0_PKT_PRIORITY_TO_COS,
958 pkt_priority_to_cos);
959}
960
961
962void bnx2x_update_pfc(struct link_params *params,
963 struct link_vars *vars,
964 struct bnx2x_nig_brb_pfc_port_params *pfc_params)
965{
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000966 /*
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000967 * The PFC and pause are orthogonal to one another, meaning when
968 * PFC is enabled, the pause are disabled, and when PFC is
969 * disabled, pause are set according to the pause result.
970 */
971 u32 val;
972 struct bnx2x *bp = params->bp;
973
974 /* update NIG params */
975 bnx2x_update_pfc_nig(params, vars, pfc_params);
976
977 /* update BRB params */
978 bnx2x_update_pfc_brb(params, vars, pfc_params);
979
980 if (!vars->link_up)
981 return;
982
983 val = REG_RD(bp, MISC_REG_RESET_REG_2);
984 if ((val & (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << params->port))
985 == 0) {
986 DP(NETIF_MSG_LINK, "About to update PFC in EMAC\n");
987 bnx2x_emac_enable(params, vars, 0);
988 return;
989 }
990
991 DP(NETIF_MSG_LINK, "About to update PFC in BMAC\n");
992 if (CHIP_IS_E2(bp))
993 bnx2x_update_pfc_bmac2(params, vars, 0);
994 else
995 bnx2x_update_pfc_bmac1(params, vars);
996
997 val = 0;
998 if ((params->feature_config_flags &
999 FEATURE_CONFIG_PFC_ENABLED) ||
1000 (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX))
1001 val = 1;
1002 REG_WR(bp, NIG_REG_BMAC0_PAUSE_OUT_EN + params->port*4, val);
1003}
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001004
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00001005static int bnx2x_bmac1_enable(struct link_params *params,
1006 struct link_vars *vars,
1007 u8 is_lb)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001008{
1009 struct bnx2x *bp = params->bp;
1010 u8 port = params->port;
1011 u32 bmac_addr = port ? NIG_REG_INGRESS_BMAC1_MEM :
1012 NIG_REG_INGRESS_BMAC0_MEM;
1013 u32 wb_data[2];
1014 u32 val;
1015
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001016 DP(NETIF_MSG_LINK, "Enabling BigMAC1\n");
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001017
1018 /* XGXS control */
1019 wb_data[0] = 0x3c;
1020 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001021 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_BMAC_XGXS_CONTROL,
1022 wb_data, 2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001023
1024 /* tx MAC SA */
1025 wb_data[0] = ((params->mac_addr[2] << 24) |
1026 (params->mac_addr[3] << 16) |
1027 (params->mac_addr[4] << 8) |
1028 params->mac_addr[5]);
1029 wb_data[1] = ((params->mac_addr[0] << 8) |
1030 params->mac_addr[1]);
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001031 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_TX_SOURCE_ADDR, wb_data, 2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001032
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001033 /* mac control */
1034 val = 0x3;
1035 if (is_lb) {
1036 val |= 0x4;
1037 DP(NETIF_MSG_LINK, "enable bmac loopback\n");
1038 }
1039 wb_data[0] = val;
1040 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001041 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_BMAC_CONTROL, wb_data, 2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001042
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001043 /* set rx mtu */
1044 wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD;
1045 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001046 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_RX_MAX_SIZE, wb_data, 2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001047
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001048 bnx2x_update_pfc_bmac1(params, vars);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001049
1050 /* set tx mtu */
1051 wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD;
1052 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001053 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_TX_MAX_SIZE, wb_data, 2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001054
1055 /* set cnt max size */
1056 wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD;
1057 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001058 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_CNT_MAX_SIZE, wb_data, 2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001059
1060 /* configure safc */
1061 wb_data[0] = 0x1000200;
1062 wb_data[1] = 0;
1063 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_RX_LLFC_MSG_FLDS,
1064 wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001065
1066 return 0;
1067}
1068
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00001069static int bnx2x_bmac2_enable(struct link_params *params,
1070 struct link_vars *vars,
1071 u8 is_lb)
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001072{
1073 struct bnx2x *bp = params->bp;
1074 u8 port = params->port;
1075 u32 bmac_addr = port ? NIG_REG_INGRESS_BMAC1_MEM :
1076 NIG_REG_INGRESS_BMAC0_MEM;
1077 u32 wb_data[2];
1078
1079 DP(NETIF_MSG_LINK, "Enabling BigMAC2\n");
1080
1081 wb_data[0] = 0;
1082 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001083 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_BMAC_CONTROL, wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001084 udelay(30);
1085
1086 /* XGXS control: Reset phy HW, MDIO registers, PHY PLL and BMAC */
1087 wb_data[0] = 0x3c;
1088 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001089 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_BMAC_XGXS_CONTROL,
1090 wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001091
1092 udelay(30);
1093
1094 /* tx MAC SA */
1095 wb_data[0] = ((params->mac_addr[2] << 24) |
1096 (params->mac_addr[3] << 16) |
1097 (params->mac_addr[4] << 8) |
1098 params->mac_addr[5]);
1099 wb_data[1] = ((params->mac_addr[0] << 8) |
1100 params->mac_addr[1]);
1101 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_TX_SOURCE_ADDR,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001102 wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001103
1104 udelay(30);
1105
1106 /* Configure SAFC */
1107 wb_data[0] = 0x1000200;
1108 wb_data[1] = 0;
1109 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_RX_LLFC_MSG_FLDS,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001110 wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001111 udelay(30);
1112
1113 /* set rx mtu */
1114 wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD;
1115 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001116 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_RX_MAX_SIZE, wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001117 udelay(30);
1118
1119 /* set tx mtu */
1120 wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD;
1121 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001122 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_TX_MAX_SIZE, wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001123 udelay(30);
1124 /* set cnt max size */
1125 wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD - 2;
1126 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001127 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_CNT_MAX_SIZE, wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001128 udelay(30);
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001129 bnx2x_update_pfc_bmac2(params, vars, is_lb);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001130
1131 return 0;
1132}
1133
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00001134static int bnx2x_bmac_enable(struct link_params *params,
1135 struct link_vars *vars,
1136 u8 is_lb)
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001137{
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00001138 int rc = 0;
1139 u8 port = params->port;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001140 struct bnx2x *bp = params->bp;
1141 u32 val;
1142 /* reset and unreset the BigMac */
1143 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001144 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port));
Yaniv Rosner1d9c05d2010-11-01 05:32:25 +00001145 msleep(1);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001146
1147 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001148 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port));
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001149
1150 /* enable access for bmac registers */
1151 REG_WR(bp, NIG_REG_BMAC0_REGS_OUT_EN + port*4, 0x1);
1152
1153 /* Enable BMAC according to BMAC type*/
1154 if (CHIP_IS_E2(bp))
1155 rc = bnx2x_bmac2_enable(params, vars, is_lb);
1156 else
1157 rc = bnx2x_bmac1_enable(params, vars, is_lb);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001158 REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 0x1);
1159 REG_WR(bp, NIG_REG_XGXS_LANE_SEL_P0 + port*4, 0x0);
1160 REG_WR(bp, NIG_REG_EGRESS_EMAC0_PORT + port*4, 0x0);
1161 val = 0;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001162 if ((params->feature_config_flags &
1163 FEATURE_CONFIG_PFC_ENABLED) ||
1164 (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX))
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001165 val = 1;
1166 REG_WR(bp, NIG_REG_BMAC0_PAUSE_OUT_EN + port*4, val);
1167 REG_WR(bp, NIG_REG_EGRESS_EMAC0_OUT_EN + port*4, 0x0);
1168 REG_WR(bp, NIG_REG_EMAC0_IN_EN + port*4, 0x0);
1169 REG_WR(bp, NIG_REG_EMAC0_PAUSE_OUT_EN + port*4, 0x0);
1170 REG_WR(bp, NIG_REG_BMAC0_IN_EN + port*4, 0x1);
1171 REG_WR(bp, NIG_REG_BMAC0_OUT_EN + port*4, 0x1);
1172
1173 vars->mac_type = MAC_TYPE_BMAC;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001174 return rc;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001175}
1176
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001177
1178static void bnx2x_update_mng(struct link_params *params, u32 link_status)
1179{
1180 struct bnx2x *bp = params->bp;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00001181
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001182 REG_WR(bp, params->shmem_base +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001183 offsetof(struct shmem_region,
1184 port_mb[params->port].link_status), link_status);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001185}
1186
1187static void bnx2x_bmac_rx_disable(struct bnx2x *bp, u8 port)
1188{
1189 u32 bmac_addr = port ? NIG_REG_INGRESS_BMAC1_MEM :
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001190 NIG_REG_INGRESS_BMAC0_MEM;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001191 u32 wb_data[2];
Eilon Greenstein3196a882008-08-13 15:58:49 -07001192 u32 nig_bmac_enable = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port*4);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001193
1194 /* Only if the bmac is out of reset */
1195 if (REG_RD(bp, MISC_REG_RESET_REG_2) &
1196 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port) &&
1197 nig_bmac_enable) {
1198
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001199 if (CHIP_IS_E2(bp)) {
1200 /* Clear Rx Enable bit in BMAC_CONTROL register */
1201 REG_RD_DMAE(bp, bmac_addr +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001202 BIGMAC2_REGISTER_BMAC_CONTROL,
1203 wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001204 wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
1205 REG_WR_DMAE(bp, bmac_addr +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001206 BIGMAC2_REGISTER_BMAC_CONTROL,
1207 wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001208 } else {
1209 /* Clear Rx Enable bit in BMAC_CONTROL register */
1210 REG_RD_DMAE(bp, bmac_addr +
1211 BIGMAC_REGISTER_BMAC_CONTROL,
1212 wb_data, 2);
1213 wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
1214 REG_WR_DMAE(bp, bmac_addr +
1215 BIGMAC_REGISTER_BMAC_CONTROL,
1216 wb_data, 2);
1217 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001218 msleep(1);
1219 }
1220}
1221
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00001222static int bnx2x_pbf_update(struct link_params *params, u32 flow_ctrl,
1223 u32 line_speed)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001224{
1225 struct bnx2x *bp = params->bp;
1226 u8 port = params->port;
1227 u32 init_crd, crd;
1228 u32 count = 1000;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001229
1230 /* disable port */
1231 REG_WR(bp, PBF_REG_DISABLE_NEW_TASK_PROC_P0 + port*4, 0x1);
1232
1233 /* wait for init credit */
1234 init_crd = REG_RD(bp, PBF_REG_P0_INIT_CRD + port*4);
1235 crd = REG_RD(bp, PBF_REG_P0_CREDIT + port*8);
1236 DP(NETIF_MSG_LINK, "init_crd 0x%x crd 0x%x\n", init_crd, crd);
1237
1238 while ((init_crd != crd) && count) {
1239 msleep(5);
1240
1241 crd = REG_RD(bp, PBF_REG_P0_CREDIT + port*8);
1242 count--;
1243 }
1244 crd = REG_RD(bp, PBF_REG_P0_CREDIT + port*8);
1245 if (init_crd != crd) {
1246 DP(NETIF_MSG_LINK, "BUG! init_crd 0x%x != crd 0x%x\n",
1247 init_crd, crd);
1248 return -EINVAL;
1249 }
1250
David S. Millerc0700f92008-12-16 23:53:20 -08001251 if (flow_ctrl & BNX2X_FLOW_CTRL_RX ||
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07001252 line_speed == SPEED_10 ||
1253 line_speed == SPEED_100 ||
1254 line_speed == SPEED_1000 ||
1255 line_speed == SPEED_2500) {
1256 REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 1);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001257 /* update threshold */
1258 REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, 0);
1259 /* update init credit */
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001260 init_crd = 778; /* (800-18-4) */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001261
1262 } else {
1263 u32 thresh = (ETH_MAX_JUMBO_PACKET_SIZE +
1264 ETH_OVREHEAD)/16;
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07001265 REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001266 /* update threshold */
1267 REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, thresh);
1268 /* update init credit */
1269 switch (line_speed) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001270 case SPEED_10000:
1271 init_crd = thresh + 553 - 22;
1272 break;
1273
1274 case SPEED_12000:
1275 init_crd = thresh + 664 - 22;
1276 break;
1277
1278 case SPEED_13000:
1279 init_crd = thresh + 742 - 22;
1280 break;
1281
1282 case SPEED_16000:
1283 init_crd = thresh + 778 - 22;
1284 break;
1285 default:
1286 DP(NETIF_MSG_LINK, "Invalid line_speed 0x%x\n",
1287 line_speed);
1288 return -EINVAL;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001289 }
1290 }
1291 REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, init_crd);
1292 DP(NETIF_MSG_LINK, "PBF updated to speed %d credit %d\n",
1293 line_speed, init_crd);
1294
1295 /* probe the credit changes */
1296 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0x1);
1297 msleep(5);
1298 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0x0);
1299
1300 /* enable port */
1301 REG_WR(bp, PBF_REG_DISABLE_NEW_TASK_PROC_P0 + port*4, 0x0);
1302 return 0;
1303}
1304
Dmitry Kravkove8920672011-05-04 23:52:40 +00001305/**
1306 * bnx2x_get_emac_base - retrive emac base address
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00001307 *
Dmitry Kravkove8920672011-05-04 23:52:40 +00001308 * @bp: driver handle
1309 * @mdc_mdio_access: access type
1310 * @port: port id
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00001311 *
1312 * This function selects the MDC/MDIO access (through emac0 or
1313 * emac1) depend on the mdc_mdio_access, port, port swapped. Each
1314 * phy has a default access mode, which could also be overridden
1315 * by nvram configuration. This parameter, whether this is the
1316 * default phy configuration, or the nvram overrun
1317 * configuration, is passed here as mdc_mdio_access and selects
1318 * the emac_base for the CL45 read/writes operations
1319 */
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00001320static u32 bnx2x_get_emac_base(struct bnx2x *bp,
1321 u32 mdc_mdio_access, u8 port)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001322{
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00001323 u32 emac_base = 0;
1324 switch (mdc_mdio_access) {
1325 case SHARED_HW_CFG_MDC_MDIO_ACCESS1_PHY_TYPE:
1326 break;
1327 case SHARED_HW_CFG_MDC_MDIO_ACCESS1_EMAC0:
1328 if (REG_RD(bp, NIG_REG_PORT_SWAP))
1329 emac_base = GRCBASE_EMAC1;
1330 else
1331 emac_base = GRCBASE_EMAC0;
1332 break;
1333 case SHARED_HW_CFG_MDC_MDIO_ACCESS1_EMAC1:
Eilon Greenstein589abe32009-02-12 08:36:55 +00001334 if (REG_RD(bp, NIG_REG_PORT_SWAP))
1335 emac_base = GRCBASE_EMAC0;
1336 else
1337 emac_base = GRCBASE_EMAC1;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001338 break;
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00001339 case SHARED_HW_CFG_MDC_MDIO_ACCESS1_BOTH:
1340 emac_base = (port) ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
1341 break;
1342 case SHARED_HW_CFG_MDC_MDIO_ACCESS1_SWAPPED:
Eilon Greenstein6378c022008-08-13 15:59:25 -07001343 emac_base = (port) ? GRCBASE_EMAC0 : GRCBASE_EMAC1;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001344 break;
1345 default:
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001346 break;
1347 }
1348 return emac_base;
1349
1350}
1351
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00001352/******************************************************************/
1353/* CL45 access functions */
1354/******************************************************************/
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00001355static int bnx2x_cl45_write(struct bnx2x *bp, struct bnx2x_phy *phy,
1356 u8 devad, u16 reg, u16 val)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001357{
1358 u32 tmp, saved_mode;
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00001359 u8 i;
1360 int rc = 0;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00001361 /*
1362 * Set clause 45 mode, slow down the MDIO clock to 2.5MHz
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001363 * (a value of 49==0x31) and make sure that the AUTO poll is off
1364 */
Eilon Greenstein589abe32009-02-12 08:36:55 +00001365
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001366 saved_mode = REG_RD(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001367 tmp = saved_mode & ~(EMAC_MDIO_MODE_AUTO_POLL |
1368 EMAC_MDIO_MODE_CLOCK_CNT);
1369 tmp |= (EMAC_MDIO_MODE_CLAUSE_45 |
1370 (49 << EMAC_MDIO_MODE_CLOCK_CNT_BITSHIFT));
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001371 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE, tmp);
1372 REG_RD(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001373 udelay(40);
1374
1375 /* address */
1376
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001377 tmp = ((phy->addr << 21) | (devad << 16) | reg |
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001378 EMAC_MDIO_COMM_COMMAND_ADDRESS |
1379 EMAC_MDIO_COMM_START_BUSY);
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001380 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, tmp);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001381
1382 for (i = 0; i < 50; i++) {
1383 udelay(10);
1384
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001385 tmp = REG_RD(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001386 if (!(tmp & EMAC_MDIO_COMM_START_BUSY)) {
1387 udelay(5);
1388 break;
1389 }
1390 }
1391 if (tmp & EMAC_MDIO_COMM_START_BUSY) {
1392 DP(NETIF_MSG_LINK, "write phy register failed\n");
Yaniv Rosner6d870c32011-01-31 04:22:20 +00001393 netdev_err(bp->dev, "MDC/MDIO access timeout\n");
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001394 rc = -EFAULT;
1395 } else {
1396 /* data */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001397 tmp = ((phy->addr << 21) | (devad << 16) | val |
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001398 EMAC_MDIO_COMM_COMMAND_WRITE_45 |
1399 EMAC_MDIO_COMM_START_BUSY);
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001400 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, tmp);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001401
1402 for (i = 0; i < 50; i++) {
1403 udelay(10);
1404
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001405 tmp = REG_RD(bp, phy->mdio_ctrl +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001406 EMAC_REG_EMAC_MDIO_COMM);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001407 if (!(tmp & EMAC_MDIO_COMM_START_BUSY)) {
1408 udelay(5);
1409 break;
1410 }
1411 }
1412 if (tmp & EMAC_MDIO_COMM_START_BUSY) {
1413 DP(NETIF_MSG_LINK, "write phy register failed\n");
Yaniv Rosner6d870c32011-01-31 04:22:20 +00001414 netdev_err(bp->dev, "MDC/MDIO access timeout\n");
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001415 rc = -EFAULT;
1416 }
1417 }
1418
1419 /* Restore the saved mode */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001420 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE, saved_mode);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001421
1422 return rc;
1423}
1424
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00001425static int bnx2x_cl45_read(struct bnx2x *bp, struct bnx2x_phy *phy,
1426 u8 devad, u16 reg, u16 *ret_val)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001427{
1428 u32 val, saved_mode;
1429 u16 i;
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00001430 int rc = 0;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00001431 /*
1432 * Set clause 45 mode, slow down the MDIO clock to 2.5MHz
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001433 * (a value of 49==0x31) and make sure that the AUTO poll is off
1434 */
Eilon Greenstein589abe32009-02-12 08:36:55 +00001435
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001436 saved_mode = REG_RD(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE);
1437 val = saved_mode & ~((EMAC_MDIO_MODE_AUTO_POLL |
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001438 EMAC_MDIO_MODE_CLOCK_CNT));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001439 val |= (EMAC_MDIO_MODE_CLAUSE_45 |
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00001440 (49L << EMAC_MDIO_MODE_CLOCK_CNT_BITSHIFT));
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001441 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE, val);
1442 REG_RD(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001443 udelay(40);
1444
1445 /* address */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001446 val = ((phy->addr << 21) | (devad << 16) | reg |
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001447 EMAC_MDIO_COMM_COMMAND_ADDRESS |
1448 EMAC_MDIO_COMM_START_BUSY);
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001449 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001450
1451 for (i = 0; i < 50; i++) {
1452 udelay(10);
1453
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001454 val = REG_RD(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001455 if (!(val & EMAC_MDIO_COMM_START_BUSY)) {
1456 udelay(5);
1457 break;
1458 }
1459 }
1460 if (val & EMAC_MDIO_COMM_START_BUSY) {
1461 DP(NETIF_MSG_LINK, "read phy register failed\n");
Yaniv Rosner6d870c32011-01-31 04:22:20 +00001462 netdev_err(bp->dev, "MDC/MDIO access timeout\n");
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001463 *ret_val = 0;
1464 rc = -EFAULT;
1465
1466 } else {
1467 /* data */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001468 val = ((phy->addr << 21) | (devad << 16) |
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001469 EMAC_MDIO_COMM_COMMAND_READ_45 |
1470 EMAC_MDIO_COMM_START_BUSY);
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001471 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001472
1473 for (i = 0; i < 50; i++) {
1474 udelay(10);
1475
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001476 val = REG_RD(bp, phy->mdio_ctrl +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001477 EMAC_REG_EMAC_MDIO_COMM);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001478 if (!(val & EMAC_MDIO_COMM_START_BUSY)) {
1479 *ret_val = (u16)(val & EMAC_MDIO_COMM_DATA);
1480 break;
1481 }
1482 }
1483 if (val & EMAC_MDIO_COMM_START_BUSY) {
1484 DP(NETIF_MSG_LINK, "read phy register failed\n");
Yaniv Rosner6d870c32011-01-31 04:22:20 +00001485 netdev_err(bp->dev, "MDC/MDIO access timeout\n");
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001486 *ret_val = 0;
1487 rc = -EFAULT;
1488 }
1489 }
1490
1491 /* Restore the saved mode */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001492 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE, saved_mode);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001493
1494 return rc;
1495}
1496
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00001497int bnx2x_phy_read(struct link_params *params, u8 phy_addr,
1498 u8 devad, u16 reg, u16 *ret_val)
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001499{
1500 u8 phy_index;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00001501 /*
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001502 * Probe for the phy according to the given phy_addr, and execute
1503 * the read request on it
1504 */
1505 for (phy_index = 0; phy_index < params->num_phys; phy_index++) {
1506 if (params->phy[phy_index].addr == phy_addr) {
1507 return bnx2x_cl45_read(params->bp,
1508 &params->phy[phy_index], devad,
1509 reg, ret_val);
1510 }
1511 }
1512 return -EINVAL;
1513}
1514
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00001515int bnx2x_phy_write(struct link_params *params, u8 phy_addr,
1516 u8 devad, u16 reg, u16 val)
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001517{
1518 u8 phy_index;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00001519 /*
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001520 * Probe for the phy according to the given phy_addr, and execute
1521 * the write request on it
1522 */
1523 for (phy_index = 0; phy_index < params->num_phys; phy_index++) {
1524 if (params->phy[phy_index].addr == phy_addr) {
1525 return bnx2x_cl45_write(params->bp,
1526 &params->phy[phy_index], devad,
1527 reg, val);
1528 }
1529 }
1530 return -EINVAL;
1531}
1532
Yaniv Rosnerec146a62011-05-31 21:29:27 +00001533static void bnx2x_set_aer_mmd(struct link_params *params,
1534 struct bnx2x_phy *phy)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001535{
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001536 u32 ser_lane;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001537 u16 offset, aer_val;
1538 struct bnx2x *bp = params->bp;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001539 ser_lane = ((params->lane_config &
1540 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_MASK) >>
1541 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_SHIFT);
1542
Yaniv Rosnerec146a62011-05-31 21:29:27 +00001543 offset = (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT) ?
1544 (phy->addr + ser_lane) : 0;
1545
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001546 if (CHIP_IS_E2(bp))
Yaniv Rosner82a0d472011-01-18 04:33:52 +00001547 aer_val = 0x3800 + offset - 1;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001548 else
1549 aer_val = 0x3800 + offset;
Yaniv Rosnerec146a62011-05-31 21:29:27 +00001550 DP(NETIF_MSG_LINK, "Set AER to 0x%x\n", aer_val);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00001551 CL22_WR_OVER_CL45(bp, phy, MDIO_REG_BANK_AER_BLOCK,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001552 MDIO_AER_BLOCK_AER_REG, aer_val);
Yaniv Rosnerec146a62011-05-31 21:29:27 +00001553
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001554}
1555
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00001556/******************************************************************/
1557/* Internal phy section */
1558/******************************************************************/
1559
1560static void bnx2x_set_serdes_access(struct bnx2x *bp, u8 port)
1561{
1562 u32 emac_base = (port) ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
1563
1564 /* Set Clause 22 */
1565 REG_WR(bp, NIG_REG_SERDES0_CTRL_MD_ST + port*0x10, 1);
1566 REG_WR(bp, emac_base + EMAC_REG_EMAC_MDIO_COMM, 0x245f8000);
1567 udelay(500);
1568 REG_WR(bp, emac_base + EMAC_REG_EMAC_MDIO_COMM, 0x245d000f);
1569 udelay(500);
1570 /* Set Clause 45 */
1571 REG_WR(bp, NIG_REG_SERDES0_CTRL_MD_ST + port*0x10, 0);
1572}
1573
1574static void bnx2x_serdes_deassert(struct bnx2x *bp, u8 port)
1575{
1576 u32 val;
1577
1578 DP(NETIF_MSG_LINK, "bnx2x_serdes_deassert\n");
1579
1580 val = SERDES_RESET_BITS << (port*16);
1581
1582 /* reset and unreset the SerDes/XGXS */
1583 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_CLEAR, val);
1584 udelay(500);
1585 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_SET, val);
1586
1587 bnx2x_set_serdes_access(bp, port);
1588
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001589 REG_WR(bp, NIG_REG_SERDES0_CTRL_MD_DEVAD + port*0x10,
1590 DEFAULT_PHY_DEV_ADDR);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00001591}
1592
1593static void bnx2x_xgxs_deassert(struct link_params *params)
1594{
1595 struct bnx2x *bp = params->bp;
1596 u8 port;
1597 u32 val;
1598 DP(NETIF_MSG_LINK, "bnx2x_xgxs_deassert\n");
1599 port = params->port;
1600
1601 val = XGXS_RESET_BITS << (port*16);
1602
1603 /* reset and unreset the SerDes/XGXS */
1604 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_CLEAR, val);
1605 udelay(500);
1606 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_SET, val);
1607
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001608 REG_WR(bp, NIG_REG_XGXS0_CTRL_MD_ST + port*0x18, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00001609 REG_WR(bp, NIG_REG_XGXS0_CTRL_MD_DEVAD + port*0x18,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001610 params->phy[INT_PHY].def_md_devad);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00001611}
1612
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00001613static void bnx2x_calc_ieee_aneg_adv(struct bnx2x_phy *phy,
1614 struct link_params *params, u16 *ieee_fc)
1615{
1616 struct bnx2x *bp = params->bp;
1617 *ieee_fc = MDIO_COMBO_IEEE0_AUTO_NEG_ADV_FULL_DUPLEX;
1618 /**
1619 * resolve pause mode and advertisement Please refer to Table
1620 * 28B-3 of the 802.3ab-1999 spec
1621 */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00001622
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00001623 switch (phy->req_flow_ctrl) {
1624 case BNX2X_FLOW_CTRL_AUTO:
1625 if (params->req_fc_auto_adv == BNX2X_FLOW_CTRL_BOTH)
1626 *ieee_fc |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH;
1627 else
1628 *ieee_fc |=
1629 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC;
1630 break;
1631
1632 case BNX2X_FLOW_CTRL_TX:
1633 *ieee_fc |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC;
1634 break;
1635
1636 case BNX2X_FLOW_CTRL_RX:
1637 case BNX2X_FLOW_CTRL_BOTH:
1638 *ieee_fc |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH;
1639 break;
1640
1641 case BNX2X_FLOW_CTRL_NONE:
1642 default:
1643 *ieee_fc |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE;
1644 break;
1645 }
1646 DP(NETIF_MSG_LINK, "ieee_fc = 0x%x\n", *ieee_fc);
1647}
1648
1649static void set_phy_vars(struct link_params *params,
1650 struct link_vars *vars)
1651{
1652 struct bnx2x *bp = params->bp;
1653 u8 actual_phy_idx, phy_index, link_cfg_idx;
1654 u8 phy_config_swapped = params->multi_phy_config &
1655 PORT_HW_CFG_PHY_SWAPPED_ENABLED;
1656 for (phy_index = INT_PHY; phy_index < params->num_phys;
1657 phy_index++) {
1658 link_cfg_idx = LINK_CONFIG_IDX(phy_index);
1659 actual_phy_idx = phy_index;
1660 if (phy_config_swapped) {
1661 if (phy_index == EXT_PHY1)
1662 actual_phy_idx = EXT_PHY2;
1663 else if (phy_index == EXT_PHY2)
1664 actual_phy_idx = EXT_PHY1;
1665 }
1666 params->phy[actual_phy_idx].req_flow_ctrl =
1667 params->req_flow_ctrl[link_cfg_idx];
1668
1669 params->phy[actual_phy_idx].req_line_speed =
1670 params->req_line_speed[link_cfg_idx];
1671
1672 params->phy[actual_phy_idx].speed_cap_mask =
1673 params->speed_cap_mask[link_cfg_idx];
1674
1675 params->phy[actual_phy_idx].req_duplex =
1676 params->req_duplex[link_cfg_idx];
1677
1678 if (params->req_line_speed[link_cfg_idx] ==
1679 SPEED_AUTO_NEG)
1680 vars->link_status |= LINK_STATUS_AUTO_NEGOTIATE_ENABLED;
1681
1682 DP(NETIF_MSG_LINK, "req_flow_ctrl %x, req_line_speed %x,"
1683 " speed_cap_mask %x\n",
1684 params->phy[actual_phy_idx].req_flow_ctrl,
1685 params->phy[actual_phy_idx].req_line_speed,
1686 params->phy[actual_phy_idx].speed_cap_mask);
1687 }
1688}
1689
1690static void bnx2x_ext_phy_set_pause(struct link_params *params,
1691 struct bnx2x_phy *phy,
1692 struct link_vars *vars)
1693{
1694 u16 val;
1695 struct bnx2x *bp = params->bp;
1696 /* read modify write pause advertizing */
1697 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV_PAUSE, &val);
1698
1699 val &= ~MDIO_AN_REG_ADV_PAUSE_BOTH;
1700
1701 /* Please refer to Table 28B-3 of 802.3ab-1999 spec. */
1702 bnx2x_calc_ieee_aneg_adv(phy, params, &vars->ieee_fc);
1703 if ((vars->ieee_fc &
1704 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC) ==
1705 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC) {
1706 val |= MDIO_AN_REG_ADV_PAUSE_ASYMMETRIC;
1707 }
1708 if ((vars->ieee_fc &
1709 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) ==
1710 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) {
1711 val |= MDIO_AN_REG_ADV_PAUSE_PAUSE;
1712 }
1713 DP(NETIF_MSG_LINK, "Ext phy AN advertize 0x%x\n", val);
1714 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV_PAUSE, val);
1715}
1716
1717static void bnx2x_pause_resolve(struct link_vars *vars, u32 pause_result)
1718{ /* LD LP */
1719 switch (pause_result) { /* ASYM P ASYM P */
1720 case 0xb: /* 1 0 1 1 */
1721 vars->flow_ctrl = BNX2X_FLOW_CTRL_TX;
1722 break;
1723
1724 case 0xe: /* 1 1 1 0 */
1725 vars->flow_ctrl = BNX2X_FLOW_CTRL_RX;
1726 break;
1727
1728 case 0x5: /* 0 1 0 1 */
1729 case 0x7: /* 0 1 1 1 */
1730 case 0xd: /* 1 1 0 1 */
1731 case 0xf: /* 1 1 1 1 */
1732 vars->flow_ctrl = BNX2X_FLOW_CTRL_BOTH;
1733 break;
1734
1735 default:
1736 break;
1737 }
1738 if (pause_result & (1<<0))
1739 vars->link_status |= LINK_STATUS_LINK_PARTNER_SYMMETRIC_PAUSE;
1740 if (pause_result & (1<<1))
1741 vars->link_status |= LINK_STATUS_LINK_PARTNER_ASYMMETRIC_PAUSE;
1742}
1743
1744static u8 bnx2x_ext_phy_resolve_fc(struct bnx2x_phy *phy,
1745 struct link_params *params,
1746 struct link_vars *vars)
1747{
1748 struct bnx2x *bp = params->bp;
1749 u16 ld_pause; /* local */
1750 u16 lp_pause; /* link partner */
1751 u16 pause_result;
1752 u8 ret = 0;
1753 /* read twice */
1754
1755 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
1756
1757 if (phy->req_flow_ctrl != BNX2X_FLOW_CTRL_AUTO)
1758 vars->flow_ctrl = phy->req_flow_ctrl;
1759 else if (phy->req_line_speed != SPEED_AUTO_NEG)
1760 vars->flow_ctrl = params->req_fc_auto_adv;
1761 else if (vars->link_status & LINK_STATUS_AUTO_NEGOTIATE_COMPLETE) {
1762 ret = 1;
1763 bnx2x_cl45_read(bp, phy,
1764 MDIO_AN_DEVAD,
1765 MDIO_AN_REG_ADV_PAUSE, &ld_pause);
1766 bnx2x_cl45_read(bp, phy,
1767 MDIO_AN_DEVAD,
1768 MDIO_AN_REG_LP_AUTO_NEG, &lp_pause);
1769 pause_result = (ld_pause &
1770 MDIO_AN_REG_ADV_PAUSE_MASK) >> 8;
1771 pause_result |= (lp_pause &
1772 MDIO_AN_REG_ADV_PAUSE_MASK) >> 10;
1773 DP(NETIF_MSG_LINK, "Ext PHY pause result 0x%x\n",
1774 pause_result);
1775 bnx2x_pause_resolve(vars, pause_result);
1776 }
1777 return ret;
1778}
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00001779void bnx2x_link_status_update(struct link_params *params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001780 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00001781{
1782 struct bnx2x *bp = params->bp;
1783 u8 link_10g;
1784 u8 port = params->port;
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00001785 u32 sync_offset, media_types;
Yaniv Rosnerfd36a2e2011-05-31 21:29:05 +00001786 /* Update PHY configuration */
1787 set_phy_vars(params, vars);
1788
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00001789 vars->link_status = REG_RD(bp, params->shmem_base +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001790 offsetof(struct shmem_region,
1791 port_mb[port].link_status));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00001792
1793 vars->link_up = (vars->link_status & LINK_STATUS_LINK_UP);
Yaniv Rosnerfd36a2e2011-05-31 21:29:05 +00001794 vars->phy_flags = PHY_XGXS_FLAG;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00001795 if (vars->link_up) {
1796 DP(NETIF_MSG_LINK, "phy link up\n");
1797
1798 vars->phy_link_up = 1;
1799 vars->duplex = DUPLEX_FULL;
1800 switch (vars->link_status &
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001801 LINK_STATUS_SPEED_AND_DUPLEX_MASK) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00001802 case LINK_10THD:
1803 vars->duplex = DUPLEX_HALF;
1804 /* fall thru */
1805 case LINK_10TFD:
1806 vars->line_speed = SPEED_10;
1807 break;
1808
1809 case LINK_100TXHD:
1810 vars->duplex = DUPLEX_HALF;
1811 /* fall thru */
1812 case LINK_100T4:
1813 case LINK_100TXFD:
1814 vars->line_speed = SPEED_100;
1815 break;
1816
1817 case LINK_1000THD:
1818 vars->duplex = DUPLEX_HALF;
1819 /* fall thru */
1820 case LINK_1000TFD:
1821 vars->line_speed = SPEED_1000;
1822 break;
1823
1824 case LINK_2500THD:
1825 vars->duplex = DUPLEX_HALF;
1826 /* fall thru */
1827 case LINK_2500TFD:
1828 vars->line_speed = SPEED_2500;
1829 break;
1830
1831 case LINK_10GTFD:
1832 vars->line_speed = SPEED_10000;
1833 break;
1834
1835 case LINK_12GTFD:
1836 vars->line_speed = SPEED_12000;
1837 break;
1838
1839 case LINK_12_5GTFD:
1840 vars->line_speed = SPEED_12500;
1841 break;
1842
1843 case LINK_13GTFD:
1844 vars->line_speed = SPEED_13000;
1845 break;
1846
1847 case LINK_15GTFD:
1848 vars->line_speed = SPEED_15000;
1849 break;
1850
1851 case LINK_16GTFD:
1852 vars->line_speed = SPEED_16000;
1853 break;
1854
1855 default:
1856 break;
1857 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00001858 vars->flow_ctrl = 0;
1859 if (vars->link_status & LINK_STATUS_TX_FLOW_CONTROL_ENABLED)
1860 vars->flow_ctrl |= BNX2X_FLOW_CTRL_TX;
1861
1862 if (vars->link_status & LINK_STATUS_RX_FLOW_CONTROL_ENABLED)
1863 vars->flow_ctrl |= BNX2X_FLOW_CTRL_RX;
1864
1865 if (!vars->flow_ctrl)
1866 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
1867
1868 if (vars->line_speed &&
1869 ((vars->line_speed == SPEED_10) ||
1870 (vars->line_speed == SPEED_100))) {
1871 vars->phy_flags |= PHY_SGMII_FLAG;
1872 } else {
1873 vars->phy_flags &= ~PHY_SGMII_FLAG;
1874 }
1875
1876 /* anything 10 and over uses the bmac */
1877 link_10g = ((vars->line_speed == SPEED_10000) ||
1878 (vars->line_speed == SPEED_12000) ||
1879 (vars->line_speed == SPEED_12500) ||
1880 (vars->line_speed == SPEED_13000) ||
1881 (vars->line_speed == SPEED_15000) ||
1882 (vars->line_speed == SPEED_16000));
1883 if (link_10g)
1884 vars->mac_type = MAC_TYPE_BMAC;
1885 else
1886 vars->mac_type = MAC_TYPE_EMAC;
1887
1888 } else { /* link down */
1889 DP(NETIF_MSG_LINK, "phy link down\n");
1890
1891 vars->phy_link_up = 0;
1892
1893 vars->line_speed = 0;
1894 vars->duplex = DUPLEX_FULL;
1895 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
1896
1897 /* indicate no mac active */
1898 vars->mac_type = MAC_TYPE_NONE;
1899 }
1900
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00001901 /* Sync media type */
1902 sync_offset = params->shmem_base +
1903 offsetof(struct shmem_region,
1904 dev_info.port_hw_config[port].media_type);
1905 media_types = REG_RD(bp, sync_offset);
1906
1907 params->phy[INT_PHY].media_type =
1908 (media_types & PORT_HW_CFG_MEDIA_TYPE_PHY0_MASK) >>
1909 PORT_HW_CFG_MEDIA_TYPE_PHY0_SHIFT;
1910 params->phy[EXT_PHY1].media_type =
1911 (media_types & PORT_HW_CFG_MEDIA_TYPE_PHY1_MASK) >>
1912 PORT_HW_CFG_MEDIA_TYPE_PHY1_SHIFT;
1913 params->phy[EXT_PHY2].media_type =
1914 (media_types & PORT_HW_CFG_MEDIA_TYPE_PHY2_MASK) >>
1915 PORT_HW_CFG_MEDIA_TYPE_PHY2_SHIFT;
1916 DP(NETIF_MSG_LINK, "media_types = 0x%x\n", media_types);
1917
Yaniv Rosner020c7e32011-05-31 21:28:43 +00001918 /* Sync AEU offset */
1919 sync_offset = params->shmem_base +
1920 offsetof(struct shmem_region,
1921 dev_info.port_hw_config[port].aeu_int_mask);
1922
1923 vars->aeu_int_mask = REG_RD(bp, sync_offset);
1924
1925 DP(NETIF_MSG_LINK, "link_status 0x%x phy_link_up %x int_mask 0x%x\n",
1926 vars->link_status, vars->phy_link_up, vars->aeu_int_mask);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00001927 DP(NETIF_MSG_LINK, "line_speed %x duplex %x flow_ctrl 0x%x\n",
1928 vars->line_speed, vars->duplex, vars->flow_ctrl);
1929}
1930
1931
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001932static void bnx2x_set_master_ln(struct link_params *params,
1933 struct bnx2x_phy *phy)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001934{
1935 struct bnx2x *bp = params->bp;
1936 u16 new_master_ln, ser_lane;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001937 ser_lane = ((params->lane_config &
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001938 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_MASK) >>
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001939 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_SHIFT);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001940
1941 /* set the master_ln for AN */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00001942 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001943 MDIO_REG_BANK_XGXS_BLOCK2,
1944 MDIO_XGXS_BLOCK2_TEST_MODE_LANE,
1945 &new_master_ln);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001946
Yaniv Rosnercd2be892011-01-31 04:21:45 +00001947 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001948 MDIO_REG_BANK_XGXS_BLOCK2 ,
1949 MDIO_XGXS_BLOCK2_TEST_MODE_LANE,
1950 (new_master_ln | ser_lane));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001951}
1952
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00001953static int bnx2x_reset_unicore(struct link_params *params,
1954 struct bnx2x_phy *phy,
1955 u8 set_serdes)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001956{
1957 struct bnx2x *bp = params->bp;
1958 u16 mii_control;
1959 u16 i;
Yaniv Rosnercd2be892011-01-31 04:21:45 +00001960 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001961 MDIO_REG_BANK_COMBO_IEEE0,
1962 MDIO_COMBO_IEEE0_MII_CONTROL, &mii_control);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001963
1964 /* reset the unicore */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00001965 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001966 MDIO_REG_BANK_COMBO_IEEE0,
1967 MDIO_COMBO_IEEE0_MII_CONTROL,
1968 (mii_control |
1969 MDIO_COMBO_IEEO_MII_CONTROL_RESET));
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001970 if (set_serdes)
1971 bnx2x_set_serdes_access(bp, params->port);
Eilon Greensteinc1b73992009-02-12 08:37:07 +00001972
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001973 /* wait for the reset to self clear */
1974 for (i = 0; i < MDIO_ACCESS_TIMEOUT; i++) {
1975 udelay(5);
1976
1977 /* the reset erased the previous bank value */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00001978 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001979 MDIO_REG_BANK_COMBO_IEEE0,
1980 MDIO_COMBO_IEEE0_MII_CONTROL,
1981 &mii_control);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001982
1983 if (!(mii_control & MDIO_COMBO_IEEO_MII_CONTROL_RESET)) {
1984 udelay(5);
1985 return 0;
1986 }
1987 }
1988
Yaniv Rosner6d870c32011-01-31 04:22:20 +00001989 netdev_err(bp->dev, "Warning: PHY was not initialized,"
1990 " Port %d\n",
1991 params->port);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001992 DP(NETIF_MSG_LINK, "BUG! XGXS is still in reset!\n");
1993 return -EINVAL;
1994
1995}
1996
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001997static void bnx2x_set_swap_lanes(struct link_params *params,
1998 struct bnx2x_phy *phy)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001999{
2000 struct bnx2x *bp = params->bp;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002001 /*
2002 * Each two bits represents a lane number:
2003 * No swap is 0123 => 0x1b no need to enable the swap
2004 */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002005 u16 ser_lane, rx_lane_swap, tx_lane_swap;
2006
2007 ser_lane = ((params->lane_config &
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002008 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_MASK) >>
2009 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_SHIFT);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002010 rx_lane_swap = ((params->lane_config &
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002011 PORT_HW_CFG_LANE_SWAP_CFG_RX_MASK) >>
2012 PORT_HW_CFG_LANE_SWAP_CFG_RX_SHIFT);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002013 tx_lane_swap = ((params->lane_config &
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002014 PORT_HW_CFG_LANE_SWAP_CFG_TX_MASK) >>
2015 PORT_HW_CFG_LANE_SWAP_CFG_TX_SHIFT);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002016
2017 if (rx_lane_swap != 0x1b) {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002018 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002019 MDIO_REG_BANK_XGXS_BLOCK2,
2020 MDIO_XGXS_BLOCK2_RX_LN_SWAP,
2021 (rx_lane_swap |
2022 MDIO_XGXS_BLOCK2_RX_LN_SWAP_ENABLE |
2023 MDIO_XGXS_BLOCK2_RX_LN_SWAP_FORCE_ENABLE));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002024 } else {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002025 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002026 MDIO_REG_BANK_XGXS_BLOCK2,
2027 MDIO_XGXS_BLOCK2_RX_LN_SWAP, 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002028 }
2029
2030 if (tx_lane_swap != 0x1b) {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002031 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002032 MDIO_REG_BANK_XGXS_BLOCK2,
2033 MDIO_XGXS_BLOCK2_TX_LN_SWAP,
2034 (tx_lane_swap |
2035 MDIO_XGXS_BLOCK2_TX_LN_SWAP_ENABLE));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002036 } else {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002037 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002038 MDIO_REG_BANK_XGXS_BLOCK2,
2039 MDIO_XGXS_BLOCK2_TX_LN_SWAP, 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002040 }
2041}
2042
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002043static void bnx2x_set_parallel_detection(struct bnx2x_phy *phy,
2044 struct link_params *params)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002045{
2046 struct bnx2x *bp = params->bp;
2047 u16 control2;
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002048 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002049 MDIO_REG_BANK_SERDES_DIGITAL,
2050 MDIO_SERDES_DIGITAL_A_1000X_CONTROL2,
2051 &control2);
Yaniv Rosner7aa07112010-09-07 11:41:01 +00002052 if (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)
Yaniv Rosner18afb0a2009-11-05 19:18:04 +02002053 control2 |= MDIO_SERDES_DIGITAL_A_1000X_CONTROL2_PRL_DT_EN;
2054 else
2055 control2 &= ~MDIO_SERDES_DIGITAL_A_1000X_CONTROL2_PRL_DT_EN;
Yaniv Rosner7aa07112010-09-07 11:41:01 +00002056 DP(NETIF_MSG_LINK, "phy->speed_cap_mask = 0x%x, control2 = 0x%x\n",
2057 phy->speed_cap_mask, control2);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002058 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002059 MDIO_REG_BANK_SERDES_DIGITAL,
2060 MDIO_SERDES_DIGITAL_A_1000X_CONTROL2,
2061 control2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002062
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002063 if ((phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT) &&
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00002064 (phy->speed_cap_mask &
Yaniv Rosner18afb0a2009-11-05 19:18:04 +02002065 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002066 DP(NETIF_MSG_LINK, "XGXS\n");
2067
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002068 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002069 MDIO_REG_BANK_10G_PARALLEL_DETECT,
2070 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_LINK,
2071 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_LINK_CNT);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002072
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002073 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002074 MDIO_REG_BANK_10G_PARALLEL_DETECT,
2075 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_CONTROL,
2076 &control2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002077
2078
2079 control2 |=
2080 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_CONTROL_PARDET10G_EN;
2081
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002082 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002083 MDIO_REG_BANK_10G_PARALLEL_DETECT,
2084 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_CONTROL,
2085 control2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002086
2087 /* Disable parallel detection of HiG */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002088 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002089 MDIO_REG_BANK_XGXS_BLOCK2,
2090 MDIO_XGXS_BLOCK2_UNICORE_MODE_10G,
2091 MDIO_XGXS_BLOCK2_UNICORE_MODE_10G_CX4_XGXS |
2092 MDIO_XGXS_BLOCK2_UNICORE_MODE_10G_HIGIG_XGXS);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002093 }
2094}
2095
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002096static void bnx2x_set_autoneg(struct bnx2x_phy *phy,
2097 struct link_params *params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002098 struct link_vars *vars,
2099 u8 enable_cl73)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002100{
2101 struct bnx2x *bp = params->bp;
2102 u16 reg_val;
2103
2104 /* CL37 Autoneg */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002105 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002106 MDIO_REG_BANK_COMBO_IEEE0,
2107 MDIO_COMBO_IEEE0_MII_CONTROL, &reg_val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002108
2109 /* CL37 Autoneg Enabled */
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002110 if (vars->line_speed == SPEED_AUTO_NEG)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002111 reg_val |= MDIO_COMBO_IEEO_MII_CONTROL_AN_EN;
2112 else /* CL37 Autoneg Disabled */
2113 reg_val &= ~(MDIO_COMBO_IEEO_MII_CONTROL_AN_EN |
2114 MDIO_COMBO_IEEO_MII_CONTROL_RESTART_AN);
2115
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002116 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002117 MDIO_REG_BANK_COMBO_IEEE0,
2118 MDIO_COMBO_IEEE0_MII_CONTROL, reg_val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002119
2120 /* Enable/Disable Autodetection */
2121
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002122 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002123 MDIO_REG_BANK_SERDES_DIGITAL,
2124 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1, &reg_val);
Eilon Greenstein239d6862009-08-12 08:23:04 +00002125 reg_val &= ~(MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_SIGNAL_DETECT_EN |
2126 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_INVERT_SIGNAL_DETECT);
2127 reg_val |= MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_FIBER_MODE;
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002128 if (vars->line_speed == SPEED_AUTO_NEG)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002129 reg_val |= MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_AUTODET;
2130 else
2131 reg_val &= ~MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_AUTODET;
2132
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002133 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002134 MDIO_REG_BANK_SERDES_DIGITAL,
2135 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1, reg_val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002136
2137 /* Enable TetonII and BAM autoneg */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002138 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002139 MDIO_REG_BANK_BAM_NEXT_PAGE,
2140 MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL,
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002141 &reg_val);
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002142 if (vars->line_speed == SPEED_AUTO_NEG) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002143 /* Enable BAM aneg Mode and TetonII aneg Mode */
2144 reg_val |= (MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL_BAM_MODE |
2145 MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL_TETON_AN);
2146 } else {
2147 /* TetonII and BAM Autoneg Disabled */
2148 reg_val &= ~(MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL_BAM_MODE |
2149 MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL_TETON_AN);
2150 }
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002151 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002152 MDIO_REG_BANK_BAM_NEXT_PAGE,
2153 MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL,
2154 reg_val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002155
Eilon Greenstein239d6862009-08-12 08:23:04 +00002156 if (enable_cl73) {
2157 /* Enable Cl73 FSM status bits */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002158 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002159 MDIO_REG_BANK_CL73_USERB0,
2160 MDIO_CL73_USERB0_CL73_UCTRL,
2161 0xe);
Eilon Greenstein239d6862009-08-12 08:23:04 +00002162
2163 /* Enable BAM Station Manager*/
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002164 CL22_WR_OVER_CL45(bp, phy,
Eilon Greenstein239d6862009-08-12 08:23:04 +00002165 MDIO_REG_BANK_CL73_USERB0,
2166 MDIO_CL73_USERB0_CL73_BAM_CTRL1,
2167 MDIO_CL73_USERB0_CL73_BAM_CTRL1_BAM_EN |
2168 MDIO_CL73_USERB0_CL73_BAM_CTRL1_BAM_STATION_MNGR_EN |
2169 MDIO_CL73_USERB0_CL73_BAM_CTRL1_BAM_NP_AFTER_BP_EN);
2170
Yaniv Rosner7846e472009-11-05 19:18:07 +02002171 /* Advertise CL73 link speeds */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002172 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002173 MDIO_REG_BANK_CL73_IEEEB1,
2174 MDIO_CL73_IEEEB1_AN_ADV2,
2175 &reg_val);
Yaniv Rosner7aa07112010-09-07 11:41:01 +00002176 if (phy->speed_cap_mask &
Yaniv Rosner7846e472009-11-05 19:18:07 +02002177 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
2178 reg_val |= MDIO_CL73_IEEEB1_AN_ADV2_ADVR_10G_KX4;
Yaniv Rosner7aa07112010-09-07 11:41:01 +00002179 if (phy->speed_cap_mask &
Yaniv Rosner7846e472009-11-05 19:18:07 +02002180 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)
2181 reg_val |= MDIO_CL73_IEEEB1_AN_ADV2_ADVR_1000M_KX;
Eilon Greenstein239d6862009-08-12 08:23:04 +00002182
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002183 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002184 MDIO_REG_BANK_CL73_IEEEB1,
2185 MDIO_CL73_IEEEB1_AN_ADV2,
2186 reg_val);
Eilon Greenstein239d6862009-08-12 08:23:04 +00002187
Eilon Greenstein239d6862009-08-12 08:23:04 +00002188 /* CL73 Autoneg Enabled */
2189 reg_val = MDIO_CL73_IEEEB0_CL73_AN_CONTROL_AN_EN;
2190
2191 } else /* CL73 Autoneg Disabled */
2192 reg_val = 0;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002193
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002194 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002195 MDIO_REG_BANK_CL73_IEEEB0,
2196 MDIO_CL73_IEEEB0_CL73_AN_CONTROL, reg_val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002197}
2198
2199/* program SerDes, forced speed */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002200static void bnx2x_program_serdes(struct bnx2x_phy *phy,
2201 struct link_params *params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002202 struct link_vars *vars)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002203{
2204 struct bnx2x *bp = params->bp;
2205 u16 reg_val;
2206
Eilon Greenstein57937202009-08-12 08:23:53 +00002207 /* program duplex, disable autoneg and sgmii*/
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002208 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002209 MDIO_REG_BANK_COMBO_IEEE0,
2210 MDIO_COMBO_IEEE0_MII_CONTROL, &reg_val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002211 reg_val &= ~(MDIO_COMBO_IEEO_MII_CONTROL_FULL_DUPLEX |
Eilon Greenstein57937202009-08-12 08:23:53 +00002212 MDIO_COMBO_IEEO_MII_CONTROL_AN_EN |
2213 MDIO_COMBO_IEEO_MII_CONTROL_MAN_SGMII_SP_MASK);
Yaniv Rosner7aa07112010-09-07 11:41:01 +00002214 if (phy->req_duplex == DUPLEX_FULL)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002215 reg_val |= MDIO_COMBO_IEEO_MII_CONTROL_FULL_DUPLEX;
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002216 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002217 MDIO_REG_BANK_COMBO_IEEE0,
2218 MDIO_COMBO_IEEE0_MII_CONTROL, reg_val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002219
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002220 /*
2221 * program speed
2222 * - needed only if the speed is greater than 1G (2.5G or 10G)
2223 */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002224 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002225 MDIO_REG_BANK_SERDES_DIGITAL,
2226 MDIO_SERDES_DIGITAL_MISC1, &reg_val);
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002227 /* clearing the speed value before setting the right speed */
2228 DP(NETIF_MSG_LINK, "MDIO_REG_BANK_SERDES_DIGITAL = 0x%x\n", reg_val);
2229
2230 reg_val &= ~(MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_MASK |
2231 MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_SEL);
2232
2233 if (!((vars->line_speed == SPEED_1000) ||
2234 (vars->line_speed == SPEED_100) ||
2235 (vars->line_speed == SPEED_10))) {
2236
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002237 reg_val |= (MDIO_SERDES_DIGITAL_MISC1_REFCLK_SEL_156_25M |
2238 MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_SEL);
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002239 if (vars->line_speed == SPEED_10000)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002240 reg_val |=
2241 MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_10G_CX4;
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002242 if (vars->line_speed == SPEED_13000)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002243 reg_val |=
2244 MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_13G;
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002245 }
2246
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002247 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002248 MDIO_REG_BANK_SERDES_DIGITAL,
2249 MDIO_SERDES_DIGITAL_MISC1, reg_val);
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002250
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002251}
2252
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00002253static void bnx2x_set_brcm_cl37_advertisement(struct bnx2x_phy *phy,
2254 struct link_params *params)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002255{
2256 struct bnx2x *bp = params->bp;
2257 u16 val = 0;
2258
2259 /* configure the 48 bits for BAM AN */
2260
2261 /* set extended capabilities */
Yaniv Rosner7aa07112010-09-07 11:41:01 +00002262 if (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002263 val |= MDIO_OVER_1G_UP1_2_5G;
Yaniv Rosner7aa07112010-09-07 11:41:01 +00002264 if (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002265 val |= MDIO_OVER_1G_UP1_10G;
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002266 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002267 MDIO_REG_BANK_OVER_1G,
2268 MDIO_OVER_1G_UP1, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002269
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002270 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002271 MDIO_REG_BANK_OVER_1G,
2272 MDIO_OVER_1G_UP3, 0x400);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002273}
2274
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00002275static void bnx2x_set_ieee_aneg_advertisement(struct bnx2x_phy *phy,
2276 struct link_params *params,
2277 u16 ieee_fc)
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002278{
2279 struct bnx2x *bp = params->bp;
Yaniv Rosner7846e472009-11-05 19:18:07 +02002280 u16 val;
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002281 /* for AN, we are always publishing full duplex */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002282
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002283 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002284 MDIO_REG_BANK_COMBO_IEEE0,
2285 MDIO_COMBO_IEEE0_AUTO_NEG_ADV, ieee_fc);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002286 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002287 MDIO_REG_BANK_CL73_IEEEB1,
2288 MDIO_CL73_IEEEB1_AN_ADV1, &val);
Yaniv Rosner7846e472009-11-05 19:18:07 +02002289 val &= ~MDIO_CL73_IEEEB1_AN_ADV1_PAUSE_BOTH;
2290 val |= ((ieee_fc<<3) & MDIO_CL73_IEEEB1_AN_ADV1_PAUSE_MASK);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002291 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002292 MDIO_REG_BANK_CL73_IEEEB1,
2293 MDIO_CL73_IEEEB1_AN_ADV1, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002294}
2295
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002296static void bnx2x_restart_autoneg(struct bnx2x_phy *phy,
2297 struct link_params *params,
2298 u8 enable_cl73)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002299{
2300 struct bnx2x *bp = params->bp;
Eilon Greenstein3a36f2e2009-02-12 08:37:09 +00002301 u16 mii_control;
Eilon Greenstein239d6862009-08-12 08:23:04 +00002302
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002303 DP(NETIF_MSG_LINK, "bnx2x_restart_autoneg\n");
Eilon Greenstein3a36f2e2009-02-12 08:37:09 +00002304 /* Enable and restart BAM/CL37 aneg */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002305
Eilon Greenstein239d6862009-08-12 08:23:04 +00002306 if (enable_cl73) {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002307 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002308 MDIO_REG_BANK_CL73_IEEEB0,
2309 MDIO_CL73_IEEEB0_CL73_AN_CONTROL,
2310 &mii_control);
Eilon Greenstein239d6862009-08-12 08:23:04 +00002311
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002312 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002313 MDIO_REG_BANK_CL73_IEEEB0,
2314 MDIO_CL73_IEEEB0_CL73_AN_CONTROL,
2315 (mii_control |
2316 MDIO_CL73_IEEEB0_CL73_AN_CONTROL_AN_EN |
2317 MDIO_CL73_IEEEB0_CL73_AN_CONTROL_RESTART_AN));
Eilon Greenstein239d6862009-08-12 08:23:04 +00002318 } else {
2319
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002320 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002321 MDIO_REG_BANK_COMBO_IEEE0,
2322 MDIO_COMBO_IEEE0_MII_CONTROL,
2323 &mii_control);
Eilon Greenstein239d6862009-08-12 08:23:04 +00002324 DP(NETIF_MSG_LINK,
2325 "bnx2x_restart_autoneg mii_control before = 0x%x\n",
2326 mii_control);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002327 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002328 MDIO_REG_BANK_COMBO_IEEE0,
2329 MDIO_COMBO_IEEE0_MII_CONTROL,
2330 (mii_control |
2331 MDIO_COMBO_IEEO_MII_CONTROL_AN_EN |
2332 MDIO_COMBO_IEEO_MII_CONTROL_RESTART_AN));
Eilon Greenstein239d6862009-08-12 08:23:04 +00002333 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002334}
2335
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002336static void bnx2x_initialize_sgmii_process(struct bnx2x_phy *phy,
2337 struct link_params *params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002338 struct link_vars *vars)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002339{
2340 struct bnx2x *bp = params->bp;
2341 u16 control1;
2342
2343 /* in SGMII mode, the unicore is always slave */
2344
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002345 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002346 MDIO_REG_BANK_SERDES_DIGITAL,
2347 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1,
2348 &control1);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002349 control1 |= MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_INVERT_SIGNAL_DETECT;
2350 /* set sgmii mode (and not fiber) */
2351 control1 &= ~(MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_FIBER_MODE |
2352 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_AUTODET |
2353 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_MSTR_MODE);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002354 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002355 MDIO_REG_BANK_SERDES_DIGITAL,
2356 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1,
2357 control1);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002358
2359 /* if forced speed */
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002360 if (!(vars->line_speed == SPEED_AUTO_NEG)) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002361 /* set speed, disable autoneg */
2362 u16 mii_control;
2363
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002364 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002365 MDIO_REG_BANK_COMBO_IEEE0,
2366 MDIO_COMBO_IEEE0_MII_CONTROL,
2367 &mii_control);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002368 mii_control &= ~(MDIO_COMBO_IEEO_MII_CONTROL_AN_EN |
2369 MDIO_COMBO_IEEO_MII_CONTROL_MAN_SGMII_SP_MASK|
2370 MDIO_COMBO_IEEO_MII_CONTROL_FULL_DUPLEX);
2371
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002372 switch (vars->line_speed) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002373 case SPEED_100:
2374 mii_control |=
2375 MDIO_COMBO_IEEO_MII_CONTROL_MAN_SGMII_SP_100;
2376 break;
2377 case SPEED_1000:
2378 mii_control |=
2379 MDIO_COMBO_IEEO_MII_CONTROL_MAN_SGMII_SP_1000;
2380 break;
2381 case SPEED_10:
2382 /* there is nothing to set for 10M */
2383 break;
2384 default:
2385 /* invalid speed for SGMII */
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002386 DP(NETIF_MSG_LINK, "Invalid line_speed 0x%x\n",
2387 vars->line_speed);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002388 break;
2389 }
2390
2391 /* setting the full duplex */
Yaniv Rosner7aa07112010-09-07 11:41:01 +00002392 if (phy->req_duplex == DUPLEX_FULL)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002393 mii_control |=
2394 MDIO_COMBO_IEEO_MII_CONTROL_FULL_DUPLEX;
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002395 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002396 MDIO_REG_BANK_COMBO_IEEE0,
2397 MDIO_COMBO_IEEE0_MII_CONTROL,
2398 mii_control);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002399
2400 } else { /* AN mode */
2401 /* enable and restart AN */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002402 bnx2x_restart_autoneg(phy, params, 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002403 }
2404}
2405
2406
2407/*
2408 * link management
2409 */
2410
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00002411static int bnx2x_direct_parallel_detect_used(struct bnx2x_phy *phy,
2412 struct link_params *params)
Yaniv Rosner15ddd2d2009-11-05 19:18:12 +02002413{
2414 struct bnx2x *bp = params->bp;
2415 u16 pd_10g, status2_1000x;
Yaniv Rosner7aa07112010-09-07 11:41:01 +00002416 if (phy->req_line_speed != SPEED_AUTO_NEG)
2417 return 0;
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002418 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002419 MDIO_REG_BANK_SERDES_DIGITAL,
2420 MDIO_SERDES_DIGITAL_A_1000X_STATUS2,
2421 &status2_1000x);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002422 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002423 MDIO_REG_BANK_SERDES_DIGITAL,
2424 MDIO_SERDES_DIGITAL_A_1000X_STATUS2,
2425 &status2_1000x);
Yaniv Rosner15ddd2d2009-11-05 19:18:12 +02002426 if (status2_1000x & MDIO_SERDES_DIGITAL_A_1000X_STATUS2_AN_DISABLED) {
2427 DP(NETIF_MSG_LINK, "1G parallel detect link on port %d\n",
2428 params->port);
2429 return 1;
2430 }
2431
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002432 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002433 MDIO_REG_BANK_10G_PARALLEL_DETECT,
2434 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_STATUS,
2435 &pd_10g);
Yaniv Rosner15ddd2d2009-11-05 19:18:12 +02002436
2437 if (pd_10g & MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_STATUS_PD_LINK) {
2438 DP(NETIF_MSG_LINK, "10G parallel detect link on port %d\n",
2439 params->port);
2440 return 1;
2441 }
2442 return 0;
2443}
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002444
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002445static void bnx2x_flow_ctrl_resolve(struct bnx2x_phy *phy,
2446 struct link_params *params,
2447 struct link_vars *vars,
2448 u32 gp_status)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002449{
2450 struct bnx2x *bp = params->bp;
Eilon Greenstein3196a882008-08-13 15:58:49 -07002451 u16 ld_pause; /* local driver */
2452 u16 lp_pause; /* link partner */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002453 u16 pause_result;
2454
David S. Millerc0700f92008-12-16 23:53:20 -08002455 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002456
2457 /* resolve from gp_status in case of AN complete and not sgmii */
Yaniv Rosner7aa07112010-09-07 11:41:01 +00002458 if (phy->req_flow_ctrl != BNX2X_FLOW_CTRL_AUTO)
2459 vars->flow_ctrl = phy->req_flow_ctrl;
2460 else if (phy->req_line_speed != SPEED_AUTO_NEG)
2461 vars->flow_ctrl = params->req_fc_auto_adv;
2462 else if ((gp_status & MDIO_AN_CL73_OR_37_COMPLETE) &&
2463 (!(vars->phy_flags & PHY_SGMII_FLAG))) {
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002464 if (bnx2x_direct_parallel_detect_used(phy, params)) {
Yaniv Rosner15ddd2d2009-11-05 19:18:12 +02002465 vars->flow_ctrl = params->req_fc_auto_adv;
2466 return;
2467 }
Yaniv Rosner7846e472009-11-05 19:18:07 +02002468 if ((gp_status &
2469 (MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_AUTONEG_COMPLETE |
2470 MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_MR_LP_NP_AN_ABLE)) ==
2471 (MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_AUTONEG_COMPLETE |
2472 MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_MR_LP_NP_AN_ABLE)) {
2473
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002474 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002475 MDIO_REG_BANK_CL73_IEEEB1,
2476 MDIO_CL73_IEEEB1_AN_ADV1,
2477 &ld_pause);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002478 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002479 MDIO_REG_BANK_CL73_IEEEB1,
2480 MDIO_CL73_IEEEB1_AN_LP_ADV1,
2481 &lp_pause);
Yaniv Rosner7846e472009-11-05 19:18:07 +02002482 pause_result = (ld_pause &
2483 MDIO_CL73_IEEEB1_AN_ADV1_PAUSE_MASK)
2484 >> 8;
2485 pause_result |= (lp_pause &
2486 MDIO_CL73_IEEEB1_AN_LP_ADV1_PAUSE_MASK)
2487 >> 10;
2488 DP(NETIF_MSG_LINK, "pause_result CL73 0x%x\n",
2489 pause_result);
2490 } else {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002491 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002492 MDIO_REG_BANK_COMBO_IEEE0,
2493 MDIO_COMBO_IEEE0_AUTO_NEG_ADV,
2494 &ld_pause);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002495 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002496 MDIO_REG_BANK_COMBO_IEEE0,
2497 MDIO_COMBO_IEEE0_AUTO_NEG_LINK_PARTNER_ABILITY1,
2498 &lp_pause);
Yaniv Rosner7846e472009-11-05 19:18:07 +02002499 pause_result = (ld_pause &
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002500 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK)>>5;
Yaniv Rosner7846e472009-11-05 19:18:07 +02002501 pause_result |= (lp_pause &
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002502 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK)>>7;
Yaniv Rosner7846e472009-11-05 19:18:07 +02002503 DP(NETIF_MSG_LINK, "pause_result CL37 0x%x\n",
2504 pause_result);
2505 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002506 bnx2x_pause_resolve(vars, pause_result);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002507 }
2508 DP(NETIF_MSG_LINK, "flow_ctrl 0x%x\n", vars->flow_ctrl);
2509}
2510
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002511static void bnx2x_check_fallback_to_cl37(struct bnx2x_phy *phy,
2512 struct link_params *params)
Eilon Greenstein239d6862009-08-12 08:23:04 +00002513{
2514 struct bnx2x *bp = params->bp;
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00002515 u16 rx_status, ustat_val, cl37_fsm_received;
Eilon Greenstein239d6862009-08-12 08:23:04 +00002516 DP(NETIF_MSG_LINK, "bnx2x_check_fallback_to_cl37\n");
2517 /* Step 1: Make sure signal is detected */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002518 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002519 MDIO_REG_BANK_RX0,
2520 MDIO_RX0_RX_STATUS,
2521 &rx_status);
Eilon Greenstein239d6862009-08-12 08:23:04 +00002522 if ((rx_status & MDIO_RX0_RX_STATUS_SIGDET) !=
2523 (MDIO_RX0_RX_STATUS_SIGDET)) {
2524 DP(NETIF_MSG_LINK, "Signal is not detected. Restoring CL73."
2525 "rx_status(0x80b0) = 0x%x\n", rx_status);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002526 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002527 MDIO_REG_BANK_CL73_IEEEB0,
2528 MDIO_CL73_IEEEB0_CL73_AN_CONTROL,
2529 MDIO_CL73_IEEEB0_CL73_AN_CONTROL_AN_EN);
Eilon Greenstein239d6862009-08-12 08:23:04 +00002530 return;
2531 }
2532 /* Step 2: Check CL73 state machine */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002533 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002534 MDIO_REG_BANK_CL73_USERB0,
2535 MDIO_CL73_USERB0_CL73_USTAT1,
2536 &ustat_val);
Eilon Greenstein239d6862009-08-12 08:23:04 +00002537 if ((ustat_val &
2538 (MDIO_CL73_USERB0_CL73_USTAT1_LINK_STATUS_CHECK |
2539 MDIO_CL73_USERB0_CL73_USTAT1_AN_GOOD_CHECK_BAM37)) !=
2540 (MDIO_CL73_USERB0_CL73_USTAT1_LINK_STATUS_CHECK |
2541 MDIO_CL73_USERB0_CL73_USTAT1_AN_GOOD_CHECK_BAM37)) {
2542 DP(NETIF_MSG_LINK, "CL73 state-machine is not stable. "
2543 "ustat_val(0x8371) = 0x%x\n", ustat_val);
2544 return;
2545 }
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002546 /*
2547 * Step 3: Check CL37 Message Pages received to indicate LP
2548 * supports only CL37
2549 */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002550 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002551 MDIO_REG_BANK_REMOTE_PHY,
2552 MDIO_REMOTE_PHY_MISC_RX_STATUS,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00002553 &cl37_fsm_received);
2554 if ((cl37_fsm_received &
Eilon Greenstein239d6862009-08-12 08:23:04 +00002555 (MDIO_REMOTE_PHY_MISC_RX_STATUS_CL37_FSM_RECEIVED_OVER1G_MSG |
2556 MDIO_REMOTE_PHY_MISC_RX_STATUS_CL37_FSM_RECEIVED_BRCM_OUI_MSG)) !=
2557 (MDIO_REMOTE_PHY_MISC_RX_STATUS_CL37_FSM_RECEIVED_OVER1G_MSG |
2558 MDIO_REMOTE_PHY_MISC_RX_STATUS_CL37_FSM_RECEIVED_BRCM_OUI_MSG)) {
2559 DP(NETIF_MSG_LINK, "No CL37 FSM were received. "
2560 "misc_rx_status(0x8330) = 0x%x\n",
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00002561 cl37_fsm_received);
Eilon Greenstein239d6862009-08-12 08:23:04 +00002562 return;
2563 }
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002564 /*
2565 * The combined cl37/cl73 fsm state information indicating that
2566 * we are connected to a device which does not support cl73, but
2567 * does support cl37 BAM. In this case we disable cl73 and
2568 * restart cl37 auto-neg
2569 */
2570
Eilon Greenstein239d6862009-08-12 08:23:04 +00002571 /* Disable CL73 */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002572 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002573 MDIO_REG_BANK_CL73_IEEEB0,
2574 MDIO_CL73_IEEEB0_CL73_AN_CONTROL,
2575 0);
Eilon Greenstein239d6862009-08-12 08:23:04 +00002576 /* Restart CL37 autoneg */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002577 bnx2x_restart_autoneg(phy, params, 0);
Eilon Greenstein239d6862009-08-12 08:23:04 +00002578 DP(NETIF_MSG_LINK, "Disabling CL73, and restarting CL37 autoneg\n");
2579}
Yaniv Rosner7aa07112010-09-07 11:41:01 +00002580
2581static void bnx2x_xgxs_an_resolve(struct bnx2x_phy *phy,
2582 struct link_params *params,
2583 struct link_vars *vars,
2584 u32 gp_status)
2585{
2586 if (gp_status & MDIO_AN_CL73_OR_37_COMPLETE)
2587 vars->link_status |=
2588 LINK_STATUS_AUTO_NEGOTIATE_COMPLETE;
2589
2590 if (bnx2x_direct_parallel_detect_used(phy, params))
2591 vars->link_status |=
2592 LINK_STATUS_PARALLEL_DETECTION_USED;
2593}
2594
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00002595static int bnx2x_link_settings_status(struct bnx2x_phy *phy,
2596 struct link_params *params,
2597 struct link_vars *vars)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002598{
2599 struct bnx2x *bp = params->bp;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002600 u16 new_line_speed, gp_status;
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00002601 int rc = 0;
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00002602
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00002603 /* Read gp_status */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002604 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002605 MDIO_REG_BANK_GP_STATUS,
2606 MDIO_GP_STATUS_TOP_AN_STATUS1,
2607 &gp_status);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00002608
Yaniv Rosner7aa07112010-09-07 11:41:01 +00002609 if (phy->req_line_speed == SPEED_AUTO_NEG)
2610 vars->link_status |= LINK_STATUS_AUTO_NEGOTIATE_ENABLED;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002611 if (gp_status & MDIO_GP_STATUS_TOP_AN_STATUS1_LINK_STATUS) {
2612 DP(NETIF_MSG_LINK, "phy link up gp_status=0x%x\n",
2613 gp_status);
2614
2615 vars->phy_link_up = 1;
2616 vars->link_status |= LINK_STATUS_LINK_UP;
2617
2618 if (gp_status & MDIO_GP_STATUS_TOP_AN_STATUS1_DUPLEX_STATUS)
2619 vars->duplex = DUPLEX_FULL;
2620 else
2621 vars->duplex = DUPLEX_HALF;
2622
Yaniv Rosner7aa07112010-09-07 11:41:01 +00002623 if (SINGLE_MEDIA_DIRECT(params)) {
2624 bnx2x_flow_ctrl_resolve(phy, params, vars, gp_status);
2625 if (phy->req_line_speed == SPEED_AUTO_NEG)
2626 bnx2x_xgxs_an_resolve(phy, params, vars,
2627 gp_status);
2628 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002629
2630 switch (gp_status & GP_STATUS_SPEED_MASK) {
2631 case GP_STATUS_10M:
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00002632 new_line_speed = SPEED_10;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002633 if (vars->duplex == DUPLEX_FULL)
2634 vars->link_status |= LINK_10TFD;
2635 else
2636 vars->link_status |= LINK_10THD;
2637 break;
2638
2639 case GP_STATUS_100M:
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00002640 new_line_speed = SPEED_100;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002641 if (vars->duplex == DUPLEX_FULL)
2642 vars->link_status |= LINK_100TXFD;
2643 else
2644 vars->link_status |= LINK_100TXHD;
2645 break;
2646
2647 case GP_STATUS_1G:
2648 case GP_STATUS_1G_KX:
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00002649 new_line_speed = SPEED_1000;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002650 if (vars->duplex == DUPLEX_FULL)
2651 vars->link_status |= LINK_1000TFD;
2652 else
2653 vars->link_status |= LINK_1000THD;
2654 break;
2655
2656 case GP_STATUS_2_5G:
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00002657 new_line_speed = SPEED_2500;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002658 if (vars->duplex == DUPLEX_FULL)
2659 vars->link_status |= LINK_2500TFD;
2660 else
2661 vars->link_status |= LINK_2500THD;
2662 break;
2663
2664 case GP_STATUS_5G:
2665 case GP_STATUS_6G:
2666 DP(NETIF_MSG_LINK,
2667 "link speed unsupported gp_status 0x%x\n",
2668 gp_status);
2669 return -EINVAL;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00002670
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002671 case GP_STATUS_10G_KX4:
2672 case GP_STATUS_10G_HIG:
2673 case GP_STATUS_10G_CX4:
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00002674 new_line_speed = SPEED_10000;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002675 vars->link_status |= LINK_10GTFD;
2676 break;
2677
2678 case GP_STATUS_12G_HIG:
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00002679 new_line_speed = SPEED_12000;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002680 vars->link_status |= LINK_12GTFD;
2681 break;
2682
2683 case GP_STATUS_12_5G:
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00002684 new_line_speed = SPEED_12500;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002685 vars->link_status |= LINK_12_5GTFD;
2686 break;
2687
2688 case GP_STATUS_13G:
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00002689 new_line_speed = SPEED_13000;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002690 vars->link_status |= LINK_13GTFD;
2691 break;
2692
2693 case GP_STATUS_15G:
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00002694 new_line_speed = SPEED_15000;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002695 vars->link_status |= LINK_15GTFD;
2696 break;
2697
2698 case GP_STATUS_16G:
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00002699 new_line_speed = SPEED_16000;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002700 vars->link_status |= LINK_16GTFD;
2701 break;
2702
2703 default:
2704 DP(NETIF_MSG_LINK,
2705 "link speed unsupported gp_status 0x%x\n",
2706 gp_status);
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00002707 return -EINVAL;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002708 }
2709
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00002710 vars->line_speed = new_line_speed;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002711
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002712 } else { /* link_down */
2713 DP(NETIF_MSG_LINK, "phy link down\n");
2714
2715 vars->phy_link_up = 0;
Yaniv Rosner57963ed2008-08-13 15:55:28 -07002716
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002717 vars->duplex = DUPLEX_FULL;
David S. Millerc0700f92008-12-16 23:53:20 -08002718 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002719 vars->mac_type = MAC_TYPE_NONE;
Eilon Greenstein239d6862009-08-12 08:23:04 +00002720
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00002721 if ((phy->req_line_speed == SPEED_AUTO_NEG) &&
2722 SINGLE_MEDIA_DIRECT(params)) {
Eilon Greenstein239d6862009-08-12 08:23:04 +00002723 /* Check signal is detected */
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00002724 bnx2x_check_fallback_to_cl37(phy, params);
Eilon Greenstein239d6862009-08-12 08:23:04 +00002725 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002726 }
2727
Frans Pop2381a552010-03-24 07:57:36 +00002728 DP(NETIF_MSG_LINK, "gp_status 0x%x phy_link_up %x line_speed %x\n",
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002729 gp_status, vars->phy_link_up, vars->line_speed);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002730 DP(NETIF_MSG_LINK, "duplex %x flow_ctrl 0x%x link_status 0x%x\n",
2731 vars->duplex, vars->flow_ctrl, vars->link_status);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002732 return rc;
2733}
2734
Eilon Greensteined8680a2009-02-12 08:37:12 +00002735static void bnx2x_set_gmii_tx_driver(struct link_params *params)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002736{
2737 struct bnx2x *bp = params->bp;
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002738 struct bnx2x_phy *phy = &params->phy[INT_PHY];
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002739 u16 lp_up2;
2740 u16 tx_driver;
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00002741 u16 bank;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002742
2743 /* read precomp */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002744 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002745 MDIO_REG_BANK_OVER_1G,
2746 MDIO_OVER_1G_LP_UP2, &lp_up2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002747
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002748 /* bits [10:7] at lp_up2, positioned at [15:12] */
2749 lp_up2 = (((lp_up2 & MDIO_OVER_1G_LP_UP2_PREEMPHASIS_MASK) >>
2750 MDIO_OVER_1G_LP_UP2_PREEMPHASIS_SHIFT) <<
2751 MDIO_TX0_TX_DRIVER_PREEMPHASIS_SHIFT);
2752
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00002753 if (lp_up2 == 0)
2754 return;
2755
2756 for (bank = MDIO_REG_BANK_TX0; bank <= MDIO_REG_BANK_TX3;
2757 bank += (MDIO_REG_BANK_TX1 - MDIO_REG_BANK_TX0)) {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002758 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002759 bank,
2760 MDIO_TX0_TX_DRIVER, &tx_driver);
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00002761
2762 /* replace tx_driver bits [15:12] */
2763 if (lp_up2 !=
2764 (tx_driver & MDIO_TX0_TX_DRIVER_PREEMPHASIS_MASK)) {
2765 tx_driver &= ~MDIO_TX0_TX_DRIVER_PREEMPHASIS_MASK;
2766 tx_driver |= lp_up2;
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002767 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002768 bank,
2769 MDIO_TX0_TX_DRIVER, tx_driver);
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00002770 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002771 }
2772}
2773
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00002774static int bnx2x_emac_program(struct link_params *params,
2775 struct link_vars *vars)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002776{
2777 struct bnx2x *bp = params->bp;
2778 u8 port = params->port;
2779 u16 mode = 0;
2780
2781 DP(NETIF_MSG_LINK, "setting link speed & duplex\n");
2782 bnx2x_bits_dis(bp, GRCBASE_EMAC0 + port*0x400 +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002783 EMAC_REG_EMAC_MODE,
2784 (EMAC_MODE_25G_MODE |
2785 EMAC_MODE_PORT_MII_10M |
2786 EMAC_MODE_HALF_DUPLEX));
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00002787 switch (vars->line_speed) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002788 case SPEED_10:
2789 mode |= EMAC_MODE_PORT_MII_10M;
2790 break;
2791
2792 case SPEED_100:
2793 mode |= EMAC_MODE_PORT_MII;
2794 break;
2795
2796 case SPEED_1000:
2797 mode |= EMAC_MODE_PORT_GMII;
2798 break;
2799
2800 case SPEED_2500:
2801 mode |= (EMAC_MODE_25G_MODE | EMAC_MODE_PORT_GMII);
2802 break;
2803
2804 default:
2805 /* 10G not valid for EMAC */
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00002806 DP(NETIF_MSG_LINK, "Invalid line_speed 0x%x\n",
2807 vars->line_speed);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002808 return -EINVAL;
2809 }
2810
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00002811 if (vars->duplex == DUPLEX_HALF)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002812 mode |= EMAC_MODE_HALF_DUPLEX;
2813 bnx2x_bits_en(bp,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002814 GRCBASE_EMAC0 + port*0x400 + EMAC_REG_EMAC_MODE,
2815 mode);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002816
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00002817 bnx2x_set_led(params, vars, LED_MODE_OPER, vars->line_speed);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002818 return 0;
2819}
2820
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00002821static void bnx2x_set_preemphasis(struct bnx2x_phy *phy,
2822 struct link_params *params)
2823{
2824
2825 u16 bank, i = 0;
2826 struct bnx2x *bp = params->bp;
2827
2828 for (bank = MDIO_REG_BANK_RX0, i = 0; bank <= MDIO_REG_BANK_RX3;
2829 bank += (MDIO_REG_BANK_RX1-MDIO_REG_BANK_RX0), i++) {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002830 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00002831 bank,
2832 MDIO_RX0_RX_EQ_BOOST,
2833 phy->rx_preemphasis[i]);
2834 }
2835
2836 for (bank = MDIO_REG_BANK_TX0, i = 0; bank <= MDIO_REG_BANK_TX3;
2837 bank += (MDIO_REG_BANK_TX1 - MDIO_REG_BANK_TX0), i++) {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002838 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00002839 bank,
2840 MDIO_TX0_TX_DRIVER,
2841 phy->tx_preemphasis[i]);
2842 }
2843}
2844
Yaniv Rosnerec146a62011-05-31 21:29:27 +00002845static void bnx2x_xgxs_config_init(struct bnx2x_phy *phy,
2846 struct link_params *params,
2847 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00002848{
2849 struct bnx2x *bp = params->bp;
2850 u8 enable_cl73 = (SINGLE_MEDIA_DIRECT(params) ||
2851 (params->loopback_mode == LOOPBACK_XGXS));
2852 if (!(vars->phy_flags & PHY_SGMII_FLAG)) {
2853 if (SINGLE_MEDIA_DIRECT(params) &&
2854 (params->feature_config_flags &
2855 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED))
2856 bnx2x_set_preemphasis(phy, params);
2857
2858 /* forced speed requested? */
2859 if (vars->line_speed != SPEED_AUTO_NEG ||
2860 (SINGLE_MEDIA_DIRECT(params) &&
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002861 params->loopback_mode == LOOPBACK_EXT)) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00002862 DP(NETIF_MSG_LINK, "not SGMII, no AN\n");
2863
2864 /* disable autoneg */
2865 bnx2x_set_autoneg(phy, params, vars, 0);
2866
2867 /* program speed and duplex */
2868 bnx2x_program_serdes(phy, params, vars);
2869
2870 } else { /* AN_mode */
2871 DP(NETIF_MSG_LINK, "not SGMII, AN\n");
2872
2873 /* AN enabled */
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00002874 bnx2x_set_brcm_cl37_advertisement(phy, params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00002875
2876 /* program duplex & pause advertisement (for aneg) */
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00002877 bnx2x_set_ieee_aneg_advertisement(phy, params,
2878 vars->ieee_fc);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00002879
2880 /* enable autoneg */
2881 bnx2x_set_autoneg(phy, params, vars, enable_cl73);
2882
2883 /* enable and restart AN */
2884 bnx2x_restart_autoneg(phy, params, enable_cl73);
2885 }
2886
2887 } else { /* SGMII mode */
2888 DP(NETIF_MSG_LINK, "SGMII\n");
2889
2890 bnx2x_initialize_sgmii_process(phy, params, vars);
2891 }
2892}
2893
Yaniv Rosnerec146a62011-05-31 21:29:27 +00002894static int bnx2x_prepare_xgxs(struct bnx2x_phy *phy,
2895 struct link_params *params,
2896 struct link_vars *vars)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00002897{
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00002898 int rc;
Yaniv Rosnerec146a62011-05-31 21:29:27 +00002899 vars->phy_flags |= PHY_XGXS_FLAG;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00002900 if ((phy->req_line_speed &&
2901 ((phy->req_line_speed == SPEED_100) ||
2902 (phy->req_line_speed == SPEED_10))) ||
2903 (!phy->req_line_speed &&
2904 (phy->speed_cap_mask >=
2905 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL) &&
2906 (phy->speed_cap_mask <
Yaniv Rosnerec146a62011-05-31 21:29:27 +00002907 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) ||
2908 (phy->type == PORT_HW_CFG_SERDES_EXT_PHY_TYPE_DIRECT_SD))
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00002909 vars->phy_flags |= PHY_SGMII_FLAG;
2910 else
2911 vars->phy_flags &= ~PHY_SGMII_FLAG;
2912
2913 bnx2x_calc_ieee_aneg_adv(phy, params, &vars->ieee_fc);
Yaniv Rosnerec146a62011-05-31 21:29:27 +00002914 bnx2x_set_aer_mmd(params, phy);
2915 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
2916 bnx2x_set_master_ln(params, phy);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00002917
2918 rc = bnx2x_reset_unicore(params, phy, 0);
2919 /* reset the SerDes and wait for reset bit return low */
2920 if (rc != 0)
2921 return rc;
2922
Yaniv Rosnerec146a62011-05-31 21:29:27 +00002923 bnx2x_set_aer_mmd(params, phy);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00002924 /* setting the masterLn_def again after the reset */
Yaniv Rosnerec146a62011-05-31 21:29:27 +00002925 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT) {
2926 bnx2x_set_master_ln(params, phy);
2927 bnx2x_set_swap_lanes(params, phy);
2928 }
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00002929
2930 return rc;
2931}
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00002932
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00002933static u16 bnx2x_wait_reset_complete(struct bnx2x *bp,
Yaniv Rosner6d870c32011-01-31 04:22:20 +00002934 struct bnx2x_phy *phy,
2935 struct link_params *params)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002936{
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00002937 u16 cnt, ctrl;
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002938 /* Wait for soft reset to get cleared up to 1 sec */
Yaniv Rosner62b29a52010-09-07 11:40:58 +00002939 for (cnt = 0; cnt < 1000; cnt++) {
2940 bnx2x_cl45_read(bp, phy,
2941 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, &ctrl);
2942 if (!(ctrl & (1<<15)))
2943 break;
2944 msleep(1);
2945 }
Yaniv Rosner6d870c32011-01-31 04:22:20 +00002946
2947 if (cnt == 1000)
2948 netdev_err(bp->dev, "Warning: PHY was not initialized,"
2949 " Port %d\n",
2950 params->port);
Yaniv Rosner62b29a52010-09-07 11:40:58 +00002951 DP(NETIF_MSG_LINK, "control reg 0x%x (after %d ms)\n", ctrl, cnt);
2952 return cnt;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00002953}
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002954
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002955static void bnx2x_link_int_enable(struct link_params *params)
2956{
2957 u8 port = params->port;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002958 u32 mask;
2959 struct bnx2x *bp = params->bp;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00002960
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002961 /* Setting the status to report on link up for either XGXS or SerDes */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002962 if (params->switch_cfg == SWITCH_CFG_10G) {
2963 mask = (NIG_MASK_XGXS0_LINK10G |
2964 NIG_MASK_XGXS0_LINK_STATUS);
2965 DP(NETIF_MSG_LINK, "enabled XGXS interrupt\n");
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002966 if (!(SINGLE_MEDIA_DIRECT(params)) &&
2967 params->phy[INT_PHY].type !=
2968 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002969 mask |= NIG_MASK_MI_INT;
2970 DP(NETIF_MSG_LINK, "enabled external phy int\n");
2971 }
2972
2973 } else { /* SerDes */
2974 mask = NIG_MASK_SERDES0_LINK_STATUS;
2975 DP(NETIF_MSG_LINK, "enabled SerDes interrupt\n");
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002976 if (!(SINGLE_MEDIA_DIRECT(params)) &&
2977 params->phy[INT_PHY].type !=
2978 PORT_HW_CFG_SERDES_EXT_PHY_TYPE_NOT_CONN) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002979 mask |= NIG_MASK_MI_INT;
2980 DP(NETIF_MSG_LINK, "enabled external phy int\n");
2981 }
2982 }
2983 bnx2x_bits_en(bp,
2984 NIG_REG_MASK_INTERRUPT_PORT0 + port*4,
2985 mask);
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00002986
2987 DP(NETIF_MSG_LINK, "port %x, is_xgxs %x, int_status 0x%x\n", port,
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002988 (params->switch_cfg == SWITCH_CFG_10G),
2989 REG_RD(bp, NIG_REG_STATUS_INTERRUPT_PORT0 + port*4));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002990 DP(NETIF_MSG_LINK, " int_mask 0x%x, MI_INT %x, SERDES_LINK %x\n",
2991 REG_RD(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4),
2992 REG_RD(bp, NIG_REG_EMAC0_STATUS_MISC_MI_INT + port*0x18),
2993 REG_RD(bp, NIG_REG_SERDES0_STATUS_LINK_STATUS+port*0x3c));
2994 DP(NETIF_MSG_LINK, " 10G %x, XGXS_LINK %x\n",
2995 REG_RD(bp, NIG_REG_XGXS0_STATUS_LINK10G + port*0x68),
2996 REG_RD(bp, NIG_REG_XGXS0_STATUS_LINK_STATUS + port*0x68));
2997}
2998
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002999static void bnx2x_rearm_latch_signal(struct bnx2x *bp, u8 port,
3000 u8 exp_mi_int)
Eilon Greenstein2f904462009-08-12 08:22:16 +00003001{
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003002 u32 latch_status = 0;
3003
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003004 /*
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003005 * Disable the MI INT ( external phy int ) by writing 1 to the
3006 * status register. Link down indication is high-active-signal,
3007 * so in this case we need to write the status to clear the XOR
Eilon Greenstein2f904462009-08-12 08:22:16 +00003008 */
3009 /* Read Latched signals */
3010 latch_status = REG_RD(bp,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003011 NIG_REG_LATCH_STATUS_0 + port*8);
3012 DP(NETIF_MSG_LINK, "latch_status = 0x%x\n", latch_status);
Eilon Greenstein2f904462009-08-12 08:22:16 +00003013 /* Handle only those with latched-signal=up.*/
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003014 if (exp_mi_int)
3015 bnx2x_bits_en(bp,
3016 NIG_REG_STATUS_INTERRUPT_PORT0
3017 + port*4,
3018 NIG_STATUS_EMAC0_MI_INT);
3019 else
3020 bnx2x_bits_dis(bp,
3021 NIG_REG_STATUS_INTERRUPT_PORT0
3022 + port*4,
3023 NIG_STATUS_EMAC0_MI_INT);
3024
Eilon Greenstein2f904462009-08-12 08:22:16 +00003025 if (latch_status & 1) {
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003026
Eilon Greenstein2f904462009-08-12 08:22:16 +00003027 /* For all latched-signal=up : Re-Arm Latch signals */
3028 REG_WR(bp, NIG_REG_LATCH_STATUS_0 + port*8,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003029 (latch_status & 0xfffe) | (latch_status & 1));
Eilon Greenstein2f904462009-08-12 08:22:16 +00003030 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003031 /* For all latched-signal=up,Write original_signal to status */
Eilon Greenstein2f904462009-08-12 08:22:16 +00003032}
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003033
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003034static void bnx2x_link_int_ack(struct link_params *params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003035 struct link_vars *vars, u8 is_10g)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003036{
3037 struct bnx2x *bp = params->bp;
3038 u8 port = params->port;
3039
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003040 /*
3041 * First reset all status we assume only one line will be
3042 * change at a time
3043 */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003044 bnx2x_bits_dis(bp, NIG_REG_STATUS_INTERRUPT_PORT0 + port*4,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003045 (NIG_STATUS_XGXS0_LINK10G |
3046 NIG_STATUS_XGXS0_LINK_STATUS |
3047 NIG_STATUS_SERDES0_LINK_STATUS));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003048 if (vars->phy_link_up) {
3049 if (is_10g) {
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003050 /*
3051 * Disable the 10G link interrupt by writing 1 to the
3052 * status register
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003053 */
3054 DP(NETIF_MSG_LINK, "10G XGXS phy link up\n");
3055 bnx2x_bits_en(bp,
3056 NIG_REG_STATUS_INTERRUPT_PORT0 + port*4,
3057 NIG_STATUS_XGXS0_LINK10G);
3058
3059 } else if (params->switch_cfg == SWITCH_CFG_10G) {
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003060 /*
3061 * Disable the link interrupt by writing 1 to the
3062 * relevant lane in the status register
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003063 */
3064 u32 ser_lane = ((params->lane_config &
3065 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_MASK) >>
3066 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_SHIFT);
3067
Eilon Greenstein2f904462009-08-12 08:22:16 +00003068 DP(NETIF_MSG_LINK, "%d speed XGXS phy link up\n",
3069 vars->line_speed);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003070 bnx2x_bits_en(bp,
3071 NIG_REG_STATUS_INTERRUPT_PORT0 + port*4,
3072 ((1 << ser_lane) <<
3073 NIG_STATUS_XGXS0_LINK_STATUS_SIZE));
3074
3075 } else { /* SerDes */
3076 DP(NETIF_MSG_LINK, "SerDes phy link up\n");
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003077 /*
3078 * Disable the link interrupt by writing 1 to the status
3079 * register
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003080 */
3081 bnx2x_bits_en(bp,
3082 NIG_REG_STATUS_INTERRUPT_PORT0 + port*4,
3083 NIG_STATUS_SERDES0_LINK_STATUS);
3084 }
3085
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003086 }
3087}
3088
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00003089static int bnx2x_format_ver(u32 num, u8 *str, u16 *len)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003090{
3091 u8 *str_ptr = str;
3092 u32 mask = 0xf0000000;
3093 u8 shift = 8*4;
3094 u8 digit;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003095 u8 remove_leading_zeros = 1;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003096 if (*len < 10) {
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02003097 /* Need more than 10chars for this format */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003098 *str_ptr = '\0';
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003099 (*len)--;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003100 return -EINVAL;
3101 }
3102 while (shift > 0) {
3103
3104 shift -= 4;
3105 digit = ((num & mask) >> shift);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003106 if (digit == 0 && remove_leading_zeros) {
3107 mask = mask >> 4;
3108 continue;
3109 } else if (digit < 0xa)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003110 *str_ptr = digit + '0';
3111 else
3112 *str_ptr = digit - 0xa + 'a';
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003113 remove_leading_zeros = 0;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003114 str_ptr++;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003115 (*len)--;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003116 mask = mask >> 4;
3117 if (shift == 4*4) {
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003118 *str_ptr = '.';
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003119 str_ptr++;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003120 (*len)--;
3121 remove_leading_zeros = 1;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003122 }
3123 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003124 return 0;
3125}
3126
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003127
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00003128static int bnx2x_null_format_ver(u32 spirom_ver, u8 *str, u16 *len)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003129{
3130 str[0] = '\0';
3131 (*len)--;
3132 return 0;
3133}
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003134
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00003135int bnx2x_get_ext_phy_fw_version(struct link_params *params, u8 driver_loaded,
3136 u8 *version, u16 len)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003137{
Julia Lawall0376d5b2009-07-19 05:26:35 +00003138 struct bnx2x *bp;
Eilon Greensteina35da8d2009-02-12 08:37:02 +00003139 u32 spirom_ver = 0;
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00003140 int status = 0;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003141 u8 *ver_p = version;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003142 u16 remain_len = len;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003143 if (version == NULL || params == NULL)
3144 return -EINVAL;
Julia Lawall0376d5b2009-07-19 05:26:35 +00003145 bp = params->bp;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003146
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003147 /* Extract first external phy*/
3148 version[0] = '\0';
3149 spirom_ver = REG_RD(bp, params->phy[EXT_PHY1].ver_addr);
Eilon Greensteina35da8d2009-02-12 08:37:02 +00003150
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003151 if (params->phy[EXT_PHY1].format_fw_ver) {
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003152 status |= params->phy[EXT_PHY1].format_fw_ver(spirom_ver,
3153 ver_p,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003154 &remain_len);
3155 ver_p += (len - remain_len);
3156 }
3157 if ((params->num_phys == MAX_PHYS) &&
3158 (params->phy[EXT_PHY2].ver_addr != 0)) {
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003159 spirom_ver = REG_RD(bp, params->phy[EXT_PHY2].ver_addr);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003160 if (params->phy[EXT_PHY2].format_fw_ver) {
3161 *ver_p = '/';
3162 ver_p++;
3163 remain_len--;
3164 status |= params->phy[EXT_PHY2].format_fw_ver(
3165 spirom_ver,
3166 ver_p,
3167 &remain_len);
3168 ver_p = version + (len - remain_len);
3169 }
3170 }
3171 *ver_p = '\0';
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003172 return status;
3173}
3174
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003175static void bnx2x_set_xgxs_loopback(struct bnx2x_phy *phy,
Yaniv Rosner62b29a52010-09-07 11:40:58 +00003176 struct link_params *params)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003177{
3178 u8 port = params->port;
3179 struct bnx2x *bp = params->bp;
3180
Yaniv Rosner62b29a52010-09-07 11:40:58 +00003181 if (phy->req_line_speed != SPEED_1000) {
Eilon Greenstein6378c022008-08-13 15:59:25 -07003182 u32 md_devad;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003183
3184 DP(NETIF_MSG_LINK, "XGXS 10G loopback enable\n");
3185
3186 /* change the uni_phy_addr in the nig */
3187 md_devad = REG_RD(bp, (NIG_REG_XGXS0_CTRL_MD_DEVAD +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003188 port*0x18));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003189
3190 REG_WR(bp, NIG_REG_XGXS0_CTRL_MD_DEVAD + port*0x18, 0x5);
3191
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003192 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003193 5,
3194 (MDIO_REG_BANK_AER_BLOCK +
3195 (MDIO_AER_BLOCK_AER_REG & 0xf)),
3196 0x2800);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003197
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003198 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003199 5,
3200 (MDIO_REG_BANK_CL73_IEEEB0 +
3201 (MDIO_CL73_IEEEB0_CL73_AN_CONTROL & 0xf)),
3202 0x6041);
Eilon Greenstein38582762009-01-14 06:44:16 +00003203 msleep(200);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003204 /* set aer mmd back */
Yaniv Rosnerec146a62011-05-31 21:29:27 +00003205 bnx2x_set_aer_mmd(params, phy);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003206
3207 /* and md_devad */
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003208 REG_WR(bp, NIG_REG_XGXS0_CTRL_MD_DEVAD + port*0x18, md_devad);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003209 } else {
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003210 u16 mii_ctrl;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003211 DP(NETIF_MSG_LINK, "XGXS 1G loopback enable\n");
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003212 bnx2x_cl45_read(bp, phy, 5,
3213 (MDIO_REG_BANK_COMBO_IEEE0 +
3214 (MDIO_COMBO_IEEE0_MII_CONTROL & 0xf)),
3215 &mii_ctrl);
3216 bnx2x_cl45_write(bp, phy, 5,
3217 (MDIO_REG_BANK_COMBO_IEEE0 +
3218 (MDIO_COMBO_IEEE0_MII_CONTROL & 0xf)),
3219 mii_ctrl |
3220 MDIO_COMBO_IEEO_MII_CONTROL_LOOPBACK);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003221 }
3222}
3223
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00003224int bnx2x_set_led(struct link_params *params,
3225 struct link_vars *vars, u8 mode, u32 speed)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003226{
Yaniv Rosner7846e472009-11-05 19:18:07 +02003227 u8 port = params->port;
3228 u16 hw_led_mode = params->hw_led_mode;
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00003229 int rc = 0;
3230 u8 phy_idx;
Eilon Greenstein345b5d52008-08-13 15:58:12 -07003231 u32 tmp;
3232 u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
Yaniv Rosner7846e472009-11-05 19:18:07 +02003233 struct bnx2x *bp = params->bp;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003234 DP(NETIF_MSG_LINK, "bnx2x_set_led: port %x, mode %d\n", port, mode);
3235 DP(NETIF_MSG_LINK, "speed 0x%x, hw_led_mode 0x%x\n",
3236 speed, hw_led_mode);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00003237 /* In case */
3238 for (phy_idx = EXT_PHY1; phy_idx < MAX_PHYS; phy_idx++) {
3239 if (params->phy[phy_idx].set_link_led) {
3240 params->phy[phy_idx].set_link_led(
3241 &params->phy[phy_idx], params, mode);
3242 }
3243 }
3244
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003245 switch (mode) {
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00003246 case LED_MODE_FRONT_PANEL_OFF:
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003247 case LED_MODE_OFF:
3248 REG_WR(bp, NIG_REG_LED_10G_P0 + port*4, 0);
3249 REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003250 SHARED_HW_CFG_LED_MAC1);
Eilon Greenstein345b5d52008-08-13 15:58:12 -07003251
3252 tmp = EMAC_RD(bp, EMAC_REG_EMAC_LED);
Eilon Greenstein3196a882008-08-13 15:58:49 -07003253 EMAC_WR(bp, EMAC_REG_EMAC_LED, (tmp | EMAC_LED_OVERRIDE));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003254 break;
3255
3256 case LED_MODE_OPER:
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003257 /*
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00003258 * For all other phys, OPER mode is same as ON, so in case
3259 * link is down, do nothing
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003260 */
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00003261 if (!vars->link_up)
3262 break;
3263 case LED_MODE_ON:
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00003264 if (((params->phy[EXT_PHY1].type ==
3265 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727) ||
3266 (params->phy[EXT_PHY1].type ==
3267 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8722)) &&
Yaniv Rosner1f483532011-01-18 04:33:31 +00003268 CHIP_IS_E2(bp) && params->num_phys == 2) {
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003269 /*
3270 * This is a work-around for E2+8727 Configurations
3271 */
Yaniv Rosner1f483532011-01-18 04:33:31 +00003272 if (mode == LED_MODE_ON ||
3273 speed == SPEED_10000){
3274 REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4, 0);
3275 REG_WR(bp, NIG_REG_LED_10G_P0 + port*4, 1);
3276
3277 tmp = EMAC_RD(bp, EMAC_REG_EMAC_LED);
3278 EMAC_WR(bp, EMAC_REG_EMAC_LED,
3279 (tmp | EMAC_LED_OVERRIDE));
3280 return rc;
3281 }
3282 } else if (SINGLE_MEDIA_DIRECT(params)) {
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003283 /*
3284 * This is a work-around for HW issue found when link
3285 * is up in CL73
3286 */
Yaniv Rosner7846e472009-11-05 19:18:07 +02003287 REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4, 0);
3288 REG_WR(bp, NIG_REG_LED_10G_P0 + port*4, 1);
3289 } else {
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003290 REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4, hw_led_mode);
Yaniv Rosner7846e472009-11-05 19:18:07 +02003291 }
3292
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003293 REG_WR(bp, NIG_REG_LED_CONTROL_OVERRIDE_TRAFFIC_P0 + port*4, 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003294 /* Set blinking rate to ~15.9Hz */
3295 REG_WR(bp, NIG_REG_LED_CONTROL_BLINK_RATE_P0 + port*4,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003296 LED_BLINK_RATE_VAL);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003297 REG_WR(bp, NIG_REG_LED_CONTROL_BLINK_RATE_ENA_P0 +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003298 port*4, 1);
Eilon Greenstein345b5d52008-08-13 15:58:12 -07003299 tmp = EMAC_RD(bp, EMAC_REG_EMAC_LED);
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003300 EMAC_WR(bp, EMAC_REG_EMAC_LED, (tmp & (~EMAC_LED_OVERRIDE)));
Eilon Greenstein345b5d52008-08-13 15:58:12 -07003301
Yaniv Rosner7846e472009-11-05 19:18:07 +02003302 if (CHIP_IS_E1(bp) &&
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003303 ((speed == SPEED_2500) ||
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003304 (speed == SPEED_1000) ||
3305 (speed == SPEED_100) ||
3306 (speed == SPEED_10))) {
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003307 /*
3308 * On Everest 1 Ax chip versions for speeds less than
3309 * 10G LED scheme is different
3310 */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003311 REG_WR(bp, NIG_REG_LED_CONTROL_OVERRIDE_TRAFFIC_P0
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003312 + port*4, 1);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003313 REG_WR(bp, NIG_REG_LED_CONTROL_TRAFFIC_P0 +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003314 port*4, 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003315 REG_WR(bp, NIG_REG_LED_CONTROL_BLINK_TRAFFIC_P0 +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003316 port*4, 1);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003317 }
3318 break;
3319
3320 default:
3321 rc = -EINVAL;
3322 DP(NETIF_MSG_LINK, "bnx2x_set_led: Invalid led mode %d\n",
3323 mode);
3324 break;
3325 }
3326 return rc;
3327
3328}
3329
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003330/*
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003331 * This function comes to reflect the actual link state read DIRECTLY from the
3332 * HW
3333 */
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00003334int bnx2x_test_link(struct link_params *params, struct link_vars *vars,
3335 u8 is_serdes)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003336{
3337 struct bnx2x *bp = params->bp;
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00003338 u16 gp_status = 0, phy_index = 0;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003339 u8 ext_phy_link_up = 0, serdes_phy_type;
3340 struct link_vars temp_vars;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003341
Yaniv Rosnercd2be892011-01-31 04:21:45 +00003342 CL22_RD_OVER_CL45(bp, &params->phy[INT_PHY],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003343 MDIO_REG_BANK_GP_STATUS,
3344 MDIO_GP_STATUS_TOP_AN_STATUS1,
3345 &gp_status);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003346 /* link is up only if both local phy and external phy are up */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003347 if (!(gp_status & MDIO_GP_STATUS_TOP_AN_STATUS1_LINK_STATUS))
3348 return -ESRCH;
3349
3350 switch (params->num_phys) {
3351 case 1:
3352 /* No external PHY */
3353 return 0;
3354 case 2:
3355 ext_phy_link_up = params->phy[EXT_PHY1].read_status(
3356 &params->phy[EXT_PHY1],
3357 params, &temp_vars);
3358 break;
3359 case 3: /* Dual Media */
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00003360 for (phy_index = EXT_PHY1; phy_index < params->num_phys;
3361 phy_index++) {
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003362 serdes_phy_type = ((params->phy[phy_index].media_type ==
3363 ETH_PHY_SFP_FIBER) ||
3364 (params->phy[phy_index].media_type ==
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00003365 ETH_PHY_XFP_FIBER) ||
3366 (params->phy[phy_index].media_type ==
3367 ETH_PHY_DA_TWINAX));
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003368
3369 if (is_serdes != serdes_phy_type)
3370 continue;
3371 if (params->phy[phy_index].read_status) {
3372 ext_phy_link_up |=
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00003373 params->phy[phy_index].read_status(
3374 &params->phy[phy_index],
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003375 params, &temp_vars);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003376 }
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00003377 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003378 break;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003379 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003380 if (ext_phy_link_up)
3381 return 0;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003382 return -ESRCH;
3383}
3384
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00003385static int bnx2x_link_initialize(struct link_params *params,
3386 struct link_vars *vars)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003387{
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00003388 int rc = 0;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003389 u8 phy_index, non_ext_phy;
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00003390 struct bnx2x *bp = params->bp;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003391 /*
3392 * In case of external phy existence, the line speed would be the
3393 * line speed linked up by the external phy. In case it is direct
3394 * only, then the line_speed during initialization will be
3395 * equal to the req_line_speed
3396 */
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00003397 vars->line_speed = params->phy[INT_PHY].req_line_speed;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003398
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003399 /*
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00003400 * Initialize the internal phy in case this is a direct board
3401 * (no external phys), or this board has external phy which requires
3402 * to first.
3403 */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003404
Yaniv Rosnerec146a62011-05-31 21:29:27 +00003405 bnx2x_prepare_xgxs(&params->phy[INT_PHY], params, vars);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003406 /* init ext phy and enable link state int */
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00003407 non_ext_phy = (SINGLE_MEDIA_DIRECT(params) ||
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003408 (params->loopback_mode == LOOPBACK_XGXS));
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003409
3410 if (non_ext_phy ||
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00003411 (params->phy[EXT_PHY1].flags & FLAGS_INIT_XGXS_FIRST) ||
Eilon Greenstein8660d8c2009-03-02 08:01:02 +00003412 (params->loopback_mode == LOOPBACK_EXT_PHY)) {
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00003413 struct bnx2x_phy *phy = &params->phy[INT_PHY];
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003414 if (vars->line_speed == SPEED_AUTO_NEG)
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00003415 bnx2x_set_parallel_detection(phy, params);
Yaniv Rosnerec146a62011-05-31 21:29:27 +00003416 if (params->phy[INT_PHY].config_init)
3417 params->phy[INT_PHY].config_init(phy,
3418 params,
3419 vars);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003420 }
3421
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00003422 /* Init external phy*/
Yaniv Rosnerfd36a2e2011-05-31 21:29:05 +00003423 if (non_ext_phy) {
3424 if (params->phy[INT_PHY].supported &
3425 SUPPORTED_FIBRE)
3426 vars->link_status |= LINK_STATUS_SERDES_LINK;
3427 } else {
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003428 for (phy_index = EXT_PHY1; phy_index < params->num_phys;
3429 phy_index++) {
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003430 /*
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003431 * No need to initialize second phy in case of first
3432 * phy only selection. In case of second phy, we do
3433 * need to initialize the first phy, since they are
3434 * connected.
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003435 */
Yaniv Rosnerfd36a2e2011-05-31 21:29:05 +00003436 if (params->phy[phy_index].supported &
3437 SUPPORTED_FIBRE)
3438 vars->link_status |= LINK_STATUS_SERDES_LINK;
3439
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003440 if (phy_index == EXT_PHY2 &&
3441 (bnx2x_phy_selection(params) ==
3442 PORT_HW_CFG_PHY_SELECTION_FIRST_PHY)) {
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00003443 DP(NETIF_MSG_LINK, "Not initializing"
3444 " second phy\n");
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003445 continue;
3446 }
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003447 params->phy[phy_index].config_init(
3448 &params->phy[phy_index],
3449 params, vars);
3450 }
Yaniv Rosnerfd36a2e2011-05-31 21:29:05 +00003451 }
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +00003452 /* Reset the interrupt indication after phy was initialized */
3453 bnx2x_bits_dis(bp, NIG_REG_STATUS_INTERRUPT_PORT0 +
3454 params->port*4,
3455 (NIG_STATUS_XGXS0_LINK10G |
3456 NIG_STATUS_XGXS0_LINK_STATUS |
3457 NIG_STATUS_SERDES0_LINK_STATUS |
3458 NIG_MASK_MI_INT));
Yaniv Rosnerfd36a2e2011-05-31 21:29:05 +00003459 bnx2x_update_mng(params, vars->link_status);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003460 return rc;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003461}
3462
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003463static void bnx2x_int_link_reset(struct bnx2x_phy *phy,
3464 struct link_params *params)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003465{
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003466 /* reset the SerDes/XGXS */
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003467 REG_WR(params->bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_CLEAR,
3468 (0x1ff << (params->port*16)));
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003469}
3470
3471static void bnx2x_common_ext_link_reset(struct bnx2x_phy *phy,
3472 struct link_params *params)
3473{
3474 struct bnx2x *bp = params->bp;
3475 u8 gpio_port;
3476 /* HW reset */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00003477 if (CHIP_IS_E2(bp))
3478 gpio_port = BP_PATH(bp);
3479 else
3480 gpio_port = params->port;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003481 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003482 MISC_REGISTERS_GPIO_OUTPUT_LOW,
3483 gpio_port);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003484 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003485 MISC_REGISTERS_GPIO_OUTPUT_LOW,
3486 gpio_port);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003487 DP(NETIF_MSG_LINK, "reset external PHY\n");
3488}
3489
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00003490static int bnx2x_update_link_down(struct link_params *params,
3491 struct link_vars *vars)
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003492{
3493 struct bnx2x *bp = params->bp;
3494 u8 port = params->port;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00003495
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003496 DP(NETIF_MSG_LINK, "Port %x: Link is down\n", port);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00003497 bnx2x_set_led(params, vars, LED_MODE_OFF, 0);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003498
3499 /* indicate no mac active */
3500 vars->mac_type = MAC_TYPE_NONE;
3501
3502 /* update shared memory */
Yaniv Rosnerfd36a2e2011-05-31 21:29:05 +00003503 vars->link_status &= ~(LINK_STATUS_SPEED_AND_DUPLEX_MASK |
3504 LINK_STATUS_LINK_UP |
3505 LINK_STATUS_AUTO_NEGOTIATE_COMPLETE |
3506 LINK_STATUS_RX_FLOW_CONTROL_FLAG_MASK |
3507 LINK_STATUS_TX_FLOW_CONTROL_FLAG_MASK |
3508 LINK_STATUS_PARALLEL_DETECTION_FLAG_MASK);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003509 vars->line_speed = 0;
3510 bnx2x_update_mng(params, vars->link_status);
3511
3512 /* activate nig drain */
3513 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + port*4, 1);
3514
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00003515 /* disable emac */
3516 REG_WR(bp, NIG_REG_NIG_EMAC0_EN + port*4, 0);
3517
3518 msleep(10);
3519
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003520 /* reset BigMac */
3521 bnx2x_bmac_rx_disable(bp, params->port);
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003522 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
3523 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port));
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003524 return 0;
3525}
3526
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00003527static int bnx2x_update_link_up(struct link_params *params,
3528 struct link_vars *vars,
3529 u8 link_10g)
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003530{
3531 struct bnx2x *bp = params->bp;
3532 u8 port = params->port;
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00003533 int rc = 0;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00003534
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003535 vars->link_status |= LINK_STATUS_LINK_UP;
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00003536
Yaniv Rosner7aa07112010-09-07 11:41:01 +00003537 if (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX)
3538 vars->link_status |=
3539 LINK_STATUS_TX_FLOW_CONTROL_ENABLED;
3540
3541 if (vars->flow_ctrl & BNX2X_FLOW_CTRL_RX)
3542 vars->link_status |=
3543 LINK_STATUS_RX_FLOW_CONTROL_ENABLED;
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00003544
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003545 if (link_10g) {
3546 bnx2x_bmac_enable(params, vars, 0);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00003547 bnx2x_set_led(params, vars,
3548 LED_MODE_OPER, SPEED_10000);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003549 } else {
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003550 rc = bnx2x_emac_program(params, vars);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003551
Yaniv Rosner0c786f02009-11-05 19:18:32 +02003552 bnx2x_emac_enable(params, vars, 0);
3553
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003554 /* AN complete? */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003555 if ((vars->link_status & LINK_STATUS_AUTO_NEGOTIATE_COMPLETE)
3556 && (!(vars->phy_flags & PHY_SGMII_FLAG)) &&
3557 SINGLE_MEDIA_DIRECT(params))
3558 bnx2x_set_gmii_tx_driver(params);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003559 }
3560
3561 /* PBF - link up */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00003562 if (!(CHIP_IS_E2(bp)))
3563 rc |= bnx2x_pbf_update(params, vars->flow_ctrl,
3564 vars->line_speed);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003565
3566 /* disable drain */
3567 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + port*4, 0);
3568
3569 /* update shared memory */
3570 bnx2x_update_mng(params, vars->link_status);
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00003571 msleep(20);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003572 return rc;
3573}
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003574/*
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003575 * The bnx2x_link_update function should be called upon link
3576 * interrupt.
3577 * Link is considered up as follows:
3578 * - DIRECT_SINGLE_MEDIA - Only XGXS link (internal link) needs
3579 * to be up
3580 * - SINGLE_MEDIA - The link between the 577xx and the external
3581 * phy (XGXS) need to up as well as the external link of the
3582 * phy (PHY_EXT1)
3583 * - DUAL_MEDIA - The link between the 577xx and the first
3584 * external phy needs to be up, and at least one of the 2
3585 * external phy link must be up.
Yaniv Rosner62b29a52010-09-07 11:40:58 +00003586 */
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00003587int bnx2x_link_update(struct link_params *params, struct link_vars *vars)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003588{
3589 struct bnx2x *bp = params->bp;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003590 struct link_vars phy_vars[MAX_PHYS];
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003591 u8 port = params->port;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003592 u8 link_10g, phy_index;
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00003593 u8 ext_phy_link_up = 0, cur_link_up;
3594 int rc = 0;
Eilon Greenstein2f904462009-08-12 08:22:16 +00003595 u8 is_mi_int = 0;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003596 u16 ext_phy_line_speed = 0, prev_line_speed = vars->line_speed;
3597 u8 active_external_phy = INT_PHY;
Yaniv Rosnerfd36a2e2011-05-31 21:29:05 +00003598
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003599 for (phy_index = INT_PHY; phy_index < params->num_phys;
3600 phy_index++) {
3601 phy_vars[phy_index].flow_ctrl = 0;
3602 phy_vars[phy_index].link_status = 0;
3603 phy_vars[phy_index].line_speed = 0;
3604 phy_vars[phy_index].duplex = DUPLEX_FULL;
3605 phy_vars[phy_index].phy_link_up = 0;
3606 phy_vars[phy_index].link_up = 0;
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00003607 phy_vars[phy_index].fault_detected = 0;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003608 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003609
3610 DP(NETIF_MSG_LINK, "port %x, XGXS?%x, int_status 0x%x\n",
Eilon Greenstein2f904462009-08-12 08:22:16 +00003611 port, (vars->phy_flags & PHY_XGXS_FLAG),
3612 REG_RD(bp, NIG_REG_STATUS_INTERRUPT_PORT0 + port*4));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003613
Eilon Greenstein2f904462009-08-12 08:22:16 +00003614 is_mi_int = (u8)(REG_RD(bp, NIG_REG_EMAC0_STATUS_MISC_MI_INT +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003615 port*0x18) > 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003616 DP(NETIF_MSG_LINK, "int_mask 0x%x MI_INT %x, SERDES_LINK %x\n",
Eilon Greenstein2f904462009-08-12 08:22:16 +00003617 REG_RD(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4),
3618 is_mi_int,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003619 REG_RD(bp, NIG_REG_SERDES0_STATUS_LINK_STATUS + port*0x3c));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003620
3621 DP(NETIF_MSG_LINK, " 10G %x, XGXS_LINK %x\n",
3622 REG_RD(bp, NIG_REG_XGXS0_STATUS_LINK10G + port*0x68),
3623 REG_RD(bp, NIG_REG_XGXS0_STATUS_LINK_STATUS + port*0x68));
3624
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00003625 /* disable emac */
3626 REG_WR(bp, NIG_REG_NIG_EMAC0_EN + port*4, 0);
3627
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003628 /*
3629 * Step 1:
3630 * Check external link change only for external phys, and apply
3631 * priority selection between them in case the link on both phys
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00003632 * is up. Note that instead of the common vars, a temporary
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003633 * vars argument is used since each phy may have different link/
3634 * speed/duplex result
3635 */
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003636 for (phy_index = EXT_PHY1; phy_index < params->num_phys;
3637 phy_index++) {
3638 struct bnx2x_phy *phy = &params->phy[phy_index];
3639 if (!phy->read_status)
3640 continue;
3641 /* Read link status and params of this ext phy */
3642 cur_link_up = phy->read_status(phy, params,
3643 &phy_vars[phy_index]);
3644 if (cur_link_up) {
3645 DP(NETIF_MSG_LINK, "phy in index %d link is up\n",
3646 phy_index);
3647 } else {
3648 DP(NETIF_MSG_LINK, "phy in index %d link is down\n",
3649 phy_index);
3650 continue;
3651 }
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003652
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003653 if (!ext_phy_link_up) {
3654 ext_phy_link_up = 1;
3655 active_external_phy = phy_index;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003656 } else {
3657 switch (bnx2x_phy_selection(params)) {
3658 case PORT_HW_CFG_PHY_SELECTION_HARDWARE_DEFAULT:
3659 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY_PRIORITY:
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003660 /*
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003661 * In this option, the first PHY makes sure to pass the
3662 * traffic through itself only.
3663 * Its not clear how to reset the link on the second phy
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003664 */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003665 active_external_phy = EXT_PHY1;
3666 break;
3667 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY_PRIORITY:
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003668 /*
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003669 * In this option, the first PHY makes sure to pass the
3670 * traffic through the second PHY.
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003671 */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003672 active_external_phy = EXT_PHY2;
3673 break;
3674 default:
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003675 /*
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003676 * Link indication on both PHYs with the following cases
3677 * is invalid:
3678 * - FIRST_PHY means that second phy wasn't initialized,
3679 * hence its link is expected to be down
3680 * - SECOND_PHY means that first phy should not be able
3681 * to link up by itself (using configuration)
3682 * - DEFAULT should be overriden during initialiazation
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003683 */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003684 DP(NETIF_MSG_LINK, "Invalid link indication"
3685 "mpc=0x%x. DISABLING LINK !!!\n",
3686 params->multi_phy_config);
3687 ext_phy_link_up = 0;
3688 break;
3689 }
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003690 }
3691 }
3692 prev_line_speed = vars->line_speed;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003693 /*
3694 * Step 2:
3695 * Read the status of the internal phy. In case of
3696 * DIRECT_SINGLE_MEDIA board, this link is the external link,
3697 * otherwise this is the link between the 577xx and the first
3698 * external phy
3699 */
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003700 if (params->phy[INT_PHY].read_status)
3701 params->phy[INT_PHY].read_status(
3702 &params->phy[INT_PHY],
3703 params, vars);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003704 /*
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003705 * The INT_PHY flow control reside in the vars. This include the
3706 * case where the speed or flow control are not set to AUTO.
3707 * Otherwise, the active external phy flow control result is set
3708 * to the vars. The ext_phy_line_speed is needed to check if the
3709 * speed is different between the internal phy and external phy.
3710 * This case may be result of intermediate link speed change.
3711 */
3712 if (active_external_phy > INT_PHY) {
3713 vars->flow_ctrl = phy_vars[active_external_phy].flow_ctrl;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003714 /*
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003715 * Link speed is taken from the XGXS. AN and FC result from
3716 * the external phy.
3717 */
3718 vars->link_status |= phy_vars[active_external_phy].link_status;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003719
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003720 /*
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003721 * if active_external_phy is first PHY and link is up - disable
3722 * disable TX on second external PHY
3723 */
3724 if (active_external_phy == EXT_PHY1) {
3725 if (params->phy[EXT_PHY2].phy_specific_func) {
3726 DP(NETIF_MSG_LINK, "Disabling TX on"
3727 " EXT_PHY2\n");
3728 params->phy[EXT_PHY2].phy_specific_func(
3729 &params->phy[EXT_PHY2],
3730 params, DISABLE_TX);
3731 }
3732 }
3733
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003734 ext_phy_line_speed = phy_vars[active_external_phy].line_speed;
3735 vars->duplex = phy_vars[active_external_phy].duplex;
3736 if (params->phy[active_external_phy].supported &
3737 SUPPORTED_FIBRE)
3738 vars->link_status |= LINK_STATUS_SERDES_LINK;
Yaniv Rosnerfd36a2e2011-05-31 21:29:05 +00003739 else
3740 vars->link_status &= ~LINK_STATUS_SERDES_LINK;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003741 DP(NETIF_MSG_LINK, "Active external phy selected: %x\n",
3742 active_external_phy);
3743 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003744
3745 for (phy_index = EXT_PHY1; phy_index < params->num_phys;
3746 phy_index++) {
3747 if (params->phy[phy_index].flags &
3748 FLAGS_REARM_LATCH_SIGNAL) {
3749 bnx2x_rearm_latch_signal(bp, port,
3750 phy_index ==
3751 active_external_phy);
3752 break;
3753 }
3754 }
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003755 DP(NETIF_MSG_LINK, "vars->flow_ctrl = 0x%x, vars->link_status = 0x%x,"
3756 " ext_phy_line_speed = %d\n", vars->flow_ctrl,
3757 vars->link_status, ext_phy_line_speed);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003758 /*
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003759 * Upon link speed change set the NIG into drain mode. Comes to
3760 * deals with possible FIFO glitch due to clk change when speed
3761 * is decreased without link down indicator
3762 */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003763
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003764 if (vars->phy_link_up) {
3765 if (!(SINGLE_MEDIA_DIRECT(params)) && ext_phy_link_up &&
3766 (ext_phy_line_speed != vars->line_speed)) {
3767 DP(NETIF_MSG_LINK, "Internal link speed %d is"
3768 " different than the external"
3769 " link speed %d\n", vars->line_speed,
3770 ext_phy_line_speed);
3771 vars->phy_link_up = 0;
3772 } else if (prev_line_speed != vars->line_speed) {
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003773 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4,
3774 0);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003775 msleep(1);
3776 }
3777 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003778
3779 /* anything 10 and over uses the bmac */
3780 link_10g = ((vars->line_speed == SPEED_10000) ||
3781 (vars->line_speed == SPEED_12000) ||
3782 (vars->line_speed == SPEED_12500) ||
3783 (vars->line_speed == SPEED_13000) ||
3784 (vars->line_speed == SPEED_15000) ||
3785 (vars->line_speed == SPEED_16000));
3786
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003787 bnx2x_link_int_ack(params, vars, link_10g);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003788
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003789 /*
3790 * In case external phy link is up, and internal link is down
3791 * (not initialized yet probably after link initialization, it
3792 * needs to be initialized.
3793 * Note that after link down-up as result of cable plug, the xgxs
3794 * link would probably become up again without the need
3795 * initialize it
3796 */
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003797 if (!(SINGLE_MEDIA_DIRECT(params))) {
3798 DP(NETIF_MSG_LINK, "ext_phy_link_up = %d, int_link_up = %d,"
3799 " init_preceding = %d\n", ext_phy_link_up,
3800 vars->phy_link_up,
3801 params->phy[EXT_PHY1].flags &
3802 FLAGS_INIT_XGXS_FIRST);
3803 if (!(params->phy[EXT_PHY1].flags &
3804 FLAGS_INIT_XGXS_FIRST)
3805 && ext_phy_link_up && !vars->phy_link_up) {
3806 vars->line_speed = ext_phy_line_speed;
3807 if (vars->line_speed < SPEED_1000)
3808 vars->phy_flags |= PHY_SGMII_FLAG;
3809 else
3810 vars->phy_flags &= ~PHY_SGMII_FLAG;
Yaniv Rosnerec146a62011-05-31 21:29:27 +00003811
3812 if (params->phy[INT_PHY].config_init)
3813 params->phy[INT_PHY].config_init(
3814 &params->phy[INT_PHY], params,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003815 vars);
3816 }
3817 }
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003818 /*
3819 * Link is up only if both local phy and external phy (in case of
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00003820 * non-direct board) are up and no fault detected on active PHY.
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003821 */
3822 vars->link_up = (vars->phy_link_up &&
3823 (ext_phy_link_up ||
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00003824 SINGLE_MEDIA_DIRECT(params)) &&
3825 (phy_vars[active_external_phy].fault_detected == 0));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003826
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003827 if (vars->link_up)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003828 rc = bnx2x_update_link_up(params, vars, link_10g);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003829 else
3830 rc = bnx2x_update_link_down(params, vars);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003831
3832 return rc;
3833}
3834
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003835
3836/*****************************************************************************/
3837/* External Phy section */
3838/*****************************************************************************/
3839void bnx2x_ext_phy_hw_reset(struct bnx2x *bp, u8 port)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003840{
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003841 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003842 MISC_REGISTERS_GPIO_OUTPUT_LOW, port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003843 msleep(1);
3844 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003845 MISC_REGISTERS_GPIO_OUTPUT_HIGH, port);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003846}
3847
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003848static void bnx2x_save_spirom_version(struct bnx2x *bp, u8 port,
3849 u32 spirom_ver, u32 ver_addr)
3850{
3851 DP(NETIF_MSG_LINK, "FW version 0x%x:0x%x for port %d\n",
3852 (u16)(spirom_ver>>16), (u16)spirom_ver, port);
3853
3854 if (ver_addr)
3855 REG_WR(bp, ver_addr, spirom_ver);
3856}
3857
3858static void bnx2x_save_bcm_spirom_ver(struct bnx2x *bp,
3859 struct bnx2x_phy *phy,
3860 u8 port)
3861{
3862 u16 fw_ver1, fw_ver2;
3863
3864 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003865 MDIO_PMA_REG_ROM_VER1, &fw_ver1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003866 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003867 MDIO_PMA_REG_ROM_VER2, &fw_ver2);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003868 bnx2x_save_spirom_version(bp, port, (u32)(fw_ver1<<16 | fw_ver2),
3869 phy->ver_addr);
3870}
3871
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003872static void bnx2x_ext_phy_10G_an_resolve(struct bnx2x *bp,
3873 struct bnx2x_phy *phy,
3874 struct link_vars *vars)
3875{
3876 u16 val;
3877 bnx2x_cl45_read(bp, phy,
3878 MDIO_AN_DEVAD,
3879 MDIO_AN_REG_STATUS, &val);
3880 bnx2x_cl45_read(bp, phy,
3881 MDIO_AN_DEVAD,
3882 MDIO_AN_REG_STATUS, &val);
3883 if (val & (1<<5))
3884 vars->link_status |= LINK_STATUS_AUTO_NEGOTIATE_COMPLETE;
3885 if ((val & (1<<0)) == 0)
3886 vars->link_status |= LINK_STATUS_PARALLEL_DETECTION_USED;
3887}
3888
3889/******************************************************************/
3890/* common BCM8073/BCM8727 PHY SECTION */
3891/******************************************************************/
3892static void bnx2x_8073_resolve_fc(struct bnx2x_phy *phy,
3893 struct link_params *params,
3894 struct link_vars *vars)
3895{
3896 struct bnx2x *bp = params->bp;
3897 if (phy->req_line_speed == SPEED_10 ||
3898 phy->req_line_speed == SPEED_100) {
3899 vars->flow_ctrl = phy->req_flow_ctrl;
3900 return;
3901 }
3902
3903 if (bnx2x_ext_phy_resolve_fc(phy, params, vars) &&
3904 (vars->flow_ctrl == BNX2X_FLOW_CTRL_NONE)) {
3905 u16 pause_result;
3906 u16 ld_pause; /* local */
3907 u16 lp_pause; /* link partner */
3908 bnx2x_cl45_read(bp, phy,
3909 MDIO_AN_DEVAD,
3910 MDIO_AN_REG_CL37_FC_LD, &ld_pause);
3911
3912 bnx2x_cl45_read(bp, phy,
3913 MDIO_AN_DEVAD,
3914 MDIO_AN_REG_CL37_FC_LP, &lp_pause);
3915 pause_result = (ld_pause &
3916 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) >> 5;
3917 pause_result |= (lp_pause &
3918 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) >> 7;
3919
3920 bnx2x_pause_resolve(vars, pause_result);
3921 DP(NETIF_MSG_LINK, "Ext PHY CL37 pause result 0x%x\n",
3922 pause_result);
3923 }
3924}
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00003925static int bnx2x_8073_8727_external_rom_boot(struct bnx2x *bp,
3926 struct bnx2x_phy *phy,
3927 u8 port)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003928{
Yaniv Rosner5c99274b2011-01-18 04:33:36 +00003929 u32 count = 0;
3930 u16 fw_ver1, fw_msgout;
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00003931 int rc = 0;
Yaniv Rosner5c99274b2011-01-18 04:33:36 +00003932
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003933 /* Boot port from external ROM */
3934 /* EDC grst */
3935 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003936 MDIO_PMA_DEVAD,
3937 MDIO_PMA_REG_GEN_CTRL,
3938 0x0001);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003939
3940 /* ucode reboot and rst */
3941 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003942 MDIO_PMA_DEVAD,
3943 MDIO_PMA_REG_GEN_CTRL,
3944 0x008c);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003945
3946 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003947 MDIO_PMA_DEVAD,
3948 MDIO_PMA_REG_MISC_CTRL1, 0x0001);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003949
3950 /* Reset internal microprocessor */
3951 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003952 MDIO_PMA_DEVAD,
3953 MDIO_PMA_REG_GEN_CTRL,
3954 MDIO_PMA_REG_GEN_CTRL_ROM_MICRO_RESET);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003955
3956 /* Release srst bit */
3957 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003958 MDIO_PMA_DEVAD,
3959 MDIO_PMA_REG_GEN_CTRL,
3960 MDIO_PMA_REG_GEN_CTRL_ROM_RESET_INTERNAL_MP);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003961
Yaniv Rosner5c99274b2011-01-18 04:33:36 +00003962 /* Delay 100ms per the PHY specifications */
3963 msleep(100);
3964
3965 /* 8073 sometimes taking longer to download */
3966 do {
3967 count++;
3968 if (count > 300) {
3969 DP(NETIF_MSG_LINK,
3970 "bnx2x_8073_8727_external_rom_boot port %x:"
3971 "Download failed. fw version = 0x%x\n",
3972 port, fw_ver1);
3973 rc = -EINVAL;
3974 break;
3975 }
3976
3977 bnx2x_cl45_read(bp, phy,
3978 MDIO_PMA_DEVAD,
3979 MDIO_PMA_REG_ROM_VER1, &fw_ver1);
3980 bnx2x_cl45_read(bp, phy,
3981 MDIO_PMA_DEVAD,
3982 MDIO_PMA_REG_M8051_MSGOUT_REG, &fw_msgout);
3983
3984 msleep(1);
3985 } while (fw_ver1 == 0 || fw_ver1 == 0x4321 ||
3986 ((fw_msgout & 0xff) != 0x03 && (phy->type ==
3987 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073)));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003988
3989 /* Clear ser_boot_ctl bit */
3990 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003991 MDIO_PMA_DEVAD,
3992 MDIO_PMA_REG_MISC_CTRL1, 0x0000);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003993 bnx2x_save_bcm_spirom_ver(bp, phy, port);
Yaniv Rosner5c99274b2011-01-18 04:33:36 +00003994
3995 DP(NETIF_MSG_LINK,
3996 "bnx2x_8073_8727_external_rom_boot port %x:"
3997 "Download complete. fw version = 0x%x\n",
3998 port, fw_ver1);
3999
4000 return rc;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004001}
4002
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004003/******************************************************************/
4004/* BCM8073 PHY SECTION */
4005/******************************************************************/
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00004006static int bnx2x_8073_is_snr_needed(struct bnx2x *bp, struct bnx2x_phy *phy)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004007{
4008 /* This is only required for 8073A1, version 102 only */
4009 u16 val;
4010
4011 /* Read 8073 HW revision*/
4012 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004013 MDIO_PMA_DEVAD,
4014 MDIO_PMA_REG_8073_CHIP_REV, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004015
4016 if (val != 1) {
4017 /* No need to workaround in 8073 A1 */
4018 return 0;
4019 }
4020
4021 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004022 MDIO_PMA_DEVAD,
4023 MDIO_PMA_REG_ROM_VER2, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004024
4025 /* SNR should be applied only for version 0x102 */
4026 if (val != 0x102)
4027 return 0;
4028
4029 return 1;
4030}
4031
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00004032static int bnx2x_8073_xaui_wa(struct bnx2x *bp, struct bnx2x_phy *phy)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004033{
4034 u16 val, cnt, cnt1 ;
4035
4036 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004037 MDIO_PMA_DEVAD,
4038 MDIO_PMA_REG_8073_CHIP_REV, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004039
4040 if (val > 0) {
4041 /* No need to workaround in 8073 A1 */
4042 return 0;
4043 }
4044 /* XAUI workaround in 8073 A0: */
4045
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00004046 /*
4047 * After loading the boot ROM and restarting Autoneg, poll
4048 * Dev1, Reg $C820:
4049 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004050
4051 for (cnt = 0; cnt < 1000; cnt++) {
4052 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004053 MDIO_PMA_DEVAD,
4054 MDIO_PMA_REG_8073_SPEED_LINK_STATUS,
4055 &val);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00004056 /*
4057 * If bit [14] = 0 or bit [13] = 0, continue on with
4058 * system initialization (XAUI work-around not required, as
4059 * these bits indicate 2.5G or 1G link up).
4060 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004061 if (!(val & (1<<14)) || !(val & (1<<13))) {
4062 DP(NETIF_MSG_LINK, "XAUI work-around not required\n");
4063 return 0;
4064 } else if (!(val & (1<<15))) {
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00004065 DP(NETIF_MSG_LINK, "bit 15 went off\n");
4066 /*
4067 * If bit 15 is 0, then poll Dev1, Reg $C841 until it's
4068 * MSB (bit15) goes to 1 (indicating that the XAUI
4069 * workaround has completed), then continue on with
4070 * system initialization.
4071 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004072 for (cnt1 = 0; cnt1 < 1000; cnt1++) {
4073 bnx2x_cl45_read(bp, phy,
4074 MDIO_PMA_DEVAD,
4075 MDIO_PMA_REG_8073_XAUI_WA, &val);
4076 if (val & (1<<15)) {
4077 DP(NETIF_MSG_LINK,
4078 "XAUI workaround has completed\n");
4079 return 0;
4080 }
4081 msleep(3);
4082 }
4083 break;
4084 }
4085 msleep(3);
4086 }
4087 DP(NETIF_MSG_LINK, "Warning: XAUI work-around timeout !!!\n");
4088 return -EINVAL;
4089}
4090
4091static void bnx2x_807x_force_10G(struct bnx2x *bp, struct bnx2x_phy *phy)
4092{
4093 /* Force KR or KX */
4094 bnx2x_cl45_write(bp, phy,
4095 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x2040);
4096 bnx2x_cl45_write(bp, phy,
4097 MDIO_PMA_DEVAD, MDIO_PMA_REG_10G_CTRL2, 0x000b);
4098 bnx2x_cl45_write(bp, phy,
4099 MDIO_PMA_DEVAD, MDIO_PMA_REG_BCM_CTRL, 0x0000);
4100 bnx2x_cl45_write(bp, phy,
4101 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x0000);
4102}
4103
4104static void bnx2x_8073_set_pause_cl37(struct link_params *params,
4105 struct bnx2x_phy *phy,
4106 struct link_vars *vars)
4107{
4108 u16 cl37_val;
4109 struct bnx2x *bp = params->bp;
4110 bnx2x_cl45_read(bp, phy,
4111 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LD, &cl37_val);
4112
4113 cl37_val &= ~MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH;
4114 /* Please refer to Table 28B-3 of 802.3ab-1999 spec. */
4115 bnx2x_calc_ieee_aneg_adv(phy, params, &vars->ieee_fc);
4116 if ((vars->ieee_fc &
4117 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_SYMMETRIC) ==
4118 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_SYMMETRIC) {
4119 cl37_val |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_SYMMETRIC;
4120 }
4121 if ((vars->ieee_fc &
4122 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC) ==
4123 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC) {
4124 cl37_val |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC;
4125 }
4126 if ((vars->ieee_fc &
4127 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) ==
4128 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) {
4129 cl37_val |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH;
4130 }
4131 DP(NETIF_MSG_LINK,
4132 "Ext phy AN advertize cl37 0x%x\n", cl37_val);
4133
4134 bnx2x_cl45_write(bp, phy,
4135 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LD, cl37_val);
4136 msleep(500);
4137}
4138
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00004139static int bnx2x_8073_config_init(struct bnx2x_phy *phy,
4140 struct link_params *params,
4141 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004142{
4143 struct bnx2x *bp = params->bp;
4144 u16 val = 0, tmp1;
4145 u8 gpio_port;
4146 DP(NETIF_MSG_LINK, "Init 8073\n");
4147
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004148 if (CHIP_IS_E2(bp))
4149 gpio_port = BP_PATH(bp);
4150 else
4151 gpio_port = params->port;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004152 /* Restore normal power mode*/
4153 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004154 MISC_REGISTERS_GPIO_OUTPUT_HIGH, gpio_port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004155
4156 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004157 MISC_REGISTERS_GPIO_OUTPUT_HIGH, gpio_port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004158
4159 /* enable LASI */
4160 bnx2x_cl45_write(bp, phy,
4161 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_ALARM_CTRL, (1<<2));
4162 bnx2x_cl45_write(bp, phy,
4163 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_CTRL, 0x0004);
4164
4165 bnx2x_8073_set_pause_cl37(params, phy, vars);
4166
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004167 bnx2x_cl45_read(bp, phy,
4168 MDIO_PMA_DEVAD, MDIO_PMA_REG_M8051_MSGOUT_REG, &tmp1);
4169
4170 bnx2x_cl45_read(bp, phy,
4171 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_ALARM, &tmp1);
4172
4173 DP(NETIF_MSG_LINK, "Before rom RX_ALARM(port1): 0x%x\n", tmp1);
4174
Yaniv Rosner74d7a112011-01-18 04:33:18 +00004175 /* Swap polarity if required - Must be done only in non-1G mode */
4176 if (params->lane_config & PORT_HW_CFG_SWAP_PHY_POLARITY_ENABLED) {
4177 /* Configure the 8073 to swap _P and _N of the KR lines */
4178 DP(NETIF_MSG_LINK, "Swapping polarity for the 8073\n");
4179 /* 10G Rx/Tx and 1G Tx signal polarity swap */
4180 bnx2x_cl45_read(bp, phy,
4181 MDIO_PMA_DEVAD,
4182 MDIO_PMA_REG_8073_OPT_DIGITAL_CTRL, &val);
4183 bnx2x_cl45_write(bp, phy,
4184 MDIO_PMA_DEVAD,
4185 MDIO_PMA_REG_8073_OPT_DIGITAL_CTRL,
4186 (val | (3<<9)));
4187 }
4188
4189
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004190 /* Enable CL37 BAM */
Yaniv Rosner121839b2010-11-01 05:32:38 +00004191 if (REG_RD(bp, params->shmem_base +
4192 offsetof(struct shmem_region, dev_info.
4193 port_hw_config[params->port].default_cfg)) &
4194 PORT_HW_CFG_ENABLE_BAM_ON_KR_ENABLED) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004195
Yaniv Rosner121839b2010-11-01 05:32:38 +00004196 bnx2x_cl45_read(bp, phy,
4197 MDIO_AN_DEVAD,
4198 MDIO_AN_REG_8073_BAM, &val);
4199 bnx2x_cl45_write(bp, phy,
4200 MDIO_AN_DEVAD,
4201 MDIO_AN_REG_8073_BAM, val | 1);
4202 DP(NETIF_MSG_LINK, "Enable CL37 BAM on KR\n");
4203 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004204 if (params->loopback_mode == LOOPBACK_EXT) {
4205 bnx2x_807x_force_10G(bp, phy);
4206 DP(NETIF_MSG_LINK, "Forced speed 10G on 807X\n");
4207 return 0;
4208 } else {
4209 bnx2x_cl45_write(bp, phy,
4210 MDIO_PMA_DEVAD, MDIO_PMA_REG_BCM_CTRL, 0x0002);
4211 }
4212 if (phy->req_line_speed != SPEED_AUTO_NEG) {
4213 if (phy->req_line_speed == SPEED_10000) {
4214 val = (1<<7);
4215 } else if (phy->req_line_speed == SPEED_2500) {
4216 val = (1<<5);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00004217 /*
4218 * Note that 2.5G works only when used with 1G
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004219 * advertisement
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00004220 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004221 } else
4222 val = (1<<5);
4223 } else {
4224 val = 0;
4225 if (phy->speed_cap_mask &
4226 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
4227 val |= (1<<7);
4228
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004229 /* Note that 2.5G works only when used with 1G advertisement */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004230 if (phy->speed_cap_mask &
4231 (PORT_HW_CFG_SPEED_CAPABILITY_D0_1G |
4232 PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
4233 val |= (1<<5);
4234 DP(NETIF_MSG_LINK, "807x autoneg val = 0x%x\n", val);
4235 }
4236
4237 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV, val);
4238 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_8073_2_5G, &tmp1);
4239
4240 if (((phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G) &&
4241 (phy->req_line_speed == SPEED_AUTO_NEG)) ||
4242 (phy->req_line_speed == SPEED_2500)) {
4243 u16 phy_ver;
4244 /* Allow 2.5G for A1 and above */
4245 bnx2x_cl45_read(bp, phy,
4246 MDIO_PMA_DEVAD, MDIO_PMA_REG_8073_CHIP_REV,
4247 &phy_ver);
4248 DP(NETIF_MSG_LINK, "Add 2.5G\n");
4249 if (phy_ver > 0)
4250 tmp1 |= 1;
4251 else
4252 tmp1 &= 0xfffe;
4253 } else {
4254 DP(NETIF_MSG_LINK, "Disable 2.5G\n");
4255 tmp1 &= 0xfffe;
4256 }
4257
4258 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_8073_2_5G, tmp1);
4259 /* Add support for CL37 (passive mode) II */
4260
4261 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LD, &tmp1);
4262 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LD,
4263 (tmp1 | ((phy->req_duplex == DUPLEX_FULL) ?
4264 0x20 : 0x40)));
4265
4266 /* Add support for CL37 (passive mode) III */
4267 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CL37_AN, 0x1000);
4268
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00004269 /*
4270 * The SNR will improve about 2db by changing BW and FEE main
4271 * tap. Rest commands are executed after link is up
4272 * Change FFE main cursor to 5 in EDC register
4273 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004274 if (bnx2x_8073_is_snr_needed(bp, phy))
4275 bnx2x_cl45_write(bp, phy,
4276 MDIO_PMA_DEVAD, MDIO_PMA_REG_EDC_FFE_MAIN,
4277 0xFB0C);
4278
4279 /* Enable FEC (Forware Error Correction) Request in the AN */
4280 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV2, &tmp1);
4281 tmp1 |= (1<<15);
4282 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV2, tmp1);
4283
4284 bnx2x_ext_phy_set_pause(params, phy, vars);
4285
4286 /* Restart autoneg */
4287 msleep(500);
4288 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x1200);
4289 DP(NETIF_MSG_LINK, "807x Autoneg Restart: Advertise 1G=%x, 10G=%x\n",
4290 ((val & (1<<5)) > 0), ((val & (1<<7)) > 0));
4291 return 0;
4292}
4293
4294static u8 bnx2x_8073_read_status(struct bnx2x_phy *phy,
4295 struct link_params *params,
4296 struct link_vars *vars)
4297{
4298 struct bnx2x *bp = params->bp;
4299 u8 link_up = 0;
4300 u16 val1, val2;
4301 u16 link_status = 0;
4302 u16 an1000_status = 0;
4303
4304 bnx2x_cl45_read(bp, phy,
4305 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_STATUS, &val1);
4306
4307 DP(NETIF_MSG_LINK, "8703 LASI status 0x%x\n", val1);
4308
4309 /* clear the interrupt LASI status register */
4310 bnx2x_cl45_read(bp, phy,
4311 MDIO_PCS_DEVAD, MDIO_PCS_REG_STATUS, &val2);
4312 bnx2x_cl45_read(bp, phy,
4313 MDIO_PCS_DEVAD, MDIO_PCS_REG_STATUS, &val1);
4314 DP(NETIF_MSG_LINK, "807x PCS status 0x%x->0x%x\n", val2, val1);
4315 /* Clear MSG-OUT */
4316 bnx2x_cl45_read(bp, phy,
4317 MDIO_PMA_DEVAD, MDIO_PMA_REG_M8051_MSGOUT_REG, &val1);
4318
4319 /* Check the LASI */
4320 bnx2x_cl45_read(bp, phy,
4321 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_ALARM, &val2);
4322
4323 DP(NETIF_MSG_LINK, "KR 0x9003 0x%x\n", val2);
4324
4325 /* Check the link status */
4326 bnx2x_cl45_read(bp, phy,
4327 MDIO_PCS_DEVAD, MDIO_PCS_REG_STATUS, &val2);
4328 DP(NETIF_MSG_LINK, "KR PCS status 0x%x\n", val2);
4329
4330 bnx2x_cl45_read(bp, phy,
4331 MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val2);
4332 bnx2x_cl45_read(bp, phy,
4333 MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val1);
4334 link_up = ((val1 & 4) == 4);
4335 DP(NETIF_MSG_LINK, "PMA_REG_STATUS=0x%x\n", val1);
4336
4337 if (link_up &&
4338 ((phy->req_line_speed != SPEED_10000))) {
4339 if (bnx2x_8073_xaui_wa(bp, phy) != 0)
4340 return 0;
4341 }
4342 bnx2x_cl45_read(bp, phy,
4343 MDIO_AN_DEVAD, MDIO_AN_REG_LINK_STATUS, &an1000_status);
4344 bnx2x_cl45_read(bp, phy,
4345 MDIO_AN_DEVAD, MDIO_AN_REG_LINK_STATUS, &an1000_status);
4346
4347 /* Check the link status on 1.1.2 */
4348 bnx2x_cl45_read(bp, phy,
4349 MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val2);
4350 bnx2x_cl45_read(bp, phy,
4351 MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val1);
4352 DP(NETIF_MSG_LINK, "KR PMA status 0x%x->0x%x,"
4353 "an_link_status=0x%x\n", val2, val1, an1000_status);
4354
4355 link_up = (((val1 & 4) == 4) || (an1000_status & (1<<1)));
4356 if (link_up && bnx2x_8073_is_snr_needed(bp, phy)) {
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00004357 /*
4358 * The SNR will improve about 2dbby changing the BW and FEE main
4359 * tap. The 1st write to change FFE main tap is set before
4360 * restart AN. Change PLL Bandwidth in EDC register
4361 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004362 bnx2x_cl45_write(bp, phy,
4363 MDIO_PMA_DEVAD, MDIO_PMA_REG_PLL_BANDWIDTH,
4364 0x26BC);
4365
4366 /* Change CDR Bandwidth in EDC register */
4367 bnx2x_cl45_write(bp, phy,
4368 MDIO_PMA_DEVAD, MDIO_PMA_REG_CDR_BANDWIDTH,
4369 0x0333);
4370 }
4371 bnx2x_cl45_read(bp, phy,
4372 MDIO_PMA_DEVAD, MDIO_PMA_REG_8073_SPEED_LINK_STATUS,
4373 &link_status);
4374
4375 /* Bits 0..2 --> speed detected, bits 13..15--> link is down */
4376 if ((link_status & (1<<2)) && (!(link_status & (1<<15)))) {
4377 link_up = 1;
4378 vars->line_speed = SPEED_10000;
4379 DP(NETIF_MSG_LINK, "port %x: External link up in 10G\n",
4380 params->port);
4381 } else if ((link_status & (1<<1)) && (!(link_status & (1<<14)))) {
4382 link_up = 1;
4383 vars->line_speed = SPEED_2500;
4384 DP(NETIF_MSG_LINK, "port %x: External link up in 2.5G\n",
4385 params->port);
4386 } else if ((link_status & (1<<0)) && (!(link_status & (1<<13)))) {
4387 link_up = 1;
4388 vars->line_speed = SPEED_1000;
4389 DP(NETIF_MSG_LINK, "port %x: External link up in 1G\n",
4390 params->port);
4391 } else {
4392 link_up = 0;
4393 DP(NETIF_MSG_LINK, "port %x: External link is down\n",
4394 params->port);
4395 }
4396
4397 if (link_up) {
Yaniv Rosner74d7a112011-01-18 04:33:18 +00004398 /* Swap polarity if required */
4399 if (params->lane_config &
4400 PORT_HW_CFG_SWAP_PHY_POLARITY_ENABLED) {
4401 /* Configure the 8073 to swap P and N of the KR lines */
4402 bnx2x_cl45_read(bp, phy,
4403 MDIO_XS_DEVAD,
4404 MDIO_XS_REG_8073_RX_CTRL_PCIE, &val1);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00004405 /*
4406 * Set bit 3 to invert Rx in 1G mode and clear this bit
4407 * when it`s in 10G mode.
4408 */
Yaniv Rosner74d7a112011-01-18 04:33:18 +00004409 if (vars->line_speed == SPEED_1000) {
4410 DP(NETIF_MSG_LINK, "Swapping 1G polarity for"
4411 "the 8073\n");
4412 val1 |= (1<<3);
4413 } else
4414 val1 &= ~(1<<3);
4415
4416 bnx2x_cl45_write(bp, phy,
4417 MDIO_XS_DEVAD,
4418 MDIO_XS_REG_8073_RX_CTRL_PCIE,
4419 val1);
4420 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004421 bnx2x_ext_phy_10G_an_resolve(bp, phy, vars);
4422 bnx2x_8073_resolve_fc(phy, params, vars);
Yaniv Rosner791f18c2011-01-18 04:33:42 +00004423 vars->duplex = DUPLEX_FULL;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004424 }
4425 return link_up;
4426}
4427
4428static void bnx2x_8073_link_reset(struct bnx2x_phy *phy,
4429 struct link_params *params)
4430{
4431 struct bnx2x *bp = params->bp;
4432 u8 gpio_port;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004433 if (CHIP_IS_E2(bp))
4434 gpio_port = BP_PATH(bp);
4435 else
4436 gpio_port = params->port;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004437 DP(NETIF_MSG_LINK, "Setting 8073 port %d into low power mode\n",
4438 gpio_port);
4439 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004440 MISC_REGISTERS_GPIO_OUTPUT_LOW,
4441 gpio_port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004442}
4443
4444/******************************************************************/
4445/* BCM8705 PHY SECTION */
4446/******************************************************************/
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00004447static int bnx2x_8705_config_init(struct bnx2x_phy *phy,
4448 struct link_params *params,
4449 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004450{
4451 struct bnx2x *bp = params->bp;
4452 DP(NETIF_MSG_LINK, "init 8705\n");
4453 /* Restore normal power mode*/
4454 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004455 MISC_REGISTERS_GPIO_OUTPUT_HIGH, params->port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004456 /* HW reset */
4457 bnx2x_ext_phy_hw_reset(bp, params->port);
4458 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0xa040);
Yaniv Rosner6d870c32011-01-31 04:22:20 +00004459 bnx2x_wait_reset_complete(bp, phy, params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004460
4461 bnx2x_cl45_write(bp, phy,
4462 MDIO_PMA_DEVAD, MDIO_PMA_REG_MISC_CTRL, 0x8288);
4463 bnx2x_cl45_write(bp, phy,
4464 MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER, 0x7fbf);
4465 bnx2x_cl45_write(bp, phy,
4466 MDIO_PMA_DEVAD, MDIO_PMA_REG_CMU_PLL_BYPASS, 0x0100);
4467 bnx2x_cl45_write(bp, phy,
4468 MDIO_WIS_DEVAD, MDIO_WIS_REG_LASI_CNTL, 0x1);
4469 /* BCM8705 doesn't have microcode, hence the 0 */
4470 bnx2x_save_spirom_version(bp, params->port, params->shmem_base, 0);
4471 return 0;
4472}
4473
4474static u8 bnx2x_8705_read_status(struct bnx2x_phy *phy,
4475 struct link_params *params,
4476 struct link_vars *vars)
4477{
4478 u8 link_up = 0;
4479 u16 val1, rx_sd;
4480 struct bnx2x *bp = params->bp;
4481 DP(NETIF_MSG_LINK, "read status 8705\n");
4482 bnx2x_cl45_read(bp, phy,
4483 MDIO_WIS_DEVAD, MDIO_WIS_REG_LASI_STATUS, &val1);
4484 DP(NETIF_MSG_LINK, "8705 LASI status 0x%x\n", val1);
4485
4486 bnx2x_cl45_read(bp, phy,
4487 MDIO_WIS_DEVAD, MDIO_WIS_REG_LASI_STATUS, &val1);
4488 DP(NETIF_MSG_LINK, "8705 LASI status 0x%x\n", val1);
4489
4490 bnx2x_cl45_read(bp, phy,
4491 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_SD, &rx_sd);
4492
4493 bnx2x_cl45_read(bp, phy,
4494 MDIO_PMA_DEVAD, 0xc809, &val1);
4495 bnx2x_cl45_read(bp, phy,
4496 MDIO_PMA_DEVAD, 0xc809, &val1);
4497
4498 DP(NETIF_MSG_LINK, "8705 1.c809 val=0x%x\n", val1);
4499 link_up = ((rx_sd & 0x1) && (val1 & (1<<9)) && ((val1 & (1<<8)) == 0));
4500 if (link_up) {
4501 vars->line_speed = SPEED_10000;
4502 bnx2x_ext_phy_resolve_fc(phy, params, vars);
4503 }
4504 return link_up;
4505}
4506
4507/******************************************************************/
4508/* SFP+ module Section */
4509/******************************************************************/
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00004510static u8 bnx2x_get_gpio_port(struct link_params *params)
4511{
4512 u8 gpio_port;
4513 u32 swap_val, swap_override;
4514 struct bnx2x *bp = params->bp;
4515 if (CHIP_IS_E2(bp))
4516 gpio_port = BP_PATH(bp);
4517 else
4518 gpio_port = params->port;
4519 swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
4520 swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
4521 return gpio_port ^ (swap_val && swap_override);
4522}
4523static void bnx2x_sfp_set_transmitter(struct link_params *params,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004524 struct bnx2x_phy *phy,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004525 u8 tx_en)
4526{
4527 u16 val;
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00004528 u8 port = params->port;
4529 struct bnx2x *bp = params->bp;
4530 u32 tx_en_mode;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004531
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004532 /* Disable/Enable transmitter ( TX laser of the SFP+ module.)*/
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00004533 tx_en_mode = REG_RD(bp, params->shmem_base +
4534 offsetof(struct shmem_region,
4535 dev_info.port_hw_config[port].sfp_ctrl)) &
4536 PORT_HW_CFG_TX_LASER_MASK;
4537 DP(NETIF_MSG_LINK, "Setting transmitter tx_en=%x for port %x "
4538 "mode = %x\n", tx_en, port, tx_en_mode);
4539 switch (tx_en_mode) {
4540 case PORT_HW_CFG_TX_LASER_MDIO:
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004541
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00004542 bnx2x_cl45_read(bp, phy,
4543 MDIO_PMA_DEVAD,
4544 MDIO_PMA_REG_PHY_IDENTIFIER,
4545 &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004546
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00004547 if (tx_en)
4548 val &= ~(1<<15);
4549 else
4550 val |= (1<<15);
4551
4552 bnx2x_cl45_write(bp, phy,
4553 MDIO_PMA_DEVAD,
4554 MDIO_PMA_REG_PHY_IDENTIFIER,
4555 val);
4556 break;
4557 case PORT_HW_CFG_TX_LASER_GPIO0:
4558 case PORT_HW_CFG_TX_LASER_GPIO1:
4559 case PORT_HW_CFG_TX_LASER_GPIO2:
4560 case PORT_HW_CFG_TX_LASER_GPIO3:
4561 {
4562 u16 gpio_pin;
4563 u8 gpio_port, gpio_mode;
4564 if (tx_en)
4565 gpio_mode = MISC_REGISTERS_GPIO_OUTPUT_HIGH;
4566 else
4567 gpio_mode = MISC_REGISTERS_GPIO_OUTPUT_LOW;
4568
4569 gpio_pin = tx_en_mode - PORT_HW_CFG_TX_LASER_GPIO0;
4570 gpio_port = bnx2x_get_gpio_port(params);
4571 bnx2x_set_gpio(bp, gpio_pin, gpio_mode, gpio_port);
4572 break;
4573 }
4574 default:
4575 DP(NETIF_MSG_LINK, "Invalid TX_LASER_MDIO 0x%x\n", tx_en_mode);
4576 break;
4577 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004578}
4579
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00004580static int bnx2x_8726_read_sfp_module_eeprom(struct bnx2x_phy *phy,
4581 struct link_params *params,
4582 u16 addr, u8 byte_cnt, u8 *o_buf)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004583{
4584 struct bnx2x *bp = params->bp;
4585 u16 val = 0;
4586 u16 i;
4587 if (byte_cnt > 16) {
4588 DP(NETIF_MSG_LINK, "Reading from eeprom is"
4589 " is limited to 0xf\n");
4590 return -EINVAL;
4591 }
4592 /* Set the read command byte count */
4593 bnx2x_cl45_write(bp, phy,
4594 MDIO_PMA_DEVAD, MDIO_PMA_REG_SFP_TWO_WIRE_BYTE_CNT,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004595 (byte_cnt | 0xa000));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004596
4597 /* Set the read command address */
4598 bnx2x_cl45_write(bp, phy,
4599 MDIO_PMA_DEVAD, MDIO_PMA_REG_SFP_TWO_WIRE_MEM_ADDR,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004600 addr);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004601
4602 /* Activate read command */
4603 bnx2x_cl45_write(bp, phy,
4604 MDIO_PMA_DEVAD, MDIO_PMA_REG_SFP_TWO_WIRE_CTRL,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004605 0x2c0f);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004606
4607 /* Wait up to 500us for command complete status */
4608 for (i = 0; i < 100; i++) {
4609 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004610 MDIO_PMA_DEVAD,
4611 MDIO_PMA_REG_SFP_TWO_WIRE_CTRL, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004612 if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) ==
4613 MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_COMPLETE)
4614 break;
4615 udelay(5);
4616 }
4617
4618 if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) !=
4619 MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_COMPLETE) {
4620 DP(NETIF_MSG_LINK,
4621 "Got bad status 0x%x when reading from SFP+ EEPROM\n",
4622 (val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK));
4623 return -EINVAL;
4624 }
4625
4626 /* Read the buffer */
4627 for (i = 0; i < byte_cnt; i++) {
4628 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004629 MDIO_PMA_DEVAD,
4630 MDIO_PMA_REG_8726_TWO_WIRE_DATA_BUF + i, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004631 o_buf[i] = (u8)(val & MDIO_PMA_REG_8726_TWO_WIRE_DATA_MASK);
4632 }
4633
4634 for (i = 0; i < 100; i++) {
4635 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004636 MDIO_PMA_DEVAD,
4637 MDIO_PMA_REG_SFP_TWO_WIRE_CTRL, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004638 if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) ==
4639 MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_IDLE)
Joe Perches6f38ad92010-11-14 17:04:31 +00004640 return 0;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004641 msleep(1);
4642 }
4643 return -EINVAL;
4644}
4645
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00004646static int bnx2x_8727_read_sfp_module_eeprom(struct bnx2x_phy *phy,
4647 struct link_params *params,
4648 u16 addr, u8 byte_cnt, u8 *o_buf)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004649{
4650 struct bnx2x *bp = params->bp;
4651 u16 val, i;
4652
4653 if (byte_cnt > 16) {
4654 DP(NETIF_MSG_LINK, "Reading from eeprom is"
4655 " is limited to 0xf\n");
4656 return -EINVAL;
4657 }
4658
4659 /* Need to read from 1.8000 to clear it */
4660 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004661 MDIO_PMA_DEVAD,
4662 MDIO_PMA_REG_SFP_TWO_WIRE_CTRL,
4663 &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004664
4665 /* Set the read command byte count */
4666 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004667 MDIO_PMA_DEVAD,
4668 MDIO_PMA_REG_SFP_TWO_WIRE_BYTE_CNT,
4669 ((byte_cnt < 2) ? 2 : byte_cnt));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004670
4671 /* Set the read command address */
4672 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004673 MDIO_PMA_DEVAD,
4674 MDIO_PMA_REG_SFP_TWO_WIRE_MEM_ADDR,
4675 addr);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004676 /* Set the destination address */
4677 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004678 MDIO_PMA_DEVAD,
4679 0x8004,
4680 MDIO_PMA_REG_8727_TWO_WIRE_DATA_BUF);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004681
4682 /* Activate read command */
4683 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004684 MDIO_PMA_DEVAD,
4685 MDIO_PMA_REG_SFP_TWO_WIRE_CTRL,
4686 0x8002);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00004687 /*
4688 * Wait appropriate time for two-wire command to finish before
4689 * polling the status register
4690 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004691 msleep(1);
4692
4693 /* Wait up to 500us for command complete status */
4694 for (i = 0; i < 100; i++) {
4695 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004696 MDIO_PMA_DEVAD,
4697 MDIO_PMA_REG_SFP_TWO_WIRE_CTRL, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004698 if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) ==
4699 MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_COMPLETE)
4700 break;
4701 udelay(5);
4702 }
4703
4704 if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) !=
4705 MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_COMPLETE) {
4706 DP(NETIF_MSG_LINK,
4707 "Got bad status 0x%x when reading from SFP+ EEPROM\n",
4708 (val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK));
Yaniv Rosner65a001b2011-01-31 04:22:03 +00004709 return -EFAULT;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004710 }
4711
4712 /* Read the buffer */
4713 for (i = 0; i < byte_cnt; i++) {
4714 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004715 MDIO_PMA_DEVAD,
4716 MDIO_PMA_REG_8727_TWO_WIRE_DATA_BUF + i, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004717 o_buf[i] = (u8)(val & MDIO_PMA_REG_8727_TWO_WIRE_DATA_MASK);
4718 }
4719
4720 for (i = 0; i < 100; i++) {
4721 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004722 MDIO_PMA_DEVAD,
4723 MDIO_PMA_REG_SFP_TWO_WIRE_CTRL, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004724 if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) ==
4725 MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_IDLE)
Joe Perches6f38ad92010-11-14 17:04:31 +00004726 return 0;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004727 msleep(1);
4728 }
4729
4730 return -EINVAL;
4731}
4732
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00004733int bnx2x_read_sfp_module_eeprom(struct bnx2x_phy *phy,
4734 struct link_params *params, u16 addr,
4735 u8 byte_cnt, u8 *o_buf)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004736{
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00004737 int rc = -EINVAL;
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00004738 switch (phy->type) {
4739 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
4740 rc = bnx2x_8726_read_sfp_module_eeprom(phy, params, addr,
4741 byte_cnt, o_buf);
4742 break;
4743 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
4744 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8722:
4745 rc = bnx2x_8727_read_sfp_module_eeprom(phy, params, addr,
4746 byte_cnt, o_buf);
4747 break;
4748 }
4749 return rc;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004750}
4751
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00004752static int bnx2x_get_edc_mode(struct bnx2x_phy *phy,
4753 struct link_params *params,
4754 u16 *edc_mode)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004755{
4756 struct bnx2x *bp = params->bp;
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00004757 u32 sync_offset = 0, phy_idx, media_types;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004758 u8 val, check_limiting_mode = 0;
4759 *edc_mode = EDC_MODE_LIMITING;
4760
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00004761 phy->media_type = ETH_PHY_UNSPECIFIED;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004762 /* First check for copper cable */
4763 if (bnx2x_read_sfp_module_eeprom(phy,
4764 params,
4765 SFP_EEPROM_CON_TYPE_ADDR,
4766 1,
4767 &val) != 0) {
4768 DP(NETIF_MSG_LINK, "Failed to read from SFP+ module EEPROM\n");
4769 return -EINVAL;
4770 }
4771
4772 switch (val) {
4773 case SFP_EEPROM_CON_TYPE_VAL_COPPER:
4774 {
4775 u8 copper_module_type;
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00004776 phy->media_type = ETH_PHY_DA_TWINAX;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00004777 /*
4778 * Check if its active cable (includes SFP+ module)
4779 * of passive cable
4780 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004781 if (bnx2x_read_sfp_module_eeprom(phy,
4782 params,
4783 SFP_EEPROM_FC_TX_TECH_ADDR,
4784 1,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00004785 &copper_module_type) != 0) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004786 DP(NETIF_MSG_LINK,
4787 "Failed to read copper-cable-type"
4788 " from SFP+ EEPROM\n");
4789 return -EINVAL;
4790 }
4791
4792 if (copper_module_type &
4793 SFP_EEPROM_FC_TX_TECH_BITMASK_COPPER_ACTIVE) {
4794 DP(NETIF_MSG_LINK, "Active Copper cable detected\n");
4795 check_limiting_mode = 1;
4796 } else if (copper_module_type &
4797 SFP_EEPROM_FC_TX_TECH_BITMASK_COPPER_PASSIVE) {
4798 DP(NETIF_MSG_LINK, "Passive Copper"
4799 " cable detected\n");
4800 *edc_mode =
4801 EDC_MODE_PASSIVE_DAC;
4802 } else {
4803 DP(NETIF_MSG_LINK, "Unknown copper-cable-"
4804 "type 0x%x !!!\n", copper_module_type);
4805 return -EINVAL;
4806 }
4807 break;
4808 }
4809 case SFP_EEPROM_CON_TYPE_VAL_LC:
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00004810 phy->media_type = ETH_PHY_SFP_FIBER;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004811 DP(NETIF_MSG_LINK, "Optic module detected\n");
4812 check_limiting_mode = 1;
4813 break;
4814 default:
4815 DP(NETIF_MSG_LINK, "Unable to determine module type 0x%x !!!\n",
4816 val);
4817 return -EINVAL;
4818 }
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00004819 sync_offset = params->shmem_base +
4820 offsetof(struct shmem_region,
4821 dev_info.port_hw_config[params->port].media_type);
4822 media_types = REG_RD(bp, sync_offset);
4823 /* Update media type for non-PMF sync */
4824 for (phy_idx = INT_PHY; phy_idx < MAX_PHYS; phy_idx++) {
4825 if (&(params->phy[phy_idx]) == phy) {
4826 media_types &= ~(PORT_HW_CFG_MEDIA_TYPE_PHY0_MASK <<
4827 (PORT_HW_CFG_MEDIA_TYPE_PHY1_SHIFT * phy_idx));
4828 media_types |= ((phy->media_type &
4829 PORT_HW_CFG_MEDIA_TYPE_PHY0_MASK) <<
4830 (PORT_HW_CFG_MEDIA_TYPE_PHY1_SHIFT * phy_idx));
4831 break;
4832 }
4833 }
4834 REG_WR(bp, sync_offset, media_types);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004835 if (check_limiting_mode) {
4836 u8 options[SFP_EEPROM_OPTIONS_SIZE];
4837 if (bnx2x_read_sfp_module_eeprom(phy,
4838 params,
4839 SFP_EEPROM_OPTIONS_ADDR,
4840 SFP_EEPROM_OPTIONS_SIZE,
4841 options) != 0) {
4842 DP(NETIF_MSG_LINK, "Failed to read Option"
4843 " field from module EEPROM\n");
4844 return -EINVAL;
4845 }
4846 if ((options[0] & SFP_EEPROM_OPTIONS_LINEAR_RX_OUT_MASK))
4847 *edc_mode = EDC_MODE_LINEAR;
4848 else
4849 *edc_mode = EDC_MODE_LIMITING;
4850 }
4851 DP(NETIF_MSG_LINK, "EDC mode is set to 0x%x\n", *edc_mode);
4852 return 0;
4853}
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00004854/*
4855 * This function read the relevant field from the module (SFP+), and verify it
4856 * is compliant with this board
4857 */
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00004858static int bnx2x_verify_sfp_module(struct bnx2x_phy *phy,
4859 struct link_params *params)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004860{
4861 struct bnx2x *bp = params->bp;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00004862 u32 val, cmd;
4863 u32 fw_resp, fw_cmd_param;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004864 char vendor_name[SFP_EEPROM_VENDOR_NAME_SIZE+1];
4865 char vendor_pn[SFP_EEPROM_PART_NO_SIZE+1];
Yaniv Rosnera22f0782010-09-07 11:41:20 +00004866 phy->flags &= ~FLAGS_SFP_NOT_APPROVED;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004867 val = REG_RD(bp, params->shmem_base +
4868 offsetof(struct shmem_region, dev_info.
4869 port_feature_config[params->port].config));
4870 if ((val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) ==
4871 PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_NO_ENFORCEMENT) {
4872 DP(NETIF_MSG_LINK, "NOT enforcing module verification\n");
4873 return 0;
4874 }
4875
Yaniv Rosnera22f0782010-09-07 11:41:20 +00004876 if (params->feature_config_flags &
4877 FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY) {
4878 /* Use specific phy request */
4879 cmd = DRV_MSG_CODE_VRFY_SPECIFIC_PHY_OPT_MDL;
4880 } else if (params->feature_config_flags &
4881 FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY) {
4882 /* Use first phy request only in case of non-dual media*/
4883 if (DUAL_MEDIA(params)) {
4884 DP(NETIF_MSG_LINK, "FW does not support OPT MDL "
4885 "verification\n");
4886 return -EINVAL;
4887 }
4888 cmd = DRV_MSG_CODE_VRFY_FIRST_PHY_OPT_MDL;
4889 } else {
4890 /* No support in OPT MDL detection */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004891 DP(NETIF_MSG_LINK, "FW does not support OPT MDL "
Yaniv Rosnera22f0782010-09-07 11:41:20 +00004892 "verification\n");
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004893 return -EINVAL;
4894 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004895
Yaniv Rosnera22f0782010-09-07 11:41:20 +00004896 fw_cmd_param = FW_PARAM_SET(phy->addr, phy->type, phy->mdio_ctrl);
4897 fw_resp = bnx2x_fw_command(bp, cmd, fw_cmd_param);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004898 if (fw_resp == FW_MSG_CODE_VRFY_OPT_MDL_SUCCESS) {
4899 DP(NETIF_MSG_LINK, "Approved module\n");
4900 return 0;
4901 }
4902
4903 /* format the warning message */
4904 if (bnx2x_read_sfp_module_eeprom(phy,
4905 params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004906 SFP_EEPROM_VENDOR_NAME_ADDR,
4907 SFP_EEPROM_VENDOR_NAME_SIZE,
4908 (u8 *)vendor_name))
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004909 vendor_name[0] = '\0';
4910 else
4911 vendor_name[SFP_EEPROM_VENDOR_NAME_SIZE] = '\0';
4912 if (bnx2x_read_sfp_module_eeprom(phy,
4913 params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004914 SFP_EEPROM_PART_NO_ADDR,
4915 SFP_EEPROM_PART_NO_SIZE,
4916 (u8 *)vendor_pn))
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004917 vendor_pn[0] = '\0';
4918 else
4919 vendor_pn[SFP_EEPROM_PART_NO_SIZE] = '\0';
4920
Yaniv Rosner6d870c32011-01-31 04:22:20 +00004921 netdev_err(bp->dev, "Warning: Unqualified SFP+ module detected,"
4922 " Port %d from %s part number %s\n",
4923 params->port, vendor_name, vendor_pn);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00004924 phy->flags |= FLAGS_SFP_NOT_APPROVED;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004925 return -EINVAL;
4926}
4927
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00004928static int bnx2x_wait_for_sfp_module_initialized(struct bnx2x_phy *phy,
4929 struct link_params *params)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004930
4931{
4932 u8 val;
4933 struct bnx2x *bp = params->bp;
4934 u16 timeout;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00004935 /*
4936 * Initialization time after hot-plug may take up to 300ms for
4937 * some phys type ( e.g. JDSU )
4938 */
4939
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004940 for (timeout = 0; timeout < 60; timeout++) {
4941 if (bnx2x_read_sfp_module_eeprom(phy, params, 1, 1, &val)
4942 == 0) {
4943 DP(NETIF_MSG_LINK, "SFP+ module initialization "
4944 "took %d ms\n", timeout * 5);
4945 return 0;
4946 }
4947 msleep(5);
4948 }
4949 return -EINVAL;
4950}
4951
4952static void bnx2x_8727_power_module(struct bnx2x *bp,
4953 struct bnx2x_phy *phy,
4954 u8 is_power_up) {
4955 /* Make sure GPIOs are not using for LED mode */
4956 u16 val;
4957 /*
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00004958 * In the GPIO register, bit 4 is use to determine if the GPIOs are
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004959 * operating as INPUT or as OUTPUT. Bit 1 is for input, and 0 for
4960 * output
4961 * Bits 0-1 determine the gpios value for OUTPUT in case bit 4 val is 0
4962 * Bits 8-9 determine the gpios value for INPUT in case bit 4 val is 1
4963 * where the 1st bit is the over-current(only input), and 2nd bit is
4964 * for power( only output )
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00004965 *
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004966 * In case of NOC feature is disabled and power is up, set GPIO control
4967 * as input to enable listening of over-current indication
4968 */
4969 if (phy->flags & FLAGS_NOC)
4970 return;
Yaniv Rosner27d02432011-05-31 21:27:48 +00004971 if (is_power_up)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004972 val = (1<<4);
4973 else
4974 /*
4975 * Set GPIO control to OUTPUT, and set the power bit
4976 * to according to the is_power_up
4977 */
Yaniv Rosner27d02432011-05-31 21:27:48 +00004978 val = (1<<1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004979
4980 bnx2x_cl45_write(bp, phy,
4981 MDIO_PMA_DEVAD,
4982 MDIO_PMA_REG_8727_GPIO_CTRL,
4983 val);
4984}
4985
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00004986static int bnx2x_8726_set_limiting_mode(struct bnx2x *bp,
4987 struct bnx2x_phy *phy,
4988 u16 edc_mode)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004989{
4990 u16 cur_limiting_mode;
4991
4992 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004993 MDIO_PMA_DEVAD,
4994 MDIO_PMA_REG_ROM_VER2,
4995 &cur_limiting_mode);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004996 DP(NETIF_MSG_LINK, "Current Limiting mode is 0x%x\n",
4997 cur_limiting_mode);
4998
4999 if (edc_mode == EDC_MODE_LIMITING) {
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005000 DP(NETIF_MSG_LINK, "Setting LIMITING MODE\n");
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005001 bnx2x_cl45_write(bp, phy,
5002 MDIO_PMA_DEVAD,
5003 MDIO_PMA_REG_ROM_VER2,
5004 EDC_MODE_LIMITING);
5005 } else { /* LRM mode ( default )*/
5006
5007 DP(NETIF_MSG_LINK, "Setting LRM MODE\n");
5008
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005009 /*
5010 * Changing to LRM mode takes quite few seconds. So do it only
5011 * if current mode is limiting (default is LRM)
5012 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005013 if (cur_limiting_mode != EDC_MODE_LIMITING)
5014 return 0;
5015
5016 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005017 MDIO_PMA_DEVAD,
5018 MDIO_PMA_REG_LRM_MODE,
5019 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005020 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005021 MDIO_PMA_DEVAD,
5022 MDIO_PMA_REG_ROM_VER2,
5023 0x128);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005024 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005025 MDIO_PMA_DEVAD,
5026 MDIO_PMA_REG_MISC_CTRL0,
5027 0x4008);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005028 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005029 MDIO_PMA_DEVAD,
5030 MDIO_PMA_REG_LRM_MODE,
5031 0xaaaa);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005032 }
5033 return 0;
5034}
5035
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00005036static int bnx2x_8727_set_limiting_mode(struct bnx2x *bp,
5037 struct bnx2x_phy *phy,
5038 u16 edc_mode)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005039{
5040 u16 phy_identifier;
5041 u16 rom_ver2_val;
5042 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005043 MDIO_PMA_DEVAD,
5044 MDIO_PMA_REG_PHY_IDENTIFIER,
5045 &phy_identifier);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005046
5047 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005048 MDIO_PMA_DEVAD,
5049 MDIO_PMA_REG_PHY_IDENTIFIER,
5050 (phy_identifier & ~(1<<9)));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005051
5052 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005053 MDIO_PMA_DEVAD,
5054 MDIO_PMA_REG_ROM_VER2,
5055 &rom_ver2_val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005056 /* Keep the MSB 8-bits, and set the LSB 8-bits with the edc_mode */
5057 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005058 MDIO_PMA_DEVAD,
5059 MDIO_PMA_REG_ROM_VER2,
5060 (rom_ver2_val & 0xff00) | (edc_mode & 0x00ff));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005061
5062 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005063 MDIO_PMA_DEVAD,
5064 MDIO_PMA_REG_PHY_IDENTIFIER,
5065 (phy_identifier | (1<<9)));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005066
5067 return 0;
5068}
5069
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005070static void bnx2x_8727_specific_func(struct bnx2x_phy *phy,
5071 struct link_params *params,
5072 u32 action)
5073{
5074 struct bnx2x *bp = params->bp;
5075
5076 switch (action) {
5077 case DISABLE_TX:
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00005078 bnx2x_sfp_set_transmitter(params, phy, 0);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005079 break;
5080 case ENABLE_TX:
5081 if (!(phy->flags & FLAGS_SFP_NOT_APPROVED))
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00005082 bnx2x_sfp_set_transmitter(params, phy, 1);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005083 break;
5084 default:
5085 DP(NETIF_MSG_LINK, "Function 0x%x not supported by 8727\n",
5086 action);
5087 return;
5088 }
5089}
5090
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00005091static void bnx2x_set_sfp_module_fault_led(struct link_params *params,
5092 u8 gpio_mode)
5093{
5094 struct bnx2x *bp = params->bp;
5095
5096 u32 fault_led_gpio = REG_RD(bp, params->shmem_base +
5097 offsetof(struct shmem_region,
5098 dev_info.port_hw_config[params->port].sfp_ctrl)) &
5099 PORT_HW_CFG_FAULT_MODULE_LED_MASK;
5100 switch (fault_led_gpio) {
5101 case PORT_HW_CFG_FAULT_MODULE_LED_DISABLED:
5102 return;
5103 case PORT_HW_CFG_FAULT_MODULE_LED_GPIO0:
5104 case PORT_HW_CFG_FAULT_MODULE_LED_GPIO1:
5105 case PORT_HW_CFG_FAULT_MODULE_LED_GPIO2:
5106 case PORT_HW_CFG_FAULT_MODULE_LED_GPIO3:
5107 {
5108 u8 gpio_port = bnx2x_get_gpio_port(params);
5109 u16 gpio_pin = fault_led_gpio -
5110 PORT_HW_CFG_FAULT_MODULE_LED_GPIO0;
5111 DP(NETIF_MSG_LINK, "Set fault module-detected led "
5112 "pin %x port %x mode %x\n",
5113 gpio_pin, gpio_port, gpio_mode);
5114 bnx2x_set_gpio(bp, gpio_pin, gpio_mode, gpio_port);
5115 }
5116 break;
5117 default:
5118 DP(NETIF_MSG_LINK, "Error: Invalid fault led mode 0x%x\n",
5119 fault_led_gpio);
5120 }
5121}
5122
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00005123static void bnx2x_power_sfp_module(struct link_params *params,
5124 struct bnx2x_phy *phy,
5125 u8 power)
5126{
5127 struct bnx2x *bp = params->bp;
5128 DP(NETIF_MSG_LINK, "Setting SFP+ power to %x\n", power);
5129
5130 switch (phy->type) {
5131 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
5132 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8722:
5133 bnx2x_8727_power_module(params->bp, phy, power);
5134 break;
5135 default:
5136 break;
5137 }
5138}
5139
5140static void bnx2x_set_limiting_mode(struct link_params *params,
5141 struct bnx2x_phy *phy,
5142 u16 edc_mode)
5143{
5144 switch (phy->type) {
5145 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
5146 bnx2x_8726_set_limiting_mode(params->bp, phy, edc_mode);
5147 break;
5148 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
5149 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8722:
5150 bnx2x_8727_set_limiting_mode(params->bp, phy, edc_mode);
5151 break;
5152 }
5153}
5154
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00005155int bnx2x_sfp_module_detection(struct bnx2x_phy *phy,
5156 struct link_params *params)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005157{
5158 struct bnx2x *bp = params->bp;
5159 u16 edc_mode;
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00005160 int rc = 0;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005161
5162 u32 val = REG_RD(bp, params->shmem_base +
5163 offsetof(struct shmem_region, dev_info.
5164 port_feature_config[params->port].config));
5165
5166 DP(NETIF_MSG_LINK, "SFP+ module plugged in/out detected on port %d\n",
5167 params->port);
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00005168 /* Power up module */
5169 bnx2x_power_sfp_module(params, phy, 1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005170 if (bnx2x_get_edc_mode(phy, params, &edc_mode) != 0) {
5171 DP(NETIF_MSG_LINK, "Failed to get valid module type\n");
5172 return -EINVAL;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005173 } else if (bnx2x_verify_sfp_module(phy, params) != 0) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005174 /* check SFP+ module compatibility */
5175 DP(NETIF_MSG_LINK, "Module verification failed!!\n");
5176 rc = -EINVAL;
5177 /* Turn on fault module-detected led */
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00005178 bnx2x_set_sfp_module_fault_led(params,
5179 MISC_REGISTERS_GPIO_HIGH);
5180
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00005181 /* Check if need to power down the SFP+ module */
5182 if ((val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) ==
5183 PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_POWER_DOWN) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005184 DP(NETIF_MSG_LINK, "Shutdown SFP+ module!!\n");
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00005185 bnx2x_power_sfp_module(params, phy, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005186 return rc;
5187 }
5188 } else {
5189 /* Turn off fault module-detected led */
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00005190 bnx2x_set_sfp_module_fault_led(params, MISC_REGISTERS_GPIO_LOW);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005191 }
5192
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005193 /*
5194 * Check and set limiting mode / LRM mode on 8726. On 8727 it
5195 * is done automatically
5196 */
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00005197 bnx2x_set_limiting_mode(params, phy, edc_mode);
5198
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005199 /*
5200 * Enable transmit for this module if the module is approved, or
5201 * if unapproved modules should also enable the Tx laser
5202 */
5203 if (rc == 0 ||
5204 (val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) !=
5205 PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_DISABLE_TX_LASER)
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00005206 bnx2x_sfp_set_transmitter(params, phy, 1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005207 else
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00005208 bnx2x_sfp_set_transmitter(params, phy, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005209
5210 return rc;
5211}
5212
5213void bnx2x_handle_module_detect_int(struct link_params *params)
5214{
5215 struct bnx2x *bp = params->bp;
5216 struct bnx2x_phy *phy = &params->phy[EXT_PHY1];
5217 u32 gpio_val;
5218 u8 port = params->port;
5219
5220 /* Set valid module led off */
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00005221 bnx2x_set_sfp_module_fault_led(params, MISC_REGISTERS_GPIO_HIGH);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005222
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005223 /* Get current gpio val reflecting module plugged in / out*/
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005224 gpio_val = bnx2x_get_gpio(bp, MISC_REGISTERS_GPIO_3, port);
5225
5226 /* Call the handling function in case module is detected */
5227 if (gpio_val == 0) {
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00005228 bnx2x_power_sfp_module(params, phy, 1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005229 bnx2x_set_gpio_int(bp, MISC_REGISTERS_GPIO_3,
5230 MISC_REGISTERS_GPIO_INT_OUTPUT_CLR,
5231 port);
5232
5233 if (bnx2x_wait_for_sfp_module_initialized(phy, params) == 0)
5234 bnx2x_sfp_module_detection(phy, params);
5235 else
5236 DP(NETIF_MSG_LINK, "SFP+ module is not initialized\n");
5237 } else {
5238 u32 val = REG_RD(bp, params->shmem_base +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005239 offsetof(struct shmem_region, dev_info.
5240 port_feature_config[params->port].
5241 config));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005242
5243 bnx2x_set_gpio_int(bp, MISC_REGISTERS_GPIO_3,
5244 MISC_REGISTERS_GPIO_INT_OUTPUT_SET,
5245 port);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005246 /*
5247 * Module was plugged out.
5248 * Disable transmit for this module
5249 */
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00005250 phy->media_type = ETH_PHY_NOT_PRESENT;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005251 if ((val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) ==
5252 PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_DISABLE_TX_LASER)
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00005253 bnx2x_sfp_set_transmitter(params, phy, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005254 }
5255}
5256
5257/******************************************************************/
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00005258/* Used by 8706 and 8727 */
5259/******************************************************************/
5260static void bnx2x_sfp_mask_fault(struct bnx2x *bp,
5261 struct bnx2x_phy *phy,
5262 u16 alarm_status_offset,
5263 u16 alarm_ctrl_offset)
5264{
5265 u16 alarm_status, val;
5266 bnx2x_cl45_read(bp, phy,
5267 MDIO_PMA_DEVAD, alarm_status_offset,
5268 &alarm_status);
5269 bnx2x_cl45_read(bp, phy,
5270 MDIO_PMA_DEVAD, alarm_status_offset,
5271 &alarm_status);
5272 /* Mask or enable the fault event. */
5273 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD, alarm_ctrl_offset, &val);
5274 if (alarm_status & (1<<0))
5275 val &= ~(1<<0);
5276 else
5277 val |= (1<<0);
5278 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, alarm_ctrl_offset, val);
5279}
5280/******************************************************************/
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005281/* common BCM8706/BCM8726 PHY SECTION */
5282/******************************************************************/
5283static u8 bnx2x_8706_8726_read_status(struct bnx2x_phy *phy,
5284 struct link_params *params,
5285 struct link_vars *vars)
5286{
5287 u8 link_up = 0;
5288 u16 val1, val2, rx_sd, pcs_status;
5289 struct bnx2x *bp = params->bp;
5290 DP(NETIF_MSG_LINK, "XGXS 8706/8726\n");
5291 /* Clear RX Alarm*/
5292 bnx2x_cl45_read(bp, phy,
5293 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_ALARM, &val2);
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00005294
5295 bnx2x_sfp_mask_fault(bp, phy, MDIO_PMA_REG_TX_ALARM,
5296 MDIO_PMA_REG_TX_ALARM_CTRL);
5297
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005298 /* clear LASI indication*/
5299 bnx2x_cl45_read(bp, phy,
5300 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_STATUS, &val1);
5301 bnx2x_cl45_read(bp, phy,
5302 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_STATUS, &val2);
5303 DP(NETIF_MSG_LINK, "8706/8726 LASI status 0x%x--> 0x%x\n", val1, val2);
5304
5305 bnx2x_cl45_read(bp, phy,
5306 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_SD, &rx_sd);
5307 bnx2x_cl45_read(bp, phy,
5308 MDIO_PCS_DEVAD, MDIO_PCS_REG_STATUS, &pcs_status);
5309 bnx2x_cl45_read(bp, phy,
5310 MDIO_AN_DEVAD, MDIO_AN_REG_LINK_STATUS, &val2);
5311 bnx2x_cl45_read(bp, phy,
5312 MDIO_AN_DEVAD, MDIO_AN_REG_LINK_STATUS, &val2);
5313
5314 DP(NETIF_MSG_LINK, "8706/8726 rx_sd 0x%x pcs_status 0x%x 1Gbps"
5315 " link_status 0x%x\n", rx_sd, pcs_status, val2);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005316 /*
5317 * link is up if both bit 0 of pmd_rx_sd and bit 0 of pcs_status
5318 * are set, or if the autoneg bit 1 is set
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005319 */
5320 link_up = ((rx_sd & pcs_status & 0x1) || (val2 & (1<<1)));
5321 if (link_up) {
5322 if (val2 & (1<<1))
5323 vars->line_speed = SPEED_1000;
5324 else
5325 vars->line_speed = SPEED_10000;
5326 bnx2x_ext_phy_resolve_fc(phy, params, vars);
Yaniv Rosner791f18c2011-01-18 04:33:42 +00005327 vars->duplex = DUPLEX_FULL;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005328 }
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00005329
5330 /* Capture 10G link fault. Read twice to clear stale value. */
5331 if (vars->line_speed == SPEED_10000) {
5332 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
5333 MDIO_PMA_REG_TX_ALARM, &val1);
5334 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
5335 MDIO_PMA_REG_TX_ALARM, &val1);
5336 if (val1 & (1<<0))
5337 vars->fault_detected = 1;
5338 }
5339
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005340 return link_up;
5341}
5342
5343/******************************************************************/
5344/* BCM8706 PHY SECTION */
5345/******************************************************************/
5346static u8 bnx2x_8706_config_init(struct bnx2x_phy *phy,
5347 struct link_params *params,
5348 struct link_vars *vars)
5349{
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00005350 u32 tx_en_mode;
5351 u16 cnt, val, tmp1;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005352 struct bnx2x *bp = params->bp;
5353 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005354 MISC_REGISTERS_GPIO_OUTPUT_HIGH, params->port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005355 /* HW reset */
5356 bnx2x_ext_phy_hw_reset(bp, params->port);
5357 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0xa040);
Yaniv Rosner6d870c32011-01-31 04:22:20 +00005358 bnx2x_wait_reset_complete(bp, phy, params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005359
5360 /* Wait until fw is loaded */
5361 for (cnt = 0; cnt < 100; cnt++) {
5362 bnx2x_cl45_read(bp, phy,
5363 MDIO_PMA_DEVAD, MDIO_PMA_REG_ROM_VER1, &val);
5364 if (val)
5365 break;
5366 msleep(10);
5367 }
5368 DP(NETIF_MSG_LINK, "XGXS 8706 is initialized after %d ms\n", cnt);
5369 if ((params->feature_config_flags &
5370 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED)) {
5371 u8 i;
5372 u16 reg;
5373 for (i = 0; i < 4; i++) {
5374 reg = MDIO_XS_8706_REG_BANK_RX0 +
5375 i*(MDIO_XS_8706_REG_BANK_RX1 -
5376 MDIO_XS_8706_REG_BANK_RX0);
5377 bnx2x_cl45_read(bp, phy, MDIO_XS_DEVAD, reg, &val);
5378 /* Clear first 3 bits of the control */
5379 val &= ~0x7;
5380 /* Set control bits according to configuration */
5381 val |= (phy->rx_preemphasis[i] & 0x7);
5382 DP(NETIF_MSG_LINK, "Setting RX Equalizer to BCM8706"
5383 " reg 0x%x <-- val 0x%x\n", reg, val);
5384 bnx2x_cl45_write(bp, phy, MDIO_XS_DEVAD, reg, val);
5385 }
5386 }
5387 /* Force speed */
5388 if (phy->req_line_speed == SPEED_10000) {
5389 DP(NETIF_MSG_LINK, "XGXS 8706 force 10Gbps\n");
5390
5391 bnx2x_cl45_write(bp, phy,
5392 MDIO_PMA_DEVAD,
5393 MDIO_PMA_REG_DIGITAL_CTRL, 0x400);
5394 bnx2x_cl45_write(bp, phy,
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00005395 MDIO_PMA_DEVAD, MDIO_PMA_REG_TX_ALARM_CTRL,
5396 0);
5397 /* Arm LASI for link and Tx fault. */
5398 bnx2x_cl45_write(bp, phy,
5399 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_CTRL, 3);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005400 } else {
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005401 /* Force 1Gbps using autoneg with 1G advertisement */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005402
5403 /* Allow CL37 through CL73 */
5404 DP(NETIF_MSG_LINK, "XGXS 8706 AutoNeg\n");
5405 bnx2x_cl45_write(bp, phy,
5406 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_CL73, 0x040c);
5407
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005408 /* Enable Full-Duplex advertisement on CL37 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005409 bnx2x_cl45_write(bp, phy,
5410 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LP, 0x0020);
5411 /* Enable CL37 AN */
5412 bnx2x_cl45_write(bp, phy,
5413 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_AN, 0x1000);
5414 /* 1G support */
5415 bnx2x_cl45_write(bp, phy,
5416 MDIO_AN_DEVAD, MDIO_AN_REG_ADV, (1<<5));
5417
5418 /* Enable clause 73 AN */
5419 bnx2x_cl45_write(bp, phy,
5420 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x1200);
5421 bnx2x_cl45_write(bp, phy,
5422 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_ALARM_CTRL,
5423 0x0400);
5424 bnx2x_cl45_write(bp, phy,
5425 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_CTRL,
5426 0x0004);
5427 }
5428 bnx2x_save_bcm_spirom_ver(bp, phy, params->port);
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00005429
5430 /*
5431 * If TX Laser is controlled by GPIO_0, do not let PHY go into low
5432 * power mode, if TX Laser is disabled
5433 */
5434
5435 tx_en_mode = REG_RD(bp, params->shmem_base +
5436 offsetof(struct shmem_region,
5437 dev_info.port_hw_config[params->port].sfp_ctrl))
5438 & PORT_HW_CFG_TX_LASER_MASK;
5439
5440 if (tx_en_mode == PORT_HW_CFG_TX_LASER_GPIO0) {
5441 DP(NETIF_MSG_LINK, "Enabling TXONOFF_PWRDN_DIS\n");
5442 bnx2x_cl45_read(bp, phy,
5443 MDIO_PMA_DEVAD, MDIO_PMA_REG_DIGITAL_CTRL, &tmp1);
5444 tmp1 |= 0x1;
5445 bnx2x_cl45_write(bp, phy,
5446 MDIO_PMA_DEVAD, MDIO_PMA_REG_DIGITAL_CTRL, tmp1);
5447 }
5448
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005449 return 0;
5450}
5451
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00005452static int bnx2x_8706_read_status(struct bnx2x_phy *phy,
5453 struct link_params *params,
5454 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005455{
5456 return bnx2x_8706_8726_read_status(phy, params, vars);
5457}
5458
5459/******************************************************************/
5460/* BCM8726 PHY SECTION */
5461/******************************************************************/
5462static void bnx2x_8726_config_loopback(struct bnx2x_phy *phy,
5463 struct link_params *params)
5464{
5465 struct bnx2x *bp = params->bp;
5466 DP(NETIF_MSG_LINK, "PMA/PMD ext_phy_loopback: 8726\n");
5467 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x0001);
5468}
5469
5470static void bnx2x_8726_external_rom_boot(struct bnx2x_phy *phy,
5471 struct link_params *params)
5472{
5473 struct bnx2x *bp = params->bp;
5474 /* Need to wait 100ms after reset */
5475 msleep(100);
5476
5477 /* Micro controller re-boot */
5478 bnx2x_cl45_write(bp, phy,
5479 MDIO_PMA_DEVAD, MDIO_PMA_REG_GEN_CTRL, 0x018B);
5480
5481 /* Set soft reset */
5482 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005483 MDIO_PMA_DEVAD,
5484 MDIO_PMA_REG_GEN_CTRL,
5485 MDIO_PMA_REG_GEN_CTRL_ROM_MICRO_RESET);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005486
5487 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005488 MDIO_PMA_DEVAD,
5489 MDIO_PMA_REG_MISC_CTRL1, 0x0001);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005490
5491 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005492 MDIO_PMA_DEVAD,
5493 MDIO_PMA_REG_GEN_CTRL,
5494 MDIO_PMA_REG_GEN_CTRL_ROM_RESET_INTERNAL_MP);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005495
5496 /* wait for 150ms for microcode load */
5497 msleep(150);
5498
5499 /* Disable serial boot control, tristates pins SS_N, SCK, MOSI, MISO */
5500 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005501 MDIO_PMA_DEVAD,
5502 MDIO_PMA_REG_MISC_CTRL1, 0x0000);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005503
5504 msleep(200);
5505 bnx2x_save_bcm_spirom_ver(bp, phy, params->port);
5506}
5507
5508static u8 bnx2x_8726_read_status(struct bnx2x_phy *phy,
5509 struct link_params *params,
5510 struct link_vars *vars)
5511{
5512 struct bnx2x *bp = params->bp;
5513 u16 val1;
5514 u8 link_up = bnx2x_8706_8726_read_status(phy, params, vars);
5515 if (link_up) {
5516 bnx2x_cl45_read(bp, phy,
5517 MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER,
5518 &val1);
5519 if (val1 & (1<<15)) {
5520 DP(NETIF_MSG_LINK, "Tx is disabled\n");
5521 link_up = 0;
5522 vars->line_speed = 0;
5523 }
5524 }
5525 return link_up;
5526}
5527
5528
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00005529static int bnx2x_8726_config_init(struct bnx2x_phy *phy,
5530 struct link_params *params,
5531 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005532{
5533 struct bnx2x *bp = params->bp;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005534 DP(NETIF_MSG_LINK, "Initializing BCM8726\n");
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005535
5536 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 1<<15);
Yaniv Rosner6d870c32011-01-31 04:22:20 +00005537 bnx2x_wait_reset_complete(bp, phy, params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005538
5539 bnx2x_8726_external_rom_boot(phy, params);
5540
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005541 /*
5542 * Need to call module detected on initialization since the module
5543 * detection triggered by actual module insertion might occur before
5544 * driver is loaded, and when driver is loaded, it reset all
5545 * registers, including the transmitter
5546 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005547 bnx2x_sfp_module_detection(phy, params);
5548
5549 if (phy->req_line_speed == SPEED_1000) {
5550 DP(NETIF_MSG_LINK, "Setting 1G force\n");
5551 bnx2x_cl45_write(bp, phy,
5552 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x40);
5553 bnx2x_cl45_write(bp, phy,
5554 MDIO_PMA_DEVAD, MDIO_PMA_REG_10G_CTRL2, 0xD);
5555 bnx2x_cl45_write(bp, phy,
5556 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_CTRL, 0x5);
5557 bnx2x_cl45_write(bp, phy,
5558 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_ALARM_CTRL,
5559 0x400);
5560 } else if ((phy->req_line_speed == SPEED_AUTO_NEG) &&
5561 (phy->speed_cap_mask &
5562 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G) &&
5563 ((phy->speed_cap_mask &
5564 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G) !=
5565 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) {
5566 DP(NETIF_MSG_LINK, "Setting 1G clause37\n");
5567 /* Set Flow control */
5568 bnx2x_ext_phy_set_pause(params, phy, vars);
5569 bnx2x_cl45_write(bp, phy,
5570 MDIO_AN_DEVAD, MDIO_AN_REG_ADV, 0x20);
5571 bnx2x_cl45_write(bp, phy,
5572 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_CL73, 0x040c);
5573 bnx2x_cl45_write(bp, phy,
5574 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LD, 0x0020);
5575 bnx2x_cl45_write(bp, phy,
5576 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_AN, 0x1000);
5577 bnx2x_cl45_write(bp, phy,
5578 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x1200);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005579 /*
5580 * Enable RX-ALARM control to receive interrupt for 1G speed
5581 * change
5582 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005583 bnx2x_cl45_write(bp, phy,
5584 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_CTRL, 0x4);
5585 bnx2x_cl45_write(bp, phy,
5586 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_ALARM_CTRL,
5587 0x400);
5588
5589 } else { /* Default 10G. Set only LASI control */
5590 bnx2x_cl45_write(bp, phy,
5591 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_CTRL, 1);
5592 }
5593
5594 /* Set TX PreEmphasis if needed */
5595 if ((params->feature_config_flags &
5596 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED)) {
5597 DP(NETIF_MSG_LINK, "Setting TX_CTRL1 0x%x,"
5598 "TX_CTRL2 0x%x\n",
5599 phy->tx_preemphasis[0],
5600 phy->tx_preemphasis[1]);
5601 bnx2x_cl45_write(bp, phy,
5602 MDIO_PMA_DEVAD,
5603 MDIO_PMA_REG_8726_TX_CTRL1,
5604 phy->tx_preemphasis[0]);
5605
5606 bnx2x_cl45_write(bp, phy,
5607 MDIO_PMA_DEVAD,
5608 MDIO_PMA_REG_8726_TX_CTRL2,
5609 phy->tx_preemphasis[1]);
5610 }
5611
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005612 return 0;
5613
5614}
5615
5616static void bnx2x_8726_link_reset(struct bnx2x_phy *phy,
5617 struct link_params *params)
5618{
5619 struct bnx2x *bp = params->bp;
5620 DP(NETIF_MSG_LINK, "bnx2x_8726_link_reset port %d\n", params->port);
5621 /* Set serial boot control for external load */
5622 bnx2x_cl45_write(bp, phy,
5623 MDIO_PMA_DEVAD,
5624 MDIO_PMA_REG_GEN_CTRL, 0x0001);
5625}
5626
5627/******************************************************************/
5628/* BCM8727 PHY SECTION */
5629/******************************************************************/
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00005630
5631static void bnx2x_8727_set_link_led(struct bnx2x_phy *phy,
5632 struct link_params *params, u8 mode)
5633{
5634 struct bnx2x *bp = params->bp;
5635 u16 led_mode_bitmask = 0;
5636 u16 gpio_pins_bitmask = 0;
5637 u16 val;
5638 /* Only NOC flavor requires to set the LED specifically */
5639 if (!(phy->flags & FLAGS_NOC))
5640 return;
5641 switch (mode) {
5642 case LED_MODE_FRONT_PANEL_OFF:
5643 case LED_MODE_OFF:
5644 led_mode_bitmask = 0;
5645 gpio_pins_bitmask = 0x03;
5646 break;
5647 case LED_MODE_ON:
5648 led_mode_bitmask = 0;
5649 gpio_pins_bitmask = 0x02;
5650 break;
5651 case LED_MODE_OPER:
5652 led_mode_bitmask = 0x60;
5653 gpio_pins_bitmask = 0x11;
5654 break;
5655 }
5656 bnx2x_cl45_read(bp, phy,
5657 MDIO_PMA_DEVAD,
5658 MDIO_PMA_REG_8727_PCS_OPT_CTRL,
5659 &val);
5660 val &= 0xff8f;
5661 val |= led_mode_bitmask;
5662 bnx2x_cl45_write(bp, phy,
5663 MDIO_PMA_DEVAD,
5664 MDIO_PMA_REG_8727_PCS_OPT_CTRL,
5665 val);
5666 bnx2x_cl45_read(bp, phy,
5667 MDIO_PMA_DEVAD,
5668 MDIO_PMA_REG_8727_GPIO_CTRL,
5669 &val);
5670 val &= 0xffe0;
5671 val |= gpio_pins_bitmask;
5672 bnx2x_cl45_write(bp, phy,
5673 MDIO_PMA_DEVAD,
5674 MDIO_PMA_REG_8727_GPIO_CTRL,
5675 val);
5676}
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005677static void bnx2x_8727_hw_reset(struct bnx2x_phy *phy,
5678 struct link_params *params) {
5679 u32 swap_val, swap_override;
5680 u8 port;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005681 /*
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005682 * The PHY reset is controlled by GPIO 1. Fake the port number
5683 * to cancel the swap done in set_gpio()
5684 */
5685 struct bnx2x *bp = params->bp;
5686 swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
5687 swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
5688 port = (swap_val && swap_override) ^ 1;
5689 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005690 MISC_REGISTERS_GPIO_OUTPUT_LOW, port);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005691}
5692
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00005693static int bnx2x_8727_config_init(struct bnx2x_phy *phy,
5694 struct link_params *params,
5695 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005696{
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00005697 u32 tx_en_mode;
5698 u16 tmp1, val, mod_abs, tmp2;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005699 u16 rx_alarm_ctrl_val;
5700 u16 lasi_ctrl_val;
5701 struct bnx2x *bp = params->bp;
5702 /* Enable PMD link, MOD_ABS_FLT, and 1G link alarm */
5703
Yaniv Rosner6d870c32011-01-31 04:22:20 +00005704 bnx2x_wait_reset_complete(bp, phy, params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005705 rx_alarm_ctrl_val = (1<<2) | (1<<5) ;
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00005706 /* Should be 0x6 to enable XS on Tx side. */
5707 lasi_ctrl_val = 0x0006;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005708
5709 DP(NETIF_MSG_LINK, "Initializing BCM8727\n");
5710 /* enable LASI */
5711 bnx2x_cl45_write(bp, phy,
5712 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_ALARM_CTRL,
5713 rx_alarm_ctrl_val);
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00005714 bnx2x_cl45_write(bp, phy,
5715 MDIO_PMA_DEVAD, MDIO_PMA_REG_TX_ALARM_CTRL,
5716 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005717 bnx2x_cl45_write(bp, phy,
5718 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_CTRL, lasi_ctrl_val);
5719
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005720 /*
5721 * Initially configure MOD_ABS to interrupt when module is
5722 * presence( bit 8)
5723 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005724 bnx2x_cl45_read(bp, phy,
5725 MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER, &mod_abs);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005726 /*
5727 * Set EDC off by setting OPTXLOS signal input to low (bit 9).
5728 * When the EDC is off it locks onto a reference clock and avoids
5729 * becoming 'lost'
5730 */
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00005731 mod_abs &= ~(1<<8);
5732 if (!(phy->flags & FLAGS_NOC))
5733 mod_abs &= ~(1<<9);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005734 bnx2x_cl45_write(bp, phy,
5735 MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER, mod_abs);
5736
5737
5738 /* Make MOD_ABS give interrupt on change */
5739 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_PCS_OPT_CTRL,
5740 &val);
5741 val |= (1<<12);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00005742 if (phy->flags & FLAGS_NOC)
5743 val |= (3<<5);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005744
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005745 /*
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00005746 * Set 8727 GPIOs to input to allow reading from the 8727 GPIO0
5747 * status which reflect SFP+ module over-current
5748 */
5749 if (!(phy->flags & FLAGS_NOC))
5750 val &= 0xff8f; /* Reset bits 4-6 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005751 bnx2x_cl45_write(bp, phy,
5752 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_PCS_OPT_CTRL, val);
5753
5754 bnx2x_8727_power_module(bp, phy, 1);
5755
5756 bnx2x_cl45_read(bp, phy,
5757 MDIO_PMA_DEVAD, MDIO_PMA_REG_M8051_MSGOUT_REG, &tmp1);
5758
5759 bnx2x_cl45_read(bp, phy,
5760 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_ALARM, &tmp1);
5761
5762 /* Set option 1G speed */
5763 if (phy->req_line_speed == SPEED_1000) {
5764 DP(NETIF_MSG_LINK, "Setting 1G force\n");
5765 bnx2x_cl45_write(bp, phy,
5766 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x40);
5767 bnx2x_cl45_write(bp, phy,
5768 MDIO_PMA_DEVAD, MDIO_PMA_REG_10G_CTRL2, 0xD);
5769 bnx2x_cl45_read(bp, phy,
5770 MDIO_PMA_DEVAD, MDIO_PMA_REG_10G_CTRL2, &tmp1);
5771 DP(NETIF_MSG_LINK, "1.7 = 0x%x\n", tmp1);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005772 /*
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005773 * Power down the XAUI until link is up in case of dual-media
5774 * and 1G
5775 */
5776 if (DUAL_MEDIA(params)) {
5777 bnx2x_cl45_read(bp, phy,
5778 MDIO_PMA_DEVAD,
5779 MDIO_PMA_REG_8727_PCS_GP, &val);
5780 val |= (3<<10);
5781 bnx2x_cl45_write(bp, phy,
5782 MDIO_PMA_DEVAD,
5783 MDIO_PMA_REG_8727_PCS_GP, val);
5784 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005785 } else if ((phy->req_line_speed == SPEED_AUTO_NEG) &&
5786 ((phy->speed_cap_mask &
5787 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) &&
5788 ((phy->speed_cap_mask &
5789 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G) !=
5790 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) {
5791
5792 DP(NETIF_MSG_LINK, "Setting 1G clause37\n");
5793 bnx2x_cl45_write(bp, phy,
5794 MDIO_AN_DEVAD, MDIO_AN_REG_8727_MISC_CTRL, 0);
5795 bnx2x_cl45_write(bp, phy,
5796 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_AN, 0x1300);
5797 } else {
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005798 /*
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005799 * Since the 8727 has only single reset pin, need to set the 10G
5800 * registers although it is default
5801 */
5802 bnx2x_cl45_write(bp, phy,
5803 MDIO_AN_DEVAD, MDIO_AN_REG_8727_MISC_CTRL,
5804 0x0020);
5805 bnx2x_cl45_write(bp, phy,
5806 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_AN, 0x0100);
5807 bnx2x_cl45_write(bp, phy,
5808 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x2040);
5809 bnx2x_cl45_write(bp, phy,
5810 MDIO_PMA_DEVAD, MDIO_PMA_REG_10G_CTRL2,
5811 0x0008);
5812 }
5813
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005814 /*
5815 * Set 2-wire transfer rate of SFP+ module EEPROM
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005816 * to 100Khz since some DACs(direct attached cables) do
5817 * not work at 400Khz.
5818 */
5819 bnx2x_cl45_write(bp, phy,
5820 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_TWO_WIRE_SLAVE_ADDR,
5821 0xa001);
5822
5823 /* Set TX PreEmphasis if needed */
5824 if ((params->feature_config_flags &
5825 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED)) {
5826 DP(NETIF_MSG_LINK, "Setting TX_CTRL1 0x%x, TX_CTRL2 0x%x\n",
5827 phy->tx_preemphasis[0],
5828 phy->tx_preemphasis[1]);
5829 bnx2x_cl45_write(bp, phy,
5830 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_TX_CTRL1,
5831 phy->tx_preemphasis[0]);
5832
5833 bnx2x_cl45_write(bp, phy,
5834 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_TX_CTRL2,
5835 phy->tx_preemphasis[1]);
5836 }
5837
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00005838 /*
5839 * If TX Laser is controlled by GPIO_0, do not let PHY go into low
5840 * power mode, if TX Laser is disabled
5841 */
5842 tx_en_mode = REG_RD(bp, params->shmem_base +
5843 offsetof(struct shmem_region,
5844 dev_info.port_hw_config[params->port].sfp_ctrl))
5845 & PORT_HW_CFG_TX_LASER_MASK;
5846
5847 if (tx_en_mode == PORT_HW_CFG_TX_LASER_GPIO0) {
5848
5849 DP(NETIF_MSG_LINK, "Enabling TXONOFF_PWRDN_DIS\n");
5850 bnx2x_cl45_read(bp, phy,
5851 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_OPT_CFG_REG, &tmp2);
5852 tmp2 |= 0x1000;
5853 tmp2 &= 0xFFEF;
5854 bnx2x_cl45_write(bp, phy,
5855 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_OPT_CFG_REG, tmp2);
5856 }
5857
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005858 return 0;
5859}
5860
5861static void bnx2x_8727_handle_mod_abs(struct bnx2x_phy *phy,
5862 struct link_params *params)
5863{
5864 struct bnx2x *bp = params->bp;
5865 u16 mod_abs, rx_alarm_status;
5866 u32 val = REG_RD(bp, params->shmem_base +
5867 offsetof(struct shmem_region, dev_info.
5868 port_feature_config[params->port].
5869 config));
5870 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005871 MDIO_PMA_DEVAD,
5872 MDIO_PMA_REG_PHY_IDENTIFIER, &mod_abs);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005873 if (mod_abs & (1<<8)) {
5874
5875 /* Module is absent */
5876 DP(NETIF_MSG_LINK, "MOD_ABS indication "
5877 "show module is absent\n");
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00005878 phy->media_type = ETH_PHY_NOT_PRESENT;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005879 /*
5880 * 1. Set mod_abs to detect next module
5881 * presence event
5882 * 2. Set EDC off by setting OPTXLOS signal input to low
5883 * (bit 9).
5884 * When the EDC is off it locks onto a reference clock and
5885 * avoids becoming 'lost'.
5886 */
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00005887 mod_abs &= ~(1<<8);
5888 if (!(phy->flags & FLAGS_NOC))
5889 mod_abs &= ~(1<<9);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005890 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005891 MDIO_PMA_DEVAD,
5892 MDIO_PMA_REG_PHY_IDENTIFIER, mod_abs);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005893
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005894 /*
5895 * Clear RX alarm since it stays up as long as
5896 * the mod_abs wasn't changed
5897 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005898 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005899 MDIO_PMA_DEVAD,
5900 MDIO_PMA_REG_RX_ALARM, &rx_alarm_status);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005901
5902 } else {
5903 /* Module is present */
5904 DP(NETIF_MSG_LINK, "MOD_ABS indication "
5905 "show module is present\n");
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005906 /*
5907 * First disable transmitter, and if the module is ok, the
5908 * module_detection will enable it
5909 * 1. Set mod_abs to detect next module absent event ( bit 8)
5910 * 2. Restore the default polarity of the OPRXLOS signal and
5911 * this signal will then correctly indicate the presence or
5912 * absence of the Rx signal. (bit 9)
5913 */
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00005914 mod_abs |= (1<<8);
5915 if (!(phy->flags & FLAGS_NOC))
5916 mod_abs |= (1<<9);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005917 bnx2x_cl45_write(bp, phy,
5918 MDIO_PMA_DEVAD,
5919 MDIO_PMA_REG_PHY_IDENTIFIER, mod_abs);
5920
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005921 /*
5922 * Clear RX alarm since it stays up as long as the mod_abs
5923 * wasn't changed. This is need to be done before calling the
5924 * module detection, otherwise it will clear* the link update
5925 * alarm
5926 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005927 bnx2x_cl45_read(bp, phy,
5928 MDIO_PMA_DEVAD,
5929 MDIO_PMA_REG_RX_ALARM, &rx_alarm_status);
5930
5931
5932 if ((val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) ==
5933 PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_DISABLE_TX_LASER)
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00005934 bnx2x_sfp_set_transmitter(params, phy, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005935
5936 if (bnx2x_wait_for_sfp_module_initialized(phy, params) == 0)
5937 bnx2x_sfp_module_detection(phy, params);
5938 else
5939 DP(NETIF_MSG_LINK, "SFP+ module is not initialized\n");
5940 }
5941
5942 DP(NETIF_MSG_LINK, "8727 RX_ALARM_STATUS 0x%x\n",
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005943 rx_alarm_status);
5944 /* No need to check link status in case of module plugged in/out */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005945}
5946
5947static u8 bnx2x_8727_read_status(struct bnx2x_phy *phy,
5948 struct link_params *params,
5949 struct link_vars *vars)
5950
5951{
5952 struct bnx2x *bp = params->bp;
Yaniv Rosner27d02432011-05-31 21:27:48 +00005953 u8 link_up = 0, oc_port = params->port;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005954 u16 link_status = 0;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005955 u16 rx_alarm_status, lasi_ctrl, val1;
5956
5957 /* If PHY is not initialized, do not check link status */
5958 bnx2x_cl45_read(bp, phy,
5959 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_CTRL,
5960 &lasi_ctrl);
5961 if (!lasi_ctrl)
5962 return 0;
5963
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00005964 /* Check the LASI on Rx */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005965 bnx2x_cl45_read(bp, phy,
5966 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_ALARM,
5967 &rx_alarm_status);
5968 vars->line_speed = 0;
5969 DP(NETIF_MSG_LINK, "8727 RX_ALARM_STATUS 0x%x\n", rx_alarm_status);
5970
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00005971 bnx2x_sfp_mask_fault(bp, phy, MDIO_PMA_REG_TX_ALARM,
5972 MDIO_PMA_REG_TX_ALARM_CTRL);
5973
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005974 bnx2x_cl45_read(bp, phy,
5975 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_STATUS, &val1);
5976
5977 DP(NETIF_MSG_LINK, "8727 LASI status 0x%x\n", val1);
5978
5979 /* Clear MSG-OUT */
5980 bnx2x_cl45_read(bp, phy,
5981 MDIO_PMA_DEVAD, MDIO_PMA_REG_M8051_MSGOUT_REG, &val1);
5982
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005983 /*
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005984 * If a module is present and there is need to check
5985 * for over current
5986 */
5987 if (!(phy->flags & FLAGS_NOC) && !(rx_alarm_status & (1<<5))) {
5988 /* Check over-current using 8727 GPIO0 input*/
5989 bnx2x_cl45_read(bp, phy,
5990 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_GPIO_CTRL,
5991 &val1);
5992
5993 if ((val1 & (1<<8)) == 0) {
Yaniv Rosner27d02432011-05-31 21:27:48 +00005994 if (!CHIP_IS_E1x(bp))
5995 oc_port = BP_PATH(bp) + (params->port << 1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005996 DP(NETIF_MSG_LINK, "8727 Power fault has been detected"
Yaniv Rosner27d02432011-05-31 21:27:48 +00005997 " on port %d\n", oc_port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005998 netdev_err(bp->dev, "Error: Power fault on Port %d has"
5999 " been detected and the power to "
6000 "that SFP+ module has been removed"
6001 " to prevent failure of the card."
6002 " Please remove the SFP+ module and"
6003 " restart the system to clear this"
6004 " error.\n",
Yaniv Rosner27d02432011-05-31 21:27:48 +00006005 oc_port);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006006 /* Disable all RX_ALARMs except for mod_abs */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006007 bnx2x_cl45_write(bp, phy,
6008 MDIO_PMA_DEVAD,
6009 MDIO_PMA_REG_RX_ALARM_CTRL, (1<<5));
6010
6011 bnx2x_cl45_read(bp, phy,
6012 MDIO_PMA_DEVAD,
6013 MDIO_PMA_REG_PHY_IDENTIFIER, &val1);
6014 /* Wait for module_absent_event */
6015 val1 |= (1<<8);
6016 bnx2x_cl45_write(bp, phy,
6017 MDIO_PMA_DEVAD,
6018 MDIO_PMA_REG_PHY_IDENTIFIER, val1);
6019 /* Clear RX alarm */
6020 bnx2x_cl45_read(bp, phy,
6021 MDIO_PMA_DEVAD,
6022 MDIO_PMA_REG_RX_ALARM, &rx_alarm_status);
6023 return 0;
6024 }
6025 } /* Over current check */
6026
6027 /* When module absent bit is set, check module */
6028 if (rx_alarm_status & (1<<5)) {
6029 bnx2x_8727_handle_mod_abs(phy, params);
6030 /* Enable all mod_abs and link detection bits */
6031 bnx2x_cl45_write(bp, phy,
6032 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_ALARM_CTRL,
6033 ((1<<5) | (1<<2)));
6034 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006035 DP(NETIF_MSG_LINK, "Enabling 8727 TX laser if SFP is approved\n");
6036 bnx2x_8727_specific_func(phy, params, ENABLE_TX);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006037 /* If transmitter is disabled, ignore false link up indication */
6038 bnx2x_cl45_read(bp, phy,
6039 MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER, &val1);
6040 if (val1 & (1<<15)) {
6041 DP(NETIF_MSG_LINK, "Tx is disabled\n");
6042 return 0;
6043 }
6044
6045 bnx2x_cl45_read(bp, phy,
6046 MDIO_PMA_DEVAD,
6047 MDIO_PMA_REG_8073_SPEED_LINK_STATUS, &link_status);
6048
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006049 /*
6050 * Bits 0..2 --> speed detected,
6051 * Bits 13..15--> link is down
6052 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006053 if ((link_status & (1<<2)) && (!(link_status & (1<<15)))) {
6054 link_up = 1;
6055 vars->line_speed = SPEED_10000;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006056 DP(NETIF_MSG_LINK, "port %x: External link up in 10G\n",
6057 params->port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006058 } else if ((link_status & (1<<0)) && (!(link_status & (1<<13)))) {
6059 link_up = 1;
6060 vars->line_speed = SPEED_1000;
6061 DP(NETIF_MSG_LINK, "port %x: External link up in 1G\n",
6062 params->port);
6063 } else {
6064 link_up = 0;
6065 DP(NETIF_MSG_LINK, "port %x: External link is down\n",
6066 params->port);
6067 }
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00006068
6069 /* Capture 10G link fault. */
6070 if (vars->line_speed == SPEED_10000) {
6071 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
6072 MDIO_PMA_REG_TX_ALARM, &val1);
6073
6074 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
6075 MDIO_PMA_REG_TX_ALARM, &val1);
6076
6077 if (val1 & (1<<0)) {
6078 vars->fault_detected = 1;
6079 }
6080 }
6081
Yaniv Rosner791f18c2011-01-18 04:33:42 +00006082 if (link_up) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006083 bnx2x_ext_phy_resolve_fc(phy, params, vars);
Yaniv Rosner791f18c2011-01-18 04:33:42 +00006084 vars->duplex = DUPLEX_FULL;
6085 DP(NETIF_MSG_LINK, "duplex = 0x%x\n", vars->duplex);
6086 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006087
6088 if ((DUAL_MEDIA(params)) &&
6089 (phy->req_line_speed == SPEED_1000)) {
6090 bnx2x_cl45_read(bp, phy,
6091 MDIO_PMA_DEVAD,
6092 MDIO_PMA_REG_8727_PCS_GP, &val1);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006093 /*
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006094 * In case of dual-media board and 1G, power up the XAUI side,
6095 * otherwise power it down. For 10G it is done automatically
6096 */
6097 if (link_up)
6098 val1 &= ~(3<<10);
6099 else
6100 val1 |= (3<<10);
6101 bnx2x_cl45_write(bp, phy,
6102 MDIO_PMA_DEVAD,
6103 MDIO_PMA_REG_8727_PCS_GP, val1);
6104 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006105 return link_up;
6106}
6107
6108static void bnx2x_8727_link_reset(struct bnx2x_phy *phy,
6109 struct link_params *params)
6110{
6111 struct bnx2x *bp = params->bp;
6112 /* Disable Transmitter */
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00006113 bnx2x_sfp_set_transmitter(params, phy, 0);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006114 /* Clear LASI */
6115 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_CTRL, 0);
6116
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006117}
6118
6119/******************************************************************/
6120/* BCM8481/BCM84823/BCM84833 PHY SECTION */
6121/******************************************************************/
6122static void bnx2x_save_848xx_spirom_version(struct bnx2x_phy *phy,
6123 struct link_params *params)
6124{
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00006125 u16 val, fw_ver1, fw_ver2, cnt;
6126 u8 port;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006127 struct bnx2x *bp = params->bp;
6128
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00006129 port = params->port;
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00006130
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006131 /* For the 32 bits registers in 848xx, access via MDIO2ARM interface.*/
6132 /* (1) set register 0xc200_0014(SPI_BRIDGE_CTRL_2) to 0x03000000 */
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00006133 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA819, 0x0014);
6134 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA81A, 0xc200);
6135 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA81B, 0x0000);
6136 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA81C, 0x0300);
6137 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA817, 0x0009);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006138
6139 for (cnt = 0; cnt < 100; cnt++) {
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00006140 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD, 0xA818, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006141 if (val & 1)
6142 break;
6143 udelay(5);
6144 }
6145 if (cnt == 100) {
6146 DP(NETIF_MSG_LINK, "Unable to read 848xx phy fw version(1)\n");
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00006147 bnx2x_save_spirom_version(bp, port, 0,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006148 phy->ver_addr);
6149 return;
6150 }
6151
6152
6153 /* 2) read register 0xc200_0000 (SPI_FW_STATUS) */
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00006154 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA819, 0x0000);
6155 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA81A, 0xc200);
6156 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA817, 0x000A);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006157 for (cnt = 0; cnt < 100; cnt++) {
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00006158 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD, 0xA818, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006159 if (val & 1)
6160 break;
6161 udelay(5);
6162 }
6163 if (cnt == 100) {
6164 DP(NETIF_MSG_LINK, "Unable to read 848xx phy fw version(2)\n");
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00006165 bnx2x_save_spirom_version(bp, port, 0,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006166 phy->ver_addr);
6167 return;
6168 }
6169
6170 /* lower 16 bits of the register SPI_FW_STATUS */
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00006171 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD, 0xA81B, &fw_ver1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006172 /* upper 16 bits of register SPI_FW_STATUS */
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00006173 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD, 0xA81C, &fw_ver2);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006174
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00006175 bnx2x_save_spirom_version(bp, port, (fw_ver2<<16) | fw_ver1,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006176 phy->ver_addr);
6177}
6178
6179static void bnx2x_848xx_set_led(struct bnx2x *bp,
6180 struct bnx2x_phy *phy)
6181{
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00006182 u16 val;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006183
6184 /* PHYC_CTL_LED_CTL */
6185 bnx2x_cl45_read(bp, phy,
6186 MDIO_PMA_DEVAD,
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00006187 MDIO_PMA_REG_8481_LINK_SIGNAL, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006188 val &= 0xFE00;
6189 val |= 0x0092;
6190
6191 bnx2x_cl45_write(bp, phy,
6192 MDIO_PMA_DEVAD,
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00006193 MDIO_PMA_REG_8481_LINK_SIGNAL, val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006194
6195 bnx2x_cl45_write(bp, phy,
6196 MDIO_PMA_DEVAD,
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00006197 MDIO_PMA_REG_8481_LED1_MASK,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006198 0x80);
6199
6200 bnx2x_cl45_write(bp, phy,
6201 MDIO_PMA_DEVAD,
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00006202 MDIO_PMA_REG_8481_LED2_MASK,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006203 0x18);
6204
Yaniv Rosnerf25b3c82011-01-18 04:33:47 +00006205 /* Select activity source by Tx and Rx, as suggested by PHY AE */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006206 bnx2x_cl45_write(bp, phy,
6207 MDIO_PMA_DEVAD,
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00006208 MDIO_PMA_REG_8481_LED3_MASK,
Yaniv Rosnerf25b3c82011-01-18 04:33:47 +00006209 0x0006);
6210
6211 /* Select the closest activity blink rate to that in 10/100/1000 */
6212 bnx2x_cl45_write(bp, phy,
6213 MDIO_PMA_DEVAD,
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00006214 MDIO_PMA_REG_8481_LED3_BLINK,
Yaniv Rosnerf25b3c82011-01-18 04:33:47 +00006215 0);
6216
6217 bnx2x_cl45_read(bp, phy,
6218 MDIO_PMA_DEVAD,
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00006219 MDIO_PMA_REG_84823_CTL_LED_CTL_1, &val);
Yaniv Rosnerf25b3c82011-01-18 04:33:47 +00006220 val |= MDIO_PMA_REG_84823_LED3_STRETCH_EN; /* stretch_en for LED3*/
6221
6222 bnx2x_cl45_write(bp, phy,
6223 MDIO_PMA_DEVAD,
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00006224 MDIO_PMA_REG_84823_CTL_LED_CTL_1, val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006225
6226 /* 'Interrupt Mask' */
6227 bnx2x_cl45_write(bp, phy,
6228 MDIO_AN_DEVAD,
6229 0xFFFB, 0xFFFD);
6230}
6231
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006232static int bnx2x_848xx_cmn_config_init(struct bnx2x_phy *phy,
6233 struct link_params *params,
6234 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006235{
6236 struct bnx2x *bp = params->bp;
6237 u16 autoneg_val, an_1000_val, an_10_100_val;
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00006238 u16 tmp_req_line_speed;
6239
6240 tmp_req_line_speed = phy->req_line_speed;
6241 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
6242 if (phy->req_line_speed == SPEED_10000)
6243 phy->req_line_speed = SPEED_AUTO_NEG;
6244
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006245 /*
6246 * This phy uses the NIG latch mechanism since link indication
6247 * arrives through its LED4 and not via its LASI signal, so we
6248 * get steady signal instead of clear on read
6249 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006250 bnx2x_bits_en(bp, NIG_REG_LATCH_BC_0 + params->port*4,
6251 1 << NIG_LATCH_BC_ENABLE_MI_INT);
6252
6253 bnx2x_cl45_write(bp, phy,
6254 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x0000);
6255
6256 bnx2x_848xx_set_led(bp, phy);
6257
6258 /* set 1000 speed advertisement */
6259 bnx2x_cl45_read(bp, phy,
6260 MDIO_AN_DEVAD, MDIO_AN_REG_8481_1000T_CTRL,
6261 &an_1000_val);
6262
6263 bnx2x_ext_phy_set_pause(params, phy, vars);
6264 bnx2x_cl45_read(bp, phy,
6265 MDIO_AN_DEVAD,
6266 MDIO_AN_REG_8481_LEGACY_AN_ADV,
6267 &an_10_100_val);
6268 bnx2x_cl45_read(bp, phy,
6269 MDIO_AN_DEVAD, MDIO_AN_REG_8481_LEGACY_MII_CTRL,
6270 &autoneg_val);
6271 /* Disable forced speed */
6272 autoneg_val &= ~((1<<6) | (1<<8) | (1<<9) | (1<<12) | (1<<13));
6273 an_10_100_val &= ~((1<<5) | (1<<6) | (1<<7) | (1<<8));
6274
6275 if (((phy->req_line_speed == SPEED_AUTO_NEG) &&
6276 (phy->speed_cap_mask &
6277 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) ||
6278 (phy->req_line_speed == SPEED_1000)) {
6279 an_1000_val |= (1<<8);
6280 autoneg_val |= (1<<9 | 1<<12);
6281 if (phy->req_duplex == DUPLEX_FULL)
6282 an_1000_val |= (1<<9);
6283 DP(NETIF_MSG_LINK, "Advertising 1G\n");
6284 } else
6285 an_1000_val &= ~((1<<8) | (1<<9));
6286
6287 bnx2x_cl45_write(bp, phy,
6288 MDIO_AN_DEVAD, MDIO_AN_REG_8481_1000T_CTRL,
6289 an_1000_val);
6290
6291 /* set 10 speed advertisement */
6292 if (((phy->req_line_speed == SPEED_AUTO_NEG) &&
6293 (phy->speed_cap_mask &
6294 (PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL |
6295 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF)))) {
6296 an_10_100_val |= (1<<7);
6297 /* Enable autoneg and restart autoneg for legacy speeds */
6298 autoneg_val |= (1<<9 | 1<<12);
6299
6300 if (phy->req_duplex == DUPLEX_FULL)
6301 an_10_100_val |= (1<<8);
6302 DP(NETIF_MSG_LINK, "Advertising 100M\n");
6303 }
6304 /* set 10 speed advertisement */
6305 if (((phy->req_line_speed == SPEED_AUTO_NEG) &&
6306 (phy->speed_cap_mask &
6307 (PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL |
6308 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF)))) {
6309 an_10_100_val |= (1<<5);
6310 autoneg_val |= (1<<9 | 1<<12);
6311 if (phy->req_duplex == DUPLEX_FULL)
6312 an_10_100_val |= (1<<6);
6313 DP(NETIF_MSG_LINK, "Advertising 10M\n");
6314 }
6315
6316 /* Only 10/100 are allowed to work in FORCE mode */
6317 if (phy->req_line_speed == SPEED_100) {
6318 autoneg_val |= (1<<13);
6319 /* Enabled AUTO-MDIX when autoneg is disabled */
6320 bnx2x_cl45_write(bp, phy,
6321 MDIO_AN_DEVAD, MDIO_AN_REG_8481_AUX_CTRL,
6322 (1<<15 | 1<<9 | 7<<0));
6323 DP(NETIF_MSG_LINK, "Setting 100M force\n");
6324 }
6325 if (phy->req_line_speed == SPEED_10) {
6326 /* Enabled AUTO-MDIX when autoneg is disabled */
6327 bnx2x_cl45_write(bp, phy,
6328 MDIO_AN_DEVAD, MDIO_AN_REG_8481_AUX_CTRL,
6329 (1<<15 | 1<<9 | 7<<0));
6330 DP(NETIF_MSG_LINK, "Setting 10M force\n");
6331 }
6332
6333 bnx2x_cl45_write(bp, phy,
6334 MDIO_AN_DEVAD, MDIO_AN_REG_8481_LEGACY_AN_ADV,
6335 an_10_100_val);
6336
6337 if (phy->req_duplex == DUPLEX_FULL)
6338 autoneg_val |= (1<<8);
6339
6340 bnx2x_cl45_write(bp, phy,
6341 MDIO_AN_DEVAD,
6342 MDIO_AN_REG_8481_LEGACY_MII_CTRL, autoneg_val);
6343
6344 if (((phy->req_line_speed == SPEED_AUTO_NEG) &&
6345 (phy->speed_cap_mask &
6346 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) ||
6347 (phy->req_line_speed == SPEED_10000)) {
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00006348 DP(NETIF_MSG_LINK, "Advertising 10G\n");
6349 /* Restart autoneg for 10G*/
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006350
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00006351 bnx2x_cl45_write(bp, phy,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006352 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL,
6353 0x3200);
6354 } else if (phy->req_line_speed != SPEED_10 &&
6355 phy->req_line_speed != SPEED_100) {
6356 bnx2x_cl45_write(bp, phy,
6357 MDIO_AN_DEVAD,
6358 MDIO_AN_REG_8481_10GBASE_T_AN_CTRL,
6359 1);
6360 }
6361 /* Save spirom version */
6362 bnx2x_save_848xx_spirom_version(phy, params);
6363
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00006364 phy->req_line_speed = tmp_req_line_speed;
6365
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006366 return 0;
6367}
6368
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006369static int bnx2x_8481_config_init(struct bnx2x_phy *phy,
6370 struct link_params *params,
6371 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006372{
6373 struct bnx2x *bp = params->bp;
6374 /* Restore normal power mode*/
6375 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006376 MISC_REGISTERS_GPIO_OUTPUT_HIGH, params->port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006377
6378 /* HW reset */
6379 bnx2x_ext_phy_hw_reset(bp, params->port);
Yaniv Rosner6d870c32011-01-31 04:22:20 +00006380 bnx2x_wait_reset_complete(bp, phy, params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006381
6382 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 1<<15);
6383 return bnx2x_848xx_cmn_config_init(phy, params, vars);
6384}
6385
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00006386
6387#define PHY84833_HDSHK_WAIT 300
6388static int bnx2x_84833_pair_swap_cfg(struct bnx2x_phy *phy,
6389 struct link_params *params,
6390 struct link_vars *vars)
6391{
6392 u32 idx;
6393 u16 val;
6394 u16 data = 0x01b1;
6395 struct bnx2x *bp = params->bp;
6396 /* Do pair swap */
6397
6398
6399 /* Write CMD_OPEN_OVERRIDE to STATUS reg */
6400 bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
6401 MDIO_84833_TOP_CFG_SCRATCH_REG2,
6402 PHY84833_CMD_OPEN_OVERRIDE);
6403 for (idx = 0; idx < PHY84833_HDSHK_WAIT; idx++) {
6404 bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD,
6405 MDIO_84833_TOP_CFG_SCRATCH_REG2, &val);
6406 if (val == PHY84833_CMD_OPEN_FOR_CMDS)
6407 break;
6408 msleep(1);
6409 }
6410 if (idx >= PHY84833_HDSHK_WAIT) {
6411 DP(NETIF_MSG_LINK, "Pairswap: FW not ready.\n");
6412 return -EINVAL;
6413 }
6414
6415 bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
6416 MDIO_84833_TOP_CFG_SCRATCH_REG4,
6417 data);
6418 /* Issue pair swap command */
6419 bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
6420 MDIO_84833_TOP_CFG_SCRATCH_REG0,
6421 PHY84833_DIAG_CMD_PAIR_SWAP_CHANGE);
6422 for (idx = 0; idx < PHY84833_HDSHK_WAIT; idx++) {
6423 bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD,
6424 MDIO_84833_TOP_CFG_SCRATCH_REG2, &val);
6425 if ((val == PHY84833_CMD_COMPLETE_PASS) ||
6426 (val == PHY84833_CMD_COMPLETE_ERROR))
6427 break;
6428 msleep(1);
6429 }
6430 if ((idx >= PHY84833_HDSHK_WAIT) ||
6431 (val == PHY84833_CMD_COMPLETE_ERROR)) {
6432 DP(NETIF_MSG_LINK, "Pairswap: override failed.\n");
6433 return -EINVAL;
6434 }
6435 bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
6436 MDIO_84833_TOP_CFG_SCRATCH_REG2,
6437 PHY84833_CMD_CLEAR_COMPLETE);
6438 DP(NETIF_MSG_LINK, "Pairswap OK, val=0x%x\n", data);
6439 return 0;
6440}
6441
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006442static int bnx2x_848x3_config_init(struct bnx2x_phy *phy,
6443 struct link_params *params,
6444 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006445{
6446 struct bnx2x *bp = params->bp;
Yaniv Rosner6a71bbe2010-11-01 05:32:31 +00006447 u8 port, initialize = 1;
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00006448 u16 val;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006449 u16 temp;
Yaniv Rosner1bef68e2011-01-31 04:22:46 +00006450 u32 actual_phy_selection, cms_enable;
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006451 int rc = 0;
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006452
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006453 msleep(1);
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00006454
6455 if (!(CHIP_IS_E1(bp)))
Yaniv Rosner6a71bbe2010-11-01 05:32:31 +00006456 port = BP_PATH(bp);
6457 else
6458 port = params->port;
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00006459
6460 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84823) {
6461 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_3,
6462 MISC_REGISTERS_GPIO_OUTPUT_HIGH,
6463 port);
6464 } else {
6465 bnx2x_cl45_write(bp, phy,
6466 MDIO_PMA_DEVAD,
6467 MDIO_PMA_REG_CTRL, 0x8000);
6468 }
6469
Yaniv Rosner6d870c32011-01-31 04:22:20 +00006470 bnx2x_wait_reset_complete(bp, phy, params);
Yaniv Rosner9bffeac2010-11-01 05:32:27 +00006471 /* Wait for GPHY to come out of reset */
6472 msleep(50);
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00006473
6474 /* Bring PHY out of super isolate mode */
6475 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833) {
6476 bnx2x_cl45_read(bp, phy,
6477 MDIO_CTL_DEVAD,
6478 MDIO_84833_TOP_CFG_XGPHY_STRAP1, &val);
6479 val &= ~MDIO_84833_SUPER_ISOLATE;
6480 bnx2x_cl45_write(bp, phy,
6481 MDIO_CTL_DEVAD,
6482 MDIO_84833_TOP_CFG_XGPHY_STRAP1, val);
6483 bnx2x_wait_reset_complete(bp, phy, params);
6484 }
6485
6486 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
6487 bnx2x_84833_pair_swap_cfg(phy, params, vars);
6488
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006489 /*
6490 * BCM84823 requires that XGXS links up first @ 10G for normal behavior
6491 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006492 temp = vars->line_speed;
6493 vars->line_speed = SPEED_10000;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006494 bnx2x_set_autoneg(&params->phy[INT_PHY], params, vars, 0);
6495 bnx2x_program_serdes(&params->phy[INT_PHY], params, vars);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006496 vars->line_speed = temp;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006497
6498 /* Set dual-media configuration according to configuration */
6499
6500 bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD,
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00006501 MDIO_CTL_REG_84823_MEDIA, &val);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006502 val &= ~(MDIO_CTL_REG_84823_MEDIA_MAC_MASK |
6503 MDIO_CTL_REG_84823_MEDIA_LINE_MASK |
6504 MDIO_CTL_REG_84823_MEDIA_COPPER_CORE_DOWN |
6505 MDIO_CTL_REG_84823_MEDIA_PRIORITY_MASK |
6506 MDIO_CTL_REG_84823_MEDIA_FIBER_1G);
6507 val |= MDIO_CTL_REG_84823_CTRL_MAC_XFI |
6508 MDIO_CTL_REG_84823_MEDIA_LINE_XAUI_L;
6509
6510 actual_phy_selection = bnx2x_phy_selection(params);
6511
6512 switch (actual_phy_selection) {
6513 case PORT_HW_CFG_PHY_SELECTION_HARDWARE_DEFAULT:
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006514 /* Do nothing. Essentially this is like the priority copper */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006515 break;
6516 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY_PRIORITY:
6517 val |= MDIO_CTL_REG_84823_MEDIA_PRIORITY_COPPER;
6518 break;
6519 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY_PRIORITY:
6520 val |= MDIO_CTL_REG_84823_MEDIA_PRIORITY_FIBER;
6521 break;
6522 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY:
6523 /* Do nothing here. The first PHY won't be initialized at all */
6524 break;
6525 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY:
6526 val |= MDIO_CTL_REG_84823_MEDIA_COPPER_CORE_DOWN;
6527 initialize = 0;
6528 break;
6529 }
6530 if (params->phy[EXT_PHY2].req_line_speed == SPEED_1000)
6531 val |= MDIO_CTL_REG_84823_MEDIA_FIBER_1G;
6532
6533 bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00006534 MDIO_CTL_REG_84823_MEDIA, val);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006535 DP(NETIF_MSG_LINK, "Multi_phy config = 0x%x, Media control = 0x%x\n",
6536 params->multi_phy_config, val);
6537
6538 if (initialize)
6539 rc = bnx2x_848xx_cmn_config_init(phy, params, vars);
6540 else
6541 bnx2x_save_848xx_spirom_version(phy, params);
Yaniv Rosner1bef68e2011-01-31 04:22:46 +00006542 cms_enable = REG_RD(bp, params->shmem_base +
6543 offsetof(struct shmem_region,
6544 dev_info.port_hw_config[params->port].default_cfg)) &
6545 PORT_HW_CFG_ENABLE_CMS_MASK;
6546
6547 bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD,
6548 MDIO_CTL_REG_84823_USER_CTRL_REG, &val);
6549 if (cms_enable)
6550 val |= MDIO_CTL_REG_84823_USER_CTRL_CMS;
6551 else
6552 val &= ~MDIO_CTL_REG_84823_USER_CTRL_CMS;
6553 bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
6554 MDIO_CTL_REG_84823_USER_CTRL_REG, val);
6555
6556
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006557 return rc;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006558}
6559
6560static u8 bnx2x_848xx_read_status(struct bnx2x_phy *phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006561 struct link_params *params,
6562 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006563{
6564 struct bnx2x *bp = params->bp;
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00006565 u16 val, val1, val2;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006566 u8 link_up = 0;
6567
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00006568
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006569 /* Check 10G-BaseT link status */
6570 /* Check PMD signal ok */
6571 bnx2x_cl45_read(bp, phy,
6572 MDIO_AN_DEVAD, 0xFFFA, &val1);
6573 bnx2x_cl45_read(bp, phy,
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00006574 MDIO_PMA_DEVAD, MDIO_PMA_REG_8481_PMD_SIGNAL,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006575 &val2);
6576 DP(NETIF_MSG_LINK, "BCM848xx: PMD_SIGNAL 1.a811 = 0x%x\n", val2);
6577
6578 /* Check link 10G */
6579 if (val2 & (1<<11)) {
6580 vars->line_speed = SPEED_10000;
Yaniv Rosner791f18c2011-01-18 04:33:42 +00006581 vars->duplex = DUPLEX_FULL;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006582 link_up = 1;
6583 bnx2x_ext_phy_10G_an_resolve(bp, phy, vars);
6584 } else { /* Check Legacy speed link */
6585 u16 legacy_status, legacy_speed;
6586
6587 /* Enable expansion register 0x42 (Operation mode status) */
6588 bnx2x_cl45_write(bp, phy,
6589 MDIO_AN_DEVAD,
6590 MDIO_AN_REG_8481_EXPANSION_REG_ACCESS, 0xf42);
6591
6592 /* Get legacy speed operation status */
6593 bnx2x_cl45_read(bp, phy,
6594 MDIO_AN_DEVAD,
6595 MDIO_AN_REG_8481_EXPANSION_REG_RD_RW,
6596 &legacy_status);
6597
6598 DP(NETIF_MSG_LINK, "Legacy speed status"
6599 " = 0x%x\n", legacy_status);
6600 link_up = ((legacy_status & (1<<11)) == (1<<11));
6601 if (link_up) {
6602 legacy_speed = (legacy_status & (3<<9));
6603 if (legacy_speed == (0<<9))
6604 vars->line_speed = SPEED_10;
6605 else if (legacy_speed == (1<<9))
6606 vars->line_speed = SPEED_100;
6607 else if (legacy_speed == (2<<9))
6608 vars->line_speed = SPEED_1000;
6609 else /* Should not happen */
6610 vars->line_speed = 0;
6611
6612 if (legacy_status & (1<<8))
6613 vars->duplex = DUPLEX_FULL;
6614 else
6615 vars->duplex = DUPLEX_HALF;
6616
6617 DP(NETIF_MSG_LINK, "Link is up in %dMbps,"
6618 " is_duplex_full= %d\n", vars->line_speed,
6619 (vars->duplex == DUPLEX_FULL));
6620 /* Check legacy speed AN resolution */
6621 bnx2x_cl45_read(bp, phy,
6622 MDIO_AN_DEVAD,
6623 MDIO_AN_REG_8481_LEGACY_MII_STATUS,
6624 &val);
6625 if (val & (1<<5))
6626 vars->link_status |=
6627 LINK_STATUS_AUTO_NEGOTIATE_COMPLETE;
6628 bnx2x_cl45_read(bp, phy,
6629 MDIO_AN_DEVAD,
6630 MDIO_AN_REG_8481_LEGACY_AN_EXPANSION,
6631 &val);
6632 if ((val & (1<<0)) == 0)
6633 vars->link_status |=
6634 LINK_STATUS_PARALLEL_DETECTION_USED;
6635 }
6636 }
6637 if (link_up) {
6638 DP(NETIF_MSG_LINK, "BCM84823: link speed is %d\n",
6639 vars->line_speed);
6640 bnx2x_ext_phy_resolve_fc(phy, params, vars);
6641 }
6642
6643 return link_up;
6644}
6645
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006646
6647static int bnx2x_848xx_format_ver(u32 raw_ver, u8 *str, u16 *len)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006648{
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006649 int status = 0;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006650 u32 spirom_ver;
6651 spirom_ver = ((raw_ver & 0xF80) >> 7) << 16 | (raw_ver & 0x7F);
6652 status = bnx2x_format_ver(spirom_ver, str, len);
6653 return status;
6654}
6655
6656static void bnx2x_8481_hw_reset(struct bnx2x_phy *phy,
6657 struct link_params *params)
6658{
6659 bnx2x_set_gpio(params->bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006660 MISC_REGISTERS_GPIO_OUTPUT_LOW, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006661 bnx2x_set_gpio(params->bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006662 MISC_REGISTERS_GPIO_OUTPUT_LOW, 1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006663}
6664
6665static void bnx2x_8481_link_reset(struct bnx2x_phy *phy,
6666 struct link_params *params)
6667{
6668 bnx2x_cl45_write(params->bp, phy,
6669 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x0000);
6670 bnx2x_cl45_write(params->bp, phy,
6671 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 1);
6672}
6673
6674static void bnx2x_848x3_link_reset(struct bnx2x_phy *phy,
6675 struct link_params *params)
6676{
6677 struct bnx2x *bp = params->bp;
Yaniv Rosner6a71bbe2010-11-01 05:32:31 +00006678 u8 port;
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00006679
6680 if (!(CHIP_IS_E1(bp)))
Yaniv Rosner6a71bbe2010-11-01 05:32:31 +00006681 port = BP_PATH(bp);
6682 else
6683 port = params->port;
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00006684
6685 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84823) {
6686 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_3,
6687 MISC_REGISTERS_GPIO_OUTPUT_LOW,
6688 port);
6689 } else {
6690 bnx2x_cl45_write(bp, phy,
6691 MDIO_PMA_DEVAD,
6692 MDIO_PMA_REG_CTRL, 0x800);
6693 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006694}
6695
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006696static void bnx2x_848xx_set_link_led(struct bnx2x_phy *phy,
6697 struct link_params *params, u8 mode)
6698{
6699 struct bnx2x *bp = params->bp;
6700 u16 val;
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00006701 u8 port;
6702
6703 if (!(CHIP_IS_E1(bp)))
6704 port = BP_PATH(bp);
6705 else
6706 port = params->port;
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006707
6708 switch (mode) {
6709 case LED_MODE_OFF:
6710
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00006711 DP(NETIF_MSG_LINK, "Port 0x%x: LED MODE OFF\n", port);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006712
6713 if ((params->hw_led_mode << SHARED_HW_CFG_LED_MODE_SHIFT) ==
6714 SHARED_HW_CFG_LED_EXTPHY1) {
6715
6716 /* Set LED masks */
6717 bnx2x_cl45_write(bp, phy,
6718 MDIO_PMA_DEVAD,
6719 MDIO_PMA_REG_8481_LED1_MASK,
6720 0x0);
6721
6722 bnx2x_cl45_write(bp, phy,
6723 MDIO_PMA_DEVAD,
6724 MDIO_PMA_REG_8481_LED2_MASK,
6725 0x0);
6726
6727 bnx2x_cl45_write(bp, phy,
6728 MDIO_PMA_DEVAD,
6729 MDIO_PMA_REG_8481_LED3_MASK,
6730 0x0);
6731
6732 bnx2x_cl45_write(bp, phy,
6733 MDIO_PMA_DEVAD,
6734 MDIO_PMA_REG_8481_LED5_MASK,
6735 0x0);
6736
6737 } else {
6738 bnx2x_cl45_write(bp, phy,
6739 MDIO_PMA_DEVAD,
6740 MDIO_PMA_REG_8481_LED1_MASK,
6741 0x0);
6742 }
6743 break;
6744 case LED_MODE_FRONT_PANEL_OFF:
6745
6746 DP(NETIF_MSG_LINK, "Port 0x%x: LED MODE FRONT PANEL OFF\n",
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00006747 port);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006748
6749 if ((params->hw_led_mode << SHARED_HW_CFG_LED_MODE_SHIFT) ==
6750 SHARED_HW_CFG_LED_EXTPHY1) {
6751
6752 /* Set LED masks */
6753 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006754 MDIO_PMA_DEVAD,
6755 MDIO_PMA_REG_8481_LED1_MASK,
6756 0x0);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006757
6758 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006759 MDIO_PMA_DEVAD,
6760 MDIO_PMA_REG_8481_LED2_MASK,
6761 0x0);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006762
6763 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006764 MDIO_PMA_DEVAD,
6765 MDIO_PMA_REG_8481_LED3_MASK,
6766 0x0);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006767
6768 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006769 MDIO_PMA_DEVAD,
6770 MDIO_PMA_REG_8481_LED5_MASK,
6771 0x20);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006772
6773 } else {
6774 bnx2x_cl45_write(bp, phy,
6775 MDIO_PMA_DEVAD,
6776 MDIO_PMA_REG_8481_LED1_MASK,
6777 0x0);
6778 }
6779 break;
6780 case LED_MODE_ON:
6781
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00006782 DP(NETIF_MSG_LINK, "Port 0x%x: LED MODE ON\n", port);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006783
6784 if ((params->hw_led_mode << SHARED_HW_CFG_LED_MODE_SHIFT) ==
6785 SHARED_HW_CFG_LED_EXTPHY1) {
6786 /* Set control reg */
6787 bnx2x_cl45_read(bp, phy,
6788 MDIO_PMA_DEVAD,
6789 MDIO_PMA_REG_8481_LINK_SIGNAL,
6790 &val);
6791 val &= 0x8000;
6792 val |= 0x2492;
6793
6794 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006795 MDIO_PMA_DEVAD,
6796 MDIO_PMA_REG_8481_LINK_SIGNAL,
6797 val);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006798
6799 /* Set LED masks */
6800 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006801 MDIO_PMA_DEVAD,
6802 MDIO_PMA_REG_8481_LED1_MASK,
6803 0x0);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006804
6805 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006806 MDIO_PMA_DEVAD,
6807 MDIO_PMA_REG_8481_LED2_MASK,
6808 0x20);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006809
6810 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006811 MDIO_PMA_DEVAD,
6812 MDIO_PMA_REG_8481_LED3_MASK,
6813 0x20);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006814
6815 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006816 MDIO_PMA_DEVAD,
6817 MDIO_PMA_REG_8481_LED5_MASK,
6818 0x0);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006819 } else {
6820 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006821 MDIO_PMA_DEVAD,
6822 MDIO_PMA_REG_8481_LED1_MASK,
6823 0x20);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006824 }
6825 break;
6826
6827 case LED_MODE_OPER:
6828
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00006829 DP(NETIF_MSG_LINK, "Port 0x%x: LED MODE OPER\n", port);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006830
6831 if ((params->hw_led_mode << SHARED_HW_CFG_LED_MODE_SHIFT) ==
6832 SHARED_HW_CFG_LED_EXTPHY1) {
6833
6834 /* Set control reg */
6835 bnx2x_cl45_read(bp, phy,
6836 MDIO_PMA_DEVAD,
6837 MDIO_PMA_REG_8481_LINK_SIGNAL,
6838 &val);
6839
6840 if (!((val &
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006841 MDIO_PMA_REG_8481_LINK_SIGNAL_LED4_ENABLE_MASK)
6842 >> MDIO_PMA_REG_8481_LINK_SIGNAL_LED4_ENABLE_SHIFT)) {
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006843 DP(NETIF_MSG_LINK, "Setting LINK_SIGNAL\n");
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006844 bnx2x_cl45_write(bp, phy,
6845 MDIO_PMA_DEVAD,
6846 MDIO_PMA_REG_8481_LINK_SIGNAL,
6847 0xa492);
6848 }
6849
6850 /* Set LED masks */
6851 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006852 MDIO_PMA_DEVAD,
6853 MDIO_PMA_REG_8481_LED1_MASK,
6854 0x10);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006855
6856 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006857 MDIO_PMA_DEVAD,
6858 MDIO_PMA_REG_8481_LED2_MASK,
6859 0x80);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006860
6861 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006862 MDIO_PMA_DEVAD,
6863 MDIO_PMA_REG_8481_LED3_MASK,
6864 0x98);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006865
6866 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006867 MDIO_PMA_DEVAD,
6868 MDIO_PMA_REG_8481_LED5_MASK,
6869 0x40);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006870
6871 } else {
6872 bnx2x_cl45_write(bp, phy,
6873 MDIO_PMA_DEVAD,
6874 MDIO_PMA_REG_8481_LED1_MASK,
6875 0x80);
Yaniv Rosner53eda062011-01-30 04:14:55 +00006876
6877 /* Tell LED3 to blink on source */
6878 bnx2x_cl45_read(bp, phy,
6879 MDIO_PMA_DEVAD,
6880 MDIO_PMA_REG_8481_LINK_SIGNAL,
6881 &val);
6882 val &= ~(7<<6);
6883 val |= (1<<6); /* A83B[8:6]= 1 */
6884 bnx2x_cl45_write(bp, phy,
6885 MDIO_PMA_DEVAD,
6886 MDIO_PMA_REG_8481_LINK_SIGNAL,
6887 val);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006888 }
6889 break;
6890 }
6891}
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006892/******************************************************************/
6893/* SFX7101 PHY SECTION */
6894/******************************************************************/
6895static void bnx2x_7101_config_loopback(struct bnx2x_phy *phy,
6896 struct link_params *params)
6897{
6898 struct bnx2x *bp = params->bp;
6899 /* SFX7101_XGXS_TEST1 */
6900 bnx2x_cl45_write(bp, phy,
6901 MDIO_XS_DEVAD, MDIO_XS_SFX7101_XGXS_TEST1, 0x100);
6902}
6903
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006904static int bnx2x_7101_config_init(struct bnx2x_phy *phy,
6905 struct link_params *params,
6906 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006907{
6908 u16 fw_ver1, fw_ver2, val;
6909 struct bnx2x *bp = params->bp;
6910 DP(NETIF_MSG_LINK, "Setting the SFX7101 LASI indication\n");
6911
6912 /* Restore normal power mode*/
6913 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006914 MISC_REGISTERS_GPIO_OUTPUT_HIGH, params->port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006915 /* HW reset */
6916 bnx2x_ext_phy_hw_reset(bp, params->port);
Yaniv Rosner6d870c32011-01-31 04:22:20 +00006917 bnx2x_wait_reset_complete(bp, phy, params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006918
6919 bnx2x_cl45_write(bp, phy,
6920 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_CTRL, 0x1);
6921 DP(NETIF_MSG_LINK, "Setting the SFX7101 LED to blink on traffic\n");
6922 bnx2x_cl45_write(bp, phy,
6923 MDIO_PMA_DEVAD, MDIO_PMA_REG_7107_LED_CNTL, (1<<3));
6924
6925 bnx2x_ext_phy_set_pause(params, phy, vars);
6926 /* Restart autoneg */
6927 bnx2x_cl45_read(bp, phy,
6928 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, &val);
6929 val |= 0x200;
6930 bnx2x_cl45_write(bp, phy,
6931 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, val);
6932
6933 /* Save spirom version */
6934 bnx2x_cl45_read(bp, phy,
6935 MDIO_PMA_DEVAD, MDIO_PMA_REG_7101_VER1, &fw_ver1);
6936
6937 bnx2x_cl45_read(bp, phy,
6938 MDIO_PMA_DEVAD, MDIO_PMA_REG_7101_VER2, &fw_ver2);
6939 bnx2x_save_spirom_version(bp, params->port,
6940 (u32)(fw_ver1<<16 | fw_ver2), phy->ver_addr);
6941 return 0;
6942}
6943
6944static u8 bnx2x_7101_read_status(struct bnx2x_phy *phy,
6945 struct link_params *params,
6946 struct link_vars *vars)
6947{
6948 struct bnx2x *bp = params->bp;
6949 u8 link_up;
6950 u16 val1, val2;
6951 bnx2x_cl45_read(bp, phy,
6952 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_STATUS, &val2);
6953 bnx2x_cl45_read(bp, phy,
6954 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_STATUS, &val1);
6955 DP(NETIF_MSG_LINK, "10G-base-T LASI status 0x%x->0x%x\n",
6956 val2, val1);
6957 bnx2x_cl45_read(bp, phy,
6958 MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val2);
6959 bnx2x_cl45_read(bp, phy,
6960 MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val1);
6961 DP(NETIF_MSG_LINK, "10G-base-T PMA status 0x%x->0x%x\n",
6962 val2, val1);
6963 link_up = ((val1 & 4) == 4);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006964 /* if link is up print the AN outcome of the SFX7101 PHY */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006965 if (link_up) {
6966 bnx2x_cl45_read(bp, phy,
6967 MDIO_AN_DEVAD, MDIO_AN_REG_MASTER_STATUS,
6968 &val2);
6969 vars->line_speed = SPEED_10000;
Yaniv Rosner791f18c2011-01-18 04:33:42 +00006970 vars->duplex = DUPLEX_FULL;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006971 DP(NETIF_MSG_LINK, "SFX7101 AN status 0x%x->Master=%x\n",
6972 val2, (val2 & (1<<14)));
6973 bnx2x_ext_phy_10G_an_resolve(bp, phy, vars);
6974 bnx2x_ext_phy_resolve_fc(phy, params, vars);
6975 }
6976 return link_up;
6977}
6978
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006979static int bnx2x_7101_format_ver(u32 spirom_ver, u8 *str, u16 *len)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006980{
6981 if (*len < 5)
6982 return -EINVAL;
6983 str[0] = (spirom_ver & 0xFF);
6984 str[1] = (spirom_ver & 0xFF00) >> 8;
6985 str[2] = (spirom_ver & 0xFF0000) >> 16;
6986 str[3] = (spirom_ver & 0xFF000000) >> 24;
6987 str[4] = '\0';
6988 *len -= 5;
6989 return 0;
6990}
6991
6992void bnx2x_sfx7101_sp_sw_reset(struct bnx2x *bp, struct bnx2x_phy *phy)
6993{
6994 u16 val, cnt;
6995
6996 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006997 MDIO_PMA_DEVAD,
6998 MDIO_PMA_REG_7101_RESET, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006999
7000 for (cnt = 0; cnt < 10; cnt++) {
7001 msleep(50);
7002 /* Writes a self-clearing reset */
7003 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007004 MDIO_PMA_DEVAD,
7005 MDIO_PMA_REG_7101_RESET,
7006 (val | (1<<15)));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007007 /* Wait for clear */
7008 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007009 MDIO_PMA_DEVAD,
7010 MDIO_PMA_REG_7101_RESET, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007011
7012 if ((val & (1<<15)) == 0)
7013 break;
7014 }
7015}
7016
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007017static void bnx2x_7101_hw_reset(struct bnx2x_phy *phy,
7018 struct link_params *params) {
7019 /* Low power mode is controlled by GPIO 2 */
7020 bnx2x_set_gpio(params->bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007021 MISC_REGISTERS_GPIO_OUTPUT_LOW, params->port);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007022 /* The PHY reset is controlled by GPIO 1 */
7023 bnx2x_set_gpio(params->bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007024 MISC_REGISTERS_GPIO_OUTPUT_LOW, params->port);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007025}
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007026
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00007027static void bnx2x_7101_set_link_led(struct bnx2x_phy *phy,
7028 struct link_params *params, u8 mode)
7029{
7030 u16 val = 0;
7031 struct bnx2x *bp = params->bp;
7032 switch (mode) {
7033 case LED_MODE_FRONT_PANEL_OFF:
7034 case LED_MODE_OFF:
7035 val = 2;
7036 break;
7037 case LED_MODE_ON:
7038 val = 1;
7039 break;
7040 case LED_MODE_OPER:
7041 val = 0;
7042 break;
7043 }
7044 bnx2x_cl45_write(bp, phy,
7045 MDIO_PMA_DEVAD,
7046 MDIO_PMA_REG_7107_LINK_LED_CNTL,
7047 val);
7048}
7049
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007050/******************************************************************/
7051/* STATIC PHY DECLARATION */
7052/******************************************************************/
7053
7054static struct bnx2x_phy phy_null = {
7055 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN,
7056 .addr = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007057 .def_md_devad = 0,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00007058 .flags = FLAGS_INIT_XGXS_FIRST,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007059 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
7060 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
7061 .mdio_ctrl = 0,
7062 .supported = 0,
7063 .media_type = ETH_PHY_NOT_PRESENT,
7064 .ver_addr = 0,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007065 .req_flow_ctrl = 0,
7066 .req_line_speed = 0,
7067 .speed_cap_mask = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007068 .req_duplex = 0,
7069 .rsrv = 0,
7070 .config_init = (config_init_t)NULL,
7071 .read_status = (read_status_t)NULL,
7072 .link_reset = (link_reset_t)NULL,
7073 .config_loopback = (config_loopback_t)NULL,
7074 .format_fw_ver = (format_fw_ver_t)NULL,
7075 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007076 .set_link_led = (set_link_led_t)NULL,
7077 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007078};
7079
7080static struct bnx2x_phy phy_serdes = {
7081 .type = PORT_HW_CFG_SERDES_EXT_PHY_TYPE_DIRECT,
7082 .addr = 0xff,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007083 .def_md_devad = 0,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00007084 .flags = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007085 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
7086 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
7087 .mdio_ctrl = 0,
7088 .supported = (SUPPORTED_10baseT_Half |
7089 SUPPORTED_10baseT_Full |
7090 SUPPORTED_100baseT_Half |
7091 SUPPORTED_100baseT_Full |
7092 SUPPORTED_1000baseT_Full |
7093 SUPPORTED_2500baseX_Full |
7094 SUPPORTED_TP |
7095 SUPPORTED_Autoneg |
7096 SUPPORTED_Pause |
7097 SUPPORTED_Asym_Pause),
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00007098 .media_type = ETH_PHY_BASE_T,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007099 .ver_addr = 0,
7100 .req_flow_ctrl = 0,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007101 .req_line_speed = 0,
7102 .speed_cap_mask = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007103 .req_duplex = 0,
7104 .rsrv = 0,
Yaniv Rosnerec146a62011-05-31 21:29:27 +00007105 .config_init = (config_init_t)bnx2x_xgxs_config_init,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007106 .read_status = (read_status_t)bnx2x_link_settings_status,
7107 .link_reset = (link_reset_t)bnx2x_int_link_reset,
7108 .config_loopback = (config_loopback_t)NULL,
7109 .format_fw_ver = (format_fw_ver_t)NULL,
7110 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007111 .set_link_led = (set_link_led_t)NULL,
7112 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007113};
7114
7115static struct bnx2x_phy phy_xgxs = {
7116 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT,
7117 .addr = 0xff,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007118 .def_md_devad = 0,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00007119 .flags = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007120 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
7121 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
7122 .mdio_ctrl = 0,
7123 .supported = (SUPPORTED_10baseT_Half |
7124 SUPPORTED_10baseT_Full |
7125 SUPPORTED_100baseT_Half |
7126 SUPPORTED_100baseT_Full |
7127 SUPPORTED_1000baseT_Full |
7128 SUPPORTED_2500baseX_Full |
7129 SUPPORTED_10000baseT_Full |
7130 SUPPORTED_FIBRE |
7131 SUPPORTED_Autoneg |
7132 SUPPORTED_Pause |
7133 SUPPORTED_Asym_Pause),
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00007134 .media_type = ETH_PHY_CX4,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007135 .ver_addr = 0,
7136 .req_flow_ctrl = 0,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007137 .req_line_speed = 0,
7138 .speed_cap_mask = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007139 .req_duplex = 0,
7140 .rsrv = 0,
Yaniv Rosnerec146a62011-05-31 21:29:27 +00007141 .config_init = (config_init_t)bnx2x_xgxs_config_init,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007142 .read_status = (read_status_t)bnx2x_link_settings_status,
7143 .link_reset = (link_reset_t)bnx2x_int_link_reset,
7144 .config_loopback = (config_loopback_t)bnx2x_set_xgxs_loopback,
7145 .format_fw_ver = (format_fw_ver_t)NULL,
7146 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007147 .set_link_led = (set_link_led_t)NULL,
7148 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007149};
7150
7151static struct bnx2x_phy phy_7101 = {
7152 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101,
7153 .addr = 0xff,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007154 .def_md_devad = 0,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00007155 .flags = FLAGS_FAN_FAILURE_DET_REQ,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007156 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
7157 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
7158 .mdio_ctrl = 0,
7159 .supported = (SUPPORTED_10000baseT_Full |
7160 SUPPORTED_TP |
7161 SUPPORTED_Autoneg |
7162 SUPPORTED_Pause |
7163 SUPPORTED_Asym_Pause),
7164 .media_type = ETH_PHY_BASE_T,
7165 .ver_addr = 0,
7166 .req_flow_ctrl = 0,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007167 .req_line_speed = 0,
7168 .speed_cap_mask = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007169 .req_duplex = 0,
7170 .rsrv = 0,
7171 .config_init = (config_init_t)bnx2x_7101_config_init,
7172 .read_status = (read_status_t)bnx2x_7101_read_status,
7173 .link_reset = (link_reset_t)bnx2x_common_ext_link_reset,
7174 .config_loopback = (config_loopback_t)bnx2x_7101_config_loopback,
7175 .format_fw_ver = (format_fw_ver_t)bnx2x_7101_format_ver,
7176 .hw_reset = (hw_reset_t)bnx2x_7101_hw_reset,
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00007177 .set_link_led = (set_link_led_t)bnx2x_7101_set_link_led,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007178 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007179};
7180static struct bnx2x_phy phy_8073 = {
7181 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073,
7182 .addr = 0xff,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007183 .def_md_devad = 0,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00007184 .flags = FLAGS_HW_LOCK_REQUIRED,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007185 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
7186 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
7187 .mdio_ctrl = 0,
7188 .supported = (SUPPORTED_10000baseT_Full |
7189 SUPPORTED_2500baseX_Full |
7190 SUPPORTED_1000baseT_Full |
7191 SUPPORTED_FIBRE |
7192 SUPPORTED_Autoneg |
7193 SUPPORTED_Pause |
7194 SUPPORTED_Asym_Pause),
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00007195 .media_type = ETH_PHY_KR,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007196 .ver_addr = 0,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007197 .req_flow_ctrl = 0,
7198 .req_line_speed = 0,
7199 .speed_cap_mask = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007200 .req_duplex = 0,
7201 .rsrv = 0,
Yaniv Rosner62b29a52010-09-07 11:40:58 +00007202 .config_init = (config_init_t)bnx2x_8073_config_init,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007203 .read_status = (read_status_t)bnx2x_8073_read_status,
7204 .link_reset = (link_reset_t)bnx2x_8073_link_reset,
7205 .config_loopback = (config_loopback_t)NULL,
7206 .format_fw_ver = (format_fw_ver_t)bnx2x_format_ver,
7207 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007208 .set_link_led = (set_link_led_t)NULL,
7209 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007210};
7211static struct bnx2x_phy phy_8705 = {
7212 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705,
7213 .addr = 0xff,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007214 .def_md_devad = 0,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00007215 .flags = FLAGS_INIT_XGXS_FIRST,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007216 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
7217 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
7218 .mdio_ctrl = 0,
7219 .supported = (SUPPORTED_10000baseT_Full |
7220 SUPPORTED_FIBRE |
7221 SUPPORTED_Pause |
7222 SUPPORTED_Asym_Pause),
7223 .media_type = ETH_PHY_XFP_FIBER,
7224 .ver_addr = 0,
7225 .req_flow_ctrl = 0,
7226 .req_line_speed = 0,
7227 .speed_cap_mask = 0,
7228 .req_duplex = 0,
7229 .rsrv = 0,
7230 .config_init = (config_init_t)bnx2x_8705_config_init,
7231 .read_status = (read_status_t)bnx2x_8705_read_status,
7232 .link_reset = (link_reset_t)bnx2x_common_ext_link_reset,
7233 .config_loopback = (config_loopback_t)NULL,
7234 .format_fw_ver = (format_fw_ver_t)bnx2x_null_format_ver,
7235 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007236 .set_link_led = (set_link_led_t)NULL,
7237 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007238};
7239static struct bnx2x_phy phy_8706 = {
7240 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706,
7241 .addr = 0xff,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007242 .def_md_devad = 0,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00007243 .flags = FLAGS_INIT_XGXS_FIRST,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007244 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
7245 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
7246 .mdio_ctrl = 0,
7247 .supported = (SUPPORTED_10000baseT_Full |
7248 SUPPORTED_1000baseT_Full |
7249 SUPPORTED_FIBRE |
7250 SUPPORTED_Pause |
7251 SUPPORTED_Asym_Pause),
7252 .media_type = ETH_PHY_SFP_FIBER,
7253 .ver_addr = 0,
7254 .req_flow_ctrl = 0,
7255 .req_line_speed = 0,
7256 .speed_cap_mask = 0,
7257 .req_duplex = 0,
7258 .rsrv = 0,
7259 .config_init = (config_init_t)bnx2x_8706_config_init,
7260 .read_status = (read_status_t)bnx2x_8706_read_status,
7261 .link_reset = (link_reset_t)bnx2x_common_ext_link_reset,
7262 .config_loopback = (config_loopback_t)NULL,
7263 .format_fw_ver = (format_fw_ver_t)bnx2x_format_ver,
7264 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007265 .set_link_led = (set_link_led_t)NULL,
7266 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007267};
7268
7269static struct bnx2x_phy phy_8726 = {
7270 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726,
7271 .addr = 0xff,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00007272 .def_md_devad = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007273 .flags = (FLAGS_HW_LOCK_REQUIRED |
7274 FLAGS_INIT_XGXS_FIRST),
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007275 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
7276 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
7277 .mdio_ctrl = 0,
7278 .supported = (SUPPORTED_10000baseT_Full |
7279 SUPPORTED_1000baseT_Full |
7280 SUPPORTED_Autoneg |
7281 SUPPORTED_FIBRE |
7282 SUPPORTED_Pause |
7283 SUPPORTED_Asym_Pause),
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00007284 .media_type = ETH_PHY_NOT_PRESENT,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007285 .ver_addr = 0,
7286 .req_flow_ctrl = 0,
7287 .req_line_speed = 0,
7288 .speed_cap_mask = 0,
7289 .req_duplex = 0,
7290 .rsrv = 0,
7291 .config_init = (config_init_t)bnx2x_8726_config_init,
7292 .read_status = (read_status_t)bnx2x_8726_read_status,
7293 .link_reset = (link_reset_t)bnx2x_8726_link_reset,
7294 .config_loopback = (config_loopback_t)bnx2x_8726_config_loopback,
7295 .format_fw_ver = (format_fw_ver_t)bnx2x_format_ver,
7296 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007297 .set_link_led = (set_link_led_t)NULL,
7298 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007299};
7300
7301static struct bnx2x_phy phy_8727 = {
7302 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727,
7303 .addr = 0xff,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007304 .def_md_devad = 0,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00007305 .flags = FLAGS_FAN_FAILURE_DET_REQ,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007306 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
7307 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
7308 .mdio_ctrl = 0,
7309 .supported = (SUPPORTED_10000baseT_Full |
7310 SUPPORTED_1000baseT_Full |
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007311 SUPPORTED_FIBRE |
7312 SUPPORTED_Pause |
7313 SUPPORTED_Asym_Pause),
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00007314 .media_type = ETH_PHY_NOT_PRESENT,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007315 .ver_addr = 0,
7316 .req_flow_ctrl = 0,
7317 .req_line_speed = 0,
7318 .speed_cap_mask = 0,
7319 .req_duplex = 0,
7320 .rsrv = 0,
7321 .config_init = (config_init_t)bnx2x_8727_config_init,
7322 .read_status = (read_status_t)bnx2x_8727_read_status,
7323 .link_reset = (link_reset_t)bnx2x_8727_link_reset,
7324 .config_loopback = (config_loopback_t)NULL,
7325 .format_fw_ver = (format_fw_ver_t)bnx2x_format_ver,
7326 .hw_reset = (hw_reset_t)bnx2x_8727_hw_reset,
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00007327 .set_link_led = (set_link_led_t)bnx2x_8727_set_link_led,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007328 .phy_specific_func = (phy_specific_func_t)bnx2x_8727_specific_func
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007329};
7330static struct bnx2x_phy phy_8481 = {
7331 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8481,
7332 .addr = 0xff,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00007333 .def_md_devad = 0,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007334 .flags = FLAGS_FAN_FAILURE_DET_REQ |
7335 FLAGS_REARM_LATCH_SIGNAL,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007336 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
7337 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
7338 .mdio_ctrl = 0,
7339 .supported = (SUPPORTED_10baseT_Half |
7340 SUPPORTED_10baseT_Full |
7341 SUPPORTED_100baseT_Half |
7342 SUPPORTED_100baseT_Full |
7343 SUPPORTED_1000baseT_Full |
7344 SUPPORTED_10000baseT_Full |
7345 SUPPORTED_TP |
7346 SUPPORTED_Autoneg |
7347 SUPPORTED_Pause |
7348 SUPPORTED_Asym_Pause),
7349 .media_type = ETH_PHY_BASE_T,
7350 .ver_addr = 0,
7351 .req_flow_ctrl = 0,
7352 .req_line_speed = 0,
7353 .speed_cap_mask = 0,
7354 .req_duplex = 0,
7355 .rsrv = 0,
7356 .config_init = (config_init_t)bnx2x_8481_config_init,
7357 .read_status = (read_status_t)bnx2x_848xx_read_status,
7358 .link_reset = (link_reset_t)bnx2x_8481_link_reset,
7359 .config_loopback = (config_loopback_t)NULL,
7360 .format_fw_ver = (format_fw_ver_t)bnx2x_848xx_format_ver,
7361 .hw_reset = (hw_reset_t)bnx2x_8481_hw_reset,
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00007362 .set_link_led = (set_link_led_t)bnx2x_848xx_set_link_led,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007363 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007364};
7365
7366static struct bnx2x_phy phy_84823 = {
7367 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84823,
7368 .addr = 0xff,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00007369 .def_md_devad = 0,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007370 .flags = FLAGS_FAN_FAILURE_DET_REQ |
7371 FLAGS_REARM_LATCH_SIGNAL,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007372 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
7373 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
7374 .mdio_ctrl = 0,
7375 .supported = (SUPPORTED_10baseT_Half |
7376 SUPPORTED_10baseT_Full |
7377 SUPPORTED_100baseT_Half |
7378 SUPPORTED_100baseT_Full |
7379 SUPPORTED_1000baseT_Full |
7380 SUPPORTED_10000baseT_Full |
7381 SUPPORTED_TP |
7382 SUPPORTED_Autoneg |
7383 SUPPORTED_Pause |
7384 SUPPORTED_Asym_Pause),
7385 .media_type = ETH_PHY_BASE_T,
7386 .ver_addr = 0,
7387 .req_flow_ctrl = 0,
7388 .req_line_speed = 0,
7389 .speed_cap_mask = 0,
7390 .req_duplex = 0,
7391 .rsrv = 0,
7392 .config_init = (config_init_t)bnx2x_848x3_config_init,
7393 .read_status = (read_status_t)bnx2x_848xx_read_status,
7394 .link_reset = (link_reset_t)bnx2x_848x3_link_reset,
7395 .config_loopback = (config_loopback_t)NULL,
7396 .format_fw_ver = (format_fw_ver_t)bnx2x_848xx_format_ver,
7397 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00007398 .set_link_led = (set_link_led_t)bnx2x_848xx_set_link_led,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007399 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007400};
7401
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00007402static struct bnx2x_phy phy_84833 = {
7403 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833,
7404 .addr = 0xff,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00007405 .def_md_devad = 0,
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00007406 .flags = FLAGS_FAN_FAILURE_DET_REQ |
7407 FLAGS_REARM_LATCH_SIGNAL,
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00007408 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
7409 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
7410 .mdio_ctrl = 0,
7411 .supported = (SUPPORTED_10baseT_Half |
7412 SUPPORTED_10baseT_Full |
7413 SUPPORTED_100baseT_Half |
7414 SUPPORTED_100baseT_Full |
7415 SUPPORTED_1000baseT_Full |
7416 SUPPORTED_10000baseT_Full |
7417 SUPPORTED_TP |
7418 SUPPORTED_Autoneg |
7419 SUPPORTED_Pause |
7420 SUPPORTED_Asym_Pause),
7421 .media_type = ETH_PHY_BASE_T,
7422 .ver_addr = 0,
7423 .req_flow_ctrl = 0,
7424 .req_line_speed = 0,
7425 .speed_cap_mask = 0,
7426 .req_duplex = 0,
7427 .rsrv = 0,
7428 .config_init = (config_init_t)bnx2x_848x3_config_init,
7429 .read_status = (read_status_t)bnx2x_848xx_read_status,
7430 .link_reset = (link_reset_t)bnx2x_848x3_link_reset,
7431 .config_loopback = (config_loopback_t)NULL,
7432 .format_fw_ver = (format_fw_ver_t)bnx2x_848xx_format_ver,
7433 .hw_reset = (hw_reset_t)NULL,
7434 .set_link_led = (set_link_led_t)bnx2x_848xx_set_link_led,
7435 .phy_specific_func = (phy_specific_func_t)NULL
7436};
7437
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007438/*****************************************************************/
7439/* */
7440/* Populate the phy according. Main function: bnx2x_populate_phy */
7441/* */
7442/*****************************************************************/
7443
7444static void bnx2x_populate_preemphasis(struct bnx2x *bp, u32 shmem_base,
7445 struct bnx2x_phy *phy, u8 port,
7446 u8 phy_index)
7447{
7448 /* Get the 4 lanes xgxs config rx and tx */
7449 u32 rx = 0, tx = 0, i;
7450 for (i = 0; i < 2; i++) {
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007451 /*
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007452 * INT_PHY and EXT_PHY1 share the same value location in the
7453 * shmem. When num_phys is greater than 1, than this value
7454 * applies only to EXT_PHY1
7455 */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007456 if (phy_index == INT_PHY || phy_index == EXT_PHY1) {
7457 rx = REG_RD(bp, shmem_base +
7458 offsetof(struct shmem_region,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007459 dev_info.port_hw_config[port].xgxs_config_rx[i<<1]));
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007460
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007461 tx = REG_RD(bp, shmem_base +
7462 offsetof(struct shmem_region,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007463 dev_info.port_hw_config[port].xgxs_config_tx[i<<1]));
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007464 } else {
7465 rx = REG_RD(bp, shmem_base +
7466 offsetof(struct shmem_region,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007467 dev_info.port_hw_config[port].xgxs_config2_rx[i<<1]));
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007468
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007469 tx = REG_RD(bp, shmem_base +
7470 offsetof(struct shmem_region,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007471 dev_info.port_hw_config[port].xgxs_config2_rx[i<<1]));
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007472 }
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007473
7474 phy->rx_preemphasis[i << 1] = ((rx>>16) & 0xffff);
7475 phy->rx_preemphasis[(i << 1) + 1] = (rx & 0xffff);
7476
7477 phy->tx_preemphasis[i << 1] = ((tx>>16) & 0xffff);
7478 phy->tx_preemphasis[(i << 1) + 1] = (tx & 0xffff);
7479 }
7480}
7481
Yaniv Rosnere10bc842010-09-07 11:40:50 +00007482static u32 bnx2x_get_ext_phy_config(struct bnx2x *bp, u32 shmem_base,
7483 u8 phy_index, u8 port)
7484{
7485 u32 ext_phy_config = 0;
7486 switch (phy_index) {
7487 case EXT_PHY1:
7488 ext_phy_config = REG_RD(bp, shmem_base +
7489 offsetof(struct shmem_region,
7490 dev_info.port_hw_config[port].external_phy_config));
7491 break;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007492 case EXT_PHY2:
7493 ext_phy_config = REG_RD(bp, shmem_base +
7494 offsetof(struct shmem_region,
7495 dev_info.port_hw_config[port].external_phy_config2));
7496 break;
Yaniv Rosnere10bc842010-09-07 11:40:50 +00007497 default:
7498 DP(NETIF_MSG_LINK, "Invalid phy_index %d\n", phy_index);
7499 return -EINVAL;
7500 }
7501
7502 return ext_phy_config;
7503}
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00007504static int bnx2x_populate_int_phy(struct bnx2x *bp, u32 shmem_base, u8 port,
7505 struct bnx2x_phy *phy)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007506{
7507 u32 phy_addr;
7508 u32 chip_id;
7509 u32 switch_cfg = (REG_RD(bp, shmem_base +
7510 offsetof(struct shmem_region,
7511 dev_info.port_feature_config[port].link_config)) &
7512 PORT_FEATURE_CONNECTED_SWITCH_MASK);
7513 chip_id = REG_RD(bp, MISC_REG_CHIP_NUM) << 16;
7514 switch (switch_cfg) {
7515 case SWITCH_CFG_1G:
7516 phy_addr = REG_RD(bp,
7517 NIG_REG_SERDES0_CTRL_PHY_ADDR +
7518 port * 0x10);
7519 *phy = phy_serdes;
7520 break;
7521 case SWITCH_CFG_10G:
7522 phy_addr = REG_RD(bp,
7523 NIG_REG_XGXS0_CTRL_PHY_ADDR +
7524 port * 0x18);
7525 *phy = phy_xgxs;
7526 break;
7527 default:
7528 DP(NETIF_MSG_LINK, "Invalid switch_cfg\n");
7529 return -EINVAL;
7530 }
7531 phy->addr = (u8)phy_addr;
7532 phy->mdio_ctrl = bnx2x_get_emac_base(bp,
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00007533 SHARED_HW_CFG_MDC_MDIO_ACCESS1_BOTH,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007534 port);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007535 if (CHIP_IS_E2(bp))
7536 phy->def_md_devad = E2_DEFAULT_PHY_DEV_ADDR;
7537 else
7538 phy->def_md_devad = DEFAULT_PHY_DEV_ADDR;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007539
7540 DP(NETIF_MSG_LINK, "Internal phy port=%d, addr=0x%x, mdio_ctl=0x%x\n",
7541 port, phy->addr, phy->mdio_ctrl);
7542
7543 bnx2x_populate_preemphasis(bp, shmem_base, phy, port, INT_PHY);
7544 return 0;
7545}
Yaniv Rosnere10bc842010-09-07 11:40:50 +00007546
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00007547static int bnx2x_populate_ext_phy(struct bnx2x *bp,
7548 u8 phy_index,
7549 u32 shmem_base,
7550 u32 shmem2_base,
7551 u8 port,
7552 struct bnx2x_phy *phy)
Yaniv Rosnere10bc842010-09-07 11:40:50 +00007553{
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00007554 u32 ext_phy_config, phy_type, config2;
7555 u32 mdc_mdio_access = SHARED_HW_CFG_MDC_MDIO_ACCESS1_BOTH;
Yaniv Rosnere10bc842010-09-07 11:40:50 +00007556 ext_phy_config = bnx2x_get_ext_phy_config(bp, shmem_base,
7557 phy_index, port);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007558 phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
7559 /* Select the phy type */
7560 switch (phy_type) {
7561 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073:
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00007562 mdc_mdio_access = SHARED_HW_CFG_MDC_MDIO_ACCESS1_SWAPPED;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007563 *phy = phy_8073;
7564 break;
7565 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705:
7566 *phy = phy_8705;
7567 break;
7568 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706:
7569 *phy = phy_8706;
7570 break;
7571 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00007572 mdc_mdio_access = SHARED_HW_CFG_MDC_MDIO_ACCESS1_EMAC1;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007573 *phy = phy_8726;
7574 break;
7575 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727_NOC:
7576 /* BCM8727_NOC => BCM8727 no over current */
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00007577 mdc_mdio_access = SHARED_HW_CFG_MDC_MDIO_ACCESS1_EMAC1;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007578 *phy = phy_8727;
7579 phy->flags |= FLAGS_NOC;
7580 break;
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00007581 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8722:
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007582 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00007583 mdc_mdio_access = SHARED_HW_CFG_MDC_MDIO_ACCESS1_EMAC1;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007584 *phy = phy_8727;
7585 break;
7586 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8481:
7587 *phy = phy_8481;
7588 break;
7589 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84823:
7590 *phy = phy_84823;
7591 break;
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00007592 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833:
7593 *phy = phy_84833;
7594 break;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007595 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101:
7596 *phy = phy_7101;
7597 break;
7598 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE:
7599 *phy = phy_null;
7600 return -EINVAL;
7601 default:
7602 *phy = phy_null;
7603 return 0;
7604 }
7605
Yaniv Rosnere10bc842010-09-07 11:40:50 +00007606 phy->addr = XGXS_EXT_PHY_ADDR(ext_phy_config);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007607 bnx2x_populate_preemphasis(bp, shmem_base, phy, port, phy_index);
Yaniv Rosner62b29a52010-09-07 11:40:58 +00007608
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007609 /*
7610 * The shmem address of the phy version is located on different
7611 * structures. In case this structure is too old, do not set
7612 * the address
7613 */
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00007614 config2 = REG_RD(bp, shmem_base + offsetof(struct shmem_region,
7615 dev_info.shared_hw_config.config2));
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007616 if (phy_index == EXT_PHY1) {
7617 phy->ver_addr = shmem_base + offsetof(struct shmem_region,
7618 port_mb[port].ext_phy_fw_version);
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00007619
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007620 /* Check specific mdc mdio settings */
7621 if (config2 & SHARED_HW_CFG_MDC_MDIO_ACCESS1_MASK)
7622 mdc_mdio_access = config2 &
7623 SHARED_HW_CFG_MDC_MDIO_ACCESS1_MASK;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007624 } else {
7625 u32 size = REG_RD(bp, shmem2_base);
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00007626
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007627 if (size >
7628 offsetof(struct shmem2_region, ext_phy_fw_version2)) {
7629 phy->ver_addr = shmem2_base +
7630 offsetof(struct shmem2_region,
7631 ext_phy_fw_version2[port]);
7632 }
7633 /* Check specific mdc mdio settings */
7634 if (config2 & SHARED_HW_CFG_MDC_MDIO_ACCESS2_MASK)
7635 mdc_mdio_access = (config2 &
7636 SHARED_HW_CFG_MDC_MDIO_ACCESS2_MASK) >>
7637 (SHARED_HW_CFG_MDC_MDIO_ACCESS2_SHIFT -
7638 SHARED_HW_CFG_MDC_MDIO_ACCESS1_SHIFT);
7639 }
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00007640 phy->mdio_ctrl = bnx2x_get_emac_base(bp, mdc_mdio_access, port);
7641
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007642 /*
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00007643 * In case mdc/mdio_access of the external phy is different than the
7644 * mdc/mdio access of the XGXS, a HW lock must be taken in each access
7645 * to prevent one port interfere with another port's CL45 operations.
7646 */
7647 if (mdc_mdio_access != SHARED_HW_CFG_MDC_MDIO_ACCESS1_BOTH)
7648 phy->flags |= FLAGS_HW_LOCK_REQUIRED;
7649 DP(NETIF_MSG_LINK, "phy_type 0x%x port %d found in index %d\n",
7650 phy_type, port, phy_index);
7651 DP(NETIF_MSG_LINK, " addr=0x%x, mdio_ctl=0x%x\n",
7652 phy->addr, phy->mdio_ctrl);
Yaniv Rosnere10bc842010-09-07 11:40:50 +00007653 return 0;
7654}
7655
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00007656static int bnx2x_populate_phy(struct bnx2x *bp, u8 phy_index, u32 shmem_base,
7657 u32 shmem2_base, u8 port, struct bnx2x_phy *phy)
Yaniv Rosnere10bc842010-09-07 11:40:50 +00007658{
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00007659 int status = 0;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007660 phy->type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN;
7661 if (phy_index == INT_PHY)
7662 return bnx2x_populate_int_phy(bp, shmem_base, port, phy);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007663 status = bnx2x_populate_ext_phy(bp, phy_index, shmem_base, shmem2_base,
Yaniv Rosnere10bc842010-09-07 11:40:50 +00007664 port, phy);
7665 return status;
7666}
7667
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007668static void bnx2x_phy_def_cfg(struct link_params *params,
7669 struct bnx2x_phy *phy,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007670 u8 phy_index)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007671{
7672 struct bnx2x *bp = params->bp;
7673 u32 link_config;
7674 /* Populate the default phy configuration for MF mode */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007675 if (phy_index == EXT_PHY2) {
7676 link_config = REG_RD(bp, params->shmem_base +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007677 offsetof(struct shmem_region, dev_info.
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007678 port_feature_config[params->port].link_config2));
7679 phy->speed_cap_mask = REG_RD(bp, params->shmem_base +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007680 offsetof(struct shmem_region,
7681 dev_info.
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007682 port_hw_config[params->port].speed_capability_mask2));
7683 } else {
7684 link_config = REG_RD(bp, params->shmem_base +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007685 offsetof(struct shmem_region, dev_info.
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007686 port_feature_config[params->port].link_config));
7687 phy->speed_cap_mask = REG_RD(bp, params->shmem_base +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007688 offsetof(struct shmem_region,
7689 dev_info.
7690 port_hw_config[params->port].speed_capability_mask));
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007691 }
7692 DP(NETIF_MSG_LINK, "Default config phy idx %x cfg 0x%x speed_cap_mask"
7693 " 0x%x\n", phy_index, link_config, phy->speed_cap_mask);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007694
7695 phy->req_duplex = DUPLEX_FULL;
7696 switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
7697 case PORT_FEATURE_LINK_SPEED_10M_HALF:
7698 phy->req_duplex = DUPLEX_HALF;
7699 case PORT_FEATURE_LINK_SPEED_10M_FULL:
7700 phy->req_line_speed = SPEED_10;
7701 break;
7702 case PORT_FEATURE_LINK_SPEED_100M_HALF:
7703 phy->req_duplex = DUPLEX_HALF;
7704 case PORT_FEATURE_LINK_SPEED_100M_FULL:
7705 phy->req_line_speed = SPEED_100;
7706 break;
7707 case PORT_FEATURE_LINK_SPEED_1G:
7708 phy->req_line_speed = SPEED_1000;
7709 break;
7710 case PORT_FEATURE_LINK_SPEED_2_5G:
7711 phy->req_line_speed = SPEED_2500;
7712 break;
7713 case PORT_FEATURE_LINK_SPEED_10G_CX4:
7714 phy->req_line_speed = SPEED_10000;
7715 break;
7716 default:
7717 phy->req_line_speed = SPEED_AUTO_NEG;
7718 break;
7719 }
7720
7721 switch (link_config & PORT_FEATURE_FLOW_CONTROL_MASK) {
7722 case PORT_FEATURE_FLOW_CONTROL_AUTO:
7723 phy->req_flow_ctrl = BNX2X_FLOW_CTRL_AUTO;
7724 break;
7725 case PORT_FEATURE_FLOW_CONTROL_TX:
7726 phy->req_flow_ctrl = BNX2X_FLOW_CTRL_TX;
7727 break;
7728 case PORT_FEATURE_FLOW_CONTROL_RX:
7729 phy->req_flow_ctrl = BNX2X_FLOW_CTRL_RX;
7730 break;
7731 case PORT_FEATURE_FLOW_CONTROL_BOTH:
7732 phy->req_flow_ctrl = BNX2X_FLOW_CTRL_BOTH;
7733 break;
7734 default:
7735 phy->req_flow_ctrl = BNX2X_FLOW_CTRL_NONE;
7736 break;
7737 }
7738}
7739
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007740u32 bnx2x_phy_selection(struct link_params *params)
7741{
7742 u32 phy_config_swapped, prio_cfg;
7743 u32 return_cfg = PORT_HW_CFG_PHY_SELECTION_HARDWARE_DEFAULT;
7744
7745 phy_config_swapped = params->multi_phy_config &
7746 PORT_HW_CFG_PHY_SWAPPED_ENABLED;
7747
7748 prio_cfg = params->multi_phy_config &
7749 PORT_HW_CFG_PHY_SELECTION_MASK;
7750
7751 if (phy_config_swapped) {
7752 switch (prio_cfg) {
7753 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY_PRIORITY:
7754 return_cfg = PORT_HW_CFG_PHY_SELECTION_SECOND_PHY_PRIORITY;
7755 break;
7756 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY_PRIORITY:
7757 return_cfg = PORT_HW_CFG_PHY_SELECTION_FIRST_PHY_PRIORITY;
7758 break;
7759 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY:
7760 return_cfg = PORT_HW_CFG_PHY_SELECTION_FIRST_PHY;
7761 break;
7762 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY:
7763 return_cfg = PORT_HW_CFG_PHY_SELECTION_SECOND_PHY;
7764 break;
7765 }
7766 } else
7767 return_cfg = prio_cfg;
7768
7769 return return_cfg;
7770}
7771
7772
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00007773int bnx2x_phy_probe(struct link_params *params)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007774{
7775 u8 phy_index, actual_phy_idx, link_cfg_idx;
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00007776 u32 phy_config_swapped, sync_offset, media_types;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007777 struct bnx2x *bp = params->bp;
7778 struct bnx2x_phy *phy;
7779 params->num_phys = 0;
7780 DP(NETIF_MSG_LINK, "Begin phy probe\n");
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007781 phy_config_swapped = params->multi_phy_config &
7782 PORT_HW_CFG_PHY_SWAPPED_ENABLED;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007783
7784 for (phy_index = INT_PHY; phy_index < MAX_PHYS;
7785 phy_index++) {
7786 link_cfg_idx = LINK_CONFIG_IDX(phy_index);
7787 actual_phy_idx = phy_index;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007788 if (phy_config_swapped) {
7789 if (phy_index == EXT_PHY1)
7790 actual_phy_idx = EXT_PHY2;
7791 else if (phy_index == EXT_PHY2)
7792 actual_phy_idx = EXT_PHY1;
7793 }
7794 DP(NETIF_MSG_LINK, "phy_config_swapped %x, phy_index %x,"
7795 " actual_phy_idx %x\n", phy_config_swapped,
7796 phy_index, actual_phy_idx);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007797 phy = &params->phy[actual_phy_idx];
7798 if (bnx2x_populate_phy(bp, phy_index, params->shmem_base,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007799 params->shmem2_base, params->port,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007800 phy) != 0) {
7801 params->num_phys = 0;
7802 DP(NETIF_MSG_LINK, "phy probe failed in phy index %d\n",
7803 phy_index);
7804 for (phy_index = INT_PHY;
7805 phy_index < MAX_PHYS;
7806 phy_index++)
7807 *phy = phy_null;
7808 return -EINVAL;
7809 }
7810 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN)
7811 break;
7812
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00007813 sync_offset = params->shmem_base +
7814 offsetof(struct shmem_region,
7815 dev_info.port_hw_config[params->port].media_type);
7816 media_types = REG_RD(bp, sync_offset);
7817
7818 /*
7819 * Update media type for non-PMF sync only for the first time
7820 * In case the media type changes afterwards, it will be updated
7821 * using the update_status function
7822 */
7823 if ((media_types & (PORT_HW_CFG_MEDIA_TYPE_PHY0_MASK <<
7824 (PORT_HW_CFG_MEDIA_TYPE_PHY1_SHIFT *
7825 actual_phy_idx))) == 0) {
7826 media_types |= ((phy->media_type &
7827 PORT_HW_CFG_MEDIA_TYPE_PHY0_MASK) <<
7828 (PORT_HW_CFG_MEDIA_TYPE_PHY1_SHIFT *
7829 actual_phy_idx));
7830 }
7831 REG_WR(bp, sync_offset, media_types);
7832
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007833 bnx2x_phy_def_cfg(params, phy, phy_index);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007834 params->num_phys++;
7835 }
7836
7837 DP(NETIF_MSG_LINK, "End phy probe. #phys found %x\n", params->num_phys);
7838 return 0;
7839}
7840
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00007841void bnx2x_init_bmac_loopback(struct link_params *params,
7842 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007843{
7844 struct bnx2x *bp = params->bp;
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00007845 vars->link_up = 1;
7846 vars->line_speed = SPEED_10000;
7847 vars->duplex = DUPLEX_FULL;
7848 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
7849 vars->mac_type = MAC_TYPE_BMAC;
7850
7851 vars->phy_flags = PHY_XGXS_FLAG;
7852
7853 bnx2x_xgxs_deassert(params);
7854
7855 /* set bmac loopback */
7856 bnx2x_bmac_enable(params, vars, 1);
7857
7858 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 0);
7859}
7860
7861void bnx2x_init_emac_loopback(struct link_params *params,
7862 struct link_vars *vars)
7863{
7864 struct bnx2x *bp = params->bp;
7865 vars->link_up = 1;
7866 vars->line_speed = SPEED_1000;
7867 vars->duplex = DUPLEX_FULL;
7868 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
7869 vars->mac_type = MAC_TYPE_EMAC;
7870
7871 vars->phy_flags = PHY_XGXS_FLAG;
7872
7873 bnx2x_xgxs_deassert(params);
7874 /* set bmac loopback */
7875 bnx2x_emac_enable(params, vars, 1);
7876 bnx2x_emac_program(params, vars);
7877 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 0);
7878}
7879
7880void bnx2x_init_xgxs_loopback(struct link_params *params,
7881 struct link_vars *vars)
7882{
7883 struct bnx2x *bp = params->bp;
7884 vars->link_up = 1;
7885 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
7886 vars->duplex = DUPLEX_FULL;
7887 if (params->req_line_speed[0] == SPEED_1000)
7888 vars->line_speed = SPEED_1000;
7889 else
7890 vars->line_speed = SPEED_10000;
7891
7892
7893 bnx2x_xgxs_deassert(params);
7894 bnx2x_link_initialize(params, vars);
7895
7896 if (params->req_line_speed[0] == SPEED_1000) {
7897 bnx2x_emac_program(params, vars);
7898 bnx2x_emac_enable(params, vars, 0);
7899
7900 } else
7901 bnx2x_bmac_enable(params, vars, 0);
7902
7903
7904 if (params->loopback_mode == LOOPBACK_XGXS) {
7905 /* set 10G XGXS loopback */
7906 params->phy[INT_PHY].config_loopback(
7907 &params->phy[INT_PHY],
7908 params);
7909
7910 } else {
7911 /* set external phy loopback */
7912 u8 phy_index;
7913 for (phy_index = EXT_PHY1;
7914 phy_index < params->num_phys; phy_index++) {
7915 if (params->phy[phy_index].config_loopback)
7916 params->phy[phy_index].config_loopback(
7917 &params->phy[phy_index],
7918 params);
7919 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007920 }
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00007921 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007922
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00007923 bnx2x_set_led(params, vars, LED_MODE_OPER, vars->line_speed);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007924}
7925
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00007926int bnx2x_phy_init(struct link_params *params, struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007927{
7928 struct bnx2x *bp = params->bp;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007929 DP(NETIF_MSG_LINK, "Phy Initialization started\n");
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007930 DP(NETIF_MSG_LINK, "(1) req_speed %d, req_flowctrl %d\n",
7931 params->req_line_speed[0], params->req_flow_ctrl[0]);
7932 DP(NETIF_MSG_LINK, "(2) req_speed %d, req_flowctrl %d\n",
7933 params->req_line_speed[1], params->req_flow_ctrl[1]);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007934 vars->link_status = 0;
7935 vars->phy_link_up = 0;
7936 vars->link_up = 0;
7937 vars->line_speed = 0;
7938 vars->duplex = DUPLEX_FULL;
7939 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
7940 vars->mac_type = MAC_TYPE_NONE;
7941 vars->phy_flags = 0;
7942
7943 /* disable attentions */
7944 bnx2x_bits_dis(bp, NIG_REG_MASK_INTERRUPT_PORT0 + params->port*4,
7945 (NIG_MASK_XGXS0_LINK_STATUS |
7946 NIG_MASK_XGXS0_LINK10G |
7947 NIG_MASK_SERDES0_LINK_STATUS |
7948 NIG_MASK_MI_INT));
7949
7950 bnx2x_emac_init(params, vars);
7951
7952 if (params->num_phys == 0) {
7953 DP(NETIF_MSG_LINK, "No phy found for initialization !!\n");
7954 return -EINVAL;
7955 }
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00007956 set_phy_vars(params, vars);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007957
7958 DP(NETIF_MSG_LINK, "Num of phys on board: %d\n", params->num_phys);
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00007959 switch (params->loopback_mode) {
7960 case LOOPBACK_BMAC:
7961 bnx2x_init_bmac_loopback(params, vars);
7962 break;
7963 case LOOPBACK_EMAC:
7964 bnx2x_init_emac_loopback(params, vars);
7965 break;
7966 case LOOPBACK_XGXS:
7967 case LOOPBACK_EXT_PHY:
7968 bnx2x_init_xgxs_loopback(params, vars);
7969 break;
7970 default:
7971 /* No loopback */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007972 if (params->switch_cfg == SWITCH_CFG_10G)
7973 bnx2x_xgxs_deassert(params);
7974 else
7975 bnx2x_serdes_deassert(bp, params->port);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00007976
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007977 bnx2x_link_initialize(params, vars);
7978 msleep(30);
7979 bnx2x_link_int_enable(params);
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00007980 break;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007981 }
7982 return 0;
7983}
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00007984
7985int bnx2x_link_reset(struct link_params *params, struct link_vars *vars,
7986 u8 reset_ext_phy)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007987{
7988 struct bnx2x *bp = params->bp;
Yaniv Rosnercf1d9722010-11-01 05:32:34 +00007989 u8 phy_index, port = params->port, clear_latch_ind = 0;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007990 DP(NETIF_MSG_LINK, "Resetting the link of port %d\n", port);
7991 /* disable attentions */
7992 vars->link_status = 0;
7993 bnx2x_update_mng(params, vars->link_status);
7994 bnx2x_bits_dis(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007995 (NIG_MASK_XGXS0_LINK_STATUS |
7996 NIG_MASK_XGXS0_LINK10G |
7997 NIG_MASK_SERDES0_LINK_STATUS |
7998 NIG_MASK_MI_INT));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007999
8000 /* activate nig drain */
8001 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + port*4, 1);
8002
8003 /* disable nig egress interface */
8004 REG_WR(bp, NIG_REG_BMAC0_OUT_EN + port*4, 0);
8005 REG_WR(bp, NIG_REG_EGRESS_EMAC0_OUT_EN + port*4, 0);
8006
8007 /* Stop BigMac rx */
8008 bnx2x_bmac_rx_disable(bp, port);
8009
8010 /* disable emac */
8011 REG_WR(bp, NIG_REG_NIG_EMAC0_EN + port*4, 0);
8012
8013 msleep(10);
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008014 /* The PHY reset is controlled by GPIO 1
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008015 * Hold it as vars low
8016 */
8017 /* clear link led */
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00008018 bnx2x_set_led(params, vars, LED_MODE_OFF, 0);
8019
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008020 if (reset_ext_phy) {
8021 for (phy_index = EXT_PHY1; phy_index < params->num_phys;
8022 phy_index++) {
8023 if (params->phy[phy_index].link_reset)
8024 params->phy[phy_index].link_reset(
8025 &params->phy[phy_index],
8026 params);
Yaniv Rosnercf1d9722010-11-01 05:32:34 +00008027 if (params->phy[phy_index].flags &
8028 FLAGS_REARM_LATCH_SIGNAL)
8029 clear_latch_ind = 1;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008030 }
8031 }
8032
Yaniv Rosnercf1d9722010-11-01 05:32:34 +00008033 if (clear_latch_ind) {
8034 /* Clear latching indication */
8035 bnx2x_rearm_latch_signal(bp, port, 0);
8036 bnx2x_bits_dis(bp, NIG_REG_LATCH_BC_0 + port*4,
8037 1 << NIG_LATCH_BC_ENABLE_MI_INT);
8038 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008039 if (params->phy[INT_PHY].link_reset)
8040 params->phy[INT_PHY].link_reset(
8041 &params->phy[INT_PHY], params);
8042 /* reset BigMac */
8043 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
8044 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port));
8045
8046 /* disable nig ingress interface */
8047 REG_WR(bp, NIG_REG_BMAC0_IN_EN + port*4, 0);
8048 REG_WR(bp, NIG_REG_EMAC0_IN_EN + port*4, 0);
8049 REG_WR(bp, NIG_REG_BMAC0_OUT_EN + port*4, 0);
8050 REG_WR(bp, NIG_REG_EGRESS_EMAC0_OUT_EN + port*4, 0);
8051 vars->link_up = 0;
8052 return 0;
8053}
8054
8055/****************************************************************************/
8056/* Common function */
8057/****************************************************************************/
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00008058static int bnx2x_8073_common_init_phy(struct bnx2x *bp,
8059 u32 shmem_base_path[],
8060 u32 shmem2_base_path[], u8 phy_index,
8061 u32 chip_id)
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008062{
Yaniv Rosnere10bc842010-09-07 11:40:50 +00008063 struct bnx2x_phy phy[PORT_MAX];
8064 struct bnx2x_phy *phy_blk[PORT_MAX];
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008065 u16 val;
Yaniv Rosnerc8e64df2011-01-30 04:15:00 +00008066 s8 port = 0;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008067 s8 port_of_path = 0;
Yaniv Rosnerc8e64df2011-01-30 04:15:00 +00008068 u32 swap_val, swap_override;
8069 swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
8070 swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
8071 port ^= (swap_val && swap_override);
8072 bnx2x_ext_phy_hw_reset(bp, port);
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008073 /* PART1 - Reset both phys */
8074 for (port = PORT_MAX - 1; port >= PORT_0; port--) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008075 u32 shmem_base, shmem2_base;
8076 /* In E2, same phy is using for port0 of the two paths */
8077 if (CHIP_IS_E2(bp)) {
8078 shmem_base = shmem_base_path[port];
8079 shmem2_base = shmem2_base_path[port];
8080 port_of_path = 0;
8081 } else {
8082 shmem_base = shmem_base_path[0];
8083 shmem2_base = shmem2_base_path[0];
8084 port_of_path = port;
8085 }
8086
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008087 /* Extract the ext phy address for the port */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008088 if (bnx2x_populate_phy(bp, phy_index, shmem_base, shmem2_base,
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008089 port_of_path, &phy[port]) !=
Yaniv Rosnere10bc842010-09-07 11:40:50 +00008090 0) {
8091 DP(NETIF_MSG_LINK, "populate_phy failed\n");
8092 return -EINVAL;
8093 }
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008094 /* disable attentions */
Yaniv Rosner6a71bbe2010-11-01 05:32:31 +00008095 bnx2x_bits_dis(bp, NIG_REG_MASK_INTERRUPT_PORT0 +
8096 port_of_path*4,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008097 (NIG_MASK_XGXS0_LINK_STATUS |
8098 NIG_MASK_XGXS0_LINK10G |
8099 NIG_MASK_SERDES0_LINK_STATUS |
8100 NIG_MASK_MI_INT));
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008101
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008102 /* Need to take the phy out of low power mode in order
8103 to write to access its registers */
8104 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008105 MISC_REGISTERS_GPIO_OUTPUT_HIGH,
8106 port);
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008107
8108 /* Reset the phy */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00008109 bnx2x_cl45_write(bp, &phy[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008110 MDIO_PMA_DEVAD,
8111 MDIO_PMA_REG_CTRL,
8112 1<<15);
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008113 }
8114
8115 /* Add delay of 150ms after reset */
8116 msleep(150);
8117
Yaniv Rosnere10bc842010-09-07 11:40:50 +00008118 if (phy[PORT_0].addr & 0x1) {
8119 phy_blk[PORT_0] = &(phy[PORT_1]);
8120 phy_blk[PORT_1] = &(phy[PORT_0]);
8121 } else {
8122 phy_blk[PORT_0] = &(phy[PORT_0]);
8123 phy_blk[PORT_1] = &(phy[PORT_1]);
8124 }
8125
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008126 /* PART2 - Download firmware to both phys */
8127 for (port = PORT_MAX - 1; port >= PORT_0; port--) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008128 if (CHIP_IS_E2(bp))
8129 port_of_path = 0;
8130 else
8131 port_of_path = port;
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008132
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008133 DP(NETIF_MSG_LINK, "Loading spirom for phy address 0x%x\n",
8134 phy_blk[port]->addr);
Yaniv Rosner5c99274b2011-01-18 04:33:36 +00008135 if (bnx2x_8073_8727_external_rom_boot(bp, phy_blk[port],
8136 port_of_path))
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008137 return -EINVAL;
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008138
8139 /* Only set bit 10 = 1 (Tx power down) */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00008140 bnx2x_cl45_read(bp, phy_blk[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008141 MDIO_PMA_DEVAD,
8142 MDIO_PMA_REG_TX_POWER_DOWN, &val);
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008143
8144 /* Phase1 of TX_POWER_DOWN reset */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00008145 bnx2x_cl45_write(bp, phy_blk[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008146 MDIO_PMA_DEVAD,
8147 MDIO_PMA_REG_TX_POWER_DOWN,
8148 (val | 1<<10));
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008149 }
8150
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008151 /*
8152 * Toggle Transmitter: Power down and then up with 600ms delay
8153 * between
8154 */
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008155 msleep(600);
8156
8157 /* PART3 - complete TX_POWER_DOWN process, and set GPIO2 back to low */
8158 for (port = PORT_MAX - 1; port >= PORT_0; port--) {
Eilon Greensteinf5372252009-02-12 08:38:30 +00008159 /* Phase2 of POWER_DOWN_RESET */
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008160 /* Release bit 10 (Release Tx power down) */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00008161 bnx2x_cl45_read(bp, phy_blk[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008162 MDIO_PMA_DEVAD,
8163 MDIO_PMA_REG_TX_POWER_DOWN, &val);
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008164
Yaniv Rosnere10bc842010-09-07 11:40:50 +00008165 bnx2x_cl45_write(bp, phy_blk[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008166 MDIO_PMA_DEVAD,
8167 MDIO_PMA_REG_TX_POWER_DOWN, (val & (~(1<<10))));
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008168 msleep(15);
8169
8170 /* Read modify write the SPI-ROM version select register */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00008171 bnx2x_cl45_read(bp, phy_blk[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008172 MDIO_PMA_DEVAD,
8173 MDIO_PMA_REG_EDC_FFE_MAIN, &val);
Yaniv Rosnere10bc842010-09-07 11:40:50 +00008174 bnx2x_cl45_write(bp, phy_blk[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008175 MDIO_PMA_DEVAD,
8176 MDIO_PMA_REG_EDC_FFE_MAIN, (val | (1<<12)));
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008177
8178 /* set GPIO2 back to LOW */
8179 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008180 MISC_REGISTERS_GPIO_OUTPUT_LOW, port);
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008181 }
8182 return 0;
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008183}
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00008184static int bnx2x_8726_common_init_phy(struct bnx2x *bp,
8185 u32 shmem_base_path[],
8186 u32 shmem2_base_path[], u8 phy_index,
8187 u32 chip_id)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008188{
8189 u32 val;
8190 s8 port;
8191 struct bnx2x_phy phy;
8192 /* Use port1 because of the static port-swap */
8193 /* Enable the module detection interrupt */
8194 val = REG_RD(bp, MISC_REG_GPIO_EVENT_EN);
8195 val |= ((1<<MISC_REGISTERS_GPIO_3)|
8196 (1<<(MISC_REGISTERS_GPIO_3 + MISC_REGISTERS_GPIO_PORT_SHIFT)));
8197 REG_WR(bp, MISC_REG_GPIO_EVENT_EN, val);
8198
Yaniv Rosner650154b2010-11-01 05:32:36 +00008199 bnx2x_ext_phy_hw_reset(bp, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008200 msleep(5);
8201 for (port = 0; port < PORT_MAX; port++) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008202 u32 shmem_base, shmem2_base;
8203
8204 /* In E2, same phy is using for port0 of the two paths */
8205 if (CHIP_IS_E2(bp)) {
8206 shmem_base = shmem_base_path[port];
8207 shmem2_base = shmem2_base_path[port];
8208 } else {
8209 shmem_base = shmem_base_path[0];
8210 shmem2_base = shmem2_base_path[0];
8211 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008212 /* Extract the ext phy address for the port */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008213 if (bnx2x_populate_phy(bp, phy_index, shmem_base, shmem2_base,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008214 port, &phy) !=
8215 0) {
8216 DP(NETIF_MSG_LINK, "populate phy failed\n");
8217 return -EINVAL;
8218 }
8219
8220 /* Reset phy*/
8221 bnx2x_cl45_write(bp, &phy,
8222 MDIO_PMA_DEVAD, MDIO_PMA_REG_GEN_CTRL, 0x0001);
8223
8224
8225 /* Set fault module detected LED on */
8226 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_0,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008227 MISC_REGISTERS_GPIO_HIGH,
8228 port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008229 }
8230
8231 return 0;
8232}
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008233static void bnx2x_get_ext_phy_reset_gpio(struct bnx2x *bp, u32 shmem_base,
8234 u8 *io_gpio, u8 *io_port)
8235{
8236
8237 u32 phy_gpio_reset = REG_RD(bp, shmem_base +
8238 offsetof(struct shmem_region,
8239 dev_info.port_hw_config[PORT_0].default_cfg));
8240 switch (phy_gpio_reset) {
8241 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO0_P0:
8242 *io_gpio = 0;
8243 *io_port = 0;
8244 break;
8245 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO1_P0:
8246 *io_gpio = 1;
8247 *io_port = 0;
8248 break;
8249 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO2_P0:
8250 *io_gpio = 2;
8251 *io_port = 0;
8252 break;
8253 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO3_P0:
8254 *io_gpio = 3;
8255 *io_port = 0;
8256 break;
8257 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO0_P1:
8258 *io_gpio = 0;
8259 *io_port = 1;
8260 break;
8261 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO1_P1:
8262 *io_gpio = 1;
8263 *io_port = 1;
8264 break;
8265 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO2_P1:
8266 *io_gpio = 2;
8267 *io_port = 1;
8268 break;
8269 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO3_P1:
8270 *io_gpio = 3;
8271 *io_port = 1;
8272 break;
8273 default:
8274 /* Don't override the io_gpio and io_port */
8275 break;
8276 }
8277}
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00008278
8279static int bnx2x_8727_common_init_phy(struct bnx2x *bp,
8280 u32 shmem_base_path[],
8281 u32 shmem2_base_path[], u8 phy_index,
8282 u32 chip_id)
Eilon Greenstein4d295db2009-07-21 05:47:47 +00008283{
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008284 s8 port, reset_gpio;
Eilon Greenstein4d295db2009-07-21 05:47:47 +00008285 u32 swap_val, swap_override;
Yaniv Rosnere10bc842010-09-07 11:40:50 +00008286 struct bnx2x_phy phy[PORT_MAX];
8287 struct bnx2x_phy *phy_blk[PORT_MAX];
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008288 s8 port_of_path;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008289 swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
8290 swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
Eilon Greenstein4d295db2009-07-21 05:47:47 +00008291
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008292 reset_gpio = MISC_REGISTERS_GPIO_1;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008293 port = 1;
8294
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008295 /*
8296 * Retrieve the reset gpio/port which control the reset.
8297 * Default is GPIO1, PORT1
8298 */
8299 bnx2x_get_ext_phy_reset_gpio(bp, shmem_base_path[0],
8300 (u8 *)&reset_gpio, (u8 *)&port);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008301
8302 /* Calculate the port based on port swap */
8303 port ^= (swap_val && swap_override);
8304
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008305 /* Initiate PHY reset*/
8306 bnx2x_set_gpio(bp, reset_gpio, MISC_REGISTERS_GPIO_OUTPUT_LOW,
8307 port);
8308 msleep(1);
8309 bnx2x_set_gpio(bp, reset_gpio, MISC_REGISTERS_GPIO_OUTPUT_HIGH,
8310 port);
8311
Eilon Greenstein4d295db2009-07-21 05:47:47 +00008312 msleep(5);
8313
8314 /* PART1 - Reset both phys */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008315 for (port = PORT_MAX - 1; port >= PORT_0; port--) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008316 u32 shmem_base, shmem2_base;
8317
8318 /* In E2, same phy is using for port0 of the two paths */
8319 if (CHIP_IS_E2(bp)) {
8320 shmem_base = shmem_base_path[port];
8321 shmem2_base = shmem2_base_path[port];
8322 port_of_path = 0;
8323 } else {
8324 shmem_base = shmem_base_path[0];
8325 shmem2_base = shmem2_base_path[0];
8326 port_of_path = port;
8327 }
8328
Eilon Greenstein4d295db2009-07-21 05:47:47 +00008329 /* Extract the ext phy address for the port */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008330 if (bnx2x_populate_phy(bp, phy_index, shmem_base, shmem2_base,
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008331 port_of_path, &phy[port]) !=
Yaniv Rosnere10bc842010-09-07 11:40:50 +00008332 0) {
8333 DP(NETIF_MSG_LINK, "populate phy failed\n");
8334 return -EINVAL;
8335 }
Eilon Greenstein4d295db2009-07-21 05:47:47 +00008336 /* disable attentions */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008337 bnx2x_bits_dis(bp, NIG_REG_MASK_INTERRUPT_PORT0 +
8338 port_of_path*4,
8339 (NIG_MASK_XGXS0_LINK_STATUS |
8340 NIG_MASK_XGXS0_LINK10G |
8341 NIG_MASK_SERDES0_LINK_STATUS |
8342 NIG_MASK_MI_INT));
Eilon Greenstein4d295db2009-07-21 05:47:47 +00008343
Eilon Greenstein4d295db2009-07-21 05:47:47 +00008344
8345 /* Reset the phy */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00008346 bnx2x_cl45_write(bp, &phy[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008347 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 1<<15);
Eilon Greenstein4d295db2009-07-21 05:47:47 +00008348 }
8349
8350 /* Add delay of 150ms after reset */
8351 msleep(150);
Yaniv Rosnere10bc842010-09-07 11:40:50 +00008352 if (phy[PORT_0].addr & 0x1) {
8353 phy_blk[PORT_0] = &(phy[PORT_1]);
8354 phy_blk[PORT_1] = &(phy[PORT_0]);
8355 } else {
8356 phy_blk[PORT_0] = &(phy[PORT_0]);
8357 phy_blk[PORT_1] = &(phy[PORT_1]);
8358 }
Eilon Greenstein4d295db2009-07-21 05:47:47 +00008359 /* PART2 - Download firmware to both phys */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00008360 for (port = PORT_MAX - 1; port >= PORT_0; port--) {
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008361 if (CHIP_IS_E2(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008362 port_of_path = 0;
8363 else
8364 port_of_path = port;
8365 DP(NETIF_MSG_LINK, "Loading spirom for phy address 0x%x\n",
8366 phy_blk[port]->addr);
Yaniv Rosner5c99274b2011-01-18 04:33:36 +00008367 if (bnx2x_8073_8727_external_rom_boot(bp, phy_blk[port],
8368 port_of_path))
Eilon Greenstein4d295db2009-07-21 05:47:47 +00008369 return -EINVAL;
Eilon Greenstein4d295db2009-07-21 05:47:47 +00008370
Yaniv Rosner5c99274b2011-01-18 04:33:36 +00008371 }
Eilon Greenstein4d295db2009-07-21 05:47:47 +00008372 return 0;
8373}
8374
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00008375static int bnx2x_ext_phy_common_init(struct bnx2x *bp, u32 shmem_base_path[],
8376 u32 shmem2_base_path[], u8 phy_index,
8377 u32 ext_phy_type, u32 chip_id)
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008378{
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00008379 int rc = 0;
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008380
8381 switch (ext_phy_type) {
8382 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073:
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008383 rc = bnx2x_8073_common_init_phy(bp, shmem_base_path,
8384 shmem2_base_path,
8385 phy_index, chip_id);
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008386 break;
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00008387 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8722:
Eilon Greenstein4d295db2009-07-21 05:47:47 +00008388 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
8389 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727_NOC:
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008390 rc = bnx2x_8727_common_init_phy(bp, shmem_base_path,
8391 shmem2_base_path,
8392 phy_index, chip_id);
Eilon Greenstein4d295db2009-07-21 05:47:47 +00008393 break;
8394
Eilon Greenstein589abe32009-02-12 08:36:55 +00008395 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008396 /*
8397 * GPIO1 affects both ports, so there's need to pull
8398 * it for single port alone
8399 */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008400 rc = bnx2x_8726_common_init_phy(bp, shmem_base_path,
8401 shmem2_base_path,
8402 phy_index, chip_id);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008403 break;
8404 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE:
8405 rc = -EINVAL;
Yaniv Rosner4f60dab2009-11-05 19:18:23 +02008406 break;
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008407 default:
8408 DP(NETIF_MSG_LINK,
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008409 "ext_phy 0x%x common init not required\n",
8410 ext_phy_type);
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008411 break;
8412 }
8413
Yaniv Rosner6d870c32011-01-31 04:22:20 +00008414 if (rc != 0)
8415 netdev_err(bp->dev, "Warning: PHY was not initialized,"
8416 " Port %d\n",
8417 0);
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008418 return rc;
8419}
8420
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00008421int bnx2x_common_init_phy(struct bnx2x *bp, u32 shmem_base_path[],
8422 u32 shmem2_base_path[], u32 chip_id)
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008423{
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00008424 int rc = 0;
Yaniv Rosnerb21a3422011-01-18 04:33:24 +00008425 u32 phy_ver;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008426 u8 phy_index;
8427 u32 ext_phy_type, ext_phy_config;
8428 DP(NETIF_MSG_LINK, "Begin common phy init\n");
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +00008429
Yaniv Rosnerb21a3422011-01-18 04:33:24 +00008430 /* Check if common init was already done */
8431 phy_ver = REG_RD(bp, shmem_base_path[0] +
8432 offsetof(struct shmem_region,
8433 port_mb[PORT_0].ext_phy_fw_version));
8434 if (phy_ver) {
8435 DP(NETIF_MSG_LINK, "Not doing common init; phy ver is 0x%x\n",
8436 phy_ver);
8437 return 0;
8438 }
8439
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008440 /* Read the ext_phy_type for arbitrary port(0) */
8441 for (phy_index = EXT_PHY1; phy_index < MAX_PHYS;
8442 phy_index++) {
8443 ext_phy_config = bnx2x_get_ext_phy_config(bp,
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008444 shmem_base_path[0],
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008445 phy_index, 0);
8446 ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008447 rc |= bnx2x_ext_phy_common_init(bp, shmem_base_path,
8448 shmem2_base_path,
8449 phy_index, ext_phy_type,
8450 chip_id);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008451 }
8452 return rc;
8453}
8454
8455u8 bnx2x_hw_lock_required(struct bnx2x *bp, u32 shmem_base, u32 shmem2_base)
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +00008456{
8457 u8 phy_index;
8458 struct bnx2x_phy phy;
8459 for (phy_index = INT_PHY; phy_index < MAX_PHYS;
8460 phy_index++) {
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008461 if (bnx2x_populate_phy(bp, phy_index, shmem_base, shmem2_base,
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +00008462 0, &phy) != 0) {
8463 DP(NETIF_MSG_LINK, "populate phy failed\n");
8464 return 0;
8465 }
8466
8467 if (phy.flags & FLAGS_HW_LOCK_REQUIRED)
8468 return 1;
8469 }
8470 return 0;
8471}
8472
8473u8 bnx2x_fan_failure_det_req(struct bnx2x *bp,
8474 u32 shmem_base,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008475 u32 shmem2_base,
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +00008476 u8 port)
8477{
8478 u8 phy_index, fan_failure_det_req = 0;
8479 struct bnx2x_phy phy;
8480 for (phy_index = EXT_PHY1; phy_index < MAX_PHYS;
8481 phy_index++) {
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008482 if (bnx2x_populate_phy(bp, phy_index, shmem_base, shmem2_base,
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +00008483 port, &phy)
8484 != 0) {
8485 DP(NETIF_MSG_LINK, "populate phy failed\n");
8486 return 0;
8487 }
8488 fan_failure_det_req |= (phy.flags &
8489 FLAGS_FAN_FAILURE_DET_REQ);
8490 }
8491 return fan_failure_det_req;
8492}
8493
8494void bnx2x_hw_reset_phy(struct link_params *params)
8495{
8496 u8 phy_index;
8497 for (phy_index = EXT_PHY1; phy_index < MAX_PHYS;
8498 phy_index++) {
8499 if (params->phy[phy_index].hw_reset) {
8500 params->phy[phy_index].hw_reset(
8501 &params->phy[phy_index],
8502 params);
8503 params->phy[phy_index] = phy_null;
8504 }
8505 }
8506}
Yaniv Rosner020c7e32011-05-31 21:28:43 +00008507
8508void bnx2x_init_mod_abs_int(struct bnx2x *bp, struct link_vars *vars,
8509 u32 chip_id, u32 shmem_base, u32 shmem2_base,
8510 u8 port)
8511{
8512 u8 gpio_num = 0xff, gpio_port = 0xff, phy_index;
8513 u32 val;
8514 u32 offset, aeu_mask, swap_val, swap_override, sync_offset;
8515
8516 {
8517 struct bnx2x_phy phy;
8518 for (phy_index = EXT_PHY1; phy_index < MAX_PHYS;
8519 phy_index++) {
8520 if (bnx2x_populate_phy(bp, phy_index, shmem_base,
8521 shmem2_base, port, &phy)
8522 != 0) {
8523 DP(NETIF_MSG_LINK, "populate phy failed\n");
8524 return;
8525 }
8526 if (phy.type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726) {
8527 gpio_num = MISC_REGISTERS_GPIO_3;
8528 gpio_port = port;
8529 break;
8530 }
8531 }
8532 }
8533
8534 if (gpio_num == 0xff)
8535 return;
8536
8537 /* Set GPIO3 to trigger SFP+ module insertion/removal */
8538 bnx2x_set_gpio(bp, gpio_num, MISC_REGISTERS_GPIO_INPUT_HI_Z, gpio_port);
8539
8540 swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
8541 swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
8542 gpio_port ^= (swap_val && swap_override);
8543
8544 vars->aeu_int_mask = AEU_INPUTS_ATTN_BITS_GPIO0_FUNCTION_0 <<
8545 (gpio_num + (gpio_port << 2));
8546
8547 sync_offset = shmem_base +
8548 offsetof(struct shmem_region,
8549 dev_info.port_hw_config[port].aeu_int_mask);
8550 REG_WR(bp, sync_offset, vars->aeu_int_mask);
8551
8552 DP(NETIF_MSG_LINK, "Setting MOD_ABS (GPIO%d_P%d) AEU to 0x%x\n",
8553 gpio_num, gpio_port, vars->aeu_int_mask);
8554
8555 if (port == 0)
8556 offset = MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0;
8557 else
8558 offset = MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0;
8559
8560 /* Open appropriate AEU for interrupts */
8561 aeu_mask = REG_RD(bp, offset);
8562 aeu_mask |= vars->aeu_int_mask;
8563 REG_WR(bp, offset, aeu_mask);
8564
8565 /* Enable the GPIO to trigger interrupt */
8566 val = REG_RD(bp, MISC_REG_GPIO_EVENT_EN);
8567 val |= 1 << (gpio_num + (gpio_port << 2));
8568 REG_WR(bp, MISC_REG_GPIO_EVENT_EN, val);
8569}