1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 1999 - 2018 Intel Corporation. */
5 #include <linux/ethtool.h>
7 static s32 e1000_wait_autoneg(struct e1000_hw *hw);
8 static s32 e1000_access_phy_wakeup_reg_bm(struct e1000_hw *hw, u32 offset,
9 u16 *data, bool read, bool page_set);
10 static u32 e1000_get_phy_addr_for_hv_page(u32 page);
11 static s32 e1000_access_phy_debug_regs_hv(struct e1000_hw *hw, u32 offset,
12 u16 *data, bool read);
14 /* Cable length tables */
15 static const u16 e1000_m88_cable_length_table[] = {
16 0, 50, 80, 110, 140, 140, E1000_CABLE_LENGTH_UNDEFINED
19 #define M88E1000_CABLE_LENGTH_TABLE_SIZE \
20 ARRAY_SIZE(e1000_m88_cable_length_table)
22 static const u16 e1000_igp_2_cable_length_table[] = {
23 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21, 0, 0, 0, 3,
24 6, 10, 13, 16, 19, 23, 26, 29, 32, 35, 38, 41, 6, 10, 14, 18, 22,
25 26, 30, 33, 37, 41, 44, 48, 51, 54, 58, 61, 21, 26, 31, 35, 40,
26 44, 49, 53, 57, 61, 65, 68, 72, 75, 79, 82, 40, 45, 51, 56, 61,
27 66, 70, 75, 79, 83, 87, 91, 94, 98, 101, 104, 60, 66, 72, 77, 82,
28 87, 92, 96, 100, 104, 108, 111, 114, 117, 119, 121, 83, 89, 95,
29 100, 105, 109, 113, 116, 119, 122, 124, 104, 109, 114, 118, 121,
33 #define IGP02E1000_CABLE_LENGTH_TABLE_SIZE \
34 ARRAY_SIZE(e1000_igp_2_cable_length_table)
37 * e1000e_check_reset_block_generic - Check if PHY reset is blocked
38 * @hw: pointer to the HW structure
40 * Read the PHY management control register and check whether a PHY reset
41 * is blocked. If a reset is not blocked return 0, otherwise
42 * return E1000_BLK_PHY_RESET (12).
44 s32 e1000e_check_reset_block_generic(struct e1000_hw *hw)
50 return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ? E1000_BLK_PHY_RESET : 0;
54 * e1000e_get_phy_id - Retrieve the PHY ID and revision
55 * @hw: pointer to the HW structure
57 * Reads the PHY registers and stores the PHY ID and possibly the PHY
58 * revision in the hardware structure.
60 s32 e1000e_get_phy_id(struct e1000_hw *hw)
62 struct e1000_phy_info *phy = &hw->phy;
67 if (!phy->ops.read_reg)
70 while (retry_count < 2) {
71 ret_val = e1e_rphy(hw, MII_PHYSID1, &phy_id);
75 phy->id = (u32)(phy_id << 16);
77 ret_val = e1e_rphy(hw, MII_PHYSID2, &phy_id);
81 phy->id |= (u32)(phy_id & PHY_REVISION_MASK);
82 phy->revision = (u32)(phy_id & ~PHY_REVISION_MASK);
84 if (phy->id != 0 && phy->id != PHY_REVISION_MASK)
94 * e1000e_phy_reset_dsp - Reset PHY DSP
95 * @hw: pointer to the HW structure
97 * Reset the digital signal processor.
99 s32 e1000e_phy_reset_dsp(struct e1000_hw *hw)
103 ret_val = e1e_wphy(hw, M88E1000_PHY_GEN_CONTROL, 0xC1);
107 return e1e_wphy(hw, M88E1000_PHY_GEN_CONTROL, 0);
111 * e1000e_read_phy_reg_mdic - Read MDI control register
112 * @hw: pointer to the HW structure
113 * @offset: register offset to be read
114 * @data: pointer to the read data
116 * Reads the MDI control register in the PHY at offset and stores the
117 * information read to data.
119 s32 e1000e_read_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 *data)
121 struct e1000_phy_info *phy = &hw->phy;
124 if (offset > MAX_PHY_REG_ADDRESS) {
125 e_dbg("PHY Address %d is out of range\n", offset);
126 return -E1000_ERR_PARAM;
129 /* Set up Op-code, Phy Address, and register offset in the MDI
130 * Control register. The MAC will take care of interfacing with the
131 * PHY to retrieve the desired data.
133 mdic = ((offset << E1000_MDIC_REG_SHIFT) |
134 (phy->addr << E1000_MDIC_PHY_SHIFT) |
135 (E1000_MDIC_OP_READ));
139 /* Poll the ready bit to see if the MDI read completed
140 * Increasing the time out as testing showed failures with
143 for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
146 if (mdic & E1000_MDIC_READY)
149 if (!(mdic & E1000_MDIC_READY)) {
150 e_dbg("MDI Read PHY Reg Address %d did not complete\n", offset);
151 return -E1000_ERR_PHY;
153 if (mdic & E1000_MDIC_ERROR) {
154 e_dbg("MDI Read PHY Reg Address %d Error\n", offset);
155 return -E1000_ERR_PHY;
157 if (((mdic & E1000_MDIC_REG_MASK) >> E1000_MDIC_REG_SHIFT) != offset) {
158 e_dbg("MDI Read offset error - requested %d, returned %d\n",
160 (mdic & E1000_MDIC_REG_MASK) >> E1000_MDIC_REG_SHIFT);
161 return -E1000_ERR_PHY;
165 /* Allow some time after each MDIC transaction to avoid
166 * reading duplicate data in the next MDIC transaction.
168 if (hw->mac.type == e1000_pch2lan)
175 * e1000e_write_phy_reg_mdic - Write MDI control register
176 * @hw: pointer to the HW structure
177 * @offset: register offset to write to
178 * @data: data to write to register at offset
180 * Writes data to MDI control register in the PHY at offset.
182 s32 e1000e_write_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 data)
184 struct e1000_phy_info *phy = &hw->phy;
187 if (offset > MAX_PHY_REG_ADDRESS) {
188 e_dbg("PHY Address %d is out of range\n", offset);
189 return -E1000_ERR_PARAM;
192 /* Set up Op-code, Phy Address, and register offset in the MDI
193 * Control register. The MAC will take care of interfacing with the
194 * PHY to retrieve the desired data.
196 mdic = (((u32)data) |
197 (offset << E1000_MDIC_REG_SHIFT) |
198 (phy->addr << E1000_MDIC_PHY_SHIFT) |
199 (E1000_MDIC_OP_WRITE));
203 /* Poll the ready bit to see if the MDI read completed
204 * Increasing the time out as testing showed failures with
207 for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
210 if (mdic & E1000_MDIC_READY)
213 if (!(mdic & E1000_MDIC_READY)) {
214 e_dbg("MDI Write PHY Reg Address %d did not complete\n", offset);
215 return -E1000_ERR_PHY;
217 if (mdic & E1000_MDIC_ERROR) {
218 e_dbg("MDI Write PHY Red Address %d Error\n", offset);
219 return -E1000_ERR_PHY;
221 if (((mdic & E1000_MDIC_REG_MASK) >> E1000_MDIC_REG_SHIFT) != offset) {
222 e_dbg("MDI Write offset error - requested %d, returned %d\n",
224 (mdic & E1000_MDIC_REG_MASK) >> E1000_MDIC_REG_SHIFT);
225 return -E1000_ERR_PHY;
228 /* Allow some time after each MDIC transaction to avoid
229 * reading duplicate data in the next MDIC transaction.
231 if (hw->mac.type == e1000_pch2lan)
238 * e1000e_read_phy_reg_m88 - Read m88 PHY register
239 * @hw: pointer to the HW structure
240 * @offset: register offset to be read
241 * @data: pointer to the read data
243 * Acquires semaphore, if necessary, then reads the PHY register at offset
244 * and storing the retrieved information in data. Release any acquired
245 * semaphores before exiting.
247 s32 e1000e_read_phy_reg_m88(struct e1000_hw *hw, u32 offset, u16 *data)
251 ret_val = hw->phy.ops.acquire(hw);
255 ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
258 hw->phy.ops.release(hw);
264 * e1000e_write_phy_reg_m88 - Write m88 PHY register
265 * @hw: pointer to the HW structure
266 * @offset: register offset to write to
267 * @data: data to write at register offset
269 * Acquires semaphore, if necessary, then writes the data to PHY register
270 * at the offset. Release any acquired semaphores before exiting.
272 s32 e1000e_write_phy_reg_m88(struct e1000_hw *hw, u32 offset, u16 data)
276 ret_val = hw->phy.ops.acquire(hw);
280 ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
283 hw->phy.ops.release(hw);
289 * e1000_set_page_igp - Set page as on IGP-like PHY(s)
290 * @hw: pointer to the HW structure
291 * @page: page to set (shifted left when necessary)
293 * Sets PHY page required for PHY register access. Assumes semaphore is
294 * already acquired. Note, this function sets phy.addr to 1 so the caller
295 * must set it appropriately (if necessary) after this function returns.
297 s32 e1000_set_page_igp(struct e1000_hw *hw, u16 page)
299 e_dbg("Setting page 0x%x\n", page);
303 return e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT, page);
307 * __e1000e_read_phy_reg_igp - Read igp PHY register
308 * @hw: pointer to the HW structure
309 * @offset: register offset to be read
310 * @data: pointer to the read data
311 * @locked: semaphore has already been acquired or not
313 * Acquires semaphore, if necessary, then reads the PHY register at offset
314 * and stores the retrieved information in data. Release any acquired
315 * semaphores before exiting.
317 static s32 __e1000e_read_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 *data,
323 if (!hw->phy.ops.acquire)
326 ret_val = hw->phy.ops.acquire(hw);
331 if (offset > MAX_PHY_MULTI_PAGE_REG)
332 ret_val = e1000e_write_phy_reg_mdic(hw,
333 IGP01E1000_PHY_PAGE_SELECT,
336 ret_val = e1000e_read_phy_reg_mdic(hw,
337 MAX_PHY_REG_ADDRESS & offset,
340 hw->phy.ops.release(hw);
346 * e1000e_read_phy_reg_igp - Read igp PHY register
347 * @hw: pointer to the HW structure
348 * @offset: register offset to be read
349 * @data: pointer to the read data
351 * Acquires semaphore then reads the PHY register at offset and stores the
352 * retrieved information in data.
353 * Release the acquired semaphore before exiting.
355 s32 e1000e_read_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 *data)
357 return __e1000e_read_phy_reg_igp(hw, offset, data, false);
361 * e1000e_read_phy_reg_igp_locked - Read igp PHY register
362 * @hw: pointer to the HW structure
363 * @offset: register offset to be read
364 * @data: pointer to the read data
366 * Reads the PHY register at offset and stores the retrieved information
367 * in data. Assumes semaphore already acquired.
369 s32 e1000e_read_phy_reg_igp_locked(struct e1000_hw *hw, u32 offset, u16 *data)
371 return __e1000e_read_phy_reg_igp(hw, offset, data, true);
375 * __e1000e_write_phy_reg_igp - Write igp PHY register
376 * @hw: pointer to the HW structure
377 * @offset: register offset to write to
378 * @data: data to write at register offset
379 * @locked: semaphore has already been acquired or not
381 * Acquires semaphore, if necessary, then writes the data to PHY register
382 * at the offset. Release any acquired semaphores before exiting.
384 static s32 __e1000e_write_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 data,
390 if (!hw->phy.ops.acquire)
393 ret_val = hw->phy.ops.acquire(hw);
398 if (offset > MAX_PHY_MULTI_PAGE_REG)
399 ret_val = e1000e_write_phy_reg_mdic(hw,
400 IGP01E1000_PHY_PAGE_SELECT,
403 ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS &
406 hw->phy.ops.release(hw);
412 * e1000e_write_phy_reg_igp - Write igp PHY register
413 * @hw: pointer to the HW structure
414 * @offset: register offset to write to
415 * @data: data to write at register offset
417 * Acquires semaphore then writes the data to PHY register
418 * at the offset. Release any acquired semaphores before exiting.
420 s32 e1000e_write_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 data)
422 return __e1000e_write_phy_reg_igp(hw, offset, data, false);
426 * e1000e_write_phy_reg_igp_locked - Write igp PHY register
427 * @hw: pointer to the HW structure
428 * @offset: register offset to write to
429 * @data: data to write at register offset
431 * Writes the data to PHY register at the offset.
432 * Assumes semaphore already acquired.
434 s32 e1000e_write_phy_reg_igp_locked(struct e1000_hw *hw, u32 offset, u16 data)
436 return __e1000e_write_phy_reg_igp(hw, offset, data, true);
440 * __e1000_read_kmrn_reg - Read kumeran register
441 * @hw: pointer to the HW structure
442 * @offset: register offset to be read
443 * @data: pointer to the read data
444 * @locked: semaphore has already been acquired or not
446 * Acquires semaphore, if necessary. Then reads the PHY register at offset
447 * using the kumeran interface. The information retrieved is stored in data.
448 * Release any acquired semaphores before exiting.
450 static s32 __e1000_read_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 *data,
458 if (!hw->phy.ops.acquire)
461 ret_val = hw->phy.ops.acquire(hw);
466 kmrnctrlsta = ((offset << E1000_KMRNCTRLSTA_OFFSET_SHIFT) &
467 E1000_KMRNCTRLSTA_OFFSET) | E1000_KMRNCTRLSTA_REN;
468 ew32(KMRNCTRLSTA, kmrnctrlsta);
473 kmrnctrlsta = er32(KMRNCTRLSTA);
474 *data = (u16)kmrnctrlsta;
477 hw->phy.ops.release(hw);
483 * e1000e_read_kmrn_reg - Read kumeran register
484 * @hw: pointer to the HW structure
485 * @offset: register offset to be read
486 * @data: pointer to the read data
488 * Acquires semaphore then reads the PHY register at offset using the
489 * kumeran interface. The information retrieved is stored in data.
490 * Release the acquired semaphore before exiting.
492 s32 e1000e_read_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 *data)
494 return __e1000_read_kmrn_reg(hw, offset, data, false);
498 * e1000e_read_kmrn_reg_locked - Read kumeran register
499 * @hw: pointer to the HW structure
500 * @offset: register offset to be read
501 * @data: pointer to the read data
503 * Reads the PHY register at offset using the kumeran interface. The
504 * information retrieved is stored in data.
505 * Assumes semaphore already acquired.
507 s32 e1000e_read_kmrn_reg_locked(struct e1000_hw *hw, u32 offset, u16 *data)
509 return __e1000_read_kmrn_reg(hw, offset, data, true);
513 * __e1000_write_kmrn_reg - Write kumeran register
514 * @hw: pointer to the HW structure
515 * @offset: register offset to write to
516 * @data: data to write at register offset
517 * @locked: semaphore has already been acquired or not
519 * Acquires semaphore, if necessary. Then write the data to PHY register
520 * at the offset using the kumeran interface. Release any acquired semaphores
523 static s32 __e1000_write_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 data,
531 if (!hw->phy.ops.acquire)
534 ret_val = hw->phy.ops.acquire(hw);
539 kmrnctrlsta = ((offset << E1000_KMRNCTRLSTA_OFFSET_SHIFT) &
540 E1000_KMRNCTRLSTA_OFFSET) | data;
541 ew32(KMRNCTRLSTA, kmrnctrlsta);
547 hw->phy.ops.release(hw);
553 * e1000e_write_kmrn_reg - Write kumeran register
554 * @hw: pointer to the HW structure
555 * @offset: register offset to write to
556 * @data: data to write at register offset
558 * Acquires semaphore then writes the data to the PHY register at the offset
559 * using the kumeran interface. Release the acquired semaphore before exiting.
561 s32 e1000e_write_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 data)
563 return __e1000_write_kmrn_reg(hw, offset, data, false);
567 * e1000e_write_kmrn_reg_locked - Write kumeran register
568 * @hw: pointer to the HW structure
569 * @offset: register offset to write to
570 * @data: data to write at register offset
572 * Write the data to PHY register at the offset using the kumeran interface.
573 * Assumes semaphore already acquired.
575 s32 e1000e_write_kmrn_reg_locked(struct e1000_hw *hw, u32 offset, u16 data)
577 return __e1000_write_kmrn_reg(hw, offset, data, true);
581 * e1000_set_master_slave_mode - Setup PHY for Master/slave mode
582 * @hw: pointer to the HW structure
584 * Sets up Master/slave mode
586 static s32 e1000_set_master_slave_mode(struct e1000_hw *hw)
591 /* Resolve Master/Slave mode */
592 ret_val = e1e_rphy(hw, MII_CTRL1000, &phy_data);
596 /* load defaults for future use */
597 hw->phy.original_ms_type = (phy_data & CTL1000_ENABLE_MASTER) ?
598 ((phy_data & CTL1000_AS_MASTER) ?
599 e1000_ms_force_master : e1000_ms_force_slave) : e1000_ms_auto;
601 switch (hw->phy.ms_type) {
602 case e1000_ms_force_master:
603 phy_data |= (CTL1000_ENABLE_MASTER | CTL1000_AS_MASTER);
605 case e1000_ms_force_slave:
606 phy_data |= CTL1000_ENABLE_MASTER;
607 phy_data &= ~(CTL1000_AS_MASTER);
610 phy_data &= ~CTL1000_ENABLE_MASTER;
616 return e1e_wphy(hw, MII_CTRL1000, phy_data);
620 * e1000_copper_link_setup_82577 - Setup 82577 PHY for copper link
621 * @hw: pointer to the HW structure
623 * Sets up Carrier-sense on Transmit and downshift values.
625 s32 e1000_copper_link_setup_82577(struct e1000_hw *hw)
630 /* Enable CRS on Tx. This must be set for half-duplex operation. */
631 ret_val = e1e_rphy(hw, I82577_CFG_REG, &phy_data);
635 phy_data |= I82577_CFG_ASSERT_CRS_ON_TX;
637 /* Enable downshift */
638 phy_data |= I82577_CFG_ENABLE_DOWNSHIFT;
640 ret_val = e1e_wphy(hw, I82577_CFG_REG, phy_data);
644 /* Set MDI/MDIX mode */
645 ret_val = e1e_rphy(hw, I82577_PHY_CTRL_2, &phy_data);
648 phy_data &= ~I82577_PHY_CTRL2_MDIX_CFG_MASK;
654 switch (hw->phy.mdix) {
658 phy_data |= I82577_PHY_CTRL2_MANUAL_MDIX;
662 phy_data |= I82577_PHY_CTRL2_AUTO_MDI_MDIX;
665 ret_val = e1e_wphy(hw, I82577_PHY_CTRL_2, phy_data);
669 return e1000_set_master_slave_mode(hw);
673 * e1000e_copper_link_setup_m88 - Setup m88 PHY's for copper link
674 * @hw: pointer to the HW structure
676 * Sets up MDI/MDI-X and polarity for m88 PHY's. If necessary, transmit clock
677 * and downshift values are set also.
679 s32 e1000e_copper_link_setup_m88(struct e1000_hw *hw)
681 struct e1000_phy_info *phy = &hw->phy;
685 /* Enable CRS on Tx. This must be set for half-duplex operation. */
686 ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
690 /* For BM PHY this bit is downshift enable */
691 if (phy->type != e1000_phy_bm)
692 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
695 * MDI/MDI-X = 0 (default)
696 * 0 - Auto for all speeds
699 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
701 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
705 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
708 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
711 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
715 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
720 * disable_polarity_correction = 0 (default)
721 * Automatic Correction for Reversed Cable Polarity
725 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
726 if (phy->disable_polarity_correction)
727 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
729 /* Enable downshift on BM (disabled by default) */
730 if (phy->type == e1000_phy_bm) {
731 /* For 82574/82583, first disable then enable downshift */
732 if (phy->id == BME1000_E_PHY_ID_R2) {
733 phy_data &= ~BME1000_PSCR_ENABLE_DOWNSHIFT;
734 ret_val = e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL,
738 /* Commit the changes. */
739 ret_val = phy->ops.commit(hw);
741 e_dbg("Error committing the PHY changes\n");
746 phy_data |= BME1000_PSCR_ENABLE_DOWNSHIFT;
749 ret_val = e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
753 if ((phy->type == e1000_phy_m88) &&
754 (phy->revision < E1000_REVISION_4) &&
755 (phy->id != BME1000_E_PHY_ID_R2)) {
756 /* Force TX_CLK in the Extended PHY Specific Control Register
759 ret_val = e1e_rphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
763 phy_data |= M88E1000_EPSCR_TX_CLK_25;
765 if ((phy->revision == 2) && (phy->id == M88E1111_I_PHY_ID)) {
766 /* 82573L PHY - set the downshift counter to 5x. */
767 phy_data &= ~M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK;
768 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
770 /* Configure Master and Slave downshift values */
771 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
772 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
773 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
774 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
776 ret_val = e1e_wphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
781 if ((phy->type == e1000_phy_bm) && (phy->id == BME1000_E_PHY_ID_R2)) {
782 /* Set PHY page 0, register 29 to 0x0003 */
783 ret_val = e1e_wphy(hw, 29, 0x0003);
787 /* Set PHY page 0, register 30 to 0x0000 */
788 ret_val = e1e_wphy(hw, 30, 0x0000);
793 /* Commit the changes. */
794 if (phy->ops.commit) {
795 ret_val = phy->ops.commit(hw);
797 e_dbg("Error committing the PHY changes\n");
802 if (phy->type == e1000_phy_82578) {
803 ret_val = e1e_rphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
807 /* 82578 PHY - set the downshift count to 1x. */
808 phy_data |= I82578_EPSCR_DOWNSHIFT_ENABLE;
809 phy_data &= ~I82578_EPSCR_DOWNSHIFT_COUNTER_MASK;
810 ret_val = e1e_wphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
819 * e1000e_copper_link_setup_igp - Setup igp PHY's for copper link
820 * @hw: pointer to the HW structure
822 * Sets up LPLU, MDI/MDI-X, polarity, Smartspeed and Master/Slave config for
825 s32 e1000e_copper_link_setup_igp(struct e1000_hw *hw)
827 struct e1000_phy_info *phy = &hw->phy;
831 ret_val = e1000_phy_hw_reset(hw);
833 e_dbg("Error resetting the PHY.\n");
837 /* Wait 100ms for MAC to configure PHY from NVM settings, to avoid
838 * timeout issues when LFS is enabled.
842 /* disable lplu d0 during driver init */
843 if (hw->phy.ops.set_d0_lplu_state) {
844 ret_val = hw->phy.ops.set_d0_lplu_state(hw, false);
846 e_dbg("Error Disabling LPLU D0\n");
850 /* Configure mdi-mdix settings */
851 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CTRL, &data);
855 data &= ~IGP01E1000_PSCR_AUTO_MDIX;
859 data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
862 data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
866 data |= IGP01E1000_PSCR_AUTO_MDIX;
869 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CTRL, data);
873 /* set auto-master slave resolution settings */
874 if (hw->mac.autoneg) {
875 /* when autonegotiation advertisement is only 1000Mbps then we
876 * should disable SmartSpeed and enable Auto MasterSlave
877 * resolution as hardware default.
879 if (phy->autoneg_advertised == ADVERTISE_1000_FULL) {
880 /* Disable SmartSpeed */
881 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
886 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
887 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
892 /* Set auto Master/Slave resolution process */
893 ret_val = e1e_rphy(hw, MII_CTRL1000, &data);
897 data &= ~CTL1000_ENABLE_MASTER;
898 ret_val = e1e_wphy(hw, MII_CTRL1000, data);
903 ret_val = e1000_set_master_slave_mode(hw);
910 * e1000_phy_setup_autoneg - Configure PHY for auto-negotiation
911 * @hw: pointer to the HW structure
913 * Reads the MII auto-neg advertisement register and/or the 1000T control
914 * register and if the PHY is already setup for auto-negotiation, then
915 * return successful. Otherwise, setup advertisement and flow control to
916 * the appropriate values for the wanted auto-negotiation.
918 static s32 e1000_phy_setup_autoneg(struct e1000_hw *hw)
920 struct e1000_phy_info *phy = &hw->phy;
922 u16 mii_autoneg_adv_reg;
923 u16 mii_1000t_ctrl_reg = 0;
925 phy->autoneg_advertised &= phy->autoneg_mask;
927 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
928 ret_val = e1e_rphy(hw, MII_ADVERTISE, &mii_autoneg_adv_reg);
932 if (phy->autoneg_mask & ADVERTISE_1000_FULL) {
933 /* Read the MII 1000Base-T Control Register (Address 9). */
934 ret_val = e1e_rphy(hw, MII_CTRL1000, &mii_1000t_ctrl_reg);
939 /* Need to parse both autoneg_advertised and fc and set up
940 * the appropriate PHY registers. First we will parse for
941 * autoneg_advertised software override. Since we can advertise
942 * a plethora of combinations, we need to check each bit
946 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
947 * Advertisement Register (Address 4) and the 1000 mb speed bits in
948 * the 1000Base-T Control Register (Address 9).
950 mii_autoneg_adv_reg &= ~(ADVERTISE_100FULL |
952 ADVERTISE_10FULL | ADVERTISE_10HALF);
953 mii_1000t_ctrl_reg &= ~(ADVERTISE_1000HALF | ADVERTISE_1000FULL);
955 e_dbg("autoneg_advertised %x\n", phy->autoneg_advertised);
957 /* Do we want to advertise 10 Mb Half Duplex? */
958 if (phy->autoneg_advertised & ADVERTISE_10_HALF) {
959 e_dbg("Advertise 10mb Half duplex\n");
960 mii_autoneg_adv_reg |= ADVERTISE_10HALF;
963 /* Do we want to advertise 10 Mb Full Duplex? */
964 if (phy->autoneg_advertised & ADVERTISE_10_FULL) {
965 e_dbg("Advertise 10mb Full duplex\n");
966 mii_autoneg_adv_reg |= ADVERTISE_10FULL;
969 /* Do we want to advertise 100 Mb Half Duplex? */
970 if (phy->autoneg_advertised & ADVERTISE_100_HALF) {
971 e_dbg("Advertise 100mb Half duplex\n");
972 mii_autoneg_adv_reg |= ADVERTISE_100HALF;
975 /* Do we want to advertise 100 Mb Full Duplex? */
976 if (phy->autoneg_advertised & ADVERTISE_100_FULL) {
977 e_dbg("Advertise 100mb Full duplex\n");
978 mii_autoneg_adv_reg |= ADVERTISE_100FULL;
981 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
982 if (phy->autoneg_advertised & ADVERTISE_1000_HALF)
983 e_dbg("Advertise 1000mb Half duplex request denied!\n");
985 /* Do we want to advertise 1000 Mb Full Duplex? */
986 if (phy->autoneg_advertised & ADVERTISE_1000_FULL) {
987 e_dbg("Advertise 1000mb Full duplex\n");
988 mii_1000t_ctrl_reg |= ADVERTISE_1000FULL;
991 /* Check for a software override of the flow control settings, and
992 * setup the PHY advertisement registers accordingly. If
993 * auto-negotiation is enabled, then software will have to set the
994 * "PAUSE" bits to the correct value in the Auto-Negotiation
995 * Advertisement Register (MII_ADVERTISE) and re-start auto-
998 * The possible values of the "fc" parameter are:
999 * 0: Flow control is completely disabled
1000 * 1: Rx flow control is enabled (we can receive pause frames
1001 * but not send pause frames).
1002 * 2: Tx flow control is enabled (we can send pause frames
1003 * but we do not support receiving pause frames).
1004 * 3: Both Rx and Tx flow control (symmetric) are enabled.
1005 * other: No software override. The flow control configuration
1006 * in the EEPROM is used.
1008 switch (hw->fc.current_mode) {
1010 /* Flow control (Rx & Tx) is completely disabled by a
1011 * software over-ride.
1013 mii_autoneg_adv_reg &=
1014 ~(ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP);
1015 phy->autoneg_advertised &=
1016 ~(ADVERTISED_Pause | ADVERTISED_Asym_Pause);
1018 case e1000_fc_rx_pause:
1019 /* Rx Flow control is enabled, and Tx Flow control is
1020 * disabled, by a software over-ride.
1022 * Since there really isn't a way to advertise that we are
1023 * capable of Rx Pause ONLY, we will advertise that we
1024 * support both symmetric and asymmetric Rx PAUSE. Later
1025 * (in e1000e_config_fc_after_link_up) we will disable the
1026 * hw's ability to send PAUSE frames.
1028 mii_autoneg_adv_reg |=
1029 (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP);
1030 phy->autoneg_advertised |=
1031 (ADVERTISED_Pause | ADVERTISED_Asym_Pause);
1033 case e1000_fc_tx_pause:
1034 /* Tx Flow control is enabled, and Rx Flow control is
1035 * disabled, by a software over-ride.
1037 mii_autoneg_adv_reg |= ADVERTISE_PAUSE_ASYM;
1038 mii_autoneg_adv_reg &= ~ADVERTISE_PAUSE_CAP;
1039 phy->autoneg_advertised |= ADVERTISED_Asym_Pause;
1040 phy->autoneg_advertised &= ~ADVERTISED_Pause;
1043 /* Flow control (both Rx and Tx) is enabled by a software
1046 mii_autoneg_adv_reg |=
1047 (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP);
1048 phy->autoneg_advertised |=
1049 (ADVERTISED_Pause | ADVERTISED_Asym_Pause);
1052 e_dbg("Flow control param set incorrectly\n");
1053 return -E1000_ERR_CONFIG;
1056 ret_val = e1e_wphy(hw, MII_ADVERTISE, mii_autoneg_adv_reg);
1060 e_dbg("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
1062 if (phy->autoneg_mask & ADVERTISE_1000_FULL)
1063 ret_val = e1e_wphy(hw, MII_CTRL1000, mii_1000t_ctrl_reg);
1069 * e1000_copper_link_autoneg - Setup/Enable autoneg for copper link
1070 * @hw: pointer to the HW structure
1072 * Performs initial bounds checking on autoneg advertisement parameter, then
1073 * configure to advertise the full capability. Setup the PHY to autoneg
1074 * and restart the negotiation process between the link partner. If
1075 * autoneg_wait_to_complete, then wait for autoneg to complete before exiting.
1077 static s32 e1000_copper_link_autoneg(struct e1000_hw *hw)
1079 struct e1000_phy_info *phy = &hw->phy;
1083 /* Perform some bounds checking on the autoneg advertisement
1086 phy->autoneg_advertised &= phy->autoneg_mask;
1088 /* If autoneg_advertised is zero, we assume it was not defaulted
1089 * by the calling code so we set to advertise full capability.
1091 if (!phy->autoneg_advertised)
1092 phy->autoneg_advertised = phy->autoneg_mask;
1094 e_dbg("Reconfiguring auto-neg advertisement params\n");
1095 ret_val = e1000_phy_setup_autoneg(hw);
1097 e_dbg("Error Setting up Auto-Negotiation\n");
1100 e_dbg("Restarting Auto-Neg\n");
1102 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
1103 * the Auto Neg Restart bit in the PHY control register.
1105 ret_val = e1e_rphy(hw, MII_BMCR, &phy_ctrl);
1109 phy_ctrl |= (BMCR_ANENABLE | BMCR_ANRESTART);
1110 ret_val = e1e_wphy(hw, MII_BMCR, phy_ctrl);
1114 /* Does the user want to wait for Auto-Neg to complete here, or
1115 * check at a later time (for example, callback routine).
1117 if (phy->autoneg_wait_to_complete) {
1118 ret_val = e1000_wait_autoneg(hw);
1120 e_dbg("Error while waiting for autoneg to complete\n");
1125 hw->mac.get_link_status = true;
1131 * e1000e_setup_copper_link - Configure copper link settings
1132 * @hw: pointer to the HW structure
1134 * Calls the appropriate function to configure the link for auto-neg or forced
1135 * speed and duplex. Then we check for link, once link is established calls
1136 * to configure collision distance and flow control are called. If link is
1137 * not established, we return -E1000_ERR_PHY (-2).
1139 s32 e1000e_setup_copper_link(struct e1000_hw *hw)
1144 if (hw->mac.autoneg) {
1145 /* Setup autoneg and flow control advertisement and perform
1148 ret_val = e1000_copper_link_autoneg(hw);
1152 /* PHY will be set to 10H, 10F, 100H or 100F
1153 * depending on user settings.
1155 e_dbg("Forcing Speed and Duplex\n");
1156 ret_val = hw->phy.ops.force_speed_duplex(hw);
1158 e_dbg("Error Forcing Speed and Duplex\n");
1163 /* Check link status. Wait up to 100 microseconds for link to become
1166 ret_val = e1000e_phy_has_link_generic(hw, COPPER_LINK_UP_LIMIT, 10,
1172 e_dbg("Valid link established!!!\n");
1173 hw->mac.ops.config_collision_dist(hw);
1174 ret_val = e1000e_config_fc_after_link_up(hw);
1176 e_dbg("Unable to establish link!!!\n");
1183 * e1000e_phy_force_speed_duplex_igp - Force speed/duplex for igp PHY
1184 * @hw: pointer to the HW structure
1186 * Calls the PHY setup function to force speed and duplex. Clears the
1187 * auto-crossover to force MDI manually. Waits for link and returns
1188 * successful if link up is successful, else -E1000_ERR_PHY (-2).
1190 s32 e1000e_phy_force_speed_duplex_igp(struct e1000_hw *hw)
1192 struct e1000_phy_info *phy = &hw->phy;
1197 ret_val = e1e_rphy(hw, MII_BMCR, &phy_data);
1201 e1000e_phy_force_speed_duplex_setup(hw, &phy_data);
1203 ret_val = e1e_wphy(hw, MII_BMCR, phy_data);
1207 /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
1208 * forced whenever speed and duplex are forced.
1210 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1214 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1215 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1217 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1221 e_dbg("IGP PSCR: %X\n", phy_data);
1225 if (phy->autoneg_wait_to_complete) {
1226 e_dbg("Waiting for forced speed/duplex link on IGP phy.\n");
1228 ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
1234 e_dbg("Link taking longer than expected.\n");
1237 ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
1245 * e1000e_phy_force_speed_duplex_m88 - Force speed/duplex for m88 PHY
1246 * @hw: pointer to the HW structure
1248 * Calls the PHY setup function to force speed and duplex. Clears the
1249 * auto-crossover to force MDI manually. Resets the PHY to commit the
1250 * changes. If time expires while waiting for link up, we reset the DSP.
1251 * After reset, TX_CLK and CRS on Tx must be set. Return successful upon
1252 * successful completion, else return corresponding error code.
1254 s32 e1000e_phy_force_speed_duplex_m88(struct e1000_hw *hw)
1256 struct e1000_phy_info *phy = &hw->phy;
1261 /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
1262 * forced whenever speed and duplex are forced.
1264 ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1268 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1269 ret_val = e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1273 e_dbg("M88E1000 PSCR: %X\n", phy_data);
1275 ret_val = e1e_rphy(hw, MII_BMCR, &phy_data);
1279 e1000e_phy_force_speed_duplex_setup(hw, &phy_data);
1281 ret_val = e1e_wphy(hw, MII_BMCR, phy_data);
1285 /* Reset the phy to commit changes. */
1286 if (hw->phy.ops.commit) {
1287 ret_val = hw->phy.ops.commit(hw);
1292 if (phy->autoneg_wait_to_complete) {
1293 e_dbg("Waiting for forced speed/duplex link on M88 phy.\n");
1295 ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
1301 if (hw->phy.type != e1000_phy_m88) {
1302 e_dbg("Link taking longer than expected.\n");
1304 /* We didn't get link.
1305 * Reset the DSP and cross our fingers.
1307 ret_val = e1e_wphy(hw, M88E1000_PHY_PAGE_SELECT,
1311 ret_val = e1000e_phy_reset_dsp(hw);
1318 ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
1324 if (hw->phy.type != e1000_phy_m88)
1327 ret_val = e1e_rphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1331 /* Resetting the phy means we need to re-force TX_CLK in the
1332 * Extended PHY Specific Control Register to 25MHz clock from
1333 * the reset value of 2.5MHz.
1335 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1336 ret_val = e1e_wphy(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1340 /* In addition, we must re-enable CRS on Tx for both half and full
1343 ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1347 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1348 ret_val = e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1354 * e1000_phy_force_speed_duplex_ife - Force PHY speed & duplex
1355 * @hw: pointer to the HW structure
1357 * Forces the speed and duplex settings of the PHY.
1358 * This is a function pointer entry point only called by
1359 * PHY setup routines.
1361 s32 e1000_phy_force_speed_duplex_ife(struct e1000_hw *hw)
1363 struct e1000_phy_info *phy = &hw->phy;
1368 ret_val = e1e_rphy(hw, MII_BMCR, &data);
1372 e1000e_phy_force_speed_duplex_setup(hw, &data);
1374 ret_val = e1e_wphy(hw, MII_BMCR, data);
1378 /* Disable MDI-X support for 10/100 */
1379 ret_val = e1e_rphy(hw, IFE_PHY_MDIX_CONTROL, &data);
1383 data &= ~IFE_PMC_AUTO_MDIX;
1384 data &= ~IFE_PMC_FORCE_MDIX;
1386 ret_val = e1e_wphy(hw, IFE_PHY_MDIX_CONTROL, data);
1390 e_dbg("IFE PMC: %X\n", data);
1394 if (phy->autoneg_wait_to_complete) {
1395 e_dbg("Waiting for forced speed/duplex link on IFE phy.\n");
1397 ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
1403 e_dbg("Link taking longer than expected.\n");
1406 ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
1416 * e1000e_phy_force_speed_duplex_setup - Configure forced PHY speed/duplex
1417 * @hw: pointer to the HW structure
1418 * @phy_ctrl: pointer to current value of MII_BMCR
1420 * Forces speed and duplex on the PHY by doing the following: disable flow
1421 * control, force speed/duplex on the MAC, disable auto speed detection,
1422 * disable auto-negotiation, configure duplex, configure speed, configure
1423 * the collision distance, write configuration to CTRL register. The
1424 * caller must write to the MII_BMCR register for these settings to
1427 void e1000e_phy_force_speed_duplex_setup(struct e1000_hw *hw, u16 *phy_ctrl)
1429 struct e1000_mac_info *mac = &hw->mac;
1432 /* Turn off flow control when forcing speed/duplex */
1433 hw->fc.current_mode = e1000_fc_none;
1435 /* Force speed/duplex on the mac */
1437 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1438 ctrl &= ~E1000_CTRL_SPD_SEL;
1440 /* Disable Auto Speed Detection */
1441 ctrl &= ~E1000_CTRL_ASDE;
1443 /* Disable autoneg on the phy */
1444 *phy_ctrl &= ~BMCR_ANENABLE;
1446 /* Forcing Full or Half Duplex? */
1447 if (mac->forced_speed_duplex & E1000_ALL_HALF_DUPLEX) {
1448 ctrl &= ~E1000_CTRL_FD;
1449 *phy_ctrl &= ~BMCR_FULLDPLX;
1450 e_dbg("Half Duplex\n");
1452 ctrl |= E1000_CTRL_FD;
1453 *phy_ctrl |= BMCR_FULLDPLX;
1454 e_dbg("Full Duplex\n");
1457 /* Forcing 10mb or 100mb? */
1458 if (mac->forced_speed_duplex & E1000_ALL_100_SPEED) {
1459 ctrl |= E1000_CTRL_SPD_100;
1460 *phy_ctrl |= BMCR_SPEED100;
1461 *phy_ctrl &= ~BMCR_SPEED1000;
1462 e_dbg("Forcing 100mb\n");
1464 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1465 *phy_ctrl &= ~(BMCR_SPEED1000 | BMCR_SPEED100);
1466 e_dbg("Forcing 10mb\n");
1469 hw->mac.ops.config_collision_dist(hw);
1475 * e1000e_set_d3_lplu_state - Sets low power link up state for D3
1476 * @hw: pointer to the HW structure
1477 * @active: boolean used to enable/disable lplu
1479 * Success returns 0, Failure returns 1
1481 * The low power link up (lplu) state is set to the power management level D3
1482 * and SmartSpeed is disabled when active is true, else clear lplu for D3
1483 * and enable Smartspeed. LPLU and Smartspeed are mutually exclusive. LPLU
1484 * is used during Dx states where the power conservation is most important.
1485 * During driver activity, SmartSpeed should be enabled so performance is
1488 s32 e1000e_set_d3_lplu_state(struct e1000_hw *hw, bool active)
1490 struct e1000_phy_info *phy = &hw->phy;
1494 ret_val = e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &data);
1499 data &= ~IGP02E1000_PM_D3_LPLU;
1500 ret_val = e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, data);
1503 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
1504 * during Dx states where the power conservation is most
1505 * important. During driver activity we should enable
1506 * SmartSpeed, so performance is maintained.
1508 if (phy->smart_speed == e1000_smart_speed_on) {
1509 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
1514 data |= IGP01E1000_PSCFR_SMART_SPEED;
1515 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
1519 } else if (phy->smart_speed == e1000_smart_speed_off) {
1520 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
1525 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1526 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
1531 } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
1532 (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
1533 (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
1534 data |= IGP02E1000_PM_D3_LPLU;
1535 ret_val = e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, data);
1539 /* When LPLU is enabled, we should disable SmartSpeed */
1540 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
1544 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1545 ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
1552 * e1000e_check_downshift - Checks whether a downshift in speed occurred
1553 * @hw: pointer to the HW structure
1555 * Success returns 0, Failure returns 1
1557 * A downshift is detected by querying the PHY link health.
1559 s32 e1000e_check_downshift(struct e1000_hw *hw)
1561 struct e1000_phy_info *phy = &hw->phy;
1563 u16 phy_data, offset, mask;
1565 switch (phy->type) {
1567 case e1000_phy_gg82563:
1569 case e1000_phy_82578:
1570 offset = M88E1000_PHY_SPEC_STATUS;
1571 mask = M88E1000_PSSR_DOWNSHIFT;
1573 case e1000_phy_igp_2:
1574 case e1000_phy_igp_3:
1575 offset = IGP01E1000_PHY_LINK_HEALTH;
1576 mask = IGP01E1000_PLHR_SS_DOWNGRADE;
1579 /* speed downshift not supported */
1580 phy->speed_downgraded = false;
1584 ret_val = e1e_rphy(hw, offset, &phy_data);
1587 phy->speed_downgraded = !!(phy_data & mask);
1593 * e1000_check_polarity_m88 - Checks the polarity.
1594 * @hw: pointer to the HW structure
1596 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1598 * Polarity is determined based on the PHY specific status register.
1600 s32 e1000_check_polarity_m88(struct e1000_hw *hw)
1602 struct e1000_phy_info *phy = &hw->phy;
1606 ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &data);
1609 phy->cable_polarity = ((data & M88E1000_PSSR_REV_POLARITY)
1610 ? e1000_rev_polarity_reversed
1611 : e1000_rev_polarity_normal);
1617 * e1000_check_polarity_igp - Checks the polarity.
1618 * @hw: pointer to the HW structure
1620 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1622 * Polarity is determined based on the PHY port status register, and the
1623 * current speed (since there is no polarity at 100Mbps).
1625 s32 e1000_check_polarity_igp(struct e1000_hw *hw)
1627 struct e1000_phy_info *phy = &hw->phy;
1629 u16 data, offset, mask;
1631 /* Polarity is determined based on the speed of
1634 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_STATUS, &data);
1638 if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
1639 IGP01E1000_PSSR_SPEED_1000MBPS) {
1640 offset = IGP01E1000_PHY_PCS_INIT_REG;
1641 mask = IGP01E1000_PHY_POLARITY_MASK;
1643 /* This really only applies to 10Mbps since
1644 * there is no polarity for 100Mbps (always 0).
1646 offset = IGP01E1000_PHY_PORT_STATUS;
1647 mask = IGP01E1000_PSSR_POLARITY_REVERSED;
1650 ret_val = e1e_rphy(hw, offset, &data);
1653 phy->cable_polarity = ((data & mask)
1654 ? e1000_rev_polarity_reversed
1655 : e1000_rev_polarity_normal);
1661 * e1000_check_polarity_ife - Check cable polarity for IFE PHY
1662 * @hw: pointer to the HW structure
1664 * Polarity is determined on the polarity reversal feature being enabled.
1666 s32 e1000_check_polarity_ife(struct e1000_hw *hw)
1668 struct e1000_phy_info *phy = &hw->phy;
1670 u16 phy_data, offset, mask;
1672 /* Polarity is determined based on the reversal feature being enabled.
1674 if (phy->polarity_correction) {
1675 offset = IFE_PHY_EXTENDED_STATUS_CONTROL;
1676 mask = IFE_PESC_POLARITY_REVERSED;
1678 offset = IFE_PHY_SPECIAL_CONTROL;
1679 mask = IFE_PSC_FORCE_POLARITY;
1682 ret_val = e1e_rphy(hw, offset, &phy_data);
1685 phy->cable_polarity = ((phy_data & mask)
1686 ? e1000_rev_polarity_reversed
1687 : e1000_rev_polarity_normal);
1693 * e1000_wait_autoneg - Wait for auto-neg completion
1694 * @hw: pointer to the HW structure
1696 * Waits for auto-negotiation to complete or for the auto-negotiation time
1697 * limit to expire, which ever happens first.
1699 static s32 e1000_wait_autoneg(struct e1000_hw *hw)
1704 /* Break after autoneg completes or PHY_AUTO_NEG_LIMIT expires. */
1705 for (i = PHY_AUTO_NEG_LIMIT; i > 0; i--) {
1706 ret_val = e1e_rphy(hw, MII_BMSR, &phy_status);
1709 ret_val = e1e_rphy(hw, MII_BMSR, &phy_status);
1712 if (phy_status & BMSR_ANEGCOMPLETE)
1717 /* PHY_AUTO_NEG_TIME expiration doesn't guarantee auto-negotiation
1724 * e1000e_phy_has_link_generic - Polls PHY for link
1725 * @hw: pointer to the HW structure
1726 * @iterations: number of times to poll for link
1727 * @usec_interval: delay between polling attempts
1728 * @success: pointer to whether polling was successful or not
1730 * Polls the PHY status register for link, 'iterations' number of times.
1732 s32 e1000e_phy_has_link_generic(struct e1000_hw *hw, u32 iterations,
1733 u32 usec_interval, bool *success)
1739 for (i = 0; i < iterations; i++) {
1740 /* Some PHYs require the MII_BMSR register to be read
1741 * twice due to the link bit being sticky. No harm doing
1742 * it across the board.
1744 ret_val = e1e_rphy(hw, MII_BMSR, &phy_status);
1746 /* If the first read fails, another entity may have
1747 * ownership of the resources, wait and try again to
1748 * see if they have relinquished the resources yet.
1750 if (usec_interval >= 1000)
1751 msleep(usec_interval / 1000);
1753 udelay(usec_interval);
1755 ret_val = e1e_rphy(hw, MII_BMSR, &phy_status);
1758 if (phy_status & BMSR_LSTATUS) {
1762 if (usec_interval >= 1000)
1763 msleep(usec_interval / 1000);
1765 udelay(usec_interval);
1772 * e1000e_get_cable_length_m88 - Determine cable length for m88 PHY
1773 * @hw: pointer to the HW structure
1775 * Reads the PHY specific status register to retrieve the cable length
1776 * information. The cable length is determined by averaging the minimum and
1777 * maximum values to get the "average" cable length. The m88 PHY has four
1778 * possible cable length values, which are:
1779 * Register Value Cable Length
1783 * 3 110 - 140 meters
1786 s32 e1000e_get_cable_length_m88(struct e1000_hw *hw)
1788 struct e1000_phy_info *phy = &hw->phy;
1790 u16 phy_data, index;
1792 ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
1796 index = ((phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
1797 M88E1000_PSSR_CABLE_LENGTH_SHIFT);
1799 if (index >= M88E1000_CABLE_LENGTH_TABLE_SIZE - 1)
1800 return -E1000_ERR_PHY;
1802 phy->min_cable_length = e1000_m88_cable_length_table[index];
1803 phy->max_cable_length = e1000_m88_cable_length_table[index + 1];
1805 phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
1811 * e1000e_get_cable_length_igp_2 - Determine cable length for igp2 PHY
1812 * @hw: pointer to the HW structure
1814 * The automatic gain control (agc) normalizes the amplitude of the
1815 * received signal, adjusting for the attenuation produced by the
1816 * cable. By reading the AGC registers, which represent the
1817 * combination of coarse and fine gain value, the value can be put
1818 * into a lookup table to obtain the approximate cable length
1821 s32 e1000e_get_cable_length_igp_2(struct e1000_hw *hw)
1823 struct e1000_phy_info *phy = &hw->phy;
1825 u16 phy_data, i, agc_value = 0;
1826 u16 cur_agc_index, max_agc_index = 0;
1827 u16 min_agc_index = IGP02E1000_CABLE_LENGTH_TABLE_SIZE - 1;
1828 static const u16 agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] = {
1829 IGP02E1000_PHY_AGC_A,
1830 IGP02E1000_PHY_AGC_B,
1831 IGP02E1000_PHY_AGC_C,
1832 IGP02E1000_PHY_AGC_D
1835 /* Read the AGC registers for all channels */
1836 for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
1837 ret_val = e1e_rphy(hw, agc_reg_array[i], &phy_data);
1841 /* Getting bits 15:9, which represent the combination of
1842 * coarse and fine gain values. The result is a number
1843 * that can be put into the lookup table to obtain the
1844 * approximate cable length.
1846 cur_agc_index = ((phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
1847 IGP02E1000_AGC_LENGTH_MASK);
1849 /* Array index bound check. */
1850 if ((cur_agc_index >= IGP02E1000_CABLE_LENGTH_TABLE_SIZE) ||
1851 (cur_agc_index == 0))
1852 return -E1000_ERR_PHY;
1854 /* Remove min & max AGC values from calculation. */
1855 if (e1000_igp_2_cable_length_table[min_agc_index] >
1856 e1000_igp_2_cable_length_table[cur_agc_index])
1857 min_agc_index = cur_agc_index;
1858 if (e1000_igp_2_cable_length_table[max_agc_index] <
1859 e1000_igp_2_cable_length_table[cur_agc_index])
1860 max_agc_index = cur_agc_index;
1862 agc_value += e1000_igp_2_cable_length_table[cur_agc_index];
1865 agc_value -= (e1000_igp_2_cable_length_table[min_agc_index] +
1866 e1000_igp_2_cable_length_table[max_agc_index]);
1867 agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
1869 /* Calculate cable length with the error range of +/- 10 meters. */
1870 phy->min_cable_length = (((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
1871 (agc_value - IGP02E1000_AGC_RANGE) : 0);
1872 phy->max_cable_length = agc_value + IGP02E1000_AGC_RANGE;
1874 phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
1880 * e1000e_get_phy_info_m88 - Retrieve PHY information
1881 * @hw: pointer to the HW structure
1883 * Valid for only copper links. Read the PHY status register (sticky read)
1884 * to verify that link is up. Read the PHY special control register to
1885 * determine the polarity and 10base-T extended distance. Read the PHY
1886 * special status register to determine MDI/MDIx and current speed. If
1887 * speed is 1000, then determine cable length, local and remote receiver.
1889 s32 e1000e_get_phy_info_m88(struct e1000_hw *hw)
1891 struct e1000_phy_info *phy = &hw->phy;
1896 if (phy->media_type != e1000_media_type_copper) {
1897 e_dbg("Phy info is only valid for copper media\n");
1898 return -E1000_ERR_CONFIG;
1901 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
1906 e_dbg("Phy info is only valid if link is up\n");
1907 return -E1000_ERR_CONFIG;
1910 ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1914 phy->polarity_correction = !!(phy_data &
1915 M88E1000_PSCR_POLARITY_REVERSAL);
1917 ret_val = e1000_check_polarity_m88(hw);
1921 ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
1925 phy->is_mdix = !!(phy_data & M88E1000_PSSR_MDIX);
1927 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
1928 ret_val = hw->phy.ops.get_cable_length(hw);
1932 ret_val = e1e_rphy(hw, MII_STAT1000, &phy_data);
1936 phy->local_rx = (phy_data & LPA_1000LOCALRXOK)
1937 ? e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
1939 phy->remote_rx = (phy_data & LPA_1000REMRXOK)
1940 ? e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
1942 /* Set values to "undefined" */
1943 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
1944 phy->local_rx = e1000_1000t_rx_status_undefined;
1945 phy->remote_rx = e1000_1000t_rx_status_undefined;
1952 * e1000e_get_phy_info_igp - Retrieve igp PHY information
1953 * @hw: pointer to the HW structure
1955 * Read PHY status to determine if link is up. If link is up, then
1956 * set/determine 10base-T extended distance and polarity correction. Read
1957 * PHY port status to determine MDI/MDIx and speed. Based on the speed,
1958 * determine on the cable length, local and remote receiver.
1960 s32 e1000e_get_phy_info_igp(struct e1000_hw *hw)
1962 struct e1000_phy_info *phy = &hw->phy;
1967 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
1972 e_dbg("Phy info is only valid if link is up\n");
1973 return -E1000_ERR_CONFIG;
1976 phy->polarity_correction = true;
1978 ret_val = e1000_check_polarity_igp(hw);
1982 ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_STATUS, &data);
1986 phy->is_mdix = !!(data & IGP01E1000_PSSR_MDIX);
1988 if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
1989 IGP01E1000_PSSR_SPEED_1000MBPS) {
1990 ret_val = phy->ops.get_cable_length(hw);
1994 ret_val = e1e_rphy(hw, MII_STAT1000, &data);
1998 phy->local_rx = (data & LPA_1000LOCALRXOK)
1999 ? e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
2001 phy->remote_rx = (data & LPA_1000REMRXOK)
2002 ? e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
2004 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
2005 phy->local_rx = e1000_1000t_rx_status_undefined;
2006 phy->remote_rx = e1000_1000t_rx_status_undefined;
2013 * e1000_get_phy_info_ife - Retrieves various IFE PHY states
2014 * @hw: pointer to the HW structure
2016 * Populates "phy" structure with various feature states.
2018 s32 e1000_get_phy_info_ife(struct e1000_hw *hw)
2020 struct e1000_phy_info *phy = &hw->phy;
2025 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
2030 e_dbg("Phy info is only valid if link is up\n");
2031 return -E1000_ERR_CONFIG;
2034 ret_val = e1e_rphy(hw, IFE_PHY_SPECIAL_CONTROL, &data);
2037 phy->polarity_correction = !(data & IFE_PSC_AUTO_POLARITY_DISABLE);
2039 if (phy->polarity_correction) {
2040 ret_val = e1000_check_polarity_ife(hw);
2044 /* Polarity is forced */
2045 phy->cable_polarity = ((data & IFE_PSC_FORCE_POLARITY)
2046 ? e1000_rev_polarity_reversed
2047 : e1000_rev_polarity_normal);
2050 ret_val = e1e_rphy(hw, IFE_PHY_MDIX_CONTROL, &data);
2054 phy->is_mdix = !!(data & IFE_PMC_MDIX_STATUS);
2056 /* The following parameters are undefined for 10/100 operation. */
2057 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
2058 phy->local_rx = e1000_1000t_rx_status_undefined;
2059 phy->remote_rx = e1000_1000t_rx_status_undefined;
2065 * e1000e_phy_sw_reset - PHY software reset
2066 * @hw: pointer to the HW structure
2068 * Does a software reset of the PHY by reading the PHY control register and
2069 * setting/write the control register reset bit to the PHY.
2071 s32 e1000e_phy_sw_reset(struct e1000_hw *hw)
2076 ret_val = e1e_rphy(hw, MII_BMCR, &phy_ctrl);
2080 phy_ctrl |= BMCR_RESET;
2081 ret_val = e1e_wphy(hw, MII_BMCR, phy_ctrl);
2091 * e1000e_phy_hw_reset_generic - PHY hardware reset
2092 * @hw: pointer to the HW structure
2094 * Verify the reset block is not blocking us from resetting. Acquire
2095 * semaphore (if necessary) and read/set/write the device control reset
2096 * bit in the PHY. Wait the appropriate delay time for the device to
2097 * reset and release the semaphore (if necessary).
2099 s32 e1000e_phy_hw_reset_generic(struct e1000_hw *hw)
2101 struct e1000_phy_info *phy = &hw->phy;
2105 if (phy->ops.check_reset_block) {
2106 ret_val = phy->ops.check_reset_block(hw);
2111 ret_val = phy->ops.acquire(hw);
2116 ew32(CTRL, ctrl | E1000_CTRL_PHY_RST);
2119 udelay(phy->reset_delay_us);
2124 usleep_range(150, 300);
2126 phy->ops.release(hw);
2128 return phy->ops.get_cfg_done(hw);
2132 * e1000e_get_cfg_done_generic - Generic configuration done
2133 * @hw: pointer to the HW structure
2135 * Generic function to wait 10 milli-seconds for configuration to complete
2136 * and return success.
2138 s32 e1000e_get_cfg_done_generic(struct e1000_hw __always_unused *hw)
2146 * e1000e_phy_init_script_igp3 - Inits the IGP3 PHY
2147 * @hw: pointer to the HW structure
2149 * Initializes a Intel Gigabit PHY3 when an EEPROM is not present.
2151 s32 e1000e_phy_init_script_igp3(struct e1000_hw *hw)
2153 e_dbg("Running IGP 3 PHY init script\n");
2155 /* PHY init IGP 3 */
2156 /* Enable rise/fall, 10-mode work in class-A */
2157 e1e_wphy(hw, 0x2F5B, 0x9018);
2158 /* Remove all caps from Replica path filter */
2159 e1e_wphy(hw, 0x2F52, 0x0000);
2160 /* Bias trimming for ADC, AFE and Driver (Default) */
2161 e1e_wphy(hw, 0x2FB1, 0x8B24);
2162 /* Increase Hybrid poly bias */
2163 e1e_wphy(hw, 0x2FB2, 0xF8F0);
2164 /* Add 4% to Tx amplitude in Gig mode */
2165 e1e_wphy(hw, 0x2010, 0x10B0);
2166 /* Disable trimming (TTT) */
2167 e1e_wphy(hw, 0x2011, 0x0000);
2168 /* Poly DC correction to 94.6% + 2% for all channels */
2169 e1e_wphy(hw, 0x20DD, 0x249A);
2170 /* ABS DC correction to 95.9% */
2171 e1e_wphy(hw, 0x20DE, 0x00D3);
2172 /* BG temp curve trim */
2173 e1e_wphy(hw, 0x28B4, 0x04CE);
2174 /* Increasing ADC OPAMP stage 1 currents to max */
2175 e1e_wphy(hw, 0x2F70, 0x29E4);
2176 /* Force 1000 ( required for enabling PHY regs configuration) */
2177 e1e_wphy(hw, 0x0000, 0x0140);
2178 /* Set upd_freq to 6 */
2179 e1e_wphy(hw, 0x1F30, 0x1606);
2181 e1e_wphy(hw, 0x1F31, 0xB814);
2182 /* Disable adaptive fixed FFE (Default) */
2183 e1e_wphy(hw, 0x1F35, 0x002A);
2184 /* Enable FFE hysteresis */
2185 e1e_wphy(hw, 0x1F3E, 0x0067);
2186 /* Fixed FFE for short cable lengths */
2187 e1e_wphy(hw, 0x1F54, 0x0065);
2188 /* Fixed FFE for medium cable lengths */
2189 e1e_wphy(hw, 0x1F55, 0x002A);
2190 /* Fixed FFE for long cable lengths */
2191 e1e_wphy(hw, 0x1F56, 0x002A);
2192 /* Enable Adaptive Clip Threshold */
2193 e1e_wphy(hw, 0x1F72, 0x3FB0);
2194 /* AHT reset limit to 1 */
2195 e1e_wphy(hw, 0x1F76, 0xC0FF);
2196 /* Set AHT master delay to 127 msec */
2197 e1e_wphy(hw, 0x1F77, 0x1DEC);
2198 /* Set scan bits for AHT */
2199 e1e_wphy(hw, 0x1F78, 0xF9EF);
2200 /* Set AHT Preset bits */
2201 e1e_wphy(hw, 0x1F79, 0x0210);
2202 /* Change integ_factor of channel A to 3 */
2203 e1e_wphy(hw, 0x1895, 0x0003);
2204 /* Change prop_factor of channels BCD to 8 */
2205 e1e_wphy(hw, 0x1796, 0x0008);
2206 /* Change cg_icount + enable integbp for channels BCD */
2207 e1e_wphy(hw, 0x1798, 0xD008);
2208 /* Change cg_icount + enable integbp + change prop_factor_master
2209 * to 8 for channel A
2211 e1e_wphy(hw, 0x1898, 0xD918);
2212 /* Disable AHT in Slave mode on channel A */
2213 e1e_wphy(hw, 0x187A, 0x0800);
2214 /* Enable LPLU and disable AN to 1000 in non-D0a states,
2217 e1e_wphy(hw, 0x0019, 0x008D);
2218 /* Enable restart AN on an1000_dis change */
2219 e1e_wphy(hw, 0x001B, 0x2080);
2220 /* Enable wh_fifo read clock in 10/100 modes */
2221 e1e_wphy(hw, 0x0014, 0x0045);
2222 /* Restart AN, Speed selection is 1000 */
2223 e1e_wphy(hw, 0x0000, 0x1340);
2229 * e1000e_get_phy_type_from_id - Get PHY type from id
2230 * @phy_id: phy_id read from the phy
2232 * Returns the phy type from the id.
2234 enum e1000_phy_type e1000e_get_phy_type_from_id(u32 phy_id)
2236 enum e1000_phy_type phy_type = e1000_phy_unknown;
2239 case M88E1000_I_PHY_ID:
2240 case M88E1000_E_PHY_ID:
2241 case M88E1111_I_PHY_ID:
2242 case M88E1011_I_PHY_ID:
2243 phy_type = e1000_phy_m88;
2245 case IGP01E1000_I_PHY_ID: /* IGP 1 & 2 share this */
2246 phy_type = e1000_phy_igp_2;
2248 case GG82563_E_PHY_ID:
2249 phy_type = e1000_phy_gg82563;
2251 case IGP03E1000_E_PHY_ID:
2252 phy_type = e1000_phy_igp_3;
2255 case IFE_PLUS_E_PHY_ID:
2256 case IFE_C_E_PHY_ID:
2257 phy_type = e1000_phy_ife;
2259 case BME1000_E_PHY_ID:
2260 case BME1000_E_PHY_ID_R2:
2261 phy_type = e1000_phy_bm;
2263 case I82578_E_PHY_ID:
2264 phy_type = e1000_phy_82578;
2266 case I82577_E_PHY_ID:
2267 phy_type = e1000_phy_82577;
2269 case I82579_E_PHY_ID:
2270 phy_type = e1000_phy_82579;
2273 phy_type = e1000_phy_i217;
2276 phy_type = e1000_phy_unknown;
2283 * e1000e_determine_phy_address - Determines PHY address.
2284 * @hw: pointer to the HW structure
2286 * This uses a trial and error method to loop through possible PHY
2287 * addresses. It tests each by reading the PHY ID registers and
2288 * checking for a match.
2290 s32 e1000e_determine_phy_address(struct e1000_hw *hw)
2294 enum e1000_phy_type phy_type = e1000_phy_unknown;
2296 hw->phy.id = phy_type;
2298 for (phy_addr = 0; phy_addr < E1000_MAX_PHY_ADDR; phy_addr++) {
2299 hw->phy.addr = phy_addr;
2303 e1000e_get_phy_id(hw);
2304 phy_type = e1000e_get_phy_type_from_id(hw->phy.id);
2306 /* If phy_type is valid, break - we found our
2309 if (phy_type != e1000_phy_unknown)
2312 usleep_range(1000, 2000);
2317 return -E1000_ERR_PHY_TYPE;
2321 * e1000_get_phy_addr_for_bm_page - Retrieve PHY page address
2322 * @page: page to access
2323 * @reg: register to check
2325 * Returns the phy address for the page requested.
2327 static u32 e1000_get_phy_addr_for_bm_page(u32 page, u32 reg)
2331 if ((page >= 768) || (page == 0 && reg == 25) || (reg == 31))
2338 * e1000e_write_phy_reg_bm - Write BM PHY register
2339 * @hw: pointer to the HW structure
2340 * @offset: register offset to write to
2341 * @data: data to write at register offset
2343 * Acquires semaphore, if necessary, then writes the data to PHY register
2344 * at the offset. Release any acquired semaphores before exiting.
2346 s32 e1000e_write_phy_reg_bm(struct e1000_hw *hw, u32 offset, u16 data)
2349 u32 page = offset >> IGP_PAGE_SHIFT;
2351 ret_val = hw->phy.ops.acquire(hw);
2355 /* Page 800 works differently than the rest so it has its own func */
2356 if (page == BM_WUC_PAGE) {
2357 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, &data,
2362 hw->phy.addr = e1000_get_phy_addr_for_bm_page(page, offset);
2364 if (offset > MAX_PHY_MULTI_PAGE_REG) {
2365 u32 page_shift, page_select;
2367 /* Page select is register 31 for phy address 1 and 22 for
2368 * phy address 2 and 3. Page select is shifted only for
2371 if (hw->phy.addr == 1) {
2372 page_shift = IGP_PAGE_SHIFT;
2373 page_select = IGP01E1000_PHY_PAGE_SELECT;
2376 page_select = BM_PHY_PAGE_SELECT;
2379 /* Page is shifted left, PHY expects (page x 32) */
2380 ret_val = e1000e_write_phy_reg_mdic(hw, page_select,
2381 (page << page_shift));
2386 ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
2390 hw->phy.ops.release(hw);
2395 * e1000e_read_phy_reg_bm - Read BM PHY register
2396 * @hw: pointer to the HW structure
2397 * @offset: register offset to be read
2398 * @data: pointer to the read data
2400 * Acquires semaphore, if necessary, then reads the PHY register at offset
2401 * and storing the retrieved information in data. Release any acquired
2402 * semaphores before exiting.
2404 s32 e1000e_read_phy_reg_bm(struct e1000_hw *hw, u32 offset, u16 *data)
2407 u32 page = offset >> IGP_PAGE_SHIFT;
2409 ret_val = hw->phy.ops.acquire(hw);
2413 /* Page 800 works differently than the rest so it has its own func */
2414 if (page == BM_WUC_PAGE) {
2415 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, data,
2420 hw->phy.addr = e1000_get_phy_addr_for_bm_page(page, offset);
2422 if (offset > MAX_PHY_MULTI_PAGE_REG) {
2423 u32 page_shift, page_select;
2425 /* Page select is register 31 for phy address 1 and 22 for
2426 * phy address 2 and 3. Page select is shifted only for
2429 if (hw->phy.addr == 1) {
2430 page_shift = IGP_PAGE_SHIFT;
2431 page_select = IGP01E1000_PHY_PAGE_SELECT;
2434 page_select = BM_PHY_PAGE_SELECT;
2437 /* Page is shifted left, PHY expects (page x 32) */
2438 ret_val = e1000e_write_phy_reg_mdic(hw, page_select,
2439 (page << page_shift));
2444 ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
2447 hw->phy.ops.release(hw);
2452 * e1000e_read_phy_reg_bm2 - Read BM PHY register
2453 * @hw: pointer to the HW structure
2454 * @offset: register offset to be read
2455 * @data: pointer to the read data
2457 * Acquires semaphore, if necessary, then reads the PHY register at offset
2458 * and storing the retrieved information in data. Release any acquired
2459 * semaphores before exiting.
2461 s32 e1000e_read_phy_reg_bm2(struct e1000_hw *hw, u32 offset, u16 *data)
2464 u16 page = (u16)(offset >> IGP_PAGE_SHIFT);
2466 ret_val = hw->phy.ops.acquire(hw);
2470 /* Page 800 works differently than the rest so it has its own func */
2471 if (page == BM_WUC_PAGE) {
2472 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, data,
2479 if (offset > MAX_PHY_MULTI_PAGE_REG) {
2480 /* Page is shifted left, PHY expects (page x 32) */
2481 ret_val = e1000e_write_phy_reg_mdic(hw, BM_PHY_PAGE_SELECT,
2488 ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
2491 hw->phy.ops.release(hw);
2496 * e1000e_write_phy_reg_bm2 - Write BM PHY register
2497 * @hw: pointer to the HW structure
2498 * @offset: register offset to write to
2499 * @data: data to write at register offset
2501 * Acquires semaphore, if necessary, then writes the data to PHY register
2502 * at the offset. Release any acquired semaphores before exiting.
2504 s32 e1000e_write_phy_reg_bm2(struct e1000_hw *hw, u32 offset, u16 data)
2507 u16 page = (u16)(offset >> IGP_PAGE_SHIFT);
2509 ret_val = hw->phy.ops.acquire(hw);
2513 /* Page 800 works differently than the rest so it has its own func */
2514 if (page == BM_WUC_PAGE) {
2515 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, &data,
2522 if (offset > MAX_PHY_MULTI_PAGE_REG) {
2523 /* Page is shifted left, PHY expects (page x 32) */
2524 ret_val = e1000e_write_phy_reg_mdic(hw, BM_PHY_PAGE_SELECT,
2531 ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
2535 hw->phy.ops.release(hw);
2540 * e1000_enable_phy_wakeup_reg_access_bm - enable access to BM wakeup registers
2541 * @hw: pointer to the HW structure
2542 * @phy_reg: pointer to store original contents of BM_WUC_ENABLE_REG
2544 * Assumes semaphore already acquired and phy_reg points to a valid memory
2545 * address to store contents of the BM_WUC_ENABLE_REG register.
2547 s32 e1000_enable_phy_wakeup_reg_access_bm(struct e1000_hw *hw, u16 *phy_reg)
2552 /* All page select, port ctrl and wakeup registers use phy address 1 */
2555 /* Select Port Control Registers page */
2556 ret_val = e1000_set_page_igp(hw, (BM_PORT_CTRL_PAGE << IGP_PAGE_SHIFT));
2558 e_dbg("Could not set Port Control page\n");
2562 ret_val = e1000e_read_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, phy_reg);
2564 e_dbg("Could not read PHY register %d.%d\n",
2565 BM_PORT_CTRL_PAGE, BM_WUC_ENABLE_REG);
2569 /* Enable both PHY wakeup mode and Wakeup register page writes.
2570 * Prevent a power state change by disabling ME and Host PHY wakeup.
2573 temp |= BM_WUC_ENABLE_BIT;
2574 temp &= ~(BM_WUC_ME_WU_BIT | BM_WUC_HOST_WU_BIT);
2576 ret_val = e1000e_write_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, temp);
2578 e_dbg("Could not write PHY register %d.%d\n",
2579 BM_PORT_CTRL_PAGE, BM_WUC_ENABLE_REG);
2583 /* Select Host Wakeup Registers page - caller now able to write
2584 * registers on the Wakeup registers page
2586 return e1000_set_page_igp(hw, (BM_WUC_PAGE << IGP_PAGE_SHIFT));
2590 * e1000_disable_phy_wakeup_reg_access_bm - disable access to BM wakeup regs
2591 * @hw: pointer to the HW structure
2592 * @phy_reg: pointer to original contents of BM_WUC_ENABLE_REG
2594 * Restore BM_WUC_ENABLE_REG to its original value.
2596 * Assumes semaphore already acquired and *phy_reg is the contents of the
2597 * BM_WUC_ENABLE_REG before register(s) on BM_WUC_PAGE were accessed by
2600 s32 e1000_disable_phy_wakeup_reg_access_bm(struct e1000_hw *hw, u16 *phy_reg)
2604 /* Select Port Control Registers page */
2605 ret_val = e1000_set_page_igp(hw, (BM_PORT_CTRL_PAGE << IGP_PAGE_SHIFT));
2607 e_dbg("Could not set Port Control page\n");
2611 /* Restore 769.17 to its original value */
2612 ret_val = e1000e_write_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, *phy_reg);
2614 e_dbg("Could not restore PHY register %d.%d\n",
2615 BM_PORT_CTRL_PAGE, BM_WUC_ENABLE_REG);
2621 * e1000_access_phy_wakeup_reg_bm - Read/write BM PHY wakeup register
2622 * @hw: pointer to the HW structure
2623 * @offset: register offset to be read or written
2624 * @data: pointer to the data to read or write
2625 * @read: determines if operation is read or write
2626 * @page_set: BM_WUC_PAGE already set and access enabled
2628 * Read the PHY register at offset and store the retrieved information in
2629 * data, or write data to PHY register at offset. Note the procedure to
2630 * access the PHY wakeup registers is different than reading the other PHY
2631 * registers. It works as such:
2632 * 1) Set 769.17.2 (page 769, register 17, bit 2) = 1
2633 * 2) Set page to 800 for host (801 if we were manageability)
2634 * 3) Write the address using the address opcode (0x11)
2635 * 4) Read or write the data using the data opcode (0x12)
2636 * 5) Restore 769.17.2 to its original value
2638 * Steps 1 and 2 are done by e1000_enable_phy_wakeup_reg_access_bm() and
2639 * step 5 is done by e1000_disable_phy_wakeup_reg_access_bm().
2641 * Assumes semaphore is already acquired. When page_set==true, assumes
2642 * the PHY page is set to BM_WUC_PAGE (i.e. a function in the call stack
2643 * is responsible for calls to e1000_[enable|disable]_phy_wakeup_reg_bm()).
2645 static s32 e1000_access_phy_wakeup_reg_bm(struct e1000_hw *hw, u32 offset,
2646 u16 *data, bool read, bool page_set)
2649 u16 reg = BM_PHY_REG_NUM(offset);
2650 u16 page = BM_PHY_REG_PAGE(offset);
2653 /* Gig must be disabled for MDIO accesses to Host Wakeup reg page */
2654 if ((hw->mac.type == e1000_pchlan) &&
2655 (!(er32(PHY_CTRL) & E1000_PHY_CTRL_GBE_DISABLE)))
2656 e_dbg("Attempting to access page %d while gig enabled.\n",
2660 /* Enable access to PHY wakeup registers */
2661 ret_val = e1000_enable_phy_wakeup_reg_access_bm(hw, &phy_reg);
2663 e_dbg("Could not enable PHY wakeup reg access\n");
2668 e_dbg("Accessing PHY page %d reg 0x%x\n", page, reg);
2670 /* Write the Wakeup register page offset value using opcode 0x11 */
2671 ret_val = e1000e_write_phy_reg_mdic(hw, BM_WUC_ADDRESS_OPCODE, reg);
2673 e_dbg("Could not write address opcode to page %d\n", page);
2678 /* Read the Wakeup register page value using opcode 0x12 */
2679 ret_val = e1000e_read_phy_reg_mdic(hw, BM_WUC_DATA_OPCODE,
2682 /* Write the Wakeup register page value using opcode 0x12 */
2683 ret_val = e1000e_write_phy_reg_mdic(hw, BM_WUC_DATA_OPCODE,
2688 e_dbg("Could not access PHY reg %d.%d\n", page, reg);
2693 ret_val = e1000_disable_phy_wakeup_reg_access_bm(hw, &phy_reg);
2699 * e1000_power_up_phy_copper - Restore copper link in case of PHY power down
2700 * @hw: pointer to the HW structure
2702 * In the case of a PHY power down to save power, or to turn off link during a
2703 * driver unload, or wake on lan is not enabled, restore the link to previous
2706 void e1000_power_up_phy_copper(struct e1000_hw *hw)
2711 /* The PHY will retain its settings across a power down/up cycle */
2712 ret = e1e_rphy(hw, MII_BMCR, &mii_reg);
2714 e_dbg("Error reading PHY register\n");
2717 mii_reg &= ~BMCR_PDOWN;
2718 e1e_wphy(hw, MII_BMCR, mii_reg);
2722 * e1000_power_down_phy_copper - Restore copper link in case of PHY power down
2723 * @hw: pointer to the HW structure
2725 * In the case of a PHY power down to save power, or to turn off link during a
2726 * driver unload, or wake on lan is not enabled, restore the link to previous
2729 void e1000_power_down_phy_copper(struct e1000_hw *hw)
2734 /* The PHY will retain its settings across a power down/up cycle */
2735 ret = e1e_rphy(hw, MII_BMCR, &mii_reg);
2737 e_dbg("Error reading PHY register\n");
2740 mii_reg |= BMCR_PDOWN;
2741 e1e_wphy(hw, MII_BMCR, mii_reg);
2742 usleep_range(1000, 2000);
2746 * __e1000_read_phy_reg_hv - Read HV PHY register
2747 * @hw: pointer to the HW structure
2748 * @offset: register offset to be read
2749 * @data: pointer to the read data
2750 * @locked: semaphore has already been acquired or not
2751 * @page_set: BM_WUC_PAGE already set and access enabled
2753 * Acquires semaphore, if necessary, then reads the PHY register at offset
2754 * and stores the retrieved information in data. Release any acquired
2755 * semaphore before exiting.
2757 static s32 __e1000_read_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 *data,
2758 bool locked, bool page_set)
2761 u16 page = BM_PHY_REG_PAGE(offset);
2762 u16 reg = BM_PHY_REG_NUM(offset);
2763 u32 phy_addr = hw->phy.addr = e1000_get_phy_addr_for_hv_page(page);
2766 ret_val = hw->phy.ops.acquire(hw);
2771 /* Page 800 works differently than the rest so it has its own func */
2772 if (page == BM_WUC_PAGE) {
2773 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, data,
2778 if (page > 0 && page < HV_INTC_FC_PAGE_START) {
2779 ret_val = e1000_access_phy_debug_regs_hv(hw, offset,
2785 if (page == HV_INTC_FC_PAGE_START)
2788 if (reg > MAX_PHY_MULTI_PAGE_REG) {
2789 /* Page is shifted left, PHY expects (page x 32) */
2790 ret_val = e1000_set_page_igp(hw,
2791 (page << IGP_PAGE_SHIFT));
2793 hw->phy.addr = phy_addr;
2800 e_dbg("reading PHY page %d (or 0x%x shifted) reg 0x%x\n", page,
2801 page << IGP_PAGE_SHIFT, reg);
2803 ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & reg, data);
2806 hw->phy.ops.release(hw);
2812 * e1000_read_phy_reg_hv - Read HV PHY register
2813 * @hw: pointer to the HW structure
2814 * @offset: register offset to be read
2815 * @data: pointer to the read data
2817 * Acquires semaphore then reads the PHY register at offset and stores
2818 * the retrieved information in data. Release the acquired semaphore
2821 s32 e1000_read_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 *data)
2823 return __e1000_read_phy_reg_hv(hw, offset, data, false, false);
2827 * e1000_read_phy_reg_hv_locked - Read HV PHY register
2828 * @hw: pointer to the HW structure
2829 * @offset: register offset to be read
2830 * @data: pointer to the read data
2832 * Reads the PHY register at offset and stores the retrieved information
2833 * in data. Assumes semaphore already acquired.
2835 s32 e1000_read_phy_reg_hv_locked(struct e1000_hw *hw, u32 offset, u16 *data)
2837 return __e1000_read_phy_reg_hv(hw, offset, data, true, false);
2841 * e1000_read_phy_reg_page_hv - Read HV PHY register
2842 * @hw: pointer to the HW structure
2843 * @offset: register offset to write to
2844 * @data: data to write at register offset
2846 * Reads the PHY register at offset and stores the retrieved information
2847 * in data. Assumes semaphore already acquired and page already set.
2849 s32 e1000_read_phy_reg_page_hv(struct e1000_hw *hw, u32 offset, u16 *data)
2851 return __e1000_read_phy_reg_hv(hw, offset, data, true, true);
2855 * __e1000_write_phy_reg_hv - Write HV PHY register
2856 * @hw: pointer to the HW structure
2857 * @offset: register offset to write to
2858 * @data: data to write at register offset
2859 * @locked: semaphore has already been acquired or not
2860 * @page_set: BM_WUC_PAGE already set and access enabled
2862 * Acquires semaphore, if necessary, then writes the data to PHY register
2863 * at the offset. Release any acquired semaphores before exiting.
2865 static s32 __e1000_write_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 data,
2866 bool locked, bool page_set)
2869 u16 page = BM_PHY_REG_PAGE(offset);
2870 u16 reg = BM_PHY_REG_NUM(offset);
2871 u32 phy_addr = hw->phy.addr = e1000_get_phy_addr_for_hv_page(page);
2874 ret_val = hw->phy.ops.acquire(hw);
2879 /* Page 800 works differently than the rest so it has its own func */
2880 if (page == BM_WUC_PAGE) {
2881 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, &data,
2886 if (page > 0 && page < HV_INTC_FC_PAGE_START) {
2887 ret_val = e1000_access_phy_debug_regs_hv(hw, offset,
2893 if (page == HV_INTC_FC_PAGE_START)
2896 /* Workaround MDIO accesses being disabled after entering IEEE
2897 * Power Down (when bit 11 of the PHY Control register is set)
2899 if ((hw->phy.type == e1000_phy_82578) &&
2900 (hw->phy.revision >= 1) &&
2901 (hw->phy.addr == 2) &&
2902 !(MAX_PHY_REG_ADDRESS & reg) && (data & BIT(11))) {
2905 ret_val = e1000_access_phy_debug_regs_hv(hw,
2912 if (reg > MAX_PHY_MULTI_PAGE_REG) {
2913 /* Page is shifted left, PHY expects (page x 32) */
2914 ret_val = e1000_set_page_igp(hw,
2915 (page << IGP_PAGE_SHIFT));
2917 hw->phy.addr = phy_addr;
2924 e_dbg("writing PHY page %d (or 0x%x shifted) reg 0x%x\n", page,
2925 page << IGP_PAGE_SHIFT, reg);
2927 ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & reg,
2932 hw->phy.ops.release(hw);
2938 * e1000_write_phy_reg_hv - Write HV PHY register
2939 * @hw: pointer to the HW structure
2940 * @offset: register offset to write to
2941 * @data: data to write at register offset
2943 * Acquires semaphore then writes the data to PHY register at the offset.
2944 * Release the acquired semaphores before exiting.
2946 s32 e1000_write_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 data)
2948 return __e1000_write_phy_reg_hv(hw, offset, data, false, false);
2952 * e1000_write_phy_reg_hv_locked - Write HV PHY register
2953 * @hw: pointer to the HW structure
2954 * @offset: register offset to write to
2955 * @data: data to write at register offset
2957 * Writes the data to PHY register at the offset. Assumes semaphore
2960 s32 e1000_write_phy_reg_hv_locked(struct e1000_hw *hw, u32 offset, u16 data)
2962 return __e1000_write_phy_reg_hv(hw, offset, data, true, false);
2966 * e1000_write_phy_reg_page_hv - Write HV PHY register
2967 * @hw: pointer to the HW structure
2968 * @offset: register offset to write to
2969 * @data: data to write at register offset
2971 * Writes the data to PHY register at the offset. Assumes semaphore
2972 * already acquired and page already set.
2974 s32 e1000_write_phy_reg_page_hv(struct e1000_hw *hw, u32 offset, u16 data)
2976 return __e1000_write_phy_reg_hv(hw, offset, data, true, true);
2980 * e1000_get_phy_addr_for_hv_page - Get PHY address based on page
2981 * @page: page to be accessed
2983 static u32 e1000_get_phy_addr_for_hv_page(u32 page)
2987 if (page >= HV_INTC_FC_PAGE_START)
2994 * e1000_access_phy_debug_regs_hv - Read HV PHY vendor specific high registers
2995 * @hw: pointer to the HW structure
2996 * @offset: register offset to be read or written
2997 * @data: pointer to the data to be read or written
2998 * @read: determines if operation is read or write
3000 * Reads the PHY register at offset and stores the retrieved information
3001 * in data. Assumes semaphore already acquired. Note that the procedure
3002 * to access these regs uses the address port and data port to read/write.
3003 * These accesses done with PHY address 2 and without using pages.
3005 static s32 e1000_access_phy_debug_regs_hv(struct e1000_hw *hw, u32 offset,
3006 u16 *data, bool read)
3012 /* This takes care of the difference with desktop vs mobile phy */
3013 addr_reg = ((hw->phy.type == e1000_phy_82578) ?
3014 I82578_ADDR_REG : I82577_ADDR_REG);
3015 data_reg = addr_reg + 1;
3017 /* All operations in this function are phy address 2 */
3020 /* masking with 0x3F to remove the page from offset */
3021 ret_val = e1000e_write_phy_reg_mdic(hw, addr_reg, (u16)offset & 0x3F);
3023 e_dbg("Could not write the Address Offset port register\n");
3027 /* Read or write the data value next */
3029 ret_val = e1000e_read_phy_reg_mdic(hw, data_reg, data);
3031 ret_val = e1000e_write_phy_reg_mdic(hw, data_reg, *data);
3034 e_dbg("Could not access the Data port register\n");
3040 * e1000_link_stall_workaround_hv - Si workaround
3041 * @hw: pointer to the HW structure
3043 * This function works around a Si bug where the link partner can get
3044 * a link up indication before the PHY does. If small packets are sent
3045 * by the link partner they can be placed in the packet buffer without
3046 * being properly accounted for by the PHY and will stall preventing
3047 * further packets from being received. The workaround is to clear the
3048 * packet buffer after the PHY detects link up.
3050 s32 e1000_link_stall_workaround_hv(struct e1000_hw *hw)
3055 if (hw->phy.type != e1000_phy_82578)
3058 /* Do not apply workaround if in PHY loopback bit 14 set */
3059 ret_val = e1e_rphy(hw, MII_BMCR, &data);
3061 e_dbg("Error reading PHY register\n");
3064 if (data & BMCR_LOOPBACK)
3067 /* check if link is up and at 1Gbps */
3068 ret_val = e1e_rphy(hw, BM_CS_STATUS, &data);
3072 data &= (BM_CS_STATUS_LINK_UP | BM_CS_STATUS_RESOLVED |
3073 BM_CS_STATUS_SPEED_MASK);
3075 if (data != (BM_CS_STATUS_LINK_UP | BM_CS_STATUS_RESOLVED |
3076 BM_CS_STATUS_SPEED_1000))
3081 /* flush the packets in the fifo buffer */
3082 ret_val = e1e_wphy(hw, HV_MUX_DATA_CTRL,
3083 (HV_MUX_DATA_CTRL_GEN_TO_MAC |
3084 HV_MUX_DATA_CTRL_FORCE_SPEED));
3088 return e1e_wphy(hw, HV_MUX_DATA_CTRL, HV_MUX_DATA_CTRL_GEN_TO_MAC);
3092 * e1000_check_polarity_82577 - Checks the polarity.
3093 * @hw: pointer to the HW structure
3095 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
3097 * Polarity is determined based on the PHY specific status register.
3099 s32 e1000_check_polarity_82577(struct e1000_hw *hw)
3101 struct e1000_phy_info *phy = &hw->phy;
3105 ret_val = e1e_rphy(hw, I82577_PHY_STATUS_2, &data);
3108 phy->cable_polarity = ((data & I82577_PHY_STATUS2_REV_POLARITY)
3109 ? e1000_rev_polarity_reversed
3110 : e1000_rev_polarity_normal);
3116 * e1000_phy_force_speed_duplex_82577 - Force speed/duplex for I82577 PHY
3117 * @hw: pointer to the HW structure
3119 * Calls the PHY setup function to force speed and duplex.
3121 s32 e1000_phy_force_speed_duplex_82577(struct e1000_hw *hw)
3123 struct e1000_phy_info *phy = &hw->phy;
3128 ret_val = e1e_rphy(hw, MII_BMCR, &phy_data);
3132 e1000e_phy_force_speed_duplex_setup(hw, &phy_data);
3134 ret_val = e1e_wphy(hw, MII_BMCR, phy_data);
3140 if (phy->autoneg_wait_to_complete) {
3141 e_dbg("Waiting for forced speed/duplex link on 82577 phy\n");
3143 ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
3149 e_dbg("Link taking longer than expected.\n");
3152 ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
3160 * e1000_get_phy_info_82577 - Retrieve I82577 PHY information
3161 * @hw: pointer to the HW structure
3163 * Read PHY status to determine if link is up. If link is up, then
3164 * set/determine 10base-T extended distance and polarity correction. Read
3165 * PHY port status to determine MDI/MDIx and speed. Based on the speed,
3166 * determine on the cable length, local and remote receiver.
3168 s32 e1000_get_phy_info_82577(struct e1000_hw *hw)
3170 struct e1000_phy_info *phy = &hw->phy;
3175 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
3180 e_dbg("Phy info is only valid if link is up\n");
3181 return -E1000_ERR_CONFIG;
3184 phy->polarity_correction = true;
3186 ret_val = e1000_check_polarity_82577(hw);
3190 ret_val = e1e_rphy(hw, I82577_PHY_STATUS_2, &data);
3194 phy->is_mdix = !!(data & I82577_PHY_STATUS2_MDIX);
3196 if ((data & I82577_PHY_STATUS2_SPEED_MASK) ==
3197 I82577_PHY_STATUS2_SPEED_1000MBPS) {
3198 ret_val = hw->phy.ops.get_cable_length(hw);
3202 ret_val = e1e_rphy(hw, MII_STAT1000, &data);
3206 phy->local_rx = (data & LPA_1000LOCALRXOK)
3207 ? e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
3209 phy->remote_rx = (data & LPA_1000REMRXOK)
3210 ? e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
3212 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
3213 phy->local_rx = e1000_1000t_rx_status_undefined;
3214 phy->remote_rx = e1000_1000t_rx_status_undefined;
3221 * e1000_get_cable_length_82577 - Determine cable length for 82577 PHY
3222 * @hw: pointer to the HW structure
3224 * Reads the diagnostic status register and verifies result is valid before
3225 * placing it in the phy_cable_length field.
3227 s32 e1000_get_cable_length_82577(struct e1000_hw *hw)
3229 struct e1000_phy_info *phy = &hw->phy;
3231 u16 phy_data, length;
3233 ret_val = e1e_rphy(hw, I82577_PHY_DIAG_STATUS, &phy_data);
3237 length = ((phy_data & I82577_DSTATUS_CABLE_LENGTH) >>
3238 I82577_DSTATUS_CABLE_LENGTH_SHIFT);
3240 if (length == E1000_CABLE_LENGTH_UNDEFINED)
3241 return -E1000_ERR_PHY;
3243 phy->cable_length = length;