blob: 1663e0b6b5a01f0baee17e6584dc6b65cf07344c [file] [log] [blame]
Yuval Mintz247fa822013-01-14 05:11:50 +00001/* Copyright 2008-2013 Broadcom Corporation
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002 *
3 * Unless you and Broadcom execute a separate written software license
4 * agreement governing use of this software, this software is licensed to you
5 * under the terms of the GNU General Public License version 2, available
6 * at http://www.gnu.org/licenses/old-licenses/gpl-2.0.html (the "GPL").
7 *
8 * Notwithstanding the above, under no circumstances may you combine this
9 * software in any way with any other Broadcom software provided under a
10 * license other than the GPL, without Broadcom's express prior written
11 * consent.
12 *
13 * Written by Yaniv Rosner
14 *
15 */
16
Joe Perches7995c642010-02-17 15:01:52 +000017#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
18
Yaniv Rosnerea4e0402008-06-23 20:27:26 -070019#include <linux/kernel.h>
20#include <linux/errno.h>
21#include <linux/pci.h>
22#include <linux/netdevice.h>
23#include <linux/delay.h>
24#include <linux/ethtool.h>
25#include <linux/mutex.h>
Yaniv Rosnerea4e0402008-06-23 20:27:26 -070026
Yaniv Rosnerea4e0402008-06-23 20:27:26 -070027#include "bnx2x.h"
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030028#include "bnx2x_cmn.h"
29
Yaniv Rosnerea4e0402008-06-23 20:27:26 -070030/********************************************************/
Eilon Greenstein3196a882008-08-13 15:58:49 -070031#define ETH_HLEN 14
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000032/* L2 header size + 2*VLANs (8 bytes) + LLC SNAP (8 bytes) */
33#define ETH_OVREHEAD (ETH_HLEN + 8 + 8)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -070034#define ETH_MIN_PACKET_SIZE 60
35#define ETH_MAX_PACKET_SIZE 1500
36#define ETH_MAX_JUMBO_PACKET_SIZE 9600
37#define MDIO_ACCESS_TIMEOUT 1000
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000038#define WC_LANE_MAX 4
39#define I2C_SWITCH_WIDTH 2
40#define I2C_BSC0 0
41#define I2C_BSC1 1
42#define I2C_WA_RETRY_CNT 3
Yuval Mintz50a29842012-06-16 20:27:14 +000043#define I2C_WA_PWR_ITER (I2C_WA_RETRY_CNT - 1)
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000044#define MCPR_IMC_COMMAND_READ_OP 1
45#define MCPR_IMC_COMMAND_WRITE_OP 2
Yaniv Rosnerea4e0402008-06-23 20:27:26 -070046
Yaniv Rosner26ffaf32011-10-27 05:09:45 +000047/* LED Blink rate that will achieve ~15.9Hz */
48#define LED_BLINK_RATE_VAL_E3 354
49#define LED_BLINK_RATE_VAL_E1X_E2 480
Yaniv Rosnerea4e0402008-06-23 20:27:26 -070050/***********************************************************/
Eilon Greenstein3196a882008-08-13 15:58:49 -070051/* Shortcut definitions */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -070052/***********************************************************/
53
Eilon Greenstein2f904462009-08-12 08:22:16 +000054#define NIG_LATCH_BC_ENABLE_MI_INT 0
55
56#define NIG_STATUS_EMAC0_MI_INT \
57 NIG_STATUS_INTERRUPT_PORT0_REG_STATUS_EMAC0_MISC_MI_INT
Yaniv Rosnerea4e0402008-06-23 20:27:26 -070058#define NIG_STATUS_XGXS0_LINK10G \
59 NIG_STATUS_INTERRUPT_PORT0_REG_STATUS_XGXS0_LINK10G
60#define NIG_STATUS_XGXS0_LINK_STATUS \
61 NIG_STATUS_INTERRUPT_PORT0_REG_STATUS_XGXS0_LINK_STATUS
62#define NIG_STATUS_XGXS0_LINK_STATUS_SIZE \
63 NIG_STATUS_INTERRUPT_PORT0_REG_STATUS_XGXS0_LINK_STATUS_SIZE
64#define NIG_STATUS_SERDES0_LINK_STATUS \
65 NIG_STATUS_INTERRUPT_PORT0_REG_STATUS_SERDES0_LINK_STATUS
66#define NIG_MASK_MI_INT \
67 NIG_MASK_INTERRUPT_PORT0_REG_MASK_EMAC0_MISC_MI_INT
68#define NIG_MASK_XGXS0_LINK10G \
69 NIG_MASK_INTERRUPT_PORT0_REG_MASK_XGXS0_LINK10G
70#define NIG_MASK_XGXS0_LINK_STATUS \
71 NIG_MASK_INTERRUPT_PORT0_REG_MASK_XGXS0_LINK_STATUS
72#define NIG_MASK_SERDES0_LINK_STATUS \
73 NIG_MASK_INTERRUPT_PORT0_REG_MASK_SERDES0_LINK_STATUS
74
75#define MDIO_AN_CL73_OR_37_COMPLETE \
76 (MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_AUTONEG_COMPLETE | \
77 MDIO_GP_STATUS_TOP_AN_STATUS1_CL37_AUTONEG_COMPLETE)
78
79#define XGXS_RESET_BITS \
80 (MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_XGXS0_RSTB_HW | \
81 MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_XGXS0_IDDQ | \
82 MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_XGXS0_PWRDWN | \
83 MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_XGXS0_PWRDWN_SD | \
84 MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_XGXS0_TXD_FIFO_RSTB)
85
86#define SERDES_RESET_BITS \
87 (MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_SERDES0_RSTB_HW | \
88 MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_SERDES0_IDDQ | \
89 MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_SERDES0_PWRDWN | \
90 MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_SERDES0_PWRDWN_SD)
91
92#define AUTONEG_CL37 SHARED_HW_CFG_AN_ENABLE_CL37
93#define AUTONEG_CL73 SHARED_HW_CFG_AN_ENABLE_CL73
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000094#define AUTONEG_BAM SHARED_HW_CFG_AN_ENABLE_BAM
Eilon Greenstein3196a882008-08-13 15:58:49 -070095#define AUTONEG_PARALLEL \
Yaniv Rosnerea4e0402008-06-23 20:27:26 -070096 SHARED_HW_CFG_AN_ENABLE_PARALLEL_DETECTION
Eilon Greenstein3196a882008-08-13 15:58:49 -070097#define AUTONEG_SGMII_FIBER_AUTODET \
Yaniv Rosnerea4e0402008-06-23 20:27:26 -070098 SHARED_HW_CFG_AN_EN_SGMII_FIBER_AUTO_DETECT
Eilon Greenstein3196a882008-08-13 15:58:49 -070099#define AUTONEG_REMOTE_PHY SHARED_HW_CFG_AN_ENABLE_REMOTE_PHY
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700100
101#define GP_STATUS_PAUSE_RSOLUTION_TXSIDE \
102 MDIO_GP_STATUS_TOP_AN_STATUS1_PAUSE_RSOLUTION_TXSIDE
103#define GP_STATUS_PAUSE_RSOLUTION_RXSIDE \
104 MDIO_GP_STATUS_TOP_AN_STATUS1_PAUSE_RSOLUTION_RXSIDE
105#define GP_STATUS_SPEED_MASK \
106 MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_MASK
107#define GP_STATUS_10M MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10M
108#define GP_STATUS_100M MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_100M
109#define GP_STATUS_1G MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_1G
110#define GP_STATUS_2_5G MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_2_5G
111#define GP_STATUS_5G MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_5G
112#define GP_STATUS_6G MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_6G
113#define GP_STATUS_10G_HIG \
114 MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10G_HIG
115#define GP_STATUS_10G_CX4 \
116 MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10G_CX4
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700117#define GP_STATUS_1G_KX MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_1G_KX
118#define GP_STATUS_10G_KX4 \
119 MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10G_KX4
Yaniv Rosner3c9ada22011-06-14 01:34:12 +0000120#define GP_STATUS_10G_KR MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10G_KR
121#define GP_STATUS_10G_XFI MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10G_XFI
122#define GP_STATUS_20G_DXGXS MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_20G_DXGXS
123#define GP_STATUS_10G_SFI MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10G_SFI
Yaniv Rosner4e7b4992012-11-27 03:46:29 +0000124#define GP_STATUS_20G_KR2 MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_20G_KR2
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000125#define LINK_10THD LINK_STATUS_SPEED_AND_DUPLEX_10THD
126#define LINK_10TFD LINK_STATUS_SPEED_AND_DUPLEX_10TFD
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700127#define LINK_100TXHD LINK_STATUS_SPEED_AND_DUPLEX_100TXHD
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000128#define LINK_100T4 LINK_STATUS_SPEED_AND_DUPLEX_100T4
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700129#define LINK_100TXFD LINK_STATUS_SPEED_AND_DUPLEX_100TXFD
130#define LINK_1000THD LINK_STATUS_SPEED_AND_DUPLEX_1000THD
131#define LINK_1000TFD LINK_STATUS_SPEED_AND_DUPLEX_1000TFD
132#define LINK_1000XFD LINK_STATUS_SPEED_AND_DUPLEX_1000XFD
133#define LINK_2500THD LINK_STATUS_SPEED_AND_DUPLEX_2500THD
134#define LINK_2500TFD LINK_STATUS_SPEED_AND_DUPLEX_2500TFD
135#define LINK_2500XFD LINK_STATUS_SPEED_AND_DUPLEX_2500XFD
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000136#define LINK_10GTFD LINK_STATUS_SPEED_AND_DUPLEX_10GTFD
137#define LINK_10GXFD LINK_STATUS_SPEED_AND_DUPLEX_10GXFD
Yaniv Rosner3c9ada22011-06-14 01:34:12 +0000138#define LINK_20GTFD LINK_STATUS_SPEED_AND_DUPLEX_20GTFD
139#define LINK_20GXFD LINK_STATUS_SPEED_AND_DUPLEX_20GXFD
Yaniv Rosner6583e332011-06-14 01:34:17 +0000140
Yaniv Rosner49781402012-10-31 05:46:55 +0000141#define LINK_UPDATE_MASK \
142 (LINK_STATUS_SPEED_AND_DUPLEX_MASK | \
143 LINK_STATUS_LINK_UP | \
144 LINK_STATUS_PHYSICAL_LINK_FLAG | \
145 LINK_STATUS_AUTO_NEGOTIATE_COMPLETE | \
146 LINK_STATUS_RX_FLOW_CONTROL_FLAG_MASK | \
147 LINK_STATUS_TX_FLOW_CONTROL_FLAG_MASK | \
148 LINK_STATUS_PARALLEL_DETECTION_FLAG_MASK | \
149 LINK_STATUS_LINK_PARTNER_SYMMETRIC_PAUSE | \
150 LINK_STATUS_LINK_PARTNER_ASYMMETRIC_PAUSE)
Yaniv Rosner6583e332011-06-14 01:34:17 +0000151
Eilon Greenstein589abe32009-02-12 08:36:55 +0000152#define SFP_EEPROM_CON_TYPE_ADDR 0x2
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000153 #define SFP_EEPROM_CON_TYPE_VAL_LC 0x7
Eilon Greenstein589abe32009-02-12 08:36:55 +0000154 #define SFP_EEPROM_CON_TYPE_VAL_COPPER 0x21
155
Eilon Greenstein4d295db2009-07-21 05:47:47 +0000156
157#define SFP_EEPROM_COMP_CODE_ADDR 0x3
158 #define SFP_EEPROM_COMP_CODE_SR_MASK (1<<4)
159 #define SFP_EEPROM_COMP_CODE_LR_MASK (1<<5)
160 #define SFP_EEPROM_COMP_CODE_LRM_MASK (1<<6)
161
Eilon Greenstein589abe32009-02-12 08:36:55 +0000162#define SFP_EEPROM_FC_TX_TECH_ADDR 0x8
163 #define SFP_EEPROM_FC_TX_TECH_BITMASK_COPPER_PASSIVE 0x4
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000164 #define SFP_EEPROM_FC_TX_TECH_BITMASK_COPPER_ACTIVE 0x8
Eilon Greenstein4d295db2009-07-21 05:47:47 +0000165
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000166#define SFP_EEPROM_OPTIONS_ADDR 0x40
Eilon Greenstein589abe32009-02-12 08:36:55 +0000167 #define SFP_EEPROM_OPTIONS_LINEAR_RX_OUT_MASK 0x1
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000168#define SFP_EEPROM_OPTIONS_SIZE 2
Eilon Greenstein589abe32009-02-12 08:36:55 +0000169
Yaniv Rosnercd88cce2011-01-31 04:21:34 +0000170#define EDC_MODE_LINEAR 0x0022
171#define EDC_MODE_LIMITING 0x0044
172#define EDC_MODE_PASSIVE_DAC 0x0055
Eilon Greenstein589abe32009-02-12 08:36:55 +0000173
Yaniv Rosner866ceda2011-11-28 00:49:45 +0000174/* ETS defines*/
Yaniv Rosner9380bb92011-06-14 01:34:07 +0000175#define DCBX_INVALID_COS (0xFF)
176
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000177#define ETS_BW_LIMIT_CREDIT_UPPER_BOUND (0x5000)
178#define ETS_BW_LIMIT_CREDIT_WEIGHT (0x5000)
Yaniv Rosner9380bb92011-06-14 01:34:07 +0000179#define ETS_E3B0_NIG_MIN_W_VAL_UP_TO_10GBPS (1360)
180#define ETS_E3B0_NIG_MIN_W_VAL_20GBPS (2720)
181#define ETS_E3B0_PBF_MIN_W_VAL (10000)
182
183#define MAX_PACKET_SIZE (9700)
Yaniv Rosnera9077bf2011-10-27 05:09:46 +0000184#define MAX_KR_LINK_RETRY 4
Yaniv Rosner9380bb92011-06-14 01:34:07 +0000185
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700186/**********************************************************/
187/* INTERFACE */
188/**********************************************************/
Yaniv Rosnere10bc842010-09-07 11:40:50 +0000189
Yaniv Rosnercd2be892011-01-31 04:21:45 +0000190#define CL22_WR_OVER_CL45(_bp, _phy, _bank, _addr, _val) \
Yaniv Rosnere10bc842010-09-07 11:40:50 +0000191 bnx2x_cl45_write(_bp, _phy, \
Yaniv Rosner7aa07112010-09-07 11:41:01 +0000192 (_phy)->def_md_devad, \
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700193 (_bank + (_addr & 0xf)), \
194 _val)
195
Yaniv Rosnercd2be892011-01-31 04:21:45 +0000196#define CL22_RD_OVER_CL45(_bp, _phy, _bank, _addr, _val) \
Yaniv Rosnere10bc842010-09-07 11:40:50 +0000197 bnx2x_cl45_read(_bp, _phy, \
Yaniv Rosner7aa07112010-09-07 11:41:01 +0000198 (_phy)->def_md_devad, \
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700199 (_bank + (_addr & 0xf)), \
200 _val)
201
Yaniv Rosnerea4e0402008-06-23 20:27:26 -0700202static u32 bnx2x_bits_en(struct bnx2x *bp, u32 reg, u32 bits)
203{
204 u32 val = REG_RD(bp, reg);
205
206 val |= bits;
207 REG_WR(bp, reg, val);
208 return val;
209}
210
211static u32 bnx2x_bits_dis(struct bnx2x *bp, u32 reg, u32 bits)
212{
213 u32 val = REG_RD(bp, reg);
214
215 val &= ~bits;
216 REG_WR(bp, reg, val);
217 return val;
218}
219
Yaniv Rosnerd3a8f132012-09-13 02:56:20 +0000220/*
221 * bnx2x_check_lfa - This function checks if link reinitialization is required,
222 * or link flap can be avoided.
223 *
224 * @params: link parameters
225 * Returns 0 if Link Flap Avoidance conditions are met otherwise, the failed
226 * condition code.
227 */
228static int bnx2x_check_lfa(struct link_params *params)
229{
230 u32 link_status, cfg_idx, lfa_mask, cfg_size;
231 u32 cur_speed_cap_mask, cur_req_fc_auto_adv, additional_config;
232 u32 saved_val, req_val, eee_status;
233 struct bnx2x *bp = params->bp;
234
235 additional_config =
236 REG_RD(bp, params->lfa_base +
237 offsetof(struct shmem_lfa, additional_config));
238
239 /* NOTE: must be first condition checked -
240 * to verify DCC bit is cleared in any case!
241 */
242 if (additional_config & NO_LFA_DUE_TO_DCC_MASK) {
243 DP(NETIF_MSG_LINK, "No LFA due to DCC flap after clp exit\n");
244 REG_WR(bp, params->lfa_base +
245 offsetof(struct shmem_lfa, additional_config),
246 additional_config & ~NO_LFA_DUE_TO_DCC_MASK);
247 return LFA_DCC_LFA_DISABLED;
248 }
249
250 /* Verify that link is up */
251 link_status = REG_RD(bp, params->shmem_base +
252 offsetof(struct shmem_region,
253 port_mb[params->port].link_status));
254 if (!(link_status & LINK_STATUS_LINK_UP))
255 return LFA_LINK_DOWN;
256
Barak Witkowskic63da992012-12-05 23:04:03 +0000257 /* if loaded after BOOT from SAN, don't flap the link in any case and
258 * rely on link set by preboot driver
259 */
260 if (params->feature_config_flags & FEATURE_CONFIG_BOOT_FROM_SAN)
261 return 0;
262
Yaniv Rosnerd3a8f132012-09-13 02:56:20 +0000263 /* Verify that loopback mode is not set */
264 if (params->loopback_mode)
265 return LFA_LOOPBACK_ENABLED;
266
267 /* Verify that MFW supports LFA */
268 if (!params->lfa_base)
269 return LFA_MFW_IS_TOO_OLD;
270
271 if (params->num_phys == 3) {
272 cfg_size = 2;
273 lfa_mask = 0xffffffff;
274 } else {
275 cfg_size = 1;
276 lfa_mask = 0xffff;
277 }
278
279 /* Compare Duplex */
280 saved_val = REG_RD(bp, params->lfa_base +
281 offsetof(struct shmem_lfa, req_duplex));
282 req_val = params->req_duplex[0] | (params->req_duplex[1] << 16);
283 if ((saved_val & lfa_mask) != (req_val & lfa_mask)) {
284 DP(NETIF_MSG_LINK, "Duplex mismatch %x vs. %x\n",
285 (saved_val & lfa_mask), (req_val & lfa_mask));
286 return LFA_DUPLEX_MISMATCH;
287 }
288 /* Compare Flow Control */
289 saved_val = REG_RD(bp, params->lfa_base +
290 offsetof(struct shmem_lfa, req_flow_ctrl));
291 req_val = params->req_flow_ctrl[0] | (params->req_flow_ctrl[1] << 16);
292 if ((saved_val & lfa_mask) != (req_val & lfa_mask)) {
293 DP(NETIF_MSG_LINK, "Flow control mismatch %x vs. %x\n",
294 (saved_val & lfa_mask), (req_val & lfa_mask));
295 return LFA_FLOW_CTRL_MISMATCH;
296 }
297 /* Compare Link Speed */
298 saved_val = REG_RD(bp, params->lfa_base +
299 offsetof(struct shmem_lfa, req_line_speed));
300 req_val = params->req_line_speed[0] | (params->req_line_speed[1] << 16);
301 if ((saved_val & lfa_mask) != (req_val & lfa_mask)) {
302 DP(NETIF_MSG_LINK, "Link speed mismatch %x vs. %x\n",
303 (saved_val & lfa_mask), (req_val & lfa_mask));
304 return LFA_LINK_SPEED_MISMATCH;
305 }
306
307 for (cfg_idx = 0; cfg_idx < cfg_size; cfg_idx++) {
308 cur_speed_cap_mask = REG_RD(bp, params->lfa_base +
309 offsetof(struct shmem_lfa,
310 speed_cap_mask[cfg_idx]));
311
312 if (cur_speed_cap_mask != params->speed_cap_mask[cfg_idx]) {
313 DP(NETIF_MSG_LINK, "Speed Cap mismatch %x vs. %x\n",
314 cur_speed_cap_mask,
315 params->speed_cap_mask[cfg_idx]);
316 return LFA_SPEED_CAP_MISMATCH;
317 }
318 }
319
320 cur_req_fc_auto_adv =
321 REG_RD(bp, params->lfa_base +
322 offsetof(struct shmem_lfa, additional_config)) &
323 REQ_FC_AUTO_ADV_MASK;
324
325 if ((u16)cur_req_fc_auto_adv != params->req_fc_auto_adv) {
326 DP(NETIF_MSG_LINK, "Flow Ctrl AN mismatch %x vs. %x\n",
327 cur_req_fc_auto_adv, params->req_fc_auto_adv);
328 return LFA_FLOW_CTRL_MISMATCH;
329 }
330
331 eee_status = REG_RD(bp, params->shmem2_base +
332 offsetof(struct shmem2_region,
333 eee_status[params->port]));
334
335 if (((eee_status & SHMEM_EEE_LPI_REQUESTED_BIT) ^
336 (params->eee_mode & EEE_MODE_ENABLE_LPI)) ||
337 ((eee_status & SHMEM_EEE_REQUESTED_BIT) ^
338 (params->eee_mode & EEE_MODE_ADV_LPI))) {
339 DP(NETIF_MSG_LINK, "EEE mismatch %x vs. %x\n", params->eee_mode,
340 eee_status);
341 return LFA_EEE_MISMATCH;
342 }
343
344 /* LFA conditions are met */
345 return 0;
346}
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000347/******************************************************************/
Yaniv Rosner3c9ada22011-06-14 01:34:12 +0000348/* EPIO/GPIO section */
349/******************************************************************/
Yaniv Rosner3deb8162011-06-14 01:34:33 +0000350static void bnx2x_get_epio(struct bnx2x *bp, u32 epio_pin, u32 *en)
351{
352 u32 epio_mask, gp_oenable;
353 *en = 0;
354 /* Sanity check */
355 if (epio_pin > 31) {
356 DP(NETIF_MSG_LINK, "Invalid EPIO pin %d to get\n", epio_pin);
357 return;
358 }
359
360 epio_mask = 1 << epio_pin;
361 /* Set this EPIO to output */
362 gp_oenable = REG_RD(bp, MCP_REG_MCPR_GP_OENABLE);
363 REG_WR(bp, MCP_REG_MCPR_GP_OENABLE, gp_oenable & ~epio_mask);
364
365 *en = (REG_RD(bp, MCP_REG_MCPR_GP_INPUTS) & epio_mask) >> epio_pin;
366}
Yaniv Rosner3c9ada22011-06-14 01:34:12 +0000367static void bnx2x_set_epio(struct bnx2x *bp, u32 epio_pin, u32 en)
368{
369 u32 epio_mask, gp_output, gp_oenable;
370
371 /* Sanity check */
372 if (epio_pin > 31) {
373 DP(NETIF_MSG_LINK, "Invalid EPIO pin %d to set\n", epio_pin);
374 return;
375 }
376 DP(NETIF_MSG_LINK, "Setting EPIO pin %d to %d\n", epio_pin, en);
377 epio_mask = 1 << epio_pin;
378 /* Set this EPIO to output */
379 gp_output = REG_RD(bp, MCP_REG_MCPR_GP_OUTPUTS);
380 if (en)
381 gp_output |= epio_mask;
382 else
383 gp_output &= ~epio_mask;
384
385 REG_WR(bp, MCP_REG_MCPR_GP_OUTPUTS, gp_output);
386
387 /* Set the value for this EPIO */
388 gp_oenable = REG_RD(bp, MCP_REG_MCPR_GP_OENABLE);
389 REG_WR(bp, MCP_REG_MCPR_GP_OENABLE, gp_oenable | epio_mask);
390}
391
392static void bnx2x_set_cfg_pin(struct bnx2x *bp, u32 pin_cfg, u32 val)
393{
394 if (pin_cfg == PIN_CFG_NA)
395 return;
396 if (pin_cfg >= PIN_CFG_EPIO0) {
397 bnx2x_set_epio(bp, pin_cfg - PIN_CFG_EPIO0, val);
398 } else {
399 u8 gpio_num = (pin_cfg - PIN_CFG_GPIO0_P0) & 0x3;
400 u8 gpio_port = (pin_cfg - PIN_CFG_GPIO0_P0) >> 2;
401 bnx2x_set_gpio(bp, gpio_num, (u8)val, gpio_port);
402 }
403}
404
Yaniv Rosner3deb8162011-06-14 01:34:33 +0000405static u32 bnx2x_get_cfg_pin(struct bnx2x *bp, u32 pin_cfg, u32 *val)
406{
407 if (pin_cfg == PIN_CFG_NA)
408 return -EINVAL;
409 if (pin_cfg >= PIN_CFG_EPIO0) {
410 bnx2x_get_epio(bp, pin_cfg - PIN_CFG_EPIO0, val);
411 } else {
412 u8 gpio_num = (pin_cfg - PIN_CFG_GPIO0_P0) & 0x3;
413 u8 gpio_port = (pin_cfg - PIN_CFG_GPIO0_P0) >> 2;
414 *val = bnx2x_get_gpio(bp, gpio_num, gpio_port);
415 }
416 return 0;
417
418}
Yaniv Rosner3c9ada22011-06-14 01:34:12 +0000419/******************************************************************/
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000420/* ETS section */
421/******************************************************************/
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000422static void bnx2x_ets_e2e3a0_disabled(struct link_params *params)
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000423{
424 /* ETS disabled configuration*/
425 struct bnx2x *bp = params->bp;
426
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000427 DP(NETIF_MSG_LINK, "ETS E2E3 disabled configuration\n");
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000428
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000429 /* mapping between entry priority to client number (0,1,2 -debug and
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000430 * management clients, 3 - COS0 client, 4 - COS client)(HIGHEST)
431 * 3bits client num.
432 * PRI4 | PRI3 | PRI2 | PRI1 | PRI0
433 * cos1-100 cos0-011 dbg1-010 dbg0-001 MCP-000
434 */
435
436 REG_WR(bp, NIG_REG_P0_TX_ARB_PRIORITY_CLIENT, 0x4688);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000437 /* Bitmap of 5bits length. Each bit specifies whether the entry behaves
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000438 * as strict. Bits 0,1,2 - debug and management entries, 3 -
439 * COS0 entry, 4 - COS1 entry.
440 * COS1 | COS0 | DEBUG1 | DEBUG0 | MGMT
441 * bit4 bit3 bit2 bit1 bit0
442 * MCP and debug are strict
443 */
444
445 REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_IS_STRICT, 0x7);
446 /* defines which entries (clients) are subjected to WFQ arbitration */
447 REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_IS_SUBJECT2WFQ, 0);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000448 /* For strict priority entries defines the number of consecutive
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +0000449 * slots for the highest priority.
450 */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000451 REG_WR(bp, NIG_REG_P0_TX_ARB_NUM_STRICT_ARB_SLOTS, 0x100);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000452 /* mapping between the CREDIT_WEIGHT registers and actual client
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000453 * numbers
454 */
455 REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_CREDIT_MAP, 0);
456 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_0, 0);
457 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_1, 0);
458
459 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_0, 0);
460 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_1, 0);
461 REG_WR(bp, PBF_REG_HIGH_PRIORITY_COS_NUM, 0);
462 /* ETS mode disable */
463 REG_WR(bp, PBF_REG_ETS_ENABLED, 0);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000464 /* If ETS mode is enabled (there is no strict priority) defines a WFQ
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000465 * weight for COS0/COS1.
466 */
467 REG_WR(bp, PBF_REG_COS0_WEIGHT, 0x2710);
468 REG_WR(bp, PBF_REG_COS1_WEIGHT, 0x2710);
469 /* Upper bound that COS0_WEIGHT can reach in the WFQ arbiter */
470 REG_WR(bp, PBF_REG_COS0_UPPER_BOUND, 0x989680);
471 REG_WR(bp, PBF_REG_COS1_UPPER_BOUND, 0x989680);
472 /* Defines the number of consecutive slots for the strict priority */
473 REG_WR(bp, PBF_REG_NUM_STRICT_ARB_SLOTS, 0);
474}
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000475/******************************************************************************
476* Description:
477* Getting min_w_val will be set according to line speed .
478*.
479******************************************************************************/
480static u32 bnx2x_ets_get_min_w_val_nig(const struct link_vars *vars)
481{
482 u32 min_w_val = 0;
483 /* Calculate min_w_val.*/
484 if (vars->link_up) {
Yaniv Rosnerde0396f2011-11-28 00:49:53 +0000485 if (vars->line_speed == SPEED_20000)
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000486 min_w_val = ETS_E3B0_NIG_MIN_W_VAL_20GBPS;
487 else
488 min_w_val = ETS_E3B0_NIG_MIN_W_VAL_UP_TO_10GBPS;
489 } else
490 min_w_val = ETS_E3B0_NIG_MIN_W_VAL_20GBPS;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000491 /* If the link isn't up (static configuration for example ) The
492 * link will be according to 20GBPS.
493 */
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000494 return min_w_val;
495}
496/******************************************************************************
497* Description:
498* Getting credit upper bound form min_w_val.
499*.
500******************************************************************************/
501static u32 bnx2x_ets_get_credit_upper_bound(const u32 min_w_val)
502{
503 const u32 credit_upper_bound = (u32)MAXVAL((150 * min_w_val),
504 MAX_PACKET_SIZE);
505 return credit_upper_bound;
506}
507/******************************************************************************
508* Description:
509* Set credit upper bound for NIG.
510*.
511******************************************************************************/
512static void bnx2x_ets_e3b0_set_credit_upper_bound_nig(
513 const struct link_params *params,
514 const u32 min_w_val)
515{
516 struct bnx2x *bp = params->bp;
517 const u8 port = params->port;
518 const u32 credit_upper_bound =
519 bnx2x_ets_get_credit_upper_bound(min_w_val);
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +0000520
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000521 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_UPPER_BOUND_0 :
522 NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_0, credit_upper_bound);
523 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_UPPER_BOUND_1 :
524 NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_1, credit_upper_bound);
525 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_UPPER_BOUND_2 :
526 NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_2, credit_upper_bound);
527 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_UPPER_BOUND_3 :
528 NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_3, credit_upper_bound);
529 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_UPPER_BOUND_4 :
530 NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_4, credit_upper_bound);
531 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_UPPER_BOUND_5 :
532 NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_5, credit_upper_bound);
533
Yaniv Rosnerde0396f2011-11-28 00:49:53 +0000534 if (!port) {
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000535 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_6,
536 credit_upper_bound);
537 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_7,
538 credit_upper_bound);
539 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_8,
540 credit_upper_bound);
541 }
542}
543/******************************************************************************
544* Description:
545* Will return the NIG ETS registers to init values.Except
546* credit_upper_bound.
547* That isn't used in this configuration (No WFQ is enabled) and will be
548* configured acording to spec
549*.
550******************************************************************************/
551static void bnx2x_ets_e3b0_nig_disabled(const struct link_params *params,
552 const struct link_vars *vars)
553{
554 struct bnx2x *bp = params->bp;
555 const u8 port = params->port;
556 const u32 min_w_val = bnx2x_ets_get_min_w_val_nig(vars);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000557 /* Mapping between entry priority to client number (0,1,2 -debug and
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000558 * management clients, 3 - COS0 client, 4 - COS1, ... 8 -
559 * COS5)(HIGHEST) 4bits client num.TODO_ETS - Should be done by
560 * reset value or init tool
561 */
562 if (port) {
563 REG_WR(bp, NIG_REG_P1_TX_ARB_PRIORITY_CLIENT2_LSB, 0x543210);
564 REG_WR(bp, NIG_REG_P1_TX_ARB_PRIORITY_CLIENT2_MSB, 0x0);
565 } else {
566 REG_WR(bp, NIG_REG_P0_TX_ARB_PRIORITY_CLIENT2_LSB, 0x76543210);
567 REG_WR(bp, NIG_REG_P0_TX_ARB_PRIORITY_CLIENT2_MSB, 0x8);
568 }
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000569 /* For strict priority entries defines the number of consecutive
570 * slots for the highest priority.
571 */
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000572 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_NUM_STRICT_ARB_SLOTS :
573 NIG_REG_P1_TX_ARB_NUM_STRICT_ARB_SLOTS, 0x100);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000574 /* Mapping between the CREDIT_WEIGHT registers and actual client
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000575 * numbers
576 */
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000577 if (port) {
578 /*Port 1 has 6 COS*/
579 REG_WR(bp, NIG_REG_P1_TX_ARB_CLIENT_CREDIT_MAP2_LSB, 0x210543);
580 REG_WR(bp, NIG_REG_P1_TX_ARB_CLIENT_CREDIT_MAP2_MSB, 0x0);
581 } else {
582 /*Port 0 has 9 COS*/
583 REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_CREDIT_MAP2_LSB,
584 0x43210876);
585 REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_CREDIT_MAP2_MSB, 0x5);
586 }
587
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000588 /* Bitmap of 5bits length. Each bit specifies whether the entry behaves
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000589 * as strict. Bits 0,1,2 - debug and management entries, 3 -
590 * COS0 entry, 4 - COS1 entry.
591 * COS1 | COS0 | DEBUG1 | DEBUG0 | MGMT
592 * bit4 bit3 bit2 bit1 bit0
593 * MCP and debug are strict
594 */
595 if (port)
596 REG_WR(bp, NIG_REG_P1_TX_ARB_CLIENT_IS_STRICT, 0x3f);
597 else
598 REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_IS_STRICT, 0x1ff);
599 /* defines which entries (clients) are subjected to WFQ arbitration */
600 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CLIENT_IS_SUBJECT2WFQ :
601 NIG_REG_P0_TX_ARB_CLIENT_IS_SUBJECT2WFQ, 0);
602
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000603 /* Please notice the register address are note continuous and a
604 * for here is note appropriate.In 2 port mode port0 only COS0-5
605 * can be used. DEBUG1,DEBUG1,MGMT are never used for WFQ* In 4
606 * port mode port1 only COS0-2 can be used. DEBUG1,DEBUG1,MGMT
607 * are never used for WFQ
608 */
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000609 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_WEIGHT_0 :
610 NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_0, 0x0);
611 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_WEIGHT_1 :
612 NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_1, 0x0);
613 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_WEIGHT_2 :
614 NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_2, 0x0);
615 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_WEIGHT_3 :
616 NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_3, 0x0);
617 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_WEIGHT_4 :
618 NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_4, 0x0);
619 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_WEIGHT_5 :
620 NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_5, 0x0);
Yaniv Rosnerde0396f2011-11-28 00:49:53 +0000621 if (!port) {
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000622 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_6, 0x0);
623 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_7, 0x0);
624 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_8, 0x0);
625 }
626
627 bnx2x_ets_e3b0_set_credit_upper_bound_nig(params, min_w_val);
628}
629/******************************************************************************
630* Description:
631* Set credit upper bound for PBF.
632*.
633******************************************************************************/
634static void bnx2x_ets_e3b0_set_credit_upper_bound_pbf(
635 const struct link_params *params,
636 const u32 min_w_val)
637{
638 struct bnx2x *bp = params->bp;
639 const u32 credit_upper_bound =
640 bnx2x_ets_get_credit_upper_bound(min_w_val);
641 const u8 port = params->port;
642 u32 base_upper_bound = 0;
643 u8 max_cos = 0;
644 u8 i = 0;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000645 /* In 2 port mode port0 has COS0-5 that can be used for WFQ.In 4
646 * port mode port1 has COS0-2 that can be used for WFQ.
647 */
Yaniv Rosnerde0396f2011-11-28 00:49:53 +0000648 if (!port) {
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000649 base_upper_bound = PBF_REG_COS0_UPPER_BOUND_P0;
650 max_cos = DCBX_E3B0_MAX_NUM_COS_PORT0;
651 } else {
652 base_upper_bound = PBF_REG_COS0_UPPER_BOUND_P1;
653 max_cos = DCBX_E3B0_MAX_NUM_COS_PORT1;
654 }
655
656 for (i = 0; i < max_cos; i++)
657 REG_WR(bp, base_upper_bound + (i << 2), credit_upper_bound);
658}
659
660/******************************************************************************
661* Description:
662* Will return the PBF ETS registers to init values.Except
663* credit_upper_bound.
664* That isn't used in this configuration (No WFQ is enabled) and will be
665* configured acording to spec
666*.
667******************************************************************************/
668static void bnx2x_ets_e3b0_pbf_disabled(const struct link_params *params)
669{
670 struct bnx2x *bp = params->bp;
671 const u8 port = params->port;
672 const u32 min_w_val_pbf = ETS_E3B0_PBF_MIN_W_VAL;
673 u8 i = 0;
674 u32 base_weight = 0;
675 u8 max_cos = 0;
676
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000677 /* Mapping between entry priority to client number 0 - COS0
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000678 * client, 2 - COS1, ... 5 - COS5)(HIGHEST) 4bits client num.
679 * TODO_ETS - Should be done by reset value or init tool
680 */
681 if (port)
682 /* 0x688 (|011|0 10|00 1|000) */
683 REG_WR(bp, PBF_REG_ETS_ARB_PRIORITY_CLIENT_P1 , 0x688);
684 else
685 /* (10 1|100 |011|0 10|00 1|000) */
686 REG_WR(bp, PBF_REG_ETS_ARB_PRIORITY_CLIENT_P0 , 0x2C688);
687
688 /* TODO_ETS - Should be done by reset value or init tool */
689 if (port)
690 /* 0x688 (|011|0 10|00 1|000)*/
691 REG_WR(bp, PBF_REG_ETS_ARB_CLIENT_CREDIT_MAP_P1, 0x688);
692 else
693 /* 0x2C688 (10 1|100 |011|0 10|00 1|000) */
694 REG_WR(bp, PBF_REG_ETS_ARB_CLIENT_CREDIT_MAP_P0, 0x2C688);
695
696 REG_WR(bp, (port) ? PBF_REG_ETS_ARB_NUM_STRICT_ARB_SLOTS_P1 :
697 PBF_REG_ETS_ARB_NUM_STRICT_ARB_SLOTS_P0 , 0x100);
698
699
700 REG_WR(bp, (port) ? PBF_REG_ETS_ARB_CLIENT_IS_STRICT_P1 :
701 PBF_REG_ETS_ARB_CLIENT_IS_STRICT_P0 , 0);
702
703 REG_WR(bp, (port) ? PBF_REG_ETS_ARB_CLIENT_IS_SUBJECT2WFQ_P1 :
704 PBF_REG_ETS_ARB_CLIENT_IS_SUBJECT2WFQ_P0 , 0);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000705 /* In 2 port mode port0 has COS0-5 that can be used for WFQ.
706 * In 4 port mode port1 has COS0-2 that can be used for WFQ.
707 */
Yaniv Rosnerde0396f2011-11-28 00:49:53 +0000708 if (!port) {
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000709 base_weight = PBF_REG_COS0_WEIGHT_P0;
710 max_cos = DCBX_E3B0_MAX_NUM_COS_PORT0;
711 } else {
712 base_weight = PBF_REG_COS0_WEIGHT_P1;
713 max_cos = DCBX_E3B0_MAX_NUM_COS_PORT1;
714 }
715
716 for (i = 0; i < max_cos; i++)
717 REG_WR(bp, base_weight + (0x4 * i), 0);
718
719 bnx2x_ets_e3b0_set_credit_upper_bound_pbf(params, min_w_val_pbf);
720}
721/******************************************************************************
722* Description:
723* E3B0 disable will return basicly the values to init values.
724*.
725******************************************************************************/
726static int bnx2x_ets_e3b0_disabled(const struct link_params *params,
727 const struct link_vars *vars)
728{
729 struct bnx2x *bp = params->bp;
730
731 if (!CHIP_IS_E3B0(bp)) {
Joe Perches94f05b02011-08-14 12:16:20 +0000732 DP(NETIF_MSG_LINK,
733 "bnx2x_ets_e3b0_disabled the chip isn't E3B0\n");
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000734 return -EINVAL;
735 }
736
737 bnx2x_ets_e3b0_nig_disabled(params, vars);
738
739 bnx2x_ets_e3b0_pbf_disabled(params);
740
741 return 0;
742}
743
744/******************************************************************************
745* Description:
746* Disable will return basicly the values to init values.
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000747*
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000748******************************************************************************/
749int bnx2x_ets_disabled(struct link_params *params,
750 struct link_vars *vars)
751{
752 struct bnx2x *bp = params->bp;
753 int bnx2x_status = 0;
754
755 if ((CHIP_IS_E2(bp)) || (CHIP_IS_E3A0(bp)))
756 bnx2x_ets_e2e3a0_disabled(params);
757 else if (CHIP_IS_E3B0(bp))
758 bnx2x_status = bnx2x_ets_e3b0_disabled(params, vars);
759 else {
760 DP(NETIF_MSG_LINK, "bnx2x_ets_disabled - chip not supported\n");
761 return -EINVAL;
762 }
763
764 return bnx2x_status;
765}
766
767/******************************************************************************
768* Description
769* Set the COS mappimg to SP and BW until this point all the COS are not
770* set as SP or BW.
771******************************************************************************/
772static int bnx2x_ets_e3b0_cli_map(const struct link_params *params,
773 const struct bnx2x_ets_params *ets_params,
774 const u8 cos_sp_bitmap,
775 const u8 cos_bw_bitmap)
776{
777 struct bnx2x *bp = params->bp;
778 const u8 port = params->port;
779 const u8 nig_cli_sp_bitmap = 0x7 | (cos_sp_bitmap << 3);
780 const u8 pbf_cli_sp_bitmap = cos_sp_bitmap;
781 const u8 nig_cli_subject2wfq_bitmap = cos_bw_bitmap << 3;
782 const u8 pbf_cli_subject2wfq_bitmap = cos_bw_bitmap;
783
784 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CLIENT_IS_STRICT :
785 NIG_REG_P0_TX_ARB_CLIENT_IS_STRICT, nig_cli_sp_bitmap);
786
787 REG_WR(bp, (port) ? PBF_REG_ETS_ARB_CLIENT_IS_STRICT_P1 :
788 PBF_REG_ETS_ARB_CLIENT_IS_STRICT_P0 , pbf_cli_sp_bitmap);
789
790 REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CLIENT_IS_SUBJECT2WFQ :
791 NIG_REG_P0_TX_ARB_CLIENT_IS_SUBJECT2WFQ,
792 nig_cli_subject2wfq_bitmap);
793
794 REG_WR(bp, (port) ? PBF_REG_ETS_ARB_CLIENT_IS_SUBJECT2WFQ_P1 :
795 PBF_REG_ETS_ARB_CLIENT_IS_SUBJECT2WFQ_P0,
796 pbf_cli_subject2wfq_bitmap);
797
798 return 0;
799}
800
801/******************************************************************************
802* Description:
803* This function is needed because NIG ARB_CREDIT_WEIGHT_X are
804* not continues and ARB_CREDIT_WEIGHT_0 + offset is suitable.
805******************************************************************************/
806static int bnx2x_ets_e3b0_set_cos_bw(struct bnx2x *bp,
807 const u8 cos_entry,
808 const u32 min_w_val_nig,
809 const u32 min_w_val_pbf,
810 const u16 total_bw,
811 const u8 bw,
812 const u8 port)
813{
814 u32 nig_reg_adress_crd_weight = 0;
815 u32 pbf_reg_adress_crd_weight = 0;
David S. Miller8decf862011-09-22 03:23:13 -0400816 /* Calculate and set BW for this COS - use 1 instead of 0 for BW */
817 const u32 cos_bw_nig = ((bw ? bw : 1) * min_w_val_nig) / total_bw;
818 const u32 cos_bw_pbf = ((bw ? bw : 1) * min_w_val_pbf) / total_bw;
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000819
820 switch (cos_entry) {
821 case 0:
822 nig_reg_adress_crd_weight =
823 (port) ? NIG_REG_P1_TX_ARB_CREDIT_WEIGHT_0 :
824 NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_0;
825 pbf_reg_adress_crd_weight = (port) ?
826 PBF_REG_COS0_WEIGHT_P1 : PBF_REG_COS0_WEIGHT_P0;
827 break;
828 case 1:
829 nig_reg_adress_crd_weight = (port) ?
830 NIG_REG_P1_TX_ARB_CREDIT_WEIGHT_1 :
831 NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_1;
832 pbf_reg_adress_crd_weight = (port) ?
833 PBF_REG_COS1_WEIGHT_P1 : PBF_REG_COS1_WEIGHT_P0;
834 break;
835 case 2:
836 nig_reg_adress_crd_weight = (port) ?
837 NIG_REG_P1_TX_ARB_CREDIT_WEIGHT_2 :
838 NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_2;
839
840 pbf_reg_adress_crd_weight = (port) ?
841 PBF_REG_COS2_WEIGHT_P1 : PBF_REG_COS2_WEIGHT_P0;
842 break;
843 case 3:
844 if (port)
845 return -EINVAL;
846 nig_reg_adress_crd_weight =
847 NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_3;
848 pbf_reg_adress_crd_weight =
849 PBF_REG_COS3_WEIGHT_P0;
850 break;
851 case 4:
852 if (port)
853 return -EINVAL;
854 nig_reg_adress_crd_weight =
855 NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_4;
856 pbf_reg_adress_crd_weight = PBF_REG_COS4_WEIGHT_P0;
857 break;
858 case 5:
859 if (port)
860 return -EINVAL;
861 nig_reg_adress_crd_weight =
862 NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_5;
863 pbf_reg_adress_crd_weight = PBF_REG_COS5_WEIGHT_P0;
864 break;
865 }
866
867 REG_WR(bp, nig_reg_adress_crd_weight, cos_bw_nig);
868
869 REG_WR(bp, pbf_reg_adress_crd_weight, cos_bw_pbf);
870
871 return 0;
872}
873/******************************************************************************
874* Description:
875* Calculate the total BW.A value of 0 isn't legal.
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000876*
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000877******************************************************************************/
878static int bnx2x_ets_e3b0_get_total_bw(
879 const struct link_params *params,
Yaniv Rosner870516e12011-11-28 00:49:46 +0000880 struct bnx2x_ets_params *ets_params,
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000881 u16 *total_bw)
882{
883 struct bnx2x *bp = params->bp;
884 u8 cos_idx = 0;
Yaniv Rosner870516e12011-11-28 00:49:46 +0000885 u8 is_bw_cos_exist = 0;
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000886
887 *total_bw = 0 ;
888 /* Calculate total BW requested */
889 for (cos_idx = 0; cos_idx < ets_params->num_of_cos; cos_idx++) {
Yaniv Rosnerde0396f2011-11-28 00:49:53 +0000890 if (ets_params->cos[cos_idx].state == bnx2x_cos_state_bw) {
Yaniv Rosner870516e12011-11-28 00:49:46 +0000891 is_bw_cos_exist = 1;
892 if (!ets_params->cos[cos_idx].params.bw_params.bw) {
893 DP(NETIF_MSG_LINK, "bnx2x_ets_E3B0_config BW"
894 "was set to 0\n");
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000895 /* This is to prevent a state when ramrods
Yaniv Rosner870516e12011-11-28 00:49:46 +0000896 * can't be sent
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000897 */
Yaniv Rosner870516e12011-11-28 00:49:46 +0000898 ets_params->cos[cos_idx].params.bw_params.bw
899 = 1;
900 }
David S. Miller8decf862011-09-22 03:23:13 -0400901 *total_bw +=
902 ets_params->cos[cos_idx].params.bw_params.bw;
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000903 }
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000904 }
905
David S. Miller8decf862011-09-22 03:23:13 -0400906 /* Check total BW is valid */
Yaniv Rosnerde0396f2011-11-28 00:49:53 +0000907 if ((is_bw_cos_exist == 1) && (*total_bw != 100)) {
908 if (*total_bw == 0) {
Joe Perches94f05b02011-08-14 12:16:20 +0000909 DP(NETIF_MSG_LINK,
Yaniv Rosner2f751a82011-11-28 00:49:52 +0000910 "bnx2x_ets_E3B0_config total BW shouldn't be 0\n");
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000911 return -EINVAL;
912 }
Joe Perches94f05b02011-08-14 12:16:20 +0000913 DP(NETIF_MSG_LINK,
Yaniv Rosner2f751a82011-11-28 00:49:52 +0000914 "bnx2x_ets_E3B0_config total BW should be 100\n");
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000915 /* We can handle a case whre the BW isn't 100 this can happen
Yaniv Rosner2f751a82011-11-28 00:49:52 +0000916 * if the TC are joined.
917 */
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000918 }
919 return 0;
920}
921
922/******************************************************************************
923* Description:
924* Invalidate all the sp_pri_to_cos.
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000925*
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000926******************************************************************************/
927static void bnx2x_ets_e3b0_sp_pri_to_cos_init(u8 *sp_pri_to_cos)
928{
929 u8 pri = 0;
930 for (pri = 0; pri < DCBX_MAX_NUM_COS; pri++)
931 sp_pri_to_cos[pri] = DCBX_INVALID_COS;
932}
933/******************************************************************************
934* Description:
935* Calculate and set the SP (ARB_PRIORITY_CLIENT) NIG and PBF registers
936* according to sp_pri_to_cos.
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000937*
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000938******************************************************************************/
939static int bnx2x_ets_e3b0_sp_pri_to_cos_set(const struct link_params *params,
940 u8 *sp_pri_to_cos, const u8 pri,
941 const u8 cos_entry)
942{
943 struct bnx2x *bp = params->bp;
944 const u8 port = params->port;
945 const u8 max_num_of_cos = (port) ? DCBX_E3B0_MAX_NUM_COS_PORT1 :
946 DCBX_E3B0_MAX_NUM_COS_PORT0;
947
Dan Carpenter7e5998a2012-04-17 20:53:42 +0000948 if (pri >= max_num_of_cos) {
949 DP(NETIF_MSG_LINK, "bnx2x_ets_e3b0_sp_pri_to_cos_set invalid "
950 "parameter Illegal strict priority\n");
951 return -EINVAL;
952 }
953
Yaniv Rosnerde0396f2011-11-28 00:49:53 +0000954 if (sp_pri_to_cos[pri] != DCBX_INVALID_COS) {
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000955 DP(NETIF_MSG_LINK, "bnx2x_ets_e3b0_sp_pri_to_cos_set invalid "
Joe Perches94f05b02011-08-14 12:16:20 +0000956 "parameter There can't be two COS's with "
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000957 "the same strict pri\n");
958 return -EINVAL;
959 }
960
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000961 sp_pri_to_cos[pri] = cos_entry;
962 return 0;
963
964}
965
966/******************************************************************************
967* Description:
968* Returns the correct value according to COS and priority in
969* the sp_pri_cli register.
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000970*
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000971******************************************************************************/
972static u64 bnx2x_e3b0_sp_get_pri_cli_reg(const u8 cos, const u8 cos_offset,
973 const u8 pri_set,
974 const u8 pri_offset,
975 const u8 entry_size)
976{
977 u64 pri_cli_nig = 0;
978 pri_cli_nig = ((u64)(cos + cos_offset)) << (entry_size *
979 (pri_set + pri_offset));
980
981 return pri_cli_nig;
982}
983/******************************************************************************
984* Description:
985* Returns the correct value according to COS and priority in the
986* sp_pri_cli register for NIG.
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +0000987*
Yaniv Rosner6c3218c2011-06-14 01:34:23 +0000988******************************************************************************/
989static u64 bnx2x_e3b0_sp_get_pri_cli_reg_nig(const u8 cos, const u8 pri_set)
990{
991 /* MCP Dbg0 and dbg1 are always with higher strict pri*/
992 const u8 nig_cos_offset = 3;
993 const u8 nig_pri_offset = 3;
994
995 return bnx2x_e3b0_sp_get_pri_cli_reg(cos, nig_cos_offset, pri_set,
996 nig_pri_offset, 4);
997
998}
999/******************************************************************************
1000* Description:
1001* Returns the correct value according to COS and priority in the
1002* sp_pri_cli register for PBF.
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001003*
Yaniv Rosner6c3218c2011-06-14 01:34:23 +00001004******************************************************************************/
1005static u64 bnx2x_e3b0_sp_get_pri_cli_reg_pbf(const u8 cos, const u8 pri_set)
1006{
1007 const u8 pbf_cos_offset = 0;
1008 const u8 pbf_pri_offset = 0;
1009
1010 return bnx2x_e3b0_sp_get_pri_cli_reg(cos, pbf_cos_offset, pri_set,
1011 pbf_pri_offset, 3);
1012
1013}
1014
1015/******************************************************************************
1016* Description:
1017* Calculate and set the SP (ARB_PRIORITY_CLIENT) NIG and PBF registers
1018* according to sp_pri_to_cos.(which COS has higher priority)
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001019*
Yaniv Rosner6c3218c2011-06-14 01:34:23 +00001020******************************************************************************/
1021static int bnx2x_ets_e3b0_sp_set_pri_cli_reg(const struct link_params *params,
1022 u8 *sp_pri_to_cos)
1023{
1024 struct bnx2x *bp = params->bp;
1025 u8 i = 0;
1026 const u8 port = params->port;
1027 /* MCP Dbg0 and dbg1 are always with higher strict pri*/
1028 u64 pri_cli_nig = 0x210;
1029 u32 pri_cli_pbf = 0x0;
1030 u8 pri_set = 0;
1031 u8 pri_bitmask = 0;
1032 const u8 max_num_of_cos = (port) ? DCBX_E3B0_MAX_NUM_COS_PORT1 :
1033 DCBX_E3B0_MAX_NUM_COS_PORT0;
1034
1035 u8 cos_bit_to_set = (1 << max_num_of_cos) - 1;
1036
1037 /* Set all the strict priority first */
1038 for (i = 0; i < max_num_of_cos; i++) {
Yaniv Rosnerde0396f2011-11-28 00:49:53 +00001039 if (sp_pri_to_cos[i] != DCBX_INVALID_COS) {
1040 if (sp_pri_to_cos[i] >= DCBX_MAX_NUM_COS) {
Yaniv Rosner6c3218c2011-06-14 01:34:23 +00001041 DP(NETIF_MSG_LINK,
1042 "bnx2x_ets_e3b0_sp_set_pri_cli_reg "
1043 "invalid cos entry\n");
1044 return -EINVAL;
1045 }
1046
1047 pri_cli_nig |= bnx2x_e3b0_sp_get_pri_cli_reg_nig(
1048 sp_pri_to_cos[i], pri_set);
1049
1050 pri_cli_pbf |= bnx2x_e3b0_sp_get_pri_cli_reg_pbf(
1051 sp_pri_to_cos[i], pri_set);
1052 pri_bitmask = 1 << sp_pri_to_cos[i];
1053 /* COS is used remove it from bitmap.*/
Yaniv Rosnerde0396f2011-11-28 00:49:53 +00001054 if (!(pri_bitmask & cos_bit_to_set)) {
Yaniv Rosner6c3218c2011-06-14 01:34:23 +00001055 DP(NETIF_MSG_LINK,
1056 "bnx2x_ets_e3b0_sp_set_pri_cli_reg "
1057 "invalid There can't be two COS's with"
1058 " the same strict pri\n");
1059 return -EINVAL;
1060 }
1061 cos_bit_to_set &= ~pri_bitmask;
1062 pri_set++;
1063 }
1064 }
1065
1066 /* Set all the Non strict priority i= COS*/
1067 for (i = 0; i < max_num_of_cos; i++) {
1068 pri_bitmask = 1 << i;
1069 /* Check if COS was already used for SP */
1070 if (pri_bitmask & cos_bit_to_set) {
1071 /* COS wasn't used for SP */
1072 pri_cli_nig |= bnx2x_e3b0_sp_get_pri_cli_reg_nig(
1073 i, pri_set);
1074
1075 pri_cli_pbf |= bnx2x_e3b0_sp_get_pri_cli_reg_pbf(
1076 i, pri_set);
1077 /* COS is used remove it from bitmap.*/
1078 cos_bit_to_set &= ~pri_bitmask;
1079 pri_set++;
1080 }
1081 }
1082
1083 if (pri_set != max_num_of_cos) {
1084 DP(NETIF_MSG_LINK, "bnx2x_ets_e3b0_sp_set_pri_cli_reg not all "
1085 "entries were set\n");
1086 return -EINVAL;
1087 }
1088
1089 if (port) {
1090 /* Only 6 usable clients*/
1091 REG_WR(bp, NIG_REG_P1_TX_ARB_PRIORITY_CLIENT2_LSB,
1092 (u32)pri_cli_nig);
1093
1094 REG_WR(bp, PBF_REG_ETS_ARB_PRIORITY_CLIENT_P1 , pri_cli_pbf);
1095 } else {
1096 /* Only 9 usable clients*/
1097 const u32 pri_cli_nig_lsb = (u32) (pri_cli_nig);
1098 const u32 pri_cli_nig_msb = (u32) ((pri_cli_nig >> 32) & 0xF);
1099
1100 REG_WR(bp, NIG_REG_P0_TX_ARB_PRIORITY_CLIENT2_LSB,
1101 pri_cli_nig_lsb);
1102 REG_WR(bp, NIG_REG_P0_TX_ARB_PRIORITY_CLIENT2_MSB,
1103 pri_cli_nig_msb);
1104
1105 REG_WR(bp, PBF_REG_ETS_ARB_PRIORITY_CLIENT_P0 , pri_cli_pbf);
1106 }
1107 return 0;
1108}
1109
1110/******************************************************************************
1111* Description:
1112* Configure the COS to ETS according to BW and SP settings.
1113******************************************************************************/
1114int bnx2x_ets_e3b0_config(const struct link_params *params,
1115 const struct link_vars *vars,
Yaniv Rosner870516e12011-11-28 00:49:46 +00001116 struct bnx2x_ets_params *ets_params)
Yaniv Rosner6c3218c2011-06-14 01:34:23 +00001117{
1118 struct bnx2x *bp = params->bp;
1119 int bnx2x_status = 0;
1120 const u8 port = params->port;
1121 u16 total_bw = 0;
1122 const u32 min_w_val_nig = bnx2x_ets_get_min_w_val_nig(vars);
1123 const u32 min_w_val_pbf = ETS_E3B0_PBF_MIN_W_VAL;
1124 u8 cos_bw_bitmap = 0;
1125 u8 cos_sp_bitmap = 0;
1126 u8 sp_pri_to_cos[DCBX_MAX_NUM_COS] = {0};
1127 const u8 max_num_of_cos = (port) ? DCBX_E3B0_MAX_NUM_COS_PORT1 :
1128 DCBX_E3B0_MAX_NUM_COS_PORT0;
1129 u8 cos_entry = 0;
1130
1131 if (!CHIP_IS_E3B0(bp)) {
Joe Perches94f05b02011-08-14 12:16:20 +00001132 DP(NETIF_MSG_LINK,
1133 "bnx2x_ets_e3b0_disabled the chip isn't E3B0\n");
Yaniv Rosner6c3218c2011-06-14 01:34:23 +00001134 return -EINVAL;
1135 }
1136
1137 if ((ets_params->num_of_cos > max_num_of_cos)) {
1138 DP(NETIF_MSG_LINK, "bnx2x_ets_E3B0_config the number of COS "
1139 "isn't supported\n");
1140 return -EINVAL;
1141 }
1142
1143 /* Prepare sp strict priority parameters*/
1144 bnx2x_ets_e3b0_sp_pri_to_cos_init(sp_pri_to_cos);
1145
1146 /* Prepare BW parameters*/
1147 bnx2x_status = bnx2x_ets_e3b0_get_total_bw(params, ets_params,
1148 &total_bw);
Yaniv Rosnerde0396f2011-11-28 00:49:53 +00001149 if (bnx2x_status) {
Joe Perches94f05b02011-08-14 12:16:20 +00001150 DP(NETIF_MSG_LINK,
1151 "bnx2x_ets_E3B0_config get_total_bw failed\n");
Yaniv Rosner6c3218c2011-06-14 01:34:23 +00001152 return -EINVAL;
1153 }
1154
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001155 /* Upper bound is set according to current link speed (min_w_val
Yaniv Rosner2f751a82011-11-28 00:49:52 +00001156 * should be the same for upper bound and COS credit val).
Yaniv Rosner6c3218c2011-06-14 01:34:23 +00001157 */
1158 bnx2x_ets_e3b0_set_credit_upper_bound_nig(params, min_w_val_nig);
1159 bnx2x_ets_e3b0_set_credit_upper_bound_pbf(params, min_w_val_pbf);
1160
1161
1162 for (cos_entry = 0; cos_entry < ets_params->num_of_cos; cos_entry++) {
1163 if (bnx2x_cos_state_bw == ets_params->cos[cos_entry].state) {
1164 cos_bw_bitmap |= (1 << cos_entry);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001165 /* The function also sets the BW in HW(not the mappin
Yaniv Rosner6c3218c2011-06-14 01:34:23 +00001166 * yet)
1167 */
1168 bnx2x_status = bnx2x_ets_e3b0_set_cos_bw(
1169 bp, cos_entry, min_w_val_nig, min_w_val_pbf,
1170 total_bw,
1171 ets_params->cos[cos_entry].params.bw_params.bw,
1172 port);
1173 } else if (bnx2x_cos_state_strict ==
1174 ets_params->cos[cos_entry].state){
1175 cos_sp_bitmap |= (1 << cos_entry);
1176
1177 bnx2x_status = bnx2x_ets_e3b0_sp_pri_to_cos_set(
1178 params,
1179 sp_pri_to_cos,
1180 ets_params->cos[cos_entry].params.sp_params.pri,
1181 cos_entry);
1182
1183 } else {
Joe Perches94f05b02011-08-14 12:16:20 +00001184 DP(NETIF_MSG_LINK,
1185 "bnx2x_ets_e3b0_config cos state not valid\n");
Yaniv Rosner6c3218c2011-06-14 01:34:23 +00001186 return -EINVAL;
1187 }
Yaniv Rosnerde0396f2011-11-28 00:49:53 +00001188 if (bnx2x_status) {
Joe Perches94f05b02011-08-14 12:16:20 +00001189 DP(NETIF_MSG_LINK,
1190 "bnx2x_ets_e3b0_config set cos bw failed\n");
Yaniv Rosner6c3218c2011-06-14 01:34:23 +00001191 return bnx2x_status;
1192 }
1193 }
1194
1195 /* Set SP register (which COS has higher priority) */
1196 bnx2x_status = bnx2x_ets_e3b0_sp_set_pri_cli_reg(params,
1197 sp_pri_to_cos);
1198
Yaniv Rosnerde0396f2011-11-28 00:49:53 +00001199 if (bnx2x_status) {
Joe Perches94f05b02011-08-14 12:16:20 +00001200 DP(NETIF_MSG_LINK,
1201 "bnx2x_ets_E3B0_config set_pri_cli_reg failed\n");
Yaniv Rosner6c3218c2011-06-14 01:34:23 +00001202 return bnx2x_status;
1203 }
1204
1205 /* Set client mapping of BW and strict */
1206 bnx2x_status = bnx2x_ets_e3b0_cli_map(params, ets_params,
1207 cos_sp_bitmap,
1208 cos_bw_bitmap);
1209
Yaniv Rosnerde0396f2011-11-28 00:49:53 +00001210 if (bnx2x_status) {
Yaniv Rosner6c3218c2011-06-14 01:34:23 +00001211 DP(NETIF_MSG_LINK, "bnx2x_ets_E3B0_config SP failed\n");
1212 return bnx2x_status;
1213 }
1214 return 0;
1215}
Yaniv Rosner65a001b2011-01-31 04:22:03 +00001216static void bnx2x_ets_bw_limit_common(const struct link_params *params)
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001217{
1218 /* ETS disabled configuration */
1219 struct bnx2x *bp = params->bp;
1220 DP(NETIF_MSG_LINK, "ETS enabled BW limit configuration\n");
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001221 /* Defines which entries (clients) are subjected to WFQ arbitration
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00001222 * COS0 0x8
1223 * COS1 0x10
1224 */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001225 REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_IS_SUBJECT2WFQ, 0x18);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001226 /* Mapping between the ARB_CREDIT_WEIGHT registers and actual
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00001227 * client numbers (WEIGHT_0 does not actually have to represent
1228 * client 0)
1229 * PRI4 | PRI3 | PRI2 | PRI1 | PRI0
1230 * cos1-001 cos0-000 dbg1-100 dbg0-011 MCP-010
1231 */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001232 REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_CREDIT_MAP, 0x111A);
1233
1234 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_0,
1235 ETS_BW_LIMIT_CREDIT_UPPER_BOUND);
1236 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_1,
1237 ETS_BW_LIMIT_CREDIT_UPPER_BOUND);
1238
1239 /* ETS mode enabled*/
1240 REG_WR(bp, PBF_REG_ETS_ENABLED, 1);
1241
1242 /* Defines the number of consecutive slots for the strict priority */
1243 REG_WR(bp, PBF_REG_NUM_STRICT_ARB_SLOTS, 0);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001244 /* Bitmap of 5bits length. Each bit specifies whether the entry behaves
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00001245 * as strict. Bits 0,1,2 - debug and management entries, 3 - COS0
1246 * entry, 4 - COS1 entry.
1247 * COS1 | COS0 | DEBUG21 | DEBUG0 | MGMT
1248 * bit4 bit3 bit2 bit1 bit0
1249 * MCP and debug are strict
1250 */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001251 REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_IS_STRICT, 0x7);
1252
1253 /* Upper bound that COS0_WEIGHT can reach in the WFQ arbiter.*/
1254 REG_WR(bp, PBF_REG_COS0_UPPER_BOUND,
1255 ETS_BW_LIMIT_CREDIT_UPPER_BOUND);
1256 REG_WR(bp, PBF_REG_COS1_UPPER_BOUND,
1257 ETS_BW_LIMIT_CREDIT_UPPER_BOUND);
1258}
1259
1260void bnx2x_ets_bw_limit(const struct link_params *params, const u32 cos0_bw,
1261 const u32 cos1_bw)
1262{
1263 /* ETS disabled configuration*/
1264 struct bnx2x *bp = params->bp;
1265 const u32 total_bw = cos0_bw + cos1_bw;
1266 u32 cos0_credit_weight = 0;
1267 u32 cos1_credit_weight = 0;
1268
1269 DP(NETIF_MSG_LINK, "ETS enabled BW limit configuration\n");
1270
Yaniv Rosnerde0396f2011-11-28 00:49:53 +00001271 if ((!total_bw) ||
1272 (!cos0_bw) ||
1273 (!cos1_bw)) {
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001274 DP(NETIF_MSG_LINK, "Total BW can't be zero\n");
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001275 return;
1276 }
1277
1278 cos0_credit_weight = (cos0_bw * ETS_BW_LIMIT_CREDIT_WEIGHT)/
1279 total_bw;
1280 cos1_credit_weight = (cos1_bw * ETS_BW_LIMIT_CREDIT_WEIGHT)/
1281 total_bw;
1282
1283 bnx2x_ets_bw_limit_common(params);
1284
1285 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_0, cos0_credit_weight);
1286 REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_1, cos1_credit_weight);
1287
1288 REG_WR(bp, PBF_REG_COS0_WEIGHT, cos0_credit_weight);
1289 REG_WR(bp, PBF_REG_COS1_WEIGHT, cos1_credit_weight);
1290}
1291
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00001292int bnx2x_ets_strict(const struct link_params *params, const u8 strict_cos)
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001293{
1294 /* ETS disabled configuration*/
1295 struct bnx2x *bp = params->bp;
1296 u32 val = 0;
1297
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001298 DP(NETIF_MSG_LINK, "ETS enabled strict configuration\n");
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001299 /* Bitmap of 5bits length. Each bit specifies whether the entry behaves
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001300 * as strict. Bits 0,1,2 - debug and management entries,
1301 * 3 - COS0 entry, 4 - COS1 entry.
1302 * COS1 | COS0 | DEBUG21 | DEBUG0 | MGMT
1303 * bit4 bit3 bit2 bit1 bit0
1304 * MCP and debug are strict
1305 */
1306 REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_IS_STRICT, 0x1F);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001307 /* For strict priority entries defines the number of consecutive slots
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001308 * for the highest priority.
1309 */
1310 REG_WR(bp, NIG_REG_P0_TX_ARB_NUM_STRICT_ARB_SLOTS, 0x100);
1311 /* ETS mode disable */
1312 REG_WR(bp, PBF_REG_ETS_ENABLED, 0);
1313 /* Defines the number of consecutive slots for the strict priority */
1314 REG_WR(bp, PBF_REG_NUM_STRICT_ARB_SLOTS, 0x100);
1315
1316 /* Defines the number of consecutive slots for the strict priority */
1317 REG_WR(bp, PBF_REG_HIGH_PRIORITY_COS_NUM, strict_cos);
1318
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001319 /* Mapping between entry priority to client number (0,1,2 -debug and
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00001320 * management clients, 3 - COS0 client, 4 - COS client)(HIGHEST)
1321 * 3bits client num.
1322 * PRI4 | PRI3 | PRI2 | PRI1 | PRI0
1323 * dbg0-010 dbg1-001 cos1-100 cos0-011 MCP-000
1324 * dbg0-010 dbg1-001 cos0-011 cos1-100 MCP-000
1325 */
Yaniv Rosnerde0396f2011-11-28 00:49:53 +00001326 val = (!strict_cos) ? 0x2318 : 0x22E0;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001327 REG_WR(bp, NIG_REG_P0_TX_ARB_PRIORITY_CLIENT, val);
1328
1329 return 0;
1330}
Yuval Mintzc8c60d82012-06-06 17:13:07 +00001331
1332/******************************************************************/
Dmitry Kravkove8920672011-05-04 23:52:40 +00001333/* PFC section */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001334/******************************************************************/
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001335static void bnx2x_update_pfc_xmac(struct link_params *params,
1336 struct link_vars *vars,
1337 u8 is_lb)
1338{
1339 struct bnx2x *bp = params->bp;
1340 u32 xmac_base;
1341 u32 pause_val, pfc0_val, pfc1_val;
1342
1343 /* XMAC base adrr */
1344 xmac_base = (params->port) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
1345
1346 /* Initialize pause and pfc registers */
1347 pause_val = 0x18000;
1348 pfc0_val = 0xFFFF8000;
1349 pfc1_val = 0x2;
1350
1351 /* No PFC support */
1352 if (!(params->feature_config_flags &
1353 FEATURE_CONFIG_PFC_ENABLED)) {
1354
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001355 /* RX flow control - Process pause frame in receive direction
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001356 */
1357 if (vars->flow_ctrl & BNX2X_FLOW_CTRL_RX)
1358 pause_val |= XMAC_PAUSE_CTRL_REG_RX_PAUSE_EN;
1359
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001360 /* TX flow control - Send pause packet when buffer is full */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001361 if (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX)
1362 pause_val |= XMAC_PAUSE_CTRL_REG_TX_PAUSE_EN;
1363 } else {/* PFC support */
1364 pfc1_val |= XMAC_PFC_CTRL_HI_REG_PFC_REFRESH_EN |
1365 XMAC_PFC_CTRL_HI_REG_PFC_STATS_EN |
1366 XMAC_PFC_CTRL_HI_REG_RX_PFC_EN |
Yaniv Rosner27d91292012-04-04 01:28:54 +00001367 XMAC_PFC_CTRL_HI_REG_TX_PFC_EN |
1368 XMAC_PFC_CTRL_HI_REG_FORCE_PFC_XON;
1369 /* Write pause and PFC registers */
1370 REG_WR(bp, xmac_base + XMAC_REG_PAUSE_CTRL, pause_val);
1371 REG_WR(bp, xmac_base + XMAC_REG_PFC_CTRL, pfc0_val);
1372 REG_WR(bp, xmac_base + XMAC_REG_PFC_CTRL_HI, pfc1_val);
1373 pfc1_val &= ~XMAC_PFC_CTRL_HI_REG_FORCE_PFC_XON;
1374
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001375 }
1376
1377 /* Write pause and PFC registers */
1378 REG_WR(bp, xmac_base + XMAC_REG_PAUSE_CTRL, pause_val);
1379 REG_WR(bp, xmac_base + XMAC_REG_PFC_CTRL, pfc0_val);
1380 REG_WR(bp, xmac_base + XMAC_REG_PFC_CTRL_HI, pfc1_val);
1381
Yaniv Rosnerb8d6d082011-07-05 01:06:27 +00001382
1383 /* Set MAC address for source TX Pause/PFC frames */
1384 REG_WR(bp, xmac_base + XMAC_REG_CTRL_SA_LO,
1385 ((params->mac_addr[2] << 24) |
1386 (params->mac_addr[3] << 16) |
1387 (params->mac_addr[4] << 8) |
1388 (params->mac_addr[5])));
1389 REG_WR(bp, xmac_base + XMAC_REG_CTRL_SA_HI,
1390 ((params->mac_addr[0] << 8) |
1391 (params->mac_addr[1])));
1392
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001393 udelay(30);
1394}
1395
1396
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001397static void bnx2x_emac_get_pfc_stat(struct link_params *params,
1398 u32 pfc_frames_sent[2],
1399 u32 pfc_frames_received[2])
1400{
1401 /* Read pfc statistic */
1402 struct bnx2x *bp = params->bp;
1403 u32 emac_base = params->port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
1404 u32 val_xon = 0;
1405 u32 val_xoff = 0;
1406
1407 DP(NETIF_MSG_LINK, "pfc statistic read from EMAC\n");
1408
1409 /* PFC received frames */
1410 val_xoff = REG_RD(bp, emac_base +
1411 EMAC_REG_RX_PFC_STATS_XOFF_RCVD);
1412 val_xoff &= EMAC_REG_RX_PFC_STATS_XOFF_RCVD_COUNT;
1413 val_xon = REG_RD(bp, emac_base + EMAC_REG_RX_PFC_STATS_XON_RCVD);
1414 val_xon &= EMAC_REG_RX_PFC_STATS_XON_RCVD_COUNT;
1415
1416 pfc_frames_received[0] = val_xon + val_xoff;
1417
1418 /* PFC received sent */
1419 val_xoff = REG_RD(bp, emac_base +
1420 EMAC_REG_RX_PFC_STATS_XOFF_SENT);
1421 val_xoff &= EMAC_REG_RX_PFC_STATS_XOFF_SENT_COUNT;
1422 val_xon = REG_RD(bp, emac_base + EMAC_REG_RX_PFC_STATS_XON_SENT);
1423 val_xon &= EMAC_REG_RX_PFC_STATS_XON_SENT_COUNT;
1424
1425 pfc_frames_sent[0] = val_xon + val_xoff;
1426}
1427
Yaniv Rosnerb8d6d082011-07-05 01:06:27 +00001428/* Read pfc statistic*/
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001429void bnx2x_pfc_statistic(struct link_params *params, struct link_vars *vars,
1430 u32 pfc_frames_sent[2],
1431 u32 pfc_frames_received[2])
1432{
1433 /* Read pfc statistic */
1434 struct bnx2x *bp = params->bp;
Yaniv Rosnerb8d6d082011-07-05 01:06:27 +00001435
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001436 DP(NETIF_MSG_LINK, "pfc statistic\n");
1437
1438 if (!vars->link_up)
1439 return;
1440
Yaniv Rosnerde0396f2011-11-28 00:49:53 +00001441 if (vars->mac_type == MAC_TYPE_EMAC) {
Yaniv Rosnerb8d6d082011-07-05 01:06:27 +00001442 DP(NETIF_MSG_LINK, "About to read PFC stats from EMAC\n");
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001443 bnx2x_emac_get_pfc_stat(params, pfc_frames_sent,
1444 pfc_frames_received);
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001445 }
1446}
1447/******************************************************************/
1448/* MAC/PBF section */
1449/******************************************************************/
Yaniv Rosner55386fe82012-11-27 03:46:30 +00001450static void bnx2x_set_mdio_clk(struct bnx2x *bp, u32 chip_id,
1451 u32 emac_base)
Yaniv Rosnera198c142011-05-31 21:29:42 +00001452{
Yaniv Rosner55386fe82012-11-27 03:46:30 +00001453 u32 new_mode, cur_mode;
1454 u32 clc_cnt;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001455 /* Set clause 45 mode, slow down the MDIO clock to 2.5MHz
Yaniv Rosnera198c142011-05-31 21:29:42 +00001456 * (a value of 49==0x31) and make sure that the AUTO poll is off
1457 */
Yaniv Rosner55386fe82012-11-27 03:46:30 +00001458 cur_mode = REG_RD(bp, emac_base + EMAC_REG_EMAC_MDIO_MODE);
Yaniv Rosnera198c142011-05-31 21:29:42 +00001459
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00001460 if (USES_WARPCORE(bp))
Yaniv Rosner55386fe82012-11-27 03:46:30 +00001461 clc_cnt = 74L << EMAC_MDIO_MODE_CLOCK_CNT_BITSHIFT;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00001462 else
Yaniv Rosner55386fe82012-11-27 03:46:30 +00001463 clc_cnt = 49L << EMAC_MDIO_MODE_CLOCK_CNT_BITSHIFT;
Yaniv Rosnera198c142011-05-31 21:29:42 +00001464
Yaniv Rosner55386fe82012-11-27 03:46:30 +00001465 if (((cur_mode & EMAC_MDIO_MODE_CLOCK_CNT) == clc_cnt) &&
1466 (cur_mode & (EMAC_MDIO_MODE_CLAUSE_45)))
1467 return;
Yaniv Rosnera198c142011-05-31 21:29:42 +00001468
Yaniv Rosner55386fe82012-11-27 03:46:30 +00001469 new_mode = cur_mode &
1470 ~(EMAC_MDIO_MODE_AUTO_POLL | EMAC_MDIO_MODE_CLOCK_CNT);
1471 new_mode |= clc_cnt;
1472 new_mode |= (EMAC_MDIO_MODE_CLAUSE_45);
1473
1474 DP(NETIF_MSG_LINK, "Changing emac_mode from 0x%x to 0x%x\n",
1475 cur_mode, new_mode);
1476 REG_WR(bp, emac_base + EMAC_REG_EMAC_MDIO_MODE, new_mode);
Yaniv Rosnera198c142011-05-31 21:29:42 +00001477 udelay(40);
1478}
Yaniv Rosner55386fe82012-11-27 03:46:30 +00001479
1480static void bnx2x_set_mdio_emac_per_phy(struct bnx2x *bp,
1481 struct link_params *params)
1482{
1483 u8 phy_index;
1484 /* Set mdio clock per phy */
1485 for (phy_index = INT_PHY; phy_index < params->num_phys;
1486 phy_index++)
1487 bnx2x_set_mdio_clk(bp, params->chip_id,
1488 params->phy[phy_index].mdio_ctrl);
1489}
1490
Yaniv Rosner2f751a82011-11-28 00:49:52 +00001491static u8 bnx2x_is_4_port_mode(struct bnx2x *bp)
1492{
1493 u32 port4mode_ovwr_val;
1494 /* Check 4-port override enabled */
1495 port4mode_ovwr_val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
1496 if (port4mode_ovwr_val & (1<<0)) {
1497 /* Return 4-port mode override value */
1498 return ((port4mode_ovwr_val & (1<<1)) == (1<<1));
1499 }
1500 /* Return 4-port mode from input pin */
1501 return (u8)REG_RD(bp, MISC_REG_PORT4MODE_EN);
1502}
Yaniv Rosnera198c142011-05-31 21:29:42 +00001503
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001504static void bnx2x_emac_init(struct link_params *params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001505 struct link_vars *vars)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001506{
1507 /* reset and unreset the emac core */
1508 struct bnx2x *bp = params->bp;
1509 u8 port = params->port;
1510 u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
1511 u32 val;
1512 u16 timeout;
1513
1514 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001515 (MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE << port));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001516 udelay(5);
1517 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001518 (MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE << port));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001519
1520 /* init emac - use read-modify-write */
1521 /* self clear reset */
1522 val = REG_RD(bp, emac_base + EMAC_REG_EMAC_MODE);
Eilon Greenstein3196a882008-08-13 15:58:49 -07001523 EMAC_WR(bp, EMAC_REG_EMAC_MODE, (val | EMAC_MODE_RESET));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001524
1525 timeout = 200;
Eilon Greenstein3196a882008-08-13 15:58:49 -07001526 do {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001527 val = REG_RD(bp, emac_base + EMAC_REG_EMAC_MODE);
1528 DP(NETIF_MSG_LINK, "EMAC reset reg is %u\n", val);
1529 if (!timeout) {
1530 DP(NETIF_MSG_LINK, "EMAC timeout!\n");
1531 return;
1532 }
1533 timeout--;
Eilon Greenstein3196a882008-08-13 15:58:49 -07001534 } while (val & EMAC_MODE_RESET);
Yaniv Rosner55386fe82012-11-27 03:46:30 +00001535
1536 bnx2x_set_mdio_emac_per_phy(bp, params);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001537 /* Set mac address */
1538 val = ((params->mac_addr[0] << 8) |
1539 params->mac_addr[1]);
Eilon Greenstein3196a882008-08-13 15:58:49 -07001540 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001541
1542 val = ((params->mac_addr[2] << 24) |
1543 (params->mac_addr[3] << 16) |
1544 (params->mac_addr[4] << 8) |
1545 params->mac_addr[5]);
Eilon Greenstein3196a882008-08-13 15:58:49 -07001546 EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + 4, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001547}
1548
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001549static void bnx2x_set_xumac_nig(struct link_params *params,
1550 u16 tx_pause_en,
1551 u8 enable)
1552{
1553 struct bnx2x *bp = params->bp;
1554
1555 REG_WR(bp, params->port ? NIG_REG_P1_MAC_IN_EN : NIG_REG_P0_MAC_IN_EN,
1556 enable);
1557 REG_WR(bp, params->port ? NIG_REG_P1_MAC_OUT_EN : NIG_REG_P0_MAC_OUT_EN,
1558 enable);
1559 REG_WR(bp, params->port ? NIG_REG_P1_MAC_PAUSE_OUT_EN :
1560 NIG_REG_P0_MAC_PAUSE_OUT_EN, tx_pause_en);
1561}
1562
Yaniv Rosnerd3a8f132012-09-13 02:56:20 +00001563static void bnx2x_set_umac_rxtx(struct link_params *params, u8 en)
Yaniv Rosnerce7c0482011-10-27 05:09:47 +00001564{
1565 u32 umac_base = params->port ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
Yaniv Rosnerd3a8f132012-09-13 02:56:20 +00001566 u32 val;
Yaniv Rosnerce7c0482011-10-27 05:09:47 +00001567 struct bnx2x *bp = params->bp;
1568 if (!(REG_RD(bp, MISC_REG_RESET_REG_2) &
1569 (MISC_REGISTERS_RESET_REG_2_UMAC0 << params->port)))
1570 return;
Yaniv Rosnerd3a8f132012-09-13 02:56:20 +00001571 val = REG_RD(bp, umac_base + UMAC_REG_COMMAND_CONFIG);
1572 if (en)
1573 val |= (UMAC_COMMAND_CONFIG_REG_TX_ENA |
1574 UMAC_COMMAND_CONFIG_REG_RX_ENA);
1575 else
1576 val &= ~(UMAC_COMMAND_CONFIG_REG_TX_ENA |
1577 UMAC_COMMAND_CONFIG_REG_RX_ENA);
Yaniv Rosnerce7c0482011-10-27 05:09:47 +00001578 /* Disable RX and TX */
Yaniv Rosnerd3a8f132012-09-13 02:56:20 +00001579 REG_WR(bp, umac_base + UMAC_REG_COMMAND_CONFIG, val);
Yaniv Rosnerce7c0482011-10-27 05:09:47 +00001580}
1581
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001582static void bnx2x_umac_enable(struct link_params *params,
1583 struct link_vars *vars, u8 lb)
1584{
1585 u32 val;
1586 u32 umac_base = params->port ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
1587 struct bnx2x *bp = params->bp;
1588 /* Reset UMAC */
1589 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
1590 (MISC_REGISTERS_RESET_REG_2_UMAC0 << params->port));
Yuval Mintzd2310232012-06-20 19:05:19 +00001591 usleep_range(1000, 2000);
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001592
1593 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
1594 (MISC_REGISTERS_RESET_REG_2_UMAC0 << params->port));
1595
1596 DP(NETIF_MSG_LINK, "enabling UMAC\n");
1597
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001598 /* This register opens the gate for the UMAC despite its name */
1599 REG_WR(bp, NIG_REG_EGRESS_EMAC0_PORT + params->port*4, 1);
1600
1601 val = UMAC_COMMAND_CONFIG_REG_PROMIS_EN |
1602 UMAC_COMMAND_CONFIG_REG_PAD_EN |
1603 UMAC_COMMAND_CONFIG_REG_SW_RESET |
1604 UMAC_COMMAND_CONFIG_REG_NO_LGTH_CHECK;
1605 switch (vars->line_speed) {
1606 case SPEED_10:
1607 val |= (0<<2);
1608 break;
1609 case SPEED_100:
1610 val |= (1<<2);
1611 break;
1612 case SPEED_1000:
1613 val |= (2<<2);
1614 break;
1615 case SPEED_2500:
1616 val |= (3<<2);
1617 break;
1618 default:
1619 DP(NETIF_MSG_LINK, "Invalid speed for UMAC %d\n",
1620 vars->line_speed);
1621 break;
1622 }
Yaniv Rosner9d5b36b2011-08-02 22:59:10 +00001623 if (!(vars->flow_ctrl & BNX2X_FLOW_CTRL_TX))
1624 val |= UMAC_COMMAND_CONFIG_REG_IGNORE_TX_PAUSE;
1625
1626 if (!(vars->flow_ctrl & BNX2X_FLOW_CTRL_RX))
1627 val |= UMAC_COMMAND_CONFIG_REG_PAUSE_IGNORE;
1628
Mintz Yuvale18c56b2012-02-15 02:10:23 +00001629 if (vars->duplex == DUPLEX_HALF)
1630 val |= UMAC_COMMAND_CONFIG_REG_HD_ENA;
1631
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001632 REG_WR(bp, umac_base + UMAC_REG_COMMAND_CONFIG, val);
1633 udelay(50);
1634
Yuval Mintz26964bb2012-09-10 05:51:08 +00001635 /* Configure UMAC for EEE */
1636 if (vars->eee_status & SHMEM_EEE_ADV_STATUS_MASK) {
1637 DP(NETIF_MSG_LINK, "configured UMAC for EEE\n");
1638 REG_WR(bp, umac_base + UMAC_REG_UMAC_EEE_CTRL,
1639 UMAC_UMAC_EEE_CTRL_REG_EEE_EN);
1640 REG_WR(bp, umac_base + UMAC_REG_EEE_WAKE_TIMER, 0x11);
1641 } else {
1642 REG_WR(bp, umac_base + UMAC_REG_UMAC_EEE_CTRL, 0x0);
1643 }
1644
Yaniv Rosnerb8d6d082011-07-05 01:06:27 +00001645 /* Set MAC address for source TX Pause/PFC frames (under SW reset) */
1646 REG_WR(bp, umac_base + UMAC_REG_MAC_ADDR0,
1647 ((params->mac_addr[2] << 24) |
1648 (params->mac_addr[3] << 16) |
1649 (params->mac_addr[4] << 8) |
1650 (params->mac_addr[5])));
1651 REG_WR(bp, umac_base + UMAC_REG_MAC_ADDR1,
1652 ((params->mac_addr[0] << 8) |
1653 (params->mac_addr[1])));
1654
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001655 /* Enable RX and TX */
1656 val &= ~UMAC_COMMAND_CONFIG_REG_PAD_EN;
1657 val |= UMAC_COMMAND_CONFIG_REG_TX_ENA |
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00001658 UMAC_COMMAND_CONFIG_REG_RX_ENA;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001659 REG_WR(bp, umac_base + UMAC_REG_COMMAND_CONFIG, val);
1660 udelay(50);
1661
1662 /* Remove SW Reset */
1663 val &= ~UMAC_COMMAND_CONFIG_REG_SW_RESET;
1664
1665 /* Check loopback mode */
1666 if (lb)
1667 val |= UMAC_COMMAND_CONFIG_REG_LOOP_ENA;
1668 REG_WR(bp, umac_base + UMAC_REG_COMMAND_CONFIG, val);
1669
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001670 /* Maximum Frame Length (RW). Defines a 14-Bit maximum frame
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001671 * length used by the MAC receive logic to check frames.
1672 */
1673 REG_WR(bp, umac_base + UMAC_REG_MAXFR, 0x2710);
1674 bnx2x_set_xumac_nig(params,
1675 ((vars->flow_ctrl & BNX2X_FLOW_CTRL_TX) != 0), 1);
1676 vars->mac_type = MAC_TYPE_UMAC;
1677
1678}
1679
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001680/* Define the XMAC mode */
Yaniv Rosnerce7c0482011-10-27 05:09:47 +00001681static void bnx2x_xmac_init(struct link_params *params, u32 max_speed)
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001682{
Yaniv Rosnerce7c0482011-10-27 05:09:47 +00001683 struct bnx2x *bp = params->bp;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001684 u32 is_port4mode = bnx2x_is_4_port_mode(bp);
1685
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001686 /* In 4-port mode, need to set the mode only once, so if XMAC is
Yaniv Rosner2f751a82011-11-28 00:49:52 +00001687 * already out of reset, it means the mode has already been set,
1688 * and it must not* reset the XMAC again, since it controls both
1689 * ports of the path
1690 */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001691
Yaniv Rosner4e7b4992012-11-27 03:46:29 +00001692 if (((CHIP_NUM(bp) == CHIP_NUM_57840_4_10) ||
1693 (CHIP_NUM(bp) == CHIP_NUM_57840_2_20) ||
1694 (CHIP_NUM(bp) == CHIP_NUM_57840_OBSOLETE)) &&
1695 is_port4mode &&
Yaniv Rosnerce7c0482011-10-27 05:09:47 +00001696 (REG_RD(bp, MISC_REG_RESET_REG_2) &
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001697 MISC_REGISTERS_RESET_REG_2_XMAC)) {
Joe Perches94f05b02011-08-14 12:16:20 +00001698 DP(NETIF_MSG_LINK,
1699 "XMAC already out of reset in 4-port mode\n");
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001700 return;
1701 }
1702
1703 /* Hard reset */
1704 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
1705 MISC_REGISTERS_RESET_REG_2_XMAC);
Yuval Mintzd2310232012-06-20 19:05:19 +00001706 usleep_range(1000, 2000);
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001707
1708 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
1709 MISC_REGISTERS_RESET_REG_2_XMAC);
1710 if (is_port4mode) {
1711 DP(NETIF_MSG_LINK, "Init XMAC to 2 ports x 10G per path\n");
1712
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001713 /* Set the number of ports on the system side to up to 2 */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001714 REG_WR(bp, MISC_REG_XMAC_CORE_PORT_MODE, 1);
1715
1716 /* Set the number of ports on the Warp Core to 10G */
1717 REG_WR(bp, MISC_REG_XMAC_PHY_PORT_MODE, 3);
1718 } else {
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001719 /* Set the number of ports on the system side to 1 */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001720 REG_WR(bp, MISC_REG_XMAC_CORE_PORT_MODE, 0);
1721 if (max_speed == SPEED_10000) {
Joe Perches94f05b02011-08-14 12:16:20 +00001722 DP(NETIF_MSG_LINK,
1723 "Init XMAC to 10G x 1 port per path\n");
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001724 /* Set the number of ports on the Warp Core to 10G */
1725 REG_WR(bp, MISC_REG_XMAC_PHY_PORT_MODE, 3);
1726 } else {
Joe Perches94f05b02011-08-14 12:16:20 +00001727 DP(NETIF_MSG_LINK,
1728 "Init XMAC to 20G x 2 ports per path\n");
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001729 /* Set the number of ports on the Warp Core to 20G */
1730 REG_WR(bp, MISC_REG_XMAC_PHY_PORT_MODE, 1);
1731 }
1732 }
1733 /* Soft reset */
1734 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
1735 MISC_REGISTERS_RESET_REG_2_XMAC_SOFT);
Yuval Mintzd2310232012-06-20 19:05:19 +00001736 usleep_range(1000, 2000);
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001737
1738 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
1739 MISC_REGISTERS_RESET_REG_2_XMAC_SOFT);
1740
1741}
1742
Yaniv Rosnerd3a8f132012-09-13 02:56:20 +00001743static void bnx2x_set_xmac_rxtx(struct link_params *params, u8 en)
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001744{
1745 u8 port = params->port;
1746 struct bnx2x *bp = params->bp;
Yaniv Rosnerb5077662011-08-02 22:59:18 +00001747 u32 pfc_ctrl, xmac_base = (port) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
Yaniv Rosnerd3a8f132012-09-13 02:56:20 +00001748 u32 val;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001749
1750 if (REG_RD(bp, MISC_REG_RESET_REG_2) &
1751 MISC_REGISTERS_RESET_REG_2_XMAC) {
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001752 /* Send an indication to change the state in the NIG back to XON
Yaniv Rosnerb5077662011-08-02 22:59:18 +00001753 * Clearing this bit enables the next set of this bit to get
1754 * rising edge
1755 */
1756 pfc_ctrl = REG_RD(bp, xmac_base + XMAC_REG_PFC_CTRL_HI);
1757 REG_WR(bp, xmac_base + XMAC_REG_PFC_CTRL_HI,
1758 (pfc_ctrl & ~(1<<1)));
1759 REG_WR(bp, xmac_base + XMAC_REG_PFC_CTRL_HI,
1760 (pfc_ctrl | (1<<1)));
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001761 DP(NETIF_MSG_LINK, "Disable XMAC on port %x\n", port);
Yaniv Rosnerd3a8f132012-09-13 02:56:20 +00001762 val = REG_RD(bp, xmac_base + XMAC_REG_CTRL);
1763 if (en)
1764 val |= (XMAC_CTRL_REG_TX_EN | XMAC_CTRL_REG_RX_EN);
1765 else
1766 val &= ~(XMAC_CTRL_REG_TX_EN | XMAC_CTRL_REG_RX_EN);
1767 REG_WR(bp, xmac_base + XMAC_REG_CTRL, val);
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001768 }
1769}
1770
1771static int bnx2x_xmac_enable(struct link_params *params,
1772 struct link_vars *vars, u8 lb)
1773{
1774 u32 val, xmac_base;
1775 struct bnx2x *bp = params->bp;
1776 DP(NETIF_MSG_LINK, "enabling XMAC\n");
1777
1778 xmac_base = (params->port) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
1779
Yaniv Rosnerce7c0482011-10-27 05:09:47 +00001780 bnx2x_xmac_init(params, vars->line_speed);
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001781
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001782 /* This register determines on which events the MAC will assert
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001783 * error on the i/f to the NIG along w/ EOP.
1784 */
1785
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001786 /* This register tells the NIG whether to send traffic to UMAC
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001787 * or XMAC
1788 */
1789 REG_WR(bp, NIG_REG_EGRESS_EMAC0_PORT + params->port*4, 0);
1790
Yaniv Rosner4e7b4992012-11-27 03:46:29 +00001791 /* When XMAC is in XLGMII mode, disable sending idles for fault
1792 * detection.
1793 */
1794 if (!(params->phy[INT_PHY].flags & FLAGS_TX_ERROR_CHECK)) {
1795 REG_WR(bp, xmac_base + XMAC_REG_RX_LSS_CTRL,
1796 (XMAC_RX_LSS_CTRL_REG_LOCAL_FAULT_DISABLE |
1797 XMAC_RX_LSS_CTRL_REG_REMOTE_FAULT_DISABLE));
1798 REG_WR(bp, xmac_base + XMAC_REG_CLEAR_RX_LSS_STATUS, 0);
1799 REG_WR(bp, xmac_base + XMAC_REG_CLEAR_RX_LSS_STATUS,
1800 XMAC_CLEAR_RX_LSS_STATUS_REG_CLEAR_LOCAL_FAULT_STATUS |
1801 XMAC_CLEAR_RX_LSS_STATUS_REG_CLEAR_REMOTE_FAULT_STATUS);
1802 }
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001803 /* Set Max packet size */
1804 REG_WR(bp, xmac_base + XMAC_REG_RX_MAX_SIZE, 0x2710);
1805
1806 /* CRC append for Tx packets */
1807 REG_WR(bp, xmac_base + XMAC_REG_TX_CTRL, 0xC800);
1808
1809 /* update PFC */
1810 bnx2x_update_pfc_xmac(params, vars, 0);
1811
Yuval Mintzc8c60d82012-06-06 17:13:07 +00001812 if (vars->eee_status & SHMEM_EEE_ADV_STATUS_MASK) {
1813 DP(NETIF_MSG_LINK, "Setting XMAC for EEE\n");
1814 REG_WR(bp, xmac_base + XMAC_REG_EEE_TIMERS_HI, 0x1380008);
1815 REG_WR(bp, xmac_base + XMAC_REG_EEE_CTRL, 0x1);
1816 } else {
1817 REG_WR(bp, xmac_base + XMAC_REG_EEE_CTRL, 0x0);
1818 }
1819
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001820 /* Enable TX and RX */
1821 val = XMAC_CTRL_REG_TX_EN | XMAC_CTRL_REG_RX_EN;
1822
Yaniv Rosner4e7b4992012-11-27 03:46:29 +00001823 /* Set MAC in XLGMII mode for dual-mode */
1824 if ((vars->line_speed == SPEED_20000) &&
1825 (params->phy[INT_PHY].supported &
1826 SUPPORTED_20000baseKR2_Full))
1827 val |= XMAC_CTRL_REG_XLGMII_ALIGN_ENB;
1828
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001829 /* Check loopback mode */
1830 if (lb)
David S. Miller8decf862011-09-22 03:23:13 -04001831 val |= XMAC_CTRL_REG_LINE_LOCAL_LPBK;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00001832 REG_WR(bp, xmac_base + XMAC_REG_CTRL, val);
1833 bnx2x_set_xumac_nig(params,
1834 ((vars->flow_ctrl & BNX2X_FLOW_CTRL_TX) != 0), 1);
1835
1836 vars->mac_type = MAC_TYPE_XMAC;
1837
1838 return 0;
1839}
Yaniv Rosner2f751a82011-11-28 00:49:52 +00001840
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00001841static int bnx2x_emac_enable(struct link_params *params,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00001842 struct link_vars *vars, u8 lb)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001843{
1844 struct bnx2x *bp = params->bp;
1845 u8 port = params->port;
1846 u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
1847 u32 val;
1848
1849 DP(NETIF_MSG_LINK, "enabling EMAC\n");
1850
Yaniv Rosnerde6f3372011-08-02 22:59:25 +00001851 /* Disable BMAC */
1852 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
1853 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port));
1854
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001855 /* enable emac and not bmac */
1856 REG_WR(bp, NIG_REG_EGRESS_EMAC0_PORT + port*4, 1);
1857
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001858 /* ASIC */
1859 if (vars->phy_flags & PHY_XGXS_FLAG) {
1860 u32 ser_lane = ((params->lane_config &
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001861 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_MASK) >>
1862 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_SHIFT);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001863
1864 DP(NETIF_MSG_LINK, "XGXS\n");
1865 /* select the master lanes (out of 0-3) */
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001866 REG_WR(bp, NIG_REG_XGXS_LANE_SEL_P0 + port*4, ser_lane);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001867 /* select XGXS */
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001868 REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001869
1870 } else { /* SerDes */
1871 DP(NETIF_MSG_LINK, "SerDes\n");
1872 /* select SerDes */
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001873 REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001874 }
1875
Eilon Greenstein811a2f22009-02-12 08:37:04 +00001876 bnx2x_bits_en(bp, emac_base + EMAC_REG_EMAC_RX_MODE,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001877 EMAC_RX_MODE_RESET);
Eilon Greenstein811a2f22009-02-12 08:37:04 +00001878 bnx2x_bits_en(bp, emac_base + EMAC_REG_EMAC_TX_MODE,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00001879 EMAC_TX_MODE_RESET);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001880
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001881 /* pause enable/disable */
1882 bnx2x_bits_dis(bp, emac_base + EMAC_REG_EMAC_RX_MODE,
1883 EMAC_RX_MODE_FLOW_EN);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001884
1885 bnx2x_bits_dis(bp, emac_base + EMAC_REG_EMAC_TX_MODE,
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001886 (EMAC_TX_MODE_EXT_PAUSE_EN |
1887 EMAC_TX_MODE_FLOW_EN));
1888 if (!(params->feature_config_flags &
1889 FEATURE_CONFIG_PFC_ENABLED)) {
1890 if (vars->flow_ctrl & BNX2X_FLOW_CTRL_RX)
1891 bnx2x_bits_en(bp, emac_base +
1892 EMAC_REG_EMAC_RX_MODE,
1893 EMAC_RX_MODE_FLOW_EN);
1894
1895 if (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX)
1896 bnx2x_bits_en(bp, emac_base +
1897 EMAC_REG_EMAC_TX_MODE,
1898 (EMAC_TX_MODE_EXT_PAUSE_EN |
1899 EMAC_TX_MODE_FLOW_EN));
1900 } else
1901 bnx2x_bits_en(bp, emac_base + EMAC_REG_EMAC_TX_MODE,
1902 EMAC_TX_MODE_FLOW_EN);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001903
1904 /* KEEP_VLAN_TAG, promiscuous */
1905 val = REG_RD(bp, emac_base + EMAC_REG_EMAC_RX_MODE);
1906 val |= EMAC_RX_MODE_KEEP_VLAN_TAG | EMAC_RX_MODE_PROMISCUOUS;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001907
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00001908 /* Setting this bit causes MAC control frames (except for pause
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00001909 * frames) to be passed on for processing. This setting has no
1910 * affect on the operation of the pause frames. This bit effects
1911 * all packets regardless of RX Parser packet sorting logic.
1912 * Turn the PFC off to make sure we are in Xon state before
1913 * enabling it.
1914 */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001915 EMAC_WR(bp, EMAC_REG_RX_PFC_MODE, 0);
1916 if (params->feature_config_flags & FEATURE_CONFIG_PFC_ENABLED) {
1917 DP(NETIF_MSG_LINK, "PFC is enabled\n");
1918 /* Enable PFC again */
1919 EMAC_WR(bp, EMAC_REG_RX_PFC_MODE,
1920 EMAC_REG_RX_PFC_MODE_RX_EN |
1921 EMAC_REG_RX_PFC_MODE_TX_EN |
1922 EMAC_REG_RX_PFC_MODE_PRIORITIES);
1923
1924 EMAC_WR(bp, EMAC_REG_RX_PFC_PARAM,
1925 ((0x0101 <<
1926 EMAC_REG_RX_PFC_PARAM_OPCODE_BITSHIFT) |
1927 (0x00ff <<
1928 EMAC_REG_RX_PFC_PARAM_PRIORITY_EN_BITSHIFT)));
1929 val |= EMAC_RX_MODE_KEEP_MAC_CONTROL;
1930 }
Eilon Greenstein3196a882008-08-13 15:58:49 -07001931 EMAC_WR(bp, EMAC_REG_EMAC_RX_MODE, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001932
1933 /* Set Loopback */
1934 val = REG_RD(bp, emac_base + EMAC_REG_EMAC_MODE);
1935 if (lb)
1936 val |= 0x810;
1937 else
1938 val &= ~0x810;
Eilon Greenstein3196a882008-08-13 15:58:49 -07001939 EMAC_WR(bp, EMAC_REG_EMAC_MODE, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001940
Yuval Mintzd2310232012-06-20 19:05:19 +00001941 /* Enable emac */
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00001942 REG_WR(bp, NIG_REG_NIG_EMAC0_EN + port*4, 1);
1943
Yuval Mintzd2310232012-06-20 19:05:19 +00001944 /* Enable emac for jumbo packets */
Eilon Greenstein3196a882008-08-13 15:58:49 -07001945 EMAC_WR(bp, EMAC_REG_EMAC_RX_MTU_SIZE,
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001946 (EMAC_RX_MTU_SIZE_JUMBO_ENA |
1947 (ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD)));
1948
Yuval Mintzd2310232012-06-20 19:05:19 +00001949 /* Strip CRC */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001950 REG_WR(bp, NIG_REG_NIG_INGRESS_EMAC0_NO_CRC + port*4, 0x1);
1951
Yuval Mintzd2310232012-06-20 19:05:19 +00001952 /* Disable the NIG in/out to the bmac */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001953 REG_WR(bp, NIG_REG_BMAC0_IN_EN + port*4, 0x0);
1954 REG_WR(bp, NIG_REG_BMAC0_PAUSE_OUT_EN + port*4, 0x0);
1955 REG_WR(bp, NIG_REG_BMAC0_OUT_EN + port*4, 0x0);
1956
Yuval Mintzd2310232012-06-20 19:05:19 +00001957 /* Enable the NIG in/out to the emac */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001958 REG_WR(bp, NIG_REG_EMAC0_IN_EN + port*4, 0x1);
1959 val = 0;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001960 if ((params->feature_config_flags &
1961 FEATURE_CONFIG_PFC_ENABLED) ||
1962 (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX))
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001963 val = 1;
1964
1965 REG_WR(bp, NIG_REG_EMAC0_PAUSE_OUT_EN + port*4, val);
1966 REG_WR(bp, NIG_REG_EGRESS_EMAC0_OUT_EN + port*4, 0x1);
1967
Yaniv Rosner02a23162011-01-31 04:22:53 +00001968 REG_WR(bp, NIG_REG_BMAC0_REGS_OUT_EN + port*4, 0x0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07001969
1970 vars->mac_type = MAC_TYPE_EMAC;
1971 return 0;
1972}
1973
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001974static void bnx2x_update_pfc_bmac1(struct link_params *params,
1975 struct link_vars *vars)
1976{
1977 u32 wb_data[2];
1978 struct bnx2x *bp = params->bp;
1979 u32 bmac_addr = params->port ? NIG_REG_INGRESS_BMAC1_MEM :
1980 NIG_REG_INGRESS_BMAC0_MEM;
1981
1982 u32 val = 0x14;
1983 if ((!(params->feature_config_flags &
1984 FEATURE_CONFIG_PFC_ENABLED)) &&
1985 (vars->flow_ctrl & BNX2X_FLOW_CTRL_RX))
1986 /* Enable BigMAC to react on received Pause packets */
1987 val |= (1<<5);
1988 wb_data[0] = val;
1989 wb_data[1] = 0;
1990 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_RX_CONTROL, wb_data, 2);
1991
Yuval Mintzd2310232012-06-20 19:05:19 +00001992 /* TX control */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00001993 val = 0xc0;
1994 if (!(params->feature_config_flags &
1995 FEATURE_CONFIG_PFC_ENABLED) &&
1996 (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX))
1997 val |= 0x800000;
1998 wb_data[0] = val;
1999 wb_data[1] = 0;
2000 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_TX_CONTROL, wb_data, 2);
2001}
2002
2003static void bnx2x_update_pfc_bmac2(struct link_params *params,
2004 struct link_vars *vars,
2005 u8 is_lb)
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002006{
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002007 /* Set rx control: Strip CRC and enable BigMAC to relay
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002008 * control packets to the system as well
2009 */
2010 u32 wb_data[2];
2011 struct bnx2x *bp = params->bp;
2012 u32 bmac_addr = params->port ? NIG_REG_INGRESS_BMAC1_MEM :
2013 NIG_REG_INGRESS_BMAC0_MEM;
2014 u32 val = 0x14;
2015
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002016 if ((!(params->feature_config_flags &
2017 FEATURE_CONFIG_PFC_ENABLED)) &&
2018 (vars->flow_ctrl & BNX2X_FLOW_CTRL_RX))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002019 /* Enable BigMAC to react on received Pause packets */
2020 val |= (1<<5);
2021 wb_data[0] = val;
2022 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002023 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_RX_CONTROL, wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002024 udelay(30);
2025
2026 /* Tx control */
2027 val = 0xc0;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002028 if (!(params->feature_config_flags &
2029 FEATURE_CONFIG_PFC_ENABLED) &&
2030 (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002031 val |= 0x800000;
2032 wb_data[0] = val;
2033 wb_data[1] = 0;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002034 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_TX_CONTROL, wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002035
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002036 if (params->feature_config_flags & FEATURE_CONFIG_PFC_ENABLED) {
2037 DP(NETIF_MSG_LINK, "PFC is enabled\n");
2038 /* Enable PFC RX & TX & STATS and set 8 COS */
2039 wb_data[0] = 0x0;
2040 wb_data[0] |= (1<<0); /* RX */
2041 wb_data[0] |= (1<<1); /* TX */
2042 wb_data[0] |= (1<<2); /* Force initial Xon */
2043 wb_data[0] |= (1<<3); /* 8 cos */
2044 wb_data[0] |= (1<<5); /* STATS */
2045 wb_data[1] = 0;
2046 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_PFC_CONTROL,
2047 wb_data, 2);
2048 /* Clear the force Xon */
2049 wb_data[0] &= ~(1<<2);
2050 } else {
2051 DP(NETIF_MSG_LINK, "PFC is disabled\n");
Yuval Mintzd2310232012-06-20 19:05:19 +00002052 /* Disable PFC RX & TX & STATS and set 8 COS */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002053 wb_data[0] = 0x8;
2054 wb_data[1] = 0;
2055 }
2056
2057 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_PFC_CONTROL, wb_data, 2);
2058
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002059 /* Set Time (based unit is 512 bit time) between automatic
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002060 * re-sending of PP packets amd enable automatic re-send of
2061 * Per-Priroity Packet as long as pp_gen is asserted and
2062 * pp_disable is low.
2063 */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002064 val = 0x8000;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002065 if (params->feature_config_flags & FEATURE_CONFIG_PFC_ENABLED)
2066 val |= (1<<16); /* enable automatic re-send */
2067
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002068 wb_data[0] = val;
2069 wb_data[1] = 0;
2070 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_TX_PAUSE_CONTROL,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002071 wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002072
2073 /* mac control */
2074 val = 0x3; /* Enable RX and TX */
2075 if (is_lb) {
2076 val |= 0x4; /* Local loopback */
2077 DP(NETIF_MSG_LINK, "enable bmac loopback\n");
2078 }
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002079 /* When PFC enabled, Pass pause frames towards the NIG. */
2080 if (params->feature_config_flags & FEATURE_CONFIG_PFC_ENABLED)
2081 val |= ((1<<6)|(1<<5));
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002082
2083 wb_data[0] = val;
2084 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002085 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_BMAC_CONTROL, wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002086}
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002087
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002088/******************************************************************************
2089* Description:
2090* This function is needed because NIG ARB_CREDIT_WEIGHT_X are
2091* not continues and ARB_CREDIT_WEIGHT_0 + offset is suitable.
2092******************************************************************************/
Yuval Mintzd2310232012-06-20 19:05:19 +00002093static int bnx2x_pfc_nig_rx_priority_mask(struct bnx2x *bp,
2094 u8 cos_entry,
2095 u32 priority_mask, u8 port)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002096{
2097 u32 nig_reg_rx_priority_mask_add = 0;
2098
2099 switch (cos_entry) {
2100 case 0:
2101 nig_reg_rx_priority_mask_add = (port) ?
2102 NIG_REG_P1_RX_COS0_PRIORITY_MASK :
2103 NIG_REG_P0_RX_COS0_PRIORITY_MASK;
2104 break;
2105 case 1:
2106 nig_reg_rx_priority_mask_add = (port) ?
2107 NIG_REG_P1_RX_COS1_PRIORITY_MASK :
2108 NIG_REG_P0_RX_COS1_PRIORITY_MASK;
2109 break;
2110 case 2:
2111 nig_reg_rx_priority_mask_add = (port) ?
2112 NIG_REG_P1_RX_COS2_PRIORITY_MASK :
2113 NIG_REG_P0_RX_COS2_PRIORITY_MASK;
2114 break;
2115 case 3:
2116 if (port)
2117 return -EINVAL;
2118 nig_reg_rx_priority_mask_add = NIG_REG_P0_RX_COS3_PRIORITY_MASK;
2119 break;
2120 case 4:
2121 if (port)
2122 return -EINVAL;
2123 nig_reg_rx_priority_mask_add = NIG_REG_P0_RX_COS4_PRIORITY_MASK;
2124 break;
2125 case 5:
2126 if (port)
2127 return -EINVAL;
2128 nig_reg_rx_priority_mask_add = NIG_REG_P0_RX_COS5_PRIORITY_MASK;
2129 break;
2130 }
2131
2132 REG_WR(bp, nig_reg_rx_priority_mask_add, priority_mask);
2133
2134 return 0;
2135}
Yaniv Rosnerb8d6d082011-07-05 01:06:27 +00002136static void bnx2x_update_mng(struct link_params *params, u32 link_status)
2137{
2138 struct bnx2x *bp = params->bp;
2139
2140 REG_WR(bp, params->shmem_base +
2141 offsetof(struct shmem_region,
2142 port_mb[params->port].link_status), link_status);
2143}
2144
Yaniv Rosner4e7b4992012-11-27 03:46:29 +00002145static void bnx2x_update_link_attr(struct link_params *params, u32 link_attr)
2146{
2147 struct bnx2x *bp = params->bp;
2148
2149 if (SHMEM2_HAS(bp, link_attr_sync))
2150 REG_WR(bp, params->shmem2_base +
2151 offsetof(struct shmem2_region,
2152 link_attr_sync[params->port]), link_attr);
2153}
2154
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002155static void bnx2x_update_pfc_nig(struct link_params *params,
2156 struct link_vars *vars,
2157 struct bnx2x_nig_brb_pfc_port_params *nig_params)
2158{
2159 u32 xcm_mask = 0, ppp_enable = 0, pause_enable = 0, llfc_out_en = 0;
Yaniv Rosner127302b2012-01-17 02:33:26 +00002160 u32 llfc_enable = 0, xcm_out_en = 0, hwpfc_enable = 0;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002161 u32 pkt_priority_to_cos = 0;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002162 struct bnx2x *bp = params->bp;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002163 u8 port = params->port;
2164
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002165 int set_pfc = params->feature_config_flags &
2166 FEATURE_CONFIG_PFC_ENABLED;
2167 DP(NETIF_MSG_LINK, "updating pfc nig parameters\n");
2168
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002169 /* When NIG_LLH0_XCM_MASK_REG_LLHX_XCM_MASK_BCN bit is set
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002170 * MAC control frames (that are not pause packets)
2171 * will be forwarded to the XCM.
2172 */
Yaniv Rosner127302b2012-01-17 02:33:26 +00002173 xcm_mask = REG_RD(bp, port ? NIG_REG_LLH1_XCM_MASK :
2174 NIG_REG_LLH0_XCM_MASK);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002175 /* NIG params will override non PFC params, since it's possible to
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002176 * do transition from PFC to SAFC
2177 */
2178 if (set_pfc) {
2179 pause_enable = 0;
2180 llfc_out_en = 0;
2181 llfc_enable = 0;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002182 if (CHIP_IS_E3(bp))
2183 ppp_enable = 0;
2184 else
Yaniv Rosner503976e2012-11-27 03:46:34 +00002185 ppp_enable = 1;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002186 xcm_mask &= ~(port ? NIG_LLH1_XCM_MASK_REG_LLH1_XCM_MASK_BCN :
2187 NIG_LLH0_XCM_MASK_REG_LLH0_XCM_MASK_BCN);
Yaniv Rosner127302b2012-01-17 02:33:26 +00002188 xcm_out_en = 0;
2189 hwpfc_enable = 1;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002190 } else {
2191 if (nig_params) {
2192 llfc_out_en = nig_params->llfc_out_en;
2193 llfc_enable = nig_params->llfc_enable;
2194 pause_enable = nig_params->pause_enable;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002195 } else /* Default non PFC mode - PAUSE */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002196 pause_enable = 1;
2197
2198 xcm_mask |= (port ? NIG_LLH1_XCM_MASK_REG_LLH1_XCM_MASK_BCN :
2199 NIG_LLH0_XCM_MASK_REG_LLH0_XCM_MASK_BCN);
Yaniv Rosner127302b2012-01-17 02:33:26 +00002200 xcm_out_en = 1;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002201 }
2202
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002203 if (CHIP_IS_E3(bp))
2204 REG_WR(bp, port ? NIG_REG_BRB1_PAUSE_IN_EN :
2205 NIG_REG_BRB0_PAUSE_IN_EN, pause_enable);
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002206 REG_WR(bp, port ? NIG_REG_LLFC_OUT_EN_1 :
2207 NIG_REG_LLFC_OUT_EN_0, llfc_out_en);
2208 REG_WR(bp, port ? NIG_REG_LLFC_ENABLE_1 :
2209 NIG_REG_LLFC_ENABLE_0, llfc_enable);
2210 REG_WR(bp, port ? NIG_REG_PAUSE_ENABLE_1 :
2211 NIG_REG_PAUSE_ENABLE_0, pause_enable);
2212
2213 REG_WR(bp, port ? NIG_REG_PPP_ENABLE_1 :
2214 NIG_REG_PPP_ENABLE_0, ppp_enable);
2215
2216 REG_WR(bp, port ? NIG_REG_LLH1_XCM_MASK :
2217 NIG_REG_LLH0_XCM_MASK, xcm_mask);
2218
Yaniv Rosner127302b2012-01-17 02:33:26 +00002219 REG_WR(bp, port ? NIG_REG_LLFC_EGRESS_SRC_ENABLE_1 :
2220 NIG_REG_LLFC_EGRESS_SRC_ENABLE_0, 0x7);
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002221
Yuval Mintzd2310232012-06-20 19:05:19 +00002222 /* Output enable for RX_XCM # IF */
Yaniv Rosner127302b2012-01-17 02:33:26 +00002223 REG_WR(bp, port ? NIG_REG_XCM1_OUT_EN :
2224 NIG_REG_XCM0_OUT_EN, xcm_out_en);
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002225
2226 /* HW PFC TX enable */
Yaniv Rosner127302b2012-01-17 02:33:26 +00002227 REG_WR(bp, port ? NIG_REG_P1_HWPFC_ENABLE :
2228 NIG_REG_P0_HWPFC_ENABLE, hwpfc_enable);
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002229
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002230 if (nig_params) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002231 u8 i = 0;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002232 pkt_priority_to_cos = nig_params->pkt_priority_to_cos;
2233
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002234 for (i = 0; i < nig_params->num_of_rx_cos_priority_mask; i++)
2235 bnx2x_pfc_nig_rx_priority_mask(bp, i,
2236 nig_params->rx_cos_priority_mask[i], port);
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002237
2238 REG_WR(bp, port ? NIG_REG_LLFC_HIGH_PRIORITY_CLASSES_1 :
2239 NIG_REG_LLFC_HIGH_PRIORITY_CLASSES_0,
2240 nig_params->llfc_high_priority_classes);
2241
2242 REG_WR(bp, port ? NIG_REG_LLFC_LOW_PRIORITY_CLASSES_1 :
2243 NIG_REG_LLFC_LOW_PRIORITY_CLASSES_0,
2244 nig_params->llfc_low_priority_classes);
2245 }
2246 REG_WR(bp, port ? NIG_REG_P1_PKT_PRIORITY_TO_COS :
2247 NIG_REG_P0_PKT_PRIORITY_TO_COS,
2248 pkt_priority_to_cos);
2249}
2250
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002251int bnx2x_update_pfc(struct link_params *params,
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002252 struct link_vars *vars,
2253 struct bnx2x_nig_brb_pfc_port_params *pfc_params)
2254{
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00002255 /* The PFC and pause are orthogonal to one another, meaning when
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002256 * PFC is enabled, the pause are disabled, and when PFC is
2257 * disabled, pause are set according to the pause result.
2258 */
2259 u32 val;
2260 struct bnx2x *bp = params->bp;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002261 int bnx2x_status = 0;
2262 u8 bmac_loopback = (params->loopback_mode == LOOPBACK_BMAC);
Yaniv Rosnerb8d6d082011-07-05 01:06:27 +00002263
2264 if (params->feature_config_flags & FEATURE_CONFIG_PFC_ENABLED)
2265 vars->link_status |= LINK_STATUS_PFC_ENABLED;
2266 else
2267 vars->link_status &= ~LINK_STATUS_PFC_ENABLED;
2268
2269 bnx2x_update_mng(params, vars->link_status);
2270
Yuval Mintzd2310232012-06-20 19:05:19 +00002271 /* Update NIG params */
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002272 bnx2x_update_pfc_nig(params, vars, pfc_params);
2273
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002274 if (!vars->link_up)
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002275 return bnx2x_status;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002276
2277 DP(NETIF_MSG_LINK, "About to update PFC in BMAC\n");
Yaniv Rosner375944c2012-09-11 04:34:10 +00002278
2279 if (CHIP_IS_E3(bp)) {
2280 if (vars->mac_type == MAC_TYPE_XMAC)
2281 bnx2x_update_pfc_xmac(params, vars, 0);
2282 } else {
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002283 val = REG_RD(bp, MISC_REG_RESET_REG_2);
2284 if ((val &
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00002285 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << params->port))
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002286 == 0) {
2287 DP(NETIF_MSG_LINK, "About to update PFC in EMAC\n");
2288 bnx2x_emac_enable(params, vars, 0);
2289 return bnx2x_status;
2290 }
Yaniv Rosner9380bb92011-06-14 01:34:07 +00002291 if (CHIP_IS_E2(bp))
2292 bnx2x_update_pfc_bmac2(params, vars, bmac_loopback);
2293 else
2294 bnx2x_update_pfc_bmac1(params, vars);
2295
2296 val = 0;
2297 if ((params->feature_config_flags &
2298 FEATURE_CONFIG_PFC_ENABLED) ||
2299 (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX))
2300 val = 1;
2301 REG_WR(bp, NIG_REG_BMAC0_PAUSE_OUT_EN + params->port*4, val);
2302 }
2303 return bnx2x_status;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002304}
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002305
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00002306static int bnx2x_bmac1_enable(struct link_params *params,
2307 struct link_vars *vars,
2308 u8 is_lb)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002309{
2310 struct bnx2x *bp = params->bp;
2311 u8 port = params->port;
2312 u32 bmac_addr = port ? NIG_REG_INGRESS_BMAC1_MEM :
2313 NIG_REG_INGRESS_BMAC0_MEM;
2314 u32 wb_data[2];
2315 u32 val;
2316
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002317 DP(NETIF_MSG_LINK, "Enabling BigMAC1\n");
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002318
2319 /* XGXS control */
2320 wb_data[0] = 0x3c;
2321 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002322 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_BMAC_XGXS_CONTROL,
2323 wb_data, 2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002324
Yuval Mintzd2310232012-06-20 19:05:19 +00002325 /* TX MAC SA */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002326 wb_data[0] = ((params->mac_addr[2] << 24) |
2327 (params->mac_addr[3] << 16) |
2328 (params->mac_addr[4] << 8) |
2329 params->mac_addr[5]);
2330 wb_data[1] = ((params->mac_addr[0] << 8) |
2331 params->mac_addr[1]);
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002332 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_TX_SOURCE_ADDR, wb_data, 2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002333
Yuval Mintzd2310232012-06-20 19:05:19 +00002334 /* MAC control */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002335 val = 0x3;
2336 if (is_lb) {
2337 val |= 0x4;
2338 DP(NETIF_MSG_LINK, "enable bmac loopback\n");
2339 }
2340 wb_data[0] = val;
2341 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002342 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_BMAC_CONTROL, wb_data, 2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002343
Yuval Mintzd2310232012-06-20 19:05:19 +00002344 /* Set rx mtu */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002345 wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD;
2346 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002347 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_RX_MAX_SIZE, wb_data, 2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002348
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002349 bnx2x_update_pfc_bmac1(params, vars);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002350
Yuval Mintzd2310232012-06-20 19:05:19 +00002351 /* Set tx mtu */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002352 wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD;
2353 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002354 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_TX_MAX_SIZE, wb_data, 2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002355
Yuval Mintzd2310232012-06-20 19:05:19 +00002356 /* Set cnt max size */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002357 wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD;
2358 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002359 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_CNT_MAX_SIZE, wb_data, 2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002360
Yuval Mintzd2310232012-06-20 19:05:19 +00002361 /* Configure SAFC */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002362 wb_data[0] = 0x1000200;
2363 wb_data[1] = 0;
2364 REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_RX_LLFC_MSG_FLDS,
2365 wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002366
2367 return 0;
2368}
2369
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00002370static int bnx2x_bmac2_enable(struct link_params *params,
2371 struct link_vars *vars,
2372 u8 is_lb)
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002373{
2374 struct bnx2x *bp = params->bp;
2375 u8 port = params->port;
2376 u32 bmac_addr = port ? NIG_REG_INGRESS_BMAC1_MEM :
2377 NIG_REG_INGRESS_BMAC0_MEM;
2378 u32 wb_data[2];
2379
2380 DP(NETIF_MSG_LINK, "Enabling BigMAC2\n");
2381
2382 wb_data[0] = 0;
2383 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002384 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_BMAC_CONTROL, wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002385 udelay(30);
2386
2387 /* XGXS control: Reset phy HW, MDIO registers, PHY PLL and BMAC */
2388 wb_data[0] = 0x3c;
2389 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002390 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_BMAC_XGXS_CONTROL,
2391 wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002392
2393 udelay(30);
2394
Yuval Mintzd2310232012-06-20 19:05:19 +00002395 /* TX MAC SA */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002396 wb_data[0] = ((params->mac_addr[2] << 24) |
2397 (params->mac_addr[3] << 16) |
2398 (params->mac_addr[4] << 8) |
2399 params->mac_addr[5]);
2400 wb_data[1] = ((params->mac_addr[0] << 8) |
2401 params->mac_addr[1]);
2402 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_TX_SOURCE_ADDR,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002403 wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002404
2405 udelay(30);
2406
2407 /* Configure SAFC */
2408 wb_data[0] = 0x1000200;
2409 wb_data[1] = 0;
2410 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_RX_LLFC_MSG_FLDS,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002411 wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002412 udelay(30);
2413
Yuval Mintzd2310232012-06-20 19:05:19 +00002414 /* Set RX MTU */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002415 wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD;
2416 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002417 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_RX_MAX_SIZE, wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002418 udelay(30);
2419
Yuval Mintzd2310232012-06-20 19:05:19 +00002420 /* Set TX MTU */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002421 wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD;
2422 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002423 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_TX_MAX_SIZE, wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002424 udelay(30);
Yuval Mintzd2310232012-06-20 19:05:19 +00002425 /* Set cnt max size */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002426 wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD - 2;
2427 wb_data[1] = 0;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002428 REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_CNT_MAX_SIZE, wb_data, 2);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002429 udelay(30);
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002430 bnx2x_update_pfc_bmac2(params, vars, is_lb);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002431
2432 return 0;
2433}
2434
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00002435static int bnx2x_bmac_enable(struct link_params *params,
2436 struct link_vars *vars,
Yaniv Rosnerd3a8f132012-09-13 02:56:20 +00002437 u8 is_lb, u8 reset_bmac)
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002438{
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00002439 int rc = 0;
2440 u8 port = params->port;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002441 struct bnx2x *bp = params->bp;
2442 u32 val;
Yuval Mintzd2310232012-06-20 19:05:19 +00002443 /* Reset and unreset the BigMac */
Yaniv Rosnerd3a8f132012-09-13 02:56:20 +00002444 if (reset_bmac) {
2445 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
2446 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port));
2447 usleep_range(1000, 2000);
2448 }
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002449
2450 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002451 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port));
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002452
Yuval Mintzd2310232012-06-20 19:05:19 +00002453 /* Enable access for bmac registers */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002454 REG_WR(bp, NIG_REG_BMAC0_REGS_OUT_EN + port*4, 0x1);
2455
2456 /* Enable BMAC according to BMAC type*/
2457 if (CHIP_IS_E2(bp))
2458 rc = bnx2x_bmac2_enable(params, vars, is_lb);
2459 else
2460 rc = bnx2x_bmac1_enable(params, vars, is_lb);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002461 REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 0x1);
2462 REG_WR(bp, NIG_REG_XGXS_LANE_SEL_P0 + port*4, 0x0);
2463 REG_WR(bp, NIG_REG_EGRESS_EMAC0_PORT + port*4, 0x0);
2464 val = 0;
Vladislav Zolotarovbcab15c2010-12-13 05:44:25 +00002465 if ((params->feature_config_flags &
2466 FEATURE_CONFIG_PFC_ENABLED) ||
2467 (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX))
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002468 val = 1;
2469 REG_WR(bp, NIG_REG_BMAC0_PAUSE_OUT_EN + port*4, val);
2470 REG_WR(bp, NIG_REG_EGRESS_EMAC0_OUT_EN + port*4, 0x0);
2471 REG_WR(bp, NIG_REG_EMAC0_IN_EN + port*4, 0x0);
2472 REG_WR(bp, NIG_REG_EMAC0_PAUSE_OUT_EN + port*4, 0x0);
2473 REG_WR(bp, NIG_REG_BMAC0_IN_EN + port*4, 0x1);
2474 REG_WR(bp, NIG_REG_BMAC0_OUT_EN + port*4, 0x1);
2475
2476 vars->mac_type = MAC_TYPE_BMAC;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002477 return rc;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002478}
2479
Yaniv Rosnerd3a8f132012-09-13 02:56:20 +00002480static void bnx2x_set_bmac_rx(struct bnx2x *bp, u32 chip_id, u8 port, u8 en)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002481{
2482 u32 bmac_addr = port ? NIG_REG_INGRESS_BMAC1_MEM :
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002483 NIG_REG_INGRESS_BMAC0_MEM;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002484 u32 wb_data[2];
Eilon Greenstein3196a882008-08-13 15:58:49 -07002485 u32 nig_bmac_enable = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port*4);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002486
Yaniv Rosnerd3a8f132012-09-13 02:56:20 +00002487 if (CHIP_IS_E2(bp))
2488 bmac_addr += BIGMAC2_REGISTER_BMAC_CONTROL;
2489 else
2490 bmac_addr += BIGMAC_REGISTER_BMAC_CONTROL;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002491 /* Only if the bmac is out of reset */
2492 if (REG_RD(bp, MISC_REG_RESET_REG_2) &
2493 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port) &&
2494 nig_bmac_enable) {
Yaniv Rosnerd3a8f132012-09-13 02:56:20 +00002495 /* Clear Rx Enable bit in BMAC_CONTROL register */
2496 REG_RD_DMAE(bp, bmac_addr, wb_data, 2);
2497 if (en)
2498 wb_data[0] |= BMAC_CONTROL_RX_ENABLE;
2499 else
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002500 wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
Yaniv Rosnerd3a8f132012-09-13 02:56:20 +00002501 REG_WR_DMAE(bp, bmac_addr, wb_data, 2);
Yuval Mintzd2310232012-06-20 19:05:19 +00002502 usleep_range(1000, 2000);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002503 }
2504}
2505
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00002506static int bnx2x_pbf_update(struct link_params *params, u32 flow_ctrl,
2507 u32 line_speed)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002508{
2509 struct bnx2x *bp = params->bp;
2510 u8 port = params->port;
2511 u32 init_crd, crd;
2512 u32 count = 1000;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002513
Yuval Mintzd2310232012-06-20 19:05:19 +00002514 /* Disable port */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002515 REG_WR(bp, PBF_REG_DISABLE_NEW_TASK_PROC_P0 + port*4, 0x1);
2516
Yuval Mintzd2310232012-06-20 19:05:19 +00002517 /* Wait for init credit */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002518 init_crd = REG_RD(bp, PBF_REG_P0_INIT_CRD + port*4);
2519 crd = REG_RD(bp, PBF_REG_P0_CREDIT + port*8);
2520 DP(NETIF_MSG_LINK, "init_crd 0x%x crd 0x%x\n", init_crd, crd);
2521
2522 while ((init_crd != crd) && count) {
Yuval Mintzd2310232012-06-20 19:05:19 +00002523 usleep_range(5000, 10000);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002524 crd = REG_RD(bp, PBF_REG_P0_CREDIT + port*8);
2525 count--;
2526 }
2527 crd = REG_RD(bp, PBF_REG_P0_CREDIT + port*8);
2528 if (init_crd != crd) {
2529 DP(NETIF_MSG_LINK, "BUG! init_crd 0x%x != crd 0x%x\n",
2530 init_crd, crd);
2531 return -EINVAL;
2532 }
2533
David S. Millerc0700f92008-12-16 23:53:20 -08002534 if (flow_ctrl & BNX2X_FLOW_CTRL_RX ||
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002535 line_speed == SPEED_10 ||
2536 line_speed == SPEED_100 ||
2537 line_speed == SPEED_1000 ||
2538 line_speed == SPEED_2500) {
2539 REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 1);
Yuval Mintzd2310232012-06-20 19:05:19 +00002540 /* Update threshold */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002541 REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, 0);
Yuval Mintzd2310232012-06-20 19:05:19 +00002542 /* Update init credit */
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002543 init_crd = 778; /* (800-18-4) */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002544
2545 } else {
2546 u32 thresh = (ETH_MAX_JUMBO_PACKET_SIZE +
2547 ETH_OVREHEAD)/16;
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07002548 REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
Yuval Mintzd2310232012-06-20 19:05:19 +00002549 /* Update threshold */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002550 REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, thresh);
Yuval Mintzd2310232012-06-20 19:05:19 +00002551 /* Update init credit */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002552 switch (line_speed) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002553 case SPEED_10000:
2554 init_crd = thresh + 553 - 22;
2555 break;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002556 default:
2557 DP(NETIF_MSG_LINK, "Invalid line_speed 0x%x\n",
2558 line_speed);
2559 return -EINVAL;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002560 }
2561 }
2562 REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, init_crd);
2563 DP(NETIF_MSG_LINK, "PBF updated to speed %d credit %d\n",
2564 line_speed, init_crd);
2565
Yuval Mintzd2310232012-06-20 19:05:19 +00002566 /* Probe the credit changes */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002567 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0x1);
Yuval Mintzd2310232012-06-20 19:05:19 +00002568 usleep_range(5000, 10000);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002569 REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0x0);
2570
Yuval Mintzd2310232012-06-20 19:05:19 +00002571 /* Enable port */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002572 REG_WR(bp, PBF_REG_DISABLE_NEW_TASK_PROC_P0 + port*4, 0x0);
2573 return 0;
2574}
2575
Dmitry Kravkove8920672011-05-04 23:52:40 +00002576/**
2577 * bnx2x_get_emac_base - retrive emac base address
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002578 *
Dmitry Kravkove8920672011-05-04 23:52:40 +00002579 * @bp: driver handle
2580 * @mdc_mdio_access: access type
2581 * @port: port id
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002582 *
2583 * This function selects the MDC/MDIO access (through emac0 or
2584 * emac1) depend on the mdc_mdio_access, port, port swapped. Each
2585 * phy has a default access mode, which could also be overridden
2586 * by nvram configuration. This parameter, whether this is the
2587 * default phy configuration, or the nvram overrun
2588 * configuration, is passed here as mdc_mdio_access and selects
2589 * the emac_base for the CL45 read/writes operations
2590 */
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00002591static u32 bnx2x_get_emac_base(struct bnx2x *bp,
2592 u32 mdc_mdio_access, u8 port)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002593{
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00002594 u32 emac_base = 0;
2595 switch (mdc_mdio_access) {
2596 case SHARED_HW_CFG_MDC_MDIO_ACCESS1_PHY_TYPE:
2597 break;
2598 case SHARED_HW_CFG_MDC_MDIO_ACCESS1_EMAC0:
2599 if (REG_RD(bp, NIG_REG_PORT_SWAP))
2600 emac_base = GRCBASE_EMAC1;
2601 else
2602 emac_base = GRCBASE_EMAC0;
2603 break;
2604 case SHARED_HW_CFG_MDC_MDIO_ACCESS1_EMAC1:
Eilon Greenstein589abe32009-02-12 08:36:55 +00002605 if (REG_RD(bp, NIG_REG_PORT_SWAP))
2606 emac_base = GRCBASE_EMAC0;
2607 else
2608 emac_base = GRCBASE_EMAC1;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002609 break;
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00002610 case SHARED_HW_CFG_MDC_MDIO_ACCESS1_BOTH:
2611 emac_base = (port) ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
2612 break;
2613 case SHARED_HW_CFG_MDC_MDIO_ACCESS1_SWAPPED:
Eilon Greenstein6378c022008-08-13 15:59:25 -07002614 emac_base = (port) ? GRCBASE_EMAC0 : GRCBASE_EMAC1;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002615 break;
2616 default:
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002617 break;
2618 }
2619 return emac_base;
2620
2621}
2622
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002623/******************************************************************/
Yaniv Rosner6583e332011-06-14 01:34:17 +00002624/* CL22 access functions */
2625/******************************************************************/
2626static int bnx2x_cl22_write(struct bnx2x *bp,
2627 struct bnx2x_phy *phy,
2628 u16 reg, u16 val)
2629{
2630 u32 tmp, mode;
2631 u8 i;
2632 int rc = 0;
2633 /* Switch to CL22 */
2634 mode = REG_RD(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE);
2635 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE,
2636 mode & ~EMAC_MDIO_MODE_CLAUSE_45);
2637
Yuval Mintzd2310232012-06-20 19:05:19 +00002638 /* Address */
Yaniv Rosner6583e332011-06-14 01:34:17 +00002639 tmp = ((phy->addr << 21) | (reg << 16) | val |
2640 EMAC_MDIO_COMM_COMMAND_WRITE_22 |
2641 EMAC_MDIO_COMM_START_BUSY);
2642 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, tmp);
2643
2644 for (i = 0; i < 50; i++) {
2645 udelay(10);
2646
2647 tmp = REG_RD(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM);
2648 if (!(tmp & EMAC_MDIO_COMM_START_BUSY)) {
2649 udelay(5);
2650 break;
2651 }
2652 }
2653 if (tmp & EMAC_MDIO_COMM_START_BUSY) {
2654 DP(NETIF_MSG_LINK, "write phy register failed\n");
2655 rc = -EFAULT;
2656 }
2657 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE, mode);
2658 return rc;
2659}
2660
2661static int bnx2x_cl22_read(struct bnx2x *bp,
2662 struct bnx2x_phy *phy,
2663 u16 reg, u16 *ret_val)
2664{
2665 u32 val, mode;
2666 u16 i;
2667 int rc = 0;
2668
2669 /* Switch to CL22 */
2670 mode = REG_RD(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE);
2671 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE,
2672 mode & ~EMAC_MDIO_MODE_CLAUSE_45);
2673
Yuval Mintzd2310232012-06-20 19:05:19 +00002674 /* Address */
Yaniv Rosner6583e332011-06-14 01:34:17 +00002675 val = ((phy->addr << 21) | (reg << 16) |
2676 EMAC_MDIO_COMM_COMMAND_READ_22 |
2677 EMAC_MDIO_COMM_START_BUSY);
2678 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, val);
2679
2680 for (i = 0; i < 50; i++) {
2681 udelay(10);
2682
2683 val = REG_RD(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM);
2684 if (!(val & EMAC_MDIO_COMM_START_BUSY)) {
2685 *ret_val = (u16)(val & EMAC_MDIO_COMM_DATA);
2686 udelay(5);
2687 break;
2688 }
2689 }
2690 if (val & EMAC_MDIO_COMM_START_BUSY) {
2691 DP(NETIF_MSG_LINK, "read phy register failed\n");
2692
2693 *ret_val = 0;
2694 rc = -EFAULT;
2695 }
2696 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE, mode);
2697 return rc;
2698}
2699
2700/******************************************************************/
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00002701/* CL45 access functions */
2702/******************************************************************/
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00002703static int bnx2x_cl45_read(struct bnx2x *bp, struct bnx2x_phy *phy,
2704 u8 devad, u16 reg, u16 *ret_val)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002705{
Yaniv Rosnera198c142011-05-31 21:29:42 +00002706 u32 val;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002707 u16 i;
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00002708 int rc = 0;
Yaniv Rosner55386fe82012-11-27 03:46:30 +00002709 u32 chip_id;
2710 if (phy->flags & FLAGS_MDC_MDIO_WA_G) {
2711 chip_id = (REG_RD(bp, MISC_REG_CHIP_NUM) << 16) |
2712 ((REG_RD(bp, MISC_REG_CHIP_REV) & 0xf) << 12);
2713 bnx2x_set_mdio_clk(bp, chip_id, phy->mdio_ctrl);
2714 }
2715
Yaniv Rosner157fa282011-08-02 22:59:32 +00002716 if (phy->flags & FLAGS_MDC_MDIO_WA_B0)
2717 bnx2x_bits_en(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_STATUS,
2718 EMAC_MDIO_STATUS_10MB);
Yuval Mintzd2310232012-06-20 19:05:19 +00002719 /* Address */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002720 val = ((phy->addr << 21) | (devad << 16) | reg |
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002721 EMAC_MDIO_COMM_COMMAND_ADDRESS |
2722 EMAC_MDIO_COMM_START_BUSY);
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002723 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002724
2725 for (i = 0; i < 50; i++) {
2726 udelay(10);
2727
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002728 val = REG_RD(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002729 if (!(val & EMAC_MDIO_COMM_START_BUSY)) {
2730 udelay(5);
2731 break;
2732 }
2733 }
2734 if (val & EMAC_MDIO_COMM_START_BUSY) {
2735 DP(NETIF_MSG_LINK, "read phy register failed\n");
Yaniv Rosner6d870c32011-01-31 04:22:20 +00002736 netdev_err(bp->dev, "MDC/MDIO access timeout\n");
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002737 *ret_val = 0;
2738 rc = -EFAULT;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002739 } else {
Yuval Mintzd2310232012-06-20 19:05:19 +00002740 /* Data */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002741 val = ((phy->addr << 21) | (devad << 16) |
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002742 EMAC_MDIO_COMM_COMMAND_READ_45 |
2743 EMAC_MDIO_COMM_START_BUSY);
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002744 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002745
2746 for (i = 0; i < 50; i++) {
2747 udelay(10);
2748
Yaniv Rosnere10bc842010-09-07 11:40:50 +00002749 val = REG_RD(bp, phy->mdio_ctrl +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00002750 EMAC_REG_EMAC_MDIO_COMM);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002751 if (!(val & EMAC_MDIO_COMM_START_BUSY)) {
2752 *ret_val = (u16)(val & EMAC_MDIO_COMM_DATA);
2753 break;
2754 }
2755 }
2756 if (val & EMAC_MDIO_COMM_START_BUSY) {
2757 DP(NETIF_MSG_LINK, "read phy register failed\n");
Yaniv Rosner6d870c32011-01-31 04:22:20 +00002758 netdev_err(bp->dev, "MDC/MDIO access timeout\n");
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002759 *ret_val = 0;
2760 rc = -EFAULT;
2761 }
2762 }
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00002763 /* Work around for E3 A0 */
2764 if (phy->flags & FLAGS_MDC_MDIO_WA) {
2765 phy->flags ^= FLAGS_DUMMY_READ;
2766 if (phy->flags & FLAGS_DUMMY_READ) {
2767 u16 temp_val;
2768 bnx2x_cl45_read(bp, phy, devad, 0xf, &temp_val);
2769 }
2770 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002771
Yaniv Rosner157fa282011-08-02 22:59:32 +00002772 if (phy->flags & FLAGS_MDC_MDIO_WA_B0)
2773 bnx2x_bits_dis(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_STATUS,
2774 EMAC_MDIO_STATUS_10MB);
Yaniv Rosnera198c142011-05-31 21:29:42 +00002775 return rc;
2776}
2777
2778static int bnx2x_cl45_write(struct bnx2x *bp, struct bnx2x_phy *phy,
2779 u8 devad, u16 reg, u16 val)
2780{
2781 u32 tmp;
2782 u8 i;
2783 int rc = 0;
Yaniv Rosner55386fe82012-11-27 03:46:30 +00002784 u32 chip_id;
2785 if (phy->flags & FLAGS_MDC_MDIO_WA_G) {
2786 chip_id = (REG_RD(bp, MISC_REG_CHIP_NUM) << 16) |
2787 ((REG_RD(bp, MISC_REG_CHIP_REV) & 0xf) << 12);
2788 bnx2x_set_mdio_clk(bp, chip_id, phy->mdio_ctrl);
2789 }
2790
Yaniv Rosner157fa282011-08-02 22:59:32 +00002791 if (phy->flags & FLAGS_MDC_MDIO_WA_B0)
2792 bnx2x_bits_en(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_STATUS,
2793 EMAC_MDIO_STATUS_10MB);
Yaniv Rosnera198c142011-05-31 21:29:42 +00002794
Yuval Mintzd2310232012-06-20 19:05:19 +00002795 /* Address */
Yaniv Rosnera198c142011-05-31 21:29:42 +00002796 tmp = ((phy->addr << 21) | (devad << 16) | reg |
2797 EMAC_MDIO_COMM_COMMAND_ADDRESS |
2798 EMAC_MDIO_COMM_START_BUSY);
2799 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, tmp);
2800
2801 for (i = 0; i < 50; i++) {
2802 udelay(10);
2803
2804 tmp = REG_RD(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM);
2805 if (!(tmp & EMAC_MDIO_COMM_START_BUSY)) {
2806 udelay(5);
2807 break;
2808 }
2809 }
2810 if (tmp & EMAC_MDIO_COMM_START_BUSY) {
2811 DP(NETIF_MSG_LINK, "write phy register failed\n");
2812 netdev_err(bp->dev, "MDC/MDIO access timeout\n");
2813 rc = -EFAULT;
Yaniv Rosnera198c142011-05-31 21:29:42 +00002814 } else {
Yuval Mintzd2310232012-06-20 19:05:19 +00002815 /* Data */
Yaniv Rosnera198c142011-05-31 21:29:42 +00002816 tmp = ((phy->addr << 21) | (devad << 16) | val |
2817 EMAC_MDIO_COMM_COMMAND_WRITE_45 |
2818 EMAC_MDIO_COMM_START_BUSY);
2819 REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, tmp);
2820
2821 for (i = 0; i < 50; i++) {
2822 udelay(10);
2823
2824 tmp = REG_RD(bp, phy->mdio_ctrl +
2825 EMAC_REG_EMAC_MDIO_COMM);
2826 if (!(tmp & EMAC_MDIO_COMM_START_BUSY)) {
2827 udelay(5);
2828 break;
2829 }
2830 }
2831 if (tmp & EMAC_MDIO_COMM_START_BUSY) {
2832 DP(NETIF_MSG_LINK, "write phy register failed\n");
2833 netdev_err(bp->dev, "MDC/MDIO access timeout\n");
2834 rc = -EFAULT;
2835 }
2836 }
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00002837 /* Work around for E3 A0 */
2838 if (phy->flags & FLAGS_MDC_MDIO_WA) {
2839 phy->flags ^= FLAGS_DUMMY_READ;
2840 if (phy->flags & FLAGS_DUMMY_READ) {
2841 u16 temp_val;
2842 bnx2x_cl45_read(bp, phy, devad, 0xf, &temp_val);
2843 }
2844 }
Yaniv Rosner157fa282011-08-02 22:59:32 +00002845 if (phy->flags & FLAGS_MDC_MDIO_WA_B0)
2846 bnx2x_bits_dis(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_STATUS,
2847 EMAC_MDIO_STATUS_10MB);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07002848 return rc;
2849}
Yuval Mintzec4010e2012-09-10 05:51:06 +00002850
2851/******************************************************************/
2852/* EEE section */
2853/******************************************************************/
2854static u8 bnx2x_eee_has_cap(struct link_params *params)
2855{
2856 struct bnx2x *bp = params->bp;
2857
2858 if (REG_RD(bp, params->shmem2_base) <=
2859 offsetof(struct shmem2_region, eee_status[params->port]))
2860 return 0;
2861
2862 return 1;
2863}
2864
2865static int bnx2x_eee_nvram_to_time(u32 nvram_mode, u32 *idle_timer)
2866{
2867 switch (nvram_mode) {
2868 case PORT_FEAT_CFG_EEE_POWER_MODE_BALANCED:
2869 *idle_timer = EEE_MODE_NVRAM_BALANCED_TIME;
2870 break;
2871 case PORT_FEAT_CFG_EEE_POWER_MODE_AGGRESSIVE:
2872 *idle_timer = EEE_MODE_NVRAM_AGGRESSIVE_TIME;
2873 break;
2874 case PORT_FEAT_CFG_EEE_POWER_MODE_LOW_LATENCY:
2875 *idle_timer = EEE_MODE_NVRAM_LATENCY_TIME;
2876 break;
2877 default:
2878 *idle_timer = 0;
2879 break;
2880 }
2881
2882 return 0;
2883}
2884
2885static int bnx2x_eee_time_to_nvram(u32 idle_timer, u32 *nvram_mode)
2886{
2887 switch (idle_timer) {
2888 case EEE_MODE_NVRAM_BALANCED_TIME:
2889 *nvram_mode = PORT_FEAT_CFG_EEE_POWER_MODE_BALANCED;
2890 break;
2891 case EEE_MODE_NVRAM_AGGRESSIVE_TIME:
2892 *nvram_mode = PORT_FEAT_CFG_EEE_POWER_MODE_AGGRESSIVE;
2893 break;
2894 case EEE_MODE_NVRAM_LATENCY_TIME:
2895 *nvram_mode = PORT_FEAT_CFG_EEE_POWER_MODE_LOW_LATENCY;
2896 break;
2897 default:
2898 *nvram_mode = PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED;
2899 break;
2900 }
2901
2902 return 0;
2903}
2904
2905static u32 bnx2x_eee_calc_timer(struct link_params *params)
2906{
2907 u32 eee_mode, eee_idle;
2908 struct bnx2x *bp = params->bp;
2909
2910 if (params->eee_mode & EEE_MODE_OVERRIDE_NVRAM) {
2911 if (params->eee_mode & EEE_MODE_OUTPUT_TIME) {
2912 /* time value in eee_mode --> used directly*/
2913 eee_idle = params->eee_mode & EEE_MODE_TIMER_MASK;
2914 } else {
2915 /* hsi value in eee_mode --> time */
2916 if (bnx2x_eee_nvram_to_time(params->eee_mode &
2917 EEE_MODE_NVRAM_MASK,
2918 &eee_idle))
2919 return 0;
2920 }
2921 } else {
2922 /* hsi values in nvram --> time*/
2923 eee_mode = ((REG_RD(bp, params->shmem_base +
2924 offsetof(struct shmem_region, dev_info.
2925 port_feature_config[params->port].
2926 eee_power_mode)) &
2927 PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >>
2928 PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT);
2929
2930 if (bnx2x_eee_nvram_to_time(eee_mode, &eee_idle))
2931 return 0;
2932 }
2933
2934 return eee_idle;
2935}
2936
2937static int bnx2x_eee_set_timers(struct link_params *params,
2938 struct link_vars *vars)
2939{
2940 u32 eee_idle = 0, eee_mode;
2941 struct bnx2x *bp = params->bp;
2942
2943 eee_idle = bnx2x_eee_calc_timer(params);
2944
2945 if (eee_idle) {
2946 REG_WR(bp, MISC_REG_CPMU_LP_IDLE_THR_P0 + (params->port << 2),
2947 eee_idle);
2948 } else if ((params->eee_mode & EEE_MODE_ENABLE_LPI) &&
2949 (params->eee_mode & EEE_MODE_OVERRIDE_NVRAM) &&
2950 (params->eee_mode & EEE_MODE_OUTPUT_TIME)) {
2951 DP(NETIF_MSG_LINK, "Error: Tx LPI is enabled with timer 0\n");
2952 return -EINVAL;
2953 }
2954
2955 vars->eee_status &= ~(SHMEM_EEE_TIMER_MASK | SHMEM_EEE_TIME_OUTPUT_BIT);
2956 if (params->eee_mode & EEE_MODE_OUTPUT_TIME) {
2957 /* eee_idle in 1u --> eee_status in 16u */
2958 eee_idle >>= 4;
2959 vars->eee_status |= (eee_idle & SHMEM_EEE_TIMER_MASK) |
2960 SHMEM_EEE_TIME_OUTPUT_BIT;
2961 } else {
2962 if (bnx2x_eee_time_to_nvram(eee_idle, &eee_mode))
2963 return -EINVAL;
2964 vars->eee_status |= eee_mode;
2965 }
2966
2967 return 0;
2968}
2969
2970static int bnx2x_eee_initial_config(struct link_params *params,
2971 struct link_vars *vars, u8 mode)
2972{
2973 vars->eee_status |= ((u32) mode) << SHMEM_EEE_SUPPORTED_SHIFT;
2974
2975 /* Propogate params' bits --> vars (for migration exposure) */
2976 if (params->eee_mode & EEE_MODE_ENABLE_LPI)
2977 vars->eee_status |= SHMEM_EEE_LPI_REQUESTED_BIT;
2978 else
2979 vars->eee_status &= ~SHMEM_EEE_LPI_REQUESTED_BIT;
2980
2981 if (params->eee_mode & EEE_MODE_ADV_LPI)
2982 vars->eee_status |= SHMEM_EEE_REQUESTED_BIT;
2983 else
2984 vars->eee_status &= ~SHMEM_EEE_REQUESTED_BIT;
2985
2986 return bnx2x_eee_set_timers(params, vars);
2987}
2988
2989static int bnx2x_eee_disable(struct bnx2x_phy *phy,
2990 struct link_params *params,
2991 struct link_vars *vars)
2992{
2993 struct bnx2x *bp = params->bp;
2994
2995 /* Make Certain LPI is disabled */
2996 REG_WR(bp, MISC_REG_CPMU_LP_FW_ENABLE_P0 + (params->port << 2), 0);
2997
2998 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_EEE_ADV, 0x0);
2999
3000 vars->eee_status &= ~SHMEM_EEE_ADV_STATUS_MASK;
3001
3002 return 0;
3003}
3004
3005static int bnx2x_eee_advertise(struct bnx2x_phy *phy,
3006 struct link_params *params,
3007 struct link_vars *vars, u8 modes)
3008{
3009 struct bnx2x *bp = params->bp;
3010 u16 val = 0;
3011
3012 /* Mask events preventing LPI generation */
3013 REG_WR(bp, MISC_REG_CPMU_LP_MASK_EXT_P0 + (params->port << 2), 0xfc20);
3014
3015 if (modes & SHMEM_EEE_10G_ADV) {
3016 DP(NETIF_MSG_LINK, "Advertise 10GBase-T EEE\n");
3017 val |= 0x8;
3018 }
3019 if (modes & SHMEM_EEE_1G_ADV) {
3020 DP(NETIF_MSG_LINK, "Advertise 1GBase-T EEE\n");
3021 val |= 0x4;
3022 }
3023
3024 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_EEE_ADV, val);
3025
3026 vars->eee_status &= ~SHMEM_EEE_ADV_STATUS_MASK;
3027 vars->eee_status |= (modes << SHMEM_EEE_ADV_STATUS_SHIFT);
3028
3029 return 0;
3030}
3031
3032static void bnx2x_update_mng_eee(struct link_params *params, u32 eee_status)
3033{
3034 struct bnx2x *bp = params->bp;
3035
3036 if (bnx2x_eee_has_cap(params))
3037 REG_WR(bp, params->shmem2_base +
3038 offsetof(struct shmem2_region,
3039 eee_status[params->port]), eee_status);
3040}
3041
3042static void bnx2x_eee_an_resolve(struct bnx2x_phy *phy,
3043 struct link_params *params,
3044 struct link_vars *vars)
3045{
3046 struct bnx2x *bp = params->bp;
3047 u16 adv = 0, lp = 0;
3048 u32 lp_adv = 0;
3049 u8 neg = 0;
3050
3051 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_EEE_ADV, &adv);
3052 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_LP_EEE_ADV, &lp);
3053
3054 if (lp & 0x2) {
3055 lp_adv |= SHMEM_EEE_100M_ADV;
3056 if (adv & 0x2) {
3057 if (vars->line_speed == SPEED_100)
3058 neg = 1;
3059 DP(NETIF_MSG_LINK, "EEE negotiated - 100M\n");
3060 }
3061 }
3062 if (lp & 0x14) {
3063 lp_adv |= SHMEM_EEE_1G_ADV;
3064 if (adv & 0x14) {
3065 if (vars->line_speed == SPEED_1000)
3066 neg = 1;
3067 DP(NETIF_MSG_LINK, "EEE negotiated - 1G\n");
3068 }
3069 }
3070 if (lp & 0x68) {
3071 lp_adv |= SHMEM_EEE_10G_ADV;
3072 if (adv & 0x68) {
3073 if (vars->line_speed == SPEED_10000)
3074 neg = 1;
3075 DP(NETIF_MSG_LINK, "EEE negotiated - 10G\n");
3076 }
3077 }
3078
3079 vars->eee_status &= ~SHMEM_EEE_LP_ADV_STATUS_MASK;
3080 vars->eee_status |= (lp_adv << SHMEM_EEE_LP_ADV_STATUS_SHIFT);
3081
3082 if (neg) {
3083 DP(NETIF_MSG_LINK, "EEE is active\n");
3084 vars->eee_status |= SHMEM_EEE_ACTIVE_BIT;
3085 }
3086
3087}
3088
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003089/******************************************************************/
3090/* BSC access functions from E3 */
3091/******************************************************************/
3092static void bnx2x_bsc_module_sel(struct link_params *params)
3093{
3094 int idx;
3095 u32 board_cfg, sfp_ctrl;
3096 u32 i2c_pins[I2C_SWITCH_WIDTH], i2c_val[I2C_SWITCH_WIDTH];
3097 struct bnx2x *bp = params->bp;
3098 u8 port = params->port;
3099 /* Read I2C output PINs */
3100 board_cfg = REG_RD(bp, params->shmem_base +
3101 offsetof(struct shmem_region,
3102 dev_info.shared_hw_config.board));
3103 i2c_pins[I2C_BSC0] = board_cfg & SHARED_HW_CFG_E3_I2C_MUX0_MASK;
3104 i2c_pins[I2C_BSC1] = (board_cfg & SHARED_HW_CFG_E3_I2C_MUX1_MASK) >>
3105 SHARED_HW_CFG_E3_I2C_MUX1_SHIFT;
3106
3107 /* Read I2C output value */
3108 sfp_ctrl = REG_RD(bp, params->shmem_base +
3109 offsetof(struct shmem_region,
3110 dev_info.port_hw_config[port].e3_cmn_pin_cfg));
3111 i2c_val[I2C_BSC0] = (sfp_ctrl & PORT_HW_CFG_E3_I2C_MUX0_MASK) > 0;
3112 i2c_val[I2C_BSC1] = (sfp_ctrl & PORT_HW_CFG_E3_I2C_MUX1_MASK) > 0;
3113 DP(NETIF_MSG_LINK, "Setting BSC switch\n");
3114 for (idx = 0; idx < I2C_SWITCH_WIDTH; idx++)
3115 bnx2x_set_cfg_pin(bp, i2c_pins[idx], i2c_val[idx]);
3116}
3117
3118static int bnx2x_bsc_read(struct link_params *params,
3119 struct bnx2x_phy *phy,
3120 u8 sl_devid,
3121 u16 sl_addr,
3122 u8 lc_addr,
3123 u8 xfer_cnt,
3124 u32 *data_array)
3125{
3126 u32 val, i;
3127 int rc = 0;
3128 struct bnx2x *bp = params->bp;
3129
3130 if ((sl_devid != 0xa0) && (sl_devid != 0xa2)) {
3131 DP(NETIF_MSG_LINK, "invalid sl_devid 0x%x\n", sl_devid);
3132 return -EINVAL;
3133 }
3134
3135 if (xfer_cnt > 16) {
3136 DP(NETIF_MSG_LINK, "invalid xfer_cnt %d. Max is 16 bytes\n",
3137 xfer_cnt);
3138 return -EINVAL;
3139 }
3140 bnx2x_bsc_module_sel(params);
3141
3142 xfer_cnt = 16 - lc_addr;
3143
Yuval Mintzd2310232012-06-20 19:05:19 +00003144 /* Enable the engine */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003145 val = REG_RD(bp, MCP_REG_MCPR_IMC_COMMAND);
3146 val |= MCPR_IMC_COMMAND_ENABLE;
3147 REG_WR(bp, MCP_REG_MCPR_IMC_COMMAND, val);
3148
Yuval Mintzd2310232012-06-20 19:05:19 +00003149 /* Program slave device ID */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003150 val = (sl_devid << 16) | sl_addr;
3151 REG_WR(bp, MCP_REG_MCPR_IMC_SLAVE_CONTROL, val);
3152
Yuval Mintzd2310232012-06-20 19:05:19 +00003153 /* Start xfer with 0 byte to update the address pointer ???*/
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003154 val = (MCPR_IMC_COMMAND_ENABLE) |
3155 (MCPR_IMC_COMMAND_WRITE_OP <<
3156 MCPR_IMC_COMMAND_OPERATION_BITSHIFT) |
3157 (lc_addr << MCPR_IMC_COMMAND_TRANSFER_ADDRESS_BITSHIFT) | (0);
3158 REG_WR(bp, MCP_REG_MCPR_IMC_COMMAND, val);
3159
Yuval Mintzd2310232012-06-20 19:05:19 +00003160 /* Poll for completion */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003161 i = 0;
3162 val = REG_RD(bp, MCP_REG_MCPR_IMC_COMMAND);
3163 while (((val >> MCPR_IMC_COMMAND_IMC_STATUS_BITSHIFT) & 0x3) != 1) {
3164 udelay(10);
3165 val = REG_RD(bp, MCP_REG_MCPR_IMC_COMMAND);
3166 if (i++ > 1000) {
3167 DP(NETIF_MSG_LINK, "wr 0 byte timed out after %d try\n",
3168 i);
3169 rc = -EFAULT;
3170 break;
3171 }
3172 }
3173 if (rc == -EFAULT)
3174 return rc;
3175
Yuval Mintzd2310232012-06-20 19:05:19 +00003176 /* Start xfer with read op */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003177 val = (MCPR_IMC_COMMAND_ENABLE) |
3178 (MCPR_IMC_COMMAND_READ_OP <<
3179 MCPR_IMC_COMMAND_OPERATION_BITSHIFT) |
3180 (lc_addr << MCPR_IMC_COMMAND_TRANSFER_ADDRESS_BITSHIFT) |
3181 (xfer_cnt);
3182 REG_WR(bp, MCP_REG_MCPR_IMC_COMMAND, val);
3183
Yuval Mintzd2310232012-06-20 19:05:19 +00003184 /* Poll for completion */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003185 i = 0;
3186 val = REG_RD(bp, MCP_REG_MCPR_IMC_COMMAND);
3187 while (((val >> MCPR_IMC_COMMAND_IMC_STATUS_BITSHIFT) & 0x3) != 1) {
3188 udelay(10);
3189 val = REG_RD(bp, MCP_REG_MCPR_IMC_COMMAND);
3190 if (i++ > 1000) {
3191 DP(NETIF_MSG_LINK, "rd op timed out after %d try\n", i);
3192 rc = -EFAULT;
3193 break;
3194 }
3195 }
3196 if (rc == -EFAULT)
3197 return rc;
3198
3199 for (i = (lc_addr >> 2); i < 4; i++) {
3200 data_array[i] = REG_RD(bp, (MCP_REG_MCPR_IMC_DATAREG0 + i*4));
3201#ifdef __BIG_ENDIAN
3202 data_array[i] = ((data_array[i] & 0x000000ff) << 24) |
3203 ((data_array[i] & 0x0000ff00) << 8) |
3204 ((data_array[i] & 0x00ff0000) >> 8) |
3205 ((data_array[i] & 0xff000000) >> 24);
3206#endif
3207 }
3208 return rc;
3209}
3210
3211static void bnx2x_cl45_read_or_write(struct bnx2x *bp, struct bnx2x_phy *phy,
3212 u8 devad, u16 reg, u16 or_val)
3213{
3214 u16 val;
3215 bnx2x_cl45_read(bp, phy, devad, reg, &val);
3216 bnx2x_cl45_write(bp, phy, devad, reg, val | or_val);
3217}
3218
Yaniv Rosner4e7b4992012-11-27 03:46:29 +00003219static void bnx2x_cl45_read_and_write(struct bnx2x *bp,
3220 struct bnx2x_phy *phy,
3221 u8 devad, u16 reg, u16 and_val)
3222{
3223 u16 val;
3224 bnx2x_cl45_read(bp, phy, devad, reg, &val);
3225 bnx2x_cl45_write(bp, phy, devad, reg, val & and_val);
3226}
3227
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00003228int bnx2x_phy_read(struct link_params *params, u8 phy_addr,
3229 u8 devad, u16 reg, u16 *ret_val)
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003230{
3231 u8 phy_index;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00003232 /* Probe for the phy according to the given phy_addr, and execute
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003233 * the read request on it
3234 */
3235 for (phy_index = 0; phy_index < params->num_phys; phy_index++) {
3236 if (params->phy[phy_index].addr == phy_addr) {
3237 return bnx2x_cl45_read(params->bp,
3238 &params->phy[phy_index], devad,
3239 reg, ret_val);
3240 }
3241 }
3242 return -EINVAL;
3243}
3244
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00003245int bnx2x_phy_write(struct link_params *params, u8 phy_addr,
3246 u8 devad, u16 reg, u16 val)
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003247{
3248 u8 phy_index;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00003249 /* Probe for the phy according to the given phy_addr, and execute
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003250 * the write request on it
3251 */
3252 for (phy_index = 0; phy_index < params->num_phys; phy_index++) {
3253 if (params->phy[phy_index].addr == phy_addr) {
3254 return bnx2x_cl45_write(params->bp,
3255 &params->phy[phy_index], devad,
3256 reg, val);
3257 }
3258 }
3259 return -EINVAL;
3260}
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003261static u8 bnx2x_get_warpcore_lane(struct bnx2x_phy *phy,
3262 struct link_params *params)
3263{
3264 u8 lane = 0;
3265 struct bnx2x *bp = params->bp;
3266 u32 path_swap, path_swap_ovr;
3267 u8 path, port;
3268
3269 path = BP_PATH(bp);
3270 port = params->port;
3271
3272 if (bnx2x_is_4_port_mode(bp)) {
3273 u32 port_swap, port_swap_ovr;
3274
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00003275 /* Figure out path swap value */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003276 path_swap_ovr = REG_RD(bp, MISC_REG_FOUR_PORT_PATH_SWAP_OVWR);
3277 if (path_swap_ovr & 0x1)
3278 path_swap = (path_swap_ovr & 0x2);
3279 else
3280 path_swap = REG_RD(bp, MISC_REG_FOUR_PORT_PATH_SWAP);
3281
3282 if (path_swap)
3283 path = path ^ 1;
3284
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00003285 /* Figure out port swap value */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003286 port_swap_ovr = REG_RD(bp, MISC_REG_FOUR_PORT_PORT_SWAP_OVWR);
3287 if (port_swap_ovr & 0x1)
3288 port_swap = (port_swap_ovr & 0x2);
3289 else
3290 port_swap = REG_RD(bp, MISC_REG_FOUR_PORT_PORT_SWAP);
3291
3292 if (port_swap)
3293 port = port ^ 1;
3294
3295 lane = (port<<1) + path;
Yuval Mintzd2310232012-06-20 19:05:19 +00003296 } else { /* Two port mode - no port swap */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003297
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00003298 /* Figure out path swap value */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003299 path_swap_ovr =
3300 REG_RD(bp, MISC_REG_TWO_PORT_PATH_SWAP_OVWR);
3301 if (path_swap_ovr & 0x1) {
3302 path_swap = (path_swap_ovr & 0x2);
3303 } else {
3304 path_swap =
3305 REG_RD(bp, MISC_REG_TWO_PORT_PATH_SWAP);
3306 }
3307 if (path_swap)
3308 path = path ^ 1;
3309
3310 lane = path << 1 ;
3311 }
3312 return lane;
3313}
Yaniv Rosnere10bc842010-09-07 11:40:50 +00003314
Yaniv Rosnerec146a62011-05-31 21:29:27 +00003315static void bnx2x_set_aer_mmd(struct link_params *params,
3316 struct bnx2x_phy *phy)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003317{
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003318 u32 ser_lane;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00003319 u16 offset, aer_val;
3320 struct bnx2x *bp = params->bp;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003321 ser_lane = ((params->lane_config &
3322 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_MASK) >>
3323 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_SHIFT);
3324
Yaniv Rosnerec146a62011-05-31 21:29:27 +00003325 offset = (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT) ?
3326 (phy->addr + ser_lane) : 0;
3327
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003328 if (USES_WARPCORE(bp)) {
3329 aer_val = bnx2x_get_warpcore_lane(phy, params);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00003330 /* In Dual-lane mode, two lanes are joined together,
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003331 * so in order to configure them, the AER broadcast method is
3332 * used here.
3333 * 0x200 is the broadcast address for lanes 0,1
3334 * 0x201 is the broadcast address for lanes 2,3
3335 */
3336 if (phy->flags & FLAGS_WC_DUAL_MODE)
3337 aer_val = (aer_val >> 1) | 0x200;
3338 } else if (CHIP_IS_E2(bp))
Yaniv Rosner82a0d472011-01-18 04:33:52 +00003339 aer_val = 0x3800 + offset - 1;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00003340 else
3341 aer_val = 0x3800 + offset;
Yaniv Rosner2f751a82011-11-28 00:49:52 +00003342
Yaniv Rosnercd2be892011-01-31 04:21:45 +00003343 CL22_WR_OVER_CL45(bp, phy, MDIO_REG_BANK_AER_BLOCK,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003344 MDIO_AER_BLOCK_AER_REG, aer_val);
Yaniv Rosnerec146a62011-05-31 21:29:27 +00003345
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07003346}
3347
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003348/******************************************************************/
3349/* Internal phy section */
3350/******************************************************************/
3351
3352static void bnx2x_set_serdes_access(struct bnx2x *bp, u8 port)
3353{
3354 u32 emac_base = (port) ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
3355
3356 /* Set Clause 22 */
3357 REG_WR(bp, NIG_REG_SERDES0_CTRL_MD_ST + port*0x10, 1);
3358 REG_WR(bp, emac_base + EMAC_REG_EMAC_MDIO_COMM, 0x245f8000);
3359 udelay(500);
3360 REG_WR(bp, emac_base + EMAC_REG_EMAC_MDIO_COMM, 0x245d000f);
3361 udelay(500);
3362 /* Set Clause 45 */
3363 REG_WR(bp, NIG_REG_SERDES0_CTRL_MD_ST + port*0x10, 0);
3364}
3365
3366static void bnx2x_serdes_deassert(struct bnx2x *bp, u8 port)
3367{
3368 u32 val;
3369
3370 DP(NETIF_MSG_LINK, "bnx2x_serdes_deassert\n");
3371
3372 val = SERDES_RESET_BITS << (port*16);
3373
Yuval Mintzd2310232012-06-20 19:05:19 +00003374 /* Reset and unreset the SerDes/XGXS */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003375 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_CLEAR, val);
3376 udelay(500);
3377 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_SET, val);
3378
3379 bnx2x_set_serdes_access(bp, port);
3380
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00003381 REG_WR(bp, NIG_REG_SERDES0_CTRL_MD_DEVAD + port*0x10,
3382 DEFAULT_PHY_DEV_ADDR);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003383}
3384
Yaniv Rosnera75bb002012-10-31 05:46:53 +00003385static void bnx2x_xgxs_specific_func(struct bnx2x_phy *phy,
3386 struct link_params *params,
3387 u32 action)
3388{
3389 struct bnx2x *bp = params->bp;
3390 switch (action) {
3391 case PHY_INIT:
3392 /* Set correct devad */
3393 REG_WR(bp, NIG_REG_XGXS0_CTRL_MD_ST + params->port*0x18, 0);
3394 REG_WR(bp, NIG_REG_XGXS0_CTRL_MD_DEVAD + params->port*0x18,
3395 phy->def_md_devad);
3396 break;
3397 }
3398}
3399
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003400static void bnx2x_xgxs_deassert(struct link_params *params)
3401{
3402 struct bnx2x *bp = params->bp;
3403 u8 port;
3404 u32 val;
3405 DP(NETIF_MSG_LINK, "bnx2x_xgxs_deassert\n");
3406 port = params->port;
3407
3408 val = XGXS_RESET_BITS << (port*16);
3409
Yuval Mintzd2310232012-06-20 19:05:19 +00003410 /* Reset and unreset the SerDes/XGXS */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003411 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_CLEAR, val);
3412 udelay(500);
3413 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_SET, val);
Yaniv Rosnera75bb002012-10-31 05:46:53 +00003414 bnx2x_xgxs_specific_func(&params->phy[INT_PHY], params,
3415 PHY_INIT);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00003416}
3417
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00003418static void bnx2x_calc_ieee_aneg_adv(struct bnx2x_phy *phy,
3419 struct link_params *params, u16 *ieee_fc)
3420{
3421 struct bnx2x *bp = params->bp;
3422 *ieee_fc = MDIO_COMBO_IEEE0_AUTO_NEG_ADV_FULL_DUPLEX;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00003423 /* Resolve pause mode and advertisement Please refer to Table
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00003424 * 28B-3 of the 802.3ab-1999 spec
3425 */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00003426
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00003427 switch (phy->req_flow_ctrl) {
3428 case BNX2X_FLOW_CTRL_AUTO:
3429 if (params->req_fc_auto_adv == BNX2X_FLOW_CTRL_BOTH)
3430 *ieee_fc |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH;
3431 else
3432 *ieee_fc |=
3433 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC;
3434 break;
3435
3436 case BNX2X_FLOW_CTRL_TX:
3437 *ieee_fc |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC;
3438 break;
3439
3440 case BNX2X_FLOW_CTRL_RX:
3441 case BNX2X_FLOW_CTRL_BOTH:
3442 *ieee_fc |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH;
3443 break;
3444
3445 case BNX2X_FLOW_CTRL_NONE:
3446 default:
3447 *ieee_fc |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE;
3448 break;
3449 }
3450 DP(NETIF_MSG_LINK, "ieee_fc = 0x%x\n", *ieee_fc);
3451}
3452
3453static void set_phy_vars(struct link_params *params,
3454 struct link_vars *vars)
3455{
3456 struct bnx2x *bp = params->bp;
3457 u8 actual_phy_idx, phy_index, link_cfg_idx;
3458 u8 phy_config_swapped = params->multi_phy_config &
3459 PORT_HW_CFG_PHY_SWAPPED_ENABLED;
3460 for (phy_index = INT_PHY; phy_index < params->num_phys;
3461 phy_index++) {
3462 link_cfg_idx = LINK_CONFIG_IDX(phy_index);
3463 actual_phy_idx = phy_index;
3464 if (phy_config_swapped) {
3465 if (phy_index == EXT_PHY1)
3466 actual_phy_idx = EXT_PHY2;
3467 else if (phy_index == EXT_PHY2)
3468 actual_phy_idx = EXT_PHY1;
3469 }
3470 params->phy[actual_phy_idx].req_flow_ctrl =
3471 params->req_flow_ctrl[link_cfg_idx];
3472
3473 params->phy[actual_phy_idx].req_line_speed =
3474 params->req_line_speed[link_cfg_idx];
3475
3476 params->phy[actual_phy_idx].speed_cap_mask =
3477 params->speed_cap_mask[link_cfg_idx];
3478
3479 params->phy[actual_phy_idx].req_duplex =
3480 params->req_duplex[link_cfg_idx];
3481
3482 if (params->req_line_speed[link_cfg_idx] ==
3483 SPEED_AUTO_NEG)
3484 vars->link_status |= LINK_STATUS_AUTO_NEGOTIATE_ENABLED;
3485
3486 DP(NETIF_MSG_LINK, "req_flow_ctrl %x, req_line_speed %x,"
3487 " speed_cap_mask %x\n",
3488 params->phy[actual_phy_idx].req_flow_ctrl,
3489 params->phy[actual_phy_idx].req_line_speed,
3490 params->phy[actual_phy_idx].speed_cap_mask);
3491 }
3492}
3493
3494static void bnx2x_ext_phy_set_pause(struct link_params *params,
3495 struct bnx2x_phy *phy,
3496 struct link_vars *vars)
3497{
3498 u16 val;
3499 struct bnx2x *bp = params->bp;
Yuval Mintzd2310232012-06-20 19:05:19 +00003500 /* Read modify write pause advertizing */
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00003501 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV_PAUSE, &val);
3502
3503 val &= ~MDIO_AN_REG_ADV_PAUSE_BOTH;
3504
3505 /* Please refer to Table 28B-3 of 802.3ab-1999 spec. */
3506 bnx2x_calc_ieee_aneg_adv(phy, params, &vars->ieee_fc);
3507 if ((vars->ieee_fc &
3508 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC) ==
3509 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC) {
3510 val |= MDIO_AN_REG_ADV_PAUSE_ASYMMETRIC;
3511 }
3512 if ((vars->ieee_fc &
3513 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) ==
3514 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) {
3515 val |= MDIO_AN_REG_ADV_PAUSE_PAUSE;
3516 }
3517 DP(NETIF_MSG_LINK, "Ext phy AN advertize 0x%x\n", val);
3518 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV_PAUSE, val);
3519}
3520
3521static void bnx2x_pause_resolve(struct link_vars *vars, u32 pause_result)
3522{ /* LD LP */
3523 switch (pause_result) { /* ASYM P ASYM P */
3524 case 0xb: /* 1 0 1 1 */
3525 vars->flow_ctrl = BNX2X_FLOW_CTRL_TX;
3526 break;
3527
3528 case 0xe: /* 1 1 1 0 */
3529 vars->flow_ctrl = BNX2X_FLOW_CTRL_RX;
3530 break;
3531
3532 case 0x5: /* 0 1 0 1 */
3533 case 0x7: /* 0 1 1 1 */
3534 case 0xd: /* 1 1 0 1 */
3535 case 0xf: /* 1 1 1 1 */
3536 vars->flow_ctrl = BNX2X_FLOW_CTRL_BOTH;
3537 break;
3538
3539 default:
3540 break;
3541 }
3542 if (pause_result & (1<<0))
3543 vars->link_status |= LINK_STATUS_LINK_PARTNER_SYMMETRIC_PAUSE;
3544 if (pause_result & (1<<1))
3545 vars->link_status |= LINK_STATUS_LINK_PARTNER_ASYMMETRIC_PAUSE;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00003546
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00003547}
3548
Mintz Yuval9e7e8392012-02-15 02:10:24 +00003549static void bnx2x_ext_phy_update_adv_fc(struct bnx2x_phy *phy,
3550 struct link_params *params,
3551 struct link_vars *vars)
3552{
3553 u16 ld_pause; /* local */
3554 u16 lp_pause; /* link partner */
3555 u16 pause_result;
3556 struct bnx2x *bp = params->bp;
3557 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54618SE) {
3558 bnx2x_cl22_read(bp, phy, 0x4, &ld_pause);
3559 bnx2x_cl22_read(bp, phy, 0x5, &lp_pause);
Yaniv Rosnerca05f292012-04-04 01:28:55 +00003560 } else if (CHIP_IS_E3(bp) &&
3561 SINGLE_MEDIA_DIRECT(params)) {
3562 u8 lane = bnx2x_get_warpcore_lane(phy, params);
3563 u16 gp_status, gp_mask;
3564 bnx2x_cl45_read(bp, phy,
3565 MDIO_AN_DEVAD, MDIO_WC_REG_GP2_STATUS_GP_2_4,
3566 &gp_status);
3567 gp_mask = (MDIO_WC_REG_GP2_STATUS_GP_2_4_CL73_AN_CMPL |
3568 MDIO_WC_REG_GP2_STATUS_GP_2_4_CL37_LP_AN_CAP) <<
3569 lane;
3570 if ((gp_status & gp_mask) == gp_mask) {
3571 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
3572 MDIO_AN_REG_ADV_PAUSE, &ld_pause);
3573 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
3574 MDIO_AN_REG_LP_AUTO_NEG, &lp_pause);
3575 } else {
3576 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
3577 MDIO_AN_REG_CL37_FC_LD, &ld_pause);
3578 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
3579 MDIO_AN_REG_CL37_FC_LP, &lp_pause);
3580 ld_pause = ((ld_pause &
3581 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH)
3582 << 3);
3583 lp_pause = ((lp_pause &
3584 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH)
3585 << 3);
3586 }
Mintz Yuval9e7e8392012-02-15 02:10:24 +00003587 } else {
3588 bnx2x_cl45_read(bp, phy,
3589 MDIO_AN_DEVAD,
3590 MDIO_AN_REG_ADV_PAUSE, &ld_pause);
3591 bnx2x_cl45_read(bp, phy,
3592 MDIO_AN_DEVAD,
3593 MDIO_AN_REG_LP_AUTO_NEG, &lp_pause);
3594 }
3595 pause_result = (ld_pause &
3596 MDIO_AN_REG_ADV_PAUSE_MASK) >> 8;
3597 pause_result |= (lp_pause &
3598 MDIO_AN_REG_ADV_PAUSE_MASK) >> 10;
3599 DP(NETIF_MSG_LINK, "Ext PHY pause result 0x%x\n", pause_result);
3600 bnx2x_pause_resolve(vars, pause_result);
3601
3602}
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00003603
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00003604static u8 bnx2x_ext_phy_resolve_fc(struct bnx2x_phy *phy,
3605 struct link_params *params,
3606 struct link_vars *vars)
3607{
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00003608 u8 ret = 0;
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00003609 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
Mintz Yuval9e7e8392012-02-15 02:10:24 +00003610 if (phy->req_flow_ctrl != BNX2X_FLOW_CTRL_AUTO) {
3611 /* Update the advertised flow-controled of LD/LP in AN */
3612 if (phy->req_line_speed == SPEED_AUTO_NEG)
3613 bnx2x_ext_phy_update_adv_fc(phy, params, vars);
3614 /* But set the flow-control result as the requested one */
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00003615 vars->flow_ctrl = phy->req_flow_ctrl;
Mintz Yuval9e7e8392012-02-15 02:10:24 +00003616 } else if (phy->req_line_speed != SPEED_AUTO_NEG)
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00003617 vars->flow_ctrl = params->req_fc_auto_adv;
3618 else if (vars->link_status & LINK_STATUS_AUTO_NEGOTIATE_COMPLETE) {
3619 ret = 1;
Mintz Yuval9e7e8392012-02-15 02:10:24 +00003620 bnx2x_ext_phy_update_adv_fc(phy, params, vars);
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00003621 }
3622 return ret;
3623}
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003624/******************************************************************/
3625/* Warpcore section */
3626/******************************************************************/
3627/* The init_internal_warpcore should mirror the xgxs,
3628 * i.e. reset the lane (if needed), set aer for the
3629 * init configuration, and set/clear SGMII flag. Internal
3630 * phy init is done purely in phy_init stage.
3631 */
Yaniv Rosner4e7b4992012-11-27 03:46:29 +00003632static void bnx2x_warpcore_enable_AN_KR2(struct bnx2x_phy *phy,
3633 struct link_params *params,
3634 struct link_vars *vars)
3635{
3636 struct bnx2x *bp = params->bp;
3637 u16 i;
3638 static struct bnx2x_reg_set reg_set[] = {
3639 /* Step 1 - Program the TX/RX alignment markers */
3640 {MDIO_WC_DEVAD, MDIO_WC_REG_CL82_USERB1_TX_CTRL5, 0xa157},
3641 {MDIO_WC_DEVAD, MDIO_WC_REG_CL82_USERB1_TX_CTRL7, 0xcbe2},
3642 {MDIO_WC_DEVAD, MDIO_WC_REG_CL82_USERB1_TX_CTRL6, 0x7537},
3643 {MDIO_WC_DEVAD, MDIO_WC_REG_CL82_USERB1_TX_CTRL9, 0xa157},
3644 {MDIO_WC_DEVAD, MDIO_WC_REG_CL82_USERB1_RX_CTRL11, 0xcbe2},
3645 {MDIO_WC_DEVAD, MDIO_WC_REG_CL82_USERB1_RX_CTRL10, 0x7537},
3646 /* Step 2 - Configure the NP registers */
3647 {MDIO_WC_DEVAD, MDIO_WC_REG_CL73_USERB0_CTRL, 0x000a},
3648 {MDIO_WC_DEVAD, MDIO_WC_REG_CL73_BAM_CTRL1, 0x6400},
3649 {MDIO_WC_DEVAD, MDIO_WC_REG_CL73_BAM_CTRL3, 0x0620},
3650 {MDIO_WC_DEVAD, MDIO_WC_REG_CL73_BAM_CODE_FIELD, 0x0157},
3651 {MDIO_WC_DEVAD, MDIO_WC_REG_ETA_CL73_OUI1, 0x6464},
3652 {MDIO_WC_DEVAD, MDIO_WC_REG_ETA_CL73_OUI2, 0x3150},
3653 {MDIO_WC_DEVAD, MDIO_WC_REG_ETA_CL73_OUI3, 0x3150},
3654 {MDIO_WC_DEVAD, MDIO_WC_REG_ETA_CL73_LD_BAM_CODE, 0x0157},
3655 {MDIO_WC_DEVAD, MDIO_WC_REG_ETA_CL73_LD_UD_CODE, 0x0620}
3656 };
3657 DP(NETIF_MSG_LINK, "Enabling 20G-KR2\n");
3658
3659 bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
3660 MDIO_WC_REG_CL49_USERB0_CTRL, (3<<6));
3661
Sasha Levinb5a05552012-12-20 09:11:24 +00003662 for (i = 0; i < ARRAY_SIZE(reg_set); i++)
Yaniv Rosner4e7b4992012-11-27 03:46:29 +00003663 bnx2x_cl45_write(bp, phy, reg_set[i].devad, reg_set[i].reg,
3664 reg_set[i].val);
3665
3666 /* Start KR2 work-around timer which handles BCM8073 link-parner */
3667 vars->link_attr_sync |= LINK_ATTR_SYNC_KR2_ENABLE;
3668 bnx2x_update_link_attr(params, vars->link_attr_sync);
3669}
Yuval Mintzec4010e2012-09-10 05:51:06 +00003670
3671static void bnx2x_warpcore_set_lpi_passthrough(struct bnx2x_phy *phy,
3672 struct link_params *params)
3673{
3674 struct bnx2x *bp = params->bp;
3675
3676 DP(NETIF_MSG_LINK, "Configure WC for LPI pass through\n");
3677 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3678 MDIO_WC_REG_EEE_COMBO_CONTROL0, 0x7c);
3679 bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
3680 MDIO_WC_REG_DIGITAL4_MISC5, 0xc000);
3681}
3682
Yaniv Rosner4e7b4992012-11-27 03:46:29 +00003683static void bnx2x_warpcore_restart_AN_KR(struct bnx2x_phy *phy,
3684 struct link_params *params)
3685{
3686 /* Restart autoneg on the leading lane only */
3687 struct bnx2x *bp = params->bp;
3688 u16 lane = bnx2x_get_warpcore_lane(phy, params);
3689 CL22_WR_OVER_CL45(bp, phy, MDIO_REG_BANK_AER_BLOCK,
3690 MDIO_AER_BLOCK_AER_REG, lane);
3691 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
3692 MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x1200);
3693
3694 /* Restore AER */
3695 bnx2x_set_aer_mmd(params, phy);
3696}
3697
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003698static void bnx2x_warpcore_enable_AN_KR(struct bnx2x_phy *phy,
3699 struct link_params *params,
3700 struct link_vars *vars) {
Yaniv Rosnercd1a26a2012-10-31 05:46:54 +00003701 u16 lane, i, cl72_ctrl, an_adv = 0;
3702 u16 ucode_ver;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003703 struct bnx2x *bp = params->bp;
Yuval Mintza351d492012-06-20 19:05:21 +00003704 static struct bnx2x_reg_set reg_set[] = {
3705 {MDIO_WC_DEVAD, MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2, 0x7},
Yuval Mintza351d492012-06-20 19:05:21 +00003706 {MDIO_PMA_DEVAD, MDIO_WC_REG_IEEE0BLK_AUTONEGNP, 0x0},
3707 {MDIO_WC_DEVAD, MDIO_WC_REG_RX66_CONTROL, 0x7415},
3708 {MDIO_WC_DEVAD, MDIO_WC_REG_SERDESDIGITAL_MISC2, 0x6190},
3709 /* Disable Autoneg: re-enable it after adv is done. */
Yaniv Rosner4e7b4992012-11-27 03:46:29 +00003710 {MDIO_AN_DEVAD, MDIO_WC_REG_IEEE0BLK_MIICNTL, 0},
3711 {MDIO_PMA_DEVAD, MDIO_WC_REG_PMD_KR_CONTROL, 0x2},
3712 {MDIO_WC_DEVAD, MDIO_WC_REG_CL72_USERB0_CL72_TX_FIR_TAP, 0},
Yuval Mintza351d492012-06-20 19:05:21 +00003713 };
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003714 DP(NETIF_MSG_LINK, "Enable Auto Negotiation for KR\n");
Yaniv Rosner6a51c0d2012-04-04 01:28:56 +00003715 /* Set to default registers that may be overriden by 10G force */
Sasha Levinb5a05552012-12-20 09:11:24 +00003716 for (i = 0; i < ARRAY_SIZE(reg_set); i++)
Yuval Mintza351d492012-06-20 19:05:21 +00003717 bnx2x_cl45_write(bp, phy, reg_set[i].devad, reg_set[i].reg,
3718 reg_set[i].val);
Yaniv Rosnera9077bf2011-10-27 05:09:46 +00003719
Yaniv Rosnerb457bcb2012-10-31 05:46:52 +00003720 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
Yaniv Rosner503976e2012-11-27 03:46:34 +00003721 MDIO_WC_REG_CL72_USERB0_CL72_MISC1_CONTROL, &cl72_ctrl);
Yaniv Rosner4e7b4992012-11-27 03:46:29 +00003722 cl72_ctrl &= 0x08ff;
Yaniv Rosnerb457bcb2012-10-31 05:46:52 +00003723 cl72_ctrl |= 0x3800;
3724 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
Yaniv Rosner503976e2012-11-27 03:46:34 +00003725 MDIO_WC_REG_CL72_USERB0_CL72_MISC1_CONTROL, cl72_ctrl);
Yaniv Rosnerb457bcb2012-10-31 05:46:52 +00003726
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003727 /* Check adding advertisement for 1G KX */
3728 if (((vars->line_speed == SPEED_AUTO_NEG) &&
3729 (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) ||
3730 (vars->line_speed == SPEED_1000)) {
Yuval Mintza351d492012-06-20 19:05:21 +00003731 u32 addr = MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2;
Yaniv Rosnercd1a26a2012-10-31 05:46:54 +00003732 an_adv |= (1<<5);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003733
3734 /* Enable CL37 1G Parallel Detect */
Yuval Mintza351d492012-06-20 19:05:21 +00003735 bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD, addr, 0x1);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003736 DP(NETIF_MSG_LINK, "Advertize 1G\n");
3737 }
3738 if (((vars->line_speed == SPEED_AUTO_NEG) &&
3739 (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) ||
3740 (vars->line_speed == SPEED_10000)) {
3741 /* Check adding advertisement for 10G KR */
Yaniv Rosnercd1a26a2012-10-31 05:46:54 +00003742 an_adv |= (1<<7);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003743 /* Enable 10G Parallel Detect */
Yaniv Rosnercd1a26a2012-10-31 05:46:54 +00003744 CL22_WR_OVER_CL45(bp, phy, MDIO_REG_BANK_AER_BLOCK,
3745 MDIO_AER_BLOCK_AER_REG, 0);
3746
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003747 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
Yuval Mintza351d492012-06-20 19:05:21 +00003748 MDIO_WC_REG_PAR_DET_10G_CTRL, 1);
Yaniv Rosnercd1a26a2012-10-31 05:46:54 +00003749 bnx2x_set_aer_mmd(params, phy);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003750 DP(NETIF_MSG_LINK, "Advertize 10G\n");
3751 }
3752
3753 /* Set Transmit PMD settings */
3754 lane = bnx2x_get_warpcore_lane(phy, params);
3755 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3756 MDIO_WC_REG_TX0_TX_DRIVER + 0x10*lane,
3757 ((0x02 << MDIO_WC_REG_TX0_TX_DRIVER_POST2_COEFF_OFFSET) |
3758 (0x06 << MDIO_WC_REG_TX0_TX_DRIVER_IDRIVER_OFFSET) |
3759 (0x09 << MDIO_WC_REG_TX0_TX_DRIVER_IPRE_DRIVER_OFFSET)));
Yaniv Rosner4e7b4992012-11-27 03:46:29 +00003760 /* Configure the next lane if dual mode */
3761 if (phy->flags & FLAGS_WC_DUAL_MODE)
3762 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3763 MDIO_WC_REG_TX0_TX_DRIVER + 0x10*(lane+1),
3764 ((0x02 <<
3765 MDIO_WC_REG_TX0_TX_DRIVER_POST2_COEFF_OFFSET) |
3766 (0x06 <<
3767 MDIO_WC_REG_TX0_TX_DRIVER_IDRIVER_OFFSET) |
3768 (0x09 <<
3769 MDIO_WC_REG_TX0_TX_DRIVER_IPRE_DRIVER_OFFSET)));
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003770 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3771 MDIO_WC_REG_CL72_USERB0_CL72_OS_DEF_CTRL,
3772 0x03f0);
3773 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3774 MDIO_WC_REG_CL72_USERB0_CL72_2P5_DEF_CTRL,
3775 0x03f0);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003776
3777 /* Advertised speeds */
3778 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
Yaniv Rosnercd1a26a2012-10-31 05:46:54 +00003779 MDIO_WC_REG_AN_IEEE1BLK_AN_ADVERTISEMENT1, an_adv);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003780
David S. Miller8decf862011-09-22 03:23:13 -04003781 /* Advertised and set FEC (Forward Error Correction) */
3782 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
3783 MDIO_WC_REG_AN_IEEE1BLK_AN_ADVERTISEMENT2,
3784 (MDIO_WC_REG_AN_IEEE1BLK_AN_ADV2_FEC_ABILITY |
3785 MDIO_WC_REG_AN_IEEE1BLK_AN_ADV2_FEC_REQ));
3786
Yaniv Rosnera34bc962011-07-05 01:06:41 +00003787 /* Enable CL37 BAM */
3788 if (REG_RD(bp, params->shmem_base +
3789 offsetof(struct shmem_region, dev_info.
3790 port_hw_config[params->port].default_cfg)) &
3791 PORT_HW_CFG_ENABLE_BAM_ON_KR_ENABLED) {
Yuval Mintza351d492012-06-20 19:05:21 +00003792 bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
3793 MDIO_WC_REG_DIGITAL6_MP5_NEXTPAGECTRL,
3794 1);
Yaniv Rosnera34bc962011-07-05 01:06:41 +00003795 DP(NETIF_MSG_LINK, "Enable CL37 BAM on KR\n");
3796 }
3797
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003798 /* Advertise pause */
3799 bnx2x_ext_phy_set_pause(params, phy, vars);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00003800 /* Set KR Autoneg Work-Around flag for Warpcore version older than D108
Yaniv Rosner6ab48a52012-01-17 02:33:29 +00003801 */
3802 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
Yaniv Rosnercd1a26a2012-10-31 05:46:54 +00003803 MDIO_WC_REG_UC_INFO_B1_VERSION, &ucode_ver);
3804 if (ucode_ver < 0xd108) {
3805 DP(NETIF_MSG_LINK, "Enable AN KR work-around. WC ver:0x%x\n",
3806 ucode_ver);
Yaniv Rosner6ab48a52012-01-17 02:33:29 +00003807 vars->rx_tx_asic_rst = MAX_KR_LINK_RETRY;
3808 }
Yuval Mintza351d492012-06-20 19:05:21 +00003809 bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
3810 MDIO_WC_REG_DIGITAL5_MISC7, 0x100);
Yaniv Rosnera9077bf2011-10-27 05:09:46 +00003811
3812 /* Over 1G - AN local device user page 1 */
3813 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3814 MDIO_WC_REG_DIGITAL3_UP1, 0x1f);
3815
Yaniv Rosner4e7b4992012-11-27 03:46:29 +00003816 if (((phy->req_line_speed == SPEED_AUTO_NEG) &&
3817 (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_20G)) ||
3818 (phy->req_line_speed == SPEED_20000)) {
Yaniv Rosnera9077bf2011-10-27 05:09:46 +00003819
Yaniv Rosner4e7b4992012-11-27 03:46:29 +00003820 CL22_WR_OVER_CL45(bp, phy, MDIO_REG_BANK_AER_BLOCK,
3821 MDIO_AER_BLOCK_AER_REG, lane);
3822
3823 bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
3824 MDIO_WC_REG_RX1_PCI_CTRL + (0x10*lane),
3825 (1<<11));
3826
3827 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3828 MDIO_WC_REG_XGXS_X2_CONTROL3, 0x7);
3829 bnx2x_set_aer_mmd(params, phy);
3830
3831 bnx2x_warpcore_enable_AN_KR2(phy, params, vars);
3832 }
3833
3834 /* Enable Autoneg: only on the main lane */
3835 bnx2x_warpcore_restart_AN_KR(phy, params);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003836}
3837
3838static void bnx2x_warpcore_set_10G_KR(struct bnx2x_phy *phy,
3839 struct link_params *params,
3840 struct link_vars *vars)
3841{
3842 struct bnx2x *bp = params->bp;
Yaniv Rosnercd1a26a2012-10-31 05:46:54 +00003843 u16 val16, i, lane;
Yuval Mintza351d492012-06-20 19:05:21 +00003844 static struct bnx2x_reg_set reg_set[] = {
3845 /* Disable Autoneg */
3846 {MDIO_WC_DEVAD, MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2, 0x7},
Yuval Mintza351d492012-06-20 19:05:21 +00003847 {MDIO_WC_DEVAD, MDIO_WC_REG_CL72_USERB0_CL72_MISC1_CONTROL,
3848 0x3f00},
3849 {MDIO_AN_DEVAD, MDIO_WC_REG_AN_IEEE1BLK_AN_ADVERTISEMENT1, 0},
3850 {MDIO_AN_DEVAD, MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x0},
3851 {MDIO_WC_DEVAD, MDIO_WC_REG_DIGITAL3_UP1, 0x1},
3852 {MDIO_WC_DEVAD, MDIO_WC_REG_DIGITAL5_MISC7, 0xa},
Yuval Mintza351d492012-06-20 19:05:21 +00003853 /* Leave cl72 training enable, needed for KR */
Yaniv Rosner4e7b4992012-11-27 03:46:29 +00003854 {MDIO_PMA_DEVAD, MDIO_WC_REG_PMD_KR_CONTROL, 0x2}
Yuval Mintza351d492012-06-20 19:05:21 +00003855 };
3856
Sasha Levinb5a05552012-12-20 09:11:24 +00003857 for (i = 0; i < ARRAY_SIZE(reg_set); i++)
Yuval Mintza351d492012-06-20 19:05:21 +00003858 bnx2x_cl45_write(bp, phy, reg_set[i].devad, reg_set[i].reg,
3859 reg_set[i].val);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003860
Yaniv Rosnercd1a26a2012-10-31 05:46:54 +00003861 lane = bnx2x_get_warpcore_lane(phy, params);
3862 /* Global registers */
3863 CL22_WR_OVER_CL45(bp, phy, MDIO_REG_BANK_AER_BLOCK,
3864 MDIO_AER_BLOCK_AER_REG, 0);
3865 /* Disable CL36 PCS Tx */
3866 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
3867 MDIO_WC_REG_XGXSBLK1_LANECTRL0, &val16);
3868 val16 &= ~(0x0011 << lane);
3869 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3870 MDIO_WC_REG_XGXSBLK1_LANECTRL0, val16);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003871
Yaniv Rosnercd1a26a2012-10-31 05:46:54 +00003872 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
3873 MDIO_WC_REG_XGXSBLK1_LANECTRL1, &val16);
3874 val16 |= (0x0303 << (lane << 1));
3875 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3876 MDIO_WC_REG_XGXSBLK1_LANECTRL1, val16);
3877 /* Restore AER */
3878 bnx2x_set_aer_mmd(params, phy);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003879 /* Set speed via PMA/PMD register */
3880 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD,
3881 MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x2040);
3882
3883 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD,
3884 MDIO_WC_REG_IEEE0BLK_AUTONEGNP, 0xB);
3885
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00003886 /* Enable encoded forced speed */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003887 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3888 MDIO_WC_REG_SERDESDIGITAL_MISC2, 0x30);
3889
3890 /* Turn TX scramble payload only the 64/66 scrambler */
3891 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3892 MDIO_WC_REG_TX66_CONTROL, 0x9);
3893
3894 /* Turn RX scramble payload only the 64/66 scrambler */
3895 bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
3896 MDIO_WC_REG_RX66_CONTROL, 0xF9);
3897
Yuval Mintzd2310232012-06-20 19:05:19 +00003898 /* Set and clear loopback to cause a reset to 64/66 decoder */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003899 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3900 MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x4000);
3901 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3902 MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x0);
3903
3904}
3905
3906static void bnx2x_warpcore_set_10G_XFI(struct bnx2x_phy *phy,
3907 struct link_params *params,
3908 u8 is_xfi)
3909{
3910 struct bnx2x *bp = params->bp;
3911 u16 misc1_val, tap_val, tx_driver_val, lane, val;
3912 /* Hold rxSeqStart */
Yuval Mintza351d492012-06-20 19:05:21 +00003913 bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
3914 MDIO_WC_REG_DSC2B0_DSC_MISC_CTRL0, 0x8000);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003915
3916 /* Hold tx_fifo_reset */
Yuval Mintza351d492012-06-20 19:05:21 +00003917 bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
3918 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X3, 0x1);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003919
3920 /* Disable CL73 AN */
3921 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0);
3922
3923 /* Disable 100FX Enable and Auto-Detect */
Yaniv Rosner503976e2012-11-27 03:46:34 +00003924 bnx2x_cl45_read_and_write(bp, phy, MDIO_WC_DEVAD,
3925 MDIO_WC_REG_FX100_CTRL1, 0xFFFA);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003926
3927 /* Disable 100FX Idle detect */
Yuval Mintza351d492012-06-20 19:05:21 +00003928 bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
3929 MDIO_WC_REG_FX100_CTRL3, 0x0080);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003930
3931 /* Set Block address to Remote PHY & Clear forced_speed[5] */
Yaniv Rosner503976e2012-11-27 03:46:34 +00003932 bnx2x_cl45_read_and_write(bp, phy, MDIO_WC_DEVAD,
3933 MDIO_WC_REG_DIGITAL4_MISC3, 0xFF7F);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003934
3935 /* Turn off auto-detect & fiber mode */
Yaniv Rosner503976e2012-11-27 03:46:34 +00003936 bnx2x_cl45_read_and_write(bp, phy, MDIO_WC_DEVAD,
3937 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X1,
3938 0xFFEE);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003939
3940 /* Set filter_force_link, disable_false_link and parallel_detect */
3941 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
3942 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2, &val);
3943 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3944 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2,
3945 ((val | 0x0006) & 0xFFFE));
3946
3947 /* Set XFI / SFI */
3948 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
3949 MDIO_WC_REG_SERDESDIGITAL_MISC1, &misc1_val);
3950
3951 misc1_val &= ~(0x1f);
3952
3953 if (is_xfi) {
3954 misc1_val |= 0x5;
3955 tap_val = ((0x08 << MDIO_WC_REG_TX_FIR_TAP_POST_TAP_OFFSET) |
3956 (0x37 << MDIO_WC_REG_TX_FIR_TAP_MAIN_TAP_OFFSET) |
3957 (0x00 << MDIO_WC_REG_TX_FIR_TAP_PRE_TAP_OFFSET));
3958 tx_driver_val =
3959 ((0x00 << MDIO_WC_REG_TX0_TX_DRIVER_POST2_COEFF_OFFSET) |
3960 (0x02 << MDIO_WC_REG_TX0_TX_DRIVER_IDRIVER_OFFSET) |
3961 (0x03 << MDIO_WC_REG_TX0_TX_DRIVER_IPRE_DRIVER_OFFSET));
3962
3963 } else {
3964 misc1_val |= 0x9;
Yaniv Rosner25182fc2012-04-04 01:28:57 +00003965 tap_val = ((0x0f << MDIO_WC_REG_TX_FIR_TAP_POST_TAP_OFFSET) |
3966 (0x2b << MDIO_WC_REG_TX_FIR_TAP_MAIN_TAP_OFFSET) |
3967 (0x02 << MDIO_WC_REG_TX_FIR_TAP_PRE_TAP_OFFSET));
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003968 tx_driver_val =
Yaniv Rosner25182fc2012-04-04 01:28:57 +00003969 ((0x03 << MDIO_WC_REG_TX0_TX_DRIVER_POST2_COEFF_OFFSET) |
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003970 (0x02 << MDIO_WC_REG_TX0_TX_DRIVER_IDRIVER_OFFSET) |
Yaniv Rosner25182fc2012-04-04 01:28:57 +00003971 (0x06 << MDIO_WC_REG_TX0_TX_DRIVER_IPRE_DRIVER_OFFSET));
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003972 }
3973 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3974 MDIO_WC_REG_SERDESDIGITAL_MISC1, misc1_val);
3975
3976 /* Set Transmit PMD settings */
3977 lane = bnx2x_get_warpcore_lane(phy, params);
3978 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3979 MDIO_WC_REG_TX_FIR_TAP,
3980 tap_val | MDIO_WC_REG_TX_FIR_TAP_ENABLE);
3981 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3982 MDIO_WC_REG_TX0_TX_DRIVER + 0x10*lane,
3983 tx_driver_val);
3984
3985 /* Enable fiber mode, enable and invert sig_det */
Yuval Mintza351d492012-06-20 19:05:21 +00003986 bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
3987 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X1, 0xd);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003988
3989 /* Set Block address to Remote PHY & Set forced_speed[5], 40bit mode */
Yuval Mintza351d492012-06-20 19:05:21 +00003990 bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
3991 MDIO_WC_REG_DIGITAL4_MISC3, 0x8080);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003992
Yuval Mintzec4010e2012-09-10 05:51:06 +00003993 bnx2x_warpcore_set_lpi_passthrough(phy, params);
Yuval Mintzc8c60d82012-06-06 17:13:07 +00003994
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00003995 /* 10G XFI Full Duplex */
3996 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
3997 MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x100);
3998
3999 /* Release tx_fifo_reset */
Yaniv Rosner503976e2012-11-27 03:46:34 +00004000 bnx2x_cl45_read_and_write(bp, phy, MDIO_WC_DEVAD,
4001 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X3,
4002 0xFFFE);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004003 /* Release rxSeqStart */
Yaniv Rosner503976e2012-11-27 03:46:34 +00004004 bnx2x_cl45_read_and_write(bp, phy, MDIO_WC_DEVAD,
4005 MDIO_WC_REG_DSC2B0_DSC_MISC_CTRL0, 0x7FFF);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004006}
4007
Yaniv Rosner4e7b4992012-11-27 03:46:29 +00004008static void bnx2x_warpcore_set_20G_force_KR2(struct bnx2x_phy *phy,
4009 struct link_params *params)
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004010{
Yaniv Rosner4e7b4992012-11-27 03:46:29 +00004011 u16 val;
4012 struct bnx2x *bp = params->bp;
4013 /* Set global registers, so set AER lane to 0 */
4014 CL22_WR_OVER_CL45(bp, phy, MDIO_REG_BANK_AER_BLOCK,
4015 MDIO_AER_BLOCK_AER_REG, 0);
4016
4017 /* Disable sequencer */
4018 bnx2x_cl45_read_and_write(bp, phy, MDIO_WC_DEVAD,
4019 MDIO_WC_REG_XGXSBLK0_XGXSCONTROL, ~(1<<13));
4020
4021 bnx2x_set_aer_mmd(params, phy);
4022
4023 bnx2x_cl45_read_and_write(bp, phy, MDIO_PMA_DEVAD,
4024 MDIO_WC_REG_PMD_KR_CONTROL, ~(1<<1));
4025 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
4026 MDIO_AN_REG_CTRL, 0);
4027 /* Turn off CL73 */
4028 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4029 MDIO_WC_REG_CL73_USERB0_CTRL, &val);
4030 val &= ~(1<<5);
4031 val |= (1<<6);
4032 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4033 MDIO_WC_REG_CL73_USERB0_CTRL, val);
4034
4035 /* Set 20G KR2 force speed */
4036 bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
4037 MDIO_WC_REG_SERDESDIGITAL_MISC1, 0x1f);
4038
4039 bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
4040 MDIO_WC_REG_DIGITAL4_MISC3, (1<<7));
4041
4042 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4043 MDIO_WC_REG_CL72_USERB0_CL72_MISC1_CONTROL, &val);
4044 val &= ~(3<<14);
4045 val |= (1<<15);
4046 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4047 MDIO_WC_REG_CL72_USERB0_CL72_MISC1_CONTROL, val);
4048 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4049 MDIO_WC_REG_CL72_USERB0_CL72_TX_FIR_TAP, 0x835A);
4050
4051 /* Enable sequencer (over lane 0) */
4052 CL22_WR_OVER_CL45(bp, phy, MDIO_REG_BANK_AER_BLOCK,
4053 MDIO_AER_BLOCK_AER_REG, 0);
4054
4055 bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
4056 MDIO_WC_REG_XGXSBLK0_XGXSCONTROL, (1<<13));
4057
4058 bnx2x_set_aer_mmd(params, phy);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004059}
4060
4061static void bnx2x_warpcore_set_20G_DXGXS(struct bnx2x *bp,
4062 struct bnx2x_phy *phy,
4063 u16 lane)
4064{
4065 /* Rx0 anaRxControl1G */
4066 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4067 MDIO_WC_REG_RX0_ANARXCONTROL1G, 0x90);
4068
4069 /* Rx2 anaRxControl1G */
4070 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4071 MDIO_WC_REG_RX2_ANARXCONTROL1G, 0x90);
4072
4073 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4074 MDIO_WC_REG_RX66_SCW0, 0xE070);
4075
4076 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4077 MDIO_WC_REG_RX66_SCW1, 0xC0D0);
4078
4079 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4080 MDIO_WC_REG_RX66_SCW2, 0xA0B0);
4081
4082 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4083 MDIO_WC_REG_RX66_SCW3, 0x8090);
4084
4085 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4086 MDIO_WC_REG_RX66_SCW0_MASK, 0xF0F0);
4087
4088 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4089 MDIO_WC_REG_RX66_SCW1_MASK, 0xF0F0);
4090
4091 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4092 MDIO_WC_REG_RX66_SCW2_MASK, 0xF0F0);
4093
4094 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4095 MDIO_WC_REG_RX66_SCW3_MASK, 0xF0F0);
4096
4097 /* Serdes Digital Misc1 */
4098 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4099 MDIO_WC_REG_SERDESDIGITAL_MISC1, 0x6008);
4100
4101 /* Serdes Digital4 Misc3 */
4102 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4103 MDIO_WC_REG_DIGITAL4_MISC3, 0x8088);
4104
4105 /* Set Transmit PMD settings */
4106 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4107 MDIO_WC_REG_TX_FIR_TAP,
4108 ((0x12 << MDIO_WC_REG_TX_FIR_TAP_POST_TAP_OFFSET) |
4109 (0x2d << MDIO_WC_REG_TX_FIR_TAP_MAIN_TAP_OFFSET) |
4110 (0x00 << MDIO_WC_REG_TX_FIR_TAP_PRE_TAP_OFFSET) |
4111 MDIO_WC_REG_TX_FIR_TAP_ENABLE));
4112 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4113 MDIO_WC_REG_TX0_TX_DRIVER + 0x10*lane,
4114 ((0x02 << MDIO_WC_REG_TX0_TX_DRIVER_POST2_COEFF_OFFSET) |
4115 (0x02 << MDIO_WC_REG_TX0_TX_DRIVER_IDRIVER_OFFSET) |
4116 (0x02 << MDIO_WC_REG_TX0_TX_DRIVER_IPRE_DRIVER_OFFSET)));
4117}
4118
4119static void bnx2x_warpcore_set_sgmii_speed(struct bnx2x_phy *phy,
4120 struct link_params *params,
Yaniv Rosner521683d2011-11-28 00:49:48 +00004121 u8 fiber_mode,
4122 u8 always_autoneg)
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004123{
4124 struct bnx2x *bp = params->bp;
4125 u16 val16, digctrl_kx1, digctrl_kx2;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004126
4127 /* Clear XFI clock comp in non-10G single lane mode. */
Yaniv Rosner503976e2012-11-27 03:46:34 +00004128 bnx2x_cl45_read_and_write(bp, phy, MDIO_WC_DEVAD,
4129 MDIO_WC_REG_RX66_CONTROL, ~(3<<13));
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004130
Yuval Mintz26964bb2012-09-10 05:51:08 +00004131 bnx2x_warpcore_set_lpi_passthrough(phy, params);
4132
Yaniv Rosner521683d2011-11-28 00:49:48 +00004133 if (always_autoneg || phy->req_line_speed == SPEED_AUTO_NEG) {
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004134 /* SGMII Autoneg */
Yaniv Rosner503976e2012-11-27 03:46:34 +00004135 bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
4136 MDIO_WC_REG_COMBO_IEEE0_MIICTRL,
4137 0x1000);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004138 DP(NETIF_MSG_LINK, "set SGMII AUTONEG\n");
4139 } else {
4140 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4141 MDIO_WC_REG_COMBO_IEEE0_MIICTRL, &val16);
Yaniv Rosner521683d2011-11-28 00:49:48 +00004142 val16 &= 0xcebf;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004143 switch (phy->req_line_speed) {
4144 case SPEED_10:
4145 break;
4146 case SPEED_100:
4147 val16 |= 0x2000;
4148 break;
4149 case SPEED_1000:
4150 val16 |= 0x0040;
4151 break;
4152 default:
Joe Perches94f05b02011-08-14 12:16:20 +00004153 DP(NETIF_MSG_LINK,
4154 "Speed not supported: 0x%x\n", phy->req_line_speed);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004155 return;
4156 }
4157
4158 if (phy->req_duplex == DUPLEX_FULL)
4159 val16 |= 0x0100;
4160
4161 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4162 MDIO_WC_REG_COMBO_IEEE0_MIICTRL, val16);
4163
4164 DP(NETIF_MSG_LINK, "set SGMII force speed %d\n",
4165 phy->req_line_speed);
4166 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4167 MDIO_WC_REG_COMBO_IEEE0_MIICTRL, &val16);
4168 DP(NETIF_MSG_LINK, " (readback) %x\n", val16);
4169 }
4170
4171 /* SGMII Slave mode and disable signal detect */
4172 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4173 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X1, &digctrl_kx1);
4174 if (fiber_mode)
4175 digctrl_kx1 = 1;
4176 else
4177 digctrl_kx1 &= 0xff4a;
4178
4179 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4180 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X1,
4181 digctrl_kx1);
4182
4183 /* Turn off parallel detect */
4184 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4185 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2, &digctrl_kx2);
4186 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4187 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2,
4188 (digctrl_kx2 & ~(1<<2)));
4189
4190 /* Re-enable parallel detect */
4191 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4192 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2,
4193 (digctrl_kx2 | (1<<2)));
4194
4195 /* Enable autodet */
4196 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4197 MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X1,
4198 (digctrl_kx1 | 0x10));
4199}
4200
4201static void bnx2x_warpcore_reset_lane(struct bnx2x *bp,
4202 struct bnx2x_phy *phy,
4203 u8 reset)
4204{
4205 u16 val;
4206 /* Take lane out of reset after configuration is finished */
4207 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4208 MDIO_WC_REG_DIGITAL5_MISC6, &val);
4209 if (reset)
4210 val |= 0xC000;
4211 else
4212 val &= 0x3FFF;
4213 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4214 MDIO_WC_REG_DIGITAL5_MISC6, val);
4215 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4216 MDIO_WC_REG_DIGITAL5_MISC6, &val);
4217}
Yaniv Rosner2f751a82011-11-28 00:49:52 +00004218/* Clear SFI/XFI link settings registers */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004219static void bnx2x_warpcore_clear_regs(struct bnx2x_phy *phy,
4220 struct link_params *params,
4221 u16 lane)
4222{
4223 struct bnx2x *bp = params->bp;
Yuval Mintza351d492012-06-20 19:05:21 +00004224 u16 i;
4225 static struct bnx2x_reg_set wc_regs[] = {
4226 {MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0},
4227 {MDIO_WC_DEVAD, MDIO_WC_REG_FX100_CTRL1, 0x014a},
4228 {MDIO_WC_DEVAD, MDIO_WC_REG_FX100_CTRL3, 0x0800},
4229 {MDIO_WC_DEVAD, MDIO_WC_REG_DIGITAL4_MISC3, 0x8008},
4230 {MDIO_WC_DEVAD, MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X1,
4231 0x0195},
4232 {MDIO_WC_DEVAD, MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2,
4233 0x0007},
4234 {MDIO_WC_DEVAD, MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X3,
4235 0x0002},
4236 {MDIO_WC_DEVAD, MDIO_WC_REG_SERDESDIGITAL_MISC1, 0x6000},
4237 {MDIO_WC_DEVAD, MDIO_WC_REG_TX_FIR_TAP, 0x0000},
4238 {MDIO_WC_DEVAD, MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x2040},
4239 {MDIO_WC_DEVAD, MDIO_WC_REG_COMBO_IEEE0_MIICTRL, 0x0140}
4240 };
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004241 /* Set XFI clock comp as default. */
Yuval Mintza351d492012-06-20 19:05:21 +00004242 bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
4243 MDIO_WC_REG_RX66_CONTROL, (3<<13));
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004244
Sasha Levinb5a05552012-12-20 09:11:24 +00004245 for (i = 0; i < ARRAY_SIZE(wc_regs); i++)
Yuval Mintza351d492012-06-20 19:05:21 +00004246 bnx2x_cl45_write(bp, phy, wc_regs[i].devad, wc_regs[i].reg,
4247 wc_regs[i].val);
4248
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004249 lane = bnx2x_get_warpcore_lane(phy, params);
4250 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004251 MDIO_WC_REG_TX0_TX_DRIVER + 0x10*lane, 0x0990);
Yuval Mintza351d492012-06-20 19:05:21 +00004252
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004253}
4254
4255static int bnx2x_get_mod_abs_int_cfg(struct bnx2x *bp,
4256 u32 chip_id,
4257 u32 shmem_base, u8 port,
4258 u8 *gpio_num, u8 *gpio_port)
4259{
4260 u32 cfg_pin;
4261 *gpio_num = 0;
4262 *gpio_port = 0;
4263 if (CHIP_IS_E3(bp)) {
4264 cfg_pin = (REG_RD(bp, shmem_base +
4265 offsetof(struct shmem_region,
4266 dev_info.port_hw_config[port].e3_sfp_ctrl)) &
4267 PORT_HW_CFG_E3_MOD_ABS_MASK) >>
4268 PORT_HW_CFG_E3_MOD_ABS_SHIFT;
4269
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00004270 /* Should not happen. This function called upon interrupt
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004271 * triggered by GPIO ( since EPIO can only generate interrupts
4272 * to MCP).
4273 * So if this function was called and none of the GPIOs was set,
4274 * it means the shit hit the fan.
4275 */
4276 if ((cfg_pin < PIN_CFG_GPIO0_P0) ||
4277 (cfg_pin > PIN_CFG_GPIO3_P1)) {
Joe Perches94f05b02011-08-14 12:16:20 +00004278 DP(NETIF_MSG_LINK,
Yaniv Rosner503976e2012-11-27 03:46:34 +00004279 "No cfg pin %x for module detect indication\n",
Joe Perches94f05b02011-08-14 12:16:20 +00004280 cfg_pin);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004281 return -EINVAL;
4282 }
4283
4284 *gpio_num = (cfg_pin - PIN_CFG_GPIO0_P0) & 0x3;
4285 *gpio_port = (cfg_pin - PIN_CFG_GPIO0_P0) >> 2;
4286 } else {
4287 *gpio_num = MISC_REGISTERS_GPIO_3;
4288 *gpio_port = port;
4289 }
Yaniv Rosner503976e2012-11-27 03:46:34 +00004290
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004291 return 0;
4292}
4293
4294static int bnx2x_is_sfp_module_plugged(struct bnx2x_phy *phy,
4295 struct link_params *params)
4296{
4297 struct bnx2x *bp = params->bp;
4298 u8 gpio_num, gpio_port;
4299 u32 gpio_val;
4300 if (bnx2x_get_mod_abs_int_cfg(bp, params->chip_id,
4301 params->shmem_base, params->port,
4302 &gpio_num, &gpio_port) != 0)
4303 return 0;
4304 gpio_val = bnx2x_get_gpio(bp, gpio_num, gpio_port);
4305
4306 /* Call the handling function in case module is detected */
4307 if (gpio_val == 0)
4308 return 1;
4309 else
4310 return 0;
4311}
Yaniv Rosnera9077bf2011-10-27 05:09:46 +00004312static int bnx2x_warpcore_get_sigdet(struct bnx2x_phy *phy,
Yaniv Rosner503976e2012-11-27 03:46:34 +00004313 struct link_params *params)
Yaniv Rosnera9077bf2011-10-27 05:09:46 +00004314{
4315 u16 gp2_status_reg0, lane;
4316 struct bnx2x *bp = params->bp;
4317
4318 lane = bnx2x_get_warpcore_lane(phy, params);
4319
4320 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD, MDIO_WC_REG_GP2_STATUS_GP_2_0,
4321 &gp2_status_reg0);
4322
4323 return (gp2_status_reg0 >> (8+lane)) & 0x1;
4324}
4325
4326static void bnx2x_warpcore_config_runtime(struct bnx2x_phy *phy,
Yaniv Rosner503976e2012-11-27 03:46:34 +00004327 struct link_params *params,
4328 struct link_vars *vars)
Yaniv Rosnera9077bf2011-10-27 05:09:46 +00004329{
4330 struct bnx2x *bp = params->bp;
4331 u32 serdes_net_if;
4332 u16 gp_status1 = 0, lnkup = 0, lnkup_kr = 0;
4333 u16 lane = bnx2x_get_warpcore_lane(phy, params);
4334
4335 vars->turn_to_run_wc_rt = vars->turn_to_run_wc_rt ? 0 : 1;
4336
4337 if (!vars->turn_to_run_wc_rt)
4338 return;
4339
Yuval Mintzd2310232012-06-20 19:05:19 +00004340 /* Return if there is no link partner */
Yaniv Rosnera9077bf2011-10-27 05:09:46 +00004341 if (!(bnx2x_warpcore_get_sigdet(phy, params))) {
4342 DP(NETIF_MSG_LINK, "bnx2x_warpcore_get_sigdet false\n");
4343 return;
4344 }
4345
4346 if (vars->rx_tx_asic_rst) {
4347 serdes_net_if = (REG_RD(bp, params->shmem_base +
4348 offsetof(struct shmem_region, dev_info.
4349 port_hw_config[params->port].default_cfg)) &
4350 PORT_HW_CFG_NET_SERDES_IF_MASK);
4351
4352 switch (serdes_net_if) {
4353 case PORT_HW_CFG_NET_SERDES_IF_KR:
4354 /* Do we get link yet? */
4355 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD, 0x81d1,
Yaniv Rosner503976e2012-11-27 03:46:34 +00004356 &gp_status1);
Yaniv Rosnera9077bf2011-10-27 05:09:46 +00004357 lnkup = (gp_status1 >> (8+lane)) & 0x1;/* 1G */
4358 /*10G KR*/
4359 lnkup_kr = (gp_status1 >> (12+lane)) & 0x1;
4360
4361 DP(NETIF_MSG_LINK,
4362 "gp_status1 0x%x\n", gp_status1);
4363
4364 if (lnkup_kr || lnkup) {
4365 vars->rx_tx_asic_rst = 0;
4366 DP(NETIF_MSG_LINK,
4367 "link up, rx_tx_asic_rst 0x%x\n",
4368 vars->rx_tx_asic_rst);
4369 } else {
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00004370 /* Reset the lane to see if link comes up.*/
Yaniv Rosnera9077bf2011-10-27 05:09:46 +00004371 bnx2x_warpcore_reset_lane(bp, phy, 1);
4372 bnx2x_warpcore_reset_lane(bp, phy, 0);
4373
Yuval Mintzd2310232012-06-20 19:05:19 +00004374 /* Restart Autoneg */
Yaniv Rosnera9077bf2011-10-27 05:09:46 +00004375 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
4376 MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x1200);
4377
4378 vars->rx_tx_asic_rst--;
4379 DP(NETIF_MSG_LINK, "0x%x retry left\n",
4380 vars->rx_tx_asic_rst);
4381 }
4382 break;
4383
4384 default:
4385 break;
4386 }
4387
4388 } /*params->rx_tx_asic_rst*/
4389
4390}
Yuval Mintzdbef8072012-06-20 19:05:22 +00004391static void bnx2x_warpcore_config_sfi(struct bnx2x_phy *phy,
4392 struct link_params *params)
4393{
4394 u16 lane = bnx2x_get_warpcore_lane(phy, params);
4395 struct bnx2x *bp = params->bp;
4396 bnx2x_warpcore_clear_regs(phy, params, lane);
4397 if ((params->req_line_speed[LINK_CONFIG_IDX(INT_PHY)] ==
4398 SPEED_10000) &&
4399 (phy->media_type != ETH_PHY_SFP_1G_FIBER)) {
4400 DP(NETIF_MSG_LINK, "Setting 10G SFI\n");
4401 bnx2x_warpcore_set_10G_XFI(phy, params, 0);
4402 } else {
4403 DP(NETIF_MSG_LINK, "Setting 1G Fiber\n");
4404 bnx2x_warpcore_set_sgmii_speed(phy, params, 1, 0);
4405 }
4406}
4407
Yaniv Rosner5a1fbf42012-11-27 03:46:31 +00004408static void bnx2x_sfp_e3_set_transmitter(struct link_params *params,
4409 struct bnx2x_phy *phy,
4410 u8 tx_en)
4411{
4412 struct bnx2x *bp = params->bp;
4413 u32 cfg_pin;
4414 u8 port = params->port;
4415
4416 cfg_pin = REG_RD(bp, params->shmem_base +
4417 offsetof(struct shmem_region,
4418 dev_info.port_hw_config[port].e3_sfp_ctrl)) &
4419 PORT_HW_CFG_E3_TX_LASER_MASK;
4420 /* Set the !tx_en since this pin is DISABLE_TX_LASER */
4421 DP(NETIF_MSG_LINK, "Setting WC TX to %d\n", tx_en);
4422
4423 /* For 20G, the expected pin to be used is 3 pins after the current */
4424 bnx2x_set_cfg_pin(bp, cfg_pin, tx_en ^ 1);
4425 if (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_20G)
4426 bnx2x_set_cfg_pin(bp, cfg_pin + 3, tx_en ^ 1);
4427}
4428
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004429static void bnx2x_warpcore_config_init(struct bnx2x_phy *phy,
4430 struct link_params *params,
4431 struct link_vars *vars)
4432{
4433 struct bnx2x *bp = params->bp;
4434 u32 serdes_net_if;
4435 u8 fiber_mode;
4436 u16 lane = bnx2x_get_warpcore_lane(phy, params);
4437 serdes_net_if = (REG_RD(bp, params->shmem_base +
4438 offsetof(struct shmem_region, dev_info.
4439 port_hw_config[params->port].default_cfg)) &
4440 PORT_HW_CFG_NET_SERDES_IF_MASK);
4441 DP(NETIF_MSG_LINK, "Begin Warpcore init, link_speed %d, "
4442 "serdes_net_if = 0x%x\n",
4443 vars->line_speed, serdes_net_if);
4444 bnx2x_set_aer_mmd(params, phy);
Yaniv Rosnerd3a8f132012-09-13 02:56:20 +00004445 bnx2x_warpcore_reset_lane(bp, phy, 1);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004446 vars->phy_flags |= PHY_XGXS_FLAG;
4447 if ((serdes_net_if == PORT_HW_CFG_NET_SERDES_IF_SGMII) ||
4448 (phy->req_line_speed &&
4449 ((phy->req_line_speed == SPEED_100) ||
4450 (phy->req_line_speed == SPEED_10)))) {
4451 vars->phy_flags |= PHY_SGMII_FLAG;
4452 DP(NETIF_MSG_LINK, "Setting SGMII mode\n");
4453 bnx2x_warpcore_clear_regs(phy, params, lane);
Yaniv Rosner521683d2011-11-28 00:49:48 +00004454 bnx2x_warpcore_set_sgmii_speed(phy, params, 0, 1);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004455 } else {
4456 switch (serdes_net_if) {
4457 case PORT_HW_CFG_NET_SERDES_IF_KR:
4458 /* Enable KR Auto Neg */
Yaniv Rosner6a51c0d2012-04-04 01:28:56 +00004459 if (params->loopback_mode != LOOPBACK_EXT)
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004460 bnx2x_warpcore_enable_AN_KR(phy, params, vars);
4461 else {
4462 DP(NETIF_MSG_LINK, "Setting KR 10G-Force\n");
4463 bnx2x_warpcore_set_10G_KR(phy, params, vars);
4464 }
4465 break;
4466
4467 case PORT_HW_CFG_NET_SERDES_IF_XFI:
4468 bnx2x_warpcore_clear_regs(phy, params, lane);
4469 if (vars->line_speed == SPEED_10000) {
4470 DP(NETIF_MSG_LINK, "Setting 10G XFI\n");
4471 bnx2x_warpcore_set_10G_XFI(phy, params, 1);
4472 } else {
4473 if (SINGLE_MEDIA_DIRECT(params)) {
4474 DP(NETIF_MSG_LINK, "1G Fiber\n");
4475 fiber_mode = 1;
4476 } else {
4477 DP(NETIF_MSG_LINK, "10/100/1G SGMII\n");
4478 fiber_mode = 0;
4479 }
4480 bnx2x_warpcore_set_sgmii_speed(phy,
4481 params,
Yaniv Rosner521683d2011-11-28 00:49:48 +00004482 fiber_mode,
4483 0);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004484 }
4485
4486 break;
4487
4488 case PORT_HW_CFG_NET_SERDES_IF_SFI:
Yaniv Rosner5a1fbf42012-11-27 03:46:31 +00004489 /* Issue Module detection if module is plugged, or
4490 * enabled transmitter to avoid current leakage in case
4491 * no module is connected
4492 */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004493 if (bnx2x_is_sfp_module_plugged(phy, params))
4494 bnx2x_sfp_module_detection(phy, params);
Yaniv Rosner5a1fbf42012-11-27 03:46:31 +00004495 else
4496 bnx2x_sfp_e3_set_transmitter(params, phy, 1);
Yuval Mintzdbef8072012-06-20 19:05:22 +00004497
4498 bnx2x_warpcore_config_sfi(phy, params);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004499 break;
4500
4501 case PORT_HW_CFG_NET_SERDES_IF_DXGXS:
4502 if (vars->line_speed != SPEED_20000) {
4503 DP(NETIF_MSG_LINK, "Speed not supported yet\n");
4504 return;
4505 }
4506 DP(NETIF_MSG_LINK, "Setting 20G DXGXS\n");
4507 bnx2x_warpcore_set_20G_DXGXS(bp, phy, lane);
4508 /* Issue Module detection */
4509
4510 bnx2x_sfp_module_detection(phy, params);
4511 break;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004512 case PORT_HW_CFG_NET_SERDES_IF_KR2:
Yaniv Rosner4e7b4992012-11-27 03:46:29 +00004513 if (!params->loopback_mode) {
4514 bnx2x_warpcore_enable_AN_KR(phy, params, vars);
4515 } else {
4516 DP(NETIF_MSG_LINK, "Setting KR 20G-Force\n");
4517 bnx2x_warpcore_set_20G_force_KR2(phy, params);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004518 }
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004519 break;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004520 default:
Joe Perches94f05b02011-08-14 12:16:20 +00004521 DP(NETIF_MSG_LINK,
4522 "Unsupported Serdes Net Interface 0x%x\n",
4523 serdes_net_if);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004524 return;
4525 }
4526 }
4527
4528 /* Take lane out of reset after configuration is finished */
4529 bnx2x_warpcore_reset_lane(bp, phy, 0);
4530 DP(NETIF_MSG_LINK, "Exit config init\n");
4531}
4532
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004533static void bnx2x_warpcore_link_reset(struct bnx2x_phy *phy,
4534 struct link_params *params)
4535{
4536 struct bnx2x *bp = params->bp;
Yaniv Rosnercd1a26a2012-10-31 05:46:54 +00004537 u16 val16, lane;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004538 bnx2x_sfp_e3_set_transmitter(params, phy, 0);
Yaniv Rosner55386fe82012-11-27 03:46:30 +00004539 bnx2x_set_mdio_emac_per_phy(bp, params);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004540 bnx2x_set_aer_mmd(params, phy);
4541 /* Global register */
4542 bnx2x_warpcore_reset_lane(bp, phy, 1);
4543
4544 /* Clear loopback settings (if any) */
4545 /* 10G & 20G */
Yaniv Rosner503976e2012-11-27 03:46:34 +00004546 bnx2x_cl45_read_and_write(bp, phy, MDIO_WC_DEVAD,
4547 MDIO_WC_REG_COMBO_IEEE0_MIICTRL, 0xBFFF);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004548
Yaniv Rosner503976e2012-11-27 03:46:34 +00004549 bnx2x_cl45_read_and_write(bp, phy, MDIO_WC_DEVAD,
4550 MDIO_WC_REG_IEEE0BLK_MIICNTL, 0xfffe);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004551
4552 /* Update those 1-copy registers */
4553 CL22_WR_OVER_CL45(bp, phy, MDIO_REG_BANK_AER_BLOCK,
4554 MDIO_AER_BLOCK_AER_REG, 0);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00004555 /* Enable 1G MDIO (1-copy) */
Yaniv Rosner503976e2012-11-27 03:46:34 +00004556 bnx2x_cl45_read_and_write(bp, phy, MDIO_WC_DEVAD,
4557 MDIO_WC_REG_XGXSBLK0_XGXSCONTROL,
4558 ~0x10);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004559
Yaniv Rosner503976e2012-11-27 03:46:34 +00004560 bnx2x_cl45_read_and_write(bp, phy, MDIO_WC_DEVAD,
4561 MDIO_WC_REG_XGXSBLK1_LANECTRL2, 0xff00);
Yaniv Rosnercd1a26a2012-10-31 05:46:54 +00004562 lane = bnx2x_get_warpcore_lane(phy, params);
4563 /* Disable CL36 PCS Tx */
4564 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4565 MDIO_WC_REG_XGXSBLK1_LANECTRL0, &val16);
4566 val16 |= (0x11 << lane);
4567 if (phy->flags & FLAGS_WC_DUAL_MODE)
4568 val16 |= (0x22 << lane);
4569 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4570 MDIO_WC_REG_XGXSBLK1_LANECTRL0, val16);
4571
4572 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4573 MDIO_WC_REG_XGXSBLK1_LANECTRL1, &val16);
4574 val16 &= ~(0x0303 << (lane << 1));
4575 val16 |= (0x0101 << (lane << 1));
4576 if (phy->flags & FLAGS_WC_DUAL_MODE) {
4577 val16 &= ~(0x0c0c << (lane << 1));
4578 val16 |= (0x0404 << (lane << 1));
4579 }
4580
4581 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
4582 MDIO_WC_REG_XGXSBLK1_LANECTRL1, val16);
4583 /* Restore AER */
4584 bnx2x_set_aer_mmd(params, phy);
4585
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004586}
4587
4588static void bnx2x_set_warpcore_loopback(struct bnx2x_phy *phy,
4589 struct link_params *params)
4590{
4591 struct bnx2x *bp = params->bp;
4592 u16 val16;
4593 u32 lane;
4594 DP(NETIF_MSG_LINK, "Setting Warpcore loopback type %x, speed %d\n",
4595 params->loopback_mode, phy->req_line_speed);
4596
Yaniv Rosner4e7b4992012-11-27 03:46:29 +00004597 if (phy->req_line_speed < SPEED_10000 ||
4598 phy->supported & SUPPORTED_20000baseKR2_Full) {
4599 /* 10/100/1000/20G-KR2 */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004600
4601 /* Update those 1-copy registers */
4602 CL22_WR_OVER_CL45(bp, phy, MDIO_REG_BANK_AER_BLOCK,
4603 MDIO_AER_BLOCK_AER_REG, 0);
4604 /* Enable 1G MDIO (1-copy) */
Yuval Mintza351d492012-06-20 19:05:21 +00004605 bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
4606 MDIO_WC_REG_XGXSBLK0_XGXSCONTROL,
4607 0x10);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004608 /* Set 1G loopback based on lane (1-copy) */
4609 lane = bnx2x_get_warpcore_lane(phy, params);
4610 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
4611 MDIO_WC_REG_XGXSBLK1_LANECTRL2, &val16);
Yaniv Rosner4e7b4992012-11-27 03:46:29 +00004612 val16 |= (1<<lane);
4613 if (phy->flags & FLAGS_WC_DUAL_MODE)
4614 val16 |= (2<<lane);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004615 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
Yaniv Rosner503976e2012-11-27 03:46:34 +00004616 MDIO_WC_REG_XGXSBLK1_LANECTRL2,
4617 val16);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004618
4619 /* Switch back to 4-copy registers */
4620 bnx2x_set_aer_mmd(params, phy);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004621 } else {
Yaniv Rosner4e7b4992012-11-27 03:46:29 +00004622 /* 10G / 20G-DXGXS */
Yuval Mintza351d492012-06-20 19:05:21 +00004623 bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
4624 MDIO_WC_REG_COMBO_IEEE0_MIICTRL,
4625 0x4000);
Yuval Mintza351d492012-06-20 19:05:21 +00004626 bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
4627 MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x1);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004628 }
4629}
4630
4631
Yuval Mintzd2310232012-06-20 19:05:19 +00004632
4633static void bnx2x_sync_link(struct link_params *params,
4634 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004635{
4636 struct bnx2x *bp = params->bp;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00004637 u8 link_10g_plus;
Yaniv Rosnerde6f3372011-08-02 22:59:25 +00004638 if (vars->link_status & LINK_STATUS_PHYSICAL_LINK_FLAG)
4639 vars->phy_flags |= PHY_PHYSICAL_LINK_FLAG;
Yaniv Rosner2f751a82011-11-28 00:49:52 +00004640 vars->link_up = (vars->link_status & LINK_STATUS_LINK_UP);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004641 if (vars->link_up) {
4642 DP(NETIF_MSG_LINK, "phy link up\n");
4643
4644 vars->phy_link_up = 1;
4645 vars->duplex = DUPLEX_FULL;
4646 switch (vars->link_status &
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004647 LINK_STATUS_SPEED_AND_DUPLEX_MASK) {
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00004648 case LINK_10THD:
4649 vars->duplex = DUPLEX_HALF;
4650 /* Fall thru */
4651 case LINK_10TFD:
4652 vars->line_speed = SPEED_10;
4653 break;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004654
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00004655 case LINK_100TXHD:
4656 vars->duplex = DUPLEX_HALF;
4657 /* Fall thru */
4658 case LINK_100T4:
4659 case LINK_100TXFD:
4660 vars->line_speed = SPEED_100;
4661 break;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004662
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00004663 case LINK_1000THD:
4664 vars->duplex = DUPLEX_HALF;
4665 /* Fall thru */
4666 case LINK_1000TFD:
4667 vars->line_speed = SPEED_1000;
4668 break;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004669
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00004670 case LINK_2500THD:
4671 vars->duplex = DUPLEX_HALF;
4672 /* Fall thru */
4673 case LINK_2500TFD:
4674 vars->line_speed = SPEED_2500;
4675 break;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004676
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00004677 case LINK_10GTFD:
4678 vars->line_speed = SPEED_10000;
4679 break;
4680 case LINK_20GTFD:
4681 vars->line_speed = SPEED_20000;
4682 break;
4683 default:
4684 break;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004685 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004686 vars->flow_ctrl = 0;
4687 if (vars->link_status & LINK_STATUS_TX_FLOW_CONTROL_ENABLED)
4688 vars->flow_ctrl |= BNX2X_FLOW_CTRL_TX;
4689
4690 if (vars->link_status & LINK_STATUS_RX_FLOW_CONTROL_ENABLED)
4691 vars->flow_ctrl |= BNX2X_FLOW_CTRL_RX;
4692
4693 if (!vars->flow_ctrl)
4694 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
4695
4696 if (vars->line_speed &&
4697 ((vars->line_speed == SPEED_10) ||
4698 (vars->line_speed == SPEED_100))) {
4699 vars->phy_flags |= PHY_SGMII_FLAG;
4700 } else {
4701 vars->phy_flags &= ~PHY_SGMII_FLAG;
4702 }
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004703 if (vars->line_speed &&
4704 USES_WARPCORE(bp) &&
4705 (vars->line_speed == SPEED_1000))
4706 vars->phy_flags |= PHY_SGMII_FLAG;
Yuval Mintzd2310232012-06-20 19:05:19 +00004707 /* Anything 10 and over uses the bmac */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00004708 link_10g_plus = (vars->line_speed >= SPEED_10000);
4709
4710 if (link_10g_plus) {
4711 if (USES_WARPCORE(bp))
4712 vars->mac_type = MAC_TYPE_XMAC;
4713 else
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004714 vars->mac_type = MAC_TYPE_BMAC;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00004715 } else {
4716 if (USES_WARPCORE(bp))
4717 vars->mac_type = MAC_TYPE_UMAC;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00004718 else
4719 vars->mac_type = MAC_TYPE_EMAC;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00004720 }
Yuval Mintzd2310232012-06-20 19:05:19 +00004721 } else { /* Link down */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004722 DP(NETIF_MSG_LINK, "phy link down\n");
4723
4724 vars->phy_link_up = 0;
4725
4726 vars->line_speed = 0;
4727 vars->duplex = DUPLEX_FULL;
4728 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
4729
Yuval Mintzd2310232012-06-20 19:05:19 +00004730 /* Indicate no mac active */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004731 vars->mac_type = MAC_TYPE_NONE;
Yaniv Rosnerde6f3372011-08-02 22:59:25 +00004732 if (vars->link_status & LINK_STATUS_PHYSICAL_LINK_FLAG)
4733 vars->phy_flags |= PHY_HALF_OPEN_CONN_FLAG;
Yuval Mintzd0b8a6f2012-06-20 19:05:18 +00004734 if (vars->link_status & LINK_STATUS_SFP_TX_FAULT)
4735 vars->phy_flags |= PHY_SFP_TX_FAULT_FLAG;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004736 }
Yaniv Rosner2f751a82011-11-28 00:49:52 +00004737}
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004738
Yaniv Rosner2f751a82011-11-28 00:49:52 +00004739void bnx2x_link_status_update(struct link_params *params,
4740 struct link_vars *vars)
4741{
4742 struct bnx2x *bp = params->bp;
4743 u8 port = params->port;
4744 u32 sync_offset, media_types;
4745 /* Update PHY configuration */
4746 set_phy_vars(params, vars);
4747
4748 vars->link_status = REG_RD(bp, params->shmem_base +
4749 offsetof(struct shmem_region,
4750 port_mb[port].link_status));
Mahesh Bandewar7614fe82013-01-30 07:00:12 +00004751
4752 /* Force link UP in non LOOPBACK_EXT loopback mode(s) */
4753 if (bp->link_params.loopback_mode != LOOPBACK_NONE &&
4754 bp->link_params.loopback_mode != LOOPBACK_EXT)
4755 vars->link_status |= LINK_STATUS_LINK_UP;
4756
Yuval Mintz08e9acc2012-09-10 05:51:04 +00004757 if (bnx2x_eee_has_cap(params))
4758 vars->eee_status = REG_RD(bp, params->shmem2_base +
4759 offsetof(struct shmem2_region,
4760 eee_status[params->port]));
Yaniv Rosner2f751a82011-11-28 00:49:52 +00004761
4762 vars->phy_flags = PHY_XGXS_FLAG;
4763 bnx2x_sync_link(params, vars);
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00004764 /* Sync media type */
4765 sync_offset = params->shmem_base +
4766 offsetof(struct shmem_region,
4767 dev_info.port_hw_config[port].media_type);
4768 media_types = REG_RD(bp, sync_offset);
4769
4770 params->phy[INT_PHY].media_type =
4771 (media_types & PORT_HW_CFG_MEDIA_TYPE_PHY0_MASK) >>
4772 PORT_HW_CFG_MEDIA_TYPE_PHY0_SHIFT;
4773 params->phy[EXT_PHY1].media_type =
4774 (media_types & PORT_HW_CFG_MEDIA_TYPE_PHY1_MASK) >>
4775 PORT_HW_CFG_MEDIA_TYPE_PHY1_SHIFT;
4776 params->phy[EXT_PHY2].media_type =
4777 (media_types & PORT_HW_CFG_MEDIA_TYPE_PHY2_MASK) >>
4778 PORT_HW_CFG_MEDIA_TYPE_PHY2_SHIFT;
4779 DP(NETIF_MSG_LINK, "media_types = 0x%x\n", media_types);
4780
Yaniv Rosner020c7e32011-05-31 21:28:43 +00004781 /* Sync AEU offset */
4782 sync_offset = params->shmem_base +
4783 offsetof(struct shmem_region,
4784 dev_info.port_hw_config[port].aeu_int_mask);
4785
4786 vars->aeu_int_mask = REG_RD(bp, sync_offset);
4787
Yaniv Rosnerb8d6d082011-07-05 01:06:27 +00004788 /* Sync PFC status */
4789 if (vars->link_status & LINK_STATUS_PFC_ENABLED)
4790 params->feature_config_flags |=
4791 FEATURE_CONFIG_PFC_ENABLED;
4792 else
4793 params->feature_config_flags &=
4794 ~FEATURE_CONFIG_PFC_ENABLED;
4795
Yaniv Rosner4e7b4992012-11-27 03:46:29 +00004796 if (SHMEM2_HAS(bp, link_attr_sync))
4797 vars->link_attr_sync = SHMEM2_RD(bp,
4798 link_attr_sync[params->port]);
4799
Yaniv Rosner020c7e32011-05-31 21:28:43 +00004800 DP(NETIF_MSG_LINK, "link_status 0x%x phy_link_up %x int_mask 0x%x\n",
4801 vars->link_status, vars->phy_link_up, vars->aeu_int_mask);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00004802 DP(NETIF_MSG_LINK, "line_speed %x duplex %x flow_ctrl 0x%x\n",
4803 vars->line_speed, vars->duplex, vars->flow_ctrl);
4804}
4805
Yaniv Rosnere10bc842010-09-07 11:40:50 +00004806static void bnx2x_set_master_ln(struct link_params *params,
4807 struct bnx2x_phy *phy)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004808{
4809 struct bnx2x *bp = params->bp;
4810 u16 new_master_ln, ser_lane;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004811 ser_lane = ((params->lane_config &
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004812 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_MASK) >>
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004813 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_SHIFT);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004814
Yuval Mintzd2310232012-06-20 19:05:19 +00004815 /* Set the master_ln for AN */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004816 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004817 MDIO_REG_BANK_XGXS_BLOCK2,
4818 MDIO_XGXS_BLOCK2_TEST_MODE_LANE,
4819 &new_master_ln);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004820
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004821 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004822 MDIO_REG_BANK_XGXS_BLOCK2 ,
4823 MDIO_XGXS_BLOCK2_TEST_MODE_LANE,
4824 (new_master_ln | ser_lane));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004825}
4826
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00004827static int bnx2x_reset_unicore(struct link_params *params,
4828 struct bnx2x_phy *phy,
4829 u8 set_serdes)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004830{
4831 struct bnx2x *bp = params->bp;
4832 u16 mii_control;
4833 u16 i;
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004834 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004835 MDIO_REG_BANK_COMBO_IEEE0,
4836 MDIO_COMBO_IEEE0_MII_CONTROL, &mii_control);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004837
Yuval Mintzd2310232012-06-20 19:05:19 +00004838 /* Reset the unicore */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004839 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004840 MDIO_REG_BANK_COMBO_IEEE0,
4841 MDIO_COMBO_IEEE0_MII_CONTROL,
4842 (mii_control |
4843 MDIO_COMBO_IEEO_MII_CONTROL_RESET));
Yaniv Rosnere10bc842010-09-07 11:40:50 +00004844 if (set_serdes)
4845 bnx2x_set_serdes_access(bp, params->port);
Eilon Greensteinc1b73992009-02-12 08:37:07 +00004846
Yuval Mintzd2310232012-06-20 19:05:19 +00004847 /* Wait for the reset to self clear */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004848 for (i = 0; i < MDIO_ACCESS_TIMEOUT; i++) {
4849 udelay(5);
4850
Yuval Mintzd2310232012-06-20 19:05:19 +00004851 /* The reset erased the previous bank value */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004852 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004853 MDIO_REG_BANK_COMBO_IEEE0,
4854 MDIO_COMBO_IEEE0_MII_CONTROL,
4855 &mii_control);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004856
4857 if (!(mii_control & MDIO_COMBO_IEEO_MII_CONTROL_RESET)) {
4858 udelay(5);
4859 return 0;
4860 }
4861 }
4862
Yaniv Rosner6d870c32011-01-31 04:22:20 +00004863 netdev_err(bp->dev, "Warning: PHY was not initialized,"
4864 " Port %d\n",
4865 params->port);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004866 DP(NETIF_MSG_LINK, "BUG! XGXS is still in reset!\n");
4867 return -EINVAL;
4868
4869}
4870
Yaniv Rosnere10bc842010-09-07 11:40:50 +00004871static void bnx2x_set_swap_lanes(struct link_params *params,
4872 struct bnx2x_phy *phy)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004873{
4874 struct bnx2x *bp = params->bp;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00004875 /* Each two bits represents a lane number:
4876 * No swap is 0123 => 0x1b no need to enable the swap
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00004877 */
Yaniv Rosner2f751a82011-11-28 00:49:52 +00004878 u16 rx_lane_swap, tx_lane_swap;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004879
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004880 rx_lane_swap = ((params->lane_config &
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004881 PORT_HW_CFG_LANE_SWAP_CFG_RX_MASK) >>
4882 PORT_HW_CFG_LANE_SWAP_CFG_RX_SHIFT);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004883 tx_lane_swap = ((params->lane_config &
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004884 PORT_HW_CFG_LANE_SWAP_CFG_TX_MASK) >>
4885 PORT_HW_CFG_LANE_SWAP_CFG_TX_SHIFT);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004886
4887 if (rx_lane_swap != 0x1b) {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004888 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004889 MDIO_REG_BANK_XGXS_BLOCK2,
4890 MDIO_XGXS_BLOCK2_RX_LN_SWAP,
4891 (rx_lane_swap |
4892 MDIO_XGXS_BLOCK2_RX_LN_SWAP_ENABLE |
4893 MDIO_XGXS_BLOCK2_RX_LN_SWAP_FORCE_ENABLE));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004894 } else {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004895 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004896 MDIO_REG_BANK_XGXS_BLOCK2,
4897 MDIO_XGXS_BLOCK2_RX_LN_SWAP, 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004898 }
4899
4900 if (tx_lane_swap != 0x1b) {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004901 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004902 MDIO_REG_BANK_XGXS_BLOCK2,
4903 MDIO_XGXS_BLOCK2_TX_LN_SWAP,
4904 (tx_lane_swap |
4905 MDIO_XGXS_BLOCK2_TX_LN_SWAP_ENABLE));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004906 } else {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004907 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004908 MDIO_REG_BANK_XGXS_BLOCK2,
4909 MDIO_XGXS_BLOCK2_TX_LN_SWAP, 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004910 }
4911}
4912
Yaniv Rosnere10bc842010-09-07 11:40:50 +00004913static void bnx2x_set_parallel_detection(struct bnx2x_phy *phy,
4914 struct link_params *params)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004915{
4916 struct bnx2x *bp = params->bp;
4917 u16 control2;
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004918 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004919 MDIO_REG_BANK_SERDES_DIGITAL,
4920 MDIO_SERDES_DIGITAL_A_1000X_CONTROL2,
4921 &control2);
Yaniv Rosner7aa07112010-09-07 11:41:01 +00004922 if (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)
Yaniv Rosner18afb0a2009-11-05 19:18:04 +02004923 control2 |= MDIO_SERDES_DIGITAL_A_1000X_CONTROL2_PRL_DT_EN;
4924 else
4925 control2 &= ~MDIO_SERDES_DIGITAL_A_1000X_CONTROL2_PRL_DT_EN;
Yaniv Rosner7aa07112010-09-07 11:41:01 +00004926 DP(NETIF_MSG_LINK, "phy->speed_cap_mask = 0x%x, control2 = 0x%x\n",
4927 phy->speed_cap_mask, control2);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004928 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004929 MDIO_REG_BANK_SERDES_DIGITAL,
4930 MDIO_SERDES_DIGITAL_A_1000X_CONTROL2,
4931 control2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004932
Yaniv Rosnere10bc842010-09-07 11:40:50 +00004933 if ((phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT) &&
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00004934 (phy->speed_cap_mask &
Yaniv Rosner18afb0a2009-11-05 19:18:04 +02004935 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004936 DP(NETIF_MSG_LINK, "XGXS\n");
4937
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004938 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004939 MDIO_REG_BANK_10G_PARALLEL_DETECT,
4940 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_LINK,
4941 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_LINK_CNT);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004942
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004943 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004944 MDIO_REG_BANK_10G_PARALLEL_DETECT,
4945 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_CONTROL,
4946 &control2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004947
4948
4949 control2 |=
4950 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_CONTROL_PARDET10G_EN;
4951
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004952 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004953 MDIO_REG_BANK_10G_PARALLEL_DETECT,
4954 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_CONTROL,
4955 control2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004956
4957 /* Disable parallel detection of HiG */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004958 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004959 MDIO_REG_BANK_XGXS_BLOCK2,
4960 MDIO_XGXS_BLOCK2_UNICORE_MODE_10G,
4961 MDIO_XGXS_BLOCK2_UNICORE_MODE_10G_CX4_XGXS |
4962 MDIO_XGXS_BLOCK2_UNICORE_MODE_10G_HIGIG_XGXS);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004963 }
4964}
4965
Yaniv Rosnere10bc842010-09-07 11:40:50 +00004966static void bnx2x_set_autoneg(struct bnx2x_phy *phy,
4967 struct link_params *params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004968 struct link_vars *vars,
4969 u8 enable_cl73)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004970{
4971 struct bnx2x *bp = params->bp;
4972 u16 reg_val;
4973
4974 /* CL37 Autoneg */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004975 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004976 MDIO_REG_BANK_COMBO_IEEE0,
4977 MDIO_COMBO_IEEE0_MII_CONTROL, &reg_val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004978
4979 /* CL37 Autoneg Enabled */
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07004980 if (vars->line_speed == SPEED_AUTO_NEG)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004981 reg_val |= MDIO_COMBO_IEEO_MII_CONTROL_AN_EN;
4982 else /* CL37 Autoneg Disabled */
4983 reg_val &= ~(MDIO_COMBO_IEEO_MII_CONTROL_AN_EN |
4984 MDIO_COMBO_IEEO_MII_CONTROL_RESTART_AN);
4985
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004986 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004987 MDIO_REG_BANK_COMBO_IEEE0,
4988 MDIO_COMBO_IEEE0_MII_CONTROL, reg_val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004989
4990 /* Enable/Disable Autodetection */
4991
Yaniv Rosnercd2be892011-01-31 04:21:45 +00004992 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00004993 MDIO_REG_BANK_SERDES_DIGITAL,
4994 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1, &reg_val);
Eilon Greenstein239d6862009-08-12 08:23:04 +00004995 reg_val &= ~(MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_SIGNAL_DETECT_EN |
4996 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_INVERT_SIGNAL_DETECT);
4997 reg_val |= MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_FIBER_MODE;
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07004998 if (vars->line_speed == SPEED_AUTO_NEG)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07004999 reg_val |= MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_AUTODET;
5000 else
5001 reg_val &= ~MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_AUTODET;
5002
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005003 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005004 MDIO_REG_BANK_SERDES_DIGITAL,
5005 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1, reg_val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005006
5007 /* Enable TetonII and BAM autoneg */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005008 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005009 MDIO_REG_BANK_BAM_NEXT_PAGE,
5010 MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL,
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005011 &reg_val);
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07005012 if (vars->line_speed == SPEED_AUTO_NEG) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005013 /* Enable BAM aneg Mode and TetonII aneg Mode */
5014 reg_val |= (MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL_BAM_MODE |
5015 MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL_TETON_AN);
5016 } else {
5017 /* TetonII and BAM Autoneg Disabled */
5018 reg_val &= ~(MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL_BAM_MODE |
5019 MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL_TETON_AN);
5020 }
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005021 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005022 MDIO_REG_BANK_BAM_NEXT_PAGE,
5023 MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL,
5024 reg_val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005025
Eilon Greenstein239d6862009-08-12 08:23:04 +00005026 if (enable_cl73) {
5027 /* Enable Cl73 FSM status bits */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005028 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005029 MDIO_REG_BANK_CL73_USERB0,
5030 MDIO_CL73_USERB0_CL73_UCTRL,
5031 0xe);
Eilon Greenstein239d6862009-08-12 08:23:04 +00005032
5033 /* Enable BAM Station Manager*/
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005034 CL22_WR_OVER_CL45(bp, phy,
Eilon Greenstein239d6862009-08-12 08:23:04 +00005035 MDIO_REG_BANK_CL73_USERB0,
5036 MDIO_CL73_USERB0_CL73_BAM_CTRL1,
5037 MDIO_CL73_USERB0_CL73_BAM_CTRL1_BAM_EN |
5038 MDIO_CL73_USERB0_CL73_BAM_CTRL1_BAM_STATION_MNGR_EN |
5039 MDIO_CL73_USERB0_CL73_BAM_CTRL1_BAM_NP_AFTER_BP_EN);
5040
Yaniv Rosner7846e472009-11-05 19:18:07 +02005041 /* Advertise CL73 link speeds */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005042 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005043 MDIO_REG_BANK_CL73_IEEEB1,
5044 MDIO_CL73_IEEEB1_AN_ADV2,
5045 &reg_val);
Yaniv Rosner7aa07112010-09-07 11:41:01 +00005046 if (phy->speed_cap_mask &
Yaniv Rosner7846e472009-11-05 19:18:07 +02005047 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
5048 reg_val |= MDIO_CL73_IEEEB1_AN_ADV2_ADVR_10G_KX4;
Yaniv Rosner7aa07112010-09-07 11:41:01 +00005049 if (phy->speed_cap_mask &
Yaniv Rosner7846e472009-11-05 19:18:07 +02005050 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)
5051 reg_val |= MDIO_CL73_IEEEB1_AN_ADV2_ADVR_1000M_KX;
Eilon Greenstein239d6862009-08-12 08:23:04 +00005052
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005053 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005054 MDIO_REG_BANK_CL73_IEEEB1,
5055 MDIO_CL73_IEEEB1_AN_ADV2,
5056 reg_val);
Eilon Greenstein239d6862009-08-12 08:23:04 +00005057
Eilon Greenstein239d6862009-08-12 08:23:04 +00005058 /* CL73 Autoneg Enabled */
5059 reg_val = MDIO_CL73_IEEEB0_CL73_AN_CONTROL_AN_EN;
5060
5061 } else /* CL73 Autoneg Disabled */
5062 reg_val = 0;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005063
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005064 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005065 MDIO_REG_BANK_CL73_IEEEB0,
5066 MDIO_CL73_IEEEB0_CL73_AN_CONTROL, reg_val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005067}
5068
Yuval Mintzd2310232012-06-20 19:05:19 +00005069/* Program SerDes, forced speed */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00005070static void bnx2x_program_serdes(struct bnx2x_phy *phy,
5071 struct link_params *params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005072 struct link_vars *vars)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005073{
5074 struct bnx2x *bp = params->bp;
5075 u16 reg_val;
5076
Yuval Mintzd2310232012-06-20 19:05:19 +00005077 /* Program duplex, disable autoneg and sgmii*/
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005078 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005079 MDIO_REG_BANK_COMBO_IEEE0,
5080 MDIO_COMBO_IEEE0_MII_CONTROL, &reg_val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005081 reg_val &= ~(MDIO_COMBO_IEEO_MII_CONTROL_FULL_DUPLEX |
Eilon Greenstein57937202009-08-12 08:23:53 +00005082 MDIO_COMBO_IEEO_MII_CONTROL_AN_EN |
5083 MDIO_COMBO_IEEO_MII_CONTROL_MAN_SGMII_SP_MASK);
Yaniv Rosner7aa07112010-09-07 11:41:01 +00005084 if (phy->req_duplex == DUPLEX_FULL)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005085 reg_val |= MDIO_COMBO_IEEO_MII_CONTROL_FULL_DUPLEX;
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005086 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005087 MDIO_REG_BANK_COMBO_IEEE0,
5088 MDIO_COMBO_IEEE0_MII_CONTROL, reg_val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005089
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00005090 /* Program speed
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005091 * - needed only if the speed is greater than 1G (2.5G or 10G)
5092 */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005093 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005094 MDIO_REG_BANK_SERDES_DIGITAL,
5095 MDIO_SERDES_DIGITAL_MISC1, &reg_val);
Yuval Mintzd2310232012-06-20 19:05:19 +00005096 /* Clearing the speed value before setting the right speed */
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07005097 DP(NETIF_MSG_LINK, "MDIO_REG_BANK_SERDES_DIGITAL = 0x%x\n", reg_val);
5098
5099 reg_val &= ~(MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_MASK |
5100 MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_SEL);
5101
5102 if (!((vars->line_speed == SPEED_1000) ||
5103 (vars->line_speed == SPEED_100) ||
5104 (vars->line_speed == SPEED_10))) {
5105
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005106 reg_val |= (MDIO_SERDES_DIGITAL_MISC1_REFCLK_SEL_156_25M |
5107 MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_SEL);
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07005108 if (vars->line_speed == SPEED_10000)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005109 reg_val |=
5110 MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_10G_CX4;
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07005111 }
5112
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005113 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005114 MDIO_REG_BANK_SERDES_DIGITAL,
5115 MDIO_SERDES_DIGITAL_MISC1, reg_val);
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07005116
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005117}
5118
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00005119static void bnx2x_set_brcm_cl37_advertisement(struct bnx2x_phy *phy,
5120 struct link_params *params)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005121{
5122 struct bnx2x *bp = params->bp;
5123 u16 val = 0;
5124
Yuval Mintzd2310232012-06-20 19:05:19 +00005125 /* Set extended capabilities */
Yaniv Rosner7aa07112010-09-07 11:41:01 +00005126 if (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005127 val |= MDIO_OVER_1G_UP1_2_5G;
Yaniv Rosner7aa07112010-09-07 11:41:01 +00005128 if (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005129 val |= MDIO_OVER_1G_UP1_10G;
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005130 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005131 MDIO_REG_BANK_OVER_1G,
5132 MDIO_OVER_1G_UP1, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005133
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005134 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005135 MDIO_REG_BANK_OVER_1G,
5136 MDIO_OVER_1G_UP3, 0x400);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005137}
5138
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00005139static void bnx2x_set_ieee_aneg_advertisement(struct bnx2x_phy *phy,
5140 struct link_params *params,
5141 u16 ieee_fc)
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07005142{
5143 struct bnx2x *bp = params->bp;
Yaniv Rosner7846e472009-11-05 19:18:07 +02005144 u16 val;
Yuval Mintzd2310232012-06-20 19:05:19 +00005145 /* For AN, we are always publishing full duplex */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005146
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005147 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005148 MDIO_REG_BANK_COMBO_IEEE0,
5149 MDIO_COMBO_IEEE0_AUTO_NEG_ADV, ieee_fc);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005150 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005151 MDIO_REG_BANK_CL73_IEEEB1,
5152 MDIO_CL73_IEEEB1_AN_ADV1, &val);
Yaniv Rosner7846e472009-11-05 19:18:07 +02005153 val &= ~MDIO_CL73_IEEEB1_AN_ADV1_PAUSE_BOTH;
5154 val |= ((ieee_fc<<3) & MDIO_CL73_IEEEB1_AN_ADV1_PAUSE_MASK);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005155 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005156 MDIO_REG_BANK_CL73_IEEEB1,
5157 MDIO_CL73_IEEEB1_AN_ADV1, val);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005158}
5159
Yaniv Rosnere10bc842010-09-07 11:40:50 +00005160static void bnx2x_restart_autoneg(struct bnx2x_phy *phy,
5161 struct link_params *params,
5162 u8 enable_cl73)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005163{
5164 struct bnx2x *bp = params->bp;
Eilon Greenstein3a36f2e2009-02-12 08:37:09 +00005165 u16 mii_control;
Eilon Greenstein239d6862009-08-12 08:23:04 +00005166
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005167 DP(NETIF_MSG_LINK, "bnx2x_restart_autoneg\n");
Eilon Greenstein3a36f2e2009-02-12 08:37:09 +00005168 /* Enable and restart BAM/CL37 aneg */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005169
Eilon Greenstein239d6862009-08-12 08:23:04 +00005170 if (enable_cl73) {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005171 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005172 MDIO_REG_BANK_CL73_IEEEB0,
5173 MDIO_CL73_IEEEB0_CL73_AN_CONTROL,
5174 &mii_control);
Eilon Greenstein239d6862009-08-12 08:23:04 +00005175
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005176 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005177 MDIO_REG_BANK_CL73_IEEEB0,
5178 MDIO_CL73_IEEEB0_CL73_AN_CONTROL,
5179 (mii_control |
5180 MDIO_CL73_IEEEB0_CL73_AN_CONTROL_AN_EN |
5181 MDIO_CL73_IEEEB0_CL73_AN_CONTROL_RESTART_AN));
Eilon Greenstein239d6862009-08-12 08:23:04 +00005182 } else {
5183
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005184 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005185 MDIO_REG_BANK_COMBO_IEEE0,
5186 MDIO_COMBO_IEEE0_MII_CONTROL,
5187 &mii_control);
Eilon Greenstein239d6862009-08-12 08:23:04 +00005188 DP(NETIF_MSG_LINK,
5189 "bnx2x_restart_autoneg mii_control before = 0x%x\n",
5190 mii_control);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005191 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005192 MDIO_REG_BANK_COMBO_IEEE0,
5193 MDIO_COMBO_IEEE0_MII_CONTROL,
5194 (mii_control |
5195 MDIO_COMBO_IEEO_MII_CONTROL_AN_EN |
5196 MDIO_COMBO_IEEO_MII_CONTROL_RESTART_AN));
Eilon Greenstein239d6862009-08-12 08:23:04 +00005197 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005198}
5199
Yaniv Rosnere10bc842010-09-07 11:40:50 +00005200static void bnx2x_initialize_sgmii_process(struct bnx2x_phy *phy,
5201 struct link_params *params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005202 struct link_vars *vars)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005203{
5204 struct bnx2x *bp = params->bp;
5205 u16 control1;
5206
Yuval Mintzd2310232012-06-20 19:05:19 +00005207 /* In SGMII mode, the unicore is always slave */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005208
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005209 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005210 MDIO_REG_BANK_SERDES_DIGITAL,
5211 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1,
5212 &control1);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005213 control1 |= MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_INVERT_SIGNAL_DETECT;
Yuval Mintzd2310232012-06-20 19:05:19 +00005214 /* Set sgmii mode (and not fiber) */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005215 control1 &= ~(MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_FIBER_MODE |
5216 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_AUTODET |
5217 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_MSTR_MODE);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005218 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005219 MDIO_REG_BANK_SERDES_DIGITAL,
5220 MDIO_SERDES_DIGITAL_A_1000X_CONTROL1,
5221 control1);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005222
Yuval Mintzd2310232012-06-20 19:05:19 +00005223 /* If forced speed */
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07005224 if (!(vars->line_speed == SPEED_AUTO_NEG)) {
Yuval Mintzd2310232012-06-20 19:05:19 +00005225 /* Set speed, disable autoneg */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005226 u16 mii_control;
5227
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005228 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005229 MDIO_REG_BANK_COMBO_IEEE0,
5230 MDIO_COMBO_IEEE0_MII_CONTROL,
5231 &mii_control);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005232 mii_control &= ~(MDIO_COMBO_IEEO_MII_CONTROL_AN_EN |
5233 MDIO_COMBO_IEEO_MII_CONTROL_MAN_SGMII_SP_MASK|
5234 MDIO_COMBO_IEEO_MII_CONTROL_FULL_DUPLEX);
5235
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07005236 switch (vars->line_speed) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005237 case SPEED_100:
5238 mii_control |=
5239 MDIO_COMBO_IEEO_MII_CONTROL_MAN_SGMII_SP_100;
5240 break;
5241 case SPEED_1000:
5242 mii_control |=
5243 MDIO_COMBO_IEEO_MII_CONTROL_MAN_SGMII_SP_1000;
5244 break;
5245 case SPEED_10:
Yuval Mintzd2310232012-06-20 19:05:19 +00005246 /* There is nothing to set for 10M */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005247 break;
5248 default:
Yuval Mintzd2310232012-06-20 19:05:19 +00005249 /* Invalid speed for SGMII */
Yaniv Rosner8c99e7b2008-08-13 15:56:17 -07005250 DP(NETIF_MSG_LINK, "Invalid line_speed 0x%x\n",
5251 vars->line_speed);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005252 break;
5253 }
5254
Yuval Mintzd2310232012-06-20 19:05:19 +00005255 /* Setting the full duplex */
Yaniv Rosner7aa07112010-09-07 11:41:01 +00005256 if (phy->req_duplex == DUPLEX_FULL)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005257 mii_control |=
5258 MDIO_COMBO_IEEO_MII_CONTROL_FULL_DUPLEX;
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005259 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005260 MDIO_REG_BANK_COMBO_IEEE0,
5261 MDIO_COMBO_IEEE0_MII_CONTROL,
5262 mii_control);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005263
5264 } else { /* AN mode */
Yuval Mintzd2310232012-06-20 19:05:19 +00005265 /* Enable and restart AN */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00005266 bnx2x_restart_autoneg(phy, params, 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005267 }
5268}
5269
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00005270/* Link management
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005271 */
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00005272static int bnx2x_direct_parallel_detect_used(struct bnx2x_phy *phy,
5273 struct link_params *params)
Yaniv Rosner15ddd2d02009-11-05 19:18:12 +02005274{
5275 struct bnx2x *bp = params->bp;
5276 u16 pd_10g, status2_1000x;
Yaniv Rosner7aa07112010-09-07 11:41:01 +00005277 if (phy->req_line_speed != SPEED_AUTO_NEG)
5278 return 0;
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005279 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005280 MDIO_REG_BANK_SERDES_DIGITAL,
5281 MDIO_SERDES_DIGITAL_A_1000X_STATUS2,
5282 &status2_1000x);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005283 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005284 MDIO_REG_BANK_SERDES_DIGITAL,
5285 MDIO_SERDES_DIGITAL_A_1000X_STATUS2,
5286 &status2_1000x);
Yaniv Rosner15ddd2d02009-11-05 19:18:12 +02005287 if (status2_1000x & MDIO_SERDES_DIGITAL_A_1000X_STATUS2_AN_DISABLED) {
5288 DP(NETIF_MSG_LINK, "1G parallel detect link on port %d\n",
5289 params->port);
5290 return 1;
5291 }
5292
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005293 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005294 MDIO_REG_BANK_10G_PARALLEL_DETECT,
5295 MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_STATUS,
5296 &pd_10g);
Yaniv Rosner15ddd2d02009-11-05 19:18:12 +02005297
5298 if (pd_10g & MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_STATUS_PD_LINK) {
5299 DP(NETIF_MSG_LINK, "10G parallel detect link on port %d\n",
5300 params->port);
5301 return 1;
5302 }
5303 return 0;
5304}
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005305
Mintz Yuval9e7e8392012-02-15 02:10:24 +00005306static void bnx2x_update_adv_fc(struct bnx2x_phy *phy,
5307 struct link_params *params,
5308 struct link_vars *vars,
5309 u32 gp_status)
5310{
5311 u16 ld_pause; /* local driver */
5312 u16 lp_pause; /* link partner */
5313 u16 pause_result;
5314 struct bnx2x *bp = params->bp;
5315 if ((gp_status &
5316 (MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_AUTONEG_COMPLETE |
5317 MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_MR_LP_NP_AN_ABLE)) ==
5318 (MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_AUTONEG_COMPLETE |
5319 MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_MR_LP_NP_AN_ABLE)) {
5320
5321 CL22_RD_OVER_CL45(bp, phy,
5322 MDIO_REG_BANK_CL73_IEEEB1,
5323 MDIO_CL73_IEEEB1_AN_ADV1,
5324 &ld_pause);
5325 CL22_RD_OVER_CL45(bp, phy,
5326 MDIO_REG_BANK_CL73_IEEEB1,
5327 MDIO_CL73_IEEEB1_AN_LP_ADV1,
5328 &lp_pause);
5329 pause_result = (ld_pause &
5330 MDIO_CL73_IEEEB1_AN_ADV1_PAUSE_MASK) >> 8;
5331 pause_result |= (lp_pause &
5332 MDIO_CL73_IEEEB1_AN_LP_ADV1_PAUSE_MASK) >> 10;
5333 DP(NETIF_MSG_LINK, "pause_result CL73 0x%x\n", pause_result);
5334 } else {
5335 CL22_RD_OVER_CL45(bp, phy,
5336 MDIO_REG_BANK_COMBO_IEEE0,
5337 MDIO_COMBO_IEEE0_AUTO_NEG_ADV,
5338 &ld_pause);
5339 CL22_RD_OVER_CL45(bp, phy,
5340 MDIO_REG_BANK_COMBO_IEEE0,
5341 MDIO_COMBO_IEEE0_AUTO_NEG_LINK_PARTNER_ABILITY1,
5342 &lp_pause);
5343 pause_result = (ld_pause &
5344 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK)>>5;
5345 pause_result |= (lp_pause &
5346 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK)>>7;
5347 DP(NETIF_MSG_LINK, "pause_result CL37 0x%x\n", pause_result);
5348 }
5349 bnx2x_pause_resolve(vars, pause_result);
5350
5351}
5352
Yaniv Rosnere10bc842010-09-07 11:40:50 +00005353static void bnx2x_flow_ctrl_resolve(struct bnx2x_phy *phy,
5354 struct link_params *params,
5355 struct link_vars *vars,
5356 u32 gp_status)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005357{
5358 struct bnx2x *bp = params->bp;
David S. Millerc0700f92008-12-16 23:53:20 -08005359 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005360
Yuval Mintzd2310232012-06-20 19:05:19 +00005361 /* Resolve from gp_status in case of AN complete and not sgmii */
Mintz Yuval9e7e8392012-02-15 02:10:24 +00005362 if (phy->req_flow_ctrl != BNX2X_FLOW_CTRL_AUTO) {
5363 /* Update the advertised flow-controled of LD/LP in AN */
5364 if (phy->req_line_speed == SPEED_AUTO_NEG)
5365 bnx2x_update_adv_fc(phy, params, vars, gp_status);
5366 /* But set the flow-control result as the requested one */
Yaniv Rosner7aa07112010-09-07 11:41:01 +00005367 vars->flow_ctrl = phy->req_flow_ctrl;
Mintz Yuval9e7e8392012-02-15 02:10:24 +00005368 } else if (phy->req_line_speed != SPEED_AUTO_NEG)
Yaniv Rosner7aa07112010-09-07 11:41:01 +00005369 vars->flow_ctrl = params->req_fc_auto_adv;
5370 else if ((gp_status & MDIO_AN_CL73_OR_37_COMPLETE) &&
5371 (!(vars->phy_flags & PHY_SGMII_FLAG))) {
Yaniv Rosnere10bc842010-09-07 11:40:50 +00005372 if (bnx2x_direct_parallel_detect_used(phy, params)) {
Yaniv Rosner15ddd2d02009-11-05 19:18:12 +02005373 vars->flow_ctrl = params->req_fc_auto_adv;
5374 return;
5375 }
Mintz Yuval9e7e8392012-02-15 02:10:24 +00005376 bnx2x_update_adv_fc(phy, params, vars, gp_status);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005377 }
5378 DP(NETIF_MSG_LINK, "flow_ctrl 0x%x\n", vars->flow_ctrl);
5379}
5380
Yaniv Rosnere10bc842010-09-07 11:40:50 +00005381static void bnx2x_check_fallback_to_cl37(struct bnx2x_phy *phy,
5382 struct link_params *params)
Eilon Greenstein239d6862009-08-12 08:23:04 +00005383{
5384 struct bnx2x *bp = params->bp;
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00005385 u16 rx_status, ustat_val, cl37_fsm_received;
Eilon Greenstein239d6862009-08-12 08:23:04 +00005386 DP(NETIF_MSG_LINK, "bnx2x_check_fallback_to_cl37\n");
5387 /* Step 1: Make sure signal is detected */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005388 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005389 MDIO_REG_BANK_RX0,
5390 MDIO_RX0_RX_STATUS,
5391 &rx_status);
Eilon Greenstein239d6862009-08-12 08:23:04 +00005392 if ((rx_status & MDIO_RX0_RX_STATUS_SIGDET) !=
5393 (MDIO_RX0_RX_STATUS_SIGDET)) {
5394 DP(NETIF_MSG_LINK, "Signal is not detected. Restoring CL73."
5395 "rx_status(0x80b0) = 0x%x\n", rx_status);
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005396 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005397 MDIO_REG_BANK_CL73_IEEEB0,
5398 MDIO_CL73_IEEEB0_CL73_AN_CONTROL,
5399 MDIO_CL73_IEEEB0_CL73_AN_CONTROL_AN_EN);
Eilon Greenstein239d6862009-08-12 08:23:04 +00005400 return;
5401 }
5402 /* Step 2: Check CL73 state machine */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005403 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005404 MDIO_REG_BANK_CL73_USERB0,
5405 MDIO_CL73_USERB0_CL73_USTAT1,
5406 &ustat_val);
Eilon Greenstein239d6862009-08-12 08:23:04 +00005407 if ((ustat_val &
5408 (MDIO_CL73_USERB0_CL73_USTAT1_LINK_STATUS_CHECK |
5409 MDIO_CL73_USERB0_CL73_USTAT1_AN_GOOD_CHECK_BAM37)) !=
5410 (MDIO_CL73_USERB0_CL73_USTAT1_LINK_STATUS_CHECK |
5411 MDIO_CL73_USERB0_CL73_USTAT1_AN_GOOD_CHECK_BAM37)) {
5412 DP(NETIF_MSG_LINK, "CL73 state-machine is not stable. "
5413 "ustat_val(0x8371) = 0x%x\n", ustat_val);
5414 return;
5415 }
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00005416 /* Step 3: Check CL37 Message Pages received to indicate LP
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005417 * supports only CL37
5418 */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005419 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005420 MDIO_REG_BANK_REMOTE_PHY,
5421 MDIO_REMOTE_PHY_MISC_RX_STATUS,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00005422 &cl37_fsm_received);
5423 if ((cl37_fsm_received &
Eilon Greenstein239d6862009-08-12 08:23:04 +00005424 (MDIO_REMOTE_PHY_MISC_RX_STATUS_CL37_FSM_RECEIVED_OVER1G_MSG |
5425 MDIO_REMOTE_PHY_MISC_RX_STATUS_CL37_FSM_RECEIVED_BRCM_OUI_MSG)) !=
5426 (MDIO_REMOTE_PHY_MISC_RX_STATUS_CL37_FSM_RECEIVED_OVER1G_MSG |
5427 MDIO_REMOTE_PHY_MISC_RX_STATUS_CL37_FSM_RECEIVED_BRCM_OUI_MSG)) {
5428 DP(NETIF_MSG_LINK, "No CL37 FSM were received. "
5429 "misc_rx_status(0x8330) = 0x%x\n",
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00005430 cl37_fsm_received);
Eilon Greenstein239d6862009-08-12 08:23:04 +00005431 return;
5432 }
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00005433 /* The combined cl37/cl73 fsm state information indicating that
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005434 * we are connected to a device which does not support cl73, but
5435 * does support cl37 BAM. In this case we disable cl73 and
5436 * restart cl37 auto-neg
5437 */
5438
Eilon Greenstein239d6862009-08-12 08:23:04 +00005439 /* Disable CL73 */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005440 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005441 MDIO_REG_BANK_CL73_IEEEB0,
5442 MDIO_CL73_IEEEB0_CL73_AN_CONTROL,
5443 0);
Eilon Greenstein239d6862009-08-12 08:23:04 +00005444 /* Restart CL37 autoneg */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00005445 bnx2x_restart_autoneg(phy, params, 0);
Eilon Greenstein239d6862009-08-12 08:23:04 +00005446 DP(NETIF_MSG_LINK, "Disabling CL73, and restarting CL37 autoneg\n");
5447}
Yaniv Rosner7aa07112010-09-07 11:41:01 +00005448
5449static void bnx2x_xgxs_an_resolve(struct bnx2x_phy *phy,
5450 struct link_params *params,
5451 struct link_vars *vars,
5452 u32 gp_status)
5453{
5454 if (gp_status & MDIO_AN_CL73_OR_37_COMPLETE)
5455 vars->link_status |=
5456 LINK_STATUS_AUTO_NEGOTIATE_COMPLETE;
5457
5458 if (bnx2x_direct_parallel_detect_used(phy, params))
5459 vars->link_status |=
5460 LINK_STATUS_PARALLEL_DETECTION_USED;
5461}
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005462static int bnx2x_get_link_speed_duplex(struct bnx2x_phy *phy,
5463 struct link_params *params,
5464 struct link_vars *vars,
5465 u16 is_link_up,
5466 u16 speed_mask,
5467 u16 is_duplex)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005468{
5469 struct bnx2x *bp = params->bp;
Yaniv Rosner7aa07112010-09-07 11:41:01 +00005470 if (phy->req_line_speed == SPEED_AUTO_NEG)
5471 vars->link_status |= LINK_STATUS_AUTO_NEGOTIATE_ENABLED;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005472 if (is_link_up) {
5473 DP(NETIF_MSG_LINK, "phy link up\n");
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005474
5475 vars->phy_link_up = 1;
5476 vars->link_status |= LINK_STATUS_LINK_UP;
5477
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005478 switch (speed_mask) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005479 case GP_STATUS_10M:
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005480 vars->line_speed = SPEED_10;
Yaniv Rosner430d1722012-09-11 04:34:11 +00005481 if (is_duplex == DUPLEX_FULL)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005482 vars->link_status |= LINK_10TFD;
5483 else
5484 vars->link_status |= LINK_10THD;
5485 break;
5486
5487 case GP_STATUS_100M:
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005488 vars->line_speed = SPEED_100;
Yaniv Rosner430d1722012-09-11 04:34:11 +00005489 if (is_duplex == DUPLEX_FULL)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005490 vars->link_status |= LINK_100TXFD;
5491 else
5492 vars->link_status |= LINK_100TXHD;
5493 break;
5494
5495 case GP_STATUS_1G:
5496 case GP_STATUS_1G_KX:
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005497 vars->line_speed = SPEED_1000;
Yaniv Rosner430d1722012-09-11 04:34:11 +00005498 if (is_duplex == DUPLEX_FULL)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005499 vars->link_status |= LINK_1000TFD;
5500 else
5501 vars->link_status |= LINK_1000THD;
5502 break;
5503
5504 case GP_STATUS_2_5G:
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005505 vars->line_speed = SPEED_2500;
Yaniv Rosner430d1722012-09-11 04:34:11 +00005506 if (is_duplex == DUPLEX_FULL)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005507 vars->link_status |= LINK_2500TFD;
5508 else
5509 vars->link_status |= LINK_2500THD;
5510 break;
5511
5512 case GP_STATUS_5G:
5513 case GP_STATUS_6G:
5514 DP(NETIF_MSG_LINK,
5515 "link speed unsupported gp_status 0x%x\n",
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005516 speed_mask);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005517 return -EINVAL;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00005518
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005519 case GP_STATUS_10G_KX4:
5520 case GP_STATUS_10G_HIG:
5521 case GP_STATUS_10G_CX4:
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005522 case GP_STATUS_10G_KR:
5523 case GP_STATUS_10G_SFI:
5524 case GP_STATUS_10G_XFI:
5525 vars->line_speed = SPEED_10000;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005526 vars->link_status |= LINK_10GTFD;
5527 break;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005528 case GP_STATUS_20G_DXGXS:
Yaniv Rosner4e7b4992012-11-27 03:46:29 +00005529 case GP_STATUS_20G_KR2:
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005530 vars->line_speed = SPEED_20000;
5531 vars->link_status |= LINK_20GTFD;
5532 break;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005533 default:
5534 DP(NETIF_MSG_LINK,
5535 "link speed unsupported gp_status 0x%x\n",
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005536 speed_mask);
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00005537 return -EINVAL;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005538 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005539 } else { /* link_down */
5540 DP(NETIF_MSG_LINK, "phy link down\n");
5541
5542 vars->phy_link_up = 0;
Yaniv Rosner57963ed2008-08-13 15:55:28 -07005543
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005544 vars->duplex = DUPLEX_FULL;
David S. Millerc0700f92008-12-16 23:53:20 -08005545 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005546 vars->mac_type = MAC_TYPE_NONE;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005547 }
5548 DP(NETIF_MSG_LINK, " phy_link_up %x line_speed %d\n",
5549 vars->phy_link_up, vars->line_speed);
5550 return 0;
5551}
Eilon Greenstein239d6862009-08-12 08:23:04 +00005552
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005553static int bnx2x_link_settings_status(struct bnx2x_phy *phy,
5554 struct link_params *params,
5555 struct link_vars *vars)
5556{
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005557 struct bnx2x *bp = params->bp;
5558
5559 u16 gp_status, duplex = DUPLEX_HALF, link_up = 0, speed_mask;
5560 int rc = 0;
5561
5562 /* Read gp_status */
5563 CL22_RD_OVER_CL45(bp, phy,
5564 MDIO_REG_BANK_GP_STATUS,
5565 MDIO_GP_STATUS_TOP_AN_STATUS1,
5566 &gp_status);
5567 if (gp_status & MDIO_GP_STATUS_TOP_AN_STATUS1_DUPLEX_STATUS)
5568 duplex = DUPLEX_FULL;
5569 if (gp_status & MDIO_GP_STATUS_TOP_AN_STATUS1_LINK_STATUS)
5570 link_up = 1;
5571 speed_mask = gp_status & GP_STATUS_SPEED_MASK;
5572 DP(NETIF_MSG_LINK, "gp_status 0x%x, is_link_up %d, speed_mask 0x%x\n",
5573 gp_status, link_up, speed_mask);
5574 rc = bnx2x_get_link_speed_duplex(phy, params, vars, link_up, speed_mask,
5575 duplex);
5576 if (rc == -EINVAL)
5577 return rc;
5578
5579 if (gp_status & MDIO_GP_STATUS_TOP_AN_STATUS1_LINK_STATUS) {
5580 if (SINGLE_MEDIA_DIRECT(params)) {
Yaniv Rosner430d1722012-09-11 04:34:11 +00005581 vars->duplex = duplex;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005582 bnx2x_flow_ctrl_resolve(phy, params, vars, gp_status);
5583 if (phy->req_line_speed == SPEED_AUTO_NEG)
5584 bnx2x_xgxs_an_resolve(phy, params, vars,
5585 gp_status);
5586 }
Yuval Mintzd2310232012-06-20 19:05:19 +00005587 } else { /* Link_down */
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00005588 if ((phy->req_line_speed == SPEED_AUTO_NEG) &&
5589 SINGLE_MEDIA_DIRECT(params)) {
Eilon Greenstein239d6862009-08-12 08:23:04 +00005590 /* Check signal is detected */
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00005591 bnx2x_check_fallback_to_cl37(phy, params);
Eilon Greenstein239d6862009-08-12 08:23:04 +00005592 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005593 }
5594
Mintz Yuval9e7e8392012-02-15 02:10:24 +00005595 /* Read LP advertised speeds*/
5596 if (SINGLE_MEDIA_DIRECT(params) &&
5597 (vars->link_status & LINK_STATUS_AUTO_NEGOTIATE_COMPLETE)) {
5598 u16 val;
5599
5600 CL22_RD_OVER_CL45(bp, phy, MDIO_REG_BANK_CL73_IEEEB1,
5601 MDIO_CL73_IEEEB1_AN_LP_ADV2, &val);
5602
5603 if (val & MDIO_CL73_IEEEB1_AN_ADV2_ADVR_1000M_KX)
5604 vars->link_status |=
5605 LINK_STATUS_LINK_PARTNER_1000TFD_CAPABLE;
5606 if (val & (MDIO_CL73_IEEEB1_AN_ADV2_ADVR_10G_KX4 |
5607 MDIO_CL73_IEEEB1_AN_ADV2_ADVR_10G_KR))
5608 vars->link_status |=
5609 LINK_STATUS_LINK_PARTNER_10GXFD_CAPABLE;
5610
5611 CL22_RD_OVER_CL45(bp, phy, MDIO_REG_BANK_OVER_1G,
5612 MDIO_OVER_1G_LP_UP1, &val);
5613
5614 if (val & MDIO_OVER_1G_UP1_2_5G)
5615 vars->link_status |=
5616 LINK_STATUS_LINK_PARTNER_2500XFD_CAPABLE;
5617 if (val & (MDIO_OVER_1G_UP1_10G | MDIO_OVER_1G_UP1_10GH))
5618 vars->link_status |=
5619 LINK_STATUS_LINK_PARTNER_10GXFD_CAPABLE;
5620 }
5621
Yaniv Rosnera22f0782010-09-07 11:41:20 +00005622 DP(NETIF_MSG_LINK, "duplex %x flow_ctrl 0x%x link_status 0x%x\n",
5623 vars->duplex, vars->flow_ctrl, vars->link_status);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005624 return rc;
5625}
5626
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005627static int bnx2x_warpcore_read_status(struct bnx2x_phy *phy,
5628 struct link_params *params,
5629 struct link_vars *vars)
5630{
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005631 struct bnx2x *bp = params->bp;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005632 u8 lane;
5633 u16 gp_status1, gp_speed, link_up, duplex = DUPLEX_FULL;
5634 int rc = 0;
5635 lane = bnx2x_get_warpcore_lane(phy, params);
5636 /* Read gp_status */
Yaniv Rosner4e7b4992012-11-27 03:46:29 +00005637 if ((params->loopback_mode) &&
5638 (phy->flags & FLAGS_WC_DUAL_MODE)) {
5639 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
5640 MDIO_WC_REG_DIGITAL5_LINK_STATUS, &link_up);
5641 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
5642 MDIO_WC_REG_DIGITAL5_LINK_STATUS, &link_up);
5643 link_up &= 0x1;
5644 } else if ((phy->req_line_speed > SPEED_10000) &&
5645 (phy->supported & SUPPORTED_20000baseMLD2_Full)) {
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005646 u16 temp_link_up;
5647 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
5648 1, &temp_link_up);
5649 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
5650 1, &link_up);
5651 DP(NETIF_MSG_LINK, "PCS RX link status = 0x%x-->0x%x\n",
5652 temp_link_up, link_up);
5653 link_up &= (1<<2);
5654 if (link_up)
5655 bnx2x_ext_phy_resolve_fc(phy, params, vars);
5656 } else {
5657 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
Yaniv Rosner4e7b4992012-11-27 03:46:29 +00005658 MDIO_WC_REG_GP2_STATUS_GP_2_1,
5659 &gp_status1);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005660 DP(NETIF_MSG_LINK, "0x81d1 = 0x%x\n", gp_status1);
Yaniv Rosner4e7b4992012-11-27 03:46:29 +00005661 /* Check for either KR, 1G, or AN up. */
5662 link_up = ((gp_status1 >> 8) |
5663 (gp_status1 >> 12) |
5664 (gp_status1)) &
5665 (1 << lane);
5666 if (phy->supported & SUPPORTED_20000baseKR2_Full) {
5667 u16 an_link;
5668 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
5669 MDIO_AN_REG_STATUS, &an_link);
5670 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
5671 MDIO_AN_REG_STATUS, &an_link);
5672 link_up |= (an_link & (1<<2));
5673 }
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005674 if (link_up && SINGLE_MEDIA_DIRECT(params)) {
5675 u16 pd, gp_status4;
5676 if (phy->req_line_speed == SPEED_AUTO_NEG) {
5677 /* Check Autoneg complete */
5678 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
5679 MDIO_WC_REG_GP2_STATUS_GP_2_4,
5680 &gp_status4);
5681 if (gp_status4 & ((1<<12)<<lane))
5682 vars->link_status |=
5683 LINK_STATUS_AUTO_NEGOTIATE_COMPLETE;
5684
5685 /* Check parallel detect used */
5686 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
5687 MDIO_WC_REG_PAR_DET_10G_STATUS,
5688 &pd);
5689 if (pd & (1<<15))
5690 vars->link_status |=
5691 LINK_STATUS_PARALLEL_DETECTION_USED;
5692 }
5693 bnx2x_ext_phy_resolve_fc(phy, params, vars);
Yaniv Rosner430d1722012-09-11 04:34:11 +00005694 vars->duplex = duplex;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005695 }
5696 }
5697
Mintz Yuval9e7e8392012-02-15 02:10:24 +00005698 if ((vars->link_status & LINK_STATUS_AUTO_NEGOTIATE_COMPLETE) &&
5699 SINGLE_MEDIA_DIRECT(params)) {
5700 u16 val;
5701
5702 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
5703 MDIO_AN_REG_LP_AUTO_NEG2, &val);
5704
5705 if (val & MDIO_CL73_IEEEB1_AN_ADV2_ADVR_1000M_KX)
5706 vars->link_status |=
5707 LINK_STATUS_LINK_PARTNER_1000TFD_CAPABLE;
5708 if (val & (MDIO_CL73_IEEEB1_AN_ADV2_ADVR_10G_KX4 |
5709 MDIO_CL73_IEEEB1_AN_ADV2_ADVR_10G_KR))
5710 vars->link_status |=
5711 LINK_STATUS_LINK_PARTNER_10GXFD_CAPABLE;
5712
5713 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
5714 MDIO_WC_REG_DIGITAL3_LP_UP1, &val);
5715
5716 if (val & MDIO_OVER_1G_UP1_2_5G)
5717 vars->link_status |=
5718 LINK_STATUS_LINK_PARTNER_2500XFD_CAPABLE;
5719 if (val & (MDIO_OVER_1G_UP1_10G | MDIO_OVER_1G_UP1_10GH))
5720 vars->link_status |=
5721 LINK_STATUS_LINK_PARTNER_10GXFD_CAPABLE;
5722
5723 }
5724
5725
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005726 if (lane < 2) {
5727 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
5728 MDIO_WC_REG_GP2_STATUS_GP_2_2, &gp_speed);
5729 } else {
5730 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
5731 MDIO_WC_REG_GP2_STATUS_GP_2_3, &gp_speed);
5732 }
5733 DP(NETIF_MSG_LINK, "lane %d gp_speed 0x%x\n", lane, gp_speed);
5734
5735 if ((lane & 1) == 0)
5736 gp_speed <<= 8;
5737 gp_speed &= 0x3f00;
Yaniv Rosner4e7b4992012-11-27 03:46:29 +00005738 link_up = !!link_up;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005739
5740 rc = bnx2x_get_link_speed_duplex(phy, params, vars, link_up, gp_speed,
5741 duplex);
5742
5743 DP(NETIF_MSG_LINK, "duplex %x flow_ctrl 0x%x link_status 0x%x\n",
5744 vars->duplex, vars->flow_ctrl, vars->link_status);
5745 return rc;
5746}
Eilon Greensteined8680a2009-02-12 08:37:12 +00005747static void bnx2x_set_gmii_tx_driver(struct link_params *params)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005748{
5749 struct bnx2x *bp = params->bp;
Yaniv Rosnere10bc842010-09-07 11:40:50 +00005750 struct bnx2x_phy *phy = &params->phy[INT_PHY];
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005751 u16 lp_up2;
5752 u16 tx_driver;
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00005753 u16 bank;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005754
Yuval Mintzd2310232012-06-20 19:05:19 +00005755 /* Read precomp */
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005756 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005757 MDIO_REG_BANK_OVER_1G,
5758 MDIO_OVER_1G_LP_UP2, &lp_up2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005759
Yuval Mintzd2310232012-06-20 19:05:19 +00005760 /* Bits [10:7] at lp_up2, positioned at [15:12] */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005761 lp_up2 = (((lp_up2 & MDIO_OVER_1G_LP_UP2_PREEMPHASIS_MASK) >>
5762 MDIO_OVER_1G_LP_UP2_PREEMPHASIS_SHIFT) <<
5763 MDIO_TX0_TX_DRIVER_PREEMPHASIS_SHIFT);
5764
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00005765 if (lp_up2 == 0)
5766 return;
5767
5768 for (bank = MDIO_REG_BANK_TX0; bank <= MDIO_REG_BANK_TX3;
5769 bank += (MDIO_REG_BANK_TX1 - MDIO_REG_BANK_TX0)) {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005770 CL22_RD_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005771 bank,
5772 MDIO_TX0_TX_DRIVER, &tx_driver);
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00005773
Yuval Mintzd2310232012-06-20 19:05:19 +00005774 /* Replace tx_driver bits [15:12] */
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00005775 if (lp_up2 !=
5776 (tx_driver & MDIO_TX0_TX_DRIVER_PREEMPHASIS_MASK)) {
5777 tx_driver &= ~MDIO_TX0_TX_DRIVER_PREEMPHASIS_MASK;
5778 tx_driver |= lp_up2;
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005779 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005780 bank,
5781 MDIO_TX0_TX_DRIVER, tx_driver);
Eilon Greensteinc2c8b032009-02-12 08:37:14 +00005782 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005783 }
5784}
5785
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00005786static int bnx2x_emac_program(struct link_params *params,
5787 struct link_vars *vars)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005788{
5789 struct bnx2x *bp = params->bp;
5790 u8 port = params->port;
5791 u16 mode = 0;
5792
5793 DP(NETIF_MSG_LINK, "setting link speed & duplex\n");
5794 bnx2x_bits_dis(bp, GRCBASE_EMAC0 + port*0x400 +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005795 EMAC_REG_EMAC_MODE,
5796 (EMAC_MODE_25G_MODE |
5797 EMAC_MODE_PORT_MII_10M |
5798 EMAC_MODE_HALF_DUPLEX));
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005799 switch (vars->line_speed) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005800 case SPEED_10:
5801 mode |= EMAC_MODE_PORT_MII_10M;
5802 break;
5803
5804 case SPEED_100:
5805 mode |= EMAC_MODE_PORT_MII;
5806 break;
5807
5808 case SPEED_1000:
5809 mode |= EMAC_MODE_PORT_GMII;
5810 break;
5811
5812 case SPEED_2500:
5813 mode |= (EMAC_MODE_25G_MODE | EMAC_MODE_PORT_GMII);
5814 break;
5815
5816 default:
5817 /* 10G not valid for EMAC */
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005818 DP(NETIF_MSG_LINK, "Invalid line_speed 0x%x\n",
5819 vars->line_speed);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005820 return -EINVAL;
5821 }
5822
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005823 if (vars->duplex == DUPLEX_HALF)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005824 mode |= EMAC_MODE_HALF_DUPLEX;
5825 bnx2x_bits_en(bp,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005826 GRCBASE_EMAC0 + port*0x400 + EMAC_REG_EMAC_MODE,
5827 mode);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005828
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00005829 bnx2x_set_led(params, vars, LED_MODE_OPER, vars->line_speed);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005830 return 0;
5831}
5832
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005833static void bnx2x_set_preemphasis(struct bnx2x_phy *phy,
5834 struct link_params *params)
5835{
5836
5837 u16 bank, i = 0;
5838 struct bnx2x *bp = params->bp;
5839
5840 for (bank = MDIO_REG_BANK_RX0, i = 0; bank <= MDIO_REG_BANK_RX3;
5841 bank += (MDIO_REG_BANK_RX1-MDIO_REG_BANK_RX0), i++) {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005842 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005843 bank,
5844 MDIO_RX0_RX_EQ_BOOST,
5845 phy->rx_preemphasis[i]);
5846 }
5847
5848 for (bank = MDIO_REG_BANK_TX0, i = 0; bank <= MDIO_REG_BANK_TX3;
5849 bank += (MDIO_REG_BANK_TX1 - MDIO_REG_BANK_TX0), i++) {
Yaniv Rosnercd2be892011-01-31 04:21:45 +00005850 CL22_WR_OVER_CL45(bp, phy,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005851 bank,
5852 MDIO_TX0_TX_DRIVER,
5853 phy->tx_preemphasis[i]);
5854 }
5855}
5856
Yaniv Rosnerec146a62011-05-31 21:29:27 +00005857static void bnx2x_xgxs_config_init(struct bnx2x_phy *phy,
5858 struct link_params *params,
5859 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005860{
5861 struct bnx2x *bp = params->bp;
5862 u8 enable_cl73 = (SINGLE_MEDIA_DIRECT(params) ||
5863 (params->loopback_mode == LOOPBACK_XGXS));
5864 if (!(vars->phy_flags & PHY_SGMII_FLAG)) {
5865 if (SINGLE_MEDIA_DIRECT(params) &&
5866 (params->feature_config_flags &
5867 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED))
5868 bnx2x_set_preemphasis(phy, params);
5869
Yuval Mintzd2310232012-06-20 19:05:19 +00005870 /* Forced speed requested? */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005871 if (vars->line_speed != SPEED_AUTO_NEG ||
5872 (SINGLE_MEDIA_DIRECT(params) &&
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00005873 params->loopback_mode == LOOPBACK_EXT)) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005874 DP(NETIF_MSG_LINK, "not SGMII, no AN\n");
5875
Yuval Mintzd2310232012-06-20 19:05:19 +00005876 /* Disable autoneg */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005877 bnx2x_set_autoneg(phy, params, vars, 0);
5878
Yuval Mintzd2310232012-06-20 19:05:19 +00005879 /* Program speed and duplex */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005880 bnx2x_program_serdes(phy, params, vars);
5881
5882 } else { /* AN_mode */
5883 DP(NETIF_MSG_LINK, "not SGMII, AN\n");
5884
5885 /* AN enabled */
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00005886 bnx2x_set_brcm_cl37_advertisement(phy, params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005887
Yuval Mintzd2310232012-06-20 19:05:19 +00005888 /* Program duplex & pause advertisement (for aneg) */
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00005889 bnx2x_set_ieee_aneg_advertisement(phy, params,
5890 vars->ieee_fc);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005891
Yuval Mintzd2310232012-06-20 19:05:19 +00005892 /* Enable autoneg */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005893 bnx2x_set_autoneg(phy, params, vars, enable_cl73);
5894
Yuval Mintzd2310232012-06-20 19:05:19 +00005895 /* Enable and restart AN */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00005896 bnx2x_restart_autoneg(phy, params, enable_cl73);
5897 }
5898
5899 } else { /* SGMII mode */
5900 DP(NETIF_MSG_LINK, "SGMII\n");
5901
5902 bnx2x_initialize_sgmii_process(phy, params, vars);
5903 }
5904}
5905
Yaniv Rosnerec146a62011-05-31 21:29:27 +00005906static int bnx2x_prepare_xgxs(struct bnx2x_phy *phy,
5907 struct link_params *params,
5908 struct link_vars *vars)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005909{
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00005910 int rc;
Yaniv Rosnerec146a62011-05-31 21:29:27 +00005911 vars->phy_flags |= PHY_XGXS_FLAG;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005912 if ((phy->req_line_speed &&
5913 ((phy->req_line_speed == SPEED_100) ||
5914 (phy->req_line_speed == SPEED_10))) ||
5915 (!phy->req_line_speed &&
5916 (phy->speed_cap_mask >=
5917 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL) &&
5918 (phy->speed_cap_mask <
Yaniv Rosnerec146a62011-05-31 21:29:27 +00005919 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) ||
5920 (phy->type == PORT_HW_CFG_SERDES_EXT_PHY_TYPE_DIRECT_SD))
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005921 vars->phy_flags |= PHY_SGMII_FLAG;
5922 else
5923 vars->phy_flags &= ~PHY_SGMII_FLAG;
5924
5925 bnx2x_calc_ieee_aneg_adv(phy, params, &vars->ieee_fc);
Yaniv Rosnerec146a62011-05-31 21:29:27 +00005926 bnx2x_set_aer_mmd(params, phy);
5927 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
5928 bnx2x_set_master_ln(params, phy);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005929
5930 rc = bnx2x_reset_unicore(params, phy, 0);
Yuval Mintzd2310232012-06-20 19:05:19 +00005931 /* Reset the SerDes and wait for reset bit return low */
5932 if (rc)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005933 return rc;
5934
Yaniv Rosnerec146a62011-05-31 21:29:27 +00005935 bnx2x_set_aer_mmd(params, phy);
Yuval Mintzd2310232012-06-20 19:05:19 +00005936 /* Setting the masterLn_def again after the reset */
Yaniv Rosnerec146a62011-05-31 21:29:27 +00005937 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT) {
5938 bnx2x_set_master_ln(params, phy);
5939 bnx2x_set_swap_lanes(params, phy);
5940 }
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005941
5942 return rc;
5943}
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00005944
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005945static u16 bnx2x_wait_reset_complete(struct bnx2x *bp,
Yaniv Rosner6d870c32011-01-31 04:22:20 +00005946 struct bnx2x_phy *phy,
5947 struct link_params *params)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005948{
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005949 u16 cnt, ctrl;
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005950 /* Wait for soft reset to get cleared up to 1 sec */
Yaniv Rosner62b29a52010-09-07 11:40:58 +00005951 for (cnt = 0; cnt < 1000; cnt++) {
Yaniv Rosner52c4d6c2011-07-05 01:06:34 +00005952 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54618SE)
Yaniv Rosner6583e332011-06-14 01:34:17 +00005953 bnx2x_cl22_read(bp, phy,
5954 MDIO_PMA_REG_CTRL, &ctrl);
5955 else
5956 bnx2x_cl45_read(bp, phy,
5957 MDIO_PMA_DEVAD,
5958 MDIO_PMA_REG_CTRL, &ctrl);
Yaniv Rosner62b29a52010-09-07 11:40:58 +00005959 if (!(ctrl & (1<<15)))
5960 break;
Yuval Mintzd2310232012-06-20 19:05:19 +00005961 usleep_range(1000, 2000);
Yaniv Rosner62b29a52010-09-07 11:40:58 +00005962 }
Yaniv Rosner6d870c32011-01-31 04:22:20 +00005963
5964 if (cnt == 1000)
5965 netdev_err(bp->dev, "Warning: PHY was not initialized,"
5966 " Port %d\n",
5967 params->port);
Yaniv Rosner62b29a52010-09-07 11:40:58 +00005968 DP(NETIF_MSG_LINK, "control reg 0x%x (after %d ms)\n", ctrl, cnt);
5969 return cnt;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00005970}
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005971
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005972static void bnx2x_link_int_enable(struct link_params *params)
5973{
5974 u8 port = params->port;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005975 u32 mask;
5976 struct bnx2x *bp = params->bp;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00005977
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00005978 /* Setting the status to report on link up for either XGXS or SerDes */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00005979 if (CHIP_IS_E3(bp)) {
5980 mask = NIG_MASK_XGXS0_LINK_STATUS;
5981 if (!(SINGLE_MEDIA_DIRECT(params)))
5982 mask |= NIG_MASK_MI_INT;
5983 } else if (params->switch_cfg == SWITCH_CFG_10G) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005984 mask = (NIG_MASK_XGXS0_LINK10G |
5985 NIG_MASK_XGXS0_LINK_STATUS);
5986 DP(NETIF_MSG_LINK, "enabled XGXS interrupt\n");
Yaniv Rosnere10bc842010-09-07 11:40:50 +00005987 if (!(SINGLE_MEDIA_DIRECT(params)) &&
5988 params->phy[INT_PHY].type !=
5989 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07005990 mask |= NIG_MASK_MI_INT;
5991 DP(NETIF_MSG_LINK, "enabled external phy int\n");
5992 }
5993
5994 } else { /* SerDes */
5995 mask = NIG_MASK_SERDES0_LINK_STATUS;
5996 DP(NETIF_MSG_LINK, "enabled SerDes interrupt\n");
Yaniv Rosnere10bc842010-09-07 11:40:50 +00005997 if (!(SINGLE_MEDIA_DIRECT(params)) &&
5998 params->phy[INT_PHY].type !=
5999 PORT_HW_CFG_SERDES_EXT_PHY_TYPE_NOT_CONN) {
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006000 mask |= NIG_MASK_MI_INT;
6001 DP(NETIF_MSG_LINK, "enabled external phy int\n");
6002 }
6003 }
6004 bnx2x_bits_en(bp,
6005 NIG_REG_MASK_INTERRUPT_PORT0 + port*4,
6006 mask);
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00006007
6008 DP(NETIF_MSG_LINK, "port %x, is_xgxs %x, int_status 0x%x\n", port,
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006009 (params->switch_cfg == SWITCH_CFG_10G),
6010 REG_RD(bp, NIG_REG_STATUS_INTERRUPT_PORT0 + port*4));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006011 DP(NETIF_MSG_LINK, " int_mask 0x%x, MI_INT %x, SERDES_LINK %x\n",
6012 REG_RD(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4),
6013 REG_RD(bp, NIG_REG_EMAC0_STATUS_MISC_MI_INT + port*0x18),
6014 REG_RD(bp, NIG_REG_SERDES0_STATUS_LINK_STATUS+port*0x3c));
6015 DP(NETIF_MSG_LINK, " 10G %x, XGXS_LINK %x\n",
6016 REG_RD(bp, NIG_REG_XGXS0_STATUS_LINK10G + port*0x68),
6017 REG_RD(bp, NIG_REG_XGXS0_STATUS_LINK_STATUS + port*0x68));
6018}
6019
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006020static void bnx2x_rearm_latch_signal(struct bnx2x *bp, u8 port,
6021 u8 exp_mi_int)
Eilon Greenstein2f904462009-08-12 08:22:16 +00006022{
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006023 u32 latch_status = 0;
6024
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00006025 /* Disable the MI INT ( external phy int ) by writing 1 to the
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006026 * status register. Link down indication is high-active-signal,
6027 * so in this case we need to write the status to clear the XOR
Eilon Greenstein2f904462009-08-12 08:22:16 +00006028 */
6029 /* Read Latched signals */
6030 latch_status = REG_RD(bp,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006031 NIG_REG_LATCH_STATUS_0 + port*8);
6032 DP(NETIF_MSG_LINK, "latch_status = 0x%x\n", latch_status);
Eilon Greenstein2f904462009-08-12 08:22:16 +00006033 /* Handle only those with latched-signal=up.*/
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006034 if (exp_mi_int)
6035 bnx2x_bits_en(bp,
6036 NIG_REG_STATUS_INTERRUPT_PORT0
6037 + port*4,
6038 NIG_STATUS_EMAC0_MI_INT);
6039 else
6040 bnx2x_bits_dis(bp,
6041 NIG_REG_STATUS_INTERRUPT_PORT0
6042 + port*4,
6043 NIG_STATUS_EMAC0_MI_INT);
6044
Eilon Greenstein2f904462009-08-12 08:22:16 +00006045 if (latch_status & 1) {
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006046
Eilon Greenstein2f904462009-08-12 08:22:16 +00006047 /* For all latched-signal=up : Re-Arm Latch signals */
6048 REG_WR(bp, NIG_REG_LATCH_STATUS_0 + port*8,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006049 (latch_status & 0xfffe) | (latch_status & 1));
Eilon Greenstein2f904462009-08-12 08:22:16 +00006050 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006051 /* For all latched-signal=up,Write original_signal to status */
Eilon Greenstein2f904462009-08-12 08:22:16 +00006052}
Yaniv Rosnere10bc842010-09-07 11:40:50 +00006053
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006054static void bnx2x_link_int_ack(struct link_params *params,
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006055 struct link_vars *vars, u8 is_10g_plus)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006056{
6057 struct bnx2x *bp = params->bp;
6058 u8 port = params->port;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006059 u32 mask;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00006060 /* First reset all status we assume only one line will be
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006061 * change at a time
6062 */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006063 bnx2x_bits_dis(bp, NIG_REG_STATUS_INTERRUPT_PORT0 + port*4,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006064 (NIG_STATUS_XGXS0_LINK10G |
6065 NIG_STATUS_XGXS0_LINK_STATUS |
6066 NIG_STATUS_SERDES0_LINK_STATUS));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006067 if (vars->phy_link_up) {
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006068 if (USES_WARPCORE(bp))
6069 mask = NIG_STATUS_XGXS0_LINK_STATUS;
6070 else {
6071 if (is_10g_plus)
6072 mask = NIG_STATUS_XGXS0_LINK10G;
6073 else if (params->switch_cfg == SWITCH_CFG_10G) {
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00006074 /* Disable the link interrupt by writing 1 to
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006075 * the relevant lane in the status register
6076 */
6077 u32 ser_lane =
6078 ((params->lane_config &
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006079 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_MASK) >>
6080 PORT_HW_CFG_LANE_SWAP_CFG_MASTER_SHIFT);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006081 mask = ((1 << ser_lane) <<
6082 NIG_STATUS_XGXS0_LINK_STATUS_SIZE);
6083 } else
6084 mask = NIG_STATUS_SERDES0_LINK_STATUS;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006085 }
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006086 DP(NETIF_MSG_LINK, "Ack link up interrupt with mask 0x%x\n",
6087 mask);
6088 bnx2x_bits_en(bp,
6089 NIG_REG_STATUS_INTERRUPT_PORT0 + port*4,
6090 mask);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006091 }
6092}
6093
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006094static int bnx2x_format_ver(u32 num, u8 *str, u16 *len)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006095{
6096 u8 *str_ptr = str;
6097 u32 mask = 0xf0000000;
6098 u8 shift = 8*4;
6099 u8 digit;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006100 u8 remove_leading_zeros = 1;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006101 if (*len < 10) {
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02006102 /* Need more than 10chars for this format */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006103 *str_ptr = '\0';
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006104 (*len)--;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006105 return -EINVAL;
6106 }
6107 while (shift > 0) {
6108
6109 shift -= 4;
6110 digit = ((num & mask) >> shift);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006111 if (digit == 0 && remove_leading_zeros) {
6112 mask = mask >> 4;
6113 continue;
6114 } else if (digit < 0xa)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006115 *str_ptr = digit + '0';
6116 else
6117 *str_ptr = digit - 0xa + 'a';
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006118 remove_leading_zeros = 0;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006119 str_ptr++;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006120 (*len)--;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006121 mask = mask >> 4;
6122 if (shift == 4*4) {
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006123 *str_ptr = '.';
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006124 str_ptr++;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006125 (*len)--;
6126 remove_leading_zeros = 1;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006127 }
6128 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006129 return 0;
6130}
6131
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006132
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006133static int bnx2x_null_format_ver(u32 spirom_ver, u8 *str, u16 *len)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006134{
6135 str[0] = '\0';
6136 (*len)--;
6137 return 0;
6138}
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006139
Mintz Yuvala1e785e2012-02-15 02:10:32 +00006140int bnx2x_get_ext_phy_fw_version(struct link_params *params, u8 *version,
6141 u16 len)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006142{
Julia Lawall0376d5b2009-07-19 05:26:35 +00006143 struct bnx2x *bp;
Eilon Greensteina35da8d2009-02-12 08:37:02 +00006144 u32 spirom_ver = 0;
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006145 int status = 0;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006146 u8 *ver_p = version;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006147 u16 remain_len = len;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006148 if (version == NULL || params == NULL)
6149 return -EINVAL;
Julia Lawall0376d5b2009-07-19 05:26:35 +00006150 bp = params->bp;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006151
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006152 /* Extract first external phy*/
6153 version[0] = '\0';
6154 spirom_ver = REG_RD(bp, params->phy[EXT_PHY1].ver_addr);
Eilon Greensteina35da8d2009-02-12 08:37:02 +00006155
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006156 if (params->phy[EXT_PHY1].format_fw_ver) {
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006157 status |= params->phy[EXT_PHY1].format_fw_ver(spirom_ver,
6158 ver_p,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006159 &remain_len);
6160 ver_p += (len - remain_len);
6161 }
6162 if ((params->num_phys == MAX_PHYS) &&
6163 (params->phy[EXT_PHY2].ver_addr != 0)) {
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006164 spirom_ver = REG_RD(bp, params->phy[EXT_PHY2].ver_addr);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006165 if (params->phy[EXT_PHY2].format_fw_ver) {
6166 *ver_p = '/';
6167 ver_p++;
6168 remain_len--;
6169 status |= params->phy[EXT_PHY2].format_fw_ver(
6170 spirom_ver,
6171 ver_p,
6172 &remain_len);
6173 ver_p = version + (len - remain_len);
6174 }
6175 }
6176 *ver_p = '\0';
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006177 return status;
6178}
6179
Yaniv Rosnere10bc842010-09-07 11:40:50 +00006180static void bnx2x_set_xgxs_loopback(struct bnx2x_phy *phy,
Yaniv Rosner62b29a52010-09-07 11:40:58 +00006181 struct link_params *params)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006182{
6183 u8 port = params->port;
6184 struct bnx2x *bp = params->bp;
6185
Yaniv Rosner62b29a52010-09-07 11:40:58 +00006186 if (phy->req_line_speed != SPEED_1000) {
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006187 u32 md_devad = 0;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006188
6189 DP(NETIF_MSG_LINK, "XGXS 10G loopback enable\n");
6190
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006191 if (!CHIP_IS_E3(bp)) {
Yuval Mintzd2310232012-06-20 19:05:19 +00006192 /* Change the uni_phy_addr in the nig */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006193 md_devad = REG_RD(bp, (NIG_REG_XGXS0_CTRL_MD_DEVAD +
6194 port*0x18));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006195
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006196 REG_WR(bp, NIG_REG_XGXS0_CTRL_MD_DEVAD + port*0x18,
6197 0x5);
6198 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006199
Yaniv Rosnere10bc842010-09-07 11:40:50 +00006200 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006201 5,
6202 (MDIO_REG_BANK_AER_BLOCK +
6203 (MDIO_AER_BLOCK_AER_REG & 0xf)),
6204 0x2800);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006205
Yaniv Rosnere10bc842010-09-07 11:40:50 +00006206 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006207 5,
6208 (MDIO_REG_BANK_CL73_IEEEB0 +
6209 (MDIO_CL73_IEEEB0_CL73_AN_CONTROL & 0xf)),
6210 0x6041);
Eilon Greenstein38582762009-01-14 06:44:16 +00006211 msleep(200);
Yuval Mintzd2310232012-06-20 19:05:19 +00006212 /* Set aer mmd back */
Yaniv Rosnerec146a62011-05-31 21:29:27 +00006213 bnx2x_set_aer_mmd(params, phy);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006214
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006215 if (!CHIP_IS_E3(bp)) {
Yuval Mintzd2310232012-06-20 19:05:19 +00006216 /* And md_devad */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006217 REG_WR(bp, NIG_REG_XGXS0_CTRL_MD_DEVAD + port*0x18,
6218 md_devad);
6219 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006220 } else {
Yaniv Rosnere10bc842010-09-07 11:40:50 +00006221 u16 mii_ctrl;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006222 DP(NETIF_MSG_LINK, "XGXS 1G loopback enable\n");
Yaniv Rosnere10bc842010-09-07 11:40:50 +00006223 bnx2x_cl45_read(bp, phy, 5,
6224 (MDIO_REG_BANK_COMBO_IEEE0 +
6225 (MDIO_COMBO_IEEE0_MII_CONTROL & 0xf)),
6226 &mii_ctrl);
6227 bnx2x_cl45_write(bp, phy, 5,
6228 (MDIO_REG_BANK_COMBO_IEEE0 +
6229 (MDIO_COMBO_IEEE0_MII_CONTROL & 0xf)),
6230 mii_ctrl |
6231 MDIO_COMBO_IEEO_MII_CONTROL_LOOPBACK);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006232 }
6233}
6234
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006235int bnx2x_set_led(struct link_params *params,
6236 struct link_vars *vars, u8 mode, u32 speed)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006237{
Yaniv Rosner7846e472009-11-05 19:18:07 +02006238 u8 port = params->port;
6239 u16 hw_led_mode = params->hw_led_mode;
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006240 int rc = 0;
6241 u8 phy_idx;
Eilon Greenstein345b5d52008-08-13 15:58:12 -07006242 u32 tmp;
6243 u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
Yaniv Rosner7846e472009-11-05 19:18:07 +02006244 struct bnx2x *bp = params->bp;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006245 DP(NETIF_MSG_LINK, "bnx2x_set_led: port %x, mode %d\n", port, mode);
6246 DP(NETIF_MSG_LINK, "speed 0x%x, hw_led_mode 0x%x\n",
6247 speed, hw_led_mode);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006248 /* In case */
6249 for (phy_idx = EXT_PHY1; phy_idx < MAX_PHYS; phy_idx++) {
6250 if (params->phy[phy_idx].set_link_led) {
6251 params->phy[phy_idx].set_link_led(
6252 &params->phy[phy_idx], params, mode);
6253 }
6254 }
6255
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006256 switch (mode) {
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006257 case LED_MODE_FRONT_PANEL_OFF:
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006258 case LED_MODE_OFF:
6259 REG_WR(bp, NIG_REG_LED_10G_P0 + port*4, 0);
6260 REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006261 SHARED_HW_CFG_LED_MAC1);
Eilon Greenstein345b5d52008-08-13 15:58:12 -07006262
6263 tmp = EMAC_RD(bp, EMAC_REG_EMAC_LED);
Yaniv Rosner001cea72011-10-27 05:09:48 +00006264 if (params->phy[EXT_PHY1].type ==
Yaniv Rosner9379c9b2012-04-04 01:28:58 +00006265 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54618SE)
6266 tmp &= ~(EMAC_LED_1000MB_OVERRIDE |
6267 EMAC_LED_100MB_OVERRIDE |
6268 EMAC_LED_10MB_OVERRIDE);
6269 else
6270 tmp |= EMAC_LED_OVERRIDE;
6271
6272 EMAC_WR(bp, EMAC_REG_EMAC_LED, tmp);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006273 break;
6274
6275 case LED_MODE_OPER:
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00006276 /* For all other phys, OPER mode is same as ON, so in case
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006277 * link is down, do nothing
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006278 */
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006279 if (!vars->link_up)
6280 break;
6281 case LED_MODE_ON:
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00006282 if (((params->phy[EXT_PHY1].type ==
6283 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727) ||
6284 (params->phy[EXT_PHY1].type ==
6285 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8722)) &&
Yaniv Rosner1f483532011-01-18 04:33:31 +00006286 CHIP_IS_E2(bp) && params->num_phys == 2) {
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00006287 /* This is a work-around for E2+8727 Configurations */
Yaniv Rosner1f483532011-01-18 04:33:31 +00006288 if (mode == LED_MODE_ON ||
6289 speed == SPEED_10000){
6290 REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4, 0);
6291 REG_WR(bp, NIG_REG_LED_10G_P0 + port*4, 1);
6292
6293 tmp = EMAC_RD(bp, EMAC_REG_EMAC_LED);
6294 EMAC_WR(bp, EMAC_REG_EMAC_LED,
6295 (tmp | EMAC_LED_OVERRIDE));
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00006296 /* Return here without enabling traffic
David S. Miller8decf862011-09-22 03:23:13 -04006297 * LED blink and setting rate in ON mode.
Yaniv Rosner793bd452011-08-02 22:59:40 +00006298 * In oper mode, enabling LED blink
6299 * and setting rate is needed.
6300 */
6301 if (mode == LED_MODE_ON)
6302 return rc;
Yaniv Rosner1f483532011-01-18 04:33:31 +00006303 }
Yaniv Rosner793bd452011-08-02 22:59:40 +00006304 } else if (SINGLE_MEDIA_DIRECT(params)) {
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00006305 /* This is a work-around for HW issue found when link
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006306 * is up in CL73
6307 */
David S. Miller8decf862011-09-22 03:23:13 -04006308 if ((!CHIP_IS_E3(bp)) ||
6309 (CHIP_IS_E3(bp) &&
6310 mode == LED_MODE_ON))
6311 REG_WR(bp, NIG_REG_LED_10G_P0 + port*4, 1);
6312
Yaniv Rosner793bd452011-08-02 22:59:40 +00006313 if (CHIP_IS_E1x(bp) ||
6314 CHIP_IS_E2(bp) ||
6315 (mode == LED_MODE_ON))
6316 REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4, 0);
6317 else
6318 REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4,
6319 hw_led_mode);
Yaniv Rosner001cea72011-10-27 05:09:48 +00006320 } else if ((params->phy[EXT_PHY1].type ==
6321 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54618SE) &&
Yaniv Rosner9379c9b2012-04-04 01:28:58 +00006322 (mode == LED_MODE_ON)) {
Yaniv Rosner001cea72011-10-27 05:09:48 +00006323 REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4, 0);
6324 tmp = EMAC_RD(bp, EMAC_REG_EMAC_LED);
Yaniv Rosner9379c9b2012-04-04 01:28:58 +00006325 EMAC_WR(bp, EMAC_REG_EMAC_LED, tmp |
6326 EMAC_LED_OVERRIDE | EMAC_LED_1000MB_OVERRIDE);
6327 /* Break here; otherwise, it'll disable the
6328 * intended override.
6329 */
6330 break;
Yaniv Rosner793bd452011-08-02 22:59:40 +00006331 } else
Yaniv Rosner001cea72011-10-27 05:09:48 +00006332 REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4,
6333 hw_led_mode);
Yaniv Rosner7846e472009-11-05 19:18:07 +02006334
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006335 REG_WR(bp, NIG_REG_LED_CONTROL_OVERRIDE_TRAFFIC_P0 + port*4, 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006336 /* Set blinking rate to ~15.9Hz */
Yaniv Rosner26ffaf32011-10-27 05:09:45 +00006337 if (CHIP_IS_E3(bp))
6338 REG_WR(bp, NIG_REG_LED_CONTROL_BLINK_RATE_P0 + port*4,
6339 LED_BLINK_RATE_VAL_E3);
6340 else
6341 REG_WR(bp, NIG_REG_LED_CONTROL_BLINK_RATE_P0 + port*4,
6342 LED_BLINK_RATE_VAL_E1X_E2);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006343 REG_WR(bp, NIG_REG_LED_CONTROL_BLINK_RATE_ENA_P0 +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006344 port*4, 1);
Yaniv Rosner9379c9b2012-04-04 01:28:58 +00006345 tmp = EMAC_RD(bp, EMAC_REG_EMAC_LED);
6346 EMAC_WR(bp, EMAC_REG_EMAC_LED,
6347 (tmp & (~EMAC_LED_OVERRIDE)));
Eilon Greenstein345b5d52008-08-13 15:58:12 -07006348
Yaniv Rosner7846e472009-11-05 19:18:07 +02006349 if (CHIP_IS_E1(bp) &&
Eilon Greenstein34f80b02008-06-23 20:33:01 -07006350 ((speed == SPEED_2500) ||
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006351 (speed == SPEED_1000) ||
6352 (speed == SPEED_100) ||
6353 (speed == SPEED_10))) {
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00006354 /* For speeds less than 10G LED scheme is different */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006355 REG_WR(bp, NIG_REG_LED_CONTROL_OVERRIDE_TRAFFIC_P0
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006356 + port*4, 1);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006357 REG_WR(bp, NIG_REG_LED_CONTROL_TRAFFIC_P0 +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006358 port*4, 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006359 REG_WR(bp, NIG_REG_LED_CONTROL_BLINK_TRAFFIC_P0 +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006360 port*4, 1);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006361 }
6362 break;
6363
6364 default:
6365 rc = -EINVAL;
6366 DP(NETIF_MSG_LINK, "bnx2x_set_led: Invalid led mode %d\n",
6367 mode);
6368 break;
6369 }
6370 return rc;
6371
6372}
6373
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00006374/* This function comes to reflect the actual link state read DIRECTLY from the
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006375 * HW
6376 */
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006377int bnx2x_test_link(struct link_params *params, struct link_vars *vars,
6378 u8 is_serdes)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006379{
6380 struct bnx2x *bp = params->bp;
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00006381 u16 gp_status = 0, phy_index = 0;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006382 u8 ext_phy_link_up = 0, serdes_phy_type;
6383 struct link_vars temp_vars;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006384 struct bnx2x_phy *int_phy = &params->phy[INT_PHY];
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006385
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006386 if (CHIP_IS_E3(bp)) {
6387 u16 link_up;
6388 if (params->req_line_speed[LINK_CONFIG_IDX(INT_PHY)]
6389 > SPEED_10000) {
6390 /* Check 20G link */
6391 bnx2x_cl45_read(bp, int_phy, MDIO_WC_DEVAD,
6392 1, &link_up);
6393 bnx2x_cl45_read(bp, int_phy, MDIO_WC_DEVAD,
6394 1, &link_up);
6395 link_up &= (1<<2);
6396 } else {
6397 /* Check 10G link and below*/
6398 u8 lane = bnx2x_get_warpcore_lane(int_phy, params);
6399 bnx2x_cl45_read(bp, int_phy, MDIO_WC_DEVAD,
6400 MDIO_WC_REG_GP2_STATUS_GP_2_1,
6401 &gp_status);
6402 gp_status = ((gp_status >> 8) & 0xf) |
6403 ((gp_status >> 12) & 0xf);
6404 link_up = gp_status & (1 << lane);
6405 }
6406 if (!link_up)
6407 return -ESRCH;
6408 } else {
6409 CL22_RD_OVER_CL45(bp, int_phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006410 MDIO_REG_BANK_GP_STATUS,
6411 MDIO_GP_STATUS_TOP_AN_STATUS1,
6412 &gp_status);
Yuval Mintzd2310232012-06-20 19:05:19 +00006413 /* Link is up only if both local phy and external phy are up */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006414 if (!(gp_status & MDIO_GP_STATUS_TOP_AN_STATUS1_LINK_STATUS))
6415 return -ESRCH;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006416 }
6417 /* In XGXS loopback mode, do not check external PHY */
6418 if (params->loopback_mode == LOOPBACK_XGXS)
6419 return 0;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006420
6421 switch (params->num_phys) {
6422 case 1:
6423 /* No external PHY */
6424 return 0;
6425 case 2:
6426 ext_phy_link_up = params->phy[EXT_PHY1].read_status(
6427 &params->phy[EXT_PHY1],
6428 params, &temp_vars);
6429 break;
6430 case 3: /* Dual Media */
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00006431 for (phy_index = EXT_PHY1; phy_index < params->num_phys;
6432 phy_index++) {
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006433 serdes_phy_type = ((params->phy[phy_index].media_type ==
Yuval Mintzdbef8072012-06-20 19:05:22 +00006434 ETH_PHY_SFPP_10G_FIBER) ||
6435 (params->phy[phy_index].media_type ==
6436 ETH_PHY_SFP_1G_FIBER) ||
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006437 (params->phy[phy_index].media_type ==
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00006438 ETH_PHY_XFP_FIBER) ||
6439 (params->phy[phy_index].media_type ==
6440 ETH_PHY_DA_TWINAX));
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006441
6442 if (is_serdes != serdes_phy_type)
6443 continue;
6444 if (params->phy[phy_index].read_status) {
6445 ext_phy_link_up |=
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00006446 params->phy[phy_index].read_status(
6447 &params->phy[phy_index],
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006448 params, &temp_vars);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006449 }
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00006450 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006451 break;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006452 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006453 if (ext_phy_link_up)
6454 return 0;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006455 return -ESRCH;
6456}
6457
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006458static int bnx2x_link_initialize(struct link_params *params,
6459 struct link_vars *vars)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006460{
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006461 int rc = 0;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006462 u8 phy_index, non_ext_phy;
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00006463 struct bnx2x *bp = params->bp;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00006464 /* In case of external phy existence, the line speed would be the
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006465 * line speed linked up by the external phy. In case it is direct
6466 * only, then the line_speed during initialization will be
6467 * equal to the req_line_speed
6468 */
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00006469 vars->line_speed = params->phy[INT_PHY].req_line_speed;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006470
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00006471 /* Initialize the internal phy in case this is a direct board
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00006472 * (no external phys), or this board has external phy which requires
6473 * to first.
6474 */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006475 if (!USES_WARPCORE(bp))
6476 bnx2x_prepare_xgxs(&params->phy[INT_PHY], params, vars);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006477 /* init ext phy and enable link state int */
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00006478 non_ext_phy = (SINGLE_MEDIA_DIRECT(params) ||
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006479 (params->loopback_mode == LOOPBACK_XGXS));
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006480
6481 if (non_ext_phy ||
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00006482 (params->phy[EXT_PHY1].flags & FLAGS_INIT_XGXS_FIRST) ||
Eilon Greenstein8660d8c2009-03-02 08:01:02 +00006483 (params->loopback_mode == LOOPBACK_EXT_PHY)) {
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00006484 struct bnx2x_phy *phy = &params->phy[INT_PHY];
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006485 if (vars->line_speed == SPEED_AUTO_NEG &&
6486 (CHIP_IS_E1x(bp) ||
6487 CHIP_IS_E2(bp)))
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00006488 bnx2x_set_parallel_detection(phy, params);
Yaniv Rosnerec146a62011-05-31 21:29:27 +00006489 if (params->phy[INT_PHY].config_init)
6490 params->phy[INT_PHY].config_init(phy,
6491 params,
6492 vars);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006493 }
6494
Yaniv Rosnerc18aa152010-09-07 11:41:07 +00006495 /* Init external phy*/
Yaniv Rosnerfd36a2e2011-05-31 21:29:05 +00006496 if (non_ext_phy) {
6497 if (params->phy[INT_PHY].supported &
6498 SUPPORTED_FIBRE)
6499 vars->link_status |= LINK_STATUS_SERDES_LINK;
6500 } else {
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006501 for (phy_index = EXT_PHY1; phy_index < params->num_phys;
6502 phy_index++) {
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00006503 /* No need to initialize second phy in case of first
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006504 * phy only selection. In case of second phy, we do
6505 * need to initialize the first phy, since they are
6506 * connected.
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006507 */
Yaniv Rosnerfd36a2e2011-05-31 21:29:05 +00006508 if (params->phy[phy_index].supported &
6509 SUPPORTED_FIBRE)
6510 vars->link_status |= LINK_STATUS_SERDES_LINK;
6511
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006512 if (phy_index == EXT_PHY2 &&
6513 (bnx2x_phy_selection(params) ==
6514 PORT_HW_CFG_PHY_SELECTION_FIRST_PHY)) {
Joe Perches94f05b02011-08-14 12:16:20 +00006515 DP(NETIF_MSG_LINK,
6516 "Not initializing second phy\n");
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006517 continue;
6518 }
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006519 params->phy[phy_index].config_init(
6520 &params->phy[phy_index],
6521 params, vars);
6522 }
Yaniv Rosnerfd36a2e2011-05-31 21:29:05 +00006523 }
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +00006524 /* Reset the interrupt indication after phy was initialized */
6525 bnx2x_bits_dis(bp, NIG_REG_STATUS_INTERRUPT_PORT0 +
6526 params->port*4,
6527 (NIG_STATUS_XGXS0_LINK10G |
6528 NIG_STATUS_XGXS0_LINK_STATUS |
6529 NIG_STATUS_SERDES0_LINK_STATUS |
6530 NIG_MASK_MI_INT));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006531 return rc;
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006532}
6533
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006534static void bnx2x_int_link_reset(struct bnx2x_phy *phy,
6535 struct link_params *params)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006536{
Yuval Mintzd2310232012-06-20 19:05:19 +00006537 /* Reset the SerDes/XGXS */
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006538 REG_WR(params->bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_CLEAR,
6539 (0x1ff << (params->port*16)));
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006540}
6541
6542static void bnx2x_common_ext_link_reset(struct bnx2x_phy *phy,
6543 struct link_params *params)
6544{
6545 struct bnx2x *bp = params->bp;
6546 u8 gpio_port;
6547 /* HW reset */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006548 if (CHIP_IS_E2(bp))
6549 gpio_port = BP_PATH(bp);
6550 else
6551 gpio_port = params->port;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006552 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006553 MISC_REGISTERS_GPIO_OUTPUT_LOW,
6554 gpio_port);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006555 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006556 MISC_REGISTERS_GPIO_OUTPUT_LOW,
6557 gpio_port);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006558 DP(NETIF_MSG_LINK, "reset external PHY\n");
6559}
6560
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006561static int bnx2x_update_link_down(struct link_params *params,
6562 struct link_vars *vars)
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006563{
6564 struct bnx2x *bp = params->bp;
6565 u8 port = params->port;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00006566
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006567 DP(NETIF_MSG_LINK, "Port %x: Link is down\n", port);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006568 bnx2x_set_led(params, vars, LED_MODE_OFF, 0);
Yaniv Rosner3deb8162011-06-14 01:34:33 +00006569 vars->phy_flags &= ~PHY_PHYSICAL_LINK_FLAG;
Yuval Mintzd2310232012-06-20 19:05:19 +00006570 /* Indicate no mac active */
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006571 vars->mac_type = MAC_TYPE_NONE;
6572
Yuval Mintzd2310232012-06-20 19:05:19 +00006573 /* Update shared memory */
Yaniv Rosner49781402012-10-31 05:46:55 +00006574 vars->link_status &= ~LINK_UPDATE_MASK;
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006575 vars->line_speed = 0;
6576 bnx2x_update_mng(params, vars->link_status);
6577
Yuval Mintzd2310232012-06-20 19:05:19 +00006578 /* Activate nig drain */
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006579 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + port*4, 1);
6580
Yuval Mintzd2310232012-06-20 19:05:19 +00006581 /* Disable emac */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00006582 if (!CHIP_IS_E3(bp))
6583 REG_WR(bp, NIG_REG_NIG_EMAC0_EN + port*4, 0);
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00006584
Yuval Mintzd2310232012-06-20 19:05:19 +00006585 usleep_range(10000, 20000);
6586 /* Reset BigMac/Xmac */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00006587 if (CHIP_IS_E1x(bp) ||
Yaniv Rosnerd3a8f132012-09-13 02:56:20 +00006588 CHIP_IS_E2(bp))
6589 bnx2x_set_bmac_rx(bp, params->chip_id, params->port, 0);
6590
Yaniv Rosnerce7c0482011-10-27 05:09:47 +00006591 if (CHIP_IS_E3(bp)) {
Yuval Mintzd2310232012-06-20 19:05:19 +00006592 /* Prevent LPI Generation by chip */
Yuval Mintzc8c60d82012-06-06 17:13:07 +00006593 REG_WR(bp, MISC_REG_CPMU_LP_FW_ENABLE_P0 + (params->port << 2),
6594 0);
Yuval Mintzc8c60d82012-06-06 17:13:07 +00006595 REG_WR(bp, MISC_REG_CPMU_LP_MASK_ENT_P0 + (params->port << 2),
6596 0);
6597 vars->eee_status &= ~(SHMEM_EEE_LP_ADV_STATUS_MASK |
6598 SHMEM_EEE_ACTIVE_BIT);
6599
6600 bnx2x_update_mng_eee(params, vars->eee_status);
Yaniv Rosnerd3a8f132012-09-13 02:56:20 +00006601 bnx2x_set_xmac_rxtx(params, 0);
6602 bnx2x_set_umac_rxtx(params, 0);
Yaniv Rosnerce7c0482011-10-27 05:09:47 +00006603 }
Yaniv Rosner9380bb92011-06-14 01:34:07 +00006604
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006605 return 0;
6606}
6607
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006608static int bnx2x_update_link_up(struct link_params *params,
6609 struct link_vars *vars,
6610 u8 link_10g)
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006611{
6612 struct bnx2x *bp = params->bp;
Yaniv Rosner55098c52012-04-03 18:41:27 +00006613 u8 phy_idx, port = params->port;
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006614 int rc = 0;
Eilon Greensteinab6ad5a2009-08-12 08:24:29 +00006615
Yaniv Rosnerde6f3372011-08-02 22:59:25 +00006616 vars->link_status |= (LINK_STATUS_LINK_UP |
6617 LINK_STATUS_PHYSICAL_LINK_FLAG);
Yaniv Rosner3deb8162011-06-14 01:34:33 +00006618 vars->phy_flags |= PHY_PHYSICAL_LINK_FLAG;
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006619
Yaniv Rosner7aa07112010-09-07 11:41:01 +00006620 if (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX)
6621 vars->link_status |=
6622 LINK_STATUS_TX_FLOW_CONTROL_ENABLED;
6623
6624 if (vars->flow_ctrl & BNX2X_FLOW_CTRL_RX)
6625 vars->link_status |=
6626 LINK_STATUS_RX_FLOW_CONTROL_ENABLED;
Yaniv Rosner9380bb92011-06-14 01:34:07 +00006627 if (USES_WARPCORE(bp)) {
Yaniv Rosner3deb8162011-06-14 01:34:33 +00006628 if (link_10g) {
6629 if (bnx2x_xmac_enable(params, vars, 0) ==
6630 -ESRCH) {
6631 DP(NETIF_MSG_LINK, "Found errors on XMAC\n");
6632 vars->link_up = 0;
6633 vars->phy_flags |= PHY_HALF_OPEN_CONN_FLAG;
6634 vars->link_status &= ~LINK_STATUS_LINK_UP;
6635 }
6636 } else
Yaniv Rosner9380bb92011-06-14 01:34:07 +00006637 bnx2x_umac_enable(params, vars, 0);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00006638 bnx2x_set_led(params, vars,
Yaniv Rosner9380bb92011-06-14 01:34:07 +00006639 LED_MODE_OPER, vars->line_speed);
Yuval Mintzc8c60d82012-06-06 17:13:07 +00006640
6641 if ((vars->eee_status & SHMEM_EEE_ACTIVE_BIT) &&
6642 (vars->eee_status & SHMEM_EEE_LPI_REQUESTED_BIT)) {
6643 DP(NETIF_MSG_LINK, "Enabling LPI assertion\n");
6644 REG_WR(bp, MISC_REG_CPMU_LP_FW_ENABLE_P0 +
6645 (params->port << 2), 1);
6646 REG_WR(bp, MISC_REG_CPMU_LP_DR_ENABLE, 1);
6647 REG_WR(bp, MISC_REG_CPMU_LP_MASK_ENT_P0 +
6648 (params->port << 2), 0xfc20);
6649 }
Yaniv Rosner9380bb92011-06-14 01:34:07 +00006650 }
6651 if ((CHIP_IS_E1x(bp) ||
6652 CHIP_IS_E2(bp))) {
6653 if (link_10g) {
Yaniv Rosnerd3a8f132012-09-13 02:56:20 +00006654 if (bnx2x_bmac_enable(params, vars, 0, 1) ==
Yaniv Rosner3deb8162011-06-14 01:34:33 +00006655 -ESRCH) {
6656 DP(NETIF_MSG_LINK, "Found errors on BMAC\n");
6657 vars->link_up = 0;
6658 vars->phy_flags |= PHY_HALF_OPEN_CONN_FLAG;
6659 vars->link_status &= ~LINK_STATUS_LINK_UP;
6660 }
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006661
Yaniv Rosner9380bb92011-06-14 01:34:07 +00006662 bnx2x_set_led(params, vars,
6663 LED_MODE_OPER, SPEED_10000);
6664 } else {
6665 rc = bnx2x_emac_program(params, vars);
6666 bnx2x_emac_enable(params, vars, 0);
Yaniv Rosner0c786f02009-11-05 19:18:32 +02006667
Yaniv Rosner9380bb92011-06-14 01:34:07 +00006668 /* AN complete? */
6669 if ((vars->link_status &
6670 LINK_STATUS_AUTO_NEGOTIATE_COMPLETE)
6671 && (!(vars->phy_flags & PHY_SGMII_FLAG)) &&
6672 SINGLE_MEDIA_DIRECT(params))
6673 bnx2x_set_gmii_tx_driver(params);
6674 }
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006675 }
6676
6677 /* PBF - link up */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00006678 if (CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00006679 rc |= bnx2x_pbf_update(params, vars->flow_ctrl,
6680 vars->line_speed);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006681
Yuval Mintzd2310232012-06-20 19:05:19 +00006682 /* Disable drain */
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006683 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + port*4, 0);
6684
Yuval Mintzd2310232012-06-20 19:05:19 +00006685 /* Update shared memory */
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006686 bnx2x_update_mng(params, vars->link_status);
Yuval Mintzc8c60d82012-06-06 17:13:07 +00006687 bnx2x_update_mng_eee(params, vars->eee_status);
Yaniv Rosner55098c52012-04-03 18:41:27 +00006688 /* Check remote fault */
6689 for (phy_idx = INT_PHY; phy_idx < MAX_PHYS; phy_idx++) {
6690 if (params->phy[phy_idx].flags & FLAGS_TX_ERROR_CHECK) {
6691 bnx2x_check_half_open_conn(params, vars, 0);
6692 break;
6693 }
6694 }
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00006695 msleep(20);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006696 return rc;
6697}
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00006698/* The bnx2x_link_update function should be called upon link
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006699 * interrupt.
6700 * Link is considered up as follows:
6701 * - DIRECT_SINGLE_MEDIA - Only XGXS link (internal link) needs
6702 * to be up
6703 * - SINGLE_MEDIA - The link between the 577xx and the external
6704 * phy (XGXS) need to up as well as the external link of the
6705 * phy (PHY_EXT1)
6706 * - DUAL_MEDIA - The link between the 577xx and the first
6707 * external phy needs to be up, and at least one of the 2
6708 * external phy link must be up.
Yaniv Rosner62b29a52010-09-07 11:40:58 +00006709 */
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006710int bnx2x_link_update(struct link_params *params, struct link_vars *vars)
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006711{
6712 struct bnx2x *bp = params->bp;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006713 struct link_vars phy_vars[MAX_PHYS];
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006714 u8 port = params->port;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006715 u8 link_10g_plus, phy_index;
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00006716 u8 ext_phy_link_up = 0, cur_link_up;
6717 int rc = 0;
Eilon Greenstein2f904462009-08-12 08:22:16 +00006718 u8 is_mi_int = 0;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006719 u16 ext_phy_line_speed = 0, prev_line_speed = vars->line_speed;
6720 u8 active_external_phy = INT_PHY;
Yaniv Rosner3deb8162011-06-14 01:34:33 +00006721 vars->phy_flags &= ~PHY_HALF_OPEN_CONN_FLAG;
Yaniv Rosner49781402012-10-31 05:46:55 +00006722 vars->link_status &= ~LINK_UPDATE_MASK;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006723 for (phy_index = INT_PHY; phy_index < params->num_phys;
6724 phy_index++) {
6725 phy_vars[phy_index].flow_ctrl = 0;
6726 phy_vars[phy_index].link_status = 0;
6727 phy_vars[phy_index].line_speed = 0;
6728 phy_vars[phy_index].duplex = DUPLEX_FULL;
6729 phy_vars[phy_index].phy_link_up = 0;
6730 phy_vars[phy_index].link_up = 0;
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00006731 phy_vars[phy_index].fault_detected = 0;
Yuval Mintzc8c60d82012-06-06 17:13:07 +00006732 /* different consideration, since vars holds inner state */
6733 phy_vars[phy_index].eee_status = vars->eee_status;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006734 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006735
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006736 if (USES_WARPCORE(bp))
6737 bnx2x_set_aer_mmd(params, &params->phy[INT_PHY]);
6738
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006739 DP(NETIF_MSG_LINK, "port %x, XGXS?%x, int_status 0x%x\n",
Eilon Greenstein2f904462009-08-12 08:22:16 +00006740 port, (vars->phy_flags & PHY_XGXS_FLAG),
6741 REG_RD(bp, NIG_REG_STATUS_INTERRUPT_PORT0 + port*4));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006742
Eilon Greenstein2f904462009-08-12 08:22:16 +00006743 is_mi_int = (u8)(REG_RD(bp, NIG_REG_EMAC0_STATUS_MISC_MI_INT +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006744 port*0x18) > 0);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006745 DP(NETIF_MSG_LINK, "int_mask 0x%x MI_INT %x, SERDES_LINK %x\n",
Eilon Greenstein2f904462009-08-12 08:22:16 +00006746 REG_RD(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4),
6747 is_mi_int,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006748 REG_RD(bp, NIG_REG_SERDES0_STATUS_LINK_STATUS + port*0x3c));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006749
6750 DP(NETIF_MSG_LINK, " 10G %x, XGXS_LINK %x\n",
6751 REG_RD(bp, NIG_REG_XGXS0_STATUS_LINK10G + port*0x68),
6752 REG_RD(bp, NIG_REG_XGXS0_STATUS_LINK_STATUS + port*0x68));
6753
Yuval Mintzd2310232012-06-20 19:05:19 +00006754 /* Disable emac */
Yaniv Rosner9380bb92011-06-14 01:34:07 +00006755 if (!CHIP_IS_E3(bp))
6756 REG_WR(bp, NIG_REG_NIG_EMAC0_EN + port*4, 0);
Eilon Greenstein6c55c3cd2009-01-14 06:44:13 +00006757
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00006758 /* Step 1:
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006759 * Check external link change only for external phys, and apply
6760 * priority selection between them in case the link on both phys
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00006761 * is up. Note that instead of the common vars, a temporary
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006762 * vars argument is used since each phy may have different link/
6763 * speed/duplex result
6764 */
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006765 for (phy_index = EXT_PHY1; phy_index < params->num_phys;
6766 phy_index++) {
6767 struct bnx2x_phy *phy = &params->phy[phy_index];
6768 if (!phy->read_status)
6769 continue;
6770 /* Read link status and params of this ext phy */
6771 cur_link_up = phy->read_status(phy, params,
6772 &phy_vars[phy_index]);
6773 if (cur_link_up) {
6774 DP(NETIF_MSG_LINK, "phy in index %d link is up\n",
6775 phy_index);
6776 } else {
6777 DP(NETIF_MSG_LINK, "phy in index %d link is down\n",
6778 phy_index);
6779 continue;
6780 }
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006781
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006782 if (!ext_phy_link_up) {
6783 ext_phy_link_up = 1;
6784 active_external_phy = phy_index;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006785 } else {
6786 switch (bnx2x_phy_selection(params)) {
6787 case PORT_HW_CFG_PHY_SELECTION_HARDWARE_DEFAULT:
6788 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY_PRIORITY:
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00006789 /* In this option, the first PHY makes sure to pass the
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006790 * traffic through itself only.
6791 * Its not clear how to reset the link on the second phy
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006792 */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006793 active_external_phy = EXT_PHY1;
6794 break;
6795 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY_PRIORITY:
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00006796 /* In this option, the first PHY makes sure to pass the
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006797 * traffic through the second PHY.
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006798 */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006799 active_external_phy = EXT_PHY2;
6800 break;
6801 default:
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00006802 /* Link indication on both PHYs with the following cases
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006803 * is invalid:
6804 * - FIRST_PHY means that second phy wasn't initialized,
6805 * hence its link is expected to be down
6806 * - SECOND_PHY means that first phy should not be able
6807 * to link up by itself (using configuration)
6808 * - DEFAULT should be overriden during initialiazation
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006809 */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006810 DP(NETIF_MSG_LINK, "Invalid link indication"
6811 "mpc=0x%x. DISABLING LINK !!!\n",
6812 params->multi_phy_config);
6813 ext_phy_link_up = 0;
6814 break;
6815 }
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006816 }
6817 }
6818 prev_line_speed = vars->line_speed;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00006819 /* Step 2:
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006820 * Read the status of the internal phy. In case of
6821 * DIRECT_SINGLE_MEDIA board, this link is the external link,
6822 * otherwise this is the link between the 577xx and the first
6823 * external phy
6824 */
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006825 if (params->phy[INT_PHY].read_status)
6826 params->phy[INT_PHY].read_status(
6827 &params->phy[INT_PHY],
6828 params, vars);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00006829 /* The INT_PHY flow control reside in the vars. This include the
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006830 * case where the speed or flow control are not set to AUTO.
6831 * Otherwise, the active external phy flow control result is set
6832 * to the vars. The ext_phy_line_speed is needed to check if the
6833 * speed is different between the internal phy and external phy.
6834 * This case may be result of intermediate link speed change.
6835 */
6836 if (active_external_phy > INT_PHY) {
6837 vars->flow_ctrl = phy_vars[active_external_phy].flow_ctrl;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00006838 /* Link speed is taken from the XGXS. AN and FC result from
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006839 * the external phy.
6840 */
6841 vars->link_status |= phy_vars[active_external_phy].link_status;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006842
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00006843 /* if active_external_phy is first PHY and link is up - disable
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006844 * disable TX on second external PHY
6845 */
6846 if (active_external_phy == EXT_PHY1) {
6847 if (params->phy[EXT_PHY2].phy_specific_func) {
Joe Perches94f05b02011-08-14 12:16:20 +00006848 DP(NETIF_MSG_LINK,
6849 "Disabling TX on EXT_PHY2\n");
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006850 params->phy[EXT_PHY2].phy_specific_func(
6851 &params->phy[EXT_PHY2],
6852 params, DISABLE_TX);
6853 }
6854 }
6855
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006856 ext_phy_line_speed = phy_vars[active_external_phy].line_speed;
6857 vars->duplex = phy_vars[active_external_phy].duplex;
6858 if (params->phy[active_external_phy].supported &
6859 SUPPORTED_FIBRE)
6860 vars->link_status |= LINK_STATUS_SERDES_LINK;
Yaniv Rosnerfd36a2e2011-05-31 21:29:05 +00006861 else
6862 vars->link_status &= ~LINK_STATUS_SERDES_LINK;
Yuval Mintzc8c60d82012-06-06 17:13:07 +00006863
6864 vars->eee_status = phy_vars[active_external_phy].eee_status;
6865
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006866 DP(NETIF_MSG_LINK, "Active external phy selected: %x\n",
6867 active_external_phy);
6868 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +00006869
6870 for (phy_index = EXT_PHY1; phy_index < params->num_phys;
6871 phy_index++) {
6872 if (params->phy[phy_index].flags &
6873 FLAGS_REARM_LATCH_SIGNAL) {
6874 bnx2x_rearm_latch_signal(bp, port,
6875 phy_index ==
6876 active_external_phy);
6877 break;
6878 }
6879 }
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006880 DP(NETIF_MSG_LINK, "vars->flow_ctrl = 0x%x, vars->link_status = 0x%x,"
6881 " ext_phy_line_speed = %d\n", vars->flow_ctrl,
6882 vars->link_status, ext_phy_line_speed);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00006883 /* Upon link speed change set the NIG into drain mode. Comes to
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006884 * deals with possible FIFO glitch due to clk change when speed
6885 * is decreased without link down indicator
6886 */
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006887
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006888 if (vars->phy_link_up) {
6889 if (!(SINGLE_MEDIA_DIRECT(params)) && ext_phy_link_up &&
6890 (ext_phy_line_speed != vars->line_speed)) {
6891 DP(NETIF_MSG_LINK, "Internal link speed %d is"
6892 " different than the external"
6893 " link speed %d\n", vars->line_speed,
6894 ext_phy_line_speed);
6895 vars->phy_link_up = 0;
6896 } else if (prev_line_speed != vars->line_speed) {
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006897 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4,
6898 0);
Yaniv Rosner503976e2012-11-27 03:46:34 +00006899 usleep_range(1000, 2000);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006900 }
6901 }
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006902
Yuval Mintzd2310232012-06-20 19:05:19 +00006903 /* Anything 10 and over uses the bmac */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006904 link_10g_plus = (vars->line_speed >= SPEED_10000);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006905
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006906 bnx2x_link_int_ack(params, vars, link_10g_plus);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006907
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00006908 /* In case external phy link is up, and internal link is down
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00006909 * (not initialized yet probably after link initialization, it
6910 * needs to be initialized.
6911 * Note that after link down-up as result of cable plug, the xgxs
6912 * link would probably become up again without the need
6913 * initialize it
6914 */
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006915 if (!(SINGLE_MEDIA_DIRECT(params))) {
6916 DP(NETIF_MSG_LINK, "ext_phy_link_up = %d, int_link_up = %d,"
6917 " init_preceding = %d\n", ext_phy_link_up,
6918 vars->phy_link_up,
6919 params->phy[EXT_PHY1].flags &
6920 FLAGS_INIT_XGXS_FIRST);
6921 if (!(params->phy[EXT_PHY1].flags &
6922 FLAGS_INIT_XGXS_FIRST)
6923 && ext_phy_link_up && !vars->phy_link_up) {
6924 vars->line_speed = ext_phy_line_speed;
6925 if (vars->line_speed < SPEED_1000)
6926 vars->phy_flags |= PHY_SGMII_FLAG;
6927 else
6928 vars->phy_flags &= ~PHY_SGMII_FLAG;
Yaniv Rosnerec146a62011-05-31 21:29:27 +00006929
6930 if (params->phy[INT_PHY].config_init)
6931 params->phy[INT_PHY].config_init(
6932 &params->phy[INT_PHY], params,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006933 vars);
6934 }
6935 }
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00006936 /* Link is up only if both local phy and external phy (in case of
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00006937 * non-direct board) are up and no fault detected on active PHY.
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006938 */
6939 vars->link_up = (vars->phy_link_up &&
6940 (ext_phy_link_up ||
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00006941 SINGLE_MEDIA_DIRECT(params)) &&
6942 (phy_vars[active_external_phy].fault_detected == 0));
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006943
Yaniv Rosner27d91292012-04-04 01:28:54 +00006944 /* Update the PFC configuration in case it was changed */
6945 if (params->feature_config_flags & FEATURE_CONFIG_PFC_ENABLED)
6946 vars->link_status |= LINK_STATUS_PFC_ENABLED;
6947 else
6948 vars->link_status &= ~LINK_STATUS_PFC_ENABLED;
6949
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006950 if (vars->link_up)
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00006951 rc = bnx2x_update_link_up(params, vars, link_10g_plus);
Yaniv Rosner57963ed2008-08-13 15:55:28 -07006952 else
6953 rc = bnx2x_update_link_down(params, vars);
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006954
Barak Witkowskia3348722012-04-23 03:04:46 +00006955 /* Update MCP link status was changed */
6956 if (params->feature_config_flags & FEATURE_CONFIG_BC_SUPPORTS_AFEX)
6957 bnx2x_fw_command(bp, DRV_MSG_CODE_LINK_STATUS_CHANGED, 0);
6958
Yaniv Rosnerea4e0402008-06-23 20:27:26 -07006959 return rc;
6960}
6961
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006962/*****************************************************************************/
6963/* External Phy section */
6964/*****************************************************************************/
6965void bnx2x_ext_phy_hw_reset(struct bnx2x *bp, u8 port)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006966{
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006967 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006968 MISC_REGISTERS_GPIO_OUTPUT_LOW, port);
Yaniv Rosner503976e2012-11-27 03:46:34 +00006969 usleep_range(1000, 2000);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006970 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006971 MISC_REGISTERS_GPIO_OUTPUT_HIGH, port);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00006972}
6973
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006974static void bnx2x_save_spirom_version(struct bnx2x *bp, u8 port,
6975 u32 spirom_ver, u32 ver_addr)
6976{
6977 DP(NETIF_MSG_LINK, "FW version 0x%x:0x%x for port %d\n",
6978 (u16)(spirom_ver>>16), (u16)spirom_ver, port);
6979
6980 if (ver_addr)
6981 REG_WR(bp, ver_addr, spirom_ver);
6982}
6983
6984static void bnx2x_save_bcm_spirom_ver(struct bnx2x *bp,
6985 struct bnx2x_phy *phy,
6986 u8 port)
6987{
6988 u16 fw_ver1, fw_ver2;
6989
6990 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006991 MDIO_PMA_REG_ROM_VER1, &fw_ver1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006992 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00006993 MDIO_PMA_REG_ROM_VER2, &fw_ver2);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006994 bnx2x_save_spirom_version(bp, port, (u32)(fw_ver1<<16 | fw_ver2),
6995 phy->ver_addr);
6996}
6997
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00006998static void bnx2x_ext_phy_10G_an_resolve(struct bnx2x *bp,
6999 struct bnx2x_phy *phy,
7000 struct link_vars *vars)
7001{
7002 u16 val;
7003 bnx2x_cl45_read(bp, phy,
7004 MDIO_AN_DEVAD,
7005 MDIO_AN_REG_STATUS, &val);
7006 bnx2x_cl45_read(bp, phy,
7007 MDIO_AN_DEVAD,
7008 MDIO_AN_REG_STATUS, &val);
7009 if (val & (1<<5))
7010 vars->link_status |= LINK_STATUS_AUTO_NEGOTIATE_COMPLETE;
7011 if ((val & (1<<0)) == 0)
7012 vars->link_status |= LINK_STATUS_PARALLEL_DETECTION_USED;
7013}
7014
7015/******************************************************************/
7016/* common BCM8073/BCM8727 PHY SECTION */
7017/******************************************************************/
7018static void bnx2x_8073_resolve_fc(struct bnx2x_phy *phy,
7019 struct link_params *params,
7020 struct link_vars *vars)
7021{
7022 struct bnx2x *bp = params->bp;
7023 if (phy->req_line_speed == SPEED_10 ||
7024 phy->req_line_speed == SPEED_100) {
7025 vars->flow_ctrl = phy->req_flow_ctrl;
7026 return;
7027 }
7028
7029 if (bnx2x_ext_phy_resolve_fc(phy, params, vars) &&
7030 (vars->flow_ctrl == BNX2X_FLOW_CTRL_NONE)) {
7031 u16 pause_result;
7032 u16 ld_pause; /* local */
7033 u16 lp_pause; /* link partner */
7034 bnx2x_cl45_read(bp, phy,
7035 MDIO_AN_DEVAD,
7036 MDIO_AN_REG_CL37_FC_LD, &ld_pause);
7037
7038 bnx2x_cl45_read(bp, phy,
7039 MDIO_AN_DEVAD,
7040 MDIO_AN_REG_CL37_FC_LP, &lp_pause);
7041 pause_result = (ld_pause &
7042 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) >> 5;
7043 pause_result |= (lp_pause &
7044 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) >> 7;
7045
7046 bnx2x_pause_resolve(vars, pause_result);
7047 DP(NETIF_MSG_LINK, "Ext PHY CL37 pause result 0x%x\n",
7048 pause_result);
7049 }
7050}
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00007051static int bnx2x_8073_8727_external_rom_boot(struct bnx2x *bp,
7052 struct bnx2x_phy *phy,
7053 u8 port)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007054{
Yaniv Rosner5c99274b2011-01-18 04:33:36 +00007055 u32 count = 0;
7056 u16 fw_ver1, fw_msgout;
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00007057 int rc = 0;
Yaniv Rosner5c99274b2011-01-18 04:33:36 +00007058
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007059 /* Boot port from external ROM */
7060 /* EDC grst */
7061 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007062 MDIO_PMA_DEVAD,
7063 MDIO_PMA_REG_GEN_CTRL,
7064 0x0001);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007065
Yuval Mintzd2310232012-06-20 19:05:19 +00007066 /* Ucode reboot and rst */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007067 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007068 MDIO_PMA_DEVAD,
7069 MDIO_PMA_REG_GEN_CTRL,
7070 0x008c);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007071
7072 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007073 MDIO_PMA_DEVAD,
7074 MDIO_PMA_REG_MISC_CTRL1, 0x0001);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007075
7076 /* Reset internal microprocessor */
7077 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007078 MDIO_PMA_DEVAD,
7079 MDIO_PMA_REG_GEN_CTRL,
7080 MDIO_PMA_REG_GEN_CTRL_ROM_MICRO_RESET);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007081
7082 /* Release srst bit */
7083 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007084 MDIO_PMA_DEVAD,
7085 MDIO_PMA_REG_GEN_CTRL,
7086 MDIO_PMA_REG_GEN_CTRL_ROM_RESET_INTERNAL_MP);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007087
Yaniv Rosner5c99274b2011-01-18 04:33:36 +00007088 /* Delay 100ms per the PHY specifications */
7089 msleep(100);
7090
7091 /* 8073 sometimes taking longer to download */
7092 do {
7093 count++;
7094 if (count > 300) {
7095 DP(NETIF_MSG_LINK,
7096 "bnx2x_8073_8727_external_rom_boot port %x:"
7097 "Download failed. fw version = 0x%x\n",
7098 port, fw_ver1);
7099 rc = -EINVAL;
7100 break;
7101 }
7102
7103 bnx2x_cl45_read(bp, phy,
7104 MDIO_PMA_DEVAD,
7105 MDIO_PMA_REG_ROM_VER1, &fw_ver1);
7106 bnx2x_cl45_read(bp, phy,
7107 MDIO_PMA_DEVAD,
7108 MDIO_PMA_REG_M8051_MSGOUT_REG, &fw_msgout);
7109
Yaniv Rosner503976e2012-11-27 03:46:34 +00007110 usleep_range(1000, 2000);
Yaniv Rosner5c99274b2011-01-18 04:33:36 +00007111 } while (fw_ver1 == 0 || fw_ver1 == 0x4321 ||
7112 ((fw_msgout & 0xff) != 0x03 && (phy->type ==
7113 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073)));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007114
7115 /* Clear ser_boot_ctl bit */
7116 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007117 MDIO_PMA_DEVAD,
7118 MDIO_PMA_REG_MISC_CTRL1, 0x0000);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007119 bnx2x_save_bcm_spirom_ver(bp, phy, port);
Yaniv Rosner5c99274b2011-01-18 04:33:36 +00007120
7121 DP(NETIF_MSG_LINK,
7122 "bnx2x_8073_8727_external_rom_boot port %x:"
7123 "Download complete. fw version = 0x%x\n",
7124 port, fw_ver1);
7125
7126 return rc;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007127}
7128
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007129/******************************************************************/
7130/* BCM8073 PHY SECTION */
7131/******************************************************************/
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00007132static int bnx2x_8073_is_snr_needed(struct bnx2x *bp, struct bnx2x_phy *phy)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007133{
7134 /* This is only required for 8073A1, version 102 only */
7135 u16 val;
7136
7137 /* Read 8073 HW revision*/
7138 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007139 MDIO_PMA_DEVAD,
7140 MDIO_PMA_REG_8073_CHIP_REV, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007141
7142 if (val != 1) {
7143 /* No need to workaround in 8073 A1 */
7144 return 0;
7145 }
7146
7147 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007148 MDIO_PMA_DEVAD,
7149 MDIO_PMA_REG_ROM_VER2, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007150
7151 /* SNR should be applied only for version 0x102 */
7152 if (val != 0x102)
7153 return 0;
7154
7155 return 1;
7156}
7157
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00007158static int bnx2x_8073_xaui_wa(struct bnx2x *bp, struct bnx2x_phy *phy)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007159{
7160 u16 val, cnt, cnt1 ;
7161
7162 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007163 MDIO_PMA_DEVAD,
7164 MDIO_PMA_REG_8073_CHIP_REV, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007165
7166 if (val > 0) {
7167 /* No need to workaround in 8073 A1 */
7168 return 0;
7169 }
7170 /* XAUI workaround in 8073 A0: */
7171
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00007172 /* After loading the boot ROM and restarting Autoneg, poll
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007173 * Dev1, Reg $C820:
7174 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007175
7176 for (cnt = 0; cnt < 1000; cnt++) {
7177 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007178 MDIO_PMA_DEVAD,
7179 MDIO_PMA_REG_8073_SPEED_LINK_STATUS,
7180 &val);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00007181 /* If bit [14] = 0 or bit [13] = 0, continue on with
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007182 * system initialization (XAUI work-around not required, as
7183 * these bits indicate 2.5G or 1G link up).
7184 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007185 if (!(val & (1<<14)) || !(val & (1<<13))) {
7186 DP(NETIF_MSG_LINK, "XAUI work-around not required\n");
7187 return 0;
7188 } else if (!(val & (1<<15))) {
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007189 DP(NETIF_MSG_LINK, "bit 15 went off\n");
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00007190 /* If bit 15 is 0, then poll Dev1, Reg $C841 until it's
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007191 * MSB (bit15) goes to 1 (indicating that the XAUI
7192 * workaround has completed), then continue on with
7193 * system initialization.
7194 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007195 for (cnt1 = 0; cnt1 < 1000; cnt1++) {
7196 bnx2x_cl45_read(bp, phy,
7197 MDIO_PMA_DEVAD,
7198 MDIO_PMA_REG_8073_XAUI_WA, &val);
7199 if (val & (1<<15)) {
7200 DP(NETIF_MSG_LINK,
7201 "XAUI workaround has completed\n");
7202 return 0;
7203 }
Yuval Mintzd2310232012-06-20 19:05:19 +00007204 usleep_range(3000, 6000);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007205 }
7206 break;
7207 }
Yuval Mintzd2310232012-06-20 19:05:19 +00007208 usleep_range(3000, 6000);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007209 }
7210 DP(NETIF_MSG_LINK, "Warning: XAUI work-around timeout !!!\n");
7211 return -EINVAL;
7212}
7213
7214static void bnx2x_807x_force_10G(struct bnx2x *bp, struct bnx2x_phy *phy)
7215{
7216 /* Force KR or KX */
7217 bnx2x_cl45_write(bp, phy,
7218 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x2040);
7219 bnx2x_cl45_write(bp, phy,
7220 MDIO_PMA_DEVAD, MDIO_PMA_REG_10G_CTRL2, 0x000b);
7221 bnx2x_cl45_write(bp, phy,
7222 MDIO_PMA_DEVAD, MDIO_PMA_REG_BCM_CTRL, 0x0000);
7223 bnx2x_cl45_write(bp, phy,
7224 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x0000);
7225}
7226
7227static void bnx2x_8073_set_pause_cl37(struct link_params *params,
7228 struct bnx2x_phy *phy,
7229 struct link_vars *vars)
7230{
7231 u16 cl37_val;
7232 struct bnx2x *bp = params->bp;
7233 bnx2x_cl45_read(bp, phy,
7234 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LD, &cl37_val);
7235
7236 cl37_val &= ~MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH;
7237 /* Please refer to Table 28B-3 of 802.3ab-1999 spec. */
7238 bnx2x_calc_ieee_aneg_adv(phy, params, &vars->ieee_fc);
7239 if ((vars->ieee_fc &
7240 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_SYMMETRIC) ==
7241 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_SYMMETRIC) {
7242 cl37_val |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_SYMMETRIC;
7243 }
7244 if ((vars->ieee_fc &
7245 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC) ==
7246 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC) {
7247 cl37_val |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC;
7248 }
7249 if ((vars->ieee_fc &
7250 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) ==
7251 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) {
7252 cl37_val |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH;
7253 }
7254 DP(NETIF_MSG_LINK,
7255 "Ext phy AN advertize cl37 0x%x\n", cl37_val);
7256
7257 bnx2x_cl45_write(bp, phy,
7258 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LD, cl37_val);
7259 msleep(500);
7260}
7261
Yaniv Rosner5c107fd2012-09-13 02:56:19 +00007262static void bnx2x_8073_specific_func(struct bnx2x_phy *phy,
7263 struct link_params *params,
7264 u32 action)
7265{
7266 struct bnx2x *bp = params->bp;
7267 switch (action) {
7268 case PHY_INIT:
7269 /* Enable LASI */
7270 bnx2x_cl45_write(bp, phy,
7271 MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXCTRL, (1<<2));
7272 bnx2x_cl45_write(bp, phy,
7273 MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL, 0x0004);
7274 break;
7275 }
7276}
7277
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00007278static int bnx2x_8073_config_init(struct bnx2x_phy *phy,
7279 struct link_params *params,
7280 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007281{
7282 struct bnx2x *bp = params->bp;
7283 u16 val = 0, tmp1;
7284 u8 gpio_port;
7285 DP(NETIF_MSG_LINK, "Init 8073\n");
7286
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007287 if (CHIP_IS_E2(bp))
7288 gpio_port = BP_PATH(bp);
7289 else
7290 gpio_port = params->port;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007291 /* Restore normal power mode*/
7292 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007293 MISC_REGISTERS_GPIO_OUTPUT_HIGH, gpio_port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007294
7295 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007296 MISC_REGISTERS_GPIO_OUTPUT_HIGH, gpio_port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007297
Yaniv Rosner5c107fd2012-09-13 02:56:19 +00007298 bnx2x_8073_specific_func(phy, params, PHY_INIT);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007299 bnx2x_8073_set_pause_cl37(params, phy, vars);
7300
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007301 bnx2x_cl45_read(bp, phy,
7302 MDIO_PMA_DEVAD, MDIO_PMA_REG_M8051_MSGOUT_REG, &tmp1);
7303
7304 bnx2x_cl45_read(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00007305 MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXSTAT, &tmp1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007306
7307 DP(NETIF_MSG_LINK, "Before rom RX_ALARM(port1): 0x%x\n", tmp1);
7308
Yaniv Rosner74d7a112011-01-18 04:33:18 +00007309 /* Swap polarity if required - Must be done only in non-1G mode */
7310 if (params->lane_config & PORT_HW_CFG_SWAP_PHY_POLARITY_ENABLED) {
7311 /* Configure the 8073 to swap _P and _N of the KR lines */
7312 DP(NETIF_MSG_LINK, "Swapping polarity for the 8073\n");
7313 /* 10G Rx/Tx and 1G Tx signal polarity swap */
7314 bnx2x_cl45_read(bp, phy,
7315 MDIO_PMA_DEVAD,
7316 MDIO_PMA_REG_8073_OPT_DIGITAL_CTRL, &val);
7317 bnx2x_cl45_write(bp, phy,
7318 MDIO_PMA_DEVAD,
7319 MDIO_PMA_REG_8073_OPT_DIGITAL_CTRL,
7320 (val | (3<<9)));
7321 }
7322
7323
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007324 /* Enable CL37 BAM */
Yaniv Rosner121839b2010-11-01 05:32:38 +00007325 if (REG_RD(bp, params->shmem_base +
7326 offsetof(struct shmem_region, dev_info.
7327 port_hw_config[params->port].default_cfg)) &
7328 PORT_HW_CFG_ENABLE_BAM_ON_KR_ENABLED) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007329
Yaniv Rosner121839b2010-11-01 05:32:38 +00007330 bnx2x_cl45_read(bp, phy,
7331 MDIO_AN_DEVAD,
7332 MDIO_AN_REG_8073_BAM, &val);
7333 bnx2x_cl45_write(bp, phy,
7334 MDIO_AN_DEVAD,
7335 MDIO_AN_REG_8073_BAM, val | 1);
7336 DP(NETIF_MSG_LINK, "Enable CL37 BAM on KR\n");
7337 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007338 if (params->loopback_mode == LOOPBACK_EXT) {
7339 bnx2x_807x_force_10G(bp, phy);
7340 DP(NETIF_MSG_LINK, "Forced speed 10G on 807X\n");
7341 return 0;
7342 } else {
7343 bnx2x_cl45_write(bp, phy,
7344 MDIO_PMA_DEVAD, MDIO_PMA_REG_BCM_CTRL, 0x0002);
7345 }
7346 if (phy->req_line_speed != SPEED_AUTO_NEG) {
7347 if (phy->req_line_speed == SPEED_10000) {
7348 val = (1<<7);
7349 } else if (phy->req_line_speed == SPEED_2500) {
7350 val = (1<<5);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00007351 /* Note that 2.5G works only when used with 1G
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007352 * advertisement
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007353 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007354 } else
7355 val = (1<<5);
7356 } else {
7357 val = 0;
7358 if (phy->speed_cap_mask &
7359 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
7360 val |= (1<<7);
7361
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007362 /* Note that 2.5G works only when used with 1G advertisement */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007363 if (phy->speed_cap_mask &
7364 (PORT_HW_CFG_SPEED_CAPABILITY_D0_1G |
7365 PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
7366 val |= (1<<5);
7367 DP(NETIF_MSG_LINK, "807x autoneg val = 0x%x\n", val);
7368 }
7369
7370 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV, val);
7371 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_8073_2_5G, &tmp1);
7372
7373 if (((phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G) &&
7374 (phy->req_line_speed == SPEED_AUTO_NEG)) ||
7375 (phy->req_line_speed == SPEED_2500)) {
7376 u16 phy_ver;
7377 /* Allow 2.5G for A1 and above */
7378 bnx2x_cl45_read(bp, phy,
7379 MDIO_PMA_DEVAD, MDIO_PMA_REG_8073_CHIP_REV,
7380 &phy_ver);
7381 DP(NETIF_MSG_LINK, "Add 2.5G\n");
7382 if (phy_ver > 0)
7383 tmp1 |= 1;
7384 else
7385 tmp1 &= 0xfffe;
7386 } else {
7387 DP(NETIF_MSG_LINK, "Disable 2.5G\n");
7388 tmp1 &= 0xfffe;
7389 }
7390
7391 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_8073_2_5G, tmp1);
7392 /* Add support for CL37 (passive mode) II */
7393
7394 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LD, &tmp1);
7395 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LD,
7396 (tmp1 | ((phy->req_duplex == DUPLEX_FULL) ?
7397 0x20 : 0x40)));
7398
7399 /* Add support for CL37 (passive mode) III */
7400 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CL37_AN, 0x1000);
7401
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00007402 /* The SNR will improve about 2db by changing BW and FEE main
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007403 * tap. Rest commands are executed after link is up
7404 * Change FFE main cursor to 5 in EDC register
7405 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007406 if (bnx2x_8073_is_snr_needed(bp, phy))
7407 bnx2x_cl45_write(bp, phy,
7408 MDIO_PMA_DEVAD, MDIO_PMA_REG_EDC_FFE_MAIN,
7409 0xFB0C);
7410
7411 /* Enable FEC (Forware Error Correction) Request in the AN */
7412 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV2, &tmp1);
7413 tmp1 |= (1<<15);
7414 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV2, tmp1);
7415
7416 bnx2x_ext_phy_set_pause(params, phy, vars);
7417
7418 /* Restart autoneg */
7419 msleep(500);
7420 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x1200);
7421 DP(NETIF_MSG_LINK, "807x Autoneg Restart: Advertise 1G=%x, 10G=%x\n",
7422 ((val & (1<<5)) > 0), ((val & (1<<7)) > 0));
7423 return 0;
7424}
7425
7426static u8 bnx2x_8073_read_status(struct bnx2x_phy *phy,
7427 struct link_params *params,
7428 struct link_vars *vars)
7429{
7430 struct bnx2x *bp = params->bp;
7431 u8 link_up = 0;
7432 u16 val1, val2;
7433 u16 link_status = 0;
7434 u16 an1000_status = 0;
7435
7436 bnx2x_cl45_read(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00007437 MDIO_PMA_DEVAD, MDIO_PMA_LASI_STAT, &val1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007438
7439 DP(NETIF_MSG_LINK, "8703 LASI status 0x%x\n", val1);
7440
Yuval Mintzd2310232012-06-20 19:05:19 +00007441 /* Clear the interrupt LASI status register */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007442 bnx2x_cl45_read(bp, phy,
7443 MDIO_PCS_DEVAD, MDIO_PCS_REG_STATUS, &val2);
7444 bnx2x_cl45_read(bp, phy,
7445 MDIO_PCS_DEVAD, MDIO_PCS_REG_STATUS, &val1);
7446 DP(NETIF_MSG_LINK, "807x PCS status 0x%x->0x%x\n", val2, val1);
7447 /* Clear MSG-OUT */
7448 bnx2x_cl45_read(bp, phy,
7449 MDIO_PMA_DEVAD, MDIO_PMA_REG_M8051_MSGOUT_REG, &val1);
7450
7451 /* Check the LASI */
7452 bnx2x_cl45_read(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00007453 MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXSTAT, &val2);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007454
7455 DP(NETIF_MSG_LINK, "KR 0x9003 0x%x\n", val2);
7456
7457 /* Check the link status */
7458 bnx2x_cl45_read(bp, phy,
7459 MDIO_PCS_DEVAD, MDIO_PCS_REG_STATUS, &val2);
7460 DP(NETIF_MSG_LINK, "KR PCS status 0x%x\n", val2);
7461
7462 bnx2x_cl45_read(bp, phy,
7463 MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val2);
7464 bnx2x_cl45_read(bp, phy,
7465 MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val1);
7466 link_up = ((val1 & 4) == 4);
7467 DP(NETIF_MSG_LINK, "PMA_REG_STATUS=0x%x\n", val1);
7468
7469 if (link_up &&
7470 ((phy->req_line_speed != SPEED_10000))) {
7471 if (bnx2x_8073_xaui_wa(bp, phy) != 0)
7472 return 0;
7473 }
7474 bnx2x_cl45_read(bp, phy,
7475 MDIO_AN_DEVAD, MDIO_AN_REG_LINK_STATUS, &an1000_status);
7476 bnx2x_cl45_read(bp, phy,
7477 MDIO_AN_DEVAD, MDIO_AN_REG_LINK_STATUS, &an1000_status);
7478
7479 /* Check the link status on 1.1.2 */
7480 bnx2x_cl45_read(bp, phy,
7481 MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val2);
7482 bnx2x_cl45_read(bp, phy,
7483 MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val1);
7484 DP(NETIF_MSG_LINK, "KR PMA status 0x%x->0x%x,"
7485 "an_link_status=0x%x\n", val2, val1, an1000_status);
7486
7487 link_up = (((val1 & 4) == 4) || (an1000_status & (1<<1)));
7488 if (link_up && bnx2x_8073_is_snr_needed(bp, phy)) {
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00007489 /* The SNR will improve about 2dbby changing the BW and FEE main
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007490 * tap. The 1st write to change FFE main tap is set before
7491 * restart AN. Change PLL Bandwidth in EDC register
7492 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007493 bnx2x_cl45_write(bp, phy,
7494 MDIO_PMA_DEVAD, MDIO_PMA_REG_PLL_BANDWIDTH,
7495 0x26BC);
7496
7497 /* Change CDR Bandwidth in EDC register */
7498 bnx2x_cl45_write(bp, phy,
7499 MDIO_PMA_DEVAD, MDIO_PMA_REG_CDR_BANDWIDTH,
7500 0x0333);
7501 }
7502 bnx2x_cl45_read(bp, phy,
7503 MDIO_PMA_DEVAD, MDIO_PMA_REG_8073_SPEED_LINK_STATUS,
7504 &link_status);
7505
7506 /* Bits 0..2 --> speed detected, bits 13..15--> link is down */
7507 if ((link_status & (1<<2)) && (!(link_status & (1<<15)))) {
7508 link_up = 1;
7509 vars->line_speed = SPEED_10000;
7510 DP(NETIF_MSG_LINK, "port %x: External link up in 10G\n",
7511 params->port);
7512 } else if ((link_status & (1<<1)) && (!(link_status & (1<<14)))) {
7513 link_up = 1;
7514 vars->line_speed = SPEED_2500;
7515 DP(NETIF_MSG_LINK, "port %x: External link up in 2.5G\n",
7516 params->port);
7517 } else if ((link_status & (1<<0)) && (!(link_status & (1<<13)))) {
7518 link_up = 1;
7519 vars->line_speed = SPEED_1000;
7520 DP(NETIF_MSG_LINK, "port %x: External link up in 1G\n",
7521 params->port);
7522 } else {
7523 link_up = 0;
7524 DP(NETIF_MSG_LINK, "port %x: External link is down\n",
7525 params->port);
7526 }
7527
7528 if (link_up) {
Yaniv Rosner74d7a112011-01-18 04:33:18 +00007529 /* Swap polarity if required */
7530 if (params->lane_config &
7531 PORT_HW_CFG_SWAP_PHY_POLARITY_ENABLED) {
7532 /* Configure the 8073 to swap P and N of the KR lines */
7533 bnx2x_cl45_read(bp, phy,
7534 MDIO_XS_DEVAD,
7535 MDIO_XS_REG_8073_RX_CTRL_PCIE, &val1);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00007536 /* Set bit 3 to invert Rx in 1G mode and clear this bit
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007537 * when it`s in 10G mode.
7538 */
Yaniv Rosner74d7a112011-01-18 04:33:18 +00007539 if (vars->line_speed == SPEED_1000) {
7540 DP(NETIF_MSG_LINK, "Swapping 1G polarity for"
7541 "the 8073\n");
7542 val1 |= (1<<3);
7543 } else
7544 val1 &= ~(1<<3);
7545
7546 bnx2x_cl45_write(bp, phy,
7547 MDIO_XS_DEVAD,
7548 MDIO_XS_REG_8073_RX_CTRL_PCIE,
7549 val1);
7550 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007551 bnx2x_ext_phy_10G_an_resolve(bp, phy, vars);
7552 bnx2x_8073_resolve_fc(phy, params, vars);
Yaniv Rosner791f18c2011-01-18 04:33:42 +00007553 vars->duplex = DUPLEX_FULL;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007554 }
Mintz Yuval9e7e8392012-02-15 02:10:24 +00007555
7556 if (vars->link_status & LINK_STATUS_AUTO_NEGOTIATE_COMPLETE) {
7557 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
7558 MDIO_AN_REG_LP_AUTO_NEG2, &val1);
7559
7560 if (val1 & (1<<5))
7561 vars->link_status |=
7562 LINK_STATUS_LINK_PARTNER_1000TFD_CAPABLE;
7563 if (val1 & (1<<7))
7564 vars->link_status |=
7565 LINK_STATUS_LINK_PARTNER_10GXFD_CAPABLE;
7566 }
7567
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007568 return link_up;
7569}
7570
7571static void bnx2x_8073_link_reset(struct bnx2x_phy *phy,
7572 struct link_params *params)
7573{
7574 struct bnx2x *bp = params->bp;
7575 u8 gpio_port;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00007576 if (CHIP_IS_E2(bp))
7577 gpio_port = BP_PATH(bp);
7578 else
7579 gpio_port = params->port;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007580 DP(NETIF_MSG_LINK, "Setting 8073 port %d into low power mode\n",
7581 gpio_port);
7582 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007583 MISC_REGISTERS_GPIO_OUTPUT_LOW,
7584 gpio_port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007585}
7586
7587/******************************************************************/
7588/* BCM8705 PHY SECTION */
7589/******************************************************************/
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00007590static int bnx2x_8705_config_init(struct bnx2x_phy *phy,
7591 struct link_params *params,
7592 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007593{
7594 struct bnx2x *bp = params->bp;
7595 DP(NETIF_MSG_LINK, "init 8705\n");
7596 /* Restore normal power mode*/
7597 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007598 MISC_REGISTERS_GPIO_OUTPUT_HIGH, params->port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007599 /* HW reset */
7600 bnx2x_ext_phy_hw_reset(bp, params->port);
7601 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0xa040);
Yaniv Rosner6d870c32011-01-31 04:22:20 +00007602 bnx2x_wait_reset_complete(bp, phy, params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007603
7604 bnx2x_cl45_write(bp, phy,
7605 MDIO_PMA_DEVAD, MDIO_PMA_REG_MISC_CTRL, 0x8288);
7606 bnx2x_cl45_write(bp, phy,
7607 MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER, 0x7fbf);
7608 bnx2x_cl45_write(bp, phy,
7609 MDIO_PMA_DEVAD, MDIO_PMA_REG_CMU_PLL_BYPASS, 0x0100);
7610 bnx2x_cl45_write(bp, phy,
7611 MDIO_WIS_DEVAD, MDIO_WIS_REG_LASI_CNTL, 0x1);
7612 /* BCM8705 doesn't have microcode, hence the 0 */
7613 bnx2x_save_spirom_version(bp, params->port, params->shmem_base, 0);
7614 return 0;
7615}
7616
7617static u8 bnx2x_8705_read_status(struct bnx2x_phy *phy,
7618 struct link_params *params,
7619 struct link_vars *vars)
7620{
7621 u8 link_up = 0;
7622 u16 val1, rx_sd;
7623 struct bnx2x *bp = params->bp;
7624 DP(NETIF_MSG_LINK, "read status 8705\n");
7625 bnx2x_cl45_read(bp, phy,
7626 MDIO_WIS_DEVAD, MDIO_WIS_REG_LASI_STATUS, &val1);
7627 DP(NETIF_MSG_LINK, "8705 LASI status 0x%x\n", val1);
7628
7629 bnx2x_cl45_read(bp, phy,
7630 MDIO_WIS_DEVAD, MDIO_WIS_REG_LASI_STATUS, &val1);
7631 DP(NETIF_MSG_LINK, "8705 LASI status 0x%x\n", val1);
7632
7633 bnx2x_cl45_read(bp, phy,
7634 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_SD, &rx_sd);
7635
7636 bnx2x_cl45_read(bp, phy,
7637 MDIO_PMA_DEVAD, 0xc809, &val1);
7638 bnx2x_cl45_read(bp, phy,
7639 MDIO_PMA_DEVAD, 0xc809, &val1);
7640
7641 DP(NETIF_MSG_LINK, "8705 1.c809 val=0x%x\n", val1);
7642 link_up = ((rx_sd & 0x1) && (val1 & (1<<9)) && ((val1 & (1<<8)) == 0));
7643 if (link_up) {
7644 vars->line_speed = SPEED_10000;
7645 bnx2x_ext_phy_resolve_fc(phy, params, vars);
7646 }
7647 return link_up;
7648}
7649
7650/******************************************************************/
7651/* SFP+ module Section */
7652/******************************************************************/
Yaniv Rosner85242ee2011-07-05 01:06:53 +00007653static void bnx2x_set_disable_pmd_transmit(struct link_params *params,
7654 struct bnx2x_phy *phy,
7655 u8 pmd_dis)
7656{
7657 struct bnx2x *bp = params->bp;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00007658 /* Disable transmitter only for bootcodes which can enable it afterwards
Yaniv Rosner85242ee2011-07-05 01:06:53 +00007659 * (for D3 link)
7660 */
7661 if (pmd_dis) {
7662 if (params->feature_config_flags &
7663 FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED)
7664 DP(NETIF_MSG_LINK, "Disabling PMD transmitter\n");
7665 else {
7666 DP(NETIF_MSG_LINK, "NOT disabling PMD transmitter\n");
7667 return;
7668 }
7669 } else
7670 DP(NETIF_MSG_LINK, "Enabling PMD transmitter\n");
7671 bnx2x_cl45_write(bp, phy,
7672 MDIO_PMA_DEVAD,
7673 MDIO_PMA_REG_TX_DISABLE, pmd_dis);
7674}
7675
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00007676static u8 bnx2x_get_gpio_port(struct link_params *params)
7677{
7678 u8 gpio_port;
7679 u32 swap_val, swap_override;
7680 struct bnx2x *bp = params->bp;
7681 if (CHIP_IS_E2(bp))
7682 gpio_port = BP_PATH(bp);
7683 else
7684 gpio_port = params->port;
7685 swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
7686 swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
7687 return gpio_port ^ (swap_val && swap_override);
7688}
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00007689
7690static void bnx2x_sfp_e1e2_set_transmitter(struct link_params *params,
7691 struct bnx2x_phy *phy,
7692 u8 tx_en)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007693{
7694 u16 val;
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00007695 u8 port = params->port;
7696 struct bnx2x *bp = params->bp;
7697 u32 tx_en_mode;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007698
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007699 /* Disable/Enable transmitter ( TX laser of the SFP+ module.)*/
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00007700 tx_en_mode = REG_RD(bp, params->shmem_base +
7701 offsetof(struct shmem_region,
7702 dev_info.port_hw_config[port].sfp_ctrl)) &
7703 PORT_HW_CFG_TX_LASER_MASK;
7704 DP(NETIF_MSG_LINK, "Setting transmitter tx_en=%x for port %x "
7705 "mode = %x\n", tx_en, port, tx_en_mode);
7706 switch (tx_en_mode) {
7707 case PORT_HW_CFG_TX_LASER_MDIO:
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007708
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00007709 bnx2x_cl45_read(bp, phy,
7710 MDIO_PMA_DEVAD,
7711 MDIO_PMA_REG_PHY_IDENTIFIER,
7712 &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007713
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00007714 if (tx_en)
7715 val &= ~(1<<15);
7716 else
7717 val |= (1<<15);
7718
7719 bnx2x_cl45_write(bp, phy,
7720 MDIO_PMA_DEVAD,
7721 MDIO_PMA_REG_PHY_IDENTIFIER,
7722 val);
7723 break;
7724 case PORT_HW_CFG_TX_LASER_GPIO0:
7725 case PORT_HW_CFG_TX_LASER_GPIO1:
7726 case PORT_HW_CFG_TX_LASER_GPIO2:
7727 case PORT_HW_CFG_TX_LASER_GPIO3:
7728 {
7729 u16 gpio_pin;
7730 u8 gpio_port, gpio_mode;
7731 if (tx_en)
7732 gpio_mode = MISC_REGISTERS_GPIO_OUTPUT_HIGH;
7733 else
7734 gpio_mode = MISC_REGISTERS_GPIO_OUTPUT_LOW;
7735
7736 gpio_pin = tx_en_mode - PORT_HW_CFG_TX_LASER_GPIO0;
7737 gpio_port = bnx2x_get_gpio_port(params);
7738 bnx2x_set_gpio(bp, gpio_pin, gpio_mode, gpio_port);
7739 break;
7740 }
7741 default:
7742 DP(NETIF_MSG_LINK, "Invalid TX_LASER_MDIO 0x%x\n", tx_en_mode);
7743 break;
7744 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007745}
7746
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00007747static void bnx2x_sfp_set_transmitter(struct link_params *params,
7748 struct bnx2x_phy *phy,
7749 u8 tx_en)
7750{
7751 struct bnx2x *bp = params->bp;
7752 DP(NETIF_MSG_LINK, "Setting SFP+ transmitter to %d\n", tx_en);
7753 if (CHIP_IS_E3(bp))
7754 bnx2x_sfp_e3_set_transmitter(params, phy, tx_en);
7755 else
7756 bnx2x_sfp_e1e2_set_transmitter(params, phy, tx_en);
7757}
7758
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00007759static int bnx2x_8726_read_sfp_module_eeprom(struct bnx2x_phy *phy,
7760 struct link_params *params,
7761 u16 addr, u8 byte_cnt, u8 *o_buf)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007762{
7763 struct bnx2x *bp = params->bp;
7764 u16 val = 0;
7765 u16 i;
Yuval Mintz24ea8182012-06-20 19:05:23 +00007766 if (byte_cnt > SFP_EEPROM_PAGE_SIZE) {
Joe Perches94f05b02011-08-14 12:16:20 +00007767 DP(NETIF_MSG_LINK,
7768 "Reading from eeprom is limited to 0xf\n");
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007769 return -EINVAL;
7770 }
7771 /* Set the read command byte count */
7772 bnx2x_cl45_write(bp, phy,
7773 MDIO_PMA_DEVAD, MDIO_PMA_REG_SFP_TWO_WIRE_BYTE_CNT,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007774 (byte_cnt | 0xa000));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007775
7776 /* Set the read command address */
7777 bnx2x_cl45_write(bp, phy,
7778 MDIO_PMA_DEVAD, MDIO_PMA_REG_SFP_TWO_WIRE_MEM_ADDR,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007779 addr);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007780
7781 /* Activate read command */
7782 bnx2x_cl45_write(bp, phy,
7783 MDIO_PMA_DEVAD, MDIO_PMA_REG_SFP_TWO_WIRE_CTRL,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007784 0x2c0f);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007785
7786 /* Wait up to 500us for command complete status */
7787 for (i = 0; i < 100; i++) {
7788 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007789 MDIO_PMA_DEVAD,
7790 MDIO_PMA_REG_SFP_TWO_WIRE_CTRL, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007791 if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) ==
7792 MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_COMPLETE)
7793 break;
7794 udelay(5);
7795 }
7796
7797 if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) !=
7798 MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_COMPLETE) {
7799 DP(NETIF_MSG_LINK,
7800 "Got bad status 0x%x when reading from SFP+ EEPROM\n",
7801 (val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK));
7802 return -EINVAL;
7803 }
7804
7805 /* Read the buffer */
7806 for (i = 0; i < byte_cnt; i++) {
7807 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007808 MDIO_PMA_DEVAD,
7809 MDIO_PMA_REG_8726_TWO_WIRE_DATA_BUF + i, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007810 o_buf[i] = (u8)(val & MDIO_PMA_REG_8726_TWO_WIRE_DATA_MASK);
7811 }
7812
7813 for (i = 0; i < 100; i++) {
7814 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007815 MDIO_PMA_DEVAD,
7816 MDIO_PMA_REG_SFP_TWO_WIRE_CTRL, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007817 if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) ==
7818 MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_IDLE)
Joe Perches6f38ad92010-11-14 17:04:31 +00007819 return 0;
Yaniv Rosner503976e2012-11-27 03:46:34 +00007820 usleep_range(1000, 2000);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007821 }
7822 return -EINVAL;
7823}
7824
Yuval Mintz50a29842012-06-16 20:27:14 +00007825static void bnx2x_warpcore_power_module(struct link_params *params,
Yuval Mintz50a29842012-06-16 20:27:14 +00007826 u8 power)
7827{
7828 u32 pin_cfg;
7829 struct bnx2x *bp = params->bp;
7830
7831 pin_cfg = (REG_RD(bp, params->shmem_base +
7832 offsetof(struct shmem_region,
7833 dev_info.port_hw_config[params->port].e3_sfp_ctrl)) &
7834 PORT_HW_CFG_E3_PWR_DIS_MASK) >>
7835 PORT_HW_CFG_E3_PWR_DIS_SHIFT;
7836
7837 if (pin_cfg == PIN_CFG_NA)
7838 return;
7839 DP(NETIF_MSG_LINK, "Setting SFP+ module power to %d using pin cfg %d\n",
7840 power, pin_cfg);
7841 /* Low ==> corresponding SFP+ module is powered
7842 * high ==> the SFP+ module is powered down
7843 */
7844 bnx2x_set_cfg_pin(bp, pin_cfg, power ^ 1);
7845}
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00007846static int bnx2x_warpcore_read_sfp_module_eeprom(struct bnx2x_phy *phy,
7847 struct link_params *params,
7848 u16 addr, u8 byte_cnt,
Yaniv Rosnere82041d2012-10-31 05:46:56 +00007849 u8 *o_buf, u8 is_init)
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00007850{
7851 int rc = 0;
7852 u8 i, j = 0, cnt = 0;
7853 u32 data_array[4];
7854 u16 addr32;
7855 struct bnx2x *bp = params->bp;
Yuval Mintz24ea8182012-06-20 19:05:23 +00007856
7857 if (byte_cnt > SFP_EEPROM_PAGE_SIZE) {
Joe Perches94f05b02011-08-14 12:16:20 +00007858 DP(NETIF_MSG_LINK,
7859 "Reading from eeprom is limited to 16 bytes\n");
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00007860 return -EINVAL;
7861 }
7862
7863 /* 4 byte aligned address */
7864 addr32 = addr & (~0x3);
7865 do {
Yaniv Rosnere82041d2012-10-31 05:46:56 +00007866 if ((!is_init) && (cnt == I2C_WA_PWR_ITER)) {
Yaniv Rosner5a1fbf42012-11-27 03:46:31 +00007867 bnx2x_warpcore_power_module(params, 0);
Yuval Mintz50a29842012-06-16 20:27:14 +00007868 /* Note that 100us are not enough here */
Yaniv Rosnere82041d2012-10-31 05:46:56 +00007869 usleep_range(1000, 2000);
Yaniv Rosner5a1fbf42012-11-27 03:46:31 +00007870 bnx2x_warpcore_power_module(params, 1);
Yuval Mintz50a29842012-06-16 20:27:14 +00007871 }
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00007872 rc = bnx2x_bsc_read(params, phy, 0xa0, addr32, 0, byte_cnt,
7873 data_array);
7874 } while ((rc != 0) && (++cnt < I2C_WA_RETRY_CNT));
7875
7876 if (rc == 0) {
7877 for (i = (addr - addr32); i < byte_cnt + (addr - addr32); i++) {
7878 o_buf[j] = *((u8 *)data_array + i);
7879 j++;
7880 }
7881 }
7882
7883 return rc;
7884}
7885
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00007886static int bnx2x_8727_read_sfp_module_eeprom(struct bnx2x_phy *phy,
7887 struct link_params *params,
7888 u16 addr, u8 byte_cnt, u8 *o_buf)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007889{
7890 struct bnx2x *bp = params->bp;
7891 u16 val, i;
7892
Yuval Mintz24ea8182012-06-20 19:05:23 +00007893 if (byte_cnt > SFP_EEPROM_PAGE_SIZE) {
Joe Perches94f05b02011-08-14 12:16:20 +00007894 DP(NETIF_MSG_LINK,
7895 "Reading from eeprom is limited to 0xf\n");
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007896 return -EINVAL;
7897 }
7898
7899 /* Need to read from 1.8000 to clear it */
7900 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007901 MDIO_PMA_DEVAD,
7902 MDIO_PMA_REG_SFP_TWO_WIRE_CTRL,
7903 &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007904
7905 /* Set the read command byte count */
7906 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007907 MDIO_PMA_DEVAD,
7908 MDIO_PMA_REG_SFP_TWO_WIRE_BYTE_CNT,
7909 ((byte_cnt < 2) ? 2 : byte_cnt));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007910
7911 /* Set the read command address */
7912 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007913 MDIO_PMA_DEVAD,
7914 MDIO_PMA_REG_SFP_TWO_WIRE_MEM_ADDR,
7915 addr);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007916 /* Set the destination address */
7917 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007918 MDIO_PMA_DEVAD,
7919 0x8004,
7920 MDIO_PMA_REG_8727_TWO_WIRE_DATA_BUF);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007921
7922 /* Activate read command */
7923 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007924 MDIO_PMA_DEVAD,
7925 MDIO_PMA_REG_SFP_TWO_WIRE_CTRL,
7926 0x8002);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00007927 /* Wait appropriate time for two-wire command to finish before
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00007928 * polling the status register
7929 */
Yaniv Rosner503976e2012-11-27 03:46:34 +00007930 usleep_range(1000, 2000);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007931
7932 /* Wait up to 500us for command complete status */
7933 for (i = 0; i < 100; i++) {
7934 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007935 MDIO_PMA_DEVAD,
7936 MDIO_PMA_REG_SFP_TWO_WIRE_CTRL, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007937 if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) ==
7938 MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_COMPLETE)
7939 break;
7940 udelay(5);
7941 }
7942
7943 if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) !=
7944 MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_COMPLETE) {
7945 DP(NETIF_MSG_LINK,
7946 "Got bad status 0x%x when reading from SFP+ EEPROM\n",
7947 (val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK));
Yaniv Rosner65a001b2011-01-31 04:22:03 +00007948 return -EFAULT;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007949 }
7950
7951 /* Read the buffer */
7952 for (i = 0; i < byte_cnt; i++) {
7953 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007954 MDIO_PMA_DEVAD,
7955 MDIO_PMA_REG_8727_TWO_WIRE_DATA_BUF + i, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007956 o_buf[i] = (u8)(val & MDIO_PMA_REG_8727_TWO_WIRE_DATA_MASK);
7957 }
7958
7959 for (i = 0; i < 100; i++) {
7960 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00007961 MDIO_PMA_DEVAD,
7962 MDIO_PMA_REG_SFP_TWO_WIRE_CTRL, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007963 if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) ==
7964 MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_IDLE)
Joe Perches6f38ad92010-11-14 17:04:31 +00007965 return 0;
Yaniv Rosner503976e2012-11-27 03:46:34 +00007966 usleep_range(1000, 2000);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007967 }
7968
7969 return -EINVAL;
7970}
7971
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00007972int bnx2x_read_sfp_module_eeprom(struct bnx2x_phy *phy,
7973 struct link_params *params, u16 addr,
7974 u8 byte_cnt, u8 *o_buf)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007975{
Yuval Mintz24ea8182012-06-20 19:05:23 +00007976 int rc = -EOPNOTSUPP;
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00007977 switch (phy->type) {
7978 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
7979 rc = bnx2x_8726_read_sfp_module_eeprom(phy, params, addr,
7980 byte_cnt, o_buf);
7981 break;
7982 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
7983 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8722:
7984 rc = bnx2x_8727_read_sfp_module_eeprom(phy, params, addr,
7985 byte_cnt, o_buf);
7986 break;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00007987 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT:
7988 rc = bnx2x_warpcore_read_sfp_module_eeprom(phy, params, addr,
Yaniv Rosnere82041d2012-10-31 05:46:56 +00007989 byte_cnt, o_buf, 0);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00007990 break;
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00007991 }
7992 return rc;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007993}
7994
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00007995static int bnx2x_get_edc_mode(struct bnx2x_phy *phy,
7996 struct link_params *params,
7997 u16 *edc_mode)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00007998{
7999 struct bnx2x *bp = params->bp;
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00008000 u32 sync_offset = 0, phy_idx, media_types;
Yaniv Rosner52160da2012-11-27 03:46:35 +00008001 u8 gport, val[2], check_limiting_mode = 0;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008002 *edc_mode = EDC_MODE_LIMITING;
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00008003 phy->media_type = ETH_PHY_UNSPECIFIED;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008004 /* First check for copper cable */
8005 if (bnx2x_read_sfp_module_eeprom(phy,
8006 params,
8007 SFP_EEPROM_CON_TYPE_ADDR,
Yuval Mintzdbef8072012-06-20 19:05:22 +00008008 2,
8009 (u8 *)val) != 0) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008010 DP(NETIF_MSG_LINK, "Failed to read from SFP+ module EEPROM\n");
8011 return -EINVAL;
8012 }
8013
Yuval Mintzdbef8072012-06-20 19:05:22 +00008014 switch (val[0]) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008015 case SFP_EEPROM_CON_TYPE_VAL_COPPER:
8016 {
8017 u8 copper_module_type;
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00008018 phy->media_type = ETH_PHY_DA_TWINAX;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00008019 /* Check if its active cable (includes SFP+ module)
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008020 * of passive cable
8021 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008022 if (bnx2x_read_sfp_module_eeprom(phy,
8023 params,
8024 SFP_EEPROM_FC_TX_TECH_ADDR,
8025 1,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00008026 &copper_module_type) != 0) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008027 DP(NETIF_MSG_LINK,
8028 "Failed to read copper-cable-type"
8029 " from SFP+ EEPROM\n");
8030 return -EINVAL;
8031 }
8032
8033 if (copper_module_type &
8034 SFP_EEPROM_FC_TX_TECH_BITMASK_COPPER_ACTIVE) {
8035 DP(NETIF_MSG_LINK, "Active Copper cable detected\n");
8036 check_limiting_mode = 1;
8037 } else if (copper_module_type &
8038 SFP_EEPROM_FC_TX_TECH_BITMASK_COPPER_PASSIVE) {
Joe Perches94f05b02011-08-14 12:16:20 +00008039 DP(NETIF_MSG_LINK,
8040 "Passive Copper cable detected\n");
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008041 *edc_mode =
8042 EDC_MODE_PASSIVE_DAC;
8043 } else {
Joe Perches94f05b02011-08-14 12:16:20 +00008044 DP(NETIF_MSG_LINK,
8045 "Unknown copper-cable-type 0x%x !!!\n",
8046 copper_module_type);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008047 return -EINVAL;
8048 }
8049 break;
8050 }
8051 case SFP_EEPROM_CON_TYPE_VAL_LC:
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008052 check_limiting_mode = 1;
Yuval Mintzdbef8072012-06-20 19:05:22 +00008053 if ((val[1] & (SFP_EEPROM_COMP_CODE_SR_MASK |
8054 SFP_EEPROM_COMP_CODE_LR_MASK |
8055 SFP_EEPROM_COMP_CODE_LRM_MASK)) == 0) {
8056 DP(NETIF_MSG_LINK, "1G Optic module detected\n");
Yaniv Rosner52160da2012-11-27 03:46:35 +00008057 gport = params->port;
Yuval Mintzdbef8072012-06-20 19:05:22 +00008058 phy->media_type = ETH_PHY_SFP_1G_FIBER;
8059 phy->req_line_speed = SPEED_1000;
Yaniv Rosner52160da2012-11-27 03:46:35 +00008060 if (!CHIP_IS_E1x(bp))
8061 gport = BP_PATH(bp) + (params->port << 1);
8062 netdev_err(bp->dev, "Warning: Link speed was forced to 1000Mbps."
8063 " Current SFP module in port %d is not"
8064 " compliant with 10G Ethernet\n",
8065 gport);
Yuval Mintzdbef8072012-06-20 19:05:22 +00008066 } else {
8067 int idx, cfg_idx = 0;
8068 DP(NETIF_MSG_LINK, "10G Optic module detected\n");
8069 for (idx = INT_PHY; idx < MAX_PHYS; idx++) {
8070 if (params->phy[idx].type == phy->type) {
8071 cfg_idx = LINK_CONFIG_IDX(idx);
8072 break;
8073 }
8074 }
8075 phy->media_type = ETH_PHY_SFPP_10G_FIBER;
8076 phy->req_line_speed = params->req_line_speed[cfg_idx];
8077 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008078 break;
8079 default:
8080 DP(NETIF_MSG_LINK, "Unable to determine module type 0x%x !!!\n",
Yuval Mintzdbef8072012-06-20 19:05:22 +00008081 val[0]);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008082 return -EINVAL;
8083 }
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00008084 sync_offset = params->shmem_base +
8085 offsetof(struct shmem_region,
8086 dev_info.port_hw_config[params->port].media_type);
8087 media_types = REG_RD(bp, sync_offset);
8088 /* Update media type for non-PMF sync */
8089 for (phy_idx = INT_PHY; phy_idx < MAX_PHYS; phy_idx++) {
8090 if (&(params->phy[phy_idx]) == phy) {
8091 media_types &= ~(PORT_HW_CFG_MEDIA_TYPE_PHY0_MASK <<
8092 (PORT_HW_CFG_MEDIA_TYPE_PHY1_SHIFT * phy_idx));
8093 media_types |= ((phy->media_type &
8094 PORT_HW_CFG_MEDIA_TYPE_PHY0_MASK) <<
8095 (PORT_HW_CFG_MEDIA_TYPE_PHY1_SHIFT * phy_idx));
8096 break;
8097 }
8098 }
8099 REG_WR(bp, sync_offset, media_types);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008100 if (check_limiting_mode) {
8101 u8 options[SFP_EEPROM_OPTIONS_SIZE];
8102 if (bnx2x_read_sfp_module_eeprom(phy,
8103 params,
8104 SFP_EEPROM_OPTIONS_ADDR,
8105 SFP_EEPROM_OPTIONS_SIZE,
8106 options) != 0) {
Joe Perches94f05b02011-08-14 12:16:20 +00008107 DP(NETIF_MSG_LINK,
8108 "Failed to read Option field from module EEPROM\n");
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008109 return -EINVAL;
8110 }
8111 if ((options[0] & SFP_EEPROM_OPTIONS_LINEAR_RX_OUT_MASK))
8112 *edc_mode = EDC_MODE_LINEAR;
8113 else
8114 *edc_mode = EDC_MODE_LIMITING;
8115 }
8116 DP(NETIF_MSG_LINK, "EDC mode is set to 0x%x\n", *edc_mode);
8117 return 0;
8118}
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00008119/* This function read the relevant field from the module (SFP+), and verify it
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008120 * is compliant with this board
8121 */
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00008122static int bnx2x_verify_sfp_module(struct bnx2x_phy *phy,
8123 struct link_params *params)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008124{
8125 struct bnx2x *bp = params->bp;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008126 u32 val, cmd;
8127 u32 fw_resp, fw_cmd_param;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008128 char vendor_name[SFP_EEPROM_VENDOR_NAME_SIZE+1];
8129 char vendor_pn[SFP_EEPROM_PART_NO_SIZE+1];
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008130 phy->flags &= ~FLAGS_SFP_NOT_APPROVED;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008131 val = REG_RD(bp, params->shmem_base +
8132 offsetof(struct shmem_region, dev_info.
8133 port_feature_config[params->port].config));
8134 if ((val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) ==
8135 PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_NO_ENFORCEMENT) {
8136 DP(NETIF_MSG_LINK, "NOT enforcing module verification\n");
8137 return 0;
8138 }
8139
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008140 if (params->feature_config_flags &
8141 FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY) {
8142 /* Use specific phy request */
8143 cmd = DRV_MSG_CODE_VRFY_SPECIFIC_PHY_OPT_MDL;
8144 } else if (params->feature_config_flags &
8145 FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY) {
8146 /* Use first phy request only in case of non-dual media*/
8147 if (DUAL_MEDIA(params)) {
Joe Perches94f05b02011-08-14 12:16:20 +00008148 DP(NETIF_MSG_LINK,
8149 "FW does not support OPT MDL verification\n");
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008150 return -EINVAL;
8151 }
8152 cmd = DRV_MSG_CODE_VRFY_FIRST_PHY_OPT_MDL;
8153 } else {
8154 /* No support in OPT MDL detection */
Joe Perches94f05b02011-08-14 12:16:20 +00008155 DP(NETIF_MSG_LINK,
8156 "FW does not support OPT MDL verification\n");
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008157 return -EINVAL;
8158 }
Dmitry Kravkov523224a2010-10-06 03:23:26 +00008159
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008160 fw_cmd_param = FW_PARAM_SET(phy->addr, phy->type, phy->mdio_ctrl);
8161 fw_resp = bnx2x_fw_command(bp, cmd, fw_cmd_param);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008162 if (fw_resp == FW_MSG_CODE_VRFY_OPT_MDL_SUCCESS) {
8163 DP(NETIF_MSG_LINK, "Approved module\n");
8164 return 0;
8165 }
8166
Yuval Mintzd2310232012-06-20 19:05:19 +00008167 /* Format the warning message */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008168 if (bnx2x_read_sfp_module_eeprom(phy,
8169 params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008170 SFP_EEPROM_VENDOR_NAME_ADDR,
8171 SFP_EEPROM_VENDOR_NAME_SIZE,
8172 (u8 *)vendor_name))
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008173 vendor_name[0] = '\0';
8174 else
8175 vendor_name[SFP_EEPROM_VENDOR_NAME_SIZE] = '\0';
8176 if (bnx2x_read_sfp_module_eeprom(phy,
8177 params,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008178 SFP_EEPROM_PART_NO_ADDR,
8179 SFP_EEPROM_PART_NO_SIZE,
8180 (u8 *)vendor_pn))
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008181 vendor_pn[0] = '\0';
8182 else
8183 vendor_pn[SFP_EEPROM_PART_NO_SIZE] = '\0';
8184
Yaniv Rosner6d870c32011-01-31 04:22:20 +00008185 netdev_err(bp->dev, "Warning: Unqualified SFP+ module detected,"
8186 " Port %d from %s part number %s\n",
8187 params->port, vendor_name, vendor_pn);
Yaniv Rosner59a2e532012-04-04 01:28:59 +00008188 if ((val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) !=
8189 PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_WARNING_MSG)
8190 phy->flags |= FLAGS_SFP_NOT_APPROVED;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008191 return -EINVAL;
8192}
8193
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00008194static int bnx2x_wait_for_sfp_module_initialized(struct bnx2x_phy *phy,
8195 struct link_params *params)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008196
8197{
8198 u8 val;
Yaniv Rosnere82041d2012-10-31 05:46:56 +00008199 int rc;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008200 struct bnx2x *bp = params->bp;
8201 u16 timeout;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00008202 /* Initialization time after hot-plug may take up to 300ms for
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008203 * some phys type ( e.g. JDSU )
8204 */
8205
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008206 for (timeout = 0; timeout < 60; timeout++) {
Yaniv Rosnere82041d2012-10-31 05:46:56 +00008207 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
8208 rc = bnx2x_warpcore_read_sfp_module_eeprom(phy,
8209 params, 1,
8210 1, &val, 1);
8211 else
8212 rc = bnx2x_read_sfp_module_eeprom(phy, params, 1, 1,
8213 &val);
8214 if (rc == 0) {
Joe Perches94f05b02011-08-14 12:16:20 +00008215 DP(NETIF_MSG_LINK,
8216 "SFP+ module initialization took %d ms\n",
8217 timeout * 5);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008218 return 0;
8219 }
Yuval Mintzd2310232012-06-20 19:05:19 +00008220 usleep_range(5000, 10000);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008221 }
Yaniv Rosnere82041d2012-10-31 05:46:56 +00008222 rc = bnx2x_read_sfp_module_eeprom(phy, params, 1, 1, &val);
8223 return rc;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008224}
8225
8226static void bnx2x_8727_power_module(struct bnx2x *bp,
8227 struct bnx2x_phy *phy,
8228 u8 is_power_up) {
8229 /* Make sure GPIOs are not using for LED mode */
8230 u16 val;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00008231 /* In the GPIO register, bit 4 is use to determine if the GPIOs are
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008232 * operating as INPUT or as OUTPUT. Bit 1 is for input, and 0 for
8233 * output
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008234 * Bits 0-1 determine the GPIOs value for OUTPUT in case bit 4 val is 0
8235 * Bits 8-9 determine the GPIOs value for INPUT in case bit 4 val is 1
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008236 * where the 1st bit is the over-current(only input), and 2nd bit is
8237 * for power( only output )
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008238 *
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008239 * In case of NOC feature is disabled and power is up, set GPIO control
8240 * as input to enable listening of over-current indication
8241 */
8242 if (phy->flags & FLAGS_NOC)
8243 return;
Yaniv Rosner27d02432011-05-31 21:27:48 +00008244 if (is_power_up)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008245 val = (1<<4);
8246 else
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00008247 /* Set GPIO control to OUTPUT, and set the power bit
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008248 * to according to the is_power_up
8249 */
Yaniv Rosner27d02432011-05-31 21:27:48 +00008250 val = (1<<1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008251
8252 bnx2x_cl45_write(bp, phy,
8253 MDIO_PMA_DEVAD,
8254 MDIO_PMA_REG_8727_GPIO_CTRL,
8255 val);
8256}
8257
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00008258static int bnx2x_8726_set_limiting_mode(struct bnx2x *bp,
8259 struct bnx2x_phy *phy,
8260 u16 edc_mode)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008261{
8262 u16 cur_limiting_mode;
8263
8264 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008265 MDIO_PMA_DEVAD,
8266 MDIO_PMA_REG_ROM_VER2,
8267 &cur_limiting_mode);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008268 DP(NETIF_MSG_LINK, "Current Limiting mode is 0x%x\n",
8269 cur_limiting_mode);
8270
8271 if (edc_mode == EDC_MODE_LIMITING) {
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008272 DP(NETIF_MSG_LINK, "Setting LIMITING MODE\n");
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008273 bnx2x_cl45_write(bp, phy,
8274 MDIO_PMA_DEVAD,
8275 MDIO_PMA_REG_ROM_VER2,
8276 EDC_MODE_LIMITING);
8277 } else { /* LRM mode ( default )*/
8278
8279 DP(NETIF_MSG_LINK, "Setting LRM MODE\n");
8280
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00008281 /* Changing to LRM mode takes quite few seconds. So do it only
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008282 * if current mode is limiting (default is LRM)
8283 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008284 if (cur_limiting_mode != EDC_MODE_LIMITING)
8285 return 0;
8286
8287 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008288 MDIO_PMA_DEVAD,
8289 MDIO_PMA_REG_LRM_MODE,
8290 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008291 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008292 MDIO_PMA_DEVAD,
8293 MDIO_PMA_REG_ROM_VER2,
8294 0x128);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008295 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008296 MDIO_PMA_DEVAD,
8297 MDIO_PMA_REG_MISC_CTRL0,
8298 0x4008);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008299 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008300 MDIO_PMA_DEVAD,
8301 MDIO_PMA_REG_LRM_MODE,
8302 0xaaaa);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008303 }
8304 return 0;
8305}
8306
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00008307static int bnx2x_8727_set_limiting_mode(struct bnx2x *bp,
8308 struct bnx2x_phy *phy,
8309 u16 edc_mode)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008310{
8311 u16 phy_identifier;
8312 u16 rom_ver2_val;
8313 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008314 MDIO_PMA_DEVAD,
8315 MDIO_PMA_REG_PHY_IDENTIFIER,
8316 &phy_identifier);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008317
8318 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008319 MDIO_PMA_DEVAD,
8320 MDIO_PMA_REG_PHY_IDENTIFIER,
8321 (phy_identifier & ~(1<<9)));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008322
8323 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008324 MDIO_PMA_DEVAD,
8325 MDIO_PMA_REG_ROM_VER2,
8326 &rom_ver2_val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008327 /* Keep the MSB 8-bits, and set the LSB 8-bits with the edc_mode */
8328 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008329 MDIO_PMA_DEVAD,
8330 MDIO_PMA_REG_ROM_VER2,
8331 (rom_ver2_val & 0xff00) | (edc_mode & 0x00ff));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008332
8333 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008334 MDIO_PMA_DEVAD,
8335 MDIO_PMA_REG_PHY_IDENTIFIER,
8336 (phy_identifier | (1<<9)));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008337
8338 return 0;
8339}
8340
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008341static void bnx2x_8727_specific_func(struct bnx2x_phy *phy,
8342 struct link_params *params,
8343 u32 action)
8344{
8345 struct bnx2x *bp = params->bp;
Yaniv Rosner5c107fd2012-09-13 02:56:19 +00008346 u16 val;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008347 switch (action) {
8348 case DISABLE_TX:
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008349 bnx2x_sfp_set_transmitter(params, phy, 0);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008350 break;
8351 case ENABLE_TX:
8352 if (!(phy->flags & FLAGS_SFP_NOT_APPROVED))
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008353 bnx2x_sfp_set_transmitter(params, phy, 1);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008354 break;
Yaniv Rosner5c107fd2012-09-13 02:56:19 +00008355 case PHY_INIT:
8356 bnx2x_cl45_write(bp, phy,
8357 MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXCTRL,
8358 (1<<2) | (1<<5));
8359 bnx2x_cl45_write(bp, phy,
8360 MDIO_PMA_DEVAD, MDIO_PMA_LASI_TXCTRL,
8361 0);
8362 bnx2x_cl45_write(bp, phy,
8363 MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL, 0x0006);
8364 /* Make MOD_ABS give interrupt on change */
8365 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
8366 MDIO_PMA_REG_8727_PCS_OPT_CTRL,
8367 &val);
8368 val |= (1<<12);
8369 if (phy->flags & FLAGS_NOC)
8370 val |= (3<<5);
8371 /* Set 8727 GPIOs to input to allow reading from the 8727 GPIO0
8372 * status which reflect SFP+ module over-current
8373 */
8374 if (!(phy->flags & FLAGS_NOC))
8375 val &= 0xff8f; /* Reset bits 4-6 */
8376 bnx2x_cl45_write(bp, phy,
8377 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_PCS_OPT_CTRL,
8378 val);
8379
8380 /* Set 2-wire transfer rate of SFP+ module EEPROM
8381 * to 100Khz since some DACs(direct attached cables) do
8382 * not work at 400Khz.
8383 */
8384 bnx2x_cl45_write(bp, phy,
8385 MDIO_PMA_DEVAD,
8386 MDIO_PMA_REG_8727_TWO_WIRE_SLAVE_ADDR,
8387 0xa001);
8388 break;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00008389 default:
8390 DP(NETIF_MSG_LINK, "Function 0x%x not supported by 8727\n",
8391 action);
8392 return;
8393 }
8394}
8395
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008396static void bnx2x_set_e1e2_module_fault_led(struct link_params *params,
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008397 u8 gpio_mode)
8398{
8399 struct bnx2x *bp = params->bp;
8400
8401 u32 fault_led_gpio = REG_RD(bp, params->shmem_base +
8402 offsetof(struct shmem_region,
8403 dev_info.port_hw_config[params->port].sfp_ctrl)) &
8404 PORT_HW_CFG_FAULT_MODULE_LED_MASK;
8405 switch (fault_led_gpio) {
8406 case PORT_HW_CFG_FAULT_MODULE_LED_DISABLED:
8407 return;
8408 case PORT_HW_CFG_FAULT_MODULE_LED_GPIO0:
8409 case PORT_HW_CFG_FAULT_MODULE_LED_GPIO1:
8410 case PORT_HW_CFG_FAULT_MODULE_LED_GPIO2:
8411 case PORT_HW_CFG_FAULT_MODULE_LED_GPIO3:
8412 {
8413 u8 gpio_port = bnx2x_get_gpio_port(params);
8414 u16 gpio_pin = fault_led_gpio -
8415 PORT_HW_CFG_FAULT_MODULE_LED_GPIO0;
8416 DP(NETIF_MSG_LINK, "Set fault module-detected led "
8417 "pin %x port %x mode %x\n",
8418 gpio_pin, gpio_port, gpio_mode);
8419 bnx2x_set_gpio(bp, gpio_pin, gpio_mode, gpio_port);
8420 }
8421 break;
8422 default:
8423 DP(NETIF_MSG_LINK, "Error: Invalid fault led mode 0x%x\n",
8424 fault_led_gpio);
8425 }
8426}
8427
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008428static void bnx2x_set_e3_module_fault_led(struct link_params *params,
8429 u8 gpio_mode)
8430{
8431 u32 pin_cfg;
8432 u8 port = params->port;
8433 struct bnx2x *bp = params->bp;
8434 pin_cfg = (REG_RD(bp, params->shmem_base +
8435 offsetof(struct shmem_region,
8436 dev_info.port_hw_config[port].e3_sfp_ctrl)) &
8437 PORT_HW_CFG_E3_FAULT_MDL_LED_MASK) >>
8438 PORT_HW_CFG_E3_FAULT_MDL_LED_SHIFT;
8439 DP(NETIF_MSG_LINK, "Setting Fault LED to %d using pin cfg %d\n",
8440 gpio_mode, pin_cfg);
8441 bnx2x_set_cfg_pin(bp, pin_cfg, gpio_mode);
8442}
8443
8444static void bnx2x_set_sfp_module_fault_led(struct link_params *params,
8445 u8 gpio_mode)
8446{
8447 struct bnx2x *bp = params->bp;
8448 DP(NETIF_MSG_LINK, "Setting SFP+ module fault LED to %d\n", gpio_mode);
8449 if (CHIP_IS_E3(bp)) {
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00008450 /* Low ==> if SFP+ module is supported otherwise
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008451 * High ==> if SFP+ module is not on the approved vendor list
8452 */
8453 bnx2x_set_e3_module_fault_led(params, gpio_mode);
8454 } else
8455 bnx2x_set_e1e2_module_fault_led(params, gpio_mode);
8456}
8457
Yaniv Rosner985848f2011-07-05 01:06:48 +00008458static void bnx2x_warpcore_hw_reset(struct bnx2x_phy *phy,
8459 struct link_params *params)
8460{
Yaniv Rosnerb76070b2011-11-28 00:49:47 +00008461 struct bnx2x *bp = params->bp;
Yaniv Rosner5a1fbf42012-11-27 03:46:31 +00008462 bnx2x_warpcore_power_module(params, 0);
Yaniv Rosnerb76070b2011-11-28 00:49:47 +00008463 /* Put Warpcore in low power mode */
8464 REG_WR(bp, MISC_REG_WC0_RESET, 0x0c0e);
8465
8466 /* Put LCPLL in low power mode */
8467 REG_WR(bp, MISC_REG_LCPLL_E40_PWRDWN, 1);
8468 REG_WR(bp, MISC_REG_LCPLL_E40_RESETB_ANA, 0);
8469 REG_WR(bp, MISC_REG_LCPLL_E40_RESETB_DIG, 0);
Yaniv Rosner985848f2011-07-05 01:06:48 +00008470}
8471
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00008472static void bnx2x_power_sfp_module(struct link_params *params,
8473 struct bnx2x_phy *phy,
8474 u8 power)
8475{
8476 struct bnx2x *bp = params->bp;
8477 DP(NETIF_MSG_LINK, "Setting SFP+ power to %x\n", power);
8478
8479 switch (phy->type) {
8480 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
8481 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8722:
8482 bnx2x_8727_power_module(params->bp, phy, power);
8483 break;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008484 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT:
Yaniv Rosner5a1fbf42012-11-27 03:46:31 +00008485 bnx2x_warpcore_power_module(params, power);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008486 break;
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00008487 default:
8488 break;
8489 }
8490}
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008491static void bnx2x_warpcore_set_limiting_mode(struct link_params *params,
8492 struct bnx2x_phy *phy,
8493 u16 edc_mode)
8494{
8495 u16 val = 0;
8496 u16 mode = MDIO_WC_REG_UC_INFO_B1_FIRMWARE_MODE_DEFAULT;
8497 struct bnx2x *bp = params->bp;
8498
8499 u8 lane = bnx2x_get_warpcore_lane(phy, params);
8500 /* This is a global register which controls all lanes */
8501 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
8502 MDIO_WC_REG_UC_INFO_B1_FIRMWARE_MODE, &val);
8503 val &= ~(0xf << (lane << 2));
8504
8505 switch (edc_mode) {
8506 case EDC_MODE_LINEAR:
8507 case EDC_MODE_LIMITING:
8508 mode = MDIO_WC_REG_UC_INFO_B1_FIRMWARE_MODE_DEFAULT;
8509 break;
8510 case EDC_MODE_PASSIVE_DAC:
8511 mode = MDIO_WC_REG_UC_INFO_B1_FIRMWARE_MODE_SFP_DAC;
8512 break;
8513 default:
8514 break;
8515 }
8516
8517 val |= (mode << (lane << 2));
8518 bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
8519 MDIO_WC_REG_UC_INFO_B1_FIRMWARE_MODE, val);
8520 /* A must read */
8521 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
8522 MDIO_WC_REG_UC_INFO_B1_FIRMWARE_MODE, &val);
8523
Yaniv Rosner19af03a2011-08-02 22:59:47 +00008524 /* Restart microcode to re-read the new mode */
8525 bnx2x_warpcore_reset_lane(bp, phy, 1);
8526 bnx2x_warpcore_reset_lane(bp, phy, 0);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008527
8528}
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00008529
8530static void bnx2x_set_limiting_mode(struct link_params *params,
8531 struct bnx2x_phy *phy,
8532 u16 edc_mode)
8533{
8534 switch (phy->type) {
8535 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
8536 bnx2x_8726_set_limiting_mode(params->bp, phy, edc_mode);
8537 break;
8538 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
8539 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8722:
8540 bnx2x_8727_set_limiting_mode(params->bp, phy, edc_mode);
8541 break;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008542 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT:
8543 bnx2x_warpcore_set_limiting_mode(params, phy, edc_mode);
8544 break;
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00008545 }
8546}
8547
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00008548int bnx2x_sfp_module_detection(struct bnx2x_phy *phy,
8549 struct link_params *params)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008550{
8551 struct bnx2x *bp = params->bp;
8552 u16 edc_mode;
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00008553 int rc = 0;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008554
8555 u32 val = REG_RD(bp, params->shmem_base +
8556 offsetof(struct shmem_region, dev_info.
8557 port_feature_config[params->port].config));
Yaniv Rosner5a1fbf42012-11-27 03:46:31 +00008558 /* Enabled transmitter by default */
8559 bnx2x_sfp_set_transmitter(params, phy, 1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008560 DP(NETIF_MSG_LINK, "SFP+ module plugged in/out detected on port %d\n",
8561 params->port);
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00008562 /* Power up module */
8563 bnx2x_power_sfp_module(params, phy, 1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008564 if (bnx2x_get_edc_mode(phy, params, &edc_mode) != 0) {
8565 DP(NETIF_MSG_LINK, "Failed to get valid module type\n");
8566 return -EINVAL;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008567 } else if (bnx2x_verify_sfp_module(phy, params) != 0) {
Yuval Mintzd2310232012-06-20 19:05:19 +00008568 /* Check SFP+ module compatibility */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008569 DP(NETIF_MSG_LINK, "Module verification failed!!\n");
8570 rc = -EINVAL;
8571 /* Turn on fault module-detected led */
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008572 bnx2x_set_sfp_module_fault_led(params,
8573 MISC_REGISTERS_GPIO_HIGH);
8574
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00008575 /* Check if need to power down the SFP+ module */
8576 if ((val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) ==
8577 PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_POWER_DOWN) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008578 DP(NETIF_MSG_LINK, "Shutdown SFP+ module!!\n");
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00008579 bnx2x_power_sfp_module(params, phy, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008580 return rc;
8581 }
8582 } else {
8583 /* Turn off fault module-detected led */
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008584 bnx2x_set_sfp_module_fault_led(params, MISC_REGISTERS_GPIO_LOW);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008585 }
8586
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00008587 /* Check and set limiting mode / LRM mode on 8726. On 8727 it
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008588 * is done automatically
8589 */
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00008590 bnx2x_set_limiting_mode(params, phy, edc_mode);
8591
Yaniv Rosner5a1fbf42012-11-27 03:46:31 +00008592 /* Disable transmit for this module if the module is not approved, and
8593 * laser needs to be disabled.
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008594 */
Yaniv Rosner5a1fbf42012-11-27 03:46:31 +00008595 if ((rc) &&
8596 ((val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) ==
8597 PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_DISABLE_TX_LASER))
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008598 bnx2x_sfp_set_transmitter(params, phy, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008599
8600 return rc;
8601}
8602
8603void bnx2x_handle_module_detect_int(struct link_params *params)
8604{
8605 struct bnx2x *bp = params->bp;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008606 struct bnx2x_phy *phy;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008607 u32 gpio_val;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008608 u8 gpio_num, gpio_port;
Yaniv Rosner5a1fbf42012-11-27 03:46:31 +00008609 if (CHIP_IS_E3(bp)) {
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008610 phy = &params->phy[INT_PHY];
Yaniv Rosner5a1fbf42012-11-27 03:46:31 +00008611 /* Always enable TX laser,will be disabled in case of fault */
8612 bnx2x_sfp_set_transmitter(params, phy, 1);
8613 } else {
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008614 phy = &params->phy[EXT_PHY1];
Yaniv Rosner5a1fbf42012-11-27 03:46:31 +00008615 }
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008616 if (bnx2x_get_mod_abs_int_cfg(bp, params->chip_id, params->shmem_base,
8617 params->port, &gpio_num, &gpio_port) ==
8618 -EINVAL) {
8619 DP(NETIF_MSG_LINK, "Failed to get MOD_ABS interrupt config\n");
8620 return;
8621 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008622
8623 /* Set valid module led off */
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008624 bnx2x_set_sfp_module_fault_led(params, MISC_REGISTERS_GPIO_HIGH);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008625
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008626 /* Get current gpio val reflecting module plugged in / out*/
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008627 gpio_val = bnx2x_get_gpio(bp, gpio_num, gpio_port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008628
8629 /* Call the handling function in case module is detected */
8630 if (gpio_val == 0) {
Yaniv Rosner55386fe82012-11-27 03:46:30 +00008631 bnx2x_set_mdio_emac_per_phy(bp, params);
Yuval Mintzdbef8072012-06-20 19:05:22 +00008632 bnx2x_set_aer_mmd(params, phy);
8633
Yaniv Rosnere4d78f12011-05-31 21:25:55 +00008634 bnx2x_power_sfp_module(params, phy, 1);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008635 bnx2x_set_gpio_int(bp, gpio_num,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008636 MISC_REGISTERS_GPIO_INT_OUTPUT_CLR,
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008637 gpio_port);
Yuval Mintzdbef8072012-06-20 19:05:22 +00008638 if (bnx2x_wait_for_sfp_module_initialized(phy, params) == 0) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008639 bnx2x_sfp_module_detection(phy, params);
Yuval Mintzdbef8072012-06-20 19:05:22 +00008640 if (CHIP_IS_E3(bp)) {
8641 u16 rx_tx_in_reset;
8642 /* In case WC is out of reset, reconfigure the
8643 * link speed while taking into account 1G
8644 * module limitation.
8645 */
8646 bnx2x_cl45_read(bp, phy,
8647 MDIO_WC_DEVAD,
8648 MDIO_WC_REG_DIGITAL5_MISC6,
8649 &rx_tx_in_reset);
8650 if (!rx_tx_in_reset) {
8651 bnx2x_warpcore_reset_lane(bp, phy, 1);
8652 bnx2x_warpcore_config_sfi(phy, params);
8653 bnx2x_warpcore_reset_lane(bp, phy, 0);
8654 }
8655 }
8656 } else {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008657 DP(NETIF_MSG_LINK, "SFP+ module is not initialized\n");
Yuval Mintzdbef8072012-06-20 19:05:22 +00008658 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008659 } else {
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008660 bnx2x_set_gpio_int(bp, gpio_num,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008661 MISC_REGISTERS_GPIO_INT_OUTPUT_SET,
Yaniv Rosner3c9ada22011-06-14 01:34:12 +00008662 gpio_port);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00008663 /* Module was plugged out.
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008664 * Disable transmit for this module
8665 */
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00008666 phy->media_type = ETH_PHY_NOT_PRESENT;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008667 }
8668}
8669
8670/******************************************************************/
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00008671/* Used by 8706 and 8727 */
8672/******************************************************************/
8673static void bnx2x_sfp_mask_fault(struct bnx2x *bp,
8674 struct bnx2x_phy *phy,
8675 u16 alarm_status_offset,
8676 u16 alarm_ctrl_offset)
8677{
8678 u16 alarm_status, val;
8679 bnx2x_cl45_read(bp, phy,
8680 MDIO_PMA_DEVAD, alarm_status_offset,
8681 &alarm_status);
8682 bnx2x_cl45_read(bp, phy,
8683 MDIO_PMA_DEVAD, alarm_status_offset,
8684 &alarm_status);
8685 /* Mask or enable the fault event. */
8686 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD, alarm_ctrl_offset, &val);
8687 if (alarm_status & (1<<0))
8688 val &= ~(1<<0);
8689 else
8690 val |= (1<<0);
8691 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, alarm_ctrl_offset, val);
8692}
8693/******************************************************************/
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008694/* common BCM8706/BCM8726 PHY SECTION */
8695/******************************************************************/
8696static u8 bnx2x_8706_8726_read_status(struct bnx2x_phy *phy,
8697 struct link_params *params,
8698 struct link_vars *vars)
8699{
8700 u8 link_up = 0;
8701 u16 val1, val2, rx_sd, pcs_status;
8702 struct bnx2x *bp = params->bp;
8703 DP(NETIF_MSG_LINK, "XGXS 8706/8726\n");
8704 /* Clear RX Alarm*/
8705 bnx2x_cl45_read(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00008706 MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXSTAT, &val2);
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00008707
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00008708 bnx2x_sfp_mask_fault(bp, phy, MDIO_PMA_LASI_TXSTAT,
8709 MDIO_PMA_LASI_TXCTRL);
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00008710
Yuval Mintzd2310232012-06-20 19:05:19 +00008711 /* Clear LASI indication*/
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008712 bnx2x_cl45_read(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00008713 MDIO_PMA_DEVAD, MDIO_PMA_LASI_STAT, &val1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008714 bnx2x_cl45_read(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00008715 MDIO_PMA_DEVAD, MDIO_PMA_LASI_STAT, &val2);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008716 DP(NETIF_MSG_LINK, "8706/8726 LASI status 0x%x--> 0x%x\n", val1, val2);
8717
8718 bnx2x_cl45_read(bp, phy,
8719 MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_SD, &rx_sd);
8720 bnx2x_cl45_read(bp, phy,
8721 MDIO_PCS_DEVAD, MDIO_PCS_REG_STATUS, &pcs_status);
8722 bnx2x_cl45_read(bp, phy,
8723 MDIO_AN_DEVAD, MDIO_AN_REG_LINK_STATUS, &val2);
8724 bnx2x_cl45_read(bp, phy,
8725 MDIO_AN_DEVAD, MDIO_AN_REG_LINK_STATUS, &val2);
8726
8727 DP(NETIF_MSG_LINK, "8706/8726 rx_sd 0x%x pcs_status 0x%x 1Gbps"
8728 " link_status 0x%x\n", rx_sd, pcs_status, val2);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00008729 /* Link is up if both bit 0 of pmd_rx_sd and bit 0 of pcs_status
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008730 * are set, or if the autoneg bit 1 is set
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008731 */
8732 link_up = ((rx_sd & pcs_status & 0x1) || (val2 & (1<<1)));
8733 if (link_up) {
8734 if (val2 & (1<<1))
8735 vars->line_speed = SPEED_1000;
8736 else
8737 vars->line_speed = SPEED_10000;
8738 bnx2x_ext_phy_resolve_fc(phy, params, vars);
Yaniv Rosner791f18c2011-01-18 04:33:42 +00008739 vars->duplex = DUPLEX_FULL;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008740 }
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00008741
8742 /* Capture 10G link fault. Read twice to clear stale value. */
8743 if (vars->line_speed == SPEED_10000) {
8744 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00008745 MDIO_PMA_LASI_TXSTAT, &val1);
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00008746 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00008747 MDIO_PMA_LASI_TXSTAT, &val1);
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00008748 if (val1 & (1<<0))
8749 vars->fault_detected = 1;
8750 }
8751
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008752 return link_up;
8753}
8754
8755/******************************************************************/
8756/* BCM8706 PHY SECTION */
8757/******************************************************************/
8758static u8 bnx2x_8706_config_init(struct bnx2x_phy *phy,
8759 struct link_params *params,
8760 struct link_vars *vars)
8761{
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008762 u32 tx_en_mode;
8763 u16 cnt, val, tmp1;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008764 struct bnx2x *bp = params->bp;
Yaniv Rosner3deb8162011-06-14 01:34:33 +00008765
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008766 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008767 MISC_REGISTERS_GPIO_OUTPUT_HIGH, params->port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008768 /* HW reset */
8769 bnx2x_ext_phy_hw_reset(bp, params->port);
8770 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0xa040);
Yaniv Rosner6d870c32011-01-31 04:22:20 +00008771 bnx2x_wait_reset_complete(bp, phy, params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008772
8773 /* Wait until fw is loaded */
8774 for (cnt = 0; cnt < 100; cnt++) {
8775 bnx2x_cl45_read(bp, phy,
8776 MDIO_PMA_DEVAD, MDIO_PMA_REG_ROM_VER1, &val);
8777 if (val)
8778 break;
Yuval Mintzd2310232012-06-20 19:05:19 +00008779 usleep_range(10000, 20000);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008780 }
8781 DP(NETIF_MSG_LINK, "XGXS 8706 is initialized after %d ms\n", cnt);
8782 if ((params->feature_config_flags &
8783 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED)) {
8784 u8 i;
8785 u16 reg;
8786 for (i = 0; i < 4; i++) {
8787 reg = MDIO_XS_8706_REG_BANK_RX0 +
8788 i*(MDIO_XS_8706_REG_BANK_RX1 -
8789 MDIO_XS_8706_REG_BANK_RX0);
8790 bnx2x_cl45_read(bp, phy, MDIO_XS_DEVAD, reg, &val);
8791 /* Clear first 3 bits of the control */
8792 val &= ~0x7;
8793 /* Set control bits according to configuration */
8794 val |= (phy->rx_preemphasis[i] & 0x7);
8795 DP(NETIF_MSG_LINK, "Setting RX Equalizer to BCM8706"
8796 " reg 0x%x <-- val 0x%x\n", reg, val);
8797 bnx2x_cl45_write(bp, phy, MDIO_XS_DEVAD, reg, val);
8798 }
8799 }
8800 /* Force speed */
8801 if (phy->req_line_speed == SPEED_10000) {
8802 DP(NETIF_MSG_LINK, "XGXS 8706 force 10Gbps\n");
8803
8804 bnx2x_cl45_write(bp, phy,
8805 MDIO_PMA_DEVAD,
8806 MDIO_PMA_REG_DIGITAL_CTRL, 0x400);
8807 bnx2x_cl45_write(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00008808 MDIO_PMA_DEVAD, MDIO_PMA_LASI_TXCTRL,
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00008809 0);
8810 /* Arm LASI for link and Tx fault. */
8811 bnx2x_cl45_write(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00008812 MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL, 3);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008813 } else {
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008814 /* Force 1Gbps using autoneg with 1G advertisement */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008815
8816 /* Allow CL37 through CL73 */
8817 DP(NETIF_MSG_LINK, "XGXS 8706 AutoNeg\n");
8818 bnx2x_cl45_write(bp, phy,
8819 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_CL73, 0x040c);
8820
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008821 /* Enable Full-Duplex advertisement on CL37 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008822 bnx2x_cl45_write(bp, phy,
8823 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LP, 0x0020);
8824 /* Enable CL37 AN */
8825 bnx2x_cl45_write(bp, phy,
8826 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_AN, 0x1000);
8827 /* 1G support */
8828 bnx2x_cl45_write(bp, phy,
8829 MDIO_AN_DEVAD, MDIO_AN_REG_ADV, (1<<5));
8830
8831 /* Enable clause 73 AN */
8832 bnx2x_cl45_write(bp, phy,
8833 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x1200);
8834 bnx2x_cl45_write(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00008835 MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXCTRL,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008836 0x0400);
8837 bnx2x_cl45_write(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00008838 MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008839 0x0004);
8840 }
8841 bnx2x_save_bcm_spirom_ver(bp, phy, params->port);
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008842
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00008843 /* If TX Laser is controlled by GPIO_0, do not let PHY go into low
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00008844 * power mode, if TX Laser is disabled
8845 */
8846
8847 tx_en_mode = REG_RD(bp, params->shmem_base +
8848 offsetof(struct shmem_region,
8849 dev_info.port_hw_config[params->port].sfp_ctrl))
8850 & PORT_HW_CFG_TX_LASER_MASK;
8851
8852 if (tx_en_mode == PORT_HW_CFG_TX_LASER_GPIO0) {
8853 DP(NETIF_MSG_LINK, "Enabling TXONOFF_PWRDN_DIS\n");
8854 bnx2x_cl45_read(bp, phy,
8855 MDIO_PMA_DEVAD, MDIO_PMA_REG_DIGITAL_CTRL, &tmp1);
8856 tmp1 |= 0x1;
8857 bnx2x_cl45_write(bp, phy,
8858 MDIO_PMA_DEVAD, MDIO_PMA_REG_DIGITAL_CTRL, tmp1);
8859 }
8860
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008861 return 0;
8862}
8863
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00008864static int bnx2x_8706_read_status(struct bnx2x_phy *phy,
8865 struct link_params *params,
8866 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008867{
8868 return bnx2x_8706_8726_read_status(phy, params, vars);
8869}
8870
8871/******************************************************************/
8872/* BCM8726 PHY SECTION */
8873/******************************************************************/
8874static void bnx2x_8726_config_loopback(struct bnx2x_phy *phy,
8875 struct link_params *params)
8876{
8877 struct bnx2x *bp = params->bp;
8878 DP(NETIF_MSG_LINK, "PMA/PMD ext_phy_loopback: 8726\n");
8879 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x0001);
8880}
8881
8882static void bnx2x_8726_external_rom_boot(struct bnx2x_phy *phy,
8883 struct link_params *params)
8884{
8885 struct bnx2x *bp = params->bp;
8886 /* Need to wait 100ms after reset */
8887 msleep(100);
8888
8889 /* Micro controller re-boot */
8890 bnx2x_cl45_write(bp, phy,
8891 MDIO_PMA_DEVAD, MDIO_PMA_REG_GEN_CTRL, 0x018B);
8892
8893 /* Set soft reset */
8894 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008895 MDIO_PMA_DEVAD,
8896 MDIO_PMA_REG_GEN_CTRL,
8897 MDIO_PMA_REG_GEN_CTRL_ROM_MICRO_RESET);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008898
8899 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008900 MDIO_PMA_DEVAD,
8901 MDIO_PMA_REG_MISC_CTRL1, 0x0001);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008902
8903 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008904 MDIO_PMA_DEVAD,
8905 MDIO_PMA_REG_GEN_CTRL,
8906 MDIO_PMA_REG_GEN_CTRL_ROM_RESET_INTERNAL_MP);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008907
Yuval Mintzd2310232012-06-20 19:05:19 +00008908 /* Wait for 150ms for microcode load */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008909 msleep(150);
8910
8911 /* Disable serial boot control, tristates pins SS_N, SCK, MOSI, MISO */
8912 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00008913 MDIO_PMA_DEVAD,
8914 MDIO_PMA_REG_MISC_CTRL1, 0x0000);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008915
8916 msleep(200);
8917 bnx2x_save_bcm_spirom_ver(bp, phy, params->port);
8918}
8919
8920static u8 bnx2x_8726_read_status(struct bnx2x_phy *phy,
8921 struct link_params *params,
8922 struct link_vars *vars)
8923{
8924 struct bnx2x *bp = params->bp;
8925 u16 val1;
8926 u8 link_up = bnx2x_8706_8726_read_status(phy, params, vars);
8927 if (link_up) {
8928 bnx2x_cl45_read(bp, phy,
8929 MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER,
8930 &val1);
8931 if (val1 & (1<<15)) {
8932 DP(NETIF_MSG_LINK, "Tx is disabled\n");
8933 link_up = 0;
8934 vars->line_speed = 0;
8935 }
8936 }
8937 return link_up;
8938}
8939
8940
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00008941static int bnx2x_8726_config_init(struct bnx2x_phy *phy,
8942 struct link_params *params,
8943 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008944{
8945 struct bnx2x *bp = params->bp;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008946 DP(NETIF_MSG_LINK, "Initializing BCM8726\n");
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008947
8948 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 1<<15);
Yaniv Rosner6d870c32011-01-31 04:22:20 +00008949 bnx2x_wait_reset_complete(bp, phy, params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008950
8951 bnx2x_8726_external_rom_boot(phy, params);
8952
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00008953 /* Need to call module detected on initialization since the module
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008954 * detection triggered by actual module insertion might occur before
8955 * driver is loaded, and when driver is loaded, it reset all
8956 * registers, including the transmitter
8957 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008958 bnx2x_sfp_module_detection(phy, params);
8959
8960 if (phy->req_line_speed == SPEED_1000) {
8961 DP(NETIF_MSG_LINK, "Setting 1G force\n");
8962 bnx2x_cl45_write(bp, phy,
8963 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x40);
8964 bnx2x_cl45_write(bp, phy,
8965 MDIO_PMA_DEVAD, MDIO_PMA_REG_10G_CTRL2, 0xD);
8966 bnx2x_cl45_write(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00008967 MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL, 0x5);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008968 bnx2x_cl45_write(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00008969 MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXCTRL,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008970 0x400);
8971 } else if ((phy->req_line_speed == SPEED_AUTO_NEG) &&
8972 (phy->speed_cap_mask &
8973 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G) &&
8974 ((phy->speed_cap_mask &
8975 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G) !=
8976 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) {
8977 DP(NETIF_MSG_LINK, "Setting 1G clause37\n");
8978 /* Set Flow control */
8979 bnx2x_ext_phy_set_pause(params, phy, vars);
8980 bnx2x_cl45_write(bp, phy,
8981 MDIO_AN_DEVAD, MDIO_AN_REG_ADV, 0x20);
8982 bnx2x_cl45_write(bp, phy,
8983 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_CL73, 0x040c);
8984 bnx2x_cl45_write(bp, phy,
8985 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LD, 0x0020);
8986 bnx2x_cl45_write(bp, phy,
8987 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_AN, 0x1000);
8988 bnx2x_cl45_write(bp, phy,
8989 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x1200);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00008990 /* Enable RX-ALARM control to receive interrupt for 1G speed
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00008991 * change
8992 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008993 bnx2x_cl45_write(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00008994 MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL, 0x4);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008995 bnx2x_cl45_write(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00008996 MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXCTRL,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00008997 0x400);
8998
8999 } else { /* Default 10G. Set only LASI control */
9000 bnx2x_cl45_write(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009001 MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL, 1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009002 }
9003
9004 /* Set TX PreEmphasis if needed */
9005 if ((params->feature_config_flags &
9006 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED)) {
Joe Perches94f05b02011-08-14 12:16:20 +00009007 DP(NETIF_MSG_LINK,
9008 "Setting TX_CTRL1 0x%x, TX_CTRL2 0x%x\n",
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009009 phy->tx_preemphasis[0],
9010 phy->tx_preemphasis[1]);
9011 bnx2x_cl45_write(bp, phy,
9012 MDIO_PMA_DEVAD,
9013 MDIO_PMA_REG_8726_TX_CTRL1,
9014 phy->tx_preemphasis[0]);
9015
9016 bnx2x_cl45_write(bp, phy,
9017 MDIO_PMA_DEVAD,
9018 MDIO_PMA_REG_8726_TX_CTRL2,
9019 phy->tx_preemphasis[1]);
9020 }
9021
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009022 return 0;
9023
9024}
9025
9026static void bnx2x_8726_link_reset(struct bnx2x_phy *phy,
9027 struct link_params *params)
9028{
9029 struct bnx2x *bp = params->bp;
9030 DP(NETIF_MSG_LINK, "bnx2x_8726_link_reset port %d\n", params->port);
9031 /* Set serial boot control for external load */
9032 bnx2x_cl45_write(bp, phy,
9033 MDIO_PMA_DEVAD,
9034 MDIO_PMA_REG_GEN_CTRL, 0x0001);
9035}
9036
9037/******************************************************************/
9038/* BCM8727 PHY SECTION */
9039/******************************************************************/
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00009040
9041static void bnx2x_8727_set_link_led(struct bnx2x_phy *phy,
9042 struct link_params *params, u8 mode)
9043{
9044 struct bnx2x *bp = params->bp;
9045 u16 led_mode_bitmask = 0;
9046 u16 gpio_pins_bitmask = 0;
9047 u16 val;
9048 /* Only NOC flavor requires to set the LED specifically */
9049 if (!(phy->flags & FLAGS_NOC))
9050 return;
9051 switch (mode) {
9052 case LED_MODE_FRONT_PANEL_OFF:
9053 case LED_MODE_OFF:
9054 led_mode_bitmask = 0;
9055 gpio_pins_bitmask = 0x03;
9056 break;
9057 case LED_MODE_ON:
9058 led_mode_bitmask = 0;
9059 gpio_pins_bitmask = 0x02;
9060 break;
9061 case LED_MODE_OPER:
9062 led_mode_bitmask = 0x60;
9063 gpio_pins_bitmask = 0x11;
9064 break;
9065 }
9066 bnx2x_cl45_read(bp, phy,
9067 MDIO_PMA_DEVAD,
9068 MDIO_PMA_REG_8727_PCS_OPT_CTRL,
9069 &val);
9070 val &= 0xff8f;
9071 val |= led_mode_bitmask;
9072 bnx2x_cl45_write(bp, phy,
9073 MDIO_PMA_DEVAD,
9074 MDIO_PMA_REG_8727_PCS_OPT_CTRL,
9075 val);
9076 bnx2x_cl45_read(bp, phy,
9077 MDIO_PMA_DEVAD,
9078 MDIO_PMA_REG_8727_GPIO_CTRL,
9079 &val);
9080 val &= 0xffe0;
9081 val |= gpio_pins_bitmask;
9082 bnx2x_cl45_write(bp, phy,
9083 MDIO_PMA_DEVAD,
9084 MDIO_PMA_REG_8727_GPIO_CTRL,
9085 val);
9086}
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009087static void bnx2x_8727_hw_reset(struct bnx2x_phy *phy,
9088 struct link_params *params) {
9089 u32 swap_val, swap_override;
9090 u8 port;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00009091 /* The PHY reset is controlled by GPIO 1. Fake the port number
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009092 * to cancel the swap done in set_gpio()
9093 */
9094 struct bnx2x *bp = params->bp;
9095 swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
9096 swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
9097 port = (swap_val && swap_override) ^ 1;
9098 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00009099 MISC_REGISTERS_GPIO_OUTPUT_LOW, port);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +00009100}
9101
Yuval Mintzdbef8072012-06-20 19:05:22 +00009102static void bnx2x_8727_config_speed(struct bnx2x_phy *phy,
9103 struct link_params *params)
9104{
9105 struct bnx2x *bp = params->bp;
9106 u16 tmp1, val;
9107 /* Set option 1G speed */
9108 if ((phy->req_line_speed == SPEED_1000) ||
9109 (phy->media_type == ETH_PHY_SFP_1G_FIBER)) {
9110 DP(NETIF_MSG_LINK, "Setting 1G force\n");
9111 bnx2x_cl45_write(bp, phy,
9112 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x40);
9113 bnx2x_cl45_write(bp, phy,
9114 MDIO_PMA_DEVAD, MDIO_PMA_REG_10G_CTRL2, 0xD);
9115 bnx2x_cl45_read(bp, phy,
9116 MDIO_PMA_DEVAD, MDIO_PMA_REG_10G_CTRL2, &tmp1);
9117 DP(NETIF_MSG_LINK, "1.7 = 0x%x\n", tmp1);
9118 /* Power down the XAUI until link is up in case of dual-media
9119 * and 1G
9120 */
9121 if (DUAL_MEDIA(params)) {
9122 bnx2x_cl45_read(bp, phy,
9123 MDIO_PMA_DEVAD,
9124 MDIO_PMA_REG_8727_PCS_GP, &val);
9125 val |= (3<<10);
9126 bnx2x_cl45_write(bp, phy,
9127 MDIO_PMA_DEVAD,
9128 MDIO_PMA_REG_8727_PCS_GP, val);
9129 }
9130 } else if ((phy->req_line_speed == SPEED_AUTO_NEG) &&
9131 ((phy->speed_cap_mask &
9132 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) &&
9133 ((phy->speed_cap_mask &
9134 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G) !=
9135 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) {
9136
9137 DP(NETIF_MSG_LINK, "Setting 1G clause37\n");
9138 bnx2x_cl45_write(bp, phy,
9139 MDIO_AN_DEVAD, MDIO_AN_REG_8727_MISC_CTRL, 0);
9140 bnx2x_cl45_write(bp, phy,
9141 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_AN, 0x1300);
9142 } else {
9143 /* Since the 8727 has only single reset pin, need to set the 10G
9144 * registers although it is default
9145 */
9146 bnx2x_cl45_write(bp, phy,
9147 MDIO_AN_DEVAD, MDIO_AN_REG_8727_MISC_CTRL,
9148 0x0020);
9149 bnx2x_cl45_write(bp, phy,
9150 MDIO_AN_DEVAD, MDIO_AN_REG_CL37_AN, 0x0100);
9151 bnx2x_cl45_write(bp, phy,
9152 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x2040);
9153 bnx2x_cl45_write(bp, phy,
9154 MDIO_PMA_DEVAD, MDIO_PMA_REG_10G_CTRL2,
9155 0x0008);
9156 }
9157}
9158
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00009159static int bnx2x_8727_config_init(struct bnx2x_phy *phy,
9160 struct link_params *params,
9161 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009162{
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00009163 u32 tx_en_mode;
Yaniv Rosner5c107fd2012-09-13 02:56:19 +00009164 u16 tmp1, mod_abs, tmp2;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009165 struct bnx2x *bp = params->bp;
9166 /* Enable PMD link, MOD_ABS_FLT, and 1G link alarm */
9167
Yaniv Rosner6d870c32011-01-31 04:22:20 +00009168 bnx2x_wait_reset_complete(bp, phy, params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009169
9170 DP(NETIF_MSG_LINK, "Initializing BCM8727\n");
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009171
Yaniv Rosner5c107fd2012-09-13 02:56:19 +00009172 bnx2x_8727_specific_func(phy, params, PHY_INIT);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00009173 /* Initially configure MOD_ABS to interrupt when module is
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00009174 * presence( bit 8)
9175 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009176 bnx2x_cl45_read(bp, phy,
9177 MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER, &mod_abs);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00009178 /* Set EDC off by setting OPTXLOS signal input to low (bit 9).
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00009179 * When the EDC is off it locks onto a reference clock and avoids
9180 * becoming 'lost'
9181 */
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00009182 mod_abs &= ~(1<<8);
9183 if (!(phy->flags & FLAGS_NOC))
9184 mod_abs &= ~(1<<9);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009185 bnx2x_cl45_write(bp, phy,
9186 MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER, mod_abs);
9187
Yaniv Rosner85242ee2011-07-05 01:06:53 +00009188 /* Enable/Disable PHY transmitter output */
9189 bnx2x_set_disable_pmd_transmit(params, phy, 0);
9190
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009191 bnx2x_8727_power_module(bp, phy, 1);
9192
9193 bnx2x_cl45_read(bp, phy,
9194 MDIO_PMA_DEVAD, MDIO_PMA_REG_M8051_MSGOUT_REG, &tmp1);
9195
9196 bnx2x_cl45_read(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009197 MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXSTAT, &tmp1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009198
Yuval Mintzdbef8072012-06-20 19:05:22 +00009199 bnx2x_8727_config_speed(phy, params);
Yaniv Rosner5c107fd2012-09-13 02:56:19 +00009200
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009201
9202 /* Set TX PreEmphasis if needed */
9203 if ((params->feature_config_flags &
9204 FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED)) {
9205 DP(NETIF_MSG_LINK, "Setting TX_CTRL1 0x%x, TX_CTRL2 0x%x\n",
9206 phy->tx_preemphasis[0],
9207 phy->tx_preemphasis[1]);
9208 bnx2x_cl45_write(bp, phy,
9209 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_TX_CTRL1,
9210 phy->tx_preemphasis[0]);
9211
9212 bnx2x_cl45_write(bp, phy,
9213 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_TX_CTRL2,
9214 phy->tx_preemphasis[1]);
9215 }
9216
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00009217 /* If TX Laser is controlled by GPIO_0, do not let PHY go into low
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00009218 * power mode, if TX Laser is disabled
9219 */
9220 tx_en_mode = REG_RD(bp, params->shmem_base +
9221 offsetof(struct shmem_region,
9222 dev_info.port_hw_config[params->port].sfp_ctrl))
9223 & PORT_HW_CFG_TX_LASER_MASK;
9224
9225 if (tx_en_mode == PORT_HW_CFG_TX_LASER_GPIO0) {
9226
9227 DP(NETIF_MSG_LINK, "Enabling TXONOFF_PWRDN_DIS\n");
9228 bnx2x_cl45_read(bp, phy,
9229 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_OPT_CFG_REG, &tmp2);
9230 tmp2 |= 0x1000;
9231 tmp2 &= 0xFFEF;
9232 bnx2x_cl45_write(bp, phy,
9233 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_OPT_CFG_REG, tmp2);
Yaniv Rosner59a2e532012-04-04 01:28:59 +00009234 bnx2x_cl45_read(bp, phy,
9235 MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER,
9236 &tmp2);
9237 bnx2x_cl45_write(bp, phy,
9238 MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER,
9239 (tmp2 & 0x7fff));
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00009240 }
9241
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009242 return 0;
9243}
9244
9245static void bnx2x_8727_handle_mod_abs(struct bnx2x_phy *phy,
9246 struct link_params *params)
9247{
9248 struct bnx2x *bp = params->bp;
9249 u16 mod_abs, rx_alarm_status;
9250 u32 val = REG_RD(bp, params->shmem_base +
9251 offsetof(struct shmem_region, dev_info.
9252 port_feature_config[params->port].
9253 config));
9254 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00009255 MDIO_PMA_DEVAD,
9256 MDIO_PMA_REG_PHY_IDENTIFIER, &mod_abs);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009257 if (mod_abs & (1<<8)) {
9258
9259 /* Module is absent */
Joe Perches94f05b02011-08-14 12:16:20 +00009260 DP(NETIF_MSG_LINK,
9261 "MOD_ABS indication show module is absent\n");
Yaniv Rosner1ac9e422011-05-31 21:26:11 +00009262 phy->media_type = ETH_PHY_NOT_PRESENT;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00009263 /* 1. Set mod_abs to detect next module
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00009264 * presence event
9265 * 2. Set EDC off by setting OPTXLOS signal input to low
9266 * (bit 9).
9267 * When the EDC is off it locks onto a reference clock and
9268 * avoids becoming 'lost'.
9269 */
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00009270 mod_abs &= ~(1<<8);
9271 if (!(phy->flags & FLAGS_NOC))
9272 mod_abs &= ~(1<<9);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009273 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00009274 MDIO_PMA_DEVAD,
9275 MDIO_PMA_REG_PHY_IDENTIFIER, mod_abs);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009276
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00009277 /* Clear RX alarm since it stays up as long as
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00009278 * the mod_abs wasn't changed
9279 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009280 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00009281 MDIO_PMA_DEVAD,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009282 MDIO_PMA_LASI_RXSTAT, &rx_alarm_status);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009283
9284 } else {
9285 /* Module is present */
Joe Perches94f05b02011-08-14 12:16:20 +00009286 DP(NETIF_MSG_LINK,
9287 "MOD_ABS indication show module is present\n");
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00009288 /* First disable transmitter, and if the module is ok, the
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00009289 * module_detection will enable it
9290 * 1. Set mod_abs to detect next module absent event ( bit 8)
9291 * 2. Restore the default polarity of the OPRXLOS signal and
9292 * this signal will then correctly indicate the presence or
9293 * absence of the Rx signal. (bit 9)
9294 */
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +00009295 mod_abs |= (1<<8);
9296 if (!(phy->flags & FLAGS_NOC))
9297 mod_abs |= (1<<9);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009298 bnx2x_cl45_write(bp, phy,
9299 MDIO_PMA_DEVAD,
9300 MDIO_PMA_REG_PHY_IDENTIFIER, mod_abs);
9301
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00009302 /* Clear RX alarm since it stays up as long as the mod_abs
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00009303 * wasn't changed. This is need to be done before calling the
9304 * module detection, otherwise it will clear* the link update
9305 * alarm
9306 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009307 bnx2x_cl45_read(bp, phy,
9308 MDIO_PMA_DEVAD,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009309 MDIO_PMA_LASI_RXSTAT, &rx_alarm_status);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009310
9311
9312 if ((val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) ==
9313 PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_DISABLE_TX_LASER)
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00009314 bnx2x_sfp_set_transmitter(params, phy, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009315
9316 if (bnx2x_wait_for_sfp_module_initialized(phy, params) == 0)
9317 bnx2x_sfp_module_detection(phy, params);
9318 else
9319 DP(NETIF_MSG_LINK, "SFP+ module is not initialized\n");
Yuval Mintzdbef8072012-06-20 19:05:22 +00009320
9321 /* Reconfigure link speed based on module type limitations */
9322 bnx2x_8727_config_speed(phy, params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009323 }
9324
9325 DP(NETIF_MSG_LINK, "8727 RX_ALARM_STATUS 0x%x\n",
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00009326 rx_alarm_status);
9327 /* No need to check link status in case of module plugged in/out */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009328}
9329
9330static u8 bnx2x_8727_read_status(struct bnx2x_phy *phy,
9331 struct link_params *params,
9332 struct link_vars *vars)
9333
9334{
9335 struct bnx2x *bp = params->bp;
Yaniv Rosner27d02432011-05-31 21:27:48 +00009336 u8 link_up = 0, oc_port = params->port;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009337 u16 link_status = 0;
Yaniv Rosnera22f0782010-09-07 11:41:20 +00009338 u16 rx_alarm_status, lasi_ctrl, val1;
9339
9340 /* If PHY is not initialized, do not check link status */
9341 bnx2x_cl45_read(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009342 MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00009343 &lasi_ctrl);
9344 if (!lasi_ctrl)
9345 return 0;
9346
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00009347 /* Check the LASI on Rx */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009348 bnx2x_cl45_read(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009349 MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXSTAT,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009350 &rx_alarm_status);
9351 vars->line_speed = 0;
9352 DP(NETIF_MSG_LINK, "8727 RX_ALARM_STATUS 0x%x\n", rx_alarm_status);
9353
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009354 bnx2x_sfp_mask_fault(bp, phy, MDIO_PMA_LASI_TXSTAT,
9355 MDIO_PMA_LASI_TXCTRL);
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00009356
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009357 bnx2x_cl45_read(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009358 MDIO_PMA_DEVAD, MDIO_PMA_LASI_STAT, &val1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009359
9360 DP(NETIF_MSG_LINK, "8727 LASI status 0x%x\n", val1);
9361
9362 /* Clear MSG-OUT */
9363 bnx2x_cl45_read(bp, phy,
9364 MDIO_PMA_DEVAD, MDIO_PMA_REG_M8051_MSGOUT_REG, &val1);
9365
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00009366 /* If a module is present and there is need to check
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009367 * for over current
9368 */
9369 if (!(phy->flags & FLAGS_NOC) && !(rx_alarm_status & (1<<5))) {
9370 /* Check over-current using 8727 GPIO0 input*/
9371 bnx2x_cl45_read(bp, phy,
9372 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_GPIO_CTRL,
9373 &val1);
9374
9375 if ((val1 & (1<<8)) == 0) {
Yaniv Rosner27d02432011-05-31 21:27:48 +00009376 if (!CHIP_IS_E1x(bp))
9377 oc_port = BP_PATH(bp) + (params->port << 1);
Joe Perches94f05b02011-08-14 12:16:20 +00009378 DP(NETIF_MSG_LINK,
9379 "8727 Power fault has been detected on port %d\n",
9380 oc_port);
Yaniv Rosner2f751a82011-11-28 00:49:52 +00009381 netdev_err(bp->dev, "Error: Power fault on Port %d has "
9382 "been detected and the power to "
9383 "that SFP+ module has been removed "
9384 "to prevent failure of the card. "
9385 "Please remove the SFP+ module and "
9386 "restart the system to clear this "
9387 "error.\n",
Yaniv Rosner27d02432011-05-31 21:27:48 +00009388 oc_port);
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00009389 /* Disable all RX_ALARMs except for mod_abs */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009390 bnx2x_cl45_write(bp, phy,
9391 MDIO_PMA_DEVAD,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009392 MDIO_PMA_LASI_RXCTRL, (1<<5));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009393
9394 bnx2x_cl45_read(bp, phy,
9395 MDIO_PMA_DEVAD,
9396 MDIO_PMA_REG_PHY_IDENTIFIER, &val1);
9397 /* Wait for module_absent_event */
9398 val1 |= (1<<8);
9399 bnx2x_cl45_write(bp, phy,
9400 MDIO_PMA_DEVAD,
9401 MDIO_PMA_REG_PHY_IDENTIFIER, val1);
9402 /* Clear RX alarm */
9403 bnx2x_cl45_read(bp, phy,
9404 MDIO_PMA_DEVAD,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009405 MDIO_PMA_LASI_RXSTAT, &rx_alarm_status);
Yaniv Rosner5a1fbf42012-11-27 03:46:31 +00009406 bnx2x_8727_power_module(params->bp, phy, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009407 return 0;
9408 }
9409 } /* Over current check */
9410
9411 /* When module absent bit is set, check module */
9412 if (rx_alarm_status & (1<<5)) {
9413 bnx2x_8727_handle_mod_abs(phy, params);
9414 /* Enable all mod_abs and link detection bits */
9415 bnx2x_cl45_write(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009416 MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXCTRL,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009417 ((1<<5) | (1<<2)));
9418 }
Yaniv Rosner59a2e532012-04-04 01:28:59 +00009419
9420 if (!(phy->flags & FLAGS_SFP_NOT_APPROVED)) {
9421 DP(NETIF_MSG_LINK, "Enabling 8727 TX laser\n");
9422 bnx2x_sfp_set_transmitter(params, phy, 1);
9423 } else {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009424 DP(NETIF_MSG_LINK, "Tx is disabled\n");
9425 return 0;
9426 }
9427
9428 bnx2x_cl45_read(bp, phy,
9429 MDIO_PMA_DEVAD,
9430 MDIO_PMA_REG_8073_SPEED_LINK_STATUS, &link_status);
9431
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00009432 /* Bits 0..2 --> speed detected,
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00009433 * Bits 13..15--> link is down
9434 */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009435 if ((link_status & (1<<2)) && (!(link_status & (1<<15)))) {
9436 link_up = 1;
9437 vars->line_speed = SPEED_10000;
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +00009438 DP(NETIF_MSG_LINK, "port %x: External link up in 10G\n",
9439 params->port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009440 } else if ((link_status & (1<<0)) && (!(link_status & (1<<13)))) {
9441 link_up = 1;
9442 vars->line_speed = SPEED_1000;
9443 DP(NETIF_MSG_LINK, "port %x: External link up in 1G\n",
9444 params->port);
9445 } else {
9446 link_up = 0;
9447 DP(NETIF_MSG_LINK, "port %x: External link is down\n",
9448 params->port);
9449 }
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00009450
9451 /* Capture 10G link fault. */
9452 if (vars->line_speed == SPEED_10000) {
9453 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009454 MDIO_PMA_LASI_TXSTAT, &val1);
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00009455
9456 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009457 MDIO_PMA_LASI_TXSTAT, &val1);
Yaniv Rosnerc688fe22011-05-31 21:27:06 +00009458
9459 if (val1 & (1<<0)) {
9460 vars->fault_detected = 1;
9461 }
9462 }
9463
Yaniv Rosner791f18c2011-01-18 04:33:42 +00009464 if (link_up) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009465 bnx2x_ext_phy_resolve_fc(phy, params, vars);
Yaniv Rosner791f18c2011-01-18 04:33:42 +00009466 vars->duplex = DUPLEX_FULL;
9467 DP(NETIF_MSG_LINK, "duplex = 0x%x\n", vars->duplex);
9468 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +00009469
9470 if ((DUAL_MEDIA(params)) &&
9471 (phy->req_line_speed == SPEED_1000)) {
9472 bnx2x_cl45_read(bp, phy,
9473 MDIO_PMA_DEVAD,
9474 MDIO_PMA_REG_8727_PCS_GP, &val1);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +00009475 /* In case of dual-media board and 1G, power up the XAUI side,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00009476 * otherwise power it down. For 10G it is done automatically
9477 */
9478 if (link_up)
9479 val1 &= ~(3<<10);
9480 else
9481 val1 |= (3<<10);
9482 bnx2x_cl45_write(bp, phy,
9483 MDIO_PMA_DEVAD,
9484 MDIO_PMA_REG_8727_PCS_GP, val1);
9485 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009486 return link_up;
9487}
9488
9489static void bnx2x_8727_link_reset(struct bnx2x_phy *phy,
9490 struct link_params *params)
9491{
9492 struct bnx2x *bp = params->bp;
Yaniv Rosner85242ee2011-07-05 01:06:53 +00009493
9494 /* Enable/Disable PHY transmitter output */
9495 bnx2x_set_disable_pmd_transmit(params, phy, 1);
9496
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009497 /* Disable Transmitter */
Yaniv Rosnera8db5b42011-01-31 04:22:28 +00009498 bnx2x_sfp_set_transmitter(params, phy, 0);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00009499 /* Clear LASI */
Yaniv Rosner60d2fe02011-06-14 01:34:38 +00009500 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL, 0);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00009501
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009502}
9503
9504/******************************************************************/
9505/* BCM8481/BCM84823/BCM84833 PHY SECTION */
9506/******************************************************************/
9507static void bnx2x_save_848xx_spirom_version(struct bnx2x_phy *phy,
Yaniv Rosner11b2ec62012-01-17 02:33:25 +00009508 struct bnx2x *bp,
9509 u8 port)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009510{
Yaniv Rosner503976e2012-11-27 03:46:34 +00009511 u16 val, fw_ver2, cnt, i;
9512 static struct bnx2x_reg_set reg_set[] = {
9513 {MDIO_PMA_DEVAD, 0xA819, 0x0014},
9514 {MDIO_PMA_DEVAD, 0xA81A, 0xc200},
9515 {MDIO_PMA_DEVAD, 0xA81B, 0x0000},
9516 {MDIO_PMA_DEVAD, 0xA81C, 0x0300},
9517 {MDIO_PMA_DEVAD, 0xA817, 0x0009}
9518 };
9519 u16 fw_ver1;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009520
Yaniv Rosner0f6bb032012-11-27 03:46:32 +00009521 if ((phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833) ||
9522 (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84834)) {
Yaniv Rosner11b2ec62012-01-17 02:33:25 +00009523 bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD, 0x400f, &fw_ver1);
Yaniv Rosner8267bbb02012-04-04 01:29:00 +00009524 bnx2x_save_spirom_version(bp, port, fw_ver1 & 0xfff,
Yaniv Rosner11b2ec62012-01-17 02:33:25 +00009525 phy->ver_addr);
9526 } else {
9527 /* For 32-bit registers in 848xx, access via MDIO2ARM i/f. */
9528 /* (1) set reg 0xc200_0014(SPI_BRIDGE_CTRL_2) to 0x03000000 */
Sasha Levinb5a05552012-12-20 09:11:24 +00009529 for (i = 0; i < ARRAY_SIZE(reg_set);
Yaniv Rosner503976e2012-11-27 03:46:34 +00009530 i++)
9531 bnx2x_cl45_write(bp, phy, reg_set[i].devad,
9532 reg_set[i].reg, reg_set[i].val);
Yaniv Rosnerc87bca12011-01-31 04:22:41 +00009533
Yaniv Rosner11b2ec62012-01-17 02:33:25 +00009534 for (cnt = 0; cnt < 100; cnt++) {
9535 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD, 0xA818, &val);
9536 if (val & 1)
9537 break;
9538 udelay(5);
9539 }
9540 if (cnt == 100) {
9541 DP(NETIF_MSG_LINK, "Unable to read 848xx "
9542 "phy fw version(1)\n");
9543 bnx2x_save_spirom_version(bp, port, 0,
9544 phy->ver_addr);
9545 return;
9546 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009547
Yaniv Rosner11b2ec62012-01-17 02:33:25 +00009548
9549 /* 2) read register 0xc200_0000 (SPI_FW_STATUS) */
9550 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA819, 0x0000);
9551 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA81A, 0xc200);
9552 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA817, 0x000A);
9553 for (cnt = 0; cnt < 100; cnt++) {
9554 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD, 0xA818, &val);
9555 if (val & 1)
9556 break;
9557 udelay(5);
9558 }
9559 if (cnt == 100) {
9560 DP(NETIF_MSG_LINK, "Unable to read 848xx phy fw "
9561 "version(2)\n");
9562 bnx2x_save_spirom_version(bp, port, 0,
9563 phy->ver_addr);
9564 return;
9565 }
9566
9567 /* lower 16 bits of the register SPI_FW_STATUS */
9568 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD, 0xA81B, &fw_ver1);
9569 /* upper 16 bits of register SPI_FW_STATUS */
9570 bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD, 0xA81C, &fw_ver2);
9571
9572 bnx2x_save_spirom_version(bp, port, (fw_ver2<<16) | fw_ver1,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009573 phy->ver_addr);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009574 }
9575
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009576}
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009577static void bnx2x_848xx_set_led(struct bnx2x *bp,
9578 struct bnx2x_phy *phy)
9579{
Yaniv Rosner503976e2012-11-27 03:46:34 +00009580 u16 val, offset, i;
9581 static struct bnx2x_reg_set reg_set[] = {
9582 {MDIO_PMA_DEVAD, MDIO_PMA_REG_8481_LED1_MASK, 0x0080},
9583 {MDIO_PMA_DEVAD, MDIO_PMA_REG_8481_LED2_MASK, 0x0018},
9584 {MDIO_PMA_DEVAD, MDIO_PMA_REG_8481_LED3_MASK, 0x0006},
9585 {MDIO_PMA_DEVAD, MDIO_PMA_REG_8481_LED3_BLINK, 0x0000},
9586 {MDIO_PMA_DEVAD, MDIO_PMA_REG_84823_CTL_SLOW_CLK_CNT_HIGH,
9587 MDIO_PMA_REG_84823_BLINK_RATE_VAL_15P9HZ},
9588 {MDIO_AN_DEVAD, 0xFFFB, 0xFFFD}
9589 };
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009590 /* PHYC_CTL_LED_CTL */
9591 bnx2x_cl45_read(bp, phy,
9592 MDIO_PMA_DEVAD,
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009593 MDIO_PMA_REG_8481_LINK_SIGNAL, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009594 val &= 0xFE00;
9595 val |= 0x0092;
9596
9597 bnx2x_cl45_write(bp, phy,
9598 MDIO_PMA_DEVAD,
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009599 MDIO_PMA_REG_8481_LINK_SIGNAL, val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009600
Sasha Levinb5a05552012-12-20 09:11:24 +00009601 for (i = 0; i < ARRAY_SIZE(reg_set); i++)
Yaniv Rosner503976e2012-11-27 03:46:34 +00009602 bnx2x_cl45_write(bp, phy, reg_set[i].devad, reg_set[i].reg,
9603 reg_set[i].val);
Yaniv Rosner521683d2011-11-28 00:49:48 +00009604
Yaniv Rosner0f6bb032012-11-27 03:46:32 +00009605 if ((phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833) ||
9606 (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84834))
Yaniv Rosner521683d2011-11-28 00:49:48 +00009607 offset = MDIO_PMA_REG_84833_CTL_LED_CTL_1;
9608 else
9609 offset = MDIO_PMA_REG_84823_CTL_LED_CTL_1;
9610
Yaniv Rosner503976e2012-11-27 03:46:34 +00009611 /* stretch_en for LED3*/
9612 bnx2x_cl45_read_or_write(bp, phy,
9613 MDIO_PMA_DEVAD, offset,
9614 MDIO_PMA_REG_84823_LED3_STRETCH_EN);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009615}
9616
Yaniv Rosner5c107fd2012-09-13 02:56:19 +00009617static void bnx2x_848xx_specific_func(struct bnx2x_phy *phy,
9618 struct link_params *params,
9619 u32 action)
9620{
9621 struct bnx2x *bp = params->bp;
9622 switch (action) {
9623 case PHY_INIT:
Yaniv Rosner0f6bb032012-11-27 03:46:32 +00009624 if ((phy->type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833) &&
9625 (phy->type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84834)) {
Yaniv Rosner5c107fd2012-09-13 02:56:19 +00009626 /* Save spirom version */
9627 bnx2x_save_848xx_spirom_version(phy, bp, params->port);
9628 }
9629 /* This phy uses the NIG latch mechanism since link indication
9630 * arrives through its LED4 and not via its LASI signal, so we
9631 * get steady signal instead of clear on read
9632 */
9633 bnx2x_bits_en(bp, NIG_REG_LATCH_BC_0 + params->port*4,
9634 1 << NIG_LATCH_BC_ENABLE_MI_INT);
9635
9636 bnx2x_848xx_set_led(bp, phy);
9637 break;
9638 }
9639}
9640
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00009641static int bnx2x_848xx_cmn_config_init(struct bnx2x_phy *phy,
9642 struct link_params *params,
9643 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009644{
9645 struct bnx2x *bp = params->bp;
Yaniv Rosner503976e2012-11-27 03:46:34 +00009646 u16 autoneg_val, an_1000_val, an_10_100_val;
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009647
Yaniv Rosner5c107fd2012-09-13 02:56:19 +00009648 bnx2x_848xx_specific_func(phy, params, PHY_INIT);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009649 bnx2x_cl45_write(bp, phy,
9650 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x0000);
9651
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009652 /* set 1000 speed advertisement */
9653 bnx2x_cl45_read(bp, phy,
9654 MDIO_AN_DEVAD, MDIO_AN_REG_8481_1000T_CTRL,
9655 &an_1000_val);
9656
9657 bnx2x_ext_phy_set_pause(params, phy, vars);
9658 bnx2x_cl45_read(bp, phy,
9659 MDIO_AN_DEVAD,
9660 MDIO_AN_REG_8481_LEGACY_AN_ADV,
9661 &an_10_100_val);
9662 bnx2x_cl45_read(bp, phy,
9663 MDIO_AN_DEVAD, MDIO_AN_REG_8481_LEGACY_MII_CTRL,
9664 &autoneg_val);
9665 /* Disable forced speed */
9666 autoneg_val &= ~((1<<6) | (1<<8) | (1<<9) | (1<<12) | (1<<13));
9667 an_10_100_val &= ~((1<<5) | (1<<6) | (1<<7) | (1<<8));
9668
9669 if (((phy->req_line_speed == SPEED_AUTO_NEG) &&
9670 (phy->speed_cap_mask &
9671 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) ||
9672 (phy->req_line_speed == SPEED_1000)) {
9673 an_1000_val |= (1<<8);
9674 autoneg_val |= (1<<9 | 1<<12);
9675 if (phy->req_duplex == DUPLEX_FULL)
9676 an_1000_val |= (1<<9);
9677 DP(NETIF_MSG_LINK, "Advertising 1G\n");
9678 } else
9679 an_1000_val &= ~((1<<8) | (1<<9));
9680
9681 bnx2x_cl45_write(bp, phy,
9682 MDIO_AN_DEVAD, MDIO_AN_REG_8481_1000T_CTRL,
9683 an_1000_val);
9684
Yaniv Rosner0520e632011-07-05 01:06:59 +00009685 /* set 100 speed advertisement */
Yaniv Rosner75318322012-01-17 02:33:27 +00009686 if ((phy->req_line_speed == SPEED_AUTO_NEG) &&
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009687 (phy->speed_cap_mask &
Yaniv Rosner0520e632011-07-05 01:06:59 +00009688 (PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL |
Yaniv Rosner75318322012-01-17 02:33:27 +00009689 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009690 an_10_100_val |= (1<<7);
9691 /* Enable autoneg and restart autoneg for legacy speeds */
9692 autoneg_val |= (1<<9 | 1<<12);
9693
9694 if (phy->req_duplex == DUPLEX_FULL)
9695 an_10_100_val |= (1<<8);
9696 DP(NETIF_MSG_LINK, "Advertising 100M\n");
9697 }
9698 /* set 10 speed advertisement */
9699 if (((phy->req_line_speed == SPEED_AUTO_NEG) &&
Yaniv Rosner0520e632011-07-05 01:06:59 +00009700 (phy->speed_cap_mask &
9701 (PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL |
9702 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF)) &&
9703 (phy->supported &
9704 (SUPPORTED_10baseT_Half |
9705 SUPPORTED_10baseT_Full)))) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009706 an_10_100_val |= (1<<5);
9707 autoneg_val |= (1<<9 | 1<<12);
9708 if (phy->req_duplex == DUPLEX_FULL)
9709 an_10_100_val |= (1<<6);
9710 DP(NETIF_MSG_LINK, "Advertising 10M\n");
9711 }
9712
9713 /* Only 10/100 are allowed to work in FORCE mode */
Yaniv Rosner0520e632011-07-05 01:06:59 +00009714 if ((phy->req_line_speed == SPEED_100) &&
9715 (phy->supported &
9716 (SUPPORTED_100baseT_Half |
9717 SUPPORTED_100baseT_Full))) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009718 autoneg_val |= (1<<13);
9719 /* Enabled AUTO-MDIX when autoneg is disabled */
9720 bnx2x_cl45_write(bp, phy,
9721 MDIO_AN_DEVAD, MDIO_AN_REG_8481_AUX_CTRL,
9722 (1<<15 | 1<<9 | 7<<0));
Yaniv Rosner521683d2011-11-28 00:49:48 +00009723 /* The PHY needs this set even for forced link. */
9724 an_10_100_val |= (1<<8) | (1<<7);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009725 DP(NETIF_MSG_LINK, "Setting 100M force\n");
9726 }
Yaniv Rosner0520e632011-07-05 01:06:59 +00009727 if ((phy->req_line_speed == SPEED_10) &&
9728 (phy->supported &
9729 (SUPPORTED_10baseT_Half |
9730 SUPPORTED_10baseT_Full))) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009731 /* Enabled AUTO-MDIX when autoneg is disabled */
9732 bnx2x_cl45_write(bp, phy,
9733 MDIO_AN_DEVAD, MDIO_AN_REG_8481_AUX_CTRL,
9734 (1<<15 | 1<<9 | 7<<0));
9735 DP(NETIF_MSG_LINK, "Setting 10M force\n");
9736 }
9737
9738 bnx2x_cl45_write(bp, phy,
9739 MDIO_AN_DEVAD, MDIO_AN_REG_8481_LEGACY_AN_ADV,
9740 an_10_100_val);
9741
9742 if (phy->req_duplex == DUPLEX_FULL)
9743 autoneg_val |= (1<<8);
9744
Yaniv Rosner0f6bb032012-11-27 03:46:32 +00009745 /* Always write this if this is not 84833/4.
9746 * For 84833/4, write it only when it's a forced speed.
Yaniv Rosnerfd38f73e2011-08-02 22:59:53 +00009747 */
Yaniv Rosner0f6bb032012-11-27 03:46:32 +00009748 if (((phy->type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833) &&
9749 (phy->type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84834)) ||
Yaniv Rosner503976e2012-11-27 03:46:34 +00009750 ((autoneg_val & (1<<12)) == 0))
Yaniv Rosnerfd38f73e2011-08-02 22:59:53 +00009751 bnx2x_cl45_write(bp, phy,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009752 MDIO_AN_DEVAD,
9753 MDIO_AN_REG_8481_LEGACY_MII_CTRL, autoneg_val);
9754
9755 if (((phy->req_line_speed == SPEED_AUTO_NEG) &&
9756 (phy->speed_cap_mask &
9757 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) ||
9758 (phy->req_line_speed == SPEED_10000)) {
Yaniv Rosner9045f6b2011-05-31 21:28:27 +00009759 DP(NETIF_MSG_LINK, "Advertising 10G\n");
9760 /* Restart autoneg for 10G*/
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009761
Yaniv Rosner503976e2012-11-27 03:46:34 +00009762 bnx2x_cl45_read_or_write(
9763 bp, phy,
9764 MDIO_AN_DEVAD,
9765 MDIO_AN_REG_8481_10GBASE_T_AN_CTRL,
9766 0x1000);
Yaniv Rosner521683d2011-11-28 00:49:48 +00009767 bnx2x_cl45_write(bp, phy,
9768 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL,
9769 0x3200);
Yaniv Rosnerfd38f73e2011-08-02 22:59:53 +00009770 } else
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009771 bnx2x_cl45_write(bp, phy,
9772 MDIO_AN_DEVAD,
9773 MDIO_AN_REG_8481_10GBASE_T_AN_CTRL,
9774 1);
Yaniv Rosnerfd38f73e2011-08-02 22:59:53 +00009775
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009776 return 0;
9777}
9778
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00009779static int bnx2x_8481_config_init(struct bnx2x_phy *phy,
9780 struct link_params *params,
9781 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009782{
9783 struct bnx2x *bp = params->bp;
9784 /* Restore normal power mode*/
9785 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +00009786 MISC_REGISTERS_GPIO_OUTPUT_HIGH, params->port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009787
9788 /* HW reset */
9789 bnx2x_ext_phy_hw_reset(bp, params->port);
Yaniv Rosner6d870c32011-01-31 04:22:20 +00009790 bnx2x_wait_reset_complete(bp, phy, params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009791
9792 bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 1<<15);
9793 return bnx2x_848xx_cmn_config_init(phy, params, vars);
9794}
9795
Yaniv Rosner521683d2011-11-28 00:49:48 +00009796#define PHY84833_CMDHDLR_WAIT 300
9797#define PHY84833_CMDHDLR_MAX_ARGS 5
9798static int bnx2x_84833_cmd_hdlr(struct bnx2x_phy *phy,
Yaniv Rosner503976e2012-11-27 03:46:34 +00009799 struct link_params *params, u16 fw_cmd,
9800 u16 cmd_args[], int argc)
Yaniv Rosner521683d2011-11-28 00:49:48 +00009801{
Yuval Mintzc8c60d82012-06-06 17:13:07 +00009802 int idx;
Yaniv Rosner521683d2011-11-28 00:49:48 +00009803 u16 val;
9804 struct bnx2x *bp = params->bp;
9805 /* Write CMD_OPEN_OVERRIDE to STATUS reg */
9806 bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
9807 MDIO_84833_CMD_HDLR_STATUS,
9808 PHY84833_STATUS_CMD_OPEN_OVERRIDE);
9809 for (idx = 0; idx < PHY84833_CMDHDLR_WAIT; idx++) {
9810 bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD,
9811 MDIO_84833_CMD_HDLR_STATUS, &val);
9812 if (val == PHY84833_STATUS_CMD_OPEN_FOR_CMDS)
9813 break;
Yaniv Rosner503976e2012-11-27 03:46:34 +00009814 usleep_range(1000, 2000);
Yaniv Rosner521683d2011-11-28 00:49:48 +00009815 }
9816 if (idx >= PHY84833_CMDHDLR_WAIT) {
9817 DP(NETIF_MSG_LINK, "FW cmd: FW not ready.\n");
9818 return -EINVAL;
9819 }
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009820
Yaniv Rosner521683d2011-11-28 00:49:48 +00009821 /* Prepare argument(s) and issue command */
Yuval Mintzc8c60d82012-06-06 17:13:07 +00009822 for (idx = 0; idx < argc; idx++) {
Yaniv Rosner521683d2011-11-28 00:49:48 +00009823 bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
9824 MDIO_84833_CMD_HDLR_DATA1 + idx,
9825 cmd_args[idx]);
9826 }
9827 bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
9828 MDIO_84833_CMD_HDLR_COMMAND, fw_cmd);
9829 for (idx = 0; idx < PHY84833_CMDHDLR_WAIT; idx++) {
9830 bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD,
9831 MDIO_84833_CMD_HDLR_STATUS, &val);
9832 if ((val == PHY84833_STATUS_CMD_COMPLETE_PASS) ||
9833 (val == PHY84833_STATUS_CMD_COMPLETE_ERROR))
9834 break;
Yaniv Rosner503976e2012-11-27 03:46:34 +00009835 usleep_range(1000, 2000);
Yaniv Rosner521683d2011-11-28 00:49:48 +00009836 }
9837 if ((idx >= PHY84833_CMDHDLR_WAIT) ||
9838 (val == PHY84833_STATUS_CMD_COMPLETE_ERROR)) {
9839 DP(NETIF_MSG_LINK, "FW cmd failed.\n");
9840 return -EINVAL;
9841 }
9842 /* Gather returning data */
Yuval Mintzc8c60d82012-06-06 17:13:07 +00009843 for (idx = 0; idx < argc; idx++) {
Yaniv Rosner521683d2011-11-28 00:49:48 +00009844 bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD,
9845 MDIO_84833_CMD_HDLR_DATA1 + idx,
9846 &cmd_args[idx]);
9847 }
9848 bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
9849 MDIO_84833_CMD_HDLR_STATUS,
9850 PHY84833_STATUS_CMD_CLEAR_COMPLETE);
9851 return 0;
9852}
9853
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009854static int bnx2x_84833_pair_swap_cfg(struct bnx2x_phy *phy,
9855 struct link_params *params,
9856 struct link_vars *vars)
9857{
Yaniv Rosner0520e632011-07-05 01:06:59 +00009858 u32 pair_swap;
Yaniv Rosner521683d2011-11-28 00:49:48 +00009859 u16 data[PHY84833_CMDHDLR_MAX_ARGS];
9860 int status;
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009861 struct bnx2x *bp = params->bp;
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009862
Yaniv Rosner0520e632011-07-05 01:06:59 +00009863 /* Check for configuration. */
9864 pair_swap = REG_RD(bp, params->shmem_base +
9865 offsetof(struct shmem_region,
9866 dev_info.port_hw_config[params->port].xgbt_phy_cfg)) &
9867 PORT_HW_CFG_RJ45_PAIR_SWAP_MASK;
9868
9869 if (pair_swap == 0)
9870 return 0;
9871
Yaniv Rosner521683d2011-11-28 00:49:48 +00009872 /* Only the second argument is used for this command */
9873 data[1] = (u16)pair_swap;
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009874
Yaniv Rosner521683d2011-11-28 00:49:48 +00009875 status = bnx2x_84833_cmd_hdlr(phy, params,
Yuval Mintzc8c60d82012-06-06 17:13:07 +00009876 PHY84833_CMD_SET_PAIR_SWAP, data, PHY84833_CMDHDLR_MAX_ARGS);
Yaniv Rosner521683d2011-11-28 00:49:48 +00009877 if (status == 0)
9878 DP(NETIF_MSG_LINK, "Pairswap OK, val=0x%x\n", data[1]);
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009879
Yaniv Rosner521683d2011-11-28 00:49:48 +00009880 return status;
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +00009881}
9882
Yaniv Rosner985848f2011-07-05 01:06:48 +00009883static u8 bnx2x_84833_get_reset_gpios(struct bnx2x *bp,
9884 u32 shmem_base_path[],
9885 u32 chip_id)
Yaniv Rosner0d40f0d2011-06-14 01:34:27 +00009886{
9887 u32 reset_pin[2];
9888 u32 idx;
9889 u8 reset_gpios;
9890 if (CHIP_IS_E3(bp)) {
9891 /* Assume that these will be GPIOs, not EPIOs. */
9892 for (idx = 0; idx < 2; idx++) {
9893 /* Map config param to register bit. */
9894 reset_pin[idx] = REG_RD(bp, shmem_base_path[idx] +
9895 offsetof(struct shmem_region,
9896 dev_info.port_hw_config[0].e3_cmn_pin_cfg));
9897 reset_pin[idx] = (reset_pin[idx] &
9898 PORT_HW_CFG_E3_PHY_RESET_MASK) >>
9899 PORT_HW_CFG_E3_PHY_RESET_SHIFT;
9900 reset_pin[idx] -= PIN_CFG_GPIO0_P0;
9901 reset_pin[idx] = (1 << reset_pin[idx]);
9902 }
9903 reset_gpios = (u8)(reset_pin[0] | reset_pin[1]);
9904 } else {
9905 /* E2, look from diff place of shmem. */
9906 for (idx = 0; idx < 2; idx++) {
9907 reset_pin[idx] = REG_RD(bp, shmem_base_path[idx] +
9908 offsetof(struct shmem_region,
9909 dev_info.port_hw_config[0].default_cfg));
9910 reset_pin[idx] &= PORT_HW_CFG_EXT_PHY_GPIO_RST_MASK;
9911 reset_pin[idx] -= PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO0_P0;
9912 reset_pin[idx] >>= PORT_HW_CFG_EXT_PHY_GPIO_RST_SHIFT;
9913 reset_pin[idx] = (1 << reset_pin[idx]);
9914 }
9915 reset_gpios = (u8)(reset_pin[0] | reset_pin[1]);
9916 }
9917
Yaniv Rosner985848f2011-07-05 01:06:48 +00009918 return reset_gpios;
9919}
9920
9921static int bnx2x_84833_hw_reset_phy(struct bnx2x_phy *phy,
9922 struct link_params *params)
9923{
9924 struct bnx2x *bp = params->bp;
9925 u8 reset_gpios;
9926 u32 other_shmem_base_addr = REG_RD(bp, params->shmem2_base +
9927 offsetof(struct shmem2_region,
9928 other_shmem_base_addr));
9929
9930 u32 shmem_base_path[2];
Yaniv Rosner99bf7f32012-04-04 01:29:01 +00009931
9932 /* Work around for 84833 LED failure inside RESET status */
9933 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
9934 MDIO_AN_REG_8481_LEGACY_MII_CTRL,
9935 MDIO_AN_REG_8481_MII_CTRL_FORCE_1G);
9936 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
9937 MDIO_AN_REG_8481_1G_100T_EXT_CTRL,
9938 MIDO_AN_REG_8481_EXT_CTRL_FORCE_LEDS_OFF);
9939
Yaniv Rosner985848f2011-07-05 01:06:48 +00009940 shmem_base_path[0] = params->shmem_base;
9941 shmem_base_path[1] = other_shmem_base_addr;
9942
9943 reset_gpios = bnx2x_84833_get_reset_gpios(bp, shmem_base_path,
9944 params->chip_id);
9945
9946 bnx2x_set_mult_gpio(bp, reset_gpios, MISC_REGISTERS_GPIO_OUTPUT_LOW);
9947 udelay(10);
9948 DP(NETIF_MSG_LINK, "84833 hw reset on pin values 0x%x\n",
9949 reset_gpios);
9950
9951 return 0;
9952}
9953
Yuval Mintzc8c60d82012-06-06 17:13:07 +00009954static int bnx2x_8483x_disable_eee(struct bnx2x_phy *phy,
9955 struct link_params *params,
9956 struct link_vars *vars)
9957{
9958 int rc;
9959 struct bnx2x *bp = params->bp;
9960 u16 cmd_args = 0;
9961
9962 DP(NETIF_MSG_LINK, "Don't Advertise 10GBase-T EEE\n");
9963
Yuval Mintzc8c60d82012-06-06 17:13:07 +00009964 /* Prevent Phy from working in EEE and advertising it */
9965 rc = bnx2x_84833_cmd_hdlr(phy, params,
9966 PHY84833_CMD_SET_EEE_MODE, &cmd_args, 1);
Yuval Mintzd2310232012-06-20 19:05:19 +00009967 if (rc) {
Yuval Mintzc8c60d82012-06-06 17:13:07 +00009968 DP(NETIF_MSG_LINK, "EEE disable failed.\n");
9969 return rc;
9970 }
9971
Yuval Mintzec4010e2012-09-10 05:51:06 +00009972 return bnx2x_eee_disable(phy, params, vars);
Yuval Mintzc8c60d82012-06-06 17:13:07 +00009973}
9974
9975static int bnx2x_8483x_enable_eee(struct bnx2x_phy *phy,
9976 struct link_params *params,
9977 struct link_vars *vars)
9978{
9979 int rc;
9980 struct bnx2x *bp = params->bp;
9981 u16 cmd_args = 1;
9982
Yuval Mintzc8c60d82012-06-06 17:13:07 +00009983 rc = bnx2x_84833_cmd_hdlr(phy, params,
9984 PHY84833_CMD_SET_EEE_MODE, &cmd_args, 1);
Yuval Mintzd2310232012-06-20 19:05:19 +00009985 if (rc) {
Yuval Mintzc8c60d82012-06-06 17:13:07 +00009986 DP(NETIF_MSG_LINK, "EEE enable failed.\n");
9987 return rc;
9988 }
9989
Yuval Mintzec4010e2012-09-10 05:51:06 +00009990 return bnx2x_eee_advertise(phy, params, vars, SHMEM_EEE_10G_ADV);
Yuval Mintzc8c60d82012-06-06 17:13:07 +00009991}
9992
Yaniv Rosnera89a1d42011-07-05 01:07:05 +00009993#define PHY84833_CONSTANT_LATENCY 1193
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +00009994static int bnx2x_848x3_config_init(struct bnx2x_phy *phy,
9995 struct link_params *params,
9996 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +00009997{
9998 struct bnx2x *bp = params->bp;
Yaniv Rosner6a71bbe2010-11-01 05:32:31 +00009999 u8 port, initialize = 1;
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010000 u16 val;
Yaniv Rosner503976e2012-11-27 03:46:34 +000010001 u32 actual_phy_selection;
Yaniv Rosner521683d2011-11-28 00:49:48 +000010002 u16 cmd_args[PHY84833_CMDHDLR_MAX_ARGS];
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000010003 int rc = 0;
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010004
Yaniv Rosner503976e2012-11-27 03:46:34 +000010005 usleep_range(1000, 2000);
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010006
Yuval Mintz54813882012-06-16 20:27:15 +000010007 if (!(CHIP_IS_E1x(bp)))
Yaniv Rosner6a71bbe2010-11-01 05:32:31 +000010008 port = BP_PATH(bp);
10009 else
10010 port = params->port;
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010011
10012 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84823) {
10013 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_3,
10014 MISC_REGISTERS_GPIO_OUTPUT_HIGH,
10015 port);
10016 } else {
Yaniv Rosner985848f2011-07-05 01:06:48 +000010017 /* MDIO reset */
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010018 bnx2x_cl45_write(bp, phy,
10019 MDIO_PMA_DEVAD,
10020 MDIO_PMA_REG_CTRL, 0x8000);
Yaniv Rosner521683d2011-11-28 00:49:48 +000010021 }
10022
10023 bnx2x_wait_reset_complete(bp, phy, params);
10024
10025 /* Wait for GPHY to come out of reset */
10026 msleep(50);
Yaniv Rosner0f6bb032012-11-27 03:46:32 +000010027 if ((phy->type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833) &&
10028 (phy->type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84834)) {
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000010029 /* BCM84823 requires that XGXS links up first @ 10G for normal
Yaniv Rosner521683d2011-11-28 00:49:48 +000010030 * behavior.
10031 */
10032 u16 temp;
10033 temp = vars->line_speed;
10034 vars->line_speed = SPEED_10000;
10035 bnx2x_set_autoneg(&params->phy[INT_PHY], params, vars, 0);
10036 bnx2x_program_serdes(&params->phy[INT_PHY], params, vars);
10037 vars->line_speed = temp;
10038 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010039
10040 bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD,
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010041 MDIO_CTL_REG_84823_MEDIA, &val);
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010042 val &= ~(MDIO_CTL_REG_84823_MEDIA_MAC_MASK |
10043 MDIO_CTL_REG_84823_MEDIA_LINE_MASK |
10044 MDIO_CTL_REG_84823_MEDIA_COPPER_CORE_DOWN |
10045 MDIO_CTL_REG_84823_MEDIA_PRIORITY_MASK |
10046 MDIO_CTL_REG_84823_MEDIA_FIBER_1G);
Yaniv Rosner0d40f0d2011-06-14 01:34:27 +000010047
10048 if (CHIP_IS_E3(bp)) {
10049 val &= ~(MDIO_CTL_REG_84823_MEDIA_MAC_MASK |
10050 MDIO_CTL_REG_84823_MEDIA_LINE_MASK);
10051 } else {
10052 val |= (MDIO_CTL_REG_84823_CTRL_MAC_XFI |
10053 MDIO_CTL_REG_84823_MEDIA_LINE_XAUI_L);
10054 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010055
10056 actual_phy_selection = bnx2x_phy_selection(params);
10057
10058 switch (actual_phy_selection) {
10059 case PORT_HW_CFG_PHY_SELECTION_HARDWARE_DEFAULT:
Lucas De Marchi25985ed2011-03-30 22:57:33 -030010060 /* Do nothing. Essentially this is like the priority copper */
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010061 break;
10062 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY_PRIORITY:
10063 val |= MDIO_CTL_REG_84823_MEDIA_PRIORITY_COPPER;
10064 break;
10065 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY_PRIORITY:
10066 val |= MDIO_CTL_REG_84823_MEDIA_PRIORITY_FIBER;
10067 break;
10068 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY:
10069 /* Do nothing here. The first PHY won't be initialized at all */
10070 break;
10071 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY:
10072 val |= MDIO_CTL_REG_84823_MEDIA_COPPER_CORE_DOWN;
10073 initialize = 0;
10074 break;
10075 }
10076 if (params->phy[EXT_PHY2].req_line_speed == SPEED_1000)
10077 val |= MDIO_CTL_REG_84823_MEDIA_FIBER_1G;
10078
10079 bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010080 MDIO_CTL_REG_84823_MEDIA, val);
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010081 DP(NETIF_MSG_LINK, "Multi_phy config = 0x%x, Media control = 0x%x\n",
10082 params->multi_phy_config, val);
10083
Yaniv Rosner0f6bb032012-11-27 03:46:32 +000010084 if ((phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833) ||
10085 (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84834)) {
Yaniv Rosner11b2ec62012-01-17 02:33:25 +000010086 bnx2x_84833_pair_swap_cfg(phy, params, vars);
Yaniv Rosnera89a1d42011-07-05 01:07:05 +000010087
Yaniv Rosner096b9522012-01-17 02:33:28 +000010088 /* Keep AutogrEEEn disabled. */
10089 cmd_args[0] = 0x0;
Yaniv Rosner11b2ec62012-01-17 02:33:25 +000010090 cmd_args[1] = 0x0;
10091 cmd_args[2] = PHY84833_CONSTANT_LATENCY + 1;
10092 cmd_args[3] = PHY84833_CONSTANT_LATENCY;
10093 rc = bnx2x_84833_cmd_hdlr(phy, params,
Yuval Mintzc8c60d82012-06-06 17:13:07 +000010094 PHY84833_CMD_SET_EEE_MODE, cmd_args,
10095 PHY84833_CMDHDLR_MAX_ARGS);
Yuval Mintzd2310232012-06-20 19:05:19 +000010096 if (rc)
Yaniv Rosner11b2ec62012-01-17 02:33:25 +000010097 DP(NETIF_MSG_LINK, "Cfg AutogrEEEn failed.\n");
10098 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010099 if (initialize)
10100 rc = bnx2x_848xx_cmn_config_init(phy, params, vars);
10101 else
Yaniv Rosner11b2ec62012-01-17 02:33:25 +000010102 bnx2x_save_848xx_spirom_version(phy, bp, params->port);
Yaniv Rosnera89a1d42011-07-05 01:07:05 +000010103 /* 84833 PHY has a better feature and doesn't need to support this. */
10104 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84823) {
Yaniv Rosner503976e2012-11-27 03:46:34 +000010105 u32 cms_enable = REG_RD(bp, params->shmem_base +
Yaniv Rosner1bef68e2011-01-31 04:22:46 +000010106 offsetof(struct shmem_region,
10107 dev_info.port_hw_config[params->port].default_cfg)) &
10108 PORT_HW_CFG_ENABLE_CMS_MASK;
10109
Yaniv Rosnera89a1d42011-07-05 01:07:05 +000010110 bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD,
10111 MDIO_CTL_REG_84823_USER_CTRL_REG, &val);
10112 if (cms_enable)
10113 val |= MDIO_CTL_REG_84823_USER_CTRL_CMS;
10114 else
10115 val &= ~MDIO_CTL_REG_84823_USER_CTRL_CMS;
10116 bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
10117 MDIO_CTL_REG_84823_USER_CTRL_REG, val);
10118 }
Yaniv Rosner1bef68e2011-01-31 04:22:46 +000010119
Yuval Mintzc8c60d82012-06-06 17:13:07 +000010120 bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD,
10121 MDIO_84833_TOP_CFG_FW_REV, &val);
10122
10123 /* Configure EEE support */
Yuval Mintzf6b6eb62012-09-10 05:51:07 +000010124 if ((val >= MDIO_84833_TOP_CFG_FW_EEE) &&
10125 (val != MDIO_84833_TOP_CFG_FW_NO_EEE) &&
10126 bnx2x_eee_has_cap(params)) {
Yuval Mintzec4010e2012-09-10 05:51:06 +000010127 rc = bnx2x_eee_initial_config(params, vars, SHMEM_EEE_10G_ADV);
Yuval Mintzd2310232012-06-20 19:05:19 +000010128 if (rc) {
Yuval Mintzc8c60d82012-06-06 17:13:07 +000010129 DP(NETIF_MSG_LINK, "Failed to configure EEE timers\n");
10130 bnx2x_8483x_disable_eee(phy, params, vars);
10131 return rc;
10132 }
10133
Yaniv Rosnerfd5dfca2012-11-27 03:46:36 +000010134 if ((phy->req_duplex == DUPLEX_FULL) &&
Yuval Mintzc8c60d82012-06-06 17:13:07 +000010135 (params->eee_mode & EEE_MODE_ADV_LPI) &&
10136 (bnx2x_eee_calc_timer(params) ||
10137 !(params->eee_mode & EEE_MODE_ENABLE_LPI)))
10138 rc = bnx2x_8483x_enable_eee(phy, params, vars);
10139 else
10140 rc = bnx2x_8483x_disable_eee(phy, params, vars);
Yuval Mintzd2310232012-06-20 19:05:19 +000010141 if (rc) {
Masanari Iidaefc7ce02012-11-02 04:36:17 +000010142 DP(NETIF_MSG_LINK, "Failed to set EEE advertisement\n");
Yuval Mintzc8c60d82012-06-06 17:13:07 +000010143 return rc;
10144 }
10145 } else {
Yuval Mintzc8c60d82012-06-06 17:13:07 +000010146 vars->eee_status &= ~SHMEM_EEE_SUPPORTED_MASK;
10147 }
10148
Yaniv Rosner0f6bb032012-11-27 03:46:32 +000010149 if ((phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833) ||
10150 (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84834)) {
Yaniv Rosner11b2ec62012-01-17 02:33:25 +000010151 /* Bring PHY out of super isolate mode as the final step. */
Yaniv Rosner503976e2012-11-27 03:46:34 +000010152 bnx2x_cl45_read_and_write(bp, phy,
10153 MDIO_CTL_DEVAD,
10154 MDIO_84833_TOP_CFG_XGPHY_STRAP1,
10155 (u16)~MDIO_84833_SUPER_ISOLATE);
Yaniv Rosner11b2ec62012-01-17 02:33:25 +000010156 }
Yaniv Rosnera22f0782010-09-07 11:41:20 +000010157 return rc;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010158}
10159
10160static u8 bnx2x_848xx_read_status(struct bnx2x_phy *phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010161 struct link_params *params,
10162 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010163{
10164 struct bnx2x *bp = params->bp;
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010165 u16 val, val1, val2;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010166 u8 link_up = 0;
10167
Yaniv Rosnerc87bca12011-01-31 04:22:41 +000010168
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010169 /* Check 10G-BaseT link status */
10170 /* Check PMD signal ok */
10171 bnx2x_cl45_read(bp, phy,
10172 MDIO_AN_DEVAD, 0xFFFA, &val1);
10173 bnx2x_cl45_read(bp, phy,
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010174 MDIO_PMA_DEVAD, MDIO_PMA_REG_8481_PMD_SIGNAL,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010175 &val2);
10176 DP(NETIF_MSG_LINK, "BCM848xx: PMD_SIGNAL 1.a811 = 0x%x\n", val2);
10177
10178 /* Check link 10G */
10179 if (val2 & (1<<11)) {
10180 vars->line_speed = SPEED_10000;
Yaniv Rosner791f18c2011-01-18 04:33:42 +000010181 vars->duplex = DUPLEX_FULL;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010182 link_up = 1;
10183 bnx2x_ext_phy_10G_an_resolve(bp, phy, vars);
10184 } else { /* Check Legacy speed link */
10185 u16 legacy_status, legacy_speed;
10186
10187 /* Enable expansion register 0x42 (Operation mode status) */
10188 bnx2x_cl45_write(bp, phy,
10189 MDIO_AN_DEVAD,
10190 MDIO_AN_REG_8481_EXPANSION_REG_ACCESS, 0xf42);
10191
10192 /* Get legacy speed operation status */
10193 bnx2x_cl45_read(bp, phy,
10194 MDIO_AN_DEVAD,
10195 MDIO_AN_REG_8481_EXPANSION_REG_RD_RW,
10196 &legacy_status);
10197
Joe Perches94f05b02011-08-14 12:16:20 +000010198 DP(NETIF_MSG_LINK, "Legacy speed status = 0x%x\n",
10199 legacy_status);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010200 link_up = ((legacy_status & (1<<11)) == (1<<11));
Yuval Mintz14400902012-06-20 19:05:20 +000010201 legacy_speed = (legacy_status & (3<<9));
10202 if (legacy_speed == (0<<9))
10203 vars->line_speed = SPEED_10;
10204 else if (legacy_speed == (1<<9))
10205 vars->line_speed = SPEED_100;
10206 else if (legacy_speed == (2<<9))
10207 vars->line_speed = SPEED_1000;
10208 else { /* Should not happen: Treat as link down */
10209 vars->line_speed = 0;
10210 link_up = 0;
10211 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010212
Yuval Mintz14400902012-06-20 19:05:20 +000010213 if (link_up) {
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010214 if (legacy_status & (1<<8))
10215 vars->duplex = DUPLEX_FULL;
10216 else
10217 vars->duplex = DUPLEX_HALF;
10218
Joe Perches94f05b02011-08-14 12:16:20 +000010219 DP(NETIF_MSG_LINK,
10220 "Link is up in %dMbps, is_duplex_full= %d\n",
10221 vars->line_speed,
10222 (vars->duplex == DUPLEX_FULL));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010223 /* Check legacy speed AN resolution */
10224 bnx2x_cl45_read(bp, phy,
10225 MDIO_AN_DEVAD,
10226 MDIO_AN_REG_8481_LEGACY_MII_STATUS,
10227 &val);
10228 if (val & (1<<5))
10229 vars->link_status |=
10230 LINK_STATUS_AUTO_NEGOTIATE_COMPLETE;
10231 bnx2x_cl45_read(bp, phy,
10232 MDIO_AN_DEVAD,
10233 MDIO_AN_REG_8481_LEGACY_AN_EXPANSION,
10234 &val);
10235 if ((val & (1<<0)) == 0)
10236 vars->link_status |=
10237 LINK_STATUS_PARALLEL_DETECTION_USED;
10238 }
10239 }
10240 if (link_up) {
Yuval Mintzd2310232012-06-20 19:05:19 +000010241 DP(NETIF_MSG_LINK, "BCM848x3: link speed is %d\n",
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010242 vars->line_speed);
10243 bnx2x_ext_phy_resolve_fc(phy, params, vars);
Mintz Yuval9e7e8392012-02-15 02:10:24 +000010244
10245 /* Read LP advertised speeds */
10246 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
10247 MDIO_AN_REG_CL37_FC_LP, &val);
10248 if (val & (1<<5))
10249 vars->link_status |=
10250 LINK_STATUS_LINK_PARTNER_10THD_CAPABLE;
10251 if (val & (1<<6))
10252 vars->link_status |=
10253 LINK_STATUS_LINK_PARTNER_10TFD_CAPABLE;
10254 if (val & (1<<7))
10255 vars->link_status |=
10256 LINK_STATUS_LINK_PARTNER_100TXHD_CAPABLE;
10257 if (val & (1<<8))
10258 vars->link_status |=
10259 LINK_STATUS_LINK_PARTNER_100TXFD_CAPABLE;
10260 if (val & (1<<9))
10261 vars->link_status |=
10262 LINK_STATUS_LINK_PARTNER_100T4_CAPABLE;
10263
10264 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
10265 MDIO_AN_REG_1000T_STATUS, &val);
10266
10267 if (val & (1<<10))
10268 vars->link_status |=
10269 LINK_STATUS_LINK_PARTNER_1000THD_CAPABLE;
10270 if (val & (1<<11))
10271 vars->link_status |=
10272 LINK_STATUS_LINK_PARTNER_1000TFD_CAPABLE;
10273
10274 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
10275 MDIO_AN_REG_MASTER_STATUS, &val);
10276
10277 if (val & (1<<11))
10278 vars->link_status |=
10279 LINK_STATUS_LINK_PARTNER_10GXFD_CAPABLE;
Yuval Mintzc8c60d82012-06-06 17:13:07 +000010280
10281 /* Determine if EEE was negotiated */
Yuval Mintzec4010e2012-09-10 05:51:06 +000010282 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
10283 bnx2x_eee_an_resolve(phy, params, vars);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010284 }
10285
10286 return link_up;
10287}
10288
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000010289static int bnx2x_848xx_format_ver(u32 raw_ver, u8 *str, u16 *len)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010290{
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000010291 int status = 0;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010292 u32 spirom_ver;
10293 spirom_ver = ((raw_ver & 0xF80) >> 7) << 16 | (raw_ver & 0x7F);
10294 status = bnx2x_format_ver(spirom_ver, str, len);
10295 return status;
10296}
10297
10298static void bnx2x_8481_hw_reset(struct bnx2x_phy *phy,
10299 struct link_params *params)
10300{
10301 bnx2x_set_gpio(params->bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010302 MISC_REGISTERS_GPIO_OUTPUT_LOW, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010303 bnx2x_set_gpio(params->bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010304 MISC_REGISTERS_GPIO_OUTPUT_LOW, 1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010305}
10306
10307static void bnx2x_8481_link_reset(struct bnx2x_phy *phy,
10308 struct link_params *params)
10309{
10310 bnx2x_cl45_write(params->bp, phy,
10311 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x0000);
10312 bnx2x_cl45_write(params->bp, phy,
10313 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 1);
10314}
10315
10316static void bnx2x_848x3_link_reset(struct bnx2x_phy *phy,
10317 struct link_params *params)
10318{
10319 struct bnx2x *bp = params->bp;
Yaniv Rosner6a71bbe2010-11-01 05:32:31 +000010320 u8 port;
Yaniv Rosner0d40f0d2011-06-14 01:34:27 +000010321 u16 val16;
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010322
Yaniv Rosnerf93fb012012-04-04 01:29:02 +000010323 if (!(CHIP_IS_E1x(bp)))
Yaniv Rosner6a71bbe2010-11-01 05:32:31 +000010324 port = BP_PATH(bp);
10325 else
10326 port = params->port;
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010327
10328 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84823) {
10329 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_3,
10330 MISC_REGISTERS_GPIO_OUTPUT_LOW,
10331 port);
10332 } else {
Yaniv Rosner0d40f0d2011-06-14 01:34:27 +000010333 bnx2x_cl45_read(bp, phy,
10334 MDIO_CTL_DEVAD,
Yaniv Rosner11b2ec62012-01-17 02:33:25 +000010335 MDIO_84833_TOP_CFG_XGPHY_STRAP1, &val16);
10336 val16 |= MDIO_84833_SUPER_ISOLATE;
Yaniv Rosnerfd38f73e2011-08-02 22:59:53 +000010337 bnx2x_cl45_write(bp, phy,
Yaniv Rosner11b2ec62012-01-17 02:33:25 +000010338 MDIO_CTL_DEVAD,
10339 MDIO_84833_TOP_CFG_XGPHY_STRAP1, val16);
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010340 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010341}
10342
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010343static void bnx2x_848xx_set_link_led(struct bnx2x_phy *phy,
10344 struct link_params *params, u8 mode)
10345{
10346 struct bnx2x *bp = params->bp;
10347 u16 val;
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010348 u8 port;
10349
Yaniv Rosnerf93fb012012-04-04 01:29:02 +000010350 if (!(CHIP_IS_E1x(bp)))
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010351 port = BP_PATH(bp);
10352 else
10353 port = params->port;
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010354
10355 switch (mode) {
10356 case LED_MODE_OFF:
10357
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010358 DP(NETIF_MSG_LINK, "Port 0x%x: LED MODE OFF\n", port);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010359
10360 if ((params->hw_led_mode << SHARED_HW_CFG_LED_MODE_SHIFT) ==
10361 SHARED_HW_CFG_LED_EXTPHY1) {
10362
10363 /* Set LED masks */
10364 bnx2x_cl45_write(bp, phy,
10365 MDIO_PMA_DEVAD,
10366 MDIO_PMA_REG_8481_LED1_MASK,
10367 0x0);
10368
10369 bnx2x_cl45_write(bp, phy,
10370 MDIO_PMA_DEVAD,
10371 MDIO_PMA_REG_8481_LED2_MASK,
10372 0x0);
10373
10374 bnx2x_cl45_write(bp, phy,
10375 MDIO_PMA_DEVAD,
10376 MDIO_PMA_REG_8481_LED3_MASK,
10377 0x0);
10378
10379 bnx2x_cl45_write(bp, phy,
10380 MDIO_PMA_DEVAD,
10381 MDIO_PMA_REG_8481_LED5_MASK,
10382 0x0);
10383
10384 } else {
10385 bnx2x_cl45_write(bp, phy,
10386 MDIO_PMA_DEVAD,
10387 MDIO_PMA_REG_8481_LED1_MASK,
10388 0x0);
10389 }
10390 break;
10391 case LED_MODE_FRONT_PANEL_OFF:
10392
10393 DP(NETIF_MSG_LINK, "Port 0x%x: LED MODE FRONT PANEL OFF\n",
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010394 port);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010395
10396 if ((params->hw_led_mode << SHARED_HW_CFG_LED_MODE_SHIFT) ==
10397 SHARED_HW_CFG_LED_EXTPHY1) {
10398
10399 /* Set LED masks */
10400 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010401 MDIO_PMA_DEVAD,
10402 MDIO_PMA_REG_8481_LED1_MASK,
10403 0x0);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010404
10405 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010406 MDIO_PMA_DEVAD,
10407 MDIO_PMA_REG_8481_LED2_MASK,
10408 0x0);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010409
10410 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010411 MDIO_PMA_DEVAD,
10412 MDIO_PMA_REG_8481_LED3_MASK,
10413 0x0);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010414
10415 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010416 MDIO_PMA_DEVAD,
10417 MDIO_PMA_REG_8481_LED5_MASK,
10418 0x20);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010419
10420 } else {
10421 bnx2x_cl45_write(bp, phy,
10422 MDIO_PMA_DEVAD,
10423 MDIO_PMA_REG_8481_LED1_MASK,
10424 0x0);
10425 }
10426 break;
10427 case LED_MODE_ON:
10428
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010429 DP(NETIF_MSG_LINK, "Port 0x%x: LED MODE ON\n", port);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010430
10431 if ((params->hw_led_mode << SHARED_HW_CFG_LED_MODE_SHIFT) ==
10432 SHARED_HW_CFG_LED_EXTPHY1) {
10433 /* Set control reg */
10434 bnx2x_cl45_read(bp, phy,
10435 MDIO_PMA_DEVAD,
10436 MDIO_PMA_REG_8481_LINK_SIGNAL,
10437 &val);
10438 val &= 0x8000;
10439 val |= 0x2492;
10440
10441 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010442 MDIO_PMA_DEVAD,
10443 MDIO_PMA_REG_8481_LINK_SIGNAL,
10444 val);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010445
10446 /* Set LED masks */
10447 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010448 MDIO_PMA_DEVAD,
10449 MDIO_PMA_REG_8481_LED1_MASK,
10450 0x0);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010451
10452 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010453 MDIO_PMA_DEVAD,
10454 MDIO_PMA_REG_8481_LED2_MASK,
10455 0x20);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010456
10457 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010458 MDIO_PMA_DEVAD,
10459 MDIO_PMA_REG_8481_LED3_MASK,
10460 0x20);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010461
10462 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010463 MDIO_PMA_DEVAD,
10464 MDIO_PMA_REG_8481_LED5_MASK,
10465 0x0);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010466 } else {
10467 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010468 MDIO_PMA_DEVAD,
10469 MDIO_PMA_REG_8481_LED1_MASK,
10470 0x20);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010471 }
10472 break;
10473
10474 case LED_MODE_OPER:
10475
Yaniv Rosnerbac27bd2011-05-31 21:28:10 +000010476 DP(NETIF_MSG_LINK, "Port 0x%x: LED MODE OPER\n", port);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010477
10478 if ((params->hw_led_mode << SHARED_HW_CFG_LED_MODE_SHIFT) ==
10479 SHARED_HW_CFG_LED_EXTPHY1) {
10480
10481 /* Set control reg */
10482 bnx2x_cl45_read(bp, phy,
10483 MDIO_PMA_DEVAD,
10484 MDIO_PMA_REG_8481_LINK_SIGNAL,
10485 &val);
10486
10487 if (!((val &
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010488 MDIO_PMA_REG_8481_LINK_SIGNAL_LED4_ENABLE_MASK)
10489 >> MDIO_PMA_REG_8481_LINK_SIGNAL_LED4_ENABLE_SHIFT)) {
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +000010490 DP(NETIF_MSG_LINK, "Setting LINK_SIGNAL\n");
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010491 bnx2x_cl45_write(bp, phy,
10492 MDIO_PMA_DEVAD,
10493 MDIO_PMA_REG_8481_LINK_SIGNAL,
10494 0xa492);
10495 }
10496
10497 /* Set LED masks */
10498 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010499 MDIO_PMA_DEVAD,
10500 MDIO_PMA_REG_8481_LED1_MASK,
10501 0x10);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010502
10503 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010504 MDIO_PMA_DEVAD,
10505 MDIO_PMA_REG_8481_LED2_MASK,
10506 0x80);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010507
10508 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010509 MDIO_PMA_DEVAD,
10510 MDIO_PMA_REG_8481_LED3_MASK,
10511 0x98);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010512
10513 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000010514 MDIO_PMA_DEVAD,
10515 MDIO_PMA_REG_8481_LED5_MASK,
10516 0x40);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010517
10518 } else {
10519 bnx2x_cl45_write(bp, phy,
10520 MDIO_PMA_DEVAD,
10521 MDIO_PMA_REG_8481_LED1_MASK,
10522 0x80);
Yaniv Rosner53eda062011-01-30 04:14:55 +000010523
10524 /* Tell LED3 to blink on source */
10525 bnx2x_cl45_read(bp, phy,
10526 MDIO_PMA_DEVAD,
10527 MDIO_PMA_REG_8481_LINK_SIGNAL,
10528 &val);
10529 val &= ~(7<<6);
10530 val |= (1<<6); /* A83B[8:6]= 1 */
10531 bnx2x_cl45_write(bp, phy,
10532 MDIO_PMA_DEVAD,
10533 MDIO_PMA_REG_8481_LINK_SIGNAL,
10534 val);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010535 }
10536 break;
10537 }
Yaniv Rosner0d40f0d2011-06-14 01:34:27 +000010538
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000010539 /* This is a workaround for E3+84833 until autoneg
Yaniv Rosner0d40f0d2011-06-14 01:34:27 +000010540 * restart is fixed in f/w
10541 */
10542 if (CHIP_IS_E3(bp)) {
10543 bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
10544 MDIO_WC_REG_GP2_STATUS_GP_2_1, &val);
10545 }
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000010546}
Yaniv Rosner0d40f0d2011-06-14 01:34:27 +000010547
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010548/******************************************************************/
Yaniv Rosner52c4d6c2011-07-05 01:06:34 +000010549/* 54618SE PHY SECTION */
Yaniv Rosner6583e332011-06-14 01:34:17 +000010550/******************************************************************/
Yaniv Rosner5c107fd2012-09-13 02:56:19 +000010551static void bnx2x_54618se_specific_func(struct bnx2x_phy *phy,
10552 struct link_params *params,
10553 u32 action)
10554{
10555 struct bnx2x *bp = params->bp;
10556 u16 temp;
10557 switch (action) {
10558 case PHY_INIT:
10559 /* Configure LED4: set to INTR (0x6). */
10560 /* Accessing shadow register 0xe. */
10561 bnx2x_cl22_write(bp, phy,
10562 MDIO_REG_GPHY_SHADOW,
10563 MDIO_REG_GPHY_SHADOW_LED_SEL2);
10564 bnx2x_cl22_read(bp, phy,
10565 MDIO_REG_GPHY_SHADOW,
10566 &temp);
10567 temp &= ~(0xf << 4);
10568 temp |= (0x6 << 4);
10569 bnx2x_cl22_write(bp, phy,
10570 MDIO_REG_GPHY_SHADOW,
10571 MDIO_REG_GPHY_SHADOW_WR_ENA | temp);
10572 /* Configure INTR based on link status change. */
10573 bnx2x_cl22_write(bp, phy,
10574 MDIO_REG_INTR_MASK,
10575 ~MDIO_REG_INTR_MASK_LINK_STATUS);
10576 break;
10577 }
10578}
10579
Yaniv Rosner52c4d6c2011-07-05 01:06:34 +000010580static int bnx2x_54618se_config_init(struct bnx2x_phy *phy,
Yaniv Rosner6583e332011-06-14 01:34:17 +000010581 struct link_params *params,
10582 struct link_vars *vars)
10583{
10584 struct bnx2x *bp = params->bp;
10585 u8 port;
10586 u16 autoneg_val, an_1000_val, an_10_100_val, fc_val, temp;
10587 u32 cfg_pin;
10588
Yaniv Rosner52c4d6c2011-07-05 01:06:34 +000010589 DP(NETIF_MSG_LINK, "54618SE cfg init\n");
Yuval Mintzd2310232012-06-20 19:05:19 +000010590 usleep_range(1000, 2000);
Yaniv Rosner6583e332011-06-14 01:34:17 +000010591
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000010592 /* This works with E3 only, no need to check the chip
Yaniv Rosner2f751a82011-11-28 00:49:52 +000010593 * before determining the port.
10594 */
Yaniv Rosner6583e332011-06-14 01:34:17 +000010595 port = params->port;
10596
10597 cfg_pin = (REG_RD(bp, params->shmem_base +
10598 offsetof(struct shmem_region,
10599 dev_info.port_hw_config[port].e3_cmn_pin_cfg)) &
10600 PORT_HW_CFG_E3_PHY_RESET_MASK) >>
10601 PORT_HW_CFG_E3_PHY_RESET_SHIFT;
10602
10603 /* Drive pin high to bring the GPHY out of reset. */
10604 bnx2x_set_cfg_pin(bp, cfg_pin, 1);
10605
10606 /* wait for GPHY to reset */
10607 msleep(50);
10608
10609 /* reset phy */
10610 bnx2x_cl22_write(bp, phy,
10611 MDIO_PMA_REG_CTRL, 0x8000);
10612 bnx2x_wait_reset_complete(bp, phy, params);
10613
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000010614 /* Wait for GPHY to reset */
Yaniv Rosner6583e332011-06-14 01:34:17 +000010615 msleep(50);
10616
Yaniv Rosner6583e332011-06-14 01:34:17 +000010617
Yaniv Rosner5c107fd2012-09-13 02:56:19 +000010618 bnx2x_54618se_specific_func(phy, params, PHY_INIT);
Yaniv Rosner6583e332011-06-14 01:34:17 +000010619 /* Flip the signal detect polarity (set 0x1c.0x1e[8]). */
10620 bnx2x_cl22_write(bp, phy,
10621 MDIO_REG_GPHY_SHADOW,
10622 MDIO_REG_GPHY_SHADOW_AUTO_DET_MED);
10623 bnx2x_cl22_read(bp, phy,
10624 MDIO_REG_GPHY_SHADOW,
10625 &temp);
10626 temp |= MDIO_REG_GPHY_SHADOW_INVERT_FIB_SD;
10627 bnx2x_cl22_write(bp, phy,
10628 MDIO_REG_GPHY_SHADOW,
10629 MDIO_REG_GPHY_SHADOW_WR_ENA | temp);
10630
10631 /* Set up fc */
10632 /* Please refer to Table 28B-3 of 802.3ab-1999 spec. */
10633 bnx2x_calc_ieee_aneg_adv(phy, params, &vars->ieee_fc);
10634 fc_val = 0;
10635 if ((vars->ieee_fc & MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC) ==
10636 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC)
10637 fc_val |= MDIO_AN_REG_ADV_PAUSE_ASYMMETRIC;
10638
10639 if ((vars->ieee_fc & MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) ==
10640 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH)
10641 fc_val |= MDIO_AN_REG_ADV_PAUSE_PAUSE;
10642
Yuval Mintzd2310232012-06-20 19:05:19 +000010643 /* Read all advertisement */
Yaniv Rosner6583e332011-06-14 01:34:17 +000010644 bnx2x_cl22_read(bp, phy,
10645 0x09,
10646 &an_1000_val);
10647
10648 bnx2x_cl22_read(bp, phy,
10649 0x04,
10650 &an_10_100_val);
10651
10652 bnx2x_cl22_read(bp, phy,
10653 MDIO_PMA_REG_CTRL,
10654 &autoneg_val);
10655
10656 /* Disable forced speed */
10657 autoneg_val &= ~((1<<6) | (1<<8) | (1<<9) | (1<<12) | (1<<13));
10658 an_10_100_val &= ~((1<<5) | (1<<6) | (1<<7) | (1<<8) | (1<<10) |
10659 (1<<11));
10660
10661 if (((phy->req_line_speed == SPEED_AUTO_NEG) &&
10662 (phy->speed_cap_mask &
10663 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) ||
10664 (phy->req_line_speed == SPEED_1000)) {
10665 an_1000_val |= (1<<8);
10666 autoneg_val |= (1<<9 | 1<<12);
10667 if (phy->req_duplex == DUPLEX_FULL)
10668 an_1000_val |= (1<<9);
10669 DP(NETIF_MSG_LINK, "Advertising 1G\n");
10670 } else
10671 an_1000_val &= ~((1<<8) | (1<<9));
10672
10673 bnx2x_cl22_write(bp, phy,
10674 0x09,
10675 an_1000_val);
10676 bnx2x_cl22_read(bp, phy,
10677 0x09,
10678 &an_1000_val);
10679
Yuval Mintzd2310232012-06-20 19:05:19 +000010680 /* Set 100 speed advertisement */
Yaniv Rosner6583e332011-06-14 01:34:17 +000010681 if (((phy->req_line_speed == SPEED_AUTO_NEG) &&
10682 (phy->speed_cap_mask &
10683 (PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL |
10684 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF)))) {
10685 an_10_100_val |= (1<<7);
10686 /* Enable autoneg and restart autoneg for legacy speeds */
10687 autoneg_val |= (1<<9 | 1<<12);
10688
10689 if (phy->req_duplex == DUPLEX_FULL)
10690 an_10_100_val |= (1<<8);
10691 DP(NETIF_MSG_LINK, "Advertising 100M\n");
10692 }
10693
Yuval Mintzd2310232012-06-20 19:05:19 +000010694 /* Set 10 speed advertisement */
Yaniv Rosner6583e332011-06-14 01:34:17 +000010695 if (((phy->req_line_speed == SPEED_AUTO_NEG) &&
10696 (phy->speed_cap_mask &
10697 (PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL |
10698 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF)))) {
10699 an_10_100_val |= (1<<5);
10700 autoneg_val |= (1<<9 | 1<<12);
10701 if (phy->req_duplex == DUPLEX_FULL)
10702 an_10_100_val |= (1<<6);
10703 DP(NETIF_MSG_LINK, "Advertising 10M\n");
10704 }
10705
10706 /* Only 10/100 are allowed to work in FORCE mode */
10707 if (phy->req_line_speed == SPEED_100) {
10708 autoneg_val |= (1<<13);
10709 /* Enabled AUTO-MDIX when autoneg is disabled */
10710 bnx2x_cl22_write(bp, phy,
10711 0x18,
10712 (1<<15 | 1<<9 | 7<<0));
10713 DP(NETIF_MSG_LINK, "Setting 100M force\n");
10714 }
10715 if (phy->req_line_speed == SPEED_10) {
10716 /* Enabled AUTO-MDIX when autoneg is disabled */
10717 bnx2x_cl22_write(bp, phy,
10718 0x18,
10719 (1<<15 | 1<<9 | 7<<0));
10720 DP(NETIF_MSG_LINK, "Setting 10M force\n");
10721 }
10722
Yuval Mintz26964bb2012-09-10 05:51:08 +000010723 if ((phy->flags & FLAGS_EEE) && bnx2x_eee_has_cap(params)) {
10724 int rc;
10725
10726 bnx2x_cl22_write(bp, phy, MDIO_REG_GPHY_EXP_ACCESS,
10727 MDIO_REG_GPHY_EXP_ACCESS_TOP |
10728 MDIO_REG_GPHY_EXP_TOP_2K_BUF);
10729 bnx2x_cl22_read(bp, phy, MDIO_REG_GPHY_EXP_ACCESS_GATE, &temp);
10730 temp &= 0xfffe;
10731 bnx2x_cl22_write(bp, phy, MDIO_REG_GPHY_EXP_ACCESS_GATE, temp);
10732
10733 rc = bnx2x_eee_initial_config(params, vars, SHMEM_EEE_1G_ADV);
10734 if (rc) {
10735 DP(NETIF_MSG_LINK, "Failed to configure EEE timers\n");
10736 bnx2x_eee_disable(phy, params, vars);
10737 } else if ((params->eee_mode & EEE_MODE_ADV_LPI) &&
10738 (phy->req_duplex == DUPLEX_FULL) &&
10739 (bnx2x_eee_calc_timer(params) ||
10740 !(params->eee_mode & EEE_MODE_ENABLE_LPI))) {
10741 /* Need to advertise EEE only when requested,
10742 * and either no LPI assertion was requested,
10743 * or it was requested and a valid timer was set.
10744 * Also notice full duplex is required for EEE.
10745 */
10746 bnx2x_eee_advertise(phy, params, vars,
10747 SHMEM_EEE_1G_ADV);
Yaniv Rosnera89a1d42011-07-05 01:07:05 +000010748 } else {
Yuval Mintz26964bb2012-09-10 05:51:08 +000010749 DP(NETIF_MSG_LINK, "Don't Advertise 1GBase-T EEE\n");
10750 bnx2x_eee_disable(phy, params, vars);
Yaniv Rosnera89a1d42011-07-05 01:07:05 +000010751 }
Yuval Mintz26964bb2012-09-10 05:51:08 +000010752 } else {
10753 vars->eee_status &= ~SHMEM_EEE_1G_ADV <<
10754 SHMEM_EEE_SUPPORTED_SHIFT;
10755
10756 if (phy->flags & FLAGS_EEE) {
10757 /* Handle legacy auto-grEEEn */
10758 if (params->feature_config_flags &
10759 FEATURE_CONFIG_AUTOGREEEN_ENABLED) {
10760 temp = 6;
10761 DP(NETIF_MSG_LINK, "Enabling Auto-GrEEEn\n");
10762 } else {
10763 temp = 0;
10764 DP(NETIF_MSG_LINK, "Don't Adv. EEE\n");
10765 }
10766 bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
10767 MDIO_AN_REG_EEE_ADV, temp);
10768 }
Yaniv Rosnera89a1d42011-07-05 01:07:05 +000010769 }
10770
Yaniv Rosner6583e332011-06-14 01:34:17 +000010771 bnx2x_cl22_write(bp, phy,
10772 0x04,
10773 an_10_100_val | fc_val);
10774
10775 if (phy->req_duplex == DUPLEX_FULL)
10776 autoneg_val |= (1<<8);
10777
10778 bnx2x_cl22_write(bp, phy,
10779 MDIO_PMA_REG_CTRL, autoneg_val);
10780
10781 return 0;
10782}
10783
Yaniv Rosner1d125bd2011-11-23 03:54:08 +000010784
10785static void bnx2x_5461x_set_link_led(struct bnx2x_phy *phy,
10786 struct link_params *params, u8 mode)
10787{
10788 struct bnx2x *bp = params->bp;
10789 u16 temp;
10790
10791 bnx2x_cl22_write(bp, phy,
10792 MDIO_REG_GPHY_SHADOW,
10793 MDIO_REG_GPHY_SHADOW_LED_SEL1);
10794 bnx2x_cl22_read(bp, phy,
10795 MDIO_REG_GPHY_SHADOW,
10796 &temp);
10797 temp &= 0xff00;
10798
10799 DP(NETIF_MSG_LINK, "54618x set link led (mode=%x)\n", mode);
10800 switch (mode) {
10801 case LED_MODE_FRONT_PANEL_OFF:
10802 case LED_MODE_OFF:
10803 temp |= 0x00ee;
10804 break;
10805 case LED_MODE_OPER:
10806 temp |= 0x0001;
10807 break;
10808 case LED_MODE_ON:
10809 temp |= 0x00ff;
10810 break;
10811 default:
10812 break;
10813 }
10814 bnx2x_cl22_write(bp, phy,
10815 MDIO_REG_GPHY_SHADOW,
10816 MDIO_REG_GPHY_SHADOW_WR_ENA | temp);
10817 return;
10818}
10819
10820
Yaniv Rosner52c4d6c2011-07-05 01:06:34 +000010821static void bnx2x_54618se_link_reset(struct bnx2x_phy *phy,
10822 struct link_params *params)
Yaniv Rosner6583e332011-06-14 01:34:17 +000010823{
10824 struct bnx2x *bp = params->bp;
10825 u32 cfg_pin;
10826 u8 port;
10827
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000010828 /* In case of no EPIO routed to reset the GPHY, put it
Yaniv Rosnerd2059a02011-08-02 23:00:00 +000010829 * in low power mode.
10830 */
10831 bnx2x_cl22_write(bp, phy, MDIO_PMA_REG_CTRL, 0x800);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000010832 /* This works with E3 only, no need to check the chip
Yaniv Rosnerd2059a02011-08-02 23:00:00 +000010833 * before determining the port.
10834 */
Yaniv Rosner6583e332011-06-14 01:34:17 +000010835 port = params->port;
10836 cfg_pin = (REG_RD(bp, params->shmem_base +
10837 offsetof(struct shmem_region,
10838 dev_info.port_hw_config[port].e3_cmn_pin_cfg)) &
10839 PORT_HW_CFG_E3_PHY_RESET_MASK) >>
10840 PORT_HW_CFG_E3_PHY_RESET_SHIFT;
10841
10842 /* Drive pin low to put GPHY in reset. */
10843 bnx2x_set_cfg_pin(bp, cfg_pin, 0);
10844}
10845
Yaniv Rosner52c4d6c2011-07-05 01:06:34 +000010846static u8 bnx2x_54618se_read_status(struct bnx2x_phy *phy,
10847 struct link_params *params,
10848 struct link_vars *vars)
Yaniv Rosner6583e332011-06-14 01:34:17 +000010849{
10850 struct bnx2x *bp = params->bp;
10851 u16 val;
10852 u8 link_up = 0;
10853 u16 legacy_status, legacy_speed;
10854
10855 /* Get speed operation status */
10856 bnx2x_cl22_read(bp, phy,
Yuval Mintza351d492012-06-20 19:05:21 +000010857 MDIO_REG_GPHY_AUX_STATUS,
Yaniv Rosner6583e332011-06-14 01:34:17 +000010858 &legacy_status);
Yaniv Rosner52c4d6c2011-07-05 01:06:34 +000010859 DP(NETIF_MSG_LINK, "54618SE read_status: 0x%x\n", legacy_status);
Yaniv Rosner6583e332011-06-14 01:34:17 +000010860
10861 /* Read status to clear the PHY interrupt. */
10862 bnx2x_cl22_read(bp, phy,
10863 MDIO_REG_INTR_STATUS,
10864 &val);
10865
10866 link_up = ((legacy_status & (1<<2)) == (1<<2));
10867
10868 if (link_up) {
10869 legacy_speed = (legacy_status & (7<<8));
10870 if (legacy_speed == (7<<8)) {
10871 vars->line_speed = SPEED_1000;
10872 vars->duplex = DUPLEX_FULL;
10873 } else if (legacy_speed == (6<<8)) {
10874 vars->line_speed = SPEED_1000;
10875 vars->duplex = DUPLEX_HALF;
10876 } else if (legacy_speed == (5<<8)) {
10877 vars->line_speed = SPEED_100;
10878 vars->duplex = DUPLEX_FULL;
10879 }
10880 /* Omitting 100Base-T4 for now */
10881 else if (legacy_speed == (3<<8)) {
10882 vars->line_speed = SPEED_100;
10883 vars->duplex = DUPLEX_HALF;
10884 } else if (legacy_speed == (2<<8)) {
10885 vars->line_speed = SPEED_10;
10886 vars->duplex = DUPLEX_FULL;
10887 } else if (legacy_speed == (1<<8)) {
10888 vars->line_speed = SPEED_10;
10889 vars->duplex = DUPLEX_HALF;
10890 } else /* Should not happen */
10891 vars->line_speed = 0;
10892
Joe Perches94f05b02011-08-14 12:16:20 +000010893 DP(NETIF_MSG_LINK,
10894 "Link is up in %dMbps, is_duplex_full= %d\n",
10895 vars->line_speed,
10896 (vars->duplex == DUPLEX_FULL));
Yaniv Rosner6583e332011-06-14 01:34:17 +000010897
10898 /* Check legacy speed AN resolution */
10899 bnx2x_cl22_read(bp, phy,
10900 0x01,
10901 &val);
10902 if (val & (1<<5))
10903 vars->link_status |=
10904 LINK_STATUS_AUTO_NEGOTIATE_COMPLETE;
10905 bnx2x_cl22_read(bp, phy,
10906 0x06,
10907 &val);
10908 if ((val & (1<<0)) == 0)
10909 vars->link_status |=
10910 LINK_STATUS_PARALLEL_DETECTION_USED;
10911
Yaniv Rosner52c4d6c2011-07-05 01:06:34 +000010912 DP(NETIF_MSG_LINK, "BCM54618SE: link speed is %d\n",
Yaniv Rosner6583e332011-06-14 01:34:17 +000010913 vars->line_speed);
Yaniv Rosner52c4d6c2011-07-05 01:06:34 +000010914
Yaniv Rosner6583e332011-06-14 01:34:17 +000010915 bnx2x_ext_phy_resolve_fc(phy, params, vars);
Mintz Yuval9e7e8392012-02-15 02:10:24 +000010916
10917 if (vars->link_status & LINK_STATUS_AUTO_NEGOTIATE_COMPLETE) {
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000010918 /* Report LP advertised speeds */
Mintz Yuval9e7e8392012-02-15 02:10:24 +000010919 bnx2x_cl22_read(bp, phy, 0x5, &val);
10920
10921 if (val & (1<<5))
10922 vars->link_status |=
10923 LINK_STATUS_LINK_PARTNER_10THD_CAPABLE;
10924 if (val & (1<<6))
10925 vars->link_status |=
10926 LINK_STATUS_LINK_PARTNER_10TFD_CAPABLE;
10927 if (val & (1<<7))
10928 vars->link_status |=
10929 LINK_STATUS_LINK_PARTNER_100TXHD_CAPABLE;
10930 if (val & (1<<8))
10931 vars->link_status |=
10932 LINK_STATUS_LINK_PARTNER_100TXFD_CAPABLE;
10933 if (val & (1<<9))
10934 vars->link_status |=
10935 LINK_STATUS_LINK_PARTNER_100T4_CAPABLE;
10936
10937 bnx2x_cl22_read(bp, phy, 0xa, &val);
10938 if (val & (1<<10))
10939 vars->link_status |=
10940 LINK_STATUS_LINK_PARTNER_1000THD_CAPABLE;
10941 if (val & (1<<11))
10942 vars->link_status |=
10943 LINK_STATUS_LINK_PARTNER_1000TFD_CAPABLE;
Yuval Mintz26964bb2012-09-10 05:51:08 +000010944
10945 if ((phy->flags & FLAGS_EEE) &&
10946 bnx2x_eee_has_cap(params))
10947 bnx2x_eee_an_resolve(phy, params, vars);
Mintz Yuval9e7e8392012-02-15 02:10:24 +000010948 }
Yaniv Rosner6583e332011-06-14 01:34:17 +000010949 }
10950 return link_up;
10951}
10952
Yaniv Rosner52c4d6c2011-07-05 01:06:34 +000010953static void bnx2x_54618se_config_loopback(struct bnx2x_phy *phy,
10954 struct link_params *params)
Yaniv Rosner6583e332011-06-14 01:34:17 +000010955{
10956 struct bnx2x *bp = params->bp;
10957 u16 val;
10958 u32 umac_base = params->port ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
10959
Yaniv Rosner52c4d6c2011-07-05 01:06:34 +000010960 DP(NETIF_MSG_LINK, "2PMA/PMD ext_phy_loopback: 54618se\n");
Yaniv Rosner6583e332011-06-14 01:34:17 +000010961
10962 /* Enable master/slave manual mmode and set to master */
10963 /* mii write 9 [bits set 11 12] */
10964 bnx2x_cl22_write(bp, phy, 0x09, 3<<11);
10965
10966 /* forced 1G and disable autoneg */
10967 /* set val [mii read 0] */
10968 /* set val [expr $val & [bits clear 6 12 13]] */
10969 /* set val [expr $val | [bits set 6 8]] */
10970 /* mii write 0 $val */
10971 bnx2x_cl22_read(bp, phy, 0x00, &val);
10972 val &= ~((1<<6) | (1<<12) | (1<<13));
10973 val |= (1<<6) | (1<<8);
10974 bnx2x_cl22_write(bp, phy, 0x00, val);
10975
10976 /* Set external loopback and Tx using 6dB coding */
10977 /* mii write 0x18 7 */
10978 /* set val [mii read 0x18] */
10979 /* mii write 0x18 [expr $val | [bits set 10 15]] */
10980 bnx2x_cl22_write(bp, phy, 0x18, 7);
10981 bnx2x_cl22_read(bp, phy, 0x18, &val);
10982 bnx2x_cl22_write(bp, phy, 0x18, val | (1<<10) | (1<<15));
10983
10984 /* This register opens the gate for the UMAC despite its name */
10985 REG_WR(bp, NIG_REG_EGRESS_EMAC0_PORT + params->port*4, 1);
10986
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000010987 /* Maximum Frame Length (RW). Defines a 14-Bit maximum frame
Yaniv Rosner6583e332011-06-14 01:34:17 +000010988 * length used by the MAC receive logic to check frames.
10989 */
10990 REG_WR(bp, umac_base + UMAC_REG_MAXFR, 0x2710);
10991}
10992
10993/******************************************************************/
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000010994/* SFX7101 PHY SECTION */
10995/******************************************************************/
10996static void bnx2x_7101_config_loopback(struct bnx2x_phy *phy,
10997 struct link_params *params)
10998{
10999 struct bnx2x *bp = params->bp;
11000 /* SFX7101_XGXS_TEST1 */
11001 bnx2x_cl45_write(bp, phy,
11002 MDIO_XS_DEVAD, MDIO_XS_SFX7101_XGXS_TEST1, 0x100);
11003}
11004
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000011005static int bnx2x_7101_config_init(struct bnx2x_phy *phy,
11006 struct link_params *params,
11007 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011008{
11009 u16 fw_ver1, fw_ver2, val;
11010 struct bnx2x *bp = params->bp;
11011 DP(NETIF_MSG_LINK, "Setting the SFX7101 LASI indication\n");
11012
11013 /* Restore normal power mode*/
11014 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000011015 MISC_REGISTERS_GPIO_OUTPUT_HIGH, params->port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011016 /* HW reset */
11017 bnx2x_ext_phy_hw_reset(bp, params->port);
Yaniv Rosner6d870c32011-01-31 04:22:20 +000011018 bnx2x_wait_reset_complete(bp, phy, params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011019
11020 bnx2x_cl45_write(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +000011021 MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL, 0x1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011022 DP(NETIF_MSG_LINK, "Setting the SFX7101 LED to blink on traffic\n");
11023 bnx2x_cl45_write(bp, phy,
11024 MDIO_PMA_DEVAD, MDIO_PMA_REG_7107_LED_CNTL, (1<<3));
11025
11026 bnx2x_ext_phy_set_pause(params, phy, vars);
11027 /* Restart autoneg */
11028 bnx2x_cl45_read(bp, phy,
11029 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, &val);
11030 val |= 0x200;
11031 bnx2x_cl45_write(bp, phy,
11032 MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, val);
11033
11034 /* Save spirom version */
11035 bnx2x_cl45_read(bp, phy,
11036 MDIO_PMA_DEVAD, MDIO_PMA_REG_7101_VER1, &fw_ver1);
11037
11038 bnx2x_cl45_read(bp, phy,
11039 MDIO_PMA_DEVAD, MDIO_PMA_REG_7101_VER2, &fw_ver2);
11040 bnx2x_save_spirom_version(bp, params->port,
11041 (u32)(fw_ver1<<16 | fw_ver2), phy->ver_addr);
11042 return 0;
11043}
11044
11045static u8 bnx2x_7101_read_status(struct bnx2x_phy *phy,
11046 struct link_params *params,
11047 struct link_vars *vars)
11048{
11049 struct bnx2x *bp = params->bp;
11050 u8 link_up;
11051 u16 val1, val2;
11052 bnx2x_cl45_read(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +000011053 MDIO_PMA_DEVAD, MDIO_PMA_LASI_STAT, &val2);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011054 bnx2x_cl45_read(bp, phy,
Yaniv Rosner60d2fe02011-06-14 01:34:38 +000011055 MDIO_PMA_DEVAD, MDIO_PMA_LASI_STAT, &val1);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011056 DP(NETIF_MSG_LINK, "10G-base-T LASI status 0x%x->0x%x\n",
11057 val2, val1);
11058 bnx2x_cl45_read(bp, phy,
11059 MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val2);
11060 bnx2x_cl45_read(bp, phy,
11061 MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val1);
11062 DP(NETIF_MSG_LINK, "10G-base-T PMA status 0x%x->0x%x\n",
11063 val2, val1);
11064 link_up = ((val1 & 4) == 4);
Yuval Mintzd2310232012-06-20 19:05:19 +000011065 /* If link is up print the AN outcome of the SFX7101 PHY */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011066 if (link_up) {
11067 bnx2x_cl45_read(bp, phy,
11068 MDIO_AN_DEVAD, MDIO_AN_REG_MASTER_STATUS,
11069 &val2);
11070 vars->line_speed = SPEED_10000;
Yaniv Rosner791f18c2011-01-18 04:33:42 +000011071 vars->duplex = DUPLEX_FULL;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011072 DP(NETIF_MSG_LINK, "SFX7101 AN status 0x%x->Master=%x\n",
11073 val2, (val2 & (1<<14)));
11074 bnx2x_ext_phy_10G_an_resolve(bp, phy, vars);
11075 bnx2x_ext_phy_resolve_fc(phy, params, vars);
Mintz Yuval9e7e8392012-02-15 02:10:24 +000011076
Yuval Mintzd2310232012-06-20 19:05:19 +000011077 /* Read LP advertised speeds */
Mintz Yuval9e7e8392012-02-15 02:10:24 +000011078 if (val2 & (1<<11))
11079 vars->link_status |=
11080 LINK_STATUS_LINK_PARTNER_10GXFD_CAPABLE;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011081 }
11082 return link_up;
11083}
11084
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000011085static int bnx2x_7101_format_ver(u32 spirom_ver, u8 *str, u16 *len)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011086{
11087 if (*len < 5)
11088 return -EINVAL;
11089 str[0] = (spirom_ver & 0xFF);
11090 str[1] = (spirom_ver & 0xFF00) >> 8;
11091 str[2] = (spirom_ver & 0xFF0000) >> 16;
11092 str[3] = (spirom_ver & 0xFF000000) >> 24;
11093 str[4] = '\0';
11094 *len -= 5;
11095 return 0;
11096}
11097
11098void bnx2x_sfx7101_sp_sw_reset(struct bnx2x *bp, struct bnx2x_phy *phy)
11099{
11100 u16 val, cnt;
11101
11102 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000011103 MDIO_PMA_DEVAD,
11104 MDIO_PMA_REG_7101_RESET, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011105
11106 for (cnt = 0; cnt < 10; cnt++) {
11107 msleep(50);
11108 /* Writes a self-clearing reset */
11109 bnx2x_cl45_write(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000011110 MDIO_PMA_DEVAD,
11111 MDIO_PMA_REG_7101_RESET,
11112 (val | (1<<15)));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011113 /* Wait for clear */
11114 bnx2x_cl45_read(bp, phy,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000011115 MDIO_PMA_DEVAD,
11116 MDIO_PMA_REG_7101_RESET, &val);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011117
11118 if ((val & (1<<15)) == 0)
11119 break;
11120 }
11121}
11122
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011123static void bnx2x_7101_hw_reset(struct bnx2x_phy *phy,
11124 struct link_params *params) {
11125 /* Low power mode is controlled by GPIO 2 */
11126 bnx2x_set_gpio(params->bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000011127 MISC_REGISTERS_GPIO_OUTPUT_LOW, params->port);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011128 /* The PHY reset is controlled by GPIO 1 */
11129 bnx2x_set_gpio(params->bp, MISC_REGISTERS_GPIO_1,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000011130 MISC_REGISTERS_GPIO_OUTPUT_LOW, params->port);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011131}
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000011132
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000011133static void bnx2x_7101_set_link_led(struct bnx2x_phy *phy,
11134 struct link_params *params, u8 mode)
11135{
11136 u16 val = 0;
11137 struct bnx2x *bp = params->bp;
11138 switch (mode) {
11139 case LED_MODE_FRONT_PANEL_OFF:
11140 case LED_MODE_OFF:
11141 val = 2;
11142 break;
11143 case LED_MODE_ON:
11144 val = 1;
11145 break;
11146 case LED_MODE_OPER:
11147 val = 0;
11148 break;
11149 }
11150 bnx2x_cl45_write(bp, phy,
11151 MDIO_PMA_DEVAD,
11152 MDIO_PMA_REG_7107_LINK_LED_CNTL,
11153 val);
11154}
11155
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011156/******************************************************************/
11157/* STATIC PHY DECLARATION */
11158/******************************************************************/
11159
Yaniv Rosner503976e2012-11-27 03:46:34 +000011160static const struct bnx2x_phy phy_null = {
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011161 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN,
11162 .addr = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011163 .def_md_devad = 0,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000011164 .flags = FLAGS_INIT_XGXS_FIRST,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011165 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11166 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11167 .mdio_ctrl = 0,
11168 .supported = 0,
11169 .media_type = ETH_PHY_NOT_PRESENT,
11170 .ver_addr = 0,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000011171 .req_flow_ctrl = 0,
11172 .req_line_speed = 0,
11173 .speed_cap_mask = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011174 .req_duplex = 0,
11175 .rsrv = 0,
11176 .config_init = (config_init_t)NULL,
11177 .read_status = (read_status_t)NULL,
11178 .link_reset = (link_reset_t)NULL,
11179 .config_loopback = (config_loopback_t)NULL,
11180 .format_fw_ver = (format_fw_ver_t)NULL,
11181 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011182 .set_link_led = (set_link_led_t)NULL,
11183 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011184};
11185
Yaniv Rosner503976e2012-11-27 03:46:34 +000011186static const struct bnx2x_phy phy_serdes = {
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011187 .type = PORT_HW_CFG_SERDES_EXT_PHY_TYPE_DIRECT,
11188 .addr = 0xff,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011189 .def_md_devad = 0,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000011190 .flags = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011191 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11192 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11193 .mdio_ctrl = 0,
11194 .supported = (SUPPORTED_10baseT_Half |
11195 SUPPORTED_10baseT_Full |
11196 SUPPORTED_100baseT_Half |
11197 SUPPORTED_100baseT_Full |
11198 SUPPORTED_1000baseT_Full |
11199 SUPPORTED_2500baseX_Full |
11200 SUPPORTED_TP |
11201 SUPPORTED_Autoneg |
11202 SUPPORTED_Pause |
11203 SUPPORTED_Asym_Pause),
Yaniv Rosner1ac9e422011-05-31 21:26:11 +000011204 .media_type = ETH_PHY_BASE_T,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011205 .ver_addr = 0,
11206 .req_flow_ctrl = 0,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000011207 .req_line_speed = 0,
11208 .speed_cap_mask = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011209 .req_duplex = 0,
11210 .rsrv = 0,
Yaniv Rosnerec146a62011-05-31 21:29:27 +000011211 .config_init = (config_init_t)bnx2x_xgxs_config_init,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011212 .read_status = (read_status_t)bnx2x_link_settings_status,
11213 .link_reset = (link_reset_t)bnx2x_int_link_reset,
11214 .config_loopback = (config_loopback_t)NULL,
11215 .format_fw_ver = (format_fw_ver_t)NULL,
11216 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011217 .set_link_led = (set_link_led_t)NULL,
11218 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011219};
11220
Yaniv Rosner503976e2012-11-27 03:46:34 +000011221static const struct bnx2x_phy phy_xgxs = {
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011222 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT,
11223 .addr = 0xff,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011224 .def_md_devad = 0,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000011225 .flags = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011226 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11227 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11228 .mdio_ctrl = 0,
11229 .supported = (SUPPORTED_10baseT_Half |
11230 SUPPORTED_10baseT_Full |
11231 SUPPORTED_100baseT_Half |
11232 SUPPORTED_100baseT_Full |
11233 SUPPORTED_1000baseT_Full |
11234 SUPPORTED_2500baseX_Full |
11235 SUPPORTED_10000baseT_Full |
11236 SUPPORTED_FIBRE |
11237 SUPPORTED_Autoneg |
11238 SUPPORTED_Pause |
11239 SUPPORTED_Asym_Pause),
Yaniv Rosner1ac9e422011-05-31 21:26:11 +000011240 .media_type = ETH_PHY_CX4,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011241 .ver_addr = 0,
11242 .req_flow_ctrl = 0,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000011243 .req_line_speed = 0,
11244 .speed_cap_mask = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011245 .req_duplex = 0,
11246 .rsrv = 0,
Yaniv Rosnerec146a62011-05-31 21:29:27 +000011247 .config_init = (config_init_t)bnx2x_xgxs_config_init,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011248 .read_status = (read_status_t)bnx2x_link_settings_status,
11249 .link_reset = (link_reset_t)bnx2x_int_link_reset,
11250 .config_loopback = (config_loopback_t)bnx2x_set_xgxs_loopback,
11251 .format_fw_ver = (format_fw_ver_t)NULL,
11252 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011253 .set_link_led = (set_link_led_t)NULL,
Yaniv Rosnera75bb002012-10-31 05:46:53 +000011254 .phy_specific_func = (phy_specific_func_t)bnx2x_xgxs_specific_func
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011255};
Yaniv Rosner503976e2012-11-27 03:46:34 +000011256static const struct bnx2x_phy phy_warpcore = {
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000011257 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT,
11258 .addr = 0xff,
11259 .def_md_devad = 0,
Yaniv Rosner8203c4b2012-11-27 03:46:33 +000011260 .flags = FLAGS_TX_ERROR_CHECK,
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000011261 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11262 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11263 .mdio_ctrl = 0,
11264 .supported = (SUPPORTED_10baseT_Half |
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000011265 SUPPORTED_10baseT_Full |
11266 SUPPORTED_100baseT_Half |
11267 SUPPORTED_100baseT_Full |
11268 SUPPORTED_1000baseT_Full |
11269 SUPPORTED_10000baseT_Full |
11270 SUPPORTED_20000baseKR2_Full |
11271 SUPPORTED_20000baseMLD2_Full |
11272 SUPPORTED_FIBRE |
11273 SUPPORTED_Autoneg |
11274 SUPPORTED_Pause |
11275 SUPPORTED_Asym_Pause),
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000011276 .media_type = ETH_PHY_UNSPECIFIED,
11277 .ver_addr = 0,
11278 .req_flow_ctrl = 0,
11279 .req_line_speed = 0,
11280 .speed_cap_mask = 0,
11281 /* req_duplex = */0,
11282 /* rsrv = */0,
11283 .config_init = (config_init_t)bnx2x_warpcore_config_init,
11284 .read_status = (read_status_t)bnx2x_warpcore_read_status,
11285 .link_reset = (link_reset_t)bnx2x_warpcore_link_reset,
11286 .config_loopback = (config_loopback_t)bnx2x_set_warpcore_loopback,
11287 .format_fw_ver = (format_fw_ver_t)NULL,
Yaniv Rosner985848f2011-07-05 01:06:48 +000011288 .hw_reset = (hw_reset_t)bnx2x_warpcore_hw_reset,
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000011289 .set_link_led = (set_link_led_t)NULL,
11290 .phy_specific_func = (phy_specific_func_t)NULL
11291};
11292
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011293
Yaniv Rosner503976e2012-11-27 03:46:34 +000011294static const struct bnx2x_phy phy_7101 = {
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011295 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101,
11296 .addr = 0xff,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011297 .def_md_devad = 0,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000011298 .flags = FLAGS_FAN_FAILURE_DET_REQ,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011299 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11300 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11301 .mdio_ctrl = 0,
11302 .supported = (SUPPORTED_10000baseT_Full |
11303 SUPPORTED_TP |
11304 SUPPORTED_Autoneg |
11305 SUPPORTED_Pause |
11306 SUPPORTED_Asym_Pause),
11307 .media_type = ETH_PHY_BASE_T,
11308 .ver_addr = 0,
11309 .req_flow_ctrl = 0,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000011310 .req_line_speed = 0,
11311 .speed_cap_mask = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011312 .req_duplex = 0,
11313 .rsrv = 0,
11314 .config_init = (config_init_t)bnx2x_7101_config_init,
11315 .read_status = (read_status_t)bnx2x_7101_read_status,
11316 .link_reset = (link_reset_t)bnx2x_common_ext_link_reset,
11317 .config_loopback = (config_loopback_t)bnx2x_7101_config_loopback,
11318 .format_fw_ver = (format_fw_ver_t)bnx2x_7101_format_ver,
11319 .hw_reset = (hw_reset_t)bnx2x_7101_hw_reset,
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000011320 .set_link_led = (set_link_led_t)bnx2x_7101_set_link_led,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011321 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011322};
Yaniv Rosner503976e2012-11-27 03:46:34 +000011323static const struct bnx2x_phy phy_8073 = {
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011324 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073,
11325 .addr = 0xff,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011326 .def_md_devad = 0,
Yaniv Rosner8203c4b2012-11-27 03:46:33 +000011327 .flags = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011328 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11329 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11330 .mdio_ctrl = 0,
11331 .supported = (SUPPORTED_10000baseT_Full |
11332 SUPPORTED_2500baseX_Full |
11333 SUPPORTED_1000baseT_Full |
11334 SUPPORTED_FIBRE |
11335 SUPPORTED_Autoneg |
11336 SUPPORTED_Pause |
11337 SUPPORTED_Asym_Pause),
Yaniv Rosner1ac9e422011-05-31 21:26:11 +000011338 .media_type = ETH_PHY_KR,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011339 .ver_addr = 0,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000011340 .req_flow_ctrl = 0,
11341 .req_line_speed = 0,
11342 .speed_cap_mask = 0,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011343 .req_duplex = 0,
11344 .rsrv = 0,
Yaniv Rosner62b29a52010-09-07 11:40:58 +000011345 .config_init = (config_init_t)bnx2x_8073_config_init,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011346 .read_status = (read_status_t)bnx2x_8073_read_status,
11347 .link_reset = (link_reset_t)bnx2x_8073_link_reset,
11348 .config_loopback = (config_loopback_t)NULL,
11349 .format_fw_ver = (format_fw_ver_t)bnx2x_format_ver,
11350 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011351 .set_link_led = (set_link_led_t)NULL,
Yaniv Rosner5c107fd2012-09-13 02:56:19 +000011352 .phy_specific_func = (phy_specific_func_t)bnx2x_8073_specific_func
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011353};
Yaniv Rosner503976e2012-11-27 03:46:34 +000011354static const struct bnx2x_phy phy_8705 = {
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011355 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705,
11356 .addr = 0xff,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011357 .def_md_devad = 0,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000011358 .flags = FLAGS_INIT_XGXS_FIRST,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011359 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11360 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11361 .mdio_ctrl = 0,
11362 .supported = (SUPPORTED_10000baseT_Full |
11363 SUPPORTED_FIBRE |
11364 SUPPORTED_Pause |
11365 SUPPORTED_Asym_Pause),
11366 .media_type = ETH_PHY_XFP_FIBER,
11367 .ver_addr = 0,
11368 .req_flow_ctrl = 0,
11369 .req_line_speed = 0,
11370 .speed_cap_mask = 0,
11371 .req_duplex = 0,
11372 .rsrv = 0,
11373 .config_init = (config_init_t)bnx2x_8705_config_init,
11374 .read_status = (read_status_t)bnx2x_8705_read_status,
11375 .link_reset = (link_reset_t)bnx2x_common_ext_link_reset,
11376 .config_loopback = (config_loopback_t)NULL,
11377 .format_fw_ver = (format_fw_ver_t)bnx2x_null_format_ver,
11378 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011379 .set_link_led = (set_link_led_t)NULL,
11380 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011381};
Yaniv Rosner503976e2012-11-27 03:46:34 +000011382static const struct bnx2x_phy phy_8706 = {
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011383 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706,
11384 .addr = 0xff,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011385 .def_md_devad = 0,
David S. Miller8decf862011-09-22 03:23:13 -040011386 .flags = FLAGS_INIT_XGXS_FIRST,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011387 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11388 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11389 .mdio_ctrl = 0,
11390 .supported = (SUPPORTED_10000baseT_Full |
11391 SUPPORTED_1000baseT_Full |
11392 SUPPORTED_FIBRE |
11393 SUPPORTED_Pause |
11394 SUPPORTED_Asym_Pause),
Yuval Mintzdbef8072012-06-20 19:05:22 +000011395 .media_type = ETH_PHY_SFPP_10G_FIBER,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011396 .ver_addr = 0,
11397 .req_flow_ctrl = 0,
11398 .req_line_speed = 0,
11399 .speed_cap_mask = 0,
11400 .req_duplex = 0,
11401 .rsrv = 0,
11402 .config_init = (config_init_t)bnx2x_8706_config_init,
11403 .read_status = (read_status_t)bnx2x_8706_read_status,
11404 .link_reset = (link_reset_t)bnx2x_common_ext_link_reset,
11405 .config_loopback = (config_loopback_t)NULL,
11406 .format_fw_ver = (format_fw_ver_t)bnx2x_format_ver,
11407 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011408 .set_link_led = (set_link_led_t)NULL,
11409 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011410};
11411
Yaniv Rosner503976e2012-11-27 03:46:34 +000011412static const struct bnx2x_phy phy_8726 = {
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011413 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726,
11414 .addr = 0xff,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000011415 .def_md_devad = 0,
Yaniv Rosner8203c4b2012-11-27 03:46:33 +000011416 .flags = (FLAGS_INIT_XGXS_FIRST |
Yaniv Rosner55098c52012-04-03 18:41:27 +000011417 FLAGS_TX_ERROR_CHECK),
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011418 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11419 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11420 .mdio_ctrl = 0,
11421 .supported = (SUPPORTED_10000baseT_Full |
11422 SUPPORTED_1000baseT_Full |
11423 SUPPORTED_Autoneg |
11424 SUPPORTED_FIBRE |
11425 SUPPORTED_Pause |
11426 SUPPORTED_Asym_Pause),
Yaniv Rosner1ac9e422011-05-31 21:26:11 +000011427 .media_type = ETH_PHY_NOT_PRESENT,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011428 .ver_addr = 0,
11429 .req_flow_ctrl = 0,
11430 .req_line_speed = 0,
11431 .speed_cap_mask = 0,
11432 .req_duplex = 0,
11433 .rsrv = 0,
11434 .config_init = (config_init_t)bnx2x_8726_config_init,
11435 .read_status = (read_status_t)bnx2x_8726_read_status,
11436 .link_reset = (link_reset_t)bnx2x_8726_link_reset,
11437 .config_loopback = (config_loopback_t)bnx2x_8726_config_loopback,
11438 .format_fw_ver = (format_fw_ver_t)bnx2x_format_ver,
11439 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011440 .set_link_led = (set_link_led_t)NULL,
11441 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011442};
11443
Yaniv Rosner503976e2012-11-27 03:46:34 +000011444static const struct bnx2x_phy phy_8727 = {
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011445 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727,
11446 .addr = 0xff,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011447 .def_md_devad = 0,
Yaniv Rosner55098c52012-04-03 18:41:27 +000011448 .flags = (FLAGS_FAN_FAILURE_DET_REQ |
11449 FLAGS_TX_ERROR_CHECK),
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011450 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11451 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11452 .mdio_ctrl = 0,
11453 .supported = (SUPPORTED_10000baseT_Full |
11454 SUPPORTED_1000baseT_Full |
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011455 SUPPORTED_FIBRE |
11456 SUPPORTED_Pause |
11457 SUPPORTED_Asym_Pause),
Yaniv Rosner1ac9e422011-05-31 21:26:11 +000011458 .media_type = ETH_PHY_NOT_PRESENT,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011459 .ver_addr = 0,
11460 .req_flow_ctrl = 0,
11461 .req_line_speed = 0,
11462 .speed_cap_mask = 0,
11463 .req_duplex = 0,
11464 .rsrv = 0,
11465 .config_init = (config_init_t)bnx2x_8727_config_init,
11466 .read_status = (read_status_t)bnx2x_8727_read_status,
11467 .link_reset = (link_reset_t)bnx2x_8727_link_reset,
11468 .config_loopback = (config_loopback_t)NULL,
11469 .format_fw_ver = (format_fw_ver_t)bnx2x_format_ver,
11470 .hw_reset = (hw_reset_t)bnx2x_8727_hw_reset,
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000011471 .set_link_led = (set_link_led_t)bnx2x_8727_set_link_led,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011472 .phy_specific_func = (phy_specific_func_t)bnx2x_8727_specific_func
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011473};
Yaniv Rosner503976e2012-11-27 03:46:34 +000011474static const struct bnx2x_phy phy_8481 = {
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011475 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8481,
11476 .addr = 0xff,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000011477 .def_md_devad = 0,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011478 .flags = FLAGS_FAN_FAILURE_DET_REQ |
11479 FLAGS_REARM_LATCH_SIGNAL,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011480 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11481 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11482 .mdio_ctrl = 0,
11483 .supported = (SUPPORTED_10baseT_Half |
11484 SUPPORTED_10baseT_Full |
11485 SUPPORTED_100baseT_Half |
11486 SUPPORTED_100baseT_Full |
11487 SUPPORTED_1000baseT_Full |
11488 SUPPORTED_10000baseT_Full |
11489 SUPPORTED_TP |
11490 SUPPORTED_Autoneg |
11491 SUPPORTED_Pause |
11492 SUPPORTED_Asym_Pause),
11493 .media_type = ETH_PHY_BASE_T,
11494 .ver_addr = 0,
11495 .req_flow_ctrl = 0,
11496 .req_line_speed = 0,
11497 .speed_cap_mask = 0,
11498 .req_duplex = 0,
11499 .rsrv = 0,
11500 .config_init = (config_init_t)bnx2x_8481_config_init,
11501 .read_status = (read_status_t)bnx2x_848xx_read_status,
11502 .link_reset = (link_reset_t)bnx2x_8481_link_reset,
11503 .config_loopback = (config_loopback_t)NULL,
11504 .format_fw_ver = (format_fw_ver_t)bnx2x_848xx_format_ver,
11505 .hw_reset = (hw_reset_t)bnx2x_8481_hw_reset,
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000011506 .set_link_led = (set_link_led_t)bnx2x_848xx_set_link_led,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011507 .phy_specific_func = (phy_specific_func_t)NULL
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011508};
11509
Yaniv Rosner503976e2012-11-27 03:46:34 +000011510static const struct bnx2x_phy phy_84823 = {
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011511 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84823,
11512 .addr = 0xff,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000011513 .def_md_devad = 0,
Yaniv Rosner55098c52012-04-03 18:41:27 +000011514 .flags = (FLAGS_FAN_FAILURE_DET_REQ |
11515 FLAGS_REARM_LATCH_SIGNAL |
11516 FLAGS_TX_ERROR_CHECK),
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011517 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11518 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11519 .mdio_ctrl = 0,
11520 .supported = (SUPPORTED_10baseT_Half |
11521 SUPPORTED_10baseT_Full |
11522 SUPPORTED_100baseT_Half |
11523 SUPPORTED_100baseT_Full |
11524 SUPPORTED_1000baseT_Full |
11525 SUPPORTED_10000baseT_Full |
11526 SUPPORTED_TP |
11527 SUPPORTED_Autoneg |
11528 SUPPORTED_Pause |
11529 SUPPORTED_Asym_Pause),
11530 .media_type = ETH_PHY_BASE_T,
11531 .ver_addr = 0,
11532 .req_flow_ctrl = 0,
11533 .req_line_speed = 0,
11534 .speed_cap_mask = 0,
11535 .req_duplex = 0,
11536 .rsrv = 0,
11537 .config_init = (config_init_t)bnx2x_848x3_config_init,
11538 .read_status = (read_status_t)bnx2x_848xx_read_status,
11539 .link_reset = (link_reset_t)bnx2x_848x3_link_reset,
11540 .config_loopback = (config_loopback_t)NULL,
11541 .format_fw_ver = (format_fw_ver_t)bnx2x_848xx_format_ver,
11542 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000011543 .set_link_led = (set_link_led_t)bnx2x_848xx_set_link_led,
Yaniv Rosner5c107fd2012-09-13 02:56:19 +000011544 .phy_specific_func = (phy_specific_func_t)bnx2x_848xx_specific_func
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011545};
11546
Yaniv Rosner503976e2012-11-27 03:46:34 +000011547static const struct bnx2x_phy phy_84833 = {
Yaniv Rosnerc87bca12011-01-31 04:22:41 +000011548 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833,
11549 .addr = 0xff,
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000011550 .def_md_devad = 0,
Yaniv Rosner55098c52012-04-03 18:41:27 +000011551 .flags = (FLAGS_FAN_FAILURE_DET_REQ |
11552 FLAGS_REARM_LATCH_SIGNAL |
Yuval Mintzf6b6eb62012-09-10 05:51:07 +000011553 FLAGS_TX_ERROR_CHECK),
Yaniv Rosnerc87bca12011-01-31 04:22:41 +000011554 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11555 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11556 .mdio_ctrl = 0,
Yaniv Rosner0520e632011-07-05 01:06:59 +000011557 .supported = (SUPPORTED_100baseT_Half |
Yaniv Rosnerc87bca12011-01-31 04:22:41 +000011558 SUPPORTED_100baseT_Full |
11559 SUPPORTED_1000baseT_Full |
11560 SUPPORTED_10000baseT_Full |
11561 SUPPORTED_TP |
11562 SUPPORTED_Autoneg |
11563 SUPPORTED_Pause |
11564 SUPPORTED_Asym_Pause),
11565 .media_type = ETH_PHY_BASE_T,
11566 .ver_addr = 0,
11567 .req_flow_ctrl = 0,
11568 .req_line_speed = 0,
11569 .speed_cap_mask = 0,
11570 .req_duplex = 0,
11571 .rsrv = 0,
11572 .config_init = (config_init_t)bnx2x_848x3_config_init,
11573 .read_status = (read_status_t)bnx2x_848xx_read_status,
11574 .link_reset = (link_reset_t)bnx2x_848x3_link_reset,
11575 .config_loopback = (config_loopback_t)NULL,
11576 .format_fw_ver = (format_fw_ver_t)bnx2x_848xx_format_ver,
Yaniv Rosner985848f2011-07-05 01:06:48 +000011577 .hw_reset = (hw_reset_t)bnx2x_84833_hw_reset_phy,
Yaniv Rosnerc87bca12011-01-31 04:22:41 +000011578 .set_link_led = (set_link_led_t)bnx2x_848xx_set_link_led,
Yaniv Rosner5c107fd2012-09-13 02:56:19 +000011579 .phy_specific_func = (phy_specific_func_t)bnx2x_848xx_specific_func
Yaniv Rosnerc87bca12011-01-31 04:22:41 +000011580};
11581
Yaniv Rosner0f6bb032012-11-27 03:46:32 +000011582static const struct bnx2x_phy phy_84834 = {
11583 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84834,
11584 .addr = 0xff,
11585 .def_md_devad = 0,
11586 .flags = FLAGS_FAN_FAILURE_DET_REQ |
11587 FLAGS_REARM_LATCH_SIGNAL,
11588 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11589 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11590 .mdio_ctrl = 0,
11591 .supported = (SUPPORTED_100baseT_Half |
11592 SUPPORTED_100baseT_Full |
11593 SUPPORTED_1000baseT_Full |
11594 SUPPORTED_10000baseT_Full |
11595 SUPPORTED_TP |
11596 SUPPORTED_Autoneg |
11597 SUPPORTED_Pause |
11598 SUPPORTED_Asym_Pause),
11599 .media_type = ETH_PHY_BASE_T,
11600 .ver_addr = 0,
11601 .req_flow_ctrl = 0,
11602 .req_line_speed = 0,
11603 .speed_cap_mask = 0,
11604 .req_duplex = 0,
11605 .rsrv = 0,
11606 .config_init = (config_init_t)bnx2x_848x3_config_init,
11607 .read_status = (read_status_t)bnx2x_848xx_read_status,
11608 .link_reset = (link_reset_t)bnx2x_848x3_link_reset,
11609 .config_loopback = (config_loopback_t)NULL,
11610 .format_fw_ver = (format_fw_ver_t)bnx2x_848xx_format_ver,
11611 .hw_reset = (hw_reset_t)bnx2x_84833_hw_reset_phy,
11612 .set_link_led = (set_link_led_t)bnx2x_848xx_set_link_led,
11613 .phy_specific_func = (phy_specific_func_t)bnx2x_848xx_specific_func
11614};
11615
Yaniv Rosner503976e2012-11-27 03:46:34 +000011616static const struct bnx2x_phy phy_54618se = {
Yaniv Rosner52c4d6c2011-07-05 01:06:34 +000011617 .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54618SE,
Yaniv Rosner6583e332011-06-14 01:34:17 +000011618 .addr = 0xff,
11619 .def_md_devad = 0,
11620 .flags = FLAGS_INIT_XGXS_FIRST,
11621 .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11622 .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11623 .mdio_ctrl = 0,
11624 .supported = (SUPPORTED_10baseT_Half |
11625 SUPPORTED_10baseT_Full |
11626 SUPPORTED_100baseT_Half |
11627 SUPPORTED_100baseT_Full |
11628 SUPPORTED_1000baseT_Full |
11629 SUPPORTED_TP |
11630 SUPPORTED_Autoneg |
11631 SUPPORTED_Pause |
11632 SUPPORTED_Asym_Pause),
11633 .media_type = ETH_PHY_BASE_T,
11634 .ver_addr = 0,
11635 .req_flow_ctrl = 0,
11636 .req_line_speed = 0,
11637 .speed_cap_mask = 0,
11638 /* req_duplex = */0,
11639 /* rsrv = */0,
Yaniv Rosner52c4d6c2011-07-05 01:06:34 +000011640 .config_init = (config_init_t)bnx2x_54618se_config_init,
11641 .read_status = (read_status_t)bnx2x_54618se_read_status,
11642 .link_reset = (link_reset_t)bnx2x_54618se_link_reset,
11643 .config_loopback = (config_loopback_t)bnx2x_54618se_config_loopback,
Yaniv Rosner6583e332011-06-14 01:34:17 +000011644 .format_fw_ver = (format_fw_ver_t)NULL,
11645 .hw_reset = (hw_reset_t)NULL,
Yaniv Rosner1d125bd2011-11-23 03:54:08 +000011646 .set_link_led = (set_link_led_t)bnx2x_5461x_set_link_led,
Yaniv Rosner5c107fd2012-09-13 02:56:19 +000011647 .phy_specific_func = (phy_specific_func_t)bnx2x_54618se_specific_func
Yaniv Rosner6583e332011-06-14 01:34:17 +000011648};
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011649/*****************************************************************/
11650/* */
11651/* Populate the phy according. Main function: bnx2x_populate_phy */
11652/* */
11653/*****************************************************************/
11654
11655static void bnx2x_populate_preemphasis(struct bnx2x *bp, u32 shmem_base,
11656 struct bnx2x_phy *phy, u8 port,
11657 u8 phy_index)
11658{
11659 /* Get the 4 lanes xgxs config rx and tx */
11660 u32 rx = 0, tx = 0, i;
11661 for (i = 0; i < 2; i++) {
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000011662 /* INT_PHY and EXT_PHY1 share the same value location in
11663 * the shmem. When num_phys is greater than 1, than this value
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011664 * applies only to EXT_PHY1
11665 */
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011666 if (phy_index == INT_PHY || phy_index == EXT_PHY1) {
11667 rx = REG_RD(bp, shmem_base +
11668 offsetof(struct shmem_region,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000011669 dev_info.port_hw_config[port].xgxs_config_rx[i<<1]));
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011670
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011671 tx = REG_RD(bp, shmem_base +
11672 offsetof(struct shmem_region,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000011673 dev_info.port_hw_config[port].xgxs_config_tx[i<<1]));
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011674 } else {
11675 rx = REG_RD(bp, shmem_base +
11676 offsetof(struct shmem_region,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000011677 dev_info.port_hw_config[port].xgxs_config2_rx[i<<1]));
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011678
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011679 tx = REG_RD(bp, shmem_base +
11680 offsetof(struct shmem_region,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000011681 dev_info.port_hw_config[port].xgxs_config2_rx[i<<1]));
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011682 }
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011683
11684 phy->rx_preemphasis[i << 1] = ((rx>>16) & 0xffff);
11685 phy->rx_preemphasis[(i << 1) + 1] = (rx & 0xffff);
11686
11687 phy->tx_preemphasis[i << 1] = ((tx>>16) & 0xffff);
11688 phy->tx_preemphasis[(i << 1) + 1] = (tx & 0xffff);
11689 }
11690}
11691
Yaniv Rosnere10bc842010-09-07 11:40:50 +000011692static u32 bnx2x_get_ext_phy_config(struct bnx2x *bp, u32 shmem_base,
11693 u8 phy_index, u8 port)
11694{
11695 u32 ext_phy_config = 0;
11696 switch (phy_index) {
11697 case EXT_PHY1:
11698 ext_phy_config = REG_RD(bp, shmem_base +
11699 offsetof(struct shmem_region,
11700 dev_info.port_hw_config[port].external_phy_config));
11701 break;
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011702 case EXT_PHY2:
11703 ext_phy_config = REG_RD(bp, shmem_base +
11704 offsetof(struct shmem_region,
11705 dev_info.port_hw_config[port].external_phy_config2));
11706 break;
Yaniv Rosnere10bc842010-09-07 11:40:50 +000011707 default:
11708 DP(NETIF_MSG_LINK, "Invalid phy_index %d\n", phy_index);
11709 return -EINVAL;
11710 }
11711
11712 return ext_phy_config;
11713}
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000011714static int bnx2x_populate_int_phy(struct bnx2x *bp, u32 shmem_base, u8 port,
11715 struct bnx2x_phy *phy)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011716{
11717 u32 phy_addr;
11718 u32 chip_id;
11719 u32 switch_cfg = (REG_RD(bp, shmem_base +
11720 offsetof(struct shmem_region,
11721 dev_info.port_feature_config[port].link_config)) &
11722 PORT_FEATURE_CONNECTED_SWITCH_MASK);
Yaniv Rosnerec15b892011-11-28 00:49:49 +000011723 chip_id = (REG_RD(bp, MISC_REG_CHIP_NUM) << 16) |
11724 ((REG_RD(bp, MISC_REG_CHIP_REV) & 0xf) << 12);
11725
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000011726 DP(NETIF_MSG_LINK, ":chip_id = 0x%x\n", chip_id);
11727 if (USES_WARPCORE(bp)) {
11728 u32 serdes_net_if;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011729 phy_addr = REG_RD(bp,
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000011730 MISC_REG_WC0_CTRL_PHY_ADDR);
11731 *phy = phy_warpcore;
11732 if (REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR) == 0x3)
11733 phy->flags |= FLAGS_4_PORT_MODE;
11734 else
11735 phy->flags &= ~FLAGS_4_PORT_MODE;
11736 /* Check Dual mode */
11737 serdes_net_if = (REG_RD(bp, shmem_base +
11738 offsetof(struct shmem_region, dev_info.
11739 port_hw_config[port].default_cfg)) &
11740 PORT_HW_CFG_NET_SERDES_IF_MASK);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000011741 /* Set the appropriate supported and flags indications per
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000011742 * interface type of the chip
11743 */
11744 switch (serdes_net_if) {
11745 case PORT_HW_CFG_NET_SERDES_IF_SGMII:
11746 phy->supported &= (SUPPORTED_10baseT_Half |
11747 SUPPORTED_10baseT_Full |
11748 SUPPORTED_100baseT_Half |
11749 SUPPORTED_100baseT_Full |
11750 SUPPORTED_1000baseT_Full |
11751 SUPPORTED_FIBRE |
11752 SUPPORTED_Autoneg |
11753 SUPPORTED_Pause |
11754 SUPPORTED_Asym_Pause);
11755 phy->media_type = ETH_PHY_BASE_T;
11756 break;
11757 case PORT_HW_CFG_NET_SERDES_IF_XFI:
Yaniv Rosner03c31482012-10-31 05:46:57 +000011758 phy->supported &= (SUPPORTED_1000baseT_Full |
11759 SUPPORTED_10000baseT_Full |
11760 SUPPORTED_FIBRE |
11761 SUPPORTED_Pause |
11762 SUPPORTED_Asym_Pause);
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000011763 phy->media_type = ETH_PHY_XFP_FIBER;
11764 break;
11765 case PORT_HW_CFG_NET_SERDES_IF_SFI:
11766 phy->supported &= (SUPPORTED_1000baseT_Full |
11767 SUPPORTED_10000baseT_Full |
11768 SUPPORTED_FIBRE |
11769 SUPPORTED_Pause |
11770 SUPPORTED_Asym_Pause);
Yuval Mintzdbef8072012-06-20 19:05:22 +000011771 phy->media_type = ETH_PHY_SFPP_10G_FIBER;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000011772 break;
11773 case PORT_HW_CFG_NET_SERDES_IF_KR:
11774 phy->media_type = ETH_PHY_KR;
11775 phy->supported &= (SUPPORTED_1000baseT_Full |
11776 SUPPORTED_10000baseT_Full |
11777 SUPPORTED_FIBRE |
11778 SUPPORTED_Autoneg |
11779 SUPPORTED_Pause |
11780 SUPPORTED_Asym_Pause);
11781 break;
11782 case PORT_HW_CFG_NET_SERDES_IF_DXGXS:
11783 phy->media_type = ETH_PHY_KR;
11784 phy->flags |= FLAGS_WC_DUAL_MODE;
11785 phy->supported &= (SUPPORTED_20000baseMLD2_Full |
11786 SUPPORTED_FIBRE |
11787 SUPPORTED_Pause |
11788 SUPPORTED_Asym_Pause);
11789 break;
11790 case PORT_HW_CFG_NET_SERDES_IF_KR2:
11791 phy->media_type = ETH_PHY_KR;
11792 phy->flags |= FLAGS_WC_DUAL_MODE;
11793 phy->supported &= (SUPPORTED_20000baseKR2_Full |
Yaniv Rosner4e7b4992012-11-27 03:46:29 +000011794 SUPPORTED_Autoneg |
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000011795 SUPPORTED_FIBRE |
11796 SUPPORTED_Pause |
11797 SUPPORTED_Asym_Pause);
Yaniv Rosner4e7b4992012-11-27 03:46:29 +000011798 phy->flags &= ~FLAGS_TX_ERROR_CHECK;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000011799 break;
11800 default:
11801 DP(NETIF_MSG_LINK, "Unknown WC interface type 0x%x\n",
11802 serdes_net_if);
11803 break;
11804 }
11805
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000011806 /* Enable MDC/MDIO work-around for E3 A0 since free running MDC
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000011807 * was not set as expected. For B0, ECO will be enabled so there
11808 * won't be an issue there
11809 */
11810 if (CHIP_REV(bp) == CHIP_REV_Ax)
11811 phy->flags |= FLAGS_MDC_MDIO_WA;
Yaniv Rosner157fa282011-08-02 22:59:32 +000011812 else
11813 phy->flags |= FLAGS_MDC_MDIO_WA_B0;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000011814 } else {
11815 switch (switch_cfg) {
11816 case SWITCH_CFG_1G:
11817 phy_addr = REG_RD(bp,
11818 NIG_REG_SERDES0_CTRL_PHY_ADDR +
11819 port * 0x10);
11820 *phy = phy_serdes;
11821 break;
11822 case SWITCH_CFG_10G:
11823 phy_addr = REG_RD(bp,
11824 NIG_REG_XGXS0_CTRL_PHY_ADDR +
11825 port * 0x18);
11826 *phy = phy_xgxs;
11827 break;
11828 default:
11829 DP(NETIF_MSG_LINK, "Invalid switch_cfg\n");
11830 return -EINVAL;
11831 }
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011832 }
11833 phy->addr = (u8)phy_addr;
11834 phy->mdio_ctrl = bnx2x_get_emac_base(bp,
Yaniv Rosnerc18aa152010-09-07 11:41:07 +000011835 SHARED_HW_CFG_MDC_MDIO_ACCESS1_BOTH,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011836 port);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000011837 if (CHIP_IS_E2(bp))
11838 phy->def_md_devad = E2_DEFAULT_PHY_DEV_ADDR;
11839 else
11840 phy->def_md_devad = DEFAULT_PHY_DEV_ADDR;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011841
11842 DP(NETIF_MSG_LINK, "Internal phy port=%d, addr=0x%x, mdio_ctl=0x%x\n",
11843 port, phy->addr, phy->mdio_ctrl);
11844
11845 bnx2x_populate_preemphasis(bp, shmem_base, phy, port, INT_PHY);
11846 return 0;
11847}
Yaniv Rosnere10bc842010-09-07 11:40:50 +000011848
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000011849static int bnx2x_populate_ext_phy(struct bnx2x *bp,
11850 u8 phy_index,
11851 u32 shmem_base,
11852 u32 shmem2_base,
11853 u8 port,
11854 struct bnx2x_phy *phy)
Yaniv Rosnere10bc842010-09-07 11:40:50 +000011855{
Yaniv Rosnerc18aa152010-09-07 11:41:07 +000011856 u32 ext_phy_config, phy_type, config2;
11857 u32 mdc_mdio_access = SHARED_HW_CFG_MDC_MDIO_ACCESS1_BOTH;
Yaniv Rosnere10bc842010-09-07 11:40:50 +000011858 ext_phy_config = bnx2x_get_ext_phy_config(bp, shmem_base,
11859 phy_index, port);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011860 phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
11861 /* Select the phy type */
11862 switch (phy_type) {
11863 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073:
Yaniv Rosnerc18aa152010-09-07 11:41:07 +000011864 mdc_mdio_access = SHARED_HW_CFG_MDC_MDIO_ACCESS1_SWAPPED;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011865 *phy = phy_8073;
11866 break;
11867 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705:
11868 *phy = phy_8705;
11869 break;
11870 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706:
11871 *phy = phy_8706;
11872 break;
11873 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
Yaniv Rosnerc18aa152010-09-07 11:41:07 +000011874 mdc_mdio_access = SHARED_HW_CFG_MDC_MDIO_ACCESS1_EMAC1;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011875 *phy = phy_8726;
11876 break;
11877 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727_NOC:
11878 /* BCM8727_NOC => BCM8727 no over current */
Yaniv Rosnerc18aa152010-09-07 11:41:07 +000011879 mdc_mdio_access = SHARED_HW_CFG_MDC_MDIO_ACCESS1_EMAC1;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011880 *phy = phy_8727;
11881 phy->flags |= FLAGS_NOC;
11882 break;
Yaniv Rosnere4d78f12011-05-31 21:25:55 +000011883 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8722:
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011884 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
Yaniv Rosnerc18aa152010-09-07 11:41:07 +000011885 mdc_mdio_access = SHARED_HW_CFG_MDC_MDIO_ACCESS1_EMAC1;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011886 *phy = phy_8727;
11887 break;
11888 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8481:
11889 *phy = phy_8481;
11890 break;
11891 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84823:
11892 *phy = phy_84823;
11893 break;
Yaniv Rosnerc87bca12011-01-31 04:22:41 +000011894 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833:
11895 *phy = phy_84833;
11896 break;
Yaniv Rosner0f6bb032012-11-27 03:46:32 +000011897 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84834:
11898 *phy = phy_84834;
11899 break;
Yaniv Rosner3756a892011-08-23 06:33:24 +000011900 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54616:
Yaniv Rosner52c4d6c2011-07-05 01:06:34 +000011901 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54618SE:
11902 *phy = phy_54618se;
Yuval Mintz26964bb2012-09-10 05:51:08 +000011903 if (phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54618SE)
11904 phy->flags |= FLAGS_EEE;
Yaniv Rosner6583e332011-06-14 01:34:17 +000011905 break;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011906 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101:
11907 *phy = phy_7101;
11908 break;
11909 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE:
11910 *phy = phy_null;
11911 return -EINVAL;
11912 default:
11913 *phy = phy_null;
Yaniv Rosner6db51932011-11-28 00:49:50 +000011914 /* In case external PHY wasn't found */
11915 if ((phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT) &&
11916 (phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
11917 return -EINVAL;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011918 return 0;
11919 }
11920
Yaniv Rosnere10bc842010-09-07 11:40:50 +000011921 phy->addr = XGXS_EXT_PHY_ADDR(ext_phy_config);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011922 bnx2x_populate_preemphasis(bp, shmem_base, phy, port, phy_index);
Yaniv Rosner62b29a52010-09-07 11:40:58 +000011923
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000011924 /* The shmem address of the phy version is located on different
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +000011925 * structures. In case this structure is too old, do not set
11926 * the address
11927 */
Yaniv Rosnerc18aa152010-09-07 11:41:07 +000011928 config2 = REG_RD(bp, shmem_base + offsetof(struct shmem_region,
11929 dev_info.shared_hw_config.config2));
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011930 if (phy_index == EXT_PHY1) {
11931 phy->ver_addr = shmem_base + offsetof(struct shmem_region,
11932 port_mb[port].ext_phy_fw_version);
Yaniv Rosnerc18aa152010-09-07 11:41:07 +000011933
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000011934 /* Check specific mdc mdio settings */
11935 if (config2 & SHARED_HW_CFG_MDC_MDIO_ACCESS1_MASK)
11936 mdc_mdio_access = config2 &
11937 SHARED_HW_CFG_MDC_MDIO_ACCESS1_MASK;
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011938 } else {
11939 u32 size = REG_RD(bp, shmem2_base);
Yaniv Rosnerc18aa152010-09-07 11:41:07 +000011940
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011941 if (size >
11942 offsetof(struct shmem2_region, ext_phy_fw_version2)) {
11943 phy->ver_addr = shmem2_base +
11944 offsetof(struct shmem2_region,
11945 ext_phy_fw_version2[port]);
11946 }
11947 /* Check specific mdc mdio settings */
11948 if (config2 & SHARED_HW_CFG_MDC_MDIO_ACCESS2_MASK)
11949 mdc_mdio_access = (config2 &
11950 SHARED_HW_CFG_MDC_MDIO_ACCESS2_MASK) >>
11951 (SHARED_HW_CFG_MDC_MDIO_ACCESS2_SHIFT -
11952 SHARED_HW_CFG_MDC_MDIO_ACCESS1_SHIFT);
11953 }
Yaniv Rosnerc18aa152010-09-07 11:41:07 +000011954 phy->mdio_ctrl = bnx2x_get_emac_base(bp, mdc_mdio_access, port);
11955
Yaniv Rosner0f6bb032012-11-27 03:46:32 +000011956 if (((phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833) ||
11957 (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84834)) &&
Yaniv Rosner75318322012-01-17 02:33:27 +000011958 (phy->ver_addr)) {
Yaniv Rosner0f6bb032012-11-27 03:46:32 +000011959 /* Remove 100Mb link supported for BCM84833/4 when phy fw
Yaniv Rosner75318322012-01-17 02:33:27 +000011960 * version lower than or equal to 1.39
11961 */
11962 u32 raw_ver = REG_RD(bp, phy->ver_addr);
11963 if (((raw_ver & 0x7F) <= 39) &&
11964 (((raw_ver & 0xF80) >> 7) <= 1))
11965 phy->supported &= ~(SUPPORTED_100baseT_Half |
11966 SUPPORTED_100baseT_Full);
11967 }
11968
Yaniv Rosnerc18aa152010-09-07 11:41:07 +000011969 DP(NETIF_MSG_LINK, "phy_type 0x%x port %d found in index %d\n",
11970 phy_type, port, phy_index);
11971 DP(NETIF_MSG_LINK, " addr=0x%x, mdio_ctl=0x%x\n",
11972 phy->addr, phy->mdio_ctrl);
Yaniv Rosnere10bc842010-09-07 11:40:50 +000011973 return 0;
11974}
11975
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000011976static int bnx2x_populate_phy(struct bnx2x *bp, u8 phy_index, u32 shmem_base,
11977 u32 shmem2_base, u8 port, struct bnx2x_phy *phy)
Yaniv Rosnere10bc842010-09-07 11:40:50 +000011978{
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000011979 int status = 0;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011980 phy->type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN;
11981 if (phy_index == INT_PHY)
11982 return bnx2x_populate_int_phy(bp, shmem_base, port, phy);
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011983 status = bnx2x_populate_ext_phy(bp, phy_index, shmem_base, shmem2_base,
Yaniv Rosnere10bc842010-09-07 11:40:50 +000011984 port, phy);
11985 return status;
11986}
11987
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011988static void bnx2x_phy_def_cfg(struct link_params *params,
11989 struct bnx2x_phy *phy,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011990 u8 phy_index)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000011991{
11992 struct bnx2x *bp = params->bp;
11993 u32 link_config;
11994 /* Populate the default phy configuration for MF mode */
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011995 if (phy_index == EXT_PHY2) {
11996 link_config = REG_RD(bp, params->shmem_base +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000011997 offsetof(struct shmem_region, dev_info.
Yaniv Rosnera22f0782010-09-07 11:41:20 +000011998 port_feature_config[params->port].link_config2));
11999 phy->speed_cap_mask = REG_RD(bp, params->shmem_base +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012000 offsetof(struct shmem_region,
12001 dev_info.
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012002 port_hw_config[params->port].speed_capability_mask2));
12003 } else {
12004 link_config = REG_RD(bp, params->shmem_base +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012005 offsetof(struct shmem_region, dev_info.
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012006 port_feature_config[params->port].link_config));
12007 phy->speed_cap_mask = REG_RD(bp, params->shmem_base +
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012008 offsetof(struct shmem_region,
12009 dev_info.
12010 port_hw_config[params->port].speed_capability_mask));
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012011 }
Joe Perches94f05b02011-08-14 12:16:20 +000012012 DP(NETIF_MSG_LINK,
12013 "Default config phy idx %x cfg 0x%x speed_cap_mask 0x%x\n",
12014 phy_index, link_config, phy->speed_cap_mask);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000012015
12016 phy->req_duplex = DUPLEX_FULL;
12017 switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
12018 case PORT_FEATURE_LINK_SPEED_10M_HALF:
12019 phy->req_duplex = DUPLEX_HALF;
12020 case PORT_FEATURE_LINK_SPEED_10M_FULL:
12021 phy->req_line_speed = SPEED_10;
12022 break;
12023 case PORT_FEATURE_LINK_SPEED_100M_HALF:
12024 phy->req_duplex = DUPLEX_HALF;
12025 case PORT_FEATURE_LINK_SPEED_100M_FULL:
12026 phy->req_line_speed = SPEED_100;
12027 break;
12028 case PORT_FEATURE_LINK_SPEED_1G:
12029 phy->req_line_speed = SPEED_1000;
12030 break;
12031 case PORT_FEATURE_LINK_SPEED_2_5G:
12032 phy->req_line_speed = SPEED_2500;
12033 break;
12034 case PORT_FEATURE_LINK_SPEED_10G_CX4:
12035 phy->req_line_speed = SPEED_10000;
12036 break;
12037 default:
12038 phy->req_line_speed = SPEED_AUTO_NEG;
12039 break;
12040 }
12041
12042 switch (link_config & PORT_FEATURE_FLOW_CONTROL_MASK) {
12043 case PORT_FEATURE_FLOW_CONTROL_AUTO:
12044 phy->req_flow_ctrl = BNX2X_FLOW_CTRL_AUTO;
12045 break;
12046 case PORT_FEATURE_FLOW_CONTROL_TX:
12047 phy->req_flow_ctrl = BNX2X_FLOW_CTRL_TX;
12048 break;
12049 case PORT_FEATURE_FLOW_CONTROL_RX:
12050 phy->req_flow_ctrl = BNX2X_FLOW_CTRL_RX;
12051 break;
12052 case PORT_FEATURE_FLOW_CONTROL_BOTH:
12053 phy->req_flow_ctrl = BNX2X_FLOW_CTRL_BOTH;
12054 break;
12055 default:
12056 phy->req_flow_ctrl = BNX2X_FLOW_CTRL_NONE;
12057 break;
12058 }
12059}
12060
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012061u32 bnx2x_phy_selection(struct link_params *params)
12062{
12063 u32 phy_config_swapped, prio_cfg;
12064 u32 return_cfg = PORT_HW_CFG_PHY_SELECTION_HARDWARE_DEFAULT;
12065
12066 phy_config_swapped = params->multi_phy_config &
12067 PORT_HW_CFG_PHY_SWAPPED_ENABLED;
12068
12069 prio_cfg = params->multi_phy_config &
12070 PORT_HW_CFG_PHY_SELECTION_MASK;
12071
12072 if (phy_config_swapped) {
12073 switch (prio_cfg) {
12074 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY_PRIORITY:
12075 return_cfg = PORT_HW_CFG_PHY_SELECTION_SECOND_PHY_PRIORITY;
12076 break;
12077 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY_PRIORITY:
12078 return_cfg = PORT_HW_CFG_PHY_SELECTION_FIRST_PHY_PRIORITY;
12079 break;
12080 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY:
12081 return_cfg = PORT_HW_CFG_PHY_SELECTION_FIRST_PHY;
12082 break;
12083 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY:
12084 return_cfg = PORT_HW_CFG_PHY_SELECTION_SECOND_PHY;
12085 break;
12086 }
12087 } else
12088 return_cfg = prio_cfg;
12089
12090 return return_cfg;
12091}
12092
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000012093int bnx2x_phy_probe(struct link_params *params)
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000012094{
Yaniv Rosner2f751a82011-11-28 00:49:52 +000012095 u8 phy_index, actual_phy_idx;
Yaniv Rosner1ac9e422011-05-31 21:26:11 +000012096 u32 phy_config_swapped, sync_offset, media_types;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000012097 struct bnx2x *bp = params->bp;
12098 struct bnx2x_phy *phy;
12099 params->num_phys = 0;
12100 DP(NETIF_MSG_LINK, "Begin phy probe\n");
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012101 phy_config_swapped = params->multi_phy_config &
12102 PORT_HW_CFG_PHY_SWAPPED_ENABLED;
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000012103
12104 for (phy_index = INT_PHY; phy_index < MAX_PHYS;
12105 phy_index++) {
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000012106 actual_phy_idx = phy_index;
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012107 if (phy_config_swapped) {
12108 if (phy_index == EXT_PHY1)
12109 actual_phy_idx = EXT_PHY2;
12110 else if (phy_index == EXT_PHY2)
12111 actual_phy_idx = EXT_PHY1;
12112 }
12113 DP(NETIF_MSG_LINK, "phy_config_swapped %x, phy_index %x,"
12114 " actual_phy_idx %x\n", phy_config_swapped,
12115 phy_index, actual_phy_idx);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000012116 phy = &params->phy[actual_phy_idx];
12117 if (bnx2x_populate_phy(bp, phy_index, params->shmem_base,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012118 params->shmem2_base, params->port,
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000012119 phy) != 0) {
12120 params->num_phys = 0;
12121 DP(NETIF_MSG_LINK, "phy probe failed in phy index %d\n",
12122 phy_index);
12123 for (phy_index = INT_PHY;
12124 phy_index < MAX_PHYS;
12125 phy_index++)
12126 *phy = phy_null;
12127 return -EINVAL;
12128 }
12129 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN)
12130 break;
12131
Yaniv Rosner55098c52012-04-03 18:41:27 +000012132 if (params->feature_config_flags &
12133 FEATURE_CONFIG_DISABLE_REMOTE_FAULT_DET)
12134 phy->flags &= ~FLAGS_TX_ERROR_CHECK;
12135
Yaniv Rosner55386fe82012-11-27 03:46:30 +000012136 if (!(params->feature_config_flags &
12137 FEATURE_CONFIG_MT_SUPPORT))
12138 phy->flags |= FLAGS_MDC_MDIO_WA_G;
12139
Yaniv Rosner1ac9e422011-05-31 21:26:11 +000012140 sync_offset = params->shmem_base +
12141 offsetof(struct shmem_region,
12142 dev_info.port_hw_config[params->port].media_type);
12143 media_types = REG_RD(bp, sync_offset);
12144
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000012145 /* Update media type for non-PMF sync only for the first time
Yaniv Rosner1ac9e422011-05-31 21:26:11 +000012146 * In case the media type changes afterwards, it will be updated
12147 * using the update_status function
12148 */
12149 if ((media_types & (PORT_HW_CFG_MEDIA_TYPE_PHY0_MASK <<
12150 (PORT_HW_CFG_MEDIA_TYPE_PHY1_SHIFT *
12151 actual_phy_idx))) == 0) {
12152 media_types |= ((phy->media_type &
12153 PORT_HW_CFG_MEDIA_TYPE_PHY0_MASK) <<
12154 (PORT_HW_CFG_MEDIA_TYPE_PHY1_SHIFT *
12155 actual_phy_idx));
12156 }
12157 REG_WR(bp, sync_offset, media_types);
12158
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012159 bnx2x_phy_def_cfg(params, phy, phy_index);
Yaniv Rosnerb7737c92010-09-07 11:40:54 +000012160 params->num_phys++;
12161 }
12162
12163 DP(NETIF_MSG_LINK, "End phy probe. #phys found %x\n", params->num_phys);
12164 return 0;
12165}
12166
Merav Sicron910cc722012-11-11 03:56:08 +000012167static void bnx2x_init_bmac_loopback(struct link_params *params,
12168 struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012169{
12170 struct bnx2x *bp = params->bp;
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000012171 vars->link_up = 1;
12172 vars->line_speed = SPEED_10000;
12173 vars->duplex = DUPLEX_FULL;
12174 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
12175 vars->mac_type = MAC_TYPE_BMAC;
12176
12177 vars->phy_flags = PHY_XGXS_FLAG;
12178
12179 bnx2x_xgxs_deassert(params);
12180
12181 /* set bmac loopback */
Yaniv Rosnerd3a8f132012-09-13 02:56:20 +000012182 bnx2x_bmac_enable(params, vars, 1, 1);
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000012183
12184 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 0);
12185}
12186
Merav Sicron910cc722012-11-11 03:56:08 +000012187static void bnx2x_init_emac_loopback(struct link_params *params,
12188 struct link_vars *vars)
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000012189{
12190 struct bnx2x *bp = params->bp;
12191 vars->link_up = 1;
12192 vars->line_speed = SPEED_1000;
12193 vars->duplex = DUPLEX_FULL;
12194 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
12195 vars->mac_type = MAC_TYPE_EMAC;
12196
12197 vars->phy_flags = PHY_XGXS_FLAG;
12198
12199 bnx2x_xgxs_deassert(params);
12200 /* set bmac loopback */
12201 bnx2x_emac_enable(params, vars, 1);
12202 bnx2x_emac_program(params, vars);
12203 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 0);
12204}
12205
Merav Sicron910cc722012-11-11 03:56:08 +000012206static void bnx2x_init_xmac_loopback(struct link_params *params,
12207 struct link_vars *vars)
Yaniv Rosner9380bb92011-06-14 01:34:07 +000012208{
12209 struct bnx2x *bp = params->bp;
12210 vars->link_up = 1;
12211 if (!params->req_line_speed[0])
12212 vars->line_speed = SPEED_10000;
12213 else
12214 vars->line_speed = params->req_line_speed[0];
12215 vars->duplex = DUPLEX_FULL;
12216 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
12217 vars->mac_type = MAC_TYPE_XMAC;
12218 vars->phy_flags = PHY_XGXS_FLAG;
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000012219 /* Set WC to loopback mode since link is required to provide clock
Yaniv Rosner9380bb92011-06-14 01:34:07 +000012220 * to the XMAC in 20G mode
12221 */
Yaniv Rosnerafad0092011-08-02 23:00:06 +000012222 bnx2x_set_aer_mmd(params, &params->phy[0]);
12223 bnx2x_warpcore_reset_lane(bp, &params->phy[0], 0);
12224 params->phy[INT_PHY].config_loopback(
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000012225 &params->phy[INT_PHY],
12226 params);
Yaniv Rosnerafad0092011-08-02 23:00:06 +000012227
Yaniv Rosner9380bb92011-06-14 01:34:07 +000012228 bnx2x_xmac_enable(params, vars, 1);
12229 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 0);
12230}
12231
Merav Sicron910cc722012-11-11 03:56:08 +000012232static void bnx2x_init_umac_loopback(struct link_params *params,
12233 struct link_vars *vars)
Yaniv Rosner9380bb92011-06-14 01:34:07 +000012234{
12235 struct bnx2x *bp = params->bp;
12236 vars->link_up = 1;
12237 vars->line_speed = SPEED_1000;
12238 vars->duplex = DUPLEX_FULL;
12239 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
12240 vars->mac_type = MAC_TYPE_UMAC;
12241 vars->phy_flags = PHY_XGXS_FLAG;
12242 bnx2x_umac_enable(params, vars, 1);
12243
12244 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 0);
12245}
12246
Merav Sicron910cc722012-11-11 03:56:08 +000012247static void bnx2x_init_xgxs_loopback(struct link_params *params,
12248 struct link_vars *vars)
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000012249{
12250 struct bnx2x *bp = params->bp;
Yaniv Rosner4e7b4992012-11-27 03:46:29 +000012251 struct bnx2x_phy *int_phy = &params->phy[INT_PHY];
Yaniv Rosner503976e2012-11-27 03:46:34 +000012252 vars->link_up = 1;
12253 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
12254 vars->duplex = DUPLEX_FULL;
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000012255 if (params->req_line_speed[0] == SPEED_1000)
Yaniv Rosner503976e2012-11-27 03:46:34 +000012256 vars->line_speed = SPEED_1000;
Yaniv Rosner4e7b4992012-11-27 03:46:29 +000012257 else if ((params->req_line_speed[0] == SPEED_20000) ||
12258 (int_phy->flags & FLAGS_WC_DUAL_MODE))
12259 vars->line_speed = SPEED_20000;
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000012260 else
Yaniv Rosner4e7b4992012-11-27 03:46:29 +000012261 vars->line_speed = SPEED_10000;
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000012262
Yaniv Rosner9380bb92011-06-14 01:34:07 +000012263 if (!USES_WARPCORE(bp))
12264 bnx2x_xgxs_deassert(params);
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000012265 bnx2x_link_initialize(params, vars);
12266
12267 if (params->req_line_speed[0] == SPEED_1000) {
Yaniv Rosner9380bb92011-06-14 01:34:07 +000012268 if (USES_WARPCORE(bp))
12269 bnx2x_umac_enable(params, vars, 0);
12270 else {
12271 bnx2x_emac_program(params, vars);
12272 bnx2x_emac_enable(params, vars, 0);
12273 }
12274 } else {
12275 if (USES_WARPCORE(bp))
12276 bnx2x_xmac_enable(params, vars, 0);
12277 else
Yaniv Rosnerd3a8f132012-09-13 02:56:20 +000012278 bnx2x_bmac_enable(params, vars, 0, 1);
Yaniv Rosner9380bb92011-06-14 01:34:07 +000012279 }
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000012280
Yaniv Rosner503976e2012-11-27 03:46:34 +000012281 if (params->loopback_mode == LOOPBACK_XGXS) {
12282 /* Set 10G XGXS loopback */
12283 int_phy->config_loopback(int_phy, params);
12284 } else {
12285 /* Set external phy loopback */
12286 u8 phy_index;
12287 for (phy_index = EXT_PHY1;
12288 phy_index < params->num_phys; phy_index++)
12289 if (params->phy[phy_index].config_loopback)
12290 params->phy[phy_index].config_loopback(
12291 &params->phy[phy_index],
12292 params);
12293 }
12294 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012295
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000012296 bnx2x_set_led(params, vars, LED_MODE_OPER, vars->line_speed);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012297}
12298
Merav Sicron55c11942012-11-07 00:45:48 +000012299void bnx2x_set_rx_filter(struct link_params *params, u8 en)
Yaniv Rosnerd3a8f132012-09-13 02:56:20 +000012300{
12301 struct bnx2x *bp = params->bp;
12302 u8 val = en * 0x1F;
12303
Yaniv Rosner503976e2012-11-27 03:46:34 +000012304 /* Open / close the gate between the NIG and the BRB */
Yaniv Rosnerd3a8f132012-09-13 02:56:20 +000012305 if (!CHIP_IS_E1x(bp))
12306 val |= en * 0x20;
12307 REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + params->port*4, val);
12308
12309 if (!CHIP_IS_E1(bp)) {
12310 REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + params->port*4,
12311 en*0x3);
12312 }
12313
12314 REG_WR(bp, (params->port ? NIG_REG_LLH1_BRB1_NOT_MCP :
12315 NIG_REG_LLH0_BRB1_NOT_MCP), en);
12316}
12317static int bnx2x_avoid_link_flap(struct link_params *params,
12318 struct link_vars *vars)
12319{
12320 u32 phy_idx;
12321 u32 dont_clear_stat, lfa_sts;
12322 struct bnx2x *bp = params->bp;
12323
12324 /* Sync the link parameters */
12325 bnx2x_link_status_update(params, vars);
12326
12327 /*
12328 * The module verification was already done by previous link owner,
12329 * so this call is meant only to get warning message
12330 */
12331
12332 for (phy_idx = INT_PHY; phy_idx < params->num_phys; phy_idx++) {
12333 struct bnx2x_phy *phy = &params->phy[phy_idx];
12334 if (phy->phy_specific_func) {
12335 DP(NETIF_MSG_LINK, "Calling PHY specific func\n");
12336 phy->phy_specific_func(phy, params, PHY_INIT);
12337 }
12338 if ((phy->media_type == ETH_PHY_SFPP_10G_FIBER) ||
12339 (phy->media_type == ETH_PHY_SFP_1G_FIBER) ||
12340 (phy->media_type == ETH_PHY_DA_TWINAX))
12341 bnx2x_verify_sfp_module(phy, params);
12342 }
12343 lfa_sts = REG_RD(bp, params->lfa_base +
12344 offsetof(struct shmem_lfa,
12345 lfa_sts));
12346
12347 dont_clear_stat = lfa_sts & SHMEM_LFA_DONT_CLEAR_STAT;
12348
12349 /* Re-enable the NIG/MAC */
12350 if (CHIP_IS_E3(bp)) {
12351 if (!dont_clear_stat) {
12352 REG_WR(bp, GRCBASE_MISC +
12353 MISC_REGISTERS_RESET_REG_2_CLEAR,
12354 (MISC_REGISTERS_RESET_REG_2_MSTAT0 <<
12355 params->port));
12356 REG_WR(bp, GRCBASE_MISC +
12357 MISC_REGISTERS_RESET_REG_2_SET,
12358 (MISC_REGISTERS_RESET_REG_2_MSTAT0 <<
12359 params->port));
12360 }
12361 if (vars->line_speed < SPEED_10000)
12362 bnx2x_umac_enable(params, vars, 0);
12363 else
12364 bnx2x_xmac_enable(params, vars, 0);
12365 } else {
12366 if (vars->line_speed < SPEED_10000)
12367 bnx2x_emac_enable(params, vars, 0);
12368 else
12369 bnx2x_bmac_enable(params, vars, 0, !dont_clear_stat);
12370 }
12371
12372 /* Increment LFA count */
12373 lfa_sts = ((lfa_sts & ~LINK_FLAP_AVOIDANCE_COUNT_MASK) |
12374 (((((lfa_sts & LINK_FLAP_AVOIDANCE_COUNT_MASK) >>
12375 LINK_FLAP_AVOIDANCE_COUNT_OFFSET) + 1) & 0xff)
12376 << LINK_FLAP_AVOIDANCE_COUNT_OFFSET));
12377 /* Clear link flap reason */
12378 lfa_sts &= ~LFA_LINK_FLAP_REASON_MASK;
12379
12380 REG_WR(bp, params->lfa_base +
12381 offsetof(struct shmem_lfa, lfa_sts), lfa_sts);
12382
12383 /* Disable NIG DRAIN */
12384 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 0);
12385
12386 /* Enable interrupts */
12387 bnx2x_link_int_enable(params);
12388 return 0;
12389}
12390
12391static void bnx2x_cannot_avoid_link_flap(struct link_params *params,
12392 struct link_vars *vars,
12393 int lfa_status)
12394{
12395 u32 lfa_sts, cfg_idx, tmp_val;
12396 struct bnx2x *bp = params->bp;
12397
12398 bnx2x_link_reset(params, vars, 1);
12399
12400 if (!params->lfa_base)
12401 return;
12402 /* Store the new link parameters */
12403 REG_WR(bp, params->lfa_base +
12404 offsetof(struct shmem_lfa, req_duplex),
12405 params->req_duplex[0] | (params->req_duplex[1] << 16));
12406
12407 REG_WR(bp, params->lfa_base +
12408 offsetof(struct shmem_lfa, req_flow_ctrl),
12409 params->req_flow_ctrl[0] | (params->req_flow_ctrl[1] << 16));
12410
12411 REG_WR(bp, params->lfa_base +
12412 offsetof(struct shmem_lfa, req_line_speed),
12413 params->req_line_speed[0] | (params->req_line_speed[1] << 16));
12414
12415 for (cfg_idx = 0; cfg_idx < SHMEM_LINK_CONFIG_SIZE; cfg_idx++) {
12416 REG_WR(bp, params->lfa_base +
12417 offsetof(struct shmem_lfa,
12418 speed_cap_mask[cfg_idx]),
12419 params->speed_cap_mask[cfg_idx]);
12420 }
12421
12422 tmp_val = REG_RD(bp, params->lfa_base +
12423 offsetof(struct shmem_lfa, additional_config));
12424 tmp_val &= ~REQ_FC_AUTO_ADV_MASK;
12425 tmp_val |= params->req_fc_auto_adv;
12426
12427 REG_WR(bp, params->lfa_base +
12428 offsetof(struct shmem_lfa, additional_config), tmp_val);
12429
12430 lfa_sts = REG_RD(bp, params->lfa_base +
12431 offsetof(struct shmem_lfa, lfa_sts));
12432
12433 /* Clear the "Don't Clear Statistics" bit, and set reason */
12434 lfa_sts &= ~SHMEM_LFA_DONT_CLEAR_STAT;
12435
12436 /* Set link flap reason */
12437 lfa_sts &= ~LFA_LINK_FLAP_REASON_MASK;
12438 lfa_sts |= ((lfa_status & LFA_LINK_FLAP_REASON_MASK) <<
12439 LFA_LINK_FLAP_REASON_OFFSET);
12440
12441 /* Increment link flap counter */
12442 lfa_sts = ((lfa_sts & ~LINK_FLAP_COUNT_MASK) |
12443 (((((lfa_sts & LINK_FLAP_COUNT_MASK) >>
12444 LINK_FLAP_COUNT_OFFSET) + 1) & 0xff)
12445 << LINK_FLAP_COUNT_OFFSET));
12446 REG_WR(bp, params->lfa_base +
12447 offsetof(struct shmem_lfa, lfa_sts), lfa_sts);
12448 /* Proceed with regular link initialization */
12449}
12450
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000012451int bnx2x_phy_init(struct link_params *params, struct link_vars *vars)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012452{
Yaniv Rosnerd3a8f132012-09-13 02:56:20 +000012453 int lfa_status;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012454 struct bnx2x *bp = params->bp;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012455 DP(NETIF_MSG_LINK, "Phy Initialization started\n");
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012456 DP(NETIF_MSG_LINK, "(1) req_speed %d, req_flowctrl %d\n",
12457 params->req_line_speed[0], params->req_flow_ctrl[0]);
12458 DP(NETIF_MSG_LINK, "(2) req_speed %d, req_flowctrl %d\n",
12459 params->req_line_speed[1], params->req_flow_ctrl[1]);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012460 vars->link_status = 0;
12461 vars->phy_link_up = 0;
12462 vars->link_up = 0;
12463 vars->line_speed = 0;
12464 vars->duplex = DUPLEX_FULL;
12465 vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
12466 vars->mac_type = MAC_TYPE_NONE;
12467 vars->phy_flags = 0;
Yaniv Rosnerd3a8f132012-09-13 02:56:20 +000012468 /* Driver opens NIG-BRB filters */
12469 bnx2x_set_rx_filter(params, 1);
12470 /* Check if link flap can be avoided */
12471 lfa_status = bnx2x_check_lfa(params);
12472
12473 if (lfa_status == 0) {
12474 DP(NETIF_MSG_LINK, "Link Flap Avoidance in progress\n");
12475 return bnx2x_avoid_link_flap(params, vars);
12476 }
12477
12478 DP(NETIF_MSG_LINK, "Cannot avoid link flap lfa_sta=0x%x\n",
12479 lfa_status);
12480 bnx2x_cannot_avoid_link_flap(params, vars, lfa_status);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012481
Yuval Mintzd2310232012-06-20 19:05:19 +000012482 /* Disable attentions */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012483 bnx2x_bits_dis(bp, NIG_REG_MASK_INTERRUPT_PORT0 + params->port*4,
12484 (NIG_MASK_XGXS0_LINK_STATUS |
12485 NIG_MASK_XGXS0_LINK10G |
12486 NIG_MASK_SERDES0_LINK_STATUS |
12487 NIG_MASK_MI_INT));
12488
12489 bnx2x_emac_init(params, vars);
12490
Yaniv Rosner27d91292012-04-04 01:28:54 +000012491 if (params->feature_config_flags & FEATURE_CONFIG_PFC_ENABLED)
12492 vars->link_status |= LINK_STATUS_PFC_ENABLED;
12493
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012494 if (params->num_phys == 0) {
12495 DP(NETIF_MSG_LINK, "No phy found for initialization !!\n");
12496 return -EINVAL;
12497 }
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000012498 set_phy_vars(params, vars);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012499
12500 DP(NETIF_MSG_LINK, "Num of phys on board: %d\n", params->num_phys);
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000012501 switch (params->loopback_mode) {
12502 case LOOPBACK_BMAC:
12503 bnx2x_init_bmac_loopback(params, vars);
12504 break;
12505 case LOOPBACK_EMAC:
12506 bnx2x_init_emac_loopback(params, vars);
12507 break;
Yaniv Rosner9380bb92011-06-14 01:34:07 +000012508 case LOOPBACK_XMAC:
12509 bnx2x_init_xmac_loopback(params, vars);
12510 break;
12511 case LOOPBACK_UMAC:
12512 bnx2x_init_umac_loopback(params, vars);
12513 break;
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000012514 case LOOPBACK_XGXS:
12515 case LOOPBACK_EXT_PHY:
12516 bnx2x_init_xgxs_loopback(params, vars);
12517 break;
12518 default:
Yaniv Rosner9380bb92011-06-14 01:34:07 +000012519 if (!CHIP_IS_E3(bp)) {
12520 if (params->switch_cfg == SWITCH_CFG_10G)
12521 bnx2x_xgxs_deassert(params);
12522 else
12523 bnx2x_serdes_deassert(bp, params->port);
12524 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012525 bnx2x_link_initialize(params, vars);
12526 msleep(30);
12527 bnx2x_link_int_enable(params);
Yaniv Rosner9045f6b2011-05-31 21:28:27 +000012528 break;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012529 }
Yaniv Rosner55098c52012-04-03 18:41:27 +000012530 bnx2x_update_mng(params, vars->link_status);
Yuval Mintzc8c60d82012-06-06 17:13:07 +000012531
12532 bnx2x_update_mng_eee(params, vars->eee_status);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012533 return 0;
12534}
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000012535
12536int bnx2x_link_reset(struct link_params *params, struct link_vars *vars,
12537 u8 reset_ext_phy)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012538{
12539 struct bnx2x *bp = params->bp;
Yaniv Rosnercf1d9722010-11-01 05:32:34 +000012540 u8 phy_index, port = params->port, clear_latch_ind = 0;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012541 DP(NETIF_MSG_LINK, "Resetting the link of port %d\n", port);
Yuval Mintzd2310232012-06-20 19:05:19 +000012542 /* Disable attentions */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012543 vars->link_status = 0;
12544 bnx2x_update_mng(params, vars->link_status);
Yuval Mintzc8c60d82012-06-06 17:13:07 +000012545 vars->eee_status &= ~(SHMEM_EEE_LP_ADV_STATUS_MASK |
12546 SHMEM_EEE_ACTIVE_BIT);
12547 bnx2x_update_mng_eee(params, vars->eee_status);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012548 bnx2x_bits_dis(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012549 (NIG_MASK_XGXS0_LINK_STATUS |
12550 NIG_MASK_XGXS0_LINK10G |
12551 NIG_MASK_SERDES0_LINK_STATUS |
12552 NIG_MASK_MI_INT));
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012553
Yuval Mintzd2310232012-06-20 19:05:19 +000012554 /* Activate nig drain */
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012555 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + port*4, 1);
12556
Yuval Mintzd2310232012-06-20 19:05:19 +000012557 /* Disable nig egress interface */
Yaniv Rosner9380bb92011-06-14 01:34:07 +000012558 if (!CHIP_IS_E3(bp)) {
12559 REG_WR(bp, NIG_REG_BMAC0_OUT_EN + port*4, 0);
12560 REG_WR(bp, NIG_REG_EGRESS_EMAC0_OUT_EN + port*4, 0);
12561 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012562
Yaniv Rosnerd3a8f132012-09-13 02:56:20 +000012563 if (!CHIP_IS_E3(bp)) {
12564 bnx2x_set_bmac_rx(bp, params->chip_id, port, 0);
12565 } else {
12566 bnx2x_set_xmac_rxtx(params, 0);
12567 bnx2x_set_umac_rxtx(params, 0);
12568 }
Yuval Mintzd2310232012-06-20 19:05:19 +000012569 /* Disable emac */
Yaniv Rosner9380bb92011-06-14 01:34:07 +000012570 if (!CHIP_IS_E3(bp))
12571 REG_WR(bp, NIG_REG_NIG_EMAC0_EN + port*4, 0);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012572
Yuval Mintzd2310232012-06-20 19:05:19 +000012573 usleep_range(10000, 20000);
Lucas De Marchi25985ed2011-03-30 22:57:33 -030012574 /* The PHY reset is controlled by GPIO 1
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012575 * Hold it as vars low
12576 */
Yuval Mintzd2310232012-06-20 19:05:19 +000012577 /* Clear link led */
Yaniv Rosner55386fe82012-11-27 03:46:30 +000012578 bnx2x_set_mdio_emac_per_phy(bp, params);
Yaniv Rosner7f02c4a2010-09-07 11:41:23 +000012579 bnx2x_set_led(params, vars, LED_MODE_OFF, 0);
12580
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012581 if (reset_ext_phy) {
12582 for (phy_index = EXT_PHY1; phy_index < params->num_phys;
12583 phy_index++) {
Yaniv Rosner28f48812011-08-02 23:00:12 +000012584 if (params->phy[phy_index].link_reset) {
12585 bnx2x_set_aer_mmd(params,
12586 &params->phy[phy_index]);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012587 params->phy[phy_index].link_reset(
12588 &params->phy[phy_index],
12589 params);
Yaniv Rosner28f48812011-08-02 23:00:12 +000012590 }
Yaniv Rosnercf1d9722010-11-01 05:32:34 +000012591 if (params->phy[phy_index].flags &
12592 FLAGS_REARM_LATCH_SIGNAL)
12593 clear_latch_ind = 1;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012594 }
12595 }
12596
Yaniv Rosnercf1d9722010-11-01 05:32:34 +000012597 if (clear_latch_ind) {
12598 /* Clear latching indication */
12599 bnx2x_rearm_latch_signal(bp, port, 0);
12600 bnx2x_bits_dis(bp, NIG_REG_LATCH_BC_0 + port*4,
12601 1 << NIG_LATCH_BC_ENABLE_MI_INT);
12602 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012603 if (params->phy[INT_PHY].link_reset)
12604 params->phy[INT_PHY].link_reset(
12605 &params->phy[INT_PHY], params);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012606
Yuval Mintzd2310232012-06-20 19:05:19 +000012607 /* Disable nig ingress interface */
Yaniv Rosner9380bb92011-06-14 01:34:07 +000012608 if (!CHIP_IS_E3(bp)) {
Yuval Mintzd2310232012-06-20 19:05:19 +000012609 /* Reset BigMac */
Yaniv Rosnerce7c0482011-10-27 05:09:47 +000012610 REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
12611 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port));
Yaniv Rosner9380bb92011-06-14 01:34:07 +000012612 REG_WR(bp, NIG_REG_BMAC0_IN_EN + port*4, 0);
12613 REG_WR(bp, NIG_REG_EMAC0_IN_EN + port*4, 0);
Yaniv Rosnerce7c0482011-10-27 05:09:47 +000012614 } else {
12615 u32 xmac_base = (params->port) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
12616 bnx2x_set_xumac_nig(params, 0, 0);
12617 if (REG_RD(bp, MISC_REG_RESET_REG_2) &
12618 MISC_REGISTERS_RESET_REG_2_XMAC)
12619 REG_WR(bp, xmac_base + XMAC_REG_CTRL,
12620 XMAC_CTRL_REG_SOFT_RESET);
Yaniv Rosner9380bb92011-06-14 01:34:07 +000012621 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012622 vars->link_up = 0;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000012623 vars->phy_flags = 0;
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012624 return 0;
12625}
Yaniv Rosnerd3a8f132012-09-13 02:56:20 +000012626int bnx2x_lfa_reset(struct link_params *params,
12627 struct link_vars *vars)
12628{
12629 struct bnx2x *bp = params->bp;
12630 vars->link_up = 0;
12631 vars->phy_flags = 0;
12632 if (!params->lfa_base)
12633 return bnx2x_link_reset(params, vars, 1);
12634 /*
12635 * Activate NIG drain so that during this time the device won't send
12636 * anything while it is unable to response.
12637 */
12638 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 1);
12639
12640 /*
12641 * Close gracefully the gate from BMAC to NIG such that no half packets
12642 * are passed.
12643 */
12644 if (!CHIP_IS_E3(bp))
12645 bnx2x_set_bmac_rx(bp, params->chip_id, params->port, 0);
12646
12647 if (CHIP_IS_E3(bp)) {
12648 bnx2x_set_xmac_rxtx(params, 0);
12649 bnx2x_set_umac_rxtx(params, 0);
12650 }
12651 /* Wait 10ms for the pipe to clean up*/
12652 usleep_range(10000, 20000);
12653
12654 /* Clean the NIG-BRB using the network filters in a way that will
12655 * not cut a packet in the middle.
12656 */
12657 bnx2x_set_rx_filter(params, 0);
12658
12659 /*
12660 * Re-open the gate between the BMAC and the NIG, after verifying the
12661 * gate to the BRB is closed, otherwise packets may arrive to the
12662 * firmware before driver had initialized it. The target is to achieve
12663 * minimum management protocol down time.
12664 */
12665 if (!CHIP_IS_E3(bp))
12666 bnx2x_set_bmac_rx(bp, params->chip_id, params->port, 1);
12667
12668 if (CHIP_IS_E3(bp)) {
12669 bnx2x_set_xmac_rxtx(params, 1);
12670 bnx2x_set_umac_rxtx(params, 1);
12671 }
12672 /* Disable NIG drain */
12673 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 0);
12674 return 0;
12675}
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012676
12677/****************************************************************************/
12678/* Common function */
12679/****************************************************************************/
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000012680static int bnx2x_8073_common_init_phy(struct bnx2x *bp,
12681 u32 shmem_base_path[],
12682 u32 shmem2_base_path[], u8 phy_index,
12683 u32 chip_id)
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012684{
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012685 struct bnx2x_phy phy[PORT_MAX];
12686 struct bnx2x_phy *phy_blk[PORT_MAX];
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012687 u16 val;
Yaniv Rosnerc8e64df2011-01-30 04:15:00 +000012688 s8 port = 0;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012689 s8 port_of_path = 0;
Yaniv Rosnerc8e64df2011-01-30 04:15:00 +000012690 u32 swap_val, swap_override;
12691 swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
12692 swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
12693 port ^= (swap_val && swap_override);
12694 bnx2x_ext_phy_hw_reset(bp, port);
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012695 /* PART1 - Reset both phys */
12696 for (port = PORT_MAX - 1; port >= PORT_0; port--) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012697 u32 shmem_base, shmem2_base;
12698 /* In E2, same phy is using for port0 of the two paths */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000012699 if (CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012700 shmem_base = shmem_base_path[0];
12701 shmem2_base = shmem2_base_path[0];
12702 port_of_path = port;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000012703 } else {
12704 shmem_base = shmem_base_path[port];
12705 shmem2_base = shmem2_base_path[port];
12706 port_of_path = 0;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012707 }
12708
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012709 /* Extract the ext phy address for the port */
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012710 if (bnx2x_populate_phy(bp, phy_index, shmem_base, shmem2_base,
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012711 port_of_path, &phy[port]) !=
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012712 0) {
12713 DP(NETIF_MSG_LINK, "populate_phy failed\n");
12714 return -EINVAL;
12715 }
Yuval Mintzd2310232012-06-20 19:05:19 +000012716 /* Disable attentions */
Yaniv Rosner6a71bbe2010-11-01 05:32:31 +000012717 bnx2x_bits_dis(bp, NIG_REG_MASK_INTERRUPT_PORT0 +
12718 port_of_path*4,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012719 (NIG_MASK_XGXS0_LINK_STATUS |
12720 NIG_MASK_XGXS0_LINK10G |
12721 NIG_MASK_SERDES0_LINK_STATUS |
12722 NIG_MASK_MI_INT));
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012723
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012724 /* Need to take the phy out of low power mode in order
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000012725 * to write to access its registers
12726 */
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012727 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012728 MISC_REGISTERS_GPIO_OUTPUT_HIGH,
12729 port);
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012730
12731 /* Reset the phy */
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012732 bnx2x_cl45_write(bp, &phy[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012733 MDIO_PMA_DEVAD,
12734 MDIO_PMA_REG_CTRL,
12735 1<<15);
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012736 }
12737
12738 /* Add delay of 150ms after reset */
12739 msleep(150);
12740
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012741 if (phy[PORT_0].addr & 0x1) {
12742 phy_blk[PORT_0] = &(phy[PORT_1]);
12743 phy_blk[PORT_1] = &(phy[PORT_0]);
12744 } else {
12745 phy_blk[PORT_0] = &(phy[PORT_0]);
12746 phy_blk[PORT_1] = &(phy[PORT_1]);
12747 }
12748
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012749 /* PART2 - Download firmware to both phys */
12750 for (port = PORT_MAX - 1; port >= PORT_0; port--) {
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000012751 if (CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012752 port_of_path = port;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000012753 else
12754 port_of_path = 0;
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012755
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012756 DP(NETIF_MSG_LINK, "Loading spirom for phy address 0x%x\n",
12757 phy_blk[port]->addr);
Yaniv Rosner5c99274b2011-01-18 04:33:36 +000012758 if (bnx2x_8073_8727_external_rom_boot(bp, phy_blk[port],
12759 port_of_path))
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012760 return -EINVAL;
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012761
12762 /* Only set bit 10 = 1 (Tx power down) */
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012763 bnx2x_cl45_read(bp, phy_blk[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012764 MDIO_PMA_DEVAD,
12765 MDIO_PMA_REG_TX_POWER_DOWN, &val);
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012766
12767 /* Phase1 of TX_POWER_DOWN reset */
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012768 bnx2x_cl45_write(bp, phy_blk[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012769 MDIO_PMA_DEVAD,
12770 MDIO_PMA_REG_TX_POWER_DOWN,
12771 (val | 1<<10));
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012772 }
12773
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000012774 /* Toggle Transmitter: Power down and then up with 600ms delay
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +000012775 * between
12776 */
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012777 msleep(600);
12778
12779 /* PART3 - complete TX_POWER_DOWN process, and set GPIO2 back to low */
12780 for (port = PORT_MAX - 1; port >= PORT_0; port--) {
Eilon Greensteinf5372252009-02-12 08:38:30 +000012781 /* Phase2 of POWER_DOWN_RESET */
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012782 /* Release bit 10 (Release Tx power down) */
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012783 bnx2x_cl45_read(bp, phy_blk[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012784 MDIO_PMA_DEVAD,
12785 MDIO_PMA_REG_TX_POWER_DOWN, &val);
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012786
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012787 bnx2x_cl45_write(bp, phy_blk[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012788 MDIO_PMA_DEVAD,
12789 MDIO_PMA_REG_TX_POWER_DOWN, (val & (~(1<<10))));
Yuval Mintzd2310232012-06-20 19:05:19 +000012790 usleep_range(15000, 30000);
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012791
12792 /* Read modify write the SPI-ROM version select register */
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012793 bnx2x_cl45_read(bp, phy_blk[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012794 MDIO_PMA_DEVAD,
12795 MDIO_PMA_REG_EDC_FFE_MAIN, &val);
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012796 bnx2x_cl45_write(bp, phy_blk[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012797 MDIO_PMA_DEVAD,
12798 MDIO_PMA_REG_EDC_FFE_MAIN, (val | (1<<12)));
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012799
12800 /* set GPIO2 back to LOW */
12801 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012802 MISC_REGISTERS_GPIO_OUTPUT_LOW, port);
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012803 }
12804 return 0;
Yaniv Rosner6bbca912008-08-13 15:57:28 -070012805}
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000012806static int bnx2x_8726_common_init_phy(struct bnx2x *bp,
12807 u32 shmem_base_path[],
12808 u32 shmem2_base_path[], u8 phy_index,
12809 u32 chip_id)
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012810{
12811 u32 val;
12812 s8 port;
12813 struct bnx2x_phy phy;
12814 /* Use port1 because of the static port-swap */
12815 /* Enable the module detection interrupt */
12816 val = REG_RD(bp, MISC_REG_GPIO_EVENT_EN);
12817 val |= ((1<<MISC_REGISTERS_GPIO_3)|
12818 (1<<(MISC_REGISTERS_GPIO_3 + MISC_REGISTERS_GPIO_PORT_SHIFT)));
12819 REG_WR(bp, MISC_REG_GPIO_EVENT_EN, val);
12820
Yaniv Rosner650154b2010-11-01 05:32:36 +000012821 bnx2x_ext_phy_hw_reset(bp, 0);
Yuval Mintzd2310232012-06-20 19:05:19 +000012822 usleep_range(5000, 10000);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012823 for (port = 0; port < PORT_MAX; port++) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012824 u32 shmem_base, shmem2_base;
12825
12826 /* In E2, same phy is using for port0 of the two paths */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000012827 if (CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012828 shmem_base = shmem_base_path[0];
12829 shmem2_base = shmem2_base_path[0];
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000012830 } else {
12831 shmem_base = shmem_base_path[port];
12832 shmem2_base = shmem2_base_path[port];
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012833 }
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012834 /* Extract the ext phy address for the port */
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012835 if (bnx2x_populate_phy(bp, phy_index, shmem_base, shmem2_base,
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012836 port, &phy) !=
12837 0) {
12838 DP(NETIF_MSG_LINK, "populate phy failed\n");
12839 return -EINVAL;
12840 }
12841
12842 /* Reset phy*/
12843 bnx2x_cl45_write(bp, &phy,
12844 MDIO_PMA_DEVAD, MDIO_PMA_REG_GEN_CTRL, 0x0001);
12845
12846
12847 /* Set fault module detected LED on */
12848 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_0,
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012849 MISC_REGISTERS_GPIO_HIGH,
12850 port);
Yaniv Rosnerde6eae12010-09-07 11:41:13 +000012851 }
12852
12853 return 0;
12854}
Yaniv Rosnera8db5b42011-01-31 04:22:28 +000012855static void bnx2x_get_ext_phy_reset_gpio(struct bnx2x *bp, u32 shmem_base,
12856 u8 *io_gpio, u8 *io_port)
12857{
12858
12859 u32 phy_gpio_reset = REG_RD(bp, shmem_base +
12860 offsetof(struct shmem_region,
12861 dev_info.port_hw_config[PORT_0].default_cfg));
12862 switch (phy_gpio_reset) {
12863 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO0_P0:
12864 *io_gpio = 0;
12865 *io_port = 0;
12866 break;
12867 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO1_P0:
12868 *io_gpio = 1;
12869 *io_port = 0;
12870 break;
12871 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO2_P0:
12872 *io_gpio = 2;
12873 *io_port = 0;
12874 break;
12875 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO3_P0:
12876 *io_gpio = 3;
12877 *io_port = 0;
12878 break;
12879 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO0_P1:
12880 *io_gpio = 0;
12881 *io_port = 1;
12882 break;
12883 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO1_P1:
12884 *io_gpio = 1;
12885 *io_port = 1;
12886 break;
12887 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO2_P1:
12888 *io_gpio = 2;
12889 *io_port = 1;
12890 break;
12891 case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO3_P1:
12892 *io_gpio = 3;
12893 *io_port = 1;
12894 break;
12895 default:
12896 /* Don't override the io_gpio and io_port */
12897 break;
12898 }
12899}
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000012900
12901static int bnx2x_8727_common_init_phy(struct bnx2x *bp,
12902 u32 shmem_base_path[],
12903 u32 shmem2_base_path[], u8 phy_index,
12904 u32 chip_id)
Eilon Greenstein4d295db2009-07-21 05:47:47 +000012905{
Yaniv Rosnera8db5b42011-01-31 04:22:28 +000012906 s8 port, reset_gpio;
Eilon Greenstein4d295db2009-07-21 05:47:47 +000012907 u32 swap_val, swap_override;
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012908 struct bnx2x_phy phy[PORT_MAX];
12909 struct bnx2x_phy *phy_blk[PORT_MAX];
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012910 s8 port_of_path;
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012911 swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
12912 swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
Eilon Greenstein4d295db2009-07-21 05:47:47 +000012913
Yaniv Rosnera8db5b42011-01-31 04:22:28 +000012914 reset_gpio = MISC_REGISTERS_GPIO_1;
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012915 port = 1;
12916
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000012917 /* Retrieve the reset gpio/port which control the reset.
Yaniv Rosnera8db5b42011-01-31 04:22:28 +000012918 * Default is GPIO1, PORT1
12919 */
12920 bnx2x_get_ext_phy_reset_gpio(bp, shmem_base_path[0],
12921 (u8 *)&reset_gpio, (u8 *)&port);
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012922
12923 /* Calculate the port based on port swap */
12924 port ^= (swap_val && swap_override);
12925
Yaniv Rosnera8db5b42011-01-31 04:22:28 +000012926 /* Initiate PHY reset*/
12927 bnx2x_set_gpio(bp, reset_gpio, MISC_REGISTERS_GPIO_OUTPUT_LOW,
12928 port);
Yaniv Rosner503976e2012-11-27 03:46:34 +000012929 usleep_range(1000, 2000);
Yaniv Rosnera8db5b42011-01-31 04:22:28 +000012930 bnx2x_set_gpio(bp, reset_gpio, MISC_REGISTERS_GPIO_OUTPUT_HIGH,
12931 port);
12932
Yuval Mintzd2310232012-06-20 19:05:19 +000012933 usleep_range(5000, 10000);
Eilon Greenstein4d295db2009-07-21 05:47:47 +000012934
12935 /* PART1 - Reset both phys */
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012936 for (port = PORT_MAX - 1; port >= PORT_0; port--) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012937 u32 shmem_base, shmem2_base;
12938
12939 /* In E2, same phy is using for port0 of the two paths */
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000012940 if (CHIP_IS_E1x(bp)) {
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012941 shmem_base = shmem_base_path[0];
12942 shmem2_base = shmem2_base_path[0];
12943 port_of_path = port;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000012944 } else {
12945 shmem_base = shmem_base_path[port];
12946 shmem2_base = shmem2_base_path[port];
12947 port_of_path = 0;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012948 }
12949
Eilon Greenstein4d295db2009-07-21 05:47:47 +000012950 /* Extract the ext phy address for the port */
Yaniv Rosnera22f0782010-09-07 11:41:20 +000012951 if (bnx2x_populate_phy(bp, phy_index, shmem_base, shmem2_base,
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012952 port_of_path, &phy[port]) !=
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012953 0) {
12954 DP(NETIF_MSG_LINK, "populate phy failed\n");
12955 return -EINVAL;
12956 }
Eilon Greenstein4d295db2009-07-21 05:47:47 +000012957 /* disable attentions */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012958 bnx2x_bits_dis(bp, NIG_REG_MASK_INTERRUPT_PORT0 +
12959 port_of_path*4,
12960 (NIG_MASK_XGXS0_LINK_STATUS |
12961 NIG_MASK_XGXS0_LINK10G |
12962 NIG_MASK_SERDES0_LINK_STATUS |
12963 NIG_MASK_MI_INT));
Eilon Greenstein4d295db2009-07-21 05:47:47 +000012964
Eilon Greenstein4d295db2009-07-21 05:47:47 +000012965
12966 /* Reset the phy */
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012967 bnx2x_cl45_write(bp, &phy[port],
Yaniv Rosnercd88cce2011-01-31 04:21:34 +000012968 MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 1<<15);
Eilon Greenstein4d295db2009-07-21 05:47:47 +000012969 }
12970
12971 /* Add delay of 150ms after reset */
12972 msleep(150);
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012973 if (phy[PORT_0].addr & 0x1) {
12974 phy_blk[PORT_0] = &(phy[PORT_1]);
12975 phy_blk[PORT_1] = &(phy[PORT_0]);
12976 } else {
12977 phy_blk[PORT_0] = &(phy[PORT_0]);
12978 phy_blk[PORT_1] = &(phy[PORT_1]);
12979 }
Eilon Greenstein4d295db2009-07-21 05:47:47 +000012980 /* PART2 - Download firmware to both phys */
Yaniv Rosnere10bc842010-09-07 11:40:50 +000012981 for (port = PORT_MAX - 1; port >= PORT_0; port--) {
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000012982 if (CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012983 port_of_path = port;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000012984 else
12985 port_of_path = 0;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000012986 DP(NETIF_MSG_LINK, "Loading spirom for phy address 0x%x\n",
12987 phy_blk[port]->addr);
Yaniv Rosner5c99274b2011-01-18 04:33:36 +000012988 if (bnx2x_8073_8727_external_rom_boot(bp, phy_blk[port],
12989 port_of_path))
Eilon Greenstein4d295db2009-07-21 05:47:47 +000012990 return -EINVAL;
Yaniv Rosner85242ee2011-07-05 01:06:53 +000012991 /* Disable PHY transmitter output */
12992 bnx2x_cl45_write(bp, phy_blk[port],
12993 MDIO_PMA_DEVAD,
12994 MDIO_PMA_REG_TX_DISABLE, 1);
Eilon Greenstein4d295db2009-07-21 05:47:47 +000012995
Yaniv Rosner5c99274b2011-01-18 04:33:36 +000012996 }
Eilon Greenstein4d295db2009-07-21 05:47:47 +000012997 return 0;
12998}
12999
Yaniv Rosner521683d2011-11-28 00:49:48 +000013000static int bnx2x_84833_common_init_phy(struct bnx2x *bp,
13001 u32 shmem_base_path[],
13002 u32 shmem2_base_path[],
13003 u8 phy_index,
13004 u32 chip_id)
13005{
13006 u8 reset_gpios;
Yaniv Rosner521683d2011-11-28 00:49:48 +000013007 reset_gpios = bnx2x_84833_get_reset_gpios(bp, shmem_base_path, chip_id);
13008 bnx2x_set_mult_gpio(bp, reset_gpios, MISC_REGISTERS_GPIO_OUTPUT_LOW);
13009 udelay(10);
13010 bnx2x_set_mult_gpio(bp, reset_gpios, MISC_REGISTERS_GPIO_OUTPUT_HIGH);
13011 DP(NETIF_MSG_LINK, "84833 reset pulse on pin values 0x%x\n",
13012 reset_gpios);
Yaniv Rosner521683d2011-11-28 00:49:48 +000013013 return 0;
13014}
13015
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000013016static int bnx2x_ext_phy_common_init(struct bnx2x *bp, u32 shmem_base_path[],
13017 u32 shmem2_base_path[], u8 phy_index,
13018 u32 ext_phy_type, u32 chip_id)
Yaniv Rosner6bbca912008-08-13 15:57:28 -070013019{
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000013020 int rc = 0;
Yaniv Rosner6bbca912008-08-13 15:57:28 -070013021
13022 switch (ext_phy_type) {
13023 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073:
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000013024 rc = bnx2x_8073_common_init_phy(bp, shmem_base_path,
13025 shmem2_base_path,
13026 phy_index, chip_id);
Yaniv Rosner6bbca912008-08-13 15:57:28 -070013027 break;
Yaniv Rosnere4d78f12011-05-31 21:25:55 +000013028 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8722:
Eilon Greenstein4d295db2009-07-21 05:47:47 +000013029 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
13030 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727_NOC:
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000013031 rc = bnx2x_8727_common_init_phy(bp, shmem_base_path,
13032 shmem2_base_path,
13033 phy_index, chip_id);
Eilon Greenstein4d295db2009-07-21 05:47:47 +000013034 break;
13035
Eilon Greenstein589abe32009-02-12 08:36:55 +000013036 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000013037 /* GPIO1 affects both ports, so there's need to pull
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +000013038 * it for single port alone
13039 */
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000013040 rc = bnx2x_8726_common_init_phy(bp, shmem_base_path,
13041 shmem2_base_path,
13042 phy_index, chip_id);
Yaniv Rosnera22f0782010-09-07 11:41:20 +000013043 break;
Yaniv Rosner0d40f0d2011-06-14 01:34:27 +000013044 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833:
Yaniv Rosner0f6bb032012-11-27 03:46:32 +000013045 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84834:
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000013046 /* GPIO3's are linked, and so both need to be toggled
Yaniv Rosner0d40f0d2011-06-14 01:34:27 +000013047 * to obtain required 2us pulse.
13048 */
Yaniv Rosner521683d2011-11-28 00:49:48 +000013049 rc = bnx2x_84833_common_init_phy(bp, shmem_base_path,
13050 shmem2_base_path,
13051 phy_index, chip_id);
Yaniv Rosner0d40f0d2011-06-14 01:34:27 +000013052 break;
Yaniv Rosnera22f0782010-09-07 11:41:20 +000013053 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE:
13054 rc = -EINVAL;
Yaniv Rosner4f60dab2009-11-05 19:18:23 +020013055 break;
Yaniv Rosner6bbca912008-08-13 15:57:28 -070013056 default:
13057 DP(NETIF_MSG_LINK,
Yaniv Rosner2cf7acf2011-01-31 04:21:55 +000013058 "ext_phy 0x%x common init not required\n",
13059 ext_phy_type);
Yaniv Rosner6bbca912008-08-13 15:57:28 -070013060 break;
13061 }
13062
Yuval Mintzd2310232012-06-20 19:05:19 +000013063 if (rc)
Yaniv Rosner6d870c32011-01-31 04:22:20 +000013064 netdev_err(bp->dev, "Warning: PHY was not initialized,"
13065 " Port %d\n",
13066 0);
Yaniv Rosner6bbca912008-08-13 15:57:28 -070013067 return rc;
13068}
13069
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000013070int bnx2x_common_init_phy(struct bnx2x *bp, u32 shmem_base_path[],
13071 u32 shmem2_base_path[], u32 chip_id)
Yaniv Rosnera22f0782010-09-07 11:41:20 +000013072{
Yaniv Rosnerfcf5b652011-05-31 21:26:28 +000013073 int rc = 0;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000013074 u32 phy_ver, val;
13075 u8 phy_index = 0;
Yaniv Rosnera22f0782010-09-07 11:41:20 +000013076 u32 ext_phy_type, ext_phy_config;
Yaniv Rosner55386fe82012-11-27 03:46:30 +000013077
13078 bnx2x_set_mdio_clk(bp, chip_id, GRCBASE_EMAC0);
13079 bnx2x_set_mdio_clk(bp, chip_id, GRCBASE_EMAC1);
Yaniv Rosnera22f0782010-09-07 11:41:20 +000013080 DP(NETIF_MSG_LINK, "Begin common phy init\n");
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000013081 if (CHIP_IS_E3(bp)) {
13082 /* Enable EPIO */
13083 val = REG_RD(bp, MISC_REG_GEN_PURP_HWG);
13084 REG_WR(bp, MISC_REG_GEN_PURP_HWG, val | 1);
13085 }
Yaniv Rosnerb21a3422011-01-18 04:33:24 +000013086 /* Check if common init was already done */
13087 phy_ver = REG_RD(bp, shmem_base_path[0] +
13088 offsetof(struct shmem_region,
13089 port_mb[PORT_0].ext_phy_fw_version));
13090 if (phy_ver) {
13091 DP(NETIF_MSG_LINK, "Not doing common init; phy ver is 0x%x\n",
13092 phy_ver);
13093 return 0;
13094 }
13095
Yaniv Rosnera22f0782010-09-07 11:41:20 +000013096 /* Read the ext_phy_type for arbitrary port(0) */
13097 for (phy_index = EXT_PHY1; phy_index < MAX_PHYS;
13098 phy_index++) {
13099 ext_phy_config = bnx2x_get_ext_phy_config(bp,
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000013100 shmem_base_path[0],
Yaniv Rosnera22f0782010-09-07 11:41:20 +000013101 phy_index, 0);
13102 ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +000013103 rc |= bnx2x_ext_phy_common_init(bp, shmem_base_path,
13104 shmem2_base_path,
13105 phy_index, ext_phy_type,
13106 chip_id);
Yaniv Rosnera22f0782010-09-07 11:41:20 +000013107 }
13108 return rc;
13109}
13110
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013111static void bnx2x_check_over_curr(struct link_params *params,
13112 struct link_vars *vars)
13113{
13114 struct bnx2x *bp = params->bp;
13115 u32 cfg_pin;
13116 u8 port = params->port;
13117 u32 pin_val;
13118
13119 cfg_pin = (REG_RD(bp, params->shmem_base +
13120 offsetof(struct shmem_region,
13121 dev_info.port_hw_config[port].e3_cmn_pin_cfg1)) &
13122 PORT_HW_CFG_E3_OVER_CURRENT_MASK) >>
13123 PORT_HW_CFG_E3_OVER_CURRENT_SHIFT;
13124
13125 /* Ignore check if no external input PIN available */
13126 if (bnx2x_get_cfg_pin(bp, cfg_pin, &pin_val) != 0)
13127 return;
13128
13129 if (!pin_val) {
13130 if ((vars->phy_flags & PHY_OVER_CURRENT_FLAG) == 0) {
13131 netdev_err(bp->dev, "Error: Power fault on Port %d has"
13132 " been detected and the power to "
13133 "that SFP+ module has been removed"
13134 " to prevent failure of the card."
13135 " Please remove the SFP+ module and"
13136 " restart the system to clear this"
13137 " error.\n",
13138 params->port);
13139 vars->phy_flags |= PHY_OVER_CURRENT_FLAG;
Yaniv Rosner5a1fbf42012-11-27 03:46:31 +000013140 bnx2x_warpcore_power_module(params, 0);
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013141 }
13142 } else
13143 vars->phy_flags &= ~PHY_OVER_CURRENT_FLAG;
13144}
13145
Yuval Mintzd0b8a6f2012-06-20 19:05:18 +000013146/* Returns 0 if no change occured since last check; 1 otherwise. */
13147static u8 bnx2x_analyze_link_error(struct link_params *params,
13148 struct link_vars *vars, u32 status,
13149 u32 phy_flag, u32 link_flag, u8 notify)
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013150{
13151 struct bnx2x *bp = params->bp;
13152 /* Compare new value with previous value */
13153 u8 led_mode;
Yuval Mintzd0b8a6f2012-06-20 19:05:18 +000013154 u32 old_status = (vars->phy_flags & phy_flag) ? 1 : 0;
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013155
Yuval Mintzd0b8a6f2012-06-20 19:05:18 +000013156 if ((status ^ old_status) == 0)
13157 return 0;
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013158
13159 /* If values differ */
Yuval Mintzd0b8a6f2012-06-20 19:05:18 +000013160 switch (phy_flag) {
13161 case PHY_HALF_OPEN_CONN_FLAG:
13162 DP(NETIF_MSG_LINK, "Analyze Remote Fault\n");
13163 break;
13164 case PHY_SFP_TX_FAULT_FLAG:
13165 DP(NETIF_MSG_LINK, "Analyze TX Fault\n");
13166 break;
13167 default:
Masanari Iidaefc7ce02012-11-02 04:36:17 +000013168 DP(NETIF_MSG_LINK, "Analyze UNKNOWN\n");
Yuval Mintzd0b8a6f2012-06-20 19:05:18 +000013169 }
13170 DP(NETIF_MSG_LINK, "Link changed:[%x %x]->%x\n", vars->link_up,
13171 old_status, status);
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013172
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000013173 /* a. Update shmem->link_status accordingly
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013174 * b. Update link_vars->link_up
13175 */
Yuval Mintzd0b8a6f2012-06-20 19:05:18 +000013176 if (status) {
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013177 vars->link_status &= ~LINK_STATUS_LINK_UP;
Yuval Mintzd0b8a6f2012-06-20 19:05:18 +000013178 vars->link_status |= link_flag;
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013179 vars->link_up = 0;
Yuval Mintzd0b8a6f2012-06-20 19:05:18 +000013180 vars->phy_flags |= phy_flag;
Yaniv Rosner55098c52012-04-03 18:41:27 +000013181
13182 /* activate nig drain */
13183 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 1);
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000013184 /* Set LED mode to off since the PHY doesn't know about these
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013185 * errors
13186 */
13187 led_mode = LED_MODE_OFF;
13188 } else {
13189 vars->link_status |= LINK_STATUS_LINK_UP;
Yuval Mintzd0b8a6f2012-06-20 19:05:18 +000013190 vars->link_status &= ~link_flag;
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013191 vars->link_up = 1;
Yuval Mintzd0b8a6f2012-06-20 19:05:18 +000013192 vars->phy_flags &= ~phy_flag;
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013193 led_mode = LED_MODE_OPER;
Yaniv Rosner55098c52012-04-03 18:41:27 +000013194
13195 /* Clear nig drain */
13196 REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 0);
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013197 }
Yaniv Rosner55098c52012-04-03 18:41:27 +000013198 bnx2x_sync_link(params, vars);
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013199 /* Update the LED according to the link state */
13200 bnx2x_set_led(params, vars, led_mode, SPEED_10000);
13201
13202 /* Update link status in the shared memory */
13203 bnx2x_update_mng(params, vars->link_status);
13204
13205 /* C. Trigger General Attention */
13206 vars->periodic_flags |= PERIODIC_FLAGS_LINK_EVENT;
Yaniv Rosner55098c52012-04-03 18:41:27 +000013207 if (notify)
13208 bnx2x_notify_link_changed(bp);
Yuval Mintzd0b8a6f2012-06-20 19:05:18 +000013209
13210 return 1;
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013211}
13212
Yaniv Rosnerde6f3372011-08-02 22:59:25 +000013213/******************************************************************************
13214* Description:
13215* This function checks for half opened connection change indication.
13216* When such change occurs, it calls the bnx2x_analyze_link_error
13217* to check if Remote Fault is set or cleared. Reception of remote fault
13218* status message in the MAC indicates that the peer's MAC has detected
13219* a fault, for example, due to break in the TX side of fiber.
13220*
13221******************************************************************************/
Yaniv Rosner55098c52012-04-03 18:41:27 +000013222int bnx2x_check_half_open_conn(struct link_params *params,
13223 struct link_vars *vars,
13224 u8 notify)
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013225{
13226 struct bnx2x *bp = params->bp;
13227 u32 lss_status = 0;
13228 u32 mac_base;
13229 /* In case link status is physically up @ 10G do */
Yaniv Rosner55098c52012-04-03 18:41:27 +000013230 if (((vars->phy_flags & PHY_PHYSICAL_LINK_FLAG) == 0) ||
13231 (REG_RD(bp, NIG_REG_EGRESS_EMAC0_PORT + params->port*4)))
13232 return 0;
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013233
Yaniv Rosnerde6f3372011-08-02 22:59:25 +000013234 if (CHIP_IS_E3(bp) &&
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013235 (REG_RD(bp, MISC_REG_RESET_REG_2) &
Yaniv Rosnerde6f3372011-08-02 22:59:25 +000013236 (MISC_REGISTERS_RESET_REG_2_XMAC))) {
13237 /* Check E3 XMAC */
Yaniv Rosner8f73f0b2012-04-03 18:41:31 +000013238 /* Note that link speed cannot be queried here, since it may be
Yaniv Rosnerde6f3372011-08-02 22:59:25 +000013239 * zero while link is down. In case UMAC is active, LSS will
13240 * simply not be set
13241 */
13242 mac_base = (params->port) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
13243
13244 /* Clear stick bits (Requires rising edge) */
13245 REG_WR(bp, mac_base + XMAC_REG_CLEAR_RX_LSS_STATUS, 0);
13246 REG_WR(bp, mac_base + XMAC_REG_CLEAR_RX_LSS_STATUS,
13247 XMAC_CLEAR_RX_LSS_STATUS_REG_CLEAR_LOCAL_FAULT_STATUS |
13248 XMAC_CLEAR_RX_LSS_STATUS_REG_CLEAR_REMOTE_FAULT_STATUS);
13249 if (REG_RD(bp, mac_base + XMAC_REG_RX_LSS_STATUS))
13250 lss_status = 1;
13251
Yuval Mintzd0b8a6f2012-06-20 19:05:18 +000013252 bnx2x_analyze_link_error(params, vars, lss_status,
13253 PHY_HALF_OPEN_CONN_FLAG,
13254 LINK_STATUS_NONE, notify);
Yaniv Rosnerde6f3372011-08-02 22:59:25 +000013255 } else if (REG_RD(bp, MISC_REG_RESET_REG_2) &
13256 (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << params->port)) {
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013257 /* Check E1X / E2 BMAC */
13258 u32 lss_status_reg;
13259 u32 wb_data[2];
13260 mac_base = params->port ? NIG_REG_INGRESS_BMAC1_MEM :
13261 NIG_REG_INGRESS_BMAC0_MEM;
13262 /* Read BIGMAC_REGISTER_RX_LSS_STATUS */
13263 if (CHIP_IS_E2(bp))
13264 lss_status_reg = BIGMAC2_REGISTER_RX_LSS_STAT;
13265 else
13266 lss_status_reg = BIGMAC_REGISTER_RX_LSS_STATUS;
13267
13268 REG_RD_DMAE(bp, mac_base + lss_status_reg, wb_data, 2);
13269 lss_status = (wb_data[0] > 0);
13270
Yuval Mintzd0b8a6f2012-06-20 19:05:18 +000013271 bnx2x_analyze_link_error(params, vars, lss_status,
13272 PHY_HALF_OPEN_CONN_FLAG,
13273 LINK_STATUS_NONE, notify);
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013274 }
Yaniv Rosner55098c52012-04-03 18:41:27 +000013275 return 0;
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013276}
Yuval Mintzd0b8a6f2012-06-20 19:05:18 +000013277static void bnx2x_sfp_tx_fault_detection(struct bnx2x_phy *phy,
13278 struct link_params *params,
13279 struct link_vars *vars)
13280{
13281 struct bnx2x *bp = params->bp;
13282 u32 cfg_pin, value = 0;
13283 u8 led_change, port = params->port;
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013284
Yuval Mintzd0b8a6f2012-06-20 19:05:18 +000013285 /* Get The SFP+ TX_Fault controlling pin ([eg]pio) */
13286 cfg_pin = (REG_RD(bp, params->shmem_base + offsetof(struct shmem_region,
13287 dev_info.port_hw_config[port].e3_cmn_pin_cfg)) &
13288 PORT_HW_CFG_E3_TX_FAULT_MASK) >>
13289 PORT_HW_CFG_E3_TX_FAULT_SHIFT;
13290
13291 if (bnx2x_get_cfg_pin(bp, cfg_pin, &value)) {
13292 DP(NETIF_MSG_LINK, "Failed to read pin 0x%02x\n", cfg_pin);
13293 return;
13294 }
13295
13296 led_change = bnx2x_analyze_link_error(params, vars, value,
13297 PHY_SFP_TX_FAULT_FLAG,
13298 LINK_STATUS_SFP_TX_FAULT, 1);
13299
13300 if (led_change) {
13301 /* Change TX_Fault led, set link status for further syncs */
13302 u8 led_mode;
13303
13304 if (vars->phy_flags & PHY_SFP_TX_FAULT_FLAG) {
13305 led_mode = MISC_REGISTERS_GPIO_HIGH;
13306 vars->link_status |= LINK_STATUS_SFP_TX_FAULT;
13307 } else {
13308 led_mode = MISC_REGISTERS_GPIO_LOW;
13309 vars->link_status &= ~LINK_STATUS_SFP_TX_FAULT;
13310 }
13311
13312 /* If module is unapproved, led should be on regardless */
13313 if (!(phy->flags & FLAGS_SFP_NOT_APPROVED)) {
13314 DP(NETIF_MSG_LINK, "Change TX_Fault LED: ->%x\n",
13315 led_mode);
13316 bnx2x_set_e3_module_fault_led(params, led_mode);
13317 }
13318 }
13319}
Yaniv Rosner4e7b4992012-11-27 03:46:29 +000013320static void bnx2x_disable_kr2(struct link_params *params,
13321 struct link_vars *vars,
13322 struct bnx2x_phy *phy)
13323{
13324 struct bnx2x *bp = params->bp;
13325 int i;
13326 static struct bnx2x_reg_set reg_set[] = {
13327 /* Step 1 - Program the TX/RX alignment markers */
13328 {MDIO_WC_DEVAD, MDIO_WC_REG_CL82_USERB1_TX_CTRL5, 0x7690},
13329 {MDIO_WC_DEVAD, MDIO_WC_REG_CL82_USERB1_TX_CTRL7, 0xe647},
13330 {MDIO_WC_DEVAD, MDIO_WC_REG_CL82_USERB1_TX_CTRL6, 0xc4f0},
13331 {MDIO_WC_DEVAD, MDIO_WC_REG_CL82_USERB1_TX_CTRL9, 0x7690},
13332 {MDIO_WC_DEVAD, MDIO_WC_REG_CL82_USERB1_RX_CTRL11, 0xe647},
13333 {MDIO_WC_DEVAD, MDIO_WC_REG_CL82_USERB1_RX_CTRL10, 0xc4f0},
13334 {MDIO_WC_DEVAD, MDIO_WC_REG_CL73_USERB0_CTRL, 0x000c},
13335 {MDIO_WC_DEVAD, MDIO_WC_REG_CL73_BAM_CTRL1, 0x6000},
13336 {MDIO_WC_DEVAD, MDIO_WC_REG_CL73_BAM_CTRL3, 0x0000},
13337 {MDIO_WC_DEVAD, MDIO_WC_REG_CL73_BAM_CODE_FIELD, 0x0002},
13338 {MDIO_WC_DEVAD, MDIO_WC_REG_ETA_CL73_OUI1, 0x0000},
13339 {MDIO_WC_DEVAD, MDIO_WC_REG_ETA_CL73_OUI2, 0x0af7},
13340 {MDIO_WC_DEVAD, MDIO_WC_REG_ETA_CL73_OUI3, 0x0af7},
13341 {MDIO_WC_DEVAD, MDIO_WC_REG_ETA_CL73_LD_BAM_CODE, 0x0002},
13342 {MDIO_WC_DEVAD, MDIO_WC_REG_ETA_CL73_LD_UD_CODE, 0x0000}
13343 };
13344 DP(NETIF_MSG_LINK, "Disabling 20G-KR2\n");
13345
Sasha Levinb5a05552012-12-20 09:11:24 +000013346 for (i = 0; i < ARRAY_SIZE(reg_set); i++)
Yaniv Rosner4e7b4992012-11-27 03:46:29 +000013347 bnx2x_cl45_write(bp, phy, reg_set[i].devad, reg_set[i].reg,
13348 reg_set[i].val);
13349 vars->link_attr_sync &= ~LINK_ATTR_SYNC_KR2_ENABLE;
13350 bnx2x_update_link_attr(params, vars->link_attr_sync);
13351
13352 /* Restart AN on leading lane */
13353 bnx2x_warpcore_restart_AN_KR(phy, params);
13354}
13355
13356static void bnx2x_kr2_recovery(struct link_params *params,
13357 struct link_vars *vars,
13358 struct bnx2x_phy *phy)
13359{
13360 struct bnx2x *bp = params->bp;
13361 DP(NETIF_MSG_LINK, "KR2 recovery\n");
13362 bnx2x_warpcore_enable_AN_KR2(phy, params, vars);
13363 bnx2x_warpcore_restart_AN_KR(phy, params);
13364}
13365
13366static void bnx2x_check_kr2_wa(struct link_params *params,
13367 struct link_vars *vars,
13368 struct bnx2x_phy *phy)
13369{
13370 struct bnx2x *bp = params->bp;
13371 u16 base_page, next_page, not_kr2_device, lane;
13372 int sigdet = bnx2x_warpcore_get_sigdet(phy, params);
13373
13374 if (!sigdet) {
13375 if (!(vars->link_attr_sync & LINK_ATTR_SYNC_KR2_ENABLE))
13376 bnx2x_kr2_recovery(params, vars, phy);
13377 return;
13378 }
13379
13380 lane = bnx2x_get_warpcore_lane(phy, params);
13381 CL22_WR_OVER_CL45(bp, phy, MDIO_REG_BANK_AER_BLOCK,
13382 MDIO_AER_BLOCK_AER_REG, lane);
13383 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
13384 MDIO_AN_REG_LP_AUTO_NEG, &base_page);
13385 bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
13386 MDIO_AN_REG_LP_AUTO_NEG2, &next_page);
13387 bnx2x_set_aer_mmd(params, phy);
13388
13389 /* CL73 has not begun yet */
13390 if (base_page == 0) {
13391 if (!(vars->link_attr_sync & LINK_ATTR_SYNC_KR2_ENABLE))
13392 bnx2x_kr2_recovery(params, vars, phy);
13393 return;
13394 }
13395
13396 /* In case NP bit is not set in the BasePage, or it is set,
13397 * but only KX is advertised, declare this link partner as non-KR2
13398 * device.
13399 */
13400 not_kr2_device = (((base_page & 0x8000) == 0) ||
13401 (((base_page & 0x8000) &&
13402 ((next_page & 0xe0) == 0x2))));
13403
13404 /* In case KR2 is already disabled, check if we need to re-enable it */
13405 if (!(vars->link_attr_sync & LINK_ATTR_SYNC_KR2_ENABLE)) {
13406 if (!not_kr2_device) {
13407 DP(NETIF_MSG_LINK, "BP=0x%x, NP=0x%x\n", base_page,
Yaniv Rosnerfd5dfca2012-11-27 03:46:36 +000013408 next_page);
Yaniv Rosner4e7b4992012-11-27 03:46:29 +000013409 bnx2x_kr2_recovery(params, vars, phy);
13410 }
13411 return;
13412 }
13413 /* KR2 is enabled, but not KR2 device */
13414 if (not_kr2_device) {
13415 /* Disable KR2 on both lanes */
13416 DP(NETIF_MSG_LINK, "BP=0x%x, NP=0x%x\n", base_page, next_page);
13417 bnx2x_disable_kr2(params, vars, phy);
13418 return;
13419 }
13420}
13421
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013422void bnx2x_period_func(struct link_params *params, struct link_vars *vars)
13423{
Yaniv Rosnerde6f3372011-08-02 22:59:25 +000013424 u16 phy_idx;
Yaniv Rosner55098c52012-04-03 18:41:27 +000013425 struct bnx2x *bp = params->bp;
Yaniv Rosnerde6f3372011-08-02 22:59:25 +000013426 for (phy_idx = INT_PHY; phy_idx < MAX_PHYS; phy_idx++) {
13427 if (params->phy[phy_idx].flags & FLAGS_TX_ERROR_CHECK) {
13428 bnx2x_set_aer_mmd(params, &params->phy[phy_idx]);
Yaniv Rosner55098c52012-04-03 18:41:27 +000013429 if (bnx2x_check_half_open_conn(params, vars, 1) !=
13430 0)
13431 DP(NETIF_MSG_LINK, "Fault detection failed\n");
Yaniv Rosnerde6f3372011-08-02 22:59:25 +000013432 break;
13433 }
13434 }
13435
Yaniv Rosnera9077bf2011-10-27 05:09:46 +000013436 if (CHIP_IS_E3(bp)) {
13437 struct bnx2x_phy *phy = &params->phy[INT_PHY];
13438 bnx2x_set_aer_mmd(params, phy);
Yaniv Rosner4e7b4992012-11-27 03:46:29 +000013439 if ((phy->supported & SUPPORTED_20000baseKR2_Full) &&
13440 (phy->speed_cap_mask & SPEED_20000))
13441 bnx2x_check_kr2_wa(params, vars, phy);
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013442 bnx2x_check_over_curr(params, vars);
Yuval Mintzd0b8a6f2012-06-20 19:05:18 +000013443 if (vars->rx_tx_asic_rst)
13444 bnx2x_warpcore_config_runtime(phy, params, vars);
13445
13446 if ((REG_RD(bp, params->shmem_base +
13447 offsetof(struct shmem_region, dev_info.
13448 port_hw_config[params->port].default_cfg))
13449 & PORT_HW_CFG_NET_SERDES_IF_MASK) ==
13450 PORT_HW_CFG_NET_SERDES_IF_SFI) {
13451 if (bnx2x_is_sfp_module_plugged(phy, params)) {
13452 bnx2x_sfp_tx_fault_detection(phy, params, vars);
13453 } else if (vars->link_status &
13454 LINK_STATUS_SFP_TX_FAULT) {
13455 /* Clean trail, interrupt corrects the leds */
13456 vars->link_status &= ~LINK_STATUS_SFP_TX_FAULT;
13457 vars->phy_flags &= ~PHY_SFP_TX_FAULT_FLAG;
13458 /* Update link status in the shared memory */
13459 bnx2x_update_mng(params, vars->link_status);
13460 }
13461 }
Yaniv Rosnera9077bf2011-10-27 05:09:46 +000013462 }
Yaniv Rosner3deb8162011-06-14 01:34:33 +000013463}
13464
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +000013465u8 bnx2x_fan_failure_det_req(struct bnx2x *bp,
13466 u32 shmem_base,
Yaniv Rosnera22f0782010-09-07 11:41:20 +000013467 u32 shmem2_base,
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +000013468 u8 port)
13469{
13470 u8 phy_index, fan_failure_det_req = 0;
13471 struct bnx2x_phy phy;
13472 for (phy_index = EXT_PHY1; phy_index < MAX_PHYS;
13473 phy_index++) {
Yaniv Rosnera22f0782010-09-07 11:41:20 +000013474 if (bnx2x_populate_phy(bp, phy_index, shmem_base, shmem2_base,
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +000013475 port, &phy)
13476 != 0) {
13477 DP(NETIF_MSG_LINK, "populate phy failed\n");
13478 return 0;
13479 }
13480 fan_failure_det_req |= (phy.flags &
13481 FLAGS_FAN_FAILURE_DET_REQ);
13482 }
13483 return fan_failure_det_req;
13484}
13485
13486void bnx2x_hw_reset_phy(struct link_params *params)
13487{
13488 u8 phy_index;
Yaniv Rosner985848f2011-07-05 01:06:48 +000013489 struct bnx2x *bp = params->bp;
13490 bnx2x_update_mng(params, 0);
13491 bnx2x_bits_dis(bp, NIG_REG_MASK_INTERRUPT_PORT0 + params->port*4,
13492 (NIG_MASK_XGXS0_LINK_STATUS |
13493 NIG_MASK_XGXS0_LINK10G |
13494 NIG_MASK_SERDES0_LINK_STATUS |
13495 NIG_MASK_MI_INT));
13496
13497 for (phy_index = INT_PHY; phy_index < MAX_PHYS;
Yaniv Rosnerd90d96b2010-09-07 11:41:04 +000013498 phy_index++) {
13499 if (params->phy[phy_index].hw_reset) {
13500 params->phy[phy_index].hw_reset(
13501 &params->phy[phy_index],
13502 params);
13503 params->phy[phy_index] = phy_null;
13504 }
13505 }
13506}
Yaniv Rosner020c7e32011-05-31 21:28:43 +000013507
13508void bnx2x_init_mod_abs_int(struct bnx2x *bp, struct link_vars *vars,
13509 u32 chip_id, u32 shmem_base, u32 shmem2_base,
13510 u8 port)
13511{
13512 u8 gpio_num = 0xff, gpio_port = 0xff, phy_index;
13513 u32 val;
13514 u32 offset, aeu_mask, swap_val, swap_override, sync_offset;
Yaniv Rosner3c9ada22011-06-14 01:34:12 +000013515 if (CHIP_IS_E3(bp)) {
13516 if (bnx2x_get_mod_abs_int_cfg(bp, chip_id,
13517 shmem_base,
13518 port,
13519 &gpio_num,
13520 &gpio_port) != 0)
13521 return;
13522 } else {
Yaniv Rosner020c7e32011-05-31 21:28:43 +000013523 struct bnx2x_phy phy;
13524 for (phy_index = EXT_PHY1; phy_index < MAX_PHYS;
13525 phy_index++) {
13526 if (bnx2x_populate_phy(bp, phy_index, shmem_base,
13527 shmem2_base, port, &phy)
13528 != 0) {
13529 DP(NETIF_MSG_LINK, "populate phy failed\n");
13530 return;
13531 }
13532 if (phy.type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726) {
13533 gpio_num = MISC_REGISTERS_GPIO_3;
13534 gpio_port = port;
13535 break;
13536 }
13537 }
13538 }
13539
13540 if (gpio_num == 0xff)
13541 return;
13542
13543 /* Set GPIO3 to trigger SFP+ module insertion/removal */
13544 bnx2x_set_gpio(bp, gpio_num, MISC_REGISTERS_GPIO_INPUT_HI_Z, gpio_port);
13545
13546 swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
13547 swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
13548 gpio_port ^= (swap_val && swap_override);
13549
13550 vars->aeu_int_mask = AEU_INPUTS_ATTN_BITS_GPIO0_FUNCTION_0 <<
13551 (gpio_num + (gpio_port << 2));
13552
13553 sync_offset = shmem_base +
13554 offsetof(struct shmem_region,
13555 dev_info.port_hw_config[port].aeu_int_mask);
13556 REG_WR(bp, sync_offset, vars->aeu_int_mask);
13557
13558 DP(NETIF_MSG_LINK, "Setting MOD_ABS (GPIO%d_P%d) AEU to 0x%x\n",
13559 gpio_num, gpio_port, vars->aeu_int_mask);
13560
13561 if (port == 0)
13562 offset = MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0;
13563 else
13564 offset = MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0;
13565
13566 /* Open appropriate AEU for interrupts */
13567 aeu_mask = REG_RD(bp, offset);
13568 aeu_mask |= vars->aeu_int_mask;
13569 REG_WR(bp, offset, aeu_mask);
13570
13571 /* Enable the GPIO to trigger interrupt */
13572 val = REG_RD(bp, MISC_REG_GPIO_EVENT_EN);
13573 val |= 1 << (gpio_num + (gpio_port << 2));
13574 REG_WR(bp, MISC_REG_GPIO_EVENT_EN, val);
13575}