blob: ffc3c16166d4c11d5800e94b994f6db206369023 [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,
512 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
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001533static void bnx2x_set_aer_mmd_xgxs(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
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001543 offset = phy->addr + ser_lane;
1544 if (CHIP_IS_E2(bp))
Yaniv Rosner82a0d472011-01-18 04:33:52 +00001545 aer_val = 0x3800 + offset - 1;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001546 else
1547 aer_val = 0x3800 + offset;
Yaniv Rosnercd2be892011-01-31 04:21:45 +00001548 CL22_WR_OVER_CL45(bp, phy, MDIO_REG_BANK_AER_BLOCK,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001549 MDIO_AER_BLOCK_AER_REG, aer_val);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001550}
1551static void bnx2x_set_aer_mmd_serdes(struct bnx2x *bp,
1552 struct bnx2x_phy *phy)
1553{
Yaniv Rosnercd2be892011-01-31 04:21:45 +00001554 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001555 MDIO_REG_BANK_AER_BLOCK,
1556 MDIO_AER_BLOCK_AER_REG, 0x3800);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001557}
1558
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00001559/******************************************************************/
1560/* Internal phy section */
1561/******************************************************************/
1562
1563static void bnx2x_set_serdes_access(struct bnx2x *bp, u8 port)
1564{
1565 u32 emac_base = (port) ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
1566
1567 /* Set Clause 22 */
1568 REG_WR(bp, NIG_REG_SERDES0_CTRL_MD_ST + port*0x10, 1);
1569 REG_WR(bp, emac_base + EMAC_REG_EMAC_MDIO_COMM, 0x245f8000);
1570 udelay(500);
1571 REG_WR(bp, emac_base + EMAC_REG_EMAC_MDIO_COMM, 0x245d000f);
1572 udelay(500);
1573 /* Set Clause 45 */
1574 REG_WR(bp, NIG_REG_SERDES0_CTRL_MD_ST + port*0x10, 0);
1575}
1576
1577static void bnx2x_serdes_deassert(struct bnx2x *bp, u8 port)
1578{
1579 u32 val;
1580
1581 DP(NETIF_MSG_LINK, "bnx2x_serdes_deassert\n");
1582
1583 val = SERDES_RESET_BITS << (port*16);
1584
1585 /* reset and unreset the SerDes/XGXS */
1586 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_CLEAR, val);
1587 udelay(500);
1588 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_SET, val);
1589
1590 bnx2x_set_serdes_access(bp, port);
1591
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001592 REG_WR(bp, NIG_REG_SERDES0_CTRL_MD_DEVAD + port*0x10,
1593 DEFAULT_PHY_DEV_ADDR);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00001594}
1595
1596static void bnx2x_xgxs_deassert(struct link_params *params)
1597{
1598 struct bnx2x *bp = params->bp;
1599 u8 port;
1600 u32 val;
1601 DP(NETIF_MSG_LINK, "bnx2x_xgxs_deassert\n");
1602 port = params->port;
1603
1604 val = XGXS_RESET_BITS << (port*16);
1605
1606 /* reset and unreset the SerDes/XGXS */
1607 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_CLEAR, val);
1608 udelay(500);
1609 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_SET, val);
1610
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001611 REG_WR(bp, NIG_REG_XGXS0_CTRL_MD_ST + port*0x18, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00001612 REG_WR(bp, NIG_REG_XGXS0_CTRL_MD_DEVAD + port*0x18,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001613 params->phy[INT_PHY].def_md_devad);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00001614}
1615
Yaniv Rosnera22f0782010-09-07 11:41:20 +00001616
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00001617void bnx2x_link_status_update(struct link_params *params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001618 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00001619{
1620 struct bnx2x *bp = params->bp;
1621 u8 link_10g;
1622 u8 port = params->port;
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00001623 u32 sync_offset, media_types;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00001624 vars->link_status = REG_RD(bp, params->shmem_base +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001625 offsetof(struct shmem_region,
1626 port_mb[port].link_status));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00001627
1628 vars->link_up = (vars->link_status & LINK_STATUS_LINK_UP);
1629
1630 if (vars->link_up) {
1631 DP(NETIF_MSG_LINK, "phy link up\n");
1632
1633 vars->phy_link_up = 1;
1634 vars->duplex = DUPLEX_FULL;
1635 switch (vars->link_status &
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001636 LINK_STATUS_SPEED_AND_DUPLEX_MASK) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00001637 case LINK_10THD:
1638 vars->duplex = DUPLEX_HALF;
1639 /* fall thru */
1640 case LINK_10TFD:
1641 vars->line_speed = SPEED_10;
1642 break;
1643
1644 case LINK_100TXHD:
1645 vars->duplex = DUPLEX_HALF;
1646 /* fall thru */
1647 case LINK_100T4:
1648 case LINK_100TXFD:
1649 vars->line_speed = SPEED_100;
1650 break;
1651
1652 case LINK_1000THD:
1653 vars->duplex = DUPLEX_HALF;
1654 /* fall thru */
1655 case LINK_1000TFD:
1656 vars->line_speed = SPEED_1000;
1657 break;
1658
1659 case LINK_2500THD:
1660 vars->duplex = DUPLEX_HALF;
1661 /* fall thru */
1662 case LINK_2500TFD:
1663 vars->line_speed = SPEED_2500;
1664 break;
1665
1666 case LINK_10GTFD:
1667 vars->line_speed = SPEED_10000;
1668 break;
1669
1670 case LINK_12GTFD:
1671 vars->line_speed = SPEED_12000;
1672 break;
1673
1674 case LINK_12_5GTFD:
1675 vars->line_speed = SPEED_12500;
1676 break;
1677
1678 case LINK_13GTFD:
1679 vars->line_speed = SPEED_13000;
1680 break;
1681
1682 case LINK_15GTFD:
1683 vars->line_speed = SPEED_15000;
1684 break;
1685
1686 case LINK_16GTFD:
1687 vars->line_speed = SPEED_16000;
1688 break;
1689
1690 default:
1691 break;
1692 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00001693 vars->flow_ctrl = 0;
1694 if (vars->link_status & LINK_STATUS_TX_FLOW_CONTROL_ENABLED)
1695 vars->flow_ctrl |= BNX2X_FLOW_CTRL_TX;
1696
1697 if (vars->link_status & LINK_STATUS_RX_FLOW_CONTROL_ENABLED)
1698 vars->flow_ctrl |= BNX2X_FLOW_CTRL_RX;
1699
1700 if (!vars->flow_ctrl)
1701 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
1702
1703 if (vars->line_speed &&
1704 ((vars->line_speed == SPEED_10) ||
1705 (vars->line_speed == SPEED_100))) {
1706 vars->phy_flags |= PHY_SGMII_FLAG;
1707 } else {
1708 vars->phy_flags &= ~PHY_SGMII_FLAG;
1709 }
1710
1711 /* anything 10 and over uses the bmac */
1712 link_10g = ((vars->line_speed == SPEED_10000) ||
1713 (vars->line_speed == SPEED_12000) ||
1714 (vars->line_speed == SPEED_12500) ||
1715 (vars->line_speed == SPEED_13000) ||
1716 (vars->line_speed == SPEED_15000) ||
1717 (vars->line_speed == SPEED_16000));
1718 if (link_10g)
1719 vars->mac_type = MAC_TYPE_BMAC;
1720 else
1721 vars->mac_type = MAC_TYPE_EMAC;
1722
1723 } else { /* link down */
1724 DP(NETIF_MSG_LINK, "phy link down\n");
1725
1726 vars->phy_link_up = 0;
1727
1728 vars->line_speed = 0;
1729 vars->duplex = DUPLEX_FULL;
1730 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
1731
1732 /* indicate no mac active */
1733 vars->mac_type = MAC_TYPE_NONE;
1734 }
1735
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00001736 /* Sync media type */
1737 sync_offset = params->shmem_base +
1738 offsetof(struct shmem_region,
1739 dev_info.port_hw_config[port].media_type);
1740 media_types = REG_RD(bp, sync_offset);
1741
1742 params->phy[INT_PHY].media_type =
1743 (media_types & PORT_HW_CFG_MEDIA_TYPE_PHY0_MASK) >>
1744 PORT_HW_CFG_MEDIA_TYPE_PHY0_SHIFT;
1745 params->phy[EXT_PHY1].media_type =
1746 (media_types & PORT_HW_CFG_MEDIA_TYPE_PHY1_MASK) >>
1747 PORT_HW_CFG_MEDIA_TYPE_PHY1_SHIFT;
1748 params->phy[EXT_PHY2].media_type =
1749 (media_types & PORT_HW_CFG_MEDIA_TYPE_PHY2_MASK) >>
1750 PORT_HW_CFG_MEDIA_TYPE_PHY2_SHIFT;
1751 DP(NETIF_MSG_LINK, "media_types = 0x%x\n", media_types);
1752
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00001753 DP(NETIF_MSG_LINK, "link_status 0x%x phy_link_up %x\n",
1754 vars->link_status, vars->phy_link_up);
1755 DP(NETIF_MSG_LINK, "line_speed %x duplex %x flow_ctrl 0x%x\n",
1756 vars->line_speed, vars->duplex, vars->flow_ctrl);
1757}
1758
1759
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001760static void bnx2x_set_master_ln(struct link_params *params,
1761 struct bnx2x_phy *phy)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001762{
1763 struct bnx2x *bp = params->bp;
1764 u16 new_master_ln, ser_lane;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001765 ser_lane = ((params->lane_config &
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001766 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_MASK) >>
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001767 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_SHIFT);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001768
1769 /* set the master_ln for AN */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00001770 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001771 MDIO_REG_BANK_XGXS_BLOCK2,
1772 MDIO_XGXS_BLOCK2_TEST_MODE_LANE,
1773 &new_master_ln);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001774
Yaniv Rosnercd2be892011-01-31 04:21:45 +00001775 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001776 MDIO_REG_BANK_XGXS_BLOCK2 ,
1777 MDIO_XGXS_BLOCK2_TEST_MODE_LANE,
1778 (new_master_ln | ser_lane));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001779}
1780
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00001781static int bnx2x_reset_unicore(struct link_params *params,
1782 struct bnx2x_phy *phy,
1783 u8 set_serdes)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001784{
1785 struct bnx2x *bp = params->bp;
1786 u16 mii_control;
1787 u16 i;
Yaniv Rosnercd2be892011-01-31 04:21:45 +00001788 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001789 MDIO_REG_BANK_COMBO_IEEE0,
1790 MDIO_COMBO_IEEE0_MII_CONTROL, &mii_control);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001791
1792 /* reset the unicore */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00001793 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001794 MDIO_REG_BANK_COMBO_IEEE0,
1795 MDIO_COMBO_IEEE0_MII_CONTROL,
1796 (mii_control |
1797 MDIO_COMBO_IEEO_MII_CONTROL_RESET));
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001798 if (set_serdes)
1799 bnx2x_set_serdes_access(bp, params->port);
Eilon Greensteinc1b73992009-02-12 08:37:07 +00001800
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001801 /* wait for the reset to self clear */
1802 for (i = 0; i < MDIO_ACCESS_TIMEOUT; i++) {
1803 udelay(5);
1804
1805 /* the reset erased the previous bank value */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00001806 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001807 MDIO_REG_BANK_COMBO_IEEE0,
1808 MDIO_COMBO_IEEE0_MII_CONTROL,
1809 &mii_control);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001810
1811 if (!(mii_control & MDIO_COMBO_IEEO_MII_CONTROL_RESET)) {
1812 udelay(5);
1813 return 0;
1814 }
1815 }
1816
Yaniv Rosner6d870c32011-01-31 04:22:20 +00001817 netdev_err(bp->dev, "Warning: PHY was not initialized,"
1818 " Port %d\n",
1819 params->port);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001820 DP(NETIF_MSG_LINK, "BUG! XGXS is still in reset!\n");
1821 return -EINVAL;
1822
1823}
1824
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001825static void bnx2x_set_swap_lanes(struct link_params *params,
1826 struct bnx2x_phy *phy)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001827{
1828 struct bnx2x *bp = params->bp;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00001829 /*
1830 * Each two bits represents a lane number:
1831 * No swap is 0123 => 0x1b no need to enable the swap
1832 */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001833 u16 ser_lane, rx_lane_swap, tx_lane_swap;
1834
1835 ser_lane = ((params->lane_config &
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001836 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_MASK) >>
1837 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_SHIFT);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001838 rx_lane_swap = ((params->lane_config &
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001839 PORT_HW_CFG_LANE_SWAP_CFG_RX_MASK) >>
1840 PORT_HW_CFG_LANE_SWAP_CFG_RX_SHIFT);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001841 tx_lane_swap = ((params->lane_config &
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001842 PORT_HW_CFG_LANE_SWAP_CFG_TX_MASK) >>
1843 PORT_HW_CFG_LANE_SWAP_CFG_TX_SHIFT);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001844
1845 if (rx_lane_swap != 0x1b) {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00001846 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001847 MDIO_REG_BANK_XGXS_BLOCK2,
1848 MDIO_XGXS_BLOCK2_RX_LN_SWAP,
1849 (rx_lane_swap |
1850 MDIO_XGXS_BLOCK2_RX_LN_SWAP_ENABLE |
1851 MDIO_XGXS_BLOCK2_RX_LN_SWAP_FORCE_ENABLE));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001852 } else {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00001853 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001854 MDIO_REG_BANK_XGXS_BLOCK2,
1855 MDIO_XGXS_BLOCK2_RX_LN_SWAP, 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001856 }
1857
1858 if (tx_lane_swap != 0x1b) {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00001859 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001860 MDIO_REG_BANK_XGXS_BLOCK2,
1861 MDIO_XGXS_BLOCK2_TX_LN_SWAP,
1862 (tx_lane_swap |
1863 MDIO_XGXS_BLOCK2_TX_LN_SWAP_ENABLE));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001864 } else {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00001865 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001866 MDIO_REG_BANK_XGXS_BLOCK2,
1867 MDIO_XGXS_BLOCK2_TX_LN_SWAP, 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001868 }
1869}
1870
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001871static void bnx2x_set_parallel_detection(struct bnx2x_phy *phy,
1872 struct link_params *params)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001873{
1874 struct bnx2x *bp = params->bp;
1875 u16 control2;
Yaniv Rosnercd2be892011-01-31 04:21:45 +00001876 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001877 MDIO_REG_BANK_SERDES_DIGITAL,
1878 MDIO_SERDES_DIGITAL_A_1000X_CONTROL2,
1879 &control2);
Yaniv Rosner7aa07112010-09-07 11:41:01 +00001880 if (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)
Yaniv Rosner18afb0a2009-11-05 19:18:04 +02001881 control2 |= MDIO_SERDES_DIGITAL_A_1000X_CONTROL2_PRL_DT_EN;
1882 else
1883 control2 &= ~MDIO_SERDES_DIGITAL_A_1000X_CONTROL2_PRL_DT_EN;
Yaniv Rosner7aa07112010-09-07 11:41:01 +00001884 DP(NETIF_MSG_LINK, "phy->speed_cap_mask = 0x%x, control2 = 0x%x\n",
1885 phy->speed_cap_mask, control2);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00001886 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001887 MDIO_REG_BANK_SERDES_DIGITAL,
1888 MDIO_SERDES_DIGITAL_A_1000X_CONTROL2,
1889 control2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001890
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001891 if ((phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT) &&
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00001892 (phy->speed_cap_mask &
Yaniv Rosner18afb0a2009-11-05 19:18:04 +02001893 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001894 DP(NETIF_MSG_LINK, "XGXS\n");
1895
Yaniv Rosnercd2be892011-01-31 04:21:45 +00001896 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001897 MDIO_REG_BANK_10G_PARALLEL_DETECT,
1898 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_LINK,
1899 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_LINK_CNT);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001900
Yaniv Rosnercd2be892011-01-31 04:21:45 +00001901 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001902 MDIO_REG_BANK_10G_PARALLEL_DETECT,
1903 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_CONTROL,
1904 &control2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001905
1906
1907 control2 |=
1908 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_CONTROL_PARDET10G_EN;
1909
Yaniv Rosnercd2be892011-01-31 04:21:45 +00001910 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001911 MDIO_REG_BANK_10G_PARALLEL_DETECT,
1912 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_CONTROL,
1913 control2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001914
1915 /* Disable parallel detection of HiG */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00001916 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001917 MDIO_REG_BANK_XGXS_BLOCK2,
1918 MDIO_XGXS_BLOCK2_UNICORE_MODE_10G,
1919 MDIO_XGXS_BLOCK2_UNICORE_MODE_10G_CX4_XGXS |
1920 MDIO_XGXS_BLOCK2_UNICORE_MODE_10G_HIGIG_XGXS);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001921 }
1922}
1923
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001924static void bnx2x_set_autoneg(struct bnx2x_phy *phy,
1925 struct link_params *params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001926 struct link_vars *vars,
1927 u8 enable_cl73)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001928{
1929 struct bnx2x *bp = params->bp;
1930 u16 reg_val;
1931
1932 /* CL37 Autoneg */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00001933 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001934 MDIO_REG_BANK_COMBO_IEEE0,
1935 MDIO_COMBO_IEEE0_MII_CONTROL, &reg_val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001936
1937 /* CL37 Autoneg Enabled */
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07001938 if (vars->line_speed == SPEED_AUTO_NEG)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001939 reg_val |= MDIO_COMBO_IEEO_MII_CONTROL_AN_EN;
1940 else /* CL37 Autoneg Disabled */
1941 reg_val &= ~(MDIO_COMBO_IEEO_MII_CONTROL_AN_EN |
1942 MDIO_COMBO_IEEO_MII_CONTROL_RESTART_AN);
1943
Yaniv Rosnercd2be892011-01-31 04:21:45 +00001944 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001945 MDIO_REG_BANK_COMBO_IEEE0,
1946 MDIO_COMBO_IEEE0_MII_CONTROL, reg_val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001947
1948 /* Enable/Disable Autodetection */
1949
Yaniv Rosnercd2be892011-01-31 04:21:45 +00001950 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001951 MDIO_REG_BANK_SERDES_DIGITAL,
1952 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1, &reg_val);
Eilon Greenstein239d6862009-08-12 08:23:04 +00001953 reg_val &= ~(MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_SIGNAL_DETECT_EN |
1954 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_INVERT_SIGNAL_DETECT);
1955 reg_val |= MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_FIBER_MODE;
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07001956 if (vars->line_speed == SPEED_AUTO_NEG)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001957 reg_val |= MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_AUTODET;
1958 else
1959 reg_val &= ~MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_AUTODET;
1960
Yaniv Rosnercd2be892011-01-31 04:21:45 +00001961 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001962 MDIO_REG_BANK_SERDES_DIGITAL,
1963 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1, reg_val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001964
1965 /* Enable TetonII and BAM autoneg */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00001966 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001967 MDIO_REG_BANK_BAM_NEXT_PAGE,
1968 MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL,
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001969 &reg_val);
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07001970 if (vars->line_speed == SPEED_AUTO_NEG) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001971 /* Enable BAM aneg Mode and TetonII aneg Mode */
1972 reg_val |= (MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL_BAM_MODE |
1973 MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL_TETON_AN);
1974 } else {
1975 /* TetonII and BAM Autoneg Disabled */
1976 reg_val &= ~(MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL_BAM_MODE |
1977 MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL_TETON_AN);
1978 }
Yaniv Rosnercd2be892011-01-31 04:21:45 +00001979 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001980 MDIO_REG_BANK_BAM_NEXT_PAGE,
1981 MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL,
1982 reg_val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001983
Eilon Greenstein239d6862009-08-12 08:23:04 +00001984 if (enable_cl73) {
1985 /* Enable Cl73 FSM status bits */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00001986 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001987 MDIO_REG_BANK_CL73_USERB0,
1988 MDIO_CL73_USERB0_CL73_UCTRL,
1989 0xe);
Eilon Greenstein239d6862009-08-12 08:23:04 +00001990
1991 /* Enable BAM Station Manager*/
Yaniv Rosnercd2be892011-01-31 04:21:45 +00001992 CL22_WR_OVER_CL45(bp, phy,
Eilon Greenstein239d6862009-08-12 08:23:04 +00001993 MDIO_REG_BANK_CL73_USERB0,
1994 MDIO_CL73_USERB0_CL73_BAM_CTRL1,
1995 MDIO_CL73_USERB0_CL73_BAM_CTRL1_BAM_EN |
1996 MDIO_CL73_USERB0_CL73_BAM_CTRL1_BAM_STATION_MNGR_EN |
1997 MDIO_CL73_USERB0_CL73_BAM_CTRL1_BAM_NP_AFTER_BP_EN);
1998
Yaniv Rosner7846e472009-11-05 19:18:07 +02001999 /* Advertise CL73 link speeds */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002000 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002001 MDIO_REG_BANK_CL73_IEEEB1,
2002 MDIO_CL73_IEEEB1_AN_ADV2,
2003 &reg_val);
Yaniv Rosner7aa07112010-09-07 11:41:01 +00002004 if (phy->speed_cap_mask &
Yaniv Rosner7846e472009-11-05 19:18:07 +02002005 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
2006 reg_val |= MDIO_CL73_IEEEB1_AN_ADV2_ADVR_10G_KX4;
Yaniv Rosner7aa07112010-09-07 11:41:01 +00002007 if (phy->speed_cap_mask &
Yaniv Rosner7846e472009-11-05 19:18:07 +02002008 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)
2009 reg_val |= MDIO_CL73_IEEEB1_AN_ADV2_ADVR_1000M_KX;
Eilon Greenstein239d6862009-08-12 08:23:04 +00002010
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002011 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002012 MDIO_REG_BANK_CL73_IEEEB1,
2013 MDIO_CL73_IEEEB1_AN_ADV2,
2014 reg_val);
Eilon Greenstein239d6862009-08-12 08:23:04 +00002015
Eilon Greenstein239d6862009-08-12 08:23:04 +00002016 /* CL73 Autoneg Enabled */
2017 reg_val = MDIO_CL73_IEEEB0_CL73_AN_CONTROL_AN_EN;
2018
2019 } else /* CL73 Autoneg Disabled */
2020 reg_val = 0;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002021
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002022 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002023 MDIO_REG_BANK_CL73_IEEEB0,
2024 MDIO_CL73_IEEEB0_CL73_AN_CONTROL, reg_val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002025}
2026
2027/* program SerDes, forced speed */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002028static void bnx2x_program_serdes(struct bnx2x_phy *phy,
2029 struct link_params *params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002030 struct link_vars *vars)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002031{
2032 struct bnx2x *bp = params->bp;
2033 u16 reg_val;
2034
Eilon Greenstein57937202009-08-12 08:23:53 +00002035 /* program duplex, disable autoneg and sgmii*/
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002036 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002037 MDIO_REG_BANK_COMBO_IEEE0,
2038 MDIO_COMBO_IEEE0_MII_CONTROL, &reg_val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002039 reg_val &= ~(MDIO_COMBO_IEEO_MII_CONTROL_FULL_DUPLEX |
Eilon Greenstein57937202009-08-12 08:23:53 +00002040 MDIO_COMBO_IEEO_MII_CONTROL_AN_EN |
2041 MDIO_COMBO_IEEO_MII_CONTROL_MAN_SGMII_SP_MASK);
Yaniv Rosner7aa07112010-09-07 11:41:01 +00002042 if (phy->req_duplex == DUPLEX_FULL)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002043 reg_val |= MDIO_COMBO_IEEO_MII_CONTROL_FULL_DUPLEX;
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002044 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002045 MDIO_REG_BANK_COMBO_IEEE0,
2046 MDIO_COMBO_IEEE0_MII_CONTROL, reg_val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002047
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002048 /*
2049 * program speed
2050 * - needed only if the speed is greater than 1G (2.5G or 10G)
2051 */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002052 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002053 MDIO_REG_BANK_SERDES_DIGITAL,
2054 MDIO_SERDES_DIGITAL_MISC1, &reg_val);
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002055 /* clearing the speed value before setting the right speed */
2056 DP(NETIF_MSG_LINK, "MDIO_REG_BANK_SERDES_DIGITAL = 0x%x\n", reg_val);
2057
2058 reg_val &= ~(MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_MASK |
2059 MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_SEL);
2060
2061 if (!((vars->line_speed == SPEED_1000) ||
2062 (vars->line_speed == SPEED_100) ||
2063 (vars->line_speed == SPEED_10))) {
2064
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002065 reg_val |= (MDIO_SERDES_DIGITAL_MISC1_REFCLK_SEL_156_25M |
2066 MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_SEL);
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002067 if (vars->line_speed == SPEED_10000)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002068 reg_val |=
2069 MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_10G_CX4;
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002070 if (vars->line_speed == SPEED_13000)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002071 reg_val |=
2072 MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_13G;
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002073 }
2074
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002075 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002076 MDIO_REG_BANK_SERDES_DIGITAL,
2077 MDIO_SERDES_DIGITAL_MISC1, reg_val);
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002078
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002079}
2080
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002081static void bnx2x_set_brcm_cl37_advertisment(struct bnx2x_phy *phy,
2082 struct link_params *params)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002083{
2084 struct bnx2x *bp = params->bp;
2085 u16 val = 0;
2086
2087 /* configure the 48 bits for BAM AN */
2088
2089 /* set extended capabilities */
Yaniv Rosner7aa07112010-09-07 11:41:01 +00002090 if (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002091 val |= MDIO_OVER_1G_UP1_2_5G;
Yaniv Rosner7aa07112010-09-07 11:41:01 +00002092 if (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002093 val |= MDIO_OVER_1G_UP1_10G;
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002094 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002095 MDIO_REG_BANK_OVER_1G,
2096 MDIO_OVER_1G_UP1, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002097
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002098 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002099 MDIO_REG_BANK_OVER_1G,
2100 MDIO_OVER_1G_UP3, 0x400);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002101}
2102
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002103static void bnx2x_calc_ieee_aneg_adv(struct bnx2x_phy *phy,
2104 struct link_params *params, u16 *ieee_fc)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002105{
Yaniv Rosnerd5cb9e92009-11-05 19:18:10 +02002106 struct bnx2x *bp = params->bp;
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002107 *ieee_fc = MDIO_COMBO_IEEE0_AUTO_NEG_ADV_FULL_DUPLEX;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002108 /*
2109 * Resolve pause mode and advertisement.
2110 * Please refer to Table 28B-3 of the 802.3ab-1999 spec
2111 */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002112
Yaniv Rosner7aa07112010-09-07 11:41:01 +00002113 switch (phy->req_flow_ctrl) {
David S. Millerc0700f92008-12-16 23:53:20 -08002114 case BNX2X_FLOW_CTRL_AUTO:
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002115 if (params->req_fc_auto_adv == BNX2X_FLOW_CTRL_BOTH)
2116 *ieee_fc |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH;
2117 else
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002118 *ieee_fc |=
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002119 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002120 break;
David S. Millerc0700f92008-12-16 23:53:20 -08002121 case BNX2X_FLOW_CTRL_TX:
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002122 *ieee_fc |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002123 break;
2124
David S. Millerc0700f92008-12-16 23:53:20 -08002125 case BNX2X_FLOW_CTRL_RX:
2126 case BNX2X_FLOW_CTRL_BOTH:
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002127 *ieee_fc |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002128 break;
2129
David S. Millerc0700f92008-12-16 23:53:20 -08002130 case BNX2X_FLOW_CTRL_NONE:
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002131 default:
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002132 *ieee_fc |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002133 break;
2134 }
Yaniv Rosnerd5cb9e92009-11-05 19:18:10 +02002135 DP(NETIF_MSG_LINK, "ieee_fc = 0x%x\n", *ieee_fc);
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002136}
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002137
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002138static void bnx2x_set_ieee_aneg_advertisment(struct bnx2x_phy *phy,
2139 struct link_params *params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002140 u16 ieee_fc)
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002141{
2142 struct bnx2x *bp = params->bp;
Yaniv Rosner7846e472009-11-05 19:18:07 +02002143 u16 val;
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002144 /* for AN, we are always publishing full duplex */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002145
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002146 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002147 MDIO_REG_BANK_COMBO_IEEE0,
2148 MDIO_COMBO_IEEE0_AUTO_NEG_ADV, ieee_fc);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002149 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002150 MDIO_REG_BANK_CL73_IEEEB1,
2151 MDIO_CL73_IEEEB1_AN_ADV1, &val);
Yaniv Rosner7846e472009-11-05 19:18:07 +02002152 val &= ~MDIO_CL73_IEEEB1_AN_ADV1_PAUSE_BOTH;
2153 val |= ((ieee_fc<<3) & MDIO_CL73_IEEEB1_AN_ADV1_PAUSE_MASK);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002154 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002155 MDIO_REG_BANK_CL73_IEEEB1,
2156 MDIO_CL73_IEEEB1_AN_ADV1, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002157}
2158
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002159static void bnx2x_restart_autoneg(struct bnx2x_phy *phy,
2160 struct link_params *params,
2161 u8 enable_cl73)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002162{
2163 struct bnx2x *bp = params->bp;
Eilon Greenstein3a36f2e2009-02-12 08:37:09 +00002164 u16 mii_control;
Eilon Greenstein239d6862009-08-12 08:23:04 +00002165
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002166 DP(NETIF_MSG_LINK, "bnx2x_restart_autoneg\n");
Eilon Greenstein3a36f2e2009-02-12 08:37:09 +00002167 /* Enable and restart BAM/CL37 aneg */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002168
Eilon Greenstein239d6862009-08-12 08:23:04 +00002169 if (enable_cl73) {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002170 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002171 MDIO_REG_BANK_CL73_IEEEB0,
2172 MDIO_CL73_IEEEB0_CL73_AN_CONTROL,
2173 &mii_control);
Eilon Greenstein239d6862009-08-12 08:23:04 +00002174
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002175 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002176 MDIO_REG_BANK_CL73_IEEEB0,
2177 MDIO_CL73_IEEEB0_CL73_AN_CONTROL,
2178 (mii_control |
2179 MDIO_CL73_IEEEB0_CL73_AN_CONTROL_AN_EN |
2180 MDIO_CL73_IEEEB0_CL73_AN_CONTROL_RESTART_AN));
Eilon Greenstein239d6862009-08-12 08:23:04 +00002181 } else {
2182
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002183 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002184 MDIO_REG_BANK_COMBO_IEEE0,
2185 MDIO_COMBO_IEEE0_MII_CONTROL,
2186 &mii_control);
Eilon Greenstein239d6862009-08-12 08:23:04 +00002187 DP(NETIF_MSG_LINK,
2188 "bnx2x_restart_autoneg mii_control before = 0x%x\n",
2189 mii_control);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002190 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002191 MDIO_REG_BANK_COMBO_IEEE0,
2192 MDIO_COMBO_IEEE0_MII_CONTROL,
2193 (mii_control |
2194 MDIO_COMBO_IEEO_MII_CONTROL_AN_EN |
2195 MDIO_COMBO_IEEO_MII_CONTROL_RESTART_AN));
Eilon Greenstein239d6862009-08-12 08:23:04 +00002196 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002197}
2198
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002199static void bnx2x_initialize_sgmii_process(struct bnx2x_phy *phy,
2200 struct link_params *params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002201 struct link_vars *vars)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002202{
2203 struct bnx2x *bp = params->bp;
2204 u16 control1;
2205
2206 /* in SGMII mode, the unicore is always slave */
2207
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_SERDES_DIGITAL,
2210 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1,
2211 &control1);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002212 control1 |= MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_INVERT_SIGNAL_DETECT;
2213 /* set sgmii mode (and not fiber) */
2214 control1 &= ~(MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_FIBER_MODE |
2215 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_AUTODET |
2216 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_MSTR_MODE);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002217 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002218 MDIO_REG_BANK_SERDES_DIGITAL,
2219 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1,
2220 control1);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002221
2222 /* if forced speed */
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002223 if (!(vars->line_speed == SPEED_AUTO_NEG)) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002224 /* set speed, disable autoneg */
2225 u16 mii_control;
2226
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002227 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002228 MDIO_REG_BANK_COMBO_IEEE0,
2229 MDIO_COMBO_IEEE0_MII_CONTROL,
2230 &mii_control);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002231 mii_control &= ~(MDIO_COMBO_IEEO_MII_CONTROL_AN_EN |
2232 MDIO_COMBO_IEEO_MII_CONTROL_MAN_SGMII_SP_MASK|
2233 MDIO_COMBO_IEEO_MII_CONTROL_FULL_DUPLEX);
2234
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002235 switch (vars->line_speed) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002236 case SPEED_100:
2237 mii_control |=
2238 MDIO_COMBO_IEEO_MII_CONTROL_MAN_SGMII_SP_100;
2239 break;
2240 case SPEED_1000:
2241 mii_control |=
2242 MDIO_COMBO_IEEO_MII_CONTROL_MAN_SGMII_SP_1000;
2243 break;
2244 case SPEED_10:
2245 /* there is nothing to set for 10M */
2246 break;
2247 default:
2248 /* invalid speed for SGMII */
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002249 DP(NETIF_MSG_LINK, "Invalid line_speed 0x%x\n",
2250 vars->line_speed);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002251 break;
2252 }
2253
2254 /* setting the full duplex */
Yaniv Rosner7aa07112010-09-07 11:41:01 +00002255 if (phy->req_duplex == DUPLEX_FULL)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002256 mii_control |=
2257 MDIO_COMBO_IEEO_MII_CONTROL_FULL_DUPLEX;
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002258 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002259 MDIO_REG_BANK_COMBO_IEEE0,
2260 MDIO_COMBO_IEEE0_MII_CONTROL,
2261 mii_control);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002262
2263 } else { /* AN mode */
2264 /* enable and restart AN */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002265 bnx2x_restart_autoneg(phy, params, 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002266 }
2267}
2268
2269
2270/*
2271 * link management
2272 */
2273
2274static void bnx2x_pause_resolve(struct link_vars *vars, u32 pause_result)
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002275{ /* LD LP */
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002276 switch (pause_result) { /* ASYM P ASYM P */
2277 case 0xb: /* 1 0 1 1 */
David S. Millerc0700f92008-12-16 23:53:20 -08002278 vars->flow_ctrl = BNX2X_FLOW_CTRL_TX;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002279 break;
2280
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002281 case 0xe: /* 1 1 1 0 */
David S. Millerc0700f92008-12-16 23:53:20 -08002282 vars->flow_ctrl = BNX2X_FLOW_CTRL_RX;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002283 break;
2284
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002285 case 0x5: /* 0 1 0 1 */
2286 case 0x7: /* 0 1 1 1 */
2287 case 0xd: /* 1 1 0 1 */
2288 case 0xf: /* 1 1 1 1 */
David S. Millerc0700f92008-12-16 23:53:20 -08002289 vars->flow_ctrl = BNX2X_FLOW_CTRL_BOTH;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002290 break;
2291
2292 default:
2293 break;
2294 }
Yaniv Rosner7aa07112010-09-07 11:41:01 +00002295 if (pause_result & (1<<0))
2296 vars->link_status |= LINK_STATUS_LINK_PARTNER_SYMMETRIC_PAUSE;
2297 if (pause_result & (1<<1))
2298 vars->link_status |= LINK_STATUS_LINK_PARTNER_ASYMMETRIC_PAUSE;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002299}
2300
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00002301static int bnx2x_direct_parallel_detect_used(struct bnx2x_phy *phy,
2302 struct link_params *params)
Yaniv Rosner15ddd2d2009-11-05 19:18:12 +02002303{
2304 struct bnx2x *bp = params->bp;
2305 u16 pd_10g, status2_1000x;
Yaniv Rosner7aa07112010-09-07 11:41:01 +00002306 if (phy->req_line_speed != SPEED_AUTO_NEG)
2307 return 0;
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002308 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002309 MDIO_REG_BANK_SERDES_DIGITAL,
2310 MDIO_SERDES_DIGITAL_A_1000X_STATUS2,
2311 &status2_1000x);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002312 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002313 MDIO_REG_BANK_SERDES_DIGITAL,
2314 MDIO_SERDES_DIGITAL_A_1000X_STATUS2,
2315 &status2_1000x);
Yaniv Rosner15ddd2d2009-11-05 19:18:12 +02002316 if (status2_1000x & MDIO_SERDES_DIGITAL_A_1000X_STATUS2_AN_DISABLED) {
2317 DP(NETIF_MSG_LINK, "1G parallel detect link on port %d\n",
2318 params->port);
2319 return 1;
2320 }
2321
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002322 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002323 MDIO_REG_BANK_10G_PARALLEL_DETECT,
2324 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_STATUS,
2325 &pd_10g);
Yaniv Rosner15ddd2d2009-11-05 19:18:12 +02002326
2327 if (pd_10g & MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_STATUS_PD_LINK) {
2328 DP(NETIF_MSG_LINK, "10G parallel detect link on port %d\n",
2329 params->port);
2330 return 1;
2331 }
2332 return 0;
2333}
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002334
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002335static void bnx2x_flow_ctrl_resolve(struct bnx2x_phy *phy,
2336 struct link_params *params,
2337 struct link_vars *vars,
2338 u32 gp_status)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002339{
2340 struct bnx2x *bp = params->bp;
Eilon Greenstein3196a882008-08-13 15:58:49 -07002341 u16 ld_pause; /* local driver */
2342 u16 lp_pause; /* link partner */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002343 u16 pause_result;
2344
David S. Millerc0700f92008-12-16 23:53:20 -08002345 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002346
2347 /* resolve from gp_status in case of AN complete and not sgmii */
Yaniv Rosner7aa07112010-09-07 11:41:01 +00002348 if (phy->req_flow_ctrl != BNX2X_FLOW_CTRL_AUTO)
2349 vars->flow_ctrl = phy->req_flow_ctrl;
2350 else if (phy->req_line_speed != SPEED_AUTO_NEG)
2351 vars->flow_ctrl = params->req_fc_auto_adv;
2352 else if ((gp_status & MDIO_AN_CL73_OR_37_COMPLETE) &&
2353 (!(vars->phy_flags & PHY_SGMII_FLAG))) {
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002354 if (bnx2x_direct_parallel_detect_used(phy, params)) {
Yaniv Rosner15ddd2d2009-11-05 19:18:12 +02002355 vars->flow_ctrl = params->req_fc_auto_adv;
2356 return;
2357 }
Yaniv Rosner7846e472009-11-05 19:18:07 +02002358 if ((gp_status &
2359 (MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_AUTONEG_COMPLETE |
2360 MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_MR_LP_NP_AN_ABLE)) ==
2361 (MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_AUTONEG_COMPLETE |
2362 MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_MR_LP_NP_AN_ABLE)) {
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_CL73_IEEEB1,
2366 MDIO_CL73_IEEEB1_AN_ADV1,
2367 &ld_pause);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002368 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002369 MDIO_REG_BANK_CL73_IEEEB1,
2370 MDIO_CL73_IEEEB1_AN_LP_ADV1,
2371 &lp_pause);
Yaniv Rosner7846e472009-11-05 19:18:07 +02002372 pause_result = (ld_pause &
2373 MDIO_CL73_IEEEB1_AN_ADV1_PAUSE_MASK)
2374 >> 8;
2375 pause_result |= (lp_pause &
2376 MDIO_CL73_IEEEB1_AN_LP_ADV1_PAUSE_MASK)
2377 >> 10;
2378 DP(NETIF_MSG_LINK, "pause_result CL73 0x%x\n",
2379 pause_result);
2380 } else {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002381 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002382 MDIO_REG_BANK_COMBO_IEEE0,
2383 MDIO_COMBO_IEEE0_AUTO_NEG_ADV,
2384 &ld_pause);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002385 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002386 MDIO_REG_BANK_COMBO_IEEE0,
2387 MDIO_COMBO_IEEE0_AUTO_NEG_LINK_PARTNER_ABILITY1,
2388 &lp_pause);
Yaniv Rosner7846e472009-11-05 19:18:07 +02002389 pause_result = (ld_pause &
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002390 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK)>>5;
Yaniv Rosner7846e472009-11-05 19:18:07 +02002391 pause_result |= (lp_pause &
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002392 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK)>>7;
Yaniv Rosner7846e472009-11-05 19:18:07 +02002393 DP(NETIF_MSG_LINK, "pause_result CL37 0x%x\n",
2394 pause_result);
2395 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002396 bnx2x_pause_resolve(vars, pause_result);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002397 }
2398 DP(NETIF_MSG_LINK, "flow_ctrl 0x%x\n", vars->flow_ctrl);
2399}
2400
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002401static void bnx2x_check_fallback_to_cl37(struct bnx2x_phy *phy,
2402 struct link_params *params)
Eilon Greenstein239d6862009-08-12 08:23:04 +00002403{
2404 struct bnx2x *bp = params->bp;
2405 u16 rx_status, ustat_val, cl37_fsm_recieved;
2406 DP(NETIF_MSG_LINK, "bnx2x_check_fallback_to_cl37\n");
2407 /* Step 1: Make sure signal is detected */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002408 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002409 MDIO_REG_BANK_RX0,
2410 MDIO_RX0_RX_STATUS,
2411 &rx_status);
Eilon Greenstein239d6862009-08-12 08:23:04 +00002412 if ((rx_status & MDIO_RX0_RX_STATUS_SIGDET) !=
2413 (MDIO_RX0_RX_STATUS_SIGDET)) {
2414 DP(NETIF_MSG_LINK, "Signal is not detected. Restoring CL73."
2415 "rx_status(0x80b0) = 0x%x\n", rx_status);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002416 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002417 MDIO_REG_BANK_CL73_IEEEB0,
2418 MDIO_CL73_IEEEB0_CL73_AN_CONTROL,
2419 MDIO_CL73_IEEEB0_CL73_AN_CONTROL_AN_EN);
Eilon Greenstein239d6862009-08-12 08:23:04 +00002420 return;
2421 }
2422 /* Step 2: Check CL73 state machine */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002423 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002424 MDIO_REG_BANK_CL73_USERB0,
2425 MDIO_CL73_USERB0_CL73_USTAT1,
2426 &ustat_val);
Eilon Greenstein239d6862009-08-12 08:23:04 +00002427 if ((ustat_val &
2428 (MDIO_CL73_USERB0_CL73_USTAT1_LINK_STATUS_CHECK |
2429 MDIO_CL73_USERB0_CL73_USTAT1_AN_GOOD_CHECK_BAM37)) !=
2430 (MDIO_CL73_USERB0_CL73_USTAT1_LINK_STATUS_CHECK |
2431 MDIO_CL73_USERB0_CL73_USTAT1_AN_GOOD_CHECK_BAM37)) {
2432 DP(NETIF_MSG_LINK, "CL73 state-machine is not stable. "
2433 "ustat_val(0x8371) = 0x%x\n", ustat_val);
2434 return;
2435 }
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002436 /*
2437 * Step 3: Check CL37 Message Pages received to indicate LP
2438 * supports only CL37
2439 */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002440 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002441 MDIO_REG_BANK_REMOTE_PHY,
2442 MDIO_REMOTE_PHY_MISC_RX_STATUS,
2443 &cl37_fsm_recieved);
Eilon Greenstein239d6862009-08-12 08:23:04 +00002444 if ((cl37_fsm_recieved &
2445 (MDIO_REMOTE_PHY_MISC_RX_STATUS_CL37_FSM_RECEIVED_OVER1G_MSG |
2446 MDIO_REMOTE_PHY_MISC_RX_STATUS_CL37_FSM_RECEIVED_BRCM_OUI_MSG)) !=
2447 (MDIO_REMOTE_PHY_MISC_RX_STATUS_CL37_FSM_RECEIVED_OVER1G_MSG |
2448 MDIO_REMOTE_PHY_MISC_RX_STATUS_CL37_FSM_RECEIVED_BRCM_OUI_MSG)) {
2449 DP(NETIF_MSG_LINK, "No CL37 FSM were received. "
2450 "misc_rx_status(0x8330) = 0x%x\n",
2451 cl37_fsm_recieved);
2452 return;
2453 }
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002454 /*
2455 * The combined cl37/cl73 fsm state information indicating that
2456 * we are connected to a device which does not support cl73, but
2457 * does support cl37 BAM. In this case we disable cl73 and
2458 * restart cl37 auto-neg
2459 */
2460
Eilon Greenstein239d6862009-08-12 08:23:04 +00002461 /* Disable CL73 */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002462 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002463 MDIO_REG_BANK_CL73_IEEEB0,
2464 MDIO_CL73_IEEEB0_CL73_AN_CONTROL,
2465 0);
Eilon Greenstein239d6862009-08-12 08:23:04 +00002466 /* Restart CL37 autoneg */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002467 bnx2x_restart_autoneg(phy, params, 0);
Eilon Greenstein239d6862009-08-12 08:23:04 +00002468 DP(NETIF_MSG_LINK, "Disabling CL73, and restarting CL37 autoneg\n");
2469}
Yaniv Rosner7aa07112010-09-07 11:41:01 +00002470
2471static void bnx2x_xgxs_an_resolve(struct bnx2x_phy *phy,
2472 struct link_params *params,
2473 struct link_vars *vars,
2474 u32 gp_status)
2475{
2476 if (gp_status & MDIO_AN_CL73_OR_37_COMPLETE)
2477 vars->link_status |=
2478 LINK_STATUS_AUTO_NEGOTIATE_COMPLETE;
2479
2480 if (bnx2x_direct_parallel_detect_used(phy, params))
2481 vars->link_status |=
2482 LINK_STATUS_PARALLEL_DETECTION_USED;
2483}
2484
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00002485static int bnx2x_link_settings_status(struct bnx2x_phy *phy,
2486 struct link_params *params,
2487 struct link_vars *vars)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002488{
2489 struct bnx2x *bp = params->bp;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002490 u16 new_line_speed, gp_status;
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00002491 int rc = 0;
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00002492
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00002493 /* Read gp_status */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002494 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002495 MDIO_REG_BANK_GP_STATUS,
2496 MDIO_GP_STATUS_TOP_AN_STATUS1,
2497 &gp_status);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00002498
Yaniv Rosner7aa07112010-09-07 11:41:01 +00002499 if (phy->req_line_speed == SPEED_AUTO_NEG)
2500 vars->link_status |= LINK_STATUS_AUTO_NEGOTIATE_ENABLED;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002501 if (gp_status & MDIO_GP_STATUS_TOP_AN_STATUS1_LINK_STATUS) {
2502 DP(NETIF_MSG_LINK, "phy link up gp_status=0x%x\n",
2503 gp_status);
2504
2505 vars->phy_link_up = 1;
2506 vars->link_status |= LINK_STATUS_LINK_UP;
2507
2508 if (gp_status & MDIO_GP_STATUS_TOP_AN_STATUS1_DUPLEX_STATUS)
2509 vars->duplex = DUPLEX_FULL;
2510 else
2511 vars->duplex = DUPLEX_HALF;
2512
Yaniv Rosner7aa07112010-09-07 11:41:01 +00002513 if (SINGLE_MEDIA_DIRECT(params)) {
2514 bnx2x_flow_ctrl_resolve(phy, params, vars, gp_status);
2515 if (phy->req_line_speed == SPEED_AUTO_NEG)
2516 bnx2x_xgxs_an_resolve(phy, params, vars,
2517 gp_status);
2518 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002519
2520 switch (gp_status & GP_STATUS_SPEED_MASK) {
2521 case GP_STATUS_10M:
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00002522 new_line_speed = SPEED_10;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002523 if (vars->duplex == DUPLEX_FULL)
2524 vars->link_status |= LINK_10TFD;
2525 else
2526 vars->link_status |= LINK_10THD;
2527 break;
2528
2529 case GP_STATUS_100M:
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00002530 new_line_speed = SPEED_100;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002531 if (vars->duplex == DUPLEX_FULL)
2532 vars->link_status |= LINK_100TXFD;
2533 else
2534 vars->link_status |= LINK_100TXHD;
2535 break;
2536
2537 case GP_STATUS_1G:
2538 case GP_STATUS_1G_KX:
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00002539 new_line_speed = SPEED_1000;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002540 if (vars->duplex == DUPLEX_FULL)
2541 vars->link_status |= LINK_1000TFD;
2542 else
2543 vars->link_status |= LINK_1000THD;
2544 break;
2545
2546 case GP_STATUS_2_5G:
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00002547 new_line_speed = SPEED_2500;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002548 if (vars->duplex == DUPLEX_FULL)
2549 vars->link_status |= LINK_2500TFD;
2550 else
2551 vars->link_status |= LINK_2500THD;
2552 break;
2553
2554 case GP_STATUS_5G:
2555 case GP_STATUS_6G:
2556 DP(NETIF_MSG_LINK,
2557 "link speed unsupported gp_status 0x%x\n",
2558 gp_status);
2559 return -EINVAL;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00002560
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002561 case GP_STATUS_10G_KX4:
2562 case GP_STATUS_10G_HIG:
2563 case GP_STATUS_10G_CX4:
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00002564 new_line_speed = SPEED_10000;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002565 vars->link_status |= LINK_10GTFD;
2566 break;
2567
2568 case GP_STATUS_12G_HIG:
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00002569 new_line_speed = SPEED_12000;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002570 vars->link_status |= LINK_12GTFD;
2571 break;
2572
2573 case GP_STATUS_12_5G:
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00002574 new_line_speed = SPEED_12500;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002575 vars->link_status |= LINK_12_5GTFD;
2576 break;
2577
2578 case GP_STATUS_13G:
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00002579 new_line_speed = SPEED_13000;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002580 vars->link_status |= LINK_13GTFD;
2581 break;
2582
2583 case GP_STATUS_15G:
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00002584 new_line_speed = SPEED_15000;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002585 vars->link_status |= LINK_15GTFD;
2586 break;
2587
2588 case GP_STATUS_16G:
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00002589 new_line_speed = SPEED_16000;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002590 vars->link_status |= LINK_16GTFD;
2591 break;
2592
2593 default:
2594 DP(NETIF_MSG_LINK,
2595 "link speed unsupported gp_status 0x%x\n",
2596 gp_status);
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00002597 return -EINVAL;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002598 }
2599
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00002600 vars->line_speed = new_line_speed;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002601
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002602 } else { /* link_down */
2603 DP(NETIF_MSG_LINK, "phy link down\n");
2604
2605 vars->phy_link_up = 0;
Yaniv Rosner57963ed2008-08-13 15:55:28 -07002606
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002607 vars->duplex = DUPLEX_FULL;
David S. Millerc0700f92008-12-16 23:53:20 -08002608 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002609 vars->mac_type = MAC_TYPE_NONE;
Eilon Greenstein239d6862009-08-12 08:23:04 +00002610
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00002611 if ((phy->req_line_speed == SPEED_AUTO_NEG) &&
2612 SINGLE_MEDIA_DIRECT(params)) {
Eilon Greenstein239d6862009-08-12 08:23:04 +00002613 /* Check signal is detected */
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00002614 bnx2x_check_fallback_to_cl37(phy, params);
Eilon Greenstein239d6862009-08-12 08:23:04 +00002615 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002616 }
2617
Frans Pop2381a552010-03-24 07:57:36 +00002618 DP(NETIF_MSG_LINK, "gp_status 0x%x phy_link_up %x line_speed %x\n",
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002619 gp_status, vars->phy_link_up, vars->line_speed);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002620 DP(NETIF_MSG_LINK, "duplex %x flow_ctrl 0x%x link_status 0x%x\n",
2621 vars->duplex, vars->flow_ctrl, vars->link_status);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002622 return rc;
2623}
2624
Eilon Greensteined8680a2009-02-12 08:37:12 +00002625static void bnx2x_set_gmii_tx_driver(struct link_params *params)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002626{
2627 struct bnx2x *bp = params->bp;
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002628 struct bnx2x_phy *phy = &params->phy[INT_PHY];
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002629 u16 lp_up2;
2630 u16 tx_driver;
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00002631 u16 bank;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002632
2633 /* read precomp */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002634 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002635 MDIO_REG_BANK_OVER_1G,
2636 MDIO_OVER_1G_LP_UP2, &lp_up2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002637
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002638 /* bits [10:7] at lp_up2, positioned at [15:12] */
2639 lp_up2 = (((lp_up2 & MDIO_OVER_1G_LP_UP2_PREEMPHASIS_MASK) >>
2640 MDIO_OVER_1G_LP_UP2_PREEMPHASIS_SHIFT) <<
2641 MDIO_TX0_TX_DRIVER_PREEMPHASIS_SHIFT);
2642
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00002643 if (lp_up2 == 0)
2644 return;
2645
2646 for (bank = MDIO_REG_BANK_TX0; bank <= MDIO_REG_BANK_TX3;
2647 bank += (MDIO_REG_BANK_TX1 - MDIO_REG_BANK_TX0)) {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002648 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002649 bank,
2650 MDIO_TX0_TX_DRIVER, &tx_driver);
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00002651
2652 /* replace tx_driver bits [15:12] */
2653 if (lp_up2 !=
2654 (tx_driver & MDIO_TX0_TX_DRIVER_PREEMPHASIS_MASK)) {
2655 tx_driver &= ~MDIO_TX0_TX_DRIVER_PREEMPHASIS_MASK;
2656 tx_driver |= lp_up2;
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002657 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002658 bank,
2659 MDIO_TX0_TX_DRIVER, tx_driver);
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00002660 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002661 }
2662}
2663
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00002664static int bnx2x_emac_program(struct link_params *params,
2665 struct link_vars *vars)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002666{
2667 struct bnx2x *bp = params->bp;
2668 u8 port = params->port;
2669 u16 mode = 0;
2670
2671 DP(NETIF_MSG_LINK, "setting link speed & duplex\n");
2672 bnx2x_bits_dis(bp, GRCBASE_EMAC0 + port*0x400 +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002673 EMAC_REG_EMAC_MODE,
2674 (EMAC_MODE_25G_MODE |
2675 EMAC_MODE_PORT_MII_10M |
2676 EMAC_MODE_HALF_DUPLEX));
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00002677 switch (vars->line_speed) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002678 case SPEED_10:
2679 mode |= EMAC_MODE_PORT_MII_10M;
2680 break;
2681
2682 case SPEED_100:
2683 mode |= EMAC_MODE_PORT_MII;
2684 break;
2685
2686 case SPEED_1000:
2687 mode |= EMAC_MODE_PORT_GMII;
2688 break;
2689
2690 case SPEED_2500:
2691 mode |= (EMAC_MODE_25G_MODE | EMAC_MODE_PORT_GMII);
2692 break;
2693
2694 default:
2695 /* 10G not valid for EMAC */
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00002696 DP(NETIF_MSG_LINK, "Invalid line_speed 0x%x\n",
2697 vars->line_speed);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002698 return -EINVAL;
2699 }
2700
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00002701 if (vars->duplex == DUPLEX_HALF)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002702 mode |= EMAC_MODE_HALF_DUPLEX;
2703 bnx2x_bits_en(bp,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002704 GRCBASE_EMAC0 + port*0x400 + EMAC_REG_EMAC_MODE,
2705 mode);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002706
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00002707 bnx2x_set_led(params, vars, LED_MODE_OPER, vars->line_speed);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002708 return 0;
2709}
2710
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00002711static void bnx2x_set_preemphasis(struct bnx2x_phy *phy,
2712 struct link_params *params)
2713{
2714
2715 u16 bank, i = 0;
2716 struct bnx2x *bp = params->bp;
2717
2718 for (bank = MDIO_REG_BANK_RX0, i = 0; bank <= MDIO_REG_BANK_RX3;
2719 bank += (MDIO_REG_BANK_RX1-MDIO_REG_BANK_RX0), i++) {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002720 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00002721 bank,
2722 MDIO_RX0_RX_EQ_BOOST,
2723 phy->rx_preemphasis[i]);
2724 }
2725
2726 for (bank = MDIO_REG_BANK_TX0, i = 0; bank <= MDIO_REG_BANK_TX3;
2727 bank += (MDIO_REG_BANK_TX1 - MDIO_REG_BANK_TX0), i++) {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002728 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00002729 bank,
2730 MDIO_TX0_TX_DRIVER,
2731 phy->tx_preemphasis[i]);
2732 }
2733}
2734
2735static void bnx2x_init_internal_phy(struct bnx2x_phy *phy,
2736 struct link_params *params,
2737 struct link_vars *vars)
2738{
2739 struct bnx2x *bp = params->bp;
2740 u8 enable_cl73 = (SINGLE_MEDIA_DIRECT(params) ||
2741 (params->loopback_mode == LOOPBACK_XGXS));
2742 if (!(vars->phy_flags & PHY_SGMII_FLAG)) {
2743 if (SINGLE_MEDIA_DIRECT(params) &&
2744 (params->feature_config_flags &
2745 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED))
2746 bnx2x_set_preemphasis(phy, params);
2747
2748 /* forced speed requested? */
2749 if (vars->line_speed != SPEED_AUTO_NEG ||
2750 (SINGLE_MEDIA_DIRECT(params) &&
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002751 params->loopback_mode == LOOPBACK_EXT)) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00002752 DP(NETIF_MSG_LINK, "not SGMII, no AN\n");
2753
2754 /* disable autoneg */
2755 bnx2x_set_autoneg(phy, params, vars, 0);
2756
2757 /* program speed and duplex */
2758 bnx2x_program_serdes(phy, params, vars);
2759
2760 } else { /* AN_mode */
2761 DP(NETIF_MSG_LINK, "not SGMII, AN\n");
2762
2763 /* AN enabled */
2764 bnx2x_set_brcm_cl37_advertisment(phy, params);
2765
2766 /* program duplex & pause advertisement (for aneg) */
2767 bnx2x_set_ieee_aneg_advertisment(phy, params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002768 vars->ieee_fc);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00002769
2770 /* enable autoneg */
2771 bnx2x_set_autoneg(phy, params, vars, enable_cl73);
2772
2773 /* enable and restart AN */
2774 bnx2x_restart_autoneg(phy, params, enable_cl73);
2775 }
2776
2777 } else { /* SGMII mode */
2778 DP(NETIF_MSG_LINK, "SGMII\n");
2779
2780 bnx2x_initialize_sgmii_process(phy, params, vars);
2781 }
2782}
2783
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00002784static int bnx2x_init_serdes(struct bnx2x_phy *phy,
2785 struct link_params *params,
2786 struct link_vars *vars)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00002787{
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00002788 int rc;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00002789 vars->phy_flags |= PHY_SGMII_FLAG;
2790 bnx2x_calc_ieee_aneg_adv(phy, params, &vars->ieee_fc);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002791 bnx2x_set_aer_mmd_serdes(params->bp, phy);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00002792 rc = bnx2x_reset_unicore(params, phy, 1);
2793 /* reset the SerDes and wait for reset bit return low */
2794 if (rc != 0)
2795 return rc;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002796 bnx2x_set_aer_mmd_serdes(params->bp, phy);
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002797
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00002798 return rc;
2799}
2800
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00002801static int bnx2x_init_xgxs(struct bnx2x_phy *phy,
2802 struct link_params *params,
2803 struct link_vars *vars)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00002804{
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00002805 int rc;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00002806 vars->phy_flags = PHY_XGXS_FLAG;
2807 if ((phy->req_line_speed &&
2808 ((phy->req_line_speed == SPEED_100) ||
2809 (phy->req_line_speed == SPEED_10))) ||
2810 (!phy->req_line_speed &&
2811 (phy->speed_cap_mask >=
2812 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL) &&
2813 (phy->speed_cap_mask <
2814 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)
2815 ))
2816 vars->phy_flags |= PHY_SGMII_FLAG;
2817 else
2818 vars->phy_flags &= ~PHY_SGMII_FLAG;
2819
2820 bnx2x_calc_ieee_aneg_adv(phy, params, &vars->ieee_fc);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002821 bnx2x_set_aer_mmd_xgxs(params, phy);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00002822 bnx2x_set_master_ln(params, phy);
2823
2824 rc = bnx2x_reset_unicore(params, phy, 0);
2825 /* reset the SerDes and wait for reset bit return low */
2826 if (rc != 0)
2827 return rc;
2828
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002829 bnx2x_set_aer_mmd_xgxs(params, phy);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00002830
2831 /* setting the masterLn_def again after the reset */
2832 bnx2x_set_master_ln(params, phy);
2833 bnx2x_set_swap_lanes(params, phy);
2834
2835 return rc;
2836}
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00002837
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00002838static u16 bnx2x_wait_reset_complete(struct bnx2x *bp,
Yaniv Rosner6d870c32011-01-31 04:22:20 +00002839 struct bnx2x_phy *phy,
2840 struct link_params *params)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002841{
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00002842 u16 cnt, ctrl;
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002843 /* Wait for soft reset to get cleared up to 1 sec */
Yaniv Rosner62b29a52010-09-07 11:40:58 +00002844 for (cnt = 0; cnt < 1000; cnt++) {
2845 bnx2x_cl45_read(bp, phy,
2846 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, &ctrl);
2847 if (!(ctrl & (1<<15)))
2848 break;
2849 msleep(1);
2850 }
Yaniv Rosner6d870c32011-01-31 04:22:20 +00002851
2852 if (cnt == 1000)
2853 netdev_err(bp->dev, "Warning: PHY was not initialized,"
2854 " Port %d\n",
2855 params->port);
Yaniv Rosner62b29a52010-09-07 11:40:58 +00002856 DP(NETIF_MSG_LINK, "control reg 0x%x (after %d ms)\n", ctrl, cnt);
2857 return cnt;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00002858}
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002859
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002860static void bnx2x_link_int_enable(struct link_params *params)
2861{
2862 u8 port = params->port;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002863 u32 mask;
2864 struct bnx2x *bp = params->bp;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00002865
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002866 /* Setting the status to report on link up for either XGXS or SerDes */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002867 if (params->switch_cfg == SWITCH_CFG_10G) {
2868 mask = (NIG_MASK_XGXS0_LINK10G |
2869 NIG_MASK_XGXS0_LINK_STATUS);
2870 DP(NETIF_MSG_LINK, "enabled XGXS interrupt\n");
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002871 if (!(SINGLE_MEDIA_DIRECT(params)) &&
2872 params->phy[INT_PHY].type !=
2873 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002874 mask |= NIG_MASK_MI_INT;
2875 DP(NETIF_MSG_LINK, "enabled external phy int\n");
2876 }
2877
2878 } else { /* SerDes */
2879 mask = NIG_MASK_SERDES0_LINK_STATUS;
2880 DP(NETIF_MSG_LINK, "enabled SerDes interrupt\n");
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002881 if (!(SINGLE_MEDIA_DIRECT(params)) &&
2882 params->phy[INT_PHY].type !=
2883 PORT_HW_CFG_SERDES_EXT_PHY_TYPE_NOT_CONN) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002884 mask |= NIG_MASK_MI_INT;
2885 DP(NETIF_MSG_LINK, "enabled external phy int\n");
2886 }
2887 }
2888 bnx2x_bits_en(bp,
2889 NIG_REG_MASK_INTERRUPT_PORT0 + port*4,
2890 mask);
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00002891
2892 DP(NETIF_MSG_LINK, "port %x, is_xgxs %x, int_status 0x%x\n", port,
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002893 (params->switch_cfg == SWITCH_CFG_10G),
2894 REG_RD(bp, NIG_REG_STATUS_INTERRUPT_PORT0 + port*4));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002895 DP(NETIF_MSG_LINK, " int_mask 0x%x, MI_INT %x, SERDES_LINK %x\n",
2896 REG_RD(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4),
2897 REG_RD(bp, NIG_REG_EMAC0_STATUS_MISC_MI_INT + port*0x18),
2898 REG_RD(bp, NIG_REG_SERDES0_STATUS_LINK_STATUS+port*0x3c));
2899 DP(NETIF_MSG_LINK, " 10G %x, XGXS_LINK %x\n",
2900 REG_RD(bp, NIG_REG_XGXS0_STATUS_LINK10G + port*0x68),
2901 REG_RD(bp, NIG_REG_XGXS0_STATUS_LINK_STATUS + port*0x68));
2902}
2903
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002904static void bnx2x_rearm_latch_signal(struct bnx2x *bp, u8 port,
2905 u8 exp_mi_int)
Eilon Greenstein2f904462009-08-12 08:22:16 +00002906{
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002907 u32 latch_status = 0;
2908
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002909 /*
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002910 * Disable the MI INT ( external phy int ) by writing 1 to the
2911 * status register. Link down indication is high-active-signal,
2912 * so in this case we need to write the status to clear the XOR
Eilon Greenstein2f904462009-08-12 08:22:16 +00002913 */
2914 /* Read Latched signals */
2915 latch_status = REG_RD(bp,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002916 NIG_REG_LATCH_STATUS_0 + port*8);
2917 DP(NETIF_MSG_LINK, "latch_status = 0x%x\n", latch_status);
Eilon Greenstein2f904462009-08-12 08:22:16 +00002918 /* Handle only those with latched-signal=up.*/
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002919 if (exp_mi_int)
2920 bnx2x_bits_en(bp,
2921 NIG_REG_STATUS_INTERRUPT_PORT0
2922 + port*4,
2923 NIG_STATUS_EMAC0_MI_INT);
2924 else
2925 bnx2x_bits_dis(bp,
2926 NIG_REG_STATUS_INTERRUPT_PORT0
2927 + port*4,
2928 NIG_STATUS_EMAC0_MI_INT);
2929
Eilon Greenstein2f904462009-08-12 08:22:16 +00002930 if (latch_status & 1) {
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002931
Eilon Greenstein2f904462009-08-12 08:22:16 +00002932 /* For all latched-signal=up : Re-Arm Latch signals */
2933 REG_WR(bp, NIG_REG_LATCH_STATUS_0 + port*8,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002934 (latch_status & 0xfffe) | (latch_status & 1));
Eilon Greenstein2f904462009-08-12 08:22:16 +00002935 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002936 /* For all latched-signal=up,Write original_signal to status */
Eilon Greenstein2f904462009-08-12 08:22:16 +00002937}
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002938
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002939static void bnx2x_link_int_ack(struct link_params *params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002940 struct link_vars *vars, u8 is_10g)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002941{
2942 struct bnx2x *bp = params->bp;
2943 u8 port = params->port;
2944
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002945 /*
2946 * First reset all status we assume only one line will be
2947 * change at a time
2948 */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002949 bnx2x_bits_dis(bp, NIG_REG_STATUS_INTERRUPT_PORT0 + port*4,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002950 (NIG_STATUS_XGXS0_LINK10G |
2951 NIG_STATUS_XGXS0_LINK_STATUS |
2952 NIG_STATUS_SERDES0_LINK_STATUS));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002953 if (vars->phy_link_up) {
2954 if (is_10g) {
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002955 /*
2956 * Disable the 10G link interrupt by writing 1 to the
2957 * status register
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002958 */
2959 DP(NETIF_MSG_LINK, "10G XGXS phy link up\n");
2960 bnx2x_bits_en(bp,
2961 NIG_REG_STATUS_INTERRUPT_PORT0 + port*4,
2962 NIG_STATUS_XGXS0_LINK10G);
2963
2964 } else if (params->switch_cfg == SWITCH_CFG_10G) {
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002965 /*
2966 * Disable the link interrupt by writing 1 to the
2967 * relevant lane in the status register
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002968 */
2969 u32 ser_lane = ((params->lane_config &
2970 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_MASK) >>
2971 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_SHIFT);
2972
Eilon Greenstein2f904462009-08-12 08:22:16 +00002973 DP(NETIF_MSG_LINK, "%d speed XGXS phy link up\n",
2974 vars->line_speed);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002975 bnx2x_bits_en(bp,
2976 NIG_REG_STATUS_INTERRUPT_PORT0 + port*4,
2977 ((1 << ser_lane) <<
2978 NIG_STATUS_XGXS0_LINK_STATUS_SIZE));
2979
2980 } else { /* SerDes */
2981 DP(NETIF_MSG_LINK, "SerDes phy link up\n");
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002982 /*
2983 * Disable the link interrupt by writing 1 to the status
2984 * register
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002985 */
2986 bnx2x_bits_en(bp,
2987 NIG_REG_STATUS_INTERRUPT_PORT0 + port*4,
2988 NIG_STATUS_SERDES0_LINK_STATUS);
2989 }
2990
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002991 }
2992}
2993
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00002994static int bnx2x_format_ver(u32 num, u8 *str, u16 *len)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002995{
2996 u8 *str_ptr = str;
2997 u32 mask = 0xf0000000;
2998 u8 shift = 8*4;
2999 u8 digit;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003000 u8 remove_leading_zeros = 1;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003001 if (*len < 10) {
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02003002 /* Need more than 10chars for this format */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003003 *str_ptr = '\0';
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003004 (*len)--;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003005 return -EINVAL;
3006 }
3007 while (shift > 0) {
3008
3009 shift -= 4;
3010 digit = ((num & mask) >> shift);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003011 if (digit == 0 && remove_leading_zeros) {
3012 mask = mask >> 4;
3013 continue;
3014 } else if (digit < 0xa)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003015 *str_ptr = digit + '0';
3016 else
3017 *str_ptr = digit - 0xa + 'a';
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003018 remove_leading_zeros = 0;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003019 str_ptr++;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003020 (*len)--;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003021 mask = mask >> 4;
3022 if (shift == 4*4) {
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003023 *str_ptr = '.';
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003024 str_ptr++;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003025 (*len)--;
3026 remove_leading_zeros = 1;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003027 }
3028 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003029 return 0;
3030}
3031
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003032
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00003033static int bnx2x_null_format_ver(u32 spirom_ver, u8 *str, u16 *len)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003034{
3035 str[0] = '\0';
3036 (*len)--;
3037 return 0;
3038}
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003039
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00003040int bnx2x_get_ext_phy_fw_version(struct link_params *params, u8 driver_loaded,
3041 u8 *version, u16 len)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003042{
Julia Lawall0376d5b2009-07-19 05:26:35 +00003043 struct bnx2x *bp;
Eilon Greensteina35da8d2009-02-12 08:37:02 +00003044 u32 spirom_ver = 0;
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00003045 int status = 0;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003046 u8 *ver_p = version;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003047 u16 remain_len = len;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003048 if (version == NULL || params == NULL)
3049 return -EINVAL;
Julia Lawall0376d5b2009-07-19 05:26:35 +00003050 bp = params->bp;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003051
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003052 /* Extract first external phy*/
3053 version[0] = '\0';
3054 spirom_ver = REG_RD(bp, params->phy[EXT_PHY1].ver_addr);
Eilon Greensteina35da8d2009-02-12 08:37:02 +00003055
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003056 if (params->phy[EXT_PHY1].format_fw_ver) {
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003057 status |= params->phy[EXT_PHY1].format_fw_ver(spirom_ver,
3058 ver_p,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003059 &remain_len);
3060 ver_p += (len - remain_len);
3061 }
3062 if ((params->num_phys == MAX_PHYS) &&
3063 (params->phy[EXT_PHY2].ver_addr != 0)) {
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003064 spirom_ver = REG_RD(bp, params->phy[EXT_PHY2].ver_addr);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003065 if (params->phy[EXT_PHY2].format_fw_ver) {
3066 *ver_p = '/';
3067 ver_p++;
3068 remain_len--;
3069 status |= params->phy[EXT_PHY2].format_fw_ver(
3070 spirom_ver,
3071 ver_p,
3072 &remain_len);
3073 ver_p = version + (len - remain_len);
3074 }
3075 }
3076 *ver_p = '\0';
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003077 return status;
3078}
3079
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003080static void bnx2x_set_xgxs_loopback(struct bnx2x_phy *phy,
Yaniv Rosner62b29a52010-09-07 11:40:58 +00003081 struct link_params *params)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003082{
3083 u8 port = params->port;
3084 struct bnx2x *bp = params->bp;
3085
Yaniv Rosner62b29a52010-09-07 11:40:58 +00003086 if (phy->req_line_speed != SPEED_1000) {
Eilon Greenstein6378c022008-08-13 15:59:25 -07003087 u32 md_devad;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003088
3089 DP(NETIF_MSG_LINK, "XGXS 10G loopback enable\n");
3090
3091 /* change the uni_phy_addr in the nig */
3092 md_devad = REG_RD(bp, (NIG_REG_XGXS0_CTRL_MD_DEVAD +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003093 port*0x18));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003094
3095 REG_WR(bp, NIG_REG_XGXS0_CTRL_MD_DEVAD + port*0x18, 0x5);
3096
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003097 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003098 5,
3099 (MDIO_REG_BANK_AER_BLOCK +
3100 (MDIO_AER_BLOCK_AER_REG & 0xf)),
3101 0x2800);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003102
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003103 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003104 5,
3105 (MDIO_REG_BANK_CL73_IEEEB0 +
3106 (MDIO_CL73_IEEEB0_CL73_AN_CONTROL & 0xf)),
3107 0x6041);
Eilon Greenstein38582762009-01-14 06:44:16 +00003108 msleep(200);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003109 /* set aer mmd back */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00003110 bnx2x_set_aer_mmd_xgxs(params, phy);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003111
3112 /* and md_devad */
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003113 REG_WR(bp, NIG_REG_XGXS0_CTRL_MD_DEVAD + port*0x18, md_devad);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003114 } else {
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003115 u16 mii_ctrl;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003116 DP(NETIF_MSG_LINK, "XGXS 1G loopback enable\n");
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003117 bnx2x_cl45_read(bp, phy, 5,
3118 (MDIO_REG_BANK_COMBO_IEEE0 +
3119 (MDIO_COMBO_IEEE0_MII_CONTROL & 0xf)),
3120 &mii_ctrl);
3121 bnx2x_cl45_write(bp, phy, 5,
3122 (MDIO_REG_BANK_COMBO_IEEE0 +
3123 (MDIO_COMBO_IEEE0_MII_CONTROL & 0xf)),
3124 mii_ctrl |
3125 MDIO_COMBO_IEEO_MII_CONTROL_LOOPBACK);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003126 }
3127}
3128
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00003129int bnx2x_set_led(struct link_params *params,
3130 struct link_vars *vars, u8 mode, u32 speed)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003131{
Yaniv Rosner7846e472009-11-05 19:18:07 +02003132 u8 port = params->port;
3133 u16 hw_led_mode = params->hw_led_mode;
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00003134 int rc = 0;
3135 u8 phy_idx;
Eilon Greenstein345b5d52008-08-13 15:58:12 -07003136 u32 tmp;
3137 u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
Yaniv Rosner7846e472009-11-05 19:18:07 +02003138 struct bnx2x *bp = params->bp;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003139 DP(NETIF_MSG_LINK, "bnx2x_set_led: port %x, mode %d\n", port, mode);
3140 DP(NETIF_MSG_LINK, "speed 0x%x, hw_led_mode 0x%x\n",
3141 speed, hw_led_mode);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00003142 /* In case */
3143 for (phy_idx = EXT_PHY1; phy_idx < MAX_PHYS; phy_idx++) {
3144 if (params->phy[phy_idx].set_link_led) {
3145 params->phy[phy_idx].set_link_led(
3146 &params->phy[phy_idx], params, mode);
3147 }
3148 }
3149
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003150 switch (mode) {
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00003151 case LED_MODE_FRONT_PANEL_OFF:
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003152 case LED_MODE_OFF:
3153 REG_WR(bp, NIG_REG_LED_10G_P0 + port*4, 0);
3154 REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003155 SHARED_HW_CFG_LED_MAC1);
Eilon Greenstein345b5d52008-08-13 15:58:12 -07003156
3157 tmp = EMAC_RD(bp, EMAC_REG_EMAC_LED);
Eilon Greenstein3196a882008-08-13 15:58:49 -07003158 EMAC_WR(bp, EMAC_REG_EMAC_LED, (tmp | EMAC_LED_OVERRIDE));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003159 break;
3160
3161 case LED_MODE_OPER:
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003162 /*
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00003163 * For all other phys, OPER mode is same as ON, so in case
3164 * link is down, do nothing
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003165 */
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00003166 if (!vars->link_up)
3167 break;
3168 case LED_MODE_ON:
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00003169 if (((params->phy[EXT_PHY1].type ==
3170 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727) ||
3171 (params->phy[EXT_PHY1].type ==
3172 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8722)) &&
Yaniv Rosner1f483532011-01-18 04:33:31 +00003173 CHIP_IS_E2(bp) && params->num_phys == 2) {
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003174 /*
3175 * This is a work-around for E2+8727 Configurations
3176 */
Yaniv Rosner1f483532011-01-18 04:33:31 +00003177 if (mode == LED_MODE_ON ||
3178 speed == SPEED_10000){
3179 REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4, 0);
3180 REG_WR(bp, NIG_REG_LED_10G_P0 + port*4, 1);
3181
3182 tmp = EMAC_RD(bp, EMAC_REG_EMAC_LED);
3183 EMAC_WR(bp, EMAC_REG_EMAC_LED,
3184 (tmp | EMAC_LED_OVERRIDE));
3185 return rc;
3186 }
3187 } else if (SINGLE_MEDIA_DIRECT(params)) {
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003188 /*
3189 * This is a work-around for HW issue found when link
3190 * is up in CL73
3191 */
Yaniv Rosner7846e472009-11-05 19:18:07 +02003192 REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4, 0);
3193 REG_WR(bp, NIG_REG_LED_10G_P0 + port*4, 1);
3194 } else {
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003195 REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4, hw_led_mode);
Yaniv Rosner7846e472009-11-05 19:18:07 +02003196 }
3197
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003198 REG_WR(bp, NIG_REG_LED_CONTROL_OVERRIDE_TRAFFIC_P0 + port*4, 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003199 /* Set blinking rate to ~15.9Hz */
3200 REG_WR(bp, NIG_REG_LED_CONTROL_BLINK_RATE_P0 + port*4,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003201 LED_BLINK_RATE_VAL);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003202 REG_WR(bp, NIG_REG_LED_CONTROL_BLINK_RATE_ENA_P0 +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003203 port*4, 1);
Eilon Greenstein345b5d52008-08-13 15:58:12 -07003204 tmp = EMAC_RD(bp, EMAC_REG_EMAC_LED);
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003205 EMAC_WR(bp, EMAC_REG_EMAC_LED, (tmp & (~EMAC_LED_OVERRIDE)));
Eilon Greenstein345b5d52008-08-13 15:58:12 -07003206
Yaniv Rosner7846e472009-11-05 19:18:07 +02003207 if (CHIP_IS_E1(bp) &&
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003208 ((speed == SPEED_2500) ||
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003209 (speed == SPEED_1000) ||
3210 (speed == SPEED_100) ||
3211 (speed == SPEED_10))) {
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003212 /*
3213 * On Everest 1 Ax chip versions for speeds less than
3214 * 10G LED scheme is different
3215 */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003216 REG_WR(bp, NIG_REG_LED_CONTROL_OVERRIDE_TRAFFIC_P0
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003217 + port*4, 1);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003218 REG_WR(bp, NIG_REG_LED_CONTROL_TRAFFIC_P0 +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003219 port*4, 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003220 REG_WR(bp, NIG_REG_LED_CONTROL_BLINK_TRAFFIC_P0 +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003221 port*4, 1);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003222 }
3223 break;
3224
3225 default:
3226 rc = -EINVAL;
3227 DP(NETIF_MSG_LINK, "bnx2x_set_led: Invalid led mode %d\n",
3228 mode);
3229 break;
3230 }
3231 return rc;
3232
3233}
3234
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003235/*
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003236 * This function comes to reflect the actual link state read DIRECTLY from the
3237 * HW
3238 */
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00003239int bnx2x_test_link(struct link_params *params, struct link_vars *vars,
3240 u8 is_serdes)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003241{
3242 struct bnx2x *bp = params->bp;
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00003243 u16 gp_status = 0, phy_index = 0;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003244 u8 ext_phy_link_up = 0, serdes_phy_type;
3245 struct link_vars temp_vars;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003246
Yaniv Rosnercd2be892011-01-31 04:21:45 +00003247 CL22_RD_OVER_CL45(bp, &params->phy[INT_PHY],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003248 MDIO_REG_BANK_GP_STATUS,
3249 MDIO_GP_STATUS_TOP_AN_STATUS1,
3250 &gp_status);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003251 /* link is up only if both local phy and external phy are up */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003252 if (!(gp_status & MDIO_GP_STATUS_TOP_AN_STATUS1_LINK_STATUS))
3253 return -ESRCH;
3254
3255 switch (params->num_phys) {
3256 case 1:
3257 /* No external PHY */
3258 return 0;
3259 case 2:
3260 ext_phy_link_up = params->phy[EXT_PHY1].read_status(
3261 &params->phy[EXT_PHY1],
3262 params, &temp_vars);
3263 break;
3264 case 3: /* Dual Media */
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00003265 for (phy_index = EXT_PHY1; phy_index < params->num_phys;
3266 phy_index++) {
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003267 serdes_phy_type = ((params->phy[phy_index].media_type ==
3268 ETH_PHY_SFP_FIBER) ||
3269 (params->phy[phy_index].media_type ==
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00003270 ETH_PHY_XFP_FIBER) ||
3271 (params->phy[phy_index].media_type ==
3272 ETH_PHY_DA_TWINAX));
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003273
3274 if (is_serdes != serdes_phy_type)
3275 continue;
3276 if (params->phy[phy_index].read_status) {
3277 ext_phy_link_up |=
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00003278 params->phy[phy_index].read_status(
3279 &params->phy[phy_index],
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003280 params, &temp_vars);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003281 }
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00003282 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003283 break;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003284 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003285 if (ext_phy_link_up)
3286 return 0;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003287 return -ESRCH;
3288}
3289
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00003290static int bnx2x_link_initialize(struct link_params *params,
3291 struct link_vars *vars)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003292{
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00003293 int rc = 0;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003294 u8 phy_index, non_ext_phy;
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00003295 struct bnx2x *bp = params->bp;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003296 /*
3297 * In case of external phy existence, the line speed would be the
3298 * line speed linked up by the external phy. In case it is direct
3299 * only, then the line_speed during initialization will be
3300 * equal to the req_line_speed
3301 */
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00003302 vars->line_speed = params->phy[INT_PHY].req_line_speed;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003303
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003304 /*
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00003305 * Initialize the internal phy in case this is a direct board
3306 * (no external phys), or this board has external phy which requires
3307 * to first.
3308 */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003309
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00003310 if (params->phy[INT_PHY].config_init)
3311 params->phy[INT_PHY].config_init(
3312 &params->phy[INT_PHY],
3313 params, vars);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003314
3315 /* init ext phy and enable link state int */
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00003316 non_ext_phy = (SINGLE_MEDIA_DIRECT(params) ||
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003317 (params->loopback_mode == LOOPBACK_XGXS));
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003318
3319 if (non_ext_phy ||
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00003320 (params->phy[EXT_PHY1].flags & FLAGS_INIT_XGXS_FIRST) ||
Eilon Greenstein8660d8c2009-03-02 08:01:02 +00003321 (params->loopback_mode == LOOPBACK_EXT_PHY)) {
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00003322 struct bnx2x_phy *phy = &params->phy[INT_PHY];
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003323 if (vars->line_speed == SPEED_AUTO_NEG)
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00003324 bnx2x_set_parallel_detection(phy, params);
3325 bnx2x_init_internal_phy(phy, params, vars);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003326 }
3327
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00003328 /* Init external phy*/
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003329 if (!non_ext_phy)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003330 for (phy_index = EXT_PHY1; phy_index < params->num_phys;
3331 phy_index++) {
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003332 /*
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003333 * No need to initialize second phy in case of first
3334 * phy only selection. In case of second phy, we do
3335 * need to initialize the first phy, since they are
3336 * connected.
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003337 */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003338 if (phy_index == EXT_PHY2 &&
3339 (bnx2x_phy_selection(params) ==
3340 PORT_HW_CFG_PHY_SELECTION_FIRST_PHY)) {
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003341 DP(NETIF_MSG_LINK, "Ignoring second phy\n");
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003342 continue;
3343 }
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003344 params->phy[phy_index].config_init(
3345 &params->phy[phy_index],
3346 params, vars);
3347 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003348
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +00003349 /* Reset the interrupt indication after phy was initialized */
3350 bnx2x_bits_dis(bp, NIG_REG_STATUS_INTERRUPT_PORT0 +
3351 params->port*4,
3352 (NIG_STATUS_XGXS0_LINK10G |
3353 NIG_STATUS_XGXS0_LINK_STATUS |
3354 NIG_STATUS_SERDES0_LINK_STATUS |
3355 NIG_MASK_MI_INT));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003356 return rc;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003357}
3358
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003359static void bnx2x_int_link_reset(struct bnx2x_phy *phy,
3360 struct link_params *params)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003361{
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003362 /* reset the SerDes/XGXS */
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003363 REG_WR(params->bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_CLEAR,
3364 (0x1ff << (params->port*16)));
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003365}
3366
3367static void bnx2x_common_ext_link_reset(struct bnx2x_phy *phy,
3368 struct link_params *params)
3369{
3370 struct bnx2x *bp = params->bp;
3371 u8 gpio_port;
3372 /* HW reset */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00003373 if (CHIP_IS_E2(bp))
3374 gpio_port = BP_PATH(bp);
3375 else
3376 gpio_port = params->port;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003377 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003378 MISC_REGISTERS_GPIO_OUTPUT_LOW,
3379 gpio_port);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003380 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003381 MISC_REGISTERS_GPIO_OUTPUT_LOW,
3382 gpio_port);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003383 DP(NETIF_MSG_LINK, "reset external PHY\n");
3384}
3385
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00003386static int bnx2x_update_link_down(struct link_params *params,
3387 struct link_vars *vars)
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003388{
3389 struct bnx2x *bp = params->bp;
3390 u8 port = params->port;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00003391
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003392 DP(NETIF_MSG_LINK, "Port %x: Link is down\n", port);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00003393 bnx2x_set_led(params, vars, LED_MODE_OFF, 0);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003394
3395 /* indicate no mac active */
3396 vars->mac_type = MAC_TYPE_NONE;
3397
3398 /* update shared memory */
3399 vars->link_status = 0;
3400 vars->line_speed = 0;
3401 bnx2x_update_mng(params, vars->link_status);
3402
3403 /* activate nig drain */
3404 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + port*4, 1);
3405
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00003406 /* disable emac */
3407 REG_WR(bp, NIG_REG_NIG_EMAC0_EN + port*4, 0);
3408
3409 msleep(10);
3410
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003411 /* reset BigMac */
3412 bnx2x_bmac_rx_disable(bp, params->port);
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003413 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
3414 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port));
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003415 return 0;
3416}
3417
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00003418static int bnx2x_update_link_up(struct link_params *params,
3419 struct link_vars *vars,
3420 u8 link_10g)
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003421{
3422 struct bnx2x *bp = params->bp;
3423 u8 port = params->port;
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00003424 int rc = 0;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00003425
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003426 vars->link_status |= LINK_STATUS_LINK_UP;
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00003427
Yaniv Rosner7aa07112010-09-07 11:41:01 +00003428 if (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX)
3429 vars->link_status |=
3430 LINK_STATUS_TX_FLOW_CONTROL_ENABLED;
3431
3432 if (vars->flow_ctrl & BNX2X_FLOW_CTRL_RX)
3433 vars->link_status |=
3434 LINK_STATUS_RX_FLOW_CONTROL_ENABLED;
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00003435
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003436 if (link_10g) {
3437 bnx2x_bmac_enable(params, vars, 0);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00003438 bnx2x_set_led(params, vars,
3439 LED_MODE_OPER, SPEED_10000);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003440 } else {
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003441 rc = bnx2x_emac_program(params, vars);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003442
Yaniv Rosner0c786f02009-11-05 19:18:32 +02003443 bnx2x_emac_enable(params, vars, 0);
3444
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003445 /* AN complete? */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003446 if ((vars->link_status & LINK_STATUS_AUTO_NEGOTIATE_COMPLETE)
3447 && (!(vars->phy_flags & PHY_SGMII_FLAG)) &&
3448 SINGLE_MEDIA_DIRECT(params))
3449 bnx2x_set_gmii_tx_driver(params);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003450 }
3451
3452 /* PBF - link up */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00003453 if (!(CHIP_IS_E2(bp)))
3454 rc |= bnx2x_pbf_update(params, vars->flow_ctrl,
3455 vars->line_speed);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003456
3457 /* disable drain */
3458 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + port*4, 0);
3459
3460 /* update shared memory */
3461 bnx2x_update_mng(params, vars->link_status);
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00003462 msleep(20);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003463 return rc;
3464}
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003465/*
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003466 * The bnx2x_link_update function should be called upon link
3467 * interrupt.
3468 * Link is considered up as follows:
3469 * - DIRECT_SINGLE_MEDIA - Only XGXS link (internal link) needs
3470 * to be up
3471 * - SINGLE_MEDIA - The link between the 577xx and the external
3472 * phy (XGXS) need to up as well as the external link of the
3473 * phy (PHY_EXT1)
3474 * - DUAL_MEDIA - The link between the 577xx and the first
3475 * external phy needs to be up, and at least one of the 2
3476 * external phy link must be up.
Yaniv Rosner62b29a52010-09-07 11:40:58 +00003477 */
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00003478int bnx2x_link_update(struct link_params *params, struct link_vars *vars)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003479{
3480 struct bnx2x *bp = params->bp;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003481 struct link_vars phy_vars[MAX_PHYS];
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003482 u8 port = params->port;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003483 u8 link_10g, phy_index;
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00003484 u8 ext_phy_link_up = 0, cur_link_up;
3485 int rc = 0;
Eilon Greenstein2f904462009-08-12 08:22:16 +00003486 u8 is_mi_int = 0;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003487 u16 ext_phy_line_speed = 0, prev_line_speed = vars->line_speed;
3488 u8 active_external_phy = INT_PHY;
3489 vars->link_status = 0;
3490 for (phy_index = INT_PHY; phy_index < params->num_phys;
3491 phy_index++) {
3492 phy_vars[phy_index].flow_ctrl = 0;
3493 phy_vars[phy_index].link_status = 0;
3494 phy_vars[phy_index].line_speed = 0;
3495 phy_vars[phy_index].duplex = DUPLEX_FULL;
3496 phy_vars[phy_index].phy_link_up = 0;
3497 phy_vars[phy_index].link_up = 0;
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00003498 phy_vars[phy_index].fault_detected = 0;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003499 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003500
3501 DP(NETIF_MSG_LINK, "port %x, XGXS?%x, int_status 0x%x\n",
Eilon Greenstein2f904462009-08-12 08:22:16 +00003502 port, (vars->phy_flags & PHY_XGXS_FLAG),
3503 REG_RD(bp, NIG_REG_STATUS_INTERRUPT_PORT0 + port*4));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003504
Eilon Greenstein2f904462009-08-12 08:22:16 +00003505 is_mi_int = (u8)(REG_RD(bp, NIG_REG_EMAC0_STATUS_MISC_MI_INT +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003506 port*0x18) > 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003507 DP(NETIF_MSG_LINK, "int_mask 0x%x MI_INT %x, SERDES_LINK %x\n",
Eilon Greenstein2f904462009-08-12 08:22:16 +00003508 REG_RD(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4),
3509 is_mi_int,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003510 REG_RD(bp, NIG_REG_SERDES0_STATUS_LINK_STATUS + port*0x3c));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003511
3512 DP(NETIF_MSG_LINK, " 10G %x, XGXS_LINK %x\n",
3513 REG_RD(bp, NIG_REG_XGXS0_STATUS_LINK10G + port*0x68),
3514 REG_RD(bp, NIG_REG_XGXS0_STATUS_LINK_STATUS + port*0x68));
3515
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00003516 /* disable emac */
3517 REG_WR(bp, NIG_REG_NIG_EMAC0_EN + port*4, 0);
3518
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003519 /*
3520 * Step 1:
3521 * Check external link change only for external phys, and apply
3522 * priority selection between them in case the link on both phys
3523 * is up. Note that the instead of the common vars, a temporary
3524 * vars argument is used since each phy may have different link/
3525 * speed/duplex result
3526 */
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003527 for (phy_index = EXT_PHY1; phy_index < params->num_phys;
3528 phy_index++) {
3529 struct bnx2x_phy *phy = &params->phy[phy_index];
3530 if (!phy->read_status)
3531 continue;
3532 /* Read link status and params of this ext phy */
3533 cur_link_up = phy->read_status(phy, params,
3534 &phy_vars[phy_index]);
3535 if (cur_link_up) {
3536 DP(NETIF_MSG_LINK, "phy in index %d link is up\n",
3537 phy_index);
3538 } else {
3539 DP(NETIF_MSG_LINK, "phy in index %d link is down\n",
3540 phy_index);
3541 continue;
3542 }
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003543
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003544 if (!ext_phy_link_up) {
3545 ext_phy_link_up = 1;
3546 active_external_phy = phy_index;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003547 } else {
3548 switch (bnx2x_phy_selection(params)) {
3549 case PORT_HW_CFG_PHY_SELECTION_HARDWARE_DEFAULT:
3550 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY_PRIORITY:
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003551 /*
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003552 * In this option, the first PHY makes sure to pass the
3553 * traffic through itself only.
3554 * Its not clear how to reset the link on the second phy
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003555 */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003556 active_external_phy = EXT_PHY1;
3557 break;
3558 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY_PRIORITY:
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003559 /*
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003560 * In this option, the first PHY makes sure to pass the
3561 * traffic through the second PHY.
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003562 */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003563 active_external_phy = EXT_PHY2;
3564 break;
3565 default:
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003566 /*
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003567 * Link indication on both PHYs with the following cases
3568 * is invalid:
3569 * - FIRST_PHY means that second phy wasn't initialized,
3570 * hence its link is expected to be down
3571 * - SECOND_PHY means that first phy should not be able
3572 * to link up by itself (using configuration)
3573 * - DEFAULT should be overriden during initialiazation
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003574 */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003575 DP(NETIF_MSG_LINK, "Invalid link indication"
3576 "mpc=0x%x. DISABLING LINK !!!\n",
3577 params->multi_phy_config);
3578 ext_phy_link_up = 0;
3579 break;
3580 }
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003581 }
3582 }
3583 prev_line_speed = vars->line_speed;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003584 /*
3585 * Step 2:
3586 * Read the status of the internal phy. In case of
3587 * DIRECT_SINGLE_MEDIA board, this link is the external link,
3588 * otherwise this is the link between the 577xx and the first
3589 * external phy
3590 */
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003591 if (params->phy[INT_PHY].read_status)
3592 params->phy[INT_PHY].read_status(
3593 &params->phy[INT_PHY],
3594 params, vars);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003595 /*
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003596 * The INT_PHY flow control reside in the vars. This include the
3597 * case where the speed or flow control are not set to AUTO.
3598 * Otherwise, the active external phy flow control result is set
3599 * to the vars. The ext_phy_line_speed is needed to check if the
3600 * speed is different between the internal phy and external phy.
3601 * This case may be result of intermediate link speed change.
3602 */
3603 if (active_external_phy > INT_PHY) {
3604 vars->flow_ctrl = phy_vars[active_external_phy].flow_ctrl;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003605 /*
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003606 * Link speed is taken from the XGXS. AN and FC result from
3607 * the external phy.
3608 */
3609 vars->link_status |= phy_vars[active_external_phy].link_status;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003610
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003611 /*
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003612 * if active_external_phy is first PHY and link is up - disable
3613 * disable TX on second external PHY
3614 */
3615 if (active_external_phy == EXT_PHY1) {
3616 if (params->phy[EXT_PHY2].phy_specific_func) {
3617 DP(NETIF_MSG_LINK, "Disabling TX on"
3618 " EXT_PHY2\n");
3619 params->phy[EXT_PHY2].phy_specific_func(
3620 &params->phy[EXT_PHY2],
3621 params, DISABLE_TX);
3622 }
3623 }
3624
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003625 ext_phy_line_speed = phy_vars[active_external_phy].line_speed;
3626 vars->duplex = phy_vars[active_external_phy].duplex;
3627 if (params->phy[active_external_phy].supported &
3628 SUPPORTED_FIBRE)
3629 vars->link_status |= LINK_STATUS_SERDES_LINK;
3630 DP(NETIF_MSG_LINK, "Active external phy selected: %x\n",
3631 active_external_phy);
3632 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003633
3634 for (phy_index = EXT_PHY1; phy_index < params->num_phys;
3635 phy_index++) {
3636 if (params->phy[phy_index].flags &
3637 FLAGS_REARM_LATCH_SIGNAL) {
3638 bnx2x_rearm_latch_signal(bp, port,
3639 phy_index ==
3640 active_external_phy);
3641 break;
3642 }
3643 }
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003644 DP(NETIF_MSG_LINK, "vars->flow_ctrl = 0x%x, vars->link_status = 0x%x,"
3645 " ext_phy_line_speed = %d\n", vars->flow_ctrl,
3646 vars->link_status, ext_phy_line_speed);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003647 /*
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003648 * Upon link speed change set the NIG into drain mode. Comes to
3649 * deals with possible FIFO glitch due to clk change when speed
3650 * is decreased without link down indicator
3651 */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003652
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003653 if (vars->phy_link_up) {
3654 if (!(SINGLE_MEDIA_DIRECT(params)) && ext_phy_link_up &&
3655 (ext_phy_line_speed != vars->line_speed)) {
3656 DP(NETIF_MSG_LINK, "Internal link speed %d is"
3657 " different than the external"
3658 " link speed %d\n", vars->line_speed,
3659 ext_phy_line_speed);
3660 vars->phy_link_up = 0;
3661 } else if (prev_line_speed != vars->line_speed) {
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003662 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4,
3663 0);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003664 msleep(1);
3665 }
3666 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003667
3668 /* anything 10 and over uses the bmac */
3669 link_10g = ((vars->line_speed == SPEED_10000) ||
3670 (vars->line_speed == SPEED_12000) ||
3671 (vars->line_speed == SPEED_12500) ||
3672 (vars->line_speed == SPEED_13000) ||
3673 (vars->line_speed == SPEED_15000) ||
3674 (vars->line_speed == SPEED_16000));
3675
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003676 bnx2x_link_int_ack(params, vars, link_10g);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003677
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003678 /*
3679 * In case external phy link is up, and internal link is down
3680 * (not initialized yet probably after link initialization, it
3681 * needs to be initialized.
3682 * Note that after link down-up as result of cable plug, the xgxs
3683 * link would probably become up again without the need
3684 * initialize it
3685 */
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003686 if (!(SINGLE_MEDIA_DIRECT(params))) {
3687 DP(NETIF_MSG_LINK, "ext_phy_link_up = %d, int_link_up = %d,"
3688 " init_preceding = %d\n", ext_phy_link_up,
3689 vars->phy_link_up,
3690 params->phy[EXT_PHY1].flags &
3691 FLAGS_INIT_XGXS_FIRST);
3692 if (!(params->phy[EXT_PHY1].flags &
3693 FLAGS_INIT_XGXS_FIRST)
3694 && ext_phy_link_up && !vars->phy_link_up) {
3695 vars->line_speed = ext_phy_line_speed;
3696 if (vars->line_speed < SPEED_1000)
3697 vars->phy_flags |= PHY_SGMII_FLAG;
3698 else
3699 vars->phy_flags &= ~PHY_SGMII_FLAG;
3700 bnx2x_init_internal_phy(&params->phy[INT_PHY],
3701 params,
3702 vars);
3703 }
3704 }
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003705 /*
3706 * Link is up only if both local phy and external phy (in case of
3707 * non-direct board) are up
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003708 */
3709 vars->link_up = (vars->phy_link_up &&
3710 (ext_phy_link_up ||
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00003711 SINGLE_MEDIA_DIRECT(params)) &&
3712 (phy_vars[active_external_phy].fault_detected == 0));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003713
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003714 if (vars->link_up)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003715 rc = bnx2x_update_link_up(params, vars, link_10g);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003716 else
3717 rc = bnx2x_update_link_down(params, vars);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003718
3719 return rc;
3720}
3721
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003722
3723/*****************************************************************************/
3724/* External Phy section */
3725/*****************************************************************************/
3726void bnx2x_ext_phy_hw_reset(struct bnx2x *bp, u8 port)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003727{
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003728 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003729 MISC_REGISTERS_GPIO_OUTPUT_LOW, port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003730 msleep(1);
3731 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003732 MISC_REGISTERS_GPIO_OUTPUT_HIGH, port);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003733}
3734
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003735static void bnx2x_save_spirom_version(struct bnx2x *bp, u8 port,
3736 u32 spirom_ver, u32 ver_addr)
3737{
3738 DP(NETIF_MSG_LINK, "FW version 0x%x:0x%x for port %d\n",
3739 (u16)(spirom_ver>>16), (u16)spirom_ver, port);
3740
3741 if (ver_addr)
3742 REG_WR(bp, ver_addr, spirom_ver);
3743}
3744
3745static void bnx2x_save_bcm_spirom_ver(struct bnx2x *bp,
3746 struct bnx2x_phy *phy,
3747 u8 port)
3748{
3749 u16 fw_ver1, fw_ver2;
3750
3751 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003752 MDIO_PMA_REG_ROM_VER1, &fw_ver1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003753 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003754 MDIO_PMA_REG_ROM_VER2, &fw_ver2);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003755 bnx2x_save_spirom_version(bp, port, (u32)(fw_ver1<<16 | fw_ver2),
3756 phy->ver_addr);
3757}
3758
3759static void bnx2x_ext_phy_set_pause(struct link_params *params,
3760 struct bnx2x_phy *phy,
3761 struct link_vars *vars)
3762{
3763 u16 val;
3764 struct bnx2x *bp = params->bp;
3765 /* read modify write pause advertizing */
3766 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV_PAUSE, &val);
3767
3768 val &= ~MDIO_AN_REG_ADV_PAUSE_BOTH;
3769
3770 /* Please refer to Table 28B-3 of 802.3ab-1999 spec. */
3771 bnx2x_calc_ieee_aneg_adv(phy, params, &vars->ieee_fc);
3772 if ((vars->ieee_fc &
3773 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC) ==
3774 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC) {
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003775 val |= MDIO_AN_REG_ADV_PAUSE_ASYMMETRIC;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003776 }
3777 if ((vars->ieee_fc &
3778 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) ==
3779 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) {
3780 val |= MDIO_AN_REG_ADV_PAUSE_PAUSE;
3781 }
3782 DP(NETIF_MSG_LINK, "Ext phy AN advertize 0x%x\n", val);
3783 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV_PAUSE, val);
3784}
3785
3786static u8 bnx2x_ext_phy_resolve_fc(struct bnx2x_phy *phy,
3787 struct link_params *params,
3788 struct link_vars *vars)
3789{
3790 struct bnx2x *bp = params->bp;
3791 u16 ld_pause; /* local */
3792 u16 lp_pause; /* link partner */
3793 u16 pause_result;
3794 u8 ret = 0;
3795 /* read twice */
3796
3797 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
3798
3799 if (phy->req_flow_ctrl != BNX2X_FLOW_CTRL_AUTO)
3800 vars->flow_ctrl = phy->req_flow_ctrl;
3801 else if (phy->req_line_speed != SPEED_AUTO_NEG)
3802 vars->flow_ctrl = params->req_fc_auto_adv;
3803 else if (vars->link_status & LINK_STATUS_AUTO_NEGOTIATE_COMPLETE) {
3804 ret = 1;
3805 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003806 MDIO_AN_DEVAD,
3807 MDIO_AN_REG_ADV_PAUSE, &ld_pause);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003808 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003809 MDIO_AN_DEVAD,
3810 MDIO_AN_REG_LP_AUTO_NEG, &lp_pause);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003811 pause_result = (ld_pause &
3812 MDIO_AN_REG_ADV_PAUSE_MASK) >> 8;
3813 pause_result |= (lp_pause &
3814 MDIO_AN_REG_ADV_PAUSE_MASK) >> 10;
3815 DP(NETIF_MSG_LINK, "Ext PHY pause result 0x%x\n",
3816 pause_result);
3817 bnx2x_pause_resolve(vars, pause_result);
3818 }
3819 return ret;
3820}
3821
3822static void bnx2x_ext_phy_10G_an_resolve(struct bnx2x *bp,
3823 struct bnx2x_phy *phy,
3824 struct link_vars *vars)
3825{
3826 u16 val;
3827 bnx2x_cl45_read(bp, phy,
3828 MDIO_AN_DEVAD,
3829 MDIO_AN_REG_STATUS, &val);
3830 bnx2x_cl45_read(bp, phy,
3831 MDIO_AN_DEVAD,
3832 MDIO_AN_REG_STATUS, &val);
3833 if (val & (1<<5))
3834 vars->link_status |= LINK_STATUS_AUTO_NEGOTIATE_COMPLETE;
3835 if ((val & (1<<0)) == 0)
3836 vars->link_status |= LINK_STATUS_PARALLEL_DETECTION_USED;
3837}
3838
3839/******************************************************************/
3840/* common BCM8073/BCM8727 PHY SECTION */
3841/******************************************************************/
3842static void bnx2x_8073_resolve_fc(struct bnx2x_phy *phy,
3843 struct link_params *params,
3844 struct link_vars *vars)
3845{
3846 struct bnx2x *bp = params->bp;
3847 if (phy->req_line_speed == SPEED_10 ||
3848 phy->req_line_speed == SPEED_100) {
3849 vars->flow_ctrl = phy->req_flow_ctrl;
3850 return;
3851 }
3852
3853 if (bnx2x_ext_phy_resolve_fc(phy, params, vars) &&
3854 (vars->flow_ctrl == BNX2X_FLOW_CTRL_NONE)) {
3855 u16 pause_result;
3856 u16 ld_pause; /* local */
3857 u16 lp_pause; /* link partner */
3858 bnx2x_cl45_read(bp, phy,
3859 MDIO_AN_DEVAD,
3860 MDIO_AN_REG_CL37_FC_LD, &ld_pause);
3861
3862 bnx2x_cl45_read(bp, phy,
3863 MDIO_AN_DEVAD,
3864 MDIO_AN_REG_CL37_FC_LP, &lp_pause);
3865 pause_result = (ld_pause &
3866 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) >> 5;
3867 pause_result |= (lp_pause &
3868 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) >> 7;
3869
3870 bnx2x_pause_resolve(vars, pause_result);
3871 DP(NETIF_MSG_LINK, "Ext PHY CL37 pause result 0x%x\n",
3872 pause_result);
3873 }
3874}
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00003875static int bnx2x_8073_8727_external_rom_boot(struct bnx2x *bp,
3876 struct bnx2x_phy *phy,
3877 u8 port)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003878{
Yaniv Rosner5c99274b2011-01-18 04:33:36 +00003879 u32 count = 0;
3880 u16 fw_ver1, fw_msgout;
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00003881 int rc = 0;
Yaniv Rosner5c99274b2011-01-18 04:33:36 +00003882
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003883 /* Boot port from external ROM */
3884 /* EDC grst */
3885 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003886 MDIO_PMA_DEVAD,
3887 MDIO_PMA_REG_GEN_CTRL,
3888 0x0001);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003889
3890 /* ucode reboot and rst */
3891 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003892 MDIO_PMA_DEVAD,
3893 MDIO_PMA_REG_GEN_CTRL,
3894 0x008c);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003895
3896 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003897 MDIO_PMA_DEVAD,
3898 MDIO_PMA_REG_MISC_CTRL1, 0x0001);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003899
3900 /* Reset internal microprocessor */
3901 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003902 MDIO_PMA_DEVAD,
3903 MDIO_PMA_REG_GEN_CTRL,
3904 MDIO_PMA_REG_GEN_CTRL_ROM_MICRO_RESET);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003905
3906 /* Release srst bit */
3907 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003908 MDIO_PMA_DEVAD,
3909 MDIO_PMA_REG_GEN_CTRL,
3910 MDIO_PMA_REG_GEN_CTRL_ROM_RESET_INTERNAL_MP);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003911
Yaniv Rosner5c99274b2011-01-18 04:33:36 +00003912 /* Delay 100ms per the PHY specifications */
3913 msleep(100);
3914
3915 /* 8073 sometimes taking longer to download */
3916 do {
3917 count++;
3918 if (count > 300) {
3919 DP(NETIF_MSG_LINK,
3920 "bnx2x_8073_8727_external_rom_boot port %x:"
3921 "Download failed. fw version = 0x%x\n",
3922 port, fw_ver1);
3923 rc = -EINVAL;
3924 break;
3925 }
3926
3927 bnx2x_cl45_read(bp, phy,
3928 MDIO_PMA_DEVAD,
3929 MDIO_PMA_REG_ROM_VER1, &fw_ver1);
3930 bnx2x_cl45_read(bp, phy,
3931 MDIO_PMA_DEVAD,
3932 MDIO_PMA_REG_M8051_MSGOUT_REG, &fw_msgout);
3933
3934 msleep(1);
3935 } while (fw_ver1 == 0 || fw_ver1 == 0x4321 ||
3936 ((fw_msgout & 0xff) != 0x03 && (phy->type ==
3937 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073)));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003938
3939 /* Clear ser_boot_ctl bit */
3940 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003941 MDIO_PMA_DEVAD,
3942 MDIO_PMA_REG_MISC_CTRL1, 0x0000);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003943 bnx2x_save_bcm_spirom_ver(bp, phy, port);
Yaniv Rosner5c99274b2011-01-18 04:33:36 +00003944
3945 DP(NETIF_MSG_LINK,
3946 "bnx2x_8073_8727_external_rom_boot port %x:"
3947 "Download complete. fw version = 0x%x\n",
3948 port, fw_ver1);
3949
3950 return rc;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003951}
3952
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003953/******************************************************************/
3954/* BCM8073 PHY SECTION */
3955/******************************************************************/
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00003956static int bnx2x_8073_is_snr_needed(struct bnx2x *bp, struct bnx2x_phy *phy)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003957{
3958 /* This is only required for 8073A1, version 102 only */
3959 u16 val;
3960
3961 /* Read 8073 HW revision*/
3962 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003963 MDIO_PMA_DEVAD,
3964 MDIO_PMA_REG_8073_CHIP_REV, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003965
3966 if (val != 1) {
3967 /* No need to workaround in 8073 A1 */
3968 return 0;
3969 }
3970
3971 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003972 MDIO_PMA_DEVAD,
3973 MDIO_PMA_REG_ROM_VER2, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003974
3975 /* SNR should be applied only for version 0x102 */
3976 if (val != 0x102)
3977 return 0;
3978
3979 return 1;
3980}
3981
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00003982static int bnx2x_8073_xaui_wa(struct bnx2x *bp, struct bnx2x_phy *phy)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003983{
3984 u16 val, cnt, cnt1 ;
3985
3986 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003987 MDIO_PMA_DEVAD,
3988 MDIO_PMA_REG_8073_CHIP_REV, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003989
3990 if (val > 0) {
3991 /* No need to workaround in 8073 A1 */
3992 return 0;
3993 }
3994 /* XAUI workaround in 8073 A0: */
3995
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003996 /*
3997 * After loading the boot ROM and restarting Autoneg, poll
3998 * Dev1, Reg $C820:
3999 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004000
4001 for (cnt = 0; cnt < 1000; cnt++) {
4002 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004003 MDIO_PMA_DEVAD,
4004 MDIO_PMA_REG_8073_SPEED_LINK_STATUS,
4005 &val);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00004006 /*
4007 * If bit [14] = 0 or bit [13] = 0, continue on with
4008 * system initialization (XAUI work-around not required, as
4009 * these bits indicate 2.5G or 1G link up).
4010 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004011 if (!(val & (1<<14)) || !(val & (1<<13))) {
4012 DP(NETIF_MSG_LINK, "XAUI work-around not required\n");
4013 return 0;
4014 } else if (!(val & (1<<15))) {
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00004015 DP(NETIF_MSG_LINK, "bit 15 went off\n");
4016 /*
4017 * If bit 15 is 0, then poll Dev1, Reg $C841 until it's
4018 * MSB (bit15) goes to 1 (indicating that the XAUI
4019 * workaround has completed), then continue on with
4020 * system initialization.
4021 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004022 for (cnt1 = 0; cnt1 < 1000; cnt1++) {
4023 bnx2x_cl45_read(bp, phy,
4024 MDIO_PMA_DEVAD,
4025 MDIO_PMA_REG_8073_XAUI_WA, &val);
4026 if (val & (1<<15)) {
4027 DP(NETIF_MSG_LINK,
4028 "XAUI workaround has completed\n");
4029 return 0;
4030 }
4031 msleep(3);
4032 }
4033 break;
4034 }
4035 msleep(3);
4036 }
4037 DP(NETIF_MSG_LINK, "Warning: XAUI work-around timeout !!!\n");
4038 return -EINVAL;
4039}
4040
4041static void bnx2x_807x_force_10G(struct bnx2x *bp, struct bnx2x_phy *phy)
4042{
4043 /* Force KR or KX */
4044 bnx2x_cl45_write(bp, phy,
4045 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x2040);
4046 bnx2x_cl45_write(bp, phy,
4047 MDIO_PMA_DEVAD, MDIO_PMA_REG_10G_CTRL2, 0x000b);
4048 bnx2x_cl45_write(bp, phy,
4049 MDIO_PMA_DEVAD, MDIO_PMA_REG_BCM_CTRL, 0x0000);
4050 bnx2x_cl45_write(bp, phy,
4051 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x0000);
4052}
4053
4054static void bnx2x_8073_set_pause_cl37(struct link_params *params,
4055 struct bnx2x_phy *phy,
4056 struct link_vars *vars)
4057{
4058 u16 cl37_val;
4059 struct bnx2x *bp = params->bp;
4060 bnx2x_cl45_read(bp, phy,
4061 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LD, &cl37_val);
4062
4063 cl37_val &= ~MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH;
4064 /* Please refer to Table 28B-3 of 802.3ab-1999 spec. */
4065 bnx2x_calc_ieee_aneg_adv(phy, params, &vars->ieee_fc);
4066 if ((vars->ieee_fc &
4067 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_SYMMETRIC) ==
4068 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_SYMMETRIC) {
4069 cl37_val |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_SYMMETRIC;
4070 }
4071 if ((vars->ieee_fc &
4072 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC) ==
4073 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC) {
4074 cl37_val |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC;
4075 }
4076 if ((vars->ieee_fc &
4077 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) ==
4078 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) {
4079 cl37_val |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH;
4080 }
4081 DP(NETIF_MSG_LINK,
4082 "Ext phy AN advertize cl37 0x%x\n", cl37_val);
4083
4084 bnx2x_cl45_write(bp, phy,
4085 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LD, cl37_val);
4086 msleep(500);
4087}
4088
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00004089static int bnx2x_8073_config_init(struct bnx2x_phy *phy,
4090 struct link_params *params,
4091 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004092{
4093 struct bnx2x *bp = params->bp;
4094 u16 val = 0, tmp1;
4095 u8 gpio_port;
4096 DP(NETIF_MSG_LINK, "Init 8073\n");
4097
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004098 if (CHIP_IS_E2(bp))
4099 gpio_port = BP_PATH(bp);
4100 else
4101 gpio_port = params->port;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004102 /* Restore normal power mode*/
4103 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004104 MISC_REGISTERS_GPIO_OUTPUT_HIGH, gpio_port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004105
4106 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004107 MISC_REGISTERS_GPIO_OUTPUT_HIGH, gpio_port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004108
4109 /* enable LASI */
4110 bnx2x_cl45_write(bp, phy,
4111 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_ALARM_CTRL, (1<<2));
4112 bnx2x_cl45_write(bp, phy,
4113 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_CTRL, 0x0004);
4114
4115 bnx2x_8073_set_pause_cl37(params, phy, vars);
4116
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004117 bnx2x_cl45_read(bp, phy,
4118 MDIO_PMA_DEVAD, MDIO_PMA_REG_M8051_MSGOUT_REG, &tmp1);
4119
4120 bnx2x_cl45_read(bp, phy,
4121 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_ALARM, &tmp1);
4122
4123 DP(NETIF_MSG_LINK, "Before rom RX_ALARM(port1): 0x%x\n", tmp1);
4124
Yaniv Rosner74d7a112011-01-18 04:33:18 +00004125 /* Swap polarity if required - Must be done only in non-1G mode */
4126 if (params->lane_config & PORT_HW_CFG_SWAP_PHY_POLARITY_ENABLED) {
4127 /* Configure the 8073 to swap _P and _N of the KR lines */
4128 DP(NETIF_MSG_LINK, "Swapping polarity for the 8073\n");
4129 /* 10G Rx/Tx and 1G Tx signal polarity swap */
4130 bnx2x_cl45_read(bp, phy,
4131 MDIO_PMA_DEVAD,
4132 MDIO_PMA_REG_8073_OPT_DIGITAL_CTRL, &val);
4133 bnx2x_cl45_write(bp, phy,
4134 MDIO_PMA_DEVAD,
4135 MDIO_PMA_REG_8073_OPT_DIGITAL_CTRL,
4136 (val | (3<<9)));
4137 }
4138
4139
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004140 /* Enable CL37 BAM */
Yaniv Rosner121839b2010-11-01 05:32:38 +00004141 if (REG_RD(bp, params->shmem_base +
4142 offsetof(struct shmem_region, dev_info.
4143 port_hw_config[params->port].default_cfg)) &
4144 PORT_HW_CFG_ENABLE_BAM_ON_KR_ENABLED) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004145
Yaniv Rosner121839b2010-11-01 05:32:38 +00004146 bnx2x_cl45_read(bp, phy,
4147 MDIO_AN_DEVAD,
4148 MDIO_AN_REG_8073_BAM, &val);
4149 bnx2x_cl45_write(bp, phy,
4150 MDIO_AN_DEVAD,
4151 MDIO_AN_REG_8073_BAM, val | 1);
4152 DP(NETIF_MSG_LINK, "Enable CL37 BAM on KR\n");
4153 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004154 if (params->loopback_mode == LOOPBACK_EXT) {
4155 bnx2x_807x_force_10G(bp, phy);
4156 DP(NETIF_MSG_LINK, "Forced speed 10G on 807X\n");
4157 return 0;
4158 } else {
4159 bnx2x_cl45_write(bp, phy,
4160 MDIO_PMA_DEVAD, MDIO_PMA_REG_BCM_CTRL, 0x0002);
4161 }
4162 if (phy->req_line_speed != SPEED_AUTO_NEG) {
4163 if (phy->req_line_speed == SPEED_10000) {
4164 val = (1<<7);
4165 } else if (phy->req_line_speed == SPEED_2500) {
4166 val = (1<<5);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00004167 /*
4168 * Note that 2.5G works only when used with 1G
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004169 * advertisement
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00004170 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004171 } else
4172 val = (1<<5);
4173 } else {
4174 val = 0;
4175 if (phy->speed_cap_mask &
4176 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
4177 val |= (1<<7);
4178
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004179 /* Note that 2.5G works only when used with 1G advertisement */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004180 if (phy->speed_cap_mask &
4181 (PORT_HW_CFG_SPEED_CAPABILITY_D0_1G |
4182 PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
4183 val |= (1<<5);
4184 DP(NETIF_MSG_LINK, "807x autoneg val = 0x%x\n", val);
4185 }
4186
4187 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV, val);
4188 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_8073_2_5G, &tmp1);
4189
4190 if (((phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G) &&
4191 (phy->req_line_speed == SPEED_AUTO_NEG)) ||
4192 (phy->req_line_speed == SPEED_2500)) {
4193 u16 phy_ver;
4194 /* Allow 2.5G for A1 and above */
4195 bnx2x_cl45_read(bp, phy,
4196 MDIO_PMA_DEVAD, MDIO_PMA_REG_8073_CHIP_REV,
4197 &phy_ver);
4198 DP(NETIF_MSG_LINK, "Add 2.5G\n");
4199 if (phy_ver > 0)
4200 tmp1 |= 1;
4201 else
4202 tmp1 &= 0xfffe;
4203 } else {
4204 DP(NETIF_MSG_LINK, "Disable 2.5G\n");
4205 tmp1 &= 0xfffe;
4206 }
4207
4208 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_8073_2_5G, tmp1);
4209 /* Add support for CL37 (passive mode) II */
4210
4211 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LD, &tmp1);
4212 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LD,
4213 (tmp1 | ((phy->req_duplex == DUPLEX_FULL) ?
4214 0x20 : 0x40)));
4215
4216 /* Add support for CL37 (passive mode) III */
4217 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CL37_AN, 0x1000);
4218
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00004219 /*
4220 * The SNR will improve about 2db by changing BW and FEE main
4221 * tap. Rest commands are executed after link is up
4222 * Change FFE main cursor to 5 in EDC register
4223 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004224 if (bnx2x_8073_is_snr_needed(bp, phy))
4225 bnx2x_cl45_write(bp, phy,
4226 MDIO_PMA_DEVAD, MDIO_PMA_REG_EDC_FFE_MAIN,
4227 0xFB0C);
4228
4229 /* Enable FEC (Forware Error Correction) Request in the AN */
4230 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV2, &tmp1);
4231 tmp1 |= (1<<15);
4232 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV2, tmp1);
4233
4234 bnx2x_ext_phy_set_pause(params, phy, vars);
4235
4236 /* Restart autoneg */
4237 msleep(500);
4238 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x1200);
4239 DP(NETIF_MSG_LINK, "807x Autoneg Restart: Advertise 1G=%x, 10G=%x\n",
4240 ((val & (1<<5)) > 0), ((val & (1<<7)) > 0));
4241 return 0;
4242}
4243
4244static u8 bnx2x_8073_read_status(struct bnx2x_phy *phy,
4245 struct link_params *params,
4246 struct link_vars *vars)
4247{
4248 struct bnx2x *bp = params->bp;
4249 u8 link_up = 0;
4250 u16 val1, val2;
4251 u16 link_status = 0;
4252 u16 an1000_status = 0;
4253
4254 bnx2x_cl45_read(bp, phy,
4255 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_STATUS, &val1);
4256
4257 DP(NETIF_MSG_LINK, "8703 LASI status 0x%x\n", val1);
4258
4259 /* clear the interrupt LASI status register */
4260 bnx2x_cl45_read(bp, phy,
4261 MDIO_PCS_DEVAD, MDIO_PCS_REG_STATUS, &val2);
4262 bnx2x_cl45_read(bp, phy,
4263 MDIO_PCS_DEVAD, MDIO_PCS_REG_STATUS, &val1);
4264 DP(NETIF_MSG_LINK, "807x PCS status 0x%x->0x%x\n", val2, val1);
4265 /* Clear MSG-OUT */
4266 bnx2x_cl45_read(bp, phy,
4267 MDIO_PMA_DEVAD, MDIO_PMA_REG_M8051_MSGOUT_REG, &val1);
4268
4269 /* Check the LASI */
4270 bnx2x_cl45_read(bp, phy,
4271 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_ALARM, &val2);
4272
4273 DP(NETIF_MSG_LINK, "KR 0x9003 0x%x\n", val2);
4274
4275 /* Check the link status */
4276 bnx2x_cl45_read(bp, phy,
4277 MDIO_PCS_DEVAD, MDIO_PCS_REG_STATUS, &val2);
4278 DP(NETIF_MSG_LINK, "KR PCS status 0x%x\n", val2);
4279
4280 bnx2x_cl45_read(bp, phy,
4281 MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val2);
4282 bnx2x_cl45_read(bp, phy,
4283 MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val1);
4284 link_up = ((val1 & 4) == 4);
4285 DP(NETIF_MSG_LINK, "PMA_REG_STATUS=0x%x\n", val1);
4286
4287 if (link_up &&
4288 ((phy->req_line_speed != SPEED_10000))) {
4289 if (bnx2x_8073_xaui_wa(bp, phy) != 0)
4290 return 0;
4291 }
4292 bnx2x_cl45_read(bp, phy,
4293 MDIO_AN_DEVAD, MDIO_AN_REG_LINK_STATUS, &an1000_status);
4294 bnx2x_cl45_read(bp, phy,
4295 MDIO_AN_DEVAD, MDIO_AN_REG_LINK_STATUS, &an1000_status);
4296
4297 /* Check the link status on 1.1.2 */
4298 bnx2x_cl45_read(bp, phy,
4299 MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val2);
4300 bnx2x_cl45_read(bp, phy,
4301 MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val1);
4302 DP(NETIF_MSG_LINK, "KR PMA status 0x%x->0x%x,"
4303 "an_link_status=0x%x\n", val2, val1, an1000_status);
4304
4305 link_up = (((val1 & 4) == 4) || (an1000_status & (1<<1)));
4306 if (link_up && bnx2x_8073_is_snr_needed(bp, phy)) {
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00004307 /*
4308 * The SNR will improve about 2dbby changing the BW and FEE main
4309 * tap. The 1st write to change FFE main tap is set before
4310 * restart AN. Change PLL Bandwidth in EDC register
4311 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004312 bnx2x_cl45_write(bp, phy,
4313 MDIO_PMA_DEVAD, MDIO_PMA_REG_PLL_BANDWIDTH,
4314 0x26BC);
4315
4316 /* Change CDR Bandwidth in EDC register */
4317 bnx2x_cl45_write(bp, phy,
4318 MDIO_PMA_DEVAD, MDIO_PMA_REG_CDR_BANDWIDTH,
4319 0x0333);
4320 }
4321 bnx2x_cl45_read(bp, phy,
4322 MDIO_PMA_DEVAD, MDIO_PMA_REG_8073_SPEED_LINK_STATUS,
4323 &link_status);
4324
4325 /* Bits 0..2 --> speed detected, bits 13..15--> link is down */
4326 if ((link_status & (1<<2)) && (!(link_status & (1<<15)))) {
4327 link_up = 1;
4328 vars->line_speed = SPEED_10000;
4329 DP(NETIF_MSG_LINK, "port %x: External link up in 10G\n",
4330 params->port);
4331 } else if ((link_status & (1<<1)) && (!(link_status & (1<<14)))) {
4332 link_up = 1;
4333 vars->line_speed = SPEED_2500;
4334 DP(NETIF_MSG_LINK, "port %x: External link up in 2.5G\n",
4335 params->port);
4336 } else if ((link_status & (1<<0)) && (!(link_status & (1<<13)))) {
4337 link_up = 1;
4338 vars->line_speed = SPEED_1000;
4339 DP(NETIF_MSG_LINK, "port %x: External link up in 1G\n",
4340 params->port);
4341 } else {
4342 link_up = 0;
4343 DP(NETIF_MSG_LINK, "port %x: External link is down\n",
4344 params->port);
4345 }
4346
4347 if (link_up) {
Yaniv Rosner74d7a112011-01-18 04:33:18 +00004348 /* Swap polarity if required */
4349 if (params->lane_config &
4350 PORT_HW_CFG_SWAP_PHY_POLARITY_ENABLED) {
4351 /* Configure the 8073 to swap P and N of the KR lines */
4352 bnx2x_cl45_read(bp, phy,
4353 MDIO_XS_DEVAD,
4354 MDIO_XS_REG_8073_RX_CTRL_PCIE, &val1);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00004355 /*
4356 * Set bit 3 to invert Rx in 1G mode and clear this bit
4357 * when it`s in 10G mode.
4358 */
Yaniv Rosner74d7a112011-01-18 04:33:18 +00004359 if (vars->line_speed == SPEED_1000) {
4360 DP(NETIF_MSG_LINK, "Swapping 1G polarity for"
4361 "the 8073\n");
4362 val1 |= (1<<3);
4363 } else
4364 val1 &= ~(1<<3);
4365
4366 bnx2x_cl45_write(bp, phy,
4367 MDIO_XS_DEVAD,
4368 MDIO_XS_REG_8073_RX_CTRL_PCIE,
4369 val1);
4370 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004371 bnx2x_ext_phy_10G_an_resolve(bp, phy, vars);
4372 bnx2x_8073_resolve_fc(phy, params, vars);
Yaniv Rosner791f18c2011-01-18 04:33:42 +00004373 vars->duplex = DUPLEX_FULL;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004374 }
4375 return link_up;
4376}
4377
4378static void bnx2x_8073_link_reset(struct bnx2x_phy *phy,
4379 struct link_params *params)
4380{
4381 struct bnx2x *bp = params->bp;
4382 u8 gpio_port;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004383 if (CHIP_IS_E2(bp))
4384 gpio_port = BP_PATH(bp);
4385 else
4386 gpio_port = params->port;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004387 DP(NETIF_MSG_LINK, "Setting 8073 port %d into low power mode\n",
4388 gpio_port);
4389 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004390 MISC_REGISTERS_GPIO_OUTPUT_LOW,
4391 gpio_port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004392}
4393
4394/******************************************************************/
4395/* BCM8705 PHY SECTION */
4396/******************************************************************/
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00004397static int bnx2x_8705_config_init(struct bnx2x_phy *phy,
4398 struct link_params *params,
4399 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004400{
4401 struct bnx2x *bp = params->bp;
4402 DP(NETIF_MSG_LINK, "init 8705\n");
4403 /* Restore normal power mode*/
4404 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004405 MISC_REGISTERS_GPIO_OUTPUT_HIGH, params->port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004406 /* HW reset */
4407 bnx2x_ext_phy_hw_reset(bp, params->port);
4408 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0xa040);
Yaniv Rosner6d870c32011-01-31 04:22:20 +00004409 bnx2x_wait_reset_complete(bp, phy, params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004410
4411 bnx2x_cl45_write(bp, phy,
4412 MDIO_PMA_DEVAD, MDIO_PMA_REG_MISC_CTRL, 0x8288);
4413 bnx2x_cl45_write(bp, phy,
4414 MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER, 0x7fbf);
4415 bnx2x_cl45_write(bp, phy,
4416 MDIO_PMA_DEVAD, MDIO_PMA_REG_CMU_PLL_BYPASS, 0x0100);
4417 bnx2x_cl45_write(bp, phy,
4418 MDIO_WIS_DEVAD, MDIO_WIS_REG_LASI_CNTL, 0x1);
4419 /* BCM8705 doesn't have microcode, hence the 0 */
4420 bnx2x_save_spirom_version(bp, params->port, params->shmem_base, 0);
4421 return 0;
4422}
4423
4424static u8 bnx2x_8705_read_status(struct bnx2x_phy *phy,
4425 struct link_params *params,
4426 struct link_vars *vars)
4427{
4428 u8 link_up = 0;
4429 u16 val1, rx_sd;
4430 struct bnx2x *bp = params->bp;
4431 DP(NETIF_MSG_LINK, "read status 8705\n");
4432 bnx2x_cl45_read(bp, phy,
4433 MDIO_WIS_DEVAD, MDIO_WIS_REG_LASI_STATUS, &val1);
4434 DP(NETIF_MSG_LINK, "8705 LASI status 0x%x\n", val1);
4435
4436 bnx2x_cl45_read(bp, phy,
4437 MDIO_WIS_DEVAD, MDIO_WIS_REG_LASI_STATUS, &val1);
4438 DP(NETIF_MSG_LINK, "8705 LASI status 0x%x\n", val1);
4439
4440 bnx2x_cl45_read(bp, phy,
4441 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_SD, &rx_sd);
4442
4443 bnx2x_cl45_read(bp, phy,
4444 MDIO_PMA_DEVAD, 0xc809, &val1);
4445 bnx2x_cl45_read(bp, phy,
4446 MDIO_PMA_DEVAD, 0xc809, &val1);
4447
4448 DP(NETIF_MSG_LINK, "8705 1.c809 val=0x%x\n", val1);
4449 link_up = ((rx_sd & 0x1) && (val1 & (1<<9)) && ((val1 & (1<<8)) == 0));
4450 if (link_up) {
4451 vars->line_speed = SPEED_10000;
4452 bnx2x_ext_phy_resolve_fc(phy, params, vars);
4453 }
4454 return link_up;
4455}
4456
4457/******************************************************************/
4458/* SFP+ module Section */
4459/******************************************************************/
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00004460static u8 bnx2x_get_gpio_port(struct link_params *params)
4461{
4462 u8 gpio_port;
4463 u32 swap_val, swap_override;
4464 struct bnx2x *bp = params->bp;
4465 if (CHIP_IS_E2(bp))
4466 gpio_port = BP_PATH(bp);
4467 else
4468 gpio_port = params->port;
4469 swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
4470 swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
4471 return gpio_port ^ (swap_val && swap_override);
4472}
4473static void bnx2x_sfp_set_transmitter(struct link_params *params,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004474 struct bnx2x_phy *phy,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004475 u8 tx_en)
4476{
4477 u16 val;
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00004478 u8 port = params->port;
4479 struct bnx2x *bp = params->bp;
4480 u32 tx_en_mode;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004481
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004482 /* Disable/Enable transmitter ( TX laser of the SFP+ module.)*/
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00004483 tx_en_mode = REG_RD(bp, params->shmem_base +
4484 offsetof(struct shmem_region,
4485 dev_info.port_hw_config[port].sfp_ctrl)) &
4486 PORT_HW_CFG_TX_LASER_MASK;
4487 DP(NETIF_MSG_LINK, "Setting transmitter tx_en=%x for port %x "
4488 "mode = %x\n", tx_en, port, tx_en_mode);
4489 switch (tx_en_mode) {
4490 case PORT_HW_CFG_TX_LASER_MDIO:
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004491
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00004492 bnx2x_cl45_read(bp, phy,
4493 MDIO_PMA_DEVAD,
4494 MDIO_PMA_REG_PHY_IDENTIFIER,
4495 &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004496
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00004497 if (tx_en)
4498 val &= ~(1<<15);
4499 else
4500 val |= (1<<15);
4501
4502 bnx2x_cl45_write(bp, phy,
4503 MDIO_PMA_DEVAD,
4504 MDIO_PMA_REG_PHY_IDENTIFIER,
4505 val);
4506 break;
4507 case PORT_HW_CFG_TX_LASER_GPIO0:
4508 case PORT_HW_CFG_TX_LASER_GPIO1:
4509 case PORT_HW_CFG_TX_LASER_GPIO2:
4510 case PORT_HW_CFG_TX_LASER_GPIO3:
4511 {
4512 u16 gpio_pin;
4513 u8 gpio_port, gpio_mode;
4514 if (tx_en)
4515 gpio_mode = MISC_REGISTERS_GPIO_OUTPUT_HIGH;
4516 else
4517 gpio_mode = MISC_REGISTERS_GPIO_OUTPUT_LOW;
4518
4519 gpio_pin = tx_en_mode - PORT_HW_CFG_TX_LASER_GPIO0;
4520 gpio_port = bnx2x_get_gpio_port(params);
4521 bnx2x_set_gpio(bp, gpio_pin, gpio_mode, gpio_port);
4522 break;
4523 }
4524 default:
4525 DP(NETIF_MSG_LINK, "Invalid TX_LASER_MDIO 0x%x\n", tx_en_mode);
4526 break;
4527 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004528}
4529
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00004530static int bnx2x_8726_read_sfp_module_eeprom(struct bnx2x_phy *phy,
4531 struct link_params *params,
4532 u16 addr, u8 byte_cnt, u8 *o_buf)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004533{
4534 struct bnx2x *bp = params->bp;
4535 u16 val = 0;
4536 u16 i;
4537 if (byte_cnt > 16) {
4538 DP(NETIF_MSG_LINK, "Reading from eeprom is"
4539 " is limited to 0xf\n");
4540 return -EINVAL;
4541 }
4542 /* Set the read command byte count */
4543 bnx2x_cl45_write(bp, phy,
4544 MDIO_PMA_DEVAD, MDIO_PMA_REG_SFP_TWO_WIRE_BYTE_CNT,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004545 (byte_cnt | 0xa000));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004546
4547 /* Set the read command address */
4548 bnx2x_cl45_write(bp, phy,
4549 MDIO_PMA_DEVAD, MDIO_PMA_REG_SFP_TWO_WIRE_MEM_ADDR,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004550 addr);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004551
4552 /* Activate read command */
4553 bnx2x_cl45_write(bp, phy,
4554 MDIO_PMA_DEVAD, MDIO_PMA_REG_SFP_TWO_WIRE_CTRL,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004555 0x2c0f);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004556
4557 /* Wait up to 500us for command complete status */
4558 for (i = 0; i < 100; i++) {
4559 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004560 MDIO_PMA_DEVAD,
4561 MDIO_PMA_REG_SFP_TWO_WIRE_CTRL, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004562 if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) ==
4563 MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_COMPLETE)
4564 break;
4565 udelay(5);
4566 }
4567
4568 if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) !=
4569 MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_COMPLETE) {
4570 DP(NETIF_MSG_LINK,
4571 "Got bad status 0x%x when reading from SFP+ EEPROM\n",
4572 (val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK));
4573 return -EINVAL;
4574 }
4575
4576 /* Read the buffer */
4577 for (i = 0; i < byte_cnt; i++) {
4578 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004579 MDIO_PMA_DEVAD,
4580 MDIO_PMA_REG_8726_TWO_WIRE_DATA_BUF + i, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004581 o_buf[i] = (u8)(val & MDIO_PMA_REG_8726_TWO_WIRE_DATA_MASK);
4582 }
4583
4584 for (i = 0; i < 100; i++) {
4585 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004586 MDIO_PMA_DEVAD,
4587 MDIO_PMA_REG_SFP_TWO_WIRE_CTRL, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004588 if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) ==
4589 MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_IDLE)
Joe Perches6f38ad92010-11-14 17:04:31 +00004590 return 0;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004591 msleep(1);
4592 }
4593 return -EINVAL;
4594}
4595
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00004596static int bnx2x_8727_read_sfp_module_eeprom(struct bnx2x_phy *phy,
4597 struct link_params *params,
4598 u16 addr, u8 byte_cnt, u8 *o_buf)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004599{
4600 struct bnx2x *bp = params->bp;
4601 u16 val, i;
4602
4603 if (byte_cnt > 16) {
4604 DP(NETIF_MSG_LINK, "Reading from eeprom is"
4605 " is limited to 0xf\n");
4606 return -EINVAL;
4607 }
4608
4609 /* Need to read from 1.8000 to clear it */
4610 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004611 MDIO_PMA_DEVAD,
4612 MDIO_PMA_REG_SFP_TWO_WIRE_CTRL,
4613 &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004614
4615 /* Set the read command byte count */
4616 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004617 MDIO_PMA_DEVAD,
4618 MDIO_PMA_REG_SFP_TWO_WIRE_BYTE_CNT,
4619 ((byte_cnt < 2) ? 2 : byte_cnt));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004620
4621 /* Set the read command address */
4622 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004623 MDIO_PMA_DEVAD,
4624 MDIO_PMA_REG_SFP_TWO_WIRE_MEM_ADDR,
4625 addr);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004626 /* Set the destination address */
4627 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004628 MDIO_PMA_DEVAD,
4629 0x8004,
4630 MDIO_PMA_REG_8727_TWO_WIRE_DATA_BUF);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004631
4632 /* Activate read command */
4633 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004634 MDIO_PMA_DEVAD,
4635 MDIO_PMA_REG_SFP_TWO_WIRE_CTRL,
4636 0x8002);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00004637 /*
4638 * Wait appropriate time for two-wire command to finish before
4639 * polling the status register
4640 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004641 msleep(1);
4642
4643 /* Wait up to 500us for command complete status */
4644 for (i = 0; i < 100; i++) {
4645 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004646 MDIO_PMA_DEVAD,
4647 MDIO_PMA_REG_SFP_TWO_WIRE_CTRL, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004648 if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) ==
4649 MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_COMPLETE)
4650 break;
4651 udelay(5);
4652 }
4653
4654 if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) !=
4655 MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_COMPLETE) {
4656 DP(NETIF_MSG_LINK,
4657 "Got bad status 0x%x when reading from SFP+ EEPROM\n",
4658 (val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK));
Yaniv Rosner65a001b2011-01-31 04:22:03 +00004659 return -EFAULT;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004660 }
4661
4662 /* Read the buffer */
4663 for (i = 0; i < byte_cnt; i++) {
4664 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004665 MDIO_PMA_DEVAD,
4666 MDIO_PMA_REG_8727_TWO_WIRE_DATA_BUF + i, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004667 o_buf[i] = (u8)(val & MDIO_PMA_REG_8727_TWO_WIRE_DATA_MASK);
4668 }
4669
4670 for (i = 0; i < 100; i++) {
4671 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004672 MDIO_PMA_DEVAD,
4673 MDIO_PMA_REG_SFP_TWO_WIRE_CTRL, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004674 if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) ==
4675 MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_IDLE)
Joe Perches6f38ad92010-11-14 17:04:31 +00004676 return 0;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004677 msleep(1);
4678 }
4679
4680 return -EINVAL;
4681}
4682
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00004683int bnx2x_read_sfp_module_eeprom(struct bnx2x_phy *phy,
4684 struct link_params *params, u16 addr,
4685 u8 byte_cnt, u8 *o_buf)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004686{
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00004687 int rc = -EINVAL;
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00004688 switch (phy->type) {
4689 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
4690 rc = bnx2x_8726_read_sfp_module_eeprom(phy, params, addr,
4691 byte_cnt, o_buf);
4692 break;
4693 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
4694 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8722:
4695 rc = bnx2x_8727_read_sfp_module_eeprom(phy, params, addr,
4696 byte_cnt, o_buf);
4697 break;
4698 }
4699 return rc;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004700}
4701
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00004702static int bnx2x_get_edc_mode(struct bnx2x_phy *phy,
4703 struct link_params *params,
4704 u16 *edc_mode)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004705{
4706 struct bnx2x *bp = params->bp;
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00004707 u32 sync_offset = 0, phy_idx, media_types;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004708 u8 val, check_limiting_mode = 0;
4709 *edc_mode = EDC_MODE_LIMITING;
4710
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00004711 phy->media_type = ETH_PHY_UNSPECIFIED;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004712 /* First check for copper cable */
4713 if (bnx2x_read_sfp_module_eeprom(phy,
4714 params,
4715 SFP_EEPROM_CON_TYPE_ADDR,
4716 1,
4717 &val) != 0) {
4718 DP(NETIF_MSG_LINK, "Failed to read from SFP+ module EEPROM\n");
4719 return -EINVAL;
4720 }
4721
4722 switch (val) {
4723 case SFP_EEPROM_CON_TYPE_VAL_COPPER:
4724 {
4725 u8 copper_module_type;
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00004726 phy->media_type = ETH_PHY_DA_TWINAX;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00004727 /*
4728 * Check if its active cable (includes SFP+ module)
4729 * of passive cable
4730 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004731 if (bnx2x_read_sfp_module_eeprom(phy,
4732 params,
4733 SFP_EEPROM_FC_TX_TECH_ADDR,
4734 1,
4735 &copper_module_type) !=
4736 0) {
4737 DP(NETIF_MSG_LINK,
4738 "Failed to read copper-cable-type"
4739 " from SFP+ EEPROM\n");
4740 return -EINVAL;
4741 }
4742
4743 if (copper_module_type &
4744 SFP_EEPROM_FC_TX_TECH_BITMASK_COPPER_ACTIVE) {
4745 DP(NETIF_MSG_LINK, "Active Copper cable detected\n");
4746 check_limiting_mode = 1;
4747 } else if (copper_module_type &
4748 SFP_EEPROM_FC_TX_TECH_BITMASK_COPPER_PASSIVE) {
4749 DP(NETIF_MSG_LINK, "Passive Copper"
4750 " cable detected\n");
4751 *edc_mode =
4752 EDC_MODE_PASSIVE_DAC;
4753 } else {
4754 DP(NETIF_MSG_LINK, "Unknown copper-cable-"
4755 "type 0x%x !!!\n", copper_module_type);
4756 return -EINVAL;
4757 }
4758 break;
4759 }
4760 case SFP_EEPROM_CON_TYPE_VAL_LC:
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00004761 phy->media_type = ETH_PHY_SFP_FIBER;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004762 DP(NETIF_MSG_LINK, "Optic module detected\n");
4763 check_limiting_mode = 1;
4764 break;
4765 default:
4766 DP(NETIF_MSG_LINK, "Unable to determine module type 0x%x !!!\n",
4767 val);
4768 return -EINVAL;
4769 }
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00004770 sync_offset = params->shmem_base +
4771 offsetof(struct shmem_region,
4772 dev_info.port_hw_config[params->port].media_type);
4773 media_types = REG_RD(bp, sync_offset);
4774 /* Update media type for non-PMF sync */
4775 for (phy_idx = INT_PHY; phy_idx < MAX_PHYS; phy_idx++) {
4776 if (&(params->phy[phy_idx]) == phy) {
4777 media_types &= ~(PORT_HW_CFG_MEDIA_TYPE_PHY0_MASK <<
4778 (PORT_HW_CFG_MEDIA_TYPE_PHY1_SHIFT * phy_idx));
4779 media_types |= ((phy->media_type &
4780 PORT_HW_CFG_MEDIA_TYPE_PHY0_MASK) <<
4781 (PORT_HW_CFG_MEDIA_TYPE_PHY1_SHIFT * phy_idx));
4782 break;
4783 }
4784 }
4785 REG_WR(bp, sync_offset, media_types);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004786 if (check_limiting_mode) {
4787 u8 options[SFP_EEPROM_OPTIONS_SIZE];
4788 if (bnx2x_read_sfp_module_eeprom(phy,
4789 params,
4790 SFP_EEPROM_OPTIONS_ADDR,
4791 SFP_EEPROM_OPTIONS_SIZE,
4792 options) != 0) {
4793 DP(NETIF_MSG_LINK, "Failed to read Option"
4794 " field from module EEPROM\n");
4795 return -EINVAL;
4796 }
4797 if ((options[0] & SFP_EEPROM_OPTIONS_LINEAR_RX_OUT_MASK))
4798 *edc_mode = EDC_MODE_LINEAR;
4799 else
4800 *edc_mode = EDC_MODE_LIMITING;
4801 }
4802 DP(NETIF_MSG_LINK, "EDC mode is set to 0x%x\n", *edc_mode);
4803 return 0;
4804}
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00004805/*
4806 * This function read the relevant field from the module (SFP+), and verify it
4807 * is compliant with this board
4808 */
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00004809static int bnx2x_verify_sfp_module(struct bnx2x_phy *phy,
4810 struct link_params *params)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004811{
4812 struct bnx2x *bp = params->bp;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00004813 u32 val, cmd;
4814 u32 fw_resp, fw_cmd_param;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004815 char vendor_name[SFP_EEPROM_VENDOR_NAME_SIZE+1];
4816 char vendor_pn[SFP_EEPROM_PART_NO_SIZE+1];
Yaniv Rosnera22f0782010-09-07 11:41:20 +00004817 phy->flags &= ~FLAGS_SFP_NOT_APPROVED;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004818 val = REG_RD(bp, params->shmem_base +
4819 offsetof(struct shmem_region, dev_info.
4820 port_feature_config[params->port].config));
4821 if ((val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) ==
4822 PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_NO_ENFORCEMENT) {
4823 DP(NETIF_MSG_LINK, "NOT enforcing module verification\n");
4824 return 0;
4825 }
4826
Yaniv Rosnera22f0782010-09-07 11:41:20 +00004827 if (params->feature_config_flags &
4828 FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY) {
4829 /* Use specific phy request */
4830 cmd = DRV_MSG_CODE_VRFY_SPECIFIC_PHY_OPT_MDL;
4831 } else if (params->feature_config_flags &
4832 FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY) {
4833 /* Use first phy request only in case of non-dual media*/
4834 if (DUAL_MEDIA(params)) {
4835 DP(NETIF_MSG_LINK, "FW does not support OPT MDL "
4836 "verification\n");
4837 return -EINVAL;
4838 }
4839 cmd = DRV_MSG_CODE_VRFY_FIRST_PHY_OPT_MDL;
4840 } else {
4841 /* No support in OPT MDL detection */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004842 DP(NETIF_MSG_LINK, "FW does not support OPT MDL "
Yaniv Rosnera22f0782010-09-07 11:41:20 +00004843 "verification\n");
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004844 return -EINVAL;
4845 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004846
Yaniv Rosnera22f0782010-09-07 11:41:20 +00004847 fw_cmd_param = FW_PARAM_SET(phy->addr, phy->type, phy->mdio_ctrl);
4848 fw_resp = bnx2x_fw_command(bp, cmd, fw_cmd_param);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004849 if (fw_resp == FW_MSG_CODE_VRFY_OPT_MDL_SUCCESS) {
4850 DP(NETIF_MSG_LINK, "Approved module\n");
4851 return 0;
4852 }
4853
4854 /* format the warning message */
4855 if (bnx2x_read_sfp_module_eeprom(phy,
4856 params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004857 SFP_EEPROM_VENDOR_NAME_ADDR,
4858 SFP_EEPROM_VENDOR_NAME_SIZE,
4859 (u8 *)vendor_name))
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004860 vendor_name[0] = '\0';
4861 else
4862 vendor_name[SFP_EEPROM_VENDOR_NAME_SIZE] = '\0';
4863 if (bnx2x_read_sfp_module_eeprom(phy,
4864 params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004865 SFP_EEPROM_PART_NO_ADDR,
4866 SFP_EEPROM_PART_NO_SIZE,
4867 (u8 *)vendor_pn))
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004868 vendor_pn[0] = '\0';
4869 else
4870 vendor_pn[SFP_EEPROM_PART_NO_SIZE] = '\0';
4871
Yaniv Rosner6d870c32011-01-31 04:22:20 +00004872 netdev_err(bp->dev, "Warning: Unqualified SFP+ module detected,"
4873 " Port %d from %s part number %s\n",
4874 params->port, vendor_name, vendor_pn);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00004875 phy->flags |= FLAGS_SFP_NOT_APPROVED;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004876 return -EINVAL;
4877}
4878
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00004879static int bnx2x_wait_for_sfp_module_initialized(struct bnx2x_phy *phy,
4880 struct link_params *params)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004881
4882{
4883 u8 val;
4884 struct bnx2x *bp = params->bp;
4885 u16 timeout;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00004886 /*
4887 * Initialization time after hot-plug may take up to 300ms for
4888 * some phys type ( e.g. JDSU )
4889 */
4890
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004891 for (timeout = 0; timeout < 60; timeout++) {
4892 if (bnx2x_read_sfp_module_eeprom(phy, params, 1, 1, &val)
4893 == 0) {
4894 DP(NETIF_MSG_LINK, "SFP+ module initialization "
4895 "took %d ms\n", timeout * 5);
4896 return 0;
4897 }
4898 msleep(5);
4899 }
4900 return -EINVAL;
4901}
4902
4903static void bnx2x_8727_power_module(struct bnx2x *bp,
4904 struct bnx2x_phy *phy,
4905 u8 is_power_up) {
4906 /* Make sure GPIOs are not using for LED mode */
4907 u16 val;
4908 /*
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00004909 * In the GPIO register, bit 4 is use to determine if the GPIOs are
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004910 * operating as INPUT or as OUTPUT. Bit 1 is for input, and 0 for
4911 * output
4912 * Bits 0-1 determine the gpios value for OUTPUT in case bit 4 val is 0
4913 * Bits 8-9 determine the gpios value for INPUT in case bit 4 val is 1
4914 * where the 1st bit is the over-current(only input), and 2nd bit is
4915 * for power( only output )
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00004916 *
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004917 * In case of NOC feature is disabled and power is up, set GPIO control
4918 * as input to enable listening of over-current indication
4919 */
4920 if (phy->flags & FLAGS_NOC)
4921 return;
Yaniv Rosner27d02432011-05-31 21:27:48 +00004922 if (is_power_up)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004923 val = (1<<4);
4924 else
4925 /*
4926 * Set GPIO control to OUTPUT, and set the power bit
4927 * to according to the is_power_up
4928 */
Yaniv Rosner27d02432011-05-31 21:27:48 +00004929 val = (1<<1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004930
4931 bnx2x_cl45_write(bp, phy,
4932 MDIO_PMA_DEVAD,
4933 MDIO_PMA_REG_8727_GPIO_CTRL,
4934 val);
4935}
4936
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00004937static int bnx2x_8726_set_limiting_mode(struct bnx2x *bp,
4938 struct bnx2x_phy *phy,
4939 u16 edc_mode)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004940{
4941 u16 cur_limiting_mode;
4942
4943 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004944 MDIO_PMA_DEVAD,
4945 MDIO_PMA_REG_ROM_VER2,
4946 &cur_limiting_mode);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004947 DP(NETIF_MSG_LINK, "Current Limiting mode is 0x%x\n",
4948 cur_limiting_mode);
4949
4950 if (edc_mode == EDC_MODE_LIMITING) {
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004951 DP(NETIF_MSG_LINK, "Setting LIMITING MODE\n");
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004952 bnx2x_cl45_write(bp, phy,
4953 MDIO_PMA_DEVAD,
4954 MDIO_PMA_REG_ROM_VER2,
4955 EDC_MODE_LIMITING);
4956 } else { /* LRM mode ( default )*/
4957
4958 DP(NETIF_MSG_LINK, "Setting LRM MODE\n");
4959
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00004960 /*
4961 * Changing to LRM mode takes quite few seconds. So do it only
4962 * if current mode is limiting (default is LRM)
4963 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004964 if (cur_limiting_mode != EDC_MODE_LIMITING)
4965 return 0;
4966
4967 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004968 MDIO_PMA_DEVAD,
4969 MDIO_PMA_REG_LRM_MODE,
4970 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004971 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004972 MDIO_PMA_DEVAD,
4973 MDIO_PMA_REG_ROM_VER2,
4974 0x128);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004975 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004976 MDIO_PMA_DEVAD,
4977 MDIO_PMA_REG_MISC_CTRL0,
4978 0x4008);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004979 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004980 MDIO_PMA_DEVAD,
4981 MDIO_PMA_REG_LRM_MODE,
4982 0xaaaa);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004983 }
4984 return 0;
4985}
4986
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00004987static int bnx2x_8727_set_limiting_mode(struct bnx2x *bp,
4988 struct bnx2x_phy *phy,
4989 u16 edc_mode)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004990{
4991 u16 phy_identifier;
4992 u16 rom_ver2_val;
4993 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004994 MDIO_PMA_DEVAD,
4995 MDIO_PMA_REG_PHY_IDENTIFIER,
4996 &phy_identifier);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004997
4998 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004999 MDIO_PMA_DEVAD,
5000 MDIO_PMA_REG_PHY_IDENTIFIER,
5001 (phy_identifier & ~(1<<9)));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005002
5003 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005004 MDIO_PMA_DEVAD,
5005 MDIO_PMA_REG_ROM_VER2,
5006 &rom_ver2_val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005007 /* Keep the MSB 8-bits, and set the LSB 8-bits with the edc_mode */
5008 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005009 MDIO_PMA_DEVAD,
5010 MDIO_PMA_REG_ROM_VER2,
5011 (rom_ver2_val & 0xff00) | (edc_mode & 0x00ff));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005012
5013 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005014 MDIO_PMA_DEVAD,
5015 MDIO_PMA_REG_PHY_IDENTIFIER,
5016 (phy_identifier | (1<<9)));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005017
5018 return 0;
5019}
5020
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005021static void bnx2x_8727_specific_func(struct bnx2x_phy *phy,
5022 struct link_params *params,
5023 u32 action)
5024{
5025 struct bnx2x *bp = params->bp;
5026
5027 switch (action) {
5028 case DISABLE_TX:
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00005029 bnx2x_sfp_set_transmitter(params, phy, 0);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005030 break;
5031 case ENABLE_TX:
5032 if (!(phy->flags & FLAGS_SFP_NOT_APPROVED))
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00005033 bnx2x_sfp_set_transmitter(params, phy, 1);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005034 break;
5035 default:
5036 DP(NETIF_MSG_LINK, "Function 0x%x not supported by 8727\n",
5037 action);
5038 return;
5039 }
5040}
5041
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00005042static void bnx2x_set_sfp_module_fault_led(struct link_params *params,
5043 u8 gpio_mode)
5044{
5045 struct bnx2x *bp = params->bp;
5046
5047 u32 fault_led_gpio = REG_RD(bp, params->shmem_base +
5048 offsetof(struct shmem_region,
5049 dev_info.port_hw_config[params->port].sfp_ctrl)) &
5050 PORT_HW_CFG_FAULT_MODULE_LED_MASK;
5051 switch (fault_led_gpio) {
5052 case PORT_HW_CFG_FAULT_MODULE_LED_DISABLED:
5053 return;
5054 case PORT_HW_CFG_FAULT_MODULE_LED_GPIO0:
5055 case PORT_HW_CFG_FAULT_MODULE_LED_GPIO1:
5056 case PORT_HW_CFG_FAULT_MODULE_LED_GPIO2:
5057 case PORT_HW_CFG_FAULT_MODULE_LED_GPIO3:
5058 {
5059 u8 gpio_port = bnx2x_get_gpio_port(params);
5060 u16 gpio_pin = fault_led_gpio -
5061 PORT_HW_CFG_FAULT_MODULE_LED_GPIO0;
5062 DP(NETIF_MSG_LINK, "Set fault module-detected led "
5063 "pin %x port %x mode %x\n",
5064 gpio_pin, gpio_port, gpio_mode);
5065 bnx2x_set_gpio(bp, gpio_pin, gpio_mode, gpio_port);
5066 }
5067 break;
5068 default:
5069 DP(NETIF_MSG_LINK, "Error: Invalid fault led mode 0x%x\n",
5070 fault_led_gpio);
5071 }
5072}
5073
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00005074static void bnx2x_power_sfp_module(struct link_params *params,
5075 struct bnx2x_phy *phy,
5076 u8 power)
5077{
5078 struct bnx2x *bp = params->bp;
5079 DP(NETIF_MSG_LINK, "Setting SFP+ power to %x\n", power);
5080
5081 switch (phy->type) {
5082 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
5083 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8722:
5084 bnx2x_8727_power_module(params->bp, phy, power);
5085 break;
5086 default:
5087 break;
5088 }
5089}
5090
5091static void bnx2x_set_limiting_mode(struct link_params *params,
5092 struct bnx2x_phy *phy,
5093 u16 edc_mode)
5094{
5095 switch (phy->type) {
5096 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
5097 bnx2x_8726_set_limiting_mode(params->bp, phy, edc_mode);
5098 break;
5099 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
5100 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8722:
5101 bnx2x_8727_set_limiting_mode(params->bp, phy, edc_mode);
5102 break;
5103 }
5104}
5105
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00005106int bnx2x_sfp_module_detection(struct bnx2x_phy *phy,
5107 struct link_params *params)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005108{
5109 struct bnx2x *bp = params->bp;
5110 u16 edc_mode;
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00005111 int rc = 0;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005112
5113 u32 val = REG_RD(bp, params->shmem_base +
5114 offsetof(struct shmem_region, dev_info.
5115 port_feature_config[params->port].config));
5116
5117 DP(NETIF_MSG_LINK, "SFP+ module plugged in/out detected on port %d\n",
5118 params->port);
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00005119 /* Power up module */
5120 bnx2x_power_sfp_module(params, phy, 1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005121 if (bnx2x_get_edc_mode(phy, params, &edc_mode) != 0) {
5122 DP(NETIF_MSG_LINK, "Failed to get valid module type\n");
5123 return -EINVAL;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005124 } else if (bnx2x_verify_sfp_module(phy, params) != 0) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005125 /* check SFP+ module compatibility */
5126 DP(NETIF_MSG_LINK, "Module verification failed!!\n");
5127 rc = -EINVAL;
5128 /* Turn on fault module-detected led */
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00005129 bnx2x_set_sfp_module_fault_led(params,
5130 MISC_REGISTERS_GPIO_HIGH);
5131
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00005132 /* Check if need to power down the SFP+ module */
5133 if ((val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) ==
5134 PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_POWER_DOWN) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005135 DP(NETIF_MSG_LINK, "Shutdown SFP+ module!!\n");
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00005136 bnx2x_power_sfp_module(params, phy, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005137 return rc;
5138 }
5139 } else {
5140 /* Turn off fault module-detected led */
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00005141 bnx2x_set_sfp_module_fault_led(params, MISC_REGISTERS_GPIO_LOW);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005142 }
5143
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005144 /*
5145 * Check and set limiting mode / LRM mode on 8726. On 8727 it
5146 * is done automatically
5147 */
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00005148 bnx2x_set_limiting_mode(params, phy, edc_mode);
5149
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005150 /*
5151 * Enable transmit for this module if the module is approved, or
5152 * if unapproved modules should also enable the Tx laser
5153 */
5154 if (rc == 0 ||
5155 (val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) !=
5156 PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_DISABLE_TX_LASER)
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00005157 bnx2x_sfp_set_transmitter(params, phy, 1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005158 else
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00005159 bnx2x_sfp_set_transmitter(params, phy, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005160
5161 return rc;
5162}
5163
5164void bnx2x_handle_module_detect_int(struct link_params *params)
5165{
5166 struct bnx2x *bp = params->bp;
5167 struct bnx2x_phy *phy = &params->phy[EXT_PHY1];
5168 u32 gpio_val;
5169 u8 port = params->port;
5170
5171 /* Set valid module led off */
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00005172 bnx2x_set_sfp_module_fault_led(params, MISC_REGISTERS_GPIO_HIGH);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005173
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005174 /* Get current gpio val reflecting module plugged in / out*/
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005175 gpio_val = bnx2x_get_gpio(bp, MISC_REGISTERS_GPIO_3, port);
5176
5177 /* Call the handling function in case module is detected */
5178 if (gpio_val == 0) {
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00005179 bnx2x_power_sfp_module(params, phy, 1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005180 bnx2x_set_gpio_int(bp, MISC_REGISTERS_GPIO_3,
5181 MISC_REGISTERS_GPIO_INT_OUTPUT_CLR,
5182 port);
5183
5184 if (bnx2x_wait_for_sfp_module_initialized(phy, params) == 0)
5185 bnx2x_sfp_module_detection(phy, params);
5186 else
5187 DP(NETIF_MSG_LINK, "SFP+ module is not initialized\n");
5188 } else {
5189 u32 val = REG_RD(bp, params->shmem_base +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005190 offsetof(struct shmem_region, dev_info.
5191 port_feature_config[params->port].
5192 config));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005193
5194 bnx2x_set_gpio_int(bp, MISC_REGISTERS_GPIO_3,
5195 MISC_REGISTERS_GPIO_INT_OUTPUT_SET,
5196 port);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005197 /*
5198 * Module was plugged out.
5199 * Disable transmit for this module
5200 */
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00005201 phy->media_type = ETH_PHY_NOT_PRESENT;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005202 if ((val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) ==
5203 PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_DISABLE_TX_LASER)
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00005204 bnx2x_sfp_set_transmitter(params, phy, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005205 }
5206}
5207
5208/******************************************************************/
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00005209/* Used by 8706 and 8727 */
5210/******************************************************************/
5211static void bnx2x_sfp_mask_fault(struct bnx2x *bp,
5212 struct bnx2x_phy *phy,
5213 u16 alarm_status_offset,
5214 u16 alarm_ctrl_offset)
5215{
5216 u16 alarm_status, val;
5217 bnx2x_cl45_read(bp, phy,
5218 MDIO_PMA_DEVAD, alarm_status_offset,
5219 &alarm_status);
5220 bnx2x_cl45_read(bp, phy,
5221 MDIO_PMA_DEVAD, alarm_status_offset,
5222 &alarm_status);
5223 /* Mask or enable the fault event. */
5224 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD, alarm_ctrl_offset, &val);
5225 if (alarm_status & (1<<0))
5226 val &= ~(1<<0);
5227 else
5228 val |= (1<<0);
5229 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, alarm_ctrl_offset, val);
5230}
5231/******************************************************************/
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005232/* common BCM8706/BCM8726 PHY SECTION */
5233/******************************************************************/
5234static u8 bnx2x_8706_8726_read_status(struct bnx2x_phy *phy,
5235 struct link_params *params,
5236 struct link_vars *vars)
5237{
5238 u8 link_up = 0;
5239 u16 val1, val2, rx_sd, pcs_status;
5240 struct bnx2x *bp = params->bp;
5241 DP(NETIF_MSG_LINK, "XGXS 8706/8726\n");
5242 /* Clear RX Alarm*/
5243 bnx2x_cl45_read(bp, phy,
5244 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_ALARM, &val2);
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00005245
5246 bnx2x_sfp_mask_fault(bp, phy, MDIO_PMA_REG_TX_ALARM,
5247 MDIO_PMA_REG_TX_ALARM_CTRL);
5248
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005249 /* clear LASI indication*/
5250 bnx2x_cl45_read(bp, phy,
5251 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_STATUS, &val1);
5252 bnx2x_cl45_read(bp, phy,
5253 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_STATUS, &val2);
5254 DP(NETIF_MSG_LINK, "8706/8726 LASI status 0x%x--> 0x%x\n", val1, val2);
5255
5256 bnx2x_cl45_read(bp, phy,
5257 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_SD, &rx_sd);
5258 bnx2x_cl45_read(bp, phy,
5259 MDIO_PCS_DEVAD, MDIO_PCS_REG_STATUS, &pcs_status);
5260 bnx2x_cl45_read(bp, phy,
5261 MDIO_AN_DEVAD, MDIO_AN_REG_LINK_STATUS, &val2);
5262 bnx2x_cl45_read(bp, phy,
5263 MDIO_AN_DEVAD, MDIO_AN_REG_LINK_STATUS, &val2);
5264
5265 DP(NETIF_MSG_LINK, "8706/8726 rx_sd 0x%x pcs_status 0x%x 1Gbps"
5266 " link_status 0x%x\n", rx_sd, pcs_status, val2);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005267 /*
5268 * link is up if both bit 0 of pmd_rx_sd and bit 0 of pcs_status
5269 * are set, or if the autoneg bit 1 is set
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005270 */
5271 link_up = ((rx_sd & pcs_status & 0x1) || (val2 & (1<<1)));
5272 if (link_up) {
5273 if (val2 & (1<<1))
5274 vars->line_speed = SPEED_1000;
5275 else
5276 vars->line_speed = SPEED_10000;
5277 bnx2x_ext_phy_resolve_fc(phy, params, vars);
Yaniv Rosner791f18c2011-01-18 04:33:42 +00005278 vars->duplex = DUPLEX_FULL;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005279 }
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00005280
5281 /* Capture 10G link fault. Read twice to clear stale value. */
5282 if (vars->line_speed == SPEED_10000) {
5283 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
5284 MDIO_PMA_REG_TX_ALARM, &val1);
5285 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
5286 MDIO_PMA_REG_TX_ALARM, &val1);
5287 if (val1 & (1<<0))
5288 vars->fault_detected = 1;
5289 }
5290
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005291 return link_up;
5292}
5293
5294/******************************************************************/
5295/* BCM8706 PHY SECTION */
5296/******************************************************************/
5297static u8 bnx2x_8706_config_init(struct bnx2x_phy *phy,
5298 struct link_params *params,
5299 struct link_vars *vars)
5300{
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00005301 u32 tx_en_mode;
5302 u16 cnt, val, tmp1;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005303 struct bnx2x *bp = params->bp;
5304 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005305 MISC_REGISTERS_GPIO_OUTPUT_HIGH, params->port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005306 /* HW reset */
5307 bnx2x_ext_phy_hw_reset(bp, params->port);
5308 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0xa040);
Yaniv Rosner6d870c32011-01-31 04:22:20 +00005309 bnx2x_wait_reset_complete(bp, phy, params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005310
5311 /* Wait until fw is loaded */
5312 for (cnt = 0; cnt < 100; cnt++) {
5313 bnx2x_cl45_read(bp, phy,
5314 MDIO_PMA_DEVAD, MDIO_PMA_REG_ROM_VER1, &val);
5315 if (val)
5316 break;
5317 msleep(10);
5318 }
5319 DP(NETIF_MSG_LINK, "XGXS 8706 is initialized after %d ms\n", cnt);
5320 if ((params->feature_config_flags &
5321 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED)) {
5322 u8 i;
5323 u16 reg;
5324 for (i = 0; i < 4; i++) {
5325 reg = MDIO_XS_8706_REG_BANK_RX0 +
5326 i*(MDIO_XS_8706_REG_BANK_RX1 -
5327 MDIO_XS_8706_REG_BANK_RX0);
5328 bnx2x_cl45_read(bp, phy, MDIO_XS_DEVAD, reg, &val);
5329 /* Clear first 3 bits of the control */
5330 val &= ~0x7;
5331 /* Set control bits according to configuration */
5332 val |= (phy->rx_preemphasis[i] & 0x7);
5333 DP(NETIF_MSG_LINK, "Setting RX Equalizer to BCM8706"
5334 " reg 0x%x <-- val 0x%x\n", reg, val);
5335 bnx2x_cl45_write(bp, phy, MDIO_XS_DEVAD, reg, val);
5336 }
5337 }
5338 /* Force speed */
5339 if (phy->req_line_speed == SPEED_10000) {
5340 DP(NETIF_MSG_LINK, "XGXS 8706 force 10Gbps\n");
5341
5342 bnx2x_cl45_write(bp, phy,
5343 MDIO_PMA_DEVAD,
5344 MDIO_PMA_REG_DIGITAL_CTRL, 0x400);
5345 bnx2x_cl45_write(bp, phy,
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00005346 MDIO_PMA_DEVAD, MDIO_PMA_REG_TX_ALARM_CTRL,
5347 0);
5348 /* Arm LASI for link and Tx fault. */
5349 bnx2x_cl45_write(bp, phy,
5350 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_CTRL, 3);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005351 } else {
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005352 /* Force 1Gbps using autoneg with 1G advertisement */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005353
5354 /* Allow CL37 through CL73 */
5355 DP(NETIF_MSG_LINK, "XGXS 8706 AutoNeg\n");
5356 bnx2x_cl45_write(bp, phy,
5357 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_CL73, 0x040c);
5358
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005359 /* Enable Full-Duplex advertisement on CL37 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005360 bnx2x_cl45_write(bp, phy,
5361 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LP, 0x0020);
5362 /* Enable CL37 AN */
5363 bnx2x_cl45_write(bp, phy,
5364 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_AN, 0x1000);
5365 /* 1G support */
5366 bnx2x_cl45_write(bp, phy,
5367 MDIO_AN_DEVAD, MDIO_AN_REG_ADV, (1<<5));
5368
5369 /* Enable clause 73 AN */
5370 bnx2x_cl45_write(bp, phy,
5371 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x1200);
5372 bnx2x_cl45_write(bp, phy,
5373 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_ALARM_CTRL,
5374 0x0400);
5375 bnx2x_cl45_write(bp, phy,
5376 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_CTRL,
5377 0x0004);
5378 }
5379 bnx2x_save_bcm_spirom_ver(bp, phy, params->port);
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00005380
5381 /*
5382 * If TX Laser is controlled by GPIO_0, do not let PHY go into low
5383 * power mode, if TX Laser is disabled
5384 */
5385
5386 tx_en_mode = REG_RD(bp, params->shmem_base +
5387 offsetof(struct shmem_region,
5388 dev_info.port_hw_config[params->port].sfp_ctrl))
5389 & PORT_HW_CFG_TX_LASER_MASK;
5390
5391 if (tx_en_mode == PORT_HW_CFG_TX_LASER_GPIO0) {
5392 DP(NETIF_MSG_LINK, "Enabling TXONOFF_PWRDN_DIS\n");
5393 bnx2x_cl45_read(bp, phy,
5394 MDIO_PMA_DEVAD, MDIO_PMA_REG_DIGITAL_CTRL, &tmp1);
5395 tmp1 |= 0x1;
5396 bnx2x_cl45_write(bp, phy,
5397 MDIO_PMA_DEVAD, MDIO_PMA_REG_DIGITAL_CTRL, tmp1);
5398 }
5399
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005400 return 0;
5401}
5402
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00005403static int bnx2x_8706_read_status(struct bnx2x_phy *phy,
5404 struct link_params *params,
5405 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005406{
5407 return bnx2x_8706_8726_read_status(phy, params, vars);
5408}
5409
5410/******************************************************************/
5411/* BCM8726 PHY SECTION */
5412/******************************************************************/
5413static void bnx2x_8726_config_loopback(struct bnx2x_phy *phy,
5414 struct link_params *params)
5415{
5416 struct bnx2x *bp = params->bp;
5417 DP(NETIF_MSG_LINK, "PMA/PMD ext_phy_loopback: 8726\n");
5418 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x0001);
5419}
5420
5421static void bnx2x_8726_external_rom_boot(struct bnx2x_phy *phy,
5422 struct link_params *params)
5423{
5424 struct bnx2x *bp = params->bp;
5425 /* Need to wait 100ms after reset */
5426 msleep(100);
5427
5428 /* Micro controller re-boot */
5429 bnx2x_cl45_write(bp, phy,
5430 MDIO_PMA_DEVAD, MDIO_PMA_REG_GEN_CTRL, 0x018B);
5431
5432 /* Set soft reset */
5433 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005434 MDIO_PMA_DEVAD,
5435 MDIO_PMA_REG_GEN_CTRL,
5436 MDIO_PMA_REG_GEN_CTRL_ROM_MICRO_RESET);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005437
5438 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005439 MDIO_PMA_DEVAD,
5440 MDIO_PMA_REG_MISC_CTRL1, 0x0001);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005441
5442 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005443 MDIO_PMA_DEVAD,
5444 MDIO_PMA_REG_GEN_CTRL,
5445 MDIO_PMA_REG_GEN_CTRL_ROM_RESET_INTERNAL_MP);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005446
5447 /* wait for 150ms for microcode load */
5448 msleep(150);
5449
5450 /* Disable serial boot control, tristates pins SS_N, SCK, MOSI, MISO */
5451 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005452 MDIO_PMA_DEVAD,
5453 MDIO_PMA_REG_MISC_CTRL1, 0x0000);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005454
5455 msleep(200);
5456 bnx2x_save_bcm_spirom_ver(bp, phy, params->port);
5457}
5458
5459static u8 bnx2x_8726_read_status(struct bnx2x_phy *phy,
5460 struct link_params *params,
5461 struct link_vars *vars)
5462{
5463 struct bnx2x *bp = params->bp;
5464 u16 val1;
5465 u8 link_up = bnx2x_8706_8726_read_status(phy, params, vars);
5466 if (link_up) {
5467 bnx2x_cl45_read(bp, phy,
5468 MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER,
5469 &val1);
5470 if (val1 & (1<<15)) {
5471 DP(NETIF_MSG_LINK, "Tx is disabled\n");
5472 link_up = 0;
5473 vars->line_speed = 0;
5474 }
5475 }
5476 return link_up;
5477}
5478
5479
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00005480static int bnx2x_8726_config_init(struct bnx2x_phy *phy,
5481 struct link_params *params,
5482 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005483{
5484 struct bnx2x *bp = params->bp;
5485 u32 val;
5486 u32 swap_val, swap_override, aeu_gpio_mask, offset;
5487 DP(NETIF_MSG_LINK, "Initializing BCM8726\n");
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005488
5489 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 1<<15);
Yaniv Rosner6d870c32011-01-31 04:22:20 +00005490 bnx2x_wait_reset_complete(bp, phy, params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005491
5492 bnx2x_8726_external_rom_boot(phy, params);
5493
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005494 /*
5495 * Need to call module detected on initialization since the module
5496 * detection triggered by actual module insertion might occur before
5497 * driver is loaded, and when driver is loaded, it reset all
5498 * registers, including the transmitter
5499 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005500 bnx2x_sfp_module_detection(phy, params);
5501
5502 if (phy->req_line_speed == SPEED_1000) {
5503 DP(NETIF_MSG_LINK, "Setting 1G force\n");
5504 bnx2x_cl45_write(bp, phy,
5505 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x40);
5506 bnx2x_cl45_write(bp, phy,
5507 MDIO_PMA_DEVAD, MDIO_PMA_REG_10G_CTRL2, 0xD);
5508 bnx2x_cl45_write(bp, phy,
5509 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_CTRL, 0x5);
5510 bnx2x_cl45_write(bp, phy,
5511 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_ALARM_CTRL,
5512 0x400);
5513 } else if ((phy->req_line_speed == SPEED_AUTO_NEG) &&
5514 (phy->speed_cap_mask &
5515 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G) &&
5516 ((phy->speed_cap_mask &
5517 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G) !=
5518 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) {
5519 DP(NETIF_MSG_LINK, "Setting 1G clause37\n");
5520 /* Set Flow control */
5521 bnx2x_ext_phy_set_pause(params, phy, vars);
5522 bnx2x_cl45_write(bp, phy,
5523 MDIO_AN_DEVAD, MDIO_AN_REG_ADV, 0x20);
5524 bnx2x_cl45_write(bp, phy,
5525 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_CL73, 0x040c);
5526 bnx2x_cl45_write(bp, phy,
5527 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LD, 0x0020);
5528 bnx2x_cl45_write(bp, phy,
5529 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_AN, 0x1000);
5530 bnx2x_cl45_write(bp, phy,
5531 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x1200);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005532 /*
5533 * Enable RX-ALARM control to receive interrupt for 1G speed
5534 * change
5535 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005536 bnx2x_cl45_write(bp, phy,
5537 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_CTRL, 0x4);
5538 bnx2x_cl45_write(bp, phy,
5539 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_ALARM_CTRL,
5540 0x400);
5541
5542 } else { /* Default 10G. Set only LASI control */
5543 bnx2x_cl45_write(bp, phy,
5544 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_CTRL, 1);
5545 }
5546
5547 /* Set TX PreEmphasis if needed */
5548 if ((params->feature_config_flags &
5549 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED)) {
5550 DP(NETIF_MSG_LINK, "Setting TX_CTRL1 0x%x,"
5551 "TX_CTRL2 0x%x\n",
5552 phy->tx_preemphasis[0],
5553 phy->tx_preemphasis[1]);
5554 bnx2x_cl45_write(bp, phy,
5555 MDIO_PMA_DEVAD,
5556 MDIO_PMA_REG_8726_TX_CTRL1,
5557 phy->tx_preemphasis[0]);
5558
5559 bnx2x_cl45_write(bp, phy,
5560 MDIO_PMA_DEVAD,
5561 MDIO_PMA_REG_8726_TX_CTRL2,
5562 phy->tx_preemphasis[1]);
5563 }
5564
5565 /* Set GPIO3 to trigger SFP+ module insertion/removal */
5566 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_3,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005567 MISC_REGISTERS_GPIO_INPUT_HI_Z, params->port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005568
5569 /* The GPIO should be swapped if the swap register is set and active */
5570 swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
5571 swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
5572
5573 /* Select function upon port-swap configuration */
5574 if (params->port == 0) {
5575 offset = MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0;
5576 aeu_gpio_mask = (swap_val && swap_override) ?
5577 AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_1 :
5578 AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_0;
5579 } else {
5580 offset = MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0;
5581 aeu_gpio_mask = (swap_val && swap_override) ?
5582 AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_0 :
5583 AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_1;
5584 }
5585 val = REG_RD(bp, offset);
5586 /* add GPIO3 to group */
5587 val |= aeu_gpio_mask;
5588 REG_WR(bp, offset, val);
5589 return 0;
5590
5591}
5592
5593static void bnx2x_8726_link_reset(struct bnx2x_phy *phy,
5594 struct link_params *params)
5595{
5596 struct bnx2x *bp = params->bp;
5597 DP(NETIF_MSG_LINK, "bnx2x_8726_link_reset port %d\n", params->port);
5598 /* Set serial boot control for external load */
5599 bnx2x_cl45_write(bp, phy,
5600 MDIO_PMA_DEVAD,
5601 MDIO_PMA_REG_GEN_CTRL, 0x0001);
5602}
5603
5604/******************************************************************/
5605/* BCM8727 PHY SECTION */
5606/******************************************************************/
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00005607
5608static void bnx2x_8727_set_link_led(struct bnx2x_phy *phy,
5609 struct link_params *params, u8 mode)
5610{
5611 struct bnx2x *bp = params->bp;
5612 u16 led_mode_bitmask = 0;
5613 u16 gpio_pins_bitmask = 0;
5614 u16 val;
5615 /* Only NOC flavor requires to set the LED specifically */
5616 if (!(phy->flags & FLAGS_NOC))
5617 return;
5618 switch (mode) {
5619 case LED_MODE_FRONT_PANEL_OFF:
5620 case LED_MODE_OFF:
5621 led_mode_bitmask = 0;
5622 gpio_pins_bitmask = 0x03;
5623 break;
5624 case LED_MODE_ON:
5625 led_mode_bitmask = 0;
5626 gpio_pins_bitmask = 0x02;
5627 break;
5628 case LED_MODE_OPER:
5629 led_mode_bitmask = 0x60;
5630 gpio_pins_bitmask = 0x11;
5631 break;
5632 }
5633 bnx2x_cl45_read(bp, phy,
5634 MDIO_PMA_DEVAD,
5635 MDIO_PMA_REG_8727_PCS_OPT_CTRL,
5636 &val);
5637 val &= 0xff8f;
5638 val |= led_mode_bitmask;
5639 bnx2x_cl45_write(bp, phy,
5640 MDIO_PMA_DEVAD,
5641 MDIO_PMA_REG_8727_PCS_OPT_CTRL,
5642 val);
5643 bnx2x_cl45_read(bp, phy,
5644 MDIO_PMA_DEVAD,
5645 MDIO_PMA_REG_8727_GPIO_CTRL,
5646 &val);
5647 val &= 0xffe0;
5648 val |= gpio_pins_bitmask;
5649 bnx2x_cl45_write(bp, phy,
5650 MDIO_PMA_DEVAD,
5651 MDIO_PMA_REG_8727_GPIO_CTRL,
5652 val);
5653}
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005654static void bnx2x_8727_hw_reset(struct bnx2x_phy *phy,
5655 struct link_params *params) {
5656 u32 swap_val, swap_override;
5657 u8 port;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005658 /*
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005659 * The PHY reset is controlled by GPIO 1. Fake the port number
5660 * to cancel the swap done in set_gpio()
5661 */
5662 struct bnx2x *bp = params->bp;
5663 swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
5664 swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
5665 port = (swap_val && swap_override) ^ 1;
5666 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005667 MISC_REGISTERS_GPIO_OUTPUT_LOW, port);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005668}
5669
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00005670static int bnx2x_8727_config_init(struct bnx2x_phy *phy,
5671 struct link_params *params,
5672 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005673{
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00005674 u32 tx_en_mode;
5675 u16 tmp1, val, mod_abs, tmp2;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005676 u16 rx_alarm_ctrl_val;
5677 u16 lasi_ctrl_val;
5678 struct bnx2x *bp = params->bp;
5679 /* Enable PMD link, MOD_ABS_FLT, and 1G link alarm */
5680
Yaniv Rosner6d870c32011-01-31 04:22:20 +00005681 bnx2x_wait_reset_complete(bp, phy, params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005682 rx_alarm_ctrl_val = (1<<2) | (1<<5) ;
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00005683 /* Should be 0x6 to enable XS on Tx side. */
5684 lasi_ctrl_val = 0x0006;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005685
5686 DP(NETIF_MSG_LINK, "Initializing BCM8727\n");
5687 /* enable LASI */
5688 bnx2x_cl45_write(bp, phy,
5689 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_ALARM_CTRL,
5690 rx_alarm_ctrl_val);
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00005691 bnx2x_cl45_write(bp, phy,
5692 MDIO_PMA_DEVAD, MDIO_PMA_REG_TX_ALARM_CTRL,
5693 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005694 bnx2x_cl45_write(bp, phy,
5695 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_CTRL, lasi_ctrl_val);
5696
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005697 /*
5698 * Initially configure MOD_ABS to interrupt when module is
5699 * presence( bit 8)
5700 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005701 bnx2x_cl45_read(bp, phy,
5702 MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER, &mod_abs);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005703 /*
5704 * Set EDC off by setting OPTXLOS signal input to low (bit 9).
5705 * When the EDC is off it locks onto a reference clock and avoids
5706 * becoming 'lost'
5707 */
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00005708 mod_abs &= ~(1<<8);
5709 if (!(phy->flags & FLAGS_NOC))
5710 mod_abs &= ~(1<<9);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005711 bnx2x_cl45_write(bp, phy,
5712 MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER, mod_abs);
5713
5714
5715 /* Make MOD_ABS give interrupt on change */
5716 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_PCS_OPT_CTRL,
5717 &val);
5718 val |= (1<<12);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00005719 if (phy->flags & FLAGS_NOC)
5720 val |= (3<<5);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005721
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005722 /*
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00005723 * Set 8727 GPIOs to input to allow reading from the 8727 GPIO0
5724 * status which reflect SFP+ module over-current
5725 */
5726 if (!(phy->flags & FLAGS_NOC))
5727 val &= 0xff8f; /* Reset bits 4-6 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005728 bnx2x_cl45_write(bp, phy,
5729 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_PCS_OPT_CTRL, val);
5730
5731 bnx2x_8727_power_module(bp, phy, 1);
5732
5733 bnx2x_cl45_read(bp, phy,
5734 MDIO_PMA_DEVAD, MDIO_PMA_REG_M8051_MSGOUT_REG, &tmp1);
5735
5736 bnx2x_cl45_read(bp, phy,
5737 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_ALARM, &tmp1);
5738
5739 /* Set option 1G speed */
5740 if (phy->req_line_speed == SPEED_1000) {
5741 DP(NETIF_MSG_LINK, "Setting 1G force\n");
5742 bnx2x_cl45_write(bp, phy,
5743 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x40);
5744 bnx2x_cl45_write(bp, phy,
5745 MDIO_PMA_DEVAD, MDIO_PMA_REG_10G_CTRL2, 0xD);
5746 bnx2x_cl45_read(bp, phy,
5747 MDIO_PMA_DEVAD, MDIO_PMA_REG_10G_CTRL2, &tmp1);
5748 DP(NETIF_MSG_LINK, "1.7 = 0x%x\n", tmp1);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005749 /*
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005750 * Power down the XAUI until link is up in case of dual-media
5751 * and 1G
5752 */
5753 if (DUAL_MEDIA(params)) {
5754 bnx2x_cl45_read(bp, phy,
5755 MDIO_PMA_DEVAD,
5756 MDIO_PMA_REG_8727_PCS_GP, &val);
5757 val |= (3<<10);
5758 bnx2x_cl45_write(bp, phy,
5759 MDIO_PMA_DEVAD,
5760 MDIO_PMA_REG_8727_PCS_GP, val);
5761 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005762 } else if ((phy->req_line_speed == SPEED_AUTO_NEG) &&
5763 ((phy->speed_cap_mask &
5764 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) &&
5765 ((phy->speed_cap_mask &
5766 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G) !=
5767 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) {
5768
5769 DP(NETIF_MSG_LINK, "Setting 1G clause37\n");
5770 bnx2x_cl45_write(bp, phy,
5771 MDIO_AN_DEVAD, MDIO_AN_REG_8727_MISC_CTRL, 0);
5772 bnx2x_cl45_write(bp, phy,
5773 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_AN, 0x1300);
5774 } else {
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005775 /*
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005776 * Since the 8727 has only single reset pin, need to set the 10G
5777 * registers although it is default
5778 */
5779 bnx2x_cl45_write(bp, phy,
5780 MDIO_AN_DEVAD, MDIO_AN_REG_8727_MISC_CTRL,
5781 0x0020);
5782 bnx2x_cl45_write(bp, phy,
5783 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_AN, 0x0100);
5784 bnx2x_cl45_write(bp, phy,
5785 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x2040);
5786 bnx2x_cl45_write(bp, phy,
5787 MDIO_PMA_DEVAD, MDIO_PMA_REG_10G_CTRL2,
5788 0x0008);
5789 }
5790
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005791 /*
5792 * Set 2-wire transfer rate of SFP+ module EEPROM
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005793 * to 100Khz since some DACs(direct attached cables) do
5794 * not work at 400Khz.
5795 */
5796 bnx2x_cl45_write(bp, phy,
5797 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_TWO_WIRE_SLAVE_ADDR,
5798 0xa001);
5799
5800 /* Set TX PreEmphasis if needed */
5801 if ((params->feature_config_flags &
5802 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED)) {
5803 DP(NETIF_MSG_LINK, "Setting TX_CTRL1 0x%x, TX_CTRL2 0x%x\n",
5804 phy->tx_preemphasis[0],
5805 phy->tx_preemphasis[1]);
5806 bnx2x_cl45_write(bp, phy,
5807 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_TX_CTRL1,
5808 phy->tx_preemphasis[0]);
5809
5810 bnx2x_cl45_write(bp, phy,
5811 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_TX_CTRL2,
5812 phy->tx_preemphasis[1]);
5813 }
5814
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00005815 /*
5816 * If TX Laser is controlled by GPIO_0, do not let PHY go into low
5817 * power mode, if TX Laser is disabled
5818 */
5819 tx_en_mode = REG_RD(bp, params->shmem_base +
5820 offsetof(struct shmem_region,
5821 dev_info.port_hw_config[params->port].sfp_ctrl))
5822 & PORT_HW_CFG_TX_LASER_MASK;
5823
5824 if (tx_en_mode == PORT_HW_CFG_TX_LASER_GPIO0) {
5825
5826 DP(NETIF_MSG_LINK, "Enabling TXONOFF_PWRDN_DIS\n");
5827 bnx2x_cl45_read(bp, phy,
5828 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_OPT_CFG_REG, &tmp2);
5829 tmp2 |= 0x1000;
5830 tmp2 &= 0xFFEF;
5831 bnx2x_cl45_write(bp, phy,
5832 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_OPT_CFG_REG, tmp2);
5833 }
5834
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005835 return 0;
5836}
5837
5838static void bnx2x_8727_handle_mod_abs(struct bnx2x_phy *phy,
5839 struct link_params *params)
5840{
5841 struct bnx2x *bp = params->bp;
5842 u16 mod_abs, rx_alarm_status;
5843 u32 val = REG_RD(bp, params->shmem_base +
5844 offsetof(struct shmem_region, dev_info.
5845 port_feature_config[params->port].
5846 config));
5847 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005848 MDIO_PMA_DEVAD,
5849 MDIO_PMA_REG_PHY_IDENTIFIER, &mod_abs);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005850 if (mod_abs & (1<<8)) {
5851
5852 /* Module is absent */
5853 DP(NETIF_MSG_LINK, "MOD_ABS indication "
5854 "show module is absent\n");
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00005855 phy->media_type = ETH_PHY_NOT_PRESENT;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005856 /*
5857 * 1. Set mod_abs to detect next module
5858 * presence event
5859 * 2. Set EDC off by setting OPTXLOS signal input to low
5860 * (bit 9).
5861 * When the EDC is off it locks onto a reference clock and
5862 * avoids becoming 'lost'.
5863 */
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00005864 mod_abs &= ~(1<<8);
5865 if (!(phy->flags & FLAGS_NOC))
5866 mod_abs &= ~(1<<9);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005867 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005868 MDIO_PMA_DEVAD,
5869 MDIO_PMA_REG_PHY_IDENTIFIER, mod_abs);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005870
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005871 /*
5872 * Clear RX alarm since it stays up as long as
5873 * the mod_abs wasn't changed
5874 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005875 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005876 MDIO_PMA_DEVAD,
5877 MDIO_PMA_REG_RX_ALARM, &rx_alarm_status);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005878
5879 } else {
5880 /* Module is present */
5881 DP(NETIF_MSG_LINK, "MOD_ABS indication "
5882 "show module is present\n");
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005883 /*
5884 * First disable transmitter, and if the module is ok, the
5885 * module_detection will enable it
5886 * 1. Set mod_abs to detect next module absent event ( bit 8)
5887 * 2. Restore the default polarity of the OPRXLOS signal and
5888 * this signal will then correctly indicate the presence or
5889 * absence of the Rx signal. (bit 9)
5890 */
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00005891 mod_abs |= (1<<8);
5892 if (!(phy->flags & FLAGS_NOC))
5893 mod_abs |= (1<<9);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005894 bnx2x_cl45_write(bp, phy,
5895 MDIO_PMA_DEVAD,
5896 MDIO_PMA_REG_PHY_IDENTIFIER, mod_abs);
5897
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005898 /*
5899 * Clear RX alarm since it stays up as long as the mod_abs
5900 * wasn't changed. This is need to be done before calling the
5901 * module detection, otherwise it will clear* the link update
5902 * alarm
5903 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005904 bnx2x_cl45_read(bp, phy,
5905 MDIO_PMA_DEVAD,
5906 MDIO_PMA_REG_RX_ALARM, &rx_alarm_status);
5907
5908
5909 if ((val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) ==
5910 PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_DISABLE_TX_LASER)
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00005911 bnx2x_sfp_set_transmitter(params, phy, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005912
5913 if (bnx2x_wait_for_sfp_module_initialized(phy, params) == 0)
5914 bnx2x_sfp_module_detection(phy, params);
5915 else
5916 DP(NETIF_MSG_LINK, "SFP+ module is not initialized\n");
5917 }
5918
5919 DP(NETIF_MSG_LINK, "8727 RX_ALARM_STATUS 0x%x\n",
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005920 rx_alarm_status);
5921 /* No need to check link status in case of module plugged in/out */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005922}
5923
5924static u8 bnx2x_8727_read_status(struct bnx2x_phy *phy,
5925 struct link_params *params,
5926 struct link_vars *vars)
5927
5928{
5929 struct bnx2x *bp = params->bp;
Yaniv Rosner27d02432011-05-31 21:27:48 +00005930 u8 link_up = 0, oc_port = params->port;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005931 u16 link_status = 0;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005932 u16 rx_alarm_status, lasi_ctrl, val1;
5933
5934 /* If PHY is not initialized, do not check link status */
5935 bnx2x_cl45_read(bp, phy,
5936 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_CTRL,
5937 &lasi_ctrl);
5938 if (!lasi_ctrl)
5939 return 0;
5940
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005941 /* Check the LASI */
5942 bnx2x_cl45_read(bp, phy,
5943 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_ALARM,
5944 &rx_alarm_status);
5945 vars->line_speed = 0;
5946 DP(NETIF_MSG_LINK, "8727 RX_ALARM_STATUS 0x%x\n", rx_alarm_status);
5947
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00005948 bnx2x_sfp_mask_fault(bp, phy, MDIO_PMA_REG_TX_ALARM,
5949 MDIO_PMA_REG_TX_ALARM_CTRL);
5950
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005951 bnx2x_cl45_read(bp, phy,
5952 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_STATUS, &val1);
5953
5954 DP(NETIF_MSG_LINK, "8727 LASI status 0x%x\n", val1);
5955
5956 /* Clear MSG-OUT */
5957 bnx2x_cl45_read(bp, phy,
5958 MDIO_PMA_DEVAD, MDIO_PMA_REG_M8051_MSGOUT_REG, &val1);
5959
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005960 /*
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005961 * If a module is present and there is need to check
5962 * for over current
5963 */
5964 if (!(phy->flags & FLAGS_NOC) && !(rx_alarm_status & (1<<5))) {
5965 /* Check over-current using 8727 GPIO0 input*/
5966 bnx2x_cl45_read(bp, phy,
5967 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_GPIO_CTRL,
5968 &val1);
5969
5970 if ((val1 & (1<<8)) == 0) {
Yaniv Rosner27d02432011-05-31 21:27:48 +00005971 if (!CHIP_IS_E1x(bp))
5972 oc_port = BP_PATH(bp) + (params->port << 1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005973 DP(NETIF_MSG_LINK, "8727 Power fault has been detected"
Yaniv Rosner27d02432011-05-31 21:27:48 +00005974 " on port %d\n", oc_port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005975 netdev_err(bp->dev, "Error: Power fault on Port %d has"
5976 " been detected and the power to "
5977 "that SFP+ module has been removed"
5978 " to prevent failure of the card."
5979 " Please remove the SFP+ module and"
5980 " restart the system to clear this"
5981 " error.\n",
Yaniv Rosner27d02432011-05-31 21:27:48 +00005982 oc_port);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005983 /* Disable all RX_ALARMs except for mod_abs */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005984 bnx2x_cl45_write(bp, phy,
5985 MDIO_PMA_DEVAD,
5986 MDIO_PMA_REG_RX_ALARM_CTRL, (1<<5));
5987
5988 bnx2x_cl45_read(bp, phy,
5989 MDIO_PMA_DEVAD,
5990 MDIO_PMA_REG_PHY_IDENTIFIER, &val1);
5991 /* Wait for module_absent_event */
5992 val1 |= (1<<8);
5993 bnx2x_cl45_write(bp, phy,
5994 MDIO_PMA_DEVAD,
5995 MDIO_PMA_REG_PHY_IDENTIFIER, val1);
5996 /* Clear RX alarm */
5997 bnx2x_cl45_read(bp, phy,
5998 MDIO_PMA_DEVAD,
5999 MDIO_PMA_REG_RX_ALARM, &rx_alarm_status);
6000 return 0;
6001 }
6002 } /* Over current check */
6003
6004 /* When module absent bit is set, check module */
6005 if (rx_alarm_status & (1<<5)) {
6006 bnx2x_8727_handle_mod_abs(phy, params);
6007 /* Enable all mod_abs and link detection bits */
6008 bnx2x_cl45_write(bp, phy,
6009 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_ALARM_CTRL,
6010 ((1<<5) | (1<<2)));
6011 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006012 DP(NETIF_MSG_LINK, "Enabling 8727 TX laser if SFP is approved\n");
6013 bnx2x_8727_specific_func(phy, params, ENABLE_TX);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006014 /* If transmitter is disabled, ignore false link up indication */
6015 bnx2x_cl45_read(bp, phy,
6016 MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER, &val1);
6017 if (val1 & (1<<15)) {
6018 DP(NETIF_MSG_LINK, "Tx is disabled\n");
6019 return 0;
6020 }
6021
6022 bnx2x_cl45_read(bp, phy,
6023 MDIO_PMA_DEVAD,
6024 MDIO_PMA_REG_8073_SPEED_LINK_STATUS, &link_status);
6025
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006026 /*
6027 * Bits 0..2 --> speed detected,
6028 * Bits 13..15--> link is down
6029 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006030 if ((link_status & (1<<2)) && (!(link_status & (1<<15)))) {
6031 link_up = 1;
6032 vars->line_speed = SPEED_10000;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006033 DP(NETIF_MSG_LINK, "port %x: External link up in 10G\n",
6034 params->port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006035 } else if ((link_status & (1<<0)) && (!(link_status & (1<<13)))) {
6036 link_up = 1;
6037 vars->line_speed = SPEED_1000;
6038 DP(NETIF_MSG_LINK, "port %x: External link up in 1G\n",
6039 params->port);
6040 } else {
6041 link_up = 0;
6042 DP(NETIF_MSG_LINK, "port %x: External link is down\n",
6043 params->port);
6044 }
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00006045
6046 /* Capture 10G link fault. */
6047 if (vars->line_speed == SPEED_10000) {
6048 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
6049 MDIO_PMA_REG_TX_ALARM, &val1);
6050
6051 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
6052 MDIO_PMA_REG_TX_ALARM, &val1);
6053
6054 if (val1 & (1<<0)) {
6055 vars->fault_detected = 1;
6056 }
6057 }
6058
Yaniv Rosner791f18c2011-01-18 04:33:42 +00006059 if (link_up) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006060 bnx2x_ext_phy_resolve_fc(phy, params, vars);
Yaniv Rosner791f18c2011-01-18 04:33:42 +00006061 vars->duplex = DUPLEX_FULL;
6062 DP(NETIF_MSG_LINK, "duplex = 0x%x\n", vars->duplex);
6063 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006064
6065 if ((DUAL_MEDIA(params)) &&
6066 (phy->req_line_speed == SPEED_1000)) {
6067 bnx2x_cl45_read(bp, phy,
6068 MDIO_PMA_DEVAD,
6069 MDIO_PMA_REG_8727_PCS_GP, &val1);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006070 /*
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006071 * In case of dual-media board and 1G, power up the XAUI side,
6072 * otherwise power it down. For 10G it is done automatically
6073 */
6074 if (link_up)
6075 val1 &= ~(3<<10);
6076 else
6077 val1 |= (3<<10);
6078 bnx2x_cl45_write(bp, phy,
6079 MDIO_PMA_DEVAD,
6080 MDIO_PMA_REG_8727_PCS_GP, val1);
6081 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006082 return link_up;
6083}
6084
6085static void bnx2x_8727_link_reset(struct bnx2x_phy *phy,
6086 struct link_params *params)
6087{
6088 struct bnx2x *bp = params->bp;
6089 /* Disable Transmitter */
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00006090 bnx2x_sfp_set_transmitter(params, phy, 0);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006091 /* Clear LASI */
6092 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_CTRL, 0);
6093
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006094}
6095
6096/******************************************************************/
6097/* BCM8481/BCM84823/BCM84833 PHY SECTION */
6098/******************************************************************/
6099static void bnx2x_save_848xx_spirom_version(struct bnx2x_phy *phy,
6100 struct link_params *params)
6101{
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00006102 u16 val, fw_ver1, fw_ver2, cnt, adj;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006103 struct bnx2x *bp = params->bp;
6104
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00006105 adj = 0;
6106 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
6107 adj = -1;
6108
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006109 /* For the 32 bits registers in 848xx, access via MDIO2ARM interface.*/
6110 /* (1) set register 0xc200_0014(SPI_BRIDGE_CTRL_2) to 0x03000000 */
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00006111 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA819 + adj, 0x0014);
6112 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA81A + adj, 0xc200);
6113 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA81B + adj, 0x0000);
6114 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA81C + adj, 0x0300);
6115 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA817 + adj, 0x0009);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006116
6117 for (cnt = 0; cnt < 100; cnt++) {
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00006118 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD, 0xA818 + adj, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006119 if (val & 1)
6120 break;
6121 udelay(5);
6122 }
6123 if (cnt == 100) {
6124 DP(NETIF_MSG_LINK, "Unable to read 848xx phy fw version(1)\n");
6125 bnx2x_save_spirom_version(bp, params->port, 0,
6126 phy->ver_addr);
6127 return;
6128 }
6129
6130
6131 /* 2) read register 0xc200_0000 (SPI_FW_STATUS) */
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00006132 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA819 + adj, 0x0000);
6133 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA81A + adj, 0xc200);
6134 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA817 + adj, 0x000A);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006135 for (cnt = 0; cnt < 100; cnt++) {
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00006136 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD, 0xA818 + adj, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006137 if (val & 1)
6138 break;
6139 udelay(5);
6140 }
6141 if (cnt == 100) {
6142 DP(NETIF_MSG_LINK, "Unable to read 848xx phy fw version(2)\n");
6143 bnx2x_save_spirom_version(bp, params->port, 0,
6144 phy->ver_addr);
6145 return;
6146 }
6147
6148 /* lower 16 bits of the register SPI_FW_STATUS */
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00006149 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD, 0xA81B + adj, &fw_ver1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006150 /* upper 16 bits of register SPI_FW_STATUS */
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00006151 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD, 0xA81C + adj, &fw_ver2);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006152
6153 bnx2x_save_spirom_version(bp, params->port, (fw_ver2<<16) | fw_ver1,
6154 phy->ver_addr);
6155}
6156
6157static void bnx2x_848xx_set_led(struct bnx2x *bp,
6158 struct bnx2x_phy *phy)
6159{
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00006160 u16 val, adj;
6161
6162 adj = 0;
6163 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
6164 adj = -1;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006165
6166 /* PHYC_CTL_LED_CTL */
6167 bnx2x_cl45_read(bp, phy,
6168 MDIO_PMA_DEVAD,
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00006169 MDIO_PMA_REG_8481_LINK_SIGNAL + adj, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006170 val &= 0xFE00;
6171 val |= 0x0092;
6172
6173 bnx2x_cl45_write(bp, phy,
6174 MDIO_PMA_DEVAD,
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00006175 MDIO_PMA_REG_8481_LINK_SIGNAL + adj, val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006176
6177 bnx2x_cl45_write(bp, phy,
6178 MDIO_PMA_DEVAD,
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00006179 MDIO_PMA_REG_8481_LED1_MASK + adj,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006180 0x80);
6181
6182 bnx2x_cl45_write(bp, phy,
6183 MDIO_PMA_DEVAD,
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00006184 MDIO_PMA_REG_8481_LED2_MASK + adj,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006185 0x18);
6186
Yaniv Rosnerf25b3c82011-01-18 04:33:47 +00006187 /* Select activity source by Tx and Rx, as suggested by PHY AE */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006188 bnx2x_cl45_write(bp, phy,
6189 MDIO_PMA_DEVAD,
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00006190 MDIO_PMA_REG_8481_LED3_MASK + adj,
Yaniv Rosnerf25b3c82011-01-18 04:33:47 +00006191 0x0006);
6192
6193 /* Select the closest activity blink rate to that in 10/100/1000 */
6194 bnx2x_cl45_write(bp, phy,
6195 MDIO_PMA_DEVAD,
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00006196 MDIO_PMA_REG_8481_LED3_BLINK + adj,
Yaniv Rosnerf25b3c82011-01-18 04:33:47 +00006197 0);
6198
6199 bnx2x_cl45_read(bp, phy,
6200 MDIO_PMA_DEVAD,
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00006201 MDIO_PMA_REG_84823_CTL_LED_CTL_1 + adj, &val);
Yaniv Rosnerf25b3c82011-01-18 04:33:47 +00006202 val |= MDIO_PMA_REG_84823_LED3_STRETCH_EN; /* stretch_en for LED3*/
6203
6204 bnx2x_cl45_write(bp, phy,
6205 MDIO_PMA_DEVAD,
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00006206 MDIO_PMA_REG_84823_CTL_LED_CTL_1 + adj, val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006207
6208 /* 'Interrupt Mask' */
6209 bnx2x_cl45_write(bp, phy,
6210 MDIO_AN_DEVAD,
6211 0xFFFB, 0xFFFD);
6212}
6213
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006214static int bnx2x_848xx_cmn_config_init(struct bnx2x_phy *phy,
6215 struct link_params *params,
6216 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006217{
6218 struct bnx2x *bp = params->bp;
6219 u16 autoneg_val, an_1000_val, an_10_100_val;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006220 /*
6221 * This phy uses the NIG latch mechanism since link indication
6222 * arrives through its LED4 and not via its LASI signal, so we
6223 * get steady signal instead of clear on read
6224 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006225 bnx2x_bits_en(bp, NIG_REG_LATCH_BC_0 + params->port*4,
6226 1 << NIG_LATCH_BC_ENABLE_MI_INT);
6227
6228 bnx2x_cl45_write(bp, phy,
6229 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x0000);
6230
6231 bnx2x_848xx_set_led(bp, phy);
6232
6233 /* set 1000 speed advertisement */
6234 bnx2x_cl45_read(bp, phy,
6235 MDIO_AN_DEVAD, MDIO_AN_REG_8481_1000T_CTRL,
6236 &an_1000_val);
6237
6238 bnx2x_ext_phy_set_pause(params, phy, vars);
6239 bnx2x_cl45_read(bp, phy,
6240 MDIO_AN_DEVAD,
6241 MDIO_AN_REG_8481_LEGACY_AN_ADV,
6242 &an_10_100_val);
6243 bnx2x_cl45_read(bp, phy,
6244 MDIO_AN_DEVAD, MDIO_AN_REG_8481_LEGACY_MII_CTRL,
6245 &autoneg_val);
6246 /* Disable forced speed */
6247 autoneg_val &= ~((1<<6) | (1<<8) | (1<<9) | (1<<12) | (1<<13));
6248 an_10_100_val &= ~((1<<5) | (1<<6) | (1<<7) | (1<<8));
6249
6250 if (((phy->req_line_speed == SPEED_AUTO_NEG) &&
6251 (phy->speed_cap_mask &
6252 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) ||
6253 (phy->req_line_speed == SPEED_1000)) {
6254 an_1000_val |= (1<<8);
6255 autoneg_val |= (1<<9 | 1<<12);
6256 if (phy->req_duplex == DUPLEX_FULL)
6257 an_1000_val |= (1<<9);
6258 DP(NETIF_MSG_LINK, "Advertising 1G\n");
6259 } else
6260 an_1000_val &= ~((1<<8) | (1<<9));
6261
6262 bnx2x_cl45_write(bp, phy,
6263 MDIO_AN_DEVAD, MDIO_AN_REG_8481_1000T_CTRL,
6264 an_1000_val);
6265
6266 /* set 10 speed advertisement */
6267 if (((phy->req_line_speed == SPEED_AUTO_NEG) &&
6268 (phy->speed_cap_mask &
6269 (PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL |
6270 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF)))) {
6271 an_10_100_val |= (1<<7);
6272 /* Enable autoneg and restart autoneg for legacy speeds */
6273 autoneg_val |= (1<<9 | 1<<12);
6274
6275 if (phy->req_duplex == DUPLEX_FULL)
6276 an_10_100_val |= (1<<8);
6277 DP(NETIF_MSG_LINK, "Advertising 100M\n");
6278 }
6279 /* set 10 speed advertisement */
6280 if (((phy->req_line_speed == SPEED_AUTO_NEG) &&
6281 (phy->speed_cap_mask &
6282 (PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL |
6283 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF)))) {
6284 an_10_100_val |= (1<<5);
6285 autoneg_val |= (1<<9 | 1<<12);
6286 if (phy->req_duplex == DUPLEX_FULL)
6287 an_10_100_val |= (1<<6);
6288 DP(NETIF_MSG_LINK, "Advertising 10M\n");
6289 }
6290
6291 /* Only 10/100 are allowed to work in FORCE mode */
6292 if (phy->req_line_speed == SPEED_100) {
6293 autoneg_val |= (1<<13);
6294 /* Enabled AUTO-MDIX when autoneg is disabled */
6295 bnx2x_cl45_write(bp, phy,
6296 MDIO_AN_DEVAD, MDIO_AN_REG_8481_AUX_CTRL,
6297 (1<<15 | 1<<9 | 7<<0));
6298 DP(NETIF_MSG_LINK, "Setting 100M force\n");
6299 }
6300 if (phy->req_line_speed == SPEED_10) {
6301 /* Enabled AUTO-MDIX when autoneg is disabled */
6302 bnx2x_cl45_write(bp, phy,
6303 MDIO_AN_DEVAD, MDIO_AN_REG_8481_AUX_CTRL,
6304 (1<<15 | 1<<9 | 7<<0));
6305 DP(NETIF_MSG_LINK, "Setting 10M force\n");
6306 }
6307
6308 bnx2x_cl45_write(bp, phy,
6309 MDIO_AN_DEVAD, MDIO_AN_REG_8481_LEGACY_AN_ADV,
6310 an_10_100_val);
6311
6312 if (phy->req_duplex == DUPLEX_FULL)
6313 autoneg_val |= (1<<8);
6314
6315 bnx2x_cl45_write(bp, phy,
6316 MDIO_AN_DEVAD,
6317 MDIO_AN_REG_8481_LEGACY_MII_CTRL, autoneg_val);
6318
6319 if (((phy->req_line_speed == SPEED_AUTO_NEG) &&
6320 (phy->speed_cap_mask &
6321 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) ||
6322 (phy->req_line_speed == SPEED_10000)) {
6323 DP(NETIF_MSG_LINK, "Advertising 10G\n");
6324 /* Restart autoneg for 10G*/
6325
6326 bnx2x_cl45_write(bp, phy,
6327 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL,
6328 0x3200);
6329 } else if (phy->req_line_speed != SPEED_10 &&
6330 phy->req_line_speed != SPEED_100) {
6331 bnx2x_cl45_write(bp, phy,
6332 MDIO_AN_DEVAD,
6333 MDIO_AN_REG_8481_10GBASE_T_AN_CTRL,
6334 1);
6335 }
6336 /* Save spirom version */
6337 bnx2x_save_848xx_spirom_version(phy, params);
6338
6339 return 0;
6340}
6341
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006342static int bnx2x_8481_config_init(struct bnx2x_phy *phy,
6343 struct link_params *params,
6344 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006345{
6346 struct bnx2x *bp = params->bp;
6347 /* Restore normal power mode*/
6348 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006349 MISC_REGISTERS_GPIO_OUTPUT_HIGH, params->port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006350
6351 /* HW reset */
6352 bnx2x_ext_phy_hw_reset(bp, params->port);
Yaniv Rosner6d870c32011-01-31 04:22:20 +00006353 bnx2x_wait_reset_complete(bp, phy, params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006354
6355 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 1<<15);
6356 return bnx2x_848xx_cmn_config_init(phy, params, vars);
6357}
6358
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006359static int bnx2x_848x3_config_init(struct bnx2x_phy *phy,
6360 struct link_params *params,
6361 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006362{
6363 struct bnx2x *bp = params->bp;
Yaniv Rosner6a71bbe2010-11-01 05:32:31 +00006364 u8 port, initialize = 1;
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00006365 u16 val, adj;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006366 u16 temp;
Yaniv Rosner1bef68e2011-01-31 04:22:46 +00006367 u32 actual_phy_selection, cms_enable;
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006368 int rc = 0;
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006369
6370 /* This is just for MDIO_CTL_REG_84823_MEDIA register. */
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00006371 adj = 0;
6372 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
6373 adj = 3;
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006374
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006375 msleep(1);
Yaniv Rosner6a71bbe2010-11-01 05:32:31 +00006376 if (CHIP_IS_E2(bp))
6377 port = BP_PATH(bp);
6378 else
6379 port = params->port;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006380 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_3,
6381 MISC_REGISTERS_GPIO_OUTPUT_HIGH,
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006382 port);
Yaniv Rosner6d870c32011-01-31 04:22:20 +00006383 bnx2x_wait_reset_complete(bp, phy, params);
Yaniv Rosner9bffeac2010-11-01 05:32:27 +00006384 /* Wait for GPHY to come out of reset */
6385 msleep(50);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006386 /*
6387 * BCM84823 requires that XGXS links up first @ 10G for normal behavior
6388 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006389 temp = vars->line_speed;
6390 vars->line_speed = SPEED_10000;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006391 bnx2x_set_autoneg(&params->phy[INT_PHY], params, vars, 0);
6392 bnx2x_program_serdes(&params->phy[INT_PHY], params, vars);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006393 vars->line_speed = temp;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006394
6395 /* Set dual-media configuration according to configuration */
6396
6397 bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD,
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00006398 MDIO_CTL_REG_84823_MEDIA + adj, &val);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006399 val &= ~(MDIO_CTL_REG_84823_MEDIA_MAC_MASK |
6400 MDIO_CTL_REG_84823_MEDIA_LINE_MASK |
6401 MDIO_CTL_REG_84823_MEDIA_COPPER_CORE_DOWN |
6402 MDIO_CTL_REG_84823_MEDIA_PRIORITY_MASK |
6403 MDIO_CTL_REG_84823_MEDIA_FIBER_1G);
6404 val |= MDIO_CTL_REG_84823_CTRL_MAC_XFI |
6405 MDIO_CTL_REG_84823_MEDIA_LINE_XAUI_L;
6406
6407 actual_phy_selection = bnx2x_phy_selection(params);
6408
6409 switch (actual_phy_selection) {
6410 case PORT_HW_CFG_PHY_SELECTION_HARDWARE_DEFAULT:
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006411 /* Do nothing. Essentially this is like the priority copper */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006412 break;
6413 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY_PRIORITY:
6414 val |= MDIO_CTL_REG_84823_MEDIA_PRIORITY_COPPER;
6415 break;
6416 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY_PRIORITY:
6417 val |= MDIO_CTL_REG_84823_MEDIA_PRIORITY_FIBER;
6418 break;
6419 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY:
6420 /* Do nothing here. The first PHY won't be initialized at all */
6421 break;
6422 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY:
6423 val |= MDIO_CTL_REG_84823_MEDIA_COPPER_CORE_DOWN;
6424 initialize = 0;
6425 break;
6426 }
6427 if (params->phy[EXT_PHY2].req_line_speed == SPEED_1000)
6428 val |= MDIO_CTL_REG_84823_MEDIA_FIBER_1G;
6429
6430 bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00006431 MDIO_CTL_REG_84823_MEDIA + adj, val);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006432 DP(NETIF_MSG_LINK, "Multi_phy config = 0x%x, Media control = 0x%x\n",
6433 params->multi_phy_config, val);
6434
6435 if (initialize)
6436 rc = bnx2x_848xx_cmn_config_init(phy, params, vars);
6437 else
6438 bnx2x_save_848xx_spirom_version(phy, params);
Yaniv Rosner1bef68e2011-01-31 04:22:46 +00006439 cms_enable = REG_RD(bp, params->shmem_base +
6440 offsetof(struct shmem_region,
6441 dev_info.port_hw_config[params->port].default_cfg)) &
6442 PORT_HW_CFG_ENABLE_CMS_MASK;
6443
6444 bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD,
6445 MDIO_CTL_REG_84823_USER_CTRL_REG, &val);
6446 if (cms_enable)
6447 val |= MDIO_CTL_REG_84823_USER_CTRL_CMS;
6448 else
6449 val &= ~MDIO_CTL_REG_84823_USER_CTRL_CMS;
6450 bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
6451 MDIO_CTL_REG_84823_USER_CTRL_REG, val);
6452
6453
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006454 return rc;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006455}
6456
6457static u8 bnx2x_848xx_read_status(struct bnx2x_phy *phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006458 struct link_params *params,
6459 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006460{
6461 struct bnx2x *bp = params->bp;
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00006462 u16 val, val1, val2, adj;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006463 u8 link_up = 0;
6464
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00006465 /* Reg offset adjustment for 84833 */
6466 adj = 0;
6467 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
6468 adj = -1;
6469
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006470 /* Check 10G-BaseT link status */
6471 /* Check PMD signal ok */
6472 bnx2x_cl45_read(bp, phy,
6473 MDIO_AN_DEVAD, 0xFFFA, &val1);
6474 bnx2x_cl45_read(bp, phy,
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00006475 MDIO_PMA_DEVAD, MDIO_PMA_REG_8481_PMD_SIGNAL + adj,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006476 &val2);
6477 DP(NETIF_MSG_LINK, "BCM848xx: PMD_SIGNAL 1.a811 = 0x%x\n", val2);
6478
6479 /* Check link 10G */
6480 if (val2 & (1<<11)) {
6481 vars->line_speed = SPEED_10000;
Yaniv Rosner791f18c2011-01-18 04:33:42 +00006482 vars->duplex = DUPLEX_FULL;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006483 link_up = 1;
6484 bnx2x_ext_phy_10G_an_resolve(bp, phy, vars);
6485 } else { /* Check Legacy speed link */
6486 u16 legacy_status, legacy_speed;
6487
6488 /* Enable expansion register 0x42 (Operation mode status) */
6489 bnx2x_cl45_write(bp, phy,
6490 MDIO_AN_DEVAD,
6491 MDIO_AN_REG_8481_EXPANSION_REG_ACCESS, 0xf42);
6492
6493 /* Get legacy speed operation status */
6494 bnx2x_cl45_read(bp, phy,
6495 MDIO_AN_DEVAD,
6496 MDIO_AN_REG_8481_EXPANSION_REG_RD_RW,
6497 &legacy_status);
6498
6499 DP(NETIF_MSG_LINK, "Legacy speed status"
6500 " = 0x%x\n", legacy_status);
6501 link_up = ((legacy_status & (1<<11)) == (1<<11));
6502 if (link_up) {
6503 legacy_speed = (legacy_status & (3<<9));
6504 if (legacy_speed == (0<<9))
6505 vars->line_speed = SPEED_10;
6506 else if (legacy_speed == (1<<9))
6507 vars->line_speed = SPEED_100;
6508 else if (legacy_speed == (2<<9))
6509 vars->line_speed = SPEED_1000;
6510 else /* Should not happen */
6511 vars->line_speed = 0;
6512
6513 if (legacy_status & (1<<8))
6514 vars->duplex = DUPLEX_FULL;
6515 else
6516 vars->duplex = DUPLEX_HALF;
6517
6518 DP(NETIF_MSG_LINK, "Link is up in %dMbps,"
6519 " is_duplex_full= %d\n", vars->line_speed,
6520 (vars->duplex == DUPLEX_FULL));
6521 /* Check legacy speed AN resolution */
6522 bnx2x_cl45_read(bp, phy,
6523 MDIO_AN_DEVAD,
6524 MDIO_AN_REG_8481_LEGACY_MII_STATUS,
6525 &val);
6526 if (val & (1<<5))
6527 vars->link_status |=
6528 LINK_STATUS_AUTO_NEGOTIATE_COMPLETE;
6529 bnx2x_cl45_read(bp, phy,
6530 MDIO_AN_DEVAD,
6531 MDIO_AN_REG_8481_LEGACY_AN_EXPANSION,
6532 &val);
6533 if ((val & (1<<0)) == 0)
6534 vars->link_status |=
6535 LINK_STATUS_PARALLEL_DETECTION_USED;
6536 }
6537 }
6538 if (link_up) {
6539 DP(NETIF_MSG_LINK, "BCM84823: link speed is %d\n",
6540 vars->line_speed);
6541 bnx2x_ext_phy_resolve_fc(phy, params, vars);
6542 }
6543
6544 return link_up;
6545}
6546
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006547
6548static int bnx2x_848xx_format_ver(u32 raw_ver, u8 *str, u16 *len)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006549{
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006550 int status = 0;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006551 u32 spirom_ver;
6552 spirom_ver = ((raw_ver & 0xF80) >> 7) << 16 | (raw_ver & 0x7F);
6553 status = bnx2x_format_ver(spirom_ver, str, len);
6554 return status;
6555}
6556
6557static void bnx2x_8481_hw_reset(struct bnx2x_phy *phy,
6558 struct link_params *params)
6559{
6560 bnx2x_set_gpio(params->bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006561 MISC_REGISTERS_GPIO_OUTPUT_LOW, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006562 bnx2x_set_gpio(params->bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006563 MISC_REGISTERS_GPIO_OUTPUT_LOW, 1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006564}
6565
6566static void bnx2x_8481_link_reset(struct bnx2x_phy *phy,
6567 struct link_params *params)
6568{
6569 bnx2x_cl45_write(params->bp, phy,
6570 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x0000);
6571 bnx2x_cl45_write(params->bp, phy,
6572 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 1);
6573}
6574
6575static void bnx2x_848x3_link_reset(struct bnx2x_phy *phy,
6576 struct link_params *params)
6577{
6578 struct bnx2x *bp = params->bp;
Yaniv Rosner6a71bbe2010-11-01 05:32:31 +00006579 u8 port;
6580 if (CHIP_IS_E2(bp))
6581 port = BP_PATH(bp);
6582 else
6583 port = params->port;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006584 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_3,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006585 MISC_REGISTERS_GPIO_OUTPUT_LOW,
6586 port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006587}
6588
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006589static void bnx2x_848xx_set_link_led(struct bnx2x_phy *phy,
6590 struct link_params *params, u8 mode)
6591{
6592 struct bnx2x *bp = params->bp;
6593 u16 val;
6594
6595 switch (mode) {
6596 case LED_MODE_OFF:
6597
6598 DP(NETIF_MSG_LINK, "Port 0x%x: LED MODE OFF\n", params->port);
6599
6600 if ((params->hw_led_mode << SHARED_HW_CFG_LED_MODE_SHIFT) ==
6601 SHARED_HW_CFG_LED_EXTPHY1) {
6602
6603 /* Set LED masks */
6604 bnx2x_cl45_write(bp, phy,
6605 MDIO_PMA_DEVAD,
6606 MDIO_PMA_REG_8481_LED1_MASK,
6607 0x0);
6608
6609 bnx2x_cl45_write(bp, phy,
6610 MDIO_PMA_DEVAD,
6611 MDIO_PMA_REG_8481_LED2_MASK,
6612 0x0);
6613
6614 bnx2x_cl45_write(bp, phy,
6615 MDIO_PMA_DEVAD,
6616 MDIO_PMA_REG_8481_LED3_MASK,
6617 0x0);
6618
6619 bnx2x_cl45_write(bp, phy,
6620 MDIO_PMA_DEVAD,
6621 MDIO_PMA_REG_8481_LED5_MASK,
6622 0x0);
6623
6624 } else {
6625 bnx2x_cl45_write(bp, phy,
6626 MDIO_PMA_DEVAD,
6627 MDIO_PMA_REG_8481_LED1_MASK,
6628 0x0);
6629 }
6630 break;
6631 case LED_MODE_FRONT_PANEL_OFF:
6632
6633 DP(NETIF_MSG_LINK, "Port 0x%x: LED MODE FRONT PANEL OFF\n",
6634 params->port);
6635
6636 if ((params->hw_led_mode << SHARED_HW_CFG_LED_MODE_SHIFT) ==
6637 SHARED_HW_CFG_LED_EXTPHY1) {
6638
6639 /* Set LED masks */
6640 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006641 MDIO_PMA_DEVAD,
6642 MDIO_PMA_REG_8481_LED1_MASK,
6643 0x0);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006644
6645 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006646 MDIO_PMA_DEVAD,
6647 MDIO_PMA_REG_8481_LED2_MASK,
6648 0x0);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006649
6650 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006651 MDIO_PMA_DEVAD,
6652 MDIO_PMA_REG_8481_LED3_MASK,
6653 0x0);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006654
6655 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006656 MDIO_PMA_DEVAD,
6657 MDIO_PMA_REG_8481_LED5_MASK,
6658 0x20);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006659
6660 } else {
6661 bnx2x_cl45_write(bp, phy,
6662 MDIO_PMA_DEVAD,
6663 MDIO_PMA_REG_8481_LED1_MASK,
6664 0x0);
6665 }
6666 break;
6667 case LED_MODE_ON:
6668
6669 DP(NETIF_MSG_LINK, "Port 0x%x: LED MODE ON\n", params->port);
6670
6671 if ((params->hw_led_mode << SHARED_HW_CFG_LED_MODE_SHIFT) ==
6672 SHARED_HW_CFG_LED_EXTPHY1) {
6673 /* Set control reg */
6674 bnx2x_cl45_read(bp, phy,
6675 MDIO_PMA_DEVAD,
6676 MDIO_PMA_REG_8481_LINK_SIGNAL,
6677 &val);
6678 val &= 0x8000;
6679 val |= 0x2492;
6680
6681 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006682 MDIO_PMA_DEVAD,
6683 MDIO_PMA_REG_8481_LINK_SIGNAL,
6684 val);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006685
6686 /* Set LED masks */
6687 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006688 MDIO_PMA_DEVAD,
6689 MDIO_PMA_REG_8481_LED1_MASK,
6690 0x0);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006691
6692 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006693 MDIO_PMA_DEVAD,
6694 MDIO_PMA_REG_8481_LED2_MASK,
6695 0x20);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006696
6697 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006698 MDIO_PMA_DEVAD,
6699 MDIO_PMA_REG_8481_LED3_MASK,
6700 0x20);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006701
6702 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006703 MDIO_PMA_DEVAD,
6704 MDIO_PMA_REG_8481_LED5_MASK,
6705 0x0);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006706 } else {
6707 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006708 MDIO_PMA_DEVAD,
6709 MDIO_PMA_REG_8481_LED1_MASK,
6710 0x20);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006711 }
6712 break;
6713
6714 case LED_MODE_OPER:
6715
6716 DP(NETIF_MSG_LINK, "Port 0x%x: LED MODE OPER\n", params->port);
6717
6718 if ((params->hw_led_mode << SHARED_HW_CFG_LED_MODE_SHIFT) ==
6719 SHARED_HW_CFG_LED_EXTPHY1) {
6720
6721 /* Set control reg */
6722 bnx2x_cl45_read(bp, phy,
6723 MDIO_PMA_DEVAD,
6724 MDIO_PMA_REG_8481_LINK_SIGNAL,
6725 &val);
6726
6727 if (!((val &
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006728 MDIO_PMA_REG_8481_LINK_SIGNAL_LED4_ENABLE_MASK)
6729 >> MDIO_PMA_REG_8481_LINK_SIGNAL_LED4_ENABLE_SHIFT)) {
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006730 DP(NETIF_MSG_LINK, "Setting LINK_SIGNAL\n");
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006731 bnx2x_cl45_write(bp, phy,
6732 MDIO_PMA_DEVAD,
6733 MDIO_PMA_REG_8481_LINK_SIGNAL,
6734 0xa492);
6735 }
6736
6737 /* Set LED masks */
6738 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006739 MDIO_PMA_DEVAD,
6740 MDIO_PMA_REG_8481_LED1_MASK,
6741 0x10);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006742
6743 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006744 MDIO_PMA_DEVAD,
6745 MDIO_PMA_REG_8481_LED2_MASK,
6746 0x80);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006747
6748 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006749 MDIO_PMA_DEVAD,
6750 MDIO_PMA_REG_8481_LED3_MASK,
6751 0x98);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006752
6753 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006754 MDIO_PMA_DEVAD,
6755 MDIO_PMA_REG_8481_LED5_MASK,
6756 0x40);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006757
6758 } else {
6759 bnx2x_cl45_write(bp, phy,
6760 MDIO_PMA_DEVAD,
6761 MDIO_PMA_REG_8481_LED1_MASK,
6762 0x80);
Yaniv Rosner53eda062011-01-30 04:14:55 +00006763
6764 /* Tell LED3 to blink on source */
6765 bnx2x_cl45_read(bp, phy,
6766 MDIO_PMA_DEVAD,
6767 MDIO_PMA_REG_8481_LINK_SIGNAL,
6768 &val);
6769 val &= ~(7<<6);
6770 val |= (1<<6); /* A83B[8:6]= 1 */
6771 bnx2x_cl45_write(bp, phy,
6772 MDIO_PMA_DEVAD,
6773 MDIO_PMA_REG_8481_LINK_SIGNAL,
6774 val);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006775 }
6776 break;
6777 }
6778}
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006779/******************************************************************/
6780/* SFX7101 PHY SECTION */
6781/******************************************************************/
6782static void bnx2x_7101_config_loopback(struct bnx2x_phy *phy,
6783 struct link_params *params)
6784{
6785 struct bnx2x *bp = params->bp;
6786 /* SFX7101_XGXS_TEST1 */
6787 bnx2x_cl45_write(bp, phy,
6788 MDIO_XS_DEVAD, MDIO_XS_SFX7101_XGXS_TEST1, 0x100);
6789}
6790
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006791static int bnx2x_7101_config_init(struct bnx2x_phy *phy,
6792 struct link_params *params,
6793 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006794{
6795 u16 fw_ver1, fw_ver2, val;
6796 struct bnx2x *bp = params->bp;
6797 DP(NETIF_MSG_LINK, "Setting the SFX7101 LASI indication\n");
6798
6799 /* Restore normal power mode*/
6800 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006801 MISC_REGISTERS_GPIO_OUTPUT_HIGH, params->port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006802 /* HW reset */
6803 bnx2x_ext_phy_hw_reset(bp, params->port);
Yaniv Rosner6d870c32011-01-31 04:22:20 +00006804 bnx2x_wait_reset_complete(bp, phy, params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006805
6806 bnx2x_cl45_write(bp, phy,
6807 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_CTRL, 0x1);
6808 DP(NETIF_MSG_LINK, "Setting the SFX7101 LED to blink on traffic\n");
6809 bnx2x_cl45_write(bp, phy,
6810 MDIO_PMA_DEVAD, MDIO_PMA_REG_7107_LED_CNTL, (1<<3));
6811
6812 bnx2x_ext_phy_set_pause(params, phy, vars);
6813 /* Restart autoneg */
6814 bnx2x_cl45_read(bp, phy,
6815 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, &val);
6816 val |= 0x200;
6817 bnx2x_cl45_write(bp, phy,
6818 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, val);
6819
6820 /* Save spirom version */
6821 bnx2x_cl45_read(bp, phy,
6822 MDIO_PMA_DEVAD, MDIO_PMA_REG_7101_VER1, &fw_ver1);
6823
6824 bnx2x_cl45_read(bp, phy,
6825 MDIO_PMA_DEVAD, MDIO_PMA_REG_7101_VER2, &fw_ver2);
6826 bnx2x_save_spirom_version(bp, params->port,
6827 (u32)(fw_ver1<<16 | fw_ver2), phy->ver_addr);
6828 return 0;
6829}
6830
6831static u8 bnx2x_7101_read_status(struct bnx2x_phy *phy,
6832 struct link_params *params,
6833 struct link_vars *vars)
6834{
6835 struct bnx2x *bp = params->bp;
6836 u8 link_up;
6837 u16 val1, val2;
6838 bnx2x_cl45_read(bp, phy,
6839 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_STATUS, &val2);
6840 bnx2x_cl45_read(bp, phy,
6841 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_STATUS, &val1);
6842 DP(NETIF_MSG_LINK, "10G-base-T LASI status 0x%x->0x%x\n",
6843 val2, val1);
6844 bnx2x_cl45_read(bp, phy,
6845 MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val2);
6846 bnx2x_cl45_read(bp, phy,
6847 MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val1);
6848 DP(NETIF_MSG_LINK, "10G-base-T PMA status 0x%x->0x%x\n",
6849 val2, val1);
6850 link_up = ((val1 & 4) == 4);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006851 /* if link is up print the AN outcome of the SFX7101 PHY */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006852 if (link_up) {
6853 bnx2x_cl45_read(bp, phy,
6854 MDIO_AN_DEVAD, MDIO_AN_REG_MASTER_STATUS,
6855 &val2);
6856 vars->line_speed = SPEED_10000;
Yaniv Rosner791f18c2011-01-18 04:33:42 +00006857 vars->duplex = DUPLEX_FULL;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006858 DP(NETIF_MSG_LINK, "SFX7101 AN status 0x%x->Master=%x\n",
6859 val2, (val2 & (1<<14)));
6860 bnx2x_ext_phy_10G_an_resolve(bp, phy, vars);
6861 bnx2x_ext_phy_resolve_fc(phy, params, vars);
6862 }
6863 return link_up;
6864}
6865
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006866static int bnx2x_7101_format_ver(u32 spirom_ver, u8 *str, u16 *len)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006867{
6868 if (*len < 5)
6869 return -EINVAL;
6870 str[0] = (spirom_ver & 0xFF);
6871 str[1] = (spirom_ver & 0xFF00) >> 8;
6872 str[2] = (spirom_ver & 0xFF0000) >> 16;
6873 str[3] = (spirom_ver & 0xFF000000) >> 24;
6874 str[4] = '\0';
6875 *len -= 5;
6876 return 0;
6877}
6878
6879void bnx2x_sfx7101_sp_sw_reset(struct bnx2x *bp, struct bnx2x_phy *phy)
6880{
6881 u16 val, cnt;
6882
6883 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006884 MDIO_PMA_DEVAD,
6885 MDIO_PMA_REG_7101_RESET, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006886
6887 for (cnt = 0; cnt < 10; cnt++) {
6888 msleep(50);
6889 /* Writes a self-clearing reset */
6890 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006891 MDIO_PMA_DEVAD,
6892 MDIO_PMA_REG_7101_RESET,
6893 (val | (1<<15)));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006894 /* Wait for clear */
6895 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006896 MDIO_PMA_DEVAD,
6897 MDIO_PMA_REG_7101_RESET, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006898
6899 if ((val & (1<<15)) == 0)
6900 break;
6901 }
6902}
6903
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006904static void bnx2x_7101_hw_reset(struct bnx2x_phy *phy,
6905 struct link_params *params) {
6906 /* Low power mode is controlled by GPIO 2 */
6907 bnx2x_set_gpio(params->bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006908 MISC_REGISTERS_GPIO_OUTPUT_LOW, params->port);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006909 /* The PHY reset is controlled by GPIO 1 */
6910 bnx2x_set_gpio(params->bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006911 MISC_REGISTERS_GPIO_OUTPUT_LOW, params->port);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006912}
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006913
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006914static void bnx2x_7101_set_link_led(struct bnx2x_phy *phy,
6915 struct link_params *params, u8 mode)
6916{
6917 u16 val = 0;
6918 struct bnx2x *bp = params->bp;
6919 switch (mode) {
6920 case LED_MODE_FRONT_PANEL_OFF:
6921 case LED_MODE_OFF:
6922 val = 2;
6923 break;
6924 case LED_MODE_ON:
6925 val = 1;
6926 break;
6927 case LED_MODE_OPER:
6928 val = 0;
6929 break;
6930 }
6931 bnx2x_cl45_write(bp, phy,
6932 MDIO_PMA_DEVAD,
6933 MDIO_PMA_REG_7107_LINK_LED_CNTL,
6934 val);
6935}
6936
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006937/******************************************************************/
6938/* STATIC PHY DECLARATION */
6939/******************************************************************/
6940
6941static struct bnx2x_phy phy_null = {
6942 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN,
6943 .addr = 0,
6944 .flags = FLAGS_INIT_XGXS_FIRST,
6945 .def_md_devad = 0,
6946 .reserved = 0,
6947 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
6948 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
6949 .mdio_ctrl = 0,
6950 .supported = 0,
6951 .media_type = ETH_PHY_NOT_PRESENT,
6952 .ver_addr = 0,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006953 .req_flow_ctrl = 0,
6954 .req_line_speed = 0,
6955 .speed_cap_mask = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006956 .req_duplex = 0,
6957 .rsrv = 0,
6958 .config_init = (config_init_t)NULL,
6959 .read_status = (read_status_t)NULL,
6960 .link_reset = (link_reset_t)NULL,
6961 .config_loopback = (config_loopback_t)NULL,
6962 .format_fw_ver = (format_fw_ver_t)NULL,
6963 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006964 .set_link_led = (set_link_led_t)NULL,
6965 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006966};
6967
6968static struct bnx2x_phy phy_serdes = {
6969 .type = PORT_HW_CFG_SERDES_EXT_PHY_TYPE_DIRECT,
6970 .addr = 0xff,
6971 .flags = 0,
6972 .def_md_devad = 0,
6973 .reserved = 0,
6974 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
6975 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
6976 .mdio_ctrl = 0,
6977 .supported = (SUPPORTED_10baseT_Half |
6978 SUPPORTED_10baseT_Full |
6979 SUPPORTED_100baseT_Half |
6980 SUPPORTED_100baseT_Full |
6981 SUPPORTED_1000baseT_Full |
6982 SUPPORTED_2500baseX_Full |
6983 SUPPORTED_TP |
6984 SUPPORTED_Autoneg |
6985 SUPPORTED_Pause |
6986 SUPPORTED_Asym_Pause),
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00006987 .media_type = ETH_PHY_BASE_T,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006988 .ver_addr = 0,
6989 .req_flow_ctrl = 0,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006990 .req_line_speed = 0,
6991 .speed_cap_mask = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006992 .req_duplex = 0,
6993 .rsrv = 0,
6994 .config_init = (config_init_t)bnx2x_init_serdes,
6995 .read_status = (read_status_t)bnx2x_link_settings_status,
6996 .link_reset = (link_reset_t)bnx2x_int_link_reset,
6997 .config_loopback = (config_loopback_t)NULL,
6998 .format_fw_ver = (format_fw_ver_t)NULL,
6999 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007000 .set_link_led = (set_link_led_t)NULL,
7001 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007002};
7003
7004static struct bnx2x_phy phy_xgxs = {
7005 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT,
7006 .addr = 0xff,
7007 .flags = 0,
7008 .def_md_devad = 0,
7009 .reserved = 0,
7010 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
7011 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
7012 .mdio_ctrl = 0,
7013 .supported = (SUPPORTED_10baseT_Half |
7014 SUPPORTED_10baseT_Full |
7015 SUPPORTED_100baseT_Half |
7016 SUPPORTED_100baseT_Full |
7017 SUPPORTED_1000baseT_Full |
7018 SUPPORTED_2500baseX_Full |
7019 SUPPORTED_10000baseT_Full |
7020 SUPPORTED_FIBRE |
7021 SUPPORTED_Autoneg |
7022 SUPPORTED_Pause |
7023 SUPPORTED_Asym_Pause),
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00007024 .media_type = ETH_PHY_CX4,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007025 .ver_addr = 0,
7026 .req_flow_ctrl = 0,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007027 .req_line_speed = 0,
7028 .speed_cap_mask = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007029 .req_duplex = 0,
7030 .rsrv = 0,
7031 .config_init = (config_init_t)bnx2x_init_xgxs,
7032 .read_status = (read_status_t)bnx2x_link_settings_status,
7033 .link_reset = (link_reset_t)bnx2x_int_link_reset,
7034 .config_loopback = (config_loopback_t)bnx2x_set_xgxs_loopback,
7035 .format_fw_ver = (format_fw_ver_t)NULL,
7036 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007037 .set_link_led = (set_link_led_t)NULL,
7038 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007039};
7040
7041static struct bnx2x_phy phy_7101 = {
7042 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101,
7043 .addr = 0xff,
7044 .flags = FLAGS_FAN_FAILURE_DET_REQ,
7045 .def_md_devad = 0,
7046 .reserved = 0,
7047 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
7048 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
7049 .mdio_ctrl = 0,
7050 .supported = (SUPPORTED_10000baseT_Full |
7051 SUPPORTED_TP |
7052 SUPPORTED_Autoneg |
7053 SUPPORTED_Pause |
7054 SUPPORTED_Asym_Pause),
7055 .media_type = ETH_PHY_BASE_T,
7056 .ver_addr = 0,
7057 .req_flow_ctrl = 0,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007058 .req_line_speed = 0,
7059 .speed_cap_mask = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007060 .req_duplex = 0,
7061 .rsrv = 0,
7062 .config_init = (config_init_t)bnx2x_7101_config_init,
7063 .read_status = (read_status_t)bnx2x_7101_read_status,
7064 .link_reset = (link_reset_t)bnx2x_common_ext_link_reset,
7065 .config_loopback = (config_loopback_t)bnx2x_7101_config_loopback,
7066 .format_fw_ver = (format_fw_ver_t)bnx2x_7101_format_ver,
7067 .hw_reset = (hw_reset_t)bnx2x_7101_hw_reset,
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00007068 .set_link_led = (set_link_led_t)bnx2x_7101_set_link_led,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007069 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007070};
7071static struct bnx2x_phy phy_8073 = {
7072 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073,
7073 .addr = 0xff,
7074 .flags = FLAGS_HW_LOCK_REQUIRED,
7075 .def_md_devad = 0,
7076 .reserved = 0,
7077 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
7078 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
7079 .mdio_ctrl = 0,
7080 .supported = (SUPPORTED_10000baseT_Full |
7081 SUPPORTED_2500baseX_Full |
7082 SUPPORTED_1000baseT_Full |
7083 SUPPORTED_FIBRE |
7084 SUPPORTED_Autoneg |
7085 SUPPORTED_Pause |
7086 SUPPORTED_Asym_Pause),
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00007087 .media_type = ETH_PHY_KR,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007088 .ver_addr = 0,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007089 .req_flow_ctrl = 0,
7090 .req_line_speed = 0,
7091 .speed_cap_mask = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007092 .req_duplex = 0,
7093 .rsrv = 0,
Yaniv Rosner62b29a52010-09-07 11:40:58 +00007094 .config_init = (config_init_t)bnx2x_8073_config_init,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007095 .read_status = (read_status_t)bnx2x_8073_read_status,
7096 .link_reset = (link_reset_t)bnx2x_8073_link_reset,
7097 .config_loopback = (config_loopback_t)NULL,
7098 .format_fw_ver = (format_fw_ver_t)bnx2x_format_ver,
7099 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007100 .set_link_led = (set_link_led_t)NULL,
7101 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007102};
7103static struct bnx2x_phy phy_8705 = {
7104 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705,
7105 .addr = 0xff,
7106 .flags = FLAGS_INIT_XGXS_FIRST,
7107 .def_md_devad = 0,
7108 .reserved = 0,
7109 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
7110 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
7111 .mdio_ctrl = 0,
7112 .supported = (SUPPORTED_10000baseT_Full |
7113 SUPPORTED_FIBRE |
7114 SUPPORTED_Pause |
7115 SUPPORTED_Asym_Pause),
7116 .media_type = ETH_PHY_XFP_FIBER,
7117 .ver_addr = 0,
7118 .req_flow_ctrl = 0,
7119 .req_line_speed = 0,
7120 .speed_cap_mask = 0,
7121 .req_duplex = 0,
7122 .rsrv = 0,
7123 .config_init = (config_init_t)bnx2x_8705_config_init,
7124 .read_status = (read_status_t)bnx2x_8705_read_status,
7125 .link_reset = (link_reset_t)bnx2x_common_ext_link_reset,
7126 .config_loopback = (config_loopback_t)NULL,
7127 .format_fw_ver = (format_fw_ver_t)bnx2x_null_format_ver,
7128 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007129 .set_link_led = (set_link_led_t)NULL,
7130 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007131};
7132static struct bnx2x_phy phy_8706 = {
7133 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706,
7134 .addr = 0xff,
7135 .flags = FLAGS_INIT_XGXS_FIRST,
7136 .def_md_devad = 0,
7137 .reserved = 0,
7138 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
7139 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
7140 .mdio_ctrl = 0,
7141 .supported = (SUPPORTED_10000baseT_Full |
7142 SUPPORTED_1000baseT_Full |
7143 SUPPORTED_FIBRE |
7144 SUPPORTED_Pause |
7145 SUPPORTED_Asym_Pause),
7146 .media_type = ETH_PHY_SFP_FIBER,
7147 .ver_addr = 0,
7148 .req_flow_ctrl = 0,
7149 .req_line_speed = 0,
7150 .speed_cap_mask = 0,
7151 .req_duplex = 0,
7152 .rsrv = 0,
7153 .config_init = (config_init_t)bnx2x_8706_config_init,
7154 .read_status = (read_status_t)bnx2x_8706_read_status,
7155 .link_reset = (link_reset_t)bnx2x_common_ext_link_reset,
7156 .config_loopback = (config_loopback_t)NULL,
7157 .format_fw_ver = (format_fw_ver_t)bnx2x_format_ver,
7158 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007159 .set_link_led = (set_link_led_t)NULL,
7160 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007161};
7162
7163static struct bnx2x_phy phy_8726 = {
7164 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726,
7165 .addr = 0xff,
7166 .flags = (FLAGS_HW_LOCK_REQUIRED |
7167 FLAGS_INIT_XGXS_FIRST),
7168 .def_md_devad = 0,
7169 .reserved = 0,
7170 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
7171 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
7172 .mdio_ctrl = 0,
7173 .supported = (SUPPORTED_10000baseT_Full |
7174 SUPPORTED_1000baseT_Full |
7175 SUPPORTED_Autoneg |
7176 SUPPORTED_FIBRE |
7177 SUPPORTED_Pause |
7178 SUPPORTED_Asym_Pause),
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00007179 .media_type = ETH_PHY_NOT_PRESENT,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007180 .ver_addr = 0,
7181 .req_flow_ctrl = 0,
7182 .req_line_speed = 0,
7183 .speed_cap_mask = 0,
7184 .req_duplex = 0,
7185 .rsrv = 0,
7186 .config_init = (config_init_t)bnx2x_8726_config_init,
7187 .read_status = (read_status_t)bnx2x_8726_read_status,
7188 .link_reset = (link_reset_t)bnx2x_8726_link_reset,
7189 .config_loopback = (config_loopback_t)bnx2x_8726_config_loopback,
7190 .format_fw_ver = (format_fw_ver_t)bnx2x_format_ver,
7191 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007192 .set_link_led = (set_link_led_t)NULL,
7193 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007194};
7195
7196static struct bnx2x_phy phy_8727 = {
7197 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727,
7198 .addr = 0xff,
7199 .flags = FLAGS_FAN_FAILURE_DET_REQ,
7200 .def_md_devad = 0,
7201 .reserved = 0,
7202 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
7203 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
7204 .mdio_ctrl = 0,
7205 .supported = (SUPPORTED_10000baseT_Full |
7206 SUPPORTED_1000baseT_Full |
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007207 SUPPORTED_FIBRE |
7208 SUPPORTED_Pause |
7209 SUPPORTED_Asym_Pause),
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00007210 .media_type = ETH_PHY_NOT_PRESENT,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007211 .ver_addr = 0,
7212 .req_flow_ctrl = 0,
7213 .req_line_speed = 0,
7214 .speed_cap_mask = 0,
7215 .req_duplex = 0,
7216 .rsrv = 0,
7217 .config_init = (config_init_t)bnx2x_8727_config_init,
7218 .read_status = (read_status_t)bnx2x_8727_read_status,
7219 .link_reset = (link_reset_t)bnx2x_8727_link_reset,
7220 .config_loopback = (config_loopback_t)NULL,
7221 .format_fw_ver = (format_fw_ver_t)bnx2x_format_ver,
7222 .hw_reset = (hw_reset_t)bnx2x_8727_hw_reset,
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00007223 .set_link_led = (set_link_led_t)bnx2x_8727_set_link_led,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007224 .phy_specific_func = (phy_specific_func_t)bnx2x_8727_specific_func
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007225};
7226static struct bnx2x_phy phy_8481 = {
7227 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8481,
7228 .addr = 0xff,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007229 .flags = FLAGS_FAN_FAILURE_DET_REQ |
7230 FLAGS_REARM_LATCH_SIGNAL,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007231 .def_md_devad = 0,
7232 .reserved = 0,
7233 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
7234 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
7235 .mdio_ctrl = 0,
7236 .supported = (SUPPORTED_10baseT_Half |
7237 SUPPORTED_10baseT_Full |
7238 SUPPORTED_100baseT_Half |
7239 SUPPORTED_100baseT_Full |
7240 SUPPORTED_1000baseT_Full |
7241 SUPPORTED_10000baseT_Full |
7242 SUPPORTED_TP |
7243 SUPPORTED_Autoneg |
7244 SUPPORTED_Pause |
7245 SUPPORTED_Asym_Pause),
7246 .media_type = ETH_PHY_BASE_T,
7247 .ver_addr = 0,
7248 .req_flow_ctrl = 0,
7249 .req_line_speed = 0,
7250 .speed_cap_mask = 0,
7251 .req_duplex = 0,
7252 .rsrv = 0,
7253 .config_init = (config_init_t)bnx2x_8481_config_init,
7254 .read_status = (read_status_t)bnx2x_848xx_read_status,
7255 .link_reset = (link_reset_t)bnx2x_8481_link_reset,
7256 .config_loopback = (config_loopback_t)NULL,
7257 .format_fw_ver = (format_fw_ver_t)bnx2x_848xx_format_ver,
7258 .hw_reset = (hw_reset_t)bnx2x_8481_hw_reset,
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00007259 .set_link_led = (set_link_led_t)bnx2x_848xx_set_link_led,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007260 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007261};
7262
7263static struct bnx2x_phy phy_84823 = {
7264 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84823,
7265 .addr = 0xff,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007266 .flags = FLAGS_FAN_FAILURE_DET_REQ |
7267 FLAGS_REARM_LATCH_SIGNAL,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007268 .def_md_devad = 0,
7269 .reserved = 0,
7270 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
7271 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
7272 .mdio_ctrl = 0,
7273 .supported = (SUPPORTED_10baseT_Half |
7274 SUPPORTED_10baseT_Full |
7275 SUPPORTED_100baseT_Half |
7276 SUPPORTED_100baseT_Full |
7277 SUPPORTED_1000baseT_Full |
7278 SUPPORTED_10000baseT_Full |
7279 SUPPORTED_TP |
7280 SUPPORTED_Autoneg |
7281 SUPPORTED_Pause |
7282 SUPPORTED_Asym_Pause),
7283 .media_type = ETH_PHY_BASE_T,
7284 .ver_addr = 0,
7285 .req_flow_ctrl = 0,
7286 .req_line_speed = 0,
7287 .speed_cap_mask = 0,
7288 .req_duplex = 0,
7289 .rsrv = 0,
7290 .config_init = (config_init_t)bnx2x_848x3_config_init,
7291 .read_status = (read_status_t)bnx2x_848xx_read_status,
7292 .link_reset = (link_reset_t)bnx2x_848x3_link_reset,
7293 .config_loopback = (config_loopback_t)NULL,
7294 .format_fw_ver = (format_fw_ver_t)bnx2x_848xx_format_ver,
7295 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00007296 .set_link_led = (set_link_led_t)bnx2x_848xx_set_link_led,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007297 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007298};
7299
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00007300static struct bnx2x_phy phy_84833 = {
7301 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833,
7302 .addr = 0xff,
7303 .flags = FLAGS_FAN_FAILURE_DET_REQ |
7304 FLAGS_REARM_LATCH_SIGNAL,
7305 .def_md_devad = 0,
7306 .reserved = 0,
7307 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
7308 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
7309 .mdio_ctrl = 0,
7310 .supported = (SUPPORTED_10baseT_Half |
7311 SUPPORTED_10baseT_Full |
7312 SUPPORTED_100baseT_Half |
7313 SUPPORTED_100baseT_Full |
7314 SUPPORTED_1000baseT_Full |
7315 SUPPORTED_10000baseT_Full |
7316 SUPPORTED_TP |
7317 SUPPORTED_Autoneg |
7318 SUPPORTED_Pause |
7319 SUPPORTED_Asym_Pause),
7320 .media_type = ETH_PHY_BASE_T,
7321 .ver_addr = 0,
7322 .req_flow_ctrl = 0,
7323 .req_line_speed = 0,
7324 .speed_cap_mask = 0,
7325 .req_duplex = 0,
7326 .rsrv = 0,
7327 .config_init = (config_init_t)bnx2x_848x3_config_init,
7328 .read_status = (read_status_t)bnx2x_848xx_read_status,
7329 .link_reset = (link_reset_t)bnx2x_848x3_link_reset,
7330 .config_loopback = (config_loopback_t)NULL,
7331 .format_fw_ver = (format_fw_ver_t)bnx2x_848xx_format_ver,
7332 .hw_reset = (hw_reset_t)NULL,
7333 .set_link_led = (set_link_led_t)bnx2x_848xx_set_link_led,
7334 .phy_specific_func = (phy_specific_func_t)NULL
7335};
7336
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007337/*****************************************************************/
7338/* */
7339/* Populate the phy according. Main function: bnx2x_populate_phy */
7340/* */
7341/*****************************************************************/
7342
7343static void bnx2x_populate_preemphasis(struct bnx2x *bp, u32 shmem_base,
7344 struct bnx2x_phy *phy, u8 port,
7345 u8 phy_index)
7346{
7347 /* Get the 4 lanes xgxs config rx and tx */
7348 u32 rx = 0, tx = 0, i;
7349 for (i = 0; i < 2; i++) {
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007350 /*
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007351 * INT_PHY and EXT_PHY1 share the same value location in the
7352 * shmem. When num_phys is greater than 1, than this value
7353 * applies only to EXT_PHY1
7354 */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007355 if (phy_index == INT_PHY || phy_index == EXT_PHY1) {
7356 rx = REG_RD(bp, shmem_base +
7357 offsetof(struct shmem_region,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007358 dev_info.port_hw_config[port].xgxs_config_rx[i<<1]));
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007359
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007360 tx = REG_RD(bp, shmem_base +
7361 offsetof(struct shmem_region,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007362 dev_info.port_hw_config[port].xgxs_config_tx[i<<1]));
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007363 } else {
7364 rx = REG_RD(bp, shmem_base +
7365 offsetof(struct shmem_region,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007366 dev_info.port_hw_config[port].xgxs_config2_rx[i<<1]));
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007367
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007368 tx = REG_RD(bp, shmem_base +
7369 offsetof(struct shmem_region,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007370 dev_info.port_hw_config[port].xgxs_config2_rx[i<<1]));
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007371 }
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007372
7373 phy->rx_preemphasis[i << 1] = ((rx>>16) & 0xffff);
7374 phy->rx_preemphasis[(i << 1) + 1] = (rx & 0xffff);
7375
7376 phy->tx_preemphasis[i << 1] = ((tx>>16) & 0xffff);
7377 phy->tx_preemphasis[(i << 1) + 1] = (tx & 0xffff);
7378 }
7379}
7380
Yaniv Rosnere10bc842010-09-07 11:40:50 +00007381static u32 bnx2x_get_ext_phy_config(struct bnx2x *bp, u32 shmem_base,
7382 u8 phy_index, u8 port)
7383{
7384 u32 ext_phy_config = 0;
7385 switch (phy_index) {
7386 case EXT_PHY1:
7387 ext_phy_config = REG_RD(bp, shmem_base +
7388 offsetof(struct shmem_region,
7389 dev_info.port_hw_config[port].external_phy_config));
7390 break;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007391 case EXT_PHY2:
7392 ext_phy_config = REG_RD(bp, shmem_base +
7393 offsetof(struct shmem_region,
7394 dev_info.port_hw_config[port].external_phy_config2));
7395 break;
Yaniv Rosnere10bc842010-09-07 11:40:50 +00007396 default:
7397 DP(NETIF_MSG_LINK, "Invalid phy_index %d\n", phy_index);
7398 return -EINVAL;
7399 }
7400
7401 return ext_phy_config;
7402}
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00007403static int bnx2x_populate_int_phy(struct bnx2x *bp, u32 shmem_base, u8 port,
7404 struct bnx2x_phy *phy)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007405{
7406 u32 phy_addr;
7407 u32 chip_id;
7408 u32 switch_cfg = (REG_RD(bp, shmem_base +
7409 offsetof(struct shmem_region,
7410 dev_info.port_feature_config[port].link_config)) &
7411 PORT_FEATURE_CONNECTED_SWITCH_MASK);
7412 chip_id = REG_RD(bp, MISC_REG_CHIP_NUM) << 16;
7413 switch (switch_cfg) {
7414 case SWITCH_CFG_1G:
7415 phy_addr = REG_RD(bp,
7416 NIG_REG_SERDES0_CTRL_PHY_ADDR +
7417 port * 0x10);
7418 *phy = phy_serdes;
7419 break;
7420 case SWITCH_CFG_10G:
7421 phy_addr = REG_RD(bp,
7422 NIG_REG_XGXS0_CTRL_PHY_ADDR +
7423 port * 0x18);
7424 *phy = phy_xgxs;
7425 break;
7426 default:
7427 DP(NETIF_MSG_LINK, "Invalid switch_cfg\n");
7428 return -EINVAL;
7429 }
7430 phy->addr = (u8)phy_addr;
7431 phy->mdio_ctrl = bnx2x_get_emac_base(bp,
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00007432 SHARED_HW_CFG_MDC_MDIO_ACCESS1_BOTH,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007433 port);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007434 if (CHIP_IS_E2(bp))
7435 phy->def_md_devad = E2_DEFAULT_PHY_DEV_ADDR;
7436 else
7437 phy->def_md_devad = DEFAULT_PHY_DEV_ADDR;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007438
7439 DP(NETIF_MSG_LINK, "Internal phy port=%d, addr=0x%x, mdio_ctl=0x%x\n",
7440 port, phy->addr, phy->mdio_ctrl);
7441
7442 bnx2x_populate_preemphasis(bp, shmem_base, phy, port, INT_PHY);
7443 return 0;
7444}
Yaniv Rosnere10bc842010-09-07 11:40:50 +00007445
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00007446static int bnx2x_populate_ext_phy(struct bnx2x *bp,
7447 u8 phy_index,
7448 u32 shmem_base,
7449 u32 shmem2_base,
7450 u8 port,
7451 struct bnx2x_phy *phy)
Yaniv Rosnere10bc842010-09-07 11:40:50 +00007452{
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00007453 u32 ext_phy_config, phy_type, config2;
7454 u32 mdc_mdio_access = SHARED_HW_CFG_MDC_MDIO_ACCESS1_BOTH;
Yaniv Rosnere10bc842010-09-07 11:40:50 +00007455 ext_phy_config = bnx2x_get_ext_phy_config(bp, shmem_base,
7456 phy_index, port);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007457 phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
7458 /* Select the phy type */
7459 switch (phy_type) {
7460 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073:
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00007461 mdc_mdio_access = SHARED_HW_CFG_MDC_MDIO_ACCESS1_SWAPPED;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007462 *phy = phy_8073;
7463 break;
7464 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705:
7465 *phy = phy_8705;
7466 break;
7467 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706:
7468 *phy = phy_8706;
7469 break;
7470 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00007471 mdc_mdio_access = SHARED_HW_CFG_MDC_MDIO_ACCESS1_EMAC1;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007472 *phy = phy_8726;
7473 break;
7474 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727_NOC:
7475 /* BCM8727_NOC => BCM8727 no over current */
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00007476 mdc_mdio_access = SHARED_HW_CFG_MDC_MDIO_ACCESS1_EMAC1;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007477 *phy = phy_8727;
7478 phy->flags |= FLAGS_NOC;
7479 break;
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00007480 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8722:
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007481 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00007482 mdc_mdio_access = SHARED_HW_CFG_MDC_MDIO_ACCESS1_EMAC1;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007483 *phy = phy_8727;
7484 break;
7485 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8481:
7486 *phy = phy_8481;
7487 break;
7488 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84823:
7489 *phy = phy_84823;
7490 break;
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00007491 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833:
7492 *phy = phy_84833;
7493 break;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007494 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101:
7495 *phy = phy_7101;
7496 break;
7497 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE:
7498 *phy = phy_null;
7499 return -EINVAL;
7500 default:
7501 *phy = phy_null;
7502 return 0;
7503 }
7504
Yaniv Rosnere10bc842010-09-07 11:40:50 +00007505 phy->addr = XGXS_EXT_PHY_ADDR(ext_phy_config);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007506 bnx2x_populate_preemphasis(bp, shmem_base, phy, port, phy_index);
Yaniv Rosner62b29a52010-09-07 11:40:58 +00007507
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007508 /*
7509 * The shmem address of the phy version is located on different
7510 * structures. In case this structure is too old, do not set
7511 * the address
7512 */
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00007513 config2 = REG_RD(bp, shmem_base + offsetof(struct shmem_region,
7514 dev_info.shared_hw_config.config2));
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007515 if (phy_index == EXT_PHY1) {
7516 phy->ver_addr = shmem_base + offsetof(struct shmem_region,
7517 port_mb[port].ext_phy_fw_version);
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00007518
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007519 /* Check specific mdc mdio settings */
7520 if (config2 & SHARED_HW_CFG_MDC_MDIO_ACCESS1_MASK)
7521 mdc_mdio_access = config2 &
7522 SHARED_HW_CFG_MDC_MDIO_ACCESS1_MASK;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007523 } else {
7524 u32 size = REG_RD(bp, shmem2_base);
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00007525
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007526 if (size >
7527 offsetof(struct shmem2_region, ext_phy_fw_version2)) {
7528 phy->ver_addr = shmem2_base +
7529 offsetof(struct shmem2_region,
7530 ext_phy_fw_version2[port]);
7531 }
7532 /* Check specific mdc mdio settings */
7533 if (config2 & SHARED_HW_CFG_MDC_MDIO_ACCESS2_MASK)
7534 mdc_mdio_access = (config2 &
7535 SHARED_HW_CFG_MDC_MDIO_ACCESS2_MASK) >>
7536 (SHARED_HW_CFG_MDC_MDIO_ACCESS2_SHIFT -
7537 SHARED_HW_CFG_MDC_MDIO_ACCESS1_SHIFT);
7538 }
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00007539 phy->mdio_ctrl = bnx2x_get_emac_base(bp, mdc_mdio_access, port);
7540
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007541 /*
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00007542 * In case mdc/mdio_access of the external phy is different than the
7543 * mdc/mdio access of the XGXS, a HW lock must be taken in each access
7544 * to prevent one port interfere with another port's CL45 operations.
7545 */
7546 if (mdc_mdio_access != SHARED_HW_CFG_MDC_MDIO_ACCESS1_BOTH)
7547 phy->flags |= FLAGS_HW_LOCK_REQUIRED;
7548 DP(NETIF_MSG_LINK, "phy_type 0x%x port %d found in index %d\n",
7549 phy_type, port, phy_index);
7550 DP(NETIF_MSG_LINK, " addr=0x%x, mdio_ctl=0x%x\n",
7551 phy->addr, phy->mdio_ctrl);
Yaniv Rosnere10bc842010-09-07 11:40:50 +00007552 return 0;
7553}
7554
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00007555static int bnx2x_populate_phy(struct bnx2x *bp, u8 phy_index, u32 shmem_base,
7556 u32 shmem2_base, u8 port, struct bnx2x_phy *phy)
Yaniv Rosnere10bc842010-09-07 11:40:50 +00007557{
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00007558 int status = 0;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007559 phy->type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN;
7560 if (phy_index == INT_PHY)
7561 return bnx2x_populate_int_phy(bp, shmem_base, port, phy);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007562 status = bnx2x_populate_ext_phy(bp, phy_index, shmem_base, shmem2_base,
Yaniv Rosnere10bc842010-09-07 11:40:50 +00007563 port, phy);
7564 return status;
7565}
7566
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007567static void bnx2x_phy_def_cfg(struct link_params *params,
7568 struct bnx2x_phy *phy,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007569 u8 phy_index)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007570{
7571 struct bnx2x *bp = params->bp;
7572 u32 link_config;
7573 /* Populate the default phy configuration for MF mode */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007574 if (phy_index == EXT_PHY2) {
7575 link_config = REG_RD(bp, params->shmem_base +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007576 offsetof(struct shmem_region, dev_info.
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007577 port_feature_config[params->port].link_config2));
7578 phy->speed_cap_mask = REG_RD(bp, params->shmem_base +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007579 offsetof(struct shmem_region,
7580 dev_info.
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007581 port_hw_config[params->port].speed_capability_mask2));
7582 } else {
7583 link_config = REG_RD(bp, params->shmem_base +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007584 offsetof(struct shmem_region, dev_info.
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007585 port_feature_config[params->port].link_config));
7586 phy->speed_cap_mask = REG_RD(bp, params->shmem_base +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007587 offsetof(struct shmem_region,
7588 dev_info.
7589 port_hw_config[params->port].speed_capability_mask));
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007590 }
7591 DP(NETIF_MSG_LINK, "Default config phy idx %x cfg 0x%x speed_cap_mask"
7592 " 0x%x\n", phy_index, link_config, phy->speed_cap_mask);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007593
7594 phy->req_duplex = DUPLEX_FULL;
7595 switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
7596 case PORT_FEATURE_LINK_SPEED_10M_HALF:
7597 phy->req_duplex = DUPLEX_HALF;
7598 case PORT_FEATURE_LINK_SPEED_10M_FULL:
7599 phy->req_line_speed = SPEED_10;
7600 break;
7601 case PORT_FEATURE_LINK_SPEED_100M_HALF:
7602 phy->req_duplex = DUPLEX_HALF;
7603 case PORT_FEATURE_LINK_SPEED_100M_FULL:
7604 phy->req_line_speed = SPEED_100;
7605 break;
7606 case PORT_FEATURE_LINK_SPEED_1G:
7607 phy->req_line_speed = SPEED_1000;
7608 break;
7609 case PORT_FEATURE_LINK_SPEED_2_5G:
7610 phy->req_line_speed = SPEED_2500;
7611 break;
7612 case PORT_FEATURE_LINK_SPEED_10G_CX4:
7613 phy->req_line_speed = SPEED_10000;
7614 break;
7615 default:
7616 phy->req_line_speed = SPEED_AUTO_NEG;
7617 break;
7618 }
7619
7620 switch (link_config & PORT_FEATURE_FLOW_CONTROL_MASK) {
7621 case PORT_FEATURE_FLOW_CONTROL_AUTO:
7622 phy->req_flow_ctrl = BNX2X_FLOW_CTRL_AUTO;
7623 break;
7624 case PORT_FEATURE_FLOW_CONTROL_TX:
7625 phy->req_flow_ctrl = BNX2X_FLOW_CTRL_TX;
7626 break;
7627 case PORT_FEATURE_FLOW_CONTROL_RX:
7628 phy->req_flow_ctrl = BNX2X_FLOW_CTRL_RX;
7629 break;
7630 case PORT_FEATURE_FLOW_CONTROL_BOTH:
7631 phy->req_flow_ctrl = BNX2X_FLOW_CTRL_BOTH;
7632 break;
7633 default:
7634 phy->req_flow_ctrl = BNX2X_FLOW_CTRL_NONE;
7635 break;
7636 }
7637}
7638
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007639u32 bnx2x_phy_selection(struct link_params *params)
7640{
7641 u32 phy_config_swapped, prio_cfg;
7642 u32 return_cfg = PORT_HW_CFG_PHY_SELECTION_HARDWARE_DEFAULT;
7643
7644 phy_config_swapped = params->multi_phy_config &
7645 PORT_HW_CFG_PHY_SWAPPED_ENABLED;
7646
7647 prio_cfg = params->multi_phy_config &
7648 PORT_HW_CFG_PHY_SELECTION_MASK;
7649
7650 if (phy_config_swapped) {
7651 switch (prio_cfg) {
7652 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY_PRIORITY:
7653 return_cfg = PORT_HW_CFG_PHY_SELECTION_SECOND_PHY_PRIORITY;
7654 break;
7655 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY_PRIORITY:
7656 return_cfg = PORT_HW_CFG_PHY_SELECTION_FIRST_PHY_PRIORITY;
7657 break;
7658 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY:
7659 return_cfg = PORT_HW_CFG_PHY_SELECTION_FIRST_PHY;
7660 break;
7661 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY:
7662 return_cfg = PORT_HW_CFG_PHY_SELECTION_SECOND_PHY;
7663 break;
7664 }
7665 } else
7666 return_cfg = prio_cfg;
7667
7668 return return_cfg;
7669}
7670
7671
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00007672int bnx2x_phy_probe(struct link_params *params)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007673{
7674 u8 phy_index, actual_phy_idx, link_cfg_idx;
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00007675 u32 phy_config_swapped, sync_offset, media_types;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007676 struct bnx2x *bp = params->bp;
7677 struct bnx2x_phy *phy;
7678 params->num_phys = 0;
7679 DP(NETIF_MSG_LINK, "Begin phy probe\n");
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007680 phy_config_swapped = params->multi_phy_config &
7681 PORT_HW_CFG_PHY_SWAPPED_ENABLED;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007682
7683 for (phy_index = INT_PHY; phy_index < MAX_PHYS;
7684 phy_index++) {
7685 link_cfg_idx = LINK_CONFIG_IDX(phy_index);
7686 actual_phy_idx = phy_index;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007687 if (phy_config_swapped) {
7688 if (phy_index == EXT_PHY1)
7689 actual_phy_idx = EXT_PHY2;
7690 else if (phy_index == EXT_PHY2)
7691 actual_phy_idx = EXT_PHY1;
7692 }
7693 DP(NETIF_MSG_LINK, "phy_config_swapped %x, phy_index %x,"
7694 " actual_phy_idx %x\n", phy_config_swapped,
7695 phy_index, actual_phy_idx);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007696 phy = &params->phy[actual_phy_idx];
7697 if (bnx2x_populate_phy(bp, phy_index, params->shmem_base,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007698 params->shmem2_base, params->port,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007699 phy) != 0) {
7700 params->num_phys = 0;
7701 DP(NETIF_MSG_LINK, "phy probe failed in phy index %d\n",
7702 phy_index);
7703 for (phy_index = INT_PHY;
7704 phy_index < MAX_PHYS;
7705 phy_index++)
7706 *phy = phy_null;
7707 return -EINVAL;
7708 }
7709 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN)
7710 break;
7711
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00007712 sync_offset = params->shmem_base +
7713 offsetof(struct shmem_region,
7714 dev_info.port_hw_config[params->port].media_type);
7715 media_types = REG_RD(bp, sync_offset);
7716
7717 /*
7718 * Update media type for non-PMF sync only for the first time
7719 * In case the media type changes afterwards, it will be updated
7720 * using the update_status function
7721 */
7722 if ((media_types & (PORT_HW_CFG_MEDIA_TYPE_PHY0_MASK <<
7723 (PORT_HW_CFG_MEDIA_TYPE_PHY1_SHIFT *
7724 actual_phy_idx))) == 0) {
7725 media_types |= ((phy->media_type &
7726 PORT_HW_CFG_MEDIA_TYPE_PHY0_MASK) <<
7727 (PORT_HW_CFG_MEDIA_TYPE_PHY1_SHIFT *
7728 actual_phy_idx));
7729 }
7730 REG_WR(bp, sync_offset, media_types);
7731
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007732 bnx2x_phy_def_cfg(params, phy, phy_index);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007733 params->num_phys++;
7734 }
7735
7736 DP(NETIF_MSG_LINK, "End phy probe. #phys found %x\n", params->num_phys);
7737 return 0;
7738}
7739
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007740static void set_phy_vars(struct link_params *params)
7741{
7742 struct bnx2x *bp = params->bp;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007743 u8 actual_phy_idx, phy_index, link_cfg_idx;
7744 u8 phy_config_swapped = params->multi_phy_config &
7745 PORT_HW_CFG_PHY_SWAPPED_ENABLED;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007746 for (phy_index = INT_PHY; phy_index < params->num_phys;
7747 phy_index++) {
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007748 link_cfg_idx = LINK_CONFIG_IDX(phy_index);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007749 actual_phy_idx = phy_index;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007750 if (phy_config_swapped) {
7751 if (phy_index == EXT_PHY1)
7752 actual_phy_idx = EXT_PHY2;
7753 else if (phy_index == EXT_PHY2)
7754 actual_phy_idx = EXT_PHY1;
7755 }
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007756 params->phy[actual_phy_idx].req_flow_ctrl =
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007757 params->req_flow_ctrl[link_cfg_idx];
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007758
7759 params->phy[actual_phy_idx].req_line_speed =
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007760 params->req_line_speed[link_cfg_idx];
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007761
7762 params->phy[actual_phy_idx].speed_cap_mask =
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007763 params->speed_cap_mask[link_cfg_idx];
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007764
7765 params->phy[actual_phy_idx].req_duplex =
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007766 params->req_duplex[link_cfg_idx];
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007767
7768 DP(NETIF_MSG_LINK, "req_flow_ctrl %x, req_line_speed %x,"
7769 " speed_cap_mask %x\n",
7770 params->phy[actual_phy_idx].req_flow_ctrl,
7771 params->phy[actual_phy_idx].req_line_speed,
7772 params->phy[actual_phy_idx].speed_cap_mask);
7773 }
7774}
7775
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00007776int bnx2x_phy_init(struct link_params *params, struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007777{
7778 struct bnx2x *bp = params->bp;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007779 DP(NETIF_MSG_LINK, "Phy Initialization started\n");
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007780 DP(NETIF_MSG_LINK, "(1) req_speed %d, req_flowctrl %d\n",
7781 params->req_line_speed[0], params->req_flow_ctrl[0]);
7782 DP(NETIF_MSG_LINK, "(2) req_speed %d, req_flowctrl %d\n",
7783 params->req_line_speed[1], params->req_flow_ctrl[1]);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007784 vars->link_status = 0;
7785 vars->phy_link_up = 0;
7786 vars->link_up = 0;
7787 vars->line_speed = 0;
7788 vars->duplex = DUPLEX_FULL;
7789 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
7790 vars->mac_type = MAC_TYPE_NONE;
7791 vars->phy_flags = 0;
7792
7793 /* disable attentions */
7794 bnx2x_bits_dis(bp, NIG_REG_MASK_INTERRUPT_PORT0 + params->port*4,
7795 (NIG_MASK_XGXS0_LINK_STATUS |
7796 NIG_MASK_XGXS0_LINK10G |
7797 NIG_MASK_SERDES0_LINK_STATUS |
7798 NIG_MASK_MI_INT));
7799
7800 bnx2x_emac_init(params, vars);
7801
7802 if (params->num_phys == 0) {
7803 DP(NETIF_MSG_LINK, "No phy found for initialization !!\n");
7804 return -EINVAL;
7805 }
7806 set_phy_vars(params);
7807
7808 DP(NETIF_MSG_LINK, "Num of phys on board: %d\n", params->num_phys);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007809 if (params->loopback_mode == LOOPBACK_BMAC) {
7810
7811 vars->link_up = 1;
7812 vars->line_speed = SPEED_10000;
7813 vars->duplex = DUPLEX_FULL;
7814 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
7815 vars->mac_type = MAC_TYPE_BMAC;
7816
7817 vars->phy_flags = PHY_XGXS_FLAG;
7818
7819 bnx2x_xgxs_deassert(params);
7820
7821 /* set bmac loopback */
7822 bnx2x_bmac_enable(params, vars, 1);
7823
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007824 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007825
7826 } else if (params->loopback_mode == LOOPBACK_EMAC) {
7827
7828 vars->link_up = 1;
7829 vars->line_speed = SPEED_1000;
7830 vars->duplex = DUPLEX_FULL;
7831 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
7832 vars->mac_type = MAC_TYPE_EMAC;
7833
7834 vars->phy_flags = PHY_XGXS_FLAG;
7835
7836 bnx2x_xgxs_deassert(params);
7837 /* set bmac loopback */
7838 bnx2x_emac_enable(params, vars, 1);
7839 bnx2x_emac_program(params, vars);
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007840 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007841
7842 } else if ((params->loopback_mode == LOOPBACK_XGXS) ||
7843 (params->loopback_mode == LOOPBACK_EXT_PHY)) {
7844
7845 vars->link_up = 1;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007846 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007847 vars->duplex = DUPLEX_FULL;
7848 if (params->req_line_speed[0] == SPEED_1000) {
7849 vars->line_speed = SPEED_1000;
7850 vars->mac_type = MAC_TYPE_EMAC;
7851 } else {
7852 vars->line_speed = SPEED_10000;
7853 vars->mac_type = MAC_TYPE_BMAC;
7854 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007855
7856 bnx2x_xgxs_deassert(params);
7857 bnx2x_link_initialize(params, vars);
7858
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007859 if (params->req_line_speed[0] == SPEED_1000) {
7860 bnx2x_emac_program(params, vars);
7861 bnx2x_emac_enable(params, vars, 0);
7862 } else
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007863 bnx2x_bmac_enable(params, vars, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007864 if (params->loopback_mode == LOOPBACK_XGXS) {
7865 /* set 10G XGXS loopback */
7866 params->phy[INT_PHY].config_loopback(
7867 &params->phy[INT_PHY],
7868 params);
7869
7870 } else {
7871 /* set external phy loopback */
7872 u8 phy_index;
7873 for (phy_index = EXT_PHY1;
7874 phy_index < params->num_phys; phy_index++) {
7875 if (params->phy[phy_index].config_loopback)
7876 params->phy[phy_index].config_loopback(
7877 &params->phy[phy_index],
7878 params);
7879 }
7880 }
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007881 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007882
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00007883 bnx2x_set_led(params, vars,
7884 LED_MODE_OPER, vars->line_speed);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007885 } else
7886 /* No loopback */
7887 {
7888 if (params->switch_cfg == SWITCH_CFG_10G)
7889 bnx2x_xgxs_deassert(params);
7890 else
7891 bnx2x_serdes_deassert(bp, params->port);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00007892
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007893 bnx2x_link_initialize(params, vars);
7894 msleep(30);
7895 bnx2x_link_int_enable(params);
7896 }
7897 return 0;
7898}
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00007899
7900int bnx2x_link_reset(struct link_params *params, struct link_vars *vars,
7901 u8 reset_ext_phy)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007902{
7903 struct bnx2x *bp = params->bp;
Yaniv Rosnercf1d9722010-11-01 05:32:34 +00007904 u8 phy_index, port = params->port, clear_latch_ind = 0;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007905 DP(NETIF_MSG_LINK, "Resetting the link of port %d\n", port);
7906 /* disable attentions */
7907 vars->link_status = 0;
7908 bnx2x_update_mng(params, vars->link_status);
7909 bnx2x_bits_dis(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007910 (NIG_MASK_XGXS0_LINK_STATUS |
7911 NIG_MASK_XGXS0_LINK10G |
7912 NIG_MASK_SERDES0_LINK_STATUS |
7913 NIG_MASK_MI_INT));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007914
7915 /* activate nig drain */
7916 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + port*4, 1);
7917
7918 /* disable nig egress interface */
7919 REG_WR(bp, NIG_REG_BMAC0_OUT_EN + port*4, 0);
7920 REG_WR(bp, NIG_REG_EGRESS_EMAC0_OUT_EN + port*4, 0);
7921
7922 /* Stop BigMac rx */
7923 bnx2x_bmac_rx_disable(bp, port);
7924
7925 /* disable emac */
7926 REG_WR(bp, NIG_REG_NIG_EMAC0_EN + port*4, 0);
7927
7928 msleep(10);
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007929 /* The PHY reset is controlled by GPIO 1
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007930 * Hold it as vars low
7931 */
7932 /* clear link led */
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00007933 bnx2x_set_led(params, vars, LED_MODE_OFF, 0);
7934
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007935 if (reset_ext_phy) {
7936 for (phy_index = EXT_PHY1; phy_index < params->num_phys;
7937 phy_index++) {
7938 if (params->phy[phy_index].link_reset)
7939 params->phy[phy_index].link_reset(
7940 &params->phy[phy_index],
7941 params);
Yaniv Rosnercf1d9722010-11-01 05:32:34 +00007942 if (params->phy[phy_index].flags &
7943 FLAGS_REARM_LATCH_SIGNAL)
7944 clear_latch_ind = 1;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007945 }
7946 }
7947
Yaniv Rosnercf1d9722010-11-01 05:32:34 +00007948 if (clear_latch_ind) {
7949 /* Clear latching indication */
7950 bnx2x_rearm_latch_signal(bp, port, 0);
7951 bnx2x_bits_dis(bp, NIG_REG_LATCH_BC_0 + port*4,
7952 1 << NIG_LATCH_BC_ENABLE_MI_INT);
7953 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007954 if (params->phy[INT_PHY].link_reset)
7955 params->phy[INT_PHY].link_reset(
7956 &params->phy[INT_PHY], params);
7957 /* reset BigMac */
7958 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
7959 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port));
7960
7961 /* disable nig ingress interface */
7962 REG_WR(bp, NIG_REG_BMAC0_IN_EN + port*4, 0);
7963 REG_WR(bp, NIG_REG_EMAC0_IN_EN + port*4, 0);
7964 REG_WR(bp, NIG_REG_BMAC0_OUT_EN + port*4, 0);
7965 REG_WR(bp, NIG_REG_EGRESS_EMAC0_OUT_EN + port*4, 0);
7966 vars->link_up = 0;
7967 return 0;
7968}
7969
7970/****************************************************************************/
7971/* Common function */
7972/****************************************************************************/
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00007973static int bnx2x_8073_common_init_phy(struct bnx2x *bp,
7974 u32 shmem_base_path[],
7975 u32 shmem2_base_path[], u8 phy_index,
7976 u32 chip_id)
Yaniv Rosner6bbca912008-08-13 15:57:28 -07007977{
Yaniv Rosnere10bc842010-09-07 11:40:50 +00007978 struct bnx2x_phy phy[PORT_MAX];
7979 struct bnx2x_phy *phy_blk[PORT_MAX];
Yaniv Rosner6bbca912008-08-13 15:57:28 -07007980 u16 val;
Yaniv Rosnerc8e64df2011-01-30 04:15:00 +00007981 s8 port = 0;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007982 s8 port_of_path = 0;
Yaniv Rosnerc8e64df2011-01-30 04:15:00 +00007983 u32 swap_val, swap_override;
7984 swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
7985 swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
7986 port ^= (swap_val && swap_override);
7987 bnx2x_ext_phy_hw_reset(bp, port);
Yaniv Rosner6bbca912008-08-13 15:57:28 -07007988 /* PART1 - Reset both phys */
7989 for (port = PORT_MAX - 1; port >= PORT_0; port--) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007990 u32 shmem_base, shmem2_base;
7991 /* In E2, same phy is using for port0 of the two paths */
7992 if (CHIP_IS_E2(bp)) {
7993 shmem_base = shmem_base_path[port];
7994 shmem2_base = shmem2_base_path[port];
7995 port_of_path = 0;
7996 } else {
7997 shmem_base = shmem_base_path[0];
7998 shmem2_base = shmem2_base_path[0];
7999 port_of_path = port;
8000 }
8001
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008002 /* Extract the ext phy address for the port */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008003 if (bnx2x_populate_phy(bp, phy_index, shmem_base, shmem2_base,
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008004 port_of_path, &phy[port]) !=
Yaniv Rosnere10bc842010-09-07 11:40:50 +00008005 0) {
8006 DP(NETIF_MSG_LINK, "populate_phy failed\n");
8007 return -EINVAL;
8008 }
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008009 /* disable attentions */
Yaniv Rosner6a71bbe2010-11-01 05:32:31 +00008010 bnx2x_bits_dis(bp, NIG_REG_MASK_INTERRUPT_PORT0 +
8011 port_of_path*4,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008012 (NIG_MASK_XGXS0_LINK_STATUS |
8013 NIG_MASK_XGXS0_LINK10G |
8014 NIG_MASK_SERDES0_LINK_STATUS |
8015 NIG_MASK_MI_INT));
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008016
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008017 /* Need to take the phy out of low power mode in order
8018 to write to access its registers */
8019 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008020 MISC_REGISTERS_GPIO_OUTPUT_HIGH,
8021 port);
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008022
8023 /* Reset the phy */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00008024 bnx2x_cl45_write(bp, &phy[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008025 MDIO_PMA_DEVAD,
8026 MDIO_PMA_REG_CTRL,
8027 1<<15);
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008028 }
8029
8030 /* Add delay of 150ms after reset */
8031 msleep(150);
8032
Yaniv Rosnere10bc842010-09-07 11:40:50 +00008033 if (phy[PORT_0].addr & 0x1) {
8034 phy_blk[PORT_0] = &(phy[PORT_1]);
8035 phy_blk[PORT_1] = &(phy[PORT_0]);
8036 } else {
8037 phy_blk[PORT_0] = &(phy[PORT_0]);
8038 phy_blk[PORT_1] = &(phy[PORT_1]);
8039 }
8040
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008041 /* PART2 - Download firmware to both phys */
8042 for (port = PORT_MAX - 1; port >= PORT_0; port--) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008043 if (CHIP_IS_E2(bp))
8044 port_of_path = 0;
8045 else
8046 port_of_path = port;
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008047
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008048 DP(NETIF_MSG_LINK, "Loading spirom for phy address 0x%x\n",
8049 phy_blk[port]->addr);
Yaniv Rosner5c99274b2011-01-18 04:33:36 +00008050 if (bnx2x_8073_8727_external_rom_boot(bp, phy_blk[port],
8051 port_of_path))
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008052 return -EINVAL;
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008053
8054 /* Only set bit 10 = 1 (Tx power down) */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00008055 bnx2x_cl45_read(bp, phy_blk[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008056 MDIO_PMA_DEVAD,
8057 MDIO_PMA_REG_TX_POWER_DOWN, &val);
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008058
8059 /* Phase1 of TX_POWER_DOWN reset */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00008060 bnx2x_cl45_write(bp, phy_blk[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008061 MDIO_PMA_DEVAD,
8062 MDIO_PMA_REG_TX_POWER_DOWN,
8063 (val | 1<<10));
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008064 }
8065
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008066 /*
8067 * Toggle Transmitter: Power down and then up with 600ms delay
8068 * between
8069 */
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008070 msleep(600);
8071
8072 /* PART3 - complete TX_POWER_DOWN process, and set GPIO2 back to low */
8073 for (port = PORT_MAX - 1; port >= PORT_0; port--) {
Eilon Greensteinf5372252009-02-12 08:38:30 +00008074 /* Phase2 of POWER_DOWN_RESET */
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008075 /* Release bit 10 (Release Tx power down) */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00008076 bnx2x_cl45_read(bp, phy_blk[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008077 MDIO_PMA_DEVAD,
8078 MDIO_PMA_REG_TX_POWER_DOWN, &val);
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008079
Yaniv Rosnere10bc842010-09-07 11:40:50 +00008080 bnx2x_cl45_write(bp, phy_blk[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008081 MDIO_PMA_DEVAD,
8082 MDIO_PMA_REG_TX_POWER_DOWN, (val & (~(1<<10))));
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008083 msleep(15);
8084
8085 /* Read modify write the SPI-ROM version select register */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00008086 bnx2x_cl45_read(bp, phy_blk[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008087 MDIO_PMA_DEVAD,
8088 MDIO_PMA_REG_EDC_FFE_MAIN, &val);
Yaniv Rosnere10bc842010-09-07 11:40:50 +00008089 bnx2x_cl45_write(bp, phy_blk[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008090 MDIO_PMA_DEVAD,
8091 MDIO_PMA_REG_EDC_FFE_MAIN, (val | (1<<12)));
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008092
8093 /* set GPIO2 back to LOW */
8094 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008095 MISC_REGISTERS_GPIO_OUTPUT_LOW, port);
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008096 }
8097 return 0;
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008098}
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00008099static int bnx2x_8726_common_init_phy(struct bnx2x *bp,
8100 u32 shmem_base_path[],
8101 u32 shmem2_base_path[], u8 phy_index,
8102 u32 chip_id)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008103{
8104 u32 val;
8105 s8 port;
8106 struct bnx2x_phy phy;
8107 /* Use port1 because of the static port-swap */
8108 /* Enable the module detection interrupt */
8109 val = REG_RD(bp, MISC_REG_GPIO_EVENT_EN);
8110 val |= ((1<<MISC_REGISTERS_GPIO_3)|
8111 (1<<(MISC_REGISTERS_GPIO_3 + MISC_REGISTERS_GPIO_PORT_SHIFT)));
8112 REG_WR(bp, MISC_REG_GPIO_EVENT_EN, val);
8113
Yaniv Rosner650154b2010-11-01 05:32:36 +00008114 bnx2x_ext_phy_hw_reset(bp, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008115 msleep(5);
8116 for (port = 0; port < PORT_MAX; port++) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008117 u32 shmem_base, shmem2_base;
8118
8119 /* In E2, same phy is using for port0 of the two paths */
8120 if (CHIP_IS_E2(bp)) {
8121 shmem_base = shmem_base_path[port];
8122 shmem2_base = shmem2_base_path[port];
8123 } else {
8124 shmem_base = shmem_base_path[0];
8125 shmem2_base = shmem2_base_path[0];
8126 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008127 /* Extract the ext phy address for the port */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008128 if (bnx2x_populate_phy(bp, phy_index, shmem_base, shmem2_base,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008129 port, &phy) !=
8130 0) {
8131 DP(NETIF_MSG_LINK, "populate phy failed\n");
8132 return -EINVAL;
8133 }
8134
8135 /* Reset phy*/
8136 bnx2x_cl45_write(bp, &phy,
8137 MDIO_PMA_DEVAD, MDIO_PMA_REG_GEN_CTRL, 0x0001);
8138
8139
8140 /* Set fault module detected LED on */
8141 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_0,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008142 MISC_REGISTERS_GPIO_HIGH,
8143 port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008144 }
8145
8146 return 0;
8147}
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008148static void bnx2x_get_ext_phy_reset_gpio(struct bnx2x *bp, u32 shmem_base,
8149 u8 *io_gpio, u8 *io_port)
8150{
8151
8152 u32 phy_gpio_reset = REG_RD(bp, shmem_base +
8153 offsetof(struct shmem_region,
8154 dev_info.port_hw_config[PORT_0].default_cfg));
8155 switch (phy_gpio_reset) {
8156 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO0_P0:
8157 *io_gpio = 0;
8158 *io_port = 0;
8159 break;
8160 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO1_P0:
8161 *io_gpio = 1;
8162 *io_port = 0;
8163 break;
8164 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO2_P0:
8165 *io_gpio = 2;
8166 *io_port = 0;
8167 break;
8168 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO3_P0:
8169 *io_gpio = 3;
8170 *io_port = 0;
8171 break;
8172 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO0_P1:
8173 *io_gpio = 0;
8174 *io_port = 1;
8175 break;
8176 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO1_P1:
8177 *io_gpio = 1;
8178 *io_port = 1;
8179 break;
8180 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO2_P1:
8181 *io_gpio = 2;
8182 *io_port = 1;
8183 break;
8184 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO3_P1:
8185 *io_gpio = 3;
8186 *io_port = 1;
8187 break;
8188 default:
8189 /* Don't override the io_gpio and io_port */
8190 break;
8191 }
8192}
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00008193
8194static int bnx2x_8727_common_init_phy(struct bnx2x *bp,
8195 u32 shmem_base_path[],
8196 u32 shmem2_base_path[], u8 phy_index,
8197 u32 chip_id)
Eilon Greenstein4d295db2009-07-21 05:47:47 +00008198{
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008199 s8 port, reset_gpio;
Eilon Greenstein4d295db2009-07-21 05:47:47 +00008200 u32 swap_val, swap_override;
Yaniv Rosnere10bc842010-09-07 11:40:50 +00008201 struct bnx2x_phy phy[PORT_MAX];
8202 struct bnx2x_phy *phy_blk[PORT_MAX];
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008203 s8 port_of_path;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008204 swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
8205 swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
Eilon Greenstein4d295db2009-07-21 05:47:47 +00008206
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008207 reset_gpio = MISC_REGISTERS_GPIO_1;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008208 port = 1;
8209
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008210 /*
8211 * Retrieve the reset gpio/port which control the reset.
8212 * Default is GPIO1, PORT1
8213 */
8214 bnx2x_get_ext_phy_reset_gpio(bp, shmem_base_path[0],
8215 (u8 *)&reset_gpio, (u8 *)&port);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008216
8217 /* Calculate the port based on port swap */
8218 port ^= (swap_val && swap_override);
8219
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008220 /* Initiate PHY reset*/
8221 bnx2x_set_gpio(bp, reset_gpio, MISC_REGISTERS_GPIO_OUTPUT_LOW,
8222 port);
8223 msleep(1);
8224 bnx2x_set_gpio(bp, reset_gpio, MISC_REGISTERS_GPIO_OUTPUT_HIGH,
8225 port);
8226
Eilon Greenstein4d295db2009-07-21 05:47:47 +00008227 msleep(5);
8228
8229 /* PART1 - Reset both phys */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008230 for (port = PORT_MAX - 1; port >= PORT_0; port--) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008231 u32 shmem_base, shmem2_base;
8232
8233 /* In E2, same phy is using for port0 of the two paths */
8234 if (CHIP_IS_E2(bp)) {
8235 shmem_base = shmem_base_path[port];
8236 shmem2_base = shmem2_base_path[port];
8237 port_of_path = 0;
8238 } else {
8239 shmem_base = shmem_base_path[0];
8240 shmem2_base = shmem2_base_path[0];
8241 port_of_path = port;
8242 }
8243
Eilon Greenstein4d295db2009-07-21 05:47:47 +00008244 /* Extract the ext phy address for the port */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008245 if (bnx2x_populate_phy(bp, phy_index, shmem_base, shmem2_base,
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008246 port_of_path, &phy[port]) !=
Yaniv Rosnere10bc842010-09-07 11:40:50 +00008247 0) {
8248 DP(NETIF_MSG_LINK, "populate phy failed\n");
8249 return -EINVAL;
8250 }
Eilon Greenstein4d295db2009-07-21 05:47:47 +00008251 /* disable attentions */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008252 bnx2x_bits_dis(bp, NIG_REG_MASK_INTERRUPT_PORT0 +
8253 port_of_path*4,
8254 (NIG_MASK_XGXS0_LINK_STATUS |
8255 NIG_MASK_XGXS0_LINK10G |
8256 NIG_MASK_SERDES0_LINK_STATUS |
8257 NIG_MASK_MI_INT));
Eilon Greenstein4d295db2009-07-21 05:47:47 +00008258
Eilon Greenstein4d295db2009-07-21 05:47:47 +00008259
8260 /* Reset the phy */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00008261 bnx2x_cl45_write(bp, &phy[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008262 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 1<<15);
Eilon Greenstein4d295db2009-07-21 05:47:47 +00008263 }
8264
8265 /* Add delay of 150ms after reset */
8266 msleep(150);
Yaniv Rosnere10bc842010-09-07 11:40:50 +00008267 if (phy[PORT_0].addr & 0x1) {
8268 phy_blk[PORT_0] = &(phy[PORT_1]);
8269 phy_blk[PORT_1] = &(phy[PORT_0]);
8270 } else {
8271 phy_blk[PORT_0] = &(phy[PORT_0]);
8272 phy_blk[PORT_1] = &(phy[PORT_1]);
8273 }
Eilon Greenstein4d295db2009-07-21 05:47:47 +00008274 /* PART2 - Download firmware to both phys */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00008275 for (port = PORT_MAX - 1; port >= PORT_0; port--) {
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008276 if (CHIP_IS_E2(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008277 port_of_path = 0;
8278 else
8279 port_of_path = port;
8280 DP(NETIF_MSG_LINK, "Loading spirom for phy address 0x%x\n",
8281 phy_blk[port]->addr);
Yaniv Rosner5c99274b2011-01-18 04:33:36 +00008282 if (bnx2x_8073_8727_external_rom_boot(bp, phy_blk[port],
8283 port_of_path))
Eilon Greenstein4d295db2009-07-21 05:47:47 +00008284 return -EINVAL;
Eilon Greenstein4d295db2009-07-21 05:47:47 +00008285
Yaniv Rosner5c99274b2011-01-18 04:33:36 +00008286 }
Eilon Greenstein4d295db2009-07-21 05:47:47 +00008287 return 0;
8288}
8289
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00008290static int bnx2x_ext_phy_common_init(struct bnx2x *bp, u32 shmem_base_path[],
8291 u32 shmem2_base_path[], u8 phy_index,
8292 u32 ext_phy_type, u32 chip_id)
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008293{
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00008294 int rc = 0;
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008295
8296 switch (ext_phy_type) {
8297 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073:
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008298 rc = bnx2x_8073_common_init_phy(bp, shmem_base_path,
8299 shmem2_base_path,
8300 phy_index, chip_id);
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008301 break;
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00008302 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8722:
Eilon Greenstein4d295db2009-07-21 05:47:47 +00008303 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
8304 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727_NOC:
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008305 rc = bnx2x_8727_common_init_phy(bp, shmem_base_path,
8306 shmem2_base_path,
8307 phy_index, chip_id);
Eilon Greenstein4d295db2009-07-21 05:47:47 +00008308 break;
8309
Eilon Greenstein589abe32009-02-12 08:36:55 +00008310 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008311 /*
8312 * GPIO1 affects both ports, so there's need to pull
8313 * it for single port alone
8314 */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008315 rc = bnx2x_8726_common_init_phy(bp, shmem_base_path,
8316 shmem2_base_path,
8317 phy_index, chip_id);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008318 break;
8319 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE:
8320 rc = -EINVAL;
Yaniv Rosner4f60dab2009-11-05 19:18:23 +02008321 break;
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008322 default:
8323 DP(NETIF_MSG_LINK,
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008324 "ext_phy 0x%x common init not required\n",
8325 ext_phy_type);
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008326 break;
8327 }
8328
Yaniv Rosner6d870c32011-01-31 04:22:20 +00008329 if (rc != 0)
8330 netdev_err(bp->dev, "Warning: PHY was not initialized,"
8331 " Port %d\n",
8332 0);
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008333 return rc;
8334}
8335
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00008336int bnx2x_common_init_phy(struct bnx2x *bp, u32 shmem_base_path[],
8337 u32 shmem2_base_path[], u32 chip_id)
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008338{
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00008339 int rc = 0;
Yaniv Rosnerb21a3422011-01-18 04:33:24 +00008340 u32 phy_ver;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008341 u8 phy_index;
8342 u32 ext_phy_type, ext_phy_config;
8343 DP(NETIF_MSG_LINK, "Begin common phy init\n");
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +00008344
Yaniv Rosnerb21a3422011-01-18 04:33:24 +00008345 /* Check if common init was already done */
8346 phy_ver = REG_RD(bp, shmem_base_path[0] +
8347 offsetof(struct shmem_region,
8348 port_mb[PORT_0].ext_phy_fw_version));
8349 if (phy_ver) {
8350 DP(NETIF_MSG_LINK, "Not doing common init; phy ver is 0x%x\n",
8351 phy_ver);
8352 return 0;
8353 }
8354
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008355 /* Read the ext_phy_type for arbitrary port(0) */
8356 for (phy_index = EXT_PHY1; phy_index < MAX_PHYS;
8357 phy_index++) {
8358 ext_phy_config = bnx2x_get_ext_phy_config(bp,
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008359 shmem_base_path[0],
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008360 phy_index, 0);
8361 ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008362 rc |= bnx2x_ext_phy_common_init(bp, shmem_base_path,
8363 shmem2_base_path,
8364 phy_index, ext_phy_type,
8365 chip_id);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008366 }
8367 return rc;
8368}
8369
8370u8 bnx2x_hw_lock_required(struct bnx2x *bp, u32 shmem_base, u32 shmem2_base)
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +00008371{
8372 u8 phy_index;
8373 struct bnx2x_phy phy;
8374 for (phy_index = INT_PHY; phy_index < MAX_PHYS;
8375 phy_index++) {
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008376 if (bnx2x_populate_phy(bp, phy_index, shmem_base, shmem2_base,
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +00008377 0, &phy) != 0) {
8378 DP(NETIF_MSG_LINK, "populate phy failed\n");
8379 return 0;
8380 }
8381
8382 if (phy.flags & FLAGS_HW_LOCK_REQUIRED)
8383 return 1;
8384 }
8385 return 0;
8386}
8387
8388u8 bnx2x_fan_failure_det_req(struct bnx2x *bp,
8389 u32 shmem_base,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008390 u32 shmem2_base,
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +00008391 u8 port)
8392{
8393 u8 phy_index, fan_failure_det_req = 0;
8394 struct bnx2x_phy phy;
8395 for (phy_index = EXT_PHY1; phy_index < MAX_PHYS;
8396 phy_index++) {
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008397 if (bnx2x_populate_phy(bp, phy_index, shmem_base, shmem2_base,
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +00008398 port, &phy)
8399 != 0) {
8400 DP(NETIF_MSG_LINK, "populate phy failed\n");
8401 return 0;
8402 }
8403 fan_failure_det_req |= (phy.flags &
8404 FLAGS_FAN_FAILURE_DET_REQ);
8405 }
8406 return fan_failure_det_req;
8407}
8408
8409void bnx2x_hw_reset_phy(struct link_params *params)
8410{
8411 u8 phy_index;
8412 for (phy_index = EXT_PHY1; phy_index < MAX_PHYS;
8413 phy_index++) {
8414 if (params->phy[phy_index].hw_reset) {
8415 params->phy[phy_index].hw_reset(
8416 &params->phy[phy_index],
8417 params);
8418 params->phy[phy_index] = phy_null;
8419 }
8420 }
8421}