1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-only
2*4882a593Smuzhiyun /****************************************************************************
3*4882a593Smuzhiyun * Driver for Solarflare network controllers and boards
4*4882a593Smuzhiyun * Copyright 2006-2011 Solarflare Communications Inc.
5*4882a593Smuzhiyun */
6*4882a593Smuzhiyun
7*4882a593Smuzhiyun /*
8*4882a593Smuzhiyun * Driver for Transwitch/Mysticom CX4 retimer
9*4882a593Smuzhiyun * see www.transwitch.com, part is TXC-43128
10*4882a593Smuzhiyun */
11*4882a593Smuzhiyun
12*4882a593Smuzhiyun #include <linux/delay.h>
13*4882a593Smuzhiyun #include <linux/slab.h>
14*4882a593Smuzhiyun #include "efx.h"
15*4882a593Smuzhiyun #include "mdio_10g.h"
16*4882a593Smuzhiyun #include "phy.h"
17*4882a593Smuzhiyun #include "nic.h"
18*4882a593Smuzhiyun
19*4882a593Smuzhiyun /* We expect these MMDs to be in the package */
20*4882a593Smuzhiyun #define TXC_REQUIRED_DEVS (MDIO_DEVS_PCS | \
21*4882a593Smuzhiyun MDIO_DEVS_PMAPMD | \
22*4882a593Smuzhiyun MDIO_DEVS_PHYXS)
23*4882a593Smuzhiyun
24*4882a593Smuzhiyun #define TXC_LOOPBACKS ((1 << LOOPBACK_PCS) | \
25*4882a593Smuzhiyun (1 << LOOPBACK_PMAPMD) | \
26*4882a593Smuzhiyun (1 << LOOPBACK_PHYXS_WS))
27*4882a593Smuzhiyun
28*4882a593Smuzhiyun /**************************************************************************
29*4882a593Smuzhiyun *
30*4882a593Smuzhiyun * Compile-time config
31*4882a593Smuzhiyun *
32*4882a593Smuzhiyun **************************************************************************
33*4882a593Smuzhiyun */
34*4882a593Smuzhiyun #define TXCNAME "TXC43128"
35*4882a593Smuzhiyun /* Total length of time we'll wait for the PHY to come out of reset (ms) */
36*4882a593Smuzhiyun #define TXC_MAX_RESET_TIME 500
37*4882a593Smuzhiyun /* Interval between checks (ms) */
38*4882a593Smuzhiyun #define TXC_RESET_WAIT 10
39*4882a593Smuzhiyun /* How long to run BIST (us) */
40*4882a593Smuzhiyun #define TXC_BIST_DURATION 50
41*4882a593Smuzhiyun
42*4882a593Smuzhiyun /**************************************************************************
43*4882a593Smuzhiyun *
44*4882a593Smuzhiyun * Register definitions
45*4882a593Smuzhiyun *
46*4882a593Smuzhiyun **************************************************************************
47*4882a593Smuzhiyun */
48*4882a593Smuzhiyun
49*4882a593Smuzhiyun /* Command register */
50*4882a593Smuzhiyun #define TXC_GLRGS_GLCMD 0xc004
51*4882a593Smuzhiyun /* Useful bits in command register */
52*4882a593Smuzhiyun /* Lane power-down */
53*4882a593Smuzhiyun #define TXC_GLCMD_L01PD_LBN 5
54*4882a593Smuzhiyun #define TXC_GLCMD_L23PD_LBN 6
55*4882a593Smuzhiyun /* Limited SW reset: preserves configuration but
56*4882a593Smuzhiyun * initiates a logic reset. Self-clearing */
57*4882a593Smuzhiyun #define TXC_GLCMD_LMTSWRST_LBN 14
58*4882a593Smuzhiyun
59*4882a593Smuzhiyun /* Signal Quality Control */
60*4882a593Smuzhiyun #define TXC_GLRGS_GSGQLCTL 0xc01a
61*4882a593Smuzhiyun /* Enable bit */
62*4882a593Smuzhiyun #define TXC_GSGQLCT_SGQLEN_LBN 15
63*4882a593Smuzhiyun /* Lane selection */
64*4882a593Smuzhiyun #define TXC_GSGQLCT_LNSL_LBN 13
65*4882a593Smuzhiyun #define TXC_GSGQLCT_LNSL_WIDTH 2
66*4882a593Smuzhiyun
67*4882a593Smuzhiyun /* Analog TX control */
68*4882a593Smuzhiyun #define TXC_ALRGS_ATXCTL 0xc040
69*4882a593Smuzhiyun /* Lane power-down */
70*4882a593Smuzhiyun #define TXC_ATXCTL_TXPD3_LBN 15
71*4882a593Smuzhiyun #define TXC_ATXCTL_TXPD2_LBN 14
72*4882a593Smuzhiyun #define TXC_ATXCTL_TXPD1_LBN 13
73*4882a593Smuzhiyun #define TXC_ATXCTL_TXPD0_LBN 12
74*4882a593Smuzhiyun
75*4882a593Smuzhiyun /* Amplitude on lanes 0, 1 */
76*4882a593Smuzhiyun #define TXC_ALRGS_ATXAMP0 0xc041
77*4882a593Smuzhiyun /* Amplitude on lanes 2, 3 */
78*4882a593Smuzhiyun #define TXC_ALRGS_ATXAMP1 0xc042
79*4882a593Smuzhiyun /* Bit position of value for lane 0 (or 2) */
80*4882a593Smuzhiyun #define TXC_ATXAMP_LANE02_LBN 3
81*4882a593Smuzhiyun /* Bit position of value for lane 1 (or 3) */
82*4882a593Smuzhiyun #define TXC_ATXAMP_LANE13_LBN 11
83*4882a593Smuzhiyun
84*4882a593Smuzhiyun #define TXC_ATXAMP_1280_mV 0
85*4882a593Smuzhiyun #define TXC_ATXAMP_1200_mV 8
86*4882a593Smuzhiyun #define TXC_ATXAMP_1120_mV 12
87*4882a593Smuzhiyun #define TXC_ATXAMP_1060_mV 14
88*4882a593Smuzhiyun #define TXC_ATXAMP_0820_mV 25
89*4882a593Smuzhiyun #define TXC_ATXAMP_0720_mV 26
90*4882a593Smuzhiyun #define TXC_ATXAMP_0580_mV 27
91*4882a593Smuzhiyun #define TXC_ATXAMP_0440_mV 28
92*4882a593Smuzhiyun
93*4882a593Smuzhiyun #define TXC_ATXAMP_0820_BOTH \
94*4882a593Smuzhiyun ((TXC_ATXAMP_0820_mV << TXC_ATXAMP_LANE02_LBN) \
95*4882a593Smuzhiyun | (TXC_ATXAMP_0820_mV << TXC_ATXAMP_LANE13_LBN))
96*4882a593Smuzhiyun
97*4882a593Smuzhiyun #define TXC_ATXAMP_DEFAULT 0x6060 /* From databook */
98*4882a593Smuzhiyun
99*4882a593Smuzhiyun /* Preemphasis on lanes 0, 1 */
100*4882a593Smuzhiyun #define TXC_ALRGS_ATXPRE0 0xc043
101*4882a593Smuzhiyun /* Preemphasis on lanes 2, 3 */
102*4882a593Smuzhiyun #define TXC_ALRGS_ATXPRE1 0xc044
103*4882a593Smuzhiyun
104*4882a593Smuzhiyun #define TXC_ATXPRE_NONE 0
105*4882a593Smuzhiyun #define TXC_ATXPRE_DEFAULT 0x1010 /* From databook */
106*4882a593Smuzhiyun
107*4882a593Smuzhiyun #define TXC_ALRGS_ARXCTL 0xc045
108*4882a593Smuzhiyun /* Lane power-down */
109*4882a593Smuzhiyun #define TXC_ARXCTL_RXPD3_LBN 15
110*4882a593Smuzhiyun #define TXC_ARXCTL_RXPD2_LBN 14
111*4882a593Smuzhiyun #define TXC_ARXCTL_RXPD1_LBN 13
112*4882a593Smuzhiyun #define TXC_ARXCTL_RXPD0_LBN 12
113*4882a593Smuzhiyun
114*4882a593Smuzhiyun /* Main control */
115*4882a593Smuzhiyun #define TXC_MRGS_CTL 0xc340
116*4882a593Smuzhiyun /* Bits in main control */
117*4882a593Smuzhiyun #define TXC_MCTL_RESET_LBN 15 /* Self clear */
118*4882a593Smuzhiyun #define TXC_MCTL_TXLED_LBN 14 /* 1 to show align status */
119*4882a593Smuzhiyun #define TXC_MCTL_RXLED_LBN 13 /* 1 to show align status */
120*4882a593Smuzhiyun
121*4882a593Smuzhiyun /* GPIO output */
122*4882a593Smuzhiyun #define TXC_GPIO_OUTPUT 0xc346
123*4882a593Smuzhiyun #define TXC_GPIO_DIR 0xc348
124*4882a593Smuzhiyun
125*4882a593Smuzhiyun /* Vendor-specific BIST registers */
126*4882a593Smuzhiyun #define TXC_BIST_CTL 0xc280
127*4882a593Smuzhiyun #define TXC_BIST_TXFRMCNT 0xc281
128*4882a593Smuzhiyun #define TXC_BIST_RX0FRMCNT 0xc282
129*4882a593Smuzhiyun #define TXC_BIST_RX1FRMCNT 0xc283
130*4882a593Smuzhiyun #define TXC_BIST_RX2FRMCNT 0xc284
131*4882a593Smuzhiyun #define TXC_BIST_RX3FRMCNT 0xc285
132*4882a593Smuzhiyun #define TXC_BIST_RX0ERRCNT 0xc286
133*4882a593Smuzhiyun #define TXC_BIST_RX1ERRCNT 0xc287
134*4882a593Smuzhiyun #define TXC_BIST_RX2ERRCNT 0xc288
135*4882a593Smuzhiyun #define TXC_BIST_RX3ERRCNT 0xc289
136*4882a593Smuzhiyun
137*4882a593Smuzhiyun /* BIST type (controls bit patter in test) */
138*4882a593Smuzhiyun #define TXC_BIST_CTRL_TYPE_LBN 10
139*4882a593Smuzhiyun #define TXC_BIST_CTRL_TYPE_TSD 0 /* TranSwitch Deterministic */
140*4882a593Smuzhiyun #define TXC_BIST_CTRL_TYPE_CRP 1 /* CRPAT standard */
141*4882a593Smuzhiyun #define TXC_BIST_CTRL_TYPE_CJP 2 /* CJPAT standard */
142*4882a593Smuzhiyun #define TXC_BIST_CTRL_TYPE_TSR 3 /* TranSwitch pseudo-random */
143*4882a593Smuzhiyun /* Set this to 1 for 10 bit and 0 for 8 bit */
144*4882a593Smuzhiyun #define TXC_BIST_CTRL_B10EN_LBN 12
145*4882a593Smuzhiyun /* Enable BIST (write 0 to disable) */
146*4882a593Smuzhiyun #define TXC_BIST_CTRL_ENAB_LBN 13
147*4882a593Smuzhiyun /* Stop BIST (self-clears when stop complete) */
148*4882a593Smuzhiyun #define TXC_BIST_CTRL_STOP_LBN 14
149*4882a593Smuzhiyun /* Start BIST (cleared by writing 1 to STOP) */
150*4882a593Smuzhiyun #define TXC_BIST_CTRL_STRT_LBN 15
151*4882a593Smuzhiyun
152*4882a593Smuzhiyun /* Mt. Diablo test configuration */
153*4882a593Smuzhiyun #define TXC_MTDIABLO_CTRL 0xc34f
154*4882a593Smuzhiyun #define TXC_MTDIABLO_CTRL_PMA_LOOP_LBN 10
155*4882a593Smuzhiyun
156*4882a593Smuzhiyun struct txc43128_data {
157*4882a593Smuzhiyun unsigned long bug10934_timer;
158*4882a593Smuzhiyun enum ef4_phy_mode phy_mode;
159*4882a593Smuzhiyun enum ef4_loopback_mode loopback_mode;
160*4882a593Smuzhiyun };
161*4882a593Smuzhiyun
162*4882a593Smuzhiyun /* The PHY sometimes needs a reset to bring the link back up. So long as
163*4882a593Smuzhiyun * it reports link down, we reset it every 5 seconds.
164*4882a593Smuzhiyun */
165*4882a593Smuzhiyun #define BUG10934_RESET_INTERVAL (5 * HZ)
166*4882a593Smuzhiyun
167*4882a593Smuzhiyun /* Perform a reset that doesn't clear configuration changes */
168*4882a593Smuzhiyun static void txc_reset_logic(struct ef4_nic *efx);
169*4882a593Smuzhiyun
170*4882a593Smuzhiyun /* Set the output value of a gpio */
falcon_txc_set_gpio_val(struct ef4_nic * efx,int pin,int on)171*4882a593Smuzhiyun void falcon_txc_set_gpio_val(struct ef4_nic *efx, int pin, int on)
172*4882a593Smuzhiyun {
173*4882a593Smuzhiyun ef4_mdio_set_flag(efx, MDIO_MMD_PHYXS, TXC_GPIO_OUTPUT, 1 << pin, on);
174*4882a593Smuzhiyun }
175*4882a593Smuzhiyun
176*4882a593Smuzhiyun /* Set up the GPIO direction register */
falcon_txc_set_gpio_dir(struct ef4_nic * efx,int pin,int dir)177*4882a593Smuzhiyun void falcon_txc_set_gpio_dir(struct ef4_nic *efx, int pin, int dir)
178*4882a593Smuzhiyun {
179*4882a593Smuzhiyun ef4_mdio_set_flag(efx, MDIO_MMD_PHYXS, TXC_GPIO_DIR, 1 << pin, dir);
180*4882a593Smuzhiyun }
181*4882a593Smuzhiyun
182*4882a593Smuzhiyun /* Reset the PMA/PMD MMD. The documentation is explicit that this does a
183*4882a593Smuzhiyun * global reset (it's less clear what reset of other MMDs does).*/
txc_reset_phy(struct ef4_nic * efx)184*4882a593Smuzhiyun static int txc_reset_phy(struct ef4_nic *efx)
185*4882a593Smuzhiyun {
186*4882a593Smuzhiyun int rc = ef4_mdio_reset_mmd(efx, MDIO_MMD_PMAPMD,
187*4882a593Smuzhiyun TXC_MAX_RESET_TIME / TXC_RESET_WAIT,
188*4882a593Smuzhiyun TXC_RESET_WAIT);
189*4882a593Smuzhiyun if (rc < 0)
190*4882a593Smuzhiyun goto fail;
191*4882a593Smuzhiyun
192*4882a593Smuzhiyun /* Check that all the MMDs we expect are present and responding. */
193*4882a593Smuzhiyun rc = ef4_mdio_check_mmds(efx, TXC_REQUIRED_DEVS);
194*4882a593Smuzhiyun if (rc < 0)
195*4882a593Smuzhiyun goto fail;
196*4882a593Smuzhiyun
197*4882a593Smuzhiyun return 0;
198*4882a593Smuzhiyun
199*4882a593Smuzhiyun fail:
200*4882a593Smuzhiyun netif_err(efx, hw, efx->net_dev, TXCNAME ": reset timed out!\n");
201*4882a593Smuzhiyun return rc;
202*4882a593Smuzhiyun }
203*4882a593Smuzhiyun
204*4882a593Smuzhiyun /* Run a single BIST on one MMD */
txc_bist_one(struct ef4_nic * efx,int mmd,int test)205*4882a593Smuzhiyun static int txc_bist_one(struct ef4_nic *efx, int mmd, int test)
206*4882a593Smuzhiyun {
207*4882a593Smuzhiyun int ctrl, bctl;
208*4882a593Smuzhiyun int lane;
209*4882a593Smuzhiyun int rc = 0;
210*4882a593Smuzhiyun
211*4882a593Smuzhiyun /* Set PMA to test into loopback using Mt Diablo reg as per app note */
212*4882a593Smuzhiyun ctrl = ef4_mdio_read(efx, MDIO_MMD_PCS, TXC_MTDIABLO_CTRL);
213*4882a593Smuzhiyun ctrl |= (1 << TXC_MTDIABLO_CTRL_PMA_LOOP_LBN);
214*4882a593Smuzhiyun ef4_mdio_write(efx, MDIO_MMD_PCS, TXC_MTDIABLO_CTRL, ctrl);
215*4882a593Smuzhiyun
216*4882a593Smuzhiyun /* The BIST app. note lists these as 3 distinct steps. */
217*4882a593Smuzhiyun /* Set the BIST type */
218*4882a593Smuzhiyun bctl = (test << TXC_BIST_CTRL_TYPE_LBN);
219*4882a593Smuzhiyun ef4_mdio_write(efx, mmd, TXC_BIST_CTL, bctl);
220*4882a593Smuzhiyun
221*4882a593Smuzhiyun /* Set the BSTEN bit in the BIST Control register to enable */
222*4882a593Smuzhiyun bctl |= (1 << TXC_BIST_CTRL_ENAB_LBN);
223*4882a593Smuzhiyun ef4_mdio_write(efx, mmd, TXC_BIST_CTL, bctl);
224*4882a593Smuzhiyun
225*4882a593Smuzhiyun /* Set the BSTRT bit in the BIST Control register */
226*4882a593Smuzhiyun ef4_mdio_write(efx, mmd, TXC_BIST_CTL,
227*4882a593Smuzhiyun bctl | (1 << TXC_BIST_CTRL_STRT_LBN));
228*4882a593Smuzhiyun
229*4882a593Smuzhiyun /* Wait. */
230*4882a593Smuzhiyun udelay(TXC_BIST_DURATION);
231*4882a593Smuzhiyun
232*4882a593Smuzhiyun /* Set the BSTOP bit in the BIST Control register */
233*4882a593Smuzhiyun bctl |= (1 << TXC_BIST_CTRL_STOP_LBN);
234*4882a593Smuzhiyun ef4_mdio_write(efx, mmd, TXC_BIST_CTL, bctl);
235*4882a593Smuzhiyun
236*4882a593Smuzhiyun /* The STOP bit should go off when things have stopped */
237*4882a593Smuzhiyun while (bctl & (1 << TXC_BIST_CTRL_STOP_LBN))
238*4882a593Smuzhiyun bctl = ef4_mdio_read(efx, mmd, TXC_BIST_CTL);
239*4882a593Smuzhiyun
240*4882a593Smuzhiyun /* Check all the error counts are 0 and all the frame counts are
241*4882a593Smuzhiyun non-zero */
242*4882a593Smuzhiyun for (lane = 0; lane < 4; lane++) {
243*4882a593Smuzhiyun int count = ef4_mdio_read(efx, mmd, TXC_BIST_RX0ERRCNT + lane);
244*4882a593Smuzhiyun if (count != 0) {
245*4882a593Smuzhiyun netif_err(efx, hw, efx->net_dev, TXCNAME": BIST error. "
246*4882a593Smuzhiyun "Lane %d had %d errs\n", lane, count);
247*4882a593Smuzhiyun rc = -EIO;
248*4882a593Smuzhiyun }
249*4882a593Smuzhiyun count = ef4_mdio_read(efx, mmd, TXC_BIST_RX0FRMCNT + lane);
250*4882a593Smuzhiyun if (count == 0) {
251*4882a593Smuzhiyun netif_err(efx, hw, efx->net_dev, TXCNAME": BIST error. "
252*4882a593Smuzhiyun "Lane %d got 0 frames\n", lane);
253*4882a593Smuzhiyun rc = -EIO;
254*4882a593Smuzhiyun }
255*4882a593Smuzhiyun }
256*4882a593Smuzhiyun
257*4882a593Smuzhiyun if (rc == 0)
258*4882a593Smuzhiyun netif_info(efx, hw, efx->net_dev, TXCNAME": BIST pass\n");
259*4882a593Smuzhiyun
260*4882a593Smuzhiyun /* Disable BIST */
261*4882a593Smuzhiyun ef4_mdio_write(efx, mmd, TXC_BIST_CTL, 0);
262*4882a593Smuzhiyun
263*4882a593Smuzhiyun /* Turn off loopback */
264*4882a593Smuzhiyun ctrl &= ~(1 << TXC_MTDIABLO_CTRL_PMA_LOOP_LBN);
265*4882a593Smuzhiyun ef4_mdio_write(efx, MDIO_MMD_PCS, TXC_MTDIABLO_CTRL, ctrl);
266*4882a593Smuzhiyun
267*4882a593Smuzhiyun return rc;
268*4882a593Smuzhiyun }
269*4882a593Smuzhiyun
txc_bist(struct ef4_nic * efx)270*4882a593Smuzhiyun static int txc_bist(struct ef4_nic *efx)
271*4882a593Smuzhiyun {
272*4882a593Smuzhiyun return txc_bist_one(efx, MDIO_MMD_PCS, TXC_BIST_CTRL_TYPE_TSD);
273*4882a593Smuzhiyun }
274*4882a593Smuzhiyun
275*4882a593Smuzhiyun /* Push the non-configurable defaults into the PHY. This must be
276*4882a593Smuzhiyun * done after every full reset */
txc_apply_defaults(struct ef4_nic * efx)277*4882a593Smuzhiyun static void txc_apply_defaults(struct ef4_nic *efx)
278*4882a593Smuzhiyun {
279*4882a593Smuzhiyun int mctrl;
280*4882a593Smuzhiyun
281*4882a593Smuzhiyun /* Turn amplitude down and preemphasis off on the host side
282*4882a593Smuzhiyun * (PHY<->MAC) as this is believed less likely to upset Falcon
283*4882a593Smuzhiyun * and no adverse effects have been noted. It probably also
284*4882a593Smuzhiyun * saves a picowatt or two */
285*4882a593Smuzhiyun
286*4882a593Smuzhiyun /* Turn off preemphasis */
287*4882a593Smuzhiyun ef4_mdio_write(efx, MDIO_MMD_PHYXS, TXC_ALRGS_ATXPRE0, TXC_ATXPRE_NONE);
288*4882a593Smuzhiyun ef4_mdio_write(efx, MDIO_MMD_PHYXS, TXC_ALRGS_ATXPRE1, TXC_ATXPRE_NONE);
289*4882a593Smuzhiyun
290*4882a593Smuzhiyun /* Turn down the amplitude */
291*4882a593Smuzhiyun ef4_mdio_write(efx, MDIO_MMD_PHYXS,
292*4882a593Smuzhiyun TXC_ALRGS_ATXAMP0, TXC_ATXAMP_0820_BOTH);
293*4882a593Smuzhiyun ef4_mdio_write(efx, MDIO_MMD_PHYXS,
294*4882a593Smuzhiyun TXC_ALRGS_ATXAMP1, TXC_ATXAMP_0820_BOTH);
295*4882a593Smuzhiyun
296*4882a593Smuzhiyun /* Set the line side amplitude and preemphasis to the databook
297*4882a593Smuzhiyun * defaults as an erratum causes them to be 0 on at least some
298*4882a593Smuzhiyun * PHY rev.s */
299*4882a593Smuzhiyun ef4_mdio_write(efx, MDIO_MMD_PMAPMD,
300*4882a593Smuzhiyun TXC_ALRGS_ATXPRE0, TXC_ATXPRE_DEFAULT);
301*4882a593Smuzhiyun ef4_mdio_write(efx, MDIO_MMD_PMAPMD,
302*4882a593Smuzhiyun TXC_ALRGS_ATXPRE1, TXC_ATXPRE_DEFAULT);
303*4882a593Smuzhiyun ef4_mdio_write(efx, MDIO_MMD_PMAPMD,
304*4882a593Smuzhiyun TXC_ALRGS_ATXAMP0, TXC_ATXAMP_DEFAULT);
305*4882a593Smuzhiyun ef4_mdio_write(efx, MDIO_MMD_PMAPMD,
306*4882a593Smuzhiyun TXC_ALRGS_ATXAMP1, TXC_ATXAMP_DEFAULT);
307*4882a593Smuzhiyun
308*4882a593Smuzhiyun /* Set up the LEDs */
309*4882a593Smuzhiyun mctrl = ef4_mdio_read(efx, MDIO_MMD_PHYXS, TXC_MRGS_CTL);
310*4882a593Smuzhiyun
311*4882a593Smuzhiyun /* Set the Green and Red LEDs to their default modes */
312*4882a593Smuzhiyun mctrl &= ~((1 << TXC_MCTL_TXLED_LBN) | (1 << TXC_MCTL_RXLED_LBN));
313*4882a593Smuzhiyun ef4_mdio_write(efx, MDIO_MMD_PHYXS, TXC_MRGS_CTL, mctrl);
314*4882a593Smuzhiyun
315*4882a593Smuzhiyun /* Databook recommends doing this after configuration changes */
316*4882a593Smuzhiyun txc_reset_logic(efx);
317*4882a593Smuzhiyun
318*4882a593Smuzhiyun falcon_board(efx)->type->init_phy(efx);
319*4882a593Smuzhiyun }
320*4882a593Smuzhiyun
txc43128_phy_probe(struct ef4_nic * efx)321*4882a593Smuzhiyun static int txc43128_phy_probe(struct ef4_nic *efx)
322*4882a593Smuzhiyun {
323*4882a593Smuzhiyun struct txc43128_data *phy_data;
324*4882a593Smuzhiyun
325*4882a593Smuzhiyun /* Allocate phy private storage */
326*4882a593Smuzhiyun phy_data = kzalloc(sizeof(*phy_data), GFP_KERNEL);
327*4882a593Smuzhiyun if (!phy_data)
328*4882a593Smuzhiyun return -ENOMEM;
329*4882a593Smuzhiyun efx->phy_data = phy_data;
330*4882a593Smuzhiyun phy_data->phy_mode = efx->phy_mode;
331*4882a593Smuzhiyun
332*4882a593Smuzhiyun efx->mdio.mmds = TXC_REQUIRED_DEVS;
333*4882a593Smuzhiyun efx->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
334*4882a593Smuzhiyun
335*4882a593Smuzhiyun efx->loopback_modes = TXC_LOOPBACKS | FALCON_XMAC_LOOPBACKS;
336*4882a593Smuzhiyun
337*4882a593Smuzhiyun return 0;
338*4882a593Smuzhiyun }
339*4882a593Smuzhiyun
340*4882a593Smuzhiyun /* Initialisation entry point for this PHY driver */
txc43128_phy_init(struct ef4_nic * efx)341*4882a593Smuzhiyun static int txc43128_phy_init(struct ef4_nic *efx)
342*4882a593Smuzhiyun {
343*4882a593Smuzhiyun int rc;
344*4882a593Smuzhiyun
345*4882a593Smuzhiyun rc = txc_reset_phy(efx);
346*4882a593Smuzhiyun if (rc < 0)
347*4882a593Smuzhiyun return rc;
348*4882a593Smuzhiyun
349*4882a593Smuzhiyun rc = txc_bist(efx);
350*4882a593Smuzhiyun if (rc < 0)
351*4882a593Smuzhiyun return rc;
352*4882a593Smuzhiyun
353*4882a593Smuzhiyun txc_apply_defaults(efx);
354*4882a593Smuzhiyun
355*4882a593Smuzhiyun return 0;
356*4882a593Smuzhiyun }
357*4882a593Smuzhiyun
358*4882a593Smuzhiyun /* Set the lane power down state in the global registers */
txc_glrgs_lane_power(struct ef4_nic * efx,int mmd)359*4882a593Smuzhiyun static void txc_glrgs_lane_power(struct ef4_nic *efx, int mmd)
360*4882a593Smuzhiyun {
361*4882a593Smuzhiyun int pd = (1 << TXC_GLCMD_L01PD_LBN) | (1 << TXC_GLCMD_L23PD_LBN);
362*4882a593Smuzhiyun int ctl = ef4_mdio_read(efx, mmd, TXC_GLRGS_GLCMD);
363*4882a593Smuzhiyun
364*4882a593Smuzhiyun if (!(efx->phy_mode & PHY_MODE_LOW_POWER))
365*4882a593Smuzhiyun ctl &= ~pd;
366*4882a593Smuzhiyun else
367*4882a593Smuzhiyun ctl |= pd;
368*4882a593Smuzhiyun
369*4882a593Smuzhiyun ef4_mdio_write(efx, mmd, TXC_GLRGS_GLCMD, ctl);
370*4882a593Smuzhiyun }
371*4882a593Smuzhiyun
372*4882a593Smuzhiyun /* Set the lane power down state in the analog control registers */
txc_analog_lane_power(struct ef4_nic * efx,int mmd)373*4882a593Smuzhiyun static void txc_analog_lane_power(struct ef4_nic *efx, int mmd)
374*4882a593Smuzhiyun {
375*4882a593Smuzhiyun int txpd = (1 << TXC_ATXCTL_TXPD3_LBN) | (1 << TXC_ATXCTL_TXPD2_LBN)
376*4882a593Smuzhiyun | (1 << TXC_ATXCTL_TXPD1_LBN) | (1 << TXC_ATXCTL_TXPD0_LBN);
377*4882a593Smuzhiyun int rxpd = (1 << TXC_ARXCTL_RXPD3_LBN) | (1 << TXC_ARXCTL_RXPD2_LBN)
378*4882a593Smuzhiyun | (1 << TXC_ARXCTL_RXPD1_LBN) | (1 << TXC_ARXCTL_RXPD0_LBN);
379*4882a593Smuzhiyun int txctl = ef4_mdio_read(efx, mmd, TXC_ALRGS_ATXCTL);
380*4882a593Smuzhiyun int rxctl = ef4_mdio_read(efx, mmd, TXC_ALRGS_ARXCTL);
381*4882a593Smuzhiyun
382*4882a593Smuzhiyun if (!(efx->phy_mode & PHY_MODE_LOW_POWER)) {
383*4882a593Smuzhiyun txctl &= ~txpd;
384*4882a593Smuzhiyun rxctl &= ~rxpd;
385*4882a593Smuzhiyun } else {
386*4882a593Smuzhiyun txctl |= txpd;
387*4882a593Smuzhiyun rxctl |= rxpd;
388*4882a593Smuzhiyun }
389*4882a593Smuzhiyun
390*4882a593Smuzhiyun ef4_mdio_write(efx, mmd, TXC_ALRGS_ATXCTL, txctl);
391*4882a593Smuzhiyun ef4_mdio_write(efx, mmd, TXC_ALRGS_ARXCTL, rxctl);
392*4882a593Smuzhiyun }
393*4882a593Smuzhiyun
txc_set_power(struct ef4_nic * efx)394*4882a593Smuzhiyun static void txc_set_power(struct ef4_nic *efx)
395*4882a593Smuzhiyun {
396*4882a593Smuzhiyun /* According to the data book, all the MMDs can do low power */
397*4882a593Smuzhiyun ef4_mdio_set_mmds_lpower(efx,
398*4882a593Smuzhiyun !!(efx->phy_mode & PHY_MODE_LOW_POWER),
399*4882a593Smuzhiyun TXC_REQUIRED_DEVS);
400*4882a593Smuzhiyun
401*4882a593Smuzhiyun /* Global register bank is in PCS, PHY XS. These control the host
402*4882a593Smuzhiyun * side and line side settings respectively. */
403*4882a593Smuzhiyun txc_glrgs_lane_power(efx, MDIO_MMD_PCS);
404*4882a593Smuzhiyun txc_glrgs_lane_power(efx, MDIO_MMD_PHYXS);
405*4882a593Smuzhiyun
406*4882a593Smuzhiyun /* Analog register bank in PMA/PMD, PHY XS */
407*4882a593Smuzhiyun txc_analog_lane_power(efx, MDIO_MMD_PMAPMD);
408*4882a593Smuzhiyun txc_analog_lane_power(efx, MDIO_MMD_PHYXS);
409*4882a593Smuzhiyun }
410*4882a593Smuzhiyun
txc_reset_logic_mmd(struct ef4_nic * efx,int mmd)411*4882a593Smuzhiyun static void txc_reset_logic_mmd(struct ef4_nic *efx, int mmd)
412*4882a593Smuzhiyun {
413*4882a593Smuzhiyun int val = ef4_mdio_read(efx, mmd, TXC_GLRGS_GLCMD);
414*4882a593Smuzhiyun int tries = 50;
415*4882a593Smuzhiyun
416*4882a593Smuzhiyun val |= (1 << TXC_GLCMD_LMTSWRST_LBN);
417*4882a593Smuzhiyun ef4_mdio_write(efx, mmd, TXC_GLRGS_GLCMD, val);
418*4882a593Smuzhiyun while (--tries) {
419*4882a593Smuzhiyun val = ef4_mdio_read(efx, mmd, TXC_GLRGS_GLCMD);
420*4882a593Smuzhiyun if (!(val & (1 << TXC_GLCMD_LMTSWRST_LBN)))
421*4882a593Smuzhiyun break;
422*4882a593Smuzhiyun udelay(1);
423*4882a593Smuzhiyun }
424*4882a593Smuzhiyun if (!tries)
425*4882a593Smuzhiyun netif_info(efx, hw, efx->net_dev,
426*4882a593Smuzhiyun TXCNAME " Logic reset timed out!\n");
427*4882a593Smuzhiyun }
428*4882a593Smuzhiyun
429*4882a593Smuzhiyun /* Perform a logic reset. This preserves the configuration registers
430*4882a593Smuzhiyun * and is needed for some configuration changes to take effect */
txc_reset_logic(struct ef4_nic * efx)431*4882a593Smuzhiyun static void txc_reset_logic(struct ef4_nic *efx)
432*4882a593Smuzhiyun {
433*4882a593Smuzhiyun /* The data sheet claims we can do the logic reset on either the
434*4882a593Smuzhiyun * PCS or the PHYXS and the result is a reset of both host- and
435*4882a593Smuzhiyun * line-side logic. */
436*4882a593Smuzhiyun txc_reset_logic_mmd(efx, MDIO_MMD_PCS);
437*4882a593Smuzhiyun }
438*4882a593Smuzhiyun
txc43128_phy_read_link(struct ef4_nic * efx)439*4882a593Smuzhiyun static bool txc43128_phy_read_link(struct ef4_nic *efx)
440*4882a593Smuzhiyun {
441*4882a593Smuzhiyun return ef4_mdio_links_ok(efx, TXC_REQUIRED_DEVS);
442*4882a593Smuzhiyun }
443*4882a593Smuzhiyun
txc43128_phy_reconfigure(struct ef4_nic * efx)444*4882a593Smuzhiyun static int txc43128_phy_reconfigure(struct ef4_nic *efx)
445*4882a593Smuzhiyun {
446*4882a593Smuzhiyun struct txc43128_data *phy_data = efx->phy_data;
447*4882a593Smuzhiyun enum ef4_phy_mode mode_change = efx->phy_mode ^ phy_data->phy_mode;
448*4882a593Smuzhiyun bool loop_change = LOOPBACK_CHANGED(phy_data, efx, TXC_LOOPBACKS);
449*4882a593Smuzhiyun
450*4882a593Smuzhiyun if (efx->phy_mode & mode_change & PHY_MODE_TX_DISABLED) {
451*4882a593Smuzhiyun txc_reset_phy(efx);
452*4882a593Smuzhiyun txc_apply_defaults(efx);
453*4882a593Smuzhiyun falcon_reset_xaui(efx);
454*4882a593Smuzhiyun mode_change &= ~PHY_MODE_TX_DISABLED;
455*4882a593Smuzhiyun }
456*4882a593Smuzhiyun
457*4882a593Smuzhiyun ef4_mdio_transmit_disable(efx);
458*4882a593Smuzhiyun ef4_mdio_phy_reconfigure(efx);
459*4882a593Smuzhiyun if (mode_change & PHY_MODE_LOW_POWER)
460*4882a593Smuzhiyun txc_set_power(efx);
461*4882a593Smuzhiyun
462*4882a593Smuzhiyun /* The data sheet claims this is required after every reconfiguration
463*4882a593Smuzhiyun * (note at end of 7.1), but we mustn't do it when nothing changes as
464*4882a593Smuzhiyun * it glitches the link, and reconfigure gets called on link change,
465*4882a593Smuzhiyun * so we get an IRQ storm on link up. */
466*4882a593Smuzhiyun if (loop_change || mode_change)
467*4882a593Smuzhiyun txc_reset_logic(efx);
468*4882a593Smuzhiyun
469*4882a593Smuzhiyun phy_data->phy_mode = efx->phy_mode;
470*4882a593Smuzhiyun phy_data->loopback_mode = efx->loopback_mode;
471*4882a593Smuzhiyun
472*4882a593Smuzhiyun return 0;
473*4882a593Smuzhiyun }
474*4882a593Smuzhiyun
txc43128_phy_fini(struct ef4_nic * efx)475*4882a593Smuzhiyun static void txc43128_phy_fini(struct ef4_nic *efx)
476*4882a593Smuzhiyun {
477*4882a593Smuzhiyun /* Disable link events */
478*4882a593Smuzhiyun ef4_mdio_write(efx, MDIO_MMD_PMAPMD, MDIO_PMA_LASI_CTRL, 0);
479*4882a593Smuzhiyun }
480*4882a593Smuzhiyun
txc43128_phy_remove(struct ef4_nic * efx)481*4882a593Smuzhiyun static void txc43128_phy_remove(struct ef4_nic *efx)
482*4882a593Smuzhiyun {
483*4882a593Smuzhiyun kfree(efx->phy_data);
484*4882a593Smuzhiyun efx->phy_data = NULL;
485*4882a593Smuzhiyun }
486*4882a593Smuzhiyun
487*4882a593Smuzhiyun /* Periodic callback: this exists mainly to poll link status as we
488*4882a593Smuzhiyun * don't use LASI interrupts */
txc43128_phy_poll(struct ef4_nic * efx)489*4882a593Smuzhiyun static bool txc43128_phy_poll(struct ef4_nic *efx)
490*4882a593Smuzhiyun {
491*4882a593Smuzhiyun struct txc43128_data *data = efx->phy_data;
492*4882a593Smuzhiyun bool was_up = efx->link_state.up;
493*4882a593Smuzhiyun
494*4882a593Smuzhiyun efx->link_state.up = txc43128_phy_read_link(efx);
495*4882a593Smuzhiyun efx->link_state.speed = 10000;
496*4882a593Smuzhiyun efx->link_state.fd = true;
497*4882a593Smuzhiyun efx->link_state.fc = efx->wanted_fc;
498*4882a593Smuzhiyun
499*4882a593Smuzhiyun if (efx->link_state.up || (efx->loopback_mode != LOOPBACK_NONE)) {
500*4882a593Smuzhiyun data->bug10934_timer = jiffies;
501*4882a593Smuzhiyun } else {
502*4882a593Smuzhiyun if (time_after_eq(jiffies, (data->bug10934_timer +
503*4882a593Smuzhiyun BUG10934_RESET_INTERVAL))) {
504*4882a593Smuzhiyun data->bug10934_timer = jiffies;
505*4882a593Smuzhiyun txc_reset_logic(efx);
506*4882a593Smuzhiyun }
507*4882a593Smuzhiyun }
508*4882a593Smuzhiyun
509*4882a593Smuzhiyun return efx->link_state.up != was_up;
510*4882a593Smuzhiyun }
511*4882a593Smuzhiyun
512*4882a593Smuzhiyun static const char *const txc43128_test_names[] = {
513*4882a593Smuzhiyun "bist"
514*4882a593Smuzhiyun };
515*4882a593Smuzhiyun
txc43128_test_name(struct ef4_nic * efx,unsigned int index)516*4882a593Smuzhiyun static const char *txc43128_test_name(struct ef4_nic *efx, unsigned int index)
517*4882a593Smuzhiyun {
518*4882a593Smuzhiyun if (index < ARRAY_SIZE(txc43128_test_names))
519*4882a593Smuzhiyun return txc43128_test_names[index];
520*4882a593Smuzhiyun return NULL;
521*4882a593Smuzhiyun }
522*4882a593Smuzhiyun
txc43128_run_tests(struct ef4_nic * efx,int * results,unsigned flags)523*4882a593Smuzhiyun static int txc43128_run_tests(struct ef4_nic *efx, int *results, unsigned flags)
524*4882a593Smuzhiyun {
525*4882a593Smuzhiyun int rc;
526*4882a593Smuzhiyun
527*4882a593Smuzhiyun if (!(flags & ETH_TEST_FL_OFFLINE))
528*4882a593Smuzhiyun return 0;
529*4882a593Smuzhiyun
530*4882a593Smuzhiyun rc = txc_reset_phy(efx);
531*4882a593Smuzhiyun if (rc < 0)
532*4882a593Smuzhiyun return rc;
533*4882a593Smuzhiyun
534*4882a593Smuzhiyun rc = txc_bist(efx);
535*4882a593Smuzhiyun txc_apply_defaults(efx);
536*4882a593Smuzhiyun results[0] = rc ? -1 : 1;
537*4882a593Smuzhiyun return rc;
538*4882a593Smuzhiyun }
539*4882a593Smuzhiyun
txc43128_get_link_ksettings(struct ef4_nic * efx,struct ethtool_link_ksettings * cmd)540*4882a593Smuzhiyun static void txc43128_get_link_ksettings(struct ef4_nic *efx,
541*4882a593Smuzhiyun struct ethtool_link_ksettings *cmd)
542*4882a593Smuzhiyun {
543*4882a593Smuzhiyun mdio45_ethtool_ksettings_get(&efx->mdio, cmd);
544*4882a593Smuzhiyun }
545*4882a593Smuzhiyun
546*4882a593Smuzhiyun const struct ef4_phy_operations falcon_txc_phy_ops = {
547*4882a593Smuzhiyun .probe = txc43128_phy_probe,
548*4882a593Smuzhiyun .init = txc43128_phy_init,
549*4882a593Smuzhiyun .reconfigure = txc43128_phy_reconfigure,
550*4882a593Smuzhiyun .poll = txc43128_phy_poll,
551*4882a593Smuzhiyun .fini = txc43128_phy_fini,
552*4882a593Smuzhiyun .remove = txc43128_phy_remove,
553*4882a593Smuzhiyun .get_link_ksettings = txc43128_get_link_ksettings,
554*4882a593Smuzhiyun .set_link_ksettings = ef4_mdio_set_link_ksettings,
555*4882a593Smuzhiyun .test_alive = ef4_mdio_test_alive,
556*4882a593Smuzhiyun .run_tests = txc43128_run_tests,
557*4882a593Smuzhiyun .test_name = txc43128_test_name,
558*4882a593Smuzhiyun };
559