1*d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
27e51b439SBen Hutchings /****************************************************************************
3f7a6d2c4SBen Hutchings * Driver for Solarflare network controllers and boards
40a6f40c6SBen Hutchings * Copyright 2006-2011 Solarflare Communications Inc.
57e51b439SBen Hutchings */
67e51b439SBen Hutchings
77e51b439SBen Hutchings /*
87e51b439SBen Hutchings * Driver for Transwitch/Mysticom CX4 retimer
97e51b439SBen Hutchings * see www.transwitch.com, part is TXC-43128
107e51b439SBen Hutchings */
117e51b439SBen Hutchings
127e51b439SBen Hutchings #include <linux/delay.h>
137e51b439SBen Hutchings #include <linux/slab.h>
147e51b439SBen Hutchings #include "efx.h"
157e51b439SBen Hutchings #include "mdio_10g.h"
167e51b439SBen Hutchings #include "phy.h"
177e51b439SBen Hutchings #include "nic.h"
187e51b439SBen Hutchings
197e51b439SBen Hutchings /* We expect these MMDs to be in the package */
207e51b439SBen Hutchings #define TXC_REQUIRED_DEVS (MDIO_DEVS_PCS | \
217e51b439SBen Hutchings MDIO_DEVS_PMAPMD | \
227e51b439SBen Hutchings MDIO_DEVS_PHYXS)
237e51b439SBen Hutchings
247e51b439SBen Hutchings #define TXC_LOOPBACKS ((1 << LOOPBACK_PCS) | \
257e51b439SBen Hutchings (1 << LOOPBACK_PMAPMD) | \
267e51b439SBen Hutchings (1 << LOOPBACK_PHYXS_WS))
277e51b439SBen Hutchings
287e51b439SBen Hutchings /**************************************************************************
297e51b439SBen Hutchings *
307e51b439SBen Hutchings * Compile-time config
317e51b439SBen Hutchings *
327e51b439SBen Hutchings **************************************************************************
337e51b439SBen Hutchings */
347e51b439SBen Hutchings #define TXCNAME "TXC43128"
357e51b439SBen Hutchings /* Total length of time we'll wait for the PHY to come out of reset (ms) */
367e51b439SBen Hutchings #define TXC_MAX_RESET_TIME 500
377e51b439SBen Hutchings /* Interval between checks (ms) */
387e51b439SBen Hutchings #define TXC_RESET_WAIT 10
397e51b439SBen Hutchings /* How long to run BIST (us) */
407e51b439SBen Hutchings #define TXC_BIST_DURATION 50
417e51b439SBen Hutchings
427e51b439SBen Hutchings /**************************************************************************
437e51b439SBen Hutchings *
447e51b439SBen Hutchings * Register definitions
457e51b439SBen Hutchings *
467e51b439SBen Hutchings **************************************************************************
477e51b439SBen Hutchings */
487e51b439SBen Hutchings
497e51b439SBen Hutchings /* Command register */
507e51b439SBen Hutchings #define TXC_GLRGS_GLCMD 0xc004
517e51b439SBen Hutchings /* Useful bits in command register */
527e51b439SBen Hutchings /* Lane power-down */
537e51b439SBen Hutchings #define TXC_GLCMD_L01PD_LBN 5
547e51b439SBen Hutchings #define TXC_GLCMD_L23PD_LBN 6
557e51b439SBen Hutchings /* Limited SW reset: preserves configuration but
567e51b439SBen Hutchings * initiates a logic reset. Self-clearing */
577e51b439SBen Hutchings #define TXC_GLCMD_LMTSWRST_LBN 14
587e51b439SBen Hutchings
597e51b439SBen Hutchings /* Signal Quality Control */
607e51b439SBen Hutchings #define TXC_GLRGS_GSGQLCTL 0xc01a
617e51b439SBen Hutchings /* Enable bit */
627e51b439SBen Hutchings #define TXC_GSGQLCT_SGQLEN_LBN 15
637e51b439SBen Hutchings /* Lane selection */
647e51b439SBen Hutchings #define TXC_GSGQLCT_LNSL_LBN 13
657e51b439SBen Hutchings #define TXC_GSGQLCT_LNSL_WIDTH 2
667e51b439SBen Hutchings
677e51b439SBen Hutchings /* Analog TX control */
687e51b439SBen Hutchings #define TXC_ALRGS_ATXCTL 0xc040
697e51b439SBen Hutchings /* Lane power-down */
707e51b439SBen Hutchings #define TXC_ATXCTL_TXPD3_LBN 15
717e51b439SBen Hutchings #define TXC_ATXCTL_TXPD2_LBN 14
727e51b439SBen Hutchings #define TXC_ATXCTL_TXPD1_LBN 13
737e51b439SBen Hutchings #define TXC_ATXCTL_TXPD0_LBN 12
747e51b439SBen Hutchings
757e51b439SBen Hutchings /* Amplitude on lanes 0, 1 */
767e51b439SBen Hutchings #define TXC_ALRGS_ATXAMP0 0xc041
777e51b439SBen Hutchings /* Amplitude on lanes 2, 3 */
787e51b439SBen Hutchings #define TXC_ALRGS_ATXAMP1 0xc042
797e51b439SBen Hutchings /* Bit position of value for lane 0 (or 2) */
807e51b439SBen Hutchings #define TXC_ATXAMP_LANE02_LBN 3
817e51b439SBen Hutchings /* Bit position of value for lane 1 (or 3) */
827e51b439SBen Hutchings #define TXC_ATXAMP_LANE13_LBN 11
837e51b439SBen Hutchings
847e51b439SBen Hutchings #define TXC_ATXAMP_1280_mV 0
857e51b439SBen Hutchings #define TXC_ATXAMP_1200_mV 8
867e51b439SBen Hutchings #define TXC_ATXAMP_1120_mV 12
877e51b439SBen Hutchings #define TXC_ATXAMP_1060_mV 14
887e51b439SBen Hutchings #define TXC_ATXAMP_0820_mV 25
897e51b439SBen Hutchings #define TXC_ATXAMP_0720_mV 26
907e51b439SBen Hutchings #define TXC_ATXAMP_0580_mV 27
917e51b439SBen Hutchings #define TXC_ATXAMP_0440_mV 28
927e51b439SBen Hutchings
937e51b439SBen Hutchings #define TXC_ATXAMP_0820_BOTH \
947e51b439SBen Hutchings ((TXC_ATXAMP_0820_mV << TXC_ATXAMP_LANE02_LBN) \
957e51b439SBen Hutchings | (TXC_ATXAMP_0820_mV << TXC_ATXAMP_LANE13_LBN))
967e51b439SBen Hutchings
977e51b439SBen Hutchings #define TXC_ATXAMP_DEFAULT 0x6060 /* From databook */
987e51b439SBen Hutchings
997e51b439SBen Hutchings /* Preemphasis on lanes 0, 1 */
1007e51b439SBen Hutchings #define TXC_ALRGS_ATXPRE0 0xc043
1017e51b439SBen Hutchings /* Preemphasis on lanes 2, 3 */
1027e51b439SBen Hutchings #define TXC_ALRGS_ATXPRE1 0xc044
1037e51b439SBen Hutchings
1047e51b439SBen Hutchings #define TXC_ATXPRE_NONE 0
1057e51b439SBen Hutchings #define TXC_ATXPRE_DEFAULT 0x1010 /* From databook */
1067e51b439SBen Hutchings
1077e51b439SBen Hutchings #define TXC_ALRGS_ARXCTL 0xc045
1087e51b439SBen Hutchings /* Lane power-down */
1097e51b439SBen Hutchings #define TXC_ARXCTL_RXPD3_LBN 15
1107e51b439SBen Hutchings #define TXC_ARXCTL_RXPD2_LBN 14
1117e51b439SBen Hutchings #define TXC_ARXCTL_RXPD1_LBN 13
1127e51b439SBen Hutchings #define TXC_ARXCTL_RXPD0_LBN 12
1137e51b439SBen Hutchings
1147e51b439SBen Hutchings /* Main control */
1157e51b439SBen Hutchings #define TXC_MRGS_CTL 0xc340
1167e51b439SBen Hutchings /* Bits in main control */
1177e51b439SBen Hutchings #define TXC_MCTL_RESET_LBN 15 /* Self clear */
1187e51b439SBen Hutchings #define TXC_MCTL_TXLED_LBN 14 /* 1 to show align status */
1197e51b439SBen Hutchings #define TXC_MCTL_RXLED_LBN 13 /* 1 to show align status */
1207e51b439SBen Hutchings
1217e51b439SBen Hutchings /* GPIO output */
1227e51b439SBen Hutchings #define TXC_GPIO_OUTPUT 0xc346
1237e51b439SBen Hutchings #define TXC_GPIO_DIR 0xc348
1247e51b439SBen Hutchings
1257e51b439SBen Hutchings /* Vendor-specific BIST registers */
1267e51b439SBen Hutchings #define TXC_BIST_CTL 0xc280
1277e51b439SBen Hutchings #define TXC_BIST_TXFRMCNT 0xc281
1287e51b439SBen Hutchings #define TXC_BIST_RX0FRMCNT 0xc282
1297e51b439SBen Hutchings #define TXC_BIST_RX1FRMCNT 0xc283
1307e51b439SBen Hutchings #define TXC_BIST_RX2FRMCNT 0xc284
1317e51b439SBen Hutchings #define TXC_BIST_RX3FRMCNT 0xc285
1327e51b439SBen Hutchings #define TXC_BIST_RX0ERRCNT 0xc286
1337e51b439SBen Hutchings #define TXC_BIST_RX1ERRCNT 0xc287
1347e51b439SBen Hutchings #define TXC_BIST_RX2ERRCNT 0xc288
1357e51b439SBen Hutchings #define TXC_BIST_RX3ERRCNT 0xc289
1367e51b439SBen Hutchings
1377e51b439SBen Hutchings /* BIST type (controls bit patter in test) */
1387e51b439SBen Hutchings #define TXC_BIST_CTRL_TYPE_LBN 10
1397e51b439SBen Hutchings #define TXC_BIST_CTRL_TYPE_TSD 0 /* TranSwitch Deterministic */
1407e51b439SBen Hutchings #define TXC_BIST_CTRL_TYPE_CRP 1 /* CRPAT standard */
1417e51b439SBen Hutchings #define TXC_BIST_CTRL_TYPE_CJP 2 /* CJPAT standard */
1427e51b439SBen Hutchings #define TXC_BIST_CTRL_TYPE_TSR 3 /* TranSwitch pseudo-random */
1437e51b439SBen Hutchings /* Set this to 1 for 10 bit and 0 for 8 bit */
1447e51b439SBen Hutchings #define TXC_BIST_CTRL_B10EN_LBN 12
1457e51b439SBen Hutchings /* Enable BIST (write 0 to disable) */
1467e51b439SBen Hutchings #define TXC_BIST_CTRL_ENAB_LBN 13
1477e51b439SBen Hutchings /* Stop BIST (self-clears when stop complete) */
1487e51b439SBen Hutchings #define TXC_BIST_CTRL_STOP_LBN 14
1497e51b439SBen Hutchings /* Start BIST (cleared by writing 1 to STOP) */
1507e51b439SBen Hutchings #define TXC_BIST_CTRL_STRT_LBN 15
1517e51b439SBen Hutchings
1527e51b439SBen Hutchings /* Mt. Diablo test configuration */
1537e51b439SBen Hutchings #define TXC_MTDIABLO_CTRL 0xc34f
1547e51b439SBen Hutchings #define TXC_MTDIABLO_CTRL_PMA_LOOP_LBN 10
1557e51b439SBen Hutchings
1567e51b439SBen Hutchings struct txc43128_data {
1577e51b439SBen Hutchings unsigned long bug10934_timer;
1585a6681e2SEdward Cree enum ef4_phy_mode phy_mode;
1595a6681e2SEdward Cree enum ef4_loopback_mode loopback_mode;
1607e51b439SBen Hutchings };
1617e51b439SBen Hutchings
1627e51b439SBen Hutchings /* The PHY sometimes needs a reset to bring the link back up. So long as
1637e51b439SBen Hutchings * it reports link down, we reset it every 5 seconds.
1647e51b439SBen Hutchings */
1657e51b439SBen Hutchings #define BUG10934_RESET_INTERVAL (5 * HZ)
1667e51b439SBen Hutchings
1677e51b439SBen Hutchings /* Perform a reset that doesn't clear configuration changes */
1685a6681e2SEdward Cree static void txc_reset_logic(struct ef4_nic *efx);
1697e51b439SBen Hutchings
1707e51b439SBen Hutchings /* Set the output value of a gpio */
falcon_txc_set_gpio_val(struct ef4_nic * efx,int pin,int on)1715a6681e2SEdward Cree void falcon_txc_set_gpio_val(struct ef4_nic *efx, int pin, int on)
1727e51b439SBen Hutchings {
1735a6681e2SEdward Cree ef4_mdio_set_flag(efx, MDIO_MMD_PHYXS, TXC_GPIO_OUTPUT, 1 << pin, on);
1747e51b439SBen Hutchings }
1757e51b439SBen Hutchings
1767e51b439SBen Hutchings /* Set up the GPIO direction register */
falcon_txc_set_gpio_dir(struct ef4_nic * efx,int pin,int dir)1775a6681e2SEdward Cree void falcon_txc_set_gpio_dir(struct ef4_nic *efx, int pin, int dir)
1787e51b439SBen Hutchings {
1795a6681e2SEdward Cree ef4_mdio_set_flag(efx, MDIO_MMD_PHYXS, TXC_GPIO_DIR, 1 << pin, dir);
1807e51b439SBen Hutchings }
1817e51b439SBen Hutchings
1827e51b439SBen Hutchings /* Reset the PMA/PMD MMD. The documentation is explicit that this does a
1837e51b439SBen Hutchings * global reset (it's less clear what reset of other MMDs does).*/
txc_reset_phy(struct ef4_nic * efx)1845a6681e2SEdward Cree static int txc_reset_phy(struct ef4_nic *efx)
1857e51b439SBen Hutchings {
1865a6681e2SEdward Cree int rc = ef4_mdio_reset_mmd(efx, MDIO_MMD_PMAPMD,
1877e51b439SBen Hutchings TXC_MAX_RESET_TIME / TXC_RESET_WAIT,
1887e51b439SBen Hutchings TXC_RESET_WAIT);
1897e51b439SBen Hutchings if (rc < 0)
1907e51b439SBen Hutchings goto fail;
1917e51b439SBen Hutchings
1927e51b439SBen Hutchings /* Check that all the MMDs we expect are present and responding. */
1935a6681e2SEdward Cree rc = ef4_mdio_check_mmds(efx, TXC_REQUIRED_DEVS);
1947e51b439SBen Hutchings if (rc < 0)
1957e51b439SBen Hutchings goto fail;
1967e51b439SBen Hutchings
1977e51b439SBen Hutchings return 0;
1987e51b439SBen Hutchings
1997e51b439SBen Hutchings fail:
2007e51b439SBen Hutchings netif_err(efx, hw, efx->net_dev, TXCNAME ": reset timed out!\n");
2017e51b439SBen Hutchings return rc;
2027e51b439SBen Hutchings }
2037e51b439SBen Hutchings
2047e51b439SBen Hutchings /* Run a single BIST on one MMD */
txc_bist_one(struct ef4_nic * efx,int mmd,int test)2055a6681e2SEdward Cree static int txc_bist_one(struct ef4_nic *efx, int mmd, int test)
2067e51b439SBen Hutchings {
2077e51b439SBen Hutchings int ctrl, bctl;
2087e51b439SBen Hutchings int lane;
2097e51b439SBen Hutchings int rc = 0;
2107e51b439SBen Hutchings
2117e51b439SBen Hutchings /* Set PMA to test into loopback using Mt Diablo reg as per app note */
2125a6681e2SEdward Cree ctrl = ef4_mdio_read(efx, MDIO_MMD_PCS, TXC_MTDIABLO_CTRL);
2137e51b439SBen Hutchings ctrl |= (1 << TXC_MTDIABLO_CTRL_PMA_LOOP_LBN);
2145a6681e2SEdward Cree ef4_mdio_write(efx, MDIO_MMD_PCS, TXC_MTDIABLO_CTRL, ctrl);
2157e51b439SBen Hutchings
2167e51b439SBen Hutchings /* The BIST app. note lists these as 3 distinct steps. */
2177e51b439SBen Hutchings /* Set the BIST type */
2187e51b439SBen Hutchings bctl = (test << TXC_BIST_CTRL_TYPE_LBN);
2195a6681e2SEdward Cree ef4_mdio_write(efx, mmd, TXC_BIST_CTL, bctl);
2207e51b439SBen Hutchings
2217e51b439SBen Hutchings /* Set the BSTEN bit in the BIST Control register to enable */
2227e51b439SBen Hutchings bctl |= (1 << TXC_BIST_CTRL_ENAB_LBN);
2235a6681e2SEdward Cree ef4_mdio_write(efx, mmd, TXC_BIST_CTL, bctl);
2247e51b439SBen Hutchings
2257e51b439SBen Hutchings /* Set the BSTRT bit in the BIST Control register */
2265a6681e2SEdward Cree ef4_mdio_write(efx, mmd, TXC_BIST_CTL,
2277e51b439SBen Hutchings bctl | (1 << TXC_BIST_CTRL_STRT_LBN));
2287e51b439SBen Hutchings
2297e51b439SBen Hutchings /* Wait. */
2307e51b439SBen Hutchings udelay(TXC_BIST_DURATION);
2317e51b439SBen Hutchings
2327e51b439SBen Hutchings /* Set the BSTOP bit in the BIST Control register */
2337e51b439SBen Hutchings bctl |= (1 << TXC_BIST_CTRL_STOP_LBN);
2345a6681e2SEdward Cree ef4_mdio_write(efx, mmd, TXC_BIST_CTL, bctl);
2357e51b439SBen Hutchings
2367e51b439SBen Hutchings /* The STOP bit should go off when things have stopped */
2377e51b439SBen Hutchings while (bctl & (1 << TXC_BIST_CTRL_STOP_LBN))
2385a6681e2SEdward Cree bctl = ef4_mdio_read(efx, mmd, TXC_BIST_CTL);
2397e51b439SBen Hutchings
2407e51b439SBen Hutchings /* Check all the error counts are 0 and all the frame counts are
2417e51b439SBen Hutchings non-zero */
2427e51b439SBen Hutchings for (lane = 0; lane < 4; lane++) {
2435a6681e2SEdward Cree int count = ef4_mdio_read(efx, mmd, TXC_BIST_RX0ERRCNT + lane);
2447e51b439SBen Hutchings if (count != 0) {
2457e51b439SBen Hutchings netif_err(efx, hw, efx->net_dev, TXCNAME": BIST error. "
2467e51b439SBen Hutchings "Lane %d had %d errs\n", lane, count);
2477e51b439SBen Hutchings rc = -EIO;
2487e51b439SBen Hutchings }
2495a6681e2SEdward Cree count = ef4_mdio_read(efx, mmd, TXC_BIST_RX0FRMCNT + lane);
2507e51b439SBen Hutchings if (count == 0) {
2517e51b439SBen Hutchings netif_err(efx, hw, efx->net_dev, TXCNAME": BIST error. "
2527e51b439SBen Hutchings "Lane %d got 0 frames\n", lane);
2537e51b439SBen Hutchings rc = -EIO;
2547e51b439SBen Hutchings }
2557e51b439SBen Hutchings }
2567e51b439SBen Hutchings
2577e51b439SBen Hutchings if (rc == 0)
2587e51b439SBen Hutchings netif_info(efx, hw, efx->net_dev, TXCNAME": BIST pass\n");
2597e51b439SBen Hutchings
2607e51b439SBen Hutchings /* Disable BIST */
2615a6681e2SEdward Cree ef4_mdio_write(efx, mmd, TXC_BIST_CTL, 0);
2627e51b439SBen Hutchings
2637e51b439SBen Hutchings /* Turn off loopback */
2647e51b439SBen Hutchings ctrl &= ~(1 << TXC_MTDIABLO_CTRL_PMA_LOOP_LBN);
2655a6681e2SEdward Cree ef4_mdio_write(efx, MDIO_MMD_PCS, TXC_MTDIABLO_CTRL, ctrl);
2667e51b439SBen Hutchings
2677e51b439SBen Hutchings return rc;
2687e51b439SBen Hutchings }
2697e51b439SBen Hutchings
txc_bist(struct ef4_nic * efx)2705a6681e2SEdward Cree static int txc_bist(struct ef4_nic *efx)
2717e51b439SBen Hutchings {
2727e51b439SBen Hutchings return txc_bist_one(efx, MDIO_MMD_PCS, TXC_BIST_CTRL_TYPE_TSD);
2737e51b439SBen Hutchings }
2747e51b439SBen Hutchings
2757e51b439SBen Hutchings /* Push the non-configurable defaults into the PHY. This must be
2767e51b439SBen Hutchings * done after every full reset */
txc_apply_defaults(struct ef4_nic * efx)2775a6681e2SEdward Cree static void txc_apply_defaults(struct ef4_nic *efx)
2787e51b439SBen Hutchings {
2797e51b439SBen Hutchings int mctrl;
2807e51b439SBen Hutchings
2817e51b439SBen Hutchings /* Turn amplitude down and preemphasis off on the host side
2827e51b439SBen Hutchings * (PHY<->MAC) as this is believed less likely to upset Falcon
2837e51b439SBen Hutchings * and no adverse effects have been noted. It probably also
2847e51b439SBen Hutchings * saves a picowatt or two */
2857e51b439SBen Hutchings
2867e51b439SBen Hutchings /* Turn off preemphasis */
2875a6681e2SEdward Cree ef4_mdio_write(efx, MDIO_MMD_PHYXS, TXC_ALRGS_ATXPRE0, TXC_ATXPRE_NONE);
2885a6681e2SEdward Cree ef4_mdio_write(efx, MDIO_MMD_PHYXS, TXC_ALRGS_ATXPRE1, TXC_ATXPRE_NONE);
2897e51b439SBen Hutchings
2907e51b439SBen Hutchings /* Turn down the amplitude */
2915a6681e2SEdward Cree ef4_mdio_write(efx, MDIO_MMD_PHYXS,
2927e51b439SBen Hutchings TXC_ALRGS_ATXAMP0, TXC_ATXAMP_0820_BOTH);
2935a6681e2SEdward Cree ef4_mdio_write(efx, MDIO_MMD_PHYXS,
2947e51b439SBen Hutchings TXC_ALRGS_ATXAMP1, TXC_ATXAMP_0820_BOTH);
2957e51b439SBen Hutchings
2967e51b439SBen Hutchings /* Set the line side amplitude and preemphasis to the databook
2977e51b439SBen Hutchings * defaults as an erratum causes them to be 0 on at least some
2987e51b439SBen Hutchings * PHY rev.s */
2995a6681e2SEdward Cree ef4_mdio_write(efx, MDIO_MMD_PMAPMD,
3007e51b439SBen Hutchings TXC_ALRGS_ATXPRE0, TXC_ATXPRE_DEFAULT);
3015a6681e2SEdward Cree ef4_mdio_write(efx, MDIO_MMD_PMAPMD,
3027e51b439SBen Hutchings TXC_ALRGS_ATXPRE1, TXC_ATXPRE_DEFAULT);
3035a6681e2SEdward Cree ef4_mdio_write(efx, MDIO_MMD_PMAPMD,
3047e51b439SBen Hutchings TXC_ALRGS_ATXAMP0, TXC_ATXAMP_DEFAULT);
3055a6681e2SEdward Cree ef4_mdio_write(efx, MDIO_MMD_PMAPMD,
3067e51b439SBen Hutchings TXC_ALRGS_ATXAMP1, TXC_ATXAMP_DEFAULT);
3077e51b439SBen Hutchings
3087e51b439SBen Hutchings /* Set up the LEDs */
3095a6681e2SEdward Cree mctrl = ef4_mdio_read(efx, MDIO_MMD_PHYXS, TXC_MRGS_CTL);
3107e51b439SBen Hutchings
3117e51b439SBen Hutchings /* Set the Green and Red LEDs to their default modes */
3127e51b439SBen Hutchings mctrl &= ~((1 << TXC_MCTL_TXLED_LBN) | (1 << TXC_MCTL_RXLED_LBN));
3135a6681e2SEdward Cree ef4_mdio_write(efx, MDIO_MMD_PHYXS, TXC_MRGS_CTL, mctrl);
3147e51b439SBen Hutchings
3157e51b439SBen Hutchings /* Databook recommends doing this after configuration changes */
3167e51b439SBen Hutchings txc_reset_logic(efx);
3177e51b439SBen Hutchings
3187e51b439SBen Hutchings falcon_board(efx)->type->init_phy(efx);
3197e51b439SBen Hutchings }
3207e51b439SBen Hutchings
txc43128_phy_probe(struct ef4_nic * efx)3215a6681e2SEdward Cree static int txc43128_phy_probe(struct ef4_nic *efx)
3227e51b439SBen Hutchings {
3237e51b439SBen Hutchings struct txc43128_data *phy_data;
3247e51b439SBen Hutchings
3257e51b439SBen Hutchings /* Allocate phy private storage */
3267e51b439SBen Hutchings phy_data = kzalloc(sizeof(*phy_data), GFP_KERNEL);
3277e51b439SBen Hutchings if (!phy_data)
3287e51b439SBen Hutchings return -ENOMEM;
3297e51b439SBen Hutchings efx->phy_data = phy_data;
3307e51b439SBen Hutchings phy_data->phy_mode = efx->phy_mode;
3317e51b439SBen Hutchings
3327e51b439SBen Hutchings efx->mdio.mmds = TXC_REQUIRED_DEVS;
3337e51b439SBen Hutchings efx->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
3347e51b439SBen Hutchings
3357e51b439SBen Hutchings efx->loopback_modes = TXC_LOOPBACKS | FALCON_XMAC_LOOPBACKS;
3367e51b439SBen Hutchings
3377e51b439SBen Hutchings return 0;
3387e51b439SBen Hutchings }
3397e51b439SBen Hutchings
3407e51b439SBen Hutchings /* Initialisation entry point for this PHY driver */
txc43128_phy_init(struct ef4_nic * efx)3415a6681e2SEdward Cree static int txc43128_phy_init(struct ef4_nic *efx)
3427e51b439SBen Hutchings {
3437e51b439SBen Hutchings int rc;
3447e51b439SBen Hutchings
3457e51b439SBen Hutchings rc = txc_reset_phy(efx);
3467e51b439SBen Hutchings if (rc < 0)
3477e51b439SBen Hutchings return rc;
3487e51b439SBen Hutchings
3497e51b439SBen Hutchings rc = txc_bist(efx);
3507e51b439SBen Hutchings if (rc < 0)
3517e51b439SBen Hutchings return rc;
3527e51b439SBen Hutchings
3537e51b439SBen Hutchings txc_apply_defaults(efx);
3547e51b439SBen Hutchings
3557e51b439SBen Hutchings return 0;
3567e51b439SBen Hutchings }
3577e51b439SBen Hutchings
3587e51b439SBen Hutchings /* Set the lane power down state in the global registers */
txc_glrgs_lane_power(struct ef4_nic * efx,int mmd)3595a6681e2SEdward Cree static void txc_glrgs_lane_power(struct ef4_nic *efx, int mmd)
3607e51b439SBen Hutchings {
3617e51b439SBen Hutchings int pd = (1 << TXC_GLCMD_L01PD_LBN) | (1 << TXC_GLCMD_L23PD_LBN);
3625a6681e2SEdward Cree int ctl = ef4_mdio_read(efx, mmd, TXC_GLRGS_GLCMD);
3637e51b439SBen Hutchings
3647e51b439SBen Hutchings if (!(efx->phy_mode & PHY_MODE_LOW_POWER))
3657e51b439SBen Hutchings ctl &= ~pd;
3667e51b439SBen Hutchings else
3677e51b439SBen Hutchings ctl |= pd;
3687e51b439SBen Hutchings
3695a6681e2SEdward Cree ef4_mdio_write(efx, mmd, TXC_GLRGS_GLCMD, ctl);
3707e51b439SBen Hutchings }
3717e51b439SBen Hutchings
3727e51b439SBen Hutchings /* Set the lane power down state in the analog control registers */
txc_analog_lane_power(struct ef4_nic * efx,int mmd)3735a6681e2SEdward Cree static void txc_analog_lane_power(struct ef4_nic *efx, int mmd)
3747e51b439SBen Hutchings {
3757e51b439SBen Hutchings int txpd = (1 << TXC_ATXCTL_TXPD3_LBN) | (1 << TXC_ATXCTL_TXPD2_LBN)
3767e51b439SBen Hutchings | (1 << TXC_ATXCTL_TXPD1_LBN) | (1 << TXC_ATXCTL_TXPD0_LBN);
3777e51b439SBen Hutchings int rxpd = (1 << TXC_ARXCTL_RXPD3_LBN) | (1 << TXC_ARXCTL_RXPD2_LBN)
3787e51b439SBen Hutchings | (1 << TXC_ARXCTL_RXPD1_LBN) | (1 << TXC_ARXCTL_RXPD0_LBN);
3795a6681e2SEdward Cree int txctl = ef4_mdio_read(efx, mmd, TXC_ALRGS_ATXCTL);
3805a6681e2SEdward Cree int rxctl = ef4_mdio_read(efx, mmd, TXC_ALRGS_ARXCTL);
3817e51b439SBen Hutchings
3827e51b439SBen Hutchings if (!(efx->phy_mode & PHY_MODE_LOW_POWER)) {
3837e51b439SBen Hutchings txctl &= ~txpd;
3847e51b439SBen Hutchings rxctl &= ~rxpd;
3857e51b439SBen Hutchings } else {
3867e51b439SBen Hutchings txctl |= txpd;
3877e51b439SBen Hutchings rxctl |= rxpd;
3887e51b439SBen Hutchings }
3897e51b439SBen Hutchings
3905a6681e2SEdward Cree ef4_mdio_write(efx, mmd, TXC_ALRGS_ATXCTL, txctl);
3915a6681e2SEdward Cree ef4_mdio_write(efx, mmd, TXC_ALRGS_ARXCTL, rxctl);
3927e51b439SBen Hutchings }
3937e51b439SBen Hutchings
txc_set_power(struct ef4_nic * efx)3945a6681e2SEdward Cree static void txc_set_power(struct ef4_nic *efx)
3957e51b439SBen Hutchings {
3967e51b439SBen Hutchings /* According to the data book, all the MMDs can do low power */
3975a6681e2SEdward Cree ef4_mdio_set_mmds_lpower(efx,
3987e51b439SBen Hutchings !!(efx->phy_mode & PHY_MODE_LOW_POWER),
3997e51b439SBen Hutchings TXC_REQUIRED_DEVS);
4007e51b439SBen Hutchings
4017e51b439SBen Hutchings /* Global register bank is in PCS, PHY XS. These control the host
4027e51b439SBen Hutchings * side and line side settings respectively. */
4037e51b439SBen Hutchings txc_glrgs_lane_power(efx, MDIO_MMD_PCS);
4047e51b439SBen Hutchings txc_glrgs_lane_power(efx, MDIO_MMD_PHYXS);
4057e51b439SBen Hutchings
4067e51b439SBen Hutchings /* Analog register bank in PMA/PMD, PHY XS */
4077e51b439SBen Hutchings txc_analog_lane_power(efx, MDIO_MMD_PMAPMD);
4087e51b439SBen Hutchings txc_analog_lane_power(efx, MDIO_MMD_PHYXS);
4097e51b439SBen Hutchings }
4107e51b439SBen Hutchings
txc_reset_logic_mmd(struct ef4_nic * efx,int mmd)4115a6681e2SEdward Cree static void txc_reset_logic_mmd(struct ef4_nic *efx, int mmd)
4127e51b439SBen Hutchings {
4135a6681e2SEdward Cree int val = ef4_mdio_read(efx, mmd, TXC_GLRGS_GLCMD);
4147e51b439SBen Hutchings int tries = 50;
4157e51b439SBen Hutchings
4167e51b439SBen Hutchings val |= (1 << TXC_GLCMD_LMTSWRST_LBN);
4175a6681e2SEdward Cree ef4_mdio_write(efx, mmd, TXC_GLRGS_GLCMD, val);
418fe0be35eSDan Carpenter while (--tries) {
4195a6681e2SEdward Cree val = ef4_mdio_read(efx, mmd, TXC_GLRGS_GLCMD);
4207e51b439SBen Hutchings if (!(val & (1 << TXC_GLCMD_LMTSWRST_LBN)))
4217e51b439SBen Hutchings break;
4227e51b439SBen Hutchings udelay(1);
4237e51b439SBen Hutchings }
4247e51b439SBen Hutchings if (!tries)
4257e51b439SBen Hutchings netif_info(efx, hw, efx->net_dev,
4267e51b439SBen Hutchings TXCNAME " Logic reset timed out!\n");
4277e51b439SBen Hutchings }
4287e51b439SBen Hutchings
4297e51b439SBen Hutchings /* Perform a logic reset. This preserves the configuration registers
4307e51b439SBen Hutchings * and is needed for some configuration changes to take effect */
txc_reset_logic(struct ef4_nic * efx)4315a6681e2SEdward Cree static void txc_reset_logic(struct ef4_nic *efx)
4327e51b439SBen Hutchings {
4337e51b439SBen Hutchings /* The data sheet claims we can do the logic reset on either the
4347e51b439SBen Hutchings * PCS or the PHYXS and the result is a reset of both host- and
4357e51b439SBen Hutchings * line-side logic. */
4367e51b439SBen Hutchings txc_reset_logic_mmd(efx, MDIO_MMD_PCS);
4377e51b439SBen Hutchings }
4387e51b439SBen Hutchings
txc43128_phy_read_link(struct ef4_nic * efx)4395a6681e2SEdward Cree static bool txc43128_phy_read_link(struct ef4_nic *efx)
4407e51b439SBen Hutchings {
4415a6681e2SEdward Cree return ef4_mdio_links_ok(efx, TXC_REQUIRED_DEVS);
4427e51b439SBen Hutchings }
4437e51b439SBen Hutchings
txc43128_phy_reconfigure(struct ef4_nic * efx)4445a6681e2SEdward Cree static int txc43128_phy_reconfigure(struct ef4_nic *efx)
4457e51b439SBen Hutchings {
4467e51b439SBen Hutchings struct txc43128_data *phy_data = efx->phy_data;
4475a6681e2SEdward Cree enum ef4_phy_mode mode_change = efx->phy_mode ^ phy_data->phy_mode;
4487e51b439SBen Hutchings bool loop_change = LOOPBACK_CHANGED(phy_data, efx, TXC_LOOPBACKS);
4497e51b439SBen Hutchings
4507e51b439SBen Hutchings if (efx->phy_mode & mode_change & PHY_MODE_TX_DISABLED) {
4517e51b439SBen Hutchings txc_reset_phy(efx);
4527e51b439SBen Hutchings txc_apply_defaults(efx);
4537e51b439SBen Hutchings falcon_reset_xaui(efx);
4547e51b439SBen Hutchings mode_change &= ~PHY_MODE_TX_DISABLED;
4557e51b439SBen Hutchings }
4567e51b439SBen Hutchings
4575a6681e2SEdward Cree ef4_mdio_transmit_disable(efx);
4585a6681e2SEdward Cree ef4_mdio_phy_reconfigure(efx);
4597e51b439SBen Hutchings if (mode_change & PHY_MODE_LOW_POWER)
4607e51b439SBen Hutchings txc_set_power(efx);
4617e51b439SBen Hutchings
4627e51b439SBen Hutchings /* The data sheet claims this is required after every reconfiguration
4637e51b439SBen Hutchings * (note at end of 7.1), but we mustn't do it when nothing changes as
4647e51b439SBen Hutchings * it glitches the link, and reconfigure gets called on link change,
4657e51b439SBen Hutchings * so we get an IRQ storm on link up. */
4667e51b439SBen Hutchings if (loop_change || mode_change)
4677e51b439SBen Hutchings txc_reset_logic(efx);
4687e51b439SBen Hutchings
4697e51b439SBen Hutchings phy_data->phy_mode = efx->phy_mode;
4707e51b439SBen Hutchings phy_data->loopback_mode = efx->loopback_mode;
4717e51b439SBen Hutchings
4727e51b439SBen Hutchings return 0;
4737e51b439SBen Hutchings }
4747e51b439SBen Hutchings
txc43128_phy_fini(struct ef4_nic * efx)4755a6681e2SEdward Cree static void txc43128_phy_fini(struct ef4_nic *efx)
4767e51b439SBen Hutchings {
4777e51b439SBen Hutchings /* Disable link events */
4785a6681e2SEdward Cree ef4_mdio_write(efx, MDIO_MMD_PMAPMD, MDIO_PMA_LASI_CTRL, 0);
4797e51b439SBen Hutchings }
4807e51b439SBen Hutchings
txc43128_phy_remove(struct ef4_nic * efx)4815a6681e2SEdward Cree static void txc43128_phy_remove(struct ef4_nic *efx)
4827e51b439SBen Hutchings {
4837e51b439SBen Hutchings kfree(efx->phy_data);
4847e51b439SBen Hutchings efx->phy_data = NULL;
4857e51b439SBen Hutchings }
4867e51b439SBen Hutchings
4877e51b439SBen Hutchings /* Periodic callback: this exists mainly to poll link status as we
4887e51b439SBen Hutchings * don't use LASI interrupts */
txc43128_phy_poll(struct ef4_nic * efx)4895a6681e2SEdward Cree static bool txc43128_phy_poll(struct ef4_nic *efx)
4907e51b439SBen Hutchings {
4917e51b439SBen Hutchings struct txc43128_data *data = efx->phy_data;
4927e51b439SBen Hutchings bool was_up = efx->link_state.up;
4937e51b439SBen Hutchings
4947e51b439SBen Hutchings efx->link_state.up = txc43128_phy_read_link(efx);
4957e51b439SBen Hutchings efx->link_state.speed = 10000;
4967e51b439SBen Hutchings efx->link_state.fd = true;
4977e51b439SBen Hutchings efx->link_state.fc = efx->wanted_fc;
4987e51b439SBen Hutchings
4997e51b439SBen Hutchings if (efx->link_state.up || (efx->loopback_mode != LOOPBACK_NONE)) {
5007e51b439SBen Hutchings data->bug10934_timer = jiffies;
5017e51b439SBen Hutchings } else {
5027e51b439SBen Hutchings if (time_after_eq(jiffies, (data->bug10934_timer +
5037e51b439SBen Hutchings BUG10934_RESET_INTERVAL))) {
5047e51b439SBen Hutchings data->bug10934_timer = jiffies;
5057e51b439SBen Hutchings txc_reset_logic(efx);
5067e51b439SBen Hutchings }
5077e51b439SBen Hutchings }
5087e51b439SBen Hutchings
5097e51b439SBen Hutchings return efx->link_state.up != was_up;
5107e51b439SBen Hutchings }
5117e51b439SBen Hutchings
51218e83e4cSBen Hutchings static const char *const txc43128_test_names[] = {
5137e51b439SBen Hutchings "bist"
5147e51b439SBen Hutchings };
5157e51b439SBen Hutchings
txc43128_test_name(struct ef4_nic * efx,unsigned int index)5165a6681e2SEdward Cree static const char *txc43128_test_name(struct ef4_nic *efx, unsigned int index)
5177e51b439SBen Hutchings {
5187e51b439SBen Hutchings if (index < ARRAY_SIZE(txc43128_test_names))
5197e51b439SBen Hutchings return txc43128_test_names[index];
5207e51b439SBen Hutchings return NULL;
5217e51b439SBen Hutchings }
5227e51b439SBen Hutchings
txc43128_run_tests(struct ef4_nic * efx,int * results,unsigned flags)5235a6681e2SEdward Cree static int txc43128_run_tests(struct ef4_nic *efx, int *results, unsigned flags)
5247e51b439SBen Hutchings {
5257e51b439SBen Hutchings int rc;
5267e51b439SBen Hutchings
5277e51b439SBen Hutchings if (!(flags & ETH_TEST_FL_OFFLINE))
5287e51b439SBen Hutchings return 0;
5297e51b439SBen Hutchings
5307e51b439SBen Hutchings rc = txc_reset_phy(efx);
5317e51b439SBen Hutchings if (rc < 0)
5327e51b439SBen Hutchings return rc;
5337e51b439SBen Hutchings
5347e51b439SBen Hutchings rc = txc_bist(efx);
5357e51b439SBen Hutchings txc_apply_defaults(efx);
5367e51b439SBen Hutchings results[0] = rc ? -1 : 1;
5377e51b439SBen Hutchings return rc;
5387e51b439SBen Hutchings }
5397e51b439SBen Hutchings
txc43128_get_link_ksettings(struct ef4_nic * efx,struct ethtool_link_ksettings * cmd)540e938ed15SPhilippe Reynes static void txc43128_get_link_ksettings(struct ef4_nic *efx,
541e938ed15SPhilippe Reynes struct ethtool_link_ksettings *cmd)
5427e51b439SBen Hutchings {
543e938ed15SPhilippe Reynes mdio45_ethtool_ksettings_get(&efx->mdio, cmd);
5447e51b439SBen Hutchings }
5457e51b439SBen Hutchings
5465a6681e2SEdward Cree const struct ef4_phy_operations falcon_txc_phy_ops = {
5477e51b439SBen Hutchings .probe = txc43128_phy_probe,
5487e51b439SBen Hutchings .init = txc43128_phy_init,
5497e51b439SBen Hutchings .reconfigure = txc43128_phy_reconfigure,
5507e51b439SBen Hutchings .poll = txc43128_phy_poll,
5517e51b439SBen Hutchings .fini = txc43128_phy_fini,
5527e51b439SBen Hutchings .remove = txc43128_phy_remove,
553e938ed15SPhilippe Reynes .get_link_ksettings = txc43128_get_link_ksettings,
554e938ed15SPhilippe Reynes .set_link_ksettings = ef4_mdio_set_link_ksettings,
5555a6681e2SEdward Cree .test_alive = ef4_mdio_test_alive,
5567e51b439SBen Hutchings .run_tests = txc43128_run_tests,
5577e51b439SBen Hutchings .test_name = txc43128_test_name,
5587e51b439SBen Hutchings };
559