1 /*******************************************************************************
3 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 2006 Intel Corporation.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *******************************************************************************/
31 static struct pci_device_id e1000_nics[] = {
32 PCI_ROM(0x8086, 0x1000, "e1000-0x1000", "E1000-0x1000"),
33 PCI_ROM(0x8086, 0x1001, "e1000-0x1001", "E1000-0x1001"),
34 PCI_ROM(0x8086, 0x1004, "e1000-0x1004", "E1000-0x1004"),
35 PCI_ROM(0x8086, 0x1008, "e1000-0x1008", "E1000-0x1008"),
36 PCI_ROM(0x8086, 0x1009, "e1000-0x1009", "E1000-0x1009"),
37 PCI_ROM(0x8086, 0x100C, "e1000-0x100C", "E1000-0x100C"),
38 PCI_ROM(0x8086, 0x100D, "e1000-0x100D", "E1000-0x100D"),
39 PCI_ROM(0x8086, 0x100E, "e1000-0x100E", "E1000-0x100E"),
40 PCI_ROM(0x8086, 0x100F, "e1000-0x100F", "E1000-0x100F"),
41 PCI_ROM(0x8086, 0x1010, "e1000-0x1010", "E1000-0x1010"),
42 PCI_ROM(0x8086, 0x1011, "e1000-0x1011", "E1000-0x1011"),
43 PCI_ROM(0x8086, 0x1012, "e1000-0x1012", "E1000-0x1012"),
44 PCI_ROM(0x8086, 0x1013, "e1000-0x1013", "E1000-0x1013"),
45 PCI_ROM(0x8086, 0x1014, "e1000-0x1014", "E1000-0x1014"),
46 PCI_ROM(0x8086, 0x1015, "e1000-0x1015", "E1000-0x1015"),
47 PCI_ROM(0x8086, 0x1016, "e1000-0x1016", "E1000-0x1016"),
48 PCI_ROM(0x8086, 0x1017, "e1000-0x1017", "E1000-0x1017"),
49 PCI_ROM(0x8086, 0x1018, "e1000-0x1018", "E1000-0x1018"),
50 PCI_ROM(0x8086, 0x1019, "e1000-0x1019", "E1000-0x1019"),
51 PCI_ROM(0x8086, 0x101A, "e1000-0x101A", "E1000-0x101A"),
52 PCI_ROM(0x8086, 0x101D, "e1000-0x101D", "E1000-0x101D"),
53 PCI_ROM(0x8086, 0x101E, "e1000-0x101E", "E1000-0x101E"),
54 PCI_ROM(0x8086, 0x1026, "e1000-0x1026", "E1000-0x1026"),
55 PCI_ROM(0x8086, 0x1027, "e1000-0x1027", "E1000-0x1027"),
56 PCI_ROM(0x8086, 0x1028, "e1000-0x1028", "E1000-0x1028"),
57 PCI_ROM(0x8086, 0x1049, "e1000-0x1049", "E1000-0x1049"),
58 PCI_ROM(0x8086, 0x104A, "e1000-0x104A", "E1000-0x104A"),
59 PCI_ROM(0x8086, 0x104B, "e1000-0x104B", "E1000-0x104B"),
60 PCI_ROM(0x8086, 0x104C, "e1000-0x104C", "E1000-0x104C"),
61 PCI_ROM(0x8086, 0x104D, "e1000-0x104D", "E1000-0x104D"),
62 PCI_ROM(0x8086, 0x105E, "e1000-0x105E", "E1000-0x105E"),
63 PCI_ROM(0x8086, 0x105F, "e1000-0x105F", "E1000-0x105F"),
64 PCI_ROM(0x8086, 0x1060, "e1000-0x1060", "E1000-0x1060"),
65 PCI_ROM(0x8086, 0x1075, "e1000-0x1075", "E1000-0x1075"),
66 PCI_ROM(0x8086, 0x1076, "e1000-0x1076", "E1000-0x1076"),
67 PCI_ROM(0x8086, 0x1077, "e1000-0x1077", "E1000-0x1077"),
68 PCI_ROM(0x8086, 0x1078, "e1000-0x1078", "E1000-0x1078"),
69 PCI_ROM(0x8086, 0x1079, "e1000-0x1079", "E1000-0x1079"),
70 PCI_ROM(0x8086, 0x107A, "e1000-0x107A", "E1000-0x107A"),
71 PCI_ROM(0x8086, 0x107B, "e1000-0x107B", "E1000-0x107B"),
72 PCI_ROM(0x8086, 0x107C, "e1000-0x107C", "E1000-0x107C"),
73 PCI_ROM(0x8086, 0x107D, "e1000-0x107D", "E1000-0x107D"),
74 PCI_ROM(0x8086, 0x107E, "e1000-0x107E", "E1000-0x107E"),
75 PCI_ROM(0x8086, 0x107F, "e1000-0x107F", "E1000-0x107F"),
76 PCI_ROM(0x8086, 0x108A, "e1000-0x108A", "E1000-0x108A"),
77 PCI_ROM(0x8086, 0x108B, "e1000-0x108B", "E1000-0x108B"),
78 PCI_ROM(0x8086, 0x108C, "e1000-0x108C", "E1000-0x108C"),
79 PCI_ROM(0x8086, 0x1096, "e1000-0x1096", "E1000-0x1096"),
80 PCI_ROM(0x8086, 0x1098, "e1000-0x1098", "E1000-0x1098"),
81 PCI_ROM(0x8086, 0x1099, "e1000-0x1099", "E1000-0x1099"),
82 PCI_ROM(0x8086, 0x109A, "e1000-0x109A", "E1000-0x109A"),
83 PCI_ROM(0x8086, 0x10A4, "e1000-0x10A4", "E1000-0x10A4"),
84 PCI_ROM(0x8086, 0x10A5, "e1000-0x10A5", "E1000-0x10A5"),
85 PCI_ROM(0x8086, 0x10B5, "e1000-0x10B5", "E1000-0x10B5"),
86 PCI_ROM(0x8086, 0x10B9, "e1000-0x10B9", "E1000-0x10B9"),
87 PCI_ROM(0x8086, 0x10BA, "e1000-0x10BA", "E1000-0x10BA"),
88 PCI_ROM(0x8086, 0x10BB, "e1000-0x10BB", "E1000-0x10BB"),
89 PCI_ROM(0x8086, 0x10BC, "e1000-0x10BC", "E1000-0x10BC"),
90 PCI_ROM(0x8086, 0x10C4, "e1000-0x10C4", "E1000-0x10C4"),
91 PCI_ROM(0x8086, 0x10C5, "e1000-0x10C5", "E1000-0x10C5"),
92 PCI_ROM(0x8086, 0x10D9, "e1000-0x10D9", "E1000-0x10D9"),
93 PCI_ROM(0x8086, 0x10DA, "e1000-0x10DA", "E1000-0x10DA"),
97 * e1000_get_hw_control - get control of the h/w from f/w
98 * @adapter: address of board private structure
100 * e1000_get_hw_control sets {CTRL_EXT|FWSM}:DRV_LOAD bit.
101 * For ASF and Pass Through versions of f/w this means that
102 * the driver is loaded. For AMT version (only with 82573)
103 * of the f/w this means that the network i/f is open.
107 e1000_get_hw_control(struct e1000_adapter *adapter)
112 DBG ( "e1000_get_hw_control\n" );
114 /* Let firmware know the driver has taken over */
115 switch (adapter->hw.mac_type) {
117 swsm = E1000_READ_REG(&adapter->hw, SWSM);
118 E1000_WRITE_REG(&adapter->hw, SWSM,
119 swsm | E1000_SWSM_DRV_LOAD);
123 case e1000_80003es2lan:
125 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
126 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
127 ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
136 * e1000_power_up_phy - restore link in case the phy was powered down
137 * @adapter: address of board private structure
139 * The phy may be powered down to save power and turn off link when the
140 * driver is unloaded and wake on lan is not enabled (among others)
141 * *** this routine MUST be followed by a call to e1000_reset ***
145 e1000_power_up_phy ( struct e1000_adapter *adapter )
147 DBG ( "e1000_power_up_phy\n" );
149 uint16_t mii_reg = 0;
151 /* Just clear the power down bit to wake the phy back up */
152 if (adapter->hw.media_type == e1000_media_type_copper) {
153 /* according to the manual, the phy will retain its
154 * settings across a power-down/up cycle */
155 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
156 mii_reg &= ~MII_CR_POWER_DOWN;
157 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
162 e1000_power_down_phy ( struct e1000_adapter *adapter )
164 DBG ( "e1000_power_down_phy\n" );
166 /* Power down the PHY so no link is implied when interface is down *
167 * The PHY cannot be powered down if any of the following is TRUE *
170 * (c) SoL/IDER session is active */
171 if (!adapter->wol && adapter->hw.mac_type >= e1000_82540 &&
172 adapter->hw.media_type == e1000_media_type_copper) {
173 uint16_t mii_reg = 0;
175 switch (adapter->hw.mac_type) {
178 case e1000_82545_rev_3:
180 case e1000_82546_rev_3:
182 case e1000_82541_rev_2:
184 case e1000_82547_rev_2:
185 if (E1000_READ_REG(&adapter->hw, MANC) &
192 case e1000_80003es2lan:
194 if (e1000_check_mng_mode(&adapter->hw) ||
195 e1000_check_phy_reset_block(&adapter->hw))
201 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
202 mii_reg |= MII_CR_POWER_DOWN;
203 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
213 * e1000_irq_enable - Enable default interrupt generation settings
214 * @adapter: board private structure
217 e1000_irq_enable ( struct e1000_adapter *adapter )
219 E1000_WRITE_REG ( &adapter->hw, IMS, E1000_IMS_RXT0 |
221 E1000_WRITE_FLUSH ( &adapter->hw );
225 * e1000_irq_disable - Mask off interrupt generation on the NIC
226 * @adapter: board private structure
229 e1000_irq_disable ( struct e1000_adapter *adapter )
231 E1000_WRITE_REG ( &adapter->hw, IMC, ~0 );
232 E1000_WRITE_FLUSH ( &adapter->hw );
236 * e1000_irq_force - trigger interrupt
237 * @adapter: board private structure
240 e1000_irq_force ( struct e1000_adapter *adapter )
242 E1000_WRITE_REG ( &adapter->hw, ICS, E1000_ICS_RXT0 );
243 E1000_WRITE_FLUSH ( &adapter->hw );
247 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
248 * @adapter: board private structure to initialize
250 * e1000_sw_init initializes the Adapter private data structure.
251 * Fields are initialized based on PCI device information and
252 * OS network device settings (MTU size).
255 e1000_sw_init ( struct e1000_adapter *adapter )
257 struct e1000_hw *hw = &adapter->hw;
258 struct pci_device *pdev = adapter->pdev;
260 /* PCI config space info */
262 hw->vendor_id = pdev->vendor;
263 hw->device_id = pdev->device;
265 pci_read_config_word ( pdev, PCI_COMMAND, &hw->pci_cmd_word );
267 /* Disable Flow Control */
268 hw->fc = E1000_FC_NONE;
270 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
271 adapter->rx_ps_bsize0 = E1000_RXBUFFER_128;
272 hw->max_frame_size = E1000_RXBUFFER_2048;
273 hw->min_frame_size = 64;
275 /* identify the MAC */
277 if ( e1000_set_mac_type ( hw ) ) {
278 DBG ( "Unknown MAC Type\n" );
282 switch ( hw->mac_type ) {
287 case e1000_82541_rev_2:
288 case e1000_82547_rev_2:
290 hw->phy_init_script = 1;
295 e1000_set_media_type ( hw );
297 hw->wait_autoneg_complete = FALSE;
298 hw->tbi_compatibility_en = TRUE;
299 hw->adaptive_ifs = TRUE;
303 if ( hw->media_type == e1000_media_type_copper ) {
304 hw->mdix = AUTO_ALL_MODES;
305 hw->disable_polarity_correction = FALSE;
306 hw->master_slave = E1000_MASTER_SLAVE;
309 /* Explicitly disable IRQ since the NIC can be in any state. */
310 e1000_irq_disable ( adapter );
316 * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
317 * @adapter: board private structure
318 * @txdr: tx descriptor ring (for a specific queue) to setup
320 * Return 0 on success, negative on failure
323 e1000_setup_tx_resources ( struct e1000_adapter *adapter )
325 DBG ( "e1000_setup_tx_resources\n" );
327 /* Allocate transmit descriptor ring memory.
328 It must not cross a 64K boundary because of hardware errata #23
329 so we use malloc_dma() requesting a 128 byte block that is
330 128 byte aligned. This should guarantee that the memory
331 allocated will not cross a 64K boundary, because 128 is an
332 even multiple of 65536 ( 65536 / 128 == 512 ), so all possible
333 allocations of 128 bytes on a 128 byte boundary will not
338 malloc_dma ( sizeof ( *adapter->tx_base ) * NUM_TX_DESC,
339 sizeof ( *adapter->tx_base ) * NUM_TX_DESC );
341 if ( ! adapter->tx_base ) {
345 memset ( adapter->tx_base, 0, sizeof ( *adapter->tx_base ) * NUM_TX_DESC );
347 DBG ( "adapter->tx_base = %#08lx\n", virt_to_bus ( adapter->tx_base ) );
349 DBG ( "sizeof ( *adapter->tx_base ) == %d bytes\n",
350 sizeof ( *adapter->tx_base ) );
356 e1000_free_tx_resources ( struct e1000_adapter *adapter )
358 DBG ( "e1000_free_tx_resources\n" );
360 free_dma ( adapter->tx_base,
361 sizeof ( *adapter->tx_base ) * NUM_TX_DESC );
365 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
366 * @adapter: board private structure
368 * Configure the Tx unit of the MAC after a reset.
371 e1000_configure_tx ( struct e1000_adapter *adapter )
373 struct e1000_hw *hw = &adapter->hw;
378 uint32_t ipgr1, ipgr2;
381 DBG ( "e1000_configure_tx\n" );
383 E1000_WRITE_REG ( hw, TDBAH, 0 );
384 E1000_WRITE_REG ( hw, TDBAL, virt_to_bus ( adapter->tx_base ) );
385 E1000_WRITE_REG ( hw, TDLEN, sizeof ( *adapter->tx_base ) * NUM_TX_DESC );
387 DBG ( "TDBAL: %#08lx\n", virt_to_bus ( adapter->tx_base ) );
388 DBG ( "TDLEN: %d\n", sizeof ( *adapter->tx_base ) * NUM_TX_DESC );
390 /* Setup the HW Tx Head and Tail descriptor pointers */
391 E1000_WRITE_REG ( hw, TDH, 0 );
392 E1000_WRITE_REG ( hw, TDT, 0 );
394 adapter->tx_head = 0;
395 adapter->tx_tail = 0;
396 adapter->tx_fill_ctr = 0;
399 /* Set the default values for the Tx Inter Packet Gap timer */
400 if (adapter->hw.mac_type <= e1000_82547_rev_2 &&
401 (hw->media_type == e1000_media_type_fiber ||
402 hw->media_type == e1000_media_type_internal_serdes))
403 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
405 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
407 switch (hw->mac_type) {
408 case e1000_82542_rev2_0:
409 case e1000_82542_rev2_1:
410 tipg = DEFAULT_82542_TIPG_IPGT;
411 ipgr1 = DEFAULT_82542_TIPG_IPGR1;
412 ipgr2 = DEFAULT_82542_TIPG_IPGR2;
414 case e1000_80003es2lan:
415 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
416 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2;
419 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
420 ipgr2 = DEFAULT_82543_TIPG_IPGR2;
423 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
424 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
425 E1000_WRITE_REG ( hw, TIPG, tipg );
427 /* Set the Tx Interrupt Delay register */
429 E1000_WRITE_REG (hw, TIDV, adapter->tx_int_delay);
430 if (hw->mac_type >= e1000_82540)
431 E1000_WRITE_REG(hw, TADV, adapter->tx_abs_int_delay);
433 /* Program the Transmit Control Register */
435 tctl = E1000_READ_REG(hw, TCTL);
436 tctl &= ~E1000_TCTL_CT;
437 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
438 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
440 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) {
441 tarc = E1000_READ_REG(hw, TARC0);
442 /* set the speed mode bit, we'll clear it if we're not at
443 * gigabit link later */
445 E1000_WRITE_REG(hw, TARC0, tarc);
446 } else if (hw->mac_type == e1000_80003es2lan) {
447 tarc = E1000_READ_REG(hw, TARC0);
449 E1000_WRITE_REG(hw, TARC0, tarc);
450 tarc = E1000_READ_REG(hw, TARC1);
452 E1000_WRITE_REG(hw, TARC1, tarc);
456 e1000_config_collision_dist ( hw );
458 tctl = E1000_TCTL_PSP | E1000_TCTL_EN |
459 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT) |
460 (E1000_HDX_COLLISION_DISTANCE << E1000_COLD_SHIFT);
463 /* Setup Transmit Descriptor Settings for eop descriptor */
464 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
466 /* only set IDE if we are delaying interrupts using the timers */
467 if (adapter->tx_int_delay)
468 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
470 if (hw->mac_type < e1000_82543)
471 adapter->txd_cmd |= E1000_TXD_CMD_RPS;
473 adapter->txd_cmd |= E1000_TXD_CMD_RS;
475 /* Cache if we're 82544 running in PCI-X because we'll
476 * need this to apply a workaround later in the send path. */
477 if (hw->mac_type == e1000_82544 &&
478 hw->bus_type == e1000_bus_type_pcix)
479 adapter->pcix_82544 = 1;
482 E1000_WRITE_REG ( hw, TCTL, tctl );
486 * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
487 * @adapter: board private structure
488 * @rxdr: rx descriptor ring (for a specific queue) to setup
490 * Returns 0 on success, negative on failure
493 e1000_setup_rx_resources ( struct e1000_adapter *adapter )
496 struct e1000_rx_desc *rx_curr_desc;
498 DBG ( "e1000_setup_rx_resources\n" );
500 /* Allocate receive descriptor ring memory.
501 It must not cross a 64K boundary because of hardware errata
505 malloc_dma ( sizeof ( *adapter->rx_base ) * NUM_RX_DESC,
506 sizeof ( *adapter->rx_base ) * NUM_RX_DESC );
508 if ( ! adapter->rx_base ) {
511 memset ( adapter->rx_base, 0, sizeof ( *adapter->rx_base ) * NUM_RX_DESC );
513 for ( i = 0; i < NUM_RX_DESC; i++ ) {
515 adapter->rx_iobuf[i] = alloc_iob ( E1000_RXBUFFER_2048 );
517 /* If unable to allocate all iobufs, free any that
518 * were successfully allocated, and return an error
520 if ( ! adapter->rx_iobuf[i] ) {
521 for ( j = 0; j < i; j++ ) {
522 free_iob ( adapter->rx_iobuf[j] );
527 rx_curr_desc = ( void * ) ( adapter->rx_base ) +
528 ( i * sizeof ( *adapter->rx_base ) );
530 rx_curr_desc->buffer_addr = virt_to_bus ( adapter->rx_iobuf[i]->data );
531 DBG ( "i = %d rx_curr_desc->buffer_addr = %#16llx\n",
532 i, rx_curr_desc->buffer_addr );
539 e1000_free_rx_resources ( struct e1000_adapter *adapter )
543 DBG ( "e1000_free_rx_resources\n" );
545 free_dma ( adapter->rx_base,
546 sizeof ( *adapter->rx_base ) * NUM_RX_DESC );
548 for ( i = 0; i < NUM_RX_DESC; i++ ) {
549 free_iob ( adapter->rx_iobuf[i] );
554 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
555 * @adapter: board private structure
557 * Configure the Rx unit of the MAC after a reset.
560 e1000_configure_rx ( struct e1000_adapter *adapter )
562 struct e1000_hw *hw = &adapter->hw;
569 DBG ( "e1000_configure_rx\n" );
571 /* disable receives while setting up the descriptors */
572 rctl = E1000_READ_REG ( hw, RCTL );
573 E1000_WRITE_REG ( hw, RCTL, rctl & ~E1000_RCTL_EN );
575 /* set the Receive Delay Timer Register */
576 E1000_WRITE_REG ( hw, RDTR, adapter->rx_int_delay );
577 E1000_WRITE_REG ( hw, RADV, adapter->rx_abs_int_delay );
580 if (hw->mac_type >= e1000_82540) {
581 E1000_WRITE_REG(hw, RADV, adapter->rx_abs_int_delay);
582 if (adapter->itr_setting != 0)
583 E1000_WRITE_REG(hw, ITR,
584 1000000000 / (adapter->itr * 256));
587 if (hw->mac_type >= e1000_82571) {
588 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
589 /* Reset delay timers after every interrupt */
590 ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR;
591 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
592 E1000_WRITE_FLUSH(hw);
596 /* Setup the HW Rx Head and Tail Descriptor Pointers and
597 * the Base and Length of the Rx Descriptor Ring */
599 adapter->rx_tail = 0;
601 E1000_WRITE_REG ( hw, RDBAH, 0 );
602 E1000_WRITE_REG ( hw, RDBAL, virt_to_bus ( adapter->rx_base ) );
603 E1000_WRITE_REG ( hw, RDLEN, sizeof ( *adapter->rx_base ) *
606 E1000_WRITE_REG ( hw, RDH, 0);
607 E1000_WRITE_REG ( hw, RDT, 0);
609 E1000_WRITE_REG ( hw, RCTL, E1000_RCTL_EN | E1000_RCTL_BAM |
610 E1000_RCTL_SZ_2048 | E1000_RCTL_MPE);
611 E1000_WRITE_FLUSH ( hw );
613 /* Enable Receives */
614 E1000_WRITE_REG ( hw, RCTL, rctl );
618 * e1000_reset - Put e1000 NIC in known initial state
620 * @v adapter e1000 private structure
623 e1000_reset ( struct e1000_adapter *adapter )
626 uint16_t fc_high_water_mark = E1000_FC_HIGH_DIFF;
628 DBG ( "e1000_reset\n" );
630 switch (adapter->hw.mac_type) {
631 case e1000_82542_rev2_0:
632 case e1000_82542_rev2_1:
637 case e1000_82541_rev_2:
641 case e1000_82545_rev_3:
643 case e1000_82546_rev_3:
647 case e1000_82547_rev_2:
652 case e1000_80003es2lan:
660 case e1000_undefined:
665 E1000_WRITE_REG ( &adapter->hw, PBA, pba );
667 /* flow control settings */
668 /* Set the FC high water mark to 90% of the FIFO size.
669 * Required to clear last 3 LSB */
670 fc_high_water_mark = ((pba * 9216)/10) & 0xFFF8;
671 /* We can't use 90% on small FIFOs because the remainder
672 * would be less than 1 full frame. In this case, we size
673 * it to allow at least a full frame above the high water
675 if (pba < E1000_PBA_16K)
676 fc_high_water_mark = (pba * 1024) - 1600;
678 adapter->hw.fc_high_water = fc_high_water_mark;
679 adapter->hw.fc_low_water = fc_high_water_mark - 8;
680 if (adapter->hw.mac_type == e1000_80003es2lan)
681 adapter->hw.fc_pause_time = 0xFFFF;
683 adapter->hw.fc_pause_time = E1000_FC_PAUSE_TIME;
684 adapter->hw.fc_send_xon = 1;
685 adapter->hw.fc = adapter->hw.original_fc;
686 /* Allow time for pending master requests to run */
688 e1000_reset_hw ( &adapter->hw );
690 if ( adapter->hw.mac_type >= e1000_82544 )
691 E1000_WRITE_REG ( &adapter->hw, WUC, 0 );
693 if ( e1000_init_hw ( &adapter->hw ) )
694 DBG ( "Hardware Error\n" );
696 /* if (adapter->hwflags & HWFLAGS_PHY_PWR_BIT) { */
697 if (adapter->hw.mac_type >= e1000_82544 &&
698 adapter->hw.mac_type <= e1000_82547_rev_2 &&
699 adapter->hw.autoneg == 1 &&
700 adapter->hw.autoneg_advertised == ADVERTISE_1000_FULL) {
701 uint32_t ctrl = E1000_READ_REG(&adapter->hw, CTRL);
702 /* clear phy power management bit if we are in gig only mode,
703 * which if enabled will attempt negotiation to 100Mb, which
704 * can cause a loss of link at power off or driver unload */
705 ctrl &= ~E1000_CTRL_SWDPIN3;
706 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
709 e1000_phy_get_info ( &adapter->hw, &adapter->phy_info );
711 if (!adapter->smart_power_down &&
712 (adapter->hw.mac_type == e1000_82571 ||
713 adapter->hw.mac_type == e1000_82572)) {
714 uint16_t phy_data = 0;
715 /* speed up time to link by disabling smart power down, ignore
716 * the return value of this function because there is nothing
717 * different we would do if it failed */
718 e1000_read_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT,
720 phy_data &= ~IGP02E1000_PM_SPD;
721 e1000_write_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT,
726 /** Functions that implement the gPXE driver API **/
729 * e1000_close - Disables a network interface
731 * @v netdev network interface device structure
735 e1000_close ( struct net_device *netdev )
737 struct e1000_adapter *adapter = netdev_priv ( netdev );
739 DBG ( "e1000_close\n" );
741 e1000_irq_disable ( adapter );
743 e1000_reset_hw ( &adapter->hw );
745 e1000_free_tx_resources ( adapter );
746 e1000_free_rx_resources ( adapter );
750 * e1000_transmit - Transmit a packet
752 * @v netdev Network device
753 * @v iobuf I/O buffer
755 * @ret rc Return status code
758 e1000_transmit ( struct net_device *netdev, struct io_buffer *iobuf )
760 struct e1000_adapter *adapter = netdev_priv( netdev );
761 struct e1000_hw *hw = &adapter->hw;
762 uint32_t tx_curr = adapter->tx_tail;
763 struct e1000_tx_desc *tx_curr_desc;
765 DBG ("e1000_transmit\n");
767 if ( adapter->tx_fill_ctr == NUM_TX_DESC ) {
768 DBG ("TX overflow\n");
772 /* Save pointer to iobuf we have been given to transmit,
773 netdev_tx_complete() will need it later
775 adapter->tx_iobuf[tx_curr] = iobuf;
777 tx_curr_desc = ( void * ) ( adapter->tx_base ) +
778 ( tx_curr * sizeof ( *adapter->tx_base ) );
780 DBG ( "tx_curr_desc = %#08lx\n", virt_to_bus ( tx_curr_desc ) );
781 DBG ( "tx_curr_desc + 16 = %#08lx\n", virt_to_bus ( tx_curr_desc ) + 16 );
782 DBG ( "iobuf->data = %#08lx\n", virt_to_bus ( iobuf->data ) );
784 /* Add the packet to TX ring
786 tx_curr_desc->buffer_addr =
787 virt_to_bus ( iobuf->data );
788 tx_curr_desc->lower.data =
789 E1000_TXD_CMD_RPS | E1000_TXD_CMD_EOP |
790 E1000_TXD_CMD_IFCS | iob_len ( iobuf );
791 tx_curr_desc->upper.data = 0;
793 DBG ( "TX fill: %ld tx_curr: %ld addr: %#08lx len: %d\n", adapter->tx_fill_ctr,
794 tx_curr, virt_to_bus ( iobuf->data ), iob_len ( iobuf ) );
796 /* Point to next free descriptor */
797 adapter->tx_tail = ( adapter->tx_tail + 1 ) % NUM_TX_DESC;
798 adapter->tx_fill_ctr++;
800 /* Write new tail to NIC, making packet available for transmit
802 E1000_WRITE_REG ( hw, TDT, adapter->tx_tail );
805 while ( ! ( tx_curr_desc->upper.data & E1000_TXD_STAT_DD ) ) {
806 udelay ( 10 ); /* give the nic a chance to write to the register */
809 DBG ( "Leaving XMIT\n" );
816 * e1000_poll - Poll for received packets
818 * @v netdev Network device
821 e1000_poll ( struct net_device *netdev )
823 struct e1000_adapter *adapter = netdev_priv( netdev );
824 struct e1000_hw *hw = &adapter->hw;
831 struct io_buffer *rx_iob;
832 struct e1000_tx_desc *tx_curr_desc;
833 struct e1000_rx_desc *rx_curr_desc;
837 DBG ( "e1000_poll\n" );
840 /* Acknowledge interrupt. */
841 icr = E1000_READ_REG ( hw, ICR );
845 DBG ( "e1000_poll: intr_status = %#08lx\n", icr );
847 /* Check status of transmitted packets
849 while ( ( i = adapter->tx_head ) != adapter->tx_tail ) {
851 tx_curr_desc = ( void * ) ( adapter->tx_base ) +
852 ( i * sizeof ( *adapter->tx_base ) );
854 tx_status = tx_curr_desc->upper.data;
857 DBG ( "tx_curr_desc = %#08lx status = %#08lx\n",
858 virt_to_bus ( tx_curr_desc ), tx_status );
861 /* if the packet at tx_head is not owned by hardware */
862 if ( ! ( tx_status & E1000_TXD_STAT_DD ) )
865 DBG ( "Sent packet. tx_head: %ld tx_tail: %ld tx_status: %#08lx\n",
866 adapter->tx_head, adapter->tx_tail, tx_status );
868 if ( tx_status & ( E1000_TXD_STAT_EC | E1000_TXD_STAT_LC |
869 E1000_TXD_STAT_TU ) ) {
870 netdev_tx_complete_err ( netdev, adapter->tx_iobuf[i], -EINVAL );
871 DBG ( "Error transmitting packet, tx_status: %#08lx\n",
874 netdev_tx_complete ( netdev, adapter->tx_iobuf[i] );
875 DBG ( "Success transmitting packet, tx_status: %#08lx\n",
879 /* Decrement count of used descriptors, clear this descriptor
881 adapter->tx_fill_ctr--;
882 memset ( tx_curr_desc, 0, sizeof ( *tx_curr_desc ) );
884 adapter->tx_head = ( adapter->tx_head + 1 ) % NUM_TX_DESC;
887 /* Process received packets
891 i = adapter->rx_tail;
893 rx_curr_desc = ( void * ) ( adapter->rx_base ) +
894 ( i * sizeof ( *adapter->rx_base ) );
895 rx_status = rx_curr_desc->status;
897 // DBG ( "Before DD Check RX_status: %#08lx\n", rx_status );
899 if ( ! ( rx_status & E1000_RXD_STAT_DD ) )
902 DBG ( "RCTL = %#08lx\n", E1000_READ_REG ( &adapter->hw, RCTL ) );
904 rx_len = rx_curr_desc->length;
906 DBG ( "Received packet, rx_tail: %ld rx_status: %#08lx rx_len: %ld\n",
907 i, rx_status, rx_len );
909 rx_err = rx_curr_desc->errors;
911 if ( rx_err & E1000_RXD_ERR_FRAME_ERR_MASK ) {
913 netdev_rx_err ( netdev, NULL, -EINVAL );
914 DBG ( "e1000_poll: Corrupted packet received!"
915 " rx_err: %#08lx\n", rx_err );
918 /* If unable allocate space for this packet,
919 * try again next poll
921 rx_iob = alloc_iob ( rx_len );
925 memcpy ( iob_put ( rx_iob, rx_len ),
926 adapter->rx_iobuf[i]->data, rx_len );
928 /* Add this packet to the receive queue.
930 netdev_rx ( netdev, rx_iob );
933 memset ( rx_curr_desc, 0, sizeof ( *rx_curr_desc ) );
935 rx_curr_desc->buffer_addr = virt_to_bus ( adapter->rx_iobuf[adapter->rx_tail]->data );
937 adapter->rx_tail = ( adapter->rx_tail + 1 ) % NUM_RX_DESC;
939 E1000_WRITE_REG ( hw, RDT, adapter->rx_tail );
944 * e1000_irq - enable or Disable interrupts
946 * @v adapter e1000 adapter
947 * @v action requested interrupt action
950 e1000_irq ( struct net_device *netdev, int enable )
952 struct e1000_adapter *adapter = netdev_priv(netdev);
954 DBG ( "e1000_irq\n" );
958 e1000_irq_enable ( adapter );
961 e1000_irq_disable ( adapter );
964 e1000_irq_force ( adapter );
969 static struct net_device_operations e1000_operations;
972 * e1000_probe - Initial configuration of e1000 NIC
977 * @ret rc Return status code
980 e1000_probe ( struct pci_device *pdev,
981 const struct pci_device_id *id __unused )
984 struct net_device *netdev;
985 struct e1000_adapter *adapter;
986 unsigned long mmio_start, mmio_len;
987 unsigned long flash_start, flash_len;
989 DBG ( "e1000_probe\n" );
993 /* Allocate net device ( also allocates memory for netdev->priv
994 and makes netdev-priv point to it ) */
995 netdev = alloc_etherdev ( sizeof ( struct e1000_adapter ) );
997 goto err_alloc_etherdev;
999 /* Associate e1000-specific network operations operations with
1000 * generic network device layer */
1001 netdev_init ( netdev, &e1000_operations );
1003 /* Associate this network device with given PCI device */
1004 pci_set_drvdata ( pdev, netdev );
1005 netdev->dev = &pdev->dev;
1007 /* Initialize driver private storage */
1008 adapter = netdev_priv ( netdev );
1009 memset ( adapter, 0, ( sizeof ( *adapter ) ) );
1011 adapter->hw.io_base = pdev->ioaddr;
1012 adapter->ioaddr = pdev->ioaddr;
1013 adapter->irqno = pdev->irq;
1014 adapter->netdev = netdev;
1015 adapter->pdev = pdev;
1016 adapter->hw.back = adapter;
1017 adapter->eeprom_wol = 0;
1018 adapter->wol = adapter->eeprom_wol;
1020 adapter->en_mng_pt = 0;
1021 adapter->rx_int_delay = 0;
1022 adapter->rx_abs_int_delay = 0;
1024 mmio_start = pci_bar_start ( pdev, PCI_BASE_ADDRESS_0 );
1025 mmio_len = pci_bar_size ( pdev, PCI_BASE_ADDRESS_0 );
1027 DBG ( "mmio_start: %#08lx\n", mmio_start );
1028 DBG ( "mmio_len: %#08lx\n", mmio_len );
1030 /* Fix up PCI device */
1031 adjust_pci_device ( pdev );
1035 adapter->hw.hw_addr = ioremap ( mmio_start, mmio_len );
1037 DBG ( "adapter->hw.hw_addr: %p\n", adapter->hw.hw_addr );
1039 if ( ! adapter->hw.hw_addr )
1042 /* setup the private structure */
1043 if ( ( err = e1000_sw_init ( adapter ) ) )
1046 DBG ( "adapter->hw.mac_type: %#08x\n", adapter->hw.mac_type );
1048 /* Flash BAR mapping must happen after e1000_sw_init
1049 * because it depends on mac_type
1051 if ( ( adapter->hw.mac_type == e1000_ich8lan ) && ( pdev->ioaddr ) ) {
1052 flash_start = pci_bar_start ( pdev, 1 );
1053 flash_len = pci_bar_size ( pdev, 1 );
1054 adapter->hw.flash_address = ioremap ( flash_start, flash_len );
1055 if ( ! adapter->hw.flash_address )
1059 /* initialize eeprom parameters */
1060 if ( e1000_init_eeprom_params ( &adapter->hw ) ) {
1061 DBG ( "EEPROM initialization failed\n" );
1065 /* before reading the EEPROM, reset the controller to
1066 * put the device in a known good starting state
1068 err = e1000_reset_hw ( &adapter->hw );
1070 DBG ( "Hardware Initialization Failed\n" );
1074 /* make sure the EEPROM is good */
1075 if ( e1000_validate_eeprom_checksum( &adapter->hw ) < 0 ) {
1076 DBG ( "The EEPROM Checksum Is Not Valid\n" );
1080 /* copy the MAC address out of the EEPROM */
1081 if ( e1000_read_mac_addr ( &adapter->hw ) )
1082 DBG ( "EEPROM Read Error\n" );
1084 memcpy ( netdev->ll_addr, adapter->hw.mac_addr, ETH_ALEN );
1086 /* print bus type/speed/width info */
1088 struct e1000_hw *hw = &adapter->hw;
1089 DBG ( "(PCI%s:%s:%s) ",
1090 ((hw->bus_type == e1000_bus_type_pcix) ? "-X" :
1091 (hw->bus_type == e1000_bus_type_pci_express ? " Express":"")),
1092 ((hw->bus_speed == e1000_bus_speed_2500) ? "2.5Gb/s" :
1093 (hw->bus_speed == e1000_bus_speed_133) ? "133MHz" :
1094 (hw->bus_speed == e1000_bus_speed_120) ? "120MHz" :
1095 (hw->bus_speed == e1000_bus_speed_100) ? "100MHz" :
1096 (hw->bus_speed == e1000_bus_speed_66) ? "66MHz" : "33MHz"),
1097 ((hw->bus_width == e1000_bus_width_64) ? "64-bit" :
1098 (hw->bus_width == e1000_bus_width_pciex_4) ? "Width x4" :
1099 (hw->bus_width == e1000_bus_width_pciex_1) ? "Width x1" :
1102 for (i = 0; i < 6; i++)
1103 DBG ("%02x%s", netdev->ll_addr[i], i == 5 ? "\n" : ":");
1105 /* reset the hardware with the new settings */
1106 e1000_reset ( adapter );
1108 e1000_get_hw_control ( adapter );
1110 if ( ( err = register_netdev ( netdev ) ) != 0)
1113 DBG ( "e1000_probe succeeded!\n" );
1115 /* No errors, return success */
1118 /* Error return paths */
1122 if ( ! e1000_check_phy_reset_block ( &adapter->hw ) )
1123 e1000_phy_hw_reset ( &adapter->hw );
1124 if ( adapter->hw.flash_address )
1125 iounmap ( adapter->hw.flash_address );
1128 iounmap ( adapter->hw.hw_addr );
1130 netdev_put ( netdev );
1136 * e1000_remove - Device Removal Routine
1138 * @v pdev PCI device information struct
1142 e1000_remove ( struct pci_device *pdev )
1144 struct net_device *netdev = pci_get_drvdata ( pdev );
1145 struct e1000_adapter *adapter = netdev_priv ( netdev );
1147 DBG ( "e1000_remove\n" );
1149 e1000_reset_hw ( &adapter->hw );
1150 unregister_netdev ( netdev );
1151 netdev_put ( netdev );
1155 * e1000_open - Called when a network interface is made active
1157 * @v netdev network interface device structure
1158 * @ret rc Return status code, 0 on success, negative value on failure
1162 e1000_open ( struct net_device *netdev )
1164 struct e1000_adapter *adapter = netdev_priv(netdev);
1167 DBG ( "e1000_open\n" );
1169 /* allocate transmit descriptors */
1170 err = e1000_setup_tx_resources ( adapter );
1173 DBG ( "Error setting up TX resources!\n" );
1176 /* allocate receive descriptors */
1177 err = e1000_setup_rx_resources ( adapter );
1179 DBG ( "Error setting up RX resources!\n" );
1183 e1000_configure_tx ( adapter );
1185 e1000_configure_rx ( adapter );
1187 e1000_irq_enable ( adapter );
1189 return E1000_SUCCESS;
1192 e1000_free_tx_resources ( adapter );
1194 e1000_reset ( adapter );
1199 struct pci_driver e1000_driver __pci_driver = {
1201 .id_count = (sizeof (e1000_nics) / sizeof (e1000_nics[0])),
1202 .probe = e1000_probe,
1203 .remove = e1000_remove,
1206 /** e1000 net device operations */
1207 static struct net_device_operations e1000_operations = {
1209 .close = e1000_close,
1210 .transmit = e1000_transmit,
1216 e1000_read_pcie_cap_reg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
1218 struct e1000_adapter *adapter = hw->back;
1219 uint16_t cap_offset;
1221 #define PCI_CAP_ID_EXP 0x10 /* PCI Express */
1222 cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP);
1224 return -E1000_ERR_CONFIG;
1226 pci_read_config_word(adapter->pdev, cap_offset + reg, value);
1228 return E1000_SUCCESS;
1232 e1000_pci_clear_mwi ( struct e1000_hw *hw __unused )
1237 e1000_pci_set_mwi ( struct e1000_hw *hw __unused )
1242 e1000_read_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
1244 struct e1000_adapter *adapter = hw->back;
1246 pci_read_config_word(adapter->pdev, reg, value);
1250 e1000_write_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
1252 struct e1000_adapter *adapter = hw->back;
1254 pci_write_config_word(adapter->pdev, reg, *value);
1258 e1000_io_write ( struct e1000_hw *hw __unused, unsigned long port, uint32_t value )
1260 outl ( value, port );