xref: /openbmc/linux/drivers/net/ethernet/amd/xgbe/xgbe-phy-v1.c (revision cf40a76e7d5874bb25f4404eecc58a2e033af885)
1e57f7a3fSLendacky, Thomas /*
2e57f7a3fSLendacky, Thomas  * AMD 10Gb Ethernet driver
3e57f7a3fSLendacky, Thomas  *
4e57f7a3fSLendacky, Thomas  * This file is available to you under your choice of the following two
5e57f7a3fSLendacky, Thomas  * licenses:
6e57f7a3fSLendacky, Thomas  *
7e57f7a3fSLendacky, Thomas  * License 1: GPLv2
8e57f7a3fSLendacky, Thomas  *
9e57f7a3fSLendacky, Thomas  * Copyright (c) 2016 Advanced Micro Devices, Inc.
10e57f7a3fSLendacky, Thomas  *
11e57f7a3fSLendacky, Thomas  * This file is free software; you may copy, redistribute and/or modify
12e57f7a3fSLendacky, Thomas  * it under the terms of the GNU General Public License as published by
13e57f7a3fSLendacky, Thomas  * the Free Software Foundation, either version 2 of the License, or (at
14e57f7a3fSLendacky, Thomas  * your option) any later version.
15e57f7a3fSLendacky, Thomas  *
16e57f7a3fSLendacky, Thomas  * This file is distributed in the hope that it will be useful, but
17e57f7a3fSLendacky, Thomas  * WITHOUT ANY WARRANTY; without even the implied warranty of
18e57f7a3fSLendacky, Thomas  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19e57f7a3fSLendacky, Thomas  * General Public License for more details.
20e57f7a3fSLendacky, Thomas  *
21e57f7a3fSLendacky, Thomas  * You should have received a copy of the GNU General Public License
22e57f7a3fSLendacky, Thomas  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23e57f7a3fSLendacky, Thomas  *
24e57f7a3fSLendacky, Thomas  * This file incorporates work covered by the following copyright and
25e57f7a3fSLendacky, Thomas  * permission notice:
26e57f7a3fSLendacky, Thomas  *     The Synopsys DWC ETHER XGMAC Software Driver and documentation
27e57f7a3fSLendacky, Thomas  *     (hereinafter "Software") is an unsupported proprietary work of Synopsys,
28e57f7a3fSLendacky, Thomas  *     Inc. unless otherwise expressly agreed to in writing between Synopsys
29e57f7a3fSLendacky, Thomas  *     and you.
30e57f7a3fSLendacky, Thomas  *
31e57f7a3fSLendacky, Thomas  *     The Software IS NOT an item of Licensed Software or Licensed Product
32e57f7a3fSLendacky, Thomas  *     under any End User Software License Agreement or Agreement for Licensed
33e57f7a3fSLendacky, Thomas  *     Product with Synopsys or any supplement thereto.  Permission is hereby
34e57f7a3fSLendacky, Thomas  *     granted, free of charge, to any person obtaining a copy of this software
35e57f7a3fSLendacky, Thomas  *     annotated with this license and the Software, to deal in the Software
36e57f7a3fSLendacky, Thomas  *     without restriction, including without limitation the rights to use,
37e57f7a3fSLendacky, Thomas  *     copy, modify, merge, publish, distribute, sublicense, and/or sell copies
38e57f7a3fSLendacky, Thomas  *     of the Software, and to permit persons to whom the Software is furnished
39e57f7a3fSLendacky, Thomas  *     to do so, subject to the following conditions:
40e57f7a3fSLendacky, Thomas  *
41e57f7a3fSLendacky, Thomas  *     The above copyright notice and this permission notice shall be included
42e57f7a3fSLendacky, Thomas  *     in all copies or substantial portions of the Software.
43e57f7a3fSLendacky, Thomas  *
44e57f7a3fSLendacky, Thomas  *     THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
45e57f7a3fSLendacky, Thomas  *     BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
46e57f7a3fSLendacky, Thomas  *     TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
47e57f7a3fSLendacky, Thomas  *     PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS
48e57f7a3fSLendacky, Thomas  *     BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
49e57f7a3fSLendacky, Thomas  *     CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
50e57f7a3fSLendacky, Thomas  *     SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
51e57f7a3fSLendacky, Thomas  *     INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
52e57f7a3fSLendacky, Thomas  *     CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
53e57f7a3fSLendacky, Thomas  *     ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
54e57f7a3fSLendacky, Thomas  *     THE POSSIBILITY OF SUCH DAMAGE.
55e57f7a3fSLendacky, Thomas  *
56e57f7a3fSLendacky, Thomas  *
57e57f7a3fSLendacky, Thomas  * License 2: Modified BSD
58e57f7a3fSLendacky, Thomas  *
59e57f7a3fSLendacky, Thomas  * Copyright (c) 2016 Advanced Micro Devices, Inc.
60e57f7a3fSLendacky, Thomas  * All rights reserved.
61e57f7a3fSLendacky, Thomas  *
62e57f7a3fSLendacky, Thomas  * Redistribution and use in source and binary forms, with or without
63e57f7a3fSLendacky, Thomas  * modification, are permitted provided that the following conditions are met:
64e57f7a3fSLendacky, Thomas  *     * Redistributions of source code must retain the above copyright
65e57f7a3fSLendacky, Thomas  *       notice, this list of conditions and the following disclaimer.
66e57f7a3fSLendacky, Thomas  *     * Redistributions in binary form must reproduce the above copyright
67e57f7a3fSLendacky, Thomas  *       notice, this list of conditions and the following disclaimer in the
68e57f7a3fSLendacky, Thomas  *       documentation and/or other materials provided with the distribution.
69e57f7a3fSLendacky, Thomas  *     * Neither the name of Advanced Micro Devices, Inc. nor the
70e57f7a3fSLendacky, Thomas  *       names of its contributors may be used to endorse or promote products
71e57f7a3fSLendacky, Thomas  *       derived from this software without specific prior written permission.
72e57f7a3fSLendacky, Thomas  *
73e57f7a3fSLendacky, Thomas  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
74e57f7a3fSLendacky, Thomas  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
75e57f7a3fSLendacky, Thomas  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
76e57f7a3fSLendacky, Thomas  * ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
77e57f7a3fSLendacky, Thomas  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
78e57f7a3fSLendacky, Thomas  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
79e57f7a3fSLendacky, Thomas  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
80e57f7a3fSLendacky, Thomas  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
81e57f7a3fSLendacky, Thomas  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
82e57f7a3fSLendacky, Thomas  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
83e57f7a3fSLendacky, Thomas  *
84e57f7a3fSLendacky, Thomas  * This file incorporates work covered by the following copyright and
85e57f7a3fSLendacky, Thomas  * permission notice:
86e57f7a3fSLendacky, Thomas  *     The Synopsys DWC ETHER XGMAC Software Driver and documentation
87e57f7a3fSLendacky, Thomas  *     (hereinafter "Software") is an unsupported proprietary work of Synopsys,
88e57f7a3fSLendacky, Thomas  *     Inc. unless otherwise expressly agreed to in writing between Synopsys
89e57f7a3fSLendacky, Thomas  *     and you.
90e57f7a3fSLendacky, Thomas  *
91e57f7a3fSLendacky, Thomas  *     The Software IS NOT an item of Licensed Software or Licensed Product
92e57f7a3fSLendacky, Thomas  *     under any End User Software License Agreement or Agreement for Licensed
93e57f7a3fSLendacky, Thomas  *     Product with Synopsys or any supplement thereto.  Permission is hereby
94e57f7a3fSLendacky, Thomas  *     granted, free of charge, to any person obtaining a copy of this software
95e57f7a3fSLendacky, Thomas  *     annotated with this license and the Software, to deal in the Software
96e57f7a3fSLendacky, Thomas  *     without restriction, including without limitation the rights to use,
97e57f7a3fSLendacky, Thomas  *     copy, modify, merge, publish, distribute, sublicense, and/or sell copies
98e57f7a3fSLendacky, Thomas  *     of the Software, and to permit persons to whom the Software is furnished
99e57f7a3fSLendacky, Thomas  *     to do so, subject to the following conditions:
100e57f7a3fSLendacky, Thomas  *
101e57f7a3fSLendacky, Thomas  *     The above copyright notice and this permission notice shall be included
102e57f7a3fSLendacky, Thomas  *     in all copies or substantial portions of the Software.
103e57f7a3fSLendacky, Thomas  *
104e57f7a3fSLendacky, Thomas  *     THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
105e57f7a3fSLendacky, Thomas  *     BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
106e57f7a3fSLendacky, Thomas  *     TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
107e57f7a3fSLendacky, Thomas  *     PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS
108e57f7a3fSLendacky, Thomas  *     BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
109e57f7a3fSLendacky, Thomas  *     CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
110e57f7a3fSLendacky, Thomas  *     SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
111e57f7a3fSLendacky, Thomas  *     INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
112e57f7a3fSLendacky, Thomas  *     CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
113e57f7a3fSLendacky, Thomas  *     ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
114e57f7a3fSLendacky, Thomas  *     THE POSSIBILITY OF SUCH DAMAGE.
115e57f7a3fSLendacky, Thomas  */
116e57f7a3fSLendacky, Thomas 
117e57f7a3fSLendacky, Thomas #include <linux/module.h>
118e57f7a3fSLendacky, Thomas #include <linux/kmod.h>
119e57f7a3fSLendacky, Thomas #include <linux/device.h>
120e57f7a3fSLendacky, Thomas #include <linux/property.h>
121e57f7a3fSLendacky, Thomas #include <linux/mdio.h>
122e57f7a3fSLendacky, Thomas #include <linux/phy.h>
123e57f7a3fSLendacky, Thomas 
124e57f7a3fSLendacky, Thomas #include "xgbe.h"
125e57f7a3fSLendacky, Thomas #include "xgbe-common.h"
126e57f7a3fSLendacky, Thomas 
127e57f7a3fSLendacky, Thomas #define XGBE_BLWC_PROPERTY		"amd,serdes-blwc"
128e57f7a3fSLendacky, Thomas #define XGBE_CDR_RATE_PROPERTY		"amd,serdes-cdr-rate"
129e57f7a3fSLendacky, Thomas #define XGBE_PQ_SKEW_PROPERTY		"amd,serdes-pq-skew"
130e57f7a3fSLendacky, Thomas #define XGBE_TX_AMP_PROPERTY		"amd,serdes-tx-amp"
131e57f7a3fSLendacky, Thomas #define XGBE_DFE_CFG_PROPERTY		"amd,serdes-dfe-tap-config"
132e57f7a3fSLendacky, Thomas #define XGBE_DFE_ENA_PROPERTY		"amd,serdes-dfe-tap-enable"
133e57f7a3fSLendacky, Thomas 
134e57f7a3fSLendacky, Thomas /* Default SerDes settings */
135e57f7a3fSLendacky, Thomas #define XGBE_SPEED_1000_BLWC		1
136e57f7a3fSLendacky, Thomas #define XGBE_SPEED_1000_CDR		0x2
137e57f7a3fSLendacky, Thomas #define XGBE_SPEED_1000_PLL		0x0
138e57f7a3fSLendacky, Thomas #define XGBE_SPEED_1000_PQ		0xa
139e57f7a3fSLendacky, Thomas #define XGBE_SPEED_1000_RATE		0x3
140e57f7a3fSLendacky, Thomas #define XGBE_SPEED_1000_TXAMP		0xf
141e57f7a3fSLendacky, Thomas #define XGBE_SPEED_1000_WORD		0x1
142e57f7a3fSLendacky, Thomas #define XGBE_SPEED_1000_DFE_TAP_CONFIG	0x3
143e57f7a3fSLendacky, Thomas #define XGBE_SPEED_1000_DFE_TAP_ENABLE	0x0
144e57f7a3fSLendacky, Thomas 
145e57f7a3fSLendacky, Thomas #define XGBE_SPEED_2500_BLWC		1
146e57f7a3fSLendacky, Thomas #define XGBE_SPEED_2500_CDR		0x2
147e57f7a3fSLendacky, Thomas #define XGBE_SPEED_2500_PLL		0x0
148e57f7a3fSLendacky, Thomas #define XGBE_SPEED_2500_PQ		0xa
149e57f7a3fSLendacky, Thomas #define XGBE_SPEED_2500_RATE		0x1
150e57f7a3fSLendacky, Thomas #define XGBE_SPEED_2500_TXAMP		0xf
151e57f7a3fSLendacky, Thomas #define XGBE_SPEED_2500_WORD		0x1
152e57f7a3fSLendacky, Thomas #define XGBE_SPEED_2500_DFE_TAP_CONFIG	0x3
153e57f7a3fSLendacky, Thomas #define XGBE_SPEED_2500_DFE_TAP_ENABLE	0x0
154e57f7a3fSLendacky, Thomas 
155e57f7a3fSLendacky, Thomas #define XGBE_SPEED_10000_BLWC		0
156e57f7a3fSLendacky, Thomas #define XGBE_SPEED_10000_CDR		0x7
157e57f7a3fSLendacky, Thomas #define XGBE_SPEED_10000_PLL		0x1
158e57f7a3fSLendacky, Thomas #define XGBE_SPEED_10000_PQ		0x12
159e57f7a3fSLendacky, Thomas #define XGBE_SPEED_10000_RATE		0x0
160e57f7a3fSLendacky, Thomas #define XGBE_SPEED_10000_TXAMP		0xa
161e57f7a3fSLendacky, Thomas #define XGBE_SPEED_10000_WORD		0x7
162e57f7a3fSLendacky, Thomas #define XGBE_SPEED_10000_DFE_TAP_CONFIG	0x1
163e57f7a3fSLendacky, Thomas #define XGBE_SPEED_10000_DFE_TAP_ENABLE	0x7f
164e57f7a3fSLendacky, Thomas 
165e57f7a3fSLendacky, Thomas /* Rate-change complete wait/retry count */
166e57f7a3fSLendacky, Thomas #define XGBE_RATECHANGE_COUNT		500
167e57f7a3fSLendacky, Thomas 
168e57f7a3fSLendacky, Thomas static const u32 xgbe_phy_blwc[] = {
169e57f7a3fSLendacky, Thomas 	XGBE_SPEED_1000_BLWC,
170e57f7a3fSLendacky, Thomas 	XGBE_SPEED_2500_BLWC,
171e57f7a3fSLendacky, Thomas 	XGBE_SPEED_10000_BLWC,
172e57f7a3fSLendacky, Thomas };
173e57f7a3fSLendacky, Thomas 
174e57f7a3fSLendacky, Thomas static const u32 xgbe_phy_cdr_rate[] = {
175e57f7a3fSLendacky, Thomas 	XGBE_SPEED_1000_CDR,
176e57f7a3fSLendacky, Thomas 	XGBE_SPEED_2500_CDR,
177e57f7a3fSLendacky, Thomas 	XGBE_SPEED_10000_CDR,
178e57f7a3fSLendacky, Thomas };
179e57f7a3fSLendacky, Thomas 
180e57f7a3fSLendacky, Thomas static const u32 xgbe_phy_pq_skew[] = {
181e57f7a3fSLendacky, Thomas 	XGBE_SPEED_1000_PQ,
182e57f7a3fSLendacky, Thomas 	XGBE_SPEED_2500_PQ,
183e57f7a3fSLendacky, Thomas 	XGBE_SPEED_10000_PQ,
184e57f7a3fSLendacky, Thomas };
185e57f7a3fSLendacky, Thomas 
186e57f7a3fSLendacky, Thomas static const u32 xgbe_phy_tx_amp[] = {
187e57f7a3fSLendacky, Thomas 	XGBE_SPEED_1000_TXAMP,
188e57f7a3fSLendacky, Thomas 	XGBE_SPEED_2500_TXAMP,
189e57f7a3fSLendacky, Thomas 	XGBE_SPEED_10000_TXAMP,
190e57f7a3fSLendacky, Thomas };
191e57f7a3fSLendacky, Thomas 
192e57f7a3fSLendacky, Thomas static const u32 xgbe_phy_dfe_tap_cfg[] = {
193e57f7a3fSLendacky, Thomas 	XGBE_SPEED_1000_DFE_TAP_CONFIG,
194e57f7a3fSLendacky, Thomas 	XGBE_SPEED_2500_DFE_TAP_CONFIG,
195e57f7a3fSLendacky, Thomas 	XGBE_SPEED_10000_DFE_TAP_CONFIG,
196e57f7a3fSLendacky, Thomas };
197e57f7a3fSLendacky, Thomas 
198e57f7a3fSLendacky, Thomas static const u32 xgbe_phy_dfe_tap_ena[] = {
199e57f7a3fSLendacky, Thomas 	XGBE_SPEED_1000_DFE_TAP_ENABLE,
200e57f7a3fSLendacky, Thomas 	XGBE_SPEED_2500_DFE_TAP_ENABLE,
201e57f7a3fSLendacky, Thomas 	XGBE_SPEED_10000_DFE_TAP_ENABLE,
202e57f7a3fSLendacky, Thomas };
203e57f7a3fSLendacky, Thomas 
204e57f7a3fSLendacky, Thomas struct xgbe_phy_data {
205e57f7a3fSLendacky, Thomas 	/* 1000/10000 vs 2500/10000 indicator */
206e57f7a3fSLendacky, Thomas 	unsigned int speed_set;
207e57f7a3fSLendacky, Thomas 
208e57f7a3fSLendacky, Thomas 	/* SerDes UEFI configurable settings.
209e57f7a3fSLendacky, Thomas 	 *   Switching between modes/speeds requires new values for some
210e57f7a3fSLendacky, Thomas 	 *   SerDes settings.  The values can be supplied as device
211e57f7a3fSLendacky, Thomas 	 *   properties in array format.  The first array entry is for
212e57f7a3fSLendacky, Thomas 	 *   1GbE, second for 2.5GbE and third for 10GbE
213e57f7a3fSLendacky, Thomas 	 */
214e57f7a3fSLendacky, Thomas 	u32 blwc[XGBE_SPEEDS];
215e57f7a3fSLendacky, Thomas 	u32 cdr_rate[XGBE_SPEEDS];
216e57f7a3fSLendacky, Thomas 	u32 pq_skew[XGBE_SPEEDS];
217e57f7a3fSLendacky, Thomas 	u32 tx_amp[XGBE_SPEEDS];
218e57f7a3fSLendacky, Thomas 	u32 dfe_tap_cfg[XGBE_SPEEDS];
219e57f7a3fSLendacky, Thomas 	u32 dfe_tap_ena[XGBE_SPEEDS];
220e57f7a3fSLendacky, Thomas };
221e57f7a3fSLendacky, Thomas 
xgbe_phy_kr_training_pre(struct xgbe_prv_data * pdata)222e57f7a3fSLendacky, Thomas static void xgbe_phy_kr_training_pre(struct xgbe_prv_data *pdata)
223e57f7a3fSLendacky, Thomas {
224e57f7a3fSLendacky, Thomas 		XSIR0_IOWRITE_BITS(pdata, SIR0_KR_RT_1, RESET, 1);
225e57f7a3fSLendacky, Thomas }
226e57f7a3fSLendacky, Thomas 
xgbe_phy_kr_training_post(struct xgbe_prv_data * pdata)227e57f7a3fSLendacky, Thomas static void xgbe_phy_kr_training_post(struct xgbe_prv_data *pdata)
228e57f7a3fSLendacky, Thomas {
229e57f7a3fSLendacky, Thomas 		XSIR0_IOWRITE_BITS(pdata, SIR0_KR_RT_1, RESET, 0);
230e57f7a3fSLendacky, Thomas }
231e57f7a3fSLendacky, Thomas 
xgbe_phy_an_outcome(struct xgbe_prv_data * pdata)232e57f7a3fSLendacky, Thomas static enum xgbe_mode xgbe_phy_an_outcome(struct xgbe_prv_data *pdata)
233e57f7a3fSLendacky, Thomas {
234*85f9feb6SLendacky, Thomas 	struct ethtool_link_ksettings *lks = &pdata->phy.lks;
235e57f7a3fSLendacky, Thomas 	struct xgbe_phy_data *phy_data = pdata->phy_data;
236e57f7a3fSLendacky, Thomas 	enum xgbe_mode mode;
237e57f7a3fSLendacky, Thomas 	unsigned int ad_reg, lp_reg;
238e57f7a3fSLendacky, Thomas 
239*85f9feb6SLendacky, Thomas 	XGBE_SET_LP_ADV(lks, Autoneg);
240*85f9feb6SLendacky, Thomas 	XGBE_SET_LP_ADV(lks, Backplane);
241e57f7a3fSLendacky, Thomas 
242e57f7a3fSLendacky, Thomas 	/* Compare Advertisement and Link Partner register 1 */
243e57f7a3fSLendacky, Thomas 	ad_reg = XMDIO_READ(pdata, MDIO_MMD_AN, MDIO_AN_ADVERTISE);
244e57f7a3fSLendacky, Thomas 	lp_reg = XMDIO_READ(pdata, MDIO_MMD_AN, MDIO_AN_LPA);
245e57f7a3fSLendacky, Thomas 	if (lp_reg & 0x400)
246*85f9feb6SLendacky, Thomas 		XGBE_SET_LP_ADV(lks, Pause);
247e57f7a3fSLendacky, Thomas 	if (lp_reg & 0x800)
248*85f9feb6SLendacky, Thomas 		XGBE_SET_LP_ADV(lks, Asym_Pause);
249e57f7a3fSLendacky, Thomas 
250e57f7a3fSLendacky, Thomas 	if (pdata->phy.pause_autoneg) {
251e57f7a3fSLendacky, Thomas 		/* Set flow control based on auto-negotiation result */
252e57f7a3fSLendacky, Thomas 		pdata->phy.tx_pause = 0;
253e57f7a3fSLendacky, Thomas 		pdata->phy.rx_pause = 0;
254e57f7a3fSLendacky, Thomas 
255e57f7a3fSLendacky, Thomas 		if (ad_reg & lp_reg & 0x400) {
256e57f7a3fSLendacky, Thomas 			pdata->phy.tx_pause = 1;
257e57f7a3fSLendacky, Thomas 			pdata->phy.rx_pause = 1;
258e57f7a3fSLendacky, Thomas 		} else if (ad_reg & lp_reg & 0x800) {
259e57f7a3fSLendacky, Thomas 			if (ad_reg & 0x400)
260e57f7a3fSLendacky, Thomas 				pdata->phy.rx_pause = 1;
261e57f7a3fSLendacky, Thomas 			else if (lp_reg & 0x400)
262e57f7a3fSLendacky, Thomas 				pdata->phy.tx_pause = 1;
263e57f7a3fSLendacky, Thomas 		}
264e57f7a3fSLendacky, Thomas 	}
265e57f7a3fSLendacky, Thomas 
266e57f7a3fSLendacky, Thomas 	/* Compare Advertisement and Link Partner register 2 */
267e57f7a3fSLendacky, Thomas 	ad_reg = XMDIO_READ(pdata, MDIO_MMD_AN, MDIO_AN_ADVERTISE + 1);
268e57f7a3fSLendacky, Thomas 	lp_reg = XMDIO_READ(pdata, MDIO_MMD_AN, MDIO_AN_LPA + 1);
269e57f7a3fSLendacky, Thomas 	if (lp_reg & 0x80)
270*85f9feb6SLendacky, Thomas 		XGBE_SET_LP_ADV(lks, 10000baseKR_Full);
271e57f7a3fSLendacky, Thomas 	if (lp_reg & 0x20) {
272e57f7a3fSLendacky, Thomas 		if (phy_data->speed_set == XGBE_SPEEDSET_2500_10000)
273*85f9feb6SLendacky, Thomas 			XGBE_SET_LP_ADV(lks, 2500baseX_Full);
274e57f7a3fSLendacky, Thomas 		else
275*85f9feb6SLendacky, Thomas 			XGBE_SET_LP_ADV(lks, 1000baseKX_Full);
276e57f7a3fSLendacky, Thomas 	}
277e57f7a3fSLendacky, Thomas 
278e57f7a3fSLendacky, Thomas 	ad_reg &= lp_reg;
279e57f7a3fSLendacky, Thomas 	if (ad_reg & 0x80) {
280e57f7a3fSLendacky, Thomas 		mode = XGBE_MODE_KR;
281e57f7a3fSLendacky, Thomas 	} else if (ad_reg & 0x20) {
282e57f7a3fSLendacky, Thomas 		if (phy_data->speed_set == XGBE_SPEEDSET_2500_10000)
283e57f7a3fSLendacky, Thomas 			mode = XGBE_MODE_KX_2500;
284e57f7a3fSLendacky, Thomas 		else
285e57f7a3fSLendacky, Thomas 			mode = XGBE_MODE_KX_1000;
286e57f7a3fSLendacky, Thomas 	} else {
287e57f7a3fSLendacky, Thomas 		mode = XGBE_MODE_UNKNOWN;
288e57f7a3fSLendacky, Thomas 	}
289e57f7a3fSLendacky, Thomas 
290e57f7a3fSLendacky, Thomas 	/* Compare Advertisement and Link Partner register 3 */
291e57f7a3fSLendacky, Thomas 	ad_reg = XMDIO_READ(pdata, MDIO_MMD_AN, MDIO_AN_ADVERTISE + 2);
292e57f7a3fSLendacky, Thomas 	lp_reg = XMDIO_READ(pdata, MDIO_MMD_AN, MDIO_AN_LPA + 2);
293e57f7a3fSLendacky, Thomas 	if (lp_reg & 0xc000)
294*85f9feb6SLendacky, Thomas 		XGBE_SET_LP_ADV(lks, 10000baseR_FEC);
295e57f7a3fSLendacky, Thomas 
296e57f7a3fSLendacky, Thomas 	return mode;
297e57f7a3fSLendacky, Thomas }
298e57f7a3fSLendacky, Thomas 
xgbe_phy_an_advertising(struct xgbe_prv_data * pdata,struct ethtool_link_ksettings * dlks)299*85f9feb6SLendacky, Thomas static void xgbe_phy_an_advertising(struct xgbe_prv_data *pdata,
300*85f9feb6SLendacky, Thomas 				    struct ethtool_link_ksettings *dlks)
301d7445d1fSLendacky, Thomas {
302*85f9feb6SLendacky, Thomas 	struct ethtool_link_ksettings *slks = &pdata->phy.lks;
303*85f9feb6SLendacky, Thomas 
304*85f9feb6SLendacky, Thomas 	XGBE_LM_COPY(dlks, advertising, slks, advertising);
305d7445d1fSLendacky, Thomas }
306d7445d1fSLendacky, Thomas 
xgbe_phy_an_config(struct xgbe_prv_data * pdata)307abf0a1c2SLendacky, Thomas static int xgbe_phy_an_config(struct xgbe_prv_data *pdata)
308abf0a1c2SLendacky, Thomas {
309abf0a1c2SLendacky, Thomas 	/* Nothing uniquely required for an configuration */
310abf0a1c2SLendacky, Thomas 	return 0;
311abf0a1c2SLendacky, Thomas }
312abf0a1c2SLendacky, Thomas 
xgbe_phy_an_mode(struct xgbe_prv_data * pdata)313a64def41SLendacky, Thomas static enum xgbe_an_mode xgbe_phy_an_mode(struct xgbe_prv_data *pdata)
314a64def41SLendacky, Thomas {
315a64def41SLendacky, Thomas 	return XGBE_AN_MODE_CL73;
316a64def41SLendacky, Thomas }
317a64def41SLendacky, Thomas 
xgbe_phy_pcs_power_cycle(struct xgbe_prv_data * pdata)318e57f7a3fSLendacky, Thomas static void xgbe_phy_pcs_power_cycle(struct xgbe_prv_data *pdata)
319e57f7a3fSLendacky, Thomas {
320e57f7a3fSLendacky, Thomas 	unsigned int reg;
321e57f7a3fSLendacky, Thomas 
322e57f7a3fSLendacky, Thomas 	reg = XMDIO_READ(pdata, MDIO_MMD_PCS, MDIO_CTRL1);
323e57f7a3fSLendacky, Thomas 
324e57f7a3fSLendacky, Thomas 	reg |= MDIO_CTRL1_LPOWER;
325e57f7a3fSLendacky, Thomas 	XMDIO_WRITE(pdata, MDIO_MMD_PCS, MDIO_CTRL1, reg);
326e57f7a3fSLendacky, Thomas 
327e57f7a3fSLendacky, Thomas 	usleep_range(75, 100);
328e57f7a3fSLendacky, Thomas 
329e57f7a3fSLendacky, Thomas 	reg &= ~MDIO_CTRL1_LPOWER;
330e57f7a3fSLendacky, Thomas 	XMDIO_WRITE(pdata, MDIO_MMD_PCS, MDIO_CTRL1, reg);
331e57f7a3fSLendacky, Thomas }
332e57f7a3fSLendacky, Thomas 
xgbe_phy_start_ratechange(struct xgbe_prv_data * pdata)333e57f7a3fSLendacky, Thomas static void xgbe_phy_start_ratechange(struct xgbe_prv_data *pdata)
334e57f7a3fSLendacky, Thomas {
335e57f7a3fSLendacky, Thomas 	/* Assert Rx and Tx ratechange */
336e57f7a3fSLendacky, Thomas 	XSIR1_IOWRITE_BITS(pdata, SIR1_SPEED, RATECHANGE, 1);
337e57f7a3fSLendacky, Thomas }
338e57f7a3fSLendacky, Thomas 
xgbe_phy_complete_ratechange(struct xgbe_prv_data * pdata)339e57f7a3fSLendacky, Thomas static void xgbe_phy_complete_ratechange(struct xgbe_prv_data *pdata)
340e57f7a3fSLendacky, Thomas {
341e57f7a3fSLendacky, Thomas 	unsigned int wait;
342e57f7a3fSLendacky, Thomas 	u16 status;
343e57f7a3fSLendacky, Thomas 
344e57f7a3fSLendacky, Thomas 	/* Release Rx and Tx ratechange */
345e57f7a3fSLendacky, Thomas 	XSIR1_IOWRITE_BITS(pdata, SIR1_SPEED, RATECHANGE, 0);
346e57f7a3fSLendacky, Thomas 
347e57f7a3fSLendacky, Thomas 	/* Wait for Rx and Tx ready */
348e57f7a3fSLendacky, Thomas 	wait = XGBE_RATECHANGE_COUNT;
349e57f7a3fSLendacky, Thomas 	while (wait--) {
350e57f7a3fSLendacky, Thomas 		usleep_range(50, 75);
351e57f7a3fSLendacky, Thomas 
352e57f7a3fSLendacky, Thomas 		status = XSIR0_IOREAD(pdata, SIR0_STATUS);
353e57f7a3fSLendacky, Thomas 		if (XSIR_GET_BITS(status, SIR0_STATUS, RX_READY) &&
354e57f7a3fSLendacky, Thomas 		    XSIR_GET_BITS(status, SIR0_STATUS, TX_READY))
355e57f7a3fSLendacky, Thomas 			goto rx_reset;
356e57f7a3fSLendacky, Thomas 	}
357e57f7a3fSLendacky, Thomas 
358e57f7a3fSLendacky, Thomas 	netif_dbg(pdata, link, pdata->netdev, "SerDes rx/tx not ready (%#hx)\n",
359e57f7a3fSLendacky, Thomas 		  status);
360e57f7a3fSLendacky, Thomas 
361e57f7a3fSLendacky, Thomas rx_reset:
362e57f7a3fSLendacky, Thomas 	/* Perform Rx reset for the DFE changes */
363e57f7a3fSLendacky, Thomas 	XRXTX_IOWRITE_BITS(pdata, RXTX_REG6, RESETB_RXD, 0);
364e57f7a3fSLendacky, Thomas 	XRXTX_IOWRITE_BITS(pdata, RXTX_REG6, RESETB_RXD, 1);
365e57f7a3fSLendacky, Thomas }
366e57f7a3fSLendacky, Thomas 
xgbe_phy_kr_mode(struct xgbe_prv_data * pdata)367e57f7a3fSLendacky, Thomas static void xgbe_phy_kr_mode(struct xgbe_prv_data *pdata)
368e57f7a3fSLendacky, Thomas {
369e57f7a3fSLendacky, Thomas 	struct xgbe_phy_data *phy_data = pdata->phy_data;
370e57f7a3fSLendacky, Thomas 	unsigned int reg;
371e57f7a3fSLendacky, Thomas 
372e57f7a3fSLendacky, Thomas 	/* Set PCS to KR/10G speed */
373e57f7a3fSLendacky, Thomas 	reg = XMDIO_READ(pdata, MDIO_MMD_PCS, MDIO_CTRL2);
374e57f7a3fSLendacky, Thomas 	reg &= ~MDIO_PCS_CTRL2_TYPE;
375e57f7a3fSLendacky, Thomas 	reg |= MDIO_PCS_CTRL2_10GBR;
376e57f7a3fSLendacky, Thomas 	XMDIO_WRITE(pdata, MDIO_MMD_PCS, MDIO_CTRL2, reg);
377e57f7a3fSLendacky, Thomas 
378e57f7a3fSLendacky, Thomas 	reg = XMDIO_READ(pdata, MDIO_MMD_PCS, MDIO_CTRL1);
379e57f7a3fSLendacky, Thomas 	reg &= ~MDIO_CTRL1_SPEEDSEL;
380e57f7a3fSLendacky, Thomas 	reg |= MDIO_CTRL1_SPEED10G;
381e57f7a3fSLendacky, Thomas 	XMDIO_WRITE(pdata, MDIO_MMD_PCS, MDIO_CTRL1, reg);
382e57f7a3fSLendacky, Thomas 
383e57f7a3fSLendacky, Thomas 	xgbe_phy_pcs_power_cycle(pdata);
384e57f7a3fSLendacky, Thomas 
385e57f7a3fSLendacky, Thomas 	/* Set SerDes to 10G speed */
386e57f7a3fSLendacky, Thomas 	xgbe_phy_start_ratechange(pdata);
387e57f7a3fSLendacky, Thomas 
388e57f7a3fSLendacky, Thomas 	XSIR1_IOWRITE_BITS(pdata, SIR1_SPEED, DATARATE, XGBE_SPEED_10000_RATE);
389e57f7a3fSLendacky, Thomas 	XSIR1_IOWRITE_BITS(pdata, SIR1_SPEED, WORDMODE, XGBE_SPEED_10000_WORD);
390e57f7a3fSLendacky, Thomas 	XSIR1_IOWRITE_BITS(pdata, SIR1_SPEED, PLLSEL, XGBE_SPEED_10000_PLL);
391e57f7a3fSLendacky, Thomas 
392e57f7a3fSLendacky, Thomas 	XSIR1_IOWRITE_BITS(pdata, SIR1_SPEED, CDR_RATE,
393e57f7a3fSLendacky, Thomas 			   phy_data->cdr_rate[XGBE_SPEED_10000]);
394e57f7a3fSLendacky, Thomas 	XSIR1_IOWRITE_BITS(pdata, SIR1_SPEED, TXAMP,
395e57f7a3fSLendacky, Thomas 			   phy_data->tx_amp[XGBE_SPEED_10000]);
396e57f7a3fSLendacky, Thomas 	XRXTX_IOWRITE_BITS(pdata, RXTX_REG20, BLWC_ENA,
397e57f7a3fSLendacky, Thomas 			   phy_data->blwc[XGBE_SPEED_10000]);
398e57f7a3fSLendacky, Thomas 	XRXTX_IOWRITE_BITS(pdata, RXTX_REG114, PQ_REG,
399e57f7a3fSLendacky, Thomas 			   phy_data->pq_skew[XGBE_SPEED_10000]);
400e57f7a3fSLendacky, Thomas 	XRXTX_IOWRITE_BITS(pdata, RXTX_REG129, RXDFE_CONFIG,
401e57f7a3fSLendacky, Thomas 			   phy_data->dfe_tap_cfg[XGBE_SPEED_10000]);
402e57f7a3fSLendacky, Thomas 	XRXTX_IOWRITE(pdata, RXTX_REG22,
403e57f7a3fSLendacky, Thomas 		      phy_data->dfe_tap_ena[XGBE_SPEED_10000]);
404e57f7a3fSLendacky, Thomas 
405e57f7a3fSLendacky, Thomas 	xgbe_phy_complete_ratechange(pdata);
406e57f7a3fSLendacky, Thomas 
407e57f7a3fSLendacky, Thomas 	netif_dbg(pdata, link, pdata->netdev, "10GbE KR mode set\n");
408e57f7a3fSLendacky, Thomas }
409e57f7a3fSLendacky, Thomas 
xgbe_phy_kx_2500_mode(struct xgbe_prv_data * pdata)410e57f7a3fSLendacky, Thomas static void xgbe_phy_kx_2500_mode(struct xgbe_prv_data *pdata)
411e57f7a3fSLendacky, Thomas {
412e57f7a3fSLendacky, Thomas 	struct xgbe_phy_data *phy_data = pdata->phy_data;
413e57f7a3fSLendacky, Thomas 	unsigned int reg;
414e57f7a3fSLendacky, Thomas 
415e57f7a3fSLendacky, Thomas 	/* Set PCS to KX/1G speed */
416e57f7a3fSLendacky, Thomas 	reg = XMDIO_READ(pdata, MDIO_MMD_PCS, MDIO_CTRL2);
417e57f7a3fSLendacky, Thomas 	reg &= ~MDIO_PCS_CTRL2_TYPE;
418e57f7a3fSLendacky, Thomas 	reg |= MDIO_PCS_CTRL2_10GBX;
419e57f7a3fSLendacky, Thomas 	XMDIO_WRITE(pdata, MDIO_MMD_PCS, MDIO_CTRL2, reg);
420e57f7a3fSLendacky, Thomas 
421e57f7a3fSLendacky, Thomas 	reg = XMDIO_READ(pdata, MDIO_MMD_PCS, MDIO_CTRL1);
422e57f7a3fSLendacky, Thomas 	reg &= ~MDIO_CTRL1_SPEEDSEL;
423e57f7a3fSLendacky, Thomas 	reg |= MDIO_CTRL1_SPEED1G;
424e57f7a3fSLendacky, Thomas 	XMDIO_WRITE(pdata, MDIO_MMD_PCS, MDIO_CTRL1, reg);
425e57f7a3fSLendacky, Thomas 
426e57f7a3fSLendacky, Thomas 	xgbe_phy_pcs_power_cycle(pdata);
427e57f7a3fSLendacky, Thomas 
428e57f7a3fSLendacky, Thomas 	/* Set SerDes to 2.5G speed */
429e57f7a3fSLendacky, Thomas 	xgbe_phy_start_ratechange(pdata);
430e57f7a3fSLendacky, Thomas 
431e57f7a3fSLendacky, Thomas 	XSIR1_IOWRITE_BITS(pdata, SIR1_SPEED, DATARATE, XGBE_SPEED_2500_RATE);
432e57f7a3fSLendacky, Thomas 	XSIR1_IOWRITE_BITS(pdata, SIR1_SPEED, WORDMODE, XGBE_SPEED_2500_WORD);
433e57f7a3fSLendacky, Thomas 	XSIR1_IOWRITE_BITS(pdata, SIR1_SPEED, PLLSEL, XGBE_SPEED_2500_PLL);
434e57f7a3fSLendacky, Thomas 
435e57f7a3fSLendacky, Thomas 	XSIR1_IOWRITE_BITS(pdata, SIR1_SPEED, CDR_RATE,
436e57f7a3fSLendacky, Thomas 			   phy_data->cdr_rate[XGBE_SPEED_2500]);
437e57f7a3fSLendacky, Thomas 	XSIR1_IOWRITE_BITS(pdata, SIR1_SPEED, TXAMP,
438e57f7a3fSLendacky, Thomas 			   phy_data->tx_amp[XGBE_SPEED_2500]);
439e57f7a3fSLendacky, Thomas 	XRXTX_IOWRITE_BITS(pdata, RXTX_REG20, BLWC_ENA,
440e57f7a3fSLendacky, Thomas 			   phy_data->blwc[XGBE_SPEED_2500]);
441e57f7a3fSLendacky, Thomas 	XRXTX_IOWRITE_BITS(pdata, RXTX_REG114, PQ_REG,
442e57f7a3fSLendacky, Thomas 			   phy_data->pq_skew[XGBE_SPEED_2500]);
443e57f7a3fSLendacky, Thomas 	XRXTX_IOWRITE_BITS(pdata, RXTX_REG129, RXDFE_CONFIG,
444e57f7a3fSLendacky, Thomas 			   phy_data->dfe_tap_cfg[XGBE_SPEED_2500]);
445e57f7a3fSLendacky, Thomas 	XRXTX_IOWRITE(pdata, RXTX_REG22,
446e57f7a3fSLendacky, Thomas 		      phy_data->dfe_tap_ena[XGBE_SPEED_2500]);
447e57f7a3fSLendacky, Thomas 
448e57f7a3fSLendacky, Thomas 	xgbe_phy_complete_ratechange(pdata);
449e57f7a3fSLendacky, Thomas 
450e57f7a3fSLendacky, Thomas 	netif_dbg(pdata, link, pdata->netdev, "2.5GbE KX mode set\n");
451e57f7a3fSLendacky, Thomas }
452e57f7a3fSLendacky, Thomas 
xgbe_phy_kx_1000_mode(struct xgbe_prv_data * pdata)453e57f7a3fSLendacky, Thomas static void xgbe_phy_kx_1000_mode(struct xgbe_prv_data *pdata)
454e57f7a3fSLendacky, Thomas {
455e57f7a3fSLendacky, Thomas 	struct xgbe_phy_data *phy_data = pdata->phy_data;
456e57f7a3fSLendacky, Thomas 	unsigned int reg;
457e57f7a3fSLendacky, Thomas 
458e57f7a3fSLendacky, Thomas 	/* Set PCS to KX/1G speed */
459e57f7a3fSLendacky, Thomas 	reg = XMDIO_READ(pdata, MDIO_MMD_PCS, MDIO_CTRL2);
460e57f7a3fSLendacky, Thomas 	reg &= ~MDIO_PCS_CTRL2_TYPE;
461e57f7a3fSLendacky, Thomas 	reg |= MDIO_PCS_CTRL2_10GBX;
462e57f7a3fSLendacky, Thomas 	XMDIO_WRITE(pdata, MDIO_MMD_PCS, MDIO_CTRL2, reg);
463e57f7a3fSLendacky, Thomas 
464e57f7a3fSLendacky, Thomas 	reg = XMDIO_READ(pdata, MDIO_MMD_PCS, MDIO_CTRL1);
465e57f7a3fSLendacky, Thomas 	reg &= ~MDIO_CTRL1_SPEEDSEL;
466e57f7a3fSLendacky, Thomas 	reg |= MDIO_CTRL1_SPEED1G;
467e57f7a3fSLendacky, Thomas 	XMDIO_WRITE(pdata, MDIO_MMD_PCS, MDIO_CTRL1, reg);
468e57f7a3fSLendacky, Thomas 
469e57f7a3fSLendacky, Thomas 	xgbe_phy_pcs_power_cycle(pdata);
470e57f7a3fSLendacky, Thomas 
471e57f7a3fSLendacky, Thomas 	/* Set SerDes to 1G speed */
472e57f7a3fSLendacky, Thomas 	xgbe_phy_start_ratechange(pdata);
473e57f7a3fSLendacky, Thomas 
474e57f7a3fSLendacky, Thomas 	XSIR1_IOWRITE_BITS(pdata, SIR1_SPEED, DATARATE, XGBE_SPEED_1000_RATE);
475e57f7a3fSLendacky, Thomas 	XSIR1_IOWRITE_BITS(pdata, SIR1_SPEED, WORDMODE, XGBE_SPEED_1000_WORD);
476e57f7a3fSLendacky, Thomas 	XSIR1_IOWRITE_BITS(pdata, SIR1_SPEED, PLLSEL, XGBE_SPEED_1000_PLL);
477e57f7a3fSLendacky, Thomas 
478e57f7a3fSLendacky, Thomas 	XSIR1_IOWRITE_BITS(pdata, SIR1_SPEED, CDR_RATE,
479e57f7a3fSLendacky, Thomas 			   phy_data->cdr_rate[XGBE_SPEED_1000]);
480e57f7a3fSLendacky, Thomas 	XSIR1_IOWRITE_BITS(pdata, SIR1_SPEED, TXAMP,
481e57f7a3fSLendacky, Thomas 			   phy_data->tx_amp[XGBE_SPEED_1000]);
482e57f7a3fSLendacky, Thomas 	XRXTX_IOWRITE_BITS(pdata, RXTX_REG20, BLWC_ENA,
483e57f7a3fSLendacky, Thomas 			   phy_data->blwc[XGBE_SPEED_1000]);
484e57f7a3fSLendacky, Thomas 	XRXTX_IOWRITE_BITS(pdata, RXTX_REG114, PQ_REG,
485e57f7a3fSLendacky, Thomas 			   phy_data->pq_skew[XGBE_SPEED_1000]);
486e57f7a3fSLendacky, Thomas 	XRXTX_IOWRITE_BITS(pdata, RXTX_REG129, RXDFE_CONFIG,
487e57f7a3fSLendacky, Thomas 			   phy_data->dfe_tap_cfg[XGBE_SPEED_1000]);
488e57f7a3fSLendacky, Thomas 	XRXTX_IOWRITE(pdata, RXTX_REG22,
489e57f7a3fSLendacky, Thomas 		      phy_data->dfe_tap_ena[XGBE_SPEED_1000]);
490e57f7a3fSLendacky, Thomas 
491e57f7a3fSLendacky, Thomas 	xgbe_phy_complete_ratechange(pdata);
492e57f7a3fSLendacky, Thomas 
493e57f7a3fSLendacky, Thomas 	netif_dbg(pdata, link, pdata->netdev, "1GbE KX mode set\n");
494e57f7a3fSLendacky, Thomas }
495e57f7a3fSLendacky, Thomas 
xgbe_phy_cur_mode(struct xgbe_prv_data * pdata)496e57f7a3fSLendacky, Thomas static enum xgbe_mode xgbe_phy_cur_mode(struct xgbe_prv_data *pdata)
497e57f7a3fSLendacky, Thomas {
498e57f7a3fSLendacky, Thomas 	struct xgbe_phy_data *phy_data = pdata->phy_data;
499e57f7a3fSLendacky, Thomas 	enum xgbe_mode mode;
500e57f7a3fSLendacky, Thomas 	unsigned int reg;
501e57f7a3fSLendacky, Thomas 
502e57f7a3fSLendacky, Thomas 	reg = XMDIO_READ(pdata, MDIO_MMD_PCS, MDIO_CTRL2);
503e57f7a3fSLendacky, Thomas 	reg &= MDIO_PCS_CTRL2_TYPE;
504e57f7a3fSLendacky, Thomas 
505e57f7a3fSLendacky, Thomas 	if (reg == MDIO_PCS_CTRL2_10GBR) {
506e57f7a3fSLendacky, Thomas 		mode = XGBE_MODE_KR;
507e57f7a3fSLendacky, Thomas 	} else {
508e57f7a3fSLendacky, Thomas 		if (phy_data->speed_set == XGBE_SPEEDSET_2500_10000)
509e57f7a3fSLendacky, Thomas 			mode = XGBE_MODE_KX_2500;
510e57f7a3fSLendacky, Thomas 		else
511e57f7a3fSLendacky, Thomas 			mode = XGBE_MODE_KX_1000;
512e57f7a3fSLendacky, Thomas 	}
513e57f7a3fSLendacky, Thomas 
514e57f7a3fSLendacky, Thomas 	return mode;
515e57f7a3fSLendacky, Thomas }
516e57f7a3fSLendacky, Thomas 
xgbe_phy_switch_mode(struct xgbe_prv_data * pdata)517e57f7a3fSLendacky, Thomas static enum xgbe_mode xgbe_phy_switch_mode(struct xgbe_prv_data *pdata)
518e57f7a3fSLendacky, Thomas {
519e57f7a3fSLendacky, Thomas 	struct xgbe_phy_data *phy_data = pdata->phy_data;
520e57f7a3fSLendacky, Thomas 	enum xgbe_mode mode;
521e57f7a3fSLendacky, Thomas 
522e57f7a3fSLendacky, Thomas 	/* If we are in KR switch to KX, and vice-versa */
523e57f7a3fSLendacky, Thomas 	if (xgbe_phy_cur_mode(pdata) == XGBE_MODE_KR) {
524e57f7a3fSLendacky, Thomas 		if (phy_data->speed_set == XGBE_SPEEDSET_2500_10000)
525e57f7a3fSLendacky, Thomas 			mode = XGBE_MODE_KX_2500;
526e57f7a3fSLendacky, Thomas 		else
527e57f7a3fSLendacky, Thomas 			mode = XGBE_MODE_KX_1000;
528e57f7a3fSLendacky, Thomas 	} else {
529e57f7a3fSLendacky, Thomas 		mode = XGBE_MODE_KR;
530e57f7a3fSLendacky, Thomas 	}
531e57f7a3fSLendacky, Thomas 
532e57f7a3fSLendacky, Thomas 	return mode;
533e57f7a3fSLendacky, Thomas }
534e57f7a3fSLendacky, Thomas 
xgbe_phy_get_mode(struct xgbe_prv_data * pdata,int speed)535e57f7a3fSLendacky, Thomas static enum xgbe_mode xgbe_phy_get_mode(struct xgbe_prv_data *pdata,
536e57f7a3fSLendacky, Thomas 					int speed)
537e57f7a3fSLendacky, Thomas {
538e57f7a3fSLendacky, Thomas 	struct xgbe_phy_data *phy_data = pdata->phy_data;
539e57f7a3fSLendacky, Thomas 
540e57f7a3fSLendacky, Thomas 	switch (speed) {
541e57f7a3fSLendacky, Thomas 	case SPEED_1000:
542e57f7a3fSLendacky, Thomas 		return (phy_data->speed_set == XGBE_SPEEDSET_1000_10000)
543e57f7a3fSLendacky, Thomas 			? XGBE_MODE_KX_1000 : XGBE_MODE_UNKNOWN;
544e57f7a3fSLendacky, Thomas 	case SPEED_2500:
545e57f7a3fSLendacky, Thomas 		return (phy_data->speed_set == XGBE_SPEEDSET_2500_10000)
546e57f7a3fSLendacky, Thomas 			? XGBE_MODE_KX_2500 : XGBE_MODE_UNKNOWN;
547e57f7a3fSLendacky, Thomas 	case SPEED_10000:
548e57f7a3fSLendacky, Thomas 		return XGBE_MODE_KR;
549e57f7a3fSLendacky, Thomas 	default:
550e57f7a3fSLendacky, Thomas 		return XGBE_MODE_UNKNOWN;
551e57f7a3fSLendacky, Thomas 	}
552e57f7a3fSLendacky, Thomas }
553e57f7a3fSLendacky, Thomas 
xgbe_phy_set_mode(struct xgbe_prv_data * pdata,enum xgbe_mode mode)554e57f7a3fSLendacky, Thomas static void xgbe_phy_set_mode(struct xgbe_prv_data *pdata, enum xgbe_mode mode)
555e57f7a3fSLendacky, Thomas {
556e57f7a3fSLendacky, Thomas 	switch (mode) {
557e57f7a3fSLendacky, Thomas 	case XGBE_MODE_KX_1000:
558e57f7a3fSLendacky, Thomas 		xgbe_phy_kx_1000_mode(pdata);
559e57f7a3fSLendacky, Thomas 		break;
560e57f7a3fSLendacky, Thomas 	case XGBE_MODE_KX_2500:
561e57f7a3fSLendacky, Thomas 		xgbe_phy_kx_2500_mode(pdata);
562e57f7a3fSLendacky, Thomas 		break;
563e57f7a3fSLendacky, Thomas 	case XGBE_MODE_KR:
564e57f7a3fSLendacky, Thomas 		xgbe_phy_kr_mode(pdata);
565e57f7a3fSLendacky, Thomas 		break;
566e57f7a3fSLendacky, Thomas 	default:
567e57f7a3fSLendacky, Thomas 		break;
568e57f7a3fSLendacky, Thomas 	}
569e57f7a3fSLendacky, Thomas }
570e57f7a3fSLendacky, Thomas 
xgbe_phy_check_mode(struct xgbe_prv_data * pdata,enum xgbe_mode mode,bool advert)571e57f7a3fSLendacky, Thomas static bool xgbe_phy_check_mode(struct xgbe_prv_data *pdata,
572*85f9feb6SLendacky, Thomas 				enum xgbe_mode mode, bool advert)
573e57f7a3fSLendacky, Thomas {
574e57f7a3fSLendacky, Thomas 	if (pdata->phy.autoneg == AUTONEG_ENABLE) {
575*85f9feb6SLendacky, Thomas 		return advert;
576e57f7a3fSLendacky, Thomas 	} else {
577e57f7a3fSLendacky, Thomas 		enum xgbe_mode cur_mode;
578e57f7a3fSLendacky, Thomas 
579e57f7a3fSLendacky, Thomas 		cur_mode = xgbe_phy_get_mode(pdata, pdata->phy.speed);
580e57f7a3fSLendacky, Thomas 		if (cur_mode == mode)
581e57f7a3fSLendacky, Thomas 			return true;
582e57f7a3fSLendacky, Thomas 	}
583e57f7a3fSLendacky, Thomas 
584e57f7a3fSLendacky, Thomas 	return false;
585e57f7a3fSLendacky, Thomas }
586e57f7a3fSLendacky, Thomas 
xgbe_phy_use_mode(struct xgbe_prv_data * pdata,enum xgbe_mode mode)587e57f7a3fSLendacky, Thomas static bool xgbe_phy_use_mode(struct xgbe_prv_data *pdata, enum xgbe_mode mode)
588e57f7a3fSLendacky, Thomas {
589*85f9feb6SLendacky, Thomas 	struct ethtool_link_ksettings *lks = &pdata->phy.lks;
590*85f9feb6SLendacky, Thomas 
591e57f7a3fSLendacky, Thomas 	switch (mode) {
592e57f7a3fSLendacky, Thomas 	case XGBE_MODE_KX_1000:
593e57f7a3fSLendacky, Thomas 		return xgbe_phy_check_mode(pdata, mode,
594*85f9feb6SLendacky, Thomas 					   XGBE_ADV(lks, 1000baseKX_Full));
595e57f7a3fSLendacky, Thomas 	case XGBE_MODE_KX_2500:
596e57f7a3fSLendacky, Thomas 		return xgbe_phy_check_mode(pdata, mode,
597*85f9feb6SLendacky, Thomas 					   XGBE_ADV(lks, 2500baseX_Full));
598e57f7a3fSLendacky, Thomas 	case XGBE_MODE_KR:
599e57f7a3fSLendacky, Thomas 		return xgbe_phy_check_mode(pdata, mode,
600*85f9feb6SLendacky, Thomas 					   XGBE_ADV(lks, 10000baseKR_Full));
601e57f7a3fSLendacky, Thomas 	default:
602e57f7a3fSLendacky, Thomas 		return false;
603e57f7a3fSLendacky, Thomas 	}
604e57f7a3fSLendacky, Thomas }
605e57f7a3fSLendacky, Thomas 
xgbe_phy_valid_speed(struct xgbe_prv_data * pdata,int speed)606e57f7a3fSLendacky, Thomas static bool xgbe_phy_valid_speed(struct xgbe_prv_data *pdata, int speed)
607e57f7a3fSLendacky, Thomas {
608e57f7a3fSLendacky, Thomas 	struct xgbe_phy_data *phy_data = pdata->phy_data;
609e57f7a3fSLendacky, Thomas 
610e57f7a3fSLendacky, Thomas 	switch (speed) {
611e57f7a3fSLendacky, Thomas 	case SPEED_1000:
612e57f7a3fSLendacky, Thomas 		if (phy_data->speed_set != XGBE_SPEEDSET_1000_10000)
613e57f7a3fSLendacky, Thomas 			return false;
614e57f7a3fSLendacky, Thomas 		return true;
615e57f7a3fSLendacky, Thomas 	case SPEED_2500:
616e57f7a3fSLendacky, Thomas 		if (phy_data->speed_set != XGBE_SPEEDSET_2500_10000)
617e57f7a3fSLendacky, Thomas 			return false;
618e57f7a3fSLendacky, Thomas 		return true;
619e57f7a3fSLendacky, Thomas 	case SPEED_10000:
620e57f7a3fSLendacky, Thomas 		return true;
621e57f7a3fSLendacky, Thomas 	default:
622e57f7a3fSLendacky, Thomas 		return false;
623e57f7a3fSLendacky, Thomas 	}
624e57f7a3fSLendacky, Thomas }
625e57f7a3fSLendacky, Thomas 
xgbe_phy_link_status(struct xgbe_prv_data * pdata,int * an_restart)626abf0a1c2SLendacky, Thomas static int xgbe_phy_link_status(struct xgbe_prv_data *pdata, int *an_restart)
627e57f7a3fSLendacky, Thomas {
628e57f7a3fSLendacky, Thomas 	unsigned int reg;
629e57f7a3fSLendacky, Thomas 
630abf0a1c2SLendacky, Thomas 	*an_restart = 0;
631abf0a1c2SLendacky, Thomas 
632e57f7a3fSLendacky, Thomas 	/* Link status is latched low, so read once to clear
633e57f7a3fSLendacky, Thomas 	 * and then read again to get current state
634e57f7a3fSLendacky, Thomas 	 */
635e57f7a3fSLendacky, Thomas 	reg = XMDIO_READ(pdata, MDIO_MMD_PCS, MDIO_STAT1);
636e57f7a3fSLendacky, Thomas 	reg = XMDIO_READ(pdata, MDIO_MMD_PCS, MDIO_STAT1);
637e57f7a3fSLendacky, Thomas 
638e57f7a3fSLendacky, Thomas 	return (reg & MDIO_STAT1_LSTATUS) ? 1 : 0;
639e57f7a3fSLendacky, Thomas }
640e57f7a3fSLendacky, Thomas 
xgbe_phy_stop(struct xgbe_prv_data * pdata)641e57f7a3fSLendacky, Thomas static void xgbe_phy_stop(struct xgbe_prv_data *pdata)
642e57f7a3fSLendacky, Thomas {
643e57f7a3fSLendacky, Thomas 	/* Nothing uniquely required for stop */
644e57f7a3fSLendacky, Thomas }
645e57f7a3fSLendacky, Thomas 
xgbe_phy_start(struct xgbe_prv_data * pdata)646e57f7a3fSLendacky, Thomas static int xgbe_phy_start(struct xgbe_prv_data *pdata)
647e57f7a3fSLendacky, Thomas {
648e57f7a3fSLendacky, Thomas 	/* Nothing uniquely required for start */
649e57f7a3fSLendacky, Thomas 	return 0;
650e57f7a3fSLendacky, Thomas }
651e57f7a3fSLendacky, Thomas 
xgbe_phy_reset(struct xgbe_prv_data * pdata)652e57f7a3fSLendacky, Thomas static int xgbe_phy_reset(struct xgbe_prv_data *pdata)
653e57f7a3fSLendacky, Thomas {
654e57f7a3fSLendacky, Thomas 	unsigned int reg, count;
655e57f7a3fSLendacky, Thomas 
656e57f7a3fSLendacky, Thomas 	/* Perform a software reset of the PCS */
657e57f7a3fSLendacky, Thomas 	reg = XMDIO_READ(pdata, MDIO_MMD_PCS, MDIO_CTRL1);
658e57f7a3fSLendacky, Thomas 	reg |= MDIO_CTRL1_RESET;
659e57f7a3fSLendacky, Thomas 	XMDIO_WRITE(pdata, MDIO_MMD_PCS, MDIO_CTRL1, reg);
660e57f7a3fSLendacky, Thomas 
661e57f7a3fSLendacky, Thomas 	count = 50;
662e57f7a3fSLendacky, Thomas 	do {
663e57f7a3fSLendacky, Thomas 		msleep(20);
664e57f7a3fSLendacky, Thomas 		reg = XMDIO_READ(pdata, MDIO_MMD_PCS, MDIO_CTRL1);
665e57f7a3fSLendacky, Thomas 	} while ((reg & MDIO_CTRL1_RESET) && --count);
666e57f7a3fSLendacky, Thomas 
667e57f7a3fSLendacky, Thomas 	if (reg & MDIO_CTRL1_RESET)
668e57f7a3fSLendacky, Thomas 		return -ETIMEDOUT;
669e57f7a3fSLendacky, Thomas 
670e57f7a3fSLendacky, Thomas 	return 0;
671e57f7a3fSLendacky, Thomas }
672e57f7a3fSLendacky, Thomas 
xgbe_phy_exit(struct xgbe_prv_data * pdata)673e57f7a3fSLendacky, Thomas static void xgbe_phy_exit(struct xgbe_prv_data *pdata)
674e57f7a3fSLendacky, Thomas {
675e57f7a3fSLendacky, Thomas 	/* Nothing uniquely required for exit */
676e57f7a3fSLendacky, Thomas }
677e57f7a3fSLendacky, Thomas 
xgbe_phy_init(struct xgbe_prv_data * pdata)678e57f7a3fSLendacky, Thomas static int xgbe_phy_init(struct xgbe_prv_data *pdata)
679e57f7a3fSLendacky, Thomas {
680*85f9feb6SLendacky, Thomas 	struct ethtool_link_ksettings *lks = &pdata->phy.lks;
681e57f7a3fSLendacky, Thomas 	struct xgbe_phy_data *phy_data;
682e57f7a3fSLendacky, Thomas 	int ret;
683e57f7a3fSLendacky, Thomas 
684e57f7a3fSLendacky, Thomas 	phy_data = devm_kzalloc(pdata->dev, sizeof(*phy_data), GFP_KERNEL);
685e57f7a3fSLendacky, Thomas 	if (!phy_data)
686e57f7a3fSLendacky, Thomas 		return -ENOMEM;
687e57f7a3fSLendacky, Thomas 
688e57f7a3fSLendacky, Thomas 	/* Retrieve the PHY speedset */
689e57f7a3fSLendacky, Thomas 	ret = device_property_read_u32(pdata->phy_dev, XGBE_SPEEDSET_PROPERTY,
690e57f7a3fSLendacky, Thomas 				       &phy_data->speed_set);
691e57f7a3fSLendacky, Thomas 	if (ret) {
692e57f7a3fSLendacky, Thomas 		dev_err(pdata->dev, "invalid %s property\n",
693e57f7a3fSLendacky, Thomas 			XGBE_SPEEDSET_PROPERTY);
694e57f7a3fSLendacky, Thomas 		return ret;
695e57f7a3fSLendacky, Thomas 	}
696e57f7a3fSLendacky, Thomas 
697e57f7a3fSLendacky, Thomas 	switch (phy_data->speed_set) {
698e57f7a3fSLendacky, Thomas 	case XGBE_SPEEDSET_1000_10000:
699e57f7a3fSLendacky, Thomas 	case XGBE_SPEEDSET_2500_10000:
700e57f7a3fSLendacky, Thomas 		break;
701e57f7a3fSLendacky, Thomas 	default:
702e57f7a3fSLendacky, Thomas 		dev_err(pdata->dev, "invalid %s property\n",
703e57f7a3fSLendacky, Thomas 			XGBE_SPEEDSET_PROPERTY);
704e57f7a3fSLendacky, Thomas 		return -EINVAL;
705e57f7a3fSLendacky, Thomas 	}
706e57f7a3fSLendacky, Thomas 
707e57f7a3fSLendacky, Thomas 	/* Retrieve the PHY configuration properties */
708e57f7a3fSLendacky, Thomas 	if (device_property_present(pdata->phy_dev, XGBE_BLWC_PROPERTY)) {
709e57f7a3fSLendacky, Thomas 		ret = device_property_read_u32_array(pdata->phy_dev,
710e57f7a3fSLendacky, Thomas 						     XGBE_BLWC_PROPERTY,
711e57f7a3fSLendacky, Thomas 						     phy_data->blwc,
712e57f7a3fSLendacky, Thomas 						     XGBE_SPEEDS);
713e57f7a3fSLendacky, Thomas 		if (ret) {
714e57f7a3fSLendacky, Thomas 			dev_err(pdata->dev, "invalid %s property\n",
715e57f7a3fSLendacky, Thomas 				XGBE_BLWC_PROPERTY);
716e57f7a3fSLendacky, Thomas 			return ret;
717e57f7a3fSLendacky, Thomas 		}
718e57f7a3fSLendacky, Thomas 	} else {
719e57f7a3fSLendacky, Thomas 		memcpy(phy_data->blwc, xgbe_phy_blwc,
720e57f7a3fSLendacky, Thomas 		       sizeof(phy_data->blwc));
721e57f7a3fSLendacky, Thomas 	}
722e57f7a3fSLendacky, Thomas 
723e57f7a3fSLendacky, Thomas 	if (device_property_present(pdata->phy_dev, XGBE_CDR_RATE_PROPERTY)) {
724e57f7a3fSLendacky, Thomas 		ret = device_property_read_u32_array(pdata->phy_dev,
725e57f7a3fSLendacky, Thomas 						     XGBE_CDR_RATE_PROPERTY,
726e57f7a3fSLendacky, Thomas 						     phy_data->cdr_rate,
727e57f7a3fSLendacky, Thomas 						     XGBE_SPEEDS);
728e57f7a3fSLendacky, Thomas 		if (ret) {
729e57f7a3fSLendacky, Thomas 			dev_err(pdata->dev, "invalid %s property\n",
730e57f7a3fSLendacky, Thomas 				XGBE_CDR_RATE_PROPERTY);
731e57f7a3fSLendacky, Thomas 			return ret;
732e57f7a3fSLendacky, Thomas 		}
733e57f7a3fSLendacky, Thomas 	} else {
734e57f7a3fSLendacky, Thomas 		memcpy(phy_data->cdr_rate, xgbe_phy_cdr_rate,
735e57f7a3fSLendacky, Thomas 		       sizeof(phy_data->cdr_rate));
736e57f7a3fSLendacky, Thomas 	}
737e57f7a3fSLendacky, Thomas 
738e57f7a3fSLendacky, Thomas 	if (device_property_present(pdata->phy_dev, XGBE_PQ_SKEW_PROPERTY)) {
739e57f7a3fSLendacky, Thomas 		ret = device_property_read_u32_array(pdata->phy_dev,
740e57f7a3fSLendacky, Thomas 						     XGBE_PQ_SKEW_PROPERTY,
741e57f7a3fSLendacky, Thomas 						     phy_data->pq_skew,
742e57f7a3fSLendacky, Thomas 						     XGBE_SPEEDS);
743e57f7a3fSLendacky, Thomas 		if (ret) {
744e57f7a3fSLendacky, Thomas 			dev_err(pdata->dev, "invalid %s property\n",
745e57f7a3fSLendacky, Thomas 				XGBE_PQ_SKEW_PROPERTY);
746e57f7a3fSLendacky, Thomas 			return ret;
747e57f7a3fSLendacky, Thomas 		}
748e57f7a3fSLendacky, Thomas 	} else {
749e57f7a3fSLendacky, Thomas 		memcpy(phy_data->pq_skew, xgbe_phy_pq_skew,
750e57f7a3fSLendacky, Thomas 		       sizeof(phy_data->pq_skew));
751e57f7a3fSLendacky, Thomas 	}
752e57f7a3fSLendacky, Thomas 
753e57f7a3fSLendacky, Thomas 	if (device_property_present(pdata->phy_dev, XGBE_TX_AMP_PROPERTY)) {
754e57f7a3fSLendacky, Thomas 		ret = device_property_read_u32_array(pdata->phy_dev,
755e57f7a3fSLendacky, Thomas 						     XGBE_TX_AMP_PROPERTY,
756e57f7a3fSLendacky, Thomas 						     phy_data->tx_amp,
757e57f7a3fSLendacky, Thomas 						     XGBE_SPEEDS);
758e57f7a3fSLendacky, Thomas 		if (ret) {
759e57f7a3fSLendacky, Thomas 			dev_err(pdata->dev, "invalid %s property\n",
760e57f7a3fSLendacky, Thomas 				XGBE_TX_AMP_PROPERTY);
761e57f7a3fSLendacky, Thomas 			return ret;
762e57f7a3fSLendacky, Thomas 		}
763e57f7a3fSLendacky, Thomas 	} else {
764e57f7a3fSLendacky, Thomas 		memcpy(phy_data->tx_amp, xgbe_phy_tx_amp,
765e57f7a3fSLendacky, Thomas 		       sizeof(phy_data->tx_amp));
766e57f7a3fSLendacky, Thomas 	}
767e57f7a3fSLendacky, Thomas 
768e57f7a3fSLendacky, Thomas 	if (device_property_present(pdata->phy_dev, XGBE_DFE_CFG_PROPERTY)) {
769e57f7a3fSLendacky, Thomas 		ret = device_property_read_u32_array(pdata->phy_dev,
770e57f7a3fSLendacky, Thomas 						     XGBE_DFE_CFG_PROPERTY,
771e57f7a3fSLendacky, Thomas 						     phy_data->dfe_tap_cfg,
772e57f7a3fSLendacky, Thomas 						     XGBE_SPEEDS);
773e57f7a3fSLendacky, Thomas 		if (ret) {
774e57f7a3fSLendacky, Thomas 			dev_err(pdata->dev, "invalid %s property\n",
775e57f7a3fSLendacky, Thomas 				XGBE_DFE_CFG_PROPERTY);
776e57f7a3fSLendacky, Thomas 			return ret;
777e57f7a3fSLendacky, Thomas 		}
778e57f7a3fSLendacky, Thomas 	} else {
779e57f7a3fSLendacky, Thomas 		memcpy(phy_data->dfe_tap_cfg, xgbe_phy_dfe_tap_cfg,
780e57f7a3fSLendacky, Thomas 		       sizeof(phy_data->dfe_tap_cfg));
781e57f7a3fSLendacky, Thomas 	}
782e57f7a3fSLendacky, Thomas 
783e57f7a3fSLendacky, Thomas 	if (device_property_present(pdata->phy_dev, XGBE_DFE_ENA_PROPERTY)) {
784e57f7a3fSLendacky, Thomas 		ret = device_property_read_u32_array(pdata->phy_dev,
785e57f7a3fSLendacky, Thomas 						     XGBE_DFE_ENA_PROPERTY,
786e57f7a3fSLendacky, Thomas 						     phy_data->dfe_tap_ena,
787e57f7a3fSLendacky, Thomas 						     XGBE_SPEEDS);
788e57f7a3fSLendacky, Thomas 		if (ret) {
789e57f7a3fSLendacky, Thomas 			dev_err(pdata->dev, "invalid %s property\n",
790e57f7a3fSLendacky, Thomas 				XGBE_DFE_ENA_PROPERTY);
791e57f7a3fSLendacky, Thomas 			return ret;
792e57f7a3fSLendacky, Thomas 		}
793e57f7a3fSLendacky, Thomas 	} else {
794e57f7a3fSLendacky, Thomas 		memcpy(phy_data->dfe_tap_ena, xgbe_phy_dfe_tap_ena,
795e57f7a3fSLendacky, Thomas 		       sizeof(phy_data->dfe_tap_ena));
796e57f7a3fSLendacky, Thomas 	}
797e57f7a3fSLendacky, Thomas 
798e57f7a3fSLendacky, Thomas 	/* Initialize supported features */
799*85f9feb6SLendacky, Thomas 	XGBE_ZERO_SUP(lks);
800*85f9feb6SLendacky, Thomas 	XGBE_SET_SUP(lks, Autoneg);
801*85f9feb6SLendacky, Thomas 	XGBE_SET_SUP(lks, Pause);
802*85f9feb6SLendacky, Thomas 	XGBE_SET_SUP(lks, Asym_Pause);
803*85f9feb6SLendacky, Thomas 	XGBE_SET_SUP(lks, Backplane);
804*85f9feb6SLendacky, Thomas 	XGBE_SET_SUP(lks, 10000baseKR_Full);
805e57f7a3fSLendacky, Thomas 	switch (phy_data->speed_set) {
806e57f7a3fSLendacky, Thomas 	case XGBE_SPEEDSET_1000_10000:
807*85f9feb6SLendacky, Thomas 		XGBE_SET_SUP(lks, 1000baseKX_Full);
808e57f7a3fSLendacky, Thomas 		break;
809e57f7a3fSLendacky, Thomas 	case XGBE_SPEEDSET_2500_10000:
810*85f9feb6SLendacky, Thomas 		XGBE_SET_SUP(lks, 2500baseX_Full);
811e57f7a3fSLendacky, Thomas 		break;
812e57f7a3fSLendacky, Thomas 	}
813e57f7a3fSLendacky, Thomas 
814e57f7a3fSLendacky, Thomas 	if (pdata->fec_ability & MDIO_PMA_10GBR_FECABLE_ABLE)
815*85f9feb6SLendacky, Thomas 		XGBE_SET_SUP(lks, 10000baseR_FEC);
816e57f7a3fSLendacky, Thomas 
817e57f7a3fSLendacky, Thomas 	pdata->phy_data = phy_data;
818e57f7a3fSLendacky, Thomas 
819e57f7a3fSLendacky, Thomas 	return 0;
820e57f7a3fSLendacky, Thomas }
821e57f7a3fSLendacky, Thomas 
xgbe_init_function_ptrs_phy_v1(struct xgbe_phy_if * phy_if)822e57f7a3fSLendacky, Thomas void xgbe_init_function_ptrs_phy_v1(struct xgbe_phy_if *phy_if)
823e57f7a3fSLendacky, Thomas {
824e57f7a3fSLendacky, Thomas 	struct xgbe_phy_impl_if *phy_impl = &phy_if->phy_impl;
825e57f7a3fSLendacky, Thomas 
826e57f7a3fSLendacky, Thomas 	phy_impl->init			= xgbe_phy_init;
827e57f7a3fSLendacky, Thomas 	phy_impl->exit			= xgbe_phy_exit;
828e57f7a3fSLendacky, Thomas 
829e57f7a3fSLendacky, Thomas 	phy_impl->reset			= xgbe_phy_reset;
830e57f7a3fSLendacky, Thomas 	phy_impl->start			= xgbe_phy_start;
831e57f7a3fSLendacky, Thomas 	phy_impl->stop			= xgbe_phy_stop;
832e57f7a3fSLendacky, Thomas 
833e57f7a3fSLendacky, Thomas 	phy_impl->link_status		= xgbe_phy_link_status;
834e57f7a3fSLendacky, Thomas 
835e57f7a3fSLendacky, Thomas 	phy_impl->valid_speed		= xgbe_phy_valid_speed;
836e57f7a3fSLendacky, Thomas 
837e57f7a3fSLendacky, Thomas 	phy_impl->use_mode		= xgbe_phy_use_mode;
838e57f7a3fSLendacky, Thomas 	phy_impl->set_mode		= xgbe_phy_set_mode;
839e57f7a3fSLendacky, Thomas 	phy_impl->get_mode		= xgbe_phy_get_mode;
840e57f7a3fSLendacky, Thomas 	phy_impl->switch_mode		= xgbe_phy_switch_mode;
841e57f7a3fSLendacky, Thomas 	phy_impl->cur_mode		= xgbe_phy_cur_mode;
842e57f7a3fSLendacky, Thomas 
843a64def41SLendacky, Thomas 	phy_impl->an_mode		= xgbe_phy_an_mode;
844a64def41SLendacky, Thomas 
845abf0a1c2SLendacky, Thomas 	phy_impl->an_config		= xgbe_phy_an_config;
846abf0a1c2SLendacky, Thomas 
847d7445d1fSLendacky, Thomas 	phy_impl->an_advertising	= xgbe_phy_an_advertising;
848d7445d1fSLendacky, Thomas 
849e57f7a3fSLendacky, Thomas 	phy_impl->an_outcome		= xgbe_phy_an_outcome;
850e57f7a3fSLendacky, Thomas 
851e57f7a3fSLendacky, Thomas 	phy_impl->kr_training_pre	= xgbe_phy_kr_training_pre;
852e57f7a3fSLendacky, Thomas 	phy_impl->kr_training_post	= xgbe_phy_kr_training_post;
853e57f7a3fSLendacky, Thomas }
854