blob: 4a1b5ee976b3d90b588118df7d862d98248dbfc3 [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
345u8 bnx2x_ets_strict(const struct link_params *params, const u8 strict_cos)
346{
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/******************************************************************/
388/* ETS section */
389/******************************************************************/
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
511static u8 bnx2x_emac_enable(struct link_params *params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000512 struct link_vars *vars, u8 lb)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700513{
514 struct bnx2x *bp = params->bp;
515 u8 port = params->port;
516 u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
517 u32 val;
518
519 DP(NETIF_MSG_LINK, "enabling EMAC\n");
520
521 /* enable emac and not bmac */
522 REG_WR(bp, NIG_REG_EGRESS_EMAC0_PORT + port*4, 1);
523
524 /* for paladium */
525 if (CHIP_REV_IS_EMUL(bp)) {
526 /* Use lane 1 (of lanes 0-3) */
527 REG_WR(bp, NIG_REG_XGXS_LANE_SEL_P0 + port*4, 1);
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000528 REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700529 }
530 /* for fpga */
531 else
532
533 if (CHIP_REV_IS_FPGA(bp)) {
534 /* Use lane 1 (of lanes 0-3) */
535 DP(NETIF_MSG_LINK, "bnx2x_emac_enable: Setting FPGA\n");
536
537 REG_WR(bp, NIG_REG_XGXS_LANE_SEL_P0 + port*4, 1);
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000538 REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700539 } else
540 /* ASIC */
541 if (vars->phy_flags & PHY_XGXS_FLAG) {
542 u32 ser_lane = ((params->lane_config &
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000543 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_MASK) >>
544 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_SHIFT);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700545
546 DP(NETIF_MSG_LINK, "XGXS\n");
547 /* select the master lanes (out of 0-3) */
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000548 REG_WR(bp, NIG_REG_XGXS_LANE_SEL_P0 + port*4, ser_lane);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700549 /* select XGXS */
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000550 REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700551
552 } else { /* SerDes */
553 DP(NETIF_MSG_LINK, "SerDes\n");
554 /* select SerDes */
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000555 REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700556 }
557
Eilon Greenstein811a2f22009-02-12 08:37:04 +0000558 bnx2x_bits_en(bp, emac_base + EMAC_REG_EMAC_RX_MODE,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000559 EMAC_RX_MODE_RESET);
Eilon Greenstein811a2f22009-02-12 08:37:04 +0000560 bnx2x_bits_en(bp, emac_base + EMAC_REG_EMAC_TX_MODE,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000561 EMAC_TX_MODE_RESET);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700562
563 if (CHIP_REV_IS_SLOW(bp)) {
564 /* config GMII mode */
565 val = REG_RD(bp, emac_base + EMAC_REG_EMAC_MODE);
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000566 EMAC_WR(bp, EMAC_REG_EMAC_MODE, (val | EMAC_MODE_PORT_GMII));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700567 } else { /* ASIC */
568 /* pause enable/disable */
569 bnx2x_bits_dis(bp, emac_base + EMAC_REG_EMAC_RX_MODE,
570 EMAC_RX_MODE_FLOW_EN);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700571
572 bnx2x_bits_dis(bp, emac_base + EMAC_REG_EMAC_TX_MODE,
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000573 (EMAC_TX_MODE_EXT_PAUSE_EN |
574 EMAC_TX_MODE_FLOW_EN));
575 if (!(params->feature_config_flags &
576 FEATURE_CONFIG_PFC_ENABLED)) {
577 if (vars->flow_ctrl & BNX2X_FLOW_CTRL_RX)
578 bnx2x_bits_en(bp, emac_base +
579 EMAC_REG_EMAC_RX_MODE,
580 EMAC_RX_MODE_FLOW_EN);
581
582 if (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX)
583 bnx2x_bits_en(bp, emac_base +
584 EMAC_REG_EMAC_TX_MODE,
585 (EMAC_TX_MODE_EXT_PAUSE_EN |
586 EMAC_TX_MODE_FLOW_EN));
587 } else
588 bnx2x_bits_en(bp, emac_base + EMAC_REG_EMAC_TX_MODE,
589 EMAC_TX_MODE_FLOW_EN);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700590 }
591
592 /* KEEP_VLAN_TAG, promiscuous */
593 val = REG_RD(bp, emac_base + EMAC_REG_EMAC_RX_MODE);
594 val |= EMAC_RX_MODE_KEEP_VLAN_TAG | EMAC_RX_MODE_PROMISCUOUS;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000595
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000596 /*
597 * Setting this bit causes MAC control frames (except for pause
598 * frames) to be passed on for processing. This setting has no
599 * affect on the operation of the pause frames. This bit effects
600 * all packets regardless of RX Parser packet sorting logic.
601 * Turn the PFC off to make sure we are in Xon state before
602 * enabling it.
603 */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000604 EMAC_WR(bp, EMAC_REG_RX_PFC_MODE, 0);
605 if (params->feature_config_flags & FEATURE_CONFIG_PFC_ENABLED) {
606 DP(NETIF_MSG_LINK, "PFC is enabled\n");
607 /* Enable PFC again */
608 EMAC_WR(bp, EMAC_REG_RX_PFC_MODE,
609 EMAC_REG_RX_PFC_MODE_RX_EN |
610 EMAC_REG_RX_PFC_MODE_TX_EN |
611 EMAC_REG_RX_PFC_MODE_PRIORITIES);
612
613 EMAC_WR(bp, EMAC_REG_RX_PFC_PARAM,
614 ((0x0101 <<
615 EMAC_REG_RX_PFC_PARAM_OPCODE_BITSHIFT) |
616 (0x00ff <<
617 EMAC_REG_RX_PFC_PARAM_PRIORITY_EN_BITSHIFT)));
618 val |= EMAC_RX_MODE_KEEP_MAC_CONTROL;
619 }
Eilon Greenstein3196a882008-08-13 15:58:49 -0700620 EMAC_WR(bp, EMAC_REG_EMAC_RX_MODE, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700621
622 /* Set Loopback */
623 val = REG_RD(bp, emac_base + EMAC_REG_EMAC_MODE);
624 if (lb)
625 val |= 0x810;
626 else
627 val &= ~0x810;
Eilon Greenstein3196a882008-08-13 15:58:49 -0700628 EMAC_WR(bp, EMAC_REG_EMAC_MODE, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700629
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +0000630 /* enable emac */
631 REG_WR(bp, NIG_REG_NIG_EMAC0_EN + port*4, 1);
632
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700633 /* enable emac for jumbo packets */
Eilon Greenstein3196a882008-08-13 15:58:49 -0700634 EMAC_WR(bp, EMAC_REG_EMAC_RX_MTU_SIZE,
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700635 (EMAC_RX_MTU_SIZE_JUMBO_ENA |
636 (ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD)));
637
638 /* strip CRC */
639 REG_WR(bp, NIG_REG_NIG_INGRESS_EMAC0_NO_CRC + port*4, 0x1);
640
641 /* disable the NIG in/out to the bmac */
642 REG_WR(bp, NIG_REG_BMAC0_IN_EN + port*4, 0x0);
643 REG_WR(bp, NIG_REG_BMAC0_PAUSE_OUT_EN + port*4, 0x0);
644 REG_WR(bp, NIG_REG_BMAC0_OUT_EN + port*4, 0x0);
645
646 /* enable the NIG in/out to the emac */
647 REG_WR(bp, NIG_REG_EMAC0_IN_EN + port*4, 0x1);
648 val = 0;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000649 if ((params->feature_config_flags &
650 FEATURE_CONFIG_PFC_ENABLED) ||
651 (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX))
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700652 val = 1;
653
654 REG_WR(bp, NIG_REG_EMAC0_PAUSE_OUT_EN + port*4, val);
655 REG_WR(bp, NIG_REG_EGRESS_EMAC0_OUT_EN + port*4, 0x1);
656
657 if (CHIP_REV_IS_EMUL(bp)) {
658 /* take the BigMac out of reset */
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000659 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
660 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700661
662 /* enable access for bmac registers */
663 REG_WR(bp, NIG_REG_BMAC0_REGS_OUT_EN + port*4, 0x1);
Eilon Greenstein6f654972009-08-12 08:23:51 +0000664 } else
665 REG_WR(bp, NIG_REG_BMAC0_REGS_OUT_EN + port*4, 0x0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700666
667 vars->mac_type = MAC_TYPE_EMAC;
668 return 0;
669}
670
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000671static void bnx2x_update_pfc_bmac1(struct link_params *params,
672 struct link_vars *vars)
673{
674 u32 wb_data[2];
675 struct bnx2x *bp = params->bp;
676 u32 bmac_addr = params->port ? NIG_REG_INGRESS_BMAC1_MEM :
677 NIG_REG_INGRESS_BMAC0_MEM;
678
679 u32 val = 0x14;
680 if ((!(params->feature_config_flags &
681 FEATURE_CONFIG_PFC_ENABLED)) &&
682 (vars->flow_ctrl & BNX2X_FLOW_CTRL_RX))
683 /* Enable BigMAC to react on received Pause packets */
684 val |= (1<<5);
685 wb_data[0] = val;
686 wb_data[1] = 0;
687 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_RX_CONTROL, wb_data, 2);
688
689 /* tx control */
690 val = 0xc0;
691 if (!(params->feature_config_flags &
692 FEATURE_CONFIG_PFC_ENABLED) &&
693 (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX))
694 val |= 0x800000;
695 wb_data[0] = val;
696 wb_data[1] = 0;
697 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_TX_CONTROL, wb_data, 2);
698}
699
700static void bnx2x_update_pfc_bmac2(struct link_params *params,
701 struct link_vars *vars,
702 u8 is_lb)
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000703{
704 /*
705 * Set rx control: Strip CRC and enable BigMAC to relay
706 * control packets to the system as well
707 */
708 u32 wb_data[2];
709 struct bnx2x *bp = params->bp;
710 u32 bmac_addr = params->port ? NIG_REG_INGRESS_BMAC1_MEM :
711 NIG_REG_INGRESS_BMAC0_MEM;
712 u32 val = 0x14;
713
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000714 if ((!(params->feature_config_flags &
715 FEATURE_CONFIG_PFC_ENABLED)) &&
716 (vars->flow_ctrl & BNX2X_FLOW_CTRL_RX))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000717 /* Enable BigMAC to react on received Pause packets */
718 val |= (1<<5);
719 wb_data[0] = val;
720 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000721 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_RX_CONTROL, wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000722 udelay(30);
723
724 /* Tx control */
725 val = 0xc0;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000726 if (!(params->feature_config_flags &
727 FEATURE_CONFIG_PFC_ENABLED) &&
728 (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000729 val |= 0x800000;
730 wb_data[0] = val;
731 wb_data[1] = 0;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000732 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_TX_CONTROL, wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000733
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000734 if (params->feature_config_flags & FEATURE_CONFIG_PFC_ENABLED) {
735 DP(NETIF_MSG_LINK, "PFC is enabled\n");
736 /* Enable PFC RX & TX & STATS and set 8 COS */
737 wb_data[0] = 0x0;
738 wb_data[0] |= (1<<0); /* RX */
739 wb_data[0] |= (1<<1); /* TX */
740 wb_data[0] |= (1<<2); /* Force initial Xon */
741 wb_data[0] |= (1<<3); /* 8 cos */
742 wb_data[0] |= (1<<5); /* STATS */
743 wb_data[1] = 0;
744 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_PFC_CONTROL,
745 wb_data, 2);
746 /* Clear the force Xon */
747 wb_data[0] &= ~(1<<2);
748 } else {
749 DP(NETIF_MSG_LINK, "PFC is disabled\n");
750 /* disable PFC RX & TX & STATS and set 8 COS */
751 wb_data[0] = 0x8;
752 wb_data[1] = 0;
753 }
754
755 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_PFC_CONTROL, wb_data, 2);
756
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000757 /*
758 * Set Time (based unit is 512 bit time) between automatic
759 * re-sending of PP packets amd enable automatic re-send of
760 * Per-Priroity Packet as long as pp_gen is asserted and
761 * pp_disable is low.
762 */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000763 val = 0x8000;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000764 if (params->feature_config_flags & FEATURE_CONFIG_PFC_ENABLED)
765 val |= (1<<16); /* enable automatic re-send */
766
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000767 wb_data[0] = val;
768 wb_data[1] = 0;
769 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_TX_PAUSE_CONTROL,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000770 wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000771
772 /* mac control */
773 val = 0x3; /* Enable RX and TX */
774 if (is_lb) {
775 val |= 0x4; /* Local loopback */
776 DP(NETIF_MSG_LINK, "enable bmac loopback\n");
777 }
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000778 /* When PFC enabled, Pass pause frames towards the NIG. */
779 if (params->feature_config_flags & FEATURE_CONFIG_PFC_ENABLED)
780 val |= ((1<<6)|(1<<5));
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000781
782 wb_data[0] = val;
783 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000784 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_BMAC_CONTROL, wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000785}
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700786
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000787static void bnx2x_update_pfc_brb(struct link_params *params,
788 struct link_vars *vars,
789 struct bnx2x_nig_brb_pfc_port_params *pfc_params)
790{
791 struct bnx2x *bp = params->bp;
792 int set_pfc = params->feature_config_flags &
793 FEATURE_CONFIG_PFC_ENABLED;
794
795 /* default - pause configuration */
796 u32 pause_xoff_th = PFC_BRB_MAC_PAUSE_XOFF_THRESHOLD_PAUSEABLE;
797 u32 pause_xon_th = PFC_BRB_MAC_PAUSE_XON_THRESHOLD_PAUSEABLE;
798 u32 full_xoff_th = PFC_BRB_MAC_FULL_XOFF_THRESHOLD_PAUSEABLE;
799 u32 full_xon_th = PFC_BRB_MAC_FULL_XON_THRESHOLD_PAUSEABLE;
800
801 if (set_pfc && pfc_params)
802 /* First COS */
803 if (!pfc_params->cos0_pauseable) {
804 pause_xoff_th =
805 PFC_BRB_MAC_PAUSE_XOFF_THRESHOLD_NON_PAUSEABLE;
806 pause_xon_th =
807 PFC_BRB_MAC_PAUSE_XON_THRESHOLD_NON_PAUSEABLE;
808 full_xoff_th =
809 PFC_BRB_MAC_FULL_XOFF_THRESHOLD_NON_PAUSEABLE;
810 full_xon_th =
811 PFC_BRB_MAC_FULL_XON_THRESHOLD_NON_PAUSEABLE;
812 }
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000813 /*
814 * The number of free blocks below which the pause signal to class 0
815 * of MAC #n is asserted. n=0,1
816 */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000817 REG_WR(bp, BRB1_REG_PAUSE_0_XOFF_THRESHOLD_0 , pause_xoff_th);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000818 /*
819 * The number of free blocks above which the pause signal to class 0
820 * of MAC #n is de-asserted. n=0,1
821 */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000822 REG_WR(bp, BRB1_REG_PAUSE_0_XON_THRESHOLD_0 , pause_xon_th);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000823 /*
824 * The number of free blocks below which the full signal to class 0
825 * of MAC #n is asserted. n=0,1
826 */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000827 REG_WR(bp, BRB1_REG_FULL_0_XOFF_THRESHOLD_0 , full_xoff_th);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000828 /*
829 * The number of free blocks above which the full signal to class 0
830 * of MAC #n is de-asserted. n=0,1
831 */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000832 REG_WR(bp, BRB1_REG_FULL_0_XON_THRESHOLD_0 , full_xon_th);
833
834 if (set_pfc && pfc_params) {
835 /* Second COS */
836 if (pfc_params->cos1_pauseable) {
837 pause_xoff_th =
838 PFC_BRB_MAC_PAUSE_XOFF_THRESHOLD_PAUSEABLE;
839 pause_xon_th =
840 PFC_BRB_MAC_PAUSE_XON_THRESHOLD_PAUSEABLE;
841 full_xoff_th =
842 PFC_BRB_MAC_FULL_XOFF_THRESHOLD_PAUSEABLE;
843 full_xon_th =
844 PFC_BRB_MAC_FULL_XON_THRESHOLD_PAUSEABLE;
845 } else {
846 pause_xoff_th =
847 PFC_BRB_MAC_PAUSE_XOFF_THRESHOLD_NON_PAUSEABLE;
848 pause_xon_th =
849 PFC_BRB_MAC_PAUSE_XON_THRESHOLD_NON_PAUSEABLE;
850 full_xoff_th =
851 PFC_BRB_MAC_FULL_XOFF_THRESHOLD_NON_PAUSEABLE;
852 full_xon_th =
853 PFC_BRB_MAC_FULL_XON_THRESHOLD_NON_PAUSEABLE;
854 }
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000855 /*
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000856 * The number of free blocks below which the pause signal to
857 * class 1 of MAC #n is asserted. n=0,1
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000858 */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000859 REG_WR(bp, BRB1_REG_PAUSE_1_XOFF_THRESHOLD_0, pause_xoff_th);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000860 /*
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000861 * The number of free blocks above which the pause signal to
862 * class 1 of MAC #n is de-asserted. n=0,1
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000863 */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000864 REG_WR(bp, BRB1_REG_PAUSE_1_XON_THRESHOLD_0, pause_xon_th);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000865 /*
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000866 * The number of free blocks below which the full signal to
867 * class 1 of MAC #n is asserted. n=0,1
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000868 */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000869 REG_WR(bp, BRB1_REG_FULL_1_XOFF_THRESHOLD_0, full_xoff_th);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000870 /*
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000871 * The number of free blocks above which the full signal to
872 * class 1 of MAC #n is de-asserted. n=0,1
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000873 */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000874 REG_WR(bp, BRB1_REG_FULL_1_XON_THRESHOLD_0, full_xon_th);
875 }
876}
877
878static void bnx2x_update_pfc_nig(struct link_params *params,
879 struct link_vars *vars,
880 struct bnx2x_nig_brb_pfc_port_params *nig_params)
881{
882 u32 xcm_mask = 0, ppp_enable = 0, pause_enable = 0, llfc_out_en = 0;
883 u32 llfc_enable = 0, xcm0_out_en = 0, p0_hwpfc_enable = 0;
884 u32 pkt_priority_to_cos = 0;
885 u32 val;
886 struct bnx2x *bp = params->bp;
887 int port = params->port;
888 int set_pfc = params->feature_config_flags &
889 FEATURE_CONFIG_PFC_ENABLED;
890 DP(NETIF_MSG_LINK, "updating pfc nig parameters\n");
891
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000892 /*
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000893 * When NIG_LLH0_XCM_MASK_REG_LLHX_XCM_MASK_BCN bit is set
894 * MAC control frames (that are not pause packets)
895 * will be forwarded to the XCM.
896 */
897 xcm_mask = REG_RD(bp,
898 port ? NIG_REG_LLH1_XCM_MASK :
899 NIG_REG_LLH0_XCM_MASK);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000900 /*
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000901 * nig params will override non PFC params, since it's possible to
902 * do transition from PFC to SAFC
903 */
904 if (set_pfc) {
905 pause_enable = 0;
906 llfc_out_en = 0;
907 llfc_enable = 0;
908 ppp_enable = 1;
909 xcm_mask &= ~(port ? NIG_LLH1_XCM_MASK_REG_LLH1_XCM_MASK_BCN :
910 NIG_LLH0_XCM_MASK_REG_LLH0_XCM_MASK_BCN);
911 xcm0_out_en = 0;
912 p0_hwpfc_enable = 1;
913 } else {
914 if (nig_params) {
915 llfc_out_en = nig_params->llfc_out_en;
916 llfc_enable = nig_params->llfc_enable;
917 pause_enable = nig_params->pause_enable;
918 } else /*defaul non PFC mode - PAUSE */
919 pause_enable = 1;
920
921 xcm_mask |= (port ? NIG_LLH1_XCM_MASK_REG_LLH1_XCM_MASK_BCN :
922 NIG_LLH0_XCM_MASK_REG_LLH0_XCM_MASK_BCN);
923 xcm0_out_en = 1;
924 }
925
926 REG_WR(bp, port ? NIG_REG_LLFC_OUT_EN_1 :
927 NIG_REG_LLFC_OUT_EN_0, llfc_out_en);
928 REG_WR(bp, port ? NIG_REG_LLFC_ENABLE_1 :
929 NIG_REG_LLFC_ENABLE_0, llfc_enable);
930 REG_WR(bp, port ? NIG_REG_PAUSE_ENABLE_1 :
931 NIG_REG_PAUSE_ENABLE_0, pause_enable);
932
933 REG_WR(bp, port ? NIG_REG_PPP_ENABLE_1 :
934 NIG_REG_PPP_ENABLE_0, ppp_enable);
935
936 REG_WR(bp, port ? NIG_REG_LLH1_XCM_MASK :
937 NIG_REG_LLH0_XCM_MASK, xcm_mask);
938
939 REG_WR(bp, NIG_REG_LLFC_EGRESS_SRC_ENABLE_0, 0x7);
940
941 /* output enable for RX_XCM # IF */
942 REG_WR(bp, NIG_REG_XCM0_OUT_EN, xcm0_out_en);
943
944 /* HW PFC TX enable */
945 REG_WR(bp, NIG_REG_P0_HWPFC_ENABLE, p0_hwpfc_enable);
946
947 /* 0x2 = BMAC, 0x1= EMAC */
948 switch (vars->mac_type) {
949 case MAC_TYPE_EMAC:
950 val = 1;
951 break;
952 case MAC_TYPE_BMAC:
953 val = 0;
954 break;
955 default:
956 val = 0;
957 break;
958 }
959 REG_WR(bp, NIG_REG_EGRESS_EMAC0_PORT, val);
960
961 if (nig_params) {
962 pkt_priority_to_cos = nig_params->pkt_priority_to_cos;
963
964 REG_WR(bp, port ? NIG_REG_P1_RX_COS0_PRIORITY_MASK :
965 NIG_REG_P0_RX_COS0_PRIORITY_MASK,
966 nig_params->rx_cos0_priority_mask);
967
968 REG_WR(bp, port ? NIG_REG_P1_RX_COS1_PRIORITY_MASK :
969 NIG_REG_P0_RX_COS1_PRIORITY_MASK,
970 nig_params->rx_cos1_priority_mask);
971
972 REG_WR(bp, port ? NIG_REG_LLFC_HIGH_PRIORITY_CLASSES_1 :
973 NIG_REG_LLFC_HIGH_PRIORITY_CLASSES_0,
974 nig_params->llfc_high_priority_classes);
975
976 REG_WR(bp, port ? NIG_REG_LLFC_LOW_PRIORITY_CLASSES_1 :
977 NIG_REG_LLFC_LOW_PRIORITY_CLASSES_0,
978 nig_params->llfc_low_priority_classes);
979 }
980 REG_WR(bp, port ? NIG_REG_P1_PKT_PRIORITY_TO_COS :
981 NIG_REG_P0_PKT_PRIORITY_TO_COS,
982 pkt_priority_to_cos);
983}
984
985
986void bnx2x_update_pfc(struct link_params *params,
987 struct link_vars *vars,
988 struct bnx2x_nig_brb_pfc_port_params *pfc_params)
989{
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000990 /*
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000991 * The PFC and pause are orthogonal to one another, meaning when
992 * PFC is enabled, the pause are disabled, and when PFC is
993 * disabled, pause are set according to the pause result.
994 */
995 u32 val;
996 struct bnx2x *bp = params->bp;
997
998 /* update NIG params */
999 bnx2x_update_pfc_nig(params, vars, pfc_params);
1000
1001 /* update BRB params */
1002 bnx2x_update_pfc_brb(params, vars, pfc_params);
1003
1004 if (!vars->link_up)
1005 return;
1006
1007 val = REG_RD(bp, MISC_REG_RESET_REG_2);
1008 if ((val & (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << params->port))
1009 == 0) {
1010 DP(NETIF_MSG_LINK, "About to update PFC in EMAC\n");
1011 bnx2x_emac_enable(params, vars, 0);
1012 return;
1013 }
1014
1015 DP(NETIF_MSG_LINK, "About to update PFC in BMAC\n");
1016 if (CHIP_IS_E2(bp))
1017 bnx2x_update_pfc_bmac2(params, vars, 0);
1018 else
1019 bnx2x_update_pfc_bmac1(params, vars);
1020
1021 val = 0;
1022 if ((params->feature_config_flags &
1023 FEATURE_CONFIG_PFC_ENABLED) ||
1024 (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX))
1025 val = 1;
1026 REG_WR(bp, NIG_REG_BMAC0_PAUSE_OUT_EN + params->port*4, val);
1027}
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001028
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001029static u8 bnx2x_bmac1_enable(struct link_params *params,
1030 struct link_vars *vars,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001031 u8 is_lb)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001032{
1033 struct bnx2x *bp = params->bp;
1034 u8 port = params->port;
1035 u32 bmac_addr = port ? NIG_REG_INGRESS_BMAC1_MEM :
1036 NIG_REG_INGRESS_BMAC0_MEM;
1037 u32 wb_data[2];
1038 u32 val;
1039
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001040 DP(NETIF_MSG_LINK, "Enabling BigMAC1\n");
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001041
1042 /* XGXS control */
1043 wb_data[0] = 0x3c;
1044 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001045 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_BMAC_XGXS_CONTROL,
1046 wb_data, 2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001047
1048 /* tx MAC SA */
1049 wb_data[0] = ((params->mac_addr[2] << 24) |
1050 (params->mac_addr[3] << 16) |
1051 (params->mac_addr[4] << 8) |
1052 params->mac_addr[5]);
1053 wb_data[1] = ((params->mac_addr[0] << 8) |
1054 params->mac_addr[1]);
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001055 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_TX_SOURCE_ADDR, wb_data, 2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001056
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001057 /* mac control */
1058 val = 0x3;
1059 if (is_lb) {
1060 val |= 0x4;
1061 DP(NETIF_MSG_LINK, "enable bmac loopback\n");
1062 }
1063 wb_data[0] = val;
1064 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001065 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_BMAC_CONTROL, wb_data, 2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001066
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001067 /* set rx mtu */
1068 wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD;
1069 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001070 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_RX_MAX_SIZE, wb_data, 2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001071
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001072 bnx2x_update_pfc_bmac1(params, vars);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001073
1074 /* set tx mtu */
1075 wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD;
1076 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001077 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_TX_MAX_SIZE, wb_data, 2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001078
1079 /* set cnt max size */
1080 wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD;
1081 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001082 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_CNT_MAX_SIZE, wb_data, 2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001083
1084 /* configure safc */
1085 wb_data[0] = 0x1000200;
1086 wb_data[1] = 0;
1087 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_RX_LLFC_MSG_FLDS,
1088 wb_data, 2);
1089 /* fix for emulation */
1090 if (CHIP_REV_IS_EMUL(bp)) {
1091 wb_data[0] = 0xf000;
1092 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001093 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_TX_PAUSE_THRESHOLD,
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001094 wb_data, 2);
1095 }
1096
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001097
1098 return 0;
1099}
1100
1101static u8 bnx2x_bmac2_enable(struct link_params *params,
1102 struct link_vars *vars,
1103 u8 is_lb)
1104{
1105 struct bnx2x *bp = params->bp;
1106 u8 port = params->port;
1107 u32 bmac_addr = port ? NIG_REG_INGRESS_BMAC1_MEM :
1108 NIG_REG_INGRESS_BMAC0_MEM;
1109 u32 wb_data[2];
1110
1111 DP(NETIF_MSG_LINK, "Enabling BigMAC2\n");
1112
1113 wb_data[0] = 0;
1114 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001115 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_BMAC_CONTROL, wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001116 udelay(30);
1117
1118 /* XGXS control: Reset phy HW, MDIO registers, PHY PLL and BMAC */
1119 wb_data[0] = 0x3c;
1120 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001121 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_BMAC_XGXS_CONTROL,
1122 wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001123
1124 udelay(30);
1125
1126 /* tx MAC SA */
1127 wb_data[0] = ((params->mac_addr[2] << 24) |
1128 (params->mac_addr[3] << 16) |
1129 (params->mac_addr[4] << 8) |
1130 params->mac_addr[5]);
1131 wb_data[1] = ((params->mac_addr[0] << 8) |
1132 params->mac_addr[1]);
1133 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_TX_SOURCE_ADDR,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001134 wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001135
1136 udelay(30);
1137
1138 /* Configure SAFC */
1139 wb_data[0] = 0x1000200;
1140 wb_data[1] = 0;
1141 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_RX_LLFC_MSG_FLDS,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001142 wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001143 udelay(30);
1144
1145 /* set rx mtu */
1146 wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD;
1147 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001148 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_RX_MAX_SIZE, wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001149 udelay(30);
1150
1151 /* set tx mtu */
1152 wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD;
1153 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001154 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_TX_MAX_SIZE, wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001155 udelay(30);
1156 /* set cnt max size */
1157 wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD - 2;
1158 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001159 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_CNT_MAX_SIZE, wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001160 udelay(30);
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001161 bnx2x_update_pfc_bmac2(params, vars, is_lb);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001162
1163 return 0;
1164}
1165
stephen hemminger8d962862010-10-21 07:50:56 +00001166static u8 bnx2x_bmac_enable(struct link_params *params,
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001167 struct link_vars *vars,
1168 u8 is_lb)
1169{
1170 u8 rc, port = params->port;
1171 struct bnx2x *bp = params->bp;
1172 u32 val;
1173 /* reset and unreset the BigMac */
1174 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001175 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port));
Yaniv Rosner1d9c05d2010-11-01 05:32:25 +00001176 msleep(1);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001177
1178 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001179 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port));
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001180
1181 /* enable access for bmac registers */
1182 REG_WR(bp, NIG_REG_BMAC0_REGS_OUT_EN + port*4, 0x1);
1183
1184 /* Enable BMAC according to BMAC type*/
1185 if (CHIP_IS_E2(bp))
1186 rc = bnx2x_bmac2_enable(params, vars, is_lb);
1187 else
1188 rc = bnx2x_bmac1_enable(params, vars, is_lb);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001189 REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 0x1);
1190 REG_WR(bp, NIG_REG_XGXS_LANE_SEL_P0 + port*4, 0x0);
1191 REG_WR(bp, NIG_REG_EGRESS_EMAC0_PORT + port*4, 0x0);
1192 val = 0;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001193 if ((params->feature_config_flags &
1194 FEATURE_CONFIG_PFC_ENABLED) ||
1195 (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX))
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001196 val = 1;
1197 REG_WR(bp, NIG_REG_BMAC0_PAUSE_OUT_EN + port*4, val);
1198 REG_WR(bp, NIG_REG_EGRESS_EMAC0_OUT_EN + port*4, 0x0);
1199 REG_WR(bp, NIG_REG_EMAC0_IN_EN + port*4, 0x0);
1200 REG_WR(bp, NIG_REG_EMAC0_PAUSE_OUT_EN + port*4, 0x0);
1201 REG_WR(bp, NIG_REG_BMAC0_IN_EN + port*4, 0x1);
1202 REG_WR(bp, NIG_REG_BMAC0_OUT_EN + port*4, 0x1);
1203
1204 vars->mac_type = MAC_TYPE_BMAC;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001205 return rc;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001206}
1207
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001208
1209static void bnx2x_update_mng(struct link_params *params, u32 link_status)
1210{
1211 struct bnx2x *bp = params->bp;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00001212
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001213 REG_WR(bp, params->shmem_base +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001214 offsetof(struct shmem_region,
1215 port_mb[params->port].link_status), link_status);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001216}
1217
1218static void bnx2x_bmac_rx_disable(struct bnx2x *bp, u8 port)
1219{
1220 u32 bmac_addr = port ? NIG_REG_INGRESS_BMAC1_MEM :
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001221 NIG_REG_INGRESS_BMAC0_MEM;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001222 u32 wb_data[2];
Eilon Greenstein3196a882008-08-13 15:58:49 -07001223 u32 nig_bmac_enable = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port*4);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001224
1225 /* Only if the bmac is out of reset */
1226 if (REG_RD(bp, MISC_REG_RESET_REG_2) &
1227 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port) &&
1228 nig_bmac_enable) {
1229
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001230 if (CHIP_IS_E2(bp)) {
1231 /* Clear Rx Enable bit in BMAC_CONTROL register */
1232 REG_RD_DMAE(bp, bmac_addr +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001233 BIGMAC2_REGISTER_BMAC_CONTROL,
1234 wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001235 wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
1236 REG_WR_DMAE(bp, bmac_addr +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001237 BIGMAC2_REGISTER_BMAC_CONTROL,
1238 wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001239 } else {
1240 /* Clear Rx Enable bit in BMAC_CONTROL register */
1241 REG_RD_DMAE(bp, bmac_addr +
1242 BIGMAC_REGISTER_BMAC_CONTROL,
1243 wb_data, 2);
1244 wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
1245 REG_WR_DMAE(bp, bmac_addr +
1246 BIGMAC_REGISTER_BMAC_CONTROL,
1247 wb_data, 2);
1248 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001249 msleep(1);
1250 }
1251}
1252
1253static u8 bnx2x_pbf_update(struct link_params *params, u32 flow_ctrl,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001254 u32 line_speed)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001255{
1256 struct bnx2x *bp = params->bp;
1257 u8 port = params->port;
1258 u32 init_crd, crd;
1259 u32 count = 1000;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001260
1261 /* disable port */
1262 REG_WR(bp, PBF_REG_DISABLE_NEW_TASK_PROC_P0 + port*4, 0x1);
1263
1264 /* wait for init credit */
1265 init_crd = REG_RD(bp, PBF_REG_P0_INIT_CRD + port*4);
1266 crd = REG_RD(bp, PBF_REG_P0_CREDIT + port*8);
1267 DP(NETIF_MSG_LINK, "init_crd 0x%x crd 0x%x\n", init_crd, crd);
1268
1269 while ((init_crd != crd) && count) {
1270 msleep(5);
1271
1272 crd = REG_RD(bp, PBF_REG_P0_CREDIT + port*8);
1273 count--;
1274 }
1275 crd = REG_RD(bp, PBF_REG_P0_CREDIT + port*8);
1276 if (init_crd != crd) {
1277 DP(NETIF_MSG_LINK, "BUG! init_crd 0x%x != crd 0x%x\n",
1278 init_crd, crd);
1279 return -EINVAL;
1280 }
1281
David S. Millerc0700f92008-12-16 23:53:20 -08001282 if (flow_ctrl & BNX2X_FLOW_CTRL_RX ||
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07001283 line_speed == SPEED_10 ||
1284 line_speed == SPEED_100 ||
1285 line_speed == SPEED_1000 ||
1286 line_speed == SPEED_2500) {
1287 REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 1);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001288 /* update threshold */
1289 REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, 0);
1290 /* update init credit */
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001291 init_crd = 778; /* (800-18-4) */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001292
1293 } else {
1294 u32 thresh = (ETH_MAX_JUMBO_PACKET_SIZE +
1295 ETH_OVREHEAD)/16;
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07001296 REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001297 /* update threshold */
1298 REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, thresh);
1299 /* update init credit */
1300 switch (line_speed) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001301 case SPEED_10000:
1302 init_crd = thresh + 553 - 22;
1303 break;
1304
1305 case SPEED_12000:
1306 init_crd = thresh + 664 - 22;
1307 break;
1308
1309 case SPEED_13000:
1310 init_crd = thresh + 742 - 22;
1311 break;
1312
1313 case SPEED_16000:
1314 init_crd = thresh + 778 - 22;
1315 break;
1316 default:
1317 DP(NETIF_MSG_LINK, "Invalid line_speed 0x%x\n",
1318 line_speed);
1319 return -EINVAL;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001320 }
1321 }
1322 REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, init_crd);
1323 DP(NETIF_MSG_LINK, "PBF updated to speed %d credit %d\n",
1324 line_speed, init_crd);
1325
1326 /* probe the credit changes */
1327 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0x1);
1328 msleep(5);
1329 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0x0);
1330
1331 /* enable port */
1332 REG_WR(bp, PBF_REG_DISABLE_NEW_TASK_PROC_P0 + port*4, 0x0);
1333 return 0;
1334}
1335
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00001336/*
1337 * get_emac_base
1338 *
1339 * @param cb
1340 * @param mdc_mdio_access
1341 * @param port
1342 *
1343 * @return u32
1344 *
1345 * This function selects the MDC/MDIO access (through emac0 or
1346 * emac1) depend on the mdc_mdio_access, port, port swapped. Each
1347 * phy has a default access mode, which could also be overridden
1348 * by nvram configuration. This parameter, whether this is the
1349 * default phy configuration, or the nvram overrun
1350 * configuration, is passed here as mdc_mdio_access and selects
1351 * the emac_base for the CL45 read/writes operations
1352 */
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00001353static u32 bnx2x_get_emac_base(struct bnx2x *bp,
1354 u32 mdc_mdio_access, u8 port)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001355{
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00001356 u32 emac_base = 0;
1357 switch (mdc_mdio_access) {
1358 case SHARED_HW_CFG_MDC_MDIO_ACCESS1_PHY_TYPE:
1359 break;
1360 case SHARED_HW_CFG_MDC_MDIO_ACCESS1_EMAC0:
1361 if (REG_RD(bp, NIG_REG_PORT_SWAP))
1362 emac_base = GRCBASE_EMAC1;
1363 else
1364 emac_base = GRCBASE_EMAC0;
1365 break;
1366 case SHARED_HW_CFG_MDC_MDIO_ACCESS1_EMAC1:
Eilon Greenstein589abe32009-02-12 08:36:55 +00001367 if (REG_RD(bp, NIG_REG_PORT_SWAP))
1368 emac_base = GRCBASE_EMAC0;
1369 else
1370 emac_base = GRCBASE_EMAC1;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001371 break;
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00001372 case SHARED_HW_CFG_MDC_MDIO_ACCESS1_BOTH:
1373 emac_base = (port) ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
1374 break;
1375 case SHARED_HW_CFG_MDC_MDIO_ACCESS1_SWAPPED:
Eilon Greenstein6378c022008-08-13 15:59:25 -07001376 emac_base = (port) ? GRCBASE_EMAC0 : GRCBASE_EMAC1;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001377 break;
1378 default:
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001379 break;
1380 }
1381 return emac_base;
1382
1383}
1384
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00001385/******************************************************************/
1386/* CL45 access functions */
1387/******************************************************************/
Yaniv Rosner65a001b2011-01-31 04:22:03 +00001388static u8 bnx2x_cl45_write(struct bnx2x *bp, struct bnx2x_phy *phy,
1389 u8 devad, u16 reg, u16 val)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001390{
1391 u32 tmp, saved_mode;
1392 u8 i, rc = 0;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00001393 /*
1394 * Set clause 45 mode, slow down the MDIO clock to 2.5MHz
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001395 * (a value of 49==0x31) and make sure that the AUTO poll is off
1396 */
Eilon Greenstein589abe32009-02-12 08:36:55 +00001397
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001398 saved_mode = REG_RD(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001399 tmp = saved_mode & ~(EMAC_MDIO_MODE_AUTO_POLL |
1400 EMAC_MDIO_MODE_CLOCK_CNT);
1401 tmp |= (EMAC_MDIO_MODE_CLAUSE_45 |
1402 (49 << EMAC_MDIO_MODE_CLOCK_CNT_BITSHIFT));
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001403 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE, tmp);
1404 REG_RD(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001405 udelay(40);
1406
1407 /* address */
1408
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001409 tmp = ((phy->addr << 21) | (devad << 16) | reg |
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001410 EMAC_MDIO_COMM_COMMAND_ADDRESS |
1411 EMAC_MDIO_COMM_START_BUSY);
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001412 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, tmp);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001413
1414 for (i = 0; i < 50; i++) {
1415 udelay(10);
1416
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001417 tmp = REG_RD(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001418 if (!(tmp & EMAC_MDIO_COMM_START_BUSY)) {
1419 udelay(5);
1420 break;
1421 }
1422 }
1423 if (tmp & EMAC_MDIO_COMM_START_BUSY) {
1424 DP(NETIF_MSG_LINK, "write phy register failed\n");
Yaniv Rosner6d870c32011-01-31 04:22:20 +00001425 netdev_err(bp->dev, "MDC/MDIO access timeout\n");
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001426 rc = -EFAULT;
1427 } else {
1428 /* data */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001429 tmp = ((phy->addr << 21) | (devad << 16) | val |
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001430 EMAC_MDIO_COMM_COMMAND_WRITE_45 |
1431 EMAC_MDIO_COMM_START_BUSY);
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001432 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, tmp);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001433
1434 for (i = 0; i < 50; i++) {
1435 udelay(10);
1436
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001437 tmp = REG_RD(bp, phy->mdio_ctrl +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001438 EMAC_REG_EMAC_MDIO_COMM);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001439 if (!(tmp & EMAC_MDIO_COMM_START_BUSY)) {
1440 udelay(5);
1441 break;
1442 }
1443 }
1444 if (tmp & EMAC_MDIO_COMM_START_BUSY) {
1445 DP(NETIF_MSG_LINK, "write phy register failed\n");
Yaniv Rosner6d870c32011-01-31 04:22:20 +00001446 netdev_err(bp->dev, "MDC/MDIO access timeout\n");
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001447 rc = -EFAULT;
1448 }
1449 }
1450
1451 /* Restore the saved mode */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001452 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE, saved_mode);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001453
1454 return rc;
1455}
1456
Yaniv Rosner65a001b2011-01-31 04:22:03 +00001457static u8 bnx2x_cl45_read(struct bnx2x *bp, struct bnx2x_phy *phy,
1458 u8 devad, u16 reg, u16 *ret_val)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001459{
1460 u32 val, saved_mode;
1461 u16 i;
1462 u8 rc = 0;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00001463 /*
1464 * Set clause 45 mode, slow down the MDIO clock to 2.5MHz
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001465 * (a value of 49==0x31) and make sure that the AUTO poll is off
1466 */
Eilon Greenstein589abe32009-02-12 08:36:55 +00001467
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001468 saved_mode = REG_RD(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE);
1469 val = saved_mode & ~((EMAC_MDIO_MODE_AUTO_POLL |
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001470 EMAC_MDIO_MODE_CLOCK_CNT));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001471 val |= (EMAC_MDIO_MODE_CLAUSE_45 |
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00001472 (49L << EMAC_MDIO_MODE_CLOCK_CNT_BITSHIFT));
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001473 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE, val);
1474 REG_RD(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001475 udelay(40);
1476
1477 /* address */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001478 val = ((phy->addr << 21) | (devad << 16) | reg |
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001479 EMAC_MDIO_COMM_COMMAND_ADDRESS |
1480 EMAC_MDIO_COMM_START_BUSY);
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001481 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001482
1483 for (i = 0; i < 50; i++) {
1484 udelay(10);
1485
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001486 val = REG_RD(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001487 if (!(val & EMAC_MDIO_COMM_START_BUSY)) {
1488 udelay(5);
1489 break;
1490 }
1491 }
1492 if (val & EMAC_MDIO_COMM_START_BUSY) {
1493 DP(NETIF_MSG_LINK, "read phy register failed\n");
Yaniv Rosner6d870c32011-01-31 04:22:20 +00001494 netdev_err(bp->dev, "MDC/MDIO access timeout\n");
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001495 *ret_val = 0;
1496 rc = -EFAULT;
1497
1498 } else {
1499 /* data */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001500 val = ((phy->addr << 21) | (devad << 16) |
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001501 EMAC_MDIO_COMM_COMMAND_READ_45 |
1502 EMAC_MDIO_COMM_START_BUSY);
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001503 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001504
1505 for (i = 0; i < 50; i++) {
1506 udelay(10);
1507
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001508 val = REG_RD(bp, phy->mdio_ctrl +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001509 EMAC_REG_EMAC_MDIO_COMM);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001510 if (!(val & EMAC_MDIO_COMM_START_BUSY)) {
1511 *ret_val = (u16)(val & EMAC_MDIO_COMM_DATA);
1512 break;
1513 }
1514 }
1515 if (val & EMAC_MDIO_COMM_START_BUSY) {
1516 DP(NETIF_MSG_LINK, "read phy register failed\n");
Yaniv Rosner6d870c32011-01-31 04:22:20 +00001517 netdev_err(bp->dev, "MDC/MDIO access timeout\n");
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001518 *ret_val = 0;
1519 rc = -EFAULT;
1520 }
1521 }
1522
1523 /* Restore the saved mode */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001524 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE, saved_mode);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001525
1526 return rc;
1527}
1528
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001529u8 bnx2x_phy_read(struct link_params *params, u8 phy_addr,
1530 u8 devad, u16 reg, u16 *ret_val)
1531{
1532 u8 phy_index;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00001533 /*
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001534 * Probe for the phy according to the given phy_addr, and execute
1535 * the read request on it
1536 */
1537 for (phy_index = 0; phy_index < params->num_phys; phy_index++) {
1538 if (params->phy[phy_index].addr == phy_addr) {
1539 return bnx2x_cl45_read(params->bp,
1540 &params->phy[phy_index], devad,
1541 reg, ret_val);
1542 }
1543 }
1544 return -EINVAL;
1545}
1546
1547u8 bnx2x_phy_write(struct link_params *params, u8 phy_addr,
1548 u8 devad, u16 reg, u16 val)
1549{
1550 u8 phy_index;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00001551 /*
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001552 * Probe for the phy according to the given phy_addr, and execute
1553 * the write request on it
1554 */
1555 for (phy_index = 0; phy_index < params->num_phys; phy_index++) {
1556 if (params->phy[phy_index].addr == phy_addr) {
1557 return bnx2x_cl45_write(params->bp,
1558 &params->phy[phy_index], devad,
1559 reg, val);
1560 }
1561 }
1562 return -EINVAL;
1563}
1564
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001565static void bnx2x_set_aer_mmd_xgxs(struct link_params *params,
1566 struct bnx2x_phy *phy)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001567{
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001568 u32 ser_lane;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001569 u16 offset, aer_val;
1570 struct bnx2x *bp = params->bp;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001571 ser_lane = ((params->lane_config &
1572 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_MASK) >>
1573 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_SHIFT);
1574
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001575 offset = phy->addr + ser_lane;
1576 if (CHIP_IS_E2(bp))
Yaniv Rosner82a0d472011-01-18 04:33:52 +00001577 aer_val = 0x3800 + offset - 1;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001578 else
1579 aer_val = 0x3800 + offset;
Yaniv Rosnercd2be892011-01-31 04:21:45 +00001580 CL22_WR_OVER_CL45(bp, phy, MDIO_REG_BANK_AER_BLOCK,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001581 MDIO_AER_BLOCK_AER_REG, aer_val);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001582}
1583static void bnx2x_set_aer_mmd_serdes(struct bnx2x *bp,
1584 struct bnx2x_phy *phy)
1585{
Yaniv Rosnercd2be892011-01-31 04:21:45 +00001586 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001587 MDIO_REG_BANK_AER_BLOCK,
1588 MDIO_AER_BLOCK_AER_REG, 0x3800);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001589}
1590
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00001591/******************************************************************/
1592/* Internal phy section */
1593/******************************************************************/
1594
1595static void bnx2x_set_serdes_access(struct bnx2x *bp, u8 port)
1596{
1597 u32 emac_base = (port) ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
1598
1599 /* Set Clause 22 */
1600 REG_WR(bp, NIG_REG_SERDES0_CTRL_MD_ST + port*0x10, 1);
1601 REG_WR(bp, emac_base + EMAC_REG_EMAC_MDIO_COMM, 0x245f8000);
1602 udelay(500);
1603 REG_WR(bp, emac_base + EMAC_REG_EMAC_MDIO_COMM, 0x245d000f);
1604 udelay(500);
1605 /* Set Clause 45 */
1606 REG_WR(bp, NIG_REG_SERDES0_CTRL_MD_ST + port*0x10, 0);
1607}
1608
1609static void bnx2x_serdes_deassert(struct bnx2x *bp, u8 port)
1610{
1611 u32 val;
1612
1613 DP(NETIF_MSG_LINK, "bnx2x_serdes_deassert\n");
1614
1615 val = SERDES_RESET_BITS << (port*16);
1616
1617 /* reset and unreset the SerDes/XGXS */
1618 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_CLEAR, val);
1619 udelay(500);
1620 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_SET, val);
1621
1622 bnx2x_set_serdes_access(bp, port);
1623
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001624 REG_WR(bp, NIG_REG_SERDES0_CTRL_MD_DEVAD + port*0x10,
1625 DEFAULT_PHY_DEV_ADDR);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00001626}
1627
1628static void bnx2x_xgxs_deassert(struct link_params *params)
1629{
1630 struct bnx2x *bp = params->bp;
1631 u8 port;
1632 u32 val;
1633 DP(NETIF_MSG_LINK, "bnx2x_xgxs_deassert\n");
1634 port = params->port;
1635
1636 val = XGXS_RESET_BITS << (port*16);
1637
1638 /* reset and unreset the SerDes/XGXS */
1639 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_CLEAR, val);
1640 udelay(500);
1641 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_SET, val);
1642
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001643 REG_WR(bp, NIG_REG_XGXS0_CTRL_MD_ST + port*0x18, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00001644 REG_WR(bp, NIG_REG_XGXS0_CTRL_MD_DEVAD + port*0x18,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001645 params->phy[INT_PHY].def_md_devad);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00001646}
1647
Yaniv Rosnera22f0782010-09-07 11:41:20 +00001648
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00001649void bnx2x_link_status_update(struct link_params *params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001650 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00001651{
1652 struct bnx2x *bp = params->bp;
1653 u8 link_10g;
1654 u8 port = params->port;
1655
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00001656 vars->link_status = REG_RD(bp, params->shmem_base +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001657 offsetof(struct shmem_region,
1658 port_mb[port].link_status));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00001659
1660 vars->link_up = (vars->link_status & LINK_STATUS_LINK_UP);
1661
1662 if (vars->link_up) {
1663 DP(NETIF_MSG_LINK, "phy link up\n");
1664
1665 vars->phy_link_up = 1;
1666 vars->duplex = DUPLEX_FULL;
1667 switch (vars->link_status &
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001668 LINK_STATUS_SPEED_AND_DUPLEX_MASK) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00001669 case LINK_10THD:
1670 vars->duplex = DUPLEX_HALF;
1671 /* fall thru */
1672 case LINK_10TFD:
1673 vars->line_speed = SPEED_10;
1674 break;
1675
1676 case LINK_100TXHD:
1677 vars->duplex = DUPLEX_HALF;
1678 /* fall thru */
1679 case LINK_100T4:
1680 case LINK_100TXFD:
1681 vars->line_speed = SPEED_100;
1682 break;
1683
1684 case LINK_1000THD:
1685 vars->duplex = DUPLEX_HALF;
1686 /* fall thru */
1687 case LINK_1000TFD:
1688 vars->line_speed = SPEED_1000;
1689 break;
1690
1691 case LINK_2500THD:
1692 vars->duplex = DUPLEX_HALF;
1693 /* fall thru */
1694 case LINK_2500TFD:
1695 vars->line_speed = SPEED_2500;
1696 break;
1697
1698 case LINK_10GTFD:
1699 vars->line_speed = SPEED_10000;
1700 break;
1701
1702 case LINK_12GTFD:
1703 vars->line_speed = SPEED_12000;
1704 break;
1705
1706 case LINK_12_5GTFD:
1707 vars->line_speed = SPEED_12500;
1708 break;
1709
1710 case LINK_13GTFD:
1711 vars->line_speed = SPEED_13000;
1712 break;
1713
1714 case LINK_15GTFD:
1715 vars->line_speed = SPEED_15000;
1716 break;
1717
1718 case LINK_16GTFD:
1719 vars->line_speed = SPEED_16000;
1720 break;
1721
1722 default:
1723 break;
1724 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00001725 vars->flow_ctrl = 0;
1726 if (vars->link_status & LINK_STATUS_TX_FLOW_CONTROL_ENABLED)
1727 vars->flow_ctrl |= BNX2X_FLOW_CTRL_TX;
1728
1729 if (vars->link_status & LINK_STATUS_RX_FLOW_CONTROL_ENABLED)
1730 vars->flow_ctrl |= BNX2X_FLOW_CTRL_RX;
1731
1732 if (!vars->flow_ctrl)
1733 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
1734
1735 if (vars->line_speed &&
1736 ((vars->line_speed == SPEED_10) ||
1737 (vars->line_speed == SPEED_100))) {
1738 vars->phy_flags |= PHY_SGMII_FLAG;
1739 } else {
1740 vars->phy_flags &= ~PHY_SGMII_FLAG;
1741 }
1742
1743 /* anything 10 and over uses the bmac */
1744 link_10g = ((vars->line_speed == SPEED_10000) ||
1745 (vars->line_speed == SPEED_12000) ||
1746 (vars->line_speed == SPEED_12500) ||
1747 (vars->line_speed == SPEED_13000) ||
1748 (vars->line_speed == SPEED_15000) ||
1749 (vars->line_speed == SPEED_16000));
1750 if (link_10g)
1751 vars->mac_type = MAC_TYPE_BMAC;
1752 else
1753 vars->mac_type = MAC_TYPE_EMAC;
1754
1755 } else { /* link down */
1756 DP(NETIF_MSG_LINK, "phy link down\n");
1757
1758 vars->phy_link_up = 0;
1759
1760 vars->line_speed = 0;
1761 vars->duplex = DUPLEX_FULL;
1762 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
1763
1764 /* indicate no mac active */
1765 vars->mac_type = MAC_TYPE_NONE;
1766 }
1767
1768 DP(NETIF_MSG_LINK, "link_status 0x%x phy_link_up %x\n",
1769 vars->link_status, vars->phy_link_up);
1770 DP(NETIF_MSG_LINK, "line_speed %x duplex %x flow_ctrl 0x%x\n",
1771 vars->line_speed, vars->duplex, vars->flow_ctrl);
1772}
1773
1774
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001775static void bnx2x_set_master_ln(struct link_params *params,
1776 struct bnx2x_phy *phy)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001777{
1778 struct bnx2x *bp = params->bp;
1779 u16 new_master_ln, ser_lane;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001780 ser_lane = ((params->lane_config &
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001781 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_MASK) >>
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001782 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_SHIFT);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001783
1784 /* set the master_ln for AN */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00001785 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001786 MDIO_REG_BANK_XGXS_BLOCK2,
1787 MDIO_XGXS_BLOCK2_TEST_MODE_LANE,
1788 &new_master_ln);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001789
Yaniv Rosnercd2be892011-01-31 04:21:45 +00001790 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001791 MDIO_REG_BANK_XGXS_BLOCK2 ,
1792 MDIO_XGXS_BLOCK2_TEST_MODE_LANE,
1793 (new_master_ln | ser_lane));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001794}
1795
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001796static u8 bnx2x_reset_unicore(struct link_params *params,
1797 struct bnx2x_phy *phy,
1798 u8 set_serdes)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001799{
1800 struct bnx2x *bp = params->bp;
1801 u16 mii_control;
1802 u16 i;
Yaniv Rosnercd2be892011-01-31 04:21:45 +00001803 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001804 MDIO_REG_BANK_COMBO_IEEE0,
1805 MDIO_COMBO_IEEE0_MII_CONTROL, &mii_control);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001806
1807 /* reset the unicore */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00001808 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001809 MDIO_REG_BANK_COMBO_IEEE0,
1810 MDIO_COMBO_IEEE0_MII_CONTROL,
1811 (mii_control |
1812 MDIO_COMBO_IEEO_MII_CONTROL_RESET));
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001813 if (set_serdes)
1814 bnx2x_set_serdes_access(bp, params->port);
Eilon Greensteinc1b73992009-02-12 08:37:07 +00001815
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001816 /* wait for the reset to self clear */
1817 for (i = 0; i < MDIO_ACCESS_TIMEOUT; i++) {
1818 udelay(5);
1819
1820 /* the reset erased the previous bank value */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00001821 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001822 MDIO_REG_BANK_COMBO_IEEE0,
1823 MDIO_COMBO_IEEE0_MII_CONTROL,
1824 &mii_control);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001825
1826 if (!(mii_control & MDIO_COMBO_IEEO_MII_CONTROL_RESET)) {
1827 udelay(5);
1828 return 0;
1829 }
1830 }
1831
Yaniv Rosner6d870c32011-01-31 04:22:20 +00001832 netdev_err(bp->dev, "Warning: PHY was not initialized,"
1833 " Port %d\n",
1834 params->port);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001835 DP(NETIF_MSG_LINK, "BUG! XGXS is still in reset!\n");
1836 return -EINVAL;
1837
1838}
1839
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001840static void bnx2x_set_swap_lanes(struct link_params *params,
1841 struct bnx2x_phy *phy)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001842{
1843 struct bnx2x *bp = params->bp;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00001844 /*
1845 * Each two bits represents a lane number:
1846 * No swap is 0123 => 0x1b no need to enable the swap
1847 */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001848 u16 ser_lane, rx_lane_swap, tx_lane_swap;
1849
1850 ser_lane = ((params->lane_config &
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001851 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_MASK) >>
1852 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_SHIFT);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001853 rx_lane_swap = ((params->lane_config &
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001854 PORT_HW_CFG_LANE_SWAP_CFG_RX_MASK) >>
1855 PORT_HW_CFG_LANE_SWAP_CFG_RX_SHIFT);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001856 tx_lane_swap = ((params->lane_config &
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001857 PORT_HW_CFG_LANE_SWAP_CFG_TX_MASK) >>
1858 PORT_HW_CFG_LANE_SWAP_CFG_TX_SHIFT);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001859
1860 if (rx_lane_swap != 0x1b) {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00001861 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001862 MDIO_REG_BANK_XGXS_BLOCK2,
1863 MDIO_XGXS_BLOCK2_RX_LN_SWAP,
1864 (rx_lane_swap |
1865 MDIO_XGXS_BLOCK2_RX_LN_SWAP_ENABLE |
1866 MDIO_XGXS_BLOCK2_RX_LN_SWAP_FORCE_ENABLE));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001867 } else {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00001868 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001869 MDIO_REG_BANK_XGXS_BLOCK2,
1870 MDIO_XGXS_BLOCK2_RX_LN_SWAP, 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001871 }
1872
1873 if (tx_lane_swap != 0x1b) {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00001874 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001875 MDIO_REG_BANK_XGXS_BLOCK2,
1876 MDIO_XGXS_BLOCK2_TX_LN_SWAP,
1877 (tx_lane_swap |
1878 MDIO_XGXS_BLOCK2_TX_LN_SWAP_ENABLE));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001879 } else {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00001880 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001881 MDIO_REG_BANK_XGXS_BLOCK2,
1882 MDIO_XGXS_BLOCK2_TX_LN_SWAP, 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001883 }
1884}
1885
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001886static void bnx2x_set_parallel_detection(struct bnx2x_phy *phy,
1887 struct link_params *params)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001888{
1889 struct bnx2x *bp = params->bp;
1890 u16 control2;
Yaniv Rosnercd2be892011-01-31 04:21:45 +00001891 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001892 MDIO_REG_BANK_SERDES_DIGITAL,
1893 MDIO_SERDES_DIGITAL_A_1000X_CONTROL2,
1894 &control2);
Yaniv Rosner7aa07112010-09-07 11:41:01 +00001895 if (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)
Yaniv Rosner18afb0a2009-11-05 19:18:04 +02001896 control2 |= MDIO_SERDES_DIGITAL_A_1000X_CONTROL2_PRL_DT_EN;
1897 else
1898 control2 &= ~MDIO_SERDES_DIGITAL_A_1000X_CONTROL2_PRL_DT_EN;
Yaniv Rosner7aa07112010-09-07 11:41:01 +00001899 DP(NETIF_MSG_LINK, "phy->speed_cap_mask = 0x%x, control2 = 0x%x\n",
1900 phy->speed_cap_mask, control2);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00001901 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001902 MDIO_REG_BANK_SERDES_DIGITAL,
1903 MDIO_SERDES_DIGITAL_A_1000X_CONTROL2,
1904 control2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001905
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001906 if ((phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT) &&
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00001907 (phy->speed_cap_mask &
Yaniv Rosner18afb0a2009-11-05 19:18:04 +02001908 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001909 DP(NETIF_MSG_LINK, "XGXS\n");
1910
Yaniv Rosnercd2be892011-01-31 04:21:45 +00001911 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001912 MDIO_REG_BANK_10G_PARALLEL_DETECT,
1913 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_LINK,
1914 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_LINK_CNT);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001915
Yaniv Rosnercd2be892011-01-31 04:21:45 +00001916 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001917 MDIO_REG_BANK_10G_PARALLEL_DETECT,
1918 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_CONTROL,
1919 &control2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001920
1921
1922 control2 |=
1923 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_CONTROL_PARDET10G_EN;
1924
Yaniv Rosnercd2be892011-01-31 04:21:45 +00001925 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001926 MDIO_REG_BANK_10G_PARALLEL_DETECT,
1927 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_CONTROL,
1928 control2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001929
1930 /* Disable parallel detection of HiG */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00001931 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001932 MDIO_REG_BANK_XGXS_BLOCK2,
1933 MDIO_XGXS_BLOCK2_UNICORE_MODE_10G,
1934 MDIO_XGXS_BLOCK2_UNICORE_MODE_10G_CX4_XGXS |
1935 MDIO_XGXS_BLOCK2_UNICORE_MODE_10G_HIGIG_XGXS);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001936 }
1937}
1938
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001939static void bnx2x_set_autoneg(struct bnx2x_phy *phy,
1940 struct link_params *params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001941 struct link_vars *vars,
1942 u8 enable_cl73)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001943{
1944 struct bnx2x *bp = params->bp;
1945 u16 reg_val;
1946
1947 /* CL37 Autoneg */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00001948 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001949 MDIO_REG_BANK_COMBO_IEEE0,
1950 MDIO_COMBO_IEEE0_MII_CONTROL, &reg_val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001951
1952 /* CL37 Autoneg Enabled */
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07001953 if (vars->line_speed == SPEED_AUTO_NEG)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001954 reg_val |= MDIO_COMBO_IEEO_MII_CONTROL_AN_EN;
1955 else /* CL37 Autoneg Disabled */
1956 reg_val &= ~(MDIO_COMBO_IEEO_MII_CONTROL_AN_EN |
1957 MDIO_COMBO_IEEO_MII_CONTROL_RESTART_AN);
1958
Yaniv Rosnercd2be892011-01-31 04:21:45 +00001959 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001960 MDIO_REG_BANK_COMBO_IEEE0,
1961 MDIO_COMBO_IEEE0_MII_CONTROL, reg_val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001962
1963 /* Enable/Disable Autodetection */
1964
Yaniv Rosnercd2be892011-01-31 04:21:45 +00001965 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001966 MDIO_REG_BANK_SERDES_DIGITAL,
1967 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1, &reg_val);
Eilon Greenstein239d6862009-08-12 08:23:04 +00001968 reg_val &= ~(MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_SIGNAL_DETECT_EN |
1969 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_INVERT_SIGNAL_DETECT);
1970 reg_val |= MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_FIBER_MODE;
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07001971 if (vars->line_speed == SPEED_AUTO_NEG)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001972 reg_val |= MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_AUTODET;
1973 else
1974 reg_val &= ~MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_AUTODET;
1975
Yaniv Rosnercd2be892011-01-31 04:21:45 +00001976 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001977 MDIO_REG_BANK_SERDES_DIGITAL,
1978 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1, reg_val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001979
1980 /* Enable TetonII and BAM autoneg */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00001981 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001982 MDIO_REG_BANK_BAM_NEXT_PAGE,
1983 MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL,
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001984 &reg_val);
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07001985 if (vars->line_speed == SPEED_AUTO_NEG) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001986 /* Enable BAM aneg Mode and TetonII aneg Mode */
1987 reg_val |= (MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL_BAM_MODE |
1988 MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL_TETON_AN);
1989 } else {
1990 /* TetonII and BAM Autoneg Disabled */
1991 reg_val &= ~(MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL_BAM_MODE |
1992 MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL_TETON_AN);
1993 }
Yaniv Rosnercd2be892011-01-31 04:21:45 +00001994 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001995 MDIO_REG_BANK_BAM_NEXT_PAGE,
1996 MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL,
1997 reg_val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001998
Eilon Greenstein239d6862009-08-12 08:23:04 +00001999 if (enable_cl73) {
2000 /* Enable Cl73 FSM status bits */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002001 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002002 MDIO_REG_BANK_CL73_USERB0,
2003 MDIO_CL73_USERB0_CL73_UCTRL,
2004 0xe);
Eilon Greenstein239d6862009-08-12 08:23:04 +00002005
2006 /* Enable BAM Station Manager*/
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002007 CL22_WR_OVER_CL45(bp, phy,
Eilon Greenstein239d6862009-08-12 08:23:04 +00002008 MDIO_REG_BANK_CL73_USERB0,
2009 MDIO_CL73_USERB0_CL73_BAM_CTRL1,
2010 MDIO_CL73_USERB0_CL73_BAM_CTRL1_BAM_EN |
2011 MDIO_CL73_USERB0_CL73_BAM_CTRL1_BAM_STATION_MNGR_EN |
2012 MDIO_CL73_USERB0_CL73_BAM_CTRL1_BAM_NP_AFTER_BP_EN);
2013
Yaniv Rosner7846e472009-11-05 19:18:07 +02002014 /* Advertise CL73 link speeds */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002015 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002016 MDIO_REG_BANK_CL73_IEEEB1,
2017 MDIO_CL73_IEEEB1_AN_ADV2,
2018 &reg_val);
Yaniv Rosner7aa07112010-09-07 11:41:01 +00002019 if (phy->speed_cap_mask &
Yaniv Rosner7846e472009-11-05 19:18:07 +02002020 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
2021 reg_val |= MDIO_CL73_IEEEB1_AN_ADV2_ADVR_10G_KX4;
Yaniv Rosner7aa07112010-09-07 11:41:01 +00002022 if (phy->speed_cap_mask &
Yaniv Rosner7846e472009-11-05 19:18:07 +02002023 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)
2024 reg_val |= MDIO_CL73_IEEEB1_AN_ADV2_ADVR_1000M_KX;
Eilon Greenstein239d6862009-08-12 08:23:04 +00002025
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002026 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002027 MDIO_REG_BANK_CL73_IEEEB1,
2028 MDIO_CL73_IEEEB1_AN_ADV2,
2029 reg_val);
Eilon Greenstein239d6862009-08-12 08:23:04 +00002030
Eilon Greenstein239d6862009-08-12 08:23:04 +00002031 /* CL73 Autoneg Enabled */
2032 reg_val = MDIO_CL73_IEEEB0_CL73_AN_CONTROL_AN_EN;
2033
2034 } else /* CL73 Autoneg Disabled */
2035 reg_val = 0;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002036
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002037 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002038 MDIO_REG_BANK_CL73_IEEEB0,
2039 MDIO_CL73_IEEEB0_CL73_AN_CONTROL, reg_val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002040}
2041
2042/* program SerDes, forced speed */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002043static void bnx2x_program_serdes(struct bnx2x_phy *phy,
2044 struct link_params *params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002045 struct link_vars *vars)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002046{
2047 struct bnx2x *bp = params->bp;
2048 u16 reg_val;
2049
Eilon Greenstein57937202009-08-12 08:23:53 +00002050 /* program duplex, disable autoneg and sgmii*/
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002051 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002052 MDIO_REG_BANK_COMBO_IEEE0,
2053 MDIO_COMBO_IEEE0_MII_CONTROL, &reg_val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002054 reg_val &= ~(MDIO_COMBO_IEEO_MII_CONTROL_FULL_DUPLEX |
Eilon Greenstein57937202009-08-12 08:23:53 +00002055 MDIO_COMBO_IEEO_MII_CONTROL_AN_EN |
2056 MDIO_COMBO_IEEO_MII_CONTROL_MAN_SGMII_SP_MASK);
Yaniv Rosner7aa07112010-09-07 11:41:01 +00002057 if (phy->req_duplex == DUPLEX_FULL)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002058 reg_val |= MDIO_COMBO_IEEO_MII_CONTROL_FULL_DUPLEX;
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002059 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002060 MDIO_REG_BANK_COMBO_IEEE0,
2061 MDIO_COMBO_IEEE0_MII_CONTROL, reg_val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002062
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002063 /*
2064 * program speed
2065 * - needed only if the speed is greater than 1G (2.5G or 10G)
2066 */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002067 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002068 MDIO_REG_BANK_SERDES_DIGITAL,
2069 MDIO_SERDES_DIGITAL_MISC1, &reg_val);
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002070 /* clearing the speed value before setting the right speed */
2071 DP(NETIF_MSG_LINK, "MDIO_REG_BANK_SERDES_DIGITAL = 0x%x\n", reg_val);
2072
2073 reg_val &= ~(MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_MASK |
2074 MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_SEL);
2075
2076 if (!((vars->line_speed == SPEED_1000) ||
2077 (vars->line_speed == SPEED_100) ||
2078 (vars->line_speed == SPEED_10))) {
2079
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002080 reg_val |= (MDIO_SERDES_DIGITAL_MISC1_REFCLK_SEL_156_25M |
2081 MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_SEL);
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002082 if (vars->line_speed == SPEED_10000)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002083 reg_val |=
2084 MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_10G_CX4;
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002085 if (vars->line_speed == SPEED_13000)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002086 reg_val |=
2087 MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_13G;
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002088 }
2089
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002090 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002091 MDIO_REG_BANK_SERDES_DIGITAL,
2092 MDIO_SERDES_DIGITAL_MISC1, reg_val);
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002093
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002094}
2095
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002096static void bnx2x_set_brcm_cl37_advertisment(struct bnx2x_phy *phy,
2097 struct link_params *params)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002098{
2099 struct bnx2x *bp = params->bp;
2100 u16 val = 0;
2101
2102 /* configure the 48 bits for BAM AN */
2103
2104 /* set extended capabilities */
Yaniv Rosner7aa07112010-09-07 11:41:01 +00002105 if (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002106 val |= MDIO_OVER_1G_UP1_2_5G;
Yaniv Rosner7aa07112010-09-07 11:41:01 +00002107 if (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002108 val |= MDIO_OVER_1G_UP1_10G;
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002109 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002110 MDIO_REG_BANK_OVER_1G,
2111 MDIO_OVER_1G_UP1, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002112
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002113 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002114 MDIO_REG_BANK_OVER_1G,
2115 MDIO_OVER_1G_UP3, 0x400);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002116}
2117
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002118static void bnx2x_calc_ieee_aneg_adv(struct bnx2x_phy *phy,
2119 struct link_params *params, u16 *ieee_fc)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002120{
Yaniv Rosnerd5cb9e92009-11-05 19:18:10 +02002121 struct bnx2x *bp = params->bp;
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002122 *ieee_fc = MDIO_COMBO_IEEE0_AUTO_NEG_ADV_FULL_DUPLEX;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002123 /*
2124 * Resolve pause mode and advertisement.
2125 * Please refer to Table 28B-3 of the 802.3ab-1999 spec
2126 */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002127
Yaniv Rosner7aa07112010-09-07 11:41:01 +00002128 switch (phy->req_flow_ctrl) {
David S. Millerc0700f92008-12-16 23:53:20 -08002129 case BNX2X_FLOW_CTRL_AUTO:
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002130 if (params->req_fc_auto_adv == BNX2X_FLOW_CTRL_BOTH)
2131 *ieee_fc |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH;
2132 else
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002133 *ieee_fc |=
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002134 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002135 break;
David S. Millerc0700f92008-12-16 23:53:20 -08002136 case BNX2X_FLOW_CTRL_TX:
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002137 *ieee_fc |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002138 break;
2139
David S. Millerc0700f92008-12-16 23:53:20 -08002140 case BNX2X_FLOW_CTRL_RX:
2141 case BNX2X_FLOW_CTRL_BOTH:
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002142 *ieee_fc |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002143 break;
2144
David S. Millerc0700f92008-12-16 23:53:20 -08002145 case BNX2X_FLOW_CTRL_NONE:
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002146 default:
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002147 *ieee_fc |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002148 break;
2149 }
Yaniv Rosnerd5cb9e92009-11-05 19:18:10 +02002150 DP(NETIF_MSG_LINK, "ieee_fc = 0x%x\n", *ieee_fc);
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002151}
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002152
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002153static void bnx2x_set_ieee_aneg_advertisment(struct bnx2x_phy *phy,
2154 struct link_params *params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002155 u16 ieee_fc)
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002156{
2157 struct bnx2x *bp = params->bp;
Yaniv Rosner7846e472009-11-05 19:18:07 +02002158 u16 val;
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002159 /* for AN, we are always publishing full duplex */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002160
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002161 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002162 MDIO_REG_BANK_COMBO_IEEE0,
2163 MDIO_COMBO_IEEE0_AUTO_NEG_ADV, ieee_fc);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002164 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002165 MDIO_REG_BANK_CL73_IEEEB1,
2166 MDIO_CL73_IEEEB1_AN_ADV1, &val);
Yaniv Rosner7846e472009-11-05 19:18:07 +02002167 val &= ~MDIO_CL73_IEEEB1_AN_ADV1_PAUSE_BOTH;
2168 val |= ((ieee_fc<<3) & MDIO_CL73_IEEEB1_AN_ADV1_PAUSE_MASK);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002169 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002170 MDIO_REG_BANK_CL73_IEEEB1,
2171 MDIO_CL73_IEEEB1_AN_ADV1, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002172}
2173
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002174static void bnx2x_restart_autoneg(struct bnx2x_phy *phy,
2175 struct link_params *params,
2176 u8 enable_cl73)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002177{
2178 struct bnx2x *bp = params->bp;
Eilon Greenstein3a36f2e2009-02-12 08:37:09 +00002179 u16 mii_control;
Eilon Greenstein239d6862009-08-12 08:23:04 +00002180
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002181 DP(NETIF_MSG_LINK, "bnx2x_restart_autoneg\n");
Eilon Greenstein3a36f2e2009-02-12 08:37:09 +00002182 /* Enable and restart BAM/CL37 aneg */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002183
Eilon Greenstein239d6862009-08-12 08:23:04 +00002184 if (enable_cl73) {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002185 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002186 MDIO_REG_BANK_CL73_IEEEB0,
2187 MDIO_CL73_IEEEB0_CL73_AN_CONTROL,
2188 &mii_control);
Eilon Greenstein239d6862009-08-12 08:23:04 +00002189
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_CL73_IEEEB0,
2192 MDIO_CL73_IEEEB0_CL73_AN_CONTROL,
2193 (mii_control |
2194 MDIO_CL73_IEEEB0_CL73_AN_CONTROL_AN_EN |
2195 MDIO_CL73_IEEEB0_CL73_AN_CONTROL_RESTART_AN));
Eilon Greenstein239d6862009-08-12 08:23:04 +00002196 } else {
2197
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002198 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002199 MDIO_REG_BANK_COMBO_IEEE0,
2200 MDIO_COMBO_IEEE0_MII_CONTROL,
2201 &mii_control);
Eilon Greenstein239d6862009-08-12 08:23:04 +00002202 DP(NETIF_MSG_LINK,
2203 "bnx2x_restart_autoneg mii_control before = 0x%x\n",
2204 mii_control);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002205 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002206 MDIO_REG_BANK_COMBO_IEEE0,
2207 MDIO_COMBO_IEEE0_MII_CONTROL,
2208 (mii_control |
2209 MDIO_COMBO_IEEO_MII_CONTROL_AN_EN |
2210 MDIO_COMBO_IEEO_MII_CONTROL_RESTART_AN));
Eilon Greenstein239d6862009-08-12 08:23:04 +00002211 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002212}
2213
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002214static void bnx2x_initialize_sgmii_process(struct bnx2x_phy *phy,
2215 struct link_params *params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002216 struct link_vars *vars)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002217{
2218 struct bnx2x *bp = params->bp;
2219 u16 control1;
2220
2221 /* in SGMII mode, the unicore is always slave */
2222
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002223 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002224 MDIO_REG_BANK_SERDES_DIGITAL,
2225 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1,
2226 &control1);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002227 control1 |= MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_INVERT_SIGNAL_DETECT;
2228 /* set sgmii mode (and not fiber) */
2229 control1 &= ~(MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_FIBER_MODE |
2230 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_AUTODET |
2231 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_MSTR_MODE);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002232 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002233 MDIO_REG_BANK_SERDES_DIGITAL,
2234 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1,
2235 control1);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002236
2237 /* if forced speed */
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002238 if (!(vars->line_speed == SPEED_AUTO_NEG)) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002239 /* set speed, disable autoneg */
2240 u16 mii_control;
2241
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002242 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002243 MDIO_REG_BANK_COMBO_IEEE0,
2244 MDIO_COMBO_IEEE0_MII_CONTROL,
2245 &mii_control);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002246 mii_control &= ~(MDIO_COMBO_IEEO_MII_CONTROL_AN_EN |
2247 MDIO_COMBO_IEEO_MII_CONTROL_MAN_SGMII_SP_MASK|
2248 MDIO_COMBO_IEEO_MII_CONTROL_FULL_DUPLEX);
2249
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002250 switch (vars->line_speed) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002251 case SPEED_100:
2252 mii_control |=
2253 MDIO_COMBO_IEEO_MII_CONTROL_MAN_SGMII_SP_100;
2254 break;
2255 case SPEED_1000:
2256 mii_control |=
2257 MDIO_COMBO_IEEO_MII_CONTROL_MAN_SGMII_SP_1000;
2258 break;
2259 case SPEED_10:
2260 /* there is nothing to set for 10M */
2261 break;
2262 default:
2263 /* invalid speed for SGMII */
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002264 DP(NETIF_MSG_LINK, "Invalid line_speed 0x%x\n",
2265 vars->line_speed);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002266 break;
2267 }
2268
2269 /* setting the full duplex */
Yaniv Rosner7aa07112010-09-07 11:41:01 +00002270 if (phy->req_duplex == DUPLEX_FULL)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002271 mii_control |=
2272 MDIO_COMBO_IEEO_MII_CONTROL_FULL_DUPLEX;
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002273 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002274 MDIO_REG_BANK_COMBO_IEEE0,
2275 MDIO_COMBO_IEEE0_MII_CONTROL,
2276 mii_control);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002277
2278 } else { /* AN mode */
2279 /* enable and restart AN */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002280 bnx2x_restart_autoneg(phy, params, 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002281 }
2282}
2283
2284
2285/*
2286 * link management
2287 */
2288
2289static void bnx2x_pause_resolve(struct link_vars *vars, u32 pause_result)
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002290{ /* LD LP */
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002291 switch (pause_result) { /* ASYM P ASYM P */
2292 case 0xb: /* 1 0 1 1 */
David S. Millerc0700f92008-12-16 23:53:20 -08002293 vars->flow_ctrl = BNX2X_FLOW_CTRL_TX;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002294 break;
2295
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002296 case 0xe: /* 1 1 1 0 */
David S. Millerc0700f92008-12-16 23:53:20 -08002297 vars->flow_ctrl = BNX2X_FLOW_CTRL_RX;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002298 break;
2299
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002300 case 0x5: /* 0 1 0 1 */
2301 case 0x7: /* 0 1 1 1 */
2302 case 0xd: /* 1 1 0 1 */
2303 case 0xf: /* 1 1 1 1 */
David S. Millerc0700f92008-12-16 23:53:20 -08002304 vars->flow_ctrl = BNX2X_FLOW_CTRL_BOTH;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002305 break;
2306
2307 default:
2308 break;
2309 }
Yaniv Rosner7aa07112010-09-07 11:41:01 +00002310 if (pause_result & (1<<0))
2311 vars->link_status |= LINK_STATUS_LINK_PARTNER_SYMMETRIC_PAUSE;
2312 if (pause_result & (1<<1))
2313 vars->link_status |= LINK_STATUS_LINK_PARTNER_ASYMMETRIC_PAUSE;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002314}
2315
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002316static u8 bnx2x_direct_parallel_detect_used(struct bnx2x_phy *phy,
2317 struct link_params *params)
Yaniv Rosner15ddd2d2009-11-05 19:18:12 +02002318{
2319 struct bnx2x *bp = params->bp;
2320 u16 pd_10g, status2_1000x;
Yaniv Rosner7aa07112010-09-07 11:41:01 +00002321 if (phy->req_line_speed != SPEED_AUTO_NEG)
2322 return 0;
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002323 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002324 MDIO_REG_BANK_SERDES_DIGITAL,
2325 MDIO_SERDES_DIGITAL_A_1000X_STATUS2,
2326 &status2_1000x);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002327 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002328 MDIO_REG_BANK_SERDES_DIGITAL,
2329 MDIO_SERDES_DIGITAL_A_1000X_STATUS2,
2330 &status2_1000x);
Yaniv Rosner15ddd2d2009-11-05 19:18:12 +02002331 if (status2_1000x & MDIO_SERDES_DIGITAL_A_1000X_STATUS2_AN_DISABLED) {
2332 DP(NETIF_MSG_LINK, "1G parallel detect link on port %d\n",
2333 params->port);
2334 return 1;
2335 }
2336
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002337 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002338 MDIO_REG_BANK_10G_PARALLEL_DETECT,
2339 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_STATUS,
2340 &pd_10g);
Yaniv Rosner15ddd2d2009-11-05 19:18:12 +02002341
2342 if (pd_10g & MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_STATUS_PD_LINK) {
2343 DP(NETIF_MSG_LINK, "10G parallel detect link on port %d\n",
2344 params->port);
2345 return 1;
2346 }
2347 return 0;
2348}
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002349
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002350static void bnx2x_flow_ctrl_resolve(struct bnx2x_phy *phy,
2351 struct link_params *params,
2352 struct link_vars *vars,
2353 u32 gp_status)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002354{
2355 struct bnx2x *bp = params->bp;
Eilon Greenstein3196a882008-08-13 15:58:49 -07002356 u16 ld_pause; /* local driver */
2357 u16 lp_pause; /* link partner */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002358 u16 pause_result;
2359
David S. Millerc0700f92008-12-16 23:53:20 -08002360 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002361
2362 /* resolve from gp_status in case of AN complete and not sgmii */
Yaniv Rosner7aa07112010-09-07 11:41:01 +00002363 if (phy->req_flow_ctrl != BNX2X_FLOW_CTRL_AUTO)
2364 vars->flow_ctrl = phy->req_flow_ctrl;
2365 else if (phy->req_line_speed != SPEED_AUTO_NEG)
2366 vars->flow_ctrl = params->req_fc_auto_adv;
2367 else if ((gp_status & MDIO_AN_CL73_OR_37_COMPLETE) &&
2368 (!(vars->phy_flags & PHY_SGMII_FLAG))) {
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002369 if (bnx2x_direct_parallel_detect_used(phy, params)) {
Yaniv Rosner15ddd2d2009-11-05 19:18:12 +02002370 vars->flow_ctrl = params->req_fc_auto_adv;
2371 return;
2372 }
Yaniv Rosner7846e472009-11-05 19:18:07 +02002373 if ((gp_status &
2374 (MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_AUTONEG_COMPLETE |
2375 MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_MR_LP_NP_AN_ABLE)) ==
2376 (MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_AUTONEG_COMPLETE |
2377 MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_MR_LP_NP_AN_ABLE)) {
2378
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002379 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002380 MDIO_REG_BANK_CL73_IEEEB1,
2381 MDIO_CL73_IEEEB1_AN_ADV1,
2382 &ld_pause);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002383 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002384 MDIO_REG_BANK_CL73_IEEEB1,
2385 MDIO_CL73_IEEEB1_AN_LP_ADV1,
2386 &lp_pause);
Yaniv Rosner7846e472009-11-05 19:18:07 +02002387 pause_result = (ld_pause &
2388 MDIO_CL73_IEEEB1_AN_ADV1_PAUSE_MASK)
2389 >> 8;
2390 pause_result |= (lp_pause &
2391 MDIO_CL73_IEEEB1_AN_LP_ADV1_PAUSE_MASK)
2392 >> 10;
2393 DP(NETIF_MSG_LINK, "pause_result CL73 0x%x\n",
2394 pause_result);
2395 } else {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002396 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002397 MDIO_REG_BANK_COMBO_IEEE0,
2398 MDIO_COMBO_IEEE0_AUTO_NEG_ADV,
2399 &ld_pause);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002400 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002401 MDIO_REG_BANK_COMBO_IEEE0,
2402 MDIO_COMBO_IEEE0_AUTO_NEG_LINK_PARTNER_ABILITY1,
2403 &lp_pause);
Yaniv Rosner7846e472009-11-05 19:18:07 +02002404 pause_result = (ld_pause &
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002405 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK)>>5;
Yaniv Rosner7846e472009-11-05 19:18:07 +02002406 pause_result |= (lp_pause &
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002407 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK)>>7;
Yaniv Rosner7846e472009-11-05 19:18:07 +02002408 DP(NETIF_MSG_LINK, "pause_result CL37 0x%x\n",
2409 pause_result);
2410 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002411 bnx2x_pause_resolve(vars, pause_result);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002412 }
2413 DP(NETIF_MSG_LINK, "flow_ctrl 0x%x\n", vars->flow_ctrl);
2414}
2415
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002416static void bnx2x_check_fallback_to_cl37(struct bnx2x_phy *phy,
2417 struct link_params *params)
Eilon Greenstein239d6862009-08-12 08:23:04 +00002418{
2419 struct bnx2x *bp = params->bp;
2420 u16 rx_status, ustat_val, cl37_fsm_recieved;
2421 DP(NETIF_MSG_LINK, "bnx2x_check_fallback_to_cl37\n");
2422 /* Step 1: Make sure signal is detected */
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_RX0,
2425 MDIO_RX0_RX_STATUS,
2426 &rx_status);
Eilon Greenstein239d6862009-08-12 08:23:04 +00002427 if ((rx_status & MDIO_RX0_RX_STATUS_SIGDET) !=
2428 (MDIO_RX0_RX_STATUS_SIGDET)) {
2429 DP(NETIF_MSG_LINK, "Signal is not detected. Restoring CL73."
2430 "rx_status(0x80b0) = 0x%x\n", rx_status);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002431 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002432 MDIO_REG_BANK_CL73_IEEEB0,
2433 MDIO_CL73_IEEEB0_CL73_AN_CONTROL,
2434 MDIO_CL73_IEEEB0_CL73_AN_CONTROL_AN_EN);
Eilon Greenstein239d6862009-08-12 08:23:04 +00002435 return;
2436 }
2437 /* Step 2: Check CL73 state machine */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002438 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002439 MDIO_REG_BANK_CL73_USERB0,
2440 MDIO_CL73_USERB0_CL73_USTAT1,
2441 &ustat_val);
Eilon Greenstein239d6862009-08-12 08:23:04 +00002442 if ((ustat_val &
2443 (MDIO_CL73_USERB0_CL73_USTAT1_LINK_STATUS_CHECK |
2444 MDIO_CL73_USERB0_CL73_USTAT1_AN_GOOD_CHECK_BAM37)) !=
2445 (MDIO_CL73_USERB0_CL73_USTAT1_LINK_STATUS_CHECK |
2446 MDIO_CL73_USERB0_CL73_USTAT1_AN_GOOD_CHECK_BAM37)) {
2447 DP(NETIF_MSG_LINK, "CL73 state-machine is not stable. "
2448 "ustat_val(0x8371) = 0x%x\n", ustat_val);
2449 return;
2450 }
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002451 /*
2452 * Step 3: Check CL37 Message Pages received to indicate LP
2453 * supports only CL37
2454 */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002455 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002456 MDIO_REG_BANK_REMOTE_PHY,
2457 MDIO_REMOTE_PHY_MISC_RX_STATUS,
2458 &cl37_fsm_recieved);
Eilon Greenstein239d6862009-08-12 08:23:04 +00002459 if ((cl37_fsm_recieved &
2460 (MDIO_REMOTE_PHY_MISC_RX_STATUS_CL37_FSM_RECEIVED_OVER1G_MSG |
2461 MDIO_REMOTE_PHY_MISC_RX_STATUS_CL37_FSM_RECEIVED_BRCM_OUI_MSG)) !=
2462 (MDIO_REMOTE_PHY_MISC_RX_STATUS_CL37_FSM_RECEIVED_OVER1G_MSG |
2463 MDIO_REMOTE_PHY_MISC_RX_STATUS_CL37_FSM_RECEIVED_BRCM_OUI_MSG)) {
2464 DP(NETIF_MSG_LINK, "No CL37 FSM were received. "
2465 "misc_rx_status(0x8330) = 0x%x\n",
2466 cl37_fsm_recieved);
2467 return;
2468 }
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002469 /*
2470 * The combined cl37/cl73 fsm state information indicating that
2471 * we are connected to a device which does not support cl73, but
2472 * does support cl37 BAM. In this case we disable cl73 and
2473 * restart cl37 auto-neg
2474 */
2475
Eilon Greenstein239d6862009-08-12 08:23:04 +00002476 /* Disable CL73 */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002477 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002478 MDIO_REG_BANK_CL73_IEEEB0,
2479 MDIO_CL73_IEEEB0_CL73_AN_CONTROL,
2480 0);
Eilon Greenstein239d6862009-08-12 08:23:04 +00002481 /* Restart CL37 autoneg */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002482 bnx2x_restart_autoneg(phy, params, 0);
Eilon Greenstein239d6862009-08-12 08:23:04 +00002483 DP(NETIF_MSG_LINK, "Disabling CL73, and restarting CL37 autoneg\n");
2484}
Yaniv Rosner7aa07112010-09-07 11:41:01 +00002485
2486static void bnx2x_xgxs_an_resolve(struct bnx2x_phy *phy,
2487 struct link_params *params,
2488 struct link_vars *vars,
2489 u32 gp_status)
2490{
2491 if (gp_status & MDIO_AN_CL73_OR_37_COMPLETE)
2492 vars->link_status |=
2493 LINK_STATUS_AUTO_NEGOTIATE_COMPLETE;
2494
2495 if (bnx2x_direct_parallel_detect_used(phy, params))
2496 vars->link_status |=
2497 LINK_STATUS_PARALLEL_DETECTION_USED;
2498}
2499
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00002500static u8 bnx2x_link_settings_status(struct bnx2x_phy *phy,
2501 struct link_params *params,
2502 struct link_vars *vars)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002503{
2504 struct bnx2x *bp = params->bp;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002505 u16 new_line_speed, gp_status;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002506 u8 rc = 0;
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00002507
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00002508 /* Read gp_status */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002509 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002510 MDIO_REG_BANK_GP_STATUS,
2511 MDIO_GP_STATUS_TOP_AN_STATUS1,
2512 &gp_status);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00002513
Yaniv Rosner7aa07112010-09-07 11:41:01 +00002514 if (phy->req_line_speed == SPEED_AUTO_NEG)
2515 vars->link_status |= LINK_STATUS_AUTO_NEGOTIATE_ENABLED;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002516 if (gp_status & MDIO_GP_STATUS_TOP_AN_STATUS1_LINK_STATUS) {
2517 DP(NETIF_MSG_LINK, "phy link up gp_status=0x%x\n",
2518 gp_status);
2519
2520 vars->phy_link_up = 1;
2521 vars->link_status |= LINK_STATUS_LINK_UP;
2522
2523 if (gp_status & MDIO_GP_STATUS_TOP_AN_STATUS1_DUPLEX_STATUS)
2524 vars->duplex = DUPLEX_FULL;
2525 else
2526 vars->duplex = DUPLEX_HALF;
2527
Yaniv Rosner7aa07112010-09-07 11:41:01 +00002528 if (SINGLE_MEDIA_DIRECT(params)) {
2529 bnx2x_flow_ctrl_resolve(phy, params, vars, gp_status);
2530 if (phy->req_line_speed == SPEED_AUTO_NEG)
2531 bnx2x_xgxs_an_resolve(phy, params, vars,
2532 gp_status);
2533 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002534
2535 switch (gp_status & GP_STATUS_SPEED_MASK) {
2536 case GP_STATUS_10M:
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00002537 new_line_speed = SPEED_10;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002538 if (vars->duplex == DUPLEX_FULL)
2539 vars->link_status |= LINK_10TFD;
2540 else
2541 vars->link_status |= LINK_10THD;
2542 break;
2543
2544 case GP_STATUS_100M:
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00002545 new_line_speed = SPEED_100;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002546 if (vars->duplex == DUPLEX_FULL)
2547 vars->link_status |= LINK_100TXFD;
2548 else
2549 vars->link_status |= LINK_100TXHD;
2550 break;
2551
2552 case GP_STATUS_1G:
2553 case GP_STATUS_1G_KX:
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00002554 new_line_speed = SPEED_1000;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002555 if (vars->duplex == DUPLEX_FULL)
2556 vars->link_status |= LINK_1000TFD;
2557 else
2558 vars->link_status |= LINK_1000THD;
2559 break;
2560
2561 case GP_STATUS_2_5G:
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00002562 new_line_speed = SPEED_2500;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002563 if (vars->duplex == DUPLEX_FULL)
2564 vars->link_status |= LINK_2500TFD;
2565 else
2566 vars->link_status |= LINK_2500THD;
2567 break;
2568
2569 case GP_STATUS_5G:
2570 case GP_STATUS_6G:
2571 DP(NETIF_MSG_LINK,
2572 "link speed unsupported gp_status 0x%x\n",
2573 gp_status);
2574 return -EINVAL;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00002575
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002576 case GP_STATUS_10G_KX4:
2577 case GP_STATUS_10G_HIG:
2578 case GP_STATUS_10G_CX4:
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00002579 new_line_speed = SPEED_10000;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002580 vars->link_status |= LINK_10GTFD;
2581 break;
2582
2583 case GP_STATUS_12G_HIG:
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00002584 new_line_speed = SPEED_12000;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002585 vars->link_status |= LINK_12GTFD;
2586 break;
2587
2588 case GP_STATUS_12_5G:
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00002589 new_line_speed = SPEED_12500;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002590 vars->link_status |= LINK_12_5GTFD;
2591 break;
2592
2593 case GP_STATUS_13G:
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00002594 new_line_speed = SPEED_13000;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002595 vars->link_status |= LINK_13GTFD;
2596 break;
2597
2598 case GP_STATUS_15G:
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00002599 new_line_speed = SPEED_15000;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002600 vars->link_status |= LINK_15GTFD;
2601 break;
2602
2603 case GP_STATUS_16G:
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00002604 new_line_speed = SPEED_16000;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002605 vars->link_status |= LINK_16GTFD;
2606 break;
2607
2608 default:
2609 DP(NETIF_MSG_LINK,
2610 "link speed unsupported gp_status 0x%x\n",
2611 gp_status);
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00002612 return -EINVAL;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002613 }
2614
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00002615 vars->line_speed = new_line_speed;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002616
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002617 } else { /* link_down */
2618 DP(NETIF_MSG_LINK, "phy link down\n");
2619
2620 vars->phy_link_up = 0;
Yaniv Rosner57963ed2008-08-13 15:55:28 -07002621
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002622 vars->duplex = DUPLEX_FULL;
David S. Millerc0700f92008-12-16 23:53:20 -08002623 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002624 vars->mac_type = MAC_TYPE_NONE;
Eilon Greenstein239d6862009-08-12 08:23:04 +00002625
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00002626 if ((phy->req_line_speed == SPEED_AUTO_NEG) &&
2627 SINGLE_MEDIA_DIRECT(params)) {
Eilon Greenstein239d6862009-08-12 08:23:04 +00002628 /* Check signal is detected */
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00002629 bnx2x_check_fallback_to_cl37(phy, params);
Eilon Greenstein239d6862009-08-12 08:23:04 +00002630 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002631 }
2632
Frans Pop2381a552010-03-24 07:57:36 +00002633 DP(NETIF_MSG_LINK, "gp_status 0x%x phy_link_up %x line_speed %x\n",
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002634 gp_status, vars->phy_link_up, vars->line_speed);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002635 DP(NETIF_MSG_LINK, "duplex %x flow_ctrl 0x%x link_status 0x%x\n",
2636 vars->duplex, vars->flow_ctrl, vars->link_status);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002637 return rc;
2638}
2639
Eilon Greensteined8680a2009-02-12 08:37:12 +00002640static void bnx2x_set_gmii_tx_driver(struct link_params *params)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002641{
2642 struct bnx2x *bp = params->bp;
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002643 struct bnx2x_phy *phy = &params->phy[INT_PHY];
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002644 u16 lp_up2;
2645 u16 tx_driver;
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00002646 u16 bank;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002647
2648 /* read precomp */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002649 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002650 MDIO_REG_BANK_OVER_1G,
2651 MDIO_OVER_1G_LP_UP2, &lp_up2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002652
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002653 /* bits [10:7] at lp_up2, positioned at [15:12] */
2654 lp_up2 = (((lp_up2 & MDIO_OVER_1G_LP_UP2_PREEMPHASIS_MASK) >>
2655 MDIO_OVER_1G_LP_UP2_PREEMPHASIS_SHIFT) <<
2656 MDIO_TX0_TX_DRIVER_PREEMPHASIS_SHIFT);
2657
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00002658 if (lp_up2 == 0)
2659 return;
2660
2661 for (bank = MDIO_REG_BANK_TX0; bank <= MDIO_REG_BANK_TX3;
2662 bank += (MDIO_REG_BANK_TX1 - MDIO_REG_BANK_TX0)) {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002663 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002664 bank,
2665 MDIO_TX0_TX_DRIVER, &tx_driver);
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00002666
2667 /* replace tx_driver bits [15:12] */
2668 if (lp_up2 !=
2669 (tx_driver & MDIO_TX0_TX_DRIVER_PREEMPHASIS_MASK)) {
2670 tx_driver &= ~MDIO_TX0_TX_DRIVER_PREEMPHASIS_MASK;
2671 tx_driver |= lp_up2;
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002672 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002673 bank,
2674 MDIO_TX0_TX_DRIVER, tx_driver);
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00002675 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002676 }
2677}
2678
2679static u8 bnx2x_emac_program(struct link_params *params,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00002680 struct link_vars *vars)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002681{
2682 struct bnx2x *bp = params->bp;
2683 u8 port = params->port;
2684 u16 mode = 0;
2685
2686 DP(NETIF_MSG_LINK, "setting link speed & duplex\n");
2687 bnx2x_bits_dis(bp, GRCBASE_EMAC0 + port*0x400 +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002688 EMAC_REG_EMAC_MODE,
2689 (EMAC_MODE_25G_MODE |
2690 EMAC_MODE_PORT_MII_10M |
2691 EMAC_MODE_HALF_DUPLEX));
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00002692 switch (vars->line_speed) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002693 case SPEED_10:
2694 mode |= EMAC_MODE_PORT_MII_10M;
2695 break;
2696
2697 case SPEED_100:
2698 mode |= EMAC_MODE_PORT_MII;
2699 break;
2700
2701 case SPEED_1000:
2702 mode |= EMAC_MODE_PORT_GMII;
2703 break;
2704
2705 case SPEED_2500:
2706 mode |= (EMAC_MODE_25G_MODE | EMAC_MODE_PORT_GMII);
2707 break;
2708
2709 default:
2710 /* 10G not valid for EMAC */
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00002711 DP(NETIF_MSG_LINK, "Invalid line_speed 0x%x\n",
2712 vars->line_speed);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002713 return -EINVAL;
2714 }
2715
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00002716 if (vars->duplex == DUPLEX_HALF)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002717 mode |= EMAC_MODE_HALF_DUPLEX;
2718 bnx2x_bits_en(bp,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002719 GRCBASE_EMAC0 + port*0x400 + EMAC_REG_EMAC_MODE,
2720 mode);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002721
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00002722 bnx2x_set_led(params, vars, LED_MODE_OPER, vars->line_speed);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002723 return 0;
2724}
2725
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00002726static void bnx2x_set_preemphasis(struct bnx2x_phy *phy,
2727 struct link_params *params)
2728{
2729
2730 u16 bank, i = 0;
2731 struct bnx2x *bp = params->bp;
2732
2733 for (bank = MDIO_REG_BANK_RX0, i = 0; bank <= MDIO_REG_BANK_RX3;
2734 bank += (MDIO_REG_BANK_RX1-MDIO_REG_BANK_RX0), i++) {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002735 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00002736 bank,
2737 MDIO_RX0_RX_EQ_BOOST,
2738 phy->rx_preemphasis[i]);
2739 }
2740
2741 for (bank = MDIO_REG_BANK_TX0, i = 0; bank <= MDIO_REG_BANK_TX3;
2742 bank += (MDIO_REG_BANK_TX1 - MDIO_REG_BANK_TX0), i++) {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00002743 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00002744 bank,
2745 MDIO_TX0_TX_DRIVER,
2746 phy->tx_preemphasis[i]);
2747 }
2748}
2749
2750static void bnx2x_init_internal_phy(struct bnx2x_phy *phy,
2751 struct link_params *params,
2752 struct link_vars *vars)
2753{
2754 struct bnx2x *bp = params->bp;
2755 u8 enable_cl73 = (SINGLE_MEDIA_DIRECT(params) ||
2756 (params->loopback_mode == LOOPBACK_XGXS));
2757 if (!(vars->phy_flags & PHY_SGMII_FLAG)) {
2758 if (SINGLE_MEDIA_DIRECT(params) &&
2759 (params->feature_config_flags &
2760 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED))
2761 bnx2x_set_preemphasis(phy, params);
2762
2763 /* forced speed requested? */
2764 if (vars->line_speed != SPEED_AUTO_NEG ||
2765 (SINGLE_MEDIA_DIRECT(params) &&
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002766 params->loopback_mode == LOOPBACK_EXT)) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00002767 DP(NETIF_MSG_LINK, "not SGMII, no AN\n");
2768
2769 /* disable autoneg */
2770 bnx2x_set_autoneg(phy, params, vars, 0);
2771
2772 /* program speed and duplex */
2773 bnx2x_program_serdes(phy, params, vars);
2774
2775 } else { /* AN_mode */
2776 DP(NETIF_MSG_LINK, "not SGMII, AN\n");
2777
2778 /* AN enabled */
2779 bnx2x_set_brcm_cl37_advertisment(phy, params);
2780
2781 /* program duplex & pause advertisement (for aneg) */
2782 bnx2x_set_ieee_aneg_advertisment(phy, params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002783 vars->ieee_fc);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00002784
2785 /* enable autoneg */
2786 bnx2x_set_autoneg(phy, params, vars, enable_cl73);
2787
2788 /* enable and restart AN */
2789 bnx2x_restart_autoneg(phy, params, enable_cl73);
2790 }
2791
2792 } else { /* SGMII mode */
2793 DP(NETIF_MSG_LINK, "SGMII\n");
2794
2795 bnx2x_initialize_sgmii_process(phy, params, vars);
2796 }
2797}
2798
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00002799static u8 bnx2x_init_serdes(struct bnx2x_phy *phy,
2800 struct link_params *params,
2801 struct link_vars *vars)
2802{
2803 u8 rc;
2804 vars->phy_flags |= PHY_SGMII_FLAG;
2805 bnx2x_calc_ieee_aneg_adv(phy, params, &vars->ieee_fc);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002806 bnx2x_set_aer_mmd_serdes(params->bp, phy);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00002807 rc = bnx2x_reset_unicore(params, phy, 1);
2808 /* reset the SerDes and wait for reset bit return low */
2809 if (rc != 0)
2810 return rc;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002811 bnx2x_set_aer_mmd_serdes(params->bp, phy);
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002812
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00002813 return rc;
2814}
2815
2816static u8 bnx2x_init_xgxs(struct bnx2x_phy *phy,
2817 struct link_params *params,
2818 struct link_vars *vars)
2819{
2820 u8 rc;
2821 vars->phy_flags = PHY_XGXS_FLAG;
2822 if ((phy->req_line_speed &&
2823 ((phy->req_line_speed == SPEED_100) ||
2824 (phy->req_line_speed == SPEED_10))) ||
2825 (!phy->req_line_speed &&
2826 (phy->speed_cap_mask >=
2827 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL) &&
2828 (phy->speed_cap_mask <
2829 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)
2830 ))
2831 vars->phy_flags |= PHY_SGMII_FLAG;
2832 else
2833 vars->phy_flags &= ~PHY_SGMII_FLAG;
2834
2835 bnx2x_calc_ieee_aneg_adv(phy, params, &vars->ieee_fc);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002836 bnx2x_set_aer_mmd_xgxs(params, phy);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00002837 bnx2x_set_master_ln(params, phy);
2838
2839 rc = bnx2x_reset_unicore(params, phy, 0);
2840 /* reset the SerDes and wait for reset bit return low */
2841 if (rc != 0)
2842 return rc;
2843
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002844 bnx2x_set_aer_mmd_xgxs(params, phy);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00002845
2846 /* setting the masterLn_def again after the reset */
2847 bnx2x_set_master_ln(params, phy);
2848 bnx2x_set_swap_lanes(params, phy);
2849
2850 return rc;
2851}
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00002852
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00002853static u16 bnx2x_wait_reset_complete(struct bnx2x *bp,
Yaniv Rosner6d870c32011-01-31 04:22:20 +00002854 struct bnx2x_phy *phy,
2855 struct link_params *params)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002856{
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00002857 u16 cnt, ctrl;
Yaniv Rosner62b29a52010-09-07 11:40:58 +00002858 /* Wait for soft reset to get cleared upto 1 sec */
2859 for (cnt = 0; cnt < 1000; cnt++) {
2860 bnx2x_cl45_read(bp, phy,
2861 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, &ctrl);
2862 if (!(ctrl & (1<<15)))
2863 break;
2864 msleep(1);
2865 }
Yaniv Rosner6d870c32011-01-31 04:22:20 +00002866
2867 if (cnt == 1000)
2868 netdev_err(bp->dev, "Warning: PHY was not initialized,"
2869 " Port %d\n",
2870 params->port);
Yaniv Rosner62b29a52010-09-07 11:40:58 +00002871 DP(NETIF_MSG_LINK, "control reg 0x%x (after %d ms)\n", ctrl, cnt);
2872 return cnt;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00002873}
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002874
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002875static void bnx2x_link_int_enable(struct link_params *params)
2876{
2877 u8 port = params->port;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002878 u32 mask;
2879 struct bnx2x *bp = params->bp;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00002880
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002881 /* Setting the status to report on link up for either XGXS or SerDes */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002882 if (params->switch_cfg == SWITCH_CFG_10G) {
2883 mask = (NIG_MASK_XGXS0_LINK10G |
2884 NIG_MASK_XGXS0_LINK_STATUS);
2885 DP(NETIF_MSG_LINK, "enabled XGXS interrupt\n");
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002886 if (!(SINGLE_MEDIA_DIRECT(params)) &&
2887 params->phy[INT_PHY].type !=
2888 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002889 mask |= NIG_MASK_MI_INT;
2890 DP(NETIF_MSG_LINK, "enabled external phy int\n");
2891 }
2892
2893 } else { /* SerDes */
2894 mask = NIG_MASK_SERDES0_LINK_STATUS;
2895 DP(NETIF_MSG_LINK, "enabled SerDes interrupt\n");
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002896 if (!(SINGLE_MEDIA_DIRECT(params)) &&
2897 params->phy[INT_PHY].type !=
2898 PORT_HW_CFG_SERDES_EXT_PHY_TYPE_NOT_CONN) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002899 mask |= NIG_MASK_MI_INT;
2900 DP(NETIF_MSG_LINK, "enabled external phy int\n");
2901 }
2902 }
2903 bnx2x_bits_en(bp,
2904 NIG_REG_MASK_INTERRUPT_PORT0 + port*4,
2905 mask);
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00002906
2907 DP(NETIF_MSG_LINK, "port %x, is_xgxs %x, int_status 0x%x\n", port,
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002908 (params->switch_cfg == SWITCH_CFG_10G),
2909 REG_RD(bp, NIG_REG_STATUS_INTERRUPT_PORT0 + port*4));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002910 DP(NETIF_MSG_LINK, " int_mask 0x%x, MI_INT %x, SERDES_LINK %x\n",
2911 REG_RD(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4),
2912 REG_RD(bp, NIG_REG_EMAC0_STATUS_MISC_MI_INT + port*0x18),
2913 REG_RD(bp, NIG_REG_SERDES0_STATUS_LINK_STATUS+port*0x3c));
2914 DP(NETIF_MSG_LINK, " 10G %x, XGXS_LINK %x\n",
2915 REG_RD(bp, NIG_REG_XGXS0_STATUS_LINK10G + port*0x68),
2916 REG_RD(bp, NIG_REG_XGXS0_STATUS_LINK_STATUS + port*0x68));
2917}
2918
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002919static void bnx2x_rearm_latch_signal(struct bnx2x *bp, u8 port,
2920 u8 exp_mi_int)
Eilon Greenstein2f904462009-08-12 08:22:16 +00002921{
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002922 u32 latch_status = 0;
2923
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002924 /*
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002925 * Disable the MI INT ( external phy int ) by writing 1 to the
2926 * status register. Link down indication is high-active-signal,
2927 * so in this case we need to write the status to clear the XOR
Eilon Greenstein2f904462009-08-12 08:22:16 +00002928 */
2929 /* Read Latched signals */
2930 latch_status = REG_RD(bp,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002931 NIG_REG_LATCH_STATUS_0 + port*8);
2932 DP(NETIF_MSG_LINK, "latch_status = 0x%x\n", latch_status);
Eilon Greenstein2f904462009-08-12 08:22:16 +00002933 /* Handle only those with latched-signal=up.*/
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002934 if (exp_mi_int)
2935 bnx2x_bits_en(bp,
2936 NIG_REG_STATUS_INTERRUPT_PORT0
2937 + port*4,
2938 NIG_STATUS_EMAC0_MI_INT);
2939 else
2940 bnx2x_bits_dis(bp,
2941 NIG_REG_STATUS_INTERRUPT_PORT0
2942 + port*4,
2943 NIG_STATUS_EMAC0_MI_INT);
2944
Eilon Greenstein2f904462009-08-12 08:22:16 +00002945 if (latch_status & 1) {
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002946
Eilon Greenstein2f904462009-08-12 08:22:16 +00002947 /* For all latched-signal=up : Re-Arm Latch signals */
2948 REG_WR(bp, NIG_REG_LATCH_STATUS_0 + port*8,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002949 (latch_status & 0xfffe) | (latch_status & 1));
Eilon Greenstein2f904462009-08-12 08:22:16 +00002950 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002951 /* For all latched-signal=up,Write original_signal to status */
Eilon Greenstein2f904462009-08-12 08:22:16 +00002952}
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002953
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002954static void bnx2x_link_int_ack(struct link_params *params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002955 struct link_vars *vars, u8 is_10g)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002956{
2957 struct bnx2x *bp = params->bp;
2958 u8 port = params->port;
2959
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002960 /*
2961 * First reset all status we assume only one line will be
2962 * change at a time
2963 */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002964 bnx2x_bits_dis(bp, NIG_REG_STATUS_INTERRUPT_PORT0 + port*4,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002965 (NIG_STATUS_XGXS0_LINK10G |
2966 NIG_STATUS_XGXS0_LINK_STATUS |
2967 NIG_STATUS_SERDES0_LINK_STATUS));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002968 if (vars->phy_link_up) {
2969 if (is_10g) {
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002970 /*
2971 * Disable the 10G link interrupt by writing 1 to the
2972 * status register
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002973 */
2974 DP(NETIF_MSG_LINK, "10G XGXS phy link up\n");
2975 bnx2x_bits_en(bp,
2976 NIG_REG_STATUS_INTERRUPT_PORT0 + port*4,
2977 NIG_STATUS_XGXS0_LINK10G);
2978
2979 } else if (params->switch_cfg == SWITCH_CFG_10G) {
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002980 /*
2981 * Disable the link interrupt by writing 1 to the
2982 * relevant lane in the status register
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002983 */
2984 u32 ser_lane = ((params->lane_config &
2985 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_MASK) >>
2986 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_SHIFT);
2987
Eilon Greenstein2f904462009-08-12 08:22:16 +00002988 DP(NETIF_MSG_LINK, "%d speed XGXS phy link up\n",
2989 vars->line_speed);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002990 bnx2x_bits_en(bp,
2991 NIG_REG_STATUS_INTERRUPT_PORT0 + port*4,
2992 ((1 << ser_lane) <<
2993 NIG_STATUS_XGXS0_LINK_STATUS_SIZE));
2994
2995 } else { /* SerDes */
2996 DP(NETIF_MSG_LINK, "SerDes phy link up\n");
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002997 /*
2998 * Disable the link interrupt by writing 1 to the status
2999 * register
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003000 */
3001 bnx2x_bits_en(bp,
3002 NIG_REG_STATUS_INTERRUPT_PORT0 + port*4,
3003 NIG_STATUS_SERDES0_LINK_STATUS);
3004 }
3005
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003006 }
3007}
3008
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003009static u8 bnx2x_format_ver(u32 num, u8 *str, u16 *len)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003010{
3011 u8 *str_ptr = str;
3012 u32 mask = 0xf0000000;
3013 u8 shift = 8*4;
3014 u8 digit;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003015 u8 remove_leading_zeros = 1;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003016 if (*len < 10) {
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02003017 /* Need more than 10chars for this format */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003018 *str_ptr = '\0';
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003019 (*len)--;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003020 return -EINVAL;
3021 }
3022 while (shift > 0) {
3023
3024 shift -= 4;
3025 digit = ((num & mask) >> shift);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003026 if (digit == 0 && remove_leading_zeros) {
3027 mask = mask >> 4;
3028 continue;
3029 } else if (digit < 0xa)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003030 *str_ptr = digit + '0';
3031 else
3032 *str_ptr = digit - 0xa + 'a';
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003033 remove_leading_zeros = 0;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003034 str_ptr++;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003035 (*len)--;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003036 mask = mask >> 4;
3037 if (shift == 4*4) {
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003038 *str_ptr = '.';
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003039 str_ptr++;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003040 (*len)--;
3041 remove_leading_zeros = 1;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003042 }
3043 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003044 return 0;
3045}
3046
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003047
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003048static u8 bnx2x_null_format_ver(u32 spirom_ver, u8 *str, u16 *len)
3049{
3050 str[0] = '\0';
3051 (*len)--;
3052 return 0;
3053}
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003054
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003055u8 bnx2x_get_ext_phy_fw_version(struct link_params *params, u8 driver_loaded,
3056 u8 *version, u16 len)
3057{
Julia Lawall0376d5b2009-07-19 05:26:35 +00003058 struct bnx2x *bp;
Eilon Greensteina35da8d2009-02-12 08:37:02 +00003059 u32 spirom_ver = 0;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003060 u8 status = 0;
3061 u8 *ver_p = version;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003062 u16 remain_len = len;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003063 if (version == NULL || params == NULL)
3064 return -EINVAL;
Julia Lawall0376d5b2009-07-19 05:26:35 +00003065 bp = params->bp;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003066
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003067 /* Extract first external phy*/
3068 version[0] = '\0';
3069 spirom_ver = REG_RD(bp, params->phy[EXT_PHY1].ver_addr);
Eilon Greensteina35da8d2009-02-12 08:37:02 +00003070
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003071 if (params->phy[EXT_PHY1].format_fw_ver) {
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003072 status |= params->phy[EXT_PHY1].format_fw_ver(spirom_ver,
3073 ver_p,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003074 &remain_len);
3075 ver_p += (len - remain_len);
3076 }
3077 if ((params->num_phys == MAX_PHYS) &&
3078 (params->phy[EXT_PHY2].ver_addr != 0)) {
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003079 spirom_ver = REG_RD(bp, params->phy[EXT_PHY2].ver_addr);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003080 if (params->phy[EXT_PHY2].format_fw_ver) {
3081 *ver_p = '/';
3082 ver_p++;
3083 remain_len--;
3084 status |= params->phy[EXT_PHY2].format_fw_ver(
3085 spirom_ver,
3086 ver_p,
3087 &remain_len);
3088 ver_p = version + (len - remain_len);
3089 }
3090 }
3091 *ver_p = '\0';
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003092 return status;
3093}
3094
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003095static void bnx2x_set_xgxs_loopback(struct bnx2x_phy *phy,
Yaniv Rosner62b29a52010-09-07 11:40:58 +00003096 struct link_params *params)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003097{
3098 u8 port = params->port;
3099 struct bnx2x *bp = params->bp;
3100
Yaniv Rosner62b29a52010-09-07 11:40:58 +00003101 if (phy->req_line_speed != SPEED_1000) {
Eilon Greenstein6378c022008-08-13 15:59:25 -07003102 u32 md_devad;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003103
3104 DP(NETIF_MSG_LINK, "XGXS 10G loopback enable\n");
3105
3106 /* change the uni_phy_addr in the nig */
3107 md_devad = REG_RD(bp, (NIG_REG_XGXS0_CTRL_MD_DEVAD +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003108 port*0x18));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003109
3110 REG_WR(bp, NIG_REG_XGXS0_CTRL_MD_DEVAD + port*0x18, 0x5);
3111
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003112 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003113 5,
3114 (MDIO_REG_BANK_AER_BLOCK +
3115 (MDIO_AER_BLOCK_AER_REG & 0xf)),
3116 0x2800);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003117
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003118 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003119 5,
3120 (MDIO_REG_BANK_CL73_IEEEB0 +
3121 (MDIO_CL73_IEEEB0_CL73_AN_CONTROL & 0xf)),
3122 0x6041);
Eilon Greenstein38582762009-01-14 06:44:16 +00003123 msleep(200);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003124 /* set aer mmd back */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00003125 bnx2x_set_aer_mmd_xgxs(params, phy);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003126
3127 /* and md_devad */
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003128 REG_WR(bp, NIG_REG_XGXS0_CTRL_MD_DEVAD + port*0x18, md_devad);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003129 } else {
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003130 u16 mii_ctrl;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003131 DP(NETIF_MSG_LINK, "XGXS 1G loopback enable\n");
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003132 bnx2x_cl45_read(bp, phy, 5,
3133 (MDIO_REG_BANK_COMBO_IEEE0 +
3134 (MDIO_COMBO_IEEE0_MII_CONTROL & 0xf)),
3135 &mii_ctrl);
3136 bnx2x_cl45_write(bp, phy, 5,
3137 (MDIO_REG_BANK_COMBO_IEEE0 +
3138 (MDIO_COMBO_IEEE0_MII_CONTROL & 0xf)),
3139 mii_ctrl |
3140 MDIO_COMBO_IEEO_MII_CONTROL_LOOPBACK);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003141 }
3142}
3143
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00003144u8 bnx2x_set_led(struct link_params *params,
3145 struct link_vars *vars, u8 mode, u32 speed)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003146{
Yaniv Rosner7846e472009-11-05 19:18:07 +02003147 u8 port = params->port;
3148 u16 hw_led_mode = params->hw_led_mode;
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00003149 u8 rc = 0, phy_idx;
Eilon Greenstein345b5d52008-08-13 15:58:12 -07003150 u32 tmp;
3151 u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
Yaniv Rosner7846e472009-11-05 19:18:07 +02003152 struct bnx2x *bp = params->bp;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003153 DP(NETIF_MSG_LINK, "bnx2x_set_led: port %x, mode %d\n", port, mode);
3154 DP(NETIF_MSG_LINK, "speed 0x%x, hw_led_mode 0x%x\n",
3155 speed, hw_led_mode);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00003156 /* In case */
3157 for (phy_idx = EXT_PHY1; phy_idx < MAX_PHYS; phy_idx++) {
3158 if (params->phy[phy_idx].set_link_led) {
3159 params->phy[phy_idx].set_link_led(
3160 &params->phy[phy_idx], params, mode);
3161 }
3162 }
3163
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003164 switch (mode) {
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00003165 case LED_MODE_FRONT_PANEL_OFF:
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003166 case LED_MODE_OFF:
3167 REG_WR(bp, NIG_REG_LED_10G_P0 + port*4, 0);
3168 REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003169 SHARED_HW_CFG_LED_MAC1);
Eilon Greenstein345b5d52008-08-13 15:58:12 -07003170
3171 tmp = EMAC_RD(bp, EMAC_REG_EMAC_LED);
Eilon Greenstein3196a882008-08-13 15:58:49 -07003172 EMAC_WR(bp, EMAC_REG_EMAC_LED, (tmp | EMAC_LED_OVERRIDE));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003173 break;
3174
3175 case LED_MODE_OPER:
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003176 /*
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00003177 * For all other phys, OPER mode is same as ON, so in case
3178 * link is down, do nothing
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003179 */
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00003180 if (!vars->link_up)
3181 break;
3182 case LED_MODE_ON:
Yaniv Rosner1f483532011-01-18 04:33:31 +00003183 if (params->phy[EXT_PHY1].type ==
3184 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727 &&
3185 CHIP_IS_E2(bp) && params->num_phys == 2) {
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003186 /*
3187 * This is a work-around for E2+8727 Configurations
3188 */
Yaniv Rosner1f483532011-01-18 04:33:31 +00003189 if (mode == LED_MODE_ON ||
3190 speed == SPEED_10000){
3191 REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4, 0);
3192 REG_WR(bp, NIG_REG_LED_10G_P0 + port*4, 1);
3193
3194 tmp = EMAC_RD(bp, EMAC_REG_EMAC_LED);
3195 EMAC_WR(bp, EMAC_REG_EMAC_LED,
3196 (tmp | EMAC_LED_OVERRIDE));
3197 return rc;
3198 }
3199 } else if (SINGLE_MEDIA_DIRECT(params)) {
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003200 /*
3201 * This is a work-around for HW issue found when link
3202 * is up in CL73
3203 */
Yaniv Rosner7846e472009-11-05 19:18:07 +02003204 REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4, 0);
3205 REG_WR(bp, NIG_REG_LED_10G_P0 + port*4, 1);
3206 } else {
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003207 REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4, hw_led_mode);
Yaniv Rosner7846e472009-11-05 19:18:07 +02003208 }
3209
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003210 REG_WR(bp, NIG_REG_LED_CONTROL_OVERRIDE_TRAFFIC_P0 + port*4, 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003211 /* Set blinking rate to ~15.9Hz */
3212 REG_WR(bp, NIG_REG_LED_CONTROL_BLINK_RATE_P0 + port*4,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003213 LED_BLINK_RATE_VAL);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003214 REG_WR(bp, NIG_REG_LED_CONTROL_BLINK_RATE_ENA_P0 +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003215 port*4, 1);
Eilon Greenstein345b5d52008-08-13 15:58:12 -07003216 tmp = EMAC_RD(bp, EMAC_REG_EMAC_LED);
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003217 EMAC_WR(bp, EMAC_REG_EMAC_LED, (tmp & (~EMAC_LED_OVERRIDE)));
Eilon Greenstein345b5d52008-08-13 15:58:12 -07003218
Yaniv Rosner7846e472009-11-05 19:18:07 +02003219 if (CHIP_IS_E1(bp) &&
Eilon Greenstein34f80b02008-06-23 20:33:01 -07003220 ((speed == SPEED_2500) ||
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003221 (speed == SPEED_1000) ||
3222 (speed == SPEED_100) ||
3223 (speed == SPEED_10))) {
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003224 /*
3225 * On Everest 1 Ax chip versions for speeds less than
3226 * 10G LED scheme is different
3227 */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003228 REG_WR(bp, NIG_REG_LED_CONTROL_OVERRIDE_TRAFFIC_P0
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003229 + port*4, 1);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003230 REG_WR(bp, NIG_REG_LED_CONTROL_TRAFFIC_P0 +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003231 port*4, 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003232 REG_WR(bp, NIG_REG_LED_CONTROL_BLINK_TRAFFIC_P0 +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003233 port*4, 1);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003234 }
3235 break;
3236
3237 default:
3238 rc = -EINVAL;
3239 DP(NETIF_MSG_LINK, "bnx2x_set_led: Invalid led mode %d\n",
3240 mode);
3241 break;
3242 }
3243 return rc;
3244
3245}
3246
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003247/*
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003248 * This function comes to reflect the actual link state read DIRECTLY from the
3249 * HW
3250 */
3251u8 bnx2x_test_link(struct link_params *params, struct link_vars *vars,
3252 u8 is_serdes)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003253{
3254 struct bnx2x *bp = params->bp;
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00003255 u16 gp_status = 0, phy_index = 0;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003256 u8 ext_phy_link_up = 0, serdes_phy_type;
3257 struct link_vars temp_vars;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003258
Yaniv Rosnercd2be892011-01-31 04:21:45 +00003259 CL22_RD_OVER_CL45(bp, &params->phy[INT_PHY],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003260 MDIO_REG_BANK_GP_STATUS,
3261 MDIO_GP_STATUS_TOP_AN_STATUS1,
3262 &gp_status);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003263 /* link is up only if both local phy and external phy are up */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003264 if (!(gp_status & MDIO_GP_STATUS_TOP_AN_STATUS1_LINK_STATUS))
3265 return -ESRCH;
3266
3267 switch (params->num_phys) {
3268 case 1:
3269 /* No external PHY */
3270 return 0;
3271 case 2:
3272 ext_phy_link_up = params->phy[EXT_PHY1].read_status(
3273 &params->phy[EXT_PHY1],
3274 params, &temp_vars);
3275 break;
3276 case 3: /* Dual Media */
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00003277 for (phy_index = EXT_PHY1; phy_index < params->num_phys;
3278 phy_index++) {
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003279 serdes_phy_type = ((params->phy[phy_index].media_type ==
3280 ETH_PHY_SFP_FIBER) ||
3281 (params->phy[phy_index].media_type ==
3282 ETH_PHY_XFP_FIBER));
3283
3284 if (is_serdes != serdes_phy_type)
3285 continue;
3286 if (params->phy[phy_index].read_status) {
3287 ext_phy_link_up |=
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00003288 params->phy[phy_index].read_status(
3289 &params->phy[phy_index],
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003290 params, &temp_vars);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003291 }
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00003292 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003293 break;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003294 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003295 if (ext_phy_link_up)
3296 return 0;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003297 return -ESRCH;
3298}
3299
3300static u8 bnx2x_link_initialize(struct link_params *params,
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +00003301 struct link_vars *vars)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003302{
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003303 u8 rc = 0;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003304 u8 phy_index, non_ext_phy;
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00003305 struct bnx2x *bp = params->bp;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003306 /*
3307 * In case of external phy existence, the line speed would be the
3308 * line speed linked up by the external phy. In case it is direct
3309 * only, then the line_speed during initialization will be
3310 * equal to the req_line_speed
3311 */
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00003312 vars->line_speed = params->phy[INT_PHY].req_line_speed;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003313
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003314 /*
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00003315 * Initialize the internal phy in case this is a direct board
3316 * (no external phys), or this board has external phy which requires
3317 * to first.
3318 */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003319
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00003320 if (params->phy[INT_PHY].config_init)
3321 params->phy[INT_PHY].config_init(
3322 &params->phy[INT_PHY],
3323 params, vars);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003324
3325 /* init ext phy and enable link state int */
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00003326 non_ext_phy = (SINGLE_MEDIA_DIRECT(params) ||
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003327 (params->loopback_mode == LOOPBACK_XGXS));
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003328
3329 if (non_ext_phy ||
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00003330 (params->phy[EXT_PHY1].flags & FLAGS_INIT_XGXS_FIRST) ||
Eilon Greenstein8660d8c2009-03-02 08:01:02 +00003331 (params->loopback_mode == LOOPBACK_EXT_PHY)) {
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00003332 struct bnx2x_phy *phy = &params->phy[INT_PHY];
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003333 if (vars->line_speed == SPEED_AUTO_NEG)
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00003334 bnx2x_set_parallel_detection(phy, params);
3335 bnx2x_init_internal_phy(phy, params, vars);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003336 }
3337
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00003338 /* Init external phy*/
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003339 if (!non_ext_phy)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003340 for (phy_index = EXT_PHY1; phy_index < params->num_phys;
3341 phy_index++) {
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003342 /*
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003343 * No need to initialize second phy in case of first
3344 * phy only selection. In case of second phy, we do
3345 * need to initialize the first phy, since they are
3346 * connected.
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003347 */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003348 if (phy_index == EXT_PHY2 &&
3349 (bnx2x_phy_selection(params) ==
3350 PORT_HW_CFG_PHY_SELECTION_FIRST_PHY)) {
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003351 DP(NETIF_MSG_LINK, "Ignoring second phy\n");
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003352 continue;
3353 }
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003354 params->phy[phy_index].config_init(
3355 &params->phy[phy_index],
3356 params, vars);
3357 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003358
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +00003359 /* Reset the interrupt indication after phy was initialized */
3360 bnx2x_bits_dis(bp, NIG_REG_STATUS_INTERRUPT_PORT0 +
3361 params->port*4,
3362 (NIG_STATUS_XGXS0_LINK10G |
3363 NIG_STATUS_XGXS0_LINK_STATUS |
3364 NIG_STATUS_SERDES0_LINK_STATUS |
3365 NIG_MASK_MI_INT));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003366 return rc;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003367}
3368
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003369static void bnx2x_int_link_reset(struct bnx2x_phy *phy,
3370 struct link_params *params)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003371{
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003372 /* reset the SerDes/XGXS */
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003373 REG_WR(params->bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_CLEAR,
3374 (0x1ff << (params->port*16)));
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003375}
3376
3377static void bnx2x_common_ext_link_reset(struct bnx2x_phy *phy,
3378 struct link_params *params)
3379{
3380 struct bnx2x *bp = params->bp;
3381 u8 gpio_port;
3382 /* HW reset */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00003383 if (CHIP_IS_E2(bp))
3384 gpio_port = BP_PATH(bp);
3385 else
3386 gpio_port = params->port;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003387 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003388 MISC_REGISTERS_GPIO_OUTPUT_LOW,
3389 gpio_port);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003390 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003391 MISC_REGISTERS_GPIO_OUTPUT_LOW,
3392 gpio_port);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003393 DP(NETIF_MSG_LINK, "reset external PHY\n");
3394}
3395
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003396static u8 bnx2x_update_link_down(struct link_params *params,
3397 struct link_vars *vars)
3398{
3399 struct bnx2x *bp = params->bp;
3400 u8 port = params->port;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00003401
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003402 DP(NETIF_MSG_LINK, "Port %x: Link is down\n", port);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00003403 bnx2x_set_led(params, vars, LED_MODE_OFF, 0);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003404
3405 /* indicate no mac active */
3406 vars->mac_type = MAC_TYPE_NONE;
3407
3408 /* update shared memory */
3409 vars->link_status = 0;
3410 vars->line_speed = 0;
3411 bnx2x_update_mng(params, vars->link_status);
3412
3413 /* activate nig drain */
3414 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + port*4, 1);
3415
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00003416 /* disable emac */
3417 REG_WR(bp, NIG_REG_NIG_EMAC0_EN + port*4, 0);
3418
3419 msleep(10);
3420
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003421 /* reset BigMac */
3422 bnx2x_bmac_rx_disable(bp, params->port);
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003423 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
3424 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port));
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003425 return 0;
3426}
3427
3428static u8 bnx2x_update_link_up(struct link_params *params,
3429 struct link_vars *vars,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003430 u8 link_10g)
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003431{
3432 struct bnx2x *bp = params->bp;
3433 u8 port = params->port;
3434 u8 rc = 0;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00003435
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003436 vars->link_status |= LINK_STATUS_LINK_UP;
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00003437
Yaniv Rosner7aa07112010-09-07 11:41:01 +00003438 if (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX)
3439 vars->link_status |=
3440 LINK_STATUS_TX_FLOW_CONTROL_ENABLED;
3441
3442 if (vars->flow_ctrl & BNX2X_FLOW_CTRL_RX)
3443 vars->link_status |=
3444 LINK_STATUS_RX_FLOW_CONTROL_ENABLED;
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00003445
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003446 if (link_10g) {
3447 bnx2x_bmac_enable(params, vars, 0);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00003448 bnx2x_set_led(params, vars,
3449 LED_MODE_OPER, SPEED_10000);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003450 } else {
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003451 rc = bnx2x_emac_program(params, vars);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003452
Yaniv Rosner0c786f02009-11-05 19:18:32 +02003453 bnx2x_emac_enable(params, vars, 0);
3454
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003455 /* AN complete? */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003456 if ((vars->link_status & LINK_STATUS_AUTO_NEGOTIATE_COMPLETE)
3457 && (!(vars->phy_flags & PHY_SGMII_FLAG)) &&
3458 SINGLE_MEDIA_DIRECT(params))
3459 bnx2x_set_gmii_tx_driver(params);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003460 }
3461
3462 /* PBF - link up */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00003463 if (!(CHIP_IS_E2(bp)))
3464 rc |= bnx2x_pbf_update(params, vars->flow_ctrl,
3465 vars->line_speed);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003466
3467 /* disable drain */
3468 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + port*4, 0);
3469
3470 /* update shared memory */
3471 bnx2x_update_mng(params, vars->link_status);
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00003472 msleep(20);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003473 return rc;
3474}
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003475/*
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003476 * The bnx2x_link_update function should be called upon link
3477 * interrupt.
3478 * Link is considered up as follows:
3479 * - DIRECT_SINGLE_MEDIA - Only XGXS link (internal link) needs
3480 * to be up
3481 * - SINGLE_MEDIA - The link between the 577xx and the external
3482 * phy (XGXS) need to up as well as the external link of the
3483 * phy (PHY_EXT1)
3484 * - DUAL_MEDIA - The link between the 577xx and the first
3485 * external phy needs to be up, and at least one of the 2
3486 * external phy link must be up.
Yaniv Rosner62b29a52010-09-07 11:40:58 +00003487 */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003488u8 bnx2x_link_update(struct link_params *params, struct link_vars *vars)
3489{
3490 struct bnx2x *bp = params->bp;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003491 struct link_vars phy_vars[MAX_PHYS];
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003492 u8 port = params->port;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003493 u8 link_10g, phy_index;
3494 u8 ext_phy_link_up = 0, cur_link_up, rc = 0;
Eilon Greenstein2f904462009-08-12 08:22:16 +00003495 u8 is_mi_int = 0;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003496 u16 ext_phy_line_speed = 0, prev_line_speed = vars->line_speed;
3497 u8 active_external_phy = INT_PHY;
3498 vars->link_status = 0;
3499 for (phy_index = INT_PHY; phy_index < params->num_phys;
3500 phy_index++) {
3501 phy_vars[phy_index].flow_ctrl = 0;
3502 phy_vars[phy_index].link_status = 0;
3503 phy_vars[phy_index].line_speed = 0;
3504 phy_vars[phy_index].duplex = DUPLEX_FULL;
3505 phy_vars[phy_index].phy_link_up = 0;
3506 phy_vars[phy_index].link_up = 0;
3507 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003508
3509 DP(NETIF_MSG_LINK, "port %x, XGXS?%x, int_status 0x%x\n",
Eilon Greenstein2f904462009-08-12 08:22:16 +00003510 port, (vars->phy_flags & PHY_XGXS_FLAG),
3511 REG_RD(bp, NIG_REG_STATUS_INTERRUPT_PORT0 + port*4));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003512
Eilon Greenstein2f904462009-08-12 08:22:16 +00003513 is_mi_int = (u8)(REG_RD(bp, NIG_REG_EMAC0_STATUS_MISC_MI_INT +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003514 port*0x18) > 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003515 DP(NETIF_MSG_LINK, "int_mask 0x%x MI_INT %x, SERDES_LINK %x\n",
Eilon Greenstein2f904462009-08-12 08:22:16 +00003516 REG_RD(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4),
3517 is_mi_int,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003518 REG_RD(bp, NIG_REG_SERDES0_STATUS_LINK_STATUS + port*0x3c));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003519
3520 DP(NETIF_MSG_LINK, " 10G %x, XGXS_LINK %x\n",
3521 REG_RD(bp, NIG_REG_XGXS0_STATUS_LINK10G + port*0x68),
3522 REG_RD(bp, NIG_REG_XGXS0_STATUS_LINK_STATUS + port*0x68));
3523
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00003524 /* disable emac */
3525 REG_WR(bp, NIG_REG_NIG_EMAC0_EN + port*4, 0);
3526
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003527 /*
3528 * Step 1:
3529 * Check external link change only for external phys, and apply
3530 * priority selection between them in case the link on both phys
3531 * is up. Note that the instead of the common vars, a temporary
3532 * vars argument is used since each phy may have different link/
3533 * speed/duplex result
3534 */
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003535 for (phy_index = EXT_PHY1; phy_index < params->num_phys;
3536 phy_index++) {
3537 struct bnx2x_phy *phy = &params->phy[phy_index];
3538 if (!phy->read_status)
3539 continue;
3540 /* Read link status and params of this ext phy */
3541 cur_link_up = phy->read_status(phy, params,
3542 &phy_vars[phy_index]);
3543 if (cur_link_up) {
3544 DP(NETIF_MSG_LINK, "phy in index %d link is up\n",
3545 phy_index);
3546 } else {
3547 DP(NETIF_MSG_LINK, "phy in index %d link is down\n",
3548 phy_index);
3549 continue;
3550 }
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003551
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003552 if (!ext_phy_link_up) {
3553 ext_phy_link_up = 1;
3554 active_external_phy = phy_index;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003555 } else {
3556 switch (bnx2x_phy_selection(params)) {
3557 case PORT_HW_CFG_PHY_SELECTION_HARDWARE_DEFAULT:
3558 case PORT_HW_CFG_PHY_SELECTION_FIRST_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 itself only.
3562 * Its not clear how to reset the link on the second phy
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003563 */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003564 active_external_phy = EXT_PHY1;
3565 break;
3566 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY_PRIORITY:
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003567 /*
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003568 * In this option, the first PHY makes sure to pass the
3569 * traffic through the second PHY.
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003570 */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003571 active_external_phy = EXT_PHY2;
3572 break;
3573 default:
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003574 /*
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003575 * Link indication on both PHYs with the following cases
3576 * is invalid:
3577 * - FIRST_PHY means that second phy wasn't initialized,
3578 * hence its link is expected to be down
3579 * - SECOND_PHY means that first phy should not be able
3580 * to link up by itself (using configuration)
3581 * - DEFAULT should be overriden during initialiazation
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003582 */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003583 DP(NETIF_MSG_LINK, "Invalid link indication"
3584 "mpc=0x%x. DISABLING LINK !!!\n",
3585 params->multi_phy_config);
3586 ext_phy_link_up = 0;
3587 break;
3588 }
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003589 }
3590 }
3591 prev_line_speed = vars->line_speed;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003592 /*
3593 * Step 2:
3594 * Read the status of the internal phy. In case of
3595 * DIRECT_SINGLE_MEDIA board, this link is the external link,
3596 * otherwise this is the link between the 577xx and the first
3597 * external phy
3598 */
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003599 if (params->phy[INT_PHY].read_status)
3600 params->phy[INT_PHY].read_status(
3601 &params->phy[INT_PHY],
3602 params, vars);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003603 /*
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003604 * The INT_PHY flow control reside in the vars. This include the
3605 * case where the speed or flow control are not set to AUTO.
3606 * Otherwise, the active external phy flow control result is set
3607 * to the vars. The ext_phy_line_speed is needed to check if the
3608 * speed is different between the internal phy and external phy.
3609 * This case may be result of intermediate link speed change.
3610 */
3611 if (active_external_phy > INT_PHY) {
3612 vars->flow_ctrl = phy_vars[active_external_phy].flow_ctrl;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003613 /*
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003614 * Link speed is taken from the XGXS. AN and FC result from
3615 * the external phy.
3616 */
3617 vars->link_status |= phy_vars[active_external_phy].link_status;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003618
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003619 /*
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003620 * if active_external_phy is first PHY and link is up - disable
3621 * disable TX on second external PHY
3622 */
3623 if (active_external_phy == EXT_PHY1) {
3624 if (params->phy[EXT_PHY2].phy_specific_func) {
3625 DP(NETIF_MSG_LINK, "Disabling TX on"
3626 " EXT_PHY2\n");
3627 params->phy[EXT_PHY2].phy_specific_func(
3628 &params->phy[EXT_PHY2],
3629 params, DISABLE_TX);
3630 }
3631 }
3632
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003633 ext_phy_line_speed = phy_vars[active_external_phy].line_speed;
3634 vars->duplex = phy_vars[active_external_phy].duplex;
3635 if (params->phy[active_external_phy].supported &
3636 SUPPORTED_FIBRE)
3637 vars->link_status |= LINK_STATUS_SERDES_LINK;
3638 DP(NETIF_MSG_LINK, "Active external phy selected: %x\n",
3639 active_external_phy);
3640 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003641
3642 for (phy_index = EXT_PHY1; phy_index < params->num_phys;
3643 phy_index++) {
3644 if (params->phy[phy_index].flags &
3645 FLAGS_REARM_LATCH_SIGNAL) {
3646 bnx2x_rearm_latch_signal(bp, port,
3647 phy_index ==
3648 active_external_phy);
3649 break;
3650 }
3651 }
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003652 DP(NETIF_MSG_LINK, "vars->flow_ctrl = 0x%x, vars->link_status = 0x%x,"
3653 " ext_phy_line_speed = %d\n", vars->flow_ctrl,
3654 vars->link_status, ext_phy_line_speed);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003655 /*
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003656 * Upon link speed change set the NIG into drain mode. Comes to
3657 * deals with possible FIFO glitch due to clk change when speed
3658 * is decreased without link down indicator
3659 */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003660
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003661 if (vars->phy_link_up) {
3662 if (!(SINGLE_MEDIA_DIRECT(params)) && ext_phy_link_up &&
3663 (ext_phy_line_speed != vars->line_speed)) {
3664 DP(NETIF_MSG_LINK, "Internal link speed %d is"
3665 " different than the external"
3666 " link speed %d\n", vars->line_speed,
3667 ext_phy_line_speed);
3668 vars->phy_link_up = 0;
3669 } else if (prev_line_speed != vars->line_speed) {
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003670 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4,
3671 0);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003672 msleep(1);
3673 }
3674 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003675
3676 /* anything 10 and over uses the bmac */
3677 link_10g = ((vars->line_speed == SPEED_10000) ||
3678 (vars->line_speed == SPEED_12000) ||
3679 (vars->line_speed == SPEED_12500) ||
3680 (vars->line_speed == SPEED_13000) ||
3681 (vars->line_speed == SPEED_15000) ||
3682 (vars->line_speed == SPEED_16000));
3683
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003684 bnx2x_link_int_ack(params, vars, link_10g);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003685
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003686 /*
3687 * In case external phy link is up, and internal link is down
3688 * (not initialized yet probably after link initialization, it
3689 * needs to be initialized.
3690 * Note that after link down-up as result of cable plug, the xgxs
3691 * link would probably become up again without the need
3692 * initialize it
3693 */
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003694 if (!(SINGLE_MEDIA_DIRECT(params))) {
3695 DP(NETIF_MSG_LINK, "ext_phy_link_up = %d, int_link_up = %d,"
3696 " init_preceding = %d\n", ext_phy_link_up,
3697 vars->phy_link_up,
3698 params->phy[EXT_PHY1].flags &
3699 FLAGS_INIT_XGXS_FIRST);
3700 if (!(params->phy[EXT_PHY1].flags &
3701 FLAGS_INIT_XGXS_FIRST)
3702 && ext_phy_link_up && !vars->phy_link_up) {
3703 vars->line_speed = ext_phy_line_speed;
3704 if (vars->line_speed < SPEED_1000)
3705 vars->phy_flags |= PHY_SGMII_FLAG;
3706 else
3707 vars->phy_flags &= ~PHY_SGMII_FLAG;
3708 bnx2x_init_internal_phy(&params->phy[INT_PHY],
3709 params,
3710 vars);
3711 }
3712 }
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00003713 /*
3714 * Link is up only if both local phy and external phy (in case of
3715 * non-direct board) are up
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003716 */
3717 vars->link_up = (vars->phy_link_up &&
3718 (ext_phy_link_up ||
3719 SINGLE_MEDIA_DIRECT(params)));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003720
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003721 if (vars->link_up)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003722 rc = bnx2x_update_link_up(params, vars, link_10g);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003723 else
3724 rc = bnx2x_update_link_down(params, vars);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003725
3726 return rc;
3727}
3728
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003729
3730/*****************************************************************************/
3731/* External Phy section */
3732/*****************************************************************************/
3733void bnx2x_ext_phy_hw_reset(struct bnx2x *bp, u8 port)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003734{
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003735 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003736 MISC_REGISTERS_GPIO_OUTPUT_LOW, port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003737 msleep(1);
3738 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003739 MISC_REGISTERS_GPIO_OUTPUT_HIGH, port);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00003740}
3741
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003742static void bnx2x_save_spirom_version(struct bnx2x *bp, u8 port,
3743 u32 spirom_ver, u32 ver_addr)
3744{
3745 DP(NETIF_MSG_LINK, "FW version 0x%x:0x%x for port %d\n",
3746 (u16)(spirom_ver>>16), (u16)spirom_ver, port);
3747
3748 if (ver_addr)
3749 REG_WR(bp, ver_addr, spirom_ver);
3750}
3751
3752static void bnx2x_save_bcm_spirom_ver(struct bnx2x *bp,
3753 struct bnx2x_phy *phy,
3754 u8 port)
3755{
3756 u16 fw_ver1, fw_ver2;
3757
3758 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003759 MDIO_PMA_REG_ROM_VER1, &fw_ver1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003760 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003761 MDIO_PMA_REG_ROM_VER2, &fw_ver2);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003762 bnx2x_save_spirom_version(bp, port, (u32)(fw_ver1<<16 | fw_ver2),
3763 phy->ver_addr);
3764}
3765
3766static void bnx2x_ext_phy_set_pause(struct link_params *params,
3767 struct bnx2x_phy *phy,
3768 struct link_vars *vars)
3769{
3770 u16 val;
3771 struct bnx2x *bp = params->bp;
3772 /* read modify write pause advertizing */
3773 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV_PAUSE, &val);
3774
3775 val &= ~MDIO_AN_REG_ADV_PAUSE_BOTH;
3776
3777 /* Please refer to Table 28B-3 of 802.3ab-1999 spec. */
3778 bnx2x_calc_ieee_aneg_adv(phy, params, &vars->ieee_fc);
3779 if ((vars->ieee_fc &
3780 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC) ==
3781 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC) {
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003782 val |= MDIO_AN_REG_ADV_PAUSE_ASYMMETRIC;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003783 }
3784 if ((vars->ieee_fc &
3785 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) ==
3786 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) {
3787 val |= MDIO_AN_REG_ADV_PAUSE_PAUSE;
3788 }
3789 DP(NETIF_MSG_LINK, "Ext phy AN advertize 0x%x\n", val);
3790 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV_PAUSE, val);
3791}
3792
3793static u8 bnx2x_ext_phy_resolve_fc(struct bnx2x_phy *phy,
3794 struct link_params *params,
3795 struct link_vars *vars)
3796{
3797 struct bnx2x *bp = params->bp;
3798 u16 ld_pause; /* local */
3799 u16 lp_pause; /* link partner */
3800 u16 pause_result;
3801 u8 ret = 0;
3802 /* read twice */
3803
3804 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
3805
3806 if (phy->req_flow_ctrl != BNX2X_FLOW_CTRL_AUTO)
3807 vars->flow_ctrl = phy->req_flow_ctrl;
3808 else if (phy->req_line_speed != SPEED_AUTO_NEG)
3809 vars->flow_ctrl = params->req_fc_auto_adv;
3810 else if (vars->link_status & LINK_STATUS_AUTO_NEGOTIATE_COMPLETE) {
3811 ret = 1;
3812 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003813 MDIO_AN_DEVAD,
3814 MDIO_AN_REG_ADV_PAUSE, &ld_pause);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003815 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003816 MDIO_AN_DEVAD,
3817 MDIO_AN_REG_LP_AUTO_NEG, &lp_pause);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003818 pause_result = (ld_pause &
3819 MDIO_AN_REG_ADV_PAUSE_MASK) >> 8;
3820 pause_result |= (lp_pause &
3821 MDIO_AN_REG_ADV_PAUSE_MASK) >> 10;
3822 DP(NETIF_MSG_LINK, "Ext PHY pause result 0x%x\n",
3823 pause_result);
3824 bnx2x_pause_resolve(vars, pause_result);
3825 }
3826 return ret;
3827}
3828
3829static void bnx2x_ext_phy_10G_an_resolve(struct bnx2x *bp,
3830 struct bnx2x_phy *phy,
3831 struct link_vars *vars)
3832{
3833 u16 val;
3834 bnx2x_cl45_read(bp, phy,
3835 MDIO_AN_DEVAD,
3836 MDIO_AN_REG_STATUS, &val);
3837 bnx2x_cl45_read(bp, phy,
3838 MDIO_AN_DEVAD,
3839 MDIO_AN_REG_STATUS, &val);
3840 if (val & (1<<5))
3841 vars->link_status |= LINK_STATUS_AUTO_NEGOTIATE_COMPLETE;
3842 if ((val & (1<<0)) == 0)
3843 vars->link_status |= LINK_STATUS_PARALLEL_DETECTION_USED;
3844}
3845
3846/******************************************************************/
3847/* common BCM8073/BCM8727 PHY SECTION */
3848/******************************************************************/
3849static void bnx2x_8073_resolve_fc(struct bnx2x_phy *phy,
3850 struct link_params *params,
3851 struct link_vars *vars)
3852{
3853 struct bnx2x *bp = params->bp;
3854 if (phy->req_line_speed == SPEED_10 ||
3855 phy->req_line_speed == SPEED_100) {
3856 vars->flow_ctrl = phy->req_flow_ctrl;
3857 return;
3858 }
3859
3860 if (bnx2x_ext_phy_resolve_fc(phy, params, vars) &&
3861 (vars->flow_ctrl == BNX2X_FLOW_CTRL_NONE)) {
3862 u16 pause_result;
3863 u16 ld_pause; /* local */
3864 u16 lp_pause; /* link partner */
3865 bnx2x_cl45_read(bp, phy,
3866 MDIO_AN_DEVAD,
3867 MDIO_AN_REG_CL37_FC_LD, &ld_pause);
3868
3869 bnx2x_cl45_read(bp, phy,
3870 MDIO_AN_DEVAD,
3871 MDIO_AN_REG_CL37_FC_LP, &lp_pause);
3872 pause_result = (ld_pause &
3873 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) >> 5;
3874 pause_result |= (lp_pause &
3875 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) >> 7;
3876
3877 bnx2x_pause_resolve(vars, pause_result);
3878 DP(NETIF_MSG_LINK, "Ext PHY CL37 pause result 0x%x\n",
3879 pause_result);
3880 }
3881}
Yaniv Rosner5c99274b2011-01-18 04:33:36 +00003882static u8 bnx2x_8073_8727_external_rom_boot(struct bnx2x *bp,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003883 struct bnx2x_phy *phy,
3884 u8 port)
3885{
Yaniv Rosner5c99274b2011-01-18 04:33:36 +00003886 u32 count = 0;
3887 u16 fw_ver1, fw_msgout;
3888 u8 rc = 0;
3889
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003890 /* Boot port from external ROM */
3891 /* EDC grst */
3892 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003893 MDIO_PMA_DEVAD,
3894 MDIO_PMA_REG_GEN_CTRL,
3895 0x0001);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003896
3897 /* ucode reboot and rst */
3898 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003899 MDIO_PMA_DEVAD,
3900 MDIO_PMA_REG_GEN_CTRL,
3901 0x008c);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003902
3903 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003904 MDIO_PMA_DEVAD,
3905 MDIO_PMA_REG_MISC_CTRL1, 0x0001);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003906
3907 /* Reset internal microprocessor */
3908 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003909 MDIO_PMA_DEVAD,
3910 MDIO_PMA_REG_GEN_CTRL,
3911 MDIO_PMA_REG_GEN_CTRL_ROM_MICRO_RESET);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003912
3913 /* Release srst bit */
3914 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003915 MDIO_PMA_DEVAD,
3916 MDIO_PMA_REG_GEN_CTRL,
3917 MDIO_PMA_REG_GEN_CTRL_ROM_RESET_INTERNAL_MP);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003918
Yaniv Rosner5c99274b2011-01-18 04:33:36 +00003919 /* Delay 100ms per the PHY specifications */
3920 msleep(100);
3921
3922 /* 8073 sometimes taking longer to download */
3923 do {
3924 count++;
3925 if (count > 300) {
3926 DP(NETIF_MSG_LINK,
3927 "bnx2x_8073_8727_external_rom_boot port %x:"
3928 "Download failed. fw version = 0x%x\n",
3929 port, fw_ver1);
3930 rc = -EINVAL;
3931 break;
3932 }
3933
3934 bnx2x_cl45_read(bp, phy,
3935 MDIO_PMA_DEVAD,
3936 MDIO_PMA_REG_ROM_VER1, &fw_ver1);
3937 bnx2x_cl45_read(bp, phy,
3938 MDIO_PMA_DEVAD,
3939 MDIO_PMA_REG_M8051_MSGOUT_REG, &fw_msgout);
3940
3941 msleep(1);
3942 } while (fw_ver1 == 0 || fw_ver1 == 0x4321 ||
3943 ((fw_msgout & 0xff) != 0x03 && (phy->type ==
3944 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073)));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003945
3946 /* Clear ser_boot_ctl bit */
3947 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003948 MDIO_PMA_DEVAD,
3949 MDIO_PMA_REG_MISC_CTRL1, 0x0000);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003950 bnx2x_save_bcm_spirom_ver(bp, phy, port);
Yaniv Rosner5c99274b2011-01-18 04:33:36 +00003951
3952 DP(NETIF_MSG_LINK,
3953 "bnx2x_8073_8727_external_rom_boot port %x:"
3954 "Download complete. fw version = 0x%x\n",
3955 port, fw_ver1);
3956
3957 return rc;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003958}
3959
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003960/******************************************************************/
3961/* BCM8073 PHY SECTION */
3962/******************************************************************/
3963static u8 bnx2x_8073_is_snr_needed(struct bnx2x *bp, struct bnx2x_phy *phy)
3964{
3965 /* This is only required for 8073A1, version 102 only */
3966 u16 val;
3967
3968 /* Read 8073 HW revision*/
3969 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003970 MDIO_PMA_DEVAD,
3971 MDIO_PMA_REG_8073_CHIP_REV, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003972
3973 if (val != 1) {
3974 /* No need to workaround in 8073 A1 */
3975 return 0;
3976 }
3977
3978 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003979 MDIO_PMA_DEVAD,
3980 MDIO_PMA_REG_ROM_VER2, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003981
3982 /* SNR should be applied only for version 0x102 */
3983 if (val != 0x102)
3984 return 0;
3985
3986 return 1;
3987}
3988
3989static u8 bnx2x_8073_xaui_wa(struct bnx2x *bp, struct bnx2x_phy *phy)
3990{
3991 u16 val, cnt, cnt1 ;
3992
3993 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003994 MDIO_PMA_DEVAD,
3995 MDIO_PMA_REG_8073_CHIP_REV, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003996
3997 if (val > 0) {
3998 /* No need to workaround in 8073 A1 */
3999 return 0;
4000 }
4001 /* XAUI workaround in 8073 A0: */
4002
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00004003 /*
4004 * After loading the boot ROM and restarting Autoneg, poll
4005 * Dev1, Reg $C820:
4006 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004007
4008 for (cnt = 0; cnt < 1000; cnt++) {
4009 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004010 MDIO_PMA_DEVAD,
4011 MDIO_PMA_REG_8073_SPEED_LINK_STATUS,
4012 &val);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00004013 /*
4014 * If bit [14] = 0 or bit [13] = 0, continue on with
4015 * system initialization (XAUI work-around not required, as
4016 * these bits indicate 2.5G or 1G link up).
4017 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004018 if (!(val & (1<<14)) || !(val & (1<<13))) {
4019 DP(NETIF_MSG_LINK, "XAUI work-around not required\n");
4020 return 0;
4021 } else if (!(val & (1<<15))) {
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00004022 DP(NETIF_MSG_LINK, "bit 15 went off\n");
4023 /*
4024 * If bit 15 is 0, then poll Dev1, Reg $C841 until it's
4025 * MSB (bit15) goes to 1 (indicating that the XAUI
4026 * workaround has completed), then continue on with
4027 * system initialization.
4028 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004029 for (cnt1 = 0; cnt1 < 1000; cnt1++) {
4030 bnx2x_cl45_read(bp, phy,
4031 MDIO_PMA_DEVAD,
4032 MDIO_PMA_REG_8073_XAUI_WA, &val);
4033 if (val & (1<<15)) {
4034 DP(NETIF_MSG_LINK,
4035 "XAUI workaround has completed\n");
4036 return 0;
4037 }
4038 msleep(3);
4039 }
4040 break;
4041 }
4042 msleep(3);
4043 }
4044 DP(NETIF_MSG_LINK, "Warning: XAUI work-around timeout !!!\n");
4045 return -EINVAL;
4046}
4047
4048static void bnx2x_807x_force_10G(struct bnx2x *bp, struct bnx2x_phy *phy)
4049{
4050 /* Force KR or KX */
4051 bnx2x_cl45_write(bp, phy,
4052 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x2040);
4053 bnx2x_cl45_write(bp, phy,
4054 MDIO_PMA_DEVAD, MDIO_PMA_REG_10G_CTRL2, 0x000b);
4055 bnx2x_cl45_write(bp, phy,
4056 MDIO_PMA_DEVAD, MDIO_PMA_REG_BCM_CTRL, 0x0000);
4057 bnx2x_cl45_write(bp, phy,
4058 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x0000);
4059}
4060
4061static void bnx2x_8073_set_pause_cl37(struct link_params *params,
4062 struct bnx2x_phy *phy,
4063 struct link_vars *vars)
4064{
4065 u16 cl37_val;
4066 struct bnx2x *bp = params->bp;
4067 bnx2x_cl45_read(bp, phy,
4068 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LD, &cl37_val);
4069
4070 cl37_val &= ~MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH;
4071 /* Please refer to Table 28B-3 of 802.3ab-1999 spec. */
4072 bnx2x_calc_ieee_aneg_adv(phy, params, &vars->ieee_fc);
4073 if ((vars->ieee_fc &
4074 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_SYMMETRIC) ==
4075 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_SYMMETRIC) {
4076 cl37_val |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_SYMMETRIC;
4077 }
4078 if ((vars->ieee_fc &
4079 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC) ==
4080 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC) {
4081 cl37_val |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC;
4082 }
4083 if ((vars->ieee_fc &
4084 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) ==
4085 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) {
4086 cl37_val |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH;
4087 }
4088 DP(NETIF_MSG_LINK,
4089 "Ext phy AN advertize cl37 0x%x\n", cl37_val);
4090
4091 bnx2x_cl45_write(bp, phy,
4092 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LD, cl37_val);
4093 msleep(500);
4094}
4095
4096static u8 bnx2x_8073_config_init(struct bnx2x_phy *phy,
4097 struct link_params *params,
4098 struct link_vars *vars)
4099{
4100 struct bnx2x *bp = params->bp;
4101 u16 val = 0, tmp1;
4102 u8 gpio_port;
4103 DP(NETIF_MSG_LINK, "Init 8073\n");
4104
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004105 if (CHIP_IS_E2(bp))
4106 gpio_port = BP_PATH(bp);
4107 else
4108 gpio_port = params->port;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004109 /* Restore normal power mode*/
4110 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004111 MISC_REGISTERS_GPIO_OUTPUT_HIGH, gpio_port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004112
4113 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004114 MISC_REGISTERS_GPIO_OUTPUT_HIGH, gpio_port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004115
4116 /* enable LASI */
4117 bnx2x_cl45_write(bp, phy,
4118 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_ALARM_CTRL, (1<<2));
4119 bnx2x_cl45_write(bp, phy,
4120 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_CTRL, 0x0004);
4121
4122 bnx2x_8073_set_pause_cl37(params, phy, vars);
4123
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004124 bnx2x_cl45_read(bp, phy,
4125 MDIO_PMA_DEVAD, MDIO_PMA_REG_M8051_MSGOUT_REG, &tmp1);
4126
4127 bnx2x_cl45_read(bp, phy,
4128 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_ALARM, &tmp1);
4129
4130 DP(NETIF_MSG_LINK, "Before rom RX_ALARM(port1): 0x%x\n", tmp1);
4131
Yaniv Rosner74d7a112011-01-18 04:33:18 +00004132 /* Swap polarity if required - Must be done only in non-1G mode */
4133 if (params->lane_config & PORT_HW_CFG_SWAP_PHY_POLARITY_ENABLED) {
4134 /* Configure the 8073 to swap _P and _N of the KR lines */
4135 DP(NETIF_MSG_LINK, "Swapping polarity for the 8073\n");
4136 /* 10G Rx/Tx and 1G Tx signal polarity swap */
4137 bnx2x_cl45_read(bp, phy,
4138 MDIO_PMA_DEVAD,
4139 MDIO_PMA_REG_8073_OPT_DIGITAL_CTRL, &val);
4140 bnx2x_cl45_write(bp, phy,
4141 MDIO_PMA_DEVAD,
4142 MDIO_PMA_REG_8073_OPT_DIGITAL_CTRL,
4143 (val | (3<<9)));
4144 }
4145
4146
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004147 /* Enable CL37 BAM */
Yaniv Rosner121839b2010-11-01 05:32:38 +00004148 if (REG_RD(bp, params->shmem_base +
4149 offsetof(struct shmem_region, dev_info.
4150 port_hw_config[params->port].default_cfg)) &
4151 PORT_HW_CFG_ENABLE_BAM_ON_KR_ENABLED) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004152
Yaniv Rosner121839b2010-11-01 05:32:38 +00004153 bnx2x_cl45_read(bp, phy,
4154 MDIO_AN_DEVAD,
4155 MDIO_AN_REG_8073_BAM, &val);
4156 bnx2x_cl45_write(bp, phy,
4157 MDIO_AN_DEVAD,
4158 MDIO_AN_REG_8073_BAM, val | 1);
4159 DP(NETIF_MSG_LINK, "Enable CL37 BAM on KR\n");
4160 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004161 if (params->loopback_mode == LOOPBACK_EXT) {
4162 bnx2x_807x_force_10G(bp, phy);
4163 DP(NETIF_MSG_LINK, "Forced speed 10G on 807X\n");
4164 return 0;
4165 } else {
4166 bnx2x_cl45_write(bp, phy,
4167 MDIO_PMA_DEVAD, MDIO_PMA_REG_BCM_CTRL, 0x0002);
4168 }
4169 if (phy->req_line_speed != SPEED_AUTO_NEG) {
4170 if (phy->req_line_speed == SPEED_10000) {
4171 val = (1<<7);
4172 } else if (phy->req_line_speed == SPEED_2500) {
4173 val = (1<<5);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00004174 /*
4175 * Note that 2.5G works only when used with 1G
4176 * advertisment
4177 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004178 } else
4179 val = (1<<5);
4180 } else {
4181 val = 0;
4182 if (phy->speed_cap_mask &
4183 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
4184 val |= (1<<7);
4185
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00004186 /* Note that 2.5G works only when used with 1G advertisment */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004187 if (phy->speed_cap_mask &
4188 (PORT_HW_CFG_SPEED_CAPABILITY_D0_1G |
4189 PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
4190 val |= (1<<5);
4191 DP(NETIF_MSG_LINK, "807x autoneg val = 0x%x\n", val);
4192 }
4193
4194 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV, val);
4195 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_8073_2_5G, &tmp1);
4196
4197 if (((phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G) &&
4198 (phy->req_line_speed == SPEED_AUTO_NEG)) ||
4199 (phy->req_line_speed == SPEED_2500)) {
4200 u16 phy_ver;
4201 /* Allow 2.5G for A1 and above */
4202 bnx2x_cl45_read(bp, phy,
4203 MDIO_PMA_DEVAD, MDIO_PMA_REG_8073_CHIP_REV,
4204 &phy_ver);
4205 DP(NETIF_MSG_LINK, "Add 2.5G\n");
4206 if (phy_ver > 0)
4207 tmp1 |= 1;
4208 else
4209 tmp1 &= 0xfffe;
4210 } else {
4211 DP(NETIF_MSG_LINK, "Disable 2.5G\n");
4212 tmp1 &= 0xfffe;
4213 }
4214
4215 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_8073_2_5G, tmp1);
4216 /* Add support for CL37 (passive mode) II */
4217
4218 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LD, &tmp1);
4219 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LD,
4220 (tmp1 | ((phy->req_duplex == DUPLEX_FULL) ?
4221 0x20 : 0x40)));
4222
4223 /* Add support for CL37 (passive mode) III */
4224 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CL37_AN, 0x1000);
4225
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00004226 /*
4227 * The SNR will improve about 2db by changing BW and FEE main
4228 * tap. Rest commands are executed after link is up
4229 * Change FFE main cursor to 5 in EDC register
4230 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004231 if (bnx2x_8073_is_snr_needed(bp, phy))
4232 bnx2x_cl45_write(bp, phy,
4233 MDIO_PMA_DEVAD, MDIO_PMA_REG_EDC_FFE_MAIN,
4234 0xFB0C);
4235
4236 /* Enable FEC (Forware Error Correction) Request in the AN */
4237 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV2, &tmp1);
4238 tmp1 |= (1<<15);
4239 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV2, tmp1);
4240
4241 bnx2x_ext_phy_set_pause(params, phy, vars);
4242
4243 /* Restart autoneg */
4244 msleep(500);
4245 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x1200);
4246 DP(NETIF_MSG_LINK, "807x Autoneg Restart: Advertise 1G=%x, 10G=%x\n",
4247 ((val & (1<<5)) > 0), ((val & (1<<7)) > 0));
4248 return 0;
4249}
4250
4251static u8 bnx2x_8073_read_status(struct bnx2x_phy *phy,
4252 struct link_params *params,
4253 struct link_vars *vars)
4254{
4255 struct bnx2x *bp = params->bp;
4256 u8 link_up = 0;
4257 u16 val1, val2;
4258 u16 link_status = 0;
4259 u16 an1000_status = 0;
4260
4261 bnx2x_cl45_read(bp, phy,
4262 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_STATUS, &val1);
4263
4264 DP(NETIF_MSG_LINK, "8703 LASI status 0x%x\n", val1);
4265
4266 /* clear the interrupt LASI status register */
4267 bnx2x_cl45_read(bp, phy,
4268 MDIO_PCS_DEVAD, MDIO_PCS_REG_STATUS, &val2);
4269 bnx2x_cl45_read(bp, phy,
4270 MDIO_PCS_DEVAD, MDIO_PCS_REG_STATUS, &val1);
4271 DP(NETIF_MSG_LINK, "807x PCS status 0x%x->0x%x\n", val2, val1);
4272 /* Clear MSG-OUT */
4273 bnx2x_cl45_read(bp, phy,
4274 MDIO_PMA_DEVAD, MDIO_PMA_REG_M8051_MSGOUT_REG, &val1);
4275
4276 /* Check the LASI */
4277 bnx2x_cl45_read(bp, phy,
4278 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_ALARM, &val2);
4279
4280 DP(NETIF_MSG_LINK, "KR 0x9003 0x%x\n", val2);
4281
4282 /* Check the link status */
4283 bnx2x_cl45_read(bp, phy,
4284 MDIO_PCS_DEVAD, MDIO_PCS_REG_STATUS, &val2);
4285 DP(NETIF_MSG_LINK, "KR PCS status 0x%x\n", val2);
4286
4287 bnx2x_cl45_read(bp, phy,
4288 MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val2);
4289 bnx2x_cl45_read(bp, phy,
4290 MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val1);
4291 link_up = ((val1 & 4) == 4);
4292 DP(NETIF_MSG_LINK, "PMA_REG_STATUS=0x%x\n", val1);
4293
4294 if (link_up &&
4295 ((phy->req_line_speed != SPEED_10000))) {
4296 if (bnx2x_8073_xaui_wa(bp, phy) != 0)
4297 return 0;
4298 }
4299 bnx2x_cl45_read(bp, phy,
4300 MDIO_AN_DEVAD, MDIO_AN_REG_LINK_STATUS, &an1000_status);
4301 bnx2x_cl45_read(bp, phy,
4302 MDIO_AN_DEVAD, MDIO_AN_REG_LINK_STATUS, &an1000_status);
4303
4304 /* Check the link status on 1.1.2 */
4305 bnx2x_cl45_read(bp, phy,
4306 MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val2);
4307 bnx2x_cl45_read(bp, phy,
4308 MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val1);
4309 DP(NETIF_MSG_LINK, "KR PMA status 0x%x->0x%x,"
4310 "an_link_status=0x%x\n", val2, val1, an1000_status);
4311
4312 link_up = (((val1 & 4) == 4) || (an1000_status & (1<<1)));
4313 if (link_up && bnx2x_8073_is_snr_needed(bp, phy)) {
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00004314 /*
4315 * The SNR will improve about 2dbby changing the BW and FEE main
4316 * tap. The 1st write to change FFE main tap is set before
4317 * restart AN. Change PLL Bandwidth in EDC register
4318 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004319 bnx2x_cl45_write(bp, phy,
4320 MDIO_PMA_DEVAD, MDIO_PMA_REG_PLL_BANDWIDTH,
4321 0x26BC);
4322
4323 /* Change CDR Bandwidth in EDC register */
4324 bnx2x_cl45_write(bp, phy,
4325 MDIO_PMA_DEVAD, MDIO_PMA_REG_CDR_BANDWIDTH,
4326 0x0333);
4327 }
4328 bnx2x_cl45_read(bp, phy,
4329 MDIO_PMA_DEVAD, MDIO_PMA_REG_8073_SPEED_LINK_STATUS,
4330 &link_status);
4331
4332 /* Bits 0..2 --> speed detected, bits 13..15--> link is down */
4333 if ((link_status & (1<<2)) && (!(link_status & (1<<15)))) {
4334 link_up = 1;
4335 vars->line_speed = SPEED_10000;
4336 DP(NETIF_MSG_LINK, "port %x: External link up in 10G\n",
4337 params->port);
4338 } else if ((link_status & (1<<1)) && (!(link_status & (1<<14)))) {
4339 link_up = 1;
4340 vars->line_speed = SPEED_2500;
4341 DP(NETIF_MSG_LINK, "port %x: External link up in 2.5G\n",
4342 params->port);
4343 } else if ((link_status & (1<<0)) && (!(link_status & (1<<13)))) {
4344 link_up = 1;
4345 vars->line_speed = SPEED_1000;
4346 DP(NETIF_MSG_LINK, "port %x: External link up in 1G\n",
4347 params->port);
4348 } else {
4349 link_up = 0;
4350 DP(NETIF_MSG_LINK, "port %x: External link is down\n",
4351 params->port);
4352 }
4353
4354 if (link_up) {
Yaniv Rosner74d7a112011-01-18 04:33:18 +00004355 /* Swap polarity if required */
4356 if (params->lane_config &
4357 PORT_HW_CFG_SWAP_PHY_POLARITY_ENABLED) {
4358 /* Configure the 8073 to swap P and N of the KR lines */
4359 bnx2x_cl45_read(bp, phy,
4360 MDIO_XS_DEVAD,
4361 MDIO_XS_REG_8073_RX_CTRL_PCIE, &val1);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00004362 /*
4363 * Set bit 3 to invert Rx in 1G mode and clear this bit
4364 * when it`s in 10G mode.
4365 */
Yaniv Rosner74d7a112011-01-18 04:33:18 +00004366 if (vars->line_speed == SPEED_1000) {
4367 DP(NETIF_MSG_LINK, "Swapping 1G polarity for"
4368 "the 8073\n");
4369 val1 |= (1<<3);
4370 } else
4371 val1 &= ~(1<<3);
4372
4373 bnx2x_cl45_write(bp, phy,
4374 MDIO_XS_DEVAD,
4375 MDIO_XS_REG_8073_RX_CTRL_PCIE,
4376 val1);
4377 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004378 bnx2x_ext_phy_10G_an_resolve(bp, phy, vars);
4379 bnx2x_8073_resolve_fc(phy, params, vars);
Yaniv Rosner791f18c2011-01-18 04:33:42 +00004380 vars->duplex = DUPLEX_FULL;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004381 }
4382 return link_up;
4383}
4384
4385static void bnx2x_8073_link_reset(struct bnx2x_phy *phy,
4386 struct link_params *params)
4387{
4388 struct bnx2x *bp = params->bp;
4389 u8 gpio_port;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00004390 if (CHIP_IS_E2(bp))
4391 gpio_port = BP_PATH(bp);
4392 else
4393 gpio_port = params->port;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004394 DP(NETIF_MSG_LINK, "Setting 8073 port %d into low power mode\n",
4395 gpio_port);
4396 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004397 MISC_REGISTERS_GPIO_OUTPUT_LOW,
4398 gpio_port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004399}
4400
4401/******************************************************************/
4402/* BCM8705 PHY SECTION */
4403/******************************************************************/
4404static u8 bnx2x_8705_config_init(struct bnx2x_phy *phy,
4405 struct link_params *params,
4406 struct link_vars *vars)
4407{
4408 struct bnx2x *bp = params->bp;
4409 DP(NETIF_MSG_LINK, "init 8705\n");
4410 /* Restore normal power mode*/
4411 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004412 MISC_REGISTERS_GPIO_OUTPUT_HIGH, params->port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004413 /* HW reset */
4414 bnx2x_ext_phy_hw_reset(bp, params->port);
4415 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0xa040);
Yaniv Rosner6d870c32011-01-31 04:22:20 +00004416 bnx2x_wait_reset_complete(bp, phy, params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004417
4418 bnx2x_cl45_write(bp, phy,
4419 MDIO_PMA_DEVAD, MDIO_PMA_REG_MISC_CTRL, 0x8288);
4420 bnx2x_cl45_write(bp, phy,
4421 MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER, 0x7fbf);
4422 bnx2x_cl45_write(bp, phy,
4423 MDIO_PMA_DEVAD, MDIO_PMA_REG_CMU_PLL_BYPASS, 0x0100);
4424 bnx2x_cl45_write(bp, phy,
4425 MDIO_WIS_DEVAD, MDIO_WIS_REG_LASI_CNTL, 0x1);
4426 /* BCM8705 doesn't have microcode, hence the 0 */
4427 bnx2x_save_spirom_version(bp, params->port, params->shmem_base, 0);
4428 return 0;
4429}
4430
4431static u8 bnx2x_8705_read_status(struct bnx2x_phy *phy,
4432 struct link_params *params,
4433 struct link_vars *vars)
4434{
4435 u8 link_up = 0;
4436 u16 val1, rx_sd;
4437 struct bnx2x *bp = params->bp;
4438 DP(NETIF_MSG_LINK, "read status 8705\n");
4439 bnx2x_cl45_read(bp, phy,
4440 MDIO_WIS_DEVAD, MDIO_WIS_REG_LASI_STATUS, &val1);
4441 DP(NETIF_MSG_LINK, "8705 LASI status 0x%x\n", val1);
4442
4443 bnx2x_cl45_read(bp, phy,
4444 MDIO_WIS_DEVAD, MDIO_WIS_REG_LASI_STATUS, &val1);
4445 DP(NETIF_MSG_LINK, "8705 LASI status 0x%x\n", val1);
4446
4447 bnx2x_cl45_read(bp, phy,
4448 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_SD, &rx_sd);
4449
4450 bnx2x_cl45_read(bp, phy,
4451 MDIO_PMA_DEVAD, 0xc809, &val1);
4452 bnx2x_cl45_read(bp, phy,
4453 MDIO_PMA_DEVAD, 0xc809, &val1);
4454
4455 DP(NETIF_MSG_LINK, "8705 1.c809 val=0x%x\n", val1);
4456 link_up = ((rx_sd & 0x1) && (val1 & (1<<9)) && ((val1 & (1<<8)) == 0));
4457 if (link_up) {
4458 vars->line_speed = SPEED_10000;
4459 bnx2x_ext_phy_resolve_fc(phy, params, vars);
4460 }
4461 return link_up;
4462}
4463
4464/******************************************************************/
4465/* SFP+ module Section */
4466/******************************************************************/
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00004467static u8 bnx2x_get_gpio_port(struct link_params *params)
4468{
4469 u8 gpio_port;
4470 u32 swap_val, swap_override;
4471 struct bnx2x *bp = params->bp;
4472 if (CHIP_IS_E2(bp))
4473 gpio_port = BP_PATH(bp);
4474 else
4475 gpio_port = params->port;
4476 swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
4477 swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
4478 return gpio_port ^ (swap_val && swap_override);
4479}
4480static void bnx2x_sfp_set_transmitter(struct link_params *params,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004481 struct bnx2x_phy *phy,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004482 u8 tx_en)
4483{
4484 u16 val;
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00004485 u8 port = params->port;
4486 struct bnx2x *bp = params->bp;
4487 u32 tx_en_mode;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004488
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004489 /* Disable/Enable transmitter ( TX laser of the SFP+ module.)*/
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00004490 tx_en_mode = REG_RD(bp, params->shmem_base +
4491 offsetof(struct shmem_region,
4492 dev_info.port_hw_config[port].sfp_ctrl)) &
4493 PORT_HW_CFG_TX_LASER_MASK;
4494 DP(NETIF_MSG_LINK, "Setting transmitter tx_en=%x for port %x "
4495 "mode = %x\n", tx_en, port, tx_en_mode);
4496 switch (tx_en_mode) {
4497 case PORT_HW_CFG_TX_LASER_MDIO:
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004498
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00004499 bnx2x_cl45_read(bp, phy,
4500 MDIO_PMA_DEVAD,
4501 MDIO_PMA_REG_PHY_IDENTIFIER,
4502 &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004503
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00004504 if (tx_en)
4505 val &= ~(1<<15);
4506 else
4507 val |= (1<<15);
4508
4509 bnx2x_cl45_write(bp, phy,
4510 MDIO_PMA_DEVAD,
4511 MDIO_PMA_REG_PHY_IDENTIFIER,
4512 val);
4513 break;
4514 case PORT_HW_CFG_TX_LASER_GPIO0:
4515 case PORT_HW_CFG_TX_LASER_GPIO1:
4516 case PORT_HW_CFG_TX_LASER_GPIO2:
4517 case PORT_HW_CFG_TX_LASER_GPIO3:
4518 {
4519 u16 gpio_pin;
4520 u8 gpio_port, gpio_mode;
4521 if (tx_en)
4522 gpio_mode = MISC_REGISTERS_GPIO_OUTPUT_HIGH;
4523 else
4524 gpio_mode = MISC_REGISTERS_GPIO_OUTPUT_LOW;
4525
4526 gpio_pin = tx_en_mode - PORT_HW_CFG_TX_LASER_GPIO0;
4527 gpio_port = bnx2x_get_gpio_port(params);
4528 bnx2x_set_gpio(bp, gpio_pin, gpio_mode, gpio_port);
4529 break;
4530 }
4531 default:
4532 DP(NETIF_MSG_LINK, "Invalid TX_LASER_MDIO 0x%x\n", tx_en_mode);
4533 break;
4534 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004535}
4536
4537static u8 bnx2x_8726_read_sfp_module_eeprom(struct bnx2x_phy *phy,
4538 struct link_params *params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004539 u16 addr, u8 byte_cnt, u8 *o_buf)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004540{
4541 struct bnx2x *bp = params->bp;
4542 u16 val = 0;
4543 u16 i;
4544 if (byte_cnt > 16) {
4545 DP(NETIF_MSG_LINK, "Reading from eeprom is"
4546 " is limited to 0xf\n");
4547 return -EINVAL;
4548 }
4549 /* Set the read command byte count */
4550 bnx2x_cl45_write(bp, phy,
4551 MDIO_PMA_DEVAD, MDIO_PMA_REG_SFP_TWO_WIRE_BYTE_CNT,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004552 (byte_cnt | 0xa000));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004553
4554 /* Set the read command address */
4555 bnx2x_cl45_write(bp, phy,
4556 MDIO_PMA_DEVAD, MDIO_PMA_REG_SFP_TWO_WIRE_MEM_ADDR,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004557 addr);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004558
4559 /* Activate read command */
4560 bnx2x_cl45_write(bp, phy,
4561 MDIO_PMA_DEVAD, MDIO_PMA_REG_SFP_TWO_WIRE_CTRL,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004562 0x2c0f);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004563
4564 /* Wait up to 500us for command complete status */
4565 for (i = 0; i < 100; i++) {
4566 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004567 MDIO_PMA_DEVAD,
4568 MDIO_PMA_REG_SFP_TWO_WIRE_CTRL, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004569 if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) ==
4570 MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_COMPLETE)
4571 break;
4572 udelay(5);
4573 }
4574
4575 if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) !=
4576 MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_COMPLETE) {
4577 DP(NETIF_MSG_LINK,
4578 "Got bad status 0x%x when reading from SFP+ EEPROM\n",
4579 (val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK));
4580 return -EINVAL;
4581 }
4582
4583 /* Read the buffer */
4584 for (i = 0; i < byte_cnt; i++) {
4585 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004586 MDIO_PMA_DEVAD,
4587 MDIO_PMA_REG_8726_TWO_WIRE_DATA_BUF + i, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004588 o_buf[i] = (u8)(val & MDIO_PMA_REG_8726_TWO_WIRE_DATA_MASK);
4589 }
4590
4591 for (i = 0; i < 100; i++) {
4592 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004593 MDIO_PMA_DEVAD,
4594 MDIO_PMA_REG_SFP_TWO_WIRE_CTRL, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004595 if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) ==
4596 MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_IDLE)
Joe Perches6f38ad92010-11-14 17:04:31 +00004597 return 0;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004598 msleep(1);
4599 }
4600 return -EINVAL;
4601}
4602
4603static u8 bnx2x_8727_read_sfp_module_eeprom(struct bnx2x_phy *phy,
4604 struct link_params *params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004605 u16 addr, u8 byte_cnt, u8 *o_buf)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004606{
4607 struct bnx2x *bp = params->bp;
4608 u16 val, i;
4609
4610 if (byte_cnt > 16) {
4611 DP(NETIF_MSG_LINK, "Reading from eeprom is"
4612 " is limited to 0xf\n");
4613 return -EINVAL;
4614 }
4615
4616 /* Need to read from 1.8000 to clear it */
4617 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004618 MDIO_PMA_DEVAD,
4619 MDIO_PMA_REG_SFP_TWO_WIRE_CTRL,
4620 &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004621
4622 /* Set the read command byte count */
4623 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004624 MDIO_PMA_DEVAD,
4625 MDIO_PMA_REG_SFP_TWO_WIRE_BYTE_CNT,
4626 ((byte_cnt < 2) ? 2 : byte_cnt));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004627
4628 /* Set the read command address */
4629 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004630 MDIO_PMA_DEVAD,
4631 MDIO_PMA_REG_SFP_TWO_WIRE_MEM_ADDR,
4632 addr);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004633 /* Set the destination address */
4634 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004635 MDIO_PMA_DEVAD,
4636 0x8004,
4637 MDIO_PMA_REG_8727_TWO_WIRE_DATA_BUF);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004638
4639 /* Activate read command */
4640 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004641 MDIO_PMA_DEVAD,
4642 MDIO_PMA_REG_SFP_TWO_WIRE_CTRL,
4643 0x8002);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00004644 /*
4645 * Wait appropriate time for two-wire command to finish before
4646 * polling the status register
4647 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004648 msleep(1);
4649
4650 /* Wait up to 500us for command complete status */
4651 for (i = 0; i < 100; i++) {
4652 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004653 MDIO_PMA_DEVAD,
4654 MDIO_PMA_REG_SFP_TWO_WIRE_CTRL, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004655 if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) ==
4656 MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_COMPLETE)
4657 break;
4658 udelay(5);
4659 }
4660
4661 if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) !=
4662 MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_COMPLETE) {
4663 DP(NETIF_MSG_LINK,
4664 "Got bad status 0x%x when reading from SFP+ EEPROM\n",
4665 (val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK));
Yaniv Rosner65a001b2011-01-31 04:22:03 +00004666 return -EFAULT;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004667 }
4668
4669 /* Read the buffer */
4670 for (i = 0; i < byte_cnt; i++) {
4671 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004672 MDIO_PMA_DEVAD,
4673 MDIO_PMA_REG_8727_TWO_WIRE_DATA_BUF + i, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004674 o_buf[i] = (u8)(val & MDIO_PMA_REG_8727_TWO_WIRE_DATA_MASK);
4675 }
4676
4677 for (i = 0; i < 100; i++) {
4678 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004679 MDIO_PMA_DEVAD,
4680 MDIO_PMA_REG_SFP_TWO_WIRE_CTRL, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004681 if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) ==
4682 MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_IDLE)
Joe Perches6f38ad92010-11-14 17:04:31 +00004683 return 0;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004684 msleep(1);
4685 }
4686
4687 return -EINVAL;
4688}
4689
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004690u8 bnx2x_read_sfp_module_eeprom(struct bnx2x_phy *phy,
4691 struct link_params *params, u16 addr,
4692 u8 byte_cnt, u8 *o_buf)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004693{
4694 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726)
4695 return bnx2x_8726_read_sfp_module_eeprom(phy, params, addr,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004696 byte_cnt, o_buf);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004697 else if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727)
4698 return bnx2x_8727_read_sfp_module_eeprom(phy, params, addr,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004699 byte_cnt, o_buf);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004700 return -EINVAL;
4701}
4702
4703static u8 bnx2x_get_edc_mode(struct bnx2x_phy *phy,
4704 struct link_params *params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004705 u16 *edc_mode)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004706{
4707 struct bnx2x *bp = params->bp;
4708 u8 val, check_limiting_mode = 0;
4709 *edc_mode = EDC_MODE_LIMITING;
4710
4711 /* First check for copper cable */
4712 if (bnx2x_read_sfp_module_eeprom(phy,
4713 params,
4714 SFP_EEPROM_CON_TYPE_ADDR,
4715 1,
4716 &val) != 0) {
4717 DP(NETIF_MSG_LINK, "Failed to read from SFP+ module EEPROM\n");
4718 return -EINVAL;
4719 }
4720
4721 switch (val) {
4722 case SFP_EEPROM_CON_TYPE_VAL_COPPER:
4723 {
4724 u8 copper_module_type;
4725
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00004726 /*
4727 * Check if its active cable (includes SFP+ module)
4728 * of passive cable
4729 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004730 if (bnx2x_read_sfp_module_eeprom(phy,
4731 params,
4732 SFP_EEPROM_FC_TX_TECH_ADDR,
4733 1,
4734 &copper_module_type) !=
4735 0) {
4736 DP(NETIF_MSG_LINK,
4737 "Failed to read copper-cable-type"
4738 " from SFP+ EEPROM\n");
4739 return -EINVAL;
4740 }
4741
4742 if (copper_module_type &
4743 SFP_EEPROM_FC_TX_TECH_BITMASK_COPPER_ACTIVE) {
4744 DP(NETIF_MSG_LINK, "Active Copper cable detected\n");
4745 check_limiting_mode = 1;
4746 } else if (copper_module_type &
4747 SFP_EEPROM_FC_TX_TECH_BITMASK_COPPER_PASSIVE) {
4748 DP(NETIF_MSG_LINK, "Passive Copper"
4749 " cable detected\n");
4750 *edc_mode =
4751 EDC_MODE_PASSIVE_DAC;
4752 } else {
4753 DP(NETIF_MSG_LINK, "Unknown copper-cable-"
4754 "type 0x%x !!!\n", copper_module_type);
4755 return -EINVAL;
4756 }
4757 break;
4758 }
4759 case SFP_EEPROM_CON_TYPE_VAL_LC:
4760 DP(NETIF_MSG_LINK, "Optic module detected\n");
4761 check_limiting_mode = 1;
4762 break;
4763 default:
4764 DP(NETIF_MSG_LINK, "Unable to determine module type 0x%x !!!\n",
4765 val);
4766 return -EINVAL;
4767 }
4768
4769 if (check_limiting_mode) {
4770 u8 options[SFP_EEPROM_OPTIONS_SIZE];
4771 if (bnx2x_read_sfp_module_eeprom(phy,
4772 params,
4773 SFP_EEPROM_OPTIONS_ADDR,
4774 SFP_EEPROM_OPTIONS_SIZE,
4775 options) != 0) {
4776 DP(NETIF_MSG_LINK, "Failed to read Option"
4777 " field from module EEPROM\n");
4778 return -EINVAL;
4779 }
4780 if ((options[0] & SFP_EEPROM_OPTIONS_LINEAR_RX_OUT_MASK))
4781 *edc_mode = EDC_MODE_LINEAR;
4782 else
4783 *edc_mode = EDC_MODE_LIMITING;
4784 }
4785 DP(NETIF_MSG_LINK, "EDC mode is set to 0x%x\n", *edc_mode);
4786 return 0;
4787}
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00004788/*
4789 * This function read the relevant field from the module (SFP+), and verify it
4790 * is compliant with this board
4791 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004792static u8 bnx2x_verify_sfp_module(struct bnx2x_phy *phy,
4793 struct link_params *params)
4794{
4795 struct bnx2x *bp = params->bp;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00004796 u32 val, cmd;
4797 u32 fw_resp, fw_cmd_param;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004798 char vendor_name[SFP_EEPROM_VENDOR_NAME_SIZE+1];
4799 char vendor_pn[SFP_EEPROM_PART_NO_SIZE+1];
Yaniv Rosnera22f0782010-09-07 11:41:20 +00004800 phy->flags &= ~FLAGS_SFP_NOT_APPROVED;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004801 val = REG_RD(bp, params->shmem_base +
4802 offsetof(struct shmem_region, dev_info.
4803 port_feature_config[params->port].config));
4804 if ((val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) ==
4805 PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_NO_ENFORCEMENT) {
4806 DP(NETIF_MSG_LINK, "NOT enforcing module verification\n");
4807 return 0;
4808 }
4809
Yaniv Rosnera22f0782010-09-07 11:41:20 +00004810 if (params->feature_config_flags &
4811 FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY) {
4812 /* Use specific phy request */
4813 cmd = DRV_MSG_CODE_VRFY_SPECIFIC_PHY_OPT_MDL;
4814 } else if (params->feature_config_flags &
4815 FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY) {
4816 /* Use first phy request only in case of non-dual media*/
4817 if (DUAL_MEDIA(params)) {
4818 DP(NETIF_MSG_LINK, "FW does not support OPT MDL "
4819 "verification\n");
4820 return -EINVAL;
4821 }
4822 cmd = DRV_MSG_CODE_VRFY_FIRST_PHY_OPT_MDL;
4823 } else {
4824 /* No support in OPT MDL detection */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004825 DP(NETIF_MSG_LINK, "FW does not support OPT MDL "
Yaniv Rosnera22f0782010-09-07 11:41:20 +00004826 "verification\n");
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004827 return -EINVAL;
4828 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00004829
Yaniv Rosnera22f0782010-09-07 11:41:20 +00004830 fw_cmd_param = FW_PARAM_SET(phy->addr, phy->type, phy->mdio_ctrl);
4831 fw_resp = bnx2x_fw_command(bp, cmd, fw_cmd_param);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004832 if (fw_resp == FW_MSG_CODE_VRFY_OPT_MDL_SUCCESS) {
4833 DP(NETIF_MSG_LINK, "Approved module\n");
4834 return 0;
4835 }
4836
4837 /* format the warning message */
4838 if (bnx2x_read_sfp_module_eeprom(phy,
4839 params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004840 SFP_EEPROM_VENDOR_NAME_ADDR,
4841 SFP_EEPROM_VENDOR_NAME_SIZE,
4842 (u8 *)vendor_name))
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004843 vendor_name[0] = '\0';
4844 else
4845 vendor_name[SFP_EEPROM_VENDOR_NAME_SIZE] = '\0';
4846 if (bnx2x_read_sfp_module_eeprom(phy,
4847 params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004848 SFP_EEPROM_PART_NO_ADDR,
4849 SFP_EEPROM_PART_NO_SIZE,
4850 (u8 *)vendor_pn))
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004851 vendor_pn[0] = '\0';
4852 else
4853 vendor_pn[SFP_EEPROM_PART_NO_SIZE] = '\0';
4854
Yaniv Rosner6d870c32011-01-31 04:22:20 +00004855 netdev_err(bp->dev, "Warning: Unqualified SFP+ module detected,"
4856 " Port %d from %s part number %s\n",
4857 params->port, vendor_name, vendor_pn);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00004858 phy->flags |= FLAGS_SFP_NOT_APPROVED;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004859 return -EINVAL;
4860}
4861
4862static u8 bnx2x_wait_for_sfp_module_initialized(struct bnx2x_phy *phy,
4863 struct link_params *params)
4864
4865{
4866 u8 val;
4867 struct bnx2x *bp = params->bp;
4868 u16 timeout;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00004869 /*
4870 * Initialization time after hot-plug may take up to 300ms for
4871 * some phys type ( e.g. JDSU )
4872 */
4873
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004874 for (timeout = 0; timeout < 60; timeout++) {
4875 if (bnx2x_read_sfp_module_eeprom(phy, params, 1, 1, &val)
4876 == 0) {
4877 DP(NETIF_MSG_LINK, "SFP+ module initialization "
4878 "took %d ms\n", timeout * 5);
4879 return 0;
4880 }
4881 msleep(5);
4882 }
4883 return -EINVAL;
4884}
4885
4886static void bnx2x_8727_power_module(struct bnx2x *bp,
4887 struct bnx2x_phy *phy,
4888 u8 is_power_up) {
4889 /* Make sure GPIOs are not using for LED mode */
4890 u16 val;
4891 /*
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00004892 * In the GPIO register, bit 4 is use to determine if the GPIOs are
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004893 * operating as INPUT or as OUTPUT. Bit 1 is for input, and 0 for
4894 * output
4895 * Bits 0-1 determine the gpios value for OUTPUT in case bit 4 val is 0
4896 * Bits 8-9 determine the gpios value for INPUT in case bit 4 val is 1
4897 * where the 1st bit is the over-current(only input), and 2nd bit is
4898 * for power( only output )
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00004899 *
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004900 * In case of NOC feature is disabled and power is up, set GPIO control
4901 * as input to enable listening of over-current indication
4902 */
4903 if (phy->flags & FLAGS_NOC)
4904 return;
4905 if (!(phy->flags &
4906 FLAGS_NOC) && is_power_up)
4907 val = (1<<4);
4908 else
4909 /*
4910 * Set GPIO control to OUTPUT, and set the power bit
4911 * to according to the is_power_up
4912 */
4913 val = ((!(is_power_up)) << 1);
4914
4915 bnx2x_cl45_write(bp, phy,
4916 MDIO_PMA_DEVAD,
4917 MDIO_PMA_REG_8727_GPIO_CTRL,
4918 val);
4919}
4920
4921static u8 bnx2x_8726_set_limiting_mode(struct bnx2x *bp,
4922 struct bnx2x_phy *phy,
4923 u16 edc_mode)
4924{
4925 u16 cur_limiting_mode;
4926
4927 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004928 MDIO_PMA_DEVAD,
4929 MDIO_PMA_REG_ROM_VER2,
4930 &cur_limiting_mode);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004931 DP(NETIF_MSG_LINK, "Current Limiting mode is 0x%x\n",
4932 cur_limiting_mode);
4933
4934 if (edc_mode == EDC_MODE_LIMITING) {
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004935 DP(NETIF_MSG_LINK, "Setting LIMITING MODE\n");
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004936 bnx2x_cl45_write(bp, phy,
4937 MDIO_PMA_DEVAD,
4938 MDIO_PMA_REG_ROM_VER2,
4939 EDC_MODE_LIMITING);
4940 } else { /* LRM mode ( default )*/
4941
4942 DP(NETIF_MSG_LINK, "Setting LRM MODE\n");
4943
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00004944 /*
4945 * Changing to LRM mode takes quite few seconds. So do it only
4946 * if current mode is limiting (default is LRM)
4947 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004948 if (cur_limiting_mode != EDC_MODE_LIMITING)
4949 return 0;
4950
4951 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004952 MDIO_PMA_DEVAD,
4953 MDIO_PMA_REG_LRM_MODE,
4954 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004955 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004956 MDIO_PMA_DEVAD,
4957 MDIO_PMA_REG_ROM_VER2,
4958 0x128);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004959 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004960 MDIO_PMA_DEVAD,
4961 MDIO_PMA_REG_MISC_CTRL0,
4962 0x4008);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004963 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004964 MDIO_PMA_DEVAD,
4965 MDIO_PMA_REG_LRM_MODE,
4966 0xaaaa);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004967 }
4968 return 0;
4969}
4970
4971static u8 bnx2x_8727_set_limiting_mode(struct bnx2x *bp,
4972 struct bnx2x_phy *phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004973 u16 edc_mode)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004974{
4975 u16 phy_identifier;
4976 u16 rom_ver2_val;
4977 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004978 MDIO_PMA_DEVAD,
4979 MDIO_PMA_REG_PHY_IDENTIFIER,
4980 &phy_identifier);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004981
4982 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004983 MDIO_PMA_DEVAD,
4984 MDIO_PMA_REG_PHY_IDENTIFIER,
4985 (phy_identifier & ~(1<<9)));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004986
4987 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004988 MDIO_PMA_DEVAD,
4989 MDIO_PMA_REG_ROM_VER2,
4990 &rom_ver2_val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004991 /* Keep the MSB 8-bits, and set the LSB 8-bits with the edc_mode */
4992 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004993 MDIO_PMA_DEVAD,
4994 MDIO_PMA_REG_ROM_VER2,
4995 (rom_ver2_val & 0xff00) | (edc_mode & 0x00ff));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004996
4997 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004998 MDIO_PMA_DEVAD,
4999 MDIO_PMA_REG_PHY_IDENTIFIER,
5000 (phy_identifier | (1<<9)));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005001
5002 return 0;
5003}
5004
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005005static void bnx2x_8727_specific_func(struct bnx2x_phy *phy,
5006 struct link_params *params,
5007 u32 action)
5008{
5009 struct bnx2x *bp = params->bp;
5010
5011 switch (action) {
5012 case DISABLE_TX:
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00005013 bnx2x_sfp_set_transmitter(params, phy, 0);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005014 break;
5015 case ENABLE_TX:
5016 if (!(phy->flags & FLAGS_SFP_NOT_APPROVED))
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00005017 bnx2x_sfp_set_transmitter(params, phy, 1);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005018 break;
5019 default:
5020 DP(NETIF_MSG_LINK, "Function 0x%x not supported by 8727\n",
5021 action);
5022 return;
5023 }
5024}
5025
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00005026static void bnx2x_set_sfp_module_fault_led(struct link_params *params,
5027 u8 gpio_mode)
5028{
5029 struct bnx2x *bp = params->bp;
5030
5031 u32 fault_led_gpio = REG_RD(bp, params->shmem_base +
5032 offsetof(struct shmem_region,
5033 dev_info.port_hw_config[params->port].sfp_ctrl)) &
5034 PORT_HW_CFG_FAULT_MODULE_LED_MASK;
5035 switch (fault_led_gpio) {
5036 case PORT_HW_CFG_FAULT_MODULE_LED_DISABLED:
5037 return;
5038 case PORT_HW_CFG_FAULT_MODULE_LED_GPIO0:
5039 case PORT_HW_CFG_FAULT_MODULE_LED_GPIO1:
5040 case PORT_HW_CFG_FAULT_MODULE_LED_GPIO2:
5041 case PORT_HW_CFG_FAULT_MODULE_LED_GPIO3:
5042 {
5043 u8 gpio_port = bnx2x_get_gpio_port(params);
5044 u16 gpio_pin = fault_led_gpio -
5045 PORT_HW_CFG_FAULT_MODULE_LED_GPIO0;
5046 DP(NETIF_MSG_LINK, "Set fault module-detected led "
5047 "pin %x port %x mode %x\n",
5048 gpio_pin, gpio_port, gpio_mode);
5049 bnx2x_set_gpio(bp, gpio_pin, gpio_mode, gpio_port);
5050 }
5051 break;
5052 default:
5053 DP(NETIF_MSG_LINK, "Error: Invalid fault led mode 0x%x\n",
5054 fault_led_gpio);
5055 }
5056}
5057
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005058static u8 bnx2x_sfp_module_detection(struct bnx2x_phy *phy,
5059 struct link_params *params)
5060{
5061 struct bnx2x *bp = params->bp;
5062 u16 edc_mode;
5063 u8 rc = 0;
5064
5065 u32 val = REG_RD(bp, params->shmem_base +
5066 offsetof(struct shmem_region, dev_info.
5067 port_feature_config[params->port].config));
5068
5069 DP(NETIF_MSG_LINK, "SFP+ module plugged in/out detected on port %d\n",
5070 params->port);
5071
5072 if (bnx2x_get_edc_mode(phy, params, &edc_mode) != 0) {
5073 DP(NETIF_MSG_LINK, "Failed to get valid module type\n");
5074 return -EINVAL;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005075 } else if (bnx2x_verify_sfp_module(phy, params) != 0) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005076 /* check SFP+ module compatibility */
5077 DP(NETIF_MSG_LINK, "Module verification failed!!\n");
5078 rc = -EINVAL;
5079 /* Turn on fault module-detected led */
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00005080 bnx2x_set_sfp_module_fault_led(params,
5081 MISC_REGISTERS_GPIO_HIGH);
5082
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005083 if ((phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727) &&
5084 ((val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) ==
5085 PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_POWER_DOWN)) {
5086 /* Shutdown SFP+ module */
5087 DP(NETIF_MSG_LINK, "Shutdown SFP+ module!!\n");
5088 bnx2x_8727_power_module(bp, phy, 0);
5089 return rc;
5090 }
5091 } else {
5092 /* Turn off fault module-detected led */
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00005093 bnx2x_set_sfp_module_fault_led(params, MISC_REGISTERS_GPIO_LOW);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005094 }
5095
5096 /* power up the SFP module */
5097 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727)
5098 bnx2x_8727_power_module(bp, phy, 1);
5099
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005100 /*
5101 * Check and set limiting mode / LRM mode on 8726. On 8727 it
5102 * is done automatically
5103 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005104 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726)
5105 bnx2x_8726_set_limiting_mode(bp, phy, edc_mode);
5106 else
5107 bnx2x_8727_set_limiting_mode(bp, phy, edc_mode);
5108 /*
5109 * Enable transmit for this module if the module is approved, or
5110 * if unapproved modules should also enable the Tx laser
5111 */
5112 if (rc == 0 ||
5113 (val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) !=
5114 PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_DISABLE_TX_LASER)
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00005115 bnx2x_sfp_set_transmitter(params, phy, 1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005116 else
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00005117 bnx2x_sfp_set_transmitter(params, phy, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005118
5119 return rc;
5120}
5121
5122void bnx2x_handle_module_detect_int(struct link_params *params)
5123{
5124 struct bnx2x *bp = params->bp;
5125 struct bnx2x_phy *phy = &params->phy[EXT_PHY1];
5126 u32 gpio_val;
5127 u8 port = params->port;
5128
5129 /* Set valid module led off */
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00005130 bnx2x_set_sfp_module_fault_led(params, MISC_REGISTERS_GPIO_HIGH);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005131
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005132 /* Get current gpio val reflecting module plugged in / out*/
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005133 gpio_val = bnx2x_get_gpio(bp, MISC_REGISTERS_GPIO_3, port);
5134
5135 /* Call the handling function in case module is detected */
5136 if (gpio_val == 0) {
5137
5138 bnx2x_set_gpio_int(bp, MISC_REGISTERS_GPIO_3,
5139 MISC_REGISTERS_GPIO_INT_OUTPUT_CLR,
5140 port);
5141
5142 if (bnx2x_wait_for_sfp_module_initialized(phy, params) == 0)
5143 bnx2x_sfp_module_detection(phy, params);
5144 else
5145 DP(NETIF_MSG_LINK, "SFP+ module is not initialized\n");
5146 } else {
5147 u32 val = REG_RD(bp, params->shmem_base +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005148 offsetof(struct shmem_region, dev_info.
5149 port_feature_config[params->port].
5150 config));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005151
5152 bnx2x_set_gpio_int(bp, MISC_REGISTERS_GPIO_3,
5153 MISC_REGISTERS_GPIO_INT_OUTPUT_SET,
5154 port);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005155 /*
5156 * Module was plugged out.
5157 * Disable transmit for this module
5158 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005159 if ((val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) ==
5160 PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_DISABLE_TX_LASER)
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00005161 bnx2x_sfp_set_transmitter(params, phy, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005162 }
5163}
5164
5165/******************************************************************/
5166/* common BCM8706/BCM8726 PHY SECTION */
5167/******************************************************************/
5168static u8 bnx2x_8706_8726_read_status(struct bnx2x_phy *phy,
5169 struct link_params *params,
5170 struct link_vars *vars)
5171{
5172 u8 link_up = 0;
5173 u16 val1, val2, rx_sd, pcs_status;
5174 struct bnx2x *bp = params->bp;
5175 DP(NETIF_MSG_LINK, "XGXS 8706/8726\n");
5176 /* Clear RX Alarm*/
5177 bnx2x_cl45_read(bp, phy,
5178 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_ALARM, &val2);
5179 /* clear LASI indication*/
5180 bnx2x_cl45_read(bp, phy,
5181 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_STATUS, &val1);
5182 bnx2x_cl45_read(bp, phy,
5183 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_STATUS, &val2);
5184 DP(NETIF_MSG_LINK, "8706/8726 LASI status 0x%x--> 0x%x\n", val1, val2);
5185
5186 bnx2x_cl45_read(bp, phy,
5187 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_SD, &rx_sd);
5188 bnx2x_cl45_read(bp, phy,
5189 MDIO_PCS_DEVAD, MDIO_PCS_REG_STATUS, &pcs_status);
5190 bnx2x_cl45_read(bp, phy,
5191 MDIO_AN_DEVAD, MDIO_AN_REG_LINK_STATUS, &val2);
5192 bnx2x_cl45_read(bp, phy,
5193 MDIO_AN_DEVAD, MDIO_AN_REG_LINK_STATUS, &val2);
5194
5195 DP(NETIF_MSG_LINK, "8706/8726 rx_sd 0x%x pcs_status 0x%x 1Gbps"
5196 " link_status 0x%x\n", rx_sd, pcs_status, val2);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005197 /*
5198 * link is up if both bit 0 of pmd_rx_sd and bit 0 of pcs_status
5199 * are set, or if the autoneg bit 1 is set
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005200 */
5201 link_up = ((rx_sd & pcs_status & 0x1) || (val2 & (1<<1)));
5202 if (link_up) {
5203 if (val2 & (1<<1))
5204 vars->line_speed = SPEED_1000;
5205 else
5206 vars->line_speed = SPEED_10000;
5207 bnx2x_ext_phy_resolve_fc(phy, params, vars);
Yaniv Rosner791f18c2011-01-18 04:33:42 +00005208 vars->duplex = DUPLEX_FULL;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005209 }
5210 return link_up;
5211}
5212
5213/******************************************************************/
5214/* BCM8706 PHY SECTION */
5215/******************************************************************/
5216static u8 bnx2x_8706_config_init(struct bnx2x_phy *phy,
5217 struct link_params *params,
5218 struct link_vars *vars)
5219{
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00005220 u32 tx_en_mode;
5221 u16 cnt, val, tmp1;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005222 struct bnx2x *bp = params->bp;
5223 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005224 MISC_REGISTERS_GPIO_OUTPUT_HIGH, params->port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005225 /* HW reset */
5226 bnx2x_ext_phy_hw_reset(bp, params->port);
5227 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0xa040);
Yaniv Rosner6d870c32011-01-31 04:22:20 +00005228 bnx2x_wait_reset_complete(bp, phy, params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005229
5230 /* Wait until fw is loaded */
5231 for (cnt = 0; cnt < 100; cnt++) {
5232 bnx2x_cl45_read(bp, phy,
5233 MDIO_PMA_DEVAD, MDIO_PMA_REG_ROM_VER1, &val);
5234 if (val)
5235 break;
5236 msleep(10);
5237 }
5238 DP(NETIF_MSG_LINK, "XGXS 8706 is initialized after %d ms\n", cnt);
5239 if ((params->feature_config_flags &
5240 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED)) {
5241 u8 i;
5242 u16 reg;
5243 for (i = 0; i < 4; i++) {
5244 reg = MDIO_XS_8706_REG_BANK_RX0 +
5245 i*(MDIO_XS_8706_REG_BANK_RX1 -
5246 MDIO_XS_8706_REG_BANK_RX0);
5247 bnx2x_cl45_read(bp, phy, MDIO_XS_DEVAD, reg, &val);
5248 /* Clear first 3 bits of the control */
5249 val &= ~0x7;
5250 /* Set control bits according to configuration */
5251 val |= (phy->rx_preemphasis[i] & 0x7);
5252 DP(NETIF_MSG_LINK, "Setting RX Equalizer to BCM8706"
5253 " reg 0x%x <-- val 0x%x\n", reg, val);
5254 bnx2x_cl45_write(bp, phy, MDIO_XS_DEVAD, reg, val);
5255 }
5256 }
5257 /* Force speed */
5258 if (phy->req_line_speed == SPEED_10000) {
5259 DP(NETIF_MSG_LINK, "XGXS 8706 force 10Gbps\n");
5260
5261 bnx2x_cl45_write(bp, phy,
5262 MDIO_PMA_DEVAD,
5263 MDIO_PMA_REG_DIGITAL_CTRL, 0x400);
5264 bnx2x_cl45_write(bp, phy,
5265 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_CTRL, 1);
5266 } else {
5267 /* Force 1Gbps using autoneg with 1G advertisment */
5268
5269 /* Allow CL37 through CL73 */
5270 DP(NETIF_MSG_LINK, "XGXS 8706 AutoNeg\n");
5271 bnx2x_cl45_write(bp, phy,
5272 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_CL73, 0x040c);
5273
5274 /* Enable Full-Duplex advertisment on CL37 */
5275 bnx2x_cl45_write(bp, phy,
5276 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LP, 0x0020);
5277 /* Enable CL37 AN */
5278 bnx2x_cl45_write(bp, phy,
5279 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_AN, 0x1000);
5280 /* 1G support */
5281 bnx2x_cl45_write(bp, phy,
5282 MDIO_AN_DEVAD, MDIO_AN_REG_ADV, (1<<5));
5283
5284 /* Enable clause 73 AN */
5285 bnx2x_cl45_write(bp, phy,
5286 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x1200);
5287 bnx2x_cl45_write(bp, phy,
5288 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_ALARM_CTRL,
5289 0x0400);
5290 bnx2x_cl45_write(bp, phy,
5291 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_CTRL,
5292 0x0004);
5293 }
5294 bnx2x_save_bcm_spirom_ver(bp, phy, params->port);
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00005295
5296 /*
5297 * If TX Laser is controlled by GPIO_0, do not let PHY go into low
5298 * power mode, if TX Laser is disabled
5299 */
5300
5301 tx_en_mode = REG_RD(bp, params->shmem_base +
5302 offsetof(struct shmem_region,
5303 dev_info.port_hw_config[params->port].sfp_ctrl))
5304 & PORT_HW_CFG_TX_LASER_MASK;
5305
5306 if (tx_en_mode == PORT_HW_CFG_TX_LASER_GPIO0) {
5307 DP(NETIF_MSG_LINK, "Enabling TXONOFF_PWRDN_DIS\n");
5308 bnx2x_cl45_read(bp, phy,
5309 MDIO_PMA_DEVAD, MDIO_PMA_REG_DIGITAL_CTRL, &tmp1);
5310 tmp1 |= 0x1;
5311 bnx2x_cl45_write(bp, phy,
5312 MDIO_PMA_DEVAD, MDIO_PMA_REG_DIGITAL_CTRL, tmp1);
5313 }
5314
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005315 return 0;
5316}
5317
5318static u8 bnx2x_8706_read_status(struct bnx2x_phy *phy,
5319 struct link_params *params,
5320 struct link_vars *vars)
5321{
5322 return bnx2x_8706_8726_read_status(phy, params, vars);
5323}
5324
5325/******************************************************************/
5326/* BCM8726 PHY SECTION */
5327/******************************************************************/
5328static void bnx2x_8726_config_loopback(struct bnx2x_phy *phy,
5329 struct link_params *params)
5330{
5331 struct bnx2x *bp = params->bp;
5332 DP(NETIF_MSG_LINK, "PMA/PMD ext_phy_loopback: 8726\n");
5333 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x0001);
5334}
5335
5336static void bnx2x_8726_external_rom_boot(struct bnx2x_phy *phy,
5337 struct link_params *params)
5338{
5339 struct bnx2x *bp = params->bp;
5340 /* Need to wait 100ms after reset */
5341 msleep(100);
5342
5343 /* Micro controller re-boot */
5344 bnx2x_cl45_write(bp, phy,
5345 MDIO_PMA_DEVAD, MDIO_PMA_REG_GEN_CTRL, 0x018B);
5346
5347 /* Set soft reset */
5348 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005349 MDIO_PMA_DEVAD,
5350 MDIO_PMA_REG_GEN_CTRL,
5351 MDIO_PMA_REG_GEN_CTRL_ROM_MICRO_RESET);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005352
5353 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005354 MDIO_PMA_DEVAD,
5355 MDIO_PMA_REG_MISC_CTRL1, 0x0001);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005356
5357 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005358 MDIO_PMA_DEVAD,
5359 MDIO_PMA_REG_GEN_CTRL,
5360 MDIO_PMA_REG_GEN_CTRL_ROM_RESET_INTERNAL_MP);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005361
5362 /* wait for 150ms for microcode load */
5363 msleep(150);
5364
5365 /* Disable serial boot control, tristates pins SS_N, SCK, MOSI, MISO */
5366 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005367 MDIO_PMA_DEVAD,
5368 MDIO_PMA_REG_MISC_CTRL1, 0x0000);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005369
5370 msleep(200);
5371 bnx2x_save_bcm_spirom_ver(bp, phy, params->port);
5372}
5373
5374static u8 bnx2x_8726_read_status(struct bnx2x_phy *phy,
5375 struct link_params *params,
5376 struct link_vars *vars)
5377{
5378 struct bnx2x *bp = params->bp;
5379 u16 val1;
5380 u8 link_up = bnx2x_8706_8726_read_status(phy, params, vars);
5381 if (link_up) {
5382 bnx2x_cl45_read(bp, phy,
5383 MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER,
5384 &val1);
5385 if (val1 & (1<<15)) {
5386 DP(NETIF_MSG_LINK, "Tx is disabled\n");
5387 link_up = 0;
5388 vars->line_speed = 0;
5389 }
5390 }
5391 return link_up;
5392}
5393
5394
5395static u8 bnx2x_8726_config_init(struct bnx2x_phy *phy,
5396 struct link_params *params,
5397 struct link_vars *vars)
5398{
5399 struct bnx2x *bp = params->bp;
5400 u32 val;
5401 u32 swap_val, swap_override, aeu_gpio_mask, offset;
5402 DP(NETIF_MSG_LINK, "Initializing BCM8726\n");
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005403
5404 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 1<<15);
Yaniv Rosner6d870c32011-01-31 04:22:20 +00005405 bnx2x_wait_reset_complete(bp, phy, params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005406
5407 bnx2x_8726_external_rom_boot(phy, params);
5408
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005409 /*
5410 * Need to call module detected on initialization since the module
5411 * detection triggered by actual module insertion might occur before
5412 * driver is loaded, and when driver is loaded, it reset all
5413 * registers, including the transmitter
5414 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005415 bnx2x_sfp_module_detection(phy, params);
5416
5417 if (phy->req_line_speed == SPEED_1000) {
5418 DP(NETIF_MSG_LINK, "Setting 1G force\n");
5419 bnx2x_cl45_write(bp, phy,
5420 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x40);
5421 bnx2x_cl45_write(bp, phy,
5422 MDIO_PMA_DEVAD, MDIO_PMA_REG_10G_CTRL2, 0xD);
5423 bnx2x_cl45_write(bp, phy,
5424 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_CTRL, 0x5);
5425 bnx2x_cl45_write(bp, phy,
5426 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_ALARM_CTRL,
5427 0x400);
5428 } else if ((phy->req_line_speed == SPEED_AUTO_NEG) &&
5429 (phy->speed_cap_mask &
5430 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G) &&
5431 ((phy->speed_cap_mask &
5432 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G) !=
5433 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) {
5434 DP(NETIF_MSG_LINK, "Setting 1G clause37\n");
5435 /* Set Flow control */
5436 bnx2x_ext_phy_set_pause(params, phy, vars);
5437 bnx2x_cl45_write(bp, phy,
5438 MDIO_AN_DEVAD, MDIO_AN_REG_ADV, 0x20);
5439 bnx2x_cl45_write(bp, phy,
5440 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_CL73, 0x040c);
5441 bnx2x_cl45_write(bp, phy,
5442 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LD, 0x0020);
5443 bnx2x_cl45_write(bp, phy,
5444 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_AN, 0x1000);
5445 bnx2x_cl45_write(bp, phy,
5446 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x1200);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005447 /*
5448 * Enable RX-ALARM control to receive interrupt for 1G speed
5449 * change
5450 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005451 bnx2x_cl45_write(bp, phy,
5452 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_CTRL, 0x4);
5453 bnx2x_cl45_write(bp, phy,
5454 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_ALARM_CTRL,
5455 0x400);
5456
5457 } else { /* Default 10G. Set only LASI control */
5458 bnx2x_cl45_write(bp, phy,
5459 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_CTRL, 1);
5460 }
5461
5462 /* Set TX PreEmphasis if needed */
5463 if ((params->feature_config_flags &
5464 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED)) {
5465 DP(NETIF_MSG_LINK, "Setting TX_CTRL1 0x%x,"
5466 "TX_CTRL2 0x%x\n",
5467 phy->tx_preemphasis[0],
5468 phy->tx_preemphasis[1]);
5469 bnx2x_cl45_write(bp, phy,
5470 MDIO_PMA_DEVAD,
5471 MDIO_PMA_REG_8726_TX_CTRL1,
5472 phy->tx_preemphasis[0]);
5473
5474 bnx2x_cl45_write(bp, phy,
5475 MDIO_PMA_DEVAD,
5476 MDIO_PMA_REG_8726_TX_CTRL2,
5477 phy->tx_preemphasis[1]);
5478 }
5479
5480 /* Set GPIO3 to trigger SFP+ module insertion/removal */
5481 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_3,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005482 MISC_REGISTERS_GPIO_INPUT_HI_Z, params->port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005483
5484 /* The GPIO should be swapped if the swap register is set and active */
5485 swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
5486 swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
5487
5488 /* Select function upon port-swap configuration */
5489 if (params->port == 0) {
5490 offset = MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0;
5491 aeu_gpio_mask = (swap_val && swap_override) ?
5492 AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_1 :
5493 AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_0;
5494 } else {
5495 offset = MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0;
5496 aeu_gpio_mask = (swap_val && swap_override) ?
5497 AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_0 :
5498 AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_1;
5499 }
5500 val = REG_RD(bp, offset);
5501 /* add GPIO3 to group */
5502 val |= aeu_gpio_mask;
5503 REG_WR(bp, offset, val);
5504 return 0;
5505
5506}
5507
5508static void bnx2x_8726_link_reset(struct bnx2x_phy *phy,
5509 struct link_params *params)
5510{
5511 struct bnx2x *bp = params->bp;
5512 DP(NETIF_MSG_LINK, "bnx2x_8726_link_reset port %d\n", params->port);
5513 /* Set serial boot control for external load */
5514 bnx2x_cl45_write(bp, phy,
5515 MDIO_PMA_DEVAD,
5516 MDIO_PMA_REG_GEN_CTRL, 0x0001);
5517}
5518
5519/******************************************************************/
5520/* BCM8727 PHY SECTION */
5521/******************************************************************/
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00005522
5523static void bnx2x_8727_set_link_led(struct bnx2x_phy *phy,
5524 struct link_params *params, u8 mode)
5525{
5526 struct bnx2x *bp = params->bp;
5527 u16 led_mode_bitmask = 0;
5528 u16 gpio_pins_bitmask = 0;
5529 u16 val;
5530 /* Only NOC flavor requires to set the LED specifically */
5531 if (!(phy->flags & FLAGS_NOC))
5532 return;
5533 switch (mode) {
5534 case LED_MODE_FRONT_PANEL_OFF:
5535 case LED_MODE_OFF:
5536 led_mode_bitmask = 0;
5537 gpio_pins_bitmask = 0x03;
5538 break;
5539 case LED_MODE_ON:
5540 led_mode_bitmask = 0;
5541 gpio_pins_bitmask = 0x02;
5542 break;
5543 case LED_MODE_OPER:
5544 led_mode_bitmask = 0x60;
5545 gpio_pins_bitmask = 0x11;
5546 break;
5547 }
5548 bnx2x_cl45_read(bp, phy,
5549 MDIO_PMA_DEVAD,
5550 MDIO_PMA_REG_8727_PCS_OPT_CTRL,
5551 &val);
5552 val &= 0xff8f;
5553 val |= led_mode_bitmask;
5554 bnx2x_cl45_write(bp, phy,
5555 MDIO_PMA_DEVAD,
5556 MDIO_PMA_REG_8727_PCS_OPT_CTRL,
5557 val);
5558 bnx2x_cl45_read(bp, phy,
5559 MDIO_PMA_DEVAD,
5560 MDIO_PMA_REG_8727_GPIO_CTRL,
5561 &val);
5562 val &= 0xffe0;
5563 val |= gpio_pins_bitmask;
5564 bnx2x_cl45_write(bp, phy,
5565 MDIO_PMA_DEVAD,
5566 MDIO_PMA_REG_8727_GPIO_CTRL,
5567 val);
5568}
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005569static void bnx2x_8727_hw_reset(struct bnx2x_phy *phy,
5570 struct link_params *params) {
5571 u32 swap_val, swap_override;
5572 u8 port;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005573 /*
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005574 * The PHY reset is controlled by GPIO 1. Fake the port number
5575 * to cancel the swap done in set_gpio()
5576 */
5577 struct bnx2x *bp = params->bp;
5578 swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
5579 swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
5580 port = (swap_val && swap_override) ^ 1;
5581 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005582 MISC_REGISTERS_GPIO_OUTPUT_LOW, port);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005583}
5584
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005585static u8 bnx2x_8727_config_init(struct bnx2x_phy *phy,
5586 struct link_params *params,
5587 struct link_vars *vars)
5588{
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00005589 u32 tx_en_mode;
5590 u16 tmp1, val, mod_abs, tmp2;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005591 u16 rx_alarm_ctrl_val;
5592 u16 lasi_ctrl_val;
5593 struct bnx2x *bp = params->bp;
5594 /* Enable PMD link, MOD_ABS_FLT, and 1G link alarm */
5595
Yaniv Rosner6d870c32011-01-31 04:22:20 +00005596 bnx2x_wait_reset_complete(bp, phy, params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005597 rx_alarm_ctrl_val = (1<<2) | (1<<5) ;
5598 lasi_ctrl_val = 0x0004;
5599
5600 DP(NETIF_MSG_LINK, "Initializing BCM8727\n");
5601 /* enable LASI */
5602 bnx2x_cl45_write(bp, phy,
5603 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_ALARM_CTRL,
5604 rx_alarm_ctrl_val);
5605
5606 bnx2x_cl45_write(bp, phy,
5607 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_CTRL, lasi_ctrl_val);
5608
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005609 /*
5610 * Initially configure MOD_ABS to interrupt when module is
5611 * presence( bit 8)
5612 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005613 bnx2x_cl45_read(bp, phy,
5614 MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER, &mod_abs);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005615 /*
5616 * Set EDC off by setting OPTXLOS signal input to low (bit 9).
5617 * When the EDC is off it locks onto a reference clock and avoids
5618 * becoming 'lost'
5619 */
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00005620 mod_abs &= ~(1<<8);
5621 if (!(phy->flags & FLAGS_NOC))
5622 mod_abs &= ~(1<<9);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005623 bnx2x_cl45_write(bp, phy,
5624 MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER, mod_abs);
5625
5626
5627 /* Make MOD_ABS give interrupt on change */
5628 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_PCS_OPT_CTRL,
5629 &val);
5630 val |= (1<<12);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00005631 if (phy->flags & FLAGS_NOC)
5632 val |= (3<<5);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005633
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005634 /*
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00005635 * Set 8727 GPIOs to input to allow reading from the 8727 GPIO0
5636 * status which reflect SFP+ module over-current
5637 */
5638 if (!(phy->flags & FLAGS_NOC))
5639 val &= 0xff8f; /* Reset bits 4-6 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005640 bnx2x_cl45_write(bp, phy,
5641 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_PCS_OPT_CTRL, val);
5642
5643 bnx2x_8727_power_module(bp, phy, 1);
5644
5645 bnx2x_cl45_read(bp, phy,
5646 MDIO_PMA_DEVAD, MDIO_PMA_REG_M8051_MSGOUT_REG, &tmp1);
5647
5648 bnx2x_cl45_read(bp, phy,
5649 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_ALARM, &tmp1);
5650
5651 /* Set option 1G speed */
5652 if (phy->req_line_speed == SPEED_1000) {
5653 DP(NETIF_MSG_LINK, "Setting 1G force\n");
5654 bnx2x_cl45_write(bp, phy,
5655 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x40);
5656 bnx2x_cl45_write(bp, phy,
5657 MDIO_PMA_DEVAD, MDIO_PMA_REG_10G_CTRL2, 0xD);
5658 bnx2x_cl45_read(bp, phy,
5659 MDIO_PMA_DEVAD, MDIO_PMA_REG_10G_CTRL2, &tmp1);
5660 DP(NETIF_MSG_LINK, "1.7 = 0x%x\n", tmp1);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005661 /*
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005662 * Power down the XAUI until link is up in case of dual-media
5663 * and 1G
5664 */
5665 if (DUAL_MEDIA(params)) {
5666 bnx2x_cl45_read(bp, phy,
5667 MDIO_PMA_DEVAD,
5668 MDIO_PMA_REG_8727_PCS_GP, &val);
5669 val |= (3<<10);
5670 bnx2x_cl45_write(bp, phy,
5671 MDIO_PMA_DEVAD,
5672 MDIO_PMA_REG_8727_PCS_GP, val);
5673 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005674 } else if ((phy->req_line_speed == SPEED_AUTO_NEG) &&
5675 ((phy->speed_cap_mask &
5676 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) &&
5677 ((phy->speed_cap_mask &
5678 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G) !=
5679 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) {
5680
5681 DP(NETIF_MSG_LINK, "Setting 1G clause37\n");
5682 bnx2x_cl45_write(bp, phy,
5683 MDIO_AN_DEVAD, MDIO_AN_REG_8727_MISC_CTRL, 0);
5684 bnx2x_cl45_write(bp, phy,
5685 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_AN, 0x1300);
5686 } else {
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005687 /*
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005688 * Since the 8727 has only single reset pin, need to set the 10G
5689 * registers although it is default
5690 */
5691 bnx2x_cl45_write(bp, phy,
5692 MDIO_AN_DEVAD, MDIO_AN_REG_8727_MISC_CTRL,
5693 0x0020);
5694 bnx2x_cl45_write(bp, phy,
5695 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_AN, 0x0100);
5696 bnx2x_cl45_write(bp, phy,
5697 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x2040);
5698 bnx2x_cl45_write(bp, phy,
5699 MDIO_PMA_DEVAD, MDIO_PMA_REG_10G_CTRL2,
5700 0x0008);
5701 }
5702
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005703 /*
5704 * Set 2-wire transfer rate of SFP+ module EEPROM
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005705 * to 100Khz since some DACs(direct attached cables) do
5706 * not work at 400Khz.
5707 */
5708 bnx2x_cl45_write(bp, phy,
5709 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_TWO_WIRE_SLAVE_ADDR,
5710 0xa001);
5711
5712 /* Set TX PreEmphasis if needed */
5713 if ((params->feature_config_flags &
5714 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED)) {
5715 DP(NETIF_MSG_LINK, "Setting TX_CTRL1 0x%x, TX_CTRL2 0x%x\n",
5716 phy->tx_preemphasis[0],
5717 phy->tx_preemphasis[1]);
5718 bnx2x_cl45_write(bp, phy,
5719 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_TX_CTRL1,
5720 phy->tx_preemphasis[0]);
5721
5722 bnx2x_cl45_write(bp, phy,
5723 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_TX_CTRL2,
5724 phy->tx_preemphasis[1]);
5725 }
5726
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00005727 /*
5728 * If TX Laser is controlled by GPIO_0, do not let PHY go into low
5729 * power mode, if TX Laser is disabled
5730 */
5731 tx_en_mode = REG_RD(bp, params->shmem_base +
5732 offsetof(struct shmem_region,
5733 dev_info.port_hw_config[params->port].sfp_ctrl))
5734 & PORT_HW_CFG_TX_LASER_MASK;
5735
5736 if (tx_en_mode == PORT_HW_CFG_TX_LASER_GPIO0) {
5737
5738 DP(NETIF_MSG_LINK, "Enabling TXONOFF_PWRDN_DIS\n");
5739 bnx2x_cl45_read(bp, phy,
5740 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_OPT_CFG_REG, &tmp2);
5741 tmp2 |= 0x1000;
5742 tmp2 &= 0xFFEF;
5743 bnx2x_cl45_write(bp, phy,
5744 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_OPT_CFG_REG, tmp2);
5745 }
5746
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005747 return 0;
5748}
5749
5750static void bnx2x_8727_handle_mod_abs(struct bnx2x_phy *phy,
5751 struct link_params *params)
5752{
5753 struct bnx2x *bp = params->bp;
5754 u16 mod_abs, rx_alarm_status;
5755 u32 val = REG_RD(bp, params->shmem_base +
5756 offsetof(struct shmem_region, dev_info.
5757 port_feature_config[params->port].
5758 config));
5759 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005760 MDIO_PMA_DEVAD,
5761 MDIO_PMA_REG_PHY_IDENTIFIER, &mod_abs);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005762 if (mod_abs & (1<<8)) {
5763
5764 /* Module is absent */
5765 DP(NETIF_MSG_LINK, "MOD_ABS indication "
5766 "show module is absent\n");
5767
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005768 /*
5769 * 1. Set mod_abs to detect next module
5770 * presence event
5771 * 2. Set EDC off by setting OPTXLOS signal input to low
5772 * (bit 9).
5773 * When the EDC is off it locks onto a reference clock and
5774 * avoids becoming 'lost'.
5775 */
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00005776 mod_abs &= ~(1<<8);
5777 if (!(phy->flags & FLAGS_NOC))
5778 mod_abs &= ~(1<<9);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005779 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005780 MDIO_PMA_DEVAD,
5781 MDIO_PMA_REG_PHY_IDENTIFIER, mod_abs);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005782
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005783 /*
5784 * Clear RX alarm since it stays up as long as
5785 * the mod_abs wasn't changed
5786 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005787 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005788 MDIO_PMA_DEVAD,
5789 MDIO_PMA_REG_RX_ALARM, &rx_alarm_status);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005790
5791 } else {
5792 /* Module is present */
5793 DP(NETIF_MSG_LINK, "MOD_ABS indication "
5794 "show module is present\n");
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005795 /*
5796 * First disable transmitter, and if the module is ok, the
5797 * module_detection will enable it
5798 * 1. Set mod_abs to detect next module absent event ( bit 8)
5799 * 2. Restore the default polarity of the OPRXLOS signal and
5800 * this signal will then correctly indicate the presence or
5801 * absence of the Rx signal. (bit 9)
5802 */
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00005803 mod_abs |= (1<<8);
5804 if (!(phy->flags & FLAGS_NOC))
5805 mod_abs |= (1<<9);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005806 bnx2x_cl45_write(bp, phy,
5807 MDIO_PMA_DEVAD,
5808 MDIO_PMA_REG_PHY_IDENTIFIER, mod_abs);
5809
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005810 /*
5811 * Clear RX alarm since it stays up as long as the mod_abs
5812 * wasn't changed. This is need to be done before calling the
5813 * module detection, otherwise it will clear* the link update
5814 * alarm
5815 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005816 bnx2x_cl45_read(bp, phy,
5817 MDIO_PMA_DEVAD,
5818 MDIO_PMA_REG_RX_ALARM, &rx_alarm_status);
5819
5820
5821 if ((val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) ==
5822 PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_DISABLE_TX_LASER)
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00005823 bnx2x_sfp_set_transmitter(params, phy, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005824
5825 if (bnx2x_wait_for_sfp_module_initialized(phy, params) == 0)
5826 bnx2x_sfp_module_detection(phy, params);
5827 else
5828 DP(NETIF_MSG_LINK, "SFP+ module is not initialized\n");
5829 }
5830
5831 DP(NETIF_MSG_LINK, "8727 RX_ALARM_STATUS 0x%x\n",
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005832 rx_alarm_status);
5833 /* No need to check link status in case of module plugged in/out */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005834}
5835
5836static u8 bnx2x_8727_read_status(struct bnx2x_phy *phy,
5837 struct link_params *params,
5838 struct link_vars *vars)
5839
5840{
5841 struct bnx2x *bp = params->bp;
5842 u8 link_up = 0;
5843 u16 link_status = 0;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005844 u16 rx_alarm_status, lasi_ctrl, val1;
5845
5846 /* If PHY is not initialized, do not check link status */
5847 bnx2x_cl45_read(bp, phy,
5848 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_CTRL,
5849 &lasi_ctrl);
5850 if (!lasi_ctrl)
5851 return 0;
5852
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005853 /* Check the LASI */
5854 bnx2x_cl45_read(bp, phy,
5855 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_ALARM,
5856 &rx_alarm_status);
5857 vars->line_speed = 0;
5858 DP(NETIF_MSG_LINK, "8727 RX_ALARM_STATUS 0x%x\n", rx_alarm_status);
5859
5860 bnx2x_cl45_read(bp, phy,
5861 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_STATUS, &val1);
5862
5863 DP(NETIF_MSG_LINK, "8727 LASI status 0x%x\n", val1);
5864
5865 /* Clear MSG-OUT */
5866 bnx2x_cl45_read(bp, phy,
5867 MDIO_PMA_DEVAD, MDIO_PMA_REG_M8051_MSGOUT_REG, &val1);
5868
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005869 /*
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005870 * If a module is present and there is need to check
5871 * for over current
5872 */
5873 if (!(phy->flags & FLAGS_NOC) && !(rx_alarm_status & (1<<5))) {
5874 /* Check over-current using 8727 GPIO0 input*/
5875 bnx2x_cl45_read(bp, phy,
5876 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_GPIO_CTRL,
5877 &val1);
5878
5879 if ((val1 & (1<<8)) == 0) {
5880 DP(NETIF_MSG_LINK, "8727 Power fault has been detected"
5881 " on port %d\n", params->port);
5882 netdev_err(bp->dev, "Error: Power fault on Port %d has"
5883 " been detected and the power to "
5884 "that SFP+ module has been removed"
5885 " to prevent failure of the card."
5886 " Please remove the SFP+ module and"
5887 " restart the system to clear this"
5888 " error.\n",
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005889 params->port);
5890 /* Disable all RX_ALARMs except for mod_abs */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005891 bnx2x_cl45_write(bp, phy,
5892 MDIO_PMA_DEVAD,
5893 MDIO_PMA_REG_RX_ALARM_CTRL, (1<<5));
5894
5895 bnx2x_cl45_read(bp, phy,
5896 MDIO_PMA_DEVAD,
5897 MDIO_PMA_REG_PHY_IDENTIFIER, &val1);
5898 /* Wait for module_absent_event */
5899 val1 |= (1<<8);
5900 bnx2x_cl45_write(bp, phy,
5901 MDIO_PMA_DEVAD,
5902 MDIO_PMA_REG_PHY_IDENTIFIER, val1);
5903 /* Clear RX alarm */
5904 bnx2x_cl45_read(bp, phy,
5905 MDIO_PMA_DEVAD,
5906 MDIO_PMA_REG_RX_ALARM, &rx_alarm_status);
5907 return 0;
5908 }
5909 } /* Over current check */
5910
5911 /* When module absent bit is set, check module */
5912 if (rx_alarm_status & (1<<5)) {
5913 bnx2x_8727_handle_mod_abs(phy, params);
5914 /* Enable all mod_abs and link detection bits */
5915 bnx2x_cl45_write(bp, phy,
5916 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_ALARM_CTRL,
5917 ((1<<5) | (1<<2)));
5918 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005919 DP(NETIF_MSG_LINK, "Enabling 8727 TX laser if SFP is approved\n");
5920 bnx2x_8727_specific_func(phy, params, ENABLE_TX);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005921 /* If transmitter is disabled, ignore false link up indication */
5922 bnx2x_cl45_read(bp, phy,
5923 MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER, &val1);
5924 if (val1 & (1<<15)) {
5925 DP(NETIF_MSG_LINK, "Tx is disabled\n");
5926 return 0;
5927 }
5928
5929 bnx2x_cl45_read(bp, phy,
5930 MDIO_PMA_DEVAD,
5931 MDIO_PMA_REG_8073_SPEED_LINK_STATUS, &link_status);
5932
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005933 /*
5934 * Bits 0..2 --> speed detected,
5935 * Bits 13..15--> link is down
5936 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005937 if ((link_status & (1<<2)) && (!(link_status & (1<<15)))) {
5938 link_up = 1;
5939 vars->line_speed = SPEED_10000;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005940 DP(NETIF_MSG_LINK, "port %x: External link up in 10G\n",
5941 params->port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005942 } else if ((link_status & (1<<0)) && (!(link_status & (1<<13)))) {
5943 link_up = 1;
5944 vars->line_speed = SPEED_1000;
5945 DP(NETIF_MSG_LINK, "port %x: External link up in 1G\n",
5946 params->port);
5947 } else {
5948 link_up = 0;
5949 DP(NETIF_MSG_LINK, "port %x: External link is down\n",
5950 params->port);
5951 }
Yaniv Rosner791f18c2011-01-18 04:33:42 +00005952 if (link_up) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005953 bnx2x_ext_phy_resolve_fc(phy, params, vars);
Yaniv Rosner791f18c2011-01-18 04:33:42 +00005954 vars->duplex = DUPLEX_FULL;
5955 DP(NETIF_MSG_LINK, "duplex = 0x%x\n", vars->duplex);
5956 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005957
5958 if ((DUAL_MEDIA(params)) &&
5959 (phy->req_line_speed == SPEED_1000)) {
5960 bnx2x_cl45_read(bp, phy,
5961 MDIO_PMA_DEVAD,
5962 MDIO_PMA_REG_8727_PCS_GP, &val1);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005963 /*
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005964 * In case of dual-media board and 1G, power up the XAUI side,
5965 * otherwise power it down. For 10G it is done automatically
5966 */
5967 if (link_up)
5968 val1 &= ~(3<<10);
5969 else
5970 val1 |= (3<<10);
5971 bnx2x_cl45_write(bp, phy,
5972 MDIO_PMA_DEVAD,
5973 MDIO_PMA_REG_8727_PCS_GP, val1);
5974 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005975 return link_up;
5976}
5977
5978static void bnx2x_8727_link_reset(struct bnx2x_phy *phy,
5979 struct link_params *params)
5980{
5981 struct bnx2x *bp = params->bp;
5982 /* Disable Transmitter */
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00005983 bnx2x_sfp_set_transmitter(params, phy, 0);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005984 /* Clear LASI */
5985 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_CTRL, 0);
5986
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005987}
5988
5989/******************************************************************/
5990/* BCM8481/BCM84823/BCM84833 PHY SECTION */
5991/******************************************************************/
5992static void bnx2x_save_848xx_spirom_version(struct bnx2x_phy *phy,
5993 struct link_params *params)
5994{
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00005995 u16 val, fw_ver1, fw_ver2, cnt, adj;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005996 struct bnx2x *bp = params->bp;
5997
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00005998 adj = 0;
5999 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
6000 adj = -1;
6001
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006002 /* For the 32 bits registers in 848xx, access via MDIO2ARM interface.*/
6003 /* (1) set register 0xc200_0014(SPI_BRIDGE_CTRL_2) to 0x03000000 */
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00006004 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA819 + adj, 0x0014);
6005 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA81A + adj, 0xc200);
6006 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA81B + adj, 0x0000);
6007 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA81C + adj, 0x0300);
6008 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA817 + adj, 0x0009);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006009
6010 for (cnt = 0; cnt < 100; cnt++) {
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00006011 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD, 0xA818 + adj, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006012 if (val & 1)
6013 break;
6014 udelay(5);
6015 }
6016 if (cnt == 100) {
6017 DP(NETIF_MSG_LINK, "Unable to read 848xx phy fw version(1)\n");
6018 bnx2x_save_spirom_version(bp, params->port, 0,
6019 phy->ver_addr);
6020 return;
6021 }
6022
6023
6024 /* 2) read register 0xc200_0000 (SPI_FW_STATUS) */
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00006025 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA819 + adj, 0x0000);
6026 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA81A + adj, 0xc200);
6027 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA817 + adj, 0x000A);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006028 for (cnt = 0; cnt < 100; cnt++) {
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00006029 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD, 0xA818 + adj, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006030 if (val & 1)
6031 break;
6032 udelay(5);
6033 }
6034 if (cnt == 100) {
6035 DP(NETIF_MSG_LINK, "Unable to read 848xx phy fw version(2)\n");
6036 bnx2x_save_spirom_version(bp, params->port, 0,
6037 phy->ver_addr);
6038 return;
6039 }
6040
6041 /* lower 16 bits of the register SPI_FW_STATUS */
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00006042 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD, 0xA81B + adj, &fw_ver1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006043 /* upper 16 bits of register SPI_FW_STATUS */
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00006044 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD, 0xA81C + adj, &fw_ver2);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006045
6046 bnx2x_save_spirom_version(bp, params->port, (fw_ver2<<16) | fw_ver1,
6047 phy->ver_addr);
6048}
6049
6050static void bnx2x_848xx_set_led(struct bnx2x *bp,
6051 struct bnx2x_phy *phy)
6052{
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00006053 u16 val, adj;
6054
6055 adj = 0;
6056 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
6057 adj = -1;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006058
6059 /* PHYC_CTL_LED_CTL */
6060 bnx2x_cl45_read(bp, phy,
6061 MDIO_PMA_DEVAD,
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00006062 MDIO_PMA_REG_8481_LINK_SIGNAL + adj, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006063 val &= 0xFE00;
6064 val |= 0x0092;
6065
6066 bnx2x_cl45_write(bp, phy,
6067 MDIO_PMA_DEVAD,
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00006068 MDIO_PMA_REG_8481_LINK_SIGNAL + adj, val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006069
6070 bnx2x_cl45_write(bp, phy,
6071 MDIO_PMA_DEVAD,
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00006072 MDIO_PMA_REG_8481_LED1_MASK + adj,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006073 0x80);
6074
6075 bnx2x_cl45_write(bp, phy,
6076 MDIO_PMA_DEVAD,
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00006077 MDIO_PMA_REG_8481_LED2_MASK + adj,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006078 0x18);
6079
Yaniv Rosnerf25b3c82011-01-18 04:33:47 +00006080 /* Select activity source by Tx and Rx, as suggested by PHY AE */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006081 bnx2x_cl45_write(bp, phy,
6082 MDIO_PMA_DEVAD,
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00006083 MDIO_PMA_REG_8481_LED3_MASK + adj,
Yaniv Rosnerf25b3c82011-01-18 04:33:47 +00006084 0x0006);
6085
6086 /* Select the closest activity blink rate to that in 10/100/1000 */
6087 bnx2x_cl45_write(bp, phy,
6088 MDIO_PMA_DEVAD,
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00006089 MDIO_PMA_REG_8481_LED3_BLINK + adj,
Yaniv Rosnerf25b3c82011-01-18 04:33:47 +00006090 0);
6091
6092 bnx2x_cl45_read(bp, phy,
6093 MDIO_PMA_DEVAD,
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00006094 MDIO_PMA_REG_84823_CTL_LED_CTL_1 + adj, &val);
Yaniv Rosnerf25b3c82011-01-18 04:33:47 +00006095 val |= MDIO_PMA_REG_84823_LED3_STRETCH_EN; /* stretch_en for LED3*/
6096
6097 bnx2x_cl45_write(bp, phy,
6098 MDIO_PMA_DEVAD,
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00006099 MDIO_PMA_REG_84823_CTL_LED_CTL_1 + adj, val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006100
6101 /* 'Interrupt Mask' */
6102 bnx2x_cl45_write(bp, phy,
6103 MDIO_AN_DEVAD,
6104 0xFFFB, 0xFFFD);
6105}
6106
6107static u8 bnx2x_848xx_cmn_config_init(struct bnx2x_phy *phy,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006108 struct link_params *params,
6109 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006110{
6111 struct bnx2x *bp = params->bp;
6112 u16 autoneg_val, an_1000_val, an_10_100_val;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006113 /*
6114 * This phy uses the NIG latch mechanism since link indication
6115 * arrives through its LED4 and not via its LASI signal, so we
6116 * get steady signal instead of clear on read
6117 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006118 bnx2x_bits_en(bp, NIG_REG_LATCH_BC_0 + params->port*4,
6119 1 << NIG_LATCH_BC_ENABLE_MI_INT);
6120
6121 bnx2x_cl45_write(bp, phy,
6122 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x0000);
6123
6124 bnx2x_848xx_set_led(bp, phy);
6125
6126 /* set 1000 speed advertisement */
6127 bnx2x_cl45_read(bp, phy,
6128 MDIO_AN_DEVAD, MDIO_AN_REG_8481_1000T_CTRL,
6129 &an_1000_val);
6130
6131 bnx2x_ext_phy_set_pause(params, phy, vars);
6132 bnx2x_cl45_read(bp, phy,
6133 MDIO_AN_DEVAD,
6134 MDIO_AN_REG_8481_LEGACY_AN_ADV,
6135 &an_10_100_val);
6136 bnx2x_cl45_read(bp, phy,
6137 MDIO_AN_DEVAD, MDIO_AN_REG_8481_LEGACY_MII_CTRL,
6138 &autoneg_val);
6139 /* Disable forced speed */
6140 autoneg_val &= ~((1<<6) | (1<<8) | (1<<9) | (1<<12) | (1<<13));
6141 an_10_100_val &= ~((1<<5) | (1<<6) | (1<<7) | (1<<8));
6142
6143 if (((phy->req_line_speed == SPEED_AUTO_NEG) &&
6144 (phy->speed_cap_mask &
6145 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) ||
6146 (phy->req_line_speed == SPEED_1000)) {
6147 an_1000_val |= (1<<8);
6148 autoneg_val |= (1<<9 | 1<<12);
6149 if (phy->req_duplex == DUPLEX_FULL)
6150 an_1000_val |= (1<<9);
6151 DP(NETIF_MSG_LINK, "Advertising 1G\n");
6152 } else
6153 an_1000_val &= ~((1<<8) | (1<<9));
6154
6155 bnx2x_cl45_write(bp, phy,
6156 MDIO_AN_DEVAD, MDIO_AN_REG_8481_1000T_CTRL,
6157 an_1000_val);
6158
6159 /* set 10 speed advertisement */
6160 if (((phy->req_line_speed == SPEED_AUTO_NEG) &&
6161 (phy->speed_cap_mask &
6162 (PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL |
6163 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF)))) {
6164 an_10_100_val |= (1<<7);
6165 /* Enable autoneg and restart autoneg for legacy speeds */
6166 autoneg_val |= (1<<9 | 1<<12);
6167
6168 if (phy->req_duplex == DUPLEX_FULL)
6169 an_10_100_val |= (1<<8);
6170 DP(NETIF_MSG_LINK, "Advertising 100M\n");
6171 }
6172 /* set 10 speed advertisement */
6173 if (((phy->req_line_speed == SPEED_AUTO_NEG) &&
6174 (phy->speed_cap_mask &
6175 (PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL |
6176 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF)))) {
6177 an_10_100_val |= (1<<5);
6178 autoneg_val |= (1<<9 | 1<<12);
6179 if (phy->req_duplex == DUPLEX_FULL)
6180 an_10_100_val |= (1<<6);
6181 DP(NETIF_MSG_LINK, "Advertising 10M\n");
6182 }
6183
6184 /* Only 10/100 are allowed to work in FORCE mode */
6185 if (phy->req_line_speed == SPEED_100) {
6186 autoneg_val |= (1<<13);
6187 /* Enabled AUTO-MDIX when autoneg is disabled */
6188 bnx2x_cl45_write(bp, phy,
6189 MDIO_AN_DEVAD, MDIO_AN_REG_8481_AUX_CTRL,
6190 (1<<15 | 1<<9 | 7<<0));
6191 DP(NETIF_MSG_LINK, "Setting 100M force\n");
6192 }
6193 if (phy->req_line_speed == SPEED_10) {
6194 /* Enabled AUTO-MDIX when autoneg is disabled */
6195 bnx2x_cl45_write(bp, phy,
6196 MDIO_AN_DEVAD, MDIO_AN_REG_8481_AUX_CTRL,
6197 (1<<15 | 1<<9 | 7<<0));
6198 DP(NETIF_MSG_LINK, "Setting 10M force\n");
6199 }
6200
6201 bnx2x_cl45_write(bp, phy,
6202 MDIO_AN_DEVAD, MDIO_AN_REG_8481_LEGACY_AN_ADV,
6203 an_10_100_val);
6204
6205 if (phy->req_duplex == DUPLEX_FULL)
6206 autoneg_val |= (1<<8);
6207
6208 bnx2x_cl45_write(bp, phy,
6209 MDIO_AN_DEVAD,
6210 MDIO_AN_REG_8481_LEGACY_MII_CTRL, autoneg_val);
6211
6212 if (((phy->req_line_speed == SPEED_AUTO_NEG) &&
6213 (phy->speed_cap_mask &
6214 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) ||
6215 (phy->req_line_speed == SPEED_10000)) {
6216 DP(NETIF_MSG_LINK, "Advertising 10G\n");
6217 /* Restart autoneg for 10G*/
6218
6219 bnx2x_cl45_write(bp, phy,
6220 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL,
6221 0x3200);
6222 } else if (phy->req_line_speed != SPEED_10 &&
6223 phy->req_line_speed != SPEED_100) {
6224 bnx2x_cl45_write(bp, phy,
6225 MDIO_AN_DEVAD,
6226 MDIO_AN_REG_8481_10GBASE_T_AN_CTRL,
6227 1);
6228 }
6229 /* Save spirom version */
6230 bnx2x_save_848xx_spirom_version(phy, params);
6231
6232 return 0;
6233}
6234
6235static u8 bnx2x_8481_config_init(struct bnx2x_phy *phy,
6236 struct link_params *params,
6237 struct link_vars *vars)
6238{
6239 struct bnx2x *bp = params->bp;
6240 /* Restore normal power mode*/
6241 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006242 MISC_REGISTERS_GPIO_OUTPUT_HIGH, params->port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006243
6244 /* HW reset */
6245 bnx2x_ext_phy_hw_reset(bp, params->port);
Yaniv Rosner6d870c32011-01-31 04:22:20 +00006246 bnx2x_wait_reset_complete(bp, phy, params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006247
6248 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 1<<15);
6249 return bnx2x_848xx_cmn_config_init(phy, params, vars);
6250}
6251
6252static u8 bnx2x_848x3_config_init(struct bnx2x_phy *phy,
6253 struct link_params *params,
6254 struct link_vars *vars)
6255{
6256 struct bnx2x *bp = params->bp;
Yaniv Rosner6a71bbe2010-11-01 05:32:31 +00006257 u8 port, initialize = 1;
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00006258 u16 val, adj;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006259 u16 temp;
Yaniv Rosner1bef68e2011-01-31 04:22:46 +00006260 u32 actual_phy_selection, cms_enable;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006261 u8 rc = 0;
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006262
6263 /* This is just for MDIO_CTL_REG_84823_MEDIA register. */
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00006264 adj = 0;
6265 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
6266 adj = 3;
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006267
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006268 msleep(1);
Yaniv Rosner6a71bbe2010-11-01 05:32:31 +00006269 if (CHIP_IS_E2(bp))
6270 port = BP_PATH(bp);
6271 else
6272 port = params->port;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006273 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_3,
6274 MISC_REGISTERS_GPIO_OUTPUT_HIGH,
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006275 port);
Yaniv Rosner6d870c32011-01-31 04:22:20 +00006276 bnx2x_wait_reset_complete(bp, phy, params);
Yaniv Rosner9bffeac2010-11-01 05:32:27 +00006277 /* Wait for GPHY to come out of reset */
6278 msleep(50);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006279 /*
6280 * BCM84823 requires that XGXS links up first @ 10G for normal behavior
6281 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006282 temp = vars->line_speed;
6283 vars->line_speed = SPEED_10000;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006284 bnx2x_set_autoneg(&params->phy[INT_PHY], params, vars, 0);
6285 bnx2x_program_serdes(&params->phy[INT_PHY], params, vars);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006286 vars->line_speed = temp;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006287
6288 /* Set dual-media configuration according to configuration */
6289
6290 bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD,
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00006291 MDIO_CTL_REG_84823_MEDIA + adj, &val);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006292 val &= ~(MDIO_CTL_REG_84823_MEDIA_MAC_MASK |
6293 MDIO_CTL_REG_84823_MEDIA_LINE_MASK |
6294 MDIO_CTL_REG_84823_MEDIA_COPPER_CORE_DOWN |
6295 MDIO_CTL_REG_84823_MEDIA_PRIORITY_MASK |
6296 MDIO_CTL_REG_84823_MEDIA_FIBER_1G);
6297 val |= MDIO_CTL_REG_84823_CTRL_MAC_XFI |
6298 MDIO_CTL_REG_84823_MEDIA_LINE_XAUI_L;
6299
6300 actual_phy_selection = bnx2x_phy_selection(params);
6301
6302 switch (actual_phy_selection) {
6303 case PORT_HW_CFG_PHY_SELECTION_HARDWARE_DEFAULT:
6304 /* Do nothing. Essentialy this is like the priority copper */
6305 break;
6306 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY_PRIORITY:
6307 val |= MDIO_CTL_REG_84823_MEDIA_PRIORITY_COPPER;
6308 break;
6309 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY_PRIORITY:
6310 val |= MDIO_CTL_REG_84823_MEDIA_PRIORITY_FIBER;
6311 break;
6312 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY:
6313 /* Do nothing here. The first PHY won't be initialized at all */
6314 break;
6315 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY:
6316 val |= MDIO_CTL_REG_84823_MEDIA_COPPER_CORE_DOWN;
6317 initialize = 0;
6318 break;
6319 }
6320 if (params->phy[EXT_PHY2].req_line_speed == SPEED_1000)
6321 val |= MDIO_CTL_REG_84823_MEDIA_FIBER_1G;
6322
6323 bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00006324 MDIO_CTL_REG_84823_MEDIA + adj, val);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006325 DP(NETIF_MSG_LINK, "Multi_phy config = 0x%x, Media control = 0x%x\n",
6326 params->multi_phy_config, val);
6327
6328 if (initialize)
6329 rc = bnx2x_848xx_cmn_config_init(phy, params, vars);
6330 else
6331 bnx2x_save_848xx_spirom_version(phy, params);
Yaniv Rosner1bef68e2011-01-31 04:22:46 +00006332 cms_enable = REG_RD(bp, params->shmem_base +
6333 offsetof(struct shmem_region,
6334 dev_info.port_hw_config[params->port].default_cfg)) &
6335 PORT_HW_CFG_ENABLE_CMS_MASK;
6336
6337 bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD,
6338 MDIO_CTL_REG_84823_USER_CTRL_REG, &val);
6339 if (cms_enable)
6340 val |= MDIO_CTL_REG_84823_USER_CTRL_CMS;
6341 else
6342 val &= ~MDIO_CTL_REG_84823_USER_CTRL_CMS;
6343 bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
6344 MDIO_CTL_REG_84823_USER_CTRL_REG, val);
6345
6346
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006347 return rc;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006348}
6349
6350static u8 bnx2x_848xx_read_status(struct bnx2x_phy *phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006351 struct link_params *params,
6352 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006353{
6354 struct bnx2x *bp = params->bp;
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00006355 u16 val, val1, val2, adj;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006356 u8 link_up = 0;
6357
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00006358 /* Reg offset adjustment for 84833 */
6359 adj = 0;
6360 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
6361 adj = -1;
6362
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006363 /* Check 10G-BaseT link status */
6364 /* Check PMD signal ok */
6365 bnx2x_cl45_read(bp, phy,
6366 MDIO_AN_DEVAD, 0xFFFA, &val1);
6367 bnx2x_cl45_read(bp, phy,
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00006368 MDIO_PMA_DEVAD, MDIO_PMA_REG_8481_PMD_SIGNAL + adj,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006369 &val2);
6370 DP(NETIF_MSG_LINK, "BCM848xx: PMD_SIGNAL 1.a811 = 0x%x\n", val2);
6371
6372 /* Check link 10G */
6373 if (val2 & (1<<11)) {
6374 vars->line_speed = SPEED_10000;
Yaniv Rosner791f18c2011-01-18 04:33:42 +00006375 vars->duplex = DUPLEX_FULL;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006376 link_up = 1;
6377 bnx2x_ext_phy_10G_an_resolve(bp, phy, vars);
6378 } else { /* Check Legacy speed link */
6379 u16 legacy_status, legacy_speed;
6380
6381 /* Enable expansion register 0x42 (Operation mode status) */
6382 bnx2x_cl45_write(bp, phy,
6383 MDIO_AN_DEVAD,
6384 MDIO_AN_REG_8481_EXPANSION_REG_ACCESS, 0xf42);
6385
6386 /* Get legacy speed operation status */
6387 bnx2x_cl45_read(bp, phy,
6388 MDIO_AN_DEVAD,
6389 MDIO_AN_REG_8481_EXPANSION_REG_RD_RW,
6390 &legacy_status);
6391
6392 DP(NETIF_MSG_LINK, "Legacy speed status"
6393 " = 0x%x\n", legacy_status);
6394 link_up = ((legacy_status & (1<<11)) == (1<<11));
6395 if (link_up) {
6396 legacy_speed = (legacy_status & (3<<9));
6397 if (legacy_speed == (0<<9))
6398 vars->line_speed = SPEED_10;
6399 else if (legacy_speed == (1<<9))
6400 vars->line_speed = SPEED_100;
6401 else if (legacy_speed == (2<<9))
6402 vars->line_speed = SPEED_1000;
6403 else /* Should not happen */
6404 vars->line_speed = 0;
6405
6406 if (legacy_status & (1<<8))
6407 vars->duplex = DUPLEX_FULL;
6408 else
6409 vars->duplex = DUPLEX_HALF;
6410
6411 DP(NETIF_MSG_LINK, "Link is up in %dMbps,"
6412 " is_duplex_full= %d\n", vars->line_speed,
6413 (vars->duplex == DUPLEX_FULL));
6414 /* Check legacy speed AN resolution */
6415 bnx2x_cl45_read(bp, phy,
6416 MDIO_AN_DEVAD,
6417 MDIO_AN_REG_8481_LEGACY_MII_STATUS,
6418 &val);
6419 if (val & (1<<5))
6420 vars->link_status |=
6421 LINK_STATUS_AUTO_NEGOTIATE_COMPLETE;
6422 bnx2x_cl45_read(bp, phy,
6423 MDIO_AN_DEVAD,
6424 MDIO_AN_REG_8481_LEGACY_AN_EXPANSION,
6425 &val);
6426 if ((val & (1<<0)) == 0)
6427 vars->link_status |=
6428 LINK_STATUS_PARALLEL_DETECTION_USED;
6429 }
6430 }
6431 if (link_up) {
6432 DP(NETIF_MSG_LINK, "BCM84823: link speed is %d\n",
6433 vars->line_speed);
6434 bnx2x_ext_phy_resolve_fc(phy, params, vars);
6435 }
6436
6437 return link_up;
6438}
6439
6440static u8 bnx2x_848xx_format_ver(u32 raw_ver, u8 *str, u16 *len)
6441{
6442 u8 status = 0;
6443 u32 spirom_ver;
6444 spirom_ver = ((raw_ver & 0xF80) >> 7) << 16 | (raw_ver & 0x7F);
6445 status = bnx2x_format_ver(spirom_ver, str, len);
6446 return status;
6447}
6448
6449static void bnx2x_8481_hw_reset(struct bnx2x_phy *phy,
6450 struct link_params *params)
6451{
6452 bnx2x_set_gpio(params->bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006453 MISC_REGISTERS_GPIO_OUTPUT_LOW, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006454 bnx2x_set_gpio(params->bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006455 MISC_REGISTERS_GPIO_OUTPUT_LOW, 1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006456}
6457
6458static void bnx2x_8481_link_reset(struct bnx2x_phy *phy,
6459 struct link_params *params)
6460{
6461 bnx2x_cl45_write(params->bp, phy,
6462 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x0000);
6463 bnx2x_cl45_write(params->bp, phy,
6464 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 1);
6465}
6466
6467static void bnx2x_848x3_link_reset(struct bnx2x_phy *phy,
6468 struct link_params *params)
6469{
6470 struct bnx2x *bp = params->bp;
Yaniv Rosner6a71bbe2010-11-01 05:32:31 +00006471 u8 port;
6472 if (CHIP_IS_E2(bp))
6473 port = BP_PATH(bp);
6474 else
6475 port = params->port;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006476 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_3,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006477 MISC_REGISTERS_GPIO_OUTPUT_LOW,
6478 port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006479}
6480
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006481static void bnx2x_848xx_set_link_led(struct bnx2x_phy *phy,
6482 struct link_params *params, u8 mode)
6483{
6484 struct bnx2x *bp = params->bp;
6485 u16 val;
6486
6487 switch (mode) {
6488 case LED_MODE_OFF:
6489
6490 DP(NETIF_MSG_LINK, "Port 0x%x: LED MODE OFF\n", params->port);
6491
6492 if ((params->hw_led_mode << SHARED_HW_CFG_LED_MODE_SHIFT) ==
6493 SHARED_HW_CFG_LED_EXTPHY1) {
6494
6495 /* Set LED masks */
6496 bnx2x_cl45_write(bp, phy,
6497 MDIO_PMA_DEVAD,
6498 MDIO_PMA_REG_8481_LED1_MASK,
6499 0x0);
6500
6501 bnx2x_cl45_write(bp, phy,
6502 MDIO_PMA_DEVAD,
6503 MDIO_PMA_REG_8481_LED2_MASK,
6504 0x0);
6505
6506 bnx2x_cl45_write(bp, phy,
6507 MDIO_PMA_DEVAD,
6508 MDIO_PMA_REG_8481_LED3_MASK,
6509 0x0);
6510
6511 bnx2x_cl45_write(bp, phy,
6512 MDIO_PMA_DEVAD,
6513 MDIO_PMA_REG_8481_LED5_MASK,
6514 0x0);
6515
6516 } else {
6517 bnx2x_cl45_write(bp, phy,
6518 MDIO_PMA_DEVAD,
6519 MDIO_PMA_REG_8481_LED1_MASK,
6520 0x0);
6521 }
6522 break;
6523 case LED_MODE_FRONT_PANEL_OFF:
6524
6525 DP(NETIF_MSG_LINK, "Port 0x%x: LED MODE FRONT PANEL OFF\n",
6526 params->port);
6527
6528 if ((params->hw_led_mode << SHARED_HW_CFG_LED_MODE_SHIFT) ==
6529 SHARED_HW_CFG_LED_EXTPHY1) {
6530
6531 /* Set LED masks */
6532 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006533 MDIO_PMA_DEVAD,
6534 MDIO_PMA_REG_8481_LED1_MASK,
6535 0x0);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006536
6537 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006538 MDIO_PMA_DEVAD,
6539 MDIO_PMA_REG_8481_LED2_MASK,
6540 0x0);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006541
6542 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006543 MDIO_PMA_DEVAD,
6544 MDIO_PMA_REG_8481_LED3_MASK,
6545 0x0);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006546
6547 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006548 MDIO_PMA_DEVAD,
6549 MDIO_PMA_REG_8481_LED5_MASK,
6550 0x20);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006551
6552 } else {
6553 bnx2x_cl45_write(bp, phy,
6554 MDIO_PMA_DEVAD,
6555 MDIO_PMA_REG_8481_LED1_MASK,
6556 0x0);
6557 }
6558 break;
6559 case LED_MODE_ON:
6560
6561 DP(NETIF_MSG_LINK, "Port 0x%x: LED MODE ON\n", params->port);
6562
6563 if ((params->hw_led_mode << SHARED_HW_CFG_LED_MODE_SHIFT) ==
6564 SHARED_HW_CFG_LED_EXTPHY1) {
6565 /* Set control reg */
6566 bnx2x_cl45_read(bp, phy,
6567 MDIO_PMA_DEVAD,
6568 MDIO_PMA_REG_8481_LINK_SIGNAL,
6569 &val);
6570 val &= 0x8000;
6571 val |= 0x2492;
6572
6573 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006574 MDIO_PMA_DEVAD,
6575 MDIO_PMA_REG_8481_LINK_SIGNAL,
6576 val);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006577
6578 /* Set LED masks */
6579 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006580 MDIO_PMA_DEVAD,
6581 MDIO_PMA_REG_8481_LED1_MASK,
6582 0x0);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006583
6584 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006585 MDIO_PMA_DEVAD,
6586 MDIO_PMA_REG_8481_LED2_MASK,
6587 0x20);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006588
6589 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006590 MDIO_PMA_DEVAD,
6591 MDIO_PMA_REG_8481_LED3_MASK,
6592 0x20);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006593
6594 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006595 MDIO_PMA_DEVAD,
6596 MDIO_PMA_REG_8481_LED5_MASK,
6597 0x0);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006598 } else {
6599 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006600 MDIO_PMA_DEVAD,
6601 MDIO_PMA_REG_8481_LED1_MASK,
6602 0x20);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006603 }
6604 break;
6605
6606 case LED_MODE_OPER:
6607
6608 DP(NETIF_MSG_LINK, "Port 0x%x: LED MODE OPER\n", params->port);
6609
6610 if ((params->hw_led_mode << SHARED_HW_CFG_LED_MODE_SHIFT) ==
6611 SHARED_HW_CFG_LED_EXTPHY1) {
6612
6613 /* Set control reg */
6614 bnx2x_cl45_read(bp, phy,
6615 MDIO_PMA_DEVAD,
6616 MDIO_PMA_REG_8481_LINK_SIGNAL,
6617 &val);
6618
6619 if (!((val &
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006620 MDIO_PMA_REG_8481_LINK_SIGNAL_LED4_ENABLE_MASK)
6621 >> MDIO_PMA_REG_8481_LINK_SIGNAL_LED4_ENABLE_SHIFT)) {
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006622 DP(NETIF_MSG_LINK, "Setting LINK_SIGNAL\n");
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006623 bnx2x_cl45_write(bp, phy,
6624 MDIO_PMA_DEVAD,
6625 MDIO_PMA_REG_8481_LINK_SIGNAL,
6626 0xa492);
6627 }
6628
6629 /* Set LED masks */
6630 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006631 MDIO_PMA_DEVAD,
6632 MDIO_PMA_REG_8481_LED1_MASK,
6633 0x10);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006634
6635 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006636 MDIO_PMA_DEVAD,
6637 MDIO_PMA_REG_8481_LED2_MASK,
6638 0x80);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006639
6640 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006641 MDIO_PMA_DEVAD,
6642 MDIO_PMA_REG_8481_LED3_MASK,
6643 0x98);
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_LED5_MASK,
6648 0x40);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006649
6650 } else {
6651 bnx2x_cl45_write(bp, phy,
6652 MDIO_PMA_DEVAD,
6653 MDIO_PMA_REG_8481_LED1_MASK,
6654 0x80);
Yaniv Rosner53eda062011-01-30 04:14:55 +00006655
6656 /* Tell LED3 to blink on source */
6657 bnx2x_cl45_read(bp, phy,
6658 MDIO_PMA_DEVAD,
6659 MDIO_PMA_REG_8481_LINK_SIGNAL,
6660 &val);
6661 val &= ~(7<<6);
6662 val |= (1<<6); /* A83B[8:6]= 1 */
6663 bnx2x_cl45_write(bp, phy,
6664 MDIO_PMA_DEVAD,
6665 MDIO_PMA_REG_8481_LINK_SIGNAL,
6666 val);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006667 }
6668 break;
6669 }
6670}
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006671/******************************************************************/
6672/* SFX7101 PHY SECTION */
6673/******************************************************************/
6674static void bnx2x_7101_config_loopback(struct bnx2x_phy *phy,
6675 struct link_params *params)
6676{
6677 struct bnx2x *bp = params->bp;
6678 /* SFX7101_XGXS_TEST1 */
6679 bnx2x_cl45_write(bp, phy,
6680 MDIO_XS_DEVAD, MDIO_XS_SFX7101_XGXS_TEST1, 0x100);
6681}
6682
6683static u8 bnx2x_7101_config_init(struct bnx2x_phy *phy,
6684 struct link_params *params,
6685 struct link_vars *vars)
6686{
6687 u16 fw_ver1, fw_ver2, val;
6688 struct bnx2x *bp = params->bp;
6689 DP(NETIF_MSG_LINK, "Setting the SFX7101 LASI indication\n");
6690
6691 /* Restore normal power mode*/
6692 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006693 MISC_REGISTERS_GPIO_OUTPUT_HIGH, params->port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006694 /* HW reset */
6695 bnx2x_ext_phy_hw_reset(bp, params->port);
Yaniv Rosner6d870c32011-01-31 04:22:20 +00006696 bnx2x_wait_reset_complete(bp, phy, params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006697
6698 bnx2x_cl45_write(bp, phy,
6699 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_CTRL, 0x1);
6700 DP(NETIF_MSG_LINK, "Setting the SFX7101 LED to blink on traffic\n");
6701 bnx2x_cl45_write(bp, phy,
6702 MDIO_PMA_DEVAD, MDIO_PMA_REG_7107_LED_CNTL, (1<<3));
6703
6704 bnx2x_ext_phy_set_pause(params, phy, vars);
6705 /* Restart autoneg */
6706 bnx2x_cl45_read(bp, phy,
6707 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, &val);
6708 val |= 0x200;
6709 bnx2x_cl45_write(bp, phy,
6710 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, val);
6711
6712 /* Save spirom version */
6713 bnx2x_cl45_read(bp, phy,
6714 MDIO_PMA_DEVAD, MDIO_PMA_REG_7101_VER1, &fw_ver1);
6715
6716 bnx2x_cl45_read(bp, phy,
6717 MDIO_PMA_DEVAD, MDIO_PMA_REG_7101_VER2, &fw_ver2);
6718 bnx2x_save_spirom_version(bp, params->port,
6719 (u32)(fw_ver1<<16 | fw_ver2), phy->ver_addr);
6720 return 0;
6721}
6722
6723static u8 bnx2x_7101_read_status(struct bnx2x_phy *phy,
6724 struct link_params *params,
6725 struct link_vars *vars)
6726{
6727 struct bnx2x *bp = params->bp;
6728 u8 link_up;
6729 u16 val1, val2;
6730 bnx2x_cl45_read(bp, phy,
6731 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_STATUS, &val2);
6732 bnx2x_cl45_read(bp, phy,
6733 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_STATUS, &val1);
6734 DP(NETIF_MSG_LINK, "10G-base-T LASI status 0x%x->0x%x\n",
6735 val2, val1);
6736 bnx2x_cl45_read(bp, phy,
6737 MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val2);
6738 bnx2x_cl45_read(bp, phy,
6739 MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val1);
6740 DP(NETIF_MSG_LINK, "10G-base-T PMA status 0x%x->0x%x\n",
6741 val2, val1);
6742 link_up = ((val1 & 4) == 4);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006743 /* if link is up print the AN outcome of the SFX7101 PHY */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006744 if (link_up) {
6745 bnx2x_cl45_read(bp, phy,
6746 MDIO_AN_DEVAD, MDIO_AN_REG_MASTER_STATUS,
6747 &val2);
6748 vars->line_speed = SPEED_10000;
Yaniv Rosner791f18c2011-01-18 04:33:42 +00006749 vars->duplex = DUPLEX_FULL;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006750 DP(NETIF_MSG_LINK, "SFX7101 AN status 0x%x->Master=%x\n",
6751 val2, (val2 & (1<<14)));
6752 bnx2x_ext_phy_10G_an_resolve(bp, phy, vars);
6753 bnx2x_ext_phy_resolve_fc(phy, params, vars);
6754 }
6755 return link_up;
6756}
6757
6758
6759static u8 bnx2x_7101_format_ver(u32 spirom_ver, u8 *str, u16 *len)
6760{
6761 if (*len < 5)
6762 return -EINVAL;
6763 str[0] = (spirom_ver & 0xFF);
6764 str[1] = (spirom_ver & 0xFF00) >> 8;
6765 str[2] = (spirom_ver & 0xFF0000) >> 16;
6766 str[3] = (spirom_ver & 0xFF000000) >> 24;
6767 str[4] = '\0';
6768 *len -= 5;
6769 return 0;
6770}
6771
6772void bnx2x_sfx7101_sp_sw_reset(struct bnx2x *bp, struct bnx2x_phy *phy)
6773{
6774 u16 val, cnt;
6775
6776 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006777 MDIO_PMA_DEVAD,
6778 MDIO_PMA_REG_7101_RESET, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006779
6780 for (cnt = 0; cnt < 10; cnt++) {
6781 msleep(50);
6782 /* Writes a self-clearing reset */
6783 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006784 MDIO_PMA_DEVAD,
6785 MDIO_PMA_REG_7101_RESET,
6786 (val | (1<<15)));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006787 /* Wait for clear */
6788 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006789 MDIO_PMA_DEVAD,
6790 MDIO_PMA_REG_7101_RESET, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006791
6792 if ((val & (1<<15)) == 0)
6793 break;
6794 }
6795}
6796
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006797static void bnx2x_7101_hw_reset(struct bnx2x_phy *phy,
6798 struct link_params *params) {
6799 /* Low power mode is controlled by GPIO 2 */
6800 bnx2x_set_gpio(params->bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006801 MISC_REGISTERS_GPIO_OUTPUT_LOW, params->port);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006802 /* The PHY reset is controlled by GPIO 1 */
6803 bnx2x_set_gpio(params->bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006804 MISC_REGISTERS_GPIO_OUTPUT_LOW, params->port);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006805}
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006806
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006807static void bnx2x_7101_set_link_led(struct bnx2x_phy *phy,
6808 struct link_params *params, u8 mode)
6809{
6810 u16 val = 0;
6811 struct bnx2x *bp = params->bp;
6812 switch (mode) {
6813 case LED_MODE_FRONT_PANEL_OFF:
6814 case LED_MODE_OFF:
6815 val = 2;
6816 break;
6817 case LED_MODE_ON:
6818 val = 1;
6819 break;
6820 case LED_MODE_OPER:
6821 val = 0;
6822 break;
6823 }
6824 bnx2x_cl45_write(bp, phy,
6825 MDIO_PMA_DEVAD,
6826 MDIO_PMA_REG_7107_LINK_LED_CNTL,
6827 val);
6828}
6829
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006830/******************************************************************/
6831/* STATIC PHY DECLARATION */
6832/******************************************************************/
6833
6834static struct bnx2x_phy phy_null = {
6835 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN,
6836 .addr = 0,
6837 .flags = FLAGS_INIT_XGXS_FIRST,
6838 .def_md_devad = 0,
6839 .reserved = 0,
6840 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
6841 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
6842 .mdio_ctrl = 0,
6843 .supported = 0,
6844 .media_type = ETH_PHY_NOT_PRESENT,
6845 .ver_addr = 0,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006846 .req_flow_ctrl = 0,
6847 .req_line_speed = 0,
6848 .speed_cap_mask = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006849 .req_duplex = 0,
6850 .rsrv = 0,
6851 .config_init = (config_init_t)NULL,
6852 .read_status = (read_status_t)NULL,
6853 .link_reset = (link_reset_t)NULL,
6854 .config_loopback = (config_loopback_t)NULL,
6855 .format_fw_ver = (format_fw_ver_t)NULL,
6856 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006857 .set_link_led = (set_link_led_t)NULL,
6858 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006859};
6860
6861static struct bnx2x_phy phy_serdes = {
6862 .type = PORT_HW_CFG_SERDES_EXT_PHY_TYPE_DIRECT,
6863 .addr = 0xff,
6864 .flags = 0,
6865 .def_md_devad = 0,
6866 .reserved = 0,
6867 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
6868 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
6869 .mdio_ctrl = 0,
6870 .supported = (SUPPORTED_10baseT_Half |
6871 SUPPORTED_10baseT_Full |
6872 SUPPORTED_100baseT_Half |
6873 SUPPORTED_100baseT_Full |
6874 SUPPORTED_1000baseT_Full |
6875 SUPPORTED_2500baseX_Full |
6876 SUPPORTED_TP |
6877 SUPPORTED_Autoneg |
6878 SUPPORTED_Pause |
6879 SUPPORTED_Asym_Pause),
6880 .media_type = ETH_PHY_UNSPECIFIED,
6881 .ver_addr = 0,
6882 .req_flow_ctrl = 0,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006883 .req_line_speed = 0,
6884 .speed_cap_mask = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006885 .req_duplex = 0,
6886 .rsrv = 0,
6887 .config_init = (config_init_t)bnx2x_init_serdes,
6888 .read_status = (read_status_t)bnx2x_link_settings_status,
6889 .link_reset = (link_reset_t)bnx2x_int_link_reset,
6890 .config_loopback = (config_loopback_t)NULL,
6891 .format_fw_ver = (format_fw_ver_t)NULL,
6892 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006893 .set_link_led = (set_link_led_t)NULL,
6894 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006895};
6896
6897static struct bnx2x_phy phy_xgxs = {
6898 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT,
6899 .addr = 0xff,
6900 .flags = 0,
6901 .def_md_devad = 0,
6902 .reserved = 0,
6903 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
6904 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
6905 .mdio_ctrl = 0,
6906 .supported = (SUPPORTED_10baseT_Half |
6907 SUPPORTED_10baseT_Full |
6908 SUPPORTED_100baseT_Half |
6909 SUPPORTED_100baseT_Full |
6910 SUPPORTED_1000baseT_Full |
6911 SUPPORTED_2500baseX_Full |
6912 SUPPORTED_10000baseT_Full |
6913 SUPPORTED_FIBRE |
6914 SUPPORTED_Autoneg |
6915 SUPPORTED_Pause |
6916 SUPPORTED_Asym_Pause),
6917 .media_type = ETH_PHY_UNSPECIFIED,
6918 .ver_addr = 0,
6919 .req_flow_ctrl = 0,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006920 .req_line_speed = 0,
6921 .speed_cap_mask = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006922 .req_duplex = 0,
6923 .rsrv = 0,
6924 .config_init = (config_init_t)bnx2x_init_xgxs,
6925 .read_status = (read_status_t)bnx2x_link_settings_status,
6926 .link_reset = (link_reset_t)bnx2x_int_link_reset,
6927 .config_loopback = (config_loopback_t)bnx2x_set_xgxs_loopback,
6928 .format_fw_ver = (format_fw_ver_t)NULL,
6929 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006930 .set_link_led = (set_link_led_t)NULL,
6931 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006932};
6933
6934static struct bnx2x_phy phy_7101 = {
6935 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101,
6936 .addr = 0xff,
6937 .flags = FLAGS_FAN_FAILURE_DET_REQ,
6938 .def_md_devad = 0,
6939 .reserved = 0,
6940 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
6941 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
6942 .mdio_ctrl = 0,
6943 .supported = (SUPPORTED_10000baseT_Full |
6944 SUPPORTED_TP |
6945 SUPPORTED_Autoneg |
6946 SUPPORTED_Pause |
6947 SUPPORTED_Asym_Pause),
6948 .media_type = ETH_PHY_BASE_T,
6949 .ver_addr = 0,
6950 .req_flow_ctrl = 0,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006951 .req_line_speed = 0,
6952 .speed_cap_mask = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006953 .req_duplex = 0,
6954 .rsrv = 0,
6955 .config_init = (config_init_t)bnx2x_7101_config_init,
6956 .read_status = (read_status_t)bnx2x_7101_read_status,
6957 .link_reset = (link_reset_t)bnx2x_common_ext_link_reset,
6958 .config_loopback = (config_loopback_t)bnx2x_7101_config_loopback,
6959 .format_fw_ver = (format_fw_ver_t)bnx2x_7101_format_ver,
6960 .hw_reset = (hw_reset_t)bnx2x_7101_hw_reset,
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006961 .set_link_led = (set_link_led_t)bnx2x_7101_set_link_led,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006962 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006963};
6964static struct bnx2x_phy phy_8073 = {
6965 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073,
6966 .addr = 0xff,
6967 .flags = FLAGS_HW_LOCK_REQUIRED,
6968 .def_md_devad = 0,
6969 .reserved = 0,
6970 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
6971 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
6972 .mdio_ctrl = 0,
6973 .supported = (SUPPORTED_10000baseT_Full |
6974 SUPPORTED_2500baseX_Full |
6975 SUPPORTED_1000baseT_Full |
6976 SUPPORTED_FIBRE |
6977 SUPPORTED_Autoneg |
6978 SUPPORTED_Pause |
6979 SUPPORTED_Asym_Pause),
6980 .media_type = ETH_PHY_UNSPECIFIED,
6981 .ver_addr = 0,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006982 .req_flow_ctrl = 0,
6983 .req_line_speed = 0,
6984 .speed_cap_mask = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006985 .req_duplex = 0,
6986 .rsrv = 0,
Yaniv Rosner62b29a52010-09-07 11:40:58 +00006987 .config_init = (config_init_t)bnx2x_8073_config_init,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006988 .read_status = (read_status_t)bnx2x_8073_read_status,
6989 .link_reset = (link_reset_t)bnx2x_8073_link_reset,
6990 .config_loopback = (config_loopback_t)NULL,
6991 .format_fw_ver = (format_fw_ver_t)bnx2x_format_ver,
6992 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006993 .set_link_led = (set_link_led_t)NULL,
6994 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006995};
6996static struct bnx2x_phy phy_8705 = {
6997 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705,
6998 .addr = 0xff,
6999 .flags = FLAGS_INIT_XGXS_FIRST,
7000 .def_md_devad = 0,
7001 .reserved = 0,
7002 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
7003 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
7004 .mdio_ctrl = 0,
7005 .supported = (SUPPORTED_10000baseT_Full |
7006 SUPPORTED_FIBRE |
7007 SUPPORTED_Pause |
7008 SUPPORTED_Asym_Pause),
7009 .media_type = ETH_PHY_XFP_FIBER,
7010 .ver_addr = 0,
7011 .req_flow_ctrl = 0,
7012 .req_line_speed = 0,
7013 .speed_cap_mask = 0,
7014 .req_duplex = 0,
7015 .rsrv = 0,
7016 .config_init = (config_init_t)bnx2x_8705_config_init,
7017 .read_status = (read_status_t)bnx2x_8705_read_status,
7018 .link_reset = (link_reset_t)bnx2x_common_ext_link_reset,
7019 .config_loopback = (config_loopback_t)NULL,
7020 .format_fw_ver = (format_fw_ver_t)bnx2x_null_format_ver,
7021 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007022 .set_link_led = (set_link_led_t)NULL,
7023 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007024};
7025static struct bnx2x_phy phy_8706 = {
7026 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706,
7027 .addr = 0xff,
7028 .flags = FLAGS_INIT_XGXS_FIRST,
7029 .def_md_devad = 0,
7030 .reserved = 0,
7031 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
7032 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
7033 .mdio_ctrl = 0,
7034 .supported = (SUPPORTED_10000baseT_Full |
7035 SUPPORTED_1000baseT_Full |
7036 SUPPORTED_FIBRE |
7037 SUPPORTED_Pause |
7038 SUPPORTED_Asym_Pause),
7039 .media_type = ETH_PHY_SFP_FIBER,
7040 .ver_addr = 0,
7041 .req_flow_ctrl = 0,
7042 .req_line_speed = 0,
7043 .speed_cap_mask = 0,
7044 .req_duplex = 0,
7045 .rsrv = 0,
7046 .config_init = (config_init_t)bnx2x_8706_config_init,
7047 .read_status = (read_status_t)bnx2x_8706_read_status,
7048 .link_reset = (link_reset_t)bnx2x_common_ext_link_reset,
7049 .config_loopback = (config_loopback_t)NULL,
7050 .format_fw_ver = (format_fw_ver_t)bnx2x_format_ver,
7051 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007052 .set_link_led = (set_link_led_t)NULL,
7053 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007054};
7055
7056static struct bnx2x_phy phy_8726 = {
7057 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726,
7058 .addr = 0xff,
7059 .flags = (FLAGS_HW_LOCK_REQUIRED |
7060 FLAGS_INIT_XGXS_FIRST),
7061 .def_md_devad = 0,
7062 .reserved = 0,
7063 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
7064 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
7065 .mdio_ctrl = 0,
7066 .supported = (SUPPORTED_10000baseT_Full |
7067 SUPPORTED_1000baseT_Full |
7068 SUPPORTED_Autoneg |
7069 SUPPORTED_FIBRE |
7070 SUPPORTED_Pause |
7071 SUPPORTED_Asym_Pause),
7072 .media_type = ETH_PHY_SFP_FIBER,
7073 .ver_addr = 0,
7074 .req_flow_ctrl = 0,
7075 .req_line_speed = 0,
7076 .speed_cap_mask = 0,
7077 .req_duplex = 0,
7078 .rsrv = 0,
7079 .config_init = (config_init_t)bnx2x_8726_config_init,
7080 .read_status = (read_status_t)bnx2x_8726_read_status,
7081 .link_reset = (link_reset_t)bnx2x_8726_link_reset,
7082 .config_loopback = (config_loopback_t)bnx2x_8726_config_loopback,
7083 .format_fw_ver = (format_fw_ver_t)bnx2x_format_ver,
7084 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007085 .set_link_led = (set_link_led_t)NULL,
7086 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007087};
7088
7089static struct bnx2x_phy phy_8727 = {
7090 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727,
7091 .addr = 0xff,
7092 .flags = FLAGS_FAN_FAILURE_DET_REQ,
7093 .def_md_devad = 0,
7094 .reserved = 0,
7095 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
7096 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
7097 .mdio_ctrl = 0,
7098 .supported = (SUPPORTED_10000baseT_Full |
7099 SUPPORTED_1000baseT_Full |
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007100 SUPPORTED_FIBRE |
7101 SUPPORTED_Pause |
7102 SUPPORTED_Asym_Pause),
7103 .media_type = ETH_PHY_SFP_FIBER,
7104 .ver_addr = 0,
7105 .req_flow_ctrl = 0,
7106 .req_line_speed = 0,
7107 .speed_cap_mask = 0,
7108 .req_duplex = 0,
7109 .rsrv = 0,
7110 .config_init = (config_init_t)bnx2x_8727_config_init,
7111 .read_status = (read_status_t)bnx2x_8727_read_status,
7112 .link_reset = (link_reset_t)bnx2x_8727_link_reset,
7113 .config_loopback = (config_loopback_t)NULL,
7114 .format_fw_ver = (format_fw_ver_t)bnx2x_format_ver,
7115 .hw_reset = (hw_reset_t)bnx2x_8727_hw_reset,
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00007116 .set_link_led = (set_link_led_t)bnx2x_8727_set_link_led,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007117 .phy_specific_func = (phy_specific_func_t)bnx2x_8727_specific_func
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007118};
7119static struct bnx2x_phy phy_8481 = {
7120 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8481,
7121 .addr = 0xff,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007122 .flags = FLAGS_FAN_FAILURE_DET_REQ |
7123 FLAGS_REARM_LATCH_SIGNAL,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007124 .def_md_devad = 0,
7125 .reserved = 0,
7126 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
7127 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
7128 .mdio_ctrl = 0,
7129 .supported = (SUPPORTED_10baseT_Half |
7130 SUPPORTED_10baseT_Full |
7131 SUPPORTED_100baseT_Half |
7132 SUPPORTED_100baseT_Full |
7133 SUPPORTED_1000baseT_Full |
7134 SUPPORTED_10000baseT_Full |
7135 SUPPORTED_TP |
7136 SUPPORTED_Autoneg |
7137 SUPPORTED_Pause |
7138 SUPPORTED_Asym_Pause),
7139 .media_type = ETH_PHY_BASE_T,
7140 .ver_addr = 0,
7141 .req_flow_ctrl = 0,
7142 .req_line_speed = 0,
7143 .speed_cap_mask = 0,
7144 .req_duplex = 0,
7145 .rsrv = 0,
7146 .config_init = (config_init_t)bnx2x_8481_config_init,
7147 .read_status = (read_status_t)bnx2x_848xx_read_status,
7148 .link_reset = (link_reset_t)bnx2x_8481_link_reset,
7149 .config_loopback = (config_loopback_t)NULL,
7150 .format_fw_ver = (format_fw_ver_t)bnx2x_848xx_format_ver,
7151 .hw_reset = (hw_reset_t)bnx2x_8481_hw_reset,
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00007152 .set_link_led = (set_link_led_t)bnx2x_848xx_set_link_led,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007153 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007154};
7155
7156static struct bnx2x_phy phy_84823 = {
7157 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84823,
7158 .addr = 0xff,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007159 .flags = FLAGS_FAN_FAILURE_DET_REQ |
7160 FLAGS_REARM_LATCH_SIGNAL,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007161 .def_md_devad = 0,
7162 .reserved = 0,
7163 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
7164 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
7165 .mdio_ctrl = 0,
7166 .supported = (SUPPORTED_10baseT_Half |
7167 SUPPORTED_10baseT_Full |
7168 SUPPORTED_100baseT_Half |
7169 SUPPORTED_100baseT_Full |
7170 SUPPORTED_1000baseT_Full |
7171 SUPPORTED_10000baseT_Full |
7172 SUPPORTED_TP |
7173 SUPPORTED_Autoneg |
7174 SUPPORTED_Pause |
7175 SUPPORTED_Asym_Pause),
7176 .media_type = ETH_PHY_BASE_T,
7177 .ver_addr = 0,
7178 .req_flow_ctrl = 0,
7179 .req_line_speed = 0,
7180 .speed_cap_mask = 0,
7181 .req_duplex = 0,
7182 .rsrv = 0,
7183 .config_init = (config_init_t)bnx2x_848x3_config_init,
7184 .read_status = (read_status_t)bnx2x_848xx_read_status,
7185 .link_reset = (link_reset_t)bnx2x_848x3_link_reset,
7186 .config_loopback = (config_loopback_t)NULL,
7187 .format_fw_ver = (format_fw_ver_t)bnx2x_848xx_format_ver,
7188 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00007189 .set_link_led = (set_link_led_t)bnx2x_848xx_set_link_led,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007190 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007191};
7192
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00007193static struct bnx2x_phy phy_84833 = {
7194 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833,
7195 .addr = 0xff,
7196 .flags = FLAGS_FAN_FAILURE_DET_REQ |
7197 FLAGS_REARM_LATCH_SIGNAL,
7198 .def_md_devad = 0,
7199 .reserved = 0,
7200 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
7201 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
7202 .mdio_ctrl = 0,
7203 .supported = (SUPPORTED_10baseT_Half |
7204 SUPPORTED_10baseT_Full |
7205 SUPPORTED_100baseT_Half |
7206 SUPPORTED_100baseT_Full |
7207 SUPPORTED_1000baseT_Full |
7208 SUPPORTED_10000baseT_Full |
7209 SUPPORTED_TP |
7210 SUPPORTED_Autoneg |
7211 SUPPORTED_Pause |
7212 SUPPORTED_Asym_Pause),
7213 .media_type = ETH_PHY_BASE_T,
7214 .ver_addr = 0,
7215 .req_flow_ctrl = 0,
7216 .req_line_speed = 0,
7217 .speed_cap_mask = 0,
7218 .req_duplex = 0,
7219 .rsrv = 0,
7220 .config_init = (config_init_t)bnx2x_848x3_config_init,
7221 .read_status = (read_status_t)bnx2x_848xx_read_status,
7222 .link_reset = (link_reset_t)bnx2x_848x3_link_reset,
7223 .config_loopback = (config_loopback_t)NULL,
7224 .format_fw_ver = (format_fw_ver_t)bnx2x_848xx_format_ver,
7225 .hw_reset = (hw_reset_t)NULL,
7226 .set_link_led = (set_link_led_t)bnx2x_848xx_set_link_led,
7227 .phy_specific_func = (phy_specific_func_t)NULL
7228};
7229
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007230/*****************************************************************/
7231/* */
7232/* Populate the phy according. Main function: bnx2x_populate_phy */
7233/* */
7234/*****************************************************************/
7235
7236static void bnx2x_populate_preemphasis(struct bnx2x *bp, u32 shmem_base,
7237 struct bnx2x_phy *phy, u8 port,
7238 u8 phy_index)
7239{
7240 /* Get the 4 lanes xgxs config rx and tx */
7241 u32 rx = 0, tx = 0, i;
7242 for (i = 0; i < 2; i++) {
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007243 /*
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007244 * INT_PHY and EXT_PHY1 share the same value location in the
7245 * shmem. When num_phys is greater than 1, than this value
7246 * applies only to EXT_PHY1
7247 */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007248 if (phy_index == INT_PHY || phy_index == EXT_PHY1) {
7249 rx = REG_RD(bp, shmem_base +
7250 offsetof(struct shmem_region,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007251 dev_info.port_hw_config[port].xgxs_config_rx[i<<1]));
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007252
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007253 tx = REG_RD(bp, shmem_base +
7254 offsetof(struct shmem_region,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007255 dev_info.port_hw_config[port].xgxs_config_tx[i<<1]));
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007256 } else {
7257 rx = REG_RD(bp, shmem_base +
7258 offsetof(struct shmem_region,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007259 dev_info.port_hw_config[port].xgxs_config2_rx[i<<1]));
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007260
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007261 tx = REG_RD(bp, shmem_base +
7262 offsetof(struct shmem_region,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007263 dev_info.port_hw_config[port].xgxs_config2_rx[i<<1]));
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007264 }
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007265
7266 phy->rx_preemphasis[i << 1] = ((rx>>16) & 0xffff);
7267 phy->rx_preemphasis[(i << 1) + 1] = (rx & 0xffff);
7268
7269 phy->tx_preemphasis[i << 1] = ((tx>>16) & 0xffff);
7270 phy->tx_preemphasis[(i << 1) + 1] = (tx & 0xffff);
7271 }
7272}
7273
Yaniv Rosnere10bc842010-09-07 11:40:50 +00007274static u32 bnx2x_get_ext_phy_config(struct bnx2x *bp, u32 shmem_base,
7275 u8 phy_index, u8 port)
7276{
7277 u32 ext_phy_config = 0;
7278 switch (phy_index) {
7279 case EXT_PHY1:
7280 ext_phy_config = REG_RD(bp, shmem_base +
7281 offsetof(struct shmem_region,
7282 dev_info.port_hw_config[port].external_phy_config));
7283 break;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007284 case EXT_PHY2:
7285 ext_phy_config = REG_RD(bp, shmem_base +
7286 offsetof(struct shmem_region,
7287 dev_info.port_hw_config[port].external_phy_config2));
7288 break;
Yaniv Rosnere10bc842010-09-07 11:40:50 +00007289 default:
7290 DP(NETIF_MSG_LINK, "Invalid phy_index %d\n", phy_index);
7291 return -EINVAL;
7292 }
7293
7294 return ext_phy_config;
7295}
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007296static u8 bnx2x_populate_int_phy(struct bnx2x *bp, u32 shmem_base, u8 port,
7297 struct bnx2x_phy *phy)
7298{
7299 u32 phy_addr;
7300 u32 chip_id;
7301 u32 switch_cfg = (REG_RD(bp, shmem_base +
7302 offsetof(struct shmem_region,
7303 dev_info.port_feature_config[port].link_config)) &
7304 PORT_FEATURE_CONNECTED_SWITCH_MASK);
7305 chip_id = REG_RD(bp, MISC_REG_CHIP_NUM) << 16;
7306 switch (switch_cfg) {
7307 case SWITCH_CFG_1G:
7308 phy_addr = REG_RD(bp,
7309 NIG_REG_SERDES0_CTRL_PHY_ADDR +
7310 port * 0x10);
7311 *phy = phy_serdes;
7312 break;
7313 case SWITCH_CFG_10G:
7314 phy_addr = REG_RD(bp,
7315 NIG_REG_XGXS0_CTRL_PHY_ADDR +
7316 port * 0x18);
7317 *phy = phy_xgxs;
7318 break;
7319 default:
7320 DP(NETIF_MSG_LINK, "Invalid switch_cfg\n");
7321 return -EINVAL;
7322 }
7323 phy->addr = (u8)phy_addr;
7324 phy->mdio_ctrl = bnx2x_get_emac_base(bp,
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00007325 SHARED_HW_CFG_MDC_MDIO_ACCESS1_BOTH,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007326 port);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007327 if (CHIP_IS_E2(bp))
7328 phy->def_md_devad = E2_DEFAULT_PHY_DEV_ADDR;
7329 else
7330 phy->def_md_devad = DEFAULT_PHY_DEV_ADDR;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007331
7332 DP(NETIF_MSG_LINK, "Internal phy port=%d, addr=0x%x, mdio_ctl=0x%x\n",
7333 port, phy->addr, phy->mdio_ctrl);
7334
7335 bnx2x_populate_preemphasis(bp, shmem_base, phy, port, INT_PHY);
7336 return 0;
7337}
Yaniv Rosnere10bc842010-09-07 11:40:50 +00007338
7339static u8 bnx2x_populate_ext_phy(struct bnx2x *bp,
7340 u8 phy_index,
7341 u32 shmem_base,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007342 u32 shmem2_base,
Yaniv Rosnere10bc842010-09-07 11:40:50 +00007343 u8 port,
7344 struct bnx2x_phy *phy)
7345{
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00007346 u32 ext_phy_config, phy_type, config2;
7347 u32 mdc_mdio_access = SHARED_HW_CFG_MDC_MDIO_ACCESS1_BOTH;
Yaniv Rosnere10bc842010-09-07 11:40:50 +00007348 ext_phy_config = bnx2x_get_ext_phy_config(bp, shmem_base,
7349 phy_index, port);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007350 phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
7351 /* Select the phy type */
7352 switch (phy_type) {
7353 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073:
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00007354 mdc_mdio_access = SHARED_HW_CFG_MDC_MDIO_ACCESS1_SWAPPED;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007355 *phy = phy_8073;
7356 break;
7357 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705:
7358 *phy = phy_8705;
7359 break;
7360 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706:
7361 *phy = phy_8706;
7362 break;
7363 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00007364 mdc_mdio_access = SHARED_HW_CFG_MDC_MDIO_ACCESS1_EMAC1;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007365 *phy = phy_8726;
7366 break;
7367 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727_NOC:
7368 /* BCM8727_NOC => BCM8727 no over current */
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00007369 mdc_mdio_access = SHARED_HW_CFG_MDC_MDIO_ACCESS1_EMAC1;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007370 *phy = phy_8727;
7371 phy->flags |= FLAGS_NOC;
7372 break;
7373 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00007374 mdc_mdio_access = SHARED_HW_CFG_MDC_MDIO_ACCESS1_EMAC1;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007375 *phy = phy_8727;
7376 break;
7377 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8481:
7378 *phy = phy_8481;
7379 break;
7380 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84823:
7381 *phy = phy_84823;
7382 break;
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00007383 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833:
7384 *phy = phy_84833;
7385 break;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007386 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101:
7387 *phy = phy_7101;
7388 break;
7389 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE:
7390 *phy = phy_null;
7391 return -EINVAL;
7392 default:
7393 *phy = phy_null;
7394 return 0;
7395 }
7396
Yaniv Rosnere10bc842010-09-07 11:40:50 +00007397 phy->addr = XGXS_EXT_PHY_ADDR(ext_phy_config);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007398 bnx2x_populate_preemphasis(bp, shmem_base, phy, port, phy_index);
Yaniv Rosner62b29a52010-09-07 11:40:58 +00007399
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007400 /*
7401 * The shmem address of the phy version is located on different
7402 * structures. In case this structure is too old, do not set
7403 * the address
7404 */
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00007405 config2 = REG_RD(bp, shmem_base + offsetof(struct shmem_region,
7406 dev_info.shared_hw_config.config2));
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007407 if (phy_index == EXT_PHY1) {
7408 phy->ver_addr = shmem_base + offsetof(struct shmem_region,
7409 port_mb[port].ext_phy_fw_version);
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00007410
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007411 /* Check specific mdc mdio settings */
7412 if (config2 & SHARED_HW_CFG_MDC_MDIO_ACCESS1_MASK)
7413 mdc_mdio_access = config2 &
7414 SHARED_HW_CFG_MDC_MDIO_ACCESS1_MASK;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007415 } else {
7416 u32 size = REG_RD(bp, shmem2_base);
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00007417
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007418 if (size >
7419 offsetof(struct shmem2_region, ext_phy_fw_version2)) {
7420 phy->ver_addr = shmem2_base +
7421 offsetof(struct shmem2_region,
7422 ext_phy_fw_version2[port]);
7423 }
7424 /* Check specific mdc mdio settings */
7425 if (config2 & SHARED_HW_CFG_MDC_MDIO_ACCESS2_MASK)
7426 mdc_mdio_access = (config2 &
7427 SHARED_HW_CFG_MDC_MDIO_ACCESS2_MASK) >>
7428 (SHARED_HW_CFG_MDC_MDIO_ACCESS2_SHIFT -
7429 SHARED_HW_CFG_MDC_MDIO_ACCESS1_SHIFT);
7430 }
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00007431 phy->mdio_ctrl = bnx2x_get_emac_base(bp, mdc_mdio_access, port);
7432
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007433 /*
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00007434 * In case mdc/mdio_access of the external phy is different than the
7435 * mdc/mdio access of the XGXS, a HW lock must be taken in each access
7436 * to prevent one port interfere with another port's CL45 operations.
7437 */
7438 if (mdc_mdio_access != SHARED_HW_CFG_MDC_MDIO_ACCESS1_BOTH)
7439 phy->flags |= FLAGS_HW_LOCK_REQUIRED;
7440 DP(NETIF_MSG_LINK, "phy_type 0x%x port %d found in index %d\n",
7441 phy_type, port, phy_index);
7442 DP(NETIF_MSG_LINK, " addr=0x%x, mdio_ctl=0x%x\n",
7443 phy->addr, phy->mdio_ctrl);
Yaniv Rosnere10bc842010-09-07 11:40:50 +00007444 return 0;
7445}
7446
7447static u8 bnx2x_populate_phy(struct bnx2x *bp, u8 phy_index, u32 shmem_base,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007448 u32 shmem2_base, u8 port, struct bnx2x_phy *phy)
Yaniv Rosnere10bc842010-09-07 11:40:50 +00007449{
7450 u8 status = 0;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007451 phy->type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN;
7452 if (phy_index == INT_PHY)
7453 return bnx2x_populate_int_phy(bp, shmem_base, port, phy);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007454 status = bnx2x_populate_ext_phy(bp, phy_index, shmem_base, shmem2_base,
Yaniv Rosnere10bc842010-09-07 11:40:50 +00007455 port, phy);
7456 return status;
7457}
7458
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007459static void bnx2x_phy_def_cfg(struct link_params *params,
7460 struct bnx2x_phy *phy,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007461 u8 phy_index)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007462{
7463 struct bnx2x *bp = params->bp;
7464 u32 link_config;
7465 /* Populate the default phy configuration for MF mode */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007466 if (phy_index == EXT_PHY2) {
7467 link_config = REG_RD(bp, params->shmem_base +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007468 offsetof(struct shmem_region, dev_info.
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007469 port_feature_config[params->port].link_config2));
7470 phy->speed_cap_mask = REG_RD(bp, params->shmem_base +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007471 offsetof(struct shmem_region,
7472 dev_info.
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007473 port_hw_config[params->port].speed_capability_mask2));
7474 } else {
7475 link_config = REG_RD(bp, params->shmem_base +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007476 offsetof(struct shmem_region, dev_info.
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007477 port_feature_config[params->port].link_config));
7478 phy->speed_cap_mask = REG_RD(bp, params->shmem_base +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007479 offsetof(struct shmem_region,
7480 dev_info.
7481 port_hw_config[params->port].speed_capability_mask));
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007482 }
7483 DP(NETIF_MSG_LINK, "Default config phy idx %x cfg 0x%x speed_cap_mask"
7484 " 0x%x\n", phy_index, link_config, phy->speed_cap_mask);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007485
7486 phy->req_duplex = DUPLEX_FULL;
7487 switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
7488 case PORT_FEATURE_LINK_SPEED_10M_HALF:
7489 phy->req_duplex = DUPLEX_HALF;
7490 case PORT_FEATURE_LINK_SPEED_10M_FULL:
7491 phy->req_line_speed = SPEED_10;
7492 break;
7493 case PORT_FEATURE_LINK_SPEED_100M_HALF:
7494 phy->req_duplex = DUPLEX_HALF;
7495 case PORT_FEATURE_LINK_SPEED_100M_FULL:
7496 phy->req_line_speed = SPEED_100;
7497 break;
7498 case PORT_FEATURE_LINK_SPEED_1G:
7499 phy->req_line_speed = SPEED_1000;
7500 break;
7501 case PORT_FEATURE_LINK_SPEED_2_5G:
7502 phy->req_line_speed = SPEED_2500;
7503 break;
7504 case PORT_FEATURE_LINK_SPEED_10G_CX4:
7505 phy->req_line_speed = SPEED_10000;
7506 break;
7507 default:
7508 phy->req_line_speed = SPEED_AUTO_NEG;
7509 break;
7510 }
7511
7512 switch (link_config & PORT_FEATURE_FLOW_CONTROL_MASK) {
7513 case PORT_FEATURE_FLOW_CONTROL_AUTO:
7514 phy->req_flow_ctrl = BNX2X_FLOW_CTRL_AUTO;
7515 break;
7516 case PORT_FEATURE_FLOW_CONTROL_TX:
7517 phy->req_flow_ctrl = BNX2X_FLOW_CTRL_TX;
7518 break;
7519 case PORT_FEATURE_FLOW_CONTROL_RX:
7520 phy->req_flow_ctrl = BNX2X_FLOW_CTRL_RX;
7521 break;
7522 case PORT_FEATURE_FLOW_CONTROL_BOTH:
7523 phy->req_flow_ctrl = BNX2X_FLOW_CTRL_BOTH;
7524 break;
7525 default:
7526 phy->req_flow_ctrl = BNX2X_FLOW_CTRL_NONE;
7527 break;
7528 }
7529}
7530
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007531u32 bnx2x_phy_selection(struct link_params *params)
7532{
7533 u32 phy_config_swapped, prio_cfg;
7534 u32 return_cfg = PORT_HW_CFG_PHY_SELECTION_HARDWARE_DEFAULT;
7535
7536 phy_config_swapped = params->multi_phy_config &
7537 PORT_HW_CFG_PHY_SWAPPED_ENABLED;
7538
7539 prio_cfg = params->multi_phy_config &
7540 PORT_HW_CFG_PHY_SELECTION_MASK;
7541
7542 if (phy_config_swapped) {
7543 switch (prio_cfg) {
7544 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY_PRIORITY:
7545 return_cfg = PORT_HW_CFG_PHY_SELECTION_SECOND_PHY_PRIORITY;
7546 break;
7547 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY_PRIORITY:
7548 return_cfg = PORT_HW_CFG_PHY_SELECTION_FIRST_PHY_PRIORITY;
7549 break;
7550 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY:
7551 return_cfg = PORT_HW_CFG_PHY_SELECTION_FIRST_PHY;
7552 break;
7553 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY:
7554 return_cfg = PORT_HW_CFG_PHY_SELECTION_SECOND_PHY;
7555 break;
7556 }
7557 } else
7558 return_cfg = prio_cfg;
7559
7560 return return_cfg;
7561}
7562
7563
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007564u8 bnx2x_phy_probe(struct link_params *params)
7565{
7566 u8 phy_index, actual_phy_idx, link_cfg_idx;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007567 u32 phy_config_swapped;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007568 struct bnx2x *bp = params->bp;
7569 struct bnx2x_phy *phy;
7570 params->num_phys = 0;
7571 DP(NETIF_MSG_LINK, "Begin phy probe\n");
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007572 phy_config_swapped = params->multi_phy_config &
7573 PORT_HW_CFG_PHY_SWAPPED_ENABLED;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007574
7575 for (phy_index = INT_PHY; phy_index < MAX_PHYS;
7576 phy_index++) {
7577 link_cfg_idx = LINK_CONFIG_IDX(phy_index);
7578 actual_phy_idx = phy_index;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007579 if (phy_config_swapped) {
7580 if (phy_index == EXT_PHY1)
7581 actual_phy_idx = EXT_PHY2;
7582 else if (phy_index == EXT_PHY2)
7583 actual_phy_idx = EXT_PHY1;
7584 }
7585 DP(NETIF_MSG_LINK, "phy_config_swapped %x, phy_index %x,"
7586 " actual_phy_idx %x\n", phy_config_swapped,
7587 phy_index, actual_phy_idx);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007588 phy = &params->phy[actual_phy_idx];
7589 if (bnx2x_populate_phy(bp, phy_index, params->shmem_base,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007590 params->shmem2_base, params->port,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007591 phy) != 0) {
7592 params->num_phys = 0;
7593 DP(NETIF_MSG_LINK, "phy probe failed in phy index %d\n",
7594 phy_index);
7595 for (phy_index = INT_PHY;
7596 phy_index < MAX_PHYS;
7597 phy_index++)
7598 *phy = phy_null;
7599 return -EINVAL;
7600 }
7601 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN)
7602 break;
7603
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007604 bnx2x_phy_def_cfg(params, phy, phy_index);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00007605 params->num_phys++;
7606 }
7607
7608 DP(NETIF_MSG_LINK, "End phy probe. #phys found %x\n", params->num_phys);
7609 return 0;
7610}
7611
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007612static void set_phy_vars(struct link_params *params)
7613{
7614 struct bnx2x *bp = params->bp;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007615 u8 actual_phy_idx, phy_index, link_cfg_idx;
7616 u8 phy_config_swapped = params->multi_phy_config &
7617 PORT_HW_CFG_PHY_SWAPPED_ENABLED;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007618 for (phy_index = INT_PHY; phy_index < params->num_phys;
7619 phy_index++) {
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007620 link_cfg_idx = LINK_CONFIG_IDX(phy_index);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007621 actual_phy_idx = phy_index;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007622 if (phy_config_swapped) {
7623 if (phy_index == EXT_PHY1)
7624 actual_phy_idx = EXT_PHY2;
7625 else if (phy_index == EXT_PHY2)
7626 actual_phy_idx = EXT_PHY1;
7627 }
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007628 params->phy[actual_phy_idx].req_flow_ctrl =
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007629 params->req_flow_ctrl[link_cfg_idx];
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007630
7631 params->phy[actual_phy_idx].req_line_speed =
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007632 params->req_line_speed[link_cfg_idx];
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007633
7634 params->phy[actual_phy_idx].speed_cap_mask =
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007635 params->speed_cap_mask[link_cfg_idx];
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007636
7637 params->phy[actual_phy_idx].req_duplex =
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007638 params->req_duplex[link_cfg_idx];
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007639
7640 DP(NETIF_MSG_LINK, "req_flow_ctrl %x, req_line_speed %x,"
7641 " speed_cap_mask %x\n",
7642 params->phy[actual_phy_idx].req_flow_ctrl,
7643 params->phy[actual_phy_idx].req_line_speed,
7644 params->phy[actual_phy_idx].speed_cap_mask);
7645 }
7646}
7647
7648u8 bnx2x_phy_init(struct link_params *params, struct link_vars *vars)
7649{
7650 struct bnx2x *bp = params->bp;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007651 DP(NETIF_MSG_LINK, "Phy Initialization started\n");
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007652 DP(NETIF_MSG_LINK, "(1) req_speed %d, req_flowctrl %d\n",
7653 params->req_line_speed[0], params->req_flow_ctrl[0]);
7654 DP(NETIF_MSG_LINK, "(2) req_speed %d, req_flowctrl %d\n",
7655 params->req_line_speed[1], params->req_flow_ctrl[1]);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007656 vars->link_status = 0;
7657 vars->phy_link_up = 0;
7658 vars->link_up = 0;
7659 vars->line_speed = 0;
7660 vars->duplex = DUPLEX_FULL;
7661 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
7662 vars->mac_type = MAC_TYPE_NONE;
7663 vars->phy_flags = 0;
7664
7665 /* disable attentions */
7666 bnx2x_bits_dis(bp, NIG_REG_MASK_INTERRUPT_PORT0 + params->port*4,
7667 (NIG_MASK_XGXS0_LINK_STATUS |
7668 NIG_MASK_XGXS0_LINK10G |
7669 NIG_MASK_SERDES0_LINK_STATUS |
7670 NIG_MASK_MI_INT));
7671
7672 bnx2x_emac_init(params, vars);
7673
7674 if (params->num_phys == 0) {
7675 DP(NETIF_MSG_LINK, "No phy found for initialization !!\n");
7676 return -EINVAL;
7677 }
7678 set_phy_vars(params);
7679
7680 DP(NETIF_MSG_LINK, "Num of phys on board: %d\n", params->num_phys);
7681 if (CHIP_REV_IS_FPGA(bp)) {
7682
7683 vars->link_up = 1;
7684 vars->line_speed = SPEED_10000;
7685 vars->duplex = DUPLEX_FULL;
7686 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
7687 vars->link_status = (LINK_STATUS_LINK_UP | LINK_10GTFD);
7688 /* enable on E1.5 FPGA */
7689 if (CHIP_IS_E1H(bp)) {
7690 vars->flow_ctrl |=
7691 (BNX2X_FLOW_CTRL_TX |
7692 BNX2X_FLOW_CTRL_RX);
7693 vars->link_status |=
7694 (LINK_STATUS_TX_FLOW_CONTROL_ENABLED |
7695 LINK_STATUS_RX_FLOW_CONTROL_ENABLED);
7696 }
7697
7698 bnx2x_emac_enable(params, vars, 0);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007699 if (!(CHIP_IS_E2(bp)))
7700 bnx2x_pbf_update(params, vars->flow_ctrl,
7701 vars->line_speed);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007702 /* disable drain */
7703 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 0);
7704
7705 /* update shared memory */
7706 bnx2x_update_mng(params, vars->link_status);
7707
7708 return 0;
7709
7710 } else
7711 if (CHIP_REV_IS_EMUL(bp)) {
7712
7713 vars->link_up = 1;
7714 vars->line_speed = SPEED_10000;
7715 vars->duplex = DUPLEX_FULL;
7716 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
7717 vars->link_status = (LINK_STATUS_LINK_UP | LINK_10GTFD);
7718
7719 bnx2x_bmac_enable(params, vars, 0);
7720
7721 bnx2x_pbf_update(params, vars->flow_ctrl, vars->line_speed);
7722 /* Disable drain */
7723 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE
7724 + params->port*4, 0);
7725
7726 /* update shared memory */
7727 bnx2x_update_mng(params, vars->link_status);
7728
7729 return 0;
7730
7731 } else
7732 if (params->loopback_mode == LOOPBACK_BMAC) {
7733
7734 vars->link_up = 1;
7735 vars->line_speed = SPEED_10000;
7736 vars->duplex = DUPLEX_FULL;
7737 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
7738 vars->mac_type = MAC_TYPE_BMAC;
7739
7740 vars->phy_flags = PHY_XGXS_FLAG;
7741
7742 bnx2x_xgxs_deassert(params);
7743
7744 /* set bmac loopback */
7745 bnx2x_bmac_enable(params, vars, 1);
7746
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007747 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007748
7749 } else if (params->loopback_mode == LOOPBACK_EMAC) {
7750
7751 vars->link_up = 1;
7752 vars->line_speed = SPEED_1000;
7753 vars->duplex = DUPLEX_FULL;
7754 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
7755 vars->mac_type = MAC_TYPE_EMAC;
7756
7757 vars->phy_flags = PHY_XGXS_FLAG;
7758
7759 bnx2x_xgxs_deassert(params);
7760 /* set bmac loopback */
7761 bnx2x_emac_enable(params, vars, 1);
7762 bnx2x_emac_program(params, vars);
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007763 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007764
7765 } else if ((params->loopback_mode == LOOPBACK_XGXS) ||
7766 (params->loopback_mode == LOOPBACK_EXT_PHY)) {
7767
7768 vars->link_up = 1;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007769 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007770 vars->duplex = DUPLEX_FULL;
7771 if (params->req_line_speed[0] == SPEED_1000) {
7772 vars->line_speed = SPEED_1000;
7773 vars->mac_type = MAC_TYPE_EMAC;
7774 } else {
7775 vars->line_speed = SPEED_10000;
7776 vars->mac_type = MAC_TYPE_BMAC;
7777 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007778
7779 bnx2x_xgxs_deassert(params);
7780 bnx2x_link_initialize(params, vars);
7781
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007782 if (params->req_line_speed[0] == SPEED_1000) {
7783 bnx2x_emac_program(params, vars);
7784 bnx2x_emac_enable(params, vars, 0);
7785 } else
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007786 bnx2x_bmac_enable(params, vars, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007787 if (params->loopback_mode == LOOPBACK_XGXS) {
7788 /* set 10G XGXS loopback */
7789 params->phy[INT_PHY].config_loopback(
7790 &params->phy[INT_PHY],
7791 params);
7792
7793 } else {
7794 /* set external phy loopback */
7795 u8 phy_index;
7796 for (phy_index = EXT_PHY1;
7797 phy_index < params->num_phys; phy_index++) {
7798 if (params->phy[phy_index].config_loopback)
7799 params->phy[phy_index].config_loopback(
7800 &params->phy[phy_index],
7801 params);
7802 }
7803 }
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007804 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007805
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00007806 bnx2x_set_led(params, vars,
7807 LED_MODE_OPER, vars->line_speed);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007808 } else
7809 /* No loopback */
7810 {
7811 if (params->switch_cfg == SWITCH_CFG_10G)
7812 bnx2x_xgxs_deassert(params);
7813 else
7814 bnx2x_serdes_deassert(bp, params->port);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00007815
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007816 bnx2x_link_initialize(params, vars);
7817 msleep(30);
7818 bnx2x_link_int_enable(params);
7819 }
7820 return 0;
7821}
7822u8 bnx2x_link_reset(struct link_params *params, struct link_vars *vars,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007823 u8 reset_ext_phy)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007824{
7825 struct bnx2x *bp = params->bp;
Yaniv Rosnercf1d9722010-11-01 05:32:34 +00007826 u8 phy_index, port = params->port, clear_latch_ind = 0;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007827 DP(NETIF_MSG_LINK, "Resetting the link of port %d\n", port);
7828 /* disable attentions */
7829 vars->link_status = 0;
7830 bnx2x_update_mng(params, vars->link_status);
7831 bnx2x_bits_dis(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007832 (NIG_MASK_XGXS0_LINK_STATUS |
7833 NIG_MASK_XGXS0_LINK10G |
7834 NIG_MASK_SERDES0_LINK_STATUS |
7835 NIG_MASK_MI_INT));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007836
7837 /* activate nig drain */
7838 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + port*4, 1);
7839
7840 /* disable nig egress interface */
7841 REG_WR(bp, NIG_REG_BMAC0_OUT_EN + port*4, 0);
7842 REG_WR(bp, NIG_REG_EGRESS_EMAC0_OUT_EN + port*4, 0);
7843
7844 /* Stop BigMac rx */
7845 bnx2x_bmac_rx_disable(bp, port);
7846
7847 /* disable emac */
7848 REG_WR(bp, NIG_REG_NIG_EMAC0_EN + port*4, 0);
7849
7850 msleep(10);
7851 /* The PHY reset is controled by GPIO 1
7852 * Hold it as vars low
7853 */
7854 /* clear link led */
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00007855 bnx2x_set_led(params, vars, LED_MODE_OFF, 0);
7856
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007857 if (reset_ext_phy) {
7858 for (phy_index = EXT_PHY1; phy_index < params->num_phys;
7859 phy_index++) {
7860 if (params->phy[phy_index].link_reset)
7861 params->phy[phy_index].link_reset(
7862 &params->phy[phy_index],
7863 params);
Yaniv Rosnercf1d9722010-11-01 05:32:34 +00007864 if (params->phy[phy_index].flags &
7865 FLAGS_REARM_LATCH_SIGNAL)
7866 clear_latch_ind = 1;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007867 }
7868 }
7869
Yaniv Rosnercf1d9722010-11-01 05:32:34 +00007870 if (clear_latch_ind) {
7871 /* Clear latching indication */
7872 bnx2x_rearm_latch_signal(bp, port, 0);
7873 bnx2x_bits_dis(bp, NIG_REG_LATCH_BC_0 + port*4,
7874 1 << NIG_LATCH_BC_ENABLE_MI_INT);
7875 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007876 if (params->phy[INT_PHY].link_reset)
7877 params->phy[INT_PHY].link_reset(
7878 &params->phy[INT_PHY], params);
7879 /* reset BigMac */
7880 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
7881 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port));
7882
7883 /* disable nig ingress interface */
7884 REG_WR(bp, NIG_REG_BMAC0_IN_EN + port*4, 0);
7885 REG_WR(bp, NIG_REG_EMAC0_IN_EN + port*4, 0);
7886 REG_WR(bp, NIG_REG_BMAC0_OUT_EN + port*4, 0);
7887 REG_WR(bp, NIG_REG_EGRESS_EMAC0_OUT_EN + port*4, 0);
7888 vars->link_up = 0;
7889 return 0;
7890}
7891
7892/****************************************************************************/
7893/* Common function */
7894/****************************************************************************/
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007895static u8 bnx2x_8073_common_init_phy(struct bnx2x *bp,
7896 u32 shmem_base_path[],
7897 u32 shmem2_base_path[], u8 phy_index,
7898 u32 chip_id)
Yaniv Rosner6bbca912008-08-13 15:57:28 -07007899{
Yaniv Rosnere10bc842010-09-07 11:40:50 +00007900 struct bnx2x_phy phy[PORT_MAX];
7901 struct bnx2x_phy *phy_blk[PORT_MAX];
Yaniv Rosner6bbca912008-08-13 15:57:28 -07007902 u16 val;
Yaniv Rosnerc8e64df2011-01-30 04:15:00 +00007903 s8 port = 0;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007904 s8 port_of_path = 0;
Yaniv Rosnerc8e64df2011-01-30 04:15:00 +00007905 u32 swap_val, swap_override;
7906 swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
7907 swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
7908 port ^= (swap_val && swap_override);
7909 bnx2x_ext_phy_hw_reset(bp, port);
Yaniv Rosner6bbca912008-08-13 15:57:28 -07007910 /* PART1 - Reset both phys */
7911 for (port = PORT_MAX - 1; port >= PORT_0; port--) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007912 u32 shmem_base, shmem2_base;
7913 /* In E2, same phy is using for port0 of the two paths */
7914 if (CHIP_IS_E2(bp)) {
7915 shmem_base = shmem_base_path[port];
7916 shmem2_base = shmem2_base_path[port];
7917 port_of_path = 0;
7918 } else {
7919 shmem_base = shmem_base_path[0];
7920 shmem2_base = shmem2_base_path[0];
7921 port_of_path = port;
7922 }
7923
Yaniv Rosner6bbca912008-08-13 15:57:28 -07007924 /* Extract the ext phy address for the port */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00007925 if (bnx2x_populate_phy(bp, phy_index, shmem_base, shmem2_base,
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007926 port_of_path, &phy[port]) !=
Yaniv Rosnere10bc842010-09-07 11:40:50 +00007927 0) {
7928 DP(NETIF_MSG_LINK, "populate_phy failed\n");
7929 return -EINVAL;
7930 }
Yaniv Rosner6bbca912008-08-13 15:57:28 -07007931 /* disable attentions */
Yaniv Rosner6a71bbe2010-11-01 05:32:31 +00007932 bnx2x_bits_dis(bp, NIG_REG_MASK_INTERRUPT_PORT0 +
7933 port_of_path*4,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007934 (NIG_MASK_XGXS0_LINK_STATUS |
7935 NIG_MASK_XGXS0_LINK10G |
7936 NIG_MASK_SERDES0_LINK_STATUS |
7937 NIG_MASK_MI_INT));
Yaniv Rosner6bbca912008-08-13 15:57:28 -07007938
Yaniv Rosner6bbca912008-08-13 15:57:28 -07007939 /* Need to take the phy out of low power mode in order
7940 to write to access its registers */
7941 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007942 MISC_REGISTERS_GPIO_OUTPUT_HIGH,
7943 port);
Yaniv Rosner6bbca912008-08-13 15:57:28 -07007944
7945 /* Reset the phy */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00007946 bnx2x_cl45_write(bp, &phy[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007947 MDIO_PMA_DEVAD,
7948 MDIO_PMA_REG_CTRL,
7949 1<<15);
Yaniv Rosner6bbca912008-08-13 15:57:28 -07007950 }
7951
7952 /* Add delay of 150ms after reset */
7953 msleep(150);
7954
Yaniv Rosnere10bc842010-09-07 11:40:50 +00007955 if (phy[PORT_0].addr & 0x1) {
7956 phy_blk[PORT_0] = &(phy[PORT_1]);
7957 phy_blk[PORT_1] = &(phy[PORT_0]);
7958 } else {
7959 phy_blk[PORT_0] = &(phy[PORT_0]);
7960 phy_blk[PORT_1] = &(phy[PORT_1]);
7961 }
7962
Yaniv Rosner6bbca912008-08-13 15:57:28 -07007963 /* PART2 - Download firmware to both phys */
7964 for (port = PORT_MAX - 1; port >= PORT_0; port--) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007965 if (CHIP_IS_E2(bp))
7966 port_of_path = 0;
7967 else
7968 port_of_path = port;
Yaniv Rosner6bbca912008-08-13 15:57:28 -07007969
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007970 DP(NETIF_MSG_LINK, "Loading spirom for phy address 0x%x\n",
7971 phy_blk[port]->addr);
Yaniv Rosner5c99274b2011-01-18 04:33:36 +00007972 if (bnx2x_8073_8727_external_rom_boot(bp, phy_blk[port],
7973 port_of_path))
Yaniv Rosner6bbca912008-08-13 15:57:28 -07007974 return -EINVAL;
Yaniv Rosner6bbca912008-08-13 15:57:28 -07007975
7976 /* Only set bit 10 = 1 (Tx power down) */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00007977 bnx2x_cl45_read(bp, phy_blk[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007978 MDIO_PMA_DEVAD,
7979 MDIO_PMA_REG_TX_POWER_DOWN, &val);
Yaniv Rosner6bbca912008-08-13 15:57:28 -07007980
7981 /* Phase1 of TX_POWER_DOWN reset */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00007982 bnx2x_cl45_write(bp, phy_blk[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007983 MDIO_PMA_DEVAD,
7984 MDIO_PMA_REG_TX_POWER_DOWN,
7985 (val | 1<<10));
Yaniv Rosner6bbca912008-08-13 15:57:28 -07007986 }
7987
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007988 /*
7989 * Toggle Transmitter: Power down and then up with 600ms delay
7990 * between
7991 */
Yaniv Rosner6bbca912008-08-13 15:57:28 -07007992 msleep(600);
7993
7994 /* PART3 - complete TX_POWER_DOWN process, and set GPIO2 back to low */
7995 for (port = PORT_MAX - 1; port >= PORT_0; port--) {
Eilon Greensteinf5372252009-02-12 08:38:30 +00007996 /* Phase2 of POWER_DOWN_RESET */
Yaniv Rosner6bbca912008-08-13 15:57:28 -07007997 /* Release bit 10 (Release Tx power down) */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00007998 bnx2x_cl45_read(bp, phy_blk[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007999 MDIO_PMA_DEVAD,
8000 MDIO_PMA_REG_TX_POWER_DOWN, &val);
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008001
Yaniv Rosnere10bc842010-09-07 11:40:50 +00008002 bnx2x_cl45_write(bp, phy_blk[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008003 MDIO_PMA_DEVAD,
8004 MDIO_PMA_REG_TX_POWER_DOWN, (val & (~(1<<10))));
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008005 msleep(15);
8006
8007 /* Read modify write the SPI-ROM version select register */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00008008 bnx2x_cl45_read(bp, phy_blk[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008009 MDIO_PMA_DEVAD,
8010 MDIO_PMA_REG_EDC_FFE_MAIN, &val);
Yaniv Rosnere10bc842010-09-07 11:40:50 +00008011 bnx2x_cl45_write(bp, phy_blk[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008012 MDIO_PMA_DEVAD,
8013 MDIO_PMA_REG_EDC_FFE_MAIN, (val | (1<<12)));
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008014
8015 /* set GPIO2 back to LOW */
8016 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008017 MISC_REGISTERS_GPIO_OUTPUT_LOW, port);
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008018 }
8019 return 0;
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008020}
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008021static u8 bnx2x_8726_common_init_phy(struct bnx2x *bp,
8022 u32 shmem_base_path[],
8023 u32 shmem2_base_path[], u8 phy_index,
8024 u32 chip_id)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008025{
8026 u32 val;
8027 s8 port;
8028 struct bnx2x_phy phy;
8029 /* Use port1 because of the static port-swap */
8030 /* Enable the module detection interrupt */
8031 val = REG_RD(bp, MISC_REG_GPIO_EVENT_EN);
8032 val |= ((1<<MISC_REGISTERS_GPIO_3)|
8033 (1<<(MISC_REGISTERS_GPIO_3 + MISC_REGISTERS_GPIO_PORT_SHIFT)));
8034 REG_WR(bp, MISC_REG_GPIO_EVENT_EN, val);
8035
Yaniv Rosner650154b2010-11-01 05:32:36 +00008036 bnx2x_ext_phy_hw_reset(bp, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008037 msleep(5);
8038 for (port = 0; port < PORT_MAX; port++) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008039 u32 shmem_base, shmem2_base;
8040
8041 /* In E2, same phy is using for port0 of the two paths */
8042 if (CHIP_IS_E2(bp)) {
8043 shmem_base = shmem_base_path[port];
8044 shmem2_base = shmem2_base_path[port];
8045 } else {
8046 shmem_base = shmem_base_path[0];
8047 shmem2_base = shmem2_base_path[0];
8048 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008049 /* Extract the ext phy address for the port */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008050 if (bnx2x_populate_phy(bp, phy_index, shmem_base, shmem2_base,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008051 port, &phy) !=
8052 0) {
8053 DP(NETIF_MSG_LINK, "populate phy failed\n");
8054 return -EINVAL;
8055 }
8056
8057 /* Reset phy*/
8058 bnx2x_cl45_write(bp, &phy,
8059 MDIO_PMA_DEVAD, MDIO_PMA_REG_GEN_CTRL, 0x0001);
8060
8061
8062 /* Set fault module detected LED on */
8063 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_0,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008064 MISC_REGISTERS_GPIO_HIGH,
8065 port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008066 }
8067
8068 return 0;
8069}
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008070static void bnx2x_get_ext_phy_reset_gpio(struct bnx2x *bp, u32 shmem_base,
8071 u8 *io_gpio, u8 *io_port)
8072{
8073
8074 u32 phy_gpio_reset = REG_RD(bp, shmem_base +
8075 offsetof(struct shmem_region,
8076 dev_info.port_hw_config[PORT_0].default_cfg));
8077 switch (phy_gpio_reset) {
8078 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO0_P0:
8079 *io_gpio = 0;
8080 *io_port = 0;
8081 break;
8082 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO1_P0:
8083 *io_gpio = 1;
8084 *io_port = 0;
8085 break;
8086 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO2_P0:
8087 *io_gpio = 2;
8088 *io_port = 0;
8089 break;
8090 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO3_P0:
8091 *io_gpio = 3;
8092 *io_port = 0;
8093 break;
8094 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO0_P1:
8095 *io_gpio = 0;
8096 *io_port = 1;
8097 break;
8098 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO1_P1:
8099 *io_gpio = 1;
8100 *io_port = 1;
8101 break;
8102 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO2_P1:
8103 *io_gpio = 2;
8104 *io_port = 1;
8105 break;
8106 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO3_P1:
8107 *io_gpio = 3;
8108 *io_port = 1;
8109 break;
8110 default:
8111 /* Don't override the io_gpio and io_port */
8112 break;
8113 }
8114}
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008115static u8 bnx2x_8727_common_init_phy(struct bnx2x *bp,
8116 u32 shmem_base_path[],
8117 u32 shmem2_base_path[], u8 phy_index,
8118 u32 chip_id)
Eilon Greenstein4d295db2009-07-21 05:47:47 +00008119{
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008120 s8 port, reset_gpio;
Eilon Greenstein4d295db2009-07-21 05:47:47 +00008121 u32 swap_val, swap_override;
Yaniv Rosnere10bc842010-09-07 11:40:50 +00008122 struct bnx2x_phy phy[PORT_MAX];
8123 struct bnx2x_phy *phy_blk[PORT_MAX];
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008124 s8 port_of_path;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008125 swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
8126 swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
Eilon Greenstein4d295db2009-07-21 05:47:47 +00008127
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008128 reset_gpio = MISC_REGISTERS_GPIO_1;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008129 port = 1;
8130
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008131 /*
8132 * Retrieve the reset gpio/port which control the reset.
8133 * Default is GPIO1, PORT1
8134 */
8135 bnx2x_get_ext_phy_reset_gpio(bp, shmem_base_path[0],
8136 (u8 *)&reset_gpio, (u8 *)&port);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008137
8138 /* Calculate the port based on port swap */
8139 port ^= (swap_val && swap_override);
8140
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008141 /* Initiate PHY reset*/
8142 bnx2x_set_gpio(bp, reset_gpio, MISC_REGISTERS_GPIO_OUTPUT_LOW,
8143 port);
8144 msleep(1);
8145 bnx2x_set_gpio(bp, reset_gpio, MISC_REGISTERS_GPIO_OUTPUT_HIGH,
8146 port);
8147
Eilon Greenstein4d295db2009-07-21 05:47:47 +00008148 msleep(5);
8149
8150 /* PART1 - Reset both phys */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008151 for (port = PORT_MAX - 1; port >= PORT_0; port--) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008152 u32 shmem_base, shmem2_base;
8153
8154 /* In E2, same phy is using for port0 of the two paths */
8155 if (CHIP_IS_E2(bp)) {
8156 shmem_base = shmem_base_path[port];
8157 shmem2_base = shmem2_base_path[port];
8158 port_of_path = 0;
8159 } else {
8160 shmem_base = shmem_base_path[0];
8161 shmem2_base = shmem2_base_path[0];
8162 port_of_path = port;
8163 }
8164
Eilon Greenstein4d295db2009-07-21 05:47:47 +00008165 /* Extract the ext phy address for the port */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008166 if (bnx2x_populate_phy(bp, phy_index, shmem_base, shmem2_base,
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008167 port_of_path, &phy[port]) !=
Yaniv Rosnere10bc842010-09-07 11:40:50 +00008168 0) {
8169 DP(NETIF_MSG_LINK, "populate phy failed\n");
8170 return -EINVAL;
8171 }
Eilon Greenstein4d295db2009-07-21 05:47:47 +00008172 /* disable attentions */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008173 bnx2x_bits_dis(bp, NIG_REG_MASK_INTERRUPT_PORT0 +
8174 port_of_path*4,
8175 (NIG_MASK_XGXS0_LINK_STATUS |
8176 NIG_MASK_XGXS0_LINK10G |
8177 NIG_MASK_SERDES0_LINK_STATUS |
8178 NIG_MASK_MI_INT));
Eilon Greenstein4d295db2009-07-21 05:47:47 +00008179
Eilon Greenstein4d295db2009-07-21 05:47:47 +00008180
8181 /* Reset the phy */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00008182 bnx2x_cl45_write(bp, &phy[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008183 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 1<<15);
Eilon Greenstein4d295db2009-07-21 05:47:47 +00008184 }
8185
8186 /* Add delay of 150ms after reset */
8187 msleep(150);
Yaniv Rosnere10bc842010-09-07 11:40:50 +00008188 if (phy[PORT_0].addr & 0x1) {
8189 phy_blk[PORT_0] = &(phy[PORT_1]);
8190 phy_blk[PORT_1] = &(phy[PORT_0]);
8191 } else {
8192 phy_blk[PORT_0] = &(phy[PORT_0]);
8193 phy_blk[PORT_1] = &(phy[PORT_1]);
8194 }
Eilon Greenstein4d295db2009-07-21 05:47:47 +00008195 /* PART2 - Download firmware to both phys */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00008196 for (port = PORT_MAX - 1; port >= PORT_0; port--) {
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008197 if (CHIP_IS_E2(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008198 port_of_path = 0;
8199 else
8200 port_of_path = port;
8201 DP(NETIF_MSG_LINK, "Loading spirom for phy address 0x%x\n",
8202 phy_blk[port]->addr);
Yaniv Rosner5c99274b2011-01-18 04:33:36 +00008203 if (bnx2x_8073_8727_external_rom_boot(bp, phy_blk[port],
8204 port_of_path))
Eilon Greenstein4d295db2009-07-21 05:47:47 +00008205 return -EINVAL;
Eilon Greenstein4d295db2009-07-21 05:47:47 +00008206
Yaniv Rosner5c99274b2011-01-18 04:33:36 +00008207 }
Eilon Greenstein4d295db2009-07-21 05:47:47 +00008208 return 0;
8209}
8210
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008211static u8 bnx2x_ext_phy_common_init(struct bnx2x *bp, u32 shmem_base_path[],
8212 u32 shmem2_base_path[], u8 phy_index,
8213 u32 ext_phy_type, u32 chip_id)
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008214{
8215 u8 rc = 0;
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008216
8217 switch (ext_phy_type) {
8218 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073:
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008219 rc = bnx2x_8073_common_init_phy(bp, shmem_base_path,
8220 shmem2_base_path,
8221 phy_index, chip_id);
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008222 break;
Eilon Greenstein4d295db2009-07-21 05:47:47 +00008223
8224 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
8225 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727_NOC:
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008226 rc = bnx2x_8727_common_init_phy(bp, shmem_base_path,
8227 shmem2_base_path,
8228 phy_index, chip_id);
Eilon Greenstein4d295db2009-07-21 05:47:47 +00008229 break;
8230
Eilon Greenstein589abe32009-02-12 08:36:55 +00008231 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008232 /*
8233 * GPIO1 affects both ports, so there's need to pull
8234 * it for single port alone
8235 */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008236 rc = bnx2x_8726_common_init_phy(bp, shmem_base_path,
8237 shmem2_base_path,
8238 phy_index, chip_id);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008239 break;
8240 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE:
8241 rc = -EINVAL;
Yaniv Rosner4f60dab2009-11-05 19:18:23 +02008242 break;
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008243 default:
8244 DP(NETIF_MSG_LINK,
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008245 "ext_phy 0x%x common init not required\n",
8246 ext_phy_type);
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008247 break;
8248 }
8249
Yaniv Rosner6d870c32011-01-31 04:22:20 +00008250 if (rc != 0)
8251 netdev_err(bp->dev, "Warning: PHY was not initialized,"
8252 " Port %d\n",
8253 0);
Yaniv Rosner6bbca912008-08-13 15:57:28 -07008254 return rc;
8255}
8256
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008257u8 bnx2x_common_init_phy(struct bnx2x *bp, u32 shmem_base_path[],
8258 u32 shmem2_base_path[], u32 chip_id)
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008259{
8260 u8 rc = 0;
Yaniv Rosnerb21a3422011-01-18 04:33:24 +00008261 u32 phy_ver;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008262 u8 phy_index;
8263 u32 ext_phy_type, ext_phy_config;
8264 DP(NETIF_MSG_LINK, "Begin common phy init\n");
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +00008265
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008266 if (CHIP_REV_IS_EMUL(bp))
8267 return 0;
8268
Yaniv Rosnerb21a3422011-01-18 04:33:24 +00008269 /* Check if common init was already done */
8270 phy_ver = REG_RD(bp, shmem_base_path[0] +
8271 offsetof(struct shmem_region,
8272 port_mb[PORT_0].ext_phy_fw_version));
8273 if (phy_ver) {
8274 DP(NETIF_MSG_LINK, "Not doing common init; phy ver is 0x%x\n",
8275 phy_ver);
8276 return 0;
8277 }
8278
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008279 /* Read the ext_phy_type for arbitrary port(0) */
8280 for (phy_index = EXT_PHY1; phy_index < MAX_PHYS;
8281 phy_index++) {
8282 ext_phy_config = bnx2x_get_ext_phy_config(bp,
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008283 shmem_base_path[0],
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008284 phy_index, 0);
8285 ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00008286 rc |= bnx2x_ext_phy_common_init(bp, shmem_base_path,
8287 shmem2_base_path,
8288 phy_index, ext_phy_type,
8289 chip_id);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008290 }
8291 return rc;
8292}
8293
8294u8 bnx2x_hw_lock_required(struct bnx2x *bp, u32 shmem_base, u32 shmem2_base)
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +00008295{
8296 u8 phy_index;
8297 struct bnx2x_phy phy;
8298 for (phy_index = INT_PHY; phy_index < MAX_PHYS;
8299 phy_index++) {
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008300 if (bnx2x_populate_phy(bp, phy_index, shmem_base, shmem2_base,
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +00008301 0, &phy) != 0) {
8302 DP(NETIF_MSG_LINK, "populate phy failed\n");
8303 return 0;
8304 }
8305
8306 if (phy.flags & FLAGS_HW_LOCK_REQUIRED)
8307 return 1;
8308 }
8309 return 0;
8310}
8311
8312u8 bnx2x_fan_failure_det_req(struct bnx2x *bp,
8313 u32 shmem_base,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008314 u32 shmem2_base,
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +00008315 u8 port)
8316{
8317 u8 phy_index, fan_failure_det_req = 0;
8318 struct bnx2x_phy phy;
8319 for (phy_index = EXT_PHY1; phy_index < MAX_PHYS;
8320 phy_index++) {
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008321 if (bnx2x_populate_phy(bp, phy_index, shmem_base, shmem2_base,
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +00008322 port, &phy)
8323 != 0) {
8324 DP(NETIF_MSG_LINK, "populate phy failed\n");
8325 return 0;
8326 }
8327 fan_failure_det_req |= (phy.flags &
8328 FLAGS_FAN_FAILURE_DET_REQ);
8329 }
8330 return fan_failure_det_req;
8331}
8332
8333void bnx2x_hw_reset_phy(struct link_params *params)
8334{
8335 u8 phy_index;
8336 for (phy_index = EXT_PHY1; phy_index < MAX_PHYS;
8337 phy_index++) {
8338 if (params->phy[phy_index].hw_reset) {
8339 params->phy[phy_index].hw_reset(
8340 &params->phy[phy_index],
8341 params);
8342 params->phy[phy_index] = phy_null;
8343 }
8344 }
8345}