1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2015-2020 Beijing WangXun Technology Co., Ltd.
3 * Copyright(c) 2010-2017 Intel Corporation
7 #include "txgbe_eeprom.h"
11 static void txgbe_i2c_start(struct txgbe_hw *hw, u8 dev_addr);
12 static void txgbe_i2c_stop(struct txgbe_hw *hw);
13 static s32 txgbe_handle_bp_flow(u32 link_mode, struct txgbe_hw *hw);
14 static void txgbe_get_bp_ability(struct txgbe_backplane_ability *ability,
15 u32 link_partner, struct txgbe_hw *hw);
16 static s32 txgbe_check_bp_ability(struct txgbe_backplane_ability *local_ability,
17 struct txgbe_backplane_ability *lp_ability, struct txgbe_hw *hw);
18 static void txgbe_clear_bp_intr(u32 bit, u32 bit_high, struct txgbe_hw *hw);
19 static s32 txgbe_enable_kr_training(struct txgbe_hw *hw);
20 static s32 txgbe_disable_kr_training(struct txgbe_hw *hw, s32 post, s32 mode);
21 static s32 txgbe_check_kr_training(struct txgbe_hw *hw);
22 static void txgbe_read_phy_lane_tx_eq(u16 lane, struct txgbe_hw *hw,
24 static s32 txgbe_set_link_to_sfi(struct txgbe_hw *hw, u32 speed);
27 * txgbe_identify_extphy - Identify a single address for a PHY
28 * @hw: pointer to hardware structure
29 * @phy_addr: PHY address to probe
31 * Returns true if PHY found
33 static bool txgbe_identify_extphy(struct txgbe_hw *hw)
37 if (!txgbe_validate_phy_addr(hw, phy_addr)) {
38 DEBUGOUT("Unable to validate PHY address 0x%04X",
43 if (txgbe_get_phy_id(hw))
46 hw->phy.type = txgbe_get_phy_type_from_id(hw->phy.id);
47 if (hw->phy.type == txgbe_phy_unknown) {
49 hw->phy.read_reg(hw, TXGBE_MD_PHY_EXT_ABILITY,
53 if (ext_ability & (TXGBE_MD_PHY_10GBASET_ABILITY |
54 TXGBE_MD_PHY_1000BASET_ABILITY))
55 hw->phy.type = txgbe_phy_cu_unknown;
57 hw->phy.type = txgbe_phy_generic;
64 * txgbe_read_phy_if - Read TXGBE_ETHPHYIF register
65 * @hw: pointer to hardware structure
67 * Read TXGBE_ETHPHYIF register and save field values,
68 * and check for valid field values.
70 static s32 txgbe_read_phy_if(struct txgbe_hw *hw)
72 hw->phy.media_type = hw->phy.get_media_type(hw);
74 /* Save NW management interface connected on board. This is used
75 * to determine internal PHY mode.
77 hw->phy.nw_mng_if_sel = rd32(hw, TXGBE_ETHPHYIF);
79 /* If MDIO is connected to external PHY, then set PHY address. */
80 if (hw->phy.nw_mng_if_sel & TXGBE_ETHPHYIF_MDIO_ACT)
81 hw->phy.addr = TXGBE_ETHPHYIF_MDIO_BASE(hw->phy.nw_mng_if_sel);
83 if (!hw->phy.phy_semaphore_mask) {
85 hw->phy.phy_semaphore_mask = TXGBE_MNGSEM_SWPHY;
87 hw->phy.phy_semaphore_mask = TXGBE_MNGSEM_SWPHY;
94 * txgbe_identify_phy - Get physical layer module
95 * @hw: pointer to hardware structure
97 * Determines the physical layer module found on the current adapter.
99 s32 txgbe_identify_phy(struct txgbe_hw *hw)
101 s32 err = TXGBE_ERR_PHY_ADDR_INVALID;
103 txgbe_read_phy_if(hw);
105 if (hw->phy.type != txgbe_phy_unknown)
108 /* Raptor 10GBASE-T requires an external PHY */
109 if (hw->phy.media_type == txgbe_media_type_copper) {
110 err = txgbe_identify_extphy(hw);
111 } else if (hw->phy.media_type == txgbe_media_type_fiber) {
112 err = txgbe_identify_module(hw);
114 hw->phy.type = txgbe_phy_none;
118 /* Return error if SFP module has been detected but is not supported */
119 if (hw->phy.type == txgbe_phy_sfp_unsupported)
120 return TXGBE_ERR_SFP_NOT_SUPPORTED;
126 * txgbe_check_reset_blocked - check status of MNG FW veto bit
127 * @hw: pointer to the hardware structure
129 * This function checks the STAT.MNGVETO bit to see if there are
130 * any constraints on link from manageability. For MAC's that don't
131 * have this bit just return faluse since the link can not be blocked
134 s32 txgbe_check_reset_blocked(struct txgbe_hw *hw)
138 mmngc = rd32(hw, TXGBE_STAT);
139 if (mmngc & TXGBE_STAT_MNGVETO) {
140 DEBUGOUT("MNG_VETO bit detected.");
148 * txgbe_validate_phy_addr - Determines phy address is valid
149 * @hw: pointer to hardware structure
150 * @phy_addr: PHY address
153 bool txgbe_validate_phy_addr(struct txgbe_hw *hw, u32 phy_addr)
158 hw->phy.addr = phy_addr;
159 hw->phy.read_reg(hw, TXGBE_MD_PHY_ID_HIGH,
160 TXGBE_MD_DEV_PMA_PMD, &phy_id);
162 if (phy_id != 0xFFFF && phy_id != 0x0)
165 DEBUGOUT("PHY ID HIGH is 0x%04X", phy_id);
171 * txgbe_get_phy_id - Get the phy type
172 * @hw: pointer to hardware structure
175 s32 txgbe_get_phy_id(struct txgbe_hw *hw)
181 err = hw->phy.read_reg(hw, TXGBE_MD_PHY_ID_HIGH,
182 TXGBE_MD_DEV_PMA_PMD,
186 hw->phy.id = (u32)(phy_id_high << 16);
187 err = hw->phy.read_reg(hw, TXGBE_MD_PHY_ID_LOW,
188 TXGBE_MD_DEV_PMA_PMD,
190 hw->phy.id |= (u32)(phy_id_low & TXGBE_PHY_REVISION_MASK);
191 hw->phy.revision = (u32)(phy_id_low & ~TXGBE_PHY_REVISION_MASK);
193 DEBUGOUT("PHY_ID_HIGH 0x%04X, PHY_ID_LOW 0x%04X",
194 phy_id_high, phy_id_low);
200 * txgbe_get_phy_type_from_id - Get the phy type
201 * @phy_id: PHY ID information
204 enum txgbe_phy_type txgbe_get_phy_type_from_id(u32 phy_id)
206 enum txgbe_phy_type phy_type;
209 case TXGBE_PHYID_TN1010:
210 phy_type = txgbe_phy_tn;
212 case TXGBE_PHYID_QT2022:
213 phy_type = txgbe_phy_qt;
215 case TXGBE_PHYID_ATH:
216 phy_type = txgbe_phy_nl;
218 case TXGBE_PHYID_MTD3310:
219 phy_type = txgbe_phy_cu_mtd;
222 phy_type = txgbe_phy_unknown;
230 txgbe_reset_extphy(struct txgbe_hw *hw)
235 err = hw->phy.read_reg(hw, TXGBE_MD_PORT_CTRL,
236 TXGBE_MD_DEV_GENERAL, &ctrl);
239 ctrl |= TXGBE_MD_PORT_CTRL_RESET;
240 err = hw->phy.write_reg(hw, TXGBE_MD_PORT_CTRL,
241 TXGBE_MD_DEV_GENERAL, ctrl);
246 * Poll for reset bit to self-clear indicating reset is complete.
247 * Some PHYs could take up to 3 seconds to complete and need about
248 * 1.7 usec delay after the reset is complete.
250 for (i = 0; i < 30; i++) {
252 err = hw->phy.read_reg(hw, TXGBE_MD_PORT_CTRL,
253 TXGBE_MD_DEV_GENERAL, &ctrl);
257 if (!(ctrl & TXGBE_MD_PORT_CTRL_RESET)) {
263 if (ctrl & TXGBE_MD_PORT_CTRL_RESET) {
264 err = TXGBE_ERR_RESET_FAILED;
265 DEBUGOUT("PHY reset polling failed to complete.");
272 * txgbe_reset_phy - Performs a PHY reset
273 * @hw: pointer to hardware structure
275 s32 txgbe_reset_phy(struct txgbe_hw *hw)
279 if (hw->phy.type == txgbe_phy_unknown)
280 err = txgbe_identify_phy(hw);
282 if (err != 0 || hw->phy.type == txgbe_phy_none)
285 /* Don't reset PHY if it's shut down due to overtemp. */
286 if (hw->phy.check_overtemp(hw) == TXGBE_ERR_OVERTEMP)
289 /* Blocked by MNG FW so bail */
290 if (txgbe_check_reset_blocked(hw))
293 switch (hw->phy.type) {
294 case txgbe_phy_cu_mtd:
295 err = txgbe_reset_extphy(hw);
305 * txgbe_read_phy_mdi - Reads a value from a specified PHY register without
307 * @hw: pointer to hardware structure
308 * @reg_addr: 32 bit address of PHY register to read
309 * @device_type: 5 bit device type
310 * @phy_data: Pointer to read data from PHY register
312 s32 txgbe_read_phy_reg_mdi(struct txgbe_hw *hw, u32 reg_addr, u32 device_type,
317 /* Setup and write the address cycle command */
318 command = TXGBE_MDIOSCA_REG(reg_addr) |
319 TXGBE_MDIOSCA_DEV(device_type) |
320 TXGBE_MDIOSCA_PORT(hw->phy.addr);
321 wr32(hw, TXGBE_MDIOSCA, command);
323 command = TXGBE_MDIOSCD_CMD_READ |
325 wr32(hw, TXGBE_MDIOSCD, command);
328 * Check every 10 usec to see if the address cycle completed.
329 * The MDI Command bit will clear when the operation is
332 if (!po32m(hw, TXGBE_MDIOSCD, TXGBE_MDIOSCD_BUSY,
333 0, NULL, 100, 100)) {
334 DEBUGOUT("PHY address command did not complete");
335 return TXGBE_ERR_PHY;
338 data = rd32(hw, TXGBE_MDIOSCD);
339 *phy_data = (u16)TXGBD_MDIOSCD_DAT(data);
345 * txgbe_read_phy_reg - Reads a value from a specified PHY register
346 * using the SWFW lock - this function is needed in most cases
347 * @hw: pointer to hardware structure
348 * @reg_addr: 32 bit address of PHY register to read
349 * @device_type: 5 bit device type
350 * @phy_data: Pointer to read data from PHY register
352 s32 txgbe_read_phy_reg(struct txgbe_hw *hw, u32 reg_addr,
353 u32 device_type, u16 *phy_data)
356 u32 gssr = hw->phy.phy_semaphore_mask;
358 if (hw->mac.acquire_swfw_sync(hw, gssr))
359 return TXGBE_ERR_SWFW_SYNC;
361 err = hw->phy.read_reg_mdi(hw, reg_addr, device_type, phy_data);
363 hw->mac.release_swfw_sync(hw, gssr);
369 * txgbe_write_phy_reg_mdi - Writes a value to specified PHY register
371 * @hw: pointer to hardware structure
372 * @reg_addr: 32 bit PHY register to write
373 * @device_type: 5 bit device type
374 * @phy_data: Data to write to the PHY register
376 s32 txgbe_write_phy_reg_mdi(struct txgbe_hw *hw, u32 reg_addr,
377 u32 device_type, u16 phy_data)
382 command = TXGBE_MDIOSCA_REG(reg_addr) |
383 TXGBE_MDIOSCA_DEV(device_type) |
384 TXGBE_MDIOSCA_PORT(hw->phy.addr);
385 wr32(hw, TXGBE_MDIOSCA, command);
387 command = TXGBE_MDIOSCD_CMD_WRITE |
388 TXGBE_MDIOSCD_DAT(phy_data) |
390 wr32(hw, TXGBE_MDIOSCD, command);
392 /* wait for completion */
393 if (!po32m(hw, TXGBE_MDIOSCD, TXGBE_MDIOSCD_BUSY,
394 0, NULL, 100, 100)) {
395 DEBUGOUT("PHY write cmd didn't complete");
403 * txgbe_write_phy_reg - Writes a value to specified PHY register
404 * using SWFW lock- this function is needed in most cases
405 * @hw: pointer to hardware structure
406 * @reg_addr: 32 bit PHY register to write
407 * @device_type: 5 bit device type
408 * @phy_data: Data to write to the PHY register
410 s32 txgbe_write_phy_reg(struct txgbe_hw *hw, u32 reg_addr,
411 u32 device_type, u16 phy_data)
414 u32 gssr = hw->phy.phy_semaphore_mask;
416 if (hw->mac.acquire_swfw_sync(hw, gssr))
417 err = TXGBE_ERR_SWFW_SYNC;
419 err = hw->phy.write_reg_mdi(hw, reg_addr, device_type,
421 hw->mac.release_swfw_sync(hw, gssr);
427 * txgbe_setup_phy_link - Set and restart auto-neg
428 * @hw: pointer to hardware structure
430 * Restart auto-negotiation and PHY and waits for completion.
432 s32 txgbe_setup_phy_link(struct txgbe_hw *hw)
435 u16 autoneg_reg = TXGBE_MII_AUTONEG_REG;
436 bool autoneg = false;
439 txgbe_get_copper_link_capabilities(hw, &speed, &autoneg);
441 /* Set or unset auto-negotiation 10G advertisement */
442 hw->phy.read_reg(hw, TXGBE_MII_10GBASE_T_AUTONEG_CTRL_REG,
443 TXGBE_MD_DEV_AUTO_NEG,
446 autoneg_reg &= ~TXGBE_MII_10GBASE_T_ADVERTISE;
447 if ((hw->phy.autoneg_advertised & TXGBE_LINK_SPEED_10GB_FULL) &&
448 (speed & TXGBE_LINK_SPEED_10GB_FULL))
449 autoneg_reg |= TXGBE_MII_10GBASE_T_ADVERTISE;
451 hw->phy.write_reg(hw, TXGBE_MII_10GBASE_T_AUTONEG_CTRL_REG,
452 TXGBE_MD_DEV_AUTO_NEG,
455 hw->phy.read_reg(hw, TXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
456 TXGBE_MD_DEV_AUTO_NEG,
459 /* Set or unset auto-negotiation 5G advertisement */
460 autoneg_reg &= ~TXGBE_MII_5GBASE_T_ADVERTISE;
461 if ((hw->phy.autoneg_advertised & TXGBE_LINK_SPEED_5GB_FULL) &&
462 (speed & TXGBE_LINK_SPEED_5GB_FULL))
463 autoneg_reg |= TXGBE_MII_5GBASE_T_ADVERTISE;
465 /* Set or unset auto-negotiation 2.5G advertisement */
466 autoneg_reg &= ~TXGBE_MII_2_5GBASE_T_ADVERTISE;
467 if ((hw->phy.autoneg_advertised &
468 TXGBE_LINK_SPEED_2_5GB_FULL) &&
469 (speed & TXGBE_LINK_SPEED_2_5GB_FULL))
470 autoneg_reg |= TXGBE_MII_2_5GBASE_T_ADVERTISE;
471 /* Set or unset auto-negotiation 1G advertisement */
472 autoneg_reg &= ~TXGBE_MII_1GBASE_T_ADVERTISE;
473 if ((hw->phy.autoneg_advertised & TXGBE_LINK_SPEED_1GB_FULL) &&
474 (speed & TXGBE_LINK_SPEED_1GB_FULL))
475 autoneg_reg |= TXGBE_MII_1GBASE_T_ADVERTISE;
477 hw->phy.write_reg(hw, TXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
478 TXGBE_MD_DEV_AUTO_NEG,
481 /* Set or unset auto-negotiation 100M advertisement */
482 hw->phy.read_reg(hw, TXGBE_MII_AUTONEG_ADVERTISE_REG,
483 TXGBE_MD_DEV_AUTO_NEG,
486 autoneg_reg &= ~(TXGBE_MII_100BASE_T_ADVERTISE |
487 TXGBE_MII_100BASE_T_ADVERTISE_HALF);
488 if ((hw->phy.autoneg_advertised & TXGBE_LINK_SPEED_100M_FULL) &&
489 (speed & TXGBE_LINK_SPEED_100M_FULL))
490 autoneg_reg |= TXGBE_MII_100BASE_T_ADVERTISE;
492 hw->phy.write_reg(hw, TXGBE_MII_AUTONEG_ADVERTISE_REG,
493 TXGBE_MD_DEV_AUTO_NEG,
496 /* Blocked by MNG FW so don't reset PHY */
497 if (txgbe_check_reset_blocked(hw))
500 /* Restart PHY auto-negotiation. */
501 hw->phy.read_reg(hw, TXGBE_MD_AUTO_NEG_CONTROL,
502 TXGBE_MD_DEV_AUTO_NEG, &autoneg_reg);
504 autoneg_reg |= TXGBE_MII_RESTART;
506 hw->phy.write_reg(hw, TXGBE_MD_AUTO_NEG_CONTROL,
507 TXGBE_MD_DEV_AUTO_NEG, autoneg_reg);
513 * txgbe_setup_phy_link_speed - Sets the auto advertised capabilities
514 * @hw: pointer to hardware structure
515 * @speed: new link speed
516 * @autoneg_wait_to_complete: unused
518 s32 txgbe_setup_phy_link_speed(struct txgbe_hw *hw,
520 bool autoneg_wait_to_complete)
522 UNREFERENCED_PARAMETER(autoneg_wait_to_complete);
525 * Clear autoneg_advertised and set new values based on input link
528 hw->phy.autoneg_advertised = 0;
530 if (speed & TXGBE_LINK_SPEED_10GB_FULL)
531 hw->phy.autoneg_advertised |= TXGBE_LINK_SPEED_10GB_FULL;
533 if (speed & TXGBE_LINK_SPEED_5GB_FULL)
534 hw->phy.autoneg_advertised |= TXGBE_LINK_SPEED_5GB_FULL;
536 if (speed & TXGBE_LINK_SPEED_2_5GB_FULL)
537 hw->phy.autoneg_advertised |= TXGBE_LINK_SPEED_2_5GB_FULL;
539 if (speed & TXGBE_LINK_SPEED_1GB_FULL)
540 hw->phy.autoneg_advertised |= TXGBE_LINK_SPEED_1GB_FULL;
542 if (speed & TXGBE_LINK_SPEED_100M_FULL)
543 hw->phy.autoneg_advertised |= TXGBE_LINK_SPEED_100M_FULL;
545 if (speed & TXGBE_LINK_SPEED_10M_FULL)
546 hw->phy.autoneg_advertised |= TXGBE_LINK_SPEED_10M_FULL;
548 /* Setup link based on the new speed settings */
549 hw->phy.setup_link(hw);
554 s32 txgbe_get_phy_fw_version(struct txgbe_hw *hw, u32 *fw_version)
556 u16 eeprom_verh, eeprom_verl;
558 hw->rom.readw_sw(hw, TXGBE_EEPROM_VERSION_H, &eeprom_verh);
559 hw->rom.readw_sw(hw, TXGBE_EEPROM_VERSION_L, &eeprom_verl);
561 *fw_version = (eeprom_verh << 16) | eeprom_verl;
567 * txgbe_get_copper_speeds_supported - Get copper link speeds from phy
568 * @hw: pointer to hardware structure
570 * Determines the supported link capabilities by reading the PHY auto
571 * negotiation register.
573 static s32 txgbe_get_copper_speeds_supported(struct txgbe_hw *hw)
578 err = hw->phy.read_reg(hw, TXGBE_MD_PHY_SPEED_ABILITY,
579 TXGBE_MD_DEV_PMA_PMD,
584 if (speed_ability & TXGBE_MD_PHY_SPEED_10G)
585 hw->phy.speeds_supported |= TXGBE_LINK_SPEED_10GB_FULL;
586 if (speed_ability & TXGBE_MD_PHY_SPEED_1G)
587 hw->phy.speeds_supported |= TXGBE_LINK_SPEED_1GB_FULL;
588 if (speed_ability & TXGBE_MD_PHY_SPEED_100M)
589 hw->phy.speeds_supported |= TXGBE_LINK_SPEED_100M_FULL;
595 * txgbe_get_copper_link_capabilities - Determines link capabilities
596 * @hw: pointer to hardware structure
597 * @speed: pointer to link speed
598 * @autoneg: boolean auto-negotiation value
600 s32 txgbe_get_copper_link_capabilities(struct txgbe_hw *hw,
607 if (!hw->phy.speeds_supported)
608 err = txgbe_get_copper_speeds_supported(hw);
610 *speed = hw->phy.speeds_supported;
615 * txgbe_check_phy_link_tnx - Determine link and speed status
616 * @hw: pointer to hardware structure
617 * @speed: current link speed
618 * @link_up: true is link is up, false otherwise
620 * Reads the VS1 register to determine if link is up and the current speed for
623 s32 txgbe_check_phy_link_tnx(struct txgbe_hw *hw, u32 *speed,
628 u32 max_time_out = 10;
633 /* Initialize speed and link to default case */
635 *speed = TXGBE_LINK_SPEED_10GB_FULL;
638 * Check current speed and link status of the PHY register.
639 * This is a vendor specific register and may have to
640 * be changed for other copper PHYs.
642 for (time_out = 0; time_out < max_time_out; time_out++) {
644 err = hw->phy.read_reg(hw,
645 TXGBE_MD_VENDOR_SPECIFIC_1_STATUS,
646 TXGBE_MD_DEV_VENDOR_1,
648 phy_link = phy_data & TXGBE_MD_VENDOR_SPECIFIC_1_LINK_STATUS;
649 phy_speed = phy_data &
650 TXGBE_MD_VENDOR_SPECIFIC_1_SPEED_STATUS;
651 if (phy_link == TXGBE_MD_VENDOR_SPECIFIC_1_LINK_STATUS) {
654 TXGBE_MD_VENDOR_SPECIFIC_1_SPEED_STATUS)
655 *speed = TXGBE_LINK_SPEED_1GB_FULL;
664 * txgbe_setup_phy_link_tnx - Set and restart auto-neg
665 * @hw: pointer to hardware structure
667 * Restart auto-negotiation and PHY and waits for completion.
669 s32 txgbe_setup_phy_link_tnx(struct txgbe_hw *hw)
672 u16 autoneg_reg = TXGBE_MII_AUTONEG_REG;
673 bool autoneg = false;
676 txgbe_get_copper_link_capabilities(hw, &speed, &autoneg);
678 if (speed & TXGBE_LINK_SPEED_10GB_FULL) {
679 /* Set or unset auto-negotiation 10G advertisement */
680 hw->phy.read_reg(hw, TXGBE_MII_10GBASE_T_AUTONEG_CTRL_REG,
681 TXGBE_MD_DEV_AUTO_NEG,
684 autoneg_reg &= ~TXGBE_MII_10GBASE_T_ADVERTISE;
685 if (hw->phy.autoneg_advertised & TXGBE_LINK_SPEED_10GB_FULL)
686 autoneg_reg |= TXGBE_MII_10GBASE_T_ADVERTISE;
688 hw->phy.write_reg(hw, TXGBE_MII_10GBASE_T_AUTONEG_CTRL_REG,
689 TXGBE_MD_DEV_AUTO_NEG,
693 if (speed & TXGBE_LINK_SPEED_1GB_FULL) {
694 /* Set or unset auto-negotiation 1G advertisement */
695 hw->phy.read_reg(hw, TXGBE_MII_AUTONEG_XNP_TX_REG,
696 TXGBE_MD_DEV_AUTO_NEG,
699 autoneg_reg &= ~TXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX;
700 if (hw->phy.autoneg_advertised & TXGBE_LINK_SPEED_1GB_FULL)
701 autoneg_reg |= TXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX;
703 hw->phy.write_reg(hw, TXGBE_MII_AUTONEG_XNP_TX_REG,
704 TXGBE_MD_DEV_AUTO_NEG,
708 if (speed & TXGBE_LINK_SPEED_100M_FULL) {
709 /* Set or unset auto-negotiation 100M advertisement */
710 hw->phy.read_reg(hw, TXGBE_MII_AUTONEG_ADVERTISE_REG,
711 TXGBE_MD_DEV_AUTO_NEG,
714 autoneg_reg &= ~TXGBE_MII_100BASE_T_ADVERTISE;
715 if (hw->phy.autoneg_advertised & TXGBE_LINK_SPEED_100M_FULL)
716 autoneg_reg |= TXGBE_MII_100BASE_T_ADVERTISE;
718 hw->phy.write_reg(hw, TXGBE_MII_AUTONEG_ADVERTISE_REG,
719 TXGBE_MD_DEV_AUTO_NEG,
723 /* Blocked by MNG FW so don't reset PHY */
724 if (txgbe_check_reset_blocked(hw))
727 /* Restart PHY auto-negotiation. */
728 hw->phy.read_reg(hw, TXGBE_MD_AUTO_NEG_CONTROL,
729 TXGBE_MD_DEV_AUTO_NEG, &autoneg_reg);
731 autoneg_reg |= TXGBE_MII_RESTART;
733 hw->phy.write_reg(hw, TXGBE_MD_AUTO_NEG_CONTROL,
734 TXGBE_MD_DEV_AUTO_NEG, autoneg_reg);
740 * txgbe_identify_module - Identifies module type
741 * @hw: pointer to hardware structure
743 * Determines HW type and calls appropriate function.
745 s32 txgbe_identify_module(struct txgbe_hw *hw)
747 s32 err = TXGBE_ERR_SFP_NOT_PRESENT;
749 switch (hw->phy.media_type) {
750 case txgbe_media_type_fiber:
751 err = txgbe_identify_sfp_module(hw);
754 case txgbe_media_type_fiber_qsfp:
755 err = txgbe_identify_qsfp_module(hw);
759 hw->phy.sfp_type = txgbe_sfp_type_not_present;
760 err = TXGBE_ERR_SFP_NOT_PRESENT;
768 * txgbe_identify_sfp_module - Identifies SFP modules
769 * @hw: pointer to hardware structure
771 * Searches for and identifies the SFP module and assigns appropriate PHY type.
773 s32 txgbe_identify_sfp_module(struct txgbe_hw *hw)
775 s32 err = TXGBE_ERR_PHY_ADDR_INVALID;
777 enum txgbe_sfp_type stored_sfp_type = hw->phy.sfp_type;
779 u8 comp_codes_1g = 0;
780 u8 comp_codes_10g = 0;
781 u8 oui_bytes[3] = {0, 0, 0};
786 if (hw->phy.media_type != txgbe_media_type_fiber) {
787 hw->phy.sfp_type = txgbe_sfp_type_not_present;
788 return TXGBE_ERR_SFP_NOT_PRESENT;
791 err = hw->phy.read_i2c_eeprom(hw, TXGBE_SFF_IDENTIFIER,
795 hw->phy.sfp_type = txgbe_sfp_type_not_present;
796 if (hw->phy.type != txgbe_phy_nl) {
798 hw->phy.type = txgbe_phy_unknown;
800 return TXGBE_ERR_SFP_NOT_PRESENT;
803 if (identifier != TXGBE_SFF_IDENTIFIER_SFP) {
804 hw->phy.type = txgbe_phy_sfp_unsupported;
805 return TXGBE_ERR_SFP_NOT_SUPPORTED;
808 err = hw->phy.read_i2c_eeprom(hw, TXGBE_SFF_1GBE_COMP_CODES,
813 err = hw->phy.read_i2c_eeprom(hw, TXGBE_SFF_10GBE_COMP_CODES,
818 err = hw->phy.read_i2c_eeprom(hw, TXGBE_SFF_CABLE_TECHNOLOGY,
828 * 3 SFP_DA_CORE0 - chip-specific
829 * 4 SFP_DA_CORE1 - chip-specific
830 * 5 SFP_SR/LR_CORE0 - chip-specific
831 * 6 SFP_SR/LR_CORE1 - chip-specific
832 * 7 SFP_act_lmt_DA_CORE0 - chip-specific
833 * 8 SFP_act_lmt_DA_CORE1 - chip-specific
834 * 9 SFP_1g_cu_CORE0 - chip-specific
835 * 10 SFP_1g_cu_CORE1 - chip-specific
836 * 11 SFP_1g_sx_CORE0 - chip-specific
837 * 12 SFP_1g_sx_CORE1 - chip-specific
839 if (cable_tech & TXGBE_SFF_CABLE_DA_PASSIVE) {
840 if (hw->bus.lan_id == 0)
841 hw->phy.sfp_type = txgbe_sfp_type_da_cu_core0;
843 hw->phy.sfp_type = txgbe_sfp_type_da_cu_core1;
844 } else if (cable_tech & TXGBE_SFF_CABLE_DA_ACTIVE) {
845 err = hw->phy.read_i2c_eeprom(hw,
846 TXGBE_SFF_CABLE_SPEC_COMP, &cable_spec);
849 if (cable_spec & TXGBE_SFF_DA_SPEC_ACTIVE_LIMITING) {
850 hw->phy.sfp_type = (hw->bus.lan_id == 0
851 ? txgbe_sfp_type_da_act_lmt_core0
852 : txgbe_sfp_type_da_act_lmt_core1);
854 hw->phy.sfp_type = txgbe_sfp_type_unknown;
856 } else if (comp_codes_10g &
857 (TXGBE_SFF_10GBASESR_CAPABLE |
858 TXGBE_SFF_10GBASELR_CAPABLE)) {
859 hw->phy.sfp_type = (hw->bus.lan_id == 0
860 ? txgbe_sfp_type_srlr_core0
861 : txgbe_sfp_type_srlr_core1);
862 } else if (comp_codes_1g & TXGBE_SFF_1GBASET_CAPABLE) {
863 hw->phy.sfp_type = (hw->bus.lan_id == 0
864 ? txgbe_sfp_type_1g_cu_core0
865 : txgbe_sfp_type_1g_cu_core1);
866 } else if (comp_codes_1g & TXGBE_SFF_1GBASESX_CAPABLE) {
867 hw->phy.sfp_type = (hw->bus.lan_id == 0
868 ? txgbe_sfp_type_1g_sx_core0
869 : txgbe_sfp_type_1g_sx_core1);
870 } else if (comp_codes_1g & TXGBE_SFF_1GBASELX_CAPABLE) {
871 hw->phy.sfp_type = (hw->bus.lan_id == 0
872 ? txgbe_sfp_type_1g_lx_core0
873 : txgbe_sfp_type_1g_lx_core1);
875 hw->phy.sfp_type = txgbe_sfp_type_unknown;
878 if (hw->phy.sfp_type != stored_sfp_type)
879 hw->phy.sfp_setup_needed = true;
881 /* Determine if the SFP+ PHY is dual speed or not. */
882 hw->phy.multispeed_fiber = false;
883 if (((comp_codes_1g & TXGBE_SFF_1GBASESX_CAPABLE) &&
884 (comp_codes_10g & TXGBE_SFF_10GBASESR_CAPABLE)) ||
885 ((comp_codes_1g & TXGBE_SFF_1GBASELX_CAPABLE) &&
886 (comp_codes_10g & TXGBE_SFF_10GBASELR_CAPABLE)))
887 hw->phy.multispeed_fiber = true;
889 /* Determine PHY vendor */
890 if (hw->phy.type != txgbe_phy_nl) {
891 hw->phy.id = identifier;
892 err = hw->phy.read_i2c_eeprom(hw,
893 TXGBE_SFF_VENDOR_OUI_BYTE0, &oui_bytes[0]);
897 err = hw->phy.read_i2c_eeprom(hw,
898 TXGBE_SFF_VENDOR_OUI_BYTE1, &oui_bytes[1]);
902 err = hw->phy.read_i2c_eeprom(hw,
903 TXGBE_SFF_VENDOR_OUI_BYTE2, &oui_bytes[2]);
907 vendor_oui = ((u32)oui_bytes[0] << 24) |
908 ((u32)oui_bytes[1] << 16) |
909 ((u32)oui_bytes[2] << 8);
910 switch (vendor_oui) {
911 case TXGBE_SFF_VENDOR_OUI_TYCO:
912 if (cable_tech & TXGBE_SFF_CABLE_DA_PASSIVE)
913 hw->phy.type = txgbe_phy_sfp_tyco_passive;
915 case TXGBE_SFF_VENDOR_OUI_FTL:
916 if (cable_tech & TXGBE_SFF_CABLE_DA_ACTIVE)
917 hw->phy.type = txgbe_phy_sfp_ftl_active;
919 hw->phy.type = txgbe_phy_sfp_ftl;
921 case TXGBE_SFF_VENDOR_OUI_AVAGO:
922 hw->phy.type = txgbe_phy_sfp_avago;
924 case TXGBE_SFF_VENDOR_OUI_INTEL:
925 hw->phy.type = txgbe_phy_sfp_intel;
928 if (cable_tech & TXGBE_SFF_CABLE_DA_PASSIVE)
929 hw->phy.type = txgbe_phy_sfp_unknown_passive;
930 else if (cable_tech & TXGBE_SFF_CABLE_DA_ACTIVE)
931 hw->phy.type = txgbe_phy_sfp_unknown_active;
933 hw->phy.type = txgbe_phy_sfp_unknown;
938 /* Allow any DA cable vendor */
939 if (cable_tech & (TXGBE_SFF_CABLE_DA_PASSIVE |
940 TXGBE_SFF_CABLE_DA_ACTIVE)) {
944 /* Verify supported 1G SFP modules */
945 if (comp_codes_10g == 0 &&
946 !(hw->phy.sfp_type == txgbe_sfp_type_1g_cu_core1 ||
947 hw->phy.sfp_type == txgbe_sfp_type_1g_cu_core0 ||
948 hw->phy.sfp_type == txgbe_sfp_type_1g_lx_core0 ||
949 hw->phy.sfp_type == txgbe_sfp_type_1g_lx_core1 ||
950 hw->phy.sfp_type == txgbe_sfp_type_1g_sx_core0 ||
951 hw->phy.sfp_type == txgbe_sfp_type_1g_sx_core1)) {
952 hw->phy.type = txgbe_phy_sfp_unsupported;
953 return TXGBE_ERR_SFP_NOT_SUPPORTED;
956 hw->mac.get_device_caps(hw, &enforce_sfp);
957 if (!(enforce_sfp & TXGBE_DEVICE_CAPS_ALLOW_ANY_SFP) &&
958 !hw->allow_unsupported_sfp &&
959 !(hw->phy.sfp_type == txgbe_sfp_type_1g_cu_core0 ||
960 hw->phy.sfp_type == txgbe_sfp_type_1g_cu_core1 ||
961 hw->phy.sfp_type == txgbe_sfp_type_1g_lx_core0 ||
962 hw->phy.sfp_type == txgbe_sfp_type_1g_lx_core1 ||
963 hw->phy.sfp_type == txgbe_sfp_type_1g_sx_core0 ||
964 hw->phy.sfp_type == txgbe_sfp_type_1g_sx_core1)) {
965 DEBUGOUT("SFP+ module not supported");
966 hw->phy.type = txgbe_phy_sfp_unsupported;
967 return TXGBE_ERR_SFP_NOT_SUPPORTED;
974 * txgbe_identify_qsfp_module - Identifies QSFP modules
975 * @hw: pointer to hardware structure
977 * Searches for and identifies the QSFP module and assigns appropriate PHY type
979 s32 txgbe_identify_qsfp_module(struct txgbe_hw *hw)
981 s32 err = TXGBE_ERR_PHY_ADDR_INVALID;
983 enum txgbe_sfp_type stored_sfp_type = hw->phy.sfp_type;
985 u8 comp_codes_1g = 0;
986 u8 comp_codes_10g = 0;
987 u8 oui_bytes[3] = {0, 0, 0};
992 bool active_cable = false;
994 if (hw->phy.media_type != txgbe_media_type_fiber_qsfp) {
995 hw->phy.sfp_type = txgbe_sfp_type_not_present;
996 err = TXGBE_ERR_SFP_NOT_PRESENT;
1000 err = hw->phy.read_i2c_eeprom(hw, TXGBE_SFF_IDENTIFIER,
1004 hw->phy.sfp_type = txgbe_sfp_type_not_present;
1006 hw->phy.type = txgbe_phy_unknown;
1007 return TXGBE_ERR_SFP_NOT_PRESENT;
1009 if (identifier != TXGBE_SFF_IDENTIFIER_QSFP_PLUS) {
1010 hw->phy.type = txgbe_phy_sfp_unsupported;
1011 err = TXGBE_ERR_SFP_NOT_SUPPORTED;
1015 hw->phy.id = identifier;
1017 err = hw->phy.read_i2c_eeprom(hw, TXGBE_SFF_QSFP_10GBE_COMP,
1023 err = hw->phy.read_i2c_eeprom(hw, TXGBE_SFF_QSFP_1GBE_COMP,
1029 if (comp_codes_10g & TXGBE_SFF_QSFP_DA_PASSIVE_CABLE) {
1030 hw->phy.type = txgbe_phy_qsfp_unknown_passive;
1031 if (hw->bus.lan_id == 0)
1032 hw->phy.sfp_type = txgbe_sfp_type_da_cu_core0;
1034 hw->phy.sfp_type = txgbe_sfp_type_da_cu_core1;
1035 } else if (comp_codes_10g & (TXGBE_SFF_10GBASESR_CAPABLE |
1036 TXGBE_SFF_10GBASELR_CAPABLE)) {
1037 if (hw->bus.lan_id == 0)
1038 hw->phy.sfp_type = txgbe_sfp_type_srlr_core0;
1040 hw->phy.sfp_type = txgbe_sfp_type_srlr_core1;
1042 if (comp_codes_10g & TXGBE_SFF_QSFP_DA_ACTIVE_CABLE)
1043 active_cable = true;
1045 if (!active_cable) {
1046 hw->phy.read_i2c_eeprom(hw,
1047 TXGBE_SFF_QSFP_CONNECTOR,
1050 hw->phy.read_i2c_eeprom(hw,
1051 TXGBE_SFF_QSFP_CABLE_LENGTH,
1054 hw->phy.read_i2c_eeprom(hw,
1055 TXGBE_SFF_QSFP_DEVICE_TECH,
1059 TXGBE_SFF_QSFP_CONNECTOR_NOT_SEPARABLE &&
1061 ((device_tech >> 4) ==
1062 TXGBE_SFF_QSFP_TRANSMITTER_850NM_VCSEL))
1063 active_cable = true;
1067 hw->phy.type = txgbe_phy_qsfp_unknown_active;
1068 if (hw->bus.lan_id == 0)
1070 txgbe_sfp_type_da_act_lmt_core0;
1073 txgbe_sfp_type_da_act_lmt_core1;
1075 /* unsupported module type */
1076 hw->phy.type = txgbe_phy_sfp_unsupported;
1077 err = TXGBE_ERR_SFP_NOT_SUPPORTED;
1082 if (hw->phy.sfp_type != stored_sfp_type)
1083 hw->phy.sfp_setup_needed = true;
1085 /* Determine if the QSFP+ PHY is dual speed or not. */
1086 hw->phy.multispeed_fiber = false;
1087 if (((comp_codes_1g & TXGBE_SFF_1GBASESX_CAPABLE) &&
1088 (comp_codes_10g & TXGBE_SFF_10GBASESR_CAPABLE)) ||
1089 ((comp_codes_1g & TXGBE_SFF_1GBASELX_CAPABLE) &&
1090 (comp_codes_10g & TXGBE_SFF_10GBASELR_CAPABLE)))
1091 hw->phy.multispeed_fiber = true;
1093 /* Determine PHY vendor for optical modules */
1094 if (comp_codes_10g & (TXGBE_SFF_10GBASESR_CAPABLE |
1095 TXGBE_SFF_10GBASELR_CAPABLE)) {
1096 err = hw->phy.read_i2c_eeprom(hw,
1097 TXGBE_SFF_QSFP_VENDOR_OUI_BYTE0,
1103 err = hw->phy.read_i2c_eeprom(hw,
1104 TXGBE_SFF_QSFP_VENDOR_OUI_BYTE1,
1110 err = hw->phy.read_i2c_eeprom(hw,
1111 TXGBE_SFF_QSFP_VENDOR_OUI_BYTE2,
1118 ((oui_bytes[0] << 24) |
1119 (oui_bytes[1] << 16) |
1120 (oui_bytes[2] << 8));
1122 if (vendor_oui == TXGBE_SFF_VENDOR_OUI_INTEL)
1123 hw->phy.type = txgbe_phy_qsfp_intel;
1125 hw->phy.type = txgbe_phy_qsfp_unknown;
1127 hw->mac.get_device_caps(hw, &enforce_sfp);
1128 if (!(enforce_sfp & TXGBE_DEVICE_CAPS_ALLOW_ANY_SFP)) {
1129 /* Make sure we're a supported PHY type */
1130 if (hw->phy.type == txgbe_phy_qsfp_intel) {
1133 if (hw->allow_unsupported_sfp) {
1134 DEBUGOUT("WARNING: Wangxun (R) Network Connections are quality tested using Wangxun (R) Ethernet Optics. "
1135 "Using untested modules is not supported and may cause unstable operation or damage to the module or the adapter. "
1136 "Wangxun Corporation is not responsible for any harm caused by using untested modules.");
1139 DEBUGOUT("QSFP module not supported");
1141 txgbe_phy_sfp_unsupported;
1142 err = TXGBE_ERR_SFP_NOT_SUPPORTED;
1155 * txgbe_read_i2c_eeprom - Reads 8 bit EEPROM word over I2C interface
1156 * @hw: pointer to hardware structure
1157 * @byte_offset: EEPROM byte offset to read
1158 * @eeprom_data: value read
1160 * Performs byte read operation to SFP module's EEPROM over I2C interface.
1162 s32 txgbe_read_i2c_eeprom(struct txgbe_hw *hw, u8 byte_offset,
1165 return hw->phy.read_i2c_byte(hw, byte_offset,
1166 TXGBE_I2C_EEPROM_DEV_ADDR,
1171 * txgbe_read_i2c_sff8472 - Reads 8 bit word over I2C interface
1172 * @hw: pointer to hardware structure
1173 * @byte_offset: byte offset at address 0xA2
1174 * @sff8472_data: value read
1176 * Performs byte read operation to SFP module's SFF-8472 data over I2C
1178 s32 txgbe_read_i2c_sff8472(struct txgbe_hw *hw, u8 byte_offset,
1181 return hw->phy.read_i2c_byte(hw, byte_offset,
1182 TXGBE_I2C_EEPROM_DEV_ADDR2,
1187 * txgbe_write_i2c_eeprom - Writes 8 bit EEPROM word over I2C interface
1188 * @hw: pointer to hardware structure
1189 * @byte_offset: EEPROM byte offset to write
1190 * @eeprom_data: value to write
1192 * Performs byte write operation to SFP module's EEPROM over I2C interface.
1194 s32 txgbe_write_i2c_eeprom(struct txgbe_hw *hw, u8 byte_offset,
1197 return hw->phy.write_i2c_byte(hw, byte_offset,
1198 TXGBE_I2C_EEPROM_DEV_ADDR,
1203 * txgbe_read_i2c_byte_unlocked - Reads 8 bit word over I2C
1204 * @hw: pointer to hardware structure
1205 * @byte_offset: byte offset to read
1206 * @dev_addr: address to read from
1209 * Performs byte read operation to SFP module's EEPROM over I2C interface at
1210 * a specified device address.
1212 s32 txgbe_read_i2c_byte_unlocked(struct txgbe_hw *hw, u8 byte_offset,
1213 u8 dev_addr, u8 *data)
1215 txgbe_i2c_start(hw, dev_addr);
1218 if (!po32m(hw, TXGBE_I2CICR, TXGBE_I2CICR_TXEMPTY,
1219 TXGBE_I2CICR_TXEMPTY, NULL, 100, 100)) {
1220 return -TERR_TIMEOUT;
1224 wr32(hw, TXGBE_I2CDATA,
1225 byte_offset | TXGBE_I2CDATA_STOP);
1226 wr32(hw, TXGBE_I2CDATA, TXGBE_I2CDATA_READ);
1228 /* wait for read complete */
1229 if (!po32m(hw, TXGBE_I2CICR, TXGBE_I2CICR_RXFULL,
1230 TXGBE_I2CICR_RXFULL, NULL, 100, 100)) {
1231 return -TERR_TIMEOUT;
1236 *data = 0xFF & rd32(hw, TXGBE_I2CDATA);
1242 * txgbe_read_i2c_byte - Reads 8 bit word over I2C
1243 * @hw: pointer to hardware structure
1244 * @byte_offset: byte offset to read
1245 * @dev_addr: address to read from
1248 * Performs byte read operation to SFP module's EEPROM over I2C interface at
1249 * a specified device address.
1251 s32 txgbe_read_i2c_byte(struct txgbe_hw *hw, u8 byte_offset,
1252 u8 dev_addr, u8 *data)
1254 u32 swfw_mask = hw->phy.phy_semaphore_mask;
1257 if (hw->mac.acquire_swfw_sync(hw, swfw_mask))
1258 return TXGBE_ERR_SWFW_SYNC;
1259 err = txgbe_read_i2c_byte_unlocked(hw, byte_offset, dev_addr, data);
1260 hw->mac.release_swfw_sync(hw, swfw_mask);
1265 * txgbe_write_i2c_byte_unlocked - Writes 8 bit word over I2C
1266 * @hw: pointer to hardware structure
1267 * @byte_offset: byte offset to write
1268 * @dev_addr: address to write to
1269 * @data: value to write
1271 * Performs byte write operation to SFP module's EEPROM over I2C interface at
1272 * a specified device address.
1274 s32 txgbe_write_i2c_byte_unlocked(struct txgbe_hw *hw, u8 byte_offset,
1275 u8 dev_addr, u8 data)
1277 txgbe_i2c_start(hw, dev_addr);
1280 if (!po32m(hw, TXGBE_I2CICR, TXGBE_I2CICR_TXEMPTY,
1281 TXGBE_I2CICR_TXEMPTY, NULL, 100, 100)) {
1282 return -TERR_TIMEOUT;
1285 wr32(hw, TXGBE_I2CDATA, byte_offset | TXGBE_I2CDATA_STOP);
1286 wr32(hw, TXGBE_I2CDATA, data | TXGBE_I2CDATA_WRITE);
1288 /* wait for write complete */
1289 if (!po32m(hw, TXGBE_I2CICR, TXGBE_I2CICR_RXFULL,
1290 TXGBE_I2CICR_RXFULL, NULL, 100, 100)) {
1291 return -TERR_TIMEOUT;
1299 * txgbe_write_i2c_byte - Writes 8 bit word over I2C
1300 * @hw: pointer to hardware structure
1301 * @byte_offset: byte offset to write
1302 * @dev_addr: address to write to
1303 * @data: value to write
1305 * Performs byte write operation to SFP module's EEPROM over I2C interface at
1306 * a specified device address.
1308 s32 txgbe_write_i2c_byte(struct txgbe_hw *hw, u8 byte_offset,
1309 u8 dev_addr, u8 data)
1311 u32 swfw_mask = hw->phy.phy_semaphore_mask;
1314 if (hw->mac.acquire_swfw_sync(hw, swfw_mask))
1315 return TXGBE_ERR_SWFW_SYNC;
1316 err = txgbe_write_i2c_byte_unlocked(hw, byte_offset, dev_addr, data);
1317 hw->mac.release_swfw_sync(hw, swfw_mask);
1323 * txgbe_i2c_start - Sets I2C start condition
1324 * @hw: pointer to hardware structure
1326 * Sets I2C start condition (High -> Low on SDA while SCL is High)
1328 static void txgbe_i2c_start(struct txgbe_hw *hw, u8 dev_addr)
1330 wr32(hw, TXGBE_I2CENA, 0);
1332 wr32(hw, TXGBE_I2CCON,
1333 (TXGBE_I2CCON_MENA |
1334 TXGBE_I2CCON_SPEED(1) |
1335 TXGBE_I2CCON_RESTART |
1336 TXGBE_I2CCON_SDIA));
1337 wr32(hw, TXGBE_I2CTAR, dev_addr >> 1);
1338 wr32(hw, TXGBE_I2CSSSCLHCNT, 200);
1339 wr32(hw, TXGBE_I2CSSSCLLCNT, 200);
1340 wr32(hw, TXGBE_I2CRXTL, 0); /* 1byte for rx full signal */
1341 wr32(hw, TXGBE_I2CTXTL, 4);
1342 wr32(hw, TXGBE_I2CSCLTMOUT, 0xFFFFFF);
1343 wr32(hw, TXGBE_I2CSDATMOUT, 0xFFFFFF);
1345 wr32(hw, TXGBE_I2CICM, 0);
1346 wr32(hw, TXGBE_I2CENA, 1);
1350 * txgbe_i2c_stop - Sets I2C stop condition
1351 * @hw: pointer to hardware structure
1353 * Sets I2C stop condition (Low -> High on SDA while SCL is High)
1355 static void txgbe_i2c_stop(struct txgbe_hw *hw)
1357 /* wait for completion */
1358 if (!po32m(hw, TXGBE_I2CSTAT, TXGBE_I2CSTAT_MST,
1359 0, NULL, 100, 100)) {
1360 DEBUGOUT("i2c stop timeout.");
1363 wr32(hw, TXGBE_I2CENA, 0);
1367 txgbe_set_sgmii_an37_ability(struct txgbe_hw *hw)
1370 u8 device_type = hw->subsystem_device_id & 0xF0;
1372 wr32_epcs(hw, VR_XS_OR_PCS_MMD_DIGI_CTL1, 0x3002);
1373 /* for sgmii + external phy, set to 0x0105 (phy sgmii mode) */
1374 /* for sgmii direct link, set to 0x010c (mac sgmii mode) */
1375 if (device_type == TXGBE_DEV_ID_MAC_SGMII ||
1376 hw->phy.media_type == txgbe_media_type_fiber)
1377 wr32_epcs(hw, SR_MII_MMD_AN_CTL, 0x010C);
1378 else if (device_type == TXGBE_DEV_ID_SGMII ||
1379 device_type == TXGBE_DEV_ID_XAUI)
1380 wr32_epcs(hw, SR_MII_MMD_AN_CTL, 0x0105);
1381 wr32_epcs(hw, SR_MII_MMD_DIGI_CTL, 0x0200);
1382 value = rd32_epcs(hw, SR_MII_MMD_CTL);
1383 value = (value & ~0x1200) | (0x1 << 12) | (0x1 << 9);
1384 wr32_epcs(hw, SR_MII_MMD_CTL, value);
1388 txgbe_set_link_to_kr(struct txgbe_hw *hw, bool autoneg)
1394 /* 1. Wait xpcs power-up good */
1395 for (i = 0; i < 100; i++) {
1396 if ((rd32_epcs(hw, VR_XS_OR_PCS_MMD_DIGI_STATUS) &
1397 VR_XS_OR_PCS_MMD_DIGI_STATUS_PSEQ_MASK) ==
1398 VR_XS_OR_PCS_MMD_DIGI_STATUS_PSEQ_POWER_GOOD)
1403 err = TXGBE_ERR_XPCS_POWER_UP_FAILED;
1406 BP_LOG("It is set to kr.\n");
1408 wr32_epcs(hw, VR_AN_INTR_MSK, 0x7);
1409 wr32_epcs(hw, TXGBE_PHY_TX_POWER_ST_CTL, 0x00FC);
1410 wr32_epcs(hw, TXGBE_PHY_RX_POWER_ST_CTL, 0x00FC);
1413 /* 2. Disable xpcs AN-73 */
1414 wr32_epcs(hw, SR_AN_CTRL,
1415 SR_AN_CTRL_AN_EN | SR_AN_CTRL_EXT_NP);
1417 wr32_epcs(hw, VR_AN_KR_MODE_CL, VR_AN_KR_MODE_CL_PDET);
1419 if (!(hw->devarg.auto_neg == 1)) {
1420 wr32_epcs(hw, SR_AN_CTRL, 0);
1421 wr32_epcs(hw, VR_AN_KR_MODE_CL, 0);
1423 value = rd32_epcs(hw, TXGBE_PHY_TX_EQ_CTL1);
1425 wr32_epcs(hw, TXGBE_PHY_TX_EQ_CTL1, value);
1427 if (hw->devarg.present == 1) {
1428 value = rd32_epcs(hw, TXGBE_PHY_TX_EQ_CTL1);
1429 value |= TXGBE_PHY_TX_EQ_CTL1_DEF;
1430 wr32_epcs(hw, TXGBE_PHY_TX_EQ_CTL1, value);
1432 if (hw->devarg.poll == 1) {
1433 wr32_epcs(hw, VR_PMA_KRTR_TIMER_CTRL0,
1434 VR_PMA_KRTR_TIMER_MAX_WAIT);
1435 wr32_epcs(hw, VR_PMA_KRTR_TIMER_CTRL2, 0xA697);
1438 /* 3. Set VR_XS_PMA_Gen5_12G_MPLLA_CTRL3 Register
1439 * Bit[10:0](MPLLA_BANDWIDTH) = 11'd123 (default: 11'd16)
1441 wr32_epcs(hw, TXGBE_PHY_MPLLA_CTL3,
1442 TXGBE_PHY_MPLLA_CTL3_MULTIPLIER_BW_10GBASER_KR);
1444 /* 4. Set VR_XS_PMA_Gen5_12G_MISC_CTRL0 Register
1445 * Bit[12:8](RX_VREF_CTRL) = 5'hF (default: 5'h11)
1447 wr32_epcs(hw, TXGBE_PHY_MISC_CTL0, 0xCF00);
1449 /* 5. Set VR_XS_PMA_Gen5_12G_RX_EQ_CTRL0 Register
1450 * Bit[15:8](VGA1/2_GAIN_0) = 8'h77
1451 * Bit[7:5](CTLE_POLE_0) = 3'h2
1452 * Bit[4:0](CTLE_BOOST_0) = 4'hA
1454 wr32_epcs(hw, TXGBE_PHY_RX_EQ_CTL0, 0x774A);
1456 /* 6. Set VR_MII_Gen5_12G_RX_GENCTRL3 Register
1457 * Bit[2:0](LOS_TRSHLD_0) = 3'h4 (default: 3)
1459 wr32_epcs(hw, TXGBE_PHY_RX_GEN_CTL3, 0x0004);
1461 /* 7. Initialize the mode by setting VR XS or PCS MMD Digital
1462 * Control1 Register Bit[15](VR_RST)
1464 wr32_epcs(hw, VR_XS_OR_PCS_MMD_DIGI_CTL1, 0xA000);
1466 /* Wait phy initialization done */
1467 for (i = 0; i < 100; i++) {
1469 VR_XS_OR_PCS_MMD_DIGI_CTL1) &
1470 VR_XS_OR_PCS_MMD_DIGI_CTL1_VR_RST) == 0)
1475 err = TXGBE_ERR_PHY_INIT_NOT_DONE;
1479 wr32_epcs(hw, VR_AN_KR_MODE_CL, 0x1);
1482 if (hw->phy.ffe_set == TXGBE_BP_M_KR) {
1483 value = (0x1804 & ~0x3F3F);
1484 value |= hw->phy.ffe_main << 8 | hw->phy.ffe_pre;
1485 wr32_epcs(hw, TXGBE_PHY_TX_EQ_CTL0, value);
1487 value = (0x50 & ~0x7F) | (1 << 6) | hw->phy.ffe_post;
1488 wr32_epcs(hw, TXGBE_PHY_TX_EQ_CTL1, value);
1495 txgbe_set_link_to_kx4(struct txgbe_hw *hw, bool autoneg)
1501 /* Check link status, if already set, skip setting it again */
1502 if (hw->link_status == TXGBE_LINK_STATUS_KX4)
1505 BP_LOG("It is set to kx4.\n");
1506 wr32_epcs(hw, TXGBE_PHY_TX_POWER_ST_CTL, 0);
1507 wr32_epcs(hw, TXGBE_PHY_RX_POWER_ST_CTL, 0);
1509 /* 1. Wait xpcs power-up good */
1510 for (i = 0; i < 100; i++) {
1511 if ((rd32_epcs(hw, VR_XS_OR_PCS_MMD_DIGI_STATUS) &
1512 VR_XS_OR_PCS_MMD_DIGI_STATUS_PSEQ_MASK) ==
1513 VR_XS_OR_PCS_MMD_DIGI_STATUS_PSEQ_POWER_GOOD)
1518 err = TXGBE_ERR_XPCS_POWER_UP_FAILED;
1522 wr32m(hw, TXGBE_MACTXCFG, TXGBE_MACTXCFG_TXE,
1523 ~TXGBE_MACTXCFG_TXE);
1525 /* 2. Disable xpcs AN-73 */
1527 wr32_epcs(hw, SR_AN_CTRL, 0x0);
1529 wr32_epcs(hw, SR_AN_CTRL, 0x3000);
1531 /* Disable PHY MPLLA for eth mode change(after ECO) */
1532 wr32_ephy(hw, 0x4, 0x250A);
1536 /* Set the eth change_mode bit first in mis_rst register
1537 * for corresponding LAN port
1539 wr32(hw, TXGBE_RST, TXGBE_RST_ETH(hw->bus.lan_id));
1541 /* Set SR PCS Control2 Register Bits[1:0] = 2'b01
1542 * PCS_TYPE_SEL: non KR
1544 wr32_epcs(hw, SR_XS_PCS_CTRL2,
1545 SR_PCS_CTRL2_TYPE_SEL_X);
1547 /* Set SR PMA MMD Control1 Register Bit[13] = 1'b1
1550 wr32_epcs(hw, SR_PMA_CTRL1,
1551 SR_PMA_CTRL1_SS13_KX4);
1553 value = (0xf5f0 & ~0x7F0) | (0x5 << 8) | (0x7 << 5) | 0xF0;
1554 wr32_epcs(hw, TXGBE_PHY_TX_GENCTRL1, value);
1556 if ((hw->subsystem_device_id & 0xFF) == TXGBE_DEV_ID_MAC_XAUI)
1557 wr32_epcs(hw, TXGBE_PHY_MISC_CTL0, 0xCF00);
1559 wr32_epcs(hw, TXGBE_PHY_MISC_CTL0, 0x4F00);
1561 for (i = 0; i < 4; i++) {
1563 value = (0x45 & ~0xFFFF) | (0x7 << 12) |
1566 value = (0xff06 & ~0xFFFF) | (0x7 << 12) |
1568 wr32_epcs(hw, TXGBE_PHY_RX_EQ_CTL0 + i, value);
1571 value = 0x0 & ~0x7777;
1572 wr32_epcs(hw, TXGBE_PHY_RX_EQ_ATT_LVL0, value);
1574 wr32_epcs(hw, TXGBE_PHY_DFE_TAP_CTL0, 0x0);
1576 value = (0x6db & ~0xFFF) | (0x1 << 9) | (0x1 << 6) | (0x1 << 3) | 0x1;
1577 wr32_epcs(hw, TXGBE_PHY_RX_GEN_CTL3, value);
1579 /* Set VR XS, PMA, or MII Gen5 12G PHY MPLLA
1580 * Control 0 Register Bit[7:0] = 8'd40 //MPLLA_MULTIPLIER
1582 wr32_epcs(hw, TXGBE_PHY_MPLLA_CTL0,
1583 TXGBE_PHY_MPLLA_CTL0_MULTIPLIER_OTHER);
1585 /* Set VR XS, PMA or MII Gen5 12G PHY MPLLA
1586 * Control 3 Register Bit[10:0] = 11'd86 //MPLLA_BANDWIDTH
1588 wr32_epcs(hw, TXGBE_PHY_MPLLA_CTL3,
1589 TXGBE_PHY_MPLLA_CTL3_MULTIPLIER_BW_OTHER);
1591 /* Set VR XS, PMA, or MII Gen5 12G PHY VCO
1592 * Calibration Load 0 Register Bit[12:0] = 13'd1360 //VCO_LD_VAL_0
1594 wr32_epcs(hw, TXGBE_PHY_VCO_CAL_LD0,
1595 TXGBE_PHY_VCO_CAL_LD0_OTHER);
1597 /* Set VR XS, PMA, or MII Gen5 12G PHY VCO
1598 * Calibration Load 1 Register Bit[12:0] = 13'd1360 //VCO_LD_VAL_1
1600 wr32_epcs(hw, TXGBE_PHY_VCO_CAL_LD1,
1601 TXGBE_PHY_VCO_CAL_LD0_OTHER);
1603 /* Set VR XS, PMA, or MII Gen5 12G PHY VCO
1604 * Calibration Load 2 Register Bit[12:0] = 13'd1360 //VCO_LD_VAL_2
1606 wr32_epcs(hw, TXGBE_PHY_VCO_CAL_LD2,
1607 TXGBE_PHY_VCO_CAL_LD0_OTHER);
1608 /* Set VR XS, PMA, or MII Gen5 12G PHY VCO
1609 * Calibration Load 3 Register Bit[12:0] = 13'd1360 //VCO_LD_VAL_3
1611 wr32_epcs(hw, TXGBE_PHY_VCO_CAL_LD3,
1612 TXGBE_PHY_VCO_CAL_LD0_OTHER);
1613 /* Set VR XS, PMA, or MII Gen5 12G PHY VCO
1614 * Calibration Reference 0 Register Bit[5:0] = 6'd34 //VCO_REF_LD_0/1
1616 wr32_epcs(hw, TXGBE_PHY_VCO_CAL_REF0, 0x2222);
1618 /* Set VR XS, PMA, or MII Gen5 12G PHY VCO
1619 * Calibration Reference 1 Register Bit[5:0] = 6'd34 //VCO_REF_LD_2/3
1621 wr32_epcs(hw, TXGBE_PHY_VCO_CAL_REF1, 0x2222);
1623 /* Set VR XS, PMA, or MII Gen5 12G PHY AFE-DFE
1624 * Enable Register Bit[7:0] = 8'd0 //AFE_EN_0/3_1, DFE_EN_0/3_1
1626 wr32_epcs(hw, TXGBE_PHY_AFE_DFE_ENABLE, 0x0);
1628 /* Set VR XS, PMA, or MII Gen5 12G PHY Rx
1629 * Equalization Control 4 Register Bit[3:0] = 4'd0 //CONT_ADAPT_0/3_1
1631 wr32_epcs(hw, TXGBE_PHY_RX_EQ_CTL, 0x00F0);
1633 /* Set VR XS, PMA, or MII Gen5 12G PHY Tx Rate
1634 * Control Register Bit[14:12], Bit[10:8], Bit[6:4], Bit[2:0],
1635 * all rates to 3'b010 //TX0/1/2/3_RATE
1637 wr32_epcs(hw, TXGBE_PHY_TX_RATE_CTL, 0x2222);
1639 /* Set VR XS, PMA, or MII Gen5 12G PHY Rx Rate
1640 * Control Register Bit[13:12], Bit[9:8], Bit[5:4], Bit[1:0],
1641 * all rates to 2'b10 //RX0/1/2/3_RATE
1643 wr32_epcs(hw, TXGBE_PHY_RX_RATE_CTL, 0x2222);
1645 /* Set VR XS, PMA, or MII Gen5 12G PHY Tx General
1646 * Control 2 Register Bit[15:8] = 2'b01 //TX0/1/2/3_WIDTH: 10bits
1648 wr32_epcs(hw, TXGBE_PHY_TX_GEN_CTL2, 0x5500);
1650 /* Set VR XS, PMA, or MII Gen5 12G PHY Rx General
1651 * Control 2 Register Bit[15:8] = 2'b01 //RX0/1/2/3_WIDTH: 10bits
1653 wr32_epcs(hw, TXGBE_PHY_RX_GEN_CTL2, 0x5500);
1655 /* Set VR XS, PMA, or MII Gen5 12G PHY MPLLA Control
1656 * 2 Register Bit[10:8] = 3'b010
1657 * MPLLA_DIV16P5_CLK_EN=0, MPLLA_DIV10_CLK_EN=1, MPLLA_DIV8_CLK_EN=0
1659 wr32_epcs(hw, TXGBE_PHY_MPLLA_CTL2,
1660 TXGBE_PHY_MPLLA_CTL2_DIV_CLK_EN_10);
1662 wr32_epcs(hw, 0x1f0000, 0x0);
1663 wr32_epcs(hw, 0x1f8001, 0x0);
1664 wr32_epcs(hw, SR_MII_MMD_DIGI_CTL, 0x0);
1666 /* 10. Initialize the mode by setting VR XS or PCS MMD Digital Control1
1667 * Register Bit[15](VR_RST)
1669 wr32_epcs(hw, VR_XS_OR_PCS_MMD_DIGI_CTL1, 0xA000);
1671 /* Wait phy initialization done */
1672 for (i = 0; i < 100; i++) {
1673 if ((rd32_epcs(hw, VR_XS_OR_PCS_MMD_DIGI_CTL1) &
1674 VR_XS_OR_PCS_MMD_DIGI_CTL1_VR_RST) == 0)
1679 /* If success, set link status */
1680 hw->link_status = TXGBE_LINK_STATUS_KX4;
1683 err = TXGBE_ERR_PHY_INIT_NOT_DONE;
1687 if (hw->phy.ffe_set == TXGBE_BP_M_KX4) {
1688 value = (0x1804 & ~0x3F3F);
1689 value |= hw->phy.ffe_main << 8 | hw->phy.ffe_pre;
1690 wr32_epcs(hw, TXGBE_PHY_TX_EQ_CTL0, value);
1692 value = (0x50 & ~0x7F) | (1 << 6) | hw->phy.ffe_post;
1693 wr32_epcs(hw, TXGBE_PHY_TX_EQ_CTL1, value);
1694 } else if (hw->fw_version <= TXGBE_FW_N_TXEQ) {
1695 value = (0x1804 & ~0x3F3F);
1696 wr32_epcs(hw, TXGBE_PHY_TX_EQ_CTL0, value);
1698 value = (0x50 & ~0x7F) | 40 | (1 << 6);
1699 wr32_epcs(hw, TXGBE_PHY_TX_EQ_CTL1, value);
1706 txgbe_set_link_to_kx(struct txgbe_hw *hw,
1715 /* Check link status, if already set, skip setting it again */
1716 if (hw->link_status == TXGBE_LINK_STATUS_KX)
1719 BP_LOG("It is set to kx. speed =0x%x\n", speed);
1720 wr32_epcs(hw, TXGBE_PHY_TX_POWER_ST_CTL, 0x00FC);
1721 wr32_epcs(hw, TXGBE_PHY_RX_POWER_ST_CTL, 0x00FC);
1723 /* 1. Wait xpcs power-up good */
1724 for (i = 0; i < 100; i++) {
1725 if ((rd32_epcs(hw, VR_XS_OR_PCS_MMD_DIGI_STATUS) &
1726 VR_XS_OR_PCS_MMD_DIGI_STATUS_PSEQ_MASK) ==
1727 VR_XS_OR_PCS_MMD_DIGI_STATUS_PSEQ_POWER_GOOD)
1732 err = TXGBE_ERR_XPCS_POWER_UP_FAILED;
1736 wr32m(hw, TXGBE_MACTXCFG, TXGBE_MACTXCFG_TXE,
1737 ~TXGBE_MACTXCFG_TXE);
1739 /* 2. Disable xpcs AN-73 */
1741 wr32_epcs(hw, SR_AN_CTRL, 0x0);
1743 wr32_epcs(hw, SR_AN_CTRL, 0x3000);
1745 /* Disable PHY MPLLA for eth mode change(after ECO) */
1746 wr32_ephy(hw, 0x4, 0x240A);
1750 /* Set the eth change_mode bit first in mis_rst register
1751 * for corresponding LAN port
1753 wr32(hw, TXGBE_RST, TXGBE_RST_ETH(hw->bus.lan_id));
1755 /* Set SR PCS Control2 Register Bits[1:0] = 2'b01
1756 * PCS_TYPE_SEL: non KR
1758 wr32_epcs(hw, SR_XS_PCS_CTRL2,
1759 SR_PCS_CTRL2_TYPE_SEL_X);
1761 /* Set SR PMA MMD Control1 Register Bit[13] = 1'b0
1764 wr32_epcs(hw, SR_PMA_CTRL1,
1765 SR_PMA_CTRL1_SS13_KX);
1767 /* Set SR MII MMD Control Register to corresponding speed: {Bit[6],
1768 * Bit[13]}=[2'b00,2'b01,2'b10]->[10M,100M,1G]
1770 if (speed == TXGBE_LINK_SPEED_100M_FULL)
1772 else if (speed == TXGBE_LINK_SPEED_1GB_FULL)
1774 else if (speed == TXGBE_LINK_SPEED_10M_FULL)
1776 wr32_epcs(hw, SR_MII_MMD_CTL,
1779 value = (0xf5f0 & ~0x710) | (0x5 << 8) | 0x10;
1780 wr32_epcs(hw, TXGBE_PHY_TX_GENCTRL1, value);
1782 if (hw->devarg.sgmii == 1)
1783 wr32_epcs(hw, TXGBE_PHY_MISC_CTL0, 0x4F00);
1785 wr32_epcs(hw, TXGBE_PHY_MISC_CTL0, 0xCF00);
1787 for (i = 0; i < 4; i++) {
1791 value = (0x45 & ~0xFFFF) | (0x7 << 12) |
1794 wr32_epcs(hw, TXGBE_PHY_RX_EQ_CTL0 + i, value);
1798 wr32_epcs(hw, TXGBE_PHY_RX_EQ_ATT_LVL0, value);
1800 wr32_epcs(hw, TXGBE_PHY_DFE_TAP_CTL0, 0x0);
1802 value = (0x6db & ~0x7) | 0x4;
1803 wr32_epcs(hw, TXGBE_PHY_RX_GEN_CTL3, value);
1805 /* Set VR XS, PMA, or MII Gen5 12G PHY MPLLA Control
1806 * 0 Register Bit[7:0] = 8'd32 //MPLLA_MULTIPLIER
1808 wr32_epcs(hw, TXGBE_PHY_MPLLA_CTL0,
1809 TXGBE_PHY_MPLLA_CTL0_MULTIPLIER_1GBASEX_KX);
1811 /* Set VR XS, PMA or MII Gen5 12G PHY MPLLA Control
1812 * 3 Register Bit[10:0] = 11'd70 //MPLLA_BANDWIDTH
1814 wr32_epcs(hw, TXGBE_PHY_MPLLA_CTL3,
1815 TXGBE_PHY_MPLLA_CTL3_MULTIPLIER_BW_1GBASEX_KX);
1817 /* Set VR XS, PMA, or MII Gen5 12G PHY VCO
1818 * Calibration Load 0 Register Bit[12:0] = 13'd1344 //VCO_LD_VAL_0
1820 wr32_epcs(hw, TXGBE_PHY_VCO_CAL_LD0,
1821 TXGBE_PHY_VCO_CAL_LD0_1GBASEX_KX);
1823 wr32_epcs(hw, TXGBE_PHY_VCO_CAL_LD1, 0x549);
1824 wr32_epcs(hw, TXGBE_PHY_VCO_CAL_LD2, 0x549);
1825 wr32_epcs(hw, TXGBE_PHY_VCO_CAL_LD3, 0x549);
1827 /* Set VR XS, PMA, or MII Gen5 12G PHY VCO
1828 * Calibration Reference 0 Register Bit[5:0] = 6'd42 //VCO_REF_LD_0
1830 wr32_epcs(hw, TXGBE_PHY_VCO_CAL_REF0,
1831 TXGBE_PHY_VCO_CAL_REF0_LD0_1GBASEX_KX);
1833 wr32_epcs(hw, TXGBE_PHY_VCO_CAL_REF1, 0x2929);
1835 /* Set VR XS, PMA, or MII Gen5 12G PHY AFE-DFE
1836 * Enable Register Bit[4], Bit[0] = 1'b0 //AFE_EN_0, DFE_EN_0
1838 wr32_epcs(hw, TXGBE_PHY_AFE_DFE_ENABLE,
1840 /* Set VR XS, PMA, or MII Gen5 12G PHY Rx
1841 * Equalization Control 4 Register Bit[0] = 1'b0 //CONT_ADAPT_0
1843 wr32_epcs(hw, TXGBE_PHY_RX_EQ_CTL,
1845 /* Set VR XS, PMA, or MII Gen5 12G PHY Tx Rate
1846 * Control Register Bit[2:0] = 3'b011 //TX0_RATE
1848 wr32_epcs(hw, TXGBE_PHY_TX_RATE_CTL,
1849 TXGBE_PHY_TX_RATE_CTL_TX0_RATE_1GBASEX_KX);
1851 /* Set VR XS, PMA, or MII Gen5 12G PHY Rx Rate
1852 * Control Register Bit[2:0] = 3'b011 //RX0_RATE
1854 wr32_epcs(hw, TXGBE_PHY_RX_RATE_CTL,
1855 TXGBE_PHY_RX_RATE_CTL_RX0_RATE_1GBASEX_KX);
1857 /* Set VR XS, PMA, or MII Gen5 12G PHY Tx General
1858 * Control 2 Register Bit[9:8] = 2'b01 //TX0_WIDTH: 10bits
1860 wr32_epcs(hw, TXGBE_PHY_TX_GEN_CTL2,
1861 TXGBE_PHY_TX_GEN_CTL2_TX0_WIDTH_OTHER);
1862 /* Set VR XS, PMA, or MII Gen5 12G PHY Rx General
1863 * Control 2 Register Bit[9:8] = 2'b01 //RX0_WIDTH: 10bits
1865 wr32_epcs(hw, TXGBE_PHY_RX_GEN_CTL2,
1866 TXGBE_PHY_RX_GEN_CTL2_RX0_WIDTH_OTHER);
1867 /* Set VR XS, PMA, or MII Gen5 12G PHY MPLLA Control
1868 * 2 Register Bit[10:8] = 3'b010 //MPLLA_DIV16P5_CLK_EN=0,
1869 * MPLLA_DIV10_CLK_EN=1, MPLLA_DIV8_CLK_EN=0
1871 wr32_epcs(hw, TXGBE_PHY_MPLLA_CTL2,
1872 TXGBE_PHY_MPLLA_CTL2_DIV_CLK_EN_10);
1874 /* VR MII MMD AN Control Register Bit[8] = 1'b1 //MII_CTRL
1875 * Set to 8bit MII (required in 10M/100M SGMII)
1877 wr32_epcs(hw, SR_MII_MMD_AN_CTL,
1880 /* 10. Initialize the mode by setting VR XS or PCS MMD Digital Control1
1881 * Register Bit[15](VR_RST)
1883 wr32_epcs(hw, VR_XS_OR_PCS_MMD_DIGI_CTL1, 0xA000);
1885 /* Wait phy initialization done */
1886 for (i = 0; i < 100; i++) {
1887 if ((rd32_epcs(hw, VR_XS_OR_PCS_MMD_DIGI_CTL1) &
1888 VR_XS_OR_PCS_MMD_DIGI_CTL1_VR_RST) == 0)
1893 /* If success, set link status */
1894 hw->link_status = TXGBE_LINK_STATUS_KX;
1897 err = TXGBE_ERR_PHY_INIT_NOT_DONE;
1901 if (hw->phy.ffe_set == TXGBE_BP_M_KX) {
1902 value = rd32_epcs(hw, TXGBE_PHY_TX_EQ_CTL0) & ~0x3F3F;
1903 value |= hw->phy.ffe_main << 8 | hw->phy.ffe_pre;
1904 wr32_epcs(hw, TXGBE_PHY_TX_EQ_CTL0, value);
1906 value = rd32_epcs(hw, TXGBE_PHY_TX_EQ_CTL0) & ~0x7F;
1907 value |= hw->phy.ffe_post | (1 << 6);
1908 wr32_epcs(hw, TXGBE_PHY_TX_EQ_CTL1, value);
1909 } else if (hw->fw_version <= TXGBE_FW_N_TXEQ) {
1910 value = (0x1804 & ~0x3F3F) | (24 << 8) | 4;
1911 wr32_epcs(hw, TXGBE_PHY_TX_EQ_CTL0, value);
1913 value = (0x50 & ~0x7F) | 16 | (1 << 6);
1914 wr32_epcs(hw, TXGBE_PHY_TX_EQ_CTL1, value);
1921 txgbe_set_link_to_sfi(struct txgbe_hw *hw,
1928 /* Set the module link speed */
1929 hw->mac.set_rate_select_speed(hw, speed);
1930 /* 1. Wait xpcs power-up good */
1931 for (i = 0; i < 100; i++) {
1932 if ((rd32_epcs(hw, VR_XS_OR_PCS_MMD_DIGI_STATUS) &
1933 VR_XS_OR_PCS_MMD_DIGI_STATUS_PSEQ_MASK) ==
1934 VR_XS_OR_PCS_MMD_DIGI_STATUS_PSEQ_POWER_GOOD)
1939 err = TXGBE_ERR_XPCS_POWER_UP_FAILED;
1943 wr32m(hw, TXGBE_MACTXCFG, TXGBE_MACTXCFG_TXE,
1944 ~TXGBE_MACTXCFG_TXE);
1946 /* 2. Disable xpcs AN-73 */
1947 wr32_epcs(hw, SR_AN_CTRL, 0x0);
1949 /* Disable PHY MPLLA for eth mode change(after ECO) */
1950 wr32_ephy(hw, 0x4, 0x243A);
1953 /* Set the eth change_mode bit first in mis_rst register
1954 * for corresponding LAN port
1956 wr32(hw, TXGBE_RST, TXGBE_RST_ETH(hw->bus.lan_id));
1958 if (speed == TXGBE_LINK_SPEED_10GB_FULL) {
1959 /* Set SR PCS Control2 Register Bits[1:0] = 2'b00
1962 wr32_epcs(hw, SR_XS_PCS_CTRL2, 0);
1963 value = rd32_epcs(hw, SR_PMA_CTRL1);
1964 value = value | 0x2000;
1965 wr32_epcs(hw, SR_PMA_CTRL1, value);
1966 /* Set VR_XS_PMA_Gen5_12G_MPLLA_CTRL0 Register Bit[7:0] = 8'd33
1969 wr32_epcs(hw, TXGBE_PHY_MPLLA_CTL0, 0x0021);
1970 /* 3. Set VR_XS_PMA_Gen5_12G_MPLLA_CTRL3 Register
1971 * Bit[10:0](MPLLA_BANDWIDTH) = 11'd0
1973 wr32_epcs(hw, TXGBE_PHY_MPLLA_CTL3, 0);
1974 value = rd32_epcs(hw, TXGBE_PHY_TX_GENCTRL1);
1975 value = (value & ~0x700) | 0x500;
1976 wr32_epcs(hw, TXGBE_PHY_TX_GENCTRL1, value);
1977 /* 4. Set VR_XS_PMA_Gen5_12G_MISC_CTRL0 Register
1978 * Bit[12:8](RX_VREF_CTRL) = 5'hF
1980 wr32_epcs(hw, TXGBE_PHY_MISC_CTL0, 0xCF00);
1981 /* Set VR_XS_PMA_Gen5_12G_VCO_CAL_LD0 Register
1982 * Bit[12:0] = 13'd1353 //VCO_LD_VAL_0
1984 wr32_epcs(hw, TXGBE_PHY_VCO_CAL_LD0, 0x0549);
1985 /* Set VR_XS_PMA_Gen5_12G_VCO_CAL_REF0 Register
1986 * Bit[5:0] = 6'd41 //VCO_REF_LD_0
1988 wr32_epcs(hw, TXGBE_PHY_VCO_CAL_REF0, 0x0029);
1989 /* Set VR_XS_PMA_Gen5_12G_TX_RATE_CTRL Register
1990 * Bit[2:0] = 3'b000 //TX0_RATE
1992 wr32_epcs(hw, TXGBE_PHY_TX_RATE_CTL, 0);
1993 /* Set VR_XS_PMA_Gen5_12G_RX_RATE_CTRL Register
1994 * Bit[2:0] = 3'b000 //RX0_RATE
1996 wr32_epcs(hw, TXGBE_PHY_RX_RATE_CTL, 0);
1997 /* Set VR_XS_PMA_Gen5_12G_TX_GENCTRL2 Register Bit[9:8] = 2'b11
2000 wr32_epcs(hw, TXGBE_PHY_TX_GEN_CTL2, 0x0300);
2001 /* Set VR_XS_PMA_Gen5_12G_RX_GENCTRL2 Register Bit[9:8] = 2'b11
2004 wr32_epcs(hw, TXGBE_PHY_RX_GEN_CTL2, 0x0300);
2005 /* Set VR_XS_PMA_Gen5_12G_MPLLA_CTRL2 Register
2006 * Bit[10:8] = 3'b110
2007 * MPLLA_DIV16P5_CLK_EN=1
2008 * MPLLA_DIV10_CLK_EN=1
2009 * MPLLA_DIV8_CLK_EN=0
2011 wr32_epcs(hw, TXGBE_PHY_MPLLA_CTL2, 0x0600);
2013 if (hw->phy.sfp_type == txgbe_sfp_type_da_cu_core0 ||
2014 hw->phy.sfp_type == txgbe_sfp_type_da_cu_core1) {
2015 /* 7. Set VR_XS_PMA_Gen5_12G_RX_EQ_CTRL0 Register
2016 * Bit[15:8](VGA1/2_GAIN_0) = 8'h77
2017 * Bit[7:5](CTLE_POLE_0) = 3'h2
2018 * Bit[4:0](CTLE_BOOST_0) = 4'hF
2020 wr32_epcs(hw, TXGBE_PHY_RX_EQ_CTL0, 0x774F);
2023 /* 7. Set VR_XS_PMA_Gen5_12G_RX_EQ_CTRL0 Register
2024 * Bit[15:8](VGA1/2_GAIN_0) = 8'h00
2025 * Bit[7:5](CTLE_POLE_0) = 3'h2
2026 * Bit[4:0](CTLE_BOOST_0) = 4'hA
2028 value = rd32_epcs(hw, TXGBE_PHY_RX_EQ_CTL0);
2029 value = (value & ~0xFFFF) | (2 << 5) | 0x05;
2030 wr32_epcs(hw, TXGBE_PHY_RX_EQ_CTL0, value);
2032 value = rd32_epcs(hw, TXGBE_PHY_RX_EQ_ATT_LVL0);
2033 value = (value & ~0x7) | 0x0;
2034 wr32_epcs(hw, TXGBE_PHY_RX_EQ_ATT_LVL0, value);
2036 if (hw->phy.sfp_type == txgbe_sfp_type_da_cu_core0 ||
2037 hw->phy.sfp_type == txgbe_sfp_type_da_cu_core1) {
2038 /* 8. Set VR_XS_PMA_Gen5_12G_DFE_TAP_CTRL0 Register
2039 * Bit[7:0](DFE_TAP1_0) = 8'd20
2041 wr32_epcs(hw, TXGBE_PHY_DFE_TAP_CTL0, 0x0014);
2042 value = rd32_epcs(hw, TXGBE_PHY_AFE_DFE_ENABLE);
2043 value = (value & ~0x11) | 0x11;
2044 wr32_epcs(hw, TXGBE_PHY_AFE_DFE_ENABLE, value);
2046 /* 8. Set VR_XS_PMA_Gen5_12G_DFE_TAP_CTRL0 Register
2047 * Bit[7:0](DFE_TAP1_0) = 8'd20
2049 wr32_epcs(hw, TXGBE_PHY_DFE_TAP_CTL0, 0xBE);
2050 /* 9. Set VR_MII_Gen5_12G_AFE_DFE_EN_CTRL Register
2051 * Bit[4](DFE_EN_0) = 1'b0, Bit[0](AFE_EN_0) = 1'b0
2053 value = rd32_epcs(hw, TXGBE_PHY_AFE_DFE_ENABLE);
2054 value = (value & ~0x11) | 0x0;
2055 wr32_epcs(hw, TXGBE_PHY_AFE_DFE_ENABLE, value);
2057 value = rd32_epcs(hw, TXGBE_PHY_RX_EQ_CTL);
2058 value = value & ~0x1;
2059 wr32_epcs(hw, TXGBE_PHY_RX_EQ_CTL, value);
2061 /* Set SR PCS Control2 Register Bits[1:0] = 2'b00
2064 wr32_epcs(hw, SR_XS_PCS_CTRL2, 0x1);
2065 /* Set SR PMA MMD Control1 Register Bit[13] = 1'b0
2068 wr32_epcs(hw, SR_PMA_CTRL1, 0x0000);
2069 /* Set SR MII MMD Control Register to corresponding speed */
2070 wr32_epcs(hw, SR_MII_MMD_CTL, 0x0140);
2072 value = rd32_epcs(hw, TXGBE_PHY_TX_GENCTRL1);
2073 value = (value & ~0x710) | 0x500;
2074 wr32_epcs(hw, TXGBE_PHY_TX_GENCTRL1, value);
2075 /* 4. Set VR_XS_PMA_Gen5_12G_MISC_CTRL0 Register
2076 * Bit[12:8](RX_VREF_CTRL) = 5'hF
2078 wr32_epcs(hw, TXGBE_PHY_MISC_CTL0, 0xCF00);
2080 if (hw->phy.sfp_type == txgbe_sfp_type_da_cu_core0 ||
2081 hw->phy.sfp_type == txgbe_sfp_type_da_cu_core1) {
2082 wr32_epcs(hw, TXGBE_PHY_RX_EQ_CTL0, 0x774F);
2084 /* 7. Set VR_XS_PMA_Gen5_12G_RX_EQ_CTRL0 Register
2085 * Bit[15:8](VGA1/2_GAIN_0) = 8'h00
2086 * Bit[7:5](CTLE_POLE_0) = 3'h2
2087 * Bit[4:0](CTLE_BOOST_0) = 4'hA
2089 value = rd32_epcs(hw, TXGBE_PHY_RX_EQ_CTL0);
2090 value = (value & ~0xFFFF) | 0x7706;
2091 wr32_epcs(hw, TXGBE_PHY_RX_EQ_CTL0, value);
2093 value = rd32_epcs(hw, TXGBE_PHY_RX_EQ_ATT_LVL0);
2094 value = (value & ~0x7) | 0x0;
2095 wr32_epcs(hw, TXGBE_PHY_RX_EQ_ATT_LVL0, value);
2096 /* 8. Set VR_XS_PMA_Gen5_12G_DFE_TAP_CTRL0 Register
2097 * Bit[7:0](DFE_TAP1_0) = 8'd00
2099 wr32_epcs(hw, TXGBE_PHY_DFE_TAP_CTL0, 0x0);
2100 /* 9. Set VR_MII_Gen5_12G_AFE_DFE_EN_CTRL Register
2101 * Bit[4](DFE_EN_0) = 1'b0, Bit[0](AFE_EN_0) = 1'b0
2103 value = rd32_epcs(hw, TXGBE_PHY_RX_GEN_CTL3);
2104 value = (value & ~0x7) | 0x4;
2105 wr32_epcs(hw, TXGBE_PHY_RX_GEN_CTL3, value);
2106 wr32_epcs(hw, TXGBE_PHY_MPLLA_CTL0, 0x0020);
2107 wr32_epcs(hw, TXGBE_PHY_MPLLA_CTL3, 0x0046);
2108 wr32_epcs(hw, TXGBE_PHY_VCO_CAL_LD0, 0x0540);
2109 wr32_epcs(hw, TXGBE_PHY_VCO_CAL_REF0, 0x002A);
2110 wr32_epcs(hw, TXGBE_PHY_AFE_DFE_ENABLE, 0x0);
2111 wr32_epcs(hw, TXGBE_PHY_RX_EQ_CTL, 0x0010);
2112 wr32_epcs(hw, TXGBE_PHY_TX_RATE_CTL, 0x0003);
2113 wr32_epcs(hw, TXGBE_PHY_RX_RATE_CTL, 0x0003);
2114 wr32_epcs(hw, TXGBE_PHY_TX_GEN_CTL2, 0x0100);
2115 wr32_epcs(hw, TXGBE_PHY_RX_GEN_CTL2, 0x0100);
2116 wr32_epcs(hw, TXGBE_PHY_MPLLA_CTL2, 0x0200);
2117 wr32_epcs(hw, SR_MII_MMD_AN_CTL, 0x0100);
2119 /* 10. Initialize the mode by setting VR XS or PCS MMD Digital Control1
2120 * Register Bit[15](VR_RST)
2122 wr32_epcs(hw, VR_XS_OR_PCS_MMD_DIGI_CTL1, 0xA000);
2124 /* Wait phy initialization done */
2125 for (i = 0; i < 100; i++) {
2126 if ((rd32_epcs(hw, VR_XS_OR_PCS_MMD_DIGI_CTL1) &
2127 VR_XS_OR_PCS_MMD_DIGI_CTL1_VR_RST) == 0)
2132 err = TXGBE_ERR_PHY_INIT_NOT_DONE;
2136 if (hw->phy.ffe_set == TXGBE_BP_M_SFI) {
2137 value = rd32_epcs(hw, TXGBE_PHY_TX_EQ_CTL0) & ~0x3F3F;
2138 value |= hw->phy.ffe_main << 8 | hw->phy.ffe_pre;
2139 wr32_epcs(hw, TXGBE_PHY_TX_EQ_CTL0, value);
2141 value = rd32_epcs(hw, TXGBE_PHY_TX_EQ_CTL0) & ~0x7F;
2142 value |= hw->phy.ffe_post | (1 << 6);
2143 wr32_epcs(hw, TXGBE_PHY_TX_EQ_CTL1, value);
2144 } else if (hw->fw_version <= TXGBE_FW_N_TXEQ) {
2145 value = rd32_epcs(hw, TXGBE_PHY_TX_EQ_CTL0);
2146 value = (value & ~0x3F3F) | (24 << 8) | 4;
2147 wr32_epcs(hw, TXGBE_PHY_TX_EQ_CTL0, value);
2149 value = rd32_epcs(hw, TXGBE_PHY_TX_EQ_CTL1);
2150 value = (value & ~0x7F) | 16 | (1 << 6);
2151 wr32_epcs(hw, TXGBE_PHY_TX_EQ_CTL1, value);
2158 * txgbe_autoc_read - Hides MAC differences needed for AUTOC read
2159 * @hw: pointer to hardware structure
2161 u64 txgbe_autoc_read(struct txgbe_hw *hw)
2168 u8 type = hw->subsystem_device_id & 0xFF;
2170 autoc = hw->mac.autoc;
2172 if (hw->phy.multispeed_fiber) {
2173 autoc |= TXGBE_AUTOC_LMS_10G;
2174 } else if (type == TXGBE_DEV_ID_SFP) {
2175 autoc |= TXGBE_AUTOC_LMS_10G;
2176 autoc |= TXGBE_AUTOC_10GS_SFI;
2177 } else if (type == TXGBE_DEV_ID_QSFP) {
2179 } else if (type == TXGBE_DEV_ID_XAUI || type == TXGBE_DEV_ID_SFI_XAUI) {
2180 autoc |= TXGBE_AUTOC_LMS_10G_LINK_NO_AN;
2181 autoc |= TXGBE_AUTOC_10G_XAUI;
2182 hw->phy.link_mode = TXGBE_PHYSICAL_LAYER_10GBASE_T;
2183 } else if (type == TXGBE_DEV_ID_SGMII) {
2184 autoc |= TXGBE_AUTOC_LMS_SGMII_1G_100M;
2185 hw->phy.link_mode = TXGBE_PHYSICAL_LAYER_1000BASE_T |
2186 TXGBE_PHYSICAL_LAYER_100BASE_TX;
2187 } else if (type == TXGBE_DEV_ID_MAC_XAUI) {
2188 autoc |= TXGBE_AUTOC_LMS_10G_LINK_NO_AN;
2189 hw->phy.link_mode = TXGBE_PHYSICAL_LAYER_10GBASE_KX4;
2190 } else if (type == TXGBE_DEV_ID_MAC_SGMII) {
2191 autoc |= TXGBE_AUTOC_LMS_1G_LINK_NO_AN;
2192 hw->phy.link_mode = TXGBE_PHYSICAL_LAYER_1000BASE_KX;
2195 if (type != TXGBE_DEV_ID_KR_KX_KX4)
2198 sr_pcs_ctl = rd32_epcs(hw, SR_XS_PCS_CTRL2);
2199 sr_pma_ctl1 = rd32_epcs(hw, SR_PMA_CTRL1);
2200 sr_an_ctl = rd32_epcs(hw, SR_AN_CTRL);
2201 sr_an_adv_reg2 = rd32_epcs(hw, SR_AN_MMD_ADV_REG2);
2203 if ((sr_pcs_ctl & SR_PCS_CTRL2_TYPE_SEL) == SR_PCS_CTRL2_TYPE_SEL_X &&
2204 (sr_pma_ctl1 & SR_PMA_CTRL1_SS13) == SR_PMA_CTRL1_SS13_KX &&
2205 (sr_an_ctl & SR_AN_CTRL_AN_EN) == 0) {
2206 /* 1G or KX - no backplane auto-negotiation */
2207 autoc |= TXGBE_AUTOC_LMS_1G_LINK_NO_AN |
2209 hw->phy.link_mode = TXGBE_PHYSICAL_LAYER_1000BASE_KX;
2210 } else if ((sr_pcs_ctl & SR_PCS_CTRL2_TYPE_SEL) ==
2211 SR_PCS_CTRL2_TYPE_SEL_X &&
2212 (sr_pma_ctl1 & SR_PMA_CTRL1_SS13) == SR_PMA_CTRL1_SS13_KX4 &&
2213 (sr_an_ctl & SR_AN_CTRL_AN_EN) == 0) {
2214 autoc |= TXGBE_AUTOC_LMS_10G |
2215 TXGBE_AUTOC_10G_KX4;
2216 hw->phy.link_mode = TXGBE_PHYSICAL_LAYER_10GBASE_KX4;
2217 } else if ((sr_pcs_ctl & SR_PCS_CTRL2_TYPE_SEL) ==
2218 SR_PCS_CTRL2_TYPE_SEL_R &&
2219 (sr_an_ctl & SR_AN_CTRL_AN_EN) == 0) {
2220 /* 10 GbE serial link (KR -no backplane auto-negotiation) */
2221 autoc |= TXGBE_AUTOC_LMS_10G |
2222 TXGBE_AUTOC_10GS_KR;
2223 hw->phy.link_mode = TXGBE_PHYSICAL_LAYER_10GBASE_KR;
2224 } else if ((sr_an_ctl & SR_AN_CTRL_AN_EN)) {
2225 /* KX/KX4/KR backplane auto-negotiation enable */
2226 if (sr_an_adv_reg2 & SR_AN_MMD_ADV_REG2_BP_TYPE_KR)
2227 autoc |= TXGBE_AUTOC_KR_SUPP;
2228 if (sr_an_adv_reg2 & SR_AN_MMD_ADV_REG2_BP_TYPE_KX4)
2229 autoc |= TXGBE_AUTOC_KX4_SUPP;
2230 if (sr_an_adv_reg2 & SR_AN_MMD_ADV_REG2_BP_TYPE_KX)
2231 autoc |= TXGBE_AUTOC_KX_SUPP;
2232 autoc |= TXGBE_AUTOC_LMS_KX4_KX_KR;
2233 hw->phy.link_mode = TXGBE_PHYSICAL_LAYER_10GBASE_KR |
2234 TXGBE_PHYSICAL_LAYER_10GBASE_KX4 |
2235 TXGBE_PHYSICAL_LAYER_1000BASE_KX;
2242 * txgbe_autoc_write - Hides MAC differences needed for AUTOC write
2243 * @hw: pointer to hardware structure
2244 * @autoc: value to write to AUTOC
2246 void txgbe_autoc_write(struct txgbe_hw *hw, u64 autoc)
2251 u8 device_type = hw->subsystem_device_id & 0xFF;
2253 speed = TXGBD_AUTOC_SPEED(autoc);
2254 autoc &= ~TXGBE_AUTOC_SPEED_MASK;
2255 autoneg = (autoc & TXGBE_AUTOC_AUTONEG ? true : false);
2256 autoc &= ~TXGBE_AUTOC_AUTONEG;
2258 if (device_type == TXGBE_DEV_ID_KR_KX_KX4) {
2260 switch (hw->phy.link_mode) {
2261 case TXGBE_PHYSICAL_LAYER_10GBASE_KR:
2262 txgbe_set_link_to_kr(hw, autoneg);
2264 case TXGBE_PHYSICAL_LAYER_10GBASE_KX4:
2265 txgbe_set_link_to_kx4(hw, autoneg);
2267 case TXGBE_PHYSICAL_LAYER_1000BASE_KX:
2268 txgbe_set_link_to_kx(hw, speed, autoneg);
2274 txgbe_set_link_to_kr(hw, !autoneg);
2276 } else if (device_type == TXGBE_DEV_ID_XAUI ||
2277 device_type == TXGBE_DEV_ID_SGMII ||
2278 device_type == TXGBE_DEV_ID_MAC_XAUI ||
2279 device_type == TXGBE_DEV_ID_MAC_SGMII ||
2280 (device_type == TXGBE_DEV_ID_SFI_XAUI &&
2281 hw->phy.media_type == txgbe_media_type_copper)) {
2282 if (speed == TXGBE_LINK_SPEED_10GB_FULL) {
2283 txgbe_set_link_to_kx4(hw, 0);
2285 txgbe_set_link_to_kx(hw, speed, 0);
2286 if (hw->devarg.auto_neg == 1)
2287 txgbe_set_sgmii_an37_ability(hw);
2289 } else if (hw->phy.media_type == txgbe_media_type_fiber) {
2290 txgbe_set_link_to_sfi(hw, speed);
2291 if (speed == TXGBE_LINK_SPEED_1GB_FULL)
2292 txgbe_set_sgmii_an37_ability(hw);
2295 if (speed == TXGBE_LINK_SPEED_10GB_FULL)
2296 mactxcfg = TXGBE_MACTXCFG_SPEED_10G;
2297 else if (speed == TXGBE_LINK_SPEED_1GB_FULL)
2298 mactxcfg = TXGBE_MACTXCFG_SPEED_1G;
2300 /* enable mac transmitter */
2301 wr32m(hw, TXGBE_MACTXCFG,
2302 TXGBE_MACTXCFG_SPEED_MASK | TXGBE_MACTXCFG_TXE,
2303 mactxcfg | TXGBE_MACTXCFG_TXE);
2306 void txgbe_bp_down_event(struct txgbe_hw *hw)
2308 if (!(hw->devarg.auto_neg == 1))
2311 BP_LOG("restart phy power.\n");
2312 wr32_epcs(hw, VR_AN_KR_MODE_CL, 0);
2313 wr32_epcs(hw, SR_AN_CTRL, 0);
2314 wr32_epcs(hw, VR_AN_INTR_MSK, 0);
2317 txgbe_set_link_to_kr(hw, 0);
2320 void txgbe_bp_mode_set(struct txgbe_hw *hw)
2322 if (hw->phy.ffe_set == TXGBE_BP_M_SFI)
2323 hw->subsystem_device_id = TXGBE_DEV_ID_WX1820_SFP;
2324 else if (hw->phy.ffe_set == TXGBE_BP_M_KR)
2325 hw->subsystem_device_id = TXGBE_DEV_ID_WX1820_KR_KX_KX4;
2326 else if (hw->phy.ffe_set == TXGBE_BP_M_KX4)
2327 hw->subsystem_device_id = TXGBE_DEV_ID_WX1820_MAC_XAUI;
2328 else if (hw->phy.ffe_set == TXGBE_BP_M_KX)
2329 hw->subsystem_device_id = TXGBE_DEV_ID_WX1820_MAC_SGMII;
2332 void txgbe_set_phy_temp(struct txgbe_hw *hw)
2336 if (hw->phy.ffe_set == TXGBE_BP_M_SFI) {
2337 BP_LOG("Set SFI TX_EQ MAIN:%d PRE:%d POST:%d\n",
2338 hw->phy.ffe_main, hw->phy.ffe_pre, hw->phy.ffe_post);
2340 value = rd32_epcs(hw, TXGBE_PHY_TX_EQ_CTL0);
2341 value = (value & ~0x3F3F) | (hw->phy.ffe_main << 8) |
2343 wr32_epcs(hw, TXGBE_PHY_TX_EQ_CTL0, value);
2345 value = rd32_epcs(hw, TXGBE_PHY_TX_EQ_CTL1);
2346 value = (value & ~0x7F) | hw->phy.ffe_post | (1 << 6);
2347 wr32_epcs(hw, TXGBE_PHY_TX_EQ_CTL1, value);
2350 if (hw->phy.ffe_set == TXGBE_BP_M_KR) {
2351 BP_LOG("Set KR TX_EQ MAIN:%d PRE:%d POST:%d\n",
2352 hw->phy.ffe_main, hw->phy.ffe_pre, hw->phy.ffe_post);
2353 value = (0x1804 & ~0x3F3F);
2354 value |= hw->phy.ffe_main << 8 | hw->phy.ffe_pre;
2355 wr32_epcs(hw, TXGBE_PHY_TX_EQ_CTL0, value);
2357 value = (0x50 & ~0x7F) | (1 << 6) | hw->phy.ffe_post;
2358 wr32_epcs(hw, TXGBE_PHY_TX_EQ_CTL1, value);
2359 wr32_epcs(hw, 0x18035, 0x00FF);
2360 wr32_epcs(hw, 0x18055, 0x00FF);
2363 if (hw->phy.ffe_set == TXGBE_BP_M_KX) {
2364 BP_LOG("Set KX TX_EQ MAIN:%d PRE:%d POST:%d\n",
2365 hw->phy.ffe_main, hw->phy.ffe_pre, hw->phy.ffe_post);
2366 value = rd32_epcs(hw, TXGBE_PHY_TX_EQ_CTL0);
2367 value = (value & ~0x3F3F) | (hw->phy.ffe_main << 8) |
2369 wr32_epcs(hw, TXGBE_PHY_TX_EQ_CTL0, value);
2371 value = rd32_epcs(hw, TXGBE_PHY_TX_EQ_CTL1);
2372 value = (value & ~0x7F) | hw->phy.ffe_post | (1 << 6);
2373 wr32_epcs(hw, TXGBE_PHY_TX_EQ_CTL1, value);
2375 wr32_epcs(hw, 0x18035, 0x00FF);
2376 wr32_epcs(hw, 0x18055, 0x00FF);
2381 * txgbe_kr_handle - Handle the interrupt of auto-negotiation
2382 * @hw: pointer to hardware structure
2384 s32 txgbe_kr_handle(struct txgbe_hw *hw)
2389 value = rd32_epcs(hw, VR_AN_INTR);
2390 BP_LOG("AN INTERRUPT!! value: 0x%x\n", value);
2391 if (!(value & VR_AN_INTR_PG_RCV)) {
2392 wr32_epcs(hw, VR_AN_INTR, 0);
2396 status = txgbe_handle_bp_flow(0, hw);
2402 * txgbe_handle_bp_flow - Handle backplane AN73 flow
2403 * @hw: pointer to hardware structure
2404 * @link_mode: local AN73 link mode
2406 static s32 txgbe_handle_bp_flow(u32 link_mode, struct txgbe_hw *hw)
2408 u32 value, i, lp_reg, ld_reg;
2410 struct txgbe_backplane_ability local_ability, lp_ability;
2412 local_ability.current_link_mode = link_mode;
2414 /* 1. Get the local AN73 Base Page Ability */
2415 BP_LOG("<1>. Get the local AN73 Base Page Ability ...\n");
2416 txgbe_get_bp_ability(&local_ability, 0, hw);
2418 /* 2. Check and clear the AN73 Interrupt Status */
2419 BP_LOG("<2>. Check the AN73 Interrupt Status ...\n");
2420 txgbe_clear_bp_intr(2, 0, hw);
2422 /* 3.1. Get the link partner AN73 Base Page Ability */
2423 BP_LOG("<3.1>. Get the link partner AN73 Base Page Ability ...\n");
2424 txgbe_get_bp_ability(&lp_ability, 1, hw);
2426 /* 3.2. Check the AN73 Link Ability with Link Partner */
2427 BP_LOG("<3.2>. Check the AN73 Link Ability with Link Partner ...\n");
2428 BP_LOG(" Local Link Ability: 0x%x\n", local_ability.link_ability);
2429 BP_LOG(" Link Partner Link Ability: 0x%x\n", lp_ability.link_ability);
2431 status = txgbe_check_bp_ability(&local_ability, &lp_ability, hw);
2433 wr32_epcs(hw, SR_AN_CTRL, 0);
2434 wr32_epcs(hw, VR_AN_KR_MODE_CL, 0);
2436 /* 3.3. Check the FEC and KR Training for KR mode */
2437 BP_LOG("<3.3>. Check the FEC for KR mode ...\n");
2438 if ((local_ability.fec_ability & lp_ability.fec_ability) == 0x03) {
2439 BP_LOG("Enable the Backplane KR FEC ...\n");
2440 wr32_epcs(hw, SR_PMA_KR_FEC_CTRL, SR_PMA_KR_FEC_CTRL_EN);
2442 BP_LOG("Backplane KR FEC is disabled.\n");
2445 printf("Enter training.\n");
2446 /* CL72 KR training on */
2447 for (i = 0; i < 2; i++) {
2448 /* 3.4. Check the CL72 KR Training for KR mode */
2449 BP_LOG("<3.4>. Check the CL72 KR Training for KR mode ...\n");
2450 BP_LOG("==================%d==================\n", i);
2451 status = txgbe_enable_kr_training(hw);
2452 BP_LOG("Check the Clause 72 KR Training status ...\n");
2453 status |= txgbe_check_kr_training(hw);
2455 lp_reg = rd32_epcs(hw, SR_PMA_KR_LP_CESTS);
2456 lp_reg &= SR_PMA_KR_LP_CESTS_RR;
2457 BP_LOG("SR PMA MMD 10GBASE-KR LP Coefficient Status Register: 0x%x\n",
2459 ld_reg = rd32_epcs(hw, SR_PMA_KR_LD_CESTS);
2460 ld_reg &= SR_PMA_KR_LD_CESTS_RR;
2461 BP_LOG("SR PMA MMD 10GBASE-KR LD Coefficient Status Register: 0x%x\n",
2463 if (hw->devarg.poll == 0 && status != 0)
2464 lp_reg = SR_PMA_KR_LP_CESTS_RR;
2466 if (lp_reg & ld_reg) {
2467 BP_LOG("==================out==================\n");
2468 status = txgbe_disable_kr_training(hw, 0, 0);
2469 wr32_epcs(hw, SR_AN_CTRL, 0);
2470 txgbe_clear_bp_intr(2, 0, hw);
2471 txgbe_clear_bp_intr(1, 0, hw);
2472 txgbe_clear_bp_intr(0, 0, hw);
2473 for (i = 0; i < 10; i++) {
2474 value = rd32_epcs(hw, SR_XS_PCS_KR_STS1);
2475 if (value & SR_XS_PCS_KR_STS1_PLU) {
2476 BP_LOG("\nINT_AN_INT_CMPLT =1, AN73 Done Success.\n");
2477 wr32_epcs(hw, SR_AN_CTRL, 0);
2483 txgbe_set_link_to_kr(hw, 0);
2488 status |= txgbe_disable_kr_training(hw, 0, 0);
2491 txgbe_clear_bp_intr(2, 0, hw);
2492 txgbe_clear_bp_intr(1, 0, hw);
2493 txgbe_clear_bp_intr(0, 0, hw);
2499 * txgbe_get_bp_ability
2500 * @hw: pointer to hardware structure
2501 * @ability: pointer to blackplane ability structure
2503 * 1: Get Link Partner Base Page
2504 * 2: Get Link Partner Next Page
2505 * (only get NXP Ability Register 1 at the moment)
2506 * 0: Get Local Device Base Page
2508 static void txgbe_get_bp_ability(struct txgbe_backplane_ability *ability,
2509 u32 link_partner, struct txgbe_hw *hw)
2513 /* Link Partner Base Page */
2514 if (link_partner == 1) {
2515 /* Read the link partner AN73 Base Page Ability Registers */
2516 BP_LOG("Read the link partner AN73 Base Page Ability Registers...\n");
2517 value = rd32_epcs(hw, SR_AN_MMD_LP_ABL1);
2518 BP_LOG("SR AN MMD LP Base Page Ability Register 1: 0x%x\n",
2520 ability->next_page = SR_MMD_LP_ABL1_ADV_NP(value);
2521 BP_LOG(" Next Page (bit15): %d\n", ability->next_page);
2523 value = rd32_epcs(hw, SR_AN_MMD_LP_ABL2);
2524 BP_LOG("SR AN MMD LP Base Page Ability Register 2: 0x%x\n",
2526 ability->link_ability =
2527 value & SR_AN_MMD_LP_ABL2_BP_TYPE_KR_KX4_KX;
2528 BP_LOG(" Link Ability (bit[15:0]): 0x%x\n",
2529 ability->link_ability);
2530 BP_LOG(" (0x20- KX_ONLY, 0x40- KX4_ONLY, 0x60- KX4_KX\n");
2531 BP_LOG(" 0x80- KR_ONLY, 0xA0- KR_KX, 0xC0- KR_KX4, 0xE0- KR_KX4_KX)\n");
2533 value = rd32_epcs(hw, SR_AN_MMD_LP_ABL3);
2534 BP_LOG("SR AN MMD LP Base Page Ability Register 3: 0x%x\n",
2536 BP_LOG(" FEC Request (bit15): %d\n", ((value >> 15) & 0x01));
2537 BP_LOG(" FEC Enable (bit14): %d\n", ((value >> 14) & 0x01));
2538 ability->fec_ability = SR_AN_MMD_LP_ABL3_FCE(value);
2539 } else if (link_partner == 2) {
2540 /* Read the link partner AN73 Next Page Ability Registers */
2541 BP_LOG("\nRead the link partner AN73 Next Page Ability Registers...\n");
2542 value = rd32_epcs(hw, SR_AN_LP_XNP_ABL1);
2543 BP_LOG(" SR AN MMD LP XNP Ability Register 1: 0x%x\n", value);
2544 ability->next_page = SR_AN_LP_XNP_ABL1_NP(value);
2545 BP_LOG(" Next Page (bit15): %d\n", ability->next_page);
2547 /* Read the local AN73 Base Page Ability Registers */
2548 BP_LOG("Read the local AN73 Base Page Ability Registers...\n");
2549 value = rd32_epcs(hw, SR_AN_MMD_ADV_REG1);
2550 BP_LOG("SR AN MMD Advertisement Register 1: 0x%x\n", value);
2551 ability->next_page = SR_AN_MMD_ADV_REG1_NP(value);
2552 BP_LOG(" Next Page (bit15): %d\n", ability->next_page);
2554 value = rd32_epcs(hw, SR_AN_MMD_ADV_REG2);
2555 BP_LOG("SR AN MMD Advertisement Register 2: 0x%x\n", value);
2556 ability->link_ability =
2557 value & SR_AN_MMD_ADV_REG2_BP_TYPE_KR_KX4_KX;
2558 BP_LOG(" Link Ability (bit[15:0]): 0x%x\n",
2559 ability->link_ability);
2560 BP_LOG(" (0x20- KX_ONLY, 0x40- KX4_ONLY, 0x60- KX4_KX\n");
2561 BP_LOG(" 0x80- KR_ONLY, 0xA0- KR_KX, 0xC0- KR_KX4, 0xE0- KR_KX4_KX)\n");
2563 value = rd32_epcs(hw, SR_AN_MMD_ADV_REG3);
2564 BP_LOG("SR AN MMD Advertisement Register 3: 0x%x\n", value);
2565 BP_LOG(" FEC Request (bit15): %d\n", ((value >> 15) & 0x01));
2566 BP_LOG(" FEC Enable (bit14): %d\n", ((value >> 14) & 0x01));
2567 ability->fec_ability = SR_AN_MMD_ADV_REG3_FCE(value);
2574 * txgbe_check_bp_ability
2575 * @hw: pointer to hardware structure
2576 * @ability: pointer to blackplane ability structure
2578 static s32 txgbe_check_bp_ability(struct txgbe_backplane_ability *local_ability,
2579 struct txgbe_backplane_ability *lp_ability, struct txgbe_hw *hw)
2584 com_link_abi = local_ability->link_ability & lp_ability->link_ability;
2585 BP_LOG("com_link_abi = 0x%x, local_ability = 0x%x, lp_ability = 0x%x\n",
2586 com_link_abi, local_ability->link_ability,
2587 lp_ability->link_ability);
2589 if (!com_link_abi) {
2590 BP_LOG("The Link Partner does not support any compatible speed mode.\n");
2592 } else if (com_link_abi & BP_TYPE_KR) {
2593 if (local_ability->current_link_mode) {
2594 BP_LOG("Link mode is not matched with Link Partner: [LINK_KR].\n");
2595 BP_LOG("Set the local link mode to [LINK_KR] ...\n");
2596 txgbe_set_link_to_kr(hw, 0);
2599 BP_LOG("Link mode is matched with Link Partner: [LINK_KR].\n");
2602 } else if (com_link_abi & BP_TYPE_KX4) {
2603 if (local_ability->current_link_mode == 0x10) {
2604 BP_LOG("Link mode is matched with Link Partner: [LINK_KX4].\n");
2607 BP_LOG("Link mode is not matched with Link Partner: [LINK_KX4].\n");
2608 BP_LOG("Set the local link mode to [LINK_KX4] ...\n");
2609 txgbe_set_link_to_kx4(hw, 1);
2612 } else if (com_link_abi & BP_TYPE_KX) {
2613 if (local_ability->current_link_mode == 0x1) {
2614 BP_LOG("Link mode is matched with Link Partner: [LINK_KX].\n");
2617 BP_LOG("Link mode is not matched with Link Partner: [LINK_KX].\n");
2618 BP_LOG("Set the local link mode to [LINK_KX] ...\n");
2619 txgbe_set_link_to_kx(hw, 1, 1);
2628 * txgbe_clear_bp_intr
2629 * @hw: pointer to hardware structure
2630 * @index: the bit will be cleared
2632 * index_high = 0: Only the index bit will be cleared
2633 * index_high != 0: the [index_high, index] range will be cleared
2635 static void txgbe_clear_bp_intr(u32 bit, u32 bit_high, struct txgbe_hw *hw)
2637 u32 rdata = 0, wdata, i;
2639 rdata = rd32_epcs(hw, VR_AN_INTR);
2640 BP_LOG("[Before clear]Read VR AN MMD Interrupt Register: 0x%x\n",
2642 BP_LOG("Interrupt: 0- AN_INT_CMPLT, 1- AN_INC_LINK, 2- AN_PG_RCV\n\n");
2646 for (i = bit; i <= bit_high; i++)
2649 wdata &= ~(1 << bit);
2652 wr32_epcs(hw, VR_AN_INTR, wdata);
2654 rdata = rd32_epcs(hw, VR_AN_INTR);
2655 BP_LOG("[After clear]Read VR AN MMD Interrupt Register: 0x%x\n", rdata);
2658 static s32 txgbe_enable_kr_training(struct txgbe_hw *hw)
2663 BP_LOG("Enable Clause 72 KR Training ...\n");
2665 if (CL72_KRTR_PRBS_MODE_EN != 0xFFFF) {
2666 /* Set PRBS Timer Duration Control to maximum 6.7ms in
2667 * VR_PMA_KRTR_PRBS_CTRL2 Register
2669 value = CL72_KRTR_PRBS_MODE_EN;
2670 wr32_epcs(hw, VR_PMA_KRTR_PRBS_CTRL2, value);
2671 /* Set PRBS Timer Duration Control to maximum 6.7ms in
2672 * VR_PMA_KRTR_PRBS_CTRL1 Register
2674 wr32_epcs(hw, VR_PMA_KRTR_PRBS_CTRL1,
2675 VR_PMA_KRTR_PRBS_TIME_LMT);
2676 /* Enable PRBS Mode to determine KR Training Status by setting
2677 * Bit 0 of VR_PMA_KRTR_PRBS_CTRL0 Register
2679 value = VR_PMA_KRTR_PRBS_MODE_EN;
2681 #ifdef CL72_KRTR_PRBS31_EN
2682 /* Enable PRBS Mode to determine KR Training Status by setting
2683 * Bit 1 of VR_PMA_KRTR_PRBS_CTRL0 Register
2685 value = VR_PMA_KRTR_PRBS31_EN;
2687 wr32_epcs(hw, VR_PMA_KRTR_PRBS_CTRL0, value);
2688 /* Read PHY Lane0 TX EQ before Clause 72 KR Training. */
2689 txgbe_read_phy_lane_tx_eq(0, hw, 0, 0);
2691 /* Enable the Clause 72 start-up protocol
2692 * by setting Bit 1 of SR_PMA_KR_PMD_CTRL Register.
2693 * Restart the Clause 72 start-up protocol
2694 * by setting Bit 0 of SR_PMA_KR_PMD_CTRL Register.
2696 wr32_epcs(hw, SR_PMA_KR_PMD_CTRL,
2697 SR_PMA_KR_PMD_CTRL_EN_TR | SR_PMA_KR_PMD_CTRL_RS_TR);
2702 static s32 txgbe_disable_kr_training(struct txgbe_hw *hw, s32 post, s32 mode)
2706 BP_LOG("Disable Clause 72 KR Training ...\n");
2707 /* Read PHY Lane0 TX EQ before Clause 72 KR Training. */
2708 txgbe_read_phy_lane_tx_eq(0, hw, post, mode);
2710 wr32_epcs(hw, SR_PMA_KR_PMD_CTRL, SR_PMA_KR_PMD_CTRL_RS_TR);
2715 static s32 txgbe_check_kr_training(struct txgbe_hw *hw)
2720 int times = hw->devarg.poll ? 35 : 20;
2722 for (i = 0; i < times; i++) {
2723 value = rd32_epcs(hw, SR_PMA_KR_LP_CEU);
2724 BP_LOG("SR PMA MMD 10GBASE-KR LP Coefficient Update Register: 0x%x\n",
2726 value = rd32_epcs(hw, SR_PMA_KR_LP_CESTS);
2727 BP_LOG("SR PMA MMD 10GBASE-KR LP Coefficient Status Register: 0x%x\n",
2729 value = rd32_epcs(hw, SR_PMA_KR_LD_CEU);
2730 BP_LOG("SR PMA MMD 10GBASE-KR LD Coefficient Update: 0x%x\n",
2732 value = rd32_epcs(hw, SR_PMA_KR_LD_CESTS);
2733 BP_LOG("SR PMA MMD 10GBASE-KR LD Coefficient Status: 0x%x\n",
2735 value = rd32_epcs(hw, SR_PMA_KR_PMD_STS);
2736 BP_LOG("SR PMA MMD 10GBASE-KR Status Register: 0x%x\n", value);
2737 BP_LOG(" Training Failure (bit3): %d\n",
2738 ((value >> 3) & 0x01));
2739 BP_LOG(" Start-Up Protocol Status (bit2): %d\n",
2740 ((value >> 2) & 0x01));
2741 BP_LOG(" Frame Lock (bit1): %d\n",
2742 ((value >> 1) & 0x01));
2743 BP_LOG(" Receiver Status (bit0): %d\n",
2744 ((value >> 0) & 0x01));
2746 test = rd32_epcs(hw, SR_PMA_KR_LP_CESTS);
2747 if (test & SR_PMA_KR_LP_CESTS_RR) {
2748 BP_LOG("TEST Coefficient Status Register: 0x%x\n",
2753 if (value & SR_PMA_KR_PMD_STS_TR_FAIL) {
2754 BP_LOG("Training is completed with failure.\n");
2755 txgbe_read_phy_lane_tx_eq(0, hw, 0, 0);
2759 if (value & SR_PMA_KR_PMD_STS_RCV) {
2760 BP_LOG("Receiver trained and ready to receive data.\n");
2761 txgbe_read_phy_lane_tx_eq(0, hw, 0, 0);
2768 BP_LOG("ERROR: Check Clause 72 KR Training Complete Timeout.\n");
2772 static void txgbe_read_phy_lane_tx_eq(u16 lane, struct txgbe_hw *hw,
2777 u32 tx_main_cursor, tx_pre_cursor, tx_post_cursor, lmain;
2779 addr = TXGBE_PHY_LANE0_TX_EQ_CTL1 | (lane << 8);
2780 value = rd32_ephy(hw, addr);
2781 BP_LOG("PHY LANE TX EQ Read Value: %x\n", lane);
2782 tx_main_cursor = TXGBE_PHY_LANE0_TX_EQ_CTL1_MAIN(value);
2783 BP_LOG("TX_MAIN_CURSOR: %x\n", tx_main_cursor);
2784 UNREFERENCED_PARAMETER(tx_main_cursor);
2786 addr = TXGBE_PHY_LANE0_TX_EQ_CTL2 | (lane << 8);
2787 value = rd32_ephy(hw, addr);
2788 tx_pre_cursor = value & TXGBE_PHY_LANE0_TX_EQ_CTL2_PRE;
2789 tx_post_cursor = TXGBE_PHY_LANE0_TX_EQ_CTL2_POST(value);
2790 BP_LOG("TX_PRE_CURSOR: %x\n", tx_pre_cursor);
2791 BP_LOG("TX_POST_CURSOR: %x\n", tx_post_cursor);
2794 lmain = 160 - tx_pre_cursor - tx_post_cursor;
2799 tx_post_cursor = post;
2801 wr32_epcs(hw, TXGBE_PHY_EQ_INIT_CTL1, tx_post_cursor);
2802 wr32_epcs(hw, TXGBE_PHY_EQ_INIT_CTL0,
2803 tx_pre_cursor | (lmain << 8));
2804 value = rd32_epcs(hw, TXGBE_PHY_TX_EQ_CTL1);
2805 value &= ~TXGBE_PHY_TX_EQ_CTL1_DEF;
2806 wr32_epcs(hw, TXGBE_PHY_TX_EQ_CTL1, value);