Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 1 | /* |
| 2 | * AMD 10Gb Ethernet PHY driver |
| 3 | * |
| 4 | * This file is available to you under your choice of the following two |
| 5 | * licenses: |
| 6 | * |
| 7 | * License 1: GPLv2 |
| 8 | * |
| 9 | * Copyright (c) 2014 Advanced Micro Devices, Inc. |
| 10 | * |
| 11 | * This file is free software; you may copy, redistribute and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation, either version 2 of the License, or (at |
| 14 | * your option) any later version. |
| 15 | * |
| 16 | * This file is distributed in the hope that it will be useful, but |
| 17 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 19 | * General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 23 | * |
| 24 | * |
| 25 | * License 2: Modified BSD |
| 26 | * |
| 27 | * Copyright (c) 2014 Advanced Micro Devices, Inc. |
| 28 | * All rights reserved. |
| 29 | * |
| 30 | * Redistribution and use in source and binary forms, with or without |
| 31 | * modification, are permitted provided that the following conditions are met: |
| 32 | * * Redistributions of source code must retain the above copyright |
| 33 | * notice, this list of conditions and the following disclaimer. |
| 34 | * * Redistributions in binary form must reproduce the above copyright |
| 35 | * notice, this list of conditions and the following disclaimer in the |
| 36 | * documentation and/or other materials provided with the distribution. |
| 37 | * * Neither the name of Advanced Micro Devices, Inc. nor the |
| 38 | * names of its contributors may be used to endorse or promote products |
| 39 | * derived from this software without specific prior written permission. |
| 40 | * |
| 41 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 42 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY |
| 45 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 46 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 47 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 48 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 49 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 50 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 51 | */ |
| 52 | |
| 53 | #include <linux/kernel.h> |
| 54 | #include <linux/device.h> |
| 55 | #include <linux/platform_device.h> |
| 56 | #include <linux/string.h> |
| 57 | #include <linux/errno.h> |
| 58 | #include <linux/unistd.h> |
| 59 | #include <linux/slab.h> |
| 60 | #include <linux/interrupt.h> |
| 61 | #include <linux/init.h> |
| 62 | #include <linux/delay.h> |
Lendacky, Thomas | c3152d4 | 2015-01-16 12:47:00 -0600 | [diff] [blame] | 63 | #include <linux/workqueue.h> |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 64 | #include <linux/netdevice.h> |
| 65 | #include <linux/etherdevice.h> |
| 66 | #include <linux/skbuff.h> |
| 67 | #include <linux/mm.h> |
| 68 | #include <linux/module.h> |
| 69 | #include <linux/mii.h> |
| 70 | #include <linux/ethtool.h> |
| 71 | #include <linux/phy.h> |
| 72 | #include <linux/mdio.h> |
| 73 | #include <linux/io.h> |
| 74 | #include <linux/of.h> |
| 75 | #include <linux/of_platform.h> |
| 76 | #include <linux/of_device.h> |
| 77 | #include <linux/uaccess.h> |
Lendacky, Thomas | cb69cb0 | 2015-01-16 12:46:29 -0600 | [diff] [blame] | 78 | #include <linux/bitops.h> |
Lendacky, Thomas | 82a1903 | 2015-01-16 12:47:16 -0600 | [diff] [blame] | 79 | #include <linux/property.h> |
| 80 | #include <linux/acpi.h> |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 81 | |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 82 | MODULE_AUTHOR("Tom Lendacky <thomas.lendacky@amd.com>"); |
| 83 | MODULE_LICENSE("Dual BSD/GPL"); |
| 84 | MODULE_VERSION("1.0.0-a"); |
| 85 | MODULE_DESCRIPTION("AMD 10GbE (amd-xgbe) PHY driver"); |
| 86 | |
| 87 | #define XGBE_PHY_ID 0x000162d0 |
| 88 | #define XGBE_PHY_MASK 0xfffffff0 |
| 89 | |
Lendacky, Thomas | f047604 | 2014-07-29 08:57:25 -0500 | [diff] [blame] | 90 | #define XGBE_PHY_SPEEDSET_PROPERTY "amd,speed-set" |
Lendacky, Thomas | 8fdb1a09 | 2015-01-16 12:47:21 -0600 | [diff] [blame] | 91 | #define XGBE_PHY_BLWC_PROPERTY "amd,serdes-blwc" |
| 92 | #define XGBE_PHY_CDR_RATE_PROPERTY "amd,serdes-cdr-rate" |
| 93 | #define XGBE_PHY_PQ_SKEW_PROPERTY "amd,serdes-pq-skew" |
| 94 | #define XGBE_PHY_TX_AMP_PROPERTY "amd,serdes-tx-amp" |
Tom Lendacky | 74ad752 | 2015-02-24 10:47:49 -0600 | [diff] [blame] | 95 | #define XGBE_PHY_DFE_CFG_PROPERTY "amd,serdes-dfe-tap-config" |
| 96 | #define XGBE_PHY_DFE_ENA_PROPERTY "amd,serdes-dfe-tap-enable" |
Lendacky, Thomas | 8fdb1a09 | 2015-01-16 12:47:21 -0600 | [diff] [blame] | 97 | |
| 98 | #define XGBE_PHY_SPEEDS 3 |
| 99 | #define XGBE_PHY_SPEED_1000 0 |
| 100 | #define XGBE_PHY_SPEED_2500 1 |
| 101 | #define XGBE_PHY_SPEED_10000 2 |
Lendacky, Thomas | f047604 | 2014-07-29 08:57:25 -0500 | [diff] [blame] | 102 | |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 103 | #define XGBE_AN_INT_CMPLT 0x01 |
| 104 | #define XGBE_AN_INC_LINK 0x02 |
| 105 | #define XGBE_AN_PG_RCV 0x04 |
Lendacky, Thomas | c3152d4 | 2015-01-16 12:47:00 -0600 | [diff] [blame] | 106 | #define XGBE_AN_INT_MASK 0x07 |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 107 | |
| 108 | #define XNP_MCF_NULL_MESSAGE 0x001 |
Lendacky, Thomas | cb69cb0 | 2015-01-16 12:46:29 -0600 | [diff] [blame] | 109 | #define XNP_ACK_PROCESSED BIT(12) |
| 110 | #define XNP_MP_FORMATTED BIT(13) |
| 111 | #define XNP_NP_EXCHANGE BIT(15) |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 112 | |
Lendacky, Thomas | 1fa1f2e | 2014-08-01 11:56:36 -0500 | [diff] [blame] | 113 | #define XGBE_PHY_RATECHANGE_COUNT 500 |
Lendacky, Thomas | 169a630 | 2014-07-29 08:57:37 -0500 | [diff] [blame] | 114 | |
Lendacky, Thomas | cf26252 | 2015-01-16 12:47:05 -0600 | [diff] [blame] | 115 | #define XGBE_PHY_KR_TRAINING_START 0x01 |
| 116 | #define XGBE_PHY_KR_TRAINING_ENABLE 0x02 |
| 117 | |
| 118 | #define XGBE_PHY_FEC_ENABLE 0x01 |
| 119 | #define XGBE_PHY_FEC_FORWARD 0x02 |
| 120 | #define XGBE_PHY_FEC_MASK 0x03 |
| 121 | |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 122 | #ifndef MDIO_PMA_10GBR_PMD_CTRL |
| 123 | #define MDIO_PMA_10GBR_PMD_CTRL 0x0096 |
| 124 | #endif |
Lendacky, Thomas | e6f0562 | 2014-09-03 12:14:22 -0500 | [diff] [blame] | 125 | |
Lendacky, Thomas | cf26252 | 2015-01-16 12:47:05 -0600 | [diff] [blame] | 126 | #ifndef MDIO_PMA_10GBR_FEC_ABILITY |
| 127 | #define MDIO_PMA_10GBR_FEC_ABILITY 0x00aa |
| 128 | #endif |
| 129 | |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 130 | #ifndef MDIO_PMA_10GBR_FEC_CTRL |
| 131 | #define MDIO_PMA_10GBR_FEC_CTRL 0x00ab |
| 132 | #endif |
Lendacky, Thomas | e6f0562 | 2014-09-03 12:14:22 -0500 | [diff] [blame] | 133 | |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 134 | #ifndef MDIO_AN_XNP |
| 135 | #define MDIO_AN_XNP 0x0016 |
| 136 | #endif |
| 137 | |
Lendacky, Thomas | 0d40b61 | 2015-01-16 12:47:10 -0600 | [diff] [blame] | 138 | #ifndef MDIO_AN_LPX |
| 139 | #define MDIO_AN_LPX 0x0019 |
| 140 | #endif |
| 141 | |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 142 | #ifndef MDIO_AN_INTMASK |
| 143 | #define MDIO_AN_INTMASK 0x8001 |
| 144 | #endif |
Lendacky, Thomas | e6f0562 | 2014-09-03 12:14:22 -0500 | [diff] [blame] | 145 | |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 146 | #ifndef MDIO_AN_INT |
| 147 | #define MDIO_AN_INT 0x8002 |
| 148 | #endif |
| 149 | |
| 150 | #ifndef MDIO_CTRL1_SPEED1G |
| 151 | #define MDIO_CTRL1_SPEED1G (MDIO_CTRL1_SPEED10G & ~BMCR_SPEED100) |
| 152 | #endif |
| 153 | |
| 154 | /* SerDes integration register offsets */ |
Lendacky, Thomas | 5c10e5c | 2014-07-29 08:57:43 -0500 | [diff] [blame] | 155 | #define SIR0_KR_RT_1 0x002c |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 156 | #define SIR0_STATUS 0x0040 |
| 157 | #define SIR1_SPEED 0x0000 |
| 158 | |
| 159 | /* SerDes integration register entry bit positions and sizes */ |
Lendacky, Thomas | 5c10e5c | 2014-07-29 08:57:43 -0500 | [diff] [blame] | 160 | #define SIR0_KR_RT_1_RESET_INDEX 11 |
| 161 | #define SIR0_KR_RT_1_RESET_WIDTH 1 |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 162 | #define SIR0_STATUS_RX_READY_INDEX 0 |
| 163 | #define SIR0_STATUS_RX_READY_WIDTH 1 |
| 164 | #define SIR0_STATUS_TX_READY_INDEX 8 |
| 165 | #define SIR0_STATUS_TX_READY_WIDTH 1 |
Lendacky, Thomas | 8fdb1a09 | 2015-01-16 12:47:21 -0600 | [diff] [blame] | 166 | #define SIR1_SPEED_CDR_RATE_INDEX 12 |
| 167 | #define SIR1_SPEED_CDR_RATE_WIDTH 4 |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 168 | #define SIR1_SPEED_DATARATE_INDEX 4 |
| 169 | #define SIR1_SPEED_DATARATE_WIDTH 2 |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 170 | #define SIR1_SPEED_PLLSEL_INDEX 3 |
| 171 | #define SIR1_SPEED_PLLSEL_WIDTH 1 |
| 172 | #define SIR1_SPEED_RATECHANGE_INDEX 6 |
| 173 | #define SIR1_SPEED_RATECHANGE_WIDTH 1 |
| 174 | #define SIR1_SPEED_TXAMP_INDEX 8 |
| 175 | #define SIR1_SPEED_TXAMP_WIDTH 4 |
| 176 | #define SIR1_SPEED_WORDMODE_INDEX 0 |
| 177 | #define SIR1_SPEED_WORDMODE_WIDTH 3 |
| 178 | |
Lendacky, Thomas | 8fdb1a09 | 2015-01-16 12:47:21 -0600 | [diff] [blame] | 179 | #define SPEED_10000_BLWC 0 |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 180 | #define SPEED_10000_CDR 0x7 |
| 181 | #define SPEED_10000_PLL 0x1 |
Tom Lendacky | 74ad752 | 2015-02-24 10:47:49 -0600 | [diff] [blame] | 182 | #define SPEED_10000_PQ 0x12 |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 183 | #define SPEED_10000_RATE 0x0 |
| 184 | #define SPEED_10000_TXAMP 0xa |
| 185 | #define SPEED_10000_WORD 0x7 |
Tom Lendacky | 74ad752 | 2015-02-24 10:47:49 -0600 | [diff] [blame] | 186 | #define SPEED_10000_DFE_TAP_CONFIG 0x1 |
| 187 | #define SPEED_10000_DFE_TAP_ENABLE 0x7f |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 188 | |
Lendacky, Thomas | 8fdb1a09 | 2015-01-16 12:47:21 -0600 | [diff] [blame] | 189 | #define SPEED_2500_BLWC 1 |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 190 | #define SPEED_2500_CDR 0x2 |
| 191 | #define SPEED_2500_PLL 0x0 |
Lendacky, Thomas | 8fdb1a09 | 2015-01-16 12:47:21 -0600 | [diff] [blame] | 192 | #define SPEED_2500_PQ 0xa |
Lendacky, Thomas | f047604 | 2014-07-29 08:57:25 -0500 | [diff] [blame] | 193 | #define SPEED_2500_RATE 0x1 |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 194 | #define SPEED_2500_TXAMP 0xf |
| 195 | #define SPEED_2500_WORD 0x1 |
Tom Lendacky | 74ad752 | 2015-02-24 10:47:49 -0600 | [diff] [blame] | 196 | #define SPEED_2500_DFE_TAP_CONFIG 0x3 |
| 197 | #define SPEED_2500_DFE_TAP_ENABLE 0x0 |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 198 | |
Lendacky, Thomas | 8fdb1a09 | 2015-01-16 12:47:21 -0600 | [diff] [blame] | 199 | #define SPEED_1000_BLWC 1 |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 200 | #define SPEED_1000_CDR 0x2 |
| 201 | #define SPEED_1000_PLL 0x0 |
Lendacky, Thomas | 8fdb1a09 | 2015-01-16 12:47:21 -0600 | [diff] [blame] | 202 | #define SPEED_1000_PQ 0xa |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 203 | #define SPEED_1000_RATE 0x3 |
| 204 | #define SPEED_1000_TXAMP 0xf |
| 205 | #define SPEED_1000_WORD 0x1 |
Tom Lendacky | 74ad752 | 2015-02-24 10:47:49 -0600 | [diff] [blame] | 206 | #define SPEED_1000_DFE_TAP_CONFIG 0x3 |
| 207 | #define SPEED_1000_DFE_TAP_ENABLE 0x0 |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 208 | |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 209 | /* SerDes RxTx register offsets */ |
Tom Lendacky | 74ad752 | 2015-02-24 10:47:49 -0600 | [diff] [blame] | 210 | #define RXTX_REG6 0x0018 |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 211 | #define RXTX_REG20 0x0050 |
Tom Lendacky | 74ad752 | 2015-02-24 10:47:49 -0600 | [diff] [blame] | 212 | #define RXTX_REG22 0x0058 |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 213 | #define RXTX_REG114 0x01c8 |
Tom Lendacky | 74ad752 | 2015-02-24 10:47:49 -0600 | [diff] [blame] | 214 | #define RXTX_REG129 0x0204 |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 215 | |
| 216 | /* SerDes RxTx register entry bit positions and sizes */ |
Tom Lendacky | 74ad752 | 2015-02-24 10:47:49 -0600 | [diff] [blame] | 217 | #define RXTX_REG6_RESETB_RXD_INDEX 8 |
| 218 | #define RXTX_REG6_RESETB_RXD_WIDTH 1 |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 219 | #define RXTX_REG20_BLWC_ENA_INDEX 2 |
| 220 | #define RXTX_REG20_BLWC_ENA_WIDTH 1 |
| 221 | #define RXTX_REG114_PQ_REG_INDEX 9 |
| 222 | #define RXTX_REG114_PQ_REG_WIDTH 7 |
Tom Lendacky | 74ad752 | 2015-02-24 10:47:49 -0600 | [diff] [blame] | 223 | #define RXTX_REG129_RXDFE_CONFIG_INDEX 14 |
| 224 | #define RXTX_REG129_RXDFE_CONFIG_WIDTH 2 |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 225 | |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 226 | /* Bit setting and getting macros |
| 227 | * The get macro will extract the current bit field value from within |
| 228 | * the variable |
| 229 | * |
| 230 | * The set macro will clear the current bit field value within the |
| 231 | * variable and then set the bit field of the variable to the |
| 232 | * specified value |
| 233 | */ |
| 234 | #define GET_BITS(_var, _index, _width) \ |
| 235 | (((_var) >> (_index)) & ((0x1 << (_width)) - 1)) |
| 236 | |
| 237 | #define SET_BITS(_var, _index, _width, _val) \ |
| 238 | do { \ |
| 239 | (_var) &= ~(((0x1 << (_width)) - 1) << (_index)); \ |
| 240 | (_var) |= (((_val) & ((0x1 << (_width)) - 1)) << (_index)); \ |
| 241 | } while (0) |
| 242 | |
Lendacky, Thomas | 169a630 | 2014-07-29 08:57:37 -0500 | [diff] [blame] | 243 | #define XSIR_GET_BITS(_var, _prefix, _field) \ |
| 244 | GET_BITS((_var), \ |
| 245 | _prefix##_##_field##_INDEX, \ |
| 246 | _prefix##_##_field##_WIDTH) |
| 247 | |
| 248 | #define XSIR_SET_BITS(_var, _prefix, _field, _val) \ |
| 249 | SET_BITS((_var), \ |
| 250 | _prefix##_##_field##_INDEX, \ |
| 251 | _prefix##_##_field##_WIDTH, (_val)) |
| 252 | |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 253 | /* Macros for reading or writing SerDes integration registers |
| 254 | * The ioread macros will get bit fields or full values using the |
| 255 | * register definitions formed using the input names |
| 256 | * |
| 257 | * The iowrite macros will set bit fields or full values using the |
| 258 | * register definitions formed using the input names |
| 259 | */ |
| 260 | #define XSIR0_IOREAD(_priv, _reg) \ |
| 261 | ioread16((_priv)->sir0_regs + _reg) |
| 262 | |
| 263 | #define XSIR0_IOREAD_BITS(_priv, _reg, _field) \ |
| 264 | GET_BITS(XSIR0_IOREAD((_priv), _reg), \ |
| 265 | _reg##_##_field##_INDEX, \ |
| 266 | _reg##_##_field##_WIDTH) |
| 267 | |
| 268 | #define XSIR0_IOWRITE(_priv, _reg, _val) \ |
| 269 | iowrite16((_val), (_priv)->sir0_regs + _reg) |
| 270 | |
| 271 | #define XSIR0_IOWRITE_BITS(_priv, _reg, _field, _val) \ |
| 272 | do { \ |
| 273 | u16 reg_val = XSIR0_IOREAD((_priv), _reg); \ |
| 274 | SET_BITS(reg_val, \ |
| 275 | _reg##_##_field##_INDEX, \ |
| 276 | _reg##_##_field##_WIDTH, (_val)); \ |
| 277 | XSIR0_IOWRITE((_priv), _reg, reg_val); \ |
| 278 | } while (0) |
| 279 | |
| 280 | #define XSIR1_IOREAD(_priv, _reg) \ |
| 281 | ioread16((_priv)->sir1_regs + _reg) |
| 282 | |
| 283 | #define XSIR1_IOREAD_BITS(_priv, _reg, _field) \ |
| 284 | GET_BITS(XSIR1_IOREAD((_priv), _reg), \ |
| 285 | _reg##_##_field##_INDEX, \ |
| 286 | _reg##_##_field##_WIDTH) |
| 287 | |
| 288 | #define XSIR1_IOWRITE(_priv, _reg, _val) \ |
| 289 | iowrite16((_val), (_priv)->sir1_regs + _reg) |
| 290 | |
| 291 | #define XSIR1_IOWRITE_BITS(_priv, _reg, _field, _val) \ |
| 292 | do { \ |
| 293 | u16 reg_val = XSIR1_IOREAD((_priv), _reg); \ |
| 294 | SET_BITS(reg_val, \ |
| 295 | _reg##_##_field##_INDEX, \ |
| 296 | _reg##_##_field##_WIDTH, (_val)); \ |
| 297 | XSIR1_IOWRITE((_priv), _reg, reg_val); \ |
| 298 | } while (0) |
| 299 | |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 300 | /* Macros for reading or writing SerDes RxTx registers |
| 301 | * The ioread macros will get bit fields or full values using the |
| 302 | * register definitions formed using the input names |
| 303 | * |
| 304 | * The iowrite macros will set bit fields or full values using the |
| 305 | * register definitions formed using the input names |
| 306 | */ |
| 307 | #define XRXTX_IOREAD(_priv, _reg) \ |
| 308 | ioread16((_priv)->rxtx_regs + _reg) |
| 309 | |
| 310 | #define XRXTX_IOREAD_BITS(_priv, _reg, _field) \ |
| 311 | GET_BITS(XRXTX_IOREAD((_priv), _reg), \ |
| 312 | _reg##_##_field##_INDEX, \ |
| 313 | _reg##_##_field##_WIDTH) |
| 314 | |
| 315 | #define XRXTX_IOWRITE(_priv, _reg, _val) \ |
| 316 | iowrite16((_val), (_priv)->rxtx_regs + _reg) |
| 317 | |
| 318 | #define XRXTX_IOWRITE_BITS(_priv, _reg, _field, _val) \ |
| 319 | do { \ |
| 320 | u16 reg_val = XRXTX_IOREAD((_priv), _reg); \ |
| 321 | SET_BITS(reg_val, \ |
| 322 | _reg##_##_field##_INDEX, \ |
| 323 | _reg##_##_field##_WIDTH, (_val)); \ |
| 324 | XRXTX_IOWRITE((_priv), _reg, reg_val); \ |
| 325 | } while (0) |
| 326 | |
Lendacky, Thomas | 8fdb1a09 | 2015-01-16 12:47:21 -0600 | [diff] [blame] | 327 | static const u32 amd_xgbe_phy_serdes_blwc[] = { |
| 328 | SPEED_1000_BLWC, |
| 329 | SPEED_2500_BLWC, |
| 330 | SPEED_10000_BLWC, |
| 331 | }; |
| 332 | |
| 333 | static const u32 amd_xgbe_phy_serdes_cdr_rate[] = { |
| 334 | SPEED_1000_CDR, |
| 335 | SPEED_2500_CDR, |
| 336 | SPEED_10000_CDR, |
| 337 | }; |
| 338 | |
| 339 | static const u32 amd_xgbe_phy_serdes_pq_skew[] = { |
| 340 | SPEED_1000_PQ, |
| 341 | SPEED_2500_PQ, |
| 342 | SPEED_10000_PQ, |
| 343 | }; |
| 344 | |
| 345 | static const u32 amd_xgbe_phy_serdes_tx_amp[] = { |
| 346 | SPEED_1000_TXAMP, |
| 347 | SPEED_2500_TXAMP, |
| 348 | SPEED_10000_TXAMP, |
| 349 | }; |
| 350 | |
Tom Lendacky | 74ad752 | 2015-02-24 10:47:49 -0600 | [diff] [blame] | 351 | static const u32 amd_xgbe_phy_serdes_dfe_tap_cfg[] = { |
| 352 | SPEED_1000_DFE_TAP_CONFIG, |
| 353 | SPEED_2500_DFE_TAP_CONFIG, |
| 354 | SPEED_10000_DFE_TAP_CONFIG, |
| 355 | }; |
| 356 | |
| 357 | static const u32 amd_xgbe_phy_serdes_dfe_tap_ena[] = { |
| 358 | SPEED_1000_DFE_TAP_ENABLE, |
| 359 | SPEED_2500_DFE_TAP_ENABLE, |
| 360 | SPEED_10000_DFE_TAP_ENABLE, |
| 361 | }; |
| 362 | |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 363 | enum amd_xgbe_phy_an { |
| 364 | AMD_XGBE_AN_READY = 0, |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 365 | AMD_XGBE_AN_PAGE_RECEIVED, |
| 366 | AMD_XGBE_AN_INCOMPAT_LINK, |
| 367 | AMD_XGBE_AN_COMPLETE, |
| 368 | AMD_XGBE_AN_NO_LINK, |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 369 | AMD_XGBE_AN_ERROR, |
| 370 | }; |
| 371 | |
| 372 | enum amd_xgbe_phy_rx { |
Lendacky, Thomas | c3152d4 | 2015-01-16 12:47:00 -0600 | [diff] [blame] | 373 | AMD_XGBE_RX_BPA = 0, |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 374 | AMD_XGBE_RX_XNP, |
| 375 | AMD_XGBE_RX_COMPLETE, |
Lendacky, Thomas | c3152d4 | 2015-01-16 12:47:00 -0600 | [diff] [blame] | 376 | AMD_XGBE_RX_ERROR, |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 377 | }; |
| 378 | |
| 379 | enum amd_xgbe_phy_mode { |
| 380 | AMD_XGBE_MODE_KR, |
| 381 | AMD_XGBE_MODE_KX, |
| 382 | }; |
| 383 | |
Lendacky, Thomas | f047604 | 2014-07-29 08:57:25 -0500 | [diff] [blame] | 384 | enum amd_xgbe_phy_speedset { |
Lendacky, Thomas | 82a1903 | 2015-01-16 12:47:16 -0600 | [diff] [blame] | 385 | AMD_XGBE_PHY_SPEEDSET_1000_10000 = 0, |
Lendacky, Thomas | f047604 | 2014-07-29 08:57:25 -0500 | [diff] [blame] | 386 | AMD_XGBE_PHY_SPEEDSET_2500_10000, |
| 387 | }; |
| 388 | |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 389 | struct amd_xgbe_phy_priv { |
| 390 | struct platform_device *pdev; |
Lendacky, Thomas | 82a1903 | 2015-01-16 12:47:16 -0600 | [diff] [blame] | 391 | struct acpi_device *adev; |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 392 | struct device *dev; |
| 393 | |
| 394 | struct phy_device *phydev; |
| 395 | |
| 396 | /* SerDes related mmio resources */ |
| 397 | struct resource *rxtx_res; |
| 398 | struct resource *sir0_res; |
| 399 | struct resource *sir1_res; |
| 400 | |
| 401 | /* SerDes related mmio registers */ |
| 402 | void __iomem *rxtx_regs; /* SerDes Rx/Tx CSRs */ |
| 403 | void __iomem *sir0_regs; /* SerDes integration registers (1/2) */ |
| 404 | void __iomem *sir1_regs; /* SerDes integration registers (2/2) */ |
| 405 | |
Lendacky, Thomas | c3152d4 | 2015-01-16 12:47:00 -0600 | [diff] [blame] | 406 | int an_irq; |
| 407 | char an_irq_name[IFNAMSIZ + 32]; |
| 408 | struct work_struct an_irq_work; |
| 409 | unsigned int an_irq_allocated; |
| 410 | |
Lendacky, Thomas | f047604 | 2014-07-29 08:57:25 -0500 | [diff] [blame] | 411 | unsigned int speed_set; |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 412 | |
Lendacky, Thomas | 8fdb1a09 | 2015-01-16 12:47:21 -0600 | [diff] [blame] | 413 | /* SerDes UEFI configurable settings. |
| 414 | * Switching between modes/speeds requires new values for some |
| 415 | * SerDes settings. The values can be supplied as device |
| 416 | * properties in array format. The first array entry is for |
| 417 | * 1GbE, second for 2.5GbE and third for 10GbE |
| 418 | */ |
| 419 | u32 serdes_blwc[XGBE_PHY_SPEEDS]; |
| 420 | u32 serdes_cdr_rate[XGBE_PHY_SPEEDS]; |
| 421 | u32 serdes_pq_skew[XGBE_PHY_SPEEDS]; |
| 422 | u32 serdes_tx_amp[XGBE_PHY_SPEEDS]; |
Tom Lendacky | 74ad752 | 2015-02-24 10:47:49 -0600 | [diff] [blame] | 423 | u32 serdes_dfe_tap_cfg[XGBE_PHY_SPEEDS]; |
| 424 | u32 serdes_dfe_tap_ena[XGBE_PHY_SPEEDS]; |
Lendacky, Thomas | 8fdb1a09 | 2015-01-16 12:47:21 -0600 | [diff] [blame] | 425 | |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 426 | /* Auto-negotiation state machine support */ |
| 427 | struct mutex an_mutex; |
| 428 | enum amd_xgbe_phy_an an_result; |
| 429 | enum amd_xgbe_phy_an an_state; |
| 430 | enum amd_xgbe_phy_rx kr_state; |
| 431 | enum amd_xgbe_phy_rx kx_state; |
| 432 | struct work_struct an_work; |
| 433 | struct workqueue_struct *an_workqueue; |
Lendacky, Thomas | c3152d4 | 2015-01-16 12:47:00 -0600 | [diff] [blame] | 434 | unsigned int an_supported; |
Lendacky, Thomas | e6f0562 | 2014-09-03 12:14:22 -0500 | [diff] [blame] | 435 | unsigned int parallel_detect; |
Lendacky, Thomas | cf26252 | 2015-01-16 12:47:05 -0600 | [diff] [blame] | 436 | unsigned int fec_ability; |
Lendacky, Thomas | 03e50fd | 2015-01-16 12:46:39 -0600 | [diff] [blame] | 437 | |
| 438 | unsigned int lpm_ctrl; /* CTRL1 for resume */ |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 439 | }; |
| 440 | |
| 441 | static int amd_xgbe_an_enable_kr_training(struct phy_device *phydev) |
| 442 | { |
| 443 | int ret; |
| 444 | |
| 445 | ret = phy_read_mmd(phydev, MDIO_MMD_PMAPMD, MDIO_PMA_10GBR_PMD_CTRL); |
| 446 | if (ret < 0) |
| 447 | return ret; |
| 448 | |
Lendacky, Thomas | cf26252 | 2015-01-16 12:47:05 -0600 | [diff] [blame] | 449 | ret |= XGBE_PHY_KR_TRAINING_ENABLE; |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 450 | phy_write_mmd(phydev, MDIO_MMD_PMAPMD, MDIO_PMA_10GBR_PMD_CTRL, ret); |
| 451 | |
| 452 | return 0; |
| 453 | } |
| 454 | |
| 455 | static int amd_xgbe_an_disable_kr_training(struct phy_device *phydev) |
| 456 | { |
| 457 | int ret; |
| 458 | |
| 459 | ret = phy_read_mmd(phydev, MDIO_MMD_PMAPMD, MDIO_PMA_10GBR_PMD_CTRL); |
| 460 | if (ret < 0) |
| 461 | return ret; |
| 462 | |
Lendacky, Thomas | cf26252 | 2015-01-16 12:47:05 -0600 | [diff] [blame] | 463 | ret &= ~XGBE_PHY_KR_TRAINING_ENABLE; |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 464 | phy_write_mmd(phydev, MDIO_MMD_PMAPMD, MDIO_PMA_10GBR_PMD_CTRL, ret); |
| 465 | |
| 466 | return 0; |
| 467 | } |
| 468 | |
| 469 | static int amd_xgbe_phy_pcs_power_cycle(struct phy_device *phydev) |
| 470 | { |
| 471 | int ret; |
| 472 | |
| 473 | ret = phy_read_mmd(phydev, MDIO_MMD_PCS, MDIO_CTRL1); |
| 474 | if (ret < 0) |
| 475 | return ret; |
| 476 | |
| 477 | ret |= MDIO_CTRL1_LPOWER; |
| 478 | phy_write_mmd(phydev, MDIO_MMD_PCS, MDIO_CTRL1, ret); |
| 479 | |
| 480 | usleep_range(75, 100); |
| 481 | |
| 482 | ret &= ~MDIO_CTRL1_LPOWER; |
| 483 | phy_write_mmd(phydev, MDIO_MMD_PCS, MDIO_CTRL1, ret); |
| 484 | |
| 485 | return 0; |
| 486 | } |
| 487 | |
| 488 | static void amd_xgbe_phy_serdes_start_ratechange(struct phy_device *phydev) |
| 489 | { |
| 490 | struct amd_xgbe_phy_priv *priv = phydev->priv; |
| 491 | |
| 492 | /* Assert Rx and Tx ratechange */ |
| 493 | XSIR1_IOWRITE_BITS(priv, SIR1_SPEED, RATECHANGE, 1); |
| 494 | } |
| 495 | |
| 496 | static void amd_xgbe_phy_serdes_complete_ratechange(struct phy_device *phydev) |
| 497 | { |
| 498 | struct amd_xgbe_phy_priv *priv = phydev->priv; |
Lendacky, Thomas | 169a630 | 2014-07-29 08:57:37 -0500 | [diff] [blame] | 499 | unsigned int wait; |
| 500 | u16 status; |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 501 | |
| 502 | /* Release Rx and Tx ratechange */ |
| 503 | XSIR1_IOWRITE_BITS(priv, SIR1_SPEED, RATECHANGE, 0); |
| 504 | |
| 505 | /* Wait for Rx and Tx ready */ |
Lendacky, Thomas | 169a630 | 2014-07-29 08:57:37 -0500 | [diff] [blame] | 506 | wait = XGBE_PHY_RATECHANGE_COUNT; |
| 507 | while (wait--) { |
Lendacky, Thomas | 1fa1f2e | 2014-08-01 11:56:36 -0500 | [diff] [blame] | 508 | usleep_range(50, 75); |
Lendacky, Thomas | 169a630 | 2014-07-29 08:57:37 -0500 | [diff] [blame] | 509 | |
| 510 | status = XSIR0_IOREAD(priv, SIR0_STATUS); |
| 511 | if (XSIR_GET_BITS(status, SIR0_STATUS, RX_READY) && |
| 512 | XSIR_GET_BITS(status, SIR0_STATUS, TX_READY)) |
Tom Lendacky | 74ad752 | 2015-02-24 10:47:49 -0600 | [diff] [blame] | 513 | goto rx_reset; |
Lendacky, Thomas | 169a630 | 2014-07-29 08:57:37 -0500 | [diff] [blame] | 514 | } |
| 515 | |
Lendacky, Thomas | 1fa1f2e | 2014-08-01 11:56:36 -0500 | [diff] [blame] | 516 | netdev_dbg(phydev->attached_dev, "SerDes rx/tx not ready (%#hx)\n", |
Lendacky, Thomas | 169a630 | 2014-07-29 08:57:37 -0500 | [diff] [blame] | 517 | status); |
Tom Lendacky | 74ad752 | 2015-02-24 10:47:49 -0600 | [diff] [blame] | 518 | |
| 519 | rx_reset: |
| 520 | /* Perform Rx reset for the DFE changes */ |
| 521 | XRXTX_IOWRITE_BITS(priv, RXTX_REG6, RESETB_RXD, 0); |
| 522 | XRXTX_IOWRITE_BITS(priv, RXTX_REG6, RESETB_RXD, 1); |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | static int amd_xgbe_phy_xgmii_mode(struct phy_device *phydev) |
| 526 | { |
| 527 | struct amd_xgbe_phy_priv *priv = phydev->priv; |
| 528 | int ret; |
| 529 | |
| 530 | /* Enable KR training */ |
| 531 | ret = amd_xgbe_an_enable_kr_training(phydev); |
| 532 | if (ret < 0) |
| 533 | return ret; |
| 534 | |
| 535 | /* Set PCS to KR/10G speed */ |
| 536 | ret = phy_read_mmd(phydev, MDIO_MMD_PCS, MDIO_CTRL2); |
| 537 | if (ret < 0) |
| 538 | return ret; |
| 539 | |
| 540 | ret &= ~MDIO_PCS_CTRL2_TYPE; |
| 541 | ret |= MDIO_PCS_CTRL2_10GBR; |
| 542 | phy_write_mmd(phydev, MDIO_MMD_PCS, MDIO_CTRL2, ret); |
| 543 | |
| 544 | ret = phy_read_mmd(phydev, MDIO_MMD_PCS, MDIO_CTRL1); |
| 545 | if (ret < 0) |
| 546 | return ret; |
| 547 | |
| 548 | ret &= ~MDIO_CTRL1_SPEEDSEL; |
| 549 | ret |= MDIO_CTRL1_SPEED10G; |
| 550 | phy_write_mmd(phydev, MDIO_MMD_PCS, MDIO_CTRL1, ret); |
| 551 | |
| 552 | ret = amd_xgbe_phy_pcs_power_cycle(phydev); |
| 553 | if (ret < 0) |
| 554 | return ret; |
| 555 | |
| 556 | /* Set SerDes to 10G speed */ |
| 557 | amd_xgbe_phy_serdes_start_ratechange(phydev); |
| 558 | |
| 559 | XSIR1_IOWRITE_BITS(priv, SIR1_SPEED, DATARATE, SPEED_10000_RATE); |
| 560 | XSIR1_IOWRITE_BITS(priv, SIR1_SPEED, WORDMODE, SPEED_10000_WORD); |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 561 | XSIR1_IOWRITE_BITS(priv, SIR1_SPEED, PLLSEL, SPEED_10000_PLL); |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 562 | |
Lendacky, Thomas | 8fdb1a09 | 2015-01-16 12:47:21 -0600 | [diff] [blame] | 563 | XSIR1_IOWRITE_BITS(priv, SIR1_SPEED, CDR_RATE, |
| 564 | priv->serdes_cdr_rate[XGBE_PHY_SPEED_10000]); |
| 565 | XSIR1_IOWRITE_BITS(priv, SIR1_SPEED, TXAMP, |
| 566 | priv->serdes_tx_amp[XGBE_PHY_SPEED_10000]); |
| 567 | XRXTX_IOWRITE_BITS(priv, RXTX_REG20, BLWC_ENA, |
| 568 | priv->serdes_blwc[XGBE_PHY_SPEED_10000]); |
| 569 | XRXTX_IOWRITE_BITS(priv, RXTX_REG114, PQ_REG, |
| 570 | priv->serdes_pq_skew[XGBE_PHY_SPEED_10000]); |
Tom Lendacky | 74ad752 | 2015-02-24 10:47:49 -0600 | [diff] [blame] | 571 | XRXTX_IOWRITE_BITS(priv, RXTX_REG129, RXDFE_CONFIG, |
| 572 | priv->serdes_dfe_tap_cfg[XGBE_PHY_SPEED_10000]); |
| 573 | XRXTX_IOWRITE(priv, RXTX_REG22, |
| 574 | priv->serdes_dfe_tap_ena[XGBE_PHY_SPEED_10000]); |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 575 | |
| 576 | amd_xgbe_phy_serdes_complete_ratechange(phydev); |
| 577 | |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 578 | return 0; |
| 579 | } |
| 580 | |
| 581 | static int amd_xgbe_phy_gmii_2500_mode(struct phy_device *phydev) |
| 582 | { |
| 583 | struct amd_xgbe_phy_priv *priv = phydev->priv; |
| 584 | int ret; |
| 585 | |
| 586 | /* Disable KR training */ |
| 587 | ret = amd_xgbe_an_disable_kr_training(phydev); |
| 588 | if (ret < 0) |
| 589 | return ret; |
| 590 | |
| 591 | /* Set PCS to KX/1G speed */ |
| 592 | ret = phy_read_mmd(phydev, MDIO_MMD_PCS, MDIO_CTRL2); |
| 593 | if (ret < 0) |
| 594 | return ret; |
| 595 | |
| 596 | ret &= ~MDIO_PCS_CTRL2_TYPE; |
| 597 | ret |= MDIO_PCS_CTRL2_10GBX; |
| 598 | phy_write_mmd(phydev, MDIO_MMD_PCS, MDIO_CTRL2, ret); |
| 599 | |
| 600 | ret = phy_read_mmd(phydev, MDIO_MMD_PCS, MDIO_CTRL1); |
| 601 | if (ret < 0) |
| 602 | return ret; |
| 603 | |
| 604 | ret &= ~MDIO_CTRL1_SPEEDSEL; |
| 605 | ret |= MDIO_CTRL1_SPEED1G; |
| 606 | phy_write_mmd(phydev, MDIO_MMD_PCS, MDIO_CTRL1, ret); |
| 607 | |
| 608 | ret = amd_xgbe_phy_pcs_power_cycle(phydev); |
| 609 | if (ret < 0) |
| 610 | return ret; |
| 611 | |
| 612 | /* Set SerDes to 2.5G speed */ |
| 613 | amd_xgbe_phy_serdes_start_ratechange(phydev); |
| 614 | |
| 615 | XSIR1_IOWRITE_BITS(priv, SIR1_SPEED, DATARATE, SPEED_2500_RATE); |
| 616 | XSIR1_IOWRITE_BITS(priv, SIR1_SPEED, WORDMODE, SPEED_2500_WORD); |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 617 | XSIR1_IOWRITE_BITS(priv, SIR1_SPEED, PLLSEL, SPEED_2500_PLL); |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 618 | |
Lendacky, Thomas | 8fdb1a09 | 2015-01-16 12:47:21 -0600 | [diff] [blame] | 619 | XSIR1_IOWRITE_BITS(priv, SIR1_SPEED, CDR_RATE, |
| 620 | priv->serdes_cdr_rate[XGBE_PHY_SPEED_2500]); |
| 621 | XSIR1_IOWRITE_BITS(priv, SIR1_SPEED, TXAMP, |
| 622 | priv->serdes_tx_amp[XGBE_PHY_SPEED_2500]); |
| 623 | XRXTX_IOWRITE_BITS(priv, RXTX_REG20, BLWC_ENA, |
| 624 | priv->serdes_blwc[XGBE_PHY_SPEED_2500]); |
| 625 | XRXTX_IOWRITE_BITS(priv, RXTX_REG114, PQ_REG, |
| 626 | priv->serdes_pq_skew[XGBE_PHY_SPEED_2500]); |
Tom Lendacky | 74ad752 | 2015-02-24 10:47:49 -0600 | [diff] [blame] | 627 | XRXTX_IOWRITE_BITS(priv, RXTX_REG129, RXDFE_CONFIG, |
| 628 | priv->serdes_dfe_tap_cfg[XGBE_PHY_SPEED_2500]); |
| 629 | XRXTX_IOWRITE(priv, RXTX_REG22, |
| 630 | priv->serdes_dfe_tap_ena[XGBE_PHY_SPEED_2500]); |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 631 | |
| 632 | amd_xgbe_phy_serdes_complete_ratechange(phydev); |
| 633 | |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 634 | return 0; |
| 635 | } |
| 636 | |
| 637 | static int amd_xgbe_phy_gmii_mode(struct phy_device *phydev) |
| 638 | { |
| 639 | struct amd_xgbe_phy_priv *priv = phydev->priv; |
| 640 | int ret; |
| 641 | |
| 642 | /* Disable KR training */ |
| 643 | ret = amd_xgbe_an_disable_kr_training(phydev); |
| 644 | if (ret < 0) |
| 645 | return ret; |
| 646 | |
| 647 | /* Set PCS to KX/1G speed */ |
| 648 | ret = phy_read_mmd(phydev, MDIO_MMD_PCS, MDIO_CTRL2); |
| 649 | if (ret < 0) |
| 650 | return ret; |
| 651 | |
| 652 | ret &= ~MDIO_PCS_CTRL2_TYPE; |
| 653 | ret |= MDIO_PCS_CTRL2_10GBX; |
| 654 | phy_write_mmd(phydev, MDIO_MMD_PCS, MDIO_CTRL2, ret); |
| 655 | |
| 656 | ret = phy_read_mmd(phydev, MDIO_MMD_PCS, MDIO_CTRL1); |
| 657 | if (ret < 0) |
| 658 | return ret; |
| 659 | |
| 660 | ret &= ~MDIO_CTRL1_SPEEDSEL; |
| 661 | ret |= MDIO_CTRL1_SPEED1G; |
| 662 | phy_write_mmd(phydev, MDIO_MMD_PCS, MDIO_CTRL1, ret); |
| 663 | |
| 664 | ret = amd_xgbe_phy_pcs_power_cycle(phydev); |
| 665 | if (ret < 0) |
| 666 | return ret; |
| 667 | |
| 668 | /* Set SerDes to 1G speed */ |
| 669 | amd_xgbe_phy_serdes_start_ratechange(phydev); |
| 670 | |
| 671 | XSIR1_IOWRITE_BITS(priv, SIR1_SPEED, DATARATE, SPEED_1000_RATE); |
| 672 | XSIR1_IOWRITE_BITS(priv, SIR1_SPEED, WORDMODE, SPEED_1000_WORD); |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 673 | XSIR1_IOWRITE_BITS(priv, SIR1_SPEED, PLLSEL, SPEED_1000_PLL); |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 674 | |
Lendacky, Thomas | 8fdb1a09 | 2015-01-16 12:47:21 -0600 | [diff] [blame] | 675 | XSIR1_IOWRITE_BITS(priv, SIR1_SPEED, CDR_RATE, |
| 676 | priv->serdes_cdr_rate[XGBE_PHY_SPEED_1000]); |
| 677 | XSIR1_IOWRITE_BITS(priv, SIR1_SPEED, TXAMP, |
| 678 | priv->serdes_tx_amp[XGBE_PHY_SPEED_1000]); |
| 679 | XRXTX_IOWRITE_BITS(priv, RXTX_REG20, BLWC_ENA, |
| 680 | priv->serdes_blwc[XGBE_PHY_SPEED_1000]); |
| 681 | XRXTX_IOWRITE_BITS(priv, RXTX_REG114, PQ_REG, |
| 682 | priv->serdes_pq_skew[XGBE_PHY_SPEED_1000]); |
Tom Lendacky | 74ad752 | 2015-02-24 10:47:49 -0600 | [diff] [blame] | 683 | XRXTX_IOWRITE_BITS(priv, RXTX_REG129, RXDFE_CONFIG, |
| 684 | priv->serdes_dfe_tap_cfg[XGBE_PHY_SPEED_1000]); |
| 685 | XRXTX_IOWRITE(priv, RXTX_REG22, |
| 686 | priv->serdes_dfe_tap_ena[XGBE_PHY_SPEED_1000]); |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 687 | |
| 688 | amd_xgbe_phy_serdes_complete_ratechange(phydev); |
| 689 | |
Lendacky, Thomas | e3eec4e | 2014-09-03 12:14:16 -0500 | [diff] [blame] | 690 | return 0; |
| 691 | } |
| 692 | |
| 693 | static int amd_xgbe_phy_cur_mode(struct phy_device *phydev, |
| 694 | enum amd_xgbe_phy_mode *mode) |
| 695 | { |
| 696 | int ret; |
| 697 | |
| 698 | ret = phy_read_mmd(phydev, MDIO_MMD_PCS, MDIO_CTRL2); |
| 699 | if (ret < 0) |
| 700 | return ret; |
| 701 | |
| 702 | if ((ret & MDIO_PCS_CTRL2_TYPE) == MDIO_PCS_CTRL2_10GBR) |
| 703 | *mode = AMD_XGBE_MODE_KR; |
| 704 | else |
| 705 | *mode = AMD_XGBE_MODE_KX; |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 706 | |
| 707 | return 0; |
| 708 | } |
| 709 | |
Lendacky, Thomas | e3eec4e | 2014-09-03 12:14:16 -0500 | [diff] [blame] | 710 | static bool amd_xgbe_phy_in_kr_mode(struct phy_device *phydev) |
| 711 | { |
| 712 | enum amd_xgbe_phy_mode mode; |
| 713 | |
| 714 | if (amd_xgbe_phy_cur_mode(phydev, &mode)) |
| 715 | return false; |
| 716 | |
| 717 | return (mode == AMD_XGBE_MODE_KR); |
| 718 | } |
| 719 | |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 720 | static int amd_xgbe_phy_switch_mode(struct phy_device *phydev) |
| 721 | { |
| 722 | struct amd_xgbe_phy_priv *priv = phydev->priv; |
| 723 | int ret; |
| 724 | |
| 725 | /* If we are in KR switch to KX, and vice-versa */ |
Lendacky, Thomas | e3eec4e | 2014-09-03 12:14:16 -0500 | [diff] [blame] | 726 | if (amd_xgbe_phy_in_kr_mode(phydev)) { |
Lendacky, Thomas | f047604 | 2014-07-29 08:57:25 -0500 | [diff] [blame] | 727 | if (priv->speed_set == AMD_XGBE_PHY_SPEEDSET_1000_10000) |
| 728 | ret = amd_xgbe_phy_gmii_mode(phydev); |
| 729 | else |
| 730 | ret = amd_xgbe_phy_gmii_2500_mode(phydev); |
| 731 | } else { |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 732 | ret = amd_xgbe_phy_xgmii_mode(phydev); |
Lendacky, Thomas | f047604 | 2014-07-29 08:57:25 -0500 | [diff] [blame] | 733 | } |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 734 | |
| 735 | return ret; |
| 736 | } |
| 737 | |
Lendacky, Thomas | e3eec4e | 2014-09-03 12:14:16 -0500 | [diff] [blame] | 738 | static int amd_xgbe_phy_set_mode(struct phy_device *phydev, |
| 739 | enum amd_xgbe_phy_mode mode) |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 740 | { |
Lendacky, Thomas | e3eec4e | 2014-09-03 12:14:16 -0500 | [diff] [blame] | 741 | enum amd_xgbe_phy_mode cur_mode; |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 742 | int ret; |
| 743 | |
Lendacky, Thomas | e3eec4e | 2014-09-03 12:14:16 -0500 | [diff] [blame] | 744 | ret = amd_xgbe_phy_cur_mode(phydev, &cur_mode); |
| 745 | if (ret) |
| 746 | return ret; |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 747 | |
Lendacky, Thomas | e3eec4e | 2014-09-03 12:14:16 -0500 | [diff] [blame] | 748 | if (mode != cur_mode) |
| 749 | ret = amd_xgbe_phy_switch_mode(phydev); |
| 750 | |
| 751 | return ret; |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 752 | } |
| 753 | |
Lendacky, Thomas | c3152d4 | 2015-01-16 12:47:00 -0600 | [diff] [blame] | 754 | static int amd_xgbe_phy_set_an(struct phy_device *phydev, bool enable, |
| 755 | bool restart) |
| 756 | { |
| 757 | int ret; |
| 758 | |
| 759 | ret = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_CTRL1); |
| 760 | if (ret < 0) |
| 761 | return ret; |
| 762 | |
| 763 | ret &= ~MDIO_AN_CTRL1_ENABLE; |
| 764 | |
| 765 | if (enable) |
| 766 | ret |= MDIO_AN_CTRL1_ENABLE; |
| 767 | |
| 768 | if (restart) |
| 769 | ret |= MDIO_AN_CTRL1_RESTART; |
| 770 | |
| 771 | phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_CTRL1, ret); |
| 772 | |
| 773 | return 0; |
| 774 | } |
| 775 | |
| 776 | static int amd_xgbe_phy_restart_an(struct phy_device *phydev) |
| 777 | { |
| 778 | return amd_xgbe_phy_set_an(phydev, true, true); |
| 779 | } |
| 780 | |
| 781 | static int amd_xgbe_phy_disable_an(struct phy_device *phydev) |
| 782 | { |
| 783 | return amd_xgbe_phy_set_an(phydev, false, false); |
| 784 | } |
| 785 | |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 786 | static enum amd_xgbe_phy_an amd_xgbe_an_tx_training(struct phy_device *phydev, |
| 787 | enum amd_xgbe_phy_rx *state) |
| 788 | { |
Tom Lendacky | a42f5c1 | 2014-09-07 09:54:41 -0500 | [diff] [blame] | 789 | struct amd_xgbe_phy_priv *priv = phydev->priv; |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 790 | int ad_reg, lp_reg, ret; |
| 791 | |
| 792 | *state = AMD_XGBE_RX_COMPLETE; |
| 793 | |
Lendacky, Thomas | e3eec4e | 2014-09-03 12:14:16 -0500 | [diff] [blame] | 794 | /* If we're not in KR mode then we're done */ |
| 795 | if (!amd_xgbe_phy_in_kr_mode(phydev)) |
Lendacky, Thomas | c3152d4 | 2015-01-16 12:47:00 -0600 | [diff] [blame] | 796 | return AMD_XGBE_AN_PAGE_RECEIVED; |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 797 | |
| 798 | /* Enable/Disable FEC */ |
| 799 | ad_reg = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_ADVERTISE + 2); |
| 800 | if (ad_reg < 0) |
| 801 | return AMD_XGBE_AN_ERROR; |
| 802 | |
| 803 | lp_reg = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_LPA + 2); |
| 804 | if (lp_reg < 0) |
| 805 | return AMD_XGBE_AN_ERROR; |
| 806 | |
| 807 | ret = phy_read_mmd(phydev, MDIO_MMD_PMAPMD, MDIO_PMA_10GBR_FEC_CTRL); |
| 808 | if (ret < 0) |
| 809 | return AMD_XGBE_AN_ERROR; |
| 810 | |
Lendacky, Thomas | cf26252 | 2015-01-16 12:47:05 -0600 | [diff] [blame] | 811 | ret &= ~XGBE_PHY_FEC_MASK; |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 812 | if ((ad_reg & 0xc000) && (lp_reg & 0xc000)) |
Lendacky, Thomas | cf26252 | 2015-01-16 12:47:05 -0600 | [diff] [blame] | 813 | ret |= priv->fec_ability; |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 814 | |
| 815 | phy_write_mmd(phydev, MDIO_MMD_PMAPMD, MDIO_PMA_10GBR_FEC_CTRL, ret); |
| 816 | |
| 817 | /* Start KR training */ |
| 818 | ret = phy_read_mmd(phydev, MDIO_MMD_PMAPMD, MDIO_PMA_10GBR_PMD_CTRL); |
| 819 | if (ret < 0) |
| 820 | return AMD_XGBE_AN_ERROR; |
| 821 | |
Lendacky, Thomas | cf26252 | 2015-01-16 12:47:05 -0600 | [diff] [blame] | 822 | if (ret & XGBE_PHY_KR_TRAINING_ENABLE) { |
| 823 | XSIR0_IOWRITE_BITS(priv, SIR0_KR_RT_1, RESET, 1); |
Lendacky, Thomas | 5c10e5c | 2014-07-29 08:57:43 -0500 | [diff] [blame] | 824 | |
Lendacky, Thomas | cf26252 | 2015-01-16 12:47:05 -0600 | [diff] [blame] | 825 | ret |= XGBE_PHY_KR_TRAINING_START; |
| 826 | phy_write_mmd(phydev, MDIO_MMD_PMAPMD, MDIO_PMA_10GBR_PMD_CTRL, |
| 827 | ret); |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 828 | |
Lendacky, Thomas | cf26252 | 2015-01-16 12:47:05 -0600 | [diff] [blame] | 829 | XSIR0_IOWRITE_BITS(priv, SIR0_KR_RT_1, RESET, 0); |
| 830 | } |
Lendacky, Thomas | 5c10e5c | 2014-07-29 08:57:43 -0500 | [diff] [blame] | 831 | |
Lendacky, Thomas | c3152d4 | 2015-01-16 12:47:00 -0600 | [diff] [blame] | 832 | return AMD_XGBE_AN_PAGE_RECEIVED; |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 833 | } |
| 834 | |
| 835 | static enum amd_xgbe_phy_an amd_xgbe_an_tx_xnp(struct phy_device *phydev, |
| 836 | enum amd_xgbe_phy_rx *state) |
| 837 | { |
| 838 | u16 msg; |
| 839 | |
| 840 | *state = AMD_XGBE_RX_XNP; |
| 841 | |
| 842 | msg = XNP_MCF_NULL_MESSAGE; |
| 843 | msg |= XNP_MP_FORMATTED; |
| 844 | |
| 845 | phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_AN_XNP + 2, 0); |
| 846 | phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_AN_XNP + 1, 0); |
| 847 | phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_AN_XNP, msg); |
| 848 | |
Lendacky, Thomas | c3152d4 | 2015-01-16 12:47:00 -0600 | [diff] [blame] | 849 | return AMD_XGBE_AN_PAGE_RECEIVED; |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 850 | } |
| 851 | |
| 852 | static enum amd_xgbe_phy_an amd_xgbe_an_rx_bpa(struct phy_device *phydev, |
| 853 | enum amd_xgbe_phy_rx *state) |
| 854 | { |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 855 | unsigned int link_support; |
| 856 | int ret, ad_reg, lp_reg; |
| 857 | |
| 858 | /* Read Base Ability register 2 first */ |
| 859 | ret = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_LPA + 1); |
| 860 | if (ret < 0) |
| 861 | return AMD_XGBE_AN_ERROR; |
| 862 | |
| 863 | /* Check for a supported mode, otherwise restart in a different one */ |
Lendacky, Thomas | e3eec4e | 2014-09-03 12:14:16 -0500 | [diff] [blame] | 864 | link_support = amd_xgbe_phy_in_kr_mode(phydev) ? 0x80 : 0x20; |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 865 | if (!(ret & link_support)) |
Lendacky, Thomas | e3eec4e | 2014-09-03 12:14:16 -0500 | [diff] [blame] | 866 | return AMD_XGBE_AN_INCOMPAT_LINK; |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 867 | |
| 868 | /* Check Extended Next Page support */ |
| 869 | ad_reg = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_ADVERTISE); |
| 870 | if (ad_reg < 0) |
| 871 | return AMD_XGBE_AN_ERROR; |
| 872 | |
| 873 | lp_reg = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_LPA); |
| 874 | if (lp_reg < 0) |
| 875 | return AMD_XGBE_AN_ERROR; |
| 876 | |
| 877 | return ((ad_reg & XNP_NP_EXCHANGE) || (lp_reg & XNP_NP_EXCHANGE)) ? |
| 878 | amd_xgbe_an_tx_xnp(phydev, state) : |
| 879 | amd_xgbe_an_tx_training(phydev, state); |
| 880 | } |
| 881 | |
| 882 | static enum amd_xgbe_phy_an amd_xgbe_an_rx_xnp(struct phy_device *phydev, |
| 883 | enum amd_xgbe_phy_rx *state) |
| 884 | { |
| 885 | int ad_reg, lp_reg; |
| 886 | |
| 887 | /* Check Extended Next Page support */ |
Lendacky, Thomas | 0d40b61 | 2015-01-16 12:47:10 -0600 | [diff] [blame] | 888 | ad_reg = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_XNP); |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 889 | if (ad_reg < 0) |
| 890 | return AMD_XGBE_AN_ERROR; |
| 891 | |
Lendacky, Thomas | 0d40b61 | 2015-01-16 12:47:10 -0600 | [diff] [blame] | 892 | lp_reg = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_LPX); |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 893 | if (lp_reg < 0) |
| 894 | return AMD_XGBE_AN_ERROR; |
| 895 | |
| 896 | return ((ad_reg & XNP_NP_EXCHANGE) || (lp_reg & XNP_NP_EXCHANGE)) ? |
| 897 | amd_xgbe_an_tx_xnp(phydev, state) : |
| 898 | amd_xgbe_an_tx_training(phydev, state); |
| 899 | } |
| 900 | |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 901 | static enum amd_xgbe_phy_an amd_xgbe_an_page_received(struct phy_device *phydev) |
| 902 | { |
| 903 | struct amd_xgbe_phy_priv *priv = phydev->priv; |
| 904 | enum amd_xgbe_phy_rx *state; |
| 905 | int ret; |
| 906 | |
Lendacky, Thomas | e3eec4e | 2014-09-03 12:14:16 -0500 | [diff] [blame] | 907 | state = amd_xgbe_phy_in_kr_mode(phydev) ? &priv->kr_state |
| 908 | : &priv->kx_state; |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 909 | |
| 910 | switch (*state) { |
| 911 | case AMD_XGBE_RX_BPA: |
| 912 | ret = amd_xgbe_an_rx_bpa(phydev, state); |
| 913 | break; |
| 914 | |
| 915 | case AMD_XGBE_RX_XNP: |
| 916 | ret = amd_xgbe_an_rx_xnp(phydev, state); |
| 917 | break; |
| 918 | |
| 919 | default: |
| 920 | ret = AMD_XGBE_AN_ERROR; |
| 921 | } |
| 922 | |
| 923 | return ret; |
| 924 | } |
| 925 | |
| 926 | static enum amd_xgbe_phy_an amd_xgbe_an_incompat_link(struct phy_device *phydev) |
| 927 | { |
Lendacky, Thomas | c3152d4 | 2015-01-16 12:47:00 -0600 | [diff] [blame] | 928 | struct amd_xgbe_phy_priv *priv = phydev->priv; |
Lendacky, Thomas | e3eec4e | 2014-09-03 12:14:16 -0500 | [diff] [blame] | 929 | int ret; |
| 930 | |
Lendacky, Thomas | c3152d4 | 2015-01-16 12:47:00 -0600 | [diff] [blame] | 931 | /* Be sure we aren't looping trying to negotiate */ |
| 932 | if (amd_xgbe_phy_in_kr_mode(phydev)) { |
| 933 | priv->kr_state = AMD_XGBE_RX_ERROR; |
| 934 | |
Lendacky, Thomas | d9663c8 | 2015-03-20 11:49:42 -0500 | [diff] [blame] | 935 | if (!(phydev->advertising & SUPPORTED_1000baseKX_Full) && |
| 936 | !(phydev->advertising & SUPPORTED_2500baseX_Full)) |
Lendacky, Thomas | c3152d4 | 2015-01-16 12:47:00 -0600 | [diff] [blame] | 937 | return AMD_XGBE_AN_NO_LINK; |
| 938 | |
| 939 | if (priv->kx_state != AMD_XGBE_RX_BPA) |
| 940 | return AMD_XGBE_AN_NO_LINK; |
| 941 | } else { |
| 942 | priv->kx_state = AMD_XGBE_RX_ERROR; |
| 943 | |
Lendacky, Thomas | d9663c8 | 2015-03-20 11:49:42 -0500 | [diff] [blame] | 944 | if (!(phydev->advertising & SUPPORTED_10000baseKR_Full)) |
Lendacky, Thomas | c3152d4 | 2015-01-16 12:47:00 -0600 | [diff] [blame] | 945 | return AMD_XGBE_AN_NO_LINK; |
| 946 | |
| 947 | if (priv->kr_state != AMD_XGBE_RX_BPA) |
| 948 | return AMD_XGBE_AN_NO_LINK; |
| 949 | } |
| 950 | |
| 951 | ret = amd_xgbe_phy_disable_an(phydev); |
| 952 | if (ret) |
| 953 | return AMD_XGBE_AN_ERROR; |
| 954 | |
Lendacky, Thomas | e3eec4e | 2014-09-03 12:14:16 -0500 | [diff] [blame] | 955 | ret = amd_xgbe_phy_switch_mode(phydev); |
| 956 | if (ret) |
| 957 | return AMD_XGBE_AN_ERROR; |
| 958 | |
Lendacky, Thomas | c3152d4 | 2015-01-16 12:47:00 -0600 | [diff] [blame] | 959 | ret = amd_xgbe_phy_restart_an(phydev); |
| 960 | if (ret) |
| 961 | return AMD_XGBE_AN_ERROR; |
| 962 | |
| 963 | return AMD_XGBE_AN_INCOMPAT_LINK; |
| 964 | } |
| 965 | |
| 966 | static irqreturn_t amd_xgbe_an_isr(int irq, void *data) |
| 967 | { |
| 968 | struct amd_xgbe_phy_priv *priv = (struct amd_xgbe_phy_priv *)data; |
| 969 | |
| 970 | /* Interrupt reason must be read and cleared outside of IRQ context */ |
| 971 | disable_irq_nosync(priv->an_irq); |
| 972 | |
| 973 | queue_work(priv->an_workqueue, &priv->an_irq_work); |
| 974 | |
| 975 | return IRQ_HANDLED; |
| 976 | } |
| 977 | |
| 978 | static void amd_xgbe_an_irq_work(struct work_struct *work) |
| 979 | { |
| 980 | struct amd_xgbe_phy_priv *priv = container_of(work, |
| 981 | struct amd_xgbe_phy_priv, |
| 982 | an_irq_work); |
| 983 | |
| 984 | /* Avoid a race between enabling the IRQ and exiting the work by |
| 985 | * waiting for the work to finish and then queueing it |
| 986 | */ |
| 987 | flush_work(&priv->an_work); |
| 988 | queue_work(priv->an_workqueue, &priv->an_work); |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 989 | } |
| 990 | |
| 991 | static void amd_xgbe_an_state_machine(struct work_struct *work) |
| 992 | { |
| 993 | struct amd_xgbe_phy_priv *priv = container_of(work, |
| 994 | struct amd_xgbe_phy_priv, |
| 995 | an_work); |
| 996 | struct phy_device *phydev = priv->phydev; |
Lendacky, Thomas | c3152d4 | 2015-01-16 12:47:00 -0600 | [diff] [blame] | 997 | enum amd_xgbe_phy_an cur_state = priv->an_state; |
| 998 | int int_reg, int_mask; |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 999 | |
Lendacky, Thomas | c3152d4 | 2015-01-16 12:47:00 -0600 | [diff] [blame] | 1000 | mutex_lock(&priv->an_mutex); |
| 1001 | |
| 1002 | /* Read the interrupt */ |
| 1003 | int_reg = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_INT); |
| 1004 | if (!int_reg) |
| 1005 | goto out; |
| 1006 | |
| 1007 | next_int: |
| 1008 | if (int_reg < 0) { |
Lendacky, Thomas | e6f0562 | 2014-09-03 12:14:22 -0500 | [diff] [blame] | 1009 | priv->an_state = AMD_XGBE_AN_ERROR; |
Lendacky, Thomas | c3152d4 | 2015-01-16 12:47:00 -0600 | [diff] [blame] | 1010 | int_mask = XGBE_AN_INT_MASK; |
| 1011 | } else if (int_reg & XGBE_AN_PG_RCV) { |
| 1012 | priv->an_state = AMD_XGBE_AN_PAGE_RECEIVED; |
| 1013 | int_mask = XGBE_AN_PG_RCV; |
| 1014 | } else if (int_reg & XGBE_AN_INC_LINK) { |
| 1015 | priv->an_state = AMD_XGBE_AN_INCOMPAT_LINK; |
| 1016 | int_mask = XGBE_AN_INC_LINK; |
| 1017 | } else if (int_reg & XGBE_AN_INT_CMPLT) { |
| 1018 | priv->an_state = AMD_XGBE_AN_COMPLETE; |
| 1019 | int_mask = XGBE_AN_INT_CMPLT; |
| 1020 | } else { |
| 1021 | priv->an_state = AMD_XGBE_AN_ERROR; |
| 1022 | int_mask = 0; |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 1023 | } |
| 1024 | |
Lendacky, Thomas | c3152d4 | 2015-01-16 12:47:00 -0600 | [diff] [blame] | 1025 | /* Clear the interrupt to be processed */ |
| 1026 | int_reg &= ~int_mask; |
| 1027 | phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_AN_INT, int_reg); |
| 1028 | |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 1029 | priv->an_result = priv->an_state; |
Lendacky, Thomas | c3152d4 | 2015-01-16 12:47:00 -0600 | [diff] [blame] | 1030 | |
| 1031 | again: |
| 1032 | cur_state = priv->an_state; |
| 1033 | |
| 1034 | switch (priv->an_state) { |
| 1035 | case AMD_XGBE_AN_READY: |
| 1036 | priv->an_supported = 0; |
| 1037 | break; |
| 1038 | |
| 1039 | case AMD_XGBE_AN_PAGE_RECEIVED: |
| 1040 | priv->an_state = amd_xgbe_an_page_received(phydev); |
| 1041 | priv->an_supported++; |
| 1042 | break; |
| 1043 | |
| 1044 | case AMD_XGBE_AN_INCOMPAT_LINK: |
| 1045 | priv->an_supported = 0; |
| 1046 | priv->parallel_detect = 0; |
| 1047 | priv->an_state = amd_xgbe_an_incompat_link(phydev); |
| 1048 | break; |
| 1049 | |
| 1050 | case AMD_XGBE_AN_COMPLETE: |
| 1051 | priv->parallel_detect = priv->an_supported ? 0 : 1; |
| 1052 | netdev_dbg(phydev->attached_dev, "%s successful\n", |
| 1053 | priv->an_supported ? "Auto negotiation" |
| 1054 | : "Parallel detection"); |
| 1055 | break; |
| 1056 | |
| 1057 | case AMD_XGBE_AN_NO_LINK: |
| 1058 | break; |
| 1059 | |
| 1060 | default: |
| 1061 | priv->an_state = AMD_XGBE_AN_ERROR; |
| 1062 | } |
| 1063 | |
| 1064 | if (priv->an_state == AMD_XGBE_AN_NO_LINK) { |
| 1065 | int_reg = 0; |
| 1066 | phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_AN_INT, 0); |
| 1067 | } else if (priv->an_state == AMD_XGBE_AN_ERROR) { |
| 1068 | netdev_err(phydev->attached_dev, |
| 1069 | "error during auto-negotiation, state=%u\n", |
| 1070 | cur_state); |
| 1071 | |
| 1072 | int_reg = 0; |
| 1073 | phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_AN_INT, 0); |
| 1074 | } |
| 1075 | |
| 1076 | if (priv->an_state >= AMD_XGBE_AN_COMPLETE) { |
| 1077 | priv->an_result = priv->an_state; |
| 1078 | priv->an_state = AMD_XGBE_AN_READY; |
| 1079 | priv->kr_state = AMD_XGBE_RX_BPA; |
| 1080 | priv->kx_state = AMD_XGBE_RX_BPA; |
| 1081 | } |
| 1082 | |
| 1083 | if (cur_state != priv->an_state) |
| 1084 | goto again; |
| 1085 | |
| 1086 | if (int_reg) |
| 1087 | goto next_int; |
| 1088 | |
| 1089 | out: |
| 1090 | enable_irq(priv->an_irq); |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 1091 | |
| 1092 | mutex_unlock(&priv->an_mutex); |
| 1093 | } |
| 1094 | |
Lendacky, Thomas | c3152d4 | 2015-01-16 12:47:00 -0600 | [diff] [blame] | 1095 | static int amd_xgbe_an_init(struct phy_device *phydev) |
| 1096 | { |
| 1097 | int ret; |
| 1098 | |
| 1099 | /* Set up Advertisement register 3 first */ |
| 1100 | ret = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_ADVERTISE + 2); |
| 1101 | if (ret < 0) |
| 1102 | return ret; |
| 1103 | |
Lendacky, Thomas | d9663c8 | 2015-03-20 11:49:42 -0500 | [diff] [blame] | 1104 | if (phydev->advertising & SUPPORTED_10000baseR_FEC) |
Lendacky, Thomas | c3152d4 | 2015-01-16 12:47:00 -0600 | [diff] [blame] | 1105 | ret |= 0xc000; |
| 1106 | else |
| 1107 | ret &= ~0xc000; |
| 1108 | |
| 1109 | phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_AN_ADVERTISE + 2, ret); |
| 1110 | |
| 1111 | /* Set up Advertisement register 2 next */ |
| 1112 | ret = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_ADVERTISE + 1); |
| 1113 | if (ret < 0) |
| 1114 | return ret; |
| 1115 | |
Lendacky, Thomas | d9663c8 | 2015-03-20 11:49:42 -0500 | [diff] [blame] | 1116 | if (phydev->advertising & SUPPORTED_10000baseKR_Full) |
Lendacky, Thomas | c3152d4 | 2015-01-16 12:47:00 -0600 | [diff] [blame] | 1117 | ret |= 0x80; |
| 1118 | else |
| 1119 | ret &= ~0x80; |
| 1120 | |
Lendacky, Thomas | d9663c8 | 2015-03-20 11:49:42 -0500 | [diff] [blame] | 1121 | if ((phydev->advertising & SUPPORTED_1000baseKX_Full) || |
| 1122 | (phydev->advertising & SUPPORTED_2500baseX_Full)) |
Lendacky, Thomas | c3152d4 | 2015-01-16 12:47:00 -0600 | [diff] [blame] | 1123 | ret |= 0x20; |
| 1124 | else |
| 1125 | ret &= ~0x20; |
| 1126 | |
| 1127 | phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_AN_ADVERTISE + 1, ret); |
| 1128 | |
| 1129 | /* Set up Advertisement register 1 last */ |
| 1130 | ret = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_ADVERTISE); |
| 1131 | if (ret < 0) |
| 1132 | return ret; |
| 1133 | |
Lendacky, Thomas | d9663c8 | 2015-03-20 11:49:42 -0500 | [diff] [blame] | 1134 | if (phydev->advertising & SUPPORTED_Pause) |
Lendacky, Thomas | c3152d4 | 2015-01-16 12:47:00 -0600 | [diff] [blame] | 1135 | ret |= 0x400; |
| 1136 | else |
| 1137 | ret &= ~0x400; |
| 1138 | |
Lendacky, Thomas | d9663c8 | 2015-03-20 11:49:42 -0500 | [diff] [blame] | 1139 | if (phydev->advertising & SUPPORTED_Asym_Pause) |
Lendacky, Thomas | c3152d4 | 2015-01-16 12:47:00 -0600 | [diff] [blame] | 1140 | ret |= 0x800; |
| 1141 | else |
| 1142 | ret &= ~0x800; |
| 1143 | |
| 1144 | /* We don't intend to perform XNP */ |
| 1145 | ret &= ~XNP_NP_EXCHANGE; |
| 1146 | |
| 1147 | phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_AN_ADVERTISE, ret); |
| 1148 | |
| 1149 | return 0; |
| 1150 | } |
| 1151 | |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 1152 | static int amd_xgbe_phy_soft_reset(struct phy_device *phydev) |
| 1153 | { |
| 1154 | int count, ret; |
| 1155 | |
| 1156 | ret = phy_read_mmd(phydev, MDIO_MMD_PCS, MDIO_CTRL1); |
| 1157 | if (ret < 0) |
| 1158 | return ret; |
| 1159 | |
| 1160 | ret |= MDIO_CTRL1_RESET; |
| 1161 | phy_write_mmd(phydev, MDIO_MMD_PCS, MDIO_CTRL1, ret); |
| 1162 | |
| 1163 | count = 50; |
| 1164 | do { |
| 1165 | msleep(20); |
| 1166 | ret = phy_read_mmd(phydev, MDIO_MMD_PCS, MDIO_CTRL1); |
| 1167 | if (ret < 0) |
| 1168 | return ret; |
| 1169 | } while ((ret & MDIO_CTRL1_RESET) && --count); |
| 1170 | |
| 1171 | if (ret & MDIO_CTRL1_RESET) |
| 1172 | return -ETIMEDOUT; |
| 1173 | |
Lendacky, Thomas | c3152d4 | 2015-01-16 12:47:00 -0600 | [diff] [blame] | 1174 | /* Disable auto-negotiation for now */ |
| 1175 | ret = amd_xgbe_phy_disable_an(phydev); |
| 1176 | if (ret < 0) |
| 1177 | return ret; |
| 1178 | |
| 1179 | /* Clear auto-negotiation interrupts */ |
| 1180 | phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_AN_INT, 0); |
| 1181 | |
| 1182 | return 0; |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 1183 | } |
| 1184 | |
| 1185 | static int amd_xgbe_phy_config_init(struct phy_device *phydev) |
| 1186 | { |
Lendacky, Thomas | f047604 | 2014-07-29 08:57:25 -0500 | [diff] [blame] | 1187 | struct amd_xgbe_phy_priv *priv = phydev->priv; |
Lendacky, Thomas | c3152d4 | 2015-01-16 12:47:00 -0600 | [diff] [blame] | 1188 | struct net_device *netdev = phydev->attached_dev; |
| 1189 | int ret; |
| 1190 | |
| 1191 | if (!priv->an_irq_allocated) { |
| 1192 | /* Allocate the auto-negotiation workqueue and interrupt */ |
| 1193 | snprintf(priv->an_irq_name, sizeof(priv->an_irq_name) - 1, |
| 1194 | "%s-pcs", netdev_name(netdev)); |
| 1195 | |
| 1196 | priv->an_workqueue = |
| 1197 | create_singlethread_workqueue(priv->an_irq_name); |
| 1198 | if (!priv->an_workqueue) { |
| 1199 | netdev_err(netdev, "phy workqueue creation failed\n"); |
| 1200 | return -ENOMEM; |
| 1201 | } |
| 1202 | |
| 1203 | ret = devm_request_irq(priv->dev, priv->an_irq, |
| 1204 | amd_xgbe_an_isr, 0, priv->an_irq_name, |
| 1205 | priv); |
| 1206 | if (ret) { |
| 1207 | netdev_err(netdev, "phy irq request failed\n"); |
| 1208 | destroy_workqueue(priv->an_workqueue); |
| 1209 | return ret; |
| 1210 | } |
| 1211 | |
| 1212 | priv->an_irq_allocated = 1; |
| 1213 | } |
Lendacky, Thomas | f047604 | 2014-07-29 08:57:25 -0500 | [diff] [blame] | 1214 | |
Lendacky, Thomas | c3152d4 | 2015-01-16 12:47:00 -0600 | [diff] [blame] | 1215 | /* Set initial mode - call the mode setting routines |
| 1216 | * directly to insure we are properly configured |
| 1217 | */ |
Lendacky, Thomas | d9663c8 | 2015-03-20 11:49:42 -0500 | [diff] [blame] | 1218 | if (phydev->advertising & SUPPORTED_10000baseKR_Full) |
Lendacky, Thomas | c3152d4 | 2015-01-16 12:47:00 -0600 | [diff] [blame] | 1219 | ret = amd_xgbe_phy_xgmii_mode(phydev); |
Lendacky, Thomas | d9663c8 | 2015-03-20 11:49:42 -0500 | [diff] [blame] | 1220 | else if (phydev->advertising & SUPPORTED_1000baseKX_Full) |
Lendacky, Thomas | c3152d4 | 2015-01-16 12:47:00 -0600 | [diff] [blame] | 1221 | ret = amd_xgbe_phy_gmii_mode(phydev); |
Lendacky, Thomas | d9663c8 | 2015-03-20 11:49:42 -0500 | [diff] [blame] | 1222 | else if (phydev->advertising & SUPPORTED_2500baseX_Full) |
Lendacky, Thomas | c3152d4 | 2015-01-16 12:47:00 -0600 | [diff] [blame] | 1223 | ret = amd_xgbe_phy_gmii_2500_mode(phydev); |
| 1224 | else |
| 1225 | ret = -EINVAL; |
| 1226 | if (ret < 0) |
| 1227 | return ret; |
| 1228 | |
| 1229 | /* Set up advertisement registers based on current settings */ |
| 1230 | ret = amd_xgbe_an_init(phydev); |
| 1231 | if (ret) |
| 1232 | return ret; |
| 1233 | |
| 1234 | /* Enable auto-negotiation interrupts */ |
| 1235 | phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_AN_INTMASK, 0x07); |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 1236 | |
| 1237 | return 0; |
| 1238 | } |
| 1239 | |
| 1240 | static int amd_xgbe_phy_setup_forced(struct phy_device *phydev) |
| 1241 | { |
| 1242 | int ret; |
| 1243 | |
| 1244 | /* Disable auto-negotiation */ |
Lendacky, Thomas | c3152d4 | 2015-01-16 12:47:00 -0600 | [diff] [blame] | 1245 | ret = amd_xgbe_phy_disable_an(phydev); |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 1246 | if (ret < 0) |
| 1247 | return ret; |
| 1248 | |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 1249 | /* Validate/Set specified speed */ |
| 1250 | switch (phydev->speed) { |
| 1251 | case SPEED_10000: |
Lendacky, Thomas | c3152d4 | 2015-01-16 12:47:00 -0600 | [diff] [blame] | 1252 | ret = amd_xgbe_phy_set_mode(phydev, AMD_XGBE_MODE_KR); |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 1253 | break; |
| 1254 | |
| 1255 | case SPEED_2500: |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 1256 | case SPEED_1000: |
Lendacky, Thomas | c3152d4 | 2015-01-16 12:47:00 -0600 | [diff] [blame] | 1257 | ret = amd_xgbe_phy_set_mode(phydev, AMD_XGBE_MODE_KX); |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 1258 | break; |
| 1259 | |
| 1260 | default: |
| 1261 | ret = -EINVAL; |
| 1262 | } |
| 1263 | |
| 1264 | if (ret < 0) |
| 1265 | return ret; |
| 1266 | |
| 1267 | /* Validate duplex mode */ |
| 1268 | if (phydev->duplex != DUPLEX_FULL) |
| 1269 | return -EINVAL; |
| 1270 | |
| 1271 | phydev->pause = 0; |
| 1272 | phydev->asym_pause = 0; |
| 1273 | |
| 1274 | return 0; |
| 1275 | } |
| 1276 | |
Lendacky, Thomas | c3152d4 | 2015-01-16 12:47:00 -0600 | [diff] [blame] | 1277 | static int __amd_xgbe_phy_config_aneg(struct phy_device *phydev) |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 1278 | { |
| 1279 | struct amd_xgbe_phy_priv *priv = phydev->priv; |
| 1280 | u32 mmd_mask = phydev->c45_ids.devices_in_package; |
Lendacky, Thomas | c3152d4 | 2015-01-16 12:47:00 -0600 | [diff] [blame] | 1281 | int ret; |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 1282 | |
| 1283 | if (phydev->autoneg != AUTONEG_ENABLE) |
| 1284 | return amd_xgbe_phy_setup_forced(phydev); |
| 1285 | |
| 1286 | /* Make sure we have the AN MMD present */ |
| 1287 | if (!(mmd_mask & MDIO_DEVS_AN)) |
| 1288 | return -EINVAL; |
| 1289 | |
Lendacky, Thomas | c3152d4 | 2015-01-16 12:47:00 -0600 | [diff] [blame] | 1290 | /* Disable auto-negotiation interrupt */ |
| 1291 | disable_irq(priv->an_irq); |
| 1292 | |
| 1293 | /* Start auto-negotiation in a supported mode */ |
Lendacky, Thomas | d9663c8 | 2015-03-20 11:49:42 -0500 | [diff] [blame] | 1294 | if (phydev->advertising & SUPPORTED_10000baseKR_Full) |
Lendacky, Thomas | c3152d4 | 2015-01-16 12:47:00 -0600 | [diff] [blame] | 1295 | ret = amd_xgbe_phy_set_mode(phydev, AMD_XGBE_MODE_KR); |
Lendacky, Thomas | d9663c8 | 2015-03-20 11:49:42 -0500 | [diff] [blame] | 1296 | else if ((phydev->advertising & SUPPORTED_1000baseKX_Full) || |
| 1297 | (phydev->advertising & SUPPORTED_2500baseX_Full)) |
Lendacky, Thomas | c3152d4 | 2015-01-16 12:47:00 -0600 | [diff] [blame] | 1298 | ret = amd_xgbe_phy_set_mode(phydev, AMD_XGBE_MODE_KX); |
| 1299 | else |
| 1300 | ret = -EINVAL; |
| 1301 | if (ret < 0) { |
| 1302 | enable_irq(priv->an_irq); |
| 1303 | return ret; |
| 1304 | } |
| 1305 | |
| 1306 | /* Disable and stop any in progress auto-negotiation */ |
| 1307 | ret = amd_xgbe_phy_disable_an(phydev); |
| 1308 | if (ret < 0) |
| 1309 | return ret; |
| 1310 | |
| 1311 | /* Clear any auto-negotitation interrupts */ |
| 1312 | phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_AN_INT, 0); |
| 1313 | |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 1314 | priv->an_result = AMD_XGBE_AN_READY; |
Lendacky, Thomas | c3152d4 | 2015-01-16 12:47:00 -0600 | [diff] [blame] | 1315 | priv->an_state = AMD_XGBE_AN_READY; |
| 1316 | priv->kr_state = AMD_XGBE_RX_BPA; |
| 1317 | priv->kx_state = AMD_XGBE_RX_BPA; |
| 1318 | |
| 1319 | /* Re-enable auto-negotiation interrupt */ |
| 1320 | enable_irq(priv->an_irq); |
| 1321 | |
| 1322 | /* Set up advertisement registers based on current settings */ |
| 1323 | ret = amd_xgbe_an_init(phydev); |
| 1324 | if (ret) |
| 1325 | return ret; |
| 1326 | |
| 1327 | /* Enable and start auto-negotiation */ |
| 1328 | return amd_xgbe_phy_restart_an(phydev); |
| 1329 | } |
| 1330 | |
| 1331 | static int amd_xgbe_phy_config_aneg(struct phy_device *phydev) |
| 1332 | { |
| 1333 | struct amd_xgbe_phy_priv *priv = phydev->priv; |
| 1334 | int ret; |
| 1335 | |
| 1336 | mutex_lock(&priv->an_mutex); |
| 1337 | |
| 1338 | ret = __amd_xgbe_phy_config_aneg(phydev); |
| 1339 | |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 1340 | mutex_unlock(&priv->an_mutex); |
| 1341 | |
Lendacky, Thomas | c3152d4 | 2015-01-16 12:47:00 -0600 | [diff] [blame] | 1342 | return ret; |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 1343 | } |
| 1344 | |
| 1345 | static int amd_xgbe_phy_aneg_done(struct phy_device *phydev) |
| 1346 | { |
| 1347 | struct amd_xgbe_phy_priv *priv = phydev->priv; |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 1348 | |
Lendacky, Thomas | c3152d4 | 2015-01-16 12:47:00 -0600 | [diff] [blame] | 1349 | return (priv->an_result == AMD_XGBE_AN_COMPLETE); |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 1350 | } |
| 1351 | |
| 1352 | static int amd_xgbe_phy_update_link(struct phy_device *phydev) |
| 1353 | { |
| 1354 | struct amd_xgbe_phy_priv *priv = phydev->priv; |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 1355 | int ret; |
| 1356 | |
| 1357 | /* If we're doing auto-negotiation don't report link down */ |
Lendacky, Thomas | c3152d4 | 2015-01-16 12:47:00 -0600 | [diff] [blame] | 1358 | if (priv->an_state != AMD_XGBE_AN_READY) { |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 1359 | phydev->link = 1; |
| 1360 | return 0; |
| 1361 | } |
| 1362 | |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 1363 | /* Link status is latched low, so read once to clear |
| 1364 | * and then read again to get current state |
| 1365 | */ |
| 1366 | ret = phy_read_mmd(phydev, MDIO_MMD_PCS, MDIO_STAT1); |
| 1367 | if (ret < 0) |
| 1368 | return ret; |
| 1369 | |
| 1370 | ret = phy_read_mmd(phydev, MDIO_MMD_PCS, MDIO_STAT1); |
| 1371 | if (ret < 0) |
| 1372 | return ret; |
| 1373 | |
| 1374 | phydev->link = (ret & MDIO_STAT1_LSTATUS) ? 1 : 0; |
| 1375 | |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 1376 | return 0; |
| 1377 | } |
| 1378 | |
| 1379 | static int amd_xgbe_phy_read_status(struct phy_device *phydev) |
| 1380 | { |
Lendacky, Thomas | f047604 | 2014-07-29 08:57:25 -0500 | [diff] [blame] | 1381 | struct amd_xgbe_phy_priv *priv = phydev->priv; |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 1382 | u32 mmd_mask = phydev->c45_ids.devices_in_package; |
Lendacky, Thomas | e3eec4e | 2014-09-03 12:14:16 -0500 | [diff] [blame] | 1383 | int ret, ad_ret, lp_ret; |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 1384 | |
| 1385 | ret = amd_xgbe_phy_update_link(phydev); |
| 1386 | if (ret) |
| 1387 | return ret; |
| 1388 | |
Lendacky, Thomas | e6f0562 | 2014-09-03 12:14:22 -0500 | [diff] [blame] | 1389 | if ((phydev->autoneg == AUTONEG_ENABLE) && |
| 1390 | !priv->parallel_detect) { |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 1391 | if (!(mmd_mask & MDIO_DEVS_AN)) |
| 1392 | return -EINVAL; |
| 1393 | |
| 1394 | if (!amd_xgbe_phy_aneg_done(phydev)) |
| 1395 | return 0; |
| 1396 | |
| 1397 | /* Compare Advertisement and Link Partner register 1 */ |
| 1398 | ad_ret = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_ADVERTISE); |
| 1399 | if (ad_ret < 0) |
| 1400 | return ad_ret; |
| 1401 | lp_ret = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_LPA); |
| 1402 | if (lp_ret < 0) |
| 1403 | return lp_ret; |
| 1404 | |
| 1405 | ad_ret &= lp_ret; |
| 1406 | phydev->pause = (ad_ret & 0x400) ? 1 : 0; |
| 1407 | phydev->asym_pause = (ad_ret & 0x800) ? 1 : 0; |
| 1408 | |
| 1409 | /* Compare Advertisement and Link Partner register 2 */ |
| 1410 | ad_ret = phy_read_mmd(phydev, MDIO_MMD_AN, |
| 1411 | MDIO_AN_ADVERTISE + 1); |
| 1412 | if (ad_ret < 0) |
| 1413 | return ad_ret; |
| 1414 | lp_ret = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_LPA + 1); |
| 1415 | if (lp_ret < 0) |
| 1416 | return lp_ret; |
| 1417 | |
| 1418 | ad_ret &= lp_ret; |
| 1419 | if (ad_ret & 0x80) { |
| 1420 | phydev->speed = SPEED_10000; |
Lendacky, Thomas | e3eec4e | 2014-09-03 12:14:16 -0500 | [diff] [blame] | 1421 | ret = amd_xgbe_phy_set_mode(phydev, AMD_XGBE_MODE_KR); |
| 1422 | if (ret) |
| 1423 | return ret; |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 1424 | } else { |
Lendacky, Thomas | e3eec4e | 2014-09-03 12:14:16 -0500 | [diff] [blame] | 1425 | switch (priv->speed_set) { |
| 1426 | case AMD_XGBE_PHY_SPEEDSET_1000_10000: |
Lendacky, Thomas | f047604 | 2014-07-29 08:57:25 -0500 | [diff] [blame] | 1427 | phydev->speed = SPEED_1000; |
Lendacky, Thomas | e3eec4e | 2014-09-03 12:14:16 -0500 | [diff] [blame] | 1428 | break; |
| 1429 | |
| 1430 | case AMD_XGBE_PHY_SPEEDSET_2500_10000: |
Lendacky, Thomas | f047604 | 2014-07-29 08:57:25 -0500 | [diff] [blame] | 1431 | phydev->speed = SPEED_2500; |
Lendacky, Thomas | e3eec4e | 2014-09-03 12:14:16 -0500 | [diff] [blame] | 1432 | break; |
Lendacky, Thomas | f047604 | 2014-07-29 08:57:25 -0500 | [diff] [blame] | 1433 | } |
| 1434 | |
Lendacky, Thomas | e3eec4e | 2014-09-03 12:14:16 -0500 | [diff] [blame] | 1435 | ret = amd_xgbe_phy_set_mode(phydev, AMD_XGBE_MODE_KX); |
| 1436 | if (ret) |
| 1437 | return ret; |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 1438 | } |
| 1439 | |
| 1440 | phydev->duplex = DUPLEX_FULL; |
| 1441 | } else { |
Lendacky, Thomas | e3eec4e | 2014-09-03 12:14:16 -0500 | [diff] [blame] | 1442 | if (amd_xgbe_phy_in_kr_mode(phydev)) { |
Lendacky, Thomas | f047604 | 2014-07-29 08:57:25 -0500 | [diff] [blame] | 1443 | phydev->speed = SPEED_10000; |
| 1444 | } else { |
Lendacky, Thomas | e3eec4e | 2014-09-03 12:14:16 -0500 | [diff] [blame] | 1445 | switch (priv->speed_set) { |
| 1446 | case AMD_XGBE_PHY_SPEEDSET_1000_10000: |
Lendacky, Thomas | f047604 | 2014-07-29 08:57:25 -0500 | [diff] [blame] | 1447 | phydev->speed = SPEED_1000; |
Lendacky, Thomas | e3eec4e | 2014-09-03 12:14:16 -0500 | [diff] [blame] | 1448 | break; |
| 1449 | |
| 1450 | case AMD_XGBE_PHY_SPEEDSET_2500_10000: |
Lendacky, Thomas | f047604 | 2014-07-29 08:57:25 -0500 | [diff] [blame] | 1451 | phydev->speed = SPEED_2500; |
Lendacky, Thomas | e3eec4e | 2014-09-03 12:14:16 -0500 | [diff] [blame] | 1452 | break; |
| 1453 | } |
Lendacky, Thomas | f047604 | 2014-07-29 08:57:25 -0500 | [diff] [blame] | 1454 | } |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 1455 | phydev->duplex = DUPLEX_FULL; |
| 1456 | phydev->pause = 0; |
| 1457 | phydev->asym_pause = 0; |
| 1458 | } |
| 1459 | |
| 1460 | return 0; |
| 1461 | } |
| 1462 | |
| 1463 | static int amd_xgbe_phy_suspend(struct phy_device *phydev) |
| 1464 | { |
Lendacky, Thomas | 03e50fd | 2015-01-16 12:46:39 -0600 | [diff] [blame] | 1465 | struct amd_xgbe_phy_priv *priv = phydev->priv; |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 1466 | int ret; |
| 1467 | |
| 1468 | mutex_lock(&phydev->lock); |
| 1469 | |
| 1470 | ret = phy_read_mmd(phydev, MDIO_MMD_PCS, MDIO_CTRL1); |
| 1471 | if (ret < 0) |
| 1472 | goto unlock; |
| 1473 | |
Lendacky, Thomas | 03e50fd | 2015-01-16 12:46:39 -0600 | [diff] [blame] | 1474 | priv->lpm_ctrl = ret; |
| 1475 | |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 1476 | ret |= MDIO_CTRL1_LPOWER; |
| 1477 | phy_write_mmd(phydev, MDIO_MMD_PCS, MDIO_CTRL1, ret); |
| 1478 | |
| 1479 | ret = 0; |
| 1480 | |
| 1481 | unlock: |
| 1482 | mutex_unlock(&phydev->lock); |
| 1483 | |
| 1484 | return ret; |
| 1485 | } |
| 1486 | |
| 1487 | static int amd_xgbe_phy_resume(struct phy_device *phydev) |
| 1488 | { |
Lendacky, Thomas | 03e50fd | 2015-01-16 12:46:39 -0600 | [diff] [blame] | 1489 | struct amd_xgbe_phy_priv *priv = phydev->priv; |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 1490 | |
| 1491 | mutex_lock(&phydev->lock); |
| 1492 | |
Lendacky, Thomas | 03e50fd | 2015-01-16 12:46:39 -0600 | [diff] [blame] | 1493 | priv->lpm_ctrl &= ~MDIO_CTRL1_LPOWER; |
| 1494 | phy_write_mmd(phydev, MDIO_MMD_PCS, MDIO_CTRL1, priv->lpm_ctrl); |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 1495 | |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 1496 | mutex_unlock(&phydev->lock); |
| 1497 | |
Lendacky, Thomas | 03e50fd | 2015-01-16 12:46:39 -0600 | [diff] [blame] | 1498 | return 0; |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 1499 | } |
| 1500 | |
Lendacky, Thomas | 82a1903 | 2015-01-16 12:47:16 -0600 | [diff] [blame] | 1501 | static unsigned int amd_xgbe_phy_resource_count(struct platform_device *pdev, |
| 1502 | unsigned int type) |
| 1503 | { |
| 1504 | unsigned int count; |
| 1505 | int i; |
| 1506 | |
| 1507 | for (i = 0, count = 0; i < pdev->num_resources; i++) { |
| 1508 | struct resource *r = &pdev->resource[i]; |
| 1509 | |
| 1510 | if (type == resource_type(r)) |
| 1511 | count++; |
| 1512 | } |
| 1513 | |
| 1514 | return count; |
| 1515 | } |
| 1516 | |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 1517 | static int amd_xgbe_phy_probe(struct phy_device *phydev) |
| 1518 | { |
| 1519 | struct amd_xgbe_phy_priv *priv; |
Lendacky, Thomas | 82a1903 | 2015-01-16 12:47:16 -0600 | [diff] [blame] | 1520 | struct platform_device *phy_pdev; |
| 1521 | struct device *dev, *phy_dev; |
| 1522 | unsigned int phy_resnum, phy_irqnum; |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 1523 | int ret; |
| 1524 | |
Lendacky, Thomas | 82a1903 | 2015-01-16 12:47:16 -0600 | [diff] [blame] | 1525 | if (!phydev->bus || !phydev->bus->parent) |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 1526 | return -EINVAL; |
| 1527 | |
Lendacky, Thomas | 82a1903 | 2015-01-16 12:47:16 -0600 | [diff] [blame] | 1528 | dev = phydev->bus->parent; |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 1529 | |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 1530 | priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); |
Lendacky, Thomas | 82a1903 | 2015-01-16 12:47:16 -0600 | [diff] [blame] | 1531 | if (!priv) |
| 1532 | return -ENOMEM; |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 1533 | |
Lendacky, Thomas | 82a1903 | 2015-01-16 12:47:16 -0600 | [diff] [blame] | 1534 | priv->pdev = to_platform_device(dev); |
| 1535 | priv->adev = ACPI_COMPANION(dev); |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 1536 | priv->dev = dev; |
| 1537 | priv->phydev = phydev; |
Lendacky, Thomas | c3152d4 | 2015-01-16 12:47:00 -0600 | [diff] [blame] | 1538 | mutex_init(&priv->an_mutex); |
| 1539 | INIT_WORK(&priv->an_irq_work, amd_xgbe_an_irq_work); |
| 1540 | INIT_WORK(&priv->an_work, amd_xgbe_an_state_machine); |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 1541 | |
Lendacky, Thomas | 82a1903 | 2015-01-16 12:47:16 -0600 | [diff] [blame] | 1542 | if (!priv->adev || acpi_disabled) { |
| 1543 | struct device_node *bus_node; |
| 1544 | struct device_node *phy_node; |
| 1545 | |
| 1546 | bus_node = priv->dev->of_node; |
| 1547 | phy_node = of_parse_phandle(bus_node, "phy-handle", 0); |
| 1548 | if (!phy_node) { |
| 1549 | dev_err(dev, "unable to parse phy-handle\n"); |
| 1550 | ret = -EINVAL; |
| 1551 | goto err_priv; |
| 1552 | } |
| 1553 | |
| 1554 | phy_pdev = of_find_device_by_node(phy_node); |
| 1555 | of_node_put(phy_node); |
| 1556 | |
| 1557 | if (!phy_pdev) { |
| 1558 | dev_err(dev, "unable to obtain phy device\n"); |
| 1559 | ret = -EINVAL; |
| 1560 | goto err_priv; |
| 1561 | } |
| 1562 | |
| 1563 | phy_resnum = 0; |
| 1564 | phy_irqnum = 0; |
| 1565 | } else { |
| 1566 | /* In ACPI, the XGBE and PHY resources are the grouped |
| 1567 | * together with the PHY resources at the end |
| 1568 | */ |
| 1569 | phy_pdev = priv->pdev; |
| 1570 | phy_resnum = amd_xgbe_phy_resource_count(phy_pdev, |
| 1571 | IORESOURCE_MEM) - 3; |
| 1572 | phy_irqnum = amd_xgbe_phy_resource_count(phy_pdev, |
| 1573 | IORESOURCE_IRQ) - 1; |
| 1574 | } |
| 1575 | phy_dev = &phy_pdev->dev; |
| 1576 | |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 1577 | /* Get the device mmio areas */ |
Lendacky, Thomas | 82a1903 | 2015-01-16 12:47:16 -0600 | [diff] [blame] | 1578 | priv->rxtx_res = platform_get_resource(phy_pdev, IORESOURCE_MEM, |
| 1579 | phy_resnum++); |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 1580 | priv->rxtx_regs = devm_ioremap_resource(dev, priv->rxtx_res); |
| 1581 | if (IS_ERR(priv->rxtx_regs)) { |
| 1582 | dev_err(dev, "rxtx ioremap failed\n"); |
| 1583 | ret = PTR_ERR(priv->rxtx_regs); |
Lendacky, Thomas | 82a1903 | 2015-01-16 12:47:16 -0600 | [diff] [blame] | 1584 | goto err_put; |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 1585 | } |
| 1586 | |
Lendacky, Thomas | 82a1903 | 2015-01-16 12:47:16 -0600 | [diff] [blame] | 1587 | priv->sir0_res = platform_get_resource(phy_pdev, IORESOURCE_MEM, |
| 1588 | phy_resnum++); |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 1589 | priv->sir0_regs = devm_ioremap_resource(dev, priv->sir0_res); |
| 1590 | if (IS_ERR(priv->sir0_regs)) { |
| 1591 | dev_err(dev, "sir0 ioremap failed\n"); |
| 1592 | ret = PTR_ERR(priv->sir0_regs); |
| 1593 | goto err_rxtx; |
| 1594 | } |
| 1595 | |
Lendacky, Thomas | 82a1903 | 2015-01-16 12:47:16 -0600 | [diff] [blame] | 1596 | priv->sir1_res = platform_get_resource(phy_pdev, IORESOURCE_MEM, |
| 1597 | phy_resnum++); |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 1598 | priv->sir1_regs = devm_ioremap_resource(dev, priv->sir1_res); |
| 1599 | if (IS_ERR(priv->sir1_regs)) { |
| 1600 | dev_err(dev, "sir1 ioremap failed\n"); |
| 1601 | ret = PTR_ERR(priv->sir1_regs); |
| 1602 | goto err_sir0; |
| 1603 | } |
| 1604 | |
Lendacky, Thomas | c3152d4 | 2015-01-16 12:47:00 -0600 | [diff] [blame] | 1605 | /* Get the auto-negotiation interrupt */ |
Lendacky, Thomas | 82a1903 | 2015-01-16 12:47:16 -0600 | [diff] [blame] | 1606 | ret = platform_get_irq(phy_pdev, phy_irqnum); |
Lendacky, Thomas | c3152d4 | 2015-01-16 12:47:00 -0600 | [diff] [blame] | 1607 | if (ret < 0) { |
| 1608 | dev_err(dev, "platform_get_irq failed\n"); |
| 1609 | goto err_sir1; |
| 1610 | } |
| 1611 | priv->an_irq = ret; |
| 1612 | |
Lendacky, Thomas | f047604 | 2014-07-29 08:57:25 -0500 | [diff] [blame] | 1613 | /* Get the device speed set property */ |
Lendacky, Thomas | 82a1903 | 2015-01-16 12:47:16 -0600 | [diff] [blame] | 1614 | ret = device_property_read_u32(phy_dev, XGBE_PHY_SPEEDSET_PROPERTY, |
| 1615 | &priv->speed_set); |
| 1616 | if (ret) { |
| 1617 | dev_err(dev, "invalid %s property\n", |
| 1618 | XGBE_PHY_SPEEDSET_PROPERTY); |
| 1619 | goto err_sir1; |
| 1620 | } |
Lendacky, Thomas | f047604 | 2014-07-29 08:57:25 -0500 | [diff] [blame] | 1621 | |
Lendacky, Thomas | 82a1903 | 2015-01-16 12:47:16 -0600 | [diff] [blame] | 1622 | switch (priv->speed_set) { |
| 1623 | case AMD_XGBE_PHY_SPEEDSET_1000_10000: |
| 1624 | case AMD_XGBE_PHY_SPEEDSET_2500_10000: |
Lendacky, Thomas | f047604 | 2014-07-29 08:57:25 -0500 | [diff] [blame] | 1625 | break; |
| 1626 | default: |
Lendacky, Thomas | 82a1903 | 2015-01-16 12:47:16 -0600 | [diff] [blame] | 1627 | dev_err(dev, "invalid %s property\n", |
| 1628 | XGBE_PHY_SPEEDSET_PROPERTY); |
Lendacky, Thomas | f047604 | 2014-07-29 08:57:25 -0500 | [diff] [blame] | 1629 | ret = -EINVAL; |
| 1630 | goto err_sir1; |
| 1631 | } |
| 1632 | |
Lendacky, Thomas | 8fdb1a09 | 2015-01-16 12:47:21 -0600 | [diff] [blame] | 1633 | if (device_property_present(phy_dev, XGBE_PHY_BLWC_PROPERTY)) { |
| 1634 | ret = device_property_read_u32_array(phy_dev, |
| 1635 | XGBE_PHY_BLWC_PROPERTY, |
| 1636 | priv->serdes_blwc, |
| 1637 | XGBE_PHY_SPEEDS); |
| 1638 | if (ret) { |
| 1639 | dev_err(dev, "invalid %s property\n", |
| 1640 | XGBE_PHY_BLWC_PROPERTY); |
| 1641 | goto err_sir1; |
| 1642 | } |
| 1643 | } else { |
| 1644 | memcpy(priv->serdes_blwc, amd_xgbe_phy_serdes_blwc, |
| 1645 | sizeof(priv->serdes_blwc)); |
| 1646 | } |
| 1647 | |
| 1648 | if (device_property_present(phy_dev, XGBE_PHY_CDR_RATE_PROPERTY)) { |
| 1649 | ret = device_property_read_u32_array(phy_dev, |
| 1650 | XGBE_PHY_CDR_RATE_PROPERTY, |
| 1651 | priv->serdes_cdr_rate, |
| 1652 | XGBE_PHY_SPEEDS); |
| 1653 | if (ret) { |
| 1654 | dev_err(dev, "invalid %s property\n", |
| 1655 | XGBE_PHY_CDR_RATE_PROPERTY); |
| 1656 | goto err_sir1; |
| 1657 | } |
| 1658 | } else { |
| 1659 | memcpy(priv->serdes_cdr_rate, amd_xgbe_phy_serdes_cdr_rate, |
| 1660 | sizeof(priv->serdes_cdr_rate)); |
| 1661 | } |
| 1662 | |
| 1663 | if (device_property_present(phy_dev, XGBE_PHY_PQ_SKEW_PROPERTY)) { |
| 1664 | ret = device_property_read_u32_array(phy_dev, |
| 1665 | XGBE_PHY_PQ_SKEW_PROPERTY, |
| 1666 | priv->serdes_pq_skew, |
| 1667 | XGBE_PHY_SPEEDS); |
| 1668 | if (ret) { |
| 1669 | dev_err(dev, "invalid %s property\n", |
| 1670 | XGBE_PHY_PQ_SKEW_PROPERTY); |
| 1671 | goto err_sir1; |
| 1672 | } |
| 1673 | } else { |
| 1674 | memcpy(priv->serdes_pq_skew, amd_xgbe_phy_serdes_pq_skew, |
| 1675 | sizeof(priv->serdes_pq_skew)); |
| 1676 | } |
| 1677 | |
| 1678 | if (device_property_present(phy_dev, XGBE_PHY_TX_AMP_PROPERTY)) { |
| 1679 | ret = device_property_read_u32_array(phy_dev, |
| 1680 | XGBE_PHY_TX_AMP_PROPERTY, |
| 1681 | priv->serdes_tx_amp, |
| 1682 | XGBE_PHY_SPEEDS); |
| 1683 | if (ret) { |
| 1684 | dev_err(dev, "invalid %s property\n", |
| 1685 | XGBE_PHY_TX_AMP_PROPERTY); |
| 1686 | goto err_sir1; |
| 1687 | } |
| 1688 | } else { |
| 1689 | memcpy(priv->serdes_tx_amp, amd_xgbe_phy_serdes_tx_amp, |
| 1690 | sizeof(priv->serdes_tx_amp)); |
| 1691 | } |
| 1692 | |
Tom Lendacky | 74ad752 | 2015-02-24 10:47:49 -0600 | [diff] [blame] | 1693 | if (device_property_present(phy_dev, XGBE_PHY_DFE_CFG_PROPERTY)) { |
| 1694 | ret = device_property_read_u32_array(phy_dev, |
| 1695 | XGBE_PHY_DFE_CFG_PROPERTY, |
| 1696 | priv->serdes_dfe_tap_cfg, |
| 1697 | XGBE_PHY_SPEEDS); |
| 1698 | if (ret) { |
| 1699 | dev_err(dev, "invalid %s property\n", |
| 1700 | XGBE_PHY_DFE_CFG_PROPERTY); |
| 1701 | goto err_sir1; |
| 1702 | } |
| 1703 | } else { |
| 1704 | memcpy(priv->serdes_dfe_tap_cfg, |
| 1705 | amd_xgbe_phy_serdes_dfe_tap_cfg, |
| 1706 | sizeof(priv->serdes_dfe_tap_cfg)); |
| 1707 | } |
| 1708 | |
| 1709 | if (device_property_present(phy_dev, XGBE_PHY_DFE_ENA_PROPERTY)) { |
| 1710 | ret = device_property_read_u32_array(phy_dev, |
| 1711 | XGBE_PHY_DFE_ENA_PROPERTY, |
| 1712 | priv->serdes_dfe_tap_ena, |
| 1713 | XGBE_PHY_SPEEDS); |
| 1714 | if (ret) { |
| 1715 | dev_err(dev, "invalid %s property\n", |
| 1716 | XGBE_PHY_DFE_ENA_PROPERTY); |
| 1717 | goto err_sir1; |
| 1718 | } |
| 1719 | } else { |
| 1720 | memcpy(priv->serdes_dfe_tap_ena, |
| 1721 | amd_xgbe_phy_serdes_dfe_tap_ena, |
| 1722 | sizeof(priv->serdes_dfe_tap_ena)); |
| 1723 | } |
| 1724 | |
Lendacky, Thomas | d9663c8 | 2015-03-20 11:49:42 -0500 | [diff] [blame] | 1725 | /* Initialize supported features */ |
| 1726 | phydev->supported = SUPPORTED_Autoneg; |
| 1727 | phydev->supported |= SUPPORTED_Pause | SUPPORTED_Asym_Pause; |
| 1728 | phydev->supported |= SUPPORTED_Backplane; |
| 1729 | phydev->supported |= SUPPORTED_10000baseKR_Full; |
| 1730 | switch (priv->speed_set) { |
| 1731 | case AMD_XGBE_PHY_SPEEDSET_1000_10000: |
| 1732 | phydev->supported |= SUPPORTED_1000baseKX_Full; |
| 1733 | break; |
| 1734 | case AMD_XGBE_PHY_SPEEDSET_2500_10000: |
| 1735 | phydev->supported |= SUPPORTED_2500baseX_Full; |
| 1736 | break; |
| 1737 | } |
| 1738 | |
| 1739 | ret = phy_read_mmd(phydev, MDIO_MMD_PMAPMD, MDIO_PMA_10GBR_FEC_ABILITY); |
| 1740 | if (ret < 0) |
| 1741 | return ret; |
| 1742 | priv->fec_ability = ret & XGBE_PHY_FEC_MASK; |
| 1743 | if (priv->fec_ability & XGBE_PHY_FEC_ENABLE) |
| 1744 | phydev->supported |= SUPPORTED_10000baseR_FEC; |
| 1745 | |
| 1746 | phydev->advertising = phydev->supported; |
| 1747 | |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 1748 | phydev->priv = priv; |
| 1749 | |
Lendacky, Thomas | 82a1903 | 2015-01-16 12:47:16 -0600 | [diff] [blame] | 1750 | if (!priv->adev || acpi_disabled) |
| 1751 | platform_device_put(phy_pdev); |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 1752 | |
| 1753 | return 0; |
| 1754 | |
| 1755 | err_sir1: |
| 1756 | devm_iounmap(dev, priv->sir1_regs); |
| 1757 | devm_release_mem_region(dev, priv->sir1_res->start, |
| 1758 | resource_size(priv->sir1_res)); |
| 1759 | |
| 1760 | err_sir0: |
| 1761 | devm_iounmap(dev, priv->sir0_regs); |
| 1762 | devm_release_mem_region(dev, priv->sir0_res->start, |
| 1763 | resource_size(priv->sir0_res)); |
| 1764 | |
| 1765 | err_rxtx: |
| 1766 | devm_iounmap(dev, priv->rxtx_regs); |
| 1767 | devm_release_mem_region(dev, priv->rxtx_res->start, |
| 1768 | resource_size(priv->rxtx_res)); |
| 1769 | |
Lendacky, Thomas | 82a1903 | 2015-01-16 12:47:16 -0600 | [diff] [blame] | 1770 | err_put: |
| 1771 | if (!priv->adev || acpi_disabled) |
| 1772 | platform_device_put(phy_pdev); |
| 1773 | |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 1774 | err_priv: |
| 1775 | devm_kfree(dev, priv); |
| 1776 | |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 1777 | return ret; |
| 1778 | } |
| 1779 | |
| 1780 | static void amd_xgbe_phy_remove(struct phy_device *phydev) |
| 1781 | { |
| 1782 | struct amd_xgbe_phy_priv *priv = phydev->priv; |
| 1783 | struct device *dev = priv->dev; |
| 1784 | |
Lendacky, Thomas | c3152d4 | 2015-01-16 12:47:00 -0600 | [diff] [blame] | 1785 | if (priv->an_irq_allocated) { |
| 1786 | devm_free_irq(dev, priv->an_irq, priv); |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 1787 | |
Lendacky, Thomas | c3152d4 | 2015-01-16 12:47:00 -0600 | [diff] [blame] | 1788 | flush_workqueue(priv->an_workqueue); |
| 1789 | destroy_workqueue(priv->an_workqueue); |
| 1790 | } |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 1791 | |
| 1792 | /* Release resources */ |
| 1793 | devm_iounmap(dev, priv->sir1_regs); |
| 1794 | devm_release_mem_region(dev, priv->sir1_res->start, |
| 1795 | resource_size(priv->sir1_res)); |
| 1796 | |
| 1797 | devm_iounmap(dev, priv->sir0_regs); |
| 1798 | devm_release_mem_region(dev, priv->sir0_res->start, |
| 1799 | resource_size(priv->sir0_res)); |
| 1800 | |
| 1801 | devm_iounmap(dev, priv->rxtx_regs); |
| 1802 | devm_release_mem_region(dev, priv->rxtx_res->start, |
| 1803 | resource_size(priv->rxtx_res)); |
| 1804 | |
| 1805 | devm_kfree(dev, priv); |
| 1806 | } |
| 1807 | |
| 1808 | static int amd_xgbe_match_phy_device(struct phy_device *phydev) |
| 1809 | { |
| 1810 | return phydev->c45_ids.device_ids[MDIO_MMD_PCS] == XGBE_PHY_ID; |
| 1811 | } |
| 1812 | |
| 1813 | static struct phy_driver amd_xgbe_phy_driver[] = { |
| 1814 | { |
| 1815 | .phy_id = XGBE_PHY_ID, |
| 1816 | .phy_id_mask = XGBE_PHY_MASK, |
| 1817 | .name = "AMD XGBE PHY", |
| 1818 | .features = 0, |
Lendacky, Thomas | 65f57cb | 2015-03-20 11:49:53 -0500 | [diff] [blame^] | 1819 | .flags = PHY_IS_INTERNAL, |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 1820 | .probe = amd_xgbe_phy_probe, |
| 1821 | .remove = amd_xgbe_phy_remove, |
| 1822 | .soft_reset = amd_xgbe_phy_soft_reset, |
| 1823 | .config_init = amd_xgbe_phy_config_init, |
| 1824 | .suspend = amd_xgbe_phy_suspend, |
| 1825 | .resume = amd_xgbe_phy_resume, |
| 1826 | .config_aneg = amd_xgbe_phy_config_aneg, |
| 1827 | .aneg_done = amd_xgbe_phy_aneg_done, |
| 1828 | .read_status = amd_xgbe_phy_read_status, |
| 1829 | .match_phy_device = amd_xgbe_match_phy_device, |
| 1830 | .driver = { |
| 1831 | .owner = THIS_MODULE, |
| 1832 | }, |
| 1833 | }, |
| 1834 | }; |
| 1835 | |
Johan Hovold | 50fd715 | 2014-11-11 19:45:59 +0100 | [diff] [blame] | 1836 | module_phy_driver(amd_xgbe_phy_driver); |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 1837 | |
françois romieu | a25aafa | 2014-06-07 11:07:48 +0200 | [diff] [blame] | 1838 | static struct mdio_device_id __maybe_unused amd_xgbe_phy_ids[] = { |
Lendacky, Thomas | 4d874b3 | 2014-06-05 09:15:12 -0500 | [diff] [blame] | 1839 | { XGBE_PHY_ID, XGBE_PHY_MASK }, |
| 1840 | { } |
| 1841 | }; |
| 1842 | MODULE_DEVICE_TABLE(mdio, amd_xgbe_phy_ids); |