1
/*******************************************************************************
3
Intel PRO/1000 Linux driver
4
Copyright(c) 1999 - 2008 Intel Corporation.
6
Portions Copyright(c) 2010 Marty Connor <mdc@etherboot.org>
7
Portions Copyright(c) 2010 Entity Cyber, Inc.
9
This program is free software; you can redistribute it and/or modify it
10
under the terms and conditions of the GNU General Public License,
11
version 2, as published by the Free Software Foundation.
13
This program is distributed in the hope it will be useful, but WITHOUT
14
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18
You should have received a copy of the GNU General Public License along with
19
this program; if not, write to the Free Software Foundation, Inc.,
20
51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
22
The full GNU General Public License is included in this distribution in
23
the file called "COPYING".
26
Linux NICS <linux.nics@intel.com>
27
e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
28
Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30
*******************************************************************************/
32
FILE_LICENCE ( GPL2_ONLY );
37
* e1000_irq_disable - Disable interrupt generation
39
* @adapter: board private structure
41
static void e1000_irq_disable ( struct e1000_adapter *adapter )
43
E1000_WRITE_REG ( &adapter->hw, E1000_IMC, ~0 );
44
E1000_WRITE_FLUSH ( &adapter->hw );
48
* e1000_irq_enable - Enable interrupt generation
50
* @adapter: board private structure
52
static void e1000_irq_enable ( struct e1000_adapter *adapter )
54
E1000_WRITE_REG(&adapter->hw, E1000_IMS, IMS_ENABLE_MASK);
55
E1000_WRITE_FLUSH(&adapter->hw);
59
* e1000_sw_init - Initialize general software structures (struct e1000_adapter)
60
* @adapter: board private structure to initialize
62
* e1000_sw_init initializes the Adapter private data structure.
63
* Fields are initialized based on PCI device information and
64
* OS network device settings (MTU size).
66
static int e1000_sw_init(struct e1000_adapter *adapter)
68
struct e1000_hw *hw = &adapter->hw;
69
struct pci_device *pdev = adapter->pdev;
71
/* PCI config space info */
73
hw->vendor_id = pdev->vendor;
74
hw->device_id = pdev->device;
76
pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &hw->subsystem_vendor_id);
77
pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &hw->subsystem_device_id);
79
pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
81
pci_read_config_word(pdev, PCI_COMMAND, &hw->bus.pci_cmd_word);
83
adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
84
adapter->max_frame_size = MAXIMUM_ETHERNET_VLAN_SIZE +
85
ETH_HLEN + ETH_FCS_LEN;
86
adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
88
hw->fc.requested_mode = e1000_fc_none;
90
/* Initialize the hardware-specific values */
91
if (e1000_setup_init_funcs(hw, false)) {
92
DBG ("Hardware Initialization Failure\n");
96
/* Explicitly disable IRQ since the NIC can be in any state. */
97
e1000_irq_disable ( adapter );
102
int32_t e1000_read_pcie_cap_reg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
104
struct e1000_adapter *adapter = hw->back;
107
#define PCI_CAP_ID_EXP 0x10 /* PCI Express */
108
cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP);
110
return -E1000_ERR_CONFIG;
112
pci_read_config_word(adapter->pdev, cap_offset + reg, value);
117
void e1000_pci_clear_mwi ( struct e1000_hw *hw )
119
struct e1000_adapter *adapter = hw->back;
121
pci_write_config_word ( adapter->pdev, PCI_COMMAND,
122
hw->bus.pci_cmd_word & ~PCI_COMMAND_INVALIDATE );
125
void e1000_pci_set_mwi ( struct e1000_hw *hw )
127
struct e1000_adapter *adapter = hw->back;
129
pci_write_config_word ( adapter->pdev, PCI_COMMAND,
130
hw->bus.pci_cmd_word );
133
void e1000_read_pci_cfg ( struct e1000_hw *hw, uint32_t reg, uint16_t *value )
135
struct e1000_adapter *adapter = hw->back;
137
pci_read_config_word ( adapter->pdev, reg, value );
140
void e1000_write_pci_cfg ( struct e1000_hw *hw, uint32_t reg, uint16_t *value )
142
struct e1000_adapter *adapter = hw->back;
144
pci_write_config_word ( adapter->pdev, reg, *value );
148
* e1000_init_manageability - disable interception of ARP packets
150
* @v adapter e1000 private structure
152
static void e1000_init_manageability ( struct e1000_adapter *adapter )
154
if (adapter->en_mng_pt) {
155
u32 manc = E1000_READ_REG(&adapter->hw, E1000_MANC);
157
/* disable hardware interception of ARP */
158
manc &= ~(E1000_MANC_ARP_EN);
160
E1000_WRITE_REG(&adapter->hw, E1000_MANC, manc);
165
* e1000_setup_tx_resources - allocate Tx resources (Descriptors)
167
* @v adapter e1000 private structure
169
* @ret rc Returns 0 on success, negative on failure
171
static int e1000_setup_tx_resources ( struct e1000_adapter *adapter )
173
DBG ( "e1000_setup_tx_resources\n" );
175
/* Allocate transmit descriptor ring memory.
176
It must not cross a 64K boundary because of hardware errata #23
177
so we use malloc_dma() requesting a 128 byte block that is
178
128 byte aligned. This should guarantee that the memory
179
allocated will not cross a 64K boundary, because 128 is an
180
even multiple of 65536 ( 65536 / 128 == 512 ), so all possible
181
allocations of 128 bytes on a 128 byte boundary will not
186
malloc_dma ( adapter->tx_ring_size, adapter->tx_ring_size );
188
if ( ! adapter->tx_base ) {
192
memset ( adapter->tx_base, 0, adapter->tx_ring_size );
194
DBG ( "adapter->tx_base = %#08lx\n", virt_to_bus ( adapter->tx_base ) );
200
* e1000_process_tx_packets - process transmitted packets
202
* @v netdev network interface device structure
204
static void e1000_process_tx_packets ( struct net_device *netdev )
206
struct e1000_adapter *adapter = netdev_priv ( netdev );
209
struct e1000_tx_desc *tx_curr_desc;
211
/* Check status of transmitted packets
213
while ( ( i = adapter->tx_head ) != adapter->tx_tail ) {
215
tx_curr_desc = ( void * ) ( adapter->tx_base ) +
216
( i * sizeof ( *adapter->tx_base ) );
218
tx_status = tx_curr_desc->upper.data;
220
/* if the packet at tx_head is not owned by hardware it is for us */
221
if ( ! ( tx_status & E1000_TXD_STAT_DD ) )
224
DBG ( "Sent packet. tx_head: %d tx_tail: %d tx_status: %#08x\n",
225
adapter->tx_head, adapter->tx_tail, tx_status );
227
if ( tx_status & ( E1000_TXD_STAT_EC | E1000_TXD_STAT_LC |
228
E1000_TXD_STAT_TU ) ) {
229
netdev_tx_complete_err ( netdev, adapter->tx_iobuf[i], -EINVAL );
230
DBG ( "Error transmitting packet, tx_status: %#08x\n",
233
netdev_tx_complete ( netdev, adapter->tx_iobuf[i] );
234
DBG ( "Success transmitting packet, tx_status: %#08x\n",
238
/* Decrement count of used descriptors, clear this descriptor
240
adapter->tx_fill_ctr--;
241
memset ( tx_curr_desc, 0, sizeof ( *tx_curr_desc ) );
243
adapter->tx_head = ( adapter->tx_head + 1 ) % NUM_TX_DESC;
247
static void e1000_free_tx_resources ( struct e1000_adapter *adapter )
249
DBG ( "e1000_free_tx_resources\n" );
251
free_dma ( adapter->tx_base, adapter->tx_ring_size );
255
* e1000_configure_tx - Configure 8254x Transmit Unit after Reset
256
* @adapter: board private structure
258
* Configure the Tx unit of the MAC after a reset.
260
static void e1000_configure_tx ( struct e1000_adapter *adapter )
262
struct e1000_hw *hw = &adapter->hw;
265
DBG ( "e1000_configure_tx\n" );
267
E1000_WRITE_REG ( hw, E1000_TDBAH(0), 0 );
268
E1000_WRITE_REG ( hw, E1000_TDBAL(0), virt_to_bus ( adapter->tx_base ) );
269
E1000_WRITE_REG ( hw, E1000_TDLEN(0), adapter->tx_ring_size );
271
DBG ( "E1000_TDBAL(0): %#08x\n", E1000_READ_REG ( hw, E1000_TDBAL(0) ) );
272
DBG ( "E1000_TDLEN(0): %d\n", E1000_READ_REG ( hw, E1000_TDLEN(0) ) );
274
/* Setup the HW Tx Head and Tail descriptor pointers */
275
E1000_WRITE_REG ( hw, E1000_TDH(0), 0 );
276
E1000_WRITE_REG ( hw, E1000_TDT(0), 0 );
278
adapter->tx_head = 0;
279
adapter->tx_tail = 0;
280
adapter->tx_fill_ctr = 0;
282
/* Setup Transmit Descriptor Settings for eop descriptor */
283
tctl = E1000_TCTL_PSP | E1000_TCTL_EN |
284
(E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT) |
285
(E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT);
287
e1000_config_collision_dist ( hw );
289
E1000_WRITE_REG ( hw, E1000_TCTL, tctl );
290
E1000_WRITE_FLUSH ( hw );
293
static void e1000_free_rx_resources ( struct e1000_adapter *adapter )
297
DBG ( "e1000_free_rx_resources\n" );
299
free_dma ( adapter->rx_base, adapter->rx_ring_size );
301
for ( i = 0; i < NUM_RX_DESC; i++ ) {
302
free_iob ( adapter->rx_iobuf[i] );
307
* e1000_refill_rx_ring - allocate Rx io_buffers
309
* @v adapter e1000 private structure
311
* @ret rc Returns 0 on success, negative on failure
313
static int e1000_refill_rx_ring ( struct e1000_adapter *adapter )
317
struct e1000_rx_desc *rx_curr_desc;
318
struct e1000_hw *hw = &adapter->hw;
319
struct io_buffer *iob;
321
DBG ("e1000_refill_rx_ring\n");
323
for ( i = 0; i < NUM_RX_DESC; i++ ) {
324
rx_curr = ( ( adapter->rx_curr + i ) % NUM_RX_DESC );
325
rx_curr_desc = adapter->rx_base + rx_curr;
327
if ( rx_curr_desc->status & E1000_RXD_STAT_DD )
330
if ( adapter->rx_iobuf[rx_curr] != NULL )
333
DBG2 ( "Refilling rx desc %d\n", rx_curr );
335
iob = alloc_iob ( MAXIMUM_ETHERNET_VLAN_SIZE );
336
adapter->rx_iobuf[rx_curr] = iob;
339
DBG ( "alloc_iob failed\n" );
343
rx_curr_desc->buffer_addr = virt_to_bus ( iob->data );
345
E1000_WRITE_REG ( hw, E1000_RDT(0), rx_curr );
352
* e1000_setup_rx_resources - allocate Rx resources (Descriptors)
354
* @v adapter e1000 private structure
356
* @ret rc Returns 0 on success, negative on failure
358
static int e1000_setup_rx_resources ( struct e1000_adapter *adapter )
362
DBG ( "e1000_setup_rx_resources\n" );
364
/* Allocate receive descriptor ring memory.
365
It must not cross a 64K boundary because of hardware errata
369
malloc_dma ( adapter->rx_ring_size, adapter->rx_ring_size );
371
if ( ! adapter->rx_base ) {
374
memset ( adapter->rx_base, 0, adapter->rx_ring_size );
376
for ( i = 0; i < NUM_RX_DESC; i++ ) {
377
/* let e1000_refill_rx_ring() io_buffer allocations */
378
adapter->rx_iobuf[i] = NULL;
381
/* allocate io_buffers */
382
rc = e1000_refill_rx_ring ( adapter );
384
e1000_free_rx_resources ( adapter );
390
* e1000_configure_rx - Configure 8254x Receive Unit after Reset
391
* @adapter: board private structure
393
* Configure the Rx unit of the MAC after a reset.
395
static void e1000_configure_rx ( struct e1000_adapter *adapter )
397
struct e1000_hw *hw = &adapter->hw;
400
DBG ( "e1000_configure_rx\n" );
402
/* disable receives while setting up the descriptors */
403
rctl = E1000_READ_REG ( hw, E1000_RCTL );
404
E1000_WRITE_REG ( hw, E1000_RCTL, rctl & ~E1000_RCTL_EN );
405
E1000_WRITE_FLUSH ( hw );
408
adapter->rx_curr = 0;
410
/* Setup the HW Rx Head and Tail Descriptor Pointers and
411
* the Base and Length of the Rx Descriptor Ring */
413
E1000_WRITE_REG ( hw, E1000_RDBAL(0), virt_to_bus ( adapter->rx_base ) );
414
E1000_WRITE_REG ( hw, E1000_RDBAH(0), 0 );
415
E1000_WRITE_REG ( hw, E1000_RDLEN(0), adapter->rx_ring_size );
417
E1000_WRITE_REG ( hw, E1000_RDH(0), 0 );
418
E1000_WRITE_REG ( hw, E1000_RDT(0), NUM_RX_DESC - 1 );
420
/* Enable Receives */
421
rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_SZ_2048 |
422
E1000_RCTL_MPE | E1000_RCTL_SECRC;
423
E1000_WRITE_REG ( hw, E1000_RCTL, rctl );
424
E1000_WRITE_FLUSH ( hw );
426
DBG ( "E1000_RDBAL(0): %#08x\n", E1000_READ_REG ( hw, E1000_RDBAL(0) ) );
427
DBG ( "E1000_RDLEN(0): %d\n", E1000_READ_REG ( hw, E1000_RDLEN(0) ) );
428
DBG ( "E1000_RCTL: %#08x\n", E1000_READ_REG ( hw, E1000_RCTL ) );
432
* e1000_process_rx_packets - process received packets
434
* @v netdev network interface device structure
436
static void e1000_process_rx_packets ( struct net_device *netdev )
438
struct e1000_adapter *adapter = netdev_priv ( netdev );
443
struct e1000_rx_desc *rx_curr_desc;
445
/* Process received packets
449
i = adapter->rx_curr;
451
rx_curr_desc = ( void * ) ( adapter->rx_base ) +
452
( i * sizeof ( *adapter->rx_base ) );
453
rx_status = rx_curr_desc->status;
455
DBG2 ( "Before DD Check RX_status: %#08x\n", rx_status );
457
if ( ! ( rx_status & E1000_RXD_STAT_DD ) )
460
if ( adapter->rx_iobuf[i] == NULL )
463
DBG ( "E1000_RCTL = %#08x\n", E1000_READ_REG ( &adapter->hw, E1000_RCTL ) );
465
rx_len = rx_curr_desc->length;
467
DBG ( "Received packet, rx_curr: %d rx_status: %#08x rx_len: %d\n",
468
i, rx_status, rx_len );
470
rx_err = rx_curr_desc->errors;
472
iob_put ( adapter->rx_iobuf[i], rx_len );
474
if ( rx_err & E1000_RXD_ERR_FRAME_ERR_MASK ) {
476
netdev_rx_err ( netdev, adapter->rx_iobuf[i], -EINVAL );
477
DBG ( "e1000_poll: Corrupted packet received!"
478
" rx_err: %#08x\n", rx_err );
480
/* Add this packet to the receive queue. */
481
netdev_rx ( netdev, adapter->rx_iobuf[i] );
483
adapter->rx_iobuf[i] = NULL;
485
memset ( rx_curr_desc, 0, sizeof ( *rx_curr_desc ) );
487
adapter->rx_curr = ( adapter->rx_curr + 1 ) % NUM_RX_DESC;
492
* e1000_reset - Put e1000 NIC in known initial state
494
* @v adapter e1000 private structure
496
void e1000_reset ( struct e1000_adapter *adapter )
498
struct e1000_mac_info *mac = &adapter->hw.mac;
501
DBG ( "e1000_reset\n" );
509
case e1000_82541_rev_2:
513
case e1000_82545_rev_3:
515
case e1000_82546_rev_3:
519
case e1000_82547_rev_2:
522
case e1000_undefined:
527
E1000_WRITE_REG ( &adapter->hw, E1000_PBA, pba );
529
/* Allow time for pending master requests to run */
530
e1000_reset_hw ( &adapter->hw );
532
if ( mac->type >= e1000_82544 )
533
E1000_WRITE_REG ( &adapter->hw, E1000_WUC, 0 );
535
if ( e1000_init_hw ( &adapter->hw ) )
536
DBG ( "Hardware Error\n" );
538
e1000_reset_adaptive ( &adapter->hw );
539
e1000_get_phy_info ( &adapter->hw );
541
e1000_init_manageability ( adapter );
544
/** Functions that implement the iPXE driver API **/
547
* e1000_close - Disables a network interface
549
* @v netdev network interface device structure
552
static void e1000_close ( struct net_device *netdev )
554
struct e1000_adapter *adapter = netdev_priv ( netdev );
555
struct e1000_hw *hw = &adapter->hw;
558
DBG ( "e1000_close\n" );
560
/* Disable and acknowledge interrupts */
561
e1000_irq_disable ( adapter );
562
E1000_READ_REG ( hw, E1000_ICR );
564
/* disable receives */
565
rctl = E1000_READ_REG ( hw, E1000_RCTL );
566
E1000_WRITE_REG ( hw, E1000_RCTL, rctl & ~E1000_RCTL_EN );
567
E1000_WRITE_FLUSH ( hw );
569
e1000_reset_hw ( hw );
571
e1000_free_tx_resources ( adapter );
572
e1000_free_rx_resources ( adapter );
576
* e1000_transmit - Transmit a packet
578
* @v netdev Network device
579
* @v iobuf I/O buffer
581
* @ret rc Returns 0 on success, negative on failure
583
static int e1000_transmit ( struct net_device *netdev, struct io_buffer *iobuf )
585
struct e1000_adapter *adapter = netdev_priv( netdev );
586
struct e1000_hw *hw = &adapter->hw;
587
uint32_t tx_curr = adapter->tx_tail;
588
struct e1000_tx_desc *tx_curr_desc;
590
DBG ("e1000_transmit\n");
592
if ( adapter->tx_fill_ctr == NUM_TX_DESC ) {
593
DBG ("TX overflow\n");
597
/* Save pointer to iobuf we have been given to transmit,
598
netdev_tx_complete() will need it later
600
adapter->tx_iobuf[tx_curr] = iobuf;
602
tx_curr_desc = ( void * ) ( adapter->tx_base ) +
603
( tx_curr * sizeof ( *adapter->tx_base ) );
605
DBG ( "tx_curr_desc = %#08lx\n", virt_to_bus ( tx_curr_desc ) );
606
DBG ( "tx_curr_desc + 16 = %#08lx\n", virt_to_bus ( tx_curr_desc ) + 16 );
607
DBG ( "iobuf->data = %#08lx\n", virt_to_bus ( iobuf->data ) );
609
/* Add the packet to TX ring
611
tx_curr_desc->buffer_addr =
612
virt_to_bus ( iobuf->data );
613
tx_curr_desc->lower.data =
614
E1000_TXD_CMD_RS | E1000_TXD_CMD_EOP |
615
E1000_TXD_CMD_IFCS | iob_len ( iobuf );
616
tx_curr_desc->upper.data = 0;
618
DBG ( "TX fill: %d tx_curr: %d addr: %#08lx len: %zd\n", adapter->tx_fill_ctr,
619
tx_curr, virt_to_bus ( iobuf->data ), iob_len ( iobuf ) );
621
/* Point to next free descriptor */
622
adapter->tx_tail = ( adapter->tx_tail + 1 ) % NUM_TX_DESC;
623
adapter->tx_fill_ctr++;
625
/* Write new tail to NIC, making packet available for transmit
628
E1000_WRITE_REG ( hw, E1000_TDT(0), adapter->tx_tail );
634
* e1000_poll - Poll for received packets
636
* @v netdev Network device
638
static void e1000_poll ( struct net_device *netdev )
640
struct e1000_adapter *adapter = netdev_priv( netdev );
641
struct e1000_hw *hw = &adapter->hw;
645
DBGP ( "e1000_poll\n" );
647
/* Acknowledge interrupts */
648
icr = E1000_READ_REG ( hw, E1000_ICR );
652
DBG ( "e1000_poll: intr_status = %#08x\n", icr );
654
e1000_process_tx_packets ( netdev );
656
e1000_process_rx_packets ( netdev );
658
e1000_refill_rx_ring(adapter);
662
* e1000_irq - enable or Disable interrupts
664
* @v adapter e1000 adapter
665
* @v action requested interrupt action
667
static void e1000_irq ( struct net_device *netdev, int enable )
669
struct e1000_adapter *adapter = netdev_priv ( netdev );
671
DBG ( "e1000_irq\n" );
674
e1000_irq_enable ( adapter );
676
e1000_irq_disable ( adapter );
680
static struct net_device_operations e1000_operations;
683
* e1000_probe - Initial configuration of e1000 NIC
688
* @ret rc Return status code
690
int e1000_probe ( struct pci_device *pdev )
693
struct net_device *netdev;
694
struct e1000_adapter *adapter;
695
unsigned long mmio_start, mmio_len;
697
DBG ( "e1000_probe\n" );
701
/* Allocate net device ( also allocates memory for netdev->priv
702
and makes netdev-priv point to it ) */
703
netdev = alloc_etherdev ( sizeof ( struct e1000_adapter ) );
705
goto err_alloc_etherdev;
707
/* Associate e1000-specific network operations operations with
708
* generic network device layer */
709
netdev_init ( netdev, &e1000_operations );
711
/* Associate this network device with given PCI device */
712
pci_set_drvdata ( pdev, netdev );
713
netdev->dev = &pdev->dev;
715
/* Initialize driver private storage */
716
adapter = netdev_priv ( netdev );
717
memset ( adapter, 0, ( sizeof ( *adapter ) ) );
719
adapter->pdev = pdev;
721
adapter->ioaddr = pdev->ioaddr;
722
adapter->hw.io_base = pdev->ioaddr;
724
adapter->irqno = pdev->irq;
725
adapter->netdev = netdev;
726
adapter->hw.back = adapter;
728
adapter->tx_ring_size = sizeof ( *adapter->tx_base ) * NUM_TX_DESC;
729
adapter->rx_ring_size = sizeof ( *adapter->rx_base ) * NUM_RX_DESC;
731
mmio_start = pci_bar_start ( pdev, PCI_BASE_ADDRESS_0 );
732
mmio_len = pci_bar_size ( pdev, PCI_BASE_ADDRESS_0 );
734
DBG ( "mmio_start: %#08lx\n", mmio_start );
735
DBG ( "mmio_len: %#08lx\n", mmio_len );
737
/* Fix up PCI device */
738
adjust_pci_device ( pdev );
742
adapter->hw.hw_addr = ioremap ( mmio_start, mmio_len );
743
DBG ( "adapter->hw.hw_addr: %p\n", adapter->hw.hw_addr );
745
if ( ! adapter->hw.hw_addr )
748
/* Hardware features, flags and workarounds */
749
if (adapter->hw.mac.type >= e1000_82540) {
750
adapter->flags |= E1000_FLAG_HAS_SMBUS;
751
adapter->flags |= E1000_FLAG_HAS_INTR_MODERATION;
754
if (adapter->hw.mac.type == e1000_82543)
755
adapter->flags |= E1000_FLAG_BAD_TX_CARRIER_STATS_FD;
757
adapter->hw.phy.autoneg_wait_to_complete = true;
758
adapter->hw.mac.adaptive_ifs = true;
760
/* setup the private structure */
761
if ( ( err = e1000_sw_init ( adapter ) ) )
764
if ((err = e1000_init_mac_params(&adapter->hw)))
767
if ((err = e1000_init_nvm_params(&adapter->hw)))
770
/* Force auto-negotiated speed and duplex */
771
adapter->hw.mac.autoneg = 1;
773
if ((err = e1000_init_phy_params(&adapter->hw)))
776
DBG ( "adapter->hw.mac.type: %#08x\n", adapter->hw.mac.type );
778
/* before reading the EEPROM, reset the controller to
779
* put the device in a known good starting state
781
err = e1000_reset_hw ( &adapter->hw );
783
DBG ( "Hardware Initialization Failed\n" );
786
/* make sure the NVM is good */
788
if ( e1000_validate_nvm_checksum(&adapter->hw) < 0 ) {
789
DBG ( "The NVM Checksum Is Not Valid\n" );
794
/* copy the MAC address out of the EEPROM */
795
if ( e1000_read_mac_addr ( &adapter->hw ) )
796
DBG ( "EEPROM Read Error\n" );
798
memcpy ( netdev->hw_addr, adapter->hw.mac.perm_addr, ETH_ALEN );
800
/* reset the hardware with the new settings */
801
e1000_reset ( adapter );
803
if ( ( err = register_netdev ( netdev ) ) != 0)
806
/* Mark as link up; we don't yet handle link state */
807
netdev_link_up ( netdev );
809
for (i = 0; i < 6; i++)
810
DBG ("%02x%s", netdev->ll_addr[i], i == 5 ? "\n" : ":");
812
DBG ( "e1000_probe succeeded!\n" );
814
/* No errors, return success */
817
/* Error return paths */
822
if (!e1000_check_reset_block(&adapter->hw))
823
e1000_phy_hw_reset(&adapter->hw);
824
if (adapter->hw.flash_address)
825
iounmap(adapter->hw.flash_address);
827
iounmap ( adapter->hw.hw_addr );
829
netdev_put ( netdev );
835
* e1000_remove - Device Removal Routine
837
* @v pdev PCI device information struct
840
void e1000_remove ( struct pci_device *pdev )
842
struct net_device *netdev = pci_get_drvdata ( pdev );
843
struct e1000_adapter *adapter = netdev_priv ( netdev );
845
DBG ( "e1000_remove\n" );
847
if ( adapter->hw.flash_address )
848
iounmap ( adapter->hw.flash_address );
849
if ( adapter->hw.hw_addr )
850
iounmap ( adapter->hw.hw_addr );
852
unregister_netdev ( netdev );
853
e1000_reset_hw ( &adapter->hw );
854
netdev_nullify ( netdev );
855
netdev_put ( netdev );
859
* e1000_open - Called when a network interface is made active
861
* @v netdev network interface device structure
862
* @ret rc Return status code, 0 on success, negative value on failure
865
static int e1000_open ( struct net_device *netdev )
867
struct e1000_adapter *adapter = netdev_priv(netdev);
870
DBG ( "e1000_open\n" );
872
/* allocate transmit descriptors */
873
err = e1000_setup_tx_resources ( adapter );
875
DBG ( "Error setting up TX resources!\n" );
879
/* allocate receive descriptors */
880
err = e1000_setup_rx_resources ( adapter );
882
DBG ( "Error setting up RX resources!\n" );
886
e1000_configure_tx ( adapter );
888
e1000_configure_rx ( adapter );
890
DBG ( "E1000_RXDCTL(0): %#08x\n", E1000_READ_REG ( &adapter->hw, E1000_RXDCTL(0) ) );
895
e1000_free_tx_resources ( adapter );
897
e1000_reset ( adapter );
902
/** e1000 net device operations */
903
static struct net_device_operations e1000_operations = {
905
.close = e1000_close,
906
.transmit = e1000_transmit,