2 * AMD 10Gb Ethernet driver
4 * This file is available to you under your choice of the following two
9 * Copyright (c) 2014-2016 Advanced Micro Devices, Inc.
11 * This file is free software; you may copy, redistribute and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 2 of the License, or (at
14 * your option) any later version.
16 * This file is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * This file incorporates work covered by the following copyright and
26 * The Synopsys DWC ETHER XGMAC Software Driver and documentation
27 * (hereinafter "Software") is an unsupported proprietary work of Synopsys,
28 * Inc. unless otherwise expressly agreed to in writing between Synopsys
31 * The Software IS NOT an item of Licensed Software or Licensed Product
32 * under any End User Software License Agreement or Agreement for Licensed
33 * Product with Synopsys or any supplement thereto. Permission is hereby
34 * granted, free of charge, to any person obtaining a copy of this software
35 * annotated with this license and the Software, to deal in the Software
36 * without restriction, including without limitation the rights to use,
37 * copy, modify, merge, publish, distribute, sublicense, and/or sell copies
38 * of the Software, and to permit persons to whom the Software is furnished
39 * to do so, subject to the following conditions:
41 * The above copyright notice and this permission notice shall be included
42 * in all copies or substantial portions of the Software.
44 * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
45 * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
46 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
47 * PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS
48 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
49 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
50 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
51 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
52 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
53 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
54 * THE POSSIBILITY OF SUCH DAMAGE.
57 * License 2: Modified BSD
59 * Copyright (c) 2014-2016 Advanced Micro Devices, Inc.
60 * All rights reserved.
62 * Redistribution and use in source and binary forms, with or without
63 * modification, are permitted provided that the following conditions are met:
64 * * Redistributions of source code must retain the above copyright
65 * notice, this list of conditions and the following disclaimer.
66 * * Redistributions in binary form must reproduce the above copyright
67 * notice, this list of conditions and the following disclaimer in the
68 * documentation and/or other materials provided with the distribution.
69 * * Neither the name of Advanced Micro Devices, Inc. nor the
70 * names of its contributors may be used to endorse or promote products
71 * derived from this software without specific prior written permission.
73 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
74 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
75 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
76 * ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
77 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
78 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
79 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
80 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
81 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
82 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
84 * This file incorporates work covered by the following copyright and
86 * The Synopsys DWC ETHER XGMAC Software Driver and documentation
87 * (hereinafter "Software") is an unsupported proprietary work of Synopsys,
88 * Inc. unless otherwise expressly agreed to in writing between Synopsys
91 * The Software IS NOT an item of Licensed Software or Licensed Product
92 * under any End User Software License Agreement or Agreement for Licensed
93 * Product with Synopsys or any supplement thereto. Permission is hereby
94 * granted, free of charge, to any person obtaining a copy of this software
95 * annotated with this license and the Software, to deal in the Software
96 * without restriction, including without limitation the rights to use,
97 * copy, modify, merge, publish, distribute, sublicense, and/or sell copies
98 * of the Software, and to permit persons to whom the Software is furnished
99 * to do so, subject to the following conditions:
101 * The above copyright notice and this permission notice shall be included
102 * in all copies or substantial portions of the Software.
104 * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
105 * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
106 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
107 * PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS
108 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
109 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
110 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
111 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
112 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
113 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
114 * THE POSSIBILITY OF SUCH DAMAGE.
117 #include <linux/interrupt.h>
118 #include <linux/module.h>
119 #include <linux/kmod.h>
120 #include <linux/mdio.h>
121 #include <linux/phy.h>
122 #include <linux/of.h>
123 #include <linux/bitops.h>
124 #include <linux/jiffies.h>
127 #include "xgbe-common.h"
129 static int xgbe_phy_module_eeprom(struct xgbe_prv_data
*pdata
,
130 struct ethtool_eeprom
*eeprom
, u8
*data
)
132 if (!pdata
->phy_if
.phy_impl
.module_eeprom
)
135 return pdata
->phy_if
.phy_impl
.module_eeprom(pdata
, eeprom
, data
);
138 static int xgbe_phy_module_info(struct xgbe_prv_data
*pdata
,
139 struct ethtool_modinfo
*modinfo
)
141 if (!pdata
->phy_if
.phy_impl
.module_info
)
144 return pdata
->phy_if
.phy_impl
.module_info(pdata
, modinfo
);
147 static void xgbe_an37_clear_interrupts(struct xgbe_prv_data
*pdata
)
151 reg
= XMDIO_READ(pdata
, MDIO_MMD_VEND2
, MDIO_VEND2_AN_STAT
);
152 reg
&= ~XGBE_AN_CL37_INT_MASK
;
153 XMDIO_WRITE(pdata
, MDIO_MMD_VEND2
, MDIO_VEND2_AN_STAT
, reg
);
156 static void xgbe_an37_disable_interrupts(struct xgbe_prv_data
*pdata
)
160 reg
= XMDIO_READ(pdata
, MDIO_MMD_VEND2
, MDIO_VEND2_AN_CTRL
);
161 reg
&= ~XGBE_AN_CL37_INT_MASK
;
162 XMDIO_WRITE(pdata
, MDIO_MMD_VEND2
, MDIO_VEND2_AN_CTRL
, reg
);
164 reg
= XMDIO_READ(pdata
, MDIO_MMD_PCS
, MDIO_PCS_DIG_CTRL
);
165 reg
&= ~XGBE_PCS_CL37_BP
;
166 XMDIO_WRITE(pdata
, MDIO_MMD_PCS
, MDIO_PCS_DIG_CTRL
, reg
);
169 static void xgbe_an37_enable_interrupts(struct xgbe_prv_data
*pdata
)
173 reg
= XMDIO_READ(pdata
, MDIO_MMD_PCS
, MDIO_PCS_DIG_CTRL
);
174 reg
|= XGBE_PCS_CL37_BP
;
175 XMDIO_WRITE(pdata
, MDIO_MMD_PCS
, MDIO_PCS_DIG_CTRL
, reg
);
177 reg
= XMDIO_READ(pdata
, MDIO_MMD_VEND2
, MDIO_VEND2_AN_CTRL
);
178 reg
|= XGBE_AN_CL37_INT_MASK
;
179 XMDIO_WRITE(pdata
, MDIO_MMD_VEND2
, MDIO_VEND2_AN_CTRL
, reg
);
182 static void xgbe_an73_clear_interrupts(struct xgbe_prv_data
*pdata
)
184 XMDIO_WRITE(pdata
, MDIO_MMD_AN
, MDIO_AN_INT
, 0);
187 static void xgbe_an73_disable_interrupts(struct xgbe_prv_data
*pdata
)
189 XMDIO_WRITE(pdata
, MDIO_MMD_AN
, MDIO_AN_INTMASK
, 0);
192 static void xgbe_an73_enable_interrupts(struct xgbe_prv_data
*pdata
)
194 XMDIO_WRITE(pdata
, MDIO_MMD_AN
, MDIO_AN_INTMASK
, XGBE_AN_CL73_INT_MASK
);
197 static void xgbe_an_enable_interrupts(struct xgbe_prv_data
*pdata
)
199 switch (pdata
->an_mode
) {
200 case XGBE_AN_MODE_CL73
:
201 case XGBE_AN_MODE_CL73_REDRV
:
202 xgbe_an73_enable_interrupts(pdata
);
204 case XGBE_AN_MODE_CL37
:
205 case XGBE_AN_MODE_CL37_SGMII
:
206 xgbe_an37_enable_interrupts(pdata
);
213 static void xgbe_an_clear_interrupts_all(struct xgbe_prv_data
*pdata
)
215 xgbe_an73_clear_interrupts(pdata
);
216 xgbe_an37_clear_interrupts(pdata
);
219 static void xgbe_kr_mode(struct xgbe_prv_data
*pdata
)
221 /* Set MAC to 10G speed */
222 pdata
->hw_if
.set_speed(pdata
, SPEED_10000
);
224 /* Call PHY implementation support to complete rate change */
225 pdata
->phy_if
.phy_impl
.set_mode(pdata
, XGBE_MODE_KR
);
228 static void xgbe_kx_2500_mode(struct xgbe_prv_data
*pdata
)
230 /* Set MAC to 2.5G speed */
231 pdata
->hw_if
.set_speed(pdata
, SPEED_2500
);
233 /* Call PHY implementation support to complete rate change */
234 pdata
->phy_if
.phy_impl
.set_mode(pdata
, XGBE_MODE_KX_2500
);
237 static void xgbe_kx_1000_mode(struct xgbe_prv_data
*pdata
)
239 /* Set MAC to 1G speed */
240 pdata
->hw_if
.set_speed(pdata
, SPEED_1000
);
242 /* Call PHY implementation support to complete rate change */
243 pdata
->phy_if
.phy_impl
.set_mode(pdata
, XGBE_MODE_KX_1000
);
246 static void xgbe_sfi_mode(struct xgbe_prv_data
*pdata
)
248 /* If a KR re-driver is present, change to KR mode instead */
250 return xgbe_kr_mode(pdata
);
252 /* Set MAC to 10G speed */
253 pdata
->hw_if
.set_speed(pdata
, SPEED_10000
);
255 /* Call PHY implementation support to complete rate change */
256 pdata
->phy_if
.phy_impl
.set_mode(pdata
, XGBE_MODE_SFI
);
259 static void xgbe_x_mode(struct xgbe_prv_data
*pdata
)
261 /* Set MAC to 1G speed */
262 pdata
->hw_if
.set_speed(pdata
, SPEED_1000
);
264 /* Call PHY implementation support to complete rate change */
265 pdata
->phy_if
.phy_impl
.set_mode(pdata
, XGBE_MODE_X
);
268 static void xgbe_sgmii_1000_mode(struct xgbe_prv_data
*pdata
)
270 /* Set MAC to 1G speed */
271 pdata
->hw_if
.set_speed(pdata
, SPEED_1000
);
273 /* Call PHY implementation support to complete rate change */
274 pdata
->phy_if
.phy_impl
.set_mode(pdata
, XGBE_MODE_SGMII_1000
);
277 static void xgbe_sgmii_100_mode(struct xgbe_prv_data
*pdata
)
279 /* Set MAC to 1G speed */
280 pdata
->hw_if
.set_speed(pdata
, SPEED_1000
);
282 /* Call PHY implementation support to complete rate change */
283 pdata
->phy_if
.phy_impl
.set_mode(pdata
, XGBE_MODE_SGMII_100
);
286 static enum xgbe_mode
xgbe_cur_mode(struct xgbe_prv_data
*pdata
)
288 return pdata
->phy_if
.phy_impl
.cur_mode(pdata
);
291 static bool xgbe_in_kr_mode(struct xgbe_prv_data
*pdata
)
293 return (xgbe_cur_mode(pdata
) == XGBE_MODE_KR
);
296 static void xgbe_change_mode(struct xgbe_prv_data
*pdata
,
300 case XGBE_MODE_KX_1000
:
301 xgbe_kx_1000_mode(pdata
);
303 case XGBE_MODE_KX_2500
:
304 xgbe_kx_2500_mode(pdata
);
309 case XGBE_MODE_SGMII_100
:
310 xgbe_sgmii_100_mode(pdata
);
312 case XGBE_MODE_SGMII_1000
:
313 xgbe_sgmii_1000_mode(pdata
);
319 xgbe_sfi_mode(pdata
);
321 case XGBE_MODE_UNKNOWN
:
324 netif_dbg(pdata
, link
, pdata
->netdev
,
325 "invalid operation mode requested (%u)\n", mode
);
329 static void xgbe_switch_mode(struct xgbe_prv_data
*pdata
)
331 xgbe_change_mode(pdata
, pdata
->phy_if
.phy_impl
.switch_mode(pdata
));
334 static bool xgbe_set_mode(struct xgbe_prv_data
*pdata
,
337 if (mode
== xgbe_cur_mode(pdata
))
340 xgbe_change_mode(pdata
, mode
);
345 static bool xgbe_use_mode(struct xgbe_prv_data
*pdata
,
348 return pdata
->phy_if
.phy_impl
.use_mode(pdata
, mode
);
351 static void xgbe_an37_set(struct xgbe_prv_data
*pdata
, bool enable
,
356 reg
= XMDIO_READ(pdata
, MDIO_MMD_VEND2
, MDIO_CTRL1
);
357 reg
&= ~MDIO_VEND2_CTRL1_AN_ENABLE
;
360 reg
|= MDIO_VEND2_CTRL1_AN_ENABLE
;
363 reg
|= MDIO_VEND2_CTRL1_AN_RESTART
;
365 XMDIO_WRITE(pdata
, MDIO_MMD_VEND2
, MDIO_CTRL1
, reg
);
368 static void xgbe_an37_restart(struct xgbe_prv_data
*pdata
)
370 xgbe_an37_enable_interrupts(pdata
);
371 xgbe_an37_set(pdata
, true, true);
373 netif_dbg(pdata
, link
, pdata
->netdev
, "CL37 AN enabled/restarted\n");
376 static void xgbe_an37_disable(struct xgbe_prv_data
*pdata
)
378 xgbe_an37_set(pdata
, false, false);
379 xgbe_an37_disable_interrupts(pdata
);
381 netif_dbg(pdata
, link
, pdata
->netdev
, "CL37 AN disabled\n");
384 static void xgbe_an73_set(struct xgbe_prv_data
*pdata
, bool enable
,
389 /* Disable KR training for now */
390 reg
= XMDIO_READ(pdata
, MDIO_MMD_PMAPMD
, MDIO_PMA_10GBR_PMD_CTRL
);
391 reg
&= ~XGBE_KR_TRAINING_ENABLE
;
392 XMDIO_WRITE(pdata
, MDIO_MMD_PMAPMD
, MDIO_PMA_10GBR_PMD_CTRL
, reg
);
394 /* Update AN settings */
395 reg
= XMDIO_READ(pdata
, MDIO_MMD_AN
, MDIO_CTRL1
);
396 reg
&= ~MDIO_AN_CTRL1_ENABLE
;
399 reg
|= MDIO_AN_CTRL1_ENABLE
;
402 reg
|= MDIO_AN_CTRL1_RESTART
;
404 XMDIO_WRITE(pdata
, MDIO_MMD_AN
, MDIO_CTRL1
, reg
);
407 static void xgbe_an73_restart(struct xgbe_prv_data
*pdata
)
409 xgbe_an73_enable_interrupts(pdata
);
410 xgbe_an73_set(pdata
, true, true);
412 netif_dbg(pdata
, link
, pdata
->netdev
, "CL73 AN enabled/restarted\n");
415 static void xgbe_an73_disable(struct xgbe_prv_data
*pdata
)
417 xgbe_an73_set(pdata
, false, false);
418 xgbe_an73_disable_interrupts(pdata
);
422 netif_dbg(pdata
, link
, pdata
->netdev
, "CL73 AN disabled\n");
425 static void xgbe_an_restart(struct xgbe_prv_data
*pdata
)
427 if (pdata
->phy_if
.phy_impl
.an_pre
)
428 pdata
->phy_if
.phy_impl
.an_pre(pdata
);
430 switch (pdata
->an_mode
) {
431 case XGBE_AN_MODE_CL73
:
432 case XGBE_AN_MODE_CL73_REDRV
:
433 xgbe_an73_restart(pdata
);
435 case XGBE_AN_MODE_CL37
:
436 case XGBE_AN_MODE_CL37_SGMII
:
437 xgbe_an37_restart(pdata
);
444 static void xgbe_an_disable(struct xgbe_prv_data
*pdata
)
446 if (pdata
->phy_if
.phy_impl
.an_post
)
447 pdata
->phy_if
.phy_impl
.an_post(pdata
);
449 switch (pdata
->an_mode
) {
450 case XGBE_AN_MODE_CL73
:
451 case XGBE_AN_MODE_CL73_REDRV
:
452 xgbe_an73_disable(pdata
);
454 case XGBE_AN_MODE_CL37
:
455 case XGBE_AN_MODE_CL37_SGMII
:
456 xgbe_an37_disable(pdata
);
463 static void xgbe_an_disable_all(struct xgbe_prv_data
*pdata
)
465 xgbe_an73_disable(pdata
);
466 xgbe_an37_disable(pdata
);
469 static enum xgbe_an
xgbe_an73_tx_training(struct xgbe_prv_data
*pdata
,
472 unsigned int ad_reg
, lp_reg
, reg
;
474 *state
= XGBE_RX_COMPLETE
;
476 /* If we're not in KR mode then we're done */
477 if (!xgbe_in_kr_mode(pdata
))
478 return XGBE_AN_PAGE_RECEIVED
;
480 /* Enable/Disable FEC */
481 ad_reg
= XMDIO_READ(pdata
, MDIO_MMD_AN
, MDIO_AN_ADVERTISE
+ 2);
482 lp_reg
= XMDIO_READ(pdata
, MDIO_MMD_AN
, MDIO_AN_LPA
+ 2);
484 reg
= XMDIO_READ(pdata
, MDIO_MMD_PMAPMD
, MDIO_PMA_10GBR_FECCTRL
);
485 reg
&= ~(MDIO_PMA_10GBR_FECABLE_ABLE
| MDIO_PMA_10GBR_FECABLE_ERRABLE
);
486 if ((ad_reg
& 0xc000) && (lp_reg
& 0xc000))
487 reg
|= pdata
->fec_ability
;
489 XMDIO_WRITE(pdata
, MDIO_MMD_PMAPMD
, MDIO_PMA_10GBR_FECCTRL
, reg
);
491 /* Start KR training */
492 if (pdata
->phy_if
.phy_impl
.kr_training_pre
)
493 pdata
->phy_if
.phy_impl
.kr_training_pre(pdata
);
495 reg
= XMDIO_READ(pdata
, MDIO_MMD_PMAPMD
, MDIO_PMA_10GBR_PMD_CTRL
);
496 reg
|= XGBE_KR_TRAINING_ENABLE
;
497 reg
|= XGBE_KR_TRAINING_START
;
498 XMDIO_WRITE(pdata
, MDIO_MMD_PMAPMD
, MDIO_PMA_10GBR_PMD_CTRL
, reg
);
500 netif_dbg(pdata
, link
, pdata
->netdev
,
501 "KR training initiated\n");
503 if (pdata
->phy_if
.phy_impl
.kr_training_post
)
504 pdata
->phy_if
.phy_impl
.kr_training_post(pdata
);
506 return XGBE_AN_PAGE_RECEIVED
;
509 static enum xgbe_an
xgbe_an73_tx_xnp(struct xgbe_prv_data
*pdata
,
514 *state
= XGBE_RX_XNP
;
516 msg
= XGBE_XNP_MCF_NULL_MESSAGE
;
517 msg
|= XGBE_XNP_MP_FORMATTED
;
519 XMDIO_WRITE(pdata
, MDIO_MMD_AN
, MDIO_AN_XNP
+ 2, 0);
520 XMDIO_WRITE(pdata
, MDIO_MMD_AN
, MDIO_AN_XNP
+ 1, 0);
521 XMDIO_WRITE(pdata
, MDIO_MMD_AN
, MDIO_AN_XNP
, msg
);
523 return XGBE_AN_PAGE_RECEIVED
;
526 static enum xgbe_an
xgbe_an73_rx_bpa(struct xgbe_prv_data
*pdata
,
529 unsigned int link_support
;
530 unsigned int reg
, ad_reg
, lp_reg
;
532 /* Read Base Ability register 2 first */
533 reg
= XMDIO_READ(pdata
, MDIO_MMD_AN
, MDIO_AN_LPA
+ 1);
535 /* Check for a supported mode, otherwise restart in a different one */
536 link_support
= xgbe_in_kr_mode(pdata
) ? 0x80 : 0x20;
537 if (!(reg
& link_support
))
538 return XGBE_AN_INCOMPAT_LINK
;
540 /* Check Extended Next Page support */
541 ad_reg
= XMDIO_READ(pdata
, MDIO_MMD_AN
, MDIO_AN_ADVERTISE
);
542 lp_reg
= XMDIO_READ(pdata
, MDIO_MMD_AN
, MDIO_AN_LPA
);
544 return ((ad_reg
& XGBE_XNP_NP_EXCHANGE
) ||
545 (lp_reg
& XGBE_XNP_NP_EXCHANGE
))
546 ? xgbe_an73_tx_xnp(pdata
, state
)
547 : xgbe_an73_tx_training(pdata
, state
);
550 static enum xgbe_an
xgbe_an73_rx_xnp(struct xgbe_prv_data
*pdata
,
553 unsigned int ad_reg
, lp_reg
;
555 /* Check Extended Next Page support */
556 ad_reg
= XMDIO_READ(pdata
, MDIO_MMD_AN
, MDIO_AN_XNP
);
557 lp_reg
= XMDIO_READ(pdata
, MDIO_MMD_AN
, MDIO_AN_LPX
);
559 return ((ad_reg
& XGBE_XNP_NP_EXCHANGE
) ||
560 (lp_reg
& XGBE_XNP_NP_EXCHANGE
))
561 ? xgbe_an73_tx_xnp(pdata
, state
)
562 : xgbe_an73_tx_training(pdata
, state
);
565 static enum xgbe_an
xgbe_an73_page_received(struct xgbe_prv_data
*pdata
)
568 unsigned long an_timeout
;
571 if (!pdata
->an_start
) {
572 pdata
->an_start
= jiffies
;
574 an_timeout
= pdata
->an_start
+
575 msecs_to_jiffies(XGBE_AN_MS_TIMEOUT
);
576 if (time_after(jiffies
, an_timeout
)) {
577 /* Auto-negotiation timed out, reset state */
578 pdata
->kr_state
= XGBE_RX_BPA
;
579 pdata
->kx_state
= XGBE_RX_BPA
;
581 pdata
->an_start
= jiffies
;
583 netif_dbg(pdata
, link
, pdata
->netdev
,
584 "CL73 AN timed out, resetting state\n");
588 state
= xgbe_in_kr_mode(pdata
) ? &pdata
->kr_state
593 ret
= xgbe_an73_rx_bpa(pdata
, state
);
597 ret
= xgbe_an73_rx_xnp(pdata
, state
);
607 static enum xgbe_an
xgbe_an73_incompat_link(struct xgbe_prv_data
*pdata
)
609 struct ethtool_link_ksettings
*lks
= &pdata
->phy
.lks
;
611 /* Be sure we aren't looping trying to negotiate */
612 if (xgbe_in_kr_mode(pdata
)) {
613 pdata
->kr_state
= XGBE_RX_ERROR
;
615 if (!XGBE_ADV(lks
, 1000baseKX_Full
) &&
616 !XGBE_ADV(lks
, 2500baseX_Full
))
617 return XGBE_AN_NO_LINK
;
619 if (pdata
->kx_state
!= XGBE_RX_BPA
)
620 return XGBE_AN_NO_LINK
;
622 pdata
->kx_state
= XGBE_RX_ERROR
;
624 if (!XGBE_ADV(lks
, 10000baseKR_Full
))
625 return XGBE_AN_NO_LINK
;
627 if (pdata
->kr_state
!= XGBE_RX_BPA
)
628 return XGBE_AN_NO_LINK
;
631 xgbe_an_disable(pdata
);
633 xgbe_switch_mode(pdata
);
635 xgbe_an_restart(pdata
);
637 return XGBE_AN_INCOMPAT_LINK
;
640 static void xgbe_an37_isr(struct xgbe_prv_data
*pdata
)
644 /* Disable AN interrupts */
645 xgbe_an37_disable_interrupts(pdata
);
647 /* Save the interrupt(s) that fired */
648 reg
= XMDIO_READ(pdata
, MDIO_MMD_VEND2
, MDIO_VEND2_AN_STAT
);
649 pdata
->an_int
= reg
& XGBE_AN_CL37_INT_MASK
;
650 pdata
->an_status
= reg
& ~XGBE_AN_CL37_INT_MASK
;
653 /* Clear the interrupt(s) that fired and process them */
654 reg
&= ~XGBE_AN_CL37_INT_MASK
;
655 XMDIO_WRITE(pdata
, MDIO_MMD_VEND2
, MDIO_VEND2_AN_STAT
, reg
);
657 queue_work(pdata
->an_workqueue
, &pdata
->an_irq_work
);
659 /* Enable AN interrupts */
660 xgbe_an37_enable_interrupts(pdata
);
662 /* Reissue interrupt if status is not clear */
663 if (pdata
->vdata
->irq_reissue_support
)
664 XP_IOWRITE(pdata
, XP_INT_REISSUE_EN
, 1 << 3);
668 static void xgbe_an73_isr(struct xgbe_prv_data
*pdata
)
670 /* Disable AN interrupts */
671 xgbe_an73_disable_interrupts(pdata
);
673 /* Save the interrupt(s) that fired */
674 pdata
->an_int
= XMDIO_READ(pdata
, MDIO_MMD_AN
, MDIO_AN_INT
);
677 /* Clear the interrupt(s) that fired and process them */
678 XMDIO_WRITE(pdata
, MDIO_MMD_AN
, MDIO_AN_INT
, ~pdata
->an_int
);
680 queue_work(pdata
->an_workqueue
, &pdata
->an_irq_work
);
682 /* Enable AN interrupts */
683 xgbe_an73_enable_interrupts(pdata
);
685 /* Reissue interrupt if status is not clear */
686 if (pdata
->vdata
->irq_reissue_support
)
687 XP_IOWRITE(pdata
, XP_INT_REISSUE_EN
, 1 << 3);
691 static void xgbe_an_isr_task(unsigned long data
)
693 struct xgbe_prv_data
*pdata
= (struct xgbe_prv_data
*)data
;
695 netif_dbg(pdata
, intr
, pdata
->netdev
, "AN interrupt received\n");
697 switch (pdata
->an_mode
) {
698 case XGBE_AN_MODE_CL73
:
699 case XGBE_AN_MODE_CL73_REDRV
:
700 xgbe_an73_isr(pdata
);
702 case XGBE_AN_MODE_CL37
:
703 case XGBE_AN_MODE_CL37_SGMII
:
704 xgbe_an37_isr(pdata
);
711 static irqreturn_t
xgbe_an_isr(int irq
, void *data
)
713 struct xgbe_prv_data
*pdata
= (struct xgbe_prv_data
*)data
;
715 if (pdata
->isr_as_tasklet
)
716 tasklet_schedule(&pdata
->tasklet_an
);
718 xgbe_an_isr_task((unsigned long)pdata
);
723 static irqreturn_t
xgbe_an_combined_isr(struct xgbe_prv_data
*pdata
)
725 xgbe_an_isr_task((unsigned long)pdata
);
730 static void xgbe_an_irq_work(struct work_struct
*work
)
732 struct xgbe_prv_data
*pdata
= container_of(work
,
733 struct xgbe_prv_data
,
736 /* Avoid a race between enabling the IRQ and exiting the work by
737 * waiting for the work to finish and then queueing it
739 flush_work(&pdata
->an_work
);
740 queue_work(pdata
->an_workqueue
, &pdata
->an_work
);
743 static const char *xgbe_state_as_string(enum xgbe_an state
)
748 case XGBE_AN_PAGE_RECEIVED
:
749 return "Page-Received";
750 case XGBE_AN_INCOMPAT_LINK
:
751 return "Incompatible-Link";
752 case XGBE_AN_COMPLETE
:
754 case XGBE_AN_NO_LINK
:
763 static void xgbe_an37_state_machine(struct xgbe_prv_data
*pdata
)
765 enum xgbe_an cur_state
= pdata
->an_state
;
770 if (pdata
->an_int
& XGBE_AN_CL37_INT_CMPLT
) {
771 pdata
->an_state
= XGBE_AN_COMPLETE
;
772 pdata
->an_int
&= ~XGBE_AN_CL37_INT_CMPLT
;
774 /* If SGMII is enabled, check the link status */
775 if ((pdata
->an_mode
== XGBE_AN_MODE_CL37_SGMII
) &&
776 !(pdata
->an_status
& XGBE_SGMII_AN_LINK_STATUS
))
777 pdata
->an_state
= XGBE_AN_NO_LINK
;
780 netif_dbg(pdata
, link
, pdata
->netdev
, "CL37 AN %s\n",
781 xgbe_state_as_string(pdata
->an_state
));
783 cur_state
= pdata
->an_state
;
785 switch (pdata
->an_state
) {
789 case XGBE_AN_COMPLETE
:
790 netif_dbg(pdata
, link
, pdata
->netdev
,
791 "Auto negotiation successful\n");
794 case XGBE_AN_NO_LINK
:
798 pdata
->an_state
= XGBE_AN_ERROR
;
801 if (pdata
->an_state
== XGBE_AN_ERROR
) {
802 netdev_err(pdata
->netdev
,
803 "error during auto-negotiation, state=%u\n",
807 xgbe_an37_clear_interrupts(pdata
);
810 if (pdata
->an_state
>= XGBE_AN_COMPLETE
) {
811 pdata
->an_result
= pdata
->an_state
;
812 pdata
->an_state
= XGBE_AN_READY
;
814 if (pdata
->phy_if
.phy_impl
.an_post
)
815 pdata
->phy_if
.phy_impl
.an_post(pdata
);
817 netif_dbg(pdata
, link
, pdata
->netdev
, "CL37 AN result: %s\n",
818 xgbe_state_as_string(pdata
->an_result
));
821 xgbe_an37_enable_interrupts(pdata
);
824 static void xgbe_an73_state_machine(struct xgbe_prv_data
*pdata
)
826 enum xgbe_an cur_state
= pdata
->an_state
;
832 if (pdata
->an_int
& XGBE_AN_CL73_PG_RCV
) {
833 pdata
->an_state
= XGBE_AN_PAGE_RECEIVED
;
834 pdata
->an_int
&= ~XGBE_AN_CL73_PG_RCV
;
835 } else if (pdata
->an_int
& XGBE_AN_CL73_INC_LINK
) {
836 pdata
->an_state
= XGBE_AN_INCOMPAT_LINK
;
837 pdata
->an_int
&= ~XGBE_AN_CL73_INC_LINK
;
838 } else if (pdata
->an_int
& XGBE_AN_CL73_INT_CMPLT
) {
839 pdata
->an_state
= XGBE_AN_COMPLETE
;
840 pdata
->an_int
&= ~XGBE_AN_CL73_INT_CMPLT
;
842 pdata
->an_state
= XGBE_AN_ERROR
;
846 netif_dbg(pdata
, link
, pdata
->netdev
, "CL73 AN %s\n",
847 xgbe_state_as_string(pdata
->an_state
));
849 cur_state
= pdata
->an_state
;
851 switch (pdata
->an_state
) {
853 pdata
->an_supported
= 0;
856 case XGBE_AN_PAGE_RECEIVED
:
857 pdata
->an_state
= xgbe_an73_page_received(pdata
);
858 pdata
->an_supported
++;
861 case XGBE_AN_INCOMPAT_LINK
:
862 pdata
->an_supported
= 0;
863 pdata
->parallel_detect
= 0;
864 pdata
->an_state
= xgbe_an73_incompat_link(pdata
);
867 case XGBE_AN_COMPLETE
:
868 pdata
->parallel_detect
= pdata
->an_supported
? 0 : 1;
869 netif_dbg(pdata
, link
, pdata
->netdev
, "%s successful\n",
870 pdata
->an_supported
? "Auto negotiation"
871 : "Parallel detection");
874 case XGBE_AN_NO_LINK
:
878 pdata
->an_state
= XGBE_AN_ERROR
;
881 if (pdata
->an_state
== XGBE_AN_NO_LINK
) {
883 xgbe_an73_clear_interrupts(pdata
);
884 } else if (pdata
->an_state
== XGBE_AN_ERROR
) {
885 netdev_err(pdata
->netdev
,
886 "error during auto-negotiation, state=%u\n",
890 xgbe_an73_clear_interrupts(pdata
);
893 if (pdata
->an_state
>= XGBE_AN_COMPLETE
) {
894 pdata
->an_result
= pdata
->an_state
;
895 pdata
->an_state
= XGBE_AN_READY
;
896 pdata
->kr_state
= XGBE_RX_BPA
;
897 pdata
->kx_state
= XGBE_RX_BPA
;
900 if (pdata
->phy_if
.phy_impl
.an_post
)
901 pdata
->phy_if
.phy_impl
.an_post(pdata
);
903 netif_dbg(pdata
, link
, pdata
->netdev
, "CL73 AN result: %s\n",
904 xgbe_state_as_string(pdata
->an_result
));
907 if (cur_state
!= pdata
->an_state
)
913 xgbe_an73_enable_interrupts(pdata
);
916 static void xgbe_an_state_machine(struct work_struct
*work
)
918 struct xgbe_prv_data
*pdata
= container_of(work
,
919 struct xgbe_prv_data
,
922 mutex_lock(&pdata
->an_mutex
);
924 switch (pdata
->an_mode
) {
925 case XGBE_AN_MODE_CL73
:
926 case XGBE_AN_MODE_CL73_REDRV
:
927 xgbe_an73_state_machine(pdata
);
929 case XGBE_AN_MODE_CL37
:
930 case XGBE_AN_MODE_CL37_SGMII
:
931 xgbe_an37_state_machine(pdata
);
937 /* Reissue interrupt if status is not clear */
938 if (pdata
->vdata
->irq_reissue_support
)
939 XP_IOWRITE(pdata
, XP_INT_REISSUE_EN
, 1 << 3);
941 mutex_unlock(&pdata
->an_mutex
);
944 static void xgbe_an37_init(struct xgbe_prv_data
*pdata
)
946 struct ethtool_link_ksettings lks
;
949 pdata
->phy_if
.phy_impl
.an_advertising(pdata
, &lks
);
951 /* Set up Advertisement register */
952 reg
= XMDIO_READ(pdata
, MDIO_MMD_VEND2
, MDIO_VEND2_AN_ADVERTISE
);
953 if (XGBE_ADV(&lks
, Pause
))
958 if (XGBE_ADV(&lks
, Asym_Pause
))
963 /* Full duplex, but not half */
964 reg
|= XGBE_AN_CL37_FD_MASK
;
965 reg
&= ~XGBE_AN_CL37_HD_MASK
;
967 XMDIO_WRITE(pdata
, MDIO_MMD_VEND2
, MDIO_VEND2_AN_ADVERTISE
, reg
);
969 /* Set up the Control register */
970 reg
= XMDIO_READ(pdata
, MDIO_MMD_VEND2
, MDIO_VEND2_AN_CTRL
);
971 reg
&= ~XGBE_AN_CL37_TX_CONFIG_MASK
;
972 reg
&= ~XGBE_AN_CL37_PCS_MODE_MASK
;
974 switch (pdata
->an_mode
) {
975 case XGBE_AN_MODE_CL37
:
976 reg
|= XGBE_AN_CL37_PCS_MODE_BASEX
;
978 case XGBE_AN_MODE_CL37_SGMII
:
979 reg
|= XGBE_AN_CL37_PCS_MODE_SGMII
;
985 reg
|= XGBE_AN_CL37_MII_CTRL_8BIT
;
987 XMDIO_WRITE(pdata
, MDIO_MMD_VEND2
, MDIO_VEND2_AN_CTRL
, reg
);
989 netif_dbg(pdata
, link
, pdata
->netdev
, "CL37 AN (%s) initialized\n",
990 (pdata
->an_mode
== XGBE_AN_MODE_CL37
) ? "BaseX" : "SGMII");
993 static void xgbe_an73_init(struct xgbe_prv_data
*pdata
)
995 struct ethtool_link_ksettings lks
;
998 pdata
->phy_if
.phy_impl
.an_advertising(pdata
, &lks
);
1000 /* Set up Advertisement register 3 first */
1001 reg
= XMDIO_READ(pdata
, MDIO_MMD_AN
, MDIO_AN_ADVERTISE
+ 2);
1002 if (XGBE_ADV(&lks
, 10000baseR_FEC
))
1007 XMDIO_WRITE(pdata
, MDIO_MMD_AN
, MDIO_AN_ADVERTISE
+ 2, reg
);
1009 /* Set up Advertisement register 2 next */
1010 reg
= XMDIO_READ(pdata
, MDIO_MMD_AN
, MDIO_AN_ADVERTISE
+ 1);
1011 if (XGBE_ADV(&lks
, 10000baseKR_Full
))
1016 if (XGBE_ADV(&lks
, 1000baseKX_Full
) ||
1017 XGBE_ADV(&lks
, 2500baseX_Full
))
1022 XMDIO_WRITE(pdata
, MDIO_MMD_AN
, MDIO_AN_ADVERTISE
+ 1, reg
);
1024 /* Set up Advertisement register 1 last */
1025 reg
= XMDIO_READ(pdata
, MDIO_MMD_AN
, MDIO_AN_ADVERTISE
);
1026 if (XGBE_ADV(&lks
, Pause
))
1031 if (XGBE_ADV(&lks
, Asym_Pause
))
1036 /* We don't intend to perform XNP */
1037 reg
&= ~XGBE_XNP_NP_EXCHANGE
;
1039 XMDIO_WRITE(pdata
, MDIO_MMD_AN
, MDIO_AN_ADVERTISE
, reg
);
1041 netif_dbg(pdata
, link
, pdata
->netdev
, "CL73 AN initialized\n");
1044 static void xgbe_an_init(struct xgbe_prv_data
*pdata
)
1046 /* Set up advertisement registers based on current settings */
1047 pdata
->an_mode
= pdata
->phy_if
.phy_impl
.an_mode(pdata
);
1048 switch (pdata
->an_mode
) {
1049 case XGBE_AN_MODE_CL73
:
1050 case XGBE_AN_MODE_CL73_REDRV
:
1051 xgbe_an73_init(pdata
);
1053 case XGBE_AN_MODE_CL37
:
1054 case XGBE_AN_MODE_CL37_SGMII
:
1055 xgbe_an37_init(pdata
);
1062 static const char *xgbe_phy_fc_string(struct xgbe_prv_data
*pdata
)
1064 if (pdata
->tx_pause
&& pdata
->rx_pause
)
1066 else if (pdata
->rx_pause
)
1068 else if (pdata
->tx_pause
)
1074 static const char *xgbe_phy_speed_string(int speed
)
1088 return "Unsupported";
1092 static void xgbe_phy_print_status(struct xgbe_prv_data
*pdata
)
1094 if (pdata
->phy
.link
)
1095 netdev_info(pdata
->netdev
,
1096 "Link is Up - %s/%s - flow control %s\n",
1097 xgbe_phy_speed_string(pdata
->phy
.speed
),
1098 pdata
->phy
.duplex
== DUPLEX_FULL
? "Full" : "Half",
1099 xgbe_phy_fc_string(pdata
));
1101 netdev_info(pdata
->netdev
, "Link is Down\n");
1104 static void xgbe_phy_adjust_link(struct xgbe_prv_data
*pdata
)
1108 if (pdata
->phy
.link
) {
1109 /* Flow control support */
1110 pdata
->pause_autoneg
= pdata
->phy
.pause_autoneg
;
1112 if (pdata
->tx_pause
!= pdata
->phy
.tx_pause
) {
1114 pdata
->tx_pause
= pdata
->phy
.tx_pause
;
1115 pdata
->hw_if
.config_tx_flow_control(pdata
);
1118 if (pdata
->rx_pause
!= pdata
->phy
.rx_pause
) {
1120 pdata
->rx_pause
= pdata
->phy
.rx_pause
;
1121 pdata
->hw_if
.config_rx_flow_control(pdata
);
1125 if (pdata
->phy_speed
!= pdata
->phy
.speed
) {
1127 pdata
->phy_speed
= pdata
->phy
.speed
;
1130 if (pdata
->phy_link
!= pdata
->phy
.link
) {
1132 pdata
->phy_link
= pdata
->phy
.link
;
1134 } else if (pdata
->phy_link
) {
1136 pdata
->phy_link
= 0;
1137 pdata
->phy_speed
= SPEED_UNKNOWN
;
1140 if (new_state
&& netif_msg_link(pdata
))
1141 xgbe_phy_print_status(pdata
);
1144 static bool xgbe_phy_valid_speed(struct xgbe_prv_data
*pdata
, int speed
)
1146 return pdata
->phy_if
.phy_impl
.valid_speed(pdata
, speed
);
1149 static int xgbe_phy_config_fixed(struct xgbe_prv_data
*pdata
)
1151 enum xgbe_mode mode
;
1153 netif_dbg(pdata
, link
, pdata
->netdev
, "fixed PHY configuration\n");
1155 /* Disable auto-negotiation */
1156 xgbe_an_disable(pdata
);
1158 /* Set specified mode for specified speed */
1159 mode
= pdata
->phy_if
.phy_impl
.get_mode(pdata
, pdata
->phy
.speed
);
1161 case XGBE_MODE_KX_1000
:
1162 case XGBE_MODE_KX_2500
:
1164 case XGBE_MODE_SGMII_100
:
1165 case XGBE_MODE_SGMII_1000
:
1169 case XGBE_MODE_UNKNOWN
:
1174 /* Validate duplex mode */
1175 if (pdata
->phy
.duplex
!= DUPLEX_FULL
)
1178 xgbe_set_mode(pdata
, mode
);
1183 static int __xgbe_phy_config_aneg(struct xgbe_prv_data
*pdata
, bool set_mode
)
1187 mutex_lock(&pdata
->an_mutex
);
1189 set_bit(XGBE_LINK_INIT
, &pdata
->dev_state
);
1190 pdata
->link_check
= jiffies
;
1192 ret
= pdata
->phy_if
.phy_impl
.an_config(pdata
);
1196 if (pdata
->phy
.autoneg
!= AUTONEG_ENABLE
) {
1197 ret
= xgbe_phy_config_fixed(pdata
);
1198 if (ret
|| !pdata
->kr_redrv
)
1201 netif_dbg(pdata
, link
, pdata
->netdev
, "AN redriver support\n");
1203 netif_dbg(pdata
, link
, pdata
->netdev
, "AN PHY configuration\n");
1206 /* Disable auto-negotiation interrupt */
1207 disable_irq(pdata
->an_irq
);
1210 /* Start auto-negotiation in a supported mode */
1211 if (xgbe_use_mode(pdata
, XGBE_MODE_KR
)) {
1212 xgbe_set_mode(pdata
, XGBE_MODE_KR
);
1213 } else if (xgbe_use_mode(pdata
, XGBE_MODE_KX_2500
)) {
1214 xgbe_set_mode(pdata
, XGBE_MODE_KX_2500
);
1215 } else if (xgbe_use_mode(pdata
, XGBE_MODE_KX_1000
)) {
1216 xgbe_set_mode(pdata
, XGBE_MODE_KX_1000
);
1217 } else if (xgbe_use_mode(pdata
, XGBE_MODE_SFI
)) {
1218 xgbe_set_mode(pdata
, XGBE_MODE_SFI
);
1219 } else if (xgbe_use_mode(pdata
, XGBE_MODE_X
)) {
1220 xgbe_set_mode(pdata
, XGBE_MODE_X
);
1221 } else if (xgbe_use_mode(pdata
, XGBE_MODE_SGMII_1000
)) {
1222 xgbe_set_mode(pdata
, XGBE_MODE_SGMII_1000
);
1223 } else if (xgbe_use_mode(pdata
, XGBE_MODE_SGMII_100
)) {
1224 xgbe_set_mode(pdata
, XGBE_MODE_SGMII_100
);
1226 enable_irq(pdata
->an_irq
);
1232 /* Disable and stop any in progress auto-negotiation */
1233 xgbe_an_disable_all(pdata
);
1235 /* Clear any auto-negotitation interrupts */
1236 xgbe_an_clear_interrupts_all(pdata
);
1238 pdata
->an_result
= XGBE_AN_READY
;
1239 pdata
->an_state
= XGBE_AN_READY
;
1240 pdata
->kr_state
= XGBE_RX_BPA
;
1241 pdata
->kx_state
= XGBE_RX_BPA
;
1243 /* Re-enable auto-negotiation interrupt */
1244 enable_irq(pdata
->an_irq
);
1246 xgbe_an_init(pdata
);
1247 xgbe_an_restart(pdata
);
1251 set_bit(XGBE_LINK_ERR
, &pdata
->dev_state
);
1253 clear_bit(XGBE_LINK_ERR
, &pdata
->dev_state
);
1255 mutex_unlock(&pdata
->an_mutex
);
1260 static int xgbe_phy_config_aneg(struct xgbe_prv_data
*pdata
)
1262 return __xgbe_phy_config_aneg(pdata
, true);
1265 static int xgbe_phy_reconfig_aneg(struct xgbe_prv_data
*pdata
)
1267 return __xgbe_phy_config_aneg(pdata
, false);
1270 static bool xgbe_phy_aneg_done(struct xgbe_prv_data
*pdata
)
1272 return (pdata
->an_result
== XGBE_AN_COMPLETE
);
1275 static void xgbe_check_link_timeout(struct xgbe_prv_data
*pdata
)
1277 unsigned long link_timeout
;
1279 link_timeout
= pdata
->link_check
+ (XGBE_LINK_TIMEOUT
* HZ
);
1280 if (time_after(jiffies
, link_timeout
)) {
1281 netif_dbg(pdata
, link
, pdata
->netdev
, "AN link timeout\n");
1282 xgbe_phy_config_aneg(pdata
);
1286 static enum xgbe_mode
xgbe_phy_status_aneg(struct xgbe_prv_data
*pdata
)
1288 return pdata
->phy_if
.phy_impl
.an_outcome(pdata
);
1291 static void xgbe_phy_status_result(struct xgbe_prv_data
*pdata
)
1293 struct ethtool_link_ksettings
*lks
= &pdata
->phy
.lks
;
1294 enum xgbe_mode mode
;
1296 XGBE_ZERO_LP_ADV(lks
);
1298 if ((pdata
->phy
.autoneg
!= AUTONEG_ENABLE
) || pdata
->parallel_detect
)
1299 mode
= xgbe_cur_mode(pdata
);
1301 mode
= xgbe_phy_status_aneg(pdata
);
1304 case XGBE_MODE_SGMII_100
:
1305 pdata
->phy
.speed
= SPEED_100
;
1308 case XGBE_MODE_KX_1000
:
1309 case XGBE_MODE_SGMII_1000
:
1310 pdata
->phy
.speed
= SPEED_1000
;
1312 case XGBE_MODE_KX_2500
:
1313 pdata
->phy
.speed
= SPEED_2500
;
1317 pdata
->phy
.speed
= SPEED_10000
;
1319 case XGBE_MODE_UNKNOWN
:
1321 pdata
->phy
.speed
= SPEED_UNKNOWN
;
1324 pdata
->phy
.duplex
= DUPLEX_FULL
;
1326 if (xgbe_set_mode(pdata
, mode
) && pdata
->an_again
)
1327 xgbe_phy_reconfig_aneg(pdata
);
1330 static void xgbe_phy_status(struct xgbe_prv_data
*pdata
)
1332 unsigned int link_aneg
;
1335 if (test_bit(XGBE_LINK_ERR
, &pdata
->dev_state
)) {
1336 netif_carrier_off(pdata
->netdev
);
1338 pdata
->phy
.link
= 0;
1342 link_aneg
= (pdata
->phy
.autoneg
== AUTONEG_ENABLE
);
1344 pdata
->phy
.link
= pdata
->phy_if
.phy_impl
.link_status(pdata
,
1347 xgbe_phy_config_aneg(pdata
);
1351 if (pdata
->phy
.link
) {
1352 if (link_aneg
&& !xgbe_phy_aneg_done(pdata
)) {
1353 xgbe_check_link_timeout(pdata
);
1357 xgbe_phy_status_result(pdata
);
1359 if (test_bit(XGBE_LINK_INIT
, &pdata
->dev_state
))
1360 clear_bit(XGBE_LINK_INIT
, &pdata
->dev_state
);
1362 netif_carrier_on(pdata
->netdev
);
1364 if (test_bit(XGBE_LINK_INIT
, &pdata
->dev_state
)) {
1365 xgbe_check_link_timeout(pdata
);
1371 xgbe_phy_status_result(pdata
);
1373 netif_carrier_off(pdata
->netdev
);
1377 xgbe_phy_adjust_link(pdata
);
1380 static void xgbe_phy_stop(struct xgbe_prv_data
*pdata
)
1382 netif_dbg(pdata
, link
, pdata
->netdev
, "stopping PHY\n");
1384 if (!pdata
->phy_started
)
1387 /* Indicate the PHY is down */
1388 pdata
->phy_started
= 0;
1390 /* Disable auto-negotiation */
1391 xgbe_an_disable_all(pdata
);
1393 if (pdata
->dev_irq
!= pdata
->an_irq
)
1394 devm_free_irq(pdata
->dev
, pdata
->an_irq
, pdata
);
1396 pdata
->phy_if
.phy_impl
.stop(pdata
);
1398 pdata
->phy
.link
= 0;
1399 netif_carrier_off(pdata
->netdev
);
1401 xgbe_phy_adjust_link(pdata
);
1404 static int xgbe_phy_start(struct xgbe_prv_data
*pdata
)
1406 struct net_device
*netdev
= pdata
->netdev
;
1409 netif_dbg(pdata
, link
, pdata
->netdev
, "starting PHY\n");
1411 ret
= pdata
->phy_if
.phy_impl
.start(pdata
);
1415 /* If we have a separate AN irq, enable it */
1416 if (pdata
->dev_irq
!= pdata
->an_irq
) {
1417 tasklet_init(&pdata
->tasklet_an
, xgbe_an_isr_task
,
1418 (unsigned long)pdata
);
1420 ret
= devm_request_irq(pdata
->dev
, pdata
->an_irq
,
1421 xgbe_an_isr
, 0, pdata
->an_name
,
1424 netdev_err(netdev
, "phy irq request failed\n");
1429 /* Set initial mode - call the mode setting routines
1430 * directly to insure we are properly configured
1432 if (xgbe_use_mode(pdata
, XGBE_MODE_KR
)) {
1433 xgbe_kr_mode(pdata
);
1434 } else if (xgbe_use_mode(pdata
, XGBE_MODE_KX_2500
)) {
1435 xgbe_kx_2500_mode(pdata
);
1436 } else if (xgbe_use_mode(pdata
, XGBE_MODE_KX_1000
)) {
1437 xgbe_kx_1000_mode(pdata
);
1438 } else if (xgbe_use_mode(pdata
, XGBE_MODE_SFI
)) {
1439 xgbe_sfi_mode(pdata
);
1440 } else if (xgbe_use_mode(pdata
, XGBE_MODE_X
)) {
1442 } else if (xgbe_use_mode(pdata
, XGBE_MODE_SGMII_1000
)) {
1443 xgbe_sgmii_1000_mode(pdata
);
1444 } else if (xgbe_use_mode(pdata
, XGBE_MODE_SGMII_100
)) {
1445 xgbe_sgmii_100_mode(pdata
);
1451 /* Indicate the PHY is up and running */
1452 pdata
->phy_started
= 1;
1454 xgbe_an_init(pdata
);
1455 xgbe_an_enable_interrupts(pdata
);
1457 return xgbe_phy_config_aneg(pdata
);
1460 if (pdata
->dev_irq
!= pdata
->an_irq
)
1461 devm_free_irq(pdata
->dev
, pdata
->an_irq
, pdata
);
1464 pdata
->phy_if
.phy_impl
.stop(pdata
);
1469 static int xgbe_phy_reset(struct xgbe_prv_data
*pdata
)
1473 ret
= pdata
->phy_if
.phy_impl
.reset(pdata
);
1477 /* Disable auto-negotiation for now */
1478 xgbe_an_disable_all(pdata
);
1480 /* Clear auto-negotiation interrupts */
1481 xgbe_an_clear_interrupts_all(pdata
);
1486 static void xgbe_dump_phy_registers(struct xgbe_prv_data
*pdata
)
1488 struct device
*dev
= pdata
->dev
;
1490 dev_dbg(dev
, "\n************* PHY Reg dump **********************\n");
1492 dev_dbg(dev
, "PCS Control Reg (%#06x) = %#06x\n", MDIO_CTRL1
,
1493 XMDIO_READ(pdata
, MDIO_MMD_PCS
, MDIO_CTRL1
));
1494 dev_dbg(dev
, "PCS Status Reg (%#06x) = %#06x\n", MDIO_STAT1
,
1495 XMDIO_READ(pdata
, MDIO_MMD_PCS
, MDIO_STAT1
));
1496 dev_dbg(dev
, "Phy Id (PHYS ID 1 %#06x)= %#06x\n", MDIO_DEVID1
,
1497 XMDIO_READ(pdata
, MDIO_MMD_PCS
, MDIO_DEVID1
));
1498 dev_dbg(dev
, "Phy Id (PHYS ID 2 %#06x)= %#06x\n", MDIO_DEVID2
,
1499 XMDIO_READ(pdata
, MDIO_MMD_PCS
, MDIO_DEVID2
));
1500 dev_dbg(dev
, "Devices in Package (%#06x)= %#06x\n", MDIO_DEVS1
,
1501 XMDIO_READ(pdata
, MDIO_MMD_PCS
, MDIO_DEVS1
));
1502 dev_dbg(dev
, "Devices in Package (%#06x)= %#06x\n", MDIO_DEVS2
,
1503 XMDIO_READ(pdata
, MDIO_MMD_PCS
, MDIO_DEVS2
));
1505 dev_dbg(dev
, "Auto-Neg Control Reg (%#06x) = %#06x\n", MDIO_CTRL1
,
1506 XMDIO_READ(pdata
, MDIO_MMD_AN
, MDIO_CTRL1
));
1507 dev_dbg(dev
, "Auto-Neg Status Reg (%#06x) = %#06x\n", MDIO_STAT1
,
1508 XMDIO_READ(pdata
, MDIO_MMD_AN
, MDIO_STAT1
));
1509 dev_dbg(dev
, "Auto-Neg Ad Reg 1 (%#06x) = %#06x\n",
1511 XMDIO_READ(pdata
, MDIO_MMD_AN
, MDIO_AN_ADVERTISE
));
1512 dev_dbg(dev
, "Auto-Neg Ad Reg 2 (%#06x) = %#06x\n",
1513 MDIO_AN_ADVERTISE
+ 1,
1514 XMDIO_READ(pdata
, MDIO_MMD_AN
, MDIO_AN_ADVERTISE
+ 1));
1515 dev_dbg(dev
, "Auto-Neg Ad Reg 3 (%#06x) = %#06x\n",
1516 MDIO_AN_ADVERTISE
+ 2,
1517 XMDIO_READ(pdata
, MDIO_MMD_AN
, MDIO_AN_ADVERTISE
+ 2));
1518 dev_dbg(dev
, "Auto-Neg Completion Reg (%#06x) = %#06x\n",
1520 XMDIO_READ(pdata
, MDIO_MMD_AN
, MDIO_AN_COMP_STAT
));
1522 dev_dbg(dev
, "\n*************************************************\n");
1525 static int xgbe_phy_best_advertised_speed(struct xgbe_prv_data
*pdata
)
1527 struct ethtool_link_ksettings
*lks
= &pdata
->phy
.lks
;
1529 if (XGBE_ADV(lks
, 10000baseKR_Full
))
1531 else if (XGBE_ADV(lks
, 10000baseT_Full
))
1533 else if (XGBE_ADV(lks
, 2500baseX_Full
))
1535 else if (XGBE_ADV(lks
, 2500baseT_Full
))
1537 else if (XGBE_ADV(lks
, 1000baseKX_Full
))
1539 else if (XGBE_ADV(lks
, 1000baseT_Full
))
1541 else if (XGBE_ADV(lks
, 100baseT_Full
))
1544 return SPEED_UNKNOWN
;
1547 static void xgbe_phy_exit(struct xgbe_prv_data
*pdata
)
1549 pdata
->phy_if
.phy_impl
.exit(pdata
);
1552 static int xgbe_phy_init(struct xgbe_prv_data
*pdata
)
1554 struct ethtool_link_ksettings
*lks
= &pdata
->phy
.lks
;
1557 mutex_init(&pdata
->an_mutex
);
1558 INIT_WORK(&pdata
->an_irq_work
, xgbe_an_irq_work
);
1559 INIT_WORK(&pdata
->an_work
, xgbe_an_state_machine
);
1560 pdata
->mdio_mmd
= MDIO_MMD_PCS
;
1562 /* Check for FEC support */
1563 pdata
->fec_ability
= XMDIO_READ(pdata
, MDIO_MMD_PMAPMD
,
1564 MDIO_PMA_10GBR_FECABLE
);
1565 pdata
->fec_ability
&= (MDIO_PMA_10GBR_FECABLE_ABLE
|
1566 MDIO_PMA_10GBR_FECABLE_ERRABLE
);
1568 /* Setup the phy (including supported features) */
1569 ret
= pdata
->phy_if
.phy_impl
.init(pdata
);
1573 /* Copy supported link modes to advertising link modes */
1574 XGBE_LM_COPY(lks
, advertising
, lks
, supported
);
1576 pdata
->phy
.address
= 0;
1578 if (XGBE_ADV(lks
, Autoneg
)) {
1579 pdata
->phy
.autoneg
= AUTONEG_ENABLE
;
1580 pdata
->phy
.speed
= SPEED_UNKNOWN
;
1581 pdata
->phy
.duplex
= DUPLEX_UNKNOWN
;
1583 pdata
->phy
.autoneg
= AUTONEG_DISABLE
;
1584 pdata
->phy
.speed
= xgbe_phy_best_advertised_speed(pdata
);
1585 pdata
->phy
.duplex
= DUPLEX_FULL
;
1588 pdata
->phy
.link
= 0;
1590 pdata
->phy
.pause_autoneg
= pdata
->pause_autoneg
;
1591 pdata
->phy
.tx_pause
= pdata
->tx_pause
;
1592 pdata
->phy
.rx_pause
= pdata
->rx_pause
;
1594 /* Fix up Flow Control advertising */
1595 XGBE_CLR_ADV(lks
, Pause
);
1596 XGBE_CLR_ADV(lks
, Asym_Pause
);
1598 if (pdata
->rx_pause
) {
1599 XGBE_SET_ADV(lks
, Pause
);
1600 XGBE_SET_ADV(lks
, Asym_Pause
);
1603 if (pdata
->tx_pause
) {
1604 /* Equivalent to XOR of Asym_Pause */
1605 if (XGBE_ADV(lks
, Asym_Pause
))
1606 XGBE_CLR_ADV(lks
, Asym_Pause
);
1608 XGBE_SET_ADV(lks
, Asym_Pause
);
1611 if (netif_msg_drv(pdata
))
1612 xgbe_dump_phy_registers(pdata
);
1617 void xgbe_init_function_ptrs_phy(struct xgbe_phy_if
*phy_if
)
1619 phy_if
->phy_init
= xgbe_phy_init
;
1620 phy_if
->phy_exit
= xgbe_phy_exit
;
1622 phy_if
->phy_reset
= xgbe_phy_reset
;
1623 phy_if
->phy_start
= xgbe_phy_start
;
1624 phy_if
->phy_stop
= xgbe_phy_stop
;
1626 phy_if
->phy_status
= xgbe_phy_status
;
1627 phy_if
->phy_config_aneg
= xgbe_phy_config_aneg
;
1629 phy_if
->phy_valid_speed
= xgbe_phy_valid_speed
;
1631 phy_if
->an_isr
= xgbe_an_combined_isr
;
1633 phy_if
->module_info
= xgbe_phy_module_info
;
1634 phy_if
->module_eeprom
= xgbe_phy_module_eeprom
;