1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2001-2020 Intel Corporation
7 STATIC s32 e1000_wait_autoneg(struct e1000_hw *hw);
8 STATIC s32 e1000_access_phy_wakeup_reg_bm(struct e1000_hw *hw, u32 offset,
9 u16 *data, bool read, bool page_set);
10 STATIC u32 e1000_get_phy_addr_for_hv_page(u32 page);
11 STATIC s32 e1000_access_phy_debug_regs_hv(struct e1000_hw *hw, u32 offset,
12 u16 *data, bool read);
14 /* Cable length tables */
15 STATIC const u16 e1000_m88_cable_length_table[] = {
16 0, 50, 80, 110, 140, 140, E1000_CABLE_LENGTH_UNDEFINED };
17 #define M88E1000_CABLE_LENGTH_TABLE_SIZE \
18 (sizeof(e1000_m88_cable_length_table) / \
19 sizeof(e1000_m88_cable_length_table[0]))
21 STATIC const u16 e1000_igp_2_cable_length_table[] = {
22 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21, 0, 0, 0, 3,
23 6, 10, 13, 16, 19, 23, 26, 29, 32, 35, 38, 41, 6, 10, 14, 18, 22,
24 26, 30, 33, 37, 41, 44, 48, 51, 54, 58, 61, 21, 26, 31, 35, 40,
25 44, 49, 53, 57, 61, 65, 68, 72, 75, 79, 82, 40, 45, 51, 56, 61,
26 66, 70, 75, 79, 83, 87, 91, 94, 98, 101, 104, 60, 66, 72, 77, 82,
27 87, 92, 96, 100, 104, 108, 111, 114, 117, 119, 121, 83, 89, 95,
28 100, 105, 109, 113, 116, 119, 122, 124, 104, 109, 114, 118, 121,
30 #define IGP02E1000_CABLE_LENGTH_TABLE_SIZE \
31 (sizeof(e1000_igp_2_cable_length_table) / \
32 sizeof(e1000_igp_2_cable_length_table[0]))
35 * e1000_init_phy_ops_generic - Initialize PHY function pointers
36 * @hw: pointer to the HW structure
38 * Setups up the function pointers to no-op functions
40 void e1000_init_phy_ops_generic(struct e1000_hw *hw)
42 struct e1000_phy_info *phy = &hw->phy;
43 DEBUGFUNC("e1000_init_phy_ops_generic");
45 /* Initialize function pointers */
46 phy->ops.init_params = e1000_null_ops_generic;
47 phy->ops.acquire = e1000_null_ops_generic;
48 phy->ops.check_polarity = e1000_null_ops_generic;
49 phy->ops.check_reset_block = e1000_null_ops_generic;
50 phy->ops.commit = e1000_null_ops_generic;
51 phy->ops.force_speed_duplex = e1000_null_ops_generic;
52 phy->ops.get_cfg_done = e1000_null_ops_generic;
53 phy->ops.get_cable_length = e1000_null_ops_generic;
54 phy->ops.get_info = e1000_null_ops_generic;
55 phy->ops.set_page = e1000_null_set_page;
56 phy->ops.read_reg = e1000_null_read_reg;
57 phy->ops.read_reg_locked = e1000_null_read_reg;
58 phy->ops.read_reg_page = e1000_null_read_reg;
59 phy->ops.release = e1000_null_phy_generic;
60 phy->ops.reset = e1000_null_ops_generic;
61 phy->ops.set_d0_lplu_state = e1000_null_lplu_state;
62 phy->ops.set_d3_lplu_state = e1000_null_lplu_state;
63 phy->ops.write_reg = e1000_null_write_reg;
64 phy->ops.write_reg_locked = e1000_null_write_reg;
65 phy->ops.write_reg_page = e1000_null_write_reg;
66 phy->ops.power_up = e1000_null_phy_generic;
67 phy->ops.power_down = e1000_null_phy_generic;
68 phy->ops.read_i2c_byte = e1000_read_i2c_byte_null;
69 phy->ops.write_i2c_byte = e1000_write_i2c_byte_null;
70 phy->ops.cfg_on_link_up = e1000_null_ops_generic;
74 * e1000_null_set_page - No-op function, return 0
75 * @hw: pointer to the HW structure
76 * @data: dummy variable
78 s32 e1000_null_set_page(struct e1000_hw E1000_UNUSEDARG *hw,
79 u16 E1000_UNUSEDARG data)
81 DEBUGFUNC("e1000_null_set_page");
82 UNREFERENCED_2PARAMETER(hw, data);
87 * e1000_null_read_reg - No-op function, return 0
88 * @hw: pointer to the HW structure
89 * @offset: dummy variable
90 * @data: dummy variable
92 s32 e1000_null_read_reg(struct e1000_hw E1000_UNUSEDARG *hw,
93 u32 E1000_UNUSEDARG offset, u16 E1000_UNUSEDARG *data)
95 DEBUGFUNC("e1000_null_read_reg");
96 UNREFERENCED_3PARAMETER(hw, offset, data);
101 * e1000_null_phy_generic - No-op function, return void
102 * @hw: pointer to the HW structure
104 void e1000_null_phy_generic(struct e1000_hw E1000_UNUSEDARG *hw)
106 DEBUGFUNC("e1000_null_phy_generic");
107 UNREFERENCED_1PARAMETER(hw);
112 * e1000_null_lplu_state - No-op function, return 0
113 * @hw: pointer to the HW structure
114 * @active: dummy variable
116 s32 e1000_null_lplu_state(struct e1000_hw E1000_UNUSEDARG *hw,
117 bool E1000_UNUSEDARG active)
119 DEBUGFUNC("e1000_null_lplu_state");
120 UNREFERENCED_2PARAMETER(hw, active);
121 return E1000_SUCCESS;
125 * e1000_null_write_reg - No-op function, return 0
126 * @hw: pointer to the HW structure
127 * @offset: dummy variable
128 * @data: dummy variable
130 s32 e1000_null_write_reg(struct e1000_hw E1000_UNUSEDARG *hw,
131 u32 E1000_UNUSEDARG offset, u16 E1000_UNUSEDARG data)
133 DEBUGFUNC("e1000_null_write_reg");
134 UNREFERENCED_3PARAMETER(hw, offset, data);
135 return E1000_SUCCESS;
139 * e1000_read_i2c_byte_null - No-op function, return 0
140 * @hw: pointer to hardware structure
141 * @byte_offset: byte offset to write
142 * @dev_addr: device address
143 * @data: data value read
146 s32 e1000_read_i2c_byte_null(struct e1000_hw E1000_UNUSEDARG *hw,
147 u8 E1000_UNUSEDARG byte_offset,
148 u8 E1000_UNUSEDARG dev_addr,
149 u8 E1000_UNUSEDARG *data)
151 DEBUGFUNC("e1000_read_i2c_byte_null");
152 UNREFERENCED_4PARAMETER(hw, byte_offset, dev_addr, data);
153 return E1000_SUCCESS;
157 * e1000_write_i2c_byte_null - No-op function, return 0
158 * @hw: pointer to hardware structure
159 * @byte_offset: byte offset to write
160 * @dev_addr: device address
161 * @data: data value to write
164 s32 e1000_write_i2c_byte_null(struct e1000_hw E1000_UNUSEDARG *hw,
165 u8 E1000_UNUSEDARG byte_offset,
166 u8 E1000_UNUSEDARG dev_addr,
167 u8 E1000_UNUSEDARG data)
169 DEBUGFUNC("e1000_write_i2c_byte_null");
170 UNREFERENCED_4PARAMETER(hw, byte_offset, dev_addr, data);
171 return E1000_SUCCESS;
175 * e1000_check_reset_block_generic - Check if PHY reset is blocked
176 * @hw: pointer to the HW structure
178 * Read the PHY management control register and check whether a PHY reset
179 * is blocked. If a reset is not blocked return E1000_SUCCESS, otherwise
180 * return E1000_BLK_PHY_RESET (12).
182 s32 e1000_check_reset_block_generic(struct e1000_hw *hw)
186 DEBUGFUNC("e1000_check_reset_block");
188 manc = E1000_READ_REG(hw, E1000_MANC);
190 return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
191 E1000_BLK_PHY_RESET : E1000_SUCCESS;
195 * e1000_get_phy_id - Retrieve the PHY ID and revision
196 * @hw: pointer to the HW structure
198 * Reads the PHY registers and stores the PHY ID and possibly the PHY
199 * revision in the hardware structure.
201 s32 e1000_get_phy_id(struct e1000_hw *hw)
203 struct e1000_phy_info *phy = &hw->phy;
204 s32 ret_val = E1000_SUCCESS;
208 DEBUGFUNC("e1000_get_phy_id");
210 if (!phy->ops.read_reg)
211 return E1000_SUCCESS;
213 while (retry_count < 2) {
214 ret_val = phy->ops.read_reg(hw, PHY_ID1, &phy_id);
218 phy->id = (u32)(phy_id << 16);
220 ret_val = phy->ops.read_reg(hw, PHY_ID2, &phy_id);
224 phy->id |= (u32)(phy_id & PHY_REVISION_MASK);
225 phy->revision = (u32)(phy_id & ~PHY_REVISION_MASK);
227 if (phy->id != 0 && phy->id != PHY_REVISION_MASK)
228 return E1000_SUCCESS;
233 return E1000_SUCCESS;
237 * e1000_phy_reset_dsp_generic - Reset PHY DSP
238 * @hw: pointer to the HW structure
240 * Reset the digital signal processor.
242 s32 e1000_phy_reset_dsp_generic(struct e1000_hw *hw)
246 DEBUGFUNC("e1000_phy_reset_dsp_generic");
248 if (!hw->phy.ops.write_reg)
249 return E1000_SUCCESS;
251 ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xC1);
255 return hw->phy.ops.write_reg(hw, M88E1000_PHY_GEN_CONTROL, 0);
259 * e1000_read_phy_reg_mdic - Read MDI control register
260 * @hw: pointer to the HW structure
261 * @offset: register offset to be read
262 * @data: pointer to the read data
264 * Reads the MDI control register in the PHY at offset and stores the
265 * information read to data.
267 s32 e1000_read_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 *data)
269 struct e1000_phy_info *phy = &hw->phy;
272 DEBUGFUNC("e1000_read_phy_reg_mdic");
274 if (offset > MAX_PHY_REG_ADDRESS) {
275 DEBUGOUT1("PHY Address %d is out of range\n", offset);
276 return -E1000_ERR_PARAM;
279 /* Set up Op-code, Phy Address, and register offset in the MDI
280 * Control register. The MAC will take care of interfacing with the
281 * PHY to retrieve the desired data.
283 mdic = ((offset << E1000_MDIC_REG_SHIFT) |
284 (phy->addr << E1000_MDIC_PHY_SHIFT) |
285 (E1000_MDIC_OP_READ));
287 E1000_WRITE_REG(hw, E1000_MDIC, mdic);
289 /* Poll the ready bit to see if the MDI read completed
290 * Increasing the time out as testing showed failures with
293 for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
295 mdic = E1000_READ_REG(hw, E1000_MDIC);
296 if (mdic & E1000_MDIC_READY)
299 if (!(mdic & E1000_MDIC_READY)) {
300 DEBUGOUT("MDI Read did not complete\n");
301 return -E1000_ERR_PHY;
303 if (mdic & E1000_MDIC_ERROR) {
304 DEBUGOUT("MDI Error\n");
305 return -E1000_ERR_PHY;
307 if (((mdic & E1000_MDIC_REG_MASK) >> E1000_MDIC_REG_SHIFT) != offset) {
308 DEBUGOUT2("MDI Read offset error - requested %d, returned %d\n",
310 (mdic & E1000_MDIC_REG_MASK) >> E1000_MDIC_REG_SHIFT);
311 return -E1000_ERR_PHY;
315 /* Allow some time after each MDIC transaction to avoid
316 * reading duplicate data in the next MDIC transaction.
318 if (hw->mac.type == e1000_pch2lan)
321 return E1000_SUCCESS;
325 * e1000_write_phy_reg_mdic - Write MDI control register
326 * @hw: pointer to the HW structure
327 * @offset: register offset to write to
328 * @data: data to write to register at offset
330 * Writes data to MDI control register in the PHY at offset.
332 s32 e1000_write_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 data)
334 struct e1000_phy_info *phy = &hw->phy;
337 DEBUGFUNC("e1000_write_phy_reg_mdic");
339 if (offset > MAX_PHY_REG_ADDRESS) {
340 DEBUGOUT1("PHY Address %d is out of range\n", offset);
341 return -E1000_ERR_PARAM;
344 /* Set up Op-code, Phy Address, and register offset in the MDI
345 * Control register. The MAC will take care of interfacing with the
346 * PHY to retrieve the desired data.
348 mdic = (((u32)data) |
349 (offset << E1000_MDIC_REG_SHIFT) |
350 (phy->addr << E1000_MDIC_PHY_SHIFT) |
351 (E1000_MDIC_OP_WRITE));
353 E1000_WRITE_REG(hw, E1000_MDIC, mdic);
355 /* Poll the ready bit to see if the MDI read completed
356 * Increasing the time out as testing showed failures with
359 for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
361 mdic = E1000_READ_REG(hw, E1000_MDIC);
362 if (mdic & E1000_MDIC_READY)
365 if (!(mdic & E1000_MDIC_READY)) {
366 DEBUGOUT("MDI Write did not complete\n");
367 return -E1000_ERR_PHY;
369 if (mdic & E1000_MDIC_ERROR) {
370 DEBUGOUT("MDI Error\n");
371 return -E1000_ERR_PHY;
373 if (((mdic & E1000_MDIC_REG_MASK) >> E1000_MDIC_REG_SHIFT) != offset) {
374 DEBUGOUT2("MDI Write offset error - requested %d, returned %d\n",
376 (mdic & E1000_MDIC_REG_MASK) >> E1000_MDIC_REG_SHIFT);
377 return -E1000_ERR_PHY;
380 /* Allow some time after each MDIC transaction to avoid
381 * reading duplicate data in the next MDIC transaction.
383 if (hw->mac.type == e1000_pch2lan)
386 return E1000_SUCCESS;
390 * e1000_read_phy_reg_i2c - Read PHY register using i2c
391 * @hw: pointer to the HW structure
392 * @offset: register offset to be read
393 * @data: pointer to the read data
395 * Reads the PHY register at offset using the i2c interface and stores the
396 * retrieved information in data.
398 s32 e1000_read_phy_reg_i2c(struct e1000_hw *hw, u32 offset, u16 *data)
400 struct e1000_phy_info *phy = &hw->phy;
403 DEBUGFUNC("e1000_read_phy_reg_i2c");
405 /* Set up Op-code, Phy Address, and register address in the I2CCMD
406 * register. The MAC will take care of interfacing with the
407 * PHY to retrieve the desired data.
409 i2ccmd = ((offset << E1000_I2CCMD_REG_ADDR_SHIFT) |
410 (phy->addr << E1000_I2CCMD_PHY_ADDR_SHIFT) |
411 (E1000_I2CCMD_OPCODE_READ));
413 E1000_WRITE_REG(hw, E1000_I2CCMD, i2ccmd);
415 /* Poll the ready bit to see if the I2C read completed */
416 for (i = 0; i < E1000_I2CCMD_PHY_TIMEOUT; i++) {
418 i2ccmd = E1000_READ_REG(hw, E1000_I2CCMD);
419 if (i2ccmd & E1000_I2CCMD_READY)
422 if (!(i2ccmd & E1000_I2CCMD_READY)) {
423 DEBUGOUT("I2CCMD Read did not complete\n");
424 return -E1000_ERR_PHY;
426 if (i2ccmd & E1000_I2CCMD_ERROR) {
427 DEBUGOUT("I2CCMD Error bit set\n");
428 return -E1000_ERR_PHY;
431 /* Need to byte-swap the 16-bit value. */
432 *data = ((i2ccmd >> 8) & 0x00FF) | ((i2ccmd << 8) & 0xFF00);
434 return E1000_SUCCESS;
438 * e1000_write_phy_reg_i2c - Write PHY register using i2c
439 * @hw: pointer to the HW structure
440 * @offset: register offset to write to
441 * @data: data to write at register offset
443 * Writes the data to PHY register at the offset using the i2c interface.
445 s32 e1000_write_phy_reg_i2c(struct e1000_hw *hw, u32 offset, u16 data)
447 struct e1000_phy_info *phy = &hw->phy;
449 u16 phy_data_swapped;
451 DEBUGFUNC("e1000_write_phy_reg_i2c");
453 /* Prevent overwritting SFP I2C EEPROM which is at A0 address.*/
454 if ((hw->phy.addr == 0) || (hw->phy.addr > 7)) {
455 DEBUGOUT1("PHY I2C Address %d is out of range.\n",
457 return -E1000_ERR_CONFIG;
460 /* Swap the data bytes for the I2C interface */
461 phy_data_swapped = ((data >> 8) & 0x00FF) | ((data << 8) & 0xFF00);
463 /* Set up Op-code, Phy Address, and register address in the I2CCMD
464 * register. The MAC will take care of interfacing with the
465 * PHY to retrieve the desired data.
467 i2ccmd = ((offset << E1000_I2CCMD_REG_ADDR_SHIFT) |
468 (phy->addr << E1000_I2CCMD_PHY_ADDR_SHIFT) |
469 E1000_I2CCMD_OPCODE_WRITE |
472 E1000_WRITE_REG(hw, E1000_I2CCMD, i2ccmd);
474 /* Poll the ready bit to see if the I2C read completed */
475 for (i = 0; i < E1000_I2CCMD_PHY_TIMEOUT; i++) {
477 i2ccmd = E1000_READ_REG(hw, E1000_I2CCMD);
478 if (i2ccmd & E1000_I2CCMD_READY)
481 if (!(i2ccmd & E1000_I2CCMD_READY)) {
482 DEBUGOUT("I2CCMD Write did not complete\n");
483 return -E1000_ERR_PHY;
485 if (i2ccmd & E1000_I2CCMD_ERROR) {
486 DEBUGOUT("I2CCMD Error bit set\n");
487 return -E1000_ERR_PHY;
490 return E1000_SUCCESS;
494 * e1000_read_sfp_data_byte - Reads SFP module data.
495 * @hw: pointer to the HW structure
496 * @offset: byte location offset to be read
497 * @data: read data buffer pointer
499 * Reads one byte from SFP module data stored
500 * in SFP resided EEPROM memory or SFP diagnostic area.
501 * Function should be called with
502 * E1000_I2CCMD_SFP_DATA_ADDR(<byte offset>) for SFP module database access
503 * E1000_I2CCMD_SFP_DIAG_ADDR(<byte offset>) for SFP diagnostics parameters
506 s32 e1000_read_sfp_data_byte(struct e1000_hw *hw, u16 offset, u8 *data)
512 DEBUGFUNC("e1000_read_sfp_data_byte");
514 if (offset > E1000_I2CCMD_SFP_DIAG_ADDR(255)) {
515 DEBUGOUT("I2CCMD command address exceeds upper limit\n");
516 return -E1000_ERR_PHY;
519 /* Set up Op-code, EEPROM Address,in the I2CCMD
520 * register. The MAC will take care of interfacing with the
521 * EEPROM to retrieve the desired data.
523 i2ccmd = ((offset << E1000_I2CCMD_REG_ADDR_SHIFT) |
524 E1000_I2CCMD_OPCODE_READ);
526 E1000_WRITE_REG(hw, E1000_I2CCMD, i2ccmd);
528 /* Poll the ready bit to see if the I2C read completed */
529 for (i = 0; i < E1000_I2CCMD_PHY_TIMEOUT; i++) {
531 data_local = E1000_READ_REG(hw, E1000_I2CCMD);
532 if (data_local & E1000_I2CCMD_READY)
535 if (!(data_local & E1000_I2CCMD_READY)) {
536 DEBUGOUT("I2CCMD Read did not complete\n");
537 return -E1000_ERR_PHY;
539 if (data_local & E1000_I2CCMD_ERROR) {
540 DEBUGOUT("I2CCMD Error bit set\n");
541 return -E1000_ERR_PHY;
543 *data = (u8) data_local & 0xFF;
545 return E1000_SUCCESS;
549 * e1000_write_sfp_data_byte - Writes SFP module data.
550 * @hw: pointer to the HW structure
551 * @offset: byte location offset to write to
552 * @data: data to write
554 * Writes one byte to SFP module data stored
555 * in SFP resided EEPROM memory or SFP diagnostic area.
556 * Function should be called with
557 * E1000_I2CCMD_SFP_DATA_ADDR(<byte offset>) for SFP module database access
558 * E1000_I2CCMD_SFP_DIAG_ADDR(<byte offset>) for SFP diagnostics parameters
561 s32 e1000_write_sfp_data_byte(struct e1000_hw *hw, u16 offset, u8 data)
567 DEBUGFUNC("e1000_write_sfp_data_byte");
569 if (offset > E1000_I2CCMD_SFP_DIAG_ADDR(255)) {
570 DEBUGOUT("I2CCMD command address exceeds upper limit\n");
571 return -E1000_ERR_PHY;
573 /* The programming interface is 16 bits wide
574 * so we need to read the whole word first
575 * then update appropriate byte lane and write
576 * the updated word back.
578 /* Set up Op-code, EEPROM Address,in the I2CCMD
579 * register. The MAC will take care of interfacing
580 * with an EEPROM to write the data given.
582 i2ccmd = ((offset << E1000_I2CCMD_REG_ADDR_SHIFT) |
583 E1000_I2CCMD_OPCODE_READ);
584 /* Set a command to read single word */
585 E1000_WRITE_REG(hw, E1000_I2CCMD, i2ccmd);
586 for (i = 0; i < E1000_I2CCMD_PHY_TIMEOUT; i++) {
588 /* Poll the ready bit to see if lastly
589 * launched I2C operation completed
591 i2ccmd = E1000_READ_REG(hw, E1000_I2CCMD);
592 if (i2ccmd & E1000_I2CCMD_READY) {
593 /* Check if this is READ or WRITE phase */
594 if ((i2ccmd & E1000_I2CCMD_OPCODE_READ) ==
595 E1000_I2CCMD_OPCODE_READ) {
596 /* Write the selected byte
597 * lane and update whole word
599 data_local = i2ccmd & 0xFF00;
600 data_local |= (u32)data;
602 E1000_I2CCMD_REG_ADDR_SHIFT) |
603 E1000_I2CCMD_OPCODE_WRITE | data_local);
604 E1000_WRITE_REG(hw, E1000_I2CCMD, i2ccmd);
610 if (!(i2ccmd & E1000_I2CCMD_READY)) {
611 DEBUGOUT("I2CCMD Write did not complete\n");
612 return -E1000_ERR_PHY;
614 if (i2ccmd & E1000_I2CCMD_ERROR) {
615 DEBUGOUT("I2CCMD Error bit set\n");
616 return -E1000_ERR_PHY;
618 return E1000_SUCCESS;
622 * e1000_read_phy_reg_m88 - Read m88 PHY register
623 * @hw: pointer to the HW structure
624 * @offset: register offset to be read
625 * @data: pointer to the read data
627 * Acquires semaphore, if necessary, then reads the PHY register at offset
628 * and storing the retrieved information in data. Release any acquired
629 * semaphores before exiting.
631 s32 e1000_read_phy_reg_m88(struct e1000_hw *hw, u32 offset, u16 *data)
635 DEBUGFUNC("e1000_read_phy_reg_m88");
637 if (!hw->phy.ops.acquire)
638 return E1000_SUCCESS;
640 ret_val = hw->phy.ops.acquire(hw);
644 ret_val = e1000_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
647 hw->phy.ops.release(hw);
653 * e1000_write_phy_reg_m88 - Write m88 PHY register
654 * @hw: pointer to the HW structure
655 * @offset: register offset to write to
656 * @data: data to write at register offset
658 * Acquires semaphore, if necessary, then writes the data to PHY register
659 * at the offset. Release any acquired semaphores before exiting.
661 s32 e1000_write_phy_reg_m88(struct e1000_hw *hw, u32 offset, u16 data)
665 DEBUGFUNC("e1000_write_phy_reg_m88");
667 if (!hw->phy.ops.acquire)
668 return E1000_SUCCESS;
670 ret_val = hw->phy.ops.acquire(hw);
674 ret_val = e1000_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
677 hw->phy.ops.release(hw);
683 * e1000_set_page_igp - Set page as on IGP-like PHY(s)
684 * @hw: pointer to the HW structure
685 * @page: page to set (shifted left when necessary)
687 * Sets PHY page required for PHY register access. Assumes semaphore is
688 * already acquired. Note, this function sets phy.addr to 1 so the caller
689 * must set it appropriately (if necessary) after this function returns.
691 s32 e1000_set_page_igp(struct e1000_hw *hw, u16 page)
693 DEBUGFUNC("e1000_set_page_igp");
695 DEBUGOUT1("Setting page 0x%x\n", page);
699 return e1000_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT, page);
703 * __e1000_read_phy_reg_igp - Read igp PHY register
704 * @hw: pointer to the HW structure
705 * @offset: register offset to be read
706 * @data: pointer to the read data
707 * @locked: semaphore has already been acquired or not
709 * Acquires semaphore, if necessary, then reads the PHY register at offset
710 * and stores the retrieved information in data. Release any acquired
711 * semaphores before exiting.
713 STATIC s32 __e1000_read_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 *data,
716 s32 ret_val = E1000_SUCCESS;
718 DEBUGFUNC("__e1000_read_phy_reg_igp");
721 if (!hw->phy.ops.acquire)
722 return E1000_SUCCESS;
724 ret_val = hw->phy.ops.acquire(hw);
729 if (offset > MAX_PHY_MULTI_PAGE_REG)
730 ret_val = e1000_write_phy_reg_mdic(hw,
731 IGP01E1000_PHY_PAGE_SELECT,
734 ret_val = e1000_read_phy_reg_mdic(hw,
735 MAX_PHY_REG_ADDRESS & offset,
738 hw->phy.ops.release(hw);
744 * e1000_read_phy_reg_igp - Read igp PHY register
745 * @hw: pointer to the HW structure
746 * @offset: register offset to be read
747 * @data: pointer to the read data
749 * Acquires semaphore then reads the PHY register at offset and stores the
750 * retrieved information in data.
751 * Release the acquired semaphore before exiting.
753 s32 e1000_read_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 *data)
755 return __e1000_read_phy_reg_igp(hw, offset, data, false);
759 * e1000_read_phy_reg_igp_locked - Read igp PHY register
760 * @hw: pointer to the HW structure
761 * @offset: register offset to be read
762 * @data: pointer to the read data
764 * Reads the PHY register at offset and stores the retrieved information
765 * in data. Assumes semaphore already acquired.
767 s32 e1000_read_phy_reg_igp_locked(struct e1000_hw *hw, u32 offset, u16 *data)
769 return __e1000_read_phy_reg_igp(hw, offset, data, true);
773 * e1000_write_phy_reg_igp - Write igp PHY register
774 * @hw: pointer to the HW structure
775 * @offset: register offset to write to
776 * @data: data to write at register offset
777 * @locked: semaphore has already been acquired or not
779 * Acquires semaphore, if necessary, then writes the data to PHY register
780 * at the offset. Release any acquired semaphores before exiting.
782 STATIC s32 __e1000_write_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 data,
785 s32 ret_val = E1000_SUCCESS;
787 DEBUGFUNC("e1000_write_phy_reg_igp");
790 if (!hw->phy.ops.acquire)
791 return E1000_SUCCESS;
793 ret_val = hw->phy.ops.acquire(hw);
798 if (offset > MAX_PHY_MULTI_PAGE_REG)
799 ret_val = e1000_write_phy_reg_mdic(hw,
800 IGP01E1000_PHY_PAGE_SELECT,
803 ret_val = e1000_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS &
807 hw->phy.ops.release(hw);
813 * e1000_write_phy_reg_igp - Write igp PHY register
814 * @hw: pointer to the HW structure
815 * @offset: register offset to write to
816 * @data: data to write at register offset
818 * Acquires semaphore then writes the data to PHY register
819 * at the offset. Release any acquired semaphores before exiting.
821 s32 e1000_write_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 data)
823 return __e1000_write_phy_reg_igp(hw, offset, data, false);
827 * e1000_write_phy_reg_igp_locked - Write igp PHY register
828 * @hw: pointer to the HW structure
829 * @offset: register offset to write to
830 * @data: data to write at register offset
832 * Writes the data to PHY register at the offset.
833 * Assumes semaphore already acquired.
835 s32 e1000_write_phy_reg_igp_locked(struct e1000_hw *hw, u32 offset, u16 data)
837 return __e1000_write_phy_reg_igp(hw, offset, data, true);
841 * __e1000_read_kmrn_reg - Read kumeran register
842 * @hw: pointer to the HW structure
843 * @offset: register offset to be read
844 * @data: pointer to the read data
845 * @locked: semaphore has already been acquired or not
847 * Acquires semaphore, if necessary. Then reads the PHY register at offset
848 * using the kumeran interface. The information retrieved is stored in data.
849 * Release any acquired semaphores before exiting.
851 STATIC s32 __e1000_read_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 *data,
856 DEBUGFUNC("__e1000_read_kmrn_reg");
859 s32 ret_val = E1000_SUCCESS;
861 if (!hw->phy.ops.acquire)
862 return E1000_SUCCESS;
864 ret_val = hw->phy.ops.acquire(hw);
869 kmrnctrlsta = ((offset << E1000_KMRNCTRLSTA_OFFSET_SHIFT) &
870 E1000_KMRNCTRLSTA_OFFSET) | E1000_KMRNCTRLSTA_REN;
871 E1000_WRITE_REG(hw, E1000_KMRNCTRLSTA, kmrnctrlsta);
872 E1000_WRITE_FLUSH(hw);
876 kmrnctrlsta = E1000_READ_REG(hw, E1000_KMRNCTRLSTA);
877 *data = (u16)kmrnctrlsta;
880 hw->phy.ops.release(hw);
882 return E1000_SUCCESS;
886 * e1000_read_kmrn_reg_generic - Read kumeran register
887 * @hw: pointer to the HW structure
888 * @offset: register offset to be read
889 * @data: pointer to the read data
891 * Acquires semaphore then reads the PHY register at offset using the
892 * kumeran interface. The information retrieved is stored in data.
893 * Release the acquired semaphore before exiting.
895 s32 e1000_read_kmrn_reg_generic(struct e1000_hw *hw, u32 offset, u16 *data)
897 return __e1000_read_kmrn_reg(hw, offset, data, false);
901 * e1000_read_kmrn_reg_locked - Read kumeran register
902 * @hw: pointer to the HW structure
903 * @offset: register offset to be read
904 * @data: pointer to the read data
906 * Reads the PHY register at offset using the kumeran interface. The
907 * information retrieved is stored in data.
908 * Assumes semaphore already acquired.
910 s32 e1000_read_kmrn_reg_locked(struct e1000_hw *hw, u32 offset, u16 *data)
912 return __e1000_read_kmrn_reg(hw, offset, data, true);
916 * __e1000_write_kmrn_reg - Write kumeran register
917 * @hw: pointer to the HW structure
918 * @offset: register offset to write to
919 * @data: data to write at register offset
920 * @locked: semaphore has already been acquired or not
922 * Acquires semaphore, if necessary. Then write the data to PHY register
923 * at the offset using the kumeran interface. Release any acquired semaphores
926 STATIC s32 __e1000_write_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 data,
931 DEBUGFUNC("e1000_write_kmrn_reg_generic");
934 s32 ret_val = E1000_SUCCESS;
936 if (!hw->phy.ops.acquire)
937 return E1000_SUCCESS;
939 ret_val = hw->phy.ops.acquire(hw);
944 kmrnctrlsta = ((offset << E1000_KMRNCTRLSTA_OFFSET_SHIFT) &
945 E1000_KMRNCTRLSTA_OFFSET) | data;
946 E1000_WRITE_REG(hw, E1000_KMRNCTRLSTA, kmrnctrlsta);
947 E1000_WRITE_FLUSH(hw);
952 hw->phy.ops.release(hw);
954 return E1000_SUCCESS;
958 * e1000_write_kmrn_reg_generic - Write kumeran register
959 * @hw: pointer to the HW structure
960 * @offset: register offset to write to
961 * @data: data to write at register offset
963 * Acquires semaphore then writes the data to the PHY register at the offset
964 * using the kumeran interface. Release the acquired semaphore before exiting.
966 s32 e1000_write_kmrn_reg_generic(struct e1000_hw *hw, u32 offset, u16 data)
968 return __e1000_write_kmrn_reg(hw, offset, data, false);
972 * e1000_write_kmrn_reg_locked - Write kumeran register
973 * @hw: pointer to the HW structure
974 * @offset: register offset to write to
975 * @data: data to write at register offset
977 * Write the data to PHY register at the offset using the kumeran interface.
978 * Assumes semaphore already acquired.
980 s32 e1000_write_kmrn_reg_locked(struct e1000_hw *hw, u32 offset, u16 data)
982 return __e1000_write_kmrn_reg(hw, offset, data, true);
986 * e1000_set_master_slave_mode - Setup PHY for Master/slave mode
987 * @hw: pointer to the HW structure
989 * Sets up Master/slave mode
991 STATIC s32 e1000_set_master_slave_mode(struct e1000_hw *hw)
996 /* Resolve Master/Slave mode */
997 ret_val = hw->phy.ops.read_reg(hw, PHY_1000T_CTRL, &phy_data);
1001 /* load defaults for future use */
1002 hw->phy.original_ms_type = (phy_data & CR_1000T_MS_ENABLE) ?
1003 ((phy_data & CR_1000T_MS_VALUE) ?
1004 e1000_ms_force_master :
1005 e1000_ms_force_slave) : e1000_ms_auto;
1007 switch (hw->phy.ms_type) {
1008 case e1000_ms_force_master:
1009 phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
1011 case e1000_ms_force_slave:
1012 phy_data |= CR_1000T_MS_ENABLE;
1013 phy_data &= ~(CR_1000T_MS_VALUE);
1016 phy_data &= ~CR_1000T_MS_ENABLE;
1022 return hw->phy.ops.write_reg(hw, PHY_1000T_CTRL, phy_data);
1026 * e1000_copper_link_setup_82577 - Setup 82577 PHY for copper link
1027 * @hw: pointer to the HW structure
1029 * Sets up Carrier-sense on Transmit and downshift values.
1031 s32 e1000_copper_link_setup_82577(struct e1000_hw *hw)
1036 DEBUGFUNC("e1000_copper_link_setup_82577");
1038 if (hw->phy.type == e1000_phy_82580) {
1039 ret_val = hw->phy.ops.reset(hw);
1041 DEBUGOUT("Error resetting the PHY.\n");
1046 /* Enable CRS on Tx. This must be set for half-duplex operation. */
1047 ret_val = hw->phy.ops.read_reg(hw, I82577_CFG_REG, &phy_data);
1051 phy_data |= I82577_CFG_ASSERT_CRS_ON_TX;
1053 /* Enable downshift */
1054 phy_data |= I82577_CFG_ENABLE_DOWNSHIFT;
1056 ret_val = hw->phy.ops.write_reg(hw, I82577_CFG_REG, phy_data);
1060 /* Set MDI/MDIX mode */
1061 ret_val = hw->phy.ops.read_reg(hw, I82577_PHY_CTRL_2, &phy_data);
1064 phy_data &= ~I82577_PHY_CTRL2_MDIX_CFG_MASK;
1066 * 0 - Auto (default)
1070 switch (hw->phy.mdix) {
1074 phy_data |= I82577_PHY_CTRL2_MANUAL_MDIX;
1078 phy_data |= I82577_PHY_CTRL2_AUTO_MDI_MDIX;
1081 ret_val = hw->phy.ops.write_reg(hw, I82577_PHY_CTRL_2, phy_data);
1085 return e1000_set_master_slave_mode(hw);
1089 * e1000_copper_link_setup_m88 - Setup m88 PHY's for copper link
1090 * @hw: pointer to the HW structure
1092 * Sets up MDI/MDI-X and polarity for m88 PHY's. If necessary, transmit clock
1093 * and downshift values are set also.
1095 s32 e1000_copper_link_setup_m88(struct e1000_hw *hw)
1097 struct e1000_phy_info *phy = &hw->phy;
1101 DEBUGFUNC("e1000_copper_link_setup_m88");
1104 /* Enable CRS on Tx. This must be set for half-duplex operation. */
1105 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1109 /* For BM PHY this bit is downshift enable */
1110 if (phy->type != e1000_phy_bm)
1111 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1114 * MDI/MDI-X = 0 (default)
1115 * 0 - Auto for all speeds
1118 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1120 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1122 switch (phy->mdix) {
1124 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
1127 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
1130 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
1134 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
1139 * disable_polarity_correction = 0 (default)
1140 * Automatic Correction for Reversed Cable Polarity
1144 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
1145 if (phy->disable_polarity_correction)
1146 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
1148 /* Enable downshift on BM (disabled by default) */
1149 if (phy->type == e1000_phy_bm) {
1150 /* For 82574/82583, first disable then enable downshift */
1151 if (phy->id == BME1000_E_PHY_ID_R2) {
1152 phy_data &= ~BME1000_PSCR_ENABLE_DOWNSHIFT;
1153 ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL,
1157 /* Commit the changes. */
1158 ret_val = phy->ops.commit(hw);
1160 DEBUGOUT("Error committing the PHY changes\n");
1165 phy_data |= BME1000_PSCR_ENABLE_DOWNSHIFT;
1168 ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1172 if ((phy->type == e1000_phy_m88) &&
1173 (phy->revision < E1000_REVISION_4) &&
1174 (phy->id != BME1000_E_PHY_ID_R2)) {
1175 /* Force TX_CLK in the Extended PHY Specific Control Register
1178 ret_val = phy->ops.read_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
1183 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1185 if ((phy->revision == E1000_REVISION_2) &&
1186 (phy->id == M88E1111_I_PHY_ID)) {
1187 /* 82573L PHY - set the downshift counter to 5x. */
1188 phy_data &= ~M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK;
1189 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
1191 /* Configure Master and Slave downshift values */
1192 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
1193 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
1194 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
1195 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
1197 ret_val = phy->ops.write_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
1203 if ((phy->type == e1000_phy_bm) && (phy->id == BME1000_E_PHY_ID_R2)) {
1204 /* Set PHY page 0, register 29 to 0x0003 */
1205 ret_val = phy->ops.write_reg(hw, 29, 0x0003);
1209 /* Set PHY page 0, register 30 to 0x0000 */
1210 ret_val = phy->ops.write_reg(hw, 30, 0x0000);
1215 /* Commit the changes. */
1216 ret_val = phy->ops.commit(hw);
1218 DEBUGOUT("Error committing the PHY changes\n");
1222 if (phy->type == e1000_phy_82578) {
1223 ret_val = phy->ops.read_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
1228 /* 82578 PHY - set the downshift count to 1x. */
1229 phy_data |= I82578_EPSCR_DOWNSHIFT_ENABLE;
1230 phy_data &= ~I82578_EPSCR_DOWNSHIFT_COUNTER_MASK;
1231 ret_val = phy->ops.write_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
1237 return E1000_SUCCESS;
1241 * e1000_copper_link_setup_m88_gen2 - Setup m88 PHY's for copper link
1242 * @hw: pointer to the HW structure
1244 * Sets up MDI/MDI-X and polarity for i347-AT4, m88e1322 and m88e1112 PHY's.
1245 * Also enables and sets the downshift parameters.
1247 s32 e1000_copper_link_setup_m88_gen2(struct e1000_hw *hw)
1249 struct e1000_phy_info *phy = &hw->phy;
1253 DEBUGFUNC("e1000_copper_link_setup_m88_gen2");
1256 /* Enable CRS on Tx. This must be set for half-duplex operation. */
1257 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1262 * MDI/MDI-X = 0 (default)
1263 * 0 - Auto for all speeds
1266 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1268 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1270 switch (phy->mdix) {
1272 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
1275 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
1278 /* M88E1112 does not support this mode) */
1279 if (phy->id != M88E1112_E_PHY_ID) {
1280 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
1286 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
1291 * disable_polarity_correction = 0 (default)
1292 * Automatic Correction for Reversed Cable Polarity
1296 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
1297 if (phy->disable_polarity_correction)
1298 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
1300 /* Enable downshift and setting it to X6 */
1301 if (phy->id == M88E1543_E_PHY_ID) {
1302 phy_data &= ~I347AT4_PSCR_DOWNSHIFT_ENABLE;
1304 phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1308 ret_val = phy->ops.commit(hw);
1310 DEBUGOUT("Error committing the PHY changes\n");
1315 phy_data &= ~I347AT4_PSCR_DOWNSHIFT_MASK;
1316 phy_data |= I347AT4_PSCR_DOWNSHIFT_6X;
1317 phy_data |= I347AT4_PSCR_DOWNSHIFT_ENABLE;
1319 ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1323 /* Commit the changes. */
1324 ret_val = phy->ops.commit(hw);
1326 DEBUGOUT("Error committing the PHY changes\n");
1330 ret_val = e1000_set_master_slave_mode(hw);
1334 return E1000_SUCCESS;
1338 * e1000_copper_link_setup_igp - Setup igp PHY's for copper link
1339 * @hw: pointer to the HW structure
1341 * Sets up LPLU, MDI/MDI-X, polarity, Smartspeed and Master/Slave config for
1344 s32 e1000_copper_link_setup_igp(struct e1000_hw *hw)
1346 struct e1000_phy_info *phy = &hw->phy;
1350 DEBUGFUNC("e1000_copper_link_setup_igp");
1353 ret_val = hw->phy.ops.reset(hw);
1355 DEBUGOUT("Error resetting the PHY.\n");
1359 /* Wait 100ms for MAC to configure PHY from NVM settings, to avoid
1360 * timeout issues when LFS is enabled.
1364 /* The NVM settings will configure LPLU in D3 for
1367 if (phy->type == e1000_phy_igp) {
1368 /* disable lplu d3 during driver init */
1369 ret_val = hw->phy.ops.set_d3_lplu_state(hw, false);
1371 DEBUGOUT("Error Disabling LPLU D3\n");
1376 /* disable lplu d0 during driver init */
1377 if (hw->phy.ops.set_d0_lplu_state) {
1378 ret_val = hw->phy.ops.set_d0_lplu_state(hw, false);
1380 DEBUGOUT("Error Disabling LPLU D0\n");
1384 /* Configure mdi-mdix settings */
1385 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CTRL, &data);
1389 data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1391 switch (phy->mdix) {
1393 data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1396 data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
1400 data |= IGP01E1000_PSCR_AUTO_MDIX;
1403 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CTRL, data);
1407 /* set auto-master slave resolution settings */
1408 if (hw->mac.autoneg) {
1409 /* when autonegotiation advertisement is only 1000Mbps then we
1410 * should disable SmartSpeed and enable Auto MasterSlave
1411 * resolution as hardware default.
1413 if (phy->autoneg_advertised == ADVERTISE_1000_FULL) {
1414 /* Disable SmartSpeed */
1415 ret_val = phy->ops.read_reg(hw,
1416 IGP01E1000_PHY_PORT_CONFIG,
1421 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1422 ret_val = phy->ops.write_reg(hw,
1423 IGP01E1000_PHY_PORT_CONFIG,
1428 /* Set auto Master/Slave resolution process */
1429 ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL, &data);
1433 data &= ~CR_1000T_MS_ENABLE;
1434 ret_val = phy->ops.write_reg(hw, PHY_1000T_CTRL, data);
1439 ret_val = e1000_set_master_slave_mode(hw);
1446 * e1000_phy_setup_autoneg - Configure PHY for auto-negotiation
1447 * @hw: pointer to the HW structure
1449 * Reads the MII auto-neg advertisement register and/or the 1000T control
1450 * register and if the PHY is already setup for auto-negotiation, then
1451 * return successful. Otherwise, setup advertisement and flow control to
1452 * the appropriate values for the wanted auto-negotiation.
1454 s32 e1000_phy_setup_autoneg(struct e1000_hw *hw)
1456 struct e1000_phy_info *phy = &hw->phy;
1458 u16 mii_autoneg_adv_reg;
1459 u16 mii_1000t_ctrl_reg = 0;
1461 DEBUGFUNC("e1000_phy_setup_autoneg");
1463 phy->autoneg_advertised &= phy->autoneg_mask;
1465 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
1466 ret_val = phy->ops.read_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
1470 if (phy->autoneg_mask & ADVERTISE_1000_FULL) {
1471 /* Read the MII 1000Base-T Control Register (Address 9). */
1472 ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL,
1473 &mii_1000t_ctrl_reg);
1478 /* Need to parse both autoneg_advertised and fc and set up
1479 * the appropriate PHY registers. First we will parse for
1480 * autoneg_advertised software override. Since we can advertise
1481 * a plethora of combinations, we need to check each bit
1485 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
1486 * Advertisement Register (Address 4) and the 1000 mb speed bits in
1487 * the 1000Base-T Control Register (Address 9).
1489 mii_autoneg_adv_reg &= ~(NWAY_AR_100TX_FD_CAPS |
1490 NWAY_AR_100TX_HD_CAPS |
1491 NWAY_AR_10T_FD_CAPS |
1492 NWAY_AR_10T_HD_CAPS);
1493 mii_1000t_ctrl_reg &= ~(CR_1000T_HD_CAPS | CR_1000T_FD_CAPS);
1495 DEBUGOUT1("autoneg_advertised %x\n", phy->autoneg_advertised);
1497 /* Do we want to advertise 10 Mb Half Duplex? */
1498 if (phy->autoneg_advertised & ADVERTISE_10_HALF) {
1499 DEBUGOUT("Advertise 10mb Half duplex\n");
1500 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
1503 /* Do we want to advertise 10 Mb Full Duplex? */
1504 if (phy->autoneg_advertised & ADVERTISE_10_FULL) {
1505 DEBUGOUT("Advertise 10mb Full duplex\n");
1506 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
1509 /* Do we want to advertise 100 Mb Half Duplex? */
1510 if (phy->autoneg_advertised & ADVERTISE_100_HALF) {
1511 DEBUGOUT("Advertise 100mb Half duplex\n");
1512 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
1515 /* Do we want to advertise 100 Mb Full Duplex? */
1516 if (phy->autoneg_advertised & ADVERTISE_100_FULL) {
1517 DEBUGOUT("Advertise 100mb Full duplex\n");
1518 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
1521 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
1522 if (phy->autoneg_advertised & ADVERTISE_1000_HALF)
1523 DEBUGOUT("Advertise 1000mb Half duplex request denied!\n");
1525 /* Do we want to advertise 1000 Mb Full Duplex? */
1526 if (phy->autoneg_advertised & ADVERTISE_1000_FULL) {
1527 DEBUGOUT("Advertise 1000mb Full duplex\n");
1528 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
1531 /* Check for a software override of the flow control settings, and
1532 * setup the PHY advertisement registers accordingly. If
1533 * auto-negotiation is enabled, then software will have to set the
1534 * "PAUSE" bits to the correct value in the Auto-Negotiation
1535 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-
1538 * The possible values of the "fc" parameter are:
1539 * 0: Flow control is completely disabled
1540 * 1: Rx flow control is enabled (we can receive pause frames
1541 * but not send pause frames).
1542 * 2: Tx flow control is enabled (we can send pause frames
1543 * but we do not support receiving pause frames).
1544 * 3: Both Rx and Tx flow control (symmetric) are enabled.
1545 * other: No software override. The flow control configuration
1546 * in the EEPROM is used.
1548 switch (hw->fc.current_mode) {
1550 /* Flow control (Rx & Tx) is completely disabled by a
1551 * software over-ride.
1553 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1555 case e1000_fc_rx_pause:
1556 /* Rx Flow control is enabled, and Tx Flow control is
1557 * disabled, by a software over-ride.
1559 * Since there really isn't a way to advertise that we are
1560 * capable of Rx Pause ONLY, we will advertise that we
1561 * support both symmetric and asymmetric Rx PAUSE. Later
1562 * (in e1000_config_fc_after_link_up) we will disable the
1563 * hw's ability to send PAUSE frames.
1565 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1567 case e1000_fc_tx_pause:
1568 /* Tx Flow control is enabled, and Rx Flow control is
1569 * disabled, by a software over-ride.
1571 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
1572 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
1575 /* Flow control (both Rx and Tx) is enabled by a software
1578 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1581 DEBUGOUT("Flow control param set incorrectly\n");
1582 return -E1000_ERR_CONFIG;
1585 ret_val = phy->ops.write_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
1589 DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
1591 if (phy->autoneg_mask & ADVERTISE_1000_FULL)
1592 ret_val = phy->ops.write_reg(hw, PHY_1000T_CTRL,
1593 mii_1000t_ctrl_reg);
1599 * e1000_copper_link_autoneg - Setup/Enable autoneg for copper link
1600 * @hw: pointer to the HW structure
1602 * Performs initial bounds checking on autoneg advertisement parameter, then
1603 * configure to advertise the full capability. Setup the PHY to autoneg
1604 * and restart the negotiation process between the link partner. If
1605 * autoneg_wait_to_complete, then wait for autoneg to complete before exiting.
1607 s32 e1000_copper_link_autoneg(struct e1000_hw *hw)
1609 struct e1000_phy_info *phy = &hw->phy;
1613 DEBUGFUNC("e1000_copper_link_autoneg");
1615 /* Perform some bounds checking on the autoneg advertisement
1618 phy->autoneg_advertised &= phy->autoneg_mask;
1620 /* If autoneg_advertised is zero, we assume it was not defaulted
1621 * by the calling code so we set to advertise full capability.
1623 if (!phy->autoneg_advertised)
1624 phy->autoneg_advertised = phy->autoneg_mask;
1626 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
1627 ret_val = e1000_phy_setup_autoneg(hw);
1629 DEBUGOUT("Error Setting up Auto-Negotiation\n");
1632 DEBUGOUT("Restarting Auto-Neg\n");
1634 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
1635 * the Auto Neg Restart bit in the PHY control register.
1637 ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_ctrl);
1641 phy_ctrl |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
1642 ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_ctrl);
1646 /* Does the user want to wait for Auto-Neg to complete here, or
1647 * check at a later time (for example, callback routine).
1649 if (phy->autoneg_wait_to_complete) {
1650 ret_val = e1000_wait_autoneg(hw);
1652 DEBUGOUT("Error while waiting for autoneg to complete\n");
1657 hw->mac.get_link_status = true;
1663 * e1000_setup_copper_link_generic - Configure copper link settings
1664 * @hw: pointer to the HW structure
1666 * Calls the appropriate function to configure the link for auto-neg or forced
1667 * speed and duplex. Then we check for link, once link is established calls
1668 * to configure collision distance and flow control are called. If link is
1669 * not established, we return -E1000_ERR_PHY (-2).
1671 s32 e1000_setup_copper_link_generic(struct e1000_hw *hw)
1676 DEBUGFUNC("e1000_setup_copper_link_generic");
1678 if (hw->mac.autoneg) {
1679 /* Setup autoneg and flow control advertisement and perform
1682 ret_val = e1000_copper_link_autoneg(hw);
1686 /* PHY will be set to 10H, 10F, 100H or 100F
1687 * depending on user settings.
1689 DEBUGOUT("Forcing Speed and Duplex\n");
1690 ret_val = hw->phy.ops.force_speed_duplex(hw);
1692 DEBUGOUT("Error Forcing Speed and Duplex\n");
1697 /* Check link status. Wait up to 100 microseconds for link to become
1700 ret_val = e1000_phy_has_link_generic(hw, COPPER_LINK_UP_LIMIT, 10,
1706 DEBUGOUT("Valid link established!!!\n");
1707 hw->mac.ops.config_collision_dist(hw);
1708 ret_val = e1000_config_fc_after_link_up_generic(hw);
1710 DEBUGOUT("Unable to establish link!!!\n");
1717 * e1000_phy_force_speed_duplex_igp - Force speed/duplex for igp PHY
1718 * @hw: pointer to the HW structure
1720 * Calls the PHY setup function to force speed and duplex. Clears the
1721 * auto-crossover to force MDI manually. Waits for link and returns
1722 * successful if link up is successful, else -E1000_ERR_PHY (-2).
1724 s32 e1000_phy_force_speed_duplex_igp(struct e1000_hw *hw)
1726 struct e1000_phy_info *phy = &hw->phy;
1731 DEBUGFUNC("e1000_phy_force_speed_duplex_igp");
1733 ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_data);
1737 e1000_phy_force_speed_duplex_setup(hw, &phy_data);
1739 ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data);
1743 /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
1744 * forced whenever speed and duplex are forced.
1746 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1750 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1751 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1753 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1757 DEBUGOUT1("IGP PSCR: %X\n", phy_data);
1761 if (phy->autoneg_wait_to_complete) {
1762 DEBUGOUT("Waiting for forced speed/duplex link on IGP phy.\n");
1764 ret_val = e1000_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
1770 DEBUGOUT("Link taking longer than expected.\n");
1773 ret_val = e1000_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
1781 * e1000_phy_force_speed_duplex_m88 - Force speed/duplex for m88 PHY
1782 * @hw: pointer to the HW structure
1784 * Calls the PHY setup function to force speed and duplex. Clears the
1785 * auto-crossover to force MDI manually. Resets the PHY to commit the
1786 * changes. If time expires while waiting for link up, we reset the DSP.
1787 * After reset, TX_CLK and CRS on Tx must be set. Return successful upon
1788 * successful completion, else return corresponding error code.
1790 s32 e1000_phy_force_speed_duplex_m88(struct e1000_hw *hw)
1792 struct e1000_phy_info *phy = &hw->phy;
1797 DEBUGFUNC("e1000_phy_force_speed_duplex_m88");
1799 /* I210 and I211 devices support Auto-Crossover in forced operation. */
1800 if (phy->type != e1000_phy_i210) {
1801 /* Clear Auto-Crossover to force MDI manually. M88E1000
1802 * requires MDI forced whenever speed and duplex are forced.
1804 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL,
1809 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1810 ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL,
1815 DEBUGOUT1("M88E1000 PSCR: %X\n", phy_data);
1818 ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_data);
1822 e1000_phy_force_speed_duplex_setup(hw, &phy_data);
1824 ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data);
1828 /* Reset the phy to commit changes. */
1829 ret_val = hw->phy.ops.commit(hw);
1833 if (phy->autoneg_wait_to_complete) {
1834 DEBUGOUT("Waiting for forced speed/duplex link on M88 phy.\n");
1836 ret_val = e1000_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
1842 bool reset_dsp = true;
1844 switch (hw->phy.id) {
1845 case I347AT4_E_PHY_ID:
1846 case M88E1340M_E_PHY_ID:
1847 case M88E1112_E_PHY_ID:
1848 case M88E1543_E_PHY_ID:
1849 case M88E1512_E_PHY_ID:
1854 if (hw->phy.type != e1000_phy_m88)
1860 DEBUGOUT("Link taking longer than expected.\n");
1862 /* We didn't get link.
1863 * Reset the DSP and cross our fingers.
1865 ret_val = phy->ops.write_reg(hw,
1866 M88E1000_PHY_PAGE_SELECT,
1870 ret_val = e1000_phy_reset_dsp_generic(hw);
1877 ret_val = e1000_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
1883 if (hw->phy.type != e1000_phy_m88)
1884 return E1000_SUCCESS;
1886 if (hw->phy.id == I347AT4_E_PHY_ID ||
1887 hw->phy.id == M88E1340M_E_PHY_ID ||
1888 hw->phy.id == M88E1112_E_PHY_ID)
1889 return E1000_SUCCESS;
1890 if (hw->phy.id == I210_I_PHY_ID)
1891 return E1000_SUCCESS;
1892 if ((hw->phy.id == M88E1543_E_PHY_ID) ||
1893 (hw->phy.id == M88E1512_E_PHY_ID))
1894 return E1000_SUCCESS;
1895 ret_val = phy->ops.read_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1899 /* Resetting the phy means we need to re-force TX_CLK in the
1900 * Extended PHY Specific Control Register to 25MHz clock from
1901 * the reset value of 2.5MHz.
1903 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1904 ret_val = phy->ops.write_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1908 /* In addition, we must re-enable CRS on Tx for both half and full
1911 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1915 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1916 ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1922 * e1000_phy_force_speed_duplex_ife - Force PHY speed & duplex
1923 * @hw: pointer to the HW structure
1925 * Forces the speed and duplex settings of the PHY.
1926 * This is a function pointer entry point only called by
1927 * PHY setup routines.
1929 s32 e1000_phy_force_speed_duplex_ife(struct e1000_hw *hw)
1931 struct e1000_phy_info *phy = &hw->phy;
1936 DEBUGFUNC("e1000_phy_force_speed_duplex_ife");
1938 ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &data);
1942 e1000_phy_force_speed_duplex_setup(hw, &data);
1944 ret_val = phy->ops.write_reg(hw, PHY_CONTROL, data);
1948 /* Disable MDI-X support for 10/100 */
1949 ret_val = phy->ops.read_reg(hw, IFE_PHY_MDIX_CONTROL, &data);
1953 data &= ~IFE_PMC_AUTO_MDIX;
1954 data &= ~IFE_PMC_FORCE_MDIX;
1956 ret_val = phy->ops.write_reg(hw, IFE_PHY_MDIX_CONTROL, data);
1960 DEBUGOUT1("IFE PMC: %X\n", data);
1964 if (phy->autoneg_wait_to_complete) {
1965 DEBUGOUT("Waiting for forced speed/duplex link on IFE phy.\n");
1967 ret_val = e1000_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
1973 DEBUGOUT("Link taking longer than expected.\n");
1976 ret_val = e1000_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
1982 return E1000_SUCCESS;
1986 * e1000_phy_force_speed_duplex_setup - Configure forced PHY speed/duplex
1987 * @hw: pointer to the HW structure
1988 * @phy_ctrl: pointer to current value of PHY_CONTROL
1990 * Forces speed and duplex on the PHY by doing the following: disable flow
1991 * control, force speed/duplex on the MAC, disable auto speed detection,
1992 * disable auto-negotiation, configure duplex, configure speed, configure
1993 * the collision distance, write configuration to CTRL register. The
1994 * caller must write to the PHY_CONTROL register for these settings to
1997 void e1000_phy_force_speed_duplex_setup(struct e1000_hw *hw, u16 *phy_ctrl)
1999 struct e1000_mac_info *mac = &hw->mac;
2002 DEBUGFUNC("e1000_phy_force_speed_duplex_setup");
2004 /* Turn off flow control when forcing speed/duplex */
2005 hw->fc.current_mode = e1000_fc_none;
2007 /* Force speed/duplex on the mac */
2008 ctrl = E1000_READ_REG(hw, E1000_CTRL);
2009 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2010 ctrl &= ~E1000_CTRL_SPD_SEL;
2012 /* Disable Auto Speed Detection */
2013 ctrl &= ~E1000_CTRL_ASDE;
2015 /* Disable autoneg on the phy */
2016 *phy_ctrl &= ~MII_CR_AUTO_NEG_EN;
2018 /* Forcing Full or Half Duplex? */
2019 if (mac->forced_speed_duplex & E1000_ALL_HALF_DUPLEX) {
2020 ctrl &= ~E1000_CTRL_FD;
2021 *phy_ctrl &= ~MII_CR_FULL_DUPLEX;
2022 DEBUGOUT("Half Duplex\n");
2024 ctrl |= E1000_CTRL_FD;
2025 *phy_ctrl |= MII_CR_FULL_DUPLEX;
2026 DEBUGOUT("Full Duplex\n");
2029 /* Forcing 10mb or 100mb? */
2030 if (mac->forced_speed_duplex & E1000_ALL_100_SPEED) {
2031 ctrl |= E1000_CTRL_SPD_100;
2032 *phy_ctrl |= MII_CR_SPEED_100;
2033 *phy_ctrl &= ~MII_CR_SPEED_1000;
2034 DEBUGOUT("Forcing 100mb\n");
2036 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
2037 *phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
2038 DEBUGOUT("Forcing 10mb\n");
2041 hw->mac.ops.config_collision_dist(hw);
2043 E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
2047 * e1000_set_d3_lplu_state_generic - Sets low power link up state for D3
2048 * @hw: pointer to the HW structure
2049 * @active: boolean used to enable/disable lplu
2051 * Success returns 0, Failure returns 1
2053 * The low power link up (lplu) state is set to the power management level D3
2054 * and SmartSpeed is disabled when active is true, else clear lplu for D3
2055 * and enable Smartspeed. LPLU and Smartspeed are mutually exclusive. LPLU
2056 * is used during Dx states where the power conservation is most important.
2057 * During driver activity, SmartSpeed should be enabled so performance is
2060 s32 e1000_set_d3_lplu_state_generic(struct e1000_hw *hw, bool active)
2062 struct e1000_phy_info *phy = &hw->phy;
2066 DEBUGFUNC("e1000_set_d3_lplu_state_generic");
2068 if (!hw->phy.ops.read_reg)
2069 return E1000_SUCCESS;
2071 ret_val = phy->ops.read_reg(hw, IGP02E1000_PHY_POWER_MGMT, &data);
2076 data &= ~IGP02E1000_PM_D3_LPLU;
2077 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
2081 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
2082 * during Dx states where the power conservation is most
2083 * important. During driver activity we should enable
2084 * SmartSpeed, so performance is maintained.
2086 if (phy->smart_speed == e1000_smart_speed_on) {
2087 ret_val = phy->ops.read_reg(hw,
2088 IGP01E1000_PHY_PORT_CONFIG,
2093 data |= IGP01E1000_PSCFR_SMART_SPEED;
2094 ret_val = phy->ops.write_reg(hw,
2095 IGP01E1000_PHY_PORT_CONFIG,
2099 } else if (phy->smart_speed == e1000_smart_speed_off) {
2100 ret_val = phy->ops.read_reg(hw,
2101 IGP01E1000_PHY_PORT_CONFIG,
2106 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2107 ret_val = phy->ops.write_reg(hw,
2108 IGP01E1000_PHY_PORT_CONFIG,
2113 } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
2114 (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
2115 (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
2116 data |= IGP02E1000_PM_D3_LPLU;
2117 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
2122 /* When LPLU is enabled, we should disable SmartSpeed */
2123 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
2128 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2129 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
2137 * e1000_check_downshift_generic - Checks whether a downshift in speed occurred
2138 * @hw: pointer to the HW structure
2140 * Success returns 0, Failure returns 1
2142 * A downshift is detected by querying the PHY link health.
2144 s32 e1000_check_downshift_generic(struct e1000_hw *hw)
2146 struct e1000_phy_info *phy = &hw->phy;
2148 u16 phy_data, offset, mask;
2150 DEBUGFUNC("e1000_check_downshift_generic");
2152 switch (phy->type) {
2153 case e1000_phy_i210:
2155 case e1000_phy_gg82563:
2157 case e1000_phy_82578:
2158 offset = M88E1000_PHY_SPEC_STATUS;
2159 mask = M88E1000_PSSR_DOWNSHIFT;
2162 case e1000_phy_igp_2:
2163 case e1000_phy_igp_3:
2164 offset = IGP01E1000_PHY_LINK_HEALTH;
2165 mask = IGP01E1000_PLHR_SS_DOWNGRADE;
2168 /* speed downshift not supported */
2169 phy->speed_downgraded = false;
2170 return E1000_SUCCESS;
2173 ret_val = phy->ops.read_reg(hw, offset, &phy_data);
2176 phy->speed_downgraded = !!(phy_data & mask);
2182 * e1000_check_polarity_m88 - Checks the polarity.
2183 * @hw: pointer to the HW structure
2185 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
2187 * Polarity is determined based on the PHY specific status register.
2189 s32 e1000_check_polarity_m88(struct e1000_hw *hw)
2191 struct e1000_phy_info *phy = &hw->phy;
2195 DEBUGFUNC("e1000_check_polarity_m88");
2197 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &data);
2200 phy->cable_polarity = ((data & M88E1000_PSSR_REV_POLARITY)
2201 ? e1000_rev_polarity_reversed
2202 : e1000_rev_polarity_normal);
2208 * e1000_check_polarity_igp - Checks the polarity.
2209 * @hw: pointer to the HW structure
2211 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
2213 * Polarity is determined based on the PHY port status register, and the
2214 * current speed (since there is no polarity at 100Mbps).
2216 s32 e1000_check_polarity_igp(struct e1000_hw *hw)
2218 struct e1000_phy_info *phy = &hw->phy;
2220 u16 data, offset, mask;
2222 DEBUGFUNC("e1000_check_polarity_igp");
2224 /* Polarity is determined based on the speed of
2227 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_STATUS, &data);
2231 if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
2232 IGP01E1000_PSSR_SPEED_1000MBPS) {
2233 offset = IGP01E1000_PHY_PCS_INIT_REG;
2234 mask = IGP01E1000_PHY_POLARITY_MASK;
2236 /* This really only applies to 10Mbps since
2237 * there is no polarity for 100Mbps (always 0).
2239 offset = IGP01E1000_PHY_PORT_STATUS;
2240 mask = IGP01E1000_PSSR_POLARITY_REVERSED;
2243 ret_val = phy->ops.read_reg(hw, offset, &data);
2246 phy->cable_polarity = ((data & mask)
2247 ? e1000_rev_polarity_reversed
2248 : e1000_rev_polarity_normal);
2254 * e1000_check_polarity_ife - Check cable polarity for IFE PHY
2255 * @hw: pointer to the HW structure
2257 * Polarity is determined on the polarity reversal feature being enabled.
2259 s32 e1000_check_polarity_ife(struct e1000_hw *hw)
2261 struct e1000_phy_info *phy = &hw->phy;
2263 u16 phy_data, offset, mask;
2265 DEBUGFUNC("e1000_check_polarity_ife");
2267 /* Polarity is determined based on the reversal feature being enabled.
2269 if (phy->polarity_correction) {
2270 offset = IFE_PHY_EXTENDED_STATUS_CONTROL;
2271 mask = IFE_PESC_POLARITY_REVERSED;
2273 offset = IFE_PHY_SPECIAL_CONTROL;
2274 mask = IFE_PSC_FORCE_POLARITY;
2277 ret_val = phy->ops.read_reg(hw, offset, &phy_data);
2280 phy->cable_polarity = ((phy_data & mask)
2281 ? e1000_rev_polarity_reversed
2282 : e1000_rev_polarity_normal);
2288 * e1000_wait_autoneg - Wait for auto-neg completion
2289 * @hw: pointer to the HW structure
2291 * Waits for auto-negotiation to complete or for the auto-negotiation time
2292 * limit to expire, which ever happens first.
2294 STATIC s32 e1000_wait_autoneg(struct e1000_hw *hw)
2296 s32 ret_val = E1000_SUCCESS;
2299 DEBUGFUNC("e1000_wait_autoneg");
2301 if (!hw->phy.ops.read_reg)
2302 return E1000_SUCCESS;
2304 /* Break after autoneg completes or PHY_AUTO_NEG_LIMIT expires. */
2305 for (i = PHY_AUTO_NEG_LIMIT; i > 0; i--) {
2306 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
2309 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
2312 if (phy_status & MII_SR_AUTONEG_COMPLETE)
2317 /* PHY_AUTO_NEG_TIME expiration doesn't guarantee auto-negotiation
2324 * e1000_phy_has_link_generic - Polls PHY for link
2325 * @hw: pointer to the HW structure
2326 * @iterations: number of times to poll for link
2327 * @usec_interval: delay between polling attempts
2328 * @success: pointer to whether polling was successful or not
2330 * Polls the PHY status register for link, 'iterations' number of times.
2332 s32 e1000_phy_has_link_generic(struct e1000_hw *hw, u32 iterations,
2333 u32 usec_interval, bool *success)
2335 s32 ret_val = E1000_SUCCESS;
2338 DEBUGFUNC("e1000_phy_has_link_generic");
2340 if (!hw->phy.ops.read_reg)
2341 return E1000_SUCCESS;
2343 for (i = 0; i < iterations; i++) {
2344 /* Some PHYs require the PHY_STATUS register to be read
2345 * twice due to the link bit being sticky. No harm doing
2346 * it across the board.
2348 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
2350 /* If the first read fails, another entity may have
2351 * ownership of the resources, wait and try again to
2352 * see if they have relinquished the resources yet.
2354 if (usec_interval >= 1000)
2355 msec_delay(usec_interval/1000);
2357 usec_delay(usec_interval);
2359 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
2362 if (phy_status & MII_SR_LINK_STATUS)
2364 if (usec_interval >= 1000)
2365 msec_delay(usec_interval/1000);
2367 usec_delay(usec_interval);
2370 *success = (i < iterations);
2376 * e1000_get_cable_length_m88 - Determine cable length for m88 PHY
2377 * @hw: pointer to the HW structure
2379 * Reads the PHY specific status register to retrieve the cable length
2380 * information. The cable length is determined by averaging the minimum and
2381 * maximum values to get the "average" cable length. The m88 PHY has four
2382 * possible cable length values, which are:
2383 * Register Value Cable Length
2387 * 3 110 - 140 meters
2390 s32 e1000_get_cable_length_m88(struct e1000_hw *hw)
2392 struct e1000_phy_info *phy = &hw->phy;
2394 u16 phy_data, index;
2396 DEBUGFUNC("e1000_get_cable_length_m88");
2398 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
2402 index = ((phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
2403 M88E1000_PSSR_CABLE_LENGTH_SHIFT);
2405 if (index >= M88E1000_CABLE_LENGTH_TABLE_SIZE - 1)
2406 return -E1000_ERR_PHY;
2408 phy->min_cable_length = e1000_m88_cable_length_table[index];
2409 phy->max_cable_length = e1000_m88_cable_length_table[index + 1];
2411 phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
2413 return E1000_SUCCESS;
2416 s32 e1000_get_cable_length_m88_gen2(struct e1000_hw *hw)
2418 struct e1000_phy_info *phy = &hw->phy;
2420 u16 phy_data, phy_data2, is_cm;
2421 u16 index, default_page;
2423 DEBUGFUNC("e1000_get_cable_length_m88_gen2");
2425 switch (hw->phy.id) {
2427 /* Get cable length from PHY Cable Diagnostics Control Reg */
2428 ret_val = phy->ops.read_reg(hw, (0x7 << GS40G_PAGE_SHIFT) +
2429 (I347AT4_PCDL + phy->addr),
2434 /* Check if the unit of cable length is meters or cm */
2435 ret_val = phy->ops.read_reg(hw, (0x7 << GS40G_PAGE_SHIFT) +
2436 I347AT4_PCDC, &phy_data2);
2440 is_cm = !(phy_data2 & I347AT4_PCDC_CABLE_LENGTH_UNIT);
2442 /* Populate the phy structure with cable length in meters */
2443 phy->min_cable_length = phy_data / (is_cm ? 100 : 1);
2444 phy->max_cable_length = phy_data / (is_cm ? 100 : 1);
2445 phy->cable_length = phy_data / (is_cm ? 100 : 1);
2447 case M88E1543_E_PHY_ID:
2448 case M88E1512_E_PHY_ID:
2449 case M88E1340M_E_PHY_ID:
2450 case I347AT4_E_PHY_ID:
2451 /* Remember the original page select and set it to 7 */
2452 ret_val = phy->ops.read_reg(hw, I347AT4_PAGE_SELECT,
2457 ret_val = phy->ops.write_reg(hw, I347AT4_PAGE_SELECT, 0x07);
2461 /* Get cable length from PHY Cable Diagnostics Control Reg */
2462 ret_val = phy->ops.read_reg(hw, (I347AT4_PCDL + phy->addr),
2467 /* Check if the unit of cable length is meters or cm */
2468 ret_val = phy->ops.read_reg(hw, I347AT4_PCDC, &phy_data2);
2472 is_cm = !(phy_data2 & I347AT4_PCDC_CABLE_LENGTH_UNIT);
2474 /* Populate the phy structure with cable length in meters */
2475 phy->min_cable_length = phy_data / (is_cm ? 100 : 1);
2476 phy->max_cable_length = phy_data / (is_cm ? 100 : 1);
2477 phy->cable_length = phy_data / (is_cm ? 100 : 1);
2479 /* Reset the page select to its original value */
2480 ret_val = phy->ops.write_reg(hw, I347AT4_PAGE_SELECT,
2486 case M88E1112_E_PHY_ID:
2487 /* Remember the original page select and set it to 5 */
2488 ret_val = phy->ops.read_reg(hw, I347AT4_PAGE_SELECT,
2493 ret_val = phy->ops.write_reg(hw, I347AT4_PAGE_SELECT, 0x05);
2497 ret_val = phy->ops.read_reg(hw, M88E1112_VCT_DSP_DISTANCE,
2502 index = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
2503 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
2505 if (index >= M88E1000_CABLE_LENGTH_TABLE_SIZE - 1)
2506 return -E1000_ERR_PHY;
2508 phy->min_cable_length = e1000_m88_cable_length_table[index];
2509 phy->max_cable_length = e1000_m88_cable_length_table[index + 1];
2511 phy->cable_length = (phy->min_cable_length +
2512 phy->max_cable_length) / 2;
2514 /* Reset the page select to its original value */
2515 ret_val = phy->ops.write_reg(hw, I347AT4_PAGE_SELECT,
2522 return -E1000_ERR_PHY;
2529 * e1000_get_cable_length_igp_2 - Determine cable length for igp2 PHY
2530 * @hw: pointer to the HW structure
2532 * The automatic gain control (agc) normalizes the amplitude of the
2533 * received signal, adjusting for the attenuation produced by the
2534 * cable. By reading the AGC registers, which represent the
2535 * combination of coarse and fine gain value, the value can be put
2536 * into a lookup table to obtain the approximate cable length
2539 s32 e1000_get_cable_length_igp_2(struct e1000_hw *hw)
2541 struct e1000_phy_info *phy = &hw->phy;
2543 u16 phy_data, i, agc_value = 0;
2544 u16 cur_agc_index, max_agc_index = 0;
2545 u16 min_agc_index = IGP02E1000_CABLE_LENGTH_TABLE_SIZE - 1;
2546 static const u16 agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] = {
2547 IGP02E1000_PHY_AGC_A,
2548 IGP02E1000_PHY_AGC_B,
2549 IGP02E1000_PHY_AGC_C,
2550 IGP02E1000_PHY_AGC_D
2553 DEBUGFUNC("e1000_get_cable_length_igp_2");
2555 /* Read the AGC registers for all channels */
2556 for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
2557 ret_val = phy->ops.read_reg(hw, agc_reg_array[i], &phy_data);
2561 /* Getting bits 15:9, which represent the combination of
2562 * coarse and fine gain values. The result is a number
2563 * that can be put into the lookup table to obtain the
2564 * approximate cable length.
2566 cur_agc_index = ((phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
2567 IGP02E1000_AGC_LENGTH_MASK);
2569 /* Array index bound check. */
2570 if ((cur_agc_index >= IGP02E1000_CABLE_LENGTH_TABLE_SIZE) ||
2571 (cur_agc_index == 0))
2572 return -E1000_ERR_PHY;
2574 /* Remove min & max AGC values from calculation. */
2575 if (e1000_igp_2_cable_length_table[min_agc_index] >
2576 e1000_igp_2_cable_length_table[cur_agc_index])
2577 min_agc_index = cur_agc_index;
2578 if (e1000_igp_2_cable_length_table[max_agc_index] <
2579 e1000_igp_2_cable_length_table[cur_agc_index])
2580 max_agc_index = cur_agc_index;
2582 agc_value += e1000_igp_2_cable_length_table[cur_agc_index];
2585 agc_value -= (e1000_igp_2_cable_length_table[min_agc_index] +
2586 e1000_igp_2_cable_length_table[max_agc_index]);
2587 agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
2589 /* Calculate cable length with the error range of +/- 10 meters. */
2590 phy->min_cable_length = (((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
2591 (agc_value - IGP02E1000_AGC_RANGE) : 0);
2592 phy->max_cable_length = agc_value + IGP02E1000_AGC_RANGE;
2594 phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
2596 return E1000_SUCCESS;
2600 * e1000_get_phy_info_m88 - Retrieve PHY information
2601 * @hw: pointer to the HW structure
2603 * Valid for only copper links. Read the PHY status register (sticky read)
2604 * to verify that link is up. Read the PHY special control register to
2605 * determine the polarity and 10base-T extended distance. Read the PHY
2606 * special status register to determine MDI/MDIx and current speed. If
2607 * speed is 1000, then determine cable length, local and remote receiver.
2609 s32 e1000_get_phy_info_m88(struct e1000_hw *hw)
2611 struct e1000_phy_info *phy = &hw->phy;
2616 DEBUGFUNC("e1000_get_phy_info_m88");
2618 if (phy->media_type != e1000_media_type_copper) {
2619 DEBUGOUT("Phy info is only valid for copper media\n");
2620 return -E1000_ERR_CONFIG;
2623 ret_val = e1000_phy_has_link_generic(hw, 1, 0, &link);
2628 DEBUGOUT("Phy info is only valid if link is up\n");
2629 return -E1000_ERR_CONFIG;
2632 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
2636 phy->polarity_correction = !!(phy_data &
2637 M88E1000_PSCR_POLARITY_REVERSAL);
2639 ret_val = e1000_check_polarity_m88(hw);
2643 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
2647 phy->is_mdix = !!(phy_data & M88E1000_PSSR_MDIX);
2649 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
2650 ret_val = hw->phy.ops.get_cable_length(hw);
2654 ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &phy_data);
2658 phy->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS)
2659 ? e1000_1000t_rx_status_ok
2660 : e1000_1000t_rx_status_not_ok;
2662 phy->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS)
2663 ? e1000_1000t_rx_status_ok
2664 : e1000_1000t_rx_status_not_ok;
2666 /* Set values to "undefined" */
2667 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
2668 phy->local_rx = e1000_1000t_rx_status_undefined;
2669 phy->remote_rx = e1000_1000t_rx_status_undefined;
2676 * e1000_get_phy_info_igp - Retrieve igp PHY information
2677 * @hw: pointer to the HW structure
2679 * Read PHY status to determine if link is up. If link is up, then
2680 * set/determine 10base-T extended distance and polarity correction. Read
2681 * PHY port status to determine MDI/MDIx and speed. Based on the speed,
2682 * determine on the cable length, local and remote receiver.
2684 s32 e1000_get_phy_info_igp(struct e1000_hw *hw)
2686 struct e1000_phy_info *phy = &hw->phy;
2691 DEBUGFUNC("e1000_get_phy_info_igp");
2693 ret_val = e1000_phy_has_link_generic(hw, 1, 0, &link);
2698 DEBUGOUT("Phy info is only valid if link is up\n");
2699 return -E1000_ERR_CONFIG;
2702 phy->polarity_correction = true;
2704 ret_val = e1000_check_polarity_igp(hw);
2708 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_STATUS, &data);
2712 phy->is_mdix = !!(data & IGP01E1000_PSSR_MDIX);
2714 if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
2715 IGP01E1000_PSSR_SPEED_1000MBPS) {
2716 ret_val = phy->ops.get_cable_length(hw);
2720 ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &data);
2724 phy->local_rx = (data & SR_1000T_LOCAL_RX_STATUS)
2725 ? e1000_1000t_rx_status_ok
2726 : e1000_1000t_rx_status_not_ok;
2728 phy->remote_rx = (data & SR_1000T_REMOTE_RX_STATUS)
2729 ? e1000_1000t_rx_status_ok
2730 : e1000_1000t_rx_status_not_ok;
2732 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
2733 phy->local_rx = e1000_1000t_rx_status_undefined;
2734 phy->remote_rx = e1000_1000t_rx_status_undefined;
2741 * e1000_get_phy_info_ife - Retrieves various IFE PHY states
2742 * @hw: pointer to the HW structure
2744 * Populates "phy" structure with various feature states.
2746 s32 e1000_get_phy_info_ife(struct e1000_hw *hw)
2748 struct e1000_phy_info *phy = &hw->phy;
2753 DEBUGFUNC("e1000_get_phy_info_ife");
2755 ret_val = e1000_phy_has_link_generic(hw, 1, 0, &link);
2760 DEBUGOUT("Phy info is only valid if link is up\n");
2761 return -E1000_ERR_CONFIG;
2764 ret_val = phy->ops.read_reg(hw, IFE_PHY_SPECIAL_CONTROL, &data);
2767 phy->polarity_correction = !(data & IFE_PSC_AUTO_POLARITY_DISABLE);
2769 if (phy->polarity_correction) {
2770 ret_val = e1000_check_polarity_ife(hw);
2774 /* Polarity is forced */
2775 phy->cable_polarity = ((data & IFE_PSC_FORCE_POLARITY)
2776 ? e1000_rev_polarity_reversed
2777 : e1000_rev_polarity_normal);
2780 ret_val = phy->ops.read_reg(hw, IFE_PHY_MDIX_CONTROL, &data);
2784 phy->is_mdix = !!(data & IFE_PMC_MDIX_STATUS);
2786 /* The following parameters are undefined for 10/100 operation. */
2787 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
2788 phy->local_rx = e1000_1000t_rx_status_undefined;
2789 phy->remote_rx = e1000_1000t_rx_status_undefined;
2791 return E1000_SUCCESS;
2795 * e1000_phy_sw_reset_generic - PHY software reset
2796 * @hw: pointer to the HW structure
2798 * Does a software reset of the PHY by reading the PHY control register and
2799 * setting/write the control register reset bit to the PHY.
2801 s32 e1000_phy_sw_reset_generic(struct e1000_hw *hw)
2806 DEBUGFUNC("e1000_phy_sw_reset_generic");
2808 if (!hw->phy.ops.read_reg)
2809 return E1000_SUCCESS;
2811 ret_val = hw->phy.ops.read_reg(hw, PHY_CONTROL, &phy_ctrl);
2815 phy_ctrl |= MII_CR_RESET;
2816 ret_val = hw->phy.ops.write_reg(hw, PHY_CONTROL, phy_ctrl);
2826 * e1000_phy_hw_reset_generic - PHY hardware reset
2827 * @hw: pointer to the HW structure
2829 * Verify the reset block is not blocking us from resetting. Acquire
2830 * semaphore (if necessary) and read/set/write the device control reset
2831 * bit in the PHY. Wait the appropriate delay time for the device to
2832 * reset and release the semaphore (if necessary).
2834 s32 e1000_phy_hw_reset_generic(struct e1000_hw *hw)
2836 struct e1000_phy_info *phy = &hw->phy;
2840 DEBUGFUNC("e1000_phy_hw_reset_generic");
2842 if (phy->ops.check_reset_block) {
2843 ret_val = phy->ops.check_reset_block(hw);
2845 return E1000_SUCCESS;
2848 ret_val = phy->ops.acquire(hw);
2852 ctrl = E1000_READ_REG(hw, E1000_CTRL);
2853 E1000_WRITE_REG(hw, E1000_CTRL, ctrl | E1000_CTRL_PHY_RST);
2854 E1000_WRITE_FLUSH(hw);
2856 usec_delay(phy->reset_delay_us);
2858 E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
2859 E1000_WRITE_FLUSH(hw);
2863 phy->ops.release(hw);
2865 return phy->ops.get_cfg_done(hw);
2869 * e1000_get_cfg_done_generic - Generic configuration done
2870 * @hw: pointer to the HW structure
2872 * Generic function to wait 10 milli-seconds for configuration to complete
2873 * and return success.
2875 s32 e1000_get_cfg_done_generic(struct e1000_hw E1000_UNUSEDARG *hw)
2877 DEBUGFUNC("e1000_get_cfg_done_generic");
2878 UNREFERENCED_1PARAMETER(hw);
2882 return E1000_SUCCESS;
2886 * e1000_phy_init_script_igp3 - Inits the IGP3 PHY
2887 * @hw: pointer to the HW structure
2889 * Initializes a Intel Gigabit PHY3 when an EEPROM is not present.
2891 s32 e1000_phy_init_script_igp3(struct e1000_hw *hw)
2893 DEBUGOUT("Running IGP 3 PHY init script\n");
2895 /* PHY init IGP 3 */
2896 /* Enable rise/fall, 10-mode work in class-A */
2897 hw->phy.ops.write_reg(hw, 0x2F5B, 0x9018);
2898 /* Remove all caps from Replica path filter */
2899 hw->phy.ops.write_reg(hw, 0x2F52, 0x0000);
2900 /* Bias trimming for ADC, AFE and Driver (Default) */
2901 hw->phy.ops.write_reg(hw, 0x2FB1, 0x8B24);
2902 /* Increase Hybrid poly bias */
2903 hw->phy.ops.write_reg(hw, 0x2FB2, 0xF8F0);
2904 /* Add 4% to Tx amplitude in Gig mode */
2905 hw->phy.ops.write_reg(hw, 0x2010, 0x10B0);
2906 /* Disable trimming (TTT) */
2907 hw->phy.ops.write_reg(hw, 0x2011, 0x0000);
2908 /* Poly DC correction to 94.6% + 2% for all channels */
2909 hw->phy.ops.write_reg(hw, 0x20DD, 0x249A);
2910 /* ABS DC correction to 95.9% */
2911 hw->phy.ops.write_reg(hw, 0x20DE, 0x00D3);
2912 /* BG temp curve trim */
2913 hw->phy.ops.write_reg(hw, 0x28B4, 0x04CE);
2914 /* Increasing ADC OPAMP stage 1 currents to max */
2915 hw->phy.ops.write_reg(hw, 0x2F70, 0x29E4);
2916 /* Force 1000 ( required for enabling PHY regs configuration) */
2917 hw->phy.ops.write_reg(hw, 0x0000, 0x0140);
2918 /* Set upd_freq to 6 */
2919 hw->phy.ops.write_reg(hw, 0x1F30, 0x1606);
2921 hw->phy.ops.write_reg(hw, 0x1F31, 0xB814);
2922 /* Disable adaptive fixed FFE (Default) */
2923 hw->phy.ops.write_reg(hw, 0x1F35, 0x002A);
2924 /* Enable FFE hysteresis */
2925 hw->phy.ops.write_reg(hw, 0x1F3E, 0x0067);
2926 /* Fixed FFE for short cable lengths */
2927 hw->phy.ops.write_reg(hw, 0x1F54, 0x0065);
2928 /* Fixed FFE for medium cable lengths */
2929 hw->phy.ops.write_reg(hw, 0x1F55, 0x002A);
2930 /* Fixed FFE for long cable lengths */
2931 hw->phy.ops.write_reg(hw, 0x1F56, 0x002A);
2932 /* Enable Adaptive Clip Threshold */
2933 hw->phy.ops.write_reg(hw, 0x1F72, 0x3FB0);
2934 /* AHT reset limit to 1 */
2935 hw->phy.ops.write_reg(hw, 0x1F76, 0xC0FF);
2936 /* Set AHT master delay to 127 msec */
2937 hw->phy.ops.write_reg(hw, 0x1F77, 0x1DEC);
2938 /* Set scan bits for AHT */
2939 hw->phy.ops.write_reg(hw, 0x1F78, 0xF9EF);
2940 /* Set AHT Preset bits */
2941 hw->phy.ops.write_reg(hw, 0x1F79, 0x0210);
2942 /* Change integ_factor of channel A to 3 */
2943 hw->phy.ops.write_reg(hw, 0x1895, 0x0003);
2944 /* Change prop_factor of channels BCD to 8 */
2945 hw->phy.ops.write_reg(hw, 0x1796, 0x0008);
2946 /* Change cg_icount + enable integbp for channels BCD */
2947 hw->phy.ops.write_reg(hw, 0x1798, 0xD008);
2948 /* Change cg_icount + enable integbp + change prop_factor_master
2949 * to 8 for channel A
2951 hw->phy.ops.write_reg(hw, 0x1898, 0xD918);
2952 /* Disable AHT in Slave mode on channel A */
2953 hw->phy.ops.write_reg(hw, 0x187A, 0x0800);
2954 /* Enable LPLU and disable AN to 1000 in non-D0a states,
2957 hw->phy.ops.write_reg(hw, 0x0019, 0x008D);
2958 /* Enable restart AN on an1000_dis change */
2959 hw->phy.ops.write_reg(hw, 0x001B, 0x2080);
2960 /* Enable wh_fifo read clock in 10/100 modes */
2961 hw->phy.ops.write_reg(hw, 0x0014, 0x0045);
2962 /* Restart AN, Speed selection is 1000 */
2963 hw->phy.ops.write_reg(hw, 0x0000, 0x1340);
2965 return E1000_SUCCESS;
2969 * e1000_get_phy_type_from_id - Get PHY type from id
2970 * @phy_id: phy_id read from the phy
2972 * Returns the phy type from the id.
2974 enum e1000_phy_type e1000_get_phy_type_from_id(u32 phy_id)
2976 enum e1000_phy_type phy_type = e1000_phy_unknown;
2979 case M88E1000_I_PHY_ID:
2980 case M88E1000_E_PHY_ID:
2981 case M88E1111_I_PHY_ID:
2982 case M88E1011_I_PHY_ID:
2983 case M88E1543_E_PHY_ID:
2984 case M88E1512_E_PHY_ID:
2985 case I347AT4_E_PHY_ID:
2986 case M88E1112_E_PHY_ID:
2987 case M88E1340M_E_PHY_ID:
2988 phy_type = e1000_phy_m88;
2990 case IGP01E1000_I_PHY_ID: /* IGP 1 & 2 share this */
2991 phy_type = e1000_phy_igp_2;
2993 case GG82563_E_PHY_ID:
2994 phy_type = e1000_phy_gg82563;
2996 case IGP03E1000_E_PHY_ID:
2997 phy_type = e1000_phy_igp_3;
3000 case IFE_PLUS_E_PHY_ID:
3001 case IFE_C_E_PHY_ID:
3002 phy_type = e1000_phy_ife;
3004 case BME1000_E_PHY_ID:
3005 case BME1000_E_PHY_ID_R2:
3006 phy_type = e1000_phy_bm;
3008 case I82578_E_PHY_ID:
3009 phy_type = e1000_phy_82578;
3011 case I82577_E_PHY_ID:
3012 phy_type = e1000_phy_82577;
3014 case I82579_E_PHY_ID:
3015 phy_type = e1000_phy_82579;
3018 phy_type = e1000_phy_i217;
3020 case I82580_I_PHY_ID:
3021 phy_type = e1000_phy_82580;
3024 phy_type = e1000_phy_i210;
3027 phy_type = e1000_phy_unknown;
3034 * e1000_determine_phy_address - Determines PHY address.
3035 * @hw: pointer to the HW structure
3037 * This uses a trial and error method to loop through possible PHY
3038 * addresses. It tests each by reading the PHY ID registers and
3039 * checking for a match.
3041 s32 e1000_determine_phy_address(struct e1000_hw *hw)
3045 enum e1000_phy_type phy_type = e1000_phy_unknown;
3047 hw->phy.id = phy_type;
3049 for (phy_addr = 0; phy_addr < E1000_MAX_PHY_ADDR; phy_addr++) {
3050 hw->phy.addr = phy_addr;
3054 e1000_get_phy_id(hw);
3055 phy_type = e1000_get_phy_type_from_id(hw->phy.id);
3057 /* If phy_type is valid, break - we found our
3060 if (phy_type != e1000_phy_unknown)
3061 return E1000_SUCCESS;
3068 return -E1000_ERR_PHY_TYPE;
3072 * e1000_get_phy_addr_for_bm_page - Retrieve PHY page address
3073 * @page: page to access
3074 * @reg: register to access
3076 * Returns the phy address for the page requested.
3078 STATIC u32 e1000_get_phy_addr_for_bm_page(u32 page, u32 reg)
3082 if ((page >= 768) || (page == 0 && reg == 25) || (reg == 31))
3089 * e1000_write_phy_reg_bm - Write BM PHY register
3090 * @hw: pointer to the HW structure
3091 * @offset: register offset to write to
3092 * @data: data to write at register offset
3094 * Acquires semaphore, if necessary, then writes the data to PHY register
3095 * at the offset. Release any acquired semaphores before exiting.
3097 s32 e1000_write_phy_reg_bm(struct e1000_hw *hw, u32 offset, u16 data)
3100 u32 page = offset >> IGP_PAGE_SHIFT;
3102 DEBUGFUNC("e1000_write_phy_reg_bm");
3104 ret_val = hw->phy.ops.acquire(hw);
3108 /* Page 800 works differently than the rest so it has its own func */
3109 if (page == BM_WUC_PAGE) {
3110 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, &data,
3115 hw->phy.addr = e1000_get_phy_addr_for_bm_page(page, offset);
3117 if (offset > MAX_PHY_MULTI_PAGE_REG) {
3118 u32 page_shift, page_select;
3120 /* Page select is register 31 for phy address 1 and 22 for
3121 * phy address 2 and 3. Page select is shifted only for
3124 if (hw->phy.addr == 1) {
3125 page_shift = IGP_PAGE_SHIFT;
3126 page_select = IGP01E1000_PHY_PAGE_SELECT;
3129 page_select = BM_PHY_PAGE_SELECT;
3132 /* Page is shifted left, PHY expects (page x 32) */
3133 ret_val = e1000_write_phy_reg_mdic(hw, page_select,
3134 (page << page_shift));
3139 ret_val = e1000_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
3143 hw->phy.ops.release(hw);
3148 * e1000_read_phy_reg_bm - Read BM PHY register
3149 * @hw: pointer to the HW structure
3150 * @offset: register offset to be read
3151 * @data: pointer to the read data
3153 * Acquires semaphore, if necessary, then reads the PHY register at offset
3154 * and storing the retrieved information in data. Release any acquired
3155 * semaphores before exiting.
3157 s32 e1000_read_phy_reg_bm(struct e1000_hw *hw, u32 offset, u16 *data)
3160 u32 page = offset >> IGP_PAGE_SHIFT;
3162 DEBUGFUNC("e1000_read_phy_reg_bm");
3164 ret_val = hw->phy.ops.acquire(hw);
3168 /* Page 800 works differently than the rest so it has its own func */
3169 if (page == BM_WUC_PAGE) {
3170 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, data,
3175 hw->phy.addr = e1000_get_phy_addr_for_bm_page(page, offset);
3177 if (offset > MAX_PHY_MULTI_PAGE_REG) {
3178 u32 page_shift, page_select;
3180 /* Page select is register 31 for phy address 1 and 22 for
3181 * phy address 2 and 3. Page select is shifted only for
3184 if (hw->phy.addr == 1) {
3185 page_shift = IGP_PAGE_SHIFT;
3186 page_select = IGP01E1000_PHY_PAGE_SELECT;
3189 page_select = BM_PHY_PAGE_SELECT;
3192 /* Page is shifted left, PHY expects (page x 32) */
3193 ret_val = e1000_write_phy_reg_mdic(hw, page_select,
3194 (page << page_shift));
3199 ret_val = e1000_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
3202 hw->phy.ops.release(hw);
3207 * e1000_read_phy_reg_bm2 - Read BM PHY register
3208 * @hw: pointer to the HW structure
3209 * @offset: register offset to be read
3210 * @data: pointer to the read data
3212 * Acquires semaphore, if necessary, then reads the PHY register at offset
3213 * and storing the retrieved information in data. Release any acquired
3214 * semaphores before exiting.
3216 s32 e1000_read_phy_reg_bm2(struct e1000_hw *hw, u32 offset, u16 *data)
3219 u16 page = (u16)(offset >> IGP_PAGE_SHIFT);
3221 DEBUGFUNC("e1000_read_phy_reg_bm2");
3223 ret_val = hw->phy.ops.acquire(hw);
3227 /* Page 800 works differently than the rest so it has its own func */
3228 if (page == BM_WUC_PAGE) {
3229 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, data,
3236 if (offset > MAX_PHY_MULTI_PAGE_REG) {
3237 /* Page is shifted left, PHY expects (page x 32) */
3238 ret_val = e1000_write_phy_reg_mdic(hw, BM_PHY_PAGE_SELECT,
3245 ret_val = e1000_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
3248 hw->phy.ops.release(hw);
3253 * e1000_write_phy_reg_bm2 - Write BM PHY register
3254 * @hw: pointer to the HW structure
3255 * @offset: register offset to write to
3256 * @data: data to write at register offset
3258 * Acquires semaphore, if necessary, then writes the data to PHY register
3259 * at the offset. Release any acquired semaphores before exiting.
3261 s32 e1000_write_phy_reg_bm2(struct e1000_hw *hw, u32 offset, u16 data)
3264 u16 page = (u16)(offset >> IGP_PAGE_SHIFT);
3266 DEBUGFUNC("e1000_write_phy_reg_bm2");
3268 ret_val = hw->phy.ops.acquire(hw);
3272 /* Page 800 works differently than the rest so it has its own func */
3273 if (page == BM_WUC_PAGE) {
3274 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, &data,
3281 if (offset > MAX_PHY_MULTI_PAGE_REG) {
3282 /* Page is shifted left, PHY expects (page x 32) */
3283 ret_val = e1000_write_phy_reg_mdic(hw, BM_PHY_PAGE_SELECT,
3290 ret_val = e1000_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
3294 hw->phy.ops.release(hw);
3299 * e1000_enable_phy_wakeup_reg_access_bm - enable access to BM wakeup registers
3300 * @hw: pointer to the HW structure
3301 * @phy_reg: pointer to store original contents of BM_WUC_ENABLE_REG
3303 * Assumes semaphore already acquired and phy_reg points to a valid memory
3304 * address to store contents of the BM_WUC_ENABLE_REG register.
3306 s32 e1000_enable_phy_wakeup_reg_access_bm(struct e1000_hw *hw, u16 *phy_reg)
3311 DEBUGFUNC("e1000_enable_phy_wakeup_reg_access_bm");
3314 return -E1000_ERR_PARAM;
3316 /* All page select, port ctrl and wakeup registers use phy address 1 */
3319 /* Select Port Control Registers page */
3320 ret_val = e1000_set_page_igp(hw, (BM_PORT_CTRL_PAGE << IGP_PAGE_SHIFT));
3322 DEBUGOUT("Could not set Port Control page\n");
3326 ret_val = e1000_read_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, phy_reg);
3328 DEBUGOUT2("Could not read PHY register %d.%d\n",
3329 BM_PORT_CTRL_PAGE, BM_WUC_ENABLE_REG);
3333 /* Enable both PHY wakeup mode and Wakeup register page writes.
3334 * Prevent a power state change by disabling ME and Host PHY wakeup.
3337 temp |= BM_WUC_ENABLE_BIT;
3338 temp &= ~(BM_WUC_ME_WU_BIT | BM_WUC_HOST_WU_BIT);
3340 ret_val = e1000_write_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, temp);
3342 DEBUGOUT2("Could not write PHY register %d.%d\n",
3343 BM_PORT_CTRL_PAGE, BM_WUC_ENABLE_REG);
3347 /* Select Host Wakeup Registers page - caller now able to write
3348 * registers on the Wakeup registers page
3350 return e1000_set_page_igp(hw, (BM_WUC_PAGE << IGP_PAGE_SHIFT));
3354 * e1000_disable_phy_wakeup_reg_access_bm - disable access to BM wakeup regs
3355 * @hw: pointer to the HW structure
3356 * @phy_reg: pointer to original contents of BM_WUC_ENABLE_REG
3358 * Restore BM_WUC_ENABLE_REG to its original value.
3360 * Assumes semaphore already acquired and *phy_reg is the contents of the
3361 * BM_WUC_ENABLE_REG before register(s) on BM_WUC_PAGE were accessed by
3364 s32 e1000_disable_phy_wakeup_reg_access_bm(struct e1000_hw *hw, u16 *phy_reg)
3368 DEBUGFUNC("e1000_disable_phy_wakeup_reg_access_bm");
3371 return -E1000_ERR_PARAM;
3373 /* Select Port Control Registers page */
3374 ret_val = e1000_set_page_igp(hw, (BM_PORT_CTRL_PAGE << IGP_PAGE_SHIFT));
3376 DEBUGOUT("Could not set Port Control page\n");
3380 /* Restore 769.17 to its original value */
3381 ret_val = e1000_write_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, *phy_reg);
3383 DEBUGOUT2("Could not restore PHY register %d.%d\n",
3384 BM_PORT_CTRL_PAGE, BM_WUC_ENABLE_REG);
3390 * e1000_access_phy_wakeup_reg_bm - Read/write BM PHY wakeup register
3391 * @hw: pointer to the HW structure
3392 * @offset: register offset to be read or written
3393 * @data: pointer to the data to read or write
3394 * @read: determines if operation is read or write
3395 * @page_set: BM_WUC_PAGE already set and access enabled
3397 * Read the PHY register at offset and store the retrieved information in
3398 * data, or write data to PHY register at offset. Note the procedure to
3399 * access the PHY wakeup registers is different than reading the other PHY
3400 * registers. It works as such:
3401 * 1) Set 769.17.2 (page 769, register 17, bit 2) = 1
3402 * 2) Set page to 800 for host (801 if we were manageability)
3403 * 3) Write the address using the address opcode (0x11)
3404 * 4) Read or write the data using the data opcode (0x12)
3405 * 5) Restore 769.17.2 to its original value
3407 * Steps 1 and 2 are done by e1000_enable_phy_wakeup_reg_access_bm() and
3408 * step 5 is done by e1000_disable_phy_wakeup_reg_access_bm().
3410 * Assumes semaphore is already acquired. When page_set==true, assumes
3411 * the PHY page is set to BM_WUC_PAGE (i.e. a function in the call stack
3412 * is responsible for calls to e1000_[enable|disable]_phy_wakeup_reg_bm()).
3414 STATIC s32 e1000_access_phy_wakeup_reg_bm(struct e1000_hw *hw, u32 offset,
3415 u16 *data, bool read, bool page_set)
3418 u16 reg = BM_PHY_REG_NUM(offset);
3419 u16 page = BM_PHY_REG_PAGE(offset);
3422 DEBUGFUNC("e1000_access_phy_wakeup_reg_bm");
3424 /* Gig must be disabled for MDIO accesses to Host Wakeup reg page */
3425 if ((hw->mac.type == e1000_pchlan) &&
3426 (!(E1000_READ_REG(hw, E1000_PHY_CTRL) & E1000_PHY_CTRL_GBE_DISABLE)))
3427 DEBUGOUT1("Attempting to access page %d while gig enabled.\n",
3431 /* Enable access to PHY wakeup registers */
3432 ret_val = e1000_enable_phy_wakeup_reg_access_bm(hw, &phy_reg);
3434 DEBUGOUT("Could not enable PHY wakeup reg access\n");
3439 DEBUGOUT2("Accessing PHY page %d reg 0x%x\n", page, reg);
3441 /* Write the Wakeup register page offset value using opcode 0x11 */
3442 ret_val = e1000_write_phy_reg_mdic(hw, BM_WUC_ADDRESS_OPCODE, reg);
3444 DEBUGOUT1("Could not write address opcode to page %d\n", page);
3449 /* Read the Wakeup register page value using opcode 0x12 */
3450 ret_val = e1000_read_phy_reg_mdic(hw, BM_WUC_DATA_OPCODE,
3453 /* Write the Wakeup register page value using opcode 0x12 */
3454 ret_val = e1000_write_phy_reg_mdic(hw, BM_WUC_DATA_OPCODE,
3459 DEBUGOUT2("Could not access PHY reg %d.%d\n", page, reg);
3464 ret_val = e1000_disable_phy_wakeup_reg_access_bm(hw, &phy_reg);
3470 * e1000_power_up_phy_copper - Restore copper link in case of PHY power down
3471 * @hw: pointer to the HW structure
3473 * In the case of a PHY power down to save power, or to turn off link during a
3474 * driver unload, or wake on lan is not enabled, restore the link to previous
3477 void e1000_power_up_phy_copper(struct e1000_hw *hw)
3481 /* The PHY will retain its settings across a power down/up cycle */
3482 hw->phy.ops.read_reg(hw, PHY_CONTROL, &mii_reg);
3483 mii_reg &= ~MII_CR_POWER_DOWN;
3484 hw->phy.ops.write_reg(hw, PHY_CONTROL, mii_reg);
3488 * e1000_power_down_phy_copper - Restore copper link in case of PHY power down
3489 * @hw: pointer to the HW structure
3491 * In the case of a PHY power down to save power, or to turn off link during a
3492 * driver unload, or wake on lan is not enabled, restore the link to previous
3495 void e1000_power_down_phy_copper(struct e1000_hw *hw)
3499 /* The PHY will retain its settings across a power down/up cycle */
3500 hw->phy.ops.read_reg(hw, PHY_CONTROL, &mii_reg);
3501 mii_reg |= MII_CR_POWER_DOWN;
3502 hw->phy.ops.write_reg(hw, PHY_CONTROL, mii_reg);
3507 * __e1000_read_phy_reg_hv - Read HV PHY register
3508 * @hw: pointer to the HW structure
3509 * @offset: register offset to be read
3510 * @data: pointer to the read data
3511 * @locked: semaphore has already been acquired or not
3512 * @page_set: BM_WUC_PAGE already set and access enabled
3514 * Acquires semaphore, if necessary, then reads the PHY register at offset
3515 * and stores the retrieved information in data. Release any acquired
3516 * semaphore before exiting.
3518 STATIC s32 __e1000_read_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 *data,
3519 bool locked, bool page_set)
3522 u16 page = BM_PHY_REG_PAGE(offset);
3523 u16 reg = BM_PHY_REG_NUM(offset);
3524 u32 phy_addr = hw->phy.addr = e1000_get_phy_addr_for_hv_page(page);
3526 DEBUGFUNC("__e1000_read_phy_reg_hv");
3529 ret_val = hw->phy.ops.acquire(hw);
3533 /* Page 800 works differently than the rest so it has its own func */
3534 if (page == BM_WUC_PAGE) {
3535 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, data,
3540 if (page > 0 && page < HV_INTC_FC_PAGE_START) {
3541 ret_val = e1000_access_phy_debug_regs_hv(hw, offset,
3547 if (page == HV_INTC_FC_PAGE_START)
3550 if (reg > MAX_PHY_MULTI_PAGE_REG) {
3551 /* Page is shifted left, PHY expects (page x 32) */
3552 ret_val = e1000_set_page_igp(hw,
3553 (page << IGP_PAGE_SHIFT));
3555 hw->phy.addr = phy_addr;
3562 DEBUGOUT3("reading PHY page %d (or 0x%x shifted) reg 0x%x\n", page,
3563 page << IGP_PAGE_SHIFT, reg);
3565 ret_val = e1000_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & reg,
3569 hw->phy.ops.release(hw);
3575 * e1000_read_phy_reg_hv - Read HV PHY register
3576 * @hw: pointer to the HW structure
3577 * @offset: register offset to be read
3578 * @data: pointer to the read data
3580 * Acquires semaphore then reads the PHY register at offset and stores
3581 * the retrieved information in data. Release the acquired semaphore
3584 s32 e1000_read_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 *data)
3586 return __e1000_read_phy_reg_hv(hw, offset, data, false, false);
3590 * e1000_read_phy_reg_hv_locked - Read HV PHY register
3591 * @hw: pointer to the HW structure
3592 * @offset: register offset to be read
3593 * @data: pointer to the read data
3595 * Reads the PHY register at offset and stores the retrieved information
3596 * in data. Assumes semaphore already acquired.
3598 s32 e1000_read_phy_reg_hv_locked(struct e1000_hw *hw, u32 offset, u16 *data)
3600 return __e1000_read_phy_reg_hv(hw, offset, data, true, false);
3604 * e1000_read_phy_reg_page_hv - Read HV PHY register
3605 * @hw: pointer to the HW structure
3606 * @offset: register offset to write to
3607 * @data: data to write at register offset
3609 * Reads the PHY register at offset and stores the retrieved information
3610 * in data. Assumes semaphore already acquired and page already set.
3612 s32 e1000_read_phy_reg_page_hv(struct e1000_hw *hw, u32 offset, u16 *data)
3614 return __e1000_read_phy_reg_hv(hw, offset, data, true, true);
3618 * __e1000_write_phy_reg_hv - Write HV PHY register
3619 * @hw: pointer to the HW structure
3620 * @offset: register offset to write to
3621 * @data: data to write at register offset
3622 * @locked: semaphore has already been acquired or not
3623 * @page_set: BM_WUC_PAGE already set and access enabled
3625 * Acquires semaphore, if necessary, then writes the data to PHY register
3626 * at the offset. Release any acquired semaphores before exiting.
3628 STATIC s32 __e1000_write_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 data,
3629 bool locked, bool page_set)
3632 u16 page = BM_PHY_REG_PAGE(offset);
3633 u16 reg = BM_PHY_REG_NUM(offset);
3634 u32 phy_addr = hw->phy.addr = e1000_get_phy_addr_for_hv_page(page);
3636 DEBUGFUNC("__e1000_write_phy_reg_hv");
3639 ret_val = hw->phy.ops.acquire(hw);
3643 /* Page 800 works differently than the rest so it has its own func */
3644 if (page == BM_WUC_PAGE) {
3645 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, &data,
3650 if (page > 0 && page < HV_INTC_FC_PAGE_START) {
3651 ret_val = e1000_access_phy_debug_regs_hv(hw, offset,
3657 if (page == HV_INTC_FC_PAGE_START)
3660 /* Workaround MDIO accesses being disabled after entering IEEE
3661 * Power Down (when bit 11 of the PHY Control register is set)
3663 if ((hw->phy.type == e1000_phy_82578) &&
3664 (hw->phy.revision >= 1) &&
3665 (hw->phy.addr == 2) &&
3666 !(MAX_PHY_REG_ADDRESS & reg) &&
3667 (data & (1 << 11))) {
3669 ret_val = e1000_access_phy_debug_regs_hv(hw,
3676 if (reg > MAX_PHY_MULTI_PAGE_REG) {
3677 /* Page is shifted left, PHY expects (page x 32) */
3678 ret_val = e1000_set_page_igp(hw,
3679 (page << IGP_PAGE_SHIFT));
3681 hw->phy.addr = phy_addr;
3688 DEBUGOUT3("writing PHY page %d (or 0x%x shifted) reg 0x%x\n", page,
3689 page << IGP_PAGE_SHIFT, reg);
3691 ret_val = e1000_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & reg,
3696 hw->phy.ops.release(hw);
3702 * e1000_write_phy_reg_hv - Write HV PHY register
3703 * @hw: pointer to the HW structure
3704 * @offset: register offset to write to
3705 * @data: data to write at register offset
3707 * Acquires semaphore then writes the data to PHY register at the offset.
3708 * Release the acquired semaphores before exiting.
3710 s32 e1000_write_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 data)
3712 return __e1000_write_phy_reg_hv(hw, offset, data, false, false);
3716 * e1000_write_phy_reg_hv_locked - Write HV PHY register
3717 * @hw: pointer to the HW structure
3718 * @offset: register offset to write to
3719 * @data: data to write at register offset
3721 * Writes the data to PHY register at the offset. Assumes semaphore
3724 s32 e1000_write_phy_reg_hv_locked(struct e1000_hw *hw, u32 offset, u16 data)
3726 return __e1000_write_phy_reg_hv(hw, offset, data, true, false);
3730 * e1000_write_phy_reg_page_hv - Write HV PHY register
3731 * @hw: pointer to the HW structure
3732 * @offset: register offset to write to
3733 * @data: data to write at register offset
3735 * Writes the data to PHY register at the offset. Assumes semaphore
3736 * already acquired and page already set.
3738 s32 e1000_write_phy_reg_page_hv(struct e1000_hw *hw, u32 offset, u16 data)
3740 return __e1000_write_phy_reg_hv(hw, offset, data, true, true);
3744 * e1000_get_phy_addr_for_hv_page - Get PHY adrress based on page
3745 * @page: page to be accessed
3747 STATIC u32 e1000_get_phy_addr_for_hv_page(u32 page)
3751 if (page >= HV_INTC_FC_PAGE_START)
3758 * e1000_access_phy_debug_regs_hv - Read HV PHY vendor specific high registers
3759 * @hw: pointer to the HW structure
3760 * @offset: register offset to be read or written
3761 * @data: pointer to the data to be read or written
3762 * @read: determines if operation is read or write
3764 * Reads the PHY register at offset and stores the retreived information
3765 * in data. Assumes semaphore already acquired. Note that the procedure
3766 * to access these regs uses the address port and data port to read/write.
3767 * These accesses done with PHY address 2 and without using pages.
3769 STATIC s32 e1000_access_phy_debug_regs_hv(struct e1000_hw *hw, u32 offset,
3770 u16 *data, bool read)
3776 DEBUGFUNC("e1000_access_phy_debug_regs_hv");
3778 /* This takes care of the difference with desktop vs mobile phy */
3779 addr_reg = ((hw->phy.type == e1000_phy_82578) ?
3780 I82578_ADDR_REG : I82577_ADDR_REG);
3781 data_reg = addr_reg + 1;
3783 /* All operations in this function are phy address 2 */
3786 /* masking with 0x3F to remove the page from offset */
3787 ret_val = e1000_write_phy_reg_mdic(hw, addr_reg, (u16)offset & 0x3F);
3789 DEBUGOUT("Could not write the Address Offset port register\n");
3793 /* Read or write the data value next */
3795 ret_val = e1000_read_phy_reg_mdic(hw, data_reg, data);
3797 ret_val = e1000_write_phy_reg_mdic(hw, data_reg, *data);
3800 DEBUGOUT("Could not access the Data port register\n");
3806 * e1000_link_stall_workaround_hv - Si workaround
3807 * @hw: pointer to the HW structure
3809 * This function works around a Si bug where the link partner can get
3810 * a link up indication before the PHY does. If small packets are sent
3811 * by the link partner they can be placed in the packet buffer without
3812 * being properly accounted for by the PHY and will stall preventing
3813 * further packets from being received. The workaround is to clear the
3814 * packet buffer after the PHY detects link up.
3816 s32 e1000_link_stall_workaround_hv(struct e1000_hw *hw)
3818 s32 ret_val = E1000_SUCCESS;
3821 DEBUGFUNC("e1000_link_stall_workaround_hv");
3823 if (hw->phy.type != e1000_phy_82578)
3824 return E1000_SUCCESS;
3826 /* Do not apply workaround if in PHY loopback bit 14 set */
3827 hw->phy.ops.read_reg(hw, PHY_CONTROL, &data);
3828 if (data & PHY_CONTROL_LB)
3829 return E1000_SUCCESS;
3831 /* check if link is up and at 1Gbps */
3832 ret_val = hw->phy.ops.read_reg(hw, BM_CS_STATUS, &data);
3836 data &= (BM_CS_STATUS_LINK_UP | BM_CS_STATUS_RESOLVED |
3837 BM_CS_STATUS_SPEED_MASK);
3839 if (data != (BM_CS_STATUS_LINK_UP | BM_CS_STATUS_RESOLVED |
3840 BM_CS_STATUS_SPEED_1000))
3841 return E1000_SUCCESS;
3845 /* flush the packets in the fifo buffer */
3846 ret_val = hw->phy.ops.write_reg(hw, HV_MUX_DATA_CTRL,
3847 (HV_MUX_DATA_CTRL_GEN_TO_MAC |
3848 HV_MUX_DATA_CTRL_FORCE_SPEED));
3852 return hw->phy.ops.write_reg(hw, HV_MUX_DATA_CTRL,
3853 HV_MUX_DATA_CTRL_GEN_TO_MAC);
3857 * e1000_check_polarity_82577 - Checks the polarity.
3858 * @hw: pointer to the HW structure
3860 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
3862 * Polarity is determined based on the PHY specific status register.
3864 s32 e1000_check_polarity_82577(struct e1000_hw *hw)
3866 struct e1000_phy_info *phy = &hw->phy;
3870 DEBUGFUNC("e1000_check_polarity_82577");
3872 ret_val = phy->ops.read_reg(hw, I82577_PHY_STATUS_2, &data);
3875 phy->cable_polarity = ((data & I82577_PHY_STATUS2_REV_POLARITY)
3876 ? e1000_rev_polarity_reversed
3877 : e1000_rev_polarity_normal);
3883 * e1000_phy_force_speed_duplex_82577 - Force speed/duplex for I82577 PHY
3884 * @hw: pointer to the HW structure
3886 * Calls the PHY setup function to force speed and duplex.
3888 s32 e1000_phy_force_speed_duplex_82577(struct e1000_hw *hw)
3890 struct e1000_phy_info *phy = &hw->phy;
3895 DEBUGFUNC("e1000_phy_force_speed_duplex_82577");
3897 ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_data);
3901 e1000_phy_force_speed_duplex_setup(hw, &phy_data);
3903 ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data);
3909 if (phy->autoneg_wait_to_complete) {
3910 DEBUGOUT("Waiting for forced speed/duplex link on 82577 phy\n");
3912 ret_val = e1000_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
3918 DEBUGOUT("Link taking longer than expected.\n");
3921 ret_val = e1000_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
3929 * e1000_get_phy_info_82577 - Retrieve I82577 PHY information
3930 * @hw: pointer to the HW structure
3932 * Read PHY status to determine if link is up. If link is up, then
3933 * set/determine 10base-T extended distance and polarity correction. Read
3934 * PHY port status to determine MDI/MDIx and speed. Based on the speed,
3935 * determine on the cable length, local and remote receiver.
3937 s32 e1000_get_phy_info_82577(struct e1000_hw *hw)
3939 struct e1000_phy_info *phy = &hw->phy;
3944 DEBUGFUNC("e1000_get_phy_info_82577");
3946 ret_val = e1000_phy_has_link_generic(hw, 1, 0, &link);
3951 DEBUGOUT("Phy info is only valid if link is up\n");
3952 return -E1000_ERR_CONFIG;
3955 phy->polarity_correction = true;
3957 ret_val = e1000_check_polarity_82577(hw);
3961 ret_val = phy->ops.read_reg(hw, I82577_PHY_STATUS_2, &data);
3965 phy->is_mdix = !!(data & I82577_PHY_STATUS2_MDIX);
3967 if ((data & I82577_PHY_STATUS2_SPEED_MASK) ==
3968 I82577_PHY_STATUS2_SPEED_1000MBPS) {
3969 ret_val = hw->phy.ops.get_cable_length(hw);
3973 ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &data);
3977 phy->local_rx = (data & SR_1000T_LOCAL_RX_STATUS)
3978 ? e1000_1000t_rx_status_ok
3979 : e1000_1000t_rx_status_not_ok;
3981 phy->remote_rx = (data & SR_1000T_REMOTE_RX_STATUS)
3982 ? e1000_1000t_rx_status_ok
3983 : e1000_1000t_rx_status_not_ok;
3985 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
3986 phy->local_rx = e1000_1000t_rx_status_undefined;
3987 phy->remote_rx = e1000_1000t_rx_status_undefined;
3990 return E1000_SUCCESS;
3994 * e1000_get_cable_length_82577 - Determine cable length for 82577 PHY
3995 * @hw: pointer to the HW structure
3997 * Reads the diagnostic status register and verifies result is valid before
3998 * placing it in the phy_cable_length field.
4000 s32 e1000_get_cable_length_82577(struct e1000_hw *hw)
4002 struct e1000_phy_info *phy = &hw->phy;
4004 u16 phy_data, length;
4006 DEBUGFUNC("e1000_get_cable_length_82577");
4008 ret_val = phy->ops.read_reg(hw, I82577_PHY_DIAG_STATUS, &phy_data);
4012 length = ((phy_data & I82577_DSTATUS_CABLE_LENGTH) >>
4013 I82577_DSTATUS_CABLE_LENGTH_SHIFT);
4015 if (length == E1000_CABLE_LENGTH_UNDEFINED)
4016 return -E1000_ERR_PHY;
4018 phy->cable_length = length;
4020 return E1000_SUCCESS;
4024 * e1000_write_phy_reg_gs40g - Write GS40G PHY register
4025 * @hw: pointer to the HW structure
4026 * @offset: register offset to write to
4027 * @data: data to write at register offset
4029 * Acquires semaphore, if necessary, then writes the data to PHY register
4030 * at the offset. Release any acquired semaphores before exiting.
4032 s32 e1000_write_phy_reg_gs40g(struct e1000_hw *hw, u32 offset, u16 data)
4035 u16 page = offset >> GS40G_PAGE_SHIFT;
4037 DEBUGFUNC("e1000_write_phy_reg_gs40g");
4039 offset = offset & GS40G_OFFSET_MASK;
4040 ret_val = hw->phy.ops.acquire(hw);
4044 ret_val = e1000_write_phy_reg_mdic(hw, GS40G_PAGE_SELECT, page);
4047 ret_val = e1000_write_phy_reg_mdic(hw, offset, data);
4050 hw->phy.ops.release(hw);
4055 * e1000_read_phy_reg_gs40g - Read GS40G PHY register
4056 * @hw: pointer to the HW structure
4057 * @offset: lower half is register offset to read to
4058 * upper half is page to use.
4059 * @data: data to read at register offset
4061 * Acquires semaphore, if necessary, then reads the data in the PHY register
4062 * at the offset. Release any acquired semaphores before exiting.
4064 s32 e1000_read_phy_reg_gs40g(struct e1000_hw *hw, u32 offset, u16 *data)
4067 u16 page = offset >> GS40G_PAGE_SHIFT;
4069 DEBUGFUNC("e1000_read_phy_reg_gs40g");
4071 offset = offset & GS40G_OFFSET_MASK;
4072 ret_val = hw->phy.ops.acquire(hw);
4076 ret_val = e1000_write_phy_reg_mdic(hw, GS40G_PAGE_SELECT, page);
4079 ret_val = e1000_read_phy_reg_mdic(hw, offset, data);
4082 hw->phy.ops.release(hw);
4087 * e1000_read_phy_reg_mphy - Read mPHY control register
4088 * @hw: pointer to the HW structure
4089 * @address: address to be read
4090 * @data: pointer to the read data
4092 * Reads the mPHY control register in the PHY at offset and stores the
4093 * information read to data.
4095 s32 e1000_read_phy_reg_mphy(struct e1000_hw *hw, u32 address, u32 *data)
4098 bool locked = false;
4101 DEBUGFUNC("e1000_read_phy_reg_mphy");
4103 /* Check if mPHY is ready to read/write operations */
4104 ready = e1000_is_mphy_ready(hw);
4106 return -E1000_ERR_PHY;
4108 /* Check if mPHY access is disabled and enable it if so */
4109 mphy_ctrl = E1000_READ_REG(hw, E1000_MPHY_ADDR_CTRL);
4110 if (mphy_ctrl & E1000_MPHY_DIS_ACCESS) {
4112 ready = e1000_is_mphy_ready(hw);
4114 return -E1000_ERR_PHY;
4115 mphy_ctrl |= E1000_MPHY_ENA_ACCESS;
4116 E1000_WRITE_REG(hw, E1000_MPHY_ADDR_CTRL, mphy_ctrl);
4119 /* Set the address that we want to read */
4120 ready = e1000_is_mphy_ready(hw);
4122 return -E1000_ERR_PHY;
4124 /* We mask address, because we want to use only current lane */
4125 mphy_ctrl = (mphy_ctrl & ~E1000_MPHY_ADDRESS_MASK &
4126 ~E1000_MPHY_ADDRESS_FNC_OVERRIDE) |
4127 (address & E1000_MPHY_ADDRESS_MASK);
4128 E1000_WRITE_REG(hw, E1000_MPHY_ADDR_CTRL, mphy_ctrl);
4130 /* Read data from the address */
4131 ready = e1000_is_mphy_ready(hw);
4133 return -E1000_ERR_PHY;
4134 *data = E1000_READ_REG(hw, E1000_MPHY_DATA);
4136 /* Disable access to mPHY if it was originally disabled */
4138 ready = e1000_is_mphy_ready(hw);
4140 return -E1000_ERR_PHY;
4141 E1000_WRITE_REG(hw, E1000_MPHY_ADDR_CTRL,
4142 E1000_MPHY_DIS_ACCESS);
4145 return E1000_SUCCESS;
4149 * e1000_write_phy_reg_mphy - Write mPHY control register
4150 * @hw: pointer to the HW structure
4151 * @address: address to write to
4152 * @data: data to write to register at offset
4153 * @line_override: used when we want to use different line than default one
4155 * Writes data to mPHY control register.
4157 s32 e1000_write_phy_reg_mphy(struct e1000_hw *hw, u32 address, u32 data,
4161 bool locked = false;
4164 DEBUGFUNC("e1000_write_phy_reg_mphy");
4166 /* Check if mPHY is ready to read/write operations */
4167 ready = e1000_is_mphy_ready(hw);
4169 return -E1000_ERR_PHY;
4171 /* Check if mPHY access is disabled and enable it if so */
4172 mphy_ctrl = E1000_READ_REG(hw, E1000_MPHY_ADDR_CTRL);
4173 if (mphy_ctrl & E1000_MPHY_DIS_ACCESS) {
4175 ready = e1000_is_mphy_ready(hw);
4177 return -E1000_ERR_PHY;
4178 mphy_ctrl |= E1000_MPHY_ENA_ACCESS;
4179 E1000_WRITE_REG(hw, E1000_MPHY_ADDR_CTRL, mphy_ctrl);
4182 /* Set the address that we want to read */
4183 ready = e1000_is_mphy_ready(hw);
4185 return -E1000_ERR_PHY;
4187 /* We mask address, because we want to use only current lane */
4189 mphy_ctrl |= E1000_MPHY_ADDRESS_FNC_OVERRIDE;
4191 mphy_ctrl &= ~E1000_MPHY_ADDRESS_FNC_OVERRIDE;
4192 mphy_ctrl = (mphy_ctrl & ~E1000_MPHY_ADDRESS_MASK) |
4193 (address & E1000_MPHY_ADDRESS_MASK);
4194 E1000_WRITE_REG(hw, E1000_MPHY_ADDR_CTRL, mphy_ctrl);
4196 /* Read data from the address */
4197 ready = e1000_is_mphy_ready(hw);
4199 return -E1000_ERR_PHY;
4200 E1000_WRITE_REG(hw, E1000_MPHY_DATA, data);
4202 /* Disable access to mPHY if it was originally disabled */
4204 ready = e1000_is_mphy_ready(hw);
4206 return -E1000_ERR_PHY;
4207 E1000_WRITE_REG(hw, E1000_MPHY_ADDR_CTRL,
4208 E1000_MPHY_DIS_ACCESS);
4211 return E1000_SUCCESS;
4215 * e1000_is_mphy_ready - Check if mPHY control register is not busy
4216 * @hw: pointer to the HW structure
4218 * Returns mPHY control register status.
4220 bool e1000_is_mphy_ready(struct e1000_hw *hw)
4222 u16 retry_count = 0;
4226 while (retry_count < 2) {
4227 mphy_ctrl = E1000_READ_REG(hw, E1000_MPHY_ADDR_CTRL);
4228 if (mphy_ctrl & E1000_MPHY_BUSY) {
4238 DEBUGOUT("ERROR READING mPHY control register, phy is busy.\n");
4244 * __e1000_access_xmdio_reg - Read/write XMDIO register
4245 * @hw: pointer to the HW structure
4246 * @address: XMDIO address to program
4247 * @dev_addr: device address to program
4248 * @data: pointer to value to read/write from/to the XMDIO address
4249 * @read: boolean flag to indicate read or write
4251 STATIC s32 __e1000_access_xmdio_reg(struct e1000_hw *hw, u16 address,
4252 u8 dev_addr, u16 *data, bool read)
4256 DEBUGFUNC("__e1000_access_xmdio_reg");
4258 ret_val = hw->phy.ops.write_reg(hw, E1000_MMDAC, dev_addr);
4262 ret_val = hw->phy.ops.write_reg(hw, E1000_MMDAAD, address);
4266 ret_val = hw->phy.ops.write_reg(hw, E1000_MMDAC, E1000_MMDAC_FUNC_DATA |
4272 ret_val = hw->phy.ops.read_reg(hw, E1000_MMDAAD, data);
4274 ret_val = hw->phy.ops.write_reg(hw, E1000_MMDAAD, *data);
4278 /* Recalibrate the device back to 0 */
4279 ret_val = hw->phy.ops.write_reg(hw, E1000_MMDAC, 0);
4287 * e1000_read_xmdio_reg - Read XMDIO register
4288 * @hw: pointer to the HW structure
4289 * @addr: XMDIO address to program
4290 * @dev_addr: device address to program
4291 * @data: value to be read from the EMI address
4293 s32 e1000_read_xmdio_reg(struct e1000_hw *hw, u16 addr, u8 dev_addr, u16 *data)
4295 DEBUGFUNC("e1000_read_xmdio_reg");
4297 return __e1000_access_xmdio_reg(hw, addr, dev_addr, data, true);
4301 * e1000_write_xmdio_reg - Write XMDIO register
4302 * @hw: pointer to the HW structure
4303 * @addr: XMDIO address to program
4304 * @dev_addr: device address to program
4305 * @data: value to be written to the XMDIO address
4307 s32 e1000_write_xmdio_reg(struct e1000_hw *hw, u16 addr, u8 dev_addr, u16 data)
4309 DEBUGFUNC("e1000_write_xmdio_reg");
4311 return __e1000_access_xmdio_reg(hw, addr, dev_addr, &data,