mlx5: prefetch next Tx mbuf header and data
[dpdk.git] / drivers / net / bnx2x / elink.c
1 /*
2  * Copyright (c) 2007-2013 QLogic Corporation. All rights reserved.
3  *
4  * Eric Davis        <edavis@broadcom.com>
5  * David Christensen <davidch@broadcom.com>
6  * Gary Zambrano     <zambrano@broadcom.com>
7  *
8  * Copyright (c) 2013-2015 Brocade Communications Systems, Inc.
9  * Copyright (c) 2015 QLogic Corporation.
10  * All rights reserved.
11  * www.qlogic.com
12  *
13  * See LICENSE.bnx2x_pmd for copyright and licensing details.
14  */
15
16 #include "bnx2x.h"
17 #include "elink.h"
18 #include "ecore_mfw_req.h"
19 #include "ecore_fw_defs.h"
20 #include "ecore_hsi.h"
21 #include "ecore_reg.h"
22
23 static elink_status_t elink_link_reset(struct elink_params *params,
24                                        struct elink_vars *vars,
25                                        uint8_t reset_ext_phy);
26 static elink_status_t elink_check_half_open_conn(struct elink_params *params,
27                                                  struct elink_vars *vars,
28                                                  uint8_t notify);
29 static elink_status_t elink_sfp_module_detection(struct elink_phy *phy,
30                                                  struct elink_params *params);
31
32 #define MDIO_REG_BANK_CL73_IEEEB0                       0x0
33 #define MDIO_CL73_IEEEB0_CL73_AN_CONTROL                0x0
34 #define MDIO_CL73_IEEEB0_CL73_AN_CONTROL_RESTART_AN     0x0200
35 #define MDIO_CL73_IEEEB0_CL73_AN_CONTROL_AN_EN          0x1000
36 #define MDIO_CL73_IEEEB0_CL73_AN_CONTROL_MAIN_RST       0x8000
37
38 #define MDIO_REG_BANK_CL73_IEEEB1                       0x10
39 #define MDIO_CL73_IEEEB1_AN_ADV1                        0x00
40 #define MDIO_CL73_IEEEB1_AN_ADV1_PAUSE                  0x0400
41 #define MDIO_CL73_IEEEB1_AN_ADV1_ASYMMETRIC             0x0800
42 #define MDIO_CL73_IEEEB1_AN_ADV1_PAUSE_BOTH             0x0C00
43 #define MDIO_CL73_IEEEB1_AN_ADV1_PAUSE_MASK             0x0C00
44 #define MDIO_CL73_IEEEB1_AN_ADV2                                0x01
45 #define MDIO_CL73_IEEEB1_AN_ADV2_ADVR_1000M             0x0000
46 #define MDIO_CL73_IEEEB1_AN_ADV2_ADVR_1000M_KX          0x0020
47 #define MDIO_CL73_IEEEB1_AN_ADV2_ADVR_10G_KX4           0x0040
48 #define MDIO_CL73_IEEEB1_AN_ADV2_ADVR_10G_KR            0x0080
49 #define MDIO_CL73_IEEEB1_AN_LP_ADV1                     0x03
50 #define MDIO_CL73_IEEEB1_AN_LP_ADV1_PAUSE               0x0400
51 #define MDIO_CL73_IEEEB1_AN_LP_ADV1_ASYMMETRIC          0x0800
52 #define MDIO_CL73_IEEEB1_AN_LP_ADV1_PAUSE_BOTH          0x0C00
53 #define MDIO_CL73_IEEEB1_AN_LP_ADV1_PAUSE_MASK          0x0C00
54 #define MDIO_CL73_IEEEB1_AN_LP_ADV2                     0x04
55
56 #define MDIO_REG_BANK_RX0                               0x80b0
57 #define MDIO_RX0_RX_STATUS                              0x10
58 #define MDIO_RX0_RX_STATUS_SIGDET                       0x8000
59 #define MDIO_RX0_RX_STATUS_RX_SEQ_DONE                  0x1000
60 #define MDIO_RX0_RX_EQ_BOOST                            0x1c
61 #define MDIO_RX0_RX_EQ_BOOST_EQUALIZER_CTRL_MASK        0x7
62 #define MDIO_RX0_RX_EQ_BOOST_OFFSET_CTRL                0x10
63
64 #define MDIO_REG_BANK_RX1                               0x80c0
65 #define MDIO_RX1_RX_EQ_BOOST                            0x1c
66 #define MDIO_RX1_RX_EQ_BOOST_EQUALIZER_CTRL_MASK        0x7
67 #define MDIO_RX1_RX_EQ_BOOST_OFFSET_CTRL                0x10
68
69 #define MDIO_REG_BANK_RX2                               0x80d0
70 #define MDIO_RX2_RX_EQ_BOOST                            0x1c
71 #define MDIO_RX2_RX_EQ_BOOST_EQUALIZER_CTRL_MASK        0x7
72 #define MDIO_RX2_RX_EQ_BOOST_OFFSET_CTRL                0x10
73
74 #define MDIO_REG_BANK_RX3                               0x80e0
75 #define MDIO_RX3_RX_EQ_BOOST                            0x1c
76 #define MDIO_RX3_RX_EQ_BOOST_EQUALIZER_CTRL_MASK        0x7
77 #define MDIO_RX3_RX_EQ_BOOST_OFFSET_CTRL                0x10
78
79 #define MDIO_REG_BANK_RX_ALL                            0x80f0
80 #define MDIO_RX_ALL_RX_EQ_BOOST                         0x1c
81 #define MDIO_RX_ALL_RX_EQ_BOOST_EQUALIZER_CTRL_MASK     0x7
82 #define MDIO_RX_ALL_RX_EQ_BOOST_OFFSET_CTRL     0x10
83
84 #define MDIO_REG_BANK_TX0                               0x8060
85 #define MDIO_TX0_TX_DRIVER                              0x17
86 #define MDIO_TX0_TX_DRIVER_PREEMPHASIS_MASK             0xf000
87 #define MDIO_TX0_TX_DRIVER_PREEMPHASIS_SHIFT            12
88 #define MDIO_TX0_TX_DRIVER_IDRIVER_MASK                 0x0f00
89 #define MDIO_TX0_TX_DRIVER_IDRIVER_SHIFT                8
90 #define MDIO_TX0_TX_DRIVER_IPREDRIVER_MASK              0x00f0
91 #define MDIO_TX0_TX_DRIVER_IPREDRIVER_SHIFT             4
92 #define MDIO_TX0_TX_DRIVER_IFULLSPD_MASK                0x000e
93 #define MDIO_TX0_TX_DRIVER_IFULLSPD_SHIFT               1
94 #define MDIO_TX0_TX_DRIVER_ICBUF1T                      1
95
96 #define MDIO_REG_BANK_TX1                               0x8070
97 #define MDIO_TX1_TX_DRIVER                              0x17
98 #define MDIO_TX0_TX_DRIVER_PREEMPHASIS_MASK             0xf000
99 #define MDIO_TX0_TX_DRIVER_PREEMPHASIS_SHIFT            12
100 #define MDIO_TX0_TX_DRIVER_IDRIVER_MASK                 0x0f00
101 #define MDIO_TX0_TX_DRIVER_IDRIVER_SHIFT                8
102 #define MDIO_TX0_TX_DRIVER_IPREDRIVER_MASK              0x00f0
103 #define MDIO_TX0_TX_DRIVER_IPREDRIVER_SHIFT             4
104 #define MDIO_TX0_TX_DRIVER_IFULLSPD_MASK                0x000e
105 #define MDIO_TX0_TX_DRIVER_IFULLSPD_SHIFT               1
106 #define MDIO_TX0_TX_DRIVER_ICBUF1T                      1
107
108 #define MDIO_REG_BANK_TX2                               0x8080
109 #define MDIO_TX2_TX_DRIVER                              0x17
110 #define MDIO_TX0_TX_DRIVER_PREEMPHASIS_MASK             0xf000
111 #define MDIO_TX0_TX_DRIVER_PREEMPHASIS_SHIFT            12
112 #define MDIO_TX0_TX_DRIVER_IDRIVER_MASK                 0x0f00
113 #define MDIO_TX0_TX_DRIVER_IDRIVER_SHIFT                8
114 #define MDIO_TX0_TX_DRIVER_IPREDRIVER_MASK              0x00f0
115 #define MDIO_TX0_TX_DRIVER_IPREDRIVER_SHIFT             4
116 #define MDIO_TX0_TX_DRIVER_IFULLSPD_MASK                0x000e
117 #define MDIO_TX0_TX_DRIVER_IFULLSPD_SHIFT               1
118 #define MDIO_TX0_TX_DRIVER_ICBUF1T                      1
119
120 #define MDIO_REG_BANK_TX3                               0x8090
121 #define MDIO_TX3_TX_DRIVER                              0x17
122 #define MDIO_TX0_TX_DRIVER_PREEMPHASIS_MASK             0xf000
123 #define MDIO_TX0_TX_DRIVER_PREEMPHASIS_SHIFT            12
124 #define MDIO_TX0_TX_DRIVER_IDRIVER_MASK                 0x0f00
125 #define MDIO_TX0_TX_DRIVER_IDRIVER_SHIFT                8
126 #define MDIO_TX0_TX_DRIVER_IPREDRIVER_MASK              0x00f0
127 #define MDIO_TX0_TX_DRIVER_IPREDRIVER_SHIFT             4
128 #define MDIO_TX0_TX_DRIVER_IFULLSPD_MASK                0x000e
129 #define MDIO_TX0_TX_DRIVER_IFULLSPD_SHIFT               1
130 #define MDIO_TX0_TX_DRIVER_ICBUF1T                      1
131
132 #define MDIO_REG_BANK_XGXS_BLOCK0                       0x8000
133 #define MDIO_BLOCK0_XGXS_CONTROL                        0x10
134
135 #define MDIO_REG_BANK_XGXS_BLOCK1                       0x8010
136 #define MDIO_BLOCK1_LANE_CTRL0                          0x15
137 #define MDIO_BLOCK1_LANE_CTRL1                          0x16
138 #define MDIO_BLOCK1_LANE_CTRL2                          0x17
139 #define MDIO_BLOCK1_LANE_PRBS                           0x19
140
141 #define MDIO_REG_BANK_XGXS_BLOCK2                       0x8100
142 #define MDIO_XGXS_BLOCK2_RX_LN_SWAP                     0x10
143 #define MDIO_XGXS_BLOCK2_RX_LN_SWAP_ENABLE              0x8000
144 #define MDIO_XGXS_BLOCK2_RX_LN_SWAP_FORCE_ENABLE        0x4000
145 #define MDIO_XGXS_BLOCK2_TX_LN_SWAP             0x11
146 #define MDIO_XGXS_BLOCK2_TX_LN_SWAP_ENABLE              0x8000
147 #define MDIO_XGXS_BLOCK2_UNICORE_MODE_10G       0x14
148 #define MDIO_XGXS_BLOCK2_UNICORE_MODE_10G_CX4_XGXS      0x0001
149 #define MDIO_XGXS_BLOCK2_UNICORE_MODE_10G_HIGIG_XGXS    0x0010
150 #define MDIO_XGXS_BLOCK2_TEST_MODE_LANE         0x15
151
152 #define MDIO_REG_BANK_GP_STATUS                         0x8120
153 #define MDIO_GP_STATUS_TOP_AN_STATUS1                           0x1B
154 #define MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_AUTONEG_COMPLETE     0x0001
155 #define MDIO_GP_STATUS_TOP_AN_STATUS1_CL37_AUTONEG_COMPLETE     0x0002
156 #define MDIO_GP_STATUS_TOP_AN_STATUS1_LINK_STATUS               0x0004
157 #define MDIO_GP_STATUS_TOP_AN_STATUS1_DUPLEX_STATUS             0x0008
158 #define MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_MR_LP_NP_AN_ABLE     0x0010
159 #define MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_LP_NP_BAM_ABLE       0x0020
160 #define MDIO_GP_STATUS_TOP_AN_STATUS1_PAUSE_RSOLUTION_TXSIDE    0x0040
161 #define MDIO_GP_STATUS_TOP_AN_STATUS1_PAUSE_RSOLUTION_RXSIDE    0x0080
162 #define MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_MASK         0x3f00
163 #define MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10M          0x0000
164 #define MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_100M         0x0100
165 #define MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_1G           0x0200
166 #define MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_2_5G         0x0300
167 #define MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_5G           0x0400
168 #define MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_6G           0x0500
169 #define MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10G_HIG      0x0600
170 #define MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10G_CX4      0x0700
171 #define MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_12G_HIG      0x0800
172 #define MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_12_5G        0x0900
173 #define MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_13G          0x0A00
174 #define MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_15G          0x0B00
175 #define MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_16G          0x0C00
176 #define MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_1G_KX        0x0D00
177 #define MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10G_KX4      0x0E00
178 #define MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10G_KR       0x0F00
179 #define MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10G_XFI      0x1B00
180 #define MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_20G_DXGXS    0x1E00
181 #define MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10G_SFI      0x1F00
182 #define MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_20G_KR2      0x3900
183
184 #define MDIO_REG_BANK_10G_PARALLEL_DETECT               0x8130
185 #define MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_STATUS             0x10
186 #define MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_STATUS_PD_LINK             0x8000
187 #define MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_CONTROL            0x11
188 #define MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_CONTROL_PARDET10G_EN       0x1
189 #define MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_LINK               0x13
190 #define MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_LINK_CNT           (0xb71<<1)
191
192 #define MDIO_REG_BANK_SERDES_DIGITAL                    0x8300
193 #define MDIO_SERDES_DIGITAL_A_1000X_CONTROL1                    0x10
194 #define MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_FIBER_MODE                 0x0001
195 #define MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_TBI_IF                     0x0002
196 #define MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_SIGNAL_DETECT_EN           0x0004
197 #define MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_INVERT_SIGNAL_DETECT       0x0008
198 #define MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_AUTODET                    0x0010
199 #define MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_MSTR_MODE                  0x0020
200 #define MDIO_SERDES_DIGITAL_A_1000X_CONTROL2                    0x11
201 #define MDIO_SERDES_DIGITAL_A_1000X_CONTROL2_PRL_DT_EN                  0x0001
202 #define MDIO_SERDES_DIGITAL_A_1000X_CONTROL2_AN_FST_TMR                 0x0040
203 #define MDIO_SERDES_DIGITAL_A_1000X_STATUS1                     0x14
204 #define MDIO_SERDES_DIGITAL_A_1000X_STATUS1_SGMII                       0x0001
205 #define MDIO_SERDES_DIGITAL_A_1000X_STATUS1_LINK                        0x0002
206 #define MDIO_SERDES_DIGITAL_A_1000X_STATUS1_DUPLEX                      0x0004
207 #define MDIO_SERDES_DIGITAL_A_1000X_STATUS1_SPEED_MASK                  0x0018
208 #define MDIO_SERDES_DIGITAL_A_1000X_STATUS1_SPEED_SHIFT                 3
209 #define MDIO_SERDES_DIGITAL_A_1000X_STATUS1_SPEED_2_5G                  0x0018
210 #define MDIO_SERDES_DIGITAL_A_1000X_STATUS1_SPEED_1G                    0x0010
211 #define MDIO_SERDES_DIGITAL_A_1000X_STATUS1_SPEED_100M                  0x0008
212 #define MDIO_SERDES_DIGITAL_A_1000X_STATUS1_SPEED_10M                   0x0000
213 #define MDIO_SERDES_DIGITAL_A_1000X_STATUS2                     0x15
214 #define MDIO_SERDES_DIGITAL_A_1000X_STATUS2_AN_DISABLED                 0x0002
215 #define MDIO_SERDES_DIGITAL_MISC1                               0x18
216 #define MDIO_SERDES_DIGITAL_MISC1_REFCLK_SEL_MASK                       0xE000
217 #define MDIO_SERDES_DIGITAL_MISC1_REFCLK_SEL_25M                        0x0000
218 #define MDIO_SERDES_DIGITAL_MISC1_REFCLK_SEL_100M                       0x2000
219 #define MDIO_SERDES_DIGITAL_MISC1_REFCLK_SEL_125M                       0x4000
220 #define MDIO_SERDES_DIGITAL_MISC1_REFCLK_SEL_156_25M                    0x6000
221 #define MDIO_SERDES_DIGITAL_MISC1_REFCLK_SEL_187_5M                     0x8000
222 #define MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_SEL                       0x0010
223 #define MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_MASK                      0x000f
224 #define MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_2_5G                      0x0000
225 #define MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_5G                        0x0001
226 #define MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_6G                        0x0002
227 #define MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_10G_HIG                   0x0003
228 #define MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_10G_CX4                   0x0004
229 #define MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_12G                       0x0005
230 #define MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_12_5G                     0x0006
231 #define MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_13G                       0x0007
232 #define MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_15G                       0x0008
233 #define MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_16G                       0x0009
234
235 #define MDIO_REG_BANK_OVER_1G                           0x8320
236 #define MDIO_OVER_1G_DIGCTL_3_4                                 0x14
237 #define MDIO_OVER_1G_DIGCTL_3_4_MP_ID_MASK                              0xffe0
238 #define MDIO_OVER_1G_DIGCTL_3_4_MP_ID_SHIFT                             5
239 #define MDIO_OVER_1G_UP1                                        0x19
240 #define MDIO_OVER_1G_UP1_2_5G                                           0x0001
241 #define MDIO_OVER_1G_UP1_5G                                             0x0002
242 #define MDIO_OVER_1G_UP1_6G                                             0x0004
243 #define MDIO_OVER_1G_UP1_10G                                            0x0010
244 #define MDIO_OVER_1G_UP1_10GH                                           0x0008
245 #define MDIO_OVER_1G_UP1_12G                                            0x0020
246 #define MDIO_OVER_1G_UP1_12_5G                                          0x0040
247 #define MDIO_OVER_1G_UP1_13G                                            0x0080
248 #define MDIO_OVER_1G_UP1_15G                                            0x0100
249 #define MDIO_OVER_1G_UP1_16G                                            0x0200
250 #define MDIO_OVER_1G_UP2                                        0x1A
251 #define MDIO_OVER_1G_UP2_IPREDRIVER_MASK                                0x0007
252 #define MDIO_OVER_1G_UP2_IDRIVER_MASK                                   0x0038
253 #define MDIO_OVER_1G_UP2_PREEMPHASIS_MASK                               0x03C0
254 #define MDIO_OVER_1G_UP3                                        0x1B
255 #define MDIO_OVER_1G_UP3_HIGIG2                                         0x0001
256 #define MDIO_OVER_1G_LP_UP1                                     0x1C
257 #define MDIO_OVER_1G_LP_UP2                                     0x1D
258 #define MDIO_OVER_1G_LP_UP2_MR_ADV_OVER_1G_MASK                         0x03ff
259 #define MDIO_OVER_1G_LP_UP2_PREEMPHASIS_MASK                            0x0780
260 #define MDIO_OVER_1G_LP_UP2_PREEMPHASIS_SHIFT                           7
261 #define MDIO_OVER_1G_LP_UP3                                             0x1E
262
263 #define MDIO_REG_BANK_REMOTE_PHY                        0x8330
264 #define MDIO_REMOTE_PHY_MISC_RX_STATUS                          0x10
265 #define MDIO_REMOTE_PHY_MISC_RX_STATUS_CL37_FSM_RECEIVED_OVER1G_MSG     0x0010
266 #define MDIO_REMOTE_PHY_MISC_RX_STATUS_CL37_FSM_RECEIVED_BRCM_OUI_MSG   0x0600
267
268 #define MDIO_REG_BANK_BAM_NEXT_PAGE                     0x8350
269 #define MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL                   0x10
270 #define MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL_BAM_MODE                  0x0001
271 #define MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL_TETON_AN                  0x0002
272
273 #define MDIO_REG_BANK_CL73_USERB0               0x8370
274 #define MDIO_CL73_USERB0_CL73_UCTRL                             0x10
275 #define MDIO_CL73_USERB0_CL73_UCTRL_USTAT1_MUXSEL                       0x0002
276 #define MDIO_CL73_USERB0_CL73_USTAT1                            0x11
277 #define MDIO_CL73_USERB0_CL73_USTAT1_LINK_STATUS_CHECK                  0x0100
278 #define MDIO_CL73_USERB0_CL73_USTAT1_AN_GOOD_CHECK_BAM37                0x0400
279 #define MDIO_CL73_USERB0_CL73_BAM_CTRL1                         0x12
280 #define MDIO_CL73_USERB0_CL73_BAM_CTRL1_BAM_EN                          0x8000
281 #define MDIO_CL73_USERB0_CL73_BAM_CTRL1_BAM_STATION_MNGR_EN             0x4000
282 #define MDIO_CL73_USERB0_CL73_BAM_CTRL1_BAM_NP_AFTER_BP_EN              0x2000
283 #define MDIO_CL73_USERB0_CL73_BAM_CTRL3                         0x14
284 #define MDIO_CL73_USERB0_CL73_BAM_CTRL3_USE_CL73_HCD_MR                 0x0001
285
286 #define MDIO_REG_BANK_AER_BLOCK                 0xFFD0
287 #define MDIO_AER_BLOCK_AER_REG                                  0x1E
288
289 #define MDIO_REG_BANK_COMBO_IEEE0               0xFFE0
290 #define MDIO_COMBO_IEEE0_MII_CONTROL                            0x10
291 #define MDIO_COMBO_IEEO_MII_CONTROL_MAN_SGMII_SP_MASK                   0x2040
292 #define MDIO_COMBO_IEEO_MII_CONTROL_MAN_SGMII_SP_10                     0x0000
293 #define MDIO_COMBO_IEEO_MII_CONTROL_MAN_SGMII_SP_100                    0x2000
294 #define MDIO_COMBO_IEEO_MII_CONTROL_MAN_SGMII_SP_1000                   0x0040
295 #define MDIO_COMBO_IEEO_MII_CONTROL_FULL_DUPLEX                         0x0100
296 #define MDIO_COMBO_IEEO_MII_CONTROL_RESTART_AN                          0x0200
297 #define MDIO_COMBO_IEEO_MII_CONTROL_AN_EN                               0x1000
298 #define MDIO_COMBO_IEEO_MII_CONTROL_LOOPBACK                            0x4000
299 #define MDIO_COMBO_IEEO_MII_CONTROL_RESET                               0x8000
300 #define MDIO_COMBO_IEEE0_MII_STATUS                             0x11
301 #define MDIO_COMBO_IEEE0_MII_STATUS_LINK_PASS                           0x0004
302 #define MDIO_COMBO_IEEE0_MII_STATUS_AUTONEG_COMPLETE                    0x0020
303 #define MDIO_COMBO_IEEE0_AUTO_NEG_ADV                           0x14
304 #define MDIO_COMBO_IEEE0_AUTO_NEG_ADV_FULL_DUPLEX                       0x0020
305 #define MDIO_COMBO_IEEE0_AUTO_NEG_ADV_HALF_DUPLEX                       0x0040
306 #define MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK                        0x0180
307 #define MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE                        0x0000
308 #define MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_SYMMETRIC                   0x0080
309 #define MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC                  0x0100
310 #define MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH                        0x0180
311 #define MDIO_COMBO_IEEE0_AUTO_NEG_ADV_NEXT_PAGE                         0x8000
312 #define MDIO_COMBO_IEEE0_AUTO_NEG_LINK_PARTNER_ABILITY1         0x15
313 #define MDIO_COMBO_IEEE0_AUTO_NEG_LINK_PARTNER_ABILITY1_NEXT_PAGE       0x8000
314 #define MDIO_COMBO_IEEE0_AUTO_NEG_LINK_PARTNER_ABILITY1_ACK             0x4000
315 #define MDIO_COMBO_IEEE0_AUTO_NEG_LINK_PARTNER_ABILITY1_PAUSE_MASK      0x0180
316 #define MDIO_COMBO_IEEE0_AUTO_NEG_LINK_PARTNER_ABILITY1_PAUSE_NONE      0x0000
317 #define MDIO_COMBO_IEEE0_AUTO_NEG_LINK_PARTNER_ABILITY1_PAUSE_BOTH      0x0180
318 #define MDIO_COMBO_IEEE0_AUTO_NEG_LINK_PARTNER_ABILITY1_HALF_DUP_CAP    0x0040
319 #define MDIO_COMBO_IEEE0_AUTO_NEG_LINK_PARTNER_ABILITY1_FULL_DUP_CAP    0x0020
320 /*WhenthelinkpartnerisinSGMIImode(bit0=1),then
321 bit15=link,bit12=duplex,bits11:10=speed,bit14=acknowledge.
322 Theotherbitsarereservedandshouldbezero*/
323 #define MDIO_COMBO_IEEE0_AUTO_NEG_LINK_PARTNER_ABILITY1_SGMII_MODE      0x0001
324
325 #define MDIO_PMA_DEVAD                  0x1
326 /*ieee*/
327 #define MDIO_PMA_REG_CTRL               0x0
328 #define MDIO_PMA_REG_STATUS             0x1
329 #define MDIO_PMA_REG_10G_CTRL2          0x7
330 #define MDIO_PMA_REG_TX_DISABLE         0x0009
331 #define MDIO_PMA_REG_RX_SD              0xa
332 /*bnx2x*/
333 #define MDIO_PMA_REG_BNX2X_CTRL         0x0096
334 #define MDIO_PMA_REG_FEC_CTRL           0x00ab
335 #define MDIO_PMA_LASI_RXCTRL            0x9000
336 #define MDIO_PMA_LASI_TXCTRL            0x9001
337 #define MDIO_PMA_LASI_CTRL              0x9002
338 #define MDIO_PMA_LASI_RXSTAT            0x9003
339 #define MDIO_PMA_LASI_TXSTAT            0x9004
340 #define MDIO_PMA_LASI_STAT              0x9005
341 #define MDIO_PMA_REG_PHY_IDENTIFIER     0xc800
342 #define MDIO_PMA_REG_DIGITAL_CTRL       0xc808
343 #define MDIO_PMA_REG_DIGITAL_STATUS     0xc809
344 #define MDIO_PMA_REG_TX_POWER_DOWN      0xca02
345 #define MDIO_PMA_REG_CMU_PLL_BYPASS     0xca09
346 #define MDIO_PMA_REG_MISC_CTRL          0xca0a
347 #define MDIO_PMA_REG_GEN_CTRL           0xca10
348 #define MDIO_PMA_REG_GEN_CTRL_ROM_RESET_INTERNAL_MP     0x0188
349 #define MDIO_PMA_REG_GEN_CTRL_ROM_MICRO_RESET           0x018a
350 #define MDIO_PMA_REG_M8051_MSGIN_REG    0xca12
351 #define MDIO_PMA_REG_M8051_MSGOUT_REG   0xca13
352 #define MDIO_PMA_REG_ROM_VER1           0xca19
353 #define MDIO_PMA_REG_ROM_VER2           0xca1a
354 #define MDIO_PMA_REG_EDC_FFE_MAIN       0xca1b
355 #define MDIO_PMA_REG_PLL_BANDWIDTH      0xca1d
356 #define MDIO_PMA_REG_PLL_CTRL           0xca1e
357 #define MDIO_PMA_REG_MISC_CTRL0         0xca23
358 #define MDIO_PMA_REG_LRM_MODE           0xca3f
359 #define MDIO_PMA_REG_CDR_BANDWIDTH      0xca46
360 #define MDIO_PMA_REG_MISC_CTRL1         0xca85
361
362 #define MDIO_PMA_REG_SFP_TWO_WIRE_CTRL          0x8000
363 #define MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK      0x000c
364 #define MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_IDLE           0x0000
365 #define MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_COMPLETE       0x0004
366 #define MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_IN_PROGRESS    0x0008
367 #define MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_FAILED         0x000c
368 #define MDIO_PMA_REG_SFP_TWO_WIRE_BYTE_CNT      0x8002
369 #define MDIO_PMA_REG_SFP_TWO_WIRE_MEM_ADDR      0x8003
370 #define MDIO_PMA_REG_8726_TWO_WIRE_DATA_BUF     0xc820
371 #define MDIO_PMA_REG_8726_TWO_WIRE_DATA_MASK 0xff
372 #define MDIO_PMA_REG_8726_TX_CTRL1              0xca01
373 #define MDIO_PMA_REG_8726_TX_CTRL2              0xca05
374
375 #define MDIO_PMA_REG_8727_TWO_WIRE_SLAVE_ADDR   0x8005
376 #define MDIO_PMA_REG_8727_TWO_WIRE_DATA_BUF     0x8007
377 #define MDIO_PMA_REG_8727_TWO_WIRE_DATA_MASK 0xff
378 #define MDIO_PMA_REG_8727_MISC_CTRL             0x8309
379 #define MDIO_PMA_REG_8727_TX_CTRL1              0xca02
380 #define MDIO_PMA_REG_8727_TX_CTRL2              0xca05
381 #define MDIO_PMA_REG_8727_PCS_OPT_CTRL          0xc808
382 #define MDIO_PMA_REG_8727_GPIO_CTRL             0xc80e
383 #define MDIO_PMA_REG_8727_PCS_GP                0xc842
384 #define MDIO_PMA_REG_8727_OPT_CFG_REG           0xc8e4
385
386 #define MDIO_AN_REG_8727_MISC_CTRL              0x8309
387 #define MDIO_PMA_REG_8073_CHIP_REV                      0xc801
388 #define MDIO_PMA_REG_8073_SPEED_LINK_STATUS             0xc820
389 #define MDIO_PMA_REG_8073_XAUI_WA                       0xc841
390 #define MDIO_PMA_REG_8073_OPT_DIGITAL_CTRL              0xcd08
391
392 #define MDIO_PMA_REG_7101_RESET         0xc000
393 #define MDIO_PMA_REG_7107_LED_CNTL      0xc007
394 #define MDIO_PMA_REG_7107_LINK_LED_CNTL 0xc009
395 #define MDIO_PMA_REG_7101_VER1          0xc026
396 #define MDIO_PMA_REG_7101_VER2          0xc027
397
398 #define MDIO_PMA_REG_8481_PMD_SIGNAL    0xa811
399 #define MDIO_PMA_REG_8481_LED1_MASK     0xa82c
400 #define MDIO_PMA_REG_8481_LED2_MASK     0xa82f
401 #define MDIO_PMA_REG_8481_LED3_MASK     0xa832
402 #define MDIO_PMA_REG_8481_LED3_BLINK    0xa834
403 #define MDIO_PMA_REG_8481_LED5_MASK                     0xa838
404 #define MDIO_PMA_REG_8481_SIGNAL_MASK   0xa835
405 #define MDIO_PMA_REG_8481_LINK_SIGNAL   0xa83b
406 #define MDIO_PMA_REG_8481_LINK_SIGNAL_LED4_ENABLE_MASK  0x800
407 #define MDIO_PMA_REG_8481_LINK_SIGNAL_LED4_ENABLE_SHIFT 11
408
409 #define MDIO_WIS_DEVAD                  0x2
410 /*bnx2x*/
411 #define MDIO_WIS_REG_LASI_CNTL          0x9002
412 #define MDIO_WIS_REG_LASI_STATUS        0x9005
413
414 #define MDIO_PCS_DEVAD                  0x3
415 #define MDIO_PCS_REG_STATUS             0x0020
416 #define MDIO_PCS_REG_LASI_STATUS        0x9005
417 #define MDIO_PCS_REG_7101_DSP_ACCESS    0xD000
418 #define MDIO_PCS_REG_7101_SPI_MUX       0xD008
419 #define MDIO_PCS_REG_7101_SPI_CTRL_ADDR 0xE12A
420 #define MDIO_PCS_REG_7101_SPI_RESET_BIT (5)
421 #define MDIO_PCS_REG_7101_SPI_FIFO_ADDR 0xE02A
422 #define MDIO_PCS_REG_7101_SPI_FIFO_ADDR_WRITE_ENABLE_CMD (6)
423 #define MDIO_PCS_REG_7101_SPI_FIFO_ADDR_BULK_ERASE_CMD   (0xC7)
424 #define MDIO_PCS_REG_7101_SPI_FIFO_ADDR_PAGE_PROGRAM_CMD (2)
425 #define MDIO_PCS_REG_7101_SPI_BYTES_TO_TRANSFER_ADDR 0xE028
426
427 #define MDIO_XS_DEVAD                   0x4
428 #define MDIO_XS_REG_STATUS              0x0001
429 #define MDIO_XS_PLL_SEQUENCER           0x8000
430 #define MDIO_XS_SFX7101_XGXS_TEST1      0xc00a
431
432 #define MDIO_XS_8706_REG_BANK_RX0       0x80bc
433 #define MDIO_XS_8706_REG_BANK_RX1       0x80cc
434 #define MDIO_XS_8706_REG_BANK_RX2       0x80dc
435 #define MDIO_XS_8706_REG_BANK_RX3       0x80ec
436 #define MDIO_XS_8706_REG_BANK_RXA       0x80fc
437
438 #define MDIO_XS_REG_8073_RX_CTRL_PCIE   0x80FA
439
440 #define MDIO_AN_DEVAD                   0x7
441 /*ieee*/
442 #define MDIO_AN_REG_CTRL                0x0000
443 #define MDIO_AN_REG_STATUS              0x0001
444 #define MDIO_AN_REG_STATUS_AN_COMPLETE          0x0020
445 #define MDIO_AN_REG_ADV_PAUSE           0x0010
446 #define MDIO_AN_REG_ADV_PAUSE_PAUSE             0x0400
447 #define MDIO_AN_REG_ADV_PAUSE_ASYMMETRIC        0x0800
448 #define MDIO_AN_REG_ADV_PAUSE_BOTH              0x0C00
449 #define MDIO_AN_REG_ADV_PAUSE_MASK              0x0C00
450 #define MDIO_AN_REG_ADV                 0x0011
451 #define MDIO_AN_REG_ADV2                0x0012
452 #define MDIO_AN_REG_LP_AUTO_NEG         0x0013
453 #define MDIO_AN_REG_LP_AUTO_NEG2        0x0014
454 #define MDIO_AN_REG_MASTER_STATUS       0x0021
455 #define MDIO_AN_REG_EEE_ADV             0x003c
456 #define MDIO_AN_REG_LP_EEE_ADV          0x003d
457 /*bnx2x*/
458 #define MDIO_AN_REG_LINK_STATUS         0x8304
459 #define MDIO_AN_REG_CL37_CL73           0x8370
460 #define MDIO_AN_REG_CL37_AN             0xffe0
461 #define MDIO_AN_REG_CL37_FC_LD          0xffe4
462 #define         MDIO_AN_REG_CL37_FC_LP          0xffe5
463 #define         MDIO_AN_REG_1000T_STATUS        0xffea
464
465 #define MDIO_AN_REG_8073_2_5G           0x8329
466 #define MDIO_AN_REG_8073_BAM            0x8350
467
468 #define MDIO_AN_REG_8481_10GBASE_T_AN_CTRL      0x0020
469 #define MDIO_AN_REG_8481_LEGACY_MII_CTRL        0xffe0
470 #define MDIO_AN_REG_8481_MII_CTRL_FORCE_1G      0x40
471 #define MDIO_AN_REG_8481_LEGACY_MII_STATUS      0xffe1
472 #define MDIO_AN_REG_8481_LEGACY_AN_ADV          0xffe4
473 #define MDIO_AN_REG_8481_LEGACY_AN_EXPANSION    0xffe6
474 #define MDIO_AN_REG_8481_1000T_CTRL             0xffe9
475 #define MDIO_AN_REG_8481_1G_100T_EXT_CTRL       0xfff0
476 #define MIDO_AN_REG_8481_EXT_CTRL_FORCE_LEDS_OFF        0x0008
477 #define MDIO_AN_REG_8481_EXPANSION_REG_RD_RW    0xfff5
478 #define MDIO_AN_REG_8481_EXPANSION_REG_ACCESS   0xfff7
479 #define MDIO_AN_REG_8481_AUX_CTRL               0xfff8
480 #define MDIO_AN_REG_8481_LEGACY_SHADOW          0xfffc
481
482 /* BNX2X84823 only */
483 #define MDIO_CTL_DEVAD                  0x1e
484 #define MDIO_CTL_REG_84823_MEDIA                0x401a
485 #define MDIO_CTL_REG_84823_MEDIA_MAC_MASK               0x0018
486         /* These pins configure the BNX2X84823 interface to MAC after reset. */
487 #define MDIO_CTL_REG_84823_CTRL_MAC_XFI                 0x0008
488 #define MDIO_CTL_REG_84823_MEDIA_MAC_XAUI_M             0x0010
489         /* These pins configure the BNX2X84823 interface to Line after reset. */
490 #define MDIO_CTL_REG_84823_MEDIA_LINE_MASK              0x0060
491 #define MDIO_CTL_REG_84823_MEDIA_LINE_XAUI_L            0x0020
492 #define MDIO_CTL_REG_84823_MEDIA_LINE_XFI               0x0040
493         /* When this pin is active high during reset, 10GBASE-T core is power
494          * down, When it is active low the 10GBASE-T is power up
495          */
496 #define MDIO_CTL_REG_84823_MEDIA_COPPER_CORE_DOWN       0x0080
497 #define MDIO_CTL_REG_84823_MEDIA_PRIORITY_MASK          0x0100
498 #define MDIO_CTL_REG_84823_MEDIA_PRIORITY_COPPER        0x0000
499 #define MDIO_CTL_REG_84823_MEDIA_PRIORITY_FIBER         0x0100
500 #define MDIO_CTL_REG_84823_MEDIA_FIBER_1G                       0x1000
501 #define MDIO_CTL_REG_84823_USER_CTRL_REG                        0x4005
502 #define MDIO_CTL_REG_84823_USER_CTRL_CMS                        0x0080
503 #define MDIO_PMA_REG_84823_CTL_SLOW_CLK_CNT_HIGH                0xa82b
504 #define MDIO_PMA_REG_84823_BLINK_RATE_VAL_15P9HZ        0x2f
505 #define MDIO_PMA_REG_84823_CTL_LED_CTL_1                        0xa8e3
506 #define MDIO_PMA_REG_84833_CTL_LED_CTL_1                        0xa8ec
507 #define MDIO_PMA_REG_84823_LED3_STRETCH_EN                      0x0080
508
509 /* BNX2X84833 only */
510 #define MDIO_84833_TOP_CFG_FW_REV                       0x400f
511 #define MDIO_84833_TOP_CFG_FW_EEE               0x10b1
512 #define MDIO_84833_TOP_CFG_FW_NO_EEE            0x1f81
513 #define MDIO_84833_TOP_CFG_XGPHY_STRAP1                 0x401a
514 #define MDIO_84833_SUPER_ISOLATE                0x8000
515 /* These are mailbox register set used by 84833. */
516 #define MDIO_84833_TOP_CFG_SCRATCH_REG0                 0x4005
517 #define MDIO_84833_TOP_CFG_SCRATCH_REG1                 0x4006
518 #define MDIO_84833_TOP_CFG_SCRATCH_REG2                 0x4007
519 #define MDIO_84833_TOP_CFG_SCRATCH_REG3                 0x4008
520 #define MDIO_84833_TOP_CFG_SCRATCH_REG4                 0x4009
521 #define MDIO_84833_TOP_CFG_SCRATCH_REG26                0x4037
522 #define MDIO_84833_TOP_CFG_SCRATCH_REG27                0x4038
523 #define MDIO_84833_TOP_CFG_SCRATCH_REG28                0x4039
524 #define MDIO_84833_TOP_CFG_SCRATCH_REG29                0x403a
525 #define MDIO_84833_TOP_CFG_SCRATCH_REG30                0x403b
526 #define MDIO_84833_TOP_CFG_SCRATCH_REG31                0x403c
527 #define MDIO_84833_CMD_HDLR_COMMAND     MDIO_84833_TOP_CFG_SCRATCH_REG0
528 #define MDIO_84833_CMD_HDLR_STATUS      MDIO_84833_TOP_CFG_SCRATCH_REG26
529 #define MDIO_84833_CMD_HDLR_DATA1       MDIO_84833_TOP_CFG_SCRATCH_REG27
530 #define MDIO_84833_CMD_HDLR_DATA2       MDIO_84833_TOP_CFG_SCRATCH_REG28
531 #define MDIO_84833_CMD_HDLR_DATA3       MDIO_84833_TOP_CFG_SCRATCH_REG29
532 #define MDIO_84833_CMD_HDLR_DATA4       MDIO_84833_TOP_CFG_SCRATCH_REG30
533 #define MDIO_84833_CMD_HDLR_DATA5       MDIO_84833_TOP_CFG_SCRATCH_REG31
534
535 /* Mailbox command set used by 84833. */
536 #define PHY84833_CMD_SET_PAIR_SWAP                      0x8001
537 #define PHY84833_CMD_GET_EEE_MODE                       0x8008
538 #define PHY84833_CMD_SET_EEE_MODE                       0x8009
539 #define PHY84833_CMD_GET_CURRENT_TEMP                   0x8031
540 /* Mailbox status set used by 84833. */
541 #define PHY84833_STATUS_CMD_RECEIVED                    0x0001
542 #define PHY84833_STATUS_CMD_IN_PROGRESS                 0x0002
543 #define PHY84833_STATUS_CMD_COMPLETE_PASS               0x0004
544 #define PHY84833_STATUS_CMD_COMPLETE_ERROR              0x0008
545 #define PHY84833_STATUS_CMD_OPEN_FOR_CMDS               0x0010
546 #define PHY84833_STATUS_CMD_SYSTEM_BOOT                 0x0020
547 #define PHY84833_STATUS_CMD_NOT_OPEN_FOR_CMDS           0x0040
548 #define PHY84833_STATUS_CMD_CLEAR_COMPLETE              0x0080
549 #define PHY84833_STATUS_CMD_OPEN_OVERRIDE               0xa5a5
550
551 /* Warpcore clause 45 addressing */
552 #define MDIO_WC_DEVAD                                   0x3
553 #define MDIO_WC_REG_IEEE0BLK_MIICNTL                    0x0
554 #define MDIO_WC_REG_IEEE0BLK_AUTONEGNP                  0x7
555 #define MDIO_WC_REG_AN_IEEE1BLK_AN_ADVERTISEMENT0       0x10
556 #define MDIO_WC_REG_AN_IEEE1BLK_AN_ADVERTISEMENT1       0x11
557 #define MDIO_WC_REG_AN_IEEE1BLK_AN_ADVERTISEMENT2       0x12
558 #define MDIO_WC_REG_AN_IEEE1BLK_AN_ADV2_FEC_ABILITY     0x4000
559 #define MDIO_WC_REG_AN_IEEE1BLK_AN_ADV2_FEC_REQ         0x8000
560 #define MDIO_WC_REG_PCS_STATUS2                         0x0021
561 #define MDIO_WC_REG_PMD_KR_CONTROL                      0x0096
562 #define MDIO_WC_REG_XGXSBLK0_XGXSCONTROL                0x8000
563 #define MDIO_WC_REG_XGXSBLK0_MISCCONTROL1               0x800e
564 #define MDIO_WC_REG_XGXSBLK1_DESKEW                     0x8010
565 #define MDIO_WC_REG_XGXSBLK1_LANECTRL0                  0x8015
566 #define MDIO_WC_REG_XGXSBLK1_LANECTRL1                  0x8016
567 #define MDIO_WC_REG_XGXSBLK1_LANECTRL2                  0x8017
568 #define MDIO_WC_REG_XGXSBLK1_LANECTRL3                  0x8018
569 #define MDIO_WC_REG_XGXSBLK1_LANETEST0                  0x801a
570 #define MDIO_WC_REG_TX0_ANA_CTRL0                       0x8061
571 #define MDIO_WC_REG_TX1_ANA_CTRL0                       0x8071
572 #define MDIO_WC_REG_TX2_ANA_CTRL0                       0x8081
573 #define MDIO_WC_REG_TX3_ANA_CTRL0                       0x8091
574 #define MDIO_WC_REG_TX0_TX_DRIVER                       0x8067
575 #define MDIO_WC_REG_TX0_TX_DRIVER_IPRE_DRIVER_OFFSET            0x04
576 #define MDIO_WC_REG_TX0_TX_DRIVER_IPRE_DRIVER_MASK                      0x00f0
577 #define MDIO_WC_REG_TX0_TX_DRIVER_IDRIVER_OFFSET                0x08
578 #define MDIO_WC_REG_TX0_TX_DRIVER_IDRIVER_MASK                          0x0f00
579 #define MDIO_WC_REG_TX0_TX_DRIVER_POST2_COEFF_OFFSET            0x0c
580 #define MDIO_WC_REG_TX0_TX_DRIVER_POST2_COEFF_MASK                      0x7000
581 #define MDIO_WC_REG_TX1_TX_DRIVER                       0x8077
582 #define MDIO_WC_REG_TX2_TX_DRIVER                       0x8087
583 #define MDIO_WC_REG_TX3_TX_DRIVER                       0x8097
584 #define MDIO_WC_REG_RX0_ANARXCONTROL1G                  0x80b9
585 #define MDIO_WC_REG_RX2_ANARXCONTROL1G                  0x80d9
586 #define MDIO_WC_REG_RX0_PCI_CTRL                        0x80ba
587 #define MDIO_WC_REG_RX1_PCI_CTRL                        0x80ca
588 #define MDIO_WC_REG_RX2_PCI_CTRL                        0x80da
589 #define MDIO_WC_REG_RX3_PCI_CTRL                        0x80ea
590 #define MDIO_WC_REG_XGXSBLK2_UNICORE_MODE_10G           0x8104
591 #define MDIO_WC_REG_XGXS_STATUS3                        0x8129
592 #define MDIO_WC_REG_PAR_DET_10G_STATUS                  0x8130
593 #define MDIO_WC_REG_PAR_DET_10G_CTRL                    0x8131
594 #define MDIO_WC_REG_XGXS_STATUS4                        0x813c
595 #define MDIO_WC_REG_XGXS_X2_CONTROL2                    0x8141
596 #define MDIO_WC_REG_XGXS_X2_CONTROL3                    0x8142
597 #define MDIO_WC_REG_XGXS_RX_LN_SWAP1                    0x816B
598 #define MDIO_WC_REG_XGXS_TX_LN_SWAP1                    0x8169
599 #define MDIO_WC_REG_GP2_STATUS_GP_2_0                   0x81d0
600 #define MDIO_WC_REG_GP2_STATUS_GP_2_1                   0x81d1
601 #define MDIO_WC_REG_GP2_STATUS_GP_2_2                   0x81d2
602 #define MDIO_WC_REG_GP2_STATUS_GP_2_3                   0x81d3
603 #define MDIO_WC_REG_GP2_STATUS_GP_2_4                   0x81d4
604 #define MDIO_WC_REG_GP2_STATUS_GP_2_4_CL73_AN_CMPL 0x1000
605 #define MDIO_WC_REG_GP2_STATUS_GP_2_4_CL37_AN_CMPL 0x0100
606 #define MDIO_WC_REG_GP2_STATUS_GP_2_4_CL37_LP_AN_CAP 0x0010
607 #define MDIO_WC_REG_GP2_STATUS_GP_2_4_CL37_AN_CAP 0x1
608 #define MDIO_WC_REG_UC_INFO_B0_DEAD_TRAP                0x81EE
609 #define MDIO_WC_REG_UC_INFO_B1_VERSION                  0x81F0
610 #define MDIO_WC_REG_UC_INFO_B1_FIRMWARE_MODE            0x81F2
611 #define MDIO_WC_REG_UC_INFO_B1_FIRMWARE_LANE0_OFFSET    0x0
612 #define MDIO_WC_REG_UC_INFO_B1_FIRMWARE_MODE_DEFAULT        0x0
613 #define MDIO_WC_REG_UC_INFO_B1_FIRMWARE_MODE_SFP_OPT_LR     0x1
614 #define MDIO_WC_REG_UC_INFO_B1_FIRMWARE_MODE_SFP_DAC        0x2
615 #define MDIO_WC_REG_UC_INFO_B1_FIRMWARE_MODE_SFP_XLAUI      0x3
616 #define MDIO_WC_REG_UC_INFO_B1_FIRMWARE_MODE_LONG_CH_6G     0x4
617 #define MDIO_WC_REG_UC_INFO_B1_FIRMWARE_LANE1_OFFSET    0x4
618 #define MDIO_WC_REG_UC_INFO_B1_FIRMWARE_LANE2_OFFSET    0x8
619 #define MDIO_WC_REG_UC_INFO_B1_FIRMWARE_LANE3_OFFSET    0xc
620 #define MDIO_WC_REG_UC_INFO_B1_CRC                      0x81FE
621 #define MDIO_WC_REG_DSC1B0_UC_CTRL                              0x820e
622 #define MDIO_WC_REG_DSC1B0_UC_CTRL_RDY4CMD                      (1<<7)
623 #define MDIO_WC_REG_DSC_SMC                             0x8213
624 #define MDIO_WC_REG_DSC2B0_DSC_MISC_CTRL0               0x821e
625 #define MDIO_WC_REG_TX_FIR_TAP                          0x82e2
626 #define MDIO_WC_REG_TX_FIR_TAP_PRE_TAP_OFFSET           0x00
627 #define MDIO_WC_REG_TX_FIR_TAP_PRE_TAP_MASK                     0x000f
628 #define MDIO_WC_REG_TX_FIR_TAP_MAIN_TAP_OFFSET          0x04
629 #define MDIO_WC_REG_TX_FIR_TAP_MAIN_TAP_MASK            0x03f0
630 #define MDIO_WC_REG_TX_FIR_TAP_POST_TAP_OFFSET          0x0a
631 #define MDIO_WC_REG_TX_FIR_TAP_POST_TAP_MASK            0x7c00
632 #define MDIO_WC_REG_TX_FIR_TAP_ENABLE           0x8000
633 #define MDIO_WC_REG_CL72_USERB0_CL72_TX_FIR_TAP         0x82e2
634 #define MDIO_WC_REG_CL72_USERB0_CL72_MISC1_CONTROL      0x82e3
635 #define MDIO_WC_REG_CL72_USERB0_CL72_OS_DEF_CTRL        0x82e6
636 #define MDIO_WC_REG_CL72_USERB0_CL72_BR_DEF_CTRL        0x82e7
637 #define MDIO_WC_REG_CL72_USERB0_CL72_2P5_DEF_CTRL       0x82e8
638 #define MDIO_WC_REG_CL72_USERB0_CL72_MISC4_CONTROL      0x82ec
639 #define MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X1         0x8300
640 #define MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2         0x8301
641 #define MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X3         0x8302
642 #define MDIO_WC_REG_SERDESDIGITAL_STATUS1000X1          0x8304
643 #define MDIO_WC_REG_SERDESDIGITAL_MISC1                 0x8308
644 #define MDIO_WC_REG_SERDESDIGITAL_MISC2                 0x8309
645 #define MDIO_WC_REG_DIGITAL3_UP1                        0x8329
646 #define MDIO_WC_REG_DIGITAL3_LP_UP1                     0x832c
647 #define MDIO_WC_REG_DIGITAL4_MISC3                      0x833c
648 #define MDIO_WC_REG_DIGITAL4_MISC5                      0x833e
649 #define MDIO_WC_REG_DIGITAL5_MISC6                      0x8345
650 #define MDIO_WC_REG_DIGITAL5_MISC7                      0x8349
651 #define MDIO_WC_REG_DIGITAL5_LINK_STATUS                0x834d
652 #define MDIO_WC_REG_DIGITAL5_ACTUAL_SPEED               0x834e
653 #define MDIO_WC_REG_DIGITAL6_MP5_NEXTPAGECTRL           0x8350
654 #define MDIO_WC_REG_CL49_USERB0_CTRL                    0x8368
655 #define MDIO_WC_REG_CL73_USERB0_CTRL                    0x8370
656 #define MDIO_WC_REG_CL73_USERB0_USTAT                   0x8371
657 #define MDIO_WC_REG_CL73_BAM_CTRL1                      0x8372
658 #define MDIO_WC_REG_CL73_BAM_CTRL2                      0x8373
659 #define MDIO_WC_REG_CL73_BAM_CTRL3                      0x8374
660 #define MDIO_WC_REG_CL73_BAM_CODE_FIELD                 0x837b
661 #define MDIO_WC_REG_EEE_COMBO_CONTROL0                  0x8390
662 #define MDIO_WC_REG_TX66_CONTROL                        0x83b0
663 #define MDIO_WC_REG_RX66_CONTROL                        0x83c0
664 #define MDIO_WC_REG_RX66_SCW0                           0x83c2
665 #define MDIO_WC_REG_RX66_SCW1                           0x83c3
666 #define MDIO_WC_REG_RX66_SCW2                           0x83c4
667 #define MDIO_WC_REG_RX66_SCW3                           0x83c5
668 #define MDIO_WC_REG_RX66_SCW0_MASK                      0x83c6
669 #define MDIO_WC_REG_RX66_SCW1_MASK                      0x83c7
670 #define MDIO_WC_REG_RX66_SCW2_MASK                      0x83c8
671 #define MDIO_WC_REG_RX66_SCW3_MASK                      0x83c9
672 #define MDIO_WC_REG_FX100_CTRL1                         0x8400
673 #define MDIO_WC_REG_FX100_CTRL3                         0x8402
674 #define MDIO_WC_REG_CL82_USERB1_TX_CTRL5                0x8436
675 #define MDIO_WC_REG_CL82_USERB1_TX_CTRL6                0x8437
676 #define MDIO_WC_REG_CL82_USERB1_TX_CTRL7                0x8438
677 #define MDIO_WC_REG_CL82_USERB1_TX_CTRL9                0x8439
678 #define MDIO_WC_REG_CL82_USERB1_RX_CTRL10               0x843a
679 #define MDIO_WC_REG_CL82_USERB1_RX_CTRL11               0x843b
680 #define MDIO_WC_REG_ETA_CL73_OUI1                       0x8453
681 #define MDIO_WC_REG_ETA_CL73_OUI2                       0x8454
682 #define MDIO_WC_REG_ETA_CL73_OUI3                       0x8455
683 #define MDIO_WC_REG_ETA_CL73_LD_BAM_CODE                0x8456
684 #define MDIO_WC_REG_ETA_CL73_LD_UD_CODE                 0x8457
685 #define MDIO_WC_REG_MICROBLK_CMD                        0xffc2
686 #define MDIO_WC_REG_MICROBLK_DL_STATUS                  0xffc5
687 #define MDIO_WC_REG_MICROBLK_CMD3                       0xffcc
688
689 #define MDIO_WC_REG_AERBLK_AER                          0xffde
690 #define MDIO_WC_REG_COMBO_IEEE0_MIICTRL                 0xffe0
691 #define MDIO_WC_REG_COMBO_IEEE0_MIIISTAT                0xffe1
692
693 #define MDIO_WC0_XGXS_BLK2_LANE_RESET                   0x810A
694 #define MDIO_WC0_XGXS_BLK2_LANE_RESET_RX_BITSHIFT       0
695 #define MDIO_WC0_XGXS_BLK2_LANE_RESET_TX_BITSHIFT       4
696
697 #define MDIO_WC0_XGXS_BLK6_XGXS_X2_CONTROL2             0x8141
698
699 #define DIGITAL5_ACTUAL_SPEED_TX_MASK                   0x003f
700
701 /* 54618se */
702 #define MDIO_REG_GPHY_MII_STATUS                        0x1
703 #define MDIO_REG_GPHY_PHYID_LSB                         0x3
704 #define MDIO_REG_GPHY_CL45_ADDR_REG                     0xd
705 #define MDIO_REG_GPHY_CL45_REG_WRITE            0x4000
706 #define MDIO_REG_GPHY_CL45_REG_READ             0xc000
707 #define MDIO_REG_GPHY_CL45_DATA_REG                     0xe
708 #define MDIO_REG_GPHY_EEE_RESOLVED              0x803e
709 #define MDIO_REG_GPHY_EXP_ACCESS_GATE                   0x15
710 #define MDIO_REG_GPHY_EXP_ACCESS                        0x17
711 #define MDIO_REG_GPHY_EXP_ACCESS_TOP            0xd00
712 #define MDIO_REG_GPHY_EXP_TOP_2K_BUF            0x40
713 #define MDIO_REG_GPHY_AUX_STATUS                        0x19
714 #define MDIO_REG_INTR_STATUS                            0x1a
715 #define MDIO_REG_INTR_MASK                              0x1b
716 #define MDIO_REG_INTR_MASK_LINK_STATUS                  (0x1 << 1)
717 #define MDIO_REG_GPHY_SHADOW                            0x1c
718 #define MDIO_REG_GPHY_SHADOW_LED_SEL1                   (0x0d << 10)
719 #define MDIO_REG_GPHY_SHADOW_LED_SEL2                   (0x0e << 10)
720 #define MDIO_REG_GPHY_SHADOW_WR_ENA                     (0x1 << 15)
721 #define MDIO_REG_GPHY_SHADOW_AUTO_DET_MED               (0x1e << 10)
722 #define MDIO_REG_GPHY_SHADOW_INVERT_FIB_SD              (0x1 << 8)
723
724 typedef elink_status_t(*read_sfp_module_eeprom_func_p) (struct elink_phy * phy,
725                                                         struct elink_params *
726                                                         params,
727                                                         uint8_t dev_addr,
728                                                         uint16_t addr,
729                                                         uint8_t byte_cnt,
730                                                         uint8_t * o_buf,
731                                                         uint8_t);
732 /********************************************************/
733 #define ELINK_ETH_HLEN                  14
734 /* L2 header size + 2*VLANs (8 bytes) + LLC SNAP (8 bytes) */
735 #define ELINK_ETH_OVREHEAD                      (ELINK_ETH_HLEN + 8 + 8)
736 #define ELINK_ETH_MIN_PACKET_SIZE               60
737 #define ELINK_ETH_MAX_PACKET_SIZE               1500
738 #define ELINK_ETH_MAX_JUMBO_PACKET_SIZE 9600
739 #define ELINK_MDIO_ACCESS_TIMEOUT               1000
740 #define WC_LANE_MAX                     4
741 #define I2C_SWITCH_WIDTH                2
742 #define I2C_BSC0                        0
743 #define I2C_BSC1                        1
744 #define I2C_WA_RETRY_CNT                3
745 #define I2C_WA_PWR_ITER                 (I2C_WA_RETRY_CNT - 1)
746 #define MCPR_IMC_COMMAND_READ_OP        1
747 #define MCPR_IMC_COMMAND_WRITE_OP       2
748
749 /* LED Blink rate that will achieve ~15.9Hz */
750 #define LED_BLINK_RATE_VAL_E3           354
751 #define LED_BLINK_RATE_VAL_E1X_E2       480
752 /***********************************************************/
753 /*                      Shortcut definitions               */
754 /***********************************************************/
755
756 #define ELINK_NIG_LATCH_BC_ENABLE_MI_INT 0
757
758 #define ELINK_NIG_STATUS_EMAC0_MI_INT \
759                 NIG_STATUS_INTERRUPT_PORT0_REG_STATUS_EMAC0_MISC_MI_INT
760 #define ELINK_NIG_STATUS_XGXS0_LINK10G \
761                 NIG_STATUS_INTERRUPT_PORT0_REG_STATUS_XGXS0_LINK10G
762 #define ELINK_NIG_STATUS_XGXS0_LINK_STATUS \
763                 NIG_STATUS_INTERRUPT_PORT0_REG_STATUS_XGXS0_LINK_STATUS
764 #define ELINK_NIG_STATUS_XGXS0_LINK_STATUS_SIZE \
765                 NIG_STATUS_INTERRUPT_PORT0_REG_STATUS_XGXS0_LINK_STATUS_SIZE
766 #define ELINK_NIG_STATUS_SERDES0_LINK_STATUS \
767                 NIG_STATUS_INTERRUPT_PORT0_REG_STATUS_SERDES0_LINK_STATUS
768 #define ELINK_NIG_MASK_MI_INT \
769                 NIG_MASK_INTERRUPT_PORT0_REG_MASK_EMAC0_MISC_MI_INT
770 #define ELINK_NIG_MASK_XGXS0_LINK10G \
771                 NIG_MASK_INTERRUPT_PORT0_REG_MASK_XGXS0_LINK10G
772 #define ELINK_NIG_MASK_XGXS0_LINK_STATUS \
773                 NIG_MASK_INTERRUPT_PORT0_REG_MASK_XGXS0_LINK_STATUS
774 #define ELINK_NIG_MASK_SERDES0_LINK_STATUS \
775                 NIG_MASK_INTERRUPT_PORT0_REG_MASK_SERDES0_LINK_STATUS
776
777 #define ELINK_MDIO_AN_CL73_OR_37_COMPLETE \
778                 (MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_AUTONEG_COMPLETE | \
779                  MDIO_GP_STATUS_TOP_AN_STATUS1_CL37_AUTONEG_COMPLETE)
780
781 #define ELINK_XGXS_RESET_BITS \
782         (MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_XGXS0_RSTB_HW |   \
783          MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_XGXS0_IDDQ |      \
784          MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_XGXS0_PWRDWN |    \
785          MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_XGXS0_PWRDWN_SD | \
786          MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_XGXS0_TXD_FIFO_RSTB)
787
788 #define ELINK_SERDES_RESET_BITS \
789         (MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_SERDES0_RSTB_HW | \
790          MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_SERDES0_IDDQ |    \
791          MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_SERDES0_PWRDWN |  \
792          MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_SERDES0_PWRDWN_SD)
793
794 #define ELINK_AUTONEG_CL37              SHARED_HW_CFG_AN_ENABLE_CL37
795 #define ELINK_AUTONEG_CL73              SHARED_HW_CFG_AN_ENABLE_CL73
796 #define ELINK_AUTONEG_BAM               SHARED_HW_CFG_AN_ENABLE_BAM
797 #define ELINK_AUTONEG_PARALLEL \
798                                 SHARED_HW_CFG_AN_ENABLE_PARALLEL_DETECTION
799 #define ELINK_AUTONEG_SGMII_FIBER_AUTODET \
800                                 SHARED_HW_CFG_AN_EN_SGMII_FIBER_AUTO_DETECT
801 #define ELINK_AUTONEG_REMOTE_PHY        SHARED_HW_CFG_AN_ENABLE_REMOTE_PHY
802
803 #define ELINK_GP_STATUS_PAUSE_RSOLUTION_TXSIDE \
804                         MDIO_GP_STATUS_TOP_AN_STATUS1_PAUSE_RSOLUTION_TXSIDE
805 #define ELINK_GP_STATUS_PAUSE_RSOLUTION_RXSIDE \
806                         MDIO_GP_STATUS_TOP_AN_STATUS1_PAUSE_RSOLUTION_RXSIDE
807 #define ELINK_GP_STATUS_SPEED_MASK \
808                         MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_MASK
809 #define ELINK_GP_STATUS_10M     MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10M
810 #define ELINK_GP_STATUS_100M    MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_100M
811 #define ELINK_GP_STATUS_1G      MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_1G
812 #define ELINK_GP_STATUS_2_5G    MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_2_5G
813 #define ELINK_GP_STATUS_5G      MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_5G
814 #define ELINK_GP_STATUS_6G      MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_6G
815 #define ELINK_GP_STATUS_10G_HIG \
816                         MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10G_HIG
817 #define ELINK_GP_STATUS_10G_CX4 \
818                         MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10G_CX4
819 #define ELINK_GP_STATUS_1G_KX MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_1G_KX
820 #define ELINK_GP_STATUS_10G_KX4 \
821                         MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10G_KX4
822 #define ELINK_GP_STATUS_10G_KR MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10G_KR
823 #define ELINK_GP_STATUS_10G_XFI   MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10G_XFI
824 #define ELINK_GP_STATUS_20G_DXGXS MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_20G_DXGXS
825 #define ELINK_GP_STATUS_10G_SFI   MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10G_SFI
826 #define ELINK_GP_STATUS_20G_KR2 MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_20G_KR2
827 #define ELINK_LINK_10THD                LINK_STATUS_SPEED_AND_DUPLEX_10THD
828 #define ELINK_LINK_10TFD                LINK_STATUS_SPEED_AND_DUPLEX_10TFD
829 #define ELINK_LINK_100TXHD              LINK_STATUS_SPEED_AND_DUPLEX_100TXHD
830 #define ELINK_LINK_100T4                LINK_STATUS_SPEED_AND_DUPLEX_100T4
831 #define ELINK_LINK_100TXFD              LINK_STATUS_SPEED_AND_DUPLEX_100TXFD
832 #define ELINK_LINK_1000THD              LINK_STATUS_SPEED_AND_DUPLEX_1000THD
833 #define ELINK_LINK_1000TFD              LINK_STATUS_SPEED_AND_DUPLEX_1000TFD
834 #define ELINK_LINK_1000XFD              LINK_STATUS_SPEED_AND_DUPLEX_1000XFD
835 #define ELINK_LINK_2500THD              LINK_STATUS_SPEED_AND_DUPLEX_2500THD
836 #define ELINK_LINK_2500TFD              LINK_STATUS_SPEED_AND_DUPLEX_2500TFD
837 #define ELINK_LINK_2500XFD              LINK_STATUS_SPEED_AND_DUPLEX_2500XFD
838 #define ELINK_LINK_10GTFD               LINK_STATUS_SPEED_AND_DUPLEX_10GTFD
839 #define ELINK_LINK_10GXFD               LINK_STATUS_SPEED_AND_DUPLEX_10GXFD
840 #define ELINK_LINK_20GTFD               LINK_STATUS_SPEED_AND_DUPLEX_20GTFD
841 #define ELINK_LINK_20GXFD               LINK_STATUS_SPEED_AND_DUPLEX_20GXFD
842
843 #define ELINK_LINK_UPDATE_MASK \
844                         (LINK_STATUS_SPEED_AND_DUPLEX_MASK | \
845                          LINK_STATUS_LINK_UP | \
846                          LINK_STATUS_PHYSICAL_LINK_FLAG | \
847                          LINK_STATUS_AUTO_NEGOTIATE_COMPLETE | \
848                          LINK_STATUS_RX_FLOW_CONTROL_FLAG_MASK | \
849                          LINK_STATUS_TX_FLOW_CONTROL_FLAG_MASK | \
850                          LINK_STATUS_PARALLEL_DETECTION_FLAG_MASK | \
851                          LINK_STATUS_LINK_PARTNER_SYMMETRIC_PAUSE | \
852                          LINK_STATUS_LINK_PARTNER_ASYMMETRIC_PAUSE)
853
854 #define ELINK_SFP_EEPROM_CON_TYPE_ADDR          0x2
855 #define ELINK_SFP_EEPROM_CON_TYPE_VAL_LC        0x7
856 #define ELINK_SFP_EEPROM_CON_TYPE_VAL_COPPER    0x21
857 #define ELINK_SFP_EEPROM_CON_TYPE_VAL_RJ45      0x22
858
859 #define ELINK_SFP_EEPROM_COMP_CODE_ADDR         0x3
860 #define ELINK_SFP_EEPROM_COMP_CODE_SR_MASK      (1<<4)
861 #define ELINK_SFP_EEPROM_COMP_CODE_LR_MASK      (1<<5)
862 #define ELINK_SFP_EEPROM_COMP_CODE_LRM_MASK     (1<<6)
863
864 #define ELINK_SFP_EEPROM_FC_TX_TECH_ADDR                0x8
865 #define ELINK_SFP_EEPROM_FC_TX_TECH_BITMASK_COPPER_PASSIVE 0x4
866 #define ELINK_SFP_EEPROM_FC_TX_TECH_BITMASK_COPPER_ACTIVE  0x8
867
868 #define ELINK_SFP_EEPROM_OPTIONS_ADDR                   0x40
869 #define ELINK_SFP_EEPROM_OPTIONS_LINEAR_RX_OUT_MASK 0x1
870 #define ELINK_SFP_EEPROM_OPTIONS_SIZE                   2
871
872 #define ELINK_EDC_MODE_LINEAR                           0x0022
873 #define ELINK_EDC_MODE_LIMITING                         0x0044
874 #define ELINK_EDC_MODE_PASSIVE_DAC                      0x0055
875 #define ELINK_EDC_MODE_ACTIVE_DAC                       0x0066
876
877 /* ETS defines*/
878 #define DCBX_INVALID_COS                                        (0xFF)
879
880 #define ELINK_ETS_BW_LIMIT_CREDIT_UPPER_BOUND           (0x5000)
881 #define ELINK_ETS_BW_LIMIT_CREDIT_WEIGHT                (0x5000)
882 #define ELINK_ETS_E3B0_NIG_MIN_W_VAL_UP_TO_10GBPS               (1360)
883 #define ELINK_ETS_E3B0_NIG_MIN_W_VAL_20GBPS                     (2720)
884 #define ELINK_ETS_E3B0_PBF_MIN_W_VAL                            (10000)
885
886 #define ELINK_MAX_PACKET_SIZE                                   (9700)
887 #define MAX_KR_LINK_RETRY                               4
888
889 /**********************************************************/
890 /*                     INTERFACE                          */
891 /**********************************************************/
892
893 #define CL22_WR_OVER_CL45(_sc, _phy, _bank, _addr, _val) \
894         elink_cl45_write(_sc, _phy, \
895                 (_phy)->def_md_devad, \
896                 (_bank + (_addr & 0xf)), \
897                 _val)
898
899 #define CL22_RD_OVER_CL45(_sc, _phy, _bank, _addr, _val) \
900         elink_cl45_read(_sc, _phy, \
901                 (_phy)->def_md_devad, \
902                 (_bank + (_addr & 0xf)), \
903                 _val)
904
905 static uint32_t elink_bits_en(struct bnx2x_softc *sc, uint32_t reg, uint32_t bits)
906 {
907         uint32_t val = REG_RD(sc, reg);
908
909         val |= bits;
910         REG_WR(sc, reg, val);
911         return val;
912 }
913
914 static uint32_t elink_bits_dis(struct bnx2x_softc *sc, uint32_t reg,
915                                uint32_t bits)
916 {
917         uint32_t val = REG_RD(sc, reg);
918
919         val &= ~bits;
920         REG_WR(sc, reg, val);
921         return val;
922 }
923
924 /*
925  * elink_check_lfa - This function checks if link reinitialization is required,
926  *                   or link flap can be avoided.
927  *
928  * @params:     link parameters
929  * Returns 0 if Link Flap Avoidance conditions are met otherwise, the failed
930  *         condition code.
931  */
932 static int elink_check_lfa(struct elink_params *params)
933 {
934         uint32_t link_status, cfg_idx, lfa_mask, cfg_size;
935         uint32_t cur_speed_cap_mask, cur_req_fc_auto_adv, additional_config;
936         uint32_t saved_val, req_val, eee_status;
937         struct bnx2x_softc *sc = params->sc;
938
939         additional_config =
940             REG_RD(sc, params->lfa_base +
941                    offsetof(struct shmem_lfa, additional_config));
942
943         /* NOTE: must be first condition checked -
944          * to verify DCC bit is cleared in any case!
945          */
946         if (additional_config & NO_LFA_DUE_TO_DCC_MASK) {
947                 PMD_DRV_LOG(DEBUG, "No LFA due to DCC flap after clp exit");
948                 REG_WR(sc, params->lfa_base +
949                        offsetof(struct shmem_lfa, additional_config),
950                        additional_config & ~NO_LFA_DUE_TO_DCC_MASK);
951                 return LFA_DCC_LFA_DISABLED;
952         }
953
954         /* Verify that link is up */
955         link_status = REG_RD(sc, params->shmem_base +
956                              offsetof(struct shmem_region,
957                                       port_mb[params->port].link_status));
958         if (!(link_status & LINK_STATUS_LINK_UP))
959                 return LFA_LINK_DOWN;
960
961         /* if loaded after BOOT from SAN, don't flap the link in any case and
962          * rely on link set by preboot driver
963          */
964         if (params->feature_config_flags & ELINK_FEATURE_CONFIG_BOOT_FROM_SAN)
965                 return 0;
966
967         /* Verify that loopback mode is not set */
968         if (params->loopback_mode)
969                 return LFA_LOOPBACK_ENABLED;
970
971         /* Verify that MFW supports LFA */
972         if (!params->lfa_base)
973                 return LFA_MFW_IS_TOO_OLD;
974
975         if (params->num_phys == 3) {
976                 cfg_size = 2;
977                 lfa_mask = 0xffffffff;
978         } else {
979                 cfg_size = 1;
980                 lfa_mask = 0xffff;
981         }
982
983         /* Compare Duplex */
984         saved_val = REG_RD(sc, params->lfa_base +
985                            offsetof(struct shmem_lfa, req_duplex));
986         req_val = params->req_duplex[0] | (params->req_duplex[1] << 16);
987         if ((saved_val & lfa_mask) != (req_val & lfa_mask)) {
988                 PMD_DRV_LOG(INFO, "Duplex mismatch %x vs. %x",
989                             (saved_val & lfa_mask), (req_val & lfa_mask));
990                 return LFA_DUPLEX_MISMATCH;
991         }
992         /* Compare Flow Control */
993         saved_val = REG_RD(sc, params->lfa_base +
994                            offsetof(struct shmem_lfa, req_flow_ctrl));
995         req_val = params->req_flow_ctrl[0] | (params->req_flow_ctrl[1] << 16);
996         if ((saved_val & lfa_mask) != (req_val & lfa_mask)) {
997                 PMD_DRV_LOG(DEBUG, "Flow control mismatch %x vs. %x",
998                             (saved_val & lfa_mask), (req_val & lfa_mask));
999                 return LFA_FLOW_CTRL_MISMATCH;
1000         }
1001         /* Compare Link Speed */
1002         saved_val = REG_RD(sc, params->lfa_base +
1003                            offsetof(struct shmem_lfa, req_line_speed));
1004         req_val = params->req_line_speed[0] | (params->req_line_speed[1] << 16);
1005         if ((saved_val & lfa_mask) != (req_val & lfa_mask)) {
1006                 PMD_DRV_LOG(DEBUG, "Link speed mismatch %x vs. %x",
1007                             (saved_val & lfa_mask), (req_val & lfa_mask));
1008                 return LFA_LINK_SPEED_MISMATCH;
1009         }
1010
1011         for (cfg_idx = 0; cfg_idx < cfg_size; cfg_idx++) {
1012                 cur_speed_cap_mask = REG_RD(sc, params->lfa_base +
1013                                             offsetof(struct shmem_lfa,
1014                                                      speed_cap_mask[cfg_idx]));
1015
1016                 if (cur_speed_cap_mask != params->speed_cap_mask[cfg_idx]) {
1017                         PMD_DRV_LOG(DEBUG, "Speed Cap mismatch %x vs. %x",
1018                                     cur_speed_cap_mask,
1019                                     params->speed_cap_mask[cfg_idx]);
1020                         return LFA_SPEED_CAP_MISMATCH;
1021                 }
1022         }
1023
1024         cur_req_fc_auto_adv =
1025             REG_RD(sc, params->lfa_base +
1026                    offsetof(struct shmem_lfa, additional_config)) &
1027             REQ_FC_AUTO_ADV_MASK;
1028
1029         if ((uint16_t) cur_req_fc_auto_adv != params->req_fc_auto_adv) {
1030                 PMD_DRV_LOG(DEBUG, "Flow Ctrl AN mismatch %x vs. %x",
1031                             cur_req_fc_auto_adv, params->req_fc_auto_adv);
1032                 return LFA_FLOW_CTRL_MISMATCH;
1033         }
1034
1035         eee_status = REG_RD(sc, params->shmem2_base +
1036                             offsetof(struct shmem2_region,
1037                                      eee_status[params->port]));
1038
1039         if (((eee_status & SHMEM_EEE_LPI_REQUESTED_BIT) ^
1040              (params->eee_mode & ELINK_EEE_MODE_ENABLE_LPI)) ||
1041             ((eee_status & SHMEM_EEE_REQUESTED_BIT) ^
1042              (params->eee_mode & ELINK_EEE_MODE_ADV_LPI))) {
1043                 PMD_DRV_LOG(DEBUG, "EEE mismatch %x vs. %x", params->eee_mode,
1044                             eee_status);
1045                 return LFA_EEE_MISMATCH;
1046         }
1047
1048         /* LFA conditions are met */
1049         return 0;
1050 }
1051
1052 /******************************************************************/
1053 /*                      EPIO/GPIO section                         */
1054 /******************************************************************/
1055 static void elink_get_epio(struct bnx2x_softc *sc, uint32_t epio_pin,
1056                            uint32_t * en)
1057 {
1058         uint32_t epio_mask, gp_oenable;
1059         *en = 0;
1060         /* Sanity check */
1061         if (epio_pin > 31) {
1062                 PMD_DRV_LOG(DEBUG, "Invalid EPIO pin %d to get", epio_pin);
1063                 return;
1064         }
1065
1066         epio_mask = 1 << epio_pin;
1067         /* Set this EPIO to output */
1068         gp_oenable = REG_RD(sc, MCP_REG_MCPR_GP_OENABLE);
1069         REG_WR(sc, MCP_REG_MCPR_GP_OENABLE, gp_oenable & ~epio_mask);
1070
1071         *en = (REG_RD(sc, MCP_REG_MCPR_GP_INPUTS) & epio_mask) >> epio_pin;
1072 }
1073
1074 static void elink_set_epio(struct bnx2x_softc *sc, uint32_t epio_pin, uint32_t en)
1075 {
1076         uint32_t epio_mask, gp_output, gp_oenable;
1077
1078         /* Sanity check */
1079         if (epio_pin > 31) {
1080                 PMD_DRV_LOG(DEBUG, "Invalid EPIO pin %d to set", epio_pin);
1081                 return;
1082         }
1083         PMD_DRV_LOG(DEBUG, "Setting EPIO pin %d to %d", epio_pin, en);
1084         epio_mask = 1 << epio_pin;
1085         /* Set this EPIO to output */
1086         gp_output = REG_RD(sc, MCP_REG_MCPR_GP_OUTPUTS);
1087         if (en)
1088                 gp_output |= epio_mask;
1089         else
1090                 gp_output &= ~epio_mask;
1091
1092         REG_WR(sc, MCP_REG_MCPR_GP_OUTPUTS, gp_output);
1093
1094         /* Set the value for this EPIO */
1095         gp_oenable = REG_RD(sc, MCP_REG_MCPR_GP_OENABLE);
1096         REG_WR(sc, MCP_REG_MCPR_GP_OENABLE, gp_oenable | epio_mask);
1097 }
1098
1099 static void elink_set_cfg_pin(struct bnx2x_softc *sc, uint32_t pin_cfg,
1100                               uint32_t val)
1101 {
1102         if (pin_cfg == PIN_CFG_NA)
1103                 return;
1104         if (pin_cfg >= PIN_CFG_EPIO0) {
1105                 elink_set_epio(sc, pin_cfg - PIN_CFG_EPIO0, val);
1106         } else {
1107                 uint8_t gpio_num = (pin_cfg - PIN_CFG_GPIO0_P0) & 0x3;
1108                 uint8_t gpio_port = (pin_cfg - PIN_CFG_GPIO0_P0) >> 2;
1109                 elink_cb_gpio_write(sc, gpio_num, (uint8_t) val, gpio_port);
1110         }
1111 }
1112
1113 static uint32_t elink_get_cfg_pin(struct bnx2x_softc *sc, uint32_t pin_cfg,
1114                                   uint32_t * val)
1115 {
1116         if (pin_cfg == PIN_CFG_NA)
1117                 return ELINK_STATUS_ERROR;
1118         if (pin_cfg >= PIN_CFG_EPIO0) {
1119                 elink_get_epio(sc, pin_cfg - PIN_CFG_EPIO0, val);
1120         } else {
1121                 uint8_t gpio_num = (pin_cfg - PIN_CFG_GPIO0_P0) & 0x3;
1122                 uint8_t gpio_port = (pin_cfg - PIN_CFG_GPIO0_P0) >> 2;
1123                 *val = elink_cb_gpio_read(sc, gpio_num, gpio_port);
1124         }
1125         return ELINK_STATUS_OK;
1126
1127 }
1128
1129 /******************************************************************/
1130 /*                      PFC section                               */
1131 /******************************************************************/
1132 static void elink_update_pfc_xmac(struct elink_params *params,
1133                                   struct elink_vars *vars)
1134 {
1135         struct bnx2x_softc *sc = params->sc;
1136         uint32_t xmac_base;
1137         uint32_t pause_val, pfc0_val, pfc1_val;
1138
1139         /* XMAC base adrr */
1140         xmac_base = (params->port) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
1141
1142         /* Initialize pause and pfc registers */
1143         pause_val = 0x18000;
1144         pfc0_val = 0xFFFF8000;
1145         pfc1_val = 0x2;
1146
1147         /* No PFC support */
1148         if (!(params->feature_config_flags & ELINK_FEATURE_CONFIG_PFC_ENABLED)) {
1149
1150                 /* RX flow control - Process pause frame in receive direction
1151                  */
1152                 if (vars->flow_ctrl & ELINK_FLOW_CTRL_RX)
1153                         pause_val |= XMAC_PAUSE_CTRL_REG_RX_PAUSE_EN;
1154
1155                 /* TX flow control - Send pause packet when buffer is full */
1156                 if (vars->flow_ctrl & ELINK_FLOW_CTRL_TX)
1157                         pause_val |= XMAC_PAUSE_CTRL_REG_TX_PAUSE_EN;
1158         } else {                /* PFC support */
1159                 pfc1_val |= XMAC_PFC_CTRL_HI_REG_PFC_REFRESH_EN |
1160                     XMAC_PFC_CTRL_HI_REG_PFC_STATS_EN |
1161                     XMAC_PFC_CTRL_HI_REG_RX_PFC_EN |
1162                     XMAC_PFC_CTRL_HI_REG_TX_PFC_EN |
1163                     XMAC_PFC_CTRL_HI_REG_FORCE_PFC_XON;
1164                 /* Write pause and PFC registers */
1165                 REG_WR(sc, xmac_base + XMAC_REG_PAUSE_CTRL, pause_val);
1166                 REG_WR(sc, xmac_base + XMAC_REG_PFC_CTRL, pfc0_val);
1167                 REG_WR(sc, xmac_base + XMAC_REG_PFC_CTRL_HI, pfc1_val);
1168                 pfc1_val &= ~XMAC_PFC_CTRL_HI_REG_FORCE_PFC_XON;
1169
1170         }
1171
1172         /* Write pause and PFC registers */
1173         REG_WR(sc, xmac_base + XMAC_REG_PAUSE_CTRL, pause_val);
1174         REG_WR(sc, xmac_base + XMAC_REG_PFC_CTRL, pfc0_val);
1175         REG_WR(sc, xmac_base + XMAC_REG_PFC_CTRL_HI, pfc1_val);
1176
1177         /* Set MAC address for source TX Pause/PFC frames */
1178         REG_WR(sc, xmac_base + XMAC_REG_CTRL_SA_LO,
1179                ((params->mac_addr[2] << 24) |
1180                 (params->mac_addr[3] << 16) |
1181                 (params->mac_addr[4] << 8) | (params->mac_addr[5])));
1182         REG_WR(sc, xmac_base + XMAC_REG_CTRL_SA_HI,
1183                ((params->mac_addr[0] << 8) | (params->mac_addr[1])));
1184
1185         DELAY(30);
1186 }
1187
1188 /******************************************************************/
1189 /*                      MAC/PBF section                           */
1190 /******************************************************************/
1191 static void elink_set_mdio_clk(struct bnx2x_softc *sc, uint32_t emac_base)
1192 {
1193         uint32_t new_mode, cur_mode;
1194         uint32_t clc_cnt;
1195         /* Set clause 45 mode, slow down the MDIO clock to 2.5MHz
1196          * (a value of 49==0x31) and make sure that the AUTO poll is off
1197          */
1198         cur_mode = REG_RD(sc, emac_base + EMAC_REG_EMAC_MDIO_MODE);
1199
1200         if (USES_WARPCORE(sc))
1201                 clc_cnt = 74L << EMAC_MDIO_MODE_CLOCK_CNT_BITSHIFT;
1202         else
1203                 clc_cnt = 49L << EMAC_MDIO_MODE_CLOCK_CNT_BITSHIFT;
1204
1205         if (((cur_mode & EMAC_MDIO_MODE_CLOCK_CNT) == clc_cnt) &&
1206             (cur_mode & (EMAC_MDIO_MODE_CLAUSE_45)))
1207                 return;
1208
1209         new_mode = cur_mode &
1210             ~(EMAC_MDIO_MODE_AUTO_POLL | EMAC_MDIO_MODE_CLOCK_CNT);
1211         new_mode |= clc_cnt;
1212         new_mode |= (EMAC_MDIO_MODE_CLAUSE_45);
1213
1214         PMD_DRV_LOG(DEBUG, "Changing emac_mode from 0x%x to 0x%x",
1215                     cur_mode, new_mode);
1216         REG_WR(sc, emac_base + EMAC_REG_EMAC_MDIO_MODE, new_mode);
1217         DELAY(40);
1218 }
1219
1220 static void elink_set_mdio_emac_per_phy(struct bnx2x_softc *sc,
1221                                         struct elink_params *params)
1222 {
1223         uint8_t phy_index;
1224         /* Set mdio clock per phy */
1225         for (phy_index = ELINK_INT_PHY; phy_index < params->num_phys;
1226              phy_index++)
1227                 elink_set_mdio_clk(sc, params->phy[phy_index].mdio_ctrl);
1228 }
1229
1230 static uint8_t elink_is_4_port_mode(struct bnx2x_softc *sc)
1231 {
1232         uint32_t port4mode_ovwr_val;
1233         /* Check 4-port override enabled */
1234         port4mode_ovwr_val = REG_RD(sc, MISC_REG_PORT4MODE_EN_OVWR);
1235         if (port4mode_ovwr_val & (1 << 0)) {
1236                 /* Return 4-port mode override value */
1237                 return (port4mode_ovwr_val & (1 << 1)) == (1 << 1);
1238         }
1239         /* Return 4-port mode from input pin */
1240         return (uint8_t) REG_RD(sc, MISC_REG_PORT4MODE_EN);
1241 }
1242
1243 static void elink_emac_init(struct elink_params *params)
1244 {
1245         /* reset and unreset the emac core */
1246         struct bnx2x_softc *sc = params->sc;
1247         uint8_t port = params->port;
1248         uint32_t emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
1249         uint32_t val;
1250         uint16_t timeout;
1251
1252         REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
1253                (MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE << port));
1254         DELAY(5);
1255         REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
1256                (MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE << port));
1257
1258         /* init emac - use read-modify-write */
1259         /* self clear reset */
1260         val = REG_RD(sc, emac_base + EMAC_REG_EMAC_MODE);
1261         elink_cb_reg_write(sc, emac_base + EMAC_REG_EMAC_MODE,
1262                            (val | EMAC_MODE_RESET));
1263
1264         timeout = 200;
1265         do {
1266                 val = REG_RD(sc, emac_base + EMAC_REG_EMAC_MODE);
1267                 PMD_DRV_LOG(DEBUG, "EMAC reset reg is %u", val);
1268                 if (!timeout) {
1269                         PMD_DRV_LOG(DEBUG, "EMAC timeout!");
1270                         return;
1271                 }
1272                 timeout--;
1273         } while (val & EMAC_MODE_RESET);
1274
1275         elink_set_mdio_emac_per_phy(sc, params);
1276         /* Set mac address */
1277         val = ((params->mac_addr[0] << 8) | params->mac_addr[1]);
1278         elink_cb_reg_write(sc, emac_base + EMAC_REG_EMAC_MAC_MATCH, val);
1279
1280         val = ((params->mac_addr[2] << 24) |
1281                (params->mac_addr[3] << 16) |
1282                (params->mac_addr[4] << 8) | params->mac_addr[5]);
1283         elink_cb_reg_write(sc, emac_base + EMAC_REG_EMAC_MAC_MATCH + 4, val);
1284 }
1285
1286 static void elink_set_xumac_nig(struct elink_params *params,
1287                                 uint16_t tx_pause_en, uint8_t enable)
1288 {
1289         struct bnx2x_softc *sc = params->sc;
1290
1291         REG_WR(sc, params->port ? NIG_REG_P1_MAC_IN_EN : NIG_REG_P0_MAC_IN_EN,
1292                enable);
1293         REG_WR(sc, params->port ? NIG_REG_P1_MAC_OUT_EN : NIG_REG_P0_MAC_OUT_EN,
1294                enable);
1295         REG_WR(sc, params->port ? NIG_REG_P1_MAC_PAUSE_OUT_EN :
1296                NIG_REG_P0_MAC_PAUSE_OUT_EN, tx_pause_en);
1297 }
1298
1299 static void elink_set_umac_rxtx(struct elink_params *params, uint8_t en)
1300 {
1301         uint32_t umac_base = params->port ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
1302         uint32_t val;
1303         struct bnx2x_softc *sc = params->sc;
1304         if (!(REG_RD(sc, MISC_REG_RESET_REG_2) &
1305               (MISC_REGISTERS_RESET_REG_2_UMAC0 << params->port)))
1306                 return;
1307         val = REG_RD(sc, umac_base + UMAC_REG_COMMAND_CONFIG);
1308         if (en)
1309                 val |= (UMAC_COMMAND_CONFIG_REG_TX_ENA |
1310                         UMAC_COMMAND_CONFIG_REG_RX_ENA);
1311         else
1312                 val &= ~(UMAC_COMMAND_CONFIG_REG_TX_ENA |
1313                          UMAC_COMMAND_CONFIG_REG_RX_ENA);
1314         /* Disable RX and TX */
1315         REG_WR(sc, umac_base + UMAC_REG_COMMAND_CONFIG, val);
1316 }
1317
1318 static void elink_umac_enable(struct elink_params *params,
1319                               struct elink_vars *vars, uint8_t lb)
1320 {
1321         uint32_t val;
1322         uint32_t umac_base = params->port ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
1323         struct bnx2x_softc *sc = params->sc;
1324         /* Reset UMAC */
1325         REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
1326                (MISC_REGISTERS_RESET_REG_2_UMAC0 << params->port));
1327         DELAY(1000 * 1);
1328
1329         REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
1330                (MISC_REGISTERS_RESET_REG_2_UMAC0 << params->port));
1331
1332         PMD_DRV_LOG(DEBUG, "enabling UMAC");
1333
1334         /* This register opens the gate for the UMAC despite its name */
1335         REG_WR(sc, NIG_REG_EGRESS_EMAC0_PORT + params->port * 4, 1);
1336
1337         val = UMAC_COMMAND_CONFIG_REG_PROMIS_EN |
1338             UMAC_COMMAND_CONFIG_REG_PAD_EN |
1339             UMAC_COMMAND_CONFIG_REG_SW_RESET |
1340             UMAC_COMMAND_CONFIG_REG_NO_LGTH_CHECK;
1341         switch (vars->line_speed) {
1342         case ELINK_SPEED_10:
1343                 val |= (0 << 2);
1344                 break;
1345         case ELINK_SPEED_100:
1346                 val |= (1 << 2);
1347                 break;
1348         case ELINK_SPEED_1000:
1349                 val |= (2 << 2);
1350                 break;
1351         case ELINK_SPEED_2500:
1352                 val |= (3 << 2);
1353                 break;
1354         default:
1355                 PMD_DRV_LOG(DEBUG, "Invalid speed for UMAC %d",
1356                             vars->line_speed);
1357                 break;
1358         }
1359         if (!(vars->flow_ctrl & ELINK_FLOW_CTRL_TX))
1360                 val |= UMAC_COMMAND_CONFIG_REG_IGNORE_TX_PAUSE;
1361
1362         if (!(vars->flow_ctrl & ELINK_FLOW_CTRL_RX))
1363                 val |= UMAC_COMMAND_CONFIG_REG_PAUSE_IGNORE;
1364
1365         if (vars->duplex == DUPLEX_HALF)
1366                 val |= UMAC_COMMAND_CONFIG_REG_HD_ENA;
1367
1368         REG_WR(sc, umac_base + UMAC_REG_COMMAND_CONFIG, val);
1369         DELAY(50);
1370
1371         /* Configure UMAC for EEE */
1372         if (vars->eee_status & SHMEM_EEE_ADV_STATUS_MASK) {
1373                 PMD_DRV_LOG(DEBUG, "configured UMAC for EEE");
1374                 REG_WR(sc, umac_base + UMAC_REG_UMAC_EEE_CTRL,
1375                        UMAC_UMAC_EEE_CTRL_REG_EEE_EN);
1376                 REG_WR(sc, umac_base + UMAC_REG_EEE_WAKE_TIMER, 0x11);
1377         } else {
1378                 REG_WR(sc, umac_base + UMAC_REG_UMAC_EEE_CTRL, 0x0);
1379         }
1380
1381         /* Set MAC address for source TX Pause/PFC frames (under SW reset) */
1382         REG_WR(sc, umac_base + UMAC_REG_MAC_ADDR0,
1383                ((params->mac_addr[2] << 24) |
1384                 (params->mac_addr[3] << 16) |
1385                 (params->mac_addr[4] << 8) | (params->mac_addr[5])));
1386         REG_WR(sc, umac_base + UMAC_REG_MAC_ADDR1,
1387                ((params->mac_addr[0] << 8) | (params->mac_addr[1])));
1388
1389         /* Enable RX and TX */
1390         val &= ~UMAC_COMMAND_CONFIG_REG_PAD_EN;
1391         val |= UMAC_COMMAND_CONFIG_REG_TX_ENA | UMAC_COMMAND_CONFIG_REG_RX_ENA;
1392         REG_WR(sc, umac_base + UMAC_REG_COMMAND_CONFIG, val);
1393         DELAY(50);
1394
1395         /* Remove SW Reset */
1396         val &= ~UMAC_COMMAND_CONFIG_REG_SW_RESET;
1397
1398         /* Check loopback mode */
1399         if (lb)
1400                 val |= UMAC_COMMAND_CONFIG_REG_LOOP_ENA;
1401         REG_WR(sc, umac_base + UMAC_REG_COMMAND_CONFIG, val);
1402
1403         /* Maximum Frame Length (RW). Defines a 14-Bit maximum frame
1404          * length used by the MAC receive logic to check frames.
1405          */
1406         REG_WR(sc, umac_base + UMAC_REG_MAXFR, 0x2710);
1407         elink_set_xumac_nig(params,
1408                             ((vars->flow_ctrl & ELINK_FLOW_CTRL_TX) != 0), 1);
1409         vars->mac_type = ELINK_MAC_TYPE_UMAC;
1410
1411 }
1412
1413 /* Define the XMAC mode */
1414 static void elink_xmac_init(struct elink_params *params, uint32_t max_speed)
1415 {
1416         struct bnx2x_softc *sc = params->sc;
1417         uint32_t is_port4mode = elink_is_4_port_mode(sc);
1418
1419         /* In 4-port mode, need to set the mode only once, so if XMAC is
1420          * already out of reset, it means the mode has already been set,
1421          * and it must not* reset the XMAC again, since it controls both
1422          * ports of the path
1423          */
1424
1425         if (((CHIP_NUM(sc) == CHIP_NUM_57840_4_10) ||
1426              (CHIP_NUM(sc) == CHIP_NUM_57840_2_20) ||
1427              (CHIP_NUM(sc) == CHIP_NUM_57840_OBS)) &&
1428             is_port4mode &&
1429             (REG_RD(sc, MISC_REG_RESET_REG_2) &
1430              MISC_REGISTERS_RESET_REG_2_XMAC)) {
1431                 PMD_DRV_LOG(DEBUG, "XMAC already out of reset in 4-port mode");
1432                 return;
1433         }
1434
1435         /* Hard reset */
1436         REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
1437                MISC_REGISTERS_RESET_REG_2_XMAC);
1438         DELAY(1000 * 1);
1439
1440         REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
1441                MISC_REGISTERS_RESET_REG_2_XMAC);
1442         if (is_port4mode) {
1443                 PMD_DRV_LOG(DEBUG, "Init XMAC to 2 ports x 10G per path");
1444
1445                 /* Set the number of ports on the system side to up to 2 */
1446                 REG_WR(sc, MISC_REG_XMAC_CORE_PORT_MODE, 1);
1447
1448                 /* Set the number of ports on the Warp Core to 10G */
1449                 REG_WR(sc, MISC_REG_XMAC_PHY_PORT_MODE, 3);
1450         } else {
1451                 /* Set the number of ports on the system side to 1 */
1452                 REG_WR(sc, MISC_REG_XMAC_CORE_PORT_MODE, 0);
1453                 if (max_speed == ELINK_SPEED_10000) {
1454                         PMD_DRV_LOG(DEBUG,
1455                                     "Init XMAC to 10G x 1 port per path");
1456                         /* Set the number of ports on the Warp Core to 10G */
1457                         REG_WR(sc, MISC_REG_XMAC_PHY_PORT_MODE, 3);
1458                 } else {
1459                         PMD_DRV_LOG(DEBUG,
1460                                     "Init XMAC to 20G x 2 ports per path");
1461                         /* Set the number of ports on the Warp Core to 20G */
1462                         REG_WR(sc, MISC_REG_XMAC_PHY_PORT_MODE, 1);
1463                 }
1464         }
1465         /* Soft reset */
1466         REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
1467                MISC_REGISTERS_RESET_REG_2_XMAC_SOFT);
1468         DELAY(1000 * 1);
1469
1470         REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
1471                MISC_REGISTERS_RESET_REG_2_XMAC_SOFT);
1472
1473 }
1474
1475 static void elink_set_xmac_rxtx(struct elink_params *params, uint8_t en)
1476 {
1477         uint8_t port = params->port;
1478         struct bnx2x_softc *sc = params->sc;
1479         uint32_t pfc_ctrl, xmac_base = (port) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
1480         uint32_t val;
1481
1482         if (REG_RD(sc, MISC_REG_RESET_REG_2) & MISC_REGISTERS_RESET_REG_2_XMAC) {
1483                 /* Send an indication to change the state in the NIG back to XON
1484                  * Clearing this bit enables the next set of this bit to get
1485                  * rising edge
1486                  */
1487                 pfc_ctrl = REG_RD(sc, xmac_base + XMAC_REG_PFC_CTRL_HI);
1488                 REG_WR(sc, xmac_base + XMAC_REG_PFC_CTRL_HI,
1489                        (pfc_ctrl & ~(1 << 1)));
1490                 REG_WR(sc, xmac_base + XMAC_REG_PFC_CTRL_HI,
1491                        (pfc_ctrl | (1 << 1)));
1492                 PMD_DRV_LOG(DEBUG, "Disable XMAC on port %x", port);
1493                 val = REG_RD(sc, xmac_base + XMAC_REG_CTRL);
1494                 if (en)
1495                         val |= (XMAC_CTRL_REG_TX_EN | XMAC_CTRL_REG_RX_EN);
1496                 else
1497                         val &= ~(XMAC_CTRL_REG_TX_EN | XMAC_CTRL_REG_RX_EN);
1498                 REG_WR(sc, xmac_base + XMAC_REG_CTRL, val);
1499         }
1500 }
1501
1502 static elink_status_t elink_xmac_enable(struct elink_params *params,
1503                                         struct elink_vars *vars, uint8_t lb)
1504 {
1505         uint32_t val, xmac_base;
1506         struct bnx2x_softc *sc = params->sc;
1507         PMD_DRV_LOG(DEBUG, "enabling XMAC");
1508
1509         xmac_base = (params->port) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
1510
1511         elink_xmac_init(params, vars->line_speed);
1512
1513         /* This register determines on which events the MAC will assert
1514          * error on the i/f to the NIG along w/ EOP.
1515          */
1516
1517         /* This register tells the NIG whether to send traffic to UMAC
1518          * or XMAC
1519          */
1520         REG_WR(sc, NIG_REG_EGRESS_EMAC0_PORT + params->port * 4, 0);
1521
1522         /* When XMAC is in XLGMII mode, disable sending idles for fault
1523          * detection.
1524          */
1525         if (!(params->phy[ELINK_INT_PHY].flags & ELINK_FLAGS_TX_ERROR_CHECK)) {
1526                 REG_WR(sc, xmac_base + XMAC_REG_RX_LSS_CTRL,
1527                        (XMAC_RX_LSS_CTRL_REG_LOCAL_FAULT_DISABLE |
1528                         XMAC_RX_LSS_CTRL_REG_REMOTE_FAULT_DISABLE));
1529                 REG_WR(sc, xmac_base + XMAC_REG_CLEAR_RX_LSS_STATUS, 0);
1530                 REG_WR(sc, xmac_base + XMAC_REG_CLEAR_RX_LSS_STATUS,
1531                        XMAC_CLEAR_RX_LSS_STATUS_REG_CLEAR_LOCAL_FAULT_STATUS |
1532                        XMAC_CLEAR_RX_LSS_STATUS_REG_CLEAR_REMOTE_FAULT_STATUS);
1533         }
1534         /* Set Max packet size */
1535         REG_WR(sc, xmac_base + XMAC_REG_RX_MAX_SIZE, 0x2710);
1536
1537         /* CRC append for Tx packets */
1538         REG_WR(sc, xmac_base + XMAC_REG_TX_CTRL, 0xC800);
1539
1540         /* update PFC */
1541         elink_update_pfc_xmac(params, vars);
1542
1543         if (vars->eee_status & SHMEM_EEE_ADV_STATUS_MASK) {
1544                 PMD_DRV_LOG(DEBUG, "Setting XMAC for EEE");
1545                 REG_WR(sc, xmac_base + XMAC_REG_EEE_TIMERS_HI, 0x1380008);
1546                 REG_WR(sc, xmac_base + XMAC_REG_EEE_CTRL, 0x1);
1547         } else {
1548                 REG_WR(sc, xmac_base + XMAC_REG_EEE_CTRL, 0x0);
1549         }
1550
1551         /* Enable TX and RX */
1552         val = XMAC_CTRL_REG_TX_EN | XMAC_CTRL_REG_RX_EN;
1553
1554         /* Set MAC in XLGMII mode for dual-mode */
1555         if ((vars->line_speed == ELINK_SPEED_20000) &&
1556             (params->phy[ELINK_INT_PHY].supported &
1557              ELINK_SUPPORTED_20000baseKR2_Full))
1558                 val |= XMAC_CTRL_REG_XLGMII_ALIGN_ENB;
1559
1560         /* Check loopback mode */
1561         if (lb)
1562                 val |= XMAC_CTRL_REG_LINE_LOCAL_LPBK;
1563         REG_WR(sc, xmac_base + XMAC_REG_CTRL, val);
1564         elink_set_xumac_nig(params,
1565                             ((vars->flow_ctrl & ELINK_FLOW_CTRL_TX) != 0), 1);
1566
1567         vars->mac_type = ELINK_MAC_TYPE_XMAC;
1568
1569         return ELINK_STATUS_OK;
1570 }
1571
1572 static elink_status_t elink_emac_enable(struct elink_params *params,
1573                                         struct elink_vars *vars, uint8_t lb)
1574 {
1575         struct bnx2x_softc *sc = params->sc;
1576         uint8_t port = params->port;
1577         uint32_t emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
1578         uint32_t val;
1579
1580         PMD_DRV_LOG(DEBUG, "enabling EMAC");
1581
1582         /* Disable BMAC */
1583         REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
1584                (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port));
1585
1586         /* enable emac and not bmac */
1587         REG_WR(sc, NIG_REG_EGRESS_EMAC0_PORT + port * 4, 1);
1588
1589 #ifdef ELINK_INCLUDE_EMUL
1590         /* for paladium */
1591         if (CHIP_REV_IS_EMUL(sc)) {
1592                 /* Use lane 1 (of lanes 0-3) */
1593                 REG_WR(sc, NIG_REG_XGXS_LANE_SEL_P0 + port * 4, 1);
1594                 REG_WR(sc, NIG_REG_XGXS_SERDES0_MODE_SEL + port * 4, 1);
1595         }
1596         /* for fpga */
1597         else
1598 #endif
1599 #ifdef ELINK_INCLUDE_FPGA
1600         if (CHIP_REV_IS_FPGA(sc)) {
1601                 /* Use lane 1 (of lanes 0-3) */
1602                 PMD_DRV_LOG(DEBUG, "elink_emac_enable: Setting FPGA");
1603
1604                 REG_WR(sc, NIG_REG_XGXS_LANE_SEL_P0 + port * 4, 1);
1605                 REG_WR(sc, NIG_REG_XGXS_SERDES0_MODE_SEL + port * 4, 0);
1606         } else
1607 #endif
1608                 /* ASIC */
1609         if (vars->phy_flags & PHY_XGXS_FLAG) {
1610                 uint32_t ser_lane = ((params->lane_config &
1611                                       PORT_HW_CFG_LANE_SWAP_CFG_MASTER_MASK) >>
1612                                      PORT_HW_CFG_LANE_SWAP_CFG_MASTER_SHIFT);
1613
1614                 PMD_DRV_LOG(DEBUG, "XGXS");
1615                 /* select the master lanes (out of 0-3) */
1616                 REG_WR(sc, NIG_REG_XGXS_LANE_SEL_P0 + port * 4, ser_lane);
1617                 /* select XGXS */
1618                 REG_WR(sc, NIG_REG_XGXS_SERDES0_MODE_SEL + port * 4, 1);
1619
1620         } else {                /* SerDes */
1621                 PMD_DRV_LOG(DEBUG, "SerDes");
1622                 /* select SerDes */
1623                 REG_WR(sc, NIG_REG_XGXS_SERDES0_MODE_SEL + port * 4, 0);
1624         }
1625
1626         elink_bits_en(sc, emac_base + EMAC_REG_EMAC_RX_MODE,
1627                       EMAC_RX_MODE_RESET);
1628         elink_bits_en(sc, emac_base + EMAC_REG_EMAC_TX_MODE,
1629                       EMAC_TX_MODE_RESET);
1630
1631 #if defined(ELINK_INCLUDE_EMUL) || defined(ELINK_INCLUDE_FPGA)
1632         if (CHIP_REV_IS_SLOW(sc)) {
1633                 /* config GMII mode */
1634                 val = REG_RD(sc, emac_base + EMAC_REG_EMAC_MODE);
1635                 elink_cb_reg_write(sc, emac_base + EMAC_REG_EMAC_MODE,
1636                                    (val | EMAC_MODE_PORT_GMII));
1637         } else {                /* ASIC */
1638 #endif
1639                 /* pause enable/disable */
1640                 elink_bits_dis(sc, emac_base + EMAC_REG_EMAC_RX_MODE,
1641                                EMAC_RX_MODE_FLOW_EN);
1642
1643                 elink_bits_dis(sc, emac_base + EMAC_REG_EMAC_TX_MODE,
1644                                (EMAC_TX_MODE_EXT_PAUSE_EN |
1645                                 EMAC_TX_MODE_FLOW_EN));
1646                 if (!(params->feature_config_flags &
1647                       ELINK_FEATURE_CONFIG_PFC_ENABLED)) {
1648                         if (vars->flow_ctrl & ELINK_FLOW_CTRL_RX)
1649                                 elink_bits_en(sc, emac_base +
1650                                               EMAC_REG_EMAC_RX_MODE,
1651                                               EMAC_RX_MODE_FLOW_EN);
1652
1653                         if (vars->flow_ctrl & ELINK_FLOW_CTRL_TX)
1654                                 elink_bits_en(sc, emac_base +
1655                                               EMAC_REG_EMAC_TX_MODE,
1656                                               (EMAC_TX_MODE_EXT_PAUSE_EN |
1657                                                EMAC_TX_MODE_FLOW_EN));
1658                 } else
1659                         elink_bits_en(sc, emac_base + EMAC_REG_EMAC_TX_MODE,
1660                                       EMAC_TX_MODE_FLOW_EN);
1661 #if defined(ELINK_INCLUDE_EMUL) || defined(ELINK_INCLUDE_FPGA)
1662         }
1663 #endif
1664
1665         /* KEEP_VLAN_TAG, promiscuous */
1666         val = REG_RD(sc, emac_base + EMAC_REG_EMAC_RX_MODE);
1667         val |= EMAC_RX_MODE_KEEP_VLAN_TAG | EMAC_RX_MODE_PROMISCUOUS;
1668
1669         /* Setting this bit causes MAC control frames (except for pause
1670          * frames) to be passed on for processing. This setting has no
1671          * affect on the operation of the pause frames. This bit effects
1672          * all packets regardless of RX Parser packet sorting logic.
1673          * Turn the PFC off to make sure we are in Xon state before
1674          * enabling it.
1675          */
1676         elink_cb_reg_write(sc, emac_base + EMAC_REG_RX_PFC_MODE, 0);
1677         if (params->feature_config_flags & ELINK_FEATURE_CONFIG_PFC_ENABLED) {
1678                 PMD_DRV_LOG(DEBUG, "PFC is enabled");
1679                 /* Enable PFC again */
1680                 elink_cb_reg_write(sc, emac_base + EMAC_REG_RX_PFC_MODE,
1681                                    EMAC_REG_RX_PFC_MODE_RX_EN |
1682                                    EMAC_REG_RX_PFC_MODE_TX_EN |
1683                                    EMAC_REG_RX_PFC_MODE_PRIORITIES);
1684
1685                 elink_cb_reg_write(sc, emac_base + EMAC_REG_RX_PFC_PARAM,
1686                                    ((0x0101 <<
1687                                      EMAC_REG_RX_PFC_PARAM_OPCODE_BITSHIFT) |
1688                                     (0x00ff <<
1689                                      EMAC_REG_RX_PFC_PARAM_PRIORITY_EN_BITSHIFT)));
1690                 val |= EMAC_RX_MODE_KEEP_MAC_CONTROL;
1691         }
1692         elink_cb_reg_write(sc, emac_base + EMAC_REG_EMAC_RX_MODE, val);
1693
1694         /* Set Loopback */
1695         val = REG_RD(sc, emac_base + EMAC_REG_EMAC_MODE);
1696         if (lb)
1697                 val |= 0x810;
1698         else
1699                 val &= ~0x810;
1700         elink_cb_reg_write(sc, emac_base + EMAC_REG_EMAC_MODE, val);
1701
1702         /* Enable emac */
1703         REG_WR(sc, NIG_REG_NIG_EMAC0_EN + port * 4, 1);
1704
1705         /* Enable emac for jumbo packets */
1706         elink_cb_reg_write(sc, emac_base + EMAC_REG_EMAC_RX_MTU_SIZE,
1707                            (EMAC_RX_MTU_SIZE_JUMBO_ENA |
1708                             (ELINK_ETH_MAX_JUMBO_PACKET_SIZE +
1709                              ELINK_ETH_OVREHEAD)));
1710
1711         /* Strip CRC */
1712         REG_WR(sc, NIG_REG_NIG_INGRESS_EMAC0_NO_CRC + port * 4, 0x1);
1713
1714         /* Disable the NIG in/out to the bmac */
1715         REG_WR(sc, NIG_REG_BMAC0_IN_EN + port * 4, 0x0);
1716         REG_WR(sc, NIG_REG_BMAC0_PAUSE_OUT_EN + port * 4, 0x0);
1717         REG_WR(sc, NIG_REG_BMAC0_OUT_EN + port * 4, 0x0);
1718
1719         /* Enable the NIG in/out to the emac */
1720         REG_WR(sc, NIG_REG_EMAC0_IN_EN + port * 4, 0x1);
1721         val = 0;
1722         if ((params->feature_config_flags &
1723              ELINK_FEATURE_CONFIG_PFC_ENABLED) ||
1724             (vars->flow_ctrl & ELINK_FLOW_CTRL_TX))
1725                 val = 1;
1726
1727         REG_WR(sc, NIG_REG_EMAC0_PAUSE_OUT_EN + port * 4, val);
1728         REG_WR(sc, NIG_REG_EGRESS_EMAC0_OUT_EN + port * 4, 0x1);
1729
1730 #ifdef ELINK_INCLUDE_EMUL
1731         if (CHIP_REV_IS_EMUL(sc)) {
1732                 /* Take the BigMac out of reset */
1733                 REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
1734                        (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port));
1735
1736                 /* Enable access for bmac registers */
1737                 REG_WR(sc, NIG_REG_BMAC0_REGS_OUT_EN + port * 4, 0x1);
1738         } else
1739 #endif
1740                 REG_WR(sc, NIG_REG_BMAC0_REGS_OUT_EN + port * 4, 0x0);
1741
1742         vars->mac_type = ELINK_MAC_TYPE_EMAC;
1743         return ELINK_STATUS_OK;
1744 }
1745
1746 static void elink_update_pfc_bmac1(struct elink_params *params,
1747                                    struct elink_vars *vars)
1748 {
1749         uint32_t wb_data[2];
1750         struct bnx2x_softc *sc = params->sc;
1751         uint32_t bmac_addr = params->port ? NIG_REG_INGRESS_BMAC1_MEM :
1752             NIG_REG_INGRESS_BMAC0_MEM;
1753
1754         uint32_t val = 0x14;
1755         if ((!(params->feature_config_flags &
1756                ELINK_FEATURE_CONFIG_PFC_ENABLED)) &&
1757             (vars->flow_ctrl & ELINK_FLOW_CTRL_RX))
1758                 /* Enable BigMAC to react on received Pause packets */
1759                 val |= (1 << 5);
1760         wb_data[0] = val;
1761         wb_data[1] = 0;
1762         REG_WR_DMAE(sc, bmac_addr + BIGMAC_REGISTER_RX_CONTROL, wb_data, 2);
1763
1764         /* TX control */
1765         val = 0xc0;
1766         if (!(params->feature_config_flags &
1767               ELINK_FEATURE_CONFIG_PFC_ENABLED) &&
1768             (vars->flow_ctrl & ELINK_FLOW_CTRL_TX))
1769                 val |= 0x800000;
1770         wb_data[0] = val;
1771         wb_data[1] = 0;
1772         REG_WR_DMAE(sc, bmac_addr + BIGMAC_REGISTER_TX_CONTROL, wb_data, 2);
1773 }
1774
1775 static void elink_update_pfc_bmac2(struct elink_params *params,
1776                                    struct elink_vars *vars, uint8_t is_lb)
1777 {
1778         /* Set rx control: Strip CRC and enable BigMAC to relay
1779          * control packets to the system as well
1780          */
1781         uint32_t wb_data[2];
1782         struct bnx2x_softc *sc = params->sc;
1783         uint32_t bmac_addr = params->port ? NIG_REG_INGRESS_BMAC1_MEM :
1784             NIG_REG_INGRESS_BMAC0_MEM;
1785         uint32_t val = 0x14;
1786
1787         if ((!(params->feature_config_flags &
1788                ELINK_FEATURE_CONFIG_PFC_ENABLED)) &&
1789             (vars->flow_ctrl & ELINK_FLOW_CTRL_RX))
1790                 /* Enable BigMAC to react on received Pause packets */
1791                 val |= (1 << 5);
1792         wb_data[0] = val;
1793         wb_data[1] = 0;
1794         REG_WR_DMAE(sc, bmac_addr + BIGMAC2_REGISTER_RX_CONTROL, wb_data, 2);
1795         DELAY(30);
1796
1797         /* Tx control */
1798         val = 0xc0;
1799         if (!(params->feature_config_flags &
1800               ELINK_FEATURE_CONFIG_PFC_ENABLED) &&
1801             (vars->flow_ctrl & ELINK_FLOW_CTRL_TX))
1802                 val |= 0x800000;
1803         wb_data[0] = val;
1804         wb_data[1] = 0;
1805         REG_WR_DMAE(sc, bmac_addr + BIGMAC2_REGISTER_TX_CONTROL, wb_data, 2);
1806
1807         if (params->feature_config_flags & ELINK_FEATURE_CONFIG_PFC_ENABLED) {
1808                 PMD_DRV_LOG(DEBUG, "PFC is enabled");
1809                 /* Enable PFC RX & TX & STATS and set 8 COS  */
1810                 wb_data[0] = 0x0;
1811                 wb_data[0] |= (1 << 0); /* RX */
1812                 wb_data[0] |= (1 << 1); /* TX */
1813                 wb_data[0] |= (1 << 2); /* Force initial Xon */
1814                 wb_data[0] |= (1 << 3); /* 8 cos */
1815                 wb_data[0] |= (1 << 5); /* STATS */
1816                 wb_data[1] = 0;
1817                 REG_WR_DMAE(sc, bmac_addr + BIGMAC2_REGISTER_PFC_CONTROL,
1818                             wb_data, 2);
1819                 /* Clear the force Xon */
1820                 wb_data[0] &= ~(1 << 2);
1821         } else {
1822                 PMD_DRV_LOG(DEBUG, "PFC is disabled");
1823                 /* Disable PFC RX & TX & STATS and set 8 COS */
1824                 wb_data[0] = 0x8;
1825                 wb_data[1] = 0;
1826         }
1827
1828         REG_WR_DMAE(sc, bmac_addr + BIGMAC2_REGISTER_PFC_CONTROL, wb_data, 2);
1829
1830         /* Set Time (based unit is 512 bit time) between automatic
1831          * re-sending of PP packets amd enable automatic re-send of
1832          * Per-Priroity Packet as long as pp_gen is asserted and
1833          * pp_disable is low.
1834          */
1835         val = 0x8000;
1836         if (params->feature_config_flags & ELINK_FEATURE_CONFIG_PFC_ENABLED)
1837                 val |= (1 << 16);       /* enable automatic re-send */
1838
1839         wb_data[0] = val;
1840         wb_data[1] = 0;
1841         REG_WR_DMAE(sc, bmac_addr + BIGMAC2_REGISTER_TX_PAUSE_CONTROL,
1842                     wb_data, 2);
1843
1844         /* mac control */
1845         val = 0x3;              /* Enable RX and TX */
1846         if (is_lb) {
1847                 val |= 0x4;     /* Local loopback */
1848                 PMD_DRV_LOG(DEBUG, "enable bmac loopback");
1849         }
1850         /* When PFC enabled, Pass pause frames towards the NIG. */
1851         if (params->feature_config_flags & ELINK_FEATURE_CONFIG_PFC_ENABLED)
1852                 val |= ((1 << 6) | (1 << 5));
1853
1854         wb_data[0] = val;
1855         wb_data[1] = 0;
1856         REG_WR_DMAE(sc, bmac_addr + BIGMAC2_REGISTER_BMAC_CONTROL, wb_data, 2);
1857 }
1858
1859 /******************************************************************************
1860 * Description:
1861 *  This function is needed because NIG ARB_CREDIT_WEIGHT_X are
1862 *  not continues and ARB_CREDIT_WEIGHT_0 + offset is suitable.
1863 ******************************************************************************/
1864 static elink_status_t elink_pfc_nig_rx_priority_mask(struct bnx2x_softc *sc,
1865                                                      uint8_t cos_entry,
1866                                                      uint32_t priority_mask,
1867                                                      uint8_t port)
1868 {
1869         uint32_t nig_reg_rx_priority_mask_add = 0;
1870
1871         switch (cos_entry) {
1872         case 0:
1873                 nig_reg_rx_priority_mask_add = (port) ?
1874                     NIG_REG_P1_RX_COS0_PRIORITY_MASK :
1875                     NIG_REG_P0_RX_COS0_PRIORITY_MASK;
1876                 break;
1877         case 1:
1878                 nig_reg_rx_priority_mask_add = (port) ?
1879                     NIG_REG_P1_RX_COS1_PRIORITY_MASK :
1880                     NIG_REG_P0_RX_COS1_PRIORITY_MASK;
1881                 break;
1882         case 2:
1883                 nig_reg_rx_priority_mask_add = (port) ?
1884                     NIG_REG_P1_RX_COS2_PRIORITY_MASK :
1885                     NIG_REG_P0_RX_COS2_PRIORITY_MASK;
1886                 break;
1887         case 3:
1888                 if (port)
1889                         return ELINK_STATUS_ERROR;
1890                 nig_reg_rx_priority_mask_add = NIG_REG_P0_RX_COS3_PRIORITY_MASK;
1891                 break;
1892         case 4:
1893                 if (port)
1894                         return ELINK_STATUS_ERROR;
1895                 nig_reg_rx_priority_mask_add = NIG_REG_P0_RX_COS4_PRIORITY_MASK;
1896                 break;
1897         case 5:
1898                 if (port)
1899                         return ELINK_STATUS_ERROR;
1900                 nig_reg_rx_priority_mask_add = NIG_REG_P0_RX_COS5_PRIORITY_MASK;
1901                 break;
1902         }
1903
1904         REG_WR(sc, nig_reg_rx_priority_mask_add, priority_mask);
1905
1906         return ELINK_STATUS_OK;
1907 }
1908
1909 static void elink_update_mng(struct elink_params *params, uint32_t link_status)
1910 {
1911         struct bnx2x_softc *sc = params->sc;
1912
1913         REG_WR(sc, params->shmem_base +
1914                offsetof(struct shmem_region,
1915                         port_mb[params->port].link_status), link_status);
1916 }
1917
1918 static void elink_update_link_attr(struct elink_params *params,
1919                                    uint32_t link_attr)
1920 {
1921         struct bnx2x_softc *sc = params->sc;
1922
1923         if (SHMEM2_HAS(sc, link_attr_sync))
1924                 REG_WR(sc, params->shmem2_base +
1925                        offsetof(struct shmem2_region,
1926                                 link_attr_sync[params->port]), link_attr);
1927 }
1928
1929 static void elink_update_pfc_nig(struct elink_params *params,
1930                                  struct elink_nig_brb_pfc_port_params
1931                                  *nig_params)
1932 {
1933         uint32_t xcm_mask = 0, ppp_enable = 0, pause_enable = 0, llfc_out_en =
1934             0;
1935         uint32_t llfc_enable = 0, xcm_out_en = 0, hwpfc_enable = 0;
1936         uint32_t pkt_priority_to_cos = 0;
1937         struct bnx2x_softc *sc = params->sc;
1938         uint8_t port = params->port;
1939
1940         int set_pfc = params->feature_config_flags &
1941             ELINK_FEATURE_CONFIG_PFC_ENABLED;
1942         PMD_DRV_LOG(DEBUG, "updating pfc nig parameters");
1943
1944         /* When NIG_LLH0_XCM_MASK_REG_LLHX_XCM_MASK_BCN bit is set
1945          * MAC control frames (that are not pause packets)
1946          * will be forwarded to the XCM.
1947          */
1948         xcm_mask = REG_RD(sc, port ? NIG_REG_LLH1_XCM_MASK :
1949                           NIG_REG_LLH0_XCM_MASK);
1950         /* NIG params will override non PFC params, since it's possible to
1951          * do transition from PFC to SAFC
1952          */
1953         if (set_pfc) {
1954                 pause_enable = 0;
1955                 llfc_out_en = 0;
1956                 llfc_enable = 0;
1957                 if (CHIP_IS_E3(sc))
1958                         ppp_enable = 0;
1959                 else
1960                         ppp_enable = 1;
1961                 xcm_mask &= ~(port ? NIG_LLH1_XCM_MASK_REG_LLH1_XCM_MASK_BCN :
1962                               NIG_LLH0_XCM_MASK_REG_LLH0_XCM_MASK_BCN);
1963                 xcm_out_en = 0;
1964                 hwpfc_enable = 1;
1965         } else {
1966                 if (nig_params) {
1967                         llfc_out_en = nig_params->llfc_out_en;
1968                         llfc_enable = nig_params->llfc_enable;
1969                         pause_enable = nig_params->pause_enable;
1970                 } else          /* Default non PFC mode - PAUSE */
1971                         pause_enable = 1;
1972
1973                 xcm_mask |= (port ? NIG_LLH1_XCM_MASK_REG_LLH1_XCM_MASK_BCN :
1974                              NIG_LLH0_XCM_MASK_REG_LLH0_XCM_MASK_BCN);
1975                 xcm_out_en = 1;
1976         }
1977
1978         if (CHIP_IS_E3(sc))
1979                 REG_WR(sc, port ? NIG_REG_BRB1_PAUSE_IN_EN :
1980                        NIG_REG_BRB0_PAUSE_IN_EN, pause_enable);
1981         REG_WR(sc, port ? NIG_REG_LLFC_OUT_EN_1 :
1982                NIG_REG_LLFC_OUT_EN_0, llfc_out_en);
1983         REG_WR(sc, port ? NIG_REG_LLFC_ENABLE_1 :
1984                NIG_REG_LLFC_ENABLE_0, llfc_enable);
1985         REG_WR(sc, port ? NIG_REG_PAUSE_ENABLE_1 :
1986                NIG_REG_PAUSE_ENABLE_0, pause_enable);
1987
1988         REG_WR(sc, port ? NIG_REG_PPP_ENABLE_1 :
1989                NIG_REG_PPP_ENABLE_0, ppp_enable);
1990
1991         REG_WR(sc, port ? NIG_REG_LLH1_XCM_MASK :
1992                NIG_REG_LLH0_XCM_MASK, xcm_mask);
1993
1994         REG_WR(sc, port ? NIG_REG_LLFC_EGRESS_SRC_ENABLE_1 :
1995                NIG_REG_LLFC_EGRESS_SRC_ENABLE_0, 0x7);
1996
1997         /* Output enable for RX_XCM # IF */
1998         REG_WR(sc, port ? NIG_REG_XCM1_OUT_EN :
1999                NIG_REG_XCM0_OUT_EN, xcm_out_en);
2000
2001         /* HW PFC TX enable */
2002         REG_WR(sc, port ? NIG_REG_P1_HWPFC_ENABLE :
2003                NIG_REG_P0_HWPFC_ENABLE, hwpfc_enable);
2004
2005         if (nig_params) {
2006                 uint8_t i = 0;
2007                 pkt_priority_to_cos = nig_params->pkt_priority_to_cos;
2008
2009                 for (i = 0; i < nig_params->num_of_rx_cos_priority_mask; i++)
2010                         elink_pfc_nig_rx_priority_mask(sc, i,
2011                                                        nig_params->
2012                                                        rx_cos_priority_mask[i],
2013                                                        port);
2014
2015                 REG_WR(sc, port ? NIG_REG_LLFC_HIGH_PRIORITY_CLASSES_1 :
2016                        NIG_REG_LLFC_HIGH_PRIORITY_CLASSES_0,
2017                        nig_params->llfc_high_priority_classes);
2018
2019                 REG_WR(sc, port ? NIG_REG_LLFC_LOW_PRIORITY_CLASSES_1 :
2020                        NIG_REG_LLFC_LOW_PRIORITY_CLASSES_0,
2021                        nig_params->llfc_low_priority_classes);
2022         }
2023         REG_WR(sc, port ? NIG_REG_P1_PKT_PRIORITY_TO_COS :
2024                NIG_REG_P0_PKT_PRIORITY_TO_COS, pkt_priority_to_cos);
2025 }
2026
2027 elink_status_t elink_update_pfc(struct elink_params *params,
2028                                 struct elink_vars *vars,
2029                                 struct elink_nig_brb_pfc_port_params
2030                                 *pfc_params)
2031 {
2032         /* The PFC and pause are orthogonal to one another, meaning when
2033          * PFC is enabled, the pause are disabled, and when PFC is
2034          * disabled, pause are set according to the pause result.
2035          */
2036         uint32_t val;
2037         struct bnx2x_softc *sc = params->sc;
2038         elink_status_t elink_status = ELINK_STATUS_OK;
2039         uint8_t bmac_loopback = (params->loopback_mode == ELINK_LOOPBACK_BMAC);
2040
2041         if (params->feature_config_flags & ELINK_FEATURE_CONFIG_PFC_ENABLED)
2042                 vars->link_status |= LINK_STATUS_PFC_ENABLED;
2043         else
2044                 vars->link_status &= ~LINK_STATUS_PFC_ENABLED;
2045
2046         elink_update_mng(params, vars->link_status);
2047
2048         /* Update NIG params */
2049         elink_update_pfc_nig(params, pfc_params);
2050
2051         if (!vars->link_up)
2052                 return elink_status;
2053
2054         PMD_DRV_LOG(DEBUG, "About to update PFC in BMAC");
2055
2056         if (CHIP_IS_E3(sc)) {
2057                 if (vars->mac_type == ELINK_MAC_TYPE_XMAC)
2058                         elink_update_pfc_xmac(params, vars);
2059         } else {
2060                 val = REG_RD(sc, MISC_REG_RESET_REG_2);
2061                 if ((val &
2062                      (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << params->port))
2063                     == 0) {
2064                         PMD_DRV_LOG(DEBUG, "About to update PFC in EMAC");
2065                         elink_emac_enable(params, vars, 0);
2066                         return elink_status;
2067                 }
2068                 if (CHIP_IS_E2(sc))
2069                         elink_update_pfc_bmac2(params, vars, bmac_loopback);
2070                 else
2071                         elink_update_pfc_bmac1(params, vars);
2072
2073                 val = 0;
2074                 if ((params->feature_config_flags &
2075                      ELINK_FEATURE_CONFIG_PFC_ENABLED) ||
2076                     (vars->flow_ctrl & ELINK_FLOW_CTRL_TX))
2077                         val = 1;
2078                 REG_WR(sc, NIG_REG_BMAC0_PAUSE_OUT_EN + params->port * 4, val);
2079         }
2080         return elink_status;
2081 }
2082
2083 static elink_status_t elink_bmac1_enable(struct elink_params *params,
2084                                          struct elink_vars *vars, uint8_t is_lb)
2085 {
2086         struct bnx2x_softc *sc = params->sc;
2087         uint8_t port = params->port;
2088         uint32_t bmac_addr = port ? NIG_REG_INGRESS_BMAC1_MEM :
2089             NIG_REG_INGRESS_BMAC0_MEM;
2090         uint32_t wb_data[2];
2091         uint32_t val;
2092
2093         PMD_DRV_LOG(DEBUG, "Enabling BigMAC1");
2094
2095         /* XGXS control */
2096         wb_data[0] = 0x3c;
2097         wb_data[1] = 0;
2098         REG_WR_DMAE(sc, bmac_addr + BIGMAC_REGISTER_BMAC_XGXS_CONTROL,
2099                     wb_data, 2);
2100
2101         /* TX MAC SA */
2102         wb_data[0] = ((params->mac_addr[2] << 24) |
2103                       (params->mac_addr[3] << 16) |
2104                       (params->mac_addr[4] << 8) | params->mac_addr[5]);
2105         wb_data[1] = ((params->mac_addr[0] << 8) | params->mac_addr[1]);
2106         REG_WR_DMAE(sc, bmac_addr + BIGMAC_REGISTER_TX_SOURCE_ADDR, wb_data, 2);
2107
2108         /* MAC control */
2109         val = 0x3;
2110         if (is_lb) {
2111                 val |= 0x4;
2112                 PMD_DRV_LOG(DEBUG, "enable bmac loopback");
2113         }
2114         wb_data[0] = val;
2115         wb_data[1] = 0;
2116         REG_WR_DMAE(sc, bmac_addr + BIGMAC_REGISTER_BMAC_CONTROL, wb_data, 2);
2117
2118         /* Set rx mtu */
2119         wb_data[0] = ELINK_ETH_MAX_JUMBO_PACKET_SIZE + ELINK_ETH_OVREHEAD;
2120         wb_data[1] = 0;
2121         REG_WR_DMAE(sc, bmac_addr + BIGMAC_REGISTER_RX_MAX_SIZE, wb_data, 2);
2122
2123         elink_update_pfc_bmac1(params, vars);
2124
2125         /* Set tx mtu */
2126         wb_data[0] = ELINK_ETH_MAX_JUMBO_PACKET_SIZE + ELINK_ETH_OVREHEAD;
2127         wb_data[1] = 0;
2128         REG_WR_DMAE(sc, bmac_addr + BIGMAC_REGISTER_TX_MAX_SIZE, wb_data, 2);
2129
2130         /* Set cnt max size */
2131         wb_data[0] = ELINK_ETH_MAX_JUMBO_PACKET_SIZE + ELINK_ETH_OVREHEAD;
2132         wb_data[1] = 0;
2133         REG_WR_DMAE(sc, bmac_addr + BIGMAC_REGISTER_CNT_MAX_SIZE, wb_data, 2);
2134
2135         /* Configure SAFC */
2136         wb_data[0] = 0x1000200;
2137         wb_data[1] = 0;
2138         REG_WR_DMAE(sc, bmac_addr + BIGMAC_REGISTER_RX_LLFC_MSG_FLDS,
2139                     wb_data, 2);
2140 #ifdef ELINK_INCLUDE_EMUL
2141         /* Fix for emulation */
2142         if (CHIP_REV_IS_EMUL(sc)) {
2143                 wb_data[0] = 0xf000;
2144                 wb_data[1] = 0;
2145                 REG_WR_DMAE(sc, bmac_addr + BIGMAC_REGISTER_TX_PAUSE_THRESHOLD,
2146                             wb_data, 2);
2147         }
2148 #endif
2149
2150         return ELINK_STATUS_OK;
2151 }
2152
2153 static elink_status_t elink_bmac2_enable(struct elink_params *params,
2154                                          struct elink_vars *vars, uint8_t is_lb)
2155 {
2156         struct bnx2x_softc *sc = params->sc;
2157         uint8_t port = params->port;
2158         uint32_t bmac_addr = port ? NIG_REG_INGRESS_BMAC1_MEM :
2159             NIG_REG_INGRESS_BMAC0_MEM;
2160         uint32_t wb_data[2];
2161
2162         PMD_DRV_LOG(DEBUG, "Enabling BigMAC2");
2163
2164         wb_data[0] = 0;
2165         wb_data[1] = 0;
2166         REG_WR_DMAE(sc, bmac_addr + BIGMAC2_REGISTER_BMAC_CONTROL, wb_data, 2);
2167         DELAY(30);
2168
2169         /* XGXS control: Reset phy HW, MDIO registers, PHY PLL and BMAC */
2170         wb_data[0] = 0x3c;
2171         wb_data[1] = 0;
2172         REG_WR_DMAE(sc, bmac_addr + BIGMAC2_REGISTER_BMAC_XGXS_CONTROL,
2173                     wb_data, 2);
2174
2175         DELAY(30);
2176
2177         /* TX MAC SA */
2178         wb_data[0] = ((params->mac_addr[2] << 24) |
2179                       (params->mac_addr[3] << 16) |
2180                       (params->mac_addr[4] << 8) | params->mac_addr[5]);
2181         wb_data[1] = ((params->mac_addr[0] << 8) | params->mac_addr[1]);
2182         REG_WR_DMAE(sc, bmac_addr + BIGMAC2_REGISTER_TX_SOURCE_ADDR,
2183                     wb_data, 2);
2184
2185         DELAY(30);
2186
2187         /* Configure SAFC */
2188         wb_data[0] = 0x1000200;
2189         wb_data[1] = 0;
2190         REG_WR_DMAE(sc, bmac_addr + BIGMAC2_REGISTER_RX_LLFC_MSG_FLDS,
2191                     wb_data, 2);
2192         DELAY(30);
2193
2194         /* Set RX MTU */
2195         wb_data[0] = ELINK_ETH_MAX_JUMBO_PACKET_SIZE + ELINK_ETH_OVREHEAD;
2196         wb_data[1] = 0;
2197         REG_WR_DMAE(sc, bmac_addr + BIGMAC2_REGISTER_RX_MAX_SIZE, wb_data, 2);
2198         DELAY(30);
2199
2200         /* Set TX MTU */
2201         wb_data[0] = ELINK_ETH_MAX_JUMBO_PACKET_SIZE + ELINK_ETH_OVREHEAD;
2202         wb_data[1] = 0;
2203         REG_WR_DMAE(sc, bmac_addr + BIGMAC2_REGISTER_TX_MAX_SIZE, wb_data, 2);
2204         DELAY(30);
2205         /* Set cnt max size */
2206         wb_data[0] = ELINK_ETH_MAX_JUMBO_PACKET_SIZE + ELINK_ETH_OVREHEAD - 2;
2207         wb_data[1] = 0;
2208         REG_WR_DMAE(sc, bmac_addr + BIGMAC2_REGISTER_CNT_MAX_SIZE, wb_data, 2);
2209         DELAY(30);
2210         elink_update_pfc_bmac2(params, vars, is_lb);
2211
2212         return ELINK_STATUS_OK;
2213 }
2214
2215 static elink_status_t elink_bmac_enable(struct elink_params *params,
2216                                         struct elink_vars *vars,
2217                                         uint8_t is_lb, uint8_t reset_bmac)
2218 {
2219         elink_status_t rc = ELINK_STATUS_OK;
2220         uint8_t port = params->port;
2221         struct bnx2x_softc *sc = params->sc;
2222         uint32_t val;
2223         /* Reset and unreset the BigMac */
2224         if (reset_bmac) {
2225                 REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
2226                        (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port));
2227                 DELAY(1000 * 1);
2228         }
2229
2230         REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
2231                (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port));
2232
2233         /* Enable access for bmac registers */
2234         REG_WR(sc, NIG_REG_BMAC0_REGS_OUT_EN + port * 4, 0x1);
2235
2236         /* Enable BMAC according to BMAC type */
2237         if (CHIP_IS_E2(sc))
2238                 rc = elink_bmac2_enable(params, vars, is_lb);
2239         else
2240                 rc = elink_bmac1_enable(params, vars, is_lb);
2241         REG_WR(sc, NIG_REG_XGXS_SERDES0_MODE_SEL + port * 4, 0x1);
2242         REG_WR(sc, NIG_REG_XGXS_LANE_SEL_P0 + port * 4, 0x0);
2243         REG_WR(sc, NIG_REG_EGRESS_EMAC0_PORT + port * 4, 0x0);
2244         val = 0;
2245         if ((params->feature_config_flags &
2246              ELINK_FEATURE_CONFIG_PFC_ENABLED) ||
2247             (vars->flow_ctrl & ELINK_FLOW_CTRL_TX))
2248                 val = 1;
2249         REG_WR(sc, NIG_REG_BMAC0_PAUSE_OUT_EN + port * 4, val);
2250         REG_WR(sc, NIG_REG_EGRESS_EMAC0_OUT_EN + port * 4, 0x0);
2251         REG_WR(sc, NIG_REG_EMAC0_IN_EN + port * 4, 0x0);
2252         REG_WR(sc, NIG_REG_EMAC0_PAUSE_OUT_EN + port * 4, 0x0);
2253         REG_WR(sc, NIG_REG_BMAC0_IN_EN + port * 4, 0x1);
2254         REG_WR(sc, NIG_REG_BMAC0_OUT_EN + port * 4, 0x1);
2255
2256         vars->mac_type = ELINK_MAC_TYPE_BMAC;
2257         return rc;
2258 }
2259
2260 static void elink_set_bmac_rx(struct bnx2x_softc *sc, uint8_t port, uint8_t en)
2261 {
2262         uint32_t bmac_addr = port ? NIG_REG_INGRESS_BMAC1_MEM :
2263             NIG_REG_INGRESS_BMAC0_MEM;
2264         uint32_t wb_data[2];
2265         uint32_t nig_bmac_enable =
2266             REG_RD(sc, NIG_REG_BMAC0_REGS_OUT_EN + port * 4);
2267
2268         if (CHIP_IS_E2(sc))
2269                 bmac_addr += BIGMAC2_REGISTER_BMAC_CONTROL;
2270         else
2271                 bmac_addr += BIGMAC_REGISTER_BMAC_CONTROL;
2272         /* Only if the bmac is out of reset */
2273         if (REG_RD(sc, MISC_REG_RESET_REG_2) &
2274             (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port) && nig_bmac_enable) {
2275                 /* Clear Rx Enable bit in BMAC_CONTROL register */
2276                 REG_RD_DMAE(sc, bmac_addr, wb_data, 2);
2277                 if (en)
2278                         wb_data[0] |= ELINK_BMAC_CONTROL_RX_ENABLE;
2279                 else
2280                         wb_data[0] &= ~ELINK_BMAC_CONTROL_RX_ENABLE;
2281                 REG_WR_DMAE(sc, bmac_addr, wb_data, 2);
2282                 DELAY(1000 * 1);
2283         }
2284 }
2285
2286 static elink_status_t elink_pbf_update(struct elink_params *params,
2287                                        uint32_t flow_ctrl, uint32_t line_speed)
2288 {
2289         struct bnx2x_softc *sc = params->sc;
2290         uint8_t port = params->port;
2291         uint32_t init_crd, crd;
2292         uint32_t count = 1000;
2293
2294         /* Disable port */
2295         REG_WR(sc, PBF_REG_DISABLE_NEW_TASK_PROC_P0 + port * 4, 0x1);
2296
2297         /* Wait for init credit */
2298         init_crd = REG_RD(sc, PBF_REG_P0_INIT_CRD + port * 4);
2299         crd = REG_RD(sc, PBF_REG_P0_CREDIT + port * 8);
2300         PMD_DRV_LOG(DEBUG, "init_crd 0x%x  crd 0x%x", init_crd, crd);
2301
2302         while ((init_crd != crd) && count) {
2303                 DELAY(1000 * 5);
2304                 crd = REG_RD(sc, PBF_REG_P0_CREDIT + port * 8);
2305                 count--;
2306         }
2307         crd = REG_RD(sc, PBF_REG_P0_CREDIT + port * 8);
2308         if (init_crd != crd) {
2309                 PMD_DRV_LOG(DEBUG, "BUG! init_crd 0x%x != crd 0x%x",
2310                             init_crd, crd);
2311                 return ELINK_STATUS_ERROR;
2312         }
2313
2314         if (flow_ctrl & ELINK_FLOW_CTRL_RX ||
2315             line_speed == ELINK_SPEED_10 ||
2316             line_speed == ELINK_SPEED_100 ||
2317             line_speed == ELINK_SPEED_1000 || line_speed == ELINK_SPEED_2500) {
2318                 REG_WR(sc, PBF_REG_P0_PAUSE_ENABLE + port * 4, 1);
2319                 /* Update threshold */
2320                 REG_WR(sc, PBF_REG_P0_ARB_THRSH + port * 4, 0);
2321                 /* Update init credit */
2322                 init_crd = 778; /* (800-18-4) */
2323
2324         } else {
2325                 uint32_t thresh = (ELINK_ETH_MAX_JUMBO_PACKET_SIZE +
2326                                    ELINK_ETH_OVREHEAD) / 16;
2327                 REG_WR(sc, PBF_REG_P0_PAUSE_ENABLE + port * 4, 0);
2328                 /* Update threshold */
2329                 REG_WR(sc, PBF_REG_P0_ARB_THRSH + port * 4, thresh);
2330                 /* Update init credit */
2331                 switch (line_speed) {
2332                 case ELINK_SPEED_10000:
2333                         init_crd = thresh + 553 - 22;
2334                         break;
2335                 default:
2336                         PMD_DRV_LOG(DEBUG, "Invalid line_speed 0x%x",
2337                                     line_speed);
2338                         return ELINK_STATUS_ERROR;
2339                 }
2340         }
2341         REG_WR(sc, PBF_REG_P0_INIT_CRD + port * 4, init_crd);
2342         PMD_DRV_LOG(DEBUG, "PBF updated to speed %d credit %d",
2343                     line_speed, init_crd);
2344
2345         /* Probe the credit changes */
2346         REG_WR(sc, PBF_REG_INIT_P0 + port * 4, 0x1);
2347         DELAY(1000 * 5);
2348         REG_WR(sc, PBF_REG_INIT_P0 + port * 4, 0x0);
2349
2350         /* Enable port */
2351         REG_WR(sc, PBF_REG_DISABLE_NEW_TASK_PROC_P0 + port * 4, 0x0);
2352         return ELINK_STATUS_OK;
2353 }
2354
2355 /**
2356  * elink_get_emac_base - retrive emac base address
2357  *
2358  * @bp:                 driver handle
2359  * @mdc_mdio_access:    access type
2360  * @port:               port id
2361  *
2362  * This function selects the MDC/MDIO access (through emac0 or
2363  * emac1) depend on the mdc_mdio_access, port, port swapped. Each
2364  * phy has a default access mode, which could also be overridden
2365  * by nvram configuration. This parameter, whether this is the
2366  * default phy configuration, or the nvram overrun
2367  * configuration, is passed here as mdc_mdio_access and selects
2368  * the emac_base for the CL45 read/writes operations
2369  */
2370 static uint32_t elink_get_emac_base(struct bnx2x_softc *sc,
2371                                     uint32_t mdc_mdio_access, uint8_t port)
2372 {
2373         uint32_t emac_base = 0;
2374         switch (mdc_mdio_access) {
2375         case SHARED_HW_CFG_MDC_MDIO_ACCESS1_PHY_TYPE:
2376                 break;
2377         case SHARED_HW_CFG_MDC_MDIO_ACCESS1_EMAC0:
2378                 if (REG_RD(sc, NIG_REG_PORT_SWAP))
2379                         emac_base = GRCBASE_EMAC1;
2380                 else
2381                         emac_base = GRCBASE_EMAC0;
2382                 break;
2383         case SHARED_HW_CFG_MDC_MDIO_ACCESS1_EMAC1:
2384                 if (REG_RD(sc, NIG_REG_PORT_SWAP))
2385                         emac_base = GRCBASE_EMAC0;
2386                 else
2387                         emac_base = GRCBASE_EMAC1;
2388                 break;
2389         case SHARED_HW_CFG_MDC_MDIO_ACCESS1_BOTH:
2390                 emac_base = (port) ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
2391                 break;
2392         case SHARED_HW_CFG_MDC_MDIO_ACCESS1_SWAPPED:
2393                 emac_base = (port) ? GRCBASE_EMAC0 : GRCBASE_EMAC1;
2394                 break;
2395         default:
2396                 break;
2397         }
2398         return emac_base;
2399
2400 }
2401
2402 /******************************************************************/
2403 /*                      CL22 access functions                     */
2404 /******************************************************************/
2405 static elink_status_t elink_cl22_write(struct bnx2x_softc *sc,
2406                                        struct elink_phy *phy,
2407                                        uint16_t reg, uint16_t val)
2408 {
2409         uint32_t tmp, mode;
2410         uint8_t i;
2411         elink_status_t rc = ELINK_STATUS_OK;
2412         /* Switch to CL22 */
2413         mode = REG_RD(sc, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE);
2414         REG_WR(sc, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE,
2415                mode & ~EMAC_MDIO_MODE_CLAUSE_45);
2416
2417         /* Address */
2418         tmp = ((phy->addr << 21) | (reg << 16) | val |
2419                EMAC_MDIO_COMM_COMMAND_WRITE_22 | EMAC_MDIO_COMM_START_BUSY);
2420         REG_WR(sc, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, tmp);
2421
2422         for (i = 0; i < 50; i++) {
2423                 DELAY(10);
2424
2425                 tmp = REG_RD(sc, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM);
2426                 if (!(tmp & EMAC_MDIO_COMM_START_BUSY)) {
2427                         DELAY(5);
2428                         break;
2429                 }
2430         }
2431         if (tmp & EMAC_MDIO_COMM_START_BUSY) {
2432                 PMD_DRV_LOG(DEBUG, "write phy register failed");
2433                 rc = ELINK_STATUS_TIMEOUT;
2434         }
2435         REG_WR(sc, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE, mode);
2436         return rc;
2437 }
2438
2439 static elink_status_t elink_cl22_read(struct bnx2x_softc *sc,
2440                                       struct elink_phy *phy,
2441                                       uint16_t reg, uint16_t * ret_val)
2442 {
2443         uint32_t val, mode;
2444         uint16_t i;
2445         elink_status_t rc = ELINK_STATUS_OK;
2446
2447         /* Switch to CL22 */
2448         mode = REG_RD(sc, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE);
2449         REG_WR(sc, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE,
2450                mode & ~EMAC_MDIO_MODE_CLAUSE_45);
2451
2452         /* Address */
2453         val = ((phy->addr << 21) | (reg << 16) |
2454                EMAC_MDIO_COMM_COMMAND_READ_22 | EMAC_MDIO_COMM_START_BUSY);
2455         REG_WR(sc, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, val);
2456
2457         for (i = 0; i < 50; i++) {
2458                 DELAY(10);
2459
2460                 val = REG_RD(sc, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM);
2461                 if (!(val & EMAC_MDIO_COMM_START_BUSY)) {
2462                         *ret_val = (uint16_t) (val & EMAC_MDIO_COMM_DATA);
2463                         DELAY(5);
2464                         break;
2465                 }
2466         }
2467         if (val & EMAC_MDIO_COMM_START_BUSY) {
2468                 PMD_DRV_LOG(DEBUG, "read phy register failed");
2469
2470                 *ret_val = 0;
2471                 rc = ELINK_STATUS_TIMEOUT;
2472         }
2473         REG_WR(sc, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE, mode);
2474         return rc;
2475 }
2476
2477 /******************************************************************/
2478 /*                      CL45 access functions                     */
2479 /******************************************************************/
2480 static elink_status_t elink_cl45_read(struct bnx2x_softc *sc,
2481                                       struct elink_phy *phy, uint8_t devad,
2482                                       uint16_t reg, uint16_t * ret_val)
2483 {
2484         uint32_t val;
2485         uint16_t i;
2486         elink_status_t rc = ELINK_STATUS_OK;
2487         if (phy->flags & ELINK_FLAGS_MDC_MDIO_WA_G) {
2488                 elink_set_mdio_clk(sc, phy->mdio_ctrl);
2489         }
2490
2491         if (phy->flags & ELINK_FLAGS_MDC_MDIO_WA_B0)
2492                 elink_bits_en(sc, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_STATUS,
2493                               EMAC_MDIO_STATUS_10MB);
2494         /* Address */
2495         val = ((phy->addr << 21) | (devad << 16) | reg |
2496                EMAC_MDIO_COMM_COMMAND_ADDRESS | EMAC_MDIO_COMM_START_BUSY);
2497         REG_WR(sc, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, val);
2498
2499         for (i = 0; i < 50; i++) {
2500                 DELAY(10);
2501
2502                 val = REG_RD(sc, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM);
2503                 if (!(val & EMAC_MDIO_COMM_START_BUSY)) {
2504                         DELAY(5);
2505                         break;
2506                 }
2507         }
2508         if (val & EMAC_MDIO_COMM_START_BUSY) {
2509                 PMD_DRV_LOG(DEBUG, "read phy register failed");
2510                 elink_cb_event_log(sc, ELINK_LOG_ID_MDIO_ACCESS_TIMEOUT);       // "MDC/MDIO access timeout"
2511
2512                 *ret_val = 0;
2513                 rc = ELINK_STATUS_TIMEOUT;
2514         } else {
2515                 /* Data */
2516                 val = ((phy->addr << 21) | (devad << 16) |
2517                        EMAC_MDIO_COMM_COMMAND_READ_45 |
2518                        EMAC_MDIO_COMM_START_BUSY);
2519                 REG_WR(sc, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, val);
2520
2521                 for (i = 0; i < 50; i++) {
2522                         DELAY(10);
2523
2524                         val = REG_RD(sc, phy->mdio_ctrl +
2525                                      EMAC_REG_EMAC_MDIO_COMM);
2526                         if (!(val & EMAC_MDIO_COMM_START_BUSY)) {
2527                                 *ret_val =
2528                                     (uint16_t) (val & EMAC_MDIO_COMM_DATA);
2529                                 break;
2530                         }
2531                 }
2532                 if (val & EMAC_MDIO_COMM_START_BUSY) {
2533                         PMD_DRV_LOG(DEBUG, "read phy register failed");
2534                         elink_cb_event_log(sc, ELINK_LOG_ID_MDIO_ACCESS_TIMEOUT);       // "MDC/MDIO access timeout"
2535
2536                         *ret_val = 0;
2537                         rc = ELINK_STATUS_TIMEOUT;
2538                 }
2539         }
2540         /* Work around for E3 A0 */
2541         if (phy->flags & ELINK_FLAGS_MDC_MDIO_WA) {
2542                 phy->flags ^= ELINK_FLAGS_DUMMY_READ;
2543                 if (phy->flags & ELINK_FLAGS_DUMMY_READ) {
2544                         uint16_t temp_val;
2545                         elink_cl45_read(sc, phy, devad, 0xf, &temp_val);
2546                 }
2547         }
2548
2549         if (phy->flags & ELINK_FLAGS_MDC_MDIO_WA_B0)
2550                 elink_bits_dis(sc, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_STATUS,
2551                                EMAC_MDIO_STATUS_10MB);
2552         return rc;
2553 }
2554
2555 static elink_status_t elink_cl45_write(struct bnx2x_softc *sc,
2556                                        struct elink_phy *phy, uint8_t devad,
2557                                        uint16_t reg, uint16_t val)
2558 {
2559         uint32_t tmp;
2560         uint8_t i;
2561         elink_status_t rc = ELINK_STATUS_OK;
2562         if (phy->flags & ELINK_FLAGS_MDC_MDIO_WA_G) {
2563                 elink_set_mdio_clk(sc, phy->mdio_ctrl);
2564         }
2565
2566         if (phy->flags & ELINK_FLAGS_MDC_MDIO_WA_B0)
2567                 elink_bits_en(sc, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_STATUS,
2568                               EMAC_MDIO_STATUS_10MB);
2569
2570         /* Address */
2571         tmp = ((phy->addr << 21) | (devad << 16) | reg |
2572                EMAC_MDIO_COMM_COMMAND_ADDRESS | EMAC_MDIO_COMM_START_BUSY);
2573         REG_WR(sc, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, tmp);
2574
2575         for (i = 0; i < 50; i++) {
2576                 DELAY(10);
2577
2578                 tmp = REG_RD(sc, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM);
2579                 if (!(tmp & EMAC_MDIO_COMM_START_BUSY)) {
2580                         DELAY(5);
2581                         break;
2582                 }
2583         }
2584         if (tmp & EMAC_MDIO_COMM_START_BUSY) {
2585                 PMD_DRV_LOG(DEBUG, "write phy register failed");
2586                 elink_cb_event_log(sc, ELINK_LOG_ID_MDIO_ACCESS_TIMEOUT);       // "MDC/MDIO access timeout"
2587
2588                 rc = ELINK_STATUS_TIMEOUT;
2589         } else {
2590                 /* Data */
2591                 tmp = ((phy->addr << 21) | (devad << 16) | val |
2592                        EMAC_MDIO_COMM_COMMAND_WRITE_45 |
2593                        EMAC_MDIO_COMM_START_BUSY);
2594                 REG_WR(sc, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, tmp);
2595
2596                 for (i = 0; i < 50; i++) {
2597                         DELAY(10);
2598
2599                         tmp = REG_RD(sc, phy->mdio_ctrl +
2600                                      EMAC_REG_EMAC_MDIO_COMM);
2601                         if (!(tmp & EMAC_MDIO_COMM_START_BUSY)) {
2602                                 DELAY(5);
2603                                 break;
2604                         }
2605                 }
2606                 if (tmp & EMAC_MDIO_COMM_START_BUSY) {
2607                         PMD_DRV_LOG(DEBUG, "write phy register failed");
2608                         elink_cb_event_log(sc, ELINK_LOG_ID_MDIO_ACCESS_TIMEOUT);       // "MDC/MDIO access timeout"
2609
2610                         rc = ELINK_STATUS_TIMEOUT;
2611                 }
2612         }
2613         /* Work around for E3 A0 */
2614         if (phy->flags & ELINK_FLAGS_MDC_MDIO_WA) {
2615                 phy->flags ^= ELINK_FLAGS_DUMMY_READ;
2616                 if (phy->flags & ELINK_FLAGS_DUMMY_READ) {
2617                         uint16_t temp_val;
2618                         elink_cl45_read(sc, phy, devad, 0xf, &temp_val);
2619                 }
2620         }
2621         if (phy->flags & ELINK_FLAGS_MDC_MDIO_WA_B0)
2622                 elink_bits_dis(sc, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_STATUS,
2623                                EMAC_MDIO_STATUS_10MB);
2624         return rc;
2625 }
2626
2627 /******************************************************************/
2628 /*                      EEE section                                */
2629 /******************************************************************/
2630 static uint8_t elink_eee_has_cap(struct elink_params *params)
2631 {
2632         struct bnx2x_softc *sc = params->sc;
2633
2634         if (REG_RD(sc, params->shmem2_base) <=
2635             offsetof(struct shmem2_region, eee_status[params->port]))
2636                  return 0;
2637
2638         return 1;
2639 }
2640
2641 static elink_status_t elink_eee_nvram_to_time(uint32_t nvram_mode,
2642                                               uint32_t * idle_timer)
2643 {
2644         switch (nvram_mode) {
2645         case PORT_FEAT_CFG_EEE_POWER_MODE_BALANCED:
2646                 *idle_timer = ELINK_EEE_MODE_NVRAM_BALANCED_TIME;
2647                 break;
2648         case PORT_FEAT_CFG_EEE_POWER_MODE_AGGRESSIVE:
2649                 *idle_timer = ELINK_EEE_MODE_NVRAM_AGGRESSIVE_TIME;
2650                 break;
2651         case PORT_FEAT_CFG_EEE_POWER_MODE_LOW_LATENCY:
2652                 *idle_timer = ELINK_EEE_MODE_NVRAM_LATENCY_TIME;
2653                 break;
2654         default:
2655                 *idle_timer = 0;
2656                 break;
2657         }
2658
2659         return ELINK_STATUS_OK;
2660 }
2661
2662 static elink_status_t elink_eee_time_to_nvram(uint32_t idle_timer,
2663                                               uint32_t * nvram_mode)
2664 {
2665         switch (idle_timer) {
2666         case ELINK_EEE_MODE_NVRAM_BALANCED_TIME:
2667                 *nvram_mode = PORT_FEAT_CFG_EEE_POWER_MODE_BALANCED;
2668                 break;
2669         case ELINK_EEE_MODE_NVRAM_AGGRESSIVE_TIME:
2670                 *nvram_mode = PORT_FEAT_CFG_EEE_POWER_MODE_AGGRESSIVE;
2671                 break;
2672         case ELINK_EEE_MODE_NVRAM_LATENCY_TIME:
2673                 *nvram_mode = PORT_FEAT_CFG_EEE_POWER_MODE_LOW_LATENCY;
2674                 break;
2675         default:
2676                 *nvram_mode = PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED;
2677                 break;
2678         }
2679
2680         return ELINK_STATUS_OK;
2681 }
2682
2683 static uint32_t elink_eee_calc_timer(struct elink_params *params)
2684 {
2685         uint32_t eee_mode, eee_idle;
2686         struct bnx2x_softc *sc = params->sc;
2687
2688         if (params->eee_mode & ELINK_EEE_MODE_OVERRIDE_NVRAM) {
2689                 if (params->eee_mode & ELINK_EEE_MODE_OUTPUT_TIME) {
2690                         /* time value in eee_mode --> used directly */
2691                         eee_idle = params->eee_mode & ELINK_EEE_MODE_TIMER_MASK;
2692                 } else {
2693                         /* hsi value in eee_mode --> time */
2694                         if (elink_eee_nvram_to_time(params->eee_mode &
2695                                                     ELINK_EEE_MODE_NVRAM_MASK,
2696                                                     &eee_idle))
2697                                 return 0;
2698                 }
2699         } else {
2700                 /* hsi values in nvram --> time */
2701                 eee_mode = ((REG_RD(sc, params->shmem_base +
2702                                     offsetof(struct shmem_region,
2703                                              dev_info.port_feature_config
2704                                              [params->
2705                                               port].eee_power_mode)) &
2706                              PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >>
2707                             PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT);
2708
2709                 if (elink_eee_nvram_to_time(eee_mode, &eee_idle))
2710                         return 0;
2711         }
2712
2713         return eee_idle;
2714 }
2715
2716 static elink_status_t elink_eee_set_timers(struct elink_params *params,
2717                                            struct elink_vars *vars)
2718 {
2719         uint32_t eee_idle = 0, eee_mode;
2720         struct bnx2x_softc *sc = params->sc;
2721
2722         eee_idle = elink_eee_calc_timer(params);
2723
2724         if (eee_idle) {
2725                 REG_WR(sc, MISC_REG_CPMU_LP_IDLE_THR_P0 + (params->port << 2),
2726                        eee_idle);
2727         } else if ((params->eee_mode & ELINK_EEE_MODE_ENABLE_LPI) &&
2728                    (params->eee_mode & ELINK_EEE_MODE_OVERRIDE_NVRAM) &&
2729                    (params->eee_mode & ELINK_EEE_MODE_OUTPUT_TIME)) {
2730                 PMD_DRV_LOG(DEBUG, "Error: Tx LPI is enabled with timer 0");
2731                 return ELINK_STATUS_ERROR;
2732         }
2733
2734         vars->eee_status &= ~(SHMEM_EEE_TIMER_MASK | SHMEM_EEE_TIME_OUTPUT_BIT);
2735         if (params->eee_mode & ELINK_EEE_MODE_OUTPUT_TIME) {
2736                 /* eee_idle in 1u --> eee_status in 16u */
2737                 eee_idle >>= 4;
2738                 vars->eee_status |= (eee_idle & SHMEM_EEE_TIMER_MASK) |
2739                     SHMEM_EEE_TIME_OUTPUT_BIT;
2740         } else {
2741                 if (elink_eee_time_to_nvram(eee_idle, &eee_mode))
2742                         return ELINK_STATUS_ERROR;
2743                 vars->eee_status |= eee_mode;
2744         }
2745
2746         return ELINK_STATUS_OK;
2747 }
2748
2749 static elink_status_t elink_eee_initial_config(struct elink_params *params,
2750                                                struct elink_vars *vars,
2751                                                uint8_t mode)
2752 {
2753         vars->eee_status |= ((uint32_t) mode) << SHMEM_EEE_SUPPORTED_SHIFT;
2754
2755         /* Propogate params' bits --> vars (for migration exposure) */
2756         if (params->eee_mode & ELINK_EEE_MODE_ENABLE_LPI)
2757                 vars->eee_status |= SHMEM_EEE_LPI_REQUESTED_BIT;
2758         else
2759                 vars->eee_status &= ~SHMEM_EEE_LPI_REQUESTED_BIT;
2760
2761         if (params->eee_mode & ELINK_EEE_MODE_ADV_LPI)
2762                 vars->eee_status |= SHMEM_EEE_REQUESTED_BIT;
2763         else
2764                 vars->eee_status &= ~SHMEM_EEE_REQUESTED_BIT;
2765
2766         return elink_eee_set_timers(params, vars);
2767 }
2768
2769 static elink_status_t elink_eee_disable(struct elink_phy *phy,
2770                                         struct elink_params *params,
2771                                         struct elink_vars *vars)
2772 {
2773         struct bnx2x_softc *sc = params->sc;
2774
2775         /* Make Certain LPI is disabled */
2776         REG_WR(sc, MISC_REG_CPMU_LP_FW_ENABLE_P0 + (params->port << 2), 0);
2777
2778         elink_cl45_write(sc, phy, MDIO_AN_DEVAD, MDIO_AN_REG_EEE_ADV, 0x0);
2779
2780         vars->eee_status &= ~SHMEM_EEE_ADV_STATUS_MASK;
2781
2782         return ELINK_STATUS_OK;
2783 }
2784
2785 static elink_status_t elink_eee_advertise(struct elink_phy *phy,
2786                                           struct elink_params *params,
2787                                           struct elink_vars *vars,
2788                                           uint8_t modes)
2789 {
2790         struct bnx2x_softc *sc = params->sc;
2791         uint16_t val = 0;
2792
2793         /* Mask events preventing LPI generation */
2794         REG_WR(sc, MISC_REG_CPMU_LP_MASK_EXT_P0 + (params->port << 2), 0xfc20);
2795
2796         if (modes & SHMEM_EEE_10G_ADV) {
2797                 PMD_DRV_LOG(DEBUG, "Advertise 10GBase-T EEE");
2798                 val |= 0x8;
2799         }
2800         if (modes & SHMEM_EEE_1G_ADV) {
2801                 PMD_DRV_LOG(DEBUG, "Advertise 1GBase-T EEE");
2802                 val |= 0x4;
2803         }
2804
2805         elink_cl45_write(sc, phy, MDIO_AN_DEVAD, MDIO_AN_REG_EEE_ADV, val);
2806
2807         vars->eee_status &= ~SHMEM_EEE_ADV_STATUS_MASK;
2808         vars->eee_status |= (modes << SHMEM_EEE_ADV_STATUS_SHIFT);
2809
2810         return ELINK_STATUS_OK;
2811 }
2812
2813 static void elink_update_mng_eee(struct elink_params *params,
2814                                  uint32_t eee_status)
2815 {
2816         struct bnx2x_softc *sc = params->sc;
2817
2818         if (elink_eee_has_cap(params))
2819                 REG_WR(sc, params->shmem2_base +
2820                        offsetof(struct shmem2_region,
2821                                 eee_status[params->port]), eee_status);
2822 }
2823
2824 static void elink_eee_an_resolve(struct elink_phy *phy,
2825                                  struct elink_params *params,
2826                                  struct elink_vars *vars)
2827 {
2828         struct bnx2x_softc *sc = params->sc;
2829         uint16_t adv = 0, lp = 0;
2830         uint32_t lp_adv = 0;
2831         uint8_t neg = 0;
2832
2833         elink_cl45_read(sc, phy, MDIO_AN_DEVAD, MDIO_AN_REG_EEE_ADV, &adv);
2834         elink_cl45_read(sc, phy, MDIO_AN_DEVAD, MDIO_AN_REG_LP_EEE_ADV, &lp);
2835
2836         if (lp & 0x2) {
2837                 lp_adv |= SHMEM_EEE_100M_ADV;
2838                 if (adv & 0x2) {
2839                         if (vars->line_speed == ELINK_SPEED_100)
2840                                 neg = 1;
2841                         PMD_DRV_LOG(DEBUG, "EEE negotiated - 100M");
2842                 }
2843         }
2844         if (lp & 0x14) {
2845                 lp_adv |= SHMEM_EEE_1G_ADV;
2846                 if (adv & 0x14) {
2847                         if (vars->line_speed == ELINK_SPEED_1000)
2848                                 neg = 1;
2849                         PMD_DRV_LOG(DEBUG, "EEE negotiated - 1G");
2850                 }
2851         }
2852         if (lp & 0x68) {
2853                 lp_adv |= SHMEM_EEE_10G_ADV;
2854                 if (adv & 0x68) {
2855                         if (vars->line_speed == ELINK_SPEED_10000)
2856                                 neg = 1;
2857                         PMD_DRV_LOG(DEBUG, "EEE negotiated - 10G");
2858                 }
2859         }
2860
2861         vars->eee_status &= ~SHMEM_EEE_LP_ADV_STATUS_MASK;
2862         vars->eee_status |= (lp_adv << SHMEM_EEE_LP_ADV_STATUS_SHIFT);
2863
2864         if (neg) {
2865                 PMD_DRV_LOG(DEBUG, "EEE is active");
2866                 vars->eee_status |= SHMEM_EEE_ACTIVE_BIT;
2867         }
2868 }
2869
2870 /******************************************************************/
2871 /*                      BSC access functions from E3              */
2872 /******************************************************************/
2873 static void elink_bsc_module_sel(struct elink_params *params)
2874 {
2875         int idx;
2876         uint32_t board_cfg, sfp_ctrl;
2877         uint32_t i2c_pins[I2C_SWITCH_WIDTH], i2c_val[I2C_SWITCH_WIDTH];
2878         struct bnx2x_softc *sc = params->sc;
2879         uint8_t port = params->port;
2880         /* Read I2C output PINs */
2881         board_cfg = REG_RD(sc, params->shmem_base +
2882                            offsetof(struct shmem_region,
2883                                     dev_info.shared_hw_config.board));
2884         i2c_pins[I2C_BSC0] = board_cfg & SHARED_HW_CFG_E3_I2C_MUX0_MASK;
2885         i2c_pins[I2C_BSC1] = (board_cfg & SHARED_HW_CFG_E3_I2C_MUX1_MASK) >>
2886             SHARED_HW_CFG_E3_I2C_MUX1_SHIFT;
2887
2888         /* Read I2C output value */
2889         sfp_ctrl = REG_RD(sc, params->shmem_base +
2890                           offsetof(struct shmem_region,
2891                                    dev_info.port_hw_config[port].
2892                                    e3_cmn_pin_cfg));
2893         i2c_val[I2C_BSC0] = (sfp_ctrl & PORT_HW_CFG_E3_I2C_MUX0_MASK) > 0;
2894         i2c_val[I2C_BSC1] = (sfp_ctrl & PORT_HW_CFG_E3_I2C_MUX1_MASK) > 0;
2895         PMD_DRV_LOG(DEBUG, "Setting BSC switch");
2896         for (idx = 0; idx < I2C_SWITCH_WIDTH; idx++)
2897                 elink_set_cfg_pin(sc, i2c_pins[idx], i2c_val[idx]);
2898 }
2899
2900 static elink_status_t elink_bsc_read(struct elink_params *params,
2901                                      struct bnx2x_softc *sc,
2902                                      uint8_t sl_devid,
2903                                      uint16_t sl_addr,
2904                                      uint8_t lc_addr,
2905                                      uint8_t xfer_cnt, uint32_t * data_array)
2906 {
2907         uint32_t val, i;
2908         elink_status_t rc = ELINK_STATUS_OK;
2909
2910         if (xfer_cnt > 16) {
2911                 PMD_DRV_LOG(DEBUG, "invalid xfer_cnt %d. Max is 16 bytes",
2912                             xfer_cnt);
2913                 return ELINK_STATUS_ERROR;
2914         }
2915         if (params)
2916                 elink_bsc_module_sel(params);
2917
2918         xfer_cnt = 16 - lc_addr;
2919
2920         /* Enable the engine */
2921         val = REG_RD(sc, MCP_REG_MCPR_IMC_COMMAND);
2922         val |= MCPR_IMC_COMMAND_ENABLE;
2923         REG_WR(sc, MCP_REG_MCPR_IMC_COMMAND, val);
2924
2925         /* Program slave device ID */
2926         val = (sl_devid << 16) | sl_addr;
2927         REG_WR(sc, MCP_REG_MCPR_IMC_SLAVE_CONTROL, val);
2928
2929         /* Start xfer with 0 byte to update the address pointer ??? */
2930         val = (MCPR_IMC_COMMAND_ENABLE) |
2931             (MCPR_IMC_COMMAND_WRITE_OP <<
2932              MCPR_IMC_COMMAND_OPERATION_BITSHIFT) |
2933             (lc_addr << MCPR_IMC_COMMAND_TRANSFER_ADDRESS_BITSHIFT) | (0);
2934         REG_WR(sc, MCP_REG_MCPR_IMC_COMMAND, val);
2935
2936         /* Poll for completion */
2937         i = 0;
2938         val = REG_RD(sc, MCP_REG_MCPR_IMC_COMMAND);
2939         while (((val >> MCPR_IMC_COMMAND_IMC_STATUS_BITSHIFT) & 0x3) != 1) {
2940                 DELAY(10);
2941                 val = REG_RD(sc, MCP_REG_MCPR_IMC_COMMAND);
2942                 if (i++ > 1000) {
2943                         PMD_DRV_LOG(DEBUG, "wr 0 byte timed out after %d try",
2944                                     i);
2945                         rc = ELINK_STATUS_TIMEOUT;
2946                         break;
2947                 }
2948         }
2949         if (rc == ELINK_STATUS_TIMEOUT)
2950                 return rc;
2951
2952         /* Start xfer with read op */
2953         val = (MCPR_IMC_COMMAND_ENABLE) |
2954             (MCPR_IMC_COMMAND_READ_OP <<
2955              MCPR_IMC_COMMAND_OPERATION_BITSHIFT) |
2956             (lc_addr << MCPR_IMC_COMMAND_TRANSFER_ADDRESS_BITSHIFT) |
2957             (xfer_cnt);
2958         REG_WR(sc, MCP_REG_MCPR_IMC_COMMAND, val);
2959
2960         /* Poll for completion */
2961         i = 0;
2962         val = REG_RD(sc, MCP_REG_MCPR_IMC_COMMAND);
2963         while (((val >> MCPR_IMC_COMMAND_IMC_STATUS_BITSHIFT) & 0x3) != 1) {
2964                 DELAY(10);
2965                 val = REG_RD(sc, MCP_REG_MCPR_IMC_COMMAND);
2966                 if (i++ > 1000) {
2967                         PMD_DRV_LOG(DEBUG, "rd op timed out after %d try", i);
2968                         rc = ELINK_STATUS_TIMEOUT;
2969                         break;
2970                 }
2971         }
2972         if (rc == ELINK_STATUS_TIMEOUT)
2973                 return rc;
2974
2975         for (i = (lc_addr >> 2); i < 4; i++) {
2976                 data_array[i] = REG_RD(sc, (MCP_REG_MCPR_IMC_DATAREG0 + i * 4));
2977 #ifdef __BIG_ENDIAN
2978                 data_array[i] = ((data_array[i] & 0x000000ff) << 24) |
2979                     ((data_array[i] & 0x0000ff00) << 8) |
2980                     ((data_array[i] & 0x00ff0000) >> 8) |
2981                     ((data_array[i] & 0xff000000) >> 24);
2982 #endif
2983         }
2984         return rc;
2985 }
2986
2987 static void elink_cl45_read_or_write(struct bnx2x_softc *sc,
2988                                      struct elink_phy *phy, uint8_t devad,
2989                                      uint16_t reg, uint16_t or_val)
2990 {
2991         uint16_t val;
2992         elink_cl45_read(sc, phy, devad, reg, &val);
2993         elink_cl45_write(sc, phy, devad, reg, val | or_val);
2994 }
2995
2996 static void elink_cl45_read_and_write(struct bnx2x_softc *sc,
2997                                       struct elink_phy *phy,
2998                                       uint8_t devad, uint16_t reg,
2999                                       uint16_t and_val)
3000 {
3001         uint16_t val;
3002         elink_cl45_read(sc, phy, devad, reg, &val);
3003         elink_cl45_write(sc, phy, devad, reg, val & and_val);
3004 }
3005
3006 static uint8_t elink_get_warpcore_lane(struct elink_params *params)
3007 {
3008         uint8_t lane = 0;
3009         struct bnx2x_softc *sc = params->sc;
3010         uint32_t path_swap, path_swap_ovr;
3011         uint8_t path, port;
3012
3013         path = SC_PATH(sc);
3014         port = params->port;
3015
3016         if (elink_is_4_port_mode(sc)) {
3017                 uint32_t port_swap, port_swap_ovr;
3018
3019                 /* Figure out path swap value */
3020                 path_swap_ovr = REG_RD(sc, MISC_REG_FOUR_PORT_PATH_SWAP_OVWR);
3021                 if (path_swap_ovr & 0x1)
3022                         path_swap = (path_swap_ovr & 0x2);
3023                 else
3024                         path_swap = REG_RD(sc, MISC_REG_FOUR_PORT_PATH_SWAP);
3025
3026                 if (path_swap)
3027                         path = path ^ 1;
3028
3029                 /* Figure out port swap value */
3030                 port_swap_ovr = REG_RD(sc, MISC_REG_FOUR_PORT_PORT_SWAP_OVWR);
3031                 if (port_swap_ovr & 0x1)
3032                         port_swap = (port_swap_ovr & 0x2);
3033                 else
3034                         port_swap = REG_RD(sc, MISC_REG_FOUR_PORT_PORT_SWAP);
3035
3036                 if (port_swap)
3037                         port = port ^ 1;
3038
3039                 lane = (port << 1) + path;
3040         } else {                /* Two port mode - no port swap */
3041
3042                 /* Figure out path swap value */
3043                 path_swap_ovr = REG_RD(sc, MISC_REG_TWO_PORT_PATH_SWAP_OVWR);
3044                 if (path_swap_ovr & 0x1) {
3045                         path_swap = (path_swap_ovr & 0x2);
3046                 } else {
3047                         path_swap = REG_RD(sc, MISC_REG_TWO_PORT_PATH_SWAP);
3048                 }
3049                 if (path_swap)
3050                         path = path ^ 1;
3051
3052                 lane = path << 1;
3053         }
3054         return lane;
3055 }
3056
3057 static void elink_set_aer_mmd(struct elink_params *params,
3058                               struct elink_phy *phy)
3059 {
3060         uint32_t ser_lane;
3061         uint16_t offset, aer_val;
3062         struct bnx2x_softc *sc = params->sc;
3063         ser_lane = ((params->lane_config &
3064                      PORT_HW_CFG_LANE_SWAP_CFG_MASTER_MASK) >>
3065                     PORT_HW_CFG_LANE_SWAP_CFG_MASTER_SHIFT);
3066
3067         offset = (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT) ?
3068             (phy->addr + ser_lane) : 0;
3069
3070         if (USES_WARPCORE(sc)) {
3071                 aer_val = elink_get_warpcore_lane(params);
3072                 /* In Dual-lane mode, two lanes are joined together,
3073                  * so in order to configure them, the AER broadcast method is
3074                  * used here.
3075                  * 0x200 is the broadcast address for lanes 0,1
3076                  * 0x201 is the broadcast address for lanes 2,3
3077                  */
3078                 if (phy->flags & ELINK_FLAGS_WC_DUAL_MODE)
3079                         aer_val = (aer_val >> 1) | 0x200;
3080         } else if (CHIP_IS_E2(sc))
3081                 aer_val = 0x3800 + offset - 1;
3082         else
3083                 aer_val = 0x3800 + offset;
3084
3085         CL22_WR_OVER_CL45(sc, phy, MDIO_REG_BANK_AER_BLOCK,
3086                           MDIO_AER_BLOCK_AER_REG, aer_val);
3087
3088 }
3089
3090 /******************************************************************/
3091 /*                      Internal phy section                      */
3092 /******************************************************************/
3093
3094 static void elink_set_serdes_access(struct bnx2x_softc *sc, uint8_t port)
3095 {
3096         uint32_t emac_base = (port) ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
3097
3098         /* Set Clause 22 */
3099         REG_WR(sc, NIG_REG_SERDES0_CTRL_MD_ST + port * 0x10, 1);
3100         REG_WR(sc, emac_base + EMAC_REG_EMAC_MDIO_COMM, 0x245f8000);
3101         DELAY(500);
3102         REG_WR(sc, emac_base + EMAC_REG_EMAC_MDIO_COMM, 0x245d000f);
3103         DELAY(500);
3104         /* Set Clause 45 */
3105         REG_WR(sc, NIG_REG_SERDES0_CTRL_MD_ST + port * 0x10, 0);
3106 }
3107
3108 static void elink_serdes_deassert(struct bnx2x_softc *sc, uint8_t port)
3109 {
3110         uint32_t val;
3111
3112         PMD_DRV_LOG(DEBUG, "elink_serdes_deassert");
3113
3114         val = ELINK_SERDES_RESET_BITS << (port * 16);
3115
3116         /* Reset and unreset the SerDes/XGXS */
3117         REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_CLEAR, val);
3118         DELAY(500);
3119         REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_SET, val);
3120
3121         elink_set_serdes_access(sc, port);
3122
3123         REG_WR(sc, NIG_REG_SERDES0_CTRL_MD_DEVAD + port * 0x10,
3124                ELINK_DEFAULT_PHY_DEV_ADDR);
3125 }
3126
3127 static void elink_xgxs_specific_func(struct elink_phy *phy,
3128                                      struct elink_params *params,
3129                                      uint32_t action)
3130 {
3131         struct bnx2x_softc *sc = params->sc;
3132         switch (action) {
3133         case ELINK_PHY_INIT:
3134                 /* Set correct devad */
3135                 REG_WR(sc, NIG_REG_XGXS0_CTRL_MD_ST + params->port * 0x18, 0);
3136                 REG_WR(sc, NIG_REG_XGXS0_CTRL_MD_DEVAD + params->port * 0x18,
3137                        phy->def_md_devad);
3138                 break;
3139         }
3140 }
3141
3142 static void elink_xgxs_deassert(struct elink_params *params)
3143 {
3144         struct bnx2x_softc *sc = params->sc;
3145         uint8_t port;
3146         uint32_t val;
3147         PMD_DRV_LOG(DEBUG, "elink_xgxs_deassert");
3148         port = params->port;
3149
3150         val = ELINK_XGXS_RESET_BITS << (port * 16);
3151
3152         /* Reset and unreset the SerDes/XGXS */
3153         REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_CLEAR, val);
3154         DELAY(500);
3155         REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_SET, val);
3156         elink_xgxs_specific_func(&params->phy[ELINK_INT_PHY], params,
3157                                  ELINK_PHY_INIT);
3158 }
3159
3160 static void elink_calc_ieee_aneg_adv(struct elink_phy *phy,
3161                                      struct elink_params *params,
3162                                      uint16_t * ieee_fc)
3163 {
3164         *ieee_fc = MDIO_COMBO_IEEE0_AUTO_NEG_ADV_FULL_DUPLEX;
3165         /* Resolve pause mode and advertisement Please refer to Table
3166          * 28B-3 of the 802.3ab-1999 spec
3167          */
3168
3169         switch (phy->req_flow_ctrl) {
3170         case ELINK_FLOW_CTRL_AUTO:
3171                 switch (params->req_fc_auto_adv) {
3172                 case ELINK_FLOW_CTRL_BOTH:
3173                         *ieee_fc |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH;
3174                         break;
3175                 case ELINK_FLOW_CTRL_RX:
3176                 case ELINK_FLOW_CTRL_TX:
3177                         *ieee_fc |=
3178                             MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC;
3179                         break;
3180                 default:
3181                         break;
3182                 }
3183                 break;
3184         case ELINK_FLOW_CTRL_TX:
3185                 *ieee_fc |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC;
3186                 break;
3187
3188         case ELINK_FLOW_CTRL_RX:
3189         case ELINK_FLOW_CTRL_BOTH:
3190                 *ieee_fc |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH;
3191                 break;
3192
3193         case ELINK_FLOW_CTRL_NONE:
3194         default:
3195                 *ieee_fc |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE;
3196                 break;
3197         }
3198         PMD_DRV_LOG(DEBUG, "ieee_fc = 0x%x", *ieee_fc);
3199 }
3200
3201 static void set_phy_vars(struct elink_params *params, struct elink_vars *vars)
3202 {
3203         uint8_t actual_phy_idx, phy_index, link_cfg_idx;
3204         uint8_t phy_config_swapped = params->multi_phy_config &
3205             PORT_HW_CFG_PHY_SWAPPED_ENABLED;
3206         for (phy_index = ELINK_INT_PHY; phy_index < params->num_phys;
3207              phy_index++) {
3208                 link_cfg_idx = ELINK_LINK_CONFIG_IDX(phy_index);
3209                 actual_phy_idx = phy_index;
3210                 if (phy_config_swapped) {
3211                         if (phy_index == ELINK_EXT_PHY1)
3212                                 actual_phy_idx = ELINK_EXT_PHY2;
3213                         else if (phy_index == ELINK_EXT_PHY2)
3214                                 actual_phy_idx = ELINK_EXT_PHY1;
3215                 }
3216                 params->phy[actual_phy_idx].req_flow_ctrl =
3217                     params->req_flow_ctrl[link_cfg_idx];
3218
3219                 params->phy[actual_phy_idx].req_line_speed =
3220                     params->req_line_speed[link_cfg_idx];
3221
3222                 params->phy[actual_phy_idx].speed_cap_mask =
3223                     params->speed_cap_mask[link_cfg_idx];
3224
3225                 params->phy[actual_phy_idx].req_duplex =
3226                     params->req_duplex[link_cfg_idx];
3227
3228                 if (params->req_line_speed[link_cfg_idx] ==
3229                     ELINK_SPEED_AUTO_NEG)
3230                         vars->link_status |= LINK_STATUS_AUTO_NEGOTIATE_ENABLED;
3231
3232                 PMD_DRV_LOG(DEBUG, "req_flow_ctrl %x, req_line_speed %x,"
3233                             " speed_cap_mask %x",
3234                             params->phy[actual_phy_idx].req_flow_ctrl,
3235                             params->phy[actual_phy_idx].req_line_speed,
3236                             params->phy[actual_phy_idx].speed_cap_mask);
3237         }
3238 }
3239
3240 static void elink_ext_phy_set_pause(struct elink_params *params,
3241                                     struct elink_phy *phy,
3242                                     struct elink_vars *vars)
3243 {
3244         uint16_t val;
3245         struct bnx2x_softc *sc = params->sc;
3246         /* Read modify write pause advertizing */
3247         elink_cl45_read(sc, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV_PAUSE, &val);
3248
3249         val &= ~MDIO_AN_REG_ADV_PAUSE_BOTH;
3250
3251         /* Please refer to Table 28B-3 of 802.3ab-1999 spec. */
3252         elink_calc_ieee_aneg_adv(phy, params, &vars->ieee_fc);
3253         if ((vars->ieee_fc &
3254              MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC) ==
3255             MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC) {
3256                 val |= MDIO_AN_REG_ADV_PAUSE_ASYMMETRIC;
3257         }
3258         if ((vars->ieee_fc &
3259              MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) ==
3260             MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) {
3261                 val |= MDIO_AN_REG_ADV_PAUSE_PAUSE;
3262         }
3263         PMD_DRV_LOG(DEBUG, "Ext phy AN advertize 0x%x", val);
3264         elink_cl45_write(sc, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV_PAUSE, val);
3265 }
3266
3267 static void elink_pause_resolve(struct elink_vars *vars, uint32_t pause_result)
3268 {                               /*  LD      LP   */
3269         switch (pause_result) { /* ASYM P ASYM P */
3270         case 0xb:               /*   1  0   1  1 */
3271                 vars->flow_ctrl = ELINK_FLOW_CTRL_TX;
3272                 break;
3273
3274         case 0xe:               /*   1  1   1  0 */
3275                 vars->flow_ctrl = ELINK_FLOW_CTRL_RX;
3276                 break;
3277
3278         case 0x5:               /*   0  1   0  1 */
3279         case 0x7:               /*   0  1   1  1 */
3280         case 0xd:               /*   1  1   0  1 */
3281         case 0xf:               /*   1  1   1  1 */
3282                 vars->flow_ctrl = ELINK_FLOW_CTRL_BOTH;
3283                 break;
3284
3285         default:
3286                 break;
3287         }
3288         if (pause_result & (1 << 0))
3289                 vars->link_status |= LINK_STATUS_LINK_PARTNER_SYMMETRIC_PAUSE;
3290         if (pause_result & (1 << 1))
3291                 vars->link_status |= LINK_STATUS_LINK_PARTNER_ASYMMETRIC_PAUSE;
3292
3293 }
3294
3295 static void elink_ext_phy_update_adv_fc(struct elink_phy *phy,
3296                                         struct elink_params *params,
3297                                         struct elink_vars *vars)
3298 {
3299         uint16_t ld_pause;      /* local */
3300         uint16_t lp_pause;      /* link partner */
3301         uint16_t pause_result;
3302         struct bnx2x_softc *sc = params->sc;
3303         if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X54618SE) {
3304                 elink_cl22_read(sc, phy, 0x4, &ld_pause);
3305                 elink_cl22_read(sc, phy, 0x5, &lp_pause);
3306         } else if (CHIP_IS_E3(sc) && ELINK_SINGLE_MEDIA_DIRECT(params)) {
3307                 uint8_t lane = elink_get_warpcore_lane(params);
3308                 uint16_t gp_status, gp_mask;
3309                 elink_cl45_read(sc, phy,
3310                                 MDIO_AN_DEVAD, MDIO_WC_REG_GP2_STATUS_GP_2_4,
3311                                 &gp_status);
3312                 gp_mask = (MDIO_WC_REG_GP2_STATUS_GP_2_4_CL73_AN_CMPL |
3313                            MDIO_WC_REG_GP2_STATUS_GP_2_4_CL37_LP_AN_CAP) <<
3314                     lane;
3315                 if ((gp_status & gp_mask) == gp_mask) {
3316                         elink_cl45_read(sc, phy, MDIO_AN_DEVAD,
3317                                         MDIO_AN_REG_ADV_PAUSE, &ld_pause);
3318                         elink_cl45_read(sc, phy, MDIO_AN_DEVAD,
3319                                         MDIO_AN_REG_LP_AUTO_NEG, &lp_pause);
3320                 } else {
3321                         elink_cl45_read(sc, phy, MDIO_AN_DEVAD,
3322                                         MDIO_AN_REG_CL37_FC_LD, &ld_pause);
3323                         elink_cl45_read(sc, phy, MDIO_AN_DEVAD,
3324                                         MDIO_AN_REG_CL37_FC_LP, &lp_pause);
3325                         ld_pause = ((ld_pause &
3326                                      MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH)
3327                                     << 3);
3328                         lp_pause = ((lp_pause &
3329                                      MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH)
3330                                     << 3);
3331                 }
3332         } else {
3333                 elink_cl45_read(sc, phy,
3334                                 MDIO_AN_DEVAD,
3335                                 MDIO_AN_REG_ADV_PAUSE, &ld_pause);
3336                 elink_cl45_read(sc, phy,
3337                                 MDIO_AN_DEVAD,
3338                                 MDIO_AN_REG_LP_AUTO_NEG, &lp_pause);
3339         }
3340         pause_result = (ld_pause & MDIO_AN_REG_ADV_PAUSE_MASK) >> 8;
3341         pause_result |= (lp_pause & MDIO_AN_REG_ADV_PAUSE_MASK) >> 10;
3342         PMD_DRV_LOG(DEBUG, "Ext PHY pause result 0x%x", pause_result);
3343         elink_pause_resolve(vars, pause_result);
3344
3345 }
3346
3347 static uint8_t elink_ext_phy_resolve_fc(struct elink_phy *phy,
3348                                         struct elink_params *params,
3349                                         struct elink_vars *vars)
3350 {
3351         uint8_t ret = 0;
3352         vars->flow_ctrl = ELINK_FLOW_CTRL_NONE;
3353         if (phy->req_flow_ctrl != ELINK_FLOW_CTRL_AUTO) {
3354                 /* Update the advertised flow-controled of LD/LP in AN */
3355                 if (phy->req_line_speed == ELINK_SPEED_AUTO_NEG)
3356                         elink_ext_phy_update_adv_fc(phy, params, vars);
3357                 /* But set the flow-control result as the requested one */
3358                 vars->flow_ctrl = phy->req_flow_ctrl;
3359         } else if (phy->req_line_speed != ELINK_SPEED_AUTO_NEG)
3360                 vars->flow_ctrl = params->req_fc_auto_adv;
3361         else if (vars->link_status & LINK_STATUS_AUTO_NEGOTIATE_COMPLETE) {
3362                 ret = 1;
3363                 elink_ext_phy_update_adv_fc(phy, params, vars);
3364         }
3365         return ret;
3366 }
3367
3368 /******************************************************************/
3369 /*                      Warpcore section                          */
3370 /******************************************************************/
3371 /* The init_internal_warpcore should mirror the xgxs,
3372  * i.e. reset the lane (if needed), set aer for the
3373  * init configuration, and set/clear SGMII flag. Internal
3374  * phy init is done purely in phy_init stage.
3375  */
3376 #define WC_TX_DRIVER(post2, idriver, ipre) \
3377         ((post2 << MDIO_WC_REG_TX0_TX_DRIVER_POST2_COEFF_OFFSET) | \
3378          (idriver << MDIO_WC_REG_TX0_TX_DRIVER_IDRIVER_OFFSET) | \
3379          (ipre << MDIO_WC_REG_TX0_TX_DRIVER_IPRE_DRIVER_OFFSET))
3380
3381 #define WC_TX_FIR(post, main, pre) \
3382         ((post << MDIO_WC_REG_TX_FIR_TAP_POST_TAP_OFFSET) | \
3383          (main << MDIO_WC_REG_TX_FIR_TAP_MAIN_TAP_OFFSET) | \
3384          (pre << MDIO_WC_REG_TX_FIR_TAP_PRE_TAP_OFFSET))
3385
3386 static void elink_warpcore_enable_AN_KR2(struct elink_phy *phy,
3387                                          struct elink_params *params,
3388                                          struct elink_vars *vars)
3389 {
3390         struct bnx2x_softc *sc = params->sc;
3391         uint16_t i;
3392         static struct elink_reg_set reg_set[] = {
3393                 /* Step 1 - Program the TX/RX alignment markers */
3394                 {MDIO_WC_DEVAD, MDIO_WC_REG_CL82_USERB1_TX_CTRL5, 0xa157},
3395                 {MDIO_WC_DEVAD, MDIO_WC_REG_CL82_USERB1_TX_CTRL7, 0xcbe2},
3396                 {MDIO_WC_DEVAD, MDIO_WC_REG_CL82_USERB1_TX_CTRL6, 0x7537},
3397                 {MDIO_WC_DEVAD, MDIO_WC_REG_CL82_USERB1_TX_CTRL9, 0xa157},
3398                 {MDIO_WC_DEVAD, MDIO_WC_REG_CL82_USERB1_RX_CTRL11, 0xcbe2},
3399                 {MDIO_WC_DEVAD, MDIO_WC_REG_CL82_USERB1_RX_CTRL10, 0x7537},
3400                 /* Step 2 - Configure the NP registers */
3401                 {MDIO_WC_DEVAD, MDIO_WC_REG_CL73_USERB0_CTRL, 0x000a},
3402                 {MDIO_WC_DEVAD, MDIO_WC_REG_CL73_BAM_CTRL1, 0x6400},
3403                 {MDIO_WC_DEVAD, MDIO_WC_REG_CL73_BAM_CTRL3, 0x0620},
3404                 {MDIO_WC_DEVAD, MDIO_WC_REG_CL73_BAM_CODE_FIELD, 0x0157},
3405                 {MDIO_WC_DEVAD, MDIO_WC_REG_ETA_CL73_OUI1, 0x6464},
3406                 {MDIO_WC_DEVAD, MDIO_WC_REG_ETA_CL73_OUI2, 0x3150},
3407                 {MDIO_WC_DEVAD, MDIO_WC_REG_ETA_CL73_OUI3, 0x3150},
3408                 {MDIO_WC_DEVAD, MDIO_WC_REG_ETA_CL73_LD_BAM_CODE, 0x0157},
3409                 {MDIO_WC_DEVAD, MDIO_WC_REG_ETA_CL73_LD_UD_CODE, 0x0620}
3410         };
3411         PMD_DRV_LOG(DEBUG, "Enabling 20G-KR2");
3412
3413         elink_cl45_read_or_write(sc, phy, MDIO_WC_DEVAD,
3414                                  MDIO_WC_REG_CL49_USERB0_CTRL, (3 << 6));
3415
3416         for (i = 0; i < ARRAY_SIZE(reg_set); i++)
3417                 elink_cl45_write(sc, phy, reg_set[i].devad, reg_set[i].reg,
3418                                  reg_set[i].val);
3419
3420         /* Start KR2 work-around timer which handles BNX2X8073 link-parner */
3421         vars->link_attr_sync |= LINK_ATTR_SYNC_KR2_ENABLE;
3422         elink_update_link_attr(params, vars->link_attr_sync);
3423 }
3424
3425 static void elink_disable_kr2(struct elink_params *params,
3426                               struct elink_vars *vars, struct elink_phy *phy)
3427 {
3428         struct bnx2x_softc *sc = params->sc;
3429         uint32_t i;
3430         static struct elink_reg_set reg_set[] = {
3431                 /* Step 1 - Program the TX/RX alignment markers */
3432                 {MDIO_WC_DEVAD, MDIO_WC_REG_CL82_USERB1_TX_CTRL5, 0x7690},
3433                 {MDIO_WC_DEVAD, MDIO_WC_REG_CL82_USERB1_TX_CTRL7, 0xe647},
3434                 {MDIO_WC_DEVAD, MDIO_WC_REG_CL82_USERB1_TX_CTRL6, 0xc4f0},
3435                 {MDIO_WC_DEVAD, MDIO_WC_REG_CL82_USERB1_TX_CTRL9, 0x7690},
3436                 {MDIO_WC_DEVAD, MDIO_WC_REG_CL82_USERB1_RX_CTRL11, 0xe647},
3437                 {MDIO_WC_DEVAD, MDIO_WC_REG_CL82_USERB1_RX_CTRL10, 0xc4f0},
3438                 {MDIO_WC_DEVAD, MDIO_WC_REG_CL73_USERB0_CTRL, 0x000c},
3439                 {MDIO_WC_DEVAD, MDIO_WC_REG_CL73_BAM_CTRL1, 0x6000},
3440                 {MDIO_WC_DEVAD, MDIO_WC_REG_CL73_BAM_CTRL3, 0x0000},
3441                 {MDIO_WC_DEVAD, MDIO_WC_REG_CL73_BAM_CODE_FIELD, 0x0002},
3442                 {MDIO_WC_DEVAD, MDIO_WC_REG_ETA_CL73_OUI1, 0x0000},
3443                 {MDIO_WC_DEVAD, MDIO_WC_REG_ETA_CL73_OUI2, 0x0af7},
3444                 {MDIO_WC_DEVAD, MDIO_WC_REG_ETA_CL73_OUI3, 0x0af7},
3445                 {MDIO_WC_DEVAD, MDIO_WC_REG_ETA_CL73_LD_BAM_CODE, 0x0002},
3446                 {MDIO_WC_DEVAD, MDIO_WC_REG_ETA_CL73_LD_UD_CODE, 0x0000}
3447         };
3448         PMD_DRV_LOG(DEBUG, "Disabling 20G-KR2");
3449
3450         for (i = 0; i < ARRAY_SIZE(reg_set); i++)
3451                 elink_cl45_write(sc, phy, reg_set[i].devad, reg_set[i].reg,
3452                                  reg_set[i].val);
3453         vars->link_attr_sync &= ~LINK_ATTR_SYNC_KR2_ENABLE;
3454         elink_update_link_attr(params, vars->link_attr_sync);
3455
3456         vars->check_kr2_recovery_cnt = ELINK_CHECK_KR2_RECOVERY_CNT;
3457 }
3458
3459 static void elink_warpcore_set_lpi_passthrough(struct elink_phy *phy,
3460                                                struct elink_params *params)
3461 {
3462         struct bnx2x_softc *sc = params->sc;
3463
3464         PMD_DRV_LOG(DEBUG, "Configure WC for LPI pass through");
3465         elink_cl45_write(sc, phy, MDIO_WC_DEVAD,
3466                          MDIO_WC_REG_EEE_COMBO_CONTROL0, 0x7c);
3467         elink_cl45_read_or_write(sc, phy, MDIO_WC_DEVAD,
3468                                  MDIO_WC_REG_DIGITAL4_MISC5, 0xc000);
3469 }
3470
3471 static void elink_warpcore_restart_AN_KR(struct elink_phy *phy,
3472                                          struct elink_params *params)
3473 {
3474         /* Restart autoneg on the leading lane only */
3475         struct bnx2x_softc *sc = params->sc;
3476         uint16_t lane = elink_get_warpcore_lane(params);
3477         CL22_WR_OVER_CL45(sc, phy, MDIO_REG_BANK_AER_BLOCK,
3478                           MDIO_AER_BLOCK_AER_REG, lane);
3479         elink_cl45_write(sc, phy, MDIO_AN_DEVAD,
3480                          MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x1200);
3481
3482         /* Restore AER */
3483         elink_set_aer_mmd(params, phy);
3484 }
3485
3486 static void elink_warpcore_enable_AN_KR(struct elink_phy *phy,
3487                                         struct elink_params *params,
3488                                         struct elink_vars *vars)
3489 {
3490         uint16_t lane, i, cl72_ctrl, an_adv = 0;
3491         struct bnx2x_softc *sc = params->sc;
3492         static struct elink_reg_set reg_set[] = {
3493                 {MDIO_WC_DEVAD, MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2, 0x7},
3494                 {MDIO_PMA_DEVAD, MDIO_WC_REG_IEEE0BLK_AUTONEGNP, 0x0},
3495                 {MDIO_WC_DEVAD, MDIO_WC_REG_RX66_CONTROL, 0x7415},
3496                 {MDIO_WC_DEVAD, MDIO_WC_REG_SERDESDIGITAL_MISC2, 0x6190},
3497                 /* Disable Autoneg: re-enable it after adv is done. */
3498                 {MDIO_AN_DEVAD, MDIO_WC_REG_IEEE0BLK_MIICNTL, 0},
3499                 {MDIO_PMA_DEVAD, MDIO_WC_REG_PMD_KR_CONTROL, 0x2},
3500                 {MDIO_WC_DEVAD, MDIO_WC_REG_CL72_USERB0_CL72_TX_FIR_TAP, 0},
3501         };
3502         PMD_DRV_LOG(DEBUG, "Enable Auto Negotiation for KR");
3503         /* Set to default registers that may be overriden by 10G force */
3504         for (i = 0; i < ARRAY_SIZE(reg_set); i++)
3505                 elink_cl45_write(sc, phy, reg_set[i].devad, reg_set[i].reg,
3506                                  reg_set[i].val);
3507
3508         elink_cl45_read(sc, phy, MDIO_WC_DEVAD,
3509                         MDIO_WC_REG_CL72_USERB0_CL72_MISC1_CONTROL, &cl72_ctrl);
3510         cl72_ctrl &= 0x08ff;
3511         cl72_ctrl |= 0x3800;
3512         elink_cl45_write(sc, phy, MDIO_WC_DEVAD,
3513                          MDIO_WC_REG_CL72_USERB0_CL72_MISC1_CONTROL, cl72_ctrl);
3514
3515         /* Check adding advertisement for 1G KX */
3516         if (((vars->line_speed == ELINK_SPEED_AUTO_NEG) &&
3517              (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) ||
3518             (vars->line_speed == ELINK_SPEED_1000)) {
3519                 uint16_t addr = MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2;
3520                 an_adv |= (1 << 5);
3521
3522                 /* Enable CL37 1G Parallel Detect */
3523                 elink_cl45_read_or_write(sc, phy, MDIO_WC_DEVAD, addr, 0x1);
3524                 PMD_DRV_LOG(DEBUG, "Advertize 1G");
3525         }
3526         if (((vars->line_speed == ELINK_SPEED_AUTO_NEG) &&
3527              (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) ||
3528             (vars->line_speed == ELINK_SPEED_10000)) {
3529                 /* Check adding advertisement for 10G KR */
3530                 an_adv |= (1 << 7);
3531                 /* Enable 10G Parallel Detect */
3532                 CL22_WR_OVER_CL45(sc, phy, MDIO_REG_BANK_AER_BLOCK,
3533                                   MDIO_AER_BLOCK_AER_REG, 0);
3534
3535                 elink_cl45_write(sc, phy, MDIO_AN_DEVAD,
3536                                  MDIO_WC_REG_PAR_DET_10G_CTRL, 1);
3537                 elink_set_aer_mmd(params, phy);
3538                 PMD_DRV_LOG(DEBUG, "Advertize 10G");
3539         }
3540
3541         /* Set Transmit PMD settings */
3542         lane = elink_get_warpcore_lane(params);
3543         elink_cl45_write(sc, phy, MDIO_WC_DEVAD,
3544                          MDIO_WC_REG_TX0_TX_DRIVER + 0x10 * lane,
3545                          WC_TX_DRIVER(0x02, 0x06, 0x09));
3546         /* Configure the next lane if dual mode */
3547         if (phy->flags & ELINK_FLAGS_WC_DUAL_MODE)
3548                 elink_cl45_write(sc, phy, MDIO_WC_DEVAD,
3549                                  MDIO_WC_REG_TX0_TX_DRIVER + 0x10 * (lane + 1),
3550                                  WC_TX_DRIVER(0x02, 0x06, 0x09));
3551         elink_cl45_write(sc, phy, MDIO_WC_DEVAD,
3552                          MDIO_WC_REG_CL72_USERB0_CL72_OS_DEF_CTRL, 0x03f0);
3553         elink_cl45_write(sc, phy, MDIO_WC_DEVAD,
3554                          MDIO_WC_REG_CL72_USERB0_CL72_2P5_DEF_CTRL, 0x03f0);
3555
3556         /* Advertised speeds */
3557         elink_cl45_write(sc, phy, MDIO_AN_DEVAD,
3558                          MDIO_WC_REG_AN_IEEE1BLK_AN_ADVERTISEMENT1, an_adv);
3559
3560         /* Advertised and set FEC (Forward Error Correction) */
3561         elink_cl45_write(sc, phy, MDIO_AN_DEVAD,
3562                          MDIO_WC_REG_AN_IEEE1BLK_AN_ADVERTISEMENT2,
3563                          (MDIO_WC_REG_AN_IEEE1BLK_AN_ADV2_FEC_ABILITY |
3564                           MDIO_WC_REG_AN_IEEE1BLK_AN_ADV2_FEC_REQ));
3565
3566         /* Enable CL37 BAM */
3567         if (REG_RD(sc, params->shmem_base +
3568                    offsetof(struct shmem_region,
3569                             dev_info.port_hw_config[params->port].
3570                             default_cfg)) &
3571             PORT_HW_CFG_ENABLE_BAM_ON_KR_ENABLED) {
3572                 elink_cl45_read_or_write(sc, phy, MDIO_WC_DEVAD,
3573                                          MDIO_WC_REG_DIGITAL6_MP5_NEXTPAGECTRL,
3574                                          1);
3575                 PMD_DRV_LOG(DEBUG, "Enable CL37 BAM on KR");
3576         }
3577
3578         /* Advertise pause */
3579         elink_ext_phy_set_pause(params, phy, vars);
3580         vars->rx_tx_asic_rst = MAX_KR_LINK_RETRY;
3581         elink_cl45_read_or_write(sc, phy, MDIO_WC_DEVAD,
3582                                  MDIO_WC_REG_DIGITAL5_MISC7, 0x100);
3583
3584         /* Over 1G - AN local device user page 1 */
3585         elink_cl45_write(sc, phy, MDIO_WC_DEVAD,
3586                          MDIO_WC_REG_DIGITAL3_UP1, 0x1f);
3587
3588         if (((phy->req_line_speed == ELINK_SPEED_AUTO_NEG) &&
3589              (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_20G)) ||
3590             (phy->req_line_speed == ELINK_SPEED_20000)) {
3591
3592                 CL22_WR_OVER_CL45(sc, phy, MDIO_REG_BANK_AER_BLOCK,
3593                                   MDIO_AER_BLOCK_AER_REG, lane);
3594
3595                 elink_cl45_read_or_write(sc, phy, MDIO_WC_DEVAD,
3596                                          MDIO_WC_REG_RX1_PCI_CTRL +
3597                                          (0x10 * lane), (1 << 11));
3598
3599                 elink_cl45_write(sc, phy, MDIO_WC_DEVAD,
3600                                  MDIO_WC_REG_XGXS_X2_CONTROL3, 0x7);
3601                 elink_set_aer_mmd(params, phy);
3602
3603                 elink_warpcore_enable_AN_KR2(phy, params, vars);
3604         } else {
3605                 elink_disable_kr2(params, vars, phy);
3606         }
3607
3608         /* Enable Autoneg: only on the main lane */
3609         elink_warpcore_restart_AN_KR(phy, params);
3610 }
3611
3612 static void elink_warpcore_set_10G_KR(struct elink_phy *phy,
3613                                       struct elink_params *params)
3614 {
3615         struct bnx2x_softc *sc = params->sc;
3616         uint16_t val16, i, lane;
3617         static struct elink_reg_set reg_set[] = {
3618                 /* Disable Autoneg */
3619                 {MDIO_WC_DEVAD, MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2, 0x7},
3620                 {MDIO_WC_DEVAD, MDIO_WC_REG_CL72_USERB0_CL72_MISC1_CONTROL,
3621                  0x3f00},
3622                 {MDIO_AN_DEVAD, MDIO_WC_REG_AN_IEEE1BLK_AN_ADVERTISEMENT1, 0},
3623                 {MDIO_AN_DEVAD, MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x0},
3624                 {MDIO_WC_DEVAD, MDIO_WC_REG_DIGITAL3_UP1, 0x1},
3625                 {MDIO_WC_DEVAD, MDIO_WC_REG_DIGITAL5_MISC7, 0xa},
3626                 /* Leave cl72 training enable, needed for KR */
3627                 {MDIO_PMA_DEVAD, MDIO_WC_REG_PMD_KR_CONTROL, 0x2}
3628         };
3629
3630         for (i = 0; i < ARRAY_SIZE(reg_set); i++)
3631                 elink_cl45_write(sc, phy, reg_set[i].devad, reg_set[i].reg,
3632                                  reg_set[i].val);
3633
3634         lane = elink_get_warpcore_lane(params);
3635         /* Global registers */
3636         CL22_WR_OVER_CL45(sc, phy, MDIO_REG_BANK_AER_BLOCK,
3637                           MDIO_AER_BLOCK_AER_REG, 0);
3638         /* Disable CL36 PCS Tx */
3639         elink_cl45_read(sc, phy, MDIO_WC_DEVAD,
3640                         MDIO_WC_REG_XGXSBLK1_LANECTRL0, &val16);
3641         val16 &= ~(0x0011 << lane);
3642         elink_cl45_write(sc, phy, MDIO_WC_DEVAD,
3643                          MDIO_WC_REG_XGXSBLK1_LANECTRL0, val16);
3644
3645         elink_cl45_read(sc, phy, MDIO_WC_DEVAD,
3646                         MDIO_WC_REG_XGXSBLK1_LANECTRL1, &val16);
3647         val16 |= (0x0303 << (lane << 1));
3648         elink_cl45_write(sc, phy, MDIO_WC_DEVAD,
3649                          MDIO_WC_REG_XGXSBLK1_LANECTRL1, val16);
3650         /* Restore AER */
3651         elink_set_aer_mmd(params, phy);
3652         /* Set speed via PMA/PMD register */
3653         elink_cl45_write(sc, phy, MDIO_PMA_DEVAD,
3654                          MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x2040);
3655
3656         elink_cl45_write(sc, phy, MDIO_PMA_DEVAD,
3657                          MDIO_WC_REG_IEEE0BLK_AUTONEGNP, 0xB);
3658
3659         /* Enable encoded forced speed */
3660         elink_cl45_write(sc, phy, MDIO_WC_DEVAD,
3661                          MDIO_WC_REG_SERDESDIGITAL_MISC2, 0x30);
3662
3663         /* Turn TX scramble payload only the 64/66 scrambler */
3664         elink_cl45_write(sc, phy, MDIO_WC_DEVAD, MDIO_WC_REG_TX66_CONTROL, 0x9);
3665
3666         /* Turn RX scramble payload only the 64/66 scrambler */
3667         elink_cl45_read_or_write(sc, phy, MDIO_WC_DEVAD,
3668                                  MDIO_WC_REG_RX66_CONTROL, 0xF9);
3669
3670         /* Set and clear loopback to cause a reset to 64/66 decoder */
3671         elink_cl45_write(sc, phy, MDIO_WC_DEVAD,
3672                          MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x4000);
3673         elink_cl45_write(sc, phy, MDIO_WC_DEVAD,
3674                          MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x0);
3675
3676 }
3677
3678 static void elink_warpcore_set_10G_XFI(struct elink_phy *phy,
3679                                        struct elink_params *params,
3680                                        uint8_t is_xfi)
3681 {
3682         struct bnx2x_softc *sc = params->sc;
3683         uint16_t misc1_val, tap_val, tx_driver_val, lane, val;
3684         uint32_t cfg_tap_val, tx_drv_brdct, tx_equal;
3685
3686         /* Hold rxSeqStart */
3687         elink_cl45_read_or_write(sc, phy, MDIO_WC_DEVAD,
3688                                  MDIO_WC_REG_DSC2B0_DSC_MISC_CTRL0, 0x8000);
3689
3690         /* Hold tx_fifo_reset */
3691         elink_cl45_read_or_write(sc, phy, MDIO_WC_DEVAD,
3692                                  MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X3, 0x1);
3693
3694         /* Disable CL73 AN */
3695         elink_cl45_write(sc, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0);
3696
3697         /* Disable 100FX Enable and Auto-Detect */
3698         elink_cl45_read_and_write(sc, phy, MDIO_WC_DEVAD,
3699                                   MDIO_WC_REG_FX100_CTRL1, 0xFFFA);
3700
3701         /* Disable 100FX Idle detect */
3702         elink_cl45_read_or_write(sc, phy, MDIO_WC_DEVAD,
3703                                  MDIO_WC_REG_FX100_CTRL3, 0x0080);
3704
3705         /* Set Block address to Remote PHY & Clear forced_speed[5] */
3706         elink_cl45_read_and_write(sc, phy, MDIO_WC_DEVAD,
3707                                   MDIO_WC_REG_DIGITAL4_MISC3, 0xFF7F);
3708
3709         /* Turn off auto-detect & fiber mode */
3710         elink_cl45_read_and_write(sc, phy, MDIO_WC_DEVAD,
3711                                   MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X1,
3712                                   0xFFEE);
3713
3714         /* Set filter_force_link, disable_false_link and parallel_detect */
3715         elink_cl45_read(sc, phy, MDIO_WC_DEVAD,
3716                         MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2, &val);
3717         elink_cl45_write(sc, phy, MDIO_WC_DEVAD,
3718                          MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2,
3719                          ((val | 0x0006) & 0xFFFE));
3720
3721         /* Set XFI / SFI */
3722         elink_cl45_read(sc, phy, MDIO_WC_DEVAD,
3723                         MDIO_WC_REG_SERDESDIGITAL_MISC1, &misc1_val);
3724
3725         misc1_val &= ~(0x1f);
3726
3727         if (is_xfi) {
3728                 misc1_val |= 0x5;
3729                 tap_val = WC_TX_FIR(0x08, 0x37, 0x00);
3730                 tx_driver_val = WC_TX_DRIVER(0x00, 0x02, 0x03);
3731         } else {
3732                 cfg_tap_val = REG_RD(sc, params->shmem_base +
3733                                      offsetof(struct shmem_region,
3734                                               dev_info.port_hw_config[params->
3735                                                                       port].sfi_tap_values));
3736
3737                 tx_equal = cfg_tap_val & PORT_HW_CFG_TX_EQUALIZATION_MASK;
3738
3739                 tx_drv_brdct = (cfg_tap_val &
3740                                 PORT_HW_CFG_TX_DRV_BROADCAST_MASK) >>
3741                     PORT_HW_CFG_TX_DRV_BROADCAST_SHIFT;
3742
3743                 misc1_val |= 0x9;
3744
3745                 /* TAP values are controlled by nvram, if value there isn't 0 */
3746                 if (tx_equal)
3747                         tap_val = (uint16_t) tx_equal;
3748                 else
3749                         tap_val = WC_TX_FIR(0x0f, 0x2b, 0x02);
3750
3751                 if (tx_drv_brdct)
3752                         tx_driver_val =
3753                             WC_TX_DRIVER(0x03, (uint16_t) tx_drv_brdct, 0x06);
3754                 else
3755                         tx_driver_val = WC_TX_DRIVER(0x03, 0x02, 0x06);
3756         }
3757         elink_cl45_write(sc, phy, MDIO_WC_DEVAD,
3758                          MDIO_WC_REG_SERDESDIGITAL_MISC1, misc1_val);
3759
3760         /* Set Transmit PMD settings */
3761         lane = elink_get_warpcore_lane(params);
3762         elink_cl45_write(sc, phy, MDIO_WC_DEVAD,
3763                          MDIO_WC_REG_TX_FIR_TAP,
3764                          tap_val | MDIO_WC_REG_TX_FIR_TAP_ENABLE);
3765         elink_cl45_write(sc, phy, MDIO_WC_DEVAD,
3766                          MDIO_WC_REG_TX0_TX_DRIVER + 0x10 * lane,
3767                          tx_driver_val);
3768
3769         /* Enable fiber mode, enable and invert sig_det */
3770         elink_cl45_read_or_write(sc, phy, MDIO_WC_DEVAD,
3771                                  MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X1, 0xd);
3772
3773         /* Set Block address to Remote PHY & Set forced_speed[5], 40bit mode */
3774         elink_cl45_read_or_write(sc, phy, MDIO_WC_DEVAD,
3775                                  MDIO_WC_REG_DIGITAL4_MISC3, 0x8080);
3776
3777         elink_warpcore_set_lpi_passthrough(phy, params);
3778
3779         /* 10G XFI Full Duplex */
3780         elink_cl45_write(sc, phy, MDIO_WC_DEVAD,
3781                          MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x100);
3782
3783         /* Release tx_fifo_reset */
3784         elink_cl45_read_and_write(sc, phy, MDIO_WC_DEVAD,
3785                                   MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X3,
3786                                   0xFFFE);
3787         /* Release rxSeqStart */
3788         elink_cl45_read_and_write(sc, phy, MDIO_WC_DEVAD,
3789                                   MDIO_WC_REG_DSC2B0_DSC_MISC_CTRL0, 0x7FFF);
3790 }
3791
3792 static void elink_warpcore_set_20G_force_KR2(struct elink_phy *phy,
3793                                              struct elink_params *params)
3794 {
3795         uint16_t val;
3796         struct bnx2x_softc *sc = params->sc;
3797         /* Set global registers, so set AER lane to 0 */
3798         CL22_WR_OVER_CL45(sc, phy, MDIO_REG_BANK_AER_BLOCK,
3799                           MDIO_AER_BLOCK_AER_REG, 0);
3800
3801         /* Disable sequencer */
3802         elink_cl45_read_and_write(sc, phy, MDIO_WC_DEVAD,
3803                                   MDIO_WC_REG_XGXSBLK0_XGXSCONTROL, ~(1 << 13));
3804
3805         elink_set_aer_mmd(params, phy);
3806
3807         elink_cl45_read_and_write(sc, phy, MDIO_PMA_DEVAD,
3808                                   MDIO_WC_REG_PMD_KR_CONTROL, ~(1 << 1));
3809         elink_cl45_write(sc, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0);
3810         /* Turn off CL73 */
3811         elink_cl45_read(sc, phy, MDIO_WC_DEVAD,
3812                         MDIO_WC_REG_CL73_USERB0_CTRL, &val);
3813         val &= ~(1 << 5);
3814         val |= (1 << 6);
3815         elink_cl45_write(sc, phy, MDIO_WC_DEVAD,
3816                          MDIO_WC_REG_CL73_USERB0_CTRL, val);
3817
3818         /* Set 20G KR2 force speed */
3819         elink_cl45_read_or_write(sc, phy, MDIO_WC_DEVAD,
3820                                  MDIO_WC_REG_SERDESDIGITAL_MISC1, 0x1f);
3821
3822         elink_cl45_read_or_write(sc, phy, MDIO_WC_DEVAD,
3823                                  MDIO_WC_REG_DIGITAL4_MISC3, (1 << 7));
3824
3825         elink_cl45_read(sc, phy, MDIO_WC_DEVAD,
3826                         MDIO_WC_REG_CL72_USERB0_CL72_MISC1_CONTROL, &val);
3827         val &= ~(3 << 14);
3828         val |= (1 << 15);
3829         elink_cl45_write(sc, phy, MDIO_WC_DEVAD,
3830                          MDIO_WC_REG_CL72_USERB0_CL72_MISC1_CONTROL, val);
3831         elink_cl45_write(sc, phy, MDIO_WC_DEVAD,
3832                          MDIO_WC_REG_CL72_USERB0_CL72_TX_FIR_TAP, 0x835A);
3833
3834         /* Enable sequencer (over lane 0) */
3835         CL22_WR_OVER_CL45(sc, phy, MDIO_REG_BANK_AER_BLOCK,
3836                           MDIO_AER_BLOCK_AER_REG, 0);
3837
3838         elink_cl45_read_or_write(sc, phy, MDIO_WC_DEVAD,
3839                                  MDIO_WC_REG_XGXSBLK0_XGXSCONTROL, (1 << 13));
3840
3841         elink_set_aer_mmd(params, phy);
3842 }
3843
3844 static void elink_warpcore_set_20G_DXGXS(struct bnx2x_softc *sc,
3845                                          struct elink_phy *phy, uint16_t lane)
3846 {
3847         /* Rx0 anaRxControl1G */
3848         elink_cl45_write(sc, phy, MDIO_WC_DEVAD,
3849                          MDIO_WC_REG_RX0_ANARXCONTROL1G, 0x90);
3850
3851         /* Rx2 anaRxControl1G */
3852         elink_cl45_write(sc, phy, MDIO_WC_DEVAD,
3853                          MDIO_WC_REG_RX2_ANARXCONTROL1G, 0x90);
3854
3855         elink_cl45_write(sc, phy, MDIO_WC_DEVAD, MDIO_WC_REG_RX66_SCW0, 0xE070);
3856
3857         elink_cl45_write(sc, phy, MDIO_WC_DEVAD, MDIO_WC_REG_RX66_SCW1, 0xC0D0);
3858
3859         elink_cl45_write(sc, phy, MDIO_WC_DEVAD, MDIO_WC_REG_RX66_SCW2, 0xA0B0);
3860
3861         elink_cl45_write(sc, phy, MDIO_WC_DEVAD, MDIO_WC_REG_RX66_SCW3, 0x8090);
3862
3863         elink_cl45_write(sc, phy, MDIO_WC_DEVAD,
3864                          MDIO_WC_REG_RX66_SCW0_MASK, 0xF0F0);
3865
3866         elink_cl45_write(sc, phy, MDIO_WC_DEVAD,
3867                          MDIO_WC_REG_RX66_SCW1_MASK, 0xF0F0);
3868
3869         elink_cl45_write(sc, phy, MDIO_WC_DEVAD,
3870                          MDIO_WC_REG_RX66_SCW2_MASK, 0xF0F0);
3871
3872         elink_cl45_write(sc, phy, MDIO_WC_DEVAD,
3873                          MDIO_WC_REG_RX66_SCW3_MASK, 0xF0F0);
3874
3875         /* Serdes Digital Misc1 */
3876         elink_cl45_write(sc, phy, MDIO_WC_DEVAD,
3877                          MDIO_WC_REG_SERDESDIGITAL_MISC1, 0x6008);
3878
3879         /* Serdes Digital4 Misc3 */
3880         elink_cl45_write(sc, phy, MDIO_WC_DEVAD,
3881                          MDIO_WC_REG_DIGITAL4_MISC3, 0x8088);
3882
3883         /* Set Transmit PMD settings */
3884         elink_cl45_write(sc, phy, MDIO_WC_DEVAD,
3885                          MDIO_WC_REG_TX_FIR_TAP,
3886                          (WC_TX_FIR(0x12, 0x2d, 0x00) |
3887                           MDIO_WC_REG_TX_FIR_TAP_ENABLE));
3888         elink_cl45_write(sc, phy, MDIO_WC_DEVAD,
3889                          MDIO_WC_REG_TX0_TX_DRIVER + 0x10 * lane,
3890                          WC_TX_DRIVER(0x02, 0x02, 0x02));
3891 }
3892
3893 static void elink_warpcore_set_sgmii_speed(struct elink_phy *phy,
3894                                            struct elink_params *params,
3895                                            uint8_t fiber_mode,
3896                                            uint8_t always_autoneg)
3897 {
3898         struct bnx2x_softc *sc = params->sc;
3899         uint16_t val16, digctrl_kx1, digctrl_kx2;
3900
3901         /* Clear XFI clock comp in non-10G single lane mode. */
3902         elink_cl45_read_and_write(sc, phy, MDIO_WC_DEVAD,
3903                                   MDIO_WC_REG_RX66_CONTROL, ~(3 << 13));
3904
3905         elink_warpcore_set_lpi_passthrough(phy, params);
3906
3907         if (always_autoneg || phy->req_line_speed == ELINK_SPEED_AUTO_NEG) {
3908                 /* SGMII Autoneg */
3909                 elink_cl45_read_or_write(sc, phy, MDIO_WC_DEVAD,
3910                                          MDIO_WC_REG_COMBO_IEEE0_MIICTRL,
3911                                          0x1000);
3912                 PMD_DRV_LOG(DEBUG, "set SGMII AUTONEG");
3913         } else {
3914                 elink_cl45_read(sc, phy, MDIO_WC_DEVAD,
3915                                 MDIO_WC_REG_COMBO_IEEE0_MIICTRL, &val16);
3916                 val16 &= 0xcebf;
3917                 switch (phy->req_line_speed) {
3918                 case ELINK_SPEED_10:
3919                         break;
3920                 case ELINK_SPEED_100:
3921                         val16 |= 0x2000;
3922                         break;
3923                 case ELINK_SPEED_1000:
3924                         val16 |= 0x0040;
3925                         break;
3926                 default:
3927                         PMD_DRV_LOG(DEBUG,
3928                                     "Speed not supported: 0x%x",
3929                                     phy->req_line_speed);
3930                         return;
3931                 }
3932
3933                 if (phy->req_duplex == DUPLEX_FULL)
3934                         val16 |= 0x0100;
3935
3936                 elink_cl45_write(sc, phy, MDIO_WC_DEVAD,
3937                                  MDIO_WC_REG_COMBO_IEEE0_MIICTRL, val16);
3938
3939                 PMD_DRV_LOG(DEBUG, "set SGMII force speed %d",
3940                             phy->req_line_speed);
3941                 elink_cl45_read(sc, phy, MDIO_WC_DEVAD,
3942                                 MDIO_WC_REG_COMBO_IEEE0_MIICTRL, &val16);
3943                 PMD_DRV_LOG(DEBUG, "  (readback) %x", val16);
3944         }
3945
3946         /* SGMII Slave mode and disable signal detect */
3947         elink_cl45_read(sc, phy, MDIO_WC_DEVAD,
3948                         MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X1, &digctrl_kx1);
3949         if (fiber_mode)
3950                 digctrl_kx1 = 1;
3951         else
3952                 digctrl_kx1 &= 0xff4a;
3953
3954         elink_cl45_write(sc, phy, MDIO_WC_DEVAD,
3955                          MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X1, digctrl_kx1);
3956
3957         /* Turn off parallel detect */
3958         elink_cl45_read(sc, phy, MDIO_WC_DEVAD,
3959                         MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2, &digctrl_kx2);
3960         elink_cl45_write(sc, phy, MDIO_WC_DEVAD,
3961                          MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2,
3962                          (digctrl_kx2 & ~(1 << 2)));
3963
3964         /* Re-enable parallel detect */
3965         elink_cl45_write(sc, phy, MDIO_WC_DEVAD,
3966                          MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2,
3967                          (digctrl_kx2 | (1 << 2)));
3968
3969         /* Enable autodet */
3970         elink_cl45_write(sc, phy, MDIO_WC_DEVAD,
3971                          MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X1,
3972                          (digctrl_kx1 | 0x10));
3973 }
3974
3975 static void elink_warpcore_reset_lane(struct bnx2x_softc *sc,
3976                                       struct elink_phy *phy, uint8_t reset)
3977 {
3978         uint16_t val;
3979         /* Take lane out of reset after configuration is finished */
3980         elink_cl45_read(sc, phy, MDIO_WC_DEVAD,
3981                         MDIO_WC_REG_DIGITAL5_MISC6, &val);
3982         if (reset)
3983                 val |= 0xC000;
3984         else
3985                 val &= 0x3FFF;
3986         elink_cl45_write(sc, phy, MDIO_WC_DEVAD,
3987                          MDIO_WC_REG_DIGITAL5_MISC6, val);
3988         elink_cl45_read(sc, phy, MDIO_WC_DEVAD,
3989                         MDIO_WC_REG_DIGITAL5_MISC6, &val);
3990 }
3991
3992 /* Clear SFI/XFI link settings registers */
3993 static void elink_warpcore_clear_regs(struct elink_phy *phy,
3994                                       struct elink_params *params,
3995                                       uint16_t lane)
3996 {
3997         struct bnx2x_softc *sc = params->sc;
3998         uint16_t i;
3999         static struct elink_reg_set wc_regs[] = {
4000                 {MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0},
4001                 {MDIO_WC_DEVAD, MDIO_WC_REG_FX100_CTRL1, 0x014a},
4002                 {MDIO_WC_DEVAD, MDIO_WC_REG_FX100_CTRL3, 0x0800},
4003                 {MDIO_WC_DEVAD, MDIO_WC_REG_DIGITAL4_MISC3, 0x8008},
4004                 {MDIO_WC_DEVAD, MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X1,
4005                  0x0195},
4006                 {MDIO_WC_DEVAD, MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2,
4007                  0x0007},
4008                 {MDIO_WC_DEVAD, MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X3,
4009                  0x0002},
4010                 {MDIO_WC_DEVAD, MDIO_WC_REG_SERDESDIGITAL_MISC1, 0x6000},
4011                 {MDIO_WC_DEVAD, MDIO_WC_REG_TX_FIR_TAP, 0x0000},
4012                 {MDIO_WC_DEVAD, MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x2040},
4013                 {MDIO_WC_DEVAD, MDIO_WC_REG_COMBO_IEEE0_MIICTRL, 0x0140}
4014         };
4015         /* Set XFI clock comp as default. */
4016         elink_cl45_read_or_write(sc, phy, MDIO_WC_DEVAD,
4017                                  MDIO_WC_REG_RX66_CONTROL, (3 << 13));
4018
4019         for (i = 0; i < ARRAY_SIZE(wc_regs); i++)
4020                 elink_cl45_write(sc, phy, wc_regs[i].devad, wc_regs[i].reg,
4021                                  wc_regs[i].val);
4022
4023         lane = elink_get_warpcore_lane(params);
4024         elink_cl45_write(sc, phy, MDIO_WC_DEVAD,
4025                          MDIO_WC_REG_TX0_TX_DRIVER + 0x10 * lane, 0x0990);
4026
4027 }
4028
4029 static elink_status_t elink_get_mod_abs_int_cfg(struct bnx2x_softc *sc,
4030                                                 uint32_t shmem_base,
4031                                                 uint8_t port,
4032                                                 uint8_t * gpio_num,
4033                                                 uint8_t * gpio_port)
4034 {
4035         uint32_t cfg_pin;
4036         *gpio_num = 0;
4037         *gpio_port = 0;
4038         if (CHIP_IS_E3(sc)) {
4039                 cfg_pin = (REG_RD(sc, shmem_base +
4040                                   offsetof(struct shmem_region,
4041                                            dev_info.port_hw_config[port].
4042                                            e3_sfp_ctrl)) &
4043                            PORT_HW_CFG_E3_MOD_ABS_MASK) >>
4044                     PORT_HW_CFG_E3_MOD_ABS_SHIFT;
4045
4046                 /* Should not happen. This function called upon interrupt
4047                  * triggered by GPIO ( since EPIO can only generate interrupts
4048                  * to MCP).
4049                  * So if this function was called and none of the GPIOs was set,
4050                  * it means the shit hit the fan.
4051                  */
4052                 if ((cfg_pin < PIN_CFG_GPIO0_P0) ||
4053                     (cfg_pin > PIN_CFG_GPIO3_P1)) {
4054                         PMD_DRV_LOG(DEBUG,
4055                                     "No cfg pin %x for module detect indication",
4056                                     cfg_pin);
4057                         return ELINK_STATUS_ERROR;
4058                 }
4059
4060                 *gpio_num = (cfg_pin - PIN_CFG_GPIO0_P0) & 0x3;
4061                 *gpio_port = (cfg_pin - PIN_CFG_GPIO0_P0) >> 2;
4062         } else {
4063                 *gpio_num = MISC_REGISTERS_GPIO_3;
4064                 *gpio_port = port;
4065         }
4066
4067         return ELINK_STATUS_OK;
4068 }
4069
4070 static int elink_is_sfp_module_plugged(struct elink_params *params)
4071 {
4072         struct bnx2x_softc *sc = params->sc;
4073         uint8_t gpio_num, gpio_port;
4074         uint32_t gpio_val;
4075         if (elink_get_mod_abs_int_cfg(sc,
4076                                       params->shmem_base, params->port,
4077                                       &gpio_num, &gpio_port) != ELINK_STATUS_OK)
4078                 return 0;
4079         gpio_val = elink_cb_gpio_read(sc, gpio_num, gpio_port);
4080
4081         /* Call the handling function in case module is detected */
4082         if (gpio_val == 0)
4083                 return 1;
4084         else
4085                 return 0;
4086 }
4087
4088 static int elink_warpcore_get_sigdet(struct elink_phy *phy,
4089                                      struct elink_params *params)
4090 {
4091         uint16_t gp2_status_reg0, lane;
4092         struct bnx2x_softc *sc = params->sc;
4093
4094         lane = elink_get_warpcore_lane(params);
4095
4096         elink_cl45_read(sc, phy, MDIO_WC_DEVAD, MDIO_WC_REG_GP2_STATUS_GP_2_0,
4097                         &gp2_status_reg0);
4098
4099         return (gp2_status_reg0 >> (8 + lane)) & 0x1;
4100 }
4101
4102 static void elink_warpcore_config_runtime(struct elink_phy *phy,
4103                                           struct elink_params *params,
4104                                           struct elink_vars *vars)
4105 {
4106         struct bnx2x_softc *sc = params->sc;
4107         uint32_t serdes_net_if;
4108         uint16_t gp_status1 = 0, lnkup = 0, lnkup_kr = 0;
4109
4110         vars->turn_to_run_wc_rt = vars->turn_to_run_wc_rt ? 0 : 1;
4111
4112         if (!vars->turn_to_run_wc_rt)
4113                 return;
4114
4115         if (vars->rx_tx_asic_rst) {
4116                 uint16_t lane = elink_get_warpcore_lane(params);
4117                 serdes_net_if = (REG_RD(sc, params->shmem_base +
4118                                         offsetof(struct shmem_region,
4119                                                  dev_info.port_hw_config
4120                                                  [params->port].
4121                                                  default_cfg)) &
4122                                  PORT_HW_CFG_NET_SERDES_IF_MASK);
4123
4124                 switch (serdes_net_if) {
4125                 case PORT_HW_CFG_NET_SERDES_IF_KR:
4126                         /* Do we get link yet? */
4127                         elink_cl45_read(sc, phy, MDIO_WC_DEVAD, 0x81d1,
4128                                         &gp_status1);
4129                         lnkup = (gp_status1 >> (8 + lane)) & 0x1;       /* 1G */
4130                         /*10G KR */
4131                         lnkup_kr = (gp_status1 >> (12 + lane)) & 0x1;
4132
4133                         if (lnkup_kr || lnkup) {
4134                                 vars->rx_tx_asic_rst = 0;
4135                         } else {
4136                                 /* Reset the lane to see if link comes up. */
4137                                 elink_warpcore_reset_lane(sc, phy, 1);
4138                                 elink_warpcore_reset_lane(sc, phy, 0);
4139
4140                                 /* Restart Autoneg */
4141                                 elink_cl45_write(sc, phy, MDIO_AN_DEVAD,
4142                                                  MDIO_WC_REG_IEEE0BLK_MIICNTL,
4143                                                  0x1200);
4144
4145                                 vars->rx_tx_asic_rst--;
4146                                 PMD_DRV_LOG(DEBUG, "0x%x retry left",
4147                                             vars->rx_tx_asic_rst);
4148                         }
4149                         break;
4150
4151                 default:
4152                         break;
4153                 }
4154
4155         }
4156         /*params->rx_tx_asic_rst */
4157 }
4158
4159 static void elink_warpcore_config_sfi(struct elink_phy *phy,
4160                                       struct elink_params *params)
4161 {
4162         uint16_t lane = elink_get_warpcore_lane(params);
4163
4164         elink_warpcore_clear_regs(phy, params, lane);
4165         if ((params->req_line_speed[ELINK_LINK_CONFIG_IDX(ELINK_INT_PHY)] ==
4166              ELINK_SPEED_10000) &&
4167             (phy->media_type != ELINK_ETH_PHY_SFP_1G_FIBER)) {
4168                 PMD_DRV_LOG(DEBUG, "Setting 10G SFI");
4169                 elink_warpcore_set_10G_XFI(phy, params, 0);
4170         } else {
4171                 PMD_DRV_LOG(DEBUG, "Setting 1G Fiber");
4172                 elink_warpcore_set_sgmii_speed(phy, params, 1, 0);
4173         }
4174 }
4175
4176 static void elink_sfp_e3_set_transmitter(struct elink_params *params,
4177                                          struct elink_phy *phy, uint8_t tx_en)
4178 {
4179         struct bnx2x_softc *sc = params->sc;
4180         uint32_t cfg_pin;
4181         uint8_t port = params->port;
4182
4183         cfg_pin = REG_RD(sc, params->shmem_base +
4184                          offsetof(struct shmem_region,
4185                                   dev_info.port_hw_config[port].e3_sfp_ctrl)) &
4186             PORT_HW_CFG_E3_TX_LASER_MASK;
4187         /* Set the !tx_en since this pin is DISABLE_TX_LASER */
4188         PMD_DRV_LOG(DEBUG, "Setting WC TX to %d", tx_en);
4189
4190         /* For 20G, the expected pin to be used is 3 pins after the current */
4191         elink_set_cfg_pin(sc, cfg_pin, tx_en ^ 1);
4192         if (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_20G)
4193                 elink_set_cfg_pin(sc, cfg_pin + 3, tx_en ^ 1);
4194 }
4195
4196 static void elink_warpcore_config_init(struct elink_phy *phy,
4197                                        struct elink_params *params,
4198                                        struct elink_vars *vars)
4199 {
4200         struct bnx2x_softc *sc = params->sc;
4201         uint32_t serdes_net_if;
4202         uint8_t fiber_mode;
4203         uint16_t lane = elink_get_warpcore_lane(params);
4204         serdes_net_if = (REG_RD(sc, params->shmem_base +
4205                                 offsetof(struct shmem_region,
4206                                          dev_info.port_hw_config[params->port].
4207                                          default_cfg)) &
4208                          PORT_HW_CFG_NET_SERDES_IF_MASK);
4209         PMD_DRV_LOG(DEBUG,
4210                     "Begin Warpcore init, link_speed %d, "
4211                     "serdes_net_if = 0x%x", vars->line_speed, serdes_net_if);
4212         elink_set_aer_mmd(params, phy);
4213         elink_warpcore_reset_lane(sc, phy, 1);
4214         vars->phy_flags |= PHY_XGXS_FLAG;
4215         if ((serdes_net_if == PORT_HW_CFG_NET_SERDES_IF_SGMII) ||
4216             (phy->req_line_speed &&
4217              ((phy->req_line_speed == ELINK_SPEED_100) ||
4218               (phy->req_line_speed == ELINK_SPEED_10)))) {
4219                 vars->phy_flags |= PHY_SGMII_FLAG;
4220                 PMD_DRV_LOG(DEBUG, "Setting SGMII mode");
4221                 elink_warpcore_clear_regs(phy, params, lane);
4222                 elink_warpcore_set_sgmii_speed(phy, params, 0, 1);
4223         } else {
4224                 switch (serdes_net_if) {
4225                 case PORT_HW_CFG_NET_SERDES_IF_KR:
4226                         /* Enable KR Auto Neg */
4227                         if (params->loopback_mode != ELINK_LOOPBACK_EXT)
4228                                 elink_warpcore_enable_AN_KR(phy, params, vars);
4229                         else {
4230                                 PMD_DRV_LOG(DEBUG, "Setting KR 10G-Force");
4231                                 elink_warpcore_set_10G_KR(phy, params);
4232                         }
4233                         break;
4234
4235                 case PORT_HW_CFG_NET_SERDES_IF_XFI:
4236                         elink_warpcore_clear_regs(phy, params, lane);
4237                         if (vars->line_speed == ELINK_SPEED_10000) {
4238                                 PMD_DRV_LOG(DEBUG, "Setting 10G XFI");
4239                                 elink_warpcore_set_10G_XFI(phy, params, 1);
4240                         } else {
4241                                 if (ELINK_SINGLE_MEDIA_DIRECT(params)) {
4242                                         PMD_DRV_LOG(DEBUG, "1G Fiber");
4243                                         fiber_mode = 1;
4244                                 } else {
4245                                         PMD_DRV_LOG(DEBUG, "10/100/1G SGMII");
4246                                         fiber_mode = 0;
4247                                 }
4248                                 elink_warpcore_set_sgmii_speed(phy,
4249                                                                params,
4250                                                                fiber_mode, 0);
4251                         }
4252
4253                         break;
4254
4255                 case PORT_HW_CFG_NET_SERDES_IF_SFI:
4256                         /* Issue Module detection if module is plugged, or
4257                          * enabled transmitter to avoid current leakage in case
4258                          * no module is connected
4259                          */
4260                         if ((params->loopback_mode == ELINK_LOOPBACK_NONE) ||
4261                             (params->loopback_mode == ELINK_LOOPBACK_EXT)) {
4262                                 if (elink_is_sfp_module_plugged(params))
4263                                         elink_sfp_module_detection(phy, params);
4264                                 else
4265                                         elink_sfp_e3_set_transmitter(params,
4266                                                                      phy, 1);
4267                         }
4268
4269                         elink_warpcore_config_sfi(phy, params);
4270                         break;
4271
4272                 case PORT_HW_CFG_NET_SERDES_IF_DXGXS:
4273                         if (vars->line_speed != ELINK_SPEED_20000) {
4274                                 PMD_DRV_LOG(DEBUG, "Speed not supported yet");
4275                                 return;
4276                         }
4277                         PMD_DRV_LOG(DEBUG, "Setting 20G DXGXS");
4278                         elink_warpcore_set_20G_DXGXS(sc, phy, lane);
4279                         /* Issue Module detection */
4280
4281                         elink_sfp_module_detection(phy, params);
4282                         break;
4283                 case PORT_HW_CFG_NET_SERDES_IF_KR2:
4284                         if (!params->loopback_mode) {
4285                                 elink_warpcore_enable_AN_KR(phy, params, vars);
4286                         } else {
4287                                 PMD_DRV_LOG(DEBUG, "Setting KR 20G-Force");
4288                                 elink_warpcore_set_20G_force_KR2(phy, params);
4289                         }
4290                         break;
4291                 default:
4292                         PMD_DRV_LOG(DEBUG,
4293                                     "Unsupported Serdes Net Interface 0x%x",
4294                                     serdes_net_if);
4295                         return;
4296                 }
4297         }
4298
4299         /* Take lane out of reset after configuration is finished */
4300         elink_warpcore_reset_lane(sc, phy, 0);
4301         PMD_DRV_LOG(DEBUG, "Exit config init");
4302 }
4303
4304 static void elink_warpcore_link_reset(struct elink_phy *phy,
4305                                       struct elink_params *params)
4306 {
4307         struct bnx2x_softc *sc = params->sc;
4308         uint16_t val16, lane;
4309         elink_sfp_e3_set_transmitter(params, phy, 0);
4310         elink_set_mdio_emac_per_phy(sc, params);
4311         elink_set_aer_mmd(params, phy);
4312         /* Global register */
4313         elink_warpcore_reset_lane(sc, phy, 1);
4314
4315         /* Clear loopback settings (if any) */
4316         /* 10G & 20G */
4317         elink_cl45_read_and_write(sc, phy, MDIO_WC_DEVAD,
4318                                   MDIO_WC_REG_COMBO_IEEE0_MIICTRL, 0xBFFF);
4319
4320         elink_cl45_read_and_write(sc, phy, MDIO_WC_DEVAD,
4321                                   MDIO_WC_REG_IEEE0BLK_MIICNTL, 0xfffe);
4322
4323         /* Update those 1-copy registers */
4324         CL22_WR_OVER_CL45(sc, phy, MDIO_REG_BANK_AER_BLOCK,
4325                           MDIO_AER_BLOCK_AER_REG, 0);
4326         /* Enable 1G MDIO (1-copy) */
4327         elink_cl45_read_and_write(sc, phy, MDIO_WC_DEVAD,
4328                                   MDIO_WC_REG_XGXSBLK0_XGXSCONTROL, ~0x10);
4329
4330         elink_cl45_read_and_write(sc, phy, MDIO_WC_DEVAD,
4331                                   MDIO_WC_REG_XGXSBLK1_LANECTRL2, 0xff00);
4332         lane = elink_get_warpcore_lane(params);
4333         /* Disable CL36 PCS Tx */
4334         elink_cl45_read(sc, phy, MDIO_WC_DEVAD,
4335                         MDIO_WC_REG_XGXSBLK1_LANECTRL0, &val16);
4336         val16 |= (0x11 << lane);
4337         if (phy->flags & ELINK_FLAGS_WC_DUAL_MODE)
4338                 val16 |= (0x22 << lane);
4339         elink_cl45_write(sc, phy, MDIO_WC_DEVAD,
4340                          MDIO_WC_REG_XGXSBLK1_LANECTRL0, val16);
4341
4342         elink_cl45_read(sc, phy, MDIO_WC_DEVAD,
4343                         MDIO_WC_REG_XGXSBLK1_LANECTRL1, &val16);
4344         val16 &= ~(0x0303 << (lane << 1));
4345         val16 |= (0x0101 << (lane << 1));
4346         if (phy->flags & ELINK_FLAGS_WC_DUAL_MODE) {
4347                 val16 &= ~(0x0c0c << (lane << 1));
4348                 val16 |= (0x0404 << (lane << 1));
4349         }
4350
4351         elink_cl45_write(sc, phy, MDIO_WC_DEVAD,
4352                          MDIO_WC_REG_XGXSBLK1_LANECTRL1, val16);
4353         /* Restore AER */
4354         elink_set_aer_mmd(params, phy);
4355
4356 }
4357
4358 static void elink_set_warpcore_loopback(struct elink_phy *phy,
4359                                         struct elink_params *params)
4360 {
4361         struct bnx2x_softc *sc = params->sc;
4362         uint16_t val16;
4363         uint32_t lane;
4364         PMD_DRV_LOG(DEBUG, "Setting Warpcore loopback type %x, speed %d",
4365                     params->loopback_mode, phy->req_line_speed);
4366
4367         if (phy->req_line_speed < ELINK_SPEED_10000 ||
4368             phy->supported & ELINK_SUPPORTED_20000baseKR2_Full) {
4369                 /* 10/100/1000/20G-KR2 */
4370
4371                 /* Update those 1-copy registers */
4372                 CL22_WR_OVER_CL45(sc, phy, MDIO_REG_BANK_AER_BLOCK,
4373                                   MDIO_AER_BLOCK_AER_REG, 0);
4374                 /* Enable 1G MDIO (1-copy) */
4375                 elink_cl45_read_or_write(sc, phy, MDIO_WC_DEVAD,
4376                                          MDIO_WC_REG_XGXSBLK0_XGXSCONTROL,
4377                                          0x10);
4378                 /* Set 1G loopback based on lane (1-copy) */
4379                 lane = elink_get_warpcore_lane(params);
4380                 elink_cl45_read(sc, phy, MDIO_WC_DEVAD,
4381                                 MDIO_WC_REG_XGXSBLK1_LANECTRL2, &val16);
4382                 val16 |= (1 << lane);
4383                 if (phy->flags & ELINK_FLAGS_WC_DUAL_MODE)
4384                         val16 |= (2 << lane);
4385                 elink_cl45_write(sc, phy, MDIO_WC_DEVAD,
4386                                  MDIO_WC_REG_XGXSBLK1_LANECTRL2, val16);
4387
4388                 /* Switch back to 4-copy registers */
4389                 elink_set_aer_mmd(params, phy);
4390         } else {
4391                 /* 10G / 20G-DXGXS */
4392                 elink_cl45_read_or_write(sc, phy, MDIO_WC_DEVAD,
4393                                          MDIO_WC_REG_COMBO_IEEE0_MIICTRL,
4394                                          0x4000);
4395                 elink_cl45_read_or_write(sc, phy, MDIO_WC_DEVAD,
4396                                          MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x1);
4397         }
4398 }
4399
4400 static void elink_sync_link(struct elink_params *params,
4401                             struct elink_vars *vars)
4402 {
4403         struct bnx2x_softc *sc = params->sc;
4404         uint8_t link_10g_plus;
4405         if (vars->link_status & LINK_STATUS_PHYSICAL_LINK_FLAG)
4406                 vars->phy_flags |= PHY_PHYSICAL_LINK_FLAG;
4407         vars->link_up = (vars->link_status & LINK_STATUS_LINK_UP);
4408         if (vars->link_up) {
4409                 PMD_DRV_LOG(DEBUG, "phy link up");
4410
4411                 vars->phy_link_up = 1;
4412                 vars->duplex = DUPLEX_FULL;
4413                 switch (vars->link_status & LINK_STATUS_SPEED_AND_DUPLEX_MASK) {
4414                 case ELINK_LINK_10THD:
4415                         vars->duplex = DUPLEX_HALF;
4416                         /* Fall thru */
4417                 case ELINK_LINK_10TFD:
4418                         vars->line_speed = ELINK_SPEED_10;
4419                         break;
4420
4421                 case ELINK_LINK_100TXHD:
4422                         vars->duplex = DUPLEX_HALF;
4423                         /* Fall thru */
4424                 case ELINK_LINK_100T4:
4425                 case ELINK_LINK_100TXFD:
4426                         vars->line_speed = ELINK_SPEED_100;
4427                         break;
4428
4429                 case ELINK_LINK_1000THD:
4430                         vars->duplex = DUPLEX_HALF;
4431                         /* Fall thru */
4432                 case ELINK_LINK_1000TFD:
4433                         vars->line_speed = ELINK_SPEED_1000;
4434                         break;
4435
4436                 case ELINK_LINK_2500THD:
4437                         vars->duplex = DUPLEX_HALF;
4438                         /* Fall thru */
4439                 case ELINK_LINK_2500TFD:
4440                         vars->line_speed = ELINK_SPEED_2500;
4441                         break;
4442
4443                 case ELINK_LINK_10GTFD:
4444                         vars->line_speed = ELINK_SPEED_10000;
4445                         break;
4446                 case ELINK_LINK_20GTFD:
4447                         vars->line_speed = ELINK_SPEED_20000;
4448                         break;
4449                 default:
4450                         break;
4451                 }
4452                 vars->flow_ctrl = 0;
4453                 if (vars->link_status & LINK_STATUS_TX_FLOW_CONTROL_ENABLED)
4454                         vars->flow_ctrl |= ELINK_FLOW_CTRL_TX;
4455
4456                 if (vars->link_status & LINK_STATUS_RX_FLOW_CONTROL_ENABLED)
4457                         vars->flow_ctrl |= ELINK_FLOW_CTRL_RX;
4458
4459                 if (!vars->flow_ctrl)
4460                         vars->flow_ctrl = ELINK_FLOW_CTRL_NONE;
4461
4462                 if (vars->line_speed &&
4463                     ((vars->line_speed == ELINK_SPEED_10) ||
4464                      (vars->line_speed == ELINK_SPEED_100))) {
4465                         vars->phy_flags |= PHY_SGMII_FLAG;
4466                 } else {
4467                         vars->phy_flags &= ~PHY_SGMII_FLAG;
4468                 }
4469                 if (vars->line_speed &&
4470                     USES_WARPCORE(sc) && (vars->line_speed == ELINK_SPEED_1000))
4471                         vars->phy_flags |= PHY_SGMII_FLAG;
4472                 /* Anything 10 and over uses the bmac */
4473                 link_10g_plus = (vars->line_speed >= ELINK_SPEED_10000);
4474
4475                 if (link_10g_plus) {
4476                         if (USES_WARPCORE(sc))
4477                                 vars->mac_type = ELINK_MAC_TYPE_XMAC;
4478                         else
4479                                 vars->mac_type = ELINK_MAC_TYPE_BMAC;
4480                 } else {
4481                         if (USES_WARPCORE(sc))
4482                                 vars->mac_type = ELINK_MAC_TYPE_UMAC;
4483                         else
4484                                 vars->mac_type = ELINK_MAC_TYPE_EMAC;
4485                 }
4486         } else {                /* Link down */
4487                 PMD_DRV_LOG(DEBUG, "phy link down");
4488
4489                 vars->phy_link_up = 0;
4490
4491                 vars->line_speed = 0;
4492                 vars->duplex = DUPLEX_FULL;
4493                 vars->flow_ctrl = ELINK_FLOW_CTRL_NONE;
4494
4495                 /* Indicate no mac active */
4496                 vars->mac_type = ELINK_MAC_TYPE_NONE;
4497                 if (vars->link_status & LINK_STATUS_PHYSICAL_LINK_FLAG)
4498                         vars->phy_flags |= PHY_HALF_OPEN_CONN_FLAG;
4499                 if (vars->link_status & LINK_STATUS_SFP_TX_FAULT)
4500                         vars->phy_flags |= PHY_SFP_TX_FAULT_FLAG;
4501         }
4502 }
4503
4504 void elink_link_status_update(struct elink_params *params,
4505                               struct elink_vars *vars)
4506 {
4507         struct bnx2x_softc *sc = params->sc;
4508         uint8_t port = params->port;
4509         uint32_t sync_offset, media_types;
4510         /* Update PHY configuration */
4511         set_phy_vars(params, vars);
4512
4513         vars->link_status = REG_RD(sc, params->shmem_base +
4514                                    offsetof(struct shmem_region,
4515                                             port_mb[port].link_status));
4516
4517         /* Force link UP in non LOOPBACK_EXT loopback mode(s) */
4518         if (params->loopback_mode != ELINK_LOOPBACK_NONE &&
4519             params->loopback_mode != ELINK_LOOPBACK_EXT)
4520                 vars->link_status |= LINK_STATUS_LINK_UP;
4521
4522         if (elink_eee_has_cap(params))
4523                 vars->eee_status = REG_RD(sc, params->shmem2_base +
4524                                           offsetof(struct shmem2_region,
4525                                                    eee_status[params->port]));
4526
4527         vars->phy_flags = PHY_XGXS_FLAG;
4528         elink_sync_link(params, vars);
4529         /* Sync media type */
4530         sync_offset = params->shmem_base +
4531             offsetof(struct shmem_region,
4532                      dev_info.port_hw_config[port].media_type);
4533         media_types = REG_RD(sc, sync_offset);
4534
4535         params->phy[ELINK_INT_PHY].media_type =
4536             (media_types & PORT_HW_CFG_MEDIA_TYPE_PHY0_MASK) >>
4537             PORT_HW_CFG_MEDIA_TYPE_PHY0_SHIFT;
4538         params->phy[ELINK_EXT_PHY1].media_type =
4539             (media_types & PORT_HW_CFG_MEDIA_TYPE_PHY1_MASK) >>
4540             PORT_HW_CFG_MEDIA_TYPE_PHY1_SHIFT;
4541         params->phy[ELINK_EXT_PHY2].media_type =
4542             (media_types & PORT_HW_CFG_MEDIA_TYPE_PHY2_MASK) >>
4543             PORT_HW_CFG_MEDIA_TYPE_PHY2_SHIFT;
4544         PMD_DRV_LOG(DEBUG, "media_types = 0x%x", media_types);
4545
4546         /* Sync AEU offset */
4547         sync_offset = params->shmem_base +
4548             offsetof(struct shmem_region,
4549                      dev_info.port_hw_config[port].aeu_int_mask);
4550
4551         vars->aeu_int_mask = REG_RD(sc, sync_offset);
4552
4553         /* Sync PFC status */
4554         if (vars->link_status & LINK_STATUS_PFC_ENABLED)
4555                 params->feature_config_flags |=
4556                     ELINK_FEATURE_CONFIG_PFC_ENABLED;
4557         else
4558                 params->feature_config_flags &=
4559                     ~ELINK_FEATURE_CONFIG_PFC_ENABLED;
4560
4561         if (SHMEM2_HAS(sc, link_attr_sync))
4562                 vars->link_attr_sync = SHMEM2_RD(sc,
4563                                                  link_attr_sync[params->port]);
4564
4565         PMD_DRV_LOG(DEBUG, "link_status 0x%x  phy_link_up %x int_mask 0x%x",
4566                     vars->link_status, vars->phy_link_up, vars->aeu_int_mask);
4567         PMD_DRV_LOG(DEBUG, "line_speed %x  duplex %x  flow_ctrl 0x%x",
4568                     vars->line_speed, vars->duplex, vars->flow_ctrl);
4569 }
4570
4571 static void elink_set_master_ln(struct elink_params *params,
4572                                 struct elink_phy *phy)
4573 {
4574         struct bnx2x_softc *sc = params->sc;
4575         uint16_t new_master_ln, ser_lane;
4576         ser_lane = ((params->lane_config &
4577                      PORT_HW_CFG_LANE_SWAP_CFG_MASTER_MASK) >>
4578                     PORT_HW_CFG_LANE_SWAP_CFG_MASTER_SHIFT);
4579
4580         /* Set the master_ln for AN */
4581         CL22_RD_OVER_CL45(sc, phy,
4582                           MDIO_REG_BANK_XGXS_BLOCK2,
4583                           MDIO_XGXS_BLOCK2_TEST_MODE_LANE, &new_master_ln);
4584
4585         CL22_WR_OVER_CL45(sc, phy,
4586                           MDIO_REG_BANK_XGXS_BLOCK2,
4587                           MDIO_XGXS_BLOCK2_TEST_MODE_LANE,
4588                           (new_master_ln | ser_lane));
4589 }
4590
4591 static elink_status_t elink_reset_unicore(struct elink_params *params,
4592                                           struct elink_phy *phy,
4593                                           uint8_t set_serdes)
4594 {
4595         struct bnx2x_softc *sc = params->sc;
4596         uint16_t mii_control;
4597         uint16_t i;
4598         CL22_RD_OVER_CL45(sc, phy,
4599                           MDIO_REG_BANK_COMBO_IEEE0,
4600                           MDIO_COMBO_IEEE0_MII_CONTROL, &mii_control);
4601
4602         /* Reset the unicore */
4603         CL22_WR_OVER_CL45(sc, phy,
4604                           MDIO_REG_BANK_COMBO_IEEE0,
4605                           MDIO_COMBO_IEEE0_MII_CONTROL,
4606                           (mii_control | MDIO_COMBO_IEEO_MII_CONTROL_RESET));
4607         if (set_serdes)
4608                 elink_set_serdes_access(sc, params->port);
4609
4610         /* Wait for the reset to self clear */
4611         for (i = 0; i < ELINK_MDIO_ACCESS_TIMEOUT; i++) {
4612                 DELAY(5);
4613
4614                 /* The reset erased the previous bank value */
4615                 CL22_RD_OVER_CL45(sc, phy,
4616                                   MDIO_REG_BANK_COMBO_IEEE0,
4617                                   MDIO_COMBO_IEEE0_MII_CONTROL, &mii_control);
4618
4619                 if (!(mii_control & MDIO_COMBO_IEEO_MII_CONTROL_RESET)) {
4620                         DELAY(5);
4621                         return ELINK_STATUS_OK;
4622                 }
4623         }
4624
4625         elink_cb_event_log(sc, ELINK_LOG_ID_PHY_UNINITIALIZED, params->port);   // "Warning: PHY was not initialized,"
4626         // " Port %d",
4627
4628         PMD_DRV_LOG(DEBUG, "BUG! XGXS is still in reset!");
4629         return ELINK_STATUS_ERROR;
4630
4631 }
4632
4633 static void elink_set_swap_lanes(struct elink_params *params,
4634                                  struct elink_phy *phy)
4635 {
4636         struct bnx2x_softc *sc = params->sc;
4637         /* Each two bits represents a lane number:
4638          * No swap is 0123 => 0x1b no need to enable the swap
4639          */
4640         uint16_t rx_lane_swap, tx_lane_swap;
4641
4642         rx_lane_swap = ((params->lane_config &
4643                          PORT_HW_CFG_LANE_SWAP_CFG_RX_MASK) >>
4644                         PORT_HW_CFG_LANE_SWAP_CFG_RX_SHIFT);
4645         tx_lane_swap = ((params->lane_config &
4646                          PORT_HW_CFG_LANE_SWAP_CFG_TX_MASK) >>
4647                         PORT_HW_CFG_LANE_SWAP_CFG_TX_SHIFT);
4648
4649         if (rx_lane_swap != 0x1b) {
4650                 CL22_WR_OVER_CL45(sc, phy,
4651                                   MDIO_REG_BANK_XGXS_BLOCK2,
4652                                   MDIO_XGXS_BLOCK2_RX_LN_SWAP,
4653                                   (rx_lane_swap |
4654                                    MDIO_XGXS_BLOCK2_RX_LN_SWAP_ENABLE |
4655                                    MDIO_XGXS_BLOCK2_RX_LN_SWAP_FORCE_ENABLE));
4656         } else {
4657                 CL22_WR_OVER_CL45(sc, phy,
4658                                   MDIO_REG_BANK_XGXS_BLOCK2,
4659                                   MDIO_XGXS_BLOCK2_RX_LN_SWAP, 0);
4660         }
4661
4662         if (tx_lane_swap != 0x1b) {
4663                 CL22_WR_OVER_CL45(sc, phy,
4664                                   MDIO_REG_BANK_XGXS_BLOCK2,
4665                                   MDIO_XGXS_BLOCK2_TX_LN_SWAP,
4666                                   (tx_lane_swap |
4667                                    MDIO_XGXS_BLOCK2_TX_LN_SWAP_ENABLE));
4668         } else {
4669                 CL22_WR_OVER_CL45(sc, phy,
4670                                   MDIO_REG_BANK_XGXS_BLOCK2,
4671                                   MDIO_XGXS_BLOCK2_TX_LN_SWAP, 0);
4672         }
4673 }
4674
4675 static void elink_set_parallel_detection(struct elink_phy *phy,
4676                                          struct elink_params *params)
4677 {
4678         struct bnx2x_softc *sc = params->sc;
4679         uint16_t control2;
4680         CL22_RD_OVER_CL45(sc, phy,
4681                           MDIO_REG_BANK_SERDES_DIGITAL,
4682                           MDIO_SERDES_DIGITAL_A_1000X_CONTROL2, &control2);
4683         if (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)
4684                 control2 |= MDIO_SERDES_DIGITAL_A_1000X_CONTROL2_PRL_DT_EN;
4685         else
4686                 control2 &= ~MDIO_SERDES_DIGITAL_A_1000X_CONTROL2_PRL_DT_EN;
4687         PMD_DRV_LOG(DEBUG, "phy->speed_cap_mask = 0x%x, control2 = 0x%x",
4688                     phy->speed_cap_mask, control2);
4689         CL22_WR_OVER_CL45(sc, phy,
4690                           MDIO_REG_BANK_SERDES_DIGITAL,
4691                           MDIO_SERDES_DIGITAL_A_1000X_CONTROL2, control2);
4692
4693         if ((phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT) &&
4694             (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) {
4695                 PMD_DRV_LOG(DEBUG, "XGXS");
4696
4697                 CL22_WR_OVER_CL45(sc, phy,
4698                                   MDIO_REG_BANK_10G_PARALLEL_DETECT,
4699                                   MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_LINK,
4700                                   MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_LINK_CNT);
4701
4702                 CL22_RD_OVER_CL45(sc, phy,
4703                                   MDIO_REG_BANK_10G_PARALLEL_DETECT,
4704                                   MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_CONTROL,
4705                                   &control2);
4706
4707                 control2 |=
4708                     MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_CONTROL_PARDET10G_EN;
4709
4710                 CL22_WR_OVER_CL45(sc, phy,
4711                                   MDIO_REG_BANK_10G_PARALLEL_DETECT,
4712                                   MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_CONTROL,
4713                                   control2);
4714
4715                 /* Disable parallel detection of HiG */
4716                 CL22_WR_OVER_CL45(sc, phy,
4717                                   MDIO_REG_BANK_XGXS_BLOCK2,
4718                                   MDIO_XGXS_BLOCK2_UNICORE_MODE_10G,
4719                                   MDIO_XGXS_BLOCK2_UNICORE_MODE_10G_CX4_XGXS |
4720                                   MDIO_XGXS_BLOCK2_UNICORE_MODE_10G_HIGIG_XGXS);
4721         }
4722 }
4723
4724 static void elink_set_autoneg(struct elink_phy *phy,
4725                               struct elink_params *params,
4726                               struct elink_vars *vars, uint8_t enable_cl73)
4727 {
4728         struct bnx2x_softc *sc = params->sc;
4729         uint16_t reg_val;
4730
4731         /* CL37 Autoneg */
4732         CL22_RD_OVER_CL45(sc, phy,
4733                           MDIO_REG_BANK_COMBO_IEEE0,
4734                           MDIO_COMBO_IEEE0_MII_CONTROL, &reg_val);
4735
4736         /* CL37 Autoneg Enabled */
4737         if (vars->line_speed == ELINK_SPEED_AUTO_NEG)
4738                 reg_val |= MDIO_COMBO_IEEO_MII_CONTROL_AN_EN;
4739         else                    /* CL37 Autoneg Disabled */
4740                 reg_val &= ~(MDIO_COMBO_IEEO_MII_CONTROL_AN_EN |
4741                              MDIO_COMBO_IEEO_MII_CONTROL_RESTART_AN);
4742
4743         CL22_WR_OVER_CL45(sc, phy,
4744                           MDIO_REG_BANK_COMBO_IEEE0,
4745                           MDIO_COMBO_IEEE0_MII_CONTROL, reg_val);
4746
4747         /* Enable/Disable Autodetection */
4748
4749         CL22_RD_OVER_CL45(sc, phy,
4750                           MDIO_REG_BANK_SERDES_DIGITAL,
4751                           MDIO_SERDES_DIGITAL_A_1000X_CONTROL1, &reg_val);
4752         reg_val &= ~(MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_SIGNAL_DETECT_EN |
4753                      MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_INVERT_SIGNAL_DETECT);
4754         reg_val |= MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_FIBER_MODE;
4755         if (vars->line_speed == ELINK_SPEED_AUTO_NEG)
4756                 reg_val |= MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_AUTODET;
4757         else
4758                 reg_val &= ~MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_AUTODET;
4759
4760         CL22_WR_OVER_CL45(sc, phy,
4761                           MDIO_REG_BANK_SERDES_DIGITAL,
4762                           MDIO_SERDES_DIGITAL_A_1000X_CONTROL1, reg_val);
4763
4764         /* Enable TetonII and BAM autoneg */
4765         CL22_RD_OVER_CL45(sc, phy,
4766                           MDIO_REG_BANK_BAM_NEXT_PAGE,
4767                           MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL, &reg_val);
4768         if (vars->line_speed == ELINK_SPEED_AUTO_NEG) {
4769                 /* Enable BAM aneg Mode and TetonII aneg Mode */
4770                 reg_val |= (MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL_BAM_MODE |
4771                             MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL_TETON_AN);
4772         } else {
4773                 /* TetonII and BAM Autoneg Disabled */
4774                 reg_val &= ~(MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL_BAM_MODE |
4775                              MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL_TETON_AN);
4776         }
4777         CL22_WR_OVER_CL45(sc, phy,
4778                           MDIO_REG_BANK_BAM_NEXT_PAGE,
4779                           MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL, reg_val);
4780
4781         if (enable_cl73) {
4782                 /* Enable Cl73 FSM status bits */
4783                 CL22_WR_OVER_CL45(sc, phy,
4784                                   MDIO_REG_BANK_CL73_USERB0,
4785                                   MDIO_CL73_USERB0_CL73_UCTRL, 0xe);
4786
4787                 /* Enable BAM Station Manager */
4788                 CL22_WR_OVER_CL45(sc, phy,
4789                                   MDIO_REG_BANK_CL73_USERB0,
4790                                   MDIO_CL73_USERB0_CL73_BAM_CTRL1,
4791                                   MDIO_CL73_USERB0_CL73_BAM_CTRL1_BAM_EN |
4792                                   MDIO_CL73_USERB0_CL73_BAM_CTRL1_BAM_STATION_MNGR_EN
4793                                   |
4794                                   MDIO_CL73_USERB0_CL73_BAM_CTRL1_BAM_NP_AFTER_BP_EN);
4795
4796                 /* Advertise CL73 link speeds */
4797                 CL22_RD_OVER_CL45(sc, phy,
4798                                   MDIO_REG_BANK_CL73_IEEEB1,
4799                                   MDIO_CL73_IEEEB1_AN_ADV2, &reg_val);
4800                 if (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
4801                         reg_val |= MDIO_CL73_IEEEB1_AN_ADV2_ADVR_10G_KX4;
4802                 if (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)
4803                         reg_val |= MDIO_CL73_IEEEB1_AN_ADV2_ADVR_1000M_KX;
4804
4805                 CL22_WR_OVER_CL45(sc, phy,
4806                                   MDIO_REG_BANK_CL73_IEEEB1,
4807                                   MDIO_CL73_IEEEB1_AN_ADV2, reg_val);
4808
4809                 /* CL73 Autoneg Enabled */
4810                 reg_val = MDIO_CL73_IEEEB0_CL73_AN_CONTROL_AN_EN;
4811
4812         } else                  /* CL73 Autoneg Disabled */
4813                 reg_val = 0;
4814
4815         CL22_WR_OVER_CL45(sc, phy,
4816                           MDIO_REG_BANK_CL73_IEEEB0,
4817                           MDIO_CL73_IEEEB0_CL73_AN_CONTROL, reg_val);
4818 }
4819
4820 /* Program SerDes, forced speed */
4821 static void elink_program_serdes(struct elink_phy *phy,
4822                                  struct elink_params *params,
4823                                  struct elink_vars *vars)
4824 {
4825         struct bnx2x_softc *sc = params->sc;
4826         uint16_t reg_val;
4827
4828         /* Program duplex, disable autoneg and sgmii */
4829         CL22_RD_OVER_CL45(sc, phy,
4830                           MDIO_REG_BANK_COMBO_IEEE0,
4831                           MDIO_COMBO_IEEE0_MII_CONTROL, &reg_val);
4832         reg_val &= ~(MDIO_COMBO_IEEO_MII_CONTROL_FULL_DUPLEX |
4833                      MDIO_COMBO_IEEO_MII_CONTROL_AN_EN |
4834                      MDIO_COMBO_IEEO_MII_CONTROL_MAN_SGMII_SP_MASK);
4835         if (phy->req_duplex == DUPLEX_FULL)
4836                 reg_val |= MDIO_COMBO_IEEO_MII_CONTROL_FULL_DUPLEX;
4837         CL22_WR_OVER_CL45(sc, phy,
4838                           MDIO_REG_BANK_COMBO_IEEE0,
4839                           MDIO_COMBO_IEEE0_MII_CONTROL, reg_val);
4840
4841         /* Program speed
4842          *  - needed only if the speed is greater than 1G (2.5G or 10G)
4843          */
4844         CL22_RD_OVER_CL45(sc, phy,
4845                           MDIO_REG_BANK_SERDES_DIGITAL,
4846                           MDIO_SERDES_DIGITAL_MISC1, &reg_val);
4847         /* Clearing the speed value before setting the right speed */
4848         PMD_DRV_LOG(DEBUG, "MDIO_REG_BANK_SERDES_DIGITAL = 0x%x", reg_val);
4849
4850         reg_val &= ~(MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_MASK |
4851                      MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_SEL);
4852
4853         if (!((vars->line_speed == ELINK_SPEED_1000) ||
4854               (vars->line_speed == ELINK_SPEED_100) ||
4855               (vars->line_speed == ELINK_SPEED_10))) {
4856
4857                 reg_val |= (MDIO_SERDES_DIGITAL_MISC1_REFCLK_SEL_156_25M |
4858                             MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_SEL);
4859                 if (vars->line_speed == ELINK_SPEED_10000)
4860                         reg_val |=
4861                             MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_10G_CX4;
4862         }
4863
4864         CL22_WR_OVER_CL45(sc, phy,
4865                           MDIO_REG_BANK_SERDES_DIGITAL,
4866                           MDIO_SERDES_DIGITAL_MISC1, reg_val);
4867
4868 }
4869
4870 static void elink_set_brcm_cl37_advertisement(struct elink_phy *phy,
4871                                               struct elink_params *params)
4872 {
4873         struct bnx2x_softc *sc = params->sc;
4874         uint16_t val = 0;
4875
4876         /* Set extended capabilities */
4877         if (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G)
4878                 val |= MDIO_OVER_1G_UP1_2_5G;
4879         if (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
4880                 val |= MDIO_OVER_1G_UP1_10G;
4881         CL22_WR_OVER_CL45(sc, phy,
4882                           MDIO_REG_BANK_OVER_1G, MDIO_OVER_1G_UP1, val);
4883
4884         CL22_WR_OVER_CL45(sc, phy,
4885                           MDIO_REG_BANK_OVER_1G, MDIO_OVER_1G_UP3, 0x400);
4886 }
4887
4888 static void elink_set_ieee_aneg_advertisement(struct elink_phy *phy,
4889                                               struct elink_params *params,
4890                                               uint16_t ieee_fc)
4891 {
4892         struct bnx2x_softc *sc = params->sc;
4893         uint16_t val;
4894         /* For AN, we are always publishing full duplex */
4895
4896         CL22_WR_OVER_CL45(sc, phy,
4897                           MDIO_REG_BANK_COMBO_IEEE0,
4898                           MDIO_COMBO_IEEE0_AUTO_NEG_ADV, ieee_fc);
4899         CL22_RD_OVER_CL45(sc, phy,
4900                           MDIO_REG_BANK_CL73_IEEEB1,
4901                           MDIO_CL73_IEEEB1_AN_ADV1, &val);
4902         val &= ~MDIO_CL73_IEEEB1_AN_ADV1_PAUSE_BOTH;
4903         val |= ((ieee_fc << 3) & MDIO_CL73_IEEEB1_AN_ADV1_PAUSE_MASK);
4904         CL22_WR_OVER_CL45(sc, phy,
4905                           MDIO_REG_BANK_CL73_IEEEB1,
4906                           MDIO_CL73_IEEEB1_AN_ADV1, val);
4907 }
4908
4909 static void elink_restart_autoneg(struct elink_phy *phy,
4910                                   struct elink_params *params,
4911                                   uint8_t enable_cl73)
4912 {
4913         struct bnx2x_softc *sc = params->sc;
4914         uint16_t mii_control;
4915
4916         PMD_DRV_LOG(DEBUG, "elink_restart_autoneg");
4917         /* Enable and restart BAM/CL37 aneg */
4918
4919         if (enable_cl73) {
4920                 CL22_RD_OVER_CL45(sc, phy,
4921                                   MDIO_REG_BANK_CL73_IEEEB0,
4922                                   MDIO_CL73_IEEEB0_CL73_AN_CONTROL,
4923                                   &mii_control);
4924
4925                 CL22_WR_OVER_CL45(sc, phy,
4926                                   MDIO_REG_BANK_CL73_IEEEB0,
4927                                   MDIO_CL73_IEEEB0_CL73_AN_CONTROL,
4928                                   (mii_control |
4929                                    MDIO_CL73_IEEEB0_CL73_AN_CONTROL_AN_EN |
4930                                    MDIO_CL73_IEEEB0_CL73_AN_CONTROL_RESTART_AN));
4931         } else {
4932
4933                 CL22_RD_OVER_CL45(sc, phy,
4934                                   MDIO_REG_BANK_COMBO_IEEE0,
4935                                   MDIO_COMBO_IEEE0_MII_CONTROL, &mii_control);
4936                 PMD_DRV_LOG(DEBUG,
4937                             "elink_restart_autoneg mii_control before = 0x%x",
4938                             mii_control);
4939                 CL22_WR_OVER_CL45(sc, phy,
4940                                   MDIO_REG_BANK_COMBO_IEEE0,
4941                                   MDIO_COMBO_IEEE0_MII_CONTROL,
4942                                   (mii_control |
4943                                    MDIO_COMBO_IEEO_MII_CONTROL_AN_EN |
4944                                    MDIO_COMBO_IEEO_MII_CONTROL_RESTART_AN));
4945         }
4946 }
4947
4948 static void elink_initialize_sgmii_process(struct elink_phy *phy,
4949                                            struct elink_params *params,
4950                                            struct elink_vars *vars)
4951 {
4952         struct bnx2x_softc *sc = params->sc;
4953         uint16_t control1;
4954
4955         /* In SGMII mode, the unicore is always slave */
4956
4957         CL22_RD_OVER_CL45(sc, phy,
4958                           MDIO_REG_BANK_SERDES_DIGITAL,
4959                           MDIO_SERDES_DIGITAL_A_1000X_CONTROL1, &control1);
4960         control1 |= MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_INVERT_SIGNAL_DETECT;
4961         /* Set sgmii mode (and not fiber) */
4962         control1 &= ~(MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_FIBER_MODE |
4963                       MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_AUTODET |
4964                       MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_MSTR_MODE);
4965         CL22_WR_OVER_CL45(sc, phy,
4966                           MDIO_REG_BANK_SERDES_DIGITAL,
4967                           MDIO_SERDES_DIGITAL_A_1000X_CONTROL1, control1);
4968
4969         /* If forced speed */
4970         if (!(vars->line_speed == ELINK_SPEED_AUTO_NEG)) {
4971                 /* Set speed, disable autoneg */
4972                 uint16_t mii_control;
4973
4974                 CL22_RD_OVER_CL45(sc, phy,
4975                                   MDIO_REG_BANK_COMBO_IEEE0,
4976                                   MDIO_COMBO_IEEE0_MII_CONTROL, &mii_control);
4977                 mii_control &= ~(MDIO_COMBO_IEEO_MII_CONTROL_AN_EN |
4978                                  MDIO_COMBO_IEEO_MII_CONTROL_MAN_SGMII_SP_MASK |
4979                                  MDIO_COMBO_IEEO_MII_CONTROL_FULL_DUPLEX);
4980
4981                 switch (vars->line_speed) {
4982                 case ELINK_SPEED_100:
4983                         mii_control |=
4984                             MDIO_COMBO_IEEO_MII_CONTROL_MAN_SGMII_SP_100;
4985                         break;
4986                 case ELINK_SPEED_1000:
4987                         mii_control |=
4988                             MDIO_COMBO_IEEO_MII_CONTROL_MAN_SGMII_SP_1000;
4989                         break;
4990                 case ELINK_SPEED_10:
4991                         /* There is nothing to set for 10M */
4992                         break;
4993                 default:
4994                         /* Invalid speed for SGMII */
4995                         PMD_DRV_LOG(DEBUG, "Invalid line_speed 0x%x",
4996                                     vars->line_speed);
4997                         break;
4998                 }
4999
5000                 /* Setting the full duplex */
5001                 if (phy->req_duplex == DUPLEX_FULL)
5002                         mii_control |= MDIO_COMBO_IEEO_MII_CONTROL_FULL_DUPLEX;
5003                 CL22_WR_OVER_CL45(sc, phy,
5004                                   MDIO_REG_BANK_COMBO_IEEE0,
5005                                   MDIO_COMBO_IEEE0_MII_CONTROL, mii_control);
5006
5007         } else {                /* AN mode */
5008                 /* Enable and restart AN */
5009                 elink_restart_autoneg(phy, params, 0);
5010         }
5011 }
5012
5013 /* Link management
5014  */
5015 static elink_status_t elink_direct_parallel_detect_used(struct elink_phy *phy,
5016                                                         struct elink_params
5017                                                         *params)
5018 {
5019         struct bnx2x_softc *sc = params->sc;
5020         uint16_t pd_10g, status2_1000x;
5021         if (phy->req_line_speed != ELINK_SPEED_AUTO_NEG)
5022                 return ELINK_STATUS_OK;
5023         CL22_RD_OVER_CL45(sc, phy,
5024                           MDIO_REG_BANK_SERDES_DIGITAL,
5025                           MDIO_SERDES_DIGITAL_A_1000X_STATUS2, &status2_1000x);
5026         CL22_RD_OVER_CL45(sc, phy,
5027                           MDIO_REG_BANK_SERDES_DIGITAL,
5028                           MDIO_SERDES_DIGITAL_A_1000X_STATUS2, &status2_1000x);
5029         if (status2_1000x & MDIO_SERDES_DIGITAL_A_1000X_STATUS2_AN_DISABLED) {
5030                 PMD_DRV_LOG(DEBUG, "1G parallel detect link on port %d",
5031                             params->port);
5032                 return 1;
5033         }
5034
5035         CL22_RD_OVER_CL45(sc, phy,
5036                           MDIO_REG_BANK_10G_PARALLEL_DETECT,
5037                           MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_STATUS, &pd_10g);
5038
5039         if (pd_10g & MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_STATUS_PD_LINK) {
5040                 PMD_DRV_LOG(DEBUG, "10G parallel detect link on port %d",
5041                             params->port);
5042                 return 1;
5043         }
5044         return ELINK_STATUS_OK;
5045 }
5046
5047 static void elink_update_adv_fc(struct elink_phy *phy,
5048                                 struct elink_params *params,
5049                                 struct elink_vars *vars, uint32_t gp_status)
5050 {
5051         uint16_t ld_pause;      /* local driver */
5052         uint16_t lp_pause;      /* link partner */
5053         uint16_t pause_result;
5054         struct bnx2x_softc *sc = params->sc;
5055         if ((gp_status &
5056              (MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_AUTONEG_COMPLETE |
5057               MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_MR_LP_NP_AN_ABLE)) ==
5058             (MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_AUTONEG_COMPLETE |
5059              MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_MR_LP_NP_AN_ABLE)) {
5060
5061                 CL22_RD_OVER_CL45(sc, phy,
5062                                   MDIO_REG_BANK_CL73_IEEEB1,
5063                                   MDIO_CL73_IEEEB1_AN_ADV1, &ld_pause);
5064                 CL22_RD_OVER_CL45(sc, phy,
5065                                   MDIO_REG_BANK_CL73_IEEEB1,
5066                                   MDIO_CL73_IEEEB1_AN_LP_ADV1, &lp_pause);
5067                 pause_result = (ld_pause &
5068                                 MDIO_CL73_IEEEB1_AN_ADV1_PAUSE_MASK) >> 8;
5069                 pause_result |= (lp_pause &
5070                                  MDIO_CL73_IEEEB1_AN_LP_ADV1_PAUSE_MASK) >> 10;
5071                 PMD_DRV_LOG(DEBUG, "pause_result CL73 0x%x", pause_result);
5072         } else {
5073                 CL22_RD_OVER_CL45(sc, phy,
5074                                   MDIO_REG_BANK_COMBO_IEEE0,
5075                                   MDIO_COMBO_IEEE0_AUTO_NEG_ADV, &ld_pause);
5076                 CL22_RD_OVER_CL45(sc, phy,
5077                                   MDIO_REG_BANK_COMBO_IEEE0,
5078                                   MDIO_COMBO_IEEE0_AUTO_NEG_LINK_PARTNER_ABILITY1,
5079                                   &lp_pause);
5080                 pause_result = (ld_pause &
5081                                 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) >> 5;
5082                 pause_result |= (lp_pause &
5083                                  MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) >> 7;
5084                 PMD_DRV_LOG(DEBUG, "pause_result CL37 0x%x", pause_result);
5085         }
5086         elink_pause_resolve(vars, pause_result);
5087
5088 }
5089
5090 static void elink_flow_ctrl_resolve(struct elink_phy *phy,
5091                                     struct elink_params *params,
5092                                     struct elink_vars *vars, uint32_t gp_status)
5093 {
5094         vars->flow_ctrl = ELINK_FLOW_CTRL_NONE;
5095
5096         /* Resolve from gp_status in case of AN complete and not sgmii */
5097         if (phy->req_flow_ctrl != ELINK_FLOW_CTRL_AUTO) {
5098                 /* Update the advertised flow-controled of LD/LP in AN */
5099                 if (phy->req_line_speed == ELINK_SPEED_AUTO_NEG)
5100                         elink_update_adv_fc(phy, params, vars, gp_status);
5101                 /* But set the flow-control result as the requested one */
5102                 vars->flow_ctrl = phy->req_flow_ctrl;
5103         } else if (phy->req_line_speed != ELINK_SPEED_AUTO_NEG)
5104                 vars->flow_ctrl = params->req_fc_auto_adv;
5105         else if ((gp_status & ELINK_MDIO_AN_CL73_OR_37_COMPLETE) &&
5106                  (!(vars->phy_flags & PHY_SGMII_FLAG))) {
5107                 if (elink_direct_parallel_detect_used(phy, params)) {
5108                         vars->flow_ctrl = params->req_fc_auto_adv;
5109                         return;
5110                 }
5111                 elink_update_adv_fc(phy, params, vars, gp_status);
5112         }
5113         PMD_DRV_LOG(DEBUG, "flow_ctrl 0x%x", vars->flow_ctrl);
5114 }
5115
5116 static void elink_check_fallback_to_cl37(struct elink_phy *phy,
5117                                          struct elink_params *params)
5118 {
5119         struct bnx2x_softc *sc = params->sc;
5120         uint16_t rx_status, ustat_val, cl37_fsm_received;
5121         PMD_DRV_LOG(DEBUG, "elink_check_fallback_to_cl37");
5122         /* Step 1: Make sure signal is detected */
5123         CL22_RD_OVER_CL45(sc, phy,
5124                           MDIO_REG_BANK_RX0, MDIO_RX0_RX_STATUS, &rx_status);
5125         if ((rx_status & MDIO_RX0_RX_STATUS_SIGDET) !=
5126             (MDIO_RX0_RX_STATUS_SIGDET)) {
5127                 PMD_DRV_LOG(DEBUG, "Signal is not detected. Restoring CL73."
5128                             "rx_status(0x80b0) = 0x%x", rx_status);
5129                 CL22_WR_OVER_CL45(sc, phy,
5130                                   MDIO_REG_BANK_CL73_IEEEB0,
5131                                   MDIO_CL73_IEEEB0_CL73_AN_CONTROL,
5132                                   MDIO_CL73_IEEEB0_CL73_AN_CONTROL_AN_EN);
5133                 return;
5134         }
5135         /* Step 2: Check CL73 state machine */
5136         CL22_RD_OVER_CL45(sc, phy,
5137                           MDIO_REG_BANK_CL73_USERB0,
5138                           MDIO_CL73_USERB0_CL73_USTAT1, &ustat_val);
5139         if ((ustat_val &
5140              (MDIO_CL73_USERB0_CL73_USTAT1_LINK_STATUS_CHECK |
5141               MDIO_CL73_USERB0_CL73_USTAT1_AN_GOOD_CHECK_BAM37)) !=
5142             (MDIO_CL73_USERB0_CL73_USTAT1_LINK_STATUS_CHECK |
5143              MDIO_CL73_USERB0_CL73_USTAT1_AN_GOOD_CHECK_BAM37)) {
5144                 PMD_DRV_LOG(DEBUG, "CL73 state-machine is not stable. "
5145                             "ustat_val(0x8371) = 0x%x", ustat_val);
5146                 return;
5147         }
5148         /* Step 3: Check CL37 Message Pages received to indicate LP
5149          * supports only CL37
5150          */
5151         CL22_RD_OVER_CL45(sc, phy,
5152                           MDIO_REG_BANK_REMOTE_PHY,
5153                           MDIO_REMOTE_PHY_MISC_RX_STATUS, &cl37_fsm_received);
5154         if ((cl37_fsm_received &
5155              (MDIO_REMOTE_PHY_MISC_RX_STATUS_CL37_FSM_RECEIVED_OVER1G_MSG |
5156               MDIO_REMOTE_PHY_MISC_RX_STATUS_CL37_FSM_RECEIVED_BRCM_OUI_MSG)) !=
5157             (MDIO_REMOTE_PHY_MISC_RX_STATUS_CL37_FSM_RECEIVED_OVER1G_MSG |
5158              MDIO_REMOTE_PHY_MISC_RX_STATUS_CL37_FSM_RECEIVED_BRCM_OUI_MSG)) {
5159                 PMD_DRV_LOG(DEBUG, "No CL37 FSM were received. "
5160                             "misc_rx_status(0x8330) = 0x%x", cl37_fsm_received);
5161                 return;
5162         }
5163         /* The combined cl37/cl73 fsm state information indicating that
5164          * we are connected to a device which does not support cl73, but
5165          * does support cl37 BAM. In this case we disable cl73 and
5166          * restart cl37 auto-neg
5167          */
5168
5169         /* Disable CL73 */
5170         CL22_WR_OVER_CL45(sc, phy,
5171                           MDIO_REG_BANK_CL73_IEEEB0,
5172                           MDIO_CL73_IEEEB0_CL73_AN_CONTROL, 0);
5173         /* Restart CL37 autoneg */
5174         elink_restart_autoneg(phy, params, 0);
5175         PMD_DRV_LOG(DEBUG, "Disabling CL73, and restarting CL37 autoneg");
5176 }
5177
5178 static void elink_xgxs_an_resolve(struct elink_phy *phy,
5179                                   struct elink_params *params,
5180                                   struct elink_vars *vars, uint32_t gp_status)
5181 {
5182         if (gp_status & ELINK_MDIO_AN_CL73_OR_37_COMPLETE)
5183                 vars->link_status |= LINK_STATUS_AUTO_NEGOTIATE_COMPLETE;
5184
5185         if (elink_direct_parallel_detect_used(phy, params))
5186                 vars->link_status |= LINK_STATUS_PARALLEL_DETECTION_USED;
5187 }
5188
5189 static elink_status_t elink_get_link_speed_duplex(struct elink_phy *phy,
5190                                                   struct elink_params *params __rte_unused,
5191                                                   struct elink_vars *vars,
5192                                                   uint16_t is_link_up,
5193                                                   uint16_t speed_mask,
5194                                                   uint16_t is_duplex)
5195 {
5196         if (phy->req_line_speed == ELINK_SPEED_AUTO_NEG)
5197                 vars->link_status |= LINK_STATUS_AUTO_NEGOTIATE_ENABLED;
5198         if (is_link_up) {
5199                 PMD_DRV_LOG(DEBUG, "phy link up");
5200
5201                 vars->phy_link_up = 1;
5202                 vars->link_status |= LINK_STATUS_LINK_UP;
5203
5204                 switch (speed_mask) {
5205                 case ELINK_GP_STATUS_10M:
5206                         vars->line_speed = ELINK_SPEED_10;
5207                         if (is_duplex == DUPLEX_FULL)
5208                                 vars->link_status |= ELINK_LINK_10TFD;
5209                         else
5210                                 vars->link_status |= ELINK_LINK_10THD;
5211                         break;
5212
5213                 case ELINK_GP_STATUS_100M:
5214                         vars->line_speed = ELINK_SPEED_100;
5215                         if (is_duplex == DUPLEX_FULL)
5216                                 vars->link_status |= ELINK_LINK_100TXFD;
5217                         else
5218                                 vars->link_status |= ELINK_LINK_100TXHD;
5219                         break;
5220
5221                 case ELINK_GP_STATUS_1G:
5222                 case ELINK_GP_STATUS_1G_KX:
5223                         vars->line_speed = ELINK_SPEED_1000;
5224                         if (is_duplex == DUPLEX_FULL)
5225                                 vars->link_status |= ELINK_LINK_1000TFD;
5226                         else
5227                                 vars->link_status |= ELINK_LINK_1000THD;
5228                         break;
5229
5230                 case ELINK_GP_STATUS_2_5G:
5231                         vars->line_speed = ELINK_SPEED_2500;
5232                         if (is_duplex == DUPLEX_FULL)
5233                                 vars->link_status |= ELINK_LINK_2500TFD;
5234                         else
5235                                 vars->link_status |= ELINK_LINK_2500THD;
5236                         break;
5237
5238                 case ELINK_GP_STATUS_5G:
5239                 case ELINK_GP_STATUS_6G:
5240                         PMD_DRV_LOG(DEBUG,
5241                                     "link speed unsupported  gp_status 0x%x",
5242                                     speed_mask);
5243                         return ELINK_STATUS_ERROR;
5244
5245                 case ELINK_GP_STATUS_10G_KX4:
5246                 case ELINK_GP_STATUS_10G_HIG:
5247                 case ELINK_GP_STATUS_10G_CX4:
5248                 case ELINK_GP_STATUS_10G_KR:
5249                 case ELINK_GP_STATUS_10G_SFI:
5250                 case ELINK_GP_STATUS_10G_XFI:
5251                         vars->line_speed = ELINK_SPEED_10000;
5252                         vars->link_status |= ELINK_LINK_10GTFD;
5253                         break;
5254                 case ELINK_GP_STATUS_20G_DXGXS:
5255                 case ELINK_GP_STATUS_20G_KR2:
5256                         vars->line_speed = ELINK_SPEED_20000;
5257                         vars->link_status |= ELINK_LINK_20GTFD;
5258                         break;
5259                 default:
5260                         PMD_DRV_LOG(DEBUG,
5261                                     "link speed unsupported gp_status 0x%x",
5262                                     speed_mask);
5263                         return ELINK_STATUS_ERROR;
5264                 }
5265         } else {                /* link_down */
5266                 PMD_DRV_LOG(DEBUG, "phy link down");
5267
5268                 vars->phy_link_up = 0;
5269
5270                 vars->duplex = DUPLEX_FULL;
5271                 vars->flow_ctrl = ELINK_FLOW_CTRL_NONE;
5272                 vars->mac_type = ELINK_MAC_TYPE_NONE;
5273         }
5274         PMD_DRV_LOG(DEBUG, " phy_link_up %x line_speed %d",
5275                     vars->phy_link_up, vars->line_speed);
5276         return ELINK_STATUS_OK;
5277 }
5278
5279 static elink_status_t elink_link_settings_status(struct elink_phy *phy,
5280                                                  struct elink_params *params,
5281                                                  struct elink_vars *vars)
5282 {
5283         struct bnx2x_softc *sc = params->sc;
5284
5285         uint16_t gp_status, duplex = DUPLEX_HALF, link_up = 0, speed_mask;
5286         elink_status_t rc = ELINK_STATUS_OK;
5287
5288         /* Read gp_status */
5289         CL22_RD_OVER_CL45(sc, phy,
5290                           MDIO_REG_BANK_GP_STATUS,
5291                           MDIO_GP_STATUS_TOP_AN_STATUS1, &gp_status);
5292         if (gp_status & MDIO_GP_STATUS_TOP_AN_STATUS1_DUPLEX_STATUS)
5293                 duplex = DUPLEX_FULL;
5294         if (gp_status & MDIO_GP_STATUS_TOP_AN_STATUS1_LINK_STATUS)
5295                 link_up = 1;
5296         speed_mask = gp_status & ELINK_GP_STATUS_SPEED_MASK;
5297         PMD_DRV_LOG(DEBUG, "gp_status 0x%x, is_link_up %d, speed_mask 0x%x",
5298                     gp_status, link_up, speed_mask);
5299         rc = elink_get_link_speed_duplex(phy, params, vars, link_up, speed_mask,
5300                                          duplex);
5301         if (rc == ELINK_STATUS_ERROR)
5302                 return rc;
5303
5304         if (gp_status & MDIO_GP_STATUS_TOP_AN_STATUS1_LINK_STATUS) {
5305                 if (ELINK_SINGLE_MEDIA_DIRECT(params)) {
5306                         vars->duplex = duplex;
5307                         elink_flow_ctrl_resolve(phy, params, vars, gp_status);
5308                         if (phy->req_line_speed == ELINK_SPEED_AUTO_NEG)
5309                                 elink_xgxs_an_resolve(phy, params, vars,
5310                                                       gp_status);
5311                 }
5312         } else {                /* Link_down */
5313                 if ((phy->req_line_speed == ELINK_SPEED_AUTO_NEG) &&
5314                     ELINK_SINGLE_MEDIA_DIRECT(params)) {
5315                         /* Check signal is detected */
5316                         elink_check_fallback_to_cl37(phy, params);
5317                 }
5318         }
5319
5320         /* Read LP advertised speeds */
5321         if (ELINK_SINGLE_MEDIA_DIRECT(params) &&
5322             (vars->link_status & LINK_STATUS_AUTO_NEGOTIATE_COMPLETE)) {
5323                 uint16_t val;
5324
5325                 CL22_RD_OVER_CL45(sc, phy, MDIO_REG_BANK_CL73_IEEEB1,
5326                                   MDIO_CL73_IEEEB1_AN_LP_ADV2, &val);
5327
5328                 if (val & MDIO_CL73_IEEEB1_AN_ADV2_ADVR_1000M_KX)
5329                         vars->link_status |=
5330                             LINK_STATUS_LINK_PARTNER_1000TFD_CAPABLE;
5331                 if (val & (MDIO_CL73_IEEEB1_AN_ADV2_ADVR_10G_KX4 |
5332                            MDIO_CL73_IEEEB1_AN_ADV2_ADVR_10G_KR))
5333                         vars->link_status |=
5334                             LINK_STATUS_LINK_PARTNER_10GXFD_CAPABLE;
5335
5336                 CL22_RD_OVER_CL45(sc, phy, MDIO_REG_BANK_OVER_1G,
5337                                   MDIO_OVER_1G_LP_UP1, &val);
5338
5339                 if (val & MDIO_OVER_1G_UP1_2_5G)
5340                         vars->link_status |=
5341                             LINK_STATUS_LINK_PARTNER_2500XFD_CAPABLE;
5342                 if (val & (MDIO_OVER_1G_UP1_10G | MDIO_OVER_1G_UP1_10GH))
5343                         vars->link_status |=
5344                             LINK_STATUS_LINK_PARTNER_10GXFD_CAPABLE;
5345         }
5346
5347         PMD_DRV_LOG(DEBUG, "duplex %x  flow_ctrl 0x%x link_status 0x%x",
5348                     vars->duplex, vars->flow_ctrl, vars->link_status);
5349         return rc;
5350 }
5351
5352 static elink_status_t elink_warpcore_read_status(struct elink_phy *phy,
5353                                                  struct elink_params *params,
5354                                                  struct elink_vars *vars)
5355 {
5356         struct bnx2x_softc *sc = params->sc;
5357         uint8_t lane;
5358         uint16_t gp_status1, gp_speed, link_up, duplex = DUPLEX_FULL;
5359         elink_status_t rc = ELINK_STATUS_OK;
5360         lane = elink_get_warpcore_lane(params);
5361         /* Read gp_status */
5362         if ((params->loopback_mode) && (phy->flags & ELINK_FLAGS_WC_DUAL_MODE)) {
5363                 elink_cl45_read(sc, phy, MDIO_WC_DEVAD,
5364                                 MDIO_WC_REG_DIGITAL5_LINK_STATUS, &link_up);
5365                 elink_cl45_read(sc, phy, MDIO_WC_DEVAD,
5366                                 MDIO_WC_REG_DIGITAL5_LINK_STATUS, &link_up);
5367                 link_up &= 0x1;
5368         } else if ((phy->req_line_speed > ELINK_SPEED_10000) &&
5369                    (phy->supported & ELINK_SUPPORTED_20000baseMLD2_Full)) {
5370                 uint16_t temp_link_up;
5371                 elink_cl45_read(sc, phy, MDIO_WC_DEVAD, 1, &temp_link_up);
5372                 elink_cl45_read(sc, phy, MDIO_WC_DEVAD, 1, &link_up);
5373                 PMD_DRV_LOG(DEBUG, "PCS RX link status = 0x%x-->0x%x",
5374                             temp_link_up, link_up);
5375                 link_up &= (1 << 2);
5376                 if (link_up)
5377                         elink_ext_phy_resolve_fc(phy, params, vars);
5378         } else {
5379                 elink_cl45_read(sc, phy, MDIO_WC_DEVAD,
5380                                 MDIO_WC_REG_GP2_STATUS_GP_2_1, &gp_status1);
5381                 PMD_DRV_LOG(DEBUG, "0x81d1 = 0x%x", gp_status1);
5382                 /* Check for either KR, 1G, or AN up. */
5383                 link_up = ((gp_status1 >> 8) |
5384                            (gp_status1 >> 12) | (gp_status1)) & (1 << lane);
5385                 if (phy->supported & ELINK_SUPPORTED_20000baseKR2_Full) {
5386                         uint16_t an_link;
5387                         elink_cl45_read(sc, phy, MDIO_AN_DEVAD,
5388                                         MDIO_AN_REG_STATUS, &an_link);
5389                         elink_cl45_read(sc, phy, MDIO_AN_DEVAD,
5390                                         MDIO_AN_REG_STATUS, &an_link);
5391                         link_up |= (an_link & (1 << 2));
5392                 }
5393                 if (link_up && ELINK_SINGLE_MEDIA_DIRECT(params)) {
5394                         uint16_t pd, gp_status4;
5395                         if (phy->req_line_speed == ELINK_SPEED_AUTO_NEG) {
5396                                 /* Check Autoneg complete */
5397                                 elink_cl45_read(sc, phy, MDIO_WC_DEVAD,
5398                                                 MDIO_WC_REG_GP2_STATUS_GP_2_4,
5399                                                 &gp_status4);
5400                                 if (gp_status4 & ((1 << 12) << lane))
5401                                         vars->link_status |=
5402                                             LINK_STATUS_AUTO_NEGOTIATE_COMPLETE;
5403
5404                                 /* Check parallel detect used */
5405                                 elink_cl45_read(sc, phy, MDIO_WC_DEVAD,
5406                                                 MDIO_WC_REG_PAR_DET_10G_STATUS,
5407                                                 &pd);
5408                                 if (pd & (1 << 15))
5409                                         vars->link_status |=
5410                                             LINK_STATUS_PARALLEL_DETECTION_USED;
5411                         }
5412                         elink_ext_phy_resolve_fc(phy, params, vars);
5413                         vars->duplex = duplex;
5414                 }
5415         }
5416
5417         if ((vars->link_status & LINK_STATUS_AUTO_NEGOTIATE_COMPLETE) &&
5418             ELINK_SINGLE_MEDIA_DIRECT(params)) {
5419                 uint16_t val;
5420
5421                 elink_cl45_read(sc, phy, MDIO_AN_DEVAD,
5422                                 MDIO_AN_REG_LP_AUTO_NEG2, &val);
5423
5424                 if (val & MDIO_CL73_IEEEB1_AN_ADV2_ADVR_1000M_KX)
5425                         vars->link_status |=
5426                             LINK_STATUS_LINK_PARTNER_1000TFD_CAPABLE;
5427                 if (val & (MDIO_CL73_IEEEB1_AN_ADV2_ADVR_10G_KX4 |
5428                            MDIO_CL73_IEEEB1_AN_ADV2_ADVR_10G_KR))
5429                         vars->link_status |=
5430                             LINK_STATUS_LINK_PARTNER_10GXFD_CAPABLE;
5431
5432                 elink_cl45_read(sc, phy, MDIO_WC_DEVAD,
5433                                 MDIO_WC_REG_DIGITAL3_LP_UP1, &val);
5434
5435                 if (val & MDIO_OVER_1G_UP1_2_5G)
5436                         vars->link_status |=
5437                             LINK_STATUS_LINK_PARTNER_2500XFD_CAPABLE;
5438                 if (val & (MDIO_OVER_1G_UP1_10G | MDIO_OVER_1G_UP1_10GH))
5439                         vars->link_status |=
5440                             LINK_STATUS_LINK_PARTNER_10GXFD_CAPABLE;
5441
5442         }
5443
5444         if (lane < 2) {
5445                 elink_cl45_read(sc, phy, MDIO_WC_DEVAD,
5446                                 MDIO_WC_REG_GP2_STATUS_GP_2_2, &gp_speed);
5447         } else {
5448                 elink_cl45_read(sc, phy, MDIO_WC_DEVAD,
5449                                 MDIO_WC_REG_GP2_STATUS_GP_2_3, &gp_speed);
5450         }
5451         PMD_DRV_LOG(DEBUG, "lane %d gp_speed 0x%x", lane, gp_speed);
5452
5453         if ((lane & 1) == 0)
5454                 gp_speed <<= 8;
5455         gp_speed &= 0x3f00;
5456         link_up = ! !link_up;
5457
5458         /* Reset the TX FIFO to fix SGMII issue */
5459         rc = elink_get_link_speed_duplex(phy, params, vars, link_up, gp_speed,
5460                                          duplex);
5461
5462         /* In case of KR link down, start up the recovering procedure */
5463         if ((!link_up) && (phy->media_type == ELINK_ETH_PHY_KR) &&
5464             (!(phy->flags & ELINK_FLAGS_WC_DUAL_MODE)))
5465                 vars->rx_tx_asic_rst = MAX_KR_LINK_RETRY;
5466
5467         PMD_DRV_LOG(DEBUG, "duplex %x  flow_ctrl 0x%x link_status 0x%x",
5468                     vars->duplex, vars->flow_ctrl, vars->link_status);
5469         return rc;
5470 }
5471
5472 static void elink_set_gmii_tx_driver(struct elink_params *params)
5473 {
5474         struct bnx2x_softc *sc = params->sc;
5475         struct elink_phy *phy = &params->phy[ELINK_INT_PHY];
5476         uint16_t lp_up2;
5477         uint16_t tx_driver;
5478         uint16_t bank;
5479
5480         /* Read precomp */
5481         CL22_RD_OVER_CL45(sc, phy,
5482                           MDIO_REG_BANK_OVER_1G, MDIO_OVER_1G_LP_UP2, &lp_up2);
5483
5484         /* Bits [10:7] at lp_up2, positioned at [15:12] */
5485         lp_up2 = (((lp_up2 & MDIO_OVER_1G_LP_UP2_PREEMPHASIS_MASK) >>
5486                    MDIO_OVER_1G_LP_UP2_PREEMPHASIS_SHIFT) <<
5487                   MDIO_TX0_TX_DRIVER_PREEMPHASIS_SHIFT);
5488
5489         if (lp_up2 == 0)
5490                 return;
5491
5492         for (bank = MDIO_REG_BANK_TX0; bank <= MDIO_REG_BANK_TX3;
5493              bank += (MDIO_REG_BANK_TX1 - MDIO_REG_BANK_TX0)) {
5494                 CL22_RD_OVER_CL45(sc, phy,
5495                                   bank, MDIO_TX0_TX_DRIVER, &tx_driver);
5496
5497                 /* Replace tx_driver bits [15:12] */
5498                 if (lp_up2 != (tx_driver & MDIO_TX0_TX_DRIVER_PREEMPHASIS_MASK)) {
5499                         tx_driver &= ~MDIO_TX0_TX_DRIVER_PREEMPHASIS_MASK;
5500                         tx_driver |= lp_up2;
5501                         CL22_WR_OVER_CL45(sc, phy,
5502                                           bank, MDIO_TX0_TX_DRIVER, tx_driver);
5503                 }
5504         }
5505 }
5506
5507 static elink_status_t elink_emac_program(struct elink_params *params,
5508                                          struct elink_vars *vars)
5509 {
5510         struct bnx2x_softc *sc = params->sc;
5511         uint8_t port = params->port;
5512         uint16_t mode = 0;
5513
5514         PMD_DRV_LOG(DEBUG, "setting link speed & duplex");
5515         elink_bits_dis(sc, GRCBASE_EMAC0 + port * 0x400 +
5516                        EMAC_REG_EMAC_MODE,
5517                        (EMAC_MODE_25G_MODE |
5518                         EMAC_MODE_PORT_MII_10M | EMAC_MODE_HALF_DUPLEX));
5519         switch (vars->line_speed) {
5520         case ELINK_SPEED_10:
5521                 mode |= EMAC_MODE_PORT_MII_10M;
5522                 break;
5523
5524         case ELINK_SPEED_100:
5525                 mode |= EMAC_MODE_PORT_MII;
5526                 break;
5527
5528         case ELINK_SPEED_1000:
5529                 mode |= EMAC_MODE_PORT_GMII;
5530                 break;
5531
5532         case ELINK_SPEED_2500:
5533                 mode |= (EMAC_MODE_25G_MODE | EMAC_MODE_PORT_GMII);
5534                 break;
5535
5536         default:
5537                 /* 10G not valid for EMAC */
5538                 PMD_DRV_LOG(DEBUG, "Invalid line_speed 0x%x", vars->line_speed);
5539                 return ELINK_STATUS_ERROR;
5540         }
5541
5542         if (vars->duplex == DUPLEX_HALF)
5543                 mode |= EMAC_MODE_HALF_DUPLEX;
5544         elink_bits_en(sc,
5545                       GRCBASE_EMAC0 + port * 0x400 + EMAC_REG_EMAC_MODE, mode);
5546
5547         elink_set_led(params, vars, ELINK_LED_MODE_OPER, vars->line_speed);
5548         return ELINK_STATUS_OK;
5549 }
5550
5551 static void elink_set_preemphasis(struct elink_phy *phy,
5552                                   struct elink_params *params)
5553 {
5554
5555         uint16_t bank, i = 0;
5556         struct bnx2x_softc *sc = params->sc;
5557
5558         for (bank = MDIO_REG_BANK_RX0, i = 0; bank <= MDIO_REG_BANK_RX3;
5559              bank += (MDIO_REG_BANK_RX1 - MDIO_REG_BANK_RX0), i++) {
5560                 CL22_WR_OVER_CL45(sc, phy,
5561                                   bank,
5562                                   MDIO_RX0_RX_EQ_BOOST, phy->rx_preemphasis[i]);
5563         }
5564
5565         for (bank = MDIO_REG_BANK_TX0, i = 0; bank <= MDIO_REG_BANK_TX3;
5566              bank += (MDIO_REG_BANK_TX1 - MDIO_REG_BANK_TX0), i++) {
5567                 CL22_WR_OVER_CL45(sc, phy,
5568                                   bank,
5569                                   MDIO_TX0_TX_DRIVER, phy->tx_preemphasis[i]);
5570         }
5571 }
5572
5573 static void elink_xgxs_config_init(struct elink_phy *phy,
5574                                    struct elink_params *params,
5575                                    struct elink_vars *vars)
5576 {
5577         uint8_t enable_cl73 = (ELINK_SINGLE_MEDIA_DIRECT(params) ||
5578                                (params->loopback_mode == ELINK_LOOPBACK_XGXS));
5579
5580         if (!(vars->phy_flags & PHY_SGMII_FLAG)) {
5581                 if (ELINK_SINGLE_MEDIA_DIRECT(params) &&
5582                     (params->feature_config_flags &
5583                      ELINK_FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED))
5584                         elink_set_preemphasis(phy, params);
5585
5586                 /* Forced speed requested? */
5587                 if (vars->line_speed != ELINK_SPEED_AUTO_NEG ||
5588                     (ELINK_SINGLE_MEDIA_DIRECT(params) &&
5589                      params->loopback_mode == ELINK_LOOPBACK_EXT)) {
5590                         PMD_DRV_LOG(DEBUG, "not SGMII, no AN");
5591
5592                         /* Disable autoneg */
5593                         elink_set_autoneg(phy, params, vars, 0);
5594
5595                         /* Program speed and duplex */
5596                         elink_program_serdes(phy, params, vars);
5597
5598                 } else {        /* AN_mode */
5599                         PMD_DRV_LOG(DEBUG, "not SGMII, AN");
5600
5601                         /* AN enabled */
5602                         elink_set_brcm_cl37_advertisement(phy, params);
5603
5604                         /* Program duplex & pause advertisement (for aneg) */
5605                         elink_set_ieee_aneg_advertisement(phy, params,
5606                                                           vars->ieee_fc);
5607
5608                         /* Enable autoneg */
5609                         elink_set_autoneg(phy, params, vars, enable_cl73);
5610
5611                         /* Enable and restart AN */
5612                         elink_restart_autoneg(phy, params, enable_cl73);
5613                 }
5614
5615         } else {                /* SGMII mode */
5616                 PMD_DRV_LOG(DEBUG, "SGMII");
5617
5618                 elink_initialize_sgmii_process(phy, params, vars);
5619         }
5620 }
5621
5622 static elink_status_t elink_prepare_xgxs(struct elink_phy *phy,
5623                                          struct elink_params *params,
5624                                          struct elink_vars *vars)
5625 {
5626         elink_status_t rc;
5627         vars->phy_flags |= PHY_XGXS_FLAG;
5628         if ((phy->req_line_speed &&
5629              ((phy->req_line_speed == ELINK_SPEED_100) ||
5630               (phy->req_line_speed == ELINK_SPEED_10))) ||
5631             (!phy->req_line_speed &&
5632              (phy->speed_cap_mask >=
5633               PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL) &&
5634              (phy->speed_cap_mask <
5635               PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) ||
5636             (phy->type == PORT_HW_CFG_SERDES_EXT_PHY_TYPE_DIRECT_SD))
5637                 vars->phy_flags |= PHY_SGMII_FLAG;
5638         else
5639                 vars->phy_flags &= ~PHY_SGMII_FLAG;
5640
5641         elink_calc_ieee_aneg_adv(phy, params, &vars->ieee_fc);
5642         elink_set_aer_mmd(params, phy);
5643         if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
5644                 elink_set_master_ln(params, phy);
5645
5646         rc = elink_reset_unicore(params, phy, 0);
5647         /* Reset the SerDes and wait for reset bit return low */
5648         if (rc != ELINK_STATUS_OK)
5649                 return rc;
5650
5651         elink_set_aer_mmd(params, phy);
5652         /* Setting the masterLn_def again after the reset */
5653         if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT) {
5654                 elink_set_master_ln(params, phy);
5655                 elink_set_swap_lanes(params, phy);
5656         }
5657
5658         return rc;
5659 }
5660
5661 static uint16_t elink_wait_reset_complete(struct bnx2x_softc *sc,
5662                                           struct elink_phy *phy,
5663                                           struct elink_params *params)
5664 {
5665         uint16_t cnt, ctrl;
5666         /* Wait for soft reset to get cleared up to 1 sec */
5667         for (cnt = 0; cnt < 1000; cnt++) {
5668                 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X54618SE)
5669                         elink_cl22_read(sc, phy, MDIO_PMA_REG_CTRL, &ctrl);
5670                 else
5671                         elink_cl45_read(sc, phy,
5672                                         MDIO_PMA_DEVAD,
5673                                         MDIO_PMA_REG_CTRL, &ctrl);
5674                 if (!(ctrl & (1 << 15)))
5675                         break;
5676                 DELAY(1000 * 1);
5677         }
5678
5679         if (cnt == 1000)
5680                 elink_cb_event_log(sc, ELINK_LOG_ID_PHY_UNINITIALIZED, params->port);   // "Warning: PHY was not initialized,"
5681         // " Port %d",
5682
5683         PMD_DRV_LOG(DEBUG, "control reg 0x%x (after %d ms)", ctrl, cnt);
5684         return cnt;
5685 }
5686
5687 static void elink_link_int_enable(struct elink_params *params)
5688 {
5689         uint8_t port = params->port;
5690         uint32_t mask;
5691         struct bnx2x_softc *sc = params->sc;
5692
5693         /* Setting the status to report on link up for either XGXS or SerDes */
5694         if (CHIP_IS_E3(sc)) {
5695                 mask = ELINK_NIG_MASK_XGXS0_LINK_STATUS;
5696                 if (!(ELINK_SINGLE_MEDIA_DIRECT(params)))
5697                         mask |= ELINK_NIG_MASK_MI_INT;
5698         } else if (params->switch_cfg == ELINK_SWITCH_CFG_10G) {
5699                 mask = (ELINK_NIG_MASK_XGXS0_LINK10G |
5700                         ELINK_NIG_MASK_XGXS0_LINK_STATUS);
5701                 PMD_DRV_LOG(DEBUG, "enabled XGXS interrupt");
5702                 if (!(ELINK_SINGLE_MEDIA_DIRECT(params)) &&
5703                     params->phy[ELINK_INT_PHY].type !=
5704                     PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) {
5705                         mask |= ELINK_NIG_MASK_MI_INT;
5706                         PMD_DRV_LOG(DEBUG, "enabled external phy int");
5707                 }
5708
5709         } else {                /* SerDes */
5710                 mask = ELINK_NIG_MASK_SERDES0_LINK_STATUS;
5711                 PMD_DRV_LOG(DEBUG, "enabled SerDes interrupt");
5712                 if (!(ELINK_SINGLE_MEDIA_DIRECT(params)) &&
5713                     params->phy[ELINK_INT_PHY].type !=
5714                     PORT_HW_CFG_SERDES_EXT_PHY_TYPE_NOT_CONN) {
5715                         mask |= ELINK_NIG_MASK_MI_INT;
5716                         PMD_DRV_LOG(DEBUG, "enabled external phy int");
5717                 }
5718         }
5719         elink_bits_en(sc, NIG_REG_MASK_INTERRUPT_PORT0 + port * 4, mask);
5720
5721         PMD_DRV_LOG(DEBUG, "port %x, is_xgxs %x, int_status 0x%x", port,
5722                     (params->switch_cfg == ELINK_SWITCH_CFG_10G),
5723                     REG_RD(sc, NIG_REG_STATUS_INTERRUPT_PORT0 + port * 4));
5724         PMD_DRV_LOG(DEBUG, " int_mask 0x%x, MI_INT %x, SERDES_LINK %x",
5725                     REG_RD(sc, NIG_REG_MASK_INTERRUPT_PORT0 + port * 4),
5726                     REG_RD(sc, NIG_REG_EMAC0_STATUS_MISC_MI_INT + port * 0x18),
5727                     REG_RD(sc,
5728                            NIG_REG_SERDES0_STATUS_LINK_STATUS + port * 0x3c));
5729         PMD_DRV_LOG(DEBUG, " 10G %x, XGXS_LINK %x",
5730                     REG_RD(sc, NIG_REG_XGXS0_STATUS_LINK10G + port * 0x68),
5731                     REG_RD(sc, NIG_REG_XGXS0_STATUS_LINK_STATUS + port * 0x68));
5732 }
5733
5734 static void elink_rearm_latch_signal(struct bnx2x_softc *sc, uint8_t port,
5735                                      uint8_t exp_mi_int)
5736 {
5737         uint32_t latch_status = 0;
5738
5739         /* Disable the MI INT ( external phy int ) by writing 1 to the
5740          * status register. Link down indication is high-active-signal,
5741          * so in this case we need to write the status to clear the XOR
5742          */
5743         /* Read Latched signals */
5744         latch_status = REG_RD(sc, NIG_REG_LATCH_STATUS_0 + port * 8);
5745         PMD_DRV_LOG(DEBUG, "latch_status = 0x%x", latch_status);
5746         /* Handle only those with latched-signal=up. */
5747         if (exp_mi_int)
5748                 elink_bits_en(sc,
5749                               NIG_REG_STATUS_INTERRUPT_PORT0
5750                               + port * 4, ELINK_NIG_STATUS_EMAC0_MI_INT);
5751         else
5752                 elink_bits_dis(sc,
5753                                NIG_REG_STATUS_INTERRUPT_PORT0
5754                                + port * 4, ELINK_NIG_STATUS_EMAC0_MI_INT);
5755
5756         if (latch_status & 1) {
5757
5758                 /* For all latched-signal=up : Re-Arm Latch signals */
5759                 REG_WR(sc, NIG_REG_LATCH_STATUS_0 + port * 8,
5760                        (latch_status & 0xfffe) | (latch_status & 1));
5761         }
5762         /* For all latched-signal=up,Write original_signal to status */
5763 }
5764
5765 static void elink_link_int_ack(struct elink_params *params,
5766                                struct elink_vars *vars, uint8_t is_10g_plus)
5767 {
5768         struct bnx2x_softc *sc = params->sc;
5769         uint8_t port = params->port;
5770         uint32_t mask;
5771         /* First reset all status we assume only one line will be
5772          * change at a time
5773          */
5774         elink_bits_dis(sc, NIG_REG_STATUS_INTERRUPT_PORT0 + port * 4,
5775                        (ELINK_NIG_STATUS_XGXS0_LINK10G |
5776                         ELINK_NIG_STATUS_XGXS0_LINK_STATUS |
5777                         ELINK_NIG_STATUS_SERDES0_LINK_STATUS));
5778         if (vars->phy_link_up) {
5779                 if (USES_WARPCORE(sc))
5780                         mask = ELINK_NIG_STATUS_XGXS0_LINK_STATUS;
5781                 else {
5782                         if (is_10g_plus)
5783                                 mask = ELINK_NIG_STATUS_XGXS0_LINK10G;
5784                         else if (params->switch_cfg == ELINK_SWITCH_CFG_10G) {
5785                                 /* Disable the link interrupt by writing 1 to
5786                                  * the relevant lane in the status register
5787                                  */
5788                                 uint32_t ser_lane =
5789                                     ((params->lane_config &
5790                                       PORT_HW_CFG_LANE_SWAP_CFG_MASTER_MASK) >>
5791                                      PORT_HW_CFG_LANE_SWAP_CFG_MASTER_SHIFT);
5792                                 mask = ((1 << ser_lane) <<
5793                                         ELINK_NIG_STATUS_XGXS0_LINK_STATUS_SIZE);
5794                         } else
5795                                 mask = ELINK_NIG_STATUS_SERDES0_LINK_STATUS;
5796                 }
5797                 PMD_DRV_LOG(DEBUG, "Ack link up interrupt with mask 0x%x",
5798                             mask);
5799                 elink_bits_en(sc,
5800                               NIG_REG_STATUS_INTERRUPT_PORT0 + port * 4, mask);
5801         }
5802 }
5803
5804 static elink_status_t elink_format_ver(uint32_t num, uint8_t * str,
5805                                        uint16_t * len)
5806 {
5807         uint8_t *str_ptr = str;
5808         uint32_t mask = 0xf0000000;
5809         uint8_t shift = 8 * 4;
5810         uint8_t digit;
5811         uint8_t remove_leading_zeros = 1;
5812         if (*len < 10) {
5813                 /* Need more than 10chars for this format */
5814                 *str_ptr = '\0';
5815                 (*len)--;
5816                 return ELINK_STATUS_ERROR;
5817         }
5818         while (shift > 0) {
5819
5820                 shift -= 4;
5821                 digit = ((num & mask) >> shift);
5822                 if (digit == 0 && remove_leading_zeros) {
5823                         mask = mask >> 4;
5824                         continue;
5825                 } else if (digit < 0xa)
5826                         *str_ptr = digit + '0';
5827                 else
5828                         *str_ptr = digit - 0xa + 'a';
5829                 remove_leading_zeros = 0;
5830                 str_ptr++;
5831                 (*len)--;
5832                 mask = mask >> 4;
5833                 if (shift == 4 * 4) {
5834                         *str_ptr = '.';
5835                         str_ptr++;
5836                         (*len)--;
5837                         remove_leading_zeros = 1;
5838                 }
5839         }
5840         return ELINK_STATUS_OK;
5841 }
5842
5843 static elink_status_t elink_null_format_ver(__rte_unused uint32_t spirom_ver,
5844                                             uint8_t * str, uint16_t * len)
5845 {
5846         str[0] = '\0';
5847         (*len)--;
5848         return ELINK_STATUS_OK;
5849 }
5850
5851 static void elink_set_xgxs_loopback(struct elink_phy *phy,
5852                                     struct elink_params *params)
5853 {
5854         uint8_t port = params->port;
5855         struct bnx2x_softc *sc = params->sc;
5856
5857         if (phy->req_line_speed != ELINK_SPEED_1000) {
5858                 uint32_t md_devad = 0;
5859
5860                 PMD_DRV_LOG(DEBUG, "XGXS 10G loopback enable");
5861
5862                 if (!CHIP_IS_E3(sc)) {
5863                         /* Change the uni_phy_addr in the nig */
5864                         md_devad = REG_RD(sc, (NIG_REG_XGXS0_CTRL_MD_DEVAD +
5865                                                port * 0x18));
5866
5867                         REG_WR(sc, NIG_REG_XGXS0_CTRL_MD_DEVAD + port * 0x18,
5868                                0x5);
5869                 }
5870
5871                 elink_cl45_write(sc, phy,
5872                                  5,
5873                                  (MDIO_REG_BANK_AER_BLOCK +
5874                                   (MDIO_AER_BLOCK_AER_REG & 0xf)), 0x2800);
5875
5876                 elink_cl45_write(sc, phy,
5877                                  5,
5878                                  (MDIO_REG_BANK_CL73_IEEEB0 +
5879                                   (MDIO_CL73_IEEEB0_CL73_AN_CONTROL & 0xf)),
5880                                  0x6041);
5881                 DELAY(1000 * 200);
5882                 /* Set aer mmd back */
5883                 elink_set_aer_mmd(params, phy);
5884
5885                 if (!CHIP_IS_E3(sc)) {
5886                         /* And md_devad */
5887                         REG_WR(sc, NIG_REG_XGXS0_CTRL_MD_DEVAD + port * 0x18,
5888                                md_devad);
5889                 }
5890         } else {
5891                 uint16_t mii_ctrl;
5892                 PMD_DRV_LOG(DEBUG, "XGXS 1G loopback enable");
5893                 elink_cl45_read(sc, phy, 5,
5894                                 (MDIO_REG_BANK_COMBO_IEEE0 +
5895                                  (MDIO_COMBO_IEEE0_MII_CONTROL & 0xf)),
5896                                 &mii_ctrl);
5897                 elink_cl45_write(sc, phy, 5,
5898                                  (MDIO_REG_BANK_COMBO_IEEE0 +
5899                                   (MDIO_COMBO_IEEE0_MII_CONTROL & 0xf)),
5900                                  mii_ctrl |
5901                                  MDIO_COMBO_IEEO_MII_CONTROL_LOOPBACK);
5902         }
5903 }
5904
5905 elink_status_t elink_set_led(struct elink_params *params,
5906                              struct elink_vars *vars, uint8_t mode,
5907                              uint32_t speed)
5908 {
5909         uint8_t port = params->port;
5910         uint16_t hw_led_mode = params->hw_led_mode;
5911         elink_status_t rc = ELINK_STATUS_OK;
5912         uint8_t phy_idx;
5913         uint32_t tmp;
5914         uint32_t emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
5915         struct bnx2x_softc *sc = params->sc;
5916         PMD_DRV_LOG(DEBUG, "elink_set_led: port %x, mode %d", port, mode);
5917         PMD_DRV_LOG(DEBUG, "speed 0x%x, hw_led_mode 0x%x", speed, hw_led_mode);
5918         /* In case */
5919         for (phy_idx = ELINK_EXT_PHY1; phy_idx < ELINK_MAX_PHYS; phy_idx++) {
5920                 if (params->phy[phy_idx].set_link_led) {
5921                         params->phy[phy_idx].set_link_led(&params->phy[phy_idx],
5922                                                           params, mode);
5923                 }
5924         }
5925 #ifdef ELINK_INCLUDE_EMUL
5926         if (params->feature_config_flags &
5927             ELINK_FEATURE_CONFIG_EMUL_DISABLE_EMAC)
5928                 return rc;
5929 #endif
5930
5931         switch (mode) {
5932         case ELINK_LED_MODE_FRONT_PANEL_OFF:
5933         case ELINK_LED_MODE_OFF:
5934                 REG_WR(sc, NIG_REG_LED_10G_P0 + port * 4, 0);
5935                 REG_WR(sc, NIG_REG_LED_MODE_P0 + port * 4,
5936                        SHARED_HW_CFG_LED_MAC1);
5937
5938                 tmp = elink_cb_reg_read(sc, emac_base + EMAC_REG_EMAC_LED);
5939                 if (params->phy[ELINK_EXT_PHY1].type ==
5940                     PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X54618SE)
5941                         tmp &= ~(EMAC_LED_1000MB_OVERRIDE |
5942                                  EMAC_LED_100MB_OVERRIDE |
5943                                  EMAC_LED_10MB_OVERRIDE);
5944                 else
5945                         tmp |= EMAC_LED_OVERRIDE;
5946
5947                 elink_cb_reg_write(sc, emac_base + EMAC_REG_EMAC_LED, tmp);
5948                 break;
5949
5950         case ELINK_LED_MODE_OPER:
5951                 /* For all other phys, OPER mode is same as ON, so in case
5952                  * link is down, do nothing
5953                  */
5954                 if (!vars->link_up)
5955                         break;
5956         case ELINK_LED_MODE_ON:
5957                 if (((params->phy[ELINK_EXT_PHY1].type ==
5958                       PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X8727) ||
5959                      (params->phy[ELINK_EXT_PHY1].type ==
5960                       PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X8722)) &&
5961                     CHIP_IS_E2(sc) && params->num_phys == 2) {
5962                         /* This is a work-around for E2+8727 Configurations */
5963                         if (mode == ELINK_LED_MODE_ON ||
5964                             speed == ELINK_SPEED_10000) {
5965                                 REG_WR(sc, NIG_REG_LED_MODE_P0 + port * 4, 0);
5966                                 REG_WR(sc, NIG_REG_LED_10G_P0 + port * 4, 1);
5967
5968                                 tmp =
5969                                     elink_cb_reg_read(sc,
5970                                                       emac_base +
5971                                                       EMAC_REG_EMAC_LED);
5972                                 elink_cb_reg_write(sc,
5973                                                    emac_base +
5974                                                    EMAC_REG_EMAC_LED,
5975                                                    (tmp | EMAC_LED_OVERRIDE));
5976                                 /* Return here without enabling traffic
5977                                  * LED blink and setting rate in ON mode.
5978                                  * In oper mode, enabling LED blink
5979                                  * and setting rate is needed.
5980                                  */
5981                                 if (mode == ELINK_LED_MODE_ON)
5982                                         return rc;
5983                         }
5984                 } else if (ELINK_SINGLE_MEDIA_DIRECT(params)) {
5985                         /* This is a work-around for HW issue found when link
5986                          * is up in CL73
5987                          */
5988                         if ((!CHIP_IS_E3(sc)) ||
5989                             (CHIP_IS_E3(sc) && mode == ELINK_LED_MODE_ON))
5990                                 REG_WR(sc, NIG_REG_LED_10G_P0 + port * 4, 1);
5991
5992                         if (CHIP_IS_E1x(sc) ||
5993                             CHIP_IS_E2(sc) || (mode == ELINK_LED_MODE_ON))
5994                                 REG_WR(sc, NIG_REG_LED_MODE_P0 + port * 4, 0);
5995                         else
5996                                 REG_WR(sc, NIG_REG_LED_MODE_P0 + port * 4,
5997                                        hw_led_mode);
5998                 } else if ((params->phy[ELINK_EXT_PHY1].type ==
5999                             PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X54618SE) &&
6000                            (mode == ELINK_LED_MODE_ON)) {
6001                         REG_WR(sc, NIG_REG_LED_MODE_P0 + port * 4, 0);
6002                         tmp =
6003                             elink_cb_reg_read(sc,
6004                                               emac_base + EMAC_REG_EMAC_LED);
6005                         elink_cb_reg_write(sc, emac_base + EMAC_REG_EMAC_LED,
6006                                            tmp | EMAC_LED_OVERRIDE |
6007                                            EMAC_LED_1000MB_OVERRIDE);
6008                         /* Break here; otherwise, it'll disable the
6009                          * intended override.
6010                          */
6011                         break;
6012                 } else {
6013                         uint32_t nig_led_mode = ((params->hw_led_mode <<
6014                                                   SHARED_HW_CFG_LED_MODE_SHIFT)
6015                                                  ==
6016                                                  SHARED_HW_CFG_LED_EXTPHY2)
6017                             ? (SHARED_HW_CFG_LED_PHY1 >>
6018                                SHARED_HW_CFG_LED_MODE_SHIFT) : hw_led_mode;
6019                         REG_WR(sc, NIG_REG_LED_MODE_P0 + port * 4,
6020                                nig_led_mode);
6021                 }
6022
6023                 REG_WR(sc, NIG_REG_LED_CONTROL_OVERRIDE_TRAFFIC_P0 + port * 4,
6024                        0);
6025                 /* Set blinking rate to ~15.9Hz */
6026                 if (CHIP_IS_E3(sc))
6027                         REG_WR(sc, NIG_REG_LED_CONTROL_BLINK_RATE_P0 + port * 4,
6028                                LED_BLINK_RATE_VAL_E3);
6029                 else
6030                         REG_WR(sc, NIG_REG_LED_CONTROL_BLINK_RATE_P0 + port * 4,
6031                                LED_BLINK_RATE_VAL_E1X_E2);
6032                 REG_WR(sc, NIG_REG_LED_CONTROL_BLINK_RATE_ENA_P0 + port * 4, 1);
6033                 tmp = elink_cb_reg_read(sc, emac_base + EMAC_REG_EMAC_LED);
6034                 elink_cb_reg_write(sc, emac_base + EMAC_REG_EMAC_LED,
6035                                    (tmp & (~EMAC_LED_OVERRIDE)));
6036
6037                 break;
6038
6039         default:
6040                 rc = ELINK_STATUS_ERROR;
6041                 PMD_DRV_LOG(DEBUG, "elink_set_led: Invalid led mode %d", mode);
6042                 break;
6043         }
6044         return rc;
6045
6046 }
6047
6048 static elink_status_t elink_link_initialize(struct elink_params *params,
6049                                             struct elink_vars *vars)
6050 {
6051         elink_status_t rc = ELINK_STATUS_OK;
6052         uint8_t phy_index, non_ext_phy;
6053         struct bnx2x_softc *sc = params->sc;
6054         /* In case of external phy existence, the line speed would be the
6055          * line speed linked up by the external phy. In case it is direct
6056          * only, then the line_speed during initialization will be
6057          * equal to the req_line_speed
6058          */
6059         vars->line_speed = params->phy[ELINK_INT_PHY].req_line_speed;
6060
6061         /* Initialize the internal phy in case this is a direct board
6062          * (no external phys), or this board has external phy which requires
6063          * to first.
6064          */
6065         if (!USES_WARPCORE(sc))
6066                 elink_prepare_xgxs(&params->phy[ELINK_INT_PHY], params, vars);
6067         /* init ext phy and enable link state int */
6068         non_ext_phy = (ELINK_SINGLE_MEDIA_DIRECT(params) ||
6069                        (params->loopback_mode == ELINK_LOOPBACK_XGXS));
6070
6071         if (non_ext_phy ||
6072             (params->phy[ELINK_EXT_PHY1].flags & ELINK_FLAGS_INIT_XGXS_FIRST) ||
6073             (params->loopback_mode == ELINK_LOOPBACK_EXT_PHY)) {
6074                 struct elink_phy *phy = &params->phy[ELINK_INT_PHY];
6075                 if (vars->line_speed == ELINK_SPEED_AUTO_NEG &&
6076                     (CHIP_IS_E1x(sc) || CHIP_IS_E2(sc)))
6077                         elink_set_parallel_detection(phy, params);
6078                 if (params->phy[ELINK_INT_PHY].config_init)
6079                         params->phy[ELINK_INT_PHY].config_init(phy,
6080                                                                params, vars);
6081         }
6082
6083         /* Re-read this value in case it was changed inside config_init due to
6084          * limitations of optic module
6085          */
6086         vars->line_speed = params->phy[ELINK_INT_PHY].req_line_speed;
6087
6088         /* Init external phy */
6089         if (non_ext_phy) {
6090                 if (params->phy[ELINK_INT_PHY].supported &
6091                     ELINK_SUPPORTED_FIBRE)
6092                         vars->link_status |= LINK_STATUS_SERDES_LINK;
6093         } else {
6094                 for (phy_index = ELINK_EXT_PHY1; phy_index < params->num_phys;
6095                      phy_index++) {
6096                         /* No need to initialize second phy in case of first
6097                          * phy only selection. In case of second phy, we do
6098                          * need to initialize the first phy, since they are
6099                          * connected.
6100                          */
6101                         if (params->phy[phy_index].supported &
6102                             ELINK_SUPPORTED_FIBRE)
6103                                 vars->link_status |= LINK_STATUS_SERDES_LINK;
6104
6105                         if (phy_index == ELINK_EXT_PHY2 &&
6106                             (elink_phy_selection(params) ==
6107                              PORT_HW_CFG_PHY_SELECTION_FIRST_PHY)) {
6108                                 PMD_DRV_LOG(DEBUG,
6109                                             "Not initializing second phy");
6110                                 continue;
6111                         }
6112                         params->phy[phy_index].config_init(&params->
6113                                                            phy[phy_index],
6114                                                            params, vars);
6115                 }
6116         }
6117         /* Reset the interrupt indication after phy was initialized */
6118         elink_bits_dis(sc, NIG_REG_STATUS_INTERRUPT_PORT0 +
6119                        params->port * 4,
6120                        (ELINK_NIG_STATUS_XGXS0_LINK10G |
6121                         ELINK_NIG_STATUS_XGXS0_LINK_STATUS |
6122                         ELINK_NIG_STATUS_SERDES0_LINK_STATUS |
6123                         ELINK_NIG_MASK_MI_INT));
6124         return rc;
6125 }
6126
6127 static void elink_int_link_reset(__rte_unused struct elink_phy *phy,
6128                                  struct elink_params *params)
6129 {
6130         /* Reset the SerDes/XGXS */
6131         REG_WR(params->sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_CLEAR,
6132                (0x1ff << (params->port * 16)));
6133 }
6134
6135 static void elink_common_ext_link_reset(__rte_unused struct elink_phy *phy,
6136                                         struct elink_params *params)
6137 {
6138         struct bnx2x_softc *sc = params->sc;
6139         uint8_t gpio_port;
6140         /* HW reset */
6141         if (CHIP_IS_E2(sc))
6142                 gpio_port = SC_PATH(sc);
6143         else
6144                 gpio_port = params->port;
6145         elink_cb_gpio_write(sc, MISC_REGISTERS_GPIO_1,
6146                             MISC_REGISTERS_GPIO_OUTPUT_LOW, gpio_port);
6147         elink_cb_gpio_write(sc, MISC_REGISTERS_GPIO_2,
6148                             MISC_REGISTERS_GPIO_OUTPUT_LOW, gpio_port);
6149         PMD_DRV_LOG(DEBUG, "reset external PHY");
6150 }
6151
6152 static elink_status_t elink_update_link_down(struct elink_params *params,
6153                                              struct elink_vars *vars)
6154 {
6155         struct bnx2x_softc *sc = params->sc;
6156         uint8_t port = params->port;
6157
6158         PMD_DRV_LOG(DEBUG, "Port %x: Link is down", port);
6159         elink_set_led(params, vars, ELINK_LED_MODE_OFF, 0);
6160         vars->phy_flags &= ~PHY_PHYSICAL_LINK_FLAG;
6161         /* Indicate no mac active */
6162         vars->mac_type = ELINK_MAC_TYPE_NONE;
6163
6164         /* Update shared memory */
6165         vars->link_status &= ~ELINK_LINK_UPDATE_MASK;
6166         vars->line_speed = 0;
6167         elink_update_mng(params, vars->link_status);
6168
6169         /* Activate nig drain */
6170         REG_WR(sc, NIG_REG_EGRESS_DRAIN0_MODE + port * 4, 1);
6171
6172         /* Disable emac */
6173         if (!CHIP_IS_E3(sc))
6174                 REG_WR(sc, NIG_REG_NIG_EMAC0_EN + port * 4, 0);
6175
6176         DELAY(1000 * 10);
6177         /* Reset BigMac/Xmac */
6178         if (CHIP_IS_E1x(sc) || CHIP_IS_E2(sc))
6179                 elink_set_bmac_rx(sc, params->port, 0);
6180
6181         if (CHIP_IS_E3(sc)) {
6182                 /* Prevent LPI Generation by chip */
6183                 REG_WR(sc, MISC_REG_CPMU_LP_FW_ENABLE_P0 + (params->port << 2),
6184                        0);
6185                 REG_WR(sc, MISC_REG_CPMU_LP_MASK_ENT_P0 + (params->port << 2),
6186                        0);
6187                 vars->eee_status &= ~(SHMEM_EEE_LP_ADV_STATUS_MASK |
6188                                       SHMEM_EEE_ACTIVE_BIT);
6189
6190                 elink_update_mng_eee(params, vars->eee_status);
6191                 elink_set_xmac_rxtx(params, 0);
6192                 elink_set_umac_rxtx(params, 0);
6193         }
6194
6195         return ELINK_STATUS_OK;
6196 }
6197
6198 static elink_status_t elink_update_link_up(struct elink_params *params,
6199                                            struct elink_vars *vars,
6200                                            uint8_t link_10g)
6201 {
6202         struct bnx2x_softc *sc = params->sc;
6203         uint8_t phy_idx, port = params->port;
6204         elink_status_t rc = ELINK_STATUS_OK;
6205
6206         vars->link_status |= (LINK_STATUS_LINK_UP |
6207                               LINK_STATUS_PHYSICAL_LINK_FLAG);
6208         vars->phy_flags |= PHY_PHYSICAL_LINK_FLAG;
6209
6210         if (vars->flow_ctrl & ELINK_FLOW_CTRL_TX)
6211                 vars->link_status |= LINK_STATUS_TX_FLOW_CONTROL_ENABLED;
6212
6213         if (vars->flow_ctrl & ELINK_FLOW_CTRL_RX)
6214                 vars->link_status |= LINK_STATUS_RX_FLOW_CONTROL_ENABLED;
6215         if (USES_WARPCORE(sc)) {
6216                 if (link_10g) {
6217                         if (elink_xmac_enable(params, vars, 0) ==
6218                             ELINK_STATUS_NO_LINK) {
6219                                 PMD_DRV_LOG(DEBUG, "Found errors on XMAC");
6220                                 vars->link_up = 0;
6221                                 vars->phy_flags |= PHY_HALF_OPEN_CONN_FLAG;
6222                                 vars->link_status &= ~LINK_STATUS_LINK_UP;
6223                         }
6224                 } else
6225                         elink_umac_enable(params, vars, 0);
6226                 elink_set_led(params, vars,
6227                               ELINK_LED_MODE_OPER, vars->line_speed);
6228
6229                 if ((vars->eee_status & SHMEM_EEE_ACTIVE_BIT) &&
6230                     (vars->eee_status & SHMEM_EEE_LPI_REQUESTED_BIT)) {
6231                         PMD_DRV_LOG(DEBUG, "Enabling LPI assertion");
6232                         REG_WR(sc, MISC_REG_CPMU_LP_FW_ENABLE_P0 +
6233                                (params->port << 2), 1);
6234                         REG_WR(sc, MISC_REG_CPMU_LP_DR_ENABLE, 1);
6235                         REG_WR(sc, MISC_REG_CPMU_LP_MASK_ENT_P0 +
6236                                (params->port << 2), 0xfc20);
6237                 }
6238         }
6239         if ((CHIP_IS_E1x(sc) || CHIP_IS_E2(sc))) {
6240                 if (link_10g) {
6241                         if (elink_bmac_enable(params, vars, 0, 1) ==
6242                             ELINK_STATUS_NO_LINK) {
6243                                 PMD_DRV_LOG(DEBUG, "Found errors on BMAC");
6244                                 vars->link_up = 0;
6245                                 vars->phy_flags |= PHY_HALF_OPEN_CONN_FLAG;
6246                                 vars->link_status &= ~LINK_STATUS_LINK_UP;
6247                         }
6248
6249                         elink_set_led(params, vars,
6250                                       ELINK_LED_MODE_OPER, ELINK_SPEED_10000);
6251                 } else {
6252                         rc = elink_emac_program(params, vars);
6253                         elink_emac_enable(params, vars, 0);
6254
6255                         /* AN complete? */
6256                         if ((vars->link_status &
6257                              LINK_STATUS_AUTO_NEGOTIATE_COMPLETE)
6258                             && (!(vars->phy_flags & PHY_SGMII_FLAG)) &&
6259                             ELINK_SINGLE_MEDIA_DIRECT(params))
6260                                 elink_set_gmii_tx_driver(params);
6261                 }
6262         }
6263
6264         /* PBF - link up */
6265         if (CHIP_IS_E1x(sc))
6266                 rc |= elink_pbf_update(params, vars->flow_ctrl,
6267                                        vars->line_speed);
6268
6269         /* Disable drain */
6270         REG_WR(sc, NIG_REG_EGRESS_DRAIN0_MODE + port * 4, 0);
6271
6272         /* Update shared memory */
6273         elink_update_mng(params, vars->link_status);
6274         elink_update_mng_eee(params, vars->eee_status);
6275         /* Check remote fault */
6276         for (phy_idx = ELINK_INT_PHY; phy_idx < ELINK_MAX_PHYS; phy_idx++) {
6277                 if (params->phy[phy_idx].flags & ELINK_FLAGS_TX_ERROR_CHECK) {
6278                         elink_check_half_open_conn(params, vars, 0);
6279                         break;
6280                 }
6281         }
6282         DELAY(1000 * 20);
6283         return rc;
6284 }
6285
6286 /* The elink_link_update function should be called upon link
6287  * interrupt.
6288  * Link is considered up as follows:
6289  * - DIRECT_SINGLE_MEDIA - Only XGXS link (internal link) needs
6290  *   to be up
6291  * - SINGLE_MEDIA - The link between the 577xx and the external
6292  *   phy (XGXS) need to up as well as the external link of the
6293  *   phy (PHY_EXT1)
6294  * - DUAL_MEDIA - The link between the 577xx and the first
6295  *   external phy needs to be up, and at least one of the 2
6296  *   external phy link must be up.
6297  */
6298 elink_status_t elink_link_update(struct elink_params * params,
6299                                  struct elink_vars * vars)
6300 {
6301         struct bnx2x_softc *sc = params->sc;
6302         struct elink_vars phy_vars[ELINK_MAX_PHYS];
6303         uint8_t port = params->port;
6304         uint8_t link_10g_plus, phy_index;
6305         uint8_t ext_phy_link_up = 0, cur_link_up;
6306         elink_status_t rc = ELINK_STATUS_OK;
6307         __rte_unused uint8_t is_mi_int = 0;
6308         uint16_t ext_phy_line_speed = 0, prev_line_speed = vars->line_speed;
6309         uint8_t active_external_phy = ELINK_INT_PHY;
6310         vars->phy_flags &= ~PHY_HALF_OPEN_CONN_FLAG;
6311         vars->link_status &= ~ELINK_LINK_UPDATE_MASK;
6312         for (phy_index = ELINK_INT_PHY; phy_index < params->num_phys;
6313              phy_index++) {
6314                 phy_vars[phy_index].flow_ctrl = 0;
6315                 phy_vars[phy_index].link_status = 0;
6316                 phy_vars[phy_index].line_speed = 0;
6317                 phy_vars[phy_index].duplex = DUPLEX_FULL;
6318                 phy_vars[phy_index].phy_link_up = 0;
6319                 phy_vars[phy_index].link_up = 0;
6320                 phy_vars[phy_index].fault_detected = 0;
6321                 /* different consideration, since vars holds inner state */
6322                 phy_vars[phy_index].eee_status = vars->eee_status;
6323         }
6324
6325         if (USES_WARPCORE(sc))
6326                 elink_set_aer_mmd(params, &params->phy[ELINK_INT_PHY]);
6327
6328         PMD_DRV_LOG(DEBUG, "port %x, XGXS?%x, int_status 0x%x",
6329                     port, (vars->phy_flags & PHY_XGXS_FLAG),
6330                     REG_RD(sc, NIG_REG_STATUS_INTERRUPT_PORT0 + port * 4));
6331
6332         is_mi_int = (uint8_t) (REG_RD(sc, NIG_REG_EMAC0_STATUS_MISC_MI_INT +
6333                                       port * 0x18) > 0);
6334         PMD_DRV_LOG(DEBUG, "int_mask 0x%x MI_INT %x, SERDES_LINK %x",
6335                     REG_RD(sc, NIG_REG_MASK_INTERRUPT_PORT0 + port * 4),
6336                     is_mi_int,
6337                     REG_RD(sc,
6338                            NIG_REG_SERDES0_STATUS_LINK_STATUS + port * 0x3c));
6339
6340         PMD_DRV_LOG(DEBUG, " 10G %x, XGXS_LINK %x",
6341                     REG_RD(sc, NIG_REG_XGXS0_STATUS_LINK10G + port * 0x68),
6342                     REG_RD(sc, NIG_REG_XGXS0_STATUS_LINK_STATUS + port * 0x68));
6343
6344         /* Disable emac */
6345         if (!CHIP_IS_E3(sc))
6346                 REG_WR(sc, NIG_REG_NIG_EMAC0_EN + port * 4, 0);
6347
6348         /* Step 1:
6349          * Check external link change only for external phys, and apply
6350          * priority selection between them in case the link on both phys
6351          * is up. Note that instead of the common vars, a temporary
6352          * vars argument is used since each phy may have different link/
6353          * speed/duplex result
6354          */
6355         for (phy_index = ELINK_EXT_PHY1; phy_index < params->num_phys;
6356              phy_index++) {
6357                 struct elink_phy *phy = &params->phy[phy_index];
6358                 if (!phy->read_status)
6359                         continue;
6360                 /* Read link status and params of this ext phy */
6361                 cur_link_up = phy->read_status(phy, params,
6362                                                &phy_vars[phy_index]);
6363                 if (cur_link_up) {
6364                         PMD_DRV_LOG(DEBUG, "phy in index %d link is up",
6365                                     phy_index);
6366                 } else {
6367                         PMD_DRV_LOG(DEBUG, "phy in index %d link is down",
6368                                     phy_index);
6369                         continue;
6370                 }
6371
6372                 if (!ext_phy_link_up) {
6373                         ext_phy_link_up = 1;
6374                         active_external_phy = phy_index;
6375                 } else {
6376                         switch (elink_phy_selection(params)) {
6377                         case PORT_HW_CFG_PHY_SELECTION_HARDWARE_DEFAULT:
6378                         case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY_PRIORITY:
6379                                 /* In this option, the first PHY makes sure to pass the
6380                                  * traffic through itself only.
6381                                  * Its not clear how to reset the link on the second phy
6382                                  */
6383                                 active_external_phy = ELINK_EXT_PHY1;
6384                                 break;
6385                         case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY_PRIORITY:
6386                                 /* In this option, the first PHY makes sure to pass the
6387                                  * traffic through the second PHY.
6388                                  */
6389                                 active_external_phy = ELINK_EXT_PHY2;
6390                                 break;
6391                         default:
6392                                 /* Link indication on both PHYs with the following cases
6393                                  * is invalid:
6394                                  * - FIRST_PHY means that second phy wasn't initialized,
6395                                  * hence its link is expected to be down
6396                                  * - SECOND_PHY means that first phy should not be able
6397                                  * to link up by itself (using configuration)
6398                                  * - DEFAULT should be overriden during initialiazation
6399                                  */
6400                                 PMD_DRV_LOG(DEBUG, "Invalid link indication"
6401                                             "mpc=0x%x. DISABLING LINK !!!",
6402                                             params->multi_phy_config);
6403                                 ext_phy_link_up = 0;
6404                                 break;
6405                         }
6406                 }
6407         }
6408         prev_line_speed = vars->line_speed;
6409         /* Step 2:
6410          * Read the status of the internal phy. In case of
6411          * DIRECT_SINGLE_MEDIA board, this link is the external link,
6412          * otherwise this is the link between the 577xx and the first
6413          * external phy
6414          */
6415         if (params->phy[ELINK_INT_PHY].read_status)
6416                 params->phy[ELINK_INT_PHY].read_status(&params->
6417                                                        phy[ELINK_INT_PHY],
6418                                                        params, vars);
6419         /* The INT_PHY flow control reside in the vars. This include the
6420          * case where the speed or flow control are not set to AUTO.
6421          * Otherwise, the active external phy flow control result is set
6422          * to the vars. The ext_phy_line_speed is needed to check if the
6423          * speed is different between the internal phy and external phy.
6424          * This case may be result of intermediate link speed change.
6425          */
6426         if (active_external_phy > ELINK_INT_PHY) {
6427                 vars->flow_ctrl = phy_vars[active_external_phy].flow_ctrl;
6428                 /* Link speed is taken from the XGXS. AN and FC result from
6429                  * the external phy.
6430                  */
6431                 vars->link_status |= phy_vars[active_external_phy].link_status;
6432
6433                 /* if active_external_phy is first PHY and link is up - disable
6434                  * disable TX on second external PHY
6435                  */
6436                 if (active_external_phy == ELINK_EXT_PHY1) {
6437                         if (params->phy[ELINK_EXT_PHY2].phy_specific_func) {
6438                                 PMD_DRV_LOG(DEBUG, "Disabling TX on EXT_PHY2");
6439                                 params->phy[ELINK_EXT_PHY2].
6440                                     phy_specific_func(&params->
6441                                                       phy[ELINK_EXT_PHY2],
6442                                                       params, ELINK_DISABLE_TX);
6443                         }
6444                 }
6445
6446                 ext_phy_line_speed = phy_vars[active_external_phy].line_speed;
6447                 vars->duplex = phy_vars[active_external_phy].duplex;
6448                 if (params->phy[active_external_phy].supported &
6449                     ELINK_SUPPORTED_FIBRE)
6450                         vars->link_status |= LINK_STATUS_SERDES_LINK;
6451                 else
6452                         vars->link_status &= ~LINK_STATUS_SERDES_LINK;
6453
6454                 vars->eee_status = phy_vars[active_external_phy].eee_status;
6455
6456                 PMD_DRV_LOG(DEBUG, "Active external phy selected: %x",
6457                             active_external_phy);
6458         }
6459
6460         for (phy_index = ELINK_EXT_PHY1; phy_index < params->num_phys;
6461              phy_index++) {
6462                 if (params->phy[phy_index].flags &
6463                     ELINK_FLAGS_REARM_LATCH_SIGNAL) {
6464                         elink_rearm_latch_signal(sc, port,
6465                                                  phy_index ==
6466                                                  active_external_phy);
6467                         break;
6468                 }
6469         }
6470         PMD_DRV_LOG(DEBUG, "vars->flow_ctrl = 0x%x, vars->link_status = 0x%x,"
6471                     " ext_phy_line_speed = %d", vars->flow_ctrl,
6472                     vars->link_status, ext_phy_line_speed);
6473         /* Upon link speed change set the NIG into drain mode. Comes to
6474          * deals with possible FIFO glitch due to clk change when speed
6475          * is decreased without link down indicator
6476          */
6477
6478         if (vars->phy_link_up) {
6479                 if (!(ELINK_SINGLE_MEDIA_DIRECT(params)) && ext_phy_link_up &&
6480                     (ext_phy_line_speed != vars->line_speed)) {
6481                         PMD_DRV_LOG(DEBUG, "Internal link speed %d is"
6482                                     " different than the external"
6483                                     " link speed %d", vars->line_speed,
6484                                     ext_phy_line_speed);
6485                         vars->phy_link_up = 0;
6486                 } else if (prev_line_speed != vars->line_speed) {
6487                         REG_WR(sc,
6488                                NIG_REG_EGRESS_DRAIN0_MODE + params->port * 4,
6489                                0);
6490                         DELAY(1000 * 1);
6491                 }
6492         }
6493
6494         /* Anything 10 and over uses the bmac */
6495         link_10g_plus = (vars->line_speed >= ELINK_SPEED_10000);
6496
6497         elink_link_int_ack(params, vars, link_10g_plus);
6498
6499         /* In case external phy link is up, and internal link is down
6500          * (not initialized yet probably after link initialization, it
6501          * needs to be initialized.
6502          * Note that after link down-up as result of cable plug, the xgxs
6503          * link would probably become up again without the need
6504          * initialize it
6505          */
6506         if (!(ELINK_SINGLE_MEDIA_DIRECT(params))) {
6507                 PMD_DRV_LOG(DEBUG, "ext_phy_link_up = %d, int_link_up = %d,"
6508                             " init_preceding = %d", ext_phy_link_up,
6509                             vars->phy_link_up,
6510                             params->phy[ELINK_EXT_PHY1].flags &
6511                             ELINK_FLAGS_INIT_XGXS_FIRST);
6512                 if (!(params->phy[ELINK_EXT_PHY1].flags &
6513                       ELINK_FLAGS_INIT_XGXS_FIRST)
6514                     && ext_phy_link_up && !vars->phy_link_up) {
6515                         vars->line_speed = ext_phy_line_speed;
6516                         if (vars->line_speed < ELINK_SPEED_1000)
6517                                 vars->phy_flags |= PHY_SGMII_FLAG;
6518                         else
6519                                 vars->phy_flags &= ~PHY_SGMII_FLAG;
6520
6521                         if (params->phy[ELINK_INT_PHY].config_init)
6522                                 params->phy[ELINK_INT_PHY].config_init(&params->
6523                                                                        phy
6524                                                                        [ELINK_INT_PHY],
6525                                                                        params,
6526                                                                        vars);
6527                 }
6528         }
6529         /* Link is up only if both local phy and external phy (in case of
6530          * non-direct board) are up and no fault detected on active PHY.
6531          */
6532         vars->link_up = (vars->phy_link_up &&
6533                          (ext_phy_link_up ||
6534                           ELINK_SINGLE_MEDIA_DIRECT(params)) &&
6535                          (phy_vars[active_external_phy].fault_detected == 0));
6536
6537         /* Update the PFC configuration in case it was changed */
6538         if (params->feature_config_flags & ELINK_FEATURE_CONFIG_PFC_ENABLED)
6539                 vars->link_status |= LINK_STATUS_PFC_ENABLED;
6540         else
6541                 vars->link_status &= ~LINK_STATUS_PFC_ENABLED;
6542
6543         if (vars->link_up)
6544                 rc = elink_update_link_up(params, vars, link_10g_plus);
6545         else
6546                 rc = elink_update_link_down(params, vars);
6547
6548         /* Update MCP link status was changed */
6549         if (params->
6550             feature_config_flags & ELINK_FEATURE_CONFIG_BC_SUPPORTS_AFEX)
6551                 elink_cb_fw_command(sc, DRV_MSG_CODE_LINK_STATUS_CHANGED, 0);
6552
6553         return rc;
6554 }
6555
6556 /*****************************************************************************/
6557 /*                          External Phy section                             */
6558 /*****************************************************************************/
6559 static void elink_ext_phy_hw_reset(struct bnx2x_softc *sc, uint8_t port)
6560 {
6561         elink_cb_gpio_write(sc, MISC_REGISTERS_GPIO_1,
6562                             MISC_REGISTERS_GPIO_OUTPUT_LOW, port);
6563         DELAY(1000 * 1);
6564         elink_cb_gpio_write(sc, MISC_REGISTERS_GPIO_1,
6565                             MISC_REGISTERS_GPIO_OUTPUT_HIGH, port);
6566 }
6567
6568 static void elink_save_spirom_version(struct bnx2x_softc *sc,
6569                                       __rte_unused uint8_t port,
6570                                       uint32_t spirom_ver, uint32_t ver_addr)
6571 {
6572         PMD_DRV_LOG(DEBUG, "FW version 0x%x:0x%x for port %d",
6573                     (uint16_t) (spirom_ver >> 16), (uint16_t) spirom_ver, port);
6574
6575         if (ver_addr)
6576                 REG_WR(sc, ver_addr, spirom_ver);
6577 }
6578
6579 static void elink_save_bnx2x_spirom_ver(struct bnx2x_softc *sc,
6580                                       struct elink_phy *phy, uint8_t port)
6581 {
6582         uint16_t fw_ver1, fw_ver2;
6583
6584         elink_cl45_read(sc, phy, MDIO_PMA_DEVAD,
6585                         MDIO_PMA_REG_ROM_VER1, &fw_ver1);
6586         elink_cl45_read(sc, phy, MDIO_PMA_DEVAD,
6587                         MDIO_PMA_REG_ROM_VER2, &fw_ver2);
6588         elink_save_spirom_version(sc, port,
6589                                   (uint32_t) (fw_ver1 << 16 | fw_ver2),
6590                                   phy->ver_addr);
6591 }
6592
6593 static void elink_ext_phy_10G_an_resolve(struct bnx2x_softc *sc,
6594                                          struct elink_phy *phy,
6595                                          struct elink_vars *vars)
6596 {
6597         uint16_t val;
6598         elink_cl45_read(sc, phy, MDIO_AN_DEVAD, MDIO_AN_REG_STATUS, &val);
6599         elink_cl45_read(sc, phy, MDIO_AN_DEVAD, MDIO_AN_REG_STATUS, &val);
6600         if (val & (1 << 5))
6601                 vars->link_status |= LINK_STATUS_AUTO_NEGOTIATE_COMPLETE;
6602         if ((val & (1 << 0)) == 0)
6603                 vars->link_status |= LINK_STATUS_PARALLEL_DETECTION_USED;
6604 }
6605
6606 /******************************************************************/
6607 /*              common BNX2X8073/BNX2X8727 PHY SECTION            */
6608 /******************************************************************/
6609 static void elink_8073_resolve_fc(struct elink_phy *phy,
6610                                   struct elink_params *params,
6611                                   struct elink_vars *vars)
6612 {
6613         struct bnx2x_softc *sc = params->sc;
6614         if (phy->req_line_speed == ELINK_SPEED_10 ||
6615             phy->req_line_speed == ELINK_SPEED_100) {
6616                 vars->flow_ctrl = phy->req_flow_ctrl;
6617                 return;
6618         }
6619
6620         if (elink_ext_phy_resolve_fc(phy, params, vars) &&
6621             (vars->flow_ctrl == ELINK_FLOW_CTRL_NONE)) {
6622                 uint16_t pause_result;
6623                 uint16_t ld_pause;      /* local */
6624                 uint16_t lp_pause;      /* link partner */
6625                 elink_cl45_read(sc, phy,
6626                                 MDIO_AN_DEVAD,
6627                                 MDIO_AN_REG_CL37_FC_LD, &ld_pause);
6628
6629                 elink_cl45_read(sc, phy,
6630                                 MDIO_AN_DEVAD,
6631                                 MDIO_AN_REG_CL37_FC_LP, &lp_pause);
6632                 pause_result = (ld_pause &
6633                                 MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) >> 5;
6634                 pause_result |= (lp_pause &
6635                                  MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) >> 7;
6636
6637                 elink_pause_resolve(vars, pause_result);
6638                 PMD_DRV_LOG(DEBUG, "Ext PHY CL37 pause result 0x%x",
6639                             pause_result);
6640         }
6641 }
6642
6643 static elink_status_t elink_8073_8727_external_rom_boot(struct bnx2x_softc *sc,
6644                                                         struct elink_phy *phy,
6645                                                         uint8_t port)
6646 {
6647         uint32_t count = 0;
6648         uint16_t fw_ver1, fw_msgout;
6649         elink_status_t rc = ELINK_STATUS_OK;
6650
6651         /* Boot port from external ROM  */
6652         /* EDC grst */
6653         elink_cl45_write(sc, phy,
6654                          MDIO_PMA_DEVAD, MDIO_PMA_REG_GEN_CTRL, 0x0001);
6655
6656         /* Ucode reboot and rst */
6657         elink_cl45_write(sc, phy,
6658                          MDIO_PMA_DEVAD, MDIO_PMA_REG_GEN_CTRL, 0x008c);
6659
6660         elink_cl45_write(sc, phy,
6661                          MDIO_PMA_DEVAD, MDIO_PMA_REG_MISC_CTRL1, 0x0001);
6662
6663         /* Reset internal microprocessor */
6664         elink_cl45_write(sc, phy,
6665                          MDIO_PMA_DEVAD,
6666                          MDIO_PMA_REG_GEN_CTRL,
6667                          MDIO_PMA_REG_GEN_CTRL_ROM_MICRO_RESET);
6668
6669         /* Release srst bit */
6670         elink_cl45_write(sc, phy,
6671                          MDIO_PMA_DEVAD,
6672                          MDIO_PMA_REG_GEN_CTRL,
6673                          MDIO_PMA_REG_GEN_CTRL_ROM_RESET_INTERNAL_MP);
6674
6675         /* Delay 100ms per the PHY specifications */
6676         DELAY(1000 * 100);
6677
6678         /* 8073 sometimes taking longer to download */
6679         do {
6680                 count++;
6681                 if (count > 300) {
6682                         PMD_DRV_LOG(DEBUG,
6683                                     "elink_8073_8727_external_rom_boot port %x:"
6684                                     "Download failed. fw version = 0x%x",
6685                                     port, fw_ver1);
6686                         rc = ELINK_STATUS_ERROR;
6687                         break;
6688                 }
6689
6690                 elink_cl45_read(sc, phy,
6691                                 MDIO_PMA_DEVAD,
6692                                 MDIO_PMA_REG_ROM_VER1, &fw_ver1);
6693                 elink_cl45_read(sc, phy,
6694                                 MDIO_PMA_DEVAD,
6695                                 MDIO_PMA_REG_M8051_MSGOUT_REG, &fw_msgout);
6696
6697                 DELAY(1000 * 1);
6698         } while (fw_ver1 == 0 || fw_ver1 == 0x4321 ||
6699                  ((fw_msgout & 0xff) != 0x03 && (phy->type ==
6700                                                  PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X8073)));
6701
6702         /* Clear ser_boot_ctl bit */
6703         elink_cl45_write(sc, phy,
6704                          MDIO_PMA_DEVAD, MDIO_PMA_REG_MISC_CTRL1, 0x0000);
6705         elink_save_bnx2x_spirom_ver(sc, phy, port);
6706
6707         PMD_DRV_LOG(DEBUG,
6708                     "elink_8073_8727_external_rom_boot port %x:"
6709                     "Download complete. fw version = 0x%x", port, fw_ver1);
6710
6711         return rc;
6712 }
6713
6714 /******************************************************************/
6715 /*                      BNX2X8073 PHY SECTION                     */
6716 /******************************************************************/
6717 static elink_status_t elink_8073_is_snr_needed(struct bnx2x_softc *sc,
6718                                                struct elink_phy *phy)
6719 {
6720         /* This is only required for 8073A1, version 102 only */
6721         uint16_t val;
6722
6723         /* Read 8073 HW revision */
6724         elink_cl45_read(sc, phy,
6725                         MDIO_PMA_DEVAD, MDIO_PMA_REG_8073_CHIP_REV, &val);
6726
6727         if (val != 1) {
6728                 /* No need to workaround in 8073 A1 */
6729                 return ELINK_STATUS_OK;
6730         }
6731
6732         elink_cl45_read(sc, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_ROM_VER2, &val);
6733
6734         /* SNR should be applied only for version 0x102 */
6735         if (val != 0x102)
6736                 return ELINK_STATUS_OK;
6737
6738         return 1;
6739 }
6740
6741 static elink_status_t elink_8073_xaui_wa(struct bnx2x_softc *sc,
6742                                          struct elink_phy *phy)
6743 {
6744         uint16_t val, cnt, cnt1;
6745
6746         elink_cl45_read(sc, phy,
6747                         MDIO_PMA_DEVAD, MDIO_PMA_REG_8073_CHIP_REV, &val);
6748
6749         if (val > 0) {
6750                 /* No need to workaround in 8073 A1 */
6751                 return ELINK_STATUS_OK;
6752         }
6753         /* XAUI workaround in 8073 A0: */
6754
6755         /* After loading the boot ROM and restarting Autoneg, poll
6756          * Dev1, Reg $C820:
6757          */
6758
6759         for (cnt = 0; cnt < 1000; cnt++) {
6760                 elink_cl45_read(sc, phy,
6761                                 MDIO_PMA_DEVAD,
6762                                 MDIO_PMA_REG_8073_SPEED_LINK_STATUS, &val);
6763                 /* If bit [14] = 0 or bit [13] = 0, continue on with
6764                  * system initialization (XAUI work-around not required, as
6765                  * these bits indicate 2.5G or 1G link up).
6766                  */
6767                 if (!(val & (1 << 14)) || !(val & (1 << 13))) {
6768                         PMD_DRV_LOG(DEBUG, "XAUI work-around not required");
6769                         return ELINK_STATUS_OK;
6770                 } else if (!(val & (1 << 15))) {
6771                         PMD_DRV_LOG(DEBUG, "bit 15 went off");
6772                         /* If bit 15 is 0, then poll Dev1, Reg $C841 until it's
6773                          * MSB (bit15) goes to 1 (indicating that the XAUI
6774                          * workaround has completed), then continue on with
6775                          * system initialization.
6776                          */
6777                         for (cnt1 = 0; cnt1 < 1000; cnt1++) {
6778                                 elink_cl45_read(sc, phy,
6779                                                 MDIO_PMA_DEVAD,
6780                                                 MDIO_PMA_REG_8073_XAUI_WA,
6781                                                 &val);
6782                                 if (val & (1 << 15)) {
6783                                         PMD_DRV_LOG(DEBUG,
6784                                                     "XAUI workaround has completed");
6785                                         return ELINK_STATUS_OK;
6786                                 }
6787                                 DELAY(1000 * 3);
6788                         }
6789                         break;
6790                 }
6791                 DELAY(1000 * 3);
6792         }
6793         PMD_DRV_LOG(DEBUG, "Warning: XAUI work-around timeout !!!");
6794         return ELINK_STATUS_ERROR;
6795 }
6796
6797 static void elink_807x_force_10G(struct bnx2x_softc *sc, struct elink_phy *phy)
6798 {
6799         /* Force KR or KX */
6800         elink_cl45_write(sc, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x2040);
6801         elink_cl45_write(sc, phy,
6802                          MDIO_PMA_DEVAD, MDIO_PMA_REG_10G_CTRL2, 0x000b);
6803         elink_cl45_write(sc, phy,
6804                          MDIO_PMA_DEVAD, MDIO_PMA_REG_BNX2X_CTRL, 0x0000);
6805         elink_cl45_write(sc, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x0000);
6806 }
6807
6808 static void elink_8073_set_pause_cl37(struct elink_params *params,
6809                                       struct elink_phy *phy,
6810                                       struct elink_vars *vars)
6811 {
6812         uint16_t cl37_val;
6813         struct bnx2x_softc *sc = params->sc;
6814         elink_cl45_read(sc, phy,
6815                         MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LD, &cl37_val);
6816
6817         cl37_val &= ~MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH;
6818         /* Please refer to Table 28B-3 of 802.3ab-1999 spec. */
6819         elink_calc_ieee_aneg_adv(phy, params, &vars->ieee_fc);
6820         if ((vars->ieee_fc &
6821              MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_SYMMETRIC) ==
6822             MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_SYMMETRIC) {
6823                 cl37_val |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_SYMMETRIC;
6824         }
6825         if ((vars->ieee_fc &
6826              MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC) ==
6827             MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC) {
6828                 cl37_val |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC;
6829         }
6830         if ((vars->ieee_fc &
6831              MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) ==
6832             MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) {
6833                 cl37_val |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH;
6834         }
6835         PMD_DRV_LOG(DEBUG, "Ext phy AN advertize cl37 0x%x", cl37_val);
6836
6837         elink_cl45_write(sc, phy,
6838                          MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LD, cl37_val);
6839         DELAY(1000 * 500);
6840 }
6841
6842 static void elink_8073_specific_func(struct elink_phy *phy,
6843                                      struct elink_params *params,
6844                                      uint32_t action)
6845 {
6846         struct bnx2x_softc *sc = params->sc;
6847         switch (action) {
6848         case ELINK_PHY_INIT:
6849                 /* Enable LASI */
6850                 elink_cl45_write(sc, phy,
6851                                  MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXCTRL,
6852                                  (1 << 2));
6853                 elink_cl45_write(sc, phy, MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL,
6854                                  0x0004);
6855                 break;
6856         }
6857 }
6858
6859 static elink_status_t elink_8073_config_init(struct elink_phy *phy,
6860                                              struct elink_params *params,
6861                                              struct elink_vars *vars)
6862 {
6863         struct bnx2x_softc *sc = params->sc;
6864         uint16_t val = 0, tmp1;
6865         uint8_t gpio_port;
6866         PMD_DRV_LOG(DEBUG, "Init 8073");
6867
6868         if (CHIP_IS_E2(sc))
6869                 gpio_port = SC_PATH(sc);
6870         else
6871                 gpio_port = params->port;
6872         /* Restore normal power mode */
6873         elink_cb_gpio_write(sc, MISC_REGISTERS_GPIO_2,
6874                             MISC_REGISTERS_GPIO_OUTPUT_HIGH, gpio_port);
6875
6876         elink_cb_gpio_write(sc, MISC_REGISTERS_GPIO_1,
6877                             MISC_REGISTERS_GPIO_OUTPUT_HIGH, gpio_port);
6878
6879         elink_8073_specific_func(phy, params, ELINK_PHY_INIT);
6880         elink_8073_set_pause_cl37(params, phy, vars);
6881
6882         elink_cl45_read(sc, phy,
6883                         MDIO_PMA_DEVAD, MDIO_PMA_REG_M8051_MSGOUT_REG, &tmp1);
6884
6885         elink_cl45_read(sc, phy, MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXSTAT, &tmp1);
6886
6887         PMD_DRV_LOG(DEBUG, "Before rom RX_ALARM(port1): 0x%x", tmp1);
6888
6889         /* Swap polarity if required - Must be done only in non-1G mode */
6890         if (params->lane_config & PORT_HW_CFG_SWAP_PHY_POLARITY_ENABLED) {
6891                 /* Configure the 8073 to swap _P and _N of the KR lines */
6892                 PMD_DRV_LOG(DEBUG, "Swapping polarity for the 8073");
6893                 /* 10G Rx/Tx and 1G Tx signal polarity swap */
6894                 elink_cl45_read(sc, phy,
6895                                 MDIO_PMA_DEVAD,
6896                                 MDIO_PMA_REG_8073_OPT_DIGITAL_CTRL, &val);
6897                 elink_cl45_write(sc, phy,
6898                                  MDIO_PMA_DEVAD,
6899                                  MDIO_PMA_REG_8073_OPT_DIGITAL_CTRL,
6900                                  (val | (3 << 9)));
6901         }
6902
6903         /* Enable CL37 BAM */
6904         if (REG_RD(sc, params->shmem_base +
6905                    offsetof(struct shmem_region,
6906                             dev_info.port_hw_config[params->port].
6907                             default_cfg)) &
6908             PORT_HW_CFG_ENABLE_BAM_ON_KR_ENABLED) {
6909
6910                 elink_cl45_read(sc, phy,
6911                                 MDIO_AN_DEVAD, MDIO_AN_REG_8073_BAM, &val);
6912                 elink_cl45_write(sc, phy,
6913                                  MDIO_AN_DEVAD, MDIO_AN_REG_8073_BAM, val | 1);
6914                 PMD_DRV_LOG(DEBUG, "Enable CL37 BAM on KR");
6915         }
6916         if (params->loopback_mode == ELINK_LOOPBACK_EXT) {
6917                 elink_807x_force_10G(sc, phy);
6918                 PMD_DRV_LOG(DEBUG, "Forced speed 10G on 807X");
6919                 return ELINK_STATUS_OK;
6920         } else {
6921                 elink_cl45_write(sc, phy,
6922                                  MDIO_PMA_DEVAD, MDIO_PMA_REG_BNX2X_CTRL, 0x0002);
6923         }
6924         if (phy->req_line_speed != ELINK_SPEED_AUTO_NEG) {
6925                 if (phy->req_line_speed == ELINK_SPEED_10000) {
6926                         val = (1 << 7);
6927                 } else if (phy->req_line_speed == ELINK_SPEED_2500) {
6928                         val = (1 << 5);
6929                         /* Note that 2.5G works only when used with 1G
6930                          * advertisement
6931                          */
6932                 } else
6933                         val = (1 << 5);
6934         } else {
6935                 val = 0;
6936                 if (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
6937                         val |= (1 << 7);
6938
6939                 /* Note that 2.5G works only when used with 1G advertisement */
6940                 if (phy->speed_cap_mask &
6941                     (PORT_HW_CFG_SPEED_CAPABILITY_D0_1G |
6942                      PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
6943                         val |= (1 << 5);
6944                 PMD_DRV_LOG(DEBUG, "807x autoneg val = 0x%x", val);
6945         }
6946
6947         elink_cl45_write(sc, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV, val);
6948         elink_cl45_read(sc, phy, MDIO_AN_DEVAD, MDIO_AN_REG_8073_2_5G, &tmp1);
6949
6950         if (((phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G) &&
6951              (phy->req_line_speed == ELINK_SPEED_AUTO_NEG)) ||
6952             (phy->req_line_speed == ELINK_SPEED_2500)) {
6953                 uint16_t phy_ver;
6954                 /* Allow 2.5G for A1 and above */
6955                 elink_cl45_read(sc, phy,
6956                                 MDIO_PMA_DEVAD, MDIO_PMA_REG_8073_CHIP_REV,
6957                                 &phy_ver);
6958                 PMD_DRV_LOG(DEBUG, "Add 2.5G");
6959                 if (phy_ver > 0)
6960                         tmp1 |= 1;
6961                 else
6962                         tmp1 &= 0xfffe;
6963         } else {
6964                 PMD_DRV_LOG(DEBUG, "Disable 2.5G");
6965                 tmp1 &= 0xfffe;
6966         }
6967
6968         elink_cl45_write(sc, phy, MDIO_AN_DEVAD, MDIO_AN_REG_8073_2_5G, tmp1);
6969         /* Add support for CL37 (passive mode) II */
6970
6971         elink_cl45_read(sc, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LD, &tmp1);
6972         elink_cl45_write(sc, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LD,
6973                          (tmp1 | ((phy->req_duplex == DUPLEX_FULL) ?
6974                                   0x20 : 0x40)));
6975
6976         /* Add support for CL37 (passive mode) III */
6977         elink_cl45_write(sc, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CL37_AN, 0x1000);
6978
6979         /* The SNR will improve about 2db by changing BW and FEE main
6980          * tap. Rest commands are executed after link is up
6981          * Change FFE main cursor to 5 in EDC register
6982          */
6983         if (elink_8073_is_snr_needed(sc, phy))
6984                 elink_cl45_write(sc, phy,
6985                                  MDIO_PMA_DEVAD, MDIO_PMA_REG_EDC_FFE_MAIN,
6986                                  0xFB0C);
6987
6988         /* Enable FEC (Forware Error Correction) Request in the AN */
6989         elink_cl45_read(sc, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV2, &tmp1);
6990         tmp1 |= (1 << 15);
6991         elink_cl45_write(sc, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV2, tmp1);
6992
6993         elink_ext_phy_set_pause(params, phy, vars);
6994
6995         /* Restart autoneg */
6996         DELAY(1000 * 500);
6997         elink_cl45_write(sc, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x1200);
6998         PMD_DRV_LOG(DEBUG, "807x Autoneg Restart: Advertise 1G=%x, 10G=%x",
6999                     ((val & (1 << 5)) > 0), ((val & (1 << 7)) > 0));
7000         return ELINK_STATUS_OK;
7001 }
7002
7003 static uint8_t elink_8073_read_status(struct elink_phy *phy,
7004                                       struct elink_params *params,
7005                                       struct elink_vars *vars)
7006 {
7007         struct bnx2x_softc *sc = params->sc;
7008         uint8_t link_up = 0;
7009         uint16_t val1, val2;
7010         uint16_t link_status = 0;
7011         uint16_t an1000_status = 0;
7012
7013         elink_cl45_read(sc, phy, MDIO_PMA_DEVAD, MDIO_PMA_LASI_STAT, &val1);
7014
7015         PMD_DRV_LOG(DEBUG, "8703 LASI status 0x%x", val1);
7016
7017         /* Clear the interrupt LASI status register */
7018         elink_cl45_read(sc, phy, MDIO_PCS_DEVAD, MDIO_PCS_REG_STATUS, &val2);
7019         elink_cl45_read(sc, phy, MDIO_PCS_DEVAD, MDIO_PCS_REG_STATUS, &val1);
7020         PMD_DRV_LOG(DEBUG, "807x PCS status 0x%x->0x%x", val2, val1);
7021         /* Clear MSG-OUT */
7022         elink_cl45_read(sc, phy,
7023                         MDIO_PMA_DEVAD, MDIO_PMA_REG_M8051_MSGOUT_REG, &val1);
7024
7025         /* Check the LASI */
7026         elink_cl45_read(sc, phy, MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXSTAT, &val2);
7027
7028         PMD_DRV_LOG(DEBUG, "KR 0x9003 0x%x", val2);
7029
7030         /* Check the link status */
7031         elink_cl45_read(sc, phy, MDIO_PCS_DEVAD, MDIO_PCS_REG_STATUS, &val2);
7032         PMD_DRV_LOG(DEBUG, "KR PCS status 0x%x", val2);
7033
7034         elink_cl45_read(sc, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val2);
7035         elink_cl45_read(sc, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val1);
7036         link_up = ((val1 & 4) == 4);
7037         PMD_DRV_LOG(DEBUG, "PMA_REG_STATUS=0x%x", val1);
7038
7039         if (link_up && ((phy->req_line_speed != ELINK_SPEED_10000))) {
7040                 if (elink_8073_xaui_wa(sc, phy) != 0)
7041                         return 0;
7042         }
7043         elink_cl45_read(sc, phy,
7044                         MDIO_AN_DEVAD, MDIO_AN_REG_LINK_STATUS, &an1000_status);
7045         elink_cl45_read(sc, phy,
7046                         MDIO_AN_DEVAD, MDIO_AN_REG_LINK_STATUS, &an1000_status);
7047
7048         /* Check the link status on 1.1.2 */
7049         elink_cl45_read(sc, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val2);
7050         elink_cl45_read(sc, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val1);
7051         PMD_DRV_LOG(DEBUG, "KR PMA status 0x%x->0x%x,"
7052                     "an_link_status=0x%x", val2, val1, an1000_status);
7053
7054         link_up = (((val1 & 4) == 4) || (an1000_status & (1 << 1)));
7055         if (link_up && elink_8073_is_snr_needed(sc, phy)) {
7056                 /* The SNR will improve about 2dbby changing the BW and FEE main
7057                  * tap. The 1st write to change FFE main tap is set before
7058                  * restart AN. Change PLL Bandwidth in EDC register
7059                  */
7060                 elink_cl45_write(sc, phy,
7061                                  MDIO_PMA_DEVAD, MDIO_PMA_REG_PLL_BANDWIDTH,
7062                                  0x26BC);
7063
7064                 /* Change CDR Bandwidth in EDC register */
7065                 elink_cl45_write(sc, phy,
7066                                  MDIO_PMA_DEVAD, MDIO_PMA_REG_CDR_BANDWIDTH,
7067                                  0x0333);
7068         }
7069         elink_cl45_read(sc, phy,
7070                         MDIO_PMA_DEVAD, MDIO_PMA_REG_8073_SPEED_LINK_STATUS,
7071                         &link_status);
7072
7073         /* Bits 0..2 --> speed detected, bits 13..15--> link is down */
7074         if ((link_status & (1 << 2)) && (!(link_status & (1 << 15)))) {
7075                 link_up = 1;
7076                 vars->line_speed = ELINK_SPEED_10000;
7077                 PMD_DRV_LOG(DEBUG, "port %x: External link up in 10G",
7078                             params->port);
7079         } else if ((link_status & (1 << 1)) && (!(link_status & (1 << 14)))) {
7080                 link_up = 1;
7081                 vars->line_speed = ELINK_SPEED_2500;
7082                 PMD_DRV_LOG(DEBUG, "port %x: External link up in 2.5G",
7083                             params->port);
7084         } else if ((link_status & (1 << 0)) && (!(link_status & (1 << 13)))) {
7085                 link_up = 1;
7086                 vars->line_speed = ELINK_SPEED_1000;
7087                 PMD_DRV_LOG(DEBUG, "port %x: External link up in 1G",
7088                             params->port);
7089         } else {
7090                 link_up = 0;
7091                 PMD_DRV_LOG(DEBUG, "port %x: External link is down",
7092                             params->port);
7093         }
7094
7095         if (link_up) {
7096                 /* Swap polarity if required */
7097                 if (params->lane_config & PORT_HW_CFG_SWAP_PHY_POLARITY_ENABLED) {
7098                         /* Configure the 8073 to swap P and N of the KR lines */
7099                         elink_cl45_read(sc, phy,
7100                                         MDIO_XS_DEVAD,
7101                                         MDIO_XS_REG_8073_RX_CTRL_PCIE, &val1);
7102                         /* Set bit 3 to invert Rx in 1G mode and clear this bit
7103                          * when it`s in 10G mode.
7104                          */
7105                         if (vars->line_speed == ELINK_SPEED_1000) {
7106                                 PMD_DRV_LOG(DEBUG, "Swapping 1G polarity for"
7107                                             "the 8073");
7108                                 val1 |= (1 << 3);
7109                         } else
7110                                 val1 &= ~(1 << 3);
7111
7112                         elink_cl45_write(sc, phy,
7113                                          MDIO_XS_DEVAD,
7114                                          MDIO_XS_REG_8073_RX_CTRL_PCIE, val1);
7115                 }
7116                 elink_ext_phy_10G_an_resolve(sc, phy, vars);
7117                 elink_8073_resolve_fc(phy, params, vars);
7118                 vars->duplex = DUPLEX_FULL;
7119         }
7120
7121         if (vars->link_status & LINK_STATUS_AUTO_NEGOTIATE_COMPLETE) {
7122                 elink_cl45_read(sc, phy, MDIO_AN_DEVAD,
7123                                 MDIO_AN_REG_LP_AUTO_NEG2, &val1);
7124
7125                 if (val1 & (1 << 5))
7126                         vars->link_status |=
7127                             LINK_STATUS_LINK_PARTNER_1000TFD_CAPABLE;
7128                 if (val1 & (1 << 7))
7129                         vars->link_status |=
7130                             LINK_STATUS_LINK_PARTNER_10GXFD_CAPABLE;
7131         }
7132
7133         return link_up;
7134 }
7135
7136 static void elink_8073_link_reset(__rte_unused struct elink_phy *phy,
7137                                   struct elink_params *params)
7138 {
7139         struct bnx2x_softc *sc = params->sc;
7140         uint8_t gpio_port;
7141         if (CHIP_IS_E2(sc))
7142                 gpio_port = SC_PATH(sc);
7143         else
7144                 gpio_port = params->port;
7145         PMD_DRV_LOG(DEBUG, "Setting 8073 port %d into low power mode",
7146                     gpio_port);
7147         elink_cb_gpio_write(sc, MISC_REGISTERS_GPIO_2,
7148                             MISC_REGISTERS_GPIO_OUTPUT_LOW, gpio_port);
7149 }
7150
7151 /******************************************************************/
7152 /*                      BNX2X8705 PHY SECTION                     */
7153 /******************************************************************/
7154 static elink_status_t elink_8705_config_init(struct elink_phy *phy,
7155                                              struct elink_params *params,
7156                                              __rte_unused struct elink_vars
7157                                              *vars)
7158 {
7159         struct bnx2x_softc *sc = params->sc;
7160         PMD_DRV_LOG(DEBUG, "init 8705");
7161         /* Restore normal power mode */
7162         elink_cb_gpio_write(sc, MISC_REGISTERS_GPIO_2,
7163                             MISC_REGISTERS_GPIO_OUTPUT_HIGH, params->port);
7164         /* HW reset */
7165         elink_ext_phy_hw_reset(sc, params->port);
7166         elink_cl45_write(sc, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0xa040);
7167         elink_wait_reset_complete(sc, phy, params);
7168
7169         elink_cl45_write(sc, phy,
7170                          MDIO_PMA_DEVAD, MDIO_PMA_REG_MISC_CTRL, 0x8288);
7171         elink_cl45_write(sc, phy,
7172                          MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER, 0x7fbf);
7173         elink_cl45_write(sc, phy,
7174                          MDIO_PMA_DEVAD, MDIO_PMA_REG_CMU_PLL_BYPASS, 0x0100);
7175         elink_cl45_write(sc, phy, MDIO_WIS_DEVAD, MDIO_WIS_REG_LASI_CNTL, 0x1);
7176         /* BNX2X8705 doesn't have microcode, hence the 0 */
7177         elink_save_spirom_version(sc, params->port, params->shmem_base, 0);
7178         return ELINK_STATUS_OK;
7179 }
7180
7181 static uint8_t elink_8705_read_status(struct elink_phy *phy,
7182                                       struct elink_params *params,
7183                                       struct elink_vars *vars)
7184 {
7185         uint8_t link_up = 0;
7186         uint16_t val1, rx_sd;
7187         struct bnx2x_softc *sc = params->sc;
7188         PMD_DRV_LOG(DEBUG, "read status 8705");
7189         elink_cl45_read(sc, phy,
7190                         MDIO_WIS_DEVAD, MDIO_WIS_REG_LASI_STATUS, &val1);
7191         PMD_DRV_LOG(DEBUG, "8705 LASI status 0x%x", val1);
7192
7193         elink_cl45_read(sc, phy,
7194                         MDIO_WIS_DEVAD, MDIO_WIS_REG_LASI_STATUS, &val1);
7195         PMD_DRV_LOG(DEBUG, "8705 LASI status 0x%x", val1);
7196
7197         elink_cl45_read(sc, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_SD, &rx_sd);
7198
7199         elink_cl45_read(sc, phy, MDIO_PMA_DEVAD, 0xc809, &val1);
7200         elink_cl45_read(sc, phy, MDIO_PMA_DEVAD, 0xc809, &val1);
7201
7202         PMD_DRV_LOG(DEBUG, "8705 1.c809 val=0x%x", val1);
7203         link_up = ((rx_sd & 0x1) && (val1 & (1 << 9))
7204                    && ((val1 & (1 << 8)) == 0));
7205         if (link_up) {
7206                 vars->line_speed = ELINK_SPEED_10000;
7207                 elink_ext_phy_resolve_fc(phy, params, vars);
7208         }
7209         return link_up;
7210 }
7211
7212 /******************************************************************/
7213 /*                      SFP+ module Section                       */
7214 /******************************************************************/
7215 static void elink_set_disable_pmd_transmit(struct elink_params *params,
7216                                            struct elink_phy *phy,
7217                                            uint8_t pmd_dis)
7218 {
7219         struct bnx2x_softc *sc = params->sc;
7220         /* Disable transmitter only for bootcodes which can enable it afterwards
7221          * (for D3 link)
7222          */
7223         if (pmd_dis) {
7224                 if (params->feature_config_flags &
7225                     ELINK_FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED) {
7226                         PMD_DRV_LOG(DEBUG, "Disabling PMD transmitter");
7227                 } else {
7228                         PMD_DRV_LOG(DEBUG, "NOT disabling PMD transmitter");
7229                         return;
7230                 }
7231         } else {
7232                 PMD_DRV_LOG(DEBUG, "Enabling PMD transmitter");
7233         }
7234         elink_cl45_write(sc, phy,
7235                          MDIO_PMA_DEVAD, MDIO_PMA_REG_TX_DISABLE, pmd_dis);
7236 }
7237
7238 static uint8_t elink_get_gpio_port(struct elink_params *params)
7239 {
7240         uint8_t gpio_port;
7241         uint32_t swap_val, swap_override;
7242         struct bnx2x_softc *sc = params->sc;
7243         if (CHIP_IS_E2(sc)) {
7244                 gpio_port = SC_PATH(sc);
7245         } else {
7246                 gpio_port = params->port;
7247         }
7248         swap_val = REG_RD(sc, NIG_REG_PORT_SWAP);
7249         swap_override = REG_RD(sc, NIG_REG_STRAP_OVERRIDE);
7250         return gpio_port ^ (swap_val && swap_override);
7251 }
7252
7253 static void elink_sfp_e1e2_set_transmitter(struct elink_params *params,
7254                                            struct elink_phy *phy, uint8_t tx_en)
7255 {
7256         uint16_t val;
7257         uint8_t port = params->port;
7258         struct bnx2x_softc *sc = params->sc;
7259         uint32_t tx_en_mode;
7260
7261         /* Disable/Enable transmitter ( TX laser of the SFP+ module.) */
7262         tx_en_mode = REG_RD(sc, params->shmem_base +
7263                             offsetof(struct shmem_region,
7264                                      dev_info.port_hw_config[port].sfp_ctrl)) &
7265             PORT_HW_CFG_TX_LASER_MASK;
7266         PMD_DRV_LOG(DEBUG, "Setting transmitter tx_en=%x for port %x "
7267                     "mode = %x", tx_en, port, tx_en_mode);
7268         switch (tx_en_mode) {
7269         case PORT_HW_CFG_TX_LASER_MDIO:
7270
7271                 elink_cl45_read(sc, phy,
7272                                 MDIO_PMA_DEVAD,
7273                                 MDIO_PMA_REG_PHY_IDENTIFIER, &val);
7274
7275                 if (tx_en)
7276                         val &= ~(1 << 15);
7277                 else
7278                         val |= (1 << 15);
7279
7280                 elink_cl45_write(sc, phy,
7281                                  MDIO_PMA_DEVAD,
7282                                  MDIO_PMA_REG_PHY_IDENTIFIER, val);
7283                 break;
7284         case PORT_HW_CFG_TX_LASER_GPIO0:
7285         case PORT_HW_CFG_TX_LASER_GPIO1:
7286         case PORT_HW_CFG_TX_LASER_GPIO2:
7287         case PORT_HW_CFG_TX_LASER_GPIO3:
7288                 {
7289                         uint16_t gpio_pin;
7290                         uint8_t gpio_port, gpio_mode;
7291                         if (tx_en)
7292                                 gpio_mode = MISC_REGISTERS_GPIO_OUTPUT_HIGH;
7293                         else
7294                                 gpio_mode = MISC_REGISTERS_GPIO_OUTPUT_LOW;
7295
7296                         gpio_pin = tx_en_mode - PORT_HW_CFG_TX_LASER_GPIO0;
7297                         gpio_port = elink_get_gpio_port(params);
7298                         elink_cb_gpio_write(sc, gpio_pin, gpio_mode, gpio_port);
7299                         break;
7300                 }
7301         default:
7302                 PMD_DRV_LOG(DEBUG, "Invalid TX_LASER_MDIO 0x%x", tx_en_mode);
7303                 break;
7304         }
7305 }
7306
7307 static void elink_sfp_set_transmitter(struct elink_params *params,
7308                                       struct elink_phy *phy, uint8_t tx_en)
7309 {
7310         struct bnx2x_softc *sc = params->sc;
7311         PMD_DRV_LOG(DEBUG, "Setting SFP+ transmitter to %d", tx_en);
7312         if (CHIP_IS_E3(sc))
7313                 elink_sfp_e3_set_transmitter(params, phy, tx_en);
7314         else
7315                 elink_sfp_e1e2_set_transmitter(params, phy, tx_en);
7316 }
7317
7318 static elink_status_t elink_8726_read_sfp_module_eeprom(struct elink_phy *phy,
7319                                                         struct elink_params
7320                                                         *params,
7321                                                         uint8_t dev_addr,
7322                                                         uint16_t addr,
7323                                                         uint8_t byte_cnt,
7324                                                         uint8_t * o_buf,
7325                                                         __rte_unused uint8_t
7326                                                         is_init)
7327 {
7328         struct bnx2x_softc *sc = params->sc;
7329         uint16_t val = 0;
7330         uint16_t i;
7331         if (byte_cnt > ELINK_SFP_EEPROM_PAGE_SIZE) {
7332                 PMD_DRV_LOG(DEBUG, "Reading from eeprom is limited to 0xf");
7333                 return ELINK_STATUS_ERROR;
7334         }
7335         /* Set the read command byte count */
7336         elink_cl45_write(sc, phy,
7337                          MDIO_PMA_DEVAD, MDIO_PMA_REG_SFP_TWO_WIRE_BYTE_CNT,
7338                          (byte_cnt | (dev_addr << 8)));
7339
7340         /* Set the read command address */
7341         elink_cl45_write(sc, phy,
7342                          MDIO_PMA_DEVAD, MDIO_PMA_REG_SFP_TWO_WIRE_MEM_ADDR,
7343                          addr);
7344
7345         /* Activate read command */
7346         elink_cl45_write(sc, phy,
7347                          MDIO_PMA_DEVAD, MDIO_PMA_REG_SFP_TWO_WIRE_CTRL,
7348                          0x2c0f);
7349
7350         /* Wait up to 500us for command complete status */
7351         for (i = 0; i < 100; i++) {
7352                 elink_cl45_read(sc, phy,
7353                                 MDIO_PMA_DEVAD,
7354                                 MDIO_PMA_REG_SFP_TWO_WIRE_CTRL, &val);
7355                 if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) ==
7356                     MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_COMPLETE)
7357                         break;
7358                 DELAY(5);
7359         }
7360
7361         if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) !=
7362             MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_COMPLETE) {
7363                 PMD_DRV_LOG(DEBUG,
7364                             "Got bad status 0x%x when reading from SFP+ EEPROM",
7365                             (val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK));
7366                 return ELINK_STATUS_ERROR;
7367         }
7368
7369         /* Read the buffer */
7370         for (i = 0; i < byte_cnt; i++) {
7371                 elink_cl45_read(sc, phy,
7372                                 MDIO_PMA_DEVAD,
7373                                 MDIO_PMA_REG_8726_TWO_WIRE_DATA_BUF + i, &val);
7374                 o_buf[i] =
7375                     (uint8_t) (val & MDIO_PMA_REG_8726_TWO_WIRE_DATA_MASK);
7376         }
7377
7378         for (i = 0; i < 100; i++) {
7379                 elink_cl45_read(sc, phy,
7380                                 MDIO_PMA_DEVAD,
7381                                 MDIO_PMA_REG_SFP_TWO_WIRE_CTRL, &val);
7382                 if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) ==
7383                     MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_IDLE)
7384                         return ELINK_STATUS_OK;
7385                 DELAY(1000 * 1);
7386         }
7387         return ELINK_STATUS_ERROR;
7388 }
7389
7390 static void elink_warpcore_power_module(struct elink_params *params,
7391                                         uint8_t power)
7392 {
7393         uint32_t pin_cfg;
7394         struct bnx2x_softc *sc = params->sc;
7395
7396         pin_cfg = (REG_RD(sc, params->shmem_base +
7397                           offsetof(struct shmem_region,
7398                                    dev_info.port_hw_config[params->port].
7399                                    e3_sfp_ctrl)) & PORT_HW_CFG_E3_PWR_DIS_MASK)
7400             >> PORT_HW_CFG_E3_PWR_DIS_SHIFT;
7401
7402         if (pin_cfg == PIN_CFG_NA)
7403                 return;
7404         PMD_DRV_LOG(DEBUG, "Setting SFP+ module power to %d using pin cfg %d",
7405                     power, pin_cfg);
7406         /* Low ==> corresponding SFP+ module is powered
7407          * high ==> the SFP+ module is powered down
7408          */
7409         elink_set_cfg_pin(sc, pin_cfg, power ^ 1);
7410 }
7411
7412 static elink_status_t elink_warpcore_read_sfp_module_eeprom(__rte_unused struct
7413                                                             elink_phy *phy,
7414                                                             struct elink_params
7415                                                             *params,
7416                                                             uint8_t dev_addr,
7417                                                             uint16_t addr,
7418                                                             uint8_t byte_cnt,
7419                                                             uint8_t * o_buf,
7420                                                             uint8_t is_init)
7421 {
7422         elink_status_t rc = ELINK_STATUS_OK;
7423         uint8_t i, j = 0, cnt = 0;
7424         uint32_t data_array[4];
7425         uint16_t addr32;
7426         struct bnx2x_softc *sc = params->sc;
7427
7428         if (byte_cnt > ELINK_SFP_EEPROM_PAGE_SIZE) {
7429                 PMD_DRV_LOG(DEBUG,
7430                             "Reading from eeprom is limited to 16 bytes");
7431                 return ELINK_STATUS_ERROR;
7432         }
7433
7434         /* 4 byte aligned address */
7435         addr32 = addr & (~0x3);
7436         do {
7437                 if ((!is_init) && (cnt == I2C_WA_PWR_ITER)) {
7438                         elink_warpcore_power_module(params, 0);
7439                         /* Note that 100us are not enough here */
7440                         DELAY(1000 * 1);
7441                         elink_warpcore_power_module(params, 1);
7442                 }
7443                 rc = elink_bsc_read(params, sc, dev_addr, addr32, 0, byte_cnt,
7444                                     data_array);
7445         } while ((rc != ELINK_STATUS_OK) && (++cnt < I2C_WA_RETRY_CNT));
7446
7447         if (rc == ELINK_STATUS_OK) {
7448                 for (i = (addr - addr32); i < byte_cnt + (addr - addr32); i++) {
7449                         o_buf[j] = *((uint8_t *) data_array + i);
7450                         j++;
7451                 }
7452         }
7453
7454         return rc;
7455 }
7456
7457 static elink_status_t elink_8727_read_sfp_module_eeprom(struct elink_phy *phy,
7458                                                         struct elink_params
7459                                                         *params,
7460                                                         uint8_t dev_addr,
7461                                                         uint16_t addr,
7462                                                         uint8_t byte_cnt,
7463                                                         uint8_t * o_buf,
7464                                                         __rte_unused uint8_t
7465                                                         is_init)
7466 {
7467         struct bnx2x_softc *sc = params->sc;
7468         uint16_t val, i;
7469
7470         if (byte_cnt > ELINK_SFP_EEPROM_PAGE_SIZE) {
7471                 PMD_DRV_LOG(DEBUG, "Reading from eeprom is limited to 0xf");
7472                 return ELINK_STATUS_ERROR;
7473         }
7474
7475         /* Set 2-wire transfer rate of SFP+ module EEPROM
7476          * to 100Khz since some DACs(direct attached cables) do
7477          * not work at 400Khz.
7478          */
7479         elink_cl45_write(sc, phy,
7480                          MDIO_PMA_DEVAD,
7481                          MDIO_PMA_REG_8727_TWO_WIRE_SLAVE_ADDR,
7482                          ((dev_addr << 8) | 1));
7483
7484         /* Need to read from 1.8000 to clear it */
7485         elink_cl45_read(sc, phy,
7486                         MDIO_PMA_DEVAD, MDIO_PMA_REG_SFP_TWO_WIRE_CTRL, &val);
7487
7488         /* Set the read command byte count */
7489         elink_cl45_write(sc, phy,
7490                          MDIO_PMA_DEVAD,
7491                          MDIO_PMA_REG_SFP_TWO_WIRE_BYTE_CNT,
7492                          ((byte_cnt < 2) ? 2 : byte_cnt));
7493
7494         /* Set the read command address */
7495         elink_cl45_write(sc, phy,
7496                          MDIO_PMA_DEVAD,
7497                          MDIO_PMA_REG_SFP_TWO_WIRE_MEM_ADDR, addr);
7498         /* Set the destination address */
7499         elink_cl45_write(sc, phy,
7500                          MDIO_PMA_DEVAD,
7501                          0x8004, MDIO_PMA_REG_8727_TWO_WIRE_DATA_BUF);
7502
7503         /* Activate read command */
7504         elink_cl45_write(sc, phy,
7505                          MDIO_PMA_DEVAD,
7506                          MDIO_PMA_REG_SFP_TWO_WIRE_CTRL, 0x8002);
7507         /* Wait appropriate time for two-wire command to finish before
7508          * polling the status register
7509          */
7510         DELAY(1000 * 1);
7511
7512         /* Wait up to 500us for command complete status */
7513         for (i = 0; i < 100; i++) {
7514                 elink_cl45_read(sc, phy,
7515                                 MDIO_PMA_DEVAD,
7516                                 MDIO_PMA_REG_SFP_TWO_WIRE_CTRL, &val);
7517                 if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) ==
7518                     MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_COMPLETE)
7519                         break;
7520                 DELAY(5);
7521         }
7522
7523         if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) !=
7524             MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_COMPLETE) {
7525                 PMD_DRV_LOG(DEBUG,
7526                             "Got bad status 0x%x when reading from SFP+ EEPROM",
7527                             (val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK));
7528                 return ELINK_STATUS_TIMEOUT;
7529         }
7530
7531         /* Read the buffer */
7532         for (i = 0; i < byte_cnt; i++) {
7533                 elink_cl45_read(sc, phy,
7534                                 MDIO_PMA_DEVAD,
7535                                 MDIO_PMA_REG_8727_TWO_WIRE_DATA_BUF + i, &val);
7536                 o_buf[i] =
7537                     (uint8_t) (val & MDIO_PMA_REG_8727_TWO_WIRE_DATA_MASK);
7538         }
7539
7540         for (i = 0; i < 100; i++) {
7541                 elink_cl45_read(sc, phy,
7542                                 MDIO_PMA_DEVAD,
7543                                 MDIO_PMA_REG_SFP_TWO_WIRE_CTRL, &val);
7544                 if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) ==
7545                     MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_IDLE)
7546                         return ELINK_STATUS_OK;
7547                 DELAY(1000 * 1);
7548         }
7549
7550         return ELINK_STATUS_ERROR;
7551 }
7552
7553 static elink_status_t elink_read_sfp_module_eeprom(struct elink_phy *phy,
7554                                                    struct elink_params *params,
7555                                                    uint8_t dev_addr,
7556                                                    uint16_t addr,
7557                                                    uint16_t byte_cnt,
7558                                                    uint8_t * o_buf)
7559 {
7560         elink_status_t rc = 0;
7561         uint8_t xfer_size;
7562         uint8_t *user_data = o_buf;
7563         read_sfp_module_eeprom_func_p read_func;
7564
7565         if ((dev_addr != 0xa0) && (dev_addr != 0xa2)) {
7566                 PMD_DRV_LOG(DEBUG, "invalid dev_addr 0x%x", dev_addr);
7567                 return ELINK_STATUS_ERROR;
7568         }
7569
7570         switch (phy->type) {
7571         case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X8726:
7572                 read_func = elink_8726_read_sfp_module_eeprom;
7573                 break;
7574         case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X8727:
7575         case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X8722:
7576                 read_func = elink_8727_read_sfp_module_eeprom;
7577                 break;
7578         case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT:
7579                 read_func = elink_warpcore_read_sfp_module_eeprom;
7580                 break;
7581         default:
7582                 return ELINK_OP_NOT_SUPPORTED;
7583         }
7584
7585         while (!rc && (byte_cnt > 0)) {
7586                 xfer_size = (byte_cnt > ELINK_SFP_EEPROM_PAGE_SIZE) ?
7587                     ELINK_SFP_EEPROM_PAGE_SIZE : byte_cnt;
7588                 rc = read_func(phy, params, dev_addr, addr, xfer_size,
7589                                user_data, 0);
7590                 byte_cnt -= xfer_size;
7591                 user_data += xfer_size;
7592                 addr += xfer_size;
7593         }
7594         return rc;
7595 }
7596
7597 static elink_status_t elink_get_edc_mode(struct elink_phy *phy,
7598                                          struct elink_params *params,
7599                                          uint16_t * edc_mode)
7600 {
7601         struct bnx2x_softc *sc = params->sc;
7602         uint32_t sync_offset = 0, phy_idx, media_types;
7603         uint8_t gport, val[2], check_limiting_mode = 0;
7604         *edc_mode = ELINK_EDC_MODE_LIMITING;
7605         phy->media_type = ELINK_ETH_PHY_UNSPECIFIED;
7606         /* First check for copper cable */
7607         if (elink_read_sfp_module_eeprom(phy,
7608                                          params,
7609                                          ELINK_I2C_DEV_ADDR_A0,
7610                                          ELINK_SFP_EEPROM_CON_TYPE_ADDR,
7611                                          2, (uint8_t *) val) != 0) {
7612                 PMD_DRV_LOG(DEBUG, "Failed to read from SFP+ module EEPROM");
7613                 return ELINK_STATUS_ERROR;
7614         }
7615
7616         switch (val[0]) {
7617         case ELINK_SFP_EEPROM_CON_TYPE_VAL_COPPER:
7618                 {
7619                         uint8_t copper_module_type;
7620                         phy->media_type = ELINK_ETH_PHY_DA_TWINAX;
7621                         /* Check if its active cable (includes SFP+ module)
7622                          * of passive cable
7623                          */
7624                         if (elink_read_sfp_module_eeprom(phy,
7625                                                          params,
7626                                                          ELINK_I2C_DEV_ADDR_A0,
7627                                                          ELINK_SFP_EEPROM_FC_TX_TECH_ADDR,
7628                                                          1,
7629                                                          &copper_module_type) !=
7630                             0) {
7631                                 PMD_DRV_LOG(DEBUG,
7632                                             "Failed to read copper-cable-type"
7633                                             " from SFP+ EEPROM");
7634                                 return ELINK_STATUS_ERROR;
7635                         }
7636
7637                         if (copper_module_type &
7638                             ELINK_SFP_EEPROM_FC_TX_TECH_BITMASK_COPPER_ACTIVE) {
7639                                 PMD_DRV_LOG(DEBUG,
7640                                             "Active Copper cable detected");
7641                                 if (phy->type ==
7642                                     PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
7643                                         *edc_mode = ELINK_EDC_MODE_ACTIVE_DAC;
7644                                 else
7645                                         check_limiting_mode = 1;
7646                         } else if (copper_module_type &
7647                                    ELINK_SFP_EEPROM_FC_TX_TECH_BITMASK_COPPER_PASSIVE)
7648                         {
7649                                 PMD_DRV_LOG(DEBUG,
7650                                             "Passive Copper cable detected");
7651                                 *edc_mode = ELINK_EDC_MODE_PASSIVE_DAC;
7652                         } else {
7653                                 PMD_DRV_LOG(DEBUG,
7654                                             "Unknown copper-cable-type 0x%x !!!",
7655                                             copper_module_type);
7656                                 return ELINK_STATUS_ERROR;
7657                         }
7658                         break;
7659                 }
7660         case ELINK_SFP_EEPROM_CON_TYPE_VAL_LC:
7661         case ELINK_SFP_EEPROM_CON_TYPE_VAL_RJ45:
7662                 check_limiting_mode = 1;
7663                 if ((val[1] & (ELINK_SFP_EEPROM_COMP_CODE_SR_MASK |
7664                                ELINK_SFP_EEPROM_COMP_CODE_LR_MASK |
7665                                ELINK_SFP_EEPROM_COMP_CODE_LRM_MASK)) == 0) {
7666                         PMD_DRV_LOG(DEBUG, "1G SFP module detected");
7667                         gport = params->port;
7668                         phy->media_type = ELINK_ETH_PHY_SFP_1G_FIBER;
7669                         if (phy->req_line_speed != ELINK_SPEED_1000) {
7670                                 phy->req_line_speed = ELINK_SPEED_1000;
7671                                 if (!CHIP_IS_E1x(sc)) {
7672                                         gport = SC_PATH(sc) +
7673                                             (params->port << 1);
7674                                 }
7675                                 elink_cb_event_log(sc, ELINK_LOG_ID_NON_10G_MODULE, gport);     //"Warning: Link speed was forced to 1000Mbps."
7676                                 // " Current SFP module in port %d is not"
7677                                 // " compliant with 10G Ethernet",
7678
7679                         }
7680                 } else {
7681                         int idx, cfg_idx = 0;
7682                         PMD_DRV_LOG(DEBUG, "10G Optic module detected");
7683                         for (idx = ELINK_INT_PHY; idx < ELINK_MAX_PHYS; idx++) {
7684                                 if (params->phy[idx].type == phy->type) {
7685                                         cfg_idx = ELINK_LINK_CONFIG_IDX(idx);
7686                                         break;
7687                                 }
7688                         }
7689                         phy->media_type = ELINK_ETH_PHY_SFPP_10G_FIBER;
7690                         phy->req_line_speed = params->req_line_speed[cfg_idx];
7691                 }
7692                 break;
7693         default:
7694                 PMD_DRV_LOG(DEBUG, "Unable to determine module type 0x%x !!!",
7695                             val[0]);
7696                 return ELINK_STATUS_ERROR;
7697         }
7698         sync_offset = params->shmem_base +
7699             offsetof(struct shmem_region,
7700                      dev_info.port_hw_config[params->port].media_type);
7701         media_types = REG_RD(sc, sync_offset);
7702         /* Update media type for non-PMF sync */
7703         for (phy_idx = ELINK_INT_PHY; phy_idx < ELINK_MAX_PHYS; phy_idx++) {
7704                 if (&(params->phy[phy_idx]) == phy) {
7705                         media_types &= ~(PORT_HW_CFG_MEDIA_TYPE_PHY0_MASK <<
7706                                          (PORT_HW_CFG_MEDIA_TYPE_PHY1_SHIFT *
7707                                           phy_idx));
7708                         media_types |=
7709                             ((phy->
7710                               media_type & PORT_HW_CFG_MEDIA_TYPE_PHY0_MASK) <<
7711                              (PORT_HW_CFG_MEDIA_TYPE_PHY1_SHIFT * phy_idx));
7712                         break;
7713                 }
7714         }
7715         REG_WR(sc, sync_offset, media_types);
7716         if (check_limiting_mode) {
7717                 uint8_t options[ELINK_SFP_EEPROM_OPTIONS_SIZE];
7718                 if (elink_read_sfp_module_eeprom(phy,
7719                                                  params,
7720                                                  ELINK_I2C_DEV_ADDR_A0,
7721                                                  ELINK_SFP_EEPROM_OPTIONS_ADDR,
7722                                                  ELINK_SFP_EEPROM_OPTIONS_SIZE,
7723                                                  options) != 0) {
7724                         PMD_DRV_LOG(DEBUG,
7725                                     "Failed to read Option field from module EEPROM");
7726                         return ELINK_STATUS_ERROR;
7727                 }
7728                 if ((options[0] & ELINK_SFP_EEPROM_OPTIONS_LINEAR_RX_OUT_MASK))
7729                         *edc_mode = ELINK_EDC_MODE_LINEAR;
7730                 else
7731                         *edc_mode = ELINK_EDC_MODE_LIMITING;
7732         }
7733         PMD_DRV_LOG(DEBUG, "EDC mode is set to 0x%x", *edc_mode);
7734         return ELINK_STATUS_OK;
7735 }
7736
7737 /* This function read the relevant field from the module (SFP+), and verify it
7738  * is compliant with this board
7739  */
7740 static elink_status_t elink_verify_sfp_module(struct elink_phy *phy,
7741                                               struct elink_params *params)
7742 {
7743         struct bnx2x_softc *sc = params->sc;
7744         uint32_t val, cmd;
7745         uint32_t fw_resp, fw_cmd_param;
7746         char vendor_name[ELINK_SFP_EEPROM_VENDOR_NAME_SIZE + 1];
7747         char vendor_pn[ELINK_SFP_EEPROM_PART_NO_SIZE + 1];
7748         phy->flags &= ~ELINK_FLAGS_SFP_NOT_APPROVED;
7749         val = REG_RD(sc, params->shmem_base +
7750                      offsetof(struct shmem_region,
7751                               dev_info.port_feature_config[params->port].
7752                               config));
7753         if ((val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) ==
7754             PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_NO_ENFORCEMENT) {
7755                 PMD_DRV_LOG(DEBUG, "NOT enforcing module verification");
7756                 return ELINK_STATUS_OK;
7757         }
7758
7759         if (params->feature_config_flags &
7760             ELINK_FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY) {
7761                 /* Use specific phy request */
7762                 cmd = DRV_MSG_CODE_VRFY_SPECIFIC_PHY_OPT_MDL;
7763         } else if (params->feature_config_flags &
7764                    ELINK_FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY) {
7765                 /* Use first phy request only in case of non-dual media */
7766                 if (ELINK_DUAL_MEDIA(params)) {
7767                         PMD_DRV_LOG(DEBUG,
7768                                     "FW does not support OPT MDL verification");
7769                         return ELINK_STATUS_ERROR;
7770                 }
7771                 cmd = DRV_MSG_CODE_VRFY_FIRST_PHY_OPT_MDL;
7772         } else {
7773                 /* No support in OPT MDL detection */
7774                 PMD_DRV_LOG(DEBUG, "FW does not support OPT MDL verification");
7775                 return ELINK_STATUS_ERROR;
7776         }
7777
7778         fw_cmd_param = ELINK_FW_PARAM_SET(phy->addr, phy->type, phy->mdio_ctrl);
7779         fw_resp = elink_cb_fw_command(sc, cmd, fw_cmd_param);
7780         if (fw_resp == FW_MSG_CODE_VRFY_OPT_MDL_SUCCESS) {
7781                 PMD_DRV_LOG(DEBUG, "Approved module");
7782                 return ELINK_STATUS_OK;
7783         }
7784
7785         /* Format the warning message */
7786         if (elink_read_sfp_module_eeprom(phy,
7787                                          params,
7788                                          ELINK_I2C_DEV_ADDR_A0,
7789                                          ELINK_SFP_EEPROM_VENDOR_NAME_ADDR,
7790                                          ELINK_SFP_EEPROM_VENDOR_NAME_SIZE,
7791                                          (uint8_t *) vendor_name))
7792                 vendor_name[0] = '\0';
7793         else
7794                 vendor_name[ELINK_SFP_EEPROM_VENDOR_NAME_SIZE] = '\0';
7795         if (elink_read_sfp_module_eeprom(phy,
7796                                          params,
7797                                          ELINK_I2C_DEV_ADDR_A0,
7798                                          ELINK_SFP_EEPROM_PART_NO_ADDR,
7799                                          ELINK_SFP_EEPROM_PART_NO_SIZE,
7800                                          (uint8_t *) vendor_pn))
7801                 vendor_pn[0] = '\0';
7802         else
7803                 vendor_pn[ELINK_SFP_EEPROM_PART_NO_SIZE] = '\0';
7804
7805         elink_cb_event_log(sc, ELINK_LOG_ID_UNQUAL_IO_MODULE, params->port, vendor_name, vendor_pn);    // "Warning: Unqualified SFP+ module detected,"
7806         // " Port %d from %s part number %s",
7807
7808         if ((val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) !=
7809             PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_WARNING_MSG)
7810                 phy->flags |= ELINK_FLAGS_SFP_NOT_APPROVED;
7811         return ELINK_STATUS_ERROR;
7812 }
7813
7814 static elink_status_t elink_wait_for_sfp_module_initialized(struct elink_phy
7815                                                             *phy,
7816                                                             struct elink_params
7817                                                             *params)
7818 {
7819         uint8_t val;
7820         elink_status_t rc;
7821         uint16_t timeout;
7822         /* Initialization time after hot-plug may take up to 300ms for
7823          * some phys type ( e.g. JDSU )
7824          */
7825
7826         for (timeout = 0; timeout < 60; timeout++) {
7827                 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
7828                         rc = elink_warpcore_read_sfp_module_eeprom(phy, params,
7829                                                                    ELINK_I2C_DEV_ADDR_A0,
7830                                                                    1, 1, &val,
7831                                                                    1);
7832                 else
7833                         rc = elink_read_sfp_module_eeprom(phy, params,
7834                                                           ELINK_I2C_DEV_ADDR_A0,
7835                                                           1, 1, &val);
7836                 if (rc == 0) {
7837                         PMD_DRV_LOG(DEBUG,
7838                                     "SFP+ module initialization took %d ms",
7839                                     timeout * 5);
7840                         return ELINK_STATUS_OK;
7841                 }
7842                 DELAY(1000 * 5);
7843         }
7844         rc = elink_read_sfp_module_eeprom(phy, params, ELINK_I2C_DEV_ADDR_A0,
7845                                           1, 1, &val);
7846         return rc;
7847 }
7848
7849 static void elink_8727_power_module(struct bnx2x_softc *sc,
7850                                     struct elink_phy *phy, uint8_t is_power_up)
7851 {
7852         /* Make sure GPIOs are not using for LED mode */
7853         uint16_t val;
7854         /* In the GPIO register, bit 4 is use to determine if the GPIOs are
7855          * operating as INPUT or as OUTPUT. Bit 1 is for input, and 0 for
7856          * output
7857          * Bits 0-1 determine the GPIOs value for OUTPUT in case bit 4 val is 0
7858          * Bits 8-9 determine the GPIOs value for INPUT in case bit 4 val is 1
7859          * where the 1st bit is the over-current(only input), and 2nd bit is
7860          * for power( only output )
7861          *
7862          * In case of NOC feature is disabled and power is up, set GPIO control
7863          *  as input to enable listening of over-current indication
7864          */
7865         if (phy->flags & ELINK_FLAGS_NOC)
7866                 return;
7867         if (is_power_up)
7868                 val = (1 << 4);
7869         else
7870                 /* Set GPIO control to OUTPUT, and set the power bit
7871                  * to according to the is_power_up
7872                  */
7873                 val = (1 << 1);
7874
7875         elink_cl45_write(sc, phy,
7876                          MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_GPIO_CTRL, val);
7877 }
7878
7879 static elink_status_t elink_8726_set_limiting_mode(struct bnx2x_softc *sc,
7880                                                    struct elink_phy *phy,
7881                                                    uint16_t edc_mode)
7882 {
7883         uint16_t cur_limiting_mode;
7884
7885         elink_cl45_read(sc, phy,
7886                         MDIO_PMA_DEVAD,
7887                         MDIO_PMA_REG_ROM_VER2, &cur_limiting_mode);
7888         PMD_DRV_LOG(DEBUG, "Current Limiting mode is 0x%x", cur_limiting_mode);
7889
7890         if (edc_mode == ELINK_EDC_MODE_LIMITING) {
7891                 PMD_DRV_LOG(DEBUG, "Setting LIMITING MODE");
7892                 elink_cl45_write(sc, phy,
7893                                  MDIO_PMA_DEVAD,
7894                                  MDIO_PMA_REG_ROM_VER2,
7895                                  ELINK_EDC_MODE_LIMITING);
7896         } else {                /* LRM mode ( default ) */
7897
7898                 PMD_DRV_LOG(DEBUG, "Setting LRM MODE");
7899
7900                 /* Changing to LRM mode takes quite few seconds. So do it only
7901                  * if current mode is limiting (default is LRM)
7902                  */
7903                 if (cur_limiting_mode != ELINK_EDC_MODE_LIMITING)
7904                         return ELINK_STATUS_OK;
7905
7906                 elink_cl45_write(sc, phy,
7907                                  MDIO_PMA_DEVAD, MDIO_PMA_REG_LRM_MODE, 0);
7908                 elink_cl45_write(sc, phy,
7909                                  MDIO_PMA_DEVAD, MDIO_PMA_REG_ROM_VER2, 0x128);
7910                 elink_cl45_write(sc, phy,
7911                                  MDIO_PMA_DEVAD,
7912                                  MDIO_PMA_REG_MISC_CTRL0, 0x4008);
7913                 elink_cl45_write(sc, phy,
7914                                  MDIO_PMA_DEVAD, MDIO_PMA_REG_LRM_MODE, 0xaaaa);
7915         }
7916         return ELINK_STATUS_OK;
7917 }
7918
7919 static elink_status_t elink_8727_set_limiting_mode(struct bnx2x_softc *sc,
7920                                                    struct elink_phy *phy,
7921                                                    uint16_t edc_mode)
7922 {
7923         uint16_t phy_identifier;
7924         uint16_t rom_ver2_val;
7925         elink_cl45_read(sc, phy,
7926                         MDIO_PMA_DEVAD,
7927                         MDIO_PMA_REG_PHY_IDENTIFIER, &phy_identifier);
7928
7929         elink_cl45_write(sc, phy,
7930                          MDIO_PMA_DEVAD,
7931                          MDIO_PMA_REG_PHY_IDENTIFIER,
7932                          (phy_identifier & ~(1 << 9)));
7933
7934         elink_cl45_read(sc, phy,
7935                         MDIO_PMA_DEVAD, MDIO_PMA_REG_ROM_VER2, &rom_ver2_val);
7936         /* Keep the MSB 8-bits, and set the LSB 8-bits with the edc_mode */
7937         elink_cl45_write(sc, phy,
7938                          MDIO_PMA_DEVAD,
7939                          MDIO_PMA_REG_ROM_VER2,
7940                          (rom_ver2_val & 0xff00) | (edc_mode & 0x00ff));
7941
7942         elink_cl45_write(sc, phy,
7943                          MDIO_PMA_DEVAD,
7944                          MDIO_PMA_REG_PHY_IDENTIFIER,
7945                          (phy_identifier | (1 << 9)));
7946
7947         return ELINK_STATUS_OK;
7948 }
7949
7950 static void elink_8727_specific_func(struct elink_phy *phy,
7951                                      struct elink_params *params,
7952                                      uint32_t action)
7953 {
7954         struct bnx2x_softc *sc = params->sc;
7955         uint16_t val;
7956         switch (action) {
7957         case ELINK_DISABLE_TX:
7958                 elink_sfp_set_transmitter(params, phy, 0);
7959                 break;
7960         case ELINK_ENABLE_TX:
7961                 if (!(phy->flags & ELINK_FLAGS_SFP_NOT_APPROVED))
7962                         elink_sfp_set_transmitter(params, phy, 1);
7963                 break;
7964         case ELINK_PHY_INIT:
7965                 elink_cl45_write(sc, phy,
7966                                  MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXCTRL,
7967                                  (1 << 2) | (1 << 5));
7968                 elink_cl45_write(sc, phy,
7969                                  MDIO_PMA_DEVAD, MDIO_PMA_LASI_TXCTRL, 0);
7970                 elink_cl45_write(sc, phy,
7971                                  MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL, 0x0006);
7972                 /* Make MOD_ABS give interrupt on change */
7973                 elink_cl45_read(sc, phy, MDIO_PMA_DEVAD,
7974                                 MDIO_PMA_REG_8727_PCS_OPT_CTRL, &val);
7975                 val |= (1 << 12);
7976                 if (phy->flags & ELINK_FLAGS_NOC)
7977                         val |= (3 << 5);
7978                 /* Set 8727 GPIOs to input to allow reading from the 8727 GPIO0
7979                  * status which reflect SFP+ module over-current
7980                  */
7981                 if (!(phy->flags & ELINK_FLAGS_NOC))
7982                         val &= 0xff8f;  /* Reset bits 4-6 */
7983                 elink_cl45_write(sc, phy,
7984                                  MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_PCS_OPT_CTRL,
7985                                  val);
7986                 break;
7987         default:
7988                 PMD_DRV_LOG(DEBUG, "Function 0x%x not supported by 8727",
7989                             action);
7990                 return;
7991         }
7992 }
7993
7994 static void elink_set_e1e2_module_fault_led(struct elink_params *params,
7995                                             uint8_t gpio_mode)
7996 {
7997         struct bnx2x_softc *sc = params->sc;
7998
7999         uint32_t fault_led_gpio = REG_RD(sc, params->shmem_base +
8000                                          offsetof(struct shmem_region,
8001                                                   dev_info.
8002                                                   port_hw_config[params->port].
8003                                                   sfp_ctrl)) &
8004             PORT_HW_CFG_FAULT_MODULE_LED_MASK;
8005         switch (fault_led_gpio) {
8006         case PORT_HW_CFG_FAULT_MODULE_LED_DISABLED:
8007                 return;
8008         case PORT_HW_CFG_FAULT_MODULE_LED_GPIO0:
8009         case PORT_HW_CFG_FAULT_MODULE_LED_GPIO1:
8010         case PORT_HW_CFG_FAULT_MODULE_LED_GPIO2:
8011         case PORT_HW_CFG_FAULT_MODULE_LED_GPIO3:
8012                 {
8013                         uint8_t gpio_port = elink_get_gpio_port(params);
8014                         uint16_t gpio_pin = fault_led_gpio -
8015                             PORT_HW_CFG_FAULT_MODULE_LED_GPIO0;
8016                         PMD_DRV_LOG(DEBUG, "Set fault module-detected led "
8017                                     "pin %x port %x mode %x",
8018                                     gpio_pin, gpio_port, gpio_mode);
8019                         elink_cb_gpio_write(sc, gpio_pin, gpio_mode, gpio_port);
8020                 }
8021                 break;
8022         default:
8023                 PMD_DRV_LOG(DEBUG, "Error: Invalid fault led mode 0x%x",
8024                             fault_led_gpio);
8025         }
8026 }
8027
8028 static void elink_set_e3_module_fault_led(struct elink_params *params,
8029                                           uint8_t gpio_mode)
8030 {
8031         uint32_t pin_cfg;
8032         uint8_t port = params->port;
8033         struct bnx2x_softc *sc = params->sc;
8034         pin_cfg = (REG_RD(sc, params->shmem_base +
8035                           offsetof(struct shmem_region,
8036                                    dev_info.port_hw_config[port].e3_sfp_ctrl)) &
8037                    PORT_HW_CFG_E3_FAULT_MDL_LED_MASK) >>
8038             PORT_HW_CFG_E3_FAULT_MDL_LED_SHIFT;
8039         PMD_DRV_LOG(DEBUG, "Setting Fault LED to %d using pin cfg %d",
8040                     gpio_mode, pin_cfg);
8041         elink_set_cfg_pin(sc, pin_cfg, gpio_mode);
8042 }
8043
8044 static void elink_set_sfp_module_fault_led(struct elink_params *params,
8045                                            uint8_t gpio_mode)
8046 {
8047         struct bnx2x_softc *sc = params->sc;
8048         PMD_DRV_LOG(DEBUG, "Setting SFP+ module fault LED to %d", gpio_mode);
8049         if (CHIP_IS_E3(sc)) {
8050                 /* Low ==> if SFP+ module is supported otherwise
8051                  * High ==> if SFP+ module is not on the approved vendor list
8052                  */
8053                 elink_set_e3_module_fault_led(params, gpio_mode);
8054         } else
8055                 elink_set_e1e2_module_fault_led(params, gpio_mode);
8056 }
8057
8058 static void elink_warpcore_hw_reset(__rte_unused struct elink_phy *phy,
8059                                     struct elink_params *params)
8060 {
8061         struct bnx2x_softc *sc = params->sc;
8062         elink_warpcore_power_module(params, 0);
8063         /* Put Warpcore in low power mode */
8064         REG_WR(sc, MISC_REG_WC0_RESET, 0x0c0e);
8065
8066         /* Put LCPLL in low power mode */
8067         REG_WR(sc, MISC_REG_LCPLL_E40_PWRDWN, 1);
8068         REG_WR(sc, MISC_REG_LCPLL_E40_RESETB_ANA, 0);
8069         REG_WR(sc, MISC_REG_LCPLL_E40_RESETB_DIG, 0);
8070 }
8071
8072 static void elink_power_sfp_module(struct elink_params *params,
8073                                    struct elink_phy *phy, uint8_t power)
8074 {
8075         PMD_DRV_LOG(DEBUG, "Setting SFP+ power to %x", power);
8076
8077         switch (phy->type) {
8078         case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X8727:
8079         case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X8722:
8080                 elink_8727_power_module(params->sc, phy, power);
8081                 break;
8082         case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT:
8083                 elink_warpcore_power_module(params, power);
8084                 break;
8085         default:
8086                 break;
8087         }
8088 }
8089
8090 static void elink_warpcore_set_limiting_mode(struct elink_params *params,
8091                                              struct elink_phy *phy,
8092                                              uint16_t edc_mode)
8093 {
8094         uint16_t val = 0;
8095         uint16_t mode = MDIO_WC_REG_UC_INFO_B1_FIRMWARE_MODE_DEFAULT;
8096         struct bnx2x_softc *sc = params->sc;
8097
8098         uint8_t lane = elink_get_warpcore_lane(params);
8099         /* This is a global register which controls all lanes */
8100         elink_cl45_read(sc, phy, MDIO_WC_DEVAD,
8101                         MDIO_WC_REG_UC_INFO_B1_FIRMWARE_MODE, &val);
8102         val &= ~(0xf << (lane << 2));
8103
8104         switch (edc_mode) {
8105         case ELINK_EDC_MODE_LINEAR:
8106         case ELINK_EDC_MODE_LIMITING:
8107                 mode = MDIO_WC_REG_UC_INFO_B1_FIRMWARE_MODE_DEFAULT;
8108                 break;
8109         case ELINK_EDC_MODE_PASSIVE_DAC:
8110         case ELINK_EDC_MODE_ACTIVE_DAC:
8111                 mode = MDIO_WC_REG_UC_INFO_B1_FIRMWARE_MODE_SFP_DAC;
8112                 break;
8113         default:
8114                 break;
8115         }
8116
8117         val |= (mode << (lane << 2));
8118         elink_cl45_write(sc, phy, MDIO_WC_DEVAD,
8119                          MDIO_WC_REG_UC_INFO_B1_FIRMWARE_MODE, val);
8120         /* A must read */
8121         elink_cl45_read(sc, phy, MDIO_WC_DEVAD,
8122                         MDIO_WC_REG_UC_INFO_B1_FIRMWARE_MODE, &val);
8123
8124         /* Restart microcode to re-read the new mode */
8125         elink_warpcore_reset_lane(sc, phy, 1);
8126         elink_warpcore_reset_lane(sc, phy, 0);
8127
8128 }
8129
8130 static void elink_set_limiting_mode(struct elink_params *params,
8131                                     struct elink_phy *phy, uint16_t edc_mode)
8132 {
8133         switch (phy->type) {
8134         case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X8726:
8135                 elink_8726_set_limiting_mode(params->sc, phy, edc_mode);
8136                 break;
8137         case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X8727:
8138         case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X8722:
8139                 elink_8727_set_limiting_mode(params->sc, phy, edc_mode);
8140                 break;
8141         case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT:
8142                 elink_warpcore_set_limiting_mode(params, phy, edc_mode);
8143                 break;
8144         }
8145 }
8146
8147 static elink_status_t elink_sfp_module_detection(struct elink_phy *phy,
8148                                                  struct elink_params *params)
8149 {
8150         struct bnx2x_softc *sc = params->sc;
8151         uint16_t edc_mode;
8152         elink_status_t rc = ELINK_STATUS_OK;
8153
8154         uint32_t val = REG_RD(sc, params->shmem_base +
8155                               offsetof(struct shmem_region,
8156                                        dev_info.port_feature_config[params->
8157                                                                     port].
8158                                        config));
8159         /* Enabled transmitter by default */
8160         elink_sfp_set_transmitter(params, phy, 1);
8161         PMD_DRV_LOG(DEBUG, "SFP+ module plugged in/out detected on port %d",
8162                     params->port);
8163         /* Power up module */
8164         elink_power_sfp_module(params, phy, 1);
8165         if (elink_get_edc_mode(phy, params, &edc_mode) != 0) {
8166                 PMD_DRV_LOG(DEBUG, "Failed to get valid module type");
8167                 return ELINK_STATUS_ERROR;
8168         } else if (elink_verify_sfp_module(phy, params) != 0) {
8169                 /* Check SFP+ module compatibility */
8170                 PMD_DRV_LOG(DEBUG, "Module verification failed!!");
8171                 rc = ELINK_STATUS_ERROR;
8172                 /* Turn on fault module-detected led */
8173                 elink_set_sfp_module_fault_led(params,
8174                                                MISC_REGISTERS_GPIO_HIGH);
8175
8176                 /* Check if need to power down the SFP+ module */
8177                 if ((val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) ==
8178                     PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_POWER_DOWN) {
8179                         PMD_DRV_LOG(DEBUG, "Shutdown SFP+ module!!");
8180                         elink_power_sfp_module(params, phy, 0);
8181                         return rc;
8182                 }
8183         } else {
8184                 /* Turn off fault module-detected led */
8185                 elink_set_sfp_module_fault_led(params, MISC_REGISTERS_GPIO_LOW);
8186         }
8187
8188         /* Check and set limiting mode / LRM mode on 8726. On 8727 it
8189          * is done automatically
8190          */
8191         elink_set_limiting_mode(params, phy, edc_mode);
8192
8193         /* Disable transmit for this module if the module is not approved, and
8194          * laser needs to be disabled.
8195          */
8196         if ((rc != 0) &&
8197             ((val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) ==
8198              PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_DISABLE_TX_LASER))
8199                 elink_sfp_set_transmitter(params, phy, 0);
8200
8201         return rc;
8202 }
8203
8204 void elink_handle_module_detect_int(struct elink_params *params)
8205 {
8206         struct bnx2x_softc *sc = params->sc;
8207         struct elink_phy *phy;
8208         uint32_t gpio_val;
8209         uint8_t gpio_num, gpio_port;
8210         if (CHIP_IS_E3(sc)) {
8211                 phy = &params->phy[ELINK_INT_PHY];
8212                 /* Always enable TX laser,will be disabled in case of fault */
8213                 elink_sfp_set_transmitter(params, phy, 1);
8214         } else {
8215                 phy = &params->phy[ELINK_EXT_PHY1];
8216         }
8217         if (elink_get_mod_abs_int_cfg(sc, params->shmem_base,
8218                                       params->port, &gpio_num, &gpio_port) ==
8219             ELINK_STATUS_ERROR) {
8220                 PMD_DRV_LOG(DEBUG, "Failed to get MOD_ABS interrupt config");
8221                 return;
8222         }
8223
8224         /* Set valid module led off */
8225         elink_set_sfp_module_fault_led(params, MISC_REGISTERS_GPIO_HIGH);
8226
8227         /* Get current gpio val reflecting module plugged in / out */
8228         gpio_val = elink_cb_gpio_read(sc, gpio_num, gpio_port);
8229
8230         /* Call the handling function in case module is detected */
8231         if (gpio_val == 0) {
8232                 elink_set_mdio_emac_per_phy(sc, params);
8233                 elink_set_aer_mmd(params, phy);
8234
8235                 elink_power_sfp_module(params, phy, 1);
8236                 elink_cb_gpio_int_write(sc, gpio_num,
8237                                         MISC_REGISTERS_GPIO_INT_OUTPUT_CLR,
8238                                         gpio_port);
8239                 if (elink_wait_for_sfp_module_initialized(phy, params) == 0) {
8240                         elink_sfp_module_detection(phy, params);
8241                         if (CHIP_IS_E3(sc)) {
8242                                 uint16_t rx_tx_in_reset;
8243                                 /* In case WC is out of reset, reconfigure the
8244                                  * link speed while taking into account 1G
8245                                  * module limitation.
8246                                  */
8247                                 elink_cl45_read(sc, phy,
8248                                                 MDIO_WC_DEVAD,
8249                                                 MDIO_WC_REG_DIGITAL5_MISC6,
8250                                                 &rx_tx_in_reset);
8251                                 if ((!rx_tx_in_reset) &&
8252                                     (params->link_flags &
8253                                      ELINK_PHY_INITIALIZED)) {
8254                                         elink_warpcore_reset_lane(sc, phy, 1);
8255                                         elink_warpcore_config_sfi(phy, params);
8256                                         elink_warpcore_reset_lane(sc, phy, 0);
8257                                 }
8258                         }
8259                 } else {
8260                         PMD_DRV_LOG(DEBUG, "SFP+ module is not initialized");
8261                 }
8262         } else {
8263                 elink_cb_gpio_int_write(sc, gpio_num,
8264                                         MISC_REGISTERS_GPIO_INT_OUTPUT_SET,
8265                                         gpio_port);
8266                 /* Module was plugged out.
8267                  * Disable transmit for this module
8268                  */
8269                 phy->media_type = ELINK_ETH_PHY_NOT_PRESENT;
8270         }
8271 }
8272
8273 /******************************************************************/
8274 /*              Used by 8706 and 8727                             */
8275 /******************************************************************/
8276 static void elink_sfp_mask_fault(struct bnx2x_softc *sc,
8277                                  struct elink_phy *phy,
8278                                  uint16_t alarm_status_offset,
8279                                  uint16_t alarm_ctrl_offset)
8280 {
8281         uint16_t alarm_status, val;
8282         elink_cl45_read(sc, phy,
8283                         MDIO_PMA_DEVAD, alarm_status_offset, &alarm_status);
8284         elink_cl45_read(sc, phy,
8285                         MDIO_PMA_DEVAD, alarm_status_offset, &alarm_status);
8286         /* Mask or enable the fault event. */
8287         elink_cl45_read(sc, phy, MDIO_PMA_DEVAD, alarm_ctrl_offset, &val);
8288         if (alarm_status & (1 << 0))
8289                 val &= ~(1 << 0);
8290         else
8291                 val |= (1 << 0);
8292         elink_cl45_write(sc, phy, MDIO_PMA_DEVAD, alarm_ctrl_offset, val);
8293 }
8294
8295 /******************************************************************/
8296 /*              common BNX2X8706/BNX2X8726 PHY SECTION            */
8297 /******************************************************************/
8298 static uint8_t elink_8706_8726_read_status(struct elink_phy *phy,
8299                                            struct elink_params *params,
8300                                            struct elink_vars *vars)
8301 {
8302         uint8_t link_up = 0;
8303         uint16_t val1, val2, rx_sd, pcs_status;
8304         struct bnx2x_softc *sc = params->sc;
8305         PMD_DRV_LOG(DEBUG, "XGXS 8706/8726");
8306         /* Clear RX Alarm */
8307         elink_cl45_read(sc, phy, MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXSTAT, &val2);
8308
8309         elink_sfp_mask_fault(sc, phy, MDIO_PMA_LASI_TXSTAT,
8310                              MDIO_PMA_LASI_TXCTRL);
8311
8312         /* Clear LASI indication */
8313         elink_cl45_read(sc, phy, MDIO_PMA_DEVAD, MDIO_PMA_LASI_STAT, &val1);
8314         elink_cl45_read(sc, phy, MDIO_PMA_DEVAD, MDIO_PMA_LASI_STAT, &val2);
8315         PMD_DRV_LOG(DEBUG, "8706/8726 LASI status 0x%x--> 0x%x", val1, val2);
8316
8317         elink_cl45_read(sc, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_SD, &rx_sd);
8318         elink_cl45_read(sc, phy,
8319                         MDIO_PCS_DEVAD, MDIO_PCS_REG_STATUS, &pcs_status);
8320         elink_cl45_read(sc, phy, MDIO_AN_DEVAD, MDIO_AN_REG_LINK_STATUS, &val2);
8321         elink_cl45_read(sc, phy, MDIO_AN_DEVAD, MDIO_AN_REG_LINK_STATUS, &val2);
8322
8323         PMD_DRV_LOG(DEBUG, "8706/8726 rx_sd 0x%x pcs_status 0x%x 1Gbps"
8324                     " link_status 0x%x", rx_sd, pcs_status, val2);
8325         /* Link is up if both bit 0 of pmd_rx_sd and bit 0 of pcs_status
8326          * are set, or if the autoneg bit 1 is set
8327          */
8328         link_up = ((rx_sd & pcs_status & 0x1) || (val2 & (1 << 1)));
8329         if (link_up) {
8330                 if (val2 & (1 << 1))
8331                         vars->line_speed = ELINK_SPEED_1000;
8332                 else
8333                         vars->line_speed = ELINK_SPEED_10000;
8334                 elink_ext_phy_resolve_fc(phy, params, vars);
8335                 vars->duplex = DUPLEX_FULL;
8336         }
8337
8338         /* Capture 10G link fault. Read twice to clear stale value. */
8339         if (vars->line_speed == ELINK_SPEED_10000) {
8340                 elink_cl45_read(sc, phy, MDIO_PMA_DEVAD,
8341                                 MDIO_PMA_LASI_TXSTAT, &val1);
8342                 elink_cl45_read(sc, phy, MDIO_PMA_DEVAD,
8343                                 MDIO_PMA_LASI_TXSTAT, &val1);
8344                 if (val1 & (1 << 0))
8345                         vars->fault_detected = 1;
8346         }
8347
8348         return link_up;
8349 }
8350
8351 /******************************************************************/
8352 /*                      BNX2X8706 PHY SECTION                     */
8353 /******************************************************************/
8354 static uint8_t elink_8706_config_init(struct elink_phy *phy,
8355                                       struct elink_params *params,
8356                                       __rte_unused struct elink_vars *vars)
8357 {
8358         uint32_t tx_en_mode;
8359         uint16_t cnt, val, tmp1;
8360         struct bnx2x_softc *sc = params->sc;
8361
8362         elink_cb_gpio_write(sc, MISC_REGISTERS_GPIO_2,
8363                             MISC_REGISTERS_GPIO_OUTPUT_HIGH, params->port);
8364         /* HW reset */
8365         elink_ext_phy_hw_reset(sc, params->port);
8366         elink_cl45_write(sc, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0xa040);
8367         elink_wait_reset_complete(sc, phy, params);
8368
8369         /* Wait until fw is loaded */
8370         for (cnt = 0; cnt < 100; cnt++) {
8371                 elink_cl45_read(sc, phy,
8372                                 MDIO_PMA_DEVAD, MDIO_PMA_REG_ROM_VER1, &val);
8373                 if (val)
8374                         break;
8375                 DELAY(1000 * 10);
8376         }
8377         PMD_DRV_LOG(DEBUG, "XGXS 8706 is initialized after %d ms", cnt);
8378         if ((params->feature_config_flags &
8379              ELINK_FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED)) {
8380                 uint8_t i;
8381                 uint16_t reg;
8382                 for (i = 0; i < 4; i++) {
8383                         reg = MDIO_XS_8706_REG_BANK_RX0 +
8384                             i * (MDIO_XS_8706_REG_BANK_RX1 -
8385                                  MDIO_XS_8706_REG_BANK_RX0);
8386                         elink_cl45_read(sc, phy, MDIO_XS_DEVAD, reg, &val);
8387                         /* Clear first 3 bits of the control */
8388                         val &= ~0x7;
8389                         /* Set control bits according to configuration */
8390                         val |= (phy->rx_preemphasis[i] & 0x7);
8391                         PMD_DRV_LOG(DEBUG, "Setting RX Equalizer to BNX2X8706"
8392                                     " reg 0x%x <-- val 0x%x", reg, val);
8393                         elink_cl45_write(sc, phy, MDIO_XS_DEVAD, reg, val);
8394                 }
8395         }
8396         /* Force speed */
8397         if (phy->req_line_speed == ELINK_SPEED_10000) {
8398                 PMD_DRV_LOG(DEBUG, "XGXS 8706 force 10Gbps");
8399
8400                 elink_cl45_write(sc, phy,
8401                                  MDIO_PMA_DEVAD,
8402                                  MDIO_PMA_REG_DIGITAL_CTRL, 0x400);
8403                 elink_cl45_write(sc, phy,
8404                                  MDIO_PMA_DEVAD, MDIO_PMA_LASI_TXCTRL, 0);
8405                 /* Arm LASI for link and Tx fault. */
8406                 elink_cl45_write(sc, phy,
8407                                  MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL, 3);
8408         } else {
8409                 /* Force 1Gbps using autoneg with 1G advertisement */
8410
8411                 /* Allow CL37 through CL73 */
8412                 PMD_DRV_LOG(DEBUG, "XGXS 8706 AutoNeg");
8413                 elink_cl45_write(sc, phy,
8414                                  MDIO_AN_DEVAD, MDIO_AN_REG_CL37_CL73, 0x040c);
8415
8416                 /* Enable Full-Duplex advertisement on CL37 */
8417                 elink_cl45_write(sc, phy,
8418                                  MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LP, 0x0020);
8419                 /* Enable CL37 AN */
8420                 elink_cl45_write(sc, phy,
8421                                  MDIO_AN_DEVAD, MDIO_AN_REG_CL37_AN, 0x1000);
8422                 /* 1G support */
8423                 elink_cl45_write(sc, phy,
8424                                  MDIO_AN_DEVAD, MDIO_AN_REG_ADV, (1 << 5));
8425
8426                 /* Enable clause 73 AN */
8427                 elink_cl45_write(sc, phy,
8428                                  MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x1200);
8429                 elink_cl45_write(sc, phy,
8430                                  MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXCTRL, 0x0400);
8431                 elink_cl45_write(sc, phy,
8432                                  MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL, 0x0004);
8433         }
8434         elink_save_bnx2x_spirom_ver(sc, phy, params->port);
8435
8436         /* If TX Laser is controlled by GPIO_0, do not let PHY go into low
8437          * power mode, if TX Laser is disabled
8438          */
8439
8440         tx_en_mode = REG_RD(sc, params->shmem_base +
8441                             offsetof(struct shmem_region,
8442                                      dev_info.port_hw_config[params->port].
8443                                      sfp_ctrl))
8444         & PORT_HW_CFG_TX_LASER_MASK;
8445
8446         if (tx_en_mode == PORT_HW_CFG_TX_LASER_GPIO0) {
8447                 PMD_DRV_LOG(DEBUG, "Enabling TXONOFF_PWRDN_DIS");
8448                 elink_cl45_read(sc, phy,
8449                                 MDIO_PMA_DEVAD, MDIO_PMA_REG_DIGITAL_CTRL,
8450                                 &tmp1);
8451                 tmp1 |= 0x1;
8452                 elink_cl45_write(sc, phy,
8453                                  MDIO_PMA_DEVAD, MDIO_PMA_REG_DIGITAL_CTRL,
8454                                  tmp1);
8455         }
8456
8457         return ELINK_STATUS_OK;
8458 }
8459
8460 static elink_status_t elink_8706_read_status(struct elink_phy *phy,
8461                                              struct elink_params *params,
8462                                              struct elink_vars *vars)
8463 {
8464         return elink_8706_8726_read_status(phy, params, vars);
8465 }
8466
8467 /******************************************************************/
8468 /*                      BNX2X8726 PHY SECTION                     */
8469 /******************************************************************/
8470 static void elink_8726_config_loopback(struct elink_phy *phy,
8471                                        struct elink_params *params)
8472 {
8473         struct bnx2x_softc *sc = params->sc;
8474         PMD_DRV_LOG(DEBUG, "PMA/PMD ext_phy_loopback: 8726");
8475         elink_cl45_write(sc, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x0001);
8476 }
8477
8478 static void elink_8726_external_rom_boot(struct elink_phy *phy,
8479                                          struct elink_params *params)
8480 {
8481         struct bnx2x_softc *sc = params->sc;
8482         /* Need to wait 100ms after reset */
8483         DELAY(1000 * 100);
8484
8485         /* Micro controller re-boot */
8486         elink_cl45_write(sc, phy,
8487                          MDIO_PMA_DEVAD, MDIO_PMA_REG_GEN_CTRL, 0x018B);
8488
8489         /* Set soft reset */
8490         elink_cl45_write(sc, phy,
8491                          MDIO_PMA_DEVAD,
8492                          MDIO_PMA_REG_GEN_CTRL,
8493                          MDIO_PMA_REG_GEN_CTRL_ROM_MICRO_RESET);
8494
8495         elink_cl45_write(sc, phy,
8496                          MDIO_PMA_DEVAD, MDIO_PMA_REG_MISC_CTRL1, 0x0001);
8497
8498         elink_cl45_write(sc, phy,
8499                          MDIO_PMA_DEVAD,
8500                          MDIO_PMA_REG_GEN_CTRL,
8501                          MDIO_PMA_REG_GEN_CTRL_ROM_RESET_INTERNAL_MP);
8502
8503         /* Wait for 150ms for microcode load */
8504         DELAY(1000 * 150);
8505
8506         /* Disable serial boot control, tristates pins SS_N, SCK, MOSI, MISO */
8507         elink_cl45_write(sc, phy,
8508                          MDIO_PMA_DEVAD, MDIO_PMA_REG_MISC_CTRL1, 0x0000);
8509
8510         DELAY(1000 * 200);
8511         elink_save_bnx2x_spirom_ver(sc, phy, params->port);
8512 }
8513
8514 static uint8_t elink_8726_read_status(struct elink_phy *phy,
8515                                       struct elink_params *params,
8516                                       struct elink_vars *vars)
8517 {
8518         struct bnx2x_softc *sc = params->sc;
8519         uint16_t val1;
8520         uint8_t link_up = elink_8706_8726_read_status(phy, params, vars);
8521         if (link_up) {
8522                 elink_cl45_read(sc, phy,
8523                                 MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER,
8524                                 &val1);
8525                 if (val1 & (1 << 15)) {
8526                         PMD_DRV_LOG(DEBUG, "Tx is disabled");
8527                         link_up = 0;
8528                         vars->line_speed = 0;
8529                 }
8530         }
8531         return link_up;
8532 }
8533
8534 static elink_status_t elink_8726_config_init(struct elink_phy *phy,
8535                                              struct elink_params *params,
8536                                              struct elink_vars *vars)
8537 {
8538         struct bnx2x_softc *sc = params->sc;
8539         PMD_DRV_LOG(DEBUG, "Initializing BNX2X8726");
8540
8541         elink_cl45_write(sc, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 1 << 15);
8542         elink_wait_reset_complete(sc, phy, params);
8543
8544         elink_8726_external_rom_boot(phy, params);
8545
8546         /* Need to call module detected on initialization since the module
8547          * detection triggered by actual module insertion might occur before
8548          * driver is loaded, and when driver is loaded, it reset all
8549          * registers, including the transmitter
8550          */
8551         elink_sfp_module_detection(phy, params);
8552
8553         if (phy->req_line_speed == ELINK_SPEED_1000) {
8554                 PMD_DRV_LOG(DEBUG, "Setting 1G force");
8555                 elink_cl45_write(sc, phy,
8556                                  MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x40);
8557                 elink_cl45_write(sc, phy,
8558                                  MDIO_PMA_DEVAD, MDIO_PMA_REG_10G_CTRL2, 0xD);
8559                 elink_cl45_write(sc, phy,
8560                                  MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL, 0x5);
8561                 elink_cl45_write(sc, phy,
8562                                  MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXCTRL, 0x400);
8563         } else if ((phy->req_line_speed == ELINK_SPEED_AUTO_NEG) &&
8564                    (phy->speed_cap_mask &
8565                     PORT_HW_CFG_SPEED_CAPABILITY_D0_1G) &&
8566                    ((phy->speed_cap_mask &
8567                      PORT_HW_CFG_SPEED_CAPABILITY_D0_10G) !=
8568                     PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) {
8569                 PMD_DRV_LOG(DEBUG, "Setting 1G clause37");
8570                 /* Set Flow control */
8571                 elink_ext_phy_set_pause(params, phy, vars);
8572                 elink_cl45_write(sc, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV, 0x20);
8573                 elink_cl45_write(sc, phy,
8574                                  MDIO_AN_DEVAD, MDIO_AN_REG_CL37_CL73, 0x040c);
8575                 elink_cl45_write(sc, phy,
8576                                  MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LD, 0x0020);
8577                 elink_cl45_write(sc, phy,
8578                                  MDIO_AN_DEVAD, MDIO_AN_REG_CL37_AN, 0x1000);
8579                 elink_cl45_write(sc, phy,
8580                                  MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x1200);
8581                 /* Enable RX-ALARM control to receive interrupt for 1G speed
8582                  * change
8583                  */
8584                 elink_cl45_write(sc, phy,
8585                                  MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL, 0x4);
8586                 elink_cl45_write(sc, phy,
8587                                  MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXCTRL, 0x400);
8588
8589         } else {                /* Default 10G. Set only LASI control */
8590                 elink_cl45_write(sc, phy,
8591                                  MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL, 1);
8592         }
8593
8594         /* Set TX PreEmphasis if needed */
8595         if ((params->feature_config_flags &
8596              ELINK_FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED)) {
8597                 PMD_DRV_LOG(DEBUG,
8598                             "Setting TX_CTRL1 0x%x, TX_CTRL2 0x%x",
8599                             phy->tx_preemphasis[0], phy->tx_preemphasis[1]);
8600                 elink_cl45_write(sc, phy,
8601                                  MDIO_PMA_DEVAD,
8602                                  MDIO_PMA_REG_8726_TX_CTRL1,
8603                                  phy->tx_preemphasis[0]);
8604
8605                 elink_cl45_write(sc, phy,
8606                                  MDIO_PMA_DEVAD,
8607                                  MDIO_PMA_REG_8726_TX_CTRL2,
8608                                  phy->tx_preemphasis[1]);
8609         }
8610
8611         return ELINK_STATUS_OK;
8612
8613 }
8614
8615 static void elink_8726_link_reset(struct elink_phy *phy,
8616                                   struct elink_params *params)
8617 {
8618         struct bnx2x_softc *sc = params->sc;
8619         PMD_DRV_LOG(DEBUG, "elink_8726_link_reset port %d", params->port);
8620         /* Set serial boot control for external load */
8621         elink_cl45_write(sc, phy,
8622                          MDIO_PMA_DEVAD, MDIO_PMA_REG_GEN_CTRL, 0x0001);
8623 }
8624
8625 /******************************************************************/
8626 /*                      BNX2X8727 PHY SECTION                     */
8627 /******************************************************************/
8628
8629 static void elink_8727_set_link_led(struct elink_phy *phy,
8630                                     struct elink_params *params, uint8_t mode)
8631 {
8632         struct bnx2x_softc *sc = params->sc;
8633         uint16_t led_mode_bitmask = 0;
8634         uint16_t gpio_pins_bitmask = 0;
8635         uint16_t val;
8636         /* Only NOC flavor requires to set the LED specifically */
8637         if (!(phy->flags & ELINK_FLAGS_NOC))
8638                 return;
8639         switch (mode) {
8640         case ELINK_LED_MODE_FRONT_PANEL_OFF:
8641         case ELINK_LED_MODE_OFF:
8642                 led_mode_bitmask = 0;
8643                 gpio_pins_bitmask = 0x03;
8644                 break;
8645         case ELINK_LED_MODE_ON:
8646                 led_mode_bitmask = 0;
8647                 gpio_pins_bitmask = 0x02;
8648                 break;
8649         case ELINK_LED_MODE_OPER:
8650                 led_mode_bitmask = 0x60;
8651                 gpio_pins_bitmask = 0x11;
8652                 break;
8653         }
8654         elink_cl45_read(sc, phy,
8655                         MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_PCS_OPT_CTRL, &val);
8656         val &= 0xff8f;
8657         val |= led_mode_bitmask;
8658         elink_cl45_write(sc, phy,
8659                          MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_PCS_OPT_CTRL, val);
8660         elink_cl45_read(sc, phy,
8661                         MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_GPIO_CTRL, &val);
8662         val &= 0xffe0;
8663         val |= gpio_pins_bitmask;
8664         elink_cl45_write(sc, phy,
8665                          MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_GPIO_CTRL, val);
8666 }
8667
8668 static void elink_8727_hw_reset(__rte_unused struct elink_phy *phy,
8669                                 struct elink_params *params)
8670 {
8671         uint32_t swap_val, swap_override;
8672         uint8_t port;
8673         /* The PHY reset is controlled by GPIO 1. Fake the port number
8674          * to cancel the swap done in set_gpio()
8675          */
8676         struct bnx2x_softc *sc = params->sc;
8677         swap_val = REG_RD(sc, NIG_REG_PORT_SWAP);
8678         swap_override = REG_RD(sc, NIG_REG_STRAP_OVERRIDE);
8679         port = (swap_val && swap_override) ^ 1;
8680         elink_cb_gpio_write(sc, MISC_REGISTERS_GPIO_1,
8681                             MISC_REGISTERS_GPIO_OUTPUT_LOW, port);
8682 }
8683
8684 static void elink_8727_config_speed(struct elink_phy *phy,
8685                                     struct elink_params *params)
8686 {
8687         struct bnx2x_softc *sc = params->sc;
8688         uint16_t tmp1, val;
8689         /* Set option 1G speed */
8690         if ((phy->req_line_speed == ELINK_SPEED_1000) ||
8691             (phy->media_type == ELINK_ETH_PHY_SFP_1G_FIBER)) {
8692                 PMD_DRV_LOG(DEBUG, "Setting 1G force");
8693                 elink_cl45_write(sc, phy,
8694                                  MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x40);
8695                 elink_cl45_write(sc, phy,
8696                                  MDIO_PMA_DEVAD, MDIO_PMA_REG_10G_CTRL2, 0xD);
8697                 elink_cl45_read(sc, phy,
8698                                 MDIO_PMA_DEVAD, MDIO_PMA_REG_10G_CTRL2, &tmp1);
8699                 PMD_DRV_LOG(DEBUG, "1.7 = 0x%x", tmp1);
8700                 /* Power down the XAUI until link is up in case of dual-media
8701                  * and 1G
8702                  */
8703                 if (ELINK_DUAL_MEDIA(params)) {
8704                         elink_cl45_read(sc, phy,
8705                                         MDIO_PMA_DEVAD,
8706                                         MDIO_PMA_REG_8727_PCS_GP, &val);
8707                         val |= (3 << 10);
8708                         elink_cl45_write(sc, phy,
8709                                          MDIO_PMA_DEVAD,
8710                                          MDIO_PMA_REG_8727_PCS_GP, val);
8711                 }
8712         } else if ((phy->req_line_speed == ELINK_SPEED_AUTO_NEG) &&
8713                    ((phy->speed_cap_mask &
8714                      PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) &&
8715                    ((phy->speed_cap_mask &
8716                      PORT_HW_CFG_SPEED_CAPABILITY_D0_10G) !=
8717                     PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) {
8718
8719                 PMD_DRV_LOG(DEBUG, "Setting 1G clause37");
8720                 elink_cl45_write(sc, phy,
8721                                  MDIO_AN_DEVAD, MDIO_AN_REG_8727_MISC_CTRL, 0);
8722                 elink_cl45_write(sc, phy,
8723                                  MDIO_AN_DEVAD, MDIO_AN_REG_CL37_AN, 0x1300);
8724         } else {
8725                 /* Since the 8727 has only single reset pin, need to set the 10G
8726                  * registers although it is default
8727                  */
8728                 elink_cl45_write(sc, phy,
8729                                  MDIO_AN_DEVAD, MDIO_AN_REG_8727_MISC_CTRL,
8730                                  0x0020);
8731                 elink_cl45_write(sc, phy,
8732                                  MDIO_AN_DEVAD, MDIO_AN_REG_CL37_AN, 0x0100);
8733                 elink_cl45_write(sc, phy,
8734                                  MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x2040);
8735                 elink_cl45_write(sc, phy,
8736                                  MDIO_PMA_DEVAD, MDIO_PMA_REG_10G_CTRL2,
8737                                  0x0008);
8738         }
8739 }
8740
8741 static elink_status_t elink_8727_config_init(struct elink_phy *phy,
8742                                              struct elink_params *params,
8743                                              __rte_unused struct elink_vars
8744                                              *vars)
8745 {
8746         uint32_t tx_en_mode;
8747         uint16_t tmp1, mod_abs, tmp2;
8748         struct bnx2x_softc *sc = params->sc;
8749         /* Enable PMD link, MOD_ABS_FLT, and 1G link alarm */
8750
8751         elink_wait_reset_complete(sc, phy, params);
8752
8753         PMD_DRV_LOG(DEBUG, "Initializing BNX2X8727");
8754
8755         elink_8727_specific_func(phy, params, ELINK_PHY_INIT);
8756         /* Initially configure MOD_ABS to interrupt when module is
8757          * presence( bit 8)
8758          */
8759         elink_cl45_read(sc, phy,
8760                         MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER, &mod_abs);
8761         /* Set EDC off by setting OPTXLOS signal input to low (bit 9).
8762          * When the EDC is off it locks onto a reference clock and avoids
8763          * becoming 'lost'
8764          */
8765         mod_abs &= ~(1 << 8);
8766         if (!(phy->flags & ELINK_FLAGS_NOC))
8767                 mod_abs &= ~(1 << 9);
8768         elink_cl45_write(sc, phy,
8769                          MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER, mod_abs);
8770
8771         /* Enable/Disable PHY transmitter output */
8772         elink_set_disable_pmd_transmit(params, phy, 0);
8773
8774         elink_8727_power_module(sc, phy, 1);
8775
8776         elink_cl45_read(sc, phy,
8777                         MDIO_PMA_DEVAD, MDIO_PMA_REG_M8051_MSGOUT_REG, &tmp1);
8778
8779         elink_cl45_read(sc, phy, MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXSTAT, &tmp1);
8780
8781         elink_8727_config_speed(phy, params);
8782
8783         /* Set TX PreEmphasis if needed */
8784         if ((params->feature_config_flags &
8785              ELINK_FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED)) {
8786                 PMD_DRV_LOG(DEBUG, "Setting TX_CTRL1 0x%x, TX_CTRL2 0x%x",
8787                             phy->tx_preemphasis[0], phy->tx_preemphasis[1]);
8788                 elink_cl45_write(sc, phy,
8789                                  MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_TX_CTRL1,
8790                                  phy->tx_preemphasis[0]);
8791
8792                 elink_cl45_write(sc, phy,
8793                                  MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_TX_CTRL2,
8794                                  phy->tx_preemphasis[1]);
8795         }
8796
8797         /* If TX Laser is controlled by GPIO_0, do not let PHY go into low
8798          * power mode, if TX Laser is disabled
8799          */
8800         tx_en_mode = REG_RD(sc, params->shmem_base +
8801                             offsetof(struct shmem_region,
8802                                      dev_info.port_hw_config[params->port].
8803                                      sfp_ctrl))
8804         & PORT_HW_CFG_TX_LASER_MASK;
8805
8806         if (tx_en_mode == PORT_HW_CFG_TX_LASER_GPIO0) {
8807
8808                 PMD_DRV_LOG(DEBUG, "Enabling TXONOFF_PWRDN_DIS");
8809                 elink_cl45_read(sc, phy,
8810                                 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_OPT_CFG_REG,
8811                                 &tmp2);
8812                 tmp2 |= 0x1000;
8813                 tmp2 &= 0xFFEF;
8814                 elink_cl45_write(sc, phy,
8815                                  MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_OPT_CFG_REG,
8816                                  tmp2);
8817                 elink_cl45_read(sc, phy, MDIO_PMA_DEVAD,
8818                                 MDIO_PMA_REG_PHY_IDENTIFIER, &tmp2);
8819                 elink_cl45_write(sc, phy, MDIO_PMA_DEVAD,
8820                                  MDIO_PMA_REG_PHY_IDENTIFIER, (tmp2 & 0x7fff));
8821         }
8822
8823         return ELINK_STATUS_OK;
8824 }
8825
8826 static void elink_8727_handle_mod_abs(struct elink_phy *phy,
8827                                       struct elink_params *params)
8828 {
8829         struct bnx2x_softc *sc = params->sc;
8830         uint16_t mod_abs, rx_alarm_status;
8831         uint32_t val = REG_RD(sc, params->shmem_base +
8832                               offsetof(struct shmem_region,
8833                                        dev_info.port_feature_config[params->
8834                                                                     port].config));
8835         elink_cl45_read(sc, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER,
8836                         &mod_abs);
8837         if (mod_abs & (1 << 8)) {
8838
8839                 /* Module is absent */
8840                 PMD_DRV_LOG(DEBUG, "MOD_ABS indication show module is absent");
8841                 phy->media_type = ELINK_ETH_PHY_NOT_PRESENT;
8842                 /* 1. Set mod_abs to detect next module
8843                  *    presence event
8844                  * 2. Set EDC off by setting OPTXLOS signal input to low
8845                  *    (bit 9).
8846                  *    When the EDC is off it locks onto a reference clock and
8847                  *    avoids becoming 'lost'.
8848                  */
8849                 mod_abs &= ~(1 << 8);
8850                 if (!(phy->flags & ELINK_FLAGS_NOC))
8851                         mod_abs &= ~(1 << 9);
8852                 elink_cl45_write(sc, phy,
8853                                  MDIO_PMA_DEVAD,
8854                                  MDIO_PMA_REG_PHY_IDENTIFIER, mod_abs);
8855
8856                 /* Clear RX alarm since it stays up as long as
8857                  * the mod_abs wasn't changed
8858                  */
8859                 elink_cl45_read(sc, phy,
8860                                 MDIO_PMA_DEVAD,
8861                                 MDIO_PMA_LASI_RXSTAT, &rx_alarm_status);
8862
8863         } else {
8864                 /* Module is present */
8865                 PMD_DRV_LOG(DEBUG, "MOD_ABS indication show module is present");
8866                 /* First disable transmitter, and if the module is ok, the
8867                  * module_detection will enable it
8868                  * 1. Set mod_abs to detect next module absent event ( bit 8)
8869                  * 2. Restore the default polarity of the OPRXLOS signal and
8870                  * this signal will then correctly indicate the presence or
8871                  * absence of the Rx signal. (bit 9)
8872                  */
8873                 mod_abs |= (1 << 8);
8874                 if (!(phy->flags & ELINK_FLAGS_NOC))
8875                         mod_abs |= (1 << 9);
8876                 elink_cl45_write(sc, phy,
8877                                  MDIO_PMA_DEVAD,
8878                                  MDIO_PMA_REG_PHY_IDENTIFIER, mod_abs);
8879
8880                 /* Clear RX alarm since it stays up as long as the mod_abs
8881                  * wasn't changed. This is need to be done before calling the
8882                  * module detection, otherwise it will clear* the link update
8883                  * alarm
8884                  */
8885                 elink_cl45_read(sc, phy,
8886                                 MDIO_PMA_DEVAD,
8887                                 MDIO_PMA_LASI_RXSTAT, &rx_alarm_status);
8888
8889                 if ((val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) ==
8890                     PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_DISABLE_TX_LASER)
8891                         elink_sfp_set_transmitter(params, phy, 0);
8892
8893                 if (elink_wait_for_sfp_module_initialized(phy, params) == 0) {
8894                         elink_sfp_module_detection(phy, params);
8895                 } else {
8896                         PMD_DRV_LOG(DEBUG, "SFP+ module is not initialized");
8897                 }
8898
8899                 /* Reconfigure link speed based on module type limitations */
8900                 elink_8727_config_speed(phy, params);
8901         }
8902
8903         PMD_DRV_LOG(DEBUG, "8727 RX_ALARM_STATUS 0x%x", rx_alarm_status);
8904         /* No need to check link status in case of module plugged in/out */
8905 }
8906
8907 static uint8_t elink_8727_read_status(struct elink_phy *phy,
8908                                       struct elink_params *params,
8909                                       struct elink_vars *vars)
8910 {
8911         struct bnx2x_softc *sc = params->sc;
8912         uint8_t link_up = 0, oc_port = params->port;
8913         uint16_t link_status = 0;
8914         uint16_t rx_alarm_status, lasi_ctrl, val1;
8915
8916         /* If PHY is not initialized, do not check link status */
8917         elink_cl45_read(sc, phy,
8918                         MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL, &lasi_ctrl);
8919         if (!lasi_ctrl)
8920                 return 0;
8921
8922         /* Check the LASI on Rx */
8923         elink_cl45_read(sc, phy,
8924                         MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXSTAT, &rx_alarm_status);
8925         vars->line_speed = 0;
8926         PMD_DRV_LOG(DEBUG, "8727 RX_ALARM_STATUS  0x%x", rx_alarm_status);
8927
8928         elink_sfp_mask_fault(sc, phy, MDIO_PMA_LASI_TXSTAT,
8929                              MDIO_PMA_LASI_TXCTRL);
8930
8931         elink_cl45_read(sc, phy, MDIO_PMA_DEVAD, MDIO_PMA_LASI_STAT, &val1);
8932
8933         PMD_DRV_LOG(DEBUG, "8727 LASI status 0x%x", val1);
8934
8935         /* Clear MSG-OUT */
8936         elink_cl45_read(sc, phy,
8937                         MDIO_PMA_DEVAD, MDIO_PMA_REG_M8051_MSGOUT_REG, &val1);
8938
8939         /* If a module is present and there is need to check
8940          * for over current
8941          */
8942         if (!(phy->flags & ELINK_FLAGS_NOC) && !(rx_alarm_status & (1 << 5))) {
8943                 /* Check over-current using 8727 GPIO0 input */
8944                 elink_cl45_read(sc, phy,
8945                                 MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_GPIO_CTRL,
8946                                 &val1);
8947
8948                 if ((val1 & (1 << 8)) == 0) {
8949                         if (!CHIP_IS_E1x(sc))
8950                                 oc_port = SC_PATH(sc) + (params->port << 1);
8951                         PMD_DRV_LOG(DEBUG,
8952                                     "8727 Power fault has been detected on port %d",
8953                                     oc_port);
8954                         elink_cb_event_log(sc, ELINK_LOG_ID_OVER_CURRENT, oc_port);     //"Error: Power fault on Port %d has "
8955                         //  "been detected and the power to "
8956                         //  "that SFP+ module has been removed "
8957                         //  "to prevent failure of the card. "
8958                         //  "Please remove the SFP+ module and "
8959                         //  "restart the system to clear this "
8960                         //  "error.",
8961                         /* Disable all RX_ALARMs except for mod_abs */
8962                         elink_cl45_write(sc, phy,
8963                                          MDIO_PMA_DEVAD,
8964                                          MDIO_PMA_LASI_RXCTRL, (1 << 5));
8965
8966                         elink_cl45_read(sc, phy,
8967                                         MDIO_PMA_DEVAD,
8968                                         MDIO_PMA_REG_PHY_IDENTIFIER, &val1);
8969                         /* Wait for module_absent_event */
8970                         val1 |= (1 << 8);
8971                         elink_cl45_write(sc, phy,
8972                                          MDIO_PMA_DEVAD,
8973                                          MDIO_PMA_REG_PHY_IDENTIFIER, val1);
8974                         /* Clear RX alarm */
8975                         elink_cl45_read(sc, phy,
8976                                         MDIO_PMA_DEVAD,
8977                                         MDIO_PMA_LASI_RXSTAT, &rx_alarm_status);
8978                         elink_8727_power_module(params->sc, phy, 0);
8979                         return 0;
8980                 }
8981         }
8982
8983         /* Over current check */
8984         /* When module absent bit is set, check module */
8985         if (rx_alarm_status & (1 << 5)) {
8986                 elink_8727_handle_mod_abs(phy, params);
8987                 /* Enable all mod_abs and link detection bits */
8988                 elink_cl45_write(sc, phy,
8989                                  MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXCTRL,
8990                                  ((1 << 5) | (1 << 2)));
8991         }
8992
8993         if (!(phy->flags & ELINK_FLAGS_SFP_NOT_APPROVED)) {
8994                 PMD_DRV_LOG(DEBUG, "Enabling 8727 TX laser");
8995                 elink_sfp_set_transmitter(params, phy, 1);
8996         } else {
8997                 PMD_DRV_LOG(DEBUG, "Tx is disabled");
8998                 return 0;
8999         }
9000
9001         elink_cl45_read(sc, phy,
9002                         MDIO_PMA_DEVAD,
9003                         MDIO_PMA_REG_8073_SPEED_LINK_STATUS, &link_status);
9004
9005         /* Bits 0..2 --> speed detected,
9006          * Bits 13..15--> link is down
9007          */
9008         if ((link_status & (1 << 2)) && (!(link_status & (1 << 15)))) {
9009                 link_up = 1;
9010                 vars->line_speed = ELINK_SPEED_10000;
9011                 PMD_DRV_LOG(DEBUG, "port %x: External link up in 10G",
9012                             params->port);
9013         } else if ((link_status & (1 << 0)) && (!(link_status & (1 << 13)))) {
9014                 link_up = 1;
9015                 vars->line_speed = ELINK_SPEED_1000;
9016                 PMD_DRV_LOG(DEBUG, "port %x: External link up in 1G",
9017                             params->port);
9018         } else {
9019                 link_up = 0;
9020                 PMD_DRV_LOG(DEBUG, "port %x: External link is down",
9021                             params->port);
9022         }
9023
9024         /* Capture 10G link fault. */
9025         if (vars->line_speed == ELINK_SPEED_10000) {
9026                 elink_cl45_read(sc, phy, MDIO_PMA_DEVAD,
9027                                 MDIO_PMA_LASI_TXSTAT, &val1);
9028
9029                 elink_cl45_read(sc, phy, MDIO_PMA_DEVAD,
9030                                 MDIO_PMA_LASI_TXSTAT, &val1);
9031
9032                 if (val1 & (1 << 0)) {
9033                         vars->fault_detected = 1;
9034                 }
9035         }
9036
9037         if (link_up) {
9038                 elink_ext_phy_resolve_fc(phy, params, vars);
9039                 vars->duplex = DUPLEX_FULL;
9040                 PMD_DRV_LOG(DEBUG, "duplex = 0x%x", vars->duplex);
9041         }
9042
9043         if ((ELINK_DUAL_MEDIA(params)) &&
9044             (phy->req_line_speed == ELINK_SPEED_1000)) {
9045                 elink_cl45_read(sc, phy,
9046                                 MDIO_PMA_DEVAD,
9047                                 MDIO_PMA_REG_8727_PCS_GP, &val1);
9048                 /* In case of dual-media board and 1G, power up the XAUI side,
9049                  * otherwise power it down. For 10G it is done automatically
9050                  */
9051                 if (link_up)
9052                         val1 &= ~(3 << 10);
9053                 else
9054                         val1 |= (3 << 10);
9055                 elink_cl45_write(sc, phy,
9056                                  MDIO_PMA_DEVAD,
9057                                  MDIO_PMA_REG_8727_PCS_GP, val1);
9058         }
9059         return link_up;
9060 }
9061
9062 static void elink_8727_link_reset(struct elink_phy *phy,
9063                                   struct elink_params *params)
9064 {
9065         struct bnx2x_softc *sc = params->sc;
9066
9067         /* Enable/Disable PHY transmitter output */
9068         elink_set_disable_pmd_transmit(params, phy, 1);
9069
9070         /* Disable Transmitter */
9071         elink_sfp_set_transmitter(params, phy, 0);
9072         /* Clear LASI */
9073         elink_cl45_write(sc, phy, MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL, 0);
9074
9075 }
9076
9077 /******************************************************************/
9078 /*              BNX2X8481/BNX2X84823/BNX2X84833 PHY SECTION               */
9079 /******************************************************************/
9080 static void elink_save_848xx_spirom_version(struct elink_phy *phy,
9081                                             struct bnx2x_softc *sc, uint8_t port)
9082 {
9083         uint16_t val, fw_ver2, cnt, i;
9084         static struct elink_reg_set reg_set[] = {
9085                 {MDIO_PMA_DEVAD, 0xA819, 0x0014},
9086                 {MDIO_PMA_DEVAD, 0xA81A, 0xc200},
9087                 {MDIO_PMA_DEVAD, 0xA81B, 0x0000},
9088                 {MDIO_PMA_DEVAD, 0xA81C, 0x0300},
9089                 {MDIO_PMA_DEVAD, 0xA817, 0x0009}
9090         };
9091         uint16_t fw_ver1;
9092
9093         if ((phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X84833) ||
9094             (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X84834)) {
9095                 elink_cl45_read(sc, phy, MDIO_CTL_DEVAD, 0x400f, &fw_ver1);
9096                 elink_save_spirom_version(sc, port, fw_ver1 & 0xfff,
9097                                           phy->ver_addr);
9098         } else {
9099                 /* For 32-bit registers in 848xx, access via MDIO2ARM i/f. */
9100                 /* (1) set reg 0xc200_0014(SPI_BRIDGE_CTRL_2) to 0x03000000 */
9101                 for (i = 0; i < ARRAY_SIZE(reg_set); i++)
9102                         elink_cl45_write(sc, phy, reg_set[i].devad,
9103                                          reg_set[i].reg, reg_set[i].val);
9104
9105                 for (cnt = 0; cnt < 100; cnt++) {
9106                         elink_cl45_read(sc, phy, MDIO_PMA_DEVAD, 0xA818, &val);
9107                         if (val & 1)
9108                                 break;
9109                         DELAY(5);
9110                 }
9111                 if (cnt == 100) {
9112                         PMD_DRV_LOG(DEBUG, "Unable to read 848xx "
9113                                     "phy fw version(1)");
9114                         elink_save_spirom_version(sc, port, 0, phy->ver_addr);
9115                         return;
9116                 }
9117
9118                 /* 2) read register 0xc200_0000 (SPI_FW_STATUS) */
9119                 elink_cl45_write(sc, phy, MDIO_PMA_DEVAD, 0xA819, 0x0000);
9120                 elink_cl45_write(sc, phy, MDIO_PMA_DEVAD, 0xA81A, 0xc200);
9121                 elink_cl45_write(sc, phy, MDIO_PMA_DEVAD, 0xA817, 0x000A);
9122                 for (cnt = 0; cnt < 100; cnt++) {
9123                         elink_cl45_read(sc, phy, MDIO_PMA_DEVAD, 0xA818, &val);
9124                         if (val & 1)
9125                                 break;
9126                         DELAY(5);
9127                 }
9128                 if (cnt == 100) {
9129                         PMD_DRV_LOG(DEBUG, "Unable to read 848xx phy fw "
9130                                     "version(2)");
9131                         elink_save_spirom_version(sc, port, 0, phy->ver_addr);
9132                         return;
9133                 }
9134
9135                 /* lower 16 bits of the register SPI_FW_STATUS */
9136                 elink_cl45_read(sc, phy, MDIO_PMA_DEVAD, 0xA81B, &fw_ver1);
9137                 /* upper 16 bits of register SPI_FW_STATUS */
9138                 elink_cl45_read(sc, phy, MDIO_PMA_DEVAD, 0xA81C, &fw_ver2);
9139
9140                 elink_save_spirom_version(sc, port, (fw_ver2 << 16) | fw_ver1,
9141                                           phy->ver_addr);
9142         }
9143
9144 }
9145
9146 static void elink_848xx_set_led(struct bnx2x_softc *sc, struct elink_phy *phy)
9147 {
9148         uint16_t val, offset, i;
9149         static struct elink_reg_set reg_set[] = {
9150                 {MDIO_PMA_DEVAD, MDIO_PMA_REG_8481_LED1_MASK, 0x0080},
9151                 {MDIO_PMA_DEVAD, MDIO_PMA_REG_8481_LED2_MASK, 0x0018},
9152                 {MDIO_PMA_DEVAD, MDIO_PMA_REG_8481_LED3_MASK, 0x0006},
9153                 {MDIO_PMA_DEVAD, MDIO_PMA_REG_8481_LED3_BLINK, 0x0000},
9154                 {MDIO_PMA_DEVAD, MDIO_PMA_REG_84823_CTL_SLOW_CLK_CNT_HIGH,
9155                  MDIO_PMA_REG_84823_BLINK_RATE_VAL_15P9HZ},
9156                 {MDIO_AN_DEVAD, 0xFFFB, 0xFFFD}
9157         };
9158         /* PHYC_CTL_LED_CTL */
9159         elink_cl45_read(sc, phy,
9160                         MDIO_PMA_DEVAD, MDIO_PMA_REG_8481_LINK_SIGNAL, &val);
9161         val &= 0xFE00;
9162         val |= 0x0092;
9163
9164         elink_cl45_write(sc, phy,
9165                          MDIO_PMA_DEVAD, MDIO_PMA_REG_8481_LINK_SIGNAL, val);
9166
9167         for (i = 0; i < ARRAY_SIZE(reg_set); i++)
9168                 elink_cl45_write(sc, phy, reg_set[i].devad, reg_set[i].reg,
9169                                  reg_set[i].val);
9170
9171         if ((phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X84833) ||
9172             (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X84834))
9173                 offset = MDIO_PMA_REG_84833_CTL_LED_CTL_1;
9174         else
9175                 offset = MDIO_PMA_REG_84823_CTL_LED_CTL_1;
9176
9177         /* stretch_en for LED3 */
9178         elink_cl45_read_or_write(sc, phy,
9179                                  MDIO_PMA_DEVAD, offset,
9180                                  MDIO_PMA_REG_84823_LED3_STRETCH_EN);
9181 }
9182
9183 static void elink_848xx_specific_func(struct elink_phy *phy,
9184                                       struct elink_params *params,
9185                                       uint32_t action)
9186 {
9187         struct bnx2x_softc *sc = params->sc;
9188         switch (action) {
9189         case ELINK_PHY_INIT:
9190                 if ((phy->type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X84833) &&
9191                     (phy->type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X84834)) {
9192                         /* Save spirom version */
9193                         elink_save_848xx_spirom_version(phy, sc, params->port);
9194                 }
9195                 /* This phy uses the NIG latch mechanism since link indication
9196                  * arrives through its LED4 and not via its LASI signal, so we
9197                  * get steady signal instead of clear on read
9198                  */
9199                 elink_bits_en(sc, NIG_REG_LATCH_BC_0 + params->port * 4,
9200                               1 << ELINK_NIG_LATCH_BC_ENABLE_MI_INT);
9201
9202                 elink_848xx_set_led(sc, phy);
9203                 break;
9204         }
9205 }
9206
9207 static elink_status_t elink_848xx_cmn_config_init(struct elink_phy *phy,
9208                                                   struct elink_params *params,
9209                                                   struct elink_vars *vars)
9210 {
9211         struct bnx2x_softc *sc = params->sc;
9212         uint16_t autoneg_val, an_1000_val, an_10_100_val;
9213
9214         elink_848xx_specific_func(phy, params, ELINK_PHY_INIT);
9215         elink_cl45_write(sc, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x0000);
9216
9217         /* set 1000 speed advertisement */
9218         elink_cl45_read(sc, phy,
9219                         MDIO_AN_DEVAD, MDIO_AN_REG_8481_1000T_CTRL,
9220                         &an_1000_val);
9221
9222         elink_ext_phy_set_pause(params, phy, vars);
9223         elink_cl45_read(sc, phy,
9224                         MDIO_AN_DEVAD,
9225                         MDIO_AN_REG_8481_LEGACY_AN_ADV, &an_10_100_val);
9226         elink_cl45_read(sc, phy,
9227                         MDIO_AN_DEVAD, MDIO_AN_REG_8481_LEGACY_MII_CTRL,
9228                         &autoneg_val);
9229         /* Disable forced speed */
9230         autoneg_val &=
9231             ~((1 << 6) | (1 << 8) | (1 << 9) | (1 << 12) | (1 << 13));
9232         an_10_100_val &= ~((1 << 5) | (1 << 6) | (1 << 7) | (1 << 8));
9233
9234         if (((phy->req_line_speed == ELINK_SPEED_AUTO_NEG) &&
9235              (phy->speed_cap_mask &
9236               PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) ||
9237             (phy->req_line_speed == ELINK_SPEED_1000)) {
9238                 an_1000_val |= (1 << 8);
9239                 autoneg_val |= (1 << 9 | 1 << 12);
9240                 if (phy->req_duplex == DUPLEX_FULL)
9241                         an_1000_val |= (1 << 9);
9242                 PMD_DRV_LOG(DEBUG, "Advertising 1G");
9243         } else
9244                 an_1000_val &= ~((1 << 8) | (1 << 9));
9245
9246         elink_cl45_write(sc, phy,
9247                          MDIO_AN_DEVAD, MDIO_AN_REG_8481_1000T_CTRL,
9248                          an_1000_val);
9249
9250         /* Set 10/100 speed advertisement */
9251         if (phy->req_line_speed == ELINK_SPEED_AUTO_NEG) {
9252                 if (phy->speed_cap_mask &
9253                     PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL) {
9254                         /* Enable autoneg and restart autoneg for legacy speeds
9255                          */
9256                         autoneg_val |= (1 << 9 | 1 << 12);
9257                         an_10_100_val |= (1 << 8);
9258                         PMD_DRV_LOG(DEBUG, "Advertising 100M-FD");
9259                 }
9260
9261                 if (phy->speed_cap_mask &
9262                     PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF) {
9263                         /* Enable autoneg and restart autoneg for legacy speeds
9264                          */
9265                         autoneg_val |= (1 << 9 | 1 << 12);
9266                         an_10_100_val |= (1 << 7);
9267                         PMD_DRV_LOG(DEBUG, "Advertising 100M-HD");
9268                 }
9269
9270                 if ((phy->speed_cap_mask &
9271                      PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL) &&
9272                     (phy->supported & ELINK_SUPPORTED_10baseT_Full)) {
9273                         an_10_100_val |= (1 << 6);
9274                         autoneg_val |= (1 << 9 | 1 << 12);
9275                         PMD_DRV_LOG(DEBUG, "Advertising 10M-FD");
9276                 }
9277
9278                 if ((phy->speed_cap_mask &
9279                      PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF) &&
9280                     (phy->supported & ELINK_SUPPORTED_10baseT_Half)) {
9281                         an_10_100_val |= (1 << 5);
9282                         autoneg_val |= (1 << 9 | 1 << 12);
9283                         PMD_DRV_LOG(DEBUG, "Advertising 10M-HD");
9284                 }
9285         }
9286
9287         /* Only 10/100 are allowed to work in FORCE mode */
9288         if ((phy->req_line_speed == ELINK_SPEED_100) &&
9289             (phy->supported &
9290              (ELINK_SUPPORTED_100baseT_Half | ELINK_SUPPORTED_100baseT_Full))) {
9291                 autoneg_val |= (1 << 13);
9292                 /* Enabled AUTO-MDIX when autoneg is disabled */
9293                 elink_cl45_write(sc, phy,
9294                                  MDIO_AN_DEVAD, MDIO_AN_REG_8481_AUX_CTRL,
9295                                  (1 << 15 | 1 << 9 | 7 << 0));
9296                 /* The PHY needs this set even for forced link. */
9297                 an_10_100_val |= (1 << 8) | (1 << 7);
9298                 PMD_DRV_LOG(DEBUG, "Setting 100M force");
9299         }
9300         if ((phy->req_line_speed == ELINK_SPEED_10) &&
9301             (phy->supported &
9302              (ELINK_SUPPORTED_10baseT_Half | ELINK_SUPPORTED_10baseT_Full))) {
9303                 /* Enabled AUTO-MDIX when autoneg is disabled */
9304                 elink_cl45_write(sc, phy,
9305                                  MDIO_AN_DEVAD, MDIO_AN_REG_8481_AUX_CTRL,
9306                                  (1 << 15 | 1 << 9 | 7 << 0));
9307                 PMD_DRV_LOG(DEBUG, "Setting 10M force");
9308         }
9309
9310         elink_cl45_write(sc, phy,
9311                          MDIO_AN_DEVAD, MDIO_AN_REG_8481_LEGACY_AN_ADV,
9312                          an_10_100_val);
9313
9314         if (phy->req_duplex == DUPLEX_FULL)
9315                 autoneg_val |= (1 << 8);
9316
9317         /* Always write this if this is not 84833/4.
9318          * For 84833/4, write it only when it's a forced speed.
9319          */
9320         if (((phy->type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X84833) &&
9321              (phy->type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X84834)) ||
9322             ((autoneg_val & (1 << 12)) == 0))
9323                 elink_cl45_write(sc, phy,
9324                                  MDIO_AN_DEVAD,
9325                                  MDIO_AN_REG_8481_LEGACY_MII_CTRL, autoneg_val);
9326
9327         if (((phy->req_line_speed == ELINK_SPEED_AUTO_NEG) &&
9328              (phy->speed_cap_mask &
9329               PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) ||
9330             (phy->req_line_speed == ELINK_SPEED_10000)) {
9331                 PMD_DRV_LOG(DEBUG, "Advertising 10G");
9332                 /* Restart autoneg for 10G */
9333
9334                 elink_cl45_read_or_write(sc, phy,
9335                                          MDIO_AN_DEVAD,
9336                                          MDIO_AN_REG_8481_10GBASE_T_AN_CTRL,
9337                                          0x1000);
9338                 elink_cl45_write(sc, phy,
9339                                  MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x3200);
9340         } else
9341                 elink_cl45_write(sc, phy,
9342                                  MDIO_AN_DEVAD,
9343                                  MDIO_AN_REG_8481_10GBASE_T_AN_CTRL, 1);
9344
9345         return ELINK_STATUS_OK;
9346 }
9347
9348 static elink_status_t elink_8481_config_init(struct elink_phy *phy,
9349                                              struct elink_params *params,
9350                                              struct elink_vars *vars)
9351 {
9352         struct bnx2x_softc *sc = params->sc;
9353         /* Restore normal power mode */
9354         elink_cb_gpio_write(sc, MISC_REGISTERS_GPIO_2,
9355                             MISC_REGISTERS_GPIO_OUTPUT_HIGH, params->port);
9356
9357         /* HW reset */
9358         elink_ext_phy_hw_reset(sc, params->port);
9359         elink_wait_reset_complete(sc, phy, params);
9360
9361         elink_cl45_write(sc, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 1 << 15);
9362         return elink_848xx_cmn_config_init(phy, params, vars);
9363 }
9364
9365 #define PHY84833_CMDHDLR_WAIT 300
9366 #define PHY84833_CMDHDLR_MAX_ARGS 5
9367 static elink_status_t elink_84833_cmd_hdlr(struct elink_phy *phy,
9368                                            struct elink_params *params,
9369                                            uint16_t fw_cmd, uint16_t cmd_args[],
9370                                            int argc)
9371 {
9372         int idx;
9373         uint16_t val;
9374         struct bnx2x_softc *sc = params->sc;
9375         /* Write CMD_OPEN_OVERRIDE to STATUS reg */
9376         elink_cl45_write(sc, phy, MDIO_CTL_DEVAD,
9377                          MDIO_84833_CMD_HDLR_STATUS,
9378                          PHY84833_STATUS_CMD_OPEN_OVERRIDE);
9379         for (idx = 0; idx < PHY84833_CMDHDLR_WAIT; idx++) {
9380                 elink_cl45_read(sc, phy, MDIO_CTL_DEVAD,
9381                                 MDIO_84833_CMD_HDLR_STATUS, &val);
9382                 if (val == PHY84833_STATUS_CMD_OPEN_FOR_CMDS)
9383                         break;
9384                 DELAY(1000 * 1);
9385         }
9386         if (idx >= PHY84833_CMDHDLR_WAIT) {
9387                 PMD_DRV_LOG(DEBUG, "FW cmd: FW not ready.");
9388                 return ELINK_STATUS_ERROR;
9389         }
9390
9391         /* Prepare argument(s) and issue command */
9392         for (idx = 0; idx < argc; idx++) {
9393                 elink_cl45_write(sc, phy, MDIO_CTL_DEVAD,
9394                                  MDIO_84833_CMD_HDLR_DATA1 + idx,
9395                                  cmd_args[idx]);
9396         }
9397         elink_cl45_write(sc, phy, MDIO_CTL_DEVAD,
9398                          MDIO_84833_CMD_HDLR_COMMAND, fw_cmd);
9399         for (idx = 0; idx < PHY84833_CMDHDLR_WAIT; idx++) {
9400                 elink_cl45_read(sc, phy, MDIO_CTL_DEVAD,
9401                                 MDIO_84833_CMD_HDLR_STATUS, &val);
9402                 if ((val == PHY84833_STATUS_CMD_COMPLETE_PASS) ||
9403                     (val == PHY84833_STATUS_CMD_COMPLETE_ERROR))
9404                         break;
9405                 DELAY(1000 * 1);
9406         }
9407         if ((idx >= PHY84833_CMDHDLR_WAIT) ||
9408             (val == PHY84833_STATUS_CMD_COMPLETE_ERROR)) {
9409                 PMD_DRV_LOG(DEBUG, "FW cmd failed.");
9410                 return ELINK_STATUS_ERROR;
9411         }
9412         /* Gather returning data */
9413         for (idx = 0; idx < argc; idx++) {
9414                 elink_cl45_read(sc, phy, MDIO_CTL_DEVAD,
9415                                 MDIO_84833_CMD_HDLR_DATA1 + idx,
9416                                 &cmd_args[idx]);
9417         }
9418         elink_cl45_write(sc, phy, MDIO_CTL_DEVAD,
9419                          MDIO_84833_CMD_HDLR_STATUS,
9420                          PHY84833_STATUS_CMD_CLEAR_COMPLETE);
9421         return ELINK_STATUS_OK;
9422 }
9423
9424 static elink_status_t elink_84833_pair_swap_cfg(struct elink_phy *phy,
9425                                                 struct elink_params *params,
9426                                                 __rte_unused struct elink_vars
9427                                                 *vars)
9428 {
9429         uint32_t pair_swap;
9430         uint16_t data[PHY84833_CMDHDLR_MAX_ARGS];
9431         elink_status_t status;
9432         struct bnx2x_softc *sc = params->sc;
9433
9434         /* Check for configuration. */
9435         pair_swap = REG_RD(sc, params->shmem_base +
9436                            offsetof(struct shmem_region,
9437                                     dev_info.port_hw_config[params->port].
9438                                     xgbt_phy_cfg)) &
9439             PORT_HW_CFG_RJ45_PAIR_SWAP_MASK;
9440
9441         if (pair_swap == 0)
9442                 return ELINK_STATUS_OK;
9443
9444         /* Only the second argument is used for this command */
9445         data[1] = (uint16_t) pair_swap;
9446
9447         status = elink_84833_cmd_hdlr(phy, params,
9448                                       PHY84833_CMD_SET_PAIR_SWAP, data,
9449                                       PHY84833_CMDHDLR_MAX_ARGS);
9450         if (status == ELINK_STATUS_OK) {
9451                 PMD_DRV_LOG(DEBUG, "Pairswap OK, val=0x%x", data[1]);
9452         }
9453
9454         return status;
9455 }
9456
9457 static uint8_t elink_84833_get_reset_gpios(struct bnx2x_softc *sc,
9458                                            uint32_t shmem_base_path[],
9459                                            __rte_unused uint32_t chip_id)
9460 {
9461         uint32_t reset_pin[2];
9462         uint32_t idx;
9463         uint8_t reset_gpios;
9464         if (CHIP_IS_E3(sc)) {
9465                 /* Assume that these will be GPIOs, not EPIOs. */
9466                 for (idx = 0; idx < 2; idx++) {
9467                         /* Map config param to register bit. */
9468                         reset_pin[idx] = REG_RD(sc, shmem_base_path[idx] +
9469                                                 offsetof(struct shmem_region,
9470                                                          dev_info.
9471                                                          port_hw_config[0].
9472                                                          e3_cmn_pin_cfg));
9473                         reset_pin[idx] =
9474                             (reset_pin[idx] & PORT_HW_CFG_E3_PHY_RESET_MASK) >>
9475                             PORT_HW_CFG_E3_PHY_RESET_SHIFT;
9476                         reset_pin[idx] -= PIN_CFG_GPIO0_P0;
9477                         reset_pin[idx] = (1 << reset_pin[idx]);
9478                 }
9479                 reset_gpios = (uint8_t) (reset_pin[0] | reset_pin[1]);
9480         } else {
9481                 /* E2, look from diff place of shmem. */
9482                 for (idx = 0; idx < 2; idx++) {
9483                         reset_pin[idx] = REG_RD(sc, shmem_base_path[idx] +
9484                                                 offsetof(struct shmem_region,
9485                                                          dev_info.
9486                                                          port_hw_config[0].
9487                                                          default_cfg));
9488                         reset_pin[idx] &= PORT_HW_CFG_EXT_PHY_GPIO_RST_MASK;
9489                         reset_pin[idx] -= PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO0_P0;
9490                         reset_pin[idx] >>= PORT_HW_CFG_EXT_PHY_GPIO_RST_SHIFT;
9491                         reset_pin[idx] = (1 << reset_pin[idx]);
9492                 }
9493                 reset_gpios = (uint8_t) (reset_pin[0] | reset_pin[1]);
9494         }
9495
9496         return reset_gpios;
9497 }
9498
9499 static elink_status_t elink_84833_hw_reset_phy(struct elink_phy *phy,
9500                                                struct elink_params *params)
9501 {
9502         struct bnx2x_softc *sc = params->sc;
9503         uint8_t reset_gpios;
9504         uint32_t other_shmem_base_addr = REG_RD(sc, params->shmem2_base +
9505                                                 offsetof(struct shmem2_region,
9506                                                          other_shmem_base_addr));
9507
9508         uint32_t shmem_base_path[2];
9509
9510         /* Work around for 84833 LED failure inside RESET status */
9511         elink_cl45_write(sc, phy, MDIO_AN_DEVAD,
9512                          MDIO_AN_REG_8481_LEGACY_MII_CTRL,
9513                          MDIO_AN_REG_8481_MII_CTRL_FORCE_1G);
9514         elink_cl45_write(sc, phy, MDIO_AN_DEVAD,
9515                          MDIO_AN_REG_8481_1G_100T_EXT_CTRL,
9516                          MIDO_AN_REG_8481_EXT_CTRL_FORCE_LEDS_OFF);
9517
9518         shmem_base_path[0] = params->shmem_base;
9519         shmem_base_path[1] = other_shmem_base_addr;
9520
9521         reset_gpios = elink_84833_get_reset_gpios(sc, shmem_base_path,
9522                                                   params->chip_id);
9523
9524         elink_cb_gpio_mult_write(sc, reset_gpios,
9525                                  MISC_REGISTERS_GPIO_OUTPUT_LOW);
9526         DELAY(10);
9527         PMD_DRV_LOG(DEBUG, "84833 hw reset on pin values 0x%x", reset_gpios);
9528
9529         return ELINK_STATUS_OK;
9530 }
9531
9532 static elink_status_t elink_8483x_disable_eee(struct elink_phy *phy,
9533                                               struct elink_params *params,
9534                                               struct elink_vars *vars)
9535 {
9536         elink_status_t rc;
9537         uint16_t cmd_args = 0;
9538
9539         PMD_DRV_LOG(DEBUG, "Don't Advertise 10GBase-T EEE");
9540
9541         /* Prevent Phy from working in EEE and advertising it */
9542         rc = elink_84833_cmd_hdlr(phy, params,
9543                                   PHY84833_CMD_SET_EEE_MODE, &cmd_args, 1);
9544         if (rc != ELINK_STATUS_OK) {
9545                 PMD_DRV_LOG(DEBUG, "EEE disable failed.");
9546                 return rc;
9547         }
9548
9549         return elink_eee_disable(phy, params, vars);
9550 }
9551
9552 static elink_status_t elink_8483x_enable_eee(struct elink_phy *phy,
9553                                              struct elink_params *params,
9554                                              struct elink_vars *vars)
9555 {
9556         elink_status_t rc;
9557         uint16_t cmd_args = 1;
9558
9559         rc = elink_84833_cmd_hdlr(phy, params,
9560                                   PHY84833_CMD_SET_EEE_MODE, &cmd_args, 1);
9561         if (rc != ELINK_STATUS_OK) {
9562                 PMD_DRV_LOG(DEBUG, "EEE enable failed.");
9563                 return rc;
9564         }
9565
9566         return elink_eee_advertise(phy, params, vars, SHMEM_EEE_10G_ADV);
9567 }
9568
9569 #define PHY84833_CONSTANT_LATENCY 1193
9570 static elink_status_t elink_848x3_config_init(struct elink_phy *phy,
9571                                               struct elink_params *params,
9572                                               struct elink_vars *vars)
9573 {
9574         struct bnx2x_softc *sc = params->sc;
9575         uint8_t port, initialize = 1;
9576         uint16_t val;
9577         uint32_t actual_phy_selection;
9578         uint16_t cmd_args[PHY84833_CMDHDLR_MAX_ARGS];
9579         elink_status_t rc = ELINK_STATUS_OK;
9580
9581         DELAY(1000 * 1);
9582
9583         if (!(CHIP_IS_E1x(sc)))
9584                 port = SC_PATH(sc);
9585         else
9586                 port = params->port;
9587
9588         if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X84823) {
9589                 elink_cb_gpio_write(sc, MISC_REGISTERS_GPIO_3,
9590                                     MISC_REGISTERS_GPIO_OUTPUT_HIGH, port);
9591         } else {
9592                 /* MDIO reset */
9593                 elink_cl45_write(sc, phy,
9594                                  MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x8000);
9595         }
9596
9597         elink_wait_reset_complete(sc, phy, params);
9598
9599         /* Wait for GPHY to come out of reset */
9600         DELAY(1000 * 50);
9601         if ((phy->type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X84833) &&
9602             (phy->type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X84834)) {
9603                 /* BNX2X84823 requires that XGXS links up first @ 10G for normal
9604                  * behavior.
9605                  */
9606                 uint16_t temp;
9607                 temp = vars->line_speed;
9608                 vars->line_speed = ELINK_SPEED_10000;
9609                 elink_set_autoneg(&params->phy[ELINK_INT_PHY], params, vars, 0);
9610                 elink_program_serdes(&params->phy[ELINK_INT_PHY], params, vars);
9611                 vars->line_speed = temp;
9612         }
9613
9614         elink_cl45_read(sc, phy, MDIO_CTL_DEVAD,
9615                         MDIO_CTL_REG_84823_MEDIA, &val);
9616         val &= ~(MDIO_CTL_REG_84823_MEDIA_MAC_MASK |
9617                  MDIO_CTL_REG_84823_MEDIA_LINE_MASK |
9618                  MDIO_CTL_REG_84823_MEDIA_COPPER_CORE_DOWN |
9619                  MDIO_CTL_REG_84823_MEDIA_PRIORITY_MASK |
9620                  MDIO_CTL_REG_84823_MEDIA_FIBER_1G);
9621
9622         if (CHIP_IS_E3(sc)) {
9623                 val &= ~(MDIO_CTL_REG_84823_MEDIA_MAC_MASK |
9624                          MDIO_CTL_REG_84823_MEDIA_LINE_MASK);
9625         } else {
9626                 val |= (MDIO_CTL_REG_84823_CTRL_MAC_XFI |
9627                         MDIO_CTL_REG_84823_MEDIA_LINE_XAUI_L);
9628         }
9629
9630         actual_phy_selection = elink_phy_selection(params);
9631
9632         switch (actual_phy_selection) {
9633         case PORT_HW_CFG_PHY_SELECTION_HARDWARE_DEFAULT:
9634                 /* Do nothing. Essentially this is like the priority copper */
9635                 break;
9636         case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY_PRIORITY:
9637                 val |= MDIO_CTL_REG_84823_MEDIA_PRIORITY_COPPER;
9638                 break;
9639         case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY_PRIORITY:
9640                 val |= MDIO_CTL_REG_84823_MEDIA_PRIORITY_FIBER;
9641                 break;
9642         case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY:
9643                 /* Do nothing here. The first PHY won't be initialized at all */
9644                 break;
9645         case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY:
9646                 val |= MDIO_CTL_REG_84823_MEDIA_COPPER_CORE_DOWN;
9647                 initialize = 0;
9648                 break;
9649         }
9650         if (params->phy[ELINK_EXT_PHY2].req_line_speed == ELINK_SPEED_1000)
9651                 val |= MDIO_CTL_REG_84823_MEDIA_FIBER_1G;
9652
9653         elink_cl45_write(sc, phy, MDIO_CTL_DEVAD,
9654                          MDIO_CTL_REG_84823_MEDIA, val);
9655         PMD_DRV_LOG(DEBUG, "Multi_phy config = 0x%x, Media control = 0x%x",
9656                     params->multi_phy_config, val);
9657
9658         if ((phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X84833) ||
9659             (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X84834)) {
9660                 elink_84833_pair_swap_cfg(phy, params, vars);
9661
9662                 /* Keep AutogrEEEn disabled. */
9663                 cmd_args[0] = 0x0;
9664                 cmd_args[1] = 0x0;
9665                 cmd_args[2] = PHY84833_CONSTANT_LATENCY + 1;
9666                 cmd_args[3] = PHY84833_CONSTANT_LATENCY;
9667                 rc = elink_84833_cmd_hdlr(phy, params,
9668                                           PHY84833_CMD_SET_EEE_MODE, cmd_args,
9669                                           PHY84833_CMDHDLR_MAX_ARGS);
9670                 if (rc != ELINK_STATUS_OK) {
9671                         PMD_DRV_LOG(DEBUG, "Cfg AutogrEEEn failed.");
9672                 }
9673         }
9674         if (initialize) {
9675                 rc = elink_848xx_cmn_config_init(phy, params, vars);
9676         } else {
9677                 elink_save_848xx_spirom_version(phy, sc, params->port);
9678         }
9679         /* 84833 PHY has a better feature and doesn't need to support this. */
9680         if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X84823) {
9681                 uint32_t cms_enable = REG_RD(sc, params->shmem_base +
9682                                              offsetof(struct shmem_region,
9683                                                       dev_info.
9684                                                       port_hw_config[params->
9685                                                                      port].
9686                                                       default_cfg)) &
9687                     PORT_HW_CFG_ENABLE_CMS_MASK;
9688
9689                 elink_cl45_read(sc, phy, MDIO_CTL_DEVAD,
9690                                 MDIO_CTL_REG_84823_USER_CTRL_REG, &val);
9691                 if (cms_enable)
9692                         val |= MDIO_CTL_REG_84823_USER_CTRL_CMS;
9693                 else
9694                         val &= ~MDIO_CTL_REG_84823_USER_CTRL_CMS;
9695                 elink_cl45_write(sc, phy, MDIO_CTL_DEVAD,
9696                                  MDIO_CTL_REG_84823_USER_CTRL_REG, val);
9697         }
9698
9699         elink_cl45_read(sc, phy, MDIO_CTL_DEVAD,
9700                         MDIO_84833_TOP_CFG_FW_REV, &val);
9701
9702         /* Configure EEE support */
9703         if ((val >= MDIO_84833_TOP_CFG_FW_EEE) &&
9704             (val != MDIO_84833_TOP_CFG_FW_NO_EEE) &&
9705             elink_eee_has_cap(params)) {
9706                 rc = elink_eee_initial_config(params, vars, SHMEM_EEE_10G_ADV);
9707                 if (rc != ELINK_STATUS_OK) {
9708                         PMD_DRV_LOG(DEBUG, "Failed to configure EEE timers");
9709                         elink_8483x_disable_eee(phy, params, vars);
9710                         return rc;
9711                 }
9712
9713                 if ((phy->req_duplex == DUPLEX_FULL) &&
9714                     (params->eee_mode & ELINK_EEE_MODE_ADV_LPI) &&
9715                     (elink_eee_calc_timer(params) ||
9716                      !(params->eee_mode & ELINK_EEE_MODE_ENABLE_LPI)))
9717                         rc = elink_8483x_enable_eee(phy, params, vars);
9718                 else
9719                         rc = elink_8483x_disable_eee(phy, params, vars);
9720                 if (rc != ELINK_STATUS_OK) {
9721                         PMD_DRV_LOG(DEBUG, "Failed to set EEE advertisement");
9722                         return rc;
9723                 }
9724         } else {
9725                 vars->eee_status &= ~SHMEM_EEE_SUPPORTED_MASK;
9726         }
9727
9728         if ((phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X84833) ||
9729             (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X84834)) {
9730                 /* Bring PHY out of super isolate mode as the final step. */
9731                 elink_cl45_read_and_write(sc, phy,
9732                                           MDIO_CTL_DEVAD,
9733                                           MDIO_84833_TOP_CFG_XGPHY_STRAP1,
9734                                           (uint16_t) ~
9735                                           MDIO_84833_SUPER_ISOLATE);
9736         }
9737         return rc;
9738 }
9739
9740 static uint8_t elink_848xx_read_status(struct elink_phy *phy,
9741                                        struct elink_params *params,
9742                                        struct elink_vars *vars)
9743 {
9744         struct bnx2x_softc *sc = params->sc;
9745         uint16_t val, val1, val2;
9746         uint8_t link_up = 0;
9747
9748         /* Check 10G-BaseT link status */
9749         /* Check PMD signal ok */
9750         elink_cl45_read(sc, phy, MDIO_AN_DEVAD, 0xFFFA, &val1);
9751         elink_cl45_read(sc, phy,
9752                         MDIO_PMA_DEVAD, MDIO_PMA_REG_8481_PMD_SIGNAL, &val2);
9753         PMD_DRV_LOG(DEBUG, "BNX2X848xx: PMD_SIGNAL 1.a811 = 0x%x", val2);
9754
9755         /* Check link 10G */
9756         if (val2 & (1 << 11)) {
9757                 vars->line_speed = ELINK_SPEED_10000;
9758                 vars->duplex = DUPLEX_FULL;
9759                 link_up = 1;
9760                 elink_ext_phy_10G_an_resolve(sc, phy, vars);
9761         } else {                /* Check Legacy speed link */
9762                 uint16_t legacy_status, legacy_speed, mii_ctrl;
9763
9764                 /* Enable expansion register 0x42 (Operation mode status) */
9765                 elink_cl45_write(sc, phy,
9766                                  MDIO_AN_DEVAD,
9767                                  MDIO_AN_REG_8481_EXPANSION_REG_ACCESS, 0xf42);
9768
9769                 /* Get legacy speed operation status */
9770                 elink_cl45_read(sc, phy,
9771                                 MDIO_AN_DEVAD,
9772                                 MDIO_AN_REG_8481_EXPANSION_REG_RD_RW,
9773                                 &legacy_status);
9774
9775                 PMD_DRV_LOG(DEBUG, "Legacy speed status = 0x%x", legacy_status);
9776                 link_up = ((legacy_status & (1 << 11)) == (1 << 11));
9777                 legacy_speed = (legacy_status & (3 << 9));
9778                 if (legacy_speed == (0 << 9))
9779                         vars->line_speed = ELINK_SPEED_10;
9780                 else if (legacy_speed == (1 << 9))
9781                         vars->line_speed = ELINK_SPEED_100;
9782                 else if (legacy_speed == (2 << 9))
9783                         vars->line_speed = ELINK_SPEED_1000;
9784                 else {          /* Should not happen: Treat as link down */
9785                         vars->line_speed = 0;
9786                         link_up = 0;
9787                 }
9788
9789                 if (params->feature_config_flags &
9790                     ELINK_FEATURE_CONFIG_IEEE_PHY_TEST) {
9791                         elink_cl45_read(sc, phy,
9792                                         MDIO_AN_DEVAD,
9793                                         MDIO_AN_REG_8481_LEGACY_MII_CTRL,
9794                                         &mii_ctrl);
9795                         /* For IEEE testing, check for a fake link. */
9796                         link_up |= ((mii_ctrl & 0x3040) == 0x40);
9797                 }
9798
9799                 if (link_up) {
9800                         if (legacy_status & (1 << 8))
9801                                 vars->duplex = DUPLEX_FULL;
9802                         else
9803                                 vars->duplex = DUPLEX_HALF;
9804
9805                         PMD_DRV_LOG(DEBUG,
9806                                     "Link is up in %dMbps, is_duplex_full= %d",
9807                                     vars->line_speed,
9808                                     (vars->duplex == DUPLEX_FULL));
9809                         /* Check legacy speed AN resolution */
9810                         elink_cl45_read(sc, phy,
9811                                         MDIO_AN_DEVAD,
9812                                         MDIO_AN_REG_8481_LEGACY_MII_STATUS,
9813                                         &val);
9814                         if (val & (1 << 5))
9815                                 vars->link_status |=
9816                                     LINK_STATUS_AUTO_NEGOTIATE_COMPLETE;
9817                         elink_cl45_read(sc, phy,
9818                                         MDIO_AN_DEVAD,
9819                                         MDIO_AN_REG_8481_LEGACY_AN_EXPANSION,
9820                                         &val);
9821                         if ((val & (1 << 0)) == 0)
9822                                 vars->link_status |=
9823                                     LINK_STATUS_PARALLEL_DETECTION_USED;
9824                 }
9825         }
9826         if (link_up) {
9827                 PMD_DRV_LOG(DEBUG, "BNX2X848x3: link speed is %d",
9828                             vars->line_speed);
9829                 elink_ext_phy_resolve_fc(phy, params, vars);
9830
9831                 /* Read LP advertised speeds */
9832                 elink_cl45_read(sc, phy, MDIO_AN_DEVAD,
9833                                 MDIO_AN_REG_CL37_FC_LP, &val);
9834                 if (val & (1 << 5))
9835                         vars->link_status |=
9836                             LINK_STATUS_LINK_PARTNER_10THD_CAPABLE;
9837                 if (val & (1 << 6))
9838                         vars->link_status |=
9839                             LINK_STATUS_LINK_PARTNER_10TFD_CAPABLE;
9840                 if (val & (1 << 7))
9841                         vars->link_status |=
9842                             LINK_STATUS_LINK_PARTNER_100TXHD_CAPABLE;
9843                 if (val & (1 << 8))
9844                         vars->link_status |=
9845                             LINK_STATUS_LINK_PARTNER_100TXFD_CAPABLE;
9846                 if (val & (1 << 9))
9847                         vars->link_status |=
9848                             LINK_STATUS_LINK_PARTNER_100T4_CAPABLE;
9849
9850                 elink_cl45_read(sc, phy, MDIO_AN_DEVAD,
9851                                 MDIO_AN_REG_1000T_STATUS, &val);
9852
9853                 if (val & (1 << 10))
9854                         vars->link_status |=
9855                             LINK_STATUS_LINK_PARTNER_1000THD_CAPABLE;
9856                 if (val & (1 << 11))
9857                         vars->link_status |=
9858                             LINK_STATUS_LINK_PARTNER_1000TFD_CAPABLE;
9859
9860                 elink_cl45_read(sc, phy, MDIO_AN_DEVAD,
9861                                 MDIO_AN_REG_MASTER_STATUS, &val);
9862
9863                 if (val & (1 << 11))
9864                         vars->link_status |=
9865                             LINK_STATUS_LINK_PARTNER_10GXFD_CAPABLE;
9866
9867                 /* Determine if EEE was negotiated */
9868                 if ((phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X84833) ||
9869                     (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X84834))
9870                         elink_eee_an_resolve(phy, params, vars);
9871         }
9872
9873         return link_up;
9874 }
9875
9876 static elink_status_t elink_848xx_format_ver(uint32_t raw_ver, uint8_t * str,
9877                                              uint16_t * len)
9878 {
9879         elink_status_t status = ELINK_STATUS_OK;
9880         uint32_t spirom_ver;
9881         spirom_ver = ((raw_ver & 0xF80) >> 7) << 16 | (raw_ver & 0x7F);
9882         status = elink_format_ver(spirom_ver, str, len);
9883         return status;
9884 }
9885
9886 static void elink_8481_hw_reset(__rte_unused struct elink_phy *phy,
9887                                 struct elink_params *params)
9888 {
9889         elink_cb_gpio_write(params->sc, MISC_REGISTERS_GPIO_1,
9890                             MISC_REGISTERS_GPIO_OUTPUT_LOW, 0);
9891         elink_cb_gpio_write(params->sc, MISC_REGISTERS_GPIO_1,
9892                             MISC_REGISTERS_GPIO_OUTPUT_LOW, 1);
9893 }
9894
9895 static void elink_8481_link_reset(struct elink_phy *phy,
9896                                   struct elink_params *params)
9897 {
9898         elink_cl45_write(params->sc, phy,
9899                          MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x0000);
9900         elink_cl45_write(params->sc, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 1);
9901 }
9902
9903 static void elink_848x3_link_reset(struct elink_phy *phy,
9904                                    struct elink_params *params)
9905 {
9906         struct bnx2x_softc *sc = params->sc;
9907         uint8_t port;
9908         uint16_t val16;
9909
9910         if (!(CHIP_IS_E1x(sc)))
9911                 port = SC_PATH(sc);
9912         else
9913                 port = params->port;
9914
9915         if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X84823) {
9916                 elink_cb_gpio_write(sc, MISC_REGISTERS_GPIO_3,
9917                                     MISC_REGISTERS_GPIO_OUTPUT_LOW, port);
9918         } else {
9919                 elink_cl45_read(sc, phy,
9920                                 MDIO_CTL_DEVAD,
9921                                 MDIO_84833_TOP_CFG_XGPHY_STRAP1, &val16);
9922                 val16 |= MDIO_84833_SUPER_ISOLATE;
9923                 elink_cl45_write(sc, phy,
9924                                  MDIO_CTL_DEVAD,
9925                                  MDIO_84833_TOP_CFG_XGPHY_STRAP1, val16);
9926         }
9927 }
9928
9929 static void elink_848xx_set_link_led(struct elink_phy *phy,
9930                                      struct elink_params *params, uint8_t mode)
9931 {
9932         struct bnx2x_softc *sc = params->sc;
9933         uint16_t val;
9934         __rte_unused uint8_t port;
9935
9936         if (!(CHIP_IS_E1x(sc)))
9937                 port = SC_PATH(sc);
9938         else
9939                 port = params->port;
9940
9941         switch (mode) {
9942         case ELINK_LED_MODE_OFF:
9943
9944                 PMD_DRV_LOG(DEBUG, "Port 0x%x: LED MODE OFF", port);
9945
9946                 if ((params->hw_led_mode << SHARED_HW_CFG_LED_MODE_SHIFT) ==
9947                     SHARED_HW_CFG_LED_EXTPHY1) {
9948
9949                         /* Set LED masks */
9950                         elink_cl45_write(sc, phy,
9951                                          MDIO_PMA_DEVAD,
9952                                          MDIO_PMA_REG_8481_LED1_MASK, 0x0);
9953
9954                         elink_cl45_write(sc, phy,
9955                                          MDIO_PMA_DEVAD,
9956                                          MDIO_PMA_REG_8481_LED2_MASK, 0x0);
9957
9958                         elink_cl45_write(sc, phy,
9959                                          MDIO_PMA_DEVAD,
9960                                          MDIO_PMA_REG_8481_LED3_MASK, 0x0);
9961
9962                         elink_cl45_write(sc, phy,
9963                                          MDIO_PMA_DEVAD,
9964                                          MDIO_PMA_REG_8481_LED5_MASK, 0x0);
9965
9966                 } else {
9967                         elink_cl45_write(sc, phy,
9968                                          MDIO_PMA_DEVAD,
9969                                          MDIO_PMA_REG_8481_LED1_MASK, 0x0);
9970                 }
9971                 break;
9972         case ELINK_LED_MODE_FRONT_PANEL_OFF:
9973
9974                 PMD_DRV_LOG(DEBUG, "Port 0x%x: LED MODE FRONT PANEL OFF", port);
9975
9976                 if ((params->hw_led_mode << SHARED_HW_CFG_LED_MODE_SHIFT) ==
9977                     SHARED_HW_CFG_LED_EXTPHY1) {
9978
9979                         /* Set LED masks */
9980                         elink_cl45_write(sc, phy,
9981                                          MDIO_PMA_DEVAD,
9982                                          MDIO_PMA_REG_8481_LED1_MASK, 0x0);
9983
9984                         elink_cl45_write(sc, phy,
9985                                          MDIO_PMA_DEVAD,
9986                                          MDIO_PMA_REG_8481_LED2_MASK, 0x0);
9987
9988                         elink_cl45_write(sc, phy,
9989                                          MDIO_PMA_DEVAD,
9990                                          MDIO_PMA_REG_8481_LED3_MASK, 0x0);
9991
9992                         elink_cl45_write(sc, phy,
9993                                          MDIO_PMA_DEVAD,
9994                                          MDIO_PMA_REG_8481_LED5_MASK, 0x20);
9995
9996                 } else {
9997                         elink_cl45_write(sc, phy,
9998                                          MDIO_PMA_DEVAD,
9999                                          MDIO_PMA_REG_8481_LED1_MASK, 0x0);
10000                         if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X84834) {
10001                                 /* Disable MI_INT interrupt before setting LED4
10002                                  * source to constant off.
10003                                  */
10004                                 if (REG_RD(sc, NIG_REG_MASK_INTERRUPT_PORT0 +
10005                                            params->port * 4) &
10006                                     ELINK_NIG_MASK_MI_INT) {
10007                                         params->link_flags |=
10008                                             ELINK_LINK_FLAGS_INT_DISABLED;
10009
10010                                         elink_bits_dis(sc,
10011                                                        NIG_REG_MASK_INTERRUPT_PORT0
10012                                                        + params->port * 4,
10013                                                        ELINK_NIG_MASK_MI_INT);
10014                                 }
10015                                 elink_cl45_write(sc, phy,
10016                                                  MDIO_PMA_DEVAD,
10017                                                  MDIO_PMA_REG_8481_SIGNAL_MASK,
10018                                                  0x0);
10019                         }
10020                 }
10021                 break;
10022         case ELINK_LED_MODE_ON:
10023
10024                 PMD_DRV_LOG(DEBUG, "Port 0x%x: LED MODE ON", port);
10025
10026                 if ((params->hw_led_mode << SHARED_HW_CFG_LED_MODE_SHIFT) ==
10027                     SHARED_HW_CFG_LED_EXTPHY1) {
10028                         /* Set control reg */
10029                         elink_cl45_read(sc, phy,
10030                                         MDIO_PMA_DEVAD,
10031                                         MDIO_PMA_REG_8481_LINK_SIGNAL, &val);
10032                         val &= 0x8000;
10033                         val |= 0x2492;
10034
10035                         elink_cl45_write(sc, phy,
10036                                          MDIO_PMA_DEVAD,
10037                                          MDIO_PMA_REG_8481_LINK_SIGNAL, val);
10038
10039                         /* Set LED masks */
10040                         elink_cl45_write(sc, phy,
10041                                          MDIO_PMA_DEVAD,
10042                                          MDIO_PMA_REG_8481_LED1_MASK, 0x0);
10043
10044                         elink_cl45_write(sc, phy,
10045                                          MDIO_PMA_DEVAD,
10046                                          MDIO_PMA_REG_8481_LED2_MASK, 0x20);
10047
10048                         elink_cl45_write(sc, phy,
10049                                          MDIO_PMA_DEVAD,
10050                                          MDIO_PMA_REG_8481_LED3_MASK, 0x20);
10051
10052                         elink_cl45_write(sc, phy,
10053                                          MDIO_PMA_DEVAD,
10054                                          MDIO_PMA_REG_8481_LED5_MASK, 0x0);
10055                 } else {
10056                         elink_cl45_write(sc, phy,
10057                                          MDIO_PMA_DEVAD,
10058                                          MDIO_PMA_REG_8481_LED1_MASK, 0x20);
10059                         if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X84834) {
10060                                 /* Disable MI_INT interrupt before setting LED4
10061                                  * source to constant on.
10062                                  */
10063                                 if (REG_RD(sc, NIG_REG_MASK_INTERRUPT_PORT0 +
10064                                            params->port * 4) &
10065                                     ELINK_NIG_MASK_MI_INT) {
10066                                         params->link_flags |=
10067                                             ELINK_LINK_FLAGS_INT_DISABLED;
10068
10069                                         elink_bits_dis(sc,
10070                                                        NIG_REG_MASK_INTERRUPT_PORT0
10071                                                        + params->port * 4,
10072                                                        ELINK_NIG_MASK_MI_INT);
10073                                 }
10074                                 elink_cl45_write(sc, phy,
10075                                                  MDIO_PMA_DEVAD,
10076                                                  MDIO_PMA_REG_8481_SIGNAL_MASK,
10077                                                  0x20);
10078                         }
10079                 }
10080                 break;
10081
10082         case ELINK_LED_MODE_OPER:
10083
10084                 PMD_DRV_LOG(DEBUG, "Port 0x%x: LED MODE OPER", port);
10085
10086                 if ((params->hw_led_mode << SHARED_HW_CFG_LED_MODE_SHIFT) ==
10087                     SHARED_HW_CFG_LED_EXTPHY1) {
10088
10089                         /* Set control reg */
10090                         elink_cl45_read(sc, phy,
10091                                         MDIO_PMA_DEVAD,
10092                                         MDIO_PMA_REG_8481_LINK_SIGNAL, &val);
10093
10094                         if (!((val &
10095                                MDIO_PMA_REG_8481_LINK_SIGNAL_LED4_ENABLE_MASK)
10096                               >>
10097                               MDIO_PMA_REG_8481_LINK_SIGNAL_LED4_ENABLE_SHIFT))
10098                         {
10099                                 PMD_DRV_LOG(DEBUG, "Setting LINK_SIGNAL");
10100                                 elink_cl45_write(sc, phy,
10101                                                  MDIO_PMA_DEVAD,
10102                                                  MDIO_PMA_REG_8481_LINK_SIGNAL,
10103                                                  0xa492);
10104                         }
10105
10106                         /* Set LED masks */
10107                         elink_cl45_write(sc, phy,
10108                                          MDIO_PMA_DEVAD,
10109                                          MDIO_PMA_REG_8481_LED1_MASK, 0x10);
10110
10111                         elink_cl45_write(sc, phy,
10112                                          MDIO_PMA_DEVAD,
10113                                          MDIO_PMA_REG_8481_LED2_MASK, 0x80);
10114
10115                         elink_cl45_write(sc, phy,
10116                                          MDIO_PMA_DEVAD,
10117                                          MDIO_PMA_REG_8481_LED3_MASK, 0x98);
10118
10119                         elink_cl45_write(sc, phy,
10120                                          MDIO_PMA_DEVAD,
10121                                          MDIO_PMA_REG_8481_LED5_MASK, 0x40);
10122
10123                 } else {
10124                         /* EXTPHY2 LED mode indicate that the 100M/1G/10G LED
10125                          * sources are all wired through LED1, rather than only
10126                          * 10G in other modes.
10127                          */
10128                         val = ((params->hw_led_mode <<
10129                                 SHARED_HW_CFG_LED_MODE_SHIFT) ==
10130                                SHARED_HW_CFG_LED_EXTPHY2) ? 0x98 : 0x80;
10131
10132                         elink_cl45_write(sc, phy,
10133                                          MDIO_PMA_DEVAD,
10134                                          MDIO_PMA_REG_8481_LED1_MASK, val);
10135
10136                         /* Tell LED3 to blink on source */
10137                         elink_cl45_read(sc, phy,
10138                                         MDIO_PMA_DEVAD,
10139                                         MDIO_PMA_REG_8481_LINK_SIGNAL, &val);
10140                         val &= ~(7 << 6);
10141                         val |= (1 << 6);        /* A83B[8:6]= 1 */
10142                         elink_cl45_write(sc, phy,
10143                                          MDIO_PMA_DEVAD,
10144                                          MDIO_PMA_REG_8481_LINK_SIGNAL, val);
10145                         if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X84834) {
10146                                 /* Restore LED4 source to external link,
10147                                  * and re-enable interrupts.
10148                                  */
10149                                 elink_cl45_write(sc, phy,
10150                                                  MDIO_PMA_DEVAD,
10151                                                  MDIO_PMA_REG_8481_SIGNAL_MASK,
10152                                                  0x40);
10153                                 if (params->link_flags &
10154                                     ELINK_LINK_FLAGS_INT_DISABLED) {
10155                                         elink_link_int_enable(params);
10156                                         params->link_flags &=
10157                                             ~ELINK_LINK_FLAGS_INT_DISABLED;
10158                                 }
10159                         }
10160                 }
10161                 break;
10162         }
10163
10164         /* This is a workaround for E3+84833 until autoneg
10165          * restart is fixed in f/w
10166          */
10167         if (CHIP_IS_E3(sc)) {
10168                 elink_cl45_read(sc, phy, MDIO_WC_DEVAD,
10169                                 MDIO_WC_REG_GP2_STATUS_GP_2_1, &val);
10170         }
10171 }
10172
10173 /******************************************************************/
10174 /*                      54618SE PHY SECTION                       */
10175 /******************************************************************/
10176 static void elink_54618se_specific_func(struct elink_phy *phy,
10177                                         struct elink_params *params,
10178                                         uint32_t action)
10179 {
10180         struct bnx2x_softc *sc = params->sc;
10181         uint16_t temp;
10182         switch (action) {
10183         case ELINK_PHY_INIT:
10184                 /* Configure LED4: set to INTR (0x6). */
10185                 /* Accessing shadow register 0xe. */
10186                 elink_cl22_write(sc, phy,
10187                                  MDIO_REG_GPHY_SHADOW,
10188                                  MDIO_REG_GPHY_SHADOW_LED_SEL2);
10189                 elink_cl22_read(sc, phy, MDIO_REG_GPHY_SHADOW, &temp);
10190                 temp &= ~(0xf << 4);
10191                 temp |= (0x6 << 4);
10192                 elink_cl22_write(sc, phy,
10193                                  MDIO_REG_GPHY_SHADOW,
10194                                  MDIO_REG_GPHY_SHADOW_WR_ENA | temp);
10195                 /* Configure INTR based on link status change. */
10196                 elink_cl22_write(sc, phy,
10197                                  MDIO_REG_INTR_MASK,
10198                                  ~MDIO_REG_INTR_MASK_LINK_STATUS);
10199                 break;
10200         }
10201 }
10202
10203 static elink_status_t elink_54618se_config_init(struct elink_phy *phy,
10204                                                 struct elink_params *params,
10205                                                 struct elink_vars *vars)
10206 {
10207         struct bnx2x_softc *sc = params->sc;
10208         uint8_t port;
10209         uint16_t autoneg_val, an_1000_val, an_10_100_val, fc_val, temp;
10210         uint32_t cfg_pin;
10211
10212         PMD_DRV_LOG(DEBUG, "54618SE cfg init");
10213         DELAY(1000 * 1);
10214
10215         /* This works with E3 only, no need to check the chip
10216          * before determining the port.
10217          */
10218         port = params->port;
10219
10220         cfg_pin = (REG_RD(sc, params->shmem_base +
10221                           offsetof(struct shmem_region,
10222                                    dev_info.port_hw_config[port].
10223                                    e3_cmn_pin_cfg)) &
10224                    PORT_HW_CFG_E3_PHY_RESET_MASK) >>
10225             PORT_HW_CFG_E3_PHY_RESET_SHIFT;
10226
10227         /* Drive pin high to bring the GPHY out of reset. */
10228         elink_set_cfg_pin(sc, cfg_pin, 1);
10229
10230         /* wait for GPHY to reset */
10231         DELAY(1000 * 50);
10232
10233         /* reset phy */
10234         elink_cl22_write(sc, phy, MDIO_PMA_REG_CTRL, 0x8000);
10235         elink_wait_reset_complete(sc, phy, params);
10236
10237         /* Wait for GPHY to reset */
10238         DELAY(1000 * 50);
10239
10240         elink_54618se_specific_func(phy, params, ELINK_PHY_INIT);
10241         /* Flip the signal detect polarity (set 0x1c.0x1e[8]). */
10242         elink_cl22_write(sc, phy,
10243                          MDIO_REG_GPHY_SHADOW,
10244                          MDIO_REG_GPHY_SHADOW_AUTO_DET_MED);
10245         elink_cl22_read(sc, phy, MDIO_REG_GPHY_SHADOW, &temp);
10246         temp |= MDIO_REG_GPHY_SHADOW_INVERT_FIB_SD;
10247         elink_cl22_write(sc, phy,
10248                          MDIO_REG_GPHY_SHADOW,
10249                          MDIO_REG_GPHY_SHADOW_WR_ENA | temp);
10250
10251         /* Set up fc */
10252         /* Please refer to Table 28B-3 of 802.3ab-1999 spec. */
10253         elink_calc_ieee_aneg_adv(phy, params, &vars->ieee_fc);
10254         fc_val = 0;
10255         if ((vars->ieee_fc & MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC) ==
10256             MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC)
10257                 fc_val |= MDIO_AN_REG_ADV_PAUSE_ASYMMETRIC;
10258
10259         if ((vars->ieee_fc & MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) ==
10260             MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH)
10261                 fc_val |= MDIO_AN_REG_ADV_PAUSE_PAUSE;
10262
10263         /* Read all advertisement */
10264         elink_cl22_read(sc, phy, 0x09, &an_1000_val);
10265
10266         elink_cl22_read(sc, phy, 0x04, &an_10_100_val);
10267
10268         elink_cl22_read(sc, phy, MDIO_PMA_REG_CTRL, &autoneg_val);
10269
10270         /* Disable forced speed */
10271         autoneg_val &=
10272             ~((1 << 6) | (1 << 8) | (1 << 9) | (1 << 12) | (1 << 13));
10273         an_10_100_val &=
10274             ~((1 << 5) | (1 << 6) | (1 << 7) | (1 << 8) | (1 << 10) |
10275               (1 << 11));
10276
10277         if (((phy->req_line_speed == ELINK_SPEED_AUTO_NEG) &&
10278              (phy->speed_cap_mask &
10279               PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) ||
10280             (phy->req_line_speed == ELINK_SPEED_1000)) {
10281                 an_1000_val |= (1 << 8);
10282                 autoneg_val |= (1 << 9 | 1 << 12);
10283                 if (phy->req_duplex == DUPLEX_FULL)
10284                         an_1000_val |= (1 << 9);
10285                 PMD_DRV_LOG(DEBUG, "Advertising 1G");
10286         } else
10287                 an_1000_val &= ~((1 << 8) | (1 << 9));
10288
10289         elink_cl22_write(sc, phy, 0x09, an_1000_val);
10290         elink_cl22_read(sc, phy, 0x09, &an_1000_val);
10291
10292         /* Advertise 10/100 link speed */
10293         if (phy->req_line_speed == ELINK_SPEED_AUTO_NEG) {
10294                 if (phy->speed_cap_mask &
10295                     PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF) {
10296                         an_10_100_val |= (1 << 5);
10297                         autoneg_val |= (1 << 9 | 1 << 12);
10298                         PMD_DRV_LOG(DEBUG, "Advertising 10M-HD");
10299                 }
10300                 if (phy->speed_cap_mask &
10301                     PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF) {
10302                         an_10_100_val |= (1 << 6);
10303                         autoneg_val |= (1 << 9 | 1 << 12);
10304                         PMD_DRV_LOG(DEBUG, "Advertising 10M-FD");
10305                 }
10306                 if (phy->speed_cap_mask &
10307                     PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF) {
10308                         an_10_100_val |= (1 << 7);
10309                         autoneg_val |= (1 << 9 | 1 << 12);
10310                         PMD_DRV_LOG(DEBUG, "Advertising 100M-HD");
10311                 }
10312                 if (phy->speed_cap_mask &
10313                     PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL) {
10314                         an_10_100_val |= (1 << 8);
10315                         autoneg_val |= (1 << 9 | 1 << 12);
10316                         PMD_DRV_LOG(DEBUG, "Advertising 100M-FD");
10317                 }
10318         }
10319
10320         /* Only 10/100 are allowed to work in FORCE mode */
10321         if (phy->req_line_speed == ELINK_SPEED_100) {
10322                 autoneg_val |= (1 << 13);
10323                 /* Enabled AUTO-MDIX when autoneg is disabled */
10324                 elink_cl22_write(sc, phy, 0x18, (1 << 15 | 1 << 9 | 7 << 0));
10325                 PMD_DRV_LOG(DEBUG, "Setting 100M force");
10326         }
10327         if (phy->req_line_speed == ELINK_SPEED_10) {
10328                 /* Enabled AUTO-MDIX when autoneg is disabled */
10329                 elink_cl22_write(sc, phy, 0x18, (1 << 15 | 1 << 9 | 7 << 0));
10330                 PMD_DRV_LOG(DEBUG, "Setting 10M force");
10331         }
10332
10333         if ((phy->flags & ELINK_FLAGS_EEE) && elink_eee_has_cap(params)) {
10334                 elink_status_t rc;
10335
10336                 elink_cl22_write(sc, phy, MDIO_REG_GPHY_EXP_ACCESS,
10337                                  MDIO_REG_GPHY_EXP_ACCESS_TOP |
10338                                  MDIO_REG_GPHY_EXP_TOP_2K_BUF);
10339                 elink_cl22_read(sc, phy, MDIO_REG_GPHY_EXP_ACCESS_GATE, &temp);
10340                 temp &= 0xfffe;
10341                 elink_cl22_write(sc, phy, MDIO_REG_GPHY_EXP_ACCESS_GATE, temp);
10342
10343                 rc = elink_eee_initial_config(params, vars, SHMEM_EEE_1G_ADV);
10344                 if (rc != ELINK_STATUS_OK) {
10345                         PMD_DRV_LOG(DEBUG, "Failed to configure EEE timers");
10346                         elink_eee_disable(phy, params, vars);
10347                 } else if ((params->eee_mode & ELINK_EEE_MODE_ADV_LPI) &&
10348                            (phy->req_duplex == DUPLEX_FULL) &&
10349                            (elink_eee_calc_timer(params) ||
10350                             !(params->eee_mode & ELINK_EEE_MODE_ENABLE_LPI))) {
10351                         /* Need to advertise EEE only when requested,
10352                          * and either no LPI assertion was requested,
10353                          * or it was requested and a valid timer was set.
10354                          * Also notice full duplex is required for EEE.
10355                          */
10356                         elink_eee_advertise(phy, params, vars,
10357                                             SHMEM_EEE_1G_ADV);
10358                 } else {
10359                         PMD_DRV_LOG(DEBUG, "Don't Advertise 1GBase-T EEE");
10360                         elink_eee_disable(phy, params, vars);
10361                 }
10362         } else {
10363                 vars->eee_status &= ~SHMEM_EEE_1G_ADV <<
10364                     SHMEM_EEE_SUPPORTED_SHIFT;
10365
10366                 if (phy->flags & ELINK_FLAGS_EEE) {
10367                         /* Handle legacy auto-grEEEn */
10368                         if (params->feature_config_flags &
10369                             ELINK_FEATURE_CONFIG_AUTOGREEEN_ENABLED) {
10370                                 temp = 6;
10371                                 PMD_DRV_LOG(DEBUG, "Enabling Auto-GrEEEn");
10372                         } else {
10373                                 temp = 0;
10374                                 PMD_DRV_LOG(DEBUG, "Don't Adv. EEE");
10375                         }
10376                         elink_cl45_write(sc, phy, MDIO_AN_DEVAD,
10377                                          MDIO_AN_REG_EEE_ADV, temp);
10378                 }
10379         }
10380
10381         elink_cl22_write(sc, phy, 0x04, an_10_100_val | fc_val);
10382
10383         if (phy->req_duplex == DUPLEX_FULL)
10384                 autoneg_val |= (1 << 8);
10385
10386         elink_cl22_write(sc, phy, MDIO_PMA_REG_CTRL, autoneg_val);
10387
10388         return ELINK_STATUS_OK;
10389 }
10390
10391 static void elink_5461x_set_link_led(struct elink_phy *phy,
10392                                      struct elink_params *params, uint8_t mode)
10393 {
10394         struct bnx2x_softc *sc = params->sc;
10395         uint16_t temp;
10396
10397         elink_cl22_write(sc, phy,
10398                          MDIO_REG_GPHY_SHADOW, MDIO_REG_GPHY_SHADOW_LED_SEL1);
10399         elink_cl22_read(sc, phy, MDIO_REG_GPHY_SHADOW, &temp);
10400         temp &= 0xff00;
10401
10402         PMD_DRV_LOG(DEBUG, "54618x set link led (mode=%x)", mode);
10403         switch (mode) {
10404         case ELINK_LED_MODE_FRONT_PANEL_OFF:
10405         case ELINK_LED_MODE_OFF:
10406                 temp |= 0x00ee;
10407                 break;
10408         case ELINK_LED_MODE_OPER:
10409                 temp |= 0x0001;
10410                 break;
10411         case ELINK_LED_MODE_ON:
10412                 temp |= 0x00ff;
10413                 break;
10414         default:
10415                 break;
10416         }
10417         elink_cl22_write(sc, phy,
10418                          MDIO_REG_GPHY_SHADOW,
10419                          MDIO_REG_GPHY_SHADOW_WR_ENA | temp);
10420         return;
10421 }
10422
10423 static void elink_54618se_link_reset(struct elink_phy *phy,
10424                                      struct elink_params *params)
10425 {
10426         struct bnx2x_softc *sc = params->sc;
10427         uint32_t cfg_pin;
10428         uint8_t port;
10429
10430         /* In case of no EPIO routed to reset the GPHY, put it
10431          * in low power mode.
10432          */
10433         elink_cl22_write(sc, phy, MDIO_PMA_REG_CTRL, 0x800);
10434         /* This works with E3 only, no need to check the chip
10435          * before determining the port.
10436          */
10437         port = params->port;
10438         cfg_pin = (REG_RD(sc, params->shmem_base +
10439                           offsetof(struct shmem_region,
10440                                    dev_info.port_hw_config[port].
10441                                    e3_cmn_pin_cfg)) &
10442                    PORT_HW_CFG_E3_PHY_RESET_MASK) >>
10443             PORT_HW_CFG_E3_PHY_RESET_SHIFT;
10444
10445         /* Drive pin low to put GPHY in reset. */
10446         elink_set_cfg_pin(sc, cfg_pin, 0);
10447 }
10448
10449 static uint8_t elink_54618se_read_status(struct elink_phy *phy,
10450                                          struct elink_params *params,
10451                                          struct elink_vars *vars)
10452 {
10453         struct bnx2x_softc *sc = params->sc;
10454         uint16_t val;
10455         uint8_t link_up = 0;
10456         uint16_t legacy_status, legacy_speed;
10457
10458         /* Get speed operation status */
10459         elink_cl22_read(sc, phy, MDIO_REG_GPHY_AUX_STATUS, &legacy_status);
10460         PMD_DRV_LOG(DEBUG, "54618SE read_status: 0x%x", legacy_status);
10461
10462         /* Read status to clear the PHY interrupt. */
10463         elink_cl22_read(sc, phy, MDIO_REG_INTR_STATUS, &val);
10464
10465         link_up = ((legacy_status & (1 << 2)) == (1 << 2));
10466
10467         if (link_up) {
10468                 legacy_speed = (legacy_status & (7 << 8));
10469                 if (legacy_speed == (7 << 8)) {
10470                         vars->line_speed = ELINK_SPEED_1000;
10471                         vars->duplex = DUPLEX_FULL;
10472                 } else if (legacy_speed == (6 << 8)) {
10473                         vars->line_speed = ELINK_SPEED_1000;
10474                         vars->duplex = DUPLEX_HALF;
10475                 } else if (legacy_speed == (5 << 8)) {
10476                         vars->line_speed = ELINK_SPEED_100;
10477                         vars->duplex = DUPLEX_FULL;
10478                 }
10479                 /* Omitting 100Base-T4 for now */
10480                 else if (legacy_speed == (3 << 8)) {
10481                         vars->line_speed = ELINK_SPEED_100;
10482                         vars->duplex = DUPLEX_HALF;
10483                 } else if (legacy_speed == (2 << 8)) {
10484                         vars->line_speed = ELINK_SPEED_10;
10485                         vars->duplex = DUPLEX_FULL;
10486                 } else if (legacy_speed == (1 << 8)) {
10487                         vars->line_speed = ELINK_SPEED_10;
10488                         vars->duplex = DUPLEX_HALF;
10489                 } else          /* Should not happen */
10490                         vars->line_speed = 0;
10491
10492                 PMD_DRV_LOG(DEBUG,
10493                             "Link is up in %dMbps, is_duplex_full= %d",
10494                             vars->line_speed, (vars->duplex == DUPLEX_FULL));
10495
10496                 /* Check legacy speed AN resolution */
10497                 elink_cl22_read(sc, phy, 0x01, &val);
10498                 if (val & (1 << 5))
10499                         vars->link_status |=
10500                             LINK_STATUS_AUTO_NEGOTIATE_COMPLETE;
10501                 elink_cl22_read(sc, phy, 0x06, &val);
10502                 if ((val & (1 << 0)) == 0)
10503                         vars->link_status |=
10504                             LINK_STATUS_PARALLEL_DETECTION_USED;
10505
10506                 PMD_DRV_LOG(DEBUG, "BNX2X54618SE: link speed is %d",
10507                             vars->line_speed);
10508
10509                 elink_ext_phy_resolve_fc(phy, params, vars);
10510
10511                 if (vars->link_status & LINK_STATUS_AUTO_NEGOTIATE_COMPLETE) {
10512                         /* Report LP advertised speeds */
10513                         elink_cl22_read(sc, phy, 0x5, &val);
10514
10515                         if (val & (1 << 5))
10516                                 vars->link_status |=
10517                                     LINK_STATUS_LINK_PARTNER_10THD_CAPABLE;
10518                         if (val & (1 << 6))
10519                                 vars->link_status |=
10520                                     LINK_STATUS_LINK_PARTNER_10TFD_CAPABLE;
10521                         if (val & (1 << 7))
10522                                 vars->link_status |=
10523                                     LINK_STATUS_LINK_PARTNER_100TXHD_CAPABLE;
10524                         if (val & (1 << 8))
10525                                 vars->link_status |=
10526                                     LINK_STATUS_LINK_PARTNER_100TXFD_CAPABLE;
10527                         if (val & (1 << 9))
10528                                 vars->link_status |=
10529                                     LINK_STATUS_LINK_PARTNER_100T4_CAPABLE;
10530
10531                         elink_cl22_read(sc, phy, 0xa, &val);
10532                         if (val & (1 << 10))
10533                                 vars->link_status |=
10534                                     LINK_STATUS_LINK_PARTNER_1000THD_CAPABLE;
10535                         if (val & (1 << 11))
10536                                 vars->link_status |=
10537                                     LINK_STATUS_LINK_PARTNER_1000TFD_CAPABLE;
10538
10539                         if ((phy->flags & ELINK_FLAGS_EEE) &&
10540                             elink_eee_has_cap(params))
10541                                 elink_eee_an_resolve(phy, params, vars);
10542                 }
10543         }
10544         return link_up;
10545 }
10546
10547 static void elink_54618se_config_loopback(struct elink_phy *phy,
10548                                           struct elink_params *params)
10549 {
10550         struct bnx2x_softc *sc = params->sc;
10551         uint16_t val;
10552         uint32_t umac_base = params->port ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
10553
10554         PMD_DRV_LOG(DEBUG, "2PMA/PMD ext_phy_loopback: 54618se");
10555
10556         /* Enable master/slave manual mmode and set to master */
10557         /* mii write 9 [bits set 11 12] */
10558         elink_cl22_write(sc, phy, 0x09, 3 << 11);
10559
10560         /* forced 1G and disable autoneg */
10561         /* set val [mii read 0] */
10562         /* set val [expr $val & [bits clear 6 12 13]] */
10563         /* set val [expr $val | [bits set 6 8]] */
10564         /* mii write 0 $val */
10565         elink_cl22_read(sc, phy, 0x00, &val);
10566         val &= ~((1 << 6) | (1 << 12) | (1 << 13));
10567         val |= (1 << 6) | (1 << 8);
10568         elink_cl22_write(sc, phy, 0x00, val);
10569
10570         /* Set external loopback and Tx using 6dB coding */
10571         /* mii write 0x18 7 */
10572         /* set val [mii read 0x18] */
10573         /* mii write 0x18 [expr $val | [bits set 10 15]] */
10574         elink_cl22_write(sc, phy, 0x18, 7);
10575         elink_cl22_read(sc, phy, 0x18, &val);
10576         elink_cl22_write(sc, phy, 0x18, val | (1 << 10) | (1 << 15));
10577
10578         /* This register opens the gate for the UMAC despite its name */
10579         REG_WR(sc, NIG_REG_EGRESS_EMAC0_PORT + params->port * 4, 1);
10580
10581         /* Maximum Frame Length (RW). Defines a 14-Bit maximum frame
10582          * length used by the MAC receive logic to check frames.
10583          */
10584         REG_WR(sc, umac_base + UMAC_REG_MAXFR, 0x2710);
10585 }
10586
10587 /******************************************************************/
10588 /*                      SFX7101 PHY SECTION                       */
10589 /******************************************************************/
10590 static void elink_7101_config_loopback(struct elink_phy *phy,
10591                                        struct elink_params *params)
10592 {
10593         struct bnx2x_softc *sc = params->sc;
10594         /* SFX7101_XGXS_TEST1 */
10595         elink_cl45_write(sc, phy,
10596                          MDIO_XS_DEVAD, MDIO_XS_SFX7101_XGXS_TEST1, 0x100);
10597 }
10598
10599 static elink_status_t elink_7101_config_init(struct elink_phy *phy,
10600                                              struct elink_params *params,
10601                                              struct elink_vars *vars)
10602 {
10603         uint16_t fw_ver1, fw_ver2, val;
10604         struct bnx2x_softc *sc = params->sc;
10605         PMD_DRV_LOG(DEBUG, "Setting the SFX7101 LASI indication");
10606
10607         /* Restore normal power mode */
10608         elink_cb_gpio_write(sc, MISC_REGISTERS_GPIO_2,
10609                             MISC_REGISTERS_GPIO_OUTPUT_HIGH, params->port);
10610         /* HW reset */
10611         elink_ext_phy_hw_reset(sc, params->port);
10612         elink_wait_reset_complete(sc, phy, params);
10613
10614         elink_cl45_write(sc, phy, MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL, 0x1);
10615         PMD_DRV_LOG(DEBUG, "Setting the SFX7101 LED to blink on traffic");
10616         elink_cl45_write(sc, phy,
10617                          MDIO_PMA_DEVAD, MDIO_PMA_REG_7107_LED_CNTL, (1 << 3));
10618
10619         elink_ext_phy_set_pause(params, phy, vars);
10620         /* Restart autoneg */
10621         elink_cl45_read(sc, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, &val);
10622         val |= 0x200;
10623         elink_cl45_write(sc, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, val);
10624
10625         /* Save spirom version */
10626         elink_cl45_read(sc, phy,
10627                         MDIO_PMA_DEVAD, MDIO_PMA_REG_7101_VER1, &fw_ver1);
10628
10629         elink_cl45_read(sc, phy,
10630                         MDIO_PMA_DEVAD, MDIO_PMA_REG_7101_VER2, &fw_ver2);
10631         elink_save_spirom_version(sc, params->port,
10632                                   (uint32_t) (fw_ver1 << 16 | fw_ver2),
10633                                   phy->ver_addr);
10634         return ELINK_STATUS_OK;
10635 }
10636
10637 static uint8_t elink_7101_read_status(struct elink_phy *phy,
10638                                       struct elink_params *params,
10639                                       struct elink_vars *vars)
10640 {
10641         struct bnx2x_softc *sc = params->sc;
10642         uint8_t link_up;
10643         uint16_t val1, val2;
10644         elink_cl45_read(sc, phy, MDIO_PMA_DEVAD, MDIO_PMA_LASI_STAT, &val2);
10645         elink_cl45_read(sc, phy, MDIO_PMA_DEVAD, MDIO_PMA_LASI_STAT, &val1);
10646         PMD_DRV_LOG(DEBUG, "10G-base-T LASI status 0x%x->0x%x", val2, val1);
10647         elink_cl45_read(sc, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val2);
10648         elink_cl45_read(sc, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val1);
10649         PMD_DRV_LOG(DEBUG, "10G-base-T PMA status 0x%x->0x%x", val2, val1);
10650         link_up = ((val1 & 4) == 4);
10651         /* If link is up print the AN outcome of the SFX7101 PHY */
10652         if (link_up) {
10653                 elink_cl45_read(sc, phy,
10654                                 MDIO_AN_DEVAD, MDIO_AN_REG_MASTER_STATUS,
10655                                 &val2);
10656                 vars->line_speed = ELINK_SPEED_10000;
10657                 vars->duplex = DUPLEX_FULL;
10658                 PMD_DRV_LOG(DEBUG, "SFX7101 AN status 0x%x->Master=%x",
10659                             val2, (val2 & (1 << 14)));
10660                 elink_ext_phy_10G_an_resolve(sc, phy, vars);
10661                 elink_ext_phy_resolve_fc(phy, params, vars);
10662
10663                 /* Read LP advertised speeds */
10664                 if (val2 & (1 << 11))
10665                         vars->link_status |=
10666                             LINK_STATUS_LINK_PARTNER_10GXFD_CAPABLE;
10667         }
10668         return link_up;
10669 }
10670
10671 static elink_status_t elink_7101_format_ver(uint32_t spirom_ver, uint8_t * str,
10672                                             uint16_t * len)
10673 {
10674         if (*len < 5)
10675                 return ELINK_STATUS_ERROR;
10676         str[0] = (spirom_ver & 0xFF);
10677         str[1] = (spirom_ver & 0xFF00) >> 8;
10678         str[2] = (spirom_ver & 0xFF0000) >> 16;
10679         str[3] = (spirom_ver & 0xFF000000) >> 24;
10680         str[4] = '\0';
10681         *len -= 5;
10682         return ELINK_STATUS_OK;
10683 }
10684
10685 static void elink_7101_hw_reset(__rte_unused struct elink_phy *phy,
10686                                 struct elink_params *params)
10687 {
10688         /* Low power mode is controlled by GPIO 2 */
10689         elink_cb_gpio_write(params->sc, MISC_REGISTERS_GPIO_2,
10690                             MISC_REGISTERS_GPIO_OUTPUT_LOW, params->port);
10691         /* The PHY reset is controlled by GPIO 1 */
10692         elink_cb_gpio_write(params->sc, MISC_REGISTERS_GPIO_1,
10693                             MISC_REGISTERS_GPIO_OUTPUT_LOW, params->port);
10694 }
10695
10696 static void elink_7101_set_link_led(struct elink_phy *phy,
10697                                     struct elink_params *params, uint8_t mode)
10698 {
10699         uint16_t val = 0;
10700         struct bnx2x_softc *sc = params->sc;
10701         switch (mode) {
10702         case ELINK_LED_MODE_FRONT_PANEL_OFF:
10703         case ELINK_LED_MODE_OFF:
10704                 val = 2;
10705                 break;
10706         case ELINK_LED_MODE_ON:
10707                 val = 1;
10708                 break;
10709         case ELINK_LED_MODE_OPER:
10710                 val = 0;
10711                 break;
10712         }
10713         elink_cl45_write(sc, phy,
10714                          MDIO_PMA_DEVAD, MDIO_PMA_REG_7107_LINK_LED_CNTL, val);
10715 }
10716
10717 /******************************************************************/
10718 /*                      STATIC PHY DECLARATION                    */
10719 /******************************************************************/
10720
10721 static const struct elink_phy phy_null = {
10722         .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN,
10723         .addr = 0,
10724         .def_md_devad = 0,
10725         .flags = ELINK_FLAGS_INIT_XGXS_FIRST,
10726         .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
10727         .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
10728         .mdio_ctrl = 0,
10729         .supported = 0,
10730         .media_type = ELINK_ETH_PHY_NOT_PRESENT,
10731         .ver_addr = 0,
10732         .req_flow_ctrl = 0,
10733         .req_line_speed = 0,
10734         .speed_cap_mask = 0,
10735         .req_duplex = 0,
10736         .rsrv = 0,
10737         .config_init = (config_init_t) NULL,
10738         .read_status = (read_status_t) NULL,
10739         .link_reset = (link_reset_t) NULL,
10740         .config_loopback = (config_loopback_t) NULL,
10741         .format_fw_ver = (format_fw_ver_t) NULL,
10742         .hw_reset = (hw_reset_t) NULL,
10743         .set_link_led = (set_link_led_t) NULL,
10744         .phy_specific_func = (phy_specific_func_t) NULL
10745 };
10746
10747 static const struct elink_phy phy_serdes = {
10748         .type = PORT_HW_CFG_SERDES_EXT_PHY_TYPE_DIRECT,
10749         .addr = 0xff,
10750         .def_md_devad = 0,
10751         .flags = 0,
10752         .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
10753         .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
10754         .mdio_ctrl = 0,
10755         .supported = (ELINK_SUPPORTED_10baseT_Half |
10756                       ELINK_SUPPORTED_10baseT_Full |
10757                       ELINK_SUPPORTED_100baseT_Half |
10758                       ELINK_SUPPORTED_100baseT_Full |
10759                       ELINK_SUPPORTED_1000baseT_Full |
10760                       ELINK_SUPPORTED_2500baseX_Full |
10761                       ELINK_SUPPORTED_TP |
10762                       ELINK_SUPPORTED_Autoneg |
10763                       ELINK_SUPPORTED_Pause | ELINK_SUPPORTED_Asym_Pause),
10764         .media_type = ELINK_ETH_PHY_BASE_T,
10765         .ver_addr = 0,
10766         .req_flow_ctrl = 0,
10767         .req_line_speed = 0,
10768         .speed_cap_mask = 0,
10769         .req_duplex = 0,
10770         .rsrv = 0,
10771         .config_init = (config_init_t) elink_xgxs_config_init,
10772         .read_status = (read_status_t) elink_link_settings_status,
10773         .link_reset = (link_reset_t) elink_int_link_reset,
10774         .config_loopback = (config_loopback_t) NULL,
10775         .format_fw_ver = (format_fw_ver_t) NULL,
10776         .hw_reset = (hw_reset_t) NULL,
10777         .set_link_led = (set_link_led_t) NULL,
10778         .phy_specific_func = (phy_specific_func_t) NULL
10779 };
10780
10781 static const struct elink_phy phy_xgxs = {
10782         .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT,
10783         .addr = 0xff,
10784         .def_md_devad = 0,
10785         .flags = 0,
10786         .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
10787         .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
10788         .mdio_ctrl = 0,
10789         .supported = (ELINK_SUPPORTED_10baseT_Half |
10790                       ELINK_SUPPORTED_10baseT_Full |
10791                       ELINK_SUPPORTED_100baseT_Half |
10792                       ELINK_SUPPORTED_100baseT_Full |
10793                       ELINK_SUPPORTED_1000baseT_Full |
10794                       ELINK_SUPPORTED_2500baseX_Full |
10795                       ELINK_SUPPORTED_10000baseT_Full |
10796                       ELINK_SUPPORTED_FIBRE |
10797                       ELINK_SUPPORTED_Autoneg |
10798                       ELINK_SUPPORTED_Pause | ELINK_SUPPORTED_Asym_Pause),
10799         .media_type = ELINK_ETH_PHY_CX4,
10800         .ver_addr = 0,
10801         .req_flow_ctrl = 0,
10802         .req_line_speed = 0,
10803         .speed_cap_mask = 0,
10804         .req_duplex = 0,
10805         .rsrv = 0,
10806         .config_init = (config_init_t) elink_xgxs_config_init,
10807         .read_status = (read_status_t) elink_link_settings_status,
10808         .link_reset = (link_reset_t) elink_int_link_reset,
10809         .config_loopback = (config_loopback_t) elink_set_xgxs_loopback,
10810         .format_fw_ver = (format_fw_ver_t) NULL,
10811         .hw_reset = (hw_reset_t) NULL,
10812         .set_link_led = (set_link_led_t) NULL,
10813         .phy_specific_func = (phy_specific_func_t) elink_xgxs_specific_func
10814 };
10815
10816 static const struct elink_phy phy_warpcore = {
10817         .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT,
10818         .addr = 0xff,
10819         .def_md_devad = 0,
10820         .flags = ELINK_FLAGS_TX_ERROR_CHECK,
10821         .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
10822         .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
10823         .mdio_ctrl = 0,
10824         .supported = (ELINK_SUPPORTED_10baseT_Half |
10825                       ELINK_SUPPORTED_10baseT_Full |
10826                       ELINK_SUPPORTED_100baseT_Half |
10827                       ELINK_SUPPORTED_100baseT_Full |
10828                       ELINK_SUPPORTED_1000baseT_Full |
10829                       ELINK_SUPPORTED_10000baseT_Full |
10830                       ELINK_SUPPORTED_20000baseKR2_Full |
10831                       ELINK_SUPPORTED_20000baseMLD2_Full |
10832                       ELINK_SUPPORTED_FIBRE |
10833                       ELINK_SUPPORTED_Autoneg |
10834                       ELINK_SUPPORTED_Pause | ELINK_SUPPORTED_Asym_Pause),
10835         .media_type = ELINK_ETH_PHY_UNSPECIFIED,
10836         .ver_addr = 0,
10837         .req_flow_ctrl = 0,
10838         .req_line_speed = 0,
10839         .speed_cap_mask = 0,
10840         /* req_duplex = */ 0,
10841         /* rsrv = */ 0,
10842         .config_init = (config_init_t) elink_warpcore_config_init,
10843         .read_status = (read_status_t) elink_warpcore_read_status,
10844         .link_reset = (link_reset_t) elink_warpcore_link_reset,
10845         .config_loopback = (config_loopback_t) elink_set_warpcore_loopback,
10846         .format_fw_ver = (format_fw_ver_t) NULL,
10847         .hw_reset = (hw_reset_t) elink_warpcore_hw_reset,
10848         .set_link_led = (set_link_led_t) NULL,
10849         .phy_specific_func = (phy_specific_func_t) NULL
10850 };
10851
10852 static const struct elink_phy phy_7101 = {
10853         .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101,
10854         .addr = 0xff,
10855         .def_md_devad = 0,
10856         .flags = ELINK_FLAGS_FAN_FAILURE_DET_REQ,
10857         .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
10858         .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
10859         .mdio_ctrl = 0,
10860         .supported = (ELINK_SUPPORTED_10000baseT_Full |
10861                       ELINK_SUPPORTED_TP |
10862                       ELINK_SUPPORTED_Autoneg |
10863                       ELINK_SUPPORTED_Pause | ELINK_SUPPORTED_Asym_Pause),
10864         .media_type = ELINK_ETH_PHY_BASE_T,
10865         .ver_addr = 0,
10866         .req_flow_ctrl = 0,
10867         .req_line_speed = 0,
10868         .speed_cap_mask = 0,
10869         .req_duplex = 0,
10870         .rsrv = 0,
10871         .config_init = (config_init_t) elink_7101_config_init,
10872         .read_status = (read_status_t) elink_7101_read_status,
10873         .link_reset = (link_reset_t) elink_common_ext_link_reset,
10874         .config_loopback = (config_loopback_t) elink_7101_config_loopback,
10875         .format_fw_ver = (format_fw_ver_t) elink_7101_format_ver,
10876         .hw_reset = (hw_reset_t) elink_7101_hw_reset,
10877         .set_link_led = (set_link_led_t) elink_7101_set_link_led,
10878         .phy_specific_func = (phy_specific_func_t) NULL
10879 };
10880
10881 static const struct elink_phy phy_8073 = {
10882         .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X8073,
10883         .addr = 0xff,
10884         .def_md_devad = 0,
10885         .flags = 0,
10886         .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
10887         .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
10888         .mdio_ctrl = 0,
10889         .supported = (ELINK_SUPPORTED_10000baseT_Full |
10890                       ELINK_SUPPORTED_2500baseX_Full |
10891                       ELINK_SUPPORTED_1000baseT_Full |
10892                       ELINK_SUPPORTED_FIBRE |
10893                       ELINK_SUPPORTED_Autoneg |
10894                       ELINK_SUPPORTED_Pause | ELINK_SUPPORTED_Asym_Pause),
10895         .media_type = ELINK_ETH_PHY_KR,
10896         .ver_addr = 0,
10897         .req_flow_ctrl = 0,
10898         .req_line_speed = 0,
10899         .speed_cap_mask = 0,
10900         .req_duplex = 0,
10901         .rsrv = 0,
10902         .config_init = (config_init_t) elink_8073_config_init,
10903         .read_status = (read_status_t) elink_8073_read_status,
10904         .link_reset = (link_reset_t) elink_8073_link_reset,
10905         .config_loopback = (config_loopback_t) NULL,
10906         .format_fw_ver = (format_fw_ver_t) elink_format_ver,
10907         .hw_reset = (hw_reset_t) NULL,
10908         .set_link_led = (set_link_led_t) NULL,
10909         .phy_specific_func = (phy_specific_func_t) elink_8073_specific_func
10910 };
10911
10912 static const struct elink_phy phy_8705 = {
10913         .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X8705,
10914         .addr = 0xff,
10915         .def_md_devad = 0,
10916         .flags = ELINK_FLAGS_INIT_XGXS_FIRST,
10917         .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
10918         .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
10919         .mdio_ctrl = 0,
10920         .supported = (ELINK_SUPPORTED_10000baseT_Full |
10921                       ELINK_SUPPORTED_FIBRE |
10922                       ELINK_SUPPORTED_Pause | ELINK_SUPPORTED_Asym_Pause),
10923         .media_type = ELINK_ETH_PHY_XFP_FIBER,
10924         .ver_addr = 0,
10925         .req_flow_ctrl = 0,
10926         .req_line_speed = 0,
10927         .speed_cap_mask = 0,
10928         .req_duplex = 0,
10929         .rsrv = 0,
10930         .config_init = (config_init_t) elink_8705_config_init,
10931         .read_status = (read_status_t) elink_8705_read_status,
10932         .link_reset = (link_reset_t) elink_common_ext_link_reset,
10933         .config_loopback = (config_loopback_t) NULL,
10934         .format_fw_ver = (format_fw_ver_t) elink_null_format_ver,
10935         .hw_reset = (hw_reset_t) NULL,
10936         .set_link_led = (set_link_led_t) NULL,
10937         .phy_specific_func = (phy_specific_func_t) NULL
10938 };
10939
10940 static const struct elink_phy phy_8706 = {
10941         .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X8706,
10942         .addr = 0xff,
10943         .def_md_devad = 0,
10944         .flags = ELINK_FLAGS_INIT_XGXS_FIRST,
10945         .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
10946         .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
10947         .mdio_ctrl = 0,
10948         .supported = (ELINK_SUPPORTED_10000baseT_Full |
10949                       ELINK_SUPPORTED_1000baseT_Full |
10950                       ELINK_SUPPORTED_FIBRE |
10951                       ELINK_SUPPORTED_Pause | ELINK_SUPPORTED_Asym_Pause),
10952         .media_type = ELINK_ETH_PHY_SFPP_10G_FIBER,
10953         .ver_addr = 0,
10954         .req_flow_ctrl = 0,
10955         .req_line_speed = 0,
10956         .speed_cap_mask = 0,
10957         .req_duplex = 0,
10958         .rsrv = 0,
10959         .config_init = (config_init_t) elink_8706_config_init,
10960         .read_status = (read_status_t) elink_8706_read_status,
10961         .link_reset = (link_reset_t) elink_common_ext_link_reset,
10962         .config_loopback = (config_loopback_t) NULL,
10963         .format_fw_ver = (format_fw_ver_t) elink_format_ver,
10964         .hw_reset = (hw_reset_t) NULL,
10965         .set_link_led = (set_link_led_t) NULL,
10966         .phy_specific_func = (phy_specific_func_t) NULL
10967 };
10968
10969 static const struct elink_phy phy_8726 = {
10970         .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X8726,
10971         .addr = 0xff,
10972         .def_md_devad = 0,
10973         .flags = (ELINK_FLAGS_INIT_XGXS_FIRST | ELINK_FLAGS_TX_ERROR_CHECK),
10974         .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
10975         .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
10976         .mdio_ctrl = 0,
10977         .supported = (ELINK_SUPPORTED_10000baseT_Full |
10978                       ELINK_SUPPORTED_1000baseT_Full |
10979                       ELINK_SUPPORTED_Autoneg |
10980                       ELINK_SUPPORTED_FIBRE |
10981                       ELINK_SUPPORTED_Pause | ELINK_SUPPORTED_Asym_Pause),
10982         .media_type = ELINK_ETH_PHY_NOT_PRESENT,
10983         .ver_addr = 0,
10984         .req_flow_ctrl = 0,
10985         .req_line_speed = 0,
10986         .speed_cap_mask = 0,
10987         .req_duplex = 0,
10988         .rsrv = 0,
10989         .config_init = (config_init_t) elink_8726_config_init,
10990         .read_status = (read_status_t) elink_8726_read_status,
10991         .link_reset = (link_reset_t) elink_8726_link_reset,
10992         .config_loopback = (config_loopback_t) elink_8726_config_loopback,
10993         .format_fw_ver = (format_fw_ver_t) elink_format_ver,
10994         .hw_reset = (hw_reset_t) NULL,
10995         .set_link_led = (set_link_led_t) NULL,
10996         .phy_specific_func = (phy_specific_func_t) NULL
10997 };
10998
10999 static const struct elink_phy phy_8727 = {
11000         .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X8727,
11001         .addr = 0xff,
11002         .def_md_devad = 0,
11003         .flags = (ELINK_FLAGS_FAN_FAILURE_DET_REQ | ELINK_FLAGS_TX_ERROR_CHECK),
11004         .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11005         .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11006         .mdio_ctrl = 0,
11007         .supported = (ELINK_SUPPORTED_10000baseT_Full |
11008                       ELINK_SUPPORTED_1000baseT_Full |
11009                       ELINK_SUPPORTED_FIBRE |
11010                       ELINK_SUPPORTED_Pause | ELINK_SUPPORTED_Asym_Pause),
11011         .media_type = ELINK_ETH_PHY_NOT_PRESENT,
11012         .ver_addr = 0,
11013         .req_flow_ctrl = 0,
11014         .req_line_speed = 0,
11015         .speed_cap_mask = 0,
11016         .req_duplex = 0,
11017         .rsrv = 0,
11018         .config_init = (config_init_t) elink_8727_config_init,
11019         .read_status = (read_status_t) elink_8727_read_status,
11020         .link_reset = (link_reset_t) elink_8727_link_reset,
11021         .config_loopback = (config_loopback_t) NULL,
11022         .format_fw_ver = (format_fw_ver_t) elink_format_ver,
11023         .hw_reset = (hw_reset_t) elink_8727_hw_reset,
11024         .set_link_led = (set_link_led_t) elink_8727_set_link_led,
11025         .phy_specific_func = (phy_specific_func_t) elink_8727_specific_func
11026 };
11027
11028 static const struct elink_phy phy_8481 = {
11029         .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X8481,
11030         .addr = 0xff,
11031         .def_md_devad = 0,
11032         .flags = ELINK_FLAGS_FAN_FAILURE_DET_REQ |
11033             ELINK_FLAGS_REARM_LATCH_SIGNAL,
11034         .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11035         .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11036         .mdio_ctrl = 0,
11037         .supported = (ELINK_SUPPORTED_10baseT_Half |
11038                       ELINK_SUPPORTED_10baseT_Full |
11039                       ELINK_SUPPORTED_100baseT_Half |
11040                       ELINK_SUPPORTED_100baseT_Full |
11041                       ELINK_SUPPORTED_1000baseT_Full |
11042                       ELINK_SUPPORTED_10000baseT_Full |
11043                       ELINK_SUPPORTED_TP |
11044                       ELINK_SUPPORTED_Autoneg |
11045                       ELINK_SUPPORTED_Pause | ELINK_SUPPORTED_Asym_Pause),
11046         .media_type = ELINK_ETH_PHY_BASE_T,
11047         .ver_addr = 0,
11048         .req_flow_ctrl = 0,
11049         .req_line_speed = 0,
11050         .speed_cap_mask = 0,
11051         .req_duplex = 0,
11052         .rsrv = 0,
11053         .config_init = (config_init_t) elink_8481_config_init,
11054         .read_status = (read_status_t) elink_848xx_read_status,
11055         .link_reset = (link_reset_t) elink_8481_link_reset,
11056         .config_loopback = (config_loopback_t) NULL,
11057         .format_fw_ver = (format_fw_ver_t) elink_848xx_format_ver,
11058         .hw_reset = (hw_reset_t) elink_8481_hw_reset,
11059         .set_link_led = (set_link_led_t) elink_848xx_set_link_led,
11060         .phy_specific_func = (phy_specific_func_t) NULL
11061 };
11062
11063 static const struct elink_phy phy_84823 = {
11064         .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X84823,
11065         .addr = 0xff,
11066         .def_md_devad = 0,
11067         .flags = (ELINK_FLAGS_FAN_FAILURE_DET_REQ |
11068                   ELINK_FLAGS_REARM_LATCH_SIGNAL | ELINK_FLAGS_TX_ERROR_CHECK),
11069         .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11070         .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11071         .mdio_ctrl = 0,
11072         .supported = (ELINK_SUPPORTED_10baseT_Half |
11073                       ELINK_SUPPORTED_10baseT_Full |
11074                       ELINK_SUPPORTED_100baseT_Half |
11075                       ELINK_SUPPORTED_100baseT_Full |
11076                       ELINK_SUPPORTED_1000baseT_Full |
11077                       ELINK_SUPPORTED_10000baseT_Full |
11078                       ELINK_SUPPORTED_TP |
11079                       ELINK_SUPPORTED_Autoneg |
11080                       ELINK_SUPPORTED_Pause | ELINK_SUPPORTED_Asym_Pause),
11081         .media_type = ELINK_ETH_PHY_BASE_T,
11082         .ver_addr = 0,
11083         .req_flow_ctrl = 0,
11084         .req_line_speed = 0,
11085         .speed_cap_mask = 0,
11086         .req_duplex = 0,
11087         .rsrv = 0,
11088         .config_init = (config_init_t) elink_848x3_config_init,
11089         .read_status = (read_status_t) elink_848xx_read_status,
11090         .link_reset = (link_reset_t) elink_848x3_link_reset,
11091         .config_loopback = (config_loopback_t) NULL,
11092         .format_fw_ver = (format_fw_ver_t) elink_848xx_format_ver,
11093         .hw_reset = (hw_reset_t) NULL,
11094         .set_link_led = (set_link_led_t) elink_848xx_set_link_led,
11095         .phy_specific_func = (phy_specific_func_t) elink_848xx_specific_func
11096 };
11097
11098 static const struct elink_phy phy_84833 = {
11099         .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X84833,
11100         .addr = 0xff,
11101         .def_md_devad = 0,
11102         .flags = (ELINK_FLAGS_FAN_FAILURE_DET_REQ |
11103                   ELINK_FLAGS_REARM_LATCH_SIGNAL |
11104                   ELINK_FLAGS_TX_ERROR_CHECK | ELINK_FLAGS_TEMPERATURE),
11105         .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11106         .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11107         .mdio_ctrl = 0,
11108         .supported = (ELINK_SUPPORTED_100baseT_Half |
11109                       ELINK_SUPPORTED_100baseT_Full |
11110                       ELINK_SUPPORTED_1000baseT_Full |
11111                       ELINK_SUPPORTED_10000baseT_Full |
11112                       ELINK_SUPPORTED_TP |
11113                       ELINK_SUPPORTED_Autoneg |
11114                       ELINK_SUPPORTED_Pause | ELINK_SUPPORTED_Asym_Pause),
11115         .media_type = ELINK_ETH_PHY_BASE_T,
11116         .ver_addr = 0,
11117         .req_flow_ctrl = 0,
11118         .req_line_speed = 0,
11119         .speed_cap_mask = 0,
11120         .req_duplex = 0,
11121         .rsrv = 0,
11122         .config_init = (config_init_t) elink_848x3_config_init,
11123         .read_status = (read_status_t) elink_848xx_read_status,
11124         .link_reset = (link_reset_t) elink_848x3_link_reset,
11125         .config_loopback = (config_loopback_t) NULL,
11126         .format_fw_ver = (format_fw_ver_t) elink_848xx_format_ver,
11127         .hw_reset = (hw_reset_t) elink_84833_hw_reset_phy,
11128         .set_link_led = (set_link_led_t) elink_848xx_set_link_led,
11129         .phy_specific_func = (phy_specific_func_t) elink_848xx_specific_func
11130 };
11131
11132 static const struct elink_phy phy_84834 = {
11133         .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X84834,
11134         .addr = 0xff,
11135         .def_md_devad = 0,
11136         .flags = ELINK_FLAGS_FAN_FAILURE_DET_REQ |
11137             ELINK_FLAGS_REARM_LATCH_SIGNAL,
11138         .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11139         .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11140         .mdio_ctrl = 0,
11141         .supported = (ELINK_SUPPORTED_100baseT_Half |
11142                       ELINK_SUPPORTED_100baseT_Full |
11143                       ELINK_SUPPORTED_1000baseT_Full |
11144                       ELINK_SUPPORTED_10000baseT_Full |
11145                       ELINK_SUPPORTED_TP |
11146                       ELINK_SUPPORTED_Autoneg |
11147                       ELINK_SUPPORTED_Pause | ELINK_SUPPORTED_Asym_Pause),
11148         .media_type = ELINK_ETH_PHY_BASE_T,
11149         .ver_addr = 0,
11150         .req_flow_ctrl = 0,
11151         .req_line_speed = 0,
11152         .speed_cap_mask = 0,
11153         .req_duplex = 0,
11154         .rsrv = 0,
11155         .config_init = (config_init_t) elink_848x3_config_init,
11156         .read_status = (read_status_t) elink_848xx_read_status,
11157         .link_reset = (link_reset_t) elink_848x3_link_reset,
11158         .config_loopback = (config_loopback_t) NULL,
11159         .format_fw_ver = (format_fw_ver_t) elink_848xx_format_ver,
11160         .hw_reset = (hw_reset_t) elink_84833_hw_reset_phy,
11161         .set_link_led = (set_link_led_t) elink_848xx_set_link_led,
11162         .phy_specific_func = (phy_specific_func_t) elink_848xx_specific_func
11163 };
11164
11165 static const struct elink_phy phy_54618se = {
11166         .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X54618SE,
11167         .addr = 0xff,
11168         .def_md_devad = 0,
11169         .flags = ELINK_FLAGS_INIT_XGXS_FIRST,
11170         .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11171         .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
11172         .mdio_ctrl = 0,
11173         .supported = (ELINK_SUPPORTED_10baseT_Half |
11174                       ELINK_SUPPORTED_10baseT_Full |
11175                       ELINK_SUPPORTED_100baseT_Half |
11176                       ELINK_SUPPORTED_100baseT_Full |
11177                       ELINK_SUPPORTED_1000baseT_Full |
11178                       ELINK_SUPPORTED_TP |
11179                       ELINK_SUPPORTED_Autoneg |
11180                       ELINK_SUPPORTED_Pause | ELINK_SUPPORTED_Asym_Pause),
11181         .media_type = ELINK_ETH_PHY_BASE_T,
11182         .ver_addr = 0,
11183         .req_flow_ctrl = 0,
11184         .req_line_speed = 0,
11185         .speed_cap_mask = 0,
11186         /* req_duplex = */ 0,
11187         /* rsrv = */ 0,
11188         .config_init = (config_init_t) elink_54618se_config_init,
11189         .read_status = (read_status_t) elink_54618se_read_status,
11190         .link_reset = (link_reset_t) elink_54618se_link_reset,
11191         .config_loopback = (config_loopback_t) elink_54618se_config_loopback,
11192         .format_fw_ver = (format_fw_ver_t) NULL,
11193         .hw_reset = (hw_reset_t) NULL,
11194         .set_link_led = (set_link_led_t) elink_5461x_set_link_led,
11195         .phy_specific_func = (phy_specific_func_t) elink_54618se_specific_func
11196 };
11197
11198 /*****************************************************************/
11199 /*                                                               */
11200 /* Populate the phy according. Main function: elink_populate_phy   */
11201 /*                                                               */
11202 /*****************************************************************/
11203
11204 static void elink_populate_preemphasis(struct bnx2x_softc *sc,
11205                                        uint32_t shmem_base,
11206                                        struct elink_phy *phy, uint8_t port,
11207                                        uint8_t phy_index)
11208 {
11209         /* Get the 4 lanes xgxs config rx and tx */
11210         uint32_t rx = 0, tx = 0, i;
11211         for (i = 0; i < 2; i++) {
11212                 /* INT_PHY and ELINK_EXT_PHY1 share the same value location in
11213                  * the shmem. When num_phys is greater than 1, than this value
11214                  * applies only to ELINK_EXT_PHY1
11215                  */
11216                 if (phy_index == ELINK_INT_PHY || phy_index == ELINK_EXT_PHY1) {
11217                         rx = REG_RD(sc, shmem_base +
11218                                     offsetof(struct shmem_region,
11219                                              dev_info.port_hw_config[port].
11220                                              xgxs_config_rx[i << 1]));
11221
11222                         tx = REG_RD(sc, shmem_base +
11223                                     offsetof(struct shmem_region,
11224                                              dev_info.port_hw_config[port].
11225                                              xgxs_config_tx[i << 1]));
11226                 } else {
11227                         rx = REG_RD(sc, shmem_base +
11228                                     offsetof(struct shmem_region,
11229                                              dev_info.port_hw_config[port].
11230                                              xgxs_config2_rx[i << 1]));
11231
11232                         tx = REG_RD(sc, shmem_base +
11233                                     offsetof(struct shmem_region,
11234                                              dev_info.port_hw_config[port].
11235                                              xgxs_config2_rx[i << 1]));
11236                 }
11237
11238                 phy->rx_preemphasis[i << 1] = ((rx >> 16) & 0xffff);
11239                 phy->rx_preemphasis[(i << 1) + 1] = (rx & 0xffff);
11240
11241                 phy->tx_preemphasis[i << 1] = ((tx >> 16) & 0xffff);
11242                 phy->tx_preemphasis[(i << 1) + 1] = (tx & 0xffff);
11243         }
11244 }
11245
11246 static uint32_t elink_get_ext_phy_config(struct bnx2x_softc *sc,
11247                                          uint32_t shmem_base, uint8_t phy_index,
11248                                          uint8_t port)
11249 {
11250         uint32_t ext_phy_config = 0;
11251         switch (phy_index) {
11252         case ELINK_EXT_PHY1:
11253                 ext_phy_config = REG_RD(sc, shmem_base +
11254                                         offsetof(struct shmem_region,
11255                                                  dev_info.port_hw_config[port].
11256                                                  external_phy_config));
11257                 break;
11258         case ELINK_EXT_PHY2:
11259                 ext_phy_config = REG_RD(sc, shmem_base +
11260                                         offsetof(struct shmem_region,
11261                                                  dev_info.port_hw_config[port].
11262                                                  external_phy_config2));
11263                 break;
11264         default:
11265                 PMD_DRV_LOG(DEBUG, "Invalid phy_index %d", phy_index);
11266                 return ELINK_STATUS_ERROR;
11267         }
11268
11269         return ext_phy_config;
11270 }
11271
11272 static elink_status_t elink_populate_int_phy(struct bnx2x_softc *sc,
11273                                              uint32_t shmem_base, uint8_t port,
11274                                              struct elink_phy *phy)
11275 {
11276         uint32_t phy_addr;
11277         __rte_unused uint32_t chip_id;
11278         uint32_t switch_cfg = (REG_RD(sc, shmem_base +
11279                                       offsetof(struct shmem_region,
11280                                                dev_info.
11281                                                port_feature_config[port].
11282                                                link_config)) &
11283                                PORT_FEATURE_CONNECTED_SWITCH_MASK);
11284         chip_id =
11285             (REG_RD(sc, MISC_REG_CHIP_NUM) << 16) |
11286             ((REG_RD(sc, MISC_REG_CHIP_REV) & 0xf) << 12);
11287
11288         PMD_DRV_LOG(DEBUG, ":chip_id = 0x%x", chip_id);
11289         if (USES_WARPCORE(sc)) {
11290                 uint32_t serdes_net_if;
11291                 phy_addr = REG_RD(sc, MISC_REG_WC0_CTRL_PHY_ADDR);
11292                 *phy = phy_warpcore;
11293                 if (REG_RD(sc, MISC_REG_PORT4MODE_EN_OVWR) == 0x3)
11294                         phy->flags |= ELINK_FLAGS_4_PORT_MODE;
11295                 else
11296                         phy->flags &= ~ELINK_FLAGS_4_PORT_MODE;
11297                 /* Check Dual mode */
11298                 serdes_net_if = (REG_RD(sc, shmem_base +
11299                                         offsetof(struct shmem_region,
11300                                                  dev_info.port_hw_config[port].
11301                                                  default_cfg)) &
11302                                  PORT_HW_CFG_NET_SERDES_IF_MASK);
11303                 /* Set the appropriate supported and flags indications per
11304                  * interface type of the chip
11305                  */
11306                 switch (serdes_net_if) {
11307                 case PORT_HW_CFG_NET_SERDES_IF_SGMII:
11308                         phy->supported &= (ELINK_SUPPORTED_10baseT_Half |
11309                                            ELINK_SUPPORTED_10baseT_Full |
11310                                            ELINK_SUPPORTED_100baseT_Half |
11311                                            ELINK_SUPPORTED_100baseT_Full |
11312                                            ELINK_SUPPORTED_1000baseT_Full |
11313                                            ELINK_SUPPORTED_FIBRE |
11314                                            ELINK_SUPPORTED_Autoneg |
11315                                            ELINK_SUPPORTED_Pause |
11316                                            ELINK_SUPPORTED_Asym_Pause);
11317                         phy->media_type = ELINK_ETH_PHY_BASE_T;
11318                         break;
11319                 case PORT_HW_CFG_NET_SERDES_IF_XFI:
11320                         phy->supported &= (ELINK_SUPPORTED_1000baseT_Full |
11321                                            ELINK_SUPPORTED_10000baseT_Full |
11322                                            ELINK_SUPPORTED_FIBRE |
11323                                            ELINK_SUPPORTED_Pause |
11324                                            ELINK_SUPPORTED_Asym_Pause);
11325                         phy->media_type = ELINK_ETH_PHY_XFP_FIBER;
11326                         break;
11327                 case PORT_HW_CFG_NET_SERDES_IF_SFI:
11328                         phy->supported &= (ELINK_SUPPORTED_1000baseT_Full |
11329                                            ELINK_SUPPORTED_10000baseT_Full |
11330                                            ELINK_SUPPORTED_FIBRE |
11331                                            ELINK_SUPPORTED_Pause |
11332                                            ELINK_SUPPORTED_Asym_Pause);
11333                         phy->media_type = ELINK_ETH_PHY_SFPP_10G_FIBER;
11334                         break;
11335                 case PORT_HW_CFG_NET_SERDES_IF_KR:
11336                         phy->media_type = ELINK_ETH_PHY_KR;
11337                         phy->supported &= (ELINK_SUPPORTED_1000baseT_Full |
11338                                            ELINK_SUPPORTED_10000baseT_Full |
11339                                            ELINK_SUPPORTED_FIBRE |
11340                                            ELINK_SUPPORTED_Autoneg |
11341                                            ELINK_SUPPORTED_Pause |
11342                                            ELINK_SUPPORTED_Asym_Pause);
11343                         break;
11344                 case PORT_HW_CFG_NET_SERDES_IF_DXGXS:
11345                         phy->media_type = ELINK_ETH_PHY_KR;
11346                         phy->flags |= ELINK_FLAGS_WC_DUAL_MODE;
11347                         phy->supported &= (ELINK_SUPPORTED_20000baseMLD2_Full |
11348                                            ELINK_SUPPORTED_FIBRE |
11349                                            ELINK_SUPPORTED_Pause |
11350                                            ELINK_SUPPORTED_Asym_Pause);
11351                         break;
11352                 case PORT_HW_CFG_NET_SERDES_IF_KR2:
11353                         phy->media_type = ELINK_ETH_PHY_KR;
11354                         phy->flags |= ELINK_FLAGS_WC_DUAL_MODE;
11355                         phy->supported &= (ELINK_SUPPORTED_20000baseKR2_Full |
11356                                            ELINK_SUPPORTED_10000baseT_Full |
11357                                            ELINK_SUPPORTED_1000baseT_Full |
11358                                            ELINK_SUPPORTED_Autoneg |
11359                                            ELINK_SUPPORTED_FIBRE |
11360                                            ELINK_SUPPORTED_Pause |
11361                                            ELINK_SUPPORTED_Asym_Pause);
11362                         phy->flags &= ~ELINK_FLAGS_TX_ERROR_CHECK;
11363                         break;
11364                 default:
11365                         PMD_DRV_LOG(DEBUG, "Unknown WC interface type 0x%x",
11366                                     serdes_net_if);
11367                         break;
11368                 }
11369
11370                 /* Enable MDC/MDIO work-around for E3 A0 since free running MDC
11371                  * was not set as expected. For B0, ECO will be enabled so there
11372                  * won't be an issue there
11373                  */
11374                 if (CHIP_REV(sc) == CHIP_REV_Ax)
11375                         phy->flags |= ELINK_FLAGS_MDC_MDIO_WA;
11376                 else
11377                         phy->flags |= ELINK_FLAGS_MDC_MDIO_WA_B0;
11378         } else {
11379                 switch (switch_cfg) {
11380                 case ELINK_SWITCH_CFG_1G:
11381                         phy_addr = REG_RD(sc,
11382                                           NIG_REG_SERDES0_CTRL_PHY_ADDR +
11383                                           port * 0x10);
11384                         *phy = phy_serdes;
11385                         break;
11386                 case ELINK_SWITCH_CFG_10G:
11387                         phy_addr = REG_RD(sc,
11388                                           NIG_REG_XGXS0_CTRL_PHY_ADDR +
11389                                           port * 0x18);
11390                         *phy = phy_xgxs;
11391                         break;
11392                 default:
11393                         PMD_DRV_LOG(DEBUG, "Invalid switch_cfg");
11394                         return ELINK_STATUS_ERROR;
11395                 }
11396         }
11397         phy->addr = (uint8_t) phy_addr;
11398         phy->mdio_ctrl = elink_get_emac_base(sc,
11399                                              SHARED_HW_CFG_MDC_MDIO_ACCESS1_BOTH,
11400                                              port);
11401         if (CHIP_IS_E2(sc))
11402                 phy->def_md_devad = ELINK_E2_DEFAULT_PHY_DEV_ADDR;
11403         else
11404                 phy->def_md_devad = ELINK_DEFAULT_PHY_DEV_ADDR;
11405
11406         PMD_DRV_LOG(DEBUG, "Internal phy port=%d, addr=0x%x, mdio_ctl=0x%x",
11407                     port, phy->addr, phy->mdio_ctrl);
11408
11409         elink_populate_preemphasis(sc, shmem_base, phy, port, ELINK_INT_PHY);
11410         return ELINK_STATUS_OK;
11411 }
11412
11413 static elink_status_t elink_populate_ext_phy(struct bnx2x_softc *sc,
11414                                              uint8_t phy_index,
11415                                              uint32_t shmem_base,
11416                                              uint32_t shmem2_base,
11417                                              uint8_t port,
11418                                              struct elink_phy *phy)
11419 {
11420         uint32_t ext_phy_config, phy_type, config2;
11421         uint32_t mdc_mdio_access = SHARED_HW_CFG_MDC_MDIO_ACCESS1_BOTH;
11422         ext_phy_config = elink_get_ext_phy_config(sc, shmem_base,
11423                                                   phy_index, port);
11424         phy_type = ELINK_XGXS_EXT_PHY_TYPE(ext_phy_config);
11425         /* Select the phy type */
11426         switch (phy_type) {
11427         case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X8073:
11428                 mdc_mdio_access = SHARED_HW_CFG_MDC_MDIO_ACCESS1_SWAPPED;
11429                 *phy = phy_8073;
11430                 break;
11431         case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X8705:
11432                 *phy = phy_8705;
11433                 break;
11434         case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X8706:
11435                 *phy = phy_8706;
11436                 break;
11437         case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X8726:
11438                 mdc_mdio_access = SHARED_HW_CFG_MDC_MDIO_ACCESS1_EMAC1;
11439                 *phy = phy_8726;
11440                 break;
11441         case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X8727_NOC:
11442                 /* BNX2X8727_NOC => BNX2X8727 no over current */
11443                 mdc_mdio_access = SHARED_HW_CFG_MDC_MDIO_ACCESS1_EMAC1;
11444                 *phy = phy_8727;
11445                 phy->flags |= ELINK_FLAGS_NOC;
11446                 break;
11447         case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X8722:
11448         case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X8727:
11449                 mdc_mdio_access = SHARED_HW_CFG_MDC_MDIO_ACCESS1_EMAC1;
11450                 *phy = phy_8727;
11451                 break;
11452         case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X8481:
11453                 *phy = phy_8481;
11454                 break;
11455         case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X84823:
11456                 *phy = phy_84823;
11457                 break;
11458         case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X84833:
11459                 *phy = phy_84833;
11460                 break;
11461         case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X84834:
11462                 *phy = phy_84834;
11463                 break;
11464         case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X54616:
11465         case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X54618SE:
11466                 *phy = phy_54618se;
11467                 if (phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X54618SE)
11468                         phy->flags |= ELINK_FLAGS_EEE;
11469                 break;
11470         case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101:
11471                 *phy = phy_7101;
11472                 break;
11473         case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE:
11474                 *phy = phy_null;
11475                 return ELINK_STATUS_ERROR;
11476         default:
11477                 *phy = phy_null;
11478                 /* In case external PHY wasn't found */
11479                 if ((phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT) &&
11480                     (phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
11481                         return ELINK_STATUS_ERROR;
11482                 return ELINK_STATUS_OK;
11483         }
11484
11485         phy->addr = ELINK_XGXS_EXT_PHY_ADDR(ext_phy_config);
11486         elink_populate_preemphasis(sc, shmem_base, phy, port, phy_index);
11487
11488         /* The shmem address of the phy version is located on different
11489          * structures. In case this structure is too old, do not set
11490          * the address
11491          */
11492         config2 = REG_RD(sc, shmem_base + offsetof(struct shmem_region,
11493                                                    dev_info.shared_hw_config.
11494                                                    config2));
11495         if (phy_index == ELINK_EXT_PHY1) {
11496                 phy->ver_addr = shmem_base + offsetof(struct shmem_region,
11497                                                       port_mb[port].
11498                                                       ext_phy_fw_version);
11499
11500                 /* Check specific mdc mdio settings */
11501                 if (config2 & SHARED_HW_CFG_MDC_MDIO_ACCESS1_MASK)
11502                         mdc_mdio_access = config2 &
11503                             SHARED_HW_CFG_MDC_MDIO_ACCESS1_MASK;
11504         } else {
11505                 uint32_t size = REG_RD(sc, shmem2_base);
11506
11507                 if (size > offsetof(struct shmem2_region, ext_phy_fw_version2)) {
11508                         phy->ver_addr = shmem2_base +
11509                             offsetof(struct shmem2_region,
11510                                      ext_phy_fw_version2[port]);
11511                 }
11512                 /* Check specific mdc mdio settings */
11513                 if (config2 & SHARED_HW_CFG_MDC_MDIO_ACCESS2_MASK)
11514                         mdc_mdio_access = (config2 &
11515                                            SHARED_HW_CFG_MDC_MDIO_ACCESS2_MASK)
11516                             >> (SHARED_HW_CFG_MDC_MDIO_ACCESS2_SHIFT -
11517                                 SHARED_HW_CFG_MDC_MDIO_ACCESS1_SHIFT);
11518         }
11519         phy->mdio_ctrl = elink_get_emac_base(sc, mdc_mdio_access, port);
11520
11521         if (((phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X84833) ||
11522              (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X84834)) &&
11523             (phy->ver_addr)) {
11524                 /* Remove 100Mb link supported for BNX2X84833/4 when phy fw
11525                  * version lower than or equal to 1.39
11526                  */
11527                 uint32_t raw_ver = REG_RD(sc, phy->ver_addr);
11528                 if (((raw_ver & 0x7F) <= 39) && (((raw_ver & 0xF80) >> 7) <= 1))
11529                         phy->supported &= ~(ELINK_SUPPORTED_100baseT_Half |
11530                                             ELINK_SUPPORTED_100baseT_Full);
11531         }
11532
11533         PMD_DRV_LOG(DEBUG, "phy_type 0x%x port %d found in index %d",
11534                     phy_type, port, phy_index);
11535         PMD_DRV_LOG(DEBUG, "             addr=0x%x, mdio_ctl=0x%x",
11536                     phy->addr, phy->mdio_ctrl);
11537         return ELINK_STATUS_OK;
11538 }
11539
11540 static elink_status_t elink_populate_phy(struct bnx2x_softc *sc,
11541                                          uint8_t phy_index, uint32_t shmem_base,
11542                                          uint32_t shmem2_base, uint8_t port,
11543                                          struct elink_phy *phy)
11544 {
11545         elink_status_t status = ELINK_STATUS_OK;
11546         phy->type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN;
11547         if (phy_index == ELINK_INT_PHY)
11548                 return elink_populate_int_phy(sc, shmem_base, port, phy);
11549         status = elink_populate_ext_phy(sc, phy_index, shmem_base, shmem2_base,
11550                                         port, phy);
11551         return status;
11552 }
11553
11554 static void elink_phy_def_cfg(struct elink_params *params,
11555                               struct elink_phy *phy, uint8_t phy_index)
11556 {
11557         struct bnx2x_softc *sc = params->sc;
11558         uint32_t link_config;
11559         /* Populate the default phy configuration for MF mode */
11560         if (phy_index == ELINK_EXT_PHY2) {
11561                 link_config = REG_RD(sc, params->shmem_base +
11562                                      offsetof(struct shmem_region,
11563                                               dev_info.port_feature_config
11564                                               [params->port].link_config2));
11565                 phy->speed_cap_mask =
11566                     REG_RD(sc,
11567                            params->shmem_base + offsetof(struct shmem_region,
11568                                                          dev_info.port_hw_config
11569                                                          [params->port].
11570                                                          speed_capability_mask2));
11571         } else {
11572                 link_config = REG_RD(sc, params->shmem_base +
11573                                      offsetof(struct shmem_region,
11574                                               dev_info.port_feature_config
11575                                               [params->port].link_config));
11576                 phy->speed_cap_mask =
11577                     REG_RD(sc,
11578                            params->shmem_base + offsetof(struct shmem_region,
11579                                                          dev_info.port_hw_config
11580                                                          [params->port].
11581                                                          speed_capability_mask));
11582         }
11583
11584         PMD_DRV_LOG(DEBUG,
11585                     "Default config phy idx %x cfg 0x%x speed_cap_mask 0x%x",
11586                     phy_index, link_config, phy->speed_cap_mask);
11587
11588         phy->req_duplex = DUPLEX_FULL;
11589         switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
11590         case PORT_FEATURE_LINK_SPEED_10M_HALF:
11591                 phy->req_duplex = DUPLEX_HALF;
11592         case PORT_FEATURE_LINK_SPEED_10M_FULL:
11593                 phy->req_line_speed = ELINK_SPEED_10;
11594                 break;
11595         case PORT_FEATURE_LINK_SPEED_100M_HALF:
11596                 phy->req_duplex = DUPLEX_HALF;
11597         case PORT_FEATURE_LINK_SPEED_100M_FULL:
11598                 phy->req_line_speed = ELINK_SPEED_100;
11599                 break;
11600         case PORT_FEATURE_LINK_SPEED_1G:
11601                 phy->req_line_speed = ELINK_SPEED_1000;
11602                 break;
11603         case PORT_FEATURE_LINK_SPEED_2_5G:
11604                 phy->req_line_speed = ELINK_SPEED_2500;
11605                 break;
11606         case PORT_FEATURE_LINK_SPEED_10G_CX4:
11607                 phy->req_line_speed = ELINK_SPEED_10000;
11608                 break;
11609         default:
11610                 phy->req_line_speed = ELINK_SPEED_AUTO_NEG;
11611                 break;
11612         }
11613
11614         switch (link_config & PORT_FEATURE_FLOW_CONTROL_MASK) {
11615         case PORT_FEATURE_FLOW_CONTROL_AUTO:
11616                 phy->req_flow_ctrl = ELINK_FLOW_CTRL_AUTO;
11617                 break;
11618         case PORT_FEATURE_FLOW_CONTROL_TX:
11619                 phy->req_flow_ctrl = ELINK_FLOW_CTRL_TX;
11620                 break;
11621         case PORT_FEATURE_FLOW_CONTROL_RX:
11622                 phy->req_flow_ctrl = ELINK_FLOW_CTRL_RX;
11623                 break;
11624         case PORT_FEATURE_FLOW_CONTROL_BOTH:
11625                 phy->req_flow_ctrl = ELINK_FLOW_CTRL_BOTH;
11626                 break;
11627         default:
11628                 phy->req_flow_ctrl = ELINK_FLOW_CTRL_NONE;
11629                 break;
11630         }
11631 }
11632
11633 uint32_t elink_phy_selection(struct elink_params *params)
11634 {
11635         uint32_t phy_config_swapped, prio_cfg;
11636         uint32_t return_cfg = PORT_HW_CFG_PHY_SELECTION_HARDWARE_DEFAULT;
11637
11638         phy_config_swapped = params->multi_phy_config &
11639             PORT_HW_CFG_PHY_SWAPPED_ENABLED;
11640
11641         prio_cfg = params->multi_phy_config & PORT_HW_CFG_PHY_SELECTION_MASK;
11642
11643         if (phy_config_swapped) {
11644                 switch (prio_cfg) {
11645                 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY_PRIORITY:
11646                         return_cfg =
11647                             PORT_HW_CFG_PHY_SELECTION_SECOND_PHY_PRIORITY;
11648                         break;
11649                 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY_PRIORITY:
11650                         return_cfg =
11651                             PORT_HW_CFG_PHY_SELECTION_FIRST_PHY_PRIORITY;
11652                         break;
11653                 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY:
11654                         return_cfg = PORT_HW_CFG_PHY_SELECTION_FIRST_PHY;
11655                         break;
11656                 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY:
11657                         return_cfg = PORT_HW_CFG_PHY_SELECTION_SECOND_PHY;
11658                         break;
11659                 }
11660         } else
11661                 return_cfg = prio_cfg;
11662
11663         return return_cfg;
11664 }
11665
11666 elink_status_t elink_phy_probe(struct elink_params * params)
11667 {
11668         uint8_t phy_index, actual_phy_idx;
11669         uint32_t phy_config_swapped, sync_offset, media_types;
11670         struct bnx2x_softc *sc = params->sc;
11671         struct elink_phy *phy;
11672         params->num_phys = 0;
11673         PMD_DRV_LOG(DEBUG, "Begin phy probe");
11674 #ifdef ELINK_INCLUDE_EMUL
11675         if (CHIP_REV_IS_EMUL(sc))
11676                 return ELINK_STATUS_OK;
11677 #endif
11678         phy_config_swapped = params->multi_phy_config &
11679             PORT_HW_CFG_PHY_SWAPPED_ENABLED;
11680
11681         for (phy_index = ELINK_INT_PHY; phy_index < ELINK_MAX_PHYS; phy_index++) {
11682                 actual_phy_idx = phy_index;
11683                 if (phy_config_swapped) {
11684                         if (phy_index == ELINK_EXT_PHY1)
11685                                 actual_phy_idx = ELINK_EXT_PHY2;
11686                         else if (phy_index == ELINK_EXT_PHY2)
11687                                 actual_phy_idx = ELINK_EXT_PHY1;
11688                 }
11689                 PMD_DRV_LOG(DEBUG, "phy_config_swapped %x, phy_index %x,"
11690                             " actual_phy_idx %x", phy_config_swapped,
11691                             phy_index, actual_phy_idx);
11692                 phy = &params->phy[actual_phy_idx];
11693                 if (elink_populate_phy(sc, phy_index, params->shmem_base,
11694                                        params->shmem2_base, params->port,
11695                                        phy) != ELINK_STATUS_OK) {
11696                         params->num_phys = 0;
11697                         PMD_DRV_LOG(DEBUG, "phy probe failed in phy index %d",
11698                                     phy_index);
11699                         for (phy_index = ELINK_INT_PHY;
11700                              phy_index < ELINK_MAX_PHYS; phy_index++)
11701                                 *phy = phy_null;
11702                         return ELINK_STATUS_ERROR;
11703                 }
11704                 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN)
11705                         break;
11706
11707                 if (params->feature_config_flags &
11708                     ELINK_FEATURE_CONFIG_DISABLE_REMOTE_FAULT_DET)
11709                         phy->flags &= ~ELINK_FLAGS_TX_ERROR_CHECK;
11710
11711                 if (!(params->feature_config_flags &
11712                       ELINK_FEATURE_CONFIG_MT_SUPPORT))
11713                         phy->flags |= ELINK_FLAGS_MDC_MDIO_WA_G;
11714
11715                 sync_offset = params->shmem_base +
11716                     offsetof(struct shmem_region,
11717                              dev_info.port_hw_config[params->port].media_type);
11718                 media_types = REG_RD(sc, sync_offset);
11719
11720                 /* Update media type for non-PMF sync only for the first time
11721                  * In case the media type changes afterwards, it will be updated
11722                  * using the update_status function
11723                  */
11724                 if ((media_types & (PORT_HW_CFG_MEDIA_TYPE_PHY0_MASK <<
11725                                     (PORT_HW_CFG_MEDIA_TYPE_PHY1_SHIFT *
11726                                      actual_phy_idx))) == 0) {
11727                         media_types |= ((phy->media_type &
11728                                          PORT_HW_CFG_MEDIA_TYPE_PHY0_MASK) <<
11729                                         (PORT_HW_CFG_MEDIA_TYPE_PHY1_SHIFT *
11730                                          actual_phy_idx));
11731                 }
11732                 REG_WR(sc, sync_offset, media_types);
11733
11734                 elink_phy_def_cfg(params, phy, phy_index);
11735                 params->num_phys++;
11736         }
11737
11738         PMD_DRV_LOG(DEBUG, "End phy probe. #phys found %x", params->num_phys);
11739         return ELINK_STATUS_OK;
11740 }
11741
11742 #ifdef ELINK_INCLUDE_EMUL
11743 static elink_status_t elink_init_e3_emul_mac(struct elink_params *params,
11744                                              struct elink_vars *vars)
11745 {
11746         struct bnx2x_softc *sc = params->sc;
11747         vars->line_speed = params->req_line_speed[0];
11748         /* In case link speed is auto, set speed the highest as possible */
11749         if (params->req_line_speed[0] == ELINK_SPEED_AUTO_NEG) {
11750                 if (params->feature_config_flags &
11751                     ELINK_FEATURE_CONFIG_EMUL_DISABLE_XMAC)
11752                         vars->line_speed = ELINK_SPEED_2500;
11753                 else if (elink_is_4_port_mode(sc))
11754                         vars->line_speed = ELINK_SPEED_10000;
11755                 else
11756                         vars->line_speed = ELINK_SPEED_20000;
11757         }
11758         if (vars->line_speed < ELINK_SPEED_10000) {
11759                 if ((params->feature_config_flags &
11760                      ELINK_FEATURE_CONFIG_EMUL_DISABLE_UMAC)) {
11761                         PMD_DRV_LOG(DEBUG, "Invalid line speed %d while UMAC is"
11762                                     " disabled!", params->req_line_speed[0]);
11763                         return ELINK_STATUS_ERROR;
11764                 }
11765                 switch (vars->line_speed) {
11766                 case ELINK_SPEED_10:
11767                         vars->link_status = ELINK_LINK_10TFD;
11768                         break;
11769                 case ELINK_SPEED_100:
11770                         vars->link_status = ELINK_LINK_100TXFD;
11771                         break;
11772                 case ELINK_SPEED_1000:
11773                         vars->link_status = ELINK_LINK_1000TFD;
11774                         break;
11775                 case ELINK_SPEED_2500:
11776                         vars->link_status = ELINK_LINK_2500TFD;
11777                         break;
11778                 default:
11779                         PMD_DRV_LOG(DEBUG, "Invalid line speed %d for UMAC",
11780                                     vars->line_speed);
11781                         return ELINK_STATUS_ERROR;
11782                 }
11783                 vars->link_status |= LINK_STATUS_LINK_UP;
11784
11785                 if (params->loopback_mode == ELINK_LOOPBACK_UMAC)
11786                         elink_umac_enable(params, vars, 1);
11787                 else
11788                         elink_umac_enable(params, vars, 0);
11789         } else {
11790                 /* Link speed >= 10000 requires XMAC enabled */
11791                 if (params->feature_config_flags &
11792                     ELINK_FEATURE_CONFIG_EMUL_DISABLE_XMAC) {
11793                         PMD_DRV_LOG(DEBUG, "Invalid line speed %d while XMAC is"
11794                                     " disabled!", params->req_line_speed[0]);
11795                         return ELINK_STATUS_ERROR;
11796                 }
11797                 /* Check link speed */
11798                 switch (vars->line_speed) {
11799                 case ELINK_SPEED_10000:
11800                         vars->link_status = ELINK_LINK_10GTFD;
11801                         break;
11802                 case ELINK_SPEED_20000:
11803                         vars->link_status = ELINK_LINK_20GTFD;
11804                         break;
11805                 default:
11806                         PMD_DRV_LOG(DEBUG, "Invalid line speed %d for XMAC",
11807                                     vars->line_speed);
11808                         return ELINK_STATUS_ERROR;
11809                 }
11810                 vars->link_status |= LINK_STATUS_LINK_UP;
11811                 if (params->loopback_mode == ELINK_LOOPBACK_XMAC)
11812                         elink_xmac_enable(params, vars, 1);
11813                 else
11814                         elink_xmac_enable(params, vars, 0);
11815         }
11816         return ELINK_STATUS_OK;
11817 }
11818
11819 static elink_status_t elink_init_emul(struct elink_params *params,
11820                                       struct elink_vars *vars)
11821 {
11822         struct bnx2x_softc *sc = params->sc;
11823         if (CHIP_IS_E3(sc)) {
11824                 if (elink_init_e3_emul_mac(params, vars) != ELINK_STATUS_OK)
11825                         return ELINK_STATUS_ERROR;
11826         } else {
11827                 if (params->feature_config_flags &
11828                     ELINK_FEATURE_CONFIG_EMUL_DISABLE_BMAC) {
11829                         vars->line_speed = ELINK_SPEED_1000;
11830                         vars->link_status = (LINK_STATUS_LINK_UP |
11831                                              ELINK_LINK_1000XFD);
11832                         if (params->loopback_mode == ELINK_LOOPBACK_EMAC)
11833                                 elink_emac_enable(params, vars, 1);
11834                         else
11835                                 elink_emac_enable(params, vars, 0);
11836                 } else {
11837                         vars->line_speed = ELINK_SPEED_10000;
11838                         vars->link_status = (LINK_STATUS_LINK_UP |
11839                                              ELINK_LINK_10GTFD);
11840                         if (params->loopback_mode == ELINK_LOOPBACK_BMAC)
11841                                 elink_bmac_enable(params, vars, 1, 1);
11842                         else
11843                                 elink_bmac_enable(params, vars, 0, 1);
11844                 }
11845         }
11846         vars->link_up = 1;
11847         vars->duplex = DUPLEX_FULL;
11848         vars->flow_ctrl = ELINK_FLOW_CTRL_NONE;
11849
11850         if (CHIP_IS_E1x(sc))
11851                 elink_pbf_update(params, vars->flow_ctrl, vars->line_speed);
11852         /* Disable drain */
11853         REG_WR(sc, NIG_REG_EGRESS_DRAIN0_MODE + params->port * 4, 0);
11854
11855         /* update shared memory */
11856         elink_update_mng(params, vars->link_status);
11857         return ELINK_STATUS_OK;
11858 }
11859 #endif
11860 #ifdef ELINK_INCLUDE_FPGA
11861 static elink_status_t elink_init_fpga(struct elink_params *params,
11862                                       struct elink_vars *vars)
11863 {
11864         /* Enable on E1.5 FPGA */
11865         struct bnx2x_softc *sc = params->sc;
11866         vars->duplex = DUPLEX_FULL;
11867         vars->flow_ctrl = ELINK_FLOW_CTRL_NONE;
11868         vars->flow_ctrl = (ELINK_FLOW_CTRL_TX | ELINK_FLOW_CTRL_RX);
11869         vars->link_status |= (LINK_STATUS_TX_FLOW_CONTROL_ENABLED |
11870                               LINK_STATUS_RX_FLOW_CONTROL_ENABLED);
11871         if (CHIP_IS_E3(sc)) {
11872                 vars->line_speed = params->req_line_speed[0];
11873                 switch (vars->line_speed) {
11874                 case ELINK_SPEED_AUTO_NEG:
11875                         vars->line_speed = ELINK_SPEED_2500;
11876                 case ELINK_SPEED_2500:
11877                         vars->link_status = ELINK_LINK_2500TFD;
11878                         break;
11879                 case ELINK_SPEED_1000:
11880                         vars->link_status = ELINK_LINK_1000XFD;
11881                         break;
11882                 case ELINK_SPEED_100:
11883                         vars->link_status = ELINK_LINK_100TXFD;
11884                         break;
11885                 case ELINK_SPEED_10:
11886                         vars->link_status = ELINK_LINK_10TFD;
11887                         break;
11888                 default:
11889                         PMD_DRV_LOG(DEBUG, "Invalid link speed %d",
11890                                     params->req_line_speed[0]);
11891                         return ELINK_STATUS_ERROR;
11892                 }
11893                 vars->link_status |= LINK_STATUS_LINK_UP;
11894                 if (params->loopback_mode == ELINK_LOOPBACK_UMAC)
11895                         elink_umac_enable(params, vars, 1);
11896                 else
11897                         elink_umac_enable(params, vars, 0);
11898         } else {
11899                 vars->line_speed = ELINK_SPEED_10000;
11900                 vars->link_status = (LINK_STATUS_LINK_UP | ELINK_LINK_10GTFD);
11901                 if (params->loopback_mode == ELINK_LOOPBACK_EMAC)
11902                         elink_emac_enable(params, vars, 1);
11903                 else
11904                         elink_emac_enable(params, vars, 0);
11905         }
11906         vars->link_up = 1;
11907
11908         if (CHIP_IS_E1x(sc))
11909                 elink_pbf_update(params, vars->flow_ctrl, vars->line_speed);
11910         /* Disable drain */
11911         REG_WR(sc, NIG_REG_EGRESS_DRAIN0_MODE + params->port * 4, 0);
11912
11913         /* Update shared memory */
11914         elink_update_mng(params, vars->link_status);
11915         return ELINK_STATUS_OK;
11916 }
11917 #endif
11918 static void elink_init_bmac_loopback(struct elink_params *params,
11919                                      struct elink_vars *vars)
11920 {
11921         struct bnx2x_softc *sc = params->sc;
11922         vars->link_up = 1;
11923         vars->line_speed = ELINK_SPEED_10000;
11924         vars->duplex = DUPLEX_FULL;
11925         vars->flow_ctrl = ELINK_FLOW_CTRL_NONE;
11926         vars->mac_type = ELINK_MAC_TYPE_BMAC;
11927
11928         vars->phy_flags = PHY_XGXS_FLAG;
11929
11930         elink_xgxs_deassert(params);
11931
11932         /* Set bmac loopback */
11933         elink_bmac_enable(params, vars, 1, 1);
11934
11935         REG_WR(sc, NIG_REG_EGRESS_DRAIN0_MODE + params->port * 4, 0);
11936 }
11937
11938 static void elink_init_emac_loopback(struct elink_params *params,
11939                                      struct elink_vars *vars)
11940 {
11941         struct bnx2x_softc *sc = params->sc;
11942         vars->link_up = 1;
11943         vars->line_speed = ELINK_SPEED_1000;
11944         vars->duplex = DUPLEX_FULL;
11945         vars->flow_ctrl = ELINK_FLOW_CTRL_NONE;
11946         vars->mac_type = ELINK_MAC_TYPE_EMAC;
11947
11948         vars->phy_flags = PHY_XGXS_FLAG;
11949
11950         elink_xgxs_deassert(params);
11951         /* Set bmac loopback */
11952         elink_emac_enable(params, vars, 1);
11953         elink_emac_program(params, vars);
11954         REG_WR(sc, NIG_REG_EGRESS_DRAIN0_MODE + params->port * 4, 0);
11955 }
11956
11957 static void elink_init_xmac_loopback(struct elink_params *params,
11958                                      struct elink_vars *vars)
11959 {
11960         struct bnx2x_softc *sc = params->sc;
11961         vars->link_up = 1;
11962         if (!params->req_line_speed[0])
11963                 vars->line_speed = ELINK_SPEED_10000;
11964         else
11965                 vars->line_speed = params->req_line_speed[0];
11966         vars->duplex = DUPLEX_FULL;
11967         vars->flow_ctrl = ELINK_FLOW_CTRL_NONE;
11968         vars->mac_type = ELINK_MAC_TYPE_XMAC;
11969         vars->phy_flags = PHY_XGXS_FLAG;
11970         /* Set WC to loopback mode since link is required to provide clock
11971          * to the XMAC in 20G mode
11972          */
11973         elink_set_aer_mmd(params, &params->phy[0]);
11974         elink_warpcore_reset_lane(sc, &params->phy[0], 0);
11975         params->phy[ELINK_INT_PHY].config_loopback(&params->phy[ELINK_INT_PHY],
11976                                                    params);
11977
11978         elink_xmac_enable(params, vars, 1);
11979         REG_WR(sc, NIG_REG_EGRESS_DRAIN0_MODE + params->port * 4, 0);
11980 }
11981
11982 static void elink_init_umac_loopback(struct elink_params *params,
11983                                      struct elink_vars *vars)
11984 {
11985         struct bnx2x_softc *sc = params->sc;
11986         vars->link_up = 1;
11987         vars->line_speed = ELINK_SPEED_1000;
11988         vars->duplex = DUPLEX_FULL;
11989         vars->flow_ctrl = ELINK_FLOW_CTRL_NONE;
11990         vars->mac_type = ELINK_MAC_TYPE_UMAC;
11991         vars->phy_flags = PHY_XGXS_FLAG;
11992         elink_umac_enable(params, vars, 1);
11993
11994         REG_WR(sc, NIG_REG_EGRESS_DRAIN0_MODE + params->port * 4, 0);
11995 }
11996
11997 static void elink_init_xgxs_loopback(struct elink_params *params,
11998                                      struct elink_vars *vars)
11999 {
12000         struct bnx2x_softc *sc = params->sc;
12001         struct elink_phy *int_phy = &params->phy[ELINK_INT_PHY];
12002         vars->link_up = 1;
12003         vars->flow_ctrl = ELINK_FLOW_CTRL_NONE;
12004         vars->duplex = DUPLEX_FULL;
12005         if (params->req_line_speed[0] == ELINK_SPEED_1000)
12006                 vars->line_speed = ELINK_SPEED_1000;
12007         else if ((params->req_line_speed[0] == ELINK_SPEED_20000) ||
12008                  (int_phy->flags & ELINK_FLAGS_WC_DUAL_MODE))
12009                 vars->line_speed = ELINK_SPEED_20000;
12010         else
12011                 vars->line_speed = ELINK_SPEED_10000;
12012
12013         if (!USES_WARPCORE(sc))
12014                 elink_xgxs_deassert(params);
12015         elink_link_initialize(params, vars);
12016
12017         if (params->req_line_speed[0] == ELINK_SPEED_1000) {
12018                 if (USES_WARPCORE(sc))
12019                         elink_umac_enable(params, vars, 0);
12020                 else {
12021                         elink_emac_program(params, vars);
12022                         elink_emac_enable(params, vars, 0);
12023                 }
12024         } else {
12025                 if (USES_WARPCORE(sc))
12026                         elink_xmac_enable(params, vars, 0);
12027                 else
12028                         elink_bmac_enable(params, vars, 0, 1);
12029         }
12030
12031         if (params->loopback_mode == ELINK_LOOPBACK_XGXS) {
12032                 /* Set 10G XGXS loopback */
12033                 int_phy->config_loopback(int_phy, params);
12034         } else {
12035                 /* Set external phy loopback */
12036                 uint8_t phy_index;
12037                 for (phy_index = ELINK_EXT_PHY1;
12038                      phy_index < params->num_phys; phy_index++)
12039                         if (params->phy[phy_index].config_loopback)
12040                                 params->phy[phy_index].config_loopback(&params->
12041                                                                        phy
12042                                                                        [phy_index],
12043                                                                        params);
12044         }
12045         REG_WR(sc, NIG_REG_EGRESS_DRAIN0_MODE + params->port * 4, 0);
12046
12047         elink_set_led(params, vars, ELINK_LED_MODE_OPER, vars->line_speed);
12048 }
12049
12050 void elink_set_rx_filter(struct elink_params *params, uint8_t en)
12051 {
12052         struct bnx2x_softc *sc = params->sc;
12053         uint8_t val = en * 0x1F;
12054
12055         /* Open / close the gate between the NIG and the BRB */
12056         if (!CHIP_IS_E1x(sc))
12057                 val |= en * 0x20;
12058         REG_WR(sc, NIG_REG_LLH0_BRB1_DRV_MASK + params->port * 4, val);
12059
12060         REG_WR(sc, NIG_REG_LLH0_BRB1_DRV_MASK_MF + params->port * 4, en * 0x3);
12061
12062         REG_WR(sc, (params->port ? NIG_REG_LLH1_BRB1_NOT_MCP :
12063                     NIG_REG_LLH0_BRB1_NOT_MCP), en);
12064 }
12065
12066 static elink_status_t elink_avoid_link_flap(struct elink_params *params,
12067                                             struct elink_vars *vars)
12068 {
12069         uint32_t phy_idx;
12070         uint32_t dont_clear_stat, lfa_sts;
12071         struct bnx2x_softc *sc = params->sc;
12072
12073         /* Sync the link parameters */
12074         elink_link_status_update(params, vars);
12075
12076         /*
12077          * The module verification was already done by previous link owner,
12078          * so this call is meant only to get warning message
12079          */
12080
12081         for (phy_idx = ELINK_INT_PHY; phy_idx < params->num_phys; phy_idx++) {
12082                 struct elink_phy *phy = &params->phy[phy_idx];
12083                 if (phy->phy_specific_func) {
12084                         PMD_DRV_LOG(DEBUG, "Calling PHY specific func");
12085                         phy->phy_specific_func(phy, params, ELINK_PHY_INIT);
12086                 }
12087                 if ((phy->media_type == ELINK_ETH_PHY_SFPP_10G_FIBER) ||
12088                     (phy->media_type == ELINK_ETH_PHY_SFP_1G_FIBER) ||
12089                     (phy->media_type == ELINK_ETH_PHY_DA_TWINAX))
12090                         elink_verify_sfp_module(phy, params);
12091         }
12092         lfa_sts = REG_RD(sc, params->lfa_base +
12093                          offsetof(struct shmem_lfa, lfa_sts));
12094
12095         dont_clear_stat = lfa_sts & SHMEM_LFA_DONT_CLEAR_STAT;
12096
12097         /* Re-enable the NIG/MAC */
12098         if (CHIP_IS_E3(sc)) {
12099                 if (!dont_clear_stat) {
12100                         REG_WR(sc, GRCBASE_MISC +
12101                                MISC_REGISTERS_RESET_REG_2_CLEAR,
12102                                (MISC_REGISTERS_RESET_REG_2_MSTAT0 <<
12103                                 params->port));
12104                         REG_WR(sc, GRCBASE_MISC +
12105                                MISC_REGISTERS_RESET_REG_2_SET,
12106                                (MISC_REGISTERS_RESET_REG_2_MSTAT0 <<
12107                                 params->port));
12108                 }
12109                 if (vars->line_speed < ELINK_SPEED_10000)
12110                         elink_umac_enable(params, vars, 0);
12111                 else
12112                         elink_xmac_enable(params, vars, 0);
12113         } else {
12114                 if (vars->line_speed < ELINK_SPEED_10000)
12115                         elink_emac_enable(params, vars, 0);
12116                 else
12117                         elink_bmac_enable(params, vars, 0, !dont_clear_stat);
12118         }
12119
12120         /* Increment LFA count */
12121         lfa_sts = ((lfa_sts & ~LINK_FLAP_AVOIDANCE_COUNT_MASK) |
12122                    (((((lfa_sts & LINK_FLAP_AVOIDANCE_COUNT_MASK) >>
12123                        LINK_FLAP_AVOIDANCE_COUNT_OFFSET) + 1) & 0xff)
12124                     << LINK_FLAP_AVOIDANCE_COUNT_OFFSET));
12125         /* Clear link flap reason */
12126         lfa_sts &= ~LFA_LINK_FLAP_REASON_MASK;
12127
12128         REG_WR(sc, params->lfa_base +
12129                offsetof(struct shmem_lfa, lfa_sts), lfa_sts);
12130
12131         /* Disable NIG DRAIN */
12132         REG_WR(sc, NIG_REG_EGRESS_DRAIN0_MODE + params->port * 4, 0);
12133
12134         /* Enable interrupts */
12135         elink_link_int_enable(params);
12136         return ELINK_STATUS_OK;
12137 }
12138
12139 static void elink_cannot_avoid_link_flap(struct elink_params *params,
12140                                          struct elink_vars *vars,
12141                                          int lfa_status)
12142 {
12143         uint32_t lfa_sts, cfg_idx, tmp_val;
12144         struct bnx2x_softc *sc = params->sc;
12145
12146         elink_link_reset(params, vars, 1);
12147
12148         if (!params->lfa_base)
12149                 return;
12150         /* Store the new link parameters */
12151         REG_WR(sc, params->lfa_base +
12152                offsetof(struct shmem_lfa, req_duplex),
12153                params->req_duplex[0] | (params->req_duplex[1] << 16));
12154
12155         REG_WR(sc, params->lfa_base +
12156                offsetof(struct shmem_lfa, req_flow_ctrl),
12157                params->req_flow_ctrl[0] | (params->req_flow_ctrl[1] << 16));
12158
12159         REG_WR(sc, params->lfa_base +
12160                offsetof(struct shmem_lfa, req_line_speed),
12161                params->req_line_speed[0] | (params->req_line_speed[1] << 16));
12162
12163         for (cfg_idx = 0; cfg_idx < SHMEM_LINK_CONFIG_SIZE; cfg_idx++) {
12164                 REG_WR(sc, params->lfa_base +
12165                        offsetof(struct shmem_lfa,
12166                                 speed_cap_mask[cfg_idx]),
12167                        params->speed_cap_mask[cfg_idx]);
12168         }
12169
12170         tmp_val = REG_RD(sc, params->lfa_base +
12171                          offsetof(struct shmem_lfa, additional_config));
12172         tmp_val &= ~REQ_FC_AUTO_ADV_MASK;
12173         tmp_val |= params->req_fc_auto_adv;
12174
12175         REG_WR(sc, params->lfa_base +
12176                offsetof(struct shmem_lfa, additional_config), tmp_val);
12177
12178         lfa_sts = REG_RD(sc, params->lfa_base +
12179                          offsetof(struct shmem_lfa, lfa_sts));
12180
12181         /* Clear the "Don't Clear Statistics" bit, and set reason */
12182         lfa_sts &= ~SHMEM_LFA_DONT_CLEAR_STAT;
12183
12184         /* Set link flap reason */
12185         lfa_sts &= ~LFA_LINK_FLAP_REASON_MASK;
12186         lfa_sts |= ((lfa_status & LFA_LINK_FLAP_REASON_MASK) <<
12187                     LFA_LINK_FLAP_REASON_OFFSET);
12188
12189         /* Increment link flap counter */
12190         lfa_sts = ((lfa_sts & ~LINK_FLAP_COUNT_MASK) |
12191                    (((((lfa_sts & LINK_FLAP_COUNT_MASK) >>
12192                        LINK_FLAP_COUNT_OFFSET) + 1) & 0xff)
12193                     << LINK_FLAP_COUNT_OFFSET));
12194         REG_WR(sc, params->lfa_base +
12195                offsetof(struct shmem_lfa, lfa_sts), lfa_sts);
12196         /* Proceed with regular link initialization */
12197 }
12198
12199 elink_status_t elink_phy_init(struct elink_params *params,
12200                               struct elink_vars *vars)
12201 {
12202         int lfa_status;
12203         struct bnx2x_softc *sc = params->sc;
12204         PMD_DRV_LOG(DEBUG, "Phy Initialization started");
12205         PMD_DRV_LOG(DEBUG, "(1) req_speed %d, req_flowctrl %d",
12206                     params->req_line_speed[0], params->req_flow_ctrl[0]);
12207         PMD_DRV_LOG(DEBUG, "(2) req_speed %d, req_flowctrl %d",
12208                     params->req_line_speed[1], params->req_flow_ctrl[1]);
12209         PMD_DRV_LOG(DEBUG, "req_adv_flow_ctrl 0x%x", params->req_fc_auto_adv);
12210         vars->link_status = 0;
12211         vars->phy_link_up = 0;
12212         vars->link_up = 0;
12213         vars->line_speed = 0;
12214         vars->duplex = DUPLEX_FULL;
12215         vars->flow_ctrl = ELINK_FLOW_CTRL_NONE;
12216         vars->mac_type = ELINK_MAC_TYPE_NONE;
12217         vars->phy_flags = 0;
12218         vars->check_kr2_recovery_cnt = 0;
12219         params->link_flags = ELINK_PHY_INITIALIZED;
12220         /* Driver opens NIG-BRB filters */
12221         elink_set_rx_filter(params, 1);
12222         /* Check if link flap can be avoided */
12223         lfa_status = elink_check_lfa(params);
12224
12225         if (lfa_status == 0) {
12226                 PMD_DRV_LOG(DEBUG, "Link Flap Avoidance in progress");
12227                 return elink_avoid_link_flap(params, vars);
12228         }
12229
12230         PMD_DRV_LOG(DEBUG, "Cannot avoid link flap lfa_sta=0x%x", lfa_status);
12231         elink_cannot_avoid_link_flap(params, vars, lfa_status);
12232
12233         /* Disable attentions */
12234         elink_bits_dis(sc, NIG_REG_MASK_INTERRUPT_PORT0 + params->port * 4,
12235                        (ELINK_NIG_MASK_XGXS0_LINK_STATUS |
12236                         ELINK_NIG_MASK_XGXS0_LINK10G |
12237                         ELINK_NIG_MASK_SERDES0_LINK_STATUS |
12238                         ELINK_NIG_MASK_MI_INT));
12239 #ifdef ELINK_INCLUDE_EMUL
12240         if (!(params->feature_config_flags &
12241               ELINK_FEATURE_CONFIG_EMUL_DISABLE_EMAC))
12242 #endif
12243
12244                 elink_emac_init(params);
12245
12246         if (params->feature_config_flags & ELINK_FEATURE_CONFIG_PFC_ENABLED)
12247                 vars->link_status |= LINK_STATUS_PFC_ENABLED;
12248
12249         if ((params->num_phys == 0) && !CHIP_REV_IS_SLOW(sc)) {
12250                 PMD_DRV_LOG(DEBUG, "No phy found for initialization !!");
12251                 return ELINK_STATUS_ERROR;
12252         }
12253         set_phy_vars(params, vars);
12254
12255         PMD_DRV_LOG(DEBUG, "Num of phys on board: %d", params->num_phys);
12256 #ifdef ELINK_INCLUDE_FPGA
12257         if (CHIP_REV_IS_FPGA(sc)) {
12258                 return elink_init_fpga(params, vars);
12259         } else
12260 #endif
12261 #ifdef ELINK_INCLUDE_EMUL
12262         if (CHIP_REV_IS_EMUL(sc)) {
12263                 return elink_init_emul(params, vars);
12264         } else
12265 #endif
12266                 switch (params->loopback_mode) {
12267                 case ELINK_LOOPBACK_BMAC:
12268                         elink_init_bmac_loopback(params, vars);
12269                         break;
12270                 case ELINK_LOOPBACK_EMAC:
12271                         elink_init_emac_loopback(params, vars);
12272                         break;
12273                 case ELINK_LOOPBACK_XMAC:
12274                         elink_init_xmac_loopback(params, vars);
12275                         break;
12276                 case ELINK_LOOPBACK_UMAC:
12277                         elink_init_umac_loopback(params, vars);
12278                         break;
12279                 case ELINK_LOOPBACK_XGXS:
12280                 case ELINK_LOOPBACK_EXT_PHY:
12281                         elink_init_xgxs_loopback(params, vars);
12282                         break;
12283                 default:
12284                         if (!CHIP_IS_E3(sc)) {
12285                                 if (params->switch_cfg == ELINK_SWITCH_CFG_10G)
12286                                         elink_xgxs_deassert(params);
12287                                 else
12288                                         elink_serdes_deassert(sc, params->port);
12289                         }
12290                         elink_link_initialize(params, vars);
12291                         DELAY(1000 * 30);
12292                         elink_link_int_enable(params);
12293                         break;
12294                 }
12295         elink_update_mng(params, vars->link_status);
12296
12297         elink_update_mng_eee(params, vars->eee_status);
12298         return ELINK_STATUS_OK;
12299 }
12300
12301 static elink_status_t elink_link_reset(struct elink_params *params,
12302                                        struct elink_vars *vars,
12303                                        uint8_t reset_ext_phy)
12304 {
12305         struct bnx2x_softc *sc = params->sc;
12306         uint8_t phy_index, port = params->port, clear_latch_ind = 0;
12307         PMD_DRV_LOG(DEBUG, "Resetting the link of port %d", port);
12308         /* Disable attentions */
12309         vars->link_status = 0;
12310         elink_update_mng(params, vars->link_status);
12311         vars->eee_status &= ~(SHMEM_EEE_LP_ADV_STATUS_MASK |
12312                               SHMEM_EEE_ACTIVE_BIT);
12313         elink_update_mng_eee(params, vars->eee_status);
12314         elink_bits_dis(sc, NIG_REG_MASK_INTERRUPT_PORT0 + port * 4,
12315                        (ELINK_NIG_MASK_XGXS0_LINK_STATUS |
12316                         ELINK_NIG_MASK_XGXS0_LINK10G |
12317                         ELINK_NIG_MASK_SERDES0_LINK_STATUS |
12318                         ELINK_NIG_MASK_MI_INT));
12319
12320         /* Activate nig drain */
12321         REG_WR(sc, NIG_REG_EGRESS_DRAIN0_MODE + port * 4, 1);
12322
12323         /* Disable nig egress interface */
12324         if (!CHIP_IS_E3(sc)) {
12325                 REG_WR(sc, NIG_REG_BMAC0_OUT_EN + port * 4, 0);
12326                 REG_WR(sc, NIG_REG_EGRESS_EMAC0_OUT_EN + port * 4, 0);
12327         }
12328 #ifdef ELINK_INCLUDE_EMUL
12329         /* Stop BigMac rx */
12330         if (!(params->feature_config_flags &
12331               ELINK_FEATURE_CONFIG_EMUL_DISABLE_BMAC))
12332 #endif
12333                 if (!CHIP_IS_E3(sc))
12334                         elink_set_bmac_rx(sc, port, 0);
12335 #ifdef ELINK_INCLUDE_EMUL
12336         /* Stop XMAC/UMAC rx */
12337         if (!(params->feature_config_flags &
12338               ELINK_FEATURE_CONFIG_EMUL_DISABLE_XMAC))
12339 #endif
12340                 if (CHIP_IS_E3(sc) && !CHIP_REV_IS_FPGA(sc)) {
12341                         elink_set_xmac_rxtx(params, 0);
12342                         elink_set_umac_rxtx(params, 0);
12343                 }
12344         /* Disable emac */
12345         if (!CHIP_IS_E3(sc))
12346                 REG_WR(sc, NIG_REG_NIG_EMAC0_EN + port * 4, 0);
12347
12348         DELAY(1000 * 10);
12349         /* The PHY reset is controlled by GPIO 1
12350          * Hold it as vars low
12351          */
12352         /* Clear link led */
12353         elink_set_mdio_emac_per_phy(sc, params);
12354         elink_set_led(params, vars, ELINK_LED_MODE_OFF, 0);
12355
12356         if (reset_ext_phy && (!CHIP_REV_IS_SLOW(sc))) {
12357                 for (phy_index = ELINK_EXT_PHY1; phy_index < params->num_phys;
12358                      phy_index++) {
12359                         if (params->phy[phy_index].link_reset) {
12360                                 elink_set_aer_mmd(params,
12361                                                   &params->phy[phy_index]);
12362                                 params->phy[phy_index].link_reset(&params->
12363                                                                   phy
12364                                                                   [phy_index],
12365                                                                   params);
12366                         }
12367                         if (params->phy[phy_index].flags &
12368                             ELINK_FLAGS_REARM_LATCH_SIGNAL)
12369                                 clear_latch_ind = 1;
12370                 }
12371         }
12372
12373         if (clear_latch_ind) {
12374                 /* Clear latching indication */
12375                 elink_rearm_latch_signal(sc, port, 0);
12376                 elink_bits_dis(sc, NIG_REG_LATCH_BC_0 + port * 4,
12377                                1 << ELINK_NIG_LATCH_BC_ENABLE_MI_INT);
12378         }
12379 #if defined(ELINK_INCLUDE_EMUL) || defined(ELINK_INCLUDE_FPGA)
12380         if (!CHIP_REV_IS_SLOW(sc))
12381 #endif
12382                 if (params->phy[ELINK_INT_PHY].link_reset)
12383                         params->phy[ELINK_INT_PHY].link_reset(&params->
12384                                                               phy
12385                                                               [ELINK_INT_PHY],
12386                                                               params);
12387
12388         /* Disable nig ingress interface */
12389         if (!CHIP_IS_E3(sc)) {
12390                 /* Reset BigMac */
12391                 REG_WR(sc, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
12392                        (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port));
12393                 REG_WR(sc, NIG_REG_BMAC0_IN_EN + port * 4, 0);
12394                 REG_WR(sc, NIG_REG_EMAC0_IN_EN + port * 4, 0);
12395         } else {
12396                 uint32_t xmac_base =
12397                     (params->port) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
12398                 elink_set_xumac_nig(params, 0, 0);
12399                 if (REG_RD(sc, MISC_REG_RESET_REG_2) &
12400                     MISC_REGISTERS_RESET_REG_2_XMAC)
12401                         REG_WR(sc, xmac_base + XMAC_REG_CTRL,
12402                                XMAC_CTRL_REG_SOFT_RESET);
12403         }
12404         vars->link_up = 0;
12405         vars->phy_flags = 0;
12406         return ELINK_STATUS_OK;
12407 }
12408
12409 elink_status_t elink_lfa_reset(struct elink_params * params,
12410                                struct elink_vars * vars)
12411 {
12412         struct bnx2x_softc *sc = params->sc;
12413         vars->link_up = 0;
12414         vars->phy_flags = 0;
12415         params->link_flags &= ~ELINK_PHY_INITIALIZED;
12416         if (!params->lfa_base)
12417                 return elink_link_reset(params, vars, 1);
12418         /*
12419          * Activate NIG drain so that during this time the device won't send
12420          * anything while it is unable to response.
12421          */
12422         REG_WR(sc, NIG_REG_EGRESS_DRAIN0_MODE + params->port * 4, 1);
12423
12424         /*
12425          * Close gracefully the gate from BMAC to NIG such that no half packets
12426          * are passed.
12427          */
12428         if (!CHIP_IS_E3(sc))
12429                 elink_set_bmac_rx(sc, params->port, 0);
12430
12431         if (CHIP_IS_E3(sc)) {
12432                 elink_set_xmac_rxtx(params, 0);
12433                 elink_set_umac_rxtx(params, 0);
12434         }
12435         /* Wait 10ms for the pipe to clean up */
12436         DELAY(1000 * 10);
12437
12438         /* Clean the NIG-BRB using the network filters in a way that will
12439          * not cut a packet in the middle.
12440          */
12441         elink_set_rx_filter(params, 0);
12442
12443         /*
12444          * Re-open the gate between the BMAC and the NIG, after verifying the
12445          * gate to the BRB is closed, otherwise packets may arrive to the
12446          * firmware before driver had initialized it. The target is to achieve
12447          * minimum management protocol down time.
12448          */
12449         if (!CHIP_IS_E3(sc))
12450                 elink_set_bmac_rx(sc, params->port, 1);
12451
12452         if (CHIP_IS_E3(sc)) {
12453                 elink_set_xmac_rxtx(params, 1);
12454                 elink_set_umac_rxtx(params, 1);
12455         }
12456         /* Disable NIG drain */
12457         REG_WR(sc, NIG_REG_EGRESS_DRAIN0_MODE + params->port * 4, 0);
12458         return ELINK_STATUS_OK;
12459 }
12460
12461 /****************************************************************************/
12462 /*                              Common function                             */
12463 /****************************************************************************/
12464 static elink_status_t elink_8073_common_init_phy(struct bnx2x_softc *sc,
12465                                                  uint32_t shmem_base_path[],
12466                                                  uint32_t shmem2_base_path[],
12467                                                  uint8_t phy_index,
12468                                                  __rte_unused uint32_t chip_id)
12469 {
12470         struct elink_phy phy[PORT_MAX];
12471         struct elink_phy *phy_blk[PORT_MAX];
12472         uint16_t val;
12473         int8_t port = 0;
12474         int8_t port_of_path = 0;
12475         uint32_t swap_val, swap_override;
12476         swap_val = REG_RD(sc, NIG_REG_PORT_SWAP);
12477         swap_override = REG_RD(sc, NIG_REG_STRAP_OVERRIDE);
12478         port ^= (swap_val && swap_override);
12479         elink_ext_phy_hw_reset(sc, port);
12480         /* PART1 - Reset both phys */
12481         for (port = PORT_MAX - 1; port >= PORT_0; port--) {
12482                 uint32_t shmem_base, shmem2_base;
12483                 /* In E2, same phy is using for port0 of the two paths */
12484                 if (CHIP_IS_E1x(sc)) {
12485                         shmem_base = shmem_base_path[0];
12486                         shmem2_base = shmem2_base_path[0];
12487                         port_of_path = port;
12488                 } else {
12489                         shmem_base = shmem_base_path[port];
12490                         shmem2_base = shmem2_base_path[port];
12491                         port_of_path = 0;
12492                 }
12493
12494                 /* Extract the ext phy address for the port */
12495                 if (elink_populate_phy(sc, phy_index, shmem_base, shmem2_base,
12496                                        port_of_path, &phy[port]) !=
12497                     ELINK_STATUS_OK) {
12498                         PMD_DRV_LOG(DEBUG, "populate_phy failed");
12499                         return ELINK_STATUS_ERROR;
12500                 }
12501                 /* Disable attentions */
12502                 elink_bits_dis(sc, NIG_REG_MASK_INTERRUPT_PORT0 +
12503                                port_of_path * 4,
12504                                (ELINK_NIG_MASK_XGXS0_LINK_STATUS |
12505                                 ELINK_NIG_MASK_XGXS0_LINK10G |
12506                                 ELINK_NIG_MASK_SERDES0_LINK_STATUS |
12507                                 ELINK_NIG_MASK_MI_INT));
12508
12509                 /* Need to take the phy out of low power mode in order
12510                  * to write to access its registers
12511                  */
12512                 elink_cb_gpio_write(sc, MISC_REGISTERS_GPIO_2,
12513                                     MISC_REGISTERS_GPIO_OUTPUT_HIGH, port);
12514
12515                 /* Reset the phy */
12516                 elink_cl45_write(sc, &phy[port],
12517                                  MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 1 << 15);
12518         }
12519
12520         /* Add delay of 150ms after reset */
12521         DELAY(1000 * 150);
12522
12523         if (phy[PORT_0].addr & 0x1) {
12524                 phy_blk[PORT_0] = &(phy[PORT_1]);
12525                 phy_blk[PORT_1] = &(phy[PORT_0]);
12526         } else {
12527                 phy_blk[PORT_0] = &(phy[PORT_0]);
12528                 phy_blk[PORT_1] = &(phy[PORT_1]);
12529         }
12530
12531         /* PART2 - Download firmware to both phys */
12532         for (port = PORT_MAX - 1; port >= PORT_0; port--) {
12533                 if (CHIP_IS_E1x(sc))
12534                         port_of_path = port;
12535                 else
12536                         port_of_path = 0;
12537
12538                 PMD_DRV_LOG(DEBUG, "Loading spirom for phy address 0x%x",
12539                             phy_blk[port]->addr);
12540                 if (elink_8073_8727_external_rom_boot(sc, phy_blk[port],
12541                                                       port_of_path))
12542                         return ELINK_STATUS_ERROR;
12543
12544                 /* Only set bit 10 = 1 (Tx power down) */
12545                 elink_cl45_read(sc, phy_blk[port],
12546                                 MDIO_PMA_DEVAD,
12547                                 MDIO_PMA_REG_TX_POWER_DOWN, &val);
12548
12549                 /* Phase1 of TX_POWER_DOWN reset */
12550                 elink_cl45_write(sc, phy_blk[port],
12551                                  MDIO_PMA_DEVAD,
12552                                  MDIO_PMA_REG_TX_POWER_DOWN, (val | 1 << 10));
12553         }
12554
12555         /* Toggle Transmitter: Power down and then up with 600ms delay
12556          * between
12557          */
12558         DELAY(1000 * 600);
12559
12560         /* PART3 - complete TX_POWER_DOWN process, and set GPIO2 back to low */
12561         for (port = PORT_MAX - 1; port >= PORT_0; port--) {
12562                 /* Phase2 of POWER_DOWN_RESET */
12563                 /* Release bit 10 (Release Tx power down) */
12564                 elink_cl45_read(sc, phy_blk[port],
12565                                 MDIO_PMA_DEVAD,
12566                                 MDIO_PMA_REG_TX_POWER_DOWN, &val);
12567
12568                 elink_cl45_write(sc, phy_blk[port],
12569                                  MDIO_PMA_DEVAD,
12570                                  MDIO_PMA_REG_TX_POWER_DOWN,
12571                                  (val & (~(1 << 10))));
12572                 DELAY(1000 * 15);
12573
12574                 /* Read modify write the SPI-ROM version select register */
12575                 elink_cl45_read(sc, phy_blk[port],
12576                                 MDIO_PMA_DEVAD,
12577                                 MDIO_PMA_REG_EDC_FFE_MAIN, &val);
12578                 elink_cl45_write(sc, phy_blk[port],
12579                                  MDIO_PMA_DEVAD,
12580                                  MDIO_PMA_REG_EDC_FFE_MAIN, (val | (1 << 12)));
12581
12582                 /* set GPIO2 back to LOW */
12583                 elink_cb_gpio_write(sc, MISC_REGISTERS_GPIO_2,
12584                                     MISC_REGISTERS_GPIO_OUTPUT_LOW, port);
12585         }
12586         return ELINK_STATUS_OK;
12587 }
12588
12589 static elink_status_t elink_8726_common_init_phy(struct bnx2x_softc *sc,
12590                                                  uint32_t shmem_base_path[],
12591                                                  uint32_t shmem2_base_path[],
12592                                                  uint8_t phy_index,
12593                                                  __rte_unused uint32_t chip_id)
12594 {
12595         uint32_t val;
12596         int8_t port;
12597         struct elink_phy phy;
12598         /* Use port1 because of the static port-swap */
12599         /* Enable the module detection interrupt */
12600         val = REG_RD(sc, MISC_REG_GPIO_EVENT_EN);
12601         val |= ((1 << MISC_REGISTERS_GPIO_3) |
12602                 (1 <<
12603                  (MISC_REGISTERS_GPIO_3 + MISC_REGISTERS_GPIO_PORT_SHIFT)));
12604         REG_WR(sc, MISC_REG_GPIO_EVENT_EN, val);
12605
12606         elink_ext_phy_hw_reset(sc, 0);
12607         DELAY(1000 * 5);
12608         for (port = 0; port < PORT_MAX; port++) {
12609                 uint32_t shmem_base, shmem2_base;
12610
12611                 /* In E2, same phy is using for port0 of the two paths */
12612                 if (CHIP_IS_E1x(sc)) {
12613                         shmem_base = shmem_base_path[0];
12614                         shmem2_base = shmem2_base_path[0];
12615                 } else {
12616                         shmem_base = shmem_base_path[port];
12617                         shmem2_base = shmem2_base_path[port];
12618                 }
12619                 /* Extract the ext phy address for the port */
12620                 if (elink_populate_phy(sc, phy_index, shmem_base, shmem2_base,
12621                                        port, &phy) != ELINK_STATUS_OK) {
12622                         PMD_DRV_LOG(DEBUG, "populate phy failed");
12623                         return ELINK_STATUS_ERROR;
12624                 }
12625
12626                 /* Reset phy */
12627                 elink_cl45_write(sc, &phy,
12628                                  MDIO_PMA_DEVAD, MDIO_PMA_REG_GEN_CTRL, 0x0001);
12629
12630                 /* Set fault module detected LED on */
12631                 elink_cb_gpio_write(sc, MISC_REGISTERS_GPIO_0,
12632                                     MISC_REGISTERS_GPIO_HIGH, port);
12633         }
12634
12635         return ELINK_STATUS_OK;
12636 }
12637
12638 static void elink_get_ext_phy_reset_gpio(struct bnx2x_softc *sc,
12639                                          uint32_t shmem_base, uint8_t * io_gpio,
12640                                          uint8_t * io_port)
12641 {
12642
12643         uint32_t phy_gpio_reset = REG_RD(sc, shmem_base +
12644                                          offsetof(struct shmem_region,
12645                                                   dev_info.
12646                                                   port_hw_config[PORT_0].
12647                                                   default_cfg));
12648         switch (phy_gpio_reset) {
12649         case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO0_P0:
12650                 *io_gpio = 0;
12651                 *io_port = 0;
12652                 break;
12653         case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO1_P0:
12654                 *io_gpio = 1;
12655                 *io_port = 0;
12656                 break;
12657         case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO2_P0:
12658                 *io_gpio = 2;
12659                 *io_port = 0;
12660                 break;
12661         case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO3_P0:
12662                 *io_gpio = 3;
12663                 *io_port = 0;
12664                 break;
12665         case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO0_P1:
12666                 *io_gpio = 0;
12667                 *io_port = 1;
12668                 break;
12669         case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO1_P1:
12670                 *io_gpio = 1;
12671                 *io_port = 1;
12672                 break;
12673         case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO2_P1:
12674                 *io_gpio = 2;
12675                 *io_port = 1;
12676                 break;
12677         case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO3_P1:
12678                 *io_gpio = 3;
12679                 *io_port = 1;
12680                 break;
12681         default:
12682                 /* Don't override the io_gpio and io_port */
12683                 break;
12684         }
12685 }
12686
12687 static elink_status_t elink_8727_common_init_phy(struct bnx2x_softc *sc,
12688                                                  uint32_t shmem_base_path[],
12689                                                  uint32_t shmem2_base_path[],
12690                                                  uint8_t phy_index,
12691                                                  __rte_unused uint32_t chip_id)
12692 {
12693         int8_t port, reset_gpio;
12694         uint32_t swap_val, swap_override;
12695         struct elink_phy phy[PORT_MAX];
12696         struct elink_phy *phy_blk[PORT_MAX];
12697         int8_t port_of_path;
12698         swap_val = REG_RD(sc, NIG_REG_PORT_SWAP);
12699         swap_override = REG_RD(sc, NIG_REG_STRAP_OVERRIDE);
12700
12701         reset_gpio = MISC_REGISTERS_GPIO_1;
12702         port = 1;
12703
12704         /* Retrieve the reset gpio/port which control the reset.
12705          * Default is GPIO1, PORT1
12706          */
12707         elink_get_ext_phy_reset_gpio(sc, shmem_base_path[0],
12708                                      (uint8_t *) & reset_gpio,
12709                                      (uint8_t *) & port);
12710
12711         /* Calculate the port based on port swap */
12712         port ^= (swap_val && swap_override);
12713
12714         /* Initiate PHY reset */
12715         elink_cb_gpio_write(sc, reset_gpio, MISC_REGISTERS_GPIO_OUTPUT_LOW,
12716                             port);
12717         DELAY(1000 * 1);
12718         elink_cb_gpio_write(sc, reset_gpio, MISC_REGISTERS_GPIO_OUTPUT_HIGH,
12719                             port);
12720
12721         DELAY(1000 * 5);
12722
12723         /* PART1 - Reset both phys */
12724         for (port = PORT_MAX - 1; port >= PORT_0; port--) {
12725                 uint32_t shmem_base, shmem2_base;
12726
12727                 /* In E2, same phy is using for port0 of the two paths */
12728                 if (CHIP_IS_E1x(sc)) {
12729                         shmem_base = shmem_base_path[0];
12730                         shmem2_base = shmem2_base_path[0];
12731                         port_of_path = port;
12732                 } else {
12733                         shmem_base = shmem_base_path[port];
12734                         shmem2_base = shmem2_base_path[port];
12735                         port_of_path = 0;
12736                 }
12737
12738                 /* Extract the ext phy address for the port */
12739                 if (elink_populate_phy(sc, phy_index, shmem_base, shmem2_base,
12740                                        port_of_path, &phy[port]) !=
12741                     ELINK_STATUS_OK) {
12742                         PMD_DRV_LOG(DEBUG, "populate phy failed");
12743                         return ELINK_STATUS_ERROR;
12744                 }
12745                 /* disable attentions */
12746                 elink_bits_dis(sc, NIG_REG_MASK_INTERRUPT_PORT0 +
12747                                port_of_path * 4,
12748                                (ELINK_NIG_MASK_XGXS0_LINK_STATUS |
12749                                 ELINK_NIG_MASK_XGXS0_LINK10G |
12750                                 ELINK_NIG_MASK_SERDES0_LINK_STATUS |
12751                                 ELINK_NIG_MASK_MI_INT));
12752
12753                 /* Reset the phy */
12754                 elink_cl45_write(sc, &phy[port],
12755                                  MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 1 << 15);
12756         }
12757
12758         /* Add delay of 150ms after reset */
12759         DELAY(1000 * 150);
12760         if (phy[PORT_0].addr & 0x1) {
12761                 phy_blk[PORT_0] = &(phy[PORT_1]);
12762                 phy_blk[PORT_1] = &(phy[PORT_0]);
12763         } else {
12764                 phy_blk[PORT_0] = &(phy[PORT_0]);
12765                 phy_blk[PORT_1] = &(phy[PORT_1]);
12766         }
12767         /* PART2 - Download firmware to both phys */
12768         for (port = PORT_MAX - 1; port >= PORT_0; port--) {
12769                 if (CHIP_IS_E1x(sc))
12770                         port_of_path = port;
12771                 else
12772                         port_of_path = 0;
12773                 PMD_DRV_LOG(DEBUG, "Loading spirom for phy address 0x%x",
12774                             phy_blk[port]->addr);
12775                 if (elink_8073_8727_external_rom_boot(sc, phy_blk[port],
12776                                                       port_of_path))
12777                         return ELINK_STATUS_ERROR;
12778                 /* Disable PHY transmitter output */
12779                 elink_cl45_write(sc, phy_blk[port],
12780                                  MDIO_PMA_DEVAD, MDIO_PMA_REG_TX_DISABLE, 1);
12781
12782         }
12783         return ELINK_STATUS_OK;
12784 }
12785
12786 static elink_status_t elink_84833_common_init_phy(struct bnx2x_softc *sc,
12787                                                   uint32_t shmem_base_path[],
12788                                                   __rte_unused uint32_t
12789                                                   shmem2_base_path[],
12790                                                   __rte_unused uint8_t
12791                                                   phy_index, uint32_t chip_id)
12792 {
12793         uint8_t reset_gpios;
12794         reset_gpios = elink_84833_get_reset_gpios(sc, shmem_base_path, chip_id);
12795         elink_cb_gpio_mult_write(sc, reset_gpios,
12796                                  MISC_REGISTERS_GPIO_OUTPUT_LOW);
12797         DELAY(10);
12798         elink_cb_gpio_mult_write(sc, reset_gpios,
12799                                  MISC_REGISTERS_GPIO_OUTPUT_HIGH);
12800         PMD_DRV_LOG(DEBUG, "84833 reset pulse on pin values 0x%x", reset_gpios);
12801         return ELINK_STATUS_OK;
12802 }
12803
12804 static elink_status_t elink_ext_phy_common_init(struct bnx2x_softc *sc,
12805                                                 uint32_t shmem_base_path[],
12806                                                 uint32_t shmem2_base_path[],
12807                                                 uint8_t phy_index,
12808                                                 uint32_t ext_phy_type,
12809                                                 uint32_t chip_id)
12810 {
12811         elink_status_t rc = ELINK_STATUS_OK;
12812
12813         switch (ext_phy_type) {
12814         case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X8073:
12815                 rc = elink_8073_common_init_phy(sc, shmem_base_path,
12816                                                 shmem2_base_path,
12817                                                 phy_index, chip_id);
12818                 break;
12819         case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X8722:
12820         case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X8727:
12821         case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X8727_NOC:
12822                 rc = elink_8727_common_init_phy(sc, shmem_base_path,
12823                                                 shmem2_base_path,
12824                                                 phy_index, chip_id);
12825                 break;
12826
12827         case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X8726:
12828                 /* GPIO1 affects both ports, so there's need to pull
12829                  * it for single port alone
12830                  */
12831                 rc = elink_8726_common_init_phy(sc, shmem_base_path,
12832                                                 shmem2_base_path,
12833                                                 phy_index, chip_id);
12834                 break;
12835         case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X84833:
12836         case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X84834:
12837                 /* GPIO3's are linked, and so both need to be toggled
12838                  * to obtain required 2us pulse.
12839                  */
12840                 rc = elink_84833_common_init_phy(sc, shmem_base_path,
12841                                                  shmem2_base_path,
12842                                                  phy_index, chip_id);
12843                 break;
12844         case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE:
12845                 rc = ELINK_STATUS_ERROR;
12846                 break;
12847         default:
12848                 PMD_DRV_LOG(DEBUG,
12849                             "ext_phy 0x%x common init not required",
12850                             ext_phy_type);
12851                 break;
12852         }
12853
12854         if (rc != ELINK_STATUS_OK)
12855                 elink_cb_event_log(sc, ELINK_LOG_ID_PHY_UNINITIALIZED, 0);      // "Warning: PHY was not initialized,"
12856         // " Port %d",
12857
12858         return rc;
12859 }
12860
12861 elink_status_t elink_common_init_phy(struct bnx2x_softc * sc,
12862                                      uint32_t shmem_base_path[],
12863                                      uint32_t shmem2_base_path[],
12864                                      uint32_t chip_id,
12865                                      __rte_unused uint8_t one_port_enabled)
12866 {
12867         elink_status_t rc = ELINK_STATUS_OK;
12868         uint32_t phy_ver, val;
12869         uint8_t phy_index = 0;
12870         uint32_t ext_phy_type, ext_phy_config;
12871 #if defined(ELINK_INCLUDE_EMUL) || defined(ELINK_INCLUDE_FPGA)
12872         if (CHIP_REV_IS_EMUL(sc) || CHIP_REV_IS_FPGA(sc))
12873                 return ELINK_STATUS_OK;
12874 #endif
12875
12876         elink_set_mdio_clk(sc, GRCBASE_EMAC0);
12877         elink_set_mdio_clk(sc, GRCBASE_EMAC1);
12878         PMD_DRV_LOG(DEBUG, "Begin common phy init");
12879         if (CHIP_IS_E3(sc)) {
12880                 /* Enable EPIO */
12881                 val = REG_RD(sc, MISC_REG_GEN_PURP_HWG);
12882                 REG_WR(sc, MISC_REG_GEN_PURP_HWG, val | 1);
12883         }
12884         /* Check if common init was already done */
12885         phy_ver = REG_RD(sc, shmem_base_path[0] +
12886                          offsetof(struct shmem_region,
12887                                   port_mb[PORT_0].ext_phy_fw_version));
12888         if (phy_ver) {
12889                 PMD_DRV_LOG(DEBUG, "Not doing common init; phy ver is 0x%x",
12890                             phy_ver);
12891                 return ELINK_STATUS_OK;
12892         }
12893
12894         /* Read the ext_phy_type for arbitrary port(0) */
12895         for (phy_index = ELINK_EXT_PHY1; phy_index < ELINK_MAX_PHYS;
12896              phy_index++) {
12897                 ext_phy_config = elink_get_ext_phy_config(sc,
12898                                                           shmem_base_path[0],
12899                                                           phy_index, 0);
12900                 ext_phy_type = ELINK_XGXS_EXT_PHY_TYPE(ext_phy_config);
12901                 rc |= elink_ext_phy_common_init(sc, shmem_base_path,
12902                                                 shmem2_base_path,
12903                                                 phy_index, ext_phy_type,
12904                                                 chip_id);
12905         }
12906         return rc;
12907 }
12908
12909 static void elink_check_over_curr(struct elink_params *params,
12910                                   struct elink_vars *vars)
12911 {
12912         struct bnx2x_softc *sc = params->sc;
12913         uint32_t cfg_pin;
12914         uint8_t port = params->port;
12915         uint32_t pin_val;
12916
12917         cfg_pin = (REG_RD(sc, params->shmem_base +
12918                           offsetof(struct shmem_region,
12919                                    dev_info.port_hw_config[port].
12920                                    e3_cmn_pin_cfg1)) &
12921                    PORT_HW_CFG_E3_OVER_CURRENT_MASK) >>
12922             PORT_HW_CFG_E3_OVER_CURRENT_SHIFT;
12923
12924         /* Ignore check if no external input PIN available */
12925         if (elink_get_cfg_pin(sc, cfg_pin, &pin_val) != ELINK_STATUS_OK)
12926                 return;
12927
12928         if (!pin_val) {
12929                 if ((vars->phy_flags & PHY_OVER_CURRENT_FLAG) == 0) {
12930                         elink_cb_event_log(sc, ELINK_LOG_ID_OVER_CURRENT, params->port);        //"Error:  Power fault on Port %d has"
12931                         //  " been detected and the power to "
12932                         //  "that SFP+ module has been removed"
12933                         //  " to prevent failure of the card."
12934                         //  " Please remove the SFP+ module and"
12935                         //  " restart the system to clear this"
12936                         //  " error.",
12937                         vars->phy_flags |= PHY_OVER_CURRENT_FLAG;
12938                         elink_warpcore_power_module(params, 0);
12939                 }
12940         } else
12941                 vars->phy_flags &= ~PHY_OVER_CURRENT_FLAG;
12942 }
12943
12944 /* Returns 0 if no change occured since last check; 1 otherwise. */
12945 static uint8_t elink_analyze_link_error(struct elink_params *params,
12946                                         struct elink_vars *vars,
12947                                         uint32_t status, uint32_t phy_flag,
12948                                         uint32_t link_flag, uint8_t notify)
12949 {
12950         struct bnx2x_softc *sc = params->sc;
12951         /* Compare new value with previous value */
12952         uint8_t led_mode;
12953         uint32_t old_status = (vars->phy_flags & phy_flag) ? 1 : 0;
12954
12955         if ((status ^ old_status) == 0)
12956                 return 0;
12957
12958         /* If values differ */
12959         switch (phy_flag) {
12960         case PHY_HALF_OPEN_CONN_FLAG:
12961                 PMD_DRV_LOG(DEBUG, "Analyze Remote Fault");
12962                 break;
12963         case PHY_SFP_TX_FAULT_FLAG:
12964                 PMD_DRV_LOG(DEBUG, "Analyze TX Fault");
12965                 break;
12966         default:
12967                 PMD_DRV_LOG(DEBUG, "Analyze UNKNOWN");
12968         }
12969         PMD_DRV_LOG(DEBUG, "Link changed:[%x %x]->%x", vars->link_up,
12970                     old_status, status);
12971
12972         /* a. Update shmem->link_status accordingly
12973          * b. Update elink_vars->link_up
12974          */
12975         if (status) {
12976                 vars->link_status &= ~LINK_STATUS_LINK_UP;
12977                 vars->link_status |= link_flag;
12978                 vars->link_up = 0;
12979                 vars->phy_flags |= phy_flag;
12980
12981                 /* activate nig drain */
12982                 REG_WR(sc, NIG_REG_EGRESS_DRAIN0_MODE + params->port * 4, 1);
12983                 /* Set LED mode to off since the PHY doesn't know about these
12984                  * errors
12985                  */
12986                 led_mode = ELINK_LED_MODE_OFF;
12987         } else {
12988                 vars->link_status |= LINK_STATUS_LINK_UP;
12989                 vars->link_status &= ~link_flag;
12990                 vars->link_up = 1;
12991                 vars->phy_flags &= ~phy_flag;
12992                 led_mode = ELINK_LED_MODE_OPER;
12993
12994                 /* Clear nig drain */
12995                 REG_WR(sc, NIG_REG_EGRESS_DRAIN0_MODE + params->port * 4, 0);
12996         }
12997         elink_sync_link(params, vars);
12998         /* Update the LED according to the link state */
12999         elink_set_led(params, vars, led_mode, ELINK_SPEED_10000);
13000
13001         /* Update link status in the shared memory */
13002         elink_update_mng(params, vars->link_status);
13003
13004         /* C. Trigger General Attention */
13005         vars->periodic_flags |= ELINK_PERIODIC_FLAGS_LINK_EVENT;
13006         if (notify)
13007                 elink_cb_notify_link_changed(sc);
13008
13009         return 1;
13010 }
13011
13012 /******************************************************************************
13013 * Description:
13014 *       This function checks for half opened connection change indication.
13015 *       When such change occurs, it calls the elink_analyze_link_error
13016 *       to check if Remote Fault is set or cleared. Reception of remote fault
13017 *       status message in the MAC indicates that the peer's MAC has detected
13018 *       a fault, for example, due to break in the TX side of fiber.
13019 *
13020 ******************************************************************************/
13021 static elink_status_t elink_check_half_open_conn(struct elink_params *params,
13022                                                  struct elink_vars *vars,
13023                                                  uint8_t notify)
13024 {
13025         struct bnx2x_softc *sc = params->sc;
13026         uint32_t lss_status = 0;
13027         uint32_t mac_base;
13028         /* In case link status is physically up @ 10G do */
13029         if (((vars->phy_flags & PHY_PHYSICAL_LINK_FLAG) == 0) ||
13030             (REG_RD(sc, NIG_REG_EGRESS_EMAC0_PORT + params->port * 4)))
13031                 return ELINK_STATUS_OK;
13032
13033         if (CHIP_IS_E3(sc) &&
13034             (REG_RD(sc, MISC_REG_RESET_REG_2) &
13035              (MISC_REGISTERS_RESET_REG_2_XMAC))) {
13036                 /* Check E3 XMAC */
13037                 /* Note that link speed cannot be queried here, since it may be
13038                  * zero while link is down. In case UMAC is active, LSS will
13039                  * simply not be set
13040                  */
13041                 mac_base = (params->port) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
13042
13043                 /* Clear stick bits (Requires rising edge) */
13044                 REG_WR(sc, mac_base + XMAC_REG_CLEAR_RX_LSS_STATUS, 0);
13045                 REG_WR(sc, mac_base + XMAC_REG_CLEAR_RX_LSS_STATUS,
13046                        XMAC_CLEAR_RX_LSS_STATUS_REG_CLEAR_LOCAL_FAULT_STATUS |
13047                        XMAC_CLEAR_RX_LSS_STATUS_REG_CLEAR_REMOTE_FAULT_STATUS);
13048                 if (REG_RD(sc, mac_base + XMAC_REG_RX_LSS_STATUS))
13049                         lss_status = 1;
13050
13051                 elink_analyze_link_error(params, vars, lss_status,
13052                                          PHY_HALF_OPEN_CONN_FLAG,
13053                                          LINK_STATUS_NONE, notify);
13054         } else if (REG_RD(sc, MISC_REG_RESET_REG_2) &
13055                    (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << params->port)) {
13056                 /* Check E1X / E2 BMAC */
13057                 uint32_t lss_status_reg;
13058                 uint32_t wb_data[2];
13059                 mac_base = params->port ? NIG_REG_INGRESS_BMAC1_MEM :
13060                     NIG_REG_INGRESS_BMAC0_MEM;
13061                 /*  Read BIGMAC_REGISTER_RX_LSS_STATUS */
13062                 if (CHIP_IS_E2(sc))
13063                         lss_status_reg = BIGMAC2_REGISTER_RX_LSS_STAT;
13064                 else
13065                         lss_status_reg = BIGMAC_REGISTER_RX_LSS_STATUS;
13066
13067                 REG_RD_DMAE(sc, mac_base + lss_status_reg, wb_data, 2);
13068                 lss_status = (wb_data[0] > 0);
13069
13070                 elink_analyze_link_error(params, vars, lss_status,
13071                                          PHY_HALF_OPEN_CONN_FLAG,
13072                                          LINK_STATUS_NONE, notify);
13073         }
13074         return ELINK_STATUS_OK;
13075 }
13076
13077 static void elink_sfp_tx_fault_detection(struct elink_phy *phy,
13078                                          struct elink_params *params,
13079                                          struct elink_vars *vars)
13080 {
13081         struct bnx2x_softc *sc = params->sc;
13082         uint32_t cfg_pin, value = 0;
13083         uint8_t led_change, port = params->port;
13084
13085         /* Get The SFP+ TX_Fault controlling pin ([eg]pio) */
13086         cfg_pin = (REG_RD(sc, params->shmem_base + offsetof(struct shmem_region,
13087                                                             dev_info.
13088                                                             port_hw_config
13089                                                             [port].
13090                                                             e3_cmn_pin_cfg)) &
13091                    PORT_HW_CFG_E3_TX_FAULT_MASK) >>
13092             PORT_HW_CFG_E3_TX_FAULT_SHIFT;
13093
13094         if (elink_get_cfg_pin(sc, cfg_pin, &value)) {
13095                 PMD_DRV_LOG(DEBUG, "Failed to read pin 0x%02x", cfg_pin);
13096                 return;
13097         }
13098
13099         led_change = elink_analyze_link_error(params, vars, value,
13100                                               PHY_SFP_TX_FAULT_FLAG,
13101                                               LINK_STATUS_SFP_TX_FAULT, 1);
13102
13103         if (led_change) {
13104                 /* Change TX_Fault led, set link status for further syncs */
13105                 uint8_t led_mode;
13106
13107                 if (vars->phy_flags & PHY_SFP_TX_FAULT_FLAG) {
13108                         led_mode = MISC_REGISTERS_GPIO_HIGH;
13109                         vars->link_status |= LINK_STATUS_SFP_TX_FAULT;
13110                 } else {
13111                         led_mode = MISC_REGISTERS_GPIO_LOW;
13112                         vars->link_status &= ~LINK_STATUS_SFP_TX_FAULT;
13113                 }
13114
13115                 /* If module is unapproved, led should be on regardless */
13116                 if (!(phy->flags & ELINK_FLAGS_SFP_NOT_APPROVED)) {
13117                         PMD_DRV_LOG(DEBUG, "Change TX_Fault LED: ->%x",
13118                                     led_mode);
13119                         elink_set_e3_module_fault_led(params, led_mode);
13120                 }
13121         }
13122 }
13123
13124 static void elink_kr2_recovery(struct elink_params *params,
13125                                struct elink_vars *vars, struct elink_phy *phy)
13126 {
13127         PMD_DRV_LOG(DEBUG, "KR2 recovery");
13128
13129         elink_warpcore_enable_AN_KR2(phy, params, vars);
13130         elink_warpcore_restart_AN_KR(phy, params);
13131 }
13132
13133 static void elink_check_kr2_wa(struct elink_params *params,
13134                                struct elink_vars *vars, struct elink_phy *phy)
13135 {
13136         struct bnx2x_softc *sc = params->sc;
13137         uint16_t base_page, next_page, not_kr2_device, lane;
13138         int sigdet;
13139
13140         /* Once KR2 was disabled, wait 5 seconds before checking KR2 recovery
13141          * Since some switches tend to reinit the AN process and clear the
13142          * the advertised BP/NP after ~2 seconds causing the KR2 to be disabled
13143          * and recovered many times
13144          */
13145         if (vars->check_kr2_recovery_cnt > 0) {
13146                 vars->check_kr2_recovery_cnt--;
13147                 return;
13148         }
13149
13150         sigdet = elink_warpcore_get_sigdet(phy, params);
13151         if (!sigdet) {
13152                 if (!(vars->link_attr_sync & LINK_ATTR_SYNC_KR2_ENABLE)) {
13153                         elink_kr2_recovery(params, vars, phy);
13154                         PMD_DRV_LOG(DEBUG, "No sigdet");
13155                 }
13156                 return;
13157         }
13158
13159         lane = elink_get_warpcore_lane(params);
13160         CL22_WR_OVER_CL45(sc, phy, MDIO_REG_BANK_AER_BLOCK,
13161                           MDIO_AER_BLOCK_AER_REG, lane);
13162         elink_cl45_read(sc, phy, MDIO_AN_DEVAD,
13163                         MDIO_AN_REG_LP_AUTO_NEG, &base_page);
13164         elink_cl45_read(sc, phy, MDIO_AN_DEVAD,
13165                         MDIO_AN_REG_LP_AUTO_NEG2, &next_page);
13166         elink_set_aer_mmd(params, phy);
13167
13168         /* CL73 has not begun yet */
13169         if (base_page == 0) {
13170                 if (!(vars->link_attr_sync & LINK_ATTR_SYNC_KR2_ENABLE)) {
13171                         elink_kr2_recovery(params, vars, phy);
13172                         PMD_DRV_LOG(DEBUG, "No BP");
13173                 }
13174                 return;
13175         }
13176
13177         /* In case NP bit is not set in the BasePage, or it is set,
13178          * but only KX is advertised, declare this link partner as non-KR2
13179          * device.
13180          */
13181         not_kr2_device = (((base_page & 0x8000) == 0) ||
13182                           (((base_page & 0x8000) &&
13183                             ((next_page & 0xe0) == 0x2))));
13184
13185         /* In case KR2 is already disabled, check if we need to re-enable it */
13186         if (!(vars->link_attr_sync & LINK_ATTR_SYNC_KR2_ENABLE)) {
13187                 if (!not_kr2_device) {
13188                         PMD_DRV_LOG(DEBUG, "BP=0x%x, NP=0x%x", base_page,
13189                                     next_page);
13190                         elink_kr2_recovery(params, vars, phy);
13191                 }
13192                 return;
13193         }
13194         /* KR2 is enabled, but not KR2 device */
13195         if (not_kr2_device) {
13196                 /* Disable KR2 on both lanes */
13197                 PMD_DRV_LOG(DEBUG, "BP=0x%x, NP=0x%x", base_page, next_page);
13198                 elink_disable_kr2(params, vars, phy);
13199                 /* Restart AN on leading lane */
13200                 elink_warpcore_restart_AN_KR(phy, params);
13201                 return;
13202         }
13203 }
13204
13205 void elink_period_func(struct elink_params *params, struct elink_vars *vars)
13206 {
13207         uint16_t phy_idx;
13208         struct bnx2x_softc *sc = params->sc;
13209         for (phy_idx = ELINK_INT_PHY; phy_idx < ELINK_MAX_PHYS; phy_idx++) {
13210                 if (params->phy[phy_idx].flags & ELINK_FLAGS_TX_ERROR_CHECK) {
13211                         elink_set_aer_mmd(params, &params->phy[phy_idx]);
13212                         if (elink_check_half_open_conn(params, vars, 1) !=
13213                             ELINK_STATUS_OK) {
13214                                 PMD_DRV_LOG(DEBUG, "Fault detection failed");
13215                         }
13216                         break;
13217                 }
13218         }
13219
13220         if (CHIP_IS_E3(sc)) {
13221                 struct elink_phy *phy = &params->phy[ELINK_INT_PHY];
13222                 elink_set_aer_mmd(params, phy);
13223                 if ((phy->supported & ELINK_SUPPORTED_20000baseKR2_Full) &&
13224                     (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_20G))
13225                         elink_check_kr2_wa(params, vars, phy);
13226                 elink_check_over_curr(params, vars);
13227                 if (vars->rx_tx_asic_rst)
13228                         elink_warpcore_config_runtime(phy, params, vars);
13229
13230                 if ((REG_RD(sc, params->shmem_base +
13231                             offsetof(struct shmem_region,
13232                                      dev_info.port_hw_config[params->port].
13233                                      default_cfg))
13234                      & PORT_HW_CFG_NET_SERDES_IF_MASK) ==
13235                     PORT_HW_CFG_NET_SERDES_IF_SFI) {
13236                         if (elink_is_sfp_module_plugged(params)) {
13237                                 elink_sfp_tx_fault_detection(phy, params, vars);
13238                         } else if (vars->link_status & LINK_STATUS_SFP_TX_FAULT) {
13239                                 /* Clean trail, interrupt corrects the leds */
13240                                 vars->link_status &= ~LINK_STATUS_SFP_TX_FAULT;
13241                                 vars->phy_flags &= ~PHY_SFP_TX_FAULT_FLAG;
13242                                 /* Update link status in the shared memory */
13243                                 elink_update_mng(params, vars->link_status);
13244                         }
13245                 }
13246         }
13247 }
13248
13249 uint8_t elink_fan_failure_det_req(struct bnx2x_softc *sc,
13250                                   uint32_t shmem_base,
13251                                   uint32_t shmem2_base, uint8_t port)
13252 {
13253         uint8_t phy_index, fan_failure_det_req = 0;
13254         struct elink_phy phy;
13255         for (phy_index = ELINK_EXT_PHY1; phy_index < ELINK_MAX_PHYS;
13256              phy_index++) {
13257                 if (elink_populate_phy(sc, phy_index, shmem_base, shmem2_base,
13258                                        port, &phy)
13259                     != ELINK_STATUS_OK) {
13260                         PMD_DRV_LOG(DEBUG, "populate phy failed");
13261                         return 0;
13262                 }
13263                 fan_failure_det_req |= (phy.flags &
13264                                         ELINK_FLAGS_FAN_FAILURE_DET_REQ);
13265         }
13266         return fan_failure_det_req;
13267 }
13268
13269 void elink_hw_reset_phy(struct elink_params *params)
13270 {
13271         uint8_t phy_index;
13272         struct bnx2x_softc *sc = params->sc;
13273         elink_update_mng(params, 0);
13274         elink_bits_dis(sc, NIG_REG_MASK_INTERRUPT_PORT0 + params->port * 4,
13275                        (ELINK_NIG_MASK_XGXS0_LINK_STATUS |
13276                         ELINK_NIG_MASK_XGXS0_LINK10G |
13277                         ELINK_NIG_MASK_SERDES0_LINK_STATUS |
13278                         ELINK_NIG_MASK_MI_INT));
13279
13280         for (phy_index = ELINK_INT_PHY; phy_index < ELINK_MAX_PHYS; phy_index++) {
13281                 if (params->phy[phy_index].hw_reset) {
13282                         params->phy[phy_index].hw_reset(&params->phy[phy_index],
13283                                                         params);
13284                         params->phy[phy_index] = phy_null;
13285                 }
13286         }
13287 }
13288
13289 void elink_init_mod_abs_int(struct bnx2x_softc *sc, struct elink_vars *vars,
13290                             __rte_unused uint32_t chip_id, uint32_t shmem_base,
13291                             uint32_t shmem2_base, uint8_t port)
13292 {
13293         uint8_t gpio_num = 0xff, gpio_port = 0xff, phy_index;
13294         uint32_t val;
13295         uint32_t offset, aeu_mask, swap_val, swap_override, sync_offset;
13296         if (CHIP_IS_E3(sc)) {
13297                 if (elink_get_mod_abs_int_cfg(sc,
13298                                               shmem_base,
13299                                               port,
13300                                               &gpio_num,
13301                                               &gpio_port) != ELINK_STATUS_OK)
13302                         return;
13303         } else {
13304                 struct elink_phy phy;
13305                 for (phy_index = ELINK_EXT_PHY1; phy_index < ELINK_MAX_PHYS;
13306                      phy_index++) {
13307                         if (elink_populate_phy(sc, phy_index, shmem_base,
13308                                                shmem2_base, port, &phy)
13309                             != ELINK_STATUS_OK) {
13310                                 PMD_DRV_LOG(DEBUG, "populate phy failed");
13311                                 return;
13312                         }
13313                         if (phy.type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BNX2X8726) {
13314                                 gpio_num = MISC_REGISTERS_GPIO_3;
13315                                 gpio_port = port;
13316                                 break;
13317                         }
13318                 }
13319         }
13320
13321         if (gpio_num == 0xff)
13322                 return;
13323
13324         /* Set GPIO3 to trigger SFP+ module insertion/removal */
13325         elink_cb_gpio_write(sc, gpio_num, MISC_REGISTERS_GPIO_INPUT_HI_Z,
13326                             gpio_port);
13327
13328         swap_val = REG_RD(sc, NIG_REG_PORT_SWAP);
13329         swap_override = REG_RD(sc, NIG_REG_STRAP_OVERRIDE);
13330         gpio_port ^= (swap_val && swap_override);
13331
13332         vars->aeu_int_mask = AEU_INPUTS_ATTN_BITS_GPIO0_FUNCTION_0 <<
13333             (gpio_num + (gpio_port << 2));
13334
13335         sync_offset = shmem_base +
13336             offsetof(struct shmem_region,
13337                      dev_info.port_hw_config[port].aeu_int_mask);
13338         REG_WR(sc, sync_offset, vars->aeu_int_mask);
13339
13340         PMD_DRV_LOG(DEBUG, "Setting MOD_ABS (GPIO%d_P%d) AEU to 0x%x",
13341                     gpio_num, gpio_port, vars->aeu_int_mask);
13342
13343         if (port == 0)
13344                 offset = MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0;
13345         else
13346                 offset = MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0;
13347
13348         /* Open appropriate AEU for interrupts */
13349         aeu_mask = REG_RD(sc, offset);
13350         aeu_mask |= vars->aeu_int_mask;
13351         REG_WR(sc, offset, aeu_mask);
13352
13353         /* Enable the GPIO to trigger interrupt */
13354         val = REG_RD(sc, MISC_REG_GPIO_EVENT_EN);
13355         val |= 1 << (gpio_num + (gpio_port << 2));
13356         REG_WR(sc, MISC_REG_GPIO_EVENT_EN, val);
13357 }