1 // SPDX-License-Identifier: GPL-2.0+ 2 /* 3 * drivers/net/phy/marvell.c 4 * 5 * Driver for Marvell PHYs 6 * 7 * Author: Andy Fleming 8 * 9 * Copyright (c) 2004 Freescale Semiconductor, Inc. 10 * 11 * Copyright (c) 2013 Michael Stapelberg <michael@stapelberg.de> 12 */ 13 #include <linux/kernel.h> 14 #include <linux/string.h> 15 #include <linux/ctype.h> 16 #include <linux/errno.h> 17 #include <linux/unistd.h> 18 #include <linux/hwmon.h> 19 #include <linux/interrupt.h> 20 #include <linux/init.h> 21 #include <linux/delay.h> 22 #include <linux/netdevice.h> 23 #include <linux/etherdevice.h> 24 #include <linux/skbuff.h> 25 #include <linux/spinlock.h> 26 #include <linux/mm.h> 27 #include <linux/module.h> 28 #include <linux/mii.h> 29 #include <linux/ethtool.h> 30 #include <linux/ethtool_netlink.h> 31 #include <linux/phy.h> 32 #include <linux/marvell_phy.h> 33 #include <linux/bitfield.h> 34 #include <linux/of.h> 35 #include <linux/sfp.h> 36 37 #include <linux/io.h> 38 #include <asm/irq.h> 39 #include <linux/uaccess.h> 40 41 #define MII_MARVELL_PHY_PAGE 22 42 #define MII_MARVELL_COPPER_PAGE 0x00 43 #define MII_MARVELL_FIBER_PAGE 0x01 44 #define MII_MARVELL_MSCR_PAGE 0x02 45 #define MII_MARVELL_LED_PAGE 0x03 46 #define MII_MARVELL_VCT5_PAGE 0x05 47 #define MII_MARVELL_MISC_TEST_PAGE 0x06 48 #define MII_MARVELL_VCT7_PAGE 0x07 49 #define MII_MARVELL_WOL_PAGE 0x11 50 #define MII_MARVELL_MODE_PAGE 0x12 51 52 #define MII_M1011_IEVENT 0x13 53 #define MII_M1011_IEVENT_CLEAR 0x0000 54 55 #define MII_M1011_IMASK 0x12 56 #define MII_M1011_IMASK_INIT 0x6400 57 #define MII_M1011_IMASK_CLEAR 0x0000 58 59 #define MII_M1011_PHY_SCR 0x10 60 #define MII_M1011_PHY_SCR_DOWNSHIFT_EN BIT(11) 61 #define MII_M1011_PHY_SCR_DOWNSHIFT_MASK GENMASK(14, 12) 62 #define MII_M1011_PHY_SCR_DOWNSHIFT_MAX 8 63 #define MII_M1011_PHY_SCR_MDI (0x0 << 5) 64 #define MII_M1011_PHY_SCR_MDI_X (0x1 << 5) 65 #define MII_M1011_PHY_SCR_AUTO_CROSS (0x3 << 5) 66 67 #define MII_M1011_PHY_SSR 0x11 68 #define MII_M1011_PHY_SSR_DOWNSHIFT BIT(5) 69 70 #define MII_M1111_PHY_LED_CONTROL 0x18 71 #define MII_M1111_PHY_LED_DIRECT 0x4100 72 #define MII_M1111_PHY_LED_COMBINE 0x411c 73 #define MII_M1111_PHY_EXT_CR 0x14 74 #define MII_M1111_PHY_EXT_CR_DOWNSHIFT_MASK GENMASK(11, 9) 75 #define MII_M1111_PHY_EXT_CR_DOWNSHIFT_MAX 8 76 #define MII_M1111_PHY_EXT_CR_DOWNSHIFT_EN BIT(8) 77 #define MII_M1111_RGMII_RX_DELAY BIT(7) 78 #define MII_M1111_RGMII_TX_DELAY BIT(1) 79 #define MII_M1111_PHY_EXT_SR 0x1b 80 81 #define MII_M1111_HWCFG_MODE_MASK 0xf 82 #define MII_M1111_HWCFG_MODE_FIBER_RGMII 0x3 83 #define MII_M1111_HWCFG_MODE_SGMII_NO_CLK 0x4 84 #define MII_M1111_HWCFG_MODE_RTBI 0x7 85 #define MII_M1111_HWCFG_MODE_COPPER_1000X_AN 0x8 86 #define MII_M1111_HWCFG_MODE_COPPER_RTBI 0x9 87 #define MII_M1111_HWCFG_MODE_COPPER_RGMII 0xb 88 #define MII_M1111_HWCFG_MODE_COPPER_1000X_NOAN 0xc 89 #define MII_M1111_HWCFG_SERIAL_AN_BYPASS BIT(12) 90 #define MII_M1111_HWCFG_FIBER_COPPER_RES BIT(13) 91 #define MII_M1111_HWCFG_FIBER_COPPER_AUTO BIT(15) 92 93 #define MII_88E1121_PHY_MSCR_REG 21 94 #define MII_88E1121_PHY_MSCR_RX_DELAY BIT(5) 95 #define MII_88E1121_PHY_MSCR_TX_DELAY BIT(4) 96 #define MII_88E1121_PHY_MSCR_DELAY_MASK (BIT(5) | BIT(4)) 97 98 #define MII_88E1121_MISC_TEST 0x1a 99 #define MII_88E1510_MISC_TEST_TEMP_THRESHOLD_MASK 0x1f00 100 #define MII_88E1510_MISC_TEST_TEMP_THRESHOLD_SHIFT 8 101 #define MII_88E1510_MISC_TEST_TEMP_IRQ_EN BIT(7) 102 #define MII_88E1510_MISC_TEST_TEMP_IRQ BIT(6) 103 #define MII_88E1121_MISC_TEST_TEMP_SENSOR_EN BIT(5) 104 #define MII_88E1121_MISC_TEST_TEMP_MASK 0x1f 105 106 #define MII_88E1510_TEMP_SENSOR 0x1b 107 #define MII_88E1510_TEMP_SENSOR_MASK 0xff 108 109 #define MII_88E1540_COPPER_CTRL3 0x1a 110 #define MII_88E1540_COPPER_CTRL3_LINK_DOWN_DELAY_MASK GENMASK(11, 10) 111 #define MII_88E1540_COPPER_CTRL3_LINK_DOWN_DELAY_00MS 0 112 #define MII_88E1540_COPPER_CTRL3_LINK_DOWN_DELAY_10MS 1 113 #define MII_88E1540_COPPER_CTRL3_LINK_DOWN_DELAY_20MS 2 114 #define MII_88E1540_COPPER_CTRL3_LINK_DOWN_DELAY_40MS 3 115 #define MII_88E1540_COPPER_CTRL3_FAST_LINK_DOWN BIT(9) 116 117 #define MII_88E6390_MISC_TEST 0x1b 118 #define MII_88E6390_MISC_TEST_TEMP_SENSOR_ENABLE_SAMPLE_1S (0x0 << 14) 119 #define MII_88E6390_MISC_TEST_TEMP_SENSOR_ENABLE (0x1 << 14) 120 #define MII_88E6390_MISC_TEST_TEMP_SENSOR_ENABLE_ONESHOT (0x2 << 14) 121 #define MII_88E6390_MISC_TEST_TEMP_SENSOR_DISABLE (0x3 << 14) 122 #define MII_88E6390_MISC_TEST_TEMP_SENSOR_MASK (0x3 << 14) 123 #define MII_88E6393_MISC_TEST_SAMPLES_2048 (0x0 << 11) 124 #define MII_88E6393_MISC_TEST_SAMPLES_4096 (0x1 << 11) 125 #define MII_88E6393_MISC_TEST_SAMPLES_8192 (0x2 << 11) 126 #define MII_88E6393_MISC_TEST_SAMPLES_16384 (0x3 << 11) 127 #define MII_88E6393_MISC_TEST_SAMPLES_MASK (0x3 << 11) 128 #define MII_88E6393_MISC_TEST_RATE_2_3MS (0x5 << 8) 129 #define MII_88E6393_MISC_TEST_RATE_6_4MS (0x6 << 8) 130 #define MII_88E6393_MISC_TEST_RATE_11_9MS (0x7 << 8) 131 #define MII_88E6393_MISC_TEST_RATE_MASK (0x7 << 8) 132 133 #define MII_88E6390_TEMP_SENSOR 0x1c 134 #define MII_88E6393_TEMP_SENSOR_THRESHOLD_MASK 0xff00 135 #define MII_88E6393_TEMP_SENSOR_THRESHOLD_SHIFT 8 136 #define MII_88E6390_TEMP_SENSOR_MASK 0xff 137 #define MII_88E6390_TEMP_SENSOR_SAMPLES 10 138 139 #define MII_88E1318S_PHY_MSCR1_REG 16 140 #define MII_88E1318S_PHY_MSCR1_PAD_ODD BIT(6) 141 142 /* Copper Specific Interrupt Enable Register */ 143 #define MII_88E1318S_PHY_CSIER 0x12 144 /* WOL Event Interrupt Enable */ 145 #define MII_88E1318S_PHY_CSIER_WOL_EIE BIT(7) 146 147 #define MII_88E1318S_PHY_LED_FUNC 0x10 148 #define MII_88E1318S_PHY_LED_FUNC_OFF (0x8) 149 #define MII_88E1318S_PHY_LED_FUNC_ON (0x9) 150 #define MII_88E1318S_PHY_LED_FUNC_HI_Z (0xa) 151 #define MII_88E1318S_PHY_LED_FUNC_BLINK (0xb) 152 #define MII_88E1318S_PHY_LED_TCR 0x12 153 #define MII_88E1318S_PHY_LED_TCR_FORCE_INT BIT(15) 154 #define MII_88E1318S_PHY_LED_TCR_INTn_ENABLE BIT(7) 155 #define MII_88E1318S_PHY_LED_TCR_INT_ACTIVE_LOW BIT(11) 156 157 /* Magic Packet MAC address registers */ 158 #define MII_88E1318S_PHY_MAGIC_PACKET_WORD2 0x17 159 #define MII_88E1318S_PHY_MAGIC_PACKET_WORD1 0x18 160 #define MII_88E1318S_PHY_MAGIC_PACKET_WORD0 0x19 161 162 #define MII_88E1318S_PHY_WOL_CTRL 0x10 163 #define MII_88E1318S_PHY_WOL_CTRL_CLEAR_WOL_STATUS BIT(12) 164 #define MII_88E1318S_PHY_WOL_CTRL_LINK_UP_ENABLE BIT(13) 165 #define MII_88E1318S_PHY_WOL_CTRL_MAGIC_PACKET_MATCH_ENABLE BIT(14) 166 167 #define MII_PHY_LED_CTRL 16 168 #define MII_88E1121_PHY_LED_DEF 0x0030 169 #define MII_88E1510_PHY_LED_DEF 0x1177 170 #define MII_88E1510_PHY_LED0_LINK_LED1_ACTIVE 0x1040 171 172 #define MII_M1011_PHY_STATUS 0x11 173 #define MII_M1011_PHY_STATUS_1000 0x8000 174 #define MII_M1011_PHY_STATUS_100 0x4000 175 #define MII_M1011_PHY_STATUS_SPD_MASK 0xc000 176 #define MII_M1011_PHY_STATUS_FULLDUPLEX 0x2000 177 #define MII_M1011_PHY_STATUS_RESOLVED 0x0800 178 #define MII_M1011_PHY_STATUS_LINK 0x0400 179 #define MII_M1011_PHY_STATUS_MDIX BIT(6) 180 181 #define MII_88E3016_PHY_SPEC_CTRL 0x10 182 #define MII_88E3016_DISABLE_SCRAMBLER 0x0200 183 #define MII_88E3016_AUTO_MDIX_CROSSOVER 0x0030 184 185 #define MII_88E1510_GEN_CTRL_REG_1 0x14 186 #define MII_88E1510_GEN_CTRL_REG_1_MODE_MASK 0x7 187 #define MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII 0x0 /* RGMII to copper */ 188 #define MII_88E1510_GEN_CTRL_REG_1_MODE_SGMII 0x1 /* SGMII to copper */ 189 /* RGMII to 1000BASE-X */ 190 #define MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII_1000X 0x2 191 /* RGMII to 100BASE-FX */ 192 #define MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII_100FX 0x3 193 /* RGMII to SGMII */ 194 #define MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII_SGMII 0x4 195 #define MII_88E1510_GEN_CTRL_REG_1_RESET 0x8000 /* Soft reset */ 196 197 #define MII_88E1510_MSCR_2 0x15 198 199 #define MII_VCT5_TX_RX_MDI0_COUPLING 0x10 200 #define MII_VCT5_TX_RX_MDI1_COUPLING 0x11 201 #define MII_VCT5_TX_RX_MDI2_COUPLING 0x12 202 #define MII_VCT5_TX_RX_MDI3_COUPLING 0x13 203 #define MII_VCT5_TX_RX_AMPLITUDE_MASK 0x7f00 204 #define MII_VCT5_TX_RX_AMPLITUDE_SHIFT 8 205 #define MII_VCT5_TX_RX_COUPLING_POSITIVE_REFLECTION BIT(15) 206 207 #define MII_VCT5_CTRL 0x17 208 #define MII_VCT5_CTRL_ENABLE BIT(15) 209 #define MII_VCT5_CTRL_COMPLETE BIT(14) 210 #define MII_VCT5_CTRL_TX_SAME_CHANNEL (0x0 << 11) 211 #define MII_VCT5_CTRL_TX0_CHANNEL (0x4 << 11) 212 #define MII_VCT5_CTRL_TX1_CHANNEL (0x5 << 11) 213 #define MII_VCT5_CTRL_TX2_CHANNEL (0x6 << 11) 214 #define MII_VCT5_CTRL_TX3_CHANNEL (0x7 << 11) 215 #define MII_VCT5_CTRL_SAMPLES_2 (0x0 << 8) 216 #define MII_VCT5_CTRL_SAMPLES_4 (0x1 << 8) 217 #define MII_VCT5_CTRL_SAMPLES_8 (0x2 << 8) 218 #define MII_VCT5_CTRL_SAMPLES_16 (0x3 << 8) 219 #define MII_VCT5_CTRL_SAMPLES_32 (0x4 << 8) 220 #define MII_VCT5_CTRL_SAMPLES_64 (0x5 << 8) 221 #define MII_VCT5_CTRL_SAMPLES_128 (0x6 << 8) 222 #define MII_VCT5_CTRL_SAMPLES_DEFAULT (0x6 << 8) 223 #define MII_VCT5_CTRL_SAMPLES_256 (0x7 << 8) 224 #define MII_VCT5_CTRL_SAMPLES_SHIFT 8 225 #define MII_VCT5_CTRL_MODE_MAXIMUM_PEEK (0x0 << 6) 226 #define MII_VCT5_CTRL_MODE_FIRST_LAST_PEEK (0x1 << 6) 227 #define MII_VCT5_CTRL_MODE_OFFSET (0x2 << 6) 228 #define MII_VCT5_CTRL_SAMPLE_POINT (0x3 << 6) 229 #define MII_VCT5_CTRL_PEEK_HYST_DEFAULT 3 230 231 #define MII_VCT5_SAMPLE_POINT_DISTANCE 0x18 232 #define MII_VCT5_SAMPLE_POINT_DISTANCE_MAX 511 233 #define MII_VCT5_TX_PULSE_CTRL 0x1c 234 #define MII_VCT5_TX_PULSE_CTRL_DONT_WAIT_LINK_DOWN BIT(12) 235 #define MII_VCT5_TX_PULSE_CTRL_PULSE_WIDTH_128nS (0x0 << 10) 236 #define MII_VCT5_TX_PULSE_CTRL_PULSE_WIDTH_96nS (0x1 << 10) 237 #define MII_VCT5_TX_PULSE_CTRL_PULSE_WIDTH_64nS (0x2 << 10) 238 #define MII_VCT5_TX_PULSE_CTRL_PULSE_WIDTH_32nS (0x3 << 10) 239 #define MII_VCT5_TX_PULSE_CTRL_PULSE_WIDTH_SHIFT 10 240 #define MII_VCT5_TX_PULSE_CTRL_PULSE_AMPLITUDE_1000mV (0x0 << 8) 241 #define MII_VCT5_TX_PULSE_CTRL_PULSE_AMPLITUDE_750mV (0x1 << 8) 242 #define MII_VCT5_TX_PULSE_CTRL_PULSE_AMPLITUDE_500mV (0x2 << 8) 243 #define MII_VCT5_TX_PULSE_CTRL_PULSE_AMPLITUDE_250mV (0x3 << 8) 244 #define MII_VCT5_TX_PULSE_CTRL_PULSE_AMPLITUDE_SHIFT 8 245 #define MII_VCT5_TX_PULSE_CTRL_MAX_AMP BIT(7) 246 #define MII_VCT5_TX_PULSE_CTRL_GT_140m_46_86mV (0x6 << 0) 247 248 /* For TDR measurements less than 11 meters, a short pulse should be 249 * used. 250 */ 251 #define TDR_SHORT_CABLE_LENGTH 11 252 253 #define MII_VCT7_PAIR_0_DISTANCE 0x10 254 #define MII_VCT7_PAIR_1_DISTANCE 0x11 255 #define MII_VCT7_PAIR_2_DISTANCE 0x12 256 #define MII_VCT7_PAIR_3_DISTANCE 0x13 257 258 #define MII_VCT7_RESULTS 0x14 259 #define MII_VCT7_RESULTS_PAIR3_MASK 0xf000 260 #define MII_VCT7_RESULTS_PAIR2_MASK 0x0f00 261 #define MII_VCT7_RESULTS_PAIR1_MASK 0x00f0 262 #define MII_VCT7_RESULTS_PAIR0_MASK 0x000f 263 #define MII_VCT7_RESULTS_PAIR3_SHIFT 12 264 #define MII_VCT7_RESULTS_PAIR2_SHIFT 8 265 #define MII_VCT7_RESULTS_PAIR1_SHIFT 4 266 #define MII_VCT7_RESULTS_PAIR0_SHIFT 0 267 #define MII_VCT7_RESULTS_INVALID 0 268 #define MII_VCT7_RESULTS_OK 1 269 #define MII_VCT7_RESULTS_OPEN 2 270 #define MII_VCT7_RESULTS_SAME_SHORT 3 271 #define MII_VCT7_RESULTS_CROSS_SHORT 4 272 #define MII_VCT7_RESULTS_BUSY 9 273 274 #define MII_VCT7_CTRL 0x15 275 #define MII_VCT7_CTRL_RUN_NOW BIT(15) 276 #define MII_VCT7_CTRL_RUN_ANEG BIT(14) 277 #define MII_VCT7_CTRL_DISABLE_CROSS BIT(13) 278 #define MII_VCT7_CTRL_RUN_AFTER_BREAK_LINK BIT(12) 279 #define MII_VCT7_CTRL_IN_PROGRESS BIT(11) 280 #define MII_VCT7_CTRL_METERS BIT(10) 281 #define MII_VCT7_CTRL_CENTIMETERS 0 282 283 #define MII_VCT_TXPINS 0x1A 284 #define MII_VCT_RXPINS 0x1B 285 #define MII_VCT_SR 0x1C 286 #define MII_VCT_TXPINS_ENVCT BIT(15) 287 #define MII_VCT_TXRXPINS_VCTTST GENMASK(14, 13) 288 #define MII_VCT_TXRXPINS_VCTTST_SHIFT 13 289 #define MII_VCT_TXRXPINS_VCTTST_OK 0 290 #define MII_VCT_TXRXPINS_VCTTST_SHORT 1 291 #define MII_VCT_TXRXPINS_VCTTST_OPEN 2 292 #define MII_VCT_TXRXPINS_VCTTST_FAIL 3 293 #define MII_VCT_TXRXPINS_AMPRFLN GENMASK(12, 8) 294 #define MII_VCT_TXRXPINS_AMPRFLN_SHIFT 8 295 #define MII_VCT_TXRXPINS_DISTRFLN GENMASK(7, 0) 296 #define MII_VCT_TXRXPINS_DISTRFLN_MAX 0xff 297 298 #define M88E3082_PAIR_A BIT(0) 299 #define M88E3082_PAIR_B BIT(1) 300 301 #define LPA_PAUSE_FIBER 0x180 302 #define LPA_PAUSE_ASYM_FIBER 0x100 303 304 #define NB_FIBER_STATS 1 305 #define NB_STAT_MAX 3 306 307 MODULE_DESCRIPTION("Marvell PHY driver"); 308 MODULE_AUTHOR("Andy Fleming"); 309 MODULE_LICENSE("GPL"); 310 311 struct marvell_hw_stat { 312 const char *string; 313 u8 page; 314 u8 reg; 315 u8 bits; 316 }; 317 318 static const struct marvell_hw_stat marvell_hw_stats[] = { 319 { "phy_receive_errors_copper", 0, 21, 16}, 320 { "phy_idle_errors", 0, 10, 8 }, 321 { "phy_receive_errors_fiber", 1, 21, 16}, 322 }; 323 324 static_assert(ARRAY_SIZE(marvell_hw_stats) <= NB_STAT_MAX); 325 326 /* "simple" stat list + corresponding marvell_get_*_simple functions are used 327 * on PHYs without a page register 328 */ 329 struct marvell_hw_stat_simple { 330 const char *string; 331 u8 reg; 332 u8 bits; 333 }; 334 335 static const struct marvell_hw_stat_simple marvell_hw_stats_simple[] = { 336 { "phy_receive_errors", 21, 16}, 337 }; 338 339 static_assert(ARRAY_SIZE(marvell_hw_stats_simple) <= NB_STAT_MAX); 340 341 enum { 342 M88E3082_VCT_OFF, 343 M88E3082_VCT_PHASE1, 344 M88E3082_VCT_PHASE2, 345 }; 346 347 struct marvell_priv { 348 u64 stats[NB_STAT_MAX]; 349 char *hwmon_name; 350 struct device *hwmon_dev; 351 bool cable_test_tdr; 352 u32 first; 353 u32 last; 354 u32 step; 355 s8 pair; 356 u8 vct_phase; 357 }; 358 359 static int marvell_read_page(struct phy_device *phydev) 360 { 361 return __phy_read(phydev, MII_MARVELL_PHY_PAGE); 362 } 363 364 static int marvell_write_page(struct phy_device *phydev, int page) 365 { 366 return __phy_write(phydev, MII_MARVELL_PHY_PAGE, page); 367 } 368 369 static int marvell_set_page(struct phy_device *phydev, int page) 370 { 371 return phy_write(phydev, MII_MARVELL_PHY_PAGE, page); 372 } 373 374 static int marvell_ack_interrupt(struct phy_device *phydev) 375 { 376 int err; 377 378 /* Clear the interrupts by reading the reg */ 379 err = phy_read(phydev, MII_M1011_IEVENT); 380 381 if (err < 0) 382 return err; 383 384 return 0; 385 } 386 387 static int marvell_config_intr(struct phy_device *phydev) 388 { 389 int err; 390 391 if (phydev->interrupts == PHY_INTERRUPT_ENABLED) { 392 err = marvell_ack_interrupt(phydev); 393 if (err) 394 return err; 395 396 err = phy_write(phydev, MII_M1011_IMASK, 397 MII_M1011_IMASK_INIT); 398 } else { 399 err = phy_write(phydev, MII_M1011_IMASK, 400 MII_M1011_IMASK_CLEAR); 401 if (err) 402 return err; 403 404 err = marvell_ack_interrupt(phydev); 405 } 406 407 return err; 408 } 409 410 static irqreturn_t marvell_handle_interrupt(struct phy_device *phydev) 411 { 412 int irq_status; 413 414 irq_status = phy_read(phydev, MII_M1011_IEVENT); 415 if (irq_status < 0) { 416 phy_error(phydev); 417 return IRQ_NONE; 418 } 419 420 if (!(irq_status & MII_M1011_IMASK_INIT)) 421 return IRQ_NONE; 422 423 phy_trigger_machine(phydev); 424 425 return IRQ_HANDLED; 426 } 427 428 static int marvell_set_polarity(struct phy_device *phydev, int polarity) 429 { 430 u16 val; 431 432 switch (polarity) { 433 case ETH_TP_MDI: 434 val = MII_M1011_PHY_SCR_MDI; 435 break; 436 case ETH_TP_MDI_X: 437 val = MII_M1011_PHY_SCR_MDI_X; 438 break; 439 case ETH_TP_MDI_AUTO: 440 case ETH_TP_MDI_INVALID: 441 default: 442 val = MII_M1011_PHY_SCR_AUTO_CROSS; 443 break; 444 } 445 446 return phy_modify_changed(phydev, MII_M1011_PHY_SCR, 447 MII_M1011_PHY_SCR_AUTO_CROSS, val); 448 } 449 450 static int marvell_config_aneg(struct phy_device *phydev) 451 { 452 int changed = 0; 453 int err; 454 455 err = marvell_set_polarity(phydev, phydev->mdix_ctrl); 456 if (err < 0) 457 return err; 458 459 changed = err; 460 461 err = phy_write(phydev, MII_M1111_PHY_LED_CONTROL, 462 MII_M1111_PHY_LED_DIRECT); 463 if (err < 0) 464 return err; 465 466 err = genphy_config_aneg(phydev); 467 if (err < 0) 468 return err; 469 470 if (phydev->autoneg != AUTONEG_ENABLE || changed) { 471 /* A write to speed/duplex bits (that is performed by 472 * genphy_config_aneg() call above) must be followed by 473 * a software reset. Otherwise, the write has no effect. 474 */ 475 err = genphy_soft_reset(phydev); 476 if (err < 0) 477 return err; 478 } 479 480 return 0; 481 } 482 483 static int m88e1101_config_aneg(struct phy_device *phydev) 484 { 485 int err; 486 487 /* This Marvell PHY has an errata which requires 488 * that certain registers get written in order 489 * to restart autonegotiation 490 */ 491 err = genphy_soft_reset(phydev); 492 if (err < 0) 493 return err; 494 495 err = phy_write(phydev, 0x1d, 0x1f); 496 if (err < 0) 497 return err; 498 499 err = phy_write(phydev, 0x1e, 0x200c); 500 if (err < 0) 501 return err; 502 503 err = phy_write(phydev, 0x1d, 0x5); 504 if (err < 0) 505 return err; 506 507 err = phy_write(phydev, 0x1e, 0); 508 if (err < 0) 509 return err; 510 511 err = phy_write(phydev, 0x1e, 0x100); 512 if (err < 0) 513 return err; 514 515 return marvell_config_aneg(phydev); 516 } 517 518 #if IS_ENABLED(CONFIG_OF_MDIO) 519 /* Set and/or override some configuration registers based on the 520 * marvell,reg-init property stored in the of_node for the phydev. 521 * 522 * marvell,reg-init = <reg-page reg mask value>,...; 523 * 524 * There may be one or more sets of <reg-page reg mask value>: 525 * 526 * reg-page: which register bank to use. 527 * reg: the register. 528 * mask: if non-zero, ANDed with existing register value. 529 * value: ORed with the masked value and written to the regiser. 530 * 531 */ 532 static int marvell_of_reg_init(struct phy_device *phydev) 533 { 534 const __be32 *paddr; 535 int len, i, saved_page, current_page, ret = 0; 536 537 if (!phydev->mdio.dev.of_node) 538 return 0; 539 540 paddr = of_get_property(phydev->mdio.dev.of_node, 541 "marvell,reg-init", &len); 542 if (!paddr || len < (4 * sizeof(*paddr))) 543 return 0; 544 545 saved_page = phy_save_page(phydev); 546 if (saved_page < 0) 547 goto err; 548 current_page = saved_page; 549 550 len /= sizeof(*paddr); 551 for (i = 0; i < len - 3; i += 4) { 552 u16 page = be32_to_cpup(paddr + i); 553 u16 reg = be32_to_cpup(paddr + i + 1); 554 u16 mask = be32_to_cpup(paddr + i + 2); 555 u16 val_bits = be32_to_cpup(paddr + i + 3); 556 int val; 557 558 if (page != current_page) { 559 current_page = page; 560 ret = marvell_write_page(phydev, page); 561 if (ret < 0) 562 goto err; 563 } 564 565 val = 0; 566 if (mask) { 567 val = __phy_read(phydev, reg); 568 if (val < 0) { 569 ret = val; 570 goto err; 571 } 572 val &= mask; 573 } 574 val |= val_bits; 575 576 ret = __phy_write(phydev, reg, val); 577 if (ret < 0) 578 goto err; 579 } 580 err: 581 return phy_restore_page(phydev, saved_page, ret); 582 } 583 #else 584 static int marvell_of_reg_init(struct phy_device *phydev) 585 { 586 return 0; 587 } 588 #endif /* CONFIG_OF_MDIO */ 589 590 static int m88e1121_config_aneg_rgmii_delays(struct phy_device *phydev) 591 { 592 int mscr; 593 594 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) 595 mscr = MII_88E1121_PHY_MSCR_RX_DELAY | 596 MII_88E1121_PHY_MSCR_TX_DELAY; 597 else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) 598 mscr = MII_88E1121_PHY_MSCR_RX_DELAY; 599 else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) 600 mscr = MII_88E1121_PHY_MSCR_TX_DELAY; 601 else 602 mscr = 0; 603 604 return phy_modify_paged_changed(phydev, MII_MARVELL_MSCR_PAGE, 605 MII_88E1121_PHY_MSCR_REG, 606 MII_88E1121_PHY_MSCR_DELAY_MASK, mscr); 607 } 608 609 static int m88e1121_config_aneg(struct phy_device *phydev) 610 { 611 int changed = 0; 612 int err = 0; 613 614 if (phy_interface_is_rgmii(phydev)) { 615 err = m88e1121_config_aneg_rgmii_delays(phydev); 616 if (err < 0) 617 return err; 618 } 619 620 changed = err; 621 622 err = marvell_set_polarity(phydev, phydev->mdix_ctrl); 623 if (err < 0) 624 return err; 625 626 changed |= err; 627 628 err = genphy_config_aneg(phydev); 629 if (err < 0) 630 return err; 631 632 if (phydev->autoneg != AUTONEG_ENABLE || changed) { 633 /* A software reset is used to ensure a "commit" of the 634 * changes is done. 635 */ 636 err = genphy_soft_reset(phydev); 637 if (err < 0) 638 return err; 639 } 640 641 return 0; 642 } 643 644 static int m88e1318_config_aneg(struct phy_device *phydev) 645 { 646 int err; 647 648 err = phy_modify_paged(phydev, MII_MARVELL_MSCR_PAGE, 649 MII_88E1318S_PHY_MSCR1_REG, 650 0, MII_88E1318S_PHY_MSCR1_PAD_ODD); 651 if (err < 0) 652 return err; 653 654 return m88e1121_config_aneg(phydev); 655 } 656 657 /** 658 * linkmode_adv_to_fiber_adv_t 659 * @advertise: the linkmode advertisement settings 660 * 661 * A small helper function that translates linkmode advertisement 662 * settings to phy autonegotiation advertisements for the MII_ADV 663 * register for fiber link. 664 */ 665 static inline u32 linkmode_adv_to_fiber_adv_t(unsigned long *advertise) 666 { 667 u32 result = 0; 668 669 if (linkmode_test_bit(ETHTOOL_LINK_MODE_1000baseT_Half_BIT, advertise)) 670 result |= ADVERTISE_1000XHALF; 671 if (linkmode_test_bit(ETHTOOL_LINK_MODE_1000baseT_Full_BIT, advertise)) 672 result |= ADVERTISE_1000XFULL; 673 674 if (linkmode_test_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, advertise) && 675 linkmode_test_bit(ETHTOOL_LINK_MODE_Pause_BIT, advertise)) 676 result |= ADVERTISE_1000XPSE_ASYM; 677 else if (linkmode_test_bit(ETHTOOL_LINK_MODE_Pause_BIT, advertise)) 678 result |= ADVERTISE_1000XPAUSE; 679 680 return result; 681 } 682 683 /** 684 * marvell_config_aneg_fiber - restart auto-negotiation or write BMCR 685 * @phydev: target phy_device struct 686 * 687 * Description: If auto-negotiation is enabled, we configure the 688 * advertising, and then restart auto-negotiation. If it is not 689 * enabled, then we write the BMCR. Adapted for fiber link in 690 * some Marvell's devices. 691 */ 692 static int marvell_config_aneg_fiber(struct phy_device *phydev) 693 { 694 int changed = 0; 695 int err; 696 u16 adv; 697 698 if (phydev->autoneg != AUTONEG_ENABLE) 699 return genphy_setup_forced(phydev); 700 701 /* Only allow advertising what this PHY supports */ 702 linkmode_and(phydev->advertising, phydev->advertising, 703 phydev->supported); 704 705 adv = linkmode_adv_to_fiber_adv_t(phydev->advertising); 706 707 /* Setup fiber advertisement */ 708 err = phy_modify_changed(phydev, MII_ADVERTISE, 709 ADVERTISE_1000XHALF | ADVERTISE_1000XFULL | 710 ADVERTISE_1000XPAUSE | ADVERTISE_1000XPSE_ASYM, 711 adv); 712 if (err < 0) 713 return err; 714 if (err > 0) 715 changed = 1; 716 717 return genphy_check_and_restart_aneg(phydev, changed); 718 } 719 720 static unsigned int m88e1111_inband_caps(struct phy_device *phydev, 721 phy_interface_t interface) 722 { 723 /* In 1000base-X and SGMII modes, the inband mode can be changed 724 * through the Fibre page BMCR ANENABLE bit. 725 */ 726 if (interface == PHY_INTERFACE_MODE_1000BASEX || 727 interface == PHY_INTERFACE_MODE_SGMII) 728 return LINK_INBAND_DISABLE | LINK_INBAND_ENABLE | 729 LINK_INBAND_BYPASS; 730 731 return 0; 732 } 733 734 static int m88e1111_config_inband(struct phy_device *phydev, unsigned int modes) 735 { 736 u16 extsr, bmcr; 737 int err; 738 739 if (phydev->interface != PHY_INTERFACE_MODE_1000BASEX && 740 phydev->interface != PHY_INTERFACE_MODE_SGMII) 741 return -EINVAL; 742 743 if (modes == LINK_INBAND_BYPASS) 744 extsr = MII_M1111_HWCFG_SERIAL_AN_BYPASS; 745 else 746 extsr = 0; 747 748 if (modes == LINK_INBAND_DISABLE) 749 bmcr = 0; 750 else 751 bmcr = BMCR_ANENABLE; 752 753 err = phy_modify(phydev, MII_M1111_PHY_EXT_SR, 754 MII_M1111_HWCFG_SERIAL_AN_BYPASS, extsr); 755 if (err < 0) 756 return extsr; 757 758 return phy_modify_paged(phydev, MII_MARVELL_FIBER_PAGE, MII_BMCR, 759 BMCR_ANENABLE, bmcr); 760 } 761 762 static int m88e1111_config_aneg(struct phy_device *phydev) 763 { 764 int extsr = phy_read(phydev, MII_M1111_PHY_EXT_SR); 765 int err; 766 767 if (extsr < 0) 768 return extsr; 769 770 /* If not using SGMII or copper 1000BaseX modes, use normal process. 771 * Steps below are only required for these modes. 772 */ 773 if (phydev->interface != PHY_INTERFACE_MODE_SGMII && 774 (extsr & MII_M1111_HWCFG_MODE_MASK) != 775 MII_M1111_HWCFG_MODE_COPPER_1000X_AN) 776 return marvell_config_aneg(phydev); 777 778 err = marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE); 779 if (err < 0) 780 goto error; 781 782 /* Configure the copper link first */ 783 err = marvell_config_aneg(phydev); 784 if (err < 0) 785 goto error; 786 787 /* Then the fiber link */ 788 err = marvell_set_page(phydev, MII_MARVELL_FIBER_PAGE); 789 if (err < 0) 790 goto error; 791 792 if (phydev->interface == PHY_INTERFACE_MODE_SGMII) 793 /* Do not touch the fiber advertisement if we're in copper->sgmii mode. 794 * Just ensure that SGMII-side autonegotiation is enabled. 795 * If we switched from some other mode to SGMII it may not be. 796 */ 797 err = genphy_check_and_restart_aneg(phydev, false); 798 else 799 err = marvell_config_aneg_fiber(phydev); 800 if (err < 0) 801 goto error; 802 803 return marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE); 804 805 error: 806 marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE); 807 return err; 808 } 809 810 static int m88e1510_config_aneg(struct phy_device *phydev) 811 { 812 int err; 813 814 err = marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE); 815 if (err < 0) 816 goto error; 817 818 /* Configure the copper link first */ 819 err = m88e1318_config_aneg(phydev); 820 if (err < 0) 821 goto error; 822 823 /* Do not touch the fiber page if we're in copper->sgmii mode */ 824 if (phydev->interface == PHY_INTERFACE_MODE_SGMII) 825 return 0; 826 827 /* Then the fiber link */ 828 err = marvell_set_page(phydev, MII_MARVELL_FIBER_PAGE); 829 if (err < 0) 830 goto error; 831 832 err = marvell_config_aneg_fiber(phydev); 833 if (err < 0) 834 goto error; 835 836 return marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE); 837 838 error: 839 marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE); 840 return err; 841 } 842 843 static void marvell_config_led(struct phy_device *phydev) 844 { 845 u16 def_config; 846 int err; 847 848 switch (MARVELL_PHY_FAMILY_ID(phydev->phy_id)) { 849 /* Default PHY LED config: LED[0] .. Link, LED[1] .. Activity */ 850 case MARVELL_PHY_FAMILY_ID(MARVELL_PHY_ID_88E1121R): 851 case MARVELL_PHY_FAMILY_ID(MARVELL_PHY_ID_88E1318S): 852 def_config = MII_88E1121_PHY_LED_DEF; 853 break; 854 /* Default PHY LED config: 855 * LED[0] .. 1000Mbps Link 856 * LED[1] .. 100Mbps Link 857 * LED[2] .. Blink, Activity 858 */ 859 case MARVELL_PHY_FAMILY_ID(MARVELL_PHY_ID_88E1510): 860 if (phydev->dev_flags & MARVELL_PHY_LED0_LINK_LED1_ACTIVE) 861 def_config = MII_88E1510_PHY_LED0_LINK_LED1_ACTIVE; 862 else 863 def_config = MII_88E1510_PHY_LED_DEF; 864 break; 865 default: 866 return; 867 } 868 869 err = phy_write_paged(phydev, MII_MARVELL_LED_PAGE, MII_PHY_LED_CTRL, 870 def_config); 871 if (err < 0) 872 phydev_warn(phydev, "Fail to config marvell phy LED.\n"); 873 } 874 875 static int marvell_config_init(struct phy_device *phydev) 876 { 877 /* Set default LED */ 878 marvell_config_led(phydev); 879 880 /* Set registers from marvell,reg-init DT property */ 881 return marvell_of_reg_init(phydev); 882 } 883 884 static int m88e3016_config_init(struct phy_device *phydev) 885 { 886 int ret; 887 888 /* Enable Scrambler and Auto-Crossover */ 889 ret = phy_modify(phydev, MII_88E3016_PHY_SPEC_CTRL, 890 MII_88E3016_DISABLE_SCRAMBLER, 891 MII_88E3016_AUTO_MDIX_CROSSOVER); 892 if (ret < 0) 893 return ret; 894 895 return marvell_config_init(phydev); 896 } 897 898 static int m88e1111_config_init_hwcfg_mode(struct phy_device *phydev, 899 u16 mode, 900 int fibre_copper_auto) 901 { 902 if (fibre_copper_auto) 903 mode |= MII_M1111_HWCFG_FIBER_COPPER_AUTO; 904 905 return phy_modify(phydev, MII_M1111_PHY_EXT_SR, 906 MII_M1111_HWCFG_MODE_MASK | 907 MII_M1111_HWCFG_FIBER_COPPER_AUTO | 908 MII_M1111_HWCFG_FIBER_COPPER_RES, 909 mode); 910 } 911 912 static int m88e1111_config_init_rgmii_delays(struct phy_device *phydev) 913 { 914 int delay; 915 916 switch (phydev->interface) { 917 case PHY_INTERFACE_MODE_RGMII_ID: 918 delay = MII_M1111_RGMII_RX_DELAY | MII_M1111_RGMII_TX_DELAY; 919 break; 920 case PHY_INTERFACE_MODE_RGMII_RXID: 921 delay = MII_M1111_RGMII_RX_DELAY; 922 break; 923 case PHY_INTERFACE_MODE_RGMII_TXID: 924 delay = MII_M1111_RGMII_TX_DELAY; 925 break; 926 default: 927 delay = 0; 928 break; 929 } 930 931 return phy_modify(phydev, MII_M1111_PHY_EXT_CR, 932 MII_M1111_RGMII_RX_DELAY | MII_M1111_RGMII_TX_DELAY, 933 delay); 934 } 935 936 static int m88e1111_config_init_rgmii(struct phy_device *phydev) 937 { 938 int temp; 939 int err; 940 941 err = m88e1111_config_init_rgmii_delays(phydev); 942 if (err < 0) 943 return err; 944 945 temp = phy_read(phydev, MII_M1111_PHY_EXT_SR); 946 if (temp < 0) 947 return temp; 948 949 temp &= ~(MII_M1111_HWCFG_MODE_MASK); 950 951 if (temp & MII_M1111_HWCFG_FIBER_COPPER_RES) 952 temp |= MII_M1111_HWCFG_MODE_FIBER_RGMII; 953 else 954 temp |= MII_M1111_HWCFG_MODE_COPPER_RGMII; 955 956 return phy_write(phydev, MII_M1111_PHY_EXT_SR, temp); 957 } 958 959 static int m88e1111_config_init_sgmii(struct phy_device *phydev) 960 { 961 int err; 962 963 err = m88e1111_config_init_hwcfg_mode( 964 phydev, 965 MII_M1111_HWCFG_MODE_SGMII_NO_CLK, 966 MII_M1111_HWCFG_FIBER_COPPER_AUTO); 967 if (err < 0) 968 return err; 969 970 /* make sure copper is selected */ 971 return marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE); 972 } 973 974 static int m88e1111_config_init_rtbi(struct phy_device *phydev) 975 { 976 int err; 977 978 err = m88e1111_config_init_rgmii_delays(phydev); 979 if (err < 0) 980 return err; 981 982 err = m88e1111_config_init_hwcfg_mode( 983 phydev, 984 MII_M1111_HWCFG_MODE_RTBI, 985 MII_M1111_HWCFG_FIBER_COPPER_AUTO); 986 if (err < 0) 987 return err; 988 989 /* soft reset */ 990 err = genphy_soft_reset(phydev); 991 if (err < 0) 992 return err; 993 994 return m88e1111_config_init_hwcfg_mode( 995 phydev, 996 MII_M1111_HWCFG_MODE_RTBI, 997 MII_M1111_HWCFG_FIBER_COPPER_AUTO); 998 } 999 1000 static int m88e1111_config_init_1000basex(struct phy_device *phydev) 1001 { 1002 int extsr = phy_read(phydev, MII_M1111_PHY_EXT_SR); 1003 int err, mode; 1004 1005 if (extsr < 0) 1006 return extsr; 1007 1008 /* If using copper mode, ensure 1000BaseX auto-negotiation is enabled. 1009 * FIXME: this does not actually enable 1000BaseX auto-negotiation if 1010 * it was previously disabled in the Fiber BMCR! 1011 */ 1012 mode = extsr & MII_M1111_HWCFG_MODE_MASK; 1013 if (mode == MII_M1111_HWCFG_MODE_COPPER_1000X_NOAN) { 1014 err = phy_modify(phydev, MII_M1111_PHY_EXT_SR, 1015 MII_M1111_HWCFG_MODE_MASK | 1016 MII_M1111_HWCFG_SERIAL_AN_BYPASS, 1017 MII_M1111_HWCFG_MODE_COPPER_1000X_AN | 1018 MII_M1111_HWCFG_SERIAL_AN_BYPASS); 1019 if (err < 0) 1020 return err; 1021 } 1022 return 0; 1023 } 1024 1025 static int m88e1111_config_init(struct phy_device *phydev) 1026 { 1027 int err; 1028 1029 if (phy_interface_is_rgmii(phydev)) { 1030 err = m88e1111_config_init_rgmii(phydev); 1031 if (err < 0) 1032 return err; 1033 } 1034 1035 if (phydev->interface == PHY_INTERFACE_MODE_SGMII) { 1036 err = m88e1111_config_init_sgmii(phydev); 1037 if (err < 0) 1038 return err; 1039 } 1040 1041 if (phydev->interface == PHY_INTERFACE_MODE_RTBI) { 1042 err = m88e1111_config_init_rtbi(phydev); 1043 if (err < 0) 1044 return err; 1045 } 1046 1047 if (phydev->interface == PHY_INTERFACE_MODE_1000BASEX) { 1048 err = m88e1111_config_init_1000basex(phydev); 1049 if (err < 0) 1050 return err; 1051 } 1052 1053 err = marvell_of_reg_init(phydev); 1054 if (err < 0) 1055 return err; 1056 1057 err = genphy_soft_reset(phydev); 1058 if (err < 0) 1059 return err; 1060 1061 if (phydev->interface == PHY_INTERFACE_MODE_SGMII) { 1062 /* If the HWCFG_MODE was changed from another mode (such as 1063 * 1000BaseX) to SGMII, the state of the support bits may have 1064 * also changed now that the PHY has been reset. 1065 * Update the PHY abilities accordingly. 1066 */ 1067 err = genphy_read_abilities(phydev); 1068 linkmode_or(phydev->advertising, phydev->advertising, 1069 phydev->supported); 1070 } 1071 return err; 1072 } 1073 1074 static int m88e1111_get_downshift(struct phy_device *phydev, u8 *data) 1075 { 1076 int val, cnt, enable; 1077 1078 val = phy_read(phydev, MII_M1111_PHY_EXT_CR); 1079 if (val < 0) 1080 return val; 1081 1082 enable = FIELD_GET(MII_M1111_PHY_EXT_CR_DOWNSHIFT_EN, val); 1083 cnt = FIELD_GET(MII_M1111_PHY_EXT_CR_DOWNSHIFT_MASK, val) + 1; 1084 1085 *data = enable ? cnt : DOWNSHIFT_DEV_DISABLE; 1086 1087 return 0; 1088 } 1089 1090 static int m88e1111_set_downshift(struct phy_device *phydev, u8 cnt) 1091 { 1092 int val, err; 1093 1094 if (cnt > MII_M1111_PHY_EXT_CR_DOWNSHIFT_MAX) 1095 return -E2BIG; 1096 1097 if (!cnt) { 1098 err = phy_clear_bits(phydev, MII_M1111_PHY_EXT_CR, 1099 MII_M1111_PHY_EXT_CR_DOWNSHIFT_EN); 1100 } else { 1101 val = MII_M1111_PHY_EXT_CR_DOWNSHIFT_EN; 1102 val |= FIELD_PREP(MII_M1111_PHY_EXT_CR_DOWNSHIFT_MASK, cnt - 1); 1103 1104 err = phy_modify(phydev, MII_M1111_PHY_EXT_CR, 1105 MII_M1111_PHY_EXT_CR_DOWNSHIFT_EN | 1106 MII_M1111_PHY_EXT_CR_DOWNSHIFT_MASK, 1107 val); 1108 } 1109 1110 if (err < 0) 1111 return err; 1112 1113 return genphy_soft_reset(phydev); 1114 } 1115 1116 static int m88e1111_get_tunable(struct phy_device *phydev, 1117 struct ethtool_tunable *tuna, void *data) 1118 { 1119 switch (tuna->id) { 1120 case ETHTOOL_PHY_DOWNSHIFT: 1121 return m88e1111_get_downshift(phydev, data); 1122 default: 1123 return -EOPNOTSUPP; 1124 } 1125 } 1126 1127 static int m88e1111_set_tunable(struct phy_device *phydev, 1128 struct ethtool_tunable *tuna, const void *data) 1129 { 1130 switch (tuna->id) { 1131 case ETHTOOL_PHY_DOWNSHIFT: 1132 return m88e1111_set_downshift(phydev, *(const u8 *)data); 1133 default: 1134 return -EOPNOTSUPP; 1135 } 1136 } 1137 1138 static int m88e1011_get_downshift(struct phy_device *phydev, u8 *data) 1139 { 1140 int val, cnt, enable; 1141 1142 val = phy_read(phydev, MII_M1011_PHY_SCR); 1143 if (val < 0) 1144 return val; 1145 1146 enable = FIELD_GET(MII_M1011_PHY_SCR_DOWNSHIFT_EN, val); 1147 cnt = FIELD_GET(MII_M1011_PHY_SCR_DOWNSHIFT_MASK, val) + 1; 1148 1149 *data = enable ? cnt : DOWNSHIFT_DEV_DISABLE; 1150 1151 return 0; 1152 } 1153 1154 static int m88e1011_set_downshift(struct phy_device *phydev, u8 cnt) 1155 { 1156 int val, err; 1157 1158 if (cnt > MII_M1011_PHY_SCR_DOWNSHIFT_MAX) 1159 return -E2BIG; 1160 1161 if (!cnt) { 1162 err = phy_clear_bits(phydev, MII_M1011_PHY_SCR, 1163 MII_M1011_PHY_SCR_DOWNSHIFT_EN); 1164 } else { 1165 val = MII_M1011_PHY_SCR_DOWNSHIFT_EN; 1166 val |= FIELD_PREP(MII_M1011_PHY_SCR_DOWNSHIFT_MASK, cnt - 1); 1167 1168 err = phy_modify(phydev, MII_M1011_PHY_SCR, 1169 MII_M1011_PHY_SCR_DOWNSHIFT_EN | 1170 MII_M1011_PHY_SCR_DOWNSHIFT_MASK, 1171 val); 1172 } 1173 1174 if (err < 0) 1175 return err; 1176 1177 return genphy_soft_reset(phydev); 1178 } 1179 1180 static int m88e1011_get_tunable(struct phy_device *phydev, 1181 struct ethtool_tunable *tuna, void *data) 1182 { 1183 switch (tuna->id) { 1184 case ETHTOOL_PHY_DOWNSHIFT: 1185 return m88e1011_get_downshift(phydev, data); 1186 default: 1187 return -EOPNOTSUPP; 1188 } 1189 } 1190 1191 static int m88e1011_set_tunable(struct phy_device *phydev, 1192 struct ethtool_tunable *tuna, const void *data) 1193 { 1194 switch (tuna->id) { 1195 case ETHTOOL_PHY_DOWNSHIFT: 1196 return m88e1011_set_downshift(phydev, *(const u8 *)data); 1197 default: 1198 return -EOPNOTSUPP; 1199 } 1200 } 1201 1202 static int m88e1112_config_init(struct phy_device *phydev) 1203 { 1204 int err; 1205 1206 err = m88e1011_set_downshift(phydev, 3); 1207 if (err < 0) 1208 return err; 1209 1210 return m88e1111_config_init(phydev); 1211 } 1212 1213 static int m88e1111gbe_config_init(struct phy_device *phydev) 1214 { 1215 int err; 1216 1217 err = m88e1111_set_downshift(phydev, 3); 1218 if (err < 0) 1219 return err; 1220 1221 return m88e1111_config_init(phydev); 1222 } 1223 1224 static int marvell_1011gbe_config_init(struct phy_device *phydev) 1225 { 1226 int err; 1227 1228 err = m88e1011_set_downshift(phydev, 3); 1229 if (err < 0) 1230 return err; 1231 1232 return marvell_config_init(phydev); 1233 } 1234 static int m88e1116r_config_init(struct phy_device *phydev) 1235 { 1236 int err; 1237 1238 err = genphy_soft_reset(phydev); 1239 if (err < 0) 1240 return err; 1241 1242 msleep(500); 1243 1244 err = marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE); 1245 if (err < 0) 1246 return err; 1247 1248 err = marvell_set_polarity(phydev, phydev->mdix_ctrl); 1249 if (err < 0) 1250 return err; 1251 1252 err = m88e1011_set_downshift(phydev, 8); 1253 if (err < 0) 1254 return err; 1255 1256 if (phy_interface_is_rgmii(phydev)) { 1257 err = m88e1121_config_aneg_rgmii_delays(phydev); 1258 if (err < 0) 1259 return err; 1260 } 1261 1262 err = genphy_soft_reset(phydev); 1263 if (err < 0) 1264 return err; 1265 1266 return marvell_config_init(phydev); 1267 } 1268 1269 static int m88e1318_config_init(struct phy_device *phydev) 1270 { 1271 if (phy_interrupt_is_valid(phydev)) { 1272 int err = phy_modify_paged( 1273 phydev, MII_MARVELL_LED_PAGE, 1274 MII_88E1318S_PHY_LED_TCR, 1275 MII_88E1318S_PHY_LED_TCR_FORCE_INT, 1276 MII_88E1318S_PHY_LED_TCR_INTn_ENABLE | 1277 MII_88E1318S_PHY_LED_TCR_INT_ACTIVE_LOW); 1278 if (err < 0) 1279 return err; 1280 } 1281 1282 return marvell_config_init(phydev); 1283 } 1284 1285 static int m88e1510_config_init(struct phy_device *phydev) 1286 { 1287 static const struct { 1288 u16 reg17, reg16; 1289 } errata_vals[] = { 1290 { 0x214b, 0x2144 }, 1291 { 0x0c28, 0x2146 }, 1292 { 0xb233, 0x214d }, 1293 { 0xcc0c, 0x2159 }, 1294 }; 1295 int err; 1296 int i; 1297 1298 /* As per Marvell Release Notes - Alaska 88E1510/88E1518/88E1512/ 1299 * 88E1514 Rev A0, Errata Section 5.1: 1300 * If EEE is intended to be used, the following register writes 1301 * must be done once after every hardware reset. 1302 */ 1303 err = marvell_set_page(phydev, 0x00FF); 1304 if (err < 0) 1305 return err; 1306 1307 for (i = 0; i < ARRAY_SIZE(errata_vals); ++i) { 1308 err = phy_write(phydev, 17, errata_vals[i].reg17); 1309 if (err) 1310 return err; 1311 err = phy_write(phydev, 16, errata_vals[i].reg16); 1312 if (err) 1313 return err; 1314 } 1315 1316 err = marvell_set_page(phydev, 0x00FB); 1317 if (err < 0) 1318 return err; 1319 err = phy_write(phydev, 07, 0xC00D); 1320 if (err < 0) 1321 return err; 1322 err = marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE); 1323 if (err < 0) 1324 return err; 1325 1326 /* SGMII-to-Copper mode initialization */ 1327 if (phydev->interface == PHY_INTERFACE_MODE_SGMII) { 1328 /* Select page 18 */ 1329 err = marvell_set_page(phydev, 18); 1330 if (err < 0) 1331 return err; 1332 1333 /* In reg 20, write MODE[2:0] = 0x1 (SGMII to Copper) */ 1334 err = phy_modify(phydev, MII_88E1510_GEN_CTRL_REG_1, 1335 MII_88E1510_GEN_CTRL_REG_1_MODE_MASK, 1336 MII_88E1510_GEN_CTRL_REG_1_MODE_SGMII); 1337 if (err < 0) 1338 return err; 1339 1340 /* PHY reset is necessary after changing MODE[2:0] */ 1341 err = phy_set_bits(phydev, MII_88E1510_GEN_CTRL_REG_1, 1342 MII_88E1510_GEN_CTRL_REG_1_RESET); 1343 if (err < 0) 1344 return err; 1345 1346 /* Reset page selection */ 1347 err = marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE); 1348 if (err < 0) 1349 return err; 1350 } 1351 err = m88e1011_set_downshift(phydev, 3); 1352 if (err < 0) 1353 return err; 1354 1355 return m88e1318_config_init(phydev); 1356 } 1357 1358 static int m88e1118_config_aneg(struct phy_device *phydev) 1359 { 1360 int err; 1361 1362 err = marvell_set_polarity(phydev, phydev->mdix_ctrl); 1363 if (err < 0) 1364 return err; 1365 1366 err = genphy_config_aneg(phydev); 1367 if (err < 0) 1368 return err; 1369 1370 return genphy_soft_reset(phydev); 1371 } 1372 1373 static int m88e1118_config_init(struct phy_device *phydev) 1374 { 1375 u16 leds; 1376 int err; 1377 1378 /* Enable 1000 Mbit */ 1379 err = phy_write_paged(phydev, MII_MARVELL_MSCR_PAGE, 1380 MII_88E1121_PHY_MSCR_REG, 0x1070); 1381 if (err < 0) 1382 return err; 1383 1384 if (phy_interface_is_rgmii(phydev)) { 1385 err = m88e1121_config_aneg_rgmii_delays(phydev); 1386 if (err < 0) 1387 return err; 1388 } 1389 1390 /* Adjust LED Control */ 1391 if (phydev->dev_flags & MARVELL_PHY_M1118_DNS323_LEDS) 1392 leds = 0x1100; 1393 else 1394 leds = 0x021e; 1395 1396 err = phy_write_paged(phydev, MII_MARVELL_LED_PAGE, 0x10, leds); 1397 if (err < 0) 1398 return err; 1399 1400 err = marvell_of_reg_init(phydev); 1401 if (err < 0) 1402 return err; 1403 1404 /* Reset page register */ 1405 err = marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE); 1406 if (err < 0) 1407 return err; 1408 1409 return genphy_soft_reset(phydev); 1410 } 1411 1412 static int m88e1149_config_init(struct phy_device *phydev) 1413 { 1414 int err; 1415 1416 /* Change address */ 1417 err = marvell_set_page(phydev, MII_MARVELL_MSCR_PAGE); 1418 if (err < 0) 1419 return err; 1420 1421 /* Enable 1000 Mbit */ 1422 err = phy_write(phydev, 0x15, 0x1048); 1423 if (err < 0) 1424 return err; 1425 1426 err = marvell_of_reg_init(phydev); 1427 if (err < 0) 1428 return err; 1429 1430 /* Reset address */ 1431 err = marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE); 1432 if (err < 0) 1433 return err; 1434 1435 return genphy_soft_reset(phydev); 1436 } 1437 1438 static int m88e1145_config_init_rgmii(struct phy_device *phydev) 1439 { 1440 int err; 1441 1442 err = m88e1111_config_init_rgmii_delays(phydev); 1443 if (err < 0) 1444 return err; 1445 1446 if (phydev->dev_flags & MARVELL_PHY_M1145_FLAGS_RESISTANCE) { 1447 err = phy_write(phydev, 0x1d, 0x0012); 1448 if (err < 0) 1449 return err; 1450 1451 err = phy_modify(phydev, 0x1e, 0x0fc0, 1452 2 << 9 | /* 36 ohm */ 1453 2 << 6); /* 39 ohm */ 1454 if (err < 0) 1455 return err; 1456 1457 err = phy_write(phydev, 0x1d, 0x3); 1458 if (err < 0) 1459 return err; 1460 1461 err = phy_write(phydev, 0x1e, 0x8000); 1462 } 1463 return err; 1464 } 1465 1466 static int m88e1145_config_init_sgmii(struct phy_device *phydev) 1467 { 1468 return m88e1111_config_init_hwcfg_mode( 1469 phydev, MII_M1111_HWCFG_MODE_SGMII_NO_CLK, 1470 MII_M1111_HWCFG_FIBER_COPPER_AUTO); 1471 } 1472 1473 static int m88e1145_config_init(struct phy_device *phydev) 1474 { 1475 int err; 1476 1477 /* Take care of errata E0 & E1 */ 1478 err = phy_write(phydev, 0x1d, 0x001b); 1479 if (err < 0) 1480 return err; 1481 1482 err = phy_write(phydev, 0x1e, 0x418f); 1483 if (err < 0) 1484 return err; 1485 1486 err = phy_write(phydev, 0x1d, 0x0016); 1487 if (err < 0) 1488 return err; 1489 1490 err = phy_write(phydev, 0x1e, 0xa2da); 1491 if (err < 0) 1492 return err; 1493 1494 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) { 1495 err = m88e1145_config_init_rgmii(phydev); 1496 if (err < 0) 1497 return err; 1498 } 1499 1500 if (phydev->interface == PHY_INTERFACE_MODE_SGMII) { 1501 err = m88e1145_config_init_sgmii(phydev); 1502 if (err < 0) 1503 return err; 1504 } 1505 err = m88e1111_set_downshift(phydev, 3); 1506 if (err < 0) 1507 return err; 1508 1509 err = marvell_of_reg_init(phydev); 1510 if (err < 0) 1511 return err; 1512 1513 return 0; 1514 } 1515 1516 static int m88e1540_get_fld(struct phy_device *phydev, u8 *msecs) 1517 { 1518 int val; 1519 1520 val = phy_read(phydev, MII_88E1540_COPPER_CTRL3); 1521 if (val < 0) 1522 return val; 1523 1524 if (!(val & MII_88E1540_COPPER_CTRL3_FAST_LINK_DOWN)) { 1525 *msecs = ETHTOOL_PHY_FAST_LINK_DOWN_OFF; 1526 return 0; 1527 } 1528 1529 val = FIELD_GET(MII_88E1540_COPPER_CTRL3_LINK_DOWN_DELAY_MASK, val); 1530 1531 switch (val) { 1532 case MII_88E1540_COPPER_CTRL3_LINK_DOWN_DELAY_00MS: 1533 *msecs = 0; 1534 break; 1535 case MII_88E1540_COPPER_CTRL3_LINK_DOWN_DELAY_10MS: 1536 *msecs = 10; 1537 break; 1538 case MII_88E1540_COPPER_CTRL3_LINK_DOWN_DELAY_20MS: 1539 *msecs = 20; 1540 break; 1541 case MII_88E1540_COPPER_CTRL3_LINK_DOWN_DELAY_40MS: 1542 *msecs = 40; 1543 break; 1544 default: 1545 return -EINVAL; 1546 } 1547 1548 return 0; 1549 } 1550 1551 static int m88e1540_set_fld(struct phy_device *phydev, const u8 *msecs) 1552 { 1553 int val, ret; 1554 1555 if (*msecs == ETHTOOL_PHY_FAST_LINK_DOWN_OFF) 1556 return phy_clear_bits(phydev, MII_88E1540_COPPER_CTRL3, 1557 MII_88E1540_COPPER_CTRL3_FAST_LINK_DOWN); 1558 1559 /* According to the Marvell data sheet EEE must be disabled for 1560 * Fast Link Down detection to work properly 1561 */ 1562 if (phydev->eee_cfg.eee_enabled) { 1563 phydev_warn(phydev, "Fast Link Down detection requires EEE to be disabled!\n"); 1564 return -EBUSY; 1565 } 1566 1567 if (*msecs <= 5) 1568 val = MII_88E1540_COPPER_CTRL3_LINK_DOWN_DELAY_00MS; 1569 else if (*msecs <= 15) 1570 val = MII_88E1540_COPPER_CTRL3_LINK_DOWN_DELAY_10MS; 1571 else if (*msecs <= 30) 1572 val = MII_88E1540_COPPER_CTRL3_LINK_DOWN_DELAY_20MS; 1573 else 1574 val = MII_88E1540_COPPER_CTRL3_LINK_DOWN_DELAY_40MS; 1575 1576 val = FIELD_PREP(MII_88E1540_COPPER_CTRL3_LINK_DOWN_DELAY_MASK, val); 1577 1578 ret = phy_modify(phydev, MII_88E1540_COPPER_CTRL3, 1579 MII_88E1540_COPPER_CTRL3_LINK_DOWN_DELAY_MASK, val); 1580 if (ret) 1581 return ret; 1582 1583 return phy_set_bits(phydev, MII_88E1540_COPPER_CTRL3, 1584 MII_88E1540_COPPER_CTRL3_FAST_LINK_DOWN); 1585 } 1586 1587 static int m88e1540_get_tunable(struct phy_device *phydev, 1588 struct ethtool_tunable *tuna, void *data) 1589 { 1590 switch (tuna->id) { 1591 case ETHTOOL_PHY_FAST_LINK_DOWN: 1592 return m88e1540_get_fld(phydev, data); 1593 case ETHTOOL_PHY_DOWNSHIFT: 1594 return m88e1011_get_downshift(phydev, data); 1595 default: 1596 return -EOPNOTSUPP; 1597 } 1598 } 1599 1600 static int m88e1540_set_tunable(struct phy_device *phydev, 1601 struct ethtool_tunable *tuna, const void *data) 1602 { 1603 switch (tuna->id) { 1604 case ETHTOOL_PHY_FAST_LINK_DOWN: 1605 return m88e1540_set_fld(phydev, data); 1606 case ETHTOOL_PHY_DOWNSHIFT: 1607 return m88e1011_set_downshift(phydev, *(const u8 *)data); 1608 default: 1609 return -EOPNOTSUPP; 1610 } 1611 } 1612 1613 /* The VOD can be out of specification on link up. Poke an 1614 * undocumented register, in an undocumented page, with a magic value 1615 * to fix this. 1616 */ 1617 static int m88e6390_errata(struct phy_device *phydev) 1618 { 1619 int err; 1620 1621 err = phy_write(phydev, MII_BMCR, 1622 BMCR_ANENABLE | BMCR_SPEED1000 | BMCR_FULLDPLX); 1623 if (err) 1624 return err; 1625 1626 usleep_range(300, 400); 1627 1628 err = phy_write_paged(phydev, 0xf8, 0x08, 0x36); 1629 if (err) 1630 return err; 1631 1632 return genphy_soft_reset(phydev); 1633 } 1634 1635 static int m88e6390_config_aneg(struct phy_device *phydev) 1636 { 1637 int err; 1638 1639 err = m88e6390_errata(phydev); 1640 if (err) 1641 return err; 1642 1643 return m88e1510_config_aneg(phydev); 1644 } 1645 1646 /** 1647 * fiber_lpa_mod_linkmode_lpa_t 1648 * @advertising: the linkmode advertisement settings 1649 * @lpa: value of the MII_LPA register for fiber link 1650 * 1651 * A small helper function that translates MII_LPA bits to linkmode LP 1652 * advertisement settings. Other bits in advertising are left 1653 * unchanged. 1654 */ 1655 static void fiber_lpa_mod_linkmode_lpa_t(unsigned long *advertising, u32 lpa) 1656 { 1657 linkmode_mod_bit(ETHTOOL_LINK_MODE_1000baseT_Half_BIT, 1658 advertising, lpa & LPA_1000XHALF); 1659 1660 linkmode_mod_bit(ETHTOOL_LINK_MODE_1000baseT_Full_BIT, 1661 advertising, lpa & LPA_1000XFULL); 1662 } 1663 1664 static int marvell_read_status_page_an(struct phy_device *phydev, 1665 int fiber, int status) 1666 { 1667 int lpa; 1668 int err; 1669 1670 if (!(status & MII_M1011_PHY_STATUS_RESOLVED)) { 1671 phydev->link = 0; 1672 return 0; 1673 } 1674 1675 if (status & MII_M1011_PHY_STATUS_FULLDUPLEX) 1676 phydev->duplex = DUPLEX_FULL; 1677 else 1678 phydev->duplex = DUPLEX_HALF; 1679 1680 switch (status & MII_M1011_PHY_STATUS_SPD_MASK) { 1681 case MII_M1011_PHY_STATUS_1000: 1682 phydev->speed = SPEED_1000; 1683 break; 1684 1685 case MII_M1011_PHY_STATUS_100: 1686 phydev->speed = SPEED_100; 1687 break; 1688 1689 default: 1690 phydev->speed = SPEED_10; 1691 break; 1692 } 1693 1694 if (!fiber) { 1695 err = genphy_read_lpa(phydev); 1696 if (err < 0) 1697 return err; 1698 1699 phy_resolve_aneg_pause(phydev); 1700 } else { 1701 lpa = phy_read(phydev, MII_LPA); 1702 if (lpa < 0) 1703 return lpa; 1704 1705 /* The fiber link is only 1000M capable */ 1706 fiber_lpa_mod_linkmode_lpa_t(phydev->lp_advertising, lpa); 1707 1708 if (phydev->duplex == DUPLEX_FULL) { 1709 if (!(lpa & LPA_PAUSE_FIBER)) { 1710 phydev->pause = 0; 1711 phydev->asym_pause = 0; 1712 } else if ((lpa & LPA_PAUSE_ASYM_FIBER)) { 1713 phydev->pause = 1; 1714 phydev->asym_pause = 1; 1715 } else { 1716 phydev->pause = 1; 1717 phydev->asym_pause = 0; 1718 } 1719 } 1720 } 1721 1722 return 0; 1723 } 1724 1725 /* marvell_read_status_page 1726 * 1727 * Description: 1728 * Check the link, then figure out the current state 1729 * by comparing what we advertise with what the link partner 1730 * advertises. Start by checking the gigabit possibilities, 1731 * then move on to 10/100. 1732 */ 1733 static int marvell_read_status_page(struct phy_device *phydev, int page) 1734 { 1735 int status; 1736 int fiber; 1737 int err; 1738 1739 status = phy_read(phydev, MII_M1011_PHY_STATUS); 1740 if (status < 0) 1741 return status; 1742 1743 /* Use the generic register for copper link status, 1744 * and the PHY status register for fiber link status. 1745 */ 1746 if (page == MII_MARVELL_FIBER_PAGE) { 1747 phydev->link = !!(status & MII_M1011_PHY_STATUS_LINK); 1748 } else { 1749 err = genphy_update_link(phydev); 1750 if (err) 1751 return err; 1752 } 1753 1754 if (page == MII_MARVELL_FIBER_PAGE) 1755 fiber = 1; 1756 else 1757 fiber = 0; 1758 1759 linkmode_zero(phydev->lp_advertising); 1760 phydev->pause = 0; 1761 phydev->asym_pause = 0; 1762 phydev->speed = SPEED_UNKNOWN; 1763 phydev->duplex = DUPLEX_UNKNOWN; 1764 phydev->port = fiber ? PORT_FIBRE : PORT_TP; 1765 1766 if (fiber) { 1767 phydev->mdix = ETH_TP_MDI_INVALID; 1768 } else { 1769 /* The MDI-X state is set regardless of Autoneg being enabled 1770 * and reflects forced MDI-X state as well as auto resolution 1771 */ 1772 if (status & MII_M1011_PHY_STATUS_RESOLVED) 1773 phydev->mdix = status & MII_M1011_PHY_STATUS_MDIX ? 1774 ETH_TP_MDI_X : ETH_TP_MDI; 1775 else 1776 phydev->mdix = ETH_TP_MDI_INVALID; 1777 } 1778 1779 if (phydev->autoneg == AUTONEG_ENABLE) 1780 err = marvell_read_status_page_an(phydev, fiber, status); 1781 else 1782 err = genphy_read_status_fixed(phydev); 1783 1784 return err; 1785 } 1786 1787 /* marvell_read_status 1788 * 1789 * Some Marvell's phys have two modes: fiber and copper. 1790 * Both need status checked. 1791 * Description: 1792 * First, check the fiber link and status. 1793 * If the fiber link is down, check the copper link and status which 1794 * will be the default value if both link are down. 1795 */ 1796 static int marvell_read_status(struct phy_device *phydev) 1797 { 1798 int err; 1799 1800 /* Check the fiber mode first */ 1801 if (linkmode_test_bit(ETHTOOL_LINK_MODE_FIBRE_BIT, 1802 phydev->supported) && 1803 phydev->interface != PHY_INTERFACE_MODE_SGMII) { 1804 err = marvell_set_page(phydev, MII_MARVELL_FIBER_PAGE); 1805 if (err < 0) 1806 goto error; 1807 1808 err = marvell_read_status_page(phydev, MII_MARVELL_FIBER_PAGE); 1809 if (err < 0) 1810 goto error; 1811 1812 /* If the fiber link is up, it is the selected and 1813 * used link. In this case, we need to stay in the 1814 * fiber page. Please to be careful about that, avoid 1815 * to restore Copper page in other functions which 1816 * could break the behaviour for some fiber phy like 1817 * 88E1512. 1818 */ 1819 if (phydev->link) 1820 return 0; 1821 1822 /* If fiber link is down, check and save copper mode state */ 1823 err = marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE); 1824 if (err < 0) 1825 goto error; 1826 } 1827 1828 return marvell_read_status_page(phydev, MII_MARVELL_COPPER_PAGE); 1829 1830 error: 1831 marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE); 1832 return err; 1833 } 1834 1835 /* marvell_suspend 1836 * 1837 * Some Marvell's phys have two modes: fiber and copper. 1838 * Both need to be suspended 1839 */ 1840 static int marvell_suspend(struct phy_device *phydev) 1841 { 1842 int err; 1843 1844 /* Suspend the fiber mode first */ 1845 if (linkmode_test_bit(ETHTOOL_LINK_MODE_FIBRE_BIT, 1846 phydev->supported)) { 1847 err = marvell_set_page(phydev, MII_MARVELL_FIBER_PAGE); 1848 if (err < 0) 1849 goto error; 1850 1851 /* With the page set, use the generic suspend */ 1852 err = genphy_suspend(phydev); 1853 if (err < 0) 1854 goto error; 1855 1856 /* Then, the copper link */ 1857 err = marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE); 1858 if (err < 0) 1859 goto error; 1860 } 1861 1862 /* With the page set, use the generic suspend */ 1863 return genphy_suspend(phydev); 1864 1865 error: 1866 marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE); 1867 return err; 1868 } 1869 1870 /* marvell_resume 1871 * 1872 * Some Marvell's phys have two modes: fiber and copper. 1873 * Both need to be resumed 1874 */ 1875 static int marvell_resume(struct phy_device *phydev) 1876 { 1877 int err; 1878 1879 /* Resume the fiber mode first */ 1880 if (linkmode_test_bit(ETHTOOL_LINK_MODE_FIBRE_BIT, 1881 phydev->supported)) { 1882 err = marvell_set_page(phydev, MII_MARVELL_FIBER_PAGE); 1883 if (err < 0) 1884 goto error; 1885 1886 /* With the page set, use the generic resume */ 1887 err = genphy_resume(phydev); 1888 if (err < 0) 1889 goto error; 1890 1891 /* Then, the copper link */ 1892 err = marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE); 1893 if (err < 0) 1894 goto error; 1895 } 1896 1897 /* With the page set, use the generic resume */ 1898 return genphy_resume(phydev); 1899 1900 error: 1901 marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE); 1902 return err; 1903 } 1904 1905 static int marvell_aneg_done(struct phy_device *phydev) 1906 { 1907 int retval = phy_read(phydev, MII_M1011_PHY_STATUS); 1908 1909 return (retval < 0) ? retval : (retval & MII_M1011_PHY_STATUS_RESOLVED); 1910 } 1911 1912 static void m88e1318_get_wol(struct phy_device *phydev, 1913 struct ethtool_wolinfo *wol) 1914 { 1915 int ret; 1916 1917 wol->supported = WAKE_MAGIC | WAKE_PHY; 1918 wol->wolopts = 0; 1919 1920 ret = phy_read_paged(phydev, MII_MARVELL_WOL_PAGE, 1921 MII_88E1318S_PHY_WOL_CTRL); 1922 if (ret < 0) 1923 return; 1924 1925 if (ret & MII_88E1318S_PHY_WOL_CTRL_MAGIC_PACKET_MATCH_ENABLE) 1926 wol->wolopts |= WAKE_MAGIC; 1927 1928 if (ret & MII_88E1318S_PHY_WOL_CTRL_LINK_UP_ENABLE) 1929 wol->wolopts |= WAKE_PHY; 1930 } 1931 1932 static int m88e1318_set_wol(struct phy_device *phydev, 1933 struct ethtool_wolinfo *wol) 1934 { 1935 int err = 0, oldpage; 1936 1937 oldpage = phy_save_page(phydev); 1938 if (oldpage < 0) 1939 goto error; 1940 1941 if (wol->wolopts & (WAKE_MAGIC | WAKE_PHY)) { 1942 /* Explicitly switch to page 0x00, just to be sure */ 1943 err = marvell_write_page(phydev, MII_MARVELL_COPPER_PAGE); 1944 if (err < 0) 1945 goto error; 1946 1947 /* If WOL event happened once, the LED[2] interrupt pin 1948 * will not be cleared unless we reading the interrupt status 1949 * register. If interrupts are in use, the normal interrupt 1950 * handling will clear the WOL event. Clear the WOL event 1951 * before enabling it if !phy_interrupt_is_valid() 1952 */ 1953 if (!phy_interrupt_is_valid(phydev)) 1954 __phy_read(phydev, MII_M1011_IEVENT); 1955 1956 /* Enable the WOL interrupt */ 1957 err = __phy_set_bits(phydev, MII_88E1318S_PHY_CSIER, 1958 MII_88E1318S_PHY_CSIER_WOL_EIE); 1959 if (err < 0) 1960 goto error; 1961 1962 err = marvell_write_page(phydev, MII_MARVELL_LED_PAGE); 1963 if (err < 0) 1964 goto error; 1965 1966 /* Setup LED[2] as interrupt pin (active low) */ 1967 err = __phy_modify(phydev, MII_88E1318S_PHY_LED_TCR, 1968 MII_88E1318S_PHY_LED_TCR_FORCE_INT, 1969 MII_88E1318S_PHY_LED_TCR_INTn_ENABLE | 1970 MII_88E1318S_PHY_LED_TCR_INT_ACTIVE_LOW); 1971 if (err < 0) 1972 goto error; 1973 } 1974 1975 if (wol->wolopts & WAKE_MAGIC) { 1976 err = marvell_write_page(phydev, MII_MARVELL_WOL_PAGE); 1977 if (err < 0) 1978 goto error; 1979 1980 /* Store the device address for the magic packet */ 1981 err = __phy_write(phydev, MII_88E1318S_PHY_MAGIC_PACKET_WORD2, 1982 ((phydev->attached_dev->dev_addr[5] << 8) | 1983 phydev->attached_dev->dev_addr[4])); 1984 if (err < 0) 1985 goto error; 1986 err = __phy_write(phydev, MII_88E1318S_PHY_MAGIC_PACKET_WORD1, 1987 ((phydev->attached_dev->dev_addr[3] << 8) | 1988 phydev->attached_dev->dev_addr[2])); 1989 if (err < 0) 1990 goto error; 1991 err = __phy_write(phydev, MII_88E1318S_PHY_MAGIC_PACKET_WORD0, 1992 ((phydev->attached_dev->dev_addr[1] << 8) | 1993 phydev->attached_dev->dev_addr[0])); 1994 if (err < 0) 1995 goto error; 1996 1997 /* Clear WOL status and enable magic packet matching */ 1998 err = __phy_set_bits(phydev, MII_88E1318S_PHY_WOL_CTRL, 1999 MII_88E1318S_PHY_WOL_CTRL_CLEAR_WOL_STATUS | 2000 MII_88E1318S_PHY_WOL_CTRL_MAGIC_PACKET_MATCH_ENABLE); 2001 if (err < 0) 2002 goto error; 2003 } else { 2004 err = marvell_write_page(phydev, MII_MARVELL_WOL_PAGE); 2005 if (err < 0) 2006 goto error; 2007 2008 /* Clear WOL status and disable magic packet matching */ 2009 err = __phy_modify(phydev, MII_88E1318S_PHY_WOL_CTRL, 2010 MII_88E1318S_PHY_WOL_CTRL_MAGIC_PACKET_MATCH_ENABLE, 2011 MII_88E1318S_PHY_WOL_CTRL_CLEAR_WOL_STATUS); 2012 if (err < 0) 2013 goto error; 2014 } 2015 2016 if (wol->wolopts & WAKE_PHY) { 2017 err = marvell_write_page(phydev, MII_MARVELL_WOL_PAGE); 2018 if (err < 0) 2019 goto error; 2020 2021 /* Clear WOL status and enable link up event */ 2022 err = __phy_modify(phydev, MII_88E1318S_PHY_WOL_CTRL, 0, 2023 MII_88E1318S_PHY_WOL_CTRL_CLEAR_WOL_STATUS | 2024 MII_88E1318S_PHY_WOL_CTRL_LINK_UP_ENABLE); 2025 if (err < 0) 2026 goto error; 2027 } else { 2028 err = marvell_write_page(phydev, MII_MARVELL_WOL_PAGE); 2029 if (err < 0) 2030 goto error; 2031 2032 /* Clear WOL status and disable link up event */ 2033 err = __phy_modify(phydev, MII_88E1318S_PHY_WOL_CTRL, 2034 MII_88E1318S_PHY_WOL_CTRL_LINK_UP_ENABLE, 2035 MII_88E1318S_PHY_WOL_CTRL_CLEAR_WOL_STATUS); 2036 if (err < 0) 2037 goto error; 2038 } 2039 2040 error: 2041 return phy_restore_page(phydev, oldpage, err); 2042 } 2043 2044 static int marvell_get_sset_count(struct phy_device *phydev) 2045 { 2046 if (linkmode_test_bit(ETHTOOL_LINK_MODE_FIBRE_BIT, 2047 phydev->supported)) 2048 return ARRAY_SIZE(marvell_hw_stats); 2049 else 2050 return ARRAY_SIZE(marvell_hw_stats) - NB_FIBER_STATS; 2051 } 2052 2053 static int marvell_get_sset_count_simple(struct phy_device *phydev) 2054 { 2055 return ARRAY_SIZE(marvell_hw_stats_simple); 2056 } 2057 2058 static void marvell_get_strings(struct phy_device *phydev, u8 *data) 2059 { 2060 int count = marvell_get_sset_count(phydev); 2061 int i; 2062 2063 for (i = 0; i < count; i++) 2064 ethtool_puts(&data, marvell_hw_stats[i].string); 2065 } 2066 2067 static void marvell_get_strings_simple(struct phy_device *phydev, u8 *data) 2068 { 2069 int count = marvell_get_sset_count_simple(phydev); 2070 int i; 2071 2072 for (i = 0; i < count; i++) 2073 ethtool_puts(&data, marvell_hw_stats_simple[i].string); 2074 } 2075 2076 static u64 marvell_get_stat(struct phy_device *phydev, int i) 2077 { 2078 struct marvell_hw_stat stat = marvell_hw_stats[i]; 2079 struct marvell_priv *priv = phydev->priv; 2080 int val; 2081 u64 ret; 2082 2083 val = phy_read_paged(phydev, stat.page, stat.reg); 2084 if (val < 0) { 2085 ret = U64_MAX; 2086 } else { 2087 val = val & ((1 << stat.bits) - 1); 2088 priv->stats[i] += val; 2089 ret = priv->stats[i]; 2090 } 2091 2092 return ret; 2093 } 2094 2095 static u64 marvell_get_stat_simple(struct phy_device *phydev, int i) 2096 { 2097 struct marvell_hw_stat_simple stat = marvell_hw_stats_simple[i]; 2098 struct marvell_priv *priv = phydev->priv; 2099 int val; 2100 u64 ret; 2101 2102 val = phy_read(phydev, stat.reg); 2103 if (val < 0) { 2104 ret = U64_MAX; 2105 } else { 2106 val = val & ((1 << stat.bits) - 1); 2107 priv->stats[i] += val; 2108 ret = priv->stats[i]; 2109 } 2110 2111 return ret; 2112 } 2113 2114 static void marvell_get_stats(struct phy_device *phydev, 2115 struct ethtool_stats *stats, u64 *data) 2116 { 2117 int count = marvell_get_sset_count(phydev); 2118 int i; 2119 2120 for (i = 0; i < count; i++) 2121 data[i] = marvell_get_stat(phydev, i); 2122 } 2123 2124 static void marvell_get_stats_simple(struct phy_device *phydev, 2125 struct ethtool_stats *stats, u64 *data) 2126 { 2127 int count = marvell_get_sset_count_simple(phydev); 2128 int i; 2129 2130 for (i = 0; i < count; i++) 2131 data[i] = marvell_get_stat_simple(phydev, i); 2132 } 2133 2134 static int m88e1510_loopback(struct phy_device *phydev, bool enable) 2135 { 2136 int err; 2137 2138 if (enable) { 2139 u16 bmcr_ctl, mscr2_ctl = 0; 2140 2141 bmcr_ctl = mii_bmcr_encode_fixed(phydev->speed, phydev->duplex); 2142 2143 err = phy_write(phydev, MII_BMCR, bmcr_ctl); 2144 if (err < 0) 2145 return err; 2146 2147 if (phydev->speed == SPEED_1000) 2148 mscr2_ctl = BMCR_SPEED1000; 2149 else if (phydev->speed == SPEED_100) 2150 mscr2_ctl = BMCR_SPEED100; 2151 2152 err = phy_modify_paged(phydev, MII_MARVELL_MSCR_PAGE, 2153 MII_88E1510_MSCR_2, BMCR_SPEED1000 | 2154 BMCR_SPEED100, mscr2_ctl); 2155 if (err < 0) 2156 return err; 2157 2158 /* Need soft reset to have speed configuration takes effect */ 2159 err = genphy_soft_reset(phydev); 2160 if (err < 0) 2161 return err; 2162 2163 err = phy_modify(phydev, MII_BMCR, BMCR_LOOPBACK, 2164 BMCR_LOOPBACK); 2165 2166 if (!err) { 2167 /* It takes some time for PHY device to switch 2168 * into/out-of loopback mode. 2169 */ 2170 msleep(1000); 2171 } 2172 return err; 2173 } else { 2174 err = phy_modify(phydev, MII_BMCR, BMCR_LOOPBACK, 0); 2175 if (err < 0) 2176 return err; 2177 2178 return phy_config_aneg(phydev); 2179 } 2180 } 2181 2182 static int marvell_vct5_wait_complete(struct phy_device *phydev) 2183 { 2184 int i; 2185 int val; 2186 2187 for (i = 0; i < 32; i++) { 2188 val = __phy_read(phydev, MII_VCT5_CTRL); 2189 if (val < 0) 2190 return val; 2191 2192 if (val & MII_VCT5_CTRL_COMPLETE) 2193 return 0; 2194 } 2195 2196 phydev_err(phydev, "Timeout while waiting for cable test to finish\n"); 2197 return -ETIMEDOUT; 2198 } 2199 2200 static int marvell_vct5_amplitude(struct phy_device *phydev, int pair) 2201 { 2202 int amplitude; 2203 int val; 2204 int reg; 2205 2206 reg = MII_VCT5_TX_RX_MDI0_COUPLING + pair; 2207 val = __phy_read(phydev, reg); 2208 2209 if (val < 0) 2210 return 0; 2211 2212 amplitude = (val & MII_VCT5_TX_RX_AMPLITUDE_MASK) >> 2213 MII_VCT5_TX_RX_AMPLITUDE_SHIFT; 2214 2215 if (!(val & MII_VCT5_TX_RX_COUPLING_POSITIVE_REFLECTION)) 2216 amplitude = -amplitude; 2217 2218 return 1000 * amplitude / 128; 2219 } 2220 2221 static u32 marvell_vct5_distance2cm(int distance) 2222 { 2223 return distance * 805 / 10; 2224 } 2225 2226 static u32 marvell_vct5_cm2distance(int cm) 2227 { 2228 return cm * 10 / 805; 2229 } 2230 2231 static int marvell_vct5_amplitude_distance(struct phy_device *phydev, 2232 int distance, int pair) 2233 { 2234 u16 reg; 2235 int err; 2236 int mV; 2237 int i; 2238 2239 err = __phy_write(phydev, MII_VCT5_SAMPLE_POINT_DISTANCE, 2240 distance); 2241 if (err) 2242 return err; 2243 2244 reg = MII_VCT5_CTRL_ENABLE | 2245 MII_VCT5_CTRL_TX_SAME_CHANNEL | 2246 MII_VCT5_CTRL_SAMPLES_DEFAULT | 2247 MII_VCT5_CTRL_SAMPLE_POINT | 2248 MII_VCT5_CTRL_PEEK_HYST_DEFAULT; 2249 err = __phy_write(phydev, MII_VCT5_CTRL, reg); 2250 if (err) 2251 return err; 2252 2253 err = marvell_vct5_wait_complete(phydev); 2254 if (err) 2255 return err; 2256 2257 for (i = 0; i < 4; i++) { 2258 if (pair != PHY_PAIR_ALL && i != pair) 2259 continue; 2260 2261 mV = marvell_vct5_amplitude(phydev, i); 2262 ethnl_cable_test_amplitude(phydev, i, mV); 2263 } 2264 2265 return 0; 2266 } 2267 2268 static int marvell_vct5_amplitude_graph(struct phy_device *phydev) 2269 { 2270 struct marvell_priv *priv = phydev->priv; 2271 int distance; 2272 u16 width; 2273 int page; 2274 int err; 2275 u16 reg; 2276 2277 if (priv->first <= TDR_SHORT_CABLE_LENGTH) 2278 width = MII_VCT5_TX_PULSE_CTRL_PULSE_WIDTH_32nS; 2279 else 2280 width = MII_VCT5_TX_PULSE_CTRL_PULSE_WIDTH_128nS; 2281 2282 reg = MII_VCT5_TX_PULSE_CTRL_GT_140m_46_86mV | 2283 MII_VCT5_TX_PULSE_CTRL_DONT_WAIT_LINK_DOWN | 2284 MII_VCT5_TX_PULSE_CTRL_MAX_AMP | width; 2285 2286 err = phy_write_paged(phydev, MII_MARVELL_VCT5_PAGE, 2287 MII_VCT5_TX_PULSE_CTRL, reg); 2288 if (err) 2289 return err; 2290 2291 /* Reading the TDR data is very MDIO heavy. We need to optimize 2292 * access to keep the time to a minimum. So lock the bus once, 2293 * and don't release it until complete. We can then avoid having 2294 * to change the page for every access, greatly speeding things 2295 * up. 2296 */ 2297 page = phy_select_page(phydev, MII_MARVELL_VCT5_PAGE); 2298 if (page < 0) 2299 goto restore_page; 2300 2301 for (distance = priv->first; 2302 distance <= priv->last; 2303 distance += priv->step) { 2304 err = marvell_vct5_amplitude_distance(phydev, distance, 2305 priv->pair); 2306 if (err) 2307 goto restore_page; 2308 2309 if (distance > TDR_SHORT_CABLE_LENGTH && 2310 width == MII_VCT5_TX_PULSE_CTRL_PULSE_WIDTH_32nS) { 2311 width = MII_VCT5_TX_PULSE_CTRL_PULSE_WIDTH_128nS; 2312 reg = MII_VCT5_TX_PULSE_CTRL_GT_140m_46_86mV | 2313 MII_VCT5_TX_PULSE_CTRL_DONT_WAIT_LINK_DOWN | 2314 MII_VCT5_TX_PULSE_CTRL_MAX_AMP | width; 2315 err = __phy_write(phydev, MII_VCT5_TX_PULSE_CTRL, reg); 2316 if (err) 2317 goto restore_page; 2318 } 2319 } 2320 2321 restore_page: 2322 return phy_restore_page(phydev, page, err); 2323 } 2324 2325 static int marvell_cable_test_start_common(struct phy_device *phydev) 2326 { 2327 int bmcr, bmsr, ret; 2328 2329 /* If auto-negotiation is enabled, but not complete, the cable 2330 * test never completes. So disable auto-neg. 2331 */ 2332 bmcr = phy_read(phydev, MII_BMCR); 2333 if (bmcr < 0) 2334 return bmcr; 2335 2336 bmsr = phy_read(phydev, MII_BMSR); 2337 2338 if (bmsr < 0) 2339 return bmsr; 2340 2341 if (bmcr & BMCR_ANENABLE) { 2342 ret = phy_clear_bits(phydev, MII_BMCR, BMCR_ANENABLE); 2343 if (ret < 0) 2344 return ret; 2345 ret = genphy_soft_reset(phydev); 2346 if (ret < 0) 2347 return ret; 2348 } 2349 2350 /* If the link is up, allow it some time to go down */ 2351 if (bmsr & BMSR_LSTATUS) 2352 msleep(1500); 2353 2354 return 0; 2355 } 2356 2357 static int marvell_vct7_cable_test_start(struct phy_device *phydev) 2358 { 2359 struct marvell_priv *priv = phydev->priv; 2360 int ret; 2361 2362 ret = marvell_cable_test_start_common(phydev); 2363 if (ret) 2364 return ret; 2365 2366 priv->cable_test_tdr = false; 2367 2368 /* Reset the VCT5 API control to defaults, otherwise 2369 * VCT7 does not work correctly. 2370 */ 2371 ret = phy_write_paged(phydev, MII_MARVELL_VCT5_PAGE, 2372 MII_VCT5_CTRL, 2373 MII_VCT5_CTRL_TX_SAME_CHANNEL | 2374 MII_VCT5_CTRL_SAMPLES_DEFAULT | 2375 MII_VCT5_CTRL_MODE_MAXIMUM_PEEK | 2376 MII_VCT5_CTRL_PEEK_HYST_DEFAULT); 2377 if (ret) 2378 return ret; 2379 2380 ret = phy_write_paged(phydev, MII_MARVELL_VCT5_PAGE, 2381 MII_VCT5_SAMPLE_POINT_DISTANCE, 0); 2382 if (ret) 2383 return ret; 2384 2385 return phy_write_paged(phydev, MII_MARVELL_VCT7_PAGE, 2386 MII_VCT7_CTRL, 2387 MII_VCT7_CTRL_RUN_NOW | 2388 MII_VCT7_CTRL_CENTIMETERS); 2389 } 2390 2391 static int marvell_vct5_cable_test_tdr_start(struct phy_device *phydev, 2392 const struct phy_tdr_config *cfg) 2393 { 2394 struct marvell_priv *priv = phydev->priv; 2395 int ret; 2396 2397 priv->cable_test_tdr = true; 2398 priv->first = marvell_vct5_cm2distance(cfg->first); 2399 priv->last = marvell_vct5_cm2distance(cfg->last); 2400 priv->step = marvell_vct5_cm2distance(cfg->step); 2401 priv->pair = cfg->pair; 2402 2403 if (priv->first > MII_VCT5_SAMPLE_POINT_DISTANCE_MAX) 2404 return -EINVAL; 2405 2406 if (priv->last > MII_VCT5_SAMPLE_POINT_DISTANCE_MAX) 2407 return -EINVAL; 2408 2409 /* Disable VCT7 */ 2410 ret = phy_write_paged(phydev, MII_MARVELL_VCT7_PAGE, 2411 MII_VCT7_CTRL, 0); 2412 if (ret) 2413 return ret; 2414 2415 ret = marvell_cable_test_start_common(phydev); 2416 if (ret) 2417 return ret; 2418 2419 ret = ethnl_cable_test_pulse(phydev, 1000); 2420 if (ret) 2421 return ret; 2422 2423 return ethnl_cable_test_step(phydev, 2424 marvell_vct5_distance2cm(priv->first), 2425 marvell_vct5_distance2cm(priv->last), 2426 marvell_vct5_distance2cm(priv->step)); 2427 } 2428 2429 static int marvell_vct7_distance_to_length(int distance, bool meter) 2430 { 2431 if (meter) 2432 distance *= 100; 2433 2434 return distance; 2435 } 2436 2437 static bool marvell_vct7_distance_valid(int result) 2438 { 2439 switch (result) { 2440 case MII_VCT7_RESULTS_OPEN: 2441 case MII_VCT7_RESULTS_SAME_SHORT: 2442 case MII_VCT7_RESULTS_CROSS_SHORT: 2443 return true; 2444 } 2445 return false; 2446 } 2447 2448 static int marvell_vct7_report_length(struct phy_device *phydev, 2449 int pair, bool meter) 2450 { 2451 int length; 2452 int ret; 2453 2454 ret = phy_read_paged(phydev, MII_MARVELL_VCT7_PAGE, 2455 MII_VCT7_PAIR_0_DISTANCE + pair); 2456 if (ret < 0) 2457 return ret; 2458 2459 length = marvell_vct7_distance_to_length(ret, meter); 2460 2461 ethnl_cable_test_fault_length(phydev, pair, length); 2462 2463 return 0; 2464 } 2465 2466 static int marvell_vct7_cable_test_report_trans(int result) 2467 { 2468 switch (result) { 2469 case MII_VCT7_RESULTS_OK: 2470 return ETHTOOL_A_CABLE_RESULT_CODE_OK; 2471 case MII_VCT7_RESULTS_OPEN: 2472 return ETHTOOL_A_CABLE_RESULT_CODE_OPEN; 2473 case MII_VCT7_RESULTS_SAME_SHORT: 2474 return ETHTOOL_A_CABLE_RESULT_CODE_SAME_SHORT; 2475 case MII_VCT7_RESULTS_CROSS_SHORT: 2476 return ETHTOOL_A_CABLE_RESULT_CODE_CROSS_SHORT; 2477 default: 2478 return ETHTOOL_A_CABLE_RESULT_CODE_UNSPEC; 2479 } 2480 } 2481 2482 static int marvell_vct7_cable_test_report(struct phy_device *phydev) 2483 { 2484 int pair0, pair1, pair2, pair3; 2485 bool meter; 2486 int ret; 2487 2488 ret = phy_read_paged(phydev, MII_MARVELL_VCT7_PAGE, 2489 MII_VCT7_RESULTS); 2490 if (ret < 0) 2491 return ret; 2492 2493 pair3 = (ret & MII_VCT7_RESULTS_PAIR3_MASK) >> 2494 MII_VCT7_RESULTS_PAIR3_SHIFT; 2495 pair2 = (ret & MII_VCT7_RESULTS_PAIR2_MASK) >> 2496 MII_VCT7_RESULTS_PAIR2_SHIFT; 2497 pair1 = (ret & MII_VCT7_RESULTS_PAIR1_MASK) >> 2498 MII_VCT7_RESULTS_PAIR1_SHIFT; 2499 pair0 = (ret & MII_VCT7_RESULTS_PAIR0_MASK) >> 2500 MII_VCT7_RESULTS_PAIR0_SHIFT; 2501 2502 ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_A, 2503 marvell_vct7_cable_test_report_trans(pair0)); 2504 ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_B, 2505 marvell_vct7_cable_test_report_trans(pair1)); 2506 ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_C, 2507 marvell_vct7_cable_test_report_trans(pair2)); 2508 ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_D, 2509 marvell_vct7_cable_test_report_trans(pair3)); 2510 2511 ret = phy_read_paged(phydev, MII_MARVELL_VCT7_PAGE, MII_VCT7_CTRL); 2512 if (ret < 0) 2513 return ret; 2514 2515 meter = ret & MII_VCT7_CTRL_METERS; 2516 2517 if (marvell_vct7_distance_valid(pair0)) 2518 marvell_vct7_report_length(phydev, 0, meter); 2519 if (marvell_vct7_distance_valid(pair1)) 2520 marvell_vct7_report_length(phydev, 1, meter); 2521 if (marvell_vct7_distance_valid(pair2)) 2522 marvell_vct7_report_length(phydev, 2, meter); 2523 if (marvell_vct7_distance_valid(pair3)) 2524 marvell_vct7_report_length(phydev, 3, meter); 2525 2526 return 0; 2527 } 2528 2529 static int marvell_vct7_cable_test_get_status(struct phy_device *phydev, 2530 bool *finished) 2531 { 2532 struct marvell_priv *priv = phydev->priv; 2533 int ret; 2534 2535 if (priv->cable_test_tdr) { 2536 ret = marvell_vct5_amplitude_graph(phydev); 2537 *finished = true; 2538 return ret; 2539 } 2540 2541 *finished = false; 2542 2543 ret = phy_read_paged(phydev, MII_MARVELL_VCT7_PAGE, 2544 MII_VCT7_CTRL); 2545 2546 if (ret < 0) 2547 return ret; 2548 2549 if (!(ret & MII_VCT7_CTRL_IN_PROGRESS)) { 2550 *finished = true; 2551 2552 return marvell_vct7_cable_test_report(phydev); 2553 } 2554 2555 return 0; 2556 } 2557 2558 static int m88e3082_vct_cable_test_start(struct phy_device *phydev) 2559 { 2560 struct marvell_priv *priv = phydev->priv; 2561 int ret; 2562 2563 /* It needs some magic workarounds described in VCT manual for this PHY. 2564 */ 2565 ret = phy_write(phydev, 29, 0x0003); 2566 if (ret < 0) 2567 return ret; 2568 2569 ret = phy_write(phydev, 30, 0x6440); 2570 if (ret < 0) 2571 return ret; 2572 2573 if (priv->vct_phase == M88E3082_VCT_PHASE1) { 2574 ret = phy_write(phydev, 29, 0x000a); 2575 if (ret < 0) 2576 return ret; 2577 2578 ret = phy_write(phydev, 30, 0x0002); 2579 if (ret < 0) 2580 return ret; 2581 } 2582 2583 ret = phy_write(phydev, MII_BMCR, 2584 BMCR_RESET | BMCR_SPEED100 | BMCR_FULLDPLX); 2585 if (ret < 0) 2586 return ret; 2587 2588 ret = phy_write(phydev, MII_VCT_TXPINS, MII_VCT_TXPINS_ENVCT); 2589 if (ret < 0) 2590 return ret; 2591 2592 ret = phy_write(phydev, 29, 0x0003); 2593 if (ret < 0) 2594 return ret; 2595 2596 ret = phy_write(phydev, 30, 0x0); 2597 if (ret < 0) 2598 return ret; 2599 2600 if (priv->vct_phase == M88E3082_VCT_OFF) { 2601 priv->vct_phase = M88E3082_VCT_PHASE1; 2602 priv->pair = 0; 2603 2604 return 0; 2605 } 2606 2607 ret = phy_write(phydev, 29, 0x000a); 2608 if (ret < 0) 2609 return ret; 2610 2611 ret = phy_write(phydev, 30, 0x0); 2612 if (ret < 0) 2613 return ret; 2614 2615 priv->vct_phase = M88E3082_VCT_PHASE2; 2616 2617 return 0; 2618 } 2619 2620 static int m88e3082_vct_cable_test_report_trans(int result, u8 distance) 2621 { 2622 switch (result) { 2623 case MII_VCT_TXRXPINS_VCTTST_OK: 2624 if (distance == MII_VCT_TXRXPINS_DISTRFLN_MAX) 2625 return ETHTOOL_A_CABLE_RESULT_CODE_OK; 2626 return ETHTOOL_A_CABLE_RESULT_CODE_IMPEDANCE_MISMATCH; 2627 case MII_VCT_TXRXPINS_VCTTST_SHORT: 2628 return ETHTOOL_A_CABLE_RESULT_CODE_SAME_SHORT; 2629 case MII_VCT_TXRXPINS_VCTTST_OPEN: 2630 return ETHTOOL_A_CABLE_RESULT_CODE_OPEN; 2631 default: 2632 return ETHTOOL_A_CABLE_RESULT_CODE_UNSPEC; 2633 } 2634 } 2635 2636 static u32 m88e3082_vct_distrfln_2_cm(u8 distrfln) 2637 { 2638 if (distrfln < 24) 2639 return 0; 2640 2641 /* Original function for meters: y = 0.7861x - 18.862 */ 2642 return (7861 * distrfln - 188620) / 100; 2643 } 2644 2645 static int m88e3082_vct_cable_test_get_status(struct phy_device *phydev, 2646 bool *finished) 2647 { 2648 u8 tx_vcttst_res, rx_vcttst_res, tx_distrfln, rx_distrfln; 2649 struct marvell_priv *priv = phydev->priv; 2650 int ret, tx_result, rx_result; 2651 bool done_phase = true; 2652 2653 *finished = false; 2654 2655 ret = phy_read(phydev, MII_VCT_TXPINS); 2656 if (ret < 0) 2657 return ret; 2658 else if (ret & MII_VCT_TXPINS_ENVCT) 2659 return 0; 2660 2661 tx_distrfln = ret & MII_VCT_TXRXPINS_DISTRFLN; 2662 tx_vcttst_res = (ret & MII_VCT_TXRXPINS_VCTTST) >> 2663 MII_VCT_TXRXPINS_VCTTST_SHIFT; 2664 2665 ret = phy_read(phydev, MII_VCT_RXPINS); 2666 if (ret < 0) 2667 return ret; 2668 2669 rx_distrfln = ret & MII_VCT_TXRXPINS_DISTRFLN; 2670 rx_vcttst_res = (ret & MII_VCT_TXRXPINS_VCTTST) >> 2671 MII_VCT_TXRXPINS_VCTTST_SHIFT; 2672 2673 *finished = true; 2674 2675 switch (priv->vct_phase) { 2676 case M88E3082_VCT_PHASE1: 2677 tx_result = m88e3082_vct_cable_test_report_trans(tx_vcttst_res, 2678 tx_distrfln); 2679 rx_result = m88e3082_vct_cable_test_report_trans(rx_vcttst_res, 2680 rx_distrfln); 2681 2682 ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_A, 2683 tx_result); 2684 ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_B, 2685 rx_result); 2686 2687 if (tx_vcttst_res == MII_VCT_TXRXPINS_VCTTST_OPEN) { 2688 done_phase = false; 2689 priv->pair |= M88E3082_PAIR_A; 2690 } else if (tx_distrfln < MII_VCT_TXRXPINS_DISTRFLN_MAX) { 2691 u8 pair = ETHTOOL_A_CABLE_PAIR_A; 2692 u32 cm = m88e3082_vct_distrfln_2_cm(tx_distrfln); 2693 2694 ethnl_cable_test_fault_length(phydev, pair, cm); 2695 } 2696 2697 if (rx_vcttst_res == MII_VCT_TXRXPINS_VCTTST_OPEN) { 2698 done_phase = false; 2699 priv->pair |= M88E3082_PAIR_B; 2700 } else if (rx_distrfln < MII_VCT_TXRXPINS_DISTRFLN_MAX) { 2701 u8 pair = ETHTOOL_A_CABLE_PAIR_B; 2702 u32 cm = m88e3082_vct_distrfln_2_cm(rx_distrfln); 2703 2704 ethnl_cable_test_fault_length(phydev, pair, cm); 2705 } 2706 2707 break; 2708 case M88E3082_VCT_PHASE2: 2709 if (priv->pair & M88E3082_PAIR_A && 2710 tx_vcttst_res == MII_VCT_TXRXPINS_VCTTST_OPEN && 2711 tx_distrfln < MII_VCT_TXRXPINS_DISTRFLN_MAX) { 2712 u8 pair = ETHTOOL_A_CABLE_PAIR_A; 2713 u32 cm = m88e3082_vct_distrfln_2_cm(tx_distrfln); 2714 2715 ethnl_cable_test_fault_length(phydev, pair, cm); 2716 } 2717 if (priv->pair & M88E3082_PAIR_B && 2718 rx_vcttst_res == MII_VCT_TXRXPINS_VCTTST_OPEN && 2719 rx_distrfln < MII_VCT_TXRXPINS_DISTRFLN_MAX) { 2720 u8 pair = ETHTOOL_A_CABLE_PAIR_B; 2721 u32 cm = m88e3082_vct_distrfln_2_cm(rx_distrfln); 2722 2723 ethnl_cable_test_fault_length(phydev, pair, cm); 2724 } 2725 2726 break; 2727 default: 2728 return -EINVAL; 2729 } 2730 2731 if (!done_phase) { 2732 *finished = false; 2733 return m88e3082_vct_cable_test_start(phydev); 2734 } 2735 if (*finished) 2736 priv->vct_phase = M88E3082_VCT_OFF; 2737 return 0; 2738 } 2739 2740 static int m88e1111_vct_cable_test_start(struct phy_device *phydev) 2741 { 2742 int ret; 2743 2744 ret = marvell_cable_test_start_common(phydev); 2745 if (ret) 2746 return ret; 2747 2748 /* It needs some magic workarounds described in VCT manual for this PHY. 2749 */ 2750 ret = phy_write(phydev, 29, 0x0018); 2751 if (ret < 0) 2752 return ret; 2753 2754 ret = phy_write(phydev, 30, 0x00c2); 2755 if (ret < 0) 2756 return ret; 2757 2758 ret = phy_write(phydev, 30, 0x00ca); 2759 if (ret < 0) 2760 return ret; 2761 2762 ret = phy_write(phydev, 30, 0x00c2); 2763 if (ret < 0) 2764 return ret; 2765 2766 ret = phy_write_paged(phydev, MII_MARVELL_COPPER_PAGE, MII_VCT_SR, 2767 MII_VCT_TXPINS_ENVCT); 2768 if (ret < 0) 2769 return ret; 2770 2771 ret = phy_write(phydev, 29, 0x0018); 2772 if (ret < 0) 2773 return ret; 2774 2775 ret = phy_write(phydev, 30, 0x0042); 2776 if (ret < 0) 2777 return ret; 2778 2779 return 0; 2780 } 2781 2782 static u32 m88e1111_vct_distrfln_2_cm(u8 distrfln) 2783 { 2784 if (distrfln < 36) 2785 return 0; 2786 2787 /* Original function for meters: y = 0.8018x - 28.751 */ 2788 return (8018 * distrfln - 287510) / 100; 2789 } 2790 2791 static int m88e1111_vct_cable_test_get_status(struct phy_device *phydev, 2792 bool *finished) 2793 { 2794 u8 vcttst_res, distrfln; 2795 int ret, result; 2796 2797 *finished = false; 2798 2799 /* Each pair use one page: A-0, B-1, C-2, D-3 */ 2800 for (u8 i = 0; i < 4; i++) { 2801 ret = phy_read_paged(phydev, i, MII_VCT_SR); 2802 if (ret < 0) 2803 return ret; 2804 else if (i == 0 && ret & MII_VCT_TXPINS_ENVCT) 2805 return 0; 2806 2807 distrfln = ret & MII_VCT_TXRXPINS_DISTRFLN; 2808 vcttst_res = (ret & MII_VCT_TXRXPINS_VCTTST) >> 2809 MII_VCT_TXRXPINS_VCTTST_SHIFT; 2810 2811 result = m88e3082_vct_cable_test_report_trans(vcttst_res, 2812 distrfln); 2813 ethnl_cable_test_result(phydev, i, result); 2814 2815 if (distrfln < MII_VCT_TXRXPINS_DISTRFLN_MAX) { 2816 u32 cm = m88e1111_vct_distrfln_2_cm(distrfln); 2817 2818 ethnl_cable_test_fault_length(phydev, i, cm); 2819 } 2820 } 2821 2822 *finished = true; 2823 return 0; 2824 } 2825 2826 #ifdef CONFIG_HWMON 2827 struct marvell_hwmon_ops { 2828 int (*config)(struct phy_device *phydev); 2829 int (*get_temp)(struct phy_device *phydev, long *temp); 2830 int (*get_temp_critical)(struct phy_device *phydev, long *temp); 2831 int (*set_temp_critical)(struct phy_device *phydev, long temp); 2832 int (*get_temp_alarm)(struct phy_device *phydev, long *alarm); 2833 }; 2834 2835 static const struct marvell_hwmon_ops * 2836 to_marvell_hwmon_ops(const struct phy_device *phydev) 2837 { 2838 return phydev->drv->driver_data; 2839 } 2840 2841 static int m88e1121_get_temp(struct phy_device *phydev, long *temp) 2842 { 2843 int oldpage; 2844 int ret = 0; 2845 int val; 2846 2847 *temp = 0; 2848 2849 oldpage = phy_select_page(phydev, MII_MARVELL_MISC_TEST_PAGE); 2850 if (oldpage < 0) 2851 goto error; 2852 2853 /* Enable temperature sensor */ 2854 ret = __phy_read(phydev, MII_88E1121_MISC_TEST); 2855 if (ret < 0) 2856 goto error; 2857 2858 ret = __phy_write(phydev, MII_88E1121_MISC_TEST, 2859 ret | MII_88E1121_MISC_TEST_TEMP_SENSOR_EN); 2860 if (ret < 0) 2861 goto error; 2862 2863 /* Wait for temperature to stabilize */ 2864 usleep_range(10000, 12000); 2865 2866 val = __phy_read(phydev, MII_88E1121_MISC_TEST); 2867 if (val < 0) { 2868 ret = val; 2869 goto error; 2870 } 2871 2872 /* Disable temperature sensor */ 2873 ret = __phy_write(phydev, MII_88E1121_MISC_TEST, 2874 ret & ~MII_88E1121_MISC_TEST_TEMP_SENSOR_EN); 2875 if (ret < 0) 2876 goto error; 2877 2878 *temp = ((val & MII_88E1121_MISC_TEST_TEMP_MASK) - 5) * 5000; 2879 2880 error: 2881 return phy_restore_page(phydev, oldpage, ret); 2882 } 2883 2884 static int m88e1510_get_temp(struct phy_device *phydev, long *temp) 2885 { 2886 int ret; 2887 2888 *temp = 0; 2889 2890 ret = phy_read_paged(phydev, MII_MARVELL_MISC_TEST_PAGE, 2891 MII_88E1510_TEMP_SENSOR); 2892 if (ret < 0) 2893 return ret; 2894 2895 *temp = ((ret & MII_88E1510_TEMP_SENSOR_MASK) - 25) * 1000; 2896 2897 return 0; 2898 } 2899 2900 static int m88e1510_get_temp_critical(struct phy_device *phydev, long *temp) 2901 { 2902 int ret; 2903 2904 *temp = 0; 2905 2906 ret = phy_read_paged(phydev, MII_MARVELL_MISC_TEST_PAGE, 2907 MII_88E1121_MISC_TEST); 2908 if (ret < 0) 2909 return ret; 2910 2911 *temp = (((ret & MII_88E1510_MISC_TEST_TEMP_THRESHOLD_MASK) >> 2912 MII_88E1510_MISC_TEST_TEMP_THRESHOLD_SHIFT) * 5) - 25; 2913 /* convert to mC */ 2914 *temp *= 1000; 2915 2916 return 0; 2917 } 2918 2919 static int m88e1510_set_temp_critical(struct phy_device *phydev, long temp) 2920 { 2921 temp = temp / 1000; 2922 temp = clamp_val(DIV_ROUND_CLOSEST(temp, 5) + 5, 0, 0x1f); 2923 2924 return phy_modify_paged(phydev, MII_MARVELL_MISC_TEST_PAGE, 2925 MII_88E1121_MISC_TEST, 2926 MII_88E1510_MISC_TEST_TEMP_THRESHOLD_MASK, 2927 temp << MII_88E1510_MISC_TEST_TEMP_THRESHOLD_SHIFT); 2928 } 2929 2930 static int m88e1510_get_temp_alarm(struct phy_device *phydev, long *alarm) 2931 { 2932 int ret; 2933 2934 *alarm = false; 2935 2936 ret = phy_read_paged(phydev, MII_MARVELL_MISC_TEST_PAGE, 2937 MII_88E1121_MISC_TEST); 2938 if (ret < 0) 2939 return ret; 2940 2941 *alarm = !!(ret & MII_88E1510_MISC_TEST_TEMP_IRQ); 2942 2943 return 0; 2944 } 2945 2946 static int m88e6390_get_temp(struct phy_device *phydev, long *temp) 2947 { 2948 int sum = 0; 2949 int oldpage; 2950 int ret = 0; 2951 int i; 2952 2953 *temp = 0; 2954 2955 oldpage = phy_select_page(phydev, MII_MARVELL_MISC_TEST_PAGE); 2956 if (oldpage < 0) 2957 goto error; 2958 2959 /* Enable temperature sensor */ 2960 ret = __phy_read(phydev, MII_88E6390_MISC_TEST); 2961 if (ret < 0) 2962 goto error; 2963 2964 ret &= ~MII_88E6390_MISC_TEST_TEMP_SENSOR_MASK; 2965 ret |= MII_88E6390_MISC_TEST_TEMP_SENSOR_ENABLE_SAMPLE_1S; 2966 2967 ret = __phy_write(phydev, MII_88E6390_MISC_TEST, ret); 2968 if (ret < 0) 2969 goto error; 2970 2971 /* Wait for temperature to stabilize */ 2972 usleep_range(10000, 12000); 2973 2974 /* Reading the temperature sense has an errata. You need to read 2975 * a number of times and take an average. 2976 */ 2977 for (i = 0; i < MII_88E6390_TEMP_SENSOR_SAMPLES; i++) { 2978 ret = __phy_read(phydev, MII_88E6390_TEMP_SENSOR); 2979 if (ret < 0) 2980 goto error; 2981 sum += ret & MII_88E6390_TEMP_SENSOR_MASK; 2982 } 2983 2984 sum /= MII_88E6390_TEMP_SENSOR_SAMPLES; 2985 *temp = (sum - 75) * 1000; 2986 2987 /* Disable temperature sensor */ 2988 ret = __phy_read(phydev, MII_88E6390_MISC_TEST); 2989 if (ret < 0) 2990 goto error; 2991 2992 ret = ret & ~MII_88E6390_MISC_TEST_TEMP_SENSOR_MASK; 2993 ret |= MII_88E6390_MISC_TEST_TEMP_SENSOR_DISABLE; 2994 2995 ret = __phy_write(phydev, MII_88E6390_MISC_TEST, ret); 2996 2997 error: 2998 phy_restore_page(phydev, oldpage, ret); 2999 3000 return ret; 3001 } 3002 3003 static int m88e6393_get_temp(struct phy_device *phydev, long *temp) 3004 { 3005 int err; 3006 3007 err = m88e1510_get_temp(phydev, temp); 3008 3009 /* 88E1510 measures T + 25, while the PHY on 88E6393X switch 3010 * T + 75, so we have to subtract another 50 3011 */ 3012 *temp -= 50000; 3013 3014 return err; 3015 } 3016 3017 static int m88e6393_get_temp_critical(struct phy_device *phydev, long *temp) 3018 { 3019 int ret; 3020 3021 *temp = 0; 3022 3023 ret = phy_read_paged(phydev, MII_MARVELL_MISC_TEST_PAGE, 3024 MII_88E6390_TEMP_SENSOR); 3025 if (ret < 0) 3026 return ret; 3027 3028 *temp = (((ret & MII_88E6393_TEMP_SENSOR_THRESHOLD_MASK) >> 3029 MII_88E6393_TEMP_SENSOR_THRESHOLD_SHIFT) - 75) * 1000; 3030 3031 return 0; 3032 } 3033 3034 static int m88e6393_set_temp_critical(struct phy_device *phydev, long temp) 3035 { 3036 temp = (temp / 1000) + 75; 3037 3038 return phy_modify_paged(phydev, MII_MARVELL_MISC_TEST_PAGE, 3039 MII_88E6390_TEMP_SENSOR, 3040 MII_88E6393_TEMP_SENSOR_THRESHOLD_MASK, 3041 temp << MII_88E6393_TEMP_SENSOR_THRESHOLD_SHIFT); 3042 } 3043 3044 static int m88e6393_hwmon_config(struct phy_device *phydev) 3045 { 3046 int err; 3047 3048 err = m88e6393_set_temp_critical(phydev, 100000); 3049 if (err) 3050 return err; 3051 3052 return phy_modify_paged(phydev, MII_MARVELL_MISC_TEST_PAGE, 3053 MII_88E6390_MISC_TEST, 3054 MII_88E6390_MISC_TEST_TEMP_SENSOR_MASK | 3055 MII_88E6393_MISC_TEST_SAMPLES_MASK | 3056 MII_88E6393_MISC_TEST_RATE_MASK, 3057 MII_88E6390_MISC_TEST_TEMP_SENSOR_ENABLE | 3058 MII_88E6393_MISC_TEST_SAMPLES_2048 | 3059 MII_88E6393_MISC_TEST_RATE_2_3MS); 3060 } 3061 3062 static int marvell_hwmon_read(struct device *dev, enum hwmon_sensor_types type, 3063 u32 attr, int channel, long *temp) 3064 { 3065 struct phy_device *phydev = dev_get_drvdata(dev); 3066 const struct marvell_hwmon_ops *ops = to_marvell_hwmon_ops(phydev); 3067 int err = -EOPNOTSUPP; 3068 3069 switch (attr) { 3070 case hwmon_temp_input: 3071 if (ops->get_temp) 3072 err = ops->get_temp(phydev, temp); 3073 break; 3074 case hwmon_temp_crit: 3075 if (ops->get_temp_critical) 3076 err = ops->get_temp_critical(phydev, temp); 3077 break; 3078 case hwmon_temp_max_alarm: 3079 if (ops->get_temp_alarm) 3080 err = ops->get_temp_alarm(phydev, temp); 3081 break; 3082 } 3083 3084 return err; 3085 } 3086 3087 static int marvell_hwmon_write(struct device *dev, enum hwmon_sensor_types type, 3088 u32 attr, int channel, long temp) 3089 { 3090 struct phy_device *phydev = dev_get_drvdata(dev); 3091 const struct marvell_hwmon_ops *ops = to_marvell_hwmon_ops(phydev); 3092 int err = -EOPNOTSUPP; 3093 3094 switch (attr) { 3095 case hwmon_temp_crit: 3096 if (ops->set_temp_critical) 3097 err = ops->set_temp_critical(phydev, temp); 3098 break; 3099 } 3100 3101 return err; 3102 } 3103 3104 static umode_t marvell_hwmon_is_visible(const void *data, 3105 enum hwmon_sensor_types type, 3106 u32 attr, int channel) 3107 { 3108 const struct phy_device *phydev = data; 3109 const struct marvell_hwmon_ops *ops = to_marvell_hwmon_ops(phydev); 3110 3111 if (type != hwmon_temp) 3112 return 0; 3113 3114 switch (attr) { 3115 case hwmon_temp_input: 3116 return ops->get_temp ? 0444 : 0; 3117 case hwmon_temp_max_alarm: 3118 return ops->get_temp_alarm ? 0444 : 0; 3119 case hwmon_temp_crit: 3120 return (ops->get_temp_critical ? 0444 : 0) | 3121 (ops->set_temp_critical ? 0200 : 0); 3122 default: 3123 return 0; 3124 } 3125 } 3126 3127 static u32 marvell_hwmon_chip_config[] = { 3128 HWMON_C_REGISTER_TZ, 3129 0 3130 }; 3131 3132 static const struct hwmon_channel_info marvell_hwmon_chip = { 3133 .type = hwmon_chip, 3134 .config = marvell_hwmon_chip_config, 3135 }; 3136 3137 /* we can define HWMON_T_CRIT and HWMON_T_MAX_ALARM even though these are not 3138 * defined for all PHYs, because the hwmon code checks whether the attributes 3139 * exists via the .is_visible method 3140 */ 3141 static u32 marvell_hwmon_temp_config[] = { 3142 HWMON_T_INPUT | HWMON_T_CRIT | HWMON_T_MAX_ALARM, 3143 0 3144 }; 3145 3146 static const struct hwmon_channel_info marvell_hwmon_temp = { 3147 .type = hwmon_temp, 3148 .config = marvell_hwmon_temp_config, 3149 }; 3150 3151 static const struct hwmon_channel_info * const marvell_hwmon_info[] = { 3152 &marvell_hwmon_chip, 3153 &marvell_hwmon_temp, 3154 NULL 3155 }; 3156 3157 static const struct hwmon_ops marvell_hwmon_hwmon_ops = { 3158 .is_visible = marvell_hwmon_is_visible, 3159 .read = marvell_hwmon_read, 3160 .write = marvell_hwmon_write, 3161 }; 3162 3163 static const struct hwmon_chip_info marvell_hwmon_chip_info = { 3164 .ops = &marvell_hwmon_hwmon_ops, 3165 .info = marvell_hwmon_info, 3166 }; 3167 3168 static int marvell_hwmon_name(struct phy_device *phydev) 3169 { 3170 struct marvell_priv *priv = phydev->priv; 3171 struct device *dev = &phydev->mdio.dev; 3172 const char *devname = dev_name(dev); 3173 size_t len = strlen(devname); 3174 int i, j; 3175 3176 priv->hwmon_name = devm_kzalloc(dev, len, GFP_KERNEL); 3177 if (!priv->hwmon_name) 3178 return -ENOMEM; 3179 3180 for (i = j = 0; i < len && devname[i]; i++) { 3181 if (isalnum(devname[i])) 3182 priv->hwmon_name[j++] = devname[i]; 3183 } 3184 3185 return 0; 3186 } 3187 3188 static int marvell_hwmon_probe(struct phy_device *phydev) 3189 { 3190 const struct marvell_hwmon_ops *ops = to_marvell_hwmon_ops(phydev); 3191 struct marvell_priv *priv = phydev->priv; 3192 struct device *dev = &phydev->mdio.dev; 3193 int err; 3194 3195 if (!ops) 3196 return 0; 3197 3198 err = marvell_hwmon_name(phydev); 3199 if (err) 3200 return err; 3201 3202 priv->hwmon_dev = devm_hwmon_device_register_with_info( 3203 dev, priv->hwmon_name, phydev, &marvell_hwmon_chip_info, NULL); 3204 if (IS_ERR(priv->hwmon_dev)) 3205 return PTR_ERR(priv->hwmon_dev); 3206 3207 if (ops->config) 3208 err = ops->config(phydev); 3209 3210 return err; 3211 } 3212 3213 static const struct marvell_hwmon_ops m88e1121_hwmon_ops = { 3214 .get_temp = m88e1121_get_temp, 3215 }; 3216 3217 static const struct marvell_hwmon_ops m88e1510_hwmon_ops = { 3218 .get_temp = m88e1510_get_temp, 3219 .get_temp_critical = m88e1510_get_temp_critical, 3220 .set_temp_critical = m88e1510_set_temp_critical, 3221 .get_temp_alarm = m88e1510_get_temp_alarm, 3222 }; 3223 3224 static const struct marvell_hwmon_ops m88e6390_hwmon_ops = { 3225 .get_temp = m88e6390_get_temp, 3226 }; 3227 3228 static const struct marvell_hwmon_ops m88e6393_hwmon_ops = { 3229 .config = m88e6393_hwmon_config, 3230 .get_temp = m88e6393_get_temp, 3231 .get_temp_critical = m88e6393_get_temp_critical, 3232 .set_temp_critical = m88e6393_set_temp_critical, 3233 .get_temp_alarm = m88e1510_get_temp_alarm, 3234 }; 3235 3236 #define DEF_MARVELL_HWMON_OPS(s) (&(s)) 3237 3238 #else 3239 3240 #define DEF_MARVELL_HWMON_OPS(s) NULL 3241 3242 static int marvell_hwmon_probe(struct phy_device *phydev) 3243 { 3244 return 0; 3245 } 3246 #endif 3247 3248 static int m88e1318_led_brightness_set(struct phy_device *phydev, 3249 u8 index, enum led_brightness value) 3250 { 3251 int reg; 3252 3253 reg = phy_read_paged(phydev, MII_MARVELL_LED_PAGE, 3254 MII_88E1318S_PHY_LED_FUNC); 3255 if (reg < 0) 3256 return reg; 3257 3258 switch (index) { 3259 case 0: 3260 case 1: 3261 case 2: 3262 reg &= ~(0xf << (4 * index)); 3263 if (value == LED_OFF) 3264 reg |= MII_88E1318S_PHY_LED_FUNC_OFF << (4 * index); 3265 else 3266 reg |= MII_88E1318S_PHY_LED_FUNC_ON << (4 * index); 3267 break; 3268 default: 3269 return -EINVAL; 3270 } 3271 3272 return phy_write_paged(phydev, MII_MARVELL_LED_PAGE, 3273 MII_88E1318S_PHY_LED_FUNC, reg); 3274 } 3275 3276 static int m88e1318_led_blink_set(struct phy_device *phydev, u8 index, 3277 unsigned long *delay_on, 3278 unsigned long *delay_off) 3279 { 3280 int reg; 3281 3282 reg = phy_read_paged(phydev, MII_MARVELL_LED_PAGE, 3283 MII_88E1318S_PHY_LED_FUNC); 3284 if (reg < 0) 3285 return reg; 3286 3287 switch (index) { 3288 case 0: 3289 case 1: 3290 case 2: 3291 reg &= ~(0xf << (4 * index)); 3292 reg |= MII_88E1318S_PHY_LED_FUNC_BLINK << (4 * index); 3293 /* Reset default is 84ms */ 3294 *delay_on = 84 / 2; 3295 *delay_off = 84 / 2; 3296 break; 3297 default: 3298 return -EINVAL; 3299 } 3300 3301 return phy_write_paged(phydev, MII_MARVELL_LED_PAGE, 3302 MII_88E1318S_PHY_LED_FUNC, reg); 3303 } 3304 3305 struct marvell_led_rules { 3306 int mode; 3307 unsigned long rules; 3308 }; 3309 3310 static const struct marvell_led_rules marvell_led0[] = { 3311 { 3312 .mode = 0, 3313 .rules = BIT(TRIGGER_NETDEV_LINK), 3314 }, 3315 { 3316 .mode = 1, 3317 .rules = (BIT(TRIGGER_NETDEV_LINK) | 3318 BIT(TRIGGER_NETDEV_RX) | 3319 BIT(TRIGGER_NETDEV_TX)), 3320 }, 3321 { 3322 .mode = 3, 3323 .rules = (BIT(TRIGGER_NETDEV_RX) | 3324 BIT(TRIGGER_NETDEV_TX)), 3325 }, 3326 { 3327 .mode = 4, 3328 .rules = (BIT(TRIGGER_NETDEV_RX) | 3329 BIT(TRIGGER_NETDEV_TX)), 3330 }, 3331 { 3332 .mode = 5, 3333 .rules = BIT(TRIGGER_NETDEV_TX), 3334 }, 3335 { 3336 .mode = 6, 3337 .rules = BIT(TRIGGER_NETDEV_LINK), 3338 }, 3339 { 3340 .mode = 7, 3341 .rules = BIT(TRIGGER_NETDEV_LINK_1000), 3342 }, 3343 { 3344 .mode = 8, 3345 .rules = 0, 3346 }, 3347 }; 3348 3349 static const struct marvell_led_rules marvell_led1[] = { 3350 { 3351 .mode = 1, 3352 .rules = (BIT(TRIGGER_NETDEV_LINK) | 3353 BIT(TRIGGER_NETDEV_RX) | 3354 BIT(TRIGGER_NETDEV_TX)), 3355 }, 3356 { 3357 .mode = 2, 3358 .rules = (BIT(TRIGGER_NETDEV_LINK) | 3359 BIT(TRIGGER_NETDEV_RX)), 3360 }, 3361 { 3362 .mode = 3, 3363 .rules = (BIT(TRIGGER_NETDEV_RX) | 3364 BIT(TRIGGER_NETDEV_TX)), 3365 }, 3366 { 3367 .mode = 4, 3368 .rules = (BIT(TRIGGER_NETDEV_RX) | 3369 BIT(TRIGGER_NETDEV_TX)), 3370 }, 3371 { 3372 .mode = 6, 3373 .rules = (BIT(TRIGGER_NETDEV_LINK_100) | 3374 BIT(TRIGGER_NETDEV_LINK_1000)), 3375 }, 3376 { 3377 .mode = 7, 3378 .rules = BIT(TRIGGER_NETDEV_LINK_100), 3379 }, 3380 { 3381 .mode = 8, 3382 .rules = 0, 3383 }, 3384 }; 3385 3386 static const struct marvell_led_rules marvell_led2[] = { 3387 { 3388 .mode = 0, 3389 .rules = BIT(TRIGGER_NETDEV_LINK), 3390 }, 3391 { 3392 .mode = 1, 3393 .rules = (BIT(TRIGGER_NETDEV_LINK) | 3394 BIT(TRIGGER_NETDEV_RX) | 3395 BIT(TRIGGER_NETDEV_TX)), 3396 }, 3397 { 3398 .mode = 3, 3399 .rules = (BIT(TRIGGER_NETDEV_RX) | 3400 BIT(TRIGGER_NETDEV_TX)), 3401 }, 3402 { 3403 .mode = 4, 3404 .rules = (BIT(TRIGGER_NETDEV_RX) | 3405 BIT(TRIGGER_NETDEV_TX)), 3406 }, 3407 { 3408 .mode = 5, 3409 .rules = BIT(TRIGGER_NETDEV_TX), 3410 }, 3411 { 3412 .mode = 6, 3413 .rules = (BIT(TRIGGER_NETDEV_LINK_10) | 3414 BIT(TRIGGER_NETDEV_LINK_1000)), 3415 }, 3416 { 3417 .mode = 7, 3418 .rules = BIT(TRIGGER_NETDEV_LINK_10), 3419 }, 3420 { 3421 .mode = 8, 3422 .rules = 0, 3423 }, 3424 }; 3425 3426 static int marvell_find_led_mode(unsigned long rules, 3427 const struct marvell_led_rules *marvell_rules, 3428 int count, 3429 int *mode) 3430 { 3431 int i; 3432 3433 for (i = 0; i < count; i++) { 3434 if (marvell_rules[i].rules == rules) { 3435 *mode = marvell_rules[i].mode; 3436 return 0; 3437 } 3438 } 3439 return -EOPNOTSUPP; 3440 } 3441 3442 static int marvell_get_led_mode(u8 index, unsigned long rules, int *mode) 3443 { 3444 int ret; 3445 3446 switch (index) { 3447 case 0: 3448 ret = marvell_find_led_mode(rules, marvell_led0, 3449 ARRAY_SIZE(marvell_led0), mode); 3450 break; 3451 case 1: 3452 ret = marvell_find_led_mode(rules, marvell_led1, 3453 ARRAY_SIZE(marvell_led1), mode); 3454 break; 3455 case 2: 3456 ret = marvell_find_led_mode(rules, marvell_led2, 3457 ARRAY_SIZE(marvell_led2), mode); 3458 break; 3459 default: 3460 ret = -EINVAL; 3461 } 3462 3463 return ret; 3464 } 3465 3466 static int marvell_find_led_rules(unsigned long *rules, 3467 const struct marvell_led_rules *marvell_rules, 3468 int count, 3469 int mode) 3470 { 3471 int i; 3472 3473 for (i = 0; i < count; i++) { 3474 if (marvell_rules[i].mode == mode) { 3475 *rules = marvell_rules[i].rules; 3476 return 0; 3477 } 3478 } 3479 return -EOPNOTSUPP; 3480 } 3481 3482 static int marvell_get_led_rules(u8 index, unsigned long *rules, int mode) 3483 { 3484 int ret; 3485 3486 switch (index) { 3487 case 0: 3488 ret = marvell_find_led_rules(rules, marvell_led0, 3489 ARRAY_SIZE(marvell_led0), mode); 3490 break; 3491 case 1: 3492 ret = marvell_find_led_rules(rules, marvell_led1, 3493 ARRAY_SIZE(marvell_led1), mode); 3494 break; 3495 case 2: 3496 ret = marvell_find_led_rules(rules, marvell_led2, 3497 ARRAY_SIZE(marvell_led2), mode); 3498 break; 3499 default: 3500 ret = -EOPNOTSUPP; 3501 } 3502 3503 return ret; 3504 } 3505 3506 static int m88e1318_led_hw_is_supported(struct phy_device *phydev, u8 index, 3507 unsigned long rules) 3508 { 3509 int mode, ret; 3510 3511 switch (index) { 3512 case 0: 3513 case 1: 3514 case 2: 3515 ret = marvell_get_led_mode(index, rules, &mode); 3516 break; 3517 default: 3518 ret = -EINVAL; 3519 } 3520 3521 return ret; 3522 } 3523 3524 static int m88e1318_led_hw_control_set(struct phy_device *phydev, u8 index, 3525 unsigned long rules) 3526 { 3527 int mode, ret, reg; 3528 3529 switch (index) { 3530 case 0: 3531 case 1: 3532 case 2: 3533 ret = marvell_get_led_mode(index, rules, &mode); 3534 break; 3535 default: 3536 ret = -EINVAL; 3537 } 3538 3539 if (ret < 0) 3540 return ret; 3541 3542 reg = phy_read_paged(phydev, MII_MARVELL_LED_PAGE, 3543 MII_88E1318S_PHY_LED_FUNC); 3544 if (reg < 0) 3545 return reg; 3546 3547 reg &= ~(0xf << (4 * index)); 3548 reg |= mode << (4 * index); 3549 return phy_write_paged(phydev, MII_MARVELL_LED_PAGE, 3550 MII_88E1318S_PHY_LED_FUNC, reg); 3551 } 3552 3553 static int m88e1318_led_hw_control_get(struct phy_device *phydev, u8 index, 3554 unsigned long *rules) 3555 { 3556 int mode, reg; 3557 3558 if (index > 2) 3559 return -EINVAL; 3560 3561 reg = phy_read_paged(phydev, MII_MARVELL_LED_PAGE, 3562 MII_88E1318S_PHY_LED_FUNC); 3563 if (reg < 0) 3564 return reg; 3565 3566 mode = (reg >> (4 * index)) & 0xf; 3567 3568 return marvell_get_led_rules(index, rules, mode); 3569 } 3570 3571 static int marvell_probe(struct phy_device *phydev) 3572 { 3573 struct marvell_priv *priv; 3574 3575 priv = devm_kzalloc(&phydev->mdio.dev, sizeof(*priv), GFP_KERNEL); 3576 if (!priv) 3577 return -ENOMEM; 3578 3579 phydev->priv = priv; 3580 3581 return marvell_hwmon_probe(phydev); 3582 } 3583 3584 static int m88e1510_sfp_insert(void *upstream, const struct sfp_eeprom_id *id) 3585 { 3586 DECLARE_PHY_INTERFACE_MASK(interfaces); 3587 struct phy_device *phydev = upstream; 3588 phy_interface_t interface; 3589 struct device *dev; 3590 int oldpage; 3591 int ret = 0; 3592 u16 mode; 3593 3594 __ETHTOOL_DECLARE_LINK_MODE_MASK(supported) = { 0, }; 3595 3596 dev = &phydev->mdio.dev; 3597 3598 sfp_parse_support(phydev->sfp_bus, id, supported, interfaces); 3599 interface = sfp_select_interface(phydev->sfp_bus, supported); 3600 3601 dev_info(dev, "%s SFP module inserted\n", phy_modes(interface)); 3602 3603 switch (interface) { 3604 case PHY_INTERFACE_MODE_1000BASEX: 3605 mode = MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII_1000X; 3606 3607 break; 3608 case PHY_INTERFACE_MODE_100BASEX: 3609 mode = MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII_100FX; 3610 3611 break; 3612 case PHY_INTERFACE_MODE_SGMII: 3613 mode = MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII_SGMII; 3614 3615 break; 3616 default: 3617 dev_err(dev, "Incompatible SFP module inserted\n"); 3618 3619 return -EINVAL; 3620 } 3621 3622 oldpage = phy_select_page(phydev, MII_MARVELL_MODE_PAGE); 3623 if (oldpage < 0) 3624 goto error; 3625 3626 ret = __phy_modify(phydev, MII_88E1510_GEN_CTRL_REG_1, 3627 MII_88E1510_GEN_CTRL_REG_1_MODE_MASK, mode); 3628 if (ret < 0) 3629 goto error; 3630 3631 ret = __phy_set_bits(phydev, MII_88E1510_GEN_CTRL_REG_1, 3632 MII_88E1510_GEN_CTRL_REG_1_RESET); 3633 3634 error: 3635 return phy_restore_page(phydev, oldpage, ret); 3636 } 3637 3638 static void m88e1510_sfp_remove(void *upstream) 3639 { 3640 struct phy_device *phydev = upstream; 3641 int oldpage; 3642 int ret = 0; 3643 3644 oldpage = phy_select_page(phydev, MII_MARVELL_MODE_PAGE); 3645 if (oldpage < 0) 3646 goto error; 3647 3648 ret = __phy_modify(phydev, MII_88E1510_GEN_CTRL_REG_1, 3649 MII_88E1510_GEN_CTRL_REG_1_MODE_MASK, 3650 MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII); 3651 if (ret < 0) 3652 goto error; 3653 3654 ret = __phy_set_bits(phydev, MII_88E1510_GEN_CTRL_REG_1, 3655 MII_88E1510_GEN_CTRL_REG_1_RESET); 3656 3657 error: 3658 phy_restore_page(phydev, oldpage, ret); 3659 } 3660 3661 static const struct sfp_upstream_ops m88e1510_sfp_ops = { 3662 .module_insert = m88e1510_sfp_insert, 3663 .module_remove = m88e1510_sfp_remove, 3664 .attach = phy_sfp_attach, 3665 .detach = phy_sfp_detach, 3666 .connect_phy = phy_sfp_connect_phy, 3667 .disconnect_phy = phy_sfp_disconnect_phy, 3668 }; 3669 3670 static int m88e1510_probe(struct phy_device *phydev) 3671 { 3672 int err; 3673 3674 err = marvell_probe(phydev); 3675 if (err) 3676 return err; 3677 3678 return phy_sfp_probe(phydev, &m88e1510_sfp_ops); 3679 } 3680 3681 static struct phy_driver marvell_drivers[] = { 3682 { 3683 .phy_id = MARVELL_PHY_ID_88E1101, 3684 .phy_id_mask = MARVELL_PHY_ID_MASK, 3685 .name = "Marvell 88E1101", 3686 /* PHY_GBIT_FEATURES */ 3687 .probe = marvell_probe, 3688 .config_init = marvell_config_init, 3689 .config_aneg = m88e1101_config_aneg, 3690 .config_intr = marvell_config_intr, 3691 .handle_interrupt = marvell_handle_interrupt, 3692 .resume = genphy_resume, 3693 .suspend = genphy_suspend, 3694 .read_page = marvell_read_page, 3695 .write_page = marvell_write_page, 3696 .get_sset_count = marvell_get_sset_count, 3697 .get_strings = marvell_get_strings, 3698 .get_stats = marvell_get_stats, 3699 }, 3700 { 3701 .phy_id = MARVELL_PHY_ID_88E3082, 3702 .phy_id_mask = MARVELL_PHY_ID_MASK, 3703 .name = "Marvell 88E308X/88E609X Family", 3704 /* PHY_BASIC_FEATURES */ 3705 .probe = marvell_probe, 3706 .config_init = marvell_config_init, 3707 .aneg_done = marvell_aneg_done, 3708 .read_status = marvell_read_status, 3709 .resume = genphy_resume, 3710 .suspend = genphy_suspend, 3711 .cable_test_start = m88e3082_vct_cable_test_start, 3712 .cable_test_get_status = m88e3082_vct_cable_test_get_status, 3713 }, 3714 { 3715 .phy_id = MARVELL_PHY_ID_88E1112, 3716 .phy_id_mask = MARVELL_PHY_ID_MASK, 3717 .name = "Marvell 88E1112", 3718 /* PHY_GBIT_FEATURES */ 3719 .probe = marvell_probe, 3720 .inband_caps = m88e1111_inband_caps, 3721 .config_inband = m88e1111_config_inband, 3722 .config_init = m88e1112_config_init, 3723 .config_aneg = marvell_config_aneg, 3724 .config_intr = marvell_config_intr, 3725 .handle_interrupt = marvell_handle_interrupt, 3726 .resume = genphy_resume, 3727 .suspend = genphy_suspend, 3728 .read_page = marvell_read_page, 3729 .write_page = marvell_write_page, 3730 .get_sset_count = marvell_get_sset_count, 3731 .get_strings = marvell_get_strings, 3732 .get_stats = marvell_get_stats, 3733 .get_tunable = m88e1011_get_tunable, 3734 .set_tunable = m88e1011_set_tunable, 3735 }, 3736 { 3737 .phy_id = MARVELL_PHY_ID_88E1111, 3738 .phy_id_mask = MARVELL_PHY_ID_MASK, 3739 .name = "Marvell 88E1111", 3740 /* PHY_GBIT_FEATURES */ 3741 .flags = PHY_POLL_CABLE_TEST, 3742 .probe = marvell_probe, 3743 .inband_caps = m88e1111_inband_caps, 3744 .config_inband = m88e1111_config_inband, 3745 .config_init = m88e1111gbe_config_init, 3746 .config_aneg = m88e1111_config_aneg, 3747 .read_status = marvell_read_status, 3748 .config_intr = marvell_config_intr, 3749 .handle_interrupt = marvell_handle_interrupt, 3750 .resume = genphy_resume, 3751 .suspend = genphy_suspend, 3752 .read_page = marvell_read_page, 3753 .write_page = marvell_write_page, 3754 .get_sset_count = marvell_get_sset_count, 3755 .get_strings = marvell_get_strings, 3756 .get_stats = marvell_get_stats, 3757 .get_tunable = m88e1111_get_tunable, 3758 .set_tunable = m88e1111_set_tunable, 3759 .cable_test_start = m88e1111_vct_cable_test_start, 3760 .cable_test_get_status = m88e1111_vct_cable_test_get_status, 3761 }, 3762 { 3763 .phy_id = MARVELL_PHY_ID_88E1111_FINISAR, 3764 .phy_id_mask = MARVELL_PHY_ID_MASK, 3765 .name = "Marvell 88E1111 (Finisar)", 3766 /* PHY_GBIT_FEATURES */ 3767 .probe = marvell_probe, 3768 .inband_caps = m88e1111_inband_caps, 3769 .config_inband = m88e1111_config_inband, 3770 .config_init = m88e1111gbe_config_init, 3771 .config_aneg = m88e1111_config_aneg, 3772 .read_status = marvell_read_status, 3773 .config_intr = marvell_config_intr, 3774 .handle_interrupt = marvell_handle_interrupt, 3775 .resume = genphy_resume, 3776 .suspend = genphy_suspend, 3777 .read_page = marvell_read_page, 3778 .write_page = marvell_write_page, 3779 .get_sset_count = marvell_get_sset_count, 3780 .get_strings = marvell_get_strings, 3781 .get_stats = marvell_get_stats, 3782 .get_tunable = m88e1111_get_tunable, 3783 .set_tunable = m88e1111_set_tunable, 3784 }, 3785 { 3786 .phy_id = MARVELL_PHY_ID_88E1118, 3787 .phy_id_mask = MARVELL_PHY_ID_MASK, 3788 .name = "Marvell 88E1118", 3789 /* PHY_GBIT_FEATURES */ 3790 .probe = marvell_probe, 3791 .config_init = m88e1118_config_init, 3792 .config_aneg = m88e1118_config_aneg, 3793 .config_intr = marvell_config_intr, 3794 .handle_interrupt = marvell_handle_interrupt, 3795 .resume = genphy_resume, 3796 .suspend = genphy_suspend, 3797 .read_page = marvell_read_page, 3798 .write_page = marvell_write_page, 3799 .get_sset_count = marvell_get_sset_count, 3800 .get_strings = marvell_get_strings, 3801 .get_stats = marvell_get_stats, 3802 }, 3803 { 3804 .phy_id = MARVELL_PHY_ID_88E1121R, 3805 .phy_id_mask = MARVELL_PHY_ID_MASK, 3806 .name = "Marvell 88E1121R", 3807 .driver_data = DEF_MARVELL_HWMON_OPS(m88e1121_hwmon_ops), 3808 /* PHY_GBIT_FEATURES */ 3809 .probe = marvell_probe, 3810 .config_init = marvell_1011gbe_config_init, 3811 .config_aneg = m88e1121_config_aneg, 3812 .read_status = marvell_read_status, 3813 .config_intr = marvell_config_intr, 3814 .handle_interrupt = marvell_handle_interrupt, 3815 .resume = genphy_resume, 3816 .suspend = genphy_suspend, 3817 .read_page = marvell_read_page, 3818 .write_page = marvell_write_page, 3819 .get_sset_count = marvell_get_sset_count, 3820 .get_strings = marvell_get_strings, 3821 .get_stats = marvell_get_stats, 3822 .get_tunable = m88e1011_get_tunable, 3823 .set_tunable = m88e1011_set_tunable, 3824 }, 3825 { 3826 .phy_id = MARVELL_PHY_ID_88E1318S, 3827 .phy_id_mask = MARVELL_PHY_ID_MASK, 3828 .name = "Marvell 88E1318S", 3829 /* PHY_GBIT_FEATURES */ 3830 .probe = marvell_probe, 3831 .config_init = m88e1318_config_init, 3832 .config_aneg = m88e1318_config_aneg, 3833 .read_status = marvell_read_status, 3834 .config_intr = marvell_config_intr, 3835 .handle_interrupt = marvell_handle_interrupt, 3836 .get_wol = m88e1318_get_wol, 3837 .set_wol = m88e1318_set_wol, 3838 .resume = genphy_resume, 3839 .suspend = genphy_suspend, 3840 .read_page = marvell_read_page, 3841 .write_page = marvell_write_page, 3842 .get_sset_count = marvell_get_sset_count, 3843 .get_strings = marvell_get_strings, 3844 .get_stats = marvell_get_stats, 3845 .led_brightness_set = m88e1318_led_brightness_set, 3846 .led_blink_set = m88e1318_led_blink_set, 3847 .led_hw_is_supported = m88e1318_led_hw_is_supported, 3848 .led_hw_control_set = m88e1318_led_hw_control_set, 3849 .led_hw_control_get = m88e1318_led_hw_control_get, 3850 }, 3851 { 3852 .phy_id = MARVELL_PHY_ID_88E1145, 3853 .phy_id_mask = MARVELL_PHY_ID_MASK, 3854 .name = "Marvell 88E1145", 3855 /* PHY_GBIT_FEATURES */ 3856 .flags = PHY_POLL_CABLE_TEST, 3857 .probe = marvell_probe, 3858 .config_init = m88e1145_config_init, 3859 .config_aneg = m88e1101_config_aneg, 3860 .config_intr = marvell_config_intr, 3861 .handle_interrupt = marvell_handle_interrupt, 3862 .resume = genphy_resume, 3863 .suspend = genphy_suspend, 3864 .read_page = marvell_read_page, 3865 .write_page = marvell_write_page, 3866 .get_sset_count = marvell_get_sset_count, 3867 .get_strings = marvell_get_strings, 3868 .get_stats = marvell_get_stats, 3869 .get_tunable = m88e1111_get_tunable, 3870 .set_tunable = m88e1111_set_tunable, 3871 .cable_test_start = m88e1111_vct_cable_test_start, 3872 .cable_test_get_status = m88e1111_vct_cable_test_get_status, 3873 }, 3874 { 3875 .phy_id = MARVELL_PHY_ID_88E1149R, 3876 .phy_id_mask = MARVELL_PHY_ID_MASK, 3877 .name = "Marvell 88E1149R", 3878 /* PHY_GBIT_FEATURES */ 3879 .probe = marvell_probe, 3880 .config_init = m88e1149_config_init, 3881 .config_aneg = m88e1118_config_aneg, 3882 .config_intr = marvell_config_intr, 3883 .handle_interrupt = marvell_handle_interrupt, 3884 .resume = genphy_resume, 3885 .suspend = genphy_suspend, 3886 .read_page = marvell_read_page, 3887 .write_page = marvell_write_page, 3888 .get_sset_count = marvell_get_sset_count, 3889 .get_strings = marvell_get_strings, 3890 .get_stats = marvell_get_stats, 3891 }, 3892 { 3893 .phy_id = MARVELL_PHY_ID_88E1240, 3894 .phy_id_mask = MARVELL_PHY_ID_MASK, 3895 .name = "Marvell 88E1240", 3896 /* PHY_GBIT_FEATURES */ 3897 .probe = marvell_probe, 3898 .config_init = m88e1112_config_init, 3899 .config_aneg = marvell_config_aneg, 3900 .config_intr = marvell_config_intr, 3901 .handle_interrupt = marvell_handle_interrupt, 3902 .resume = genphy_resume, 3903 .suspend = genphy_suspend, 3904 .read_page = marvell_read_page, 3905 .write_page = marvell_write_page, 3906 .get_sset_count = marvell_get_sset_count, 3907 .get_strings = marvell_get_strings, 3908 .get_stats = marvell_get_stats, 3909 .get_tunable = m88e1011_get_tunable, 3910 .set_tunable = m88e1011_set_tunable, 3911 }, 3912 { 3913 .phy_id = MARVELL_PHY_ID_88E1116R, 3914 .phy_id_mask = MARVELL_PHY_ID_MASK, 3915 .name = "Marvell 88E1116R", 3916 /* PHY_GBIT_FEATURES */ 3917 .probe = marvell_probe, 3918 .config_init = m88e1116r_config_init, 3919 .config_intr = marvell_config_intr, 3920 .handle_interrupt = marvell_handle_interrupt, 3921 .resume = genphy_resume, 3922 .suspend = genphy_suspend, 3923 .read_page = marvell_read_page, 3924 .write_page = marvell_write_page, 3925 .get_sset_count = marvell_get_sset_count, 3926 .get_strings = marvell_get_strings, 3927 .get_stats = marvell_get_stats, 3928 .get_tunable = m88e1011_get_tunable, 3929 .set_tunable = m88e1011_set_tunable, 3930 }, 3931 { 3932 .phy_id = MARVELL_PHY_ID_88E1510, 3933 .phy_id_mask = MARVELL_PHY_ID_MASK, 3934 .name = "Marvell 88E1510", 3935 .driver_data = DEF_MARVELL_HWMON_OPS(m88e1510_hwmon_ops), 3936 .features = PHY_GBIT_FIBRE_FEATURES, 3937 .flags = PHY_POLL_CABLE_TEST, 3938 .probe = m88e1510_probe, 3939 .config_init = m88e1510_config_init, 3940 .config_aneg = m88e1510_config_aneg, 3941 .read_status = marvell_read_status, 3942 .config_intr = marvell_config_intr, 3943 .handle_interrupt = marvell_handle_interrupt, 3944 .get_wol = m88e1318_get_wol, 3945 .set_wol = m88e1318_set_wol, 3946 .resume = marvell_resume, 3947 .suspend = marvell_suspend, 3948 .read_page = marvell_read_page, 3949 .write_page = marvell_write_page, 3950 .get_sset_count = marvell_get_sset_count, 3951 .get_strings = marvell_get_strings, 3952 .get_stats = marvell_get_stats, 3953 .set_loopback = m88e1510_loopback, 3954 .get_tunable = m88e1011_get_tunable, 3955 .set_tunable = m88e1011_set_tunable, 3956 .cable_test_start = marvell_vct7_cable_test_start, 3957 .cable_test_tdr_start = marvell_vct5_cable_test_tdr_start, 3958 .cable_test_get_status = marvell_vct7_cable_test_get_status, 3959 .led_brightness_set = m88e1318_led_brightness_set, 3960 .led_blink_set = m88e1318_led_blink_set, 3961 .led_hw_is_supported = m88e1318_led_hw_is_supported, 3962 .led_hw_control_set = m88e1318_led_hw_control_set, 3963 .led_hw_control_get = m88e1318_led_hw_control_get, 3964 }, 3965 { 3966 .phy_id = MARVELL_PHY_ID_88E1540, 3967 .phy_id_mask = MARVELL_PHY_ID_MASK, 3968 .name = "Marvell 88E1540", 3969 .driver_data = DEF_MARVELL_HWMON_OPS(m88e1510_hwmon_ops), 3970 /* PHY_GBIT_FEATURES */ 3971 .flags = PHY_POLL_CABLE_TEST, 3972 .probe = marvell_probe, 3973 .config_init = marvell_1011gbe_config_init, 3974 .config_aneg = m88e1510_config_aneg, 3975 .read_status = marvell_read_status, 3976 .config_intr = marvell_config_intr, 3977 .handle_interrupt = marvell_handle_interrupt, 3978 .resume = genphy_resume, 3979 .suspend = genphy_suspend, 3980 .read_page = marvell_read_page, 3981 .write_page = marvell_write_page, 3982 .get_sset_count = marvell_get_sset_count, 3983 .get_strings = marvell_get_strings, 3984 .get_stats = marvell_get_stats, 3985 .get_tunable = m88e1540_get_tunable, 3986 .set_tunable = m88e1540_set_tunable, 3987 .cable_test_start = marvell_vct7_cable_test_start, 3988 .cable_test_tdr_start = marvell_vct5_cable_test_tdr_start, 3989 .cable_test_get_status = marvell_vct7_cable_test_get_status, 3990 .led_brightness_set = m88e1318_led_brightness_set, 3991 .led_blink_set = m88e1318_led_blink_set, 3992 .led_hw_is_supported = m88e1318_led_hw_is_supported, 3993 .led_hw_control_set = m88e1318_led_hw_control_set, 3994 .led_hw_control_get = m88e1318_led_hw_control_get, 3995 }, 3996 { 3997 .phy_id = MARVELL_PHY_ID_88E1545, 3998 .phy_id_mask = MARVELL_PHY_ID_MASK, 3999 .name = "Marvell 88E1545", 4000 .driver_data = DEF_MARVELL_HWMON_OPS(m88e1510_hwmon_ops), 4001 .probe = marvell_probe, 4002 /* PHY_GBIT_FEATURES */ 4003 .flags = PHY_POLL_CABLE_TEST, 4004 .config_init = marvell_1011gbe_config_init, 4005 .config_aneg = m88e1510_config_aneg, 4006 .read_status = marvell_read_status, 4007 .config_intr = marvell_config_intr, 4008 .handle_interrupt = marvell_handle_interrupt, 4009 .resume = genphy_resume, 4010 .suspend = genphy_suspend, 4011 .read_page = marvell_read_page, 4012 .write_page = marvell_write_page, 4013 .get_sset_count = marvell_get_sset_count, 4014 .get_strings = marvell_get_strings, 4015 .get_stats = marvell_get_stats, 4016 .get_tunable = m88e1540_get_tunable, 4017 .set_tunable = m88e1540_set_tunable, 4018 .cable_test_start = marvell_vct7_cable_test_start, 4019 .cable_test_tdr_start = marvell_vct5_cable_test_tdr_start, 4020 .cable_test_get_status = marvell_vct7_cable_test_get_status, 4021 .led_brightness_set = m88e1318_led_brightness_set, 4022 .led_blink_set = m88e1318_led_blink_set, 4023 .led_hw_is_supported = m88e1318_led_hw_is_supported, 4024 .led_hw_control_set = m88e1318_led_hw_control_set, 4025 .led_hw_control_get = m88e1318_led_hw_control_get, 4026 }, 4027 { 4028 .phy_id = MARVELL_PHY_ID_88E3016, 4029 .phy_id_mask = MARVELL_PHY_ID_MASK, 4030 .name = "Marvell 88E3016", 4031 /* PHY_BASIC_FEATURES */ 4032 .probe = marvell_probe, 4033 .config_init = m88e3016_config_init, 4034 .aneg_done = marvell_aneg_done, 4035 .read_status = marvell_read_status, 4036 .config_intr = marvell_config_intr, 4037 .handle_interrupt = marvell_handle_interrupt, 4038 .resume = genphy_resume, 4039 .suspend = genphy_suspend, 4040 .read_page = marvell_read_page, 4041 .write_page = marvell_write_page, 4042 .get_sset_count = marvell_get_sset_count, 4043 .get_strings = marvell_get_strings, 4044 .get_stats = marvell_get_stats, 4045 }, 4046 { 4047 .phy_id = MARVELL_PHY_ID_88E6250_FAMILY, 4048 .phy_id_mask = MARVELL_PHY_ID_MASK, 4049 .name = "Marvell 88E6250 Family", 4050 /* PHY_BASIC_FEATURES */ 4051 .probe = marvell_probe, 4052 .aneg_done = marvell_aneg_done, 4053 .config_intr = marvell_config_intr, 4054 .handle_interrupt = marvell_handle_interrupt, 4055 .resume = genphy_resume, 4056 .suspend = genphy_suspend, 4057 .get_sset_count = marvell_get_sset_count_simple, 4058 .get_strings = marvell_get_strings_simple, 4059 .get_stats = marvell_get_stats_simple, 4060 }, 4061 { 4062 .phy_id = MARVELL_PHY_ID_88E6341_FAMILY, 4063 .phy_id_mask = MARVELL_PHY_ID_MASK, 4064 .name = "Marvell 88E6341 Family", 4065 .driver_data = DEF_MARVELL_HWMON_OPS(m88e1510_hwmon_ops), 4066 /* PHY_GBIT_FEATURES */ 4067 .flags = PHY_POLL_CABLE_TEST, 4068 .probe = marvell_probe, 4069 .config_init = marvell_1011gbe_config_init, 4070 .config_aneg = m88e6390_config_aneg, 4071 .read_status = marvell_read_status, 4072 .config_intr = marvell_config_intr, 4073 .handle_interrupt = marvell_handle_interrupt, 4074 .resume = genphy_resume, 4075 .suspend = genphy_suspend, 4076 .read_page = marvell_read_page, 4077 .write_page = marvell_write_page, 4078 .get_sset_count = marvell_get_sset_count, 4079 .get_strings = marvell_get_strings, 4080 .get_stats = marvell_get_stats, 4081 .get_tunable = m88e1540_get_tunable, 4082 .set_tunable = m88e1540_set_tunable, 4083 .cable_test_start = marvell_vct7_cable_test_start, 4084 .cable_test_tdr_start = marvell_vct5_cable_test_tdr_start, 4085 .cable_test_get_status = marvell_vct7_cable_test_get_status, 4086 }, 4087 { 4088 .phy_id = MARVELL_PHY_ID_88E6390_FAMILY, 4089 .phy_id_mask = MARVELL_PHY_ID_MASK, 4090 .name = "Marvell 88E6390 Family", 4091 .driver_data = DEF_MARVELL_HWMON_OPS(m88e6390_hwmon_ops), 4092 /* PHY_GBIT_FEATURES */ 4093 .flags = PHY_POLL_CABLE_TEST, 4094 .probe = marvell_probe, 4095 .config_init = marvell_1011gbe_config_init, 4096 .config_aneg = m88e6390_config_aneg, 4097 .read_status = marvell_read_status, 4098 .config_intr = marvell_config_intr, 4099 .handle_interrupt = marvell_handle_interrupt, 4100 .resume = genphy_resume, 4101 .suspend = genphy_suspend, 4102 .read_page = marvell_read_page, 4103 .write_page = marvell_write_page, 4104 .get_sset_count = marvell_get_sset_count, 4105 .get_strings = marvell_get_strings, 4106 .get_stats = marvell_get_stats, 4107 .get_tunable = m88e1540_get_tunable, 4108 .set_tunable = m88e1540_set_tunable, 4109 .cable_test_start = marvell_vct7_cable_test_start, 4110 .cable_test_tdr_start = marvell_vct5_cable_test_tdr_start, 4111 .cable_test_get_status = marvell_vct7_cable_test_get_status, 4112 }, 4113 { 4114 .phy_id = MARVELL_PHY_ID_88E6393_FAMILY, 4115 .phy_id_mask = MARVELL_PHY_ID_MASK, 4116 .name = "Marvell 88E6393 Family", 4117 .driver_data = DEF_MARVELL_HWMON_OPS(m88e6393_hwmon_ops), 4118 /* PHY_GBIT_FEATURES */ 4119 .flags = PHY_POLL_CABLE_TEST, 4120 .probe = marvell_probe, 4121 .config_init = marvell_1011gbe_config_init, 4122 .config_aneg = m88e1510_config_aneg, 4123 .read_status = marvell_read_status, 4124 .config_intr = marvell_config_intr, 4125 .handle_interrupt = marvell_handle_interrupt, 4126 .resume = genphy_resume, 4127 .suspend = genphy_suspend, 4128 .read_page = marvell_read_page, 4129 .write_page = marvell_write_page, 4130 .get_sset_count = marvell_get_sset_count, 4131 .get_strings = marvell_get_strings, 4132 .get_stats = marvell_get_stats, 4133 .get_tunable = m88e1540_get_tunable, 4134 .set_tunable = m88e1540_set_tunable, 4135 .cable_test_start = marvell_vct7_cable_test_start, 4136 .cable_test_tdr_start = marvell_vct5_cable_test_tdr_start, 4137 .cable_test_get_status = marvell_vct7_cable_test_get_status, 4138 }, 4139 { 4140 .phy_id = MARVELL_PHY_ID_88E1340S, 4141 .phy_id_mask = MARVELL_PHY_ID_MASK, 4142 .name = "Marvell 88E1340S", 4143 .driver_data = DEF_MARVELL_HWMON_OPS(m88e1510_hwmon_ops), 4144 .probe = marvell_probe, 4145 /* PHY_GBIT_FEATURES */ 4146 .config_init = marvell_1011gbe_config_init, 4147 .config_aneg = m88e1510_config_aneg, 4148 .read_status = marvell_read_status, 4149 .config_intr = marvell_config_intr, 4150 .handle_interrupt = marvell_handle_interrupt, 4151 .resume = genphy_resume, 4152 .suspend = genphy_suspend, 4153 .read_page = marvell_read_page, 4154 .write_page = marvell_write_page, 4155 .get_sset_count = marvell_get_sset_count, 4156 .get_strings = marvell_get_strings, 4157 .get_stats = marvell_get_stats, 4158 .get_tunable = m88e1540_get_tunable, 4159 .set_tunable = m88e1540_set_tunable, 4160 }, 4161 { 4162 .phy_id = MARVELL_PHY_ID_88E1548P, 4163 .phy_id_mask = MARVELL_PHY_ID_MASK, 4164 .name = "Marvell 88E1548P", 4165 .driver_data = DEF_MARVELL_HWMON_OPS(m88e1510_hwmon_ops), 4166 .probe = marvell_probe, 4167 .features = PHY_GBIT_FIBRE_FEATURES, 4168 .config_init = marvell_1011gbe_config_init, 4169 .config_aneg = m88e1510_config_aneg, 4170 .read_status = marvell_read_status, 4171 .config_intr = marvell_config_intr, 4172 .handle_interrupt = marvell_handle_interrupt, 4173 .resume = genphy_resume, 4174 .suspend = genphy_suspend, 4175 .read_page = marvell_read_page, 4176 .write_page = marvell_write_page, 4177 .get_sset_count = marvell_get_sset_count, 4178 .get_strings = marvell_get_strings, 4179 .get_stats = marvell_get_stats, 4180 .get_tunable = m88e1540_get_tunable, 4181 .set_tunable = m88e1540_set_tunable, 4182 .led_brightness_set = m88e1318_led_brightness_set, 4183 .led_blink_set = m88e1318_led_blink_set, 4184 .led_hw_is_supported = m88e1318_led_hw_is_supported, 4185 .led_hw_control_set = m88e1318_led_hw_control_set, 4186 .led_hw_control_get = m88e1318_led_hw_control_get, 4187 }, 4188 }; 4189 4190 module_phy_driver(marvell_drivers); 4191 4192 static struct mdio_device_id __maybe_unused marvell_tbl[] = { 4193 { MARVELL_PHY_ID_88E1101, MARVELL_PHY_ID_MASK }, 4194 { MARVELL_PHY_ID_88E3082, MARVELL_PHY_ID_MASK }, 4195 { MARVELL_PHY_ID_88E1112, MARVELL_PHY_ID_MASK }, 4196 { MARVELL_PHY_ID_88E1111, MARVELL_PHY_ID_MASK }, 4197 { MARVELL_PHY_ID_88E1111_FINISAR, MARVELL_PHY_ID_MASK }, 4198 { MARVELL_PHY_ID_88E1118, MARVELL_PHY_ID_MASK }, 4199 { MARVELL_PHY_ID_88E1121R, MARVELL_PHY_ID_MASK }, 4200 { MARVELL_PHY_ID_88E1145, MARVELL_PHY_ID_MASK }, 4201 { MARVELL_PHY_ID_88E1149R, MARVELL_PHY_ID_MASK }, 4202 { MARVELL_PHY_ID_88E1240, MARVELL_PHY_ID_MASK }, 4203 { MARVELL_PHY_ID_88E1318S, MARVELL_PHY_ID_MASK }, 4204 { MARVELL_PHY_ID_88E1116R, MARVELL_PHY_ID_MASK }, 4205 { MARVELL_PHY_ID_88E1510, MARVELL_PHY_ID_MASK }, 4206 { MARVELL_PHY_ID_88E1540, MARVELL_PHY_ID_MASK }, 4207 { MARVELL_PHY_ID_88E1545, MARVELL_PHY_ID_MASK }, 4208 { MARVELL_PHY_ID_88E3016, MARVELL_PHY_ID_MASK }, 4209 { MARVELL_PHY_ID_88E6250_FAMILY, MARVELL_PHY_ID_MASK }, 4210 { MARVELL_PHY_ID_88E6341_FAMILY, MARVELL_PHY_ID_MASK }, 4211 { MARVELL_PHY_ID_88E6390_FAMILY, MARVELL_PHY_ID_MASK }, 4212 { MARVELL_PHY_ID_88E6393_FAMILY, MARVELL_PHY_ID_MASK }, 4213 { MARVELL_PHY_ID_88E1340S, MARVELL_PHY_ID_MASK }, 4214 { MARVELL_PHY_ID_88E1548P, MARVELL_PHY_ID_MASK }, 4215 { } 4216 }; 4217 4218 MODULE_DEVICE_TABLE(mdio, marvell_tbl); 4219