blob: cc50c26874f637cc38a26d2401203b26315fc201 [file] [log] [blame]
wdenk4e112c12003-06-03 23:54:09 +00001/**************************************************************************
2Inter Pro 1000 for ppcboot/das-u-boot
3Drivers 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
12 This program is free software; you can redistribute it and/or modify it
13 under the terms of the GNU General Public License as published by the Free
14 Software Foundation; either version 2 of the License, or (at your option)
wdenk4e112c12003-06-03 23:54:09 +000015 any later version.
wdenk57b2d802003-06-27 21:31:46 +000016
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
wdenk4e112c12003-06-03 23:54:09 +000020 more details.
wdenk57b2d802003-06-27 21:31:46 +000021
wdenk4e112c12003-06-03 23:54:09 +000022 You should have received a copy of the GNU General Public License along with
wdenk57b2d802003-06-27 21:31:46 +000023 this program; if not, write to the Free Software Foundation, Inc., 59
wdenk4e112c12003-06-03 23:54:09 +000024 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
wdenk57b2d802003-06-27 21:31:46 +000025
wdenk4e112c12003-06-03 23:54:09 +000026 The full GNU General Public License is included in this distribution in the
27 file called LICENSE.
wdenk57b2d802003-06-27 21:31:46 +000028
wdenk4e112c12003-06-03 23:54:09 +000029 Contact Information:
30 Linux NICS <linux.nics@intel.com>
31 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
32
33*******************************************************************************/
34/*
35 * Copyright (C) Archway Digital Solutions.
36 *
37 * written by Chrsitopher Li <cli at arcyway dot com> or <chrisl at gnuchina dot org>
38 * 2/9/2002
39 *
40 * Copyright (C) Linux Networx.
41 * Massive upgrade to work with the new intel gigabit NICs.
42 * <ebiederman at lnxi dot com>
43 */
44
45#include "e1000.h"
46
47#if (CONFIG_COMMANDS & CFG_CMD_NET) && defined(CONFIG_NET_MULTI) && \
48 defined(CONFIG_E1000)
49
50#define TOUT_LOOP 100000
51
52#undef virt_to_bus
53#define virt_to_bus(x) ((unsigned long)x)
54#define bus_to_phys(devno, a) pci_mem_to_phys(devno, a)
55#define mdelay(n) udelay((n)*1000)
56
57#define E1000_DEFAULT_PBA 0x00000030
58
59/* NIC specific static variables go here */
60
61static char tx_pool[128 + 16];
62static char rx_pool[128 + 16];
63static char packet[2096];
64
65static struct e1000_tx_desc *tx_base;
66static struct e1000_rx_desc *rx_base;
67
68static int tx_tail;
69static int rx_tail, rx_last;
70
71static struct pci_device_id supported[] = {
72 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82542},
73 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82543GC_FIBER},
74 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82543GC_COPPER},
75 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82544EI_COPPER},
76 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82544EI_FIBER},
77 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82544GC_COPPER},
78 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82544GC_LOM},
79 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82540EM},
80 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82545EM_COPPER},
81 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82546EB_COPPER},
82 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82545EM_FIBER},
83 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82546EB_FIBER},
84 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82540EM_LOM},
85};
86
87/* Function forward declarations */
88static int e1000_setup_link(struct eth_device *nic);
89static int e1000_setup_fiber_link(struct eth_device *nic);
90static int e1000_setup_copper_link(struct eth_device *nic);
91static int e1000_phy_setup_autoneg(struct e1000_hw *hw);
92static void e1000_config_collision_dist(struct e1000_hw *hw);
93static int e1000_config_mac_to_phy(struct e1000_hw *hw);
94static int e1000_config_fc_after_link_up(struct e1000_hw *hw);
95static int e1000_check_for_link(struct eth_device *nic);
96static int e1000_wait_autoneg(struct e1000_hw *hw);
97static void e1000_get_speed_and_duplex(struct e1000_hw *hw, uint16_t * speed,
98 uint16_t * duplex);
99static int e1000_read_phy_reg(struct e1000_hw *hw, uint32_t reg_addr,
100 uint16_t * phy_data);
101static int e1000_write_phy_reg(struct e1000_hw *hw, uint32_t reg_addr,
102 uint16_t phy_data);
103static void e1000_phy_hw_reset(struct e1000_hw *hw);
104static int e1000_phy_reset(struct e1000_hw *hw);
105static int e1000_detect_gig_phy(struct e1000_hw *hw);
106
107#define E1000_WRITE_REG(a, reg, value) (writel((value), ((a)->hw_addr + E1000_##reg)))
108#define E1000_READ_REG(a, reg) (readl((a)->hw_addr + E1000_##reg))
109#define E1000_WRITE_REG_ARRAY(a, reg, offset, value) (\
110 writel((value), ((a)->hw_addr + E1000_##reg + ((offset) << 2))))
111#define E1000_READ_REG_ARRAY(a, reg, offset) ( \
wdenk57b2d802003-06-27 21:31:46 +0000112 readl((a)->hw_addr + E1000_##reg + ((offset) << 2)))
wdenk4e112c12003-06-03 23:54:09 +0000113#define E1000_WRITE_FLUSH(a) {uint32_t x; x = E1000_READ_REG(a, STATUS);}
114
115/******************************************************************************
116 * Raises the EEPROM's clock input.
117 *
118 * hw - Struct containing variables accessed by shared code
119 * eecd - EECD's current value
120 *****************************************************************************/
121static void
122e1000_raise_ee_clk(struct e1000_hw *hw, uint32_t * eecd)
123{
124 /* Raise the clock input to the EEPROM (by setting the SK bit), and then
125 * wait 50 microseconds.
126 */
127 *eecd = *eecd | E1000_EECD_SK;
128 E1000_WRITE_REG(hw, EECD, *eecd);
129 E1000_WRITE_FLUSH(hw);
130 udelay(50);
131}
132
133/******************************************************************************
134 * Lowers the EEPROM's clock input.
135 *
wdenk57b2d802003-06-27 21:31:46 +0000136 * hw - Struct containing variables accessed by shared code
wdenk4e112c12003-06-03 23:54:09 +0000137 * eecd - EECD's current value
138 *****************************************************************************/
139static void
140e1000_lower_ee_clk(struct e1000_hw *hw, uint32_t * eecd)
141{
wdenk57b2d802003-06-27 21:31:46 +0000142 /* Lower the clock input to the EEPROM (by clearing the SK bit), and then
143 * wait 50 microseconds.
wdenk4e112c12003-06-03 23:54:09 +0000144 */
145 *eecd = *eecd & ~E1000_EECD_SK;
146 E1000_WRITE_REG(hw, EECD, *eecd);
147 E1000_WRITE_FLUSH(hw);
148 udelay(50);
149}
150
151/******************************************************************************
152 * Shift data bits out to the EEPROM.
153 *
154 * hw - Struct containing variables accessed by shared code
155 * data - data to send to the EEPROM
156 * count - number of bits to shift out
157 *****************************************************************************/
158static void
159e1000_shift_out_ee_bits(struct e1000_hw *hw, uint16_t data, uint16_t count)
160{
161 uint32_t eecd;
162 uint32_t mask;
163
164 /* We need to shift "count" bits out to the EEPROM. So, value in the
165 * "data" parameter will be shifted out to the EEPROM one bit at a time.
wdenk57b2d802003-06-27 21:31:46 +0000166 * In order to do this, "data" must be broken down into bits.
wdenk4e112c12003-06-03 23:54:09 +0000167 */
168 mask = 0x01 << (count - 1);
169 eecd = E1000_READ_REG(hw, EECD);
170 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
171 do {
172 /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
173 * and then raising and then lowering the clock (the SK bit controls
174 * the clock input to the EEPROM). A "0" is shifted out to the EEPROM
175 * by setting "DI" to "0" and then raising and then lowering the clock.
176 */
177 eecd &= ~E1000_EECD_DI;
178
179 if (data & mask)
180 eecd |= E1000_EECD_DI;
181
182 E1000_WRITE_REG(hw, EECD, eecd);
183 E1000_WRITE_FLUSH(hw);
184
185 udelay(50);
186
187 e1000_raise_ee_clk(hw, &eecd);
188 e1000_lower_ee_clk(hw, &eecd);
189
190 mask = mask >> 1;
191
192 } while (mask);
193
194 /* We leave the "DI" bit set to "0" when we leave this routine. */
195 eecd &= ~E1000_EECD_DI;
196 E1000_WRITE_REG(hw, EECD, eecd);
197}
198
199/******************************************************************************
200 * Shift data bits in from the EEPROM
201 *
202 * hw - Struct containing variables accessed by shared code
203 *****************************************************************************/
204static uint16_t
205e1000_shift_in_ee_bits(struct e1000_hw *hw)
206{
207 uint32_t eecd;
208 uint32_t i;
209 uint16_t data;
210
wdenk57b2d802003-06-27 21:31:46 +0000211 /* In order to read a register from the EEPROM, we need to shift 16 bits
wdenk4e112c12003-06-03 23:54:09 +0000212 * in from the EEPROM. Bits are "shifted in" by raising the clock input to
213 * the EEPROM (setting the SK bit), and then reading the value of the "DO"
wdenk57b2d802003-06-27 21:31:46 +0000214 * bit. During this "shifting in" process the "DI" bit should always be
wdenk4e112c12003-06-03 23:54:09 +0000215 * clear..
216 */
217
218 eecd = E1000_READ_REG(hw, EECD);
219
220 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
221 data = 0;
222
223 for (i = 0; i < 16; i++) {
224 data = data << 1;
225 e1000_raise_ee_clk(hw, &eecd);
226
227 eecd = E1000_READ_REG(hw, EECD);
228
229 eecd &= ~(E1000_EECD_DI);
230 if (eecd & E1000_EECD_DO)
231 data |= 1;
232
233 e1000_lower_ee_clk(hw, &eecd);
234 }
235
236 return data;
237}
238
239/******************************************************************************
240 * Prepares EEPROM for access
241 *
242 * hw - Struct containing variables accessed by shared code
243 *
wdenk57b2d802003-06-27 21:31:46 +0000244 * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
wdenk4e112c12003-06-03 23:54:09 +0000245 * function should be called before issuing a command to the EEPROM.
246 *****************************************************************************/
247static void
248e1000_setup_eeprom(struct e1000_hw *hw)
249{
250 uint32_t eecd;
251
252 eecd = E1000_READ_REG(hw, EECD);
253
254 /* Clear SK and DI */
255 eecd &= ~(E1000_EECD_SK | E1000_EECD_DI);
256 E1000_WRITE_REG(hw, EECD, eecd);
257
258 /* Set CS */
259 eecd |= E1000_EECD_CS;
260 E1000_WRITE_REG(hw, EECD, eecd);
261}
262
263/******************************************************************************
264 * Returns EEPROM to a "standby" state
wdenk57b2d802003-06-27 21:31:46 +0000265 *
wdenk4e112c12003-06-03 23:54:09 +0000266 * hw - Struct containing variables accessed by shared code
267 *****************************************************************************/
268static void
269e1000_standby_eeprom(struct e1000_hw *hw)
270{
271 uint32_t eecd;
272
273 eecd = E1000_READ_REG(hw, EECD);
274
275 /* Deselct EEPROM */
276 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
277 E1000_WRITE_REG(hw, EECD, eecd);
278 E1000_WRITE_FLUSH(hw);
279 udelay(50);
280
281 /* Clock high */
282 eecd |= E1000_EECD_SK;
283 E1000_WRITE_REG(hw, EECD, eecd);
284 E1000_WRITE_FLUSH(hw);
285 udelay(50);
286
287 /* Select EEPROM */
288 eecd |= E1000_EECD_CS;
289 E1000_WRITE_REG(hw, EECD, eecd);
290 E1000_WRITE_FLUSH(hw);
291 udelay(50);
292
293 /* Clock low */
294 eecd &= ~E1000_EECD_SK;
295 E1000_WRITE_REG(hw, EECD, eecd);
296 E1000_WRITE_FLUSH(hw);
297 udelay(50);
298}
299
300/******************************************************************************
301 * Reads a 16 bit word from the EEPROM.
302 *
303 * hw - Struct containing variables accessed by shared code
304 * offset - offset of word in the EEPROM to read
wdenk57b2d802003-06-27 21:31:46 +0000305 * data - word read from the EEPROM
wdenk4e112c12003-06-03 23:54:09 +0000306 *****************************************************************************/
307static int
308e1000_read_eeprom(struct e1000_hw *hw, uint16_t offset, uint16_t * data)
309{
310 uint32_t eecd;
311 uint32_t i = 0;
312 int large_eeprom = FALSE;
313
314 /* Request EEPROM Access */
315 if (hw->mac_type > e1000_82544) {
316 eecd = E1000_READ_REG(hw, EECD);
317 if (eecd & E1000_EECD_SIZE)
318 large_eeprom = TRUE;
319 eecd |= E1000_EECD_REQ;
320 E1000_WRITE_REG(hw, EECD, eecd);
321 eecd = E1000_READ_REG(hw, EECD);
322 while ((!(eecd & E1000_EECD_GNT)) && (i < 100)) {
323 i++;
324 udelay(10);
325 eecd = E1000_READ_REG(hw, EECD);
326 }
327 if (!(eecd & E1000_EECD_GNT)) {
328 eecd &= ~E1000_EECD_REQ;
329 E1000_WRITE_REG(hw, EECD, eecd);
330 DEBUGOUT("Could not acquire EEPROM grant\n");
331 return -E1000_ERR_EEPROM;
332 }
333 }
334
335 /* Prepare the EEPROM for reading */
336 e1000_setup_eeprom(hw);
337
338 /* Send the READ command (opcode + addr) */
339 e1000_shift_out_ee_bits(hw, EEPROM_READ_OPCODE, 3);
340 e1000_shift_out_ee_bits(hw, offset, (large_eeprom) ? 8 : 6);
341
342 /* Read the data */
343 *data = e1000_shift_in_ee_bits(hw);
344
345 /* End this read operation */
346 e1000_standby_eeprom(hw);
347
348 /* Stop requesting EEPROM access */
349 if (hw->mac_type > e1000_82544) {
350 eecd = E1000_READ_REG(hw, EECD);
351 eecd &= ~E1000_EECD_REQ;
352 E1000_WRITE_REG(hw, EECD, eecd);
353 }
354
355 return 0;
356}
357
358#if 0
359static void
360e1000_eeprom_cleanup(struct e1000_hw *hw)
361{
362 uint32_t eecd;
363
364 eecd = E1000_READ_REG(hw, EECD);
365 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
366 E1000_WRITE_REG(hw, EECD, eecd);
367 e1000_raise_ee_clk(hw, &eecd);
368 e1000_lower_ee_clk(hw, &eecd);
369}
370
371static uint16_t
372e1000_wait_eeprom_done(struct e1000_hw *hw)
373{
374 uint32_t eecd;
375 uint32_t i;
376
377 e1000_standby_eeprom(hw);
378 for (i = 0; i < 200; i++) {
379 eecd = E1000_READ_REG(hw, EECD);
380 if (eecd & E1000_EECD_DO)
381 return (TRUE);
382 udelay(5);
383 }
384 return (FALSE);
385}
386
387static int
388e1000_write_eeprom(struct e1000_hw *hw, uint16_t Reg, uint16_t Data)
389{
390 uint32_t eecd;
391 int large_eeprom = FALSE;
392 int i = 0;
393
394 /* Request EEPROM Access */
395 if (hw->mac_type > e1000_82544) {
396 eecd = E1000_READ_REG(hw, EECD);
397 if (eecd & E1000_EECD_SIZE)
398 large_eeprom = TRUE;
399 eecd |= E1000_EECD_REQ;
400 E1000_WRITE_REG(hw, EECD, eecd);
401 eecd = E1000_READ_REG(hw, EECD);
402 while ((!(eecd & E1000_EECD_GNT)) && (i < 100)) {
403 i++;
404 udelay(5);
405 eecd = E1000_READ_REG(hw, EECD);
406 }
407 if (!(eecd & E1000_EECD_GNT)) {
408 eecd &= ~E1000_EECD_REQ;
409 E1000_WRITE_REG(hw, EECD, eecd);
410 DEBUGOUT("Could not acquire EEPROM grant\n");
411 return FALSE;
412 }
413 }
414 e1000_setup_eeprom(hw);
415 e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE, 5);
416 e1000_shift_out_ee_bits(hw, Reg, (large_eeprom) ? 6 : 4);
417 e1000_standby_eeprom(hw);
418 e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE, 3);
419 e1000_shift_out_ee_bits(hw, Reg, (large_eeprom) ? 8 : 6);
420 e1000_shift_out_ee_bits(hw, Data, 16);
421 if (!e1000_wait_eeprom_done(hw)) {
422 return FALSE;
423 }
424 e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE, 5);
425 e1000_shift_out_ee_bits(hw, Reg, (large_eeprom) ? 6 : 4);
426 e1000_eeprom_cleanup(hw);
427
428 /* Stop requesting EEPROM access */
429 if (hw->mac_type > e1000_82544) {
430 eecd = E1000_READ_REG(hw, EECD);
431 eecd &= ~E1000_EECD_REQ;
432 E1000_WRITE_REG(hw, EECD, eecd);
433 }
434 i = 0;
435 eecd = E1000_READ_REG(hw, EECD);
436 while (((eecd & E1000_EECD_GNT)) && (i < 500)) {
437 i++;
438 udelay(10);
439 eecd = E1000_READ_REG(hw, EECD);
440 }
441 if ((eecd & E1000_EECD_GNT)) {
442 DEBUGOUT("Could not release EEPROM grant\n");
443 }
444 return TRUE;
445}
446#endif
447
448/******************************************************************************
449 * Verifies that the EEPROM has a valid checksum
wdenk57b2d802003-06-27 21:31:46 +0000450 *
wdenk4e112c12003-06-03 23:54:09 +0000451 * hw - Struct containing variables accessed by shared code
452 *
453 * Reads the first 64 16 bit words of the EEPROM and sums the values read.
454 * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
455 * valid.
456 *****************************************************************************/
457static int
458e1000_validate_eeprom_checksum(struct eth_device *nic)
459{
460 struct e1000_hw *hw = nic->priv;
461 uint16_t checksum = 0;
462 uint16_t i, eeprom_data;
463
464 DEBUGFUNC();
465
466 for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
467 if (e1000_read_eeprom(hw, i, &eeprom_data) < 0) {
468 DEBUGOUT("EEPROM Read Error\n");
469 return -E1000_ERR_EEPROM;
470 }
471 checksum += eeprom_data;
472 }
wdenk57b2d802003-06-27 21:31:46 +0000473
wdenk4e112c12003-06-03 23:54:09 +0000474 if (checksum == (uint16_t) EEPROM_SUM) {
475 return 0;
476 } else {
477 DEBUGOUT("EEPROM Checksum Invalid\n");
478 return -E1000_ERR_EEPROM;
479 }
480}
481
482/******************************************************************************
483 * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
484 * second function of dual function devices
485 *
486 * nic - Struct containing variables accessed by shared code
487 *****************************************************************************/
488static int
489e1000_read_mac_addr(struct eth_device *nic)
490{
491 struct e1000_hw *hw = nic->priv;
492 uint16_t offset;
493 uint16_t eeprom_data;
494 int i;
495
496 DEBUGFUNC();
497
498 for (i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
499 offset = i >> 1;
500 if (e1000_read_eeprom(hw, offset, &eeprom_data) < 0) {
501 DEBUGOUT("EEPROM Read Error\n");
502 return -E1000_ERR_EEPROM;
503 }
504 nic->enetaddr[i] = eeprom_data & 0xff;
505 nic->enetaddr[i + 1] = (eeprom_data >> 8) & 0xff;
506 }
507 if ((hw->mac_type == e1000_82546) &&
508 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
509 /* Invert the last bit if this is the second device */
510 nic->enetaddr[5] += 1;
511 }
512 return 0;
513}
514
515/******************************************************************************
516 * Initializes receive address filters.
517 *
wdenk57b2d802003-06-27 21:31:46 +0000518 * hw - Struct containing variables accessed by shared code
wdenk4e112c12003-06-03 23:54:09 +0000519 *
520 * Places the MAC address in receive address register 0 and clears the rest
521 * of the receive addresss registers. Clears the multicast table. Assumes
522 * the receiver is in reset when the routine is called.
523 *****************************************************************************/
524static void
525e1000_init_rx_addrs(struct eth_device *nic)
526{
527 struct e1000_hw *hw = nic->priv;
528 uint32_t i;
529 uint32_t addr_low;
530 uint32_t addr_high;
531
532 DEBUGFUNC();
533
534 /* Setup the receive address. */
535 DEBUGOUT("Programming MAC Address into RAR[0]\n");
536 addr_low = (nic->enetaddr[0] |
537 (nic->enetaddr[1] << 8) |
538 (nic->enetaddr[2] << 16) | (nic->enetaddr[3] << 24));
539
540 addr_high = (nic->enetaddr[4] | (nic->enetaddr[5] << 8) | E1000_RAH_AV);
541
542 E1000_WRITE_REG_ARRAY(hw, RA, 0, addr_low);
543 E1000_WRITE_REG_ARRAY(hw, RA, 1, addr_high);
544
545 /* Zero out the other 15 receive addresses. */
546 DEBUGOUT("Clearing RAR[1-15]\n");
547 for (i = 1; i < E1000_RAR_ENTRIES; i++) {
548 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
549 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
550 }
551}
552
553/******************************************************************************
554 * Clears the VLAN filer table
555 *
556 * hw - Struct containing variables accessed by shared code
557 *****************************************************************************/
558static void
559e1000_clear_vfta(struct e1000_hw *hw)
560{
561 uint32_t offset;
562
563 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++)
564 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, 0);
565}
566
567/******************************************************************************
568 * Set the mac type member in the hw struct.
wdenk57b2d802003-06-27 21:31:46 +0000569 *
wdenk4e112c12003-06-03 23:54:09 +0000570 * hw - Struct containing variables accessed by shared code
571 *****************************************************************************/
572static int
573e1000_set_mac_type(struct e1000_hw *hw)
574{
575 DEBUGFUNC();
576
577 switch (hw->device_id) {
578 case E1000_DEV_ID_82542:
579 switch (hw->revision_id) {
580 case E1000_82542_2_0_REV_ID:
581 hw->mac_type = e1000_82542_rev2_0;
582 break;
583 case E1000_82542_2_1_REV_ID:
584 hw->mac_type = e1000_82542_rev2_1;
585 break;
586 default:
587 /* Invalid 82542 revision ID */
588 return -E1000_ERR_MAC_TYPE;
589 }
590 break;
591 case E1000_DEV_ID_82543GC_FIBER:
592 case E1000_DEV_ID_82543GC_COPPER:
593 hw->mac_type = e1000_82543;
594 break;
595 case E1000_DEV_ID_82544EI_COPPER:
596 case E1000_DEV_ID_82544EI_FIBER:
597 case E1000_DEV_ID_82544GC_COPPER:
598 case E1000_DEV_ID_82544GC_LOM:
599 hw->mac_type = e1000_82544;
600 break;
601 case E1000_DEV_ID_82540EM:
602 case E1000_DEV_ID_82540EM_LOM:
603 hw->mac_type = e1000_82540;
604 break;
605 case E1000_DEV_ID_82545EM_COPPER:
606 case E1000_DEV_ID_82545EM_FIBER:
607 hw->mac_type = e1000_82545;
608 break;
609 case E1000_DEV_ID_82546EB_COPPER:
610 case E1000_DEV_ID_82546EB_FIBER:
611 hw->mac_type = e1000_82546;
612 break;
613 default:
614 /* Should never have loaded on this device */
615 return -E1000_ERR_MAC_TYPE;
616 }
617 return E1000_SUCCESS;
618}
619
620/******************************************************************************
621 * Reset the transmit and receive units; mask and clear all interrupts.
622 *
623 * hw - Struct containing variables accessed by shared code
624 *****************************************************************************/
625void
626e1000_reset_hw(struct e1000_hw *hw)
627{
628 uint32_t ctrl;
629 uint32_t ctrl_ext;
630 uint32_t icr;
631 uint32_t manc;
632
633 DEBUGFUNC();
634
635 /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
636 if (hw->mac_type == e1000_82542_rev2_0) {
637 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
638 pci_write_config_word(hw->pdev, PCI_COMMAND,
639 hw->
640 pci_cmd_word & ~PCI_COMMAND_INVALIDATE);
641 }
642
643 /* Clear interrupt mask to stop board from generating interrupts */
644 DEBUGOUT("Masking off all interrupts\n");
645 E1000_WRITE_REG(hw, IMC, 0xffffffff);
646
647 /* Disable the Transmit and Receive units. Then delay to allow
648 * any pending transactions to complete before we hit the MAC with
649 * the global reset.
650 */
651 E1000_WRITE_REG(hw, RCTL, 0);
652 E1000_WRITE_REG(hw, TCTL, E1000_TCTL_PSP);
653 E1000_WRITE_FLUSH(hw);
654
655 /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
656 hw->tbi_compatibility_on = FALSE;
657
658 /* Delay to allow any outstanding PCI transactions to complete before
659 * resetting the device
660 */
661 mdelay(10);
662
663 /* Issue a global reset to the MAC. This will reset the chip's
664 * transmit, receive, DMA, and link units. It will not effect
665 * the current PCI configuration. The global reset bit is self-
666 * clearing, and should clear within a microsecond.
667 */
668 DEBUGOUT("Issuing a global reset to MAC\n");
669 ctrl = E1000_READ_REG(hw, CTRL);
670
671#if 0
672 if (hw->mac_type > e1000_82543)
673 E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST));
674 else
675#endif
676 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
677
678 /* Force a reload from the EEPROM if necessary */
679 if (hw->mac_type < e1000_82540) {
680 /* Wait for reset to complete */
681 udelay(10);
682 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
683 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
684 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
685 E1000_WRITE_FLUSH(hw);
686 /* Wait for EEPROM reload */
687 mdelay(2);
688 } else {
689 /* Wait for EEPROM reload (it happens automatically) */
690 mdelay(4);
691 /* Dissable HW ARPs on ASF enabled adapters */
692 manc = E1000_READ_REG(hw, MANC);
693 manc &= ~(E1000_MANC_ARP_EN);
694 E1000_WRITE_REG(hw, MANC, manc);
695 }
696
697 /* Clear interrupt mask to stop board from generating interrupts */
698 DEBUGOUT("Masking off all interrupts\n");
699 E1000_WRITE_REG(hw, IMC, 0xffffffff);
700
701 /* Clear any pending interrupt events. */
702 icr = E1000_READ_REG(hw, ICR);
703
704 /* If MWI was previously enabled, reenable it. */
705 if (hw->mac_type == e1000_82542_rev2_0) {
706 pci_write_config_word(hw->pdev, PCI_COMMAND, hw->pci_cmd_word);
707 }
708}
709
710/******************************************************************************
711 * Performs basic configuration of the adapter.
712 *
713 * hw - Struct containing variables accessed by shared code
wdenk57b2d802003-06-27 21:31:46 +0000714 *
715 * Assumes that the controller has previously been reset and is in a
wdenk4e112c12003-06-03 23:54:09 +0000716 * post-reset uninitialized state. Initializes the receive address registers,
717 * multicast table, and VLAN filter table. Calls routines to setup link
718 * configuration and flow control settings. Clears all on-chip counters. Leaves
719 * the transmit and receive units disabled and uninitialized.
720 *****************************************************************************/
721static int
722e1000_init_hw(struct eth_device *nic)
723{
724 struct e1000_hw *hw = nic->priv;
725 uint32_t ctrl, status;
726 uint32_t i;
727 int32_t ret_val;
728 uint16_t pcix_cmd_word;
729 uint16_t pcix_stat_hi_word;
730 uint16_t cmd_mmrbc;
731 uint16_t stat_mmrbc;
732 e1000_bus_type bus_type = e1000_bus_type_unknown;
733
734 DEBUGFUNC();
735#if 0
736 /* Initialize Identification LED */
737 ret_val = e1000_id_led_init(hw);
738 if (ret_val < 0) {
739 DEBUGOUT("Error Initializing Identification LED\n");
740 return ret_val;
741 }
742#endif
743 /* Set the Media Type and exit with error if it is not valid. */
744 if (hw->mac_type != e1000_82543) {
745 /* tbi_compatibility is only valid on 82543 */
746 hw->tbi_compatibility_en = FALSE;
747 }
748
749 if (hw->mac_type >= e1000_82543) {
750 status = E1000_READ_REG(hw, STATUS);
751 if (status & E1000_STATUS_TBIMODE) {
752 hw->media_type = e1000_media_type_fiber;
753 /* tbi_compatibility not valid on fiber */
754 hw->tbi_compatibility_en = FALSE;
755 } else {
756 hw->media_type = e1000_media_type_copper;
757 }
758 } else {
759 /* This is an 82542 (fiber only) */
760 hw->media_type = e1000_media_type_fiber;
761 }
762
763 /* Disabling VLAN filtering. */
764 DEBUGOUT("Initializing the IEEE VLAN\n");
765 E1000_WRITE_REG(hw, VET, 0);
766
767 e1000_clear_vfta(hw);
768
769 /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
770 if (hw->mac_type == e1000_82542_rev2_0) {
771 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
772 pci_write_config_word(hw->pdev, PCI_COMMAND,
773 hw->
774 pci_cmd_word & ~PCI_COMMAND_INVALIDATE);
775 E1000_WRITE_REG(hw, RCTL, E1000_RCTL_RST);
776 E1000_WRITE_FLUSH(hw);
777 mdelay(5);
778 }
779
780 /* Setup the receive address. This involves initializing all of the Receive
781 * Address Registers (RARs 0 - 15).
782 */
783 e1000_init_rx_addrs(nic);
784
785 /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
786 if (hw->mac_type == e1000_82542_rev2_0) {
787 E1000_WRITE_REG(hw, RCTL, 0);
788 E1000_WRITE_FLUSH(hw);
789 mdelay(1);
790 pci_write_config_word(hw->pdev, PCI_COMMAND, hw->pci_cmd_word);
791 }
792
793 /* Zero out the Multicast HASH table */
794 DEBUGOUT("Zeroing the MTA\n");
795 for (i = 0; i < E1000_MC_TBL_SIZE; i++)
796 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
797
798#if 0
799 /* Set the PCI priority bit correctly in the CTRL register. This
800 * determines if the adapter gives priority to receives, or if it
801 * gives equal priority to transmits and receives.
802 */
803 if (hw->dma_fairness) {
804 ctrl = E1000_READ_REG(hw, CTRL);
805 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PRIOR);
806 }
807#endif
808 if (hw->mac_type >= e1000_82543) {
809 status = E1000_READ_REG(hw, STATUS);
810 bus_type = (status & E1000_STATUS_PCIX_MODE) ?
811 e1000_bus_type_pcix : e1000_bus_type_pci;
812 }
813 /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
814 if (bus_type == e1000_bus_type_pcix) {
815 pci_read_config_word(hw->pdev, PCIX_COMMAND_REGISTER,
816 &pcix_cmd_word);
817 pci_read_config_word(hw->pdev, PCIX_STATUS_REGISTER_HI,
818 &pcix_stat_hi_word);
819 cmd_mmrbc =
820 (pcix_cmd_word & PCIX_COMMAND_MMRBC_MASK) >>
821 PCIX_COMMAND_MMRBC_SHIFT;
822 stat_mmrbc =
823 (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >>
824 PCIX_STATUS_HI_MMRBC_SHIFT;
825 if (stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K)
826 stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K;
827 if (cmd_mmrbc > stat_mmrbc) {
828 pcix_cmd_word &= ~PCIX_COMMAND_MMRBC_MASK;
829 pcix_cmd_word |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT;
830 pci_write_config_word(hw->pdev, PCIX_COMMAND_REGISTER,
831 pcix_cmd_word);
832 }
833 }
834
835 /* Call a subroutine to configure the link and setup flow control. */
836 ret_val = e1000_setup_link(nic);
837
838 /* Set the transmit descriptor write-back policy */
839 if (hw->mac_type > e1000_82544) {
840 ctrl = E1000_READ_REG(hw, TXDCTL);
841 ctrl =
842 (ctrl & ~E1000_TXDCTL_WTHRESH) |
843 E1000_TXDCTL_FULL_TX_DESC_WB;
844 E1000_WRITE_REG(hw, TXDCTL, ctrl);
845 }
846#if 0
847 /* Clear all of the statistics registers (clear on read). It is
848 * important that we do this after we have tried to establish link
849 * because the symbol error count will increment wildly if there
850 * is no link.
851 */
852 e1000_clear_hw_cntrs(hw);
853#endif
854
855 return ret_val;
856}
857
858/******************************************************************************
859 * Configures flow control and link settings.
wdenk57b2d802003-06-27 21:31:46 +0000860 *
wdenk4e112c12003-06-03 23:54:09 +0000861 * hw - Struct containing variables accessed by shared code
wdenk57b2d802003-06-27 21:31:46 +0000862 *
wdenk4e112c12003-06-03 23:54:09 +0000863 * Determines which flow control settings to use. Calls the apropriate media-
864 * specific link configuration function. Configures the flow control settings.
865 * Assuming the adapter has a valid link partner, a valid link should be
wdenk57b2d802003-06-27 21:31:46 +0000866 * established. Assumes the hardware has previously been reset and the
wdenk4e112c12003-06-03 23:54:09 +0000867 * transmitter and receiver are not enabled.
868 *****************************************************************************/
869static int
870e1000_setup_link(struct eth_device *nic)
871{
872 struct e1000_hw *hw = nic->priv;
873 uint32_t ctrl_ext;
874 int32_t ret_val;
875 uint16_t eeprom_data;
876
877 DEBUGFUNC();
878
879 /* Read and store word 0x0F of the EEPROM. This word contains bits
880 * that determine the hardware's default PAUSE (flow control) mode,
881 * a bit that determines whether the HW defaults to enabling or
882 * disabling auto-negotiation, and the direction of the
883 * SW defined pins. If there is no SW over-ride of the flow
884 * control setting, then the variable hw->fc will
885 * be initialized based on a value in the EEPROM.
886 */
887 if (e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG, &eeprom_data) < 0) {
888 DEBUGOUT("EEPROM Read Error\n");
889 return -E1000_ERR_EEPROM;
890 }
891
892 if (hw->fc == e1000_fc_default) {
893 if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
894 hw->fc = e1000_fc_none;
895 else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
896 EEPROM_WORD0F_ASM_DIR)
897 hw->fc = e1000_fc_tx_pause;
898 else
899 hw->fc = e1000_fc_full;
900 }
901
902 /* We want to save off the original Flow Control configuration just
903 * in case we get disconnected and then reconnected into a different
904 * hub or switch with different Flow Control capabilities.
905 */
906 if (hw->mac_type == e1000_82542_rev2_0)
907 hw->fc &= (~e1000_fc_tx_pause);
908
909 if ((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
910 hw->fc &= (~e1000_fc_rx_pause);
911
912 hw->original_fc = hw->fc;
913
914 DEBUGOUT("After fix-ups FlowControl is now = %x\n", hw->fc);
915
916 /* Take the 4 bits from EEPROM word 0x0F that determine the initial
917 * polarity value for the SW controlled pins, and setup the
918 * Extended Device Control reg with that info.
919 * This is needed because one of the SW controlled pins is used for
920 * signal detection. So this should be done before e1000_setup_pcs_link()
921 * or e1000_phy_setup() is called.
922 */
923 if (hw->mac_type == e1000_82543) {
924 ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
925 SWDPIO__EXT_SHIFT);
926 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
927 }
928
929 /* Call the necessary subroutine to configure the link. */
930 ret_val = (hw->media_type == e1000_media_type_fiber) ?
931 e1000_setup_fiber_link(nic) : e1000_setup_copper_link(nic);
932 if (ret_val < 0) {
933 return ret_val;
934 }
935
936 /* Initialize the flow control address, type, and PAUSE timer
937 * registers to their default values. This is done even if flow
938 * control is disabled, because it does not hurt anything to
939 * initialize these registers.
940 */
941 DEBUGOUT
942 ("Initializing the Flow Control address, type and timer regs\n");
943
944 E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW);
945 E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH);
946 E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE);
947 E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time);
948
949 /* Set the flow control receive threshold registers. Normally,
950 * these registers will be set to a default threshold that may be
951 * adjusted later by the driver's runtime code. However, if the
952 * ability to transmit pause frames in not enabled, then these
wdenk57b2d802003-06-27 21:31:46 +0000953 * registers will be set to 0.
wdenk4e112c12003-06-03 23:54:09 +0000954 */
955 if (!(hw->fc & e1000_fc_tx_pause)) {
956 E1000_WRITE_REG(hw, FCRTL, 0);
957 E1000_WRITE_REG(hw, FCRTH, 0);
958 } else {
959 /* We need to set up the Receive Threshold high and low water marks
960 * as well as (optionally) enabling the transmission of XON frames.
961 */
962 if (hw->fc_send_xon) {
963 E1000_WRITE_REG(hw, FCRTL,
964 (hw->fc_low_water | E1000_FCRTL_XONE));
965 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
966 } else {
967 E1000_WRITE_REG(hw, FCRTL, hw->fc_low_water);
968 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
969 }
970 }
971 return ret_val;
972}
973
974/******************************************************************************
975 * Sets up link for a fiber based adapter
976 *
977 * hw - Struct containing variables accessed by shared code
978 *
979 * Manipulates Physical Coding Sublayer functions in order to configure
980 * link. Assumes the hardware has been previously reset and the transmitter
981 * and receiver are not enabled.
982 *****************************************************************************/
983static int
984e1000_setup_fiber_link(struct eth_device *nic)
985{
986 struct e1000_hw *hw = nic->priv;
987 uint32_t ctrl;
988 uint32_t status;
989 uint32_t txcw = 0;
990 uint32_t i;
991 uint32_t signal;
992 int32_t ret_val;
993
994 DEBUGFUNC();
wdenk57b2d802003-06-27 21:31:46 +0000995 /* On adapters with a MAC newer that 82544, SW Defineable pin 1 will be
996 * set when the optics detect a signal. On older adapters, it will be
wdenk4e112c12003-06-03 23:54:09 +0000997 * cleared when there is a signal
998 */
999 ctrl = E1000_READ_REG(hw, CTRL);
1000 if ((hw->mac_type > e1000_82544) && !(ctrl & E1000_CTRL_ILOS))
1001 signal = E1000_CTRL_SWDPIN1;
1002 else
1003 signal = 0;
1004
1005 printf("signal for %s is %x (ctrl %08x)!!!!\n", nic->name, signal,
1006 ctrl);
1007 /* Take the link out of reset */
1008 ctrl &= ~(E1000_CTRL_LRST);
1009
1010 e1000_config_collision_dist(hw);
1011
1012 /* Check for a software override of the flow control settings, and setup
1013 * the device accordingly. If auto-negotiation is enabled, then software
1014 * will have to set the "PAUSE" bits to the correct value in the Tranmsit
1015 * Config Word Register (TXCW) and re-start auto-negotiation. However, if
wdenk57b2d802003-06-27 21:31:46 +00001016 * auto-negotiation is disabled, then software will have to manually
wdenk4e112c12003-06-03 23:54:09 +00001017 * configure the two flow control enable bits in the CTRL register.
1018 *
1019 * The possible values of the "fc" parameter are:
1020 * 0: Flow control is completely disabled
wdenk57b2d802003-06-27 21:31:46 +00001021 * 1: Rx flow control is enabled (we can receive pause frames, but
wdenk4e112c12003-06-03 23:54:09 +00001022 * not send pause frames).
1023 * 2: Tx flow control is enabled (we can send pause frames but we do
1024 * not support receiving pause frames).
1025 * 3: Both Rx and TX flow control (symmetric) are enabled.
1026 */
1027 switch (hw->fc) {
1028 case e1000_fc_none:
1029 /* Flow control is completely disabled by a software over-ride. */
1030 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
1031 break;
1032 case e1000_fc_rx_pause:
wdenk57b2d802003-06-27 21:31:46 +00001033 /* RX Flow control is enabled and TX Flow control is disabled by a
1034 * software over-ride. Since there really isn't a way to advertise
wdenk4e112c12003-06-03 23:54:09 +00001035 * that we are capable of RX Pause ONLY, we will advertise that we
1036 * support both symmetric and asymmetric RX PAUSE. Later, we will
1037 * disable the adapter's ability to send PAUSE frames.
1038 */
1039 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1040 break;
1041 case e1000_fc_tx_pause:
wdenk57b2d802003-06-27 21:31:46 +00001042 /* TX Flow control is enabled, and RX Flow control is disabled, by a
wdenk4e112c12003-06-03 23:54:09 +00001043 * software over-ride.
1044 */
1045 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
1046 break;
1047 case e1000_fc_full:
1048 /* Flow control (both RX and TX) is enabled by a software over-ride. */
1049 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1050 break;
1051 default:
1052 DEBUGOUT("Flow control param set incorrectly\n");
1053 return -E1000_ERR_CONFIG;
1054 break;
1055 }
1056
1057 /* Since auto-negotiation is enabled, take the link out of reset (the link
1058 * will be in reset, because we previously reset the chip). This will
1059 * restart auto-negotiation. If auto-neogtiation is successful then the
1060 * link-up status bit will be set and the flow control enable bits (RFCE
1061 * and TFCE) will be set according to their negotiated value.
1062 */
1063 DEBUGOUT("Auto-negotiation enabled (%#x)\n", txcw);
1064
1065 E1000_WRITE_REG(hw, TXCW, txcw);
1066 E1000_WRITE_REG(hw, CTRL, ctrl);
1067 E1000_WRITE_FLUSH(hw);
1068
1069 hw->txcw = txcw;
1070 mdelay(1);
1071
1072 /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
wdenk57b2d802003-06-27 21:31:46 +00001073 * indication in the Device Status Register. Time-out if a link isn't
1074 * seen in 500 milliseconds seconds (Auto-negotiation should complete in
wdenk4e112c12003-06-03 23:54:09 +00001075 * less than 500 milliseconds even if the other end is doing it in SW).
1076 */
1077 if ((E1000_READ_REG(hw, CTRL) & E1000_CTRL_SWDPIN1) == signal) {
1078 DEBUGOUT("Looking for Link\n");
1079 for (i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
1080 mdelay(10);
1081 status = E1000_READ_REG(hw, STATUS);
1082 if (status & E1000_STATUS_LU)
1083 break;
1084 }
1085 if (i == (LINK_UP_TIMEOUT / 10)) {
wdenk57b2d802003-06-27 21:31:46 +00001086 /* AutoNeg failed to achieve a link, so we'll call
wdenk4e112c12003-06-03 23:54:09 +00001087 * e1000_check_for_link. This routine will force the link up if we
1088 * detect a signal. This will allow us to communicate with
1089 * non-autonegotiating link partners.
1090 */
1091 DEBUGOUT("Never got a valid link from auto-neg!!!\n");
1092 hw->autoneg_failed = 1;
1093 ret_val = e1000_check_for_link(nic);
1094 if (ret_val < 0) {
1095 DEBUGOUT("Error while checking for link\n");
1096 return ret_val;
1097 }
1098 hw->autoneg_failed = 0;
1099 } else {
1100 hw->autoneg_failed = 0;
1101 DEBUGOUT("Valid Link Found\n");
1102 }
1103 } else {
1104 DEBUGOUT("No Signal Detected\n");
1105 return -E1000_ERR_NOLINK;
1106 }
1107 return 0;
1108}
1109
1110/******************************************************************************
1111* Detects which PHY is present and the speed and duplex
1112*
1113* hw - Struct containing variables accessed by shared code
1114******************************************************************************/
1115static int
1116e1000_setup_copper_link(struct eth_device *nic)
1117{
1118 struct e1000_hw *hw = nic->priv;
1119 uint32_t ctrl;
1120 int32_t ret_val;
1121 uint16_t i;
1122 uint16_t phy_data;
1123
1124 DEBUGFUNC();
1125
1126 ctrl = E1000_READ_REG(hw, CTRL);
1127 /* With 82543, we need to force speed and duplex on the MAC equal to what
1128 * the PHY speed and duplex configuration is. In addition, we need to
1129 * perform a hardware reset on the PHY to take it out of reset.
1130 */
1131 if (hw->mac_type > e1000_82543) {
1132 ctrl |= E1000_CTRL_SLU;
1133 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1134 E1000_WRITE_REG(hw, CTRL, ctrl);
1135 } else {
1136 ctrl |=
1137 (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU);
1138 E1000_WRITE_REG(hw, CTRL, ctrl);
1139 e1000_phy_hw_reset(hw);
1140 }
1141
1142 /* Make sure we have a valid PHY */
1143 ret_val = e1000_detect_gig_phy(hw);
1144 if (ret_val < 0) {
1145 DEBUGOUT("Error, did not detect valid phy.\n");
1146 return ret_val;
1147 }
1148 DEBUGOUT("Phy ID = %x \n", hw->phy_id);
1149
1150 /* Enable CRS on TX. This must be set for half-duplex operation. */
1151 if (e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data) < 0) {
1152 DEBUGOUT("PHY Read Error\n");
1153 return -E1000_ERR_PHY;
1154 }
1155 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1156
1157#if 0
1158 /* Options:
1159 * MDI/MDI-X = 0 (default)
1160 * 0 - Auto for all speeds
1161 * 1 - MDI mode
1162 * 2 - MDI-X mode
1163 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1164 */
1165 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1166 switch (hw->mdix) {
1167 case 1:
1168 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
1169 break;
1170 case 2:
1171 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
1172 break;
1173 case 3:
1174 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
1175 break;
1176 case 0:
1177 default:
1178 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
1179 break;
1180 }
1181#else
1182 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
1183#endif
1184
1185#if 0
1186 /* Options:
1187 * disable_polarity_correction = 0 (default)
1188 * Automatic Correction for Reversed Cable Polarity
1189 * 0 - Disabled
1190 * 1 - Enabled
1191 */
1192 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
1193 if (hw->disable_polarity_correction == 1)
1194 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
1195#else
1196 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
1197#endif
1198 if (e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data) < 0) {
1199 DEBUGOUT("PHY Write Error\n");
1200 return -E1000_ERR_PHY;
1201 }
1202
1203 /* Force TX_CLK in the Extended PHY Specific Control Register
1204 * to 25MHz clock.
1205 */
1206 if (e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data) < 0) {
1207 DEBUGOUT("PHY Read Error\n");
1208 return -E1000_ERR_PHY;
1209 }
1210 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1211 /* Configure Master and Slave downshift values */
1212 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
1213 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
1214 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
1215 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
1216 if (e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data) < 0) {
1217 DEBUGOUT("PHY Write Error\n");
1218 return -E1000_ERR_PHY;
1219 }
1220
1221 /* SW Reset the PHY so all changes take effect */
1222 ret_val = e1000_phy_reset(hw);
1223 if (ret_val < 0) {
1224 DEBUGOUT("Error Resetting the PHY\n");
1225 return ret_val;
1226 }
1227
1228 /* Options:
1229 * autoneg = 1 (default)
1230 * PHY will advertise value(s) parsed from
1231 * autoneg_advertised and fc
1232 * autoneg = 0
1233 * PHY will be set to 10H, 10F, 100H, or 100F
1234 * depending on value parsed from forced_speed_duplex.
1235 */
1236
1237 /* Is autoneg enabled? This is enabled by default or by software override.
1238 * If so, call e1000_phy_setup_autoneg routine to parse the
1239 * autoneg_advertised and fc options. If autoneg is NOT enabled, then the
1240 * user should have provided a speed/duplex override. If so, then call
1241 * e1000_phy_force_speed_duplex to parse and set this up.
1242 */
1243 /* Perform some bounds checking on the hw->autoneg_advertised
1244 * parameter. If this variable is zero, then set it to the default.
1245 */
1246 hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
1247
1248 /* If autoneg_advertised is zero, we assume it was not defaulted
1249 * by the calling code so we set to advertise full capability.
1250 */
1251 if (hw->autoneg_advertised == 0)
1252 hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
1253
1254 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
1255 ret_val = e1000_phy_setup_autoneg(hw);
1256 if (ret_val < 0) {
1257 DEBUGOUT("Error Setting up Auto-Negotiation\n");
1258 return ret_val;
1259 }
1260 DEBUGOUT("Restarting Auto-Neg\n");
1261
1262 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
1263 * the Auto Neg Restart bit in the PHY control register.
1264 */
1265 if (e1000_read_phy_reg(hw, PHY_CTRL, &phy_data) < 0) {
1266 DEBUGOUT("PHY Read Error\n");
1267 return -E1000_ERR_PHY;
1268 }
1269 phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
1270 if (e1000_write_phy_reg(hw, PHY_CTRL, phy_data) < 0) {
1271 DEBUGOUT("PHY Write Error\n");
1272 return -E1000_ERR_PHY;
1273 }
1274#if 0
1275 /* Does the user want to wait for Auto-Neg to complete here, or
1276 * check at a later time (for example, callback routine).
1277 */
1278 if (hw->wait_autoneg_complete) {
1279 ret_val = e1000_wait_autoneg(hw);
1280 if (ret_val < 0) {
1281 DEBUGOUT
1282 ("Error while waiting for autoneg to complete\n");
1283 return ret_val;
1284 }
1285 }
1286#else
wdenk57b2d802003-06-27 21:31:46 +00001287 /* If we do not wait for autonegtation to complete I
wdenk4e112c12003-06-03 23:54:09 +00001288 * do not see a valid link status.
1289 */
1290 ret_val = e1000_wait_autoneg(hw);
1291 if (ret_val < 0) {
1292 DEBUGOUT("Error while waiting for autoneg to complete\n");
1293 return ret_val;
1294 }
1295#endif
1296
1297 /* Check link status. Wait up to 100 microseconds for link to become
1298 * valid.
1299 */
1300 for (i = 0; i < 10; i++) {
1301 if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
1302 DEBUGOUT("PHY Read Error\n");
1303 return -E1000_ERR_PHY;
1304 }
1305 if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
1306 DEBUGOUT("PHY Read Error\n");
1307 return -E1000_ERR_PHY;
1308 }
1309 if (phy_data & MII_SR_LINK_STATUS) {
1310 /* We have link, so we need to finish the config process:
1311 * 1) Set up the MAC to the current PHY speed/duplex
1312 * if we are on 82543. If we
1313 * are on newer silicon, we only need to configure
1314 * collision distance in the Transmit Control Register.
1315 * 2) Set up flow control on the MAC to that established with
1316 * the link partner.
1317 */
1318 if (hw->mac_type >= e1000_82544) {
1319 e1000_config_collision_dist(hw);
1320 } else {
1321 ret_val = e1000_config_mac_to_phy(hw);
1322 if (ret_val < 0) {
1323 DEBUGOUT
1324 ("Error configuring MAC to PHY settings\n");
1325 return ret_val;
1326 }
1327 }
1328 ret_val = e1000_config_fc_after_link_up(hw);
1329 if (ret_val < 0) {
1330 DEBUGOUT("Error Configuring Flow Control\n");
1331 return ret_val;
1332 }
1333 DEBUGOUT("Valid link established!!!\n");
1334 return 0;
1335 }
1336 udelay(10);
1337 }
1338
1339 DEBUGOUT("Unable to establish link!!!\n");
1340 return -E1000_ERR_NOLINK;
1341}
1342
1343/******************************************************************************
1344* Configures PHY autoneg and flow control advertisement settings
1345*
1346* hw - Struct containing variables accessed by shared code
1347******************************************************************************/
1348static int
1349e1000_phy_setup_autoneg(struct e1000_hw *hw)
1350{
1351 uint16_t mii_autoneg_adv_reg;
1352 uint16_t mii_1000t_ctrl_reg;
1353
1354 DEBUGFUNC();
1355
1356 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
1357 if (e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg) < 0) {
1358 DEBUGOUT("PHY Read Error\n");
1359 return -E1000_ERR_PHY;
1360 }
1361
1362 /* Read the MII 1000Base-T Control Register (Address 9). */
1363 if (e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg) < 0) {
1364 DEBUGOUT("PHY Read Error\n");
1365 return -E1000_ERR_PHY;
1366 }
1367
1368 /* Need to parse both autoneg_advertised and fc and set up
1369 * the appropriate PHY registers. First we will parse for
1370 * autoneg_advertised software override. Since we can advertise
1371 * a plethora of combinations, we need to check each bit
1372 * individually.
1373 */
1374
1375 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
1376 * Advertisement Register (Address 4) and the 1000 mb speed bits in
1377 * the 1000Base-T Control Register (Address 9).
1378 */
1379 mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
1380 mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
1381
1382 DEBUGOUT("autoneg_advertised %x\n", hw->autoneg_advertised);
1383
1384 /* Do we want to advertise 10 Mb Half Duplex? */
1385 if (hw->autoneg_advertised & ADVERTISE_10_HALF) {
1386 DEBUGOUT("Advertise 10mb Half duplex\n");
1387 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
1388 }
1389
1390 /* Do we want to advertise 10 Mb Full Duplex? */
1391 if (hw->autoneg_advertised & ADVERTISE_10_FULL) {
1392 DEBUGOUT("Advertise 10mb Full duplex\n");
1393 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
1394 }
1395
1396 /* Do we want to advertise 100 Mb Half Duplex? */
1397 if (hw->autoneg_advertised & ADVERTISE_100_HALF) {
1398 DEBUGOUT("Advertise 100mb Half duplex\n");
1399 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
1400 }
1401
1402 /* Do we want to advertise 100 Mb Full Duplex? */
1403 if (hw->autoneg_advertised & ADVERTISE_100_FULL) {
1404 DEBUGOUT("Advertise 100mb Full duplex\n");
1405 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
1406 }
1407
1408 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
1409 if (hw->autoneg_advertised & ADVERTISE_1000_HALF) {
1410 DEBUGOUT
1411 ("Advertise 1000mb Half duplex requested, request denied!\n");
1412 }
1413
1414 /* Do we want to advertise 1000 Mb Full Duplex? */
1415 if (hw->autoneg_advertised & ADVERTISE_1000_FULL) {
1416 DEBUGOUT("Advertise 1000mb Full duplex\n");
1417 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
1418 }
1419
1420 /* Check for a software override of the flow control settings, and
1421 * setup the PHY advertisement registers accordingly. If
1422 * auto-negotiation is enabled, then software will have to set the
1423 * "PAUSE" bits to the correct value in the Auto-Negotiation
1424 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
1425 *
1426 * The possible values of the "fc" parameter are:
1427 * 0: Flow control is completely disabled
1428 * 1: Rx flow control is enabled (we can receive pause frames
1429 * but not send pause frames).
1430 * 2: Tx flow control is enabled (we can send pause frames
1431 * but we do not support receiving pause frames).
1432 * 3: Both Rx and TX flow control (symmetric) are enabled.
1433 * other: No software override. The flow control configuration
1434 * in the EEPROM is used.
1435 */
1436 switch (hw->fc) {
1437 case e1000_fc_none: /* 0 */
1438 /* Flow control (RX & TX) is completely disabled by a
1439 * software over-ride.
1440 */
1441 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1442 break;
1443 case e1000_fc_rx_pause: /* 1 */
1444 /* RX Flow control is enabled, and TX Flow control is
1445 * disabled, by a software over-ride.
1446 */
1447 /* Since there really isn't a way to advertise that we are
1448 * capable of RX Pause ONLY, we will advertise that we
1449 * support both symmetric and asymmetric RX PAUSE. Later
1450 * (in e1000_config_fc_after_link_up) we will disable the
1451 *hw's ability to send PAUSE frames.
1452 */
1453 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1454 break;
1455 case e1000_fc_tx_pause: /* 2 */
1456 /* TX Flow control is enabled, and RX Flow control is
1457 * disabled, by a software over-ride.
1458 */
1459 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
1460 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
1461 break;
1462 case e1000_fc_full: /* 3 */
1463 /* Flow control (both RX and TX) is enabled by a software
1464 * over-ride.
1465 */
1466 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1467 break;
1468 default:
1469 DEBUGOUT("Flow control param set incorrectly\n");
1470 return -E1000_ERR_CONFIG;
1471 }
1472
1473 if (e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg) < 0) {
1474 DEBUGOUT("PHY Write Error\n");
1475 return -E1000_ERR_PHY;
1476 }
1477
1478 DEBUGOUT("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
1479
1480 if (e1000_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg) < 0) {
1481 DEBUGOUT("PHY Write Error\n");
1482 return -E1000_ERR_PHY;
1483 }
1484 return 0;
1485}
1486
1487/******************************************************************************
1488* Sets the collision distance in the Transmit Control register
1489*
1490* hw - Struct containing variables accessed by shared code
1491*
1492* Link should have been established previously. Reads the speed and duplex
1493* information from the Device Status register.
1494******************************************************************************/
1495static void
1496e1000_config_collision_dist(struct e1000_hw *hw)
1497{
1498 uint32_t tctl;
1499
1500 tctl = E1000_READ_REG(hw, TCTL);
1501
1502 tctl &= ~E1000_TCTL_COLD;
1503 tctl |= E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT;
1504
1505 E1000_WRITE_REG(hw, TCTL, tctl);
1506 E1000_WRITE_FLUSH(hw);
1507}
1508
1509/******************************************************************************
1510* Sets MAC speed and duplex settings to reflect the those in the PHY
1511*
1512* hw - Struct containing variables accessed by shared code
1513* mii_reg - data to write to the MII control register
1514*
1515* The contents of the PHY register containing the needed information need to
1516* be passed in.
1517******************************************************************************/
1518static int
1519e1000_config_mac_to_phy(struct e1000_hw *hw)
1520{
1521 uint32_t ctrl;
1522 uint16_t phy_data;
1523
1524 DEBUGFUNC();
1525
1526 /* Read the Device Control Register and set the bits to Force Speed
1527 * and Duplex.
1528 */
1529 ctrl = E1000_READ_REG(hw, CTRL);
1530 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1531 ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
1532
1533 /* Set up duplex in the Device Control and Transmit Control
1534 * registers depending on negotiated values.
1535 */
1536 if (e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data) < 0) {
1537 DEBUGOUT("PHY Read Error\n");
1538 return -E1000_ERR_PHY;
1539 }
1540 if (phy_data & M88E1000_PSSR_DPLX)
1541 ctrl |= E1000_CTRL_FD;
1542 else
1543 ctrl &= ~E1000_CTRL_FD;
1544
1545 e1000_config_collision_dist(hw);
1546
1547 /* Set up speed in the Device Control register depending on
1548 * negotiated values.
1549 */
1550 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
1551 ctrl |= E1000_CTRL_SPD_1000;
1552 else if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
1553 ctrl |= E1000_CTRL_SPD_100;
1554 /* Write the configured values back to the Device Control Reg. */
1555 E1000_WRITE_REG(hw, CTRL, ctrl);
1556 return 0;
1557}
1558
1559/******************************************************************************
1560 * Forces the MAC's flow control settings.
wdenk57b2d802003-06-27 21:31:46 +00001561 *
wdenk4e112c12003-06-03 23:54:09 +00001562 * hw - Struct containing variables accessed by shared code
1563 *
1564 * Sets the TFCE and RFCE bits in the device control register to reflect
1565 * the adapter settings. TFCE and RFCE need to be explicitly set by
1566 * software when a Copper PHY is used because autonegotiation is managed
1567 * by the PHY rather than the MAC. Software must also configure these
1568 * bits when link is forced on a fiber connection.
1569 *****************************************************************************/
1570static int
1571e1000_force_mac_fc(struct e1000_hw *hw)
1572{
1573 uint32_t ctrl;
1574
1575 DEBUGFUNC();
1576
1577 /* Get the current configuration of the Device Control Register */
1578 ctrl = E1000_READ_REG(hw, CTRL);
1579
1580 /* Because we didn't get link via the internal auto-negotiation
1581 * mechanism (we either forced link or we got link via PHY
1582 * auto-neg), we have to manually enable/disable transmit an
1583 * receive flow control.
1584 *
1585 * The "Case" statement below enables/disable flow control
1586 * according to the "hw->fc" parameter.
1587 *
1588 * The possible values of the "fc" parameter are:
1589 * 0: Flow control is completely disabled
1590 * 1: Rx flow control is enabled (we can receive pause
1591 * frames but not send pause frames).
1592 * 2: Tx flow control is enabled (we can send pause frames
1593 * frames but we do not receive pause frames).
1594 * 3: Both Rx and TX flow control (symmetric) is enabled.
1595 * other: No other values should be possible at this point.
1596 */
1597
1598 switch (hw->fc) {
1599 case e1000_fc_none:
1600 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
1601 break;
1602 case e1000_fc_rx_pause:
1603 ctrl &= (~E1000_CTRL_TFCE);
1604 ctrl |= E1000_CTRL_RFCE;
1605 break;
1606 case e1000_fc_tx_pause:
1607 ctrl &= (~E1000_CTRL_RFCE);
1608 ctrl |= E1000_CTRL_TFCE;
1609 break;
1610 case e1000_fc_full:
1611 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
1612 break;
1613 default:
1614 DEBUGOUT("Flow control param set incorrectly\n");
1615 return -E1000_ERR_CONFIG;
1616 }
1617
1618 /* Disable TX Flow Control for 82542 (rev 2.0) */
1619 if (hw->mac_type == e1000_82542_rev2_0)
1620 ctrl &= (~E1000_CTRL_TFCE);
1621
1622 E1000_WRITE_REG(hw, CTRL, ctrl);
1623 return 0;
1624}
1625
1626/******************************************************************************
1627 * Configures flow control settings after link is established
wdenk57b2d802003-06-27 21:31:46 +00001628 *
wdenk4e112c12003-06-03 23:54:09 +00001629 * hw - Struct containing variables accessed by shared code
1630 *
1631 * Should be called immediately after a valid link has been established.
1632 * Forces MAC flow control settings if link was forced. When in MII/GMII mode
1633 * and autonegotiation is enabled, the MAC flow control settings will be set
1634 * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
1635 * and RFCE bits will be automaticaly set to the negotiated flow control mode.
1636 *****************************************************************************/
1637static int
1638e1000_config_fc_after_link_up(struct e1000_hw *hw)
1639{
1640 int32_t ret_val;
1641 uint16_t mii_status_reg;
1642 uint16_t mii_nway_adv_reg;
1643 uint16_t mii_nway_lp_ability_reg;
1644 uint16_t speed;
1645 uint16_t duplex;
1646
1647 DEBUGFUNC();
1648
1649 /* Check for the case where we have fiber media and auto-neg failed
1650 * so we had to force link. In this case, we need to force the
1651 * configuration of the MAC to match the "fc" parameter.
1652 */
1653 if ((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed)) {
1654 ret_val = e1000_force_mac_fc(hw);
1655 if (ret_val < 0) {
1656 DEBUGOUT("Error forcing flow control settings\n");
1657 return ret_val;
1658 }
1659 }
1660
1661 /* Check for the case where we have copper media and auto-neg is
1662 * enabled. In this case, we need to check and see if Auto-Neg
1663 * has completed, and if so, how the PHY and link partner has
1664 * flow control configured.
1665 */
1666 if (hw->media_type == e1000_media_type_copper) {
1667 /* Read the MII Status Register and check to see if AutoNeg
1668 * has completed. We read this twice because this reg has
1669 * some "sticky" (latched) bits.
1670 */
1671 if (e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg) < 0) {
1672 DEBUGOUT("PHY Read Error \n");
1673 return -E1000_ERR_PHY;
1674 }
1675 if (e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg) < 0) {
1676 DEBUGOUT("PHY Read Error \n");
1677 return -E1000_ERR_PHY;
1678 }
1679
1680 if (mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
1681 /* The AutoNeg process has completed, so we now need to
1682 * read both the Auto Negotiation Advertisement Register
1683 * (Address 4) and the Auto_Negotiation Base Page Ability
1684 * Register (Address 5) to determine how flow control was
1685 * negotiated.
1686 */
1687 if (e1000_read_phy_reg
1688 (hw, PHY_AUTONEG_ADV, &mii_nway_adv_reg) < 0) {
1689 DEBUGOUT("PHY Read Error\n");
1690 return -E1000_ERR_PHY;
1691 }
1692 if (e1000_read_phy_reg
1693 (hw, PHY_LP_ABILITY,
1694 &mii_nway_lp_ability_reg) < 0) {
1695 DEBUGOUT("PHY Read Error\n");
1696 return -E1000_ERR_PHY;
1697 }
1698
1699 /* Two bits in the Auto Negotiation Advertisement Register
1700 * (Address 4) and two bits in the Auto Negotiation Base
1701 * Page Ability Register (Address 5) determine flow control
1702 * for both the PHY and the link partner. The following
1703 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
1704 * 1999, describes these PAUSE resolution bits and how flow
1705 * control is determined based upon these settings.
1706 * NOTE: DC = Don't Care
1707 *
1708 * LOCAL DEVICE | LINK PARTNER
1709 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
1710 *-------|---------|-------|---------|--------------------
1711 * 0 | 0 | DC | DC | e1000_fc_none
1712 * 0 | 1 | 0 | DC | e1000_fc_none
1713 * 0 | 1 | 1 | 0 | e1000_fc_none
1714 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
1715 * 1 | 0 | 0 | DC | e1000_fc_none
1716 * 1 | DC | 1 | DC | e1000_fc_full
1717 * 1 | 1 | 0 | 0 | e1000_fc_none
1718 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
1719 *
1720 */
1721 /* Are both PAUSE bits set to 1? If so, this implies
1722 * Symmetric Flow Control is enabled at both ends. The
1723 * ASM_DIR bits are irrelevant per the spec.
1724 *
1725 * For Symmetric Flow Control:
1726 *
1727 * LOCAL DEVICE | LINK PARTNER
1728 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
1729 *-------|---------|-------|---------|--------------------
1730 * 1 | DC | 1 | DC | e1000_fc_full
1731 *
1732 */
1733 if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
1734 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
1735 /* Now we need to check if the user selected RX ONLY
1736 * of pause frames. In this case, we had to advertise
1737 * FULL flow control because we could not advertise RX
1738 * ONLY. Hence, we must now check to see if we need to
1739 * turn OFF the TRANSMISSION of PAUSE frames.
1740 */
1741 if (hw->original_fc == e1000_fc_full) {
1742 hw->fc = e1000_fc_full;
1743 DEBUGOUT("Flow Control = FULL.\r\n");
1744 } else {
1745 hw->fc = e1000_fc_rx_pause;
1746 DEBUGOUT
1747 ("Flow Control = RX PAUSE frames only.\r\n");
1748 }
1749 }
1750 /* For receiving PAUSE frames ONLY.
1751 *
1752 * LOCAL DEVICE | LINK PARTNER
1753 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
1754 *-------|---------|-------|---------|--------------------
1755 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
1756 *
1757 */
1758 else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
1759 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
1760 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
1761 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR))
1762 {
1763 hw->fc = e1000_fc_tx_pause;
1764 DEBUGOUT
1765 ("Flow Control = TX PAUSE frames only.\r\n");
1766 }
1767 /* For transmitting PAUSE frames ONLY.
1768 *
1769 * LOCAL DEVICE | LINK PARTNER
1770 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
1771 *-------|---------|-------|---------|--------------------
1772 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
1773 *
1774 */
1775 else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
1776 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
1777 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
1778 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR))
1779 {
1780 hw->fc = e1000_fc_rx_pause;
1781 DEBUGOUT
1782 ("Flow Control = RX PAUSE frames only.\r\n");
1783 }
1784 /* Per the IEEE spec, at this point flow control should be
1785 * disabled. However, we want to consider that we could
1786 * be connected to a legacy switch that doesn't advertise
1787 * desired flow control, but can be forced on the link
1788 * partner. So if we advertised no flow control, that is
1789 * what we will resolve to. If we advertised some kind of
1790 * receive capability (Rx Pause Only or Full Flow Control)
1791 * and the link partner advertised none, we will configure
1792 * ourselves to enable Rx Flow Control only. We can do
1793 * this safely for two reasons: If the link partner really
1794 * didn't want flow control enabled, and we enable Rx, no
1795 * harm done since we won't be receiving any PAUSE frames
1796 * anyway. If the intent on the link partner was to have
1797 * flow control enabled, then by us enabling RX only, we
1798 * can at least receive pause frames and process them.
1799 * This is a good idea because in most cases, since we are
1800 * predominantly a server NIC, more times than not we will
1801 * be asked to delay transmission of packets than asking
1802 * our link partner to pause transmission of frames.
1803 */
1804 else if (hw->original_fc == e1000_fc_none ||
1805 hw->original_fc == e1000_fc_tx_pause) {
1806 hw->fc = e1000_fc_none;
1807 DEBUGOUT("Flow Control = NONE.\r\n");
1808 } else {
1809 hw->fc = e1000_fc_rx_pause;
1810 DEBUGOUT
1811 ("Flow Control = RX PAUSE frames only.\r\n");
1812 }
1813
1814 /* Now we need to do one last check... If we auto-
1815 * negotiated to HALF DUPLEX, flow control should not be
1816 * enabled per IEEE 802.3 spec.
1817 */
1818 e1000_get_speed_and_duplex(hw, &speed, &duplex);
1819
1820 if (duplex == HALF_DUPLEX)
1821 hw->fc = e1000_fc_none;
1822
1823 /* Now we call a subroutine to actually force the MAC
1824 * controller to use the correct flow control settings.
1825 */
1826 ret_val = e1000_force_mac_fc(hw);
1827 if (ret_val < 0) {
1828 DEBUGOUT
1829 ("Error forcing flow control settings\n");
1830 return ret_val;
1831 }
1832 } else {
1833 DEBUGOUT
1834 ("Copper PHY and Auto Neg has not completed.\r\n");
1835 }
1836 }
1837 return 0;
1838}
1839
1840/******************************************************************************
1841 * Checks to see if the link status of the hardware has changed.
1842 *
1843 * hw - Struct containing variables accessed by shared code
1844 *
1845 * Called by any function that needs to check the link status of the adapter.
1846 *****************************************************************************/
1847static int
1848e1000_check_for_link(struct eth_device *nic)
1849{
1850 struct e1000_hw *hw = nic->priv;
1851 uint32_t rxcw;
1852 uint32_t ctrl;
1853 uint32_t status;
1854 uint32_t rctl;
1855 uint32_t signal;
1856 int32_t ret_val;
1857 uint16_t phy_data;
1858 uint16_t lp_capability;
1859
1860 DEBUGFUNC();
1861
wdenk57b2d802003-06-27 21:31:46 +00001862 /* On adapters with a MAC newer that 82544, SW Defineable pin 1 will be
1863 * set when the optics detect a signal. On older adapters, it will be
wdenk4e112c12003-06-03 23:54:09 +00001864 * cleared when there is a signal
1865 */
1866 ctrl = E1000_READ_REG(hw, CTRL);
1867 if ((hw->mac_type > e1000_82544) && !(ctrl & E1000_CTRL_ILOS))
1868 signal = E1000_CTRL_SWDPIN1;
1869 else
1870 signal = 0;
1871
1872 status = E1000_READ_REG(hw, STATUS);
1873 rxcw = E1000_READ_REG(hw, RXCW);
1874 DEBUGOUT("ctrl: %#08x status %#08x rxcw %#08x\n", ctrl, status, rxcw);
1875
1876 /* If we have a copper PHY then we only want to go out to the PHY
1877 * registers to see if Auto-Neg has completed and/or if our link
1878 * status has changed. The get_link_status flag will be set if we
1879 * receive a Link Status Change interrupt or we have Rx Sequence
1880 * Errors.
1881 */
1882 if ((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
1883 /* First we want to see if the MII Status Register reports
1884 * link. If so, then we want to get the current speed/duplex
1885 * of the PHY.
1886 * Read the register twice since the link bit is sticky.
1887 */
1888 if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
1889 DEBUGOUT("PHY Read Error\n");
1890 return -E1000_ERR_PHY;
1891 }
1892 if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
1893 DEBUGOUT("PHY Read Error\n");
1894 return -E1000_ERR_PHY;
1895 }
1896
1897 if (phy_data & MII_SR_LINK_STATUS) {
1898 hw->get_link_status = FALSE;
1899 } else {
1900 /* No link detected */
1901 return -E1000_ERR_NOLINK;
1902 }
1903
1904 /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
1905 * have Si on board that is 82544 or newer, Auto
1906 * Speed Detection takes care of MAC speed/duplex
1907 * configuration. So we only need to configure Collision
1908 * Distance in the MAC. Otherwise, we need to force
1909 * speed/duplex on the MAC to the current PHY speed/duplex
1910 * settings.
1911 */
1912 if (hw->mac_type >= e1000_82544)
1913 e1000_config_collision_dist(hw);
1914 else {
1915 ret_val = e1000_config_mac_to_phy(hw);
1916 if (ret_val < 0) {
1917 DEBUGOUT
1918 ("Error configuring MAC to PHY settings\n");
1919 return ret_val;
1920 }
1921 }
1922
wdenk57b2d802003-06-27 21:31:46 +00001923 /* Configure Flow Control now that Auto-Neg has completed. First, we
wdenk4e112c12003-06-03 23:54:09 +00001924 * need to restore the desired flow control settings because we may
1925 * have had to re-autoneg with a different link partner.
1926 */
1927 ret_val = e1000_config_fc_after_link_up(hw);
1928 if (ret_val < 0) {
1929 DEBUGOUT("Error configuring flow control\n");
1930 return ret_val;
1931 }
1932
1933 /* At this point we know that we are on copper and we have
1934 * auto-negotiated link. These are conditions for checking the link
1935 * parter capability register. We use the link partner capability to
1936 * determine if TBI Compatibility needs to be turned on or off. If
1937 * the link partner advertises any speed in addition to Gigabit, then
1938 * we assume that they are GMII-based, and TBI compatibility is not
1939 * needed. If no other speeds are advertised, we assume the link
1940 * partner is TBI-based, and we turn on TBI Compatibility.
1941 */
1942 if (hw->tbi_compatibility_en) {
1943 if (e1000_read_phy_reg
1944 (hw, PHY_LP_ABILITY, &lp_capability) < 0) {
1945 DEBUGOUT("PHY Read Error\n");
1946 return -E1000_ERR_PHY;
1947 }
1948 if (lp_capability & (NWAY_LPAR_10T_HD_CAPS |
1949 NWAY_LPAR_10T_FD_CAPS |
1950 NWAY_LPAR_100TX_HD_CAPS |
1951 NWAY_LPAR_100TX_FD_CAPS |
1952 NWAY_LPAR_100T4_CAPS)) {
wdenk57b2d802003-06-27 21:31:46 +00001953 /* If our link partner advertises anything in addition to
wdenk4e112c12003-06-03 23:54:09 +00001954 * gigabit, we do not need to enable TBI compatibility.
1955 */
1956 if (hw->tbi_compatibility_on) {
1957 /* If we previously were in the mode, turn it off. */
1958 rctl = E1000_READ_REG(hw, RCTL);
1959 rctl &= ~E1000_RCTL_SBP;
1960 E1000_WRITE_REG(hw, RCTL, rctl);
1961 hw->tbi_compatibility_on = FALSE;
1962 }
1963 } else {
1964 /* If TBI compatibility is was previously off, turn it on. For
1965 * compatibility with a TBI link partner, we will store bad
1966 * packets. Some frames have an additional byte on the end and
1967 * will look like CRC errors to to the hardware.
1968 */
1969 if (!hw->tbi_compatibility_on) {
1970 hw->tbi_compatibility_on = TRUE;
1971 rctl = E1000_READ_REG(hw, RCTL);
1972 rctl |= E1000_RCTL_SBP;
1973 E1000_WRITE_REG(hw, RCTL, rctl);
1974 }
1975 }
1976 }
1977 }
1978 /* If we don't have link (auto-negotiation failed or link partner cannot
1979 * auto-negotiate), the cable is plugged in (we have signal), and our
1980 * link partner is not trying to auto-negotiate with us (we are receiving
1981 * idles or data), we need to force link up. We also need to give
1982 * auto-negotiation time to complete, in case the cable was just plugged
1983 * in. The autoneg_failed flag does this.
1984 */
1985 else if ((hw->media_type == e1000_media_type_fiber) &&
1986 (!(status & E1000_STATUS_LU)) &&
1987 ((ctrl & E1000_CTRL_SWDPIN1) == signal) &&
1988 (!(rxcw & E1000_RXCW_C))) {
1989 if (hw->autoneg_failed == 0) {
1990 hw->autoneg_failed = 1;
1991 return 0;
1992 }
1993 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\r\n");
1994
1995 /* Disable auto-negotiation in the TXCW register */
1996 E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE));
1997
1998 /* Force link-up and also force full-duplex. */
1999 ctrl = E1000_READ_REG(hw, CTRL);
2000 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
2001 E1000_WRITE_REG(hw, CTRL, ctrl);
2002
2003 /* Configure Flow Control after forcing link up. */
2004 ret_val = e1000_config_fc_after_link_up(hw);
2005 if (ret_val < 0) {
2006 DEBUGOUT("Error configuring flow control\n");
2007 return ret_val;
2008 }
2009 }
2010 /* If we are forcing link and we are receiving /C/ ordered sets, re-enable
2011 * auto-negotiation in the TXCW register and disable forced link in the
2012 * Device Control register in an attempt to auto-negotiate with our link
2013 * partner.
2014 */
2015 else if ((hw->media_type == e1000_media_type_fiber) &&
2016 (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
2017 DEBUGOUT
2018 ("RXing /C/, enable AutoNeg and stop forcing link.\r\n");
2019 E1000_WRITE_REG(hw, TXCW, hw->txcw);
2020 E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU));
2021 }
2022 return 0;
2023}
2024
2025/******************************************************************************
2026 * Detects the current speed and duplex settings of the hardware.
2027 *
2028 * hw - Struct containing variables accessed by shared code
2029 * speed - Speed of the connection
2030 * duplex - Duplex setting of the connection
2031 *****************************************************************************/
2032static void
2033e1000_get_speed_and_duplex(struct e1000_hw *hw,
2034 uint16_t * speed, uint16_t * duplex)
2035{
2036 uint32_t status;
2037
2038 DEBUGFUNC();
2039
2040 if (hw->mac_type >= e1000_82543) {
2041 status = E1000_READ_REG(hw, STATUS);
2042 if (status & E1000_STATUS_SPEED_1000) {
2043 *speed = SPEED_1000;
2044 DEBUGOUT("1000 Mbs, ");
2045 } else if (status & E1000_STATUS_SPEED_100) {
2046 *speed = SPEED_100;
2047 DEBUGOUT("100 Mbs, ");
2048 } else {
2049 *speed = SPEED_10;
2050 DEBUGOUT("10 Mbs, ");
2051 }
2052
2053 if (status & E1000_STATUS_FD) {
2054 *duplex = FULL_DUPLEX;
2055 DEBUGOUT("Full Duplex\r\n");
2056 } else {
2057 *duplex = HALF_DUPLEX;
2058 DEBUGOUT(" Half Duplex\r\n");
2059 }
2060 } else {
2061 DEBUGOUT("1000 Mbs, Full Duplex\r\n");
2062 *speed = SPEED_1000;
2063 *duplex = FULL_DUPLEX;
2064 }
2065}
2066
2067/******************************************************************************
2068* Blocks until autoneg completes or times out (~4.5 seconds)
2069*
2070* hw - Struct containing variables accessed by shared code
2071******************************************************************************/
2072static int
2073e1000_wait_autoneg(struct e1000_hw *hw)
2074{
2075 uint16_t i;
2076 uint16_t phy_data;
2077
2078 DEBUGFUNC();
2079 DEBUGOUT("Waiting for Auto-Neg to complete.\n");
2080
2081 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
2082 for (i = PHY_AUTO_NEG_TIME; i > 0; i--) {
2083 /* Read the MII Status Register and wait for Auto-Neg
2084 * Complete bit to be set.
2085 */
2086 if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
2087 DEBUGOUT("PHY Read Error\n");
2088 return -E1000_ERR_PHY;
2089 }
2090 if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
2091 DEBUGOUT("PHY Read Error\n");
2092 return -E1000_ERR_PHY;
2093 }
2094 if (phy_data & MII_SR_AUTONEG_COMPLETE) {
2095 DEBUGOUT("Auto-Neg complete.\n");
2096 return 0;
2097 }
2098 mdelay(100);
2099 }
2100 DEBUGOUT("Auto-Neg timedout.\n");
2101 return -E1000_ERR_TIMEOUT;
2102}
2103
2104/******************************************************************************
2105* Raises the Management Data Clock
2106*
2107* hw - Struct containing variables accessed by shared code
2108* ctrl - Device control register's current value
2109******************************************************************************/
2110static void
2111e1000_raise_mdi_clk(struct e1000_hw *hw, uint32_t * ctrl)
2112{
2113 /* Raise the clock input to the Management Data Clock (by setting the MDC
2114 * bit), and then delay 2 microseconds.
2115 */
2116 E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC));
2117 E1000_WRITE_FLUSH(hw);
2118 udelay(2);
2119}
2120
2121/******************************************************************************
2122* Lowers the Management Data Clock
2123*
2124* hw - Struct containing variables accessed by shared code
2125* ctrl - Device control register's current value
2126******************************************************************************/
2127static void
2128e1000_lower_mdi_clk(struct e1000_hw *hw, uint32_t * ctrl)
2129{
2130 /* Lower the clock input to the Management Data Clock (by clearing the MDC
2131 * bit), and then delay 2 microseconds.
2132 */
2133 E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC));
2134 E1000_WRITE_FLUSH(hw);
2135 udelay(2);
2136}
2137
2138/******************************************************************************
2139* Shifts data bits out to the PHY
2140*
2141* hw - Struct containing variables accessed by shared code
2142* data - Data to send out to the PHY
2143* count - Number of bits to shift out
2144*
2145* Bits are shifted out in MSB to LSB order.
2146******************************************************************************/
2147static void
2148e1000_shift_out_mdi_bits(struct e1000_hw *hw, uint32_t data, uint16_t count)
2149{
2150 uint32_t ctrl;
2151 uint32_t mask;
2152
2153 /* We need to shift "count" number of bits out to the PHY. So, the value
wdenk57b2d802003-06-27 21:31:46 +00002154 * in the "data" parameter will be shifted out to the PHY one bit at a
wdenk4e112c12003-06-03 23:54:09 +00002155 * time. In order to do this, "data" must be broken down into bits.
2156 */
2157 mask = 0x01;
2158 mask <<= (count - 1);
2159
2160 ctrl = E1000_READ_REG(hw, CTRL);
2161
2162 /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
2163 ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
2164
2165 while (mask) {
2166 /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
2167 * then raising and lowering the Management Data Clock. A "0" is
2168 * shifted out to the PHY by setting the MDIO bit to "0" and then
2169 * raising and lowering the clock.
2170 */
2171 if (data & mask)
2172 ctrl |= E1000_CTRL_MDIO;
2173 else
2174 ctrl &= ~E1000_CTRL_MDIO;
2175
2176 E1000_WRITE_REG(hw, CTRL, ctrl);
2177 E1000_WRITE_FLUSH(hw);
2178
2179 udelay(2);
2180
2181 e1000_raise_mdi_clk(hw, &ctrl);
2182 e1000_lower_mdi_clk(hw, &ctrl);
2183
2184 mask = mask >> 1;
2185 }
2186}
2187
2188/******************************************************************************
2189* Shifts data bits in from the PHY
2190*
2191* hw - Struct containing variables accessed by shared code
2192*
wdenk57b2d802003-06-27 21:31:46 +00002193* Bits are shifted in in MSB to LSB order.
wdenk4e112c12003-06-03 23:54:09 +00002194******************************************************************************/
2195static uint16_t
2196e1000_shift_in_mdi_bits(struct e1000_hw *hw)
2197{
2198 uint32_t ctrl;
2199 uint16_t data = 0;
2200 uint8_t i;
2201
2202 /* In order to read a register from the PHY, we need to shift in a total
2203 * of 18 bits from the PHY. The first two bit (turnaround) times are used
2204 * to avoid contention on the MDIO pin when a read operation is performed.
2205 * These two bits are ignored by us and thrown away. Bits are "shifted in"
2206 * by raising the input to the Management Data Clock (setting the MDC bit),
2207 * and then reading the value of the MDIO bit.
2208 */
2209 ctrl = E1000_READ_REG(hw, CTRL);
2210
2211 /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
2212 ctrl &= ~E1000_CTRL_MDIO_DIR;
2213 ctrl &= ~E1000_CTRL_MDIO;
2214
2215 E1000_WRITE_REG(hw, CTRL, ctrl);
2216 E1000_WRITE_FLUSH(hw);
2217
2218 /* Raise and Lower the clock before reading in the data. This accounts for
2219 * the turnaround bits. The first clock occurred when we clocked out the
2220 * last bit of the Register Address.
2221 */
2222 e1000_raise_mdi_clk(hw, &ctrl);
2223 e1000_lower_mdi_clk(hw, &ctrl);
2224
2225 for (data = 0, i = 0; i < 16; i++) {
2226 data = data << 1;
2227 e1000_raise_mdi_clk(hw, &ctrl);
2228 ctrl = E1000_READ_REG(hw, CTRL);
2229 /* Check to see if we shifted in a "1". */
2230 if (ctrl & E1000_CTRL_MDIO)
2231 data |= 1;
2232 e1000_lower_mdi_clk(hw, &ctrl);
2233 }
2234
2235 e1000_raise_mdi_clk(hw, &ctrl);
2236 e1000_lower_mdi_clk(hw, &ctrl);
2237
2238 return data;
2239}
2240
2241/*****************************************************************************
2242* Reads the value from a PHY register
2243*
2244* hw - Struct containing variables accessed by shared code
2245* reg_addr - address of the PHY register to read
2246******************************************************************************/
2247static int
2248e1000_read_phy_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t * phy_data)
2249{
2250 uint32_t i;
2251 uint32_t mdic = 0;
2252 const uint32_t phy_addr = 1;
2253
2254 if (reg_addr > MAX_PHY_REG_ADDRESS) {
2255 DEBUGOUT("PHY Address %d is out of range\n", reg_addr);
2256 return -E1000_ERR_PARAM;
2257 }
2258
2259 if (hw->mac_type > e1000_82543) {
2260 /* Set up Op-code, Phy Address, and register address in the MDI
2261 * Control register. The MAC will take care of interfacing with the
2262 * PHY to retrieve the desired data.
2263 */
2264 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
2265 (phy_addr << E1000_MDIC_PHY_SHIFT) |
2266 (E1000_MDIC_OP_READ));
2267
2268 E1000_WRITE_REG(hw, MDIC, mdic);
2269
2270 /* Poll the ready bit to see if the MDI read completed */
2271 for (i = 0; i < 64; i++) {
2272 udelay(10);
2273 mdic = E1000_READ_REG(hw, MDIC);
2274 if (mdic & E1000_MDIC_READY)
2275 break;
2276 }
2277 if (!(mdic & E1000_MDIC_READY)) {
2278 DEBUGOUT("MDI Read did not complete\n");
2279 return -E1000_ERR_PHY;
2280 }
2281 if (mdic & E1000_MDIC_ERROR) {
2282 DEBUGOUT("MDI Error\n");
2283 return -E1000_ERR_PHY;
2284 }
2285 *phy_data = (uint16_t) mdic;
2286 } else {
2287 /* We must first send a preamble through the MDIO pin to signal the
2288 * beginning of an MII instruction. This is done by sending 32
2289 * consecutive "1" bits.
2290 */
2291 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
2292
2293 /* Now combine the next few fields that are required for a read
2294 * operation. We use this method instead of calling the
2295 * e1000_shift_out_mdi_bits routine five different times. The format of
2296 * a MII read instruction consists of a shift out of 14 bits and is
2297 * defined as follows:
2298 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
2299 * followed by a shift in of 18 bits. This first two bits shifted in
2300 * are TurnAround bits used to avoid contention on the MDIO pin when a
2301 * READ operation is performed. These two bits are thrown away
2302 * followed by a shift in of 16 bits which contains the desired data.
2303 */
2304 mdic = ((reg_addr) | (phy_addr << 5) |
2305 (PHY_OP_READ << 10) | (PHY_SOF << 12));
2306
2307 e1000_shift_out_mdi_bits(hw, mdic, 14);
2308
2309 /* Now that we've shifted out the read command to the MII, we need to
2310 * "shift in" the 16-bit value (18 total bits) of the requested PHY
2311 * register address.
2312 */
2313 *phy_data = e1000_shift_in_mdi_bits(hw);
2314 }
2315 return 0;
2316}
2317
2318/******************************************************************************
2319* Writes a value to a PHY register
2320*
2321* hw - Struct containing variables accessed by shared code
2322* reg_addr - address of the PHY register to write
2323* data - data to write to the PHY
2324******************************************************************************/
2325static int
2326e1000_write_phy_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t phy_data)
2327{
2328 uint32_t i;
2329 uint32_t mdic = 0;
2330 const uint32_t phy_addr = 1;
2331
2332 if (reg_addr > MAX_PHY_REG_ADDRESS) {
2333 DEBUGOUT("PHY Address %d is out of range\n", reg_addr);
2334 return -E1000_ERR_PARAM;
2335 }
2336
2337 if (hw->mac_type > e1000_82543) {
2338 /* Set up Op-code, Phy Address, register address, and data intended
2339 * for the PHY register in the MDI Control register. The MAC will take
2340 * care of interfacing with the PHY to send the desired data.
2341 */
2342 mdic = (((uint32_t) phy_data) |
2343 (reg_addr << E1000_MDIC_REG_SHIFT) |
2344 (phy_addr << E1000_MDIC_PHY_SHIFT) |
2345 (E1000_MDIC_OP_WRITE));
2346
2347 E1000_WRITE_REG(hw, MDIC, mdic);
2348
2349 /* Poll the ready bit to see if the MDI read completed */
2350 for (i = 0; i < 64; i++) {
2351 udelay(10);
2352 mdic = E1000_READ_REG(hw, MDIC);
2353 if (mdic & E1000_MDIC_READY)
2354 break;
2355 }
2356 if (!(mdic & E1000_MDIC_READY)) {
2357 DEBUGOUT("MDI Write did not complete\n");
2358 return -E1000_ERR_PHY;
2359 }
2360 } else {
2361 /* We'll need to use the SW defined pins to shift the write command
2362 * out to the PHY. We first send a preamble to the PHY to signal the
wdenk57b2d802003-06-27 21:31:46 +00002363 * beginning of the MII instruction. This is done by sending 32
wdenk4e112c12003-06-03 23:54:09 +00002364 * consecutive "1" bits.
2365 */
2366 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
2367
wdenk57b2d802003-06-27 21:31:46 +00002368 /* Now combine the remaining required fields that will indicate a
wdenk4e112c12003-06-03 23:54:09 +00002369 * write operation. We use this method instead of calling the
2370 * e1000_shift_out_mdi_bits routine for each field in the command. The
2371 * format of a MII write instruction is as follows:
2372 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
2373 */
2374 mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
2375 (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
2376 mdic <<= 16;
2377 mdic |= (uint32_t) phy_data;
2378
2379 e1000_shift_out_mdi_bits(hw, mdic, 32);
2380 }
2381 return 0;
2382}
2383
2384/******************************************************************************
2385* Returns the PHY to the power-on reset state
2386*
2387* hw - Struct containing variables accessed by shared code
2388******************************************************************************/
2389static void
2390e1000_phy_hw_reset(struct e1000_hw *hw)
2391{
2392 uint32_t ctrl;
2393 uint32_t ctrl_ext;
2394
2395 DEBUGFUNC();
2396
2397 DEBUGOUT("Resetting Phy...\n");
2398
2399 if (hw->mac_type > e1000_82543) {
2400 /* Read the device control register and assert the E1000_CTRL_PHY_RST
2401 * bit. Then, take it out of reset.
2402 */
2403 ctrl = E1000_READ_REG(hw, CTRL);
2404 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PHY_RST);
2405 E1000_WRITE_FLUSH(hw);
2406 mdelay(10);
2407 E1000_WRITE_REG(hw, CTRL, ctrl);
2408 E1000_WRITE_FLUSH(hw);
2409 } else {
2410 /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
2411 * bit to put the PHY into reset. Then, take it out of reset.
2412 */
2413 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
2414 ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
2415 ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
2416 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
2417 E1000_WRITE_FLUSH(hw);
2418 mdelay(10);
2419 ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
2420 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
2421 E1000_WRITE_FLUSH(hw);
2422 }
2423 udelay(150);
2424}
2425
2426/******************************************************************************
2427* Resets the PHY
2428*
2429* hw - Struct containing variables accessed by shared code
2430*
2431* Sets bit 15 of the MII Control regiser
2432******************************************************************************/
2433static int
2434e1000_phy_reset(struct e1000_hw *hw)
2435{
2436 uint16_t phy_data;
2437
2438 DEBUGFUNC();
2439
2440 if (e1000_read_phy_reg(hw, PHY_CTRL, &phy_data) < 0) {
2441 DEBUGOUT("PHY Read Error\n");
2442 return -E1000_ERR_PHY;
2443 }
2444 phy_data |= MII_CR_RESET;
2445 if (e1000_write_phy_reg(hw, PHY_CTRL, phy_data) < 0) {
2446 DEBUGOUT("PHY Write Error\n");
2447 return -E1000_ERR_PHY;
2448 }
2449 udelay(1);
2450 return 0;
2451}
2452
2453/******************************************************************************
2454* Probes the expected PHY address for known PHY IDs
2455*
2456* hw - Struct containing variables accessed by shared code
2457******************************************************************************/
2458static int
2459e1000_detect_gig_phy(struct e1000_hw *hw)
2460{
2461 uint16_t phy_id_high, phy_id_low;
2462 int match = FALSE;
2463
2464 DEBUGFUNC();
2465
2466 /* Read the PHY ID Registers to identify which PHY is onboard. */
2467 if (e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high) < 0) {
2468 DEBUGOUT("PHY Read Error\n");
2469 return -E1000_ERR_PHY;
2470 }
2471 hw->phy_id = (uint32_t) (phy_id_high << 16);
2472 udelay(2);
2473 if (e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low) < 0) {
2474 DEBUGOUT("PHY Read Error\n");
2475 return -E1000_ERR_PHY;
2476 }
2477 hw->phy_id |= (uint32_t) (phy_id_low & PHY_REVISION_MASK);
2478
2479 switch (hw->mac_type) {
2480 case e1000_82543:
2481 if (hw->phy_id == M88E1000_E_PHY_ID)
2482 match = TRUE;
2483 break;
2484 case e1000_82544:
2485 if (hw->phy_id == M88E1000_I_PHY_ID)
2486 match = TRUE;
2487 break;
2488 case e1000_82540:
2489 case e1000_82545:
2490 case e1000_82546:
2491 if (hw->phy_id == M88E1011_I_PHY_ID)
2492 match = TRUE;
2493 break;
2494 default:
2495 DEBUGOUT("Invalid MAC type %d\n", hw->mac_type);
2496 return -E1000_ERR_CONFIG;
2497 }
2498 if (match) {
2499 DEBUGOUT("PHY ID 0x%X detected\n", hw->phy_id);
2500 return 0;
2501 }
2502 DEBUGOUT("Invalid PHY ID 0x%X\n", hw->phy_id);
2503 return -E1000_ERR_PHY;
2504}
2505
2506/**
2507 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
2508 *
2509 * e1000_sw_init initializes the Adapter private data structure.
2510 * Fields are initialized based on PCI device information and
2511 * OS network device settings (MTU size).
2512 **/
2513
2514static int
2515e1000_sw_init(struct eth_device *nic, int cardnum)
2516{
2517 struct e1000_hw *hw = (typeof(hw)) nic->priv;
2518 int result;
2519
2520 /* PCI config space info */
2521 pci_read_config_word(hw->pdev, PCI_VENDOR_ID, &hw->vendor_id);
2522 pci_read_config_word(hw->pdev, PCI_DEVICE_ID, &hw->device_id);
2523 pci_read_config_word(hw->pdev, PCI_SUBSYSTEM_VENDOR_ID,
2524 &hw->subsystem_vendor_id);
2525 pci_read_config_word(hw->pdev, PCI_SUBSYSTEM_ID, &hw->subsystem_id);
2526
2527 pci_read_config_byte(hw->pdev, PCI_REVISION_ID, &hw->revision_id);
2528 pci_read_config_word(hw->pdev, PCI_COMMAND, &hw->pci_cmd_word);
2529
2530 /* identify the MAC */
2531 result = e1000_set_mac_type(hw);
2532 if (result) {
2533 E1000_ERR("Unknown MAC Type\n");
2534 return result;
2535 }
2536
2537 /* lan a vs. lan b settings */
2538 if (hw->mac_type == e1000_82546)
2539 /*this also works w/ multiple 82546 cards */
2540 /*but not if they're intermingled /w other e1000s */
2541 hw->lan_loc = (cardnum % 2) ? e1000_lan_b : e1000_lan_a;
2542 else
2543 hw->lan_loc = e1000_lan_a;
2544
2545 /* flow control settings */
2546 hw->fc_high_water = E1000_FC_HIGH_THRESH;
2547 hw->fc_low_water = E1000_FC_LOW_THRESH;
2548 hw->fc_pause_time = E1000_FC_PAUSE_TIME;
2549 hw->fc_send_xon = 1;
2550
2551 /* Media type - copper or fiber */
2552
2553 if (hw->mac_type >= e1000_82543) {
2554 uint32_t status = E1000_READ_REG(hw, STATUS);
2555
2556 if (status & E1000_STATUS_TBIMODE) {
2557 DEBUGOUT("fiber interface\n");
2558 hw->media_type = e1000_media_type_fiber;
2559 } else {
2560 DEBUGOUT("copper interface\n");
2561 hw->media_type = e1000_media_type_copper;
2562 }
2563 } else {
2564 hw->media_type = e1000_media_type_fiber;
2565 }
2566
2567 if (hw->mac_type < e1000_82543)
2568 hw->report_tx_early = 0;
2569 else
2570 hw->report_tx_early = 1;
2571
2572 hw->tbi_compatibility_en = TRUE;
2573#if 0
2574 hw->wait_autoneg_complete = FALSE;
2575 hw->adaptive_ifs = TRUE;
2576
2577 /* Copper options */
2578 if (hw->media_type == e1000_media_type_copper) {
2579 hw->mdix = AUTO_ALL_MODES;
2580 hw->disable_polarity_correction = FALSE;
2581 }
2582#endif
2583 return E1000_SUCCESS;
2584}
2585
2586void
2587fill_rx(struct e1000_hw *hw)
2588{
2589 struct e1000_rx_desc *rd;
2590
2591 rx_last = rx_tail;
2592 rd = rx_base + rx_tail;
2593 rx_tail = (rx_tail + 1) % 8;
2594 memset(rd, 0, 16);
2595 rd->buffer_addr = cpu_to_le64((u32) & packet);
2596 E1000_WRITE_REG(hw, RDT, rx_tail);
2597}
2598
2599/**
2600 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
2601 * @adapter: board private structure
2602 *
2603 * Configure the Tx unit of the MAC after a reset.
2604 **/
2605
2606static void
2607e1000_configure_tx(struct e1000_hw *hw)
2608{
2609 unsigned long ptr;
2610 unsigned long tctl;
2611 unsigned long tipg;
2612
2613 ptr = (u32) tx_pool;
2614 if (ptr & 0xf)
2615 ptr = (ptr + 0x10) & (~0xf);
2616
2617 tx_base = (typeof(tx_base)) ptr;
2618
2619 E1000_WRITE_REG(hw, TDBAL, (u32) tx_base);
2620 E1000_WRITE_REG(hw, TDBAH, 0);
2621
2622 E1000_WRITE_REG(hw, TDLEN, 128);
2623
2624 /* Setup the HW Tx Head and Tail descriptor pointers */
2625 E1000_WRITE_REG(hw, TDH, 0);
2626 E1000_WRITE_REG(hw, TDT, 0);
2627 tx_tail = 0;
2628
2629 /* Set the default values for the Tx Inter Packet Gap timer */
2630 switch (hw->mac_type) {
2631 case e1000_82542_rev2_0:
2632 case e1000_82542_rev2_1:
2633 tipg = DEFAULT_82542_TIPG_IPGT;
2634 tipg |= DEFAULT_82542_TIPG_IPGR1 << E1000_TIPG_IPGR1_SHIFT;
2635 tipg |= DEFAULT_82542_TIPG_IPGR2 << E1000_TIPG_IPGR2_SHIFT;
2636 break;
2637 default:
2638 if (hw->media_type == e1000_media_type_fiber)
2639 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
2640 else
2641 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
2642 tipg |= DEFAULT_82543_TIPG_IPGR1 << E1000_TIPG_IPGR1_SHIFT;
2643 tipg |= DEFAULT_82543_TIPG_IPGR2 << E1000_TIPG_IPGR2_SHIFT;
2644 }
2645 E1000_WRITE_REG(hw, TIPG, tipg);
2646#if 0
2647 /* Set the Tx Interrupt Delay register */
2648 E1000_WRITE_REG(hw, TIDV, adapter->tx_int_delay);
2649 if (hw->mac_type >= e1000_82540)
2650 E1000_WRITE_REG(hw, TADV, adapter->tx_abs_int_delay);
2651#endif
2652 /* Program the Transmit Control Register */
2653 tctl = E1000_READ_REG(hw, TCTL);
2654 tctl &= ~E1000_TCTL_CT;
2655 tctl |= E1000_TCTL_EN | E1000_TCTL_PSP |
2656 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
2657 E1000_WRITE_REG(hw, TCTL, tctl);
2658
2659 e1000_config_collision_dist(hw);
2660#if 0
2661 /* Setup Transmit Descriptor Settings for this adapter */
2662 adapter->txd_cmd = E1000_TXD_CMD_IFCS | E1000_TXD_CMD_IDE;
2663
2664 if (adapter->hw.report_tx_early == 1)
2665 adapter->txd_cmd |= E1000_TXD_CMD_RS;
2666 else
2667 adapter->txd_cmd |= E1000_TXD_CMD_RPS;
2668#endif
2669}
2670
2671/**
2672 * e1000_setup_rctl - configure the receive control register
2673 * @adapter: Board private structure
2674 **/
2675static void
2676e1000_setup_rctl(struct e1000_hw *hw)
2677{
2678 uint32_t rctl;
2679
2680 rctl = E1000_READ_REG(hw, RCTL);
2681
2682 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
2683
2684 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF; /* |
2685 (hw.mc_filter_type << E1000_RCTL_MO_SHIFT); */
2686
2687 if (hw->tbi_compatibility_on == 1)
2688 rctl |= E1000_RCTL_SBP;
2689 else
2690 rctl &= ~E1000_RCTL_SBP;
2691
2692 rctl &= ~(E1000_RCTL_SZ_4096);
2693#if 0
2694 switch (adapter->rx_buffer_len) {
2695 case E1000_RXBUFFER_2048:
2696 default:
2697#endif
2698 rctl |= E1000_RCTL_SZ_2048;
2699 rctl &= ~(E1000_RCTL_BSEX | E1000_RCTL_LPE);
2700#if 0
2701 break;
2702 case E1000_RXBUFFER_4096:
2703 rctl |= E1000_RCTL_SZ_4096 | E1000_RCTL_BSEX | E1000_RCTL_LPE;
2704 break;
2705 case E1000_RXBUFFER_8192:
2706 rctl |= E1000_RCTL_SZ_8192 | E1000_RCTL_BSEX | E1000_RCTL_LPE;
2707 break;
2708 case E1000_RXBUFFER_16384:
2709 rctl |= E1000_RCTL_SZ_16384 | E1000_RCTL_BSEX | E1000_RCTL_LPE;
2710 break;
2711 }
2712#endif
2713 E1000_WRITE_REG(hw, RCTL, rctl);
2714}
2715
2716/**
2717 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
2718 * @adapter: board private structure
2719 *
2720 * Configure the Rx unit of the MAC after a reset.
2721 **/
2722static void
2723e1000_configure_rx(struct e1000_hw *hw)
2724{
2725 unsigned long ptr;
2726 unsigned long rctl;
2727#if 0
2728 unsigned long rxcsum;
2729#endif
2730 rx_tail = 0;
2731 /* make sure receives are disabled while setting up the descriptors */
2732 rctl = E1000_READ_REG(hw, RCTL);
2733 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
2734#if 0
2735 /* set the Receive Delay Timer Register */
2736
2737 E1000_WRITE_REG(hw, RDTR, adapter->rx_int_delay);
2738#endif
2739 if (hw->mac_type >= e1000_82540) {
2740#if 0
2741 E1000_WRITE_REG(hw, RADV, adapter->rx_abs_int_delay);
2742#endif
2743 /* Set the interrupt throttling rate. Value is calculated
2744 * as DEFAULT_ITR = 1/(MAX_INTS_PER_SEC * 256ns) */
2745#define MAX_INTS_PER_SEC 8000
2746#define DEFAULT_ITR 1000000000/(MAX_INTS_PER_SEC * 256)
2747 E1000_WRITE_REG(hw, ITR, DEFAULT_ITR);
2748 }
2749
2750 /* Setup the Base and Length of the Rx Descriptor Ring */
2751 ptr = (u32) rx_pool;
2752 if (ptr & 0xf)
2753 ptr = (ptr + 0x10) & (~0xf);
2754 rx_base = (typeof(rx_base)) ptr;
2755 E1000_WRITE_REG(hw, RDBAL, (u32) rx_base);
2756 E1000_WRITE_REG(hw, RDBAH, 0);
2757
2758 E1000_WRITE_REG(hw, RDLEN, 128);
2759
2760 /* Setup the HW Rx Head and Tail Descriptor Pointers */
2761 E1000_WRITE_REG(hw, RDH, 0);
2762 E1000_WRITE_REG(hw, RDT, 0);
2763#if 0
2764 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
2765 if ((adapter->hw.mac_type >= e1000_82543) && (adapter->rx_csum == TRUE)) {
2766 rxcsum = E1000_READ_REG(hw, RXCSUM);
2767 rxcsum |= E1000_RXCSUM_TUOFL;
2768 E1000_WRITE_REG(hw, RXCSUM, rxcsum);
2769 }
2770#endif
2771 /* Enable Receives */
2772
2773 E1000_WRITE_REG(hw, RCTL, rctl);
2774 fill_rx(hw);
2775}
2776
2777/**************************************************************************
2778POLL - Wait for a frame
2779***************************************************************************/
2780static int
2781e1000_poll(struct eth_device *nic)
2782{
2783 struct e1000_hw *hw = nic->priv;
2784 struct e1000_rx_desc *rd;
2785 /* return true if there's an ethernet packet ready to read */
2786 rd = rx_base + rx_last;
2787 if (!(le32_to_cpu(rd->status)) & E1000_RXD_STAT_DD)
2788 return 0;
2789 /*DEBUGOUT("recv: packet len=%d \n", rd->length); */
2790 NetReceive(packet, le32_to_cpu(rd->length));
2791 fill_rx(hw);
2792 return 1;
2793}
2794
2795/**************************************************************************
2796TRANSMIT - Transmit a frame
2797***************************************************************************/
2798static int
2799e1000_transmit(struct eth_device *nic, volatile void *packet, int length)
2800{
2801 struct e1000_hw *hw = nic->priv;
2802 struct e1000_tx_desc *txp;
2803 int i = 0;
2804
2805 txp = tx_base + tx_tail;
2806 tx_tail = (tx_tail + 1) % 8;
2807
2808 txp->buffer_addr = cpu_to_le64(virt_to_bus(packet));
2809 txp->lower.data = cpu_to_le32(E1000_TXD_CMD_RPS | E1000_TXD_CMD_EOP |
2810 E1000_TXD_CMD_IFCS | length);
2811 txp->upper.data = 0;
2812 E1000_WRITE_REG(hw, TDT, tx_tail);
2813
2814 while (!(le32_to_cpu(txp->upper.data) & E1000_TXD_STAT_DD)) {
2815 if (i++ > TOUT_LOOP) {
2816 DEBUGOUT("e1000: tx timeout\n");
2817 return 0;
2818 }
2819 udelay(10); /* give the nic a chance to write to the register */
2820 }
2821 return 1;
2822}
2823
2824/*reset function*/
2825static inline int
2826e1000_reset(struct eth_device *nic)
2827{
2828 struct e1000_hw *hw = nic->priv;
2829
2830 e1000_reset_hw(hw);
2831 if (hw->mac_type >= e1000_82544) {
2832 E1000_WRITE_REG(hw, WUC, 0);
2833 }
2834 return e1000_init_hw(nic);
2835}
2836
2837/**************************************************************************
2838DISABLE - Turn off ethernet interface
2839***************************************************************************/
2840static void
2841e1000_disable(struct eth_device *nic)
2842{
2843 struct e1000_hw *hw = nic->priv;
2844
2845 /* Turn off the ethernet interface */
2846 E1000_WRITE_REG(hw, RCTL, 0);
2847 E1000_WRITE_REG(hw, TCTL, 0);
2848
2849 /* Clear the transmit ring */
2850 E1000_WRITE_REG(hw, TDH, 0);
2851 E1000_WRITE_REG(hw, TDT, 0);
2852
2853 /* Clear the receive ring */
2854 E1000_WRITE_REG(hw, RDH, 0);
2855 E1000_WRITE_REG(hw, RDT, 0);
2856
2857 /* put the card in its initial state */
2858#if 0
2859 E1000_WRITE_REG(hw, CTRL, E1000_CTRL_RST);
2860#endif
2861 mdelay(10);
2862
2863}
2864
2865/**************************************************************************
2866INIT - set up ethernet interface(s)
2867***************************************************************************/
2868static int
2869e1000_init(struct eth_device *nic, bd_t * bis)
2870{
2871 struct e1000_hw *hw = nic->priv;
2872 int ret_val = 0;
2873
2874 ret_val = e1000_reset(nic);
2875 if (ret_val < 0) {
2876 if ((ret_val == -E1000_ERR_NOLINK) ||
2877 (ret_val == -E1000_ERR_TIMEOUT)) {
2878 E1000_ERR("Valid Link not detected\n");
2879 } else {
2880 E1000_ERR("Hardware Initialization Failed\n");
2881 }
2882 return 0;
2883 }
2884 e1000_configure_tx(hw);
2885 e1000_setup_rctl(hw);
2886 e1000_configure_rx(hw);
2887 return 1;
2888}
2889
2890/**************************************************************************
2891PROBE - Look for an adapter, this routine's visible to the outside
2892You should omit the last argument struct pci_device * for a non-PCI NIC
2893***************************************************************************/
2894int
2895e1000_initialize(bd_t * bis)
2896{
2897 pci_dev_t devno;
2898 int card_number = 0;
2899 struct eth_device *nic = NULL;
2900 struct e1000_hw *hw = NULL;
2901 u32 iobase;
2902 int idx = 0;
2903 u32 PciCommandWord;
2904
2905 while (1) { /* Find PCI device(s) */
2906 if ((devno = pci_find_devices(supported, idx++)) < 0) {
2907 break;
2908 }
2909
2910 pci_read_config_dword(devno, PCI_BASE_ADDRESS_0, &iobase);
2911 iobase &= ~0xf; /* Mask the bits that say "this is an io addr" */
2912 DEBUGOUT("e1000#%d: iobase 0x%08x\n", card_number, iobase);
2913
2914 pci_write_config_dword(devno, PCI_COMMAND,
2915 PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
2916 /* Check if I/O accesses and Bus Mastering are enabled. */
2917 pci_read_config_dword(devno, PCI_COMMAND, &PciCommandWord);
2918 if (!(PciCommandWord & PCI_COMMAND_MEMORY)) {
2919 printf("Error: Can not enable MEM access.\n");
2920 continue;
2921 } else if (!(PciCommandWord & PCI_COMMAND_MASTER)) {
2922 printf("Error: Can not enable Bus Mastering.\n");
2923 continue;
2924 }
2925
2926 nic = (struct eth_device *) malloc(sizeof (*nic));
2927 hw = (struct e1000_hw *) malloc(sizeof (*hw));
2928 hw->pdev = devno;
2929 nic->priv = hw;
2930 nic->iobase = bus_to_phys(devno, iobase);
2931
2932 sprintf(nic->name, "e1000#%d", card_number);
2933
2934 /* Are these variables needed? */
2935#if 0
2936 hw->fc = e1000_fc_none;
2937 hw->original_fc = e1000_fc_none;
2938#else
2939 hw->fc = e1000_fc_default;
2940 hw->original_fc = e1000_fc_default;
2941#endif
2942 hw->autoneg_failed = 0;
2943 hw->get_link_status = TRUE;
2944 hw->hw_addr = (typeof(hw->hw_addr)) iobase;
2945 hw->mac_type = e1000_undefined;
2946
2947 /* MAC and Phy settings */
2948 if (e1000_sw_init(nic, card_number) < 0) {
2949 free(hw);
2950 free(nic);
2951 return 0;
2952 }
2953 if (e1000_validate_eeprom_checksum(nic) < 0) {
2954 printf("The EEPROM Checksum Is Not Valid\n");
2955 free(hw);
2956 free(nic);
2957 return 0;
2958 }
2959 e1000_read_mac_addr(nic);
2960
2961 E1000_WRITE_REG(hw, PBA, E1000_DEFAULT_PBA);
2962
2963 printf("e1000: %02x:%02x:%02x:%02x:%02x:%02x\n",
2964 nic->enetaddr[0], nic->enetaddr[1], nic->enetaddr[2],
2965 nic->enetaddr[3], nic->enetaddr[4], nic->enetaddr[5]);
2966
2967 nic->init = e1000_init;
2968 nic->recv = e1000_poll;
2969 nic->send = e1000_transmit;
2970 nic->halt = e1000_disable;
2971
2972 eth_register(nic);
2973
2974 card_number++;
2975 }
2976 return 1;
2977}
2978
2979#endif