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 *******************************************************************************/
32 * e1000_get_hw_control - get control of the h/w from f/w
33 * @adapter: address of board private structure
35 * e1000_get_hw_control sets {CTRL_EXT|FWSM}:DRV_LOAD bit.
36 * For ASF and Pass Through versions of f/w this means that
37 * the driver is loaded. For AMT version (only with 82573)
38 * of the f/w this means that the network i/f is open.
42 e1000_get_hw_control(struct e1000_adapter *adapter)
47 DBG ( "e1000_get_hw_control\n" );
49 /* Let firmware know the driver has taken over */
50 switch (adapter->hw.mac_type) {
52 swsm = E1000_READ_REG(&adapter->hw, SWSM);
53 E1000_WRITE_REG(&adapter->hw, SWSM,
54 swsm | E1000_SWSM_DRV_LOAD);
58 case e1000_80003es2lan:
60 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
61 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
62 ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
70 * e1000_irq_enable - Enable default interrupt generation settings
71 * @adapter: board private structure
74 e1000_irq_enable ( struct e1000_adapter *adapter )
76 E1000_WRITE_REG ( &adapter->hw, IMS, E1000_IMS_RXDMT0 |
78 E1000_WRITE_FLUSH ( &adapter->hw );
82 * e1000_irq_disable - Mask off interrupt generation on the NIC
83 * @adapter: board private structure
86 e1000_irq_disable ( struct e1000_adapter *adapter )
88 E1000_WRITE_REG ( &adapter->hw, IMC, ~0 );
89 E1000_WRITE_FLUSH ( &adapter->hw );
93 * e1000_irq_force - trigger interrupt
94 * @adapter: board private structure
97 e1000_irq_force ( struct e1000_adapter *adapter )
99 E1000_WRITE_REG ( &adapter->hw, ICS, E1000_ICS_RXDMT0 );
100 E1000_WRITE_FLUSH ( &adapter->hw );
104 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
105 * @adapter: board private structure to initialize
107 * e1000_sw_init initializes the Adapter private data structure.
108 * Fields are initialized based on PCI device information and
109 * OS network device settings (MTU size).
112 e1000_sw_init ( struct e1000_adapter *adapter )
114 struct e1000_hw *hw = &adapter->hw;
115 struct pci_device *pdev = adapter->pdev;
117 /* PCI config space info */
119 hw->vendor_id = pdev->vendor;
120 hw->device_id = pdev->device;
122 pci_read_config_word ( pdev, PCI_COMMAND, &hw->pci_cmd_word );
124 /* Disable Flow Control */
125 hw->fc = E1000_FC_NONE;
127 adapter->eeprom_wol = 0;
128 adapter->wol = adapter->eeprom_wol;
129 adapter->en_mng_pt = 0;
130 adapter->rx_int_delay = 0;
131 adapter->rx_abs_int_delay = 0;
133 adapter->rx_buffer_len = 1600;
134 adapter->rx_ps_bsize0 = E1000_RXBUFFER_128;
135 hw->max_frame_size = 1600;
136 hw->min_frame_size = ETH_ZLEN;
138 /* identify the MAC */
140 if ( e1000_set_mac_type ( hw ) ) {
141 DBG ( "Unknown MAC Type\n" );
145 switch ( hw->mac_type ) {
150 case e1000_82541_rev_2:
151 case e1000_82547_rev_2:
152 hw->phy_init_script = 1;
156 e1000_set_media_type ( hw );
159 hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
160 hw->wait_autoneg_complete = TRUE;
162 hw->tbi_compatibility_en = TRUE;
163 hw->adaptive_ifs = TRUE;
167 if ( hw->media_type == e1000_media_type_copper ) {
168 hw->mdix = AUTO_ALL_MODES;
169 hw->disable_polarity_correction = FALSE;
170 hw->master_slave = E1000_MASTER_SLAVE;
173 /* Explicitly disable IRQ since the NIC can be in any state. */
174 e1000_irq_disable ( adapter );
180 * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
181 * @adapter: board private structure
182 * @txdr: tx descriptor ring (for a specific queue) to setup
184 * Return 0 on success, negative on failure
187 e1000_setup_tx_resources ( struct e1000_adapter *adapter )
189 DBG ( "e1000_setup_tx_resources\n" );
191 /* Allocate transmit descriptor ring memory.
192 It must not cross a 64K boundary because of hardware errata #23
193 so we use malloc_dma() requesting a 128 byte block that is
194 128 byte aligned. This should guarantee that the memory
195 allocated will not cross a 64K boundary, because 128 is an
196 even multiple of 65536 ( 65536 / 128 == 512 ), so all possible
197 allocations of 128 bytes on a 128 byte boundary will not
202 malloc_dma ( adapter->tx_ring_size, adapter->tx_ring_size );
204 if ( ! adapter->tx_base ) {
208 memset ( adapter->tx_base, 0, adapter->tx_ring_size );
210 DBG ( "adapter->tx_base = %#08lx\n", virt_to_bus ( adapter->tx_base ) );
216 e1000_free_tx_resources ( struct e1000_adapter *adapter )
218 DBG ( "e1000_free_tx_resources\n" );
220 free_dma ( adapter->tx_base, adapter->tx_ring_size );
224 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
225 * @adapter: board private structure
227 * Configure the Tx unit of the MAC after a reset.
230 e1000_configure_tx ( struct e1000_adapter *adapter )
232 struct e1000_hw *hw = &adapter->hw;
237 uint32_t ipgr1, ipgr2;
240 DBG ( "e1000_configure_tx\n" );
242 E1000_WRITE_REG ( hw, TDBAH, 0 );
243 E1000_WRITE_REG ( hw, TDBAL, virt_to_bus ( adapter->tx_base ) );
244 E1000_WRITE_REG ( hw, TDLEN, adapter->tx_ring_size );
246 DBG ( "TDBAL: %#08lx\n", E1000_READ_REG ( hw, TDBAL ) );
247 DBG ( "TDLEN: %ld\n", E1000_READ_REG ( hw, TDLEN ) );
249 /* Setup the HW Tx Head and Tail descriptor pointers */
250 E1000_WRITE_REG ( hw, TDH, 0 );
251 E1000_WRITE_REG ( hw, TDT, 0 );
253 adapter->tx_head = 0;
254 adapter->tx_tail = 0;
255 adapter->tx_fill_ctr = 0;
258 /* Set the default values for the Tx Inter Packet Gap timer */
259 if (adapter->hw.mac_type <= e1000_82547_rev_2 &&
260 (hw->media_type == e1000_media_type_fiber ||
261 hw->media_type == e1000_media_type_internal_serdes))
262 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
264 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
266 switch (hw->mac_type) {
267 case e1000_82542_rev2_0:
268 case e1000_82542_rev2_1:
269 tipg = DEFAULT_82542_TIPG_IPGT;
270 ipgr1 = DEFAULT_82542_TIPG_IPGR1;
271 ipgr2 = DEFAULT_82542_TIPG_IPGR2;
273 case e1000_80003es2lan:
274 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
275 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2;
278 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
279 ipgr2 = DEFAULT_82543_TIPG_IPGR2;
282 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
283 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
284 E1000_WRITE_REG ( hw, TIPG, tipg );
286 /* Set the Tx Interrupt Delay register */
288 E1000_WRITE_REG (hw, TIDV, adapter->tx_int_delay);
289 if (hw->mac_type >= e1000_82540)
290 E1000_WRITE_REG(hw, TADV, adapter->tx_abs_int_delay);
292 /* Program the Transmit Control Register */
294 tctl = E1000_READ_REG ( hw, TCTL );
295 tctl &= ~E1000_TCTL_CT;
296 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
297 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
299 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) {
300 tarc = E1000_READ_REG(hw, TARC0);
301 /* set the speed mode bit, we'll clear it if we're not at
302 * gigabit link later */
304 E1000_WRITE_REG(hw, TARC0, tarc);
305 } else if (hw->mac_type == e1000_80003es2lan) {
306 tarc = E1000_READ_REG(hw, TARC0);
308 E1000_WRITE_REG(hw, TARC0, tarc);
309 tarc = E1000_READ_REG(hw, TARC1);
311 E1000_WRITE_REG(hw, TARC1, tarc);
315 e1000_config_collision_dist ( hw );
317 tctl = E1000_TCTL_PSP | E1000_TCTL_EN |
318 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT) |
319 (E1000_HDX_COLLISION_DISTANCE << E1000_COLD_SHIFT);
322 /* Setup Transmit Descriptor Settings for eop descriptor */
323 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
325 /* only set IDE if we are delaying interrupts using the timers */
326 if (adapter->tx_int_delay)
327 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
329 if (hw->mac_type < e1000_82543)
330 adapter->txd_cmd |= E1000_TXD_CMD_RPS;
332 adapter->txd_cmd |= E1000_TXD_CMD_RS;
334 /* Cache if we're 82544 running in PCI-X because we'll
335 * need this to apply a workaround later in the send path. */
336 if (hw->mac_type == e1000_82544 &&
337 hw->bus_type == e1000_bus_type_pcix)
338 adapter->pcix_82544 = 1;
341 E1000_WRITE_REG ( hw, TCTL, tctl );
345 * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
346 * @adapter: board private structure
347 * @rxdr: rx descriptor ring (for a specific queue) to setup
349 * Returns 0 on success, negative on failure
352 e1000_setup_rx_resources ( struct e1000_adapter *adapter )
355 struct e1000_rx_desc *rx_curr_desc;
357 DBG ( "e1000_setup_rx_resources\n" );
359 /* Allocate receive descriptor ring memory.
360 It must not cross a 64K boundary because of hardware errata
364 malloc_dma ( adapter->rx_ring_size, adapter->rx_ring_size );
366 if ( ! adapter->rx_base ) {
369 memset ( adapter->rx_base, 0, adapter->rx_ring_size );
371 for ( i = 0; i < NUM_RX_DESC; i++ ) {
373 adapter->rx_iobuf[i] = alloc_iob ( 1600 );
375 /* If unable to allocate all iobufs, free any that
376 * were successfully allocated, and return an error
378 if ( ! adapter->rx_iobuf[i] ) {
379 for ( j = 0; j < i; j++ ) {
380 free_iob ( adapter->rx_iobuf[j] );
385 rx_curr_desc = ( void * ) ( adapter->rx_base ) +
386 ( i * sizeof ( *adapter->rx_base ) );
388 rx_curr_desc->buffer_addr = virt_to_bus ( adapter->rx_iobuf[i]->data );
389 DBG ( "i = %d rx_curr_desc->buffer_addr = %#16llx\n",
390 i, rx_curr_desc->buffer_addr );
397 e1000_free_rx_resources ( struct e1000_adapter *adapter )
401 DBG ( "e1000_free_rx_resources\n" );
403 free_dma ( adapter->rx_base, adapter->rx_ring_size );
405 for ( i = 0; i < NUM_RX_DESC; i++ ) {
406 free_iob ( adapter->rx_iobuf[i] );
411 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
412 * @adapter: board private structure
414 * Configure the Rx unit of the MAC after a reset.
417 e1000_configure_rx ( struct e1000_adapter *adapter )
419 struct e1000_hw *hw = &adapter->hw;
422 DBG ( "e1000_configure_rx\n" );
424 /* disable receives while setting up the descriptors */
425 rctl = E1000_READ_REG ( hw, RCTL );
426 E1000_WRITE_REG ( hw, RCTL, rctl & ~E1000_RCTL_EN );
428 adapter->rx_tail = 0;
430 /* Setup the HW Rx Head and Tail Descriptor Pointers and
431 * the Base and Length of the Rx Descriptor Ring */
433 E1000_WRITE_REG ( hw, RDBAL, virt_to_bus ( adapter->rx_base ) );
434 E1000_WRITE_REG ( hw, RDBAH, 0 );
435 E1000_WRITE_REG ( hw, RDLEN, adapter->rx_ring_size );
437 E1000_WRITE_REG ( hw, RDH, 0 );
438 E1000_WRITE_REG ( hw, RDT, NUM_TX_DESC );
440 /* Enable Receives */
441 rctl = ( E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_SZ_2048 |
445 E1000_WRITE_REG ( hw, RCTL, rctl );
446 E1000_WRITE_FLUSH ( hw );
448 DBG ( "RDBAL: %#08lx\n", E1000_READ_REG ( hw, RDBAL ) );
449 DBG ( "RDLEN: %ld\n", E1000_READ_REG ( hw, RDLEN ) );
450 DBG ( "RCTL: %#08lx\n", E1000_READ_REG ( hw, RCTL ) );
454 * e1000_reset - Put e1000 NIC in known initial state
456 * @v adapter e1000 private structure
459 e1000_reset ( struct e1000_adapter *adapter )
462 uint16_t fc_high_water_mark = E1000_FC_HIGH_DIFF;
464 DBG ( "e1000_reset\n" );
466 switch (adapter->hw.mac_type) {
467 case e1000_82542_rev2_0:
468 case e1000_82542_rev2_1:
473 case e1000_82541_rev_2:
477 case e1000_82545_rev_3:
479 case e1000_82546_rev_3:
483 case e1000_82547_rev_2:
488 case e1000_80003es2lan:
496 case e1000_undefined:
501 E1000_WRITE_REG ( &adapter->hw, PBA, pba );
503 /* flow control settings */
504 /* Set the FC high water mark to 90% of the FIFO size.
505 * Required to clear last 3 LSB */
506 fc_high_water_mark = ((pba * 9216)/10) & 0xFFF8;
507 /* We can't use 90% on small FIFOs because the remainder
508 * would be less than 1 full frame. In this case, we size
509 * it to allow at least a full frame above the high water
511 if (pba < E1000_PBA_16K)
512 fc_high_water_mark = (pba * 1024) - 1600;
514 adapter->hw.fc_high_water = fc_high_water_mark;
515 adapter->hw.fc_low_water = fc_high_water_mark - 8;
516 if (adapter->hw.mac_type == e1000_80003es2lan)
517 adapter->hw.fc_pause_time = 0xFFFF;
519 adapter->hw.fc_pause_time = E1000_FC_PAUSE_TIME;
520 adapter->hw.fc_send_xon = 1;
521 adapter->hw.fc = adapter->hw.original_fc;
522 /* Allow time for pending master requests to run */
524 e1000_reset_hw ( &adapter->hw );
526 if ( adapter->hw.mac_type >= e1000_82544 )
527 E1000_WRITE_REG ( &adapter->hw, WUC, 0 );
529 if ( e1000_init_hw ( &adapter->hw ) )
530 DBG ( "Hardware Error\n" );
532 /* if (adapter->hwflags & HWFLAGS_PHY_PWR_BIT) { */
533 if (adapter->hw.mac_type >= e1000_82544 &&
534 adapter->hw.mac_type <= e1000_82547_rev_2 &&
535 adapter->hw.autoneg == 1 &&
536 adapter->hw.autoneg_advertised == ADVERTISE_1000_FULL) {
537 uint32_t ctrl = E1000_READ_REG(&adapter->hw, CTRL);
538 /* clear phy power management bit if we are in gig only mode,
539 * which if enabled will attempt negotiation to 100Mb, which
540 * can cause a loss of link at power off or driver unload */
541 ctrl &= ~E1000_CTRL_SWDPIN3;
542 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
545 e1000_phy_get_info ( &adapter->hw, &adapter->phy_info );
547 if (!adapter->smart_power_down &&
548 (adapter->hw.mac_type == e1000_82571 ||
549 adapter->hw.mac_type == e1000_82572)) {
550 uint16_t phy_data = 0;
551 /* speed up time to link by disabling smart power down, ignore
552 * the return value of this function because there is nothing
553 * different we would do if it failed */
554 e1000_read_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT,
556 phy_data &= ~IGP02E1000_PM_SPD;
557 e1000_write_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT,
562 /** Functions that implement the gPXE driver API **/
565 * e1000_close - Disables a network interface
567 * @v netdev network interface device structure
571 e1000_close ( struct net_device *netdev )
573 struct e1000_adapter *adapter = netdev_priv ( netdev );
577 DBG ( "e1000_close\n" );
579 /* disable receives */
580 rctl = E1000_READ_REG ( &adapter->hw, RCTL );
581 E1000_WRITE_REG ( &adapter->hw, RCTL, rctl & ~E1000_RCTL_EN );
582 E1000_WRITE_FLUSH ( &adapter->hw );
584 /* Acknowledge interrupts */
585 icr = E1000_READ_REG ( &adapter->hw, ICR );
587 e1000_irq_disable ( adapter );
589 e1000_reset_hw ( &adapter->hw );
591 e1000_free_tx_resources ( adapter );
592 e1000_free_rx_resources ( adapter );
596 * e1000_transmit - Transmit a packet
598 * @v netdev Network device
599 * @v iobuf I/O buffer
601 * @ret rc Return status code
604 e1000_transmit ( struct net_device *netdev, struct io_buffer *iobuf )
606 struct e1000_adapter *adapter = netdev_priv( netdev );
607 struct e1000_hw *hw = &adapter->hw;
608 uint32_t tx_curr = adapter->tx_tail;
609 struct e1000_tx_desc *tx_curr_desc;
611 DBG ("e1000_transmit\n");
613 if ( adapter->tx_fill_ctr == NUM_TX_DESC ) {
614 DBG ("TX overflow\n");
618 /* Save pointer to iobuf we have been given to transmit,
619 netdev_tx_complete() will need it later
621 adapter->tx_iobuf[tx_curr] = iobuf;
623 tx_curr_desc = ( void * ) ( adapter->tx_base ) +
624 ( tx_curr * sizeof ( *adapter->tx_base ) );
626 DBG ( "tx_curr_desc = %#08lx\n", virt_to_bus ( tx_curr_desc ) );
627 DBG ( "tx_curr_desc + 16 = %#08lx\n", virt_to_bus ( tx_curr_desc ) + 16 );
628 DBG ( "iobuf->data = %#08lx\n", virt_to_bus ( iobuf->data ) );
630 /* Add the packet to TX ring
632 tx_curr_desc->buffer_addr =
633 virt_to_bus ( iobuf->data );
634 tx_curr_desc->lower.data =
635 E1000_TXD_CMD_RPS | E1000_TXD_CMD_EOP |
636 E1000_TXD_CMD_IFCS | iob_len ( iobuf );
637 tx_curr_desc->upper.data = 0;
639 DBG ( "TX fill: %ld tx_curr: %ld addr: %#08lx len: %d\n", adapter->tx_fill_ctr,
640 tx_curr, virt_to_bus ( iobuf->data ), iob_len ( iobuf ) );
642 /* Point to next free descriptor */
643 adapter->tx_tail = ( adapter->tx_tail + 1 ) % NUM_TX_DESC;
644 adapter->tx_fill_ctr++;
646 /* Write new tail to NIC, making packet available for transmit
648 E1000_WRITE_REG ( hw, TDT, adapter->tx_tail );
651 while ( ! ( tx_curr_desc->upper.data & E1000_TXD_STAT_DD ) ) {
652 udelay ( 10 ); /* give the nic a chance to write to the register */
655 DBG ( "Leaving XMIT\n" );
662 * e1000_poll - Poll for received packets
664 * @v netdev Network device
667 e1000_poll ( struct net_device *netdev )
669 struct e1000_adapter *adapter = netdev_priv( netdev );
670 struct e1000_hw *hw = &adapter->hw;
677 struct io_buffer *rx_iob;
678 struct e1000_tx_desc *tx_curr_desc;
679 struct e1000_rx_desc *rx_curr_desc;
683 DBG ( "e1000_poll\n" );
686 /* Acknowledge interrupts */
687 icr = E1000_READ_REG ( hw, ICR );
691 DBG ( "e1000_poll: intr_status = %#08lx\n", icr );
693 /* Check status of transmitted packets
695 while ( ( i = adapter->tx_head ) != adapter->tx_tail ) {
697 tx_curr_desc = ( void * ) ( adapter->tx_base ) +
698 ( i * sizeof ( *adapter->tx_base ) );
700 tx_status = tx_curr_desc->upper.data;
703 DBG ( "tx_curr_desc = %#08lx status = %#08lx\n",
704 virt_to_bus ( tx_curr_desc ), tx_status );
707 /* if the packet at tx_head is not owned by hardware it is for us */
708 if ( ! ( tx_status & E1000_TXD_STAT_DD ) )
711 DBG ( "Sent packet. tx_head: %ld tx_tail: %ld tx_status: %#08lx\n",
712 adapter->tx_head, adapter->tx_tail, tx_status );
714 if ( tx_status & ( E1000_TXD_STAT_EC | E1000_TXD_STAT_LC |
715 E1000_TXD_STAT_TU ) ) {
716 netdev_tx_complete_err ( netdev, adapter->tx_iobuf[i], -EINVAL );
717 DBG ( "Error transmitting packet, tx_status: %#08lx\n",
720 netdev_tx_complete ( netdev, adapter->tx_iobuf[i] );
721 DBG ( "Success transmitting packet, tx_status: %#08lx\n",
725 /* Decrement count of used descriptors, clear this descriptor
727 adapter->tx_fill_ctr--;
728 memset ( tx_curr_desc, 0, sizeof ( *tx_curr_desc ) );
730 adapter->tx_head = ( adapter->tx_head + 1 ) % NUM_TX_DESC;
733 /* Process received packets
737 i = adapter->rx_tail;;
739 rx_curr_desc = ( void * ) ( adapter->rx_base ) +
740 ( i * sizeof ( *adapter->rx_base ) );
741 rx_status = rx_curr_desc->status;
743 // DBG ( "Before DD Check RX_status: %#08lx\n", rx_status );
745 if ( ! ( rx_status & E1000_RXD_STAT_DD ) )
748 DBG ( "RCTL = %#08lx\n", E1000_READ_REG ( &adapter->hw, RCTL ) );
750 rx_len = rx_curr_desc->length;
752 DBG ( "Received packet, rx_tail: %ld rx_status: %#08lx rx_len: %ld\n",
753 i, rx_status, rx_len );
755 rx_err = rx_curr_desc->errors;
757 if ( rx_err & E1000_RXD_ERR_FRAME_ERR_MASK ) {
759 netdev_rx_err ( netdev, NULL, -EINVAL );
760 DBG ( "e1000_poll: Corrupted packet received!"
761 " rx_err: %#08lx\n", rx_err );
764 /* If unable allocate space for this packet,
765 * try again next poll
767 rx_iob = alloc_iob ( rx_len );
771 memcpy ( iob_put ( rx_iob, rx_len ),
772 adapter->rx_iobuf[i]->data, rx_len );
774 /* Add this packet to the receive queue.
776 netdev_rx ( netdev, rx_iob );
779 memset ( rx_curr_desc, 0, sizeof ( *rx_curr_desc ) );
781 rx_curr_desc->buffer_addr = virt_to_bus ( adapter->rx_iobuf[adapter->rx_tail]->data );
783 E1000_WRITE_REG ( hw, RDT, adapter->rx_tail );
785 adapter->rx_tail = ( adapter->rx_tail + 1 ) % NUM_RX_DESC;
790 * e1000_irq - enable or Disable interrupts
792 * @v adapter e1000 adapter
793 * @v action requested interrupt action
796 e1000_irq ( struct net_device *netdev, int enable )
798 struct e1000_adapter *adapter = netdev_priv(netdev);
800 DBG ( "e1000_irq\n" );
804 e1000_irq_enable ( adapter );
807 e1000_irq_disable ( adapter );
810 e1000_irq_force ( adapter );
815 static struct net_device_operations e1000_operations;
818 * e1000_probe - Initial configuration of e1000 NIC
823 * @ret rc Return status code
826 e1000_probe ( struct pci_device *pdev,
827 const struct pci_device_id *id __unused )
830 struct net_device *netdev;
831 struct e1000_adapter *adapter;
832 unsigned long mmio_start, mmio_len;
833 unsigned long flash_start, flash_len;
835 DBG ( "e1000_probe\n" );
839 /* Allocate net device ( also allocates memory for netdev->priv
840 and makes netdev-priv point to it ) */
841 netdev = alloc_etherdev ( sizeof ( struct e1000_adapter ) );
843 goto err_alloc_etherdev;
845 /* Associate e1000-specific network operations operations with
846 * generic network device layer */
847 netdev_init ( netdev, &e1000_operations );
849 /* Associate this network device with given PCI device */
850 pci_set_drvdata ( pdev, netdev );
851 netdev->dev = &pdev->dev;
853 /* Initialize driver private storage */
854 adapter = netdev_priv ( netdev );
855 memset ( adapter, 0, ( sizeof ( *adapter ) ) );
857 adapter->hw.io_base = pdev->ioaddr;
858 adapter->ioaddr = pdev->ioaddr;
859 adapter->irqno = pdev->irq;
860 adapter->netdev = netdev;
861 adapter->pdev = pdev;
862 adapter->hw.back = adapter;
864 adapter->tx_ring_size = sizeof ( *adapter->tx_base ) * NUM_TX_DESC;
865 adapter->rx_ring_size = sizeof ( *adapter->rx_base ) * NUM_RX_DESC;
867 mmio_start = pci_bar_start ( pdev, PCI_BASE_ADDRESS_0 );
868 mmio_len = pci_bar_size ( pdev, PCI_BASE_ADDRESS_0 );
870 DBG ( "mmio_start: %#08lx\n", mmio_start );
871 DBG ( "mmio_len: %#08lx\n", mmio_len );
873 /* Fix up PCI device */
874 adjust_pci_device ( pdev );
878 adapter->hw.hw_addr = ioremap ( mmio_start, mmio_len );
880 DBG ( "adapter->hw.hw_addr: %p\n", adapter->hw.hw_addr );
882 if ( ! adapter->hw.hw_addr )
885 /* setup the private structure */
886 if ( ( err = e1000_sw_init ( adapter ) ) )
889 DBG ( "adapter->hw.mac_type: %#08x\n", adapter->hw.mac_type );
891 /* Flash BAR mapping must happen after e1000_sw_init
892 * because it depends on mac_type
894 if ( ( adapter->hw.mac_type == e1000_ich8lan ) && ( pdev->ioaddr ) ) {
895 flash_start = pci_bar_start ( pdev, 1 );
896 flash_len = pci_bar_size ( pdev, 1 );
897 adapter->hw.flash_address = ioremap ( flash_start, flash_len );
898 if ( ! adapter->hw.flash_address )
902 /* initialize eeprom parameters */
903 if ( e1000_init_eeprom_params ( &adapter->hw ) ) {
904 DBG ( "EEPROM initialization failed\n" );
908 /* before reading the EEPROM, reset the controller to
909 * put the device in a known good starting state
911 err = e1000_reset_hw ( &adapter->hw );
913 DBG ( "Hardware Initialization Failed\n" );
917 /* make sure the EEPROM is good */
918 if ( e1000_validate_eeprom_checksum( &adapter->hw ) < 0 ) {
919 DBG ( "The EEPROM Checksum Is Not Valid\n" );
923 /* copy the MAC address out of the EEPROM */
924 if ( e1000_read_mac_addr ( &adapter->hw ) )
925 DBG ( "EEPROM Read Error\n" );
927 memcpy ( netdev->ll_addr, adapter->hw.mac_addr, ETH_ALEN );
929 /* print bus type/speed/width info */
931 struct e1000_hw *hw = &adapter->hw;
932 DBG ( "(PCI%s:%s:%s) ",
933 ((hw->bus_type == e1000_bus_type_pcix) ? "-X" :
934 (hw->bus_type == e1000_bus_type_pci_express ? " Express":"")),
935 ((hw->bus_speed == e1000_bus_speed_2500) ? "2.5Gb/s" :
936 (hw->bus_speed == e1000_bus_speed_133) ? "133MHz" :
937 (hw->bus_speed == e1000_bus_speed_120) ? "120MHz" :
938 (hw->bus_speed == e1000_bus_speed_100) ? "100MHz" :
939 (hw->bus_speed == e1000_bus_speed_66) ? "66MHz" : "33MHz"),
940 ((hw->bus_width == e1000_bus_width_64) ? "64-bit" :
941 (hw->bus_width == e1000_bus_width_pciex_4) ? "Width x4" :
942 (hw->bus_width == e1000_bus_width_pciex_1) ? "Width x1" :
945 for (i = 0; i < 6; i++)
946 DBG ("%02x%s", netdev->ll_addr[i], i == 5 ? "\n" : ":");
948 /* reset the hardware with the new settings */
949 e1000_reset ( adapter );
951 e1000_get_hw_control ( adapter );
953 if ( ( err = register_netdev ( netdev ) ) != 0)
956 DBG ( "e1000_probe succeeded!\n" );
958 /* No errors, return success */
961 /* Error return paths */
965 if ( ! e1000_check_phy_reset_block ( &adapter->hw ) )
966 e1000_phy_hw_reset ( &adapter->hw );
967 if ( adapter->hw.flash_address )
968 iounmap ( adapter->hw.flash_address );
971 iounmap ( adapter->hw.hw_addr );
973 netdev_put ( netdev );
979 * e1000_remove - Device Removal Routine
981 * @v pdev PCI device information struct
985 e1000_remove ( struct pci_device *pdev )
987 struct net_device *netdev = pci_get_drvdata ( pdev );
988 struct e1000_adapter *adapter = netdev_priv ( netdev );
990 DBG ( "e1000_remove\n" );
992 unregister_netdev ( netdev );
993 e1000_reset_hw ( &adapter->hw );
994 netdev_nullify ( netdev );
995 netdev_put ( netdev );
999 * e1000_open - Called when a network interface is made active
1001 * @v netdev network interface device structure
1002 * @ret rc Return status code, 0 on success, negative value on failure
1006 e1000_open ( struct net_device *netdev )
1008 struct e1000_adapter *adapter = netdev_priv(netdev);
1011 DBG ( "e1000_open\n" );
1013 /* allocate transmit descriptors */
1014 err = e1000_setup_tx_resources ( adapter );
1016 DBG ( "Error setting up TX resources!\n" );
1020 /* allocate receive descriptors */
1021 err = e1000_setup_rx_resources ( adapter );
1023 DBG ( "Error setting up RX resources!\n" );
1027 e1000_configure_tx ( adapter );
1029 e1000_configure_rx ( adapter );
1031 DBG ( "RXDCTL: %#08lx\n", E1000_READ_REG ( &adapter->hw, RXDCTL ) );
1033 e1000_irq_enable ( adapter );
1038 e1000_free_tx_resources ( adapter );
1040 e1000_reset ( adapter );
1045 /** e1000 net device operations */
1046 static struct net_device_operations e1000_operations = {
1048 .close = e1000_close,
1049 .transmit = e1000_transmit,
1055 e1000_read_pcie_cap_reg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
1057 struct e1000_adapter *adapter = hw->back;
1058 uint16_t cap_offset;
1060 #define PCI_CAP_ID_EXP 0x10 /* PCI Express */
1061 cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP);
1063 return -E1000_ERR_CONFIG;
1065 pci_read_config_word(adapter->pdev, cap_offset + reg, value);
1067 return E1000_SUCCESS;
1071 e1000_pci_clear_mwi ( struct e1000_hw *hw )
1073 struct e1000_adapter *adapter = hw->back;
1075 pci_write_config_word ( adapter->pdev, PCI_COMMAND,
1076 hw->pci_cmd_word & ~PCI_COMMAND_INVALIDATE );
1080 e1000_pci_set_mwi ( struct e1000_hw *hw )
1082 struct e1000_adapter *adapter = hw->back;
1084 pci_write_config_word ( adapter->pdev, PCI_COMMAND, hw->pci_cmd_word );
1088 e1000_read_pci_cfg ( struct e1000_hw *hw, uint32_t reg, uint16_t *value )
1090 struct e1000_adapter *adapter = hw->back;
1092 pci_read_config_word ( adapter->pdev, reg, value );
1096 e1000_write_pci_cfg ( struct e1000_hw *hw, uint32_t reg, uint16_t *value )
1098 struct e1000_adapter *adapter = hw->back;
1100 pci_write_config_word ( adapter->pdev, reg, *value );
1104 e1000_io_write ( struct e1000_hw *hw __unused, unsigned long port, uint32_t value )
1106 outl ( value, port );
1109 static struct pci_device_id e1000_nics[] = {
1110 PCI_ROM(0x8086, 0x1000, "e1000-0x1000", "E1000-0x1000"),
1111 PCI_ROM(0x8086, 0x1001, "e1000-0x1001", "E1000-0x1001"),
1112 PCI_ROM(0x8086, 0x1004, "e1000-0x1004", "E1000-0x1004"),
1113 PCI_ROM(0x8086, 0x1008, "e1000-0x1008", "E1000-0x1008"),
1114 PCI_ROM(0x8086, 0x1009, "e1000-0x1009", "E1000-0x1009"),
1115 PCI_ROM(0x8086, 0x100C, "e1000-0x100C", "E1000-0x100C"),
1116 PCI_ROM(0x8086, 0x100D, "e1000-0x100D", "E1000-0x100D"),
1117 PCI_ROM(0x8086, 0x100E, "e1000-0x100E", "E1000-0x100E"),
1118 PCI_ROM(0x8086, 0x100F, "e1000-0x100F", "E1000-0x100F"),
1119 PCI_ROM(0x8086, 0x1010, "e1000-0x1010", "E1000-0x1010"),
1120 PCI_ROM(0x8086, 0x1011, "e1000-0x1011", "E1000-0x1011"),
1121 PCI_ROM(0x8086, 0x1012, "e1000-0x1012", "E1000-0x1012"),
1122 PCI_ROM(0x8086, 0x1013, "e1000-0x1013", "E1000-0x1013"),
1123 PCI_ROM(0x8086, 0x1014, "e1000-0x1014", "E1000-0x1014"),
1124 PCI_ROM(0x8086, 0x1015, "e1000-0x1015", "E1000-0x1015"),
1125 PCI_ROM(0x8086, 0x1016, "e1000-0x1016", "E1000-0x1016"),
1126 PCI_ROM(0x8086, 0x1017, "e1000-0x1017", "E1000-0x1017"),
1127 PCI_ROM(0x8086, 0x1018, "e1000-0x1018", "E1000-0x1018"),
1128 PCI_ROM(0x8086, 0x1019, "e1000-0x1019", "E1000-0x1019"),
1129 PCI_ROM(0x8086, 0x101A, "e1000-0x101A", "E1000-0x101A"),
1130 PCI_ROM(0x8086, 0x101D, "e1000-0x101D", "E1000-0x101D"),
1131 PCI_ROM(0x8086, 0x101E, "e1000-0x101E", "E1000-0x101E"),
1132 PCI_ROM(0x8086, 0x1026, "e1000-0x1026", "E1000-0x1026"),
1133 PCI_ROM(0x8086, 0x1027, "e1000-0x1027", "E1000-0x1027"),
1134 PCI_ROM(0x8086, 0x1028, "e1000-0x1028", "E1000-0x1028"),
1135 PCI_ROM(0x8086, 0x1049, "e1000-0x1049", "E1000-0x1049"),
1136 PCI_ROM(0x8086, 0x104A, "e1000-0x104A", "E1000-0x104A"),
1137 PCI_ROM(0x8086, 0x104B, "e1000-0x104B", "E1000-0x104B"),
1138 PCI_ROM(0x8086, 0x104C, "e1000-0x104C", "E1000-0x104C"),
1139 PCI_ROM(0x8086, 0x104D, "e1000-0x104D", "E1000-0x104D"),
1140 PCI_ROM(0x8086, 0x105E, "e1000-0x105E", "E1000-0x105E"),
1141 PCI_ROM(0x8086, 0x105F, "e1000-0x105F", "E1000-0x105F"),
1142 PCI_ROM(0x8086, 0x1060, "e1000-0x1060", "E1000-0x1060"),
1143 PCI_ROM(0x8086, 0x1075, "e1000-0x1075", "E1000-0x1075"),
1144 PCI_ROM(0x8086, 0x1076, "e1000-0x1076", "E1000-0x1076"),
1145 PCI_ROM(0x8086, 0x1077, "e1000-0x1077", "E1000-0x1077"),
1146 PCI_ROM(0x8086, 0x1078, "e1000-0x1078", "E1000-0x1078"),
1147 PCI_ROM(0x8086, 0x1079, "e1000-0x1079", "E1000-0x1079"),
1148 PCI_ROM(0x8086, 0x107A, "e1000-0x107A", "E1000-0x107A"),
1149 PCI_ROM(0x8086, 0x107B, "e1000-0x107B", "E1000-0x107B"),
1150 PCI_ROM(0x8086, 0x107C, "e1000-0x107C", "E1000-0x107C"),
1151 PCI_ROM(0x8086, 0x107D, "e1000-0x107D", "E1000-0x107D"),
1152 PCI_ROM(0x8086, 0x107E, "e1000-0x107E", "E1000-0x107E"),
1153 PCI_ROM(0x8086, 0x107F, "e1000-0x107F", "E1000-0x107F"),
1154 PCI_ROM(0x8086, 0x108A, "e1000-0x108A", "E1000-0x108A"),
1155 PCI_ROM(0x8086, 0x108B, "e1000-0x108B", "E1000-0x108B"),
1156 PCI_ROM(0x8086, 0x108C, "e1000-0x108C", "E1000-0x108C"),
1157 PCI_ROM(0x8086, 0x1096, "e1000-0x1096", "E1000-0x1096"),
1158 PCI_ROM(0x8086, 0x1098, "e1000-0x1098", "E1000-0x1098"),
1159 PCI_ROM(0x8086, 0x1099, "e1000-0x1099", "E1000-0x1099"),
1160 PCI_ROM(0x8086, 0x109A, "e1000-0x109A", "E1000-0x109A"),
1161 PCI_ROM(0x8086, 0x10A4, "e1000-0x10A4", "E1000-0x10A4"),
1162 PCI_ROM(0x8086, 0x10A5, "e1000-0x10A5", "E1000-0x10A5"),
1163 PCI_ROM(0x8086, 0x10B5, "e1000-0x10B5", "E1000-0x10B5"),
1164 PCI_ROM(0x8086, 0x10B9, "e1000-0x10B9", "E1000-0x10B9"),
1165 PCI_ROM(0x8086, 0x10BA, "e1000-0x10BA", "E1000-0x10BA"),
1166 PCI_ROM(0x8086, 0x10BB, "e1000-0x10BB", "E1000-0x10BB"),
1167 PCI_ROM(0x8086, 0x10BC, "e1000-0x10BC", "E1000-0x10BC"),
1168 PCI_ROM(0x8086, 0x10C4, "e1000-0x10C4", "E1000-0x10C4"),
1169 PCI_ROM(0x8086, 0x10C5, "e1000-0x10C5", "E1000-0x10C5"),
1170 PCI_ROM(0x8086, 0x10D9, "e1000-0x10D9", "E1000-0x10D9"),
1171 PCI_ROM(0x8086, 0x10DA, "e1000-0x10DA", "E1000-0x10DA"),
1174 struct pci_driver e1000_driver __pci_driver = {
1176 .id_count = (sizeof (e1000_nics) / sizeof (e1000_nics[0])),
1177 .probe = e1000_probe,
1178 .remove = e1000_remove,