blob: b092867272f5bbc7c9a84eeda6777f22ee5e2abc [file] [log] [blame]
wdenk4e112c12003-06-03 23:54:09 +00001/**************************************************************************
Andre Schwarz68c2a302008-03-06 16:45:44 +01002Intel Pro 1000 for ppcboot/das-u-boot
wdenk4e112c12003-06-03 23:54:09 +00003Drivers are port from Intel's Linux driver e1000-4.3.15
4and from Etherboot pro 1000 driver by mrakes at vivato dot net
5tested on both gig copper and gig fiber boards
6***************************************************************************/
7/*******************************************************************************
8
wdenk57b2d802003-06-27 21:31:46 +00009
wdenk4e112c12003-06-03 23:54:09 +000010 Copyright(c) 1999 - 2002 Intel Corporation. All rights reserved.
wdenk57b2d802003-06-27 21:31:46 +000011
Wolfgang Denkd79de1d2013-07-08 09:37:19 +020012 * SPDX-License-Identifier: GPL-2.0+
wdenk57b2d802003-06-27 21:31:46 +000013
wdenk4e112c12003-06-03 23:54:09 +000014 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 Zang181119b2011-01-21 11:29:38 +080028 *
29 * Copyright 2011 Freescale Semiconductor, Inc.
wdenk4e112c12003-06-03 23:54:09 +000030 */
31
32#include "e1000.h"
33
wdenk4e112c12003-06-03 23:54:09 +000034#define TOUT_LOOP 100000
35
Timur Tabiedc45b52009-08-17 15:55:38 -050036#define virt_to_bus(devno, v) pci_virt_to_mem(devno, (void *) (v))
wdenk4e112c12003-06-03 23:54:09 +000037#define bus_to_phys(devno, a) pci_mem_to_phys(devno, a)
wdenk4e112c12003-06-03 23:54:09 +000038
Roy Zang966172e2009-08-22 03:49:52 +080039#define E1000_DEFAULT_PCI_PBA 0x00000030
40#define E1000_DEFAULT_PCIE_PBA 0x000a0026
wdenk4e112c12003-06-03 23:54:09 +000041
42/* NIC specific static variables go here */
43
Marek Vasut742c5c22014-08-08 07:41:38 -070044/* Intel i210 needs the DMA descriptor rings aligned to 128b */
45#define E1000_BUFFER_ALIGN 128
wdenk4e112c12003-06-03 23:54:09 +000046
Marek Vasut742c5c22014-08-08 07:41:38 -070047DEFINE_ALIGN_BUFFER(struct e1000_tx_desc, tx_base, 16, E1000_BUFFER_ALIGN);
48DEFINE_ALIGN_BUFFER(struct e1000_rx_desc, rx_base, 16, E1000_BUFFER_ALIGN);
49DEFINE_ALIGN_BUFFER(unsigned char, packet, 4096, E1000_BUFFER_ALIGN);
wdenk4e112c12003-06-03 23:54:09 +000050
51static int tx_tail;
52static int rx_tail, rx_last;
53
Kyle Moffett7b698d52011-10-18 11:05:26 +000054static struct pci_device_id e1000_supported[] = {
wdenk4e112c12003-06-03 23:54:09 +000055 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82542},
56 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82543GC_FIBER},
57 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82543GC_COPPER},
58 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82544EI_COPPER},
59 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82544EI_FIBER},
60 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82544GC_COPPER},
61 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82544GC_LOM},
62 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82540EM},
63 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82545EM_COPPER},
Paul Gortmaker7d13b8d2008-07-09 17:50:45 -040064 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82545GM_COPPER},
wdenk4e112c12003-06-03 23:54:09 +000065 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82546EB_COPPER},
66 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82545EM_FIBER},
67 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82546EB_FIBER},
Reinhard Arlt1140ea52009-12-04 09:52:17 +010068 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82546GB_COPPER},
wdenk4e112c12003-06-03 23:54:09 +000069 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82540EM_LOM},
Andre Schwarz68c2a302008-03-06 16:45:44 +010070 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82541ER},
Wolfgang Grandegger8562c382008-05-28 19:55:19 +020071 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82541GI_LF},
Roy Zang28f7a052009-07-31 13:34:02 +080072 /* E1000 PCIe card */
73 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_COPPER},
74 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_FIBER },
75 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_SERDES },
76 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_QUAD_COPPER},
77 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571PT_QUAD_COPPER},
78 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_QUAD_FIBER},
79 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_QUAD_COPPER_LOWPROFILE},
80 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_SERDES_DUAL},
81 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_SERDES_QUAD},
82 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82572EI_COPPER},
83 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82572EI_FIBER},
84 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82572EI_SERDES},
85 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82572EI},
86 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82573E},
87 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82573E_IAMT},
88 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82573L},
Roy Zang181119b2011-01-21 11:29:38 +080089 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82574L},
Roy Zang28f7a052009-07-31 13:34:02 +080090 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82546GB_QUAD_COPPER_KSP3},
91 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80003ES2LAN_COPPER_DPT},
92 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80003ES2LAN_SERDES_DPT},
93 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80003ES2LAN_COPPER_SPT},
94 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80003ES2LAN_SERDES_SPT},
Marek Vasut74a13c22014-08-08 07:41:39 -070095 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I210_COPPER},
96 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I210_COPPER_FLASHLESS},
97 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I210_SERDES},
98 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I210_SERDES_FLASHLESS},
99 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I210_1000BASEKX},
100
Stefan Althoeferbc6d2fc2008-12-20 19:40:41 +0100101 {}
wdenk4e112c12003-06-03 23:54:09 +0000102};
103
104/* Function forward declarations */
105static int e1000_setup_link(struct eth_device *nic);
106static int e1000_setup_fiber_link(struct eth_device *nic);
107static int e1000_setup_copper_link(struct eth_device *nic);
108static int e1000_phy_setup_autoneg(struct e1000_hw *hw);
109static void e1000_config_collision_dist(struct e1000_hw *hw);
110static int e1000_config_mac_to_phy(struct e1000_hw *hw);
111static int e1000_config_fc_after_link_up(struct e1000_hw *hw);
112static int e1000_check_for_link(struct eth_device *nic);
113static int e1000_wait_autoneg(struct e1000_hw *hw);
Roy Zang28f7a052009-07-31 13:34:02 +0800114static int e1000_get_speed_and_duplex(struct e1000_hw *hw, uint16_t * speed,
wdenk4e112c12003-06-03 23:54:09 +0000115 uint16_t * duplex);
116static int e1000_read_phy_reg(struct e1000_hw *hw, uint32_t reg_addr,
117 uint16_t * phy_data);
118static int e1000_write_phy_reg(struct e1000_hw *hw, uint32_t reg_addr,
119 uint16_t phy_data);
Roy Zang28f7a052009-07-31 13:34:02 +0800120static int32_t e1000_phy_hw_reset(struct e1000_hw *hw);
wdenk4e112c12003-06-03 23:54:09 +0000121static int e1000_phy_reset(struct e1000_hw *hw);
122static int e1000_detect_gig_phy(struct e1000_hw *hw);
Roy Zang28f7a052009-07-31 13:34:02 +0800123static void e1000_set_media_type(struct e1000_hw *hw);
wdenk4e112c12003-06-03 23:54:09 +0000124
Roy Zang28f7a052009-07-31 13:34:02 +0800125static int32_t e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask);
126static int32_t e1000_check_phy_reset_block(struct e1000_hw *hw);
wdenk4e112c12003-06-03 23:54:09 +0000127
Rojhalat Ibrahimbbcd2b02013-10-07 18:30:39 +0200128#ifndef CONFIG_E1000_NO_NVM
129static void e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw);
Roy Zang9b7c4302009-08-11 03:48:05 +0800130static int32_t e1000_read_eeprom(struct e1000_hw *hw, uint16_t offset,
131 uint16_t words,
132 uint16_t *data);
wdenk4e112c12003-06-03 23:54:09 +0000133/******************************************************************************
134 * Raises the EEPROM's clock input.
135 *
136 * hw - Struct containing variables accessed by shared code
137 * eecd - EECD's current value
138 *****************************************************************************/
Kyle Moffett142cbf82011-10-18 11:05:28 +0000139void e1000_raise_ee_clk(struct e1000_hw *hw, uint32_t * eecd)
wdenk4e112c12003-06-03 23:54:09 +0000140{
141 /* Raise the clock input to the EEPROM (by setting the SK bit), and then
142 * wait 50 microseconds.
143 */
144 *eecd = *eecd | E1000_EECD_SK;
145 E1000_WRITE_REG(hw, EECD, *eecd);
146 E1000_WRITE_FLUSH(hw);
147 udelay(50);
148}
149
150/******************************************************************************
151 * Lowers the EEPROM's clock input.
152 *
wdenk57b2d802003-06-27 21:31:46 +0000153 * hw - Struct containing variables accessed by shared code
wdenk4e112c12003-06-03 23:54:09 +0000154 * eecd - EECD's current value
155 *****************************************************************************/
Kyle Moffett142cbf82011-10-18 11:05:28 +0000156void e1000_lower_ee_clk(struct e1000_hw *hw, uint32_t * eecd)
wdenk4e112c12003-06-03 23:54:09 +0000157{
wdenk57b2d802003-06-27 21:31:46 +0000158 /* Lower the clock input to the EEPROM (by clearing the SK bit), and then
159 * wait 50 microseconds.
wdenk4e112c12003-06-03 23:54:09 +0000160 */
161 *eecd = *eecd & ~E1000_EECD_SK;
162 E1000_WRITE_REG(hw, EECD, *eecd);
163 E1000_WRITE_FLUSH(hw);
164 udelay(50);
165}
166
167/******************************************************************************
168 * Shift data bits out to the EEPROM.
169 *
170 * hw - Struct containing variables accessed by shared code
171 * data - data to send to the EEPROM
172 * count - number of bits to shift out
173 *****************************************************************************/
174static void
175e1000_shift_out_ee_bits(struct e1000_hw *hw, uint16_t data, uint16_t count)
176{
177 uint32_t eecd;
178 uint32_t mask;
179
180 /* We need to shift "count" bits out to the EEPROM. So, value in the
181 * "data" parameter will be shifted out to the EEPROM one bit at a time.
wdenk57b2d802003-06-27 21:31:46 +0000182 * In order to do this, "data" must be broken down into bits.
wdenk4e112c12003-06-03 23:54:09 +0000183 */
184 mask = 0x01 << (count - 1);
185 eecd = E1000_READ_REG(hw, EECD);
186 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
187 do {
188 /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
189 * and then raising and then lowering the clock (the SK bit controls
190 * the clock input to the EEPROM). A "0" is shifted out to the EEPROM
191 * by setting "DI" to "0" and then raising and then lowering the clock.
192 */
193 eecd &= ~E1000_EECD_DI;
194
195 if (data & mask)
196 eecd |= E1000_EECD_DI;
197
198 E1000_WRITE_REG(hw, EECD, eecd);
199 E1000_WRITE_FLUSH(hw);
200
201 udelay(50);
202
203 e1000_raise_ee_clk(hw, &eecd);
204 e1000_lower_ee_clk(hw, &eecd);
205
206 mask = mask >> 1;
207
208 } while (mask);
209
210 /* We leave the "DI" bit set to "0" when we leave this routine. */
211 eecd &= ~E1000_EECD_DI;
212 E1000_WRITE_REG(hw, EECD, eecd);
213}
214
215/******************************************************************************
216 * Shift data bits in from the EEPROM
217 *
218 * hw - Struct containing variables accessed by shared code
219 *****************************************************************************/
220static uint16_t
Roy Zang28f7a052009-07-31 13:34:02 +0800221e1000_shift_in_ee_bits(struct e1000_hw *hw, uint16_t count)
wdenk4e112c12003-06-03 23:54:09 +0000222{
223 uint32_t eecd;
224 uint32_t i;
225 uint16_t data;
226
Roy Zang28f7a052009-07-31 13:34:02 +0800227 /* In order to read a register from the EEPROM, we need to shift 'count'
228 * bits in from the EEPROM. Bits are "shifted in" by raising the clock
229 * input to the EEPROM (setting the SK bit), and then reading the
230 * value of the "DO" bit. During this "shifting in" process the
231 * "DI" bit should always be clear.
wdenk4e112c12003-06-03 23:54:09 +0000232 */
233
234 eecd = E1000_READ_REG(hw, EECD);
235
236 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
237 data = 0;
238
Roy Zang28f7a052009-07-31 13:34:02 +0800239 for (i = 0; i < count; i++) {
wdenk4e112c12003-06-03 23:54:09 +0000240 data = data << 1;
241 e1000_raise_ee_clk(hw, &eecd);
242
243 eecd = E1000_READ_REG(hw, EECD);
244
245 eecd &= ~(E1000_EECD_DI);
246 if (eecd & E1000_EECD_DO)
247 data |= 1;
248
249 e1000_lower_ee_clk(hw, &eecd);
250 }
251
252 return data;
253}
254
255/******************************************************************************
Roy Zang28f7a052009-07-31 13:34:02 +0800256 * Returns EEPROM to a "standby" state
wdenk4e112c12003-06-03 23:54:09 +0000257 *
258 * hw - Struct containing variables accessed by shared code
wdenk4e112c12003-06-03 23:54:09 +0000259 *****************************************************************************/
Kyle Moffett142cbf82011-10-18 11:05:28 +0000260void e1000_standby_eeprom(struct e1000_hw *hw)
wdenk4e112c12003-06-03 23:54:09 +0000261{
Roy Zang28f7a052009-07-31 13:34:02 +0800262 struct e1000_eeprom_info *eeprom = &hw->eeprom;
wdenk4e112c12003-06-03 23:54:09 +0000263 uint32_t eecd;
264
265 eecd = E1000_READ_REG(hw, EECD);
266
Roy Zang28f7a052009-07-31 13:34:02 +0800267 if (eeprom->type == e1000_eeprom_microwire) {
268 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
269 E1000_WRITE_REG(hw, EECD, eecd);
270 E1000_WRITE_FLUSH(hw);
271 udelay(eeprom->delay_usec);
wdenk4e112c12003-06-03 23:54:09 +0000272
Roy Zang28f7a052009-07-31 13:34:02 +0800273 /* Clock high */
274 eecd |= E1000_EECD_SK;
275 E1000_WRITE_REG(hw, EECD, eecd);
276 E1000_WRITE_FLUSH(hw);
277 udelay(eeprom->delay_usec);
278
279 /* Select EEPROM */
280 eecd |= E1000_EECD_CS;
281 E1000_WRITE_REG(hw, EECD, eecd);
282 E1000_WRITE_FLUSH(hw);
283 udelay(eeprom->delay_usec);
284
285 /* Clock low */
286 eecd &= ~E1000_EECD_SK;
287 E1000_WRITE_REG(hw, EECD, eecd);
288 E1000_WRITE_FLUSH(hw);
289 udelay(eeprom->delay_usec);
290 } else if (eeprom->type == e1000_eeprom_spi) {
291 /* Toggle CS to flush commands */
292 eecd |= E1000_EECD_CS;
293 E1000_WRITE_REG(hw, EECD, eecd);
294 E1000_WRITE_FLUSH(hw);
295 udelay(eeprom->delay_usec);
296 eecd &= ~E1000_EECD_CS;
297 E1000_WRITE_REG(hw, EECD, eecd);
298 E1000_WRITE_FLUSH(hw);
299 udelay(eeprom->delay_usec);
300 }
301}
302
303/***************************************************************************
304* Description: Determines if the onboard NVM is FLASH or EEPROM.
305*
306* hw - Struct containing variables accessed by shared code
307****************************************************************************/
York Sun4a598092013-04-01 11:29:11 -0700308static bool e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw)
Roy Zang28f7a052009-07-31 13:34:02 +0800309{
310 uint32_t eecd = 0;
311
312 DEBUGFUNC();
313
314 if (hw->mac_type == e1000_ich8lan)
York Sun4a598092013-04-01 11:29:11 -0700315 return false;
Roy Zang28f7a052009-07-31 13:34:02 +0800316
Roy Zang181119b2011-01-21 11:29:38 +0800317 if (hw->mac_type == e1000_82573 || hw->mac_type == e1000_82574) {
Roy Zang28f7a052009-07-31 13:34:02 +0800318 eecd = E1000_READ_REG(hw, EECD);
319
320 /* Isolate bits 15 & 16 */
321 eecd = ((eecd >> 15) & 0x03);
322
323 /* If both bits are set, device is Flash type */
324 if (eecd == 0x03)
York Sun4a598092013-04-01 11:29:11 -0700325 return false;
Roy Zang28f7a052009-07-31 13:34:02 +0800326 }
York Sun4a598092013-04-01 11:29:11 -0700327 return true;
wdenk4e112c12003-06-03 23:54:09 +0000328}
329
330/******************************************************************************
Roy Zang28f7a052009-07-31 13:34:02 +0800331 * Prepares EEPROM for access
wdenk57b2d802003-06-27 21:31:46 +0000332 *
wdenk4e112c12003-06-03 23:54:09 +0000333 * hw - Struct containing variables accessed by shared code
Roy Zang28f7a052009-07-31 13:34:02 +0800334 *
335 * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
336 * function should be called before issuing a command to the EEPROM.
wdenk4e112c12003-06-03 23:54:09 +0000337 *****************************************************************************/
Kyle Moffett142cbf82011-10-18 11:05:28 +0000338int32_t e1000_acquire_eeprom(struct e1000_hw *hw)
wdenk4e112c12003-06-03 23:54:09 +0000339{
Roy Zang28f7a052009-07-31 13:34:02 +0800340 struct e1000_eeprom_info *eeprom = &hw->eeprom;
341 uint32_t eecd, i = 0;
342
Timur Tabiedc45b52009-08-17 15:55:38 -0500343 DEBUGFUNC();
wdenk4e112c12003-06-03 23:54:09 +0000344
Roy Zang28f7a052009-07-31 13:34:02 +0800345 if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM))
346 return -E1000_ERR_SWFW_SYNC;
wdenk4e112c12003-06-03 23:54:09 +0000347 eecd = E1000_READ_REG(hw, EECD);
348
Marek Vasut74a13c22014-08-08 07:41:39 -0700349 if (hw->mac_type != e1000_82573 && hw->mac_type != e1000_82574) {
Roy Zang28f7a052009-07-31 13:34:02 +0800350 /* Request EEPROM Access */
351 if (hw->mac_type > e1000_82544) {
352 eecd |= E1000_EECD_REQ;
353 E1000_WRITE_REG(hw, EECD, eecd);
354 eecd = E1000_READ_REG(hw, EECD);
355 while ((!(eecd & E1000_EECD_GNT)) &&
356 (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
357 i++;
358 udelay(5);
359 eecd = E1000_READ_REG(hw, EECD);
360 }
361 if (!(eecd & E1000_EECD_GNT)) {
362 eecd &= ~E1000_EECD_REQ;
363 E1000_WRITE_REG(hw, EECD, eecd);
364 DEBUGOUT("Could not acquire EEPROM grant\n");
365 return -E1000_ERR_EEPROM;
366 }
367 }
368 }
wdenk4e112c12003-06-03 23:54:09 +0000369
Roy Zang28f7a052009-07-31 13:34:02 +0800370 /* Setup EEPROM for Read/Write */
wdenk4e112c12003-06-03 23:54:09 +0000371
Roy Zang28f7a052009-07-31 13:34:02 +0800372 if (eeprom->type == e1000_eeprom_microwire) {
373 /* Clear SK and DI */
374 eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
375 E1000_WRITE_REG(hw, EECD, eecd);
wdenk4e112c12003-06-03 23:54:09 +0000376
Roy Zang28f7a052009-07-31 13:34:02 +0800377 /* Set CS */
378 eecd |= E1000_EECD_CS;
379 E1000_WRITE_REG(hw, EECD, eecd);
380 } else if (eeprom->type == e1000_eeprom_spi) {
381 /* Clear SK and CS */
382 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
383 E1000_WRITE_REG(hw, EECD, eecd);
384 udelay(1);
385 }
386
387 return E1000_SUCCESS;
wdenk4e112c12003-06-03 23:54:09 +0000388}
389
390/******************************************************************************
Roy Zang28f7a052009-07-31 13:34:02 +0800391 * Sets up eeprom variables in the hw struct. Must be called after mac_type
392 * is configured. Additionally, if this is ICH8, the flash controller GbE
393 * registers must be mapped, or this will crash.
wdenk4e112c12003-06-03 23:54:09 +0000394 *
395 * hw - Struct containing variables accessed by shared code
wdenk4e112c12003-06-03 23:54:09 +0000396 *****************************************************************************/
Roy Zang28f7a052009-07-31 13:34:02 +0800397static int32_t e1000_init_eeprom_params(struct e1000_hw *hw)
wdenk4e112c12003-06-03 23:54:09 +0000398{
Roy Zang28f7a052009-07-31 13:34:02 +0800399 struct e1000_eeprom_info *eeprom = &hw->eeprom;
Marek Vasut74a13c22014-08-08 07:41:39 -0700400 uint32_t eecd;
Roy Zang28f7a052009-07-31 13:34:02 +0800401 int32_t ret_val = E1000_SUCCESS;
402 uint16_t eeprom_size;
wdenk4e112c12003-06-03 23:54:09 +0000403
Marek Vasut74a13c22014-08-08 07:41:39 -0700404 if (hw->mac_type == e1000_igb)
405 eecd = E1000_READ_REG(hw, I210_EECD);
406 else
407 eecd = E1000_READ_REG(hw, EECD);
408
Timur Tabiedc45b52009-08-17 15:55:38 -0500409 DEBUGFUNC();
Roy Zang28f7a052009-07-31 13:34:02 +0800410
411 switch (hw->mac_type) {
412 case e1000_82542_rev2_0:
413 case e1000_82542_rev2_1:
414 case e1000_82543:
415 case e1000_82544:
416 eeprom->type = e1000_eeprom_microwire;
417 eeprom->word_size = 64;
418 eeprom->opcode_bits = 3;
419 eeprom->address_bits = 6;
420 eeprom->delay_usec = 50;
York Sun4a598092013-04-01 11:29:11 -0700421 eeprom->use_eerd = false;
422 eeprom->use_eewr = false;
Roy Zang28f7a052009-07-31 13:34:02 +0800423 break;
424 case e1000_82540:
425 case e1000_82545:
426 case e1000_82545_rev_3:
427 case e1000_82546:
428 case e1000_82546_rev_3:
429 eeprom->type = e1000_eeprom_microwire;
430 eeprom->opcode_bits = 3;
431 eeprom->delay_usec = 50;
432 if (eecd & E1000_EECD_SIZE) {
433 eeprom->word_size = 256;
434 eeprom->address_bits = 8;
435 } else {
436 eeprom->word_size = 64;
437 eeprom->address_bits = 6;
438 }
York Sun4a598092013-04-01 11:29:11 -0700439 eeprom->use_eerd = false;
440 eeprom->use_eewr = false;
Roy Zang28f7a052009-07-31 13:34:02 +0800441 break;
442 case e1000_82541:
443 case e1000_82541_rev_2:
444 case e1000_82547:
445 case e1000_82547_rev_2:
446 if (eecd & E1000_EECD_TYPE) {
447 eeprom->type = e1000_eeprom_spi;
448 eeprom->opcode_bits = 8;
449 eeprom->delay_usec = 1;
450 if (eecd & E1000_EECD_ADDR_BITS) {
451 eeprom->page_size = 32;
452 eeprom->address_bits = 16;
453 } else {
454 eeprom->page_size = 8;
455 eeprom->address_bits = 8;
456 }
457 } else {
458 eeprom->type = e1000_eeprom_microwire;
459 eeprom->opcode_bits = 3;
460 eeprom->delay_usec = 50;
461 if (eecd & E1000_EECD_ADDR_BITS) {
462 eeprom->word_size = 256;
463 eeprom->address_bits = 8;
464 } else {
465 eeprom->word_size = 64;
466 eeprom->address_bits = 6;
467 }
468 }
York Sun4a598092013-04-01 11:29:11 -0700469 eeprom->use_eerd = false;
470 eeprom->use_eewr = false;
Roy Zang28f7a052009-07-31 13:34:02 +0800471 break;
472 case e1000_82571:
473 case e1000_82572:
474 eeprom->type = e1000_eeprom_spi;
475 eeprom->opcode_bits = 8;
476 eeprom->delay_usec = 1;
477 if (eecd & E1000_EECD_ADDR_BITS) {
478 eeprom->page_size = 32;
479 eeprom->address_bits = 16;
480 } else {
481 eeprom->page_size = 8;
482 eeprom->address_bits = 8;
483 }
York Sun4a598092013-04-01 11:29:11 -0700484 eeprom->use_eerd = false;
485 eeprom->use_eewr = false;
Roy Zang28f7a052009-07-31 13:34:02 +0800486 break;
487 case e1000_82573:
Roy Zang181119b2011-01-21 11:29:38 +0800488 case e1000_82574:
Roy Zang28f7a052009-07-31 13:34:02 +0800489 eeprom->type = e1000_eeprom_spi;
490 eeprom->opcode_bits = 8;
491 eeprom->delay_usec = 1;
492 if (eecd & E1000_EECD_ADDR_BITS) {
493 eeprom->page_size = 32;
494 eeprom->address_bits = 16;
495 } else {
496 eeprom->page_size = 8;
497 eeprom->address_bits = 8;
wdenk4e112c12003-06-03 23:54:09 +0000498 }
York Sun4a598092013-04-01 11:29:11 -0700499 if (e1000_is_onboard_nvm_eeprom(hw) == false) {
Marek Vasut74a13c22014-08-08 07:41:39 -0700500 eeprom->use_eerd = true;
501 eeprom->use_eewr = true;
502
Roy Zang28f7a052009-07-31 13:34:02 +0800503 eeprom->type = e1000_eeprom_flash;
504 eeprom->word_size = 2048;
505
506 /* Ensure that the Autonomous FLASH update bit is cleared due to
507 * Flash update issue on parts which use a FLASH for NVM. */
508 eecd &= ~E1000_EECD_AUPDEN;
wdenk4e112c12003-06-03 23:54:09 +0000509 E1000_WRITE_REG(hw, EECD, eecd);
wdenk4e112c12003-06-03 23:54:09 +0000510 }
Roy Zang28f7a052009-07-31 13:34:02 +0800511 break;
512 case e1000_80003es2lan:
513 eeprom->type = e1000_eeprom_spi;
514 eeprom->opcode_bits = 8;
515 eeprom->delay_usec = 1;
516 if (eecd & E1000_EECD_ADDR_BITS) {
517 eeprom->page_size = 32;
518 eeprom->address_bits = 16;
519 } else {
520 eeprom->page_size = 8;
521 eeprom->address_bits = 8;
522 }
York Sun4a598092013-04-01 11:29:11 -0700523 eeprom->use_eerd = true;
524 eeprom->use_eewr = false;
Roy Zang28f7a052009-07-31 13:34:02 +0800525 break;
Marek Vasut74a13c22014-08-08 07:41:39 -0700526 case e1000_igb:
527 /* i210 has 4k of iNVM mapped as EEPROM */
528 eeprom->type = e1000_eeprom_invm;
529 eeprom->opcode_bits = 8;
530 eeprom->delay_usec = 1;
531 eeprom->page_size = 32;
532 eeprom->address_bits = 16;
533 eeprom->use_eerd = true;
534 eeprom->use_eewr = false;
535 break;
wdenk4e112c12003-06-03 23:54:09 +0000536
Roy Zang28f7a052009-07-31 13:34:02 +0800537 /* ich8lan does not support currently. if needed, please
538 * add corresponding code and functions.
539 */
540#if 0
541 case e1000_ich8lan:
542 {
543 int32_t i = 0;
wdenk4e112c12003-06-03 23:54:09 +0000544
Roy Zang28f7a052009-07-31 13:34:02 +0800545 eeprom->type = e1000_eeprom_ich8;
York Sun4a598092013-04-01 11:29:11 -0700546 eeprom->use_eerd = false;
547 eeprom->use_eewr = false;
Roy Zang28f7a052009-07-31 13:34:02 +0800548 eeprom->word_size = E1000_SHADOW_RAM_WORDS;
549 uint32_t flash_size = E1000_READ_ICH_FLASH_REG(hw,
550 ICH_FLASH_GFPREG);
551 /* Zero the shadow RAM structure. But don't load it from NVM
552 * so as to save time for driver init */
553 if (hw->eeprom_shadow_ram != NULL) {
554 for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
York Sun4a598092013-04-01 11:29:11 -0700555 hw->eeprom_shadow_ram[i].modified = false;
Roy Zang28f7a052009-07-31 13:34:02 +0800556 hw->eeprom_shadow_ram[i].eeprom_word = 0xFFFF;
557 }
558 }
wdenk4e112c12003-06-03 23:54:09 +0000559
Roy Zang28f7a052009-07-31 13:34:02 +0800560 hw->flash_base_addr = (flash_size & ICH_GFPREG_BASE_MASK) *
561 ICH_FLASH_SECTOR_SIZE;
wdenk4e112c12003-06-03 23:54:09 +0000562
Roy Zang28f7a052009-07-31 13:34:02 +0800563 hw->flash_bank_size = ((flash_size >> 16)
564 & ICH_GFPREG_BASE_MASK) + 1;
565 hw->flash_bank_size -= (flash_size & ICH_GFPREG_BASE_MASK);
wdenk4e112c12003-06-03 23:54:09 +0000566
Roy Zang28f7a052009-07-31 13:34:02 +0800567 hw->flash_bank_size *= ICH_FLASH_SECTOR_SIZE;
568
569 hw->flash_bank_size /= 2 * sizeof(uint16_t);
570 break;
571 }
572#endif
573 default:
574 break;
wdenk4e112c12003-06-03 23:54:09 +0000575 }
576
Marek Vasut74a13c22014-08-08 07:41:39 -0700577 if (eeprom->type == e1000_eeprom_spi ||
578 eeprom->type == e1000_eeprom_invm) {
Roy Zang28f7a052009-07-31 13:34:02 +0800579 /* eeprom_size will be an enum [0..8] that maps
580 * to eeprom sizes 128B to
581 * 32KB (incremented by powers of 2).
582 */
583 if (hw->mac_type <= e1000_82547_rev_2) {
584 /* Set to default value for initial eeprom read. */
585 eeprom->word_size = 64;
586 ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1,
587 &eeprom_size);
588 if (ret_val)
589 return ret_val;
590 eeprom_size = (eeprom_size & EEPROM_SIZE_MASK)
591 >> EEPROM_SIZE_SHIFT;
592 /* 256B eeprom size was not supported in earlier
593 * hardware, so we bump eeprom_size up one to
594 * ensure that "1" (which maps to 256B) is never
595 * the result used in the shifting logic below. */
596 if (eeprom_size)
597 eeprom_size++;
598 } else {
599 eeprom_size = (uint16_t)((eecd &
600 E1000_EECD_SIZE_EX_MASK) >>
601 E1000_EECD_SIZE_EX_SHIFT);
602 }
603
604 eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT);
605 }
606 return ret_val;
wdenk4e112c12003-06-03 23:54:09 +0000607}
608
Roy Zang28f7a052009-07-31 13:34:02 +0800609/******************************************************************************
610 * Polls the status bit (bit 1) of the EERD to determine when the read is done.
611 *
612 * hw - Struct containing variables accessed by shared code
613 *****************************************************************************/
614static int32_t
615e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd)
wdenk4e112c12003-06-03 23:54:09 +0000616{
Roy Zang28f7a052009-07-31 13:34:02 +0800617 uint32_t attempts = 100000;
618 uint32_t i, reg = 0;
619 int32_t done = E1000_ERR_EEPROM;
wdenk4e112c12003-06-03 23:54:09 +0000620
Roy Zang28f7a052009-07-31 13:34:02 +0800621 for (i = 0; i < attempts; i++) {
Marek Vasut74a13c22014-08-08 07:41:39 -0700622 if (eerd == E1000_EEPROM_POLL_READ) {
623 if (hw->mac_type == e1000_igb)
624 reg = E1000_READ_REG(hw, I210_EERD);
625 else
626 reg = E1000_READ_REG(hw, EERD);
627 } else {
628 if (hw->mac_type == e1000_igb)
629 reg = E1000_READ_REG(hw, I210_EEWR);
630 else
631 reg = E1000_READ_REG(hw, EEWR);
632 }
Roy Zang28f7a052009-07-31 13:34:02 +0800633
634 if (reg & E1000_EEPROM_RW_REG_DONE) {
635 done = E1000_SUCCESS;
636 break;
637 }
638 udelay(5);
639 }
640
641 return done;
wdenk4e112c12003-06-03 23:54:09 +0000642}
643
Roy Zang28f7a052009-07-31 13:34:02 +0800644/******************************************************************************
645 * Reads a 16 bit word from the EEPROM using the EERD register.
646 *
647 * hw - Struct containing variables accessed by shared code
648 * offset - offset of word in the EEPROM to read
649 * data - word read from the EEPROM
650 * words - number of words to read
651 *****************************************************************************/
652static int32_t
653e1000_read_eeprom_eerd(struct e1000_hw *hw,
654 uint16_t offset,
655 uint16_t words,
656 uint16_t *data)
wdenk4e112c12003-06-03 23:54:09 +0000657{
Roy Zang28f7a052009-07-31 13:34:02 +0800658 uint32_t i, eerd = 0;
659 int32_t error = 0;
wdenk4e112c12003-06-03 23:54:09 +0000660
Roy Zang28f7a052009-07-31 13:34:02 +0800661 for (i = 0; i < words; i++) {
662 eerd = ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) +
663 E1000_EEPROM_RW_REG_START;
664
Marek Vasut74a13c22014-08-08 07:41:39 -0700665 if (hw->mac_type == e1000_igb)
666 E1000_WRITE_REG(hw, I210_EERD, eerd);
667 else
668 E1000_WRITE_REG(hw, EERD, eerd);
669
Roy Zang28f7a052009-07-31 13:34:02 +0800670 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_READ);
671
672 if (error)
673 break;
Marek Vasut74a13c22014-08-08 07:41:39 -0700674
675 if (hw->mac_type == e1000_igb) {
676 data[i] = (E1000_READ_REG(hw, I210_EERD) >>
Roy Zang28f7a052009-07-31 13:34:02 +0800677 E1000_EEPROM_RW_REG_DATA);
Marek Vasut74a13c22014-08-08 07:41:39 -0700678 } else {
679 data[i] = (E1000_READ_REG(hw, EERD) >>
680 E1000_EEPROM_RW_REG_DATA);
681 }
Roy Zang28f7a052009-07-31 13:34:02 +0800682
wdenk4e112c12003-06-03 23:54:09 +0000683 }
Roy Zang28f7a052009-07-31 13:34:02 +0800684
685 return error;
wdenk4e112c12003-06-03 23:54:09 +0000686}
687
Kyle Moffett142cbf82011-10-18 11:05:28 +0000688void e1000_release_eeprom(struct e1000_hw *hw)
wdenk4e112c12003-06-03 23:54:09 +0000689{
690 uint32_t eecd;
wdenk4e112c12003-06-03 23:54:09 +0000691
Roy Zang28f7a052009-07-31 13:34:02 +0800692 DEBUGFUNC();
693
694 eecd = E1000_READ_REG(hw, EECD);
695
696 if (hw->eeprom.type == e1000_eeprom_spi) {
697 eecd |= E1000_EECD_CS; /* Pull CS high */
698 eecd &= ~E1000_EECD_SK; /* Lower SCK */
699
wdenk4e112c12003-06-03 23:54:09 +0000700 E1000_WRITE_REG(hw, EECD, eecd);
Roy Zang28f7a052009-07-31 13:34:02 +0800701
702 udelay(hw->eeprom.delay_usec);
703 } else if (hw->eeprom.type == e1000_eeprom_microwire) {
704 /* cleanup eeprom */
705
706 /* CS on Microwire is active-high */
707 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
708
709 E1000_WRITE_REG(hw, EECD, eecd);
710
711 /* Rising edge of clock */
712 eecd |= E1000_EECD_SK;
713 E1000_WRITE_REG(hw, EECD, eecd);
714 E1000_WRITE_FLUSH(hw);
715 udelay(hw->eeprom.delay_usec);
716
717 /* Falling edge of clock */
718 eecd &= ~E1000_EECD_SK;
719 E1000_WRITE_REG(hw, EECD, eecd);
720 E1000_WRITE_FLUSH(hw);
721 udelay(hw->eeprom.delay_usec);
wdenk4e112c12003-06-03 23:54:09 +0000722 }
wdenk4e112c12003-06-03 23:54:09 +0000723
724 /* Stop requesting EEPROM access */
725 if (hw->mac_type > e1000_82544) {
wdenk4e112c12003-06-03 23:54:09 +0000726 eecd &= ~E1000_EECD_REQ;
727 E1000_WRITE_REG(hw, EECD, eecd);
728 }
wdenk4e112c12003-06-03 23:54:09 +0000729}
wdenk4e112c12003-06-03 23:54:09 +0000730/******************************************************************************
Roy Zang28f7a052009-07-31 13:34:02 +0800731 * Reads a 16 bit word from the EEPROM.
wdenk57b2d802003-06-27 21:31:46 +0000732 *
wdenk4e112c12003-06-03 23:54:09 +0000733 * hw - Struct containing variables accessed by shared code
wdenk4e112c12003-06-03 23:54:09 +0000734 *****************************************************************************/
Roy Zang28f7a052009-07-31 13:34:02 +0800735static int32_t
736e1000_spi_eeprom_ready(struct e1000_hw *hw)
wdenk4e112c12003-06-03 23:54:09 +0000737{
Roy Zang28f7a052009-07-31 13:34:02 +0800738 uint16_t retry_count = 0;
739 uint8_t spi_stat_reg;
wdenk4e112c12003-06-03 23:54:09 +0000740
741 DEBUGFUNC();
742
Roy Zang28f7a052009-07-31 13:34:02 +0800743 /* Read "Status Register" repeatedly until the LSB is cleared. The
744 * EEPROM will signal that the command has been completed by clearing
745 * bit 0 of the internal status register. If it's not cleared within
746 * 5 milliseconds, then error out.
747 */
748 retry_count = 0;
749 do {
750 e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
751 hw->eeprom.opcode_bits);
752 spi_stat_reg = (uint8_t)e1000_shift_in_ee_bits(hw, 8);
753 if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
754 break;
wdenk57b2d802003-06-27 21:31:46 +0000755
Roy Zang28f7a052009-07-31 13:34:02 +0800756 udelay(5);
757 retry_count += 5;
758
759 e1000_standby_eeprom(hw);
760 } while (retry_count < EEPROM_MAX_RETRY_SPI);
761
762 /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
763 * only 0-5mSec on 5V devices)
764 */
765 if (retry_count >= EEPROM_MAX_RETRY_SPI) {
766 DEBUGOUT("SPI EEPROM Status error\n");
wdenk4e112c12003-06-03 23:54:09 +0000767 return -E1000_ERR_EEPROM;
768 }
Roy Zang28f7a052009-07-31 13:34:02 +0800769
770 return E1000_SUCCESS;
wdenk4e112c12003-06-03 23:54:09 +0000771}
772
773/******************************************************************************
Roy Zang28f7a052009-07-31 13:34:02 +0800774 * Reads a 16 bit word from the EEPROM.
wdenk4e112c12003-06-03 23:54:09 +0000775 *
Roy Zang28f7a052009-07-31 13:34:02 +0800776 * hw - Struct containing variables accessed by shared code
777 * offset - offset of word in the EEPROM to read
778 * data - word read from the EEPROM
wdenk4e112c12003-06-03 23:54:09 +0000779 *****************************************************************************/
Roy Zang28f7a052009-07-31 13:34:02 +0800780static int32_t
781e1000_read_eeprom(struct e1000_hw *hw, uint16_t offset,
782 uint16_t words, uint16_t *data)
wdenk4e112c12003-06-03 23:54:09 +0000783{
Roy Zang28f7a052009-07-31 13:34:02 +0800784 struct e1000_eeprom_info *eeprom = &hw->eeprom;
785 uint32_t i = 0;
wdenk4e112c12003-06-03 23:54:09 +0000786
787 DEBUGFUNC();
788
Roy Zang28f7a052009-07-31 13:34:02 +0800789 /* If eeprom is not yet detected, do so now */
790 if (eeprom->word_size == 0)
791 e1000_init_eeprom_params(hw);
792
793 /* A check for invalid values: offset too large, too many words,
794 * and not enough words.
795 */
796 if ((offset >= eeprom->word_size) ||
797 (words > eeprom->word_size - offset) ||
798 (words == 0)) {
799 DEBUGOUT("\"words\" parameter out of bounds."
800 "Words = %d, size = %d\n", offset, eeprom->word_size);
801 return -E1000_ERR_EEPROM;
802 }
803
804 /* EEPROM's that don't use EERD to read require us to bit-bang the SPI
805 * directly. In this case, we need to acquire the EEPROM so that
806 * FW or other port software does not interrupt.
807 */
York Sun4a598092013-04-01 11:29:11 -0700808 if (e1000_is_onboard_nvm_eeprom(hw) == true &&
809 hw->eeprom.use_eerd == false) {
Roy Zang28f7a052009-07-31 13:34:02 +0800810
811 /* Prepare the EEPROM for bit-bang reading */
812 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
813 return -E1000_ERR_EEPROM;
814 }
815
816 /* Eerd register EEPROM access requires no eeprom aquire/release */
York Sun4a598092013-04-01 11:29:11 -0700817 if (eeprom->use_eerd == true)
Roy Zang28f7a052009-07-31 13:34:02 +0800818 return e1000_read_eeprom_eerd(hw, offset, words, data);
819
820 /* ich8lan does not support currently. if needed, please
821 * add corresponding code and functions.
822 */
823#if 0
824 /* ICH EEPROM access is done via the ICH flash controller */
825 if (eeprom->type == e1000_eeprom_ich8)
826 return e1000_read_eeprom_ich8(hw, offset, words, data);
827#endif
828 /* Set up the SPI or Microwire EEPROM for bit-bang reading. We have
829 * acquired the EEPROM at this point, so any returns should relase it */
830 if (eeprom->type == e1000_eeprom_spi) {
831 uint16_t word_in;
832 uint8_t read_opcode = EEPROM_READ_OPCODE_SPI;
833
834 if (e1000_spi_eeprom_ready(hw)) {
835 e1000_release_eeprom(hw);
836 return -E1000_ERR_EEPROM;
837 }
838
839 e1000_standby_eeprom(hw);
840
841 /* Some SPI eeproms use the 8th address bit embedded in
842 * the opcode */
843 if ((eeprom->address_bits == 8) && (offset >= 128))
844 read_opcode |= EEPROM_A8_OPCODE_SPI;
845
846 /* Send the READ command (opcode + addr) */
847 e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
848 e1000_shift_out_ee_bits(hw, (uint16_t)(offset*2),
849 eeprom->address_bits);
850
851 /* Read the data. The address of the eeprom internally
852 * increments with each byte (spi) being read, saving on the
853 * overhead of eeprom setup and tear-down. The address
854 * counter will roll over if reading beyond the size of
855 * the eeprom, thus allowing the entire memory to be read
856 * starting from any offset. */
857 for (i = 0; i < words; i++) {
858 word_in = e1000_shift_in_ee_bits(hw, 16);
859 data[i] = (word_in >> 8) | (word_in << 8);
860 }
861 } else if (eeprom->type == e1000_eeprom_microwire) {
862 for (i = 0; i < words; i++) {
863 /* Send the READ command (opcode + addr) */
864 e1000_shift_out_ee_bits(hw,
865 EEPROM_READ_OPCODE_MICROWIRE,
866 eeprom->opcode_bits);
867 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + i),
868 eeprom->address_bits);
869
870 /* Read the data. For microwire, each word requires
871 * the overhead of eeprom setup and tear-down. */
872 data[i] = e1000_shift_in_ee_bits(hw, 16);
873 e1000_standby_eeprom(hw);
874 }
875 }
876
877 /* End this read operation */
878 e1000_release_eeprom(hw);
879
880 return E1000_SUCCESS;
881}
882
883/******************************************************************************
884 * Verifies that the EEPROM has a valid checksum
885 *
886 * hw - Struct containing variables accessed by shared code
887 *
888 * Reads the first 64 16 bit words of the EEPROM and sums the values read.
889 * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
890 * valid.
891 *****************************************************************************/
Kyle Moffett70946bc2011-10-18 11:05:27 +0000892static int e1000_validate_eeprom_checksum(struct e1000_hw *hw)
Roy Zang28f7a052009-07-31 13:34:02 +0800893{
Kyle Moffett70946bc2011-10-18 11:05:27 +0000894 uint16_t i, checksum, checksum_reg, *buf;
Roy Zang28f7a052009-07-31 13:34:02 +0800895
896 DEBUGFUNC();
897
Kyle Moffett70946bc2011-10-18 11:05:27 +0000898 /* Allocate a temporary buffer */
899 buf = malloc(sizeof(buf[0]) * (EEPROM_CHECKSUM_REG + 1));
900 if (!buf) {
901 E1000_ERR(hw->nic, "Unable to allocate EEPROM buffer!\n");
902 return -E1000_ERR_EEPROM;
Roy Zang28f7a052009-07-31 13:34:02 +0800903 }
904
Kyle Moffett70946bc2011-10-18 11:05:27 +0000905 /* Read the EEPROM */
906 if (e1000_read_eeprom(hw, 0, EEPROM_CHECKSUM_REG + 1, buf) < 0) {
907 E1000_ERR(hw->nic, "Unable to read EEPROM!\n");
Roy Zang28f7a052009-07-31 13:34:02 +0800908 return -E1000_ERR_EEPROM;
909 }
Kyle Moffett70946bc2011-10-18 11:05:27 +0000910
911 /* Compute the checksum */
Wolfgang Denk15690332011-10-28 07:37:04 +0200912 checksum = 0;
Kyle Moffett70946bc2011-10-18 11:05:27 +0000913 for (i = 0; i < EEPROM_CHECKSUM_REG; i++)
914 checksum += buf[i];
915 checksum = ((uint16_t)EEPROM_SUM) - checksum;
916 checksum_reg = buf[i];
917
918 /* Verify it! */
919 if (checksum == checksum_reg)
920 return 0;
921
922 /* Hrm, verification failed, print an error */
923 E1000_ERR(hw->nic, "EEPROM checksum is incorrect!\n");
924 E1000_ERR(hw->nic, " ...register was 0x%04hx, calculated 0x%04hx\n",
925 checksum_reg, checksum);
926
927 return -E1000_ERR_EEPROM;
Roy Zang9b7c4302009-08-11 03:48:05 +0800928}
Rojhalat Ibrahimbbcd2b02013-10-07 18:30:39 +0200929#endif /* CONFIG_E1000_NO_NVM */
Roy Zang9b7c4302009-08-11 03:48:05 +0800930
931/*****************************************************************************
932 * Set PHY to class A mode
933 * Assumes the following operations will follow to enable the new class mode.
934 * 1. Do a PHY soft reset
935 * 2. Restart auto-negotiation or force link.
936 *
937 * hw - Struct containing variables accessed by shared code
938 ****************************************************************************/
939static int32_t
940e1000_set_phy_mode(struct e1000_hw *hw)
941{
Rojhalat Ibrahimbbcd2b02013-10-07 18:30:39 +0200942#ifndef CONFIG_E1000_NO_NVM
Roy Zang9b7c4302009-08-11 03:48:05 +0800943 int32_t ret_val;
944 uint16_t eeprom_data;
945
946 DEBUGFUNC();
947
948 if ((hw->mac_type == e1000_82545_rev_3) &&
949 (hw->media_type == e1000_media_type_copper)) {
950 ret_val = e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD,
951 1, &eeprom_data);
952 if (ret_val)
953 return ret_val;
954
955 if ((eeprom_data != EEPROM_RESERVED_WORD) &&
956 (eeprom_data & EEPROM_PHY_CLASS_A)) {
957 ret_val = e1000_write_phy_reg(hw,
958 M88E1000_PHY_PAGE_SELECT, 0x000B);
959 if (ret_val)
960 return ret_val;
961 ret_val = e1000_write_phy_reg(hw,
962 M88E1000_PHY_GEN_CONTROL, 0x8104);
963 if (ret_val)
964 return ret_val;
965
York Sun4a598092013-04-01 11:29:11 -0700966 hw->phy_reset_disable = false;
Roy Zang9b7c4302009-08-11 03:48:05 +0800967 }
968 }
Rojhalat Ibrahimbbcd2b02013-10-07 18:30:39 +0200969#endif
Roy Zang9b7c4302009-08-11 03:48:05 +0800970 return E1000_SUCCESS;
Roy Zang28f7a052009-07-31 13:34:02 +0800971}
Roy Zang28f7a052009-07-31 13:34:02 +0800972
Rojhalat Ibrahimbbcd2b02013-10-07 18:30:39 +0200973#ifndef CONFIG_E1000_NO_NVM
Roy Zang28f7a052009-07-31 13:34:02 +0800974/***************************************************************************
975 *
976 * Obtaining software semaphore bit (SMBI) before resetting PHY.
977 *
978 * hw: Struct containing variables accessed by shared code
979 *
980 * returns: - E1000_ERR_RESET if fail to obtain semaphore.
981 * E1000_SUCCESS at any other case.
982 *
983 ***************************************************************************/
984static int32_t
985e1000_get_software_semaphore(struct e1000_hw *hw)
986{
987 int32_t timeout = hw->eeprom.word_size + 1;
988 uint32_t swsm;
989
990 DEBUGFUNC();
991
Marek Vasut74a13c22014-08-08 07:41:39 -0700992 swsm = E1000_READ_REG(hw, SWSM);
993 swsm &= ~E1000_SWSM_SMBI;
994 E1000_WRITE_REG(hw, SWSM, swsm);
995
Roy Zang28f7a052009-07-31 13:34:02 +0800996 if (hw->mac_type != e1000_80003es2lan)
997 return E1000_SUCCESS;
998
999 while (timeout) {
1000 swsm = E1000_READ_REG(hw, SWSM);
1001 /* If SMBI bit cleared, it is now set and we hold
1002 * the semaphore */
1003 if (!(swsm & E1000_SWSM_SMBI))
1004 break;
1005 mdelay(1);
1006 timeout--;
1007 }
1008
1009 if (!timeout) {
1010 DEBUGOUT("Driver can't access device - SMBI bit is set.\n");
1011 return -E1000_ERR_RESET;
1012 }
1013
1014 return E1000_SUCCESS;
1015}
Rojhalat Ibrahimbbcd2b02013-10-07 18:30:39 +02001016#endif
Roy Zang28f7a052009-07-31 13:34:02 +08001017
1018/***************************************************************************
1019 * This function clears HW semaphore bits.
1020 *
1021 * hw: Struct containing variables accessed by shared code
1022 *
1023 * returns: - None.
1024 *
1025 ***************************************************************************/
1026static void
1027e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw)
1028{
Rojhalat Ibrahimbbcd2b02013-10-07 18:30:39 +02001029#ifndef CONFIG_E1000_NO_NVM
Roy Zang28f7a052009-07-31 13:34:02 +08001030 uint32_t swsm;
1031
1032 DEBUGFUNC();
1033
1034 if (!hw->eeprom_semaphore_present)
1035 return;
1036
1037 swsm = E1000_READ_REG(hw, SWSM);
1038 if (hw->mac_type == e1000_80003es2lan) {
1039 /* Release both semaphores. */
1040 swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI);
1041 } else
1042 swsm &= ~(E1000_SWSM_SWESMBI);
1043 E1000_WRITE_REG(hw, SWSM, swsm);
Rojhalat Ibrahimbbcd2b02013-10-07 18:30:39 +02001044#endif
Roy Zang28f7a052009-07-31 13:34:02 +08001045}
1046
1047/***************************************************************************
1048 *
1049 * Using the combination of SMBI and SWESMBI semaphore bits when resetting
1050 * adapter or Eeprom access.
1051 *
1052 * hw: Struct containing variables accessed by shared code
1053 *
1054 * returns: - E1000_ERR_EEPROM if fail to access EEPROM.
1055 * E1000_SUCCESS at any other case.
1056 *
1057 ***************************************************************************/
1058static int32_t
1059e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw)
1060{
Rojhalat Ibrahimbbcd2b02013-10-07 18:30:39 +02001061#ifndef CONFIG_E1000_NO_NVM
Roy Zang28f7a052009-07-31 13:34:02 +08001062 int32_t timeout;
1063 uint32_t swsm;
1064
1065 DEBUGFUNC();
1066
1067 if (!hw->eeprom_semaphore_present)
1068 return E1000_SUCCESS;
1069
1070 if (hw->mac_type == e1000_80003es2lan) {
1071 /* Get the SW semaphore. */
1072 if (e1000_get_software_semaphore(hw) != E1000_SUCCESS)
1073 return -E1000_ERR_EEPROM;
1074 }
1075
1076 /* Get the FW semaphore. */
1077 timeout = hw->eeprom.word_size + 1;
1078 while (timeout) {
1079 swsm = E1000_READ_REG(hw, SWSM);
1080 swsm |= E1000_SWSM_SWESMBI;
1081 E1000_WRITE_REG(hw, SWSM, swsm);
1082 /* if we managed to set the bit we got the semaphore. */
1083 swsm = E1000_READ_REG(hw, SWSM);
1084 if (swsm & E1000_SWSM_SWESMBI)
1085 break;
1086
1087 udelay(50);
1088 timeout--;
1089 }
1090
1091 if (!timeout) {
1092 /* Release semaphores */
1093 e1000_put_hw_eeprom_semaphore(hw);
1094 DEBUGOUT("Driver can't access the Eeprom - "
1095 "SWESMBI bit is set.\n");
1096 return -E1000_ERR_EEPROM;
1097 }
Rojhalat Ibrahimbbcd2b02013-10-07 18:30:39 +02001098#endif
Roy Zang28f7a052009-07-31 13:34:02 +08001099 return E1000_SUCCESS;
1100}
1101
1102static int32_t
1103e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask)
1104{
1105 uint32_t swfw_sync = 0;
1106 uint32_t swmask = mask;
1107 uint32_t fwmask = mask << 16;
1108 int32_t timeout = 200;
1109
1110 DEBUGFUNC();
1111 while (timeout) {
1112 if (e1000_get_hw_eeprom_semaphore(hw))
1113 return -E1000_ERR_SWFW_SYNC;
1114
1115 swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
York Sun4303a832014-10-17 13:44:06 -07001116 if (!(swfw_sync & (fwmask | swmask)))
Roy Zang28f7a052009-07-31 13:34:02 +08001117 break;
1118
1119 /* firmware currently using resource (fwmask) */
1120 /* or other software thread currently using resource (swmask) */
1121 e1000_put_hw_eeprom_semaphore(hw);
1122 mdelay(5);
1123 timeout--;
1124 }
1125
1126 if (!timeout) {
1127 DEBUGOUT("Driver can't access resource, SW_FW_SYNC timeout.\n");
1128 return -E1000_ERR_SWFW_SYNC;
1129 }
1130
1131 swfw_sync |= swmask;
1132 E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
1133
1134 e1000_put_hw_eeprom_semaphore(hw);
1135 return E1000_SUCCESS;
1136}
1137
York Sun4a598092013-04-01 11:29:11 -07001138static bool e1000_is_second_port(struct e1000_hw *hw)
Kyle Moffett7376f8d2010-09-13 05:52:22 +00001139{
1140 switch (hw->mac_type) {
1141 case e1000_80003es2lan:
1142 case e1000_82546:
1143 case e1000_82571:
1144 if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
York Sun4a598092013-04-01 11:29:11 -07001145 return true;
Kyle Moffett7376f8d2010-09-13 05:52:22 +00001146 /* Fallthrough */
1147 default:
York Sun4a598092013-04-01 11:29:11 -07001148 return false;
Kyle Moffett7376f8d2010-09-13 05:52:22 +00001149 }
1150}
1151
Rojhalat Ibrahimbbcd2b02013-10-07 18:30:39 +02001152#ifndef CONFIG_E1000_NO_NVM
Roy Zang28f7a052009-07-31 13:34:02 +08001153/******************************************************************************
1154 * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
1155 * second function of dual function devices
1156 *
1157 * nic - Struct containing variables accessed by shared code
1158 *****************************************************************************/
1159static int
1160e1000_read_mac_addr(struct eth_device *nic)
1161{
Roy Zang28f7a052009-07-31 13:34:02 +08001162 struct e1000_hw *hw = nic->priv;
1163 uint16_t offset;
1164 uint16_t eeprom_data;
Marek Vasut74a13c22014-08-08 07:41:39 -07001165 uint32_t reg_data = 0;
Roy Zang28f7a052009-07-31 13:34:02 +08001166 int i;
1167
1168 DEBUGFUNC();
1169
1170 for (i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
wdenk4e112c12003-06-03 23:54:09 +00001171 offset = i >> 1;
Marek Vasut74a13c22014-08-08 07:41:39 -07001172 if (hw->mac_type == e1000_igb) {
1173 /* i210 preloads MAC address into RAL/RAH registers */
1174 if (offset == 0)
1175 reg_data = E1000_READ_REG_ARRAY(hw, RA, 0);
1176 else if (offset == 1)
1177 reg_data >>= 16;
1178 else if (offset == 2)
1179 reg_data = E1000_READ_REG_ARRAY(hw, RA, 1);
1180 eeprom_data = reg_data & 0xffff;
1181 } else if (e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
wdenk4e112c12003-06-03 23:54:09 +00001182 DEBUGOUT("EEPROM Read Error\n");
1183 return -E1000_ERR_EEPROM;
1184 }
1185 nic->enetaddr[i] = eeprom_data & 0xff;
1186 nic->enetaddr[i + 1] = (eeprom_data >> 8) & 0xff;
1187 }
Kyle Moffett7376f8d2010-09-13 05:52:22 +00001188
1189 /* Invert the last bit if this is the second device */
1190 if (e1000_is_second_port(hw))
1191 nic->enetaddr[5] ^= 1;
1192
Andre Schwarz68c2a302008-03-06 16:45:44 +01001193#ifdef CONFIG_E1000_FALLBACK_MAC
Anatolij Gustschin25826ae2011-12-20 07:36:39 +00001194 if (!is_valid_ether_addr(nic->enetaddr)) {
Stefan Roese37628252008-08-06 14:05:38 +02001195 unsigned char fb_mac[NODE_ADDRESS_SIZE] = CONFIG_E1000_FALLBACK_MAC;
1196
1197 memcpy (nic->enetaddr, fb_mac, NODE_ADDRESS_SIZE);
1198 }
Andre Schwarz68c2a302008-03-06 16:45:44 +01001199#endif
wdenk4e112c12003-06-03 23:54:09 +00001200 return 0;
1201}
Rojhalat Ibrahimbbcd2b02013-10-07 18:30:39 +02001202#endif
wdenk4e112c12003-06-03 23:54:09 +00001203
1204/******************************************************************************
1205 * Initializes receive address filters.
1206 *
wdenk57b2d802003-06-27 21:31:46 +00001207 * hw - Struct containing variables accessed by shared code
wdenk4e112c12003-06-03 23:54:09 +00001208 *
1209 * Places the MAC address in receive address register 0 and clears the rest
1210 * of the receive addresss registers. Clears the multicast table. Assumes
1211 * the receiver is in reset when the routine is called.
1212 *****************************************************************************/
1213static void
1214e1000_init_rx_addrs(struct eth_device *nic)
1215{
1216 struct e1000_hw *hw = nic->priv;
1217 uint32_t i;
1218 uint32_t addr_low;
1219 uint32_t addr_high;
1220
1221 DEBUGFUNC();
1222
1223 /* Setup the receive address. */
1224 DEBUGOUT("Programming MAC Address into RAR[0]\n");
1225 addr_low = (nic->enetaddr[0] |
1226 (nic->enetaddr[1] << 8) |
1227 (nic->enetaddr[2] << 16) | (nic->enetaddr[3] << 24));
1228
1229 addr_high = (nic->enetaddr[4] | (nic->enetaddr[5] << 8) | E1000_RAH_AV);
1230
1231 E1000_WRITE_REG_ARRAY(hw, RA, 0, addr_low);
1232 E1000_WRITE_REG_ARRAY(hw, RA, 1, addr_high);
1233
1234 /* Zero out the other 15 receive addresses. */
1235 DEBUGOUT("Clearing RAR[1-15]\n");
1236 for (i = 1; i < E1000_RAR_ENTRIES; i++) {
1237 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
1238 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
1239 }
1240}
1241
1242/******************************************************************************
1243 * Clears the VLAN filer table
1244 *
1245 * hw - Struct containing variables accessed by shared code
1246 *****************************************************************************/
1247static void
1248e1000_clear_vfta(struct e1000_hw *hw)
1249{
1250 uint32_t offset;
1251
1252 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++)
1253 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, 0);
1254}
1255
1256/******************************************************************************
1257 * Set the mac type member in the hw struct.
wdenk57b2d802003-06-27 21:31:46 +00001258 *
wdenk4e112c12003-06-03 23:54:09 +00001259 * hw - Struct containing variables accessed by shared code
1260 *****************************************************************************/
Roy Zang28f7a052009-07-31 13:34:02 +08001261int32_t
wdenk4e112c12003-06-03 23:54:09 +00001262e1000_set_mac_type(struct e1000_hw *hw)
1263{
1264 DEBUGFUNC();
1265
1266 switch (hw->device_id) {
1267 case E1000_DEV_ID_82542:
1268 switch (hw->revision_id) {
1269 case E1000_82542_2_0_REV_ID:
1270 hw->mac_type = e1000_82542_rev2_0;
1271 break;
1272 case E1000_82542_2_1_REV_ID:
1273 hw->mac_type = e1000_82542_rev2_1;
1274 break;
1275 default:
1276 /* Invalid 82542 revision ID */
1277 return -E1000_ERR_MAC_TYPE;
1278 }
1279 break;
1280 case E1000_DEV_ID_82543GC_FIBER:
1281 case E1000_DEV_ID_82543GC_COPPER:
1282 hw->mac_type = e1000_82543;
1283 break;
1284 case E1000_DEV_ID_82544EI_COPPER:
1285 case E1000_DEV_ID_82544EI_FIBER:
1286 case E1000_DEV_ID_82544GC_COPPER:
1287 case E1000_DEV_ID_82544GC_LOM:
1288 hw->mac_type = e1000_82544;
1289 break;
1290 case E1000_DEV_ID_82540EM:
1291 case E1000_DEV_ID_82540EM_LOM:
Roy Zang28f7a052009-07-31 13:34:02 +08001292 case E1000_DEV_ID_82540EP:
1293 case E1000_DEV_ID_82540EP_LOM:
1294 case E1000_DEV_ID_82540EP_LP:
wdenk4e112c12003-06-03 23:54:09 +00001295 hw->mac_type = e1000_82540;
1296 break;
1297 case E1000_DEV_ID_82545EM_COPPER:
1298 case E1000_DEV_ID_82545EM_FIBER:
1299 hw->mac_type = e1000_82545;
1300 break;
Roy Zang28f7a052009-07-31 13:34:02 +08001301 case E1000_DEV_ID_82545GM_COPPER:
1302 case E1000_DEV_ID_82545GM_FIBER:
1303 case E1000_DEV_ID_82545GM_SERDES:
1304 hw->mac_type = e1000_82545_rev_3;
1305 break;
wdenk4e112c12003-06-03 23:54:09 +00001306 case E1000_DEV_ID_82546EB_COPPER:
1307 case E1000_DEV_ID_82546EB_FIBER:
Roy Zang28f7a052009-07-31 13:34:02 +08001308 case E1000_DEV_ID_82546EB_QUAD_COPPER:
wdenk4e112c12003-06-03 23:54:09 +00001309 hw->mac_type = e1000_82546;
1310 break;
Roy Zang28f7a052009-07-31 13:34:02 +08001311 case E1000_DEV_ID_82546GB_COPPER:
1312 case E1000_DEV_ID_82546GB_FIBER:
1313 case E1000_DEV_ID_82546GB_SERDES:
1314 case E1000_DEV_ID_82546GB_PCIE:
1315 case E1000_DEV_ID_82546GB_QUAD_COPPER:
1316 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
1317 hw->mac_type = e1000_82546_rev_3;
1318 break;
1319 case E1000_DEV_ID_82541EI:
1320 case E1000_DEV_ID_82541EI_MOBILE:
1321 case E1000_DEV_ID_82541ER_LOM:
1322 hw->mac_type = e1000_82541;
1323 break;
Andre Schwarz68c2a302008-03-06 16:45:44 +01001324 case E1000_DEV_ID_82541ER:
Roy Zang28f7a052009-07-31 13:34:02 +08001325 case E1000_DEV_ID_82541GI:
Wolfgang Grandegger8562c382008-05-28 19:55:19 +02001326 case E1000_DEV_ID_82541GI_LF:
Roy Zang28f7a052009-07-31 13:34:02 +08001327 case E1000_DEV_ID_82541GI_MOBILE:
Wolfgang Denk35f734f2008-04-13 09:59:26 -07001328 hw->mac_type = e1000_82541_rev_2;
1329 break;
Roy Zang28f7a052009-07-31 13:34:02 +08001330 case E1000_DEV_ID_82547EI:
1331 case E1000_DEV_ID_82547EI_MOBILE:
1332 hw->mac_type = e1000_82547;
1333 break;
1334 case E1000_DEV_ID_82547GI:
1335 hw->mac_type = e1000_82547_rev_2;
1336 break;
1337 case E1000_DEV_ID_82571EB_COPPER:
1338 case E1000_DEV_ID_82571EB_FIBER:
1339 case E1000_DEV_ID_82571EB_SERDES:
1340 case E1000_DEV_ID_82571EB_SERDES_DUAL:
1341 case E1000_DEV_ID_82571EB_SERDES_QUAD:
1342 case E1000_DEV_ID_82571EB_QUAD_COPPER:
1343 case E1000_DEV_ID_82571PT_QUAD_COPPER:
1344 case E1000_DEV_ID_82571EB_QUAD_FIBER:
1345 case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE:
1346 hw->mac_type = e1000_82571;
1347 break;
1348 case E1000_DEV_ID_82572EI_COPPER:
1349 case E1000_DEV_ID_82572EI_FIBER:
1350 case E1000_DEV_ID_82572EI_SERDES:
1351 case E1000_DEV_ID_82572EI:
1352 hw->mac_type = e1000_82572;
1353 break;
1354 case E1000_DEV_ID_82573E:
1355 case E1000_DEV_ID_82573E_IAMT:
1356 case E1000_DEV_ID_82573L:
1357 hw->mac_type = e1000_82573;
1358 break;
Roy Zang181119b2011-01-21 11:29:38 +08001359 case E1000_DEV_ID_82574L:
1360 hw->mac_type = e1000_82574;
1361 break;
Roy Zang28f7a052009-07-31 13:34:02 +08001362 case E1000_DEV_ID_80003ES2LAN_COPPER_SPT:
1363 case E1000_DEV_ID_80003ES2LAN_SERDES_SPT:
1364 case E1000_DEV_ID_80003ES2LAN_COPPER_DPT:
1365 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
1366 hw->mac_type = e1000_80003es2lan;
1367 break;
1368 case E1000_DEV_ID_ICH8_IGP_M_AMT:
1369 case E1000_DEV_ID_ICH8_IGP_AMT:
1370 case E1000_DEV_ID_ICH8_IGP_C:
1371 case E1000_DEV_ID_ICH8_IFE:
1372 case E1000_DEV_ID_ICH8_IFE_GT:
1373 case E1000_DEV_ID_ICH8_IFE_G:
1374 case E1000_DEV_ID_ICH8_IGP_M:
1375 hw->mac_type = e1000_ich8lan;
1376 break;
Marek Vasut74a13c22014-08-08 07:41:39 -07001377 case PCI_DEVICE_ID_INTEL_I210_COPPER:
1378 case PCI_DEVICE_ID_INTEL_I210_COPPER_FLASHLESS:
1379 case PCI_DEVICE_ID_INTEL_I210_SERDES:
1380 case PCI_DEVICE_ID_INTEL_I210_SERDES_FLASHLESS:
1381 case PCI_DEVICE_ID_INTEL_I210_1000BASEKX:
1382 hw->mac_type = e1000_igb;
1383 break;
wdenk4e112c12003-06-03 23:54:09 +00001384 default:
1385 /* Should never have loaded on this device */
1386 return -E1000_ERR_MAC_TYPE;
1387 }
1388 return E1000_SUCCESS;
1389}
1390
1391/******************************************************************************
1392 * Reset the transmit and receive units; mask and clear all interrupts.
1393 *
1394 * hw - Struct containing variables accessed by shared code
1395 *****************************************************************************/
1396void
1397e1000_reset_hw(struct e1000_hw *hw)
1398{
1399 uint32_t ctrl;
1400 uint32_t ctrl_ext;
wdenk4e112c12003-06-03 23:54:09 +00001401 uint32_t manc;
Roy Zang966172e2009-08-22 03:49:52 +08001402 uint32_t pba = 0;
Marek Vasut74a13c22014-08-08 07:41:39 -07001403 uint32_t reg;
wdenk4e112c12003-06-03 23:54:09 +00001404
1405 DEBUGFUNC();
1406
Roy Zang966172e2009-08-22 03:49:52 +08001407 /* get the correct pba value for both PCI and PCIe*/
1408 if (hw->mac_type < e1000_82571)
1409 pba = E1000_DEFAULT_PCI_PBA;
1410 else
1411 pba = E1000_DEFAULT_PCIE_PBA;
1412
wdenk4e112c12003-06-03 23:54:09 +00001413 /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
1414 if (hw->mac_type == e1000_82542_rev2_0) {
1415 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
1416 pci_write_config_word(hw->pdev, PCI_COMMAND,
Roy Zang28f7a052009-07-31 13:34:02 +08001417 hw->pci_cmd_word & ~PCI_COMMAND_INVALIDATE);
wdenk4e112c12003-06-03 23:54:09 +00001418 }
1419
1420 /* Clear interrupt mask to stop board from generating interrupts */
1421 DEBUGOUT("Masking off all interrupts\n");
Marek Vasut74a13c22014-08-08 07:41:39 -07001422 if (hw->mac_type == e1000_igb)
1423 E1000_WRITE_REG(hw, I210_IAM, 0);
wdenk4e112c12003-06-03 23:54:09 +00001424 E1000_WRITE_REG(hw, IMC, 0xffffffff);
1425
1426 /* Disable the Transmit and Receive units. Then delay to allow
1427 * any pending transactions to complete before we hit the MAC with
1428 * the global reset.
1429 */
1430 E1000_WRITE_REG(hw, RCTL, 0);
1431 E1000_WRITE_REG(hw, TCTL, E1000_TCTL_PSP);
1432 E1000_WRITE_FLUSH(hw);
1433
1434 /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
York Sun4a598092013-04-01 11:29:11 -07001435 hw->tbi_compatibility_on = false;
wdenk4e112c12003-06-03 23:54:09 +00001436
1437 /* Delay to allow any outstanding PCI transactions to complete before
1438 * resetting the device
1439 */
1440 mdelay(10);
1441
1442 /* Issue a global reset to the MAC. This will reset the chip's
1443 * transmit, receive, DMA, and link units. It will not effect
1444 * the current PCI configuration. The global reset bit is self-
1445 * clearing, and should clear within a microsecond.
1446 */
1447 DEBUGOUT("Issuing a global reset to MAC\n");
1448 ctrl = E1000_READ_REG(hw, CTRL);
1449
Roy Zang28f7a052009-07-31 13:34:02 +08001450 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
wdenk4e112c12003-06-03 23:54:09 +00001451
1452 /* Force a reload from the EEPROM if necessary */
Marek Vasut74a13c22014-08-08 07:41:39 -07001453 if (hw->mac_type == e1000_igb) {
1454 mdelay(20);
1455 reg = E1000_READ_REG(hw, STATUS);
1456 if (reg & E1000_STATUS_PF_RST_DONE)
1457 DEBUGOUT("PF OK\n");
1458 reg = E1000_READ_REG(hw, I210_EECD);
1459 if (reg & E1000_EECD_AUTO_RD)
1460 DEBUGOUT("EEC OK\n");
1461 } else if (hw->mac_type < e1000_82540) {
wdenk4e112c12003-06-03 23:54:09 +00001462 /* Wait for reset to complete */
1463 udelay(10);
1464 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
1465 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
1466 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1467 E1000_WRITE_FLUSH(hw);
1468 /* Wait for EEPROM reload */
1469 mdelay(2);
1470 } else {
1471 /* Wait for EEPROM reload (it happens automatically) */
1472 mdelay(4);
1473 /* Dissable HW ARPs on ASF enabled adapters */
1474 manc = E1000_READ_REG(hw, MANC);
1475 manc &= ~(E1000_MANC_ARP_EN);
1476 E1000_WRITE_REG(hw, MANC, manc);
1477 }
1478
1479 /* Clear interrupt mask to stop board from generating interrupts */
1480 DEBUGOUT("Masking off all interrupts\n");
Marek Vasut74a13c22014-08-08 07:41:39 -07001481 if (hw->mac_type == e1000_igb)
1482 E1000_WRITE_REG(hw, I210_IAM, 0);
wdenk4e112c12003-06-03 23:54:09 +00001483 E1000_WRITE_REG(hw, IMC, 0xffffffff);
1484
1485 /* Clear any pending interrupt events. */
Zang Roy-R61911e36d67c2011-11-06 22:22:36 +00001486 E1000_READ_REG(hw, ICR);
wdenk4e112c12003-06-03 23:54:09 +00001487
1488 /* If MWI was previously enabled, reenable it. */
1489 if (hw->mac_type == e1000_82542_rev2_0) {
1490 pci_write_config_word(hw->pdev, PCI_COMMAND, hw->pci_cmd_word);
1491 }
Marek Vasut74a13c22014-08-08 07:41:39 -07001492 if (hw->mac_type != e1000_igb)
1493 E1000_WRITE_REG(hw, PBA, pba);
Roy Zang28f7a052009-07-31 13:34:02 +08001494}
1495
1496/******************************************************************************
1497 *
1498 * Initialize a number of hardware-dependent bits
1499 *
1500 * hw: Struct containing variables accessed by shared code
1501 *
1502 * This function contains hardware limitation workarounds for PCI-E adapters
1503 *
1504 *****************************************************************************/
1505static void
1506e1000_initialize_hardware_bits(struct e1000_hw *hw)
1507{
1508 if ((hw->mac_type >= e1000_82571) &&
1509 (!hw->initialize_hw_bits_disable)) {
1510 /* Settings common to all PCI-express silicon */
1511 uint32_t reg_ctrl, reg_ctrl_ext;
1512 uint32_t reg_tarc0, reg_tarc1;
1513 uint32_t reg_tctl;
1514 uint32_t reg_txdctl, reg_txdctl1;
1515
1516 /* link autonegotiation/sync workarounds */
1517 reg_tarc0 = E1000_READ_REG(hw, TARC0);
1518 reg_tarc0 &= ~((1 << 30)|(1 << 29)|(1 << 28)|(1 << 27));
1519
1520 /* Enable not-done TX descriptor counting */
1521 reg_txdctl = E1000_READ_REG(hw, TXDCTL);
1522 reg_txdctl |= E1000_TXDCTL_COUNT_DESC;
1523 E1000_WRITE_REG(hw, TXDCTL, reg_txdctl);
1524
1525 reg_txdctl1 = E1000_READ_REG(hw, TXDCTL1);
1526 reg_txdctl1 |= E1000_TXDCTL_COUNT_DESC;
1527 E1000_WRITE_REG(hw, TXDCTL1, reg_txdctl1);
1528
Marek Vasut74a13c22014-08-08 07:41:39 -07001529 /* IGB is cool */
1530 if (hw->mac_type == e1000_igb)
1531 return;
1532
Roy Zang28f7a052009-07-31 13:34:02 +08001533 switch (hw->mac_type) {
1534 case e1000_82571:
1535 case e1000_82572:
1536 /* Clear PHY TX compatible mode bits */
1537 reg_tarc1 = E1000_READ_REG(hw, TARC1);
1538 reg_tarc1 &= ~((1 << 30)|(1 << 29));
1539
1540 /* link autonegotiation/sync workarounds */
1541 reg_tarc0 |= ((1 << 26)|(1 << 25)|(1 << 24)|(1 << 23));
1542
1543 /* TX ring control fixes */
1544 reg_tarc1 |= ((1 << 26)|(1 << 25)|(1 << 24));
1545
1546 /* Multiple read bit is reversed polarity */
1547 reg_tctl = E1000_READ_REG(hw, TCTL);
1548 if (reg_tctl & E1000_TCTL_MULR)
1549 reg_tarc1 &= ~(1 << 28);
1550 else
1551 reg_tarc1 |= (1 << 28);
1552
1553 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
1554 break;
1555 case e1000_82573:
Roy Zang181119b2011-01-21 11:29:38 +08001556 case e1000_82574:
Roy Zang28f7a052009-07-31 13:34:02 +08001557 reg_ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
1558 reg_ctrl_ext &= ~(1 << 23);
1559 reg_ctrl_ext |= (1 << 22);
1560
1561 /* TX byte count fix */
1562 reg_ctrl = E1000_READ_REG(hw, CTRL);
1563 reg_ctrl &= ~(1 << 29);
1564
1565 E1000_WRITE_REG(hw, CTRL_EXT, reg_ctrl_ext);
1566 E1000_WRITE_REG(hw, CTRL, reg_ctrl);
1567 break;
1568 case e1000_80003es2lan:
1569 /* improve small packet performace for fiber/serdes */
1570 if ((hw->media_type == e1000_media_type_fiber)
1571 || (hw->media_type ==
1572 e1000_media_type_internal_serdes)) {
1573 reg_tarc0 &= ~(1 << 20);
1574 }
1575
1576 /* Multiple read bit is reversed polarity */
1577 reg_tctl = E1000_READ_REG(hw, TCTL);
1578 reg_tarc1 = E1000_READ_REG(hw, TARC1);
1579 if (reg_tctl & E1000_TCTL_MULR)
1580 reg_tarc1 &= ~(1 << 28);
1581 else
1582 reg_tarc1 |= (1 << 28);
1583
1584 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
1585 break;
1586 case e1000_ich8lan:
1587 /* Reduce concurrent DMA requests to 3 from 4 */
1588 if ((hw->revision_id < 3) ||
1589 ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) &&
1590 (hw->device_id != E1000_DEV_ID_ICH8_IGP_M)))
1591 reg_tarc0 |= ((1 << 29)|(1 << 28));
1592
1593 reg_ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
1594 reg_ctrl_ext |= (1 << 22);
1595 E1000_WRITE_REG(hw, CTRL_EXT, reg_ctrl_ext);
1596
1597 /* workaround TX hang with TSO=on */
1598 reg_tarc0 |= ((1 << 27)|(1 << 26)|(1 << 24)|(1 << 23));
1599
1600 /* Multiple read bit is reversed polarity */
1601 reg_tctl = E1000_READ_REG(hw, TCTL);
1602 reg_tarc1 = E1000_READ_REG(hw, TARC1);
1603 if (reg_tctl & E1000_TCTL_MULR)
1604 reg_tarc1 &= ~(1 << 28);
1605 else
1606 reg_tarc1 |= (1 << 28);
1607
1608 /* workaround TX hang with TSO=on */
1609 reg_tarc1 |= ((1 << 30)|(1 << 26)|(1 << 24));
1610
1611 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
1612 break;
1613 default:
1614 break;
1615 }
1616
1617 E1000_WRITE_REG(hw, TARC0, reg_tarc0);
1618 }
wdenk4e112c12003-06-03 23:54:09 +00001619}
1620
1621/******************************************************************************
1622 * Performs basic configuration of the adapter.
1623 *
1624 * hw - Struct containing variables accessed by shared code
wdenk57b2d802003-06-27 21:31:46 +00001625 *
1626 * Assumes that the controller has previously been reset and is in a
wdenk4e112c12003-06-03 23:54:09 +00001627 * post-reset uninitialized state. Initializes the receive address registers,
1628 * multicast table, and VLAN filter table. Calls routines to setup link
1629 * configuration and flow control settings. Clears all on-chip counters. Leaves
1630 * the transmit and receive units disabled and uninitialized.
1631 *****************************************************************************/
1632static int
1633e1000_init_hw(struct eth_device *nic)
1634{
1635 struct e1000_hw *hw = nic->priv;
Roy Zang28f7a052009-07-31 13:34:02 +08001636 uint32_t ctrl;
wdenk4e112c12003-06-03 23:54:09 +00001637 uint32_t i;
1638 int32_t ret_val;
1639 uint16_t pcix_cmd_word;
1640 uint16_t pcix_stat_hi_word;
1641 uint16_t cmd_mmrbc;
1642 uint16_t stat_mmrbc;
Roy Zang28f7a052009-07-31 13:34:02 +08001643 uint32_t mta_size;
1644 uint32_t reg_data;
1645 uint32_t ctrl_ext;
wdenk4e112c12003-06-03 23:54:09 +00001646 DEBUGFUNC();
Roy Zang28f7a052009-07-31 13:34:02 +08001647 /* force full DMA clock frequency for 10/100 on ICH8 A0-B0 */
1648 if ((hw->mac_type == e1000_ich8lan) &&
1649 ((hw->revision_id < 3) ||
1650 ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) &&
1651 (hw->device_id != E1000_DEV_ID_ICH8_IGP_M)))) {
1652 reg_data = E1000_READ_REG(hw, STATUS);
1653 reg_data &= ~0x80000000;
1654 E1000_WRITE_REG(hw, STATUS, reg_data);
wdenk4e112c12003-06-03 23:54:09 +00001655 }
Roy Zang28f7a052009-07-31 13:34:02 +08001656 /* Do not need initialize Identification LED */
wdenk4e112c12003-06-03 23:54:09 +00001657
Roy Zang28f7a052009-07-31 13:34:02 +08001658 /* Set the media type and TBI compatibility */
1659 e1000_set_media_type(hw);
1660
1661 /* Must be called after e1000_set_media_type
1662 * because media_type is used */
1663 e1000_initialize_hardware_bits(hw);
wdenk4e112c12003-06-03 23:54:09 +00001664
1665 /* Disabling VLAN filtering. */
1666 DEBUGOUT("Initializing the IEEE VLAN\n");
Roy Zang28f7a052009-07-31 13:34:02 +08001667 /* VET hardcoded to standard value and VFTA removed in ICH8 LAN */
1668 if (hw->mac_type != e1000_ich8lan) {
1669 if (hw->mac_type < e1000_82545_rev_3)
1670 E1000_WRITE_REG(hw, VET, 0);
1671 e1000_clear_vfta(hw);
1672 }
wdenk4e112c12003-06-03 23:54:09 +00001673
1674 /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
1675 if (hw->mac_type == e1000_82542_rev2_0) {
1676 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
1677 pci_write_config_word(hw->pdev, PCI_COMMAND,
1678 hw->
1679 pci_cmd_word & ~PCI_COMMAND_INVALIDATE);
1680 E1000_WRITE_REG(hw, RCTL, E1000_RCTL_RST);
1681 E1000_WRITE_FLUSH(hw);
1682 mdelay(5);
1683 }
1684
1685 /* Setup the receive address. This involves initializing all of the Receive
1686 * Address Registers (RARs 0 - 15).
1687 */
1688 e1000_init_rx_addrs(nic);
1689
1690 /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
1691 if (hw->mac_type == e1000_82542_rev2_0) {
1692 E1000_WRITE_REG(hw, RCTL, 0);
1693 E1000_WRITE_FLUSH(hw);
1694 mdelay(1);
1695 pci_write_config_word(hw->pdev, PCI_COMMAND, hw->pci_cmd_word);
1696 }
1697
1698 /* Zero out the Multicast HASH table */
1699 DEBUGOUT("Zeroing the MTA\n");
Roy Zang28f7a052009-07-31 13:34:02 +08001700 mta_size = E1000_MC_TBL_SIZE;
1701 if (hw->mac_type == e1000_ich8lan)
1702 mta_size = E1000_MC_TBL_SIZE_ICH8LAN;
1703 for (i = 0; i < mta_size; i++) {
wdenk4e112c12003-06-03 23:54:09 +00001704 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
Roy Zang28f7a052009-07-31 13:34:02 +08001705 /* use write flush to prevent Memory Write Block (MWB) from
1706 * occuring when accessing our register space */
1707 E1000_WRITE_FLUSH(hw);
1708 }
wdenk4e112c12003-06-03 23:54:09 +00001709#if 0
1710 /* Set the PCI priority bit correctly in the CTRL register. This
1711 * determines if the adapter gives priority to receives, or if it
Roy Zang28f7a052009-07-31 13:34:02 +08001712 * gives equal priority to transmits and receives. Valid only on
1713 * 82542 and 82543 silicon.
wdenk4e112c12003-06-03 23:54:09 +00001714 */
Roy Zang28f7a052009-07-31 13:34:02 +08001715 if (hw->dma_fairness && hw->mac_type <= e1000_82543) {
wdenk4e112c12003-06-03 23:54:09 +00001716 ctrl = E1000_READ_REG(hw, CTRL);
1717 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PRIOR);
1718 }
1719#endif
Roy Zang28f7a052009-07-31 13:34:02 +08001720 switch (hw->mac_type) {
1721 case e1000_82545_rev_3:
1722 case e1000_82546_rev_3:
Marek Vasut74a13c22014-08-08 07:41:39 -07001723 case e1000_igb:
Roy Zang28f7a052009-07-31 13:34:02 +08001724 break;
1725 default:
wdenk4e112c12003-06-03 23:54:09 +00001726 /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
Roy Zang28f7a052009-07-31 13:34:02 +08001727 if (hw->bus_type == e1000_bus_type_pcix) {
wdenk4e112c12003-06-03 23:54:09 +00001728 pci_read_config_word(hw->pdev, PCIX_COMMAND_REGISTER,
1729 &pcix_cmd_word);
1730 pci_read_config_word(hw->pdev, PCIX_STATUS_REGISTER_HI,
1731 &pcix_stat_hi_word);
1732 cmd_mmrbc =
1733 (pcix_cmd_word & PCIX_COMMAND_MMRBC_MASK) >>
1734 PCIX_COMMAND_MMRBC_SHIFT;
1735 stat_mmrbc =
1736 (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >>
1737 PCIX_STATUS_HI_MMRBC_SHIFT;
1738 if (stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K)
1739 stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K;
1740 if (cmd_mmrbc > stat_mmrbc) {
1741 pcix_cmd_word &= ~PCIX_COMMAND_MMRBC_MASK;
1742 pcix_cmd_word |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT;
1743 pci_write_config_word(hw->pdev, PCIX_COMMAND_REGISTER,
1744 pcix_cmd_word);
1745 }
1746 }
Roy Zang28f7a052009-07-31 13:34:02 +08001747 break;
1748 }
wdenk4e112c12003-06-03 23:54:09 +00001749
Roy Zang28f7a052009-07-31 13:34:02 +08001750 /* More time needed for PHY to initialize */
1751 if (hw->mac_type == e1000_ich8lan)
1752 mdelay(15);
Marek Vasut74a13c22014-08-08 07:41:39 -07001753 if (hw->mac_type == e1000_igb)
1754 mdelay(15);
Roy Zang28f7a052009-07-31 13:34:02 +08001755
wdenk4e112c12003-06-03 23:54:09 +00001756 /* Call a subroutine to configure the link and setup flow control. */
1757 ret_val = e1000_setup_link(nic);
1758
1759 /* Set the transmit descriptor write-back policy */
1760 if (hw->mac_type > e1000_82544) {
1761 ctrl = E1000_READ_REG(hw, TXDCTL);
1762 ctrl =
1763 (ctrl & ~E1000_TXDCTL_WTHRESH) |
1764 E1000_TXDCTL_FULL_TX_DESC_WB;
1765 E1000_WRITE_REG(hw, TXDCTL, ctrl);
1766 }
Roy Zang28f7a052009-07-31 13:34:02 +08001767
Ruchika Guptaed1f72f2012-04-19 02:27:11 +00001768 /* Set the receive descriptor write back policy */
Ruchika Guptaed1f72f2012-04-19 02:27:11 +00001769 if (hw->mac_type >= e1000_82571) {
1770 ctrl = E1000_READ_REG(hw, RXDCTL);
1771 ctrl =
1772 (ctrl & ~E1000_RXDCTL_WTHRESH) |
1773 E1000_RXDCTL_FULL_RX_DESC_WB;
1774 E1000_WRITE_REG(hw, RXDCTL, ctrl);
1775 }
1776
Roy Zang28f7a052009-07-31 13:34:02 +08001777 switch (hw->mac_type) {
1778 default:
1779 break;
1780 case e1000_80003es2lan:
1781 /* Enable retransmit on late collisions */
1782 reg_data = E1000_READ_REG(hw, TCTL);
1783 reg_data |= E1000_TCTL_RTLC;
1784 E1000_WRITE_REG(hw, TCTL, reg_data);
1785
1786 /* Configure Gigabit Carry Extend Padding */
1787 reg_data = E1000_READ_REG(hw, TCTL_EXT);
1788 reg_data &= ~E1000_TCTL_EXT_GCEX_MASK;
1789 reg_data |= DEFAULT_80003ES2LAN_TCTL_EXT_GCEX;
1790 E1000_WRITE_REG(hw, TCTL_EXT, reg_data);
1791
1792 /* Configure Transmit Inter-Packet Gap */
1793 reg_data = E1000_READ_REG(hw, TIPG);
1794 reg_data &= ~E1000_TIPG_IPGT_MASK;
1795 reg_data |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
1796 E1000_WRITE_REG(hw, TIPG, reg_data);
1797
1798 reg_data = E1000_READ_REG_ARRAY(hw, FFLT, 0x0001);
1799 reg_data &= ~0x00100000;
1800 E1000_WRITE_REG_ARRAY(hw, FFLT, 0x0001, reg_data);
1801 /* Fall through */
1802 case e1000_82571:
1803 case e1000_82572:
1804 case e1000_ich8lan:
1805 ctrl = E1000_READ_REG(hw, TXDCTL1);
1806 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH)
1807 | E1000_TXDCTL_FULL_TX_DESC_WB;
1808 E1000_WRITE_REG(hw, TXDCTL1, ctrl);
1809 break;
Roy Zang181119b2011-01-21 11:29:38 +08001810 case e1000_82573:
1811 case e1000_82574:
1812 reg_data = E1000_READ_REG(hw, GCR);
1813 reg_data |= E1000_GCR_L1_ACT_WITHOUT_L0S_RX;
1814 E1000_WRITE_REG(hw, GCR, reg_data);
Marek Vasut74a13c22014-08-08 07:41:39 -07001815 case e1000_igb:
1816 break;
Roy Zang28f7a052009-07-31 13:34:02 +08001817 }
1818
wdenk4e112c12003-06-03 23:54:09 +00001819#if 0
1820 /* Clear all of the statistics registers (clear on read). It is
1821 * important that we do this after we have tried to establish link
1822 * because the symbol error count will increment wildly if there
1823 * is no link.
1824 */
1825 e1000_clear_hw_cntrs(hw);
Roy Zang28f7a052009-07-31 13:34:02 +08001826
1827 /* ICH8 No-snoop bits are opposite polarity.
1828 * Set to snoop by default after reset. */
1829 if (hw->mac_type == e1000_ich8lan)
1830 e1000_set_pci_ex_no_snoop(hw, PCI_EX_82566_SNOOP_ALL);
wdenk4e112c12003-06-03 23:54:09 +00001831#endif
1832
Roy Zang28f7a052009-07-31 13:34:02 +08001833 if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER ||
1834 hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) {
1835 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
1836 /* Relaxed ordering must be disabled to avoid a parity
1837 * error crash in a PCI slot. */
1838 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
1839 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1840 }
1841
1842 return ret_val;
1843}
wdenk4e112c12003-06-03 23:54:09 +00001844
1845/******************************************************************************
1846 * Configures flow control and link settings.
wdenk57b2d802003-06-27 21:31:46 +00001847 *
wdenk4e112c12003-06-03 23:54:09 +00001848 * hw - Struct containing variables accessed by shared code
wdenk57b2d802003-06-27 21:31:46 +00001849 *
wdenk4e112c12003-06-03 23:54:09 +00001850 * Determines which flow control settings to use. Calls the apropriate media-
1851 * specific link configuration function. Configures the flow control settings.
1852 * Assuming the adapter has a valid link partner, a valid link should be
wdenk57b2d802003-06-27 21:31:46 +00001853 * established. Assumes the hardware has previously been reset and the
wdenk4e112c12003-06-03 23:54:09 +00001854 * transmitter and receiver are not enabled.
1855 *****************************************************************************/
1856static int
1857e1000_setup_link(struct eth_device *nic)
1858{
1859 struct e1000_hw *hw = nic->priv;
wdenk4e112c12003-06-03 23:54:09 +00001860 int32_t ret_val;
Rojhalat Ibrahimbbcd2b02013-10-07 18:30:39 +02001861#ifndef CONFIG_E1000_NO_NVM
1862 uint32_t ctrl_ext;
wdenk4e112c12003-06-03 23:54:09 +00001863 uint16_t eeprom_data;
Rojhalat Ibrahimbbcd2b02013-10-07 18:30:39 +02001864#endif
wdenk4e112c12003-06-03 23:54:09 +00001865
1866 DEBUGFUNC();
1867
Roy Zang28f7a052009-07-31 13:34:02 +08001868 /* In the case of the phy reset being blocked, we already have a link.
1869 * We do not have to set it up again. */
1870 if (e1000_check_phy_reset_block(hw))
1871 return E1000_SUCCESS;
1872
Rojhalat Ibrahimbbcd2b02013-10-07 18:30:39 +02001873#ifndef CONFIG_E1000_NO_NVM
wdenk4e112c12003-06-03 23:54:09 +00001874 /* Read and store word 0x0F of the EEPROM. This word contains bits
1875 * that determine the hardware's default PAUSE (flow control) mode,
1876 * a bit that determines whether the HW defaults to enabling or
1877 * disabling auto-negotiation, and the direction of the
1878 * SW defined pins. If there is no SW over-ride of the flow
1879 * control setting, then the variable hw->fc will
1880 * be initialized based on a value in the EEPROM.
1881 */
Roy Zang28f7a052009-07-31 13:34:02 +08001882 if (e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG, 1,
1883 &eeprom_data) < 0) {
wdenk4e112c12003-06-03 23:54:09 +00001884 DEBUGOUT("EEPROM Read Error\n");
1885 return -E1000_ERR_EEPROM;
1886 }
Rojhalat Ibrahimbbcd2b02013-10-07 18:30:39 +02001887#endif
wdenk4e112c12003-06-03 23:54:09 +00001888 if (hw->fc == e1000_fc_default) {
Roy Zang28f7a052009-07-31 13:34:02 +08001889 switch (hw->mac_type) {
1890 case e1000_ich8lan:
1891 case e1000_82573:
Roy Zang181119b2011-01-21 11:29:38 +08001892 case e1000_82574:
Marek Vasut74a13c22014-08-08 07:41:39 -07001893 case e1000_igb:
wdenk4e112c12003-06-03 23:54:09 +00001894 hw->fc = e1000_fc_full;
Roy Zang28f7a052009-07-31 13:34:02 +08001895 break;
1896 default:
Rojhalat Ibrahimbbcd2b02013-10-07 18:30:39 +02001897#ifndef CONFIG_E1000_NO_NVM
Roy Zang28f7a052009-07-31 13:34:02 +08001898 ret_val = e1000_read_eeprom(hw,
1899 EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
1900 if (ret_val) {
1901 DEBUGOUT("EEPROM Read Error\n");
1902 return -E1000_ERR_EEPROM;
1903 }
Roy Zang28f7a052009-07-31 13:34:02 +08001904 if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
1905 hw->fc = e1000_fc_none;
1906 else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
1907 EEPROM_WORD0F_ASM_DIR)
1908 hw->fc = e1000_fc_tx_pause;
1909 else
Rojhalat Ibrahimbbcd2b02013-10-07 18:30:39 +02001910#endif
Roy Zang28f7a052009-07-31 13:34:02 +08001911 hw->fc = e1000_fc_full;
1912 break;
1913 }
wdenk4e112c12003-06-03 23:54:09 +00001914 }
1915
1916 /* We want to save off the original Flow Control configuration just
1917 * in case we get disconnected and then reconnected into a different
1918 * hub or switch with different Flow Control capabilities.
1919 */
1920 if (hw->mac_type == e1000_82542_rev2_0)
1921 hw->fc &= (~e1000_fc_tx_pause);
1922
1923 if ((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
1924 hw->fc &= (~e1000_fc_rx_pause);
1925
1926 hw->original_fc = hw->fc;
1927
1928 DEBUGOUT("After fix-ups FlowControl is now = %x\n", hw->fc);
1929
Rojhalat Ibrahimbbcd2b02013-10-07 18:30:39 +02001930#ifndef CONFIG_E1000_NO_NVM
wdenk4e112c12003-06-03 23:54:09 +00001931 /* Take the 4 bits from EEPROM word 0x0F that determine the initial
1932 * polarity value for the SW controlled pins, and setup the
1933 * Extended Device Control reg with that info.
1934 * This is needed because one of the SW controlled pins is used for
1935 * signal detection. So this should be done before e1000_setup_pcs_link()
1936 * or e1000_phy_setup() is called.
1937 */
1938 if (hw->mac_type == e1000_82543) {
1939 ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
1940 SWDPIO__EXT_SHIFT);
1941 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1942 }
Rojhalat Ibrahimbbcd2b02013-10-07 18:30:39 +02001943#endif
wdenk4e112c12003-06-03 23:54:09 +00001944
1945 /* Call the necessary subroutine to configure the link. */
1946 ret_val = (hw->media_type == e1000_media_type_fiber) ?
1947 e1000_setup_fiber_link(nic) : e1000_setup_copper_link(nic);
1948 if (ret_val < 0) {
1949 return ret_val;
1950 }
1951
1952 /* Initialize the flow control address, type, and PAUSE timer
1953 * registers to their default values. This is done even if flow
1954 * control is disabled, because it does not hurt anything to
1955 * initialize these registers.
1956 */
Roy Zang28f7a052009-07-31 13:34:02 +08001957 DEBUGOUT("Initializing the Flow Control address, type"
1958 "and timer regs\n");
1959
1960 /* FCAL/H and FCT are hardcoded to standard values in e1000_ich8lan. */
1961 if (hw->mac_type != e1000_ich8lan) {
1962 E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE);
1963 E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH);
1964 E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW);
1965 }
wdenk4e112c12003-06-03 23:54:09 +00001966
wdenk4e112c12003-06-03 23:54:09 +00001967 E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time);
1968
1969 /* Set the flow control receive threshold registers. Normally,
1970 * these registers will be set to a default threshold that may be
1971 * adjusted later by the driver's runtime code. However, if the
1972 * ability to transmit pause frames in not enabled, then these
wdenk57b2d802003-06-27 21:31:46 +00001973 * registers will be set to 0.
wdenk4e112c12003-06-03 23:54:09 +00001974 */
1975 if (!(hw->fc & e1000_fc_tx_pause)) {
1976 E1000_WRITE_REG(hw, FCRTL, 0);
1977 E1000_WRITE_REG(hw, FCRTH, 0);
1978 } else {
1979 /* We need to set up the Receive Threshold high and low water marks
1980 * as well as (optionally) enabling the transmission of XON frames.
1981 */
1982 if (hw->fc_send_xon) {
1983 E1000_WRITE_REG(hw, FCRTL,
1984 (hw->fc_low_water | E1000_FCRTL_XONE));
1985 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
1986 } else {
1987 E1000_WRITE_REG(hw, FCRTL, hw->fc_low_water);
1988 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
1989 }
1990 }
1991 return ret_val;
1992}
1993
1994/******************************************************************************
1995 * Sets up link for a fiber based adapter
1996 *
1997 * hw - Struct containing variables accessed by shared code
1998 *
1999 * Manipulates Physical Coding Sublayer functions in order to configure
2000 * link. Assumes the hardware has been previously reset and the transmitter
2001 * and receiver are not enabled.
2002 *****************************************************************************/
2003static int
2004e1000_setup_fiber_link(struct eth_device *nic)
2005{
2006 struct e1000_hw *hw = nic->priv;
2007 uint32_t ctrl;
2008 uint32_t status;
2009 uint32_t txcw = 0;
2010 uint32_t i;
2011 uint32_t signal;
2012 int32_t ret_val;
2013
2014 DEBUGFUNC();
wdenk57b2d802003-06-27 21:31:46 +00002015 /* On adapters with a MAC newer that 82544, SW Defineable pin 1 will be
2016 * set when the optics detect a signal. On older adapters, it will be
wdenk4e112c12003-06-03 23:54:09 +00002017 * cleared when there is a signal
2018 */
2019 ctrl = E1000_READ_REG(hw, CTRL);
2020 if ((hw->mac_type > e1000_82544) && !(ctrl & E1000_CTRL_ILOS))
2021 signal = E1000_CTRL_SWDPIN1;
2022 else
2023 signal = 0;
2024
2025 printf("signal for %s is %x (ctrl %08x)!!!!\n", nic->name, signal,
2026 ctrl);
2027 /* Take the link out of reset */
2028 ctrl &= ~(E1000_CTRL_LRST);
2029
2030 e1000_config_collision_dist(hw);
2031
2032 /* Check for a software override of the flow control settings, and setup
2033 * the device accordingly. If auto-negotiation is enabled, then software
2034 * will have to set the "PAUSE" bits to the correct value in the Tranmsit
2035 * Config Word Register (TXCW) and re-start auto-negotiation. However, if
wdenk57b2d802003-06-27 21:31:46 +00002036 * auto-negotiation is disabled, then software will have to manually
wdenk4e112c12003-06-03 23:54:09 +00002037 * configure the two flow control enable bits in the CTRL register.
2038 *
2039 * The possible values of the "fc" parameter are:
Wolfgang Denk35f734f2008-04-13 09:59:26 -07002040 * 0: Flow control is completely disabled
2041 * 1: Rx flow control is enabled (we can receive pause frames, but
2042 * not send pause frames).
2043 * 2: Tx flow control is enabled (we can send pause frames but we do
2044 * not support receiving pause frames).
2045 * 3: Both Rx and TX flow control (symmetric) are enabled.
wdenk4e112c12003-06-03 23:54:09 +00002046 */
2047 switch (hw->fc) {
2048 case e1000_fc_none:
2049 /* Flow control is completely disabled by a software over-ride. */
2050 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
2051 break;
2052 case e1000_fc_rx_pause:
wdenk57b2d802003-06-27 21:31:46 +00002053 /* RX Flow control is enabled and TX Flow control is disabled by a
2054 * software over-ride. Since there really isn't a way to advertise
wdenk4e112c12003-06-03 23:54:09 +00002055 * that we are capable of RX Pause ONLY, we will advertise that we
2056 * support both symmetric and asymmetric RX PAUSE. Later, we will
2057 * disable the adapter's ability to send PAUSE frames.
2058 */
2059 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
2060 break;
2061 case e1000_fc_tx_pause:
wdenk57b2d802003-06-27 21:31:46 +00002062 /* TX Flow control is enabled, and RX Flow control is disabled, by a
wdenk4e112c12003-06-03 23:54:09 +00002063 * software over-ride.
2064 */
2065 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
2066 break;
2067 case e1000_fc_full:
2068 /* Flow control (both RX and TX) is enabled by a software over-ride. */
2069 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
2070 break;
2071 default:
2072 DEBUGOUT("Flow control param set incorrectly\n");
2073 return -E1000_ERR_CONFIG;
2074 break;
2075 }
2076
2077 /* Since auto-negotiation is enabled, take the link out of reset (the link
2078 * will be in reset, because we previously reset the chip). This will
2079 * restart auto-negotiation. If auto-neogtiation is successful then the
2080 * link-up status bit will be set and the flow control enable bits (RFCE
2081 * and TFCE) will be set according to their negotiated value.
2082 */
2083 DEBUGOUT("Auto-negotiation enabled (%#x)\n", txcw);
2084
2085 E1000_WRITE_REG(hw, TXCW, txcw);
2086 E1000_WRITE_REG(hw, CTRL, ctrl);
2087 E1000_WRITE_FLUSH(hw);
2088
2089 hw->txcw = txcw;
2090 mdelay(1);
2091
2092 /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
wdenk57b2d802003-06-27 21:31:46 +00002093 * indication in the Device Status Register. Time-out if a link isn't
2094 * seen in 500 milliseconds seconds (Auto-negotiation should complete in
wdenk4e112c12003-06-03 23:54:09 +00002095 * less than 500 milliseconds even if the other end is doing it in SW).
2096 */
2097 if ((E1000_READ_REG(hw, CTRL) & E1000_CTRL_SWDPIN1) == signal) {
2098 DEBUGOUT("Looking for Link\n");
2099 for (i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
2100 mdelay(10);
2101 status = E1000_READ_REG(hw, STATUS);
2102 if (status & E1000_STATUS_LU)
2103 break;
2104 }
2105 if (i == (LINK_UP_TIMEOUT / 10)) {
wdenk57b2d802003-06-27 21:31:46 +00002106 /* AutoNeg failed to achieve a link, so we'll call
wdenk4e112c12003-06-03 23:54:09 +00002107 * e1000_check_for_link. This routine will force the link up if we
2108 * detect a signal. This will allow us to communicate with
2109 * non-autonegotiating link partners.
2110 */
2111 DEBUGOUT("Never got a valid link from auto-neg!!!\n");
2112 hw->autoneg_failed = 1;
2113 ret_val = e1000_check_for_link(nic);
2114 if (ret_val < 0) {
2115 DEBUGOUT("Error while checking for link\n");
2116 return ret_val;
2117 }
2118 hw->autoneg_failed = 0;
2119 } else {
2120 hw->autoneg_failed = 0;
2121 DEBUGOUT("Valid Link Found\n");
2122 }
2123 } else {
2124 DEBUGOUT("No Signal Detected\n");
2125 return -E1000_ERR_NOLINK;
2126 }
2127 return 0;
2128}
2129
2130/******************************************************************************
Roy Zang28f7a052009-07-31 13:34:02 +08002131* Make sure we have a valid PHY and change PHY mode before link setup.
wdenk4e112c12003-06-03 23:54:09 +00002132*
2133* hw - Struct containing variables accessed by shared code
2134******************************************************************************/
Roy Zang28f7a052009-07-31 13:34:02 +08002135static int32_t
2136e1000_copper_link_preconfig(struct e1000_hw *hw)
wdenk4e112c12003-06-03 23:54:09 +00002137{
wdenk4e112c12003-06-03 23:54:09 +00002138 uint32_t ctrl;
2139 int32_t ret_val;
wdenk4e112c12003-06-03 23:54:09 +00002140 uint16_t phy_data;
2141
2142 DEBUGFUNC();
2143
2144 ctrl = E1000_READ_REG(hw, CTRL);
2145 /* With 82543, we need to force speed and duplex on the MAC equal to what
2146 * the PHY speed and duplex configuration is. In addition, we need to
2147 * perform a hardware reset on the PHY to take it out of reset.
2148 */
2149 if (hw->mac_type > e1000_82543) {
2150 ctrl |= E1000_CTRL_SLU;
2151 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2152 E1000_WRITE_REG(hw, CTRL, ctrl);
2153 } else {
Roy Zang28f7a052009-07-31 13:34:02 +08002154 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX
2155 | E1000_CTRL_SLU);
wdenk4e112c12003-06-03 23:54:09 +00002156 E1000_WRITE_REG(hw, CTRL, ctrl);
Roy Zang28f7a052009-07-31 13:34:02 +08002157 ret_val = e1000_phy_hw_reset(hw);
2158 if (ret_val)
2159 return ret_val;
wdenk4e112c12003-06-03 23:54:09 +00002160 }
2161
2162 /* Make sure we have a valid PHY */
2163 ret_val = e1000_detect_gig_phy(hw);
Roy Zang28f7a052009-07-31 13:34:02 +08002164 if (ret_val) {
wdenk4e112c12003-06-03 23:54:09 +00002165 DEBUGOUT("Error, did not detect valid phy.\n");
2166 return ret_val;
2167 }
2168 DEBUGOUT("Phy ID = %x \n", hw->phy_id);
2169
Roy Zang28f7a052009-07-31 13:34:02 +08002170 /* Set PHY to class A mode (if necessary) */
2171 ret_val = e1000_set_phy_mode(hw);
2172 if (ret_val)
2173 return ret_val;
Roy Zang28f7a052009-07-31 13:34:02 +08002174 if ((hw->mac_type == e1000_82545_rev_3) ||
2175 (hw->mac_type == e1000_82546_rev_3)) {
2176 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL,
2177 &phy_data);
2178 phy_data |= 0x00000008;
2179 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL,
2180 phy_data);
2181 }
2182
2183 if (hw->mac_type <= e1000_82543 ||
2184 hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
2185 hw->mac_type == e1000_82541_rev_2
2186 || hw->mac_type == e1000_82547_rev_2)
York Sun4a598092013-04-01 11:29:11 -07002187 hw->phy_reset_disable = false;
Roy Zang28f7a052009-07-31 13:34:02 +08002188
2189 return E1000_SUCCESS;
2190}
2191
2192/*****************************************************************************
2193 *
2194 * This function sets the lplu state according to the active flag. When
2195 * activating lplu this function also disables smart speed and vise versa.
2196 * lplu will not be activated unless the device autonegotiation advertisment
2197 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
2198 * hw: Struct containing variables accessed by shared code
2199 * active - true to enable lplu false to disable lplu.
2200 *
2201 * returns: - E1000_ERR_PHY if fail to read/write the PHY
2202 * E1000_SUCCESS at any other case.
2203 *
2204 ****************************************************************************/
2205
2206static int32_t
York Sun4a598092013-04-01 11:29:11 -07002207e1000_set_d3_lplu_state(struct e1000_hw *hw, bool active)
Roy Zang28f7a052009-07-31 13:34:02 +08002208{
2209 uint32_t phy_ctrl = 0;
2210 int32_t ret_val;
2211 uint16_t phy_data;
2212 DEBUGFUNC();
2213
2214 if (hw->phy_type != e1000_phy_igp && hw->phy_type != e1000_phy_igp_2
2215 && hw->phy_type != e1000_phy_igp_3)
2216 return E1000_SUCCESS;
2217
2218 /* During driver activity LPLU should not be used or it will attain link
2219 * from the lowest speeds starting from 10Mbps. The capability is used
2220 * for Dx transitions and states */
2221 if (hw->mac_type == e1000_82541_rev_2
2222 || hw->mac_type == e1000_82547_rev_2) {
2223 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO,
2224 &phy_data);
2225 if (ret_val)
2226 return ret_val;
2227 } else if (hw->mac_type == e1000_ich8lan) {
2228 /* MAC writes into PHY register based on the state transition
2229 * and start auto-negotiation. SW driver can overwrite the
2230 * settings in CSR PHY power control E1000_PHY_CTRL register. */
2231 phy_ctrl = E1000_READ_REG(hw, PHY_CTRL);
2232 } else {
2233 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
2234 &phy_data);
2235 if (ret_val)
2236 return ret_val;
2237 }
2238
2239 if (!active) {
2240 if (hw->mac_type == e1000_82541_rev_2 ||
2241 hw->mac_type == e1000_82547_rev_2) {
2242 phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
2243 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
2244 phy_data);
2245 if (ret_val)
2246 return ret_val;
2247 } else {
2248 if (hw->mac_type == e1000_ich8lan) {
2249 phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU;
2250 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
2251 } else {
2252 phy_data &= ~IGP02E1000_PM_D3_LPLU;
2253 ret_val = e1000_write_phy_reg(hw,
2254 IGP02E1000_PHY_POWER_MGMT, phy_data);
2255 if (ret_val)
2256 return ret_val;
2257 }
2258 }
2259
2260 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
2261 * Dx states where the power conservation is most important. During
2262 * driver activity we should enable SmartSpeed, so performance is
2263 * maintained. */
2264 if (hw->smart_speed == e1000_smart_speed_on) {
2265 ret_val = e1000_read_phy_reg(hw,
2266 IGP01E1000_PHY_PORT_CONFIG, &phy_data);
2267 if (ret_val)
2268 return ret_val;
2269
2270 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
2271 ret_val = e1000_write_phy_reg(hw,
2272 IGP01E1000_PHY_PORT_CONFIG, phy_data);
2273 if (ret_val)
2274 return ret_val;
2275 } else if (hw->smart_speed == e1000_smart_speed_off) {
2276 ret_val = e1000_read_phy_reg(hw,
2277 IGP01E1000_PHY_PORT_CONFIG, &phy_data);
2278 if (ret_val)
2279 return ret_val;
2280
2281 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2282 ret_val = e1000_write_phy_reg(hw,
2283 IGP01E1000_PHY_PORT_CONFIG, phy_data);
2284 if (ret_val)
2285 return ret_val;
2286 }
2287
2288 } else if ((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT)
2289 || (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL) ||
2290 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_100_ALL)) {
2291
2292 if (hw->mac_type == e1000_82541_rev_2 ||
2293 hw->mac_type == e1000_82547_rev_2) {
2294 phy_data |= IGP01E1000_GMII_FLEX_SPD;
2295 ret_val = e1000_write_phy_reg(hw,
2296 IGP01E1000_GMII_FIFO, phy_data);
2297 if (ret_val)
2298 return ret_val;
2299 } else {
2300 if (hw->mac_type == e1000_ich8lan) {
2301 phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU;
2302 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
2303 } else {
2304 phy_data |= IGP02E1000_PM_D3_LPLU;
2305 ret_val = e1000_write_phy_reg(hw,
2306 IGP02E1000_PHY_POWER_MGMT, phy_data);
2307 if (ret_val)
2308 return ret_val;
2309 }
2310 }
2311
2312 /* When LPLU is enabled we should disable SmartSpeed */
2313 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
2314 &phy_data);
2315 if (ret_val)
2316 return ret_val;
2317
2318 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2319 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
2320 phy_data);
2321 if (ret_val)
2322 return ret_val;
2323 }
2324 return E1000_SUCCESS;
2325}
2326
2327/*****************************************************************************
2328 *
2329 * This function sets the lplu d0 state according to the active flag. When
2330 * activating lplu this function also disables smart speed and vise versa.
2331 * lplu will not be activated unless the device autonegotiation advertisment
2332 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
2333 * hw: Struct containing variables accessed by shared code
2334 * active - true to enable lplu false to disable lplu.
2335 *
2336 * returns: - E1000_ERR_PHY if fail to read/write the PHY
2337 * E1000_SUCCESS at any other case.
2338 *
2339 ****************************************************************************/
2340
2341static int32_t
York Sun4a598092013-04-01 11:29:11 -07002342e1000_set_d0_lplu_state(struct e1000_hw *hw, bool active)
Roy Zang28f7a052009-07-31 13:34:02 +08002343{
2344 uint32_t phy_ctrl = 0;
2345 int32_t ret_val;
2346 uint16_t phy_data;
2347 DEBUGFUNC();
2348
2349 if (hw->mac_type <= e1000_82547_rev_2)
2350 return E1000_SUCCESS;
2351
2352 if (hw->mac_type == e1000_ich8lan) {
2353 phy_ctrl = E1000_READ_REG(hw, PHY_CTRL);
Marek Vasut74a13c22014-08-08 07:41:39 -07002354 } else if (hw->mac_type == e1000_igb) {
2355 phy_ctrl = E1000_READ_REG(hw, I210_PHY_CTRL);
Roy Zang28f7a052009-07-31 13:34:02 +08002356 } else {
2357 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
2358 &phy_data);
2359 if (ret_val)
2360 return ret_val;
2361 }
2362
2363 if (!active) {
2364 if (hw->mac_type == e1000_ich8lan) {
2365 phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
2366 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
Marek Vasut74a13c22014-08-08 07:41:39 -07002367 } else if (hw->mac_type == e1000_igb) {
2368 phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
2369 E1000_WRITE_REG(hw, I210_PHY_CTRL, phy_ctrl);
Roy Zang28f7a052009-07-31 13:34:02 +08002370 } else {
2371 phy_data &= ~IGP02E1000_PM_D0_LPLU;
2372 ret_val = e1000_write_phy_reg(hw,
2373 IGP02E1000_PHY_POWER_MGMT, phy_data);
2374 if (ret_val)
2375 return ret_val;
2376 }
2377
Marek Vasut74a13c22014-08-08 07:41:39 -07002378 if (hw->mac_type == e1000_igb)
2379 return E1000_SUCCESS;
2380
Roy Zang28f7a052009-07-31 13:34:02 +08002381 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
2382 * Dx states where the power conservation is most important. During
2383 * driver activity we should enable SmartSpeed, so performance is
2384 * maintained. */
2385 if (hw->smart_speed == e1000_smart_speed_on) {
2386 ret_val = e1000_read_phy_reg(hw,
2387 IGP01E1000_PHY_PORT_CONFIG, &phy_data);
2388 if (ret_val)
2389 return ret_val;
2390
2391 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
2392 ret_val = e1000_write_phy_reg(hw,
2393 IGP01E1000_PHY_PORT_CONFIG, phy_data);
2394 if (ret_val)
2395 return ret_val;
2396 } else if (hw->smart_speed == e1000_smart_speed_off) {
2397 ret_val = e1000_read_phy_reg(hw,
2398 IGP01E1000_PHY_PORT_CONFIG, &phy_data);
2399 if (ret_val)
2400 return ret_val;
2401
2402 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2403 ret_val = e1000_write_phy_reg(hw,
2404 IGP01E1000_PHY_PORT_CONFIG, phy_data);
2405 if (ret_val)
2406 return ret_val;
2407 }
2408
2409
2410 } else {
2411
2412 if (hw->mac_type == e1000_ich8lan) {
2413 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
2414 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
Marek Vasut74a13c22014-08-08 07:41:39 -07002415 } else if (hw->mac_type == e1000_igb) {
2416 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
2417 E1000_WRITE_REG(hw, I210_PHY_CTRL, phy_ctrl);
Roy Zang28f7a052009-07-31 13:34:02 +08002418 } else {
2419 phy_data |= IGP02E1000_PM_D0_LPLU;
2420 ret_val = e1000_write_phy_reg(hw,
2421 IGP02E1000_PHY_POWER_MGMT, phy_data);
2422 if (ret_val)
2423 return ret_val;
2424 }
2425
Marek Vasut74a13c22014-08-08 07:41:39 -07002426 if (hw->mac_type == e1000_igb)
2427 return E1000_SUCCESS;
2428
Roy Zang28f7a052009-07-31 13:34:02 +08002429 /* When LPLU is enabled we should disable SmartSpeed */
2430 ret_val = e1000_read_phy_reg(hw,
2431 IGP01E1000_PHY_PORT_CONFIG, &phy_data);
2432 if (ret_val)
2433 return ret_val;
2434
2435 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2436 ret_val = e1000_write_phy_reg(hw,
2437 IGP01E1000_PHY_PORT_CONFIG, phy_data);
2438 if (ret_val)
2439 return ret_val;
2440
2441 }
2442 return E1000_SUCCESS;
2443}
2444
2445/********************************************************************
2446* Copper link setup for e1000_phy_igp series.
2447*
2448* hw - Struct containing variables accessed by shared code
2449*********************************************************************/
2450static int32_t
2451e1000_copper_link_igp_setup(struct e1000_hw *hw)
2452{
2453 uint32_t led_ctrl;
2454 int32_t ret_val;
2455 uint16_t phy_data;
2456
Timur Tabiedc45b52009-08-17 15:55:38 -05002457 DEBUGFUNC();
Roy Zang28f7a052009-07-31 13:34:02 +08002458
2459 if (hw->phy_reset_disable)
2460 return E1000_SUCCESS;
2461
2462 ret_val = e1000_phy_reset(hw);
2463 if (ret_val) {
2464 DEBUGOUT("Error Resetting the PHY\n");
2465 return ret_val;
wdenk4e112c12003-06-03 23:54:09 +00002466 }
Roy Zang28f7a052009-07-31 13:34:02 +08002467
2468 /* Wait 15ms for MAC to configure PHY from eeprom settings */
2469 mdelay(15);
2470 if (hw->mac_type != e1000_ich8lan) {
2471 /* Configure activity LED after PHY reset */
2472 led_ctrl = E1000_READ_REG(hw, LEDCTL);
2473 led_ctrl &= IGP_ACTIVITY_LED_MASK;
2474 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
2475 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
2476 }
2477
2478 /* The NVM settings will configure LPLU in D3 for IGP2 and IGP3 PHYs */
2479 if (hw->phy_type == e1000_phy_igp) {
2480 /* disable lplu d3 during driver init */
York Sun4a598092013-04-01 11:29:11 -07002481 ret_val = e1000_set_d3_lplu_state(hw, false);
Roy Zang28f7a052009-07-31 13:34:02 +08002482 if (ret_val) {
2483 DEBUGOUT("Error Disabling LPLU D3\n");
2484 return ret_val;
2485 }
2486 }
2487
2488 /* disable lplu d0 during driver init */
York Sun4a598092013-04-01 11:29:11 -07002489 ret_val = e1000_set_d0_lplu_state(hw, false);
Roy Zang28f7a052009-07-31 13:34:02 +08002490 if (ret_val) {
2491 DEBUGOUT("Error Disabling LPLU D0\n");
2492 return ret_val;
2493 }
2494 /* Configure mdi-mdix settings */
2495 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
2496 if (ret_val)
2497 return ret_val;
2498
2499 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
2500 hw->dsp_config_state = e1000_dsp_config_disabled;
2501 /* Force MDI for earlier revs of the IGP PHY */
2502 phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX
2503 | IGP01E1000_PSCR_FORCE_MDI_MDIX);
2504 hw->mdix = 1;
2505
2506 } else {
2507 hw->dsp_config_state = e1000_dsp_config_enabled;
2508 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
2509
2510 switch (hw->mdix) {
2511 case 1:
2512 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
2513 break;
2514 case 2:
2515 phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
2516 break;
2517 case 0:
2518 default:
2519 phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
2520 break;
2521 }
2522 }
2523 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
2524 if (ret_val)
2525 return ret_val;
2526
2527 /* set auto-master slave resolution settings */
2528 if (hw->autoneg) {
2529 e1000_ms_type phy_ms_setting = hw->master_slave;
2530
2531 if (hw->ffe_config_state == e1000_ffe_config_active)
2532 hw->ffe_config_state = e1000_ffe_config_enabled;
2533
2534 if (hw->dsp_config_state == e1000_dsp_config_activated)
2535 hw->dsp_config_state = e1000_dsp_config_enabled;
2536
2537 /* when autonegotiation advertisment is only 1000Mbps then we
2538 * should disable SmartSpeed and enable Auto MasterSlave
2539 * resolution as hardware default. */
2540 if (hw->autoneg_advertised == ADVERTISE_1000_FULL) {
2541 /* Disable SmartSpeed */
2542 ret_val = e1000_read_phy_reg(hw,
2543 IGP01E1000_PHY_PORT_CONFIG, &phy_data);
2544 if (ret_val)
2545 return ret_val;
2546 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2547 ret_val = e1000_write_phy_reg(hw,
2548 IGP01E1000_PHY_PORT_CONFIG, phy_data);
2549 if (ret_val)
2550 return ret_val;
2551 /* Set auto Master/Slave resolution process */
2552 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL,
2553 &phy_data);
2554 if (ret_val)
2555 return ret_val;
2556 phy_data &= ~CR_1000T_MS_ENABLE;
2557 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL,
2558 phy_data);
2559 if (ret_val)
2560 return ret_val;
2561 }
2562
2563 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
2564 if (ret_val)
2565 return ret_val;
2566
2567 /* load defaults for future use */
2568 hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
2569 ((phy_data & CR_1000T_MS_VALUE) ?
2570 e1000_ms_force_master :
2571 e1000_ms_force_slave) :
2572 e1000_ms_auto;
2573
2574 switch (phy_ms_setting) {
2575 case e1000_ms_force_master:
2576 phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
2577 break;
2578 case e1000_ms_force_slave:
2579 phy_data |= CR_1000T_MS_ENABLE;
2580 phy_data &= ~(CR_1000T_MS_VALUE);
2581 break;
2582 case e1000_ms_auto:
2583 phy_data &= ~CR_1000T_MS_ENABLE;
2584 default:
2585 break;
2586 }
2587 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
2588 if (ret_val)
2589 return ret_val;
2590 }
2591
2592 return E1000_SUCCESS;
2593}
2594
2595/*****************************************************************************
2596 * This function checks the mode of the firmware.
2597 *
York Sun4a598092013-04-01 11:29:11 -07002598 * returns - true when the mode is IAMT or false.
Roy Zang28f7a052009-07-31 13:34:02 +08002599 ****************************************************************************/
York Sun4a598092013-04-01 11:29:11 -07002600bool
Roy Zang28f7a052009-07-31 13:34:02 +08002601e1000_check_mng_mode(struct e1000_hw *hw)
2602{
2603 uint32_t fwsm;
2604 DEBUGFUNC();
2605
2606 fwsm = E1000_READ_REG(hw, FWSM);
2607
2608 if (hw->mac_type == e1000_ich8lan) {
2609 if ((fwsm & E1000_FWSM_MODE_MASK) ==
2610 (E1000_MNG_ICH_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
York Sun4a598092013-04-01 11:29:11 -07002611 return true;
Roy Zang28f7a052009-07-31 13:34:02 +08002612 } else if ((fwsm & E1000_FWSM_MODE_MASK) ==
2613 (E1000_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
York Sun4a598092013-04-01 11:29:11 -07002614 return true;
Roy Zang28f7a052009-07-31 13:34:02 +08002615
York Sun4a598092013-04-01 11:29:11 -07002616 return false;
Roy Zang28f7a052009-07-31 13:34:02 +08002617}
2618
2619static int32_t
2620e1000_write_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t data)
2621{
Kyle Moffett7376f8d2010-09-13 05:52:22 +00002622 uint16_t swfw = E1000_SWFW_PHY0_SM;
Roy Zang28f7a052009-07-31 13:34:02 +08002623 uint32_t reg_val;
Roy Zang28f7a052009-07-31 13:34:02 +08002624 DEBUGFUNC();
2625
Kyle Moffett7376f8d2010-09-13 05:52:22 +00002626 if (e1000_is_second_port(hw))
Roy Zang28f7a052009-07-31 13:34:02 +08002627 swfw = E1000_SWFW_PHY1_SM;
Kyle Moffett7376f8d2010-09-13 05:52:22 +00002628
Roy Zang28f7a052009-07-31 13:34:02 +08002629 if (e1000_swfw_sync_acquire(hw, swfw))
2630 return -E1000_ERR_SWFW_SYNC;
2631
2632 reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT)
2633 & E1000_KUMCTRLSTA_OFFSET) | data;
2634 E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
2635 udelay(2);
2636
2637 return E1000_SUCCESS;
2638}
2639
2640static int32_t
2641e1000_read_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t *data)
2642{
Kyle Moffett7376f8d2010-09-13 05:52:22 +00002643 uint16_t swfw = E1000_SWFW_PHY0_SM;
Roy Zang28f7a052009-07-31 13:34:02 +08002644 uint32_t reg_val;
Roy Zang28f7a052009-07-31 13:34:02 +08002645 DEBUGFUNC();
2646
Kyle Moffett7376f8d2010-09-13 05:52:22 +00002647 if (e1000_is_second_port(hw))
Roy Zang28f7a052009-07-31 13:34:02 +08002648 swfw = E1000_SWFW_PHY1_SM;
Kyle Moffett7376f8d2010-09-13 05:52:22 +00002649
Marek Vasut74a13c22014-08-08 07:41:39 -07002650 if (e1000_swfw_sync_acquire(hw, swfw)) {
2651 debug("%s[%i]\n", __func__, __LINE__);
Roy Zang28f7a052009-07-31 13:34:02 +08002652 return -E1000_ERR_SWFW_SYNC;
Marek Vasut74a13c22014-08-08 07:41:39 -07002653 }
Roy Zang28f7a052009-07-31 13:34:02 +08002654
2655 /* Write register address */
2656 reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) &
2657 E1000_KUMCTRLSTA_OFFSET) | E1000_KUMCTRLSTA_REN;
2658 E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
2659 udelay(2);
2660
2661 /* Read the data returned */
2662 reg_val = E1000_READ_REG(hw, KUMCTRLSTA);
2663 *data = (uint16_t)reg_val;
2664
2665 return E1000_SUCCESS;
2666}
2667
2668/********************************************************************
2669* Copper link setup for e1000_phy_gg82563 series.
2670*
2671* hw - Struct containing variables accessed by shared code
2672*********************************************************************/
2673static int32_t
2674e1000_copper_link_ggp_setup(struct e1000_hw *hw)
2675{
2676 int32_t ret_val;
2677 uint16_t phy_data;
2678 uint32_t reg_data;
2679
2680 DEBUGFUNC();
2681
2682 if (!hw->phy_reset_disable) {
2683 /* Enable CRS on TX for half-duplex operation. */
2684 ret_val = e1000_read_phy_reg(hw,
2685 GG82563_PHY_MAC_SPEC_CTRL, &phy_data);
2686 if (ret_val)
2687 return ret_val;
2688
2689 phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
2690 /* Use 25MHz for both link down and 1000BASE-T for Tx clock */
2691 phy_data |= GG82563_MSCR_TX_CLK_1000MBPS_25MHZ;
2692
2693 ret_val = e1000_write_phy_reg(hw,
2694 GG82563_PHY_MAC_SPEC_CTRL, phy_data);
2695 if (ret_val)
2696 return ret_val;
2697
2698 /* Options:
2699 * MDI/MDI-X = 0 (default)
2700 * 0 - Auto for all speeds
2701 * 1 - MDI mode
2702 * 2 - MDI-X mode
2703 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
2704 */
2705 ret_val = e1000_read_phy_reg(hw,
2706 GG82563_PHY_SPEC_CTRL, &phy_data);
2707 if (ret_val)
2708 return ret_val;
2709
2710 phy_data &= ~GG82563_PSCR_CROSSOVER_MODE_MASK;
2711
2712 switch (hw->mdix) {
2713 case 1:
2714 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDI;
2715 break;
2716 case 2:
2717 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDIX;
2718 break;
2719 case 0:
2720 default:
2721 phy_data |= GG82563_PSCR_CROSSOVER_MODE_AUTO;
2722 break;
2723 }
2724
2725 /* Options:
2726 * disable_polarity_correction = 0 (default)
2727 * Automatic Correction for Reversed Cable Polarity
2728 * 0 - Disabled
2729 * 1 - Enabled
2730 */
2731 phy_data &= ~GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
2732 ret_val = e1000_write_phy_reg(hw,
2733 GG82563_PHY_SPEC_CTRL, phy_data);
2734
2735 if (ret_val)
2736 return ret_val;
2737
2738 /* SW Reset the PHY so all changes take effect */
2739 ret_val = e1000_phy_reset(hw);
2740 if (ret_val) {
2741 DEBUGOUT("Error Resetting the PHY\n");
2742 return ret_val;
2743 }
2744 } /* phy_reset_disable */
2745
2746 if (hw->mac_type == e1000_80003es2lan) {
2747 /* Bypass RX and TX FIFO's */
2748 ret_val = e1000_write_kmrn_reg(hw,
2749 E1000_KUMCTRLSTA_OFFSET_FIFO_CTRL,
2750 E1000_KUMCTRLSTA_FIFO_CTRL_RX_BYPASS
2751 | E1000_KUMCTRLSTA_FIFO_CTRL_TX_BYPASS);
2752 if (ret_val)
2753 return ret_val;
2754
2755 ret_val = e1000_read_phy_reg(hw,
2756 GG82563_PHY_SPEC_CTRL_2, &phy_data);
2757 if (ret_val)
2758 return ret_val;
2759
2760 phy_data &= ~GG82563_PSCR2_REVERSE_AUTO_NEG;
2761 ret_val = e1000_write_phy_reg(hw,
2762 GG82563_PHY_SPEC_CTRL_2, phy_data);
2763
2764 if (ret_val)
2765 return ret_val;
2766
2767 reg_data = E1000_READ_REG(hw, CTRL_EXT);
2768 reg_data &= ~(E1000_CTRL_EXT_LINK_MODE_MASK);
2769 E1000_WRITE_REG(hw, CTRL_EXT, reg_data);
2770
2771 ret_val = e1000_read_phy_reg(hw,
2772 GG82563_PHY_PWR_MGMT_CTRL, &phy_data);
2773 if (ret_val)
2774 return ret_val;
2775
2776 /* Do not init these registers when the HW is in IAMT mode, since the
2777 * firmware will have already initialized them. We only initialize
2778 * them if the HW is not in IAMT mode.
2779 */
York Sun4a598092013-04-01 11:29:11 -07002780 if (e1000_check_mng_mode(hw) == false) {
Roy Zang28f7a052009-07-31 13:34:02 +08002781 /* Enable Electrical Idle on the PHY */
2782 phy_data |= GG82563_PMCR_ENABLE_ELECTRICAL_IDLE;
2783 ret_val = e1000_write_phy_reg(hw,
2784 GG82563_PHY_PWR_MGMT_CTRL, phy_data);
2785 if (ret_val)
2786 return ret_val;
2787
2788 ret_val = e1000_read_phy_reg(hw,
2789 GG82563_PHY_KMRN_MODE_CTRL, &phy_data);
2790 if (ret_val)
2791 return ret_val;
2792
2793 phy_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
2794 ret_val = e1000_write_phy_reg(hw,
2795 GG82563_PHY_KMRN_MODE_CTRL, phy_data);
2796
2797 if (ret_val)
2798 return ret_val;
2799 }
2800
2801 /* Workaround: Disable padding in Kumeran interface in the MAC
2802 * and in the PHY to avoid CRC errors.
2803 */
2804 ret_val = e1000_read_phy_reg(hw,
2805 GG82563_PHY_INBAND_CTRL, &phy_data);
2806 if (ret_val)
2807 return ret_val;
2808 phy_data |= GG82563_ICR_DIS_PADDING;
2809 ret_val = e1000_write_phy_reg(hw,
2810 GG82563_PHY_INBAND_CTRL, phy_data);
2811 if (ret_val)
2812 return ret_val;
2813 }
2814 return E1000_SUCCESS;
2815}
2816
2817/********************************************************************
2818* Copper link setup for e1000_phy_m88 series.
2819*
2820* hw - Struct containing variables accessed by shared code
2821*********************************************************************/
2822static int32_t
2823e1000_copper_link_mgp_setup(struct e1000_hw *hw)
2824{
2825 int32_t ret_val;
2826 uint16_t phy_data;
2827
2828 DEBUGFUNC();
2829
2830 if (hw->phy_reset_disable)
2831 return E1000_SUCCESS;
2832
2833 /* Enable CRS on TX. This must be set for half-duplex operation. */
2834 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
2835 if (ret_val)
2836 return ret_val;
2837
wdenk4e112c12003-06-03 23:54:09 +00002838 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
2839
wdenk4e112c12003-06-03 23:54:09 +00002840 /* Options:
2841 * MDI/MDI-X = 0 (default)
2842 * 0 - Auto for all speeds
2843 * 1 - MDI mode
2844 * 2 - MDI-X mode
2845 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
2846 */
2847 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
Roy Zang28f7a052009-07-31 13:34:02 +08002848
wdenk4e112c12003-06-03 23:54:09 +00002849 switch (hw->mdix) {
2850 case 1:
2851 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
2852 break;
2853 case 2:
2854 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
2855 break;
2856 case 3:
2857 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
2858 break;
2859 case 0:
2860 default:
2861 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
2862 break;
2863 }
wdenk4e112c12003-06-03 23:54:09 +00002864
wdenk4e112c12003-06-03 23:54:09 +00002865 /* Options:
2866 * disable_polarity_correction = 0 (default)
Roy Zang28f7a052009-07-31 13:34:02 +08002867 * Automatic Correction for Reversed Cable Polarity
wdenk4e112c12003-06-03 23:54:09 +00002868 * 0 - Disabled
2869 * 1 - Enabled
2870 */
2871 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
Roy Zang28f7a052009-07-31 13:34:02 +08002872 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
2873 if (ret_val)
2874 return ret_val;
wdenk4e112c12003-06-03 23:54:09 +00002875
Roy Zang28f7a052009-07-31 13:34:02 +08002876 if (hw->phy_revision < M88E1011_I_REV_4) {
2877 /* Force TX_CLK in the Extended PHY Specific Control Register
2878 * to 25MHz clock.
2879 */
2880 ret_val = e1000_read_phy_reg(hw,
2881 M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
2882 if (ret_val)
2883 return ret_val;
2884
2885 phy_data |= M88E1000_EPSCR_TX_CLK_25;
2886
2887 if ((hw->phy_revision == E1000_REVISION_2) &&
2888 (hw->phy_id == M88E1111_I_PHY_ID)) {
2889 /* Vidalia Phy, set the downshift counter to 5x */
2890 phy_data &= ~(M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK);
2891 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
2892 ret_val = e1000_write_phy_reg(hw,
2893 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
2894 if (ret_val)
2895 return ret_val;
2896 } else {
2897 /* Configure Master and Slave downshift values */
2898 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK
2899 | M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
2900 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X
2901 | M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
2902 ret_val = e1000_write_phy_reg(hw,
2903 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
2904 if (ret_val)
2905 return ret_val;
2906 }
wdenk4e112c12003-06-03 23:54:09 +00002907 }
2908
2909 /* SW Reset the PHY so all changes take effect */
2910 ret_val = e1000_phy_reset(hw);
Roy Zang28f7a052009-07-31 13:34:02 +08002911 if (ret_val) {
wdenk4e112c12003-06-03 23:54:09 +00002912 DEBUGOUT("Error Resetting the PHY\n");
2913 return ret_val;
2914 }
2915
Roy Zang28f7a052009-07-31 13:34:02 +08002916 return E1000_SUCCESS;
2917}
wdenk4e112c12003-06-03 23:54:09 +00002918
Roy Zang28f7a052009-07-31 13:34:02 +08002919/********************************************************************
2920* Setup auto-negotiation and flow control advertisements,
2921* and then perform auto-negotiation.
2922*
2923* hw - Struct containing variables accessed by shared code
2924*********************************************************************/
2925static int32_t
2926e1000_copper_link_autoneg(struct e1000_hw *hw)
2927{
2928 int32_t ret_val;
2929 uint16_t phy_data;
2930
2931 DEBUGFUNC();
2932
wdenk4e112c12003-06-03 23:54:09 +00002933 /* Perform some bounds checking on the hw->autoneg_advertised
2934 * parameter. If this variable is zero, then set it to the default.
2935 */
2936 hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
2937
2938 /* If autoneg_advertised is zero, we assume it was not defaulted
2939 * by the calling code so we set to advertise full capability.
2940 */
2941 if (hw->autoneg_advertised == 0)
2942 hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
2943
Roy Zang28f7a052009-07-31 13:34:02 +08002944 /* IFE phy only supports 10/100 */
2945 if (hw->phy_type == e1000_phy_ife)
2946 hw->autoneg_advertised &= AUTONEG_ADVERTISE_10_100_ALL;
2947
wdenk4e112c12003-06-03 23:54:09 +00002948 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
2949 ret_val = e1000_phy_setup_autoneg(hw);
Roy Zang28f7a052009-07-31 13:34:02 +08002950 if (ret_val) {
wdenk4e112c12003-06-03 23:54:09 +00002951 DEBUGOUT("Error Setting up Auto-Negotiation\n");
2952 return ret_val;
2953 }
2954 DEBUGOUT("Restarting Auto-Neg\n");
2955
2956 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
2957 * the Auto Neg Restart bit in the PHY control register.
2958 */
Roy Zang28f7a052009-07-31 13:34:02 +08002959 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
2960 if (ret_val)
2961 return ret_val;
2962
wdenk4e112c12003-06-03 23:54:09 +00002963 phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
Roy Zang28f7a052009-07-31 13:34:02 +08002964 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
2965 if (ret_val)
2966 return ret_val;
2967
wdenk4e112c12003-06-03 23:54:09 +00002968 /* Does the user want to wait for Auto-Neg to complete here, or
2969 * check at a later time (for example, callback routine).
2970 */
Roy Zang28f7a052009-07-31 13:34:02 +08002971 /* If we do not wait for autonegtation to complete I
2972 * do not see a valid link status.
2973 * wait_autoneg_complete = 1 .
2974 */
wdenk4e112c12003-06-03 23:54:09 +00002975 if (hw->wait_autoneg_complete) {
2976 ret_val = e1000_wait_autoneg(hw);
Roy Zang28f7a052009-07-31 13:34:02 +08002977 if (ret_val) {
2978 DEBUGOUT("Error while waiting for autoneg"
2979 "to complete\n");
wdenk4e112c12003-06-03 23:54:09 +00002980 return ret_val;
2981 }
2982 }
Roy Zang28f7a052009-07-31 13:34:02 +08002983
York Sun4a598092013-04-01 11:29:11 -07002984 hw->get_link_status = true;
Roy Zang28f7a052009-07-31 13:34:02 +08002985
2986 return E1000_SUCCESS;
2987}
2988
2989/******************************************************************************
2990* Config the MAC and the PHY after link is up.
2991* 1) Set up the MAC to the current PHY speed/duplex
2992* if we are on 82543. If we
2993* are on newer silicon, we only need to configure
2994* collision distance in the Transmit Control Register.
2995* 2) Set up flow control on the MAC to that established with
2996* the link partner.
2997* 3) Config DSP to improve Gigabit link quality for some PHY revisions.
2998*
2999* hw - Struct containing variables accessed by shared code
3000******************************************************************************/
3001static int32_t
3002e1000_copper_link_postconfig(struct e1000_hw *hw)
3003{
3004 int32_t ret_val;
3005 DEBUGFUNC();
3006
3007 if (hw->mac_type >= e1000_82544) {
3008 e1000_config_collision_dist(hw);
3009 } else {
3010 ret_val = e1000_config_mac_to_phy(hw);
3011 if (ret_val) {
3012 DEBUGOUT("Error configuring MAC to PHY settings\n");
3013 return ret_val;
3014 }
3015 }
3016 ret_val = e1000_config_fc_after_link_up(hw);
3017 if (ret_val) {
3018 DEBUGOUT("Error Configuring Flow Control\n");
wdenk4e112c12003-06-03 23:54:09 +00003019 return ret_val;
3020 }
Roy Zang28f7a052009-07-31 13:34:02 +08003021 return E1000_SUCCESS;
3022}
3023
3024/******************************************************************************
3025* Detects which PHY is present and setup the speed and duplex
3026*
3027* hw - Struct containing variables accessed by shared code
3028******************************************************************************/
3029static int
3030e1000_setup_copper_link(struct eth_device *nic)
3031{
3032 struct e1000_hw *hw = nic->priv;
3033 int32_t ret_val;
3034 uint16_t i;
3035 uint16_t phy_data;
3036 uint16_t reg_data;
3037
3038 DEBUGFUNC();
3039
3040 switch (hw->mac_type) {
3041 case e1000_80003es2lan:
3042 case e1000_ich8lan:
3043 /* Set the mac to wait the maximum time between each
3044 * iteration and increase the max iterations when
3045 * polling the phy; this fixes erroneous timeouts at 10Mbps. */
3046 ret_val = e1000_write_kmrn_reg(hw,
3047 GG82563_REG(0x34, 4), 0xFFFF);
3048 if (ret_val)
3049 return ret_val;
3050 ret_val = e1000_read_kmrn_reg(hw,
3051 GG82563_REG(0x34, 9), &reg_data);
3052 if (ret_val)
3053 return ret_val;
3054 reg_data |= 0x3F;
3055 ret_val = e1000_write_kmrn_reg(hw,
3056 GG82563_REG(0x34, 9), reg_data);
3057 if (ret_val)
3058 return ret_val;
3059 default:
3060 break;
3061 }
3062
3063 /* Check if it is a valid PHY and set PHY mode if necessary. */
3064 ret_val = e1000_copper_link_preconfig(hw);
3065 if (ret_val)
3066 return ret_val;
3067 switch (hw->mac_type) {
3068 case e1000_80003es2lan:
3069 /* Kumeran registers are written-only */
3070 reg_data =
3071 E1000_KUMCTRLSTA_INB_CTRL_LINK_STATUS_TX_TIMEOUT_DEFAULT;
3072 reg_data |= E1000_KUMCTRLSTA_INB_CTRL_DIS_PADDING;
3073 ret_val = e1000_write_kmrn_reg(hw,
3074 E1000_KUMCTRLSTA_OFFSET_INB_CTRL, reg_data);
3075 if (ret_val)
3076 return ret_val;
3077 break;
3078 default:
3079 break;
3080 }
3081
3082 if (hw->phy_type == e1000_phy_igp ||
3083 hw->phy_type == e1000_phy_igp_3 ||
3084 hw->phy_type == e1000_phy_igp_2) {
3085 ret_val = e1000_copper_link_igp_setup(hw);
3086 if (ret_val)
3087 return ret_val;
Marek Vasut74a13c22014-08-08 07:41:39 -07003088 } else if (hw->phy_type == e1000_phy_m88 ||
3089 hw->phy_type == e1000_phy_igb) {
Roy Zang28f7a052009-07-31 13:34:02 +08003090 ret_val = e1000_copper_link_mgp_setup(hw);
3091 if (ret_val)
3092 return ret_val;
3093 } else if (hw->phy_type == e1000_phy_gg82563) {
3094 ret_val = e1000_copper_link_ggp_setup(hw);
3095 if (ret_val)
3096 return ret_val;
3097 }
3098
3099 /* always auto */
3100 /* Setup autoneg and flow control advertisement
3101 * and perform autonegotiation */
3102 ret_val = e1000_copper_link_autoneg(hw);
3103 if (ret_val)
3104 return ret_val;
wdenk4e112c12003-06-03 23:54:09 +00003105
3106 /* Check link status. Wait up to 100 microseconds for link to become
3107 * valid.
3108 */
3109 for (i = 0; i < 10; i++) {
Roy Zang28f7a052009-07-31 13:34:02 +08003110 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3111 if (ret_val)
3112 return ret_val;
3113 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3114 if (ret_val)
3115 return ret_val;
3116
wdenk4e112c12003-06-03 23:54:09 +00003117 if (phy_data & MII_SR_LINK_STATUS) {
Roy Zang28f7a052009-07-31 13:34:02 +08003118 /* Config the MAC and PHY after link is up */
3119 ret_val = e1000_copper_link_postconfig(hw);
3120 if (ret_val)
wdenk4e112c12003-06-03 23:54:09 +00003121 return ret_val;
Roy Zang28f7a052009-07-31 13:34:02 +08003122
wdenk4e112c12003-06-03 23:54:09 +00003123 DEBUGOUT("Valid link established!!!\n");
Roy Zang28f7a052009-07-31 13:34:02 +08003124 return E1000_SUCCESS;
wdenk4e112c12003-06-03 23:54:09 +00003125 }
3126 udelay(10);
3127 }
3128
3129 DEBUGOUT("Unable to establish link!!!\n");
Roy Zang28f7a052009-07-31 13:34:02 +08003130 return E1000_SUCCESS;
wdenk4e112c12003-06-03 23:54:09 +00003131}
3132
3133/******************************************************************************
3134* Configures PHY autoneg and flow control advertisement settings
3135*
3136* hw - Struct containing variables accessed by shared code
3137******************************************************************************/
Roy Zang28f7a052009-07-31 13:34:02 +08003138int32_t
wdenk4e112c12003-06-03 23:54:09 +00003139e1000_phy_setup_autoneg(struct e1000_hw *hw)
3140{
Roy Zang28f7a052009-07-31 13:34:02 +08003141 int32_t ret_val;
wdenk4e112c12003-06-03 23:54:09 +00003142 uint16_t mii_autoneg_adv_reg;
3143 uint16_t mii_1000t_ctrl_reg;
3144
3145 DEBUGFUNC();
3146
3147 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
Roy Zang28f7a052009-07-31 13:34:02 +08003148 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
3149 if (ret_val)
3150 return ret_val;
wdenk4e112c12003-06-03 23:54:09 +00003151
Roy Zang28f7a052009-07-31 13:34:02 +08003152 if (hw->phy_type != e1000_phy_ife) {
3153 /* Read the MII 1000Base-T Control Register (Address 9). */
3154 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL,
3155 &mii_1000t_ctrl_reg);
3156 if (ret_val)
3157 return ret_val;
3158 } else
3159 mii_1000t_ctrl_reg = 0;
wdenk4e112c12003-06-03 23:54:09 +00003160
3161 /* Need to parse both autoneg_advertised and fc and set up
3162 * the appropriate PHY registers. First we will parse for
3163 * autoneg_advertised software override. Since we can advertise
3164 * a plethora of combinations, we need to check each bit
3165 * individually.
3166 */
3167
3168 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
3169 * Advertisement Register (Address 4) and the 1000 mb speed bits in
Roy Zang28f7a052009-07-31 13:34:02 +08003170 * the 1000Base-T Control Register (Address 9).
wdenk4e112c12003-06-03 23:54:09 +00003171 */
3172 mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
3173 mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
3174
3175 DEBUGOUT("autoneg_advertised %x\n", hw->autoneg_advertised);
3176
3177 /* Do we want to advertise 10 Mb Half Duplex? */
3178 if (hw->autoneg_advertised & ADVERTISE_10_HALF) {
3179 DEBUGOUT("Advertise 10mb Half duplex\n");
3180 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
3181 }
3182
3183 /* Do we want to advertise 10 Mb Full Duplex? */
3184 if (hw->autoneg_advertised & ADVERTISE_10_FULL) {
3185 DEBUGOUT("Advertise 10mb Full duplex\n");
3186 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
3187 }
3188
3189 /* Do we want to advertise 100 Mb Half Duplex? */
3190 if (hw->autoneg_advertised & ADVERTISE_100_HALF) {
3191 DEBUGOUT("Advertise 100mb Half duplex\n");
3192 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
3193 }
3194
3195 /* Do we want to advertise 100 Mb Full Duplex? */
3196 if (hw->autoneg_advertised & ADVERTISE_100_FULL) {
3197 DEBUGOUT("Advertise 100mb Full duplex\n");
3198 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
3199 }
3200
3201 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
3202 if (hw->autoneg_advertised & ADVERTISE_1000_HALF) {
3203 DEBUGOUT
3204 ("Advertise 1000mb Half duplex requested, request denied!\n");
3205 }
3206
3207 /* Do we want to advertise 1000 Mb Full Duplex? */
3208 if (hw->autoneg_advertised & ADVERTISE_1000_FULL) {
3209 DEBUGOUT("Advertise 1000mb Full duplex\n");
3210 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
3211 }
3212
3213 /* Check for a software override of the flow control settings, and
3214 * setup the PHY advertisement registers accordingly. If
3215 * auto-negotiation is enabled, then software will have to set the
3216 * "PAUSE" bits to the correct value in the Auto-Negotiation
3217 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
3218 *
3219 * The possible values of the "fc" parameter are:
Wolfgang Denk35f734f2008-04-13 09:59:26 -07003220 * 0: Flow control is completely disabled
3221 * 1: Rx flow control is enabled (we can receive pause frames
3222 * but not send pause frames).
3223 * 2: Tx flow control is enabled (we can send pause frames
3224 * but we do not support receiving pause frames).
3225 * 3: Both Rx and TX flow control (symmetric) are enabled.
wdenk4e112c12003-06-03 23:54:09 +00003226 * other: No software override. The flow control configuration
Wolfgang Denk35f734f2008-04-13 09:59:26 -07003227 * in the EEPROM is used.
wdenk4e112c12003-06-03 23:54:09 +00003228 */
3229 switch (hw->fc) {
3230 case e1000_fc_none: /* 0 */
3231 /* Flow control (RX & TX) is completely disabled by a
3232 * software over-ride.
3233 */
3234 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
3235 break;
3236 case e1000_fc_rx_pause: /* 1 */
3237 /* RX Flow control is enabled, and TX Flow control is
3238 * disabled, by a software over-ride.
3239 */
3240 /* Since there really isn't a way to advertise that we are
3241 * capable of RX Pause ONLY, we will advertise that we
3242 * support both symmetric and asymmetric RX PAUSE. Later
3243 * (in e1000_config_fc_after_link_up) we will disable the
3244 *hw's ability to send PAUSE frames.
3245 */
3246 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
3247 break;
3248 case e1000_fc_tx_pause: /* 2 */
3249 /* TX Flow control is enabled, and RX Flow control is
3250 * disabled, by a software over-ride.
3251 */
3252 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
3253 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
3254 break;
3255 case e1000_fc_full: /* 3 */
3256 /* Flow control (both RX and TX) is enabled by a software
3257 * over-ride.
3258 */
3259 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
3260 break;
3261 default:
3262 DEBUGOUT("Flow control param set incorrectly\n");
3263 return -E1000_ERR_CONFIG;
3264 }
3265
Roy Zang28f7a052009-07-31 13:34:02 +08003266 ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
3267 if (ret_val)
3268 return ret_val;
wdenk4e112c12003-06-03 23:54:09 +00003269
3270 DEBUGOUT("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
3271
Roy Zang28f7a052009-07-31 13:34:02 +08003272 if (hw->phy_type != e1000_phy_ife) {
3273 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL,
3274 mii_1000t_ctrl_reg);
3275 if (ret_val)
3276 return ret_val;
wdenk4e112c12003-06-03 23:54:09 +00003277 }
Roy Zang28f7a052009-07-31 13:34:02 +08003278
3279 return E1000_SUCCESS;
wdenk4e112c12003-06-03 23:54:09 +00003280}
3281
3282/******************************************************************************
3283* Sets the collision distance in the Transmit Control register
3284*
3285* hw - Struct containing variables accessed by shared code
3286*
3287* Link should have been established previously. Reads the speed and duplex
3288* information from the Device Status register.
3289******************************************************************************/
3290static void
3291e1000_config_collision_dist(struct e1000_hw *hw)
3292{
Roy Zang28f7a052009-07-31 13:34:02 +08003293 uint32_t tctl, coll_dist;
3294
3295 DEBUGFUNC();
3296
3297 if (hw->mac_type < e1000_82543)
3298 coll_dist = E1000_COLLISION_DISTANCE_82542;
3299 else
3300 coll_dist = E1000_COLLISION_DISTANCE;
wdenk4e112c12003-06-03 23:54:09 +00003301
3302 tctl = E1000_READ_REG(hw, TCTL);
3303
3304 tctl &= ~E1000_TCTL_COLD;
Roy Zang28f7a052009-07-31 13:34:02 +08003305 tctl |= coll_dist << E1000_COLD_SHIFT;
wdenk4e112c12003-06-03 23:54:09 +00003306
3307 E1000_WRITE_REG(hw, TCTL, tctl);
3308 E1000_WRITE_FLUSH(hw);
3309}
3310
3311/******************************************************************************
3312* Sets MAC speed and duplex settings to reflect the those in the PHY
3313*
3314* hw - Struct containing variables accessed by shared code
3315* mii_reg - data to write to the MII control register
3316*
3317* The contents of the PHY register containing the needed information need to
3318* be passed in.
3319******************************************************************************/
3320static int
3321e1000_config_mac_to_phy(struct e1000_hw *hw)
3322{
3323 uint32_t ctrl;
3324 uint16_t phy_data;
3325
3326 DEBUGFUNC();
3327
3328 /* Read the Device Control Register and set the bits to Force Speed
3329 * and Duplex.
3330 */
3331 ctrl = E1000_READ_REG(hw, CTRL);
3332 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
Marek Vasut74a13c22014-08-08 07:41:39 -07003333 ctrl &= ~(E1000_CTRL_ILOS);
3334 ctrl |= (E1000_CTRL_SPD_SEL);
wdenk4e112c12003-06-03 23:54:09 +00003335
3336 /* Set up duplex in the Device Control and Transmit Control
3337 * registers depending on negotiated values.
3338 */
3339 if (e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data) < 0) {
3340 DEBUGOUT("PHY Read Error\n");
3341 return -E1000_ERR_PHY;
3342 }
3343 if (phy_data & M88E1000_PSSR_DPLX)
3344 ctrl |= E1000_CTRL_FD;
3345 else
3346 ctrl &= ~E1000_CTRL_FD;
3347
3348 e1000_config_collision_dist(hw);
3349
3350 /* Set up speed in the Device Control register depending on
3351 * negotiated values.
3352 */
3353 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
3354 ctrl |= E1000_CTRL_SPD_1000;
3355 else if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
3356 ctrl |= E1000_CTRL_SPD_100;
3357 /* Write the configured values back to the Device Control Reg. */
3358 E1000_WRITE_REG(hw, CTRL, ctrl);
3359 return 0;
3360}
3361
3362/******************************************************************************
3363 * Forces the MAC's flow control settings.
wdenk57b2d802003-06-27 21:31:46 +00003364 *
wdenk4e112c12003-06-03 23:54:09 +00003365 * hw - Struct containing variables accessed by shared code
3366 *
3367 * Sets the TFCE and RFCE bits in the device control register to reflect
3368 * the adapter settings. TFCE and RFCE need to be explicitly set by
3369 * software when a Copper PHY is used because autonegotiation is managed
3370 * by the PHY rather than the MAC. Software must also configure these
3371 * bits when link is forced on a fiber connection.
3372 *****************************************************************************/
3373static int
3374e1000_force_mac_fc(struct e1000_hw *hw)
3375{
3376 uint32_t ctrl;
3377
3378 DEBUGFUNC();
3379
3380 /* Get the current configuration of the Device Control Register */
3381 ctrl = E1000_READ_REG(hw, CTRL);
3382
3383 /* Because we didn't get link via the internal auto-negotiation
3384 * mechanism (we either forced link or we got link via PHY
3385 * auto-neg), we have to manually enable/disable transmit an
3386 * receive flow control.
3387 *
3388 * The "Case" statement below enables/disable flow control
3389 * according to the "hw->fc" parameter.
3390 *
3391 * The possible values of the "fc" parameter are:
Wolfgang Denk35f734f2008-04-13 09:59:26 -07003392 * 0: Flow control is completely disabled
3393 * 1: Rx flow control is enabled (we can receive pause
3394 * frames but not send pause frames).
3395 * 2: Tx flow control is enabled (we can send pause frames
3396 * frames but we do not receive pause frames).
3397 * 3: Both Rx and TX flow control (symmetric) is enabled.
wdenk4e112c12003-06-03 23:54:09 +00003398 * other: No other values should be possible at this point.
3399 */
3400
3401 switch (hw->fc) {
3402 case e1000_fc_none:
3403 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
3404 break;
3405 case e1000_fc_rx_pause:
3406 ctrl &= (~E1000_CTRL_TFCE);
3407 ctrl |= E1000_CTRL_RFCE;
3408 break;
3409 case e1000_fc_tx_pause:
3410 ctrl &= (~E1000_CTRL_RFCE);
3411 ctrl |= E1000_CTRL_TFCE;
3412 break;
3413 case e1000_fc_full:
3414 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
3415 break;
3416 default:
3417 DEBUGOUT("Flow control param set incorrectly\n");
3418 return -E1000_ERR_CONFIG;
3419 }
3420
3421 /* Disable TX Flow Control for 82542 (rev 2.0) */
3422 if (hw->mac_type == e1000_82542_rev2_0)
3423 ctrl &= (~E1000_CTRL_TFCE);
3424
3425 E1000_WRITE_REG(hw, CTRL, ctrl);
3426 return 0;
3427}
3428
3429/******************************************************************************
3430 * Configures flow control settings after link is established
wdenk57b2d802003-06-27 21:31:46 +00003431 *
wdenk4e112c12003-06-03 23:54:09 +00003432 * hw - Struct containing variables accessed by shared code
3433 *
3434 * Should be called immediately after a valid link has been established.
3435 * Forces MAC flow control settings if link was forced. When in MII/GMII mode
3436 * and autonegotiation is enabled, the MAC flow control settings will be set
3437 * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
3438 * and RFCE bits will be automaticaly set to the negotiated flow control mode.
3439 *****************************************************************************/
Roy Zang28f7a052009-07-31 13:34:02 +08003440static int32_t
wdenk4e112c12003-06-03 23:54:09 +00003441e1000_config_fc_after_link_up(struct e1000_hw *hw)
3442{
3443 int32_t ret_val;
3444 uint16_t mii_status_reg;
3445 uint16_t mii_nway_adv_reg;
3446 uint16_t mii_nway_lp_ability_reg;
3447 uint16_t speed;
3448 uint16_t duplex;
3449
3450 DEBUGFUNC();
3451
3452 /* Check for the case where we have fiber media and auto-neg failed
3453 * so we had to force link. In this case, we need to force the
3454 * configuration of the MAC to match the "fc" parameter.
3455 */
Roy Zang28f7a052009-07-31 13:34:02 +08003456 if (((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed))
3457 || ((hw->media_type == e1000_media_type_internal_serdes)
3458 && (hw->autoneg_failed))
3459 || ((hw->media_type == e1000_media_type_copper)
3460 && (!hw->autoneg))) {
wdenk4e112c12003-06-03 23:54:09 +00003461 ret_val = e1000_force_mac_fc(hw);
3462 if (ret_val < 0) {
3463 DEBUGOUT("Error forcing flow control settings\n");
3464 return ret_val;
3465 }
3466 }
3467
3468 /* Check for the case where we have copper media and auto-neg is
3469 * enabled. In this case, we need to check and see if Auto-Neg
3470 * has completed, and if so, how the PHY and link partner has
3471 * flow control configured.
3472 */
3473 if (hw->media_type == e1000_media_type_copper) {
3474 /* Read the MII Status Register and check to see if AutoNeg
3475 * has completed. We read this twice because this reg has
3476 * some "sticky" (latched) bits.
3477 */
3478 if (e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg) < 0) {
3479 DEBUGOUT("PHY Read Error \n");
3480 return -E1000_ERR_PHY;
3481 }
3482 if (e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg) < 0) {
3483 DEBUGOUT("PHY Read Error \n");
3484 return -E1000_ERR_PHY;
3485 }
3486
3487 if (mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
3488 /* The AutoNeg process has completed, so we now need to
3489 * read both the Auto Negotiation Advertisement Register
3490 * (Address 4) and the Auto_Negotiation Base Page Ability
3491 * Register (Address 5) to determine how flow control was
3492 * negotiated.
3493 */
3494 if (e1000_read_phy_reg
3495 (hw, PHY_AUTONEG_ADV, &mii_nway_adv_reg) < 0) {
3496 DEBUGOUT("PHY Read Error\n");
3497 return -E1000_ERR_PHY;
3498 }
3499 if (e1000_read_phy_reg
3500 (hw, PHY_LP_ABILITY,
3501 &mii_nway_lp_ability_reg) < 0) {
3502 DEBUGOUT("PHY Read Error\n");
3503 return -E1000_ERR_PHY;
3504 }
3505
3506 /* Two bits in the Auto Negotiation Advertisement Register
3507 * (Address 4) and two bits in the Auto Negotiation Base
3508 * Page Ability Register (Address 5) determine flow control
3509 * for both the PHY and the link partner. The following
3510 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
3511 * 1999, describes these PAUSE resolution bits and how flow
3512 * control is determined based upon these settings.
3513 * NOTE: DC = Don't Care
3514 *
3515 * LOCAL DEVICE | LINK PARTNER
3516 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
3517 *-------|---------|-------|---------|--------------------
Wolfgang Denk35f734f2008-04-13 09:59:26 -07003518 * 0 | 0 | DC | DC | e1000_fc_none
3519 * 0 | 1 | 0 | DC | e1000_fc_none
3520 * 0 | 1 | 1 | 0 | e1000_fc_none
3521 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
3522 * 1 | 0 | 0 | DC | e1000_fc_none
3523 * 1 | DC | 1 | DC | e1000_fc_full
3524 * 1 | 1 | 0 | 0 | e1000_fc_none
3525 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
wdenk4e112c12003-06-03 23:54:09 +00003526 *
3527 */
3528 /* Are both PAUSE bits set to 1? If so, this implies
3529 * Symmetric Flow Control is enabled at both ends. The
3530 * ASM_DIR bits are irrelevant per the spec.
3531 *
3532 * For Symmetric Flow Control:
3533 *
3534 * LOCAL DEVICE | LINK PARTNER
3535 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
3536 *-------|---------|-------|---------|--------------------
Wolfgang Denk35f734f2008-04-13 09:59:26 -07003537 * 1 | DC | 1 | DC | e1000_fc_full
wdenk4e112c12003-06-03 23:54:09 +00003538 *
3539 */
3540 if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
3541 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
3542 /* Now we need to check if the user selected RX ONLY
3543 * of pause frames. In this case, we had to advertise
3544 * FULL flow control because we could not advertise RX
3545 * ONLY. Hence, we must now check to see if we need to
3546 * turn OFF the TRANSMISSION of PAUSE frames.
3547 */
3548 if (hw->original_fc == e1000_fc_full) {
3549 hw->fc = e1000_fc_full;
3550 DEBUGOUT("Flow Control = FULL.\r\n");
3551 } else {
3552 hw->fc = e1000_fc_rx_pause;
3553 DEBUGOUT
3554 ("Flow Control = RX PAUSE frames only.\r\n");
3555 }
3556 }
3557 /* For receiving PAUSE frames ONLY.
3558 *
3559 * LOCAL DEVICE | LINK PARTNER
3560 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
3561 *-------|---------|-------|---------|--------------------
Wolfgang Denk35f734f2008-04-13 09:59:26 -07003562 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
wdenk4e112c12003-06-03 23:54:09 +00003563 *
3564 */
3565 else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
3566 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
3567 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
3568 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR))
3569 {
3570 hw->fc = e1000_fc_tx_pause;
3571 DEBUGOUT
3572 ("Flow Control = TX PAUSE frames only.\r\n");
3573 }
3574 /* For transmitting PAUSE frames ONLY.
3575 *
3576 * LOCAL DEVICE | LINK PARTNER
3577 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
3578 *-------|---------|-------|---------|--------------------
Wolfgang Denk35f734f2008-04-13 09:59:26 -07003579 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
wdenk4e112c12003-06-03 23:54:09 +00003580 *
3581 */
3582 else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
3583 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
3584 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
3585 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR))
3586 {
3587 hw->fc = e1000_fc_rx_pause;
3588 DEBUGOUT
3589 ("Flow Control = RX PAUSE frames only.\r\n");
3590 }
3591 /* Per the IEEE spec, at this point flow control should be
3592 * disabled. However, we want to consider that we could
3593 * be connected to a legacy switch that doesn't advertise
3594 * desired flow control, but can be forced on the link
3595 * partner. So if we advertised no flow control, that is
3596 * what we will resolve to. If we advertised some kind of
3597 * receive capability (Rx Pause Only or Full Flow Control)
3598 * and the link partner advertised none, we will configure
3599 * ourselves to enable Rx Flow Control only. We can do
3600 * this safely for two reasons: If the link partner really
3601 * didn't want flow control enabled, and we enable Rx, no
3602 * harm done since we won't be receiving any PAUSE frames
3603 * anyway. If the intent on the link partner was to have
3604 * flow control enabled, then by us enabling RX only, we
3605 * can at least receive pause frames and process them.
3606 * This is a good idea because in most cases, since we are
3607 * predominantly a server NIC, more times than not we will
3608 * be asked to delay transmission of packets than asking
3609 * our link partner to pause transmission of frames.
3610 */
3611 else if (hw->original_fc == e1000_fc_none ||
3612 hw->original_fc == e1000_fc_tx_pause) {
3613 hw->fc = e1000_fc_none;
3614 DEBUGOUT("Flow Control = NONE.\r\n");
3615 } else {
3616 hw->fc = e1000_fc_rx_pause;
3617 DEBUGOUT
3618 ("Flow Control = RX PAUSE frames only.\r\n");
3619 }
3620
Wolfgang Denk35f734f2008-04-13 09:59:26 -07003621 /* Now we need to do one last check... If we auto-
wdenk4e112c12003-06-03 23:54:09 +00003622 * negotiated to HALF DUPLEX, flow control should not be
3623 * enabled per IEEE 802.3 spec.
3624 */
3625 e1000_get_speed_and_duplex(hw, &speed, &duplex);
3626
3627 if (duplex == HALF_DUPLEX)
3628 hw->fc = e1000_fc_none;
3629
3630 /* Now we call a subroutine to actually force the MAC
3631 * controller to use the correct flow control settings.
3632 */
3633 ret_val = e1000_force_mac_fc(hw);
3634 if (ret_val < 0) {
3635 DEBUGOUT
3636 ("Error forcing flow control settings\n");
3637 return ret_val;
3638 }
3639 } else {
3640 DEBUGOUT
3641 ("Copper PHY and Auto Neg has not completed.\r\n");
3642 }
3643 }
Roy Zang28f7a052009-07-31 13:34:02 +08003644 return E1000_SUCCESS;
wdenk4e112c12003-06-03 23:54:09 +00003645}
3646
3647/******************************************************************************
3648 * Checks to see if the link status of the hardware has changed.
3649 *
3650 * hw - Struct containing variables accessed by shared code
3651 *
3652 * Called by any function that needs to check the link status of the adapter.
3653 *****************************************************************************/
3654static int
3655e1000_check_for_link(struct eth_device *nic)
3656{
3657 struct e1000_hw *hw = nic->priv;
3658 uint32_t rxcw;
3659 uint32_t ctrl;
3660 uint32_t status;
3661 uint32_t rctl;
3662 uint32_t signal;
3663 int32_t ret_val;
3664 uint16_t phy_data;
3665 uint16_t lp_capability;
3666
3667 DEBUGFUNC();
3668
wdenk57b2d802003-06-27 21:31:46 +00003669 /* On adapters with a MAC newer that 82544, SW Defineable pin 1 will be
3670 * set when the optics detect a signal. On older adapters, it will be
wdenk4e112c12003-06-03 23:54:09 +00003671 * cleared when there is a signal
3672 */
3673 ctrl = E1000_READ_REG(hw, CTRL);
3674 if ((hw->mac_type > e1000_82544) && !(ctrl & E1000_CTRL_ILOS))
3675 signal = E1000_CTRL_SWDPIN1;
3676 else
3677 signal = 0;
3678
3679 status = E1000_READ_REG(hw, STATUS);
3680 rxcw = E1000_READ_REG(hw, RXCW);
3681 DEBUGOUT("ctrl: %#08x status %#08x rxcw %#08x\n", ctrl, status, rxcw);
3682
3683 /* If we have a copper PHY then we only want to go out to the PHY
3684 * registers to see if Auto-Neg has completed and/or if our link
Wolfgang Denk35f734f2008-04-13 09:59:26 -07003685 * status has changed. The get_link_status flag will be set if we
wdenk4e112c12003-06-03 23:54:09 +00003686 * receive a Link Status Change interrupt or we have Rx Sequence
3687 * Errors.
3688 */
3689 if ((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
3690 /* First we want to see if the MII Status Register reports
3691 * link. If so, then we want to get the current speed/duplex
3692 * of the PHY.
3693 * Read the register twice since the link bit is sticky.
3694 */
3695 if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
3696 DEBUGOUT("PHY Read Error\n");
3697 return -E1000_ERR_PHY;
3698 }
3699 if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
3700 DEBUGOUT("PHY Read Error\n");
3701 return -E1000_ERR_PHY;
3702 }
3703
3704 if (phy_data & MII_SR_LINK_STATUS) {
York Sun4a598092013-04-01 11:29:11 -07003705 hw->get_link_status = false;
wdenk4e112c12003-06-03 23:54:09 +00003706 } else {
3707 /* No link detected */
3708 return -E1000_ERR_NOLINK;
3709 }
3710
3711 /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
3712 * have Si on board that is 82544 or newer, Auto
3713 * Speed Detection takes care of MAC speed/duplex
3714 * configuration. So we only need to configure Collision
3715 * Distance in the MAC. Otherwise, we need to force
3716 * speed/duplex on the MAC to the current PHY speed/duplex
3717 * settings.
3718 */
3719 if (hw->mac_type >= e1000_82544)
3720 e1000_config_collision_dist(hw);
3721 else {
3722 ret_val = e1000_config_mac_to_phy(hw);
3723 if (ret_val < 0) {
3724 DEBUGOUT
3725 ("Error configuring MAC to PHY settings\n");
3726 return ret_val;
3727 }
3728 }
3729
wdenk57b2d802003-06-27 21:31:46 +00003730 /* Configure Flow Control now that Auto-Neg has completed. First, we
wdenk4e112c12003-06-03 23:54:09 +00003731 * need to restore the desired flow control settings because we may
3732 * have had to re-autoneg with a different link partner.
3733 */
3734 ret_val = e1000_config_fc_after_link_up(hw);
3735 if (ret_val < 0) {
3736 DEBUGOUT("Error configuring flow control\n");
3737 return ret_val;
3738 }
3739
3740 /* At this point we know that we are on copper and we have
3741 * auto-negotiated link. These are conditions for checking the link
Wolfgang Denk35f734f2008-04-13 09:59:26 -07003742 * parter capability register. We use the link partner capability to
wdenk4e112c12003-06-03 23:54:09 +00003743 * determine if TBI Compatibility needs to be turned on or off. If
3744 * the link partner advertises any speed in addition to Gigabit, then
3745 * we assume that they are GMII-based, and TBI compatibility is not
3746 * needed. If no other speeds are advertised, we assume the link
3747 * partner is TBI-based, and we turn on TBI Compatibility.
3748 */
3749 if (hw->tbi_compatibility_en) {
3750 if (e1000_read_phy_reg
3751 (hw, PHY_LP_ABILITY, &lp_capability) < 0) {
3752 DEBUGOUT("PHY Read Error\n");
3753 return -E1000_ERR_PHY;
3754 }
3755 if (lp_capability & (NWAY_LPAR_10T_HD_CAPS |
3756 NWAY_LPAR_10T_FD_CAPS |
3757 NWAY_LPAR_100TX_HD_CAPS |
3758 NWAY_LPAR_100TX_FD_CAPS |
3759 NWAY_LPAR_100T4_CAPS)) {
wdenk57b2d802003-06-27 21:31:46 +00003760 /* If our link partner advertises anything in addition to
wdenk4e112c12003-06-03 23:54:09 +00003761 * gigabit, we do not need to enable TBI compatibility.
3762 */
3763 if (hw->tbi_compatibility_on) {
3764 /* If we previously were in the mode, turn it off. */
3765 rctl = E1000_READ_REG(hw, RCTL);
3766 rctl &= ~E1000_RCTL_SBP;
3767 E1000_WRITE_REG(hw, RCTL, rctl);
York Sun4a598092013-04-01 11:29:11 -07003768 hw->tbi_compatibility_on = false;
wdenk4e112c12003-06-03 23:54:09 +00003769 }
3770 } else {
3771 /* If TBI compatibility is was previously off, turn it on. For
3772 * compatibility with a TBI link partner, we will store bad
3773 * packets. Some frames have an additional byte on the end and
3774 * will look like CRC errors to to the hardware.
3775 */
3776 if (!hw->tbi_compatibility_on) {
York Sun4a598092013-04-01 11:29:11 -07003777 hw->tbi_compatibility_on = true;
wdenk4e112c12003-06-03 23:54:09 +00003778 rctl = E1000_READ_REG(hw, RCTL);
3779 rctl |= E1000_RCTL_SBP;
3780 E1000_WRITE_REG(hw, RCTL, rctl);
3781 }
3782 }
3783 }
3784 }
3785 /* If we don't have link (auto-negotiation failed or link partner cannot
3786 * auto-negotiate), the cable is plugged in (we have signal), and our
3787 * link partner is not trying to auto-negotiate with us (we are receiving
3788 * idles or data), we need to force link up. We also need to give
3789 * auto-negotiation time to complete, in case the cable was just plugged
3790 * in. The autoneg_failed flag does this.
3791 */
3792 else if ((hw->media_type == e1000_media_type_fiber) &&
3793 (!(status & E1000_STATUS_LU)) &&
3794 ((ctrl & E1000_CTRL_SWDPIN1) == signal) &&
3795 (!(rxcw & E1000_RXCW_C))) {
3796 if (hw->autoneg_failed == 0) {
3797 hw->autoneg_failed = 1;
3798 return 0;
3799 }
3800 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\r\n");
3801
3802 /* Disable auto-negotiation in the TXCW register */
3803 E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE));
3804
3805 /* Force link-up and also force full-duplex. */
3806 ctrl = E1000_READ_REG(hw, CTRL);
3807 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
3808 E1000_WRITE_REG(hw, CTRL, ctrl);
3809
3810 /* Configure Flow Control after forcing link up. */
3811 ret_val = e1000_config_fc_after_link_up(hw);
3812 if (ret_val < 0) {
3813 DEBUGOUT("Error configuring flow control\n");
3814 return ret_val;
3815 }
3816 }
3817 /* If we are forcing link and we are receiving /C/ ordered sets, re-enable
3818 * auto-negotiation in the TXCW register and disable forced link in the
3819 * Device Control register in an attempt to auto-negotiate with our link
3820 * partner.
3821 */
3822 else if ((hw->media_type == e1000_media_type_fiber) &&
3823 (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
3824 DEBUGOUT
3825 ("RXing /C/, enable AutoNeg and stop forcing link.\r\n");
3826 E1000_WRITE_REG(hw, TXCW, hw->txcw);
3827 E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU));
3828 }
3829 return 0;
3830}
3831
3832/******************************************************************************
Roy Zang28f7a052009-07-31 13:34:02 +08003833* Configure the MAC-to-PHY interface for 10/100Mbps
3834*
3835* hw - Struct containing variables accessed by shared code
3836******************************************************************************/
3837static int32_t
3838e1000_configure_kmrn_for_10_100(struct e1000_hw *hw, uint16_t duplex)
3839{
3840 int32_t ret_val = E1000_SUCCESS;
3841 uint32_t tipg;
3842 uint16_t reg_data;
3843
3844 DEBUGFUNC();
3845
3846 reg_data = E1000_KUMCTRLSTA_HD_CTRL_10_100_DEFAULT;
3847 ret_val = e1000_write_kmrn_reg(hw,
3848 E1000_KUMCTRLSTA_OFFSET_HD_CTRL, reg_data);
3849 if (ret_val)
3850 return ret_val;
3851
3852 /* Configure Transmit Inter-Packet Gap */
3853 tipg = E1000_READ_REG(hw, TIPG);
3854 tipg &= ~E1000_TIPG_IPGT_MASK;
3855 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_10_100;
3856 E1000_WRITE_REG(hw, TIPG, tipg);
3857
3858 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, &reg_data);
3859
3860 if (ret_val)
3861 return ret_val;
3862
3863 if (duplex == HALF_DUPLEX)
3864 reg_data |= GG82563_KMCR_PASS_FALSE_CARRIER;
3865 else
3866 reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
3867
3868 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
3869
3870 return ret_val;
3871}
3872
3873static int32_t
3874e1000_configure_kmrn_for_1000(struct e1000_hw *hw)
3875{
3876 int32_t ret_val = E1000_SUCCESS;
3877 uint16_t reg_data;
3878 uint32_t tipg;
3879
3880 DEBUGFUNC();
3881
3882 reg_data = E1000_KUMCTRLSTA_HD_CTRL_1000_DEFAULT;
3883 ret_val = e1000_write_kmrn_reg(hw,
3884 E1000_KUMCTRLSTA_OFFSET_HD_CTRL, reg_data);
3885 if (ret_val)
3886 return ret_val;
3887
3888 /* Configure Transmit Inter-Packet Gap */
3889 tipg = E1000_READ_REG(hw, TIPG);
3890 tipg &= ~E1000_TIPG_IPGT_MASK;
3891 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
3892 E1000_WRITE_REG(hw, TIPG, tipg);
3893
3894 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, &reg_data);
3895
3896 if (ret_val)
3897 return ret_val;
3898
3899 reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
3900 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
3901
3902 return ret_val;
3903}
3904
3905/******************************************************************************
wdenk4e112c12003-06-03 23:54:09 +00003906 * Detects the current speed and duplex settings of the hardware.
3907 *
3908 * hw - Struct containing variables accessed by shared code
3909 * speed - Speed of the connection
3910 * duplex - Duplex setting of the connection
3911 *****************************************************************************/
Roy Zang28f7a052009-07-31 13:34:02 +08003912static int
3913e1000_get_speed_and_duplex(struct e1000_hw *hw, uint16_t *speed,
3914 uint16_t *duplex)
wdenk4e112c12003-06-03 23:54:09 +00003915{
3916 uint32_t status;
Roy Zang28f7a052009-07-31 13:34:02 +08003917 int32_t ret_val;
3918 uint16_t phy_data;
wdenk4e112c12003-06-03 23:54:09 +00003919
3920 DEBUGFUNC();
3921
3922 if (hw->mac_type >= e1000_82543) {
3923 status = E1000_READ_REG(hw, STATUS);
3924 if (status & E1000_STATUS_SPEED_1000) {
3925 *speed = SPEED_1000;
3926 DEBUGOUT("1000 Mbs, ");
3927 } else if (status & E1000_STATUS_SPEED_100) {
3928 *speed = SPEED_100;
3929 DEBUGOUT("100 Mbs, ");
3930 } else {
3931 *speed = SPEED_10;
3932 DEBUGOUT("10 Mbs, ");
3933 }
3934
3935 if (status & E1000_STATUS_FD) {
3936 *duplex = FULL_DUPLEX;
3937 DEBUGOUT("Full Duplex\r\n");
3938 } else {
3939 *duplex = HALF_DUPLEX;
3940 DEBUGOUT(" Half Duplex\r\n");
3941 }
3942 } else {
3943 DEBUGOUT("1000 Mbs, Full Duplex\r\n");
3944 *speed = SPEED_1000;
3945 *duplex = FULL_DUPLEX;
3946 }
Roy Zang28f7a052009-07-31 13:34:02 +08003947
3948 /* IGP01 PHY may advertise full duplex operation after speed downgrade
3949 * even if it is operating at half duplex. Here we set the duplex
3950 * settings to match the duplex in the link partner's capabilities.
3951 */
3952 if (hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
3953 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
3954 if (ret_val)
3955 return ret_val;
3956
3957 if (!(phy_data & NWAY_ER_LP_NWAY_CAPS))
3958 *duplex = HALF_DUPLEX;
3959 else {
3960 ret_val = e1000_read_phy_reg(hw,
3961 PHY_LP_ABILITY, &phy_data);
3962 if (ret_val)
3963 return ret_val;
3964 if ((*speed == SPEED_100 &&
3965 !(phy_data & NWAY_LPAR_100TX_FD_CAPS))
3966 || (*speed == SPEED_10
3967 && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
3968 *duplex = HALF_DUPLEX;
3969 }
3970 }
3971
3972 if ((hw->mac_type == e1000_80003es2lan) &&
3973 (hw->media_type == e1000_media_type_copper)) {
3974 if (*speed == SPEED_1000)
3975 ret_val = e1000_configure_kmrn_for_1000(hw);
3976 else
3977 ret_val = e1000_configure_kmrn_for_10_100(hw, *duplex);
3978 if (ret_val)
3979 return ret_val;
3980 }
3981 return E1000_SUCCESS;
wdenk4e112c12003-06-03 23:54:09 +00003982}
3983
3984/******************************************************************************
3985* Blocks until autoneg completes or times out (~4.5 seconds)
3986*
3987* hw - Struct containing variables accessed by shared code
3988******************************************************************************/
3989static int
3990e1000_wait_autoneg(struct e1000_hw *hw)
3991{
3992 uint16_t i;
3993 uint16_t phy_data;
3994
3995 DEBUGFUNC();
3996 DEBUGOUT("Waiting for Auto-Neg to complete.\n");
3997
3998 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
3999 for (i = PHY_AUTO_NEG_TIME; i > 0; i--) {
4000 /* Read the MII Status Register and wait for Auto-Neg
4001 * Complete bit to be set.
4002 */
4003 if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
4004 DEBUGOUT("PHY Read Error\n");
4005 return -E1000_ERR_PHY;
4006 }
4007 if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
4008 DEBUGOUT("PHY Read Error\n");
4009 return -E1000_ERR_PHY;
4010 }
4011 if (phy_data & MII_SR_AUTONEG_COMPLETE) {
4012 DEBUGOUT("Auto-Neg complete.\n");
4013 return 0;
4014 }
4015 mdelay(100);
4016 }
4017 DEBUGOUT("Auto-Neg timedout.\n");
4018 return -E1000_ERR_TIMEOUT;
4019}
4020
4021/******************************************************************************
4022* Raises the Management Data Clock
4023*
4024* hw - Struct containing variables accessed by shared code
4025* ctrl - Device control register's current value
4026******************************************************************************/
4027static void
4028e1000_raise_mdi_clk(struct e1000_hw *hw, uint32_t * ctrl)
4029{
4030 /* Raise the clock input to the Management Data Clock (by setting the MDC
4031 * bit), and then delay 2 microseconds.
4032 */
4033 E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC));
4034 E1000_WRITE_FLUSH(hw);
4035 udelay(2);
4036}
4037
4038/******************************************************************************
4039* Lowers the Management Data Clock
4040*
4041* hw - Struct containing variables accessed by shared code
4042* ctrl - Device control register's current value
4043******************************************************************************/
4044static void
4045e1000_lower_mdi_clk(struct e1000_hw *hw, uint32_t * ctrl)
4046{
4047 /* Lower the clock input to the Management Data Clock (by clearing the MDC
4048 * bit), and then delay 2 microseconds.
4049 */
4050 E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC));
4051 E1000_WRITE_FLUSH(hw);
4052 udelay(2);
4053}
4054
4055/******************************************************************************
4056* Shifts data bits out to the PHY
4057*
4058* hw - Struct containing variables accessed by shared code
4059* data - Data to send out to the PHY
4060* count - Number of bits to shift out
4061*
4062* Bits are shifted out in MSB to LSB order.
4063******************************************************************************/
4064static void
4065e1000_shift_out_mdi_bits(struct e1000_hw *hw, uint32_t data, uint16_t count)
4066{
4067 uint32_t ctrl;
4068 uint32_t mask;
4069
4070 /* We need to shift "count" number of bits out to the PHY. So, the value
wdenk57b2d802003-06-27 21:31:46 +00004071 * in the "data" parameter will be shifted out to the PHY one bit at a
wdenk4e112c12003-06-03 23:54:09 +00004072 * time. In order to do this, "data" must be broken down into bits.
4073 */
4074 mask = 0x01;
4075 mask <<= (count - 1);
4076
4077 ctrl = E1000_READ_REG(hw, CTRL);
4078
4079 /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
4080 ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
4081
4082 while (mask) {
4083 /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
4084 * then raising and lowering the Management Data Clock. A "0" is
4085 * shifted out to the PHY by setting the MDIO bit to "0" and then
4086 * raising and lowering the clock.
4087 */
4088 if (data & mask)
4089 ctrl |= E1000_CTRL_MDIO;
4090 else
4091 ctrl &= ~E1000_CTRL_MDIO;
4092
4093 E1000_WRITE_REG(hw, CTRL, ctrl);
4094 E1000_WRITE_FLUSH(hw);
4095
4096 udelay(2);
4097
4098 e1000_raise_mdi_clk(hw, &ctrl);
4099 e1000_lower_mdi_clk(hw, &ctrl);
4100
4101 mask = mask >> 1;
4102 }
4103}
4104
4105/******************************************************************************
4106* Shifts data bits in from the PHY
4107*
4108* hw - Struct containing variables accessed by shared code
4109*
wdenk57b2d802003-06-27 21:31:46 +00004110* Bits are shifted in in MSB to LSB order.
wdenk4e112c12003-06-03 23:54:09 +00004111******************************************************************************/
4112static uint16_t
4113e1000_shift_in_mdi_bits(struct e1000_hw *hw)
4114{
4115 uint32_t ctrl;
4116 uint16_t data = 0;
4117 uint8_t i;
4118
4119 /* In order to read a register from the PHY, we need to shift in a total
4120 * of 18 bits from the PHY. The first two bit (turnaround) times are used
4121 * to avoid contention on the MDIO pin when a read operation is performed.
4122 * These two bits are ignored by us and thrown away. Bits are "shifted in"
4123 * by raising the input to the Management Data Clock (setting the MDC bit),
4124 * and then reading the value of the MDIO bit.
4125 */
4126 ctrl = E1000_READ_REG(hw, CTRL);
4127
4128 /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
4129 ctrl &= ~E1000_CTRL_MDIO_DIR;
4130 ctrl &= ~E1000_CTRL_MDIO;
4131
4132 E1000_WRITE_REG(hw, CTRL, ctrl);
4133 E1000_WRITE_FLUSH(hw);
4134
4135 /* Raise and Lower the clock before reading in the data. This accounts for
4136 * the turnaround bits. The first clock occurred when we clocked out the
4137 * last bit of the Register Address.
4138 */
4139 e1000_raise_mdi_clk(hw, &ctrl);
4140 e1000_lower_mdi_clk(hw, &ctrl);
4141
4142 for (data = 0, i = 0; i < 16; i++) {
4143 data = data << 1;
4144 e1000_raise_mdi_clk(hw, &ctrl);
4145 ctrl = E1000_READ_REG(hw, CTRL);
4146 /* Check to see if we shifted in a "1". */
4147 if (ctrl & E1000_CTRL_MDIO)
4148 data |= 1;
4149 e1000_lower_mdi_clk(hw, &ctrl);
4150 }
4151
4152 e1000_raise_mdi_clk(hw, &ctrl);
4153 e1000_lower_mdi_clk(hw, &ctrl);
4154
4155 return data;
4156}
4157
4158/*****************************************************************************
4159* Reads the value from a PHY register
4160*
4161* hw - Struct containing variables accessed by shared code
4162* reg_addr - address of the PHY register to read
4163******************************************************************************/
4164static int
4165e1000_read_phy_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t * phy_data)
4166{
4167 uint32_t i;
4168 uint32_t mdic = 0;
4169 const uint32_t phy_addr = 1;
4170
4171 if (reg_addr > MAX_PHY_REG_ADDRESS) {
4172 DEBUGOUT("PHY Address %d is out of range\n", reg_addr);
4173 return -E1000_ERR_PARAM;
4174 }
4175
4176 if (hw->mac_type > e1000_82543) {
4177 /* Set up Op-code, Phy Address, and register address in the MDI
4178 * Control register. The MAC will take care of interfacing with the
4179 * PHY to retrieve the desired data.
4180 */
4181 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
4182 (phy_addr << E1000_MDIC_PHY_SHIFT) |
4183 (E1000_MDIC_OP_READ));
4184
4185 E1000_WRITE_REG(hw, MDIC, mdic);
4186
4187 /* Poll the ready bit to see if the MDI read completed */
4188 for (i = 0; i < 64; i++) {
4189 udelay(10);
4190 mdic = E1000_READ_REG(hw, MDIC);
4191 if (mdic & E1000_MDIC_READY)
4192 break;
4193 }
4194 if (!(mdic & E1000_MDIC_READY)) {
4195 DEBUGOUT("MDI Read did not complete\n");
4196 return -E1000_ERR_PHY;
4197 }
4198 if (mdic & E1000_MDIC_ERROR) {
4199 DEBUGOUT("MDI Error\n");
4200 return -E1000_ERR_PHY;
4201 }
4202 *phy_data = (uint16_t) mdic;
4203 } else {
4204 /* We must first send a preamble through the MDIO pin to signal the
4205 * beginning of an MII instruction. This is done by sending 32
4206 * consecutive "1" bits.
4207 */
4208 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
4209
4210 /* Now combine the next few fields that are required for a read
4211 * operation. We use this method instead of calling the
4212 * e1000_shift_out_mdi_bits routine five different times. The format of
4213 * a MII read instruction consists of a shift out of 14 bits and is
4214 * defined as follows:
4215 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
4216 * followed by a shift in of 18 bits. This first two bits shifted in
4217 * are TurnAround bits used to avoid contention on the MDIO pin when a
4218 * READ operation is performed. These two bits are thrown away
4219 * followed by a shift in of 16 bits which contains the desired data.
4220 */
4221 mdic = ((reg_addr) | (phy_addr << 5) |
4222 (PHY_OP_READ << 10) | (PHY_SOF << 12));
4223
4224 e1000_shift_out_mdi_bits(hw, mdic, 14);
4225
4226 /* Now that we've shifted out the read command to the MII, we need to
4227 * "shift in" the 16-bit value (18 total bits) of the requested PHY
4228 * register address.
4229 */
4230 *phy_data = e1000_shift_in_mdi_bits(hw);
4231 }
4232 return 0;
4233}
4234
4235/******************************************************************************
4236* Writes a value to a PHY register
4237*
4238* hw - Struct containing variables accessed by shared code
4239* reg_addr - address of the PHY register to write
4240* data - data to write to the PHY
4241******************************************************************************/
4242static int
4243e1000_write_phy_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t phy_data)
4244{
4245 uint32_t i;
4246 uint32_t mdic = 0;
4247 const uint32_t phy_addr = 1;
4248
4249 if (reg_addr > MAX_PHY_REG_ADDRESS) {
4250 DEBUGOUT("PHY Address %d is out of range\n", reg_addr);
4251 return -E1000_ERR_PARAM;
4252 }
4253
4254 if (hw->mac_type > e1000_82543) {
4255 /* Set up Op-code, Phy Address, register address, and data intended
4256 * for the PHY register in the MDI Control register. The MAC will take
4257 * care of interfacing with the PHY to send the desired data.
4258 */
4259 mdic = (((uint32_t) phy_data) |
4260 (reg_addr << E1000_MDIC_REG_SHIFT) |
4261 (phy_addr << E1000_MDIC_PHY_SHIFT) |
4262 (E1000_MDIC_OP_WRITE));
4263
4264 E1000_WRITE_REG(hw, MDIC, mdic);
4265
4266 /* Poll the ready bit to see if the MDI read completed */
4267 for (i = 0; i < 64; i++) {
4268 udelay(10);
4269 mdic = E1000_READ_REG(hw, MDIC);
4270 if (mdic & E1000_MDIC_READY)
4271 break;
Roy Zang28f7a052009-07-31 13:34:02 +08004272 }
4273 if (!(mdic & E1000_MDIC_READY)) {
4274 DEBUGOUT("MDI Write did not complete\n");
4275 return -E1000_ERR_PHY;
4276 }
4277 } else {
4278 /* We'll need to use the SW defined pins to shift the write command
4279 * out to the PHY. We first send a preamble to the PHY to signal the
4280 * beginning of the MII instruction. This is done by sending 32
4281 * consecutive "1" bits.
4282 */
4283 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
4284
4285 /* Now combine the remaining required fields that will indicate a
4286 * write operation. We use this method instead of calling the
4287 * e1000_shift_out_mdi_bits routine for each field in the command. The
4288 * format of a MII write instruction is as follows:
4289 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
4290 */
4291 mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
4292 (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
4293 mdic <<= 16;
4294 mdic |= (uint32_t) phy_data;
4295
4296 e1000_shift_out_mdi_bits(hw, mdic, 32);
4297 }
4298 return 0;
4299}
4300
4301/******************************************************************************
4302 * Checks if PHY reset is blocked due to SOL/IDER session, for example.
4303 * Returning E1000_BLK_PHY_RESET isn't necessarily an error. But it's up to
4304 * the caller to figure out how to deal with it.
4305 *
4306 * hw - Struct containing variables accessed by shared code
4307 *
4308 * returns: - E1000_BLK_PHY_RESET
4309 * E1000_SUCCESS
4310 *
4311 *****************************************************************************/
4312int32_t
4313e1000_check_phy_reset_block(struct e1000_hw *hw)
4314{
4315 uint32_t manc = 0;
4316 uint32_t fwsm = 0;
4317
4318 if (hw->mac_type == e1000_ich8lan) {
4319 fwsm = E1000_READ_REG(hw, FWSM);
4320 return (fwsm & E1000_FWSM_RSPCIPHY) ? E1000_SUCCESS
4321 : E1000_BLK_PHY_RESET;
4322 }
4323
4324 if (hw->mac_type > e1000_82547_rev_2)
4325 manc = E1000_READ_REG(hw, MANC);
4326 return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
4327 E1000_BLK_PHY_RESET : E1000_SUCCESS;
4328}
4329
4330/***************************************************************************
4331 * Checks if the PHY configuration is done
4332 *
4333 * hw: Struct containing variables accessed by shared code
4334 *
4335 * returns: - E1000_ERR_RESET if fail to reset MAC
4336 * E1000_SUCCESS at any other case.
4337 *
4338 ***************************************************************************/
4339static int32_t
4340e1000_get_phy_cfg_done(struct e1000_hw *hw)
4341{
4342 int32_t timeout = PHY_CFG_TIMEOUT;
4343 uint32_t cfg_mask = E1000_EEPROM_CFG_DONE;
4344
4345 DEBUGFUNC();
4346
4347 switch (hw->mac_type) {
4348 default:
4349 mdelay(10);
4350 break;
Kyle Moffett7376f8d2010-09-13 05:52:22 +00004351
Roy Zang28f7a052009-07-31 13:34:02 +08004352 case e1000_80003es2lan:
4353 /* Separate *_CFG_DONE_* bit for each port */
Kyle Moffett7376f8d2010-09-13 05:52:22 +00004354 if (e1000_is_second_port(hw))
Roy Zang28f7a052009-07-31 13:34:02 +08004355 cfg_mask = E1000_EEPROM_CFG_DONE_PORT_1;
Kyle Moffett7376f8d2010-09-13 05:52:22 +00004356 /* Fall Through */
4357
Roy Zang28f7a052009-07-31 13:34:02 +08004358 case e1000_82571:
4359 case e1000_82572:
Marek Vasut74a13c22014-08-08 07:41:39 -07004360 case e1000_igb:
Roy Zang28f7a052009-07-31 13:34:02 +08004361 while (timeout) {
Marek Vasut74a13c22014-08-08 07:41:39 -07004362 if (hw->mac_type == e1000_igb) {
4363 if (E1000_READ_REG(hw, I210_EEMNGCTL) & cfg_mask)
4364 break;
4365 } else {
4366 if (E1000_READ_REG(hw, EEMNGCTL) & cfg_mask)
4367 break;
4368 }
4369 mdelay(1);
Roy Zang28f7a052009-07-31 13:34:02 +08004370 timeout--;
wdenk4e112c12003-06-03 23:54:09 +00004371 }
Roy Zang28f7a052009-07-31 13:34:02 +08004372 if (!timeout) {
4373 DEBUGOUT("MNG configuration cycle has not "
4374 "completed.\n");
4375 return -E1000_ERR_RESET;
wdenk4e112c12003-06-03 23:54:09 +00004376 }
Roy Zang28f7a052009-07-31 13:34:02 +08004377 break;
wdenk4e112c12003-06-03 23:54:09 +00004378 }
Roy Zang28f7a052009-07-31 13:34:02 +08004379
4380 return E1000_SUCCESS;
wdenk4e112c12003-06-03 23:54:09 +00004381}
4382
4383/******************************************************************************
4384* Returns the PHY to the power-on reset state
4385*
4386* hw - Struct containing variables accessed by shared code
4387******************************************************************************/
Roy Zang28f7a052009-07-31 13:34:02 +08004388int32_t
wdenk4e112c12003-06-03 23:54:09 +00004389e1000_phy_hw_reset(struct e1000_hw *hw)
4390{
Kyle Moffett7376f8d2010-09-13 05:52:22 +00004391 uint16_t swfw = E1000_SWFW_PHY0_SM;
Roy Zang28f7a052009-07-31 13:34:02 +08004392 uint32_t ctrl, ctrl_ext;
4393 uint32_t led_ctrl;
4394 int32_t ret_val;
wdenk4e112c12003-06-03 23:54:09 +00004395
4396 DEBUGFUNC();
4397
Roy Zang28f7a052009-07-31 13:34:02 +08004398 /* In the case of the phy reset being blocked, it's not an error, we
4399 * simply return success without performing the reset. */
4400 ret_val = e1000_check_phy_reset_block(hw);
4401 if (ret_val)
4402 return E1000_SUCCESS;
4403
wdenk4e112c12003-06-03 23:54:09 +00004404 DEBUGOUT("Resetting Phy...\n");
4405
4406 if (hw->mac_type > e1000_82543) {
Kyle Moffett7376f8d2010-09-13 05:52:22 +00004407 if (e1000_is_second_port(hw))
Roy Zang28f7a052009-07-31 13:34:02 +08004408 swfw = E1000_SWFW_PHY1_SM;
Kyle Moffett7376f8d2010-09-13 05:52:22 +00004409
Roy Zang28f7a052009-07-31 13:34:02 +08004410 if (e1000_swfw_sync_acquire(hw, swfw)) {
4411 DEBUGOUT("Unable to acquire swfw sync\n");
4412 return -E1000_ERR_SWFW_SYNC;
4413 }
Kyle Moffett7376f8d2010-09-13 05:52:22 +00004414
wdenk4e112c12003-06-03 23:54:09 +00004415 /* Read the device control register and assert the E1000_CTRL_PHY_RST
4416 * bit. Then, take it out of reset.
4417 */
4418 ctrl = E1000_READ_REG(hw, CTRL);
4419 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PHY_RST);
4420 E1000_WRITE_FLUSH(hw);
Roy Zang28f7a052009-07-31 13:34:02 +08004421
4422 if (hw->mac_type < e1000_82571)
4423 udelay(10);
4424 else
4425 udelay(100);
4426
wdenk4e112c12003-06-03 23:54:09 +00004427 E1000_WRITE_REG(hw, CTRL, ctrl);
4428 E1000_WRITE_FLUSH(hw);
Roy Zang28f7a052009-07-31 13:34:02 +08004429
4430 if (hw->mac_type >= e1000_82571)
4431 mdelay(10);
4432
wdenk4e112c12003-06-03 23:54:09 +00004433 } else {
4434 /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
4435 * bit to put the PHY into reset. Then, take it out of reset.
4436 */
4437 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
4438 ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
4439 ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
4440 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
4441 E1000_WRITE_FLUSH(hw);
4442 mdelay(10);
4443 ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
4444 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
4445 E1000_WRITE_FLUSH(hw);
4446 }
4447 udelay(150);
Roy Zang28f7a052009-07-31 13:34:02 +08004448
4449 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
4450 /* Configure activity LED after PHY reset */
4451 led_ctrl = E1000_READ_REG(hw, LEDCTL);
4452 led_ctrl &= IGP_ACTIVITY_LED_MASK;
4453 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
4454 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
4455 }
4456
4457 /* Wait for FW to finish PHY configuration. */
4458 ret_val = e1000_get_phy_cfg_done(hw);
4459 if (ret_val != E1000_SUCCESS)
4460 return ret_val;
4461
4462 return ret_val;
4463}
4464
4465/******************************************************************************
4466 * IGP phy init script - initializes the GbE PHY
4467 *
4468 * hw - Struct containing variables accessed by shared code
4469 *****************************************************************************/
4470static void
4471e1000_phy_init_script(struct e1000_hw *hw)
4472{
4473 uint32_t ret_val;
4474 uint16_t phy_saved_data;
4475 DEBUGFUNC();
4476
4477 if (hw->phy_init_script) {
4478 mdelay(20);
4479
4480 /* Save off the current value of register 0x2F5B to be
4481 * restored at the end of this routine. */
4482 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
4483
4484 /* Disabled the PHY transmitter */
4485 e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
4486
4487 mdelay(20);
4488
4489 e1000_write_phy_reg(hw, 0x0000, 0x0140);
4490
4491 mdelay(5);
4492
4493 switch (hw->mac_type) {
4494 case e1000_82541:
4495 case e1000_82547:
4496 e1000_write_phy_reg(hw, 0x1F95, 0x0001);
4497
4498 e1000_write_phy_reg(hw, 0x1F71, 0xBD21);
4499
4500 e1000_write_phy_reg(hw, 0x1F79, 0x0018);
4501
4502 e1000_write_phy_reg(hw, 0x1F30, 0x1600);
4503
4504 e1000_write_phy_reg(hw, 0x1F31, 0x0014);
4505
4506 e1000_write_phy_reg(hw, 0x1F32, 0x161C);
4507
4508 e1000_write_phy_reg(hw, 0x1F94, 0x0003);
4509
4510 e1000_write_phy_reg(hw, 0x1F96, 0x003F);
4511
4512 e1000_write_phy_reg(hw, 0x2010, 0x0008);
4513 break;
4514
4515 case e1000_82541_rev_2:
4516 case e1000_82547_rev_2:
4517 e1000_write_phy_reg(hw, 0x1F73, 0x0099);
4518 break;
4519 default:
4520 break;
4521 }
4522
4523 e1000_write_phy_reg(hw, 0x0000, 0x3300);
4524
4525 mdelay(20);
4526
4527 /* Now enable the transmitter */
Zang Roy-R61911e36d67c2011-11-06 22:22:36 +00004528 if (!ret_val)
4529 e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
Roy Zang28f7a052009-07-31 13:34:02 +08004530
4531 if (hw->mac_type == e1000_82547) {
4532 uint16_t fused, fine, coarse;
4533
4534 /* Move to analog registers page */
4535 e1000_read_phy_reg(hw,
4536 IGP01E1000_ANALOG_SPARE_FUSE_STATUS, &fused);
4537
4538 if (!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) {
4539 e1000_read_phy_reg(hw,
4540 IGP01E1000_ANALOG_FUSE_STATUS, &fused);
4541
4542 fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK;
4543 coarse = fused
4544 & IGP01E1000_ANALOG_FUSE_COARSE_MASK;
4545
4546 if (coarse >
4547 IGP01E1000_ANALOG_FUSE_COARSE_THRESH) {
4548 coarse -=
4549 IGP01E1000_ANALOG_FUSE_COARSE_10;
4550 fine -= IGP01E1000_ANALOG_FUSE_FINE_1;
4551 } else if (coarse
4552 == IGP01E1000_ANALOG_FUSE_COARSE_THRESH)
4553 fine -= IGP01E1000_ANALOG_FUSE_FINE_10;
4554
4555 fused = (fused
4556 & IGP01E1000_ANALOG_FUSE_POLY_MASK) |
4557 (fine
4558 & IGP01E1000_ANALOG_FUSE_FINE_MASK) |
4559 (coarse
4560 & IGP01E1000_ANALOG_FUSE_COARSE_MASK);
4561
4562 e1000_write_phy_reg(hw,
4563 IGP01E1000_ANALOG_FUSE_CONTROL, fused);
4564 e1000_write_phy_reg(hw,
4565 IGP01E1000_ANALOG_FUSE_BYPASS,
4566 IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL);
4567 }
4568 }
4569 }
wdenk4e112c12003-06-03 23:54:09 +00004570}
4571
4572/******************************************************************************
4573* Resets the PHY
4574*
4575* hw - Struct containing variables accessed by shared code
4576*
Roy Zang28f7a052009-07-31 13:34:02 +08004577* Sets bit 15 of the MII Control register
wdenk4e112c12003-06-03 23:54:09 +00004578******************************************************************************/
Roy Zang28f7a052009-07-31 13:34:02 +08004579int32_t
wdenk4e112c12003-06-03 23:54:09 +00004580e1000_phy_reset(struct e1000_hw *hw)
4581{
Roy Zang28f7a052009-07-31 13:34:02 +08004582 int32_t ret_val;
wdenk4e112c12003-06-03 23:54:09 +00004583 uint16_t phy_data;
4584
4585 DEBUGFUNC();
4586
Roy Zang28f7a052009-07-31 13:34:02 +08004587 /* In the case of the phy reset being blocked, it's not an error, we
4588 * simply return success without performing the reset. */
4589 ret_val = e1000_check_phy_reset_block(hw);
4590 if (ret_val)
4591 return E1000_SUCCESS;
4592
4593 switch (hw->phy_type) {
4594 case e1000_phy_igp:
4595 case e1000_phy_igp_2:
4596 case e1000_phy_igp_3:
4597 case e1000_phy_ife:
Marek Vasut74a13c22014-08-08 07:41:39 -07004598 case e1000_phy_igb:
Roy Zang28f7a052009-07-31 13:34:02 +08004599 ret_val = e1000_phy_hw_reset(hw);
4600 if (ret_val)
4601 return ret_val;
4602 break;
4603 default:
4604 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
4605 if (ret_val)
4606 return ret_val;
4607
4608 phy_data |= MII_CR_RESET;
4609 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
4610 if (ret_val)
4611 return ret_val;
4612
4613 udelay(1);
4614 break;
wdenk4e112c12003-06-03 23:54:09 +00004615 }
Roy Zang28f7a052009-07-31 13:34:02 +08004616
4617 if (hw->phy_type == e1000_phy_igp || hw->phy_type == e1000_phy_igp_2)
4618 e1000_phy_init_script(hw);
4619
4620 return E1000_SUCCESS;
wdenk4e112c12003-06-03 23:54:09 +00004621}
4622
Wolfgang Denk35f734f2008-04-13 09:59:26 -07004623static int e1000_set_phy_type (struct e1000_hw *hw)
Andre Schwarz68c2a302008-03-06 16:45:44 +01004624{
Wolfgang Denk35f734f2008-04-13 09:59:26 -07004625 DEBUGFUNC ();
Andre Schwarz68c2a302008-03-06 16:45:44 +01004626
Wolfgang Denk35f734f2008-04-13 09:59:26 -07004627 if (hw->mac_type == e1000_undefined)
4628 return -E1000_ERR_PHY_TYPE;
Andre Schwarz68c2a302008-03-06 16:45:44 +01004629
Wolfgang Denk35f734f2008-04-13 09:59:26 -07004630 switch (hw->phy_id) {
4631 case M88E1000_E_PHY_ID:
4632 case M88E1000_I_PHY_ID:
4633 case M88E1011_I_PHY_ID:
Roy Zang28f7a052009-07-31 13:34:02 +08004634 case M88E1111_I_PHY_ID:
Wolfgang Denk35f734f2008-04-13 09:59:26 -07004635 hw->phy_type = e1000_phy_m88;
4636 break;
4637 case IGP01E1000_I_PHY_ID:
4638 if (hw->mac_type == e1000_82541 ||
Roy Zang28f7a052009-07-31 13:34:02 +08004639 hw->mac_type == e1000_82541_rev_2 ||
4640 hw->mac_type == e1000_82547 ||
4641 hw->mac_type == e1000_82547_rev_2) {
Wolfgang Denk35f734f2008-04-13 09:59:26 -07004642 hw->phy_type = e1000_phy_igp;
Roy Zang28f7a052009-07-31 13:34:02 +08004643 break;
4644 }
4645 case IGP03E1000_E_PHY_ID:
4646 hw->phy_type = e1000_phy_igp_3;
4647 break;
4648 case IFE_E_PHY_ID:
4649 case IFE_PLUS_E_PHY_ID:
4650 case IFE_C_E_PHY_ID:
4651 hw->phy_type = e1000_phy_ife;
4652 break;
4653 case GG82563_E_PHY_ID:
4654 if (hw->mac_type == e1000_80003es2lan) {
4655 hw->phy_type = e1000_phy_gg82563;
Wolfgang Denk35f734f2008-04-13 09:59:26 -07004656 break;
4657 }
Roy Zang181119b2011-01-21 11:29:38 +08004658 case BME1000_E_PHY_ID:
4659 hw->phy_type = e1000_phy_bm;
4660 break;
Marek Vasut74a13c22014-08-08 07:41:39 -07004661 case I210_I_PHY_ID:
4662 hw->phy_type = e1000_phy_igb;
4663 break;
Wolfgang Denk35f734f2008-04-13 09:59:26 -07004664 /* Fall Through */
4665 default:
4666 /* Should never have loaded on this device */
4667 hw->phy_type = e1000_phy_undefined;
4668 return -E1000_ERR_PHY_TYPE;
4669 }
Andre Schwarz68c2a302008-03-06 16:45:44 +01004670
Wolfgang Denk35f734f2008-04-13 09:59:26 -07004671 return E1000_SUCCESS;
Andre Schwarz68c2a302008-03-06 16:45:44 +01004672}
4673
wdenk4e112c12003-06-03 23:54:09 +00004674/******************************************************************************
4675* Probes the expected PHY address for known PHY IDs
4676*
4677* hw - Struct containing variables accessed by shared code
4678******************************************************************************/
Roy Zang28f7a052009-07-31 13:34:02 +08004679static int32_t
wdenk4e112c12003-06-03 23:54:09 +00004680e1000_detect_gig_phy(struct e1000_hw *hw)
4681{
Roy Zang28f7a052009-07-31 13:34:02 +08004682 int32_t phy_init_status, ret_val;
wdenk4e112c12003-06-03 23:54:09 +00004683 uint16_t phy_id_high, phy_id_low;
York Sun4a598092013-04-01 11:29:11 -07004684 bool match = false;
wdenk4e112c12003-06-03 23:54:09 +00004685
4686 DEBUGFUNC();
4687
Roy Zang28f7a052009-07-31 13:34:02 +08004688 /* The 82571 firmware may still be configuring the PHY. In this
4689 * case, we cannot access the PHY until the configuration is done. So
4690 * we explicitly set the PHY values. */
4691 if (hw->mac_type == e1000_82571 ||
4692 hw->mac_type == e1000_82572) {
4693 hw->phy_id = IGP01E1000_I_PHY_ID;
4694 hw->phy_type = e1000_phy_igp_2;
4695 return E1000_SUCCESS;
wdenk4e112c12003-06-03 23:54:09 +00004696 }
Roy Zang28f7a052009-07-31 13:34:02 +08004697
4698 /* ESB-2 PHY reads require e1000_phy_gg82563 to be set because of a
4699 * work- around that forces PHY page 0 to be set or the reads fail.
4700 * The rest of the code in this routine uses e1000_read_phy_reg to
4701 * read the PHY ID. So for ESB-2 we need to have this set so our
4702 * reads won't fail. If the attached PHY is not a e1000_phy_gg82563,
4703 * the routines below will figure this out as well. */
4704 if (hw->mac_type == e1000_80003es2lan)
4705 hw->phy_type = e1000_phy_gg82563;
4706
4707 /* Read the PHY ID Registers to identify which PHY is onboard. */
4708 ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high);
4709 if (ret_val)
4710 return ret_val;
4711
wdenk4e112c12003-06-03 23:54:09 +00004712 hw->phy_id = (uint32_t) (phy_id_high << 16);
Roy Zang28f7a052009-07-31 13:34:02 +08004713 udelay(20);
4714 ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low);
4715 if (ret_val)
4716 return ret_val;
4717
wdenk4e112c12003-06-03 23:54:09 +00004718 hw->phy_id |= (uint32_t) (phy_id_low & PHY_REVISION_MASK);
Roy Zang28f7a052009-07-31 13:34:02 +08004719 hw->phy_revision = (uint32_t) phy_id_low & ~PHY_REVISION_MASK;
wdenk4e112c12003-06-03 23:54:09 +00004720
4721 switch (hw->mac_type) {
4722 case e1000_82543:
4723 if (hw->phy_id == M88E1000_E_PHY_ID)
York Sun4a598092013-04-01 11:29:11 -07004724 match = true;
wdenk4e112c12003-06-03 23:54:09 +00004725 break;
4726 case e1000_82544:
4727 if (hw->phy_id == M88E1000_I_PHY_ID)
York Sun4a598092013-04-01 11:29:11 -07004728 match = true;
wdenk4e112c12003-06-03 23:54:09 +00004729 break;
4730 case e1000_82540:
4731 case e1000_82545:
Roy Zang28f7a052009-07-31 13:34:02 +08004732 case e1000_82545_rev_3:
wdenk4e112c12003-06-03 23:54:09 +00004733 case e1000_82546:
Roy Zang28f7a052009-07-31 13:34:02 +08004734 case e1000_82546_rev_3:
wdenk4e112c12003-06-03 23:54:09 +00004735 if (hw->phy_id == M88E1011_I_PHY_ID)
York Sun4a598092013-04-01 11:29:11 -07004736 match = true;
Andre Schwarz68c2a302008-03-06 16:45:44 +01004737 break;
Roy Zang28f7a052009-07-31 13:34:02 +08004738 case e1000_82541:
Andre Schwarz68c2a302008-03-06 16:45:44 +01004739 case e1000_82541_rev_2:
Roy Zang28f7a052009-07-31 13:34:02 +08004740 case e1000_82547:
4741 case e1000_82547_rev_2:
Andre Schwarz68c2a302008-03-06 16:45:44 +01004742 if(hw->phy_id == IGP01E1000_I_PHY_ID)
York Sun4a598092013-04-01 11:29:11 -07004743 match = true;
Andre Schwarz68c2a302008-03-06 16:45:44 +01004744
wdenk4e112c12003-06-03 23:54:09 +00004745 break;
Roy Zang28f7a052009-07-31 13:34:02 +08004746 case e1000_82573:
4747 if (hw->phy_id == M88E1111_I_PHY_ID)
York Sun4a598092013-04-01 11:29:11 -07004748 match = true;
Roy Zang28f7a052009-07-31 13:34:02 +08004749 break;
Roy Zang181119b2011-01-21 11:29:38 +08004750 case e1000_82574:
4751 if (hw->phy_id == BME1000_E_PHY_ID)
York Sun4a598092013-04-01 11:29:11 -07004752 match = true;
Roy Zang181119b2011-01-21 11:29:38 +08004753 break;
Roy Zang28f7a052009-07-31 13:34:02 +08004754 case e1000_80003es2lan:
4755 if (hw->phy_id == GG82563_E_PHY_ID)
York Sun4a598092013-04-01 11:29:11 -07004756 match = true;
Roy Zang28f7a052009-07-31 13:34:02 +08004757 break;
4758 case e1000_ich8lan:
4759 if (hw->phy_id == IGP03E1000_E_PHY_ID)
York Sun4a598092013-04-01 11:29:11 -07004760 match = true;
Roy Zang28f7a052009-07-31 13:34:02 +08004761 if (hw->phy_id == IFE_E_PHY_ID)
York Sun4a598092013-04-01 11:29:11 -07004762 match = true;
Roy Zang28f7a052009-07-31 13:34:02 +08004763 if (hw->phy_id == IFE_PLUS_E_PHY_ID)
York Sun4a598092013-04-01 11:29:11 -07004764 match = true;
Roy Zang28f7a052009-07-31 13:34:02 +08004765 if (hw->phy_id == IFE_C_E_PHY_ID)
York Sun4a598092013-04-01 11:29:11 -07004766 match = true;
Roy Zang28f7a052009-07-31 13:34:02 +08004767 break;
Marek Vasut74a13c22014-08-08 07:41:39 -07004768 case e1000_igb:
4769 if (hw->phy_id == I210_I_PHY_ID)
4770 match = true;
4771 break;
wdenk4e112c12003-06-03 23:54:09 +00004772 default:
4773 DEBUGOUT("Invalid MAC type %d\n", hw->mac_type);
4774 return -E1000_ERR_CONFIG;
4775 }
Andre Schwarz68c2a302008-03-06 16:45:44 +01004776
4777 phy_init_status = e1000_set_phy_type(hw);
4778
4779 if ((match) && (phy_init_status == E1000_SUCCESS)) {
wdenk4e112c12003-06-03 23:54:09 +00004780 DEBUGOUT("PHY ID 0x%X detected\n", hw->phy_id);
4781 return 0;
4782 }
4783 DEBUGOUT("Invalid PHY ID 0x%X\n", hw->phy_id);
4784 return -E1000_ERR_PHY;
4785}
4786
Roy Zang28f7a052009-07-31 13:34:02 +08004787/*****************************************************************************
4788 * Set media type and TBI compatibility.
4789 *
4790 * hw - Struct containing variables accessed by shared code
4791 * **************************************************************************/
4792void
4793e1000_set_media_type(struct e1000_hw *hw)
4794{
4795 uint32_t status;
4796
4797 DEBUGFUNC();
4798
4799 if (hw->mac_type != e1000_82543) {
4800 /* tbi_compatibility is only valid on 82543 */
York Sun4a598092013-04-01 11:29:11 -07004801 hw->tbi_compatibility_en = false;
Roy Zang28f7a052009-07-31 13:34:02 +08004802 }
4803
4804 switch (hw->device_id) {
4805 case E1000_DEV_ID_82545GM_SERDES:
4806 case E1000_DEV_ID_82546GB_SERDES:
4807 case E1000_DEV_ID_82571EB_SERDES:
4808 case E1000_DEV_ID_82571EB_SERDES_DUAL:
4809 case E1000_DEV_ID_82571EB_SERDES_QUAD:
4810 case E1000_DEV_ID_82572EI_SERDES:
4811 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
4812 hw->media_type = e1000_media_type_internal_serdes;
4813 break;
4814 default:
4815 switch (hw->mac_type) {
4816 case e1000_82542_rev2_0:
4817 case e1000_82542_rev2_1:
4818 hw->media_type = e1000_media_type_fiber;
4819 break;
4820 case e1000_ich8lan:
4821 case e1000_82573:
Roy Zang181119b2011-01-21 11:29:38 +08004822 case e1000_82574:
Marek Vasut74a13c22014-08-08 07:41:39 -07004823 case e1000_igb:
Roy Zang28f7a052009-07-31 13:34:02 +08004824 /* The STATUS_TBIMODE bit is reserved or reused
4825 * for the this device.
4826 */
4827 hw->media_type = e1000_media_type_copper;
4828 break;
4829 default:
4830 status = E1000_READ_REG(hw, STATUS);
4831 if (status & E1000_STATUS_TBIMODE) {
4832 hw->media_type = e1000_media_type_fiber;
4833 /* tbi_compatibility not valid on fiber */
York Sun4a598092013-04-01 11:29:11 -07004834 hw->tbi_compatibility_en = false;
Roy Zang28f7a052009-07-31 13:34:02 +08004835 } else {
4836 hw->media_type = e1000_media_type_copper;
4837 }
4838 break;
4839 }
4840 }
4841}
4842
wdenk4e112c12003-06-03 23:54:09 +00004843/**
4844 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
4845 *
4846 * e1000_sw_init initializes the Adapter private data structure.
4847 * Fields are initialized based on PCI device information and
4848 * OS network device settings (MTU size).
4849 **/
4850
4851static int
Kyle Moffett7b698d52011-10-18 11:05:26 +00004852e1000_sw_init(struct eth_device *nic)
wdenk4e112c12003-06-03 23:54:09 +00004853{
4854 struct e1000_hw *hw = (typeof(hw)) nic->priv;
4855 int result;
4856
4857 /* PCI config space info */
4858 pci_read_config_word(hw->pdev, PCI_VENDOR_ID, &hw->vendor_id);
4859 pci_read_config_word(hw->pdev, PCI_DEVICE_ID, &hw->device_id);
4860 pci_read_config_word(hw->pdev, PCI_SUBSYSTEM_VENDOR_ID,
4861 &hw->subsystem_vendor_id);
4862 pci_read_config_word(hw->pdev, PCI_SUBSYSTEM_ID, &hw->subsystem_id);
4863
4864 pci_read_config_byte(hw->pdev, PCI_REVISION_ID, &hw->revision_id);
4865 pci_read_config_word(hw->pdev, PCI_COMMAND, &hw->pci_cmd_word);
4866
4867 /* identify the MAC */
4868 result = e1000_set_mac_type(hw);
4869 if (result) {
Kyle Moffett7b698d52011-10-18 11:05:26 +00004870 E1000_ERR(hw->nic, "Unknown MAC Type\n");
wdenk4e112c12003-06-03 23:54:09 +00004871 return result;
4872 }
4873
Roy Zang28f7a052009-07-31 13:34:02 +08004874 switch (hw->mac_type) {
4875 default:
4876 break;
4877 case e1000_82541:
4878 case e1000_82547:
4879 case e1000_82541_rev_2:
4880 case e1000_82547_rev_2:
4881 hw->phy_init_script = 1;
4882 break;
4883 }
4884
wdenk4e112c12003-06-03 23:54:09 +00004885 /* flow control settings */
4886 hw->fc_high_water = E1000_FC_HIGH_THRESH;
4887 hw->fc_low_water = E1000_FC_LOW_THRESH;
4888 hw->fc_pause_time = E1000_FC_PAUSE_TIME;
4889 hw->fc_send_xon = 1;
4890
4891 /* Media type - copper or fiber */
Marek Vasut74a13c22014-08-08 07:41:39 -07004892 hw->tbi_compatibility_en = true;
Roy Zang28f7a052009-07-31 13:34:02 +08004893 e1000_set_media_type(hw);
wdenk4e112c12003-06-03 23:54:09 +00004894
4895 if (hw->mac_type >= e1000_82543) {
4896 uint32_t status = E1000_READ_REG(hw, STATUS);
4897
4898 if (status & E1000_STATUS_TBIMODE) {
4899 DEBUGOUT("fiber interface\n");
4900 hw->media_type = e1000_media_type_fiber;
4901 } else {
4902 DEBUGOUT("copper interface\n");
4903 hw->media_type = e1000_media_type_copper;
4904 }
4905 } else {
4906 hw->media_type = e1000_media_type_fiber;
4907 }
4908
York Sun4a598092013-04-01 11:29:11 -07004909 hw->wait_autoneg_complete = true;
wdenk4e112c12003-06-03 23:54:09 +00004910 if (hw->mac_type < e1000_82543)
4911 hw->report_tx_early = 0;
4912 else
4913 hw->report_tx_early = 1;
4914
wdenk4e112c12003-06-03 23:54:09 +00004915 return E1000_SUCCESS;
4916}
4917
4918void
4919fill_rx(struct e1000_hw *hw)
4920{
4921 struct e1000_rx_desc *rd;
Marek Vasut742c5c22014-08-08 07:41:38 -07004922 uint32_t flush_start, flush_end;
wdenk4e112c12003-06-03 23:54:09 +00004923
4924 rx_last = rx_tail;
4925 rd = rx_base + rx_tail;
4926 rx_tail = (rx_tail + 1) % 8;
4927 memset(rd, 0, 16);
Marek Vasut742c5c22014-08-08 07:41:38 -07004928 rd->buffer_addr = cpu_to_le64((u32)packet);
4929
4930 /*
4931 * Make sure there are no stale data in WB over this area, which
4932 * might get written into the memory while the e1000 also writes
4933 * into the same memory area.
4934 */
4935 invalidate_dcache_range((u32)packet, (u32)packet + 4096);
4936 /* Dump the DMA descriptor into RAM. */
4937 flush_start = ((u32)rd) & ~(ARCH_DMA_MINALIGN - 1);
4938 flush_end = flush_start + roundup(sizeof(*rd), ARCH_DMA_MINALIGN);
4939 flush_dcache_range(flush_start, flush_end);
4940
wdenk4e112c12003-06-03 23:54:09 +00004941 E1000_WRITE_REG(hw, RDT, rx_tail);
4942}
4943
4944/**
4945 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
4946 * @adapter: board private structure
4947 *
4948 * Configure the Tx unit of the MAC after a reset.
4949 **/
4950
4951static void
4952e1000_configure_tx(struct e1000_hw *hw)
4953{
wdenk4e112c12003-06-03 23:54:09 +00004954 unsigned long tctl;
Roy Zang28f7a052009-07-31 13:34:02 +08004955 unsigned long tipg, tarc;
4956 uint32_t ipgr1, ipgr2;
wdenk4e112c12003-06-03 23:54:09 +00004957
wdenk4e112c12003-06-03 23:54:09 +00004958 E1000_WRITE_REG(hw, TDBAL, (u32) tx_base);
4959 E1000_WRITE_REG(hw, TDBAH, 0);
4960
4961 E1000_WRITE_REG(hw, TDLEN, 128);
4962
4963 /* Setup the HW Tx Head and Tail descriptor pointers */
4964 E1000_WRITE_REG(hw, TDH, 0);
4965 E1000_WRITE_REG(hw, TDT, 0);
4966 tx_tail = 0;
4967
4968 /* Set the default values for the Tx Inter Packet Gap timer */
Roy Zang28f7a052009-07-31 13:34:02 +08004969 if (hw->mac_type <= e1000_82547_rev_2 &&
4970 (hw->media_type == e1000_media_type_fiber ||
4971 hw->media_type == e1000_media_type_internal_serdes))
4972 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
4973 else
4974 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
4975
4976 /* Set the default values for the Tx Inter Packet Gap timer */
wdenk4e112c12003-06-03 23:54:09 +00004977 switch (hw->mac_type) {
4978 case e1000_82542_rev2_0:
4979 case e1000_82542_rev2_1:
4980 tipg = DEFAULT_82542_TIPG_IPGT;
Roy Zang28f7a052009-07-31 13:34:02 +08004981 ipgr1 = DEFAULT_82542_TIPG_IPGR1;
4982 ipgr2 = DEFAULT_82542_TIPG_IPGR2;
4983 break;
4984 case e1000_80003es2lan:
4985 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
4986 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2;
wdenk4e112c12003-06-03 23:54:09 +00004987 break;
4988 default:
Roy Zang28f7a052009-07-31 13:34:02 +08004989 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
4990 ipgr2 = DEFAULT_82543_TIPG_IPGR2;
4991 break;
wdenk4e112c12003-06-03 23:54:09 +00004992 }
Roy Zang28f7a052009-07-31 13:34:02 +08004993 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
4994 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
wdenk4e112c12003-06-03 23:54:09 +00004995 E1000_WRITE_REG(hw, TIPG, tipg);
wdenk4e112c12003-06-03 23:54:09 +00004996 /* Program the Transmit Control Register */
4997 tctl = E1000_READ_REG(hw, TCTL);
4998 tctl &= ~E1000_TCTL_CT;
4999 tctl |= E1000_TCTL_EN | E1000_TCTL_PSP |
5000 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
Roy Zang28f7a052009-07-31 13:34:02 +08005001
5002 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) {
5003 tarc = E1000_READ_REG(hw, TARC0);
5004 /* set the speed mode bit, we'll clear it if we're not at
5005 * gigabit link later */
5006 /* git bit can be set to 1*/
5007 } else if (hw->mac_type == e1000_80003es2lan) {
5008 tarc = E1000_READ_REG(hw, TARC0);
5009 tarc |= 1;
5010 E1000_WRITE_REG(hw, TARC0, tarc);
5011 tarc = E1000_READ_REG(hw, TARC1);
5012 tarc |= 1;
5013 E1000_WRITE_REG(hw, TARC1, tarc);
5014 }
5015
wdenk4e112c12003-06-03 23:54:09 +00005016
5017 e1000_config_collision_dist(hw);
Roy Zang28f7a052009-07-31 13:34:02 +08005018 /* Setup Transmit Descriptor Settings for eop descriptor */
5019 hw->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
wdenk4e112c12003-06-03 23:54:09 +00005020
Roy Zang28f7a052009-07-31 13:34:02 +08005021 /* Need to set up RS bit */
5022 if (hw->mac_type < e1000_82543)
5023 hw->txd_cmd |= E1000_TXD_CMD_RPS;
wdenk4e112c12003-06-03 23:54:09 +00005024 else
Roy Zang28f7a052009-07-31 13:34:02 +08005025 hw->txd_cmd |= E1000_TXD_CMD_RS;
Marek Vasut74a13c22014-08-08 07:41:39 -07005026
5027
5028 if (hw->mac_type == e1000_igb) {
5029 E1000_WRITE_REG(hw, TCTL_EXT, 0x42 << 10);
5030
5031 uint32_t reg_txdctl = E1000_READ_REG(hw, TXDCTL);
5032 reg_txdctl |= 1 << 25;
5033 E1000_WRITE_REG(hw, TXDCTL, reg_txdctl);
5034 mdelay(20);
5035 }
5036
5037
5038
Roy Zang28f7a052009-07-31 13:34:02 +08005039 E1000_WRITE_REG(hw, TCTL, tctl);
Marek Vasut74a13c22014-08-08 07:41:39 -07005040
5041
wdenk4e112c12003-06-03 23:54:09 +00005042}
5043
5044/**
5045 * e1000_setup_rctl - configure the receive control register
5046 * @adapter: Board private structure
5047 **/
5048static void
5049e1000_setup_rctl(struct e1000_hw *hw)
5050{
5051 uint32_t rctl;
5052
5053 rctl = E1000_READ_REG(hw, RCTL);
5054
5055 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
5056
Roy Zang28f7a052009-07-31 13:34:02 +08005057 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_LBM_NO
5058 | E1000_RCTL_RDMTS_HALF; /* |
5059 (hw.mc_filter_type << E1000_RCTL_MO_SHIFT); */
wdenk4e112c12003-06-03 23:54:09 +00005060
5061 if (hw->tbi_compatibility_on == 1)
5062 rctl |= E1000_RCTL_SBP;
5063 else
5064 rctl &= ~E1000_RCTL_SBP;
5065
5066 rctl &= ~(E1000_RCTL_SZ_4096);
wdenk4e112c12003-06-03 23:54:09 +00005067 rctl |= E1000_RCTL_SZ_2048;
5068 rctl &= ~(E1000_RCTL_BSEX | E1000_RCTL_LPE);
wdenk4e112c12003-06-03 23:54:09 +00005069 E1000_WRITE_REG(hw, RCTL, rctl);
5070}
5071
5072/**
5073 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
5074 * @adapter: board private structure
5075 *
5076 * Configure the Rx unit of the MAC after a reset.
5077 **/
5078static void
5079e1000_configure_rx(struct e1000_hw *hw)
5080{
Roy Zang28f7a052009-07-31 13:34:02 +08005081 unsigned long rctl, ctrl_ext;
wdenk4e112c12003-06-03 23:54:09 +00005082 rx_tail = 0;
5083 /* make sure receives are disabled while setting up the descriptors */
5084 rctl = E1000_READ_REG(hw, RCTL);
5085 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
wdenk4e112c12003-06-03 23:54:09 +00005086 if (hw->mac_type >= e1000_82540) {
wdenk4e112c12003-06-03 23:54:09 +00005087 /* Set the interrupt throttling rate. Value is calculated
5088 * as DEFAULT_ITR = 1/(MAX_INTS_PER_SEC * 256ns) */
Wolfgang Denk35f734f2008-04-13 09:59:26 -07005089#define MAX_INTS_PER_SEC 8000
5090#define DEFAULT_ITR 1000000000/(MAX_INTS_PER_SEC * 256)
wdenk4e112c12003-06-03 23:54:09 +00005091 E1000_WRITE_REG(hw, ITR, DEFAULT_ITR);
5092 }
5093
Roy Zang28f7a052009-07-31 13:34:02 +08005094 if (hw->mac_type >= e1000_82571) {
5095 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
5096 /* Reset delay timers after every interrupt */
5097 ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR;
5098 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
5099 E1000_WRITE_FLUSH(hw);
5100 }
wdenk4e112c12003-06-03 23:54:09 +00005101 /* Setup the Base and Length of the Rx Descriptor Ring */
wdenk4e112c12003-06-03 23:54:09 +00005102 E1000_WRITE_REG(hw, RDBAL, (u32) rx_base);
5103 E1000_WRITE_REG(hw, RDBAH, 0);
5104
5105 E1000_WRITE_REG(hw, RDLEN, 128);
5106
5107 /* Setup the HW Rx Head and Tail Descriptor Pointers */
5108 E1000_WRITE_REG(hw, RDH, 0);
5109 E1000_WRITE_REG(hw, RDT, 0);
wdenk4e112c12003-06-03 23:54:09 +00005110 /* Enable Receives */
5111
Marek Vasut74a13c22014-08-08 07:41:39 -07005112 if (hw->mac_type == e1000_igb) {
5113
5114 uint32_t reg_rxdctl = E1000_READ_REG(hw, RXDCTL);
5115 reg_rxdctl |= 1 << 25;
5116 E1000_WRITE_REG(hw, RXDCTL, reg_rxdctl);
5117 mdelay(20);
5118 }
5119
wdenk4e112c12003-06-03 23:54:09 +00005120 E1000_WRITE_REG(hw, RCTL, rctl);
Marek Vasut74a13c22014-08-08 07:41:39 -07005121
wdenk4e112c12003-06-03 23:54:09 +00005122 fill_rx(hw);
5123}
5124
5125/**************************************************************************
5126POLL - Wait for a frame
5127***************************************************************************/
5128static int
5129e1000_poll(struct eth_device *nic)
5130{
5131 struct e1000_hw *hw = nic->priv;
5132 struct e1000_rx_desc *rd;
Marek Vasut742c5c22014-08-08 07:41:38 -07005133 uint32_t inval_start, inval_end;
5134 uint32_t len;
5135
wdenk4e112c12003-06-03 23:54:09 +00005136 /* return true if there's an ethernet packet ready to read */
5137 rd = rx_base + rx_last;
Marek Vasut742c5c22014-08-08 07:41:38 -07005138
5139 /* Re-load the descriptor from RAM. */
5140 inval_start = ((u32)rd) & ~(ARCH_DMA_MINALIGN - 1);
5141 inval_end = inval_start + roundup(sizeof(*rd), ARCH_DMA_MINALIGN);
5142 invalidate_dcache_range(inval_start, inval_end);
5143
wdenk4e112c12003-06-03 23:54:09 +00005144 if (!(le32_to_cpu(rd->status)) & E1000_RXD_STAT_DD)
5145 return 0;
5146 /*DEBUGOUT("recv: packet len=%d \n", rd->length); */
Marek Vasut742c5c22014-08-08 07:41:38 -07005147 /* Packet received, make sure the data are re-loaded from RAM. */
5148 len = le32_to_cpu(rd->length);
5149 invalidate_dcache_range((u32)packet,
5150 (u32)packet + roundup(len, ARCH_DMA_MINALIGN));
5151 NetReceive((uchar *)packet, len);
wdenk4e112c12003-06-03 23:54:09 +00005152 fill_rx(hw);
5153 return 1;
5154}
5155
5156/**************************************************************************
5157TRANSMIT - Transmit a frame
5158***************************************************************************/
Marek Vasut742c5c22014-08-08 07:41:38 -07005159static int e1000_transmit(struct eth_device *nic, void *txpacket, int length)
wdenk4e112c12003-06-03 23:54:09 +00005160{
Marek Vasut742c5c22014-08-08 07:41:38 -07005161 void *nv_packet = (void *)txpacket;
wdenk4e112c12003-06-03 23:54:09 +00005162 struct e1000_hw *hw = nic->priv;
5163 struct e1000_tx_desc *txp;
5164 int i = 0;
Marek Vasut742c5c22014-08-08 07:41:38 -07005165 uint32_t flush_start, flush_end;
wdenk4e112c12003-06-03 23:54:09 +00005166
5167 txp = tx_base + tx_tail;
5168 tx_tail = (tx_tail + 1) % 8;
5169
Wolfgang Denkf83102e2010-11-22 09:48:45 +01005170 txp->buffer_addr = cpu_to_le64(virt_to_bus(hw->pdev, nv_packet));
Roy Zang28f7a052009-07-31 13:34:02 +08005171 txp->lower.data = cpu_to_le32(hw->txd_cmd | length);
wdenk4e112c12003-06-03 23:54:09 +00005172 txp->upper.data = 0;
Marek Vasut742c5c22014-08-08 07:41:38 -07005173
5174 /* Dump the packet into RAM so e1000 can pick them. */
5175 flush_dcache_range((u32)nv_packet,
5176 (u32)nv_packet + roundup(length, ARCH_DMA_MINALIGN));
5177 /* Dump the descriptor into RAM as well. */
5178 flush_start = ((u32)txp) & ~(ARCH_DMA_MINALIGN - 1);
5179 flush_end = flush_start + roundup(sizeof(*txp), ARCH_DMA_MINALIGN);
5180 flush_dcache_range(flush_start, flush_end);
5181
wdenk4e112c12003-06-03 23:54:09 +00005182 E1000_WRITE_REG(hw, TDT, tx_tail);
5183
Roy Zang28f7a052009-07-31 13:34:02 +08005184 E1000_WRITE_FLUSH(hw);
Marek Vasut742c5c22014-08-08 07:41:38 -07005185 while (1) {
5186 invalidate_dcache_range(flush_start, flush_end);
5187 if (le32_to_cpu(txp->upper.data) & E1000_TXD_STAT_DD)
5188 break;
wdenk4e112c12003-06-03 23:54:09 +00005189 if (i++ > TOUT_LOOP) {
5190 DEBUGOUT("e1000: tx timeout\n");
5191 return 0;
5192 }
5193 udelay(10); /* give the nic a chance to write to the register */
5194 }
5195 return 1;
5196}
5197
5198/*reset function*/
5199static inline int
5200e1000_reset(struct eth_device *nic)
5201{
5202 struct e1000_hw *hw = nic->priv;
5203
5204 e1000_reset_hw(hw);
5205 if (hw->mac_type >= e1000_82544) {
5206 E1000_WRITE_REG(hw, WUC, 0);
5207 }
5208 return e1000_init_hw(nic);
5209}
5210
5211/**************************************************************************
5212DISABLE - Turn off ethernet interface
5213***************************************************************************/
5214static void
5215e1000_disable(struct eth_device *nic)
5216{
5217 struct e1000_hw *hw = nic->priv;
5218
5219 /* Turn off the ethernet interface */
5220 E1000_WRITE_REG(hw, RCTL, 0);
5221 E1000_WRITE_REG(hw, TCTL, 0);
5222
5223 /* Clear the transmit ring */
5224 E1000_WRITE_REG(hw, TDH, 0);
5225 E1000_WRITE_REG(hw, TDT, 0);
5226
5227 /* Clear the receive ring */
5228 E1000_WRITE_REG(hw, RDH, 0);
5229 E1000_WRITE_REG(hw, RDT, 0);
5230
5231 /* put the card in its initial state */
5232#if 0
5233 E1000_WRITE_REG(hw, CTRL, E1000_CTRL_RST);
5234#endif
5235 mdelay(10);
5236
5237}
5238
5239/**************************************************************************
5240INIT - set up ethernet interface(s)
5241***************************************************************************/
5242static int
5243e1000_init(struct eth_device *nic, bd_t * bis)
5244{
5245 struct e1000_hw *hw = nic->priv;
5246 int ret_val = 0;
5247
5248 ret_val = e1000_reset(nic);
5249 if (ret_val < 0) {
5250 if ((ret_val == -E1000_ERR_NOLINK) ||
5251 (ret_val == -E1000_ERR_TIMEOUT)) {
Kyle Moffett7b698d52011-10-18 11:05:26 +00005252 E1000_ERR(hw->nic, "Valid Link not detected\n");
wdenk4e112c12003-06-03 23:54:09 +00005253 } else {
Kyle Moffett7b698d52011-10-18 11:05:26 +00005254 E1000_ERR(hw->nic, "Hardware Initialization Failed\n");
wdenk4e112c12003-06-03 23:54:09 +00005255 }
5256 return 0;
5257 }
5258 e1000_configure_tx(hw);
5259 e1000_setup_rctl(hw);
5260 e1000_configure_rx(hw);
5261 return 1;
5262}
5263
Roy Zang28f7a052009-07-31 13:34:02 +08005264/******************************************************************************
5265 * Gets the current PCI bus type of hardware
5266 *
5267 * hw - Struct containing variables accessed by shared code
5268 *****************************************************************************/
5269void e1000_get_bus_type(struct e1000_hw *hw)
5270{
5271 uint32_t status;
5272
5273 switch (hw->mac_type) {
5274 case e1000_82542_rev2_0:
5275 case e1000_82542_rev2_1:
5276 hw->bus_type = e1000_bus_type_pci;
5277 break;
5278 case e1000_82571:
5279 case e1000_82572:
5280 case e1000_82573:
Roy Zang181119b2011-01-21 11:29:38 +08005281 case e1000_82574:
Roy Zang28f7a052009-07-31 13:34:02 +08005282 case e1000_80003es2lan:
Roy Zang28f7a052009-07-31 13:34:02 +08005283 case e1000_ich8lan:
Marek Vasut74a13c22014-08-08 07:41:39 -07005284 case e1000_igb:
Roy Zang28f7a052009-07-31 13:34:02 +08005285 hw->bus_type = e1000_bus_type_pci_express;
5286 break;
5287 default:
5288 status = E1000_READ_REG(hw, STATUS);
5289 hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
5290 e1000_bus_type_pcix : e1000_bus_type_pci;
5291 break;
5292 }
5293}
5294
Kyle Moffett64b94dd2011-10-18 11:05:29 +00005295/* A list of all registered e1000 devices */
5296static LIST_HEAD(e1000_hw_list);
5297
wdenk4e112c12003-06-03 23:54:09 +00005298/**************************************************************************
5299PROBE - Look for an adapter, this routine's visible to the outside
5300You should omit the last argument struct pci_device * for a non-PCI NIC
5301***************************************************************************/
5302int
5303e1000_initialize(bd_t * bis)
5304{
Kyle Moffett7b698d52011-10-18 11:05:26 +00005305 unsigned int i;
wdenk4e112c12003-06-03 23:54:09 +00005306 pci_dev_t devno;
wdenk4e112c12003-06-03 23:54:09 +00005307
Timur Tabiedc45b52009-08-17 15:55:38 -05005308 DEBUGFUNC();
5309
Kyle Moffett7b698d52011-10-18 11:05:26 +00005310 /* Find and probe all the matching PCI devices */
5311 for (i = 0; (devno = pci_find_devices(e1000_supported, i)) >= 0; i++) {
5312 u32 val;
Kumar Gala76933572010-11-12 04:13:06 -06005313
Kyle Moffett7b698d52011-10-18 11:05:26 +00005314 /*
5315 * These will never get freed due to errors, this allows us to
5316 * perform SPI EEPROM programming from U-boot, for example.
5317 */
5318 struct eth_device *nic = malloc(sizeof(*nic));
5319 struct e1000_hw *hw = malloc(sizeof(*hw));
5320 if (!nic || !hw) {
5321 printf("e1000#%u: Out of Memory!\n", i);
Kumar Gala76933572010-11-12 04:13:06 -06005322 free(nic);
Kyle Moffett7b698d52011-10-18 11:05:26 +00005323 free(hw);
5324 continue;
Kumar Gala76933572010-11-12 04:13:06 -06005325 }
5326
Kyle Moffett7b698d52011-10-18 11:05:26 +00005327 /* Make sure all of the fields are initially zeroed */
Matthew McClintock5761ce42010-11-15 18:02:53 -06005328 memset(nic, 0, sizeof(*nic));
Kumar Gala76933572010-11-12 04:13:06 -06005329 memset(hw, 0, sizeof(*hw));
5330
Kyle Moffett7b698d52011-10-18 11:05:26 +00005331 /* Assign the passed-in values */
5332 hw->cardnum = i;
wdenk4e112c12003-06-03 23:54:09 +00005333 hw->pdev = devno;
Kyle Moffett7b698d52011-10-18 11:05:26 +00005334 hw->nic = nic;
wdenk4e112c12003-06-03 23:54:09 +00005335 nic->priv = hw;
wdenk4e112c12003-06-03 23:54:09 +00005336
Kyle Moffett7b698d52011-10-18 11:05:26 +00005337 /* Generate a card name */
5338 sprintf(nic->name, "e1000#%u", hw->cardnum);
5339
5340 /* Print a debug message with the IO base address */
5341 pci_read_config_dword(devno, PCI_BASE_ADDRESS_0, &val);
5342 E1000_DBG(nic, "iobase 0x%08x\n", val & 0xfffffff0);
5343
5344 /* Try to enable I/O accesses and bus-mastering */
5345 val = PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER;
5346 pci_write_config_dword(devno, PCI_COMMAND, val);
5347
5348 /* Make sure it worked */
5349 pci_read_config_dword(devno, PCI_COMMAND, &val);
5350 if (!(val & PCI_COMMAND_MEMORY)) {
5351 E1000_ERR(nic, "Can't enable I/O memory\n");
5352 continue;
5353 }
5354 if (!(val & PCI_COMMAND_MASTER)) {
5355 E1000_ERR(nic, "Can't enable bus-mastering\n");
5356 continue;
5357 }
wdenk4e112c12003-06-03 23:54:09 +00005358
5359 /* Are these variables needed? */
wdenk4e112c12003-06-03 23:54:09 +00005360 hw->fc = e1000_fc_default;
5361 hw->original_fc = e1000_fc_default;
wdenk4e112c12003-06-03 23:54:09 +00005362 hw->autoneg_failed = 0;
Roy Zang28f7a052009-07-31 13:34:02 +08005363 hw->autoneg = 1;
York Sun4a598092013-04-01 11:29:11 -07005364 hw->get_link_status = true;
Marcel Ziswilera07e0ae2014-09-08 00:02:11 +02005365#ifndef CONFIG_E1000_NO_NVM
Marek Vasut74a13c22014-08-08 07:41:39 -07005366 hw->eeprom_semaphore_present = true;
Marcel Ziswilera07e0ae2014-09-08 00:02:11 +02005367#endif
Kyle Moffett7b698d52011-10-18 11:05:26 +00005368 hw->hw_addr = pci_map_bar(devno, PCI_BASE_ADDRESS_0,
5369 PCI_REGION_MEM);
wdenk4e112c12003-06-03 23:54:09 +00005370 hw->mac_type = e1000_undefined;
5371
5372 /* MAC and Phy settings */
Kyle Moffett7b698d52011-10-18 11:05:26 +00005373 if (e1000_sw_init(nic) < 0) {
5374 E1000_ERR(nic, "Software init failed\n");
5375 continue;
wdenk4e112c12003-06-03 23:54:09 +00005376 }
Roy Zang28f7a052009-07-31 13:34:02 +08005377 if (e1000_check_phy_reset_block(hw))
Kyle Moffett7b698d52011-10-18 11:05:26 +00005378 E1000_ERR(nic, "PHY Reset is blocked!\n");
5379
Kyle Moffett64b94dd2011-10-18 11:05:29 +00005380 /* Basic init was OK, reset the hardware and allow SPI access */
Roy Zang28f7a052009-07-31 13:34:02 +08005381 e1000_reset_hw(hw);
Kyle Moffett64b94dd2011-10-18 11:05:29 +00005382 list_add_tail(&hw->list_node, &e1000_hw_list);
Kyle Moffett7b698d52011-10-18 11:05:26 +00005383
Rojhalat Ibrahimbbcd2b02013-10-07 18:30:39 +02005384#ifndef CONFIG_E1000_NO_NVM
Kyle Moffett7b698d52011-10-18 11:05:26 +00005385 /* Validate the EEPROM and get chipset information */
Stefan Roesed47f07e2012-09-19 15:18:52 +02005386#if !defined(CONFIG_MVBC_1G)
Roy Zang28f7a052009-07-31 13:34:02 +08005387 if (e1000_init_eeprom_params(hw)) {
Kyle Moffett7b698d52011-10-18 11:05:26 +00005388 E1000_ERR(nic, "EEPROM is invalid!\n");
5389 continue;
Roy Zang28f7a052009-07-31 13:34:02 +08005390 }
Marek Vasut74a13c22014-08-08 07:41:39 -07005391 if ((E1000_READ_REG(hw, I210_EECD) & E1000_EECD_FLUPD) &&
5392 e1000_validate_eeprom_checksum(hw))
Kyle Moffett7b698d52011-10-18 11:05:26 +00005393 continue;
Wolfgang Denk56811f62005-10-09 01:04:33 +02005394#endif
wdenk4e112c12003-06-03 23:54:09 +00005395 e1000_read_mac_addr(nic);
Rojhalat Ibrahimbbcd2b02013-10-07 18:30:39 +02005396#endif
Roy Zang28f7a052009-07-31 13:34:02 +08005397 e1000_get_bus_type(hw);
wdenk4e112c12003-06-03 23:54:09 +00005398
Rojhalat Ibrahimbbcd2b02013-10-07 18:30:39 +02005399#ifndef CONFIG_E1000_NO_NVM
Kyle Moffett7b698d52011-10-18 11:05:26 +00005400 printf("e1000: %02x:%02x:%02x:%02x:%02x:%02x\n ",
wdenk4e112c12003-06-03 23:54:09 +00005401 nic->enetaddr[0], nic->enetaddr[1], nic->enetaddr[2],
5402 nic->enetaddr[3], nic->enetaddr[4], nic->enetaddr[5]);
Rojhalat Ibrahimbbcd2b02013-10-07 18:30:39 +02005403#else
5404 memset(nic->enetaddr, 0, 6);
5405 printf("e1000: no NVM\n");
5406#endif
wdenk4e112c12003-06-03 23:54:09 +00005407
Kyle Moffett7b698d52011-10-18 11:05:26 +00005408 /* Set up the function pointers and register the device */
wdenk4e112c12003-06-03 23:54:09 +00005409 nic->init = e1000_init;
5410 nic->recv = e1000_poll;
5411 nic->send = e1000_transmit;
5412 nic->halt = e1000_disable;
wdenk4e112c12003-06-03 23:54:09 +00005413 eth_register(nic);
wdenk4e112c12003-06-03 23:54:09 +00005414 }
Kyle Moffett7b698d52011-10-18 11:05:26 +00005415
5416 return i;
wdenk4e112c12003-06-03 23:54:09 +00005417}
Kyle Moffett64b94dd2011-10-18 11:05:29 +00005418
5419struct e1000_hw *e1000_find_card(unsigned int cardnum)
5420{
5421 struct e1000_hw *hw;
5422
5423 list_for_each_entry(hw, &e1000_hw_list, list_node)
5424 if (hw->cardnum == cardnum)
5425 return hw;
5426
5427 return NULL;
5428}
5429
5430#ifdef CONFIG_CMD_E1000
5431static int do_e1000(cmd_tbl_t *cmdtp, int flag,
5432 int argc, char * const argv[])
5433{
5434 struct e1000_hw *hw;
5435
5436 if (argc < 3) {
5437 cmd_usage(cmdtp);
5438 return 1;
5439 }
5440
5441 /* Make sure we can find the requested e1000 card */
5442 hw = e1000_find_card(simple_strtoul(argv[1], NULL, 10));
5443 if (!hw) {
5444 printf("e1000: ERROR: No such device: e1000#%s\n", argv[1]);
5445 return 1;
5446 }
5447
5448 if (!strcmp(argv[2], "print-mac-address")) {
5449 unsigned char *mac = hw->nic->enetaddr;
5450 printf("%02x:%02x:%02x:%02x:%02x:%02x\n",
5451 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
5452 return 0;
5453 }
5454
5455#ifdef CONFIG_E1000_SPI
5456 /* Handle the "SPI" subcommand */
5457 if (!strcmp(argv[2], "spi"))
5458 return do_e1000_spi(cmdtp, hw, argc - 3, argv + 3);
5459#endif
5460
5461 cmd_usage(cmdtp);
5462 return 1;
5463}
5464
5465U_BOOT_CMD(
5466 e1000, 7, 0, do_e1000,
5467 "Intel e1000 controller management",
5468 /* */"<card#> print-mac-address\n"
5469#ifdef CONFIG_E1000_SPI
5470 "e1000 <card#> spi show [<offset> [<length>]]\n"
5471 "e1000 <card#> spi dump <addr> <offset> <length>\n"
5472 "e1000 <card#> spi program <addr> <offset> <length>\n"
5473 "e1000 <card#> spi checksum [update]\n"
5474#endif
5475 " - Manage the Intel E1000 PCI device"
5476);
5477#endif /* not CONFIG_CMD_E1000 */