1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2015-2020
6 #include "txgbe_eeprom.h"
10 static void txgbe_i2c_start(struct txgbe_hw *hw);
11 static void txgbe_i2c_stop(struct txgbe_hw *hw);
12 static s32 txgbe_set_link_to_sfi(struct txgbe_hw *hw, u32 speed);
15 * txgbe_identify_extphy - Identify a single address for a PHY
16 * @hw: pointer to hardware structure
17 * @phy_addr: PHY address to probe
19 * Returns true if PHY found
21 static bool txgbe_identify_extphy(struct txgbe_hw *hw)
25 if (!txgbe_validate_phy_addr(hw, phy_addr)) {
26 DEBUGOUT("Unable to validate PHY address 0x%04X\n",
31 if (txgbe_get_phy_id(hw))
34 hw->phy.type = txgbe_get_phy_type_from_id(hw->phy.id);
35 if (hw->phy.type == txgbe_phy_unknown) {
37 hw->phy.read_reg(hw, TXGBE_MD_PHY_EXT_ABILITY,
41 if (ext_ability & (TXGBE_MD_PHY_10GBASET_ABILITY |
42 TXGBE_MD_PHY_1000BASET_ABILITY))
43 hw->phy.type = txgbe_phy_cu_unknown;
45 hw->phy.type = txgbe_phy_generic;
52 * txgbe_read_phy_if - Read TXGBE_ETHPHYIF register
53 * @hw: pointer to hardware structure
55 * Read TXGBE_ETHPHYIF register and save field values,
56 * and check for valid field values.
58 static s32 txgbe_read_phy_if(struct txgbe_hw *hw)
60 hw->phy.media_type = hw->phy.get_media_type(hw);
62 /* Save NW management interface connected on board. This is used
63 * to determine internal PHY mode.
65 hw->phy.nw_mng_if_sel = rd32(hw, TXGBE_ETHPHYIF);
67 /* If MDIO is connected to external PHY, then set PHY address. */
68 if (hw->phy.nw_mng_if_sel & TXGBE_ETHPHYIF_MDIO_ACT)
69 hw->phy.addr = TXGBE_ETHPHYIF_MDIO_BASE(hw->phy.nw_mng_if_sel);
71 if (!hw->phy.phy_semaphore_mask) {
73 hw->phy.phy_semaphore_mask = TXGBE_MNGSEM_SWPHY;
75 hw->phy.phy_semaphore_mask = TXGBE_MNGSEM_SWPHY;
82 * txgbe_identify_phy - Get physical layer module
83 * @hw: pointer to hardware structure
85 * Determines the physical layer module found on the current adapter.
87 s32 txgbe_identify_phy(struct txgbe_hw *hw)
89 s32 err = TXGBE_ERR_PHY_ADDR_INVALID;
91 DEBUGFUNC("txgbe_identify_phy");
93 txgbe_read_phy_if(hw);
95 if (hw->phy.type != txgbe_phy_unknown)
98 /* Raptor 10GBASE-T requires an external PHY */
99 if (hw->phy.media_type == txgbe_media_type_copper) {
100 err = txgbe_identify_extphy(hw);
101 } else if (hw->phy.media_type == txgbe_media_type_fiber) {
102 err = txgbe_identify_module(hw);
104 hw->phy.type = txgbe_phy_none;
108 /* Return error if SFP module has been detected but is not supported */
109 if (hw->phy.type == txgbe_phy_sfp_unsupported)
110 return TXGBE_ERR_SFP_NOT_SUPPORTED;
116 * txgbe_check_reset_blocked - check status of MNG FW veto bit
117 * @hw: pointer to the hardware structure
119 * This function checks the STAT.MNGVETO bit to see if there are
120 * any constraints on link from manageability. For MAC's that don't
121 * have this bit just return faluse since the link can not be blocked
124 s32 txgbe_check_reset_blocked(struct txgbe_hw *hw)
128 DEBUGFUNC("txgbe_check_reset_blocked");
130 mmngc = rd32(hw, TXGBE_STAT);
131 if (mmngc & TXGBE_STAT_MNGVETO) {
132 DEBUGOUT("MNG_VETO bit detected.\n");
140 * txgbe_validate_phy_addr - Determines phy address is valid
141 * @hw: pointer to hardware structure
142 * @phy_addr: PHY address
145 bool txgbe_validate_phy_addr(struct txgbe_hw *hw, u32 phy_addr)
150 DEBUGFUNC("txgbe_validate_phy_addr");
152 hw->phy.addr = phy_addr;
153 hw->phy.read_reg(hw, TXGBE_MD_PHY_ID_HIGH,
154 TXGBE_MD_DEV_PMA_PMD, &phy_id);
156 if (phy_id != 0xFFFF && phy_id != 0x0)
159 DEBUGOUT("PHY ID HIGH is 0x%04X\n", phy_id);
165 * txgbe_get_phy_id - Get the phy type
166 * @hw: pointer to hardware structure
169 s32 txgbe_get_phy_id(struct txgbe_hw *hw)
175 DEBUGFUNC("txgbe_get_phy_id");
177 err = hw->phy.read_reg(hw, TXGBE_MD_PHY_ID_HIGH,
178 TXGBE_MD_DEV_PMA_PMD,
182 hw->phy.id = (u32)(phy_id_high << 16);
183 err = hw->phy.read_reg(hw, TXGBE_MD_PHY_ID_LOW,
184 TXGBE_MD_DEV_PMA_PMD,
186 hw->phy.id |= (u32)(phy_id_low & TXGBE_PHY_REVISION_MASK);
187 hw->phy.revision = (u32)(phy_id_low & ~TXGBE_PHY_REVISION_MASK);
189 DEBUGOUT("PHY_ID_HIGH 0x%04X, PHY_ID_LOW 0x%04X\n",
190 phy_id_high, phy_id_low);
196 * txgbe_get_phy_type_from_id - Get the phy type
197 * @phy_id: PHY ID information
200 enum txgbe_phy_type txgbe_get_phy_type_from_id(u32 phy_id)
202 enum txgbe_phy_type phy_type;
204 DEBUGFUNC("txgbe_get_phy_type_from_id");
207 case TXGBE_PHYID_TN1010:
208 phy_type = txgbe_phy_tn;
210 case TXGBE_PHYID_QT2022:
211 phy_type = txgbe_phy_qt;
213 case TXGBE_PHYID_ATH:
214 phy_type = txgbe_phy_nl;
216 case TXGBE_PHYID_MTD3310:
217 phy_type = txgbe_phy_cu_mtd;
220 phy_type = txgbe_phy_unknown;
228 txgbe_reset_extphy(struct txgbe_hw *hw)
233 err = hw->phy.read_reg(hw, TXGBE_MD_PORT_CTRL,
234 TXGBE_MD_DEV_GENERAL, &ctrl);
237 ctrl |= TXGBE_MD_PORT_CTRL_RESET;
238 err = hw->phy.write_reg(hw, TXGBE_MD_PORT_CTRL,
239 TXGBE_MD_DEV_GENERAL, ctrl);
244 * Poll for reset bit to self-clear indicating reset is complete.
245 * Some PHYs could take up to 3 seconds to complete and need about
246 * 1.7 usec delay after the reset is complete.
248 for (i = 0; i < 30; i++) {
250 err = hw->phy.read_reg(hw, TXGBE_MD_PORT_CTRL,
251 TXGBE_MD_DEV_GENERAL, &ctrl);
255 if (!(ctrl & TXGBE_MD_PORT_CTRL_RESET)) {
261 if (ctrl & TXGBE_MD_PORT_CTRL_RESET) {
262 err = TXGBE_ERR_RESET_FAILED;
263 DEBUGOUT("PHY reset polling failed to complete.\n");
270 * txgbe_reset_phy - Performs a PHY reset
271 * @hw: pointer to hardware structure
273 s32 txgbe_reset_phy(struct txgbe_hw *hw)
277 DEBUGFUNC("txgbe_reset_phy");
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\n");
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 DEBUGFUNC("txgbe_read_phy_reg");
360 if (hw->mac.acquire_swfw_sync(hw, gssr))
361 return TXGBE_ERR_SWFW_SYNC;
363 err = hw->phy.read_reg_mdi(hw, reg_addr, device_type, phy_data);
365 hw->mac.release_swfw_sync(hw, gssr);
371 * txgbe_write_phy_reg_mdi - Writes a value to specified PHY register
373 * @hw: pointer to hardware structure
374 * @reg_addr: 32 bit PHY register to write
375 * @device_type: 5 bit device type
376 * @phy_data: Data to write to the PHY register
378 s32 txgbe_write_phy_reg_mdi(struct txgbe_hw *hw, u32 reg_addr,
379 u32 device_type, u16 phy_data)
384 command = TXGBE_MDIOSCA_REG(reg_addr) |
385 TXGBE_MDIOSCA_DEV(device_type) |
386 TXGBE_MDIOSCA_PORT(hw->phy.addr);
387 wr32(hw, TXGBE_MDIOSCA, command);
389 command = TXGBE_MDIOSCD_CMD_WRITE |
390 TXGBE_MDIOSCD_DAT(phy_data) |
392 wr32(hw, TXGBE_MDIOSCD, command);
394 /* wait for completion */
395 if (!po32m(hw, TXGBE_MDIOSCD, TXGBE_MDIOSCD_BUSY,
396 0, NULL, 100, 100)) {
397 TLOG_DEBUG("PHY write cmd didn't complete\n");
405 * txgbe_write_phy_reg - Writes a value to specified PHY register
406 * using SWFW lock- this function is needed in most cases
407 * @hw: pointer to hardware structure
408 * @reg_addr: 32 bit PHY register to write
409 * @device_type: 5 bit device type
410 * @phy_data: Data to write to the PHY register
412 s32 txgbe_write_phy_reg(struct txgbe_hw *hw, u32 reg_addr,
413 u32 device_type, u16 phy_data)
416 u32 gssr = hw->phy.phy_semaphore_mask;
418 DEBUGFUNC("txgbe_write_phy_reg");
420 if (hw->mac.acquire_swfw_sync(hw, gssr))
421 err = TXGBE_ERR_SWFW_SYNC;
423 err = hw->phy.write_reg_mdi(hw, reg_addr, device_type,
425 hw->mac.release_swfw_sync(hw, gssr);
431 * txgbe_setup_phy_link - Set and restart auto-neg
432 * @hw: pointer to hardware structure
434 * Restart auto-negotiation and PHY and waits for completion.
436 s32 txgbe_setup_phy_link(struct txgbe_hw *hw)
439 u16 autoneg_reg = TXGBE_MII_AUTONEG_REG;
440 bool autoneg = false;
443 DEBUGFUNC("txgbe_setup_phy_link");
445 txgbe_get_copper_link_capabilities(hw, &speed, &autoneg);
447 /* Set or unset auto-negotiation 10G advertisement */
448 hw->phy.read_reg(hw, TXGBE_MII_10GBASE_T_AUTONEG_CTRL_REG,
449 TXGBE_MD_DEV_AUTO_NEG,
452 autoneg_reg &= ~TXGBE_MII_10GBASE_T_ADVERTISE;
453 if ((hw->phy.autoneg_advertised & TXGBE_LINK_SPEED_10GB_FULL) &&
454 (speed & TXGBE_LINK_SPEED_10GB_FULL))
455 autoneg_reg |= TXGBE_MII_10GBASE_T_ADVERTISE;
457 hw->phy.write_reg(hw, TXGBE_MII_10GBASE_T_AUTONEG_CTRL_REG,
458 TXGBE_MD_DEV_AUTO_NEG,
461 hw->phy.read_reg(hw, TXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
462 TXGBE_MD_DEV_AUTO_NEG,
465 /* Set or unset auto-negotiation 5G advertisement */
466 autoneg_reg &= ~TXGBE_MII_5GBASE_T_ADVERTISE;
467 if ((hw->phy.autoneg_advertised & TXGBE_LINK_SPEED_5GB_FULL) &&
468 (speed & TXGBE_LINK_SPEED_5GB_FULL))
469 autoneg_reg |= TXGBE_MII_5GBASE_T_ADVERTISE;
471 /* Set or unset auto-negotiation 2.5G advertisement */
472 autoneg_reg &= ~TXGBE_MII_2_5GBASE_T_ADVERTISE;
473 if ((hw->phy.autoneg_advertised &
474 TXGBE_LINK_SPEED_2_5GB_FULL) &&
475 (speed & TXGBE_LINK_SPEED_2_5GB_FULL))
476 autoneg_reg |= TXGBE_MII_2_5GBASE_T_ADVERTISE;
477 /* Set or unset auto-negotiation 1G advertisement */
478 autoneg_reg &= ~TXGBE_MII_1GBASE_T_ADVERTISE;
479 if ((hw->phy.autoneg_advertised & TXGBE_LINK_SPEED_1GB_FULL) &&
480 (speed & TXGBE_LINK_SPEED_1GB_FULL))
481 autoneg_reg |= TXGBE_MII_1GBASE_T_ADVERTISE;
483 hw->phy.write_reg(hw, TXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
484 TXGBE_MD_DEV_AUTO_NEG,
487 /* Set or unset auto-negotiation 100M advertisement */
488 hw->phy.read_reg(hw, TXGBE_MII_AUTONEG_ADVERTISE_REG,
489 TXGBE_MD_DEV_AUTO_NEG,
492 autoneg_reg &= ~(TXGBE_MII_100BASE_T_ADVERTISE |
493 TXGBE_MII_100BASE_T_ADVERTISE_HALF);
494 if ((hw->phy.autoneg_advertised & TXGBE_LINK_SPEED_100M_FULL) &&
495 (speed & TXGBE_LINK_SPEED_100M_FULL))
496 autoneg_reg |= TXGBE_MII_100BASE_T_ADVERTISE;
498 hw->phy.write_reg(hw, TXGBE_MII_AUTONEG_ADVERTISE_REG,
499 TXGBE_MD_DEV_AUTO_NEG,
502 /* Blocked by MNG FW so don't reset PHY */
503 if (txgbe_check_reset_blocked(hw))
506 /* Restart PHY auto-negotiation. */
507 hw->phy.read_reg(hw, TXGBE_MD_AUTO_NEG_CONTROL,
508 TXGBE_MD_DEV_AUTO_NEG, &autoneg_reg);
510 autoneg_reg |= TXGBE_MII_RESTART;
512 hw->phy.write_reg(hw, TXGBE_MD_AUTO_NEG_CONTROL,
513 TXGBE_MD_DEV_AUTO_NEG, autoneg_reg);
519 * txgbe_setup_phy_link_speed - Sets the auto advertised capabilities
520 * @hw: pointer to hardware structure
521 * @speed: new link speed
522 * @autoneg_wait_to_complete: unused
524 s32 txgbe_setup_phy_link_speed(struct txgbe_hw *hw,
526 bool autoneg_wait_to_complete)
528 UNREFERENCED_PARAMETER(autoneg_wait_to_complete);
530 DEBUGFUNC("txgbe_setup_phy_link_speed");
533 * Clear autoneg_advertised and set new values based on input link
536 hw->phy.autoneg_advertised = 0;
538 if (speed & TXGBE_LINK_SPEED_10GB_FULL)
539 hw->phy.autoneg_advertised |= TXGBE_LINK_SPEED_10GB_FULL;
541 if (speed & TXGBE_LINK_SPEED_5GB_FULL)
542 hw->phy.autoneg_advertised |= TXGBE_LINK_SPEED_5GB_FULL;
544 if (speed & TXGBE_LINK_SPEED_2_5GB_FULL)
545 hw->phy.autoneg_advertised |= TXGBE_LINK_SPEED_2_5GB_FULL;
547 if (speed & TXGBE_LINK_SPEED_1GB_FULL)
548 hw->phy.autoneg_advertised |= TXGBE_LINK_SPEED_1GB_FULL;
550 if (speed & TXGBE_LINK_SPEED_100M_FULL)
551 hw->phy.autoneg_advertised |= TXGBE_LINK_SPEED_100M_FULL;
553 if (speed & TXGBE_LINK_SPEED_10M_FULL)
554 hw->phy.autoneg_advertised |= TXGBE_LINK_SPEED_10M_FULL;
556 /* Setup link based on the new speed settings */
557 hw->phy.setup_link(hw);
562 s32 txgbe_get_phy_fw_version(struct txgbe_hw *hw, u32 *fw_version)
564 u16 eeprom_verh, eeprom_verl;
566 hw->rom.readw_sw(hw, TXGBE_EEPROM_VERSION_H, &eeprom_verh);
567 hw->rom.readw_sw(hw, TXGBE_EEPROM_VERSION_L, &eeprom_verl);
569 *fw_version = (eeprom_verh << 16) | eeprom_verl;
575 * txgbe_get_copper_speeds_supported - Get copper link speeds from phy
576 * @hw: pointer to hardware structure
578 * Determines the supported link capabilities by reading the PHY auto
579 * negotiation register.
581 static s32 txgbe_get_copper_speeds_supported(struct txgbe_hw *hw)
586 err = hw->phy.read_reg(hw, TXGBE_MD_PHY_SPEED_ABILITY,
587 TXGBE_MD_DEV_PMA_PMD,
592 if (speed_ability & TXGBE_MD_PHY_SPEED_10G)
593 hw->phy.speeds_supported |= TXGBE_LINK_SPEED_10GB_FULL;
594 if (speed_ability & TXGBE_MD_PHY_SPEED_1G)
595 hw->phy.speeds_supported |= TXGBE_LINK_SPEED_1GB_FULL;
596 if (speed_ability & TXGBE_MD_PHY_SPEED_100M)
597 hw->phy.speeds_supported |= TXGBE_LINK_SPEED_100M_FULL;
603 * txgbe_get_copper_link_capabilities - Determines link capabilities
604 * @hw: pointer to hardware structure
605 * @speed: pointer to link speed
606 * @autoneg: boolean auto-negotiation value
608 s32 txgbe_get_copper_link_capabilities(struct txgbe_hw *hw,
614 DEBUGFUNC("txgbe_get_copper_link_capabilities");
617 if (!hw->phy.speeds_supported)
618 err = txgbe_get_copper_speeds_supported(hw);
620 *speed = hw->phy.speeds_supported;
625 * txgbe_check_phy_link_tnx - Determine link and speed status
626 * @hw: pointer to hardware structure
627 * @speed: current link speed
628 * @link_up: true is link is up, false otherwise
630 * Reads the VS1 register to determine if link is up and the current speed for
633 s32 txgbe_check_phy_link_tnx(struct txgbe_hw *hw, u32 *speed,
638 u32 max_time_out = 10;
643 DEBUGFUNC("txgbe_check_phy_link_tnx");
645 /* Initialize speed and link to default case */
647 *speed = TXGBE_LINK_SPEED_10GB_FULL;
650 * Check current speed and link status of the PHY register.
651 * This is a vendor specific register and may have to
652 * be changed for other copper PHYs.
654 for (time_out = 0; time_out < max_time_out; time_out++) {
656 err = hw->phy.read_reg(hw,
657 TXGBE_MD_VENDOR_SPECIFIC_1_STATUS,
658 TXGBE_MD_DEV_VENDOR_1,
660 phy_link = phy_data & TXGBE_MD_VENDOR_SPECIFIC_1_LINK_STATUS;
661 phy_speed = phy_data &
662 TXGBE_MD_VENDOR_SPECIFIC_1_SPEED_STATUS;
663 if (phy_link == TXGBE_MD_VENDOR_SPECIFIC_1_LINK_STATUS) {
666 TXGBE_MD_VENDOR_SPECIFIC_1_SPEED_STATUS)
667 *speed = TXGBE_LINK_SPEED_1GB_FULL;
676 * txgbe_setup_phy_link_tnx - Set and restart auto-neg
677 * @hw: pointer to hardware structure
679 * Restart auto-negotiation and PHY and waits for completion.
681 s32 txgbe_setup_phy_link_tnx(struct txgbe_hw *hw)
684 u16 autoneg_reg = TXGBE_MII_AUTONEG_REG;
685 bool autoneg = false;
688 DEBUGFUNC("txgbe_setup_phy_link_tnx");
690 txgbe_get_copper_link_capabilities(hw, &speed, &autoneg);
692 if (speed & TXGBE_LINK_SPEED_10GB_FULL) {
693 /* Set or unset auto-negotiation 10G advertisement */
694 hw->phy.read_reg(hw, TXGBE_MII_10GBASE_T_AUTONEG_CTRL_REG,
695 TXGBE_MD_DEV_AUTO_NEG,
698 autoneg_reg &= ~TXGBE_MII_10GBASE_T_ADVERTISE;
699 if (hw->phy.autoneg_advertised & TXGBE_LINK_SPEED_10GB_FULL)
700 autoneg_reg |= TXGBE_MII_10GBASE_T_ADVERTISE;
702 hw->phy.write_reg(hw, TXGBE_MII_10GBASE_T_AUTONEG_CTRL_REG,
703 TXGBE_MD_DEV_AUTO_NEG,
707 if (speed & TXGBE_LINK_SPEED_1GB_FULL) {
708 /* Set or unset auto-negotiation 1G advertisement */
709 hw->phy.read_reg(hw, TXGBE_MII_AUTONEG_XNP_TX_REG,
710 TXGBE_MD_DEV_AUTO_NEG,
713 autoneg_reg &= ~TXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX;
714 if (hw->phy.autoneg_advertised & TXGBE_LINK_SPEED_1GB_FULL)
715 autoneg_reg |= TXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX;
717 hw->phy.write_reg(hw, TXGBE_MII_AUTONEG_XNP_TX_REG,
718 TXGBE_MD_DEV_AUTO_NEG,
722 if (speed & TXGBE_LINK_SPEED_100M_FULL) {
723 /* Set or unset auto-negotiation 100M advertisement */
724 hw->phy.read_reg(hw, TXGBE_MII_AUTONEG_ADVERTISE_REG,
725 TXGBE_MD_DEV_AUTO_NEG,
728 autoneg_reg &= ~TXGBE_MII_100BASE_T_ADVERTISE;
729 if (hw->phy.autoneg_advertised & TXGBE_LINK_SPEED_100M_FULL)
730 autoneg_reg |= TXGBE_MII_100BASE_T_ADVERTISE;
732 hw->phy.write_reg(hw, TXGBE_MII_AUTONEG_ADVERTISE_REG,
733 TXGBE_MD_DEV_AUTO_NEG,
737 /* Blocked by MNG FW so don't reset PHY */
738 if (txgbe_check_reset_blocked(hw))
741 /* Restart PHY auto-negotiation. */
742 hw->phy.read_reg(hw, TXGBE_MD_AUTO_NEG_CONTROL,
743 TXGBE_MD_DEV_AUTO_NEG, &autoneg_reg);
745 autoneg_reg |= TXGBE_MII_RESTART;
747 hw->phy.write_reg(hw, TXGBE_MD_AUTO_NEG_CONTROL,
748 TXGBE_MD_DEV_AUTO_NEG, autoneg_reg);
754 * txgbe_identify_module - Identifies module type
755 * @hw: pointer to hardware structure
757 * Determines HW type and calls appropriate function.
759 s32 txgbe_identify_module(struct txgbe_hw *hw)
761 s32 err = TXGBE_ERR_SFP_NOT_PRESENT;
763 DEBUGFUNC("txgbe_identify_module");
765 switch (hw->phy.media_type) {
766 case txgbe_media_type_fiber:
767 err = txgbe_identify_sfp_module(hw);
770 case txgbe_media_type_fiber_qsfp:
771 err = txgbe_identify_qsfp_module(hw);
775 hw->phy.sfp_type = txgbe_sfp_type_not_present;
776 err = TXGBE_ERR_SFP_NOT_PRESENT;
784 * txgbe_identify_sfp_module - Identifies SFP modules
785 * @hw: pointer to hardware structure
787 * Searches for and identifies the SFP module and assigns appropriate PHY type.
789 s32 txgbe_identify_sfp_module(struct txgbe_hw *hw)
791 s32 err = TXGBE_ERR_PHY_ADDR_INVALID;
793 enum txgbe_sfp_type stored_sfp_type = hw->phy.sfp_type;
795 u8 comp_codes_1g = 0;
796 u8 comp_codes_10g = 0;
797 u8 oui_bytes[3] = {0, 0, 0};
802 DEBUGFUNC("txgbe_identify_sfp_module");
804 if (hw->phy.media_type != txgbe_media_type_fiber) {
805 hw->phy.sfp_type = txgbe_sfp_type_not_present;
806 return TXGBE_ERR_SFP_NOT_PRESENT;
809 err = hw->phy.read_i2c_eeprom(hw, TXGBE_SFF_IDENTIFIER,
813 hw->phy.sfp_type = txgbe_sfp_type_not_present;
814 if (hw->phy.type != txgbe_phy_nl) {
816 hw->phy.type = txgbe_phy_unknown;
818 return TXGBE_ERR_SFP_NOT_PRESENT;
821 if (identifier != TXGBE_SFF_IDENTIFIER_SFP) {
822 hw->phy.type = txgbe_phy_sfp_unsupported;
823 return TXGBE_ERR_SFP_NOT_SUPPORTED;
826 err = hw->phy.read_i2c_eeprom(hw, TXGBE_SFF_1GBE_COMP_CODES,
831 err = hw->phy.read_i2c_eeprom(hw, TXGBE_SFF_10GBE_COMP_CODES,
836 err = hw->phy.read_i2c_eeprom(hw, TXGBE_SFF_CABLE_TECHNOLOGY,
846 * 3 SFP_DA_CORE0 - chip-specific
847 * 4 SFP_DA_CORE1 - chip-specific
848 * 5 SFP_SR/LR_CORE0 - chip-specific
849 * 6 SFP_SR/LR_CORE1 - chip-specific
850 * 7 SFP_act_lmt_DA_CORE0 - chip-specific
851 * 8 SFP_act_lmt_DA_CORE1 - chip-specific
852 * 9 SFP_1g_cu_CORE0 - chip-specific
853 * 10 SFP_1g_cu_CORE1 - chip-specific
854 * 11 SFP_1g_sx_CORE0 - chip-specific
855 * 12 SFP_1g_sx_CORE1 - chip-specific
857 if (cable_tech & TXGBE_SFF_CABLE_DA_PASSIVE) {
858 if (hw->bus.lan_id == 0)
859 hw->phy.sfp_type = txgbe_sfp_type_da_cu_core0;
861 hw->phy.sfp_type = txgbe_sfp_type_da_cu_core1;
862 } else if (cable_tech & TXGBE_SFF_CABLE_DA_ACTIVE) {
863 err = hw->phy.read_i2c_eeprom(hw,
864 TXGBE_SFF_CABLE_SPEC_COMP, &cable_spec);
867 if (cable_spec & TXGBE_SFF_DA_SPEC_ACTIVE_LIMITING) {
868 hw->phy.sfp_type = (hw->bus.lan_id == 0
869 ? txgbe_sfp_type_da_act_lmt_core0
870 : txgbe_sfp_type_da_act_lmt_core1);
872 hw->phy.sfp_type = txgbe_sfp_type_unknown;
874 } else if (comp_codes_10g &
875 (TXGBE_SFF_10GBASESR_CAPABLE |
876 TXGBE_SFF_10GBASELR_CAPABLE)) {
877 hw->phy.sfp_type = (hw->bus.lan_id == 0
878 ? txgbe_sfp_type_srlr_core0
879 : txgbe_sfp_type_srlr_core1);
880 } else if (comp_codes_1g & TXGBE_SFF_1GBASET_CAPABLE) {
881 hw->phy.sfp_type = (hw->bus.lan_id == 0
882 ? txgbe_sfp_type_1g_cu_core0
883 : txgbe_sfp_type_1g_cu_core1);
884 } else if (comp_codes_1g & TXGBE_SFF_1GBASESX_CAPABLE) {
885 hw->phy.sfp_type = (hw->bus.lan_id == 0
886 ? txgbe_sfp_type_1g_sx_core0
887 : txgbe_sfp_type_1g_sx_core1);
888 } else if (comp_codes_1g & TXGBE_SFF_1GBASELX_CAPABLE) {
889 hw->phy.sfp_type = (hw->bus.lan_id == 0
890 ? txgbe_sfp_type_1g_lx_core0
891 : txgbe_sfp_type_1g_lx_core1);
893 hw->phy.sfp_type = txgbe_sfp_type_unknown;
896 if (hw->phy.sfp_type != stored_sfp_type)
897 hw->phy.sfp_setup_needed = true;
899 /* Determine if the SFP+ PHY is dual speed or not. */
900 hw->phy.multispeed_fiber = false;
901 if (((comp_codes_1g & TXGBE_SFF_1GBASESX_CAPABLE) &&
902 (comp_codes_10g & TXGBE_SFF_10GBASESR_CAPABLE)) ||
903 ((comp_codes_1g & TXGBE_SFF_1GBASELX_CAPABLE) &&
904 (comp_codes_10g & TXGBE_SFF_10GBASELR_CAPABLE)))
905 hw->phy.multispeed_fiber = true;
907 /* Determine PHY vendor */
908 if (hw->phy.type != txgbe_phy_nl) {
909 hw->phy.id = identifier;
910 err = hw->phy.read_i2c_eeprom(hw,
911 TXGBE_SFF_VENDOR_OUI_BYTE0, &oui_bytes[0]);
915 err = hw->phy.read_i2c_eeprom(hw,
916 TXGBE_SFF_VENDOR_OUI_BYTE1, &oui_bytes[1]);
920 err = hw->phy.read_i2c_eeprom(hw,
921 TXGBE_SFF_VENDOR_OUI_BYTE2, &oui_bytes[2]);
925 vendor_oui = ((u32)oui_bytes[0] << 24) |
926 ((u32)oui_bytes[1] << 16) |
927 ((u32)oui_bytes[2] << 8);
928 switch (vendor_oui) {
929 case TXGBE_SFF_VENDOR_OUI_TYCO:
930 if (cable_tech & TXGBE_SFF_CABLE_DA_PASSIVE)
931 hw->phy.type = txgbe_phy_sfp_tyco_passive;
933 case TXGBE_SFF_VENDOR_OUI_FTL:
934 if (cable_tech & TXGBE_SFF_CABLE_DA_ACTIVE)
935 hw->phy.type = txgbe_phy_sfp_ftl_active;
937 hw->phy.type = txgbe_phy_sfp_ftl;
939 case TXGBE_SFF_VENDOR_OUI_AVAGO:
940 hw->phy.type = txgbe_phy_sfp_avago;
942 case TXGBE_SFF_VENDOR_OUI_INTEL:
943 hw->phy.type = txgbe_phy_sfp_intel;
946 if (cable_tech & TXGBE_SFF_CABLE_DA_PASSIVE)
947 hw->phy.type = txgbe_phy_sfp_unknown_passive;
948 else if (cable_tech & TXGBE_SFF_CABLE_DA_ACTIVE)
949 hw->phy.type = txgbe_phy_sfp_unknown_active;
951 hw->phy.type = txgbe_phy_sfp_unknown;
956 /* Allow any DA cable vendor */
957 if (cable_tech & (TXGBE_SFF_CABLE_DA_PASSIVE |
958 TXGBE_SFF_CABLE_DA_ACTIVE)) {
962 /* Verify supported 1G SFP modules */
963 if (comp_codes_10g == 0 &&
964 !(hw->phy.sfp_type == txgbe_sfp_type_1g_cu_core1 ||
965 hw->phy.sfp_type == txgbe_sfp_type_1g_cu_core0 ||
966 hw->phy.sfp_type == txgbe_sfp_type_1g_lx_core0 ||
967 hw->phy.sfp_type == txgbe_sfp_type_1g_lx_core1 ||
968 hw->phy.sfp_type == txgbe_sfp_type_1g_sx_core0 ||
969 hw->phy.sfp_type == txgbe_sfp_type_1g_sx_core1)) {
970 hw->phy.type = txgbe_phy_sfp_unsupported;
971 return TXGBE_ERR_SFP_NOT_SUPPORTED;
974 hw->mac.get_device_caps(hw, &enforce_sfp);
975 if (!(enforce_sfp & TXGBE_DEVICE_CAPS_ALLOW_ANY_SFP) &&
976 !hw->allow_unsupported_sfp &&
977 !(hw->phy.sfp_type == txgbe_sfp_type_1g_cu_core0 ||
978 hw->phy.sfp_type == txgbe_sfp_type_1g_cu_core1 ||
979 hw->phy.sfp_type == txgbe_sfp_type_1g_lx_core0 ||
980 hw->phy.sfp_type == txgbe_sfp_type_1g_lx_core1 ||
981 hw->phy.sfp_type == txgbe_sfp_type_1g_sx_core0 ||
982 hw->phy.sfp_type == txgbe_sfp_type_1g_sx_core1)) {
983 DEBUGOUT("SFP+ module not supported\n");
984 hw->phy.type = txgbe_phy_sfp_unsupported;
985 return TXGBE_ERR_SFP_NOT_SUPPORTED;
992 * txgbe_identify_qsfp_module - Identifies QSFP modules
993 * @hw: pointer to hardware structure
995 * Searches for and identifies the QSFP module and assigns appropriate PHY type
997 s32 txgbe_identify_qsfp_module(struct txgbe_hw *hw)
999 s32 err = TXGBE_ERR_PHY_ADDR_INVALID;
1001 enum txgbe_sfp_type stored_sfp_type = hw->phy.sfp_type;
1003 u8 comp_codes_1g = 0;
1004 u8 comp_codes_10g = 0;
1005 u8 oui_bytes[3] = {0, 0, 0};
1006 u16 enforce_sfp = 0;
1008 u8 cable_length = 0;
1010 bool active_cable = false;
1012 DEBUGFUNC("txgbe_identify_qsfp_module");
1014 if (hw->phy.media_type != txgbe_media_type_fiber_qsfp) {
1015 hw->phy.sfp_type = txgbe_sfp_type_not_present;
1016 err = TXGBE_ERR_SFP_NOT_PRESENT;
1020 err = hw->phy.read_i2c_eeprom(hw, TXGBE_SFF_IDENTIFIER,
1024 hw->phy.sfp_type = txgbe_sfp_type_not_present;
1026 hw->phy.type = txgbe_phy_unknown;
1027 return TXGBE_ERR_SFP_NOT_PRESENT;
1029 if (identifier != TXGBE_SFF_IDENTIFIER_QSFP_PLUS) {
1030 hw->phy.type = txgbe_phy_sfp_unsupported;
1031 err = TXGBE_ERR_SFP_NOT_SUPPORTED;
1035 hw->phy.id = identifier;
1037 err = hw->phy.read_i2c_eeprom(hw, TXGBE_SFF_QSFP_10GBE_COMP,
1043 err = hw->phy.read_i2c_eeprom(hw, TXGBE_SFF_QSFP_1GBE_COMP,
1049 if (comp_codes_10g & TXGBE_SFF_QSFP_DA_PASSIVE_CABLE) {
1050 hw->phy.type = txgbe_phy_qsfp_unknown_passive;
1051 if (hw->bus.lan_id == 0)
1052 hw->phy.sfp_type = txgbe_sfp_type_da_cu_core0;
1054 hw->phy.sfp_type = txgbe_sfp_type_da_cu_core1;
1055 } else if (comp_codes_10g & (TXGBE_SFF_10GBASESR_CAPABLE |
1056 TXGBE_SFF_10GBASELR_CAPABLE)) {
1057 if (hw->bus.lan_id == 0)
1058 hw->phy.sfp_type = txgbe_sfp_type_srlr_core0;
1060 hw->phy.sfp_type = txgbe_sfp_type_srlr_core1;
1062 if (comp_codes_10g & TXGBE_SFF_QSFP_DA_ACTIVE_CABLE)
1063 active_cable = true;
1065 if (!active_cable) {
1066 hw->phy.read_i2c_eeprom(hw,
1067 TXGBE_SFF_QSFP_CONNECTOR,
1070 hw->phy.read_i2c_eeprom(hw,
1071 TXGBE_SFF_QSFP_CABLE_LENGTH,
1074 hw->phy.read_i2c_eeprom(hw,
1075 TXGBE_SFF_QSFP_DEVICE_TECH,
1079 TXGBE_SFF_QSFP_CONNECTOR_NOT_SEPARABLE &&
1081 ((device_tech >> 4) ==
1082 TXGBE_SFF_QSFP_TRANSMITTER_850NM_VCSEL))
1083 active_cable = true;
1087 hw->phy.type = txgbe_phy_qsfp_unknown_active;
1088 if (hw->bus.lan_id == 0)
1090 txgbe_sfp_type_da_act_lmt_core0;
1093 txgbe_sfp_type_da_act_lmt_core1;
1095 /* unsupported module type */
1096 hw->phy.type = txgbe_phy_sfp_unsupported;
1097 err = TXGBE_ERR_SFP_NOT_SUPPORTED;
1102 if (hw->phy.sfp_type != stored_sfp_type)
1103 hw->phy.sfp_setup_needed = true;
1105 /* Determine if the QSFP+ PHY is dual speed or not. */
1106 hw->phy.multispeed_fiber = false;
1107 if (((comp_codes_1g & TXGBE_SFF_1GBASESX_CAPABLE) &&
1108 (comp_codes_10g & TXGBE_SFF_10GBASESR_CAPABLE)) ||
1109 ((comp_codes_1g & TXGBE_SFF_1GBASELX_CAPABLE) &&
1110 (comp_codes_10g & TXGBE_SFF_10GBASELR_CAPABLE)))
1111 hw->phy.multispeed_fiber = true;
1113 /* Determine PHY vendor for optical modules */
1114 if (comp_codes_10g & (TXGBE_SFF_10GBASESR_CAPABLE |
1115 TXGBE_SFF_10GBASELR_CAPABLE)) {
1116 err = hw->phy.read_i2c_eeprom(hw,
1117 TXGBE_SFF_QSFP_VENDOR_OUI_BYTE0,
1123 err = hw->phy.read_i2c_eeprom(hw,
1124 TXGBE_SFF_QSFP_VENDOR_OUI_BYTE1,
1130 err = hw->phy.read_i2c_eeprom(hw,
1131 TXGBE_SFF_QSFP_VENDOR_OUI_BYTE2,
1138 ((oui_bytes[0] << 24) |
1139 (oui_bytes[1] << 16) |
1140 (oui_bytes[2] << 8));
1142 if (vendor_oui == TXGBE_SFF_VENDOR_OUI_INTEL)
1143 hw->phy.type = txgbe_phy_qsfp_intel;
1145 hw->phy.type = txgbe_phy_qsfp_unknown;
1147 hw->mac.get_device_caps(hw, &enforce_sfp);
1148 if (!(enforce_sfp & TXGBE_DEVICE_CAPS_ALLOW_ANY_SFP)) {
1149 /* Make sure we're a supported PHY type */
1150 if (hw->phy.type == txgbe_phy_qsfp_intel) {
1153 if (hw->allow_unsupported_sfp) {
1154 DEBUGOUT("WARNING: Wangxun (R) Network Connections are quality tested using Wangxun (R) Ethernet Optics. "
1155 "Using untested modules is not supported and may cause unstable operation or damage to the module or the adapter. "
1156 "Wangxun Corporation is not responsible for any harm caused by using untested modules.\n");
1159 DEBUGOUT("QSFP module not supported\n");
1161 txgbe_phy_sfp_unsupported;
1162 err = TXGBE_ERR_SFP_NOT_SUPPORTED;
1175 * txgbe_read_i2c_eeprom - Reads 8 bit EEPROM word over I2C interface
1176 * @hw: pointer to hardware structure
1177 * @byte_offset: EEPROM byte offset to read
1178 * @eeprom_data: value read
1180 * Performs byte read operation to SFP module's EEPROM over I2C interface.
1182 s32 txgbe_read_i2c_eeprom(struct txgbe_hw *hw, u8 byte_offset,
1185 DEBUGFUNC("txgbe_read_i2c_eeprom");
1187 return hw->phy.read_i2c_byte(hw, byte_offset,
1188 TXGBE_I2C_EEPROM_DEV_ADDR,
1193 * txgbe_read_i2c_sff8472 - Reads 8 bit word over I2C interface
1194 * @hw: pointer to hardware structure
1195 * @byte_offset: byte offset at address 0xA2
1196 * @sff8472_data: value read
1198 * Performs byte read operation to SFP module's SFF-8472 data over I2C
1200 s32 txgbe_read_i2c_sff8472(struct txgbe_hw *hw, u8 byte_offset,
1203 return hw->phy.read_i2c_byte(hw, byte_offset,
1204 TXGBE_I2C_EEPROM_DEV_ADDR2,
1209 * txgbe_write_i2c_eeprom - Writes 8 bit EEPROM word over I2C interface
1210 * @hw: pointer to hardware structure
1211 * @byte_offset: EEPROM byte offset to write
1212 * @eeprom_data: value to write
1214 * Performs byte write operation to SFP module's EEPROM over I2C interface.
1216 s32 txgbe_write_i2c_eeprom(struct txgbe_hw *hw, u8 byte_offset,
1219 DEBUGFUNC("txgbe_write_i2c_eeprom");
1221 return hw->phy.write_i2c_byte(hw, byte_offset,
1222 TXGBE_I2C_EEPROM_DEV_ADDR,
1227 * txgbe_read_i2c_byte_unlocked - Reads 8 bit word over I2C
1228 * @hw: pointer to hardware structure
1229 * @byte_offset: byte offset to read
1230 * @dev_addr: address to read from
1233 * Performs byte read operation to SFP module's EEPROM over I2C interface at
1234 * a specified device address.
1236 s32 txgbe_read_i2c_byte_unlocked(struct txgbe_hw *hw, u8 byte_offset,
1237 u8 dev_addr, u8 *data)
1239 UNREFERENCED_PARAMETER(dev_addr);
1241 DEBUGFUNC("txgbe_read_i2c_byte");
1243 txgbe_i2c_start(hw);
1246 if (!po32m(hw, TXGBE_I2CICR, TXGBE_I2CICR_TXEMPTY,
1247 TXGBE_I2CICR_TXEMPTY, NULL, 100, 100)) {
1248 return -TERR_TIMEOUT;
1252 wr32(hw, TXGBE_I2CDATA,
1253 byte_offset | TXGBE_I2CDATA_STOP);
1254 wr32(hw, TXGBE_I2CDATA, TXGBE_I2CDATA_READ);
1256 /* wait for read complete */
1257 if (!po32m(hw, TXGBE_I2CICR, TXGBE_I2CICR_RXFULL,
1258 TXGBE_I2CICR_RXFULL, NULL, 100, 100)) {
1259 return -TERR_TIMEOUT;
1264 *data = 0xFF & rd32(hw, TXGBE_I2CDATA);
1270 * txgbe_read_i2c_byte - Reads 8 bit word over I2C
1271 * @hw: pointer to hardware structure
1272 * @byte_offset: byte offset to read
1273 * @dev_addr: address to read from
1276 * Performs byte read operation to SFP module's EEPROM over I2C interface at
1277 * a specified device address.
1279 s32 txgbe_read_i2c_byte(struct txgbe_hw *hw, u8 byte_offset,
1280 u8 dev_addr, u8 *data)
1282 u32 swfw_mask = hw->phy.phy_semaphore_mask;
1285 if (hw->mac.acquire_swfw_sync(hw, swfw_mask))
1286 return TXGBE_ERR_SWFW_SYNC;
1287 err = txgbe_read_i2c_byte_unlocked(hw, byte_offset, dev_addr, data);
1288 hw->mac.release_swfw_sync(hw, swfw_mask);
1293 * txgbe_write_i2c_byte_unlocked - Writes 8 bit word over I2C
1294 * @hw: pointer to hardware structure
1295 * @byte_offset: byte offset to write
1296 * @dev_addr: address to write to
1297 * @data: value to write
1299 * Performs byte write operation to SFP module's EEPROM over I2C interface at
1300 * a specified device address.
1302 s32 txgbe_write_i2c_byte_unlocked(struct txgbe_hw *hw, u8 byte_offset,
1303 u8 dev_addr, u8 data)
1305 UNREFERENCED_PARAMETER(dev_addr);
1307 DEBUGFUNC("txgbe_write_i2c_byte");
1309 txgbe_i2c_start(hw);
1312 if (!po32m(hw, TXGBE_I2CICR, TXGBE_I2CICR_TXEMPTY,
1313 TXGBE_I2CICR_TXEMPTY, NULL, 100, 100)) {
1314 return -TERR_TIMEOUT;
1317 wr32(hw, TXGBE_I2CDATA, byte_offset | TXGBE_I2CDATA_STOP);
1318 wr32(hw, TXGBE_I2CDATA, data | TXGBE_I2CDATA_WRITE);
1320 /* wait for write complete */
1321 if (!po32m(hw, TXGBE_I2CICR, TXGBE_I2CICR_RXFULL,
1322 TXGBE_I2CICR_RXFULL, NULL, 100, 100)) {
1323 return -TERR_TIMEOUT;
1331 * txgbe_write_i2c_byte - Writes 8 bit word over I2C
1332 * @hw: pointer to hardware structure
1333 * @byte_offset: byte offset to write
1334 * @dev_addr: address to write to
1335 * @data: value to write
1337 * Performs byte write operation to SFP module's EEPROM over I2C interface at
1338 * a specified device address.
1340 s32 txgbe_write_i2c_byte(struct txgbe_hw *hw, u8 byte_offset,
1341 u8 dev_addr, u8 data)
1343 u32 swfw_mask = hw->phy.phy_semaphore_mask;
1346 if (hw->mac.acquire_swfw_sync(hw, swfw_mask))
1347 return TXGBE_ERR_SWFW_SYNC;
1348 err = txgbe_write_i2c_byte_unlocked(hw, byte_offset, dev_addr, data);
1349 hw->mac.release_swfw_sync(hw, swfw_mask);
1355 * txgbe_i2c_start - Sets I2C start condition
1356 * @hw: pointer to hardware structure
1358 * Sets I2C start condition (High -> Low on SDA while SCL is High)
1360 static void txgbe_i2c_start(struct txgbe_hw *hw)
1362 DEBUGFUNC("txgbe_i2c_start");
1364 wr32(hw, TXGBE_I2CENA, 0);
1366 wr32(hw, TXGBE_I2CCON,
1367 (TXGBE_I2CCON_MENA |
1368 TXGBE_I2CCON_SPEED(1) |
1369 TXGBE_I2CCON_RESTART |
1370 TXGBE_I2CCON_SDIA));
1371 wr32(hw, TXGBE_I2CTAR, TXGBE_I2C_SLAVEADDR);
1372 wr32(hw, TXGBE_I2CSSSCLHCNT, 600);
1373 wr32(hw, TXGBE_I2CSSSCLLCNT, 600);
1374 wr32(hw, TXGBE_I2CRXTL, 0); /* 1byte for rx full signal */
1375 wr32(hw, TXGBE_I2CTXTL, 4);
1376 wr32(hw, TXGBE_I2CSCLTMOUT, 0xFFFFFF);
1377 wr32(hw, TXGBE_I2CSDATMOUT, 0xFFFFFF);
1379 wr32(hw, TXGBE_I2CICM, 0);
1380 wr32(hw, TXGBE_I2CENA, 1);
1384 * txgbe_i2c_stop - Sets I2C stop condition
1385 * @hw: pointer to hardware structure
1387 * Sets I2C stop condition (Low -> High on SDA while SCL is High)
1389 static void txgbe_i2c_stop(struct txgbe_hw *hw)
1391 DEBUGFUNC("txgbe_i2c_stop");
1393 /* wait for completion */
1394 if (!po32m(hw, TXGBE_I2CSTAT, TXGBE_I2CSTAT_MST,
1395 0, NULL, 100, 100)) {
1396 DEBUGFUNC("i2c stop timeout.");
1399 wr32(hw, TXGBE_I2CENA, 0);
1403 txgbe_set_sgmii_an37_ability(struct txgbe_hw *hw)
1407 wr32_epcs(hw, VR_XS_OR_PCS_MMD_DIGI_CTL1, 0x3002);
1408 wr32_epcs(hw, SR_MII_MMD_AN_CTL, 0x0105);
1409 wr32_epcs(hw, SR_MII_MMD_DIGI_CTL, 0x0200);
1410 value = rd32_epcs(hw, SR_MII_MMD_CTL);
1411 value = (value & ~0x1200) | (0x1 << 12) | (0x1 << 9);
1412 wr32_epcs(hw, SR_MII_MMD_CTL, value);
1417 txgbe_set_link_to_kr(struct txgbe_hw *hw, bool autoneg)
1423 /* 1. Wait xpcs power-up good */
1424 for (i = 0; i < 100; i++) {
1425 if ((rd32_epcs(hw, VR_XS_OR_PCS_MMD_DIGI_STATUS) &
1426 VR_XS_OR_PCS_MMD_DIGI_STATUS_PSEQ_MASK) ==
1427 VR_XS_OR_PCS_MMD_DIGI_STATUS_PSEQ_POWER_GOOD)
1432 err = TXGBE_ERR_XPCS_POWER_UP_FAILED;
1435 BP_LOG("It is set to kr.\n");
1437 wr32_epcs(hw, VR_AN_INTR_MSK, 0x7);
1438 wr32_epcs(hw, TXGBE_PHY_TX_POWER_ST_CTL, 0x00FC);
1439 wr32_epcs(hw, TXGBE_PHY_RX_POWER_ST_CTL, 0x00FC);
1442 /* 2. Disable xpcs AN-73 */
1443 wr32_epcs(hw, SR_AN_CTRL,
1444 SR_AN_CTRL_AN_EN | SR_AN_CTRL_EXT_NP);
1446 wr32_epcs(hw, VR_AN_KR_MODE_CL, VR_AN_KR_MODE_CL_PDET);
1448 if (!(hw->devarg.auto_neg == 1)) {
1449 wr32_epcs(hw, SR_AN_CTRL, 0);
1450 wr32_epcs(hw, VR_AN_KR_MODE_CL, 0);
1452 if (hw->devarg.present == 1) {
1453 value = rd32_epcs(hw, TXGBE_PHY_TX_EQ_CTL1);
1454 value |= TXGBE_PHY_TX_EQ_CTL1_DEF;
1455 wr32_epcs(hw, TXGBE_PHY_TX_EQ_CTL1, value);
1457 if (hw->devarg.poll == 1) {
1458 wr32_epcs(hw, VR_PMA_KRTR_TIMER_CTRL0,
1459 VR_PMA_KRTR_TIMER_MAX_WAIT);
1460 wr32_epcs(hw, VR_PMA_KRTR_TIMER_CTRL2, 0xA697);
1463 /* 3. Set VR_XS_PMA_Gen5_12G_MPLLA_CTRL3 Register
1464 * Bit[10:0](MPLLA_BANDWIDTH) = 11'd123 (default: 11'd16)
1466 wr32_epcs(hw, TXGBE_PHY_MPLLA_CTL3,
1467 TXGBE_PHY_MPLLA_CTL3_MULTIPLIER_BW_10GBASER_KR);
1469 /* 4. Set VR_XS_PMA_Gen5_12G_MISC_CTRL0 Register
1470 * Bit[12:8](RX_VREF_CTRL) = 5'hF (default: 5'h11)
1472 wr32_epcs(hw, TXGBE_PHY_MISC_CTL0, 0xCF00);
1474 /* 5. Set VR_XS_PMA_Gen5_12G_RX_EQ_CTRL0 Register
1475 * Bit[15:8](VGA1/2_GAIN_0) = 8'h77
1476 * Bit[7:5](CTLE_POLE_0) = 3'h2
1477 * Bit[4:0](CTLE_BOOST_0) = 4'hA
1479 wr32_epcs(hw, TXGBE_PHY_RX_EQ_CTL0, 0x774A);
1481 /* 6. Set VR_MII_Gen5_12G_RX_GENCTRL3 Register
1482 * Bit[2:0](LOS_TRSHLD_0) = 3'h4 (default: 3)
1484 wr32_epcs(hw, TXGBE_PHY_RX_GEN_CTL3, 0x0004);
1486 /* 7. Initialize the mode by setting VR XS or PCS MMD Digital
1487 * Control1 Register Bit[15](VR_RST)
1489 wr32_epcs(hw, VR_XS_OR_PCS_MMD_DIGI_CTL1, 0xA000);
1491 /* Wait phy initialization done */
1492 for (i = 0; i < 100; i++) {
1494 VR_XS_OR_PCS_MMD_DIGI_CTL1) &
1495 VR_XS_OR_PCS_MMD_DIGI_CTL1_VR_RST) == 0)
1500 err = TXGBE_ERR_PHY_INIT_NOT_DONE;
1504 wr32_epcs(hw, VR_AN_KR_MODE_CL, 0x1);
1511 txgbe_set_link_to_kx4(struct txgbe_hw *hw, bool autoneg)
1517 /* Check link status, if already set, skip setting it again */
1518 if (hw->link_status == TXGBE_LINK_STATUS_KX4)
1521 BP_LOG("It is set to kx4.\n");
1522 wr32_epcs(hw, TXGBE_PHY_TX_POWER_ST_CTL, 0);
1523 wr32_epcs(hw, TXGBE_PHY_RX_POWER_ST_CTL, 0);
1525 /* 1. Wait xpcs power-up good */
1526 for (i = 0; i < 100; i++) {
1527 if ((rd32_epcs(hw, VR_XS_OR_PCS_MMD_DIGI_STATUS) &
1528 VR_XS_OR_PCS_MMD_DIGI_STATUS_PSEQ_MASK) ==
1529 VR_XS_OR_PCS_MMD_DIGI_STATUS_PSEQ_POWER_GOOD)
1534 err = TXGBE_ERR_XPCS_POWER_UP_FAILED;
1538 wr32m(hw, TXGBE_MACTXCFG, TXGBE_MACTXCFG_TXE,
1539 ~TXGBE_MACTXCFG_TXE);
1541 /* 2. Disable xpcs AN-73 */
1543 wr32_epcs(hw, SR_AN_CTRL, 0x0);
1545 wr32_epcs(hw, SR_AN_CTRL, 0x3000);
1547 /* Disable PHY MPLLA for eth mode change(after ECO) */
1548 wr32_ephy(hw, 0x4, 0x250A);
1552 /* Set the eth change_mode bit first in mis_rst register
1553 * for corresponding LAN port
1555 wr32(hw, TXGBE_RST, TXGBE_RST_ETH(hw->bus.lan_id));
1557 /* Set SR PCS Control2 Register Bits[1:0] = 2'b01
1558 * PCS_TYPE_SEL: non KR
1560 wr32_epcs(hw, SR_XS_PCS_CTRL2,
1561 SR_PCS_CTRL2_TYPE_SEL_X);
1563 /* Set SR PMA MMD Control1 Register Bit[13] = 1'b1
1566 wr32_epcs(hw, SR_PMA_CTRL1,
1567 SR_PMA_CTRL1_SS13_KX4);
1569 value = (0xf5f0 & ~0x7F0) | (0x5 << 8) | (0x7 << 5) | 0xF0;
1570 wr32_epcs(hw, TXGBE_PHY_TX_GENCTRL1, value);
1572 if ((hw->subsystem_device_id & 0xFF) == TXGBE_DEV_ID_MAC_XAUI)
1573 wr32_epcs(hw, TXGBE_PHY_MISC_CTL0, 0xCF00);
1575 wr32_epcs(hw, TXGBE_PHY_MISC_CTL0, 0x4F00);
1577 for (i = 0; i < 4; i++) {
1579 value = (0x45 & ~0xFFFF) | (0x7 << 12) |
1582 value = (0xff06 & ~0xFFFF) | (0x7 << 12) |
1584 wr32_epcs(hw, TXGBE_PHY_RX_EQ_CTL0 + i, value);
1587 value = 0x0 & ~0x7777;
1588 wr32_epcs(hw, TXGBE_PHY_RX_EQ_ATT_LVL0, value);
1590 wr32_epcs(hw, TXGBE_PHY_DFE_TAP_CTL0, 0x0);
1592 value = (0x6db & ~0xFFF) | (0x1 << 9) | (0x1 << 6) | (0x1 << 3) | 0x1;
1593 wr32_epcs(hw, TXGBE_PHY_RX_GEN_CTL3, value);
1595 /* Set VR XS, PMA, or MII Gen5 12G PHY MPLLA
1596 * Control 0 Register Bit[7:0] = 8'd40 //MPLLA_MULTIPLIER
1598 wr32_epcs(hw, TXGBE_PHY_MPLLA_CTL0,
1599 TXGBE_PHY_MPLLA_CTL0_MULTIPLIER_OTHER);
1601 /* Set VR XS, PMA or MII Gen5 12G PHY MPLLA
1602 * Control 3 Register Bit[10:0] = 11'd86 //MPLLA_BANDWIDTH
1604 wr32_epcs(hw, TXGBE_PHY_MPLLA_CTL3,
1605 TXGBE_PHY_MPLLA_CTL3_MULTIPLIER_BW_OTHER);
1607 /* Set VR XS, PMA, or MII Gen5 12G PHY VCO
1608 * Calibration Load 0 Register Bit[12:0] = 13'd1360 //VCO_LD_VAL_0
1610 wr32_epcs(hw, TXGBE_PHY_VCO_CAL_LD0,
1611 TXGBE_PHY_VCO_CAL_LD0_OTHER);
1613 /* Set VR XS, PMA, or MII Gen5 12G PHY VCO
1614 * Calibration Load 1 Register Bit[12:0] = 13'd1360 //VCO_LD_VAL_1
1616 wr32_epcs(hw, TXGBE_PHY_VCO_CAL_LD1,
1617 TXGBE_PHY_VCO_CAL_LD0_OTHER);
1619 /* Set VR XS, PMA, or MII Gen5 12G PHY VCO
1620 * Calibration Load 2 Register Bit[12:0] = 13'd1360 //VCO_LD_VAL_2
1622 wr32_epcs(hw, TXGBE_PHY_VCO_CAL_LD2,
1623 TXGBE_PHY_VCO_CAL_LD0_OTHER);
1624 /* Set VR XS, PMA, or MII Gen5 12G PHY VCO
1625 * Calibration Load 3 Register Bit[12:0] = 13'd1360 //VCO_LD_VAL_3
1627 wr32_epcs(hw, TXGBE_PHY_VCO_CAL_LD3,
1628 TXGBE_PHY_VCO_CAL_LD0_OTHER);
1629 /* Set VR XS, PMA, or MII Gen5 12G PHY VCO
1630 * Calibration Reference 0 Register Bit[5:0] = 6'd34 //VCO_REF_LD_0/1
1632 wr32_epcs(hw, TXGBE_PHY_VCO_CAL_REF0, 0x2222);
1634 /* Set VR XS, PMA, or MII Gen5 12G PHY VCO
1635 * Calibration Reference 1 Register Bit[5:0] = 6'd34 //VCO_REF_LD_2/3
1637 wr32_epcs(hw, TXGBE_PHY_VCO_CAL_REF1, 0x2222);
1639 /* Set VR XS, PMA, or MII Gen5 12G PHY AFE-DFE
1640 * Enable Register Bit[7:0] = 8'd0 //AFE_EN_0/3_1, DFE_EN_0/3_1
1642 wr32_epcs(hw, TXGBE_PHY_AFE_DFE_ENABLE, 0x0);
1644 /* Set VR XS, PMA, or MII Gen5 12G PHY Rx
1645 * Equalization Control 4 Register Bit[3:0] = 4'd0 //CONT_ADAPT_0/3_1
1647 wr32_epcs(hw, TXGBE_PHY_RX_EQ_CTL, 0x00F0);
1649 /* Set VR XS, PMA, or MII Gen5 12G PHY Tx Rate
1650 * Control Register Bit[14:12], Bit[10:8], Bit[6:4], Bit[2:0],
1651 * all rates to 3'b010 //TX0/1/2/3_RATE
1653 wr32_epcs(hw, TXGBE_PHY_TX_RATE_CTL, 0x2222);
1655 /* Set VR XS, PMA, or MII Gen5 12G PHY Rx Rate
1656 * Control Register Bit[13:12], Bit[9:8], Bit[5:4], Bit[1:0],
1657 * all rates to 2'b10 //RX0/1/2/3_RATE
1659 wr32_epcs(hw, TXGBE_PHY_RX_RATE_CTL, 0x2222);
1661 /* Set VR XS, PMA, or MII Gen5 12G PHY Tx General
1662 * Control 2 Register Bit[15:8] = 2'b01 //TX0/1/2/3_WIDTH: 10bits
1664 wr32_epcs(hw, TXGBE_PHY_TX_GEN_CTL2, 0x5500);
1666 /* Set VR XS, PMA, or MII Gen5 12G PHY Rx General
1667 * Control 2 Register Bit[15:8] = 2'b01 //RX0/1/2/3_WIDTH: 10bits
1669 wr32_epcs(hw, TXGBE_PHY_RX_GEN_CTL2, 0x5500);
1671 /* Set VR XS, PMA, or MII Gen5 12G PHY MPLLA Control
1672 * 2 Register Bit[10:8] = 3'b010
1673 * MPLLA_DIV16P5_CLK_EN=0, MPLLA_DIV10_CLK_EN=1, MPLLA_DIV8_CLK_EN=0
1675 wr32_epcs(hw, TXGBE_PHY_MPLLA_CTL2,
1676 TXGBE_PHY_MPLLA_CTL2_DIV_CLK_EN_10);
1678 wr32_epcs(hw, 0x1f0000, 0x0);
1679 wr32_epcs(hw, 0x1f8001, 0x0);
1680 wr32_epcs(hw, SR_MII_MMD_DIGI_CTL, 0x0);
1682 /* 10. Initialize the mode by setting VR XS or PCS MMD Digital Control1
1683 * Register Bit[15](VR_RST)
1685 wr32_epcs(hw, VR_XS_OR_PCS_MMD_DIGI_CTL1, 0xA000);
1687 /* Wait phy initialization done */
1688 for (i = 0; i < 100; i++) {
1689 if ((rd32_epcs(hw, VR_XS_OR_PCS_MMD_DIGI_CTL1) &
1690 VR_XS_OR_PCS_MMD_DIGI_CTL1_VR_RST) == 0)
1695 /* If success, set link status */
1696 hw->link_status = TXGBE_LINK_STATUS_KX4;
1699 err = TXGBE_ERR_PHY_INIT_NOT_DONE;
1703 if (hw->fw_version <= TXGBE_FW_N_TXEQ) {
1704 value = (0x1804 & ~0x3F3F);
1705 wr32_epcs(hw, TXGBE_PHY_TX_EQ_CTL0, value);
1707 value = (0x50 & ~0x7F) | 40 | (1 << 6);
1708 wr32_epcs(hw, TXGBE_PHY_TX_EQ_CTL1, value);
1715 txgbe_set_link_to_kx(struct txgbe_hw *hw,
1724 /* Check link status, if already set, skip setting it again */
1725 if (hw->link_status == TXGBE_LINK_STATUS_KX)
1728 BP_LOG("It is set to kx. speed =0x%x\n", speed);
1729 wr32_epcs(hw, TXGBE_PHY_TX_POWER_ST_CTL, 0x00FC);
1730 wr32_epcs(hw, TXGBE_PHY_RX_POWER_ST_CTL, 0x00FC);
1732 /* 1. Wait xpcs power-up good */
1733 for (i = 0; i < 100; i++) {
1734 if ((rd32_epcs(hw, VR_XS_OR_PCS_MMD_DIGI_STATUS) &
1735 VR_XS_OR_PCS_MMD_DIGI_STATUS_PSEQ_MASK) ==
1736 VR_XS_OR_PCS_MMD_DIGI_STATUS_PSEQ_POWER_GOOD)
1741 err = TXGBE_ERR_XPCS_POWER_UP_FAILED;
1745 wr32m(hw, TXGBE_MACTXCFG, TXGBE_MACTXCFG_TXE,
1746 ~TXGBE_MACTXCFG_TXE);
1748 /* 2. Disable xpcs AN-73 */
1750 wr32_epcs(hw, SR_AN_CTRL, 0x0);
1752 wr32_epcs(hw, SR_AN_CTRL, 0x3000);
1754 /* Disable PHY MPLLA for eth mode change(after ECO) */
1755 wr32_ephy(hw, 0x4, 0x240A);
1759 /* Set the eth change_mode bit first in mis_rst register
1760 * for corresponding LAN port
1762 wr32(hw, TXGBE_RST, TXGBE_RST_ETH(hw->bus.lan_id));
1764 /* Set SR PCS Control2 Register Bits[1:0] = 2'b01
1765 * PCS_TYPE_SEL: non KR
1767 wr32_epcs(hw, SR_XS_PCS_CTRL2,
1768 SR_PCS_CTRL2_TYPE_SEL_X);
1770 /* Set SR PMA MMD Control1 Register Bit[13] = 1'b0
1773 wr32_epcs(hw, SR_PMA_CTRL1,
1774 SR_PMA_CTRL1_SS13_KX);
1776 /* Set SR MII MMD Control Register to corresponding speed: {Bit[6],
1777 * Bit[13]}=[2'b00,2'b01,2'b10]->[10M,100M,1G]
1779 if (speed == TXGBE_LINK_SPEED_100M_FULL)
1781 else if (speed == TXGBE_LINK_SPEED_1GB_FULL)
1783 else if (speed == TXGBE_LINK_SPEED_10M_FULL)
1785 wr32_epcs(hw, SR_MII_MMD_CTL,
1788 value = (0xf5f0 & ~0x710) | (0x5 << 8) | 0x10;
1789 wr32_epcs(hw, TXGBE_PHY_TX_GENCTRL1, value);
1791 if (hw->devarg.sgmii == 1)
1792 wr32_epcs(hw, TXGBE_PHY_MISC_CTL0, 0x4F00);
1794 wr32_epcs(hw, TXGBE_PHY_MISC_CTL0, 0xCF00);
1796 for (i = 0; i < 4; i++) {
1800 value = (0x45 & ~0xFFFF) | (0x7 << 12) |
1803 wr32_epcs(hw, TXGBE_PHY_RX_EQ_CTL0 + i, value);
1807 wr32_epcs(hw, TXGBE_PHY_RX_EQ_ATT_LVL0, value);
1809 wr32_epcs(hw, TXGBE_PHY_DFE_TAP_CTL0, 0x0);
1811 value = (0x6db & ~0x7) | 0x4;
1812 wr32_epcs(hw, TXGBE_PHY_RX_GEN_CTL3, value);
1814 /* Set VR XS, PMA, or MII Gen5 12G PHY MPLLA Control
1815 * 0 Register Bit[7:0] = 8'd32 //MPLLA_MULTIPLIER
1817 wr32_epcs(hw, TXGBE_PHY_MPLLA_CTL0,
1818 TXGBE_PHY_MPLLA_CTL0_MULTIPLIER_1GBASEX_KX);
1820 /* Set VR XS, PMA or MII Gen5 12G PHY MPLLA Control
1821 * 3 Register Bit[10:0] = 11'd70 //MPLLA_BANDWIDTH
1823 wr32_epcs(hw, TXGBE_PHY_MPLLA_CTL3,
1824 TXGBE_PHY_MPLLA_CTL3_MULTIPLIER_BW_1GBASEX_KX);
1826 /* Set VR XS, PMA, or MII Gen5 12G PHY VCO
1827 * Calibration Load 0 Register Bit[12:0] = 13'd1344 //VCO_LD_VAL_0
1829 wr32_epcs(hw, TXGBE_PHY_VCO_CAL_LD0,
1830 TXGBE_PHY_VCO_CAL_LD0_1GBASEX_KX);
1832 wr32_epcs(hw, TXGBE_PHY_VCO_CAL_LD1, 0x549);
1833 wr32_epcs(hw, TXGBE_PHY_VCO_CAL_LD2, 0x549);
1834 wr32_epcs(hw, TXGBE_PHY_VCO_CAL_LD3, 0x549);
1836 /* Set VR XS, PMA, or MII Gen5 12G PHY VCO
1837 * Calibration Reference 0 Register Bit[5:0] = 6'd42 //VCO_REF_LD_0
1839 wr32_epcs(hw, TXGBE_PHY_VCO_CAL_REF0,
1840 TXGBE_PHY_VCO_CAL_REF0_LD0_1GBASEX_KX);
1842 wr32_epcs(hw, TXGBE_PHY_VCO_CAL_REF1, 0x2929);
1844 /* Set VR XS, PMA, or MII Gen5 12G PHY AFE-DFE
1845 * Enable Register Bit[4], Bit[0] = 1'b0 //AFE_EN_0, DFE_EN_0
1847 wr32_epcs(hw, TXGBE_PHY_AFE_DFE_ENABLE,
1849 /* Set VR XS, PMA, or MII Gen5 12G PHY Rx
1850 * Equalization Control 4 Register Bit[0] = 1'b0 //CONT_ADAPT_0
1852 wr32_epcs(hw, TXGBE_PHY_RX_EQ_CTL,
1854 /* Set VR XS, PMA, or MII Gen5 12G PHY Tx Rate
1855 * Control Register Bit[2:0] = 3'b011 //TX0_RATE
1857 wr32_epcs(hw, TXGBE_PHY_TX_RATE_CTL,
1858 TXGBE_PHY_TX_RATE_CTL_TX0_RATE_1GBASEX_KX);
1860 /* Set VR XS, PMA, or MII Gen5 12G PHY Rx Rate
1861 * Control Register Bit[2:0] = 3'b011 //RX0_RATE
1863 wr32_epcs(hw, TXGBE_PHY_RX_RATE_CTL,
1864 TXGBE_PHY_RX_RATE_CTL_RX0_RATE_1GBASEX_KX);
1866 /* Set VR XS, PMA, or MII Gen5 12G PHY Tx General
1867 * Control 2 Register Bit[9:8] = 2'b01 //TX0_WIDTH: 10bits
1869 wr32_epcs(hw, TXGBE_PHY_TX_GEN_CTL2,
1870 TXGBE_PHY_TX_GEN_CTL2_TX0_WIDTH_OTHER);
1871 /* Set VR XS, PMA, or MII Gen5 12G PHY Rx General
1872 * Control 2 Register Bit[9:8] = 2'b01 //RX0_WIDTH: 10bits
1874 wr32_epcs(hw, TXGBE_PHY_RX_GEN_CTL2,
1875 TXGBE_PHY_RX_GEN_CTL2_RX0_WIDTH_OTHER);
1876 /* Set VR XS, PMA, or MII Gen5 12G PHY MPLLA Control
1877 * 2 Register Bit[10:8] = 3'b010 //MPLLA_DIV16P5_CLK_EN=0,
1878 * MPLLA_DIV10_CLK_EN=1, MPLLA_DIV8_CLK_EN=0
1880 wr32_epcs(hw, TXGBE_PHY_MPLLA_CTL2,
1881 TXGBE_PHY_MPLLA_CTL2_DIV_CLK_EN_10);
1883 /* VR MII MMD AN Control Register Bit[8] = 1'b1 //MII_CTRL
1884 * Set to 8bit MII (required in 10M/100M SGMII)
1886 wr32_epcs(hw, SR_MII_MMD_AN_CTL,
1889 /* 10. Initialize the mode by setting VR XS or PCS MMD Digital Control1
1890 * Register Bit[15](VR_RST)
1892 wr32_epcs(hw, VR_XS_OR_PCS_MMD_DIGI_CTL1, 0xA000);
1894 /* Wait phy initialization done */
1895 for (i = 0; i < 100; i++) {
1896 if ((rd32_epcs(hw, VR_XS_OR_PCS_MMD_DIGI_CTL1) &
1897 VR_XS_OR_PCS_MMD_DIGI_CTL1_VR_RST) == 0)
1902 /* If success, set link status */
1903 hw->link_status = TXGBE_LINK_STATUS_KX;
1906 err = TXGBE_ERR_PHY_INIT_NOT_DONE;
1910 if (hw->fw_version <= TXGBE_FW_N_TXEQ) {
1911 value = (0x1804 & ~0x3F3F) | (24 << 8) | 4;
1912 wr32_epcs(hw, TXGBE_PHY_TX_EQ_CTL0, value);
1914 value = (0x50 & ~0x7F) | 16 | (1 << 6);
1915 wr32_epcs(hw, TXGBE_PHY_TX_EQ_CTL1, value);
1922 txgbe_set_link_to_sfi(struct txgbe_hw *hw,
1929 /* Set the module link speed */
1930 hw->mac.set_rate_select_speed(hw, speed);
1931 /* 1. Wait xpcs power-up good */
1932 for (i = 0; i < 100; i++) {
1933 if ((rd32_epcs(hw, VR_XS_OR_PCS_MMD_DIGI_STATUS) &
1934 VR_XS_OR_PCS_MMD_DIGI_STATUS_PSEQ_MASK) ==
1935 VR_XS_OR_PCS_MMD_DIGI_STATUS_PSEQ_POWER_GOOD)
1940 err = TXGBE_ERR_XPCS_POWER_UP_FAILED;
1944 wr32m(hw, TXGBE_MACTXCFG, TXGBE_MACTXCFG_TXE,
1945 ~TXGBE_MACTXCFG_TXE);
1947 /* 2. Disable xpcs AN-73 */
1948 wr32_epcs(hw, SR_AN_CTRL, 0x0);
1950 /* Disable PHY MPLLA for eth mode change(after ECO) */
1951 wr32_ephy(hw, 0x4, 0x243A);
1954 /* Set the eth change_mode bit first in mis_rst register
1955 * for corresponding LAN port
1957 wr32(hw, TXGBE_RST, TXGBE_RST_ETH(hw->bus.lan_id));
1959 if (speed == TXGBE_LINK_SPEED_10GB_FULL) {
1960 /* Set SR PCS Control2 Register Bits[1:0] = 2'b00
1963 wr32_epcs(hw, SR_XS_PCS_CTRL2, 0);
1964 value = rd32_epcs(hw, SR_PMA_CTRL1);
1965 value = value | 0x2000;
1966 wr32_epcs(hw, SR_PMA_CTRL1, value);
1967 /* Set VR_XS_PMA_Gen5_12G_MPLLA_CTRL0 Register Bit[7:0] = 8'd33
1970 wr32_epcs(hw, TXGBE_PHY_MPLLA_CTL0, 0x0021);
1971 /* 3. Set VR_XS_PMA_Gen5_12G_MPLLA_CTRL3 Register
1972 * Bit[10:0](MPLLA_BANDWIDTH) = 11'd0
1974 wr32_epcs(hw, TXGBE_PHY_MPLLA_CTL3, 0);
1975 value = rd32_epcs(hw, TXGBE_PHY_TX_GENCTRL1);
1976 value = (value & ~0x700) | 0x500;
1977 wr32_epcs(hw, TXGBE_PHY_TX_GENCTRL1, value);
1978 /* 4. Set VR_XS_PMA_Gen5_12G_MISC_CTRL0 Register
1979 * Bit[12:8](RX_VREF_CTRL) = 5'hF
1981 wr32_epcs(hw, TXGBE_PHY_MISC_CTL0, 0xCF00);
1982 /* Set VR_XS_PMA_Gen5_12G_VCO_CAL_LD0 Register
1983 * Bit[12:0] = 13'd1353 //VCO_LD_VAL_0
1985 wr32_epcs(hw, TXGBE_PHY_VCO_CAL_LD0, 0x0549);
1986 /* Set VR_XS_PMA_Gen5_12G_VCO_CAL_REF0 Register
1987 * Bit[5:0] = 6'd41 //VCO_REF_LD_0
1989 wr32_epcs(hw, TXGBE_PHY_VCO_CAL_REF0, 0x0029);
1990 /* Set VR_XS_PMA_Gen5_12G_TX_RATE_CTRL Register
1991 * Bit[2:0] = 3'b000 //TX0_RATE
1993 wr32_epcs(hw, TXGBE_PHY_TX_RATE_CTL, 0);
1994 /* Set VR_XS_PMA_Gen5_12G_RX_RATE_CTRL Register
1995 * Bit[2:0] = 3'b000 //RX0_RATE
1997 wr32_epcs(hw, TXGBE_PHY_RX_RATE_CTL, 0);
1998 /* Set VR_XS_PMA_Gen5_12G_TX_GENCTRL2 Register Bit[9:8] = 2'b11
2001 wr32_epcs(hw, TXGBE_PHY_TX_GEN_CTL2, 0x0300);
2002 /* Set VR_XS_PMA_Gen5_12G_RX_GENCTRL2 Register Bit[9:8] = 2'b11
2005 wr32_epcs(hw, TXGBE_PHY_RX_GEN_CTL2, 0x0300);
2006 /* Set VR_XS_PMA_Gen5_12G_MPLLA_CTRL2 Register
2007 * Bit[10:8] = 3'b110
2008 * MPLLA_DIV16P5_CLK_EN=1
2009 * MPLLA_DIV10_CLK_EN=1
2010 * MPLLA_DIV8_CLK_EN=0
2012 wr32_epcs(hw, TXGBE_PHY_MPLLA_CTL2, 0x0600);
2014 if (hw->phy.sfp_type == txgbe_sfp_type_da_cu_core0 ||
2015 hw->phy.sfp_type == txgbe_sfp_type_da_cu_core1) {
2016 /* 7. Set VR_XS_PMA_Gen5_12G_RX_EQ_CTRL0 Register
2017 * Bit[15:8](VGA1/2_GAIN_0) = 8'h77
2018 * Bit[7:5](CTLE_POLE_0) = 3'h2
2019 * Bit[4:0](CTLE_BOOST_0) = 4'hF
2021 wr32_epcs(hw, TXGBE_PHY_RX_EQ_CTL0, 0x774F);
2024 /* 7. Set VR_XS_PMA_Gen5_12G_RX_EQ_CTRL0 Register
2025 * Bit[15:8](VGA1/2_GAIN_0) = 8'h00
2026 * Bit[7:5](CTLE_POLE_0) = 3'h2
2027 * Bit[4:0](CTLE_BOOST_0) = 4'hA
2029 value = rd32_epcs(hw, TXGBE_PHY_RX_EQ_CTL0);
2030 value = (value & ~0xFFFF) | (2 << 5) | 0x05;
2031 wr32_epcs(hw, TXGBE_PHY_RX_EQ_CTL0, value);
2033 value = rd32_epcs(hw, TXGBE_PHY_RX_EQ_ATT_LVL0);
2034 value = (value & ~0x7) | 0x0;
2035 wr32_epcs(hw, TXGBE_PHY_RX_EQ_ATT_LVL0, value);
2037 if (hw->phy.sfp_type == txgbe_sfp_type_da_cu_core0 ||
2038 hw->phy.sfp_type == txgbe_sfp_type_da_cu_core1) {
2039 /* 8. Set VR_XS_PMA_Gen5_12G_DFE_TAP_CTRL0 Register
2040 * Bit[7:0](DFE_TAP1_0) = 8'd20
2042 wr32_epcs(hw, TXGBE_PHY_DFE_TAP_CTL0, 0x0014);
2043 value = rd32_epcs(hw, TXGBE_PHY_AFE_DFE_ENABLE);
2044 value = (value & ~0x11) | 0x11;
2045 wr32_epcs(hw, TXGBE_PHY_AFE_DFE_ENABLE, value);
2047 /* 8. Set VR_XS_PMA_Gen5_12G_DFE_TAP_CTRL0 Register
2048 * Bit[7:0](DFE_TAP1_0) = 8'd20
2050 wr32_epcs(hw, TXGBE_PHY_DFE_TAP_CTL0, 0xBE);
2051 /* 9. Set VR_MII_Gen5_12G_AFE_DFE_EN_CTRL Register
2052 * Bit[4](DFE_EN_0) = 1'b0, Bit[0](AFE_EN_0) = 1'b0
2054 value = rd32_epcs(hw, TXGBE_PHY_AFE_DFE_ENABLE);
2055 value = (value & ~0x11) | 0x0;
2056 wr32_epcs(hw, TXGBE_PHY_AFE_DFE_ENABLE, value);
2058 value = rd32_epcs(hw, TXGBE_PHY_RX_EQ_CTL);
2059 value = value & ~0x1;
2060 wr32_epcs(hw, TXGBE_PHY_RX_EQ_CTL, value);
2062 /* Set SR PCS Control2 Register Bits[1:0] = 2'b00
2065 wr32_epcs(hw, SR_XS_PCS_CTRL2, 0x1);
2066 /* Set SR PMA MMD Control1 Register Bit[13] = 1'b0
2069 wr32_epcs(hw, SR_PMA_CTRL1, 0x0000);
2070 /* Set SR MII MMD Control Register to corresponding speed */
2071 wr32_epcs(hw, SR_MII_MMD_CTL, 0x0140);
2073 value = rd32_epcs(hw, TXGBE_PHY_TX_GENCTRL1);
2074 value = (value & ~0x710) | 0x500;
2075 wr32_epcs(hw, TXGBE_PHY_TX_GENCTRL1, value);
2076 /* 4. Set VR_XS_PMA_Gen5_12G_MISC_CTRL0 Register
2077 * Bit[12:8](RX_VREF_CTRL) = 5'hF
2079 wr32_epcs(hw, TXGBE_PHY_MISC_CTL0, 0xCF00);
2081 if (hw->phy.sfp_type == txgbe_sfp_type_da_cu_core0 ||
2082 hw->phy.sfp_type == txgbe_sfp_type_da_cu_core1) {
2083 wr32_epcs(hw, TXGBE_PHY_RX_EQ_CTL0, 0x774F);
2085 /* 7. Set VR_XS_PMA_Gen5_12G_RX_EQ_CTRL0 Register
2086 * Bit[15:8](VGA1/2_GAIN_0) = 8'h00
2087 * Bit[7:5](CTLE_POLE_0) = 3'h2
2088 * Bit[4:0](CTLE_BOOST_0) = 4'hA
2090 value = rd32_epcs(hw, TXGBE_PHY_RX_EQ_CTL0);
2091 value = (value & ~0xFFFF) | 0x7706;
2092 wr32_epcs(hw, TXGBE_PHY_RX_EQ_CTL0, value);
2094 value = rd32_epcs(hw, TXGBE_PHY_RX_EQ_ATT_LVL0);
2095 value = (value & ~0x7) | 0x0;
2096 wr32_epcs(hw, TXGBE_PHY_RX_EQ_ATT_LVL0, value);
2097 /* 8. Set VR_XS_PMA_Gen5_12G_DFE_TAP_CTRL0 Register
2098 * Bit[7:0](DFE_TAP1_0) = 8'd00
2100 wr32_epcs(hw, TXGBE_PHY_DFE_TAP_CTL0, 0x0);
2101 /* 9. Set VR_MII_Gen5_12G_AFE_DFE_EN_CTRL Register
2102 * Bit[4](DFE_EN_0) = 1'b0, Bit[0](AFE_EN_0) = 1'b0
2104 value = rd32_epcs(hw, TXGBE_PHY_RX_GEN_CTL3);
2105 value = (value & ~0x7) | 0x4;
2106 wr32_epcs(hw, TXGBE_PHY_RX_GEN_CTL3, value);
2107 wr32_epcs(hw, TXGBE_PHY_MPLLA_CTL0, 0x0020);
2108 wr32_epcs(hw, TXGBE_PHY_MPLLA_CTL3, 0x0046);
2109 wr32_epcs(hw, TXGBE_PHY_VCO_CAL_LD0, 0x0540);
2110 wr32_epcs(hw, TXGBE_PHY_VCO_CAL_REF0, 0x002A);
2111 wr32_epcs(hw, TXGBE_PHY_AFE_DFE_ENABLE, 0x0);
2112 wr32_epcs(hw, TXGBE_PHY_RX_EQ_CTL, 0x0010);
2113 wr32_epcs(hw, TXGBE_PHY_TX_RATE_CTL, 0x0003);
2114 wr32_epcs(hw, TXGBE_PHY_RX_RATE_CTL, 0x0003);
2115 wr32_epcs(hw, TXGBE_PHY_TX_GEN_CTL2, 0x0100);
2116 wr32_epcs(hw, TXGBE_PHY_RX_GEN_CTL2, 0x0100);
2117 wr32_epcs(hw, TXGBE_PHY_MPLLA_CTL2, 0x0200);
2118 wr32_epcs(hw, SR_MII_MMD_AN_CTL, 0x0100);
2120 /* 10. Initialize the mode by setting VR XS or PCS MMD Digital Control1
2121 * Register Bit[15](VR_RST)
2123 wr32_epcs(hw, VR_XS_OR_PCS_MMD_DIGI_CTL1, 0xA000);
2125 /* Wait phy initialization done */
2126 for (i = 0; i < 100; i++) {
2127 if ((rd32_epcs(hw, VR_XS_OR_PCS_MMD_DIGI_CTL1) &
2128 VR_XS_OR_PCS_MMD_DIGI_CTL1_VR_RST) == 0)
2133 err = TXGBE_ERR_PHY_INIT_NOT_DONE;
2137 if (hw->fw_version <= TXGBE_FW_N_TXEQ) {
2138 value = rd32_epcs(hw, TXGBE_PHY_TX_EQ_CTL0);
2139 value = (value & ~0x3F3F) | (24 << 8) | 4;
2140 wr32_epcs(hw, TXGBE_PHY_TX_EQ_CTL0, value);
2142 value = rd32_epcs(hw, TXGBE_PHY_TX_EQ_CTL1);
2143 value = (value & ~0x7F) | 16 | (1 << 6);
2144 wr32_epcs(hw, TXGBE_PHY_TX_EQ_CTL1, value);
2151 * txgbe_autoc_read - Hides MAC differences needed for AUTOC read
2152 * @hw: pointer to hardware structure
2154 u64 txgbe_autoc_read(struct txgbe_hw *hw)
2161 u8 type = hw->subsystem_device_id & 0xFF;
2163 autoc = hw->mac.autoc;
2165 if (hw->phy.multispeed_fiber) {
2166 autoc |= TXGBE_AUTOC_LMS_10G;
2167 } else if (type == TXGBE_DEV_ID_SFP) {
2168 autoc |= TXGBE_AUTOC_LMS_10G;
2169 autoc |= TXGBE_AUTOC_10GS_SFI;
2170 } else if (type == TXGBE_DEV_ID_QSFP) {
2172 } else if (type == TXGBE_DEV_ID_XAUI || type == TXGBE_DEV_ID_SFI_XAUI) {
2173 autoc |= TXGBE_AUTOC_LMS_10G_LINK_NO_AN;
2174 autoc |= TXGBE_AUTOC_10G_XAUI;
2175 hw->phy.link_mode = TXGBE_PHYSICAL_LAYER_10GBASE_T;
2176 } else if (type == TXGBE_DEV_ID_SGMII) {
2177 autoc |= TXGBE_AUTOC_LMS_SGMII_1G_100M;
2178 hw->phy.link_mode = TXGBE_PHYSICAL_LAYER_1000BASE_T |
2179 TXGBE_PHYSICAL_LAYER_100BASE_TX;
2180 } else if (type == TXGBE_DEV_ID_MAC_XAUI) {
2181 autoc |= TXGBE_AUTOC_LMS_10G_LINK_NO_AN;
2182 hw->phy.link_mode = TXGBE_PHYSICAL_LAYER_10GBASE_KX4;
2183 } else if (type == TXGBE_DEV_ID_MAC_SGMII) {
2184 autoc |= TXGBE_AUTOC_LMS_1G_LINK_NO_AN;
2185 hw->phy.link_mode = TXGBE_PHYSICAL_LAYER_1000BASE_KX;
2188 if (type != TXGBE_DEV_ID_KR_KX_KX4)
2191 sr_pcs_ctl = rd32_epcs(hw, SR_XS_PCS_CTRL2);
2192 sr_pma_ctl1 = rd32_epcs(hw, SR_PMA_CTRL1);
2193 sr_an_ctl = rd32_epcs(hw, SR_AN_CTRL);
2194 sr_an_adv_reg2 = rd32_epcs(hw, SR_AN_MMD_ADV_REG2);
2196 if ((sr_pcs_ctl & SR_PCS_CTRL2_TYPE_SEL) == SR_PCS_CTRL2_TYPE_SEL_X &&
2197 (sr_pma_ctl1 & SR_PMA_CTRL1_SS13) == SR_PMA_CTRL1_SS13_KX &&
2198 (sr_an_ctl & SR_AN_CTRL_AN_EN) == 0) {
2199 /* 1G or KX - no backplane auto-negotiation */
2200 autoc |= TXGBE_AUTOC_LMS_1G_LINK_NO_AN |
2202 hw->phy.link_mode = TXGBE_PHYSICAL_LAYER_1000BASE_KX;
2203 } else if ((sr_pcs_ctl & SR_PCS_CTRL2_TYPE_SEL) ==
2204 SR_PCS_CTRL2_TYPE_SEL_X &&
2205 (sr_pma_ctl1 & SR_PMA_CTRL1_SS13) == SR_PMA_CTRL1_SS13_KX4 &&
2206 (sr_an_ctl & SR_AN_CTRL_AN_EN) == 0) {
2207 autoc |= TXGBE_AUTOC_LMS_10G |
2208 TXGBE_AUTOC_10G_KX4;
2209 hw->phy.link_mode = TXGBE_PHYSICAL_LAYER_10GBASE_KX4;
2210 } else if ((sr_pcs_ctl & SR_PCS_CTRL2_TYPE_SEL) ==
2211 SR_PCS_CTRL2_TYPE_SEL_R &&
2212 (sr_an_ctl & SR_AN_CTRL_AN_EN) == 0) {
2213 /* 10 GbE serial link (KR -no backplane auto-negotiation) */
2214 autoc |= TXGBE_AUTOC_LMS_10G |
2215 TXGBE_AUTOC_10GS_KR;
2216 hw->phy.link_mode = TXGBE_PHYSICAL_LAYER_10GBASE_KR;
2217 } else if ((sr_an_ctl & SR_AN_CTRL_AN_EN)) {
2218 /* KX/KX4/KR backplane auto-negotiation enable */
2219 if (sr_an_adv_reg2 & SR_AN_MMD_ADV_REG2_BP_TYPE_KR)
2220 autoc |= TXGBE_AUTOC_KR_SUPP;
2221 if (sr_an_adv_reg2 & SR_AN_MMD_ADV_REG2_BP_TYPE_KX4)
2222 autoc |= TXGBE_AUTOC_KX4_SUPP;
2223 if (sr_an_adv_reg2 & SR_AN_MMD_ADV_REG2_BP_TYPE_KX)
2224 autoc |= TXGBE_AUTOC_KX_SUPP;
2225 autoc |= TXGBE_AUTOC_LMS_KX4_KX_KR;
2226 hw->phy.link_mode = TXGBE_PHYSICAL_LAYER_10GBASE_KR |
2227 TXGBE_PHYSICAL_LAYER_10GBASE_KX4 |
2228 TXGBE_PHYSICAL_LAYER_1000BASE_KX;
2235 * txgbe_autoc_write - Hides MAC differences needed for AUTOC write
2236 * @hw: pointer to hardware structure
2237 * @autoc: value to write to AUTOC
2239 void txgbe_autoc_write(struct txgbe_hw *hw, u64 autoc)
2244 u8 device_type = hw->subsystem_device_id & 0xFF;
2246 speed = TXGBD_AUTOC_SPEED(autoc);
2247 autoc &= ~TXGBE_AUTOC_SPEED_MASK;
2248 autoneg = (autoc & TXGBE_AUTOC_AUTONEG ? true : false);
2249 autoc &= ~TXGBE_AUTOC_AUTONEG;
2251 if (device_type == TXGBE_DEV_ID_KR_KX_KX4) {
2253 switch (hw->phy.link_mode) {
2254 case TXGBE_PHYSICAL_LAYER_10GBASE_KR:
2255 txgbe_set_link_to_kr(hw, autoneg);
2257 case TXGBE_PHYSICAL_LAYER_10GBASE_KX4:
2258 txgbe_set_link_to_kx4(hw, autoneg);
2260 case TXGBE_PHYSICAL_LAYER_1000BASE_KX:
2261 txgbe_set_link_to_kx(hw, speed, autoneg);
2267 txgbe_set_link_to_kr(hw, !autoneg);
2269 } else if (device_type == TXGBE_DEV_ID_XAUI ||
2270 device_type == TXGBE_DEV_ID_SGMII ||
2271 device_type == TXGBE_DEV_ID_MAC_XAUI ||
2272 device_type == TXGBE_DEV_ID_MAC_SGMII ||
2273 (device_type == TXGBE_DEV_ID_SFI_XAUI &&
2274 hw->phy.media_type == txgbe_media_type_copper)) {
2275 if (speed == TXGBE_LINK_SPEED_10GB_FULL) {
2276 txgbe_set_link_to_kx4(hw, 0);
2278 txgbe_set_link_to_kx(hw, speed, 0);
2279 if (hw->devarg.auto_neg == 1)
2280 txgbe_set_sgmii_an37_ability(hw);
2282 } else if (hw->phy.media_type == txgbe_media_type_fiber) {
2283 txgbe_set_link_to_sfi(hw, speed);
2286 if (speed == TXGBE_LINK_SPEED_10GB_FULL)
2287 mactxcfg = TXGBE_MACTXCFG_SPEED_10G;
2288 else if (speed == TXGBE_LINK_SPEED_1GB_FULL)
2289 mactxcfg = TXGBE_MACTXCFG_SPEED_1G;
2291 /* enable mac transmitter */
2292 wr32m(hw, TXGBE_MACTXCFG,
2293 TXGBE_MACTXCFG_SPEED_MASK | TXGBE_MACTXCFG_TXE,
2294 mactxcfg | TXGBE_MACTXCFG_TXE);