1 // SPDX-License-Identifier: GPL-2.0+ 2 /* 3 * drivers/net/phy/micrel.c 4 * 5 * Driver for Micrel PHYs 6 * 7 * Author: David J. Choi 8 * 9 * Copyright (c) 2010-2013 Micrel, Inc. 10 * Copyright (c) 2014 Johan Hovold <johan@kernel.org> 11 * 12 * Support : Micrel Phys: 13 * Giga phys: ksz9021, ksz9031, ksz9131 14 * 100/10 Phys : ksz8001, ksz8721, ksz8737, ksz8041 15 * ksz8021, ksz8031, ksz8051, 16 * ksz8081, ksz8091, 17 * ksz8061, 18 * Switch : ksz8873, ksz886x 19 * ksz9477 20 */ 21 22 #include <linux/bitfield.h> 23 #include <linux/ethtool_netlink.h> 24 #include <linux/kernel.h> 25 #include <linux/module.h> 26 #include <linux/phy.h> 27 #include <linux/micrel_phy.h> 28 #include <linux/of.h> 29 #include <linux/clk.h> 30 #include <linux/delay.h> 31 #include <linux/ptp_clock_kernel.h> 32 #include <linux/ptp_clock.h> 33 #include <linux/ptp_classify.h> 34 #include <linux/net_tstamp.h> 35 #include <linux/gpio/consumer.h> 36 37 /* Operation Mode Strap Override */ 38 #define MII_KSZPHY_OMSO 0x16 39 #define KSZPHY_OMSO_FACTORY_TEST BIT(15) 40 #define KSZPHY_OMSO_B_CAST_OFF BIT(9) 41 #define KSZPHY_OMSO_NAND_TREE_ON BIT(5) 42 #define KSZPHY_OMSO_RMII_OVERRIDE BIT(1) 43 #define KSZPHY_OMSO_MII_OVERRIDE BIT(0) 44 45 /* general Interrupt control/status reg in vendor specific block. */ 46 #define MII_KSZPHY_INTCS 0x1B 47 #define KSZPHY_INTCS_JABBER BIT(15) 48 #define KSZPHY_INTCS_RECEIVE_ERR BIT(14) 49 #define KSZPHY_INTCS_PAGE_RECEIVE BIT(13) 50 #define KSZPHY_INTCS_PARELLEL BIT(12) 51 #define KSZPHY_INTCS_LINK_PARTNER_ACK BIT(11) 52 #define KSZPHY_INTCS_LINK_DOWN BIT(10) 53 #define KSZPHY_INTCS_REMOTE_FAULT BIT(9) 54 #define KSZPHY_INTCS_LINK_UP BIT(8) 55 #define KSZPHY_INTCS_ALL (KSZPHY_INTCS_LINK_UP |\ 56 KSZPHY_INTCS_LINK_DOWN) 57 #define KSZPHY_INTCS_LINK_DOWN_STATUS BIT(2) 58 #define KSZPHY_INTCS_LINK_UP_STATUS BIT(0) 59 #define KSZPHY_INTCS_STATUS (KSZPHY_INTCS_LINK_DOWN_STATUS |\ 60 KSZPHY_INTCS_LINK_UP_STATUS) 61 62 /* LinkMD Control/Status */ 63 #define KSZ8081_LMD 0x1d 64 #define KSZ8081_LMD_ENABLE_TEST BIT(15) 65 #define KSZ8081_LMD_STAT_NORMAL 0 66 #define KSZ8081_LMD_STAT_OPEN 1 67 #define KSZ8081_LMD_STAT_SHORT 2 68 #define KSZ8081_LMD_STAT_FAIL 3 69 #define KSZ8081_LMD_STAT_MASK GENMASK(14, 13) 70 /* Short cable (<10 meter) has been detected by LinkMD */ 71 #define KSZ8081_LMD_SHORT_INDICATOR BIT(12) 72 #define KSZ8081_LMD_DELTA_TIME_MASK GENMASK(8, 0) 73 74 #define KSZ9x31_LMD 0x12 75 #define KSZ9x31_LMD_VCT_EN BIT(15) 76 #define KSZ9x31_LMD_VCT_DIS_TX BIT(14) 77 #define KSZ9x31_LMD_VCT_PAIR(n) (((n) & 0x3) << 12) 78 #define KSZ9x31_LMD_VCT_SEL_RESULT 0 79 #define KSZ9x31_LMD_VCT_SEL_THRES_HI BIT(10) 80 #define KSZ9x31_LMD_VCT_SEL_THRES_LO BIT(11) 81 #define KSZ9x31_LMD_VCT_SEL_MASK GENMASK(11, 10) 82 #define KSZ9x31_LMD_VCT_ST_NORMAL 0 83 #define KSZ9x31_LMD_VCT_ST_OPEN 1 84 #define KSZ9x31_LMD_VCT_ST_SHORT 2 85 #define KSZ9x31_LMD_VCT_ST_FAIL 3 86 #define KSZ9x31_LMD_VCT_ST_MASK GENMASK(9, 8) 87 #define KSZ9x31_LMD_VCT_DATA_REFLECTED_INVALID BIT(7) 88 #define KSZ9x31_LMD_VCT_DATA_SIG_WAIT_TOO_LONG BIT(6) 89 #define KSZ9x31_LMD_VCT_DATA_MASK100 BIT(5) 90 #define KSZ9x31_LMD_VCT_DATA_NLP_FLP BIT(4) 91 #define KSZ9x31_LMD_VCT_DATA_LO_PULSE_MASK GENMASK(3, 2) 92 #define KSZ9x31_LMD_VCT_DATA_HI_PULSE_MASK GENMASK(1, 0) 93 #define KSZ9x31_LMD_VCT_DATA_MASK GENMASK(7, 0) 94 95 #define KSZPHY_WIRE_PAIR_MASK 0x3 96 97 #define LAN8814_CABLE_DIAG 0x12 98 #define LAN8814_CABLE_DIAG_STAT_MASK GENMASK(9, 8) 99 #define LAN8814_CABLE_DIAG_VCT_DATA_MASK GENMASK(7, 0) 100 #define LAN8814_PAIR_BIT_SHIFT 12 101 102 #define LAN8814_WIRE_PAIR_MASK 0xF 103 104 /* Lan8814 general Interrupt control/status reg in GPHY specific block. */ 105 #define LAN8814_INTC 0x18 106 #define LAN8814_INTS 0x1B 107 108 #define LAN8814_INT_LINK_DOWN BIT(2) 109 #define LAN8814_INT_LINK_UP BIT(0) 110 #define LAN8814_INT_LINK (LAN8814_INT_LINK_UP |\ 111 LAN8814_INT_LINK_DOWN) 112 113 #define LAN8814_INTR_CTRL_REG 0x34 114 #define LAN8814_INTR_CTRL_REG_POLARITY BIT(1) 115 #define LAN8814_INTR_CTRL_REG_INTR_ENABLE BIT(0) 116 117 /* Represents 1ppm adjustment in 2^32 format with 118 * each nsec contains 4 clock cycles. 119 * The value is calculated as following: (1/1000000)/((2^-32)/4) 120 */ 121 #define LAN8814_1PPM_FORMAT 17179 122 123 #define PTP_RX_MOD 0x024F 124 #define PTP_RX_MOD_BAD_UDPV4_CHKSUM_FORCE_FCS_DIS_ BIT(3) 125 #define PTP_RX_TIMESTAMP_EN 0x024D 126 #define PTP_TX_TIMESTAMP_EN 0x028D 127 128 #define PTP_TIMESTAMP_EN_SYNC_ BIT(0) 129 #define PTP_TIMESTAMP_EN_DREQ_ BIT(1) 130 #define PTP_TIMESTAMP_EN_PDREQ_ BIT(2) 131 #define PTP_TIMESTAMP_EN_PDRES_ BIT(3) 132 133 #define PTP_TX_PARSE_L2_ADDR_EN 0x0284 134 #define PTP_RX_PARSE_L2_ADDR_EN 0x0244 135 136 #define PTP_TX_PARSE_IP_ADDR_EN 0x0285 137 #define PTP_RX_PARSE_IP_ADDR_EN 0x0245 138 #define LTC_HARD_RESET 0x023F 139 #define LTC_HARD_RESET_ BIT(0) 140 141 #define TSU_HARD_RESET 0x02C1 142 #define TSU_HARD_RESET_ BIT(0) 143 144 #define PTP_CMD_CTL 0x0200 145 #define PTP_CMD_CTL_PTP_DISABLE_ BIT(0) 146 #define PTP_CMD_CTL_PTP_ENABLE_ BIT(1) 147 #define PTP_CMD_CTL_PTP_CLOCK_READ_ BIT(3) 148 #define PTP_CMD_CTL_PTP_CLOCK_LOAD_ BIT(4) 149 #define PTP_CMD_CTL_PTP_LTC_STEP_SEC_ BIT(5) 150 #define PTP_CMD_CTL_PTP_LTC_STEP_NSEC_ BIT(6) 151 152 #define PTP_CLOCK_SET_SEC_MID 0x0206 153 #define PTP_CLOCK_SET_SEC_LO 0x0207 154 #define PTP_CLOCK_SET_NS_HI 0x0208 155 #define PTP_CLOCK_SET_NS_LO 0x0209 156 157 #define PTP_CLOCK_READ_SEC_MID 0x022A 158 #define PTP_CLOCK_READ_SEC_LO 0x022B 159 #define PTP_CLOCK_READ_NS_HI 0x022C 160 #define PTP_CLOCK_READ_NS_LO 0x022D 161 162 #define PTP_OPERATING_MODE 0x0241 163 #define PTP_OPERATING_MODE_STANDALONE_ BIT(0) 164 165 #define PTP_TX_MOD 0x028F 166 #define PTP_TX_MOD_TX_PTP_SYNC_TS_INSERT_ BIT(12) 167 #define PTP_TX_MOD_BAD_UDPV4_CHKSUM_FORCE_FCS_DIS_ BIT(3) 168 169 #define PTP_RX_PARSE_CONFIG 0x0242 170 #define PTP_RX_PARSE_CONFIG_LAYER2_EN_ BIT(0) 171 #define PTP_RX_PARSE_CONFIG_IPV4_EN_ BIT(1) 172 #define PTP_RX_PARSE_CONFIG_IPV6_EN_ BIT(2) 173 174 #define PTP_TX_PARSE_CONFIG 0x0282 175 #define PTP_TX_PARSE_CONFIG_LAYER2_EN_ BIT(0) 176 #define PTP_TX_PARSE_CONFIG_IPV4_EN_ BIT(1) 177 #define PTP_TX_PARSE_CONFIG_IPV6_EN_ BIT(2) 178 179 #define PTP_CLOCK_RATE_ADJ_HI 0x020C 180 #define PTP_CLOCK_RATE_ADJ_LO 0x020D 181 #define PTP_CLOCK_RATE_ADJ_DIR_ BIT(15) 182 183 #define PTP_LTC_STEP_ADJ_HI 0x0212 184 #define PTP_LTC_STEP_ADJ_LO 0x0213 185 #define PTP_LTC_STEP_ADJ_DIR_ BIT(15) 186 187 #define LAN8814_INTR_STS_REG 0x0033 188 #define LAN8814_INTR_STS_REG_1588_TSU0_ BIT(0) 189 #define LAN8814_INTR_STS_REG_1588_TSU1_ BIT(1) 190 #define LAN8814_INTR_STS_REG_1588_TSU2_ BIT(2) 191 #define LAN8814_INTR_STS_REG_1588_TSU3_ BIT(3) 192 193 #define PTP_CAP_INFO 0x022A 194 #define PTP_CAP_INFO_TX_TS_CNT_GET_(reg_val) (((reg_val) & 0x0f00) >> 8) 195 #define PTP_CAP_INFO_RX_TS_CNT_GET_(reg_val) ((reg_val) & 0x000f) 196 197 #define PTP_TX_EGRESS_SEC_HI 0x0296 198 #define PTP_TX_EGRESS_SEC_LO 0x0297 199 #define PTP_TX_EGRESS_NS_HI 0x0294 200 #define PTP_TX_EGRESS_NS_LO 0x0295 201 #define PTP_TX_MSG_HEADER2 0x0299 202 203 #define PTP_RX_INGRESS_SEC_HI 0x0256 204 #define PTP_RX_INGRESS_SEC_LO 0x0257 205 #define PTP_RX_INGRESS_NS_HI 0x0254 206 #define PTP_RX_INGRESS_NS_LO 0x0255 207 #define PTP_RX_MSG_HEADER2 0x0259 208 209 #define PTP_TSU_INT_EN 0x0200 210 #define PTP_TSU_INT_EN_PTP_TX_TS_OVRFL_EN_ BIT(3) 211 #define PTP_TSU_INT_EN_PTP_TX_TS_EN_ BIT(2) 212 #define PTP_TSU_INT_EN_PTP_RX_TS_OVRFL_EN_ BIT(1) 213 #define PTP_TSU_INT_EN_PTP_RX_TS_EN_ BIT(0) 214 215 #define PTP_TSU_INT_STS 0x0201 216 #define PTP_TSU_INT_STS_PTP_TX_TS_OVRFL_INT_ BIT(3) 217 #define PTP_TSU_INT_STS_PTP_TX_TS_EN_ BIT(2) 218 #define PTP_TSU_INT_STS_PTP_RX_TS_OVRFL_INT_ BIT(1) 219 #define PTP_TSU_INT_STS_PTP_RX_TS_EN_ BIT(0) 220 221 #define LAN8814_LED_CTRL_1 0x0 222 #define LAN8814_LED_CTRL_1_KSZ9031_LED_MODE_ BIT(6) 223 224 /* PHY Control 1 */ 225 #define MII_KSZPHY_CTRL_1 0x1e 226 #define KSZ8081_CTRL1_MDIX_STAT BIT(4) 227 228 /* PHY Control 2 / PHY Control (if no PHY Control 1) */ 229 #define MII_KSZPHY_CTRL_2 0x1f 230 #define MII_KSZPHY_CTRL MII_KSZPHY_CTRL_2 231 /* bitmap of PHY register to set interrupt mode */ 232 #define KSZ8081_CTRL2_HP_MDIX BIT(15) 233 #define KSZ8081_CTRL2_MDI_MDI_X_SELECT BIT(14) 234 #define KSZ8081_CTRL2_DISABLE_AUTO_MDIX BIT(13) 235 #define KSZ8081_CTRL2_FORCE_LINK BIT(11) 236 #define KSZ8081_CTRL2_POWER_SAVING BIT(10) 237 #define KSZPHY_CTRL_INT_ACTIVE_HIGH BIT(9) 238 #define KSZPHY_RMII_REF_CLK_SEL BIT(7) 239 240 /* Write/read to/from extended registers */ 241 #define MII_KSZPHY_EXTREG 0x0b 242 #define KSZPHY_EXTREG_WRITE 0x8000 243 244 #define MII_KSZPHY_EXTREG_WRITE 0x0c 245 #define MII_KSZPHY_EXTREG_READ 0x0d 246 247 /* Extended registers */ 248 #define MII_KSZPHY_CLK_CONTROL_PAD_SKEW 0x104 249 #define MII_KSZPHY_RX_DATA_PAD_SKEW 0x105 250 #define MII_KSZPHY_TX_DATA_PAD_SKEW 0x106 251 252 #define PS_TO_REG 200 253 #define FIFO_SIZE 8 254 255 struct kszphy_hw_stat { 256 const char *string; 257 u8 reg; 258 u8 bits; 259 }; 260 261 static struct kszphy_hw_stat kszphy_hw_stats[] = { 262 { "phy_receive_errors", 21, 16}, 263 { "phy_idle_errors", 10, 8 }, 264 }; 265 266 struct kszphy_type { 267 u32 led_mode_reg; 268 u16 interrupt_level_mask; 269 u16 cable_diag_reg; 270 unsigned long pair_mask; 271 bool has_broadcast_disable; 272 bool has_nand_tree_disable; 273 bool has_rmii_ref_clk_sel; 274 }; 275 276 /* Shared structure between the PHYs of the same package. */ 277 struct lan8814_shared_priv { 278 struct phy_device *phydev; 279 struct ptp_clock *ptp_clock; 280 struct ptp_clock_info ptp_clock_info; 281 282 /* Reference counter to how many ports in the package are enabling the 283 * timestamping 284 */ 285 u8 ref; 286 287 /* Lock for ptp_clock and ref */ 288 struct mutex shared_lock; 289 }; 290 291 struct lan8814_ptp_rx_ts { 292 struct list_head list; 293 u32 seconds; 294 u32 nsec; 295 u16 seq_id; 296 }; 297 298 struct kszphy_ptp_priv { 299 struct mii_timestamper mii_ts; 300 struct phy_device *phydev; 301 302 struct sk_buff_head tx_queue; 303 struct sk_buff_head rx_queue; 304 305 struct list_head rx_ts_list; 306 /* Lock for Rx ts fifo */ 307 spinlock_t rx_ts_lock; 308 309 int hwts_tx_type; 310 enum hwtstamp_rx_filters rx_filter; 311 int layer; 312 int version; 313 }; 314 315 struct kszphy_priv { 316 struct kszphy_ptp_priv ptp_priv; 317 const struct kszphy_type *type; 318 int led_mode; 319 u16 vct_ctrl1000; 320 bool rmii_ref_clk_sel; 321 bool rmii_ref_clk_sel_val; 322 u64 stats[ARRAY_SIZE(kszphy_hw_stats)]; 323 }; 324 325 static const struct kszphy_type lan8814_type = { 326 .led_mode_reg = ~LAN8814_LED_CTRL_1, 327 .cable_diag_reg = LAN8814_CABLE_DIAG, 328 .pair_mask = LAN8814_WIRE_PAIR_MASK, 329 }; 330 331 static const struct kszphy_type ksz886x_type = { 332 .cable_diag_reg = KSZ8081_LMD, 333 .pair_mask = KSZPHY_WIRE_PAIR_MASK, 334 }; 335 336 static const struct kszphy_type ksz8021_type = { 337 .led_mode_reg = MII_KSZPHY_CTRL_2, 338 .has_broadcast_disable = true, 339 .has_nand_tree_disable = true, 340 .has_rmii_ref_clk_sel = true, 341 }; 342 343 static const struct kszphy_type ksz8041_type = { 344 .led_mode_reg = MII_KSZPHY_CTRL_1, 345 }; 346 347 static const struct kszphy_type ksz8051_type = { 348 .led_mode_reg = MII_KSZPHY_CTRL_2, 349 .has_nand_tree_disable = true, 350 }; 351 352 static const struct kszphy_type ksz8081_type = { 353 .led_mode_reg = MII_KSZPHY_CTRL_2, 354 .has_broadcast_disable = true, 355 .has_nand_tree_disable = true, 356 .has_rmii_ref_clk_sel = true, 357 }; 358 359 static const struct kszphy_type ks8737_type = { 360 .interrupt_level_mask = BIT(14), 361 }; 362 363 static const struct kszphy_type ksz9021_type = { 364 .interrupt_level_mask = BIT(14), 365 }; 366 367 static int kszphy_extended_write(struct phy_device *phydev, 368 u32 regnum, u16 val) 369 { 370 phy_write(phydev, MII_KSZPHY_EXTREG, KSZPHY_EXTREG_WRITE | regnum); 371 return phy_write(phydev, MII_KSZPHY_EXTREG_WRITE, val); 372 } 373 374 static int kszphy_extended_read(struct phy_device *phydev, 375 u32 regnum) 376 { 377 phy_write(phydev, MII_KSZPHY_EXTREG, regnum); 378 return phy_read(phydev, MII_KSZPHY_EXTREG_READ); 379 } 380 381 static int kszphy_ack_interrupt(struct phy_device *phydev) 382 { 383 /* bit[7..0] int status, which is a read and clear register. */ 384 int rc; 385 386 rc = phy_read(phydev, MII_KSZPHY_INTCS); 387 388 return (rc < 0) ? rc : 0; 389 } 390 391 static int kszphy_config_intr(struct phy_device *phydev) 392 { 393 const struct kszphy_type *type = phydev->drv->driver_data; 394 int temp, err; 395 u16 mask; 396 397 if (type && type->interrupt_level_mask) 398 mask = type->interrupt_level_mask; 399 else 400 mask = KSZPHY_CTRL_INT_ACTIVE_HIGH; 401 402 /* set the interrupt pin active low */ 403 temp = phy_read(phydev, MII_KSZPHY_CTRL); 404 if (temp < 0) 405 return temp; 406 temp &= ~mask; 407 phy_write(phydev, MII_KSZPHY_CTRL, temp); 408 409 /* enable / disable interrupts */ 410 if (phydev->interrupts == PHY_INTERRUPT_ENABLED) { 411 err = kszphy_ack_interrupt(phydev); 412 if (err) 413 return err; 414 415 temp = KSZPHY_INTCS_ALL; 416 err = phy_write(phydev, MII_KSZPHY_INTCS, temp); 417 } else { 418 temp = 0; 419 err = phy_write(phydev, MII_KSZPHY_INTCS, temp); 420 if (err) 421 return err; 422 423 err = kszphy_ack_interrupt(phydev); 424 } 425 426 return err; 427 } 428 429 static irqreturn_t kszphy_handle_interrupt(struct phy_device *phydev) 430 { 431 int irq_status; 432 433 irq_status = phy_read(phydev, MII_KSZPHY_INTCS); 434 if (irq_status < 0) { 435 phy_error(phydev); 436 return IRQ_NONE; 437 } 438 439 if (!(irq_status & KSZPHY_INTCS_STATUS)) 440 return IRQ_NONE; 441 442 phy_trigger_machine(phydev); 443 444 return IRQ_HANDLED; 445 } 446 447 static int kszphy_rmii_clk_sel(struct phy_device *phydev, bool val) 448 { 449 int ctrl; 450 451 ctrl = phy_read(phydev, MII_KSZPHY_CTRL); 452 if (ctrl < 0) 453 return ctrl; 454 455 if (val) 456 ctrl |= KSZPHY_RMII_REF_CLK_SEL; 457 else 458 ctrl &= ~KSZPHY_RMII_REF_CLK_SEL; 459 460 return phy_write(phydev, MII_KSZPHY_CTRL, ctrl); 461 } 462 463 static int kszphy_setup_led(struct phy_device *phydev, u32 reg, int val) 464 { 465 int rc, temp, shift; 466 467 switch (reg) { 468 case MII_KSZPHY_CTRL_1: 469 shift = 14; 470 break; 471 case MII_KSZPHY_CTRL_2: 472 shift = 4; 473 break; 474 default: 475 return -EINVAL; 476 } 477 478 temp = phy_read(phydev, reg); 479 if (temp < 0) { 480 rc = temp; 481 goto out; 482 } 483 484 temp &= ~(3 << shift); 485 temp |= val << shift; 486 rc = phy_write(phydev, reg, temp); 487 out: 488 if (rc < 0) 489 phydev_err(phydev, "failed to set led mode\n"); 490 491 return rc; 492 } 493 494 /* Disable PHY address 0 as the broadcast address, so that it can be used as a 495 * unique (non-broadcast) address on a shared bus. 496 */ 497 static int kszphy_broadcast_disable(struct phy_device *phydev) 498 { 499 int ret; 500 501 ret = phy_read(phydev, MII_KSZPHY_OMSO); 502 if (ret < 0) 503 goto out; 504 505 ret = phy_write(phydev, MII_KSZPHY_OMSO, ret | KSZPHY_OMSO_B_CAST_OFF); 506 out: 507 if (ret) 508 phydev_err(phydev, "failed to disable broadcast address\n"); 509 510 return ret; 511 } 512 513 static int kszphy_nand_tree_disable(struct phy_device *phydev) 514 { 515 int ret; 516 517 ret = phy_read(phydev, MII_KSZPHY_OMSO); 518 if (ret < 0) 519 goto out; 520 521 if (!(ret & KSZPHY_OMSO_NAND_TREE_ON)) 522 return 0; 523 524 ret = phy_write(phydev, MII_KSZPHY_OMSO, 525 ret & ~KSZPHY_OMSO_NAND_TREE_ON); 526 out: 527 if (ret) 528 phydev_err(phydev, "failed to disable NAND tree mode\n"); 529 530 return ret; 531 } 532 533 /* Some config bits need to be set again on resume, handle them here. */ 534 static int kszphy_config_reset(struct phy_device *phydev) 535 { 536 struct kszphy_priv *priv = phydev->priv; 537 int ret; 538 539 if (priv->rmii_ref_clk_sel) { 540 ret = kszphy_rmii_clk_sel(phydev, priv->rmii_ref_clk_sel_val); 541 if (ret) { 542 phydev_err(phydev, 543 "failed to set rmii reference clock\n"); 544 return ret; 545 } 546 } 547 548 if (priv->type && priv->led_mode >= 0) 549 kszphy_setup_led(phydev, priv->type->led_mode_reg, priv->led_mode); 550 551 return 0; 552 } 553 554 static int kszphy_config_init(struct phy_device *phydev) 555 { 556 struct kszphy_priv *priv = phydev->priv; 557 const struct kszphy_type *type; 558 559 if (!priv) 560 return 0; 561 562 type = priv->type; 563 564 if (type && type->has_broadcast_disable) 565 kszphy_broadcast_disable(phydev); 566 567 if (type && type->has_nand_tree_disable) 568 kszphy_nand_tree_disable(phydev); 569 570 return kszphy_config_reset(phydev); 571 } 572 573 static int ksz8041_fiber_mode(struct phy_device *phydev) 574 { 575 struct device_node *of_node = phydev->mdio.dev.of_node; 576 577 return of_property_read_bool(of_node, "micrel,fiber-mode"); 578 } 579 580 static int ksz8041_config_init(struct phy_device *phydev) 581 { 582 __ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, }; 583 584 /* Limit supported and advertised modes in fiber mode */ 585 if (ksz8041_fiber_mode(phydev)) { 586 phydev->dev_flags |= MICREL_PHY_FXEN; 587 linkmode_set_bit(ETHTOOL_LINK_MODE_100baseT_Full_BIT, mask); 588 linkmode_set_bit(ETHTOOL_LINK_MODE_100baseT_Half_BIT, mask); 589 590 linkmode_and(phydev->supported, phydev->supported, mask); 591 linkmode_set_bit(ETHTOOL_LINK_MODE_FIBRE_BIT, 592 phydev->supported); 593 linkmode_and(phydev->advertising, phydev->advertising, mask); 594 linkmode_set_bit(ETHTOOL_LINK_MODE_FIBRE_BIT, 595 phydev->advertising); 596 phydev->autoneg = AUTONEG_DISABLE; 597 } 598 599 return kszphy_config_init(phydev); 600 } 601 602 static int ksz8041_config_aneg(struct phy_device *phydev) 603 { 604 /* Skip auto-negotiation in fiber mode */ 605 if (phydev->dev_flags & MICREL_PHY_FXEN) { 606 phydev->speed = SPEED_100; 607 return 0; 608 } 609 610 return genphy_config_aneg(phydev); 611 } 612 613 static int ksz8051_ksz8795_match_phy_device(struct phy_device *phydev, 614 const bool ksz_8051) 615 { 616 int ret; 617 618 if ((phydev->phy_id & MICREL_PHY_ID_MASK) != PHY_ID_KSZ8051) 619 return 0; 620 621 ret = phy_read(phydev, MII_BMSR); 622 if (ret < 0) 623 return ret; 624 625 /* KSZ8051 PHY and KSZ8794/KSZ8795/KSZ8765 switch share the same 626 * exact PHY ID. However, they can be told apart by the extended 627 * capability registers presence. The KSZ8051 PHY has them while 628 * the switch does not. 629 */ 630 ret &= BMSR_ERCAP; 631 if (ksz_8051) 632 return ret; 633 else 634 return !ret; 635 } 636 637 static int ksz8051_match_phy_device(struct phy_device *phydev) 638 { 639 return ksz8051_ksz8795_match_phy_device(phydev, true); 640 } 641 642 static int ksz8081_config_init(struct phy_device *phydev) 643 { 644 /* KSZPHY_OMSO_FACTORY_TEST is set at de-assertion of the reset line 645 * based on the RXER (KSZ8081RNA/RND) or TXC (KSZ8081MNX/RNB) pin. If a 646 * pull-down is missing, the factory test mode should be cleared by 647 * manually writing a 0. 648 */ 649 phy_clear_bits(phydev, MII_KSZPHY_OMSO, KSZPHY_OMSO_FACTORY_TEST); 650 651 return kszphy_config_init(phydev); 652 } 653 654 static int ksz8081_config_mdix(struct phy_device *phydev, u8 ctrl) 655 { 656 u16 val; 657 658 switch (ctrl) { 659 case ETH_TP_MDI: 660 val = KSZ8081_CTRL2_DISABLE_AUTO_MDIX; 661 break; 662 case ETH_TP_MDI_X: 663 val = KSZ8081_CTRL2_DISABLE_AUTO_MDIX | 664 KSZ8081_CTRL2_MDI_MDI_X_SELECT; 665 break; 666 case ETH_TP_MDI_AUTO: 667 val = 0; 668 break; 669 default: 670 return 0; 671 } 672 673 return phy_modify(phydev, MII_KSZPHY_CTRL_2, 674 KSZ8081_CTRL2_HP_MDIX | 675 KSZ8081_CTRL2_MDI_MDI_X_SELECT | 676 KSZ8081_CTRL2_DISABLE_AUTO_MDIX, 677 KSZ8081_CTRL2_HP_MDIX | val); 678 } 679 680 static int ksz8081_config_aneg(struct phy_device *phydev) 681 { 682 int ret; 683 684 ret = genphy_config_aneg(phydev); 685 if (ret) 686 return ret; 687 688 /* The MDI-X configuration is automatically changed by the PHY after 689 * switching from autoneg off to on. So, take MDI-X configuration under 690 * own control and set it after autoneg configuration was done. 691 */ 692 return ksz8081_config_mdix(phydev, phydev->mdix_ctrl); 693 } 694 695 static int ksz8081_mdix_update(struct phy_device *phydev) 696 { 697 int ret; 698 699 ret = phy_read(phydev, MII_KSZPHY_CTRL_2); 700 if (ret < 0) 701 return ret; 702 703 if (ret & KSZ8081_CTRL2_DISABLE_AUTO_MDIX) { 704 if (ret & KSZ8081_CTRL2_MDI_MDI_X_SELECT) 705 phydev->mdix_ctrl = ETH_TP_MDI_X; 706 else 707 phydev->mdix_ctrl = ETH_TP_MDI; 708 } else { 709 phydev->mdix_ctrl = ETH_TP_MDI_AUTO; 710 } 711 712 ret = phy_read(phydev, MII_KSZPHY_CTRL_1); 713 if (ret < 0) 714 return ret; 715 716 if (ret & KSZ8081_CTRL1_MDIX_STAT) 717 phydev->mdix = ETH_TP_MDI; 718 else 719 phydev->mdix = ETH_TP_MDI_X; 720 721 return 0; 722 } 723 724 static int ksz8081_read_status(struct phy_device *phydev) 725 { 726 int ret; 727 728 ret = ksz8081_mdix_update(phydev); 729 if (ret < 0) 730 return ret; 731 732 return genphy_read_status(phydev); 733 } 734 735 static int ksz8061_config_init(struct phy_device *phydev) 736 { 737 int ret; 738 739 ret = phy_write_mmd(phydev, MDIO_MMD_PMAPMD, MDIO_DEVID1, 0xB61A); 740 if (ret) 741 return ret; 742 743 return kszphy_config_init(phydev); 744 } 745 746 static int ksz8795_match_phy_device(struct phy_device *phydev) 747 { 748 return ksz8051_ksz8795_match_phy_device(phydev, false); 749 } 750 751 static int ksz9021_load_values_from_of(struct phy_device *phydev, 752 const struct device_node *of_node, 753 u16 reg, 754 const char *field1, const char *field2, 755 const char *field3, const char *field4) 756 { 757 int val1 = -1; 758 int val2 = -2; 759 int val3 = -3; 760 int val4 = -4; 761 int newval; 762 int matches = 0; 763 764 if (!of_property_read_u32(of_node, field1, &val1)) 765 matches++; 766 767 if (!of_property_read_u32(of_node, field2, &val2)) 768 matches++; 769 770 if (!of_property_read_u32(of_node, field3, &val3)) 771 matches++; 772 773 if (!of_property_read_u32(of_node, field4, &val4)) 774 matches++; 775 776 if (!matches) 777 return 0; 778 779 if (matches < 4) 780 newval = kszphy_extended_read(phydev, reg); 781 else 782 newval = 0; 783 784 if (val1 != -1) 785 newval = ((newval & 0xfff0) | ((val1 / PS_TO_REG) & 0xf) << 0); 786 787 if (val2 != -2) 788 newval = ((newval & 0xff0f) | ((val2 / PS_TO_REG) & 0xf) << 4); 789 790 if (val3 != -3) 791 newval = ((newval & 0xf0ff) | ((val3 / PS_TO_REG) & 0xf) << 8); 792 793 if (val4 != -4) 794 newval = ((newval & 0x0fff) | ((val4 / PS_TO_REG) & 0xf) << 12); 795 796 return kszphy_extended_write(phydev, reg, newval); 797 } 798 799 static int ksz9021_config_init(struct phy_device *phydev) 800 { 801 const struct device_node *of_node; 802 const struct device *dev_walker; 803 804 /* The Micrel driver has a deprecated option to place phy OF 805 * properties in the MAC node. Walk up the tree of devices to 806 * find a device with an OF node. 807 */ 808 dev_walker = &phydev->mdio.dev; 809 do { 810 of_node = dev_walker->of_node; 811 dev_walker = dev_walker->parent; 812 813 } while (!of_node && dev_walker); 814 815 if (of_node) { 816 ksz9021_load_values_from_of(phydev, of_node, 817 MII_KSZPHY_CLK_CONTROL_PAD_SKEW, 818 "txen-skew-ps", "txc-skew-ps", 819 "rxdv-skew-ps", "rxc-skew-ps"); 820 ksz9021_load_values_from_of(phydev, of_node, 821 MII_KSZPHY_RX_DATA_PAD_SKEW, 822 "rxd0-skew-ps", "rxd1-skew-ps", 823 "rxd2-skew-ps", "rxd3-skew-ps"); 824 ksz9021_load_values_from_of(phydev, of_node, 825 MII_KSZPHY_TX_DATA_PAD_SKEW, 826 "txd0-skew-ps", "txd1-skew-ps", 827 "txd2-skew-ps", "txd3-skew-ps"); 828 } 829 return 0; 830 } 831 832 #define KSZ9031_PS_TO_REG 60 833 834 /* Extended registers */ 835 /* MMD Address 0x0 */ 836 #define MII_KSZ9031RN_FLP_BURST_TX_LO 3 837 #define MII_KSZ9031RN_FLP_BURST_TX_HI 4 838 839 /* MMD Address 0x2 */ 840 #define MII_KSZ9031RN_CONTROL_PAD_SKEW 4 841 #define MII_KSZ9031RN_RX_CTL_M GENMASK(7, 4) 842 #define MII_KSZ9031RN_TX_CTL_M GENMASK(3, 0) 843 844 #define MII_KSZ9031RN_RX_DATA_PAD_SKEW 5 845 #define MII_KSZ9031RN_RXD3 GENMASK(15, 12) 846 #define MII_KSZ9031RN_RXD2 GENMASK(11, 8) 847 #define MII_KSZ9031RN_RXD1 GENMASK(7, 4) 848 #define MII_KSZ9031RN_RXD0 GENMASK(3, 0) 849 850 #define MII_KSZ9031RN_TX_DATA_PAD_SKEW 6 851 #define MII_KSZ9031RN_TXD3 GENMASK(15, 12) 852 #define MII_KSZ9031RN_TXD2 GENMASK(11, 8) 853 #define MII_KSZ9031RN_TXD1 GENMASK(7, 4) 854 #define MII_KSZ9031RN_TXD0 GENMASK(3, 0) 855 856 #define MII_KSZ9031RN_CLK_PAD_SKEW 8 857 #define MII_KSZ9031RN_GTX_CLK GENMASK(9, 5) 858 #define MII_KSZ9031RN_RX_CLK GENMASK(4, 0) 859 860 /* KSZ9031 has internal RGMII_IDRX = 1.2ns and RGMII_IDTX = 0ns. To 861 * provide different RGMII options we need to configure delay offset 862 * for each pad relative to build in delay. 863 */ 864 /* keep rx as "No delay adjustment" and set rx_clk to +0.60ns to get delays of 865 * 1.80ns 866 */ 867 #define RX_ID 0x7 868 #define RX_CLK_ID 0x19 869 870 /* set rx to +0.30ns and rx_clk to -0.90ns to compensate the 871 * internal 1.2ns delay. 872 */ 873 #define RX_ND 0xc 874 #define RX_CLK_ND 0x0 875 876 /* set tx to -0.42ns and tx_clk to +0.96ns to get 1.38ns delay */ 877 #define TX_ID 0x0 878 #define TX_CLK_ID 0x1f 879 880 /* set tx and tx_clk to "No delay adjustment" to keep 0ns 881 * dealy 882 */ 883 #define TX_ND 0x7 884 #define TX_CLK_ND 0xf 885 886 /* MMD Address 0x1C */ 887 #define MII_KSZ9031RN_EDPD 0x23 888 #define MII_KSZ9031RN_EDPD_ENABLE BIT(0) 889 890 static int ksz9031_of_load_skew_values(struct phy_device *phydev, 891 const struct device_node *of_node, 892 u16 reg, size_t field_sz, 893 const char *field[], u8 numfields, 894 bool *update) 895 { 896 int val[4] = {-1, -2, -3, -4}; 897 int matches = 0; 898 u16 mask; 899 u16 maxval; 900 u16 newval; 901 int i; 902 903 for (i = 0; i < numfields; i++) 904 if (!of_property_read_u32(of_node, field[i], val + i)) 905 matches++; 906 907 if (!matches) 908 return 0; 909 910 *update |= true; 911 912 if (matches < numfields) 913 newval = phy_read_mmd(phydev, 2, reg); 914 else 915 newval = 0; 916 917 maxval = (field_sz == 4) ? 0xf : 0x1f; 918 for (i = 0; i < numfields; i++) 919 if (val[i] != -(i + 1)) { 920 mask = 0xffff; 921 mask ^= maxval << (field_sz * i); 922 newval = (newval & mask) | 923 (((val[i] / KSZ9031_PS_TO_REG) & maxval) 924 << (field_sz * i)); 925 } 926 927 return phy_write_mmd(phydev, 2, reg, newval); 928 } 929 930 /* Center KSZ9031RNX FLP timing at 16ms. */ 931 static int ksz9031_center_flp_timing(struct phy_device *phydev) 932 { 933 int result; 934 935 result = phy_write_mmd(phydev, 0, MII_KSZ9031RN_FLP_BURST_TX_HI, 936 0x0006); 937 if (result) 938 return result; 939 940 result = phy_write_mmd(phydev, 0, MII_KSZ9031RN_FLP_BURST_TX_LO, 941 0x1A80); 942 if (result) 943 return result; 944 945 return genphy_restart_aneg(phydev); 946 } 947 948 /* Enable energy-detect power-down mode */ 949 static int ksz9031_enable_edpd(struct phy_device *phydev) 950 { 951 int reg; 952 953 reg = phy_read_mmd(phydev, 0x1C, MII_KSZ9031RN_EDPD); 954 if (reg < 0) 955 return reg; 956 return phy_write_mmd(phydev, 0x1C, MII_KSZ9031RN_EDPD, 957 reg | MII_KSZ9031RN_EDPD_ENABLE); 958 } 959 960 static int ksz9031_config_rgmii_delay(struct phy_device *phydev) 961 { 962 u16 rx, tx, rx_clk, tx_clk; 963 int ret; 964 965 switch (phydev->interface) { 966 case PHY_INTERFACE_MODE_RGMII: 967 tx = TX_ND; 968 tx_clk = TX_CLK_ND; 969 rx = RX_ND; 970 rx_clk = RX_CLK_ND; 971 break; 972 case PHY_INTERFACE_MODE_RGMII_ID: 973 tx = TX_ID; 974 tx_clk = TX_CLK_ID; 975 rx = RX_ID; 976 rx_clk = RX_CLK_ID; 977 break; 978 case PHY_INTERFACE_MODE_RGMII_RXID: 979 tx = TX_ND; 980 tx_clk = TX_CLK_ND; 981 rx = RX_ID; 982 rx_clk = RX_CLK_ID; 983 break; 984 case PHY_INTERFACE_MODE_RGMII_TXID: 985 tx = TX_ID; 986 tx_clk = TX_CLK_ID; 987 rx = RX_ND; 988 rx_clk = RX_CLK_ND; 989 break; 990 default: 991 return 0; 992 } 993 994 ret = phy_write_mmd(phydev, 2, MII_KSZ9031RN_CONTROL_PAD_SKEW, 995 FIELD_PREP(MII_KSZ9031RN_RX_CTL_M, rx) | 996 FIELD_PREP(MII_KSZ9031RN_TX_CTL_M, tx)); 997 if (ret < 0) 998 return ret; 999 1000 ret = phy_write_mmd(phydev, 2, MII_KSZ9031RN_RX_DATA_PAD_SKEW, 1001 FIELD_PREP(MII_KSZ9031RN_RXD3, rx) | 1002 FIELD_PREP(MII_KSZ9031RN_RXD2, rx) | 1003 FIELD_PREP(MII_KSZ9031RN_RXD1, rx) | 1004 FIELD_PREP(MII_KSZ9031RN_RXD0, rx)); 1005 if (ret < 0) 1006 return ret; 1007 1008 ret = phy_write_mmd(phydev, 2, MII_KSZ9031RN_TX_DATA_PAD_SKEW, 1009 FIELD_PREP(MII_KSZ9031RN_TXD3, tx) | 1010 FIELD_PREP(MII_KSZ9031RN_TXD2, tx) | 1011 FIELD_PREP(MII_KSZ9031RN_TXD1, tx) | 1012 FIELD_PREP(MII_KSZ9031RN_TXD0, tx)); 1013 if (ret < 0) 1014 return ret; 1015 1016 return phy_write_mmd(phydev, 2, MII_KSZ9031RN_CLK_PAD_SKEW, 1017 FIELD_PREP(MII_KSZ9031RN_GTX_CLK, tx_clk) | 1018 FIELD_PREP(MII_KSZ9031RN_RX_CLK, rx_clk)); 1019 } 1020 1021 static int ksz9031_config_init(struct phy_device *phydev) 1022 { 1023 const struct device_node *of_node; 1024 static const char *clk_skews[2] = {"rxc-skew-ps", "txc-skew-ps"}; 1025 static const char *rx_data_skews[4] = { 1026 "rxd0-skew-ps", "rxd1-skew-ps", 1027 "rxd2-skew-ps", "rxd3-skew-ps" 1028 }; 1029 static const char *tx_data_skews[4] = { 1030 "txd0-skew-ps", "txd1-skew-ps", 1031 "txd2-skew-ps", "txd3-skew-ps" 1032 }; 1033 static const char *control_skews[2] = {"txen-skew-ps", "rxdv-skew-ps"}; 1034 const struct device *dev_walker; 1035 int result; 1036 1037 result = ksz9031_enable_edpd(phydev); 1038 if (result < 0) 1039 return result; 1040 1041 /* The Micrel driver has a deprecated option to place phy OF 1042 * properties in the MAC node. Walk up the tree of devices to 1043 * find a device with an OF node. 1044 */ 1045 dev_walker = &phydev->mdio.dev; 1046 do { 1047 of_node = dev_walker->of_node; 1048 dev_walker = dev_walker->parent; 1049 } while (!of_node && dev_walker); 1050 1051 if (of_node) { 1052 bool update = false; 1053 1054 if (phy_interface_is_rgmii(phydev)) { 1055 result = ksz9031_config_rgmii_delay(phydev); 1056 if (result < 0) 1057 return result; 1058 } 1059 1060 ksz9031_of_load_skew_values(phydev, of_node, 1061 MII_KSZ9031RN_CLK_PAD_SKEW, 5, 1062 clk_skews, 2, &update); 1063 1064 ksz9031_of_load_skew_values(phydev, of_node, 1065 MII_KSZ9031RN_CONTROL_PAD_SKEW, 4, 1066 control_skews, 2, &update); 1067 1068 ksz9031_of_load_skew_values(phydev, of_node, 1069 MII_KSZ9031RN_RX_DATA_PAD_SKEW, 4, 1070 rx_data_skews, 4, &update); 1071 1072 ksz9031_of_load_skew_values(phydev, of_node, 1073 MII_KSZ9031RN_TX_DATA_PAD_SKEW, 4, 1074 tx_data_skews, 4, &update); 1075 1076 if (update && !phy_interface_is_rgmii(phydev)) 1077 phydev_warn(phydev, 1078 "*-skew-ps values should be used only with RGMII PHY modes\n"); 1079 1080 /* Silicon Errata Sheet (DS80000691D or DS80000692D): 1081 * When the device links in the 1000BASE-T slave mode only, 1082 * the optional 125MHz reference output clock (CLK125_NDO) 1083 * has wide duty cycle variation. 1084 * 1085 * The optional CLK125_NDO clock does not meet the RGMII 1086 * 45/55 percent (min/max) duty cycle requirement and therefore 1087 * cannot be used directly by the MAC side for clocking 1088 * applications that have setup/hold time requirements on 1089 * rising and falling clock edges. 1090 * 1091 * Workaround: 1092 * Force the phy to be the master to receive a stable clock 1093 * which meets the duty cycle requirement. 1094 */ 1095 if (of_property_read_bool(of_node, "micrel,force-master")) { 1096 result = phy_read(phydev, MII_CTRL1000); 1097 if (result < 0) 1098 goto err_force_master; 1099 1100 /* enable master mode, config & prefer master */ 1101 result |= CTL1000_ENABLE_MASTER | CTL1000_AS_MASTER; 1102 result = phy_write(phydev, MII_CTRL1000, result); 1103 if (result < 0) 1104 goto err_force_master; 1105 } 1106 } 1107 1108 return ksz9031_center_flp_timing(phydev); 1109 1110 err_force_master: 1111 phydev_err(phydev, "failed to force the phy to master mode\n"); 1112 return result; 1113 } 1114 1115 #define KSZ9131_SKEW_5BIT_MAX 2400 1116 #define KSZ9131_SKEW_4BIT_MAX 800 1117 #define KSZ9131_OFFSET 700 1118 #define KSZ9131_STEP 100 1119 1120 static int ksz9131_of_load_skew_values(struct phy_device *phydev, 1121 struct device_node *of_node, 1122 u16 reg, size_t field_sz, 1123 char *field[], u8 numfields) 1124 { 1125 int val[4] = {-(1 + KSZ9131_OFFSET), -(2 + KSZ9131_OFFSET), 1126 -(3 + KSZ9131_OFFSET), -(4 + KSZ9131_OFFSET)}; 1127 int skewval, skewmax = 0; 1128 int matches = 0; 1129 u16 maxval; 1130 u16 newval; 1131 u16 mask; 1132 int i; 1133 1134 /* psec properties in dts should mean x pico seconds */ 1135 if (field_sz == 5) 1136 skewmax = KSZ9131_SKEW_5BIT_MAX; 1137 else 1138 skewmax = KSZ9131_SKEW_4BIT_MAX; 1139 1140 for (i = 0; i < numfields; i++) 1141 if (!of_property_read_s32(of_node, field[i], &skewval)) { 1142 if (skewval < -KSZ9131_OFFSET) 1143 skewval = -KSZ9131_OFFSET; 1144 else if (skewval > skewmax) 1145 skewval = skewmax; 1146 1147 val[i] = skewval + KSZ9131_OFFSET; 1148 matches++; 1149 } 1150 1151 if (!matches) 1152 return 0; 1153 1154 if (matches < numfields) 1155 newval = phy_read_mmd(phydev, 2, reg); 1156 else 1157 newval = 0; 1158 1159 maxval = (field_sz == 4) ? 0xf : 0x1f; 1160 for (i = 0; i < numfields; i++) 1161 if (val[i] != -(i + 1 + KSZ9131_OFFSET)) { 1162 mask = 0xffff; 1163 mask ^= maxval << (field_sz * i); 1164 newval = (newval & mask) | 1165 (((val[i] / KSZ9131_STEP) & maxval) 1166 << (field_sz * i)); 1167 } 1168 1169 return phy_write_mmd(phydev, 2, reg, newval); 1170 } 1171 1172 #define KSZ9131RN_MMD_COMMON_CTRL_REG 2 1173 #define KSZ9131RN_RXC_DLL_CTRL 76 1174 #define KSZ9131RN_TXC_DLL_CTRL 77 1175 #define KSZ9131RN_DLL_CTRL_BYPASS BIT_MASK(12) 1176 #define KSZ9131RN_DLL_ENABLE_DELAY 0 1177 #define KSZ9131RN_DLL_DISABLE_DELAY BIT(12) 1178 1179 static int ksz9131_config_rgmii_delay(struct phy_device *phydev) 1180 { 1181 u16 rxcdll_val, txcdll_val; 1182 int ret; 1183 1184 switch (phydev->interface) { 1185 case PHY_INTERFACE_MODE_RGMII: 1186 rxcdll_val = KSZ9131RN_DLL_DISABLE_DELAY; 1187 txcdll_val = KSZ9131RN_DLL_DISABLE_DELAY; 1188 break; 1189 case PHY_INTERFACE_MODE_RGMII_ID: 1190 rxcdll_val = KSZ9131RN_DLL_ENABLE_DELAY; 1191 txcdll_val = KSZ9131RN_DLL_ENABLE_DELAY; 1192 break; 1193 case PHY_INTERFACE_MODE_RGMII_RXID: 1194 rxcdll_val = KSZ9131RN_DLL_ENABLE_DELAY; 1195 txcdll_val = KSZ9131RN_DLL_DISABLE_DELAY; 1196 break; 1197 case PHY_INTERFACE_MODE_RGMII_TXID: 1198 rxcdll_val = KSZ9131RN_DLL_DISABLE_DELAY; 1199 txcdll_val = KSZ9131RN_DLL_ENABLE_DELAY; 1200 break; 1201 default: 1202 return 0; 1203 } 1204 1205 ret = phy_modify_mmd(phydev, KSZ9131RN_MMD_COMMON_CTRL_REG, 1206 KSZ9131RN_RXC_DLL_CTRL, KSZ9131RN_DLL_CTRL_BYPASS, 1207 rxcdll_val); 1208 if (ret < 0) 1209 return ret; 1210 1211 return phy_modify_mmd(phydev, KSZ9131RN_MMD_COMMON_CTRL_REG, 1212 KSZ9131RN_TXC_DLL_CTRL, KSZ9131RN_DLL_CTRL_BYPASS, 1213 txcdll_val); 1214 } 1215 1216 /* Silicon Errata DS80000693B 1217 * 1218 * When LEDs are configured in Individual Mode, LED1 is ON in a no-link 1219 * condition. Workaround is to set register 0x1e, bit 9, this way LED1 behaves 1220 * according to the datasheet (off if there is no link). 1221 */ 1222 static int ksz9131_led_errata(struct phy_device *phydev) 1223 { 1224 int reg; 1225 1226 reg = phy_read_mmd(phydev, 2, 0); 1227 if (reg < 0) 1228 return reg; 1229 1230 if (!(reg & BIT(4))) 1231 return 0; 1232 1233 return phy_set_bits(phydev, 0x1e, BIT(9)); 1234 } 1235 1236 static int ksz9131_config_init(struct phy_device *phydev) 1237 { 1238 struct device_node *of_node; 1239 char *clk_skews[2] = {"rxc-skew-psec", "txc-skew-psec"}; 1240 char *rx_data_skews[4] = { 1241 "rxd0-skew-psec", "rxd1-skew-psec", 1242 "rxd2-skew-psec", "rxd3-skew-psec" 1243 }; 1244 char *tx_data_skews[4] = { 1245 "txd0-skew-psec", "txd1-skew-psec", 1246 "txd2-skew-psec", "txd3-skew-psec" 1247 }; 1248 char *control_skews[2] = {"txen-skew-psec", "rxdv-skew-psec"}; 1249 const struct device *dev_walker; 1250 int ret; 1251 1252 dev_walker = &phydev->mdio.dev; 1253 do { 1254 of_node = dev_walker->of_node; 1255 dev_walker = dev_walker->parent; 1256 } while (!of_node && dev_walker); 1257 1258 if (!of_node) 1259 return 0; 1260 1261 if (phy_interface_is_rgmii(phydev)) { 1262 ret = ksz9131_config_rgmii_delay(phydev); 1263 if (ret < 0) 1264 return ret; 1265 } 1266 1267 ret = ksz9131_of_load_skew_values(phydev, of_node, 1268 MII_KSZ9031RN_CLK_PAD_SKEW, 5, 1269 clk_skews, 2); 1270 if (ret < 0) 1271 return ret; 1272 1273 ret = ksz9131_of_load_skew_values(phydev, of_node, 1274 MII_KSZ9031RN_CONTROL_PAD_SKEW, 4, 1275 control_skews, 2); 1276 if (ret < 0) 1277 return ret; 1278 1279 ret = ksz9131_of_load_skew_values(phydev, of_node, 1280 MII_KSZ9031RN_RX_DATA_PAD_SKEW, 4, 1281 rx_data_skews, 4); 1282 if (ret < 0) 1283 return ret; 1284 1285 ret = ksz9131_of_load_skew_values(phydev, of_node, 1286 MII_KSZ9031RN_TX_DATA_PAD_SKEW, 4, 1287 tx_data_skews, 4); 1288 if (ret < 0) 1289 return ret; 1290 1291 ret = ksz9131_led_errata(phydev); 1292 if (ret < 0) 1293 return ret; 1294 1295 return 0; 1296 } 1297 1298 #define MII_KSZ9131_AUTO_MDIX 0x1C 1299 #define MII_KSZ9131_AUTO_MDI_SET BIT(7) 1300 #define MII_KSZ9131_AUTO_MDIX_SWAP_OFF BIT(6) 1301 1302 static int ksz9131_mdix_update(struct phy_device *phydev) 1303 { 1304 int ret; 1305 1306 ret = phy_read(phydev, MII_KSZ9131_AUTO_MDIX); 1307 if (ret < 0) 1308 return ret; 1309 1310 if (ret & MII_KSZ9131_AUTO_MDIX_SWAP_OFF) { 1311 if (ret & MII_KSZ9131_AUTO_MDI_SET) 1312 phydev->mdix_ctrl = ETH_TP_MDI; 1313 else 1314 phydev->mdix_ctrl = ETH_TP_MDI_X; 1315 } else { 1316 phydev->mdix_ctrl = ETH_TP_MDI_AUTO; 1317 } 1318 1319 if (ret & MII_KSZ9131_AUTO_MDI_SET) 1320 phydev->mdix = ETH_TP_MDI; 1321 else 1322 phydev->mdix = ETH_TP_MDI_X; 1323 1324 return 0; 1325 } 1326 1327 static int ksz9131_config_mdix(struct phy_device *phydev, u8 ctrl) 1328 { 1329 u16 val; 1330 1331 switch (ctrl) { 1332 case ETH_TP_MDI: 1333 val = MII_KSZ9131_AUTO_MDIX_SWAP_OFF | 1334 MII_KSZ9131_AUTO_MDI_SET; 1335 break; 1336 case ETH_TP_MDI_X: 1337 val = MII_KSZ9131_AUTO_MDIX_SWAP_OFF; 1338 break; 1339 case ETH_TP_MDI_AUTO: 1340 val = 0; 1341 break; 1342 default: 1343 return 0; 1344 } 1345 1346 return phy_modify(phydev, MII_KSZ9131_AUTO_MDIX, 1347 MII_KSZ9131_AUTO_MDIX_SWAP_OFF | 1348 MII_KSZ9131_AUTO_MDI_SET, val); 1349 } 1350 1351 static int ksz9131_read_status(struct phy_device *phydev) 1352 { 1353 int ret; 1354 1355 ret = ksz9131_mdix_update(phydev); 1356 if (ret < 0) 1357 return ret; 1358 1359 return genphy_read_status(phydev); 1360 } 1361 1362 static int ksz9131_config_aneg(struct phy_device *phydev) 1363 { 1364 int ret; 1365 1366 ret = ksz9131_config_mdix(phydev, phydev->mdix_ctrl); 1367 if (ret) 1368 return ret; 1369 1370 return genphy_config_aneg(phydev); 1371 } 1372 1373 #define KSZ8873MLL_GLOBAL_CONTROL_4 0x06 1374 #define KSZ8873MLL_GLOBAL_CONTROL_4_DUPLEX BIT(6) 1375 #define KSZ8873MLL_GLOBAL_CONTROL_4_SPEED BIT(4) 1376 static int ksz8873mll_read_status(struct phy_device *phydev) 1377 { 1378 int regval; 1379 1380 /* dummy read */ 1381 regval = phy_read(phydev, KSZ8873MLL_GLOBAL_CONTROL_4); 1382 1383 regval = phy_read(phydev, KSZ8873MLL_GLOBAL_CONTROL_4); 1384 1385 if (regval & KSZ8873MLL_GLOBAL_CONTROL_4_DUPLEX) 1386 phydev->duplex = DUPLEX_HALF; 1387 else 1388 phydev->duplex = DUPLEX_FULL; 1389 1390 if (regval & KSZ8873MLL_GLOBAL_CONTROL_4_SPEED) 1391 phydev->speed = SPEED_10; 1392 else 1393 phydev->speed = SPEED_100; 1394 1395 phydev->link = 1; 1396 phydev->pause = phydev->asym_pause = 0; 1397 1398 return 0; 1399 } 1400 1401 static int ksz9031_get_features(struct phy_device *phydev) 1402 { 1403 int ret; 1404 1405 ret = genphy_read_abilities(phydev); 1406 if (ret < 0) 1407 return ret; 1408 1409 /* Silicon Errata Sheet (DS80000691D or DS80000692D): 1410 * Whenever the device's Asymmetric Pause capability is set to 1, 1411 * link-up may fail after a link-up to link-down transition. 1412 * 1413 * The Errata Sheet is for ksz9031, but ksz9021 has the same issue 1414 * 1415 * Workaround: 1416 * Do not enable the Asymmetric Pause capability bit. 1417 */ 1418 linkmode_clear_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, phydev->supported); 1419 1420 /* We force setting the Pause capability as the core will force the 1421 * Asymmetric Pause capability to 1 otherwise. 1422 */ 1423 linkmode_set_bit(ETHTOOL_LINK_MODE_Pause_BIT, phydev->supported); 1424 1425 return 0; 1426 } 1427 1428 static int ksz9031_read_status(struct phy_device *phydev) 1429 { 1430 int err; 1431 int regval; 1432 1433 err = genphy_read_status(phydev); 1434 if (err) 1435 return err; 1436 1437 /* Make sure the PHY is not broken. Read idle error count, 1438 * and reset the PHY if it is maxed out. 1439 */ 1440 regval = phy_read(phydev, MII_STAT1000); 1441 if ((regval & 0xFF) == 0xFF) { 1442 phy_init_hw(phydev); 1443 phydev->link = 0; 1444 if (phydev->drv->config_intr && phy_interrupt_is_valid(phydev)) 1445 phydev->drv->config_intr(phydev); 1446 return genphy_config_aneg(phydev); 1447 } 1448 1449 return 0; 1450 } 1451 1452 static int ksz9x31_cable_test_start(struct phy_device *phydev) 1453 { 1454 struct kszphy_priv *priv = phydev->priv; 1455 int ret; 1456 1457 /* KSZ9131RNX, DS00002841B-page 38, 4.14 LinkMD (R) Cable Diagnostic 1458 * Prior to running the cable diagnostics, Auto-negotiation should 1459 * be disabled, full duplex set and the link speed set to 1000Mbps 1460 * via the Basic Control Register. 1461 */ 1462 ret = phy_modify(phydev, MII_BMCR, 1463 BMCR_SPEED1000 | BMCR_FULLDPLX | 1464 BMCR_ANENABLE | BMCR_SPEED100, 1465 BMCR_SPEED1000 | BMCR_FULLDPLX); 1466 if (ret) 1467 return ret; 1468 1469 /* KSZ9131RNX, DS00002841B-page 38, 4.14 LinkMD (R) Cable Diagnostic 1470 * The Master-Slave configuration should be set to Slave by writing 1471 * a value of 0x1000 to the Auto-Negotiation Master Slave Control 1472 * Register. 1473 */ 1474 ret = phy_read(phydev, MII_CTRL1000); 1475 if (ret < 0) 1476 return ret; 1477 1478 /* Cache these bits, they need to be restored once LinkMD finishes. */ 1479 priv->vct_ctrl1000 = ret & (CTL1000_ENABLE_MASTER | CTL1000_AS_MASTER); 1480 ret &= ~(CTL1000_ENABLE_MASTER | CTL1000_AS_MASTER); 1481 ret |= CTL1000_ENABLE_MASTER; 1482 1483 return phy_write(phydev, MII_CTRL1000, ret); 1484 } 1485 1486 static int ksz9x31_cable_test_result_trans(u16 status) 1487 { 1488 switch (FIELD_GET(KSZ9x31_LMD_VCT_ST_MASK, status)) { 1489 case KSZ9x31_LMD_VCT_ST_NORMAL: 1490 return ETHTOOL_A_CABLE_RESULT_CODE_OK; 1491 case KSZ9x31_LMD_VCT_ST_OPEN: 1492 return ETHTOOL_A_CABLE_RESULT_CODE_OPEN; 1493 case KSZ9x31_LMD_VCT_ST_SHORT: 1494 return ETHTOOL_A_CABLE_RESULT_CODE_SAME_SHORT; 1495 case KSZ9x31_LMD_VCT_ST_FAIL: 1496 fallthrough; 1497 default: 1498 return ETHTOOL_A_CABLE_RESULT_CODE_UNSPEC; 1499 } 1500 } 1501 1502 static bool ksz9x31_cable_test_failed(u16 status) 1503 { 1504 int stat = FIELD_GET(KSZ9x31_LMD_VCT_ST_MASK, status); 1505 1506 return stat == KSZ9x31_LMD_VCT_ST_FAIL; 1507 } 1508 1509 static bool ksz9x31_cable_test_fault_length_valid(u16 status) 1510 { 1511 switch (FIELD_GET(KSZ9x31_LMD_VCT_ST_MASK, status)) { 1512 case KSZ9x31_LMD_VCT_ST_OPEN: 1513 fallthrough; 1514 case KSZ9x31_LMD_VCT_ST_SHORT: 1515 return true; 1516 } 1517 return false; 1518 } 1519 1520 static int ksz9x31_cable_test_fault_length(struct phy_device *phydev, u16 stat) 1521 { 1522 int dt = FIELD_GET(KSZ9x31_LMD_VCT_DATA_MASK, stat); 1523 1524 /* KSZ9131RNX, DS00002841B-page 38, 4.14 LinkMD (R) Cable Diagnostic 1525 * 1526 * distance to fault = (VCT_DATA - 22) * 4 / cable propagation velocity 1527 */ 1528 if ((phydev->phy_id & MICREL_PHY_ID_MASK) == PHY_ID_KSZ9131) 1529 dt = clamp(dt - 22, 0, 255); 1530 1531 return (dt * 400) / 10; 1532 } 1533 1534 static int ksz9x31_cable_test_wait_for_completion(struct phy_device *phydev) 1535 { 1536 int val, ret; 1537 1538 ret = phy_read_poll_timeout(phydev, KSZ9x31_LMD, val, 1539 !(val & KSZ9x31_LMD_VCT_EN), 1540 30000, 100000, true); 1541 1542 return ret < 0 ? ret : 0; 1543 } 1544 1545 static int ksz9x31_cable_test_get_pair(int pair) 1546 { 1547 static const int ethtool_pair[] = { 1548 ETHTOOL_A_CABLE_PAIR_A, 1549 ETHTOOL_A_CABLE_PAIR_B, 1550 ETHTOOL_A_CABLE_PAIR_C, 1551 ETHTOOL_A_CABLE_PAIR_D, 1552 }; 1553 1554 return ethtool_pair[pair]; 1555 } 1556 1557 static int ksz9x31_cable_test_one_pair(struct phy_device *phydev, int pair) 1558 { 1559 int ret, val; 1560 1561 /* KSZ9131RNX, DS00002841B-page 38, 4.14 LinkMD (R) Cable Diagnostic 1562 * To test each individual cable pair, set the cable pair in the Cable 1563 * Diagnostics Test Pair (VCT_PAIR[1:0]) field of the LinkMD Cable 1564 * Diagnostic Register, along with setting the Cable Diagnostics Test 1565 * Enable (VCT_EN) bit. The Cable Diagnostics Test Enable (VCT_EN) bit 1566 * will self clear when the test is concluded. 1567 */ 1568 ret = phy_write(phydev, KSZ9x31_LMD, 1569 KSZ9x31_LMD_VCT_EN | KSZ9x31_LMD_VCT_PAIR(pair)); 1570 if (ret) 1571 return ret; 1572 1573 ret = ksz9x31_cable_test_wait_for_completion(phydev); 1574 if (ret) 1575 return ret; 1576 1577 val = phy_read(phydev, KSZ9x31_LMD); 1578 if (val < 0) 1579 return val; 1580 1581 if (ksz9x31_cable_test_failed(val)) 1582 return -EAGAIN; 1583 1584 ret = ethnl_cable_test_result(phydev, 1585 ksz9x31_cable_test_get_pair(pair), 1586 ksz9x31_cable_test_result_trans(val)); 1587 if (ret) 1588 return ret; 1589 1590 if (!ksz9x31_cable_test_fault_length_valid(val)) 1591 return 0; 1592 1593 return ethnl_cable_test_fault_length(phydev, 1594 ksz9x31_cable_test_get_pair(pair), 1595 ksz9x31_cable_test_fault_length(phydev, val)); 1596 } 1597 1598 static int ksz9x31_cable_test_get_status(struct phy_device *phydev, 1599 bool *finished) 1600 { 1601 struct kszphy_priv *priv = phydev->priv; 1602 unsigned long pair_mask = 0xf; 1603 int retries = 20; 1604 int pair, ret, rv; 1605 1606 *finished = false; 1607 1608 /* Try harder if link partner is active */ 1609 while (pair_mask && retries--) { 1610 for_each_set_bit(pair, &pair_mask, 4) { 1611 ret = ksz9x31_cable_test_one_pair(phydev, pair); 1612 if (ret == -EAGAIN) 1613 continue; 1614 if (ret < 0) 1615 return ret; 1616 clear_bit(pair, &pair_mask); 1617 } 1618 /* If link partner is in autonegotiation mode it will send 2ms 1619 * of FLPs with at least 6ms of silence. 1620 * Add 2ms sleep to have better chances to hit this silence. 1621 */ 1622 if (pair_mask) 1623 usleep_range(2000, 3000); 1624 } 1625 1626 /* Report remaining unfinished pair result as unknown. */ 1627 for_each_set_bit(pair, &pair_mask, 4) { 1628 ret = ethnl_cable_test_result(phydev, 1629 ksz9x31_cable_test_get_pair(pair), 1630 ETHTOOL_A_CABLE_RESULT_CODE_UNSPEC); 1631 } 1632 1633 *finished = true; 1634 1635 /* Restore cached bits from before LinkMD got started. */ 1636 rv = phy_modify(phydev, MII_CTRL1000, 1637 CTL1000_ENABLE_MASTER | CTL1000_AS_MASTER, 1638 priv->vct_ctrl1000); 1639 if (rv) 1640 return rv; 1641 1642 return ret; 1643 } 1644 1645 static int ksz8873mll_config_aneg(struct phy_device *phydev) 1646 { 1647 return 0; 1648 } 1649 1650 static int ksz886x_config_mdix(struct phy_device *phydev, u8 ctrl) 1651 { 1652 u16 val; 1653 1654 switch (ctrl) { 1655 case ETH_TP_MDI: 1656 val = KSZ886X_BMCR_DISABLE_AUTO_MDIX; 1657 break; 1658 case ETH_TP_MDI_X: 1659 /* Note: The naming of the bit KSZ886X_BMCR_FORCE_MDI is bit 1660 * counter intuitive, the "-X" in "1 = Force MDI" in the data 1661 * sheet seems to be missing: 1662 * 1 = Force MDI (sic!) (transmit on RX+/RX- pins) 1663 * 0 = Normal operation (transmit on TX+/TX- pins) 1664 */ 1665 val = KSZ886X_BMCR_DISABLE_AUTO_MDIX | KSZ886X_BMCR_FORCE_MDI; 1666 break; 1667 case ETH_TP_MDI_AUTO: 1668 val = 0; 1669 break; 1670 default: 1671 return 0; 1672 } 1673 1674 return phy_modify(phydev, MII_BMCR, 1675 KSZ886X_BMCR_HP_MDIX | KSZ886X_BMCR_FORCE_MDI | 1676 KSZ886X_BMCR_DISABLE_AUTO_MDIX, 1677 KSZ886X_BMCR_HP_MDIX | val); 1678 } 1679 1680 static int ksz886x_config_aneg(struct phy_device *phydev) 1681 { 1682 int ret; 1683 1684 ret = genphy_config_aneg(phydev); 1685 if (ret) 1686 return ret; 1687 1688 /* The MDI-X configuration is automatically changed by the PHY after 1689 * switching from autoneg off to on. So, take MDI-X configuration under 1690 * own control and set it after autoneg configuration was done. 1691 */ 1692 return ksz886x_config_mdix(phydev, phydev->mdix_ctrl); 1693 } 1694 1695 static int ksz886x_mdix_update(struct phy_device *phydev) 1696 { 1697 int ret; 1698 1699 ret = phy_read(phydev, MII_BMCR); 1700 if (ret < 0) 1701 return ret; 1702 1703 if (ret & KSZ886X_BMCR_DISABLE_AUTO_MDIX) { 1704 if (ret & KSZ886X_BMCR_FORCE_MDI) 1705 phydev->mdix_ctrl = ETH_TP_MDI_X; 1706 else 1707 phydev->mdix_ctrl = ETH_TP_MDI; 1708 } else { 1709 phydev->mdix_ctrl = ETH_TP_MDI_AUTO; 1710 } 1711 1712 ret = phy_read(phydev, MII_KSZPHY_CTRL); 1713 if (ret < 0) 1714 return ret; 1715 1716 /* Same reverse logic as KSZ886X_BMCR_FORCE_MDI */ 1717 if (ret & KSZ886X_CTRL_MDIX_STAT) 1718 phydev->mdix = ETH_TP_MDI_X; 1719 else 1720 phydev->mdix = ETH_TP_MDI; 1721 1722 return 0; 1723 } 1724 1725 static int ksz886x_read_status(struct phy_device *phydev) 1726 { 1727 int ret; 1728 1729 ret = ksz886x_mdix_update(phydev); 1730 if (ret < 0) 1731 return ret; 1732 1733 return genphy_read_status(phydev); 1734 } 1735 1736 static int kszphy_get_sset_count(struct phy_device *phydev) 1737 { 1738 return ARRAY_SIZE(kszphy_hw_stats); 1739 } 1740 1741 static void kszphy_get_strings(struct phy_device *phydev, u8 *data) 1742 { 1743 int i; 1744 1745 for (i = 0; i < ARRAY_SIZE(kszphy_hw_stats); i++) { 1746 strscpy(data + i * ETH_GSTRING_LEN, 1747 kszphy_hw_stats[i].string, ETH_GSTRING_LEN); 1748 } 1749 } 1750 1751 static u64 kszphy_get_stat(struct phy_device *phydev, int i) 1752 { 1753 struct kszphy_hw_stat stat = kszphy_hw_stats[i]; 1754 struct kszphy_priv *priv = phydev->priv; 1755 int val; 1756 u64 ret; 1757 1758 val = phy_read(phydev, stat.reg); 1759 if (val < 0) { 1760 ret = U64_MAX; 1761 } else { 1762 val = val & ((1 << stat.bits) - 1); 1763 priv->stats[i] += val; 1764 ret = priv->stats[i]; 1765 } 1766 1767 return ret; 1768 } 1769 1770 static void kszphy_get_stats(struct phy_device *phydev, 1771 struct ethtool_stats *stats, u64 *data) 1772 { 1773 int i; 1774 1775 for (i = 0; i < ARRAY_SIZE(kszphy_hw_stats); i++) 1776 data[i] = kszphy_get_stat(phydev, i); 1777 } 1778 1779 static int kszphy_suspend(struct phy_device *phydev) 1780 { 1781 /* Disable PHY Interrupts */ 1782 if (phy_interrupt_is_valid(phydev)) { 1783 phydev->interrupts = PHY_INTERRUPT_DISABLED; 1784 if (phydev->drv->config_intr) 1785 phydev->drv->config_intr(phydev); 1786 } 1787 1788 return genphy_suspend(phydev); 1789 } 1790 1791 static void kszphy_parse_led_mode(struct phy_device *phydev) 1792 { 1793 const struct kszphy_type *type = phydev->drv->driver_data; 1794 const struct device_node *np = phydev->mdio.dev.of_node; 1795 struct kszphy_priv *priv = phydev->priv; 1796 int ret; 1797 1798 if (type && type->led_mode_reg) { 1799 ret = of_property_read_u32(np, "micrel,led-mode", 1800 &priv->led_mode); 1801 1802 if (ret) 1803 priv->led_mode = -1; 1804 1805 if (priv->led_mode > 3) { 1806 phydev_err(phydev, "invalid led mode: 0x%02x\n", 1807 priv->led_mode); 1808 priv->led_mode = -1; 1809 } 1810 } else { 1811 priv->led_mode = -1; 1812 } 1813 } 1814 1815 static int kszphy_resume(struct phy_device *phydev) 1816 { 1817 int ret; 1818 1819 genphy_resume(phydev); 1820 1821 /* After switching from power-down to normal mode, an internal global 1822 * reset is automatically generated. Wait a minimum of 1 ms before 1823 * read/write access to the PHY registers. 1824 */ 1825 usleep_range(1000, 2000); 1826 1827 ret = kszphy_config_reset(phydev); 1828 if (ret) 1829 return ret; 1830 1831 /* Enable PHY Interrupts */ 1832 if (phy_interrupt_is_valid(phydev)) { 1833 phydev->interrupts = PHY_INTERRUPT_ENABLED; 1834 if (phydev->drv->config_intr) 1835 phydev->drv->config_intr(phydev); 1836 } 1837 1838 return 0; 1839 } 1840 1841 static int kszphy_probe(struct phy_device *phydev) 1842 { 1843 const struct kszphy_type *type = phydev->drv->driver_data; 1844 const struct device_node *np = phydev->mdio.dev.of_node; 1845 struct kszphy_priv *priv; 1846 struct clk *clk; 1847 1848 priv = devm_kzalloc(&phydev->mdio.dev, sizeof(*priv), GFP_KERNEL); 1849 if (!priv) 1850 return -ENOMEM; 1851 1852 phydev->priv = priv; 1853 1854 priv->type = type; 1855 1856 kszphy_parse_led_mode(phydev); 1857 1858 clk = devm_clk_get(&phydev->mdio.dev, "rmii-ref"); 1859 /* NOTE: clk may be NULL if building without CONFIG_HAVE_CLK */ 1860 if (!IS_ERR_OR_NULL(clk)) { 1861 unsigned long rate = clk_get_rate(clk); 1862 bool rmii_ref_clk_sel_25_mhz; 1863 1864 if (type) 1865 priv->rmii_ref_clk_sel = type->has_rmii_ref_clk_sel; 1866 rmii_ref_clk_sel_25_mhz = of_property_read_bool(np, 1867 "micrel,rmii-reference-clock-select-25-mhz"); 1868 1869 if (rate > 24500000 && rate < 25500000) { 1870 priv->rmii_ref_clk_sel_val = rmii_ref_clk_sel_25_mhz; 1871 } else if (rate > 49500000 && rate < 50500000) { 1872 priv->rmii_ref_clk_sel_val = !rmii_ref_clk_sel_25_mhz; 1873 } else { 1874 phydev_err(phydev, "Clock rate out of range: %ld\n", 1875 rate); 1876 return -EINVAL; 1877 } 1878 } 1879 1880 if (ksz8041_fiber_mode(phydev)) 1881 phydev->port = PORT_FIBRE; 1882 1883 /* Support legacy board-file configuration */ 1884 if (phydev->dev_flags & MICREL_PHY_50MHZ_CLK) { 1885 priv->rmii_ref_clk_sel = true; 1886 priv->rmii_ref_clk_sel_val = true; 1887 } 1888 1889 return 0; 1890 } 1891 1892 static int lan8814_cable_test_start(struct phy_device *phydev) 1893 { 1894 /* If autoneg is enabled, we won't be able to test cross pair 1895 * short. In this case, the PHY will "detect" a link and 1896 * confuse the internal state machine - disable auto neg here. 1897 * Set the speed to 1000mbit and full duplex. 1898 */ 1899 return phy_modify(phydev, MII_BMCR, BMCR_ANENABLE | BMCR_SPEED100, 1900 BMCR_SPEED1000 | BMCR_FULLDPLX); 1901 } 1902 1903 static int ksz886x_cable_test_start(struct phy_device *phydev) 1904 { 1905 if (phydev->dev_flags & MICREL_KSZ8_P1_ERRATA) 1906 return -EOPNOTSUPP; 1907 1908 /* If autoneg is enabled, we won't be able to test cross pair 1909 * short. In this case, the PHY will "detect" a link and 1910 * confuse the internal state machine - disable auto neg here. 1911 * If autoneg is disabled, we should set the speed to 10mbit. 1912 */ 1913 return phy_clear_bits(phydev, MII_BMCR, BMCR_ANENABLE | BMCR_SPEED100); 1914 } 1915 1916 static __always_inline int ksz886x_cable_test_result_trans(u16 status, u16 mask) 1917 { 1918 switch (FIELD_GET(mask, status)) { 1919 case KSZ8081_LMD_STAT_NORMAL: 1920 return ETHTOOL_A_CABLE_RESULT_CODE_OK; 1921 case KSZ8081_LMD_STAT_SHORT: 1922 return ETHTOOL_A_CABLE_RESULT_CODE_SAME_SHORT; 1923 case KSZ8081_LMD_STAT_OPEN: 1924 return ETHTOOL_A_CABLE_RESULT_CODE_OPEN; 1925 case KSZ8081_LMD_STAT_FAIL: 1926 fallthrough; 1927 default: 1928 return ETHTOOL_A_CABLE_RESULT_CODE_UNSPEC; 1929 } 1930 } 1931 1932 static __always_inline bool ksz886x_cable_test_failed(u16 status, u16 mask) 1933 { 1934 return FIELD_GET(mask, status) == 1935 KSZ8081_LMD_STAT_FAIL; 1936 } 1937 1938 static __always_inline bool ksz886x_cable_test_fault_length_valid(u16 status, u16 mask) 1939 { 1940 switch (FIELD_GET(mask, status)) { 1941 case KSZ8081_LMD_STAT_OPEN: 1942 fallthrough; 1943 case KSZ8081_LMD_STAT_SHORT: 1944 return true; 1945 } 1946 return false; 1947 } 1948 1949 static __always_inline int ksz886x_cable_test_fault_length(struct phy_device *phydev, 1950 u16 status, u16 data_mask) 1951 { 1952 int dt; 1953 1954 /* According to the data sheet the distance to the fault is 1955 * DELTA_TIME * 0.4 meters for ksz phys. 1956 * (DELTA_TIME - 22) * 0.8 for lan8814 phy. 1957 */ 1958 dt = FIELD_GET(data_mask, status); 1959 1960 if ((phydev->phy_id & MICREL_PHY_ID_MASK) == PHY_ID_LAN8814) 1961 return ((dt - 22) * 800) / 10; 1962 else 1963 return (dt * 400) / 10; 1964 } 1965 1966 static int ksz886x_cable_test_wait_for_completion(struct phy_device *phydev) 1967 { 1968 const struct kszphy_type *type = phydev->drv->driver_data; 1969 int val, ret; 1970 1971 ret = phy_read_poll_timeout(phydev, type->cable_diag_reg, val, 1972 !(val & KSZ8081_LMD_ENABLE_TEST), 1973 30000, 100000, true); 1974 1975 return ret < 0 ? ret : 0; 1976 } 1977 1978 static int lan8814_cable_test_one_pair(struct phy_device *phydev, int pair) 1979 { 1980 static const int ethtool_pair[] = { ETHTOOL_A_CABLE_PAIR_A, 1981 ETHTOOL_A_CABLE_PAIR_B, 1982 ETHTOOL_A_CABLE_PAIR_C, 1983 ETHTOOL_A_CABLE_PAIR_D, 1984 }; 1985 u32 fault_length; 1986 int ret; 1987 int val; 1988 1989 val = KSZ8081_LMD_ENABLE_TEST; 1990 val = val | (pair << LAN8814_PAIR_BIT_SHIFT); 1991 1992 ret = phy_write(phydev, LAN8814_CABLE_DIAG, val); 1993 if (ret < 0) 1994 return ret; 1995 1996 ret = ksz886x_cable_test_wait_for_completion(phydev); 1997 if (ret) 1998 return ret; 1999 2000 val = phy_read(phydev, LAN8814_CABLE_DIAG); 2001 if (val < 0) 2002 return val; 2003 2004 if (ksz886x_cable_test_failed(val, LAN8814_CABLE_DIAG_STAT_MASK)) 2005 return -EAGAIN; 2006 2007 ret = ethnl_cable_test_result(phydev, ethtool_pair[pair], 2008 ksz886x_cable_test_result_trans(val, 2009 LAN8814_CABLE_DIAG_STAT_MASK 2010 )); 2011 if (ret) 2012 return ret; 2013 2014 if (!ksz886x_cable_test_fault_length_valid(val, LAN8814_CABLE_DIAG_STAT_MASK)) 2015 return 0; 2016 2017 fault_length = ksz886x_cable_test_fault_length(phydev, val, 2018 LAN8814_CABLE_DIAG_VCT_DATA_MASK); 2019 2020 return ethnl_cable_test_fault_length(phydev, ethtool_pair[pair], fault_length); 2021 } 2022 2023 static int ksz886x_cable_test_one_pair(struct phy_device *phydev, int pair) 2024 { 2025 static const int ethtool_pair[] = { 2026 ETHTOOL_A_CABLE_PAIR_A, 2027 ETHTOOL_A_CABLE_PAIR_B, 2028 }; 2029 int ret, val, mdix; 2030 u32 fault_length; 2031 2032 /* There is no way to choice the pair, like we do one ksz9031. 2033 * We can workaround this limitation by using the MDI-X functionality. 2034 */ 2035 if (pair == 0) 2036 mdix = ETH_TP_MDI; 2037 else 2038 mdix = ETH_TP_MDI_X; 2039 2040 switch (phydev->phy_id & MICREL_PHY_ID_MASK) { 2041 case PHY_ID_KSZ8081: 2042 ret = ksz8081_config_mdix(phydev, mdix); 2043 break; 2044 case PHY_ID_KSZ886X: 2045 ret = ksz886x_config_mdix(phydev, mdix); 2046 break; 2047 default: 2048 ret = -ENODEV; 2049 } 2050 2051 if (ret) 2052 return ret; 2053 2054 /* Now we are ready to fire. This command will send a 100ns pulse 2055 * to the pair. 2056 */ 2057 ret = phy_write(phydev, KSZ8081_LMD, KSZ8081_LMD_ENABLE_TEST); 2058 if (ret) 2059 return ret; 2060 2061 ret = ksz886x_cable_test_wait_for_completion(phydev); 2062 if (ret) 2063 return ret; 2064 2065 val = phy_read(phydev, KSZ8081_LMD); 2066 if (val < 0) 2067 return val; 2068 2069 if (ksz886x_cable_test_failed(val, KSZ8081_LMD_STAT_MASK)) 2070 return -EAGAIN; 2071 2072 ret = ethnl_cable_test_result(phydev, ethtool_pair[pair], 2073 ksz886x_cable_test_result_trans(val, KSZ8081_LMD_STAT_MASK)); 2074 if (ret) 2075 return ret; 2076 2077 if (!ksz886x_cable_test_fault_length_valid(val, KSZ8081_LMD_STAT_MASK)) 2078 return 0; 2079 2080 fault_length = ksz886x_cable_test_fault_length(phydev, val, KSZ8081_LMD_DELTA_TIME_MASK); 2081 2082 return ethnl_cable_test_fault_length(phydev, ethtool_pair[pair], fault_length); 2083 } 2084 2085 static int ksz886x_cable_test_get_status(struct phy_device *phydev, 2086 bool *finished) 2087 { 2088 const struct kszphy_type *type = phydev->drv->driver_data; 2089 unsigned long pair_mask = type->pair_mask; 2090 int retries = 20; 2091 int ret = 0; 2092 int pair; 2093 2094 *finished = false; 2095 2096 /* Try harder if link partner is active */ 2097 while (pair_mask && retries--) { 2098 for_each_set_bit(pair, &pair_mask, 4) { 2099 if (type->cable_diag_reg == LAN8814_CABLE_DIAG) 2100 ret = lan8814_cable_test_one_pair(phydev, pair); 2101 else 2102 ret = ksz886x_cable_test_one_pair(phydev, pair); 2103 if (ret == -EAGAIN) 2104 continue; 2105 if (ret < 0) 2106 return ret; 2107 clear_bit(pair, &pair_mask); 2108 } 2109 /* If link partner is in autonegotiation mode it will send 2ms 2110 * of FLPs with at least 6ms of silence. 2111 * Add 2ms sleep to have better chances to hit this silence. 2112 */ 2113 if (pair_mask) 2114 msleep(2); 2115 } 2116 2117 *finished = true; 2118 2119 return ret; 2120 } 2121 2122 #define LAN_EXT_PAGE_ACCESS_CONTROL 0x16 2123 #define LAN_EXT_PAGE_ACCESS_ADDRESS_DATA 0x17 2124 #define LAN_EXT_PAGE_ACCESS_CTRL_EP_FUNC 0x4000 2125 2126 #define LAN8814_QSGMII_SOFT_RESET 0x43 2127 #define LAN8814_QSGMII_SOFT_RESET_BIT BIT(0) 2128 #define LAN8814_QSGMII_PCS1G_ANEG_CONFIG 0x13 2129 #define LAN8814_QSGMII_PCS1G_ANEG_CONFIG_ANEG_ENA BIT(3) 2130 #define LAN8814_ALIGN_SWAP 0x4a 2131 #define LAN8814_ALIGN_TX_A_B_SWAP 0x1 2132 #define LAN8814_ALIGN_TX_A_B_SWAP_MASK GENMASK(2, 0) 2133 2134 #define LAN8804_ALIGN_SWAP 0x4a 2135 #define LAN8804_ALIGN_TX_A_B_SWAP 0x1 2136 #define LAN8804_ALIGN_TX_A_B_SWAP_MASK GENMASK(2, 0) 2137 #define LAN8814_CLOCK_MANAGEMENT 0xd 2138 #define LAN8814_LINK_QUALITY 0x8e 2139 2140 static int lanphy_read_page_reg(struct phy_device *phydev, int page, u32 addr) 2141 { 2142 int data; 2143 2144 phy_lock_mdio_bus(phydev); 2145 __phy_write(phydev, LAN_EXT_PAGE_ACCESS_CONTROL, page); 2146 __phy_write(phydev, LAN_EXT_PAGE_ACCESS_ADDRESS_DATA, addr); 2147 __phy_write(phydev, LAN_EXT_PAGE_ACCESS_CONTROL, 2148 (page | LAN_EXT_PAGE_ACCESS_CTRL_EP_FUNC)); 2149 data = __phy_read(phydev, LAN_EXT_PAGE_ACCESS_ADDRESS_DATA); 2150 phy_unlock_mdio_bus(phydev); 2151 2152 return data; 2153 } 2154 2155 static int lanphy_write_page_reg(struct phy_device *phydev, int page, u16 addr, 2156 u16 val) 2157 { 2158 phy_lock_mdio_bus(phydev); 2159 __phy_write(phydev, LAN_EXT_PAGE_ACCESS_CONTROL, page); 2160 __phy_write(phydev, LAN_EXT_PAGE_ACCESS_ADDRESS_DATA, addr); 2161 __phy_write(phydev, LAN_EXT_PAGE_ACCESS_CONTROL, 2162 page | LAN_EXT_PAGE_ACCESS_CTRL_EP_FUNC); 2163 2164 val = __phy_write(phydev, LAN_EXT_PAGE_ACCESS_ADDRESS_DATA, val); 2165 if (val != 0) 2166 phydev_err(phydev, "Error: phy_write has returned error %d\n", 2167 val); 2168 phy_unlock_mdio_bus(phydev); 2169 return val; 2170 } 2171 2172 static int lan8814_config_ts_intr(struct phy_device *phydev, bool enable) 2173 { 2174 u16 val = 0; 2175 2176 if (enable) 2177 val = PTP_TSU_INT_EN_PTP_TX_TS_EN_ | 2178 PTP_TSU_INT_EN_PTP_TX_TS_OVRFL_EN_ | 2179 PTP_TSU_INT_EN_PTP_RX_TS_EN_ | 2180 PTP_TSU_INT_EN_PTP_RX_TS_OVRFL_EN_; 2181 2182 return lanphy_write_page_reg(phydev, 5, PTP_TSU_INT_EN, val); 2183 } 2184 2185 static void lan8814_ptp_rx_ts_get(struct phy_device *phydev, 2186 u32 *seconds, u32 *nano_seconds, u16 *seq_id) 2187 { 2188 *seconds = lanphy_read_page_reg(phydev, 5, PTP_RX_INGRESS_SEC_HI); 2189 *seconds = (*seconds << 16) | 2190 lanphy_read_page_reg(phydev, 5, PTP_RX_INGRESS_SEC_LO); 2191 2192 *nano_seconds = lanphy_read_page_reg(phydev, 5, PTP_RX_INGRESS_NS_HI); 2193 *nano_seconds = ((*nano_seconds & 0x3fff) << 16) | 2194 lanphy_read_page_reg(phydev, 5, PTP_RX_INGRESS_NS_LO); 2195 2196 *seq_id = lanphy_read_page_reg(phydev, 5, PTP_RX_MSG_HEADER2); 2197 } 2198 2199 static void lan8814_ptp_tx_ts_get(struct phy_device *phydev, 2200 u32 *seconds, u32 *nano_seconds, u16 *seq_id) 2201 { 2202 *seconds = lanphy_read_page_reg(phydev, 5, PTP_TX_EGRESS_SEC_HI); 2203 *seconds = *seconds << 16 | 2204 lanphy_read_page_reg(phydev, 5, PTP_TX_EGRESS_SEC_LO); 2205 2206 *nano_seconds = lanphy_read_page_reg(phydev, 5, PTP_TX_EGRESS_NS_HI); 2207 *nano_seconds = ((*nano_seconds & 0x3fff) << 16) | 2208 lanphy_read_page_reg(phydev, 5, PTP_TX_EGRESS_NS_LO); 2209 2210 *seq_id = lanphy_read_page_reg(phydev, 5, PTP_TX_MSG_HEADER2); 2211 } 2212 2213 static int lan8814_ts_info(struct mii_timestamper *mii_ts, struct ethtool_ts_info *info) 2214 { 2215 struct kszphy_ptp_priv *ptp_priv = container_of(mii_ts, struct kszphy_ptp_priv, mii_ts); 2216 struct phy_device *phydev = ptp_priv->phydev; 2217 struct lan8814_shared_priv *shared = phydev->shared->priv; 2218 2219 info->so_timestamping = SOF_TIMESTAMPING_TX_HARDWARE | 2220 SOF_TIMESTAMPING_RX_HARDWARE | 2221 SOF_TIMESTAMPING_RAW_HARDWARE; 2222 2223 info->phc_index = ptp_clock_index(shared->ptp_clock); 2224 2225 info->tx_types = 2226 (1 << HWTSTAMP_TX_OFF) | 2227 (1 << HWTSTAMP_TX_ON) | 2228 (1 << HWTSTAMP_TX_ONESTEP_SYNC); 2229 2230 info->rx_filters = 2231 (1 << HWTSTAMP_FILTER_NONE) | 2232 (1 << HWTSTAMP_FILTER_PTP_V1_L4_EVENT) | 2233 (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) | 2234 (1 << HWTSTAMP_FILTER_PTP_V2_L2_EVENT) | 2235 (1 << HWTSTAMP_FILTER_PTP_V2_EVENT); 2236 2237 return 0; 2238 } 2239 2240 static void lan8814_flush_fifo(struct phy_device *phydev, bool egress) 2241 { 2242 int i; 2243 2244 for (i = 0; i < FIFO_SIZE; ++i) 2245 lanphy_read_page_reg(phydev, 5, 2246 egress ? PTP_TX_MSG_HEADER2 : PTP_RX_MSG_HEADER2); 2247 2248 /* Read to clear overflow status bit */ 2249 lanphy_read_page_reg(phydev, 5, PTP_TSU_INT_STS); 2250 } 2251 2252 static int lan8814_hwtstamp(struct mii_timestamper *mii_ts, struct ifreq *ifr) 2253 { 2254 struct kszphy_ptp_priv *ptp_priv = 2255 container_of(mii_ts, struct kszphy_ptp_priv, mii_ts); 2256 struct phy_device *phydev = ptp_priv->phydev; 2257 struct lan8814_shared_priv *shared = phydev->shared->priv; 2258 struct lan8814_ptp_rx_ts *rx_ts, *tmp; 2259 struct hwtstamp_config config; 2260 int txcfg = 0, rxcfg = 0; 2261 int pkt_ts_enable; 2262 2263 if (copy_from_user(&config, ifr->ifr_data, sizeof(config))) 2264 return -EFAULT; 2265 2266 ptp_priv->hwts_tx_type = config.tx_type; 2267 ptp_priv->rx_filter = config.rx_filter; 2268 2269 switch (config.rx_filter) { 2270 case HWTSTAMP_FILTER_NONE: 2271 ptp_priv->layer = 0; 2272 ptp_priv->version = 0; 2273 break; 2274 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT: 2275 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC: 2276 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ: 2277 ptp_priv->layer = PTP_CLASS_L4; 2278 ptp_priv->version = PTP_CLASS_V2; 2279 break; 2280 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT: 2281 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC: 2282 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ: 2283 ptp_priv->layer = PTP_CLASS_L2; 2284 ptp_priv->version = PTP_CLASS_V2; 2285 break; 2286 case HWTSTAMP_FILTER_PTP_V2_EVENT: 2287 case HWTSTAMP_FILTER_PTP_V2_SYNC: 2288 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ: 2289 ptp_priv->layer = PTP_CLASS_L4 | PTP_CLASS_L2; 2290 ptp_priv->version = PTP_CLASS_V2; 2291 break; 2292 default: 2293 return -ERANGE; 2294 } 2295 2296 if (ptp_priv->layer & PTP_CLASS_L2) { 2297 rxcfg = PTP_RX_PARSE_CONFIG_LAYER2_EN_; 2298 txcfg = PTP_TX_PARSE_CONFIG_LAYER2_EN_; 2299 } else if (ptp_priv->layer & PTP_CLASS_L4) { 2300 rxcfg |= PTP_RX_PARSE_CONFIG_IPV4_EN_ | PTP_RX_PARSE_CONFIG_IPV6_EN_; 2301 txcfg |= PTP_TX_PARSE_CONFIG_IPV4_EN_ | PTP_TX_PARSE_CONFIG_IPV6_EN_; 2302 } 2303 lanphy_write_page_reg(ptp_priv->phydev, 5, PTP_RX_PARSE_CONFIG, rxcfg); 2304 lanphy_write_page_reg(ptp_priv->phydev, 5, PTP_TX_PARSE_CONFIG, txcfg); 2305 2306 pkt_ts_enable = PTP_TIMESTAMP_EN_SYNC_ | PTP_TIMESTAMP_EN_DREQ_ | 2307 PTP_TIMESTAMP_EN_PDREQ_ | PTP_TIMESTAMP_EN_PDRES_; 2308 lanphy_write_page_reg(ptp_priv->phydev, 5, PTP_RX_TIMESTAMP_EN, pkt_ts_enable); 2309 lanphy_write_page_reg(ptp_priv->phydev, 5, PTP_TX_TIMESTAMP_EN, pkt_ts_enable); 2310 2311 if (ptp_priv->hwts_tx_type == HWTSTAMP_TX_ONESTEP_SYNC) 2312 lanphy_write_page_reg(ptp_priv->phydev, 5, PTP_TX_MOD, 2313 PTP_TX_MOD_TX_PTP_SYNC_TS_INSERT_); 2314 2315 if (config.rx_filter != HWTSTAMP_FILTER_NONE) 2316 lan8814_config_ts_intr(ptp_priv->phydev, true); 2317 else 2318 lan8814_config_ts_intr(ptp_priv->phydev, false); 2319 2320 mutex_lock(&shared->shared_lock); 2321 if (config.rx_filter != HWTSTAMP_FILTER_NONE) 2322 shared->ref++; 2323 else 2324 shared->ref--; 2325 2326 if (shared->ref) 2327 lanphy_write_page_reg(ptp_priv->phydev, 4, PTP_CMD_CTL, 2328 PTP_CMD_CTL_PTP_ENABLE_); 2329 else 2330 lanphy_write_page_reg(ptp_priv->phydev, 4, PTP_CMD_CTL, 2331 PTP_CMD_CTL_PTP_DISABLE_); 2332 mutex_unlock(&shared->shared_lock); 2333 2334 /* In case of multiple starts and stops, these needs to be cleared */ 2335 list_for_each_entry_safe(rx_ts, tmp, &ptp_priv->rx_ts_list, list) { 2336 list_del(&rx_ts->list); 2337 kfree(rx_ts); 2338 } 2339 skb_queue_purge(&ptp_priv->rx_queue); 2340 skb_queue_purge(&ptp_priv->tx_queue); 2341 2342 lan8814_flush_fifo(ptp_priv->phydev, false); 2343 lan8814_flush_fifo(ptp_priv->phydev, true); 2344 2345 return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ? -EFAULT : 0; 2346 } 2347 2348 static void lan8814_txtstamp(struct mii_timestamper *mii_ts, 2349 struct sk_buff *skb, int type) 2350 { 2351 struct kszphy_ptp_priv *ptp_priv = container_of(mii_ts, struct kszphy_ptp_priv, mii_ts); 2352 2353 switch (ptp_priv->hwts_tx_type) { 2354 case HWTSTAMP_TX_ONESTEP_SYNC: 2355 if (ptp_msg_is_sync(skb, type)) { 2356 kfree_skb(skb); 2357 return; 2358 } 2359 fallthrough; 2360 case HWTSTAMP_TX_ON: 2361 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS; 2362 skb_queue_tail(&ptp_priv->tx_queue, skb); 2363 break; 2364 case HWTSTAMP_TX_OFF: 2365 default: 2366 kfree_skb(skb); 2367 break; 2368 } 2369 } 2370 2371 static void lan8814_get_sig_rx(struct sk_buff *skb, u16 *sig) 2372 { 2373 struct ptp_header *ptp_header; 2374 u32 type; 2375 2376 skb_push(skb, ETH_HLEN); 2377 type = ptp_classify_raw(skb); 2378 ptp_header = ptp_parse_header(skb, type); 2379 skb_pull_inline(skb, ETH_HLEN); 2380 2381 *sig = (__force u16)(ntohs(ptp_header->sequence_id)); 2382 } 2383 2384 static bool lan8814_match_rx_ts(struct kszphy_ptp_priv *ptp_priv, 2385 struct sk_buff *skb) 2386 { 2387 struct skb_shared_hwtstamps *shhwtstamps; 2388 struct lan8814_ptp_rx_ts *rx_ts, *tmp; 2389 unsigned long flags; 2390 bool ret = false; 2391 u16 skb_sig; 2392 2393 lan8814_get_sig_rx(skb, &skb_sig); 2394 2395 /* Iterate over all RX timestamps and match it with the received skbs */ 2396 spin_lock_irqsave(&ptp_priv->rx_ts_lock, flags); 2397 list_for_each_entry_safe(rx_ts, tmp, &ptp_priv->rx_ts_list, list) { 2398 /* Check if we found the signature we were looking for. */ 2399 if (memcmp(&skb_sig, &rx_ts->seq_id, sizeof(rx_ts->seq_id))) 2400 continue; 2401 2402 shhwtstamps = skb_hwtstamps(skb); 2403 memset(shhwtstamps, 0, sizeof(*shhwtstamps)); 2404 shhwtstamps->hwtstamp = ktime_set(rx_ts->seconds, 2405 rx_ts->nsec); 2406 list_del(&rx_ts->list); 2407 kfree(rx_ts); 2408 2409 ret = true; 2410 break; 2411 } 2412 spin_unlock_irqrestore(&ptp_priv->rx_ts_lock, flags); 2413 2414 if (ret) 2415 netif_rx(skb); 2416 return ret; 2417 } 2418 2419 static bool lan8814_rxtstamp(struct mii_timestamper *mii_ts, struct sk_buff *skb, int type) 2420 { 2421 struct kszphy_ptp_priv *ptp_priv = 2422 container_of(mii_ts, struct kszphy_ptp_priv, mii_ts); 2423 2424 if (ptp_priv->rx_filter == HWTSTAMP_FILTER_NONE || 2425 type == PTP_CLASS_NONE) 2426 return false; 2427 2428 if ((type & ptp_priv->version) == 0 || (type & ptp_priv->layer) == 0) 2429 return false; 2430 2431 /* If we failed to match then add it to the queue for when the timestamp 2432 * will come 2433 */ 2434 if (!lan8814_match_rx_ts(ptp_priv, skb)) 2435 skb_queue_tail(&ptp_priv->rx_queue, skb); 2436 2437 return true; 2438 } 2439 2440 static void lan8814_ptp_clock_set(struct phy_device *phydev, 2441 u32 seconds, u32 nano_seconds) 2442 { 2443 u32 sec_low, sec_high, nsec_low, nsec_high; 2444 2445 sec_low = seconds & 0xffff; 2446 sec_high = (seconds >> 16) & 0xffff; 2447 nsec_low = nano_seconds & 0xffff; 2448 nsec_high = (nano_seconds >> 16) & 0x3fff; 2449 2450 lanphy_write_page_reg(phydev, 4, PTP_CLOCK_SET_SEC_LO, sec_low); 2451 lanphy_write_page_reg(phydev, 4, PTP_CLOCK_SET_SEC_MID, sec_high); 2452 lanphy_write_page_reg(phydev, 4, PTP_CLOCK_SET_NS_LO, nsec_low); 2453 lanphy_write_page_reg(phydev, 4, PTP_CLOCK_SET_NS_HI, nsec_high); 2454 2455 lanphy_write_page_reg(phydev, 4, PTP_CMD_CTL, PTP_CMD_CTL_PTP_CLOCK_LOAD_); 2456 } 2457 2458 static void lan8814_ptp_clock_get(struct phy_device *phydev, 2459 u32 *seconds, u32 *nano_seconds) 2460 { 2461 lanphy_write_page_reg(phydev, 4, PTP_CMD_CTL, PTP_CMD_CTL_PTP_CLOCK_READ_); 2462 2463 *seconds = lanphy_read_page_reg(phydev, 4, PTP_CLOCK_READ_SEC_MID); 2464 *seconds = (*seconds << 16) | 2465 lanphy_read_page_reg(phydev, 4, PTP_CLOCK_READ_SEC_LO); 2466 2467 *nano_seconds = lanphy_read_page_reg(phydev, 4, PTP_CLOCK_READ_NS_HI); 2468 *nano_seconds = ((*nano_seconds & 0x3fff) << 16) | 2469 lanphy_read_page_reg(phydev, 4, PTP_CLOCK_READ_NS_LO); 2470 } 2471 2472 static int lan8814_ptpci_gettime64(struct ptp_clock_info *ptpci, 2473 struct timespec64 *ts) 2474 { 2475 struct lan8814_shared_priv *shared = container_of(ptpci, struct lan8814_shared_priv, 2476 ptp_clock_info); 2477 struct phy_device *phydev = shared->phydev; 2478 u32 nano_seconds; 2479 u32 seconds; 2480 2481 mutex_lock(&shared->shared_lock); 2482 lan8814_ptp_clock_get(phydev, &seconds, &nano_seconds); 2483 mutex_unlock(&shared->shared_lock); 2484 ts->tv_sec = seconds; 2485 ts->tv_nsec = nano_seconds; 2486 2487 return 0; 2488 } 2489 2490 static int lan8814_ptpci_settime64(struct ptp_clock_info *ptpci, 2491 const struct timespec64 *ts) 2492 { 2493 struct lan8814_shared_priv *shared = container_of(ptpci, struct lan8814_shared_priv, 2494 ptp_clock_info); 2495 struct phy_device *phydev = shared->phydev; 2496 2497 mutex_lock(&shared->shared_lock); 2498 lan8814_ptp_clock_set(phydev, ts->tv_sec, ts->tv_nsec); 2499 mutex_unlock(&shared->shared_lock); 2500 2501 return 0; 2502 } 2503 2504 static void lan8814_ptp_clock_step(struct phy_device *phydev, 2505 s64 time_step_ns) 2506 { 2507 u32 nano_seconds_step; 2508 u64 abs_time_step_ns; 2509 u32 unsigned_seconds; 2510 u32 nano_seconds; 2511 u32 remainder; 2512 s32 seconds; 2513 2514 if (time_step_ns > 15000000000LL) { 2515 /* convert to clock set */ 2516 lan8814_ptp_clock_get(phydev, &unsigned_seconds, &nano_seconds); 2517 unsigned_seconds += div_u64_rem(time_step_ns, 1000000000LL, 2518 &remainder); 2519 nano_seconds += remainder; 2520 if (nano_seconds >= 1000000000) { 2521 unsigned_seconds++; 2522 nano_seconds -= 1000000000; 2523 } 2524 lan8814_ptp_clock_set(phydev, unsigned_seconds, nano_seconds); 2525 return; 2526 } else if (time_step_ns < -15000000000LL) { 2527 /* convert to clock set */ 2528 time_step_ns = -time_step_ns; 2529 2530 lan8814_ptp_clock_get(phydev, &unsigned_seconds, &nano_seconds); 2531 unsigned_seconds -= div_u64_rem(time_step_ns, 1000000000LL, 2532 &remainder); 2533 nano_seconds_step = remainder; 2534 if (nano_seconds < nano_seconds_step) { 2535 unsigned_seconds--; 2536 nano_seconds += 1000000000; 2537 } 2538 nano_seconds -= nano_seconds_step; 2539 lan8814_ptp_clock_set(phydev, unsigned_seconds, 2540 nano_seconds); 2541 return; 2542 } 2543 2544 /* do clock step */ 2545 if (time_step_ns >= 0) { 2546 abs_time_step_ns = (u64)time_step_ns; 2547 seconds = (s32)div_u64_rem(abs_time_step_ns, 1000000000, 2548 &remainder); 2549 nano_seconds = remainder; 2550 } else { 2551 abs_time_step_ns = (u64)(-time_step_ns); 2552 seconds = -((s32)div_u64_rem(abs_time_step_ns, 1000000000, 2553 &remainder)); 2554 nano_seconds = remainder; 2555 if (nano_seconds > 0) { 2556 /* subtracting nano seconds is not allowed 2557 * convert to subtracting from seconds, 2558 * and adding to nanoseconds 2559 */ 2560 seconds--; 2561 nano_seconds = (1000000000 - nano_seconds); 2562 } 2563 } 2564 2565 if (nano_seconds > 0) { 2566 /* add 8 ns to cover the likely normal increment */ 2567 nano_seconds += 8; 2568 } 2569 2570 if (nano_seconds >= 1000000000) { 2571 /* carry into seconds */ 2572 seconds++; 2573 nano_seconds -= 1000000000; 2574 } 2575 2576 while (seconds) { 2577 if (seconds > 0) { 2578 u32 adjustment_value = (u32)seconds; 2579 u16 adjustment_value_lo, adjustment_value_hi; 2580 2581 if (adjustment_value > 0xF) 2582 adjustment_value = 0xF; 2583 2584 adjustment_value_lo = adjustment_value & 0xffff; 2585 adjustment_value_hi = (adjustment_value >> 16) & 0x3fff; 2586 2587 lanphy_write_page_reg(phydev, 4, PTP_LTC_STEP_ADJ_LO, 2588 adjustment_value_lo); 2589 lanphy_write_page_reg(phydev, 4, PTP_LTC_STEP_ADJ_HI, 2590 PTP_LTC_STEP_ADJ_DIR_ | 2591 adjustment_value_hi); 2592 seconds -= ((s32)adjustment_value); 2593 } else { 2594 u32 adjustment_value = (u32)(-seconds); 2595 u16 adjustment_value_lo, adjustment_value_hi; 2596 2597 if (adjustment_value > 0xF) 2598 adjustment_value = 0xF; 2599 2600 adjustment_value_lo = adjustment_value & 0xffff; 2601 adjustment_value_hi = (adjustment_value >> 16) & 0x3fff; 2602 2603 lanphy_write_page_reg(phydev, 4, PTP_LTC_STEP_ADJ_LO, 2604 adjustment_value_lo); 2605 lanphy_write_page_reg(phydev, 4, PTP_LTC_STEP_ADJ_HI, 2606 adjustment_value_hi); 2607 seconds += ((s32)adjustment_value); 2608 } 2609 lanphy_write_page_reg(phydev, 4, PTP_CMD_CTL, 2610 PTP_CMD_CTL_PTP_LTC_STEP_SEC_); 2611 } 2612 if (nano_seconds) { 2613 u16 nano_seconds_lo; 2614 u16 nano_seconds_hi; 2615 2616 nano_seconds_lo = nano_seconds & 0xffff; 2617 nano_seconds_hi = (nano_seconds >> 16) & 0x3fff; 2618 2619 lanphy_write_page_reg(phydev, 4, PTP_LTC_STEP_ADJ_LO, 2620 nano_seconds_lo); 2621 lanphy_write_page_reg(phydev, 4, PTP_LTC_STEP_ADJ_HI, 2622 PTP_LTC_STEP_ADJ_DIR_ | 2623 nano_seconds_hi); 2624 lanphy_write_page_reg(phydev, 4, PTP_CMD_CTL, 2625 PTP_CMD_CTL_PTP_LTC_STEP_NSEC_); 2626 } 2627 } 2628 2629 static int lan8814_ptpci_adjtime(struct ptp_clock_info *ptpci, s64 delta) 2630 { 2631 struct lan8814_shared_priv *shared = container_of(ptpci, struct lan8814_shared_priv, 2632 ptp_clock_info); 2633 struct phy_device *phydev = shared->phydev; 2634 2635 mutex_lock(&shared->shared_lock); 2636 lan8814_ptp_clock_step(phydev, delta); 2637 mutex_unlock(&shared->shared_lock); 2638 2639 return 0; 2640 } 2641 2642 static int lan8814_ptpci_adjfine(struct ptp_clock_info *ptpci, long scaled_ppm) 2643 { 2644 struct lan8814_shared_priv *shared = container_of(ptpci, struct lan8814_shared_priv, 2645 ptp_clock_info); 2646 struct phy_device *phydev = shared->phydev; 2647 u16 kszphy_rate_adj_lo, kszphy_rate_adj_hi; 2648 bool positive = true; 2649 u32 kszphy_rate_adj; 2650 2651 if (scaled_ppm < 0) { 2652 scaled_ppm = -scaled_ppm; 2653 positive = false; 2654 } 2655 2656 kszphy_rate_adj = LAN8814_1PPM_FORMAT * (scaled_ppm >> 16); 2657 kszphy_rate_adj += (LAN8814_1PPM_FORMAT * (0xffff & scaled_ppm)) >> 16; 2658 2659 kszphy_rate_adj_lo = kszphy_rate_adj & 0xffff; 2660 kszphy_rate_adj_hi = (kszphy_rate_adj >> 16) & 0x3fff; 2661 2662 if (positive) 2663 kszphy_rate_adj_hi |= PTP_CLOCK_RATE_ADJ_DIR_; 2664 2665 mutex_lock(&shared->shared_lock); 2666 lanphy_write_page_reg(phydev, 4, PTP_CLOCK_RATE_ADJ_HI, kszphy_rate_adj_hi); 2667 lanphy_write_page_reg(phydev, 4, PTP_CLOCK_RATE_ADJ_LO, kszphy_rate_adj_lo); 2668 mutex_unlock(&shared->shared_lock); 2669 2670 return 0; 2671 } 2672 2673 static void lan8814_get_sig_tx(struct sk_buff *skb, u16 *sig) 2674 { 2675 struct ptp_header *ptp_header; 2676 u32 type; 2677 2678 type = ptp_classify_raw(skb); 2679 ptp_header = ptp_parse_header(skb, type); 2680 2681 *sig = (__force u16)(ntohs(ptp_header->sequence_id)); 2682 } 2683 2684 static void lan8814_dequeue_tx_skb(struct kszphy_ptp_priv *ptp_priv) 2685 { 2686 struct phy_device *phydev = ptp_priv->phydev; 2687 struct skb_shared_hwtstamps shhwtstamps; 2688 struct sk_buff *skb, *skb_tmp; 2689 unsigned long flags; 2690 u32 seconds, nsec; 2691 bool ret = false; 2692 u16 skb_sig; 2693 u16 seq_id; 2694 2695 lan8814_ptp_tx_ts_get(phydev, &seconds, &nsec, &seq_id); 2696 2697 spin_lock_irqsave(&ptp_priv->tx_queue.lock, flags); 2698 skb_queue_walk_safe(&ptp_priv->tx_queue, skb, skb_tmp) { 2699 lan8814_get_sig_tx(skb, &skb_sig); 2700 2701 if (memcmp(&skb_sig, &seq_id, sizeof(seq_id))) 2702 continue; 2703 2704 __skb_unlink(skb, &ptp_priv->tx_queue); 2705 ret = true; 2706 break; 2707 } 2708 spin_unlock_irqrestore(&ptp_priv->tx_queue.lock, flags); 2709 2710 if (ret) { 2711 memset(&shhwtstamps, 0, sizeof(shhwtstamps)); 2712 shhwtstamps.hwtstamp = ktime_set(seconds, nsec); 2713 skb_complete_tx_timestamp(skb, &shhwtstamps); 2714 } 2715 } 2716 2717 static void lan8814_get_tx_ts(struct kszphy_ptp_priv *ptp_priv) 2718 { 2719 struct phy_device *phydev = ptp_priv->phydev; 2720 u32 reg; 2721 2722 do { 2723 lan8814_dequeue_tx_skb(ptp_priv); 2724 2725 /* If other timestamps are available in the FIFO, 2726 * process them. 2727 */ 2728 reg = lanphy_read_page_reg(phydev, 5, PTP_CAP_INFO); 2729 } while (PTP_CAP_INFO_TX_TS_CNT_GET_(reg) > 0); 2730 } 2731 2732 static bool lan8814_match_skb(struct kszphy_ptp_priv *ptp_priv, 2733 struct lan8814_ptp_rx_ts *rx_ts) 2734 { 2735 struct skb_shared_hwtstamps *shhwtstamps; 2736 struct sk_buff *skb, *skb_tmp; 2737 unsigned long flags; 2738 bool ret = false; 2739 u16 skb_sig; 2740 2741 spin_lock_irqsave(&ptp_priv->rx_queue.lock, flags); 2742 skb_queue_walk_safe(&ptp_priv->rx_queue, skb, skb_tmp) { 2743 lan8814_get_sig_rx(skb, &skb_sig); 2744 2745 if (memcmp(&skb_sig, &rx_ts->seq_id, sizeof(rx_ts->seq_id))) 2746 continue; 2747 2748 __skb_unlink(skb, &ptp_priv->rx_queue); 2749 2750 ret = true; 2751 break; 2752 } 2753 spin_unlock_irqrestore(&ptp_priv->rx_queue.lock, flags); 2754 2755 if (ret) { 2756 shhwtstamps = skb_hwtstamps(skb); 2757 memset(shhwtstamps, 0, sizeof(*shhwtstamps)); 2758 shhwtstamps->hwtstamp = ktime_set(rx_ts->seconds, rx_ts->nsec); 2759 netif_rx(skb); 2760 } 2761 2762 return ret; 2763 } 2764 2765 static void lan8814_get_rx_ts(struct kszphy_ptp_priv *ptp_priv) 2766 { 2767 struct phy_device *phydev = ptp_priv->phydev; 2768 struct lan8814_ptp_rx_ts *rx_ts; 2769 unsigned long flags; 2770 u32 reg; 2771 2772 do { 2773 rx_ts = kzalloc(sizeof(*rx_ts), GFP_KERNEL); 2774 if (!rx_ts) 2775 return; 2776 2777 lan8814_ptp_rx_ts_get(phydev, &rx_ts->seconds, &rx_ts->nsec, 2778 &rx_ts->seq_id); 2779 2780 /* If we failed to match the skb add it to the queue for when 2781 * the frame will come 2782 */ 2783 if (!lan8814_match_skb(ptp_priv, rx_ts)) { 2784 spin_lock_irqsave(&ptp_priv->rx_ts_lock, flags); 2785 list_add(&rx_ts->list, &ptp_priv->rx_ts_list); 2786 spin_unlock_irqrestore(&ptp_priv->rx_ts_lock, flags); 2787 } else { 2788 kfree(rx_ts); 2789 } 2790 2791 /* If other timestamps are available in the FIFO, 2792 * process them. 2793 */ 2794 reg = lanphy_read_page_reg(phydev, 5, PTP_CAP_INFO); 2795 } while (PTP_CAP_INFO_RX_TS_CNT_GET_(reg) > 0); 2796 } 2797 2798 static void lan8814_handle_ptp_interrupt(struct phy_device *phydev, u16 status) 2799 { 2800 struct kszphy_priv *priv = phydev->priv; 2801 struct kszphy_ptp_priv *ptp_priv = &priv->ptp_priv; 2802 2803 if (status & PTP_TSU_INT_STS_PTP_TX_TS_EN_) 2804 lan8814_get_tx_ts(ptp_priv); 2805 2806 if (status & PTP_TSU_INT_STS_PTP_RX_TS_EN_) 2807 lan8814_get_rx_ts(ptp_priv); 2808 2809 if (status & PTP_TSU_INT_STS_PTP_TX_TS_OVRFL_INT_) { 2810 lan8814_flush_fifo(phydev, true); 2811 skb_queue_purge(&ptp_priv->tx_queue); 2812 } 2813 2814 if (status & PTP_TSU_INT_STS_PTP_RX_TS_OVRFL_INT_) { 2815 lan8814_flush_fifo(phydev, false); 2816 skb_queue_purge(&ptp_priv->rx_queue); 2817 } 2818 } 2819 2820 static int lan8804_config_init(struct phy_device *phydev) 2821 { 2822 int val; 2823 2824 /* MDI-X setting for swap A,B transmit */ 2825 val = lanphy_read_page_reg(phydev, 2, LAN8804_ALIGN_SWAP); 2826 val &= ~LAN8804_ALIGN_TX_A_B_SWAP_MASK; 2827 val |= LAN8804_ALIGN_TX_A_B_SWAP; 2828 lanphy_write_page_reg(phydev, 2, LAN8804_ALIGN_SWAP, val); 2829 2830 /* Make sure that the PHY will not stop generating the clock when the 2831 * link partner goes down 2832 */ 2833 lanphy_write_page_reg(phydev, 31, LAN8814_CLOCK_MANAGEMENT, 0x27e); 2834 lanphy_read_page_reg(phydev, 1, LAN8814_LINK_QUALITY); 2835 2836 return 0; 2837 } 2838 2839 static irqreturn_t lan8804_handle_interrupt(struct phy_device *phydev) 2840 { 2841 int status; 2842 2843 status = phy_read(phydev, LAN8814_INTS); 2844 if (status < 0) { 2845 phy_error(phydev); 2846 return IRQ_NONE; 2847 } 2848 2849 if (status > 0) 2850 phy_trigger_machine(phydev); 2851 2852 return IRQ_HANDLED; 2853 } 2854 2855 #define LAN8804_OUTPUT_CONTROL 25 2856 #define LAN8804_OUTPUT_CONTROL_INTR_BUFFER BIT(14) 2857 #define LAN8804_CONTROL 31 2858 #define LAN8804_CONTROL_INTR_POLARITY BIT(14) 2859 2860 static int lan8804_config_intr(struct phy_device *phydev) 2861 { 2862 int err; 2863 2864 /* This is an internal PHY of lan966x and is not possible to change the 2865 * polarity on the GIC found in lan966x, therefore change the polarity 2866 * of the interrupt in the PHY from being active low instead of active 2867 * high. 2868 */ 2869 phy_write(phydev, LAN8804_CONTROL, LAN8804_CONTROL_INTR_POLARITY); 2870 2871 /* By default interrupt buffer is open-drain in which case the interrupt 2872 * can be active only low. Therefore change the interrupt buffer to be 2873 * push-pull to be able to change interrupt polarity 2874 */ 2875 phy_write(phydev, LAN8804_OUTPUT_CONTROL, 2876 LAN8804_OUTPUT_CONTROL_INTR_BUFFER); 2877 2878 if (phydev->interrupts == PHY_INTERRUPT_ENABLED) { 2879 err = phy_read(phydev, LAN8814_INTS); 2880 if (err < 0) 2881 return err; 2882 2883 err = phy_write(phydev, LAN8814_INTC, LAN8814_INT_LINK); 2884 if (err) 2885 return err; 2886 } else { 2887 err = phy_write(phydev, LAN8814_INTC, 0); 2888 if (err) 2889 return err; 2890 2891 err = phy_read(phydev, LAN8814_INTS); 2892 if (err < 0) 2893 return err; 2894 } 2895 2896 return 0; 2897 } 2898 2899 static irqreturn_t lan8814_handle_interrupt(struct phy_device *phydev) 2900 { 2901 int ret = IRQ_NONE; 2902 int irq_status; 2903 2904 irq_status = phy_read(phydev, LAN8814_INTS); 2905 if (irq_status < 0) { 2906 phy_error(phydev); 2907 return IRQ_NONE; 2908 } 2909 2910 if (irq_status & LAN8814_INT_LINK) { 2911 phy_trigger_machine(phydev); 2912 ret = IRQ_HANDLED; 2913 } 2914 2915 while (true) { 2916 irq_status = lanphy_read_page_reg(phydev, 5, PTP_TSU_INT_STS); 2917 if (!irq_status) 2918 break; 2919 2920 lan8814_handle_ptp_interrupt(phydev, irq_status); 2921 ret = IRQ_HANDLED; 2922 } 2923 2924 return ret; 2925 } 2926 2927 static int lan8814_ack_interrupt(struct phy_device *phydev) 2928 { 2929 /* bit[12..0] int status, which is a read and clear register. */ 2930 int rc; 2931 2932 rc = phy_read(phydev, LAN8814_INTS); 2933 2934 return (rc < 0) ? rc : 0; 2935 } 2936 2937 static int lan8814_config_intr(struct phy_device *phydev) 2938 { 2939 int err; 2940 2941 lanphy_write_page_reg(phydev, 4, LAN8814_INTR_CTRL_REG, 2942 LAN8814_INTR_CTRL_REG_POLARITY | 2943 LAN8814_INTR_CTRL_REG_INTR_ENABLE); 2944 2945 /* enable / disable interrupts */ 2946 if (phydev->interrupts == PHY_INTERRUPT_ENABLED) { 2947 err = lan8814_ack_interrupt(phydev); 2948 if (err) 2949 return err; 2950 2951 err = phy_write(phydev, LAN8814_INTC, LAN8814_INT_LINK); 2952 } else { 2953 err = phy_write(phydev, LAN8814_INTC, 0); 2954 if (err) 2955 return err; 2956 2957 err = lan8814_ack_interrupt(phydev); 2958 } 2959 2960 return err; 2961 } 2962 2963 static void lan8814_ptp_init(struct phy_device *phydev) 2964 { 2965 struct kszphy_priv *priv = phydev->priv; 2966 struct kszphy_ptp_priv *ptp_priv = &priv->ptp_priv; 2967 u32 temp; 2968 2969 if (!IS_ENABLED(CONFIG_PTP_1588_CLOCK) || 2970 !IS_ENABLED(CONFIG_NETWORK_PHY_TIMESTAMPING)) 2971 return; 2972 2973 lanphy_write_page_reg(phydev, 5, TSU_HARD_RESET, TSU_HARD_RESET_); 2974 2975 temp = lanphy_read_page_reg(phydev, 5, PTP_TX_MOD); 2976 temp |= PTP_TX_MOD_BAD_UDPV4_CHKSUM_FORCE_FCS_DIS_; 2977 lanphy_write_page_reg(phydev, 5, PTP_TX_MOD, temp); 2978 2979 temp = lanphy_read_page_reg(phydev, 5, PTP_RX_MOD); 2980 temp |= PTP_RX_MOD_BAD_UDPV4_CHKSUM_FORCE_FCS_DIS_; 2981 lanphy_write_page_reg(phydev, 5, PTP_RX_MOD, temp); 2982 2983 lanphy_write_page_reg(phydev, 5, PTP_RX_PARSE_CONFIG, 0); 2984 lanphy_write_page_reg(phydev, 5, PTP_TX_PARSE_CONFIG, 0); 2985 2986 /* Removing default registers configs related to L2 and IP */ 2987 lanphy_write_page_reg(phydev, 5, PTP_TX_PARSE_L2_ADDR_EN, 0); 2988 lanphy_write_page_reg(phydev, 5, PTP_RX_PARSE_L2_ADDR_EN, 0); 2989 lanphy_write_page_reg(phydev, 5, PTP_TX_PARSE_IP_ADDR_EN, 0); 2990 lanphy_write_page_reg(phydev, 5, PTP_RX_PARSE_IP_ADDR_EN, 0); 2991 2992 skb_queue_head_init(&ptp_priv->tx_queue); 2993 skb_queue_head_init(&ptp_priv->rx_queue); 2994 INIT_LIST_HEAD(&ptp_priv->rx_ts_list); 2995 spin_lock_init(&ptp_priv->rx_ts_lock); 2996 2997 ptp_priv->phydev = phydev; 2998 2999 ptp_priv->mii_ts.rxtstamp = lan8814_rxtstamp; 3000 ptp_priv->mii_ts.txtstamp = lan8814_txtstamp; 3001 ptp_priv->mii_ts.hwtstamp = lan8814_hwtstamp; 3002 ptp_priv->mii_ts.ts_info = lan8814_ts_info; 3003 3004 phydev->mii_ts = &ptp_priv->mii_ts; 3005 } 3006 3007 static int lan8814_ptp_probe_once(struct phy_device *phydev) 3008 { 3009 struct lan8814_shared_priv *shared = phydev->shared->priv; 3010 3011 /* Initialise shared lock for clock*/ 3012 mutex_init(&shared->shared_lock); 3013 3014 shared->ptp_clock_info.owner = THIS_MODULE; 3015 snprintf(shared->ptp_clock_info.name, 30, "%s", phydev->drv->name); 3016 shared->ptp_clock_info.max_adj = 31249999; 3017 shared->ptp_clock_info.n_alarm = 0; 3018 shared->ptp_clock_info.n_ext_ts = 0; 3019 shared->ptp_clock_info.n_pins = 0; 3020 shared->ptp_clock_info.pps = 0; 3021 shared->ptp_clock_info.pin_config = NULL; 3022 shared->ptp_clock_info.adjfine = lan8814_ptpci_adjfine; 3023 shared->ptp_clock_info.adjtime = lan8814_ptpci_adjtime; 3024 shared->ptp_clock_info.gettime64 = lan8814_ptpci_gettime64; 3025 shared->ptp_clock_info.settime64 = lan8814_ptpci_settime64; 3026 shared->ptp_clock_info.getcrosststamp = NULL; 3027 3028 shared->ptp_clock = ptp_clock_register(&shared->ptp_clock_info, 3029 &phydev->mdio.dev); 3030 if (IS_ERR(shared->ptp_clock)) { 3031 phydev_err(phydev, "ptp_clock_register failed %lu\n", 3032 PTR_ERR(shared->ptp_clock)); 3033 return -EINVAL; 3034 } 3035 3036 /* Check if PHC support is missing at the configuration level */ 3037 if (!shared->ptp_clock) 3038 return 0; 3039 3040 phydev_dbg(phydev, "successfully registered ptp clock\n"); 3041 3042 shared->phydev = phydev; 3043 3044 /* The EP.4 is shared between all the PHYs in the package and also it 3045 * can be accessed by any of the PHYs 3046 */ 3047 lanphy_write_page_reg(phydev, 4, LTC_HARD_RESET, LTC_HARD_RESET_); 3048 lanphy_write_page_reg(phydev, 4, PTP_OPERATING_MODE, 3049 PTP_OPERATING_MODE_STANDALONE_); 3050 3051 return 0; 3052 } 3053 3054 static void lan8814_setup_led(struct phy_device *phydev, int val) 3055 { 3056 int temp; 3057 3058 temp = lanphy_read_page_reg(phydev, 5, LAN8814_LED_CTRL_1); 3059 3060 if (val) 3061 temp |= LAN8814_LED_CTRL_1_KSZ9031_LED_MODE_; 3062 else 3063 temp &= ~LAN8814_LED_CTRL_1_KSZ9031_LED_MODE_; 3064 3065 lanphy_write_page_reg(phydev, 5, LAN8814_LED_CTRL_1, temp); 3066 } 3067 3068 static int lan8814_config_init(struct phy_device *phydev) 3069 { 3070 struct kszphy_priv *lan8814 = phydev->priv; 3071 int val; 3072 3073 /* Reset the PHY */ 3074 val = lanphy_read_page_reg(phydev, 4, LAN8814_QSGMII_SOFT_RESET); 3075 val |= LAN8814_QSGMII_SOFT_RESET_BIT; 3076 lanphy_write_page_reg(phydev, 4, LAN8814_QSGMII_SOFT_RESET, val); 3077 3078 /* Disable ANEG with QSGMII PCS Host side */ 3079 val = lanphy_read_page_reg(phydev, 5, LAN8814_QSGMII_PCS1G_ANEG_CONFIG); 3080 val &= ~LAN8814_QSGMII_PCS1G_ANEG_CONFIG_ANEG_ENA; 3081 lanphy_write_page_reg(phydev, 5, LAN8814_QSGMII_PCS1G_ANEG_CONFIG, val); 3082 3083 /* MDI-X setting for swap A,B transmit */ 3084 val = lanphy_read_page_reg(phydev, 2, LAN8814_ALIGN_SWAP); 3085 val &= ~LAN8814_ALIGN_TX_A_B_SWAP_MASK; 3086 val |= LAN8814_ALIGN_TX_A_B_SWAP; 3087 lanphy_write_page_reg(phydev, 2, LAN8814_ALIGN_SWAP, val); 3088 3089 if (lan8814->led_mode >= 0) 3090 lan8814_setup_led(phydev, lan8814->led_mode); 3091 3092 return 0; 3093 } 3094 3095 /* It is expected that there will not be any 'lan8814_take_coma_mode' 3096 * function called in suspend. Because the GPIO line can be shared, so if one of 3097 * the phys goes back in coma mode, then all the other PHYs will go, which is 3098 * wrong. 3099 */ 3100 static int lan8814_release_coma_mode(struct phy_device *phydev) 3101 { 3102 struct gpio_desc *gpiod; 3103 3104 gpiod = devm_gpiod_get_optional(&phydev->mdio.dev, "coma-mode", 3105 GPIOD_OUT_HIGH_OPEN_DRAIN | 3106 GPIOD_FLAGS_BIT_NONEXCLUSIVE); 3107 if (IS_ERR(gpiod)) 3108 return PTR_ERR(gpiod); 3109 3110 gpiod_set_consumer_name(gpiod, "LAN8814 coma mode"); 3111 gpiod_set_value_cansleep(gpiod, 0); 3112 3113 return 0; 3114 } 3115 3116 static int lan8814_probe(struct phy_device *phydev) 3117 { 3118 const struct kszphy_type *type = phydev->drv->driver_data; 3119 struct kszphy_priv *priv; 3120 u16 addr; 3121 int err; 3122 3123 priv = devm_kzalloc(&phydev->mdio.dev, sizeof(*priv), GFP_KERNEL); 3124 if (!priv) 3125 return -ENOMEM; 3126 3127 phydev->priv = priv; 3128 3129 priv->type = type; 3130 3131 kszphy_parse_led_mode(phydev); 3132 3133 /* Strap-in value for PHY address, below register read gives starting 3134 * phy address value 3135 */ 3136 addr = lanphy_read_page_reg(phydev, 4, 0) & 0x1F; 3137 devm_phy_package_join(&phydev->mdio.dev, phydev, 3138 addr, sizeof(struct lan8814_shared_priv)); 3139 3140 if (phy_package_init_once(phydev)) { 3141 err = lan8814_release_coma_mode(phydev); 3142 if (err) 3143 return err; 3144 3145 err = lan8814_ptp_probe_once(phydev); 3146 if (err) 3147 return err; 3148 } 3149 3150 lan8814_ptp_init(phydev); 3151 3152 return 0; 3153 } 3154 3155 static struct phy_driver ksphy_driver[] = { 3156 { 3157 .phy_id = PHY_ID_KS8737, 3158 .phy_id_mask = MICREL_PHY_ID_MASK, 3159 .name = "Micrel KS8737", 3160 /* PHY_BASIC_FEATURES */ 3161 .driver_data = &ks8737_type, 3162 .probe = kszphy_probe, 3163 .config_init = kszphy_config_init, 3164 .config_intr = kszphy_config_intr, 3165 .handle_interrupt = kszphy_handle_interrupt, 3166 .suspend = kszphy_suspend, 3167 .resume = kszphy_resume, 3168 }, { 3169 .phy_id = PHY_ID_KSZ8021, 3170 .phy_id_mask = 0x00ffffff, 3171 .name = "Micrel KSZ8021 or KSZ8031", 3172 /* PHY_BASIC_FEATURES */ 3173 .driver_data = &ksz8021_type, 3174 .probe = kszphy_probe, 3175 .config_init = kszphy_config_init, 3176 .config_intr = kszphy_config_intr, 3177 .handle_interrupt = kszphy_handle_interrupt, 3178 .get_sset_count = kszphy_get_sset_count, 3179 .get_strings = kszphy_get_strings, 3180 .get_stats = kszphy_get_stats, 3181 .suspend = kszphy_suspend, 3182 .resume = kszphy_resume, 3183 }, { 3184 .phy_id = PHY_ID_KSZ8031, 3185 .phy_id_mask = 0x00ffffff, 3186 .name = "Micrel KSZ8031", 3187 /* PHY_BASIC_FEATURES */ 3188 .driver_data = &ksz8021_type, 3189 .probe = kszphy_probe, 3190 .config_init = kszphy_config_init, 3191 .config_intr = kszphy_config_intr, 3192 .handle_interrupt = kszphy_handle_interrupt, 3193 .get_sset_count = kszphy_get_sset_count, 3194 .get_strings = kszphy_get_strings, 3195 .get_stats = kszphy_get_stats, 3196 .suspend = kszphy_suspend, 3197 .resume = kszphy_resume, 3198 }, { 3199 .phy_id = PHY_ID_KSZ8041, 3200 .phy_id_mask = MICREL_PHY_ID_MASK, 3201 .name = "Micrel KSZ8041", 3202 /* PHY_BASIC_FEATURES */ 3203 .driver_data = &ksz8041_type, 3204 .probe = kszphy_probe, 3205 .config_init = ksz8041_config_init, 3206 .config_aneg = ksz8041_config_aneg, 3207 .config_intr = kszphy_config_intr, 3208 .handle_interrupt = kszphy_handle_interrupt, 3209 .get_sset_count = kszphy_get_sset_count, 3210 .get_strings = kszphy_get_strings, 3211 .get_stats = kszphy_get_stats, 3212 /* No suspend/resume callbacks because of errata DS80000700A, 3213 * receiver error following software power down. 3214 */ 3215 }, { 3216 .phy_id = PHY_ID_KSZ8041RNLI, 3217 .phy_id_mask = MICREL_PHY_ID_MASK, 3218 .name = "Micrel KSZ8041RNLI", 3219 /* PHY_BASIC_FEATURES */ 3220 .driver_data = &ksz8041_type, 3221 .probe = kszphy_probe, 3222 .config_init = kszphy_config_init, 3223 .config_intr = kszphy_config_intr, 3224 .handle_interrupt = kszphy_handle_interrupt, 3225 .get_sset_count = kszphy_get_sset_count, 3226 .get_strings = kszphy_get_strings, 3227 .get_stats = kszphy_get_stats, 3228 .suspend = kszphy_suspend, 3229 .resume = kszphy_resume, 3230 }, { 3231 .name = "Micrel KSZ8051", 3232 /* PHY_BASIC_FEATURES */ 3233 .driver_data = &ksz8051_type, 3234 .probe = kszphy_probe, 3235 .config_init = kszphy_config_init, 3236 .config_intr = kszphy_config_intr, 3237 .handle_interrupt = kszphy_handle_interrupt, 3238 .get_sset_count = kszphy_get_sset_count, 3239 .get_strings = kszphy_get_strings, 3240 .get_stats = kszphy_get_stats, 3241 .match_phy_device = ksz8051_match_phy_device, 3242 .suspend = kszphy_suspend, 3243 .resume = kszphy_resume, 3244 }, { 3245 .phy_id = PHY_ID_KSZ8001, 3246 .name = "Micrel KSZ8001 or KS8721", 3247 .phy_id_mask = 0x00fffffc, 3248 /* PHY_BASIC_FEATURES */ 3249 .driver_data = &ksz8041_type, 3250 .probe = kszphy_probe, 3251 .config_init = kszphy_config_init, 3252 .config_intr = kszphy_config_intr, 3253 .handle_interrupt = kszphy_handle_interrupt, 3254 .get_sset_count = kszphy_get_sset_count, 3255 .get_strings = kszphy_get_strings, 3256 .get_stats = kszphy_get_stats, 3257 .suspend = kszphy_suspend, 3258 .resume = kszphy_resume, 3259 }, { 3260 .phy_id = PHY_ID_KSZ8081, 3261 .name = "Micrel KSZ8081 or KSZ8091", 3262 .phy_id_mask = MICREL_PHY_ID_MASK, 3263 .flags = PHY_POLL_CABLE_TEST, 3264 /* PHY_BASIC_FEATURES */ 3265 .driver_data = &ksz8081_type, 3266 .probe = kszphy_probe, 3267 .config_init = ksz8081_config_init, 3268 .soft_reset = genphy_soft_reset, 3269 .config_aneg = ksz8081_config_aneg, 3270 .read_status = ksz8081_read_status, 3271 .config_intr = kszphy_config_intr, 3272 .handle_interrupt = kszphy_handle_interrupt, 3273 .get_sset_count = kszphy_get_sset_count, 3274 .get_strings = kszphy_get_strings, 3275 .get_stats = kszphy_get_stats, 3276 .suspend = kszphy_suspend, 3277 .resume = kszphy_resume, 3278 .cable_test_start = ksz886x_cable_test_start, 3279 .cable_test_get_status = ksz886x_cable_test_get_status, 3280 }, { 3281 .phy_id = PHY_ID_KSZ8061, 3282 .name = "Micrel KSZ8061", 3283 .phy_id_mask = MICREL_PHY_ID_MASK, 3284 /* PHY_BASIC_FEATURES */ 3285 .probe = kszphy_probe, 3286 .config_init = ksz8061_config_init, 3287 .config_intr = kszphy_config_intr, 3288 .handle_interrupt = kszphy_handle_interrupt, 3289 .suspend = kszphy_suspend, 3290 .resume = kszphy_resume, 3291 }, { 3292 .phy_id = PHY_ID_KSZ9021, 3293 .phy_id_mask = 0x000ffffe, 3294 .name = "Micrel KSZ9021 Gigabit PHY", 3295 /* PHY_GBIT_FEATURES */ 3296 .driver_data = &ksz9021_type, 3297 .probe = kszphy_probe, 3298 .get_features = ksz9031_get_features, 3299 .config_init = ksz9021_config_init, 3300 .config_intr = kszphy_config_intr, 3301 .handle_interrupt = kszphy_handle_interrupt, 3302 .get_sset_count = kszphy_get_sset_count, 3303 .get_strings = kszphy_get_strings, 3304 .get_stats = kszphy_get_stats, 3305 .suspend = kszphy_suspend, 3306 .resume = kszphy_resume, 3307 .read_mmd = genphy_read_mmd_unsupported, 3308 .write_mmd = genphy_write_mmd_unsupported, 3309 }, { 3310 .phy_id = PHY_ID_KSZ9031, 3311 .phy_id_mask = MICREL_PHY_ID_MASK, 3312 .name = "Micrel KSZ9031 Gigabit PHY", 3313 .flags = PHY_POLL_CABLE_TEST, 3314 .driver_data = &ksz9021_type, 3315 .probe = kszphy_probe, 3316 .get_features = ksz9031_get_features, 3317 .config_init = ksz9031_config_init, 3318 .soft_reset = genphy_soft_reset, 3319 .read_status = ksz9031_read_status, 3320 .config_intr = kszphy_config_intr, 3321 .handle_interrupt = kszphy_handle_interrupt, 3322 .get_sset_count = kszphy_get_sset_count, 3323 .get_strings = kszphy_get_strings, 3324 .get_stats = kszphy_get_stats, 3325 .suspend = kszphy_suspend, 3326 .resume = kszphy_resume, 3327 .cable_test_start = ksz9x31_cable_test_start, 3328 .cable_test_get_status = ksz9x31_cable_test_get_status, 3329 }, { 3330 .phy_id = PHY_ID_LAN8814, 3331 .phy_id_mask = MICREL_PHY_ID_MASK, 3332 .name = "Microchip INDY Gigabit Quad PHY", 3333 .flags = PHY_POLL_CABLE_TEST, 3334 .config_init = lan8814_config_init, 3335 .driver_data = &lan8814_type, 3336 .probe = lan8814_probe, 3337 .soft_reset = genphy_soft_reset, 3338 .read_status = ksz9031_read_status, 3339 .get_sset_count = kszphy_get_sset_count, 3340 .get_strings = kszphy_get_strings, 3341 .get_stats = kszphy_get_stats, 3342 .suspend = genphy_suspend, 3343 .resume = kszphy_resume, 3344 .config_intr = lan8814_config_intr, 3345 .handle_interrupt = lan8814_handle_interrupt, 3346 .cable_test_start = lan8814_cable_test_start, 3347 .cable_test_get_status = ksz886x_cable_test_get_status, 3348 }, { 3349 .phy_id = PHY_ID_LAN8804, 3350 .phy_id_mask = MICREL_PHY_ID_MASK, 3351 .name = "Microchip LAN966X Gigabit PHY", 3352 .config_init = lan8804_config_init, 3353 .driver_data = &ksz9021_type, 3354 .probe = kszphy_probe, 3355 .soft_reset = genphy_soft_reset, 3356 .read_status = ksz9031_read_status, 3357 .get_sset_count = kszphy_get_sset_count, 3358 .get_strings = kszphy_get_strings, 3359 .get_stats = kszphy_get_stats, 3360 .suspend = genphy_suspend, 3361 .resume = kszphy_resume, 3362 .config_intr = lan8804_config_intr, 3363 .handle_interrupt = lan8804_handle_interrupt, 3364 }, { 3365 .phy_id = PHY_ID_KSZ9131, 3366 .phy_id_mask = MICREL_PHY_ID_MASK, 3367 .name = "Microchip KSZ9131 Gigabit PHY", 3368 /* PHY_GBIT_FEATURES */ 3369 .flags = PHY_POLL_CABLE_TEST, 3370 .driver_data = &ksz9021_type, 3371 .probe = kszphy_probe, 3372 .config_init = ksz9131_config_init, 3373 .config_intr = kszphy_config_intr, 3374 .config_aneg = ksz9131_config_aneg, 3375 .read_status = ksz9131_read_status, 3376 .handle_interrupt = kszphy_handle_interrupt, 3377 .get_sset_count = kszphy_get_sset_count, 3378 .get_strings = kszphy_get_strings, 3379 .get_stats = kszphy_get_stats, 3380 .suspend = kszphy_suspend, 3381 .resume = kszphy_resume, 3382 .cable_test_start = ksz9x31_cable_test_start, 3383 .cable_test_get_status = ksz9x31_cable_test_get_status, 3384 }, { 3385 .phy_id = PHY_ID_KSZ8873MLL, 3386 .phy_id_mask = MICREL_PHY_ID_MASK, 3387 .name = "Micrel KSZ8873MLL Switch", 3388 /* PHY_BASIC_FEATURES */ 3389 .config_init = kszphy_config_init, 3390 .config_aneg = ksz8873mll_config_aneg, 3391 .read_status = ksz8873mll_read_status, 3392 .suspend = genphy_suspend, 3393 .resume = genphy_resume, 3394 }, { 3395 .phy_id = PHY_ID_KSZ886X, 3396 .phy_id_mask = MICREL_PHY_ID_MASK, 3397 .name = "Micrel KSZ8851 Ethernet MAC or KSZ886X Switch", 3398 .driver_data = &ksz886x_type, 3399 /* PHY_BASIC_FEATURES */ 3400 .flags = PHY_POLL_CABLE_TEST, 3401 .config_init = kszphy_config_init, 3402 .config_aneg = ksz886x_config_aneg, 3403 .read_status = ksz886x_read_status, 3404 .suspend = genphy_suspend, 3405 .resume = genphy_resume, 3406 .cable_test_start = ksz886x_cable_test_start, 3407 .cable_test_get_status = ksz886x_cable_test_get_status, 3408 }, { 3409 .name = "Micrel KSZ87XX Switch", 3410 /* PHY_BASIC_FEATURES */ 3411 .config_init = kszphy_config_init, 3412 .match_phy_device = ksz8795_match_phy_device, 3413 .suspend = genphy_suspend, 3414 .resume = genphy_resume, 3415 }, { 3416 .phy_id = PHY_ID_KSZ9477, 3417 .phy_id_mask = MICREL_PHY_ID_MASK, 3418 .name = "Microchip KSZ9477", 3419 /* PHY_GBIT_FEATURES */ 3420 .config_init = kszphy_config_init, 3421 .config_intr = kszphy_config_intr, 3422 .handle_interrupt = kszphy_handle_interrupt, 3423 .suspend = genphy_suspend, 3424 .resume = genphy_resume, 3425 } }; 3426 3427 module_phy_driver(ksphy_driver); 3428 3429 MODULE_DESCRIPTION("Micrel PHY driver"); 3430 MODULE_AUTHOR("David J. Choi"); 3431 MODULE_LICENSE("GPL"); 3432 3433 static struct mdio_device_id __maybe_unused micrel_tbl[] = { 3434 { PHY_ID_KSZ9021, 0x000ffffe }, 3435 { PHY_ID_KSZ9031, MICREL_PHY_ID_MASK }, 3436 { PHY_ID_KSZ9131, MICREL_PHY_ID_MASK }, 3437 { PHY_ID_KSZ8001, 0x00fffffc }, 3438 { PHY_ID_KS8737, MICREL_PHY_ID_MASK }, 3439 { PHY_ID_KSZ8021, 0x00ffffff }, 3440 { PHY_ID_KSZ8031, 0x00ffffff }, 3441 { PHY_ID_KSZ8041, MICREL_PHY_ID_MASK }, 3442 { PHY_ID_KSZ8051, MICREL_PHY_ID_MASK }, 3443 { PHY_ID_KSZ8061, MICREL_PHY_ID_MASK }, 3444 { PHY_ID_KSZ8081, MICREL_PHY_ID_MASK }, 3445 { PHY_ID_KSZ8873MLL, MICREL_PHY_ID_MASK }, 3446 { PHY_ID_KSZ886X, MICREL_PHY_ID_MASK }, 3447 { PHY_ID_LAN8814, MICREL_PHY_ID_MASK }, 3448 { PHY_ID_LAN8804, MICREL_PHY_ID_MASK }, 3449 { } 3450 }; 3451 3452 MODULE_DEVICE_TABLE(mdio, micrel_tbl); 3453