18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/**************************************************************************** 38c2ecf20Sopenharmony_ci * Driver for Solarflare network controllers and boards 48c2ecf20Sopenharmony_ci * Copyright 2006-2011 Solarflare Communications Inc. 58c2ecf20Sopenharmony_ci */ 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci/* 88c2ecf20Sopenharmony_ci * Driver for Transwitch/Mysticom CX4 retimer 98c2ecf20Sopenharmony_ci * see www.transwitch.com, part is TXC-43128 108c2ecf20Sopenharmony_ci */ 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci#include <linux/delay.h> 138c2ecf20Sopenharmony_ci#include <linux/slab.h> 148c2ecf20Sopenharmony_ci#include "efx.h" 158c2ecf20Sopenharmony_ci#include "mdio_10g.h" 168c2ecf20Sopenharmony_ci#include "phy.h" 178c2ecf20Sopenharmony_ci#include "nic.h" 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci/* We expect these MMDs to be in the package */ 208c2ecf20Sopenharmony_ci#define TXC_REQUIRED_DEVS (MDIO_DEVS_PCS | \ 218c2ecf20Sopenharmony_ci MDIO_DEVS_PMAPMD | \ 228c2ecf20Sopenharmony_ci MDIO_DEVS_PHYXS) 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci#define TXC_LOOPBACKS ((1 << LOOPBACK_PCS) | \ 258c2ecf20Sopenharmony_ci (1 << LOOPBACK_PMAPMD) | \ 268c2ecf20Sopenharmony_ci (1 << LOOPBACK_PHYXS_WS)) 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci/************************************************************************** 298c2ecf20Sopenharmony_ci * 308c2ecf20Sopenharmony_ci * Compile-time config 318c2ecf20Sopenharmony_ci * 328c2ecf20Sopenharmony_ci ************************************************************************** 338c2ecf20Sopenharmony_ci */ 348c2ecf20Sopenharmony_ci#define TXCNAME "TXC43128" 358c2ecf20Sopenharmony_ci/* Total length of time we'll wait for the PHY to come out of reset (ms) */ 368c2ecf20Sopenharmony_ci#define TXC_MAX_RESET_TIME 500 378c2ecf20Sopenharmony_ci/* Interval between checks (ms) */ 388c2ecf20Sopenharmony_ci#define TXC_RESET_WAIT 10 398c2ecf20Sopenharmony_ci/* How long to run BIST (us) */ 408c2ecf20Sopenharmony_ci#define TXC_BIST_DURATION 50 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci/************************************************************************** 438c2ecf20Sopenharmony_ci * 448c2ecf20Sopenharmony_ci * Register definitions 458c2ecf20Sopenharmony_ci * 468c2ecf20Sopenharmony_ci ************************************************************************** 478c2ecf20Sopenharmony_ci */ 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ci/* Command register */ 508c2ecf20Sopenharmony_ci#define TXC_GLRGS_GLCMD 0xc004 518c2ecf20Sopenharmony_ci/* Useful bits in command register */ 528c2ecf20Sopenharmony_ci/* Lane power-down */ 538c2ecf20Sopenharmony_ci#define TXC_GLCMD_L01PD_LBN 5 548c2ecf20Sopenharmony_ci#define TXC_GLCMD_L23PD_LBN 6 558c2ecf20Sopenharmony_ci/* Limited SW reset: preserves configuration but 568c2ecf20Sopenharmony_ci * initiates a logic reset. Self-clearing */ 578c2ecf20Sopenharmony_ci#define TXC_GLCMD_LMTSWRST_LBN 14 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci/* Signal Quality Control */ 608c2ecf20Sopenharmony_ci#define TXC_GLRGS_GSGQLCTL 0xc01a 618c2ecf20Sopenharmony_ci/* Enable bit */ 628c2ecf20Sopenharmony_ci#define TXC_GSGQLCT_SGQLEN_LBN 15 638c2ecf20Sopenharmony_ci/* Lane selection */ 648c2ecf20Sopenharmony_ci#define TXC_GSGQLCT_LNSL_LBN 13 658c2ecf20Sopenharmony_ci#define TXC_GSGQLCT_LNSL_WIDTH 2 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci/* Analog TX control */ 688c2ecf20Sopenharmony_ci#define TXC_ALRGS_ATXCTL 0xc040 698c2ecf20Sopenharmony_ci/* Lane power-down */ 708c2ecf20Sopenharmony_ci#define TXC_ATXCTL_TXPD3_LBN 15 718c2ecf20Sopenharmony_ci#define TXC_ATXCTL_TXPD2_LBN 14 728c2ecf20Sopenharmony_ci#define TXC_ATXCTL_TXPD1_LBN 13 738c2ecf20Sopenharmony_ci#define TXC_ATXCTL_TXPD0_LBN 12 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ci/* Amplitude on lanes 0, 1 */ 768c2ecf20Sopenharmony_ci#define TXC_ALRGS_ATXAMP0 0xc041 778c2ecf20Sopenharmony_ci/* Amplitude on lanes 2, 3 */ 788c2ecf20Sopenharmony_ci#define TXC_ALRGS_ATXAMP1 0xc042 798c2ecf20Sopenharmony_ci/* Bit position of value for lane 0 (or 2) */ 808c2ecf20Sopenharmony_ci#define TXC_ATXAMP_LANE02_LBN 3 818c2ecf20Sopenharmony_ci/* Bit position of value for lane 1 (or 3) */ 828c2ecf20Sopenharmony_ci#define TXC_ATXAMP_LANE13_LBN 11 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_ci#define TXC_ATXAMP_1280_mV 0 858c2ecf20Sopenharmony_ci#define TXC_ATXAMP_1200_mV 8 868c2ecf20Sopenharmony_ci#define TXC_ATXAMP_1120_mV 12 878c2ecf20Sopenharmony_ci#define TXC_ATXAMP_1060_mV 14 888c2ecf20Sopenharmony_ci#define TXC_ATXAMP_0820_mV 25 898c2ecf20Sopenharmony_ci#define TXC_ATXAMP_0720_mV 26 908c2ecf20Sopenharmony_ci#define TXC_ATXAMP_0580_mV 27 918c2ecf20Sopenharmony_ci#define TXC_ATXAMP_0440_mV 28 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_ci#define TXC_ATXAMP_0820_BOTH \ 948c2ecf20Sopenharmony_ci ((TXC_ATXAMP_0820_mV << TXC_ATXAMP_LANE02_LBN) \ 958c2ecf20Sopenharmony_ci | (TXC_ATXAMP_0820_mV << TXC_ATXAMP_LANE13_LBN)) 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_ci#define TXC_ATXAMP_DEFAULT 0x6060 /* From databook */ 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_ci/* Preemphasis on lanes 0, 1 */ 1008c2ecf20Sopenharmony_ci#define TXC_ALRGS_ATXPRE0 0xc043 1018c2ecf20Sopenharmony_ci/* Preemphasis on lanes 2, 3 */ 1028c2ecf20Sopenharmony_ci#define TXC_ALRGS_ATXPRE1 0xc044 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_ci#define TXC_ATXPRE_NONE 0 1058c2ecf20Sopenharmony_ci#define TXC_ATXPRE_DEFAULT 0x1010 /* From databook */ 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ci#define TXC_ALRGS_ARXCTL 0xc045 1088c2ecf20Sopenharmony_ci/* Lane power-down */ 1098c2ecf20Sopenharmony_ci#define TXC_ARXCTL_RXPD3_LBN 15 1108c2ecf20Sopenharmony_ci#define TXC_ARXCTL_RXPD2_LBN 14 1118c2ecf20Sopenharmony_ci#define TXC_ARXCTL_RXPD1_LBN 13 1128c2ecf20Sopenharmony_ci#define TXC_ARXCTL_RXPD0_LBN 12 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_ci/* Main control */ 1158c2ecf20Sopenharmony_ci#define TXC_MRGS_CTL 0xc340 1168c2ecf20Sopenharmony_ci/* Bits in main control */ 1178c2ecf20Sopenharmony_ci#define TXC_MCTL_RESET_LBN 15 /* Self clear */ 1188c2ecf20Sopenharmony_ci#define TXC_MCTL_TXLED_LBN 14 /* 1 to show align status */ 1198c2ecf20Sopenharmony_ci#define TXC_MCTL_RXLED_LBN 13 /* 1 to show align status */ 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_ci/* GPIO output */ 1228c2ecf20Sopenharmony_ci#define TXC_GPIO_OUTPUT 0xc346 1238c2ecf20Sopenharmony_ci#define TXC_GPIO_DIR 0xc348 1248c2ecf20Sopenharmony_ci 1258c2ecf20Sopenharmony_ci/* Vendor-specific BIST registers */ 1268c2ecf20Sopenharmony_ci#define TXC_BIST_CTL 0xc280 1278c2ecf20Sopenharmony_ci#define TXC_BIST_TXFRMCNT 0xc281 1288c2ecf20Sopenharmony_ci#define TXC_BIST_RX0FRMCNT 0xc282 1298c2ecf20Sopenharmony_ci#define TXC_BIST_RX1FRMCNT 0xc283 1308c2ecf20Sopenharmony_ci#define TXC_BIST_RX2FRMCNT 0xc284 1318c2ecf20Sopenharmony_ci#define TXC_BIST_RX3FRMCNT 0xc285 1328c2ecf20Sopenharmony_ci#define TXC_BIST_RX0ERRCNT 0xc286 1338c2ecf20Sopenharmony_ci#define TXC_BIST_RX1ERRCNT 0xc287 1348c2ecf20Sopenharmony_ci#define TXC_BIST_RX2ERRCNT 0xc288 1358c2ecf20Sopenharmony_ci#define TXC_BIST_RX3ERRCNT 0xc289 1368c2ecf20Sopenharmony_ci 1378c2ecf20Sopenharmony_ci/* BIST type (controls bit patter in test) */ 1388c2ecf20Sopenharmony_ci#define TXC_BIST_CTRL_TYPE_LBN 10 1398c2ecf20Sopenharmony_ci#define TXC_BIST_CTRL_TYPE_TSD 0 /* TranSwitch Deterministic */ 1408c2ecf20Sopenharmony_ci#define TXC_BIST_CTRL_TYPE_CRP 1 /* CRPAT standard */ 1418c2ecf20Sopenharmony_ci#define TXC_BIST_CTRL_TYPE_CJP 2 /* CJPAT standard */ 1428c2ecf20Sopenharmony_ci#define TXC_BIST_CTRL_TYPE_TSR 3 /* TranSwitch pseudo-random */ 1438c2ecf20Sopenharmony_ci/* Set this to 1 for 10 bit and 0 for 8 bit */ 1448c2ecf20Sopenharmony_ci#define TXC_BIST_CTRL_B10EN_LBN 12 1458c2ecf20Sopenharmony_ci/* Enable BIST (write 0 to disable) */ 1468c2ecf20Sopenharmony_ci#define TXC_BIST_CTRL_ENAB_LBN 13 1478c2ecf20Sopenharmony_ci/* Stop BIST (self-clears when stop complete) */ 1488c2ecf20Sopenharmony_ci#define TXC_BIST_CTRL_STOP_LBN 14 1498c2ecf20Sopenharmony_ci/* Start BIST (cleared by writing 1 to STOP) */ 1508c2ecf20Sopenharmony_ci#define TXC_BIST_CTRL_STRT_LBN 15 1518c2ecf20Sopenharmony_ci 1528c2ecf20Sopenharmony_ci/* Mt. Diablo test configuration */ 1538c2ecf20Sopenharmony_ci#define TXC_MTDIABLO_CTRL 0xc34f 1548c2ecf20Sopenharmony_ci#define TXC_MTDIABLO_CTRL_PMA_LOOP_LBN 10 1558c2ecf20Sopenharmony_ci 1568c2ecf20Sopenharmony_cistruct txc43128_data { 1578c2ecf20Sopenharmony_ci unsigned long bug10934_timer; 1588c2ecf20Sopenharmony_ci enum ef4_phy_mode phy_mode; 1598c2ecf20Sopenharmony_ci enum ef4_loopback_mode loopback_mode; 1608c2ecf20Sopenharmony_ci}; 1618c2ecf20Sopenharmony_ci 1628c2ecf20Sopenharmony_ci/* The PHY sometimes needs a reset to bring the link back up. So long as 1638c2ecf20Sopenharmony_ci * it reports link down, we reset it every 5 seconds. 1648c2ecf20Sopenharmony_ci */ 1658c2ecf20Sopenharmony_ci#define BUG10934_RESET_INTERVAL (5 * HZ) 1668c2ecf20Sopenharmony_ci 1678c2ecf20Sopenharmony_ci/* Perform a reset that doesn't clear configuration changes */ 1688c2ecf20Sopenharmony_cistatic void txc_reset_logic(struct ef4_nic *efx); 1698c2ecf20Sopenharmony_ci 1708c2ecf20Sopenharmony_ci/* Set the output value of a gpio */ 1718c2ecf20Sopenharmony_civoid falcon_txc_set_gpio_val(struct ef4_nic *efx, int pin, int on) 1728c2ecf20Sopenharmony_ci{ 1738c2ecf20Sopenharmony_ci ef4_mdio_set_flag(efx, MDIO_MMD_PHYXS, TXC_GPIO_OUTPUT, 1 << pin, on); 1748c2ecf20Sopenharmony_ci} 1758c2ecf20Sopenharmony_ci 1768c2ecf20Sopenharmony_ci/* Set up the GPIO direction register */ 1778c2ecf20Sopenharmony_civoid falcon_txc_set_gpio_dir(struct ef4_nic *efx, int pin, int dir) 1788c2ecf20Sopenharmony_ci{ 1798c2ecf20Sopenharmony_ci ef4_mdio_set_flag(efx, MDIO_MMD_PHYXS, TXC_GPIO_DIR, 1 << pin, dir); 1808c2ecf20Sopenharmony_ci} 1818c2ecf20Sopenharmony_ci 1828c2ecf20Sopenharmony_ci/* Reset the PMA/PMD MMD. The documentation is explicit that this does a 1838c2ecf20Sopenharmony_ci * global reset (it's less clear what reset of other MMDs does).*/ 1848c2ecf20Sopenharmony_cistatic int txc_reset_phy(struct ef4_nic *efx) 1858c2ecf20Sopenharmony_ci{ 1868c2ecf20Sopenharmony_ci int rc = ef4_mdio_reset_mmd(efx, MDIO_MMD_PMAPMD, 1878c2ecf20Sopenharmony_ci TXC_MAX_RESET_TIME / TXC_RESET_WAIT, 1888c2ecf20Sopenharmony_ci TXC_RESET_WAIT); 1898c2ecf20Sopenharmony_ci if (rc < 0) 1908c2ecf20Sopenharmony_ci goto fail; 1918c2ecf20Sopenharmony_ci 1928c2ecf20Sopenharmony_ci /* Check that all the MMDs we expect are present and responding. */ 1938c2ecf20Sopenharmony_ci rc = ef4_mdio_check_mmds(efx, TXC_REQUIRED_DEVS); 1948c2ecf20Sopenharmony_ci if (rc < 0) 1958c2ecf20Sopenharmony_ci goto fail; 1968c2ecf20Sopenharmony_ci 1978c2ecf20Sopenharmony_ci return 0; 1988c2ecf20Sopenharmony_ci 1998c2ecf20Sopenharmony_cifail: 2008c2ecf20Sopenharmony_ci netif_err(efx, hw, efx->net_dev, TXCNAME ": reset timed out!\n"); 2018c2ecf20Sopenharmony_ci return rc; 2028c2ecf20Sopenharmony_ci} 2038c2ecf20Sopenharmony_ci 2048c2ecf20Sopenharmony_ci/* Run a single BIST on one MMD */ 2058c2ecf20Sopenharmony_cistatic int txc_bist_one(struct ef4_nic *efx, int mmd, int test) 2068c2ecf20Sopenharmony_ci{ 2078c2ecf20Sopenharmony_ci int ctrl, bctl; 2088c2ecf20Sopenharmony_ci int lane; 2098c2ecf20Sopenharmony_ci int rc = 0; 2108c2ecf20Sopenharmony_ci 2118c2ecf20Sopenharmony_ci /* Set PMA to test into loopback using Mt Diablo reg as per app note */ 2128c2ecf20Sopenharmony_ci ctrl = ef4_mdio_read(efx, MDIO_MMD_PCS, TXC_MTDIABLO_CTRL); 2138c2ecf20Sopenharmony_ci ctrl |= (1 << TXC_MTDIABLO_CTRL_PMA_LOOP_LBN); 2148c2ecf20Sopenharmony_ci ef4_mdio_write(efx, MDIO_MMD_PCS, TXC_MTDIABLO_CTRL, ctrl); 2158c2ecf20Sopenharmony_ci 2168c2ecf20Sopenharmony_ci /* The BIST app. note lists these as 3 distinct steps. */ 2178c2ecf20Sopenharmony_ci /* Set the BIST type */ 2188c2ecf20Sopenharmony_ci bctl = (test << TXC_BIST_CTRL_TYPE_LBN); 2198c2ecf20Sopenharmony_ci ef4_mdio_write(efx, mmd, TXC_BIST_CTL, bctl); 2208c2ecf20Sopenharmony_ci 2218c2ecf20Sopenharmony_ci /* Set the BSTEN bit in the BIST Control register to enable */ 2228c2ecf20Sopenharmony_ci bctl |= (1 << TXC_BIST_CTRL_ENAB_LBN); 2238c2ecf20Sopenharmony_ci ef4_mdio_write(efx, mmd, TXC_BIST_CTL, bctl); 2248c2ecf20Sopenharmony_ci 2258c2ecf20Sopenharmony_ci /* Set the BSTRT bit in the BIST Control register */ 2268c2ecf20Sopenharmony_ci ef4_mdio_write(efx, mmd, TXC_BIST_CTL, 2278c2ecf20Sopenharmony_ci bctl | (1 << TXC_BIST_CTRL_STRT_LBN)); 2288c2ecf20Sopenharmony_ci 2298c2ecf20Sopenharmony_ci /* Wait. */ 2308c2ecf20Sopenharmony_ci udelay(TXC_BIST_DURATION); 2318c2ecf20Sopenharmony_ci 2328c2ecf20Sopenharmony_ci /* Set the BSTOP bit in the BIST Control register */ 2338c2ecf20Sopenharmony_ci bctl |= (1 << TXC_BIST_CTRL_STOP_LBN); 2348c2ecf20Sopenharmony_ci ef4_mdio_write(efx, mmd, TXC_BIST_CTL, bctl); 2358c2ecf20Sopenharmony_ci 2368c2ecf20Sopenharmony_ci /* The STOP bit should go off when things have stopped */ 2378c2ecf20Sopenharmony_ci while (bctl & (1 << TXC_BIST_CTRL_STOP_LBN)) 2388c2ecf20Sopenharmony_ci bctl = ef4_mdio_read(efx, mmd, TXC_BIST_CTL); 2398c2ecf20Sopenharmony_ci 2408c2ecf20Sopenharmony_ci /* Check all the error counts are 0 and all the frame counts are 2418c2ecf20Sopenharmony_ci non-zero */ 2428c2ecf20Sopenharmony_ci for (lane = 0; lane < 4; lane++) { 2438c2ecf20Sopenharmony_ci int count = ef4_mdio_read(efx, mmd, TXC_BIST_RX0ERRCNT + lane); 2448c2ecf20Sopenharmony_ci if (count != 0) { 2458c2ecf20Sopenharmony_ci netif_err(efx, hw, efx->net_dev, TXCNAME": BIST error. " 2468c2ecf20Sopenharmony_ci "Lane %d had %d errs\n", lane, count); 2478c2ecf20Sopenharmony_ci rc = -EIO; 2488c2ecf20Sopenharmony_ci } 2498c2ecf20Sopenharmony_ci count = ef4_mdio_read(efx, mmd, TXC_BIST_RX0FRMCNT + lane); 2508c2ecf20Sopenharmony_ci if (count == 0) { 2518c2ecf20Sopenharmony_ci netif_err(efx, hw, efx->net_dev, TXCNAME": BIST error. " 2528c2ecf20Sopenharmony_ci "Lane %d got 0 frames\n", lane); 2538c2ecf20Sopenharmony_ci rc = -EIO; 2548c2ecf20Sopenharmony_ci } 2558c2ecf20Sopenharmony_ci } 2568c2ecf20Sopenharmony_ci 2578c2ecf20Sopenharmony_ci if (rc == 0) 2588c2ecf20Sopenharmony_ci netif_info(efx, hw, efx->net_dev, TXCNAME": BIST pass\n"); 2598c2ecf20Sopenharmony_ci 2608c2ecf20Sopenharmony_ci /* Disable BIST */ 2618c2ecf20Sopenharmony_ci ef4_mdio_write(efx, mmd, TXC_BIST_CTL, 0); 2628c2ecf20Sopenharmony_ci 2638c2ecf20Sopenharmony_ci /* Turn off loopback */ 2648c2ecf20Sopenharmony_ci ctrl &= ~(1 << TXC_MTDIABLO_CTRL_PMA_LOOP_LBN); 2658c2ecf20Sopenharmony_ci ef4_mdio_write(efx, MDIO_MMD_PCS, TXC_MTDIABLO_CTRL, ctrl); 2668c2ecf20Sopenharmony_ci 2678c2ecf20Sopenharmony_ci return rc; 2688c2ecf20Sopenharmony_ci} 2698c2ecf20Sopenharmony_ci 2708c2ecf20Sopenharmony_cistatic int txc_bist(struct ef4_nic *efx) 2718c2ecf20Sopenharmony_ci{ 2728c2ecf20Sopenharmony_ci return txc_bist_one(efx, MDIO_MMD_PCS, TXC_BIST_CTRL_TYPE_TSD); 2738c2ecf20Sopenharmony_ci} 2748c2ecf20Sopenharmony_ci 2758c2ecf20Sopenharmony_ci/* Push the non-configurable defaults into the PHY. This must be 2768c2ecf20Sopenharmony_ci * done after every full reset */ 2778c2ecf20Sopenharmony_cistatic void txc_apply_defaults(struct ef4_nic *efx) 2788c2ecf20Sopenharmony_ci{ 2798c2ecf20Sopenharmony_ci int mctrl; 2808c2ecf20Sopenharmony_ci 2818c2ecf20Sopenharmony_ci /* Turn amplitude down and preemphasis off on the host side 2828c2ecf20Sopenharmony_ci * (PHY<->MAC) as this is believed less likely to upset Falcon 2838c2ecf20Sopenharmony_ci * and no adverse effects have been noted. It probably also 2848c2ecf20Sopenharmony_ci * saves a picowatt or two */ 2858c2ecf20Sopenharmony_ci 2868c2ecf20Sopenharmony_ci /* Turn off preemphasis */ 2878c2ecf20Sopenharmony_ci ef4_mdio_write(efx, MDIO_MMD_PHYXS, TXC_ALRGS_ATXPRE0, TXC_ATXPRE_NONE); 2888c2ecf20Sopenharmony_ci ef4_mdio_write(efx, MDIO_MMD_PHYXS, TXC_ALRGS_ATXPRE1, TXC_ATXPRE_NONE); 2898c2ecf20Sopenharmony_ci 2908c2ecf20Sopenharmony_ci /* Turn down the amplitude */ 2918c2ecf20Sopenharmony_ci ef4_mdio_write(efx, MDIO_MMD_PHYXS, 2928c2ecf20Sopenharmony_ci TXC_ALRGS_ATXAMP0, TXC_ATXAMP_0820_BOTH); 2938c2ecf20Sopenharmony_ci ef4_mdio_write(efx, MDIO_MMD_PHYXS, 2948c2ecf20Sopenharmony_ci TXC_ALRGS_ATXAMP1, TXC_ATXAMP_0820_BOTH); 2958c2ecf20Sopenharmony_ci 2968c2ecf20Sopenharmony_ci /* Set the line side amplitude and preemphasis to the databook 2978c2ecf20Sopenharmony_ci * defaults as an erratum causes them to be 0 on at least some 2988c2ecf20Sopenharmony_ci * PHY rev.s */ 2998c2ecf20Sopenharmony_ci ef4_mdio_write(efx, MDIO_MMD_PMAPMD, 3008c2ecf20Sopenharmony_ci TXC_ALRGS_ATXPRE0, TXC_ATXPRE_DEFAULT); 3018c2ecf20Sopenharmony_ci ef4_mdio_write(efx, MDIO_MMD_PMAPMD, 3028c2ecf20Sopenharmony_ci TXC_ALRGS_ATXPRE1, TXC_ATXPRE_DEFAULT); 3038c2ecf20Sopenharmony_ci ef4_mdio_write(efx, MDIO_MMD_PMAPMD, 3048c2ecf20Sopenharmony_ci TXC_ALRGS_ATXAMP0, TXC_ATXAMP_DEFAULT); 3058c2ecf20Sopenharmony_ci ef4_mdio_write(efx, MDIO_MMD_PMAPMD, 3068c2ecf20Sopenharmony_ci TXC_ALRGS_ATXAMP1, TXC_ATXAMP_DEFAULT); 3078c2ecf20Sopenharmony_ci 3088c2ecf20Sopenharmony_ci /* Set up the LEDs */ 3098c2ecf20Sopenharmony_ci mctrl = ef4_mdio_read(efx, MDIO_MMD_PHYXS, TXC_MRGS_CTL); 3108c2ecf20Sopenharmony_ci 3118c2ecf20Sopenharmony_ci /* Set the Green and Red LEDs to their default modes */ 3128c2ecf20Sopenharmony_ci mctrl &= ~((1 << TXC_MCTL_TXLED_LBN) | (1 << TXC_MCTL_RXLED_LBN)); 3138c2ecf20Sopenharmony_ci ef4_mdio_write(efx, MDIO_MMD_PHYXS, TXC_MRGS_CTL, mctrl); 3148c2ecf20Sopenharmony_ci 3158c2ecf20Sopenharmony_ci /* Databook recommends doing this after configuration changes */ 3168c2ecf20Sopenharmony_ci txc_reset_logic(efx); 3178c2ecf20Sopenharmony_ci 3188c2ecf20Sopenharmony_ci falcon_board(efx)->type->init_phy(efx); 3198c2ecf20Sopenharmony_ci} 3208c2ecf20Sopenharmony_ci 3218c2ecf20Sopenharmony_cistatic int txc43128_phy_probe(struct ef4_nic *efx) 3228c2ecf20Sopenharmony_ci{ 3238c2ecf20Sopenharmony_ci struct txc43128_data *phy_data; 3248c2ecf20Sopenharmony_ci 3258c2ecf20Sopenharmony_ci /* Allocate phy private storage */ 3268c2ecf20Sopenharmony_ci phy_data = kzalloc(sizeof(*phy_data), GFP_KERNEL); 3278c2ecf20Sopenharmony_ci if (!phy_data) 3288c2ecf20Sopenharmony_ci return -ENOMEM; 3298c2ecf20Sopenharmony_ci efx->phy_data = phy_data; 3308c2ecf20Sopenharmony_ci phy_data->phy_mode = efx->phy_mode; 3318c2ecf20Sopenharmony_ci 3328c2ecf20Sopenharmony_ci efx->mdio.mmds = TXC_REQUIRED_DEVS; 3338c2ecf20Sopenharmony_ci efx->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22; 3348c2ecf20Sopenharmony_ci 3358c2ecf20Sopenharmony_ci efx->loopback_modes = TXC_LOOPBACKS | FALCON_XMAC_LOOPBACKS; 3368c2ecf20Sopenharmony_ci 3378c2ecf20Sopenharmony_ci return 0; 3388c2ecf20Sopenharmony_ci} 3398c2ecf20Sopenharmony_ci 3408c2ecf20Sopenharmony_ci/* Initialisation entry point for this PHY driver */ 3418c2ecf20Sopenharmony_cistatic int txc43128_phy_init(struct ef4_nic *efx) 3428c2ecf20Sopenharmony_ci{ 3438c2ecf20Sopenharmony_ci int rc; 3448c2ecf20Sopenharmony_ci 3458c2ecf20Sopenharmony_ci rc = txc_reset_phy(efx); 3468c2ecf20Sopenharmony_ci if (rc < 0) 3478c2ecf20Sopenharmony_ci return rc; 3488c2ecf20Sopenharmony_ci 3498c2ecf20Sopenharmony_ci rc = txc_bist(efx); 3508c2ecf20Sopenharmony_ci if (rc < 0) 3518c2ecf20Sopenharmony_ci return rc; 3528c2ecf20Sopenharmony_ci 3538c2ecf20Sopenharmony_ci txc_apply_defaults(efx); 3548c2ecf20Sopenharmony_ci 3558c2ecf20Sopenharmony_ci return 0; 3568c2ecf20Sopenharmony_ci} 3578c2ecf20Sopenharmony_ci 3588c2ecf20Sopenharmony_ci/* Set the lane power down state in the global registers */ 3598c2ecf20Sopenharmony_cistatic void txc_glrgs_lane_power(struct ef4_nic *efx, int mmd) 3608c2ecf20Sopenharmony_ci{ 3618c2ecf20Sopenharmony_ci int pd = (1 << TXC_GLCMD_L01PD_LBN) | (1 << TXC_GLCMD_L23PD_LBN); 3628c2ecf20Sopenharmony_ci int ctl = ef4_mdio_read(efx, mmd, TXC_GLRGS_GLCMD); 3638c2ecf20Sopenharmony_ci 3648c2ecf20Sopenharmony_ci if (!(efx->phy_mode & PHY_MODE_LOW_POWER)) 3658c2ecf20Sopenharmony_ci ctl &= ~pd; 3668c2ecf20Sopenharmony_ci else 3678c2ecf20Sopenharmony_ci ctl |= pd; 3688c2ecf20Sopenharmony_ci 3698c2ecf20Sopenharmony_ci ef4_mdio_write(efx, mmd, TXC_GLRGS_GLCMD, ctl); 3708c2ecf20Sopenharmony_ci} 3718c2ecf20Sopenharmony_ci 3728c2ecf20Sopenharmony_ci/* Set the lane power down state in the analog control registers */ 3738c2ecf20Sopenharmony_cistatic void txc_analog_lane_power(struct ef4_nic *efx, int mmd) 3748c2ecf20Sopenharmony_ci{ 3758c2ecf20Sopenharmony_ci int txpd = (1 << TXC_ATXCTL_TXPD3_LBN) | (1 << TXC_ATXCTL_TXPD2_LBN) 3768c2ecf20Sopenharmony_ci | (1 << TXC_ATXCTL_TXPD1_LBN) | (1 << TXC_ATXCTL_TXPD0_LBN); 3778c2ecf20Sopenharmony_ci int rxpd = (1 << TXC_ARXCTL_RXPD3_LBN) | (1 << TXC_ARXCTL_RXPD2_LBN) 3788c2ecf20Sopenharmony_ci | (1 << TXC_ARXCTL_RXPD1_LBN) | (1 << TXC_ARXCTL_RXPD0_LBN); 3798c2ecf20Sopenharmony_ci int txctl = ef4_mdio_read(efx, mmd, TXC_ALRGS_ATXCTL); 3808c2ecf20Sopenharmony_ci int rxctl = ef4_mdio_read(efx, mmd, TXC_ALRGS_ARXCTL); 3818c2ecf20Sopenharmony_ci 3828c2ecf20Sopenharmony_ci if (!(efx->phy_mode & PHY_MODE_LOW_POWER)) { 3838c2ecf20Sopenharmony_ci txctl &= ~txpd; 3848c2ecf20Sopenharmony_ci rxctl &= ~rxpd; 3858c2ecf20Sopenharmony_ci } else { 3868c2ecf20Sopenharmony_ci txctl |= txpd; 3878c2ecf20Sopenharmony_ci rxctl |= rxpd; 3888c2ecf20Sopenharmony_ci } 3898c2ecf20Sopenharmony_ci 3908c2ecf20Sopenharmony_ci ef4_mdio_write(efx, mmd, TXC_ALRGS_ATXCTL, txctl); 3918c2ecf20Sopenharmony_ci ef4_mdio_write(efx, mmd, TXC_ALRGS_ARXCTL, rxctl); 3928c2ecf20Sopenharmony_ci} 3938c2ecf20Sopenharmony_ci 3948c2ecf20Sopenharmony_cistatic void txc_set_power(struct ef4_nic *efx) 3958c2ecf20Sopenharmony_ci{ 3968c2ecf20Sopenharmony_ci /* According to the data book, all the MMDs can do low power */ 3978c2ecf20Sopenharmony_ci ef4_mdio_set_mmds_lpower(efx, 3988c2ecf20Sopenharmony_ci !!(efx->phy_mode & PHY_MODE_LOW_POWER), 3998c2ecf20Sopenharmony_ci TXC_REQUIRED_DEVS); 4008c2ecf20Sopenharmony_ci 4018c2ecf20Sopenharmony_ci /* Global register bank is in PCS, PHY XS. These control the host 4028c2ecf20Sopenharmony_ci * side and line side settings respectively. */ 4038c2ecf20Sopenharmony_ci txc_glrgs_lane_power(efx, MDIO_MMD_PCS); 4048c2ecf20Sopenharmony_ci txc_glrgs_lane_power(efx, MDIO_MMD_PHYXS); 4058c2ecf20Sopenharmony_ci 4068c2ecf20Sopenharmony_ci /* Analog register bank in PMA/PMD, PHY XS */ 4078c2ecf20Sopenharmony_ci txc_analog_lane_power(efx, MDIO_MMD_PMAPMD); 4088c2ecf20Sopenharmony_ci txc_analog_lane_power(efx, MDIO_MMD_PHYXS); 4098c2ecf20Sopenharmony_ci} 4108c2ecf20Sopenharmony_ci 4118c2ecf20Sopenharmony_cistatic void txc_reset_logic_mmd(struct ef4_nic *efx, int mmd) 4128c2ecf20Sopenharmony_ci{ 4138c2ecf20Sopenharmony_ci int val = ef4_mdio_read(efx, mmd, TXC_GLRGS_GLCMD); 4148c2ecf20Sopenharmony_ci int tries = 50; 4158c2ecf20Sopenharmony_ci 4168c2ecf20Sopenharmony_ci val |= (1 << TXC_GLCMD_LMTSWRST_LBN); 4178c2ecf20Sopenharmony_ci ef4_mdio_write(efx, mmd, TXC_GLRGS_GLCMD, val); 4188c2ecf20Sopenharmony_ci while (--tries) { 4198c2ecf20Sopenharmony_ci val = ef4_mdio_read(efx, mmd, TXC_GLRGS_GLCMD); 4208c2ecf20Sopenharmony_ci if (!(val & (1 << TXC_GLCMD_LMTSWRST_LBN))) 4218c2ecf20Sopenharmony_ci break; 4228c2ecf20Sopenharmony_ci udelay(1); 4238c2ecf20Sopenharmony_ci } 4248c2ecf20Sopenharmony_ci if (!tries) 4258c2ecf20Sopenharmony_ci netif_info(efx, hw, efx->net_dev, 4268c2ecf20Sopenharmony_ci TXCNAME " Logic reset timed out!\n"); 4278c2ecf20Sopenharmony_ci} 4288c2ecf20Sopenharmony_ci 4298c2ecf20Sopenharmony_ci/* Perform a logic reset. This preserves the configuration registers 4308c2ecf20Sopenharmony_ci * and is needed for some configuration changes to take effect */ 4318c2ecf20Sopenharmony_cistatic void txc_reset_logic(struct ef4_nic *efx) 4328c2ecf20Sopenharmony_ci{ 4338c2ecf20Sopenharmony_ci /* The data sheet claims we can do the logic reset on either the 4348c2ecf20Sopenharmony_ci * PCS or the PHYXS and the result is a reset of both host- and 4358c2ecf20Sopenharmony_ci * line-side logic. */ 4368c2ecf20Sopenharmony_ci txc_reset_logic_mmd(efx, MDIO_MMD_PCS); 4378c2ecf20Sopenharmony_ci} 4388c2ecf20Sopenharmony_ci 4398c2ecf20Sopenharmony_cistatic bool txc43128_phy_read_link(struct ef4_nic *efx) 4408c2ecf20Sopenharmony_ci{ 4418c2ecf20Sopenharmony_ci return ef4_mdio_links_ok(efx, TXC_REQUIRED_DEVS); 4428c2ecf20Sopenharmony_ci} 4438c2ecf20Sopenharmony_ci 4448c2ecf20Sopenharmony_cistatic int txc43128_phy_reconfigure(struct ef4_nic *efx) 4458c2ecf20Sopenharmony_ci{ 4468c2ecf20Sopenharmony_ci struct txc43128_data *phy_data = efx->phy_data; 4478c2ecf20Sopenharmony_ci enum ef4_phy_mode mode_change = efx->phy_mode ^ phy_data->phy_mode; 4488c2ecf20Sopenharmony_ci bool loop_change = LOOPBACK_CHANGED(phy_data, efx, TXC_LOOPBACKS); 4498c2ecf20Sopenharmony_ci 4508c2ecf20Sopenharmony_ci if (efx->phy_mode & mode_change & PHY_MODE_TX_DISABLED) { 4518c2ecf20Sopenharmony_ci txc_reset_phy(efx); 4528c2ecf20Sopenharmony_ci txc_apply_defaults(efx); 4538c2ecf20Sopenharmony_ci falcon_reset_xaui(efx); 4548c2ecf20Sopenharmony_ci mode_change &= ~PHY_MODE_TX_DISABLED; 4558c2ecf20Sopenharmony_ci } 4568c2ecf20Sopenharmony_ci 4578c2ecf20Sopenharmony_ci ef4_mdio_transmit_disable(efx); 4588c2ecf20Sopenharmony_ci ef4_mdio_phy_reconfigure(efx); 4598c2ecf20Sopenharmony_ci if (mode_change & PHY_MODE_LOW_POWER) 4608c2ecf20Sopenharmony_ci txc_set_power(efx); 4618c2ecf20Sopenharmony_ci 4628c2ecf20Sopenharmony_ci /* The data sheet claims this is required after every reconfiguration 4638c2ecf20Sopenharmony_ci * (note at end of 7.1), but we mustn't do it when nothing changes as 4648c2ecf20Sopenharmony_ci * it glitches the link, and reconfigure gets called on link change, 4658c2ecf20Sopenharmony_ci * so we get an IRQ storm on link up. */ 4668c2ecf20Sopenharmony_ci if (loop_change || mode_change) 4678c2ecf20Sopenharmony_ci txc_reset_logic(efx); 4688c2ecf20Sopenharmony_ci 4698c2ecf20Sopenharmony_ci phy_data->phy_mode = efx->phy_mode; 4708c2ecf20Sopenharmony_ci phy_data->loopback_mode = efx->loopback_mode; 4718c2ecf20Sopenharmony_ci 4728c2ecf20Sopenharmony_ci return 0; 4738c2ecf20Sopenharmony_ci} 4748c2ecf20Sopenharmony_ci 4758c2ecf20Sopenharmony_cistatic void txc43128_phy_fini(struct ef4_nic *efx) 4768c2ecf20Sopenharmony_ci{ 4778c2ecf20Sopenharmony_ci /* Disable link events */ 4788c2ecf20Sopenharmony_ci ef4_mdio_write(efx, MDIO_MMD_PMAPMD, MDIO_PMA_LASI_CTRL, 0); 4798c2ecf20Sopenharmony_ci} 4808c2ecf20Sopenharmony_ci 4818c2ecf20Sopenharmony_cistatic void txc43128_phy_remove(struct ef4_nic *efx) 4828c2ecf20Sopenharmony_ci{ 4838c2ecf20Sopenharmony_ci kfree(efx->phy_data); 4848c2ecf20Sopenharmony_ci efx->phy_data = NULL; 4858c2ecf20Sopenharmony_ci} 4868c2ecf20Sopenharmony_ci 4878c2ecf20Sopenharmony_ci/* Periodic callback: this exists mainly to poll link status as we 4888c2ecf20Sopenharmony_ci * don't use LASI interrupts */ 4898c2ecf20Sopenharmony_cistatic bool txc43128_phy_poll(struct ef4_nic *efx) 4908c2ecf20Sopenharmony_ci{ 4918c2ecf20Sopenharmony_ci struct txc43128_data *data = efx->phy_data; 4928c2ecf20Sopenharmony_ci bool was_up = efx->link_state.up; 4938c2ecf20Sopenharmony_ci 4948c2ecf20Sopenharmony_ci efx->link_state.up = txc43128_phy_read_link(efx); 4958c2ecf20Sopenharmony_ci efx->link_state.speed = 10000; 4968c2ecf20Sopenharmony_ci efx->link_state.fd = true; 4978c2ecf20Sopenharmony_ci efx->link_state.fc = efx->wanted_fc; 4988c2ecf20Sopenharmony_ci 4998c2ecf20Sopenharmony_ci if (efx->link_state.up || (efx->loopback_mode != LOOPBACK_NONE)) { 5008c2ecf20Sopenharmony_ci data->bug10934_timer = jiffies; 5018c2ecf20Sopenharmony_ci } else { 5028c2ecf20Sopenharmony_ci if (time_after_eq(jiffies, (data->bug10934_timer + 5038c2ecf20Sopenharmony_ci BUG10934_RESET_INTERVAL))) { 5048c2ecf20Sopenharmony_ci data->bug10934_timer = jiffies; 5058c2ecf20Sopenharmony_ci txc_reset_logic(efx); 5068c2ecf20Sopenharmony_ci } 5078c2ecf20Sopenharmony_ci } 5088c2ecf20Sopenharmony_ci 5098c2ecf20Sopenharmony_ci return efx->link_state.up != was_up; 5108c2ecf20Sopenharmony_ci} 5118c2ecf20Sopenharmony_ci 5128c2ecf20Sopenharmony_cistatic const char *const txc43128_test_names[] = { 5138c2ecf20Sopenharmony_ci "bist" 5148c2ecf20Sopenharmony_ci}; 5158c2ecf20Sopenharmony_ci 5168c2ecf20Sopenharmony_cistatic const char *txc43128_test_name(struct ef4_nic *efx, unsigned int index) 5178c2ecf20Sopenharmony_ci{ 5188c2ecf20Sopenharmony_ci if (index < ARRAY_SIZE(txc43128_test_names)) 5198c2ecf20Sopenharmony_ci return txc43128_test_names[index]; 5208c2ecf20Sopenharmony_ci return NULL; 5218c2ecf20Sopenharmony_ci} 5228c2ecf20Sopenharmony_ci 5238c2ecf20Sopenharmony_cistatic int txc43128_run_tests(struct ef4_nic *efx, int *results, unsigned flags) 5248c2ecf20Sopenharmony_ci{ 5258c2ecf20Sopenharmony_ci int rc; 5268c2ecf20Sopenharmony_ci 5278c2ecf20Sopenharmony_ci if (!(flags & ETH_TEST_FL_OFFLINE)) 5288c2ecf20Sopenharmony_ci return 0; 5298c2ecf20Sopenharmony_ci 5308c2ecf20Sopenharmony_ci rc = txc_reset_phy(efx); 5318c2ecf20Sopenharmony_ci if (rc < 0) 5328c2ecf20Sopenharmony_ci return rc; 5338c2ecf20Sopenharmony_ci 5348c2ecf20Sopenharmony_ci rc = txc_bist(efx); 5358c2ecf20Sopenharmony_ci txc_apply_defaults(efx); 5368c2ecf20Sopenharmony_ci results[0] = rc ? -1 : 1; 5378c2ecf20Sopenharmony_ci return rc; 5388c2ecf20Sopenharmony_ci} 5398c2ecf20Sopenharmony_ci 5408c2ecf20Sopenharmony_cistatic void txc43128_get_link_ksettings(struct ef4_nic *efx, 5418c2ecf20Sopenharmony_ci struct ethtool_link_ksettings *cmd) 5428c2ecf20Sopenharmony_ci{ 5438c2ecf20Sopenharmony_ci mdio45_ethtool_ksettings_get(&efx->mdio, cmd); 5448c2ecf20Sopenharmony_ci} 5458c2ecf20Sopenharmony_ci 5468c2ecf20Sopenharmony_ciconst struct ef4_phy_operations falcon_txc_phy_ops = { 5478c2ecf20Sopenharmony_ci .probe = txc43128_phy_probe, 5488c2ecf20Sopenharmony_ci .init = txc43128_phy_init, 5498c2ecf20Sopenharmony_ci .reconfigure = txc43128_phy_reconfigure, 5508c2ecf20Sopenharmony_ci .poll = txc43128_phy_poll, 5518c2ecf20Sopenharmony_ci .fini = txc43128_phy_fini, 5528c2ecf20Sopenharmony_ci .remove = txc43128_phy_remove, 5538c2ecf20Sopenharmony_ci .get_link_ksettings = txc43128_get_link_ksettings, 5548c2ecf20Sopenharmony_ci .set_link_ksettings = ef4_mdio_set_link_ksettings, 5558c2ecf20Sopenharmony_ci .test_alive = ef4_mdio_test_alive, 5568c2ecf20Sopenharmony_ci .run_tests = txc43128_run_tests, 5578c2ecf20Sopenharmony_ci .test_name = txc43128_test_name, 5588c2ecf20Sopenharmony_ci}; 559