blob: b08ff77f1f969c3b495167ce329c0b33b4b79371 [file] [log] [blame]
Eilon Greensteind05c26c2009-01-17 23:26:13 -08001/* Copyright 2008-2009 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
17#include <linux/kernel.h>
18#include <linux/errno.h>
19#include <linux/pci.h>
20#include <linux/netdevice.h>
21#include <linux/delay.h>
22#include <linux/ethtool.h>
23#include <linux/mutex.h>
Yaniv Rosnerea4e0402008-06-23 20:27:26 -070024
Yaniv Rosnerea4e0402008-06-23 20:27:26 -070025#include "bnx2x.h"
26
27/********************************************************/
Eilon Greenstein3196a882008-08-13 15:58:49 -070028#define ETH_HLEN 14
Yaniv Rosnerea4e0402008-06-23 20:27:26 -070029#define ETH_OVREHEAD (ETH_HLEN + 8)/* 8 for CRC + VLAN*/
30#define ETH_MIN_PACKET_SIZE 60
31#define ETH_MAX_PACKET_SIZE 1500
32#define ETH_MAX_JUMBO_PACKET_SIZE 9600
33#define MDIO_ACCESS_TIMEOUT 1000
34#define BMAC_CONTROL_RX_ENABLE 2
Yaniv Rosnerea4e0402008-06-23 20:27:26 -070035
36/***********************************************************/
Eilon Greenstein3196a882008-08-13 15:58:49 -070037/* Shortcut definitions */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -070038/***********************************************************/
39
Eilon Greenstein2f904462009-08-12 08:22:16 +000040#define NIG_LATCH_BC_ENABLE_MI_INT 0
41
42#define NIG_STATUS_EMAC0_MI_INT \
43 NIG_STATUS_INTERRUPT_PORT0_REG_STATUS_EMAC0_MISC_MI_INT
Yaniv Rosnerea4e0402008-06-23 20:27:26 -070044#define NIG_STATUS_XGXS0_LINK10G \
45 NIG_STATUS_INTERRUPT_PORT0_REG_STATUS_XGXS0_LINK10G
46#define NIG_STATUS_XGXS0_LINK_STATUS \
47 NIG_STATUS_INTERRUPT_PORT0_REG_STATUS_XGXS0_LINK_STATUS
48#define NIG_STATUS_XGXS0_LINK_STATUS_SIZE \
49 NIG_STATUS_INTERRUPT_PORT0_REG_STATUS_XGXS0_LINK_STATUS_SIZE
50#define NIG_STATUS_SERDES0_LINK_STATUS \
51 NIG_STATUS_INTERRUPT_PORT0_REG_STATUS_SERDES0_LINK_STATUS
52#define NIG_MASK_MI_INT \
53 NIG_MASK_INTERRUPT_PORT0_REG_MASK_EMAC0_MISC_MI_INT
54#define NIG_MASK_XGXS0_LINK10G \
55 NIG_MASK_INTERRUPT_PORT0_REG_MASK_XGXS0_LINK10G
56#define NIG_MASK_XGXS0_LINK_STATUS \
57 NIG_MASK_INTERRUPT_PORT0_REG_MASK_XGXS0_LINK_STATUS
58#define NIG_MASK_SERDES0_LINK_STATUS \
59 NIG_MASK_INTERRUPT_PORT0_REG_MASK_SERDES0_LINK_STATUS
60
61#define MDIO_AN_CL73_OR_37_COMPLETE \
62 (MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_AUTONEG_COMPLETE | \
63 MDIO_GP_STATUS_TOP_AN_STATUS1_CL37_AUTONEG_COMPLETE)
64
65#define XGXS_RESET_BITS \
66 (MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_XGXS0_RSTB_HW | \
67 MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_XGXS0_IDDQ | \
68 MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_XGXS0_PWRDWN | \
69 MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_XGXS0_PWRDWN_SD | \
70 MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_XGXS0_TXD_FIFO_RSTB)
71
72#define SERDES_RESET_BITS \
73 (MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_SERDES0_RSTB_HW | \
74 MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_SERDES0_IDDQ | \
75 MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_SERDES0_PWRDWN | \
76 MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_SERDES0_PWRDWN_SD)
77
78#define AUTONEG_CL37 SHARED_HW_CFG_AN_ENABLE_CL37
79#define AUTONEG_CL73 SHARED_HW_CFG_AN_ENABLE_CL73
Eilon Greenstein3196a882008-08-13 15:58:49 -070080#define AUTONEG_BAM SHARED_HW_CFG_AN_ENABLE_BAM
81#define AUTONEG_PARALLEL \
Yaniv Rosnerea4e0402008-06-23 20:27:26 -070082 SHARED_HW_CFG_AN_ENABLE_PARALLEL_DETECTION
Eilon Greenstein3196a882008-08-13 15:58:49 -070083#define AUTONEG_SGMII_FIBER_AUTODET \
Yaniv Rosnerea4e0402008-06-23 20:27:26 -070084 SHARED_HW_CFG_AN_EN_SGMII_FIBER_AUTO_DETECT
Eilon Greenstein3196a882008-08-13 15:58:49 -070085#define AUTONEG_REMOTE_PHY SHARED_HW_CFG_AN_ENABLE_REMOTE_PHY
Yaniv Rosnerea4e0402008-06-23 20:27:26 -070086
87#define GP_STATUS_PAUSE_RSOLUTION_TXSIDE \
88 MDIO_GP_STATUS_TOP_AN_STATUS1_PAUSE_RSOLUTION_TXSIDE
89#define GP_STATUS_PAUSE_RSOLUTION_RXSIDE \
90 MDIO_GP_STATUS_TOP_AN_STATUS1_PAUSE_RSOLUTION_RXSIDE
91#define GP_STATUS_SPEED_MASK \
92 MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_MASK
93#define GP_STATUS_10M MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10M
94#define GP_STATUS_100M MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_100M
95#define GP_STATUS_1G MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_1G
96#define GP_STATUS_2_5G MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_2_5G
97#define GP_STATUS_5G MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_5G
98#define GP_STATUS_6G MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_6G
99#define GP_STATUS_10G_HIG \
100 MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10G_HIG
101#define GP_STATUS_10G_CX4 \
102 MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10G_CX4
103#define GP_STATUS_12G_HIG \
104 MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_12G_HIG
105#define GP_STATUS_12_5G MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_12_5G
106#define GP_STATUS_13G MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_13G
107#define GP_STATUS_15G MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_15G
108#define GP_STATUS_16G MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_16G
109#define GP_STATUS_1G_KX MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_1G_KX
110#define GP_STATUS_10G_KX4 \
111 MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10G_KX4
112
113#define LINK_10THD LINK_STATUS_SPEED_AND_DUPLEX_10THD
114#define LINK_10TFD LINK_STATUS_SPEED_AND_DUPLEX_10TFD
115#define LINK_100TXHD LINK_STATUS_SPEED_AND_DUPLEX_100TXHD
116#define LINK_100T4 LINK_STATUS_SPEED_AND_DUPLEX_100T4
117#define LINK_100TXFD LINK_STATUS_SPEED_AND_DUPLEX_100TXFD
118#define LINK_1000THD LINK_STATUS_SPEED_AND_DUPLEX_1000THD
119#define LINK_1000TFD LINK_STATUS_SPEED_AND_DUPLEX_1000TFD
120#define LINK_1000XFD LINK_STATUS_SPEED_AND_DUPLEX_1000XFD
121#define LINK_2500THD LINK_STATUS_SPEED_AND_DUPLEX_2500THD
122#define LINK_2500TFD LINK_STATUS_SPEED_AND_DUPLEX_2500TFD
123#define LINK_2500XFD LINK_STATUS_SPEED_AND_DUPLEX_2500XFD
124#define LINK_10GTFD LINK_STATUS_SPEED_AND_DUPLEX_10GTFD
125#define LINK_10GXFD LINK_STATUS_SPEED_AND_DUPLEX_10GXFD
126#define LINK_12GTFD LINK_STATUS_SPEED_AND_DUPLEX_12GTFD
127#define LINK_12GXFD LINK_STATUS_SPEED_AND_DUPLEX_12GXFD
128#define LINK_12_5GTFD LINK_STATUS_SPEED_AND_DUPLEX_12_5GTFD
129#define LINK_12_5GXFD LINK_STATUS_SPEED_AND_DUPLEX_12_5GXFD
130#define LINK_13GTFD LINK_STATUS_SPEED_AND_DUPLEX_13GTFD
131#define LINK_13GXFD LINK_STATUS_SPEED_AND_DUPLEX_13GXFD
132#define LINK_15GTFD LINK_STATUS_SPEED_AND_DUPLEX_15GTFD
133#define LINK_15GXFD LINK_STATUS_SPEED_AND_DUPLEX_15GXFD
134#define LINK_16GTFD LINK_STATUS_SPEED_AND_DUPLEX_16GTFD
135#define LINK_16GXFD LINK_STATUS_SPEED_AND_DUPLEX_16GXFD
136
137#define PHY_XGXS_FLAG 0x1
138#define PHY_SGMII_FLAG 0x2
139#define PHY_SERDES_FLAG 0x4
140
Eilon Greenstein589abe32009-02-12 08:36:55 +0000141/* */
142#define SFP_EEPROM_CON_TYPE_ADDR 0x2
143 #define SFP_EEPROM_CON_TYPE_VAL_LC 0x7
144 #define SFP_EEPROM_CON_TYPE_VAL_COPPER 0x21
145
Eilon Greenstein4d295db2009-07-21 05:47:47 +0000146
147#define SFP_EEPROM_COMP_CODE_ADDR 0x3
148 #define SFP_EEPROM_COMP_CODE_SR_MASK (1<<4)
149 #define SFP_EEPROM_COMP_CODE_LR_MASK (1<<5)
150 #define SFP_EEPROM_COMP_CODE_LRM_MASK (1<<6)
151
Eilon Greenstein589abe32009-02-12 08:36:55 +0000152#define SFP_EEPROM_FC_TX_TECH_ADDR 0x8
153 #define SFP_EEPROM_FC_TX_TECH_BITMASK_COPPER_PASSIVE 0x4
154 #define SFP_EEPROM_FC_TX_TECH_BITMASK_COPPER_ACTIVE 0x8
Eilon Greenstein4d295db2009-07-21 05:47:47 +0000155
Eilon Greenstein589abe32009-02-12 08:36:55 +0000156#define SFP_EEPROM_OPTIONS_ADDR 0x40
157 #define SFP_EEPROM_OPTIONS_LINEAR_RX_OUT_MASK 0x1
158#define SFP_EEPROM_OPTIONS_SIZE 2
159
Eilon Greenstein4d295db2009-07-21 05:47:47 +0000160#define EDC_MODE_LINEAR 0x0022
161#define EDC_MODE_LIMITING 0x0044
162#define EDC_MODE_PASSIVE_DAC 0x0055
Eilon Greenstein589abe32009-02-12 08:36:55 +0000163
Eilon Greenstein4d295db2009-07-21 05:47:47 +0000164
165
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700166/**********************************************************/
167/* INTERFACE */
168/**********************************************************/
169#define CL45_WR_OVER_CL22(_bp, _port, _phy_addr, _bank, _addr, _val) \
170 bnx2x_cl45_write(_bp, _port, 0, _phy_addr, \
171 DEFAULT_PHY_DEV_ADDR, \
172 (_bank + (_addr & 0xf)), \
173 _val)
174
175#define CL45_RD_OVER_CL22(_bp, _port, _phy_addr, _bank, _addr, _val) \
176 bnx2x_cl45_read(_bp, _port, 0, _phy_addr, \
177 DEFAULT_PHY_DEV_ADDR, \
178 (_bank + (_addr & 0xf)), \
179 _val)
180
Eilon Greensteinc1b73992009-02-12 08:37:07 +0000181static void bnx2x_set_serdes_access(struct link_params *params)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700182{
183 struct bnx2x *bp = params->bp;
Eilon Greensteinc1b73992009-02-12 08:37:07 +0000184 u32 emac_base = (params->port) ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +0000185
Eilon Greensteinc1b73992009-02-12 08:37:07 +0000186 /* Set Clause 22 */
187 REG_WR(bp, NIG_REG_SERDES0_CTRL_MD_ST + params->port*0x10, 1);
188 REG_WR(bp, emac_base + EMAC_REG_EMAC_MDIO_COMM, 0x245f8000);
189 udelay(500);
190 REG_WR(bp, emac_base + EMAC_REG_EMAC_MDIO_COMM, 0x245d000f);
191 udelay(500);
192 /* Set Clause 45 */
193 REG_WR(bp, NIG_REG_SERDES0_CTRL_MD_ST + params->port*0x10, 0);
194}
195static void bnx2x_set_phy_mdio(struct link_params *params, u8 phy_flags)
196{
197 struct bnx2x *bp = params->bp;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +0000198
Eilon Greensteinc1b73992009-02-12 08:37:07 +0000199 if (phy_flags & PHY_XGXS_FLAG) {
200 REG_WR(bp, NIG_REG_XGXS0_CTRL_MD_ST +
201 params->port*0x18, 0);
202 REG_WR(bp, NIG_REG_XGXS0_CTRL_MD_DEVAD + params->port*0x18,
203 DEFAULT_PHY_DEV_ADDR);
204 } else {
205 bnx2x_set_serdes_access(params);
206
207 REG_WR(bp, NIG_REG_SERDES0_CTRL_MD_DEVAD +
208 params->port*0x10,
209 DEFAULT_PHY_DEV_ADDR);
210 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700211}
212
213static u32 bnx2x_bits_en(struct bnx2x *bp, u32 reg, u32 bits)
214{
215 u32 val = REG_RD(bp, reg);
216
217 val |= bits;
218 REG_WR(bp, reg, val);
219 return val;
220}
221
222static u32 bnx2x_bits_dis(struct bnx2x *bp, u32 reg, u32 bits)
223{
224 u32 val = REG_RD(bp, reg);
225
226 val &= ~bits;
227 REG_WR(bp, reg, val);
228 return val;
229}
230
231static void bnx2x_emac_init(struct link_params *params,
232 struct link_vars *vars)
233{
234 /* reset and unreset the emac core */
235 struct bnx2x *bp = params->bp;
236 u8 port = params->port;
237 u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
238 u32 val;
239 u16 timeout;
240
241 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
242 (MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE << port));
243 udelay(5);
244 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
245 (MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE << port));
246
247 /* init emac - use read-modify-write */
248 /* self clear reset */
249 val = REG_RD(bp, emac_base + EMAC_REG_EMAC_MODE);
Eilon Greenstein3196a882008-08-13 15:58:49 -0700250 EMAC_WR(bp, EMAC_REG_EMAC_MODE, (val | EMAC_MODE_RESET));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700251
252 timeout = 200;
Eilon Greenstein3196a882008-08-13 15:58:49 -0700253 do {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700254 val = REG_RD(bp, emac_base + EMAC_REG_EMAC_MODE);
255 DP(NETIF_MSG_LINK, "EMAC reset reg is %u\n", val);
256 if (!timeout) {
257 DP(NETIF_MSG_LINK, "EMAC timeout!\n");
258 return;
259 }
260 timeout--;
Eilon Greenstein3196a882008-08-13 15:58:49 -0700261 } while (val & EMAC_MODE_RESET);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700262
263 /* Set mac address */
264 val = ((params->mac_addr[0] << 8) |
265 params->mac_addr[1]);
Eilon Greenstein3196a882008-08-13 15:58:49 -0700266 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700267
268 val = ((params->mac_addr[2] << 24) |
269 (params->mac_addr[3] << 16) |
270 (params->mac_addr[4] << 8) |
271 params->mac_addr[5]);
Eilon Greenstein3196a882008-08-13 15:58:49 -0700272 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + 4, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700273}
274
275static u8 bnx2x_emac_enable(struct link_params *params,
276 struct link_vars *vars, u8 lb)
277{
278 struct bnx2x *bp = params->bp;
279 u8 port = params->port;
280 u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
281 u32 val;
282
283 DP(NETIF_MSG_LINK, "enabling EMAC\n");
284
285 /* enable emac and not bmac */
286 REG_WR(bp, NIG_REG_EGRESS_EMAC0_PORT + port*4, 1);
287
288 /* for paladium */
289 if (CHIP_REV_IS_EMUL(bp)) {
290 /* Use lane 1 (of lanes 0-3) */
291 REG_WR(bp, NIG_REG_XGXS_LANE_SEL_P0 + port*4, 1);
292 REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL +
293 port*4, 1);
294 }
295 /* for fpga */
296 else
297
298 if (CHIP_REV_IS_FPGA(bp)) {
299 /* Use lane 1 (of lanes 0-3) */
300 DP(NETIF_MSG_LINK, "bnx2x_emac_enable: Setting FPGA\n");
301
302 REG_WR(bp, NIG_REG_XGXS_LANE_SEL_P0 + port*4, 1);
303 REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4,
304 0);
305 } else
306 /* ASIC */
307 if (vars->phy_flags & PHY_XGXS_FLAG) {
308 u32 ser_lane = ((params->lane_config &
309 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_MASK) >>
310 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_SHIFT);
311
312 DP(NETIF_MSG_LINK, "XGXS\n");
313 /* select the master lanes (out of 0-3) */
314 REG_WR(bp, NIG_REG_XGXS_LANE_SEL_P0 +
315 port*4, ser_lane);
316 /* select XGXS */
317 REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL +
318 port*4, 1);
319
320 } else { /* SerDes */
321 DP(NETIF_MSG_LINK, "SerDes\n");
322 /* select SerDes */
323 REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL +
324 port*4, 0);
325 }
326
Eilon Greenstein811a2f22009-02-12 08:37:04 +0000327 bnx2x_bits_en(bp, emac_base + EMAC_REG_EMAC_RX_MODE,
328 EMAC_RX_MODE_RESET);
329 bnx2x_bits_en(bp, emac_base + EMAC_REG_EMAC_TX_MODE,
330 EMAC_TX_MODE_RESET);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700331
332 if (CHIP_REV_IS_SLOW(bp)) {
333 /* config GMII mode */
334 val = REG_RD(bp, emac_base + EMAC_REG_EMAC_MODE);
Eilon Greenstein3196a882008-08-13 15:58:49 -0700335 EMAC_WR(bp, EMAC_REG_EMAC_MODE,
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700336 (val | EMAC_MODE_PORT_GMII));
337 } else { /* ASIC */
338 /* pause enable/disable */
339 bnx2x_bits_dis(bp, emac_base + EMAC_REG_EMAC_RX_MODE,
340 EMAC_RX_MODE_FLOW_EN);
David S. Millerc0700f92008-12-16 23:53:20 -0800341 if (vars->flow_ctrl & BNX2X_FLOW_CTRL_RX)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700342 bnx2x_bits_en(bp, emac_base +
343 EMAC_REG_EMAC_RX_MODE,
344 EMAC_RX_MODE_FLOW_EN);
345
346 bnx2x_bits_dis(bp, emac_base + EMAC_REG_EMAC_TX_MODE,
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -0700347 (EMAC_TX_MODE_EXT_PAUSE_EN |
348 EMAC_TX_MODE_FLOW_EN));
David S. Millerc0700f92008-12-16 23:53:20 -0800349 if (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700350 bnx2x_bits_en(bp, emac_base +
351 EMAC_REG_EMAC_TX_MODE,
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -0700352 (EMAC_TX_MODE_EXT_PAUSE_EN |
353 EMAC_TX_MODE_FLOW_EN));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700354 }
355
356 /* KEEP_VLAN_TAG, promiscuous */
357 val = REG_RD(bp, emac_base + EMAC_REG_EMAC_RX_MODE);
358 val |= EMAC_RX_MODE_KEEP_VLAN_TAG | EMAC_RX_MODE_PROMISCUOUS;
Eilon Greenstein3196a882008-08-13 15:58:49 -0700359 EMAC_WR(bp, EMAC_REG_EMAC_RX_MODE, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700360
361 /* Set Loopback */
362 val = REG_RD(bp, emac_base + EMAC_REG_EMAC_MODE);
363 if (lb)
364 val |= 0x810;
365 else
366 val &= ~0x810;
Eilon Greenstein3196a882008-08-13 15:58:49 -0700367 EMAC_WR(bp, EMAC_REG_EMAC_MODE, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700368
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +0000369 /* enable emac */
370 REG_WR(bp, NIG_REG_NIG_EMAC0_EN + port*4, 1);
371
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700372 /* enable emac for jumbo packets */
Eilon Greenstein3196a882008-08-13 15:58:49 -0700373 EMAC_WR(bp, EMAC_REG_EMAC_RX_MTU_SIZE,
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700374 (EMAC_RX_MTU_SIZE_JUMBO_ENA |
375 (ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD)));
376
377 /* strip CRC */
378 REG_WR(bp, NIG_REG_NIG_INGRESS_EMAC0_NO_CRC + port*4, 0x1);
379
380 /* disable the NIG in/out to the bmac */
381 REG_WR(bp, NIG_REG_BMAC0_IN_EN + port*4, 0x0);
382 REG_WR(bp, NIG_REG_BMAC0_PAUSE_OUT_EN + port*4, 0x0);
383 REG_WR(bp, NIG_REG_BMAC0_OUT_EN + port*4, 0x0);
384
385 /* enable the NIG in/out to the emac */
386 REG_WR(bp, NIG_REG_EMAC0_IN_EN + port*4, 0x1);
387 val = 0;
David S. Millerc0700f92008-12-16 23:53:20 -0800388 if (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700389 val = 1;
390
391 REG_WR(bp, NIG_REG_EMAC0_PAUSE_OUT_EN + port*4, val);
392 REG_WR(bp, NIG_REG_EGRESS_EMAC0_OUT_EN + port*4, 0x1);
393
394 if (CHIP_REV_IS_EMUL(bp)) {
395 /* take the BigMac out of reset */
396 REG_WR(bp,
397 GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
398 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port));
399
400 /* enable access for bmac registers */
401 REG_WR(bp, NIG_REG_BMAC0_REGS_OUT_EN + port*4, 0x1);
Eilon Greenstein6f654972009-08-12 08:23:51 +0000402 } else
403 REG_WR(bp, NIG_REG_BMAC0_REGS_OUT_EN + port*4, 0x0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700404
405 vars->mac_type = MAC_TYPE_EMAC;
406 return 0;
407}
408
409
410
411static u8 bnx2x_bmac_enable(struct link_params *params, struct link_vars *vars,
412 u8 is_lb)
413{
414 struct bnx2x *bp = params->bp;
415 u8 port = params->port;
416 u32 bmac_addr = port ? NIG_REG_INGRESS_BMAC1_MEM :
417 NIG_REG_INGRESS_BMAC0_MEM;
418 u32 wb_data[2];
419 u32 val;
420
421 DP(NETIF_MSG_LINK, "Enabling BigMAC\n");
422 /* reset and unreset the BigMac */
423 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
424 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port));
425 msleep(1);
426
427 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
428 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port));
429
430 /* enable access for bmac registers */
431 REG_WR(bp, NIG_REG_BMAC0_REGS_OUT_EN + port*4, 0x1);
432
433 /* XGXS control */
434 wb_data[0] = 0x3c;
435 wb_data[1] = 0;
436 REG_WR_DMAE(bp, bmac_addr +
437 BIGMAC_REGISTER_BMAC_XGXS_CONTROL,
438 wb_data, 2);
439
440 /* tx MAC SA */
441 wb_data[0] = ((params->mac_addr[2] << 24) |
442 (params->mac_addr[3] << 16) |
443 (params->mac_addr[4] << 8) |
444 params->mac_addr[5]);
445 wb_data[1] = ((params->mac_addr[0] << 8) |
446 params->mac_addr[1]);
447 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_TX_SOURCE_ADDR,
448 wb_data, 2);
449
450 /* tx control */
451 val = 0xc0;
David S. Millerc0700f92008-12-16 23:53:20 -0800452 if (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700453 val |= 0x800000;
454 wb_data[0] = val;
455 wb_data[1] = 0;
456 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_TX_CONTROL,
457 wb_data, 2);
458
459 /* mac control */
460 val = 0x3;
461 if (is_lb) {
462 val |= 0x4;
463 DP(NETIF_MSG_LINK, "enable bmac loopback\n");
464 }
465 wb_data[0] = val;
466 wb_data[1] = 0;
467 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_BMAC_CONTROL,
468 wb_data, 2);
469
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700470 /* set rx mtu */
471 wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD;
472 wb_data[1] = 0;
473 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_RX_MAX_SIZE,
474 wb_data, 2);
475
476 /* rx control set to don't strip crc */
477 val = 0x14;
David S. Millerc0700f92008-12-16 23:53:20 -0800478 if (vars->flow_ctrl & BNX2X_FLOW_CTRL_RX)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700479 val |= 0x20;
480 wb_data[0] = val;
481 wb_data[1] = 0;
482 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_RX_CONTROL,
483 wb_data, 2);
484
485 /* set tx mtu */
486 wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD;
487 wb_data[1] = 0;
488 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_TX_MAX_SIZE,
489 wb_data, 2);
490
491 /* set cnt max size */
492 wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD;
493 wb_data[1] = 0;
494 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_CNT_MAX_SIZE,
495 wb_data, 2);
496
497 /* configure safc */
498 wb_data[0] = 0x1000200;
499 wb_data[1] = 0;
500 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_RX_LLFC_MSG_FLDS,
501 wb_data, 2);
502 /* fix for emulation */
503 if (CHIP_REV_IS_EMUL(bp)) {
504 wb_data[0] = 0xf000;
505 wb_data[1] = 0;
506 REG_WR_DMAE(bp,
507 bmac_addr + BIGMAC_REGISTER_TX_PAUSE_THRESHOLD,
508 wb_data, 2);
509 }
510
511 REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 0x1);
512 REG_WR(bp, NIG_REG_XGXS_LANE_SEL_P0 + port*4, 0x0);
513 REG_WR(bp, NIG_REG_EGRESS_EMAC0_PORT + port*4, 0x0);
514 val = 0;
David S. Millerc0700f92008-12-16 23:53:20 -0800515 if (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700516 val = 1;
517 REG_WR(bp, NIG_REG_BMAC0_PAUSE_OUT_EN + port*4, val);
518 REG_WR(bp, NIG_REG_EGRESS_EMAC0_OUT_EN + port*4, 0x0);
519 REG_WR(bp, NIG_REG_EMAC0_IN_EN + port*4, 0x0);
520 REG_WR(bp, NIG_REG_EMAC0_PAUSE_OUT_EN + port*4, 0x0);
521 REG_WR(bp, NIG_REG_BMAC0_IN_EN + port*4, 0x1);
522 REG_WR(bp, NIG_REG_BMAC0_OUT_EN + port*4, 0x1);
523
524 vars->mac_type = MAC_TYPE_BMAC;
525 return 0;
526}
527
528static void bnx2x_phy_deassert(struct link_params *params, u8 phy_flags)
529{
530 struct bnx2x *bp = params->bp;
531 u32 val;
532
533 if (phy_flags & PHY_XGXS_FLAG) {
534 DP(NETIF_MSG_LINK, "bnx2x_phy_deassert:XGXS\n");
535 val = XGXS_RESET_BITS;
536
537 } else { /* SerDes */
538 DP(NETIF_MSG_LINK, "bnx2x_phy_deassert:SerDes\n");
539 val = SERDES_RESET_BITS;
540 }
541
542 val = val << (params->port*16);
543
544 /* reset and unreset the SerDes/XGXS */
545 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_CLEAR,
546 val);
547 udelay(500);
548 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_SET,
549 val);
Eilon Greensteinc1b73992009-02-12 08:37:07 +0000550 bnx2x_set_phy_mdio(params, phy_flags);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700551}
552
553void bnx2x_link_status_update(struct link_params *params,
554 struct link_vars *vars)
555{
556 struct bnx2x *bp = params->bp;
557 u8 link_10g;
558 u8 port = params->port;
559
560 if (params->switch_cfg == SWITCH_CFG_1G)
561 vars->phy_flags = PHY_SERDES_FLAG;
562 else
563 vars->phy_flags = PHY_XGXS_FLAG;
564 vars->link_status = REG_RD(bp, params->shmem_base +
565 offsetof(struct shmem_region,
566 port_mb[port].link_status));
567
568 vars->link_up = (vars->link_status & LINK_STATUS_LINK_UP);
569
570 if (vars->link_up) {
571 DP(NETIF_MSG_LINK, "phy link up\n");
572
573 vars->phy_link_up = 1;
574 vars->duplex = DUPLEX_FULL;
575 switch (vars->link_status &
576 LINK_STATUS_SPEED_AND_DUPLEX_MASK) {
577 case LINK_10THD:
578 vars->duplex = DUPLEX_HALF;
579 /* fall thru */
580 case LINK_10TFD:
581 vars->line_speed = SPEED_10;
582 break;
583
584 case LINK_100TXHD:
585 vars->duplex = DUPLEX_HALF;
586 /* fall thru */
587 case LINK_100T4:
588 case LINK_100TXFD:
589 vars->line_speed = SPEED_100;
590 break;
591
592 case LINK_1000THD:
593 vars->duplex = DUPLEX_HALF;
594 /* fall thru */
595 case LINK_1000TFD:
596 vars->line_speed = SPEED_1000;
597 break;
598
599 case LINK_2500THD:
600 vars->duplex = DUPLEX_HALF;
601 /* fall thru */
602 case LINK_2500TFD:
603 vars->line_speed = SPEED_2500;
604 break;
605
606 case LINK_10GTFD:
607 vars->line_speed = SPEED_10000;
608 break;
609
610 case LINK_12GTFD:
611 vars->line_speed = SPEED_12000;
612 break;
613
614 case LINK_12_5GTFD:
615 vars->line_speed = SPEED_12500;
616 break;
617
618 case LINK_13GTFD:
619 vars->line_speed = SPEED_13000;
620 break;
621
622 case LINK_15GTFD:
623 vars->line_speed = SPEED_15000;
624 break;
625
626 case LINK_16GTFD:
627 vars->line_speed = SPEED_16000;
628 break;
629
630 default:
631 break;
632 }
633
634 if (vars->link_status & LINK_STATUS_TX_FLOW_CONTROL_ENABLED)
David S. Millerc0700f92008-12-16 23:53:20 -0800635 vars->flow_ctrl |= BNX2X_FLOW_CTRL_TX;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700636 else
David S. Millerc0700f92008-12-16 23:53:20 -0800637 vars->flow_ctrl &= ~BNX2X_FLOW_CTRL_TX;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700638
639 if (vars->link_status & LINK_STATUS_RX_FLOW_CONTROL_ENABLED)
David S. Millerc0700f92008-12-16 23:53:20 -0800640 vars->flow_ctrl |= BNX2X_FLOW_CTRL_RX;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700641 else
David S. Millerc0700f92008-12-16 23:53:20 -0800642 vars->flow_ctrl &= ~BNX2X_FLOW_CTRL_RX;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700643
644 if (vars->phy_flags & PHY_XGXS_FLAG) {
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -0700645 if (vars->line_speed &&
646 ((vars->line_speed == SPEED_10) ||
647 (vars->line_speed == SPEED_100))) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700648 vars->phy_flags |= PHY_SGMII_FLAG;
649 } else {
650 vars->phy_flags &= ~PHY_SGMII_FLAG;
651 }
652 }
653
654 /* anything 10 and over uses the bmac */
655 link_10g = ((vars->line_speed == SPEED_10000) ||
656 (vars->line_speed == SPEED_12000) ||
657 (vars->line_speed == SPEED_12500) ||
658 (vars->line_speed == SPEED_13000) ||
659 (vars->line_speed == SPEED_15000) ||
660 (vars->line_speed == SPEED_16000));
661 if (link_10g)
662 vars->mac_type = MAC_TYPE_BMAC;
663 else
664 vars->mac_type = MAC_TYPE_EMAC;
665
666 } else { /* link down */
667 DP(NETIF_MSG_LINK, "phy link down\n");
668
669 vars->phy_link_up = 0;
670
671 vars->line_speed = 0;
672 vars->duplex = DUPLEX_FULL;
David S. Millerc0700f92008-12-16 23:53:20 -0800673 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700674
675 /* indicate no mac active */
676 vars->mac_type = MAC_TYPE_NONE;
677 }
678
679 DP(NETIF_MSG_LINK, "link_status 0x%x phy_link_up %x\n",
680 vars->link_status, vars->phy_link_up);
681 DP(NETIF_MSG_LINK, "line_speed %x duplex %x flow_ctrl 0x%x\n",
682 vars->line_speed, vars->duplex, vars->flow_ctrl);
683}
684
685static void bnx2x_update_mng(struct link_params *params, u32 link_status)
686{
687 struct bnx2x *bp = params->bp;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +0000688
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700689 REG_WR(bp, params->shmem_base +
690 offsetof(struct shmem_region,
691 port_mb[params->port].link_status),
692 link_status);
693}
694
695static void bnx2x_bmac_rx_disable(struct bnx2x *bp, u8 port)
696{
697 u32 bmac_addr = port ? NIG_REG_INGRESS_BMAC1_MEM :
698 NIG_REG_INGRESS_BMAC0_MEM;
699 u32 wb_data[2];
Eilon Greenstein3196a882008-08-13 15:58:49 -0700700 u32 nig_bmac_enable = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port*4);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700701
702 /* Only if the bmac is out of reset */
703 if (REG_RD(bp, MISC_REG_RESET_REG_2) &
704 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port) &&
705 nig_bmac_enable) {
706
707 /* Clear Rx Enable bit in BMAC_CONTROL register */
708 REG_RD_DMAE(bp, bmac_addr + BIGMAC_REGISTER_BMAC_CONTROL,
709 wb_data, 2);
710 wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
711 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_BMAC_CONTROL,
712 wb_data, 2);
713
714 msleep(1);
715 }
716}
717
718static u8 bnx2x_pbf_update(struct link_params *params, u32 flow_ctrl,
719 u32 line_speed)
720{
721 struct bnx2x *bp = params->bp;
722 u8 port = params->port;
723 u32 init_crd, crd;
724 u32 count = 1000;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700725
726 /* disable port */
727 REG_WR(bp, PBF_REG_DISABLE_NEW_TASK_PROC_P0 + port*4, 0x1);
728
729 /* wait for init credit */
730 init_crd = REG_RD(bp, PBF_REG_P0_INIT_CRD + port*4);
731 crd = REG_RD(bp, PBF_REG_P0_CREDIT + port*8);
732 DP(NETIF_MSG_LINK, "init_crd 0x%x crd 0x%x\n", init_crd, crd);
733
734 while ((init_crd != crd) && count) {
735 msleep(5);
736
737 crd = REG_RD(bp, PBF_REG_P0_CREDIT + port*8);
738 count--;
739 }
740 crd = REG_RD(bp, PBF_REG_P0_CREDIT + port*8);
741 if (init_crd != crd) {
742 DP(NETIF_MSG_LINK, "BUG! init_crd 0x%x != crd 0x%x\n",
743 init_crd, crd);
744 return -EINVAL;
745 }
746
David S. Millerc0700f92008-12-16 23:53:20 -0800747 if (flow_ctrl & BNX2X_FLOW_CTRL_RX ||
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -0700748 line_speed == SPEED_10 ||
749 line_speed == SPEED_100 ||
750 line_speed == SPEED_1000 ||
751 line_speed == SPEED_2500) {
752 REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 1);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700753 /* update threshold */
754 REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, 0);
755 /* update init credit */
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -0700756 init_crd = 778; /* (800-18-4) */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700757
758 } else {
759 u32 thresh = (ETH_MAX_JUMBO_PACKET_SIZE +
760 ETH_OVREHEAD)/16;
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -0700761 REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700762 /* update threshold */
763 REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, thresh);
764 /* update init credit */
765 switch (line_speed) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700766 case SPEED_10000:
767 init_crd = thresh + 553 - 22;
768 break;
769
770 case SPEED_12000:
771 init_crd = thresh + 664 - 22;
772 break;
773
774 case SPEED_13000:
775 init_crd = thresh + 742 - 22;
776 break;
777
778 case SPEED_16000:
779 init_crd = thresh + 778 - 22;
780 break;
781 default:
782 DP(NETIF_MSG_LINK, "Invalid line_speed 0x%x\n",
783 line_speed);
784 return -EINVAL;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700785 }
786 }
787 REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, init_crd);
788 DP(NETIF_MSG_LINK, "PBF updated to speed %d credit %d\n",
789 line_speed, init_crd);
790
791 /* probe the credit changes */
792 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0x1);
793 msleep(5);
794 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0x0);
795
796 /* enable port */
797 REG_WR(bp, PBF_REG_DISABLE_NEW_TASK_PROC_P0 + port*4, 0x0);
798 return 0;
799}
800
Eilon Greenstein589abe32009-02-12 08:36:55 +0000801static u32 bnx2x_get_emac_base(struct bnx2x *bp, u32 ext_phy_type, u8 port)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700802{
803 u32 emac_base;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +0000804
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700805 switch (ext_phy_type) {
806 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8072:
Eilon Greenstein589abe32009-02-12 08:36:55 +0000807 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
Eilon Greenstein4d295db2009-07-21 05:47:47 +0000808 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
Eilon Greenstein589abe32009-02-12 08:36:55 +0000809 /* All MDC/MDIO is directed through single EMAC */
810 if (REG_RD(bp, NIG_REG_PORT_SWAP))
811 emac_base = GRCBASE_EMAC0;
812 else
813 emac_base = GRCBASE_EMAC1;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700814 break;
815 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073:
Eilon Greenstein6378c022008-08-13 15:59:25 -0700816 emac_base = (port) ? GRCBASE_EMAC0 : GRCBASE_EMAC1;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700817 break;
818 default:
Eilon Greenstein6378c022008-08-13 15:59:25 -0700819 emac_base = (port) ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700820 break;
821 }
822 return emac_base;
823
824}
825
826u8 bnx2x_cl45_write(struct bnx2x *bp, u8 port, u32 ext_phy_type,
827 u8 phy_addr, u8 devad, u16 reg, u16 val)
828{
829 u32 tmp, saved_mode;
830 u8 i, rc = 0;
Eilon Greenstein589abe32009-02-12 08:36:55 +0000831 u32 mdio_ctrl = bnx2x_get_emac_base(bp, ext_phy_type, port);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700832
833 /* set clause 45 mode, slow down the MDIO clock to 2.5MHz
834 * (a value of 49==0x31) and make sure that the AUTO poll is off
835 */
Eilon Greenstein589abe32009-02-12 08:36:55 +0000836
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700837 saved_mode = REG_RD(bp, mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE);
838 tmp = saved_mode & ~(EMAC_MDIO_MODE_AUTO_POLL |
839 EMAC_MDIO_MODE_CLOCK_CNT);
840 tmp |= (EMAC_MDIO_MODE_CLAUSE_45 |
841 (49 << EMAC_MDIO_MODE_CLOCK_CNT_BITSHIFT));
842 REG_WR(bp, mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE, tmp);
843 REG_RD(bp, mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE);
844 udelay(40);
845
846 /* address */
847
848 tmp = ((phy_addr << 21) | (devad << 16) | reg |
849 EMAC_MDIO_COMM_COMMAND_ADDRESS |
850 EMAC_MDIO_COMM_START_BUSY);
851 REG_WR(bp, mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, tmp);
852
853 for (i = 0; i < 50; i++) {
854 udelay(10);
855
856 tmp = REG_RD(bp, mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM);
857 if (!(tmp & EMAC_MDIO_COMM_START_BUSY)) {
858 udelay(5);
859 break;
860 }
861 }
862 if (tmp & EMAC_MDIO_COMM_START_BUSY) {
863 DP(NETIF_MSG_LINK, "write phy register failed\n");
864 rc = -EFAULT;
865 } else {
866 /* data */
867 tmp = ((phy_addr << 21) | (devad << 16) | val |
868 EMAC_MDIO_COMM_COMMAND_WRITE_45 |
869 EMAC_MDIO_COMM_START_BUSY);
870 REG_WR(bp, mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, tmp);
871
872 for (i = 0; i < 50; i++) {
873 udelay(10);
874
875 tmp = REG_RD(bp, mdio_ctrl +
876 EMAC_REG_EMAC_MDIO_COMM);
877 if (!(tmp & EMAC_MDIO_COMM_START_BUSY)) {
878 udelay(5);
879 break;
880 }
881 }
882 if (tmp & EMAC_MDIO_COMM_START_BUSY) {
883 DP(NETIF_MSG_LINK, "write phy register failed\n");
884 rc = -EFAULT;
885 }
886 }
887
888 /* Restore the saved mode */
889 REG_WR(bp, mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE, saved_mode);
890
891 return rc;
892}
893
894u8 bnx2x_cl45_read(struct bnx2x *bp, u8 port, u32 ext_phy_type,
895 u8 phy_addr, u8 devad, u16 reg, u16 *ret_val)
896{
897 u32 val, saved_mode;
898 u16 i;
899 u8 rc = 0;
900
Eilon Greenstein589abe32009-02-12 08:36:55 +0000901 u32 mdio_ctrl = bnx2x_get_emac_base(bp, ext_phy_type, port);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700902 /* set clause 45 mode, slow down the MDIO clock to 2.5MHz
903 * (a value of 49==0x31) and make sure that the AUTO poll is off
904 */
Eilon Greenstein589abe32009-02-12 08:36:55 +0000905
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700906 saved_mode = REG_RD(bp, mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE);
907 val = saved_mode & ((EMAC_MDIO_MODE_AUTO_POLL |
908 EMAC_MDIO_MODE_CLOCK_CNT));
909 val |= (EMAC_MDIO_MODE_CLAUSE_45 |
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +0000910 (49L << EMAC_MDIO_MODE_CLOCK_CNT_BITSHIFT));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700911 REG_WR(bp, mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE, val);
912 REG_RD(bp, mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE);
913 udelay(40);
914
915 /* address */
916 val = ((phy_addr << 21) | (devad << 16) | reg |
917 EMAC_MDIO_COMM_COMMAND_ADDRESS |
918 EMAC_MDIO_COMM_START_BUSY);
919 REG_WR(bp, mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, val);
920
921 for (i = 0; i < 50; i++) {
922 udelay(10);
923
924 val = REG_RD(bp, mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM);
925 if (!(val & EMAC_MDIO_COMM_START_BUSY)) {
926 udelay(5);
927 break;
928 }
929 }
930 if (val & EMAC_MDIO_COMM_START_BUSY) {
931 DP(NETIF_MSG_LINK, "read phy register failed\n");
932
933 *ret_val = 0;
934 rc = -EFAULT;
935
936 } else {
937 /* data */
938 val = ((phy_addr << 21) | (devad << 16) |
939 EMAC_MDIO_COMM_COMMAND_READ_45 |
940 EMAC_MDIO_COMM_START_BUSY);
941 REG_WR(bp, mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, val);
942
943 for (i = 0; i < 50; i++) {
944 udelay(10);
945
946 val = REG_RD(bp, mdio_ctrl +
947 EMAC_REG_EMAC_MDIO_COMM);
948 if (!(val & EMAC_MDIO_COMM_START_BUSY)) {
949 *ret_val = (u16)(val & EMAC_MDIO_COMM_DATA);
950 break;
951 }
952 }
953 if (val & EMAC_MDIO_COMM_START_BUSY) {
954 DP(NETIF_MSG_LINK, "read phy register failed\n");
955
956 *ret_val = 0;
957 rc = -EFAULT;
958 }
959 }
960
961 /* Restore the saved mode */
962 REG_WR(bp, mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE, saved_mode);
963
964 return rc;
965}
966
967static void bnx2x_set_aer_mmd(struct link_params *params,
968 struct link_vars *vars)
969{
970 struct bnx2x *bp = params->bp;
971 u32 ser_lane;
972 u16 offset;
973
974 ser_lane = ((params->lane_config &
975 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_MASK) >>
976 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_SHIFT);
977
978 offset = (vars->phy_flags & PHY_XGXS_FLAG) ?
979 (params->phy_addr + ser_lane) : 0;
980
981 CL45_WR_OVER_CL22(bp, params->port,
982 params->phy_addr,
983 MDIO_REG_BANK_AER_BLOCK,
984 MDIO_AER_BLOCK_AER_REG, 0x3800 + offset);
985}
986
987static void bnx2x_set_master_ln(struct link_params *params)
988{
989 struct bnx2x *bp = params->bp;
990 u16 new_master_ln, ser_lane;
991 ser_lane = ((params->lane_config &
992 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_MASK) >>
993 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_SHIFT);
994
995 /* set the master_ln for AN */
996 CL45_RD_OVER_CL22(bp, params->port,
997 params->phy_addr,
998 MDIO_REG_BANK_XGXS_BLOCK2,
999 MDIO_XGXS_BLOCK2_TEST_MODE_LANE,
1000 &new_master_ln);
1001
1002 CL45_WR_OVER_CL22(bp, params->port,
1003 params->phy_addr,
1004 MDIO_REG_BANK_XGXS_BLOCK2 ,
1005 MDIO_XGXS_BLOCK2_TEST_MODE_LANE,
1006 (new_master_ln | ser_lane));
1007}
1008
1009static u8 bnx2x_reset_unicore(struct link_params *params)
1010{
1011 struct bnx2x *bp = params->bp;
1012 u16 mii_control;
1013 u16 i;
1014
1015 CL45_RD_OVER_CL22(bp, params->port,
1016 params->phy_addr,
1017 MDIO_REG_BANK_COMBO_IEEE0,
1018 MDIO_COMBO_IEEE0_MII_CONTROL, &mii_control);
1019
1020 /* reset the unicore */
1021 CL45_WR_OVER_CL22(bp, params->port,
1022 params->phy_addr,
1023 MDIO_REG_BANK_COMBO_IEEE0,
1024 MDIO_COMBO_IEEE0_MII_CONTROL,
1025 (mii_control |
1026 MDIO_COMBO_IEEO_MII_CONTROL_RESET));
Eilon Greenstein6f654972009-08-12 08:23:51 +00001027 if (params->switch_cfg == SWITCH_CFG_1G)
1028 bnx2x_set_serdes_access(params);
Eilon Greensteinc1b73992009-02-12 08:37:07 +00001029
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001030 /* wait for the reset to self clear */
1031 for (i = 0; i < MDIO_ACCESS_TIMEOUT; i++) {
1032 udelay(5);
1033
1034 /* the reset erased the previous bank value */
1035 CL45_RD_OVER_CL22(bp, params->port,
1036 params->phy_addr,
1037 MDIO_REG_BANK_COMBO_IEEE0,
1038 MDIO_COMBO_IEEE0_MII_CONTROL,
1039 &mii_control);
1040
1041 if (!(mii_control & MDIO_COMBO_IEEO_MII_CONTROL_RESET)) {
1042 udelay(5);
1043 return 0;
1044 }
1045 }
1046
1047 DP(NETIF_MSG_LINK, "BUG! XGXS is still in reset!\n");
1048 return -EINVAL;
1049
1050}
1051
1052static void bnx2x_set_swap_lanes(struct link_params *params)
1053{
1054 struct bnx2x *bp = params->bp;
1055 /* Each two bits represents a lane number:
1056 No swap is 0123 => 0x1b no need to enable the swap */
1057 u16 ser_lane, rx_lane_swap, tx_lane_swap;
1058
1059 ser_lane = ((params->lane_config &
1060 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_MASK) >>
1061 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_SHIFT);
1062 rx_lane_swap = ((params->lane_config &
1063 PORT_HW_CFG_LANE_SWAP_CFG_RX_MASK) >>
1064 PORT_HW_CFG_LANE_SWAP_CFG_RX_SHIFT);
1065 tx_lane_swap = ((params->lane_config &
1066 PORT_HW_CFG_LANE_SWAP_CFG_TX_MASK) >>
1067 PORT_HW_CFG_LANE_SWAP_CFG_TX_SHIFT);
1068
1069 if (rx_lane_swap != 0x1b) {
1070 CL45_WR_OVER_CL22(bp, params->port,
1071 params->phy_addr,
1072 MDIO_REG_BANK_XGXS_BLOCK2,
1073 MDIO_XGXS_BLOCK2_RX_LN_SWAP,
1074 (rx_lane_swap |
1075 MDIO_XGXS_BLOCK2_RX_LN_SWAP_ENABLE |
1076 MDIO_XGXS_BLOCK2_RX_LN_SWAP_FORCE_ENABLE));
1077 } else {
1078 CL45_WR_OVER_CL22(bp, params->port,
1079 params->phy_addr,
1080 MDIO_REG_BANK_XGXS_BLOCK2,
1081 MDIO_XGXS_BLOCK2_RX_LN_SWAP, 0);
1082 }
1083
1084 if (tx_lane_swap != 0x1b) {
1085 CL45_WR_OVER_CL22(bp, params->port,
1086 params->phy_addr,
1087 MDIO_REG_BANK_XGXS_BLOCK2,
1088 MDIO_XGXS_BLOCK2_TX_LN_SWAP,
1089 (tx_lane_swap |
1090 MDIO_XGXS_BLOCK2_TX_LN_SWAP_ENABLE));
1091 } else {
1092 CL45_WR_OVER_CL22(bp, params->port,
1093 params->phy_addr,
1094 MDIO_REG_BANK_XGXS_BLOCK2,
1095 MDIO_XGXS_BLOCK2_TX_LN_SWAP, 0);
1096 }
1097}
1098
1099static void bnx2x_set_parallel_detection(struct link_params *params,
Eilon Greenstein3196a882008-08-13 15:58:49 -07001100 u8 phy_flags)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001101{
1102 struct bnx2x *bp = params->bp;
1103 u16 control2;
1104
1105 CL45_RD_OVER_CL22(bp, params->port,
1106 params->phy_addr,
1107 MDIO_REG_BANK_SERDES_DIGITAL,
1108 MDIO_SERDES_DIGITAL_A_1000X_CONTROL2,
1109 &control2);
Yaniv Rosner18afb0a2009-11-05 19:18:04 +02001110 if (params->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)
1111 control2 |= MDIO_SERDES_DIGITAL_A_1000X_CONTROL2_PRL_DT_EN;
1112 else
1113 control2 &= ~MDIO_SERDES_DIGITAL_A_1000X_CONTROL2_PRL_DT_EN;
1114 DP(NETIF_MSG_LINK, "params->speed_cap_mask = 0x%x, control2 = 0x%x\n",
1115 params->speed_cap_mask, control2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001116 CL45_WR_OVER_CL22(bp, params->port,
1117 params->phy_addr,
1118 MDIO_REG_BANK_SERDES_DIGITAL,
1119 MDIO_SERDES_DIGITAL_A_1000X_CONTROL2,
1120 control2);
1121
Yaniv Rosner18afb0a2009-11-05 19:18:04 +02001122 if ((phy_flags & PHY_XGXS_FLAG) &&
1123 (params->speed_cap_mask &
1124 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001125 DP(NETIF_MSG_LINK, "XGXS\n");
1126
1127 CL45_WR_OVER_CL22(bp, params->port,
1128 params->phy_addr,
1129 MDIO_REG_BANK_10G_PARALLEL_DETECT,
1130 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_LINK,
1131 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_LINK_CNT);
1132
1133 CL45_RD_OVER_CL22(bp, params->port,
1134 params->phy_addr,
1135 MDIO_REG_BANK_10G_PARALLEL_DETECT,
1136 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_CONTROL,
1137 &control2);
1138
1139
1140 control2 |=
1141 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_CONTROL_PARDET10G_EN;
1142
1143 CL45_WR_OVER_CL22(bp, params->port,
1144 params->phy_addr,
1145 MDIO_REG_BANK_10G_PARALLEL_DETECT,
1146 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_CONTROL,
1147 control2);
1148
1149 /* Disable parallel detection of HiG */
1150 CL45_WR_OVER_CL22(bp, params->port,
1151 params->phy_addr,
1152 MDIO_REG_BANK_XGXS_BLOCK2,
1153 MDIO_XGXS_BLOCK2_UNICORE_MODE_10G,
1154 MDIO_XGXS_BLOCK2_UNICORE_MODE_10G_CX4_XGXS |
1155 MDIO_XGXS_BLOCK2_UNICORE_MODE_10G_HIGIG_XGXS);
1156 }
1157}
1158
1159static void bnx2x_set_autoneg(struct link_params *params,
Eilon Greenstein239d6862009-08-12 08:23:04 +00001160 struct link_vars *vars,
1161 u8 enable_cl73)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001162{
1163 struct bnx2x *bp = params->bp;
1164 u16 reg_val;
1165
1166 /* CL37 Autoneg */
1167
1168 CL45_RD_OVER_CL22(bp, params->port,
1169 params->phy_addr,
1170 MDIO_REG_BANK_COMBO_IEEE0,
1171 MDIO_COMBO_IEEE0_MII_CONTROL, &reg_val);
1172
1173 /* CL37 Autoneg Enabled */
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07001174 if (vars->line_speed == SPEED_AUTO_NEG)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001175 reg_val |= MDIO_COMBO_IEEO_MII_CONTROL_AN_EN;
1176 else /* CL37 Autoneg Disabled */
1177 reg_val &= ~(MDIO_COMBO_IEEO_MII_CONTROL_AN_EN |
1178 MDIO_COMBO_IEEO_MII_CONTROL_RESTART_AN);
1179
1180 CL45_WR_OVER_CL22(bp, params->port,
1181 params->phy_addr,
1182 MDIO_REG_BANK_COMBO_IEEE0,
1183 MDIO_COMBO_IEEE0_MII_CONTROL, reg_val);
1184
1185 /* Enable/Disable Autodetection */
1186
1187 CL45_RD_OVER_CL22(bp, params->port,
1188 params->phy_addr,
1189 MDIO_REG_BANK_SERDES_DIGITAL,
1190 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1, &reg_val);
Eilon Greenstein239d6862009-08-12 08:23:04 +00001191 reg_val &= ~(MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_SIGNAL_DETECT_EN |
1192 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_INVERT_SIGNAL_DETECT);
1193 reg_val |= MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_FIBER_MODE;
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07001194 if (vars->line_speed == SPEED_AUTO_NEG)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001195 reg_val |= MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_AUTODET;
1196 else
1197 reg_val &= ~MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_AUTODET;
1198
1199 CL45_WR_OVER_CL22(bp, params->port,
1200 params->phy_addr,
1201 MDIO_REG_BANK_SERDES_DIGITAL,
1202 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1, reg_val);
1203
1204 /* Enable TetonII and BAM autoneg */
1205 CL45_RD_OVER_CL22(bp, params->port,
1206 params->phy_addr,
1207 MDIO_REG_BANK_BAM_NEXT_PAGE,
1208 MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL,
1209 &reg_val);
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07001210 if (vars->line_speed == SPEED_AUTO_NEG) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001211 /* Enable BAM aneg Mode and TetonII aneg Mode */
1212 reg_val |= (MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL_BAM_MODE |
1213 MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL_TETON_AN);
1214 } else {
1215 /* TetonII and BAM Autoneg Disabled */
1216 reg_val &= ~(MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL_BAM_MODE |
1217 MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL_TETON_AN);
1218 }
1219 CL45_WR_OVER_CL22(bp, params->port,
1220 params->phy_addr,
1221 MDIO_REG_BANK_BAM_NEXT_PAGE,
1222 MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL,
1223 reg_val);
1224
Eilon Greenstein239d6862009-08-12 08:23:04 +00001225 if (enable_cl73) {
1226 /* Enable Cl73 FSM status bits */
1227 CL45_WR_OVER_CL22(bp, params->port,
1228 params->phy_addr,
1229 MDIO_REG_BANK_CL73_USERB0,
1230 MDIO_CL73_USERB0_CL73_UCTRL,
Yaniv Rosner7846e472009-11-05 19:18:07 +02001231 0xe);
Eilon Greenstein239d6862009-08-12 08:23:04 +00001232
1233 /* Enable BAM Station Manager*/
1234 CL45_WR_OVER_CL22(bp, params->port,
1235 params->phy_addr,
1236 MDIO_REG_BANK_CL73_USERB0,
1237 MDIO_CL73_USERB0_CL73_BAM_CTRL1,
1238 MDIO_CL73_USERB0_CL73_BAM_CTRL1_BAM_EN |
1239 MDIO_CL73_USERB0_CL73_BAM_CTRL1_BAM_STATION_MNGR_EN |
1240 MDIO_CL73_USERB0_CL73_BAM_CTRL1_BAM_NP_AFTER_BP_EN);
1241
Yaniv Rosner7846e472009-11-05 19:18:07 +02001242 /* Advertise CL73 link speeds */
Eilon Greenstein239d6862009-08-12 08:23:04 +00001243 CL45_RD_OVER_CL22(bp, params->port,
1244 params->phy_addr,
1245 MDIO_REG_BANK_CL73_IEEEB1,
1246 MDIO_CL73_IEEEB1_AN_ADV2,
1247 &reg_val);
Yaniv Rosner7846e472009-11-05 19:18:07 +02001248 if (params->speed_cap_mask &
1249 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
1250 reg_val |= MDIO_CL73_IEEEB1_AN_ADV2_ADVR_10G_KX4;
1251 if (params->speed_cap_mask &
1252 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)
1253 reg_val |= MDIO_CL73_IEEEB1_AN_ADV2_ADVR_1000M_KX;
Eilon Greenstein239d6862009-08-12 08:23:04 +00001254
1255 CL45_WR_OVER_CL22(bp, params->port,
1256 params->phy_addr,
1257 MDIO_REG_BANK_CL73_IEEEB1,
1258 MDIO_CL73_IEEEB1_AN_ADV2,
Yaniv Rosner7846e472009-11-05 19:18:07 +02001259 reg_val);
Eilon Greenstein239d6862009-08-12 08:23:04 +00001260
Eilon Greenstein239d6862009-08-12 08:23:04 +00001261 /* CL73 Autoneg Enabled */
1262 reg_val = MDIO_CL73_IEEEB0_CL73_AN_CONTROL_AN_EN;
1263
1264 } else /* CL73 Autoneg Disabled */
1265 reg_val = 0;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001266
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001267 CL45_WR_OVER_CL22(bp, params->port,
1268 params->phy_addr,
1269 MDIO_REG_BANK_CL73_IEEEB0,
1270 MDIO_CL73_IEEEB0_CL73_AN_CONTROL, reg_val);
1271}
1272
1273/* program SerDes, forced speed */
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07001274static void bnx2x_program_serdes(struct link_params *params,
1275 struct link_vars *vars)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001276{
1277 struct bnx2x *bp = params->bp;
1278 u16 reg_val;
1279
Eilon Greenstein57937202009-08-12 08:23:53 +00001280 /* program duplex, disable autoneg and sgmii*/
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001281 CL45_RD_OVER_CL22(bp, params->port,
1282 params->phy_addr,
1283 MDIO_REG_BANK_COMBO_IEEE0,
1284 MDIO_COMBO_IEEE0_MII_CONTROL, &reg_val);
1285 reg_val &= ~(MDIO_COMBO_IEEO_MII_CONTROL_FULL_DUPLEX |
Eilon Greenstein57937202009-08-12 08:23:53 +00001286 MDIO_COMBO_IEEO_MII_CONTROL_AN_EN |
1287 MDIO_COMBO_IEEO_MII_CONTROL_MAN_SGMII_SP_MASK);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001288 if (params->req_duplex == DUPLEX_FULL)
1289 reg_val |= MDIO_COMBO_IEEO_MII_CONTROL_FULL_DUPLEX;
1290 CL45_WR_OVER_CL22(bp, params->port,
1291 params->phy_addr,
1292 MDIO_REG_BANK_COMBO_IEEE0,
1293 MDIO_COMBO_IEEE0_MII_CONTROL, reg_val);
1294
1295 /* program speed
1296 - needed only if the speed is greater than 1G (2.5G or 10G) */
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07001297 CL45_RD_OVER_CL22(bp, params->port,
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001298 params->phy_addr,
1299 MDIO_REG_BANK_SERDES_DIGITAL,
1300 MDIO_SERDES_DIGITAL_MISC1, &reg_val);
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07001301 /* clearing the speed value before setting the right speed */
1302 DP(NETIF_MSG_LINK, "MDIO_REG_BANK_SERDES_DIGITAL = 0x%x\n", reg_val);
1303
1304 reg_val &= ~(MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_MASK |
1305 MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_SEL);
1306
1307 if (!((vars->line_speed == SPEED_1000) ||
1308 (vars->line_speed == SPEED_100) ||
1309 (vars->line_speed == SPEED_10))) {
1310
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001311 reg_val |= (MDIO_SERDES_DIGITAL_MISC1_REFCLK_SEL_156_25M |
1312 MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_SEL);
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07001313 if (vars->line_speed == SPEED_10000)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001314 reg_val |=
1315 MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_10G_CX4;
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07001316 if (vars->line_speed == SPEED_13000)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001317 reg_val |=
1318 MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_13G;
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07001319 }
1320
1321 CL45_WR_OVER_CL22(bp, params->port,
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001322 params->phy_addr,
1323 MDIO_REG_BANK_SERDES_DIGITAL,
1324 MDIO_SERDES_DIGITAL_MISC1, reg_val);
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07001325
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001326}
1327
1328static void bnx2x_set_brcm_cl37_advertisment(struct link_params *params)
1329{
1330 struct bnx2x *bp = params->bp;
1331 u16 val = 0;
1332
1333 /* configure the 48 bits for BAM AN */
1334
1335 /* set extended capabilities */
1336 if (params->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G)
1337 val |= MDIO_OVER_1G_UP1_2_5G;
1338 if (params->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
1339 val |= MDIO_OVER_1G_UP1_10G;
1340 CL45_WR_OVER_CL22(bp, params->port,
1341 params->phy_addr,
1342 MDIO_REG_BANK_OVER_1G,
1343 MDIO_OVER_1G_UP1, val);
1344
1345 CL45_WR_OVER_CL22(bp, params->port,
1346 params->phy_addr,
1347 MDIO_REG_BANK_OVER_1G,
Eilon Greenstein239d6862009-08-12 08:23:04 +00001348 MDIO_OVER_1G_UP3, 0x400);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001349}
1350
Eilon Greenstein1ef70b92009-08-12 08:23:59 +00001351static void bnx2x_calc_ieee_aneg_adv(struct link_params *params, u16 *ieee_fc)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001352{
Yaniv Rosnerd5cb9e92009-11-05 19:18:10 +02001353 struct bnx2x *bp = params->bp;
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07001354 *ieee_fc = MDIO_COMBO_IEEE0_AUTO_NEG_ADV_FULL_DUPLEX;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001355 /* resolve pause mode and advertisement
1356 * Please refer to Table 28B-3 of the 802.3ab-1999 spec */
1357
1358 switch (params->req_flow_ctrl) {
David S. Millerc0700f92008-12-16 23:53:20 -08001359 case BNX2X_FLOW_CTRL_AUTO:
1360 if (params->req_fc_auto_adv == BNX2X_FLOW_CTRL_BOTH) {
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07001361 *ieee_fc |=
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001362 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH;
1363 } else {
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07001364 *ieee_fc |=
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001365 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC;
1366 }
1367 break;
David S. Millerc0700f92008-12-16 23:53:20 -08001368 case BNX2X_FLOW_CTRL_TX:
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07001369 *ieee_fc |=
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001370 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC;
1371 break;
1372
David S. Millerc0700f92008-12-16 23:53:20 -08001373 case BNX2X_FLOW_CTRL_RX:
1374 case BNX2X_FLOW_CTRL_BOTH:
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07001375 *ieee_fc |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001376 break;
1377
David S. Millerc0700f92008-12-16 23:53:20 -08001378 case BNX2X_FLOW_CTRL_NONE:
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001379 default:
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07001380 *ieee_fc |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001381 break;
1382 }
Yaniv Rosnerd5cb9e92009-11-05 19:18:10 +02001383 DP(NETIF_MSG_LINK, "ieee_fc = 0x%x\n", *ieee_fc);
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07001384}
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001385
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07001386static void bnx2x_set_ieee_aneg_advertisment(struct link_params *params,
Eilon Greenstein1ef70b92009-08-12 08:23:59 +00001387 u16 ieee_fc)
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07001388{
1389 struct bnx2x *bp = params->bp;
Yaniv Rosner7846e472009-11-05 19:18:07 +02001390 u16 val;
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07001391 /* for AN, we are always publishing full duplex */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001392
1393 CL45_WR_OVER_CL22(bp, params->port,
1394 params->phy_addr,
1395 MDIO_REG_BANK_COMBO_IEEE0,
Eilon Greenstein1ef70b92009-08-12 08:23:59 +00001396 MDIO_COMBO_IEEE0_AUTO_NEG_ADV, ieee_fc);
Yaniv Rosner7846e472009-11-05 19:18:07 +02001397 CL45_RD_OVER_CL22(bp, params->port,
1398 params->phy_addr,
1399 MDIO_REG_BANK_CL73_IEEEB1,
1400 MDIO_CL73_IEEEB1_AN_ADV1, &val);
1401 val &= ~MDIO_CL73_IEEEB1_AN_ADV1_PAUSE_BOTH;
1402 val |= ((ieee_fc<<3) & MDIO_CL73_IEEEB1_AN_ADV1_PAUSE_MASK);
1403 CL45_WR_OVER_CL22(bp, params->port,
1404 params->phy_addr,
1405 MDIO_REG_BANK_CL73_IEEEB1,
1406 MDIO_CL73_IEEEB1_AN_ADV1, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001407}
1408
Eilon Greenstein239d6862009-08-12 08:23:04 +00001409static void bnx2x_restart_autoneg(struct link_params *params, u8 enable_cl73)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001410{
1411 struct bnx2x *bp = params->bp;
Eilon Greenstein3a36f2e2009-02-12 08:37:09 +00001412 u16 mii_control;
Eilon Greenstein239d6862009-08-12 08:23:04 +00001413
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001414 DP(NETIF_MSG_LINK, "bnx2x_restart_autoneg\n");
Eilon Greenstein3a36f2e2009-02-12 08:37:09 +00001415 /* Enable and restart BAM/CL37 aneg */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001416
Eilon Greenstein239d6862009-08-12 08:23:04 +00001417 if (enable_cl73) {
1418 CL45_RD_OVER_CL22(bp, params->port,
1419 params->phy_addr,
1420 MDIO_REG_BANK_CL73_IEEEB0,
1421 MDIO_CL73_IEEEB0_CL73_AN_CONTROL,
1422 &mii_control);
1423
1424 CL45_WR_OVER_CL22(bp, params->port,
1425 params->phy_addr,
1426 MDIO_REG_BANK_CL73_IEEEB0,
1427 MDIO_CL73_IEEEB0_CL73_AN_CONTROL,
1428 (mii_control |
1429 MDIO_CL73_IEEEB0_CL73_AN_CONTROL_AN_EN |
1430 MDIO_CL73_IEEEB0_CL73_AN_CONTROL_RESTART_AN));
1431 } else {
1432
1433 CL45_RD_OVER_CL22(bp, params->port,
1434 params->phy_addr,
1435 MDIO_REG_BANK_COMBO_IEEE0,
1436 MDIO_COMBO_IEEE0_MII_CONTROL,
1437 &mii_control);
1438 DP(NETIF_MSG_LINK,
1439 "bnx2x_restart_autoneg mii_control before = 0x%x\n",
1440 mii_control);
1441 CL45_WR_OVER_CL22(bp, params->port,
1442 params->phy_addr,
1443 MDIO_REG_BANK_COMBO_IEEE0,
1444 MDIO_COMBO_IEEE0_MII_CONTROL,
1445 (mii_control |
1446 MDIO_COMBO_IEEO_MII_CONTROL_AN_EN |
1447 MDIO_COMBO_IEEO_MII_CONTROL_RESTART_AN));
1448 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001449}
1450
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07001451static void bnx2x_initialize_sgmii_process(struct link_params *params,
1452 struct link_vars *vars)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001453{
1454 struct bnx2x *bp = params->bp;
1455 u16 control1;
1456
1457 /* in SGMII mode, the unicore is always slave */
1458
1459 CL45_RD_OVER_CL22(bp, params->port,
1460 params->phy_addr,
1461 MDIO_REG_BANK_SERDES_DIGITAL,
1462 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1,
1463 &control1);
1464 control1 |= MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_INVERT_SIGNAL_DETECT;
1465 /* set sgmii mode (and not fiber) */
1466 control1 &= ~(MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_FIBER_MODE |
1467 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_AUTODET |
1468 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_MSTR_MODE);
1469 CL45_WR_OVER_CL22(bp, params->port,
1470 params->phy_addr,
1471 MDIO_REG_BANK_SERDES_DIGITAL,
1472 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1,
1473 control1);
1474
1475 /* if forced speed */
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07001476 if (!(vars->line_speed == SPEED_AUTO_NEG)) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001477 /* set speed, disable autoneg */
1478 u16 mii_control;
1479
1480 CL45_RD_OVER_CL22(bp, params->port,
1481 params->phy_addr,
1482 MDIO_REG_BANK_COMBO_IEEE0,
1483 MDIO_COMBO_IEEE0_MII_CONTROL,
1484 &mii_control);
1485 mii_control &= ~(MDIO_COMBO_IEEO_MII_CONTROL_AN_EN |
1486 MDIO_COMBO_IEEO_MII_CONTROL_MAN_SGMII_SP_MASK|
1487 MDIO_COMBO_IEEO_MII_CONTROL_FULL_DUPLEX);
1488
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07001489 switch (vars->line_speed) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001490 case SPEED_100:
1491 mii_control |=
1492 MDIO_COMBO_IEEO_MII_CONTROL_MAN_SGMII_SP_100;
1493 break;
1494 case SPEED_1000:
1495 mii_control |=
1496 MDIO_COMBO_IEEO_MII_CONTROL_MAN_SGMII_SP_1000;
1497 break;
1498 case SPEED_10:
1499 /* there is nothing to set for 10M */
1500 break;
1501 default:
1502 /* invalid speed for SGMII */
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07001503 DP(NETIF_MSG_LINK, "Invalid line_speed 0x%x\n",
1504 vars->line_speed);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001505 break;
1506 }
1507
1508 /* setting the full duplex */
1509 if (params->req_duplex == DUPLEX_FULL)
1510 mii_control |=
1511 MDIO_COMBO_IEEO_MII_CONTROL_FULL_DUPLEX;
1512 CL45_WR_OVER_CL22(bp, params->port,
1513 params->phy_addr,
1514 MDIO_REG_BANK_COMBO_IEEE0,
1515 MDIO_COMBO_IEEE0_MII_CONTROL,
1516 mii_control);
1517
1518 } else { /* AN mode */
1519 /* enable and restart AN */
Eilon Greenstein239d6862009-08-12 08:23:04 +00001520 bnx2x_restart_autoneg(params, 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001521 }
1522}
1523
1524
1525/*
1526 * link management
1527 */
1528
1529static void bnx2x_pause_resolve(struct link_vars *vars, u32 pause_result)
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07001530{ /* LD LP */
1531 switch (pause_result) { /* ASYM P ASYM P */
1532 case 0xb: /* 1 0 1 1 */
David S. Millerc0700f92008-12-16 23:53:20 -08001533 vars->flow_ctrl = BNX2X_FLOW_CTRL_TX;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001534 break;
1535
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07001536 case 0xe: /* 1 1 1 0 */
David S. Millerc0700f92008-12-16 23:53:20 -08001537 vars->flow_ctrl = BNX2X_FLOW_CTRL_RX;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001538 break;
1539
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07001540 case 0x5: /* 0 1 0 1 */
1541 case 0x7: /* 0 1 1 1 */
1542 case 0xd: /* 1 1 0 1 */
1543 case 0xf: /* 1 1 1 1 */
David S. Millerc0700f92008-12-16 23:53:20 -08001544 vars->flow_ctrl = BNX2X_FLOW_CTRL_BOTH;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001545 break;
1546
1547 default:
1548 break;
1549 }
1550}
1551
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00001552static u8 bnx2x_ext_phy_resolve_fc(struct link_params *params,
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001553 struct link_vars *vars)
1554{
1555 struct bnx2x *bp = params->bp;
1556 u8 ext_phy_addr;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00001557 u16 ld_pause; /* local */
1558 u16 lp_pause; /* link partner */
1559 u16 an_complete; /* AN complete */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001560 u16 pause_result;
1561 u8 ret = 0;
1562 u32 ext_phy_type;
1563 u8 port = params->port;
Eilon Greenstein659bc5c2009-08-12 08:24:02 +00001564 ext_phy_addr = XGXS_EXT_PHY_ADDR(params->ext_phy_config);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001565 ext_phy_type = XGXS_EXT_PHY_TYPE(params->ext_phy_config);
1566 /* read twice */
1567
1568 bnx2x_cl45_read(bp, port,
1569 ext_phy_type,
1570 ext_phy_addr,
1571 MDIO_AN_DEVAD,
1572 MDIO_AN_REG_STATUS, &an_complete);
1573 bnx2x_cl45_read(bp, port,
1574 ext_phy_type,
1575 ext_phy_addr,
1576 MDIO_AN_DEVAD,
1577 MDIO_AN_REG_STATUS, &an_complete);
1578
1579 if (an_complete & MDIO_AN_REG_STATUS_AN_COMPLETE) {
1580 ret = 1;
1581 bnx2x_cl45_read(bp, port,
1582 ext_phy_type,
1583 ext_phy_addr,
1584 MDIO_AN_DEVAD,
1585 MDIO_AN_REG_ADV_PAUSE, &ld_pause);
1586 bnx2x_cl45_read(bp, port,
1587 ext_phy_type,
1588 ext_phy_addr,
1589 MDIO_AN_DEVAD,
1590 MDIO_AN_REG_LP_AUTO_NEG, &lp_pause);
1591 pause_result = (ld_pause &
1592 MDIO_AN_REG_ADV_PAUSE_MASK) >> 8;
1593 pause_result |= (lp_pause &
1594 MDIO_AN_REG_ADV_PAUSE_MASK) >> 10;
1595 DP(NETIF_MSG_LINK, "Ext PHY pause result 0x%x \n",
1596 pause_result);
1597 bnx2x_pause_resolve(vars, pause_result);
David S. Millerc0700f92008-12-16 23:53:20 -08001598 if (vars->flow_ctrl == BNX2X_FLOW_CTRL_NONE &&
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07001599 ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073) {
1600 bnx2x_cl45_read(bp, port,
1601 ext_phy_type,
1602 ext_phy_addr,
1603 MDIO_AN_DEVAD,
1604 MDIO_AN_REG_CL37_FC_LD, &ld_pause);
1605
1606 bnx2x_cl45_read(bp, port,
1607 ext_phy_type,
1608 ext_phy_addr,
1609 MDIO_AN_DEVAD,
1610 MDIO_AN_REG_CL37_FC_LP, &lp_pause);
1611 pause_result = (ld_pause &
1612 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) >> 5;
1613 pause_result |= (lp_pause &
1614 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) >> 7;
1615
1616 bnx2x_pause_resolve(vars, pause_result);
1617 DP(NETIF_MSG_LINK, "Ext PHY CL37 pause result 0x%x \n",
1618 pause_result);
1619 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001620 }
1621 return ret;
1622}
1623
Yaniv Rosner15ddd2d2009-11-05 19:18:12 +02001624static u8 bnx2x_direct_parallel_detect_used(struct link_params *params)
1625{
1626 struct bnx2x *bp = params->bp;
1627 u16 pd_10g, status2_1000x;
1628 CL45_RD_OVER_CL22(bp, params->port,
1629 params->phy_addr,
1630 MDIO_REG_BANK_SERDES_DIGITAL,
1631 MDIO_SERDES_DIGITAL_A_1000X_STATUS2,
1632 &status2_1000x);
1633 CL45_RD_OVER_CL22(bp, params->port,
1634 params->phy_addr,
1635 MDIO_REG_BANK_SERDES_DIGITAL,
1636 MDIO_SERDES_DIGITAL_A_1000X_STATUS2,
1637 &status2_1000x);
1638 if (status2_1000x & MDIO_SERDES_DIGITAL_A_1000X_STATUS2_AN_DISABLED) {
1639 DP(NETIF_MSG_LINK, "1G parallel detect link on port %d\n",
1640 params->port);
1641 return 1;
1642 }
1643
1644 CL45_RD_OVER_CL22(bp, params->port,
1645 params->phy_addr,
1646 MDIO_REG_BANK_10G_PARALLEL_DETECT,
1647 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_STATUS,
1648 &pd_10g);
1649
1650 if (pd_10g & MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_STATUS_PD_LINK) {
1651 DP(NETIF_MSG_LINK, "10G parallel detect link on port %d\n",
1652 params->port);
1653 return 1;
1654 }
1655 return 0;
1656}
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001657
1658static void bnx2x_flow_ctrl_resolve(struct link_params *params,
1659 struct link_vars *vars,
1660 u32 gp_status)
1661{
1662 struct bnx2x *bp = params->bp;
Eilon Greenstein3196a882008-08-13 15:58:49 -07001663 u16 ld_pause; /* local driver */
1664 u16 lp_pause; /* link partner */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001665 u16 pause_result;
1666
David S. Millerc0700f92008-12-16 23:53:20 -08001667 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001668
1669 /* resolve from gp_status in case of AN complete and not sgmii */
David S. Millerc0700f92008-12-16 23:53:20 -08001670 if ((params->req_flow_ctrl == BNX2X_FLOW_CTRL_AUTO) &&
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001671 (gp_status & MDIO_AN_CL73_OR_37_COMPLETE) &&
1672 (!(vars->phy_flags & PHY_SGMII_FLAG)) &&
1673 (XGXS_EXT_PHY_TYPE(params->ext_phy_config) ==
1674 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)) {
Yaniv Rosner15ddd2d2009-11-05 19:18:12 +02001675 if (bnx2x_direct_parallel_detect_used(params)) {
1676 vars->flow_ctrl = params->req_fc_auto_adv;
1677 return;
1678 }
Yaniv Rosner7846e472009-11-05 19:18:07 +02001679 if ((gp_status &
1680 (MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_AUTONEG_COMPLETE |
1681 MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_MR_LP_NP_AN_ABLE)) ==
1682 (MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_AUTONEG_COMPLETE |
1683 MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_MR_LP_NP_AN_ABLE)) {
1684
1685 CL45_RD_OVER_CL22(bp, params->port,
1686 params->phy_addr,
1687 MDIO_REG_BANK_CL73_IEEEB1,
1688 MDIO_CL73_IEEEB1_AN_ADV1,
1689 &ld_pause);
1690 CL45_RD_OVER_CL22(bp, params->port,
1691 params->phy_addr,
1692 MDIO_REG_BANK_CL73_IEEEB1,
1693 MDIO_CL73_IEEEB1_AN_LP_ADV1,
1694 &lp_pause);
1695 pause_result = (ld_pause &
1696 MDIO_CL73_IEEEB1_AN_ADV1_PAUSE_MASK)
1697 >> 8;
1698 pause_result |= (lp_pause &
1699 MDIO_CL73_IEEEB1_AN_LP_ADV1_PAUSE_MASK)
1700 >> 10;
1701 DP(NETIF_MSG_LINK, "pause_result CL73 0x%x\n",
1702 pause_result);
1703 } else {
1704
1705 CL45_RD_OVER_CL22(bp, params->port,
1706 params->phy_addr,
1707 MDIO_REG_BANK_COMBO_IEEE0,
1708 MDIO_COMBO_IEEE0_AUTO_NEG_ADV,
1709 &ld_pause);
1710 CL45_RD_OVER_CL22(bp, params->port,
1711 params->phy_addr,
1712 MDIO_REG_BANK_COMBO_IEEE0,
1713 MDIO_COMBO_IEEE0_AUTO_NEG_LINK_PARTNER_ABILITY1,
1714 &lp_pause);
1715 pause_result = (ld_pause &
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001716 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK)>>5;
Yaniv Rosner7846e472009-11-05 19:18:07 +02001717 pause_result |= (lp_pause &
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001718 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK)>>7;
Yaniv Rosner7846e472009-11-05 19:18:07 +02001719 DP(NETIF_MSG_LINK, "pause_result CL37 0x%x\n",
1720 pause_result);
1721 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001722 bnx2x_pause_resolve(vars, pause_result);
David S. Millerc0700f92008-12-16 23:53:20 -08001723 } else if ((params->req_flow_ctrl == BNX2X_FLOW_CTRL_AUTO) &&
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00001724 (bnx2x_ext_phy_resolve_fc(params, vars))) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001725 return;
1726 } else {
David S. Millerc0700f92008-12-16 23:53:20 -08001727 if (params->req_flow_ctrl == BNX2X_FLOW_CTRL_AUTO)
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07001728 vars->flow_ctrl = params->req_fc_auto_adv;
1729 else
1730 vars->flow_ctrl = params->req_flow_ctrl;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001731 }
1732 DP(NETIF_MSG_LINK, "flow_ctrl 0x%x\n", vars->flow_ctrl);
1733}
1734
Eilon Greenstein239d6862009-08-12 08:23:04 +00001735static void bnx2x_check_fallback_to_cl37(struct link_params *params)
1736{
1737 struct bnx2x *bp = params->bp;
1738 u16 rx_status, ustat_val, cl37_fsm_recieved;
1739 DP(NETIF_MSG_LINK, "bnx2x_check_fallback_to_cl37\n");
1740 /* Step 1: Make sure signal is detected */
1741 CL45_RD_OVER_CL22(bp, params->port,
1742 params->phy_addr,
1743 MDIO_REG_BANK_RX0,
1744 MDIO_RX0_RX_STATUS,
1745 &rx_status);
1746 if ((rx_status & MDIO_RX0_RX_STATUS_SIGDET) !=
1747 (MDIO_RX0_RX_STATUS_SIGDET)) {
1748 DP(NETIF_MSG_LINK, "Signal is not detected. Restoring CL73."
1749 "rx_status(0x80b0) = 0x%x\n", rx_status);
1750 CL45_WR_OVER_CL22(bp, params->port,
1751 params->phy_addr,
1752 MDIO_REG_BANK_CL73_IEEEB0,
1753 MDIO_CL73_IEEEB0_CL73_AN_CONTROL,
1754 MDIO_CL73_IEEEB0_CL73_AN_CONTROL_AN_EN);
1755 return;
1756 }
1757 /* Step 2: Check CL73 state machine */
1758 CL45_RD_OVER_CL22(bp, params->port,
1759 params->phy_addr,
1760 MDIO_REG_BANK_CL73_USERB0,
1761 MDIO_CL73_USERB0_CL73_USTAT1,
1762 &ustat_val);
1763 if ((ustat_val &
1764 (MDIO_CL73_USERB0_CL73_USTAT1_LINK_STATUS_CHECK |
1765 MDIO_CL73_USERB0_CL73_USTAT1_AN_GOOD_CHECK_BAM37)) !=
1766 (MDIO_CL73_USERB0_CL73_USTAT1_LINK_STATUS_CHECK |
1767 MDIO_CL73_USERB0_CL73_USTAT1_AN_GOOD_CHECK_BAM37)) {
1768 DP(NETIF_MSG_LINK, "CL73 state-machine is not stable. "
1769 "ustat_val(0x8371) = 0x%x\n", ustat_val);
1770 return;
1771 }
1772 /* Step 3: Check CL37 Message Pages received to indicate LP
1773 supports only CL37 */
1774 CL45_RD_OVER_CL22(bp, params->port,
1775 params->phy_addr,
1776 MDIO_REG_BANK_REMOTE_PHY,
1777 MDIO_REMOTE_PHY_MISC_RX_STATUS,
1778 &cl37_fsm_recieved);
1779 if ((cl37_fsm_recieved &
1780 (MDIO_REMOTE_PHY_MISC_RX_STATUS_CL37_FSM_RECEIVED_OVER1G_MSG |
1781 MDIO_REMOTE_PHY_MISC_RX_STATUS_CL37_FSM_RECEIVED_BRCM_OUI_MSG)) !=
1782 (MDIO_REMOTE_PHY_MISC_RX_STATUS_CL37_FSM_RECEIVED_OVER1G_MSG |
1783 MDIO_REMOTE_PHY_MISC_RX_STATUS_CL37_FSM_RECEIVED_BRCM_OUI_MSG)) {
1784 DP(NETIF_MSG_LINK, "No CL37 FSM were received. "
1785 "misc_rx_status(0x8330) = 0x%x\n",
1786 cl37_fsm_recieved);
1787 return;
1788 }
1789 /* The combined cl37/cl73 fsm state information indicating that we are
1790 connected to a device which does not support cl73, but does support
1791 cl37 BAM. In this case we disable cl73 and restart cl37 auto-neg */
1792 /* Disable CL73 */
1793 CL45_WR_OVER_CL22(bp, params->port,
1794 params->phy_addr,
1795 MDIO_REG_BANK_CL73_IEEEB0,
1796 MDIO_CL73_IEEEB0_CL73_AN_CONTROL,
1797 0);
1798 /* Restart CL37 autoneg */
1799 bnx2x_restart_autoneg(params, 0);
1800 DP(NETIF_MSG_LINK, "Disabling CL73, and restarting CL37 autoneg\n");
1801}
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001802static u8 bnx2x_link_settings_status(struct link_params *params,
Eilon Greenstein2f904462009-08-12 08:22:16 +00001803 struct link_vars *vars,
1804 u32 gp_status,
1805 u8 ext_phy_link_up)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001806{
1807 struct bnx2x *bp = params->bp;
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00001808 u16 new_line_speed;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001809 u8 rc = 0;
1810 vars->link_status = 0;
1811
1812 if (gp_status & MDIO_GP_STATUS_TOP_AN_STATUS1_LINK_STATUS) {
1813 DP(NETIF_MSG_LINK, "phy link up gp_status=0x%x\n",
1814 gp_status);
1815
1816 vars->phy_link_up = 1;
1817 vars->link_status |= LINK_STATUS_LINK_UP;
1818
1819 if (gp_status & MDIO_GP_STATUS_TOP_AN_STATUS1_DUPLEX_STATUS)
1820 vars->duplex = DUPLEX_FULL;
1821 else
1822 vars->duplex = DUPLEX_HALF;
1823
1824 bnx2x_flow_ctrl_resolve(params, vars, gp_status);
1825
1826 switch (gp_status & GP_STATUS_SPEED_MASK) {
1827 case GP_STATUS_10M:
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00001828 new_line_speed = SPEED_10;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001829 if (vars->duplex == DUPLEX_FULL)
1830 vars->link_status |= LINK_10TFD;
1831 else
1832 vars->link_status |= LINK_10THD;
1833 break;
1834
1835 case GP_STATUS_100M:
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00001836 new_line_speed = SPEED_100;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001837 if (vars->duplex == DUPLEX_FULL)
1838 vars->link_status |= LINK_100TXFD;
1839 else
1840 vars->link_status |= LINK_100TXHD;
1841 break;
1842
1843 case GP_STATUS_1G:
1844 case GP_STATUS_1G_KX:
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00001845 new_line_speed = SPEED_1000;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001846 if (vars->duplex == DUPLEX_FULL)
1847 vars->link_status |= LINK_1000TFD;
1848 else
1849 vars->link_status |= LINK_1000THD;
1850 break;
1851
1852 case GP_STATUS_2_5G:
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00001853 new_line_speed = SPEED_2500;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001854 if (vars->duplex == DUPLEX_FULL)
1855 vars->link_status |= LINK_2500TFD;
1856 else
1857 vars->link_status |= LINK_2500THD;
1858 break;
1859
1860 case GP_STATUS_5G:
1861 case GP_STATUS_6G:
1862 DP(NETIF_MSG_LINK,
1863 "link speed unsupported gp_status 0x%x\n",
1864 gp_status);
1865 return -EINVAL;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00001866
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001867 case GP_STATUS_10G_KX4:
1868 case GP_STATUS_10G_HIG:
1869 case GP_STATUS_10G_CX4:
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00001870 new_line_speed = SPEED_10000;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001871 vars->link_status |= LINK_10GTFD;
1872 break;
1873
1874 case GP_STATUS_12G_HIG:
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00001875 new_line_speed = SPEED_12000;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001876 vars->link_status |= LINK_12GTFD;
1877 break;
1878
1879 case GP_STATUS_12_5G:
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00001880 new_line_speed = SPEED_12500;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001881 vars->link_status |= LINK_12_5GTFD;
1882 break;
1883
1884 case GP_STATUS_13G:
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00001885 new_line_speed = SPEED_13000;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001886 vars->link_status |= LINK_13GTFD;
1887 break;
1888
1889 case GP_STATUS_15G:
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00001890 new_line_speed = SPEED_15000;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001891 vars->link_status |= LINK_15GTFD;
1892 break;
1893
1894 case GP_STATUS_16G:
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00001895 new_line_speed = SPEED_16000;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001896 vars->link_status |= LINK_16GTFD;
1897 break;
1898
1899 default:
1900 DP(NETIF_MSG_LINK,
1901 "link speed unsupported gp_status 0x%x\n",
1902 gp_status);
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00001903 return -EINVAL;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001904 }
1905
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00001906 /* Upon link speed change set the NIG into drain mode.
1907 Comes to deals with possible FIFO glitch due to clk change
1908 when speed is decreased without link down indicator */
1909 if (new_line_speed != vars->line_speed) {
Eilon Greenstein2f904462009-08-12 08:22:16 +00001910 if (XGXS_EXT_PHY_TYPE(params->ext_phy_config) !=
1911 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT &&
1912 ext_phy_link_up) {
1913 DP(NETIF_MSG_LINK, "Internal link speed %d is"
1914 " different than the external"
1915 " link speed %d\n", new_line_speed,
1916 vars->line_speed);
1917 vars->phy_link_up = 0;
1918 return 0;
1919 }
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00001920 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE
1921 + params->port*4, 0);
1922 msleep(1);
1923 }
1924 vars->line_speed = new_line_speed;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001925 vars->link_status |= LINK_STATUS_SERDES_LINK;
1926
Yaniv Rosner57963ed2008-08-13 15:55:28 -07001927 if ((params->req_line_speed == SPEED_AUTO_NEG) &&
1928 ((XGXS_EXT_PHY_TYPE(params->ext_phy_config) ==
1929 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT) ||
1930 (XGXS_EXT_PHY_TYPE(params->ext_phy_config) ==
Eilon Greenstein589abe32009-02-12 08:36:55 +00001931 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705) ||
1932 (XGXS_EXT_PHY_TYPE(params->ext_phy_config) ==
Yaniv Rosnerb5bbf002009-11-05 19:18:21 +02001933 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706) ||
1934 (XGXS_EXT_PHY_TYPE(params->ext_phy_config) ==
Eilon Greenstein2f904462009-08-12 08:22:16 +00001935 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726))) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001936 vars->autoneg = AUTO_NEG_ENABLED;
1937
1938 if (gp_status & MDIO_AN_CL73_OR_37_COMPLETE) {
1939 vars->autoneg |= AUTO_NEG_COMPLETE;
1940 vars->link_status |=
1941 LINK_STATUS_AUTO_NEGOTIATE_COMPLETE;
1942 }
1943
1944 vars->autoneg |= AUTO_NEG_PARALLEL_DETECTION_USED;
1945 vars->link_status |=
1946 LINK_STATUS_PARALLEL_DETECTION_USED;
1947
1948 }
David S. Millerc0700f92008-12-16 23:53:20 -08001949 if (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX)
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07001950 vars->link_status |=
1951 LINK_STATUS_TX_FLOW_CONTROL_ENABLED;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001952
David S. Millerc0700f92008-12-16 23:53:20 -08001953 if (vars->flow_ctrl & BNX2X_FLOW_CTRL_RX)
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07001954 vars->link_status |=
1955 LINK_STATUS_RX_FLOW_CONTROL_ENABLED;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001956
1957 } else { /* link_down */
1958 DP(NETIF_MSG_LINK, "phy link down\n");
1959
1960 vars->phy_link_up = 0;
Yaniv Rosner57963ed2008-08-13 15:55:28 -07001961
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001962 vars->duplex = DUPLEX_FULL;
David S. Millerc0700f92008-12-16 23:53:20 -08001963 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001964 vars->autoneg = AUTO_NEG_DISABLED;
1965 vars->mac_type = MAC_TYPE_NONE;
Eilon Greenstein239d6862009-08-12 08:23:04 +00001966
1967 if ((params->req_line_speed == SPEED_AUTO_NEG) &&
1968 ((XGXS_EXT_PHY_TYPE(params->ext_phy_config) ==
1969 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT))) {
1970 /* Check signal is detected */
1971 bnx2x_check_fallback_to_cl37(params);
1972 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001973 }
1974
1975 DP(NETIF_MSG_LINK, "gp_status 0x%x phy_link_up %x line_speed %x \n",
1976 gp_status, vars->phy_link_up, vars->line_speed);
1977 DP(NETIF_MSG_LINK, "duplex %x flow_ctrl 0x%x"
1978 " autoneg 0x%x\n",
1979 vars->duplex,
1980 vars->flow_ctrl, vars->autoneg);
1981 DP(NETIF_MSG_LINK, "link_status 0x%x\n", vars->link_status);
1982
1983 return rc;
1984}
1985
Eilon Greensteined8680a2009-02-12 08:37:12 +00001986static void bnx2x_set_gmii_tx_driver(struct link_params *params)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001987{
1988 struct bnx2x *bp = params->bp;
1989 u16 lp_up2;
1990 u16 tx_driver;
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00001991 u16 bank;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001992
1993 /* read precomp */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001994 CL45_RD_OVER_CL22(bp, params->port,
1995 params->phy_addr,
1996 MDIO_REG_BANK_OVER_1G,
1997 MDIO_OVER_1G_LP_UP2, &lp_up2);
1998
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001999 /* bits [10:7] at lp_up2, positioned at [15:12] */
2000 lp_up2 = (((lp_up2 & MDIO_OVER_1G_LP_UP2_PREEMPHASIS_MASK) >>
2001 MDIO_OVER_1G_LP_UP2_PREEMPHASIS_SHIFT) <<
2002 MDIO_TX0_TX_DRIVER_PREEMPHASIS_SHIFT);
2003
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00002004 if (lp_up2 == 0)
2005 return;
2006
2007 for (bank = MDIO_REG_BANK_TX0; bank <= MDIO_REG_BANK_TX3;
2008 bank += (MDIO_REG_BANK_TX1 - MDIO_REG_BANK_TX0)) {
2009 CL45_RD_OVER_CL22(bp, params->port,
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002010 params->phy_addr,
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00002011 bank,
2012 MDIO_TX0_TX_DRIVER, &tx_driver);
2013
2014 /* replace tx_driver bits [15:12] */
2015 if (lp_up2 !=
2016 (tx_driver & MDIO_TX0_TX_DRIVER_PREEMPHASIS_MASK)) {
2017 tx_driver &= ~MDIO_TX0_TX_DRIVER_PREEMPHASIS_MASK;
2018 tx_driver |= lp_up2;
2019 CL45_WR_OVER_CL22(bp, params->port,
2020 params->phy_addr,
2021 bank,
2022 MDIO_TX0_TX_DRIVER, tx_driver);
2023 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002024 }
2025}
2026
2027static u8 bnx2x_emac_program(struct link_params *params,
2028 u32 line_speed, u32 duplex)
2029{
2030 struct bnx2x *bp = params->bp;
2031 u8 port = params->port;
2032 u16 mode = 0;
2033
2034 DP(NETIF_MSG_LINK, "setting link speed & duplex\n");
2035 bnx2x_bits_dis(bp, GRCBASE_EMAC0 + port*0x400 +
2036 EMAC_REG_EMAC_MODE,
2037 (EMAC_MODE_25G_MODE |
2038 EMAC_MODE_PORT_MII_10M |
2039 EMAC_MODE_HALF_DUPLEX));
2040 switch (line_speed) {
2041 case SPEED_10:
2042 mode |= EMAC_MODE_PORT_MII_10M;
2043 break;
2044
2045 case SPEED_100:
2046 mode |= EMAC_MODE_PORT_MII;
2047 break;
2048
2049 case SPEED_1000:
2050 mode |= EMAC_MODE_PORT_GMII;
2051 break;
2052
2053 case SPEED_2500:
2054 mode |= (EMAC_MODE_25G_MODE | EMAC_MODE_PORT_GMII);
2055 break;
2056
2057 default:
2058 /* 10G not valid for EMAC */
2059 DP(NETIF_MSG_LINK, "Invalid line_speed 0x%x\n", line_speed);
2060 return -EINVAL;
2061 }
2062
2063 if (duplex == DUPLEX_HALF)
2064 mode |= EMAC_MODE_HALF_DUPLEX;
2065 bnx2x_bits_en(bp,
2066 GRCBASE_EMAC0 + port*0x400 + EMAC_REG_EMAC_MODE,
2067 mode);
2068
Yaniv Rosner7846e472009-11-05 19:18:07 +02002069 bnx2x_set_led(params, LED_MODE_OPER, line_speed);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002070 return 0;
2071}
2072
2073/*****************************************************************************/
Eilon Greenstein17de50b2008-08-13 15:56:59 -07002074/* External Phy section */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002075/*****************************************************************************/
Eilon Greensteinf57a6022009-08-12 08:23:11 +00002076void bnx2x_ext_phy_hw_reset(struct bnx2x *bp, u8 port)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002077{
2078 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
Eilon Greenstein17de50b2008-08-13 15:56:59 -07002079 MISC_REGISTERS_GPIO_OUTPUT_LOW, port);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002080 msleep(1);
2081 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
Eilon Greenstein17de50b2008-08-13 15:56:59 -07002082 MISC_REGISTERS_GPIO_OUTPUT_HIGH, port);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002083}
2084
2085static void bnx2x_ext_phy_reset(struct link_params *params,
2086 struct link_vars *vars)
2087{
2088 struct bnx2x *bp = params->bp;
2089 u32 ext_phy_type;
Eilon Greenstein659bc5c2009-08-12 08:24:02 +00002090 u8 ext_phy_addr = XGXS_EXT_PHY_ADDR(params->ext_phy_config);
2091
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002092 DP(NETIF_MSG_LINK, "Port %x: bnx2x_ext_phy_reset\n", params->port);
2093 ext_phy_type = XGXS_EXT_PHY_TYPE(params->ext_phy_config);
2094 /* The PHY reset is controled by GPIO 1
2095 * Give it 1ms of reset pulse
2096 */
2097 if (vars->phy_flags & PHY_XGXS_FLAG) {
2098
2099 switch (ext_phy_type) {
2100 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT:
2101 DP(NETIF_MSG_LINK, "XGXS Direct\n");
2102 break;
2103
2104 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705:
2105 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706:
2106 DP(NETIF_MSG_LINK, "XGXS 8705/8706\n");
2107
2108 /* Restore normal power mode*/
2109 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Eilon Greenstein17de50b2008-08-13 15:56:59 -07002110 MISC_REGISTERS_GPIO_OUTPUT_HIGH,
2111 params->port);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002112
2113 /* HW reset */
Eilon Greensteinf57a6022009-08-12 08:23:11 +00002114 bnx2x_ext_phy_hw_reset(bp, params->port);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002115
2116 bnx2x_cl45_write(bp, params->port,
2117 ext_phy_type,
2118 ext_phy_addr,
2119 MDIO_PMA_DEVAD,
2120 MDIO_PMA_REG_CTRL, 0xa040);
2121 break;
Eilon Greenstein4d295db2009-07-21 05:47:47 +00002122
2123 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
2124 break;
2125
Eilon Greenstein589abe32009-02-12 08:36:55 +00002126 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
2127
2128 /* Restore normal power mode*/
2129 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
2130 MISC_REGISTERS_GPIO_OUTPUT_HIGH,
2131 params->port);
2132
2133 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
2134 MISC_REGISTERS_GPIO_OUTPUT_HIGH,
2135 params->port);
2136
2137 bnx2x_cl45_write(bp, params->port,
2138 ext_phy_type,
2139 ext_phy_addr,
2140 MDIO_PMA_DEVAD,
2141 MDIO_PMA_REG_CTRL,
2142 1<<15);
Eilon Greenstein589abe32009-02-12 08:36:55 +00002143 break;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00002144
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002145 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8072:
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00002146 DP(NETIF_MSG_LINK, "XGXS 8072\n");
2147
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002148 /* Unset Low Power Mode and SW reset */
2149 /* Restore normal power mode*/
2150 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Eilon Greenstein17de50b2008-08-13 15:56:59 -07002151 MISC_REGISTERS_GPIO_OUTPUT_HIGH,
2152 params->port);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002153
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002154 bnx2x_cl45_write(bp, params->port,
2155 ext_phy_type,
2156 ext_phy_addr,
2157 MDIO_PMA_DEVAD,
2158 MDIO_PMA_REG_CTRL,
2159 1<<15);
2160 break;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00002161
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002162 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073:
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00002163 DP(NETIF_MSG_LINK, "XGXS 8073\n");
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002164
2165 /* Restore normal power mode*/
2166 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Eilon Greenstein17de50b2008-08-13 15:56:59 -07002167 MISC_REGISTERS_GPIO_OUTPUT_HIGH,
2168 params->port);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002169
2170 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
Eilon Greenstein17de50b2008-08-13 15:56:59 -07002171 MISC_REGISTERS_GPIO_OUTPUT_HIGH,
2172 params->port);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002173 break;
2174
2175 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101:
2176 DP(NETIF_MSG_LINK, "XGXS SFX7101\n");
2177
2178 /* Restore normal power mode*/
2179 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Eilon Greenstein17de50b2008-08-13 15:56:59 -07002180 MISC_REGISTERS_GPIO_OUTPUT_HIGH,
2181 params->port);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002182
2183 /* HW reset */
Eilon Greensteinf57a6022009-08-12 08:23:11 +00002184 bnx2x_ext_phy_hw_reset(bp, params->port);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002185 break;
2186
Eilon Greenstein28577182009-02-12 08:37:00 +00002187 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8481:
Eilon Greenstein28577182009-02-12 08:37:00 +00002188 /* Restore normal power mode*/
2189 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
2190 MISC_REGISTERS_GPIO_OUTPUT_HIGH,
2191 params->port);
2192
2193 /* HW reset */
Eilon Greensteinf57a6022009-08-12 08:23:11 +00002194 bnx2x_ext_phy_hw_reset(bp, params->port);
Eilon Greenstein28577182009-02-12 08:37:00 +00002195
2196 bnx2x_cl45_write(bp, params->port,
2197 ext_phy_type,
2198 ext_phy_addr,
2199 MDIO_PMA_DEVAD,
2200 MDIO_PMA_REG_CTRL,
2201 1<<15);
2202 break;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002203 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE:
2204 DP(NETIF_MSG_LINK, "XGXS PHY Failure detected\n");
2205 break;
2206
2207 default:
2208 DP(NETIF_MSG_LINK, "BAD XGXS ext_phy_config 0x%x\n",
2209 params->ext_phy_config);
2210 break;
2211 }
2212
2213 } else { /* SerDes */
2214 ext_phy_type = SERDES_EXT_PHY_TYPE(params->ext_phy_config);
2215 switch (ext_phy_type) {
2216 case PORT_HW_CFG_SERDES_EXT_PHY_TYPE_DIRECT:
2217 DP(NETIF_MSG_LINK, "SerDes Direct\n");
2218 break;
2219
2220 case PORT_HW_CFG_SERDES_EXT_PHY_TYPE_BCM5482:
2221 DP(NETIF_MSG_LINK, "SerDes 5482\n");
Eilon Greensteinf57a6022009-08-12 08:23:11 +00002222 bnx2x_ext_phy_hw_reset(bp, params->port);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002223 break;
2224
2225 default:
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00002226 DP(NETIF_MSG_LINK, "BAD SerDes ext_phy_config 0x%x\n",
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002227 params->ext_phy_config);
2228 break;
2229 }
2230 }
2231}
2232
Eilon Greensteina35da8d2009-02-12 08:37:02 +00002233static void bnx2x_save_spirom_version(struct bnx2x *bp, u8 port,
2234 u32 shmem_base, u32 spirom_ver)
2235{
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00002236 DP(NETIF_MSG_LINK, "FW version 0x%x:0x%x for port %d\n",
2237 (u16)(spirom_ver>>16), (u16)spirom_ver, port);
Eilon Greensteina35da8d2009-02-12 08:37:02 +00002238 REG_WR(bp, shmem_base +
2239 offsetof(struct shmem_region,
2240 port_mb[port].ext_phy_fw_version),
2241 spirom_ver);
2242}
2243
2244static void bnx2x_save_bcm_spirom_ver(struct bnx2x *bp, u8 port,
2245 u32 ext_phy_type, u8 ext_phy_addr,
2246 u32 shmem_base)
2247{
2248 u16 fw_ver1, fw_ver2;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00002249
Eilon Greensteina35da8d2009-02-12 08:37:02 +00002250 bnx2x_cl45_read(bp, port, ext_phy_type, ext_phy_addr, MDIO_PMA_DEVAD,
2251 MDIO_PMA_REG_ROM_VER1, &fw_ver1);
2252 bnx2x_cl45_read(bp, port, ext_phy_type, ext_phy_addr, MDIO_PMA_DEVAD,
2253 MDIO_PMA_REG_ROM_VER2, &fw_ver2);
2254 bnx2x_save_spirom_version(bp, port, shmem_base,
2255 (u32)(fw_ver1<<16 | fw_ver2));
2256}
2257
Eilon Greensteinb1607af2009-08-12 08:22:54 +00002258
2259static void bnx2x_save_8481_spirom_version(struct bnx2x *bp, u8 port,
2260 u8 ext_phy_addr, u32 shmem_base)
2261{
2262 u16 val, fw_ver1, fw_ver2, cnt;
2263 /* For the 32 bits registers in 8481, access via MDIO2ARM interface.*/
2264 /* (1) set register 0xc200_0014(SPI_BRIDGE_CTRL_2) to 0x03000000 */
2265 bnx2x_cl45_write(bp, port,
2266 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8481,
2267 ext_phy_addr, MDIO_PMA_DEVAD,
2268 0xA819, 0x0014);
2269 bnx2x_cl45_write(bp, port,
2270 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8481,
2271 ext_phy_addr,
2272 MDIO_PMA_DEVAD,
2273 0xA81A,
2274 0xc200);
2275 bnx2x_cl45_write(bp, port,
2276 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8481,
2277 ext_phy_addr,
2278 MDIO_PMA_DEVAD,
2279 0xA81B,
2280 0x0000);
2281 bnx2x_cl45_write(bp, port,
2282 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8481,
2283 ext_phy_addr,
2284 MDIO_PMA_DEVAD,
2285 0xA81C,
2286 0x0300);
2287 bnx2x_cl45_write(bp, port,
2288 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8481,
2289 ext_phy_addr,
2290 MDIO_PMA_DEVAD,
2291 0xA817,
2292 0x0009);
2293
2294 for (cnt = 0; cnt < 100; cnt++) {
2295 bnx2x_cl45_read(bp, port,
2296 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8481,
2297 ext_phy_addr,
2298 MDIO_PMA_DEVAD,
2299 0xA818,
2300 &val);
2301 if (val & 1)
2302 break;
2303 udelay(5);
2304 }
2305 if (cnt == 100) {
2306 DP(NETIF_MSG_LINK, "Unable to read 8481 phy fw version(1)\n");
2307 bnx2x_save_spirom_version(bp, port,
2308 shmem_base, 0);
2309 return;
2310 }
2311
2312
2313 /* 2) read register 0xc200_0000 (SPI_FW_STATUS) */
2314 bnx2x_cl45_write(bp, port,
2315 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8481,
2316 ext_phy_addr, MDIO_PMA_DEVAD,
2317 0xA819, 0x0000);
2318 bnx2x_cl45_write(bp, port,
2319 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8481,
2320 ext_phy_addr, MDIO_PMA_DEVAD,
2321 0xA81A, 0xc200);
2322 bnx2x_cl45_write(bp, port,
2323 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8481,
2324 ext_phy_addr, MDIO_PMA_DEVAD,
2325 0xA817, 0x000A);
2326 for (cnt = 0; cnt < 100; cnt++) {
2327 bnx2x_cl45_read(bp, port,
2328 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8481,
2329 ext_phy_addr,
2330 MDIO_PMA_DEVAD,
2331 0xA818,
2332 &val);
2333 if (val & 1)
2334 break;
2335 udelay(5);
2336 }
2337 if (cnt == 100) {
2338 DP(NETIF_MSG_LINK, "Unable to read 8481 phy fw version(2)\n");
2339 bnx2x_save_spirom_version(bp, port,
2340 shmem_base, 0);
2341 return;
2342 }
2343
2344 /* lower 16 bits of the register SPI_FW_STATUS */
2345 bnx2x_cl45_read(bp, port,
2346 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8481,
2347 ext_phy_addr,
2348 MDIO_PMA_DEVAD,
2349 0xA81B,
2350 &fw_ver1);
2351 /* upper 16 bits of register SPI_FW_STATUS */
2352 bnx2x_cl45_read(bp, port,
2353 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8481,
2354 ext_phy_addr,
2355 MDIO_PMA_DEVAD,
2356 0xA81C,
2357 &fw_ver2);
2358
2359 bnx2x_save_spirom_version(bp, port,
2360 shmem_base, (fw_ver2<<16) | fw_ver1);
2361}
2362
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002363static void bnx2x_bcm8072_external_rom_boot(struct link_params *params)
2364{
2365 struct bnx2x *bp = params->bp;
2366 u8 port = params->port;
Eilon Greenstein659bc5c2009-08-12 08:24:02 +00002367 u8 ext_phy_addr = XGXS_EXT_PHY_ADDR(params->ext_phy_config);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002368 u32 ext_phy_type = XGXS_EXT_PHY_TYPE(params->ext_phy_config);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002369
2370 /* Need to wait 200ms after reset */
2371 msleep(200);
2372 /* Boot port from external ROM
2373 * Set ser_boot_ctl bit in the MISC_CTRL1 register
2374 */
2375 bnx2x_cl45_write(bp, port, ext_phy_type, ext_phy_addr,
2376 MDIO_PMA_DEVAD,
2377 MDIO_PMA_REG_MISC_CTRL1, 0x0001);
2378
2379 /* Reset internal microprocessor */
2380 bnx2x_cl45_write(bp, port, ext_phy_type, ext_phy_addr,
2381 MDIO_PMA_DEVAD,
2382 MDIO_PMA_REG_GEN_CTRL,
2383 MDIO_PMA_REG_GEN_CTRL_ROM_RESET_INTERNAL_MP);
2384 /* set micro reset = 0 */
2385 bnx2x_cl45_write(bp, port, ext_phy_type, ext_phy_addr,
2386 MDIO_PMA_DEVAD,
2387 MDIO_PMA_REG_GEN_CTRL,
2388 MDIO_PMA_REG_GEN_CTRL_ROM_MICRO_RESET);
2389 /* Reset internal microprocessor */
2390 bnx2x_cl45_write(bp, port, ext_phy_type, ext_phy_addr,
2391 MDIO_PMA_DEVAD,
2392 MDIO_PMA_REG_GEN_CTRL,
2393 MDIO_PMA_REG_GEN_CTRL_ROM_RESET_INTERNAL_MP);
2394 /* wait for 100ms for code download via SPI port */
2395 msleep(100);
2396
2397 /* Clear ser_boot_ctl bit */
2398 bnx2x_cl45_write(bp, port, ext_phy_type, ext_phy_addr,
2399 MDIO_PMA_DEVAD,
2400 MDIO_PMA_REG_MISC_CTRL1, 0x0000);
2401 /* Wait 100ms */
2402 msleep(100);
2403
Eilon Greensteina35da8d2009-02-12 08:37:02 +00002404 bnx2x_save_bcm_spirom_ver(bp, port,
2405 ext_phy_type,
2406 ext_phy_addr,
2407 params->shmem_base);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002408}
2409
2410static u8 bnx2x_8073_is_snr_needed(struct link_params *params)
2411{
2412 /* This is only required for 8073A1, version 102 only */
2413
2414 struct bnx2x *bp = params->bp;
Eilon Greenstein659bc5c2009-08-12 08:24:02 +00002415 u8 ext_phy_addr = XGXS_EXT_PHY_ADDR(params->ext_phy_config);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002416 u16 val;
2417
2418 /* Read 8073 HW revision*/
2419 bnx2x_cl45_read(bp, params->port,
2420 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073,
2421 ext_phy_addr,
2422 MDIO_PMA_DEVAD,
Eilon Greenstein052a38e2009-02-12 08:37:16 +00002423 MDIO_PMA_REG_8073_CHIP_REV, &val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002424
2425 if (val != 1) {
2426 /* No need to workaround in 8073 A1 */
2427 return 0;
2428 }
2429
2430 bnx2x_cl45_read(bp, params->port,
2431 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073,
2432 ext_phy_addr,
2433 MDIO_PMA_DEVAD,
2434 MDIO_PMA_REG_ROM_VER2, &val);
2435
2436 /* SNR should be applied only for version 0x102 */
2437 if (val != 0x102)
2438 return 0;
2439
2440 return 1;
2441}
2442
2443static u8 bnx2x_bcm8073_xaui_wa(struct link_params *params)
2444{
2445 struct bnx2x *bp = params->bp;
Eilon Greenstein659bc5c2009-08-12 08:24:02 +00002446 u8 ext_phy_addr = XGXS_EXT_PHY_ADDR(params->ext_phy_config);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002447 u16 val, cnt, cnt1 ;
2448
2449 bnx2x_cl45_read(bp, params->port,
2450 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073,
2451 ext_phy_addr,
2452 MDIO_PMA_DEVAD,
Eilon Greenstein052a38e2009-02-12 08:37:16 +00002453 MDIO_PMA_REG_8073_CHIP_REV, &val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002454
2455 if (val > 0) {
2456 /* No need to workaround in 8073 A1 */
2457 return 0;
2458 }
2459 /* XAUI workaround in 8073 A0: */
2460
2461 /* After loading the boot ROM and restarting Autoneg,
2462 poll Dev1, Reg $C820: */
2463
2464 for (cnt = 0; cnt < 1000; cnt++) {
2465 bnx2x_cl45_read(bp, params->port,
2466 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073,
2467 ext_phy_addr,
2468 MDIO_PMA_DEVAD,
Eilon Greenstein052a38e2009-02-12 08:37:16 +00002469 MDIO_PMA_REG_8073_SPEED_LINK_STATUS,
2470 &val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002471 /* If bit [14] = 0 or bit [13] = 0, continue on with
2472 system initialization (XAUI work-around not required,
2473 as these bits indicate 2.5G or 1G link up). */
2474 if (!(val & (1<<14)) || !(val & (1<<13))) {
2475 DP(NETIF_MSG_LINK, "XAUI work-around not required\n");
2476 return 0;
2477 } else if (!(val & (1<<15))) {
2478 DP(NETIF_MSG_LINK, "clc bit 15 went off\n");
2479 /* If bit 15 is 0, then poll Dev1, Reg $C841 until
2480 it's MSB (bit 15) goes to 1 (indicating that the
2481 XAUI workaround has completed),
2482 then continue on with system initialization.*/
2483 for (cnt1 = 0; cnt1 < 1000; cnt1++) {
2484 bnx2x_cl45_read(bp, params->port,
2485 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073,
2486 ext_phy_addr,
2487 MDIO_PMA_DEVAD,
Eilon Greenstein052a38e2009-02-12 08:37:16 +00002488 MDIO_PMA_REG_8073_XAUI_WA, &val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002489 if (val & (1<<15)) {
2490 DP(NETIF_MSG_LINK,
2491 "XAUI workaround has completed\n");
2492 return 0;
2493 }
2494 msleep(3);
2495 }
2496 break;
2497 }
2498 msleep(3);
2499 }
2500 DP(NETIF_MSG_LINK, "Warning: XAUI work-around timeout !!!\n");
2501 return -EINVAL;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002502}
2503
Eilon Greenstein4d295db2009-07-21 05:47:47 +00002504static void bnx2x_bcm8073_bcm8727_external_rom_boot(struct bnx2x *bp, u8 port,
2505 u8 ext_phy_addr,
2506 u32 ext_phy_type,
2507 u32 shmem_base)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002508{
Yaniv Rosner6bbca912008-08-13 15:57:28 -07002509 /* Boot port from external ROM */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002510 /* EDC grst */
Yaniv Rosner6bbca912008-08-13 15:57:28 -07002511 bnx2x_cl45_write(bp, port,
Eilon Greenstein4d295db2009-07-21 05:47:47 +00002512 ext_phy_type,
Yaniv Rosner6bbca912008-08-13 15:57:28 -07002513 ext_phy_addr,
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002514 MDIO_PMA_DEVAD,
2515 MDIO_PMA_REG_GEN_CTRL,
2516 0x0001);
2517
2518 /* ucode reboot and rst */
Yaniv Rosner6bbca912008-08-13 15:57:28 -07002519 bnx2x_cl45_write(bp, port,
Eilon Greenstein4d295db2009-07-21 05:47:47 +00002520 ext_phy_type,
Yaniv Rosner6bbca912008-08-13 15:57:28 -07002521 ext_phy_addr,
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002522 MDIO_PMA_DEVAD,
2523 MDIO_PMA_REG_GEN_CTRL,
2524 0x008c);
2525
Yaniv Rosner6bbca912008-08-13 15:57:28 -07002526 bnx2x_cl45_write(bp, port,
Eilon Greenstein4d295db2009-07-21 05:47:47 +00002527 ext_phy_type,
Yaniv Rosner6bbca912008-08-13 15:57:28 -07002528 ext_phy_addr,
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002529 MDIO_PMA_DEVAD,
2530 MDIO_PMA_REG_MISC_CTRL1, 0x0001);
2531
2532 /* Reset internal microprocessor */
Yaniv Rosner6bbca912008-08-13 15:57:28 -07002533 bnx2x_cl45_write(bp, port,
Eilon Greenstein4d295db2009-07-21 05:47:47 +00002534 ext_phy_type,
Yaniv Rosner6bbca912008-08-13 15:57:28 -07002535 ext_phy_addr,
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002536 MDIO_PMA_DEVAD,
2537 MDIO_PMA_REG_GEN_CTRL,
2538 MDIO_PMA_REG_GEN_CTRL_ROM_MICRO_RESET);
2539
2540 /* Release srst bit */
Yaniv Rosner6bbca912008-08-13 15:57:28 -07002541 bnx2x_cl45_write(bp, port,
Eilon Greenstein4d295db2009-07-21 05:47:47 +00002542 ext_phy_type,
Yaniv Rosner6bbca912008-08-13 15:57:28 -07002543 ext_phy_addr,
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002544 MDIO_PMA_DEVAD,
2545 MDIO_PMA_REG_GEN_CTRL,
2546 MDIO_PMA_REG_GEN_CTRL_ROM_RESET_INTERNAL_MP);
2547
2548 /* wait for 100ms for code download via SPI port */
2549 msleep(100);
2550
2551 /* Clear ser_boot_ctl bit */
Yaniv Rosner6bbca912008-08-13 15:57:28 -07002552 bnx2x_cl45_write(bp, port,
Eilon Greenstein4d295db2009-07-21 05:47:47 +00002553 ext_phy_type,
Yaniv Rosner6bbca912008-08-13 15:57:28 -07002554 ext_phy_addr,
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002555 MDIO_PMA_DEVAD,
2556 MDIO_PMA_REG_MISC_CTRL1, 0x0000);
2557
Eilon Greensteina35da8d2009-02-12 08:37:02 +00002558 bnx2x_save_bcm_spirom_ver(bp, port,
Eilon Greenstein4d295db2009-07-21 05:47:47 +00002559 ext_phy_type,
Eilon Greensteina35da8d2009-02-12 08:37:02 +00002560 ext_phy_addr,
2561 shmem_base);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002562}
2563
Eilon Greenstein4d295db2009-07-21 05:47:47 +00002564static void bnx2x_bcm8073_external_rom_boot(struct bnx2x *bp, u8 port,
2565 u8 ext_phy_addr,
2566 u32 shmem_base)
2567{
2568 bnx2x_bcm8073_bcm8727_external_rom_boot(bp, port, ext_phy_addr,
2569 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073,
2570 shmem_base);
2571}
2572
2573static void bnx2x_bcm8727_external_rom_boot(struct bnx2x *bp, u8 port,
2574 u8 ext_phy_addr,
2575 u32 shmem_base)
2576{
2577 bnx2x_bcm8073_bcm8727_external_rom_boot(bp, port, ext_phy_addr,
2578 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727,
2579 shmem_base);
2580
2581}
2582
Eilon Greenstein589abe32009-02-12 08:36:55 +00002583static void bnx2x_bcm8726_external_rom_boot(struct link_params *params)
2584{
2585 struct bnx2x *bp = params->bp;
2586 u8 port = params->port;
Eilon Greenstein659bc5c2009-08-12 08:24:02 +00002587 u8 ext_phy_addr = XGXS_EXT_PHY_ADDR(params->ext_phy_config);
Eilon Greenstein589abe32009-02-12 08:36:55 +00002588 u32 ext_phy_type = XGXS_EXT_PHY_TYPE(params->ext_phy_config);
2589
2590 /* Need to wait 100ms after reset */
2591 msleep(100);
2592
2593 /* Set serial boot control for external load */
2594 bnx2x_cl45_write(bp, port, ext_phy_type, ext_phy_addr,
2595 MDIO_PMA_DEVAD,
2596 MDIO_PMA_REG_MISC_CTRL1, 0x0001);
2597
2598 /* Micro controller re-boot */
2599 bnx2x_cl45_write(bp, port, ext_phy_type, ext_phy_addr,
2600 MDIO_PMA_DEVAD,
2601 MDIO_PMA_REG_GEN_CTRL,
2602 MDIO_PMA_REG_GEN_CTRL_ROM_RESET_INTERNAL_MP);
2603
2604 /* Set soft reset */
2605 bnx2x_cl45_write(bp, port, ext_phy_type, ext_phy_addr,
2606 MDIO_PMA_DEVAD,
2607 MDIO_PMA_REG_GEN_CTRL,
2608 MDIO_PMA_REG_GEN_CTRL_ROM_MICRO_RESET);
2609
Eilon Greenstein4d295db2009-07-21 05:47:47 +00002610 /* Set PLL register value to be same like in P13 ver */
Eilon Greensteincc1cb002009-03-02 08:00:03 +00002611 bnx2x_cl45_write(bp, port, ext_phy_type, ext_phy_addr,
2612 MDIO_PMA_DEVAD,
Eilon Greenstein4d295db2009-07-21 05:47:47 +00002613 MDIO_PMA_REG_PLL_CTRL,
Eilon Greensteincc1cb002009-03-02 08:00:03 +00002614 0x73A0);
2615
Eilon Greenstein589abe32009-02-12 08:36:55 +00002616 /* Clear soft reset.
2617 Will automatically reset micro-controller re-boot */
2618 bnx2x_cl45_write(bp, port, ext_phy_type, ext_phy_addr,
2619 MDIO_PMA_DEVAD,
2620 MDIO_PMA_REG_GEN_CTRL,
2621 MDIO_PMA_REG_GEN_CTRL_ROM_RESET_INTERNAL_MP);
2622
Eilon Greensteincc1cb002009-03-02 08:00:03 +00002623 /* wait for 150ms for microcode load */
2624 msleep(150);
Eilon Greenstein589abe32009-02-12 08:36:55 +00002625
2626 /* Disable serial boot control, tristates pins SS_N, SCK, MOSI, MISO */
2627 bnx2x_cl45_write(bp, port, ext_phy_type, ext_phy_addr,
2628 MDIO_PMA_DEVAD,
2629 MDIO_PMA_REG_MISC_CTRL1, 0x0000);
2630
2631 msleep(200);
Eilon Greensteina35da8d2009-02-12 08:37:02 +00002632 bnx2x_save_bcm_spirom_ver(bp, port,
2633 ext_phy_type,
2634 ext_phy_addr,
2635 params->shmem_base);
Eilon Greenstein589abe32009-02-12 08:36:55 +00002636}
2637
Eilon Greenstein4d295db2009-07-21 05:47:47 +00002638static void bnx2x_sfp_set_transmitter(struct bnx2x *bp, u8 port,
2639 u32 ext_phy_type, u8 ext_phy_addr,
2640 u8 tx_en)
Eilon Greenstein589abe32009-02-12 08:36:55 +00002641{
2642 u16 val;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00002643
Eilon Greenstein589abe32009-02-12 08:36:55 +00002644 DP(NETIF_MSG_LINK, "Setting transmitter tx_en=%x for port %x\n",
2645 tx_en, port);
2646 /* Disable/Enable transmitter ( TX laser of the SFP+ module.)*/
2647 bnx2x_cl45_read(bp, port,
Eilon Greenstein4d295db2009-07-21 05:47:47 +00002648 ext_phy_type,
Eilon Greenstein589abe32009-02-12 08:36:55 +00002649 ext_phy_addr,
2650 MDIO_PMA_DEVAD,
2651 MDIO_PMA_REG_PHY_IDENTIFIER,
2652 &val);
2653
2654 if (tx_en)
2655 val &= ~(1<<15);
2656 else
2657 val |= (1<<15);
2658
2659 bnx2x_cl45_write(bp, port,
Eilon Greenstein4d295db2009-07-21 05:47:47 +00002660 ext_phy_type,
Eilon Greenstein589abe32009-02-12 08:36:55 +00002661 ext_phy_addr,
2662 MDIO_PMA_DEVAD,
2663 MDIO_PMA_REG_PHY_IDENTIFIER,
2664 val);
2665}
2666
Eilon Greenstein4d295db2009-07-21 05:47:47 +00002667static u8 bnx2x_8726_read_sfp_module_eeprom(struct link_params *params,
2668 u16 addr, u8 byte_cnt, u8 *o_buf)
2669{
Eilon Greenstein589abe32009-02-12 08:36:55 +00002670 struct bnx2x *bp = params->bp;
Eilon Greenstein4d295db2009-07-21 05:47:47 +00002671 u16 val = 0;
2672 u16 i;
Eilon Greenstein589abe32009-02-12 08:36:55 +00002673 u8 port = params->port;
Eilon Greenstein659bc5c2009-08-12 08:24:02 +00002674 u8 ext_phy_addr = XGXS_EXT_PHY_ADDR(params->ext_phy_config);
Eilon Greenstein589abe32009-02-12 08:36:55 +00002675 u32 ext_phy_type = XGXS_EXT_PHY_TYPE(params->ext_phy_config);
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00002676
Eilon Greenstein589abe32009-02-12 08:36:55 +00002677 if (byte_cnt > 16) {
2678 DP(NETIF_MSG_LINK, "Reading from eeprom is"
2679 " is limited to 0xf\n");
2680 return -EINVAL;
2681 }
2682 /* Set the read command byte count */
2683 bnx2x_cl45_write(bp, port,
2684 ext_phy_type,
2685 ext_phy_addr,
2686 MDIO_PMA_DEVAD,
Eilon Greenstein4d295db2009-07-21 05:47:47 +00002687 MDIO_PMA_REG_SFP_TWO_WIRE_BYTE_CNT,
Eilon Greenstein589abe32009-02-12 08:36:55 +00002688 (byte_cnt | 0xa000));
2689
2690 /* Set the read command address */
2691 bnx2x_cl45_write(bp, port,
2692 ext_phy_type,
2693 ext_phy_addr,
2694 MDIO_PMA_DEVAD,
Eilon Greenstein4d295db2009-07-21 05:47:47 +00002695 MDIO_PMA_REG_SFP_TWO_WIRE_MEM_ADDR,
Eilon Greenstein589abe32009-02-12 08:36:55 +00002696 addr);
2697
2698 /* Activate read command */
2699 bnx2x_cl45_write(bp, port,
2700 ext_phy_type,
2701 ext_phy_addr,
2702 MDIO_PMA_DEVAD,
Eilon Greenstein4d295db2009-07-21 05:47:47 +00002703 MDIO_PMA_REG_SFP_TWO_WIRE_CTRL,
Eilon Greenstein589abe32009-02-12 08:36:55 +00002704 0x2c0f);
2705
2706 /* Wait up to 500us for command complete status */
2707 for (i = 0; i < 100; i++) {
2708 bnx2x_cl45_read(bp, port,
2709 ext_phy_type,
2710 ext_phy_addr,
2711 MDIO_PMA_DEVAD,
Eilon Greenstein4d295db2009-07-21 05:47:47 +00002712 MDIO_PMA_REG_SFP_TWO_WIRE_CTRL, &val);
2713 if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) ==
2714 MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_COMPLETE)
Eilon Greenstein589abe32009-02-12 08:36:55 +00002715 break;
2716 udelay(5);
2717 }
2718
Eilon Greenstein4d295db2009-07-21 05:47:47 +00002719 if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) !=
2720 MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_COMPLETE) {
Eilon Greenstein589abe32009-02-12 08:36:55 +00002721 DP(NETIF_MSG_LINK,
2722 "Got bad status 0x%x when reading from SFP+ EEPROM\n",
Eilon Greenstein4d295db2009-07-21 05:47:47 +00002723 (val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK));
Eilon Greenstein589abe32009-02-12 08:36:55 +00002724 return -EINVAL;
2725 }
2726
2727 /* Read the buffer */
2728 for (i = 0; i < byte_cnt; i++) {
2729 bnx2x_cl45_read(bp, port,
2730 ext_phy_type,
2731 ext_phy_addr,
2732 MDIO_PMA_DEVAD,
2733 MDIO_PMA_REG_8726_TWO_WIRE_DATA_BUF + i, &val);
2734 o_buf[i] = (u8)(val & MDIO_PMA_REG_8726_TWO_WIRE_DATA_MASK);
2735 }
2736
2737 for (i = 0; i < 100; i++) {
2738 bnx2x_cl45_read(bp, port,
2739 ext_phy_type,
2740 ext_phy_addr,
2741 MDIO_PMA_DEVAD,
Eilon Greenstein4d295db2009-07-21 05:47:47 +00002742 MDIO_PMA_REG_SFP_TWO_WIRE_CTRL, &val);
2743 if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) ==
2744 MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_IDLE)
Eilon Greenstein589abe32009-02-12 08:36:55 +00002745 return 0;;
2746 msleep(1);
2747 }
2748 return -EINVAL;
2749}
2750
Eilon Greenstein4d295db2009-07-21 05:47:47 +00002751static u8 bnx2x_8727_read_sfp_module_eeprom(struct link_params *params,
2752 u16 addr, u8 byte_cnt, u8 *o_buf)
Eilon Greenstein589abe32009-02-12 08:36:55 +00002753{
2754 struct bnx2x *bp = params->bp;
Eilon Greenstein4d295db2009-07-21 05:47:47 +00002755 u16 val, i;
2756 u8 port = params->port;
Eilon Greenstein659bc5c2009-08-12 08:24:02 +00002757 u8 ext_phy_addr = XGXS_EXT_PHY_ADDR(params->ext_phy_config);
Eilon Greenstein4d295db2009-07-21 05:47:47 +00002758 u32 ext_phy_type = XGXS_EXT_PHY_TYPE(params->ext_phy_config);
2759
2760 if (byte_cnt > 16) {
2761 DP(NETIF_MSG_LINK, "Reading from eeprom is"
2762 " is limited to 0xf\n");
2763 return -EINVAL;
2764 }
2765
2766 /* Need to read from 1.8000 to clear it */
2767 bnx2x_cl45_read(bp, port,
2768 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727,
2769 ext_phy_addr,
2770 MDIO_PMA_DEVAD,
2771 MDIO_PMA_REG_SFP_TWO_WIRE_CTRL,
2772 &val);
2773
2774 /* Set the read command byte count */
2775 bnx2x_cl45_write(bp, port,
2776 ext_phy_type,
2777 ext_phy_addr,
2778 MDIO_PMA_DEVAD,
2779 MDIO_PMA_REG_SFP_TWO_WIRE_BYTE_CNT,
2780 ((byte_cnt < 2) ? 2 : byte_cnt));
2781
2782 /* Set the read command address */
2783 bnx2x_cl45_write(bp, port,
2784 ext_phy_type,
2785 ext_phy_addr,
2786 MDIO_PMA_DEVAD,
2787 MDIO_PMA_REG_SFP_TWO_WIRE_MEM_ADDR,
2788 addr);
2789 /* Set the destination address */
2790 bnx2x_cl45_write(bp, port,
2791 ext_phy_type,
2792 ext_phy_addr,
2793 MDIO_PMA_DEVAD,
2794 0x8004,
2795 MDIO_PMA_REG_8727_TWO_WIRE_DATA_BUF);
2796
2797 /* Activate read command */
2798 bnx2x_cl45_write(bp, port,
2799 ext_phy_type,
2800 ext_phy_addr,
2801 MDIO_PMA_DEVAD,
2802 MDIO_PMA_REG_SFP_TWO_WIRE_CTRL,
2803 0x8002);
2804 /* Wait appropriate time for two-wire command to finish before
2805 polling the status register */
2806 msleep(1);
2807
2808 /* Wait up to 500us for command complete status */
2809 for (i = 0; i < 100; i++) {
2810 bnx2x_cl45_read(bp, port,
2811 ext_phy_type,
2812 ext_phy_addr,
2813 MDIO_PMA_DEVAD,
2814 MDIO_PMA_REG_SFP_TWO_WIRE_CTRL, &val);
2815 if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) ==
2816 MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_COMPLETE)
2817 break;
2818 udelay(5);
2819 }
2820
2821 if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) !=
2822 MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_COMPLETE) {
2823 DP(NETIF_MSG_LINK,
2824 "Got bad status 0x%x when reading from SFP+ EEPROM\n",
2825 (val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK));
2826 return -EINVAL;
2827 }
2828
2829 /* Read the buffer */
2830 for (i = 0; i < byte_cnt; i++) {
2831 bnx2x_cl45_read(bp, port,
2832 ext_phy_type,
2833 ext_phy_addr,
2834 MDIO_PMA_DEVAD,
2835 MDIO_PMA_REG_8727_TWO_WIRE_DATA_BUF + i, &val);
2836 o_buf[i] = (u8)(val & MDIO_PMA_REG_8727_TWO_WIRE_DATA_MASK);
2837 }
2838
2839 for (i = 0; i < 100; i++) {
2840 bnx2x_cl45_read(bp, port,
2841 ext_phy_type,
2842 ext_phy_addr,
2843 MDIO_PMA_DEVAD,
2844 MDIO_PMA_REG_SFP_TWO_WIRE_CTRL, &val);
2845 if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) ==
2846 MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_IDLE)
2847 return 0;;
2848 msleep(1);
2849 }
2850
2851 return -EINVAL;
2852}
2853
2854u8 bnx2x_read_sfp_module_eeprom(struct link_params *params, u16 addr,
2855 u8 byte_cnt, u8 *o_buf)
2856{
2857 u32 ext_phy_type = XGXS_EXT_PHY_TYPE(params->ext_phy_config);
2858
2859 if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726)
2860 return bnx2x_8726_read_sfp_module_eeprom(params, addr,
2861 byte_cnt, o_buf);
2862 else if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727)
2863 return bnx2x_8727_read_sfp_module_eeprom(params, addr,
2864 byte_cnt, o_buf);
2865 return -EINVAL;
2866}
2867
2868static u8 bnx2x_get_edc_mode(struct link_params *params,
2869 u16 *edc_mode)
2870{
2871 struct bnx2x *bp = params->bp;
2872 u8 val, check_limiting_mode = 0;
2873 *edc_mode = EDC_MODE_LIMITING;
Eilon Greenstein589abe32009-02-12 08:36:55 +00002874
2875 /* First check for copper cable */
2876 if (bnx2x_read_sfp_module_eeprom(params,
2877 SFP_EEPROM_CON_TYPE_ADDR,
2878 1,
2879 &val) != 0) {
Eilon Greenstein4d295db2009-07-21 05:47:47 +00002880 DP(NETIF_MSG_LINK, "Failed to read from SFP+ module EEPROM\n");
Eilon Greenstein589abe32009-02-12 08:36:55 +00002881 return -EINVAL;
2882 }
2883
2884 switch (val) {
2885 case SFP_EEPROM_CON_TYPE_VAL_COPPER:
2886 {
2887 u8 copper_module_type;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00002888
Eilon Greenstein589abe32009-02-12 08:36:55 +00002889 /* Check if its active cable( includes SFP+ module)
2890 of passive cable*/
2891 if (bnx2x_read_sfp_module_eeprom(params,
2892 SFP_EEPROM_FC_TX_TECH_ADDR,
2893 1,
2894 &copper_module_type) !=
2895 0) {
2896 DP(NETIF_MSG_LINK,
2897 "Failed to read copper-cable-type"
2898 " from SFP+ EEPROM\n");
2899 return -EINVAL;
2900 }
2901
2902 if (copper_module_type &
2903 SFP_EEPROM_FC_TX_TECH_BITMASK_COPPER_ACTIVE) {
2904 DP(NETIF_MSG_LINK, "Active Copper cable detected\n");
Eilon Greenstein4d295db2009-07-21 05:47:47 +00002905 check_limiting_mode = 1;
Eilon Greenstein589abe32009-02-12 08:36:55 +00002906 } else if (copper_module_type &
2907 SFP_EEPROM_FC_TX_TECH_BITMASK_COPPER_PASSIVE) {
2908 DP(NETIF_MSG_LINK, "Passive Copper"
2909 " cable detected\n");
Eilon Greenstein4d295db2009-07-21 05:47:47 +00002910 *edc_mode =
2911 EDC_MODE_PASSIVE_DAC;
Eilon Greenstein589abe32009-02-12 08:36:55 +00002912 } else {
2913 DP(NETIF_MSG_LINK, "Unknown copper-cable-"
2914 "type 0x%x !!!\n", copper_module_type);
2915 return -EINVAL;
2916 }
2917 break;
2918 }
2919 case SFP_EEPROM_CON_TYPE_VAL_LC:
2920 DP(NETIF_MSG_LINK, "Optic module detected\n");
Eilon Greenstein4d295db2009-07-21 05:47:47 +00002921 check_limiting_mode = 1;
Eilon Greenstein589abe32009-02-12 08:36:55 +00002922 break;
Eilon Greenstein589abe32009-02-12 08:36:55 +00002923 default:
2924 DP(NETIF_MSG_LINK, "Unable to determine module type 0x%x !!!\n",
2925 val);
2926 return -EINVAL;
2927 }
Eilon Greenstein4d295db2009-07-21 05:47:47 +00002928
2929 if (check_limiting_mode) {
2930 u8 options[SFP_EEPROM_OPTIONS_SIZE];
2931 if (bnx2x_read_sfp_module_eeprom(params,
2932 SFP_EEPROM_OPTIONS_ADDR,
2933 SFP_EEPROM_OPTIONS_SIZE,
2934 options) != 0) {
2935 DP(NETIF_MSG_LINK, "Failed to read Option"
2936 " field from module EEPROM\n");
2937 return -EINVAL;
2938 }
2939 if ((options[0] & SFP_EEPROM_OPTIONS_LINEAR_RX_OUT_MASK))
2940 *edc_mode = EDC_MODE_LINEAR;
2941 else
2942 *edc_mode = EDC_MODE_LIMITING;
2943 }
2944 DP(NETIF_MSG_LINK, "EDC mode is set to 0x%x\n", *edc_mode);
Eilon Greenstein589abe32009-02-12 08:36:55 +00002945 return 0;
2946}
2947
Eilon Greenstein589abe32009-02-12 08:36:55 +00002948/* This function read the relevant field from the module ( SFP+ ),
2949 and verify it is compliant with this board */
Eilon Greenstein4d295db2009-07-21 05:47:47 +00002950static u8 bnx2x_verify_sfp_module(struct link_params *params)
Eilon Greenstein589abe32009-02-12 08:36:55 +00002951{
2952 struct bnx2x *bp = params->bp;
Eilon Greenstein4d295db2009-07-21 05:47:47 +00002953 u32 val;
2954 u32 fw_resp;
2955 char vendor_name[SFP_EEPROM_VENDOR_NAME_SIZE+1];
2956 char vendor_pn[SFP_EEPROM_PART_NO_SIZE+1];
Eilon Greenstein589abe32009-02-12 08:36:55 +00002957
Eilon Greenstein4d295db2009-07-21 05:47:47 +00002958 val = REG_RD(bp, params->shmem_base +
2959 offsetof(struct shmem_region, dev_info.
2960 port_feature_config[params->port].config));
2961 if ((val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) ==
2962 PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_NO_ENFORCEMENT) {
Eilon Greenstein589abe32009-02-12 08:36:55 +00002963 DP(NETIF_MSG_LINK, "NOT enforcing module verification\n");
2964 return 0;
2965 }
2966
Eilon Greenstein4d295db2009-07-21 05:47:47 +00002967 /* Ask the FW to validate the module */
2968 if (!(params->feature_config_flags &
2969 FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY)) {
2970 DP(NETIF_MSG_LINK, "FW does not support OPT MDL "
2971 "verification\n");
2972 return -EINVAL;
2973 }
2974
2975 fw_resp = bnx2x_fw_command(bp, DRV_MSG_CODE_VRFY_OPT_MDL);
2976 if (fw_resp == FW_MSG_CODE_VRFY_OPT_MDL_SUCCESS) {
2977 DP(NETIF_MSG_LINK, "Approved module\n");
Eilon Greenstein589abe32009-02-12 08:36:55 +00002978 return 0;
2979 }
2980
Eilon Greenstein4d295db2009-07-21 05:47:47 +00002981 /* format the warning message */
Eilon Greenstein589abe32009-02-12 08:36:55 +00002982 if (bnx2x_read_sfp_module_eeprom(params,
2983 SFP_EEPROM_VENDOR_NAME_ADDR,
2984 SFP_EEPROM_VENDOR_NAME_SIZE,
Eilon Greenstein4d295db2009-07-21 05:47:47 +00002985 (u8 *)vendor_name))
2986 vendor_name[0] = '\0';
2987 else
2988 vendor_name[SFP_EEPROM_VENDOR_NAME_SIZE] = '\0';
2989 if (bnx2x_read_sfp_module_eeprom(params,
2990 SFP_EEPROM_PART_NO_ADDR,
2991 SFP_EEPROM_PART_NO_SIZE,
2992 (u8 *)vendor_pn))
2993 vendor_pn[0] = '\0';
2994 else
2995 vendor_pn[SFP_EEPROM_PART_NO_SIZE] = '\0';
Eilon Greenstein589abe32009-02-12 08:36:55 +00002996
Eilon Greenstein4d295db2009-07-21 05:47:47 +00002997 printk(KERN_INFO PFX "Warning: "
2998 "Unqualified SFP+ module "
2999 "detected on %s, Port %d from %s part number %s\n"
3000 , bp->dev->name, params->port,
3001 vendor_name, vendor_pn);
Eilon Greenstein589abe32009-02-12 08:36:55 +00003002 return -EINVAL;
3003}
3004
Eilon Greenstein589abe32009-02-12 08:36:55 +00003005static u8 bnx2x_bcm8726_set_limiting_mode(struct link_params *params,
Eilon Greenstein4d295db2009-07-21 05:47:47 +00003006 u16 edc_mode)
Eilon Greenstein589abe32009-02-12 08:36:55 +00003007{
3008 struct bnx2x *bp = params->bp;
3009 u8 port = params->port;
Eilon Greenstein659bc5c2009-08-12 08:24:02 +00003010 u8 ext_phy_addr = XGXS_EXT_PHY_ADDR(params->ext_phy_config);
Eilon Greensteincc1cb002009-03-02 08:00:03 +00003011 u16 cur_limiting_mode;
Eilon Greensteincc1cb002009-03-02 08:00:03 +00003012
3013 bnx2x_cl45_read(bp, port,
3014 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726,
3015 ext_phy_addr,
3016 MDIO_PMA_DEVAD,
3017 MDIO_PMA_REG_ROM_VER2,
3018 &cur_limiting_mode);
3019 DP(NETIF_MSG_LINK, "Current Limiting mode is 0x%x\n",
3020 cur_limiting_mode);
3021
Eilon Greenstein4d295db2009-07-21 05:47:47 +00003022 if (edc_mode == EDC_MODE_LIMITING) {
Eilon Greenstein589abe32009-02-12 08:36:55 +00003023 DP(NETIF_MSG_LINK,
Eilon Greenstein4d295db2009-07-21 05:47:47 +00003024 "Setting LIMITING MODE\n");
Eilon Greenstein589abe32009-02-12 08:36:55 +00003025 bnx2x_cl45_write(bp, port,
3026 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726,
3027 ext_phy_addr,
3028 MDIO_PMA_DEVAD,
3029 MDIO_PMA_REG_ROM_VER2,
Eilon Greenstein4d295db2009-07-21 05:47:47 +00003030 EDC_MODE_LIMITING);
Eilon Greenstein589abe32009-02-12 08:36:55 +00003031 } else { /* LRM mode ( default )*/
Eilon Greensteincc1cb002009-03-02 08:00:03 +00003032
Eilon Greenstein4d295db2009-07-21 05:47:47 +00003033 DP(NETIF_MSG_LINK, "Setting LRM MODE\n");
Eilon Greenstein589abe32009-02-12 08:36:55 +00003034
Eilon Greenstein589abe32009-02-12 08:36:55 +00003035 /* Changing to LRM mode takes quite few seconds.
3036 So do it only if current mode is limiting
3037 ( default is LRM )*/
Eilon Greenstein4d295db2009-07-21 05:47:47 +00003038 if (cur_limiting_mode != EDC_MODE_LIMITING)
Eilon Greenstein589abe32009-02-12 08:36:55 +00003039 return 0;
3040
3041 bnx2x_cl45_write(bp, port,
3042 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726,
3043 ext_phy_addr,
3044 MDIO_PMA_DEVAD,
3045 MDIO_PMA_REG_LRM_MODE,
3046 0);
3047 bnx2x_cl45_write(bp, port,
3048 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726,
3049 ext_phy_addr,
3050 MDIO_PMA_DEVAD,
3051 MDIO_PMA_REG_ROM_VER2,
3052 0x128);
3053 bnx2x_cl45_write(bp, port,
3054 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726,
3055 ext_phy_addr,
3056 MDIO_PMA_DEVAD,
3057 MDIO_PMA_REG_MISC_CTRL0,
3058 0x4008);
3059 bnx2x_cl45_write(bp, port,
3060 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726,
3061 ext_phy_addr,
3062 MDIO_PMA_DEVAD,
3063 MDIO_PMA_REG_LRM_MODE,
3064 0xaaaa);
3065 }
3066 return 0;
3067}
3068
Eilon Greenstein4d295db2009-07-21 05:47:47 +00003069static u8 bnx2x_bcm8727_set_limiting_mode(struct link_params *params,
3070 u16 edc_mode)
3071{
3072 struct bnx2x *bp = params->bp;
3073 u8 port = params->port;
3074 u16 phy_identifier;
3075 u16 rom_ver2_val;
Eilon Greenstein659bc5c2009-08-12 08:24:02 +00003076 u8 ext_phy_addr = XGXS_EXT_PHY_ADDR(params->ext_phy_config);
Eilon Greenstein4d295db2009-07-21 05:47:47 +00003077
3078 bnx2x_cl45_read(bp, port,
3079 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727,
3080 ext_phy_addr,
3081 MDIO_PMA_DEVAD,
3082 MDIO_PMA_REG_PHY_IDENTIFIER,
3083 &phy_identifier);
3084
3085 bnx2x_cl45_write(bp, port,
3086 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727,
3087 ext_phy_addr,
3088 MDIO_PMA_DEVAD,
3089 MDIO_PMA_REG_PHY_IDENTIFIER,
3090 (phy_identifier & ~(1<<9)));
3091
3092 bnx2x_cl45_read(bp, port,
3093 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727,
3094 ext_phy_addr,
3095 MDIO_PMA_DEVAD,
3096 MDIO_PMA_REG_ROM_VER2,
3097 &rom_ver2_val);
3098 /* Keep the MSB 8-bits, and set the LSB 8-bits with the edc_mode */
3099 bnx2x_cl45_write(bp, port,
3100 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727,
3101 ext_phy_addr,
3102 MDIO_PMA_DEVAD,
3103 MDIO_PMA_REG_ROM_VER2,
3104 (rom_ver2_val & 0xff00) | (edc_mode & 0x00ff));
3105
3106 bnx2x_cl45_write(bp, port,
3107 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727,
3108 ext_phy_addr,
3109 MDIO_PMA_DEVAD,
3110 MDIO_PMA_REG_PHY_IDENTIFIER,
3111 (phy_identifier | (1<<9)));
3112
3113 return 0;
3114}
3115
3116
Eilon Greenstein589abe32009-02-12 08:36:55 +00003117static u8 bnx2x_wait_for_sfp_module_initialized(struct link_params *params)
3118{
3119 u8 val;
3120 struct bnx2x *bp = params->bp;
3121 u16 timeout;
3122 /* Initialization time after hot-plug may take up to 300ms for some
3123 phys type ( e.g. JDSU ) */
3124 for (timeout = 0; timeout < 60; timeout++) {
3125 if (bnx2x_read_sfp_module_eeprom(params, 1, 1, &val)
3126 == 0) {
3127 DP(NETIF_MSG_LINK, "SFP+ module initialization "
3128 "took %d ms\n", timeout * 5);
3129 return 0;
3130 }
3131 msleep(5);
3132 }
3133 return -EINVAL;
3134}
3135
Eilon Greenstein4d295db2009-07-21 05:47:47 +00003136static void bnx2x_8727_power_module(struct bnx2x *bp,
3137 struct link_params *params,
3138 u8 ext_phy_addr, u8 is_power_up) {
3139 /* Make sure GPIOs are not using for LED mode */
3140 u16 val;
3141 u8 port = params->port;
3142 /*
3143 * In the GPIO register, bit 4 is use to detemine if the GPIOs are
3144 * operating as INPUT or as OUTPUT. Bit 1 is for input, and 0 for
3145 * output
3146 * Bits 0-1 determine the gpios value for OUTPUT in case bit 4 val is 0
3147 * Bits 8-9 determine the gpios value for INPUT in case bit 4 val is 1
3148 * where the 1st bit is the over-current(only input), and 2nd bit is
3149 * for power( only output )
3150 */
3151
3152 /*
3153 * In case of NOC feature is disabled and power is up, set GPIO control
3154 * as input to enable listening of over-current indication
3155 */
3156
3157 if (!(params->feature_config_flags &
3158 FEATURE_CONFIG_BCM8727_NOC) && is_power_up)
3159 val = (1<<4);
3160 else
3161 /*
3162 * Set GPIO control to OUTPUT, and set the power bit
3163 * to according to the is_power_up
3164 */
3165 val = ((!(is_power_up)) << 1);
3166
3167 bnx2x_cl45_write(bp, port,
3168 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727,
3169 ext_phy_addr,
3170 MDIO_PMA_DEVAD,
3171 MDIO_PMA_REG_8727_GPIO_CTRL,
3172 val);
3173}
3174
Eilon Greenstein589abe32009-02-12 08:36:55 +00003175static u8 bnx2x_sfp_module_detection(struct link_params *params)
3176{
3177 struct bnx2x *bp = params->bp;
Eilon Greenstein4d295db2009-07-21 05:47:47 +00003178 u16 edc_mode;
3179 u8 rc = 0;
Eilon Greenstein659bc5c2009-08-12 08:24:02 +00003180 u8 ext_phy_addr = XGXS_EXT_PHY_ADDR(params->ext_phy_config);
Eilon Greenstein589abe32009-02-12 08:36:55 +00003181 u32 ext_phy_type = XGXS_EXT_PHY_TYPE(params->ext_phy_config);
Eilon Greenstein4d295db2009-07-21 05:47:47 +00003182 u32 val = REG_RD(bp, params->shmem_base +
3183 offsetof(struct shmem_region, dev_info.
3184 port_feature_config[params->port].config));
Eilon Greenstein589abe32009-02-12 08:36:55 +00003185
3186 DP(NETIF_MSG_LINK, "SFP+ module plugged in/out detected on port %d\n",
3187 params->port);
3188
Eilon Greenstein4d295db2009-07-21 05:47:47 +00003189 if (bnx2x_get_edc_mode(params, &edc_mode) != 0) {
Eilon Greenstein589abe32009-02-12 08:36:55 +00003190 DP(NETIF_MSG_LINK, "Failed to get valid module type\n");
Eilon Greenstein4d295db2009-07-21 05:47:47 +00003191 return -EINVAL;
3192 } else if (bnx2x_verify_sfp_module(params) !=
Eilon Greenstein589abe32009-02-12 08:36:55 +00003193 0) {
3194 /* check SFP+ module compatibility */
3195 DP(NETIF_MSG_LINK, "Module verification failed!!\n");
Eilon Greenstein4d295db2009-07-21 05:47:47 +00003196 rc = -EINVAL;
Eilon Greenstein589abe32009-02-12 08:36:55 +00003197 /* Turn on fault module-detected led */
3198 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_0,
3199 MISC_REGISTERS_GPIO_HIGH,
3200 params->port);
Eilon Greenstein4d295db2009-07-21 05:47:47 +00003201 if ((ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727) &&
3202 ((val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) ==
3203 PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_POWER_DOWN)) {
3204 /* Shutdown SFP+ module */
3205 DP(NETIF_MSG_LINK, "Shutdown SFP+ module!!\n");
3206 bnx2x_8727_power_module(bp, params,
3207 ext_phy_addr, 0);
3208 return rc;
3209 }
3210 } else {
3211 /* Turn off fault module-detected led */
3212 DP(NETIF_MSG_LINK, "Turn off fault module-detected led\n");
3213 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_0,
3214 MISC_REGISTERS_GPIO_LOW,
3215 params->port);
Eilon Greenstein589abe32009-02-12 08:36:55 +00003216 }
3217
Eilon Greenstein4d295db2009-07-21 05:47:47 +00003218 /* power up the SFP module */
3219 if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727)
3220 bnx2x_8727_power_module(bp, params, ext_phy_addr, 1);
Eilon Greenstein589abe32009-02-12 08:36:55 +00003221
Eilon Greenstein4d295db2009-07-21 05:47:47 +00003222 /* Check and set limiting mode / LRM mode on 8726.
3223 On 8727 it is done automatically */
3224 if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726)
3225 bnx2x_bcm8726_set_limiting_mode(params, edc_mode);
3226 else
3227 bnx2x_bcm8727_set_limiting_mode(params, edc_mode);
3228 /*
3229 * Enable transmit for this module if the module is approved, or
3230 * if unapproved modules should also enable the Tx laser
3231 */
3232 if (rc == 0 ||
3233 (val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) !=
3234 PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_DISABLE_TX_LASER)
3235 bnx2x_sfp_set_transmitter(bp, params->port,
3236 ext_phy_type, ext_phy_addr, 1);
3237 else
3238 bnx2x_sfp_set_transmitter(bp, params->port,
3239 ext_phy_type, ext_phy_addr, 0);
Eilon Greenstein589abe32009-02-12 08:36:55 +00003240
Eilon Greenstein4d295db2009-07-21 05:47:47 +00003241 return rc;
Eilon Greenstein589abe32009-02-12 08:36:55 +00003242}
3243
3244void bnx2x_handle_module_detect_int(struct link_params *params)
3245{
3246 struct bnx2x *bp = params->bp;
3247 u32 gpio_val;
3248 u8 port = params->port;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00003249
Eilon Greenstein589abe32009-02-12 08:36:55 +00003250 /* Set valid module led off */
3251 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_0,
3252 MISC_REGISTERS_GPIO_HIGH,
3253 params->port);
3254
3255 /* Get current gpio val refelecting module plugged in / out*/
3256 gpio_val = bnx2x_get_gpio(bp, MISC_REGISTERS_GPIO_3, port);
3257
3258 /* Call the handling function in case module is detected */
3259 if (gpio_val == 0) {
3260
3261 bnx2x_set_gpio_int(bp, MISC_REGISTERS_GPIO_3,
3262 MISC_REGISTERS_GPIO_INT_OUTPUT_CLR,
3263 port);
3264
Eilon Greenstein4d295db2009-07-21 05:47:47 +00003265 if (bnx2x_wait_for_sfp_module_initialized(params) ==
3266 0)
Eilon Greenstein589abe32009-02-12 08:36:55 +00003267 bnx2x_sfp_module_detection(params);
3268 else
3269 DP(NETIF_MSG_LINK, "SFP+ module is not initialized\n");
3270 } else {
Eilon Greenstein659bc5c2009-08-12 08:24:02 +00003271 u8 ext_phy_addr = XGXS_EXT_PHY_ADDR(params->ext_phy_config);
3272
Eilon Greenstein4d295db2009-07-21 05:47:47 +00003273 u32 ext_phy_type =
3274 XGXS_EXT_PHY_TYPE(params->ext_phy_config);
3275 u32 val = REG_RD(bp, params->shmem_base +
3276 offsetof(struct shmem_region, dev_info.
3277 port_feature_config[params->port].
3278 config));
3279
Eilon Greenstein589abe32009-02-12 08:36:55 +00003280 bnx2x_set_gpio_int(bp, MISC_REGISTERS_GPIO_3,
3281 MISC_REGISTERS_GPIO_INT_OUTPUT_SET,
3282 port);
3283 /* Module was plugged out. */
3284 /* Disable transmit for this module */
Eilon Greenstein4d295db2009-07-21 05:47:47 +00003285 if ((val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) ==
3286 PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_DISABLE_TX_LASER)
3287 bnx2x_sfp_set_transmitter(bp, params->port,
3288 ext_phy_type, ext_phy_addr, 0);
Eilon Greenstein589abe32009-02-12 08:36:55 +00003289 }
3290}
3291
Yaniv Rosner6bbca912008-08-13 15:57:28 -07003292static void bnx2x_bcm807x_force_10G(struct link_params *params)
3293{
3294 struct bnx2x *bp = params->bp;
3295 u8 port = params->port;
Eilon Greenstein659bc5c2009-08-12 08:24:02 +00003296 u8 ext_phy_addr = XGXS_EXT_PHY_ADDR(params->ext_phy_config);
Yaniv Rosner6bbca912008-08-13 15:57:28 -07003297 u32 ext_phy_type = XGXS_EXT_PHY_TYPE(params->ext_phy_config);
3298
3299 /* Force KR or KX */
3300 bnx2x_cl45_write(bp, port, ext_phy_type, ext_phy_addr,
3301 MDIO_PMA_DEVAD,
3302 MDIO_PMA_REG_CTRL,
3303 0x2040);
3304 bnx2x_cl45_write(bp, port, ext_phy_type, ext_phy_addr,
3305 MDIO_PMA_DEVAD,
3306 MDIO_PMA_REG_10G_CTRL2,
3307 0x000b);
3308 bnx2x_cl45_write(bp, port, ext_phy_type, ext_phy_addr,
3309 MDIO_PMA_DEVAD,
3310 MDIO_PMA_REG_BCM_CTRL,
3311 0x0000);
3312 bnx2x_cl45_write(bp, port, ext_phy_type, ext_phy_addr,
3313 MDIO_AN_DEVAD,
3314 MDIO_AN_REG_CTRL,
3315 0x0000);
3316}
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00003317
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003318static void bnx2x_bcm8073_set_xaui_low_power_mode(struct link_params *params)
3319{
3320 struct bnx2x *bp = params->bp;
3321 u8 port = params->port;
3322 u16 val;
Eilon Greenstein659bc5c2009-08-12 08:24:02 +00003323 u8 ext_phy_addr = XGXS_EXT_PHY_ADDR(params->ext_phy_config);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003324 u32 ext_phy_type = XGXS_EXT_PHY_TYPE(params->ext_phy_config);
3325
3326 bnx2x_cl45_read(bp, params->port,
3327 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073,
3328 ext_phy_addr,
3329 MDIO_PMA_DEVAD,
Eilon Greenstein052a38e2009-02-12 08:37:16 +00003330 MDIO_PMA_REG_8073_CHIP_REV, &val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003331
3332 if (val == 0) {
3333 /* Mustn't set low power mode in 8073 A0 */
3334 return;
3335 }
3336
3337 /* Disable PLL sequencer (use read-modify-write to clear bit 13) */
3338 bnx2x_cl45_read(bp, port, ext_phy_type, ext_phy_addr,
3339 MDIO_XS_DEVAD,
3340 MDIO_XS_PLL_SEQUENCER, &val);
3341 val &= ~(1<<13);
3342 bnx2x_cl45_write(bp, port, ext_phy_type, ext_phy_addr,
3343 MDIO_XS_DEVAD, MDIO_XS_PLL_SEQUENCER, val);
3344
3345 /* PLL controls */
3346 bnx2x_cl45_write(bp, port, ext_phy_type, ext_phy_addr,
3347 MDIO_XS_DEVAD, 0x805E, 0x1077);
3348 bnx2x_cl45_write(bp, port, ext_phy_type, ext_phy_addr,
3349 MDIO_XS_DEVAD, 0x805D, 0x0000);
3350 bnx2x_cl45_write(bp, port, ext_phy_type, ext_phy_addr,
3351 MDIO_XS_DEVAD, 0x805C, 0x030B);
3352 bnx2x_cl45_write(bp, port, ext_phy_type, ext_phy_addr,
3353 MDIO_XS_DEVAD, 0x805B, 0x1240);
3354 bnx2x_cl45_write(bp, port, ext_phy_type, ext_phy_addr,
3355 MDIO_XS_DEVAD, 0x805A, 0x2490);
3356
3357 /* Tx Controls */
3358 bnx2x_cl45_write(bp, port, ext_phy_type, ext_phy_addr,
3359 MDIO_XS_DEVAD, 0x80A7, 0x0C74);
3360 bnx2x_cl45_write(bp, port, ext_phy_type, ext_phy_addr,
3361 MDIO_XS_DEVAD, 0x80A6, 0x9041);
3362 bnx2x_cl45_write(bp, port, ext_phy_type, ext_phy_addr,
3363 MDIO_XS_DEVAD, 0x80A5, 0x4640);
3364
3365 /* Rx Controls */
3366 bnx2x_cl45_write(bp, port, ext_phy_type, ext_phy_addr,
3367 MDIO_XS_DEVAD, 0x80FE, 0x01C4);
3368 bnx2x_cl45_write(bp, port, ext_phy_type, ext_phy_addr,
3369 MDIO_XS_DEVAD, 0x80FD, 0x9249);
3370 bnx2x_cl45_write(bp, port, ext_phy_type, ext_phy_addr,
3371 MDIO_XS_DEVAD, 0x80FC, 0x2015);
3372
3373 /* Enable PLL sequencer (use read-modify-write to set bit 13) */
3374 bnx2x_cl45_read(bp, port, ext_phy_type, ext_phy_addr,
3375 MDIO_XS_DEVAD,
3376 MDIO_XS_PLL_SEQUENCER, &val);
3377 val |= (1<<13);
3378 bnx2x_cl45_write(bp, port, ext_phy_type, ext_phy_addr,
3379 MDIO_XS_DEVAD, MDIO_XS_PLL_SEQUENCER, val);
3380}
Yaniv Rosner6bbca912008-08-13 15:57:28 -07003381
3382static void bnx2x_8073_set_pause_cl37(struct link_params *params,
3383 struct link_vars *vars)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003384{
3385 struct bnx2x *bp = params->bp;
Yaniv Rosner6bbca912008-08-13 15:57:28 -07003386 u16 cl37_val;
Eilon Greenstein659bc5c2009-08-12 08:24:02 +00003387 u8 ext_phy_addr = XGXS_EXT_PHY_ADDR(params->ext_phy_config);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003388 u32 ext_phy_type = XGXS_EXT_PHY_TYPE(params->ext_phy_config);
3389
Yaniv Rosner6bbca912008-08-13 15:57:28 -07003390 bnx2x_cl45_read(bp, params->port,
3391 ext_phy_type,
3392 ext_phy_addr,
3393 MDIO_AN_DEVAD,
3394 MDIO_AN_REG_CL37_FC_LD, &cl37_val);
3395
3396 cl37_val &= ~MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH;
3397 /* Please refer to Table 28B-3 of 802.3ab-1999 spec. */
3398
3399 if ((vars->ieee_fc &
3400 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_SYMMETRIC) ==
3401 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_SYMMETRIC) {
3402 cl37_val |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_SYMMETRIC;
3403 }
3404 if ((vars->ieee_fc &
3405 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC) ==
3406 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC) {
3407 cl37_val |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC;
3408 }
3409 if ((vars->ieee_fc &
3410 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) ==
3411 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) {
3412 cl37_val |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH;
3413 }
3414 DP(NETIF_MSG_LINK,
3415 "Ext phy AN advertize cl37 0x%x\n", cl37_val);
3416
3417 bnx2x_cl45_write(bp, params->port,
3418 ext_phy_type,
3419 ext_phy_addr,
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003420 MDIO_AN_DEVAD,
Yaniv Rosner6bbca912008-08-13 15:57:28 -07003421 MDIO_AN_REG_CL37_FC_LD, cl37_val);
3422 msleep(500);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003423}
3424
3425static void bnx2x_ext_phy_set_pause(struct link_params *params,
3426 struct link_vars *vars)
3427{
3428 struct bnx2x *bp = params->bp;
3429 u16 val;
Eilon Greenstein659bc5c2009-08-12 08:24:02 +00003430 u8 ext_phy_addr = XGXS_EXT_PHY_ADDR(params->ext_phy_config);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003431 u32 ext_phy_type = XGXS_EXT_PHY_TYPE(params->ext_phy_config);
3432
3433 /* read modify write pause advertizing */
3434 bnx2x_cl45_read(bp, params->port,
3435 ext_phy_type,
3436 ext_phy_addr,
3437 MDIO_AN_DEVAD,
3438 MDIO_AN_REG_ADV_PAUSE, &val);
3439
3440 val &= ~MDIO_AN_REG_ADV_PAUSE_BOTH;
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07003441
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003442 /* Please refer to Table 28B-3 of 802.3ab-1999 spec. */
3443
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07003444 if ((vars->ieee_fc &
3445 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC) ==
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003446 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC) {
3447 val |= MDIO_AN_REG_ADV_PAUSE_ASYMMETRIC;
3448 }
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07003449 if ((vars->ieee_fc &
3450 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) ==
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003451 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) {
3452 val |=
3453 MDIO_AN_REG_ADV_PAUSE_PAUSE;
3454 }
3455 DP(NETIF_MSG_LINK,
3456 "Ext phy AN advertize 0x%x\n", val);
3457 bnx2x_cl45_write(bp, params->port,
3458 ext_phy_type,
3459 ext_phy_addr,
3460 MDIO_AN_DEVAD,
3461 MDIO_AN_REG_ADV_PAUSE, val);
3462}
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00003463static void bnx2x_set_preemphasis(struct link_params *params)
3464{
3465 u16 bank, i = 0;
3466 struct bnx2x *bp = params->bp;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003467
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00003468 for (bank = MDIO_REG_BANK_RX0, i = 0; bank <= MDIO_REG_BANK_RX3;
3469 bank += (MDIO_REG_BANK_RX1-MDIO_REG_BANK_RX0), i++) {
3470 CL45_WR_OVER_CL22(bp, params->port,
3471 params->phy_addr,
3472 bank,
3473 MDIO_RX0_RX_EQ_BOOST,
3474 params->xgxs_config_rx[i]);
3475 }
3476
3477 for (bank = MDIO_REG_BANK_TX0, i = 0; bank <= MDIO_REG_BANK_TX3;
3478 bank += (MDIO_REG_BANK_TX1 - MDIO_REG_BANK_TX0), i++) {
3479 CL45_WR_OVER_CL22(bp, params->port,
3480 params->phy_addr,
3481 bank,
3482 MDIO_TX0_TX_DRIVER,
3483 params->xgxs_config_tx[i]);
3484 }
3485}
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003486
Eilon Greenstein2f904462009-08-12 08:22:16 +00003487
3488static void bnx2x_8481_set_led4(struct link_params *params,
3489 u32 ext_phy_type, u8 ext_phy_addr)
3490{
3491 struct bnx2x *bp = params->bp;
3492
3493 /* PHYC_CTL_LED_CTL */
3494 bnx2x_cl45_write(bp, params->port,
3495 ext_phy_type,
3496 ext_phy_addr,
3497 MDIO_PMA_DEVAD,
3498 MDIO_PMA_REG_8481_LINK_SIGNAL, 0xa482);
3499
3500 /* Unmask LED4 for 10G link */
3501 bnx2x_cl45_write(bp, params->port,
3502 ext_phy_type,
3503 ext_phy_addr,
3504 MDIO_PMA_DEVAD,
3505 MDIO_PMA_REG_8481_SIGNAL_MASK, (1<<6));
3506 /* 'Interrupt Mask' */
3507 bnx2x_cl45_write(bp, params->port,
3508 ext_phy_type,
3509 ext_phy_addr,
3510 MDIO_AN_DEVAD,
3511 0xFFFB, 0xFFFD);
3512}
3513static void bnx2x_8481_set_legacy_led_mode(struct link_params *params,
3514 u32 ext_phy_type, u8 ext_phy_addr)
3515{
3516 struct bnx2x *bp = params->bp;
3517
3518 /* LED1 (10G Link): Disable LED1 when 10/100/1000 link */
3519 /* LED2 (1G/100/10 Link): Enable LED2 when 10/100/1000 link) */
3520 bnx2x_cl45_write(bp, params->port,
3521 ext_phy_type,
3522 ext_phy_addr,
3523 MDIO_AN_DEVAD,
3524 MDIO_AN_REG_8481_LEGACY_SHADOW,
3525 (1<<15) | (0xd << 10) | (0xc<<4) | 0xe);
3526}
3527
3528static void bnx2x_8481_set_10G_led_mode(struct link_params *params,
3529 u32 ext_phy_type, u8 ext_phy_addr)
3530{
3531 struct bnx2x *bp = params->bp;
3532 u16 val1;
3533
3534 /* LED1 (10G Link) */
3535 /* Enable continuse based on source 7(10G-link) */
3536 bnx2x_cl45_read(bp, params->port,
3537 ext_phy_type,
3538 ext_phy_addr,
3539 MDIO_PMA_DEVAD,
3540 MDIO_PMA_REG_8481_LINK_SIGNAL,
3541 &val1);
3542 /* Set bit 2 to 0, and bits [1:0] to 10 */
3543 val1 &= ~((1<<0) | (1<<2)); /* Clear bits 0,2*/
3544 val1 |= (1<<1); /* Set bit 1 */
3545
3546 bnx2x_cl45_write(bp, params->port,
3547 ext_phy_type,
3548 ext_phy_addr,
3549 MDIO_PMA_DEVAD,
3550 MDIO_PMA_REG_8481_LINK_SIGNAL,
3551 val1);
3552
3553 /* Unmask LED1 for 10G link */
3554 bnx2x_cl45_read(bp, params->port,
3555 ext_phy_type,
3556 ext_phy_addr,
3557 MDIO_PMA_DEVAD,
3558 MDIO_PMA_REG_8481_LED1_MASK,
3559 &val1);
3560 /* Set bit 2 to 0, and bits [1:0] to 10 */
3561 val1 |= (1<<7);
3562 bnx2x_cl45_write(bp, params->port,
3563 ext_phy_type,
3564 ext_phy_addr,
3565 MDIO_PMA_DEVAD,
3566 MDIO_PMA_REG_8481_LED1_MASK,
3567 val1);
3568
3569 /* LED2 (1G/100/10G Link) */
3570 /* Mask LED2 for 10G link */
3571 bnx2x_cl45_write(bp, params->port,
3572 ext_phy_type,
3573 ext_phy_addr,
3574 MDIO_PMA_DEVAD,
3575 MDIO_PMA_REG_8481_LED2_MASK,
3576 0);
3577
3578 /* LED3 (10G/1G/100/10G Activity) */
3579 bnx2x_cl45_read(bp, params->port,
3580 ext_phy_type,
3581 ext_phy_addr,
3582 MDIO_PMA_DEVAD,
3583 MDIO_PMA_REG_8481_LINK_SIGNAL,
3584 &val1);
3585 /* Enable blink based on source 4(Activity) */
3586 val1 &= ~((1<<7) | (1<<8)); /* Clear bits 7,8 */
3587 val1 |= (1<<6); /* Set only bit 6 */
3588 bnx2x_cl45_write(bp, params->port,
3589 ext_phy_type,
3590 ext_phy_addr,
3591 MDIO_PMA_DEVAD,
3592 MDIO_PMA_REG_8481_LINK_SIGNAL,
3593 val1);
3594
3595 bnx2x_cl45_read(bp, params->port,
3596 ext_phy_type,
3597 ext_phy_addr,
3598 MDIO_PMA_DEVAD,
3599 MDIO_PMA_REG_8481_LED3_MASK,
3600 &val1);
3601 val1 |= (1<<4); /* Unmask LED3 for 10G link */
3602 bnx2x_cl45_write(bp, params->port,
3603 ext_phy_type,
3604 ext_phy_addr,
3605 MDIO_PMA_DEVAD,
3606 MDIO_PMA_REG_8481_LED3_MASK,
3607 val1);
3608}
3609
3610
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003611static void bnx2x_init_internal_phy(struct link_params *params,
Eilon Greenstein239d6862009-08-12 08:23:04 +00003612 struct link_vars *vars,
3613 u8 enable_cl73)
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003614{
3615 struct bnx2x *bp = params->bp;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00003616
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003617 if (!(vars->phy_flags & PHY_SGMII_FLAG)) {
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00003618 if ((XGXS_EXT_PHY_TYPE(params->ext_phy_config) ==
3619 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT) &&
3620 (params->feature_config_flags &
3621 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED))
3622 bnx2x_set_preemphasis(params);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003623
3624 /* forced speed requested? */
Yaniv Rosner7846e472009-11-05 19:18:07 +02003625 if (vars->line_speed != SPEED_AUTO_NEG ||
3626 ((XGXS_EXT_PHY_TYPE(params->ext_phy_config) ==
3627 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT) &&
3628 params->loopback_mode == LOOPBACK_EXT)) {
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003629 DP(NETIF_MSG_LINK, "not SGMII, no AN\n");
3630
3631 /* disable autoneg */
Eilon Greenstein239d6862009-08-12 08:23:04 +00003632 bnx2x_set_autoneg(params, vars, 0);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003633
3634 /* program speed and duplex */
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07003635 bnx2x_program_serdes(params, vars);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003636
3637 } else { /* AN_mode */
3638 DP(NETIF_MSG_LINK, "not SGMII, AN\n");
3639
3640 /* AN enabled */
3641 bnx2x_set_brcm_cl37_advertisment(params);
3642
3643 /* program duplex & pause advertisement (for aneg) */
3644 bnx2x_set_ieee_aneg_advertisment(params,
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07003645 vars->ieee_fc);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003646
3647 /* enable autoneg */
Eilon Greenstein239d6862009-08-12 08:23:04 +00003648 bnx2x_set_autoneg(params, vars, enable_cl73);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003649
3650 /* enable and restart AN */
Eilon Greenstein239d6862009-08-12 08:23:04 +00003651 bnx2x_restart_autoneg(params, enable_cl73);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003652 }
3653
3654 } else { /* SGMII mode */
3655 DP(NETIF_MSG_LINK, "SGMII\n");
3656
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07003657 bnx2x_initialize_sgmii_process(params, vars);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07003658 }
3659}
3660
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003661static u8 bnx2x_ext_phy_init(struct link_params *params, struct link_vars *vars)
3662{
3663 struct bnx2x *bp = params->bp;
3664 u32 ext_phy_type;
3665 u8 ext_phy_addr;
3666 u16 cnt;
3667 u16 ctrl = 0;
3668 u16 val = 0;
3669 u8 rc = 0;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00003670
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003671 if (vars->phy_flags & PHY_XGXS_FLAG) {
Eilon Greenstein659bc5c2009-08-12 08:24:02 +00003672 ext_phy_addr = XGXS_EXT_PHY_ADDR(params->ext_phy_config);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003673
3674 ext_phy_type = XGXS_EXT_PHY_TYPE(params->ext_phy_config);
3675 /* Make sure that the soft reset is off (expect for the 8072:
3676 * due to the lock, it will be done inside the specific
3677 * handling)
3678 */
3679 if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT) &&
3680 (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
3681 (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN) &&
3682 (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8072) &&
3683 (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073)) {
3684 /* Wait for soft reset to get cleared upto 1 sec */
3685 for (cnt = 0; cnt < 1000; cnt++) {
3686 bnx2x_cl45_read(bp, params->port,
3687 ext_phy_type,
3688 ext_phy_addr,
3689 MDIO_PMA_DEVAD,
3690 MDIO_PMA_REG_CTRL, &ctrl);
3691 if (!(ctrl & (1<<15)))
3692 break;
3693 msleep(1);
3694 }
3695 DP(NETIF_MSG_LINK, "control reg 0x%x (after %d ms)\n",
3696 ctrl, cnt);
3697 }
3698
3699 switch (ext_phy_type) {
3700 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT:
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003701 break;
3702
3703 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705:
3704 DP(NETIF_MSG_LINK, "XGXS 8705\n");
3705
3706 bnx2x_cl45_write(bp, params->port,
3707 ext_phy_type,
3708 ext_phy_addr,
3709 MDIO_PMA_DEVAD,
3710 MDIO_PMA_REG_MISC_CTRL,
3711 0x8288);
3712 bnx2x_cl45_write(bp, params->port,
3713 ext_phy_type,
3714 ext_phy_addr,
3715 MDIO_PMA_DEVAD,
3716 MDIO_PMA_REG_PHY_IDENTIFIER,
3717 0x7fbf);
3718 bnx2x_cl45_write(bp, params->port,
3719 ext_phy_type,
3720 ext_phy_addr,
3721 MDIO_PMA_DEVAD,
3722 MDIO_PMA_REG_CMU_PLL_BYPASS,
3723 0x0100);
3724 bnx2x_cl45_write(bp, params->port,
3725 ext_phy_type,
3726 ext_phy_addr,
3727 MDIO_WIS_DEVAD,
3728 MDIO_WIS_REG_LASI_CNTL, 0x1);
Eilon Greensteina35da8d2009-02-12 08:37:02 +00003729
Eilon Greenstein3b313b62009-03-02 08:00:10 +00003730 /* BCM8705 doesn't have microcode, hence the 0 */
3731 bnx2x_save_spirom_version(bp, params->port,
3732 params->shmem_base, 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003733 break;
3734
3735 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706:
Eilon Greensteina35da8d2009-02-12 08:37:02 +00003736 /* Wait until fw is loaded */
3737 for (cnt = 0; cnt < 100; cnt++) {
3738 bnx2x_cl45_read(bp, params->port, ext_phy_type,
3739 ext_phy_addr, MDIO_PMA_DEVAD,
3740 MDIO_PMA_REG_ROM_VER1, &val);
3741 if (val)
3742 break;
3743 msleep(10);
3744 }
3745 DP(NETIF_MSG_LINK, "XGXS 8706 is initialized "
3746 "after %d ms\n", cnt);
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00003747 if ((params->feature_config_flags &
3748 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED)) {
3749 u8 i;
3750 u16 reg;
3751 for (i = 0; i < 4; i++) {
3752 reg = MDIO_XS_8706_REG_BANK_RX0 +
3753 i*(MDIO_XS_8706_REG_BANK_RX1 -
3754 MDIO_XS_8706_REG_BANK_RX0);
3755 bnx2x_cl45_read(bp, params->port,
3756 ext_phy_type,
3757 ext_phy_addr,
3758 MDIO_XS_DEVAD,
3759 reg, &val);
3760 /* Clear first 3 bits of the control */
3761 val &= ~0x7;
3762 /* Set control bits according to
3763 configuation */
3764 val |= (params->xgxs_config_rx[i] &
3765 0x7);
3766 DP(NETIF_MSG_LINK, "Setting RX"
3767 "Equalizer to BCM8706 reg 0x%x"
3768 " <-- val 0x%x\n", reg, val);
3769 bnx2x_cl45_write(bp, params->port,
3770 ext_phy_type,
3771 ext_phy_addr,
3772 MDIO_XS_DEVAD,
3773 reg, val);
3774 }
3775 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003776 /* Force speed */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003777 if (params->req_line_speed == SPEED_10000) {
3778 DP(NETIF_MSG_LINK, "XGXS 8706 force 10Gbps\n");
3779
3780 bnx2x_cl45_write(bp, params->port,
3781 ext_phy_type,
3782 ext_phy_addr,
3783 MDIO_PMA_DEVAD,
3784 MDIO_PMA_REG_DIGITAL_CTRL,
3785 0x400);
Yaniv Rosnerb5bbf002009-11-05 19:18:21 +02003786 bnx2x_cl45_write(bp, params->port, ext_phy_type,
3787 ext_phy_addr, MDIO_PMA_DEVAD,
3788 MDIO_PMA_REG_LASI_CTRL, 1);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003789 } else {
3790 /* Force 1Gbps using autoneg with 1G
3791 advertisment */
3792
3793 /* Allow CL37 through CL73 */
3794 DP(NETIF_MSG_LINK, "XGXS 8706 AutoNeg\n");
3795 bnx2x_cl45_write(bp, params->port,
3796 ext_phy_type,
3797 ext_phy_addr,
3798 MDIO_AN_DEVAD,
3799 MDIO_AN_REG_CL37_CL73,
3800 0x040c);
3801
3802 /* Enable Full-Duplex advertisment on CL37 */
3803 bnx2x_cl45_write(bp, params->port,
3804 ext_phy_type,
3805 ext_phy_addr,
3806 MDIO_AN_DEVAD,
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07003807 MDIO_AN_REG_CL37_FC_LP,
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003808 0x0020);
3809 /* Enable CL37 AN */
3810 bnx2x_cl45_write(bp, params->port,
3811 ext_phy_type,
3812 ext_phy_addr,
3813 MDIO_AN_DEVAD,
3814 MDIO_AN_REG_CL37_AN,
3815 0x1000);
3816 /* 1G support */
3817 bnx2x_cl45_write(bp, params->port,
3818 ext_phy_type,
3819 ext_phy_addr,
3820 MDIO_AN_DEVAD,
3821 MDIO_AN_REG_ADV, (1<<5));
3822
3823 /* Enable clause 73 AN */
3824 bnx2x_cl45_write(bp, params->port,
3825 ext_phy_type,
3826 ext_phy_addr,
3827 MDIO_AN_DEVAD,
3828 MDIO_AN_REG_CTRL,
3829 0x1200);
Yaniv Rosnerb5bbf002009-11-05 19:18:21 +02003830 bnx2x_cl45_write(bp, params->port,
3831 ext_phy_type,
3832 ext_phy_addr,
3833 MDIO_PMA_DEVAD,
3834 MDIO_PMA_REG_RX_ALARM_CTRL,
3835 0x0400);
3836 bnx2x_cl45_write(bp, params->port,
3837 ext_phy_type,
3838 ext_phy_addr,
3839 MDIO_PMA_DEVAD,
3840 MDIO_PMA_REG_LASI_CTRL, 0x0004);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003841
3842 }
Eilon Greensteina35da8d2009-02-12 08:37:02 +00003843 bnx2x_save_bcm_spirom_ver(bp, params->port,
3844 ext_phy_type,
3845 ext_phy_addr,
3846 params->shmem_base);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003847 break;
Eilon Greenstein589abe32009-02-12 08:36:55 +00003848 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
3849 DP(NETIF_MSG_LINK, "Initializing BCM8726\n");
3850 bnx2x_bcm8726_external_rom_boot(params);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003851
Eilon Greenstein589abe32009-02-12 08:36:55 +00003852 /* Need to call module detected on initialization since
3853 the module detection triggered by actual module
3854 insertion might occur before driver is loaded, and when
3855 driver is loaded, it reset all registers, including the
3856 transmitter */
3857 bnx2x_sfp_module_detection(params);
Eilon Greenstein4d295db2009-07-21 05:47:47 +00003858
3859 /* Set Flow control */
3860 bnx2x_ext_phy_set_pause(params, vars);
Eilon Greenstein589abe32009-02-12 08:36:55 +00003861 if (params->req_line_speed == SPEED_1000) {
3862 DP(NETIF_MSG_LINK, "Setting 1G force\n");
3863 bnx2x_cl45_write(bp, params->port, ext_phy_type,
3864 ext_phy_addr, MDIO_PMA_DEVAD,
3865 MDIO_PMA_REG_CTRL, 0x40);
3866 bnx2x_cl45_write(bp, params->port, ext_phy_type,
3867 ext_phy_addr, MDIO_PMA_DEVAD,
3868 MDIO_PMA_REG_10G_CTRL2, 0xD);
3869 bnx2x_cl45_write(bp, params->port, ext_phy_type,
3870 ext_phy_addr, MDIO_PMA_DEVAD,
3871 MDIO_PMA_REG_LASI_CTRL, 0x5);
3872 bnx2x_cl45_write(bp, params->port, ext_phy_type,
3873 ext_phy_addr, MDIO_PMA_DEVAD,
3874 MDIO_PMA_REG_RX_ALARM_CTRL,
3875 0x400);
3876 } else if ((params->req_line_speed ==
3877 SPEED_AUTO_NEG) &&
3878 ((params->speed_cap_mask &
3879 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))) {
3880 DP(NETIF_MSG_LINK, "Setting 1G clause37 \n");
3881 bnx2x_cl45_write(bp, params->port, ext_phy_type,
3882 ext_phy_addr, MDIO_AN_DEVAD,
3883 MDIO_AN_REG_ADV, 0x20);
3884 bnx2x_cl45_write(bp, params->port, ext_phy_type,
3885 ext_phy_addr, MDIO_AN_DEVAD,
3886 MDIO_AN_REG_CL37_CL73, 0x040c);
3887 bnx2x_cl45_write(bp, params->port, ext_phy_type,
3888 ext_phy_addr, MDIO_AN_DEVAD,
3889 MDIO_AN_REG_CL37_FC_LD, 0x0020);
3890 bnx2x_cl45_write(bp, params->port, ext_phy_type,
3891 ext_phy_addr, MDIO_AN_DEVAD,
3892 MDIO_AN_REG_CL37_AN, 0x1000);
3893 bnx2x_cl45_write(bp, params->port, ext_phy_type,
3894 ext_phy_addr, MDIO_AN_DEVAD,
3895 MDIO_AN_REG_CTRL, 0x1200);
3896
3897 /* Enable RX-ALARM control to receive
3898 interrupt for 1G speed change */
3899 bnx2x_cl45_write(bp, params->port, ext_phy_type,
3900 ext_phy_addr, MDIO_PMA_DEVAD,
3901 MDIO_PMA_REG_LASI_CTRL, 0x4);
3902 bnx2x_cl45_write(bp, params->port, ext_phy_type,
3903 ext_phy_addr, MDIO_PMA_DEVAD,
3904 MDIO_PMA_REG_RX_ALARM_CTRL,
3905 0x400);
3906
3907 } else { /* Default 10G. Set only LASI control */
3908 bnx2x_cl45_write(bp, params->port, ext_phy_type,
3909 ext_phy_addr, MDIO_PMA_DEVAD,
3910 MDIO_PMA_REG_LASI_CTRL, 1);
3911 }
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00003912
3913 /* Set TX PreEmphasis if needed */
3914 if ((params->feature_config_flags &
3915 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED)) {
3916 DP(NETIF_MSG_LINK, "Setting TX_CTRL1 0x%x,"
3917 "TX_CTRL2 0x%x\n",
3918 params->xgxs_config_tx[0],
3919 params->xgxs_config_tx[1]);
3920 bnx2x_cl45_write(bp, params->port,
3921 ext_phy_type,
3922 ext_phy_addr,
3923 MDIO_PMA_DEVAD,
3924 MDIO_PMA_REG_8726_TX_CTRL1,
3925 params->xgxs_config_tx[0]);
3926
3927 bnx2x_cl45_write(bp, params->port,
3928 ext_phy_type,
3929 ext_phy_addr,
3930 MDIO_PMA_DEVAD,
3931 MDIO_PMA_REG_8726_TX_CTRL2,
3932 params->xgxs_config_tx[1]);
3933 }
Eilon Greenstein589abe32009-02-12 08:36:55 +00003934 break;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003935 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8072:
3936 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073:
3937 {
3938 u16 tmp1;
3939 u16 rx_alarm_ctrl_val;
3940 u16 lasi_ctrl_val;
3941 if (ext_phy_type ==
3942 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8072) {
3943 rx_alarm_ctrl_val = 0x400;
3944 lasi_ctrl_val = 0x0004;
3945 } else {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003946 rx_alarm_ctrl_val = (1<<2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003947 lasi_ctrl_val = 0x0004;
3948 }
3949
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003950 /* enable LASI */
3951 bnx2x_cl45_write(bp, params->port,
Yaniv Rosner6bbca912008-08-13 15:57:28 -07003952 ext_phy_type,
3953 ext_phy_addr,
3954 MDIO_PMA_DEVAD,
3955 MDIO_PMA_REG_RX_ALARM_CTRL,
3956 rx_alarm_ctrl_val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003957
3958 bnx2x_cl45_write(bp, params->port,
3959 ext_phy_type,
3960 ext_phy_addr,
3961 MDIO_PMA_DEVAD,
3962 MDIO_PMA_REG_LASI_CTRL,
3963 lasi_ctrl_val);
3964
Yaniv Rosner6bbca912008-08-13 15:57:28 -07003965 bnx2x_8073_set_pause_cl37(params, vars);
3966
3967 if (ext_phy_type ==
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00003968 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8072)
Yaniv Rosner6bbca912008-08-13 15:57:28 -07003969 bnx2x_bcm8072_external_rom_boot(params);
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00003970 else
Yaniv Rosner6bbca912008-08-13 15:57:28 -07003971 /* In case of 8073 with long xaui lines,
3972 don't set the 8073 xaui low power*/
3973 bnx2x_bcm8073_set_xaui_low_power_mode(params);
Yaniv Rosner6bbca912008-08-13 15:57:28 -07003974
3975 bnx2x_cl45_read(bp, params->port,
3976 ext_phy_type,
3977 ext_phy_addr,
3978 MDIO_PMA_DEVAD,
Eilon Greenstein052a38e2009-02-12 08:37:16 +00003979 MDIO_PMA_REG_M8051_MSGOUT_REG,
Yaniv Rosner6bbca912008-08-13 15:57:28 -07003980 &tmp1);
3981
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003982 bnx2x_cl45_read(bp, params->port,
3983 ext_phy_type,
3984 ext_phy_addr,
3985 MDIO_PMA_DEVAD,
3986 MDIO_PMA_REG_RX_ALARM, &tmp1);
3987
3988 DP(NETIF_MSG_LINK, "Before rom RX_ALARM(port1):"
3989 "0x%x\n", tmp1);
3990
3991 /* If this is forced speed, set to KR or KX
3992 * (all other are not supported)
3993 */
Yaniv Rosner6bbca912008-08-13 15:57:28 -07003994 if (params->loopback_mode == LOOPBACK_EXT) {
3995 bnx2x_bcm807x_force_10G(params);
3996 DP(NETIF_MSG_LINK,
3997 "Forced speed 10G on 807X\n");
3998 break;
3999 } else {
4000 bnx2x_cl45_write(bp, params->port,
4001 ext_phy_type, ext_phy_addr,
4002 MDIO_PMA_DEVAD,
4003 MDIO_PMA_REG_BCM_CTRL,
4004 0x0002);
4005 }
4006 if (params->req_line_speed != SPEED_AUTO_NEG) {
4007 if (params->req_line_speed == SPEED_10000) {
4008 val = (1<<7);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004009 } else if (params->req_line_speed ==
4010 SPEED_2500) {
4011 val = (1<<5);
4012 /* Note that 2.5G works only
4013 when used with 1G advertisment */
4014 } else
4015 val = (1<<5);
4016 } else {
4017
4018 val = 0;
4019 if (params->speed_cap_mask &
4020 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
4021 val |= (1<<7);
4022
Yaniv Rosner6bbca912008-08-13 15:57:28 -07004023 /* Note that 2.5G works only when
4024 used with 1G advertisment */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004025 if (params->speed_cap_mask &
Yaniv Rosner6bbca912008-08-13 15:57:28 -07004026 (PORT_HW_CFG_SPEED_CAPABILITY_D0_1G |
4027 PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004028 val |= (1<<5);
Yaniv Rosner6bbca912008-08-13 15:57:28 -07004029 DP(NETIF_MSG_LINK,
4030 "807x autoneg val = 0x%x\n", val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004031 }
4032
4033 bnx2x_cl45_write(bp, params->port,
4034 ext_phy_type,
4035 ext_phy_addr,
4036 MDIO_AN_DEVAD,
4037 MDIO_AN_REG_ADV, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004038 if (ext_phy_type ==
4039 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004040 bnx2x_cl45_read(bp, params->port,
4041 ext_phy_type,
4042 ext_phy_addr,
4043 MDIO_AN_DEVAD,
Eilon Greenstein052a38e2009-02-12 08:37:16 +00004044 MDIO_AN_REG_8073_2_5G, &tmp1);
Yaniv Rosner6bbca912008-08-13 15:57:28 -07004045
4046 if (((params->speed_cap_mask &
4047 PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G) &&
4048 (params->req_line_speed ==
4049 SPEED_AUTO_NEG)) ||
4050 (params->req_line_speed ==
4051 SPEED_2500)) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004052 u16 phy_ver;
4053 /* Allow 2.5G for A1 and above */
4054 bnx2x_cl45_read(bp, params->port,
4055 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073,
4056 ext_phy_addr,
4057 MDIO_PMA_DEVAD,
Eilon Greenstein052a38e2009-02-12 08:37:16 +00004058 MDIO_PMA_REG_8073_CHIP_REV, &phy_ver);
Yaniv Rosner6bbca912008-08-13 15:57:28 -07004059 DP(NETIF_MSG_LINK, "Add 2.5G\n");
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004060 if (phy_ver > 0)
4061 tmp1 |= 1;
4062 else
4063 tmp1 &= 0xfffe;
Yaniv Rosner6bbca912008-08-13 15:57:28 -07004064 } else {
4065 DP(NETIF_MSG_LINK, "Disable 2.5G\n");
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004066 tmp1 &= 0xfffe;
Yaniv Rosner6bbca912008-08-13 15:57:28 -07004067 }
4068
4069 bnx2x_cl45_write(bp, params->port,
4070 ext_phy_type,
4071 ext_phy_addr,
4072 MDIO_AN_DEVAD,
Eilon Greenstein052a38e2009-02-12 08:37:16 +00004073 MDIO_AN_REG_8073_2_5G, tmp1);
Yaniv Rosner6bbca912008-08-13 15:57:28 -07004074 }
4075
4076 /* Add support for CL37 (passive mode) II */
4077
4078 bnx2x_cl45_read(bp, params->port,
4079 ext_phy_type,
4080 ext_phy_addr,
4081 MDIO_AN_DEVAD,
4082 MDIO_AN_REG_CL37_FC_LD,
4083 &tmp1);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004084
4085 bnx2x_cl45_write(bp, params->port,
4086 ext_phy_type,
4087 ext_phy_addr,
4088 MDIO_AN_DEVAD,
Yaniv Rosner6bbca912008-08-13 15:57:28 -07004089 MDIO_AN_REG_CL37_FC_LD, (tmp1 |
4090 ((params->req_duplex == DUPLEX_FULL) ?
4091 0x20 : 0x40)));
4092
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004093 /* Add support for CL37 (passive mode) III */
4094 bnx2x_cl45_write(bp, params->port,
4095 ext_phy_type,
4096 ext_phy_addr,
4097 MDIO_AN_DEVAD,
4098 MDIO_AN_REG_CL37_AN, 0x1000);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004099
4100 if (ext_phy_type ==
4101 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073) {
Yaniv Rosner6bbca912008-08-13 15:57:28 -07004102 /* The SNR will improve about 2db by changing
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004103 BW and FEE main tap. Rest commands are executed
4104 after link is up*/
Yaniv Rosner6bbca912008-08-13 15:57:28 -07004105 /*Change FFE main cursor to 5 in EDC register*/
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004106 if (bnx2x_8073_is_snr_needed(params))
4107 bnx2x_cl45_write(bp, params->port,
4108 ext_phy_type,
4109 ext_phy_addr,
4110 MDIO_PMA_DEVAD,
4111 MDIO_PMA_REG_EDC_FFE_MAIN,
4112 0xFB0C);
4113
Yaniv Rosner6bbca912008-08-13 15:57:28 -07004114 /* Enable FEC (Forware Error Correction)
4115 Request in the AN */
4116 bnx2x_cl45_read(bp, params->port,
4117 ext_phy_type,
4118 ext_phy_addr,
4119 MDIO_AN_DEVAD,
4120 MDIO_AN_REG_ADV2, &tmp1);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004121
Yaniv Rosner6bbca912008-08-13 15:57:28 -07004122 tmp1 |= (1<<15);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004123
Yaniv Rosner6bbca912008-08-13 15:57:28 -07004124 bnx2x_cl45_write(bp, params->port,
4125 ext_phy_type,
4126 ext_phy_addr,
4127 MDIO_AN_DEVAD,
4128 MDIO_AN_REG_ADV2, tmp1);
4129
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004130 }
4131
4132 bnx2x_ext_phy_set_pause(params, vars);
4133
Yaniv Rosner6bbca912008-08-13 15:57:28 -07004134 /* Restart autoneg */
4135 msleep(500);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004136 bnx2x_cl45_write(bp, params->port,
4137 ext_phy_type,
4138 ext_phy_addr,
4139 MDIO_AN_DEVAD,
4140 MDIO_AN_REG_CTRL, 0x1200);
4141 DP(NETIF_MSG_LINK, "807x Autoneg Restart: "
4142 "Advertise 1G=%x, 10G=%x\n",
4143 ((val & (1<<5)) > 0),
4144 ((val & (1<<7)) > 0));
4145 break;
4146 }
Eilon Greenstein4d295db2009-07-21 05:47:47 +00004147
4148 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
4149 {
4150 u16 tmp1;
4151 u16 rx_alarm_ctrl_val;
4152 u16 lasi_ctrl_val;
4153
4154 /* Enable PMD link, MOD_ABS_FLT, and 1G link alarm */
4155
4156 u16 mod_abs;
4157 rx_alarm_ctrl_val = (1<<2) | (1<<5) ;
4158 lasi_ctrl_val = 0x0004;
4159
4160 DP(NETIF_MSG_LINK, "Initializing BCM8727\n");
4161 /* enable LASI */
4162 bnx2x_cl45_write(bp, params->port,
4163 ext_phy_type,
4164 ext_phy_addr,
4165 MDIO_PMA_DEVAD,
4166 MDIO_PMA_REG_RX_ALARM_CTRL,
4167 rx_alarm_ctrl_val);
4168
4169 bnx2x_cl45_write(bp, params->port,
4170 ext_phy_type,
4171 ext_phy_addr,
4172 MDIO_PMA_DEVAD,
4173 MDIO_PMA_REG_LASI_CTRL,
4174 lasi_ctrl_val);
4175
4176 /* Initially configure MOD_ABS to interrupt when
4177 module is presence( bit 8) */
4178 bnx2x_cl45_read(bp, params->port,
4179 ext_phy_type,
4180 ext_phy_addr,
4181 MDIO_PMA_DEVAD,
4182 MDIO_PMA_REG_PHY_IDENTIFIER, &mod_abs);
4183 /* Set EDC off by setting OPTXLOS signal input to low
4184 (bit 9).
4185 When the EDC is off it locks onto a reference clock and
4186 avoids becoming 'lost'.*/
4187 mod_abs &= ~((1<<8) | (1<<9));
4188 bnx2x_cl45_write(bp, params->port,
4189 ext_phy_type,
4190 ext_phy_addr,
4191 MDIO_PMA_DEVAD,
4192 MDIO_PMA_REG_PHY_IDENTIFIER, mod_abs);
4193
4194 /* Make MOD_ABS give interrupt on change */
4195 bnx2x_cl45_read(bp, params->port,
4196 ext_phy_type,
4197 ext_phy_addr,
4198 MDIO_PMA_DEVAD,
4199 MDIO_PMA_REG_8727_PCS_OPT_CTRL,
4200 &val);
4201 val |= (1<<12);
4202 bnx2x_cl45_write(bp, params->port,
4203 ext_phy_type,
4204 ext_phy_addr,
4205 MDIO_PMA_DEVAD,
4206 MDIO_PMA_REG_8727_PCS_OPT_CTRL,
4207 val);
4208
4209 /* Set 8727 GPIOs to input to allow reading from the
4210 8727 GPIO0 status which reflect SFP+ module
4211 over-current */
4212
4213 bnx2x_cl45_read(bp, params->port,
4214 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727,
4215 ext_phy_addr,
4216 MDIO_PMA_DEVAD,
4217 MDIO_PMA_REG_8727_PCS_OPT_CTRL,
4218 &val);
4219 val &= 0xff8f; /* Reset bits 4-6 */
4220 bnx2x_cl45_write(bp, params->port,
4221 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727,
4222 ext_phy_addr,
4223 MDIO_PMA_DEVAD,
4224 MDIO_PMA_REG_8727_PCS_OPT_CTRL,
4225 val);
4226
4227 bnx2x_8727_power_module(bp, params, ext_phy_addr, 1);
4228 bnx2x_bcm8073_set_xaui_low_power_mode(params);
4229
4230 bnx2x_cl45_read(bp, params->port,
4231 ext_phy_type,
4232 ext_phy_addr,
4233 MDIO_PMA_DEVAD,
4234 MDIO_PMA_REG_M8051_MSGOUT_REG,
4235 &tmp1);
4236
4237 bnx2x_cl45_read(bp, params->port,
4238 ext_phy_type,
4239 ext_phy_addr,
4240 MDIO_PMA_DEVAD,
4241 MDIO_PMA_REG_RX_ALARM, &tmp1);
4242
4243 /* Set option 1G speed */
4244 if (params->req_line_speed == SPEED_1000) {
4245
4246 DP(NETIF_MSG_LINK, "Setting 1G force\n");
4247 bnx2x_cl45_write(bp, params->port,
4248 ext_phy_type,
4249 ext_phy_addr,
4250 MDIO_PMA_DEVAD,
4251 MDIO_PMA_REG_CTRL, 0x40);
4252 bnx2x_cl45_write(bp, params->port,
4253 ext_phy_type,
4254 ext_phy_addr,
4255 MDIO_PMA_DEVAD,
4256 MDIO_PMA_REG_10G_CTRL2, 0xD);
4257 bnx2x_cl45_read(bp, params->port,
4258 ext_phy_type,
4259 ext_phy_addr,
4260 MDIO_PMA_DEVAD,
4261 MDIO_PMA_REG_10G_CTRL2, &tmp1);
4262 DP(NETIF_MSG_LINK, "1.7 = 0x%x \n", tmp1);
4263
4264 } else if ((params->req_line_speed ==
4265 SPEED_AUTO_NEG) &&
4266 ((params->speed_cap_mask &
4267 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))) {
4268
4269 DP(NETIF_MSG_LINK, "Setting 1G clause37 \n");
4270 bnx2x_cl45_write(bp, params->port, ext_phy_type,
4271 ext_phy_addr, MDIO_AN_DEVAD,
4272 MDIO_PMA_REG_8727_MISC_CTRL, 0);
4273 bnx2x_cl45_write(bp, params->port, ext_phy_type,
4274 ext_phy_addr, MDIO_AN_DEVAD,
4275 MDIO_AN_REG_CL37_AN, 0x1300);
4276 } else {
4277 /* Since the 8727 has only single reset pin,
4278 need to set the 10G registers although it is
4279 default */
4280 bnx2x_cl45_write(bp, params->port, ext_phy_type,
4281 ext_phy_addr, MDIO_AN_DEVAD,
4282 MDIO_AN_REG_CTRL, 0x0020);
4283 bnx2x_cl45_write(bp, params->port, ext_phy_type,
4284 ext_phy_addr, MDIO_AN_DEVAD,
4285 0x7, 0x0100);
4286 bnx2x_cl45_write(bp, params->port, ext_phy_type,
4287 ext_phy_addr, MDIO_PMA_DEVAD,
4288 MDIO_PMA_REG_CTRL, 0x2040);
4289 bnx2x_cl45_write(bp, params->port, ext_phy_type,
4290 ext_phy_addr, MDIO_PMA_DEVAD,
4291 MDIO_PMA_REG_10G_CTRL2, 0x0008);
4292 }
4293
4294 /* Set 2-wire transfer rate to 400Khz since 100Khz
4295 is not operational */
4296 bnx2x_cl45_write(bp, params->port,
4297 ext_phy_type,
4298 ext_phy_addr,
4299 MDIO_PMA_DEVAD,
4300 MDIO_PMA_REG_8727_TWO_WIRE_SLAVE_ADDR,
4301 0xa101);
4302
4303 /* Set TX PreEmphasis if needed */
4304 if ((params->feature_config_flags &
4305 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED)) {
4306 DP(NETIF_MSG_LINK, "Setting TX_CTRL1 0x%x,"
4307 "TX_CTRL2 0x%x\n",
4308 params->xgxs_config_tx[0],
4309 params->xgxs_config_tx[1]);
4310 bnx2x_cl45_write(bp, params->port,
4311 ext_phy_type,
4312 ext_phy_addr,
4313 MDIO_PMA_DEVAD,
4314 MDIO_PMA_REG_8727_TX_CTRL1,
4315 params->xgxs_config_tx[0]);
4316
4317 bnx2x_cl45_write(bp, params->port,
4318 ext_phy_type,
4319 ext_phy_addr,
4320 MDIO_PMA_DEVAD,
4321 MDIO_PMA_REG_8727_TX_CTRL2,
4322 params->xgxs_config_tx[1]);
4323 }
4324
4325 break;
4326 }
4327
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004328 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101:
Eilon Greensteina35da8d2009-02-12 08:37:02 +00004329 {
4330 u16 fw_ver1, fw_ver2;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004331 DP(NETIF_MSG_LINK,
4332 "Setting the SFX7101 LASI indication\n");
4333
4334 bnx2x_cl45_write(bp, params->port,
4335 ext_phy_type,
4336 ext_phy_addr,
4337 MDIO_PMA_DEVAD,
4338 MDIO_PMA_REG_LASI_CTRL, 0x1);
4339 DP(NETIF_MSG_LINK,
4340 "Setting the SFX7101 LED to blink on traffic\n");
4341 bnx2x_cl45_write(bp, params->port,
4342 ext_phy_type,
4343 ext_phy_addr,
4344 MDIO_PMA_DEVAD,
4345 MDIO_PMA_REG_7107_LED_CNTL, (1<<3));
4346
4347 bnx2x_ext_phy_set_pause(params, vars);
4348 /* Restart autoneg */
4349 bnx2x_cl45_read(bp, params->port,
4350 ext_phy_type,
4351 ext_phy_addr,
4352 MDIO_AN_DEVAD,
4353 MDIO_AN_REG_CTRL, &val);
4354 val |= 0x200;
4355 bnx2x_cl45_write(bp, params->port,
4356 ext_phy_type,
4357 ext_phy_addr,
4358 MDIO_AN_DEVAD,
4359 MDIO_AN_REG_CTRL, val);
Eilon Greenstein28577182009-02-12 08:37:00 +00004360
Eilon Greensteina35da8d2009-02-12 08:37:02 +00004361 /* Save spirom version */
4362 bnx2x_cl45_read(bp, params->port, ext_phy_type,
4363 ext_phy_addr, MDIO_PMA_DEVAD,
4364 MDIO_PMA_REG_7101_VER1, &fw_ver1);
4365
4366 bnx2x_cl45_read(bp, params->port, ext_phy_type,
4367 ext_phy_addr, MDIO_PMA_DEVAD,
4368 MDIO_PMA_REG_7101_VER2, &fw_ver2);
4369
4370 bnx2x_save_spirom_version(params->bp, params->port,
4371 params->shmem_base,
4372 (u32)(fw_ver1<<16 | fw_ver2));
Eilon Greenstein28577182009-02-12 08:37:00 +00004373 break;
Eilon Greensteina35da8d2009-02-12 08:37:02 +00004374 }
Eilon Greenstein28577182009-02-12 08:37:00 +00004375 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8481:
Eilon Greenstein2f904462009-08-12 08:22:16 +00004376 /* This phy uses the NIG latch mechanism since link
4377 indication arrives through its LED4 and not via
4378 its LASI signal, so we get steady signal
4379 instead of clear on read */
4380 bnx2x_bits_en(bp, NIG_REG_LATCH_BC_0 + params->port*4,
4381 1 << NIG_LATCH_BC_ENABLE_MI_INT);
Eilon Greenstein28577182009-02-12 08:37:00 +00004382
Eilon Greenstein2f904462009-08-12 08:22:16 +00004383 bnx2x_8481_set_led4(params, ext_phy_type, ext_phy_addr);
4384 if (params->req_line_speed == SPEED_AUTO_NEG) {
Eilon Greenstein28577182009-02-12 08:37:00 +00004385
Eilon Greenstein2f904462009-08-12 08:22:16 +00004386 u16 autoneg_val, an_1000_val, an_10_100_val;
4387 /* set 1000 speed advertisement */
4388 bnx2x_cl45_read(bp, params->port,
4389 ext_phy_type,
4390 ext_phy_addr,
4391 MDIO_AN_DEVAD,
4392 MDIO_AN_REG_8481_1000T_CTRL,
4393 &an_1000_val);
4394
4395 if (params->speed_cap_mask &
4396 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G) {
4397 an_1000_val |= (1<<8);
4398 if (params->req_duplex == DUPLEX_FULL)
4399 an_1000_val |= (1<<9);
4400 DP(NETIF_MSG_LINK, "Advertising 1G\n");
4401 } else
4402 an_1000_val &= ~((1<<8) | (1<<9));
4403
4404 bnx2x_cl45_write(bp, params->port,
4405 ext_phy_type,
4406 ext_phy_addr,
4407 MDIO_AN_DEVAD,
4408 MDIO_AN_REG_8481_1000T_CTRL,
4409 an_1000_val);
4410
4411 /* set 100 speed advertisement */
4412 bnx2x_cl45_read(bp, params->port,
4413 ext_phy_type,
4414 ext_phy_addr,
4415 MDIO_AN_DEVAD,
4416 MDIO_AN_REG_8481_LEGACY_AN_ADV,
4417 &an_10_100_val);
4418
4419 if (params->speed_cap_mask &
4420 (PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL |
4421 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF)) {
4422 an_10_100_val |= (1<<7);
4423 if (params->req_duplex == DUPLEX_FULL)
4424 an_10_100_val |= (1<<8);
4425 DP(NETIF_MSG_LINK,
4426 "Advertising 100M\n");
4427 } else
4428 an_10_100_val &= ~((1<<7) | (1<<8));
4429
4430 /* set 10 speed advertisement */
4431 if (params->speed_cap_mask &
4432 (PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL |
4433 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF)) {
4434 an_10_100_val |= (1<<5);
4435 if (params->req_duplex == DUPLEX_FULL)
4436 an_10_100_val |= (1<<6);
4437 DP(NETIF_MSG_LINK, "Advertising 10M\n");
4438 }
4439 else
4440 an_10_100_val &= ~((1<<5) | (1<<6));
4441
4442 bnx2x_cl45_write(bp, params->port,
4443 ext_phy_type,
4444 ext_phy_addr,
4445 MDIO_AN_DEVAD,
4446 MDIO_AN_REG_8481_LEGACY_AN_ADV,
4447 an_10_100_val);
4448
4449 bnx2x_cl45_read(bp, params->port,
4450 ext_phy_type,
4451 ext_phy_addr,
4452 MDIO_AN_DEVAD,
4453 MDIO_AN_REG_8481_LEGACY_MII_CTRL,
4454 &autoneg_val);
4455
4456 /* Disable forced speed */
4457 autoneg_val &= ~(1<<6|1<<13);
4458
4459 /* Enable autoneg and restart autoneg
4460 for legacy speeds */
4461 autoneg_val |= (1<<9|1<<12);
4462
4463 if (params->req_duplex == DUPLEX_FULL)
4464 autoneg_val |= (1<<8);
4465 else
4466 autoneg_val &= ~(1<<8);
4467
4468 bnx2x_cl45_write(bp, params->port,
4469 ext_phy_type,
4470 ext_phy_addr,
4471 MDIO_AN_DEVAD,
4472 MDIO_AN_REG_8481_LEGACY_MII_CTRL,
4473 autoneg_val);
4474
4475 if (params->speed_cap_mask &
4476 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G) {
4477 DP(NETIF_MSG_LINK, "Advertising 10G\n");
4478 /* Restart autoneg for 10G*/
Eilon Greenstein28577182009-02-12 08:37:00 +00004479 bnx2x_cl45_read(bp, params->port,
4480 ext_phy_type,
4481 ext_phy_addr,
4482 MDIO_AN_DEVAD,
4483 MDIO_AN_REG_CTRL, &val);
4484 val |= 0x200;
4485 bnx2x_cl45_write(bp, params->port,
4486 ext_phy_type,
4487 ext_phy_addr,
4488 MDIO_AN_DEVAD,
4489 MDIO_AN_REG_CTRL, val);
Eilon Greenstein2f904462009-08-12 08:22:16 +00004490 }
4491 } else {
4492 /* Force speed */
4493 u16 autoneg_ctrl, pma_ctrl;
4494 bnx2x_cl45_read(bp, params->port,
4495 ext_phy_type,
4496 ext_phy_addr,
4497 MDIO_AN_DEVAD,
4498 MDIO_AN_REG_8481_LEGACY_MII_CTRL,
4499 &autoneg_ctrl);
4500
4501 /* Disable autoneg */
4502 autoneg_ctrl &= ~(1<<12);
4503
4504 /* Set 1000 force */
4505 switch (params->req_line_speed) {
4506 case SPEED_10000:
4507 DP(NETIF_MSG_LINK,
4508 "Unable to set 10G force !\n");
4509 break;
4510 case SPEED_1000:
4511 bnx2x_cl45_read(bp, params->port,
4512 ext_phy_type,
4513 ext_phy_addr,
4514 MDIO_PMA_DEVAD,
4515 MDIO_PMA_REG_CTRL,
4516 &pma_ctrl);
4517 autoneg_ctrl &= ~(1<<13);
4518 autoneg_ctrl |= (1<<6);
4519 pma_ctrl &= ~(1<<13);
4520 pma_ctrl |= (1<<6);
4521 DP(NETIF_MSG_LINK,
4522 "Setting 1000M force\n");
4523 bnx2x_cl45_write(bp, params->port,
4524 ext_phy_type,
4525 ext_phy_addr,
4526 MDIO_PMA_DEVAD,
4527 MDIO_PMA_REG_CTRL,
4528 pma_ctrl);
4529 break;
4530 case SPEED_100:
4531 autoneg_ctrl |= (1<<13);
4532 autoneg_ctrl &= ~(1<<6);
4533 DP(NETIF_MSG_LINK,
4534 "Setting 100M force\n");
4535 break;
4536 case SPEED_10:
4537 autoneg_ctrl &= ~(1<<13);
4538 autoneg_ctrl &= ~(1<<6);
4539 DP(NETIF_MSG_LINK,
4540 "Setting 10M force\n");
4541 break;
4542 }
4543
4544 /* Duplex mode */
4545 if (params->req_duplex == DUPLEX_FULL) {
4546 autoneg_ctrl |= (1<<8);
4547 DP(NETIF_MSG_LINK,
4548 "Setting full duplex\n");
4549 } else
4550 autoneg_ctrl &= ~(1<<8);
4551
4552 /* Update autoneg ctrl and pma ctrl */
4553 bnx2x_cl45_write(bp, params->port,
4554 ext_phy_type,
4555 ext_phy_addr,
4556 MDIO_AN_DEVAD,
4557 MDIO_AN_REG_8481_LEGACY_MII_CTRL,
4558 autoneg_ctrl);
4559 }
Eilon Greenstein28577182009-02-12 08:37:00 +00004560
Eilon Greensteinb1607af2009-08-12 08:22:54 +00004561 /* Save spirom version */
4562 bnx2x_save_8481_spirom_version(bp, params->port,
4563 ext_phy_addr,
4564 params->shmem_base);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004565 break;
4566 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE:
4567 DP(NETIF_MSG_LINK,
4568 "XGXS PHY Failure detected 0x%x\n",
4569 params->ext_phy_config);
4570 rc = -EINVAL;
4571 break;
4572 default:
4573 DP(NETIF_MSG_LINK, "BAD XGXS ext_phy_config 0x%x\n",
4574 params->ext_phy_config);
4575 rc = -EINVAL;
4576 break;
4577 }
4578
4579 } else { /* SerDes */
Yaniv Rosner57963ed2008-08-13 15:55:28 -07004580
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004581 ext_phy_type = SERDES_EXT_PHY_TYPE(params->ext_phy_config);
4582 switch (ext_phy_type) {
4583 case PORT_HW_CFG_SERDES_EXT_PHY_TYPE_DIRECT:
4584 DP(NETIF_MSG_LINK, "SerDes Direct\n");
4585 break;
4586
4587 case PORT_HW_CFG_SERDES_EXT_PHY_TYPE_BCM5482:
4588 DP(NETIF_MSG_LINK, "SerDes 5482\n");
4589 break;
4590
4591 default:
4592 DP(NETIF_MSG_LINK, "BAD SerDes ext_phy_config 0x%x\n",
4593 params->ext_phy_config);
4594 break;
4595 }
4596 }
4597 return rc;
4598}
4599
Eilon Greenstein4d295db2009-07-21 05:47:47 +00004600static void bnx2x_8727_handle_mod_abs(struct link_params *params)
4601{
4602 struct bnx2x *bp = params->bp;
4603 u16 mod_abs, rx_alarm_status;
Eilon Greenstein659bc5c2009-08-12 08:24:02 +00004604 u8 ext_phy_addr = XGXS_EXT_PHY_ADDR(params->ext_phy_config);
Eilon Greenstein4d295db2009-07-21 05:47:47 +00004605 u32 val = REG_RD(bp, params->shmem_base +
4606 offsetof(struct shmem_region, dev_info.
4607 port_feature_config[params->port].
4608 config));
4609 bnx2x_cl45_read(bp, params->port,
4610 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727,
4611 ext_phy_addr,
4612 MDIO_PMA_DEVAD,
4613 MDIO_PMA_REG_PHY_IDENTIFIER, &mod_abs);
4614 if (mod_abs & (1<<8)) {
4615
4616 /* Module is absent */
4617 DP(NETIF_MSG_LINK, "MOD_ABS indication "
4618 "show module is absent\n");
4619
4620 /* 1. Set mod_abs to detect next module
4621 presence event
4622 2. Set EDC off by setting OPTXLOS signal input to low
4623 (bit 9).
4624 When the EDC is off it locks onto a reference clock and
4625 avoids becoming 'lost'.*/
4626 mod_abs &= ~((1<<8)|(1<<9));
4627 bnx2x_cl45_write(bp, params->port,
4628 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727,
4629 ext_phy_addr,
4630 MDIO_PMA_DEVAD,
4631 MDIO_PMA_REG_PHY_IDENTIFIER, mod_abs);
4632
4633 /* Clear RX alarm since it stays up as long as
4634 the mod_abs wasn't changed */
4635 bnx2x_cl45_read(bp, params->port,
4636 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727,
4637 ext_phy_addr,
4638 MDIO_PMA_DEVAD,
4639 MDIO_PMA_REG_RX_ALARM, &rx_alarm_status);
4640
4641 } else {
4642 /* Module is present */
4643 DP(NETIF_MSG_LINK, "MOD_ABS indication "
4644 "show module is present\n");
4645 /* First thing, disable transmitter,
4646 and if the module is ok, the
4647 module_detection will enable it*/
4648
4649 /* 1. Set mod_abs to detect next module
4650 absent event ( bit 8)
4651 2. Restore the default polarity of the OPRXLOS signal and
4652 this signal will then correctly indicate the presence or
4653 absence of the Rx signal. (bit 9) */
4654 mod_abs |= ((1<<8)|(1<<9));
4655 bnx2x_cl45_write(bp, params->port,
4656 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727,
4657 ext_phy_addr,
4658 MDIO_PMA_DEVAD,
4659 MDIO_PMA_REG_PHY_IDENTIFIER, mod_abs);
4660
4661 /* Clear RX alarm since it stays up as long as
4662 the mod_abs wasn't changed. This is need to be done
4663 before calling the module detection, otherwise it will clear
4664 the link update alarm */
4665 bnx2x_cl45_read(bp, params->port,
4666 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727,
4667 ext_phy_addr,
4668 MDIO_PMA_DEVAD,
4669 MDIO_PMA_REG_RX_ALARM, &rx_alarm_status);
4670
4671
4672 if ((val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) ==
4673 PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_DISABLE_TX_LASER)
4674 bnx2x_sfp_set_transmitter(bp, params->port,
4675 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727,
4676 ext_phy_addr, 0);
4677
4678 if (bnx2x_wait_for_sfp_module_initialized(params)
4679 == 0)
4680 bnx2x_sfp_module_detection(params);
4681 else
4682 DP(NETIF_MSG_LINK, "SFP+ module is not initialized\n");
4683 }
4684
4685 DP(NETIF_MSG_LINK, "8727 RX_ALARM_STATUS 0x%x\n",
4686 rx_alarm_status);
4687 /* No need to check link status in case of
4688 module plugged in/out */
4689}
4690
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004691
4692static u8 bnx2x_ext_phy_is_link_up(struct link_params *params,
Eilon Greenstein2f904462009-08-12 08:22:16 +00004693 struct link_vars *vars,
4694 u8 is_mi_int)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004695{
4696 struct bnx2x *bp = params->bp;
4697 u32 ext_phy_type;
4698 u8 ext_phy_addr;
4699 u16 val1 = 0, val2;
4700 u16 rx_sd, pcs_status;
4701 u8 ext_phy_link_up = 0;
4702 u8 port = params->port;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00004703
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004704 if (vars->phy_flags & PHY_XGXS_FLAG) {
Eilon Greenstein659bc5c2009-08-12 08:24:02 +00004705 ext_phy_addr = XGXS_EXT_PHY_ADDR(params->ext_phy_config);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004706 ext_phy_type = XGXS_EXT_PHY_TYPE(params->ext_phy_config);
4707 switch (ext_phy_type) {
4708 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT:
4709 DP(NETIF_MSG_LINK, "XGXS Direct\n");
4710 ext_phy_link_up = 1;
4711 break;
4712
4713 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705:
4714 DP(NETIF_MSG_LINK, "XGXS 8705\n");
4715 bnx2x_cl45_read(bp, params->port, ext_phy_type,
4716 ext_phy_addr,
4717 MDIO_WIS_DEVAD,
4718 MDIO_WIS_REG_LASI_STATUS, &val1);
4719 DP(NETIF_MSG_LINK, "8705 LASI status 0x%x\n", val1);
4720
4721 bnx2x_cl45_read(bp, params->port, ext_phy_type,
4722 ext_phy_addr,
4723 MDIO_WIS_DEVAD,
4724 MDIO_WIS_REG_LASI_STATUS, &val1);
4725 DP(NETIF_MSG_LINK, "8705 LASI status 0x%x\n", val1);
4726
4727 bnx2x_cl45_read(bp, params->port, ext_phy_type,
4728 ext_phy_addr,
4729 MDIO_PMA_DEVAD,
4730 MDIO_PMA_REG_RX_SD, &rx_sd);
Eilon Greenstein4d295db2009-07-21 05:47:47 +00004731
4732 bnx2x_cl45_read(bp, params->port, ext_phy_type,
4733 ext_phy_addr,
4734 1,
4735 0xc809, &val1);
4736 bnx2x_cl45_read(bp, params->port, ext_phy_type,
4737 ext_phy_addr,
4738 1,
4739 0xc809, &val1);
4740
4741 DP(NETIF_MSG_LINK, "8705 1.c809 val=0x%x\n", val1);
4742 ext_phy_link_up = ((rx_sd & 0x1) && (val1 & (1<<9))
4743 && ((val1 & (1<<8)) == 0));
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07004744 if (ext_phy_link_up)
4745 vars->line_speed = SPEED_10000;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004746 break;
4747
4748 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706:
Eilon Greenstein589abe32009-02-12 08:36:55 +00004749 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
4750 DP(NETIF_MSG_LINK, "XGXS 8706/8726\n");
4751 /* Clear RX Alarm*/
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004752 bnx2x_cl45_read(bp, params->port, ext_phy_type,
4753 ext_phy_addr,
Eilon Greenstein589abe32009-02-12 08:36:55 +00004754 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_ALARM,
4755 &val2);
4756 /* clear LASI indication*/
4757 bnx2x_cl45_read(bp, params->port, ext_phy_type,
4758 ext_phy_addr,
4759 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_STATUS,
4760 &val1);
4761 bnx2x_cl45_read(bp, params->port, ext_phy_type,
4762 ext_phy_addr,
4763 MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_STATUS,
4764 &val2);
4765 DP(NETIF_MSG_LINK, "8706/8726 LASI status 0x%x-->"
4766 "0x%x\n", val1, val2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004767
4768 bnx2x_cl45_read(bp, params->port, ext_phy_type,
4769 ext_phy_addr,
Eilon Greenstein589abe32009-02-12 08:36:55 +00004770 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_SD,
4771 &rx_sd);
4772 bnx2x_cl45_read(bp, params->port, ext_phy_type,
4773 ext_phy_addr,
4774 MDIO_PCS_DEVAD, MDIO_PCS_REG_STATUS,
4775 &pcs_status);
4776 bnx2x_cl45_read(bp, params->port, ext_phy_type,
4777 ext_phy_addr,
4778 MDIO_AN_DEVAD, MDIO_AN_REG_LINK_STATUS,
4779 &val2);
4780 bnx2x_cl45_read(bp, params->port, ext_phy_type,
4781 ext_phy_addr,
4782 MDIO_AN_DEVAD, MDIO_AN_REG_LINK_STATUS,
4783 &val2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004784
Eilon Greenstein589abe32009-02-12 08:36:55 +00004785 DP(NETIF_MSG_LINK, "8706/8726 rx_sd 0x%x"
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004786 " pcs_status 0x%x 1Gbps link_status 0x%x\n",
4787 rx_sd, pcs_status, val2);
4788 /* link is up if both bit 0 of pmd_rx_sd and
4789 * bit 0 of pcs_status are set, or if the autoneg bit
4790 1 is set
4791 */
4792 ext_phy_link_up = ((rx_sd & pcs_status & 0x1) ||
4793 (val2 & (1<<1)));
Yaniv Rosner57963ed2008-08-13 15:55:28 -07004794 if (ext_phy_link_up) {
Eilon Greenstein589abe32009-02-12 08:36:55 +00004795 if (ext_phy_type ==
4796 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726) {
4797 /* If transmitter is disabled,
4798 ignore false link up indication */
4799 bnx2x_cl45_read(bp, params->port,
4800 ext_phy_type,
4801 ext_phy_addr,
4802 MDIO_PMA_DEVAD,
4803 MDIO_PMA_REG_PHY_IDENTIFIER,
4804 &val1);
4805 if (val1 & (1<<15)) {
4806 DP(NETIF_MSG_LINK, "Tx is "
4807 "disabled\n");
4808 ext_phy_link_up = 0;
4809 break;
4810 }
4811 }
Yaniv Rosner57963ed2008-08-13 15:55:28 -07004812 if (val2 & (1<<1))
4813 vars->line_speed = SPEED_1000;
4814 else
4815 vars->line_speed = SPEED_10000;
4816 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004817 break;
Eilon Greenstein4d295db2009-07-21 05:47:47 +00004818
4819 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
4820 {
4821 u16 link_status = 0;
4822 u16 rx_alarm_status;
4823 /* Check the LASI */
4824 bnx2x_cl45_read(bp, params->port,
4825 ext_phy_type,
4826 ext_phy_addr,
4827 MDIO_PMA_DEVAD,
4828 MDIO_PMA_REG_RX_ALARM, &rx_alarm_status);
4829
4830 DP(NETIF_MSG_LINK, "8727 RX_ALARM_STATUS 0x%x\n",
4831 rx_alarm_status);
4832
4833 bnx2x_cl45_read(bp, params->port,
4834 ext_phy_type,
4835 ext_phy_addr,
4836 MDIO_PMA_DEVAD,
4837 MDIO_PMA_REG_LASI_STATUS, &val1);
4838
4839 DP(NETIF_MSG_LINK,
4840 "8727 LASI status 0x%x\n",
4841 val1);
4842
4843 /* Clear MSG-OUT */
4844 bnx2x_cl45_read(bp, params->port,
4845 ext_phy_type,
4846 ext_phy_addr,
4847 MDIO_PMA_DEVAD,
4848 MDIO_PMA_REG_M8051_MSGOUT_REG,
4849 &val1);
4850
4851 /*
4852 * If a module is present and there is need to check
4853 * for over current
4854 */
4855 if (!(params->feature_config_flags &
4856 FEATURE_CONFIG_BCM8727_NOC) &&
4857 !(rx_alarm_status & (1<<5))) {
4858 /* Check over-current using 8727 GPIO0 input*/
4859 bnx2x_cl45_read(bp, params->port,
4860 ext_phy_type,
4861 ext_phy_addr,
4862 MDIO_PMA_DEVAD,
4863 MDIO_PMA_REG_8727_GPIO_CTRL,
4864 &val1);
4865
4866 if ((val1 & (1<<8)) == 0) {
4867 DP(NETIF_MSG_LINK, "8727 Power fault"
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00004868 " has been detected on "
4869 "port %d\n",
4870 params->port);
Eilon Greenstein4d295db2009-07-21 05:47:47 +00004871 printk(KERN_ERR PFX "Error: Power"
4872 " fault on %s Port %d has"
4873 " been detected and the"
4874 " power to that SFP+ module"
4875 " has been removed to prevent"
4876 " failure of the card. Please"
4877 " remove the SFP+ module and"
4878 " restart the system to clear"
4879 " this error.\n"
4880 , bp->dev->name, params->port);
4881 /*
4882 * Disable all RX_ALARMs except for
4883 * mod_abs
4884 */
4885 bnx2x_cl45_write(bp, params->port,
4886 ext_phy_type,
4887 ext_phy_addr,
4888 MDIO_PMA_DEVAD,
4889 MDIO_PMA_REG_RX_ALARM_CTRL,
4890 (1<<5));
4891
4892 bnx2x_cl45_read(bp, params->port,
4893 ext_phy_type,
4894 ext_phy_addr,
4895 MDIO_PMA_DEVAD,
4896 MDIO_PMA_REG_PHY_IDENTIFIER,
4897 &val1);
4898 /* Wait for module_absent_event */
4899 val1 |= (1<<8);
4900 bnx2x_cl45_write(bp, params->port,
4901 ext_phy_type,
4902 ext_phy_addr,
4903 MDIO_PMA_DEVAD,
4904 MDIO_PMA_REG_PHY_IDENTIFIER,
4905 val1);
4906 /* Clear RX alarm */
4907 bnx2x_cl45_read(bp, params->port,
4908 ext_phy_type,
4909 ext_phy_addr,
4910 MDIO_PMA_DEVAD,
4911 MDIO_PMA_REG_RX_ALARM,
4912 &rx_alarm_status);
4913 break;
4914 }
4915 } /* Over current check */
4916
4917 /* When module absent bit is set, check module */
4918 if (rx_alarm_status & (1<<5)) {
4919 bnx2x_8727_handle_mod_abs(params);
4920 /* Enable all mod_abs and link detection bits */
4921 bnx2x_cl45_write(bp, params->port,
4922 ext_phy_type,
4923 ext_phy_addr,
4924 MDIO_PMA_DEVAD,
4925 MDIO_PMA_REG_RX_ALARM_CTRL,
4926 ((1<<5) | (1<<2)));
4927 }
4928
4929 /* If transmitter is disabled,
4930 ignore false link up indication */
4931 bnx2x_cl45_read(bp, params->port,
4932 ext_phy_type,
4933 ext_phy_addr,
4934 MDIO_PMA_DEVAD,
4935 MDIO_PMA_REG_PHY_IDENTIFIER,
4936 &val1);
4937 if (val1 & (1<<15)) {
4938 DP(NETIF_MSG_LINK, "Tx is disabled\n");
4939 ext_phy_link_up = 0;
4940 break;
4941 }
4942
4943 bnx2x_cl45_read(bp, params->port,
4944 ext_phy_type,
4945 ext_phy_addr,
4946 MDIO_PMA_DEVAD,
4947 MDIO_PMA_REG_8073_SPEED_LINK_STATUS,
4948 &link_status);
4949
4950 /* Bits 0..2 --> speed detected,
4951 bits 13..15--> link is down */
4952 if ((link_status & (1<<2)) &&
4953 (!(link_status & (1<<15)))) {
4954 ext_phy_link_up = 1;
4955 vars->line_speed = SPEED_10000;
4956 } else if ((link_status & (1<<0)) &&
4957 (!(link_status & (1<<13)))) {
4958 ext_phy_link_up = 1;
4959 vars->line_speed = SPEED_1000;
4960 DP(NETIF_MSG_LINK,
4961 "port %x: External link"
4962 " up in 1G\n", params->port);
4963 } else {
4964 ext_phy_link_up = 0;
4965 DP(NETIF_MSG_LINK,
4966 "port %x: External link"
4967 " is down\n", params->port);
4968 }
4969 break;
4970 }
4971
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004972 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8072:
4973 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073:
4974 {
Yaniv Rosner6bbca912008-08-13 15:57:28 -07004975 u16 link_status = 0;
4976 u16 an1000_status = 0;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00004977
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004978 if (ext_phy_type ==
4979 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8072) {
4980 bnx2x_cl45_read(bp, params->port,
4981 ext_phy_type,
4982 ext_phy_addr,
4983 MDIO_PCS_DEVAD,
4984 MDIO_PCS_REG_LASI_STATUS, &val1);
4985 bnx2x_cl45_read(bp, params->port,
4986 ext_phy_type,
4987 ext_phy_addr,
4988 MDIO_PCS_DEVAD,
4989 MDIO_PCS_REG_LASI_STATUS, &val2);
4990 DP(NETIF_MSG_LINK,
4991 "870x LASI status 0x%x->0x%x\n",
4992 val1, val2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004993 } else {
4994 /* In 8073, port1 is directed through emac0 and
4995 * port0 is directed through emac1
4996 */
4997 bnx2x_cl45_read(bp, params->port,
4998 ext_phy_type,
4999 ext_phy_addr,
5000 MDIO_PMA_DEVAD,
5001 MDIO_PMA_REG_LASI_STATUS, &val1);
5002
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005003 DP(NETIF_MSG_LINK,
Yaniv Rosner6bbca912008-08-13 15:57:28 -07005004 "8703 LASI status 0x%x\n",
5005 val1);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005006 }
5007
5008 /* clear the interrupt LASI status register */
5009 bnx2x_cl45_read(bp, params->port,
5010 ext_phy_type,
5011 ext_phy_addr,
5012 MDIO_PCS_DEVAD,
5013 MDIO_PCS_REG_STATUS, &val2);
5014 bnx2x_cl45_read(bp, params->port,
5015 ext_phy_type,
5016 ext_phy_addr,
5017 MDIO_PCS_DEVAD,
5018 MDIO_PCS_REG_STATUS, &val1);
5019 DP(NETIF_MSG_LINK, "807x PCS status 0x%x->0x%x\n",
5020 val2, val1);
Yaniv Rosner6bbca912008-08-13 15:57:28 -07005021 /* Clear MSG-OUT */
5022 bnx2x_cl45_read(bp, params->port,
5023 ext_phy_type,
5024 ext_phy_addr,
5025 MDIO_PMA_DEVAD,
Eilon Greenstein052a38e2009-02-12 08:37:16 +00005026 MDIO_PMA_REG_M8051_MSGOUT_REG,
Yaniv Rosner6bbca912008-08-13 15:57:28 -07005027 &val1);
5028
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005029 /* Check the LASI */
5030 bnx2x_cl45_read(bp, params->port,
5031 ext_phy_type,
5032 ext_phy_addr,
5033 MDIO_PMA_DEVAD,
5034 MDIO_PMA_REG_RX_ALARM, &val2);
Yaniv Rosner6bbca912008-08-13 15:57:28 -07005035
5036 DP(NETIF_MSG_LINK, "KR 0x9003 0x%x\n", val2);
5037
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005038 /* Check the link status */
5039 bnx2x_cl45_read(bp, params->port,
5040 ext_phy_type,
5041 ext_phy_addr,
5042 MDIO_PCS_DEVAD,
5043 MDIO_PCS_REG_STATUS, &val2);
5044 DP(NETIF_MSG_LINK, "KR PCS status 0x%x\n", val2);
5045
5046 bnx2x_cl45_read(bp, params->port,
5047 ext_phy_type,
5048 ext_phy_addr,
5049 MDIO_PMA_DEVAD,
5050 MDIO_PMA_REG_STATUS, &val2);
5051 bnx2x_cl45_read(bp, params->port,
5052 ext_phy_type,
5053 ext_phy_addr,
5054 MDIO_PMA_DEVAD,
5055 MDIO_PMA_REG_STATUS, &val1);
5056 ext_phy_link_up = ((val1 & 4) == 4);
5057 DP(NETIF_MSG_LINK, "PMA_REG_STATUS=0x%x\n", val1);
5058 if (ext_phy_type ==
5059 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073) {
Yaniv Rosner6bbca912008-08-13 15:57:28 -07005060
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005061 if (ext_phy_link_up &&
Yaniv Rosner6bbca912008-08-13 15:57:28 -07005062 ((params->req_line_speed !=
5063 SPEED_10000))) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005064 if (bnx2x_bcm8073_xaui_wa(params)
5065 != 0) {
5066 ext_phy_link_up = 0;
5067 break;
5068 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005069 }
Yaniv Rosner6bbca912008-08-13 15:57:28 -07005070 bnx2x_cl45_read(bp, params->port,
Eilon Greenstein052a38e2009-02-12 08:37:16 +00005071 ext_phy_type,
5072 ext_phy_addr,
5073 MDIO_AN_DEVAD,
5074 MDIO_AN_REG_LINK_STATUS,
5075 &an1000_status);
Yaniv Rosner6bbca912008-08-13 15:57:28 -07005076 bnx2x_cl45_read(bp, params->port,
Eilon Greenstein052a38e2009-02-12 08:37:16 +00005077 ext_phy_type,
5078 ext_phy_addr,
5079 MDIO_AN_DEVAD,
5080 MDIO_AN_REG_LINK_STATUS,
5081 &an1000_status);
Yaniv Rosner6bbca912008-08-13 15:57:28 -07005082
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005083 /* Check the link status on 1.1.2 */
5084 bnx2x_cl45_read(bp, params->port,
5085 ext_phy_type,
5086 ext_phy_addr,
5087 MDIO_PMA_DEVAD,
5088 MDIO_PMA_REG_STATUS, &val2);
5089 bnx2x_cl45_read(bp, params->port,
5090 ext_phy_type,
5091 ext_phy_addr,
5092 MDIO_PMA_DEVAD,
5093 MDIO_PMA_REG_STATUS, &val1);
5094 DP(NETIF_MSG_LINK, "KR PMA status 0x%x->0x%x,"
5095 "an_link_status=0x%x\n",
5096 val2, val1, an1000_status);
5097
Eilon Greenstein356e2382009-02-12 08:38:32 +00005098 ext_phy_link_up = (((val1 & 4) == 4) ||
Yaniv Rosner6bbca912008-08-13 15:57:28 -07005099 (an1000_status & (1<<1)));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005100 if (ext_phy_link_up &&
5101 bnx2x_8073_is_snr_needed(params)) {
5102 /* The SNR will improve about 2dbby
5103 changing the BW and FEE main tap.*/
5104
5105 /* The 1st write to change FFE main
5106 tap is set before restart AN */
5107 /* Change PLL Bandwidth in EDC
5108 register */
5109 bnx2x_cl45_write(bp, port, ext_phy_type,
5110 ext_phy_addr,
5111 MDIO_PMA_DEVAD,
5112 MDIO_PMA_REG_PLL_BANDWIDTH,
5113 0x26BC);
5114
5115 /* Change CDR Bandwidth in EDC
5116 register */
5117 bnx2x_cl45_write(bp, port, ext_phy_type,
5118 ext_phy_addr,
5119 MDIO_PMA_DEVAD,
5120 MDIO_PMA_REG_CDR_BANDWIDTH,
5121 0x0333);
Yaniv Rosner6bbca912008-08-13 15:57:28 -07005122 }
5123 bnx2x_cl45_read(bp, params->port,
Eilon Greenstein052a38e2009-02-12 08:37:16 +00005124 ext_phy_type,
5125 ext_phy_addr,
5126 MDIO_PMA_DEVAD,
5127 MDIO_PMA_REG_8073_SPEED_LINK_STATUS,
5128 &link_status);
Yaniv Rosner6bbca912008-08-13 15:57:28 -07005129
5130 /* Bits 0..2 --> speed detected,
5131 bits 13..15--> link is down */
5132 if ((link_status & (1<<2)) &&
5133 (!(link_status & (1<<15)))) {
5134 ext_phy_link_up = 1;
5135 vars->line_speed = SPEED_10000;
5136 DP(NETIF_MSG_LINK,
5137 "port %x: External link"
5138 " up in 10G\n", params->port);
5139 } else if ((link_status & (1<<1)) &&
5140 (!(link_status & (1<<14)))) {
5141 ext_phy_link_up = 1;
5142 vars->line_speed = SPEED_2500;
5143 DP(NETIF_MSG_LINK,
5144 "port %x: External link"
5145 " up in 2.5G\n", params->port);
5146 } else if ((link_status & (1<<0)) &&
5147 (!(link_status & (1<<13)))) {
5148 ext_phy_link_up = 1;
5149 vars->line_speed = SPEED_1000;
5150 DP(NETIF_MSG_LINK,
5151 "port %x: External link"
5152 " up in 1G\n", params->port);
5153 } else {
5154 ext_phy_link_up = 0;
5155 DP(NETIF_MSG_LINK,
5156 "port %x: External link"
5157 " is down\n", params->port);
5158 }
5159 } else {
5160 /* See if 1G link is up for the 8072 */
5161 bnx2x_cl45_read(bp, params->port,
Eilon Greenstein052a38e2009-02-12 08:37:16 +00005162 ext_phy_type,
5163 ext_phy_addr,
5164 MDIO_AN_DEVAD,
5165 MDIO_AN_REG_LINK_STATUS,
5166 &an1000_status);
Yaniv Rosner6bbca912008-08-13 15:57:28 -07005167 bnx2x_cl45_read(bp, params->port,
Eilon Greenstein052a38e2009-02-12 08:37:16 +00005168 ext_phy_type,
5169 ext_phy_addr,
5170 MDIO_AN_DEVAD,
5171 MDIO_AN_REG_LINK_STATUS,
5172 &an1000_status);
Yaniv Rosner6bbca912008-08-13 15:57:28 -07005173 if (an1000_status & (1<<1)) {
5174 ext_phy_link_up = 1;
5175 vars->line_speed = SPEED_1000;
5176 DP(NETIF_MSG_LINK,
5177 "port %x: External link"
5178 " up in 1G\n", params->port);
5179 } else if (ext_phy_link_up) {
5180 ext_phy_link_up = 1;
5181 vars->line_speed = SPEED_10000;
5182 DP(NETIF_MSG_LINK,
5183 "port %x: External link"
5184 " up in 10G\n", params->port);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005185 }
5186 }
Yaniv Rosner6bbca912008-08-13 15:57:28 -07005187
5188
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005189 break;
5190 }
5191 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101:
5192 bnx2x_cl45_read(bp, params->port, ext_phy_type,
5193 ext_phy_addr,
5194 MDIO_PMA_DEVAD,
5195 MDIO_PMA_REG_LASI_STATUS, &val2);
5196 bnx2x_cl45_read(bp, params->port, ext_phy_type,
5197 ext_phy_addr,
5198 MDIO_PMA_DEVAD,
5199 MDIO_PMA_REG_LASI_STATUS, &val1);
5200 DP(NETIF_MSG_LINK,
5201 "10G-base-T LASI status 0x%x->0x%x\n",
5202 val2, val1);
5203 bnx2x_cl45_read(bp, params->port, ext_phy_type,
5204 ext_phy_addr,
5205 MDIO_PMA_DEVAD,
5206 MDIO_PMA_REG_STATUS, &val2);
5207 bnx2x_cl45_read(bp, params->port, ext_phy_type,
5208 ext_phy_addr,
5209 MDIO_PMA_DEVAD,
5210 MDIO_PMA_REG_STATUS, &val1);
5211 DP(NETIF_MSG_LINK,
5212 "10G-base-T PMA status 0x%x->0x%x\n",
5213 val2, val1);
5214 ext_phy_link_up = ((val1 & 4) == 4);
5215 /* if link is up
5216 * print the AN outcome of the SFX7101 PHY
5217 */
5218 if (ext_phy_link_up) {
5219 bnx2x_cl45_read(bp, params->port,
5220 ext_phy_type,
5221 ext_phy_addr,
5222 MDIO_AN_DEVAD,
5223 MDIO_AN_REG_MASTER_STATUS,
5224 &val2);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07005225 vars->line_speed = SPEED_10000;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005226 DP(NETIF_MSG_LINK,
5227 "SFX7101 AN status 0x%x->Master=%x\n",
5228 val2,
5229 (val2 & (1<<14)));
5230 }
5231 break;
Eilon Greenstein28577182009-02-12 08:37:00 +00005232 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8481:
Eilon Greenstein2f904462009-08-12 08:22:16 +00005233 /* Check 10G-BaseT link status */
5234 /* Check PMD signal ok */
5235 bnx2x_cl45_read(bp, params->port, ext_phy_type,
5236 ext_phy_addr,
5237 MDIO_AN_DEVAD,
5238 0xFFFA,
5239 &val1);
5240 bnx2x_cl45_read(bp, params->port, ext_phy_type,
Eilon Greenstein28577182009-02-12 08:37:00 +00005241 ext_phy_addr,
5242 MDIO_PMA_DEVAD,
Eilon Greenstein2f904462009-08-12 08:22:16 +00005243 MDIO_PMA_REG_8481_PMD_SIGNAL,
5244 &val2);
5245 DP(NETIF_MSG_LINK, "PMD_SIGNAL 1.a811 = 0x%x\n", val2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005246
Eilon Greenstein2f904462009-08-12 08:22:16 +00005247 /* Check link 10G */
5248 if (val2 & (1<<11)) {
Eilon Greenstein28577182009-02-12 08:37:00 +00005249 vars->line_speed = SPEED_10000;
5250 ext_phy_link_up = 1;
Eilon Greenstein2f904462009-08-12 08:22:16 +00005251 bnx2x_8481_set_10G_led_mode(params,
5252 ext_phy_type,
5253 ext_phy_addr);
5254 } else { /* Check Legacy speed link */
5255 u16 legacy_status, legacy_speed;
Eilon Greenstein28577182009-02-12 08:37:00 +00005256
Eilon Greenstein2f904462009-08-12 08:22:16 +00005257 /* Enable expansion register 0x42
5258 (Operation mode status) */
5259 bnx2x_cl45_write(bp, params->port,
5260 ext_phy_type,
5261 ext_phy_addr,
5262 MDIO_AN_DEVAD,
5263 MDIO_AN_REG_8481_EXPANSION_REG_ACCESS,
5264 0xf42);
Eilon Greenstein28577182009-02-12 08:37:00 +00005265
Eilon Greenstein2f904462009-08-12 08:22:16 +00005266 /* Get legacy speed operation status */
5267 bnx2x_cl45_read(bp, params->port,
5268 ext_phy_type,
5269 ext_phy_addr,
5270 MDIO_AN_DEVAD,
5271 MDIO_AN_REG_8481_EXPANSION_REG_RD_RW,
5272 &legacy_status);
5273
5274 DP(NETIF_MSG_LINK, "Legacy speed status"
5275 " = 0x%x\n", legacy_status);
5276 ext_phy_link_up = ((legacy_status & (1<<11))
5277 == (1<<11));
5278 if (ext_phy_link_up) {
5279 legacy_speed = (legacy_status & (3<<9));
5280 if (legacy_speed == (0<<9))
5281 vars->line_speed = SPEED_10;
5282 else if (legacy_speed == (1<<9))
5283 vars->line_speed =
5284 SPEED_100;
5285 else if (legacy_speed == (2<<9))
5286 vars->line_speed =
5287 SPEED_1000;
5288 else /* Should not happen */
5289 vars->line_speed = 0;
5290
5291 if (legacy_status & (1<<8))
5292 vars->duplex = DUPLEX_FULL;
5293 else
5294 vars->duplex = DUPLEX_HALF;
5295
5296 DP(NETIF_MSG_LINK, "Link is up "
5297 "in %dMbps, is_duplex_full"
5298 "= %d\n",
5299 vars->line_speed,
5300 (vars->duplex == DUPLEX_FULL));
5301 bnx2x_8481_set_legacy_led_mode(params,
5302 ext_phy_type,
5303 ext_phy_addr);
Eilon Greenstein28577182009-02-12 08:37:00 +00005304 }
5305 }
Eilon Greenstein28577182009-02-12 08:37:00 +00005306 break;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005307 default:
5308 DP(NETIF_MSG_LINK, "BAD XGXS ext_phy_config 0x%x\n",
5309 params->ext_phy_config);
5310 ext_phy_link_up = 0;
5311 break;
5312 }
Eilon Greenstein57937202009-08-12 08:23:53 +00005313 /* Set SGMII mode for external phy */
5314 if (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT) {
5315 if (vars->line_speed < SPEED_1000)
5316 vars->phy_flags |= PHY_SGMII_FLAG;
5317 else
5318 vars->phy_flags &= ~PHY_SGMII_FLAG;
5319 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005320
5321 } else { /* SerDes */
5322 ext_phy_type = SERDES_EXT_PHY_TYPE(params->ext_phy_config);
5323 switch (ext_phy_type) {
5324 case PORT_HW_CFG_SERDES_EXT_PHY_TYPE_DIRECT:
5325 DP(NETIF_MSG_LINK, "SerDes Direct\n");
5326 ext_phy_link_up = 1;
5327 break;
5328
5329 case PORT_HW_CFG_SERDES_EXT_PHY_TYPE_BCM5482:
5330 DP(NETIF_MSG_LINK, "SerDes 5482\n");
5331 ext_phy_link_up = 1;
5332 break;
5333
5334 default:
5335 DP(NETIF_MSG_LINK,
5336 "BAD SerDes ext_phy_config 0x%x\n",
5337 params->ext_phy_config);
5338 ext_phy_link_up = 0;
5339 break;
5340 }
5341 }
5342
5343 return ext_phy_link_up;
5344}
5345
5346static void bnx2x_link_int_enable(struct link_params *params)
5347{
5348 u8 port = params->port;
5349 u32 ext_phy_type;
5350 u32 mask;
5351 struct bnx2x *bp = params->bp;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00005352
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005353 /* setting the status to report on link up
5354 for either XGXS or SerDes */
5355
5356 if (params->switch_cfg == SWITCH_CFG_10G) {
5357 mask = (NIG_MASK_XGXS0_LINK10G |
5358 NIG_MASK_XGXS0_LINK_STATUS);
5359 DP(NETIF_MSG_LINK, "enabled XGXS interrupt\n");
5360 ext_phy_type = XGXS_EXT_PHY_TYPE(params->ext_phy_config);
5361 if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT) &&
5362 (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
5363 (ext_phy_type !=
5364 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN)) {
5365 mask |= NIG_MASK_MI_INT;
5366 DP(NETIF_MSG_LINK, "enabled external phy int\n");
5367 }
5368
5369 } else { /* SerDes */
5370 mask = NIG_MASK_SERDES0_LINK_STATUS;
5371 DP(NETIF_MSG_LINK, "enabled SerDes interrupt\n");
5372 ext_phy_type = SERDES_EXT_PHY_TYPE(params->ext_phy_config);
5373 if ((ext_phy_type !=
5374 PORT_HW_CFG_SERDES_EXT_PHY_TYPE_DIRECT) &&
5375 (ext_phy_type !=
5376 PORT_HW_CFG_SERDES_EXT_PHY_TYPE_NOT_CONN)) {
5377 mask |= NIG_MASK_MI_INT;
5378 DP(NETIF_MSG_LINK, "enabled external phy int\n");
5379 }
5380 }
5381 bnx2x_bits_en(bp,
5382 NIG_REG_MASK_INTERRUPT_PORT0 + port*4,
5383 mask);
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00005384
5385 DP(NETIF_MSG_LINK, "port %x, is_xgxs %x, int_status 0x%x\n", port,
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005386 (params->switch_cfg == SWITCH_CFG_10G),
5387 REG_RD(bp, NIG_REG_STATUS_INTERRUPT_PORT0 + port*4));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005388 DP(NETIF_MSG_LINK, " int_mask 0x%x, MI_INT %x, SERDES_LINK %x\n",
5389 REG_RD(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4),
5390 REG_RD(bp, NIG_REG_EMAC0_STATUS_MISC_MI_INT + port*0x18),
5391 REG_RD(bp, NIG_REG_SERDES0_STATUS_LINK_STATUS+port*0x3c));
5392 DP(NETIF_MSG_LINK, " 10G %x, XGXS_LINK %x\n",
5393 REG_RD(bp, NIG_REG_XGXS0_STATUS_LINK10G + port*0x68),
5394 REG_RD(bp, NIG_REG_XGXS0_STATUS_LINK_STATUS + port*0x68));
5395}
5396
Eilon Greenstein2f904462009-08-12 08:22:16 +00005397static void bnx2x_8481_rearm_latch_signal(struct bnx2x *bp, u8 port,
5398 u8 is_mi_int)
5399{
5400 u32 latch_status = 0, is_mi_int_status;
5401 /* Disable the MI INT ( external phy int )
5402 * by writing 1 to the status register. Link down indication
5403 * is high-active-signal, so in this case we need to write the
5404 * status to clear the XOR
5405 */
5406 /* Read Latched signals */
5407 latch_status = REG_RD(bp,
5408 NIG_REG_LATCH_STATUS_0 + port*8);
5409 is_mi_int_status = REG_RD(bp,
5410 NIG_REG_STATUS_INTERRUPT_PORT0 + port*4);
5411 DP(NETIF_MSG_LINK, "original_signal = 0x%x, nig_status = 0x%x,"
5412 "latch_status = 0x%x\n",
5413 is_mi_int, is_mi_int_status, latch_status);
5414 /* Handle only those with latched-signal=up.*/
5415 if (latch_status & 1) {
5416 /* For all latched-signal=up,Write original_signal to status */
5417 if (is_mi_int)
5418 bnx2x_bits_en(bp,
5419 NIG_REG_STATUS_INTERRUPT_PORT0
5420 + port*4,
5421 NIG_STATUS_EMAC0_MI_INT);
5422 else
5423 bnx2x_bits_dis(bp,
5424 NIG_REG_STATUS_INTERRUPT_PORT0
5425 + port*4,
5426 NIG_STATUS_EMAC0_MI_INT);
5427 /* For all latched-signal=up : Re-Arm Latch signals */
5428 REG_WR(bp, NIG_REG_LATCH_STATUS_0 + port*8,
5429 (latch_status & 0xfffe) | (latch_status & 1));
5430 }
5431}
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005432/*
5433 * link management
5434 */
5435static void bnx2x_link_int_ack(struct link_params *params,
Eilon Greenstein2f904462009-08-12 08:22:16 +00005436 struct link_vars *vars, u8 is_10g,
5437 u8 is_mi_int)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005438{
5439 struct bnx2x *bp = params->bp;
5440 u8 port = params->port;
5441
5442 /* first reset all status
5443 * we assume only one line will be change at a time */
5444 bnx2x_bits_dis(bp, NIG_REG_STATUS_INTERRUPT_PORT0 + port*4,
5445 (NIG_STATUS_XGXS0_LINK10G |
5446 NIG_STATUS_XGXS0_LINK_STATUS |
5447 NIG_STATUS_SERDES0_LINK_STATUS));
Eilon Greenstein2f904462009-08-12 08:22:16 +00005448 if (XGXS_EXT_PHY_TYPE(params->ext_phy_config)
5449 == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8481) {
5450 bnx2x_8481_rearm_latch_signal(bp, port, is_mi_int);
5451 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005452 if (vars->phy_link_up) {
5453 if (is_10g) {
5454 /* Disable the 10G link interrupt
5455 * by writing 1 to the status register
5456 */
5457 DP(NETIF_MSG_LINK, "10G XGXS phy link up\n");
5458 bnx2x_bits_en(bp,
5459 NIG_REG_STATUS_INTERRUPT_PORT0 + port*4,
5460 NIG_STATUS_XGXS0_LINK10G);
5461
5462 } else if (params->switch_cfg == SWITCH_CFG_10G) {
5463 /* Disable the link interrupt
5464 * by writing 1 to the relevant lane
5465 * in the status register
5466 */
5467 u32 ser_lane = ((params->lane_config &
5468 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_MASK) >>
5469 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_SHIFT);
5470
Eilon Greenstein2f904462009-08-12 08:22:16 +00005471 DP(NETIF_MSG_LINK, "%d speed XGXS phy link up\n",
5472 vars->line_speed);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005473 bnx2x_bits_en(bp,
5474 NIG_REG_STATUS_INTERRUPT_PORT0 + port*4,
5475 ((1 << ser_lane) <<
5476 NIG_STATUS_XGXS0_LINK_STATUS_SIZE));
5477
5478 } else { /* SerDes */
5479 DP(NETIF_MSG_LINK, "SerDes phy link up\n");
5480 /* Disable the link interrupt
5481 * by writing 1 to the status register
5482 */
5483 bnx2x_bits_en(bp,
5484 NIG_REG_STATUS_INTERRUPT_PORT0 + port*4,
5485 NIG_STATUS_SERDES0_LINK_STATUS);
5486 }
5487
5488 } else { /* link_down */
5489 }
5490}
5491
5492static u8 bnx2x_format_ver(u32 num, u8 *str, u16 len)
5493{
5494 u8 *str_ptr = str;
5495 u32 mask = 0xf0000000;
5496 u8 shift = 8*4;
5497 u8 digit;
5498 if (len < 10) {
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02005499 /* Need more than 10chars for this format */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005500 *str_ptr = '\0';
5501 return -EINVAL;
5502 }
5503 while (shift > 0) {
5504
5505 shift -= 4;
5506 digit = ((num & mask) >> shift);
5507 if (digit < 0xa)
5508 *str_ptr = digit + '0';
5509 else
5510 *str_ptr = digit - 0xa + 'a';
5511 str_ptr++;
5512 mask = mask >> 4;
5513 if (shift == 4*4) {
5514 *str_ptr = ':';
5515 str_ptr++;
5516 }
5517 }
5518 *str_ptr = '\0';
5519 return 0;
5520}
5521
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005522u8 bnx2x_get_ext_phy_fw_version(struct link_params *params, u8 driver_loaded,
5523 u8 *version, u16 len)
5524{
Julia Lawall0376d5b2009-07-19 05:26:35 +00005525 struct bnx2x *bp;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005526 u32 ext_phy_type = 0;
Eilon Greensteina35da8d2009-02-12 08:37:02 +00005527 u32 spirom_ver = 0;
Eilon Greenstein97b41da2009-08-12 08:22:59 +00005528 u8 status;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005529
5530 if (version == NULL || params == NULL)
5531 return -EINVAL;
Julia Lawall0376d5b2009-07-19 05:26:35 +00005532 bp = params->bp;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005533
Eilon Greensteina35da8d2009-02-12 08:37:02 +00005534 spirom_ver = REG_RD(bp, params->shmem_base +
5535 offsetof(struct shmem_region,
5536 port_mb[params->port].ext_phy_fw_version));
5537
Eilon Greenstein97b41da2009-08-12 08:22:59 +00005538 status = 0;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005539 /* reset the returned value to zero */
5540 ext_phy_type = XGXS_EXT_PHY_TYPE(params->ext_phy_config);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005541 switch (ext_phy_type) {
5542 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101:
5543
5544 if (len < 5)
5545 return -EINVAL;
5546
Eilon Greensteina35da8d2009-02-12 08:37:02 +00005547 version[0] = (spirom_ver & 0xFF);
5548 version[1] = (spirom_ver & 0xFF00) >> 8;
5549 version[2] = (spirom_ver & 0xFF0000) >> 16;
5550 version[3] = (spirom_ver & 0xFF000000) >> 24;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005551 version[4] = '\0';
5552
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005553 break;
5554 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8072:
5555 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073:
Eilon Greenstein4d295db2009-07-21 05:47:47 +00005556 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005557 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706:
Eilon Greenstein589abe32009-02-12 08:36:55 +00005558 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
Eilon Greensteinb1607af2009-08-12 08:22:54 +00005559 status = bnx2x_format_ver(spirom_ver, version, len);
5560 break;
Eilon Greenstein9223dea2009-03-02 08:00:15 +00005561 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8481:
Eilon Greensteinb1607af2009-08-12 08:22:54 +00005562 spirom_ver = ((spirom_ver & 0xF80) >> 7) << 16 |
5563 (spirom_ver & 0x7F);
Eilon Greensteina35da8d2009-02-12 08:37:02 +00005564 status = bnx2x_format_ver(spirom_ver, version, len);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005565 break;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005566 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT:
Eilon Greenstein97b41da2009-08-12 08:22:59 +00005567 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705:
5568 version[0] = '\0';
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005569 break;
5570
5571 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE:
5572 DP(NETIF_MSG_LINK, "bnx2x_get_ext_phy_fw_version:"
5573 " type is FAILURE!\n");
5574 status = -EINVAL;
5575 break;
5576
5577 default:
5578 break;
5579 }
5580 return status;
5581}
5582
5583static void bnx2x_set_xgxs_loopback(struct link_params *params,
5584 struct link_vars *vars,
5585 u8 is_10g)
5586{
5587 u8 port = params->port;
5588 struct bnx2x *bp = params->bp;
5589
5590 if (is_10g) {
Eilon Greenstein6378c022008-08-13 15:59:25 -07005591 u32 md_devad;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005592
5593 DP(NETIF_MSG_LINK, "XGXS 10G loopback enable\n");
5594
5595 /* change the uni_phy_addr in the nig */
5596 md_devad = REG_RD(bp, (NIG_REG_XGXS0_CTRL_MD_DEVAD +
5597 port*0x18));
5598
5599 REG_WR(bp, NIG_REG_XGXS0_CTRL_MD_DEVAD + port*0x18, 0x5);
5600
5601 bnx2x_cl45_write(bp, port, 0,
5602 params->phy_addr,
5603 5,
5604 (MDIO_REG_BANK_AER_BLOCK +
5605 (MDIO_AER_BLOCK_AER_REG & 0xf)),
5606 0x2800);
5607
5608 bnx2x_cl45_write(bp, port, 0,
5609 params->phy_addr,
5610 5,
5611 (MDIO_REG_BANK_CL73_IEEEB0 +
5612 (MDIO_CL73_IEEEB0_CL73_AN_CONTROL & 0xf)),
5613 0x6041);
Eilon Greenstein38582762009-01-14 06:44:16 +00005614 msleep(200);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005615 /* set aer mmd back */
5616 bnx2x_set_aer_mmd(params, vars);
5617
5618 /* and md_devad */
5619 REG_WR(bp, NIG_REG_XGXS0_CTRL_MD_DEVAD + port*0x18,
5620 md_devad);
5621
5622 } else {
5623 u16 mii_control;
5624
5625 DP(NETIF_MSG_LINK, "XGXS 1G loopback enable\n");
5626
5627 CL45_RD_OVER_CL22(bp, port,
5628 params->phy_addr,
5629 MDIO_REG_BANK_COMBO_IEEE0,
5630 MDIO_COMBO_IEEE0_MII_CONTROL,
5631 &mii_control);
5632
5633 CL45_WR_OVER_CL22(bp, port,
5634 params->phy_addr,
5635 MDIO_REG_BANK_COMBO_IEEE0,
5636 MDIO_COMBO_IEEE0_MII_CONTROL,
5637 (mii_control |
5638 MDIO_COMBO_IEEO_MII_CONTROL_LOOPBACK));
5639 }
5640}
5641
5642
5643static void bnx2x_ext_phy_loopback(struct link_params *params)
5644{
5645 struct bnx2x *bp = params->bp;
5646 u8 ext_phy_addr;
5647 u32 ext_phy_type;
5648
5649 if (params->switch_cfg == SWITCH_CFG_10G) {
5650 ext_phy_type = XGXS_EXT_PHY_TYPE(params->ext_phy_config);
Eilon Greenstein659bc5c2009-08-12 08:24:02 +00005651 ext_phy_addr = XGXS_EXT_PHY_ADDR(params->ext_phy_config);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005652 /* CL37 Autoneg Enabled */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005653 switch (ext_phy_type) {
5654 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT:
5655 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN:
5656 DP(NETIF_MSG_LINK,
5657 "ext_phy_loopback: We should not get here\n");
5658 break;
5659 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705:
5660 DP(NETIF_MSG_LINK, "ext_phy_loopback: 8705\n");
5661 break;
5662 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706:
5663 DP(NETIF_MSG_LINK, "ext_phy_loopback: 8706\n");
5664 break;
Eilon Greenstein589abe32009-02-12 08:36:55 +00005665 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
5666 DP(NETIF_MSG_LINK, "PMA/PMD ext_phy_loopback: 8726\n");
5667 bnx2x_cl45_write(bp, params->port, ext_phy_type,
5668 ext_phy_addr,
5669 MDIO_PMA_DEVAD,
5670 MDIO_PMA_REG_CTRL,
5671 0x0001);
5672 break;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005673 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101:
5674 /* SFX7101_XGXS_TEST1 */
5675 bnx2x_cl45_write(bp, params->port, ext_phy_type,
5676 ext_phy_addr,
5677 MDIO_XS_DEVAD,
5678 MDIO_XS_SFX7101_XGXS_TEST1,
5679 0x100);
5680 DP(NETIF_MSG_LINK,
5681 "ext_phy_loopback: set ext phy loopback\n");
5682 break;
5683 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8072:
5684
5685 break;
5686 } /* switch external PHY type */
5687 } else {
5688 /* serdes */
5689 ext_phy_type = SERDES_EXT_PHY_TYPE(params->ext_phy_config);
5690 ext_phy_addr = (params->ext_phy_config &
5691 PORT_HW_CFG_SERDES_EXT_PHY_ADDR_MASK)
5692 >> PORT_HW_CFG_SERDES_EXT_PHY_ADDR_SHIFT;
5693 }
5694}
5695
5696
5697/*
5698 *------------------------------------------------------------------------
5699 * bnx2x_override_led_value -
5700 *
5701 * Override the led value of the requsted led
5702 *
5703 *------------------------------------------------------------------------
5704 */
5705u8 bnx2x_override_led_value(struct bnx2x *bp, u8 port,
5706 u32 led_idx, u32 value)
5707{
5708 u32 reg_val;
5709
5710 /* If port 0 then use EMAC0, else use EMAC1*/
5711 u32 emac_base = (port) ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
5712
5713 DP(NETIF_MSG_LINK,
5714 "bnx2x_override_led_value() port %x led_idx %d value %d\n",
5715 port, led_idx, value);
5716
5717 switch (led_idx) {
5718 case 0: /* 10MB led */
5719 /* Read the current value of the LED register in
5720 the EMAC block */
5721 reg_val = REG_RD(bp, emac_base + EMAC_REG_EMAC_LED);
5722 /* Set the OVERRIDE bit to 1 */
5723 reg_val |= EMAC_LED_OVERRIDE;
5724 /* If value is 1, set the 10M_OVERRIDE bit,
5725 otherwise reset it.*/
5726 reg_val = (value == 1) ? (reg_val | EMAC_LED_10MB_OVERRIDE) :
5727 (reg_val & ~EMAC_LED_10MB_OVERRIDE);
5728 REG_WR(bp, emac_base + EMAC_REG_EMAC_LED, reg_val);
5729 break;
5730 case 1: /*100MB led */
5731 /*Read the current value of the LED register in
5732 the EMAC block */
5733 reg_val = REG_RD(bp, emac_base + EMAC_REG_EMAC_LED);
5734 /* Set the OVERRIDE bit to 1 */
5735 reg_val |= EMAC_LED_OVERRIDE;
5736 /* If value is 1, set the 100M_OVERRIDE bit,
5737 otherwise reset it.*/
5738 reg_val = (value == 1) ? (reg_val | EMAC_LED_100MB_OVERRIDE) :
5739 (reg_val & ~EMAC_LED_100MB_OVERRIDE);
5740 REG_WR(bp, emac_base + EMAC_REG_EMAC_LED, reg_val);
5741 break;
5742 case 2: /* 1000MB led */
5743 /* Read the current value of the LED register in the
5744 EMAC block */
5745 reg_val = REG_RD(bp, emac_base + EMAC_REG_EMAC_LED);
5746 /* Set the OVERRIDE bit to 1 */
5747 reg_val |= EMAC_LED_OVERRIDE;
5748 /* If value is 1, set the 1000M_OVERRIDE bit, otherwise
5749 reset it. */
5750 reg_val = (value == 1) ? (reg_val | EMAC_LED_1000MB_OVERRIDE) :
5751 (reg_val & ~EMAC_LED_1000MB_OVERRIDE);
5752 REG_WR(bp, emac_base + EMAC_REG_EMAC_LED, reg_val);
5753 break;
5754 case 3: /* 2500MB led */
5755 /* Read the current value of the LED register in the
5756 EMAC block*/
5757 reg_val = REG_RD(bp, emac_base + EMAC_REG_EMAC_LED);
5758 /* Set the OVERRIDE bit to 1 */
5759 reg_val |= EMAC_LED_OVERRIDE;
5760 /* If value is 1, set the 2500M_OVERRIDE bit, otherwise
5761 reset it.*/
5762 reg_val = (value == 1) ? (reg_val | EMAC_LED_2500MB_OVERRIDE) :
5763 (reg_val & ~EMAC_LED_2500MB_OVERRIDE);
5764 REG_WR(bp, emac_base + EMAC_REG_EMAC_LED, reg_val);
5765 break;
5766 case 4: /*10G led */
5767 if (port == 0) {
5768 REG_WR(bp, NIG_REG_LED_10G_P0,
5769 value);
5770 } else {
5771 REG_WR(bp, NIG_REG_LED_10G_P1,
5772 value);
5773 }
5774 break;
5775 case 5: /* TRAFFIC led */
5776 /* Find if the traffic control is via BMAC or EMAC */
5777 if (port == 0)
5778 reg_val = REG_RD(bp, NIG_REG_NIG_EMAC0_EN);
5779 else
5780 reg_val = REG_RD(bp, NIG_REG_NIG_EMAC1_EN);
5781
5782 /* Override the traffic led in the EMAC:*/
5783 if (reg_val == 1) {
5784 /* Read the current value of the LED register in
5785 the EMAC block */
5786 reg_val = REG_RD(bp, emac_base +
5787 EMAC_REG_EMAC_LED);
5788 /* Set the TRAFFIC_OVERRIDE bit to 1 */
5789 reg_val |= EMAC_LED_OVERRIDE;
5790 /* If value is 1, set the TRAFFIC bit, otherwise
5791 reset it.*/
5792 reg_val = (value == 1) ? (reg_val | EMAC_LED_TRAFFIC) :
5793 (reg_val & ~EMAC_LED_TRAFFIC);
5794 REG_WR(bp, emac_base + EMAC_REG_EMAC_LED, reg_val);
5795 } else { /* Override the traffic led in the BMAC: */
5796 REG_WR(bp, NIG_REG_LED_CONTROL_OVERRIDE_TRAFFIC_P0
5797 + port*4, 1);
5798 REG_WR(bp, NIG_REG_LED_CONTROL_TRAFFIC_P0 + port*4,
5799 value);
5800 }
5801 break;
5802 default:
5803 DP(NETIF_MSG_LINK,
5804 "bnx2x_override_led_value() unknown led index %d "
5805 "(should be 0-5)\n", led_idx);
5806 return -EINVAL;
5807 }
5808
5809 return 0;
5810}
5811
5812
Yaniv Rosner7846e472009-11-05 19:18:07 +02005813u8 bnx2x_set_led(struct link_params *params, u8 mode, u32 speed)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005814{
Yaniv Rosner7846e472009-11-05 19:18:07 +02005815 u8 port = params->port;
5816 u16 hw_led_mode = params->hw_led_mode;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005817 u8 rc = 0;
Eilon Greenstein345b5d52008-08-13 15:58:12 -07005818 u32 tmp;
5819 u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
Yaniv Rosner7846e472009-11-05 19:18:07 +02005820 u32 ext_phy_type = XGXS_EXT_PHY_TYPE(params->ext_phy_config);
5821 struct bnx2x *bp = params->bp;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005822 DP(NETIF_MSG_LINK, "bnx2x_set_led: port %x, mode %d\n", port, mode);
5823 DP(NETIF_MSG_LINK, "speed 0x%x, hw_led_mode 0x%x\n",
5824 speed, hw_led_mode);
5825 switch (mode) {
5826 case LED_MODE_OFF:
5827 REG_WR(bp, NIG_REG_LED_10G_P0 + port*4, 0);
5828 REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4,
5829 SHARED_HW_CFG_LED_MAC1);
Eilon Greenstein345b5d52008-08-13 15:58:12 -07005830
5831 tmp = EMAC_RD(bp, EMAC_REG_EMAC_LED);
Eilon Greenstein3196a882008-08-13 15:58:49 -07005832 EMAC_WR(bp, EMAC_REG_EMAC_LED, (tmp | EMAC_LED_OVERRIDE));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005833 break;
5834
5835 case LED_MODE_OPER:
Yaniv Rosner7846e472009-11-05 19:18:07 +02005836 if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT) {
5837 REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4, 0);
5838 REG_WR(bp, NIG_REG_LED_10G_P0 + port*4, 1);
5839 } else {
5840 REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4,
5841 hw_led_mode);
5842 }
5843
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005844 REG_WR(bp, NIG_REG_LED_CONTROL_OVERRIDE_TRAFFIC_P0 +
5845 port*4, 0);
5846 /* Set blinking rate to ~15.9Hz */
5847 REG_WR(bp, NIG_REG_LED_CONTROL_BLINK_RATE_P0 + port*4,
5848 LED_BLINK_RATE_VAL);
5849 REG_WR(bp, NIG_REG_LED_CONTROL_BLINK_RATE_ENA_P0 +
5850 port*4, 1);
Eilon Greenstein345b5d52008-08-13 15:58:12 -07005851 tmp = EMAC_RD(bp, EMAC_REG_EMAC_LED);
Eilon Greenstein3196a882008-08-13 15:58:49 -07005852 EMAC_WR(bp, EMAC_REG_EMAC_LED,
Eilon Greenstein345b5d52008-08-13 15:58:12 -07005853 (tmp & (~EMAC_LED_OVERRIDE)));
5854
Yaniv Rosner7846e472009-11-05 19:18:07 +02005855 if (CHIP_IS_E1(bp) &&
Eilon Greenstein34f80b02008-06-23 20:33:01 -07005856 ((speed == SPEED_2500) ||
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005857 (speed == SPEED_1000) ||
5858 (speed == SPEED_100) ||
5859 (speed == SPEED_10))) {
5860 /* On Everest 1 Ax chip versions for speeds less than
5861 10G LED scheme is different */
5862 REG_WR(bp, NIG_REG_LED_CONTROL_OVERRIDE_TRAFFIC_P0
5863 + port*4, 1);
5864 REG_WR(bp, NIG_REG_LED_CONTROL_TRAFFIC_P0 +
5865 port*4, 0);
5866 REG_WR(bp, NIG_REG_LED_CONTROL_BLINK_TRAFFIC_P0 +
5867 port*4, 1);
5868 }
5869 break;
5870
5871 default:
5872 rc = -EINVAL;
5873 DP(NETIF_MSG_LINK, "bnx2x_set_led: Invalid led mode %d\n",
5874 mode);
5875 break;
5876 }
5877 return rc;
5878
5879}
5880
5881u8 bnx2x_test_link(struct link_params *params, struct link_vars *vars)
5882{
5883 struct bnx2x *bp = params->bp;
5884 u16 gp_status = 0;
5885
5886 CL45_RD_OVER_CL22(bp, params->port,
5887 params->phy_addr,
5888 MDIO_REG_BANK_GP_STATUS,
5889 MDIO_GP_STATUS_TOP_AN_STATUS1,
5890 &gp_status);
5891 /* link is up only if both local phy and external phy are up */
5892 if ((gp_status & MDIO_GP_STATUS_TOP_AN_STATUS1_LINK_STATUS) &&
Eilon Greenstein2f904462009-08-12 08:22:16 +00005893 bnx2x_ext_phy_is_link_up(params, vars, 1))
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005894 return 0;
5895
5896 return -ESRCH;
5897}
5898
5899static u8 bnx2x_link_initialize(struct link_params *params,
5900 struct link_vars *vars)
5901{
5902 struct bnx2x *bp = params->bp;
5903 u8 port = params->port;
5904 u8 rc = 0;
Yaniv Rosner57963ed2008-08-13 15:55:28 -07005905 u8 non_ext_phy;
5906 u32 ext_phy_type = XGXS_EXT_PHY_TYPE(params->ext_phy_config);
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00005907
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005908 /* Activate the external PHY */
5909 bnx2x_ext_phy_reset(params, vars);
5910
5911 bnx2x_set_aer_mmd(params, vars);
5912
5913 if (vars->phy_flags & PHY_XGXS_FLAG)
5914 bnx2x_set_master_ln(params);
5915
5916 rc = bnx2x_reset_unicore(params);
5917 /* reset the SerDes and wait for reset bit return low */
5918 if (rc != 0)
5919 return rc;
5920
5921 bnx2x_set_aer_mmd(params, vars);
5922
5923 /* setting the masterLn_def again after the reset */
5924 if (vars->phy_flags & PHY_XGXS_FLAG) {
5925 bnx2x_set_master_ln(params);
5926 bnx2x_set_swap_lanes(params);
5927 }
5928
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005929 if (vars->phy_flags & PHY_XGXS_FLAG) {
Eilon Greenstein44722d12009-01-14 06:44:21 +00005930 if ((params->req_line_speed &&
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005931 ((params->req_line_speed == SPEED_100) ||
Eilon Greenstein44722d12009-01-14 06:44:21 +00005932 (params->req_line_speed == SPEED_10))) ||
5933 (!params->req_line_speed &&
5934 (params->speed_cap_mask >=
5935 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL) &&
5936 (params->speed_cap_mask <
5937 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)
5938 )) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005939 vars->phy_flags |= PHY_SGMII_FLAG;
5940 } else {
5941 vars->phy_flags &= ~PHY_SGMII_FLAG;
5942 }
5943 }
Yaniv Rosner57963ed2008-08-13 15:55:28 -07005944 /* In case of external phy existance, the line speed would be the
5945 line speed linked up by the external phy. In case it is direct only,
5946 then the line_speed during initialization will be equal to the
5947 req_line_speed*/
5948 vars->line_speed = params->req_line_speed;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005949
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07005950 bnx2x_calc_ieee_aneg_adv(params, &vars->ieee_fc);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005951
5952 /* init ext phy and enable link state int */
Yaniv Rosner57963ed2008-08-13 15:55:28 -07005953 non_ext_phy = ((ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT) ||
Eilon Greenstein8660d8c2009-03-02 08:01:02 +00005954 (params->loopback_mode == LOOPBACK_XGXS_10));
Yaniv Rosner57963ed2008-08-13 15:55:28 -07005955
5956 if (non_ext_phy ||
Eilon Greenstein589abe32009-02-12 08:36:55 +00005957 (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705) ||
Yaniv Rosnerb5bbf002009-11-05 19:18:21 +02005958 (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706) ||
Eilon Greenstein28577182009-02-12 08:37:00 +00005959 (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726) ||
Eilon Greenstein8660d8c2009-03-02 08:01:02 +00005960 (params->loopback_mode == LOOPBACK_EXT_PHY)) {
Yaniv Rosner57963ed2008-08-13 15:55:28 -07005961 if (params->req_line_speed == SPEED_AUTO_NEG)
5962 bnx2x_set_parallel_detection(params, vars->phy_flags);
Eilon Greenstein239d6862009-08-12 08:23:04 +00005963 bnx2x_init_internal_phy(params, vars, non_ext_phy);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07005964 }
5965
5966 if (!non_ext_phy)
5967 rc |= bnx2x_ext_phy_init(params, vars);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005968
5969 bnx2x_bits_dis(bp, NIG_REG_STATUS_INTERRUPT_PORT0 + port*4,
Yaniv Rosner57963ed2008-08-13 15:55:28 -07005970 (NIG_STATUS_XGXS0_LINK10G |
5971 NIG_STATUS_XGXS0_LINK_STATUS |
5972 NIG_STATUS_SERDES0_LINK_STATUS));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005973
5974 return rc;
5975
5976}
5977
5978
5979u8 bnx2x_phy_init(struct link_params *params, struct link_vars *vars)
5980{
5981 struct bnx2x *bp = params->bp;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005982 u32 val;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00005983
5984 DP(NETIF_MSG_LINK, "Phy Initialization started\n");
5985 DP(NETIF_MSG_LINK, "req_speed %d, req_flowctrl %d\n",
5986 params->req_line_speed, params->req_flow_ctrl);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005987 vars->link_status = 0;
Yaniv Rosner57963ed2008-08-13 15:55:28 -07005988 vars->phy_link_up = 0;
5989 vars->link_up = 0;
5990 vars->line_speed = 0;
5991 vars->duplex = DUPLEX_FULL;
David S. Millerc0700f92008-12-16 23:53:20 -08005992 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
Yaniv Rosner57963ed2008-08-13 15:55:28 -07005993 vars->mac_type = MAC_TYPE_NONE;
5994
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005995 if (params->switch_cfg == SWITCH_CFG_1G)
5996 vars->phy_flags = PHY_SERDES_FLAG;
5997 else
5998 vars->phy_flags = PHY_XGXS_FLAG;
5999
6000 /* disable attentions */
6001 bnx2x_bits_dis(bp, NIG_REG_MASK_INTERRUPT_PORT0 + params->port*4,
6002 (NIG_MASK_XGXS0_LINK_STATUS |
6003 NIG_MASK_XGXS0_LINK10G |
6004 NIG_MASK_SERDES0_LINK_STATUS |
6005 NIG_MASK_MI_INT));
6006
6007 bnx2x_emac_init(params, vars);
6008
6009 if (CHIP_REV_IS_FPGA(bp)) {
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00006010
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006011 vars->link_up = 1;
6012 vars->line_speed = SPEED_10000;
6013 vars->duplex = DUPLEX_FULL;
David S. Millerc0700f92008-12-16 23:53:20 -08006014 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006015 vars->link_status = (LINK_STATUS_LINK_UP | LINK_10GTFD);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006016 /* enable on E1.5 FPGA */
6017 if (CHIP_IS_E1H(bp)) {
6018 vars->flow_ctrl |=
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00006019 (BNX2X_FLOW_CTRL_TX |
6020 BNX2X_FLOW_CTRL_RX);
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006021 vars->link_status |=
6022 (LINK_STATUS_TX_FLOW_CONTROL_ENABLED |
6023 LINK_STATUS_RX_FLOW_CONTROL_ENABLED);
6024 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006025
6026 bnx2x_emac_enable(params, vars, 0);
6027 bnx2x_pbf_update(params, vars->flow_ctrl, vars->line_speed);
6028 /* disable drain */
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00006029 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006030
6031 /* update shared memory */
6032 bnx2x_update_mng(params, vars->link_status);
6033
6034 return 0;
6035
6036 } else
6037 if (CHIP_REV_IS_EMUL(bp)) {
6038
6039 vars->link_up = 1;
6040 vars->line_speed = SPEED_10000;
6041 vars->duplex = DUPLEX_FULL;
David S. Millerc0700f92008-12-16 23:53:20 -08006042 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006043 vars->link_status = (LINK_STATUS_LINK_UP | LINK_10GTFD);
6044
6045 bnx2x_bmac_enable(params, vars, 0);
6046
6047 bnx2x_pbf_update(params, vars->flow_ctrl, vars->line_speed);
6048 /* Disable drain */
6049 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE
6050 + params->port*4, 0);
6051
6052 /* update shared memory */
6053 bnx2x_update_mng(params, vars->link_status);
6054
6055 return 0;
6056
6057 } else
6058 if (params->loopback_mode == LOOPBACK_BMAC) {
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00006059
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006060 vars->link_up = 1;
6061 vars->line_speed = SPEED_10000;
6062 vars->duplex = DUPLEX_FULL;
David S. Millerc0700f92008-12-16 23:53:20 -08006063 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006064 vars->mac_type = MAC_TYPE_BMAC;
6065
6066 vars->phy_flags = PHY_XGXS_FLAG;
6067
6068 bnx2x_phy_deassert(params, vars->phy_flags);
6069 /* set bmac loopback */
6070 bnx2x_bmac_enable(params, vars, 1);
6071
6072 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE +
6073 params->port*4, 0);
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00006074
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006075 } else if (params->loopback_mode == LOOPBACK_EMAC) {
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00006076
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006077 vars->link_up = 1;
6078 vars->line_speed = SPEED_1000;
6079 vars->duplex = DUPLEX_FULL;
David S. Millerc0700f92008-12-16 23:53:20 -08006080 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006081 vars->mac_type = MAC_TYPE_EMAC;
6082
6083 vars->phy_flags = PHY_XGXS_FLAG;
6084
6085 bnx2x_phy_deassert(params, vars->phy_flags);
6086 /* set bmac loopback */
6087 bnx2x_emac_enable(params, vars, 1);
6088 bnx2x_emac_program(params, vars->line_speed,
6089 vars->duplex);
6090 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE +
6091 params->port*4, 0);
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00006092
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006093 } else if ((params->loopback_mode == LOOPBACK_XGXS_10) ||
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00006094 (params->loopback_mode == LOOPBACK_EXT_PHY)) {
6095
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006096 vars->link_up = 1;
6097 vars->line_speed = SPEED_10000;
6098 vars->duplex = DUPLEX_FULL;
David S. Millerc0700f92008-12-16 23:53:20 -08006099 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006100
6101 vars->phy_flags = PHY_XGXS_FLAG;
6102
6103 val = REG_RD(bp,
6104 NIG_REG_XGXS0_CTRL_PHY_ADDR+
6105 params->port*0x18);
6106 params->phy_addr = (u8)val;
6107
6108 bnx2x_phy_deassert(params, vars->phy_flags);
6109 bnx2x_link_initialize(params, vars);
6110
6111 vars->mac_type = MAC_TYPE_BMAC;
6112
6113 bnx2x_bmac_enable(params, vars, 0);
6114
6115 if (params->loopback_mode == LOOPBACK_XGXS_10) {
6116 /* set 10G XGXS loopback */
6117 bnx2x_set_xgxs_loopback(params, vars, 1);
6118 } else {
6119 /* set external phy loopback */
6120 bnx2x_ext_phy_loopback(params);
6121 }
6122 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE +
6123 params->port*4, 0);
Eilon Greensteinba71d312009-07-21 05:47:49 +00006124
Yaniv Rosner7846e472009-11-05 19:18:07 +02006125 bnx2x_set_led(params, LED_MODE_OPER, vars->line_speed);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006126 } else
6127 /* No loopback */
6128 {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006129 bnx2x_phy_deassert(params, vars->phy_flags);
6130 switch (params->switch_cfg) {
6131 case SWITCH_CFG_1G:
6132 vars->phy_flags |= PHY_SERDES_FLAG;
6133 if ((params->ext_phy_config &
6134 PORT_HW_CFG_SERDES_EXT_PHY_TYPE_MASK) ==
6135 PORT_HW_CFG_SERDES_EXT_PHY_TYPE_BCM5482) {
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00006136 vars->phy_flags |= PHY_SGMII_FLAG;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006137 }
6138
6139 val = REG_RD(bp,
6140 NIG_REG_SERDES0_CTRL_PHY_ADDR+
6141 params->port*0x10);
6142
6143 params->phy_addr = (u8)val;
6144
6145 break;
6146 case SWITCH_CFG_10G:
6147 vars->phy_flags |= PHY_XGXS_FLAG;
6148 val = REG_RD(bp,
6149 NIG_REG_XGXS0_CTRL_PHY_ADDR+
6150 params->port*0x18);
6151 params->phy_addr = (u8)val;
6152
6153 break;
6154 default:
6155 DP(NETIF_MSG_LINK, "Invalid switch_cfg\n");
6156 return -EINVAL;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006157 }
Eilon Greensteinf5372252009-02-12 08:38:30 +00006158 DP(NETIF_MSG_LINK, "Phy address = 0x%x\n", params->phy_addr);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006159
6160 bnx2x_link_initialize(params, vars);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006161 msleep(30);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006162 bnx2x_link_int_enable(params);
6163 }
6164 return 0;
6165}
6166
Eilon Greenstein589abe32009-02-12 08:36:55 +00006167static void bnx2x_8726_reset_phy(struct bnx2x *bp, u8 port, u8 ext_phy_addr)
6168{
6169 DP(NETIF_MSG_LINK, "bnx2x_8726_reset_phy port %d\n", port);
6170
6171 /* Set serial boot control for external load */
6172 bnx2x_cl45_write(bp, port,
6173 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726, ext_phy_addr,
6174 MDIO_PMA_DEVAD,
6175 MDIO_PMA_REG_GEN_CTRL, 0x0001);
Eilon Greenstein589abe32009-02-12 08:36:55 +00006176}
6177
6178u8 bnx2x_link_reset(struct link_params *params, struct link_vars *vars,
6179 u8 reset_ext_phy)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006180{
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006181 struct bnx2x *bp = params->bp;
6182 u32 ext_phy_config = params->ext_phy_config;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006183 u8 port = params->port;
6184 u32 ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
Eilon Greenstein4d295db2009-07-21 05:47:47 +00006185 u32 val = REG_RD(bp, params->shmem_base +
6186 offsetof(struct shmem_region, dev_info.
6187 port_feature_config[params->port].
6188 config));
Yaniv Rosnerd5cb9e92009-11-05 19:18:10 +02006189 DP(NETIF_MSG_LINK, "Resetting the link of port %d\n", port);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006190 /* disable attentions */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006191 vars->link_status = 0;
6192 bnx2x_update_mng(params, vars->link_status);
6193 bnx2x_bits_dis(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4,
6194 (NIG_MASK_XGXS0_LINK_STATUS |
6195 NIG_MASK_XGXS0_LINK10G |
6196 NIG_MASK_SERDES0_LINK_STATUS |
6197 NIG_MASK_MI_INT));
6198
6199 /* activate nig drain */
6200 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + port*4, 1);
6201
6202 /* disable nig egress interface */
6203 REG_WR(bp, NIG_REG_BMAC0_OUT_EN + port*4, 0);
6204 REG_WR(bp, NIG_REG_EGRESS_EMAC0_OUT_EN + port*4, 0);
6205
6206 /* Stop BigMac rx */
6207 bnx2x_bmac_rx_disable(bp, port);
6208
6209 /* disable emac */
6210 REG_WR(bp, NIG_REG_NIG_EMAC0_EN + port*4, 0);
6211
6212 msleep(10);
6213 /* The PHY reset is controled by GPIO 1
6214 * Hold it as vars low
6215 */
6216 /* clear link led */
Yaniv Rosner7846e472009-11-05 19:18:07 +02006217 bnx2x_set_led(params, LED_MODE_OFF, 0);
Eilon Greenstein589abe32009-02-12 08:36:55 +00006218 if (reset_ext_phy) {
6219 switch (ext_phy_type) {
6220 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT:
6221 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8072:
6222 break;
Eilon Greenstein4d295db2009-07-21 05:47:47 +00006223
6224 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
6225 {
6226
6227 /* Disable Transmitter */
Eilon Greenstein659bc5c2009-08-12 08:24:02 +00006228 u8 ext_phy_addr =
6229 XGXS_EXT_PHY_ADDR(params->ext_phy_config);
Eilon Greenstein4d295db2009-07-21 05:47:47 +00006230 if ((val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) ==
6231 PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_DISABLE_TX_LASER)
6232 bnx2x_sfp_set_transmitter(bp, port,
6233 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727,
6234 ext_phy_addr, 0);
6235 break;
6236 }
Eilon Greenstein589abe32009-02-12 08:36:55 +00006237 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073:
6238 DP(NETIF_MSG_LINK, "Setting 8073 port %d into "
6239 "low power mode\n",
6240 port);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006241 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Eilon Greenstein17de50b2008-08-13 15:56:59 -07006242 MISC_REGISTERS_GPIO_OUTPUT_LOW,
6243 port);
Eilon Greenstein589abe32009-02-12 08:36:55 +00006244 break;
6245 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
6246 {
Eilon Greenstein659bc5c2009-08-12 08:24:02 +00006247 u8 ext_phy_addr =
6248 XGXS_EXT_PHY_ADDR(params->ext_phy_config);
Eilon Greenstein589abe32009-02-12 08:36:55 +00006249 /* Set soft reset */
6250 bnx2x_8726_reset_phy(bp, params->port, ext_phy_addr);
6251 break;
6252 }
6253 default:
6254 /* HW reset */
6255 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
6256 MISC_REGISTERS_GPIO_OUTPUT_LOW,
6257 port);
6258 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
6259 MISC_REGISTERS_GPIO_OUTPUT_LOW,
6260 port);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006261 DP(NETIF_MSG_LINK, "reset external PHY\n");
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006262 }
6263 }
6264 /* reset the SerDes/XGXS */
6265 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_CLEAR,
6266 (0x1ff << (port*16)));
6267
6268 /* reset BigMac */
6269 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
6270 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port));
6271
6272 /* disable nig ingress interface */
6273 REG_WR(bp, NIG_REG_BMAC0_IN_EN + port*4, 0);
6274 REG_WR(bp, NIG_REG_EMAC0_IN_EN + port*4, 0);
6275 REG_WR(bp, NIG_REG_BMAC0_OUT_EN + port*4, 0);
6276 REG_WR(bp, NIG_REG_EGRESS_EMAC0_OUT_EN + port*4, 0);
6277 vars->link_up = 0;
6278 return 0;
6279}
6280
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006281static u8 bnx2x_update_link_down(struct link_params *params,
6282 struct link_vars *vars)
6283{
6284 struct bnx2x *bp = params->bp;
6285 u8 port = params->port;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00006286
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006287 DP(NETIF_MSG_LINK, "Port %x: Link is down\n", port);
Yaniv Rosner7846e472009-11-05 19:18:07 +02006288 bnx2x_set_led(params, LED_MODE_OFF, 0);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006289
6290 /* indicate no mac active */
6291 vars->mac_type = MAC_TYPE_NONE;
6292
6293 /* update shared memory */
6294 vars->link_status = 0;
6295 vars->line_speed = 0;
6296 bnx2x_update_mng(params, vars->link_status);
6297
6298 /* activate nig drain */
6299 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + port*4, 1);
6300
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00006301 /* disable emac */
6302 REG_WR(bp, NIG_REG_NIG_EMAC0_EN + port*4, 0);
6303
6304 msleep(10);
6305
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006306 /* reset BigMac */
6307 bnx2x_bmac_rx_disable(bp, params->port);
6308 REG_WR(bp, GRCBASE_MISC +
6309 MISC_REGISTERS_RESET_REG_2_CLEAR,
6310 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port));
6311 return 0;
6312}
6313
6314static u8 bnx2x_update_link_up(struct link_params *params,
6315 struct link_vars *vars,
6316 u8 link_10g, u32 gp_status)
6317{
6318 struct bnx2x *bp = params->bp;
6319 u8 port = params->port;
6320 u8 rc = 0;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00006321
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006322 vars->link_status |= LINK_STATUS_LINK_UP;
6323 if (link_10g) {
6324 bnx2x_bmac_enable(params, vars, 0);
Yaniv Rosner7846e472009-11-05 19:18:07 +02006325 bnx2x_set_led(params, LED_MODE_OPER, SPEED_10000);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006326 } else {
6327 bnx2x_emac_enable(params, vars, 0);
6328 rc = bnx2x_emac_program(params, vars->line_speed,
6329 vars->duplex);
6330
6331 /* AN complete? */
6332 if (gp_status & MDIO_AN_CL73_OR_37_COMPLETE) {
6333 if (!(vars->phy_flags &
6334 PHY_SGMII_FLAG))
Eilon Greensteined8680a2009-02-12 08:37:12 +00006335 bnx2x_set_gmii_tx_driver(params);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006336 }
6337 }
6338
6339 /* PBF - link up */
6340 rc |= bnx2x_pbf_update(params, vars->flow_ctrl,
6341 vars->line_speed);
6342
6343 /* disable drain */
6344 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + port*4, 0);
6345
6346 /* update shared memory */
6347 bnx2x_update_mng(params, vars->link_status);
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00006348 msleep(20);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006349 return rc;
6350}
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006351/* This function should called upon link interrupt */
6352/* In case vars->link_up, driver needs to
6353 1. Update the pbf
6354 2. Disable drain
6355 3. Update the shared memory
6356 4. Indicate link up
6357 5. Set LEDs
6358 Otherwise,
6359 1. Update shared memory
6360 2. Reset BigMac
6361 3. Report link down
6362 4. Unset LEDs
6363*/
6364u8 bnx2x_link_update(struct link_params *params, struct link_vars *vars)
6365{
6366 struct bnx2x *bp = params->bp;
6367 u8 port = params->port;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006368 u16 gp_status;
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006369 u8 link_10g;
6370 u8 ext_phy_link_up, rc = 0;
6371 u32 ext_phy_type;
Eilon Greenstein2f904462009-08-12 08:22:16 +00006372 u8 is_mi_int = 0;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006373
6374 DP(NETIF_MSG_LINK, "port %x, XGXS?%x, int_status 0x%x\n",
Eilon Greenstein2f904462009-08-12 08:22:16 +00006375 port, (vars->phy_flags & PHY_XGXS_FLAG),
6376 REG_RD(bp, NIG_REG_STATUS_INTERRUPT_PORT0 + port*4));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006377
Eilon Greenstein2f904462009-08-12 08:22:16 +00006378 is_mi_int = (u8)(REG_RD(bp, NIG_REG_EMAC0_STATUS_MISC_MI_INT +
6379 port*0x18) > 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006380 DP(NETIF_MSG_LINK, "int_mask 0x%x MI_INT %x, SERDES_LINK %x\n",
Eilon Greenstein2f904462009-08-12 08:22:16 +00006381 REG_RD(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4),
6382 is_mi_int,
6383 REG_RD(bp,
6384 NIG_REG_SERDES0_STATUS_LINK_STATUS + port*0x3c));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006385
6386 DP(NETIF_MSG_LINK, " 10G %x, XGXS_LINK %x\n",
6387 REG_RD(bp, NIG_REG_XGXS0_STATUS_LINK10G + port*0x68),
6388 REG_RD(bp, NIG_REG_XGXS0_STATUS_LINK_STATUS + port*0x68));
6389
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00006390 /* disable emac */
6391 REG_WR(bp, NIG_REG_NIG_EMAC0_EN + port*4, 0);
6392
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006393 ext_phy_type = XGXS_EXT_PHY_TYPE(params->ext_phy_config);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006394
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006395 /* Check external link change only for non-direct */
Eilon Greenstein2f904462009-08-12 08:22:16 +00006396 ext_phy_link_up = bnx2x_ext_phy_is_link_up(params, vars, is_mi_int);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006397
6398 /* Read gp_status */
6399 CL45_RD_OVER_CL22(bp, port, params->phy_addr,
6400 MDIO_REG_BANK_GP_STATUS,
6401 MDIO_GP_STATUS_TOP_AN_STATUS1,
6402 &gp_status);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006403
Eilon Greenstein2f904462009-08-12 08:22:16 +00006404 rc = bnx2x_link_settings_status(params, vars, gp_status,
6405 ext_phy_link_up);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006406 if (rc != 0)
6407 return rc;
6408
6409 /* anything 10 and over uses the bmac */
6410 link_10g = ((vars->line_speed == SPEED_10000) ||
6411 (vars->line_speed == SPEED_12000) ||
6412 (vars->line_speed == SPEED_12500) ||
6413 (vars->line_speed == SPEED_13000) ||
6414 (vars->line_speed == SPEED_15000) ||
6415 (vars->line_speed == SPEED_16000));
6416
Eilon Greenstein2f904462009-08-12 08:22:16 +00006417 bnx2x_link_int_ack(params, vars, link_10g, is_mi_int);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006418
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006419 /* In case external phy link is up, and internal link is down
6420 ( not initialized yet probably after link initialization, it needs
6421 to be initialized.
6422 Note that after link down-up as result of cable plug,
6423 the xgxs link would probably become up again without the need to
6424 initialize it*/
6425
6426 if ((ext_phy_type != PORT_HW_CFG_SERDES_EXT_PHY_TYPE_DIRECT) &&
6427 (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705) &&
Yaniv Rosnerb5bbf002009-11-05 19:18:21 +02006428 (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706) &&
Eilon Greenstein589abe32009-02-12 08:36:55 +00006429 (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726) &&
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006430 (ext_phy_link_up && !vars->phy_link_up))
Eilon Greenstein239d6862009-08-12 08:23:04 +00006431 bnx2x_init_internal_phy(params, vars, 0);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006432
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006433 /* link is up only if both local phy and external phy are up */
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006434 vars->link_up = (ext_phy_link_up && vars->phy_link_up);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006435
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006436 if (vars->link_up)
6437 rc = bnx2x_update_link_up(params, vars, link_10g, gp_status);
6438 else
6439 rc = bnx2x_update_link_down(params, vars);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006440
6441 return rc;
6442}
6443
Yaniv Rosner6bbca912008-08-13 15:57:28 -07006444static u8 bnx2x_8073_common_init_phy(struct bnx2x *bp, u32 shmem_base)
6445{
6446 u8 ext_phy_addr[PORT_MAX];
6447 u16 val;
6448 s8 port;
6449
6450 /* PART1 - Reset both phys */
6451 for (port = PORT_MAX - 1; port >= PORT_0; port--) {
6452 /* Extract the ext phy address for the port */
6453 u32 ext_phy_config = REG_RD(bp, shmem_base +
6454 offsetof(struct shmem_region,
6455 dev_info.port_hw_config[port].external_phy_config));
6456
6457 /* disable attentions */
6458 bnx2x_bits_dis(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4,
6459 (NIG_MASK_XGXS0_LINK_STATUS |
6460 NIG_MASK_XGXS0_LINK10G |
6461 NIG_MASK_SERDES0_LINK_STATUS |
6462 NIG_MASK_MI_INT));
6463
Eilon Greenstein659bc5c2009-08-12 08:24:02 +00006464 ext_phy_addr[port] = XGXS_EXT_PHY_ADDR(ext_phy_config);
Yaniv Rosner6bbca912008-08-13 15:57:28 -07006465
6466 /* Need to take the phy out of low power mode in order
6467 to write to access its registers */
6468 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
6469 MISC_REGISTERS_GPIO_OUTPUT_HIGH, port);
6470
6471 /* Reset the phy */
6472 bnx2x_cl45_write(bp, port,
6473 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073,
6474 ext_phy_addr[port],
6475 MDIO_PMA_DEVAD,
6476 MDIO_PMA_REG_CTRL,
6477 1<<15);
6478 }
6479
6480 /* Add delay of 150ms after reset */
6481 msleep(150);
6482
6483 /* PART2 - Download firmware to both phys */
6484 for (port = PORT_MAX - 1; port >= PORT_0; port--) {
6485 u16 fw_ver1;
6486
6487 bnx2x_bcm8073_external_rom_boot(bp, port,
Eilon Greensteina35da8d2009-02-12 08:37:02 +00006488 ext_phy_addr[port], shmem_base);
Yaniv Rosner6bbca912008-08-13 15:57:28 -07006489
6490 bnx2x_cl45_read(bp, port, PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073,
6491 ext_phy_addr[port],
6492 MDIO_PMA_DEVAD,
6493 MDIO_PMA_REG_ROM_VER1, &fw_ver1);
Eilon Greenstein16b311c2009-01-14 06:44:24 +00006494 if (fw_ver1 == 0 || fw_ver1 == 0x4321) {
Yaniv Rosner6bbca912008-08-13 15:57:28 -07006495 DP(NETIF_MSG_LINK,
Eilon Greenstein16b311c2009-01-14 06:44:24 +00006496 "bnx2x_8073_common_init_phy port %x:"
6497 "Download failed. fw version = 0x%x\n",
6498 port, fw_ver1);
Yaniv Rosner6bbca912008-08-13 15:57:28 -07006499 return -EINVAL;
6500 }
6501
6502 /* Only set bit 10 = 1 (Tx power down) */
6503 bnx2x_cl45_read(bp, port,
6504 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073,
6505 ext_phy_addr[port],
6506 MDIO_PMA_DEVAD,
6507 MDIO_PMA_REG_TX_POWER_DOWN, &val);
6508
6509 /* Phase1 of TX_POWER_DOWN reset */
6510 bnx2x_cl45_write(bp, port,
6511 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073,
6512 ext_phy_addr[port],
6513 MDIO_PMA_DEVAD,
6514 MDIO_PMA_REG_TX_POWER_DOWN,
6515 (val | 1<<10));
6516 }
6517
6518 /* Toggle Transmitter: Power down and then up with 600ms
6519 delay between */
6520 msleep(600);
6521
6522 /* PART3 - complete TX_POWER_DOWN process, and set GPIO2 back to low */
6523 for (port = PORT_MAX - 1; port >= PORT_0; port--) {
Eilon Greensteinf5372252009-02-12 08:38:30 +00006524 /* Phase2 of POWER_DOWN_RESET */
Yaniv Rosner6bbca912008-08-13 15:57:28 -07006525 /* Release bit 10 (Release Tx power down) */
6526 bnx2x_cl45_read(bp, port,
6527 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073,
6528 ext_phy_addr[port],
6529 MDIO_PMA_DEVAD,
6530 MDIO_PMA_REG_TX_POWER_DOWN, &val);
6531
6532 bnx2x_cl45_write(bp, port,
6533 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073,
6534 ext_phy_addr[port],
6535 MDIO_PMA_DEVAD,
6536 MDIO_PMA_REG_TX_POWER_DOWN, (val & (~(1<<10))));
6537 msleep(15);
6538
6539 /* Read modify write the SPI-ROM version select register */
6540 bnx2x_cl45_read(bp, port,
6541 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073,
6542 ext_phy_addr[port],
6543 MDIO_PMA_DEVAD,
6544 MDIO_PMA_REG_EDC_FFE_MAIN, &val);
6545 bnx2x_cl45_write(bp, port,
6546 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073,
6547 ext_phy_addr[port],
6548 MDIO_PMA_DEVAD,
6549 MDIO_PMA_REG_EDC_FFE_MAIN, (val | (1<<12)));
6550
6551 /* set GPIO2 back to LOW */
6552 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
6553 MISC_REGISTERS_GPIO_OUTPUT_LOW, port);
6554 }
6555 return 0;
6556
6557}
6558
Eilon Greenstein4d295db2009-07-21 05:47:47 +00006559static u8 bnx2x_8727_common_init_phy(struct bnx2x *bp, u32 shmem_base)
6560{
6561 u8 ext_phy_addr[PORT_MAX];
Eilon Greensteinbc7f0a02009-08-12 08:23:01 +00006562 s8 port, first_port, i;
Eilon Greenstein4d295db2009-07-21 05:47:47 +00006563 u32 swap_val, swap_override;
6564 DP(NETIF_MSG_LINK, "Executing BCM8727 common init\n");
6565 swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
6566 swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
6567
Eilon Greensteinf57a6022009-08-12 08:23:11 +00006568 bnx2x_ext_phy_hw_reset(bp, 1 ^ (swap_val && swap_override));
Eilon Greenstein4d295db2009-07-21 05:47:47 +00006569 msleep(5);
6570
Eilon Greensteinbc7f0a02009-08-12 08:23:01 +00006571 if (swap_val && swap_override)
6572 first_port = PORT_0;
6573 else
6574 first_port = PORT_1;
6575
Eilon Greenstein4d295db2009-07-21 05:47:47 +00006576 /* PART1 - Reset both phys */
Eilon Greensteinbc7f0a02009-08-12 08:23:01 +00006577 for (i = 0, port = first_port; i < PORT_MAX; i++, port = !port) {
Eilon Greenstein4d295db2009-07-21 05:47:47 +00006578 /* Extract the ext phy address for the port */
6579 u32 ext_phy_config = REG_RD(bp, shmem_base +
6580 offsetof(struct shmem_region,
6581 dev_info.port_hw_config[port].external_phy_config));
6582
6583 /* disable attentions */
6584 bnx2x_bits_dis(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4,
6585 (NIG_MASK_XGXS0_LINK_STATUS |
6586 NIG_MASK_XGXS0_LINK10G |
6587 NIG_MASK_SERDES0_LINK_STATUS |
6588 NIG_MASK_MI_INT));
6589
Eilon Greenstein659bc5c2009-08-12 08:24:02 +00006590 ext_phy_addr[port] = XGXS_EXT_PHY_ADDR(ext_phy_config);
Eilon Greenstein4d295db2009-07-21 05:47:47 +00006591
6592 /* Reset the phy */
6593 bnx2x_cl45_write(bp, port,
6594 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727,
6595 ext_phy_addr[port],
6596 MDIO_PMA_DEVAD,
6597 MDIO_PMA_REG_CTRL,
6598 1<<15);
6599 }
6600
6601 /* Add delay of 150ms after reset */
6602 msleep(150);
6603
6604 /* PART2 - Download firmware to both phys */
Eilon Greensteinbc7f0a02009-08-12 08:23:01 +00006605 for (i = 0, port = first_port; i < PORT_MAX; i++, port = !port) {
Eilon Greenstein4d295db2009-07-21 05:47:47 +00006606 u16 fw_ver1;
6607
6608 bnx2x_bcm8727_external_rom_boot(bp, port,
6609 ext_phy_addr[port], shmem_base);
6610
6611 bnx2x_cl45_read(bp, port, PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727,
6612 ext_phy_addr[port],
6613 MDIO_PMA_DEVAD,
6614 MDIO_PMA_REG_ROM_VER1, &fw_ver1);
6615 if (fw_ver1 == 0 || fw_ver1 == 0x4321) {
6616 DP(NETIF_MSG_LINK,
Eilon Greensteinbc7f0a02009-08-12 08:23:01 +00006617 "bnx2x_8727_common_init_phy port %x:"
Eilon Greenstein4d295db2009-07-21 05:47:47 +00006618 "Download failed. fw version = 0x%x\n",
6619 port, fw_ver1);
6620 return -EINVAL;
6621 }
Eilon Greenstein4d295db2009-07-21 05:47:47 +00006622 }
6623
Eilon Greenstein4d295db2009-07-21 05:47:47 +00006624 return 0;
6625}
6626
Eilon Greenstein589abe32009-02-12 08:36:55 +00006627
6628static u8 bnx2x_8726_common_init_phy(struct bnx2x *bp, u32 shmem_base)
6629{
6630 u8 ext_phy_addr;
6631 u32 val;
6632 s8 port;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00006633
Eilon Greenstein589abe32009-02-12 08:36:55 +00006634 /* Use port1 because of the static port-swap */
6635 /* Enable the module detection interrupt */
6636 val = REG_RD(bp, MISC_REG_GPIO_EVENT_EN);
6637 val |= ((1<<MISC_REGISTERS_GPIO_3)|
6638 (1<<(MISC_REGISTERS_GPIO_3 + MISC_REGISTERS_GPIO_PORT_SHIFT)));
6639 REG_WR(bp, MISC_REG_GPIO_EVENT_EN, val);
6640
Eilon Greensteinf57a6022009-08-12 08:23:11 +00006641 bnx2x_ext_phy_hw_reset(bp, 1);
Eilon Greenstein589abe32009-02-12 08:36:55 +00006642 msleep(5);
6643 for (port = 0; port < PORT_MAX; port++) {
6644 /* Extract the ext phy address for the port */
6645 u32 ext_phy_config = REG_RD(bp, shmem_base +
6646 offsetof(struct shmem_region,
6647 dev_info.port_hw_config[port].external_phy_config));
6648
Eilon Greenstein659bc5c2009-08-12 08:24:02 +00006649 ext_phy_addr = XGXS_EXT_PHY_ADDR(ext_phy_config);
Eilon Greenstein589abe32009-02-12 08:36:55 +00006650 DP(NETIF_MSG_LINK, "8726_common_init : ext_phy_addr = 0x%x\n",
6651 ext_phy_addr);
6652
6653 bnx2x_8726_reset_phy(bp, port, ext_phy_addr);
6654
6655 /* Set fault module detected LED on */
6656 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_0,
6657 MISC_REGISTERS_GPIO_HIGH,
6658 port);
6659 }
6660
6661 return 0;
6662}
6663
Yaniv Rosner6bbca912008-08-13 15:57:28 -07006664u8 bnx2x_common_init_phy(struct bnx2x *bp, u32 shmem_base)
6665{
6666 u8 rc = 0;
6667 u32 ext_phy_type;
6668
Eilon Greensteinf5372252009-02-12 08:38:30 +00006669 DP(NETIF_MSG_LINK, "Begin common phy init\n");
Yaniv Rosner6bbca912008-08-13 15:57:28 -07006670
6671 /* Read the ext_phy_type for arbitrary port(0) */
6672 ext_phy_type = XGXS_EXT_PHY_TYPE(
6673 REG_RD(bp, shmem_base +
6674 offsetof(struct shmem_region,
6675 dev_info.port_hw_config[0].external_phy_config)));
6676
6677 switch (ext_phy_type) {
6678 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073:
6679 {
6680 rc = bnx2x_8073_common_init_phy(bp, shmem_base);
6681 break;
6682 }
Eilon Greenstein4d295db2009-07-21 05:47:47 +00006683
6684 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
6685 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727_NOC:
6686 rc = bnx2x_8727_common_init_phy(bp, shmem_base);
6687 break;
6688
Eilon Greenstein589abe32009-02-12 08:36:55 +00006689 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
6690 /* GPIO1 affects both ports, so there's need to pull
6691 it for single port alone */
6692 rc = bnx2x_8726_common_init_phy(bp, shmem_base);
6693
6694 break;
Yaniv Rosner6bbca912008-08-13 15:57:28 -07006695 default:
6696 DP(NETIF_MSG_LINK,
6697 "bnx2x_common_init_phy: ext_phy 0x%x not required\n",
6698 ext_phy_type);
6699 break;
6700 }
6701
6702 return rc;
6703}
6704
Eilon Greensteinf57a6022009-08-12 08:23:11 +00006705void bnx2x_sfx7101_sp_sw_reset(struct bnx2x *bp, u8 port, u8 phy_addr)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006706{
6707 u16 val, cnt;
6708
6709 bnx2x_cl45_read(bp, port,
6710 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101,
6711 phy_addr,
6712 MDIO_PMA_DEVAD,
6713 MDIO_PMA_REG_7101_RESET, &val);
6714
6715 for (cnt = 0; cnt < 10; cnt++) {
6716 msleep(50);
6717 /* Writes a self-clearing reset */
6718 bnx2x_cl45_write(bp, port,
6719 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101,
6720 phy_addr,
6721 MDIO_PMA_DEVAD,
6722 MDIO_PMA_REG_7101_RESET,
6723 (val | (1<<15)));
6724 /* Wait for clear */
6725 bnx2x_cl45_read(bp, port,
6726 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101,
6727 phy_addr,
6728 MDIO_PMA_DEVAD,
6729 MDIO_PMA_REG_7101_RESET, &val);
6730
6731 if ((val & (1<<15)) == 0)
6732 break;
6733 }
6734}