aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/e1000e/phy.c
diff options
context:
space:
mode:
authorBruce Allan <bruce.w.allan@intel.com>2009-06-02 07:29:18 -0400
committerDavid S. Miller <davem@davemloft.net>2009-06-03 05:46:34 -0400
commita4f58f5455ba0efda36fb33c37074922d1527a10 (patch)
tree98aa6d14824b7c1b7907e703abedd80219e0abda /drivers/net/e1000e/phy.c
parent2adc55c959940fc680074392eddbd5585a76f3d9 (diff)
e1000e: add support for 82577/82578 GbE LOM parts
This patch provides support for the next generation Intel desktop and mobile gigabit ethernet LOM adapters. These adapters are the follow-on parts to the LOMs tied to the prior ICH chipsets and are comprised of a MAC in the PCH chipset and an external PHY (82577 for mobile and 82578 for desktop versions). New features consist of PHY wakeup to save power by completely turning off the MAC while in Sx state, and 4K jumbo frames. Signed-off-by: Bruce Allan <bruce.w.allan@intel.com> Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/e1000e/phy.c')
-rw-r--r--drivers/net/e1000e/phy.c699
1 files changed, 682 insertions, 17 deletions
diff --git a/drivers/net/e1000e/phy.c b/drivers/net/e1000e/phy.c
index dc4a9cba6a73..e23459cf3d0e 100644
--- a/drivers/net/e1000e/phy.c
+++ b/drivers/net/e1000e/phy.c
@@ -37,6 +37,9 @@ static s32 e1000_wait_autoneg(struct e1000_hw *hw);
37static u32 e1000_get_phy_addr_for_bm_page(u32 page, u32 reg); 37static u32 e1000_get_phy_addr_for_bm_page(u32 page, u32 reg);
38static s32 e1000_access_phy_wakeup_reg_bm(struct e1000_hw *hw, u32 offset, 38static s32 e1000_access_phy_wakeup_reg_bm(struct e1000_hw *hw, u32 offset,
39 u16 *data, bool read); 39 u16 *data, bool read);
40static u32 e1000_get_phy_addr_for_hv_page(u32 page);
41static s32 e1000_access_phy_debug_regs_hv(struct e1000_hw *hw, u32 offset,
42 u16 *data, bool read);
40 43
41/* Cable length tables */ 44/* Cable length tables */
42static const u16 e1000_m88_cable_length_table[] = 45static const u16 e1000_m88_cable_length_table[] =
@@ -54,6 +57,55 @@ static const u16 e1000_igp_2_cable_length_table[] =
54#define IGP02E1000_CABLE_LENGTH_TABLE_SIZE \ 57#define IGP02E1000_CABLE_LENGTH_TABLE_SIZE \
55 ARRAY_SIZE(e1000_igp_2_cable_length_table) 58 ARRAY_SIZE(e1000_igp_2_cable_length_table)
56 59
60#define BM_PHY_REG_PAGE(offset) \
61 ((u16)(((offset) >> PHY_PAGE_SHIFT) & 0xFFFF))
62#define BM_PHY_REG_NUM(offset) \
63 ((u16)(((offset) & MAX_PHY_REG_ADDRESS) |\
64 (((offset) >> (PHY_UPPER_SHIFT - PHY_PAGE_SHIFT)) &\
65 ~MAX_PHY_REG_ADDRESS)))
66
67#define HV_INTC_FC_PAGE_START 768
68#define I82578_ADDR_REG 29
69#define I82577_ADDR_REG 16
70#define I82577_CFG_REG 22
71#define I82577_CFG_ASSERT_CRS_ON_TX (1 << 15)
72#define I82577_CFG_ENABLE_DOWNSHIFT (3 << 10) /* auto downshift 100/10 */
73#define I82577_CTRL_REG 23
74#define I82577_CTRL_DOWNSHIFT_MASK (7 << 10)
75
76/* 82577 specific PHY registers */
77#define I82577_PHY_CTRL_2 18
78#define I82577_PHY_STATUS_2 26
79#define I82577_PHY_DIAG_STATUS 31
80
81/* I82577 PHY Status 2 */
82#define I82577_PHY_STATUS2_REV_POLARITY 0x0400
83#define I82577_PHY_STATUS2_MDIX 0x0800
84#define I82577_PHY_STATUS2_SPEED_MASK 0x0300
85#define I82577_PHY_STATUS2_SPEED_1000MBPS 0x0200
86
87/* I82577 PHY Control 2 */
88#define I82577_PHY_CTRL2_AUTO_MDIX 0x0400
89#define I82577_PHY_CTRL2_FORCE_MDI_MDIX 0x0200
90
91/* I82577 PHY Diagnostics Status */
92#define I82577_DSTATUS_CABLE_LENGTH 0x03FC
93#define I82577_DSTATUS_CABLE_LENGTH_SHIFT 2
94
95/* BM PHY Copper Specific Control 1 */
96#define BM_CS_CTRL1 16
97
98/* BM PHY Copper Specific Status */
99#define BM_CS_STATUS 17
100#define BM_CS_STATUS_LINK_UP 0x0400
101#define BM_CS_STATUS_RESOLVED 0x0800
102#define BM_CS_STATUS_SPEED_MASK 0xC000
103#define BM_CS_STATUS_SPEED_1000 0x8000
104
105#define HV_MUX_DATA_CTRL PHY_REG(776, 16)
106#define HV_MUX_DATA_CTRL_GEN_TO_MAC 0x0400
107#define HV_MUX_DATA_CTRL_FORCE_SPEED 0x0004
108
57/** 109/**
58 * e1000e_check_reset_block_generic - Check if PHY reset is blocked 110 * e1000e_check_reset_block_generic - Check if PHY reset is blocked
59 * @hw: pointer to the HW structure 111 * @hw: pointer to the HW structure
@@ -82,23 +134,48 @@ s32 e1000e_check_reset_block_generic(struct e1000_hw *hw)
82s32 e1000e_get_phy_id(struct e1000_hw *hw) 134s32 e1000e_get_phy_id(struct e1000_hw *hw)
83{ 135{
84 struct e1000_phy_info *phy = &hw->phy; 136 struct e1000_phy_info *phy = &hw->phy;
85 s32 ret_val; 137 s32 ret_val = 0;
86 u16 phy_id; 138 u16 phy_id;
139 u16 retry_count = 0;
87 140
88 ret_val = e1e_rphy(hw, PHY_ID1, &phy_id); 141 if (!(phy->ops.read_phy_reg))
89 if (ret_val) 142 goto out;
90 return ret_val;
91 143
92 phy->id = (u32)(phy_id << 16); 144 while (retry_count < 2) {
93 udelay(20); 145 ret_val = e1e_rphy(hw, PHY_ID1, &phy_id);
94 ret_val = e1e_rphy(hw, PHY_ID2, &phy_id); 146 if (ret_val)
95 if (ret_val) 147 goto out;
96 return ret_val;
97 148
98 phy->id |= (u32)(phy_id & PHY_REVISION_MASK); 149 phy->id = (u32)(phy_id << 16);
99 phy->revision = (u32)(phy_id & ~PHY_REVISION_MASK); 150 udelay(20);
151 ret_val = e1e_rphy(hw, PHY_ID2, &phy_id);
152 if (ret_val)
153 goto out;
100 154
101 return 0; 155 phy->id |= (u32)(phy_id & PHY_REVISION_MASK);
156 phy->revision = (u32)(phy_id & ~PHY_REVISION_MASK);
157
158 if (phy->id != 0 && phy->id != PHY_REVISION_MASK)
159 goto out;
160
161 /*
162 * If the PHY ID is still unknown, we may have an 82577i
163 * without link. We will try again after setting Slow
164 * MDIC mode. No harm in trying again in this case since
165 * the PHY ID is unknown at this point anyway
166 */
167 ret_val = e1000_set_mdio_slow_mode_hv(hw, true);
168 if (ret_val)
169 goto out;
170
171 retry_count++;
172 }
173out:
174 /* Revert to MDIO fast mode, if applicable */
175 if (retry_count)
176 ret_val = e1000_set_mdio_slow_mode_hv(hw, false);
177
178 return ret_val;
102} 179}
103 180
104/** 181/**
@@ -410,6 +487,43 @@ s32 e1000e_write_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 data)
410} 487}
411 488
412/** 489/**
490 * e1000_copper_link_setup_82577 - Setup 82577 PHY for copper link
491 * @hw: pointer to the HW structure
492 *
493 * Sets up Carrier-sense on Transmit and downshift values.
494 **/
495s32 e1000_copper_link_setup_82577(struct e1000_hw *hw)
496{
497 struct e1000_phy_info *phy = &hw->phy;
498 s32 ret_val;
499 u16 phy_data;
500
501 /* Enable CRS on TX. This must be set for half-duplex operation. */
502 ret_val = phy->ops.read_phy_reg(hw, I82577_CFG_REG, &phy_data);
503 if (ret_val)
504 goto out;
505
506 phy_data |= I82577_CFG_ASSERT_CRS_ON_TX;
507
508 /* Enable downshift */
509 phy_data |= I82577_CFG_ENABLE_DOWNSHIFT;
510
511 ret_val = phy->ops.write_phy_reg(hw, I82577_CFG_REG, phy_data);
512 if (ret_val)
513 goto out;
514
515 /* Set number of link attempts before downshift */
516 ret_val = phy->ops.read_phy_reg(hw, I82577_CTRL_REG, &phy_data);
517 if (ret_val)
518 goto out;
519 phy_data &= ~I82577_CTRL_DOWNSHIFT_MASK;
520 ret_val = phy->ops.write_phy_reg(hw, I82577_CTRL_REG, phy_data);
521
522out:
523 return ret_val;
524}
525
526/**
413 * e1000e_copper_link_setup_m88 - Setup m88 PHY's for copper link 527 * e1000e_copper_link_setup_m88 - Setup m88 PHY's for copper link
414 * @hw: pointer to the HW structure 528 * @hw: pointer to the HW structure
415 * 529 *
@@ -427,8 +541,8 @@ s32 e1000e_copper_link_setup_m88(struct e1000_hw *hw)
427 if (ret_val) 541 if (ret_val)
428 return ret_val; 542 return ret_val;
429 543
430 /* For newer PHYs this bit is downshift enable */ 544 /* For BM PHY this bit is downshift enable */
431 if (phy->type == e1000_phy_m88) 545 if (phy->type != e1000_phy_bm)
432 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX; 546 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
433 547
434 /* 548 /*
@@ -520,10 +634,27 @@ s32 e1000e_copper_link_setup_m88(struct e1000_hw *hw)
520 634
521 /* Commit the changes. */ 635 /* Commit the changes. */
522 ret_val = e1000e_commit_phy(hw); 636 ret_val = e1000e_commit_phy(hw);
523 if (ret_val) 637 if (ret_val) {
524 hw_dbg(hw, "Error committing the PHY changes\n"); 638 hw_dbg(hw, "Error committing the PHY changes\n");
639 return ret_val;
640 }
525 641
526 return ret_val; 642 if (phy->type == e1000_phy_82578) {
643 ret_val = phy->ops.read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
644 &phy_data);
645 if (ret_val)
646 return ret_val;
647
648 /* 82578 PHY - set the downshift count to 1x. */
649 phy_data |= I82578_EPSCR_DOWNSHIFT_ENABLE;
650 phy_data &= ~I82578_EPSCR_DOWNSHIFT_COUNTER_MASK;
651 ret_val = phy->ops.write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
652 phy_data);
653 if (ret_val)
654 return ret_val;
655 }
656
657 return 0;
527} 658}
528 659
529/** 660/**
@@ -1251,6 +1382,8 @@ s32 e1000e_check_downshift(struct e1000_hw *hw)
1251 switch (phy->type) { 1382 switch (phy->type) {
1252 case e1000_phy_m88: 1383 case e1000_phy_m88:
1253 case e1000_phy_gg82563: 1384 case e1000_phy_gg82563:
1385 case e1000_phy_82578:
1386 case e1000_phy_82577:
1254 offset = M88E1000_PHY_SPEC_STATUS; 1387 offset = M88E1000_PHY_SPEC_STATUS;
1255 mask = M88E1000_PSSR_DOWNSHIFT; 1388 mask = M88E1000_PSSR_DOWNSHIFT;
1256 break; 1389 break;
@@ -1886,6 +2019,12 @@ enum e1000_phy_type e1000e_get_phy_type_from_id(u32 phy_id)
1886 case BME1000_E_PHY_ID_R2: 2019 case BME1000_E_PHY_ID_R2:
1887 phy_type = e1000_phy_bm; 2020 phy_type = e1000_phy_bm;
1888 break; 2021 break;
2022 case I82578_E_PHY_ID:
2023 phy_type = e1000_phy_82578;
2024 break;
2025 case I82577_E_PHY_ID:
2026 phy_type = e1000_phy_82577;
2027 break;
1889 default: 2028 default:
1890 phy_type = e1000_phy_unknown; 2029 phy_type = e1000_phy_unknown;
1891 break; 2030 break;
@@ -2181,11 +2320,16 @@ static s32 e1000_access_phy_wakeup_reg_bm(struct e1000_hw *hw, u32 offset,
2181 u16 *data, bool read) 2320 u16 *data, bool read)
2182{ 2321{
2183 s32 ret_val; 2322 s32 ret_val;
2184 u16 reg = ((u16)offset) & PHY_REG_MASK; 2323 u16 reg = BM_PHY_REG_NUM(offset);
2185 u16 phy_reg = 0; 2324 u16 phy_reg = 0;
2186 u8 phy_acquired = 1; 2325 u8 phy_acquired = 1;
2187 2326
2188 2327
2328 /* Gig must be disabled for MDIO accesses to page 800 */
2329 if ((hw->mac.type == e1000_pchlan) &&
2330 (!(er32(PHY_CTRL) & E1000_PHY_CTRL_GBE_DISABLE)))
2331 hw_dbg(hw, "Attempting to access page 800 while gig enabled\n");
2332
2189 ret_val = hw->phy.ops.acquire_phy(hw); 2333 ret_val = hw->phy.ops.acquire_phy(hw);
2190 if (ret_val) { 2334 if (ret_val) {
2191 phy_acquired = 0; 2335 phy_acquired = 0;
@@ -2289,3 +2433,524 @@ static s32 e1000_set_d0_lplu_state(struct e1000_hw *hw, bool active)
2289 2433
2290 return 0; 2434 return 0;
2291} 2435}
2436
2437s32 e1000_set_mdio_slow_mode_hv(struct e1000_hw *hw, bool slow)
2438{
2439 s32 ret_val = 0;
2440 u16 data = 0;
2441
2442 ret_val = hw->phy.ops.acquire_phy(hw);
2443 if (ret_val)
2444 return ret_val;
2445
2446 /* Set MDIO mode - page 769, register 16: 0x2580==slow, 0x2180==fast */
2447 hw->phy.addr = 1;
2448 ret_val = e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
2449 (BM_PORT_CTRL_PAGE << IGP_PAGE_SHIFT));
2450 if (ret_val) {
2451 hw->phy.ops.release_phy(hw);
2452 return ret_val;
2453 }
2454 ret_val = e1000e_write_phy_reg_mdic(hw, BM_CS_CTRL1,
2455 (0x2180 | (slow << 10)));
2456
2457 /* dummy read when reverting to fast mode - throw away result */
2458 if (!slow)
2459 e1000e_read_phy_reg_mdic(hw, BM_CS_CTRL1, &data);
2460
2461 hw->phy.ops.release_phy(hw);
2462
2463 return ret_val;
2464}
2465
2466/**
2467 * e1000_read_phy_reg_hv - Read HV PHY register
2468 * @hw: pointer to the HW structure
2469 * @offset: register offset to be read
2470 * @data: pointer to the read data
2471 *
2472 * Acquires semaphore, if necessary, then reads the PHY register at offset
2473 * and storing the retrieved information in data. Release any acquired
2474 * semaphore before exiting.
2475 **/
2476s32 e1000_read_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 *data)
2477{
2478 s32 ret_val;
2479 u16 page = BM_PHY_REG_PAGE(offset);
2480 u16 reg = BM_PHY_REG_NUM(offset);
2481 bool in_slow_mode = false;
2482
2483 /* Workaround failure in MDIO access while cable is disconnected */
2484 if ((hw->phy.type == e1000_phy_82577) &&
2485 !(er32(STATUS) & E1000_STATUS_LU)) {
2486 ret_val = e1000_set_mdio_slow_mode_hv(hw, true);
2487 if (ret_val)
2488 goto out;
2489
2490 in_slow_mode = true;
2491 }
2492
2493 /* Page 800 works differently than the rest so it has its own func */
2494 if (page == BM_WUC_PAGE) {
2495 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset,
2496 data, true);
2497 goto out;
2498 }
2499
2500 if (page > 0 && page < HV_INTC_FC_PAGE_START) {
2501 ret_val = e1000_access_phy_debug_regs_hv(hw, offset,
2502 data, true);
2503 goto out;
2504 }
2505
2506 ret_val = hw->phy.ops.acquire_phy(hw);
2507 if (ret_val)
2508 goto out;
2509
2510 hw->phy.addr = e1000_get_phy_addr_for_hv_page(page);
2511
2512 if (page == HV_INTC_FC_PAGE_START)
2513 page = 0;
2514
2515 if (reg > MAX_PHY_MULTI_PAGE_REG) {
2516 if ((hw->phy.type != e1000_phy_82578) ||
2517 ((reg != I82578_ADDR_REG) &&
2518 (reg != I82578_ADDR_REG + 1))) {
2519 u32 phy_addr = hw->phy.addr;
2520
2521 hw->phy.addr = 1;
2522
2523 /* Page is shifted left, PHY expects (page x 32) */
2524 ret_val = e1000e_write_phy_reg_mdic(hw,
2525 IGP01E1000_PHY_PAGE_SELECT,
2526 (page << IGP_PAGE_SHIFT));
2527 if (ret_val) {
2528 hw->phy.ops.release_phy(hw);
2529 goto out;
2530 }
2531 hw->phy.addr = phy_addr;
2532 }
2533 }
2534
2535 ret_val = e1000e_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & reg,
2536 data);
2537 hw->phy.ops.release_phy(hw);
2538
2539out:
2540 /* Revert to MDIO fast mode, if applicable */
2541 if ((hw->phy.type == e1000_phy_82577) && in_slow_mode)
2542 ret_val = e1000_set_mdio_slow_mode_hv(hw, false);
2543
2544 return ret_val;
2545}
2546
2547/**
2548 * e1000_write_phy_reg_hv - Write HV PHY register
2549 * @hw: pointer to the HW structure
2550 * @offset: register offset to write to
2551 * @data: data to write at register offset
2552 *
2553 * Acquires semaphore, if necessary, then writes the data to PHY register
2554 * at the offset. Release any acquired semaphores before exiting.
2555 **/
2556s32 e1000_write_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 data)
2557{
2558 s32 ret_val;
2559 u16 page = BM_PHY_REG_PAGE(offset);
2560 u16 reg = BM_PHY_REG_NUM(offset);
2561 bool in_slow_mode = false;
2562
2563 /* Workaround failure in MDIO access while cable is disconnected */
2564 if ((hw->phy.type == e1000_phy_82577) &&
2565 !(er32(STATUS) & E1000_STATUS_LU)) {
2566 ret_val = e1000_set_mdio_slow_mode_hv(hw, true);
2567 if (ret_val)
2568 goto out;
2569
2570 in_slow_mode = true;
2571 }
2572
2573 /* Page 800 works differently than the rest so it has its own func */
2574 if (page == BM_WUC_PAGE) {
2575 ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset,
2576 &data, false);
2577 goto out;
2578 }
2579
2580 if (page > 0 && page < HV_INTC_FC_PAGE_START) {
2581 ret_val = e1000_access_phy_debug_regs_hv(hw, offset,
2582 &data, false);
2583 goto out;
2584 }
2585
2586 ret_val = hw->phy.ops.acquire_phy(hw);
2587 if (ret_val)
2588 goto out;
2589
2590 hw->phy.addr = e1000_get_phy_addr_for_hv_page(page);
2591
2592 if (page == HV_INTC_FC_PAGE_START)
2593 page = 0;
2594
2595 /*
2596 * Workaround MDIO accesses being disabled after entering IEEE Power
2597 * Down (whenever bit 11 of the PHY Control register is set)
2598 */
2599 if ((hw->phy.type == e1000_phy_82578) &&
2600 (hw->phy.revision >= 1) &&
2601 (hw->phy.addr == 2) &&
2602 ((MAX_PHY_REG_ADDRESS & reg) == 0) &&
2603 (data & (1 << 11))) {
2604 u16 data2 = 0x7EFF;
2605 hw->phy.ops.release_phy(hw);
2606 ret_val = e1000_access_phy_debug_regs_hv(hw, (1 << 6) | 0x3,
2607 &data2, false);
2608 if (ret_val)
2609 goto out;
2610
2611 ret_val = hw->phy.ops.acquire_phy(hw);
2612 if (ret_val)
2613 goto out;
2614 }
2615
2616 if (reg > MAX_PHY_MULTI_PAGE_REG) {
2617 if ((hw->phy.type != e1000_phy_82578) ||
2618 ((reg != I82578_ADDR_REG) &&
2619 (reg != I82578_ADDR_REG + 1))) {
2620 u32 phy_addr = hw->phy.addr;
2621
2622 hw->phy.addr = 1;
2623
2624 /* Page is shifted left, PHY expects (page x 32) */
2625 ret_val = e1000e_write_phy_reg_mdic(hw,
2626 IGP01E1000_PHY_PAGE_SELECT,
2627 (page << IGP_PAGE_SHIFT));
2628 if (ret_val) {
2629 hw->phy.ops.release_phy(hw);
2630 goto out;
2631 }
2632 hw->phy.addr = phy_addr;
2633 }
2634 }
2635
2636 ret_val = e1000e_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & reg,
2637 data);
2638 hw->phy.ops.release_phy(hw);
2639
2640out:
2641 /* Revert to MDIO fast mode, if applicable */
2642 if ((hw->phy.type == e1000_phy_82577) && in_slow_mode)
2643 ret_val = e1000_set_mdio_slow_mode_hv(hw, false);
2644
2645 return ret_val;
2646}
2647
2648/**
2649 * e1000_get_phy_addr_for_hv_page - Get PHY adrress based on page
2650 * @page: page to be accessed
2651 **/
2652static u32 e1000_get_phy_addr_for_hv_page(u32 page)
2653{
2654 u32 phy_addr = 2;
2655
2656 if (page >= HV_INTC_FC_PAGE_START)
2657 phy_addr = 1;
2658
2659 return phy_addr;
2660}
2661
2662/**
2663 * e1000_access_phy_debug_regs_hv - Read HV PHY vendor specific high registers
2664 * @hw: pointer to the HW structure
2665 * @offset: register offset to be read or written
2666 * @data: pointer to the data to be read or written
2667 * @read: determines if operation is read or written
2668 *
2669 * Acquires semaphore, if necessary, then reads the PHY register at offset
2670 * and storing the retreived information in data. Release any acquired
2671 * semaphores before exiting. Note that the procedure to read these regs
2672 * uses the address port and data port to read/write.
2673 **/
2674static s32 e1000_access_phy_debug_regs_hv(struct e1000_hw *hw, u32 offset,
2675 u16 *data, bool read)
2676{
2677 s32 ret_val;
2678 u32 addr_reg = 0;
2679 u32 data_reg = 0;
2680 u8 phy_acquired = 1;
2681
2682 /* This takes care of the difference with desktop vs mobile phy */
2683 addr_reg = (hw->phy.type == e1000_phy_82578) ?
2684 I82578_ADDR_REG : I82577_ADDR_REG;
2685 data_reg = addr_reg + 1;
2686
2687 ret_val = hw->phy.ops.acquire_phy(hw);
2688 if (ret_val) {
2689 hw_dbg(hw, "Could not acquire PHY\n");
2690 phy_acquired = 0;
2691 goto out;
2692 }
2693
2694 /* All operations in this function are phy address 2 */
2695 hw->phy.addr = 2;
2696
2697 /* masking with 0x3F to remove the page from offset */
2698 ret_val = e1000e_write_phy_reg_mdic(hw, addr_reg, (u16)offset & 0x3F);
2699 if (ret_val) {
2700 hw_dbg(hw, "Could not write PHY the HV address register\n");
2701 goto out;
2702 }
2703
2704 /* Read or write the data value next */
2705 if (read)
2706 ret_val = e1000e_read_phy_reg_mdic(hw, data_reg, data);
2707 else
2708 ret_val = e1000e_write_phy_reg_mdic(hw, data_reg, *data);
2709
2710 if (ret_val) {
2711 hw_dbg(hw, "Could not read data value from HV data register\n");
2712 goto out;
2713 }
2714
2715out:
2716 if (phy_acquired == 1)
2717 hw->phy.ops.release_phy(hw);
2718 return ret_val;
2719}
2720
2721/**
2722 * e1000_link_stall_workaround_hv - Si workaround
2723 * @hw: pointer to the HW structure
2724 *
2725 * This function works around a Si bug where the link partner can get
2726 * a link up indication before the PHY does. If small packets are sent
2727 * by the link partner they can be placed in the packet buffer without
2728 * being properly accounted for by the PHY and will stall preventing
2729 * further packets from being received. The workaround is to clear the
2730 * packet buffer after the PHY detects link up.
2731 **/
2732s32 e1000_link_stall_workaround_hv(struct e1000_hw *hw)
2733{
2734 s32 ret_val = 0;
2735 u16 data;
2736
2737 if (hw->phy.type != e1000_phy_82578)
2738 goto out;
2739
2740 /* check if link is up and at 1Gbps */
2741 ret_val = hw->phy.ops.read_phy_reg(hw, BM_CS_STATUS, &data);
2742 if (ret_val)
2743 goto out;
2744
2745 data &= BM_CS_STATUS_LINK_UP |
2746 BM_CS_STATUS_RESOLVED |
2747 BM_CS_STATUS_SPEED_MASK;
2748
2749 if (data != (BM_CS_STATUS_LINK_UP |
2750 BM_CS_STATUS_RESOLVED |
2751 BM_CS_STATUS_SPEED_1000))
2752 goto out;
2753
2754 mdelay(200);
2755
2756 /* flush the packets in the fifo buffer */
2757 ret_val = hw->phy.ops.write_phy_reg(hw, HV_MUX_DATA_CTRL,
2758 HV_MUX_DATA_CTRL_GEN_TO_MAC |
2759 HV_MUX_DATA_CTRL_FORCE_SPEED);
2760 if (ret_val)
2761 goto out;
2762
2763 ret_val = hw->phy.ops.write_phy_reg(hw, HV_MUX_DATA_CTRL,
2764 HV_MUX_DATA_CTRL_GEN_TO_MAC);
2765
2766out:
2767 return ret_val;
2768}
2769
2770/**
2771 * e1000_check_polarity_82577 - Checks the polarity.
2772 * @hw: pointer to the HW structure
2773 *
2774 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
2775 *
2776 * Polarity is determined based on the PHY specific status register.
2777 **/
2778s32 e1000_check_polarity_82577(struct e1000_hw *hw)
2779{
2780 struct e1000_phy_info *phy = &hw->phy;
2781 s32 ret_val;
2782 u16 data;
2783
2784 ret_val = phy->ops.read_phy_reg(hw, I82577_PHY_STATUS_2, &data);
2785
2786 if (!ret_val)
2787 phy->cable_polarity = (data & I82577_PHY_STATUS2_REV_POLARITY)
2788 ? e1000_rev_polarity_reversed
2789 : e1000_rev_polarity_normal;
2790
2791 return ret_val;
2792}
2793
2794/**
2795 * e1000_phy_force_speed_duplex_82577 - Force speed/duplex for I82577 PHY
2796 * @hw: pointer to the HW structure
2797 *
2798 * Calls the PHY setup function to force speed and duplex. Clears the
2799 * auto-crossover to force MDI manually. Waits for link and returns
2800 * successful if link up is successful, else -E1000_ERR_PHY (-2).
2801 **/
2802s32 e1000_phy_force_speed_duplex_82577(struct e1000_hw *hw)
2803{
2804 struct e1000_phy_info *phy = &hw->phy;
2805 s32 ret_val;
2806 u16 phy_data;
2807 bool link;
2808
2809 ret_val = phy->ops.read_phy_reg(hw, PHY_CONTROL, &phy_data);
2810 if (ret_val)
2811 goto out;
2812
2813 e1000e_phy_force_speed_duplex_setup(hw, &phy_data);
2814
2815 ret_val = phy->ops.write_phy_reg(hw, PHY_CONTROL, phy_data);
2816 if (ret_val)
2817 goto out;
2818
2819 /*
2820 * Clear Auto-Crossover to force MDI manually. 82577 requires MDI
2821 * forced whenever speed and duplex are forced.
2822 */
2823 ret_val = phy->ops.read_phy_reg(hw, I82577_PHY_CTRL_2, &phy_data);
2824 if (ret_val)
2825 goto out;
2826
2827 phy_data &= ~I82577_PHY_CTRL2_AUTO_MDIX;
2828 phy_data &= ~I82577_PHY_CTRL2_FORCE_MDI_MDIX;
2829
2830 ret_val = phy->ops.write_phy_reg(hw, I82577_PHY_CTRL_2, phy_data);
2831 if (ret_val)
2832 goto out;
2833
2834 hw_dbg(hw, "I82577_PHY_CTRL_2: %X\n", phy_data);
2835
2836 udelay(1);
2837
2838 if (phy->autoneg_wait_to_complete) {
2839 hw_dbg(hw, "Waiting for forced speed/duplex link on 82577 phy\n");
2840
2841 ret_val = e1000e_phy_has_link_generic(hw,
2842 PHY_FORCE_LIMIT,
2843 100000,
2844 &link);
2845 if (ret_val)
2846 goto out;
2847
2848 if (!link)
2849 hw_dbg(hw, "Link taking longer than expected.\n");
2850
2851 /* Try once more */
2852 ret_val = e1000e_phy_has_link_generic(hw,
2853 PHY_FORCE_LIMIT,
2854 100000,
2855 &link);
2856 if (ret_val)
2857 goto out;
2858 }
2859
2860out:
2861 return ret_val;
2862}
2863
2864/**
2865 * e1000_get_phy_info_82577 - Retrieve I82577 PHY information
2866 * @hw: pointer to the HW structure
2867 *
2868 * Read PHY status to determine if link is up. If link is up, then
2869 * set/determine 10base-T extended distance and polarity correction. Read
2870 * PHY port status to determine MDI/MDIx and speed. Based on the speed,
2871 * determine on the cable length, local and remote receiver.
2872 **/
2873s32 e1000_get_phy_info_82577(struct e1000_hw *hw)
2874{
2875 struct e1000_phy_info *phy = &hw->phy;
2876 s32 ret_val;
2877 u16 data;
2878 bool link;
2879
2880 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
2881 if (ret_val)
2882 goto out;
2883
2884 if (!link) {
2885 hw_dbg(hw, "Phy info is only valid if link is up\n");
2886 ret_val = -E1000_ERR_CONFIG;
2887 goto out;
2888 }
2889
2890 phy->polarity_correction = true;
2891
2892 ret_val = e1000_check_polarity_82577(hw);
2893 if (ret_val)
2894 goto out;
2895
2896 ret_val = phy->ops.read_phy_reg(hw, I82577_PHY_STATUS_2, &data);
2897 if (ret_val)
2898 goto out;
2899
2900 phy->is_mdix = (data & I82577_PHY_STATUS2_MDIX) ? true : false;
2901
2902 if ((data & I82577_PHY_STATUS2_SPEED_MASK) ==
2903 I82577_PHY_STATUS2_SPEED_1000MBPS) {
2904 ret_val = hw->phy.ops.get_cable_length(hw);
2905 if (ret_val)
2906 goto out;
2907
2908 ret_val = phy->ops.read_phy_reg(hw, PHY_1000T_STATUS, &data);
2909 if (ret_val)
2910 goto out;
2911
2912 phy->local_rx = (data & SR_1000T_LOCAL_RX_STATUS)
2913 ? e1000_1000t_rx_status_ok
2914 : e1000_1000t_rx_status_not_ok;
2915
2916 phy->remote_rx = (data & SR_1000T_REMOTE_RX_STATUS)
2917 ? e1000_1000t_rx_status_ok
2918 : e1000_1000t_rx_status_not_ok;
2919 } else {
2920 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
2921 phy->local_rx = e1000_1000t_rx_status_undefined;
2922 phy->remote_rx = e1000_1000t_rx_status_undefined;
2923 }
2924
2925out:
2926 return ret_val;
2927}
2928
2929/**
2930 * e1000_get_cable_length_82577 - Determine cable length for 82577 PHY
2931 * @hw: pointer to the HW structure
2932 *
2933 * Reads the diagnostic status register and verifies result is valid before
2934 * placing it in the phy_cable_length field.
2935 **/
2936s32 e1000_get_cable_length_82577(struct e1000_hw *hw)
2937{
2938 struct e1000_phy_info *phy = &hw->phy;
2939 s32 ret_val;
2940 u16 phy_data, length;
2941
2942 ret_val = phy->ops.read_phy_reg(hw, I82577_PHY_DIAG_STATUS, &phy_data);
2943 if (ret_val)
2944 goto out;
2945
2946 length = (phy_data & I82577_DSTATUS_CABLE_LENGTH) >>
2947 I82577_DSTATUS_CABLE_LENGTH_SHIFT;
2948
2949 if (length == E1000_CABLE_LENGTH_UNDEFINED)
2950 ret_val = E1000_ERR_PHY;
2951
2952 phy->cable_length = length;
2953
2954out:
2955 return ret_val;
2956}