2 * gPXE driver for Intel eepro1000 ethernet cards
4 * Written by Marty Connor
6 * Copyright Entity Cyber, Inc. 2007
8 * This software may be used and distributed according to the terms of
9 * the GNU General Public License (GPL), incorporated herein by
10 * reference. Drivers based on or derived from this code fall under
11 * the GPL and must retain the authorship, copyright and license
16 /*******************************************************************************
18 Intel PRO/1000 Linux driver
19 Copyright(c) 1999 - 2006 Intel Corporation.
21 This program is free software; you can redistribute it and/or modify it
22 under the terms and conditions of the GNU General Public License,
23 version 2, as published by the Free Software Foundation.
25 This program is distributed in the hope it will be useful, but WITHOUT
26 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
27 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
30 You should have received a copy of the GNU General Public License along with
31 this program; if not, write to the Free Software Foundation, Inc.,
32 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
34 The full GNU General Public License is included in this distribution in
35 the file called "COPYING".
38 Linux NICS <linux.nics@intel.com>
39 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
40 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
42 *******************************************************************************/
44 FILE_LICENCE ( GPL2_ONLY );
49 * e1000_get_hw_control - get control of the h/w from f/w
51 * @v adapter e1000 private structure
53 * e1000_get_hw_control sets {CTRL_EXT|FWSM}:DRV_LOAD bit.
54 * For ASF and Pass Through versions of f/w this means that
55 * the driver is loaded. For AMT version (only with 82573)
56 * of the f/w this means that the network i/f is open.
60 e1000_get_hw_control ( struct e1000_adapter *adapter )
65 DBG ( "e1000_get_hw_control\n" );
67 /* Let firmware know the driver has taken over */
68 switch (adapter->hw.mac_type) {
70 swsm = E1000_READ_REG(&adapter->hw, SWSM);
71 E1000_WRITE_REG(&adapter->hw, SWSM,
72 swsm | E1000_SWSM_DRV_LOAD);
76 case e1000_80003es2lan:
78 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
79 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
80 ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
88 * e1000_irq_enable - Enable default interrupt generation settings
90 * @v adapter e1000 private structure
93 e1000_irq_enable ( struct e1000_adapter *adapter )
95 E1000_WRITE_REG ( &adapter->hw, IMS, E1000_IMS_RXDMT0 |
97 E1000_WRITE_FLUSH ( &adapter->hw );
101 * e1000_irq_disable - Mask off interrupt generation on the NIC
103 * @v adapter e1000 private structure
106 e1000_irq_disable ( struct e1000_adapter *adapter )
108 E1000_WRITE_REG ( &adapter->hw, IMC, ~0 );
109 E1000_WRITE_FLUSH ( &adapter->hw );
113 * e1000_irq_force - trigger interrupt
115 * @v adapter e1000 private structure
118 e1000_irq_force ( struct e1000_adapter *adapter )
120 E1000_WRITE_REG ( &adapter->hw, ICS, E1000_ICS_RXDMT0 );
121 E1000_WRITE_FLUSH ( &adapter->hw );
125 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
127 * @v adapter e1000 private structure
129 * e1000_sw_init initializes the Adapter private data structure.
130 * Fields are initialized based on PCI device information and
131 * OS network device settings (MTU size).
134 e1000_sw_init ( struct e1000_adapter *adapter )
136 struct e1000_hw *hw = &adapter->hw;
137 struct pci_device *pdev = adapter->pdev;
139 /* PCI config space info */
141 hw->vendor_id = pdev->vendor;
142 hw->device_id = pdev->device;
144 pci_read_config_word ( pdev, PCI_COMMAND, &hw->pci_cmd_word );
146 /* Disable Flow Control */
147 hw->fc = E1000_FC_NONE;
149 adapter->eeprom_wol = 0;
150 adapter->wol = adapter->eeprom_wol;
151 adapter->en_mng_pt = 0;
152 adapter->rx_int_delay = 0;
153 adapter->rx_abs_int_delay = 0;
155 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
156 adapter->rx_ps_bsize0 = E1000_RXBUFFER_128;
157 hw->max_frame_size = MAXIMUM_ETHERNET_VLAN_SIZE +
158 ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
159 hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE;
161 /* identify the MAC */
163 if ( e1000_set_mac_type ( hw ) ) {
164 DBG ( "Unknown MAC Type\n" );
168 switch ( hw->mac_type ) {
173 case e1000_82541_rev_2:
174 case e1000_82547_rev_2:
175 hw->phy_init_script = 1;
179 e1000_set_media_type ( hw );
182 hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
183 hw->wait_autoneg_complete = TRUE;
185 hw->tbi_compatibility_en = TRUE;
186 hw->adaptive_ifs = TRUE;
190 if ( hw->media_type == e1000_media_type_copper ) {
191 hw->mdix = AUTO_ALL_MODES;
192 hw->disable_polarity_correction = FALSE;
193 hw->master_slave = E1000_MASTER_SLAVE;
196 e1000_irq_disable ( adapter );
202 * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
204 * @v adapter e1000 private structure
206 * @ret rc Returns 0 on success, negative on failure
209 e1000_setup_tx_resources ( struct e1000_adapter *adapter )
211 DBG ( "e1000_setup_tx_resources\n" );
213 /* Allocate transmit descriptor ring memory.
214 It must not cross a 64K boundary because of hardware errata #23
215 so we use malloc_dma() requesting a 128 byte block that is
216 128 byte aligned. This should guarantee that the memory
217 allocated will not cross a 64K boundary, because 128 is an
218 even multiple of 65536 ( 65536 / 128 == 512 ), so all possible
219 allocations of 128 bytes on a 128 byte boundary will not
224 malloc_dma ( adapter->tx_ring_size, adapter->tx_ring_size );
226 if ( ! adapter->tx_base ) {
230 memset ( adapter->tx_base, 0, adapter->tx_ring_size );
232 DBG ( "adapter->tx_base = %#08lx\n", virt_to_bus ( adapter->tx_base ) );
238 e1000_free_tx_resources ( struct e1000_adapter *adapter )
240 DBG ( "e1000_free_tx_resources\n" );
242 free_dma ( adapter->tx_base, adapter->tx_ring_size );
246 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
247 * @adapter: board private structure
249 * Configure the Tx unit of the MAC after a reset.
252 e1000_configure_tx ( struct e1000_adapter *adapter )
254 struct e1000_hw *hw = &adapter->hw;
257 DBG ( "e1000_configure_tx\n" );
259 E1000_WRITE_REG ( hw, TDBAH, 0 );
260 E1000_WRITE_REG ( hw, TDBAL, virt_to_bus ( adapter->tx_base ) );
261 E1000_WRITE_REG ( hw, TDLEN, adapter->tx_ring_size );
263 DBG ( "TDBAL: %#08x\n", E1000_READ_REG ( hw, TDBAL ) );
264 DBG ( "TDLEN: %d\n", E1000_READ_REG ( hw, TDLEN ) );
266 /* Setup the HW Tx Head and Tail descriptor pointers */
267 E1000_WRITE_REG ( hw, TDH, 0 );
268 E1000_WRITE_REG ( hw, TDT, 0 );
270 adapter->tx_head = 0;
271 adapter->tx_tail = 0;
272 adapter->tx_fill_ctr = 0;
274 /* Setup Transmit Descriptor Settings for eop descriptor */
275 tctl = E1000_TCTL_PSP | E1000_TCTL_EN |
276 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT) |
277 (E1000_HDX_COLLISION_DISTANCE << E1000_COLD_SHIFT);
279 e1000_config_collision_dist ( hw );
281 E1000_WRITE_REG ( hw, TCTL, tctl );
282 E1000_WRITE_FLUSH ( hw );
286 * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
288 * @v adapter e1000 private structure
290 * @ret rc Returns 0 on success, negative on failure
293 e1000_setup_rx_resources ( struct e1000_adapter *adapter )
296 struct e1000_rx_desc *rx_curr_desc;
298 DBG ( "e1000_setup_rx_resources\n" );
300 /* Allocate receive descriptor ring memory.
301 It must not cross a 64K boundary because of hardware errata
305 malloc_dma ( adapter->rx_ring_size, adapter->rx_ring_size );
307 if ( ! adapter->rx_base ) {
310 memset ( adapter->rx_base, 0, adapter->rx_ring_size );
312 for ( i = 0; i < NUM_RX_DESC; i++ ) {
314 adapter->rx_iobuf[i] = alloc_iob ( MAXIMUM_ETHERNET_VLAN_SIZE );
316 /* If unable to allocate all iobufs, free any that
317 * were successfully allocated, and return an error
319 if ( ! adapter->rx_iobuf[i] ) {
320 for ( j = 0; j < i; j++ ) {
321 free_iob ( adapter->rx_iobuf[j] );
326 rx_curr_desc = ( void * ) ( adapter->rx_base ) +
327 ( i * sizeof ( *adapter->rx_base ) );
329 rx_curr_desc->buffer_addr = virt_to_bus ( adapter->rx_iobuf[i]->data );
331 DBG ( "i = %d rx_curr_desc->buffer_addr = %#16llx\n",
332 i, rx_curr_desc->buffer_addr );
339 e1000_free_rx_resources ( struct e1000_adapter *adapter )
343 DBG ( "e1000_free_rx_resources\n" );
345 free_dma ( adapter->rx_base, adapter->rx_ring_size );
347 for ( i = 0; i < NUM_RX_DESC; i++ ) {
348 free_iob ( adapter->rx_iobuf[i] );
353 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
354 * @adapter: board private structure
356 * Configure the Rx unit of the MAC after a reset.
359 e1000_configure_rx ( struct e1000_adapter *adapter )
361 struct e1000_hw *hw = &adapter->hw;
364 DBG ( "e1000_configure_rx\n" );
366 /* disable receives while setting up the descriptors */
367 rctl = E1000_READ_REG ( hw, RCTL );
368 E1000_WRITE_REG ( hw, RCTL, rctl & ~E1000_RCTL_EN );
370 adapter->rx_curr = 0;
372 /* Setup the HW Rx Head and Tail Descriptor Pointers and
373 * the Base and Length of the Rx Descriptor Ring */
375 E1000_WRITE_REG ( hw, RDBAL, virt_to_bus ( adapter->rx_base ) );
376 E1000_WRITE_REG ( hw, RDBAH, 0 );
377 E1000_WRITE_REG ( hw, RDLEN, adapter->rx_ring_size );
379 E1000_WRITE_REG ( hw, RDH, 0 );
380 E1000_WRITE_REG ( hw, RDT, NUM_RX_DESC - 1 );
382 /* Enable Receives */
383 rctl = ( E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_SZ_2048 |
387 E1000_WRITE_REG ( hw, RCTL, rctl );
388 E1000_WRITE_FLUSH ( hw );
390 DBG ( "RDBAL: %#08x\n", E1000_READ_REG ( hw, RDBAL ) );
391 DBG ( "RDLEN: %d\n", E1000_READ_REG ( hw, RDLEN ) );
392 DBG ( "RCTL: %#08x\n", E1000_READ_REG ( hw, RCTL ) );
396 * e1000_reset - Put e1000 NIC in known initial state
398 * @v adapter e1000 private structure
401 e1000_reset ( struct e1000_adapter *adapter )
404 uint16_t fc_high_water_mark = E1000_FC_HIGH_DIFF;
406 DBG ( "e1000_reset\n" );
408 switch (adapter->hw.mac_type) {
409 case e1000_82542_rev2_0:
410 case e1000_82542_rev2_1:
415 case e1000_82541_rev_2:
419 case e1000_82545_rev_3:
421 case e1000_82546_rev_3:
425 case e1000_82547_rev_2:
430 case e1000_80003es2lan:
438 case e1000_undefined:
443 E1000_WRITE_REG ( &adapter->hw, PBA, pba );
445 /* flow control settings */
446 /* Set the FC high water mark to 90% of the FIFO size.
447 * Required to clear last 3 LSB */
448 fc_high_water_mark = ((pba * 9216)/10) & 0xFFF8;
449 /* We can't use 90% on small FIFOs because the remainder
450 * would be less than 1 full frame. In this case, we size
451 * it to allow at least a full frame above the high water
453 if (pba < E1000_PBA_16K)
454 fc_high_water_mark = (pba * 1024) - 1600;
456 adapter->hw.fc_high_water = fc_high_water_mark;
457 adapter->hw.fc_low_water = fc_high_water_mark - 8;
458 if (adapter->hw.mac_type == e1000_80003es2lan)
459 adapter->hw.fc_pause_time = 0xFFFF;
461 adapter->hw.fc_pause_time = E1000_FC_PAUSE_TIME;
462 adapter->hw.fc_send_xon = 1;
463 adapter->hw.fc = adapter->hw.original_fc;
464 /* Allow time for pending master requests to run */
466 e1000_reset_hw ( &adapter->hw );
468 if ( adapter->hw.mac_type >= e1000_82544 )
469 E1000_WRITE_REG ( &adapter->hw, WUC, 0 );
471 if ( e1000_init_hw ( &adapter->hw ) )
472 DBG ( "Hardware Error\n" );
474 /* if (adapter->hwflags & HWFLAGS_PHY_PWR_BIT) { */
475 if (adapter->hw.mac_type >= e1000_82544 &&
476 adapter->hw.mac_type <= e1000_82547_rev_2 &&
477 adapter->hw.autoneg == 1 &&
478 adapter->hw.autoneg_advertised == ADVERTISE_1000_FULL) {
479 uint32_t ctrl = E1000_READ_REG(&adapter->hw, CTRL);
480 /* clear phy power management bit if we are in gig only mode,
481 * which if enabled will attempt negotiation to 100Mb, which
482 * can cause a loss of link at power off or driver unload */
483 ctrl &= ~E1000_CTRL_SWDPIN3;
484 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
487 e1000_phy_get_info ( &adapter->hw, &adapter->phy_info );
489 if (!adapter->smart_power_down &&
490 (adapter->hw.mac_type == e1000_82571 ||
491 adapter->hw.mac_type == e1000_82572)) {
492 uint16_t phy_data = 0;
493 /* speed up time to link by disabling smart power down, ignore
494 * the return value of this function because there is nothing
495 * different we would do if it failed */
496 e1000_read_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT,
498 phy_data &= ~IGP02E1000_PM_SPD;
499 e1000_write_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT,
504 /** Functions that implement the gPXE driver API **/
507 * e1000_close - Disables a network interface
509 * @v netdev network interface device structure
513 e1000_close ( struct net_device *netdev )
515 struct e1000_adapter *adapter = netdev_priv ( netdev );
516 struct e1000_hw *hw = &adapter->hw;
520 DBG ( "e1000_close\n" );
522 /* Acknowledge interrupts */
523 icr = E1000_READ_REG ( hw, ICR );
525 e1000_irq_disable ( adapter );
527 /* disable receives */
528 rctl = E1000_READ_REG ( hw, RCTL );
529 E1000_WRITE_REG ( hw, RCTL, rctl & ~E1000_RCTL_EN );
530 E1000_WRITE_FLUSH ( hw );
532 e1000_reset_hw ( hw );
534 e1000_free_tx_resources ( adapter );
535 e1000_free_rx_resources ( adapter );
539 * e1000_transmit - Transmit a packet
541 * @v netdev Network device
542 * @v iobuf I/O buffer
544 * @ret rc Returns 0 on success, negative on failure
547 e1000_transmit ( struct net_device *netdev, struct io_buffer *iobuf )
549 struct e1000_adapter *adapter = netdev_priv( netdev );
550 struct e1000_hw *hw = &adapter->hw;
551 uint32_t tx_curr = adapter->tx_tail;
552 struct e1000_tx_desc *tx_curr_desc;
554 DBG ("e1000_transmit\n");
556 if ( adapter->tx_fill_ctr == NUM_TX_DESC ) {
557 DBG ("TX overflow\n");
561 /* Save pointer to iobuf we have been given to transmit,
562 netdev_tx_complete() will need it later
564 adapter->tx_iobuf[tx_curr] = iobuf;
566 tx_curr_desc = ( void * ) ( adapter->tx_base ) +
567 ( tx_curr * sizeof ( *adapter->tx_base ) );
569 DBG ( "tx_curr_desc = %#08lx\n", virt_to_bus ( tx_curr_desc ) );
570 DBG ( "tx_curr_desc + 16 = %#08lx\n", virt_to_bus ( tx_curr_desc ) + 16 );
571 DBG ( "iobuf->data = %#08lx\n", virt_to_bus ( iobuf->data ) );
573 /* Add the packet to TX ring
575 tx_curr_desc->buffer_addr =
576 virt_to_bus ( iobuf->data );
577 tx_curr_desc->lower.data =
578 E1000_TXD_CMD_RPS | E1000_TXD_CMD_EOP |
579 E1000_TXD_CMD_IFCS | iob_len ( iobuf );
580 tx_curr_desc->upper.data = 0;
582 DBG ( "TX fill: %d tx_curr: %d addr: %#08lx len: %zd\n", adapter->tx_fill_ctr,
583 tx_curr, virt_to_bus ( iobuf->data ), iob_len ( iobuf ) );
585 /* Point to next free descriptor */
586 adapter->tx_tail = ( adapter->tx_tail + 1 ) % NUM_TX_DESC;
587 adapter->tx_fill_ctr++;
589 /* Write new tail to NIC, making packet available for transmit
592 E1000_WRITE_REG ( hw, TDT, adapter->tx_tail );
598 * e1000_poll - Poll for received packets
600 * @v netdev Network device
603 e1000_poll ( struct net_device *netdev )
605 struct e1000_adapter *adapter = netdev_priv( netdev );
606 struct e1000_hw *hw = &adapter->hw;
613 struct io_buffer *rx_iob;
614 struct e1000_tx_desc *tx_curr_desc;
615 struct e1000_rx_desc *rx_curr_desc;
617 uint64_t tmp_buffer_addr;
619 DBGP ( "e1000_poll\n" );
621 /* Acknowledge interrupts */
622 icr = E1000_READ_REG ( hw, ICR );
626 DBG ( "e1000_poll: intr_status = %#08x\n", icr );
628 /* Check status of transmitted packets
630 while ( ( i = adapter->tx_head ) != adapter->tx_tail ) {
632 tx_curr_desc = ( void * ) ( adapter->tx_base ) +
633 ( i * sizeof ( *adapter->tx_base ) );
635 tx_status = tx_curr_desc->upper.data;
637 /* if the packet at tx_head is not owned by hardware it is for us */
638 if ( ! ( tx_status & E1000_TXD_STAT_DD ) )
641 DBG ( "Sent packet. tx_head: %d tx_tail: %d tx_status: %#08x\n",
642 adapter->tx_head, adapter->tx_tail, tx_status );
644 if ( tx_status & ( E1000_TXD_STAT_EC | E1000_TXD_STAT_LC |
645 E1000_TXD_STAT_TU ) ) {
646 netdev_tx_complete_err ( netdev, adapter->tx_iobuf[i], -EINVAL );
647 DBG ( "Error transmitting packet, tx_status: %#08x\n",
650 netdev_tx_complete ( netdev, adapter->tx_iobuf[i] );
651 DBG ( "Success transmitting packet, tx_status: %#08x\n",
655 /* Decrement count of used descriptors, clear this descriptor
657 adapter->tx_fill_ctr--;
658 memset ( tx_curr_desc, 0, sizeof ( *tx_curr_desc ) );
660 adapter->tx_head = ( adapter->tx_head + 1 ) % NUM_TX_DESC;
663 /* Process received packets
667 i = adapter->rx_curr;
669 rx_curr_desc = ( void * ) ( adapter->rx_base ) +
670 ( i * sizeof ( *adapter->rx_base ) );
671 rx_status = rx_curr_desc->status;
673 DBG2 ( "Before DD Check RX_status: %#08x\n", rx_status );
675 if ( ! ( rx_status & E1000_RXD_STAT_DD ) )
678 DBG ( "RCTL = %#08x\n", E1000_READ_REG ( &adapter->hw, RCTL ) );
680 rx_len = rx_curr_desc->length;
682 DBG ( "Received packet, rx_curr: %d rx_status: %#08x rx_len: %d\n",
683 i, rx_status, rx_len );
685 rx_err = rx_curr_desc->errors;
687 if ( rx_err & E1000_RXD_ERR_FRAME_ERR_MASK ) {
689 netdev_rx_err ( netdev, NULL, -EINVAL );
690 DBG ( "e1000_poll: Corrupted packet received!"
691 " rx_err: %#08x\n", rx_err );
694 /* If unable allocate space for this packet,
695 * try again next poll
697 rx_iob = alloc_iob ( rx_len );
701 memcpy ( iob_put ( rx_iob, rx_len ),
702 adapter->rx_iobuf[i]->data, rx_len );
704 /* Add this packet to the receive queue.
706 netdev_rx ( netdev, rx_iob );
709 tmp_buffer_addr = rx_curr_desc->buffer_addr;
710 memset ( rx_curr_desc, 0, sizeof ( *rx_curr_desc ) );
711 rx_curr_desc->buffer_addr = tmp_buffer_addr;
713 E1000_WRITE_REG ( hw, RDT, adapter->rx_curr );
715 adapter->rx_curr = ( adapter->rx_curr + 1 ) % NUM_RX_DESC;
720 * e1000_irq - enable or Disable interrupts
722 * @v adapter e1000 adapter
723 * @v action requested interrupt action
726 e1000_irq ( struct net_device *netdev, int enable )
728 struct e1000_adapter *adapter = netdev_priv(netdev);
730 DBG ( "e1000_irq\n" );
734 e1000_irq_disable ( adapter );
737 e1000_irq_enable ( adapter );
740 e1000_irq_force ( adapter );
745 static struct net_device_operations e1000_operations;
748 * e1000_probe - Initial configuration of e1000 NIC
753 * @ret rc Return status code
756 e1000_probe ( struct pci_device *pdev,
757 const struct pci_device_id *id __unused )
760 struct net_device *netdev;
761 struct e1000_adapter *adapter;
762 unsigned long mmio_start, mmio_len;
763 unsigned long flash_start, flash_len;
765 DBG ( "e1000_probe\n" );
769 /* Allocate net device ( also allocates memory for netdev->priv
770 and makes netdev-priv point to it ) */
771 netdev = alloc_etherdev ( sizeof ( struct e1000_adapter ) );
773 goto err_alloc_etherdev;
775 /* Associate e1000-specific network operations operations with
776 * generic network device layer */
777 netdev_init ( netdev, &e1000_operations );
779 /* Associate this network device with given PCI device */
780 pci_set_drvdata ( pdev, netdev );
781 netdev->dev = &pdev->dev;
783 /* Initialize driver private storage */
784 adapter = netdev_priv ( netdev );
785 memset ( adapter, 0, ( sizeof ( *adapter ) ) );
787 adapter->hw.io_base = pdev->ioaddr;
788 adapter->ioaddr = pdev->ioaddr;
789 adapter->irqno = pdev->irq;
790 adapter->netdev = netdev;
791 adapter->pdev = pdev;
792 adapter->hw.back = adapter;
794 adapter->tx_ring_size = sizeof ( *adapter->tx_base ) * NUM_TX_DESC;
795 adapter->rx_ring_size = sizeof ( *adapter->rx_base ) * NUM_RX_DESC;
797 mmio_start = pci_bar_start ( pdev, PCI_BASE_ADDRESS_0 );
798 mmio_len = pci_bar_size ( pdev, PCI_BASE_ADDRESS_0 );
800 DBG ( "mmio_start: %#08lx\n", mmio_start );
801 DBG ( "mmio_len: %#08lx\n", mmio_len );
803 /* Fix up PCI device */
804 adjust_pci_device ( pdev );
808 adapter->hw.hw_addr = ioremap ( mmio_start, mmio_len );
809 DBG ( "adapter->hw.hw_addr: %p\n", adapter->hw.hw_addr );
811 if ( ! adapter->hw.hw_addr )
814 /* setup the private structure */
815 if ( ( err = e1000_sw_init ( adapter ) ) )
818 DBG ( "adapter->hw.mac_type: %#08x\n", adapter->hw.mac_type );
820 /* Flash BAR mapping must happen after e1000_sw_init
821 * because it depends on mac_type
823 if ( ( adapter->hw.mac_type == e1000_ich8lan ) && ( pdev->ioaddr ) ) {
824 flash_start = pci_bar_start ( pdev, PCI_BASE_ADDRESS_1 );
825 flash_len = pci_bar_size ( pdev, PCI_BASE_ADDRESS_1 );
826 adapter->hw.flash_address = ioremap ( flash_start, flash_len );
827 if ( ! adapter->hw.flash_address )
831 /* initialize eeprom parameters */
832 if ( e1000_init_eeprom_params ( &adapter->hw ) ) {
833 DBG ( "EEPROM initialization failed\n" );
837 /* before reading the EEPROM, reset the controller to
838 * put the device in a known good starting state
840 err = e1000_reset_hw ( &adapter->hw );
842 DBG ( "Hardware Initialization Failed\n" );
846 /* make sure the EEPROM is good */
847 if ( e1000_validate_eeprom_checksum( &adapter->hw ) < 0 ) {
848 DBG ( "The EEPROM Checksum Is Not Valid\n" );
852 /* copy the MAC address out of the EEPROM */
853 if ( e1000_read_mac_addr ( &adapter->hw ) )
854 DBG ( "EEPROM Read Error\n" );
856 memcpy ( netdev->hw_addr, adapter->hw.mac_addr, ETH_ALEN );
858 /* print bus type/speed/width info */
860 struct e1000_hw *hw = &adapter->hw;
861 DBG ( "(PCI%s:%s:%s) ",
862 ((hw->bus_type == e1000_bus_type_pcix) ? "-X" :
863 (hw->bus_type == e1000_bus_type_pci_express ? " Express":"")),
864 ((hw->bus_speed == e1000_bus_speed_2500) ? "2.5Gb/s" :
865 (hw->bus_speed == e1000_bus_speed_133) ? "133MHz" :
866 (hw->bus_speed == e1000_bus_speed_120) ? "120MHz" :
867 (hw->bus_speed == e1000_bus_speed_100) ? "100MHz" :
868 (hw->bus_speed == e1000_bus_speed_66) ? "66MHz" : "33MHz"),
869 ((hw->bus_width == e1000_bus_width_64) ? "64-bit" :
870 (hw->bus_width == e1000_bus_width_pciex_4) ? "Width x4" :
871 (hw->bus_width == e1000_bus_width_pciex_1) ? "Width x1" :
874 for (i = 0; i < 6; i++)
875 DBG ("%02x%s", netdev->ll_addr[i], i == 5 ? "\n" : ":");
877 /* reset the hardware with the new settings */
878 e1000_reset ( adapter );
880 e1000_get_hw_control ( adapter );
882 /* Mark as link up; we don't yet handle link state */
883 netdev_link_up ( netdev );
885 if ( ( err = register_netdev ( netdev ) ) != 0)
888 DBG ( "e1000_probe succeeded!\n" );
890 /* No errors, return success */
893 /* Error return paths */
897 if ( ! e1000_check_phy_reset_block ( &adapter->hw ) )
898 e1000_phy_hw_reset ( &adapter->hw );
899 if ( adapter->hw.flash_address )
900 iounmap ( adapter->hw.flash_address );
903 iounmap ( adapter->hw.hw_addr );
905 netdev_put ( netdev );
911 * e1000_remove - Device Removal Routine
913 * @v pdev PCI device information struct
917 e1000_remove ( struct pci_device *pdev )
919 struct net_device *netdev = pci_get_drvdata ( pdev );
920 struct e1000_adapter *adapter = netdev_priv ( netdev );
922 DBG ( "e1000_remove\n" );
924 if ( adapter->hw.flash_address )
925 iounmap ( adapter->hw.flash_address );
926 if ( adapter->hw.hw_addr )
927 iounmap ( adapter->hw.hw_addr );
929 unregister_netdev ( netdev );
930 e1000_reset_hw ( &adapter->hw );
931 netdev_nullify ( netdev );
932 netdev_put ( netdev );
936 * e1000_open - Called when a network interface is made active
938 * @v netdev network interface device structure
939 * @ret rc Return status code, 0 on success, negative value on failure
943 e1000_open ( struct net_device *netdev )
945 struct e1000_adapter *adapter = netdev_priv(netdev);
948 DBG ( "e1000_open\n" );
950 /* allocate transmit descriptors */
951 err = e1000_setup_tx_resources ( adapter );
953 DBG ( "Error setting up TX resources!\n" );
957 /* allocate receive descriptors */
958 err = e1000_setup_rx_resources ( adapter );
960 DBG ( "Error setting up RX resources!\n" );
964 e1000_configure_tx ( adapter );
966 e1000_configure_rx ( adapter );
968 DBG ( "RXDCTL: %#08x\n", E1000_READ_REG ( &adapter->hw, RXDCTL ) );
973 e1000_free_tx_resources ( adapter );
975 e1000_reset ( adapter );
980 /** e1000 net device operations */
981 static struct net_device_operations e1000_operations = {
983 .close = e1000_close,
984 .transmit = e1000_transmit,
990 e1000_read_pcie_cap_reg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
992 struct e1000_adapter *adapter = hw->back;
995 #define PCI_CAP_ID_EXP 0x10 /* PCI Express */
996 cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP);
998 return -E1000_ERR_CONFIG;
1000 pci_read_config_word(adapter->pdev, cap_offset + reg, value);
1006 e1000_pci_clear_mwi ( struct e1000_hw *hw )
1008 struct e1000_adapter *adapter = hw->back;
1010 pci_write_config_word ( adapter->pdev, PCI_COMMAND,
1011 hw->pci_cmd_word & ~PCI_COMMAND_INVALIDATE );
1015 e1000_pci_set_mwi ( struct e1000_hw *hw )
1017 struct e1000_adapter *adapter = hw->back;
1019 pci_write_config_word ( adapter->pdev, PCI_COMMAND, hw->pci_cmd_word );
1023 e1000_read_pci_cfg ( struct e1000_hw *hw, uint32_t reg, uint16_t *value )
1025 struct e1000_adapter *adapter = hw->back;
1027 pci_read_config_word ( adapter->pdev, reg, value );
1031 e1000_write_pci_cfg ( struct e1000_hw *hw, uint32_t reg, uint16_t *value )
1033 struct e1000_adapter *adapter = hw->back;
1035 pci_write_config_word ( adapter->pdev, reg, *value );
1039 e1000_io_write ( struct e1000_hw *hw __unused, unsigned long port, uint32_t value )
1041 outl ( value, port );
1044 static struct pci_device_id e1000_nics[] = {
1045 PCI_ROM(0x8086, 0x1000, "e1000-0x1000", "e1000-0x1000", 0),
1046 PCI_ROM(0x8086, 0x1001, "e1000-0x1001", "e1000-0x1001", 0),
1047 PCI_ROM(0x8086, 0x1004, "e1000-0x1004", "e1000-0x1004", 0),
1048 PCI_ROM(0x8086, 0x1008, "e1000-0x1008", "e1000-0x1008", 0),
1049 PCI_ROM(0x8086, 0x1009, "e1000-0x1009", "e1000-0x1009", 0),
1050 PCI_ROM(0x8086, 0x100c, "e1000-0x100c", "e1000-0x100c", 0),
1051 PCI_ROM(0x8086, 0x100d, "e1000-0x100d", "e1000-0x100d", 0),
1052 PCI_ROM(0x8086, 0x100e, "e1000-0x100e", "e1000-0x100e", 0),
1053 PCI_ROM(0x8086, 0x100f, "e1000-0x100f", "e1000-0x100f", 0),
1054 PCI_ROM(0x8086, 0x1010, "e1000-0x1010", "e1000-0x1010", 0),
1055 PCI_ROM(0x8086, 0x1011, "e1000-0x1011", "e1000-0x1011", 0),
1056 PCI_ROM(0x8086, 0x1012, "e1000-0x1012", "e1000-0x1012", 0),
1057 PCI_ROM(0x8086, 0x1013, "e1000-0x1013", "e1000-0x1013", 0),
1058 PCI_ROM(0x8086, 0x1014, "e1000-0x1014", "e1000-0x1014", 0),
1059 PCI_ROM(0x8086, 0x1015, "e1000-0x1015", "e1000-0x1015", 0),
1060 PCI_ROM(0x8086, 0x1016, "e1000-0x1016", "e1000-0x1016", 0),
1061 PCI_ROM(0x8086, 0x1017, "e1000-0x1017", "e1000-0x1017", 0),
1062 PCI_ROM(0x8086, 0x1018, "e1000-0x1018", "e1000-0x1018", 0),
1063 PCI_ROM(0x8086, 0x1019, "e1000-0x1019", "e1000-0x1019", 0),
1064 PCI_ROM(0x8086, 0x101a, "e1000-0x101a", "e1000-0x101a", 0),
1065 PCI_ROM(0x8086, 0x101d, "e1000-0x101d", "e1000-0x101d", 0),
1066 PCI_ROM(0x8086, 0x101e, "e1000-0x101e", "e1000-0x101e", 0),
1067 PCI_ROM(0x8086, 0x1026, "e1000-0x1026", "e1000-0x1026", 0),
1068 PCI_ROM(0x8086, 0x1027, "e1000-0x1027", "e1000-0x1027", 0),
1069 PCI_ROM(0x8086, 0x1028, "e1000-0x1028", "e1000-0x1028", 0),
1070 PCI_ROM(0x8086, 0x1049, "e1000-0x1049", "e1000-0x1049", 0),
1071 PCI_ROM(0x8086, 0x104a, "e1000-0x104a", "e1000-0x104a", 0),
1072 PCI_ROM(0x8086, 0x104b, "e1000-0x104b", "e1000-0x104b", 0),
1073 PCI_ROM(0x8086, 0x104c, "e1000-0x104c", "e1000-0x104c", 0),
1074 PCI_ROM(0x8086, 0x104d, "e1000-0x104d", "e1000-0x104d", 0),
1075 PCI_ROM(0x8086, 0x105e, "e1000-0x105e", "e1000-0x105e", 0),
1076 PCI_ROM(0x8086, 0x105f, "e1000-0x105f", "e1000-0x105f", 0),
1077 PCI_ROM(0x8086, 0x1060, "e1000-0x1060", "e1000-0x1060", 0),
1078 PCI_ROM(0x8086, 0x1075, "e1000-0x1075", "e1000-0x1075", 0),
1079 PCI_ROM(0x8086, 0x1076, "e1000-0x1076", "e1000-0x1076", 0),
1080 PCI_ROM(0x8086, 0x1077, "e1000-0x1077", "e1000-0x1077", 0),
1081 PCI_ROM(0x8086, 0x1078, "e1000-0x1078", "e1000-0x1078", 0),
1082 PCI_ROM(0x8086, 0x1079, "e1000-0x1079", "e1000-0x1079", 0),
1083 PCI_ROM(0x8086, 0x107a, "e1000-0x107a", "e1000-0x107a", 0),
1084 PCI_ROM(0x8086, 0x107b, "e1000-0x107b", "e1000-0x107b", 0),
1085 PCI_ROM(0x8086, 0x107c, "e1000-0x107c", "e1000-0x107c", 0),
1086 PCI_ROM(0x8086, 0x107d, "e1000-0x107d", "e1000-0x107d", 0),
1087 PCI_ROM(0x8086, 0x107e, "e1000-0x107e", "e1000-0x107e", 0),
1088 PCI_ROM(0x8086, 0x107f, "e1000-0x107f", "e1000-0x107f", 0),
1089 PCI_ROM(0x8086, 0x108a, "e1000-0x108a", "e1000-0x108a", 0),
1090 PCI_ROM(0x8086, 0x108b, "e1000-0x108b", "e1000-0x108b", 0),
1091 PCI_ROM(0x8086, 0x108c, "e1000-0x108c", "e1000-0x108c", 0),
1092 PCI_ROM(0x8086, 0x1096, "e1000-0x1096", "e1000-0x1096", 0),
1093 PCI_ROM(0x8086, 0x1098, "e1000-0x1098", "e1000-0x1098", 0),
1094 PCI_ROM(0x8086, 0x1099, "e1000-0x1099", "e1000-0x1099", 0),
1095 PCI_ROM(0x8086, 0x109a, "e1000-0x109a", "e1000-0x109a", 0),
1096 PCI_ROM(0x8086, 0x10a4, "e1000-0x10a4", "e1000-0x10a4", 0),
1097 PCI_ROM(0x8086, 0x10a5, "e1000-0x10a5", "e1000-0x10a5", 0),
1098 PCI_ROM(0x8086, 0x10b5, "e1000-0x10b5", "e1000-0x10b5", 0),
1099 PCI_ROM(0x8086, 0x10b9, "e1000-0x10b9", "e1000-0x10b9", 0),
1100 PCI_ROM(0x8086, 0x10ba, "e1000-0x10ba", "e1000-0x10ba", 0),
1101 PCI_ROM(0x8086, 0x10bb, "e1000-0x10bb", "e1000-0x10bb", 0),
1102 PCI_ROM(0x8086, 0x10bc, "e1000-0x10bc", "e1000-0x10bc", 0),
1103 PCI_ROM(0x8086, 0x10c4, "e1000-0x10c4", "e1000-0x10c4", 0),
1104 PCI_ROM(0x8086, 0x10c5, "e1000-0x10c5", "e1000-0x10c5", 0),
1105 PCI_ROM(0x8086, 0x10d9, "e1000-0x10d9", "e1000-0x10d9", 0),
1106 PCI_ROM(0x8086, 0x10da, "e1000-0x10da", "e1000-0x10da", 0),
1109 struct pci_driver e1000_driver __pci_driver = {
1111 .id_count = (sizeof (e1000_nics) / sizeof (e1000_nics[0])),
1112 .probe = e1000_probe,
1113 .remove = e1000_remove,