162306a36Sopenharmony_ci/* 262306a36Sopenharmony_ci * AMD 10Gb Ethernet driver 362306a36Sopenharmony_ci * 462306a36Sopenharmony_ci * This file is available to you under your choice of the following two 562306a36Sopenharmony_ci * licenses: 662306a36Sopenharmony_ci * 762306a36Sopenharmony_ci * License 1: GPLv2 862306a36Sopenharmony_ci * 962306a36Sopenharmony_ci * Copyright (c) 2016 Advanced Micro Devices, Inc. 1062306a36Sopenharmony_ci * 1162306a36Sopenharmony_ci * This file is free software; you may copy, redistribute and/or modify 1262306a36Sopenharmony_ci * it under the terms of the GNU General Public License as published by 1362306a36Sopenharmony_ci * the Free Software Foundation, either version 2 of the License, or (at 1462306a36Sopenharmony_ci * your option) any later version. 1562306a36Sopenharmony_ci * 1662306a36Sopenharmony_ci * This file is distributed in the hope that it will be useful, but 1762306a36Sopenharmony_ci * WITHOUT ANY WARRANTY; without even the implied warranty of 1862306a36Sopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 1962306a36Sopenharmony_ci * General Public License for more details. 2062306a36Sopenharmony_ci * 2162306a36Sopenharmony_ci * You should have received a copy of the GNU General Public License 2262306a36Sopenharmony_ci * along with this program. If not, see <http://www.gnu.org/licenses/>. 2362306a36Sopenharmony_ci * 2462306a36Sopenharmony_ci * This file incorporates work covered by the following copyright and 2562306a36Sopenharmony_ci * permission notice: 2662306a36Sopenharmony_ci * The Synopsys DWC ETHER XGMAC Software Driver and documentation 2762306a36Sopenharmony_ci * (hereinafter "Software") is an unsupported proprietary work of Synopsys, 2862306a36Sopenharmony_ci * Inc. unless otherwise expressly agreed to in writing between Synopsys 2962306a36Sopenharmony_ci * and you. 3062306a36Sopenharmony_ci * 3162306a36Sopenharmony_ci * The Software IS NOT an item of Licensed Software or Licensed Product 3262306a36Sopenharmony_ci * under any End User Software License Agreement or Agreement for Licensed 3362306a36Sopenharmony_ci * Product with Synopsys or any supplement thereto. Permission is hereby 3462306a36Sopenharmony_ci * granted, free of charge, to any person obtaining a copy of this software 3562306a36Sopenharmony_ci * annotated with this license and the Software, to deal in the Software 3662306a36Sopenharmony_ci * without restriction, including without limitation the rights to use, 3762306a36Sopenharmony_ci * copy, modify, merge, publish, distribute, sublicense, and/or sell copies 3862306a36Sopenharmony_ci * of the Software, and to permit persons to whom the Software is furnished 3962306a36Sopenharmony_ci * to do so, subject to the following conditions: 4062306a36Sopenharmony_ci * 4162306a36Sopenharmony_ci * The above copyright notice and this permission notice shall be included 4262306a36Sopenharmony_ci * in all copies or substantial portions of the Software. 4362306a36Sopenharmony_ci * 4462306a36Sopenharmony_ci * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" 4562306a36Sopenharmony_ci * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 4662306a36Sopenharmony_ci * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 4762306a36Sopenharmony_ci * PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS 4862306a36Sopenharmony_ci * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 4962306a36Sopenharmony_ci * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 5062306a36Sopenharmony_ci * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 5162306a36Sopenharmony_ci * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 5262306a36Sopenharmony_ci * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 5362306a36Sopenharmony_ci * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 5462306a36Sopenharmony_ci * THE POSSIBILITY OF SUCH DAMAGE. 5562306a36Sopenharmony_ci * 5662306a36Sopenharmony_ci * 5762306a36Sopenharmony_ci * License 2: Modified BSD 5862306a36Sopenharmony_ci * 5962306a36Sopenharmony_ci * Copyright (c) 2016 Advanced Micro Devices, Inc. 6062306a36Sopenharmony_ci * All rights reserved. 6162306a36Sopenharmony_ci * 6262306a36Sopenharmony_ci * Redistribution and use in source and binary forms, with or without 6362306a36Sopenharmony_ci * modification, are permitted provided that the following conditions are met: 6462306a36Sopenharmony_ci * * Redistributions of source code must retain the above copyright 6562306a36Sopenharmony_ci * notice, this list of conditions and the following disclaimer. 6662306a36Sopenharmony_ci * * Redistributions in binary form must reproduce the above copyright 6762306a36Sopenharmony_ci * notice, this list of conditions and the following disclaimer in the 6862306a36Sopenharmony_ci * documentation and/or other materials provided with the distribution. 6962306a36Sopenharmony_ci * * Neither the name of Advanced Micro Devices, Inc. nor the 7062306a36Sopenharmony_ci * names of its contributors may be used to endorse or promote products 7162306a36Sopenharmony_ci * derived from this software without specific prior written permission. 7262306a36Sopenharmony_ci * 7362306a36Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 7462306a36Sopenharmony_ci * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 7562306a36Sopenharmony_ci * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 7662306a36Sopenharmony_ci * ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY 7762306a36Sopenharmony_ci * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 7862306a36Sopenharmony_ci * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 7962306a36Sopenharmony_ci * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 8062306a36Sopenharmony_ci * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 8162306a36Sopenharmony_ci * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 8262306a36Sopenharmony_ci * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 8362306a36Sopenharmony_ci * 8462306a36Sopenharmony_ci * This file incorporates work covered by the following copyright and 8562306a36Sopenharmony_ci * permission notice: 8662306a36Sopenharmony_ci * The Synopsys DWC ETHER XGMAC Software Driver and documentation 8762306a36Sopenharmony_ci * (hereinafter "Software") is an unsupported proprietary work of Synopsys, 8862306a36Sopenharmony_ci * Inc. unless otherwise expressly agreed to in writing between Synopsys 8962306a36Sopenharmony_ci * and you. 9062306a36Sopenharmony_ci * 9162306a36Sopenharmony_ci * The Software IS NOT an item of Licensed Software or Licensed Product 9262306a36Sopenharmony_ci * under any End User Software License Agreement or Agreement for Licensed 9362306a36Sopenharmony_ci * Product with Synopsys or any supplement thereto. Permission is hereby 9462306a36Sopenharmony_ci * granted, free of charge, to any person obtaining a copy of this software 9562306a36Sopenharmony_ci * annotated with this license and the Software, to deal in the Software 9662306a36Sopenharmony_ci * without restriction, including without limitation the rights to use, 9762306a36Sopenharmony_ci * copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9862306a36Sopenharmony_ci * of the Software, and to permit persons to whom the Software is furnished 9962306a36Sopenharmony_ci * to do so, subject to the following conditions: 10062306a36Sopenharmony_ci * 10162306a36Sopenharmony_ci * The above copyright notice and this permission notice shall be included 10262306a36Sopenharmony_ci * in all copies or substantial portions of the Software. 10362306a36Sopenharmony_ci * 10462306a36Sopenharmony_ci * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" 10562306a36Sopenharmony_ci * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 10662306a36Sopenharmony_ci * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 10762306a36Sopenharmony_ci * PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS 10862306a36Sopenharmony_ci * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 10962306a36Sopenharmony_ci * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 11062306a36Sopenharmony_ci * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 11162306a36Sopenharmony_ci * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 11262306a36Sopenharmony_ci * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 11362306a36Sopenharmony_ci * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 11462306a36Sopenharmony_ci * THE POSSIBILITY OF SUCH DAMAGE. 11562306a36Sopenharmony_ci */ 11662306a36Sopenharmony_ci 11762306a36Sopenharmony_ci#include <linux/module.h> 11862306a36Sopenharmony_ci#include <linux/kmod.h> 11962306a36Sopenharmony_ci#include <linux/device.h> 12062306a36Sopenharmony_ci#include <linux/property.h> 12162306a36Sopenharmony_ci#include <linux/mdio.h> 12262306a36Sopenharmony_ci#include <linux/phy.h> 12362306a36Sopenharmony_ci 12462306a36Sopenharmony_ci#include "xgbe.h" 12562306a36Sopenharmony_ci#include "xgbe-common.h" 12662306a36Sopenharmony_ci 12762306a36Sopenharmony_ci#define XGBE_BLWC_PROPERTY "amd,serdes-blwc" 12862306a36Sopenharmony_ci#define XGBE_CDR_RATE_PROPERTY "amd,serdes-cdr-rate" 12962306a36Sopenharmony_ci#define XGBE_PQ_SKEW_PROPERTY "amd,serdes-pq-skew" 13062306a36Sopenharmony_ci#define XGBE_TX_AMP_PROPERTY "amd,serdes-tx-amp" 13162306a36Sopenharmony_ci#define XGBE_DFE_CFG_PROPERTY "amd,serdes-dfe-tap-config" 13262306a36Sopenharmony_ci#define XGBE_DFE_ENA_PROPERTY "amd,serdes-dfe-tap-enable" 13362306a36Sopenharmony_ci 13462306a36Sopenharmony_ci/* Default SerDes settings */ 13562306a36Sopenharmony_ci#define XGBE_SPEED_1000_BLWC 1 13662306a36Sopenharmony_ci#define XGBE_SPEED_1000_CDR 0x2 13762306a36Sopenharmony_ci#define XGBE_SPEED_1000_PLL 0x0 13862306a36Sopenharmony_ci#define XGBE_SPEED_1000_PQ 0xa 13962306a36Sopenharmony_ci#define XGBE_SPEED_1000_RATE 0x3 14062306a36Sopenharmony_ci#define XGBE_SPEED_1000_TXAMP 0xf 14162306a36Sopenharmony_ci#define XGBE_SPEED_1000_WORD 0x1 14262306a36Sopenharmony_ci#define XGBE_SPEED_1000_DFE_TAP_CONFIG 0x3 14362306a36Sopenharmony_ci#define XGBE_SPEED_1000_DFE_TAP_ENABLE 0x0 14462306a36Sopenharmony_ci 14562306a36Sopenharmony_ci#define XGBE_SPEED_2500_BLWC 1 14662306a36Sopenharmony_ci#define XGBE_SPEED_2500_CDR 0x2 14762306a36Sopenharmony_ci#define XGBE_SPEED_2500_PLL 0x0 14862306a36Sopenharmony_ci#define XGBE_SPEED_2500_PQ 0xa 14962306a36Sopenharmony_ci#define XGBE_SPEED_2500_RATE 0x1 15062306a36Sopenharmony_ci#define XGBE_SPEED_2500_TXAMP 0xf 15162306a36Sopenharmony_ci#define XGBE_SPEED_2500_WORD 0x1 15262306a36Sopenharmony_ci#define XGBE_SPEED_2500_DFE_TAP_CONFIG 0x3 15362306a36Sopenharmony_ci#define XGBE_SPEED_2500_DFE_TAP_ENABLE 0x0 15462306a36Sopenharmony_ci 15562306a36Sopenharmony_ci#define XGBE_SPEED_10000_BLWC 0 15662306a36Sopenharmony_ci#define XGBE_SPEED_10000_CDR 0x7 15762306a36Sopenharmony_ci#define XGBE_SPEED_10000_PLL 0x1 15862306a36Sopenharmony_ci#define XGBE_SPEED_10000_PQ 0x12 15962306a36Sopenharmony_ci#define XGBE_SPEED_10000_RATE 0x0 16062306a36Sopenharmony_ci#define XGBE_SPEED_10000_TXAMP 0xa 16162306a36Sopenharmony_ci#define XGBE_SPEED_10000_WORD 0x7 16262306a36Sopenharmony_ci#define XGBE_SPEED_10000_DFE_TAP_CONFIG 0x1 16362306a36Sopenharmony_ci#define XGBE_SPEED_10000_DFE_TAP_ENABLE 0x7f 16462306a36Sopenharmony_ci 16562306a36Sopenharmony_ci/* Rate-change complete wait/retry count */ 16662306a36Sopenharmony_ci#define XGBE_RATECHANGE_COUNT 500 16762306a36Sopenharmony_ci 16862306a36Sopenharmony_cistatic const u32 xgbe_phy_blwc[] = { 16962306a36Sopenharmony_ci XGBE_SPEED_1000_BLWC, 17062306a36Sopenharmony_ci XGBE_SPEED_2500_BLWC, 17162306a36Sopenharmony_ci XGBE_SPEED_10000_BLWC, 17262306a36Sopenharmony_ci}; 17362306a36Sopenharmony_ci 17462306a36Sopenharmony_cistatic const u32 xgbe_phy_cdr_rate[] = { 17562306a36Sopenharmony_ci XGBE_SPEED_1000_CDR, 17662306a36Sopenharmony_ci XGBE_SPEED_2500_CDR, 17762306a36Sopenharmony_ci XGBE_SPEED_10000_CDR, 17862306a36Sopenharmony_ci}; 17962306a36Sopenharmony_ci 18062306a36Sopenharmony_cistatic const u32 xgbe_phy_pq_skew[] = { 18162306a36Sopenharmony_ci XGBE_SPEED_1000_PQ, 18262306a36Sopenharmony_ci XGBE_SPEED_2500_PQ, 18362306a36Sopenharmony_ci XGBE_SPEED_10000_PQ, 18462306a36Sopenharmony_ci}; 18562306a36Sopenharmony_ci 18662306a36Sopenharmony_cistatic const u32 xgbe_phy_tx_amp[] = { 18762306a36Sopenharmony_ci XGBE_SPEED_1000_TXAMP, 18862306a36Sopenharmony_ci XGBE_SPEED_2500_TXAMP, 18962306a36Sopenharmony_ci XGBE_SPEED_10000_TXAMP, 19062306a36Sopenharmony_ci}; 19162306a36Sopenharmony_ci 19262306a36Sopenharmony_cistatic const u32 xgbe_phy_dfe_tap_cfg[] = { 19362306a36Sopenharmony_ci XGBE_SPEED_1000_DFE_TAP_CONFIG, 19462306a36Sopenharmony_ci XGBE_SPEED_2500_DFE_TAP_CONFIG, 19562306a36Sopenharmony_ci XGBE_SPEED_10000_DFE_TAP_CONFIG, 19662306a36Sopenharmony_ci}; 19762306a36Sopenharmony_ci 19862306a36Sopenharmony_cistatic const u32 xgbe_phy_dfe_tap_ena[] = { 19962306a36Sopenharmony_ci XGBE_SPEED_1000_DFE_TAP_ENABLE, 20062306a36Sopenharmony_ci XGBE_SPEED_2500_DFE_TAP_ENABLE, 20162306a36Sopenharmony_ci XGBE_SPEED_10000_DFE_TAP_ENABLE, 20262306a36Sopenharmony_ci}; 20362306a36Sopenharmony_ci 20462306a36Sopenharmony_cistruct xgbe_phy_data { 20562306a36Sopenharmony_ci /* 1000/10000 vs 2500/10000 indicator */ 20662306a36Sopenharmony_ci unsigned int speed_set; 20762306a36Sopenharmony_ci 20862306a36Sopenharmony_ci /* SerDes UEFI configurable settings. 20962306a36Sopenharmony_ci * Switching between modes/speeds requires new values for some 21062306a36Sopenharmony_ci * SerDes settings. The values can be supplied as device 21162306a36Sopenharmony_ci * properties in array format. The first array entry is for 21262306a36Sopenharmony_ci * 1GbE, second for 2.5GbE and third for 10GbE 21362306a36Sopenharmony_ci */ 21462306a36Sopenharmony_ci u32 blwc[XGBE_SPEEDS]; 21562306a36Sopenharmony_ci u32 cdr_rate[XGBE_SPEEDS]; 21662306a36Sopenharmony_ci u32 pq_skew[XGBE_SPEEDS]; 21762306a36Sopenharmony_ci u32 tx_amp[XGBE_SPEEDS]; 21862306a36Sopenharmony_ci u32 dfe_tap_cfg[XGBE_SPEEDS]; 21962306a36Sopenharmony_ci u32 dfe_tap_ena[XGBE_SPEEDS]; 22062306a36Sopenharmony_ci}; 22162306a36Sopenharmony_ci 22262306a36Sopenharmony_cistatic void xgbe_phy_kr_training_pre(struct xgbe_prv_data *pdata) 22362306a36Sopenharmony_ci{ 22462306a36Sopenharmony_ci XSIR0_IOWRITE_BITS(pdata, SIR0_KR_RT_1, RESET, 1); 22562306a36Sopenharmony_ci} 22662306a36Sopenharmony_ci 22762306a36Sopenharmony_cistatic void xgbe_phy_kr_training_post(struct xgbe_prv_data *pdata) 22862306a36Sopenharmony_ci{ 22962306a36Sopenharmony_ci XSIR0_IOWRITE_BITS(pdata, SIR0_KR_RT_1, RESET, 0); 23062306a36Sopenharmony_ci} 23162306a36Sopenharmony_ci 23262306a36Sopenharmony_cistatic enum xgbe_mode xgbe_phy_an_outcome(struct xgbe_prv_data *pdata) 23362306a36Sopenharmony_ci{ 23462306a36Sopenharmony_ci struct ethtool_link_ksettings *lks = &pdata->phy.lks; 23562306a36Sopenharmony_ci struct xgbe_phy_data *phy_data = pdata->phy_data; 23662306a36Sopenharmony_ci enum xgbe_mode mode; 23762306a36Sopenharmony_ci unsigned int ad_reg, lp_reg; 23862306a36Sopenharmony_ci 23962306a36Sopenharmony_ci XGBE_SET_LP_ADV(lks, Autoneg); 24062306a36Sopenharmony_ci XGBE_SET_LP_ADV(lks, Backplane); 24162306a36Sopenharmony_ci 24262306a36Sopenharmony_ci /* Compare Advertisement and Link Partner register 1 */ 24362306a36Sopenharmony_ci ad_reg = XMDIO_READ(pdata, MDIO_MMD_AN, MDIO_AN_ADVERTISE); 24462306a36Sopenharmony_ci lp_reg = XMDIO_READ(pdata, MDIO_MMD_AN, MDIO_AN_LPA); 24562306a36Sopenharmony_ci if (lp_reg & 0x400) 24662306a36Sopenharmony_ci XGBE_SET_LP_ADV(lks, Pause); 24762306a36Sopenharmony_ci if (lp_reg & 0x800) 24862306a36Sopenharmony_ci XGBE_SET_LP_ADV(lks, Asym_Pause); 24962306a36Sopenharmony_ci 25062306a36Sopenharmony_ci if (pdata->phy.pause_autoneg) { 25162306a36Sopenharmony_ci /* Set flow control based on auto-negotiation result */ 25262306a36Sopenharmony_ci pdata->phy.tx_pause = 0; 25362306a36Sopenharmony_ci pdata->phy.rx_pause = 0; 25462306a36Sopenharmony_ci 25562306a36Sopenharmony_ci if (ad_reg & lp_reg & 0x400) { 25662306a36Sopenharmony_ci pdata->phy.tx_pause = 1; 25762306a36Sopenharmony_ci pdata->phy.rx_pause = 1; 25862306a36Sopenharmony_ci } else if (ad_reg & lp_reg & 0x800) { 25962306a36Sopenharmony_ci if (ad_reg & 0x400) 26062306a36Sopenharmony_ci pdata->phy.rx_pause = 1; 26162306a36Sopenharmony_ci else if (lp_reg & 0x400) 26262306a36Sopenharmony_ci pdata->phy.tx_pause = 1; 26362306a36Sopenharmony_ci } 26462306a36Sopenharmony_ci } 26562306a36Sopenharmony_ci 26662306a36Sopenharmony_ci /* Compare Advertisement and Link Partner register 2 */ 26762306a36Sopenharmony_ci ad_reg = XMDIO_READ(pdata, MDIO_MMD_AN, MDIO_AN_ADVERTISE + 1); 26862306a36Sopenharmony_ci lp_reg = XMDIO_READ(pdata, MDIO_MMD_AN, MDIO_AN_LPA + 1); 26962306a36Sopenharmony_ci if (lp_reg & 0x80) 27062306a36Sopenharmony_ci XGBE_SET_LP_ADV(lks, 10000baseKR_Full); 27162306a36Sopenharmony_ci if (lp_reg & 0x20) { 27262306a36Sopenharmony_ci if (phy_data->speed_set == XGBE_SPEEDSET_2500_10000) 27362306a36Sopenharmony_ci XGBE_SET_LP_ADV(lks, 2500baseX_Full); 27462306a36Sopenharmony_ci else 27562306a36Sopenharmony_ci XGBE_SET_LP_ADV(lks, 1000baseKX_Full); 27662306a36Sopenharmony_ci } 27762306a36Sopenharmony_ci 27862306a36Sopenharmony_ci ad_reg &= lp_reg; 27962306a36Sopenharmony_ci if (ad_reg & 0x80) { 28062306a36Sopenharmony_ci mode = XGBE_MODE_KR; 28162306a36Sopenharmony_ci } else if (ad_reg & 0x20) { 28262306a36Sopenharmony_ci if (phy_data->speed_set == XGBE_SPEEDSET_2500_10000) 28362306a36Sopenharmony_ci mode = XGBE_MODE_KX_2500; 28462306a36Sopenharmony_ci else 28562306a36Sopenharmony_ci mode = XGBE_MODE_KX_1000; 28662306a36Sopenharmony_ci } else { 28762306a36Sopenharmony_ci mode = XGBE_MODE_UNKNOWN; 28862306a36Sopenharmony_ci } 28962306a36Sopenharmony_ci 29062306a36Sopenharmony_ci /* Compare Advertisement and Link Partner register 3 */ 29162306a36Sopenharmony_ci ad_reg = XMDIO_READ(pdata, MDIO_MMD_AN, MDIO_AN_ADVERTISE + 2); 29262306a36Sopenharmony_ci lp_reg = XMDIO_READ(pdata, MDIO_MMD_AN, MDIO_AN_LPA + 2); 29362306a36Sopenharmony_ci if (lp_reg & 0xc000) 29462306a36Sopenharmony_ci XGBE_SET_LP_ADV(lks, 10000baseR_FEC); 29562306a36Sopenharmony_ci 29662306a36Sopenharmony_ci return mode; 29762306a36Sopenharmony_ci} 29862306a36Sopenharmony_ci 29962306a36Sopenharmony_cistatic void xgbe_phy_an_advertising(struct xgbe_prv_data *pdata, 30062306a36Sopenharmony_ci struct ethtool_link_ksettings *dlks) 30162306a36Sopenharmony_ci{ 30262306a36Sopenharmony_ci struct ethtool_link_ksettings *slks = &pdata->phy.lks; 30362306a36Sopenharmony_ci 30462306a36Sopenharmony_ci XGBE_LM_COPY(dlks, advertising, slks, advertising); 30562306a36Sopenharmony_ci} 30662306a36Sopenharmony_ci 30762306a36Sopenharmony_cistatic int xgbe_phy_an_config(struct xgbe_prv_data *pdata) 30862306a36Sopenharmony_ci{ 30962306a36Sopenharmony_ci /* Nothing uniquely required for an configuration */ 31062306a36Sopenharmony_ci return 0; 31162306a36Sopenharmony_ci} 31262306a36Sopenharmony_ci 31362306a36Sopenharmony_cistatic enum xgbe_an_mode xgbe_phy_an_mode(struct xgbe_prv_data *pdata) 31462306a36Sopenharmony_ci{ 31562306a36Sopenharmony_ci return XGBE_AN_MODE_CL73; 31662306a36Sopenharmony_ci} 31762306a36Sopenharmony_ci 31862306a36Sopenharmony_cistatic void xgbe_phy_pcs_power_cycle(struct xgbe_prv_data *pdata) 31962306a36Sopenharmony_ci{ 32062306a36Sopenharmony_ci unsigned int reg; 32162306a36Sopenharmony_ci 32262306a36Sopenharmony_ci reg = XMDIO_READ(pdata, MDIO_MMD_PCS, MDIO_CTRL1); 32362306a36Sopenharmony_ci 32462306a36Sopenharmony_ci reg |= MDIO_CTRL1_LPOWER; 32562306a36Sopenharmony_ci XMDIO_WRITE(pdata, MDIO_MMD_PCS, MDIO_CTRL1, reg); 32662306a36Sopenharmony_ci 32762306a36Sopenharmony_ci usleep_range(75, 100); 32862306a36Sopenharmony_ci 32962306a36Sopenharmony_ci reg &= ~MDIO_CTRL1_LPOWER; 33062306a36Sopenharmony_ci XMDIO_WRITE(pdata, MDIO_MMD_PCS, MDIO_CTRL1, reg); 33162306a36Sopenharmony_ci} 33262306a36Sopenharmony_ci 33362306a36Sopenharmony_cistatic void xgbe_phy_start_ratechange(struct xgbe_prv_data *pdata) 33462306a36Sopenharmony_ci{ 33562306a36Sopenharmony_ci /* Assert Rx and Tx ratechange */ 33662306a36Sopenharmony_ci XSIR1_IOWRITE_BITS(pdata, SIR1_SPEED, RATECHANGE, 1); 33762306a36Sopenharmony_ci} 33862306a36Sopenharmony_ci 33962306a36Sopenharmony_cistatic void xgbe_phy_complete_ratechange(struct xgbe_prv_data *pdata) 34062306a36Sopenharmony_ci{ 34162306a36Sopenharmony_ci unsigned int wait; 34262306a36Sopenharmony_ci u16 status; 34362306a36Sopenharmony_ci 34462306a36Sopenharmony_ci /* Release Rx and Tx ratechange */ 34562306a36Sopenharmony_ci XSIR1_IOWRITE_BITS(pdata, SIR1_SPEED, RATECHANGE, 0); 34662306a36Sopenharmony_ci 34762306a36Sopenharmony_ci /* Wait for Rx and Tx ready */ 34862306a36Sopenharmony_ci wait = XGBE_RATECHANGE_COUNT; 34962306a36Sopenharmony_ci while (wait--) { 35062306a36Sopenharmony_ci usleep_range(50, 75); 35162306a36Sopenharmony_ci 35262306a36Sopenharmony_ci status = XSIR0_IOREAD(pdata, SIR0_STATUS); 35362306a36Sopenharmony_ci if (XSIR_GET_BITS(status, SIR0_STATUS, RX_READY) && 35462306a36Sopenharmony_ci XSIR_GET_BITS(status, SIR0_STATUS, TX_READY)) 35562306a36Sopenharmony_ci goto rx_reset; 35662306a36Sopenharmony_ci } 35762306a36Sopenharmony_ci 35862306a36Sopenharmony_ci netif_dbg(pdata, link, pdata->netdev, "SerDes rx/tx not ready (%#hx)\n", 35962306a36Sopenharmony_ci status); 36062306a36Sopenharmony_ci 36162306a36Sopenharmony_cirx_reset: 36262306a36Sopenharmony_ci /* Perform Rx reset for the DFE changes */ 36362306a36Sopenharmony_ci XRXTX_IOWRITE_BITS(pdata, RXTX_REG6, RESETB_RXD, 0); 36462306a36Sopenharmony_ci XRXTX_IOWRITE_BITS(pdata, RXTX_REG6, RESETB_RXD, 1); 36562306a36Sopenharmony_ci} 36662306a36Sopenharmony_ci 36762306a36Sopenharmony_cistatic void xgbe_phy_kr_mode(struct xgbe_prv_data *pdata) 36862306a36Sopenharmony_ci{ 36962306a36Sopenharmony_ci struct xgbe_phy_data *phy_data = pdata->phy_data; 37062306a36Sopenharmony_ci unsigned int reg; 37162306a36Sopenharmony_ci 37262306a36Sopenharmony_ci /* Set PCS to KR/10G speed */ 37362306a36Sopenharmony_ci reg = XMDIO_READ(pdata, MDIO_MMD_PCS, MDIO_CTRL2); 37462306a36Sopenharmony_ci reg &= ~MDIO_PCS_CTRL2_TYPE; 37562306a36Sopenharmony_ci reg |= MDIO_PCS_CTRL2_10GBR; 37662306a36Sopenharmony_ci XMDIO_WRITE(pdata, MDIO_MMD_PCS, MDIO_CTRL2, reg); 37762306a36Sopenharmony_ci 37862306a36Sopenharmony_ci reg = XMDIO_READ(pdata, MDIO_MMD_PCS, MDIO_CTRL1); 37962306a36Sopenharmony_ci reg &= ~MDIO_CTRL1_SPEEDSEL; 38062306a36Sopenharmony_ci reg |= MDIO_CTRL1_SPEED10G; 38162306a36Sopenharmony_ci XMDIO_WRITE(pdata, MDIO_MMD_PCS, MDIO_CTRL1, reg); 38262306a36Sopenharmony_ci 38362306a36Sopenharmony_ci xgbe_phy_pcs_power_cycle(pdata); 38462306a36Sopenharmony_ci 38562306a36Sopenharmony_ci /* Set SerDes to 10G speed */ 38662306a36Sopenharmony_ci xgbe_phy_start_ratechange(pdata); 38762306a36Sopenharmony_ci 38862306a36Sopenharmony_ci XSIR1_IOWRITE_BITS(pdata, SIR1_SPEED, DATARATE, XGBE_SPEED_10000_RATE); 38962306a36Sopenharmony_ci XSIR1_IOWRITE_BITS(pdata, SIR1_SPEED, WORDMODE, XGBE_SPEED_10000_WORD); 39062306a36Sopenharmony_ci XSIR1_IOWRITE_BITS(pdata, SIR1_SPEED, PLLSEL, XGBE_SPEED_10000_PLL); 39162306a36Sopenharmony_ci 39262306a36Sopenharmony_ci XSIR1_IOWRITE_BITS(pdata, SIR1_SPEED, CDR_RATE, 39362306a36Sopenharmony_ci phy_data->cdr_rate[XGBE_SPEED_10000]); 39462306a36Sopenharmony_ci XSIR1_IOWRITE_BITS(pdata, SIR1_SPEED, TXAMP, 39562306a36Sopenharmony_ci phy_data->tx_amp[XGBE_SPEED_10000]); 39662306a36Sopenharmony_ci XRXTX_IOWRITE_BITS(pdata, RXTX_REG20, BLWC_ENA, 39762306a36Sopenharmony_ci phy_data->blwc[XGBE_SPEED_10000]); 39862306a36Sopenharmony_ci XRXTX_IOWRITE_BITS(pdata, RXTX_REG114, PQ_REG, 39962306a36Sopenharmony_ci phy_data->pq_skew[XGBE_SPEED_10000]); 40062306a36Sopenharmony_ci XRXTX_IOWRITE_BITS(pdata, RXTX_REG129, RXDFE_CONFIG, 40162306a36Sopenharmony_ci phy_data->dfe_tap_cfg[XGBE_SPEED_10000]); 40262306a36Sopenharmony_ci XRXTX_IOWRITE(pdata, RXTX_REG22, 40362306a36Sopenharmony_ci phy_data->dfe_tap_ena[XGBE_SPEED_10000]); 40462306a36Sopenharmony_ci 40562306a36Sopenharmony_ci xgbe_phy_complete_ratechange(pdata); 40662306a36Sopenharmony_ci 40762306a36Sopenharmony_ci netif_dbg(pdata, link, pdata->netdev, "10GbE KR mode set\n"); 40862306a36Sopenharmony_ci} 40962306a36Sopenharmony_ci 41062306a36Sopenharmony_cistatic void xgbe_phy_kx_2500_mode(struct xgbe_prv_data *pdata) 41162306a36Sopenharmony_ci{ 41262306a36Sopenharmony_ci struct xgbe_phy_data *phy_data = pdata->phy_data; 41362306a36Sopenharmony_ci unsigned int reg; 41462306a36Sopenharmony_ci 41562306a36Sopenharmony_ci /* Set PCS to KX/1G speed */ 41662306a36Sopenharmony_ci reg = XMDIO_READ(pdata, MDIO_MMD_PCS, MDIO_CTRL2); 41762306a36Sopenharmony_ci reg &= ~MDIO_PCS_CTRL2_TYPE; 41862306a36Sopenharmony_ci reg |= MDIO_PCS_CTRL2_10GBX; 41962306a36Sopenharmony_ci XMDIO_WRITE(pdata, MDIO_MMD_PCS, MDIO_CTRL2, reg); 42062306a36Sopenharmony_ci 42162306a36Sopenharmony_ci reg = XMDIO_READ(pdata, MDIO_MMD_PCS, MDIO_CTRL1); 42262306a36Sopenharmony_ci reg &= ~MDIO_CTRL1_SPEEDSEL; 42362306a36Sopenharmony_ci reg |= MDIO_CTRL1_SPEED1G; 42462306a36Sopenharmony_ci XMDIO_WRITE(pdata, MDIO_MMD_PCS, MDIO_CTRL1, reg); 42562306a36Sopenharmony_ci 42662306a36Sopenharmony_ci xgbe_phy_pcs_power_cycle(pdata); 42762306a36Sopenharmony_ci 42862306a36Sopenharmony_ci /* Set SerDes to 2.5G speed */ 42962306a36Sopenharmony_ci xgbe_phy_start_ratechange(pdata); 43062306a36Sopenharmony_ci 43162306a36Sopenharmony_ci XSIR1_IOWRITE_BITS(pdata, SIR1_SPEED, DATARATE, XGBE_SPEED_2500_RATE); 43262306a36Sopenharmony_ci XSIR1_IOWRITE_BITS(pdata, SIR1_SPEED, WORDMODE, XGBE_SPEED_2500_WORD); 43362306a36Sopenharmony_ci XSIR1_IOWRITE_BITS(pdata, SIR1_SPEED, PLLSEL, XGBE_SPEED_2500_PLL); 43462306a36Sopenharmony_ci 43562306a36Sopenharmony_ci XSIR1_IOWRITE_BITS(pdata, SIR1_SPEED, CDR_RATE, 43662306a36Sopenharmony_ci phy_data->cdr_rate[XGBE_SPEED_2500]); 43762306a36Sopenharmony_ci XSIR1_IOWRITE_BITS(pdata, SIR1_SPEED, TXAMP, 43862306a36Sopenharmony_ci phy_data->tx_amp[XGBE_SPEED_2500]); 43962306a36Sopenharmony_ci XRXTX_IOWRITE_BITS(pdata, RXTX_REG20, BLWC_ENA, 44062306a36Sopenharmony_ci phy_data->blwc[XGBE_SPEED_2500]); 44162306a36Sopenharmony_ci XRXTX_IOWRITE_BITS(pdata, RXTX_REG114, PQ_REG, 44262306a36Sopenharmony_ci phy_data->pq_skew[XGBE_SPEED_2500]); 44362306a36Sopenharmony_ci XRXTX_IOWRITE_BITS(pdata, RXTX_REG129, RXDFE_CONFIG, 44462306a36Sopenharmony_ci phy_data->dfe_tap_cfg[XGBE_SPEED_2500]); 44562306a36Sopenharmony_ci XRXTX_IOWRITE(pdata, RXTX_REG22, 44662306a36Sopenharmony_ci phy_data->dfe_tap_ena[XGBE_SPEED_2500]); 44762306a36Sopenharmony_ci 44862306a36Sopenharmony_ci xgbe_phy_complete_ratechange(pdata); 44962306a36Sopenharmony_ci 45062306a36Sopenharmony_ci netif_dbg(pdata, link, pdata->netdev, "2.5GbE KX mode set\n"); 45162306a36Sopenharmony_ci} 45262306a36Sopenharmony_ci 45362306a36Sopenharmony_cistatic void xgbe_phy_kx_1000_mode(struct xgbe_prv_data *pdata) 45462306a36Sopenharmony_ci{ 45562306a36Sopenharmony_ci struct xgbe_phy_data *phy_data = pdata->phy_data; 45662306a36Sopenharmony_ci unsigned int reg; 45762306a36Sopenharmony_ci 45862306a36Sopenharmony_ci /* Set PCS to KX/1G speed */ 45962306a36Sopenharmony_ci reg = XMDIO_READ(pdata, MDIO_MMD_PCS, MDIO_CTRL2); 46062306a36Sopenharmony_ci reg &= ~MDIO_PCS_CTRL2_TYPE; 46162306a36Sopenharmony_ci reg |= MDIO_PCS_CTRL2_10GBX; 46262306a36Sopenharmony_ci XMDIO_WRITE(pdata, MDIO_MMD_PCS, MDIO_CTRL2, reg); 46362306a36Sopenharmony_ci 46462306a36Sopenharmony_ci reg = XMDIO_READ(pdata, MDIO_MMD_PCS, MDIO_CTRL1); 46562306a36Sopenharmony_ci reg &= ~MDIO_CTRL1_SPEEDSEL; 46662306a36Sopenharmony_ci reg |= MDIO_CTRL1_SPEED1G; 46762306a36Sopenharmony_ci XMDIO_WRITE(pdata, MDIO_MMD_PCS, MDIO_CTRL1, reg); 46862306a36Sopenharmony_ci 46962306a36Sopenharmony_ci xgbe_phy_pcs_power_cycle(pdata); 47062306a36Sopenharmony_ci 47162306a36Sopenharmony_ci /* Set SerDes to 1G speed */ 47262306a36Sopenharmony_ci xgbe_phy_start_ratechange(pdata); 47362306a36Sopenharmony_ci 47462306a36Sopenharmony_ci XSIR1_IOWRITE_BITS(pdata, SIR1_SPEED, DATARATE, XGBE_SPEED_1000_RATE); 47562306a36Sopenharmony_ci XSIR1_IOWRITE_BITS(pdata, SIR1_SPEED, WORDMODE, XGBE_SPEED_1000_WORD); 47662306a36Sopenharmony_ci XSIR1_IOWRITE_BITS(pdata, SIR1_SPEED, PLLSEL, XGBE_SPEED_1000_PLL); 47762306a36Sopenharmony_ci 47862306a36Sopenharmony_ci XSIR1_IOWRITE_BITS(pdata, SIR1_SPEED, CDR_RATE, 47962306a36Sopenharmony_ci phy_data->cdr_rate[XGBE_SPEED_1000]); 48062306a36Sopenharmony_ci XSIR1_IOWRITE_BITS(pdata, SIR1_SPEED, TXAMP, 48162306a36Sopenharmony_ci phy_data->tx_amp[XGBE_SPEED_1000]); 48262306a36Sopenharmony_ci XRXTX_IOWRITE_BITS(pdata, RXTX_REG20, BLWC_ENA, 48362306a36Sopenharmony_ci phy_data->blwc[XGBE_SPEED_1000]); 48462306a36Sopenharmony_ci XRXTX_IOWRITE_BITS(pdata, RXTX_REG114, PQ_REG, 48562306a36Sopenharmony_ci phy_data->pq_skew[XGBE_SPEED_1000]); 48662306a36Sopenharmony_ci XRXTX_IOWRITE_BITS(pdata, RXTX_REG129, RXDFE_CONFIG, 48762306a36Sopenharmony_ci phy_data->dfe_tap_cfg[XGBE_SPEED_1000]); 48862306a36Sopenharmony_ci XRXTX_IOWRITE(pdata, RXTX_REG22, 48962306a36Sopenharmony_ci phy_data->dfe_tap_ena[XGBE_SPEED_1000]); 49062306a36Sopenharmony_ci 49162306a36Sopenharmony_ci xgbe_phy_complete_ratechange(pdata); 49262306a36Sopenharmony_ci 49362306a36Sopenharmony_ci netif_dbg(pdata, link, pdata->netdev, "1GbE KX mode set\n"); 49462306a36Sopenharmony_ci} 49562306a36Sopenharmony_ci 49662306a36Sopenharmony_cistatic enum xgbe_mode xgbe_phy_cur_mode(struct xgbe_prv_data *pdata) 49762306a36Sopenharmony_ci{ 49862306a36Sopenharmony_ci struct xgbe_phy_data *phy_data = pdata->phy_data; 49962306a36Sopenharmony_ci enum xgbe_mode mode; 50062306a36Sopenharmony_ci unsigned int reg; 50162306a36Sopenharmony_ci 50262306a36Sopenharmony_ci reg = XMDIO_READ(pdata, MDIO_MMD_PCS, MDIO_CTRL2); 50362306a36Sopenharmony_ci reg &= MDIO_PCS_CTRL2_TYPE; 50462306a36Sopenharmony_ci 50562306a36Sopenharmony_ci if (reg == MDIO_PCS_CTRL2_10GBR) { 50662306a36Sopenharmony_ci mode = XGBE_MODE_KR; 50762306a36Sopenharmony_ci } else { 50862306a36Sopenharmony_ci if (phy_data->speed_set == XGBE_SPEEDSET_2500_10000) 50962306a36Sopenharmony_ci mode = XGBE_MODE_KX_2500; 51062306a36Sopenharmony_ci else 51162306a36Sopenharmony_ci mode = XGBE_MODE_KX_1000; 51262306a36Sopenharmony_ci } 51362306a36Sopenharmony_ci 51462306a36Sopenharmony_ci return mode; 51562306a36Sopenharmony_ci} 51662306a36Sopenharmony_ci 51762306a36Sopenharmony_cistatic enum xgbe_mode xgbe_phy_switch_mode(struct xgbe_prv_data *pdata) 51862306a36Sopenharmony_ci{ 51962306a36Sopenharmony_ci struct xgbe_phy_data *phy_data = pdata->phy_data; 52062306a36Sopenharmony_ci enum xgbe_mode mode; 52162306a36Sopenharmony_ci 52262306a36Sopenharmony_ci /* If we are in KR switch to KX, and vice-versa */ 52362306a36Sopenharmony_ci if (xgbe_phy_cur_mode(pdata) == XGBE_MODE_KR) { 52462306a36Sopenharmony_ci if (phy_data->speed_set == XGBE_SPEEDSET_2500_10000) 52562306a36Sopenharmony_ci mode = XGBE_MODE_KX_2500; 52662306a36Sopenharmony_ci else 52762306a36Sopenharmony_ci mode = XGBE_MODE_KX_1000; 52862306a36Sopenharmony_ci } else { 52962306a36Sopenharmony_ci mode = XGBE_MODE_KR; 53062306a36Sopenharmony_ci } 53162306a36Sopenharmony_ci 53262306a36Sopenharmony_ci return mode; 53362306a36Sopenharmony_ci} 53462306a36Sopenharmony_ci 53562306a36Sopenharmony_cistatic enum xgbe_mode xgbe_phy_get_mode(struct xgbe_prv_data *pdata, 53662306a36Sopenharmony_ci int speed) 53762306a36Sopenharmony_ci{ 53862306a36Sopenharmony_ci struct xgbe_phy_data *phy_data = pdata->phy_data; 53962306a36Sopenharmony_ci 54062306a36Sopenharmony_ci switch (speed) { 54162306a36Sopenharmony_ci case SPEED_1000: 54262306a36Sopenharmony_ci return (phy_data->speed_set == XGBE_SPEEDSET_1000_10000) 54362306a36Sopenharmony_ci ? XGBE_MODE_KX_1000 : XGBE_MODE_UNKNOWN; 54462306a36Sopenharmony_ci case SPEED_2500: 54562306a36Sopenharmony_ci return (phy_data->speed_set == XGBE_SPEEDSET_2500_10000) 54662306a36Sopenharmony_ci ? XGBE_MODE_KX_2500 : XGBE_MODE_UNKNOWN; 54762306a36Sopenharmony_ci case SPEED_10000: 54862306a36Sopenharmony_ci return XGBE_MODE_KR; 54962306a36Sopenharmony_ci default: 55062306a36Sopenharmony_ci return XGBE_MODE_UNKNOWN; 55162306a36Sopenharmony_ci } 55262306a36Sopenharmony_ci} 55362306a36Sopenharmony_ci 55462306a36Sopenharmony_cistatic void xgbe_phy_set_mode(struct xgbe_prv_data *pdata, enum xgbe_mode mode) 55562306a36Sopenharmony_ci{ 55662306a36Sopenharmony_ci switch (mode) { 55762306a36Sopenharmony_ci case XGBE_MODE_KX_1000: 55862306a36Sopenharmony_ci xgbe_phy_kx_1000_mode(pdata); 55962306a36Sopenharmony_ci break; 56062306a36Sopenharmony_ci case XGBE_MODE_KX_2500: 56162306a36Sopenharmony_ci xgbe_phy_kx_2500_mode(pdata); 56262306a36Sopenharmony_ci break; 56362306a36Sopenharmony_ci case XGBE_MODE_KR: 56462306a36Sopenharmony_ci xgbe_phy_kr_mode(pdata); 56562306a36Sopenharmony_ci break; 56662306a36Sopenharmony_ci default: 56762306a36Sopenharmony_ci break; 56862306a36Sopenharmony_ci } 56962306a36Sopenharmony_ci} 57062306a36Sopenharmony_ci 57162306a36Sopenharmony_cistatic bool xgbe_phy_check_mode(struct xgbe_prv_data *pdata, 57262306a36Sopenharmony_ci enum xgbe_mode mode, bool advert) 57362306a36Sopenharmony_ci{ 57462306a36Sopenharmony_ci if (pdata->phy.autoneg == AUTONEG_ENABLE) { 57562306a36Sopenharmony_ci return advert; 57662306a36Sopenharmony_ci } else { 57762306a36Sopenharmony_ci enum xgbe_mode cur_mode; 57862306a36Sopenharmony_ci 57962306a36Sopenharmony_ci cur_mode = xgbe_phy_get_mode(pdata, pdata->phy.speed); 58062306a36Sopenharmony_ci if (cur_mode == mode) 58162306a36Sopenharmony_ci return true; 58262306a36Sopenharmony_ci } 58362306a36Sopenharmony_ci 58462306a36Sopenharmony_ci return false; 58562306a36Sopenharmony_ci} 58662306a36Sopenharmony_ci 58762306a36Sopenharmony_cistatic bool xgbe_phy_use_mode(struct xgbe_prv_data *pdata, enum xgbe_mode mode) 58862306a36Sopenharmony_ci{ 58962306a36Sopenharmony_ci struct ethtool_link_ksettings *lks = &pdata->phy.lks; 59062306a36Sopenharmony_ci 59162306a36Sopenharmony_ci switch (mode) { 59262306a36Sopenharmony_ci case XGBE_MODE_KX_1000: 59362306a36Sopenharmony_ci return xgbe_phy_check_mode(pdata, mode, 59462306a36Sopenharmony_ci XGBE_ADV(lks, 1000baseKX_Full)); 59562306a36Sopenharmony_ci case XGBE_MODE_KX_2500: 59662306a36Sopenharmony_ci return xgbe_phy_check_mode(pdata, mode, 59762306a36Sopenharmony_ci XGBE_ADV(lks, 2500baseX_Full)); 59862306a36Sopenharmony_ci case XGBE_MODE_KR: 59962306a36Sopenharmony_ci return xgbe_phy_check_mode(pdata, mode, 60062306a36Sopenharmony_ci XGBE_ADV(lks, 10000baseKR_Full)); 60162306a36Sopenharmony_ci default: 60262306a36Sopenharmony_ci return false; 60362306a36Sopenharmony_ci } 60462306a36Sopenharmony_ci} 60562306a36Sopenharmony_ci 60662306a36Sopenharmony_cistatic bool xgbe_phy_valid_speed(struct xgbe_prv_data *pdata, int speed) 60762306a36Sopenharmony_ci{ 60862306a36Sopenharmony_ci struct xgbe_phy_data *phy_data = pdata->phy_data; 60962306a36Sopenharmony_ci 61062306a36Sopenharmony_ci switch (speed) { 61162306a36Sopenharmony_ci case SPEED_1000: 61262306a36Sopenharmony_ci if (phy_data->speed_set != XGBE_SPEEDSET_1000_10000) 61362306a36Sopenharmony_ci return false; 61462306a36Sopenharmony_ci return true; 61562306a36Sopenharmony_ci case SPEED_2500: 61662306a36Sopenharmony_ci if (phy_data->speed_set != XGBE_SPEEDSET_2500_10000) 61762306a36Sopenharmony_ci return false; 61862306a36Sopenharmony_ci return true; 61962306a36Sopenharmony_ci case SPEED_10000: 62062306a36Sopenharmony_ci return true; 62162306a36Sopenharmony_ci default: 62262306a36Sopenharmony_ci return false; 62362306a36Sopenharmony_ci } 62462306a36Sopenharmony_ci} 62562306a36Sopenharmony_ci 62662306a36Sopenharmony_cistatic int xgbe_phy_link_status(struct xgbe_prv_data *pdata, int *an_restart) 62762306a36Sopenharmony_ci{ 62862306a36Sopenharmony_ci unsigned int reg; 62962306a36Sopenharmony_ci 63062306a36Sopenharmony_ci *an_restart = 0; 63162306a36Sopenharmony_ci 63262306a36Sopenharmony_ci /* Link status is latched low, so read once to clear 63362306a36Sopenharmony_ci * and then read again to get current state 63462306a36Sopenharmony_ci */ 63562306a36Sopenharmony_ci reg = XMDIO_READ(pdata, MDIO_MMD_PCS, MDIO_STAT1); 63662306a36Sopenharmony_ci reg = XMDIO_READ(pdata, MDIO_MMD_PCS, MDIO_STAT1); 63762306a36Sopenharmony_ci 63862306a36Sopenharmony_ci return (reg & MDIO_STAT1_LSTATUS) ? 1 : 0; 63962306a36Sopenharmony_ci} 64062306a36Sopenharmony_ci 64162306a36Sopenharmony_cistatic void xgbe_phy_stop(struct xgbe_prv_data *pdata) 64262306a36Sopenharmony_ci{ 64362306a36Sopenharmony_ci /* Nothing uniquely required for stop */ 64462306a36Sopenharmony_ci} 64562306a36Sopenharmony_ci 64662306a36Sopenharmony_cistatic int xgbe_phy_start(struct xgbe_prv_data *pdata) 64762306a36Sopenharmony_ci{ 64862306a36Sopenharmony_ci /* Nothing uniquely required for start */ 64962306a36Sopenharmony_ci return 0; 65062306a36Sopenharmony_ci} 65162306a36Sopenharmony_ci 65262306a36Sopenharmony_cistatic int xgbe_phy_reset(struct xgbe_prv_data *pdata) 65362306a36Sopenharmony_ci{ 65462306a36Sopenharmony_ci unsigned int reg, count; 65562306a36Sopenharmony_ci 65662306a36Sopenharmony_ci /* Perform a software reset of the PCS */ 65762306a36Sopenharmony_ci reg = XMDIO_READ(pdata, MDIO_MMD_PCS, MDIO_CTRL1); 65862306a36Sopenharmony_ci reg |= MDIO_CTRL1_RESET; 65962306a36Sopenharmony_ci XMDIO_WRITE(pdata, MDIO_MMD_PCS, MDIO_CTRL1, reg); 66062306a36Sopenharmony_ci 66162306a36Sopenharmony_ci count = 50; 66262306a36Sopenharmony_ci do { 66362306a36Sopenharmony_ci msleep(20); 66462306a36Sopenharmony_ci reg = XMDIO_READ(pdata, MDIO_MMD_PCS, MDIO_CTRL1); 66562306a36Sopenharmony_ci } while ((reg & MDIO_CTRL1_RESET) && --count); 66662306a36Sopenharmony_ci 66762306a36Sopenharmony_ci if (reg & MDIO_CTRL1_RESET) 66862306a36Sopenharmony_ci return -ETIMEDOUT; 66962306a36Sopenharmony_ci 67062306a36Sopenharmony_ci return 0; 67162306a36Sopenharmony_ci} 67262306a36Sopenharmony_ci 67362306a36Sopenharmony_cistatic void xgbe_phy_exit(struct xgbe_prv_data *pdata) 67462306a36Sopenharmony_ci{ 67562306a36Sopenharmony_ci /* Nothing uniquely required for exit */ 67662306a36Sopenharmony_ci} 67762306a36Sopenharmony_ci 67862306a36Sopenharmony_cistatic int xgbe_phy_init(struct xgbe_prv_data *pdata) 67962306a36Sopenharmony_ci{ 68062306a36Sopenharmony_ci struct ethtool_link_ksettings *lks = &pdata->phy.lks; 68162306a36Sopenharmony_ci struct xgbe_phy_data *phy_data; 68262306a36Sopenharmony_ci int ret; 68362306a36Sopenharmony_ci 68462306a36Sopenharmony_ci phy_data = devm_kzalloc(pdata->dev, sizeof(*phy_data), GFP_KERNEL); 68562306a36Sopenharmony_ci if (!phy_data) 68662306a36Sopenharmony_ci return -ENOMEM; 68762306a36Sopenharmony_ci 68862306a36Sopenharmony_ci /* Retrieve the PHY speedset */ 68962306a36Sopenharmony_ci ret = device_property_read_u32(pdata->phy_dev, XGBE_SPEEDSET_PROPERTY, 69062306a36Sopenharmony_ci &phy_data->speed_set); 69162306a36Sopenharmony_ci if (ret) { 69262306a36Sopenharmony_ci dev_err(pdata->dev, "invalid %s property\n", 69362306a36Sopenharmony_ci XGBE_SPEEDSET_PROPERTY); 69462306a36Sopenharmony_ci return ret; 69562306a36Sopenharmony_ci } 69662306a36Sopenharmony_ci 69762306a36Sopenharmony_ci switch (phy_data->speed_set) { 69862306a36Sopenharmony_ci case XGBE_SPEEDSET_1000_10000: 69962306a36Sopenharmony_ci case XGBE_SPEEDSET_2500_10000: 70062306a36Sopenharmony_ci break; 70162306a36Sopenharmony_ci default: 70262306a36Sopenharmony_ci dev_err(pdata->dev, "invalid %s property\n", 70362306a36Sopenharmony_ci XGBE_SPEEDSET_PROPERTY); 70462306a36Sopenharmony_ci return -EINVAL; 70562306a36Sopenharmony_ci } 70662306a36Sopenharmony_ci 70762306a36Sopenharmony_ci /* Retrieve the PHY configuration properties */ 70862306a36Sopenharmony_ci if (device_property_present(pdata->phy_dev, XGBE_BLWC_PROPERTY)) { 70962306a36Sopenharmony_ci ret = device_property_read_u32_array(pdata->phy_dev, 71062306a36Sopenharmony_ci XGBE_BLWC_PROPERTY, 71162306a36Sopenharmony_ci phy_data->blwc, 71262306a36Sopenharmony_ci XGBE_SPEEDS); 71362306a36Sopenharmony_ci if (ret) { 71462306a36Sopenharmony_ci dev_err(pdata->dev, "invalid %s property\n", 71562306a36Sopenharmony_ci XGBE_BLWC_PROPERTY); 71662306a36Sopenharmony_ci return ret; 71762306a36Sopenharmony_ci } 71862306a36Sopenharmony_ci } else { 71962306a36Sopenharmony_ci memcpy(phy_data->blwc, xgbe_phy_blwc, 72062306a36Sopenharmony_ci sizeof(phy_data->blwc)); 72162306a36Sopenharmony_ci } 72262306a36Sopenharmony_ci 72362306a36Sopenharmony_ci if (device_property_present(pdata->phy_dev, XGBE_CDR_RATE_PROPERTY)) { 72462306a36Sopenharmony_ci ret = device_property_read_u32_array(pdata->phy_dev, 72562306a36Sopenharmony_ci XGBE_CDR_RATE_PROPERTY, 72662306a36Sopenharmony_ci phy_data->cdr_rate, 72762306a36Sopenharmony_ci XGBE_SPEEDS); 72862306a36Sopenharmony_ci if (ret) { 72962306a36Sopenharmony_ci dev_err(pdata->dev, "invalid %s property\n", 73062306a36Sopenharmony_ci XGBE_CDR_RATE_PROPERTY); 73162306a36Sopenharmony_ci return ret; 73262306a36Sopenharmony_ci } 73362306a36Sopenharmony_ci } else { 73462306a36Sopenharmony_ci memcpy(phy_data->cdr_rate, xgbe_phy_cdr_rate, 73562306a36Sopenharmony_ci sizeof(phy_data->cdr_rate)); 73662306a36Sopenharmony_ci } 73762306a36Sopenharmony_ci 73862306a36Sopenharmony_ci if (device_property_present(pdata->phy_dev, XGBE_PQ_SKEW_PROPERTY)) { 73962306a36Sopenharmony_ci ret = device_property_read_u32_array(pdata->phy_dev, 74062306a36Sopenharmony_ci XGBE_PQ_SKEW_PROPERTY, 74162306a36Sopenharmony_ci phy_data->pq_skew, 74262306a36Sopenharmony_ci XGBE_SPEEDS); 74362306a36Sopenharmony_ci if (ret) { 74462306a36Sopenharmony_ci dev_err(pdata->dev, "invalid %s property\n", 74562306a36Sopenharmony_ci XGBE_PQ_SKEW_PROPERTY); 74662306a36Sopenharmony_ci return ret; 74762306a36Sopenharmony_ci } 74862306a36Sopenharmony_ci } else { 74962306a36Sopenharmony_ci memcpy(phy_data->pq_skew, xgbe_phy_pq_skew, 75062306a36Sopenharmony_ci sizeof(phy_data->pq_skew)); 75162306a36Sopenharmony_ci } 75262306a36Sopenharmony_ci 75362306a36Sopenharmony_ci if (device_property_present(pdata->phy_dev, XGBE_TX_AMP_PROPERTY)) { 75462306a36Sopenharmony_ci ret = device_property_read_u32_array(pdata->phy_dev, 75562306a36Sopenharmony_ci XGBE_TX_AMP_PROPERTY, 75662306a36Sopenharmony_ci phy_data->tx_amp, 75762306a36Sopenharmony_ci XGBE_SPEEDS); 75862306a36Sopenharmony_ci if (ret) { 75962306a36Sopenharmony_ci dev_err(pdata->dev, "invalid %s property\n", 76062306a36Sopenharmony_ci XGBE_TX_AMP_PROPERTY); 76162306a36Sopenharmony_ci return ret; 76262306a36Sopenharmony_ci } 76362306a36Sopenharmony_ci } else { 76462306a36Sopenharmony_ci memcpy(phy_data->tx_amp, xgbe_phy_tx_amp, 76562306a36Sopenharmony_ci sizeof(phy_data->tx_amp)); 76662306a36Sopenharmony_ci } 76762306a36Sopenharmony_ci 76862306a36Sopenharmony_ci if (device_property_present(pdata->phy_dev, XGBE_DFE_CFG_PROPERTY)) { 76962306a36Sopenharmony_ci ret = device_property_read_u32_array(pdata->phy_dev, 77062306a36Sopenharmony_ci XGBE_DFE_CFG_PROPERTY, 77162306a36Sopenharmony_ci phy_data->dfe_tap_cfg, 77262306a36Sopenharmony_ci XGBE_SPEEDS); 77362306a36Sopenharmony_ci if (ret) { 77462306a36Sopenharmony_ci dev_err(pdata->dev, "invalid %s property\n", 77562306a36Sopenharmony_ci XGBE_DFE_CFG_PROPERTY); 77662306a36Sopenharmony_ci return ret; 77762306a36Sopenharmony_ci } 77862306a36Sopenharmony_ci } else { 77962306a36Sopenharmony_ci memcpy(phy_data->dfe_tap_cfg, xgbe_phy_dfe_tap_cfg, 78062306a36Sopenharmony_ci sizeof(phy_data->dfe_tap_cfg)); 78162306a36Sopenharmony_ci } 78262306a36Sopenharmony_ci 78362306a36Sopenharmony_ci if (device_property_present(pdata->phy_dev, XGBE_DFE_ENA_PROPERTY)) { 78462306a36Sopenharmony_ci ret = device_property_read_u32_array(pdata->phy_dev, 78562306a36Sopenharmony_ci XGBE_DFE_ENA_PROPERTY, 78662306a36Sopenharmony_ci phy_data->dfe_tap_ena, 78762306a36Sopenharmony_ci XGBE_SPEEDS); 78862306a36Sopenharmony_ci if (ret) { 78962306a36Sopenharmony_ci dev_err(pdata->dev, "invalid %s property\n", 79062306a36Sopenharmony_ci XGBE_DFE_ENA_PROPERTY); 79162306a36Sopenharmony_ci return ret; 79262306a36Sopenharmony_ci } 79362306a36Sopenharmony_ci } else { 79462306a36Sopenharmony_ci memcpy(phy_data->dfe_tap_ena, xgbe_phy_dfe_tap_ena, 79562306a36Sopenharmony_ci sizeof(phy_data->dfe_tap_ena)); 79662306a36Sopenharmony_ci } 79762306a36Sopenharmony_ci 79862306a36Sopenharmony_ci /* Initialize supported features */ 79962306a36Sopenharmony_ci XGBE_ZERO_SUP(lks); 80062306a36Sopenharmony_ci XGBE_SET_SUP(lks, Autoneg); 80162306a36Sopenharmony_ci XGBE_SET_SUP(lks, Pause); 80262306a36Sopenharmony_ci XGBE_SET_SUP(lks, Asym_Pause); 80362306a36Sopenharmony_ci XGBE_SET_SUP(lks, Backplane); 80462306a36Sopenharmony_ci XGBE_SET_SUP(lks, 10000baseKR_Full); 80562306a36Sopenharmony_ci switch (phy_data->speed_set) { 80662306a36Sopenharmony_ci case XGBE_SPEEDSET_1000_10000: 80762306a36Sopenharmony_ci XGBE_SET_SUP(lks, 1000baseKX_Full); 80862306a36Sopenharmony_ci break; 80962306a36Sopenharmony_ci case XGBE_SPEEDSET_2500_10000: 81062306a36Sopenharmony_ci XGBE_SET_SUP(lks, 2500baseX_Full); 81162306a36Sopenharmony_ci break; 81262306a36Sopenharmony_ci } 81362306a36Sopenharmony_ci 81462306a36Sopenharmony_ci if (pdata->fec_ability & MDIO_PMA_10GBR_FECABLE_ABLE) 81562306a36Sopenharmony_ci XGBE_SET_SUP(lks, 10000baseR_FEC); 81662306a36Sopenharmony_ci 81762306a36Sopenharmony_ci pdata->phy_data = phy_data; 81862306a36Sopenharmony_ci 81962306a36Sopenharmony_ci return 0; 82062306a36Sopenharmony_ci} 82162306a36Sopenharmony_ci 82262306a36Sopenharmony_civoid xgbe_init_function_ptrs_phy_v1(struct xgbe_phy_if *phy_if) 82362306a36Sopenharmony_ci{ 82462306a36Sopenharmony_ci struct xgbe_phy_impl_if *phy_impl = &phy_if->phy_impl; 82562306a36Sopenharmony_ci 82662306a36Sopenharmony_ci phy_impl->init = xgbe_phy_init; 82762306a36Sopenharmony_ci phy_impl->exit = xgbe_phy_exit; 82862306a36Sopenharmony_ci 82962306a36Sopenharmony_ci phy_impl->reset = xgbe_phy_reset; 83062306a36Sopenharmony_ci phy_impl->start = xgbe_phy_start; 83162306a36Sopenharmony_ci phy_impl->stop = xgbe_phy_stop; 83262306a36Sopenharmony_ci 83362306a36Sopenharmony_ci phy_impl->link_status = xgbe_phy_link_status; 83462306a36Sopenharmony_ci 83562306a36Sopenharmony_ci phy_impl->valid_speed = xgbe_phy_valid_speed; 83662306a36Sopenharmony_ci 83762306a36Sopenharmony_ci phy_impl->use_mode = xgbe_phy_use_mode; 83862306a36Sopenharmony_ci phy_impl->set_mode = xgbe_phy_set_mode; 83962306a36Sopenharmony_ci phy_impl->get_mode = xgbe_phy_get_mode; 84062306a36Sopenharmony_ci phy_impl->switch_mode = xgbe_phy_switch_mode; 84162306a36Sopenharmony_ci phy_impl->cur_mode = xgbe_phy_cur_mode; 84262306a36Sopenharmony_ci 84362306a36Sopenharmony_ci phy_impl->an_mode = xgbe_phy_an_mode; 84462306a36Sopenharmony_ci 84562306a36Sopenharmony_ci phy_impl->an_config = xgbe_phy_an_config; 84662306a36Sopenharmony_ci 84762306a36Sopenharmony_ci phy_impl->an_advertising = xgbe_phy_an_advertising; 84862306a36Sopenharmony_ci 84962306a36Sopenharmony_ci phy_impl->an_outcome = xgbe_phy_an_outcome; 85062306a36Sopenharmony_ci 85162306a36Sopenharmony_ci phy_impl->kr_training_pre = xgbe_phy_kr_training_pre; 85262306a36Sopenharmony_ci phy_impl->kr_training_post = xgbe_phy_kr_training_post; 85362306a36Sopenharmony_ci} 854