Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2 | /************************************************************************** |
Andre Schwarz | 68c2a30 | 2008-03-06 16:45:44 +0100 | [diff] [blame] | 3 | Intel Pro 1000 for ppcboot/das-u-boot |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4 | Drivers are port from Intel's Linux driver e1000-4.3.15 |
| 5 | and from Etherboot pro 1000 driver by mrakes at vivato dot net |
| 6 | tested on both gig copper and gig fiber boards |
| 7 | ***************************************************************************/ |
| 8 | /******************************************************************************* |
| 9 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 10 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 11 | Copyright(c) 1999 - 2002 Intel Corporation. All rights reserved. |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 12 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 13 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 14 | Contact Information: |
| 15 | Linux NICS <linux.nics@intel.com> |
| 16 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 17 | |
| 18 | *******************************************************************************/ |
| 19 | /* |
| 20 | * Copyright (C) Archway Digital Solutions. |
| 21 | * |
| 22 | * written by Chrsitopher Li <cli at arcyway dot com> or <chrisl at gnuchina dot org> |
| 23 | * 2/9/2002 |
| 24 | * |
| 25 | * Copyright (C) Linux Networx. |
| 26 | * Massive upgrade to work with the new intel gigabit NICs. |
| 27 | * <ebiederman at lnxi dot com> |
Roy Zang | 181119b | 2011-01-21 11:29:38 +0800 | [diff] [blame] | 28 | * |
| 29 | * Copyright 2011 Freescale Semiconductor, Inc. |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 30 | */ |
| 31 | |
Simon Glass | cece904 | 2015-08-19 09:33:38 -0600 | [diff] [blame] | 32 | #include <common.h> |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 33 | #include <command.h> |
Simon Glass | 6333448 | 2019-11-14 12:57:39 -0700 | [diff] [blame] | 34 | #include <cpu_func.h> |
Simon Glass | 9f86b38 | 2015-08-19 09:33:40 -0600 | [diff] [blame] | 35 | #include <dm.h> |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 36 | #include <errno.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 37 | #include <log.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 38 | #include <malloc.h> |
Simon Glass | 2dd337a | 2015-09-02 17:24:58 -0600 | [diff] [blame] | 39 | #include <memalign.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 40 | #include <net.h> |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 41 | #include <pci.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 42 | #include <linux/delay.h> |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 43 | #include "e1000.h" |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 44 | #include <asm/cache.h> |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 45 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 46 | #define TOUT_LOOP 100000 |
| 47 | |
Bin Meng | 83cf24c | 2016-02-02 05:58:01 -0800 | [diff] [blame] | 48 | #ifdef CONFIG_DM_ETH |
| 49 | #define virt_to_bus(devno, v) dm_pci_virt_to_mem(devno, (void *) (v)) |
Bin Meng | 83cf24c | 2016-02-02 05:58:01 -0800 | [diff] [blame] | 50 | #else |
Timur Tabi | edc45b5 | 2009-08-17 15:55:38 -0500 | [diff] [blame] | 51 | #define virt_to_bus(devno, v) pci_virt_to_mem(devno, (void *) (v)) |
Bin Meng | 83cf24c | 2016-02-02 05:58:01 -0800 | [diff] [blame] | 52 | #endif |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 53 | |
Roy Zang | 966172e | 2009-08-22 03:49:52 +0800 | [diff] [blame] | 54 | #define E1000_DEFAULT_PCI_PBA 0x00000030 |
| 55 | #define E1000_DEFAULT_PCIE_PBA 0x000a0026 |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 56 | |
| 57 | /* NIC specific static variables go here */ |
| 58 | |
Marek Vasut | 742c5c2 | 2014-08-08 07:41:38 -0700 | [diff] [blame] | 59 | /* Intel i210 needs the DMA descriptor rings aligned to 128b */ |
| 60 | #define E1000_BUFFER_ALIGN 128 |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 61 | |
Simon Glass | 9f86b38 | 2015-08-19 09:33:40 -0600 | [diff] [blame] | 62 | /* |
| 63 | * TODO(sjg@chromium.org): Even with driver model we share these buffers. |
| 64 | * Concurrent receiving on multiple active Ethernet devices will not work. |
| 65 | * Normally U-Boot does not support this anyway. To fix it in this driver, |
| 66 | * move these buffers and the tx/rx pointers to struct e1000_hw. |
| 67 | */ |
Marek Vasut | 742c5c2 | 2014-08-08 07:41:38 -0700 | [diff] [blame] | 68 | DEFINE_ALIGN_BUFFER(struct e1000_tx_desc, tx_base, 16, E1000_BUFFER_ALIGN); |
| 69 | DEFINE_ALIGN_BUFFER(struct e1000_rx_desc, rx_base, 16, E1000_BUFFER_ALIGN); |
| 70 | DEFINE_ALIGN_BUFFER(unsigned char, packet, 4096, E1000_BUFFER_ALIGN); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 71 | |
| 72 | static int tx_tail; |
| 73 | static int rx_tail, rx_last; |
Simon Glass | 9f86b38 | 2015-08-19 09:33:40 -0600 | [diff] [blame] | 74 | #ifdef CONFIG_DM_ETH |
| 75 | static int num_cards; /* Number of E1000 devices seen so far */ |
| 76 | #endif |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 77 | |
Kyle Moffett | 7b698d5 | 2011-10-18 11:05:26 +0000 | [diff] [blame] | 78 | static struct pci_device_id e1000_supported[] = { |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 79 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82542) }, |
| 80 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82543GC_FIBER) }, |
| 81 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82543GC_COPPER) }, |
| 82 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82544EI_COPPER) }, |
| 83 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82544EI_FIBER) }, |
| 84 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82544GC_COPPER) }, |
| 85 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82544GC_LOM) }, |
| 86 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82540EM) }, |
| 87 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82545EM_COPPER) }, |
| 88 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82545GM_COPPER) }, |
| 89 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82546EB_COPPER) }, |
| 90 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82545EM_FIBER) }, |
| 91 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82546EB_FIBER) }, |
| 92 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82546GB_COPPER) }, |
| 93 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82540EM_LOM) }, |
| 94 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82541ER) }, |
| 95 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82541GI_LF) }, |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 96 | /* E1000 PCIe card */ |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 97 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_COPPER) }, |
| 98 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_FIBER) }, |
| 99 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_SERDES) }, |
| 100 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_QUAD_COPPER) }, |
| 101 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571PT_QUAD_COPPER) }, |
| 102 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_QUAD_FIBER) }, |
| 103 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_QUAD_COPPER_LOWPROFILE) }, |
| 104 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_SERDES_DUAL) }, |
| 105 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_SERDES_QUAD) }, |
| 106 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82572EI_COPPER) }, |
| 107 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82572EI_FIBER) }, |
| 108 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82572EI_SERDES) }, |
| 109 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82572EI) }, |
| 110 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82573E) }, |
| 111 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82573E_IAMT) }, |
| 112 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82573L) }, |
| 113 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82574L) }, |
| 114 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82546GB_QUAD_COPPER_KSP3) }, |
| 115 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80003ES2LAN_COPPER_DPT) }, |
| 116 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80003ES2LAN_SERDES_DPT) }, |
| 117 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80003ES2LAN_COPPER_SPT) }, |
| 118 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80003ES2LAN_SERDES_SPT) }, |
| 119 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I210_UNPROGRAMMED) }, |
| 120 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I211_UNPROGRAMMED) }, |
| 121 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I210_COPPER) }, |
| 122 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I211_COPPER) }, |
| 123 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I210_COPPER_FLASHLESS) }, |
| 124 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I210_SERDES) }, |
| 125 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I210_SERDES_FLASHLESS) }, |
| 126 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I210_1000BASEKX) }, |
Marek Vasut | 74a13c2 | 2014-08-08 07:41:39 -0700 | [diff] [blame] | 127 | |
Stefan Althoefer | bc6d2fc | 2008-12-20 19:40:41 +0100 | [diff] [blame] | 128 | {} |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 129 | }; |
| 130 | |
| 131 | /* Function forward declarations */ |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 132 | static int e1000_setup_link(struct e1000_hw *hw); |
| 133 | static int e1000_setup_fiber_link(struct e1000_hw *hw); |
| 134 | static int e1000_setup_copper_link(struct e1000_hw *hw); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 135 | static int e1000_phy_setup_autoneg(struct e1000_hw *hw); |
| 136 | static void e1000_config_collision_dist(struct e1000_hw *hw); |
| 137 | static int e1000_config_mac_to_phy(struct e1000_hw *hw); |
| 138 | static int e1000_config_fc_after_link_up(struct e1000_hw *hw); |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 139 | static int e1000_check_for_link(struct e1000_hw *hw); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 140 | static int e1000_wait_autoneg(struct e1000_hw *hw); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 141 | static int e1000_get_speed_and_duplex(struct e1000_hw *hw, uint16_t * speed, |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 142 | uint16_t * duplex); |
| 143 | static int e1000_read_phy_reg(struct e1000_hw *hw, uint32_t reg_addr, |
| 144 | uint16_t * phy_data); |
| 145 | static int e1000_write_phy_reg(struct e1000_hw *hw, uint32_t reg_addr, |
| 146 | uint16_t phy_data); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 147 | static int32_t e1000_phy_hw_reset(struct e1000_hw *hw); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 148 | static int e1000_phy_reset(struct e1000_hw *hw); |
| 149 | static int e1000_detect_gig_phy(struct e1000_hw *hw); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 150 | static void e1000_set_media_type(struct e1000_hw *hw); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 151 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 152 | static int32_t e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask); |
Tim Harvey | 5cb59ec | 2015-05-19 10:01:18 -0700 | [diff] [blame] | 153 | static void e1000_swfw_sync_release(struct e1000_hw *hw, uint16_t mask); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 154 | static int32_t e1000_check_phy_reset_block(struct e1000_hw *hw); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 155 | |
Rojhalat Ibrahim | bbcd2b0 | 2013-10-07 18:30:39 +0200 | [diff] [blame] | 156 | #ifndef CONFIG_E1000_NO_NVM |
| 157 | static void e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw); |
Hannu Lounento | c56999e | 2018-01-10 20:31:24 +0100 | [diff] [blame] | 158 | static int32_t e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw); |
Roy Zang | 9b7c430 | 2009-08-11 03:48:05 +0800 | [diff] [blame] | 159 | static int32_t e1000_read_eeprom(struct e1000_hw *hw, uint16_t offset, |
| 160 | uint16_t words, |
| 161 | uint16_t *data); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 162 | /****************************************************************************** |
| 163 | * Raises the EEPROM's clock input. |
| 164 | * |
| 165 | * hw - Struct containing variables accessed by shared code |
| 166 | * eecd - EECD's current value |
| 167 | *****************************************************************************/ |
Kyle Moffett | 142cbf8 | 2011-10-18 11:05:28 +0000 | [diff] [blame] | 168 | void e1000_raise_ee_clk(struct e1000_hw *hw, uint32_t * eecd) |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 169 | { |
| 170 | /* Raise the clock input to the EEPROM (by setting the SK bit), and then |
| 171 | * wait 50 microseconds. |
| 172 | */ |
| 173 | *eecd = *eecd | E1000_EECD_SK; |
| 174 | E1000_WRITE_REG(hw, EECD, *eecd); |
| 175 | E1000_WRITE_FLUSH(hw); |
| 176 | udelay(50); |
| 177 | } |
| 178 | |
| 179 | /****************************************************************************** |
| 180 | * Lowers the EEPROM's clock input. |
| 181 | * |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 182 | * hw - Struct containing variables accessed by shared code |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 183 | * eecd - EECD's current value |
| 184 | *****************************************************************************/ |
Kyle Moffett | 142cbf8 | 2011-10-18 11:05:28 +0000 | [diff] [blame] | 185 | void e1000_lower_ee_clk(struct e1000_hw *hw, uint32_t * eecd) |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 186 | { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 187 | /* Lower the clock input to the EEPROM (by clearing the SK bit), and then |
| 188 | * wait 50 microseconds. |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 189 | */ |
| 190 | *eecd = *eecd & ~E1000_EECD_SK; |
| 191 | E1000_WRITE_REG(hw, EECD, *eecd); |
| 192 | E1000_WRITE_FLUSH(hw); |
| 193 | udelay(50); |
| 194 | } |
| 195 | |
| 196 | /****************************************************************************** |
| 197 | * Shift data bits out to the EEPROM. |
| 198 | * |
| 199 | * hw - Struct containing variables accessed by shared code |
| 200 | * data - data to send to the EEPROM |
| 201 | * count - number of bits to shift out |
| 202 | *****************************************************************************/ |
| 203 | static void |
| 204 | e1000_shift_out_ee_bits(struct e1000_hw *hw, uint16_t data, uint16_t count) |
| 205 | { |
| 206 | uint32_t eecd; |
| 207 | uint32_t mask; |
| 208 | |
| 209 | /* We need to shift "count" bits out to the EEPROM. So, value in the |
| 210 | * "data" parameter will be shifted out to the EEPROM one bit at a time. |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 211 | * In order to do this, "data" must be broken down into bits. |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 212 | */ |
| 213 | mask = 0x01 << (count - 1); |
| 214 | eecd = E1000_READ_REG(hw, EECD); |
| 215 | eecd &= ~(E1000_EECD_DO | E1000_EECD_DI); |
| 216 | do { |
| 217 | /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1", |
| 218 | * and then raising and then lowering the clock (the SK bit controls |
| 219 | * the clock input to the EEPROM). A "0" is shifted out to the EEPROM |
| 220 | * by setting "DI" to "0" and then raising and then lowering the clock. |
| 221 | */ |
| 222 | eecd &= ~E1000_EECD_DI; |
| 223 | |
| 224 | if (data & mask) |
| 225 | eecd |= E1000_EECD_DI; |
| 226 | |
| 227 | E1000_WRITE_REG(hw, EECD, eecd); |
| 228 | E1000_WRITE_FLUSH(hw); |
| 229 | |
| 230 | udelay(50); |
| 231 | |
| 232 | e1000_raise_ee_clk(hw, &eecd); |
| 233 | e1000_lower_ee_clk(hw, &eecd); |
| 234 | |
| 235 | mask = mask >> 1; |
| 236 | |
| 237 | } while (mask); |
| 238 | |
| 239 | /* We leave the "DI" bit set to "0" when we leave this routine. */ |
| 240 | eecd &= ~E1000_EECD_DI; |
| 241 | E1000_WRITE_REG(hw, EECD, eecd); |
| 242 | } |
| 243 | |
| 244 | /****************************************************************************** |
| 245 | * Shift data bits in from the EEPROM |
| 246 | * |
| 247 | * hw - Struct containing variables accessed by shared code |
| 248 | *****************************************************************************/ |
| 249 | static uint16_t |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 250 | e1000_shift_in_ee_bits(struct e1000_hw *hw, uint16_t count) |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 251 | { |
| 252 | uint32_t eecd; |
| 253 | uint32_t i; |
| 254 | uint16_t data; |
| 255 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 256 | /* In order to read a register from the EEPROM, we need to shift 'count' |
| 257 | * bits in from the EEPROM. Bits are "shifted in" by raising the clock |
| 258 | * input to the EEPROM (setting the SK bit), and then reading the |
| 259 | * value of the "DO" bit. During this "shifting in" process the |
| 260 | * "DI" bit should always be clear. |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 261 | */ |
| 262 | |
| 263 | eecd = E1000_READ_REG(hw, EECD); |
| 264 | |
| 265 | eecd &= ~(E1000_EECD_DO | E1000_EECD_DI); |
| 266 | data = 0; |
| 267 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 268 | for (i = 0; i < count; i++) { |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 269 | data = data << 1; |
| 270 | e1000_raise_ee_clk(hw, &eecd); |
| 271 | |
| 272 | eecd = E1000_READ_REG(hw, EECD); |
| 273 | |
| 274 | eecd &= ~(E1000_EECD_DI); |
| 275 | if (eecd & E1000_EECD_DO) |
| 276 | data |= 1; |
| 277 | |
| 278 | e1000_lower_ee_clk(hw, &eecd); |
| 279 | } |
| 280 | |
| 281 | return data; |
| 282 | } |
| 283 | |
| 284 | /****************************************************************************** |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 285 | * Returns EEPROM to a "standby" state |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 286 | * |
| 287 | * hw - Struct containing variables accessed by shared code |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 288 | *****************************************************************************/ |
Kyle Moffett | 142cbf8 | 2011-10-18 11:05:28 +0000 | [diff] [blame] | 289 | void e1000_standby_eeprom(struct e1000_hw *hw) |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 290 | { |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 291 | struct e1000_eeprom_info *eeprom = &hw->eeprom; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 292 | uint32_t eecd; |
| 293 | |
| 294 | eecd = E1000_READ_REG(hw, EECD); |
| 295 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 296 | if (eeprom->type == e1000_eeprom_microwire) { |
| 297 | eecd &= ~(E1000_EECD_CS | E1000_EECD_SK); |
| 298 | E1000_WRITE_REG(hw, EECD, eecd); |
| 299 | E1000_WRITE_FLUSH(hw); |
| 300 | udelay(eeprom->delay_usec); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 301 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 302 | /* Clock high */ |
| 303 | eecd |= E1000_EECD_SK; |
| 304 | E1000_WRITE_REG(hw, EECD, eecd); |
| 305 | E1000_WRITE_FLUSH(hw); |
| 306 | udelay(eeprom->delay_usec); |
| 307 | |
| 308 | /* Select EEPROM */ |
| 309 | eecd |= E1000_EECD_CS; |
| 310 | E1000_WRITE_REG(hw, EECD, eecd); |
| 311 | E1000_WRITE_FLUSH(hw); |
| 312 | udelay(eeprom->delay_usec); |
| 313 | |
| 314 | /* Clock low */ |
| 315 | eecd &= ~E1000_EECD_SK; |
| 316 | E1000_WRITE_REG(hw, EECD, eecd); |
| 317 | E1000_WRITE_FLUSH(hw); |
| 318 | udelay(eeprom->delay_usec); |
| 319 | } else if (eeprom->type == e1000_eeprom_spi) { |
| 320 | /* Toggle CS to flush commands */ |
| 321 | eecd |= E1000_EECD_CS; |
| 322 | E1000_WRITE_REG(hw, EECD, eecd); |
| 323 | E1000_WRITE_FLUSH(hw); |
| 324 | udelay(eeprom->delay_usec); |
| 325 | eecd &= ~E1000_EECD_CS; |
| 326 | E1000_WRITE_REG(hw, EECD, eecd); |
| 327 | E1000_WRITE_FLUSH(hw); |
| 328 | udelay(eeprom->delay_usec); |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | /*************************************************************************** |
| 333 | * Description: Determines if the onboard NVM is FLASH or EEPROM. |
| 334 | * |
| 335 | * hw - Struct containing variables accessed by shared code |
| 336 | ****************************************************************************/ |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 337 | static bool e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw) |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 338 | { |
| 339 | uint32_t eecd = 0; |
| 340 | |
| 341 | DEBUGFUNC(); |
| 342 | |
| 343 | if (hw->mac_type == e1000_ich8lan) |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 344 | return false; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 345 | |
Roy Zang | 181119b | 2011-01-21 11:29:38 +0800 | [diff] [blame] | 346 | if (hw->mac_type == e1000_82573 || hw->mac_type == e1000_82574) { |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 347 | eecd = E1000_READ_REG(hw, EECD); |
| 348 | |
| 349 | /* Isolate bits 15 & 16 */ |
| 350 | eecd = ((eecd >> 15) & 0x03); |
| 351 | |
| 352 | /* If both bits are set, device is Flash type */ |
| 353 | if (eecd == 0x03) |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 354 | return false; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 355 | } |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 356 | return true; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | /****************************************************************************** |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 360 | * Prepares EEPROM for access |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 361 | * |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 362 | * hw - Struct containing variables accessed by shared code |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 363 | * |
| 364 | * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This |
| 365 | * function should be called before issuing a command to the EEPROM. |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 366 | *****************************************************************************/ |
Kyle Moffett | 142cbf8 | 2011-10-18 11:05:28 +0000 | [diff] [blame] | 367 | int32_t e1000_acquire_eeprom(struct e1000_hw *hw) |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 368 | { |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 369 | struct e1000_eeprom_info *eeprom = &hw->eeprom; |
| 370 | uint32_t eecd, i = 0; |
| 371 | |
Timur Tabi | edc45b5 | 2009-08-17 15:55:38 -0500 | [diff] [blame] | 372 | DEBUGFUNC(); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 373 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 374 | if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM)) |
| 375 | return -E1000_ERR_SWFW_SYNC; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 376 | eecd = E1000_READ_REG(hw, EECD); |
| 377 | |
Marek Vasut | 74a13c2 | 2014-08-08 07:41:39 -0700 | [diff] [blame] | 378 | if (hw->mac_type != e1000_82573 && hw->mac_type != e1000_82574) { |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 379 | /* Request EEPROM Access */ |
| 380 | if (hw->mac_type > e1000_82544) { |
| 381 | eecd |= E1000_EECD_REQ; |
| 382 | E1000_WRITE_REG(hw, EECD, eecd); |
| 383 | eecd = E1000_READ_REG(hw, EECD); |
| 384 | while ((!(eecd & E1000_EECD_GNT)) && |
| 385 | (i < E1000_EEPROM_GRANT_ATTEMPTS)) { |
| 386 | i++; |
| 387 | udelay(5); |
| 388 | eecd = E1000_READ_REG(hw, EECD); |
| 389 | } |
| 390 | if (!(eecd & E1000_EECD_GNT)) { |
| 391 | eecd &= ~E1000_EECD_REQ; |
| 392 | E1000_WRITE_REG(hw, EECD, eecd); |
| 393 | DEBUGOUT("Could not acquire EEPROM grant\n"); |
| 394 | return -E1000_ERR_EEPROM; |
| 395 | } |
| 396 | } |
| 397 | } |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 398 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 399 | /* Setup EEPROM for Read/Write */ |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 400 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 401 | if (eeprom->type == e1000_eeprom_microwire) { |
| 402 | /* Clear SK and DI */ |
| 403 | eecd &= ~(E1000_EECD_DI | E1000_EECD_SK); |
| 404 | E1000_WRITE_REG(hw, EECD, eecd); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 405 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 406 | /* Set CS */ |
| 407 | eecd |= E1000_EECD_CS; |
| 408 | E1000_WRITE_REG(hw, EECD, eecd); |
| 409 | } else if (eeprom->type == e1000_eeprom_spi) { |
| 410 | /* Clear SK and CS */ |
| 411 | eecd &= ~(E1000_EECD_CS | E1000_EECD_SK); |
| 412 | E1000_WRITE_REG(hw, EECD, eecd); |
| 413 | udelay(1); |
| 414 | } |
| 415 | |
| 416 | return E1000_SUCCESS; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | /****************************************************************************** |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 420 | * Sets up eeprom variables in the hw struct. Must be called after mac_type |
| 421 | * is configured. Additionally, if this is ICH8, the flash controller GbE |
| 422 | * registers must be mapped, or this will crash. |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 423 | * |
| 424 | * hw - Struct containing variables accessed by shared code |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 425 | *****************************************************************************/ |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 426 | static int32_t e1000_init_eeprom_params(struct e1000_hw *hw) |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 427 | { |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 428 | struct e1000_eeprom_info *eeprom = &hw->eeprom; |
Marek Vasut | 74a13c2 | 2014-08-08 07:41:39 -0700 | [diff] [blame] | 429 | uint32_t eecd; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 430 | int32_t ret_val = E1000_SUCCESS; |
| 431 | uint16_t eeprom_size; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 432 | |
Marek Vasut | 74a13c2 | 2014-08-08 07:41:39 -0700 | [diff] [blame] | 433 | if (hw->mac_type == e1000_igb) |
| 434 | eecd = E1000_READ_REG(hw, I210_EECD); |
| 435 | else |
| 436 | eecd = E1000_READ_REG(hw, EECD); |
| 437 | |
Timur Tabi | edc45b5 | 2009-08-17 15:55:38 -0500 | [diff] [blame] | 438 | DEBUGFUNC(); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 439 | |
| 440 | switch (hw->mac_type) { |
| 441 | case e1000_82542_rev2_0: |
| 442 | case e1000_82542_rev2_1: |
| 443 | case e1000_82543: |
| 444 | case e1000_82544: |
| 445 | eeprom->type = e1000_eeprom_microwire; |
| 446 | eeprom->word_size = 64; |
| 447 | eeprom->opcode_bits = 3; |
| 448 | eeprom->address_bits = 6; |
| 449 | eeprom->delay_usec = 50; |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 450 | eeprom->use_eerd = false; |
| 451 | eeprom->use_eewr = false; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 452 | break; |
| 453 | case e1000_82540: |
| 454 | case e1000_82545: |
| 455 | case e1000_82545_rev_3: |
| 456 | case e1000_82546: |
| 457 | case e1000_82546_rev_3: |
| 458 | eeprom->type = e1000_eeprom_microwire; |
| 459 | eeprom->opcode_bits = 3; |
| 460 | eeprom->delay_usec = 50; |
| 461 | if (eecd & E1000_EECD_SIZE) { |
| 462 | eeprom->word_size = 256; |
| 463 | eeprom->address_bits = 8; |
| 464 | } else { |
| 465 | eeprom->word_size = 64; |
| 466 | eeprom->address_bits = 6; |
| 467 | } |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 468 | eeprom->use_eerd = false; |
| 469 | eeprom->use_eewr = false; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 470 | break; |
| 471 | case e1000_82541: |
| 472 | case e1000_82541_rev_2: |
| 473 | case e1000_82547: |
| 474 | case e1000_82547_rev_2: |
| 475 | if (eecd & E1000_EECD_TYPE) { |
| 476 | eeprom->type = e1000_eeprom_spi; |
| 477 | eeprom->opcode_bits = 8; |
| 478 | eeprom->delay_usec = 1; |
| 479 | if (eecd & E1000_EECD_ADDR_BITS) { |
| 480 | eeprom->page_size = 32; |
| 481 | eeprom->address_bits = 16; |
| 482 | } else { |
| 483 | eeprom->page_size = 8; |
| 484 | eeprom->address_bits = 8; |
| 485 | } |
| 486 | } else { |
| 487 | eeprom->type = e1000_eeprom_microwire; |
| 488 | eeprom->opcode_bits = 3; |
| 489 | eeprom->delay_usec = 50; |
| 490 | if (eecd & E1000_EECD_ADDR_BITS) { |
| 491 | eeprom->word_size = 256; |
| 492 | eeprom->address_bits = 8; |
| 493 | } else { |
| 494 | eeprom->word_size = 64; |
| 495 | eeprom->address_bits = 6; |
| 496 | } |
| 497 | } |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 498 | eeprom->use_eerd = false; |
| 499 | eeprom->use_eewr = false; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 500 | break; |
| 501 | case e1000_82571: |
| 502 | case e1000_82572: |
| 503 | eeprom->type = e1000_eeprom_spi; |
| 504 | eeprom->opcode_bits = 8; |
| 505 | eeprom->delay_usec = 1; |
| 506 | if (eecd & E1000_EECD_ADDR_BITS) { |
| 507 | eeprom->page_size = 32; |
| 508 | eeprom->address_bits = 16; |
| 509 | } else { |
| 510 | eeprom->page_size = 8; |
| 511 | eeprom->address_bits = 8; |
| 512 | } |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 513 | eeprom->use_eerd = false; |
| 514 | eeprom->use_eewr = false; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 515 | break; |
| 516 | case e1000_82573: |
Roy Zang | 181119b | 2011-01-21 11:29:38 +0800 | [diff] [blame] | 517 | case e1000_82574: |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 518 | eeprom->type = e1000_eeprom_spi; |
| 519 | eeprom->opcode_bits = 8; |
| 520 | eeprom->delay_usec = 1; |
| 521 | if (eecd & E1000_EECD_ADDR_BITS) { |
| 522 | eeprom->page_size = 32; |
| 523 | eeprom->address_bits = 16; |
| 524 | } else { |
| 525 | eeprom->page_size = 8; |
| 526 | eeprom->address_bits = 8; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 527 | } |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 528 | if (e1000_is_onboard_nvm_eeprom(hw) == false) { |
Marek Vasut | 74a13c2 | 2014-08-08 07:41:39 -0700 | [diff] [blame] | 529 | eeprom->use_eerd = true; |
| 530 | eeprom->use_eewr = true; |
| 531 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 532 | eeprom->type = e1000_eeprom_flash; |
| 533 | eeprom->word_size = 2048; |
| 534 | |
| 535 | /* Ensure that the Autonomous FLASH update bit is cleared due to |
| 536 | * Flash update issue on parts which use a FLASH for NVM. */ |
| 537 | eecd &= ~E1000_EECD_AUPDEN; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 538 | E1000_WRITE_REG(hw, EECD, eecd); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 539 | } |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 540 | break; |
| 541 | case e1000_80003es2lan: |
| 542 | eeprom->type = e1000_eeprom_spi; |
| 543 | eeprom->opcode_bits = 8; |
| 544 | eeprom->delay_usec = 1; |
| 545 | if (eecd & E1000_EECD_ADDR_BITS) { |
| 546 | eeprom->page_size = 32; |
| 547 | eeprom->address_bits = 16; |
| 548 | } else { |
| 549 | eeprom->page_size = 8; |
| 550 | eeprom->address_bits = 8; |
| 551 | } |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 552 | eeprom->use_eerd = true; |
| 553 | eeprom->use_eewr = false; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 554 | break; |
Marek Vasut | 74a13c2 | 2014-08-08 07:41:39 -0700 | [diff] [blame] | 555 | case e1000_igb: |
| 556 | /* i210 has 4k of iNVM mapped as EEPROM */ |
| 557 | eeprom->type = e1000_eeprom_invm; |
| 558 | eeprom->opcode_bits = 8; |
| 559 | eeprom->delay_usec = 1; |
| 560 | eeprom->page_size = 32; |
| 561 | eeprom->address_bits = 16; |
| 562 | eeprom->use_eerd = true; |
| 563 | eeprom->use_eewr = false; |
| 564 | break; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 565 | default: |
| 566 | break; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 567 | } |
| 568 | |
Marek Vasut | 74a13c2 | 2014-08-08 07:41:39 -0700 | [diff] [blame] | 569 | if (eeprom->type == e1000_eeprom_spi || |
| 570 | eeprom->type == e1000_eeprom_invm) { |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 571 | /* eeprom_size will be an enum [0..8] that maps |
| 572 | * to eeprom sizes 128B to |
| 573 | * 32KB (incremented by powers of 2). |
| 574 | */ |
| 575 | if (hw->mac_type <= e1000_82547_rev_2) { |
| 576 | /* Set to default value for initial eeprom read. */ |
| 577 | eeprom->word_size = 64; |
| 578 | ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1, |
| 579 | &eeprom_size); |
| 580 | if (ret_val) |
| 581 | return ret_val; |
| 582 | eeprom_size = (eeprom_size & EEPROM_SIZE_MASK) |
| 583 | >> EEPROM_SIZE_SHIFT; |
| 584 | /* 256B eeprom size was not supported in earlier |
| 585 | * hardware, so we bump eeprom_size up one to |
| 586 | * ensure that "1" (which maps to 256B) is never |
| 587 | * the result used in the shifting logic below. */ |
| 588 | if (eeprom_size) |
| 589 | eeprom_size++; |
| 590 | } else { |
| 591 | eeprom_size = (uint16_t)((eecd & |
| 592 | E1000_EECD_SIZE_EX_MASK) >> |
| 593 | E1000_EECD_SIZE_EX_SHIFT); |
| 594 | } |
| 595 | |
| 596 | eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT); |
| 597 | } |
| 598 | return ret_val; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 599 | } |
| 600 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 601 | /****************************************************************************** |
| 602 | * Polls the status bit (bit 1) of the EERD to determine when the read is done. |
| 603 | * |
| 604 | * hw - Struct containing variables accessed by shared code |
| 605 | *****************************************************************************/ |
| 606 | static int32_t |
| 607 | e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd) |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 608 | { |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 609 | uint32_t attempts = 100000; |
| 610 | uint32_t i, reg = 0; |
| 611 | int32_t done = E1000_ERR_EEPROM; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 612 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 613 | for (i = 0; i < attempts; i++) { |
Marek Vasut | 74a13c2 | 2014-08-08 07:41:39 -0700 | [diff] [blame] | 614 | if (eerd == E1000_EEPROM_POLL_READ) { |
| 615 | if (hw->mac_type == e1000_igb) |
| 616 | reg = E1000_READ_REG(hw, I210_EERD); |
| 617 | else |
| 618 | reg = E1000_READ_REG(hw, EERD); |
| 619 | } else { |
| 620 | if (hw->mac_type == e1000_igb) |
| 621 | reg = E1000_READ_REG(hw, I210_EEWR); |
| 622 | else |
| 623 | reg = E1000_READ_REG(hw, EEWR); |
| 624 | } |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 625 | |
| 626 | if (reg & E1000_EEPROM_RW_REG_DONE) { |
| 627 | done = E1000_SUCCESS; |
| 628 | break; |
| 629 | } |
| 630 | udelay(5); |
| 631 | } |
| 632 | |
| 633 | return done; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 634 | } |
| 635 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 636 | /****************************************************************************** |
| 637 | * Reads a 16 bit word from the EEPROM using the EERD register. |
| 638 | * |
| 639 | * hw - Struct containing variables accessed by shared code |
| 640 | * offset - offset of word in the EEPROM to read |
| 641 | * data - word read from the EEPROM |
| 642 | * words - number of words to read |
| 643 | *****************************************************************************/ |
| 644 | static int32_t |
| 645 | e1000_read_eeprom_eerd(struct e1000_hw *hw, |
| 646 | uint16_t offset, |
| 647 | uint16_t words, |
| 648 | uint16_t *data) |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 649 | { |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 650 | uint32_t i, eerd = 0; |
| 651 | int32_t error = 0; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 652 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 653 | for (i = 0; i < words; i++) { |
| 654 | eerd = ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) + |
| 655 | E1000_EEPROM_RW_REG_START; |
| 656 | |
Marek Vasut | 74a13c2 | 2014-08-08 07:41:39 -0700 | [diff] [blame] | 657 | if (hw->mac_type == e1000_igb) |
| 658 | E1000_WRITE_REG(hw, I210_EERD, eerd); |
| 659 | else |
| 660 | E1000_WRITE_REG(hw, EERD, eerd); |
| 661 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 662 | error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_READ); |
| 663 | |
| 664 | if (error) |
| 665 | break; |
Marek Vasut | 74a13c2 | 2014-08-08 07:41:39 -0700 | [diff] [blame] | 666 | |
| 667 | if (hw->mac_type == e1000_igb) { |
| 668 | data[i] = (E1000_READ_REG(hw, I210_EERD) >> |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 669 | E1000_EEPROM_RW_REG_DATA); |
Marek Vasut | 74a13c2 | 2014-08-08 07:41:39 -0700 | [diff] [blame] | 670 | } else { |
| 671 | data[i] = (E1000_READ_REG(hw, EERD) >> |
| 672 | E1000_EEPROM_RW_REG_DATA); |
| 673 | } |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 674 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 675 | } |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 676 | |
| 677 | return error; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 678 | } |
| 679 | |
Kyle Moffett | 142cbf8 | 2011-10-18 11:05:28 +0000 | [diff] [blame] | 680 | void e1000_release_eeprom(struct e1000_hw *hw) |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 681 | { |
| 682 | uint32_t eecd; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 683 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 684 | DEBUGFUNC(); |
| 685 | |
| 686 | eecd = E1000_READ_REG(hw, EECD); |
| 687 | |
| 688 | if (hw->eeprom.type == e1000_eeprom_spi) { |
| 689 | eecd |= E1000_EECD_CS; /* Pull CS high */ |
| 690 | eecd &= ~E1000_EECD_SK; /* Lower SCK */ |
| 691 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 692 | E1000_WRITE_REG(hw, EECD, eecd); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 693 | |
| 694 | udelay(hw->eeprom.delay_usec); |
| 695 | } else if (hw->eeprom.type == e1000_eeprom_microwire) { |
| 696 | /* cleanup eeprom */ |
| 697 | |
| 698 | /* CS on Microwire is active-high */ |
| 699 | eecd &= ~(E1000_EECD_CS | E1000_EECD_DI); |
| 700 | |
| 701 | E1000_WRITE_REG(hw, EECD, eecd); |
| 702 | |
| 703 | /* Rising edge of clock */ |
| 704 | eecd |= E1000_EECD_SK; |
| 705 | E1000_WRITE_REG(hw, EECD, eecd); |
| 706 | E1000_WRITE_FLUSH(hw); |
| 707 | udelay(hw->eeprom.delay_usec); |
| 708 | |
| 709 | /* Falling edge of clock */ |
| 710 | eecd &= ~E1000_EECD_SK; |
| 711 | E1000_WRITE_REG(hw, EECD, eecd); |
| 712 | E1000_WRITE_FLUSH(hw); |
| 713 | udelay(hw->eeprom.delay_usec); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 714 | } |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 715 | |
| 716 | /* Stop requesting EEPROM access */ |
| 717 | if (hw->mac_type > e1000_82544) { |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 718 | eecd &= ~E1000_EECD_REQ; |
| 719 | E1000_WRITE_REG(hw, EECD, eecd); |
| 720 | } |
Tim Harvey | 5cb59ec | 2015-05-19 10:01:18 -0700 | [diff] [blame] | 721 | |
| 722 | e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 723 | } |
Tim Harvey | 5cb59ec | 2015-05-19 10:01:18 -0700 | [diff] [blame] | 724 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 725 | /****************************************************************************** |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 726 | * Reads a 16 bit word from the EEPROM. |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 727 | * |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 728 | * hw - Struct containing variables accessed by shared code |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 729 | *****************************************************************************/ |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 730 | static int32_t |
| 731 | e1000_spi_eeprom_ready(struct e1000_hw *hw) |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 732 | { |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 733 | uint16_t retry_count = 0; |
| 734 | uint8_t spi_stat_reg; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 735 | |
| 736 | DEBUGFUNC(); |
| 737 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 738 | /* Read "Status Register" repeatedly until the LSB is cleared. The |
| 739 | * EEPROM will signal that the command has been completed by clearing |
| 740 | * bit 0 of the internal status register. If it's not cleared within |
| 741 | * 5 milliseconds, then error out. |
| 742 | */ |
| 743 | retry_count = 0; |
| 744 | do { |
| 745 | e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI, |
| 746 | hw->eeprom.opcode_bits); |
| 747 | spi_stat_reg = (uint8_t)e1000_shift_in_ee_bits(hw, 8); |
| 748 | if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI)) |
| 749 | break; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 750 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 751 | udelay(5); |
| 752 | retry_count += 5; |
| 753 | |
| 754 | e1000_standby_eeprom(hw); |
| 755 | } while (retry_count < EEPROM_MAX_RETRY_SPI); |
| 756 | |
| 757 | /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and |
| 758 | * only 0-5mSec on 5V devices) |
| 759 | */ |
| 760 | if (retry_count >= EEPROM_MAX_RETRY_SPI) { |
| 761 | DEBUGOUT("SPI EEPROM Status error\n"); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 762 | return -E1000_ERR_EEPROM; |
| 763 | } |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 764 | |
| 765 | return E1000_SUCCESS; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 766 | } |
| 767 | |
| 768 | /****************************************************************************** |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 769 | * Reads a 16 bit word from the EEPROM. |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 770 | * |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 771 | * hw - Struct containing variables accessed by shared code |
| 772 | * offset - offset of word in the EEPROM to read |
| 773 | * data - word read from the EEPROM |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 774 | *****************************************************************************/ |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 775 | static int32_t |
| 776 | e1000_read_eeprom(struct e1000_hw *hw, uint16_t offset, |
| 777 | uint16_t words, uint16_t *data) |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 778 | { |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 779 | struct e1000_eeprom_info *eeprom = &hw->eeprom; |
| 780 | uint32_t i = 0; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 781 | |
| 782 | DEBUGFUNC(); |
| 783 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 784 | /* If eeprom is not yet detected, do so now */ |
| 785 | if (eeprom->word_size == 0) |
| 786 | e1000_init_eeprom_params(hw); |
| 787 | |
| 788 | /* A check for invalid values: offset too large, too many words, |
| 789 | * and not enough words. |
| 790 | */ |
| 791 | if ((offset >= eeprom->word_size) || |
| 792 | (words > eeprom->word_size - offset) || |
| 793 | (words == 0)) { |
| 794 | DEBUGOUT("\"words\" parameter out of bounds." |
| 795 | "Words = %d, size = %d\n", offset, eeprom->word_size); |
| 796 | return -E1000_ERR_EEPROM; |
| 797 | } |
| 798 | |
| 799 | /* EEPROM's that don't use EERD to read require us to bit-bang the SPI |
| 800 | * directly. In this case, we need to acquire the EEPROM so that |
| 801 | * FW or other port software does not interrupt. |
| 802 | */ |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 803 | if (e1000_is_onboard_nvm_eeprom(hw) == true && |
| 804 | hw->eeprom.use_eerd == false) { |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 805 | |
| 806 | /* Prepare the EEPROM for bit-bang reading */ |
| 807 | if (e1000_acquire_eeprom(hw) != E1000_SUCCESS) |
| 808 | return -E1000_ERR_EEPROM; |
| 809 | } |
| 810 | |
| 811 | /* Eerd register EEPROM access requires no eeprom aquire/release */ |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 812 | if (eeprom->use_eerd == true) |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 813 | return e1000_read_eeprom_eerd(hw, offset, words, data); |
| 814 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 815 | /* Set up the SPI or Microwire EEPROM for bit-bang reading. We have |
| 816 | * acquired the EEPROM at this point, so any returns should relase it */ |
| 817 | if (eeprom->type == e1000_eeprom_spi) { |
| 818 | uint16_t word_in; |
| 819 | uint8_t read_opcode = EEPROM_READ_OPCODE_SPI; |
| 820 | |
| 821 | if (e1000_spi_eeprom_ready(hw)) { |
| 822 | e1000_release_eeprom(hw); |
| 823 | return -E1000_ERR_EEPROM; |
| 824 | } |
| 825 | |
| 826 | e1000_standby_eeprom(hw); |
| 827 | |
| 828 | /* Some SPI eeproms use the 8th address bit embedded in |
| 829 | * the opcode */ |
| 830 | if ((eeprom->address_bits == 8) && (offset >= 128)) |
| 831 | read_opcode |= EEPROM_A8_OPCODE_SPI; |
| 832 | |
| 833 | /* Send the READ command (opcode + addr) */ |
| 834 | e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits); |
| 835 | e1000_shift_out_ee_bits(hw, (uint16_t)(offset*2), |
| 836 | eeprom->address_bits); |
| 837 | |
| 838 | /* Read the data. The address of the eeprom internally |
| 839 | * increments with each byte (spi) being read, saving on the |
| 840 | * overhead of eeprom setup and tear-down. The address |
| 841 | * counter will roll over if reading beyond the size of |
| 842 | * the eeprom, thus allowing the entire memory to be read |
| 843 | * starting from any offset. */ |
| 844 | for (i = 0; i < words; i++) { |
| 845 | word_in = e1000_shift_in_ee_bits(hw, 16); |
| 846 | data[i] = (word_in >> 8) | (word_in << 8); |
| 847 | } |
| 848 | } else if (eeprom->type == e1000_eeprom_microwire) { |
| 849 | for (i = 0; i < words; i++) { |
| 850 | /* Send the READ command (opcode + addr) */ |
| 851 | e1000_shift_out_ee_bits(hw, |
| 852 | EEPROM_READ_OPCODE_MICROWIRE, |
| 853 | eeprom->opcode_bits); |
| 854 | e1000_shift_out_ee_bits(hw, (uint16_t)(offset + i), |
| 855 | eeprom->address_bits); |
| 856 | |
| 857 | /* Read the data. For microwire, each word requires |
| 858 | * the overhead of eeprom setup and tear-down. */ |
| 859 | data[i] = e1000_shift_in_ee_bits(hw, 16); |
| 860 | e1000_standby_eeprom(hw); |
| 861 | } |
| 862 | } |
| 863 | |
| 864 | /* End this read operation */ |
| 865 | e1000_release_eeprom(hw); |
| 866 | |
| 867 | return E1000_SUCCESS; |
| 868 | } |
| 869 | |
Hannu Lounento | c56999e | 2018-01-10 20:31:24 +0100 | [diff] [blame] | 870 | /****************************************************************************** |
| 871 | * e1000_write_eeprom_srwr - Write to Shadow Ram using EEWR |
| 872 | * @hw: pointer to the HW structure |
| 873 | * @offset: offset within the Shadow Ram to be written to |
| 874 | * @words: number of words to write |
| 875 | * @data: 16 bit word(s) to be written to the Shadow Ram |
| 876 | * |
| 877 | * Writes data to Shadow Ram at offset using EEWR register. |
| 878 | * |
| 879 | * If e1000_update_eeprom_checksum_i210 is not called after this function, the |
| 880 | * Shadow Ram will most likely contain an invalid checksum. |
| 881 | *****************************************************************************/ |
| 882 | static int32_t e1000_write_eeprom_srwr(struct e1000_hw *hw, uint16_t offset, |
| 883 | uint16_t words, uint16_t *data) |
| 884 | { |
| 885 | struct e1000_eeprom_info *eeprom = &hw->eeprom; |
| 886 | uint32_t i, k, eewr = 0; |
| 887 | uint32_t attempts = 100000; |
| 888 | int32_t ret_val = 0; |
| 889 | |
| 890 | /* A check for invalid values: offset too large, too many words, |
| 891 | * too many words for the offset, and not enough words. |
| 892 | */ |
| 893 | if ((offset >= eeprom->word_size) || |
| 894 | (words > (eeprom->word_size - offset)) || (words == 0)) { |
| 895 | DEBUGOUT("nvm parameter(s) out of bounds\n"); |
| 896 | ret_val = -E1000_ERR_EEPROM; |
| 897 | goto out; |
| 898 | } |
| 899 | |
| 900 | for (i = 0; i < words; i++) { |
| 901 | eewr = ((offset + i) << E1000_EEPROM_RW_ADDR_SHIFT) |
| 902 | | (data[i] << E1000_EEPROM_RW_REG_DATA) | |
| 903 | E1000_EEPROM_RW_REG_START; |
| 904 | |
| 905 | E1000_WRITE_REG(hw, I210_EEWR, eewr); |
| 906 | |
| 907 | for (k = 0; k < attempts; k++) { |
| 908 | if (E1000_EEPROM_RW_REG_DONE & |
| 909 | E1000_READ_REG(hw, I210_EEWR)) { |
| 910 | ret_val = 0; |
| 911 | break; |
| 912 | } |
| 913 | udelay(5); |
| 914 | } |
| 915 | |
| 916 | if (ret_val) { |
| 917 | DEBUGOUT("Shadow RAM write EEWR timed out\n"); |
| 918 | break; |
| 919 | } |
| 920 | } |
| 921 | |
| 922 | out: |
| 923 | return ret_val; |
| 924 | } |
| 925 | |
| 926 | /****************************************************************************** |
| 927 | * e1000_pool_flash_update_done_i210 - Pool FLUDONE status. |
| 928 | * @hw: pointer to the HW structure |
| 929 | * |
| 930 | *****************************************************************************/ |
| 931 | static int32_t e1000_pool_flash_update_done_i210(struct e1000_hw *hw) |
| 932 | { |
| 933 | int32_t ret_val = -E1000_ERR_EEPROM; |
| 934 | uint32_t i, reg; |
| 935 | |
| 936 | for (i = 0; i < E1000_FLUDONE_ATTEMPTS; i++) { |
| 937 | reg = E1000_READ_REG(hw, EECD); |
| 938 | if (reg & E1000_EECD_FLUDONE_I210) { |
| 939 | ret_val = 0; |
| 940 | break; |
| 941 | } |
| 942 | udelay(5); |
| 943 | } |
| 944 | |
| 945 | return ret_val; |
| 946 | } |
| 947 | |
| 948 | /****************************************************************************** |
| 949 | * e1000_update_flash_i210 - Commit EEPROM to the flash |
| 950 | * @hw: pointer to the HW structure |
| 951 | * |
| 952 | *****************************************************************************/ |
| 953 | static int32_t e1000_update_flash_i210(struct e1000_hw *hw) |
| 954 | { |
| 955 | int32_t ret_val = 0; |
| 956 | uint32_t flup; |
| 957 | |
| 958 | ret_val = e1000_pool_flash_update_done_i210(hw); |
| 959 | if (ret_val == -E1000_ERR_EEPROM) { |
| 960 | DEBUGOUT("Flash update time out\n"); |
| 961 | goto out; |
| 962 | } |
| 963 | |
| 964 | flup = E1000_READ_REG(hw, EECD) | E1000_EECD_FLUPD_I210; |
| 965 | E1000_WRITE_REG(hw, EECD, flup); |
| 966 | |
| 967 | ret_val = e1000_pool_flash_update_done_i210(hw); |
| 968 | if (ret_val) |
| 969 | DEBUGOUT("Flash update time out\n"); |
| 970 | else |
| 971 | DEBUGOUT("Flash update complete\n"); |
| 972 | |
| 973 | out: |
| 974 | return ret_val; |
| 975 | } |
| 976 | |
| 977 | /****************************************************************************** |
| 978 | * e1000_update_eeprom_checksum_i210 - Update EEPROM checksum |
| 979 | * @hw: pointer to the HW structure |
| 980 | * |
| 981 | * Updates the EEPROM checksum by reading/adding each word of the EEPROM |
| 982 | * up to the checksum. Then calculates the EEPROM checksum and writes the |
| 983 | * value to the EEPROM. Next commit EEPROM data onto the Flash. |
| 984 | *****************************************************************************/ |
| 985 | static int32_t e1000_update_eeprom_checksum_i210(struct e1000_hw *hw) |
| 986 | { |
| 987 | int32_t ret_val = 0; |
| 988 | uint16_t checksum = 0; |
| 989 | uint16_t i, nvm_data; |
| 990 | |
| 991 | /* Read the first word from the EEPROM. If this times out or fails, do |
| 992 | * not continue or we could be in for a very long wait while every |
| 993 | * EEPROM read fails |
| 994 | */ |
| 995 | ret_val = e1000_read_eeprom_eerd(hw, 0, 1, &nvm_data); |
| 996 | if (ret_val) { |
| 997 | DEBUGOUT("EEPROM read failed\n"); |
| 998 | goto out; |
| 999 | } |
| 1000 | |
| 1001 | if (!(e1000_get_hw_eeprom_semaphore(hw))) { |
| 1002 | /* Do not use hw->nvm.ops.write, hw->nvm.ops.read |
| 1003 | * because we do not want to take the synchronization |
| 1004 | * semaphores twice here. |
| 1005 | */ |
| 1006 | |
| 1007 | for (i = 0; i < EEPROM_CHECKSUM_REG; i++) { |
| 1008 | ret_val = e1000_read_eeprom_eerd(hw, i, 1, &nvm_data); |
| 1009 | if (ret_val) { |
| 1010 | e1000_put_hw_eeprom_semaphore(hw); |
| 1011 | DEBUGOUT("EEPROM Read Error while updating checksum.\n"); |
| 1012 | goto out; |
| 1013 | } |
| 1014 | checksum += nvm_data; |
| 1015 | } |
| 1016 | checksum = (uint16_t)EEPROM_SUM - checksum; |
| 1017 | ret_val = e1000_write_eeprom_srwr(hw, EEPROM_CHECKSUM_REG, 1, |
| 1018 | &checksum); |
| 1019 | if (ret_val) { |
| 1020 | e1000_put_hw_eeprom_semaphore(hw); |
| 1021 | DEBUGOUT("EEPROM Write Error while updating checksum.\n"); |
| 1022 | goto out; |
| 1023 | } |
| 1024 | |
| 1025 | e1000_put_hw_eeprom_semaphore(hw); |
| 1026 | |
| 1027 | ret_val = e1000_update_flash_i210(hw); |
| 1028 | } else { |
| 1029 | ret_val = -E1000_ERR_SWFW_SYNC; |
| 1030 | } |
| 1031 | |
| 1032 | out: |
| 1033 | return ret_val; |
| 1034 | } |
Hannu Lounento | c56999e | 2018-01-10 20:31:24 +0100 | [diff] [blame] | 1035 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1036 | /****************************************************************************** |
| 1037 | * Verifies that the EEPROM has a valid checksum |
| 1038 | * |
| 1039 | * hw - Struct containing variables accessed by shared code |
| 1040 | * |
| 1041 | * Reads the first 64 16 bit words of the EEPROM and sums the values read. |
| 1042 | * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is |
| 1043 | * valid. |
| 1044 | *****************************************************************************/ |
Kyle Moffett | 70946bc | 2011-10-18 11:05:27 +0000 | [diff] [blame] | 1045 | static int e1000_validate_eeprom_checksum(struct e1000_hw *hw) |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1046 | { |
Kyle Moffett | 70946bc | 2011-10-18 11:05:27 +0000 | [diff] [blame] | 1047 | uint16_t i, checksum, checksum_reg, *buf; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1048 | |
| 1049 | DEBUGFUNC(); |
| 1050 | |
Kyle Moffett | 70946bc | 2011-10-18 11:05:27 +0000 | [diff] [blame] | 1051 | /* Allocate a temporary buffer */ |
| 1052 | buf = malloc(sizeof(buf[0]) * (EEPROM_CHECKSUM_REG + 1)); |
| 1053 | if (!buf) { |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 1054 | E1000_ERR(hw, "Unable to allocate EEPROM buffer!\n"); |
Kyle Moffett | 70946bc | 2011-10-18 11:05:27 +0000 | [diff] [blame] | 1055 | return -E1000_ERR_EEPROM; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1056 | } |
| 1057 | |
Kyle Moffett | 70946bc | 2011-10-18 11:05:27 +0000 | [diff] [blame] | 1058 | /* Read the EEPROM */ |
| 1059 | if (e1000_read_eeprom(hw, 0, EEPROM_CHECKSUM_REG + 1, buf) < 0) { |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 1060 | E1000_ERR(hw, "Unable to read EEPROM!\n"); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1061 | return -E1000_ERR_EEPROM; |
| 1062 | } |
Kyle Moffett | 70946bc | 2011-10-18 11:05:27 +0000 | [diff] [blame] | 1063 | |
| 1064 | /* Compute the checksum */ |
Wolfgang Denk | 1569033 | 2011-10-28 07:37:04 +0200 | [diff] [blame] | 1065 | checksum = 0; |
Kyle Moffett | 70946bc | 2011-10-18 11:05:27 +0000 | [diff] [blame] | 1066 | for (i = 0; i < EEPROM_CHECKSUM_REG; i++) |
| 1067 | checksum += buf[i]; |
| 1068 | checksum = ((uint16_t)EEPROM_SUM) - checksum; |
| 1069 | checksum_reg = buf[i]; |
| 1070 | |
| 1071 | /* Verify it! */ |
| 1072 | if (checksum == checksum_reg) |
| 1073 | return 0; |
| 1074 | |
| 1075 | /* Hrm, verification failed, print an error */ |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 1076 | E1000_ERR(hw, "EEPROM checksum is incorrect!\n"); |
| 1077 | E1000_ERR(hw, " ...register was 0x%04hx, calculated 0x%04hx\n", |
| 1078 | checksum_reg, checksum); |
Kyle Moffett | 70946bc | 2011-10-18 11:05:27 +0000 | [diff] [blame] | 1079 | |
| 1080 | return -E1000_ERR_EEPROM; |
Roy Zang | 9b7c430 | 2009-08-11 03:48:05 +0800 | [diff] [blame] | 1081 | } |
Rojhalat Ibrahim | bbcd2b0 | 2013-10-07 18:30:39 +0200 | [diff] [blame] | 1082 | #endif /* CONFIG_E1000_NO_NVM */ |
Roy Zang | 9b7c430 | 2009-08-11 03:48:05 +0800 | [diff] [blame] | 1083 | |
| 1084 | /***************************************************************************** |
| 1085 | * Set PHY to class A mode |
| 1086 | * Assumes the following operations will follow to enable the new class mode. |
| 1087 | * 1. Do a PHY soft reset |
| 1088 | * 2. Restart auto-negotiation or force link. |
| 1089 | * |
| 1090 | * hw - Struct containing variables accessed by shared code |
| 1091 | ****************************************************************************/ |
| 1092 | static int32_t |
| 1093 | e1000_set_phy_mode(struct e1000_hw *hw) |
| 1094 | { |
Rojhalat Ibrahim | bbcd2b0 | 2013-10-07 18:30:39 +0200 | [diff] [blame] | 1095 | #ifndef CONFIG_E1000_NO_NVM |
Roy Zang | 9b7c430 | 2009-08-11 03:48:05 +0800 | [diff] [blame] | 1096 | int32_t ret_val; |
| 1097 | uint16_t eeprom_data; |
| 1098 | |
| 1099 | DEBUGFUNC(); |
| 1100 | |
| 1101 | if ((hw->mac_type == e1000_82545_rev_3) && |
| 1102 | (hw->media_type == e1000_media_type_copper)) { |
| 1103 | ret_val = e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD, |
| 1104 | 1, &eeprom_data); |
| 1105 | if (ret_val) |
| 1106 | return ret_val; |
| 1107 | |
| 1108 | if ((eeprom_data != EEPROM_RESERVED_WORD) && |
| 1109 | (eeprom_data & EEPROM_PHY_CLASS_A)) { |
| 1110 | ret_val = e1000_write_phy_reg(hw, |
| 1111 | M88E1000_PHY_PAGE_SELECT, 0x000B); |
| 1112 | if (ret_val) |
| 1113 | return ret_val; |
| 1114 | ret_val = e1000_write_phy_reg(hw, |
| 1115 | M88E1000_PHY_GEN_CONTROL, 0x8104); |
| 1116 | if (ret_val) |
| 1117 | return ret_val; |
| 1118 | |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 1119 | hw->phy_reset_disable = false; |
Roy Zang | 9b7c430 | 2009-08-11 03:48:05 +0800 | [diff] [blame] | 1120 | } |
| 1121 | } |
Rojhalat Ibrahim | bbcd2b0 | 2013-10-07 18:30:39 +0200 | [diff] [blame] | 1122 | #endif |
Roy Zang | 9b7c430 | 2009-08-11 03:48:05 +0800 | [diff] [blame] | 1123 | return E1000_SUCCESS; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1124 | } |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1125 | |
Rojhalat Ibrahim | bbcd2b0 | 2013-10-07 18:30:39 +0200 | [diff] [blame] | 1126 | #ifndef CONFIG_E1000_NO_NVM |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1127 | /*************************************************************************** |
| 1128 | * |
| 1129 | * Obtaining software semaphore bit (SMBI) before resetting PHY. |
| 1130 | * |
| 1131 | * hw: Struct containing variables accessed by shared code |
| 1132 | * |
| 1133 | * returns: - E1000_ERR_RESET if fail to obtain semaphore. |
| 1134 | * E1000_SUCCESS at any other case. |
| 1135 | * |
| 1136 | ***************************************************************************/ |
| 1137 | static int32_t |
| 1138 | e1000_get_software_semaphore(struct e1000_hw *hw) |
| 1139 | { |
| 1140 | int32_t timeout = hw->eeprom.word_size + 1; |
| 1141 | uint32_t swsm; |
| 1142 | |
| 1143 | DEBUGFUNC(); |
| 1144 | |
Hannu Lounento | c56999e | 2018-01-10 20:31:24 +0100 | [diff] [blame] | 1145 | if (hw->mac_type != e1000_80003es2lan && hw->mac_type != e1000_igb) |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1146 | return E1000_SUCCESS; |
| 1147 | |
| 1148 | while (timeout) { |
| 1149 | swsm = E1000_READ_REG(hw, SWSM); |
| 1150 | /* If SMBI bit cleared, it is now set and we hold |
| 1151 | * the semaphore */ |
| 1152 | if (!(swsm & E1000_SWSM_SMBI)) |
| 1153 | break; |
| 1154 | mdelay(1); |
| 1155 | timeout--; |
| 1156 | } |
| 1157 | |
| 1158 | if (!timeout) { |
| 1159 | DEBUGOUT("Driver can't access device - SMBI bit is set.\n"); |
| 1160 | return -E1000_ERR_RESET; |
| 1161 | } |
| 1162 | |
| 1163 | return E1000_SUCCESS; |
| 1164 | } |
Rojhalat Ibrahim | bbcd2b0 | 2013-10-07 18:30:39 +0200 | [diff] [blame] | 1165 | #endif |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1166 | |
| 1167 | /*************************************************************************** |
| 1168 | * This function clears HW semaphore bits. |
| 1169 | * |
| 1170 | * hw: Struct containing variables accessed by shared code |
| 1171 | * |
| 1172 | * returns: - None. |
| 1173 | * |
| 1174 | ***************************************************************************/ |
| 1175 | static void |
| 1176 | e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw) |
| 1177 | { |
Rojhalat Ibrahim | bbcd2b0 | 2013-10-07 18:30:39 +0200 | [diff] [blame] | 1178 | #ifndef CONFIG_E1000_NO_NVM |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1179 | uint32_t swsm; |
| 1180 | |
| 1181 | DEBUGFUNC(); |
| 1182 | |
| 1183 | if (!hw->eeprom_semaphore_present) |
| 1184 | return; |
| 1185 | |
| 1186 | swsm = E1000_READ_REG(hw, SWSM); |
Bernhard Messerklinger | 801ae71 | 2018-02-15 08:55:49 +0100 | [diff] [blame] | 1187 | if (hw->mac_type == e1000_80003es2lan || hw->mac_type == e1000_igb) { |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1188 | /* Release both semaphores. */ |
| 1189 | swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI); |
| 1190 | } else |
| 1191 | swsm &= ~(E1000_SWSM_SWESMBI); |
| 1192 | E1000_WRITE_REG(hw, SWSM, swsm); |
Rojhalat Ibrahim | bbcd2b0 | 2013-10-07 18:30:39 +0200 | [diff] [blame] | 1193 | #endif |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1194 | } |
| 1195 | |
| 1196 | /*************************************************************************** |
| 1197 | * |
| 1198 | * Using the combination of SMBI and SWESMBI semaphore bits when resetting |
| 1199 | * adapter or Eeprom access. |
| 1200 | * |
| 1201 | * hw: Struct containing variables accessed by shared code |
| 1202 | * |
| 1203 | * returns: - E1000_ERR_EEPROM if fail to access EEPROM. |
| 1204 | * E1000_SUCCESS at any other case. |
| 1205 | * |
| 1206 | ***************************************************************************/ |
| 1207 | static int32_t |
| 1208 | e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw) |
| 1209 | { |
Rojhalat Ibrahim | bbcd2b0 | 2013-10-07 18:30:39 +0200 | [diff] [blame] | 1210 | #ifndef CONFIG_E1000_NO_NVM |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1211 | int32_t timeout; |
| 1212 | uint32_t swsm; |
| 1213 | |
| 1214 | DEBUGFUNC(); |
| 1215 | |
| 1216 | if (!hw->eeprom_semaphore_present) |
| 1217 | return E1000_SUCCESS; |
| 1218 | |
Hannu Lounento | c56999e | 2018-01-10 20:31:24 +0100 | [diff] [blame] | 1219 | if (hw->mac_type == e1000_80003es2lan || hw->mac_type == e1000_igb) { |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1220 | /* Get the SW semaphore. */ |
| 1221 | if (e1000_get_software_semaphore(hw) != E1000_SUCCESS) |
| 1222 | return -E1000_ERR_EEPROM; |
| 1223 | } |
| 1224 | |
| 1225 | /* Get the FW semaphore. */ |
| 1226 | timeout = hw->eeprom.word_size + 1; |
| 1227 | while (timeout) { |
| 1228 | swsm = E1000_READ_REG(hw, SWSM); |
| 1229 | swsm |= E1000_SWSM_SWESMBI; |
| 1230 | E1000_WRITE_REG(hw, SWSM, swsm); |
| 1231 | /* if we managed to set the bit we got the semaphore. */ |
| 1232 | swsm = E1000_READ_REG(hw, SWSM); |
| 1233 | if (swsm & E1000_SWSM_SWESMBI) |
| 1234 | break; |
| 1235 | |
| 1236 | udelay(50); |
| 1237 | timeout--; |
| 1238 | } |
| 1239 | |
| 1240 | if (!timeout) { |
| 1241 | /* Release semaphores */ |
| 1242 | e1000_put_hw_eeprom_semaphore(hw); |
| 1243 | DEBUGOUT("Driver can't access the Eeprom - " |
| 1244 | "SWESMBI bit is set.\n"); |
| 1245 | return -E1000_ERR_EEPROM; |
| 1246 | } |
Rojhalat Ibrahim | bbcd2b0 | 2013-10-07 18:30:39 +0200 | [diff] [blame] | 1247 | #endif |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1248 | return E1000_SUCCESS; |
| 1249 | } |
| 1250 | |
Tim Harvey | 5cb59ec | 2015-05-19 10:01:18 -0700 | [diff] [blame] | 1251 | /* Take ownership of the PHY */ |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1252 | static int32_t |
| 1253 | e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask) |
| 1254 | { |
| 1255 | uint32_t swfw_sync = 0; |
| 1256 | uint32_t swmask = mask; |
| 1257 | uint32_t fwmask = mask << 16; |
| 1258 | int32_t timeout = 200; |
| 1259 | |
| 1260 | DEBUGFUNC(); |
| 1261 | while (timeout) { |
| 1262 | if (e1000_get_hw_eeprom_semaphore(hw)) |
| 1263 | return -E1000_ERR_SWFW_SYNC; |
| 1264 | |
Tim Harvey | dca3565 | 2015-05-19 10:01:19 -0700 | [diff] [blame] | 1265 | swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC); |
York Sun | 4303a83 | 2014-10-17 13:44:06 -0700 | [diff] [blame] | 1266 | if (!(swfw_sync & (fwmask | swmask))) |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1267 | break; |
| 1268 | |
| 1269 | /* firmware currently using resource (fwmask) */ |
| 1270 | /* or other software thread currently using resource (swmask) */ |
| 1271 | e1000_put_hw_eeprom_semaphore(hw); |
| 1272 | mdelay(5); |
| 1273 | timeout--; |
| 1274 | } |
| 1275 | |
| 1276 | if (!timeout) { |
| 1277 | DEBUGOUT("Driver can't access resource, SW_FW_SYNC timeout.\n"); |
| 1278 | return -E1000_ERR_SWFW_SYNC; |
| 1279 | } |
| 1280 | |
| 1281 | swfw_sync |= swmask; |
| 1282 | E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync); |
| 1283 | |
| 1284 | e1000_put_hw_eeprom_semaphore(hw); |
| 1285 | return E1000_SUCCESS; |
| 1286 | } |
| 1287 | |
Tim Harvey | 5cb59ec | 2015-05-19 10:01:18 -0700 | [diff] [blame] | 1288 | static void e1000_swfw_sync_release(struct e1000_hw *hw, uint16_t mask) |
| 1289 | { |
| 1290 | uint32_t swfw_sync = 0; |
| 1291 | |
| 1292 | DEBUGFUNC(); |
| 1293 | while (e1000_get_hw_eeprom_semaphore(hw)) |
| 1294 | ; /* Empty */ |
| 1295 | |
| 1296 | swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC); |
| 1297 | swfw_sync &= ~mask; |
| 1298 | E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync); |
| 1299 | |
| 1300 | e1000_put_hw_eeprom_semaphore(hw); |
| 1301 | } |
| 1302 | |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 1303 | static bool e1000_is_second_port(struct e1000_hw *hw) |
Kyle Moffett | 7376f8d | 2010-09-13 05:52:22 +0000 | [diff] [blame] | 1304 | { |
| 1305 | switch (hw->mac_type) { |
| 1306 | case e1000_80003es2lan: |
| 1307 | case e1000_82546: |
| 1308 | case e1000_82571: |
| 1309 | if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1) |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 1310 | return true; |
Kyle Moffett | 7376f8d | 2010-09-13 05:52:22 +0000 | [diff] [blame] | 1311 | /* Fallthrough */ |
| 1312 | default: |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 1313 | return false; |
Kyle Moffett | 7376f8d | 2010-09-13 05:52:22 +0000 | [diff] [blame] | 1314 | } |
| 1315 | } |
| 1316 | |
Rojhalat Ibrahim | bbcd2b0 | 2013-10-07 18:30:39 +0200 | [diff] [blame] | 1317 | #ifndef CONFIG_E1000_NO_NVM |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1318 | /****************************************************************************** |
Hannu Lounento | f36be3c | 2018-01-10 20:31:25 +0100 | [diff] [blame] | 1319 | * Reads the adapter's MAC address from the EEPROM |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1320 | * |
Hannu Lounento | f36be3c | 2018-01-10 20:31:25 +0100 | [diff] [blame] | 1321 | * hw - Struct containing variables accessed by shared code |
| 1322 | * enetaddr - buffering where the MAC address will be stored |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1323 | *****************************************************************************/ |
Hannu Lounento | f36be3c | 2018-01-10 20:31:25 +0100 | [diff] [blame] | 1324 | static int e1000_read_mac_addr_from_eeprom(struct e1000_hw *hw, |
| 1325 | unsigned char enetaddr[6]) |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1326 | { |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1327 | uint16_t offset; |
| 1328 | uint16_t eeprom_data; |
| 1329 | int i; |
| 1330 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1331 | for (i = 0; i < NODE_ADDRESS_SIZE; i += 2) { |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1332 | offset = i >> 1; |
Hannu Lounento | f36be3c | 2018-01-10 20:31:25 +0100 | [diff] [blame] | 1333 | if (e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) { |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1334 | DEBUGOUT("EEPROM Read Error\n"); |
| 1335 | return -E1000_ERR_EEPROM; |
| 1336 | } |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 1337 | enetaddr[i] = eeprom_data & 0xff; |
| 1338 | enetaddr[i + 1] = (eeprom_data >> 8) & 0xff; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1339 | } |
Hannu Lounento | f36be3c | 2018-01-10 20:31:25 +0100 | [diff] [blame] | 1340 | |
| 1341 | return 0; |
| 1342 | } |
| 1343 | |
| 1344 | /****************************************************************************** |
| 1345 | * Reads the adapter's MAC address from the RAL/RAH registers |
| 1346 | * |
| 1347 | * hw - Struct containing variables accessed by shared code |
| 1348 | * enetaddr - buffering where the MAC address will be stored |
| 1349 | *****************************************************************************/ |
| 1350 | static int e1000_read_mac_addr_from_regs(struct e1000_hw *hw, |
| 1351 | unsigned char enetaddr[6]) |
| 1352 | { |
| 1353 | uint16_t offset, tmp; |
| 1354 | uint32_t reg_data = 0; |
| 1355 | int i; |
| 1356 | |
| 1357 | if (hw->mac_type != e1000_igb) |
| 1358 | return -E1000_ERR_MAC_TYPE; |
| 1359 | |
| 1360 | for (i = 0; i < NODE_ADDRESS_SIZE; i += 2) { |
| 1361 | offset = i >> 1; |
| 1362 | |
| 1363 | if (offset == 0) |
| 1364 | reg_data = E1000_READ_REG_ARRAY(hw, RA, 0); |
| 1365 | else if (offset == 1) |
| 1366 | reg_data >>= 16; |
| 1367 | else if (offset == 2) |
| 1368 | reg_data = E1000_READ_REG_ARRAY(hw, RA, 1); |
| 1369 | tmp = reg_data & 0xffff; |
| 1370 | |
| 1371 | enetaddr[i] = tmp & 0xff; |
| 1372 | enetaddr[i + 1] = (tmp >> 8) & 0xff; |
| 1373 | } |
| 1374 | |
| 1375 | return 0; |
| 1376 | } |
| 1377 | |
| 1378 | /****************************************************************************** |
| 1379 | * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the |
| 1380 | * second function of dual function devices |
| 1381 | * |
| 1382 | * hw - Struct containing variables accessed by shared code |
| 1383 | * enetaddr - buffering where the MAC address will be stored |
| 1384 | *****************************************************************************/ |
| 1385 | static int e1000_read_mac_addr(struct e1000_hw *hw, unsigned char enetaddr[6]) |
| 1386 | { |
| 1387 | int ret_val; |
| 1388 | |
| 1389 | if (hw->mac_type == e1000_igb) { |
| 1390 | /* i210 preloads MAC address into RAL/RAH registers */ |
| 1391 | ret_val = e1000_read_mac_addr_from_regs(hw, enetaddr); |
| 1392 | } else { |
| 1393 | ret_val = e1000_read_mac_addr_from_eeprom(hw, enetaddr); |
| 1394 | } |
| 1395 | if (ret_val) |
| 1396 | return ret_val; |
Kyle Moffett | 7376f8d | 2010-09-13 05:52:22 +0000 | [diff] [blame] | 1397 | |
| 1398 | /* Invert the last bit if this is the second device */ |
| 1399 | if (e1000_is_second_port(hw)) |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 1400 | enetaddr[5] ^= 1; |
Kyle Moffett | 7376f8d | 2010-09-13 05:52:22 +0000 | [diff] [blame] | 1401 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1402 | return 0; |
| 1403 | } |
Rojhalat Ibrahim | bbcd2b0 | 2013-10-07 18:30:39 +0200 | [diff] [blame] | 1404 | #endif |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1405 | |
| 1406 | /****************************************************************************** |
| 1407 | * Initializes receive address filters. |
| 1408 | * |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1409 | * hw - Struct containing variables accessed by shared code |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1410 | * |
| 1411 | * Places the MAC address in receive address register 0 and clears the rest |
| 1412 | * of the receive addresss registers. Clears the multicast table. Assumes |
| 1413 | * the receiver is in reset when the routine is called. |
| 1414 | *****************************************************************************/ |
| 1415 | static void |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 1416 | e1000_init_rx_addrs(struct e1000_hw *hw, unsigned char enetaddr[6]) |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1417 | { |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1418 | uint32_t i; |
| 1419 | uint32_t addr_low; |
| 1420 | uint32_t addr_high; |
| 1421 | |
| 1422 | DEBUGFUNC(); |
| 1423 | |
| 1424 | /* Setup the receive address. */ |
| 1425 | DEBUGOUT("Programming MAC Address into RAR[0]\n"); |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 1426 | addr_low = (enetaddr[0] | |
| 1427 | (enetaddr[1] << 8) | |
| 1428 | (enetaddr[2] << 16) | (enetaddr[3] << 24)); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1429 | |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 1430 | addr_high = (enetaddr[4] | (enetaddr[5] << 8) | E1000_RAH_AV); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1431 | |
| 1432 | E1000_WRITE_REG_ARRAY(hw, RA, 0, addr_low); |
| 1433 | E1000_WRITE_REG_ARRAY(hw, RA, 1, addr_high); |
| 1434 | |
| 1435 | /* Zero out the other 15 receive addresses. */ |
| 1436 | DEBUGOUT("Clearing RAR[1-15]\n"); |
| 1437 | for (i = 1; i < E1000_RAR_ENTRIES; i++) { |
| 1438 | E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0); |
| 1439 | E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0); |
| 1440 | } |
| 1441 | } |
| 1442 | |
| 1443 | /****************************************************************************** |
| 1444 | * Clears the VLAN filer table |
| 1445 | * |
| 1446 | * hw - Struct containing variables accessed by shared code |
| 1447 | *****************************************************************************/ |
| 1448 | static void |
| 1449 | e1000_clear_vfta(struct e1000_hw *hw) |
| 1450 | { |
| 1451 | uint32_t offset; |
| 1452 | |
| 1453 | for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) |
| 1454 | E1000_WRITE_REG_ARRAY(hw, VFTA, offset, 0); |
| 1455 | } |
| 1456 | |
| 1457 | /****************************************************************************** |
| 1458 | * Set the mac type member in the hw struct. |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1459 | * |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1460 | * hw - Struct containing variables accessed by shared code |
| 1461 | *****************************************************************************/ |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1462 | int32_t |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1463 | e1000_set_mac_type(struct e1000_hw *hw) |
| 1464 | { |
| 1465 | DEBUGFUNC(); |
| 1466 | |
| 1467 | switch (hw->device_id) { |
| 1468 | case E1000_DEV_ID_82542: |
| 1469 | switch (hw->revision_id) { |
| 1470 | case E1000_82542_2_0_REV_ID: |
| 1471 | hw->mac_type = e1000_82542_rev2_0; |
| 1472 | break; |
| 1473 | case E1000_82542_2_1_REV_ID: |
| 1474 | hw->mac_type = e1000_82542_rev2_1; |
| 1475 | break; |
| 1476 | default: |
| 1477 | /* Invalid 82542 revision ID */ |
| 1478 | return -E1000_ERR_MAC_TYPE; |
| 1479 | } |
| 1480 | break; |
| 1481 | case E1000_DEV_ID_82543GC_FIBER: |
| 1482 | case E1000_DEV_ID_82543GC_COPPER: |
| 1483 | hw->mac_type = e1000_82543; |
| 1484 | break; |
| 1485 | case E1000_DEV_ID_82544EI_COPPER: |
| 1486 | case E1000_DEV_ID_82544EI_FIBER: |
| 1487 | case E1000_DEV_ID_82544GC_COPPER: |
| 1488 | case E1000_DEV_ID_82544GC_LOM: |
| 1489 | hw->mac_type = e1000_82544; |
| 1490 | break; |
| 1491 | case E1000_DEV_ID_82540EM: |
| 1492 | case E1000_DEV_ID_82540EM_LOM: |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1493 | case E1000_DEV_ID_82540EP: |
| 1494 | case E1000_DEV_ID_82540EP_LOM: |
| 1495 | case E1000_DEV_ID_82540EP_LP: |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1496 | hw->mac_type = e1000_82540; |
| 1497 | break; |
| 1498 | case E1000_DEV_ID_82545EM_COPPER: |
| 1499 | case E1000_DEV_ID_82545EM_FIBER: |
| 1500 | hw->mac_type = e1000_82545; |
| 1501 | break; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1502 | case E1000_DEV_ID_82545GM_COPPER: |
| 1503 | case E1000_DEV_ID_82545GM_FIBER: |
| 1504 | case E1000_DEV_ID_82545GM_SERDES: |
| 1505 | hw->mac_type = e1000_82545_rev_3; |
| 1506 | break; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1507 | case E1000_DEV_ID_82546EB_COPPER: |
| 1508 | case E1000_DEV_ID_82546EB_FIBER: |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1509 | case E1000_DEV_ID_82546EB_QUAD_COPPER: |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1510 | hw->mac_type = e1000_82546; |
| 1511 | break; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1512 | case E1000_DEV_ID_82546GB_COPPER: |
| 1513 | case E1000_DEV_ID_82546GB_FIBER: |
| 1514 | case E1000_DEV_ID_82546GB_SERDES: |
| 1515 | case E1000_DEV_ID_82546GB_PCIE: |
| 1516 | case E1000_DEV_ID_82546GB_QUAD_COPPER: |
| 1517 | case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3: |
| 1518 | hw->mac_type = e1000_82546_rev_3; |
| 1519 | break; |
| 1520 | case E1000_DEV_ID_82541EI: |
| 1521 | case E1000_DEV_ID_82541EI_MOBILE: |
| 1522 | case E1000_DEV_ID_82541ER_LOM: |
| 1523 | hw->mac_type = e1000_82541; |
| 1524 | break; |
Andre Schwarz | 68c2a30 | 2008-03-06 16:45:44 +0100 | [diff] [blame] | 1525 | case E1000_DEV_ID_82541ER: |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1526 | case E1000_DEV_ID_82541GI: |
Wolfgang Grandegger | 8562c38 | 2008-05-28 19:55:19 +0200 | [diff] [blame] | 1527 | case E1000_DEV_ID_82541GI_LF: |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1528 | case E1000_DEV_ID_82541GI_MOBILE: |
Wolfgang Denk | 35f734f | 2008-04-13 09:59:26 -0700 | [diff] [blame] | 1529 | hw->mac_type = e1000_82541_rev_2; |
| 1530 | break; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1531 | case E1000_DEV_ID_82547EI: |
| 1532 | case E1000_DEV_ID_82547EI_MOBILE: |
| 1533 | hw->mac_type = e1000_82547; |
| 1534 | break; |
| 1535 | case E1000_DEV_ID_82547GI: |
| 1536 | hw->mac_type = e1000_82547_rev_2; |
| 1537 | break; |
| 1538 | case E1000_DEV_ID_82571EB_COPPER: |
| 1539 | case E1000_DEV_ID_82571EB_FIBER: |
| 1540 | case E1000_DEV_ID_82571EB_SERDES: |
| 1541 | case E1000_DEV_ID_82571EB_SERDES_DUAL: |
| 1542 | case E1000_DEV_ID_82571EB_SERDES_QUAD: |
| 1543 | case E1000_DEV_ID_82571EB_QUAD_COPPER: |
| 1544 | case E1000_DEV_ID_82571PT_QUAD_COPPER: |
| 1545 | case E1000_DEV_ID_82571EB_QUAD_FIBER: |
| 1546 | case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE: |
| 1547 | hw->mac_type = e1000_82571; |
| 1548 | break; |
| 1549 | case E1000_DEV_ID_82572EI_COPPER: |
| 1550 | case E1000_DEV_ID_82572EI_FIBER: |
| 1551 | case E1000_DEV_ID_82572EI_SERDES: |
| 1552 | case E1000_DEV_ID_82572EI: |
| 1553 | hw->mac_type = e1000_82572; |
| 1554 | break; |
| 1555 | case E1000_DEV_ID_82573E: |
| 1556 | case E1000_DEV_ID_82573E_IAMT: |
| 1557 | case E1000_DEV_ID_82573L: |
| 1558 | hw->mac_type = e1000_82573; |
| 1559 | break; |
Roy Zang | 181119b | 2011-01-21 11:29:38 +0800 | [diff] [blame] | 1560 | case E1000_DEV_ID_82574L: |
| 1561 | hw->mac_type = e1000_82574; |
| 1562 | break; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1563 | case E1000_DEV_ID_80003ES2LAN_COPPER_SPT: |
| 1564 | case E1000_DEV_ID_80003ES2LAN_SERDES_SPT: |
| 1565 | case E1000_DEV_ID_80003ES2LAN_COPPER_DPT: |
| 1566 | case E1000_DEV_ID_80003ES2LAN_SERDES_DPT: |
| 1567 | hw->mac_type = e1000_80003es2lan; |
| 1568 | break; |
| 1569 | case E1000_DEV_ID_ICH8_IGP_M_AMT: |
| 1570 | case E1000_DEV_ID_ICH8_IGP_AMT: |
| 1571 | case E1000_DEV_ID_ICH8_IGP_C: |
| 1572 | case E1000_DEV_ID_ICH8_IFE: |
| 1573 | case E1000_DEV_ID_ICH8_IFE_GT: |
| 1574 | case E1000_DEV_ID_ICH8_IFE_G: |
| 1575 | case E1000_DEV_ID_ICH8_IGP_M: |
| 1576 | hw->mac_type = e1000_ich8lan; |
| 1577 | break; |
Marcel Ziswiler | b9f6623 | 2014-09-08 00:03:50 +0200 | [diff] [blame] | 1578 | case PCI_DEVICE_ID_INTEL_I210_UNPROGRAMMED: |
| 1579 | case PCI_DEVICE_ID_INTEL_I211_UNPROGRAMMED: |
Marek Vasut | 74a13c2 | 2014-08-08 07:41:39 -0700 | [diff] [blame] | 1580 | case PCI_DEVICE_ID_INTEL_I210_COPPER: |
Marcel Ziswiler | b9f6623 | 2014-09-08 00:03:50 +0200 | [diff] [blame] | 1581 | case PCI_DEVICE_ID_INTEL_I211_COPPER: |
Marek Vasut | 74a13c2 | 2014-08-08 07:41:39 -0700 | [diff] [blame] | 1582 | case PCI_DEVICE_ID_INTEL_I210_COPPER_FLASHLESS: |
| 1583 | case PCI_DEVICE_ID_INTEL_I210_SERDES: |
| 1584 | case PCI_DEVICE_ID_INTEL_I210_SERDES_FLASHLESS: |
| 1585 | case PCI_DEVICE_ID_INTEL_I210_1000BASEKX: |
| 1586 | hw->mac_type = e1000_igb; |
| 1587 | break; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1588 | default: |
| 1589 | /* Should never have loaded on this device */ |
| 1590 | return -E1000_ERR_MAC_TYPE; |
| 1591 | } |
| 1592 | return E1000_SUCCESS; |
| 1593 | } |
| 1594 | |
| 1595 | /****************************************************************************** |
| 1596 | * Reset the transmit and receive units; mask and clear all interrupts. |
| 1597 | * |
| 1598 | * hw - Struct containing variables accessed by shared code |
| 1599 | *****************************************************************************/ |
| 1600 | void |
| 1601 | e1000_reset_hw(struct e1000_hw *hw) |
| 1602 | { |
| 1603 | uint32_t ctrl; |
| 1604 | uint32_t ctrl_ext; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1605 | uint32_t manc; |
Roy Zang | 966172e | 2009-08-22 03:49:52 +0800 | [diff] [blame] | 1606 | uint32_t pba = 0; |
Marek Vasut | 74a13c2 | 2014-08-08 07:41:39 -0700 | [diff] [blame] | 1607 | uint32_t reg; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1608 | |
| 1609 | DEBUGFUNC(); |
| 1610 | |
Roy Zang | 966172e | 2009-08-22 03:49:52 +0800 | [diff] [blame] | 1611 | /* get the correct pba value for both PCI and PCIe*/ |
| 1612 | if (hw->mac_type < e1000_82571) |
| 1613 | pba = E1000_DEFAULT_PCI_PBA; |
| 1614 | else |
| 1615 | pba = E1000_DEFAULT_PCIE_PBA; |
| 1616 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1617 | /* For 82542 (rev 2.0), disable MWI before issuing a device reset */ |
| 1618 | if (hw->mac_type == e1000_82542_rev2_0) { |
| 1619 | DEBUGOUT("Disabling MWI on 82542 rev 2.0\n"); |
Bin Meng | 83cf24c | 2016-02-02 05:58:01 -0800 | [diff] [blame] | 1620 | #ifdef CONFIG_DM_ETH |
| 1621 | dm_pci_write_config16(hw->pdev, PCI_COMMAND, |
| 1622 | hw->pci_cmd_word & ~PCI_COMMAND_INVALIDATE); |
| 1623 | #else |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1624 | pci_write_config_word(hw->pdev, PCI_COMMAND, |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1625 | hw->pci_cmd_word & ~PCI_COMMAND_INVALIDATE); |
Bin Meng | 83cf24c | 2016-02-02 05:58:01 -0800 | [diff] [blame] | 1626 | #endif |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1627 | } |
| 1628 | |
| 1629 | /* Clear interrupt mask to stop board from generating interrupts */ |
| 1630 | DEBUGOUT("Masking off all interrupts\n"); |
Marek Vasut | 74a13c2 | 2014-08-08 07:41:39 -0700 | [diff] [blame] | 1631 | if (hw->mac_type == e1000_igb) |
| 1632 | E1000_WRITE_REG(hw, I210_IAM, 0); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1633 | E1000_WRITE_REG(hw, IMC, 0xffffffff); |
| 1634 | |
| 1635 | /* Disable the Transmit and Receive units. Then delay to allow |
| 1636 | * any pending transactions to complete before we hit the MAC with |
| 1637 | * the global reset. |
| 1638 | */ |
| 1639 | E1000_WRITE_REG(hw, RCTL, 0); |
| 1640 | E1000_WRITE_REG(hw, TCTL, E1000_TCTL_PSP); |
| 1641 | E1000_WRITE_FLUSH(hw); |
| 1642 | |
Christian Gmeiner | 7c7b3c9 | 2020-10-06 16:08:35 +0200 | [diff] [blame] | 1643 | if (hw->mac_type == e1000_igb) { |
| 1644 | E1000_WRITE_REG(hw, RXPBS, I210_RXPBSIZE_DEFAULT); |
| 1645 | E1000_WRITE_REG(hw, TXPBS, I210_TXPBSIZE_DEFAULT); |
| 1646 | } |
| 1647 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1648 | /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */ |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 1649 | hw->tbi_compatibility_on = false; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1650 | |
| 1651 | /* Delay to allow any outstanding PCI transactions to complete before |
| 1652 | * resetting the device |
| 1653 | */ |
| 1654 | mdelay(10); |
| 1655 | |
| 1656 | /* Issue a global reset to the MAC. This will reset the chip's |
| 1657 | * transmit, receive, DMA, and link units. It will not effect |
| 1658 | * the current PCI configuration. The global reset bit is self- |
| 1659 | * clearing, and should clear within a microsecond. |
| 1660 | */ |
| 1661 | DEBUGOUT("Issuing a global reset to MAC\n"); |
| 1662 | ctrl = E1000_READ_REG(hw, CTRL); |
| 1663 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1664 | E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST)); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1665 | |
| 1666 | /* Force a reload from the EEPROM if necessary */ |
Marek Vasut | 74a13c2 | 2014-08-08 07:41:39 -0700 | [diff] [blame] | 1667 | if (hw->mac_type == e1000_igb) { |
| 1668 | mdelay(20); |
| 1669 | reg = E1000_READ_REG(hw, STATUS); |
| 1670 | if (reg & E1000_STATUS_PF_RST_DONE) |
| 1671 | DEBUGOUT("PF OK\n"); |
| 1672 | reg = E1000_READ_REG(hw, I210_EECD); |
| 1673 | if (reg & E1000_EECD_AUTO_RD) |
| 1674 | DEBUGOUT("EEC OK\n"); |
| 1675 | } else if (hw->mac_type < e1000_82540) { |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1676 | /* Wait for reset to complete */ |
| 1677 | udelay(10); |
| 1678 | ctrl_ext = E1000_READ_REG(hw, CTRL_EXT); |
| 1679 | ctrl_ext |= E1000_CTRL_EXT_EE_RST; |
| 1680 | E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext); |
| 1681 | E1000_WRITE_FLUSH(hw); |
| 1682 | /* Wait for EEPROM reload */ |
| 1683 | mdelay(2); |
| 1684 | } else { |
| 1685 | /* Wait for EEPROM reload (it happens automatically) */ |
| 1686 | mdelay(4); |
| 1687 | /* Dissable HW ARPs on ASF enabled adapters */ |
| 1688 | manc = E1000_READ_REG(hw, MANC); |
| 1689 | manc &= ~(E1000_MANC_ARP_EN); |
| 1690 | E1000_WRITE_REG(hw, MANC, manc); |
| 1691 | } |
| 1692 | |
| 1693 | /* Clear interrupt mask to stop board from generating interrupts */ |
| 1694 | DEBUGOUT("Masking off all interrupts\n"); |
Marek Vasut | 74a13c2 | 2014-08-08 07:41:39 -0700 | [diff] [blame] | 1695 | if (hw->mac_type == e1000_igb) |
| 1696 | E1000_WRITE_REG(hw, I210_IAM, 0); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1697 | E1000_WRITE_REG(hw, IMC, 0xffffffff); |
| 1698 | |
| 1699 | /* Clear any pending interrupt events. */ |
Zang Roy-R61911 | e36d67c | 2011-11-06 22:22:36 +0000 | [diff] [blame] | 1700 | E1000_READ_REG(hw, ICR); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1701 | |
| 1702 | /* If MWI was previously enabled, reenable it. */ |
| 1703 | if (hw->mac_type == e1000_82542_rev2_0) { |
Bin Meng | 83cf24c | 2016-02-02 05:58:01 -0800 | [diff] [blame] | 1704 | #ifdef CONFIG_DM_ETH |
| 1705 | dm_pci_write_config16(hw->pdev, PCI_COMMAND, hw->pci_cmd_word); |
| 1706 | #else |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1707 | pci_write_config_word(hw->pdev, PCI_COMMAND, hw->pci_cmd_word); |
Bin Meng | 83cf24c | 2016-02-02 05:58:01 -0800 | [diff] [blame] | 1708 | #endif |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1709 | } |
Marek Vasut | 74a13c2 | 2014-08-08 07:41:39 -0700 | [diff] [blame] | 1710 | if (hw->mac_type != e1000_igb) |
| 1711 | E1000_WRITE_REG(hw, PBA, pba); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1712 | } |
| 1713 | |
| 1714 | /****************************************************************************** |
| 1715 | * |
| 1716 | * Initialize a number of hardware-dependent bits |
| 1717 | * |
| 1718 | * hw: Struct containing variables accessed by shared code |
| 1719 | * |
| 1720 | * This function contains hardware limitation workarounds for PCI-E adapters |
| 1721 | * |
| 1722 | *****************************************************************************/ |
| 1723 | static void |
| 1724 | e1000_initialize_hardware_bits(struct e1000_hw *hw) |
| 1725 | { |
| 1726 | if ((hw->mac_type >= e1000_82571) && |
| 1727 | (!hw->initialize_hw_bits_disable)) { |
| 1728 | /* Settings common to all PCI-express silicon */ |
| 1729 | uint32_t reg_ctrl, reg_ctrl_ext; |
| 1730 | uint32_t reg_tarc0, reg_tarc1; |
| 1731 | uint32_t reg_tctl; |
| 1732 | uint32_t reg_txdctl, reg_txdctl1; |
| 1733 | |
| 1734 | /* link autonegotiation/sync workarounds */ |
| 1735 | reg_tarc0 = E1000_READ_REG(hw, TARC0); |
| 1736 | reg_tarc0 &= ~((1 << 30)|(1 << 29)|(1 << 28)|(1 << 27)); |
| 1737 | |
| 1738 | /* Enable not-done TX descriptor counting */ |
| 1739 | reg_txdctl = E1000_READ_REG(hw, TXDCTL); |
| 1740 | reg_txdctl |= E1000_TXDCTL_COUNT_DESC; |
| 1741 | E1000_WRITE_REG(hw, TXDCTL, reg_txdctl); |
| 1742 | |
| 1743 | reg_txdctl1 = E1000_READ_REG(hw, TXDCTL1); |
| 1744 | reg_txdctl1 |= E1000_TXDCTL_COUNT_DESC; |
| 1745 | E1000_WRITE_REG(hw, TXDCTL1, reg_txdctl1); |
| 1746 | |
Marek Vasut | 74a13c2 | 2014-08-08 07:41:39 -0700 | [diff] [blame] | 1747 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1748 | switch (hw->mac_type) { |
Andre Przywara | 4b307c1 | 2016-11-16 00:50:07 +0000 | [diff] [blame] | 1749 | case e1000_igb: /* IGB is cool */ |
| 1750 | return; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1751 | case e1000_82571: |
| 1752 | case e1000_82572: |
| 1753 | /* Clear PHY TX compatible mode bits */ |
| 1754 | reg_tarc1 = E1000_READ_REG(hw, TARC1); |
| 1755 | reg_tarc1 &= ~((1 << 30)|(1 << 29)); |
| 1756 | |
| 1757 | /* link autonegotiation/sync workarounds */ |
| 1758 | reg_tarc0 |= ((1 << 26)|(1 << 25)|(1 << 24)|(1 << 23)); |
| 1759 | |
| 1760 | /* TX ring control fixes */ |
| 1761 | reg_tarc1 |= ((1 << 26)|(1 << 25)|(1 << 24)); |
| 1762 | |
| 1763 | /* Multiple read bit is reversed polarity */ |
| 1764 | reg_tctl = E1000_READ_REG(hw, TCTL); |
| 1765 | if (reg_tctl & E1000_TCTL_MULR) |
| 1766 | reg_tarc1 &= ~(1 << 28); |
| 1767 | else |
| 1768 | reg_tarc1 |= (1 << 28); |
| 1769 | |
| 1770 | E1000_WRITE_REG(hw, TARC1, reg_tarc1); |
| 1771 | break; |
| 1772 | case e1000_82573: |
Roy Zang | 181119b | 2011-01-21 11:29:38 +0800 | [diff] [blame] | 1773 | case e1000_82574: |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1774 | reg_ctrl_ext = E1000_READ_REG(hw, CTRL_EXT); |
| 1775 | reg_ctrl_ext &= ~(1 << 23); |
| 1776 | reg_ctrl_ext |= (1 << 22); |
| 1777 | |
| 1778 | /* TX byte count fix */ |
| 1779 | reg_ctrl = E1000_READ_REG(hw, CTRL); |
| 1780 | reg_ctrl &= ~(1 << 29); |
| 1781 | |
| 1782 | E1000_WRITE_REG(hw, CTRL_EXT, reg_ctrl_ext); |
| 1783 | E1000_WRITE_REG(hw, CTRL, reg_ctrl); |
| 1784 | break; |
| 1785 | case e1000_80003es2lan: |
| 1786 | /* improve small packet performace for fiber/serdes */ |
| 1787 | if ((hw->media_type == e1000_media_type_fiber) |
| 1788 | || (hw->media_type == |
| 1789 | e1000_media_type_internal_serdes)) { |
| 1790 | reg_tarc0 &= ~(1 << 20); |
| 1791 | } |
| 1792 | |
| 1793 | /* Multiple read bit is reversed polarity */ |
| 1794 | reg_tctl = E1000_READ_REG(hw, TCTL); |
| 1795 | reg_tarc1 = E1000_READ_REG(hw, TARC1); |
| 1796 | if (reg_tctl & E1000_TCTL_MULR) |
| 1797 | reg_tarc1 &= ~(1 << 28); |
| 1798 | else |
| 1799 | reg_tarc1 |= (1 << 28); |
| 1800 | |
| 1801 | E1000_WRITE_REG(hw, TARC1, reg_tarc1); |
| 1802 | break; |
| 1803 | case e1000_ich8lan: |
| 1804 | /* Reduce concurrent DMA requests to 3 from 4 */ |
| 1805 | if ((hw->revision_id < 3) || |
| 1806 | ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) && |
| 1807 | (hw->device_id != E1000_DEV_ID_ICH8_IGP_M))) |
| 1808 | reg_tarc0 |= ((1 << 29)|(1 << 28)); |
| 1809 | |
| 1810 | reg_ctrl_ext = E1000_READ_REG(hw, CTRL_EXT); |
| 1811 | reg_ctrl_ext |= (1 << 22); |
| 1812 | E1000_WRITE_REG(hw, CTRL_EXT, reg_ctrl_ext); |
| 1813 | |
| 1814 | /* workaround TX hang with TSO=on */ |
| 1815 | reg_tarc0 |= ((1 << 27)|(1 << 26)|(1 << 24)|(1 << 23)); |
| 1816 | |
| 1817 | /* Multiple read bit is reversed polarity */ |
| 1818 | reg_tctl = E1000_READ_REG(hw, TCTL); |
| 1819 | reg_tarc1 = E1000_READ_REG(hw, TARC1); |
| 1820 | if (reg_tctl & E1000_TCTL_MULR) |
| 1821 | reg_tarc1 &= ~(1 << 28); |
| 1822 | else |
| 1823 | reg_tarc1 |= (1 << 28); |
| 1824 | |
| 1825 | /* workaround TX hang with TSO=on */ |
| 1826 | reg_tarc1 |= ((1 << 30)|(1 << 26)|(1 << 24)); |
| 1827 | |
| 1828 | E1000_WRITE_REG(hw, TARC1, reg_tarc1); |
| 1829 | break; |
| 1830 | default: |
| 1831 | break; |
| 1832 | } |
| 1833 | |
| 1834 | E1000_WRITE_REG(hw, TARC0, reg_tarc0); |
| 1835 | } |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1836 | } |
| 1837 | |
| 1838 | /****************************************************************************** |
| 1839 | * Performs basic configuration of the adapter. |
| 1840 | * |
| 1841 | * hw - Struct containing variables accessed by shared code |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1842 | * |
| 1843 | * Assumes that the controller has previously been reset and is in a |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1844 | * post-reset uninitialized state. Initializes the receive address registers, |
| 1845 | * multicast table, and VLAN filter table. Calls routines to setup link |
| 1846 | * configuration and flow control settings. Clears all on-chip counters. Leaves |
| 1847 | * the transmit and receive units disabled and uninitialized. |
| 1848 | *****************************************************************************/ |
| 1849 | static int |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 1850 | e1000_init_hw(struct e1000_hw *hw, unsigned char enetaddr[6]) |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1851 | { |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1852 | uint32_t ctrl; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1853 | uint32_t i; |
| 1854 | int32_t ret_val; |
| 1855 | uint16_t pcix_cmd_word; |
| 1856 | uint16_t pcix_stat_hi_word; |
| 1857 | uint16_t cmd_mmrbc; |
| 1858 | uint16_t stat_mmrbc; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1859 | uint32_t mta_size; |
| 1860 | uint32_t reg_data; |
| 1861 | uint32_t ctrl_ext; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1862 | DEBUGFUNC(); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1863 | /* force full DMA clock frequency for 10/100 on ICH8 A0-B0 */ |
| 1864 | if ((hw->mac_type == e1000_ich8lan) && |
| 1865 | ((hw->revision_id < 3) || |
| 1866 | ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) && |
| 1867 | (hw->device_id != E1000_DEV_ID_ICH8_IGP_M)))) { |
| 1868 | reg_data = E1000_READ_REG(hw, STATUS); |
| 1869 | reg_data &= ~0x80000000; |
| 1870 | E1000_WRITE_REG(hw, STATUS, reg_data); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1871 | } |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1872 | /* Do not need initialize Identification LED */ |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1873 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1874 | /* Set the media type and TBI compatibility */ |
| 1875 | e1000_set_media_type(hw); |
| 1876 | |
| 1877 | /* Must be called after e1000_set_media_type |
| 1878 | * because media_type is used */ |
| 1879 | e1000_initialize_hardware_bits(hw); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1880 | |
| 1881 | /* Disabling VLAN filtering. */ |
| 1882 | DEBUGOUT("Initializing the IEEE VLAN\n"); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1883 | /* VET hardcoded to standard value and VFTA removed in ICH8 LAN */ |
| 1884 | if (hw->mac_type != e1000_ich8lan) { |
| 1885 | if (hw->mac_type < e1000_82545_rev_3) |
| 1886 | E1000_WRITE_REG(hw, VET, 0); |
| 1887 | e1000_clear_vfta(hw); |
| 1888 | } |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1889 | |
| 1890 | /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */ |
| 1891 | if (hw->mac_type == e1000_82542_rev2_0) { |
| 1892 | DEBUGOUT("Disabling MWI on 82542 rev 2.0\n"); |
Bin Meng | 83cf24c | 2016-02-02 05:58:01 -0800 | [diff] [blame] | 1893 | #ifdef CONFIG_DM_ETH |
| 1894 | dm_pci_write_config16(hw->pdev, PCI_COMMAND, |
| 1895 | hw-> |
| 1896 | pci_cmd_word & ~PCI_COMMAND_INVALIDATE); |
| 1897 | #else |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1898 | pci_write_config_word(hw->pdev, PCI_COMMAND, |
| 1899 | hw-> |
| 1900 | pci_cmd_word & ~PCI_COMMAND_INVALIDATE); |
Bin Meng | 83cf24c | 2016-02-02 05:58:01 -0800 | [diff] [blame] | 1901 | #endif |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1902 | E1000_WRITE_REG(hw, RCTL, E1000_RCTL_RST); |
| 1903 | E1000_WRITE_FLUSH(hw); |
| 1904 | mdelay(5); |
| 1905 | } |
| 1906 | |
| 1907 | /* Setup the receive address. This involves initializing all of the Receive |
| 1908 | * Address Registers (RARs 0 - 15). |
| 1909 | */ |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 1910 | e1000_init_rx_addrs(hw, enetaddr); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1911 | |
| 1912 | /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */ |
| 1913 | if (hw->mac_type == e1000_82542_rev2_0) { |
| 1914 | E1000_WRITE_REG(hw, RCTL, 0); |
| 1915 | E1000_WRITE_FLUSH(hw); |
| 1916 | mdelay(1); |
Bin Meng | 83cf24c | 2016-02-02 05:58:01 -0800 | [diff] [blame] | 1917 | #ifdef CONFIG_DM_ETH |
| 1918 | dm_pci_write_config16(hw->pdev, PCI_COMMAND, hw->pci_cmd_word); |
| 1919 | #else |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1920 | pci_write_config_word(hw->pdev, PCI_COMMAND, hw->pci_cmd_word); |
Bin Meng | 83cf24c | 2016-02-02 05:58:01 -0800 | [diff] [blame] | 1921 | #endif |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1922 | } |
| 1923 | |
| 1924 | /* Zero out the Multicast HASH table */ |
| 1925 | DEBUGOUT("Zeroing the MTA\n"); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1926 | mta_size = E1000_MC_TBL_SIZE; |
| 1927 | if (hw->mac_type == e1000_ich8lan) |
| 1928 | mta_size = E1000_MC_TBL_SIZE_ICH8LAN; |
| 1929 | for (i = 0; i < mta_size; i++) { |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1930 | E1000_WRITE_REG_ARRAY(hw, MTA, i, 0); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1931 | /* use write flush to prevent Memory Write Block (MWB) from |
| 1932 | * occuring when accessing our register space */ |
| 1933 | E1000_WRITE_FLUSH(hw); |
| 1934 | } |
Bin Meng | 1ba7e95 | 2015-11-16 01:19:16 -0800 | [diff] [blame] | 1935 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1936 | switch (hw->mac_type) { |
| 1937 | case e1000_82545_rev_3: |
| 1938 | case e1000_82546_rev_3: |
Marek Vasut | 74a13c2 | 2014-08-08 07:41:39 -0700 | [diff] [blame] | 1939 | case e1000_igb: |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1940 | break; |
| 1941 | default: |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1942 | /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */ |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1943 | if (hw->bus_type == e1000_bus_type_pcix) { |
Bin Meng | 83cf24c | 2016-02-02 05:58:01 -0800 | [diff] [blame] | 1944 | #ifdef CONFIG_DM_ETH |
| 1945 | dm_pci_read_config16(hw->pdev, PCIX_COMMAND_REGISTER, |
| 1946 | &pcix_cmd_word); |
| 1947 | dm_pci_read_config16(hw->pdev, PCIX_STATUS_REGISTER_HI, |
| 1948 | &pcix_stat_hi_word); |
| 1949 | #else |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1950 | pci_read_config_word(hw->pdev, PCIX_COMMAND_REGISTER, |
| 1951 | &pcix_cmd_word); |
| 1952 | pci_read_config_word(hw->pdev, PCIX_STATUS_REGISTER_HI, |
| 1953 | &pcix_stat_hi_word); |
Bin Meng | 83cf24c | 2016-02-02 05:58:01 -0800 | [diff] [blame] | 1954 | #endif |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1955 | cmd_mmrbc = |
| 1956 | (pcix_cmd_word & PCIX_COMMAND_MMRBC_MASK) >> |
| 1957 | PCIX_COMMAND_MMRBC_SHIFT; |
| 1958 | stat_mmrbc = |
| 1959 | (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >> |
| 1960 | PCIX_STATUS_HI_MMRBC_SHIFT; |
| 1961 | if (stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K) |
| 1962 | stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K; |
| 1963 | if (cmd_mmrbc > stat_mmrbc) { |
| 1964 | pcix_cmd_word &= ~PCIX_COMMAND_MMRBC_MASK; |
| 1965 | pcix_cmd_word |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT; |
Bin Meng | 83cf24c | 2016-02-02 05:58:01 -0800 | [diff] [blame] | 1966 | #ifdef CONFIG_DM_ETH |
| 1967 | dm_pci_write_config16(hw->pdev, PCIX_COMMAND_REGISTER, |
| 1968 | pcix_cmd_word); |
| 1969 | #else |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1970 | pci_write_config_word(hw->pdev, PCIX_COMMAND_REGISTER, |
| 1971 | pcix_cmd_word); |
Bin Meng | 83cf24c | 2016-02-02 05:58:01 -0800 | [diff] [blame] | 1972 | #endif |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1973 | } |
| 1974 | } |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1975 | break; |
| 1976 | } |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1977 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1978 | /* More time needed for PHY to initialize */ |
| 1979 | if (hw->mac_type == e1000_ich8lan) |
| 1980 | mdelay(15); |
Marek Vasut | 74a13c2 | 2014-08-08 07:41:39 -0700 | [diff] [blame] | 1981 | if (hw->mac_type == e1000_igb) |
| 1982 | mdelay(15); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1983 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1984 | /* Call a subroutine to configure the link and setup flow control. */ |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 1985 | ret_val = e1000_setup_link(hw); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 1986 | |
| 1987 | /* Set the transmit descriptor write-back policy */ |
| 1988 | if (hw->mac_type > e1000_82544) { |
| 1989 | ctrl = E1000_READ_REG(hw, TXDCTL); |
| 1990 | ctrl = |
| 1991 | (ctrl & ~E1000_TXDCTL_WTHRESH) | |
| 1992 | E1000_TXDCTL_FULL_TX_DESC_WB; |
| 1993 | E1000_WRITE_REG(hw, TXDCTL, ctrl); |
| 1994 | } |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 1995 | |
Ruchika Gupta | ed1f72f | 2012-04-19 02:27:11 +0000 | [diff] [blame] | 1996 | /* Set the receive descriptor write back policy */ |
Ruchika Gupta | ed1f72f | 2012-04-19 02:27:11 +0000 | [diff] [blame] | 1997 | if (hw->mac_type >= e1000_82571) { |
| 1998 | ctrl = E1000_READ_REG(hw, RXDCTL); |
| 1999 | ctrl = |
| 2000 | (ctrl & ~E1000_RXDCTL_WTHRESH) | |
| 2001 | E1000_RXDCTL_FULL_RX_DESC_WB; |
| 2002 | E1000_WRITE_REG(hw, RXDCTL, ctrl); |
| 2003 | } |
| 2004 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2005 | switch (hw->mac_type) { |
| 2006 | default: |
| 2007 | break; |
| 2008 | case e1000_80003es2lan: |
| 2009 | /* Enable retransmit on late collisions */ |
| 2010 | reg_data = E1000_READ_REG(hw, TCTL); |
| 2011 | reg_data |= E1000_TCTL_RTLC; |
| 2012 | E1000_WRITE_REG(hw, TCTL, reg_data); |
| 2013 | |
| 2014 | /* Configure Gigabit Carry Extend Padding */ |
| 2015 | reg_data = E1000_READ_REG(hw, TCTL_EXT); |
| 2016 | reg_data &= ~E1000_TCTL_EXT_GCEX_MASK; |
| 2017 | reg_data |= DEFAULT_80003ES2LAN_TCTL_EXT_GCEX; |
| 2018 | E1000_WRITE_REG(hw, TCTL_EXT, reg_data); |
| 2019 | |
| 2020 | /* Configure Transmit Inter-Packet Gap */ |
| 2021 | reg_data = E1000_READ_REG(hw, TIPG); |
| 2022 | reg_data &= ~E1000_TIPG_IPGT_MASK; |
| 2023 | reg_data |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000; |
| 2024 | E1000_WRITE_REG(hw, TIPG, reg_data); |
| 2025 | |
| 2026 | reg_data = E1000_READ_REG_ARRAY(hw, FFLT, 0x0001); |
| 2027 | reg_data &= ~0x00100000; |
| 2028 | E1000_WRITE_REG_ARRAY(hw, FFLT, 0x0001, reg_data); |
| 2029 | /* Fall through */ |
| 2030 | case e1000_82571: |
| 2031 | case e1000_82572: |
| 2032 | case e1000_ich8lan: |
| 2033 | ctrl = E1000_READ_REG(hw, TXDCTL1); |
| 2034 | ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) |
| 2035 | | E1000_TXDCTL_FULL_TX_DESC_WB; |
| 2036 | E1000_WRITE_REG(hw, TXDCTL1, ctrl); |
| 2037 | break; |
Roy Zang | 181119b | 2011-01-21 11:29:38 +0800 | [diff] [blame] | 2038 | case e1000_82573: |
| 2039 | case e1000_82574: |
| 2040 | reg_data = E1000_READ_REG(hw, GCR); |
| 2041 | reg_data |= E1000_GCR_L1_ACT_WITHOUT_L0S_RX; |
| 2042 | E1000_WRITE_REG(hw, GCR, reg_data); |
Marek Vasut | 74a13c2 | 2014-08-08 07:41:39 -0700 | [diff] [blame] | 2043 | case e1000_igb: |
| 2044 | break; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2045 | } |
| 2046 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2047 | if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER || |
| 2048 | hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) { |
| 2049 | ctrl_ext = E1000_READ_REG(hw, CTRL_EXT); |
| 2050 | /* Relaxed ordering must be disabled to avoid a parity |
| 2051 | * error crash in a PCI slot. */ |
| 2052 | ctrl_ext |= E1000_CTRL_EXT_RO_DIS; |
| 2053 | E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext); |
| 2054 | } |
| 2055 | |
| 2056 | return ret_val; |
| 2057 | } |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2058 | |
| 2059 | /****************************************************************************** |
| 2060 | * Configures flow control and link settings. |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 2061 | * |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2062 | * hw - Struct containing variables accessed by shared code |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 2063 | * |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2064 | * Determines which flow control settings to use. Calls the apropriate media- |
| 2065 | * specific link configuration function. Configures the flow control settings. |
| 2066 | * Assuming the adapter has a valid link partner, a valid link should be |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 2067 | * established. Assumes the hardware has previously been reset and the |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2068 | * transmitter and receiver are not enabled. |
| 2069 | *****************************************************************************/ |
| 2070 | static int |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 2071 | e1000_setup_link(struct e1000_hw *hw) |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2072 | { |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2073 | int32_t ret_val; |
Rojhalat Ibrahim | bbcd2b0 | 2013-10-07 18:30:39 +0200 | [diff] [blame] | 2074 | #ifndef CONFIG_E1000_NO_NVM |
| 2075 | uint32_t ctrl_ext; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2076 | uint16_t eeprom_data; |
Rojhalat Ibrahim | bbcd2b0 | 2013-10-07 18:30:39 +0200 | [diff] [blame] | 2077 | #endif |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2078 | |
| 2079 | DEBUGFUNC(); |
| 2080 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2081 | /* In the case of the phy reset being blocked, we already have a link. |
| 2082 | * We do not have to set it up again. */ |
| 2083 | if (e1000_check_phy_reset_block(hw)) |
| 2084 | return E1000_SUCCESS; |
| 2085 | |
Rojhalat Ibrahim | bbcd2b0 | 2013-10-07 18:30:39 +0200 | [diff] [blame] | 2086 | #ifndef CONFIG_E1000_NO_NVM |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2087 | /* Read and store word 0x0F of the EEPROM. This word contains bits |
| 2088 | * that determine the hardware's default PAUSE (flow control) mode, |
| 2089 | * a bit that determines whether the HW defaults to enabling or |
| 2090 | * disabling auto-negotiation, and the direction of the |
| 2091 | * SW defined pins. If there is no SW over-ride of the flow |
| 2092 | * control setting, then the variable hw->fc will |
| 2093 | * be initialized based on a value in the EEPROM. |
| 2094 | */ |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2095 | if (e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG, 1, |
| 2096 | &eeprom_data) < 0) { |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2097 | DEBUGOUT("EEPROM Read Error\n"); |
| 2098 | return -E1000_ERR_EEPROM; |
| 2099 | } |
Rojhalat Ibrahim | bbcd2b0 | 2013-10-07 18:30:39 +0200 | [diff] [blame] | 2100 | #endif |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2101 | if (hw->fc == e1000_fc_default) { |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2102 | switch (hw->mac_type) { |
| 2103 | case e1000_ich8lan: |
| 2104 | case e1000_82573: |
Roy Zang | 181119b | 2011-01-21 11:29:38 +0800 | [diff] [blame] | 2105 | case e1000_82574: |
Marek Vasut | 74a13c2 | 2014-08-08 07:41:39 -0700 | [diff] [blame] | 2106 | case e1000_igb: |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2107 | hw->fc = e1000_fc_full; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2108 | break; |
| 2109 | default: |
Rojhalat Ibrahim | bbcd2b0 | 2013-10-07 18:30:39 +0200 | [diff] [blame] | 2110 | #ifndef CONFIG_E1000_NO_NVM |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2111 | ret_val = e1000_read_eeprom(hw, |
| 2112 | EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data); |
| 2113 | if (ret_val) { |
| 2114 | DEBUGOUT("EEPROM Read Error\n"); |
| 2115 | return -E1000_ERR_EEPROM; |
| 2116 | } |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2117 | if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0) |
| 2118 | hw->fc = e1000_fc_none; |
| 2119 | else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == |
| 2120 | EEPROM_WORD0F_ASM_DIR) |
| 2121 | hw->fc = e1000_fc_tx_pause; |
| 2122 | else |
Rojhalat Ibrahim | bbcd2b0 | 2013-10-07 18:30:39 +0200 | [diff] [blame] | 2123 | #endif |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2124 | hw->fc = e1000_fc_full; |
| 2125 | break; |
| 2126 | } |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2127 | } |
| 2128 | |
| 2129 | /* We want to save off the original Flow Control configuration just |
| 2130 | * in case we get disconnected and then reconnected into a different |
| 2131 | * hub or switch with different Flow Control capabilities. |
| 2132 | */ |
| 2133 | if (hw->mac_type == e1000_82542_rev2_0) |
| 2134 | hw->fc &= (~e1000_fc_tx_pause); |
| 2135 | |
| 2136 | if ((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1)) |
| 2137 | hw->fc &= (~e1000_fc_rx_pause); |
| 2138 | |
| 2139 | hw->original_fc = hw->fc; |
| 2140 | |
| 2141 | DEBUGOUT("After fix-ups FlowControl is now = %x\n", hw->fc); |
| 2142 | |
Rojhalat Ibrahim | bbcd2b0 | 2013-10-07 18:30:39 +0200 | [diff] [blame] | 2143 | #ifndef CONFIG_E1000_NO_NVM |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2144 | /* Take the 4 bits from EEPROM word 0x0F that determine the initial |
| 2145 | * polarity value for the SW controlled pins, and setup the |
| 2146 | * Extended Device Control reg with that info. |
| 2147 | * This is needed because one of the SW controlled pins is used for |
| 2148 | * signal detection. So this should be done before e1000_setup_pcs_link() |
| 2149 | * or e1000_phy_setup() is called. |
| 2150 | */ |
| 2151 | if (hw->mac_type == e1000_82543) { |
| 2152 | ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) << |
| 2153 | SWDPIO__EXT_SHIFT); |
| 2154 | E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext); |
| 2155 | } |
Rojhalat Ibrahim | bbcd2b0 | 2013-10-07 18:30:39 +0200 | [diff] [blame] | 2156 | #endif |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2157 | |
| 2158 | /* Call the necessary subroutine to configure the link. */ |
| 2159 | ret_val = (hw->media_type == e1000_media_type_fiber) ? |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 2160 | e1000_setup_fiber_link(hw) : e1000_setup_copper_link(hw); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2161 | if (ret_val < 0) { |
| 2162 | return ret_val; |
| 2163 | } |
| 2164 | |
| 2165 | /* Initialize the flow control address, type, and PAUSE timer |
| 2166 | * registers to their default values. This is done even if flow |
| 2167 | * control is disabled, because it does not hurt anything to |
| 2168 | * initialize these registers. |
| 2169 | */ |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2170 | DEBUGOUT("Initializing the Flow Control address, type" |
| 2171 | "and timer regs\n"); |
| 2172 | |
| 2173 | /* FCAL/H and FCT are hardcoded to standard values in e1000_ich8lan. */ |
| 2174 | if (hw->mac_type != e1000_ich8lan) { |
| 2175 | E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE); |
| 2176 | E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH); |
| 2177 | E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW); |
| 2178 | } |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2179 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2180 | E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time); |
| 2181 | |
| 2182 | /* Set the flow control receive threshold registers. Normally, |
| 2183 | * these registers will be set to a default threshold that may be |
| 2184 | * adjusted later by the driver's runtime code. However, if the |
| 2185 | * ability to transmit pause frames in not enabled, then these |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 2186 | * registers will be set to 0. |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2187 | */ |
| 2188 | if (!(hw->fc & e1000_fc_tx_pause)) { |
| 2189 | E1000_WRITE_REG(hw, FCRTL, 0); |
| 2190 | E1000_WRITE_REG(hw, FCRTH, 0); |
| 2191 | } else { |
| 2192 | /* We need to set up the Receive Threshold high and low water marks |
| 2193 | * as well as (optionally) enabling the transmission of XON frames. |
| 2194 | */ |
| 2195 | if (hw->fc_send_xon) { |
| 2196 | E1000_WRITE_REG(hw, FCRTL, |
| 2197 | (hw->fc_low_water | E1000_FCRTL_XONE)); |
| 2198 | E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water); |
| 2199 | } else { |
| 2200 | E1000_WRITE_REG(hw, FCRTL, hw->fc_low_water); |
| 2201 | E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water); |
| 2202 | } |
| 2203 | } |
| 2204 | return ret_val; |
| 2205 | } |
| 2206 | |
| 2207 | /****************************************************************************** |
| 2208 | * Sets up link for a fiber based adapter |
| 2209 | * |
| 2210 | * hw - Struct containing variables accessed by shared code |
| 2211 | * |
| 2212 | * Manipulates Physical Coding Sublayer functions in order to configure |
| 2213 | * link. Assumes the hardware has been previously reset and the transmitter |
| 2214 | * and receiver are not enabled. |
| 2215 | *****************************************************************************/ |
| 2216 | static int |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 2217 | e1000_setup_fiber_link(struct e1000_hw *hw) |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2218 | { |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2219 | uint32_t ctrl; |
| 2220 | uint32_t status; |
| 2221 | uint32_t txcw = 0; |
| 2222 | uint32_t i; |
| 2223 | uint32_t signal; |
| 2224 | int32_t ret_val; |
| 2225 | |
| 2226 | DEBUGFUNC(); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 2227 | /* On adapters with a MAC newer that 82544, SW Defineable pin 1 will be |
| 2228 | * set when the optics detect a signal. On older adapters, it will be |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2229 | * cleared when there is a signal |
| 2230 | */ |
| 2231 | ctrl = E1000_READ_REG(hw, CTRL); |
| 2232 | if ((hw->mac_type > e1000_82544) && !(ctrl & E1000_CTRL_ILOS)) |
| 2233 | signal = E1000_CTRL_SWDPIN1; |
| 2234 | else |
| 2235 | signal = 0; |
| 2236 | |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 2237 | printf("signal for %s is %x (ctrl %08x)!!!!\n", hw->name, signal, |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2238 | ctrl); |
| 2239 | /* Take the link out of reset */ |
| 2240 | ctrl &= ~(E1000_CTRL_LRST); |
| 2241 | |
| 2242 | e1000_config_collision_dist(hw); |
| 2243 | |
| 2244 | /* Check for a software override of the flow control settings, and setup |
| 2245 | * the device accordingly. If auto-negotiation is enabled, then software |
| 2246 | * will have to set the "PAUSE" bits to the correct value in the Tranmsit |
| 2247 | * Config Word Register (TXCW) and re-start auto-negotiation. However, if |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 2248 | * auto-negotiation is disabled, then software will have to manually |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2249 | * configure the two flow control enable bits in the CTRL register. |
| 2250 | * |
| 2251 | * The possible values of the "fc" parameter are: |
Wolfgang Denk | 35f734f | 2008-04-13 09:59:26 -0700 | [diff] [blame] | 2252 | * 0: Flow control is completely disabled |
| 2253 | * 1: Rx flow control is enabled (we can receive pause frames, but |
| 2254 | * not send pause frames). |
| 2255 | * 2: Tx flow control is enabled (we can send pause frames but we do |
| 2256 | * not support receiving pause frames). |
| 2257 | * 3: Both Rx and TX flow control (symmetric) are enabled. |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2258 | */ |
| 2259 | switch (hw->fc) { |
| 2260 | case e1000_fc_none: |
| 2261 | /* Flow control is completely disabled by a software over-ride. */ |
| 2262 | txcw = (E1000_TXCW_ANE | E1000_TXCW_FD); |
| 2263 | break; |
| 2264 | case e1000_fc_rx_pause: |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 2265 | /* RX Flow control is enabled and TX Flow control is disabled by a |
| 2266 | * software over-ride. Since there really isn't a way to advertise |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2267 | * that we are capable of RX Pause ONLY, we will advertise that we |
| 2268 | * support both symmetric and asymmetric RX PAUSE. Later, we will |
| 2269 | * disable the adapter's ability to send PAUSE frames. |
| 2270 | */ |
| 2271 | txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK); |
| 2272 | break; |
| 2273 | case e1000_fc_tx_pause: |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 2274 | /* TX Flow control is enabled, and RX Flow control is disabled, by a |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2275 | * software over-ride. |
| 2276 | */ |
| 2277 | txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR); |
| 2278 | break; |
| 2279 | case e1000_fc_full: |
| 2280 | /* Flow control (both RX and TX) is enabled by a software over-ride. */ |
| 2281 | txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK); |
| 2282 | break; |
| 2283 | default: |
| 2284 | DEBUGOUT("Flow control param set incorrectly\n"); |
| 2285 | return -E1000_ERR_CONFIG; |
| 2286 | break; |
| 2287 | } |
| 2288 | |
| 2289 | /* Since auto-negotiation is enabled, take the link out of reset (the link |
| 2290 | * will be in reset, because we previously reset the chip). This will |
| 2291 | * restart auto-negotiation. If auto-neogtiation is successful then the |
| 2292 | * link-up status bit will be set and the flow control enable bits (RFCE |
| 2293 | * and TFCE) will be set according to their negotiated value. |
| 2294 | */ |
| 2295 | DEBUGOUT("Auto-negotiation enabled (%#x)\n", txcw); |
| 2296 | |
| 2297 | E1000_WRITE_REG(hw, TXCW, txcw); |
| 2298 | E1000_WRITE_REG(hw, CTRL, ctrl); |
| 2299 | E1000_WRITE_FLUSH(hw); |
| 2300 | |
| 2301 | hw->txcw = txcw; |
| 2302 | mdelay(1); |
| 2303 | |
| 2304 | /* If we have a signal (the cable is plugged in) then poll for a "Link-Up" |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 2305 | * indication in the Device Status Register. Time-out if a link isn't |
| 2306 | * seen in 500 milliseconds seconds (Auto-negotiation should complete in |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2307 | * less than 500 milliseconds even if the other end is doing it in SW). |
| 2308 | */ |
| 2309 | if ((E1000_READ_REG(hw, CTRL) & E1000_CTRL_SWDPIN1) == signal) { |
| 2310 | DEBUGOUT("Looking for Link\n"); |
| 2311 | for (i = 0; i < (LINK_UP_TIMEOUT / 10); i++) { |
| 2312 | mdelay(10); |
| 2313 | status = E1000_READ_REG(hw, STATUS); |
| 2314 | if (status & E1000_STATUS_LU) |
| 2315 | break; |
| 2316 | } |
| 2317 | if (i == (LINK_UP_TIMEOUT / 10)) { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 2318 | /* AutoNeg failed to achieve a link, so we'll call |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2319 | * e1000_check_for_link. This routine will force the link up if we |
| 2320 | * detect a signal. This will allow us to communicate with |
| 2321 | * non-autonegotiating link partners. |
| 2322 | */ |
| 2323 | DEBUGOUT("Never got a valid link from auto-neg!!!\n"); |
| 2324 | hw->autoneg_failed = 1; |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 2325 | ret_val = e1000_check_for_link(hw); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2326 | if (ret_val < 0) { |
| 2327 | DEBUGOUT("Error while checking for link\n"); |
| 2328 | return ret_val; |
| 2329 | } |
| 2330 | hw->autoneg_failed = 0; |
| 2331 | } else { |
| 2332 | hw->autoneg_failed = 0; |
| 2333 | DEBUGOUT("Valid Link Found\n"); |
| 2334 | } |
| 2335 | } else { |
| 2336 | DEBUGOUT("No Signal Detected\n"); |
| 2337 | return -E1000_ERR_NOLINK; |
| 2338 | } |
| 2339 | return 0; |
| 2340 | } |
| 2341 | |
| 2342 | /****************************************************************************** |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2343 | * Make sure we have a valid PHY and change PHY mode before link setup. |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2344 | * |
| 2345 | * hw - Struct containing variables accessed by shared code |
| 2346 | ******************************************************************************/ |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2347 | static int32_t |
| 2348 | e1000_copper_link_preconfig(struct e1000_hw *hw) |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2349 | { |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2350 | uint32_t ctrl; |
| 2351 | int32_t ret_val; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2352 | uint16_t phy_data; |
| 2353 | |
| 2354 | DEBUGFUNC(); |
| 2355 | |
| 2356 | ctrl = E1000_READ_REG(hw, CTRL); |
| 2357 | /* With 82543, we need to force speed and duplex on the MAC equal to what |
| 2358 | * the PHY speed and duplex configuration is. In addition, we need to |
| 2359 | * perform a hardware reset on the PHY to take it out of reset. |
| 2360 | */ |
| 2361 | if (hw->mac_type > e1000_82543) { |
| 2362 | ctrl |= E1000_CTRL_SLU; |
| 2363 | ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX); |
| 2364 | E1000_WRITE_REG(hw, CTRL, ctrl); |
| 2365 | } else { |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2366 | ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX |
| 2367 | | E1000_CTRL_SLU); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2368 | E1000_WRITE_REG(hw, CTRL, ctrl); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2369 | ret_val = e1000_phy_hw_reset(hw); |
| 2370 | if (ret_val) |
| 2371 | return ret_val; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2372 | } |
| 2373 | |
| 2374 | /* Make sure we have a valid PHY */ |
| 2375 | ret_val = e1000_detect_gig_phy(hw); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2376 | if (ret_val) { |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2377 | DEBUGOUT("Error, did not detect valid phy.\n"); |
| 2378 | return ret_val; |
| 2379 | } |
Minghuan Lian | 674bcd5 | 2015-03-19 09:43:51 -0700 | [diff] [blame] | 2380 | DEBUGOUT("Phy ID = %x\n", hw->phy_id); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2381 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2382 | /* Set PHY to class A mode (if necessary) */ |
| 2383 | ret_val = e1000_set_phy_mode(hw); |
| 2384 | if (ret_val) |
| 2385 | return ret_val; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2386 | if ((hw->mac_type == e1000_82545_rev_3) || |
| 2387 | (hw->mac_type == e1000_82546_rev_3)) { |
| 2388 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, |
| 2389 | &phy_data); |
| 2390 | phy_data |= 0x00000008; |
| 2391 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, |
| 2392 | phy_data); |
| 2393 | } |
| 2394 | |
| 2395 | if (hw->mac_type <= e1000_82543 || |
| 2396 | hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 || |
| 2397 | hw->mac_type == e1000_82541_rev_2 |
| 2398 | || hw->mac_type == e1000_82547_rev_2) |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 2399 | hw->phy_reset_disable = false; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2400 | |
| 2401 | return E1000_SUCCESS; |
| 2402 | } |
| 2403 | |
| 2404 | /***************************************************************************** |
| 2405 | * |
| 2406 | * This function sets the lplu state according to the active flag. When |
| 2407 | * activating lplu this function also disables smart speed and vise versa. |
| 2408 | * lplu will not be activated unless the device autonegotiation advertisment |
| 2409 | * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes. |
| 2410 | * hw: Struct containing variables accessed by shared code |
| 2411 | * active - true to enable lplu false to disable lplu. |
| 2412 | * |
| 2413 | * returns: - E1000_ERR_PHY if fail to read/write the PHY |
| 2414 | * E1000_SUCCESS at any other case. |
| 2415 | * |
| 2416 | ****************************************************************************/ |
| 2417 | |
| 2418 | static int32_t |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 2419 | e1000_set_d3_lplu_state(struct e1000_hw *hw, bool active) |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2420 | { |
| 2421 | uint32_t phy_ctrl = 0; |
| 2422 | int32_t ret_val; |
| 2423 | uint16_t phy_data; |
| 2424 | DEBUGFUNC(); |
| 2425 | |
| 2426 | if (hw->phy_type != e1000_phy_igp && hw->phy_type != e1000_phy_igp_2 |
| 2427 | && hw->phy_type != e1000_phy_igp_3) |
| 2428 | return E1000_SUCCESS; |
| 2429 | |
| 2430 | /* During driver activity LPLU should not be used or it will attain link |
| 2431 | * from the lowest speeds starting from 10Mbps. The capability is used |
| 2432 | * for Dx transitions and states */ |
| 2433 | if (hw->mac_type == e1000_82541_rev_2 |
| 2434 | || hw->mac_type == e1000_82547_rev_2) { |
| 2435 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, |
| 2436 | &phy_data); |
| 2437 | if (ret_val) |
| 2438 | return ret_val; |
| 2439 | } else if (hw->mac_type == e1000_ich8lan) { |
| 2440 | /* MAC writes into PHY register based on the state transition |
| 2441 | * and start auto-negotiation. SW driver can overwrite the |
| 2442 | * settings in CSR PHY power control E1000_PHY_CTRL register. */ |
| 2443 | phy_ctrl = E1000_READ_REG(hw, PHY_CTRL); |
| 2444 | } else { |
| 2445 | ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, |
| 2446 | &phy_data); |
| 2447 | if (ret_val) |
| 2448 | return ret_val; |
| 2449 | } |
| 2450 | |
| 2451 | if (!active) { |
| 2452 | if (hw->mac_type == e1000_82541_rev_2 || |
| 2453 | hw->mac_type == e1000_82547_rev_2) { |
| 2454 | phy_data &= ~IGP01E1000_GMII_FLEX_SPD; |
| 2455 | ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, |
| 2456 | phy_data); |
| 2457 | if (ret_val) |
| 2458 | return ret_val; |
| 2459 | } else { |
| 2460 | if (hw->mac_type == e1000_ich8lan) { |
| 2461 | phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU; |
| 2462 | E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl); |
| 2463 | } else { |
| 2464 | phy_data &= ~IGP02E1000_PM_D3_LPLU; |
| 2465 | ret_val = e1000_write_phy_reg(hw, |
| 2466 | IGP02E1000_PHY_POWER_MGMT, phy_data); |
| 2467 | if (ret_val) |
| 2468 | return ret_val; |
| 2469 | } |
| 2470 | } |
| 2471 | |
| 2472 | /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during |
| 2473 | * Dx states where the power conservation is most important. During |
| 2474 | * driver activity we should enable SmartSpeed, so performance is |
| 2475 | * maintained. */ |
| 2476 | if (hw->smart_speed == e1000_smart_speed_on) { |
| 2477 | ret_val = e1000_read_phy_reg(hw, |
| 2478 | IGP01E1000_PHY_PORT_CONFIG, &phy_data); |
| 2479 | if (ret_val) |
| 2480 | return ret_val; |
| 2481 | |
| 2482 | phy_data |= IGP01E1000_PSCFR_SMART_SPEED; |
| 2483 | ret_val = e1000_write_phy_reg(hw, |
| 2484 | IGP01E1000_PHY_PORT_CONFIG, phy_data); |
| 2485 | if (ret_val) |
| 2486 | return ret_val; |
| 2487 | } else if (hw->smart_speed == e1000_smart_speed_off) { |
| 2488 | ret_val = e1000_read_phy_reg(hw, |
| 2489 | IGP01E1000_PHY_PORT_CONFIG, &phy_data); |
| 2490 | if (ret_val) |
| 2491 | return ret_val; |
| 2492 | |
| 2493 | phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED; |
| 2494 | ret_val = e1000_write_phy_reg(hw, |
| 2495 | IGP01E1000_PHY_PORT_CONFIG, phy_data); |
| 2496 | if (ret_val) |
| 2497 | return ret_val; |
| 2498 | } |
| 2499 | |
| 2500 | } else if ((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT) |
| 2501 | || (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL) || |
| 2502 | (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_100_ALL)) { |
| 2503 | |
| 2504 | if (hw->mac_type == e1000_82541_rev_2 || |
| 2505 | hw->mac_type == e1000_82547_rev_2) { |
| 2506 | phy_data |= IGP01E1000_GMII_FLEX_SPD; |
| 2507 | ret_val = e1000_write_phy_reg(hw, |
| 2508 | IGP01E1000_GMII_FIFO, phy_data); |
| 2509 | if (ret_val) |
| 2510 | return ret_val; |
| 2511 | } else { |
| 2512 | if (hw->mac_type == e1000_ich8lan) { |
| 2513 | phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU; |
| 2514 | E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl); |
| 2515 | } else { |
| 2516 | phy_data |= IGP02E1000_PM_D3_LPLU; |
| 2517 | ret_val = e1000_write_phy_reg(hw, |
| 2518 | IGP02E1000_PHY_POWER_MGMT, phy_data); |
| 2519 | if (ret_val) |
| 2520 | return ret_val; |
| 2521 | } |
| 2522 | } |
| 2523 | |
| 2524 | /* When LPLU is enabled we should disable SmartSpeed */ |
| 2525 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, |
| 2526 | &phy_data); |
| 2527 | if (ret_val) |
| 2528 | return ret_val; |
| 2529 | |
| 2530 | phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED; |
| 2531 | ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, |
| 2532 | phy_data); |
| 2533 | if (ret_val) |
| 2534 | return ret_val; |
| 2535 | } |
| 2536 | return E1000_SUCCESS; |
| 2537 | } |
| 2538 | |
| 2539 | /***************************************************************************** |
| 2540 | * |
| 2541 | * This function sets the lplu d0 state according to the active flag. When |
| 2542 | * activating lplu this function also disables smart speed and vise versa. |
| 2543 | * lplu will not be activated unless the device autonegotiation advertisment |
| 2544 | * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes. |
| 2545 | * hw: Struct containing variables accessed by shared code |
| 2546 | * active - true to enable lplu false to disable lplu. |
| 2547 | * |
| 2548 | * returns: - E1000_ERR_PHY if fail to read/write the PHY |
| 2549 | * E1000_SUCCESS at any other case. |
| 2550 | * |
| 2551 | ****************************************************************************/ |
| 2552 | |
| 2553 | static int32_t |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 2554 | e1000_set_d0_lplu_state(struct e1000_hw *hw, bool active) |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2555 | { |
| 2556 | uint32_t phy_ctrl = 0; |
| 2557 | int32_t ret_val; |
| 2558 | uint16_t phy_data; |
| 2559 | DEBUGFUNC(); |
| 2560 | |
| 2561 | if (hw->mac_type <= e1000_82547_rev_2) |
| 2562 | return E1000_SUCCESS; |
| 2563 | |
| 2564 | if (hw->mac_type == e1000_ich8lan) { |
| 2565 | phy_ctrl = E1000_READ_REG(hw, PHY_CTRL); |
Marek Vasut | 74a13c2 | 2014-08-08 07:41:39 -0700 | [diff] [blame] | 2566 | } else if (hw->mac_type == e1000_igb) { |
| 2567 | phy_ctrl = E1000_READ_REG(hw, I210_PHY_CTRL); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2568 | } else { |
| 2569 | ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, |
| 2570 | &phy_data); |
| 2571 | if (ret_val) |
| 2572 | return ret_val; |
| 2573 | } |
| 2574 | |
| 2575 | if (!active) { |
| 2576 | if (hw->mac_type == e1000_ich8lan) { |
| 2577 | phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU; |
| 2578 | E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl); |
Marek Vasut | 74a13c2 | 2014-08-08 07:41:39 -0700 | [diff] [blame] | 2579 | } else if (hw->mac_type == e1000_igb) { |
| 2580 | phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU; |
| 2581 | E1000_WRITE_REG(hw, I210_PHY_CTRL, phy_ctrl); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2582 | } else { |
| 2583 | phy_data &= ~IGP02E1000_PM_D0_LPLU; |
| 2584 | ret_val = e1000_write_phy_reg(hw, |
| 2585 | IGP02E1000_PHY_POWER_MGMT, phy_data); |
| 2586 | if (ret_val) |
| 2587 | return ret_val; |
| 2588 | } |
| 2589 | |
Marek Vasut | 74a13c2 | 2014-08-08 07:41:39 -0700 | [diff] [blame] | 2590 | if (hw->mac_type == e1000_igb) |
| 2591 | return E1000_SUCCESS; |
| 2592 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2593 | /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during |
| 2594 | * Dx states where the power conservation is most important. During |
| 2595 | * driver activity we should enable SmartSpeed, so performance is |
| 2596 | * maintained. */ |
| 2597 | if (hw->smart_speed == e1000_smart_speed_on) { |
| 2598 | ret_val = e1000_read_phy_reg(hw, |
| 2599 | IGP01E1000_PHY_PORT_CONFIG, &phy_data); |
| 2600 | if (ret_val) |
| 2601 | return ret_val; |
| 2602 | |
| 2603 | phy_data |= IGP01E1000_PSCFR_SMART_SPEED; |
| 2604 | ret_val = e1000_write_phy_reg(hw, |
| 2605 | IGP01E1000_PHY_PORT_CONFIG, phy_data); |
| 2606 | if (ret_val) |
| 2607 | return ret_val; |
| 2608 | } else if (hw->smart_speed == e1000_smart_speed_off) { |
| 2609 | ret_val = e1000_read_phy_reg(hw, |
| 2610 | IGP01E1000_PHY_PORT_CONFIG, &phy_data); |
| 2611 | if (ret_val) |
| 2612 | return ret_val; |
| 2613 | |
| 2614 | phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED; |
| 2615 | ret_val = e1000_write_phy_reg(hw, |
| 2616 | IGP01E1000_PHY_PORT_CONFIG, phy_data); |
| 2617 | if (ret_val) |
| 2618 | return ret_val; |
| 2619 | } |
| 2620 | |
| 2621 | |
| 2622 | } else { |
| 2623 | |
| 2624 | if (hw->mac_type == e1000_ich8lan) { |
| 2625 | phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU; |
| 2626 | E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl); |
Marek Vasut | 74a13c2 | 2014-08-08 07:41:39 -0700 | [diff] [blame] | 2627 | } else if (hw->mac_type == e1000_igb) { |
| 2628 | phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU; |
| 2629 | E1000_WRITE_REG(hw, I210_PHY_CTRL, phy_ctrl); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2630 | } else { |
| 2631 | phy_data |= IGP02E1000_PM_D0_LPLU; |
| 2632 | ret_val = e1000_write_phy_reg(hw, |
| 2633 | IGP02E1000_PHY_POWER_MGMT, phy_data); |
| 2634 | if (ret_val) |
| 2635 | return ret_val; |
| 2636 | } |
| 2637 | |
Marek Vasut | 74a13c2 | 2014-08-08 07:41:39 -0700 | [diff] [blame] | 2638 | if (hw->mac_type == e1000_igb) |
| 2639 | return E1000_SUCCESS; |
| 2640 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2641 | /* When LPLU is enabled we should disable SmartSpeed */ |
| 2642 | ret_val = e1000_read_phy_reg(hw, |
| 2643 | IGP01E1000_PHY_PORT_CONFIG, &phy_data); |
| 2644 | if (ret_val) |
| 2645 | return ret_val; |
| 2646 | |
| 2647 | phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED; |
| 2648 | ret_val = e1000_write_phy_reg(hw, |
| 2649 | IGP01E1000_PHY_PORT_CONFIG, phy_data); |
| 2650 | if (ret_val) |
| 2651 | return ret_val; |
| 2652 | |
| 2653 | } |
| 2654 | return E1000_SUCCESS; |
| 2655 | } |
| 2656 | |
| 2657 | /******************************************************************** |
| 2658 | * Copper link setup for e1000_phy_igp series. |
| 2659 | * |
| 2660 | * hw - Struct containing variables accessed by shared code |
| 2661 | *********************************************************************/ |
| 2662 | static int32_t |
| 2663 | e1000_copper_link_igp_setup(struct e1000_hw *hw) |
| 2664 | { |
| 2665 | uint32_t led_ctrl; |
| 2666 | int32_t ret_val; |
| 2667 | uint16_t phy_data; |
| 2668 | |
Timur Tabi | edc45b5 | 2009-08-17 15:55:38 -0500 | [diff] [blame] | 2669 | DEBUGFUNC(); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2670 | |
| 2671 | if (hw->phy_reset_disable) |
| 2672 | return E1000_SUCCESS; |
| 2673 | |
| 2674 | ret_val = e1000_phy_reset(hw); |
| 2675 | if (ret_val) { |
| 2676 | DEBUGOUT("Error Resetting the PHY\n"); |
| 2677 | return ret_val; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 2678 | } |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2679 | |
| 2680 | /* Wait 15ms for MAC to configure PHY from eeprom settings */ |
| 2681 | mdelay(15); |
| 2682 | if (hw->mac_type != e1000_ich8lan) { |
| 2683 | /* Configure activity LED after PHY reset */ |
| 2684 | led_ctrl = E1000_READ_REG(hw, LEDCTL); |
| 2685 | led_ctrl &= IGP_ACTIVITY_LED_MASK; |
| 2686 | led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE); |
| 2687 | E1000_WRITE_REG(hw, LEDCTL, led_ctrl); |
| 2688 | } |
| 2689 | |
| 2690 | /* The NVM settings will configure LPLU in D3 for IGP2 and IGP3 PHYs */ |
| 2691 | if (hw->phy_type == e1000_phy_igp) { |
| 2692 | /* disable lplu d3 during driver init */ |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 2693 | ret_val = e1000_set_d3_lplu_state(hw, false); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2694 | if (ret_val) { |
| 2695 | DEBUGOUT("Error Disabling LPLU D3\n"); |
| 2696 | return ret_val; |
| 2697 | } |
| 2698 | } |
| 2699 | |
| 2700 | /* disable lplu d0 during driver init */ |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 2701 | ret_val = e1000_set_d0_lplu_state(hw, false); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2702 | if (ret_val) { |
| 2703 | DEBUGOUT("Error Disabling LPLU D0\n"); |
| 2704 | return ret_val; |
| 2705 | } |
| 2706 | /* Configure mdi-mdix settings */ |
| 2707 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data); |
| 2708 | if (ret_val) |
| 2709 | return ret_val; |
| 2710 | |
| 2711 | if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) { |
| 2712 | hw->dsp_config_state = e1000_dsp_config_disabled; |
| 2713 | /* Force MDI for earlier revs of the IGP PHY */ |
| 2714 | phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX |
| 2715 | | IGP01E1000_PSCR_FORCE_MDI_MDIX); |
| 2716 | hw->mdix = 1; |
| 2717 | |
| 2718 | } else { |
| 2719 | hw->dsp_config_state = e1000_dsp_config_enabled; |
| 2720 | phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX; |
| 2721 | |
| 2722 | switch (hw->mdix) { |
| 2723 | case 1: |
| 2724 | phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX; |
| 2725 | break; |
| 2726 | case 2: |
| 2727 | phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX; |
| 2728 | break; |
| 2729 | case 0: |
| 2730 | default: |
| 2731 | phy_data |= IGP01E1000_PSCR_AUTO_MDIX; |
| 2732 | break; |
| 2733 | } |
| 2734 | } |
| 2735 | ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data); |
| 2736 | if (ret_val) |
| 2737 | return ret_val; |
| 2738 | |
| 2739 | /* set auto-master slave resolution settings */ |
| 2740 | if (hw->autoneg) { |
| 2741 | e1000_ms_type phy_ms_setting = hw->master_slave; |
| 2742 | |
| 2743 | if (hw->ffe_config_state == e1000_ffe_config_active) |
| 2744 | hw->ffe_config_state = e1000_ffe_config_enabled; |
| 2745 | |
| 2746 | if (hw->dsp_config_state == e1000_dsp_config_activated) |
| 2747 | hw->dsp_config_state = e1000_dsp_config_enabled; |
| 2748 | |
| 2749 | /* when autonegotiation advertisment is only 1000Mbps then we |
| 2750 | * should disable SmartSpeed and enable Auto MasterSlave |
| 2751 | * resolution as hardware default. */ |
| 2752 | if (hw->autoneg_advertised == ADVERTISE_1000_FULL) { |
| 2753 | /* Disable SmartSpeed */ |
| 2754 | ret_val = e1000_read_phy_reg(hw, |
| 2755 | IGP01E1000_PHY_PORT_CONFIG, &phy_data); |
| 2756 | if (ret_val) |
| 2757 | return ret_val; |
| 2758 | phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED; |
| 2759 | ret_val = e1000_write_phy_reg(hw, |
| 2760 | IGP01E1000_PHY_PORT_CONFIG, phy_data); |
| 2761 | if (ret_val) |
| 2762 | return ret_val; |
| 2763 | /* Set auto Master/Slave resolution process */ |
| 2764 | ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, |
| 2765 | &phy_data); |
| 2766 | if (ret_val) |
| 2767 | return ret_val; |
| 2768 | phy_data &= ~CR_1000T_MS_ENABLE; |
| 2769 | ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, |
| 2770 | phy_data); |
| 2771 | if (ret_val) |
| 2772 | return ret_val; |
| 2773 | } |
| 2774 | |
| 2775 | ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data); |
| 2776 | if (ret_val) |
| 2777 | return ret_val; |
| 2778 | |
| 2779 | /* load defaults for future use */ |
| 2780 | hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ? |
| 2781 | ((phy_data & CR_1000T_MS_VALUE) ? |
| 2782 | e1000_ms_force_master : |
| 2783 | e1000_ms_force_slave) : |
| 2784 | e1000_ms_auto; |
| 2785 | |
| 2786 | switch (phy_ms_setting) { |
| 2787 | case e1000_ms_force_master: |
| 2788 | phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE); |
| 2789 | break; |
| 2790 | case e1000_ms_force_slave: |
| 2791 | phy_data |= CR_1000T_MS_ENABLE; |
| 2792 | phy_data &= ~(CR_1000T_MS_VALUE); |
| 2793 | break; |
| 2794 | case e1000_ms_auto: |
| 2795 | phy_data &= ~CR_1000T_MS_ENABLE; |
| 2796 | default: |
| 2797 | break; |
| 2798 | } |
| 2799 | ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data); |
| 2800 | if (ret_val) |
| 2801 | return ret_val; |
| 2802 | } |
| 2803 | |
| 2804 | return E1000_SUCCESS; |
| 2805 | } |
| 2806 | |
| 2807 | /***************************************************************************** |
| 2808 | * This function checks the mode of the firmware. |
| 2809 | * |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 2810 | * returns - true when the mode is IAMT or false. |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2811 | ****************************************************************************/ |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 2812 | bool |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2813 | e1000_check_mng_mode(struct e1000_hw *hw) |
| 2814 | { |
| 2815 | uint32_t fwsm; |
| 2816 | DEBUGFUNC(); |
| 2817 | |
| 2818 | fwsm = E1000_READ_REG(hw, FWSM); |
| 2819 | |
| 2820 | if (hw->mac_type == e1000_ich8lan) { |
| 2821 | if ((fwsm & E1000_FWSM_MODE_MASK) == |
| 2822 | (E1000_MNG_ICH_IAMT_MODE << E1000_FWSM_MODE_SHIFT)) |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 2823 | return true; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2824 | } else if ((fwsm & E1000_FWSM_MODE_MASK) == |
| 2825 | (E1000_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT)) |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 2826 | return true; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2827 | |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 2828 | return false; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2829 | } |
| 2830 | |
| 2831 | static int32_t |
| 2832 | e1000_write_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t data) |
| 2833 | { |
Kyle Moffett | 7376f8d | 2010-09-13 05:52:22 +0000 | [diff] [blame] | 2834 | uint16_t swfw = E1000_SWFW_PHY0_SM; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2835 | uint32_t reg_val; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2836 | DEBUGFUNC(); |
| 2837 | |
Kyle Moffett | 7376f8d | 2010-09-13 05:52:22 +0000 | [diff] [blame] | 2838 | if (e1000_is_second_port(hw)) |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2839 | swfw = E1000_SWFW_PHY1_SM; |
Kyle Moffett | 7376f8d | 2010-09-13 05:52:22 +0000 | [diff] [blame] | 2840 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2841 | if (e1000_swfw_sync_acquire(hw, swfw)) |
| 2842 | return -E1000_ERR_SWFW_SYNC; |
| 2843 | |
| 2844 | reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) |
| 2845 | & E1000_KUMCTRLSTA_OFFSET) | data; |
| 2846 | E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val); |
| 2847 | udelay(2); |
| 2848 | |
| 2849 | return E1000_SUCCESS; |
| 2850 | } |
| 2851 | |
| 2852 | static int32_t |
| 2853 | e1000_read_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t *data) |
| 2854 | { |
Kyle Moffett | 7376f8d | 2010-09-13 05:52:22 +0000 | [diff] [blame] | 2855 | uint16_t swfw = E1000_SWFW_PHY0_SM; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2856 | uint32_t reg_val; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2857 | DEBUGFUNC(); |
| 2858 | |
Kyle Moffett | 7376f8d | 2010-09-13 05:52:22 +0000 | [diff] [blame] | 2859 | if (e1000_is_second_port(hw)) |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2860 | swfw = E1000_SWFW_PHY1_SM; |
Kyle Moffett | 7376f8d | 2010-09-13 05:52:22 +0000 | [diff] [blame] | 2861 | |
Marek Vasut | 74a13c2 | 2014-08-08 07:41:39 -0700 | [diff] [blame] | 2862 | if (e1000_swfw_sync_acquire(hw, swfw)) { |
| 2863 | debug("%s[%i]\n", __func__, __LINE__); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2864 | return -E1000_ERR_SWFW_SYNC; |
Marek Vasut | 74a13c2 | 2014-08-08 07:41:39 -0700 | [diff] [blame] | 2865 | } |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2866 | |
| 2867 | /* Write register address */ |
| 2868 | reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) & |
| 2869 | E1000_KUMCTRLSTA_OFFSET) | E1000_KUMCTRLSTA_REN; |
| 2870 | E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val); |
| 2871 | udelay(2); |
| 2872 | |
| 2873 | /* Read the data returned */ |
| 2874 | reg_val = E1000_READ_REG(hw, KUMCTRLSTA); |
| 2875 | *data = (uint16_t)reg_val; |
| 2876 | |
| 2877 | return E1000_SUCCESS; |
| 2878 | } |
| 2879 | |
| 2880 | /******************************************************************** |
| 2881 | * Copper link setup for e1000_phy_gg82563 series. |
| 2882 | * |
| 2883 | * hw - Struct containing variables accessed by shared code |
| 2884 | *********************************************************************/ |
| 2885 | static int32_t |
| 2886 | e1000_copper_link_ggp_setup(struct e1000_hw *hw) |
| 2887 | { |
| 2888 | int32_t ret_val; |
| 2889 | uint16_t phy_data; |
| 2890 | uint32_t reg_data; |
| 2891 | |
| 2892 | DEBUGFUNC(); |
| 2893 | |
| 2894 | if (!hw->phy_reset_disable) { |
| 2895 | /* Enable CRS on TX for half-duplex operation. */ |
| 2896 | ret_val = e1000_read_phy_reg(hw, |
| 2897 | GG82563_PHY_MAC_SPEC_CTRL, &phy_data); |
| 2898 | if (ret_val) |
| 2899 | return ret_val; |
| 2900 | |
| 2901 | phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX; |
| 2902 | /* Use 25MHz for both link down and 1000BASE-T for Tx clock */ |
| 2903 | phy_data |= GG82563_MSCR_TX_CLK_1000MBPS_25MHZ; |
| 2904 | |
| 2905 | ret_val = e1000_write_phy_reg(hw, |
| 2906 | GG82563_PHY_MAC_SPEC_CTRL, phy_data); |
| 2907 | if (ret_val) |
| 2908 | return ret_val; |
| 2909 | |
| 2910 | /* Options: |
| 2911 | * MDI/MDI-X = 0 (default) |
| 2912 | * 0 - Auto for all speeds |
| 2913 | * 1 - MDI mode |
| 2914 | * 2 - MDI-X mode |
| 2915 | * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes) |
| 2916 | */ |
| 2917 | ret_val = e1000_read_phy_reg(hw, |
| 2918 | GG82563_PHY_SPEC_CTRL, &phy_data); |
| 2919 | if (ret_val) |
| 2920 | return ret_val; |
| 2921 | |
| 2922 | phy_data &= ~GG82563_PSCR_CROSSOVER_MODE_MASK; |
| 2923 | |
| 2924 | switch (hw->mdix) { |
| 2925 | case 1: |
| 2926 | phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDI; |
| 2927 | break; |
| 2928 | case 2: |
| 2929 | phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDIX; |
| 2930 | break; |
| 2931 | case 0: |
| 2932 | default: |
| 2933 | phy_data |= GG82563_PSCR_CROSSOVER_MODE_AUTO; |
| 2934 | break; |
| 2935 | } |
| 2936 | |
| 2937 | /* Options: |
| 2938 | * disable_polarity_correction = 0 (default) |
| 2939 | * Automatic Correction for Reversed Cable Polarity |
| 2940 | * 0 - Disabled |
| 2941 | * 1 - Enabled |
| 2942 | */ |
| 2943 | phy_data &= ~GG82563_PSCR_POLARITY_REVERSAL_DISABLE; |
| 2944 | ret_val = e1000_write_phy_reg(hw, |
| 2945 | GG82563_PHY_SPEC_CTRL, phy_data); |
| 2946 | |
| 2947 | if (ret_val) |
| 2948 | return ret_val; |
| 2949 | |
| 2950 | /* SW Reset the PHY so all changes take effect */ |
| 2951 | ret_val = e1000_phy_reset(hw); |
| 2952 | if (ret_val) { |
| 2953 | DEBUGOUT("Error Resetting the PHY\n"); |
| 2954 | return ret_val; |
| 2955 | } |
| 2956 | } /* phy_reset_disable */ |
| 2957 | |
| 2958 | if (hw->mac_type == e1000_80003es2lan) { |
| 2959 | /* Bypass RX and TX FIFO's */ |
| 2960 | ret_val = e1000_write_kmrn_reg(hw, |
| 2961 | E1000_KUMCTRLSTA_OFFSET_FIFO_CTRL, |
| 2962 | E1000_KUMCTRLSTA_FIFO_CTRL_RX_BYPASS |
| 2963 | | E1000_KUMCTRLSTA_FIFO_CTRL_TX_BYPASS); |
| 2964 | if (ret_val) |
| 2965 | return ret_val; |
| 2966 | |
| 2967 | ret_val = e1000_read_phy_reg(hw, |
| 2968 | GG82563_PHY_SPEC_CTRL_2, &phy_data); |
| 2969 | if (ret_val) |
| 2970 | return ret_val; |
| 2971 | |
| 2972 | phy_data &= ~GG82563_PSCR2_REVERSE_AUTO_NEG; |
| 2973 | ret_val = e1000_write_phy_reg(hw, |
| 2974 | GG82563_PHY_SPEC_CTRL_2, phy_data); |
| 2975 | |
| 2976 | if (ret_val) |
| 2977 | return ret_val; |
| 2978 | |
| 2979 | reg_data = E1000_READ_REG(hw, CTRL_EXT); |
| 2980 | reg_data &= ~(E1000_CTRL_EXT_LINK_MODE_MASK); |
| 2981 | E1000_WRITE_REG(hw, CTRL_EXT, reg_data); |
| 2982 | |
| 2983 | ret_val = e1000_read_phy_reg(hw, |
| 2984 | GG82563_PHY_PWR_MGMT_CTRL, &phy_data); |
| 2985 | if (ret_val) |
| 2986 | return ret_val; |
| 2987 | |
| 2988 | /* Do not init these registers when the HW is in IAMT mode, since the |
| 2989 | * firmware will have already initialized them. We only initialize |
| 2990 | * them if the HW is not in IAMT mode. |
| 2991 | */ |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 2992 | if (e1000_check_mng_mode(hw) == false) { |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 2993 | /* Enable Electrical Idle on the PHY */ |
| 2994 | phy_data |= GG82563_PMCR_ENABLE_ELECTRICAL_IDLE; |
| 2995 | ret_val = e1000_write_phy_reg(hw, |
| 2996 | GG82563_PHY_PWR_MGMT_CTRL, phy_data); |
| 2997 | if (ret_val) |
| 2998 | return ret_val; |
| 2999 | |
| 3000 | ret_val = e1000_read_phy_reg(hw, |
| 3001 | GG82563_PHY_KMRN_MODE_CTRL, &phy_data); |
| 3002 | if (ret_val) |
| 3003 | return ret_val; |
| 3004 | |
| 3005 | phy_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER; |
| 3006 | ret_val = e1000_write_phy_reg(hw, |
| 3007 | GG82563_PHY_KMRN_MODE_CTRL, phy_data); |
| 3008 | |
| 3009 | if (ret_val) |
| 3010 | return ret_val; |
| 3011 | } |
| 3012 | |
| 3013 | /* Workaround: Disable padding in Kumeran interface in the MAC |
| 3014 | * and in the PHY to avoid CRC errors. |
| 3015 | */ |
| 3016 | ret_val = e1000_read_phy_reg(hw, |
| 3017 | GG82563_PHY_INBAND_CTRL, &phy_data); |
| 3018 | if (ret_val) |
| 3019 | return ret_val; |
| 3020 | phy_data |= GG82563_ICR_DIS_PADDING; |
| 3021 | ret_val = e1000_write_phy_reg(hw, |
| 3022 | GG82563_PHY_INBAND_CTRL, phy_data); |
| 3023 | if (ret_val) |
| 3024 | return ret_val; |
| 3025 | } |
| 3026 | return E1000_SUCCESS; |
| 3027 | } |
| 3028 | |
| 3029 | /******************************************************************** |
| 3030 | * Copper link setup for e1000_phy_m88 series. |
| 3031 | * |
| 3032 | * hw - Struct containing variables accessed by shared code |
| 3033 | *********************************************************************/ |
| 3034 | static int32_t |
| 3035 | e1000_copper_link_mgp_setup(struct e1000_hw *hw) |
| 3036 | { |
| 3037 | int32_t ret_val; |
| 3038 | uint16_t phy_data; |
| 3039 | |
| 3040 | DEBUGFUNC(); |
| 3041 | |
| 3042 | if (hw->phy_reset_disable) |
| 3043 | return E1000_SUCCESS; |
| 3044 | |
| 3045 | /* Enable CRS on TX. This must be set for half-duplex operation. */ |
| 3046 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data); |
| 3047 | if (ret_val) |
| 3048 | return ret_val; |
| 3049 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3050 | phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX; |
| 3051 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3052 | /* Options: |
| 3053 | * MDI/MDI-X = 0 (default) |
| 3054 | * 0 - Auto for all speeds |
| 3055 | * 1 - MDI mode |
| 3056 | * 2 - MDI-X mode |
| 3057 | * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes) |
| 3058 | */ |
| 3059 | phy_data &= ~M88E1000_PSCR_AUTO_X_MODE; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 3060 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3061 | switch (hw->mdix) { |
| 3062 | case 1: |
| 3063 | phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE; |
| 3064 | break; |
| 3065 | case 2: |
| 3066 | phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE; |
| 3067 | break; |
| 3068 | case 3: |
| 3069 | phy_data |= M88E1000_PSCR_AUTO_X_1000T; |
| 3070 | break; |
| 3071 | case 0: |
| 3072 | default: |
| 3073 | phy_data |= M88E1000_PSCR_AUTO_X_MODE; |
| 3074 | break; |
| 3075 | } |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3076 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3077 | /* Options: |
| 3078 | * disable_polarity_correction = 0 (default) |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 3079 | * Automatic Correction for Reversed Cable Polarity |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3080 | * 0 - Disabled |
| 3081 | * 1 - Enabled |
| 3082 | */ |
| 3083 | phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 3084 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data); |
| 3085 | if (ret_val) |
| 3086 | return ret_val; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3087 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 3088 | if (hw->phy_revision < M88E1011_I_REV_4) { |
| 3089 | /* Force TX_CLK in the Extended PHY Specific Control Register |
| 3090 | * to 25MHz clock. |
| 3091 | */ |
| 3092 | ret_val = e1000_read_phy_reg(hw, |
| 3093 | M88E1000_EXT_PHY_SPEC_CTRL, &phy_data); |
| 3094 | if (ret_val) |
| 3095 | return ret_val; |
| 3096 | |
| 3097 | phy_data |= M88E1000_EPSCR_TX_CLK_25; |
| 3098 | |
| 3099 | if ((hw->phy_revision == E1000_REVISION_2) && |
| 3100 | (hw->phy_id == M88E1111_I_PHY_ID)) { |
| 3101 | /* Vidalia Phy, set the downshift counter to 5x */ |
| 3102 | phy_data &= ~(M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK); |
| 3103 | phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X; |
| 3104 | ret_val = e1000_write_phy_reg(hw, |
| 3105 | M88E1000_EXT_PHY_SPEC_CTRL, phy_data); |
| 3106 | if (ret_val) |
| 3107 | return ret_val; |
| 3108 | } else { |
| 3109 | /* Configure Master and Slave downshift values */ |
| 3110 | phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
| 3111 | | M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK); |
| 3112 | phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
| 3113 | | M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X); |
| 3114 | ret_val = e1000_write_phy_reg(hw, |
| 3115 | M88E1000_EXT_PHY_SPEC_CTRL, phy_data); |
| 3116 | if (ret_val) |
| 3117 | return ret_val; |
| 3118 | } |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3119 | } |
| 3120 | |
| 3121 | /* SW Reset the PHY so all changes take effect */ |
| 3122 | ret_val = e1000_phy_reset(hw); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 3123 | if (ret_val) { |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3124 | DEBUGOUT("Error Resetting the PHY\n"); |
| 3125 | return ret_val; |
| 3126 | } |
| 3127 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 3128 | return E1000_SUCCESS; |
| 3129 | } |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3130 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 3131 | /******************************************************************** |
| 3132 | * Setup auto-negotiation and flow control advertisements, |
| 3133 | * and then perform auto-negotiation. |
| 3134 | * |
| 3135 | * hw - Struct containing variables accessed by shared code |
| 3136 | *********************************************************************/ |
| 3137 | static int32_t |
| 3138 | e1000_copper_link_autoneg(struct e1000_hw *hw) |
| 3139 | { |
| 3140 | int32_t ret_val; |
| 3141 | uint16_t phy_data; |
| 3142 | |
| 3143 | DEBUGFUNC(); |
| 3144 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3145 | /* Perform some bounds checking on the hw->autoneg_advertised |
| 3146 | * parameter. If this variable is zero, then set it to the default. |
| 3147 | */ |
| 3148 | hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT; |
| 3149 | |
| 3150 | /* If autoneg_advertised is zero, we assume it was not defaulted |
| 3151 | * by the calling code so we set to advertise full capability. |
| 3152 | */ |
| 3153 | if (hw->autoneg_advertised == 0) |
| 3154 | hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT; |
| 3155 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 3156 | /* IFE phy only supports 10/100 */ |
| 3157 | if (hw->phy_type == e1000_phy_ife) |
| 3158 | hw->autoneg_advertised &= AUTONEG_ADVERTISE_10_100_ALL; |
| 3159 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3160 | DEBUGOUT("Reconfiguring auto-neg advertisement params\n"); |
| 3161 | ret_val = e1000_phy_setup_autoneg(hw); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 3162 | if (ret_val) { |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3163 | DEBUGOUT("Error Setting up Auto-Negotiation\n"); |
| 3164 | return ret_val; |
| 3165 | } |
| 3166 | DEBUGOUT("Restarting Auto-Neg\n"); |
| 3167 | |
| 3168 | /* Restart auto-negotiation by setting the Auto Neg Enable bit and |
| 3169 | * the Auto Neg Restart bit in the PHY control register. |
| 3170 | */ |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 3171 | ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data); |
| 3172 | if (ret_val) |
| 3173 | return ret_val; |
| 3174 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3175 | phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 3176 | ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data); |
| 3177 | if (ret_val) |
| 3178 | return ret_val; |
| 3179 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3180 | /* Does the user want to wait for Auto-Neg to complete here, or |
| 3181 | * check at a later time (for example, callback routine). |
| 3182 | */ |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 3183 | /* If we do not wait for autonegtation to complete I |
| 3184 | * do not see a valid link status. |
| 3185 | * wait_autoneg_complete = 1 . |
| 3186 | */ |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3187 | if (hw->wait_autoneg_complete) { |
| 3188 | ret_val = e1000_wait_autoneg(hw); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 3189 | if (ret_val) { |
| 3190 | DEBUGOUT("Error while waiting for autoneg" |
| 3191 | "to complete\n"); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3192 | return ret_val; |
| 3193 | } |
| 3194 | } |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 3195 | |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 3196 | hw->get_link_status = true; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 3197 | |
| 3198 | return E1000_SUCCESS; |
| 3199 | } |
| 3200 | |
| 3201 | /****************************************************************************** |
| 3202 | * Config the MAC and the PHY after link is up. |
| 3203 | * 1) Set up the MAC to the current PHY speed/duplex |
| 3204 | * if we are on 82543. If we |
| 3205 | * are on newer silicon, we only need to configure |
| 3206 | * collision distance in the Transmit Control Register. |
| 3207 | * 2) Set up flow control on the MAC to that established with |
| 3208 | * the link partner. |
| 3209 | * 3) Config DSP to improve Gigabit link quality for some PHY revisions. |
| 3210 | * |
| 3211 | * hw - Struct containing variables accessed by shared code |
| 3212 | ******************************************************************************/ |
| 3213 | static int32_t |
| 3214 | e1000_copper_link_postconfig(struct e1000_hw *hw) |
| 3215 | { |
| 3216 | int32_t ret_val; |
| 3217 | DEBUGFUNC(); |
| 3218 | |
| 3219 | if (hw->mac_type >= e1000_82544) { |
| 3220 | e1000_config_collision_dist(hw); |
| 3221 | } else { |
| 3222 | ret_val = e1000_config_mac_to_phy(hw); |
| 3223 | if (ret_val) { |
| 3224 | DEBUGOUT("Error configuring MAC to PHY settings\n"); |
| 3225 | return ret_val; |
| 3226 | } |
| 3227 | } |
| 3228 | ret_val = e1000_config_fc_after_link_up(hw); |
| 3229 | if (ret_val) { |
| 3230 | DEBUGOUT("Error Configuring Flow Control\n"); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3231 | return ret_val; |
| 3232 | } |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 3233 | return E1000_SUCCESS; |
| 3234 | } |
| 3235 | |
| 3236 | /****************************************************************************** |
| 3237 | * Detects which PHY is present and setup the speed and duplex |
| 3238 | * |
| 3239 | * hw - Struct containing variables accessed by shared code |
| 3240 | ******************************************************************************/ |
| 3241 | static int |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 3242 | e1000_setup_copper_link(struct e1000_hw *hw) |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 3243 | { |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 3244 | int32_t ret_val; |
| 3245 | uint16_t i; |
| 3246 | uint16_t phy_data; |
| 3247 | uint16_t reg_data; |
| 3248 | |
| 3249 | DEBUGFUNC(); |
| 3250 | |
| 3251 | switch (hw->mac_type) { |
| 3252 | case e1000_80003es2lan: |
| 3253 | case e1000_ich8lan: |
| 3254 | /* Set the mac to wait the maximum time between each |
| 3255 | * iteration and increase the max iterations when |
| 3256 | * polling the phy; this fixes erroneous timeouts at 10Mbps. */ |
| 3257 | ret_val = e1000_write_kmrn_reg(hw, |
| 3258 | GG82563_REG(0x34, 4), 0xFFFF); |
| 3259 | if (ret_val) |
| 3260 | return ret_val; |
| 3261 | ret_val = e1000_read_kmrn_reg(hw, |
| 3262 | GG82563_REG(0x34, 9), ®_data); |
| 3263 | if (ret_val) |
| 3264 | return ret_val; |
| 3265 | reg_data |= 0x3F; |
| 3266 | ret_val = e1000_write_kmrn_reg(hw, |
| 3267 | GG82563_REG(0x34, 9), reg_data); |
| 3268 | if (ret_val) |
| 3269 | return ret_val; |
| 3270 | default: |
| 3271 | break; |
| 3272 | } |
| 3273 | |
| 3274 | /* Check if it is a valid PHY and set PHY mode if necessary. */ |
| 3275 | ret_val = e1000_copper_link_preconfig(hw); |
| 3276 | if (ret_val) |
| 3277 | return ret_val; |
| 3278 | switch (hw->mac_type) { |
| 3279 | case e1000_80003es2lan: |
| 3280 | /* Kumeran registers are written-only */ |
| 3281 | reg_data = |
| 3282 | E1000_KUMCTRLSTA_INB_CTRL_LINK_STATUS_TX_TIMEOUT_DEFAULT; |
| 3283 | reg_data |= E1000_KUMCTRLSTA_INB_CTRL_DIS_PADDING; |
| 3284 | ret_val = e1000_write_kmrn_reg(hw, |
| 3285 | E1000_KUMCTRLSTA_OFFSET_INB_CTRL, reg_data); |
| 3286 | if (ret_val) |
| 3287 | return ret_val; |
| 3288 | break; |
| 3289 | default: |
| 3290 | break; |
| 3291 | } |
| 3292 | |
| 3293 | if (hw->phy_type == e1000_phy_igp || |
| 3294 | hw->phy_type == e1000_phy_igp_3 || |
| 3295 | hw->phy_type == e1000_phy_igp_2) { |
| 3296 | ret_val = e1000_copper_link_igp_setup(hw); |
| 3297 | if (ret_val) |
| 3298 | return ret_val; |
Marek Vasut | 74a13c2 | 2014-08-08 07:41:39 -0700 | [diff] [blame] | 3299 | } else if (hw->phy_type == e1000_phy_m88 || |
| 3300 | hw->phy_type == e1000_phy_igb) { |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 3301 | ret_val = e1000_copper_link_mgp_setup(hw); |
| 3302 | if (ret_val) |
| 3303 | return ret_val; |
| 3304 | } else if (hw->phy_type == e1000_phy_gg82563) { |
| 3305 | ret_val = e1000_copper_link_ggp_setup(hw); |
| 3306 | if (ret_val) |
| 3307 | return ret_val; |
| 3308 | } |
| 3309 | |
| 3310 | /* always auto */ |
| 3311 | /* Setup autoneg and flow control advertisement |
| 3312 | * and perform autonegotiation */ |
| 3313 | ret_val = e1000_copper_link_autoneg(hw); |
| 3314 | if (ret_val) |
| 3315 | return ret_val; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3316 | |
| 3317 | /* Check link status. Wait up to 100 microseconds for link to become |
| 3318 | * valid. |
| 3319 | */ |
| 3320 | for (i = 0; i < 10; i++) { |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 3321 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); |
| 3322 | if (ret_val) |
| 3323 | return ret_val; |
| 3324 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); |
| 3325 | if (ret_val) |
| 3326 | return ret_val; |
| 3327 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3328 | if (phy_data & MII_SR_LINK_STATUS) { |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 3329 | /* Config the MAC and PHY after link is up */ |
| 3330 | ret_val = e1000_copper_link_postconfig(hw); |
| 3331 | if (ret_val) |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3332 | return ret_val; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 3333 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3334 | DEBUGOUT("Valid link established!!!\n"); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 3335 | return E1000_SUCCESS; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3336 | } |
| 3337 | udelay(10); |
| 3338 | } |
| 3339 | |
| 3340 | DEBUGOUT("Unable to establish link!!!\n"); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 3341 | return E1000_SUCCESS; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3342 | } |
| 3343 | |
| 3344 | /****************************************************************************** |
| 3345 | * Configures PHY autoneg and flow control advertisement settings |
| 3346 | * |
| 3347 | * hw - Struct containing variables accessed by shared code |
| 3348 | ******************************************************************************/ |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 3349 | int32_t |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3350 | e1000_phy_setup_autoneg(struct e1000_hw *hw) |
| 3351 | { |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 3352 | int32_t ret_val; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3353 | uint16_t mii_autoneg_adv_reg; |
| 3354 | uint16_t mii_1000t_ctrl_reg; |
| 3355 | |
| 3356 | DEBUGFUNC(); |
| 3357 | |
| 3358 | /* Read the MII Auto-Neg Advertisement Register (Address 4). */ |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 3359 | ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg); |
| 3360 | if (ret_val) |
| 3361 | return ret_val; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3362 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 3363 | if (hw->phy_type != e1000_phy_ife) { |
| 3364 | /* Read the MII 1000Base-T Control Register (Address 9). */ |
| 3365 | ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, |
| 3366 | &mii_1000t_ctrl_reg); |
| 3367 | if (ret_val) |
| 3368 | return ret_val; |
| 3369 | } else |
| 3370 | mii_1000t_ctrl_reg = 0; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3371 | |
| 3372 | /* Need to parse both autoneg_advertised and fc and set up |
| 3373 | * the appropriate PHY registers. First we will parse for |
| 3374 | * autoneg_advertised software override. Since we can advertise |
| 3375 | * a plethora of combinations, we need to check each bit |
| 3376 | * individually. |
| 3377 | */ |
| 3378 | |
| 3379 | /* First we clear all the 10/100 mb speed bits in the Auto-Neg |
| 3380 | * Advertisement Register (Address 4) and the 1000 mb speed bits in |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 3381 | * the 1000Base-T Control Register (Address 9). |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3382 | */ |
| 3383 | mii_autoneg_adv_reg &= ~REG4_SPEED_MASK; |
| 3384 | mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK; |
| 3385 | |
| 3386 | DEBUGOUT("autoneg_advertised %x\n", hw->autoneg_advertised); |
| 3387 | |
| 3388 | /* Do we want to advertise 10 Mb Half Duplex? */ |
| 3389 | if (hw->autoneg_advertised & ADVERTISE_10_HALF) { |
| 3390 | DEBUGOUT("Advertise 10mb Half duplex\n"); |
| 3391 | mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS; |
| 3392 | } |
| 3393 | |
| 3394 | /* Do we want to advertise 10 Mb Full Duplex? */ |
| 3395 | if (hw->autoneg_advertised & ADVERTISE_10_FULL) { |
| 3396 | DEBUGOUT("Advertise 10mb Full duplex\n"); |
| 3397 | mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS; |
| 3398 | } |
| 3399 | |
| 3400 | /* Do we want to advertise 100 Mb Half Duplex? */ |
| 3401 | if (hw->autoneg_advertised & ADVERTISE_100_HALF) { |
| 3402 | DEBUGOUT("Advertise 100mb Half duplex\n"); |
| 3403 | mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS; |
| 3404 | } |
| 3405 | |
| 3406 | /* Do we want to advertise 100 Mb Full Duplex? */ |
| 3407 | if (hw->autoneg_advertised & ADVERTISE_100_FULL) { |
| 3408 | DEBUGOUT("Advertise 100mb Full duplex\n"); |
| 3409 | mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS; |
| 3410 | } |
| 3411 | |
| 3412 | /* We do not allow the Phy to advertise 1000 Mb Half Duplex */ |
| 3413 | if (hw->autoneg_advertised & ADVERTISE_1000_HALF) { |
| 3414 | DEBUGOUT |
| 3415 | ("Advertise 1000mb Half duplex requested, request denied!\n"); |
| 3416 | } |
| 3417 | |
| 3418 | /* Do we want to advertise 1000 Mb Full Duplex? */ |
| 3419 | if (hw->autoneg_advertised & ADVERTISE_1000_FULL) { |
| 3420 | DEBUGOUT("Advertise 1000mb Full duplex\n"); |
| 3421 | mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS; |
| 3422 | } |
| 3423 | |
| 3424 | /* Check for a software override of the flow control settings, and |
| 3425 | * setup the PHY advertisement registers accordingly. If |
| 3426 | * auto-negotiation is enabled, then software will have to set the |
| 3427 | * "PAUSE" bits to the correct value in the Auto-Negotiation |
| 3428 | * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation. |
| 3429 | * |
| 3430 | * The possible values of the "fc" parameter are: |
Wolfgang Denk | 35f734f | 2008-04-13 09:59:26 -0700 | [diff] [blame] | 3431 | * 0: Flow control is completely disabled |
| 3432 | * 1: Rx flow control is enabled (we can receive pause frames |
| 3433 | * but not send pause frames). |
| 3434 | * 2: Tx flow control is enabled (we can send pause frames |
| 3435 | * but we do not support receiving pause frames). |
| 3436 | * 3: Both Rx and TX flow control (symmetric) are enabled. |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3437 | * other: No software override. The flow control configuration |
Wolfgang Denk | 35f734f | 2008-04-13 09:59:26 -0700 | [diff] [blame] | 3438 | * in the EEPROM is used. |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3439 | */ |
| 3440 | switch (hw->fc) { |
| 3441 | case e1000_fc_none: /* 0 */ |
| 3442 | /* Flow control (RX & TX) is completely disabled by a |
| 3443 | * software over-ride. |
| 3444 | */ |
| 3445 | mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE); |
| 3446 | break; |
| 3447 | case e1000_fc_rx_pause: /* 1 */ |
| 3448 | /* RX Flow control is enabled, and TX Flow control is |
| 3449 | * disabled, by a software over-ride. |
| 3450 | */ |
| 3451 | /* Since there really isn't a way to advertise that we are |
| 3452 | * capable of RX Pause ONLY, we will advertise that we |
| 3453 | * support both symmetric and asymmetric RX PAUSE. Later |
| 3454 | * (in e1000_config_fc_after_link_up) we will disable the |
| 3455 | *hw's ability to send PAUSE frames. |
| 3456 | */ |
| 3457 | mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE); |
| 3458 | break; |
| 3459 | case e1000_fc_tx_pause: /* 2 */ |
| 3460 | /* TX Flow control is enabled, and RX Flow control is |
| 3461 | * disabled, by a software over-ride. |
| 3462 | */ |
| 3463 | mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR; |
| 3464 | mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE; |
| 3465 | break; |
| 3466 | case e1000_fc_full: /* 3 */ |
| 3467 | /* Flow control (both RX and TX) is enabled by a software |
| 3468 | * over-ride. |
| 3469 | */ |
| 3470 | mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE); |
| 3471 | break; |
| 3472 | default: |
| 3473 | DEBUGOUT("Flow control param set incorrectly\n"); |
| 3474 | return -E1000_ERR_CONFIG; |
| 3475 | } |
| 3476 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 3477 | ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg); |
| 3478 | if (ret_val) |
| 3479 | return ret_val; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3480 | |
| 3481 | DEBUGOUT("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg); |
| 3482 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 3483 | if (hw->phy_type != e1000_phy_ife) { |
| 3484 | ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, |
| 3485 | mii_1000t_ctrl_reg); |
| 3486 | if (ret_val) |
| 3487 | return ret_val; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3488 | } |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 3489 | |
| 3490 | return E1000_SUCCESS; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3491 | } |
| 3492 | |
| 3493 | /****************************************************************************** |
| 3494 | * Sets the collision distance in the Transmit Control register |
| 3495 | * |
| 3496 | * hw - Struct containing variables accessed by shared code |
| 3497 | * |
| 3498 | * Link should have been established previously. Reads the speed and duplex |
| 3499 | * information from the Device Status register. |
| 3500 | ******************************************************************************/ |
| 3501 | static void |
| 3502 | e1000_config_collision_dist(struct e1000_hw *hw) |
| 3503 | { |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 3504 | uint32_t tctl, coll_dist; |
| 3505 | |
| 3506 | DEBUGFUNC(); |
| 3507 | |
| 3508 | if (hw->mac_type < e1000_82543) |
| 3509 | coll_dist = E1000_COLLISION_DISTANCE_82542; |
| 3510 | else |
| 3511 | coll_dist = E1000_COLLISION_DISTANCE; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3512 | |
| 3513 | tctl = E1000_READ_REG(hw, TCTL); |
| 3514 | |
| 3515 | tctl &= ~E1000_TCTL_COLD; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 3516 | tctl |= coll_dist << E1000_COLD_SHIFT; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3517 | |
| 3518 | E1000_WRITE_REG(hw, TCTL, tctl); |
| 3519 | E1000_WRITE_FLUSH(hw); |
| 3520 | } |
| 3521 | |
| 3522 | /****************************************************************************** |
| 3523 | * Sets MAC speed and duplex settings to reflect the those in the PHY |
| 3524 | * |
| 3525 | * hw - Struct containing variables accessed by shared code |
| 3526 | * mii_reg - data to write to the MII control register |
| 3527 | * |
| 3528 | * The contents of the PHY register containing the needed information need to |
| 3529 | * be passed in. |
| 3530 | ******************************************************************************/ |
| 3531 | static int |
| 3532 | e1000_config_mac_to_phy(struct e1000_hw *hw) |
| 3533 | { |
| 3534 | uint32_t ctrl; |
| 3535 | uint16_t phy_data; |
| 3536 | |
| 3537 | DEBUGFUNC(); |
| 3538 | |
| 3539 | /* Read the Device Control Register and set the bits to Force Speed |
| 3540 | * and Duplex. |
| 3541 | */ |
| 3542 | ctrl = E1000_READ_REG(hw, CTRL); |
| 3543 | ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX); |
Marek Vasut | 74a13c2 | 2014-08-08 07:41:39 -0700 | [diff] [blame] | 3544 | ctrl &= ~(E1000_CTRL_ILOS); |
| 3545 | ctrl |= (E1000_CTRL_SPD_SEL); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3546 | |
| 3547 | /* Set up duplex in the Device Control and Transmit Control |
| 3548 | * registers depending on negotiated values. |
| 3549 | */ |
| 3550 | if (e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data) < 0) { |
| 3551 | DEBUGOUT("PHY Read Error\n"); |
| 3552 | return -E1000_ERR_PHY; |
| 3553 | } |
| 3554 | if (phy_data & M88E1000_PSSR_DPLX) |
| 3555 | ctrl |= E1000_CTRL_FD; |
| 3556 | else |
| 3557 | ctrl &= ~E1000_CTRL_FD; |
| 3558 | |
| 3559 | e1000_config_collision_dist(hw); |
| 3560 | |
| 3561 | /* Set up speed in the Device Control register depending on |
| 3562 | * negotiated values. |
| 3563 | */ |
| 3564 | if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) |
| 3565 | ctrl |= E1000_CTRL_SPD_1000; |
| 3566 | else if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS) |
| 3567 | ctrl |= E1000_CTRL_SPD_100; |
| 3568 | /* Write the configured values back to the Device Control Reg. */ |
| 3569 | E1000_WRITE_REG(hw, CTRL, ctrl); |
| 3570 | return 0; |
| 3571 | } |
| 3572 | |
| 3573 | /****************************************************************************** |
| 3574 | * Forces the MAC's flow control settings. |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 3575 | * |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3576 | * hw - Struct containing variables accessed by shared code |
| 3577 | * |
| 3578 | * Sets the TFCE and RFCE bits in the device control register to reflect |
| 3579 | * the adapter settings. TFCE and RFCE need to be explicitly set by |
| 3580 | * software when a Copper PHY is used because autonegotiation is managed |
| 3581 | * by the PHY rather than the MAC. Software must also configure these |
| 3582 | * bits when link is forced on a fiber connection. |
| 3583 | *****************************************************************************/ |
| 3584 | static int |
| 3585 | e1000_force_mac_fc(struct e1000_hw *hw) |
| 3586 | { |
| 3587 | uint32_t ctrl; |
| 3588 | |
| 3589 | DEBUGFUNC(); |
| 3590 | |
| 3591 | /* Get the current configuration of the Device Control Register */ |
| 3592 | ctrl = E1000_READ_REG(hw, CTRL); |
| 3593 | |
| 3594 | /* Because we didn't get link via the internal auto-negotiation |
| 3595 | * mechanism (we either forced link or we got link via PHY |
| 3596 | * auto-neg), we have to manually enable/disable transmit an |
| 3597 | * receive flow control. |
| 3598 | * |
| 3599 | * The "Case" statement below enables/disable flow control |
| 3600 | * according to the "hw->fc" parameter. |
| 3601 | * |
| 3602 | * The possible values of the "fc" parameter are: |
Wolfgang Denk | 35f734f | 2008-04-13 09:59:26 -0700 | [diff] [blame] | 3603 | * 0: Flow control is completely disabled |
| 3604 | * 1: Rx flow control is enabled (we can receive pause |
| 3605 | * frames but not send pause frames). |
| 3606 | * 2: Tx flow control is enabled (we can send pause frames |
| 3607 | * frames but we do not receive pause frames). |
| 3608 | * 3: Both Rx and TX flow control (symmetric) is enabled. |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3609 | * other: No other values should be possible at this point. |
| 3610 | */ |
| 3611 | |
| 3612 | switch (hw->fc) { |
| 3613 | case e1000_fc_none: |
| 3614 | ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE)); |
| 3615 | break; |
| 3616 | case e1000_fc_rx_pause: |
| 3617 | ctrl &= (~E1000_CTRL_TFCE); |
| 3618 | ctrl |= E1000_CTRL_RFCE; |
| 3619 | break; |
| 3620 | case e1000_fc_tx_pause: |
| 3621 | ctrl &= (~E1000_CTRL_RFCE); |
| 3622 | ctrl |= E1000_CTRL_TFCE; |
| 3623 | break; |
| 3624 | case e1000_fc_full: |
| 3625 | ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE); |
| 3626 | break; |
| 3627 | default: |
| 3628 | DEBUGOUT("Flow control param set incorrectly\n"); |
| 3629 | return -E1000_ERR_CONFIG; |
| 3630 | } |
| 3631 | |
| 3632 | /* Disable TX Flow Control for 82542 (rev 2.0) */ |
| 3633 | if (hw->mac_type == e1000_82542_rev2_0) |
| 3634 | ctrl &= (~E1000_CTRL_TFCE); |
| 3635 | |
| 3636 | E1000_WRITE_REG(hw, CTRL, ctrl); |
| 3637 | return 0; |
| 3638 | } |
| 3639 | |
| 3640 | /****************************************************************************** |
| 3641 | * Configures flow control settings after link is established |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 3642 | * |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3643 | * hw - Struct containing variables accessed by shared code |
| 3644 | * |
| 3645 | * Should be called immediately after a valid link has been established. |
| 3646 | * Forces MAC flow control settings if link was forced. When in MII/GMII mode |
| 3647 | * and autonegotiation is enabled, the MAC flow control settings will be set |
| 3648 | * based on the flow control negotiated by the PHY. In TBI mode, the TFCE |
| 3649 | * and RFCE bits will be automaticaly set to the negotiated flow control mode. |
| 3650 | *****************************************************************************/ |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 3651 | static int32_t |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3652 | e1000_config_fc_after_link_up(struct e1000_hw *hw) |
| 3653 | { |
| 3654 | int32_t ret_val; |
| 3655 | uint16_t mii_status_reg; |
| 3656 | uint16_t mii_nway_adv_reg; |
| 3657 | uint16_t mii_nway_lp_ability_reg; |
| 3658 | uint16_t speed; |
| 3659 | uint16_t duplex; |
| 3660 | |
| 3661 | DEBUGFUNC(); |
| 3662 | |
| 3663 | /* Check for the case where we have fiber media and auto-neg failed |
| 3664 | * so we had to force link. In this case, we need to force the |
| 3665 | * configuration of the MAC to match the "fc" parameter. |
| 3666 | */ |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 3667 | if (((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed)) |
| 3668 | || ((hw->media_type == e1000_media_type_internal_serdes) |
| 3669 | && (hw->autoneg_failed)) |
| 3670 | || ((hw->media_type == e1000_media_type_copper) |
| 3671 | && (!hw->autoneg))) { |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3672 | ret_val = e1000_force_mac_fc(hw); |
| 3673 | if (ret_val < 0) { |
| 3674 | DEBUGOUT("Error forcing flow control settings\n"); |
| 3675 | return ret_val; |
| 3676 | } |
| 3677 | } |
| 3678 | |
| 3679 | /* Check for the case where we have copper media and auto-neg is |
| 3680 | * enabled. In this case, we need to check and see if Auto-Neg |
| 3681 | * has completed, and if so, how the PHY and link partner has |
| 3682 | * flow control configured. |
| 3683 | */ |
| 3684 | if (hw->media_type == e1000_media_type_copper) { |
| 3685 | /* Read the MII Status Register and check to see if AutoNeg |
| 3686 | * has completed. We read this twice because this reg has |
| 3687 | * some "sticky" (latched) bits. |
| 3688 | */ |
| 3689 | if (e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg) < 0) { |
Minghuan Lian | 674bcd5 | 2015-03-19 09:43:51 -0700 | [diff] [blame] | 3690 | DEBUGOUT("PHY Read Error\n"); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3691 | return -E1000_ERR_PHY; |
| 3692 | } |
| 3693 | if (e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg) < 0) { |
Minghuan Lian | 674bcd5 | 2015-03-19 09:43:51 -0700 | [diff] [blame] | 3694 | DEBUGOUT("PHY Read Error\n"); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3695 | return -E1000_ERR_PHY; |
| 3696 | } |
| 3697 | |
| 3698 | if (mii_status_reg & MII_SR_AUTONEG_COMPLETE) { |
| 3699 | /* The AutoNeg process has completed, so we now need to |
| 3700 | * read both the Auto Negotiation Advertisement Register |
| 3701 | * (Address 4) and the Auto_Negotiation Base Page Ability |
| 3702 | * Register (Address 5) to determine how flow control was |
| 3703 | * negotiated. |
| 3704 | */ |
| 3705 | if (e1000_read_phy_reg |
| 3706 | (hw, PHY_AUTONEG_ADV, &mii_nway_adv_reg) < 0) { |
| 3707 | DEBUGOUT("PHY Read Error\n"); |
| 3708 | return -E1000_ERR_PHY; |
| 3709 | } |
| 3710 | if (e1000_read_phy_reg |
| 3711 | (hw, PHY_LP_ABILITY, |
| 3712 | &mii_nway_lp_ability_reg) < 0) { |
| 3713 | DEBUGOUT("PHY Read Error\n"); |
| 3714 | return -E1000_ERR_PHY; |
| 3715 | } |
| 3716 | |
| 3717 | /* Two bits in the Auto Negotiation Advertisement Register |
| 3718 | * (Address 4) and two bits in the Auto Negotiation Base |
| 3719 | * Page Ability Register (Address 5) determine flow control |
| 3720 | * for both the PHY and the link partner. The following |
| 3721 | * table, taken out of the IEEE 802.3ab/D6.0 dated March 25, |
| 3722 | * 1999, describes these PAUSE resolution bits and how flow |
| 3723 | * control is determined based upon these settings. |
| 3724 | * NOTE: DC = Don't Care |
| 3725 | * |
| 3726 | * LOCAL DEVICE | LINK PARTNER |
| 3727 | * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution |
| 3728 | *-------|---------|-------|---------|-------------------- |
Wolfgang Denk | 35f734f | 2008-04-13 09:59:26 -0700 | [diff] [blame] | 3729 | * 0 | 0 | DC | DC | e1000_fc_none |
| 3730 | * 0 | 1 | 0 | DC | e1000_fc_none |
| 3731 | * 0 | 1 | 1 | 0 | e1000_fc_none |
| 3732 | * 0 | 1 | 1 | 1 | e1000_fc_tx_pause |
| 3733 | * 1 | 0 | 0 | DC | e1000_fc_none |
| 3734 | * 1 | DC | 1 | DC | e1000_fc_full |
| 3735 | * 1 | 1 | 0 | 0 | e1000_fc_none |
| 3736 | * 1 | 1 | 0 | 1 | e1000_fc_rx_pause |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3737 | * |
| 3738 | */ |
| 3739 | /* Are both PAUSE bits set to 1? If so, this implies |
| 3740 | * Symmetric Flow Control is enabled at both ends. The |
| 3741 | * ASM_DIR bits are irrelevant per the spec. |
| 3742 | * |
| 3743 | * For Symmetric Flow Control: |
| 3744 | * |
| 3745 | * LOCAL DEVICE | LINK PARTNER |
| 3746 | * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result |
| 3747 | *-------|---------|-------|---------|-------------------- |
Wolfgang Denk | 35f734f | 2008-04-13 09:59:26 -0700 | [diff] [blame] | 3748 | * 1 | DC | 1 | DC | e1000_fc_full |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3749 | * |
| 3750 | */ |
| 3751 | if ((mii_nway_adv_reg & NWAY_AR_PAUSE) && |
| 3752 | (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) { |
| 3753 | /* Now we need to check if the user selected RX ONLY |
| 3754 | * of pause frames. In this case, we had to advertise |
| 3755 | * FULL flow control because we could not advertise RX |
| 3756 | * ONLY. Hence, we must now check to see if we need to |
| 3757 | * turn OFF the TRANSMISSION of PAUSE frames. |
| 3758 | */ |
| 3759 | if (hw->original_fc == e1000_fc_full) { |
| 3760 | hw->fc = e1000_fc_full; |
| 3761 | DEBUGOUT("Flow Control = FULL.\r\n"); |
| 3762 | } else { |
| 3763 | hw->fc = e1000_fc_rx_pause; |
| 3764 | DEBUGOUT |
| 3765 | ("Flow Control = RX PAUSE frames only.\r\n"); |
| 3766 | } |
| 3767 | } |
| 3768 | /* For receiving PAUSE frames ONLY. |
| 3769 | * |
| 3770 | * LOCAL DEVICE | LINK PARTNER |
| 3771 | * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result |
| 3772 | *-------|---------|-------|---------|-------------------- |
Wolfgang Denk | 35f734f | 2008-04-13 09:59:26 -0700 | [diff] [blame] | 3773 | * 0 | 1 | 1 | 1 | e1000_fc_tx_pause |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3774 | * |
| 3775 | */ |
| 3776 | else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) && |
| 3777 | (mii_nway_adv_reg & NWAY_AR_ASM_DIR) && |
| 3778 | (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) && |
| 3779 | (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) |
| 3780 | { |
| 3781 | hw->fc = e1000_fc_tx_pause; |
| 3782 | DEBUGOUT |
| 3783 | ("Flow Control = TX PAUSE frames only.\r\n"); |
| 3784 | } |
| 3785 | /* For transmitting PAUSE frames ONLY. |
| 3786 | * |
| 3787 | * LOCAL DEVICE | LINK PARTNER |
| 3788 | * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result |
| 3789 | *-------|---------|-------|---------|-------------------- |
Wolfgang Denk | 35f734f | 2008-04-13 09:59:26 -0700 | [diff] [blame] | 3790 | * 1 | 1 | 0 | 1 | e1000_fc_rx_pause |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3791 | * |
| 3792 | */ |
| 3793 | else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) && |
| 3794 | (mii_nway_adv_reg & NWAY_AR_ASM_DIR) && |
| 3795 | !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) && |
| 3796 | (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) |
| 3797 | { |
| 3798 | hw->fc = e1000_fc_rx_pause; |
| 3799 | DEBUGOUT |
| 3800 | ("Flow Control = RX PAUSE frames only.\r\n"); |
| 3801 | } |
| 3802 | /* Per the IEEE spec, at this point flow control should be |
| 3803 | * disabled. However, we want to consider that we could |
| 3804 | * be connected to a legacy switch that doesn't advertise |
| 3805 | * desired flow control, but can be forced on the link |
| 3806 | * partner. So if we advertised no flow control, that is |
| 3807 | * what we will resolve to. If we advertised some kind of |
| 3808 | * receive capability (Rx Pause Only or Full Flow Control) |
| 3809 | * and the link partner advertised none, we will configure |
| 3810 | * ourselves to enable Rx Flow Control only. We can do |
| 3811 | * this safely for two reasons: If the link partner really |
| 3812 | * didn't want flow control enabled, and we enable Rx, no |
| 3813 | * harm done since we won't be receiving any PAUSE frames |
| 3814 | * anyway. If the intent on the link partner was to have |
| 3815 | * flow control enabled, then by us enabling RX only, we |
| 3816 | * can at least receive pause frames and process them. |
| 3817 | * This is a good idea because in most cases, since we are |
| 3818 | * predominantly a server NIC, more times than not we will |
| 3819 | * be asked to delay transmission of packets than asking |
| 3820 | * our link partner to pause transmission of frames. |
| 3821 | */ |
| 3822 | else if (hw->original_fc == e1000_fc_none || |
| 3823 | hw->original_fc == e1000_fc_tx_pause) { |
| 3824 | hw->fc = e1000_fc_none; |
| 3825 | DEBUGOUT("Flow Control = NONE.\r\n"); |
| 3826 | } else { |
| 3827 | hw->fc = e1000_fc_rx_pause; |
| 3828 | DEBUGOUT |
| 3829 | ("Flow Control = RX PAUSE frames only.\r\n"); |
| 3830 | } |
| 3831 | |
Wolfgang Denk | 35f734f | 2008-04-13 09:59:26 -0700 | [diff] [blame] | 3832 | /* Now we need to do one last check... If we auto- |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3833 | * negotiated to HALF DUPLEX, flow control should not be |
| 3834 | * enabled per IEEE 802.3 spec. |
| 3835 | */ |
| 3836 | e1000_get_speed_and_duplex(hw, &speed, &duplex); |
| 3837 | |
| 3838 | if (duplex == HALF_DUPLEX) |
| 3839 | hw->fc = e1000_fc_none; |
| 3840 | |
| 3841 | /* Now we call a subroutine to actually force the MAC |
| 3842 | * controller to use the correct flow control settings. |
| 3843 | */ |
| 3844 | ret_val = e1000_force_mac_fc(hw); |
| 3845 | if (ret_val < 0) { |
| 3846 | DEBUGOUT |
| 3847 | ("Error forcing flow control settings\n"); |
| 3848 | return ret_val; |
| 3849 | } |
| 3850 | } else { |
| 3851 | DEBUGOUT |
| 3852 | ("Copper PHY and Auto Neg has not completed.\r\n"); |
| 3853 | } |
| 3854 | } |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 3855 | return E1000_SUCCESS; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3856 | } |
| 3857 | |
| 3858 | /****************************************************************************** |
| 3859 | * Checks to see if the link status of the hardware has changed. |
| 3860 | * |
| 3861 | * hw - Struct containing variables accessed by shared code |
| 3862 | * |
| 3863 | * Called by any function that needs to check the link status of the adapter. |
| 3864 | *****************************************************************************/ |
| 3865 | static int |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 3866 | e1000_check_for_link(struct e1000_hw *hw) |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3867 | { |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3868 | uint32_t rxcw; |
| 3869 | uint32_t ctrl; |
| 3870 | uint32_t status; |
| 3871 | uint32_t rctl; |
| 3872 | uint32_t signal; |
| 3873 | int32_t ret_val; |
| 3874 | uint16_t phy_data; |
| 3875 | uint16_t lp_capability; |
| 3876 | |
| 3877 | DEBUGFUNC(); |
| 3878 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 3879 | /* On adapters with a MAC newer that 82544, SW Defineable pin 1 will be |
| 3880 | * set when the optics detect a signal. On older adapters, it will be |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3881 | * cleared when there is a signal |
| 3882 | */ |
| 3883 | ctrl = E1000_READ_REG(hw, CTRL); |
| 3884 | if ((hw->mac_type > e1000_82544) && !(ctrl & E1000_CTRL_ILOS)) |
| 3885 | signal = E1000_CTRL_SWDPIN1; |
| 3886 | else |
| 3887 | signal = 0; |
| 3888 | |
| 3889 | status = E1000_READ_REG(hw, STATUS); |
| 3890 | rxcw = E1000_READ_REG(hw, RXCW); |
| 3891 | DEBUGOUT("ctrl: %#08x status %#08x rxcw %#08x\n", ctrl, status, rxcw); |
| 3892 | |
| 3893 | /* If we have a copper PHY then we only want to go out to the PHY |
| 3894 | * registers to see if Auto-Neg has completed and/or if our link |
Wolfgang Denk | 35f734f | 2008-04-13 09:59:26 -0700 | [diff] [blame] | 3895 | * status has changed. The get_link_status flag will be set if we |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3896 | * receive a Link Status Change interrupt or we have Rx Sequence |
| 3897 | * Errors. |
| 3898 | */ |
| 3899 | if ((hw->media_type == e1000_media_type_copper) && hw->get_link_status) { |
| 3900 | /* First we want to see if the MII Status Register reports |
| 3901 | * link. If so, then we want to get the current speed/duplex |
| 3902 | * of the PHY. |
| 3903 | * Read the register twice since the link bit is sticky. |
| 3904 | */ |
| 3905 | if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) { |
| 3906 | DEBUGOUT("PHY Read Error\n"); |
| 3907 | return -E1000_ERR_PHY; |
| 3908 | } |
| 3909 | if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) { |
| 3910 | DEBUGOUT("PHY Read Error\n"); |
| 3911 | return -E1000_ERR_PHY; |
| 3912 | } |
| 3913 | |
| 3914 | if (phy_data & MII_SR_LINK_STATUS) { |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 3915 | hw->get_link_status = false; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3916 | } else { |
| 3917 | /* No link detected */ |
| 3918 | return -E1000_ERR_NOLINK; |
| 3919 | } |
| 3920 | |
| 3921 | /* We have a M88E1000 PHY and Auto-Neg is enabled. If we |
| 3922 | * have Si on board that is 82544 or newer, Auto |
| 3923 | * Speed Detection takes care of MAC speed/duplex |
| 3924 | * configuration. So we only need to configure Collision |
| 3925 | * Distance in the MAC. Otherwise, we need to force |
| 3926 | * speed/duplex on the MAC to the current PHY speed/duplex |
| 3927 | * settings. |
| 3928 | */ |
| 3929 | if (hw->mac_type >= e1000_82544) |
| 3930 | e1000_config_collision_dist(hw); |
| 3931 | else { |
| 3932 | ret_val = e1000_config_mac_to_phy(hw); |
| 3933 | if (ret_val < 0) { |
| 3934 | DEBUGOUT |
| 3935 | ("Error configuring MAC to PHY settings\n"); |
| 3936 | return ret_val; |
| 3937 | } |
| 3938 | } |
| 3939 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 3940 | /* Configure Flow Control now that Auto-Neg has completed. First, we |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3941 | * need to restore the desired flow control settings because we may |
| 3942 | * have had to re-autoneg with a different link partner. |
| 3943 | */ |
| 3944 | ret_val = e1000_config_fc_after_link_up(hw); |
| 3945 | if (ret_val < 0) { |
| 3946 | DEBUGOUT("Error configuring flow control\n"); |
| 3947 | return ret_val; |
| 3948 | } |
| 3949 | |
| 3950 | /* At this point we know that we are on copper and we have |
| 3951 | * auto-negotiated link. These are conditions for checking the link |
Wolfgang Denk | 35f734f | 2008-04-13 09:59:26 -0700 | [diff] [blame] | 3952 | * parter capability register. We use the link partner capability to |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3953 | * determine if TBI Compatibility needs to be turned on or off. If |
| 3954 | * the link partner advertises any speed in addition to Gigabit, then |
| 3955 | * we assume that they are GMII-based, and TBI compatibility is not |
| 3956 | * needed. If no other speeds are advertised, we assume the link |
| 3957 | * partner is TBI-based, and we turn on TBI Compatibility. |
| 3958 | */ |
| 3959 | if (hw->tbi_compatibility_en) { |
| 3960 | if (e1000_read_phy_reg |
| 3961 | (hw, PHY_LP_ABILITY, &lp_capability) < 0) { |
| 3962 | DEBUGOUT("PHY Read Error\n"); |
| 3963 | return -E1000_ERR_PHY; |
| 3964 | } |
| 3965 | if (lp_capability & (NWAY_LPAR_10T_HD_CAPS | |
| 3966 | NWAY_LPAR_10T_FD_CAPS | |
| 3967 | NWAY_LPAR_100TX_HD_CAPS | |
| 3968 | NWAY_LPAR_100TX_FD_CAPS | |
| 3969 | NWAY_LPAR_100T4_CAPS)) { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 3970 | /* If our link partner advertises anything in addition to |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3971 | * gigabit, we do not need to enable TBI compatibility. |
| 3972 | */ |
| 3973 | if (hw->tbi_compatibility_on) { |
| 3974 | /* If we previously were in the mode, turn it off. */ |
| 3975 | rctl = E1000_READ_REG(hw, RCTL); |
| 3976 | rctl &= ~E1000_RCTL_SBP; |
| 3977 | E1000_WRITE_REG(hw, RCTL, rctl); |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 3978 | hw->tbi_compatibility_on = false; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3979 | } |
| 3980 | } else { |
| 3981 | /* If TBI compatibility is was previously off, turn it on. For |
| 3982 | * compatibility with a TBI link partner, we will store bad |
| 3983 | * packets. Some frames have an additional byte on the end and |
| 3984 | * will look like CRC errors to to the hardware. |
| 3985 | */ |
| 3986 | if (!hw->tbi_compatibility_on) { |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 3987 | hw->tbi_compatibility_on = true; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 3988 | rctl = E1000_READ_REG(hw, RCTL); |
| 3989 | rctl |= E1000_RCTL_SBP; |
| 3990 | E1000_WRITE_REG(hw, RCTL, rctl); |
| 3991 | } |
| 3992 | } |
| 3993 | } |
| 3994 | } |
| 3995 | /* If we don't have link (auto-negotiation failed or link partner cannot |
| 3996 | * auto-negotiate), the cable is plugged in (we have signal), and our |
| 3997 | * link partner is not trying to auto-negotiate with us (we are receiving |
| 3998 | * idles or data), we need to force link up. We also need to give |
| 3999 | * auto-negotiation time to complete, in case the cable was just plugged |
| 4000 | * in. The autoneg_failed flag does this. |
| 4001 | */ |
| 4002 | else if ((hw->media_type == e1000_media_type_fiber) && |
| 4003 | (!(status & E1000_STATUS_LU)) && |
| 4004 | ((ctrl & E1000_CTRL_SWDPIN1) == signal) && |
| 4005 | (!(rxcw & E1000_RXCW_C))) { |
| 4006 | if (hw->autoneg_failed == 0) { |
| 4007 | hw->autoneg_failed = 1; |
| 4008 | return 0; |
| 4009 | } |
| 4010 | DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\r\n"); |
| 4011 | |
| 4012 | /* Disable auto-negotiation in the TXCW register */ |
| 4013 | E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE)); |
| 4014 | |
| 4015 | /* Force link-up and also force full-duplex. */ |
| 4016 | ctrl = E1000_READ_REG(hw, CTRL); |
| 4017 | ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD); |
| 4018 | E1000_WRITE_REG(hw, CTRL, ctrl); |
| 4019 | |
| 4020 | /* Configure Flow Control after forcing link up. */ |
| 4021 | ret_val = e1000_config_fc_after_link_up(hw); |
| 4022 | if (ret_val < 0) { |
| 4023 | DEBUGOUT("Error configuring flow control\n"); |
| 4024 | return ret_val; |
| 4025 | } |
| 4026 | } |
| 4027 | /* If we are forcing link and we are receiving /C/ ordered sets, re-enable |
| 4028 | * auto-negotiation in the TXCW register and disable forced link in the |
| 4029 | * Device Control register in an attempt to auto-negotiate with our link |
| 4030 | * partner. |
| 4031 | */ |
| 4032 | else if ((hw->media_type == e1000_media_type_fiber) && |
| 4033 | (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) { |
| 4034 | DEBUGOUT |
| 4035 | ("RXing /C/, enable AutoNeg and stop forcing link.\r\n"); |
| 4036 | E1000_WRITE_REG(hw, TXCW, hw->txcw); |
| 4037 | E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU)); |
| 4038 | } |
| 4039 | return 0; |
| 4040 | } |
| 4041 | |
| 4042 | /****************************************************************************** |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4043 | * Configure the MAC-to-PHY interface for 10/100Mbps |
| 4044 | * |
| 4045 | * hw - Struct containing variables accessed by shared code |
| 4046 | ******************************************************************************/ |
| 4047 | static int32_t |
| 4048 | e1000_configure_kmrn_for_10_100(struct e1000_hw *hw, uint16_t duplex) |
| 4049 | { |
| 4050 | int32_t ret_val = E1000_SUCCESS; |
| 4051 | uint32_t tipg; |
| 4052 | uint16_t reg_data; |
| 4053 | |
| 4054 | DEBUGFUNC(); |
| 4055 | |
| 4056 | reg_data = E1000_KUMCTRLSTA_HD_CTRL_10_100_DEFAULT; |
| 4057 | ret_val = e1000_write_kmrn_reg(hw, |
| 4058 | E1000_KUMCTRLSTA_OFFSET_HD_CTRL, reg_data); |
| 4059 | if (ret_val) |
| 4060 | return ret_val; |
| 4061 | |
| 4062 | /* Configure Transmit Inter-Packet Gap */ |
| 4063 | tipg = E1000_READ_REG(hw, TIPG); |
| 4064 | tipg &= ~E1000_TIPG_IPGT_MASK; |
| 4065 | tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_10_100; |
| 4066 | E1000_WRITE_REG(hw, TIPG, tipg); |
| 4067 | |
| 4068 | ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, ®_data); |
| 4069 | |
| 4070 | if (ret_val) |
| 4071 | return ret_val; |
| 4072 | |
| 4073 | if (duplex == HALF_DUPLEX) |
| 4074 | reg_data |= GG82563_KMCR_PASS_FALSE_CARRIER; |
| 4075 | else |
| 4076 | reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER; |
| 4077 | |
| 4078 | ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data); |
| 4079 | |
| 4080 | return ret_val; |
| 4081 | } |
| 4082 | |
| 4083 | static int32_t |
| 4084 | e1000_configure_kmrn_for_1000(struct e1000_hw *hw) |
| 4085 | { |
| 4086 | int32_t ret_val = E1000_SUCCESS; |
| 4087 | uint16_t reg_data; |
| 4088 | uint32_t tipg; |
| 4089 | |
| 4090 | DEBUGFUNC(); |
| 4091 | |
| 4092 | reg_data = E1000_KUMCTRLSTA_HD_CTRL_1000_DEFAULT; |
| 4093 | ret_val = e1000_write_kmrn_reg(hw, |
| 4094 | E1000_KUMCTRLSTA_OFFSET_HD_CTRL, reg_data); |
| 4095 | if (ret_val) |
| 4096 | return ret_val; |
| 4097 | |
| 4098 | /* Configure Transmit Inter-Packet Gap */ |
| 4099 | tipg = E1000_READ_REG(hw, TIPG); |
| 4100 | tipg &= ~E1000_TIPG_IPGT_MASK; |
| 4101 | tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000; |
| 4102 | E1000_WRITE_REG(hw, TIPG, tipg); |
| 4103 | |
| 4104 | ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, ®_data); |
| 4105 | |
| 4106 | if (ret_val) |
| 4107 | return ret_val; |
| 4108 | |
| 4109 | reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER; |
| 4110 | ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data); |
| 4111 | |
| 4112 | return ret_val; |
| 4113 | } |
| 4114 | |
| 4115 | /****************************************************************************** |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4116 | * Detects the current speed and duplex settings of the hardware. |
| 4117 | * |
| 4118 | * hw - Struct containing variables accessed by shared code |
| 4119 | * speed - Speed of the connection |
| 4120 | * duplex - Duplex setting of the connection |
| 4121 | *****************************************************************************/ |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4122 | static int |
| 4123 | e1000_get_speed_and_duplex(struct e1000_hw *hw, uint16_t *speed, |
| 4124 | uint16_t *duplex) |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4125 | { |
| 4126 | uint32_t status; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4127 | int32_t ret_val; |
| 4128 | uint16_t phy_data; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4129 | |
| 4130 | DEBUGFUNC(); |
| 4131 | |
| 4132 | if (hw->mac_type >= e1000_82543) { |
| 4133 | status = E1000_READ_REG(hw, STATUS); |
| 4134 | if (status & E1000_STATUS_SPEED_1000) { |
| 4135 | *speed = SPEED_1000; |
| 4136 | DEBUGOUT("1000 Mbs, "); |
| 4137 | } else if (status & E1000_STATUS_SPEED_100) { |
| 4138 | *speed = SPEED_100; |
| 4139 | DEBUGOUT("100 Mbs, "); |
| 4140 | } else { |
| 4141 | *speed = SPEED_10; |
| 4142 | DEBUGOUT("10 Mbs, "); |
| 4143 | } |
| 4144 | |
| 4145 | if (status & E1000_STATUS_FD) { |
| 4146 | *duplex = FULL_DUPLEX; |
| 4147 | DEBUGOUT("Full Duplex\r\n"); |
| 4148 | } else { |
| 4149 | *duplex = HALF_DUPLEX; |
| 4150 | DEBUGOUT(" Half Duplex\r\n"); |
| 4151 | } |
| 4152 | } else { |
| 4153 | DEBUGOUT("1000 Mbs, Full Duplex\r\n"); |
| 4154 | *speed = SPEED_1000; |
| 4155 | *duplex = FULL_DUPLEX; |
| 4156 | } |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4157 | |
| 4158 | /* IGP01 PHY may advertise full duplex operation after speed downgrade |
| 4159 | * even if it is operating at half duplex. Here we set the duplex |
| 4160 | * settings to match the duplex in the link partner's capabilities. |
| 4161 | */ |
| 4162 | if (hw->phy_type == e1000_phy_igp && hw->speed_downgraded) { |
| 4163 | ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data); |
| 4164 | if (ret_val) |
| 4165 | return ret_val; |
| 4166 | |
| 4167 | if (!(phy_data & NWAY_ER_LP_NWAY_CAPS)) |
| 4168 | *duplex = HALF_DUPLEX; |
| 4169 | else { |
| 4170 | ret_val = e1000_read_phy_reg(hw, |
| 4171 | PHY_LP_ABILITY, &phy_data); |
| 4172 | if (ret_val) |
| 4173 | return ret_val; |
| 4174 | if ((*speed == SPEED_100 && |
| 4175 | !(phy_data & NWAY_LPAR_100TX_FD_CAPS)) |
| 4176 | || (*speed == SPEED_10 |
| 4177 | && !(phy_data & NWAY_LPAR_10T_FD_CAPS))) |
| 4178 | *duplex = HALF_DUPLEX; |
| 4179 | } |
| 4180 | } |
| 4181 | |
| 4182 | if ((hw->mac_type == e1000_80003es2lan) && |
| 4183 | (hw->media_type == e1000_media_type_copper)) { |
| 4184 | if (*speed == SPEED_1000) |
| 4185 | ret_val = e1000_configure_kmrn_for_1000(hw); |
| 4186 | else |
| 4187 | ret_val = e1000_configure_kmrn_for_10_100(hw, *duplex); |
| 4188 | if (ret_val) |
| 4189 | return ret_val; |
| 4190 | } |
| 4191 | return E1000_SUCCESS; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4192 | } |
| 4193 | |
| 4194 | /****************************************************************************** |
| 4195 | * Blocks until autoneg completes or times out (~4.5 seconds) |
| 4196 | * |
| 4197 | * hw - Struct containing variables accessed by shared code |
| 4198 | ******************************************************************************/ |
| 4199 | static int |
| 4200 | e1000_wait_autoneg(struct e1000_hw *hw) |
| 4201 | { |
| 4202 | uint16_t i; |
| 4203 | uint16_t phy_data; |
| 4204 | |
| 4205 | DEBUGFUNC(); |
| 4206 | DEBUGOUT("Waiting for Auto-Neg to complete.\n"); |
| 4207 | |
Stefan Roese | 497c731 | 2015-08-11 17:12:44 +0200 | [diff] [blame] | 4208 | /* We will wait for autoneg to complete or timeout to expire. */ |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4209 | for (i = PHY_AUTO_NEG_TIME; i > 0; i--) { |
| 4210 | /* Read the MII Status Register and wait for Auto-Neg |
| 4211 | * Complete bit to be set. |
| 4212 | */ |
| 4213 | if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) { |
| 4214 | DEBUGOUT("PHY Read Error\n"); |
| 4215 | return -E1000_ERR_PHY; |
| 4216 | } |
| 4217 | if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) { |
| 4218 | DEBUGOUT("PHY Read Error\n"); |
| 4219 | return -E1000_ERR_PHY; |
| 4220 | } |
| 4221 | if (phy_data & MII_SR_AUTONEG_COMPLETE) { |
| 4222 | DEBUGOUT("Auto-Neg complete.\n"); |
| 4223 | return 0; |
| 4224 | } |
| 4225 | mdelay(100); |
| 4226 | } |
| 4227 | DEBUGOUT("Auto-Neg timedout.\n"); |
| 4228 | return -E1000_ERR_TIMEOUT; |
| 4229 | } |
| 4230 | |
| 4231 | /****************************************************************************** |
| 4232 | * Raises the Management Data Clock |
| 4233 | * |
| 4234 | * hw - Struct containing variables accessed by shared code |
| 4235 | * ctrl - Device control register's current value |
| 4236 | ******************************************************************************/ |
| 4237 | static void |
| 4238 | e1000_raise_mdi_clk(struct e1000_hw *hw, uint32_t * ctrl) |
| 4239 | { |
| 4240 | /* Raise the clock input to the Management Data Clock (by setting the MDC |
| 4241 | * bit), and then delay 2 microseconds. |
| 4242 | */ |
| 4243 | E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC)); |
| 4244 | E1000_WRITE_FLUSH(hw); |
| 4245 | udelay(2); |
| 4246 | } |
| 4247 | |
| 4248 | /****************************************************************************** |
| 4249 | * Lowers the Management Data Clock |
| 4250 | * |
| 4251 | * hw - Struct containing variables accessed by shared code |
| 4252 | * ctrl - Device control register's current value |
| 4253 | ******************************************************************************/ |
| 4254 | static void |
| 4255 | e1000_lower_mdi_clk(struct e1000_hw *hw, uint32_t * ctrl) |
| 4256 | { |
| 4257 | /* Lower the clock input to the Management Data Clock (by clearing the MDC |
| 4258 | * bit), and then delay 2 microseconds. |
| 4259 | */ |
| 4260 | E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC)); |
| 4261 | E1000_WRITE_FLUSH(hw); |
| 4262 | udelay(2); |
| 4263 | } |
| 4264 | |
| 4265 | /****************************************************************************** |
| 4266 | * Shifts data bits out to the PHY |
| 4267 | * |
| 4268 | * hw - Struct containing variables accessed by shared code |
| 4269 | * data - Data to send out to the PHY |
| 4270 | * count - Number of bits to shift out |
| 4271 | * |
| 4272 | * Bits are shifted out in MSB to LSB order. |
| 4273 | ******************************************************************************/ |
| 4274 | static void |
| 4275 | e1000_shift_out_mdi_bits(struct e1000_hw *hw, uint32_t data, uint16_t count) |
| 4276 | { |
| 4277 | uint32_t ctrl; |
| 4278 | uint32_t mask; |
| 4279 | |
| 4280 | /* We need to shift "count" number of bits out to the PHY. So, the value |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 4281 | * in the "data" parameter will be shifted out to the PHY one bit at a |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4282 | * time. In order to do this, "data" must be broken down into bits. |
| 4283 | */ |
| 4284 | mask = 0x01; |
| 4285 | mask <<= (count - 1); |
| 4286 | |
| 4287 | ctrl = E1000_READ_REG(hw, CTRL); |
| 4288 | |
| 4289 | /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */ |
| 4290 | ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR); |
| 4291 | |
| 4292 | while (mask) { |
| 4293 | /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and |
| 4294 | * then raising and lowering the Management Data Clock. A "0" is |
| 4295 | * shifted out to the PHY by setting the MDIO bit to "0" and then |
| 4296 | * raising and lowering the clock. |
| 4297 | */ |
| 4298 | if (data & mask) |
| 4299 | ctrl |= E1000_CTRL_MDIO; |
| 4300 | else |
| 4301 | ctrl &= ~E1000_CTRL_MDIO; |
| 4302 | |
| 4303 | E1000_WRITE_REG(hw, CTRL, ctrl); |
| 4304 | E1000_WRITE_FLUSH(hw); |
| 4305 | |
| 4306 | udelay(2); |
| 4307 | |
| 4308 | e1000_raise_mdi_clk(hw, &ctrl); |
| 4309 | e1000_lower_mdi_clk(hw, &ctrl); |
| 4310 | |
| 4311 | mask = mask >> 1; |
| 4312 | } |
| 4313 | } |
| 4314 | |
| 4315 | /****************************************************************************** |
| 4316 | * Shifts data bits in from the PHY |
| 4317 | * |
| 4318 | * hw - Struct containing variables accessed by shared code |
| 4319 | * |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 4320 | * Bits are shifted in in MSB to LSB order. |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4321 | ******************************************************************************/ |
| 4322 | static uint16_t |
| 4323 | e1000_shift_in_mdi_bits(struct e1000_hw *hw) |
| 4324 | { |
| 4325 | uint32_t ctrl; |
| 4326 | uint16_t data = 0; |
| 4327 | uint8_t i; |
| 4328 | |
| 4329 | /* In order to read a register from the PHY, we need to shift in a total |
| 4330 | * of 18 bits from the PHY. The first two bit (turnaround) times are used |
| 4331 | * to avoid contention on the MDIO pin when a read operation is performed. |
| 4332 | * These two bits are ignored by us and thrown away. Bits are "shifted in" |
| 4333 | * by raising the input to the Management Data Clock (setting the MDC bit), |
| 4334 | * and then reading the value of the MDIO bit. |
| 4335 | */ |
| 4336 | ctrl = E1000_READ_REG(hw, CTRL); |
| 4337 | |
| 4338 | /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */ |
| 4339 | ctrl &= ~E1000_CTRL_MDIO_DIR; |
| 4340 | ctrl &= ~E1000_CTRL_MDIO; |
| 4341 | |
| 4342 | E1000_WRITE_REG(hw, CTRL, ctrl); |
| 4343 | E1000_WRITE_FLUSH(hw); |
| 4344 | |
| 4345 | /* Raise and Lower the clock before reading in the data. This accounts for |
| 4346 | * the turnaround bits. The first clock occurred when we clocked out the |
| 4347 | * last bit of the Register Address. |
| 4348 | */ |
| 4349 | e1000_raise_mdi_clk(hw, &ctrl); |
| 4350 | e1000_lower_mdi_clk(hw, &ctrl); |
| 4351 | |
| 4352 | for (data = 0, i = 0; i < 16; i++) { |
| 4353 | data = data << 1; |
| 4354 | e1000_raise_mdi_clk(hw, &ctrl); |
| 4355 | ctrl = E1000_READ_REG(hw, CTRL); |
| 4356 | /* Check to see if we shifted in a "1". */ |
| 4357 | if (ctrl & E1000_CTRL_MDIO) |
| 4358 | data |= 1; |
| 4359 | e1000_lower_mdi_clk(hw, &ctrl); |
| 4360 | } |
| 4361 | |
| 4362 | e1000_raise_mdi_clk(hw, &ctrl); |
| 4363 | e1000_lower_mdi_clk(hw, &ctrl); |
| 4364 | |
| 4365 | return data; |
| 4366 | } |
| 4367 | |
| 4368 | /***************************************************************************** |
| 4369 | * Reads the value from a PHY register |
| 4370 | * |
| 4371 | * hw - Struct containing variables accessed by shared code |
| 4372 | * reg_addr - address of the PHY register to read |
| 4373 | ******************************************************************************/ |
| 4374 | static int |
| 4375 | e1000_read_phy_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t * phy_data) |
| 4376 | { |
| 4377 | uint32_t i; |
| 4378 | uint32_t mdic = 0; |
| 4379 | const uint32_t phy_addr = 1; |
| 4380 | |
| 4381 | if (reg_addr > MAX_PHY_REG_ADDRESS) { |
| 4382 | DEBUGOUT("PHY Address %d is out of range\n", reg_addr); |
| 4383 | return -E1000_ERR_PARAM; |
| 4384 | } |
| 4385 | |
| 4386 | if (hw->mac_type > e1000_82543) { |
| 4387 | /* Set up Op-code, Phy Address, and register address in the MDI |
| 4388 | * Control register. The MAC will take care of interfacing with the |
| 4389 | * PHY to retrieve the desired data. |
| 4390 | */ |
| 4391 | mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) | |
| 4392 | (phy_addr << E1000_MDIC_PHY_SHIFT) | |
| 4393 | (E1000_MDIC_OP_READ)); |
| 4394 | |
| 4395 | E1000_WRITE_REG(hw, MDIC, mdic); |
| 4396 | |
| 4397 | /* Poll the ready bit to see if the MDI read completed */ |
| 4398 | for (i = 0; i < 64; i++) { |
| 4399 | udelay(10); |
| 4400 | mdic = E1000_READ_REG(hw, MDIC); |
| 4401 | if (mdic & E1000_MDIC_READY) |
| 4402 | break; |
| 4403 | } |
| 4404 | if (!(mdic & E1000_MDIC_READY)) { |
| 4405 | DEBUGOUT("MDI Read did not complete\n"); |
| 4406 | return -E1000_ERR_PHY; |
| 4407 | } |
| 4408 | if (mdic & E1000_MDIC_ERROR) { |
| 4409 | DEBUGOUT("MDI Error\n"); |
| 4410 | return -E1000_ERR_PHY; |
| 4411 | } |
| 4412 | *phy_data = (uint16_t) mdic; |
| 4413 | } else { |
| 4414 | /* We must first send a preamble through the MDIO pin to signal the |
| 4415 | * beginning of an MII instruction. This is done by sending 32 |
| 4416 | * consecutive "1" bits. |
| 4417 | */ |
| 4418 | e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE); |
| 4419 | |
| 4420 | /* Now combine the next few fields that are required for a read |
| 4421 | * operation. We use this method instead of calling the |
| 4422 | * e1000_shift_out_mdi_bits routine five different times. The format of |
| 4423 | * a MII read instruction consists of a shift out of 14 bits and is |
| 4424 | * defined as follows: |
| 4425 | * <Preamble><SOF><Op Code><Phy Addr><Reg Addr> |
| 4426 | * followed by a shift in of 18 bits. This first two bits shifted in |
| 4427 | * are TurnAround bits used to avoid contention on the MDIO pin when a |
| 4428 | * READ operation is performed. These two bits are thrown away |
| 4429 | * followed by a shift in of 16 bits which contains the desired data. |
| 4430 | */ |
| 4431 | mdic = ((reg_addr) | (phy_addr << 5) | |
| 4432 | (PHY_OP_READ << 10) | (PHY_SOF << 12)); |
| 4433 | |
| 4434 | e1000_shift_out_mdi_bits(hw, mdic, 14); |
| 4435 | |
| 4436 | /* Now that we've shifted out the read command to the MII, we need to |
| 4437 | * "shift in" the 16-bit value (18 total bits) of the requested PHY |
| 4438 | * register address. |
| 4439 | */ |
| 4440 | *phy_data = e1000_shift_in_mdi_bits(hw); |
| 4441 | } |
| 4442 | return 0; |
| 4443 | } |
| 4444 | |
| 4445 | /****************************************************************************** |
| 4446 | * Writes a value to a PHY register |
| 4447 | * |
| 4448 | * hw - Struct containing variables accessed by shared code |
| 4449 | * reg_addr - address of the PHY register to write |
| 4450 | * data - data to write to the PHY |
| 4451 | ******************************************************************************/ |
| 4452 | static int |
| 4453 | e1000_write_phy_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t phy_data) |
| 4454 | { |
| 4455 | uint32_t i; |
| 4456 | uint32_t mdic = 0; |
| 4457 | const uint32_t phy_addr = 1; |
| 4458 | |
| 4459 | if (reg_addr > MAX_PHY_REG_ADDRESS) { |
| 4460 | DEBUGOUT("PHY Address %d is out of range\n", reg_addr); |
| 4461 | return -E1000_ERR_PARAM; |
| 4462 | } |
| 4463 | |
| 4464 | if (hw->mac_type > e1000_82543) { |
| 4465 | /* Set up Op-code, Phy Address, register address, and data intended |
| 4466 | * for the PHY register in the MDI Control register. The MAC will take |
| 4467 | * care of interfacing with the PHY to send the desired data. |
| 4468 | */ |
| 4469 | mdic = (((uint32_t) phy_data) | |
| 4470 | (reg_addr << E1000_MDIC_REG_SHIFT) | |
| 4471 | (phy_addr << E1000_MDIC_PHY_SHIFT) | |
| 4472 | (E1000_MDIC_OP_WRITE)); |
| 4473 | |
| 4474 | E1000_WRITE_REG(hw, MDIC, mdic); |
| 4475 | |
| 4476 | /* Poll the ready bit to see if the MDI read completed */ |
| 4477 | for (i = 0; i < 64; i++) { |
| 4478 | udelay(10); |
| 4479 | mdic = E1000_READ_REG(hw, MDIC); |
| 4480 | if (mdic & E1000_MDIC_READY) |
| 4481 | break; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4482 | } |
| 4483 | if (!(mdic & E1000_MDIC_READY)) { |
| 4484 | DEBUGOUT("MDI Write did not complete\n"); |
| 4485 | return -E1000_ERR_PHY; |
| 4486 | } |
| 4487 | } else { |
| 4488 | /* We'll need to use the SW defined pins to shift the write command |
| 4489 | * out to the PHY. We first send a preamble to the PHY to signal the |
| 4490 | * beginning of the MII instruction. This is done by sending 32 |
| 4491 | * consecutive "1" bits. |
| 4492 | */ |
| 4493 | e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE); |
| 4494 | |
| 4495 | /* Now combine the remaining required fields that will indicate a |
| 4496 | * write operation. We use this method instead of calling the |
| 4497 | * e1000_shift_out_mdi_bits routine for each field in the command. The |
| 4498 | * format of a MII write instruction is as follows: |
| 4499 | * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>. |
| 4500 | */ |
| 4501 | mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) | |
| 4502 | (PHY_OP_WRITE << 12) | (PHY_SOF << 14)); |
| 4503 | mdic <<= 16; |
| 4504 | mdic |= (uint32_t) phy_data; |
| 4505 | |
| 4506 | e1000_shift_out_mdi_bits(hw, mdic, 32); |
| 4507 | } |
| 4508 | return 0; |
| 4509 | } |
| 4510 | |
| 4511 | /****************************************************************************** |
| 4512 | * Checks if PHY reset is blocked due to SOL/IDER session, for example. |
| 4513 | * Returning E1000_BLK_PHY_RESET isn't necessarily an error. But it's up to |
| 4514 | * the caller to figure out how to deal with it. |
| 4515 | * |
| 4516 | * hw - Struct containing variables accessed by shared code |
| 4517 | * |
| 4518 | * returns: - E1000_BLK_PHY_RESET |
| 4519 | * E1000_SUCCESS |
| 4520 | * |
| 4521 | *****************************************************************************/ |
| 4522 | int32_t |
| 4523 | e1000_check_phy_reset_block(struct e1000_hw *hw) |
| 4524 | { |
| 4525 | uint32_t manc = 0; |
| 4526 | uint32_t fwsm = 0; |
| 4527 | |
| 4528 | if (hw->mac_type == e1000_ich8lan) { |
| 4529 | fwsm = E1000_READ_REG(hw, FWSM); |
| 4530 | return (fwsm & E1000_FWSM_RSPCIPHY) ? E1000_SUCCESS |
| 4531 | : E1000_BLK_PHY_RESET; |
| 4532 | } |
| 4533 | |
| 4534 | if (hw->mac_type > e1000_82547_rev_2) |
| 4535 | manc = E1000_READ_REG(hw, MANC); |
| 4536 | return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ? |
| 4537 | E1000_BLK_PHY_RESET : E1000_SUCCESS; |
| 4538 | } |
| 4539 | |
| 4540 | /*************************************************************************** |
| 4541 | * Checks if the PHY configuration is done |
| 4542 | * |
| 4543 | * hw: Struct containing variables accessed by shared code |
| 4544 | * |
| 4545 | * returns: - E1000_ERR_RESET if fail to reset MAC |
| 4546 | * E1000_SUCCESS at any other case. |
| 4547 | * |
| 4548 | ***************************************************************************/ |
| 4549 | static int32_t |
| 4550 | e1000_get_phy_cfg_done(struct e1000_hw *hw) |
| 4551 | { |
| 4552 | int32_t timeout = PHY_CFG_TIMEOUT; |
| 4553 | uint32_t cfg_mask = E1000_EEPROM_CFG_DONE; |
| 4554 | |
| 4555 | DEBUGFUNC(); |
| 4556 | |
| 4557 | switch (hw->mac_type) { |
| 4558 | default: |
| 4559 | mdelay(10); |
| 4560 | break; |
Kyle Moffett | 7376f8d | 2010-09-13 05:52:22 +0000 | [diff] [blame] | 4561 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4562 | case e1000_80003es2lan: |
| 4563 | /* Separate *_CFG_DONE_* bit for each port */ |
Kyle Moffett | 7376f8d | 2010-09-13 05:52:22 +0000 | [diff] [blame] | 4564 | if (e1000_is_second_port(hw)) |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4565 | cfg_mask = E1000_EEPROM_CFG_DONE_PORT_1; |
Kyle Moffett | 7376f8d | 2010-09-13 05:52:22 +0000 | [diff] [blame] | 4566 | /* Fall Through */ |
| 4567 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4568 | case e1000_82571: |
| 4569 | case e1000_82572: |
Marek Vasut | 74a13c2 | 2014-08-08 07:41:39 -0700 | [diff] [blame] | 4570 | case e1000_igb: |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4571 | while (timeout) { |
Marek Vasut | 74a13c2 | 2014-08-08 07:41:39 -0700 | [diff] [blame] | 4572 | if (hw->mac_type == e1000_igb) { |
| 4573 | if (E1000_READ_REG(hw, I210_EEMNGCTL) & cfg_mask) |
| 4574 | break; |
| 4575 | } else { |
| 4576 | if (E1000_READ_REG(hw, EEMNGCTL) & cfg_mask) |
| 4577 | break; |
| 4578 | } |
| 4579 | mdelay(1); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4580 | timeout--; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4581 | } |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4582 | if (!timeout) { |
| 4583 | DEBUGOUT("MNG configuration cycle has not " |
| 4584 | "completed.\n"); |
| 4585 | return -E1000_ERR_RESET; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4586 | } |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4587 | break; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4588 | } |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4589 | |
| 4590 | return E1000_SUCCESS; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4591 | } |
| 4592 | |
| 4593 | /****************************************************************************** |
| 4594 | * Returns the PHY to the power-on reset state |
| 4595 | * |
| 4596 | * hw - Struct containing variables accessed by shared code |
| 4597 | ******************************************************************************/ |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4598 | int32_t |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4599 | e1000_phy_hw_reset(struct e1000_hw *hw) |
| 4600 | { |
Kyle Moffett | 7376f8d | 2010-09-13 05:52:22 +0000 | [diff] [blame] | 4601 | uint16_t swfw = E1000_SWFW_PHY0_SM; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4602 | uint32_t ctrl, ctrl_ext; |
| 4603 | uint32_t led_ctrl; |
| 4604 | int32_t ret_val; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4605 | |
| 4606 | DEBUGFUNC(); |
| 4607 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4608 | /* In the case of the phy reset being blocked, it's not an error, we |
| 4609 | * simply return success without performing the reset. */ |
| 4610 | ret_val = e1000_check_phy_reset_block(hw); |
| 4611 | if (ret_val) |
| 4612 | return E1000_SUCCESS; |
| 4613 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4614 | DEBUGOUT("Resetting Phy...\n"); |
| 4615 | |
| 4616 | if (hw->mac_type > e1000_82543) { |
Kyle Moffett | 7376f8d | 2010-09-13 05:52:22 +0000 | [diff] [blame] | 4617 | if (e1000_is_second_port(hw)) |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4618 | swfw = E1000_SWFW_PHY1_SM; |
Kyle Moffett | 7376f8d | 2010-09-13 05:52:22 +0000 | [diff] [blame] | 4619 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4620 | if (e1000_swfw_sync_acquire(hw, swfw)) { |
| 4621 | DEBUGOUT("Unable to acquire swfw sync\n"); |
| 4622 | return -E1000_ERR_SWFW_SYNC; |
| 4623 | } |
Kyle Moffett | 7376f8d | 2010-09-13 05:52:22 +0000 | [diff] [blame] | 4624 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4625 | /* Read the device control register and assert the E1000_CTRL_PHY_RST |
| 4626 | * bit. Then, take it out of reset. |
| 4627 | */ |
| 4628 | ctrl = E1000_READ_REG(hw, CTRL); |
| 4629 | E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PHY_RST); |
| 4630 | E1000_WRITE_FLUSH(hw); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4631 | |
| 4632 | if (hw->mac_type < e1000_82571) |
| 4633 | udelay(10); |
| 4634 | else |
| 4635 | udelay(100); |
| 4636 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4637 | E1000_WRITE_REG(hw, CTRL, ctrl); |
| 4638 | E1000_WRITE_FLUSH(hw); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4639 | |
| 4640 | if (hw->mac_type >= e1000_82571) |
| 4641 | mdelay(10); |
Tim Harvey | dca3565 | 2015-05-19 10:01:19 -0700 | [diff] [blame] | 4642 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4643 | } else { |
| 4644 | /* Read the Extended Device Control Register, assert the PHY_RESET_DIR |
| 4645 | * bit to put the PHY into reset. Then, take it out of reset. |
| 4646 | */ |
| 4647 | ctrl_ext = E1000_READ_REG(hw, CTRL_EXT); |
| 4648 | ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR; |
| 4649 | ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA; |
| 4650 | E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext); |
| 4651 | E1000_WRITE_FLUSH(hw); |
| 4652 | mdelay(10); |
| 4653 | ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA; |
| 4654 | E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext); |
| 4655 | E1000_WRITE_FLUSH(hw); |
| 4656 | } |
| 4657 | udelay(150); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4658 | |
| 4659 | if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) { |
| 4660 | /* Configure activity LED after PHY reset */ |
| 4661 | led_ctrl = E1000_READ_REG(hw, LEDCTL); |
| 4662 | led_ctrl &= IGP_ACTIVITY_LED_MASK; |
| 4663 | led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE); |
| 4664 | E1000_WRITE_REG(hw, LEDCTL, led_ctrl); |
| 4665 | } |
| 4666 | |
Tim Harvey | 5cb59ec | 2015-05-19 10:01:18 -0700 | [diff] [blame] | 4667 | e1000_swfw_sync_release(hw, swfw); |
| 4668 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4669 | /* Wait for FW to finish PHY configuration. */ |
| 4670 | ret_val = e1000_get_phy_cfg_done(hw); |
| 4671 | if (ret_val != E1000_SUCCESS) |
| 4672 | return ret_val; |
| 4673 | |
| 4674 | return ret_val; |
| 4675 | } |
| 4676 | |
| 4677 | /****************************************************************************** |
| 4678 | * IGP phy init script - initializes the GbE PHY |
| 4679 | * |
| 4680 | * hw - Struct containing variables accessed by shared code |
| 4681 | *****************************************************************************/ |
| 4682 | static void |
| 4683 | e1000_phy_init_script(struct e1000_hw *hw) |
| 4684 | { |
| 4685 | uint32_t ret_val; |
| 4686 | uint16_t phy_saved_data; |
| 4687 | DEBUGFUNC(); |
| 4688 | |
| 4689 | if (hw->phy_init_script) { |
| 4690 | mdelay(20); |
| 4691 | |
| 4692 | /* Save off the current value of register 0x2F5B to be |
| 4693 | * restored at the end of this routine. */ |
| 4694 | ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data); |
| 4695 | |
| 4696 | /* Disabled the PHY transmitter */ |
| 4697 | e1000_write_phy_reg(hw, 0x2F5B, 0x0003); |
| 4698 | |
| 4699 | mdelay(20); |
| 4700 | |
| 4701 | e1000_write_phy_reg(hw, 0x0000, 0x0140); |
| 4702 | |
| 4703 | mdelay(5); |
| 4704 | |
| 4705 | switch (hw->mac_type) { |
| 4706 | case e1000_82541: |
| 4707 | case e1000_82547: |
| 4708 | e1000_write_phy_reg(hw, 0x1F95, 0x0001); |
| 4709 | |
| 4710 | e1000_write_phy_reg(hw, 0x1F71, 0xBD21); |
| 4711 | |
| 4712 | e1000_write_phy_reg(hw, 0x1F79, 0x0018); |
| 4713 | |
| 4714 | e1000_write_phy_reg(hw, 0x1F30, 0x1600); |
| 4715 | |
| 4716 | e1000_write_phy_reg(hw, 0x1F31, 0x0014); |
| 4717 | |
| 4718 | e1000_write_phy_reg(hw, 0x1F32, 0x161C); |
| 4719 | |
| 4720 | e1000_write_phy_reg(hw, 0x1F94, 0x0003); |
| 4721 | |
| 4722 | e1000_write_phy_reg(hw, 0x1F96, 0x003F); |
| 4723 | |
| 4724 | e1000_write_phy_reg(hw, 0x2010, 0x0008); |
| 4725 | break; |
| 4726 | |
| 4727 | case e1000_82541_rev_2: |
| 4728 | case e1000_82547_rev_2: |
| 4729 | e1000_write_phy_reg(hw, 0x1F73, 0x0099); |
| 4730 | break; |
| 4731 | default: |
| 4732 | break; |
| 4733 | } |
| 4734 | |
| 4735 | e1000_write_phy_reg(hw, 0x0000, 0x3300); |
| 4736 | |
| 4737 | mdelay(20); |
| 4738 | |
| 4739 | /* Now enable the transmitter */ |
Zang Roy-R61911 | e36d67c | 2011-11-06 22:22:36 +0000 | [diff] [blame] | 4740 | if (!ret_val) |
| 4741 | e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4742 | |
| 4743 | if (hw->mac_type == e1000_82547) { |
| 4744 | uint16_t fused, fine, coarse; |
| 4745 | |
| 4746 | /* Move to analog registers page */ |
| 4747 | e1000_read_phy_reg(hw, |
| 4748 | IGP01E1000_ANALOG_SPARE_FUSE_STATUS, &fused); |
| 4749 | |
| 4750 | if (!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) { |
| 4751 | e1000_read_phy_reg(hw, |
| 4752 | IGP01E1000_ANALOG_FUSE_STATUS, &fused); |
| 4753 | |
| 4754 | fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK; |
| 4755 | coarse = fused |
| 4756 | & IGP01E1000_ANALOG_FUSE_COARSE_MASK; |
| 4757 | |
| 4758 | if (coarse > |
| 4759 | IGP01E1000_ANALOG_FUSE_COARSE_THRESH) { |
| 4760 | coarse -= |
| 4761 | IGP01E1000_ANALOG_FUSE_COARSE_10; |
| 4762 | fine -= IGP01E1000_ANALOG_FUSE_FINE_1; |
| 4763 | } else if (coarse |
| 4764 | == IGP01E1000_ANALOG_FUSE_COARSE_THRESH) |
| 4765 | fine -= IGP01E1000_ANALOG_FUSE_FINE_10; |
| 4766 | |
| 4767 | fused = (fused |
| 4768 | & IGP01E1000_ANALOG_FUSE_POLY_MASK) | |
| 4769 | (fine |
| 4770 | & IGP01E1000_ANALOG_FUSE_FINE_MASK) | |
| 4771 | (coarse |
| 4772 | & IGP01E1000_ANALOG_FUSE_COARSE_MASK); |
| 4773 | |
| 4774 | e1000_write_phy_reg(hw, |
| 4775 | IGP01E1000_ANALOG_FUSE_CONTROL, fused); |
| 4776 | e1000_write_phy_reg(hw, |
| 4777 | IGP01E1000_ANALOG_FUSE_BYPASS, |
| 4778 | IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL); |
| 4779 | } |
| 4780 | } |
| 4781 | } |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4782 | } |
| 4783 | |
| 4784 | /****************************************************************************** |
| 4785 | * Resets the PHY |
| 4786 | * |
| 4787 | * hw - Struct containing variables accessed by shared code |
| 4788 | * |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4789 | * Sets bit 15 of the MII Control register |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4790 | ******************************************************************************/ |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4791 | int32_t |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4792 | e1000_phy_reset(struct e1000_hw *hw) |
| 4793 | { |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4794 | int32_t ret_val; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4795 | uint16_t phy_data; |
| 4796 | |
| 4797 | DEBUGFUNC(); |
| 4798 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4799 | /* In the case of the phy reset being blocked, it's not an error, we |
| 4800 | * simply return success without performing the reset. */ |
| 4801 | ret_val = e1000_check_phy_reset_block(hw); |
| 4802 | if (ret_val) |
| 4803 | return E1000_SUCCESS; |
| 4804 | |
| 4805 | switch (hw->phy_type) { |
| 4806 | case e1000_phy_igp: |
| 4807 | case e1000_phy_igp_2: |
| 4808 | case e1000_phy_igp_3: |
| 4809 | case e1000_phy_ife: |
Marek Vasut | 74a13c2 | 2014-08-08 07:41:39 -0700 | [diff] [blame] | 4810 | case e1000_phy_igb: |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4811 | ret_val = e1000_phy_hw_reset(hw); |
| 4812 | if (ret_val) |
| 4813 | return ret_val; |
| 4814 | break; |
| 4815 | default: |
| 4816 | ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data); |
| 4817 | if (ret_val) |
| 4818 | return ret_val; |
| 4819 | |
| 4820 | phy_data |= MII_CR_RESET; |
| 4821 | ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data); |
| 4822 | if (ret_val) |
| 4823 | return ret_val; |
| 4824 | |
| 4825 | udelay(1); |
| 4826 | break; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4827 | } |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4828 | |
| 4829 | if (hw->phy_type == e1000_phy_igp || hw->phy_type == e1000_phy_igp_2) |
| 4830 | e1000_phy_init_script(hw); |
| 4831 | |
| 4832 | return E1000_SUCCESS; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4833 | } |
| 4834 | |
Wolfgang Denk | 35f734f | 2008-04-13 09:59:26 -0700 | [diff] [blame] | 4835 | static int e1000_set_phy_type (struct e1000_hw *hw) |
Andre Schwarz | 68c2a30 | 2008-03-06 16:45:44 +0100 | [diff] [blame] | 4836 | { |
Wolfgang Denk | 35f734f | 2008-04-13 09:59:26 -0700 | [diff] [blame] | 4837 | DEBUGFUNC (); |
Andre Schwarz | 68c2a30 | 2008-03-06 16:45:44 +0100 | [diff] [blame] | 4838 | |
Wolfgang Denk | 35f734f | 2008-04-13 09:59:26 -0700 | [diff] [blame] | 4839 | if (hw->mac_type == e1000_undefined) |
| 4840 | return -E1000_ERR_PHY_TYPE; |
Andre Schwarz | 68c2a30 | 2008-03-06 16:45:44 +0100 | [diff] [blame] | 4841 | |
Wolfgang Denk | 35f734f | 2008-04-13 09:59:26 -0700 | [diff] [blame] | 4842 | switch (hw->phy_id) { |
| 4843 | case M88E1000_E_PHY_ID: |
| 4844 | case M88E1000_I_PHY_ID: |
| 4845 | case M88E1011_I_PHY_ID: |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4846 | case M88E1111_I_PHY_ID: |
Wolfgang Denk | 35f734f | 2008-04-13 09:59:26 -0700 | [diff] [blame] | 4847 | hw->phy_type = e1000_phy_m88; |
| 4848 | break; |
| 4849 | case IGP01E1000_I_PHY_ID: |
| 4850 | if (hw->mac_type == e1000_82541 || |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4851 | hw->mac_type == e1000_82541_rev_2 || |
| 4852 | hw->mac_type == e1000_82547 || |
| 4853 | hw->mac_type == e1000_82547_rev_2) { |
Wolfgang Denk | 35f734f | 2008-04-13 09:59:26 -0700 | [diff] [blame] | 4854 | hw->phy_type = e1000_phy_igp; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4855 | break; |
| 4856 | } |
| 4857 | case IGP03E1000_E_PHY_ID: |
| 4858 | hw->phy_type = e1000_phy_igp_3; |
| 4859 | break; |
| 4860 | case IFE_E_PHY_ID: |
| 4861 | case IFE_PLUS_E_PHY_ID: |
| 4862 | case IFE_C_E_PHY_ID: |
| 4863 | hw->phy_type = e1000_phy_ife; |
| 4864 | break; |
| 4865 | case GG82563_E_PHY_ID: |
| 4866 | if (hw->mac_type == e1000_80003es2lan) { |
| 4867 | hw->phy_type = e1000_phy_gg82563; |
Wolfgang Denk | 35f734f | 2008-04-13 09:59:26 -0700 | [diff] [blame] | 4868 | break; |
| 4869 | } |
Roy Zang | 181119b | 2011-01-21 11:29:38 +0800 | [diff] [blame] | 4870 | case BME1000_E_PHY_ID: |
| 4871 | hw->phy_type = e1000_phy_bm; |
| 4872 | break; |
Marek Vasut | 74a13c2 | 2014-08-08 07:41:39 -0700 | [diff] [blame] | 4873 | case I210_I_PHY_ID: |
| 4874 | hw->phy_type = e1000_phy_igb; |
| 4875 | break; |
Wolfgang Denk | 35f734f | 2008-04-13 09:59:26 -0700 | [diff] [blame] | 4876 | /* Fall Through */ |
| 4877 | default: |
| 4878 | /* Should never have loaded on this device */ |
| 4879 | hw->phy_type = e1000_phy_undefined; |
| 4880 | return -E1000_ERR_PHY_TYPE; |
| 4881 | } |
Andre Schwarz | 68c2a30 | 2008-03-06 16:45:44 +0100 | [diff] [blame] | 4882 | |
Wolfgang Denk | 35f734f | 2008-04-13 09:59:26 -0700 | [diff] [blame] | 4883 | return E1000_SUCCESS; |
Andre Schwarz | 68c2a30 | 2008-03-06 16:45:44 +0100 | [diff] [blame] | 4884 | } |
| 4885 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4886 | /****************************************************************************** |
| 4887 | * Probes the expected PHY address for known PHY IDs |
| 4888 | * |
| 4889 | * hw - Struct containing variables accessed by shared code |
| 4890 | ******************************************************************************/ |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4891 | static int32_t |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4892 | e1000_detect_gig_phy(struct e1000_hw *hw) |
| 4893 | { |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4894 | int32_t phy_init_status, ret_val; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4895 | uint16_t phy_id_high, phy_id_low; |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 4896 | bool match = false; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4897 | |
| 4898 | DEBUGFUNC(); |
| 4899 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4900 | /* The 82571 firmware may still be configuring the PHY. In this |
| 4901 | * case, we cannot access the PHY until the configuration is done. So |
| 4902 | * we explicitly set the PHY values. */ |
| 4903 | if (hw->mac_type == e1000_82571 || |
| 4904 | hw->mac_type == e1000_82572) { |
| 4905 | hw->phy_id = IGP01E1000_I_PHY_ID; |
| 4906 | hw->phy_type = e1000_phy_igp_2; |
| 4907 | return E1000_SUCCESS; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4908 | } |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4909 | |
| 4910 | /* ESB-2 PHY reads require e1000_phy_gg82563 to be set because of a |
| 4911 | * work- around that forces PHY page 0 to be set or the reads fail. |
| 4912 | * The rest of the code in this routine uses e1000_read_phy_reg to |
| 4913 | * read the PHY ID. So for ESB-2 we need to have this set so our |
| 4914 | * reads won't fail. If the attached PHY is not a e1000_phy_gg82563, |
| 4915 | * the routines below will figure this out as well. */ |
| 4916 | if (hw->mac_type == e1000_80003es2lan) |
| 4917 | hw->phy_type = e1000_phy_gg82563; |
| 4918 | |
| 4919 | /* Read the PHY ID Registers to identify which PHY is onboard. */ |
| 4920 | ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high); |
| 4921 | if (ret_val) |
| 4922 | return ret_val; |
| 4923 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4924 | hw->phy_id = (uint32_t) (phy_id_high << 16); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4925 | udelay(20); |
| 4926 | ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low); |
| 4927 | if (ret_val) |
| 4928 | return ret_val; |
| 4929 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4930 | hw->phy_id |= (uint32_t) (phy_id_low & PHY_REVISION_MASK); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4931 | hw->phy_revision = (uint32_t) phy_id_low & ~PHY_REVISION_MASK; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4932 | |
| 4933 | switch (hw->mac_type) { |
| 4934 | case e1000_82543: |
| 4935 | if (hw->phy_id == M88E1000_E_PHY_ID) |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 4936 | match = true; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4937 | break; |
| 4938 | case e1000_82544: |
| 4939 | if (hw->phy_id == M88E1000_I_PHY_ID) |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 4940 | match = true; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4941 | break; |
| 4942 | case e1000_82540: |
| 4943 | case e1000_82545: |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4944 | case e1000_82545_rev_3: |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4945 | case e1000_82546: |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4946 | case e1000_82546_rev_3: |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4947 | if (hw->phy_id == M88E1011_I_PHY_ID) |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 4948 | match = true; |
Andre Schwarz | 68c2a30 | 2008-03-06 16:45:44 +0100 | [diff] [blame] | 4949 | break; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4950 | case e1000_82541: |
Andre Schwarz | 68c2a30 | 2008-03-06 16:45:44 +0100 | [diff] [blame] | 4951 | case e1000_82541_rev_2: |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4952 | case e1000_82547: |
| 4953 | case e1000_82547_rev_2: |
Andre Schwarz | 68c2a30 | 2008-03-06 16:45:44 +0100 | [diff] [blame] | 4954 | if(hw->phy_id == IGP01E1000_I_PHY_ID) |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 4955 | match = true; |
Andre Schwarz | 68c2a30 | 2008-03-06 16:45:44 +0100 | [diff] [blame] | 4956 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4957 | break; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4958 | case e1000_82573: |
| 4959 | if (hw->phy_id == M88E1111_I_PHY_ID) |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 4960 | match = true; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4961 | break; |
Roy Zang | 181119b | 2011-01-21 11:29:38 +0800 | [diff] [blame] | 4962 | case e1000_82574: |
| 4963 | if (hw->phy_id == BME1000_E_PHY_ID) |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 4964 | match = true; |
Roy Zang | 181119b | 2011-01-21 11:29:38 +0800 | [diff] [blame] | 4965 | break; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4966 | case e1000_80003es2lan: |
| 4967 | if (hw->phy_id == GG82563_E_PHY_ID) |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 4968 | match = true; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4969 | break; |
| 4970 | case e1000_ich8lan: |
| 4971 | if (hw->phy_id == IGP03E1000_E_PHY_ID) |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 4972 | match = true; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4973 | if (hw->phy_id == IFE_E_PHY_ID) |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 4974 | match = true; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4975 | if (hw->phy_id == IFE_PLUS_E_PHY_ID) |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 4976 | match = true; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4977 | if (hw->phy_id == IFE_C_E_PHY_ID) |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 4978 | match = true; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4979 | break; |
Marek Vasut | 74a13c2 | 2014-08-08 07:41:39 -0700 | [diff] [blame] | 4980 | case e1000_igb: |
| 4981 | if (hw->phy_id == I210_I_PHY_ID) |
| 4982 | match = true; |
| 4983 | break; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4984 | default: |
| 4985 | DEBUGOUT("Invalid MAC type %d\n", hw->mac_type); |
| 4986 | return -E1000_ERR_CONFIG; |
| 4987 | } |
Andre Schwarz | 68c2a30 | 2008-03-06 16:45:44 +0100 | [diff] [blame] | 4988 | |
| 4989 | phy_init_status = e1000_set_phy_type(hw); |
| 4990 | |
| 4991 | if ((match) && (phy_init_status == E1000_SUCCESS)) { |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 4992 | DEBUGOUT("PHY ID 0x%X detected\n", hw->phy_id); |
| 4993 | return 0; |
| 4994 | } |
| 4995 | DEBUGOUT("Invalid PHY ID 0x%X\n", hw->phy_id); |
| 4996 | return -E1000_ERR_PHY; |
| 4997 | } |
| 4998 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 4999 | /***************************************************************************** |
| 5000 | * Set media type and TBI compatibility. |
| 5001 | * |
| 5002 | * hw - Struct containing variables accessed by shared code |
| 5003 | * **************************************************************************/ |
| 5004 | void |
| 5005 | e1000_set_media_type(struct e1000_hw *hw) |
| 5006 | { |
| 5007 | uint32_t status; |
| 5008 | |
| 5009 | DEBUGFUNC(); |
| 5010 | |
| 5011 | if (hw->mac_type != e1000_82543) { |
| 5012 | /* tbi_compatibility is only valid on 82543 */ |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 5013 | hw->tbi_compatibility_en = false; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 5014 | } |
| 5015 | |
| 5016 | switch (hw->device_id) { |
| 5017 | case E1000_DEV_ID_82545GM_SERDES: |
| 5018 | case E1000_DEV_ID_82546GB_SERDES: |
| 5019 | case E1000_DEV_ID_82571EB_SERDES: |
| 5020 | case E1000_DEV_ID_82571EB_SERDES_DUAL: |
| 5021 | case E1000_DEV_ID_82571EB_SERDES_QUAD: |
| 5022 | case E1000_DEV_ID_82572EI_SERDES: |
| 5023 | case E1000_DEV_ID_80003ES2LAN_SERDES_DPT: |
| 5024 | hw->media_type = e1000_media_type_internal_serdes; |
| 5025 | break; |
| 5026 | default: |
| 5027 | switch (hw->mac_type) { |
| 5028 | case e1000_82542_rev2_0: |
| 5029 | case e1000_82542_rev2_1: |
| 5030 | hw->media_type = e1000_media_type_fiber; |
| 5031 | break; |
| 5032 | case e1000_ich8lan: |
| 5033 | case e1000_82573: |
Roy Zang | 181119b | 2011-01-21 11:29:38 +0800 | [diff] [blame] | 5034 | case e1000_82574: |
Marek Vasut | 74a13c2 | 2014-08-08 07:41:39 -0700 | [diff] [blame] | 5035 | case e1000_igb: |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 5036 | /* The STATUS_TBIMODE bit is reserved or reused |
| 5037 | * for the this device. |
| 5038 | */ |
| 5039 | hw->media_type = e1000_media_type_copper; |
| 5040 | break; |
| 5041 | default: |
| 5042 | status = E1000_READ_REG(hw, STATUS); |
| 5043 | if (status & E1000_STATUS_TBIMODE) { |
| 5044 | hw->media_type = e1000_media_type_fiber; |
| 5045 | /* tbi_compatibility not valid on fiber */ |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 5046 | hw->tbi_compatibility_en = false; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 5047 | } else { |
| 5048 | hw->media_type = e1000_media_type_copper; |
| 5049 | } |
| 5050 | break; |
| 5051 | } |
| 5052 | } |
| 5053 | } |
| 5054 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5055 | /** |
| 5056 | * e1000_sw_init - Initialize general software structures (struct e1000_adapter) |
| 5057 | * |
| 5058 | * e1000_sw_init initializes the Adapter private data structure. |
| 5059 | * Fields are initialized based on PCI device information and |
| 5060 | * OS network device settings (MTU size). |
| 5061 | **/ |
| 5062 | |
| 5063 | static int |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 5064 | e1000_sw_init(struct e1000_hw *hw) |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5065 | { |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5066 | int result; |
| 5067 | |
| 5068 | /* PCI config space info */ |
Bin Meng | 83cf24c | 2016-02-02 05:58:01 -0800 | [diff] [blame] | 5069 | #ifdef CONFIG_DM_ETH |
| 5070 | dm_pci_read_config16(hw->pdev, PCI_VENDOR_ID, &hw->vendor_id); |
| 5071 | dm_pci_read_config16(hw->pdev, PCI_DEVICE_ID, &hw->device_id); |
| 5072 | dm_pci_read_config16(hw->pdev, PCI_SUBSYSTEM_VENDOR_ID, |
| 5073 | &hw->subsystem_vendor_id); |
| 5074 | dm_pci_read_config16(hw->pdev, PCI_SUBSYSTEM_ID, &hw->subsystem_id); |
| 5075 | |
| 5076 | dm_pci_read_config8(hw->pdev, PCI_REVISION_ID, &hw->revision_id); |
| 5077 | dm_pci_read_config16(hw->pdev, PCI_COMMAND, &hw->pci_cmd_word); |
| 5078 | #else |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5079 | pci_read_config_word(hw->pdev, PCI_VENDOR_ID, &hw->vendor_id); |
| 5080 | pci_read_config_word(hw->pdev, PCI_DEVICE_ID, &hw->device_id); |
| 5081 | pci_read_config_word(hw->pdev, PCI_SUBSYSTEM_VENDOR_ID, |
| 5082 | &hw->subsystem_vendor_id); |
| 5083 | pci_read_config_word(hw->pdev, PCI_SUBSYSTEM_ID, &hw->subsystem_id); |
| 5084 | |
| 5085 | pci_read_config_byte(hw->pdev, PCI_REVISION_ID, &hw->revision_id); |
| 5086 | pci_read_config_word(hw->pdev, PCI_COMMAND, &hw->pci_cmd_word); |
Bin Meng | 83cf24c | 2016-02-02 05:58:01 -0800 | [diff] [blame] | 5087 | #endif |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5088 | |
| 5089 | /* identify the MAC */ |
| 5090 | result = e1000_set_mac_type(hw); |
| 5091 | if (result) { |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 5092 | E1000_ERR(hw, "Unknown MAC Type\n"); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5093 | return result; |
| 5094 | } |
| 5095 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 5096 | switch (hw->mac_type) { |
| 5097 | default: |
| 5098 | break; |
| 5099 | case e1000_82541: |
| 5100 | case e1000_82547: |
| 5101 | case e1000_82541_rev_2: |
| 5102 | case e1000_82547_rev_2: |
| 5103 | hw->phy_init_script = 1; |
| 5104 | break; |
| 5105 | } |
| 5106 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5107 | /* flow control settings */ |
| 5108 | hw->fc_high_water = E1000_FC_HIGH_THRESH; |
| 5109 | hw->fc_low_water = E1000_FC_LOW_THRESH; |
| 5110 | hw->fc_pause_time = E1000_FC_PAUSE_TIME; |
| 5111 | hw->fc_send_xon = 1; |
| 5112 | |
| 5113 | /* Media type - copper or fiber */ |
Marek Vasut | 74a13c2 | 2014-08-08 07:41:39 -0700 | [diff] [blame] | 5114 | hw->tbi_compatibility_en = true; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 5115 | e1000_set_media_type(hw); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5116 | |
| 5117 | if (hw->mac_type >= e1000_82543) { |
| 5118 | uint32_t status = E1000_READ_REG(hw, STATUS); |
| 5119 | |
| 5120 | if (status & E1000_STATUS_TBIMODE) { |
| 5121 | DEBUGOUT("fiber interface\n"); |
| 5122 | hw->media_type = e1000_media_type_fiber; |
| 5123 | } else { |
| 5124 | DEBUGOUT("copper interface\n"); |
| 5125 | hw->media_type = e1000_media_type_copper; |
| 5126 | } |
| 5127 | } else { |
| 5128 | hw->media_type = e1000_media_type_fiber; |
| 5129 | } |
| 5130 | |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 5131 | hw->wait_autoneg_complete = true; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5132 | if (hw->mac_type < e1000_82543) |
| 5133 | hw->report_tx_early = 0; |
| 5134 | else |
| 5135 | hw->report_tx_early = 1; |
| 5136 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5137 | return E1000_SUCCESS; |
| 5138 | } |
| 5139 | |
| 5140 | void |
| 5141 | fill_rx(struct e1000_hw *hw) |
| 5142 | { |
| 5143 | struct e1000_rx_desc *rd; |
Minghuan Lian | e2e4b78 | 2015-01-22 13:21:54 +0800 | [diff] [blame] | 5144 | unsigned long flush_start, flush_end; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5145 | |
| 5146 | rx_last = rx_tail; |
| 5147 | rd = rx_base + rx_tail; |
| 5148 | rx_tail = (rx_tail + 1) % 8; |
| 5149 | memset(rd, 0, 16); |
Minghuan Lian | e2e4b78 | 2015-01-22 13:21:54 +0800 | [diff] [blame] | 5150 | rd->buffer_addr = cpu_to_le64((unsigned long)packet); |
Marek Vasut | 742c5c2 | 2014-08-08 07:41:38 -0700 | [diff] [blame] | 5151 | |
| 5152 | /* |
| 5153 | * Make sure there are no stale data in WB over this area, which |
| 5154 | * might get written into the memory while the e1000 also writes |
| 5155 | * into the same memory area. |
| 5156 | */ |
Minghuan Lian | e2e4b78 | 2015-01-22 13:21:54 +0800 | [diff] [blame] | 5157 | invalidate_dcache_range((unsigned long)packet, |
| 5158 | (unsigned long)packet + 4096); |
Marek Vasut | 742c5c2 | 2014-08-08 07:41:38 -0700 | [diff] [blame] | 5159 | /* Dump the DMA descriptor into RAM. */ |
Minghuan Lian | e2e4b78 | 2015-01-22 13:21:54 +0800 | [diff] [blame] | 5160 | flush_start = ((unsigned long)rd) & ~(ARCH_DMA_MINALIGN - 1); |
Marek Vasut | 742c5c2 | 2014-08-08 07:41:38 -0700 | [diff] [blame] | 5161 | flush_end = flush_start + roundup(sizeof(*rd), ARCH_DMA_MINALIGN); |
| 5162 | flush_dcache_range(flush_start, flush_end); |
| 5163 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5164 | E1000_WRITE_REG(hw, RDT, rx_tail); |
| 5165 | } |
| 5166 | |
| 5167 | /** |
| 5168 | * e1000_configure_tx - Configure 8254x Transmit Unit after Reset |
| 5169 | * @adapter: board private structure |
| 5170 | * |
| 5171 | * Configure the Tx unit of the MAC after a reset. |
| 5172 | **/ |
| 5173 | |
| 5174 | static void |
| 5175 | e1000_configure_tx(struct e1000_hw *hw) |
| 5176 | { |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5177 | unsigned long tctl; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 5178 | unsigned long tipg, tarc; |
| 5179 | uint32_t ipgr1, ipgr2; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5180 | |
Bin Meng | d0ee7d0 | 2015-08-26 06:17:27 -0700 | [diff] [blame] | 5181 | E1000_WRITE_REG(hw, TDBAL, lower_32_bits((unsigned long)tx_base)); |
| 5182 | E1000_WRITE_REG(hw, TDBAH, upper_32_bits((unsigned long)tx_base)); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5183 | |
| 5184 | E1000_WRITE_REG(hw, TDLEN, 128); |
| 5185 | |
| 5186 | /* Setup the HW Tx Head and Tail descriptor pointers */ |
| 5187 | E1000_WRITE_REG(hw, TDH, 0); |
| 5188 | E1000_WRITE_REG(hw, TDT, 0); |
| 5189 | tx_tail = 0; |
| 5190 | |
| 5191 | /* Set the default values for the Tx Inter Packet Gap timer */ |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 5192 | if (hw->mac_type <= e1000_82547_rev_2 && |
| 5193 | (hw->media_type == e1000_media_type_fiber || |
| 5194 | hw->media_type == e1000_media_type_internal_serdes)) |
| 5195 | tipg = DEFAULT_82543_TIPG_IPGT_FIBER; |
| 5196 | else |
| 5197 | tipg = DEFAULT_82543_TIPG_IPGT_COPPER; |
| 5198 | |
| 5199 | /* Set the default values for the Tx Inter Packet Gap timer */ |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5200 | switch (hw->mac_type) { |
| 5201 | case e1000_82542_rev2_0: |
| 5202 | case e1000_82542_rev2_1: |
| 5203 | tipg = DEFAULT_82542_TIPG_IPGT; |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 5204 | ipgr1 = DEFAULT_82542_TIPG_IPGR1; |
| 5205 | ipgr2 = DEFAULT_82542_TIPG_IPGR2; |
| 5206 | break; |
| 5207 | case e1000_80003es2lan: |
| 5208 | ipgr1 = DEFAULT_82543_TIPG_IPGR1; |
| 5209 | ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5210 | break; |
| 5211 | default: |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 5212 | ipgr1 = DEFAULT_82543_TIPG_IPGR1; |
| 5213 | ipgr2 = DEFAULT_82543_TIPG_IPGR2; |
| 5214 | break; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5215 | } |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 5216 | tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT; |
| 5217 | tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5218 | E1000_WRITE_REG(hw, TIPG, tipg); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5219 | /* Program the Transmit Control Register */ |
| 5220 | tctl = E1000_READ_REG(hw, TCTL); |
| 5221 | tctl &= ~E1000_TCTL_CT; |
| 5222 | tctl |= E1000_TCTL_EN | E1000_TCTL_PSP | |
| 5223 | (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 5224 | |
| 5225 | if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) { |
| 5226 | tarc = E1000_READ_REG(hw, TARC0); |
| 5227 | /* set the speed mode bit, we'll clear it if we're not at |
| 5228 | * gigabit link later */ |
| 5229 | /* git bit can be set to 1*/ |
| 5230 | } else if (hw->mac_type == e1000_80003es2lan) { |
| 5231 | tarc = E1000_READ_REG(hw, TARC0); |
| 5232 | tarc |= 1; |
| 5233 | E1000_WRITE_REG(hw, TARC0, tarc); |
| 5234 | tarc = E1000_READ_REG(hw, TARC1); |
| 5235 | tarc |= 1; |
| 5236 | E1000_WRITE_REG(hw, TARC1, tarc); |
| 5237 | } |
| 5238 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5239 | |
| 5240 | e1000_config_collision_dist(hw); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 5241 | /* Setup Transmit Descriptor Settings for eop descriptor */ |
| 5242 | hw->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5243 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 5244 | /* Need to set up RS bit */ |
| 5245 | if (hw->mac_type < e1000_82543) |
| 5246 | hw->txd_cmd |= E1000_TXD_CMD_RPS; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5247 | else |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 5248 | hw->txd_cmd |= E1000_TXD_CMD_RS; |
Marek Vasut | 74a13c2 | 2014-08-08 07:41:39 -0700 | [diff] [blame] | 5249 | |
| 5250 | |
| 5251 | if (hw->mac_type == e1000_igb) { |
| 5252 | E1000_WRITE_REG(hw, TCTL_EXT, 0x42 << 10); |
| 5253 | |
| 5254 | uint32_t reg_txdctl = E1000_READ_REG(hw, TXDCTL); |
| 5255 | reg_txdctl |= 1 << 25; |
| 5256 | E1000_WRITE_REG(hw, TXDCTL, reg_txdctl); |
| 5257 | mdelay(20); |
| 5258 | } |
| 5259 | |
| 5260 | |
| 5261 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 5262 | E1000_WRITE_REG(hw, TCTL, tctl); |
Marek Vasut | 74a13c2 | 2014-08-08 07:41:39 -0700 | [diff] [blame] | 5263 | |
| 5264 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5265 | } |
| 5266 | |
| 5267 | /** |
| 5268 | * e1000_setup_rctl - configure the receive control register |
| 5269 | * @adapter: Board private structure |
| 5270 | **/ |
| 5271 | static void |
| 5272 | e1000_setup_rctl(struct e1000_hw *hw) |
| 5273 | { |
| 5274 | uint32_t rctl; |
| 5275 | |
| 5276 | rctl = E1000_READ_REG(hw, RCTL); |
| 5277 | |
| 5278 | rctl &= ~(3 << E1000_RCTL_MO_SHIFT); |
| 5279 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 5280 | rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_LBM_NO |
| 5281 | | E1000_RCTL_RDMTS_HALF; /* | |
| 5282 | (hw.mc_filter_type << E1000_RCTL_MO_SHIFT); */ |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5283 | |
| 5284 | if (hw->tbi_compatibility_on == 1) |
| 5285 | rctl |= E1000_RCTL_SBP; |
| 5286 | else |
| 5287 | rctl &= ~E1000_RCTL_SBP; |
| 5288 | |
| 5289 | rctl &= ~(E1000_RCTL_SZ_4096); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5290 | rctl |= E1000_RCTL_SZ_2048; |
| 5291 | rctl &= ~(E1000_RCTL_BSEX | E1000_RCTL_LPE); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5292 | E1000_WRITE_REG(hw, RCTL, rctl); |
| 5293 | } |
| 5294 | |
| 5295 | /** |
| 5296 | * e1000_configure_rx - Configure 8254x Receive Unit after Reset |
| 5297 | * @adapter: board private structure |
| 5298 | * |
| 5299 | * Configure the Rx unit of the MAC after a reset. |
| 5300 | **/ |
| 5301 | static void |
| 5302 | e1000_configure_rx(struct e1000_hw *hw) |
| 5303 | { |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 5304 | unsigned long rctl, ctrl_ext; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5305 | rx_tail = 0; |
Bin Meng | d0ee7d0 | 2015-08-26 06:17:27 -0700 | [diff] [blame] | 5306 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5307 | /* make sure receives are disabled while setting up the descriptors */ |
| 5308 | rctl = E1000_READ_REG(hw, RCTL); |
| 5309 | E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5310 | if (hw->mac_type >= e1000_82540) { |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5311 | /* Set the interrupt throttling rate. Value is calculated |
| 5312 | * as DEFAULT_ITR = 1/(MAX_INTS_PER_SEC * 256ns) */ |
Wolfgang Denk | 35f734f | 2008-04-13 09:59:26 -0700 | [diff] [blame] | 5313 | #define MAX_INTS_PER_SEC 8000 |
| 5314 | #define DEFAULT_ITR 1000000000/(MAX_INTS_PER_SEC * 256) |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5315 | E1000_WRITE_REG(hw, ITR, DEFAULT_ITR); |
| 5316 | } |
| 5317 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 5318 | if (hw->mac_type >= e1000_82571) { |
| 5319 | ctrl_ext = E1000_READ_REG(hw, CTRL_EXT); |
| 5320 | /* Reset delay timers after every interrupt */ |
| 5321 | ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR; |
| 5322 | E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext); |
| 5323 | E1000_WRITE_FLUSH(hw); |
| 5324 | } |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5325 | /* Setup the Base and Length of the Rx Descriptor Ring */ |
Bin Meng | d0ee7d0 | 2015-08-26 06:17:27 -0700 | [diff] [blame] | 5326 | E1000_WRITE_REG(hw, RDBAL, lower_32_bits((unsigned long)rx_base)); |
| 5327 | E1000_WRITE_REG(hw, RDBAH, upper_32_bits((unsigned long)rx_base)); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5328 | |
| 5329 | E1000_WRITE_REG(hw, RDLEN, 128); |
| 5330 | |
| 5331 | /* Setup the HW Rx Head and Tail Descriptor Pointers */ |
| 5332 | E1000_WRITE_REG(hw, RDH, 0); |
| 5333 | E1000_WRITE_REG(hw, RDT, 0); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5334 | /* Enable Receives */ |
| 5335 | |
Marek Vasut | 74a13c2 | 2014-08-08 07:41:39 -0700 | [diff] [blame] | 5336 | if (hw->mac_type == e1000_igb) { |
| 5337 | |
| 5338 | uint32_t reg_rxdctl = E1000_READ_REG(hw, RXDCTL); |
| 5339 | reg_rxdctl |= 1 << 25; |
| 5340 | E1000_WRITE_REG(hw, RXDCTL, reg_rxdctl); |
| 5341 | mdelay(20); |
| 5342 | } |
| 5343 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5344 | E1000_WRITE_REG(hw, RCTL, rctl); |
Marek Vasut | 74a13c2 | 2014-08-08 07:41:39 -0700 | [diff] [blame] | 5345 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5346 | fill_rx(hw); |
| 5347 | } |
| 5348 | |
| 5349 | /************************************************************************** |
| 5350 | POLL - Wait for a frame |
| 5351 | ***************************************************************************/ |
| 5352 | static int |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 5353 | _e1000_poll(struct e1000_hw *hw) |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5354 | { |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5355 | struct e1000_rx_desc *rd; |
Minghuan Lian | e2e4b78 | 2015-01-22 13:21:54 +0800 | [diff] [blame] | 5356 | unsigned long inval_start, inval_end; |
Marek Vasut | 742c5c2 | 2014-08-08 07:41:38 -0700 | [diff] [blame] | 5357 | uint32_t len; |
| 5358 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5359 | /* return true if there's an ethernet packet ready to read */ |
| 5360 | rd = rx_base + rx_last; |
Marek Vasut | 742c5c2 | 2014-08-08 07:41:38 -0700 | [diff] [blame] | 5361 | |
| 5362 | /* Re-load the descriptor from RAM. */ |
Minghuan Lian | e2e4b78 | 2015-01-22 13:21:54 +0800 | [diff] [blame] | 5363 | inval_start = ((unsigned long)rd) & ~(ARCH_DMA_MINALIGN - 1); |
Marek Vasut | 742c5c2 | 2014-08-08 07:41:38 -0700 | [diff] [blame] | 5364 | inval_end = inval_start + roundup(sizeof(*rd), ARCH_DMA_MINALIGN); |
| 5365 | invalidate_dcache_range(inval_start, inval_end); |
| 5366 | |
Miao Yan | 41a084a | 2015-12-21 02:07:02 -0800 | [diff] [blame] | 5367 | if (!(rd->status & E1000_RXD_STAT_DD)) |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5368 | return 0; |
Minghuan Lian | 674bcd5 | 2015-03-19 09:43:51 -0700 | [diff] [blame] | 5369 | /* DEBUGOUT("recv: packet len=%d\n", rd->length); */ |
Marek Vasut | 742c5c2 | 2014-08-08 07:41:38 -0700 | [diff] [blame] | 5370 | /* Packet received, make sure the data are re-loaded from RAM. */ |
Miao Yan | 41a084a | 2015-12-21 02:07:02 -0800 | [diff] [blame] | 5371 | len = le16_to_cpu(rd->length); |
Minghuan Lian | e2e4b78 | 2015-01-22 13:21:54 +0800 | [diff] [blame] | 5372 | invalidate_dcache_range((unsigned long)packet, |
| 5373 | (unsigned long)packet + |
| 5374 | roundup(len, ARCH_DMA_MINALIGN)); |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 5375 | return len; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5376 | } |
| 5377 | |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 5378 | static int _e1000_transmit(struct e1000_hw *hw, void *txpacket, int length) |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5379 | { |
Marek Vasut | 742c5c2 | 2014-08-08 07:41:38 -0700 | [diff] [blame] | 5380 | void *nv_packet = (void *)txpacket; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5381 | struct e1000_tx_desc *txp; |
| 5382 | int i = 0; |
Minghuan Lian | e2e4b78 | 2015-01-22 13:21:54 +0800 | [diff] [blame] | 5383 | unsigned long flush_start, flush_end; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5384 | |
| 5385 | txp = tx_base + tx_tail; |
| 5386 | tx_tail = (tx_tail + 1) % 8; |
| 5387 | |
Wolfgang Denk | f83102e | 2010-11-22 09:48:45 +0100 | [diff] [blame] | 5388 | txp->buffer_addr = cpu_to_le64(virt_to_bus(hw->pdev, nv_packet)); |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 5389 | txp->lower.data = cpu_to_le32(hw->txd_cmd | length); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5390 | txp->upper.data = 0; |
Marek Vasut | 742c5c2 | 2014-08-08 07:41:38 -0700 | [diff] [blame] | 5391 | |
| 5392 | /* Dump the packet into RAM so e1000 can pick them. */ |
Minghuan Lian | e2e4b78 | 2015-01-22 13:21:54 +0800 | [diff] [blame] | 5393 | flush_dcache_range((unsigned long)nv_packet, |
| 5394 | (unsigned long)nv_packet + |
| 5395 | roundup(length, ARCH_DMA_MINALIGN)); |
Marek Vasut | 742c5c2 | 2014-08-08 07:41:38 -0700 | [diff] [blame] | 5396 | /* Dump the descriptor into RAM as well. */ |
Minghuan Lian | e2e4b78 | 2015-01-22 13:21:54 +0800 | [diff] [blame] | 5397 | flush_start = ((unsigned long)txp) & ~(ARCH_DMA_MINALIGN - 1); |
Marek Vasut | 742c5c2 | 2014-08-08 07:41:38 -0700 | [diff] [blame] | 5398 | flush_end = flush_start + roundup(sizeof(*txp), ARCH_DMA_MINALIGN); |
| 5399 | flush_dcache_range(flush_start, flush_end); |
| 5400 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5401 | E1000_WRITE_REG(hw, TDT, tx_tail); |
| 5402 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 5403 | E1000_WRITE_FLUSH(hw); |
Marek Vasut | 742c5c2 | 2014-08-08 07:41:38 -0700 | [diff] [blame] | 5404 | while (1) { |
| 5405 | invalidate_dcache_range(flush_start, flush_end); |
| 5406 | if (le32_to_cpu(txp->upper.data) & E1000_TXD_STAT_DD) |
| 5407 | break; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5408 | if (i++ > TOUT_LOOP) { |
| 5409 | DEBUGOUT("e1000: tx timeout\n"); |
| 5410 | return 0; |
| 5411 | } |
| 5412 | udelay(10); /* give the nic a chance to write to the register */ |
| 5413 | } |
| 5414 | return 1; |
| 5415 | } |
| 5416 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5417 | static void |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 5418 | _e1000_disable(struct e1000_hw *hw) |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5419 | { |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5420 | /* Turn off the ethernet interface */ |
| 5421 | E1000_WRITE_REG(hw, RCTL, 0); |
| 5422 | E1000_WRITE_REG(hw, TCTL, 0); |
| 5423 | |
| 5424 | /* Clear the transmit ring */ |
| 5425 | E1000_WRITE_REG(hw, TDH, 0); |
| 5426 | E1000_WRITE_REG(hw, TDT, 0); |
| 5427 | |
| 5428 | /* Clear the receive ring */ |
| 5429 | E1000_WRITE_REG(hw, RDH, 0); |
| 5430 | E1000_WRITE_REG(hw, RDT, 0); |
| 5431 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5432 | mdelay(10); |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 5433 | } |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5434 | |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 5435 | /*reset function*/ |
| 5436 | static inline int |
| 5437 | e1000_reset(struct e1000_hw *hw, unsigned char enetaddr[6]) |
| 5438 | { |
| 5439 | e1000_reset_hw(hw); |
| 5440 | if (hw->mac_type >= e1000_82544) |
| 5441 | E1000_WRITE_REG(hw, WUC, 0); |
| 5442 | |
| 5443 | return e1000_init_hw(hw, enetaddr); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5444 | } |
| 5445 | |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5446 | static int |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 5447 | _e1000_init(struct e1000_hw *hw, unsigned char enetaddr[6]) |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5448 | { |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5449 | int ret_val = 0; |
| 5450 | |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 5451 | ret_val = e1000_reset(hw, enetaddr); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5452 | if (ret_val < 0) { |
| 5453 | if ((ret_val == -E1000_ERR_NOLINK) || |
| 5454 | (ret_val == -E1000_ERR_TIMEOUT)) { |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 5455 | E1000_ERR(hw, "Valid Link not detected: %d\n", ret_val); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5456 | } else { |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 5457 | E1000_ERR(hw, "Hardware Initialization Failed\n"); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5458 | } |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 5459 | return ret_val; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5460 | } |
| 5461 | e1000_configure_tx(hw); |
| 5462 | e1000_setup_rctl(hw); |
| 5463 | e1000_configure_rx(hw); |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 5464 | return 0; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5465 | } |
| 5466 | |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 5467 | /****************************************************************************** |
| 5468 | * Gets the current PCI bus type of hardware |
| 5469 | * |
| 5470 | * hw - Struct containing variables accessed by shared code |
| 5471 | *****************************************************************************/ |
| 5472 | void e1000_get_bus_type(struct e1000_hw *hw) |
| 5473 | { |
| 5474 | uint32_t status; |
| 5475 | |
| 5476 | switch (hw->mac_type) { |
| 5477 | case e1000_82542_rev2_0: |
| 5478 | case e1000_82542_rev2_1: |
| 5479 | hw->bus_type = e1000_bus_type_pci; |
| 5480 | break; |
| 5481 | case e1000_82571: |
| 5482 | case e1000_82572: |
| 5483 | case e1000_82573: |
Roy Zang | 181119b | 2011-01-21 11:29:38 +0800 | [diff] [blame] | 5484 | case e1000_82574: |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 5485 | case e1000_80003es2lan: |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 5486 | case e1000_ich8lan: |
Marek Vasut | 74a13c2 | 2014-08-08 07:41:39 -0700 | [diff] [blame] | 5487 | case e1000_igb: |
Roy Zang | 28f7a05 | 2009-07-31 13:34:02 +0800 | [diff] [blame] | 5488 | hw->bus_type = e1000_bus_type_pci_express; |
| 5489 | break; |
| 5490 | default: |
| 5491 | status = E1000_READ_REG(hw, STATUS); |
| 5492 | hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ? |
| 5493 | e1000_bus_type_pcix : e1000_bus_type_pci; |
| 5494 | break; |
| 5495 | } |
| 5496 | } |
| 5497 | |
Simon Glass | 9f86b38 | 2015-08-19 09:33:40 -0600 | [diff] [blame] | 5498 | #ifndef CONFIG_DM_ETH |
Kyle Moffett | 64b94dd | 2011-10-18 11:05:29 +0000 | [diff] [blame] | 5499 | /* A list of all registered e1000 devices */ |
| 5500 | static LIST_HEAD(e1000_hw_list); |
Simon Glass | 9f86b38 | 2015-08-19 09:33:40 -0600 | [diff] [blame] | 5501 | #endif |
Kyle Moffett | 64b94dd | 2011-10-18 11:05:29 +0000 | [diff] [blame] | 5502 | |
Bin Meng | 83cf24c | 2016-02-02 05:58:01 -0800 | [diff] [blame] | 5503 | #ifdef CONFIG_DM_ETH |
| 5504 | static int e1000_init_one(struct e1000_hw *hw, int cardnum, |
| 5505 | struct udevice *devno, unsigned char enetaddr[6]) |
| 5506 | #else |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 5507 | static int e1000_init_one(struct e1000_hw *hw, int cardnum, pci_dev_t devno, |
| 5508 | unsigned char enetaddr[6]) |
Bin Meng | 83cf24c | 2016-02-02 05:58:01 -0800 | [diff] [blame] | 5509 | #endif |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 5510 | { |
| 5511 | u32 val; |
| 5512 | |
| 5513 | /* Assign the passed-in values */ |
Bin Meng | 83cf24c | 2016-02-02 05:58:01 -0800 | [diff] [blame] | 5514 | #ifdef CONFIG_DM_ETH |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 5515 | hw->pdev = devno; |
Bin Meng | 83cf24c | 2016-02-02 05:58:01 -0800 | [diff] [blame] | 5516 | #else |
| 5517 | hw->pdev = devno; |
| 5518 | #endif |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 5519 | hw->cardnum = cardnum; |
| 5520 | |
| 5521 | /* Print a debug message with the IO base address */ |
Bin Meng | 83cf24c | 2016-02-02 05:58:01 -0800 | [diff] [blame] | 5522 | #ifdef CONFIG_DM_ETH |
| 5523 | dm_pci_read_config32(devno, PCI_BASE_ADDRESS_0, &val); |
| 5524 | #else |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 5525 | pci_read_config_dword(devno, PCI_BASE_ADDRESS_0, &val); |
Bin Meng | 83cf24c | 2016-02-02 05:58:01 -0800 | [diff] [blame] | 5526 | #endif |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 5527 | E1000_DBG(hw, "iobase 0x%08x\n", val & 0xfffffff0); |
| 5528 | |
| 5529 | /* Try to enable I/O accesses and bus-mastering */ |
| 5530 | val = PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER; |
Bin Meng | 83cf24c | 2016-02-02 05:58:01 -0800 | [diff] [blame] | 5531 | #ifdef CONFIG_DM_ETH |
| 5532 | dm_pci_write_config32(devno, PCI_COMMAND, val); |
| 5533 | #else |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 5534 | pci_write_config_dword(devno, PCI_COMMAND, val); |
Bin Meng | 83cf24c | 2016-02-02 05:58:01 -0800 | [diff] [blame] | 5535 | #endif |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 5536 | |
| 5537 | /* Make sure it worked */ |
Bin Meng | 83cf24c | 2016-02-02 05:58:01 -0800 | [diff] [blame] | 5538 | #ifdef CONFIG_DM_ETH |
| 5539 | dm_pci_read_config32(devno, PCI_COMMAND, &val); |
| 5540 | #else |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 5541 | pci_read_config_dword(devno, PCI_COMMAND, &val); |
Bin Meng | 83cf24c | 2016-02-02 05:58:01 -0800 | [diff] [blame] | 5542 | #endif |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 5543 | if (!(val & PCI_COMMAND_MEMORY)) { |
| 5544 | E1000_ERR(hw, "Can't enable I/O memory\n"); |
| 5545 | return -ENOSPC; |
| 5546 | } |
| 5547 | if (!(val & PCI_COMMAND_MASTER)) { |
| 5548 | E1000_ERR(hw, "Can't enable bus-mastering\n"); |
| 5549 | return -EPERM; |
| 5550 | } |
| 5551 | |
| 5552 | /* Are these variables needed? */ |
| 5553 | hw->fc = e1000_fc_default; |
| 5554 | hw->original_fc = e1000_fc_default; |
| 5555 | hw->autoneg_failed = 0; |
| 5556 | hw->autoneg = 1; |
| 5557 | hw->get_link_status = true; |
| 5558 | #ifndef CONFIG_E1000_NO_NVM |
| 5559 | hw->eeprom_semaphore_present = true; |
| 5560 | #endif |
Bin Meng | 83cf24c | 2016-02-02 05:58:01 -0800 | [diff] [blame] | 5561 | #ifdef CONFIG_DM_ETH |
| 5562 | hw->hw_addr = dm_pci_map_bar(devno, PCI_BASE_ADDRESS_0, |
| 5563 | PCI_REGION_MEM); |
| 5564 | #else |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 5565 | hw->hw_addr = pci_map_bar(devno, PCI_BASE_ADDRESS_0, |
| 5566 | PCI_REGION_MEM); |
Bin Meng | 83cf24c | 2016-02-02 05:58:01 -0800 | [diff] [blame] | 5567 | #endif |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 5568 | hw->mac_type = e1000_undefined; |
| 5569 | |
| 5570 | /* MAC and Phy settings */ |
| 5571 | if (e1000_sw_init(hw) < 0) { |
| 5572 | E1000_ERR(hw, "Software init failed\n"); |
| 5573 | return -EIO; |
| 5574 | } |
| 5575 | if (e1000_check_phy_reset_block(hw)) |
| 5576 | E1000_ERR(hw, "PHY Reset is blocked!\n"); |
| 5577 | |
| 5578 | /* Basic init was OK, reset the hardware and allow SPI access */ |
| 5579 | e1000_reset_hw(hw); |
| 5580 | |
| 5581 | #ifndef CONFIG_E1000_NO_NVM |
| 5582 | /* Validate the EEPROM and get chipset information */ |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 5583 | if (e1000_init_eeprom_params(hw)) { |
| 5584 | E1000_ERR(hw, "EEPROM is invalid!\n"); |
| 5585 | return -EINVAL; |
| 5586 | } |
| 5587 | if ((E1000_READ_REG(hw, I210_EECD) & E1000_EECD_FLUPD) && |
| 5588 | e1000_validate_eeprom_checksum(hw)) |
| 5589 | return -ENXIO; |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 5590 | e1000_read_mac_addr(hw, enetaddr); |
| 5591 | #endif |
| 5592 | e1000_get_bus_type(hw); |
| 5593 | |
| 5594 | #ifndef CONFIG_E1000_NO_NVM |
| 5595 | printf("e1000: %02x:%02x:%02x:%02x:%02x:%02x\n ", |
| 5596 | enetaddr[0], enetaddr[1], enetaddr[2], |
| 5597 | enetaddr[3], enetaddr[4], enetaddr[5]); |
| 5598 | #else |
| 5599 | memset(enetaddr, 0, 6); |
| 5600 | printf("e1000: no NVM\n"); |
| 5601 | #endif |
| 5602 | |
| 5603 | return 0; |
| 5604 | } |
| 5605 | |
| 5606 | /* Put the name of a device in a string */ |
| 5607 | static void e1000_name(char *str, int cardnum) |
| 5608 | { |
| 5609 | sprintf(str, "e1000#%u", cardnum); |
| 5610 | } |
| 5611 | |
Simon Glass | 9f86b38 | 2015-08-19 09:33:40 -0600 | [diff] [blame] | 5612 | #ifndef CONFIG_DM_ETH |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 5613 | /************************************************************************** |
| 5614 | TRANSMIT - Transmit a frame |
| 5615 | ***************************************************************************/ |
| 5616 | static int e1000_transmit(struct eth_device *nic, void *txpacket, int length) |
| 5617 | { |
| 5618 | struct e1000_hw *hw = nic->priv; |
| 5619 | |
| 5620 | return _e1000_transmit(hw, txpacket, length); |
| 5621 | } |
| 5622 | |
| 5623 | /************************************************************************** |
| 5624 | DISABLE - Turn off ethernet interface |
| 5625 | ***************************************************************************/ |
| 5626 | static void |
| 5627 | e1000_disable(struct eth_device *nic) |
| 5628 | { |
| 5629 | struct e1000_hw *hw = nic->priv; |
| 5630 | |
| 5631 | _e1000_disable(hw); |
| 5632 | } |
| 5633 | |
| 5634 | /************************************************************************** |
| 5635 | INIT - set up ethernet interface(s) |
| 5636 | ***************************************************************************/ |
| 5637 | static int |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 5638 | e1000_init(struct eth_device *nic, struct bd_info *bis) |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 5639 | { |
| 5640 | struct e1000_hw *hw = nic->priv; |
| 5641 | |
| 5642 | return _e1000_init(hw, nic->enetaddr); |
| 5643 | } |
| 5644 | |
| 5645 | static int |
| 5646 | e1000_poll(struct eth_device *nic) |
| 5647 | { |
| 5648 | struct e1000_hw *hw = nic->priv; |
| 5649 | int len; |
| 5650 | |
| 5651 | len = _e1000_poll(hw); |
| 5652 | if (len) { |
| 5653 | net_process_received_packet((uchar *)packet, len); |
| 5654 | fill_rx(hw); |
| 5655 | } |
| 5656 | |
| 5657 | return len ? 1 : 0; |
| 5658 | } |
Ian Ray | 9635e2d | 2020-11-04 17:26:01 +0100 | [diff] [blame] | 5659 | #endif /* !CONFIG_DM_ETH */ |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 5660 | |
Ian Ray | 9635e2d | 2020-11-04 17:26:01 +0100 | [diff] [blame] | 5661 | #ifdef CONFIG_DM_ETH |
| 5662 | static int e1000_write_hwaddr(struct udevice *dev) |
| 5663 | #else |
Hannu Lounento | 68d31f6 | 2018-01-10 20:31:26 +0100 | [diff] [blame] | 5664 | static int e1000_write_hwaddr(struct eth_device *dev) |
Ian Ray | 9635e2d | 2020-11-04 17:26:01 +0100 | [diff] [blame] | 5665 | #endif |
Hannu Lounento | 68d31f6 | 2018-01-10 20:31:26 +0100 | [diff] [blame] | 5666 | { |
| 5667 | #ifndef CONFIG_E1000_NO_NVM |
Hannu Lounento | 68d31f6 | 2018-01-10 20:31:26 +0100 | [diff] [blame] | 5668 | unsigned char current_mac[6]; |
Ian Ray | 9635e2d | 2020-11-04 17:26:01 +0100 | [diff] [blame] | 5669 | #ifdef CONFIG_DM_ETH |
| 5670 | struct eth_pdata *plat = dev_get_plat(dev); |
| 5671 | struct e1000_hw *hw = dev_get_priv(dev); |
| 5672 | u8 *mac = plat->enetaddr; |
| 5673 | #else |
Hannu Lounento | 68d31f6 | 2018-01-10 20:31:26 +0100 | [diff] [blame] | 5674 | struct e1000_hw *hw = dev->priv; |
Ian Ray | 9635e2d | 2020-11-04 17:26:01 +0100 | [diff] [blame] | 5675 | u8 *mac = dev->enetaddr; |
| 5676 | #endif |
Hannu Lounento | 68d31f6 | 2018-01-10 20:31:26 +0100 | [diff] [blame] | 5677 | uint16_t data[3]; |
| 5678 | int ret_val, i; |
| 5679 | |
| 5680 | DEBUGOUT("%s: mac=%pM\n", __func__, mac); |
| 5681 | |
| 5682 | memset(current_mac, 0, 6); |
| 5683 | |
| 5684 | /* Read from EEPROM, not from registers, to make sure |
| 5685 | * the address is persistently configured |
| 5686 | */ |
| 5687 | ret_val = e1000_read_mac_addr_from_eeprom(hw, current_mac); |
| 5688 | DEBUGOUT("%s: current mac=%pM\n", __func__, current_mac); |
| 5689 | |
| 5690 | /* Only write to EEPROM if the given address is different or |
| 5691 | * reading the current address failed |
| 5692 | */ |
| 5693 | if (!ret_val && memcmp(current_mac, mac, 6) == 0) |
| 5694 | return 0; |
| 5695 | |
| 5696 | for (i = 0; i < 3; ++i) |
| 5697 | data[i] = mac[i * 2 + 1] << 8 | mac[i * 2]; |
| 5698 | |
| 5699 | ret_val = e1000_write_eeprom_srwr(hw, 0x0, 3, data); |
| 5700 | |
| 5701 | if (!ret_val) |
| 5702 | ret_val = e1000_update_eeprom_checksum_i210(hw); |
| 5703 | |
| 5704 | return ret_val; |
| 5705 | #else |
| 5706 | return 0; |
| 5707 | #endif |
| 5708 | } |
| 5709 | |
Ian Ray | 9635e2d | 2020-11-04 17:26:01 +0100 | [diff] [blame] | 5710 | #ifndef CONFIG_DM_ETH |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5711 | /************************************************************************** |
| 5712 | PROBE - Look for an adapter, this routine's visible to the outside |
| 5713 | You should omit the last argument struct pci_device * for a non-PCI NIC |
| 5714 | ***************************************************************************/ |
| 5715 | int |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 5716 | e1000_initialize(struct bd_info * bis) |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5717 | { |
Kyle Moffett | 7b698d5 | 2011-10-18 11:05:26 +0000 | [diff] [blame] | 5718 | unsigned int i; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5719 | pci_dev_t devno; |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 5720 | int ret; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5721 | |
Timur Tabi | edc45b5 | 2009-08-17 15:55:38 -0500 | [diff] [blame] | 5722 | DEBUGFUNC(); |
| 5723 | |
Kyle Moffett | 7b698d5 | 2011-10-18 11:05:26 +0000 | [diff] [blame] | 5724 | /* Find and probe all the matching PCI devices */ |
| 5725 | for (i = 0; (devno = pci_find_devices(e1000_supported, i)) >= 0; i++) { |
Kyle Moffett | 7b698d5 | 2011-10-18 11:05:26 +0000 | [diff] [blame] | 5726 | /* |
| 5727 | * These will never get freed due to errors, this allows us to |
Bin Meng | 7557405 | 2016-02-05 19:30:11 -0800 | [diff] [blame] | 5728 | * perform SPI EEPROM programming from U-Boot, for example. |
Kyle Moffett | 7b698d5 | 2011-10-18 11:05:26 +0000 | [diff] [blame] | 5729 | */ |
| 5730 | struct eth_device *nic = malloc(sizeof(*nic)); |
| 5731 | struct e1000_hw *hw = malloc(sizeof(*hw)); |
| 5732 | if (!nic || !hw) { |
| 5733 | printf("e1000#%u: Out of Memory!\n", i); |
Kumar Gala | 7693357 | 2010-11-12 04:13:06 -0600 | [diff] [blame] | 5734 | free(nic); |
Kyle Moffett | 7b698d5 | 2011-10-18 11:05:26 +0000 | [diff] [blame] | 5735 | free(hw); |
| 5736 | continue; |
Kumar Gala | 7693357 | 2010-11-12 04:13:06 -0600 | [diff] [blame] | 5737 | } |
| 5738 | |
Kyle Moffett | 7b698d5 | 2011-10-18 11:05:26 +0000 | [diff] [blame] | 5739 | /* Make sure all of the fields are initially zeroed */ |
Matthew McClintock | 5761ce4 | 2010-11-15 18:02:53 -0600 | [diff] [blame] | 5740 | memset(nic, 0, sizeof(*nic)); |
Kumar Gala | 7693357 | 2010-11-12 04:13:06 -0600 | [diff] [blame] | 5741 | memset(hw, 0, sizeof(*hw)); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5742 | nic->priv = hw; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5743 | |
Kyle Moffett | 7b698d5 | 2011-10-18 11:05:26 +0000 | [diff] [blame] | 5744 | /* Generate a card name */ |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 5745 | e1000_name(nic->name, i); |
| 5746 | hw->name = nic->name; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5747 | |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 5748 | ret = e1000_init_one(hw, i, devno, nic->enetaddr); |
| 5749 | if (ret) |
Kyle Moffett | 7b698d5 | 2011-10-18 11:05:26 +0000 | [diff] [blame] | 5750 | continue; |
Kyle Moffett | 64b94dd | 2011-10-18 11:05:29 +0000 | [diff] [blame] | 5751 | list_add_tail(&hw->list_node, &e1000_hw_list); |
Kyle Moffett | 7b698d5 | 2011-10-18 11:05:26 +0000 | [diff] [blame] | 5752 | |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 5753 | hw->nic = nic; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5754 | |
Kyle Moffett | 7b698d5 | 2011-10-18 11:05:26 +0000 | [diff] [blame] | 5755 | /* Set up the function pointers and register the device */ |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5756 | nic->init = e1000_init; |
| 5757 | nic->recv = e1000_poll; |
| 5758 | nic->send = e1000_transmit; |
| 5759 | nic->halt = e1000_disable; |
Hannu Lounento | 68d31f6 | 2018-01-10 20:31:26 +0100 | [diff] [blame] | 5760 | nic->write_hwaddr = e1000_write_hwaddr; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5761 | eth_register(nic); |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5762 | } |
Kyle Moffett | 7b698d5 | 2011-10-18 11:05:26 +0000 | [diff] [blame] | 5763 | |
| 5764 | return i; |
wdenk | 4e112c1 | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 5765 | } |
Kyle Moffett | 64b94dd | 2011-10-18 11:05:29 +0000 | [diff] [blame] | 5766 | |
| 5767 | struct e1000_hw *e1000_find_card(unsigned int cardnum) |
| 5768 | { |
| 5769 | struct e1000_hw *hw; |
| 5770 | |
| 5771 | list_for_each_entry(hw, &e1000_hw_list, list_node) |
| 5772 | if (hw->cardnum == cardnum) |
| 5773 | return hw; |
| 5774 | |
| 5775 | return NULL; |
| 5776 | } |
Simon Glass | 9f86b38 | 2015-08-19 09:33:40 -0600 | [diff] [blame] | 5777 | #endif /* !CONFIG_DM_ETH */ |
Kyle Moffett | 64b94dd | 2011-10-18 11:05:29 +0000 | [diff] [blame] | 5778 | |
| 5779 | #ifdef CONFIG_CMD_E1000 |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 5780 | static int do_e1000(struct cmd_tbl *cmdtp, int flag, int argc, |
| 5781 | char *const argv[]) |
Kyle Moffett | 64b94dd | 2011-10-18 11:05:29 +0000 | [diff] [blame] | 5782 | { |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 5783 | unsigned char *mac = NULL; |
Simon Glass | 9f86b38 | 2015-08-19 09:33:40 -0600 | [diff] [blame] | 5784 | #ifdef CONFIG_DM_ETH |
| 5785 | struct eth_pdata *plat; |
| 5786 | struct udevice *dev; |
| 5787 | char name[30]; |
| 5788 | int ret; |
Alban Bedel | c1255dd | 2016-08-03 11:31:03 +0200 | [diff] [blame] | 5789 | #endif |
| 5790 | #if !defined(CONFIG_DM_ETH) || defined(CONFIG_E1000_SPI) |
Kyle Moffett | 64b94dd | 2011-10-18 11:05:29 +0000 | [diff] [blame] | 5791 | struct e1000_hw *hw; |
Simon Glass | 9f86b38 | 2015-08-19 09:33:40 -0600 | [diff] [blame] | 5792 | #endif |
| 5793 | int cardnum; |
Kyle Moffett | 64b94dd | 2011-10-18 11:05:29 +0000 | [diff] [blame] | 5794 | |
| 5795 | if (argc < 3) { |
| 5796 | cmd_usage(cmdtp); |
| 5797 | return 1; |
| 5798 | } |
| 5799 | |
| 5800 | /* Make sure we can find the requested e1000 card */ |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 5801 | cardnum = simple_strtoul(argv[1], NULL, 10); |
Simon Glass | 9f86b38 | 2015-08-19 09:33:40 -0600 | [diff] [blame] | 5802 | #ifdef CONFIG_DM_ETH |
| 5803 | e1000_name(name, cardnum); |
| 5804 | ret = uclass_get_device_by_name(UCLASS_ETH, name, &dev); |
| 5805 | if (!ret) { |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 5806 | plat = dev_get_plat(dev); |
Simon Glass | 9f86b38 | 2015-08-19 09:33:40 -0600 | [diff] [blame] | 5807 | mac = plat->enetaddr; |
| 5808 | } |
| 5809 | #else |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 5810 | hw = e1000_find_card(cardnum); |
| 5811 | if (hw) |
| 5812 | mac = hw->nic->enetaddr; |
Simon Glass | 9f86b38 | 2015-08-19 09:33:40 -0600 | [diff] [blame] | 5813 | #endif |
Simon Glass | c53abc3 | 2015-08-19 09:33:39 -0600 | [diff] [blame] | 5814 | if (!mac) { |
Kyle Moffett | 64b94dd | 2011-10-18 11:05:29 +0000 | [diff] [blame] | 5815 | printf("e1000: ERROR: No such device: e1000#%s\n", argv[1]); |
| 5816 | return 1; |
| 5817 | } |
| 5818 | |
| 5819 | if (!strcmp(argv[2], "print-mac-address")) { |
Kyle Moffett | 64b94dd | 2011-10-18 11:05:29 +0000 | [diff] [blame] | 5820 | printf("%02x:%02x:%02x:%02x:%02x:%02x\n", |
| 5821 | mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); |
| 5822 | return 0; |
| 5823 | } |
| 5824 | |
| 5825 | #ifdef CONFIG_E1000_SPI |
Alban Bedel | c1255dd | 2016-08-03 11:31:03 +0200 | [diff] [blame] | 5826 | #ifdef CONFIG_DM_ETH |
| 5827 | hw = dev_get_priv(dev); |
| 5828 | #endif |
Kyle Moffett | 64b94dd | 2011-10-18 11:05:29 +0000 | [diff] [blame] | 5829 | /* Handle the "SPI" subcommand */ |
| 5830 | if (!strcmp(argv[2], "spi")) |
| 5831 | return do_e1000_spi(cmdtp, hw, argc - 3, argv + 3); |
| 5832 | #endif |
| 5833 | |
| 5834 | cmd_usage(cmdtp); |
| 5835 | return 1; |
| 5836 | } |
| 5837 | |
| 5838 | U_BOOT_CMD( |
| 5839 | e1000, 7, 0, do_e1000, |
| 5840 | "Intel e1000 controller management", |
| 5841 | /* */"<card#> print-mac-address\n" |
| 5842 | #ifdef CONFIG_E1000_SPI |
| 5843 | "e1000 <card#> spi show [<offset> [<length>]]\n" |
| 5844 | "e1000 <card#> spi dump <addr> <offset> <length>\n" |
| 5845 | "e1000 <card#> spi program <addr> <offset> <length>\n" |
| 5846 | "e1000 <card#> spi checksum [update]\n" |
| 5847 | #endif |
| 5848 | " - Manage the Intel E1000 PCI device" |
| 5849 | ); |
| 5850 | #endif /* not CONFIG_CMD_E1000 */ |
Simon Glass | 9f86b38 | 2015-08-19 09:33:40 -0600 | [diff] [blame] | 5851 | |
| 5852 | #ifdef CONFIG_DM_ETH |
| 5853 | static int e1000_eth_start(struct udevice *dev) |
| 5854 | { |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 5855 | struct eth_pdata *plat = dev_get_plat(dev); |
Simon Glass | 9f86b38 | 2015-08-19 09:33:40 -0600 | [diff] [blame] | 5856 | struct e1000_hw *hw = dev_get_priv(dev); |
| 5857 | |
| 5858 | return _e1000_init(hw, plat->enetaddr); |
| 5859 | } |
| 5860 | |
| 5861 | static void e1000_eth_stop(struct udevice *dev) |
| 5862 | { |
| 5863 | struct e1000_hw *hw = dev_get_priv(dev); |
| 5864 | |
| 5865 | _e1000_disable(hw); |
| 5866 | } |
| 5867 | |
| 5868 | static int e1000_eth_send(struct udevice *dev, void *packet, int length) |
| 5869 | { |
| 5870 | struct e1000_hw *hw = dev_get_priv(dev); |
| 5871 | int ret; |
| 5872 | |
| 5873 | ret = _e1000_transmit(hw, packet, length); |
| 5874 | |
| 5875 | return ret ? 0 : -ETIMEDOUT; |
| 5876 | } |
| 5877 | |
| 5878 | static int e1000_eth_recv(struct udevice *dev, int flags, uchar **packetp) |
| 5879 | { |
| 5880 | struct e1000_hw *hw = dev_get_priv(dev); |
| 5881 | int len; |
| 5882 | |
| 5883 | len = _e1000_poll(hw); |
| 5884 | if (len) |
| 5885 | *packetp = packet; |
| 5886 | |
| 5887 | return len ? len : -EAGAIN; |
| 5888 | } |
| 5889 | |
| 5890 | static int e1000_free_pkt(struct udevice *dev, uchar *packet, int length) |
| 5891 | { |
| 5892 | struct e1000_hw *hw = dev_get_priv(dev); |
| 5893 | |
| 5894 | fill_rx(hw); |
| 5895 | |
| 5896 | return 0; |
| 5897 | } |
| 5898 | |
| 5899 | static int e1000_eth_probe(struct udevice *dev) |
| 5900 | { |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 5901 | struct eth_pdata *plat = dev_get_plat(dev); |
Simon Glass | 9f86b38 | 2015-08-19 09:33:40 -0600 | [diff] [blame] | 5902 | struct e1000_hw *hw = dev_get_priv(dev); |
| 5903 | int ret; |
| 5904 | |
| 5905 | hw->name = dev->name; |
Simon Glass | eaa1489 | 2015-11-29 13:17:47 -0700 | [diff] [blame] | 5906 | ret = e1000_init_one(hw, trailing_strtol(dev->name), |
Bin Meng | 83cf24c | 2016-02-02 05:58:01 -0800 | [diff] [blame] | 5907 | dev, plat->enetaddr); |
Simon Glass | 9f86b38 | 2015-08-19 09:33:40 -0600 | [diff] [blame] | 5908 | if (ret < 0) { |
| 5909 | printf(pr_fmt("failed to initialize card: %d\n"), ret); |
| 5910 | return ret; |
| 5911 | } |
| 5912 | |
| 5913 | return 0; |
| 5914 | } |
| 5915 | |
| 5916 | static int e1000_eth_bind(struct udevice *dev) |
| 5917 | { |
| 5918 | char name[20]; |
| 5919 | |
| 5920 | /* |
| 5921 | * A simple way to number the devices. When device tree is used this |
| 5922 | * is unnecessary, but when the device is just discovered on the PCI |
| 5923 | * bus we need a name. We could instead have the uclass figure out |
| 5924 | * which devices are different and number them. |
| 5925 | */ |
| 5926 | e1000_name(name, num_cards++); |
| 5927 | |
| 5928 | return device_set_name(dev, name); |
| 5929 | } |
| 5930 | |
| 5931 | static const struct eth_ops e1000_eth_ops = { |
| 5932 | .start = e1000_eth_start, |
| 5933 | .send = e1000_eth_send, |
| 5934 | .recv = e1000_eth_recv, |
| 5935 | .stop = e1000_eth_stop, |
| 5936 | .free_pkt = e1000_free_pkt, |
Ian Ray | 9635e2d | 2020-11-04 17:26:01 +0100 | [diff] [blame] | 5937 | .write_hwaddr = e1000_write_hwaddr, |
Simon Glass | 9f86b38 | 2015-08-19 09:33:40 -0600 | [diff] [blame] | 5938 | }; |
| 5939 | |
| 5940 | static const struct udevice_id e1000_eth_ids[] = { |
| 5941 | { .compatible = "intel,e1000" }, |
| 5942 | { } |
| 5943 | }; |
| 5944 | |
| 5945 | U_BOOT_DRIVER(eth_e1000) = { |
| 5946 | .name = "eth_e1000", |
| 5947 | .id = UCLASS_ETH, |
| 5948 | .of_match = e1000_eth_ids, |
| 5949 | .bind = e1000_eth_bind, |
| 5950 | .probe = e1000_eth_probe, |
| 5951 | .ops = &e1000_eth_ops, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 5952 | .priv_auto = sizeof(struct e1000_hw), |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 5953 | .plat_auto = sizeof(struct eth_pdata), |
Simon Glass | 9f86b38 | 2015-08-19 09:33:40 -0600 | [diff] [blame] | 5954 | }; |
| 5955 | |
| 5956 | U_BOOT_PCI_DEVICE(eth_e1000, e1000_supported); |
| 5957 | #endif |