2 * AMD 10Gb Ethernet driver
4 * This file is available to you under your choice of the following two
9 * Copyright (c) 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) 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/module.h>
118 #include <linux/kmod.h>
119 #include <linux/device.h>
120 #include <linux/property.h>
121 #include <linux/mdio.h>
122 #include <linux/phy.h>
125 #include "xgbe-common.h"
127 #define XGBE_BLWC_PROPERTY "amd,serdes-blwc"
128 #define XGBE_CDR_RATE_PROPERTY "amd,serdes-cdr-rate"
129 #define XGBE_PQ_SKEW_PROPERTY "amd,serdes-pq-skew"
130 #define XGBE_TX_AMP_PROPERTY "amd,serdes-tx-amp"
131 #define XGBE_DFE_CFG_PROPERTY "amd,serdes-dfe-tap-config"
132 #define XGBE_DFE_ENA_PROPERTY "amd,serdes-dfe-tap-enable"
134 /* Default SerDes settings */
135 #define XGBE_SPEED_1000_BLWC 1
136 #define XGBE_SPEED_1000_CDR 0x2
137 #define XGBE_SPEED_1000_PLL 0x0
138 #define XGBE_SPEED_1000_PQ 0xa
139 #define XGBE_SPEED_1000_RATE 0x3
140 #define XGBE_SPEED_1000_TXAMP 0xf
141 #define XGBE_SPEED_1000_WORD 0x1
142 #define XGBE_SPEED_1000_DFE_TAP_CONFIG 0x3
143 #define XGBE_SPEED_1000_DFE_TAP_ENABLE 0x0
145 #define XGBE_SPEED_2500_BLWC 1
146 #define XGBE_SPEED_2500_CDR 0x2
147 #define XGBE_SPEED_2500_PLL 0x0
148 #define XGBE_SPEED_2500_PQ 0xa
149 #define XGBE_SPEED_2500_RATE 0x1
150 #define XGBE_SPEED_2500_TXAMP 0xf
151 #define XGBE_SPEED_2500_WORD 0x1
152 #define XGBE_SPEED_2500_DFE_TAP_CONFIG 0x3
153 #define XGBE_SPEED_2500_DFE_TAP_ENABLE 0x0
155 #define XGBE_SPEED_10000_BLWC 0
156 #define XGBE_SPEED_10000_CDR 0x7
157 #define XGBE_SPEED_10000_PLL 0x1
158 #define XGBE_SPEED_10000_PQ 0x12
159 #define XGBE_SPEED_10000_RATE 0x0
160 #define XGBE_SPEED_10000_TXAMP 0xa
161 #define XGBE_SPEED_10000_WORD 0x7
162 #define XGBE_SPEED_10000_DFE_TAP_CONFIG 0x1
163 #define XGBE_SPEED_10000_DFE_TAP_ENABLE 0x7f
165 /* Rate-change complete wait/retry count */
166 #define XGBE_RATECHANGE_COUNT 500
168 static const u32 xgbe_phy_blwc
[] = {
169 XGBE_SPEED_1000_BLWC
,
170 XGBE_SPEED_2500_BLWC
,
171 XGBE_SPEED_10000_BLWC
,
174 static const u32 xgbe_phy_cdr_rate
[] = {
177 XGBE_SPEED_10000_CDR
,
180 static const u32 xgbe_phy_pq_skew
[] = {
186 static const u32 xgbe_phy_tx_amp
[] = {
187 XGBE_SPEED_1000_TXAMP
,
188 XGBE_SPEED_2500_TXAMP
,
189 XGBE_SPEED_10000_TXAMP
,
192 static const u32 xgbe_phy_dfe_tap_cfg
[] = {
193 XGBE_SPEED_1000_DFE_TAP_CONFIG
,
194 XGBE_SPEED_2500_DFE_TAP_CONFIG
,
195 XGBE_SPEED_10000_DFE_TAP_CONFIG
,
198 static const u32 xgbe_phy_dfe_tap_ena
[] = {
199 XGBE_SPEED_1000_DFE_TAP_ENABLE
,
200 XGBE_SPEED_2500_DFE_TAP_ENABLE
,
201 XGBE_SPEED_10000_DFE_TAP_ENABLE
,
204 struct xgbe_phy_data
{
205 /* 1000/10000 vs 2500/10000 indicator */
206 unsigned int speed_set
;
208 /* SerDes UEFI configurable settings.
209 * Switching between modes/speeds requires new values for some
210 * SerDes settings. The values can be supplied as device
211 * properties in array format. The first array entry is for
212 * 1GbE, second for 2.5GbE and third for 10GbE
214 u32 blwc
[XGBE_SPEEDS
];
215 u32 cdr_rate
[XGBE_SPEEDS
];
216 u32 pq_skew
[XGBE_SPEEDS
];
217 u32 tx_amp
[XGBE_SPEEDS
];
218 u32 dfe_tap_cfg
[XGBE_SPEEDS
];
219 u32 dfe_tap_ena
[XGBE_SPEEDS
];
222 static void xgbe_phy_kr_training_pre(struct xgbe_prv_data
*pdata
)
224 XSIR0_IOWRITE_BITS(pdata
, SIR0_KR_RT_1
, RESET
, 1);
227 static void xgbe_phy_kr_training_post(struct xgbe_prv_data
*pdata
)
229 XSIR0_IOWRITE_BITS(pdata
, SIR0_KR_RT_1
, RESET
, 0);
232 static enum xgbe_mode
xgbe_phy_an_outcome(struct xgbe_prv_data
*pdata
)
234 struct xgbe_phy_data
*phy_data
= pdata
->phy_data
;
236 unsigned int ad_reg
, lp_reg
;
238 pdata
->phy
.lp_advertising
|= ADVERTISED_Autoneg
;
239 pdata
->phy
.lp_advertising
|= ADVERTISED_Backplane
;
241 /* Compare Advertisement and Link Partner register 1 */
242 ad_reg
= XMDIO_READ(pdata
, MDIO_MMD_AN
, MDIO_AN_ADVERTISE
);
243 lp_reg
= XMDIO_READ(pdata
, MDIO_MMD_AN
, MDIO_AN_LPA
);
245 pdata
->phy
.lp_advertising
|= ADVERTISED_Pause
;
247 pdata
->phy
.lp_advertising
|= ADVERTISED_Asym_Pause
;
249 if (pdata
->phy
.pause_autoneg
) {
250 /* Set flow control based on auto-negotiation result */
251 pdata
->phy
.tx_pause
= 0;
252 pdata
->phy
.rx_pause
= 0;
254 if (ad_reg
& lp_reg
& 0x400) {
255 pdata
->phy
.tx_pause
= 1;
256 pdata
->phy
.rx_pause
= 1;
257 } else if (ad_reg
& lp_reg
& 0x800) {
259 pdata
->phy
.rx_pause
= 1;
260 else if (lp_reg
& 0x400)
261 pdata
->phy
.tx_pause
= 1;
265 /* Compare Advertisement and Link Partner register 2 */
266 ad_reg
= XMDIO_READ(pdata
, MDIO_MMD_AN
, MDIO_AN_ADVERTISE
+ 1);
267 lp_reg
= XMDIO_READ(pdata
, MDIO_MMD_AN
, MDIO_AN_LPA
+ 1);
269 pdata
->phy
.lp_advertising
|= ADVERTISED_10000baseKR_Full
;
271 if (phy_data
->speed_set
== XGBE_SPEEDSET_2500_10000
)
272 pdata
->phy
.lp_advertising
|= ADVERTISED_2500baseX_Full
;
274 pdata
->phy
.lp_advertising
|= ADVERTISED_1000baseKX_Full
;
280 } else if (ad_reg
& 0x20) {
281 if (phy_data
->speed_set
== XGBE_SPEEDSET_2500_10000
)
282 mode
= XGBE_MODE_KX_2500
;
284 mode
= XGBE_MODE_KX_1000
;
286 mode
= XGBE_MODE_UNKNOWN
;
289 /* Compare Advertisement and Link Partner register 3 */
290 ad_reg
= XMDIO_READ(pdata
, MDIO_MMD_AN
, MDIO_AN_ADVERTISE
+ 2);
291 lp_reg
= XMDIO_READ(pdata
, MDIO_MMD_AN
, MDIO_AN_LPA
+ 2);
293 pdata
->phy
.lp_advertising
|= ADVERTISED_10000baseR_FEC
;
298 static unsigned int xgbe_phy_an_advertising(struct xgbe_prv_data
*pdata
)
300 return pdata
->phy
.advertising
;
303 static int xgbe_phy_an_config(struct xgbe_prv_data
*pdata
)
305 /* Nothing uniquely required for an configuration */
309 static enum xgbe_an_mode
xgbe_phy_an_mode(struct xgbe_prv_data
*pdata
)
311 return XGBE_AN_MODE_CL73
;
314 static void xgbe_phy_pcs_power_cycle(struct xgbe_prv_data
*pdata
)
318 reg
= XMDIO_READ(pdata
, MDIO_MMD_PCS
, MDIO_CTRL1
);
320 reg
|= MDIO_CTRL1_LPOWER
;
321 XMDIO_WRITE(pdata
, MDIO_MMD_PCS
, MDIO_CTRL1
, reg
);
323 usleep_range(75, 100);
325 reg
&= ~MDIO_CTRL1_LPOWER
;
326 XMDIO_WRITE(pdata
, MDIO_MMD_PCS
, MDIO_CTRL1
, reg
);
329 static void xgbe_phy_start_ratechange(struct xgbe_prv_data
*pdata
)
331 /* Assert Rx and Tx ratechange */
332 XSIR1_IOWRITE_BITS(pdata
, SIR1_SPEED
, RATECHANGE
, 1);
335 static void xgbe_phy_complete_ratechange(struct xgbe_prv_data
*pdata
)
340 /* Release Rx and Tx ratechange */
341 XSIR1_IOWRITE_BITS(pdata
, SIR1_SPEED
, RATECHANGE
, 0);
343 /* Wait for Rx and Tx ready */
344 wait
= XGBE_RATECHANGE_COUNT
;
346 usleep_range(50, 75);
348 status
= XSIR0_IOREAD(pdata
, SIR0_STATUS
);
349 if (XSIR_GET_BITS(status
, SIR0_STATUS
, RX_READY
) &&
350 XSIR_GET_BITS(status
, SIR0_STATUS
, TX_READY
))
354 netif_dbg(pdata
, link
, pdata
->netdev
, "SerDes rx/tx not ready (%#hx)\n",
358 /* Perform Rx reset for the DFE changes */
359 XRXTX_IOWRITE_BITS(pdata
, RXTX_REG6
, RESETB_RXD
, 0);
360 XRXTX_IOWRITE_BITS(pdata
, RXTX_REG6
, RESETB_RXD
, 1);
363 static void xgbe_phy_kr_mode(struct xgbe_prv_data
*pdata
)
365 struct xgbe_phy_data
*phy_data
= pdata
->phy_data
;
368 /* Set PCS to KR/10G speed */
369 reg
= XMDIO_READ(pdata
, MDIO_MMD_PCS
, MDIO_CTRL2
);
370 reg
&= ~MDIO_PCS_CTRL2_TYPE
;
371 reg
|= MDIO_PCS_CTRL2_10GBR
;
372 XMDIO_WRITE(pdata
, MDIO_MMD_PCS
, MDIO_CTRL2
, reg
);
374 reg
= XMDIO_READ(pdata
, MDIO_MMD_PCS
, MDIO_CTRL1
);
375 reg
&= ~MDIO_CTRL1_SPEEDSEL
;
376 reg
|= MDIO_CTRL1_SPEED10G
;
377 XMDIO_WRITE(pdata
, MDIO_MMD_PCS
, MDIO_CTRL1
, reg
);
379 xgbe_phy_pcs_power_cycle(pdata
);
381 /* Set SerDes to 10G speed */
382 xgbe_phy_start_ratechange(pdata
);
384 XSIR1_IOWRITE_BITS(pdata
, SIR1_SPEED
, DATARATE
, XGBE_SPEED_10000_RATE
);
385 XSIR1_IOWRITE_BITS(pdata
, SIR1_SPEED
, WORDMODE
, XGBE_SPEED_10000_WORD
);
386 XSIR1_IOWRITE_BITS(pdata
, SIR1_SPEED
, PLLSEL
, XGBE_SPEED_10000_PLL
);
388 XSIR1_IOWRITE_BITS(pdata
, SIR1_SPEED
, CDR_RATE
,
389 phy_data
->cdr_rate
[XGBE_SPEED_10000
]);
390 XSIR1_IOWRITE_BITS(pdata
, SIR1_SPEED
, TXAMP
,
391 phy_data
->tx_amp
[XGBE_SPEED_10000
]);
392 XRXTX_IOWRITE_BITS(pdata
, RXTX_REG20
, BLWC_ENA
,
393 phy_data
->blwc
[XGBE_SPEED_10000
]);
394 XRXTX_IOWRITE_BITS(pdata
, RXTX_REG114
, PQ_REG
,
395 phy_data
->pq_skew
[XGBE_SPEED_10000
]);
396 XRXTX_IOWRITE_BITS(pdata
, RXTX_REG129
, RXDFE_CONFIG
,
397 phy_data
->dfe_tap_cfg
[XGBE_SPEED_10000
]);
398 XRXTX_IOWRITE(pdata
, RXTX_REG22
,
399 phy_data
->dfe_tap_ena
[XGBE_SPEED_10000
]);
401 xgbe_phy_complete_ratechange(pdata
);
403 netif_dbg(pdata
, link
, pdata
->netdev
, "10GbE KR mode set\n");
406 static void xgbe_phy_kx_2500_mode(struct xgbe_prv_data
*pdata
)
408 struct xgbe_phy_data
*phy_data
= pdata
->phy_data
;
411 /* Set PCS to KX/1G speed */
412 reg
= XMDIO_READ(pdata
, MDIO_MMD_PCS
, MDIO_CTRL2
);
413 reg
&= ~MDIO_PCS_CTRL2_TYPE
;
414 reg
|= MDIO_PCS_CTRL2_10GBX
;
415 XMDIO_WRITE(pdata
, MDIO_MMD_PCS
, MDIO_CTRL2
, reg
);
417 reg
= XMDIO_READ(pdata
, MDIO_MMD_PCS
, MDIO_CTRL1
);
418 reg
&= ~MDIO_CTRL1_SPEEDSEL
;
419 reg
|= MDIO_CTRL1_SPEED1G
;
420 XMDIO_WRITE(pdata
, MDIO_MMD_PCS
, MDIO_CTRL1
, reg
);
422 xgbe_phy_pcs_power_cycle(pdata
);
424 /* Set SerDes to 2.5G speed */
425 xgbe_phy_start_ratechange(pdata
);
427 XSIR1_IOWRITE_BITS(pdata
, SIR1_SPEED
, DATARATE
, XGBE_SPEED_2500_RATE
);
428 XSIR1_IOWRITE_BITS(pdata
, SIR1_SPEED
, WORDMODE
, XGBE_SPEED_2500_WORD
);
429 XSIR1_IOWRITE_BITS(pdata
, SIR1_SPEED
, PLLSEL
, XGBE_SPEED_2500_PLL
);
431 XSIR1_IOWRITE_BITS(pdata
, SIR1_SPEED
, CDR_RATE
,
432 phy_data
->cdr_rate
[XGBE_SPEED_2500
]);
433 XSIR1_IOWRITE_BITS(pdata
, SIR1_SPEED
, TXAMP
,
434 phy_data
->tx_amp
[XGBE_SPEED_2500
]);
435 XRXTX_IOWRITE_BITS(pdata
, RXTX_REG20
, BLWC_ENA
,
436 phy_data
->blwc
[XGBE_SPEED_2500
]);
437 XRXTX_IOWRITE_BITS(pdata
, RXTX_REG114
, PQ_REG
,
438 phy_data
->pq_skew
[XGBE_SPEED_2500
]);
439 XRXTX_IOWRITE_BITS(pdata
, RXTX_REG129
, RXDFE_CONFIG
,
440 phy_data
->dfe_tap_cfg
[XGBE_SPEED_2500
]);
441 XRXTX_IOWRITE(pdata
, RXTX_REG22
,
442 phy_data
->dfe_tap_ena
[XGBE_SPEED_2500
]);
444 xgbe_phy_complete_ratechange(pdata
);
446 netif_dbg(pdata
, link
, pdata
->netdev
, "2.5GbE KX mode set\n");
449 static void xgbe_phy_kx_1000_mode(struct xgbe_prv_data
*pdata
)
451 struct xgbe_phy_data
*phy_data
= pdata
->phy_data
;
454 /* Set PCS to KX/1G speed */
455 reg
= XMDIO_READ(pdata
, MDIO_MMD_PCS
, MDIO_CTRL2
);
456 reg
&= ~MDIO_PCS_CTRL2_TYPE
;
457 reg
|= MDIO_PCS_CTRL2_10GBX
;
458 XMDIO_WRITE(pdata
, MDIO_MMD_PCS
, MDIO_CTRL2
, reg
);
460 reg
= XMDIO_READ(pdata
, MDIO_MMD_PCS
, MDIO_CTRL1
);
461 reg
&= ~MDIO_CTRL1_SPEEDSEL
;
462 reg
|= MDIO_CTRL1_SPEED1G
;
463 XMDIO_WRITE(pdata
, MDIO_MMD_PCS
, MDIO_CTRL1
, reg
);
465 xgbe_phy_pcs_power_cycle(pdata
);
467 /* Set SerDes to 1G speed */
468 xgbe_phy_start_ratechange(pdata
);
470 XSIR1_IOWRITE_BITS(pdata
, SIR1_SPEED
, DATARATE
, XGBE_SPEED_1000_RATE
);
471 XSIR1_IOWRITE_BITS(pdata
, SIR1_SPEED
, WORDMODE
, XGBE_SPEED_1000_WORD
);
472 XSIR1_IOWRITE_BITS(pdata
, SIR1_SPEED
, PLLSEL
, XGBE_SPEED_1000_PLL
);
474 XSIR1_IOWRITE_BITS(pdata
, SIR1_SPEED
, CDR_RATE
,
475 phy_data
->cdr_rate
[XGBE_SPEED_1000
]);
476 XSIR1_IOWRITE_BITS(pdata
, SIR1_SPEED
, TXAMP
,
477 phy_data
->tx_amp
[XGBE_SPEED_1000
]);
478 XRXTX_IOWRITE_BITS(pdata
, RXTX_REG20
, BLWC_ENA
,
479 phy_data
->blwc
[XGBE_SPEED_1000
]);
480 XRXTX_IOWRITE_BITS(pdata
, RXTX_REG114
, PQ_REG
,
481 phy_data
->pq_skew
[XGBE_SPEED_1000
]);
482 XRXTX_IOWRITE_BITS(pdata
, RXTX_REG129
, RXDFE_CONFIG
,
483 phy_data
->dfe_tap_cfg
[XGBE_SPEED_1000
]);
484 XRXTX_IOWRITE(pdata
, RXTX_REG22
,
485 phy_data
->dfe_tap_ena
[XGBE_SPEED_1000
]);
487 xgbe_phy_complete_ratechange(pdata
);
489 netif_dbg(pdata
, link
, pdata
->netdev
, "1GbE KX mode set\n");
492 static enum xgbe_mode
xgbe_phy_cur_mode(struct xgbe_prv_data
*pdata
)
494 struct xgbe_phy_data
*phy_data
= pdata
->phy_data
;
498 reg
= XMDIO_READ(pdata
, MDIO_MMD_PCS
, MDIO_CTRL2
);
499 reg
&= MDIO_PCS_CTRL2_TYPE
;
501 if (reg
== MDIO_PCS_CTRL2_10GBR
) {
504 if (phy_data
->speed_set
== XGBE_SPEEDSET_2500_10000
)
505 mode
= XGBE_MODE_KX_2500
;
507 mode
= XGBE_MODE_KX_1000
;
513 static enum xgbe_mode
xgbe_phy_switch_mode(struct xgbe_prv_data
*pdata
)
515 struct xgbe_phy_data
*phy_data
= pdata
->phy_data
;
518 /* If we are in KR switch to KX, and vice-versa */
519 if (xgbe_phy_cur_mode(pdata
) == XGBE_MODE_KR
) {
520 if (phy_data
->speed_set
== XGBE_SPEEDSET_2500_10000
)
521 mode
= XGBE_MODE_KX_2500
;
523 mode
= XGBE_MODE_KX_1000
;
531 static enum xgbe_mode
xgbe_phy_get_mode(struct xgbe_prv_data
*pdata
,
534 struct xgbe_phy_data
*phy_data
= pdata
->phy_data
;
538 return (phy_data
->speed_set
== XGBE_SPEEDSET_1000_10000
)
539 ? XGBE_MODE_KX_1000
: XGBE_MODE_UNKNOWN
;
541 return (phy_data
->speed_set
== XGBE_SPEEDSET_2500_10000
)
542 ? XGBE_MODE_KX_2500
: XGBE_MODE_UNKNOWN
;
546 return XGBE_MODE_UNKNOWN
;
550 static void xgbe_phy_set_mode(struct xgbe_prv_data
*pdata
, enum xgbe_mode mode
)
553 case XGBE_MODE_KX_1000
:
554 xgbe_phy_kx_1000_mode(pdata
);
556 case XGBE_MODE_KX_2500
:
557 xgbe_phy_kx_2500_mode(pdata
);
560 xgbe_phy_kr_mode(pdata
);
567 static bool xgbe_phy_check_mode(struct xgbe_prv_data
*pdata
,
568 enum xgbe_mode mode
, u32 advert
)
570 if (pdata
->phy
.autoneg
== AUTONEG_ENABLE
) {
571 if (pdata
->phy
.advertising
& advert
)
574 enum xgbe_mode cur_mode
;
576 cur_mode
= xgbe_phy_get_mode(pdata
, pdata
->phy
.speed
);
577 if (cur_mode
== mode
)
584 static bool xgbe_phy_use_mode(struct xgbe_prv_data
*pdata
, enum xgbe_mode mode
)
587 case XGBE_MODE_KX_1000
:
588 return xgbe_phy_check_mode(pdata
, mode
,
589 ADVERTISED_1000baseKX_Full
);
590 case XGBE_MODE_KX_2500
:
591 return xgbe_phy_check_mode(pdata
, mode
,
592 ADVERTISED_2500baseX_Full
);
594 return xgbe_phy_check_mode(pdata
, mode
,
595 ADVERTISED_10000baseKR_Full
);
601 static bool xgbe_phy_valid_speed(struct xgbe_prv_data
*pdata
, int speed
)
603 struct xgbe_phy_data
*phy_data
= pdata
->phy_data
;
607 if (phy_data
->speed_set
!= XGBE_SPEEDSET_1000_10000
)
611 if (phy_data
->speed_set
!= XGBE_SPEEDSET_2500_10000
)
621 static int xgbe_phy_link_status(struct xgbe_prv_data
*pdata
, int *an_restart
)
627 /* Link status is latched low, so read once to clear
628 * and then read again to get current state
630 reg
= XMDIO_READ(pdata
, MDIO_MMD_PCS
, MDIO_STAT1
);
631 reg
= XMDIO_READ(pdata
, MDIO_MMD_PCS
, MDIO_STAT1
);
633 return (reg
& MDIO_STAT1_LSTATUS
) ? 1 : 0;
636 static void xgbe_phy_stop(struct xgbe_prv_data
*pdata
)
638 /* Nothing uniquely required for stop */
641 static int xgbe_phy_start(struct xgbe_prv_data
*pdata
)
643 /* Nothing uniquely required for start */
647 static int xgbe_phy_reset(struct xgbe_prv_data
*pdata
)
649 unsigned int reg
, count
;
651 /* Perform a software reset of the PCS */
652 reg
= XMDIO_READ(pdata
, MDIO_MMD_PCS
, MDIO_CTRL1
);
653 reg
|= MDIO_CTRL1_RESET
;
654 XMDIO_WRITE(pdata
, MDIO_MMD_PCS
, MDIO_CTRL1
, reg
);
659 reg
= XMDIO_READ(pdata
, MDIO_MMD_PCS
, MDIO_CTRL1
);
660 } while ((reg
& MDIO_CTRL1_RESET
) && --count
);
662 if (reg
& MDIO_CTRL1_RESET
)
668 static void xgbe_phy_exit(struct xgbe_prv_data
*pdata
)
670 /* Nothing uniquely required for exit */
673 static int xgbe_phy_init(struct xgbe_prv_data
*pdata
)
675 struct xgbe_phy_data
*phy_data
;
678 phy_data
= devm_kzalloc(pdata
->dev
, sizeof(*phy_data
), GFP_KERNEL
);
682 /* Retrieve the PHY speedset */
683 ret
= device_property_read_u32(pdata
->phy_dev
, XGBE_SPEEDSET_PROPERTY
,
684 &phy_data
->speed_set
);
686 dev_err(pdata
->dev
, "invalid %s property\n",
687 XGBE_SPEEDSET_PROPERTY
);
691 switch (phy_data
->speed_set
) {
692 case XGBE_SPEEDSET_1000_10000
:
693 case XGBE_SPEEDSET_2500_10000
:
696 dev_err(pdata
->dev
, "invalid %s property\n",
697 XGBE_SPEEDSET_PROPERTY
);
701 /* Retrieve the PHY configuration properties */
702 if (device_property_present(pdata
->phy_dev
, XGBE_BLWC_PROPERTY
)) {
703 ret
= device_property_read_u32_array(pdata
->phy_dev
,
708 dev_err(pdata
->dev
, "invalid %s property\n",
713 memcpy(phy_data
->blwc
, xgbe_phy_blwc
,
714 sizeof(phy_data
->blwc
));
717 if (device_property_present(pdata
->phy_dev
, XGBE_CDR_RATE_PROPERTY
)) {
718 ret
= device_property_read_u32_array(pdata
->phy_dev
,
719 XGBE_CDR_RATE_PROPERTY
,
723 dev_err(pdata
->dev
, "invalid %s property\n",
724 XGBE_CDR_RATE_PROPERTY
);
728 memcpy(phy_data
->cdr_rate
, xgbe_phy_cdr_rate
,
729 sizeof(phy_data
->cdr_rate
));
732 if (device_property_present(pdata
->phy_dev
, XGBE_PQ_SKEW_PROPERTY
)) {
733 ret
= device_property_read_u32_array(pdata
->phy_dev
,
734 XGBE_PQ_SKEW_PROPERTY
,
738 dev_err(pdata
->dev
, "invalid %s property\n",
739 XGBE_PQ_SKEW_PROPERTY
);
743 memcpy(phy_data
->pq_skew
, xgbe_phy_pq_skew
,
744 sizeof(phy_data
->pq_skew
));
747 if (device_property_present(pdata
->phy_dev
, XGBE_TX_AMP_PROPERTY
)) {
748 ret
= device_property_read_u32_array(pdata
->phy_dev
,
749 XGBE_TX_AMP_PROPERTY
,
753 dev_err(pdata
->dev
, "invalid %s property\n",
754 XGBE_TX_AMP_PROPERTY
);
758 memcpy(phy_data
->tx_amp
, xgbe_phy_tx_amp
,
759 sizeof(phy_data
->tx_amp
));
762 if (device_property_present(pdata
->phy_dev
, XGBE_DFE_CFG_PROPERTY
)) {
763 ret
= device_property_read_u32_array(pdata
->phy_dev
,
764 XGBE_DFE_CFG_PROPERTY
,
765 phy_data
->dfe_tap_cfg
,
768 dev_err(pdata
->dev
, "invalid %s property\n",
769 XGBE_DFE_CFG_PROPERTY
);
773 memcpy(phy_data
->dfe_tap_cfg
, xgbe_phy_dfe_tap_cfg
,
774 sizeof(phy_data
->dfe_tap_cfg
));
777 if (device_property_present(pdata
->phy_dev
, XGBE_DFE_ENA_PROPERTY
)) {
778 ret
= device_property_read_u32_array(pdata
->phy_dev
,
779 XGBE_DFE_ENA_PROPERTY
,
780 phy_data
->dfe_tap_ena
,
783 dev_err(pdata
->dev
, "invalid %s property\n",
784 XGBE_DFE_ENA_PROPERTY
);
788 memcpy(phy_data
->dfe_tap_ena
, xgbe_phy_dfe_tap_ena
,
789 sizeof(phy_data
->dfe_tap_ena
));
792 /* Initialize supported features */
793 pdata
->phy
.supported
= SUPPORTED_Autoneg
;
794 pdata
->phy
.supported
|= SUPPORTED_Pause
| SUPPORTED_Asym_Pause
;
795 pdata
->phy
.supported
|= SUPPORTED_Backplane
;
796 pdata
->phy
.supported
|= SUPPORTED_10000baseKR_Full
;
797 switch (phy_data
->speed_set
) {
798 case XGBE_SPEEDSET_1000_10000
:
799 pdata
->phy
.supported
|= SUPPORTED_1000baseKX_Full
;
801 case XGBE_SPEEDSET_2500_10000
:
802 pdata
->phy
.supported
|= SUPPORTED_2500baseX_Full
;
806 if (pdata
->fec_ability
& MDIO_PMA_10GBR_FECABLE_ABLE
)
807 pdata
->phy
.supported
|= SUPPORTED_10000baseR_FEC
;
809 pdata
->phy_data
= phy_data
;
814 void xgbe_init_function_ptrs_phy_v1(struct xgbe_phy_if
*phy_if
)
816 struct xgbe_phy_impl_if
*phy_impl
= &phy_if
->phy_impl
;
818 phy_impl
->init
= xgbe_phy_init
;
819 phy_impl
->exit
= xgbe_phy_exit
;
821 phy_impl
->reset
= xgbe_phy_reset
;
822 phy_impl
->start
= xgbe_phy_start
;
823 phy_impl
->stop
= xgbe_phy_stop
;
825 phy_impl
->link_status
= xgbe_phy_link_status
;
827 phy_impl
->valid_speed
= xgbe_phy_valid_speed
;
829 phy_impl
->use_mode
= xgbe_phy_use_mode
;
830 phy_impl
->set_mode
= xgbe_phy_set_mode
;
831 phy_impl
->get_mode
= xgbe_phy_get_mode
;
832 phy_impl
->switch_mode
= xgbe_phy_switch_mode
;
833 phy_impl
->cur_mode
= xgbe_phy_cur_mode
;
835 phy_impl
->an_mode
= xgbe_phy_an_mode
;
837 phy_impl
->an_config
= xgbe_phy_an_config
;
839 phy_impl
->an_advertising
= xgbe_phy_an_advertising
;
841 phy_impl
->an_outcome
= xgbe_phy_an_outcome
;
843 phy_impl
->kr_training_pre
= xgbe_phy_kr_training_pre
;
844 phy_impl
->kr_training_post
= xgbe_phy_kr_training_post
;