revert between 56095 -> 55830 in arch
[AROS.git] / workbench / devs / networks / e1000 / e1000_phy.c
blobdbaf3a90f89e89aecfc0c9a1f68d18b7324d324e
1 /*******************************************************************************
3 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 2010 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"
31 /* Cable length tables */
32 static const u16 e1000_m88_cable_length_table[] = {
33 0, 50, 80, 110, 140, 140, E1000_CABLE_LENGTH_UNDEFINED };
34 #define M88E1000_CABLE_LENGTH_TABLE_SIZE \
35 (sizeof(e1000_m88_cable_length_table) / \
36 sizeof(e1000_m88_cable_length_table[0]))
38 static const u16 e1000_igp_2_cable_length_table[] = {
39 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21, 0, 0, 0, 3,
40 6, 10, 13, 16, 19, 23, 26, 29, 32, 35, 38, 41, 6, 10, 14, 18, 22,
41 26, 30, 33, 37, 41, 44, 48, 51, 54, 58, 61, 21, 26, 31, 35, 40,
42 44, 49, 53, 57, 61, 65, 68, 72, 75, 79, 82, 40, 45, 51, 56, 61,
43 66, 70, 75, 79, 83, 87, 91, 94, 98, 101, 104, 60, 66, 72, 77, 82,
44 87, 92, 96, 100, 104, 108, 111, 114, 117, 119, 121, 83, 89, 95,
45 100, 105, 109, 113, 116, 119, 122, 124, 104, 109, 114, 118, 121,
46 124};
47 #define IGP02E1000_CABLE_LENGTH_TABLE_SIZE \
48 (sizeof(e1000_igp_2_cable_length_table) / \
49 sizeof(e1000_igp_2_cable_length_table[0]))
51 /**
52 * e1000_init_phy_ops_generic - Initialize PHY function pointers
53 * @hw: pointer to the HW structure
55 * Setups up the function pointers to no-op functions
56 **/
57 void e1000_init_phy_ops_generic(struct e1000_hw *hw)
59 struct e1000_phy_info *phy = &hw->phy;
60 DEBUGFUNC("e1000_init_phy_ops_generic");
62 /* Initialize function pointers */
63 phy->ops.init_params = e1000_null_ops_generic;
64 phy->ops.acquire = e1000_null_ops_generic;
65 phy->ops.check_polarity = e1000_null_ops_generic;
66 phy->ops.check_reset_block = e1000_null_ops_generic;
67 phy->ops.commit = e1000_null_ops_generic;
68 phy->ops.force_speed_duplex = e1000_null_ops_generic;
69 phy->ops.get_cfg_done = e1000_null_ops_generic;
70 phy->ops.get_cable_length = e1000_null_ops_generic;
71 phy->ops.get_info = e1000_null_ops_generic;
72 phy->ops.set_page = e1000_null_set_page;
73 phy->ops.read_reg = e1000_null_read_reg;
74 phy->ops.read_reg_locked = e1000_null_read_reg;
75 phy->ops.read_reg_page = e1000_null_read_reg;
76 phy->ops.release = e1000_null_phy_generic;
77 phy->ops.reset = e1000_null_ops_generic;
78 phy->ops.set_d0_lplu_state = e1000_null_lplu_state;
79 phy->ops.set_d3_lplu_state = e1000_null_lplu_state;
80 phy->ops.write_reg = e1000_null_write_reg;
81 phy->ops.write_reg_locked = e1000_null_write_reg;
82 phy->ops.write_reg_page = e1000_null_write_reg;
83 phy->ops.power_up = e1000_null_phy_generic;
84 phy->ops.power_down = e1000_null_phy_generic;
87 /**
88 * e1000_null_set_page - No-op function, return 0
89 * @hw: pointer to the HW structure
90 **/
91 s32 e1000_null_set_page(struct e1000_hw *hw, u16 data)
93 DEBUGFUNC("e1000_null_set_page");
94 return E1000_SUCCESS;
97 /**
98 * e1000_null_read_reg - No-op function, return 0
99 * @hw: pointer to the HW structure
101 s32 e1000_null_read_reg(struct e1000_hw *hw, u32 offset, u16 *data)
103 DEBUGFUNC("e1000_null_read_reg");
104 return E1000_SUCCESS;
108 * e1000_null_phy_generic - No-op function, return void
109 * @hw: pointer to the HW structure
111 void e1000_null_phy_generic(struct e1000_hw *hw)
113 DEBUGFUNC("e1000_null_phy_generic");
114 return;
118 * e1000_null_lplu_state - No-op function, return 0
119 * @hw: pointer to the HW structure
121 s32 e1000_null_lplu_state(struct e1000_hw *hw, bool active)
123 DEBUGFUNC("e1000_null_lplu_state");
124 return E1000_SUCCESS;
128 * e1000_null_write_reg - No-op function, return 0
129 * @hw: pointer to the HW structure
131 s32 e1000_null_write_reg(struct e1000_hw *hw, u32 offset, u16 data)
133 DEBUGFUNC("e1000_null_write_reg");
134 return E1000_SUCCESS;
138 * e1000_check_reset_block_generic - Check if PHY reset is blocked
139 * @hw: pointer to the HW structure
141 * Read the PHY management control register and check whether a PHY reset
142 * is blocked. If a reset is not blocked return E1000_SUCCESS, otherwise
143 * return E1000_BLK_PHY_RESET (12).
145 s32 e1000_check_reset_block_generic(struct e1000_hw *hw)
147 u32 manc;
149 DEBUGFUNC("e1000_check_reset_block");
151 manc = E1000_READ_REG(hw, E1000_MANC);
153 return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
154 E1000_BLK_PHY_RESET : E1000_SUCCESS;
158 * e1000_get_phy_id - Retrieve the PHY ID and revision
159 * @hw: pointer to the HW structure
161 * Reads the PHY registers and stores the PHY ID and possibly the PHY
162 * revision in the hardware structure.
164 s32 e1000_get_phy_id(struct e1000_hw *hw)
166 struct e1000_phy_info *phy = &hw->phy;
167 s32 ret_val = E1000_SUCCESS;
168 u16 phy_id;
170 DEBUGFUNC("e1000_get_phy_id");
172 if (!(phy->ops.read_reg))
173 goto out;
175 ret_val = phy->ops.read_reg(hw, PHY_ID1, &phy_id);
176 if (ret_val)
177 goto out;
179 phy->id = (u32)(phy_id << 16);
180 usec_delay(20);
181 ret_val = phy->ops.read_reg(hw, PHY_ID2, &phy_id);
182 if (ret_val)
183 goto out;
185 phy->id |= (u32)(phy_id & PHY_REVISION_MASK);
186 phy->revision = (u32)(phy_id & ~PHY_REVISION_MASK);
188 out:
189 return ret_val;
193 * e1000_phy_reset_dsp_generic - Reset PHY DSP
194 * @hw: pointer to the HW structure
196 * Reset the digital signal processor.
198 s32 e1000_phy_reset_dsp_generic(struct e1000_hw *hw)
200 s32 ret_val = E1000_SUCCESS;
202 DEBUGFUNC("e1000_phy_reset_dsp_generic");
204 if (!(hw->phy.ops.write_reg))
205 goto out;
207 ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xC1);
208 if (ret_val)
209 goto out;
211 ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_GEN_CONTROL, 0);
213 out:
214 return ret_val;
218 * e1000_read_phy_reg_mdic - Read MDI control register
219 * @hw: pointer to the HW structure
220 * @offset: register offset to be read
221 * @data: pointer to the read data
223 * Reads the MDI control register in the PHY at offset and stores the
224 * information read to data.
226 s32 e1000_read_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 *data)
228 struct e1000_phy_info *phy = &hw->phy;
229 u32 i, mdic = 0;
230 s32 ret_val = E1000_SUCCESS;
232 DEBUGFUNC("e1000_read_phy_reg_mdic");
234 if (offset > MAX_PHY_REG_ADDRESS) {
235 DEBUGOUT1("PHY Address %d is out of range\n", offset);
236 return -E1000_ERR_PARAM;
240 * Set up Op-code, Phy Address, and register offset in the MDI
241 * Control register. The MAC will take care of interfacing with the
242 * PHY to retrieve the desired data.
244 mdic = ((offset << E1000_MDIC_REG_SHIFT) |
245 (phy->addr << E1000_MDIC_PHY_SHIFT) |
246 (E1000_MDIC_OP_READ));
248 E1000_WRITE_REG(hw, E1000_MDIC, mdic);
251 * Poll the ready bit to see if the MDI read completed
252 * Increasing the time out as testing showed failures with
253 * the lower time out
255 for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
256 usec_delay(50);
257 mdic = E1000_READ_REG(hw, E1000_MDIC);
258 if (mdic & E1000_MDIC_READY)
259 break;
261 if (!(mdic & E1000_MDIC_READY)) {
262 DEBUGOUT("MDI Read did not complete\n");
263 ret_val = -E1000_ERR_PHY;
264 goto out;
266 if (mdic & E1000_MDIC_ERROR) {
267 DEBUGOUT("MDI Error\n");
268 ret_val = -E1000_ERR_PHY;
269 goto out;
271 *data = (u16) mdic;
273 out:
274 return ret_val;
278 * e1000_write_phy_reg_mdic - Write MDI control register
279 * @hw: pointer to the HW structure
280 * @offset: register offset to write to
281 * @data: data to write to register at offset
283 * Writes data to MDI control register in the PHY at offset.
285 s32 e1000_write_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 data)
287 struct e1000_phy_info *phy = &hw->phy;
288 u32 i, mdic = 0;
289 s32 ret_val = E1000_SUCCESS;
291 DEBUGFUNC("e1000_write_phy_reg_mdic");
293 if (offset > MAX_PHY_REG_ADDRESS) {
294 DEBUGOUT1("PHY Address %d is out of range\n", offset);
295 return -E1000_ERR_PARAM;
299 * Set up Op-code, Phy Address, and register offset in the MDI
300 * Control register. The MAC will take care of interfacing with the
301 * PHY to retrieve the desired data.
303 mdic = (((u32)data) |
304 (offset << E1000_MDIC_REG_SHIFT) |
305 (phy->addr << E1000_MDIC_PHY_SHIFT) |
306 (E1000_MDIC_OP_WRITE));
308 E1000_WRITE_REG(hw, E1000_MDIC, mdic);
311 * Poll the ready bit to see if the MDI read completed
312 * Increasing the time out as testing showed failures with
313 * the lower time out
315 for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
316 usec_delay(50);
317 mdic = E1000_READ_REG(hw, E1000_MDIC);
318 if (mdic & E1000_MDIC_READY)
319 break;
321 if (!(mdic & E1000_MDIC_READY)) {
322 DEBUGOUT("MDI Write did not complete\n");
323 ret_val = -E1000_ERR_PHY;
324 goto out;
326 if (mdic & E1000_MDIC_ERROR) {
327 DEBUGOUT("MDI Error\n");
328 ret_val = -E1000_ERR_PHY;
329 goto out;
332 out:
333 return ret_val;
337 * e1000_read_phy_reg_m88 - Read m88 PHY register
338 * @hw: pointer to the HW structure
339 * @offset: register offset to be read
340 * @data: pointer to the read data
342 * Acquires semaphore, if necessary, then reads the PHY register at offset
343 * and storing the retrieved information in data. Release any acquired
344 * semaphores before exiting.
346 s32 e1000_read_phy_reg_m88(struct e1000_hw *hw, u32 offset, u16 *data)
348 s32 ret_val = E1000_SUCCESS;
350 DEBUGFUNC("e1000_read_phy_reg_m88");
352 if (!(hw->phy.ops.acquire))
353 goto out;
355 ret_val = hw->phy.ops.acquire(hw);
356 if (ret_val)
357 goto out;
359 ret_val = e1000_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
360 data);
362 hw->phy.ops.release(hw);
364 out:
365 return ret_val;
369 * e1000_write_phy_reg_m88 - Write m88 PHY register
370 * @hw: pointer to the HW structure
371 * @offset: register offset to write to
372 * @data: data to write at register offset
374 * Acquires semaphore, if necessary, then writes the data to PHY register
375 * at the offset. Release any acquired semaphores before exiting.
377 s32 e1000_write_phy_reg_m88(struct e1000_hw *hw, u32 offset, u16 data)
379 s32 ret_val = E1000_SUCCESS;
381 DEBUGFUNC("e1000_write_phy_reg_m88");
383 if (!(hw->phy.ops.acquire))
384 goto out;
386 ret_val = hw->phy.ops.acquire(hw);
387 if (ret_val)
388 goto out;
390 ret_val = e1000_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
391 data);
393 hw->phy.ops.release(hw);
395 out:
396 return ret_val;
400 * e1000_set_page_igp - Set page as on IGP-like PHY(s)
401 * @hw: pointer to the HW structure
402 * @page: page to set (shifted left when necessary)
404 * Sets PHY page required for PHY register access. Assumes semaphore is
405 * already acquired. Note, this function sets phy.addr to 1 so the caller
406 * must set it appropriately (if necessary) after this function returns.
408 s32 e1000_set_page_igp(struct e1000_hw *hw, u16 page)
410 DEBUGFUNC("e1000_set_page_igp");
412 DEBUGOUT1("Setting page 0x%x\n", page);
414 hw->phy.addr = 1;
416 return e1000_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT, page);
420 * __e1000_read_phy_reg_igp - Read igp PHY register
421 * @hw: pointer to the HW structure
422 * @offset: register offset to be read
423 * @data: pointer to the read data
424 * @locked: semaphore has already been acquired or not
426 * Acquires semaphore, if necessary, then reads the PHY register at offset
427 * and stores the retrieved information in data. Release any acquired
428 * semaphores before exiting.
430 static s32 __e1000_read_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 *data,
431 bool locked)
433 s32 ret_val = E1000_SUCCESS;
435 DEBUGFUNC("__e1000_read_phy_reg_igp");
437 if (!locked) {
438 if (!(hw->phy.ops.acquire))
439 goto out;
441 ret_val = hw->phy.ops.acquire(hw);
442 if (ret_val)
443 goto out;
446 if (offset > MAX_PHY_MULTI_PAGE_REG) {
447 ret_val = e1000_write_phy_reg_mdic(hw,
448 IGP01E1000_PHY_PAGE_SELECT,
449 (u16)offset);
450 if (ret_val)
451 goto release;
454 ret_val = e1000_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
455 data);
457 release:
458 if (!locked)
459 hw->phy.ops.release(hw);
460 out:
461 return ret_val;
465 * e1000_read_phy_reg_igp - Read igp PHY register
466 * @hw: pointer to the HW structure
467 * @offset: register offset to be read
468 * @data: pointer to the read data
470 * Acquires semaphore then reads the PHY register at offset and stores the
471 * retrieved information in data.
472 * Release the acquired semaphore before exiting.
474 s32 e1000_read_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 *data)
476 return __e1000_read_phy_reg_igp(hw, offset, data, false);
480 * e1000_read_phy_reg_igp_locked - Read igp PHY register
481 * @hw: pointer to the HW structure
482 * @offset: register offset to be read
483 * @data: pointer to the read data
485 * Reads the PHY register at offset and stores the retrieved information
486 * in data. Assumes semaphore already acquired.
488 s32 e1000_read_phy_reg_igp_locked(struct e1000_hw *hw, u32 offset, u16 *data)
490 return __e1000_read_phy_reg_igp(hw, offset, data, true);
494 * e1000_write_phy_reg_igp - Write igp PHY register
495 * @hw: pointer to the HW structure
496 * @offset: register offset to write to
497 * @data: data to write at register offset
498 * @locked: semaphore has already been acquired or not
500 * Acquires semaphore, if necessary, then writes the data to PHY register
501 * at the offset. Release any acquired semaphores before exiting.
503 static s32 __e1000_write_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 data,
504 bool locked)
506 s32 ret_val = E1000_SUCCESS;
508 DEBUGFUNC("e1000_write_phy_reg_igp");
510 if (!locked) {
511 if (!(hw->phy.ops.acquire))
512 goto out;
514 ret_val = hw->phy.ops.acquire(hw);
515 if (ret_val)
516 goto out;
519 if (offset > MAX_PHY_MULTI_PAGE_REG) {
520 ret_val = e1000_write_phy_reg_mdic(hw,
521 IGP01E1000_PHY_PAGE_SELECT,
522 (u16)offset);
523 if (ret_val)
524 goto release;
527 ret_val = e1000_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
528 data);
530 release:
531 if (!locked)
532 hw->phy.ops.release(hw);
534 out:
535 return ret_val;
539 * e1000_write_phy_reg_igp - Write igp PHY register
540 * @hw: pointer to the HW structure
541 * @offset: register offset to write to
542 * @data: data to write at register offset
544 * Acquires semaphore then writes the data to PHY register
545 * at the offset. Release any acquired semaphores before exiting.
547 s32 e1000_write_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 data)
549 return __e1000_write_phy_reg_igp(hw, offset, data, false);
553 * e1000_write_phy_reg_igp_locked - Write igp PHY register
554 * @hw: pointer to the HW structure
555 * @offset: register offset to write to
556 * @data: data to write at register offset
558 * Writes the data to PHY register at the offset.
559 * Assumes semaphore already acquired.
561 s32 e1000_write_phy_reg_igp_locked(struct e1000_hw *hw, u32 offset, u16 data)
563 return __e1000_write_phy_reg_igp(hw, offset, data, true);
567 * __e1000_read_kmrn_reg - Read kumeran register
568 * @hw: pointer to the HW structure
569 * @offset: register offset to be read
570 * @data: pointer to the read data
571 * @locked: semaphore has already been acquired or not
573 * Acquires semaphore, if necessary. Then reads the PHY register at offset
574 * using the kumeran interface. The information retrieved is stored in data.
575 * Release any acquired semaphores before exiting.
577 static s32 __e1000_read_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 *data,
578 bool locked)
580 u32 kmrnctrlsta;
581 s32 ret_val = E1000_SUCCESS;
583 DEBUGFUNC("__e1000_read_kmrn_reg");
585 if (!locked) {
586 if (!(hw->phy.ops.acquire))
587 goto out;
589 ret_val = hw->phy.ops.acquire(hw);
590 if (ret_val)
591 goto out;
594 kmrnctrlsta = ((offset << E1000_KMRNCTRLSTA_OFFSET_SHIFT) &
595 E1000_KMRNCTRLSTA_OFFSET) | E1000_KMRNCTRLSTA_REN;
596 E1000_WRITE_REG(hw, E1000_KMRNCTRLSTA, kmrnctrlsta);
597 E1000_WRITE_FLUSH(hw);
599 usec_delay(2);
601 kmrnctrlsta = E1000_READ_REG(hw, E1000_KMRNCTRLSTA);
602 *data = (u16)kmrnctrlsta;
604 if (!locked)
605 hw->phy.ops.release(hw);
607 out:
608 return ret_val;
612 * e1000_read_kmrn_reg_generic - Read kumeran register
613 * @hw: pointer to the HW structure
614 * @offset: register offset to be read
615 * @data: pointer to the read data
617 * Acquires semaphore then reads the PHY register at offset using the
618 * kumeran interface. The information retrieved is stored in data.
619 * Release the acquired semaphore before exiting.
621 s32 e1000_read_kmrn_reg_generic(struct e1000_hw *hw, u32 offset, u16 *data)
623 return __e1000_read_kmrn_reg(hw, offset, data, false);
627 * e1000_read_kmrn_reg_locked - Read kumeran register
628 * @hw: pointer to the HW structure
629 * @offset: register offset to be read
630 * @data: pointer to the read data
632 * Reads the PHY register at offset using the kumeran interface. The
633 * information retrieved is stored in data.
634 * Assumes semaphore already acquired.
636 s32 e1000_read_kmrn_reg_locked(struct e1000_hw *hw, u32 offset, u16 *data)
638 return __e1000_read_kmrn_reg(hw, offset, data, true);
642 * __e1000_write_kmrn_reg - Write kumeran register
643 * @hw: pointer to the HW structure
644 * @offset: register offset to write to
645 * @data: data to write at register offset
646 * @locked: semaphore has already been acquired or not
648 * Acquires semaphore, if necessary. Then write the data to PHY register
649 * at the offset using the kumeran interface. Release any acquired semaphores
650 * before exiting.
652 static s32 __e1000_write_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 data,
653 bool locked)
655 u32 kmrnctrlsta;
656 s32 ret_val = E1000_SUCCESS;
658 DEBUGFUNC("e1000_write_kmrn_reg_generic");
660 if (!locked) {
661 if (!(hw->phy.ops.acquire))
662 goto out;
664 ret_val = hw->phy.ops.acquire(hw);
665 if (ret_val)
666 goto out;
669 kmrnctrlsta = ((offset << E1000_KMRNCTRLSTA_OFFSET_SHIFT) &
670 E1000_KMRNCTRLSTA_OFFSET) | data;
671 E1000_WRITE_REG(hw, E1000_KMRNCTRLSTA, kmrnctrlsta);
672 E1000_WRITE_FLUSH(hw);
674 usec_delay(2);
676 if (!locked)
677 hw->phy.ops.release(hw);
679 out:
680 return ret_val;
684 * e1000_write_kmrn_reg_generic - Write kumeran register
685 * @hw: pointer to the HW structure
686 * @offset: register offset to write to
687 * @data: data to write at register offset
689 * Acquires semaphore then writes the data to the PHY register at the offset
690 * using the kumeran interface. Release the acquired semaphore before exiting.
692 s32 e1000_write_kmrn_reg_generic(struct e1000_hw *hw, u32 offset, u16 data)
694 return __e1000_write_kmrn_reg(hw, offset, data, false);
698 * e1000_write_kmrn_reg_locked - Write kumeran register
699 * @hw: pointer to the HW structure
700 * @offset: register offset to write to
701 * @data: data to write at register offset
703 * Write the data to PHY register at the offset using the kumeran interface.
704 * Assumes semaphore already acquired.
706 s32 e1000_write_kmrn_reg_locked(struct e1000_hw *hw, u32 offset, u16 data)
708 return __e1000_write_kmrn_reg(hw, offset, data, true);
712 * e1000_copper_link_setup_m88 - Setup m88 PHY's for copper link
713 * @hw: pointer to the HW structure
715 * Sets up MDI/MDI-X and polarity for m88 PHY's. If necessary, transmit clock
716 * and downshift values are set also.
718 s32 e1000_copper_link_setup_m88(struct e1000_hw *hw)
720 struct e1000_phy_info *phy = &hw->phy;
721 s32 ret_val;
722 u16 phy_data;
724 DEBUGFUNC("e1000_copper_link_setup_m88");
726 if (phy->reset_disable) {
727 ret_val = E1000_SUCCESS;
728 goto out;
731 /* Enable CRS on Tx. This must be set for half-duplex operation. */
732 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
733 if (ret_val)
734 goto out;
736 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
739 * Options:
740 * MDI/MDI-X = 0 (default)
741 * 0 - Auto for all speeds
742 * 1 - MDI mode
743 * 2 - MDI-X mode
744 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
746 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
748 switch (phy->mdix) {
749 case 1:
750 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
751 break;
752 case 2:
753 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
754 break;
755 case 3:
756 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
757 break;
758 case 0:
759 default:
760 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
761 break;
765 * Options:
766 * disable_polarity_correction = 0 (default)
767 * Automatic Correction for Reversed Cable Polarity
768 * 0 - Disabled
769 * 1 - Enabled
771 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
772 if (phy->disable_polarity_correction == 1)
773 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
775 ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
776 if (ret_val)
777 goto out;
779 if (phy->revision < E1000_REVISION_4) {
781 * Force TX_CLK in the Extended PHY Specific Control Register
782 * to 25MHz clock.
784 ret_val = phy->ops.read_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
785 &phy_data);
786 if (ret_val)
787 goto out;
789 phy_data |= M88E1000_EPSCR_TX_CLK_25;
791 if ((phy->revision == E1000_REVISION_2) &&
792 (phy->id == M88E1111_I_PHY_ID)) {
793 /* 82573L PHY - set the downshift counter to 5x. */
794 phy_data &= ~M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK;
795 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
796 } else {
797 /* Configure Master and Slave downshift values */
798 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
799 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
800 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
801 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
803 ret_val = phy->ops.write_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
804 phy_data);
805 if (ret_val)
806 goto out;
809 /* Commit the changes. */
810 ret_val = phy->ops.commit(hw);
811 if (ret_val) {
812 DEBUGOUT("Error committing the PHY changes\n");
813 goto out;
816 out:
817 return ret_val;
821 * e1000_copper_link_setup_igp - Setup igp PHY's for copper link
822 * @hw: pointer to the HW structure
824 * Sets up LPLU, MDI/MDI-X, polarity, Smartspeed and Master/Slave config for
825 * igp PHY's.
827 s32 e1000_copper_link_setup_igp(struct e1000_hw *hw)
829 struct e1000_phy_info *phy = &hw->phy;
830 s32 ret_val;
831 u16 data;
833 DEBUGFUNC("e1000_copper_link_setup_igp");
835 if (phy->reset_disable) {
836 ret_val = E1000_SUCCESS;
837 goto out;
840 ret_val = hw->phy.ops.reset(hw);
841 if (ret_val) {
842 DEBUGOUT("Error resetting the PHY.\n");
843 goto out;
847 * Wait 100ms for MAC to configure PHY from NVM settings, to avoid
848 * timeout issues when LFS is enabled.
850 msec_delay(100);
853 * The NVM settings will configure LPLU in D3 for
854 * non-IGP1 PHYs.
856 if (phy->type == e1000_phy_igp) {
857 /* disable lplu d3 during driver init */
858 ret_val = hw->phy.ops.set_d3_lplu_state(hw, false);
859 if (ret_val) {
860 DEBUGOUT("Error Disabling LPLU D3\n");
861 goto out;
865 /* disable lplu d0 during driver init */
866 if (hw->phy.ops.set_d0_lplu_state) {
867 ret_val = hw->phy.ops.set_d0_lplu_state(hw, false);
868 if (ret_val) {
869 DEBUGOUT("Error Disabling LPLU D0\n");
870 goto out;
873 /* Configure mdi-mdix settings */
874 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CTRL, &data);
875 if (ret_val)
876 goto out;
878 data &= ~IGP01E1000_PSCR_AUTO_MDIX;
880 switch (phy->mdix) {
881 case 1:
882 data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
883 break;
884 case 2:
885 data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
886 break;
887 case 0:
888 default:
889 data |= IGP01E1000_PSCR_AUTO_MDIX;
890 break;
892 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CTRL, data);
893 if (ret_val)
894 goto out;
896 /* set auto-master slave resolution settings */
897 if (hw->mac.autoneg) {
899 * when autonegotiation advertisement is only 1000Mbps then we
900 * should disable SmartSpeed and enable Auto MasterSlave
901 * resolution as hardware default.
903 if (phy->autoneg_advertised == ADVERTISE_1000_FULL) {
904 /* Disable SmartSpeed */
905 ret_val = phy->ops.read_reg(hw,
906 IGP01E1000_PHY_PORT_CONFIG,
907 &data);
908 if (ret_val)
909 goto out;
911 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
912 ret_val = phy->ops.write_reg(hw,
913 IGP01E1000_PHY_PORT_CONFIG,
914 data);
915 if (ret_val)
916 goto out;
918 /* Set auto Master/Slave resolution process */
919 ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL, &data);
920 if (ret_val)
921 goto out;
923 data &= ~CR_1000T_MS_ENABLE;
924 ret_val = phy->ops.write_reg(hw, PHY_1000T_CTRL, data);
925 if (ret_val)
926 goto out;
929 ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL, &data);
930 if (ret_val)
931 goto out;
933 /* load defaults for future use */
934 phy->original_ms_type = (data & CR_1000T_MS_ENABLE) ?
935 ((data & CR_1000T_MS_VALUE) ?
936 e1000_ms_force_master :
937 e1000_ms_force_slave) :
938 e1000_ms_auto;
940 switch (phy->ms_type) {
941 case e1000_ms_force_master:
942 data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
943 break;
944 case e1000_ms_force_slave:
945 data |= CR_1000T_MS_ENABLE;
946 data &= ~(CR_1000T_MS_VALUE);
947 break;
948 case e1000_ms_auto:
949 data &= ~CR_1000T_MS_ENABLE;
950 default:
951 break;
953 ret_val = phy->ops.write_reg(hw, PHY_1000T_CTRL, data);
954 if (ret_val)
955 goto out;
958 out:
959 return ret_val;
963 * e1000_copper_link_autoneg - Setup/Enable autoneg for copper link
964 * @hw: pointer to the HW structure
966 * Performs initial bounds checking on autoneg advertisement parameter, then
967 * configure to advertise the full capability. Setup the PHY to autoneg
968 * and restart the negotiation process between the link partner. If
969 * autoneg_wait_to_complete, then wait for autoneg to complete before exiting.
971 s32 e1000_copper_link_autoneg(struct e1000_hw *hw)
973 struct e1000_phy_info *phy = &hw->phy;
974 s32 ret_val;
975 u16 phy_ctrl;
977 DEBUGFUNC("e1000_copper_link_autoneg");
980 * Perform some bounds checking on the autoneg advertisement
981 * parameter.
983 phy->autoneg_advertised &= phy->autoneg_mask;
986 * If autoneg_advertised is zero, we assume it was not defaulted
987 * by the calling code so we set to advertise full capability.
989 if (phy->autoneg_advertised == 0)
990 phy->autoneg_advertised = phy->autoneg_mask;
992 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
993 ret_val = e1000_phy_setup_autoneg(hw);
994 if (ret_val) {
995 DEBUGOUT("Error Setting up Auto-Negotiation\n");
996 goto out;
998 DEBUGOUT("Restarting Auto-Neg\n");
1001 * Restart auto-negotiation by setting the Auto Neg Enable bit and
1002 * the Auto Neg Restart bit in the PHY control register.
1004 ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_ctrl);
1005 if (ret_val)
1006 goto out;
1008 phy_ctrl |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
1009 ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_ctrl);
1010 if (ret_val)
1011 goto out;
1014 * Does the user want to wait for Auto-Neg to complete here, or
1015 * check at a later time (for example, callback routine).
1017 if (phy->autoneg_wait_to_complete) {
1018 ret_val = hw->mac.ops.wait_autoneg(hw);
1019 if (ret_val) {
1020 DEBUGOUT("Error while waiting for "
1021 "autoneg to complete\n");
1022 goto out;
1026 hw->mac.get_link_status = true;
1028 out:
1029 return ret_val;
1033 * e1000_phy_setup_autoneg - Configure PHY for auto-negotiation
1034 * @hw: pointer to the HW structure
1036 * Reads the MII auto-neg advertisement register and/or the 1000T control
1037 * register and if the PHY is already setup for auto-negotiation, then
1038 * return successful. Otherwise, setup advertisement and flow control to
1039 * the appropriate values for the wanted auto-negotiation.
1041 s32 e1000_phy_setup_autoneg(struct e1000_hw *hw)
1043 struct e1000_phy_info *phy = &hw->phy;
1044 s32 ret_val;
1045 u16 mii_autoneg_adv_reg;
1046 u16 mii_1000t_ctrl_reg = 0;
1048 DEBUGFUNC("e1000_phy_setup_autoneg");
1050 phy->autoneg_advertised &= phy->autoneg_mask;
1052 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
1053 ret_val = phy->ops.read_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
1054 if (ret_val)
1055 goto out;
1057 if (phy->autoneg_mask & ADVERTISE_1000_FULL) {
1058 /* Read the MII 1000Base-T Control Register (Address 9). */
1059 ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL,
1060 &mii_1000t_ctrl_reg);
1061 if (ret_val)
1062 goto out;
1066 * Need to parse both autoneg_advertised and fc and set up
1067 * the appropriate PHY registers. First we will parse for
1068 * autoneg_advertised software override. Since we can advertise
1069 * a plethora of combinations, we need to check each bit
1070 * individually.
1074 * First we clear all the 10/100 mb speed bits in the Auto-Neg
1075 * Advertisement Register (Address 4) and the 1000 mb speed bits in
1076 * the 1000Base-T Control Register (Address 9).
1078 mii_autoneg_adv_reg &= ~(NWAY_AR_100TX_FD_CAPS |
1079 NWAY_AR_100TX_HD_CAPS |
1080 NWAY_AR_10T_FD_CAPS |
1081 NWAY_AR_10T_HD_CAPS);
1082 mii_1000t_ctrl_reg &= ~(CR_1000T_HD_CAPS | CR_1000T_FD_CAPS);
1084 DEBUGOUT1("autoneg_advertised %x\n", phy->autoneg_advertised);
1086 /* Do we want to advertise 10 Mb Half Duplex? */
1087 if (phy->autoneg_advertised & ADVERTISE_10_HALF) {
1088 DEBUGOUT("Advertise 10mb Half duplex\n");
1089 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
1092 /* Do we want to advertise 10 Mb Full Duplex? */
1093 if (phy->autoneg_advertised & ADVERTISE_10_FULL) {
1094 DEBUGOUT("Advertise 10mb Full duplex\n");
1095 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
1098 /* Do we want to advertise 100 Mb Half Duplex? */
1099 if (phy->autoneg_advertised & ADVERTISE_100_HALF) {
1100 DEBUGOUT("Advertise 100mb Half duplex\n");
1101 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
1104 /* Do we want to advertise 100 Mb Full Duplex? */
1105 if (phy->autoneg_advertised & ADVERTISE_100_FULL) {
1106 DEBUGOUT("Advertise 100mb Full duplex\n");
1107 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
1110 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
1111 if (phy->autoneg_advertised & ADVERTISE_1000_HALF)
1112 DEBUGOUT("Advertise 1000mb Half duplex request denied!\n");
1114 /* Do we want to advertise 1000 Mb Full Duplex? */
1115 if (phy->autoneg_advertised & ADVERTISE_1000_FULL) {
1116 DEBUGOUT("Advertise 1000mb Full duplex\n");
1117 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
1121 * Check for a software override of the flow control settings, and
1122 * setup the PHY advertisement registers accordingly. If
1123 * auto-negotiation is enabled, then software will have to set the
1124 * "PAUSE" bits to the correct value in the Auto-Negotiation
1125 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-
1126 * negotiation.
1128 * The possible values of the "fc" parameter are:
1129 * 0: Flow control is completely disabled
1130 * 1: Rx flow control is enabled (we can receive pause frames
1131 * but not send pause frames).
1132 * 2: Tx flow control is enabled (we can send pause frames
1133 * but we do not support receiving pause frames).
1134 * 3: Both Rx and Tx flow control (symmetric) are enabled.
1135 * other: No software override. The flow control configuration
1136 * in the EEPROM is used.
1138 switch (hw->fc.current_mode) {
1139 case e1000_fc_none:
1141 * Flow control (Rx & Tx) is completely disabled by a
1142 * software over-ride.
1144 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1145 break;
1146 case e1000_fc_rx_pause:
1148 * Rx Flow control is enabled, and Tx Flow control is
1149 * disabled, by a software over-ride.
1151 * Since there really isn't a way to advertise that we are
1152 * capable of Rx Pause ONLY, we will advertise that we
1153 * support both symmetric and asymmetric Rx PAUSE. Later
1154 * (in e1000_config_fc_after_link_up) we will disable the
1155 * hw's ability to send PAUSE frames.
1157 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1158 break;
1159 case e1000_fc_tx_pause:
1161 * Tx Flow control is enabled, and Rx Flow control is
1162 * disabled, by a software over-ride.
1164 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
1165 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
1166 break;
1167 case e1000_fc_full:
1169 * Flow control (both Rx and Tx) is enabled by a software
1170 * over-ride.
1172 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1173 break;
1174 default:
1175 DEBUGOUT("Flow control param set incorrectly\n");
1176 ret_val = -E1000_ERR_CONFIG;
1177 goto out;
1180 ret_val = phy->ops.write_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
1181 if (ret_val)
1182 goto out;
1184 DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
1186 if (phy->autoneg_mask & ADVERTISE_1000_FULL) {
1187 ret_val = phy->ops.write_reg(hw,
1188 PHY_1000T_CTRL,
1189 mii_1000t_ctrl_reg);
1190 if (ret_val)
1191 goto out;
1194 out:
1195 return ret_val;
1199 * e1000_setup_copper_link_generic - Configure copper link settings
1200 * @hw: pointer to the HW structure
1202 * Calls the appropriate function to configure the link for auto-neg or forced
1203 * speed and duplex. Then we check for link, once link is established calls
1204 * to configure collision distance and flow control are called. If link is
1205 * not established, we return -E1000_ERR_PHY (-2).
1207 s32 e1000_setup_copper_link_generic(struct e1000_hw *hw)
1209 s32 ret_val;
1210 bool link;
1212 DEBUGFUNC("e1000_setup_copper_link_generic");
1214 if (hw->mac.autoneg) {
1216 * Setup autoneg and flow control advertisement and perform
1217 * autonegotiation.
1219 ret_val = e1000_copper_link_autoneg(hw);
1220 if (ret_val)
1221 goto out;
1222 } else {
1224 * PHY will be set to 10H, 10F, 100H or 100F
1225 * depending on user settings.
1227 DEBUGOUT("Forcing Speed and Duplex\n");
1228 ret_val = hw->phy.ops.force_speed_duplex(hw);
1229 if (ret_val) {
1230 DEBUGOUT("Error Forcing Speed and Duplex\n");
1231 goto out;
1236 * Check link status. Wait up to 100 microseconds for link to become
1237 * valid.
1239 ret_val = e1000_phy_has_link_generic(hw,
1240 COPPER_LINK_UP_LIMIT,
1242 &link);
1243 if (ret_val)
1244 goto out;
1246 if (link) {
1247 DEBUGOUT("Valid link established!!!\n");
1248 e1000_config_collision_dist_generic(hw);
1249 ret_val = e1000_config_fc_after_link_up_generic(hw);
1250 } else {
1251 DEBUGOUT("Unable to establish link!!!\n");
1254 out:
1255 return ret_val;
1259 * e1000_phy_force_speed_duplex_igp - Force speed/duplex for igp PHY
1260 * @hw: pointer to the HW structure
1262 * Calls the PHY setup function to force speed and duplex. Clears the
1263 * auto-crossover to force MDI manually. Waits for link and returns
1264 * successful if link up is successful, else -E1000_ERR_PHY (-2).
1266 s32 e1000_phy_force_speed_duplex_igp(struct e1000_hw *hw)
1268 struct e1000_phy_info *phy = &hw->phy;
1269 s32 ret_val;
1270 u16 phy_data;
1271 bool link;
1273 DEBUGFUNC("e1000_phy_force_speed_duplex_igp");
1275 ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_data);
1276 if (ret_val)
1277 goto out;
1279 e1000_phy_force_speed_duplex_setup(hw, &phy_data);
1281 ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data);
1282 if (ret_val)
1283 goto out;
1286 * Clear Auto-Crossover to force MDI manually. IGP requires MDI
1287 * forced whenever speed and duplex are forced.
1289 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1290 if (ret_val)
1291 goto out;
1293 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1294 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1296 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1297 if (ret_val)
1298 goto out;
1300 DEBUGOUT1("IGP PSCR: %X\n", phy_data);
1302 usec_delay(1);
1304 if (phy->autoneg_wait_to_complete) {
1305 DEBUGOUT("Waiting for forced speed/duplex link on IGP phy.\n");
1307 ret_val = e1000_phy_has_link_generic(hw,
1308 PHY_FORCE_LIMIT,
1309 100000,
1310 &link);
1311 if (ret_val)
1312 goto out;
1314 if (!link)
1315 DEBUGOUT("Link taking longer than expected.\n");
1317 /* Try once more */
1318 ret_val = e1000_phy_has_link_generic(hw,
1319 PHY_FORCE_LIMIT,
1320 100000,
1321 &link);
1322 if (ret_val)
1323 goto out;
1326 out:
1327 return ret_val;
1331 * e1000_phy_force_speed_duplex_m88 - Force speed/duplex for m88 PHY
1332 * @hw: pointer to the HW structure
1334 * Calls the PHY setup function to force speed and duplex. Clears the
1335 * auto-crossover to force MDI manually. Resets the PHY to commit the
1336 * changes. If time expires while waiting for link up, we reset the DSP.
1337 * After reset, TX_CLK and CRS on Tx must be set. Return successful upon
1338 * successful completion, else return corresponding error code.
1340 s32 e1000_phy_force_speed_duplex_m88(struct e1000_hw *hw)
1342 struct e1000_phy_info *phy = &hw->phy;
1343 s32 ret_val;
1344 u16 phy_data;
1345 bool link;
1347 DEBUGFUNC("e1000_phy_force_speed_duplex_m88");
1350 * Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
1351 * forced whenever speed and duplex are forced.
1353 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1354 if (ret_val)
1355 goto out;
1357 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1358 ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1359 if (ret_val)
1360 goto out;
1362 DEBUGOUT1("M88E1000 PSCR: %X\n", phy_data);
1364 ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_data);
1365 if (ret_val)
1366 goto out;
1368 e1000_phy_force_speed_duplex_setup(hw, &phy_data);
1370 ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data);
1371 if (ret_val)
1372 goto out;
1374 /* Reset the phy to commit changes. */
1375 ret_val = hw->phy.ops.commit(hw);
1376 if (ret_val)
1377 goto out;
1379 if (phy->autoneg_wait_to_complete) {
1380 DEBUGOUT("Waiting for forced speed/duplex link on M88 phy.\n");
1382 ret_val = e1000_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
1383 100000, &link);
1384 if (ret_val)
1385 goto out;
1387 if (!link) {
1388 if (hw->phy.type != e1000_phy_m88) {
1389 DEBUGOUT("Link taking longer than expected.\n");
1390 } else {
1392 * We didn't get link.
1393 * Reset the DSP and cross our fingers.
1395 ret_val = phy->ops.write_reg(hw,
1396 M88E1000_PHY_PAGE_SELECT,
1397 0x001d);
1398 if (ret_val)
1399 goto out;
1400 ret_val = e1000_phy_reset_dsp_generic(hw);
1401 if (ret_val)
1402 goto out;
1406 /* Try once more */
1407 ret_val = e1000_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
1408 100000, &link);
1409 if (ret_val)
1410 goto out;
1413 if (hw->phy.type != e1000_phy_m88)
1414 goto out;
1416 ret_val = phy->ops.read_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1417 if (ret_val)
1418 goto out;
1421 * Resetting the phy means we need to re-force TX_CLK in the
1422 * Extended PHY Specific Control Register to 25MHz clock from
1423 * the reset value of 2.5MHz.
1425 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1426 ret_val = phy->ops.write_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1427 if (ret_val)
1428 goto out;
1431 * In addition, we must re-enable CRS on Tx for both half and full
1432 * duplex.
1434 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1435 if (ret_val)
1436 goto out;
1438 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1439 ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1441 out:
1442 return ret_val;
1446 * e1000_phy_force_speed_duplex_ife - Force PHY speed & duplex
1447 * @hw: pointer to the HW structure
1449 * Forces the speed and duplex settings of the PHY.
1450 * This is a function pointer entry point only called by
1451 * PHY setup routines.
1453 s32 e1000_phy_force_speed_duplex_ife(struct e1000_hw *hw)
1455 struct e1000_phy_info *phy = &hw->phy;
1456 s32 ret_val;
1457 u16 data;
1458 bool link;
1460 DEBUGFUNC("e1000_phy_force_speed_duplex_ife");
1462 ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &data);
1463 if (ret_val)
1464 goto out;
1466 e1000_phy_force_speed_duplex_setup(hw, &data);
1468 ret_val = phy->ops.write_reg(hw, PHY_CONTROL, data);
1469 if (ret_val)
1470 goto out;
1472 /* Disable MDI-X support for 10/100 */
1473 ret_val = phy->ops.read_reg(hw, IFE_PHY_MDIX_CONTROL, &data);
1474 if (ret_val)
1475 goto out;
1477 data &= ~IFE_PMC_AUTO_MDIX;
1478 data &= ~IFE_PMC_FORCE_MDIX;
1480 ret_val = phy->ops.write_reg(hw, IFE_PHY_MDIX_CONTROL, data);
1481 if (ret_val)
1482 goto out;
1484 DEBUGOUT1("IFE PMC: %X\n", data);
1486 usec_delay(1);
1488 if (phy->autoneg_wait_to_complete) {
1489 DEBUGOUT("Waiting for forced speed/duplex link on IFE phy.\n");
1491 ret_val = e1000_phy_has_link_generic(hw,
1492 PHY_FORCE_LIMIT,
1493 100000,
1494 &link);
1495 if (ret_val)
1496 goto out;
1498 if (!link)
1499 DEBUGOUT("Link taking longer than expected.\n");
1501 /* Try once more */
1502 ret_val = e1000_phy_has_link_generic(hw,
1503 PHY_FORCE_LIMIT,
1504 100000,
1505 &link);
1506 if (ret_val)
1507 goto out;
1510 out:
1511 return ret_val;
1515 * e1000_phy_force_speed_duplex_setup - Configure forced PHY speed/duplex
1516 * @hw: pointer to the HW structure
1517 * @phy_ctrl: pointer to current value of PHY_CONTROL
1519 * Forces speed and duplex on the PHY by doing the following: disable flow
1520 * control, force speed/duplex on the MAC, disable auto speed detection,
1521 * disable auto-negotiation, configure duplex, configure speed, configure
1522 * the collision distance, write configuration to CTRL register. The
1523 * caller must write to the PHY_CONTROL register for these settings to
1524 * take affect.
1526 void e1000_phy_force_speed_duplex_setup(struct e1000_hw *hw, u16 *phy_ctrl)
1528 struct e1000_mac_info *mac = &hw->mac;
1529 u32 ctrl;
1531 DEBUGFUNC("e1000_phy_force_speed_duplex_setup");
1533 /* Turn off flow control when forcing speed/duplex */
1534 hw->fc.current_mode = e1000_fc_none;
1536 /* Force speed/duplex on the mac */
1537 ctrl = E1000_READ_REG(hw, E1000_CTRL);
1538 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1539 ctrl &= ~E1000_CTRL_SPD_SEL;
1541 /* Disable Auto Speed Detection */
1542 ctrl &= ~E1000_CTRL_ASDE;
1544 /* Disable autoneg on the phy */
1545 *phy_ctrl &= ~MII_CR_AUTO_NEG_EN;
1547 /* Forcing Full or Half Duplex? */
1548 if (mac->forced_speed_duplex & E1000_ALL_HALF_DUPLEX) {
1549 ctrl &= ~E1000_CTRL_FD;
1550 *phy_ctrl &= ~MII_CR_FULL_DUPLEX;
1551 DEBUGOUT("Half Duplex\n");
1552 } else {
1553 ctrl |= E1000_CTRL_FD;
1554 *phy_ctrl |= MII_CR_FULL_DUPLEX;
1555 DEBUGOUT("Full Duplex\n");
1558 /* Forcing 10mb or 100mb? */
1559 if (mac->forced_speed_duplex & E1000_ALL_100_SPEED) {
1560 ctrl |= E1000_CTRL_SPD_100;
1561 *phy_ctrl |= MII_CR_SPEED_100;
1562 *phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
1563 DEBUGOUT("Forcing 100mb\n");
1564 } else {
1565 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1566 *phy_ctrl |= MII_CR_SPEED_10;
1567 *phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
1568 DEBUGOUT("Forcing 10mb\n");
1571 e1000_config_collision_dist_generic(hw);
1573 E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
1577 * e1000_set_d3_lplu_state_generic - Sets low power link up state for D3
1578 * @hw: pointer to the HW structure
1579 * @active: boolean used to enable/disable lplu
1581 * Success returns 0, Failure returns 1
1583 * The low power link up (lplu) state is set to the power management level D3
1584 * and SmartSpeed is disabled when active is true, else clear lplu for D3
1585 * and enable Smartspeed. LPLU and Smartspeed are mutually exclusive. LPLU
1586 * is used during Dx states where the power conservation is most important.
1587 * During driver activity, SmartSpeed should be enabled so performance is
1588 * maintained.
1590 s32 e1000_set_d3_lplu_state_generic(struct e1000_hw *hw, bool active)
1592 struct e1000_phy_info *phy = &hw->phy;
1593 s32 ret_val = E1000_SUCCESS;
1594 u16 data;
1596 DEBUGFUNC("e1000_set_d3_lplu_state_generic");
1598 if (!(hw->phy.ops.read_reg))
1599 goto out;
1601 ret_val = phy->ops.read_reg(hw, IGP02E1000_PHY_POWER_MGMT, &data);
1602 if (ret_val)
1603 goto out;
1605 if (!active) {
1606 data &= ~IGP02E1000_PM_D3_LPLU;
1607 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
1608 data);
1609 if (ret_val)
1610 goto out;
1612 * LPLU and SmartSpeed are mutually exclusive. LPLU is used
1613 * during Dx states where the power conservation is most
1614 * important. During driver activity we should enable
1615 * SmartSpeed, so performance is maintained.
1617 if (phy->smart_speed == e1000_smart_speed_on) {
1618 ret_val = phy->ops.read_reg(hw,
1619 IGP01E1000_PHY_PORT_CONFIG,
1620 &data);
1621 if (ret_val)
1622 goto out;
1624 data |= IGP01E1000_PSCFR_SMART_SPEED;
1625 ret_val = phy->ops.write_reg(hw,
1626 IGP01E1000_PHY_PORT_CONFIG,
1627 data);
1628 if (ret_val)
1629 goto out;
1630 } else if (phy->smart_speed == e1000_smart_speed_off) {
1631 ret_val = phy->ops.read_reg(hw,
1632 IGP01E1000_PHY_PORT_CONFIG,
1633 &data);
1634 if (ret_val)
1635 goto out;
1637 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1638 ret_val = phy->ops.write_reg(hw,
1639 IGP01E1000_PHY_PORT_CONFIG,
1640 data);
1641 if (ret_val)
1642 goto out;
1644 } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
1645 (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
1646 (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
1647 data |= IGP02E1000_PM_D3_LPLU;
1648 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
1649 data);
1650 if (ret_val)
1651 goto out;
1653 /* When LPLU is enabled, we should disable SmartSpeed */
1654 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1655 &data);
1656 if (ret_val)
1657 goto out;
1659 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1660 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1661 data);
1664 out:
1665 return ret_val;
1669 * e1000_check_downshift_generic - Checks whether a downshift in speed occurred
1670 * @hw: pointer to the HW structure
1672 * Success returns 0, Failure returns 1
1674 * A downshift is detected by querying the PHY link health.
1676 s32 e1000_check_downshift_generic(struct e1000_hw *hw)
1678 struct e1000_phy_info *phy = &hw->phy;
1679 s32 ret_val;
1680 u16 phy_data, offset, mask;
1682 DEBUGFUNC("e1000_check_downshift_generic");
1684 switch (phy->type) {
1685 case e1000_phy_m88:
1686 case e1000_phy_gg82563:
1687 offset = M88E1000_PHY_SPEC_STATUS;
1688 mask = M88E1000_PSSR_DOWNSHIFT;
1689 break;
1690 case e1000_phy_igp:
1691 case e1000_phy_igp_2:
1692 case e1000_phy_igp_3:
1693 offset = IGP01E1000_PHY_LINK_HEALTH;
1694 mask = IGP01E1000_PLHR_SS_DOWNGRADE;
1695 break;
1696 default:
1697 /* speed downshift not supported */
1698 phy->speed_downgraded = false;
1699 ret_val = E1000_SUCCESS;
1700 goto out;
1703 ret_val = phy->ops.read_reg(hw, offset, &phy_data);
1705 if (!ret_val)
1706 phy->speed_downgraded = (phy_data & mask) ? true : false;
1708 out:
1709 return ret_val;
1713 * e1000_check_polarity_m88 - Checks the polarity.
1714 * @hw: pointer to the HW structure
1716 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1718 * Polarity is determined based on the PHY specific status register.
1720 s32 e1000_check_polarity_m88(struct e1000_hw *hw)
1722 struct e1000_phy_info *phy = &hw->phy;
1723 s32 ret_val;
1724 u16 data;
1726 DEBUGFUNC("e1000_check_polarity_m88");
1728 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &data);
1730 if (!ret_val)
1731 phy->cable_polarity = (data & M88E1000_PSSR_REV_POLARITY)
1732 ? e1000_rev_polarity_reversed
1733 : e1000_rev_polarity_normal;
1735 return ret_val;
1739 * e1000_check_polarity_igp - Checks the polarity.
1740 * @hw: pointer to the HW structure
1742 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1744 * Polarity is determined based on the PHY port status register, and the
1745 * current speed (since there is no polarity at 100Mbps).
1747 s32 e1000_check_polarity_igp(struct e1000_hw *hw)
1749 struct e1000_phy_info *phy = &hw->phy;
1750 s32 ret_val;
1751 u16 data, offset, mask;
1753 DEBUGFUNC("e1000_check_polarity_igp");
1756 * Polarity is determined based on the speed of
1757 * our connection.
1759 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_STATUS, &data);
1760 if (ret_val)
1761 goto out;
1763 if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
1764 IGP01E1000_PSSR_SPEED_1000MBPS) {
1765 offset = IGP01E1000_PHY_PCS_INIT_REG;
1766 mask = IGP01E1000_PHY_POLARITY_MASK;
1767 } else {
1769 * This really only applies to 10Mbps since
1770 * there is no polarity for 100Mbps (always 0).
1772 offset = IGP01E1000_PHY_PORT_STATUS;
1773 mask = IGP01E1000_PSSR_POLARITY_REVERSED;
1776 ret_val = phy->ops.read_reg(hw, offset, &data);
1778 if (!ret_val)
1779 phy->cable_polarity = (data & mask)
1780 ? e1000_rev_polarity_reversed
1781 : e1000_rev_polarity_normal;
1783 out:
1784 return ret_val;
1788 * e1000_check_polarity_ife - Check cable polarity for IFE PHY
1789 * @hw: pointer to the HW structure
1791 * Polarity is determined on the polarity reversal feature being enabled.
1793 s32 e1000_check_polarity_ife(struct e1000_hw *hw)
1795 struct e1000_phy_info *phy = &hw->phy;
1796 s32 ret_val;
1797 u16 phy_data, offset, mask;
1799 DEBUGFUNC("e1000_check_polarity_ife");
1802 * Polarity is determined based on the reversal feature being enabled.
1804 if (phy->polarity_correction) {
1805 offset = IFE_PHY_EXTENDED_STATUS_CONTROL;
1806 mask = IFE_PESC_POLARITY_REVERSED;
1807 } else {
1808 offset = IFE_PHY_SPECIAL_CONTROL;
1809 mask = IFE_PSC_FORCE_POLARITY;
1812 ret_val = phy->ops.read_reg(hw, offset, &phy_data);
1814 if (!ret_val)
1815 phy->cable_polarity = (phy_data & mask)
1816 ? e1000_rev_polarity_reversed
1817 : e1000_rev_polarity_normal;
1819 return ret_val;
1823 * e1000_wait_autoneg_generic - Wait for auto-neg completion
1824 * @hw: pointer to the HW structure
1826 * Waits for auto-negotiation to complete or for the auto-negotiation time
1827 * limit to expire, which ever happens first.
1829 s32 e1000_wait_autoneg_generic(struct e1000_hw *hw)
1831 s32 ret_val = E1000_SUCCESS;
1832 u16 i, phy_status;
1834 DEBUGFUNC("e1000_wait_autoneg_generic");
1836 if (!(hw->phy.ops.read_reg))
1837 return E1000_SUCCESS;
1839 /* Break after autoneg completes or PHY_AUTO_NEG_LIMIT expires. */
1840 for (i = PHY_AUTO_NEG_LIMIT; i > 0; i--) {
1841 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
1842 if (ret_val)
1843 break;
1844 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
1845 if (ret_val)
1846 break;
1847 if (phy_status & MII_SR_AUTONEG_COMPLETE)
1848 break;
1849 msec_delay(100);
1853 * PHY_AUTO_NEG_TIME expiration doesn't guarantee auto-negotiation
1854 * has completed.
1856 return ret_val;
1860 * e1000_phy_has_link_generic - Polls PHY for link
1861 * @hw: pointer to the HW structure
1862 * @iterations: number of times to poll for link
1863 * @usec_interval: delay between polling attempts
1864 * @success: pointer to whether polling was successful or not
1866 * Polls the PHY status register for link, 'iterations' number of times.
1868 s32 e1000_phy_has_link_generic(struct e1000_hw *hw, u32 iterations,
1869 u32 usec_interval, bool *success)
1871 s32 ret_val = E1000_SUCCESS;
1872 u16 i, phy_status;
1874 DEBUGFUNC("e1000_phy_has_link_generic");
1876 if (!(hw->phy.ops.read_reg))
1877 return E1000_SUCCESS;
1879 for (i = 0; i < iterations; i++) {
1881 * Some PHYs require the PHY_STATUS register to be read
1882 * twice due to the link bit being sticky. No harm doing
1883 * it across the board.
1885 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
1886 if (ret_val)
1888 * If the first read fails, another entity may have
1889 * ownership of the resources, wait and try again to
1890 * see if they have relinquished the resources yet.
1892 usec_delay(usec_interval);
1893 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
1894 if (ret_val)
1895 break;
1896 if (phy_status & MII_SR_LINK_STATUS)
1897 break;
1898 if (usec_interval >= 1000)
1899 msec_delay_irq(usec_interval/1000);
1900 else
1901 usec_delay(usec_interval);
1904 *success = (i < iterations) ? true : false;
1906 return ret_val;
1910 * e1000_get_cable_length_m88 - Determine cable length for m88 PHY
1911 * @hw: pointer to the HW structure
1913 * Reads the PHY specific status register to retrieve the cable length
1914 * information. The cable length is determined by averaging the minimum and
1915 * maximum values to get the "average" cable length. The m88 PHY has four
1916 * possible cable length values, which are:
1917 * Register Value Cable Length
1918 * 0 < 50 meters
1919 * 1 50 - 80 meters
1920 * 2 80 - 110 meters
1921 * 3 110 - 140 meters
1922 * 4 > 140 meters
1924 s32 e1000_get_cable_length_m88(struct e1000_hw *hw)
1926 struct e1000_phy_info *phy = &hw->phy;
1927 s32 ret_val;
1928 u16 phy_data, index;
1930 DEBUGFUNC("e1000_get_cable_length_m88");
1932 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
1933 if (ret_val)
1934 goto out;
1936 index = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
1937 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
1938 if (index >= M88E1000_CABLE_LENGTH_TABLE_SIZE - 1) {
1939 ret_val = -E1000_ERR_PHY;
1940 goto out;
1943 phy->min_cable_length = e1000_m88_cable_length_table[index];
1944 phy->max_cable_length = e1000_m88_cable_length_table[index + 1];
1946 phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
1948 out:
1949 return ret_val;
1953 * e1000_get_cable_length_igp_2 - Determine cable length for igp2 PHY
1954 * @hw: pointer to the HW structure
1956 * The automatic gain control (agc) normalizes the amplitude of the
1957 * received signal, adjusting for the attenuation produced by the
1958 * cable. By reading the AGC registers, which represent the
1959 * combination of coarse and fine gain value, the value can be put
1960 * into a lookup table to obtain the approximate cable length
1961 * for each channel.
1963 s32 e1000_get_cable_length_igp_2(struct e1000_hw *hw)
1965 struct e1000_phy_info *phy = &hw->phy;
1966 s32 ret_val = E1000_SUCCESS;
1967 u16 phy_data, i, agc_value = 0;
1968 u16 cur_agc_index, max_agc_index = 0;
1969 u16 min_agc_index = IGP02E1000_CABLE_LENGTH_TABLE_SIZE - 1;
1970 static const u16 agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] = {
1971 IGP02E1000_PHY_AGC_A,
1972 IGP02E1000_PHY_AGC_B,
1973 IGP02E1000_PHY_AGC_C,
1974 IGP02E1000_PHY_AGC_D
1977 DEBUGFUNC("e1000_get_cable_length_igp_2");
1979 /* Read the AGC registers for all channels */
1980 for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
1981 ret_val = phy->ops.read_reg(hw, agc_reg_array[i], &phy_data);
1982 if (ret_val)
1983 goto out;
1986 * Getting bits 15:9, which represent the combination of
1987 * coarse and fine gain values. The result is a number
1988 * that can be put into the lookup table to obtain the
1989 * approximate cable length.
1991 cur_agc_index = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
1992 IGP02E1000_AGC_LENGTH_MASK;
1994 /* Array index bound check. */
1995 if ((cur_agc_index >= IGP02E1000_CABLE_LENGTH_TABLE_SIZE) ||
1996 (cur_agc_index == 0)) {
1997 ret_val = -E1000_ERR_PHY;
1998 goto out;
2001 /* Remove min & max AGC values from calculation. */
2002 if (e1000_igp_2_cable_length_table[min_agc_index] >
2003 e1000_igp_2_cable_length_table[cur_agc_index])
2004 min_agc_index = cur_agc_index;
2005 if (e1000_igp_2_cable_length_table[max_agc_index] <
2006 e1000_igp_2_cable_length_table[cur_agc_index])
2007 max_agc_index = cur_agc_index;
2009 agc_value += e1000_igp_2_cable_length_table[cur_agc_index];
2012 agc_value -= (e1000_igp_2_cable_length_table[min_agc_index] +
2013 e1000_igp_2_cable_length_table[max_agc_index]);
2014 agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
2016 /* Calculate cable length with the error range of +/- 10 meters. */
2017 phy->min_cable_length = ((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
2018 (agc_value - IGP02E1000_AGC_RANGE) : 0;
2019 phy->max_cable_length = agc_value + IGP02E1000_AGC_RANGE;
2021 phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
2023 out:
2024 return ret_val;
2028 * e1000_get_phy_info_m88 - Retrieve PHY information
2029 * @hw: pointer to the HW structure
2031 * Valid for only copper links. Read the PHY status register (sticky read)
2032 * to verify that link is up. Read the PHY special control register to
2033 * determine the polarity and 10base-T extended distance. Read the PHY
2034 * special status register to determine MDI/MDIx and current speed. If
2035 * speed is 1000, then determine cable length, local and remote receiver.
2037 s32 e1000_get_phy_info_m88(struct e1000_hw *hw)
2039 struct e1000_phy_info *phy = &hw->phy;
2040 s32 ret_val;
2041 u16 phy_data;
2042 bool link;
2044 DEBUGFUNC("e1000_get_phy_info_m88");
2046 if (phy->media_type != e1000_media_type_copper) {
2047 DEBUGOUT("Phy info is only valid for copper media\n");
2048 ret_val = -E1000_ERR_CONFIG;
2049 goto out;
2052 ret_val = e1000_phy_has_link_generic(hw, 1, 0, &link);
2053 if (ret_val)
2054 goto out;
2056 if (!link) {
2057 DEBUGOUT("Phy info is only valid if link is up\n");
2058 ret_val = -E1000_ERR_CONFIG;
2059 goto out;
2062 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
2063 if (ret_val)
2064 goto out;
2066 phy->polarity_correction = (phy_data & M88E1000_PSCR_POLARITY_REVERSAL)
2067 ? true : false;
2069 ret_val = e1000_check_polarity_m88(hw);
2070 if (ret_val)
2071 goto out;
2073 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
2074 if (ret_val)
2075 goto out;
2077 phy->is_mdix = (phy_data & M88E1000_PSSR_MDIX) ? true : false;
2079 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
2080 ret_val = hw->phy.ops.get_cable_length(hw);
2081 if (ret_val)
2082 goto out;
2084 ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &phy_data);
2085 if (ret_val)
2086 goto out;
2088 phy->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS)
2089 ? e1000_1000t_rx_status_ok
2090 : e1000_1000t_rx_status_not_ok;
2092 phy->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS)
2093 ? e1000_1000t_rx_status_ok
2094 : e1000_1000t_rx_status_not_ok;
2095 } else {
2096 /* Set values to "undefined" */
2097 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
2098 phy->local_rx = e1000_1000t_rx_status_undefined;
2099 phy->remote_rx = e1000_1000t_rx_status_undefined;
2102 out:
2103 return ret_val;
2107 * e1000_get_phy_info_igp - Retrieve igp PHY information
2108 * @hw: pointer to the HW structure
2110 * Read PHY status to determine if link is up. If link is up, then
2111 * set/determine 10base-T extended distance and polarity correction. Read
2112 * PHY port status to determine MDI/MDIx and speed. Based on the speed,
2113 * determine on the cable length, local and remote receiver.
2115 s32 e1000_get_phy_info_igp(struct e1000_hw *hw)
2117 struct e1000_phy_info *phy = &hw->phy;
2118 s32 ret_val;
2119 u16 data;
2120 bool link;
2122 DEBUGFUNC("e1000_get_phy_info_igp");
2124 ret_val = e1000_phy_has_link_generic(hw, 1, 0, &link);
2125 if (ret_val)
2126 goto out;
2128 if (!link) {
2129 DEBUGOUT("Phy info is only valid if link is up\n");
2130 ret_val = -E1000_ERR_CONFIG;
2131 goto out;
2134 phy->polarity_correction = true;
2136 ret_val = e1000_check_polarity_igp(hw);
2137 if (ret_val)
2138 goto out;
2140 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_STATUS, &data);
2141 if (ret_val)
2142 goto out;
2144 phy->is_mdix = (data & IGP01E1000_PSSR_MDIX) ? true : false;
2146 if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
2147 IGP01E1000_PSSR_SPEED_1000MBPS) {
2148 ret_val = phy->ops.get_cable_length(hw);
2149 if (ret_val)
2150 goto out;
2152 ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &data);
2153 if (ret_val)
2154 goto out;
2156 phy->local_rx = (data & SR_1000T_LOCAL_RX_STATUS)
2157 ? e1000_1000t_rx_status_ok
2158 : e1000_1000t_rx_status_not_ok;
2160 phy->remote_rx = (data & SR_1000T_REMOTE_RX_STATUS)
2161 ? e1000_1000t_rx_status_ok
2162 : e1000_1000t_rx_status_not_ok;
2163 } else {
2164 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
2165 phy->local_rx = e1000_1000t_rx_status_undefined;
2166 phy->remote_rx = e1000_1000t_rx_status_undefined;
2169 out:
2170 return ret_val;
2174 * e1000_get_phy_info_ife - Retrieves various IFE PHY states
2175 * @hw: pointer to the HW structure
2177 * Populates "phy" structure with various feature states.
2179 s32 e1000_get_phy_info_ife(struct e1000_hw *hw)
2181 struct e1000_phy_info *phy = &hw->phy;
2182 s32 ret_val;
2183 u16 data;
2184 bool link;
2186 DEBUGFUNC("e1000_get_phy_info_ife");
2188 ret_val = e1000_phy_has_link_generic(hw, 1, 0, &link);
2189 if (ret_val)
2190 goto out;
2192 if (!link) {
2193 DEBUGOUT("Phy info is only valid if link is up\n");
2194 ret_val = -E1000_ERR_CONFIG;
2195 goto out;
2198 ret_val = phy->ops.read_reg(hw, IFE_PHY_SPECIAL_CONTROL, &data);
2199 if (ret_val)
2200 goto out;
2201 phy->polarity_correction = (data & IFE_PSC_AUTO_POLARITY_DISABLE)
2202 ? false : true;
2204 if (phy->polarity_correction) {
2205 ret_val = e1000_check_polarity_ife(hw);
2206 if (ret_val)
2207 goto out;
2208 } else {
2209 /* Polarity is forced */
2210 phy->cable_polarity = (data & IFE_PSC_FORCE_POLARITY)
2211 ? e1000_rev_polarity_reversed
2212 : e1000_rev_polarity_normal;
2215 ret_val = phy->ops.read_reg(hw, IFE_PHY_MDIX_CONTROL, &data);
2216 if (ret_val)
2217 goto out;
2219 phy->is_mdix = (data & IFE_PMC_MDIX_STATUS) ? true : false;
2221 /* The following parameters are undefined for 10/100 operation. */
2222 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
2223 phy->local_rx = e1000_1000t_rx_status_undefined;
2224 phy->remote_rx = e1000_1000t_rx_status_undefined;
2226 out:
2227 return ret_val;
2231 * e1000_phy_sw_reset_generic - PHY software reset
2232 * @hw: pointer to the HW structure
2234 * Does a software reset of the PHY by reading the PHY control register and
2235 * setting/write the control register reset bit to the PHY.
2237 s32 e1000_phy_sw_reset_generic(struct e1000_hw *hw)
2239 s32 ret_val = E1000_SUCCESS;
2240 u16 phy_ctrl;
2242 DEBUGFUNC("e1000_phy_sw_reset_generic");
2244 if (!(hw->phy.ops.read_reg))
2245 goto out;
2247 ret_val = hw->phy.ops.read_reg(hw, PHY_CONTROL, &phy_ctrl);
2248 if (ret_val)
2249 goto out;
2251 phy_ctrl |= MII_CR_RESET;
2252 ret_val = hw->phy.ops.write_reg(hw, PHY_CONTROL, phy_ctrl);
2253 if (ret_val)
2254 goto out;
2256 usec_delay(1);
2258 out:
2259 return ret_val;
2263 * e1000_phy_hw_reset_generic - PHY hardware reset
2264 * @hw: pointer to the HW structure
2266 * Verify the reset block is not blocking us from resetting. Acquire
2267 * semaphore (if necessary) and read/set/write the device control reset
2268 * bit in the PHY. Wait the appropriate delay time for the device to
2269 * reset and release the semaphore (if necessary).
2271 s32 e1000_phy_hw_reset_generic(struct e1000_hw *hw)
2273 struct e1000_phy_info *phy = &hw->phy;
2274 s32 ret_val = E1000_SUCCESS;
2275 u32 ctrl;
2277 DEBUGFUNC("e1000_phy_hw_reset_generic");
2279 ret_val = phy->ops.check_reset_block(hw);
2280 if (ret_val) {
2281 ret_val = E1000_SUCCESS;
2282 goto out;
2285 ret_val = phy->ops.acquire(hw);
2286 if (ret_val)
2287 goto out;
2289 ctrl = E1000_READ_REG(hw, E1000_CTRL);
2290 E1000_WRITE_REG(hw, E1000_CTRL, ctrl | E1000_CTRL_PHY_RST);
2291 E1000_WRITE_FLUSH(hw);
2293 usec_delay(phy->reset_delay_us);
2295 E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
2296 E1000_WRITE_FLUSH(hw);
2298 usec_delay(150);
2300 phy->ops.release(hw);
2302 ret_val = phy->ops.get_cfg_done(hw);
2304 out:
2305 return ret_val;
2309 * e1000_get_cfg_done_generic - Generic configuration done
2310 * @hw: pointer to the HW structure
2312 * Generic function to wait 10 milli-seconds for configuration to complete
2313 * and return success.
2315 s32 e1000_get_cfg_done_generic(struct e1000_hw *hw)
2317 DEBUGFUNC("e1000_get_cfg_done_generic");
2319 msec_delay_irq(10);
2321 return E1000_SUCCESS;
2325 * e1000_phy_init_script_igp3 - Inits the IGP3 PHY
2326 * @hw: pointer to the HW structure
2328 * Initializes a Intel Gigabit PHY3 when an EEPROM is not present.
2330 s32 e1000_phy_init_script_igp3(struct e1000_hw *hw)
2332 DEBUGOUT("Running IGP 3 PHY init script\n");
2334 /* PHY init IGP 3 */
2335 /* Enable rise/fall, 10-mode work in class-A */
2336 hw->phy.ops.write_reg(hw, 0x2F5B, 0x9018);
2337 /* Remove all caps from Replica path filter */
2338 hw->phy.ops.write_reg(hw, 0x2F52, 0x0000);
2339 /* Bias trimming for ADC, AFE and Driver (Default) */
2340 hw->phy.ops.write_reg(hw, 0x2FB1, 0x8B24);
2341 /* Increase Hybrid poly bias */
2342 hw->phy.ops.write_reg(hw, 0x2FB2, 0xF8F0);
2343 /* Add 4% to Tx amplitude in Gig mode */
2344 hw->phy.ops.write_reg(hw, 0x2010, 0x10B0);
2345 /* Disable trimming (TTT) */
2346 hw->phy.ops.write_reg(hw, 0x2011, 0x0000);
2347 /* Poly DC correction to 94.6% + 2% for all channels */
2348 hw->phy.ops.write_reg(hw, 0x20DD, 0x249A);
2349 /* ABS DC correction to 95.9% */
2350 hw->phy.ops.write_reg(hw, 0x20DE, 0x00D3);
2351 /* BG temp curve trim */
2352 hw->phy.ops.write_reg(hw, 0x28B4, 0x04CE);
2353 /* Increasing ADC OPAMP stage 1 currents to max */
2354 hw->phy.ops.write_reg(hw, 0x2F70, 0x29E4);
2355 /* Force 1000 ( required for enabling PHY regs configuration) */
2356 hw->phy.ops.write_reg(hw, 0x0000, 0x0140);
2357 /* Set upd_freq to 6 */
2358 hw->phy.ops.write_reg(hw, 0x1F30, 0x1606);
2359 /* Disable NPDFE */
2360 hw->phy.ops.write_reg(hw, 0x1F31, 0xB814);
2361 /* Disable adaptive fixed FFE (Default) */
2362 hw->phy.ops.write_reg(hw, 0x1F35, 0x002A);
2363 /* Enable FFE hysteresis */
2364 hw->phy.ops.write_reg(hw, 0x1F3E, 0x0067);
2365 /* Fixed FFE for short cable lengths */
2366 hw->phy.ops.write_reg(hw, 0x1F54, 0x0065);
2367 /* Fixed FFE for medium cable lengths */
2368 hw->phy.ops.write_reg(hw, 0x1F55, 0x002A);
2369 /* Fixed FFE for long cable lengths */
2370 hw->phy.ops.write_reg(hw, 0x1F56, 0x002A);
2371 /* Enable Adaptive Clip Threshold */
2372 hw->phy.ops.write_reg(hw, 0x1F72, 0x3FB0);
2373 /* AHT reset limit to 1 */
2374 hw->phy.ops.write_reg(hw, 0x1F76, 0xC0FF);
2375 /* Set AHT master delay to 127 msec */
2376 hw->phy.ops.write_reg(hw, 0x1F77, 0x1DEC);
2377 /* Set scan bits for AHT */
2378 hw->phy.ops.write_reg(hw, 0x1F78, 0xF9EF);
2379 /* Set AHT Preset bits */
2380 hw->phy.ops.write_reg(hw, 0x1F79, 0x0210);
2381 /* Change integ_factor of channel A to 3 */
2382 hw->phy.ops.write_reg(hw, 0x1895, 0x0003);
2383 /* Change prop_factor of channels BCD to 8 */
2384 hw->phy.ops.write_reg(hw, 0x1796, 0x0008);
2385 /* Change cg_icount + enable integbp for channels BCD */
2386 hw->phy.ops.write_reg(hw, 0x1798, 0xD008);
2388 * Change cg_icount + enable integbp + change prop_factor_master
2389 * to 8 for channel A
2391 hw->phy.ops.write_reg(hw, 0x1898, 0xD918);
2392 /* Disable AHT in Slave mode on channel A */
2393 hw->phy.ops.write_reg(hw, 0x187A, 0x0800);
2395 * Enable LPLU and disable AN to 1000 in non-D0a states,
2396 * Enable SPD+B2B
2398 hw->phy.ops.write_reg(hw, 0x0019, 0x008D);
2399 /* Enable restart AN on an1000_dis change */
2400 hw->phy.ops.write_reg(hw, 0x001B, 0x2080);
2401 /* Enable wh_fifo read clock in 10/100 modes */
2402 hw->phy.ops.write_reg(hw, 0x0014, 0x0045);
2403 /* Restart AN, Speed selection is 1000 */
2404 hw->phy.ops.write_reg(hw, 0x0000, 0x1340);
2406 return E1000_SUCCESS;
2410 * e1000_get_phy_type_from_id - Get PHY type from id
2411 * @phy_id: phy_id read from the phy
2413 * Returns the phy type from the id.
2415 enum e1000_phy_type e1000_get_phy_type_from_id(u32 phy_id)
2417 enum e1000_phy_type phy_type = e1000_phy_unknown;
2419 switch (phy_id) {
2420 case M88E1000_I_PHY_ID:
2421 case M88E1000_E_PHY_ID:
2422 case M88E1111_I_PHY_ID:
2423 case M88E1011_I_PHY_ID:
2424 phy_type = e1000_phy_m88;
2425 break;
2426 case IGP01E1000_I_PHY_ID: /* IGP 1 & 2 share this */
2427 phy_type = e1000_phy_igp_2;
2428 break;
2429 case GG82563_E_PHY_ID:
2430 phy_type = e1000_phy_gg82563;
2431 break;
2432 case IGP03E1000_E_PHY_ID:
2433 phy_type = e1000_phy_igp_3;
2434 break;
2435 case IFE_E_PHY_ID:
2436 case IFE_PLUS_E_PHY_ID:
2437 case IFE_C_E_PHY_ID:
2438 phy_type = e1000_phy_ife;
2439 break;
2440 default:
2441 phy_type = e1000_phy_unknown;
2442 break;
2444 return phy_type;
2448 * e1000_determine_phy_address - Determines PHY address.
2449 * @hw: pointer to the HW structure
2451 * This uses a trial and error method to loop through possible PHY
2452 * addresses. It tests each by reading the PHY ID registers and
2453 * checking for a match.
2455 s32 e1000_determine_phy_address(struct e1000_hw *hw)
2457 s32 ret_val = -E1000_ERR_PHY_TYPE;
2458 u32 phy_addr = 0;
2459 u32 i;
2460 enum e1000_phy_type phy_type = e1000_phy_unknown;
2462 hw->phy.id = phy_type;
2464 for (phy_addr = 0; phy_addr < E1000_MAX_PHY_ADDR; phy_addr++) {
2465 hw->phy.addr = phy_addr;
2466 i = 0;
2468 do {
2469 e1000_get_phy_id(hw);
2470 phy_type = e1000_get_phy_type_from_id(hw->phy.id);
2473 * If phy_type is valid, break - we found our
2474 * PHY address
2476 if (phy_type != e1000_phy_unknown) {
2477 ret_val = E1000_SUCCESS;
2478 goto out;
2480 msec_delay(1);
2481 i++;
2482 } while (i < 10);
2485 out:
2486 return ret_val;
2490 * e1000_power_up_phy_copper - Restore copper link in case of PHY power down
2491 * @hw: pointer to the HW structure
2493 * In the case of a PHY power down to save power, or to turn off link during a
2494 * driver unload, or wake on lan is not enabled, restore the link to previous
2495 * settings.
2497 void e1000_power_up_phy_copper(struct e1000_hw *hw)
2499 u16 mii_reg = 0;
2501 /* The PHY will retain its settings across a power down/up cycle */
2502 hw->phy.ops.read_reg(hw, PHY_CONTROL, &mii_reg);
2503 mii_reg &= ~MII_CR_POWER_DOWN;
2504 hw->phy.ops.write_reg(hw, PHY_CONTROL, mii_reg);
2508 * e1000_power_down_phy_copper - Restore copper link in case of PHY power down
2509 * @hw: pointer to the HW structure
2511 * In the case of a PHY power down to save power, or to turn off link during a
2512 * driver unload, or wake on lan is not enabled, restore the link to previous
2513 * settings.
2515 void e1000_power_down_phy_copper(struct e1000_hw *hw)
2517 u16 mii_reg = 0;
2519 /* The PHY will retain its settings across a power down/up cycle */
2520 hw->phy.ops.read_reg(hw, PHY_CONTROL, &mii_reg);
2521 mii_reg |= MII_CR_POWER_DOWN;
2522 hw->phy.ops.write_reg(hw, PHY_CONTROL, mii_reg);
2523 msec_delay(1);