Fixed binary search: no more infinite loops when vendor is unknown.
[tangerine.git] / workbench / devs / networks / e1000 / e1000_phy.c
blob27c4648185e043c0d66aeebbd51960efdf29df50
1 /*******************************************************************************
3 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 2008 Intel Corporation.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
22 Contact Information:
23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *******************************************************************************/
29 #include "e1000_api.h"
30 #include "e1000_phy.h"
32 /* Cable length tables */
33 static const u16 e1000_m88_cable_length_table[] =
34 { 0, 50, 80, 110, 140, 140, E1000_CABLE_LENGTH_UNDEFINED };
35 #define M88E1000_CABLE_LENGTH_TABLE_SIZE \
36 (sizeof(e1000_m88_cable_length_table) / \
37 sizeof(e1000_m88_cable_length_table[0]))
39 static const u16 e1000_igp_2_cable_length_table[] =
40 { 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21,
41 0, 0, 0, 3, 6, 10, 13, 16, 19, 23, 26, 29, 32, 35, 38, 41,
42 6, 10, 14, 18, 22, 26, 30, 33, 37, 41, 44, 48, 51, 54, 58, 61,
43 21, 26, 31, 35, 40, 44, 49, 53, 57, 61, 65, 68, 72, 75, 79, 82,
44 40, 45, 51, 56, 61, 66, 70, 75, 79, 83, 87, 91, 94, 98, 101, 104,
45 60, 66, 72, 77, 82, 87, 92, 96, 100, 104, 108, 111, 114, 117, 119, 121,
46 83, 89, 95, 100, 105, 109, 113, 116, 119, 122, 124,
47 104, 109, 114, 118, 121, 124};
48 #define IGP02E1000_CABLE_LENGTH_TABLE_SIZE \
49 (sizeof(e1000_igp_2_cable_length_table) / \
50 sizeof(e1000_igp_2_cable_length_table[0]))
52 /**
53 * e1000_init_phy_ops_generic - Initialize PHY function pointers
54 * @hw: pointer to the HW structure
56 * Setups up the function pointers to no-op functions
57 **/
58 void e1000_init_phy_ops_generic(struct e1000_hw *hw)
60 struct e1000_phy_info *phy = &hw->phy;
61 DEBUGFUNC("e1000_init_phy_ops_generic");
63 /* Initialize function pointers */
64 phy->ops.init_params = e1000_null_ops_generic;
65 phy->ops.acquire = e1000_null_ops_generic;
66 phy->ops.check_polarity = e1000_null_ops_generic;
67 phy->ops.check_reset_block = e1000_null_ops_generic;
68 phy->ops.commit = e1000_null_ops_generic;
69 phy->ops.force_speed_duplex = e1000_null_ops_generic;
70 phy->ops.get_cfg_done = e1000_null_ops_generic;
71 phy->ops.get_cable_length = e1000_null_ops_generic;
72 phy->ops.get_info = e1000_null_ops_generic;
73 phy->ops.read_reg = e1000_null_read_reg;
74 phy->ops.release = e1000_null_phy_generic;
75 phy->ops.reset = e1000_null_ops_generic;
76 phy->ops.set_d0_lplu_state = e1000_null_lplu_state;
77 phy->ops.set_d3_lplu_state = e1000_null_lplu_state;
78 phy->ops.write_reg = e1000_null_write_reg;
79 phy->ops.power_up = e1000_null_phy_generic;
80 phy->ops.power_down = e1000_null_phy_generic;
83 /**
84 * e1000_null_read_reg - No-op function, return 0
85 * @hw: pointer to the HW structure
86 **/
87 s32 e1000_null_read_reg(struct e1000_hw *hw, u32 offset, u16 *data)
89 DEBUGFUNC("e1000_null_read_reg");
90 return E1000_SUCCESS;
93 /**
94 * e1000_null_phy_generic - No-op function, return void
95 * @hw: pointer to the HW structure
96 **/
97 void e1000_null_phy_generic(struct e1000_hw *hw)
99 DEBUGFUNC("e1000_null_phy_generic");
100 return;
104 * e1000_null_lplu_state - No-op function, return 0
105 * @hw: pointer to the HW structure
107 s32 e1000_null_lplu_state(struct e1000_hw *hw, bool active)
109 DEBUGFUNC("e1000_null_lplu_state");
110 return E1000_SUCCESS;
114 * e1000_null_write_reg - No-op function, return 0
115 * @hw: pointer to the HW structure
117 s32 e1000_null_write_reg(struct e1000_hw *hw, u32 offset, u16 data)
119 DEBUGFUNC("e1000_null_write_reg");
120 return E1000_SUCCESS;
124 * e1000_check_reset_block_generic - Check if PHY reset is blocked
125 * @hw: pointer to the HW structure
127 * Read the PHY management control register and check whether a PHY reset
128 * is blocked. If a reset is not blocked return E1000_SUCCESS, otherwise
129 * return E1000_BLK_PHY_RESET (12).
131 s32 e1000_check_reset_block_generic(struct e1000_hw *hw)
133 u32 manc;
135 DEBUGFUNC("e1000_check_reset_block");
137 manc = E1000_READ_REG(hw, E1000_MANC);
139 return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
140 E1000_BLK_PHY_RESET : E1000_SUCCESS;
144 * e1000_get_phy_id - Retrieve the PHY ID and revision
145 * @hw: pointer to the HW structure
147 * Reads the PHY registers and stores the PHY ID and possibly the PHY
148 * revision in the hardware structure.
150 s32 e1000_get_phy_id(struct e1000_hw *hw)
152 struct e1000_phy_info *phy = &hw->phy;
153 s32 ret_val = E1000_SUCCESS;
154 u16 phy_id;
156 DEBUGFUNC("e1000_get_phy_id");
158 if (!(phy->ops.read_reg))
159 goto out;
161 ret_val = phy->ops.read_reg(hw, PHY_ID1, &phy_id);
162 if (ret_val)
163 goto out;
165 phy->id = (u32)(phy_id << 16);
166 usec_delay(20);
167 ret_val = phy->ops.read_reg(hw, PHY_ID2, &phy_id);
168 if (ret_val)
169 goto out;
171 phy->id |= (u32)(phy_id & PHY_REVISION_MASK);
172 phy->revision = (u32)(phy_id & ~PHY_REVISION_MASK);
174 out:
175 return ret_val;
179 * e1000_phy_reset_dsp_generic - Reset PHY DSP
180 * @hw: pointer to the HW structure
182 * Reset the digital signal processor.
184 s32 e1000_phy_reset_dsp_generic(struct e1000_hw *hw)
186 s32 ret_val = E1000_SUCCESS;
188 DEBUGFUNC("e1000_phy_reset_dsp_generic");
190 if (!(hw->phy.ops.write_reg))
191 goto out;
193 ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xC1);
194 if (ret_val)
195 goto out;
197 ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_GEN_CONTROL, 0);
199 out:
200 return ret_val;
204 * e1000_read_phy_reg_mdic - Read MDI control register
205 * @hw: pointer to the HW structure
206 * @offset: register offset to be read
207 * @data: pointer to the read data
209 * Reads the MDI control register in the PHY at offset and stores the
210 * information read to data.
212 s32 e1000_read_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 *data)
214 struct e1000_phy_info *phy = &hw->phy;
215 u32 i, mdic = 0;
216 s32 ret_val = E1000_SUCCESS;
218 DEBUGFUNC("e1000_read_phy_reg_mdic");
220 if (offset > MAX_PHY_REG_ADDRESS) {
221 DEBUGOUT1("PHY Address %d is out of range\n", offset);
222 ret_val = -E1000_ERR_PARAM;
223 goto out;
227 * Set up Op-code, Phy Address, and register offset in the MDI
228 * Control register. The MAC will take care of interfacing with the
229 * PHY to retrieve the desired data.
231 mdic = ((offset << E1000_MDIC_REG_SHIFT) |
232 (phy->addr << E1000_MDIC_PHY_SHIFT) |
233 (E1000_MDIC_OP_READ));
235 E1000_WRITE_REG(hw, E1000_MDIC, mdic);
238 * Poll the ready bit to see if the MDI read completed
239 * Increasing the time out as testing showed failures with
240 * the lower time out
242 for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
243 usec_delay(50);
244 mdic = E1000_READ_REG(hw, E1000_MDIC);
245 if (mdic & E1000_MDIC_READY)
246 break;
248 if (!(mdic & E1000_MDIC_READY)) {
249 DEBUGOUT("MDI Read did not complete\n");
250 ret_val = -E1000_ERR_PHY;
251 goto out;
253 if (mdic & E1000_MDIC_ERROR) {
254 DEBUGOUT("MDI Error\n");
255 ret_val = -E1000_ERR_PHY;
256 goto out;
258 *data = (u16) mdic;
260 out:
261 return ret_val;
265 * e1000_write_phy_reg_mdic - Write MDI control register
266 * @hw: pointer to the HW structure
267 * @offset: register offset to write to
268 * @data: data to write to register at offset
270 * Writes data to MDI control register in the PHY at offset.
272 s32 e1000_write_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 data)
274 struct e1000_phy_info *phy = &hw->phy;
275 u32 i, mdic = 0;
276 s32 ret_val = E1000_SUCCESS;
278 DEBUGFUNC("e1000_write_phy_reg_mdic");
280 if (offset > MAX_PHY_REG_ADDRESS) {
281 DEBUGOUT1("PHY Address %d is out of range\n", offset);
282 ret_val = -E1000_ERR_PARAM;
283 goto out;
287 * Set up Op-code, Phy Address, and register offset in the MDI
288 * Control register. The MAC will take care of interfacing with the
289 * PHY to retrieve the desired data.
291 mdic = (((u32)data) |
292 (offset << E1000_MDIC_REG_SHIFT) |
293 (phy->addr << E1000_MDIC_PHY_SHIFT) |
294 (E1000_MDIC_OP_WRITE));
296 E1000_WRITE_REG(hw, E1000_MDIC, mdic);
299 * Poll the ready bit to see if the MDI read completed
300 * Increasing the time out as testing showed failures with
301 * the lower time out
303 for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
304 usec_delay(50);
305 mdic = E1000_READ_REG(hw, E1000_MDIC);
306 if (mdic & E1000_MDIC_READY)
307 break;
309 if (!(mdic & E1000_MDIC_READY)) {
310 DEBUGOUT("MDI Write did not complete\n");
311 ret_val = -E1000_ERR_PHY;
312 goto out;
314 if (mdic & E1000_MDIC_ERROR) {
315 DEBUGOUT("MDI Error\n");
316 ret_val = -E1000_ERR_PHY;
317 goto out;
320 out:
321 return ret_val;
325 * e1000_read_phy_reg_m88 - Read m88 PHY register
326 * @hw: pointer to the HW structure
327 * @offset: register offset to be read
328 * @data: pointer to the read data
330 * Acquires semaphore, if necessary, then reads the PHY register at offset
331 * and storing the retrieved information in data. Release any acquired
332 * semaphores before exiting.
334 s32 e1000_read_phy_reg_m88(struct e1000_hw *hw, u32 offset, u16 *data)
336 s32 ret_val = E1000_SUCCESS;
338 DEBUGFUNC("e1000_read_phy_reg_m88");
340 if (!(hw->phy.ops.acquire))
341 goto out;
343 ret_val = hw->phy.ops.acquire(hw);
344 if (ret_val)
345 goto out;
347 ret_val = e1000_read_phy_reg_mdic(hw,
348 MAX_PHY_REG_ADDRESS & offset,
349 data);
351 hw->phy.ops.release(hw);
353 out:
354 return ret_val;
358 * e1000_write_phy_reg_m88 - Write m88 PHY register
359 * @hw: pointer to the HW structure
360 * @offset: register offset to write to
361 * @data: data to write at register offset
363 * Acquires semaphore, if necessary, then writes the data to PHY register
364 * at the offset. Release any acquired semaphores before exiting.
366 s32 e1000_write_phy_reg_m88(struct e1000_hw *hw, u32 offset, u16 data)
368 s32 ret_val = E1000_SUCCESS;
370 DEBUGFUNC("e1000_write_phy_reg_m88");
372 if (!(hw->phy.ops.acquire))
373 goto out;
375 ret_val = hw->phy.ops.acquire(hw);
376 if (ret_val)
377 goto out;
379 ret_val = e1000_write_phy_reg_mdic(hw,
380 MAX_PHY_REG_ADDRESS & offset,
381 data);
383 hw->phy.ops.release(hw);
385 out:
386 return ret_val;
390 * e1000_read_phy_reg_igp - Read igp PHY register
391 * @hw: pointer to the HW structure
392 * @offset: register offset to be read
393 * @data: pointer to the read data
395 * Acquires semaphore, if necessary, then reads the PHY register at offset
396 * and storing the retrieved information in data. Release any acquired
397 * semaphores before exiting.
399 s32 e1000_read_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 *data)
401 s32 ret_val = E1000_SUCCESS;
403 DEBUGFUNC("e1000_read_phy_reg_igp");
405 if (!(hw->phy.ops.acquire))
406 goto out;
408 ret_val = hw->phy.ops.acquire(hw);
409 if (ret_val)
410 goto out;
412 if (offset > MAX_PHY_MULTI_PAGE_REG) {
413 ret_val = e1000_write_phy_reg_mdic(hw,
414 IGP01E1000_PHY_PAGE_SELECT,
415 (u16)offset);
416 if (ret_val) {
417 hw->phy.ops.release(hw);
418 goto out;
422 ret_val = e1000_read_phy_reg_mdic(hw,
423 MAX_PHY_REG_ADDRESS & offset,
424 data);
426 hw->phy.ops.release(hw);
428 out:
429 return ret_val;
433 * e1000_write_phy_reg_igp - Write igp PHY register
434 * @hw: pointer to the HW structure
435 * @offset: register offset to write to
436 * @data: data to write at register offset
438 * Acquires semaphore, if necessary, then writes the data to PHY register
439 * at the offset. Release any acquired semaphores before exiting.
441 s32 e1000_write_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 data)
443 s32 ret_val = E1000_SUCCESS;
445 DEBUGFUNC("e1000_write_phy_reg_igp");
447 if (!(hw->phy.ops.acquire))
448 goto out;
450 ret_val = hw->phy.ops.acquire(hw);
451 if (ret_val)
452 goto out;
454 if (offset > MAX_PHY_MULTI_PAGE_REG) {
455 ret_val = e1000_write_phy_reg_mdic(hw,
456 IGP01E1000_PHY_PAGE_SELECT,
457 (u16)offset);
458 if (ret_val) {
459 hw->phy.ops.release(hw);
460 goto out;
464 ret_val = e1000_write_phy_reg_mdic(hw,
465 MAX_PHY_REG_ADDRESS & offset,
466 data);
468 hw->phy.ops.release(hw);
470 out:
471 return ret_val;
475 * e1000_read_kmrn_reg_generic - Read kumeran register
476 * @hw: pointer to the HW structure
477 * @offset: register offset to be read
478 * @data: pointer to the read data
480 * Acquires semaphore, if necessary. Then reads the PHY register at offset
481 * using the kumeran interface. The information retrieved is stored in data.
482 * Release any acquired semaphores before exiting.
484 s32 e1000_read_kmrn_reg_generic(struct e1000_hw *hw, u32 offset, u16 *data)
486 u32 kmrnctrlsta;
487 s32 ret_val = E1000_SUCCESS;
489 DEBUGFUNC("e1000_read_kmrn_reg_generic");
491 if (!(hw->phy.ops.acquire))
492 goto out;
494 ret_val = hw->phy.ops.acquire(hw);
495 if (ret_val)
496 goto out;
498 kmrnctrlsta = ((offset << E1000_KMRNCTRLSTA_OFFSET_SHIFT) &
499 E1000_KMRNCTRLSTA_OFFSET) | E1000_KMRNCTRLSTA_REN;
500 E1000_WRITE_REG(hw, E1000_KMRNCTRLSTA, kmrnctrlsta);
502 usec_delay(2);
504 kmrnctrlsta = E1000_READ_REG(hw, E1000_KMRNCTRLSTA);
505 *data = (u16)kmrnctrlsta;
507 hw->phy.ops.release(hw);
509 out:
510 return ret_val;
514 * e1000_write_kmrn_reg_generic - Write kumeran register
515 * @hw: pointer to the HW structure
516 * @offset: register offset to write to
517 * @data: data to write at register offset
519 * Acquires semaphore, if necessary. Then write the data to PHY register
520 * at the offset using the kumeran interface. Release any acquired semaphores
521 * before exiting.
523 s32 e1000_write_kmrn_reg_generic(struct e1000_hw *hw, u32 offset, u16 data)
525 u32 kmrnctrlsta;
526 s32 ret_val = E1000_SUCCESS;
528 DEBUGFUNC("e1000_write_kmrn_reg_generic");
530 if (!(hw->phy.ops.acquire))
531 goto out;
533 ret_val = hw->phy.ops.acquire(hw);
534 if (ret_val)
535 goto out;
537 kmrnctrlsta = ((offset << E1000_KMRNCTRLSTA_OFFSET_SHIFT) &
538 E1000_KMRNCTRLSTA_OFFSET) | data;
539 E1000_WRITE_REG(hw, E1000_KMRNCTRLSTA, kmrnctrlsta);
541 usec_delay(2);
542 hw->phy.ops.release(hw);
544 out:
545 return ret_val;
549 * e1000_copper_link_setup_m88 - Setup m88 PHY's for copper link
550 * @hw: pointer to the HW structure
552 * Sets up MDI/MDI-X and polarity for m88 PHY's. If necessary, transmit clock
553 * and downshift values are set also.
555 s32 e1000_copper_link_setup_m88(struct e1000_hw *hw)
557 struct e1000_phy_info *phy = &hw->phy;
558 s32 ret_val;
559 u16 phy_data;
561 DEBUGFUNC("e1000_copper_link_setup_m88");
563 if (phy->reset_disable) {
564 ret_val = E1000_SUCCESS;
565 goto out;
568 /* Enable CRS on TX. This must be set for half-duplex operation. */
569 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
570 if (ret_val)
571 goto out;
573 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
576 * Options:
577 * MDI/MDI-X = 0 (default)
578 * 0 - Auto for all speeds
579 * 1 - MDI mode
580 * 2 - MDI-X mode
581 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
583 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
585 switch (phy->mdix) {
586 case 1:
587 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
588 break;
589 case 2:
590 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
591 break;
592 case 3:
593 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
594 break;
595 case 0:
596 default:
597 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
598 break;
602 * Options:
603 * disable_polarity_correction = 0 (default)
604 * Automatic Correction for Reversed Cable Polarity
605 * 0 - Disabled
606 * 1 - Enabled
608 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
609 if (phy->disable_polarity_correction == 1)
610 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
612 ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
613 if (ret_val)
614 goto out;
616 if (phy->revision < E1000_REVISION_4) {
618 * Force TX_CLK in the Extended PHY Specific Control Register
619 * to 25MHz clock.
621 ret_val = phy->ops.read_reg(hw,
622 M88E1000_EXT_PHY_SPEC_CTRL,
623 &phy_data);
624 if (ret_val)
625 goto out;
627 phy_data |= M88E1000_EPSCR_TX_CLK_25;
629 if ((phy->revision == E1000_REVISION_2) &&
630 (phy->id == M88E1111_I_PHY_ID)) {
631 /* 82573L PHY - set the downshift counter to 5x. */
632 phy_data &= ~M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK;
633 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
634 } else {
635 /* Configure Master and Slave downshift values */
636 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
637 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
638 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
639 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
641 ret_val = phy->ops.write_reg(hw,
642 M88E1000_EXT_PHY_SPEC_CTRL,
643 phy_data);
644 if (ret_val)
645 goto out;
648 /* Commit the changes. */
649 ret_val = phy->ops.commit(hw);
650 if (ret_val) {
651 DEBUGOUT("Error committing the PHY changes\n");
652 goto out;
655 out:
656 return ret_val;
660 * e1000_copper_link_setup_igp - Setup igp PHY's for copper link
661 * @hw: pointer to the HW structure
663 * Sets up LPLU, MDI/MDI-X, polarity, Smartspeed and Master/Slave config for
664 * igp PHY's.
666 s32 e1000_copper_link_setup_igp(struct e1000_hw *hw)
668 struct e1000_phy_info *phy = &hw->phy;
669 s32 ret_val;
670 u16 data;
672 DEBUGFUNC("e1000_copper_link_setup_igp");
674 if (phy->reset_disable) {
675 ret_val = E1000_SUCCESS;
676 goto out;
679 ret_val = e1000_phy_hw_reset(hw);
680 if (ret_val) {
681 DEBUGOUT("Error resetting the PHY.\n");
682 goto out;
686 * Wait 100ms for MAC to configure PHY from NVM settings, to avoid
687 * timeout issues when LFS is enabled.
689 msec_delay(100);
692 * The NVM settings will configure LPLU in D3 for
693 * non-IGP1 PHYs.
695 if (phy->type == e1000_phy_igp) {
696 /* disable lplu d3 during driver init */
697 ret_val = e1000_set_d3_lplu_state(hw, FALSE);
698 if (ret_val) {
699 DEBUGOUT("Error Disabling LPLU D3\n");
700 goto out;
704 /* disable lplu d0 during driver init */
705 ret_val = e1000_set_d0_lplu_state(hw, FALSE);
706 if (ret_val) {
707 DEBUGOUT("Error Disabling LPLU D0\n");
708 goto out;
710 /* Configure mdi-mdix settings */
711 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CTRL, &data);
712 if (ret_val)
713 goto out;
715 data &= ~IGP01E1000_PSCR_AUTO_MDIX;
717 switch (phy->mdix) {
718 case 1:
719 data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
720 break;
721 case 2:
722 data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
723 break;
724 case 0:
725 default:
726 data |= IGP01E1000_PSCR_AUTO_MDIX;
727 break;
729 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CTRL, data);
730 if (ret_val)
731 goto out;
733 /* set auto-master slave resolution settings */
734 if (hw->mac.autoneg) {
736 * when autonegotiation advertisement is only 1000Mbps then we
737 * should disable SmartSpeed and enable Auto MasterSlave
738 * resolution as hardware default.
740 if (phy->autoneg_advertised == ADVERTISE_1000_FULL) {
741 /* Disable SmartSpeed */
742 ret_val = phy->ops.read_reg(hw,
743 IGP01E1000_PHY_PORT_CONFIG,
744 &data);
745 if (ret_val)
746 goto out;
748 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
749 ret_val = phy->ops.write_reg(hw,
750 IGP01E1000_PHY_PORT_CONFIG,
751 data);
752 if (ret_val)
753 goto out;
755 /* Set auto Master/Slave resolution process */
756 ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL, &data);
757 if (ret_val)
758 goto out;
760 data &= ~CR_1000T_MS_ENABLE;
761 ret_val = phy->ops.write_reg(hw, PHY_1000T_CTRL, data);
762 if (ret_val)
763 goto out;
766 ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL, &data);
767 if (ret_val)
768 goto out;
770 /* load defaults for future use */
771 phy->original_ms_type = (data & CR_1000T_MS_ENABLE) ?
772 ((data & CR_1000T_MS_VALUE) ?
773 e1000_ms_force_master :
774 e1000_ms_force_slave) :
775 e1000_ms_auto;
777 switch (phy->ms_type) {
778 case e1000_ms_force_master:
779 data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
780 break;
781 case e1000_ms_force_slave:
782 data |= CR_1000T_MS_ENABLE;
783 data &= ~(CR_1000T_MS_VALUE);
784 break;
785 case e1000_ms_auto:
786 data &= ~CR_1000T_MS_ENABLE;
787 default:
788 break;
790 ret_val = phy->ops.write_reg(hw, PHY_1000T_CTRL, data);
791 if (ret_val)
792 goto out;
795 out:
796 return ret_val;
800 * e1000_copper_link_autoneg - Setup/Enable autoneg for copper link
801 * @hw: pointer to the HW structure
803 * Performs initial bounds checking on autoneg advertisement parameter, then
804 * configure to advertise the full capability. Setup the PHY to autoneg
805 * and restart the negotiation process between the link partner. If
806 * autoneg_wait_to_complete, then wait for autoneg to complete before exiting.
808 s32 e1000_copper_link_autoneg(struct e1000_hw *hw)
810 struct e1000_phy_info *phy = &hw->phy;
811 s32 ret_val;
812 u16 phy_ctrl;
814 DEBUGFUNC("e1000_copper_link_autoneg");
817 * Perform some bounds checking on the autoneg advertisement
818 * parameter.
820 phy->autoneg_advertised &= phy->autoneg_mask;
823 * If autoneg_advertised is zero, we assume it was not defaulted
824 * by the calling code so we set to advertise full capability.
826 if (phy->autoneg_advertised == 0)
827 phy->autoneg_advertised = phy->autoneg_mask;
829 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
830 ret_val = e1000_phy_setup_autoneg(hw);
831 if (ret_val) {
832 DEBUGOUT("Error Setting up Auto-Negotiation\n");
833 goto out;
835 DEBUGOUT("Restarting Auto-Neg\n");
838 * Restart auto-negotiation by setting the Auto Neg Enable bit and
839 * the Auto Neg Restart bit in the PHY control register.
841 ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_ctrl);
842 if (ret_val)
843 goto out;
845 phy_ctrl |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
846 ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_ctrl);
847 if (ret_val)
848 goto out;
851 * Does the user want to wait for Auto-Neg to complete here, or
852 * check at a later time (for example, callback routine).
854 if (phy->autoneg_wait_to_complete) {
855 ret_val = e1000_wait_autoneg(hw);
856 if (ret_val) {
857 DEBUGOUT("Error while waiting for "
858 "autoneg to complete\n");
859 goto out;
863 hw->mac.get_link_status = TRUE;
865 out:
866 return ret_val;
870 * e1000_phy_setup_autoneg - Configure PHY for auto-negotiation
871 * @hw: pointer to the HW structure
873 * Reads the MII auto-neg advertisement register and/or the 1000T control
874 * register and if the PHY is already setup for auto-negotiation, then
875 * return successful. Otherwise, setup advertisement and flow control to
876 * the appropriate values for the wanted auto-negotiation.
878 s32 e1000_phy_setup_autoneg(struct e1000_hw *hw)
880 struct e1000_phy_info *phy = &hw->phy;
881 s32 ret_val;
882 u16 mii_autoneg_adv_reg;
883 u16 mii_1000t_ctrl_reg = 0;
885 DEBUGFUNC("e1000_phy_setup_autoneg");
887 phy->autoneg_advertised &= phy->autoneg_mask;
889 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
890 ret_val = phy->ops.read_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
891 if (ret_val)
892 goto out;
894 if (phy->autoneg_mask & ADVERTISE_1000_FULL) {
895 /* Read the MII 1000Base-T Control Register (Address 9). */
896 ret_val = phy->ops.read_reg(hw,
897 PHY_1000T_CTRL,
898 &mii_1000t_ctrl_reg);
899 if (ret_val)
900 goto out;
904 * Need to parse both autoneg_advertised and fc and set up
905 * the appropriate PHY registers. First we will parse for
906 * autoneg_advertised software override. Since we can advertise
907 * a plethora of combinations, we need to check each bit
908 * individually.
912 * First we clear all the 10/100 mb speed bits in the Auto-Neg
913 * Advertisement Register (Address 4) and the 1000 mb speed bits in
914 * the 1000Base-T Control Register (Address 9).
916 mii_autoneg_adv_reg &= ~(NWAY_AR_100TX_FD_CAPS |
917 NWAY_AR_100TX_HD_CAPS |
918 NWAY_AR_10T_FD_CAPS |
919 NWAY_AR_10T_HD_CAPS);
920 mii_1000t_ctrl_reg &= ~(CR_1000T_HD_CAPS | CR_1000T_FD_CAPS);
922 DEBUGOUT1("autoneg_advertised %x\n", phy->autoneg_advertised);
924 /* Do we want to advertise 10 Mb Half Duplex? */
925 if (phy->autoneg_advertised & ADVERTISE_10_HALF) {
926 DEBUGOUT("Advertise 10mb Half duplex\n");
927 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
930 /* Do we want to advertise 10 Mb Full Duplex? */
931 if (phy->autoneg_advertised & ADVERTISE_10_FULL) {
932 DEBUGOUT("Advertise 10mb Full duplex\n");
933 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
936 /* Do we want to advertise 100 Mb Half Duplex? */
937 if (phy->autoneg_advertised & ADVERTISE_100_HALF) {
938 DEBUGOUT("Advertise 100mb Half duplex\n");
939 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
942 /* Do we want to advertise 100 Mb Full Duplex? */
943 if (phy->autoneg_advertised & ADVERTISE_100_FULL) {
944 DEBUGOUT("Advertise 100mb Full duplex\n");
945 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
948 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
949 if (phy->autoneg_advertised & ADVERTISE_1000_HALF) {
950 DEBUGOUT("Advertise 1000mb Half duplex request denied!\n");
953 /* Do we want to advertise 1000 Mb Full Duplex? */
954 if (phy->autoneg_advertised & ADVERTISE_1000_FULL) {
955 DEBUGOUT("Advertise 1000mb Full duplex\n");
956 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
960 * Check for a software override of the flow control settings, and
961 * setup the PHY advertisement registers accordingly. If
962 * auto-negotiation is enabled, then software will have to set the
963 * "PAUSE" bits to the correct value in the Auto-Negotiation
964 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-
965 * negotiation.
967 * The possible values of the "fc" parameter are:
968 * 0: Flow control is completely disabled
969 * 1: Rx flow control is enabled (we can receive pause frames
970 * but not send pause frames).
971 * 2: Tx flow control is enabled (we can send pause frames
972 * but we do not support receiving pause frames).
973 * 3: Both Rx and Tx flow control (symmetric) are enabled.
974 * other: No software override. The flow control configuration
975 * in the EEPROM is used.
977 switch (hw->fc.type) {
978 case e1000_fc_none:
980 * Flow control (Rx & Tx) is completely disabled by a
981 * software over-ride.
983 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
984 break;
985 case e1000_fc_rx_pause:
987 * Rx Flow control is enabled, and Tx Flow control is
988 * disabled, by a software over-ride.
990 * Since there really isn't a way to advertise that we are
991 * capable of Rx Pause ONLY, we will advertise that we
992 * support both symmetric and asymmetric Rx PAUSE. Later
993 * (in e1000_config_fc_after_link_up) we will disable the
994 * hw's ability to send PAUSE frames.
996 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
997 break;
998 case e1000_fc_tx_pause:
1000 * Tx Flow control is enabled, and Rx Flow control is
1001 * disabled, by a software over-ride.
1003 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
1004 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
1005 break;
1006 case e1000_fc_full:
1008 * Flow control (both Rx and Tx) is enabled by a software
1009 * over-ride.
1011 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1012 break;
1013 default:
1014 DEBUGOUT("Flow control param set incorrectly\n");
1015 ret_val = -E1000_ERR_CONFIG;
1016 goto out;
1019 ret_val = phy->ops.write_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
1020 if (ret_val)
1021 goto out;
1023 DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
1025 if (phy->autoneg_mask & ADVERTISE_1000_FULL) {
1026 ret_val = phy->ops.write_reg(hw,
1027 PHY_1000T_CTRL,
1028 mii_1000t_ctrl_reg);
1029 if (ret_val)
1030 goto out;
1033 out:
1034 return ret_val;
1038 * e1000_setup_copper_link_generic - Configure copper link settings
1039 * @hw: pointer to the HW structure
1041 * Calls the appropriate function to configure the link for auto-neg or forced
1042 * speed and duplex. Then we check for link, once link is established calls
1043 * to configure collision distance and flow control are called. If link is
1044 * not established, we return -E1000_ERR_PHY (-2).
1046 s32 e1000_setup_copper_link_generic(struct e1000_hw *hw)
1048 s32 ret_val;
1049 bool link;
1051 DEBUGFUNC("e1000_setup_copper_link_generic");
1053 if (hw->mac.autoneg) {
1055 * Setup autoneg and flow control advertisement and perform
1056 * autonegotiation.
1058 ret_val = e1000_copper_link_autoneg(hw);
1059 if (ret_val)
1060 goto out;
1061 } else {
1063 * PHY will be set to 10H, 10F, 100H or 100F
1064 * depending on user settings.
1066 DEBUGOUT("Forcing Speed and Duplex\n");
1067 ret_val = hw->phy.ops.force_speed_duplex(hw);
1068 if (ret_val) {
1069 DEBUGOUT("Error Forcing Speed and Duplex\n");
1070 goto out;
1075 * Check link status. Wait up to 100 microseconds for link to become
1076 * valid.
1078 ret_val = e1000_phy_has_link_generic(hw,
1079 COPPER_LINK_UP_LIMIT,
1081 &link);
1082 if (ret_val)
1083 goto out;
1085 if (link) {
1086 DEBUGOUT("Valid link established!!!\n");
1087 e1000_config_collision_dist_generic(hw);
1088 ret_val = e1000_config_fc_after_link_up_generic(hw);
1089 } else {
1090 DEBUGOUT("Unable to establish link!!!\n");
1093 out:
1094 return ret_val;
1098 * e1000_phy_force_speed_duplex_igp - Force speed/duplex for igp PHY
1099 * @hw: pointer to the HW structure
1101 * Calls the PHY setup function to force speed and duplex. Clears the
1102 * auto-crossover to force MDI manually. Waits for link and returns
1103 * successful if link up is successful, else -E1000_ERR_PHY (-2).
1105 s32 e1000_phy_force_speed_duplex_igp(struct e1000_hw *hw)
1107 struct e1000_phy_info *phy = &hw->phy;
1108 s32 ret_val;
1109 u16 phy_data;
1110 bool link;
1112 DEBUGFUNC("e1000_phy_force_speed_duplex_igp");
1114 ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_data);
1115 if (ret_val)
1116 goto out;
1118 e1000_phy_force_speed_duplex_setup(hw, &phy_data);
1120 ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data);
1121 if (ret_val)
1122 goto out;
1125 * Clear Auto-Crossover to force MDI manually. IGP requires MDI
1126 * forced whenever speed and duplex are forced.
1128 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1129 if (ret_val)
1130 goto out;
1132 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1133 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1135 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1136 if (ret_val)
1137 goto out;
1139 DEBUGOUT1("IGP PSCR: %X\n", phy_data);
1141 usec_delay(1);
1143 if (phy->autoneg_wait_to_complete) {
1144 DEBUGOUT("Waiting for forced speed/duplex link on IGP phy.\n");
1146 ret_val = e1000_phy_has_link_generic(hw,
1147 PHY_FORCE_LIMIT,
1148 100000,
1149 &link);
1150 if (ret_val)
1151 goto out;
1153 if (!link) {
1154 DEBUGOUT("Link taking longer than expected.\n");
1157 /* Try once more */
1158 ret_val = e1000_phy_has_link_generic(hw,
1159 PHY_FORCE_LIMIT,
1160 100000,
1161 &link);
1162 if (ret_val)
1163 goto out;
1166 out:
1167 return ret_val;
1171 * e1000_phy_force_speed_duplex_m88 - Force speed/duplex for m88 PHY
1172 * @hw: pointer to the HW structure
1174 * Calls the PHY setup function to force speed and duplex. Clears the
1175 * auto-crossover to force MDI manually. Resets the PHY to commit the
1176 * changes. If time expires while waiting for link up, we reset the DSP.
1177 * After reset, TX_CLK and CRS on Tx must be set. Return successful upon
1178 * successful completion, else return corresponding error code.
1180 s32 e1000_phy_force_speed_duplex_m88(struct e1000_hw *hw)
1182 struct e1000_phy_info *phy = &hw->phy;
1183 s32 ret_val;
1184 u16 phy_data;
1185 bool link;
1187 DEBUGFUNC("e1000_phy_force_speed_duplex_m88");
1190 * Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
1191 * forced whenever speed and duplex are forced.
1193 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1194 if (ret_val)
1195 goto out;
1197 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1198 ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1199 if (ret_val)
1200 goto out;
1202 DEBUGOUT1("M88E1000 PSCR: %X\n", phy_data);
1204 ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_data);
1205 if (ret_val)
1206 goto out;
1208 e1000_phy_force_speed_duplex_setup(hw, &phy_data);
1210 /* Reset the phy to commit changes. */
1211 phy_data |= MII_CR_RESET;
1213 ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data);
1214 if (ret_val)
1215 goto out;
1217 usec_delay(1);
1219 if (phy->autoneg_wait_to_complete) {
1220 DEBUGOUT("Waiting for forced speed/duplex link on M88 phy.\n");
1222 ret_val = e1000_phy_has_link_generic(hw,
1223 PHY_FORCE_LIMIT,
1224 100000,
1225 &link);
1226 if (ret_val)
1227 goto out;
1229 if (!link) {
1231 * We didn't get link.
1232 * Reset the DSP and cross our fingers.
1234 ret_val = phy->ops.write_reg(hw,
1235 M88E1000_PHY_PAGE_SELECT,
1236 0x001d);
1237 if (ret_val)
1238 goto out;
1239 ret_val = e1000_phy_reset_dsp_generic(hw);
1240 if (ret_val)
1241 goto out;
1244 /* Try once more */
1245 ret_val = e1000_phy_has_link_generic(hw,
1246 PHY_FORCE_LIMIT,
1247 100000,
1248 &link);
1249 if (ret_val)
1250 goto out;
1253 ret_val = phy->ops.read_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1254 if (ret_val)
1255 goto out;
1258 * Resetting the phy means we need to re-force TX_CLK in the
1259 * Extended PHY Specific Control Register to 25MHz clock from
1260 * the reset value of 2.5MHz.
1262 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1263 ret_val = phy->ops.write_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1264 if (ret_val)
1265 goto out;
1268 * In addition, we must re-enable CRS on Tx for both half and full
1269 * duplex.
1271 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1272 if (ret_val)
1273 goto out;
1275 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1276 ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1278 out:
1279 return ret_val;
1283 * e1000_phy_force_speed_duplex_setup - Configure forced PHY speed/duplex
1284 * @hw: pointer to the HW structure
1285 * @phy_ctrl: pointer to current value of PHY_CONTROL
1287 * Forces speed and duplex on the PHY by doing the following: disable flow
1288 * control, force speed/duplex on the MAC, disable auto speed detection,
1289 * disable auto-negotiation, configure duplex, configure speed, configure
1290 * the collision distance, write configuration to CTRL register. The
1291 * caller must write to the PHY_CONTROL register for these settings to
1292 * take affect.
1294 void e1000_phy_force_speed_duplex_setup(struct e1000_hw *hw, u16 *phy_ctrl)
1296 struct e1000_mac_info *mac = &hw->mac;
1297 u32 ctrl;
1299 DEBUGFUNC("e1000_phy_force_speed_duplex_setup");
1301 /* Turn off flow control when forcing speed/duplex */
1302 hw->fc.type = e1000_fc_none;
1304 /* Force speed/duplex on the mac */
1305 ctrl = E1000_READ_REG(hw, E1000_CTRL);
1306 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1307 ctrl &= ~E1000_CTRL_SPD_SEL;
1309 /* Disable Auto Speed Detection */
1310 ctrl &= ~E1000_CTRL_ASDE;
1312 /* Disable autoneg on the phy */
1313 *phy_ctrl &= ~MII_CR_AUTO_NEG_EN;
1315 /* Forcing Full or Half Duplex? */
1316 if (mac->forced_speed_duplex & E1000_ALL_HALF_DUPLEX) {
1317 ctrl &= ~E1000_CTRL_FD;
1318 *phy_ctrl &= ~MII_CR_FULL_DUPLEX;
1319 DEBUGOUT("Half Duplex\n");
1320 } else {
1321 ctrl |= E1000_CTRL_FD;
1322 *phy_ctrl |= MII_CR_FULL_DUPLEX;
1323 DEBUGOUT("Full Duplex\n");
1326 /* Forcing 10mb or 100mb? */
1327 if (mac->forced_speed_duplex & E1000_ALL_100_SPEED) {
1328 ctrl |= E1000_CTRL_SPD_100;
1329 *phy_ctrl |= MII_CR_SPEED_100;
1330 *phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
1331 DEBUGOUT("Forcing 100mb\n");
1332 } else {
1333 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1334 *phy_ctrl |= MII_CR_SPEED_10;
1335 *phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
1336 DEBUGOUT("Forcing 10mb\n");
1339 e1000_config_collision_dist_generic(hw);
1341 E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
1345 * e1000_set_d3_lplu_state_generic - Sets low power link up state for D3
1346 * @hw: pointer to the HW structure
1347 * @active: boolean used to enable/disable lplu
1349 * Success returns 0, Failure returns 1
1351 * The low power link up (lplu) state is set to the power management level D3
1352 * and SmartSpeed is disabled when active is true, else clear lplu for D3
1353 * and enable Smartspeed. LPLU and Smartspeed are mutually exclusive. LPLU
1354 * is used during Dx states where the power conservation is most important.
1355 * During driver activity, SmartSpeed should be enabled so performance is
1356 * maintained.
1358 s32 e1000_set_d3_lplu_state_generic(struct e1000_hw *hw, bool active)
1360 struct e1000_phy_info *phy = &hw->phy;
1361 s32 ret_val = E1000_SUCCESS;
1362 u16 data;
1364 DEBUGFUNC("e1000_set_d3_lplu_state_generic");
1366 if (!(hw->phy.ops.read_reg))
1367 goto out;
1369 ret_val = phy->ops.read_reg(hw, IGP02E1000_PHY_POWER_MGMT, &data);
1370 if (ret_val)
1371 goto out;
1373 if (!active) {
1374 data &= ~IGP02E1000_PM_D3_LPLU;
1375 ret_val = phy->ops.write_reg(hw,
1376 IGP02E1000_PHY_POWER_MGMT,
1377 data);
1378 if (ret_val)
1379 goto out;
1381 * LPLU and SmartSpeed are mutually exclusive. LPLU is used
1382 * during Dx states where the power conservation is most
1383 * important. During driver activity we should enable
1384 * SmartSpeed, so performance is maintained.
1386 if (phy->smart_speed == e1000_smart_speed_on) {
1387 ret_val = phy->ops.read_reg(hw,
1388 IGP01E1000_PHY_PORT_CONFIG,
1389 &data);
1390 if (ret_val)
1391 goto out;
1393 data |= IGP01E1000_PSCFR_SMART_SPEED;
1394 ret_val = phy->ops.write_reg(hw,
1395 IGP01E1000_PHY_PORT_CONFIG,
1396 data);
1397 if (ret_val)
1398 goto out;
1399 } else if (phy->smart_speed == e1000_smart_speed_off) {
1400 ret_val = phy->ops.read_reg(hw,
1401 IGP01E1000_PHY_PORT_CONFIG,
1402 &data);
1403 if (ret_val)
1404 goto out;
1406 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1407 ret_val = phy->ops.write_reg(hw,
1408 IGP01E1000_PHY_PORT_CONFIG,
1409 data);
1410 if (ret_val)
1411 goto out;
1413 } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
1414 (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
1415 (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
1416 data |= IGP02E1000_PM_D3_LPLU;
1417 ret_val = phy->ops.write_reg(hw,
1418 IGP02E1000_PHY_POWER_MGMT,
1419 data);
1420 if (ret_val)
1421 goto out;
1423 /* When LPLU is enabled, we should disable SmartSpeed */
1424 ret_val = phy->ops.read_reg(hw,
1425 IGP01E1000_PHY_PORT_CONFIG,
1426 &data);
1427 if (ret_val)
1428 goto out;
1430 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1431 ret_val = phy->ops.write_reg(hw,
1432 IGP01E1000_PHY_PORT_CONFIG,
1433 data);
1436 out:
1437 return ret_val;
1441 * e1000_check_downshift_generic - Checks whether a downshift in speed occurred
1442 * @hw: pointer to the HW structure
1444 * Success returns 0, Failure returns 1
1446 * A downshift is detected by querying the PHY link health.
1448 s32 e1000_check_downshift_generic(struct e1000_hw *hw)
1450 struct e1000_phy_info *phy = &hw->phy;
1451 s32 ret_val;
1452 u16 phy_data, offset, mask;
1454 DEBUGFUNC("e1000_check_downshift_generic");
1456 switch (phy->type) {
1457 case e1000_phy_m88:
1458 case e1000_phy_gg82563:
1459 offset = M88E1000_PHY_SPEC_STATUS;
1460 mask = M88E1000_PSSR_DOWNSHIFT;
1461 break;
1462 case e1000_phy_igp_2:
1463 case e1000_phy_igp:
1464 case e1000_phy_igp_3:
1465 offset = IGP01E1000_PHY_LINK_HEALTH;
1466 mask = IGP01E1000_PLHR_SS_DOWNGRADE;
1467 break;
1468 default:
1469 /* speed downshift not supported */
1470 phy->speed_downgraded = FALSE;
1471 ret_val = E1000_SUCCESS;
1472 goto out;
1475 ret_val = phy->ops.read_reg(hw, offset, &phy_data);
1477 if (!ret_val)
1478 phy->speed_downgraded = (phy_data & mask) ? TRUE : FALSE;
1480 out:
1481 return ret_val;
1485 * e1000_check_polarity_m88 - Checks the polarity.
1486 * @hw: pointer to the HW structure
1488 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1490 * Polarity is determined based on the PHY specific status register.
1492 s32 e1000_check_polarity_m88(struct e1000_hw *hw)
1494 struct e1000_phy_info *phy = &hw->phy;
1495 s32 ret_val;
1496 u16 data;
1498 DEBUGFUNC("e1000_check_polarity_m88");
1500 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &data);
1502 if (!ret_val)
1503 phy->cable_polarity = (data & M88E1000_PSSR_REV_POLARITY)
1504 ? e1000_rev_polarity_reversed
1505 : e1000_rev_polarity_normal;
1507 return ret_val;
1511 * e1000_check_polarity_igp - Checks the polarity.
1512 * @hw: pointer to the HW structure
1514 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1516 * Polarity is determined based on the PHY port status register, and the
1517 * current speed (since there is no polarity at 100Mbps).
1519 s32 e1000_check_polarity_igp(struct e1000_hw *hw)
1521 struct e1000_phy_info *phy = &hw->phy;
1522 s32 ret_val;
1523 u16 data, offset, mask;
1525 DEBUGFUNC("e1000_check_polarity_igp");
1528 * Polarity is determined based on the speed of
1529 * our connection.
1531 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_STATUS, &data);
1532 if (ret_val)
1533 goto out;
1535 if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
1536 IGP01E1000_PSSR_SPEED_1000MBPS) {
1537 offset = IGP01E1000_PHY_PCS_INIT_REG;
1538 mask = IGP01E1000_PHY_POLARITY_MASK;
1539 } else {
1541 * This really only applies to 10Mbps since
1542 * there is no polarity for 100Mbps (always 0).
1544 offset = IGP01E1000_PHY_PORT_STATUS;
1545 mask = IGP01E1000_PSSR_POLARITY_REVERSED;
1548 ret_val = phy->ops.read_reg(hw, offset, &data);
1550 if (!ret_val)
1551 phy->cable_polarity = (data & mask)
1552 ? e1000_rev_polarity_reversed
1553 : e1000_rev_polarity_normal;
1555 out:
1556 return ret_val;
1560 * e1000_wait_autoneg_generic - Wait for auto-neg completion
1561 * @hw: pointer to the HW structure
1563 * Waits for auto-negotiation to complete or for the auto-negotiation time
1564 * limit to expire, which ever happens first.
1566 s32 e1000_wait_autoneg_generic(struct e1000_hw *hw)
1568 s32 ret_val = E1000_SUCCESS;
1569 u16 i, phy_status;
1571 DEBUGFUNC("e1000_wait_autoneg_generic");
1573 if (!(hw->phy.ops.read_reg))
1574 return E1000_SUCCESS;
1576 /* Break after autoneg completes or PHY_AUTO_NEG_LIMIT expires. */
1577 for (i = PHY_AUTO_NEG_LIMIT; i > 0; i--) {
1578 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
1579 if (ret_val)
1580 break;
1581 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
1582 if (ret_val)
1583 break;
1584 if (phy_status & MII_SR_AUTONEG_COMPLETE)
1585 break;
1586 msec_delay(100);
1590 * PHY_AUTO_NEG_TIME expiration doesn't guarantee auto-negotiation
1591 * has completed.
1593 return ret_val;
1597 * e1000_phy_has_link_generic - Polls PHY for link
1598 * @hw: pointer to the HW structure
1599 * @iterations: number of times to poll for link
1600 * @usec_interval: delay between polling attempts
1601 * @success: pointer to whether polling was successful or not
1603 * Polls the PHY status register for link, 'iterations' number of times.
1605 s32 e1000_phy_has_link_generic(struct e1000_hw *hw, u32 iterations,
1606 u32 usec_interval, bool *success)
1608 s32 ret_val = E1000_SUCCESS;
1609 u16 i, phy_status;
1611 DEBUGFUNC("e1000_phy_has_link_generic");
1613 if (!(hw->phy.ops.read_reg))
1614 return E1000_SUCCESS;
1616 for (i = 0; i < iterations; i++) {
1618 * Some PHYs require the PHY_STATUS register to be read
1619 * twice due to the link bit being sticky. No harm doing
1620 * it across the board.
1622 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
1623 if (ret_val)
1624 break;
1625 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
1626 if (ret_val)
1627 break;
1628 if (phy_status & MII_SR_LINK_STATUS)
1629 break;
1630 if (usec_interval >= 1000)
1631 msec_delay_irq(usec_interval/1000);
1632 else
1633 usec_delay(usec_interval);
1636 *success = (i < iterations) ? TRUE : FALSE;
1638 return ret_val;
1642 * e1000_get_cable_length_m88 - Determine cable length for m88 PHY
1643 * @hw: pointer to the HW structure
1645 * Reads the PHY specific status register to retrieve the cable length
1646 * information. The cable length is determined by averaging the minimum and
1647 * maximum values to get the "average" cable length. The m88 PHY has four
1648 * possible cable length values, which are:
1649 * Register Value Cable Length
1650 * 0 < 50 meters
1651 * 1 50 - 80 meters
1652 * 2 80 - 110 meters
1653 * 3 110 - 140 meters
1654 * 4 > 140 meters
1656 s32 e1000_get_cable_length_m88(struct e1000_hw *hw)
1658 struct e1000_phy_info *phy = &hw->phy;
1659 s32 ret_val;
1660 u16 phy_data, index;
1662 DEBUGFUNC("e1000_get_cable_length_m88");
1664 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
1665 if (ret_val)
1666 goto out;
1668 index = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
1669 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
1670 phy->min_cable_length = e1000_m88_cable_length_table[index];
1671 phy->max_cable_length = e1000_m88_cable_length_table[index+1];
1673 phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
1675 out:
1676 return ret_val;
1680 * e1000_get_cable_length_igp_2 - Determine cable length for igp2 PHY
1681 * @hw: pointer to the HW structure
1683 * The automatic gain control (agc) normalizes the amplitude of the
1684 * received signal, adjusting for the attenuation produced by the
1685 * cable. By reading the AGC registers, which represent the
1686 * combination of coarse and fine gain value, the value can be put
1687 * into a lookup table to obtain the approximate cable length
1688 * for each channel.
1690 s32 e1000_get_cable_length_igp_2(struct e1000_hw *hw)
1692 struct e1000_phy_info *phy = &hw->phy;
1693 s32 ret_val = E1000_SUCCESS;
1694 u16 phy_data, i, agc_value = 0;
1695 u16 cur_agc_index, max_agc_index = 0;
1696 u16 min_agc_index = IGP02E1000_CABLE_LENGTH_TABLE_SIZE - 1;
1697 u16 agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] =
1698 {IGP02E1000_PHY_AGC_A,
1699 IGP02E1000_PHY_AGC_B,
1700 IGP02E1000_PHY_AGC_C,
1701 IGP02E1000_PHY_AGC_D};
1703 DEBUGFUNC("e1000_get_cable_length_igp_2");
1705 /* Read the AGC registers for all channels */
1706 for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
1707 ret_val = phy->ops.read_reg(hw, agc_reg_array[i], &phy_data);
1708 if (ret_val)
1709 goto out;
1712 * Getting bits 15:9, which represent the combination of
1713 * coarse and fine gain values. The result is a number
1714 * that can be put into the lookup table to obtain the
1715 * approximate cable length.
1717 cur_agc_index = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
1718 IGP02E1000_AGC_LENGTH_MASK;
1720 /* Array index bound check. */
1721 if ((cur_agc_index >= IGP02E1000_CABLE_LENGTH_TABLE_SIZE) ||
1722 (cur_agc_index == 0)) {
1723 ret_val = -E1000_ERR_PHY;
1724 goto out;
1727 /* Remove min & max AGC values from calculation. */
1728 if (e1000_igp_2_cable_length_table[min_agc_index] >
1729 e1000_igp_2_cable_length_table[cur_agc_index])
1730 min_agc_index = cur_agc_index;
1731 if (e1000_igp_2_cable_length_table[max_agc_index] <
1732 e1000_igp_2_cable_length_table[cur_agc_index])
1733 max_agc_index = cur_agc_index;
1735 agc_value += e1000_igp_2_cable_length_table[cur_agc_index];
1738 agc_value -= (e1000_igp_2_cable_length_table[min_agc_index] +
1739 e1000_igp_2_cable_length_table[max_agc_index]);
1740 agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
1742 /* Calculate cable length with the error range of +/- 10 meters. */
1743 phy->min_cable_length = ((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
1744 (agc_value - IGP02E1000_AGC_RANGE) : 0;
1745 phy->max_cable_length = agc_value + IGP02E1000_AGC_RANGE;
1747 phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
1749 out:
1750 return ret_val;
1754 * e1000_get_phy_info_m88 - Retrieve PHY information
1755 * @hw: pointer to the HW structure
1757 * Valid for only copper links. Read the PHY status register (sticky read)
1758 * to verify that link is up. Read the PHY special control register to
1759 * determine the polarity and 10base-T extended distance. Read the PHY
1760 * special status register to determine MDI/MDIx and current speed. If
1761 * speed is 1000, then determine cable length, local and remote receiver.
1763 s32 e1000_get_phy_info_m88(struct e1000_hw *hw)
1765 struct e1000_phy_info *phy = &hw->phy;
1766 s32 ret_val;
1767 u16 phy_data;
1768 bool link;
1770 DEBUGFUNC("e1000_get_phy_info_m88");
1772 if (hw->phy.media_type != e1000_media_type_copper) {
1773 DEBUGOUT("Phy info is only valid for copper media\n");
1774 ret_val = -E1000_ERR_CONFIG;
1775 goto out;
1778 ret_val = e1000_phy_has_link_generic(hw, 1, 0, &link);
1779 if (ret_val)
1780 goto out;
1782 if (!link) {
1783 DEBUGOUT("Phy info is only valid if link is up\n");
1784 ret_val = -E1000_ERR_CONFIG;
1785 goto out;
1788 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1789 if (ret_val)
1790 goto out;
1792 phy->polarity_correction = (phy_data & M88E1000_PSCR_POLARITY_REVERSAL)
1793 ? TRUE
1794 : FALSE;
1796 ret_val = e1000_check_polarity_m88(hw);
1797 if (ret_val)
1798 goto out;
1800 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
1801 if (ret_val)
1802 goto out;
1804 phy->is_mdix = (phy_data & M88E1000_PSSR_MDIX) ? TRUE : FALSE;
1806 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
1807 ret_val = e1000_get_cable_length(hw);
1808 if (ret_val)
1809 goto out;
1811 ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &phy_data);
1812 if (ret_val)
1813 goto out;
1815 phy->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS)
1816 ? e1000_1000t_rx_status_ok
1817 : e1000_1000t_rx_status_not_ok;
1819 phy->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS)
1820 ? e1000_1000t_rx_status_ok
1821 : e1000_1000t_rx_status_not_ok;
1822 } else {
1823 /* Set values to "undefined" */
1824 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
1825 phy->local_rx = e1000_1000t_rx_status_undefined;
1826 phy->remote_rx = e1000_1000t_rx_status_undefined;
1829 out:
1830 return ret_val;
1834 * e1000_get_phy_info_igp - Retrieve igp PHY information
1835 * @hw: pointer to the HW structure
1837 * Read PHY status to determine if link is up. If link is up, then
1838 * set/determine 10base-T extended distance and polarity correction. Read
1839 * PHY port status to determine MDI/MDIx and speed. Based on the speed,
1840 * determine on the cable length, local and remote receiver.
1842 s32 e1000_get_phy_info_igp(struct e1000_hw *hw)
1844 struct e1000_phy_info *phy = &hw->phy;
1845 s32 ret_val;
1846 u16 data;
1847 bool link;
1849 DEBUGFUNC("e1000_get_phy_info_igp");
1851 ret_val = e1000_phy_has_link_generic(hw, 1, 0, &link);
1852 if (ret_val)
1853 goto out;
1855 if (!link) {
1856 DEBUGOUT("Phy info is only valid if link is up\n");
1857 ret_val = -E1000_ERR_CONFIG;
1858 goto out;
1861 phy->polarity_correction = TRUE;
1863 ret_val = e1000_check_polarity_igp(hw);
1864 if (ret_val)
1865 goto out;
1867 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_STATUS, &data);
1868 if (ret_val)
1869 goto out;
1871 phy->is_mdix = (data & IGP01E1000_PSSR_MDIX) ? TRUE : FALSE;
1873 if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
1874 IGP01E1000_PSSR_SPEED_1000MBPS) {
1875 ret_val = e1000_get_cable_length(hw);
1876 if (ret_val)
1877 goto out;
1879 ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &data);
1880 if (ret_val)
1881 goto out;
1883 phy->local_rx = (data & SR_1000T_LOCAL_RX_STATUS)
1884 ? e1000_1000t_rx_status_ok
1885 : e1000_1000t_rx_status_not_ok;
1887 phy->remote_rx = (data & SR_1000T_REMOTE_RX_STATUS)
1888 ? e1000_1000t_rx_status_ok
1889 : e1000_1000t_rx_status_not_ok;
1890 } else {
1891 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
1892 phy->local_rx = e1000_1000t_rx_status_undefined;
1893 phy->remote_rx = e1000_1000t_rx_status_undefined;
1896 out:
1897 return ret_val;
1901 * e1000_phy_sw_reset_generic - PHY software reset
1902 * @hw: pointer to the HW structure
1904 * Does a software reset of the PHY by reading the PHY control register and
1905 * setting/write the control register reset bit to the PHY.
1907 s32 e1000_phy_sw_reset_generic(struct e1000_hw *hw)
1909 s32 ret_val = E1000_SUCCESS;
1910 u16 phy_ctrl;
1912 DEBUGFUNC("e1000_phy_sw_reset_generic");
1914 if (!(hw->phy.ops.read_reg))
1915 goto out;
1917 ret_val = hw->phy.ops.read_reg(hw, PHY_CONTROL, &phy_ctrl);
1918 if (ret_val)
1919 goto out;
1921 phy_ctrl |= MII_CR_RESET;
1922 ret_val = hw->phy.ops.write_reg(hw, PHY_CONTROL, phy_ctrl);
1923 if (ret_val)
1924 goto out;
1926 usec_delay(1);
1928 out:
1929 return ret_val;
1933 * e1000_phy_hw_reset_generic - PHY hardware reset
1934 * @hw: pointer to the HW structure
1936 * Verify the reset block is not blocking us from resetting. Acquire
1937 * semaphore (if necessary) and read/set/write the device control reset
1938 * bit in the PHY. Wait the appropriate delay time for the device to
1939 * reset and release the semaphore (if necessary).
1941 s32 e1000_phy_hw_reset_generic(struct e1000_hw *hw)
1943 struct e1000_phy_info *phy = &hw->phy;
1944 s32 ret_val = E1000_SUCCESS;
1945 u32 ctrl;
1947 DEBUGFUNC("e1000_phy_hw_reset_generic");
1949 ret_val = phy->ops.check_reset_block(hw);
1950 if (ret_val) {
1951 ret_val = E1000_SUCCESS;
1952 goto out;
1955 ret_val = phy->ops.acquire(hw);
1956 if (ret_val)
1957 goto out;
1959 ctrl = E1000_READ_REG(hw, E1000_CTRL);
1960 E1000_WRITE_REG(hw, E1000_CTRL, ctrl | E1000_CTRL_PHY_RST);
1961 E1000_WRITE_FLUSH(hw);
1963 usec_delay(phy->reset_delay_us);
1965 E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
1966 E1000_WRITE_FLUSH(hw);
1968 usec_delay(150);
1970 phy->ops.release(hw);
1972 ret_val = phy->ops.get_cfg_done(hw);
1974 out:
1975 return ret_val;
1979 * e1000_get_cfg_done_generic - Generic configuration done
1980 * @hw: pointer to the HW structure
1982 * Generic function to wait 10 milli-seconds for configuration to complete
1983 * and return success.
1985 s32 e1000_get_cfg_done_generic(struct e1000_hw *hw)
1987 DEBUGFUNC("e1000_get_cfg_done_generic");
1989 msec_delay_irq(10);
1991 return E1000_SUCCESS;
1995 * e1000_phy_init_script_igp3 - Inits the IGP3 PHY
1996 * @hw: pointer to the HW structure
1998 * Initializes a Intel Gigabit PHY3 when an EEPROM is not present.
2000 s32 e1000_phy_init_script_igp3(struct e1000_hw *hw)
2002 DEBUGOUT("Running IGP 3 PHY init script\n");
2004 /* PHY init IGP 3 */
2005 /* Enable rise/fall, 10-mode work in class-A */
2006 hw->phy.ops.write_reg(hw, 0x2F5B, 0x9018);
2007 /* Remove all caps from Replica path filter */
2008 hw->phy.ops.write_reg(hw, 0x2F52, 0x0000);
2009 /* Bias trimming for ADC, AFE and Driver (Default) */
2010 hw->phy.ops.write_reg(hw, 0x2FB1, 0x8B24);
2011 /* Increase Hybrid poly bias */
2012 hw->phy.ops.write_reg(hw, 0x2FB2, 0xF8F0);
2013 /* Add 4% to Tx amplitude in Gig mode */
2014 hw->phy.ops.write_reg(hw, 0x2010, 0x10B0);
2015 /* Disable trimming (TTT) */
2016 hw->phy.ops.write_reg(hw, 0x2011, 0x0000);
2017 /* Poly DC correction to 94.6% + 2% for all channels */
2018 hw->phy.ops.write_reg(hw, 0x20DD, 0x249A);
2019 /* ABS DC correction to 95.9% */
2020 hw->phy.ops.write_reg(hw, 0x20DE, 0x00D3);
2021 /* BG temp curve trim */
2022 hw->phy.ops.write_reg(hw, 0x28B4, 0x04CE);
2023 /* Increasing ADC OPAMP stage 1 currents to max */
2024 hw->phy.ops.write_reg(hw, 0x2F70, 0x29E4);
2025 /* Force 1000 ( required for enabling PHY regs configuration) */
2026 hw->phy.ops.write_reg(hw, 0x0000, 0x0140);
2027 /* Set upd_freq to 6 */
2028 hw->phy.ops.write_reg(hw, 0x1F30, 0x1606);
2029 /* Disable NPDFE */
2030 hw->phy.ops.write_reg(hw, 0x1F31, 0xB814);
2031 /* Disable adaptive fixed FFE (Default) */
2032 hw->phy.ops.write_reg(hw, 0x1F35, 0x002A);
2033 /* Enable FFE hysteresis */
2034 hw->phy.ops.write_reg(hw, 0x1F3E, 0x0067);
2035 /* Fixed FFE for short cable lengths */
2036 hw->phy.ops.write_reg(hw, 0x1F54, 0x0065);
2037 /* Fixed FFE for medium cable lengths */
2038 hw->phy.ops.write_reg(hw, 0x1F55, 0x002A);
2039 /* Fixed FFE for long cable lengths */
2040 hw->phy.ops.write_reg(hw, 0x1F56, 0x002A);
2041 /* Enable Adaptive Clip Threshold */
2042 hw->phy.ops.write_reg(hw, 0x1F72, 0x3FB0);
2043 /* AHT reset limit to 1 */
2044 hw->phy.ops.write_reg(hw, 0x1F76, 0xC0FF);
2045 /* Set AHT master delay to 127 msec */
2046 hw->phy.ops.write_reg(hw, 0x1F77, 0x1DEC);
2047 /* Set scan bits for AHT */
2048 hw->phy.ops.write_reg(hw, 0x1F78, 0xF9EF);
2049 /* Set AHT Preset bits */
2050 hw->phy.ops.write_reg(hw, 0x1F79, 0x0210);
2051 /* Change integ_factor of channel A to 3 */
2052 hw->phy.ops.write_reg(hw, 0x1895, 0x0003);
2053 /* Change prop_factor of channels BCD to 8 */
2054 hw->phy.ops.write_reg(hw, 0x1796, 0x0008);
2055 /* Change cg_icount + enable integbp for channels BCD */
2056 hw->phy.ops.write_reg(hw, 0x1798, 0xD008);
2058 * Change cg_icount + enable integbp + change prop_factor_master
2059 * to 8 for channel A
2061 hw->phy.ops.write_reg(hw, 0x1898, 0xD918);
2062 /* Disable AHT in Slave mode on channel A */
2063 hw->phy.ops.write_reg(hw, 0x187A, 0x0800);
2065 * Enable LPLU and disable AN to 1000 in non-D0a states,
2066 * Enable SPD+B2B
2068 hw->phy.ops.write_reg(hw, 0x0019, 0x008D);
2069 /* Enable restart AN on an1000_dis change */
2070 hw->phy.ops.write_reg(hw, 0x001B, 0x2080);
2071 /* Enable wh_fifo read clock in 10/100 modes */
2072 hw->phy.ops.write_reg(hw, 0x0014, 0x0045);
2073 /* Restart AN, Speed selection is 1000 */
2074 hw->phy.ops.write_reg(hw, 0x0000, 0x1340);
2076 return E1000_SUCCESS;
2080 * e1000_get_phy_type_from_id - Get PHY type from id
2081 * @phy_id: phy_id read from the phy
2083 * Returns the phy type from the id.
2085 e1000_phy_type e1000_get_phy_type_from_id(u32 phy_id)
2087 e1000_phy_type phy_type = e1000_phy_unknown;
2089 switch (phy_id) {
2090 case M88E1000_I_PHY_ID:
2091 case M88E1000_E_PHY_ID:
2092 case M88E1111_I_PHY_ID:
2093 case M88E1011_I_PHY_ID:
2094 phy_type = e1000_phy_m88;
2095 break;
2096 case IGP01E1000_I_PHY_ID: /* IGP 1 & 2 share this */
2097 phy_type = e1000_phy_igp_2;
2098 break;
2099 case GG82563_E_PHY_ID:
2100 phy_type = e1000_phy_gg82563;
2101 break;
2102 case IGP03E1000_E_PHY_ID:
2103 phy_type = e1000_phy_igp_3;
2104 break;
2105 case IFE_E_PHY_ID:
2106 case IFE_PLUS_E_PHY_ID:
2107 case IFE_C_E_PHY_ID:
2108 phy_type = e1000_phy_ife;
2109 break;
2110 default:
2111 phy_type = e1000_phy_unknown;
2112 break;
2114 return phy_type;
2118 * e1000_power_up_phy_copper - Restore copper link in case of PHY power down
2119 * @hw: pointer to the HW structure
2121 * In the case of a PHY power down to save power, or to turn off link during a
2122 * driver unload, or wake on lan is not enabled, restore the link to previous
2123 * settings.
2125 void e1000_power_up_phy_copper(struct e1000_hw *hw)
2127 u16 mii_reg = 0;
2129 /* The PHY will retain its settings across a power down/up cycle */
2130 hw->phy.ops.read_reg(hw, PHY_CONTROL, &mii_reg);
2131 mii_reg &= ~MII_CR_POWER_DOWN;
2132 hw->phy.ops.write_reg(hw, PHY_CONTROL, mii_reg);
2136 * e1000_power_down_phy_copper - Restore copper link in case of PHY power down
2137 * @hw: pointer to the HW structure
2139 * In the case of a PHY power down to save power, or to turn off link during a
2140 * driver unload, or wake on lan is not enabled, restore the link to previous
2141 * settings.
2143 void e1000_power_down_phy_copper(struct e1000_hw *hw)
2145 u16 mii_reg = 0;
2147 /* The PHY will retain its settings across a power down/up cycle */
2148 hw->phy.ops.read_reg(hw, PHY_CONTROL, &mii_reg);
2149 mii_reg |= MII_CR_POWER_DOWN;
2150 hw->phy.ops.write_reg(hw, PHY_CONTROL, mii_reg);
2151 msec_delay(1);