3 * 10/100/1000 Base-T Ethernet Driver for the ET1301 and ET131x series MACs
5 * Copyright © 2005 Agere Systems Inc.
9 *------------------------------------------------------------------------------
11 * et131x_initpci.c - Routines and data used to register the driver with the
12 * PCI (and PCI Express) subsystem, as well as basic driver
15 *------------------------------------------------------------------------------
19 * This software is provided subject to the following terms and conditions,
20 * which you should read carefully before using the software. Using this
21 * software indicates your acceptance of these terms and conditions. If you do
22 * not agree with these terms and conditions, do not use the software.
24 * Copyright © 2005 Agere Systems Inc.
25 * All rights reserved.
27 * Redistribution and use in source or binary forms, with or without
28 * modifications, are permitted provided that the following conditions are met:
30 * . Redistributions of source code must retain the above copyright notice, this
31 * list of conditions and the following Disclaimer as comments in the code as
32 * well as in the documentation and/or other materials provided with the
35 * . Redistributions in binary form must reproduce the above copyright notice,
36 * this list of conditions and the following Disclaimer in the documentation
37 * and/or other materials provided with the distribution.
39 * . Neither the name of Agere Systems Inc. nor the names of the contributors
40 * may be used to endorse or promote products derived from this software
41 * without specific prior written permission.
45 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
46 * INCLUDING, BUT NOT LIMITED TO, INFRINGEMENT AND THE IMPLIED WARRANTIES OF
47 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ANY
48 * USE, MODIFICATION OR DISTRIBUTION OF THIS SOFTWARE IS SOLELY AT THE USERS OWN
49 * RISK. IN NO EVENT SHALL AGERE SYSTEMS INC. OR CONTRIBUTORS BE LIABLE FOR ANY
50 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
51 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
52 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
53 * ON ANY THEORY OF LIABILITY, INCLUDING, BUT NOT LIMITED TO, CONTRACT, STRICT
54 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
55 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
60 #include "et131x_version.h"
61 #include "et131x_defs.h"
63 #include <linux/pci.h>
64 #include <linux/init.h>
65 #include <linux/module.h>
66 #include <linux/types.h>
67 #include <linux/kernel.h>
69 #include <linux/sched.h>
70 #include <linux/ptrace.h>
71 #include <linux/ctype.h>
72 #include <linux/string.h>
73 #include <linux/timer.h>
74 #include <linux/interrupt.h>
76 #include <linux/delay.h>
78 #include <linux/bitops.h>
79 #include <asm/system.h>
81 #include <linux/netdevice.h>
82 #include <linux/etherdevice.h>
83 #include <linux/skbuff.h>
84 #include <linux/if_arp.h>
85 #include <linux/ioport.h>
86 #include <linux/random.h>
88 #include "et1310_phy.h"
90 #include "et131x_adapter.h"
92 #include "et1310_address_map.h"
93 #include "et1310_tx.h"
94 #include "et1310_rx.h"
97 #define INTERNAL_MEM_SIZE 0x400 /* 1024 of internal memory */
98 #define INTERNAL_MEM_RX_OFFSET 0x1FF /* 50% Tx, 50% Rx */
100 /* Defines for Parameter Default/Min/Max vaules */
101 #define PARM_SPEED_DUPLEX_MIN 0
102 #define PARM_SPEED_DUPLEX_MAX 5
104 /* Module parameter for manual speed setting
105 * Set Link speed and dublex manually (0-5) [0]
106 * 1 : 10Mb Half-Duplex
107 * 2 : 10Mb Full-Duplex
108 * 3 : 100Mb Half-Duplex
109 * 4 : 100Mb Full-Duplex
110 * 5 : 1000Mb Full-Duplex
111 * 0 : Auto Speed Auto Duplex // default
113 static u32 et131x_speed_set
;
114 module_param(et131x_speed_set
, uint
, 0);
115 MODULE_PARM_DESC(et131x_speed_set
,
116 "Set Link speed and dublex manually (0-5) [0]\n"
117 "1 : 10Mb Half-Duplex\n"
118 "2 : 10Mb Full-Duplex\n"
119 "3 : 100Mb Half-Duplex\n"
120 "4 : 100Mb Full-Duplex\n"
121 "5 : 1000Mb Full-Duplex\n"
122 "0 : Auto Speed Auto Dublex");
125 * et131x_hwaddr_init - set up the MAC Address on the ET1310
126 * @adapter: pointer to our private adapter structure
128 void et131x_hwaddr_init(struct et131x_adapter
*adapter
)
130 /* If have our default mac from init and no mac address from
131 * EEPROM then we need to generate the last octet and set it on the
134 if (adapter
->rom_addr
[0] == 0x00 &&
135 adapter
->rom_addr
[1] == 0x00 &&
136 adapter
->rom_addr
[2] == 0x00 &&
137 adapter
->rom_addr
[3] == 0x00 &&
138 adapter
->rom_addr
[4] == 0x00 &&
139 adapter
->rom_addr
[5] == 0x00) {
141 * We need to randomly generate the last octet so we
142 * decrease our chances of setting the mac address to
143 * same as another one of our cards in the system
145 get_random_bytes(&adapter
->addr
[5], 1);
147 * We have the default value in the register we are
148 * working with so we need to copy the current
149 * address into the permanent address
151 memcpy(adapter
->rom_addr
,
152 adapter
->addr
, ETH_ALEN
);
154 /* We do not have an override address, so set the
155 * current address to the permanent address and add
158 memcpy(adapter
->addr
,
159 adapter
->rom_addr
, ETH_ALEN
);
165 * et131x_pci_init - initial PCI setup
166 * @adapter: pointer to our private adapter structure
167 * @pdev: our PCI device
169 * Perform the initial setup of PCI registers and if possible initialise
170 * the MAC address. At this point the I/O registers have yet to be mapped
173 static int et131x_pci_init(struct et131x_adapter
*adapter
,
174 struct pci_dev
*pdev
)
180 if (et131x_init_eeprom(adapter
) < 0)
183 /* Let's set up the PORT LOGIC Register. First we need to know what
184 * the max_payload_size is
186 if (pci_read_config_byte(pdev
, ET1310_PCI_MAX_PYLD
, &max_payload
)) {
188 "Could not read PCI config space for Max Payload Size\n");
192 /* Program the Ack/Nak latency and replay timers */
193 max_payload
&= 0x07; /* Only the lower 3 bits are valid */
195 if (max_payload
< 2) {
196 static const u16 acknak
[2] = { 0x76, 0xD0 };
197 static const u16 replay
[2] = { 0x1E0, 0x2ED };
199 if (pci_write_config_word(pdev
, ET1310_PCI_ACK_NACK
,
200 acknak
[max_payload
])) {
202 "Could not write PCI config space for ACK/NAK\n");
205 if (pci_write_config_word(pdev
, ET1310_PCI_REPLAY
,
206 replay
[max_payload
])) {
208 "Could not write PCI config space for Replay Timer\n");
213 /* l0s and l1 latency timers. We are using default values.
214 * Representing 001 for L0s and 010 for L1
216 if (pci_write_config_byte(pdev
, ET1310_PCI_L0L1LATENCY
, 0x11)) {
218 "Could not write PCI config space for Latency Timers\n");
222 /* Change the max read size to 2k */
223 if (pci_read_config_byte(pdev
, 0x51, &read_size_reg
)) {
225 "Could not read PCI config space for Max read size\n");
229 read_size_reg
&= 0x8f;
230 read_size_reg
|= 0x40;
232 if (pci_write_config_byte(pdev
, 0x51, read_size_reg
)) {
234 "Could not write PCI config space for Max read size\n");
238 /* Get MAC address from config space if an eeprom exists, otherwise
239 * the MAC address there will not be valid
241 if (!adapter
->has_eeprom
) {
242 et131x_hwaddr_init(adapter
);
246 for (i
= 0; i
< ETH_ALEN
; i
++) {
247 if (pci_read_config_byte(pdev
, ET1310_PCI_MAC_ADDRESS
+ i
,
248 adapter
->rom_addr
+ i
)) {
249 dev_err(&pdev
->dev
, "Could not read PCI config space for MAC address\n");
253 memcpy(adapter
->addr
, adapter
->rom_addr
, ETH_ALEN
);
258 * et131x_error_timer_handler
259 * @data: timer-specific variable; here a pointer to our adapter structure
261 * The routine called when the error timer expires, to track the number of
264 void et131x_error_timer_handler(unsigned long data
)
266 struct et131x_adapter
*etdev
= (struct et131x_adapter
*) data
;
269 pm_csr
= readl(&etdev
->regs
->global
.pm_csr
);
271 if ((pm_csr
& ET_PM_PHY_SW_COMA
) == 0)
272 UpdateMacStatHostCounters(etdev
);
274 dev_err(&etdev
->pdev
->dev
,
275 "No interrupts, in PHY coma, pm_csr = 0x%x\n", pm_csr
);
277 if (!(etdev
->bmsr
& MI_BMSR_LINK_STATUS
) &&
278 etdev
->RegistryPhyComa
&&
279 etdev
->boot_coma
< 11) {
283 if (etdev
->boot_coma
== 10) {
284 if (!(etdev
->bmsr
& MI_BMSR_LINK_STATUS
)
285 && etdev
->RegistryPhyComa
) {
286 if ((pm_csr
& ET_PM_PHY_SW_COMA
) == 0) {
287 /* NOTE - This was originally a 'sync with
288 * interrupt'. How to do that under Linux?
290 et131x_enable_interrupts(etdev
);
291 EnablePhyComa(etdev
);
296 /* This is a periodic timer, so reschedule */
297 mod_timer(&etdev
->ErrorTimer
, jiffies
+
298 TX_ERROR_PERIOD
* HZ
/ 1000);
302 * et131x_link_detection_handler
304 * Timer function for link up at driver load time
306 void et131x_link_detection_handler(unsigned long data
)
308 struct et131x_adapter
*etdev
= (struct et131x_adapter
*) data
;
311 if (etdev
->MediaState
== 0) {
312 spin_lock_irqsave(&etdev
->Lock
, flags
);
314 etdev
->MediaState
= NETIF_STATUS_MEDIA_DISCONNECT
;
316 spin_unlock_irqrestore(&etdev
->Lock
, flags
);
318 netif_carrier_off(etdev
->netdev
);
323 * et131x_configure_global_regs - configure JAGCore global regs
324 * @etdev: pointer to our adapter structure
326 * Used to configure the global registers on the JAGCore
328 void ConfigGlobalRegs(struct et131x_adapter
*etdev
)
330 struct global_regs __iomem
*regs
= &etdev
->regs
->global
;
332 writel(0, ®s
->rxq_start_addr
);
333 writel(INTERNAL_MEM_SIZE
- 1, ®s
->txq_end_addr
);
335 if (etdev
->RegistryJumboPacket
< 2048) {
336 /* Tx / RxDMA and Tx/Rx MAC interfaces have a 1k word
337 * block of RAM that the driver can split between Tx
338 * and Rx as it desires. Our default is to split it
341 writel(PARM_RX_MEM_END_DEF
, ®s
->rxq_end_addr
);
342 writel(PARM_RX_MEM_END_DEF
+ 1, ®s
->txq_start_addr
);
343 } else if (etdev
->RegistryJumboPacket
< 8192) {
344 /* For jumbo packets > 2k but < 8k, split 50-50. */
345 writel(INTERNAL_MEM_RX_OFFSET
, ®s
->rxq_end_addr
);
346 writel(INTERNAL_MEM_RX_OFFSET
+ 1, ®s
->txq_start_addr
);
348 /* 9216 is the only packet size greater than 8k that
349 * is available. The Tx buffer has to be big enough
350 * for one whole packet on the Tx side. We'll make
351 * the Tx 9408, and give the rest to Rx
353 writel(0x01b3, ®s
->rxq_end_addr
);
354 writel(0x01b4, ®s
->txq_start_addr
);
357 /* Initialize the loopback register. Disable all loopbacks. */
358 writel(0, ®s
->loopback
);
361 writel(0, ®s
->msi_config
);
363 /* By default, disable the watchdog timer. It will be enabled when
364 * a packet is queued.
366 writel(0, ®s
->watchdog_timer
);
371 * et131x_adapter_setup - Set the adapter up as per cassini+ documentation
372 * @adapter: pointer to our private adapter structure
374 * Returns 0 on success, errno on failure (as defined in errno.h)
376 int et131x_adapter_setup(struct et131x_adapter
*etdev
)
380 /* Configure the JAGCore */
381 ConfigGlobalRegs(etdev
);
383 ConfigMACRegs1(etdev
);
385 /* Configure the MMC registers */
386 /* All we need to do is initialize the Memory Control Register */
387 writel(ET_MMC_ENABLE
, &etdev
->regs
->mmc
.mmc_ctrl
);
389 ConfigRxMacRegs(etdev
);
390 ConfigTxMacRegs(etdev
);
392 ConfigRxDmaRegs(etdev
);
393 ConfigTxDmaRegs(etdev
);
395 ConfigMacStatRegs(etdev
);
397 /* Move the following code to Timer function?? */
398 status
= et131x_xcvr_find(etdev
);
401 dev_warn(&etdev
->pdev
->dev
, "Could not find the xcvr\n");
403 /* Prepare the TRUEPHY library. */
404 ET1310_PhyInit(etdev
);
406 /* Reset the phy now so changes take place */
407 ET1310_PhyReset(etdev
);
410 ET1310_PhyPowerDown(etdev
, 1);
413 * We need to turn off 1000 base half dulplex, the mac does not
414 * support it. For the 10/100 part, turn off all gig advertisement
416 if (etdev
->pdev
->device
!= ET131X_PCI_DEVICE_ID_FAST
)
417 ET1310_PhyAdvertise1000BaseT(etdev
, TRUEPHY_ADV_DUPLEX_FULL
);
419 ET1310_PhyAdvertise1000BaseT(etdev
, TRUEPHY_ADV_DUPLEX_NONE
);
422 ET1310_PhyPowerDown(etdev
, 0);
424 et131x_setphy_normal(etdev
);
429 * et131x_soft_reset - Issue a soft reset to the hardware, complete for ET1310
430 * @adapter: pointer to our private adapter structure
432 void et131x_soft_reset(struct et131x_adapter
*adapter
)
434 /* Disable MAC Core */
435 writel(0xc00f0000, &adapter
->regs
->mac
.cfg1
);
437 /* Set everything to a reset value */
438 writel(0x7F, &adapter
->regs
->global
.sw_reset
);
439 writel(0x000f0000, &adapter
->regs
->mac
.cfg1
);
440 writel(0x00000000, &adapter
->regs
->mac
.cfg1
);
444 * et131x_align_allocated_memory - Align allocated memory on a given boundary
445 * @adapter: pointer to our adapter structure
446 * @phys_addr: pointer to Physical address
447 * @offset: pointer to the offset variable
448 * @mask: correct mask
450 void et131x_align_allocated_memory(struct et131x_adapter
*adapter
,
452 uint64_t *offset
, uint64_t mask
)
458 new_addr
= *phys_addr
& ~mask
;
460 if (new_addr
!= *phys_addr
) {
461 /* Move to next aligned block */
462 new_addr
+= mask
+ 1;
463 /* Return offset for adjusting virt addr */
464 *offset
= new_addr
- *phys_addr
;
465 /* Return new physical address */
466 *phys_addr
= new_addr
;
471 * et131x_adapter_memory_alloc
472 * @adapter: pointer to our private adapter structure
474 * Returns 0 on success, errno on failure (as defined in errno.h).
476 * Allocate all the memory blocks for send, receive and others.
478 int et131x_adapter_memory_alloc(struct et131x_adapter
*adapter
)
482 /* Allocate memory for the Tx Ring */
483 status
= et131x_tx_dma_memory_alloc(adapter
);
485 dev_err(&adapter
->pdev
->dev
,
486 "et131x_tx_dma_memory_alloc FAILED\n");
489 /* Receive buffer memory allocation */
490 status
= et131x_rx_dma_memory_alloc(adapter
);
492 dev_err(&adapter
->pdev
->dev
,
493 "et131x_rx_dma_memory_alloc FAILED\n");
494 et131x_tx_dma_memory_free(adapter
);
498 /* Init receive data structures */
499 status
= et131x_init_recv(adapter
);
501 dev_err(&adapter
->pdev
->dev
,
502 "et131x_init_recv FAILED\n");
503 et131x_tx_dma_memory_free(adapter
);
504 et131x_rx_dma_memory_free(adapter
);
510 * et131x_adapter_memory_free - Free all memory allocated for use by Tx & Rx
511 * @adapter: pointer to our private adapter structure
513 void et131x_adapter_memory_free(struct et131x_adapter
*adapter
)
515 /* Free DMA memory */
516 et131x_tx_dma_memory_free(adapter
);
517 et131x_rx_dma_memory_free(adapter
);
523 * et131x_adapter_init
524 * @etdev: pointer to the private adapter struct
525 * @pdev: pointer to the PCI device
527 * Initialize the data structures for the et131x_adapter object and link
528 * them together with the platform provided device structures.
532 static struct et131x_adapter
*et131x_adapter_init(struct net_device
*netdev
,
533 struct pci_dev
*pdev
)
535 static const u8 default_mac
[] = { 0x00, 0x05, 0x3d, 0x00, 0x02, 0x00 };
536 static const u8 duplex
[] = { 0, 1, 2, 1, 2, 2 };
537 static const u16 speed
[] = { 0, 10, 10, 100, 100, 1000 };
539 struct et131x_adapter
*etdev
;
541 /* Setup the fundamental net_device and private adapter structure
543 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
545 /* Allocate private adapter struct and copy in relevant information */
546 etdev
= netdev_priv(netdev
);
547 etdev
->pdev
= pci_dev_get(pdev
);
548 etdev
->netdev
= netdev
;
550 /* Do the same for the netdev struct */
551 netdev
->irq
= pdev
->irq
;
552 netdev
->base_addr
= pci_resource_start(pdev
, 0);
554 /* Initialize spinlocks here */
555 spin_lock_init(&etdev
->Lock
);
556 spin_lock_init(&etdev
->TCBSendQLock
);
557 spin_lock_init(&etdev
->TCBReadyQLock
);
558 spin_lock_init(&etdev
->send_hw_lock
);
559 spin_lock_init(&etdev
->rcv_lock
);
560 spin_lock_init(&etdev
->RcvPendLock
);
561 spin_lock_init(&etdev
->FbrLock
);
562 spin_lock_init(&etdev
->PHYLock
);
564 /* Parse configuration parameters into the private adapter struct */
565 if (et131x_speed_set
)
566 dev_info(&etdev
->pdev
->dev
,
567 "Speed set manually to : %d\n", et131x_speed_set
);
569 etdev
->SpeedDuplex
= et131x_speed_set
;
570 etdev
->RegistryJumboPacket
= 1514; /* 1514-9216 */
572 /* Set the MAC address to a default */
573 memcpy(etdev
->addr
, default_mac
, ETH_ALEN
);
575 /* Decode SpeedDuplex
577 * Set up as if we are auto negotiating always and then change if we
580 * If we are the 10/100 device, and gigabit is somehow requested then
581 * knock it down to 100 full.
583 if (etdev
->pdev
->device
== ET131X_PCI_DEVICE_ID_FAST
&&
584 etdev
->SpeedDuplex
== 5)
585 etdev
->SpeedDuplex
= 4;
587 etdev
->AiForceSpeed
= speed
[etdev
->SpeedDuplex
];
588 etdev
->AiForceDpx
= duplex
[etdev
->SpeedDuplex
]; /* Auto FDX */
594 * et131x_pci_setup - Perform device initialization
595 * @pdev: a pointer to the device's pci_dev structure
596 * @ent: this device's entry in the pci_device_id table
598 * Returns 0 on success, errno on failure (as defined in errno.h)
600 * Registered in the pci_driver structure, this function is called when the
601 * PCI subsystem finds a new PCI device which matches the information
602 * contained in the pci_device_id table. This routine is the equivalent to
603 * a device insertion routine.
606 static int __devinit
et131x_pci_setup(struct pci_dev
*pdev
,
607 const struct pci_device_id
*ent
)
612 struct net_device
*netdev
;
613 struct et131x_adapter
*adapter
;
615 /* Enable the device via the PCI subsystem */
616 if (pci_enable_device(pdev
) != 0) {
618 "pci_enable_device() failed\n");
622 /* Perform some basic PCI checks */
623 if (!(pci_resource_flags(pdev
, 0) & IORESOURCE_MEM
)) {
625 "Can't find PCI device's base address\n");
629 if (pci_request_regions(pdev
, DRIVER_NAME
)) {
631 "Can't get PCI resources\n");
635 /* Enable PCI bus mastering */
636 pci_set_master(pdev
);
638 /* Query PCI for Power Mgmt Capabilities
640 * NOTE: Now reading PowerMgmt in another location; is this still
643 pm_cap
= pci_find_capability(pdev
, PCI_CAP_ID_PM
);
646 "Cannot find Power Management capabilities\n");
648 goto err_release_res
;
651 /* Check the DMA addressing support of this device */
652 if (!pci_set_dma_mask(pdev
, DMA_BIT_MASK(64))) {
653 pci_using_dac
= true;
655 result
= pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(64));
658 "Unable to obtain 64 bit DMA for consistent allocations\n");
659 goto err_release_res
;
661 } else if (!pci_set_dma_mask(pdev
, DMA_BIT_MASK(32))) {
662 pci_using_dac
= false;
665 "No usable DMA addressing method\n");
667 goto err_release_res
;
670 /* Allocate netdev and private adapter structs */
671 netdev
= et131x_device_alloc();
672 if (netdev
== NULL
) {
673 dev_err(&pdev
->dev
, "Couldn't alloc netdev struct\n");
675 goto err_release_res
;
677 adapter
= et131x_adapter_init(netdev
, pdev
);
678 /* Initialise the PCI setup for the device */
679 et131x_pci_init(adapter
, pdev
);
681 /* Map the bus-relative registers to system virtual memory */
682 adapter
->regs
= pci_ioremap_bar(pdev
, 0);
683 if (adapter
->regs
== NULL
) {
684 dev_err(&pdev
->dev
, "Cannot map device registers\n");
689 /* If Phy COMA mode was enabled when we went down, disable it here. */
690 writel(ET_PMCSR_INIT
, &adapter
->regs
->global
.pm_csr
);
692 /* Issue a global reset to the et1310 */
693 et131x_soft_reset(adapter
);
695 /* Disable all interrupts (paranoid) */
696 et131x_disable_interrupts(adapter
);
698 /* Allocate DMA memory */
699 result
= et131x_adapter_memory_alloc(adapter
);
701 dev_err(&pdev
->dev
, "Could not alloc adapater memory (DMA)\n");
705 /* Init send data structures */
706 et131x_init_send(adapter
);
709 * Set up the task structure for the ISR's deferred handler
711 INIT_WORK(&adapter
->task
, et131x_isr_handler
);
713 /* Copy address into the net_device struct */
714 memcpy(netdev
->dev_addr
, adapter
->addr
, ETH_ALEN
);
716 /* Setup et1310 as per the documentation */
717 et131x_adapter_setup(adapter
);
719 /* Create a timer to count errors received by the NIC */
720 init_timer(&adapter
->ErrorTimer
);
722 adapter
->ErrorTimer
.expires
= jiffies
+ TX_ERROR_PERIOD
* HZ
/ 1000;
723 adapter
->ErrorTimer
.function
= et131x_error_timer_handler
;
724 adapter
->ErrorTimer
.data
= (unsigned long)adapter
;
726 /* Initialize link state */
727 et131x_link_detection_handler((unsigned long)adapter
);
729 /* Initialize variable for counting how long we do not have
731 adapter
->boot_coma
= 0;
733 /* We can enable interrupts now
735 * NOTE - Because registration of interrupt handler is done in the
736 * device's open(), defer enabling device interrupts to that
740 /* Register the net_device struct with the Linux network layer */
741 result
= register_netdev(netdev
);
743 dev_err(&pdev
->dev
, "register_netdev() failed\n");
747 /* Register the net_device struct with the PCI subsystem. Save a copy
748 * of the PCI config space for this device now that the device has
749 * been initialized, just in case it needs to be quickly restored.
751 pci_set_drvdata(pdev
, netdev
);
752 pci_save_state(adapter
->pdev
);
756 et131x_adapter_memory_free(adapter
);
758 iounmap(adapter
->regs
);
763 pci_release_regions(pdev
);
765 pci_disable_device(pdev
);
771 * @pdev: a pointer to the device's pci_dev structure
773 * Registered in the pci_driver structure, this function is called when the
774 * PCI subsystem detects that a PCI device which matches the information
775 * contained in the pci_device_id table has been removed.
778 static void __devexit
et131x_pci_remove(struct pci_dev
*pdev
)
780 struct net_device
*netdev
;
781 struct et131x_adapter
*adapter
;
783 /* Retrieve the net_device pointer from the pci_dev struct, as well
784 * as the private adapter struct
786 netdev
= pci_get_drvdata(pdev
);
787 adapter
= netdev_priv(netdev
);
789 /* Perform device cleanup */
790 unregister_netdev(netdev
);
791 et131x_adapter_memory_free(adapter
);
792 iounmap(adapter
->regs
);
793 pci_dev_put(adapter
->pdev
);
795 pci_release_regions(pdev
);
796 pci_disable_device(pdev
);
799 static struct pci_device_id et131x_pci_table
[] __devinitdata
= {
800 {ET131X_PCI_VENDOR_ID
, ET131X_PCI_DEVICE_ID_GIG
, PCI_ANY_ID
,
801 PCI_ANY_ID
, 0, 0, 0UL},
802 {ET131X_PCI_VENDOR_ID
, ET131X_PCI_DEVICE_ID_FAST
, PCI_ANY_ID
,
803 PCI_ANY_ID
, 0, 0, 0UL},
807 MODULE_DEVICE_TABLE(pci
, et131x_pci_table
);
809 static struct pci_driver et131x_driver
= {
811 .id_table
= et131x_pci_table
,
812 .probe
= et131x_pci_setup
,
813 .remove
= __devexit_p(et131x_pci_remove
),
814 .suspend
= NULL
, /* et131x_pci_suspend */
815 .resume
= NULL
, /* et131x_pci_resume */
820 * et131x_init_module - The "main" entry point called on driver initialization
822 * Returns 0 on success, errno on failure (as defined in errno.h)
824 static int __init
et131x_init_module(void)
826 if (et131x_speed_set
< PARM_SPEED_DUPLEX_MIN
||
827 et131x_speed_set
> PARM_SPEED_DUPLEX_MAX
) {
828 printk(KERN_WARNING
"et131x: invalid speed setting ignored.\n");
829 et131x_speed_set
= 0;
831 return pci_register_driver(&et131x_driver
);
835 * et131x_cleanup_module - The entry point called on driver cleanup
837 static void __exit
et131x_cleanup_module(void)
839 pci_unregister_driver(&et131x_driver
);
842 module_init(et131x_init_module
);
843 module_exit(et131x_cleanup_module
);
845 /* Modinfo parameters (filled out using defines from et131x_version.h) */
846 MODULE_AUTHOR(DRIVER_AUTHOR
);
847 MODULE_DESCRIPTION(DRIVER_INFO
);
848 MODULE_LICENSE(DRIVER_LICENSE
);