blob: 19cafc2b418dab716bebfab2005eee7efd61bb1e [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* de2104x.c: A Linux PCI Ethernet driver for Intel/Digital 21040/1 chips. */
2/*
3 Copyright 2001,2003 Jeff Garzik <jgarzik@pobox.com>
4
5 Copyright 1994, 1995 Digital Equipment Corporation. [de4x5.c]
6 Written/copyright 1994-2001 by Donald Becker. [tulip.c]
7
8 This software may be used and distributed according to the terms of
9 the GNU General Public License (GPL), incorporated herein by reference.
10 Drivers based on or derived from this code fall under the GPL and must
11 retain the authorship, copyright and license notice. This file is not
12 a complete program and may only be used when the entire operating
13 system is licensed under the GPL.
14
15 See the file COPYING in this distribution for more information.
16
17 TODO, in rough priority order:
18 * Support forcing media type with a module parameter,
19 like dl2k.c/sundance.c
20 * Constants (module parms?) for Rx work limit
21 * Complete reset on PciErr
22 * Jumbo frames / dev->change_mtu
23 * Adjust Rx FIFO threshold and Max Rx DMA burst on Rx FIFO error
24 * Adjust Tx FIFO threshold and Max Tx DMA burst on Tx FIFO error
25 * Implement Tx software interrupt mitigation via
26 Tx descriptor bit
27
28 */
29
30#define DRV_NAME "de2104x"
31#define DRV_VERSION "0.7"
32#define DRV_RELDATE "Mar 17, 2004"
33
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include <linux/module.h>
35#include <linux/kernel.h>
36#include <linux/netdevice.h>
37#include <linux/etherdevice.h>
38#include <linux/init.h>
39#include <linux/pci.h>
40#include <linux/delay.h>
41#include <linux/ethtool.h>
42#include <linux/compiler.h>
43#include <linux/rtnetlink.h>
44#include <linux/crc32.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090045#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
47#include <asm/io.h>
48#include <asm/irq.h>
49#include <asm/uaccess.h>
50#include <asm/unaligned.h>
51
52/* These identify the driver base version and may not be removed. */
53static char version[] =
54KERN_INFO DRV_NAME " PCI Ethernet driver v" DRV_VERSION " (" DRV_RELDATE ")\n";
55
56MODULE_AUTHOR("Jeff Garzik <jgarzik@pobox.com>");
57MODULE_DESCRIPTION("Intel/Digital 21040/1 series PCI Ethernet driver");
58MODULE_LICENSE("GPL");
59MODULE_VERSION(DRV_VERSION);
60
61static int debug = -1;
62module_param (debug, int, 0);
63MODULE_PARM_DESC (debug, "de2104x bitmapped message enable number");
64
65/* Set the copy breakpoint for the copy-only-tiny-buffer Rx structure. */
Joe Perches8e95a202009-12-03 07:58:21 +000066#if defined(__alpha__) || defined(__arm__) || defined(__hppa__) || \
67 defined(CONFIG_SPARC) || defined(__ia64__) || \
68 defined(__sh__) || defined(__mips__)
Linus Torvalds1da177e2005-04-16 15:20:36 -070069static int rx_copybreak = 1518;
70#else
71static int rx_copybreak = 100;
72#endif
73module_param (rx_copybreak, int, 0);
74MODULE_PARM_DESC (rx_copybreak, "de2104x Breakpoint at which Rx packets are copied");
75
76#define PFX DRV_NAME ": "
77
78#define DE_DEF_MSG_ENABLE (NETIF_MSG_DRV | \
79 NETIF_MSG_PROBE | \
80 NETIF_MSG_LINK | \
81 NETIF_MSG_IFDOWN | \
82 NETIF_MSG_IFUP | \
83 NETIF_MSG_RX_ERR | \
84 NETIF_MSG_TX_ERR)
85
Risto Suominenb77e5222009-06-10 09:55:00 +000086/* Descriptor skip length in 32 bit longwords. */
87#ifndef CONFIG_DE2104X_DSL
88#define DSL 0
89#else
90#define DSL CONFIG_DE2104X_DSL
91#endif
92
Linus Torvalds1da177e2005-04-16 15:20:36 -070093#define DE_RX_RING_SIZE 64
94#define DE_TX_RING_SIZE 64
95#define DE_RING_BYTES \
96 ((sizeof(struct de_desc) * DE_RX_RING_SIZE) + \
97 (sizeof(struct de_desc) * DE_TX_RING_SIZE))
98#define NEXT_TX(N) (((N) + 1) & (DE_TX_RING_SIZE - 1))
99#define NEXT_RX(N) (((N) + 1) & (DE_RX_RING_SIZE - 1))
100#define TX_BUFFS_AVAIL(CP) \
101 (((CP)->tx_tail <= (CP)->tx_head) ? \
102 (CP)->tx_tail + (DE_TX_RING_SIZE - 1) - (CP)->tx_head : \
103 (CP)->tx_tail - (CP)->tx_head - 1)
104
105#define PKT_BUF_SZ 1536 /* Size of each temporary Rx buffer.*/
106#define RX_OFFSET 2
107
108#define DE_SETUP_SKB ((struct sk_buff *) 1)
109#define DE_DUMMY_SKB ((struct sk_buff *) 2)
110#define DE_SETUP_FRAME_WORDS 96
111#define DE_EEPROM_WORDS 256
112#define DE_EEPROM_SIZE (DE_EEPROM_WORDS * sizeof(u16))
113#define DE_MAX_MEDIA 5
114
115#define DE_MEDIA_TP_AUTO 0
116#define DE_MEDIA_BNC 1
117#define DE_MEDIA_AUI 2
118#define DE_MEDIA_TP 3
119#define DE_MEDIA_TP_FD 4
120#define DE_MEDIA_INVALID DE_MAX_MEDIA
121#define DE_MEDIA_FIRST 0
122#define DE_MEDIA_LAST (DE_MAX_MEDIA - 1)
123#define DE_AUI_BNC (SUPPORTED_AUI | SUPPORTED_BNC)
124
125#define DE_TIMER_LINK (60 * HZ)
126#define DE_TIMER_NO_LINK (5 * HZ)
127
128#define DE_NUM_REGS 16
129#define DE_REGS_SIZE (DE_NUM_REGS * sizeof(u32))
130#define DE_REGS_VER 1
131
132/* Time in jiffies before concluding the transmitter is hung. */
133#define TX_TIMEOUT (6*HZ)
134
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135/* This is a mysterious value that can be written to CSR11 in the 21040 (only)
136 to support a pre-NWay full-duplex signaling mechanism using short frames.
137 No one knows what it should be, but if left at its default value some
138 10base2(!) packets trigger a full-duplex-request interrupt. */
139#define FULL_DUPLEX_MAGIC 0x6969
140
141enum {
142 /* NIC registers */
143 BusMode = 0x00,
144 TxPoll = 0x08,
145 RxPoll = 0x10,
146 RxRingAddr = 0x18,
147 TxRingAddr = 0x20,
148 MacStatus = 0x28,
149 MacMode = 0x30,
150 IntrMask = 0x38,
151 RxMissed = 0x40,
152 ROMCmd = 0x48,
153 CSR11 = 0x58,
154 SIAStatus = 0x60,
155 CSR13 = 0x68,
156 CSR14 = 0x70,
157 CSR15 = 0x78,
158 PCIPM = 0x40,
159
160 /* BusMode bits */
161 CmdReset = (1 << 0),
162 CacheAlign16 = 0x00008000,
163 BurstLen4 = 0x00000400,
Risto Suominenb77e5222009-06-10 09:55:00 +0000164 DescSkipLen = (DSL << 2),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165
166 /* Rx/TxPoll bits */
167 NormalTxPoll = (1 << 0),
168 NormalRxPoll = (1 << 0),
169
170 /* Tx/Rx descriptor status bits */
171 DescOwn = (1 << 31),
172 RxError = (1 << 15),
173 RxErrLong = (1 << 7),
174 RxErrCRC = (1 << 1),
175 RxErrFIFO = (1 << 0),
176 RxErrRunt = (1 << 11),
177 RxErrFrame = (1 << 14),
178 RingEnd = (1 << 25),
179 FirstFrag = (1 << 29),
180 LastFrag = (1 << 30),
181 TxError = (1 << 15),
182 TxFIFOUnder = (1 << 1),
183 TxLinkFail = (1 << 2) | (1 << 10) | (1 << 11),
184 TxMaxCol = (1 << 8),
185 TxOWC = (1 << 9),
186 TxJabber = (1 << 14),
187 SetupFrame = (1 << 27),
188 TxSwInt = (1 << 31),
189
190 /* MacStatus bits */
191 IntrOK = (1 << 16),
192 IntrErr = (1 << 15),
193 RxIntr = (1 << 6),
194 RxEmpty = (1 << 7),
195 TxIntr = (1 << 0),
196 TxEmpty = (1 << 2),
197 PciErr = (1 << 13),
198 TxState = (1 << 22) | (1 << 21) | (1 << 20),
199 RxState = (1 << 19) | (1 << 18) | (1 << 17),
200 LinkFail = (1 << 12),
201 LinkPass = (1 << 4),
202 RxStopped = (1 << 8),
203 TxStopped = (1 << 1),
204
205 /* MacMode bits */
206 TxEnable = (1 << 13),
207 RxEnable = (1 << 1),
208 RxTx = TxEnable | RxEnable,
209 FullDuplex = (1 << 9),
210 AcceptAllMulticast = (1 << 7),
211 AcceptAllPhys = (1 << 6),
212 BOCnt = (1 << 5),
213 MacModeClear = (1<<12) | (1<<11) | (1<<10) | (1<<8) | (1<<3) |
214 RxTx | BOCnt | AcceptAllPhys | AcceptAllMulticast,
215
216 /* ROMCmd bits */
217 EE_SHIFT_CLK = 0x02, /* EEPROM shift clock. */
218 EE_CS = 0x01, /* EEPROM chip select. */
219 EE_DATA_WRITE = 0x04, /* Data from the Tulip to EEPROM. */
220 EE_WRITE_0 = 0x01,
221 EE_WRITE_1 = 0x05,
222 EE_DATA_READ = 0x08, /* Data from the EEPROM chip. */
223 EE_ENB = (0x4800 | EE_CS),
224
225 /* The EEPROM commands include the alway-set leading bit. */
226 EE_READ_CMD = 6,
227
228 /* RxMissed bits */
229 RxMissedOver = (1 << 16),
230 RxMissedMask = 0xffff,
231
232 /* SROM-related bits */
233 SROMC0InfoLeaf = 27,
234 MediaBlockMask = 0x3f,
235 MediaCustomCSRs = (1 << 6),
Jeff Garzikf3b197a2006-05-26 21:39:03 -0400236
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 /* PCIPM bits */
238 PM_Sleep = (1 << 31),
239 PM_Snooze = (1 << 30),
240 PM_Mask = PM_Sleep | PM_Snooze,
Jeff Garzikf3b197a2006-05-26 21:39:03 -0400241
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 /* SIAStatus bits */
243 NWayState = (1 << 14) | (1 << 13) | (1 << 12),
244 NWayRestart = (1 << 12),
245 NonselPortActive = (1 << 9),
246 LinkFailStatus = (1 << 2),
247 NetCxnErr = (1 << 1),
248};
249
250static const u32 de_intr_mask =
251 IntrOK | IntrErr | RxIntr | RxEmpty | TxIntr | TxEmpty |
252 LinkPass | LinkFail | PciErr;
253
254/*
255 * Set the programmable burst length to 4 longwords for all:
256 * DMA errors result without these values. Cache align 16 long.
257 */
Risto Suominenb77e5222009-06-10 09:55:00 +0000258static const u32 de_bus_mode = CacheAlign16 | BurstLen4 | DescSkipLen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259
260struct de_srom_media_block {
261 u8 opts;
262 u16 csr13;
263 u16 csr14;
264 u16 csr15;
265} __attribute__((packed));
266
267struct de_srom_info_leaf {
268 u16 default_media;
269 u8 n_blocks;
270 u8 unused;
271} __attribute__((packed));
272
273struct de_desc {
Al Viroc559a5b2007-08-23 00:43:22 -0400274 __le32 opts1;
275 __le32 opts2;
276 __le32 addr1;
277 __le32 addr2;
Risto Suominenb77e5222009-06-10 09:55:00 +0000278#if DSL
279 __le32 skip[DSL];
280#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281};
282
283struct media_info {
284 u16 type; /* DE_MEDIA_xxx */
285 u16 csr13;
286 u16 csr14;
287 u16 csr15;
288};
289
290struct ring_info {
291 struct sk_buff *skb;
292 dma_addr_t mapping;
293};
294
295struct de_private {
296 unsigned tx_head;
297 unsigned tx_tail;
298 unsigned rx_tail;
299
300 void __iomem *regs;
301 struct net_device *dev;
302 spinlock_t lock;
303
304 struct de_desc *rx_ring;
305 struct de_desc *tx_ring;
306 struct ring_info tx_skb[DE_TX_RING_SIZE];
307 struct ring_info rx_skb[DE_RX_RING_SIZE];
308 unsigned rx_buf_sz;
309 dma_addr_t ring_dma;
310
311 u32 msg_enable;
312
313 struct net_device_stats net_stats;
314
315 struct pci_dev *pdev;
316
317 u16 setup_frame[DE_SETUP_FRAME_WORDS];
318
319 u32 media_type;
320 u32 media_supported;
321 u32 media_advertise;
322 struct media_info media[DE_MAX_MEDIA];
323 struct timer_list media_timer;
324
325 u8 *ee_data;
326 unsigned board_idx;
327 unsigned de21040 : 1;
328 unsigned media_lock : 1;
329};
330
331
332static void de_set_rx_mode (struct net_device *dev);
333static void de_tx (struct de_private *de);
334static void de_clean_rings (struct de_private *de);
335static void de_media_interrupt (struct de_private *de, u32 status);
336static void de21040_media_timer (unsigned long data);
337static void de21041_media_timer (unsigned long data);
338static unsigned int de_ok_to_advertise (struct de_private *de, u32 new_media);
339
340
Alexey Dobriyana3aa1882010-01-07 11:58:11 +0000341static DEFINE_PCI_DEVICE_TABLE(de_pci_tbl) = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 { PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_TULIP,
343 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
344 { PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_TULIP_PLUS,
345 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 },
346 { },
347};
348MODULE_DEVICE_TABLE(pci, de_pci_tbl);
349
350static const char * const media_name[DE_MAX_MEDIA] = {
351 "10baseT auto",
352 "BNC",
353 "AUI",
354 "10baseT-HD",
355 "10baseT-FD"
356};
357
358/* 21040 transceiver register settings:
359 * TP AUTO(unused), BNC(unused), AUI, TP, TP FD*/
360static u16 t21040_csr13[] = { 0, 0, 0x8F09, 0x8F01, 0x8F01, };
361static u16 t21040_csr14[] = { 0, 0, 0x0705, 0xFFFF, 0xFFFD, };
362static u16 t21040_csr15[] = { 0, 0, 0x0006, 0x0000, 0x0000, };
363
364/* 21041 transceiver register settings: TP AUTO, BNC, AUI, TP, TP FD*/
365static u16 t21041_csr13[] = { 0xEF01, 0xEF09, 0xEF09, 0xEF01, 0xEF09, };
366static u16 t21041_csr14[] = { 0xFFFF, 0xF7FD, 0xF7FD, 0x6F3F, 0x6F3D, };
367static u16 t21041_csr15[] = { 0x0008, 0x0006, 0x000E, 0x0008, 0x0008, };
368
369
370#define dr32(reg) readl(de->regs + (reg))
371#define dw32(reg,val) writel((val), de->regs + (reg))
372
373
374static void de_rx_err_acct (struct de_private *de, unsigned rx_tail,
375 u32 status, u32 len)
376{
377 if (netif_msg_rx_err (de))
378 printk (KERN_DEBUG
379 "%s: rx err, slot %d status 0x%x len %d\n",
380 de->dev->name, rx_tail, status, len);
381
382 if ((status & 0x38000300) != 0x0300) {
383 /* Ingore earlier buffers. */
384 if ((status & 0xffff) != 0x7fff) {
385 if (netif_msg_rx_err(de))
Joe Perchesf639dc72010-01-28 20:59:19 +0000386 dev_warn(&de->dev->dev,
387 "Oversized Ethernet frame spanned multiple buffers, status %08x!\n",
388 status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 de->net_stats.rx_length_errors++;
390 }
391 } else if (status & RxError) {
392 /* There was a fatal error. */
393 de->net_stats.rx_errors++; /* end of a packet.*/
394 if (status & 0x0890) de->net_stats.rx_length_errors++;
395 if (status & RxErrCRC) de->net_stats.rx_crc_errors++;
396 if (status & RxErrFIFO) de->net_stats.rx_fifo_errors++;
397 }
398}
399
400static void de_rx (struct de_private *de)
401{
402 unsigned rx_tail = de->rx_tail;
403 unsigned rx_work = DE_RX_RING_SIZE;
404 unsigned drop = 0;
405 int rc;
406
Roel Kluin46578a692009-02-02 21:39:02 -0800407 while (--rx_work) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 u32 status, len;
409 dma_addr_t mapping;
410 struct sk_buff *skb, *copy_skb;
411 unsigned copying_skb, buflen;
412
413 skb = de->rx_skb[rx_tail].skb;
Eric Sesterhenn / snakebyte7e0b58f2006-01-26 22:02:43 +0100414 BUG_ON(!skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 rmb();
416 status = le32_to_cpu(de->rx_ring[rx_tail].opts1);
417 if (status & DescOwn)
418 break;
419
420 len = ((status >> 16) & 0x7ff) - 4;
421 mapping = de->rx_skb[rx_tail].mapping;
422
423 if (unlikely(drop)) {
424 de->net_stats.rx_dropped++;
425 goto rx_next;
426 }
427
428 if (unlikely((status & 0x38008300) != 0x0300)) {
429 de_rx_err_acct(de, rx_tail, status, len);
430 goto rx_next;
431 }
432
433 copying_skb = (len <= rx_copybreak);
434
435 if (unlikely(netif_msg_rx_status(de)))
436 printk(KERN_DEBUG "%s: rx slot %d status 0x%x len %d copying? %d\n",
437 de->dev->name, rx_tail, status, len,
438 copying_skb);
439
440 buflen = copying_skb ? (len + RX_OFFSET) : de->rx_buf_sz;
441 copy_skb = dev_alloc_skb (buflen);
442 if (unlikely(!copy_skb)) {
443 de->net_stats.rx_dropped++;
444 drop = 1;
445 rx_work = 100;
446 goto rx_next;
447 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448
449 if (!copying_skb) {
450 pci_unmap_single(de->pdev, mapping,
451 buflen, PCI_DMA_FROMDEVICE);
452 skb_put(skb, len);
453
454 mapping =
455 de->rx_skb[rx_tail].mapping =
David S. Miller689be432005-06-28 15:25:31 -0700456 pci_map_single(de->pdev, copy_skb->data,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 buflen, PCI_DMA_FROMDEVICE);
458 de->rx_skb[rx_tail].skb = copy_skb;
459 } else {
460 pci_dma_sync_single_for_cpu(de->pdev, mapping, len, PCI_DMA_FROMDEVICE);
461 skb_reserve(copy_skb, RX_OFFSET);
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -0300462 skb_copy_from_linear_data(skb, skb_put(copy_skb, len),
463 len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 pci_dma_sync_single_for_device(de->pdev, mapping, len, PCI_DMA_FROMDEVICE);
465
466 /* We'll reuse the original ring buffer. */
467 skb = copy_skb;
468 }
469
470 skb->protocol = eth_type_trans (skb, de->dev);
471
472 de->net_stats.rx_packets++;
473 de->net_stats.rx_bytes += skb->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 rc = netif_rx (skb);
475 if (rc == NET_RX_DROP)
476 drop = 1;
477
478rx_next:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 if (rx_tail == (DE_RX_RING_SIZE - 1))
480 de->rx_ring[rx_tail].opts2 =
481 cpu_to_le32(RingEnd | de->rx_buf_sz);
482 else
483 de->rx_ring[rx_tail].opts2 = cpu_to_le32(de->rx_buf_sz);
484 de->rx_ring[rx_tail].addr1 = cpu_to_le32(mapping);
Risto Suominenb991d2b2009-02-08 17:50:34 -0800485 wmb();
486 de->rx_ring[rx_tail].opts1 = cpu_to_le32(DescOwn);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 rx_tail = NEXT_RX(rx_tail);
488 }
489
490 if (!rx_work)
Joe Perchesf639dc72010-01-28 20:59:19 +0000491 dev_warn(&de->dev->dev, "rx work limit reached\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492
493 de->rx_tail = rx_tail;
494}
495
David Howells7d12e782006-10-05 14:55:46 +0100496static irqreturn_t de_interrupt (int irq, void *dev_instance)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497{
498 struct net_device *dev = dev_instance;
Wang Chen8f15ea42008-11-12 23:38:36 -0800499 struct de_private *de = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 u32 status;
501
502 status = dr32(MacStatus);
503 if ((!(status & (IntrOK|IntrErr))) || (status == 0xFFFF))
504 return IRQ_NONE;
505
506 if (netif_msg_intr(de))
507 printk(KERN_DEBUG "%s: intr, status %08x mode %08x desc %u/%u/%u\n",
Joe Perchesf639dc72010-01-28 20:59:19 +0000508 dev->name, status, dr32(MacMode),
509 de->rx_tail, de->tx_head, de->tx_tail);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510
511 dw32(MacStatus, status);
512
513 if (status & (RxIntr | RxEmpty)) {
514 de_rx(de);
515 if (status & RxEmpty)
516 dw32(RxPoll, NormalRxPoll);
517 }
518
519 spin_lock(&de->lock);
520
521 if (status & (TxIntr | TxEmpty))
522 de_tx(de);
523
524 if (status & (LinkPass | LinkFail))
525 de_media_interrupt(de, status);
526
527 spin_unlock(&de->lock);
528
529 if (status & PciErr) {
530 u16 pci_status;
531
532 pci_read_config_word(de->pdev, PCI_STATUS, &pci_status);
533 pci_write_config_word(de->pdev, PCI_STATUS, pci_status);
Joe Perchesf639dc72010-01-28 20:59:19 +0000534 dev_err(&de->dev->dev,
535 "PCI bus error, status=%08x, PCI status=%04x\n",
536 status, pci_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 }
538
539 return IRQ_HANDLED;
540}
541
542static void de_tx (struct de_private *de)
543{
544 unsigned tx_head = de->tx_head;
545 unsigned tx_tail = de->tx_tail;
546
547 while (tx_tail != tx_head) {
548 struct sk_buff *skb;
549 u32 status;
550
551 rmb();
552 status = le32_to_cpu(de->tx_ring[tx_tail].opts1);
553 if (status & DescOwn)
554 break;
555
556 skb = de->tx_skb[tx_tail].skb;
Eric Sesterhenn / snakebyte7e0b58f2006-01-26 22:02:43 +0100557 BUG_ON(!skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 if (unlikely(skb == DE_DUMMY_SKB))
559 goto next;
560
561 if (unlikely(skb == DE_SETUP_SKB)) {
562 pci_unmap_single(de->pdev, de->tx_skb[tx_tail].mapping,
563 sizeof(de->setup_frame), PCI_DMA_TODEVICE);
564 goto next;
565 }
566
567 pci_unmap_single(de->pdev, de->tx_skb[tx_tail].mapping,
568 skb->len, PCI_DMA_TODEVICE);
569
570 if (status & LastFrag) {
571 if (status & TxError) {
572 if (netif_msg_tx_err(de))
573 printk(KERN_DEBUG "%s: tx err, status 0x%x\n",
574 de->dev->name, status);
575 de->net_stats.tx_errors++;
576 if (status & TxOWC)
577 de->net_stats.tx_window_errors++;
578 if (status & TxMaxCol)
579 de->net_stats.tx_aborted_errors++;
580 if (status & TxLinkFail)
581 de->net_stats.tx_carrier_errors++;
582 if (status & TxFIFOUnder)
583 de->net_stats.tx_fifo_errors++;
584 } else {
585 de->net_stats.tx_packets++;
586 de->net_stats.tx_bytes += skb->len;
587 if (netif_msg_tx_done(de))
Joe Perchesf639dc72010-01-28 20:59:19 +0000588 printk(KERN_DEBUG "%s: tx done, slot %d\n",
589 de->dev->name, tx_tail);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 }
591 dev_kfree_skb_irq(skb);
592 }
593
594next:
595 de->tx_skb[tx_tail].skb = NULL;
596
597 tx_tail = NEXT_TX(tx_tail);
598 }
599
600 de->tx_tail = tx_tail;
601
602 if (netif_queue_stopped(de->dev) && (TX_BUFFS_AVAIL(de) > (DE_TX_RING_SIZE / 4)))
603 netif_wake_queue(de->dev);
604}
605
Stephen Hemmingerad096462009-08-31 19:50:53 +0000606static netdev_tx_t de_start_xmit (struct sk_buff *skb,
607 struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608{
Wang Chen8f15ea42008-11-12 23:38:36 -0800609 struct de_private *de = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 unsigned int entry, tx_free;
611 u32 mapping, len, flags = FirstFrag | LastFrag;
612 struct de_desc *txd;
613
614 spin_lock_irq(&de->lock);
615
616 tx_free = TX_BUFFS_AVAIL(de);
617 if (tx_free == 0) {
618 netif_stop_queue(dev);
619 spin_unlock_irq(&de->lock);
Patrick McHardy5b548142009-06-12 06:22:29 +0000620 return NETDEV_TX_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 }
622 tx_free--;
623
624 entry = de->tx_head;
625
626 txd = &de->tx_ring[entry];
627
628 len = skb->len;
629 mapping = pci_map_single(de->pdev, skb->data, len, PCI_DMA_TODEVICE);
630 if (entry == (DE_TX_RING_SIZE - 1))
631 flags |= RingEnd;
632 if (!tx_free || (tx_free == (DE_TX_RING_SIZE / 2)))
633 flags |= TxSwInt;
634 flags |= len;
635 txd->opts2 = cpu_to_le32(flags);
636 txd->addr1 = cpu_to_le32(mapping);
637
638 de->tx_skb[entry].skb = skb;
639 de->tx_skb[entry].mapping = mapping;
640 wmb();
641
642 txd->opts1 = cpu_to_le32(DescOwn);
643 wmb();
644
645 de->tx_head = NEXT_TX(entry);
646 if (netif_msg_tx_queued(de))
647 printk(KERN_DEBUG "%s: tx queued, slot %d, skblen %d\n",
648 dev->name, entry, skb->len);
649
650 if (tx_free == 0)
651 netif_stop_queue(dev);
652
653 spin_unlock_irq(&de->lock);
654
655 /* Trigger an immediate transmit demand. */
656 dw32(TxPoll, NormalTxPoll);
657 dev->trans_start = jiffies;
658
Patrick McHardy6ed10652009-06-23 06:03:08 +0000659 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660}
661
662/* Set or clear the multicast filter for this adaptor.
663 Note that we only use exclusion around actually queueing the
664 new frame, not around filling de->setup_frame. This is non-deterministic
665 when re-entered but still correct. */
666
667#undef set_bit_le
668#define set_bit_le(i,p) do { ((char *)(p))[(i)/8] |= (1<<((i)%8)); } while(0)
669
670static void build_setup_frame_hash(u16 *setup_frm, struct net_device *dev)
671{
Wang Chen8f15ea42008-11-12 23:38:36 -0800672 struct de_private *de = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 u16 hash_table[32];
674 struct dev_mc_list *mclist;
675 int i;
676 u16 *eaddrs;
677
678 memset(hash_table, 0, sizeof(hash_table));
679 set_bit_le(255, hash_table); /* Broadcast entry */
680 /* This should work on big-endian machines as well. */
Jiri Pirko4302b672010-02-18 03:34:54 +0000681 netdev_for_each_mc_addr(mclist, dev) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 int index = ether_crc_le(ETH_ALEN, mclist->dmi_addr) & 0x1ff;
683
684 set_bit_le(index, hash_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 }
686
Jiri Pirko4302b672010-02-18 03:34:54 +0000687 for (i = 0; i < 32; i++) {
688 *setup_frm++ = hash_table[i];
689 *setup_frm++ = hash_table[i];
690 }
691 setup_frm = &de->setup_frame[13*6];
692
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 /* Fill the final entry with our physical address. */
694 eaddrs = (u16 *)dev->dev_addr;
695 *setup_frm++ = eaddrs[0]; *setup_frm++ = eaddrs[0];
696 *setup_frm++ = eaddrs[1]; *setup_frm++ = eaddrs[1];
697 *setup_frm++ = eaddrs[2]; *setup_frm++ = eaddrs[2];
698}
699
700static void build_setup_frame_perfect(u16 *setup_frm, struct net_device *dev)
701{
Wang Chen8f15ea42008-11-12 23:38:36 -0800702 struct de_private *de = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 struct dev_mc_list *mclist;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 u16 *eaddrs;
705
706 /* We have <= 14 addresses so we can use the wonderful
707 16 address perfect filtering of the Tulip. */
Jiri Pirko4302b672010-02-18 03:34:54 +0000708 netdev_for_each_mc_addr(mclist, dev) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 eaddrs = (u16 *)mclist->dmi_addr;
710 *setup_frm++ = *eaddrs; *setup_frm++ = *eaddrs++;
711 *setup_frm++ = *eaddrs; *setup_frm++ = *eaddrs++;
712 *setup_frm++ = *eaddrs; *setup_frm++ = *eaddrs++;
713 }
714 /* Fill the unused entries with the broadcast address. */
Jiri Pirko4302b672010-02-18 03:34:54 +0000715 memset(setup_frm, 0xff, (15 - netdev_mc_count(dev)) * 12);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 setup_frm = &de->setup_frame[15*6];
717
718 /* Fill the final entry with our physical address. */
719 eaddrs = (u16 *)dev->dev_addr;
720 *setup_frm++ = eaddrs[0]; *setup_frm++ = eaddrs[0];
721 *setup_frm++ = eaddrs[1]; *setup_frm++ = eaddrs[1];
722 *setup_frm++ = eaddrs[2]; *setup_frm++ = eaddrs[2];
723}
724
725
726static void __de_set_rx_mode (struct net_device *dev)
727{
Wang Chen8f15ea42008-11-12 23:38:36 -0800728 struct de_private *de = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 u32 macmode;
730 unsigned int entry;
731 u32 mapping;
732 struct de_desc *txd;
733 struct de_desc *dummy_txd = NULL;
734
735 macmode = dr32(MacMode) & ~(AcceptAllMulticast | AcceptAllPhys);
736
737 if (dev->flags & IFF_PROMISC) { /* Set promiscuous. */
738 macmode |= AcceptAllMulticast | AcceptAllPhys;
739 goto out;
740 }
741
Jiri Pirko4cd24ea2010-02-08 04:30:35 +0000742 if ((netdev_mc_count(dev) > 1000) || (dev->flags & IFF_ALLMULTI)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 /* Too many to filter well -- accept all multicasts. */
744 macmode |= AcceptAllMulticast;
745 goto out;
746 }
747
748 /* Note that only the low-address shortword of setup_frame is valid!
749 The values are doubled for big-endian architectures. */
Jiri Pirko4cd24ea2010-02-08 04:30:35 +0000750 if (netdev_mc_count(dev) > 14) /* Must use a multicast hash table. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 build_setup_frame_hash (de->setup_frame, dev);
752 else
753 build_setup_frame_perfect (de->setup_frame, dev);
754
755 /*
756 * Now add this frame to the Tx list.
757 */
758
759 entry = de->tx_head;
760
761 /* Avoid a chip errata by prefixing a dummy entry. */
762 if (entry != 0) {
763 de->tx_skb[entry].skb = DE_DUMMY_SKB;
764
765 dummy_txd = &de->tx_ring[entry];
766 dummy_txd->opts2 = (entry == (DE_TX_RING_SIZE - 1)) ?
767 cpu_to_le32(RingEnd) : 0;
768 dummy_txd->addr1 = 0;
769
770 /* Must set DescOwned later to avoid race with chip */
771
772 entry = NEXT_TX(entry);
773 }
774
775 de->tx_skb[entry].skb = DE_SETUP_SKB;
776 de->tx_skb[entry].mapping = mapping =
777 pci_map_single (de->pdev, de->setup_frame,
778 sizeof (de->setup_frame), PCI_DMA_TODEVICE);
779
780 /* Put the setup frame on the Tx list. */
781 txd = &de->tx_ring[entry];
782 if (entry == (DE_TX_RING_SIZE - 1))
783 txd->opts2 = cpu_to_le32(SetupFrame | RingEnd | sizeof (de->setup_frame));
784 else
785 txd->opts2 = cpu_to_le32(SetupFrame | sizeof (de->setup_frame));
786 txd->addr1 = cpu_to_le32(mapping);
787 wmb();
788
789 txd->opts1 = cpu_to_le32(DescOwn);
790 wmb();
791
792 if (dummy_txd) {
793 dummy_txd->opts1 = cpu_to_le32(DescOwn);
794 wmb();
795 }
796
797 de->tx_head = NEXT_TX(entry);
798
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 if (TX_BUFFS_AVAIL(de) == 0)
800 netif_stop_queue(dev);
801
802 /* Trigger an immediate transmit demand. */
803 dw32(TxPoll, NormalTxPoll);
804
805out:
806 if (macmode != dr32(MacMode))
807 dw32(MacMode, macmode);
808}
809
810static void de_set_rx_mode (struct net_device *dev)
811{
812 unsigned long flags;
Wang Chen8f15ea42008-11-12 23:38:36 -0800813 struct de_private *de = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814
815 spin_lock_irqsave (&de->lock, flags);
816 __de_set_rx_mode(dev);
817 spin_unlock_irqrestore (&de->lock, flags);
818}
819
820static inline void de_rx_missed(struct de_private *de, u32 rx_missed)
821{
822 if (unlikely(rx_missed & RxMissedOver))
823 de->net_stats.rx_missed_errors += RxMissedMask;
824 else
825 de->net_stats.rx_missed_errors += (rx_missed & RxMissedMask);
826}
827
828static void __de_get_stats(struct de_private *de)
829{
830 u32 tmp = dr32(RxMissed); /* self-clearing */
831
832 de_rx_missed(de, tmp);
833}
834
835static struct net_device_stats *de_get_stats(struct net_device *dev)
836{
Wang Chen8f15ea42008-11-12 23:38:36 -0800837 struct de_private *de = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838
839 /* The chip only need report frame silently dropped. */
840 spin_lock_irq(&de->lock);
841 if (netif_running(dev) && netif_device_present(dev))
842 __de_get_stats(de);
843 spin_unlock_irq(&de->lock);
844
845 return &de->net_stats;
846}
847
848static inline int de_is_running (struct de_private *de)
849{
850 return (dr32(MacStatus) & (RxState | TxState)) ? 1 : 0;
851}
852
853static void de_stop_rxtx (struct de_private *de)
854{
855 u32 macmode;
Grant Grundler69cac982008-03-08 18:33:16 -0700856 unsigned int i = 1300/100;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857
858 macmode = dr32(MacMode);
859 if (macmode & RxTx) {
860 dw32(MacMode, macmode & ~RxTx);
861 dr32(MacMode);
862 }
863
Grant Grundler69cac982008-03-08 18:33:16 -0700864 /* wait until in-flight frame completes.
865 * Max time @ 10BT: 1500*8b/10Mbps == 1200us (+ 100us margin)
866 * Typically expect this loop to end in < 50 us on 100BT.
867 */
868 while (--i) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 if (!de_is_running(de))
870 return;
Grant Grundler69cac982008-03-08 18:33:16 -0700871 udelay(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 }
Jeff Garzikf3b197a2006-05-26 21:39:03 -0400873
Joe Perchesf639dc72010-01-28 20:59:19 +0000874 dev_warn(&de->dev->dev, "timeout expired stopping DMA\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875}
876
877static inline void de_start_rxtx (struct de_private *de)
878{
879 u32 macmode;
880
881 macmode = dr32(MacMode);
882 if ((macmode & RxTx) != RxTx) {
883 dw32(MacMode, macmode | RxTx);
884 dr32(MacMode);
885 }
886}
887
888static void de_stop_hw (struct de_private *de)
889{
890
891 udelay(5);
892 dw32(IntrMask, 0);
893
894 de_stop_rxtx(de);
895
896 dw32(MacStatus, dr32(MacStatus));
897
898 udelay(10);
899
900 de->rx_tail = 0;
901 de->tx_head = de->tx_tail = 0;
902}
903
904static void de_link_up(struct de_private *de)
905{
906 if (!netif_carrier_ok(de->dev)) {
907 netif_carrier_on(de->dev);
908 if (netif_msg_link(de))
Joe Perchesf639dc72010-01-28 20:59:19 +0000909 dev_info(&de->dev->dev, "link up, media %s\n",
910 media_name[de->media_type]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 }
912}
913
914static void de_link_down(struct de_private *de)
915{
916 if (netif_carrier_ok(de->dev)) {
917 netif_carrier_off(de->dev);
918 if (netif_msg_link(de))
Joe Perchesf639dc72010-01-28 20:59:19 +0000919 dev_info(&de->dev->dev, "link down\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 }
921}
922
923static void de_set_media (struct de_private *de)
924{
925 unsigned media = de->media_type;
926 u32 macmode = dr32(MacMode);
927
Ondrej Zaryf25f0f82008-02-25 18:45:46 +0100928 if (de_is_running(de))
Joe Perchesf639dc72010-01-28 20:59:19 +0000929 dev_warn(&de->dev->dev,
930 "chip is running while changing media!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931
932 if (de->de21040)
933 dw32(CSR11, FULL_DUPLEX_MAGIC);
934 dw32(CSR13, 0); /* Reset phy */
935 dw32(CSR14, de->media[media].csr14);
936 dw32(CSR15, de->media[media].csr15);
937 dw32(CSR13, de->media[media].csr13);
938
939 /* must delay 10ms before writing to other registers,
940 * especially CSR6
941 */
942 mdelay(10);
943
944 if (media == DE_MEDIA_TP_FD)
945 macmode |= FullDuplex;
946 else
947 macmode &= ~FullDuplex;
Jeff Garzikf3b197a2006-05-26 21:39:03 -0400948
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949 if (netif_msg_link(de)) {
Joe Perchesf639dc72010-01-28 20:59:19 +0000950 dev_info(&de->dev->dev, "set link %s\n", media_name[media]);
951 dev_info(&de->dev->dev, "mode 0x%x, sia 0x%x,0x%x,0x%x,0x%x\n",
952 dr32(MacMode), dr32(SIAStatus),
953 dr32(CSR13), dr32(CSR14), dr32(CSR15));
954
955 dev_info(&de->dev->dev,
956 "set mode 0x%x, set sia 0x%x,0x%x,0x%x\n",
957 macmode, de->media[media].csr13,
958 de->media[media].csr14, de->media[media].csr15);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959 }
960 if (macmode != dr32(MacMode))
961 dw32(MacMode, macmode);
962}
963
964static void de_next_media (struct de_private *de, u32 *media,
965 unsigned int n_media)
966{
967 unsigned int i;
968
969 for (i = 0; i < n_media; i++) {
970 if (de_ok_to_advertise(de, media[i])) {
971 de->media_type = media[i];
972 return;
973 }
974 }
975}
976
977static void de21040_media_timer (unsigned long data)
978{
979 struct de_private *de = (struct de_private *) data;
980 struct net_device *dev = de->dev;
981 u32 status = dr32(SIAStatus);
982 unsigned int carrier;
983 unsigned long flags;
Jeff Garzikf3b197a2006-05-26 21:39:03 -0400984
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985 carrier = (status & NetCxnErr) ? 0 : 1;
Jeff Garzikf3b197a2006-05-26 21:39:03 -0400986
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987 if (carrier) {
988 if (de->media_type != DE_MEDIA_AUI && (status & LinkFailStatus))
989 goto no_link_yet;
990
991 de->media_timer.expires = jiffies + DE_TIMER_LINK;
992 add_timer(&de->media_timer);
993 if (!netif_carrier_ok(dev))
994 de_link_up(de);
995 else
996 if (netif_msg_timer(de))
Joe Perchesf639dc72010-01-28 20:59:19 +0000997 dev_info(&dev->dev, "%s link ok, status %x\n",
998 media_name[de->media_type], status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 return;
1000 }
1001
Jeff Garzikf3b197a2006-05-26 21:39:03 -04001002 de_link_down(de);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003
1004 if (de->media_lock)
1005 return;
1006
1007 if (de->media_type == DE_MEDIA_AUI) {
1008 u32 next_state = DE_MEDIA_TP;
1009 de_next_media(de, &next_state, 1);
1010 } else {
1011 u32 next_state = DE_MEDIA_AUI;
1012 de_next_media(de, &next_state, 1);
1013 }
1014
1015 spin_lock_irqsave(&de->lock, flags);
1016 de_stop_rxtx(de);
1017 spin_unlock_irqrestore(&de->lock, flags);
1018 de_set_media(de);
1019 de_start_rxtx(de);
1020
1021no_link_yet:
1022 de->media_timer.expires = jiffies + DE_TIMER_NO_LINK;
1023 add_timer(&de->media_timer);
1024
1025 if (netif_msg_timer(de))
Joe Perchesf639dc72010-01-28 20:59:19 +00001026 dev_info(&dev->dev, "no link, trying media %s, status %x\n",
1027 media_name[de->media_type], status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028}
1029
1030static unsigned int de_ok_to_advertise (struct de_private *de, u32 new_media)
1031{
1032 switch (new_media) {
1033 case DE_MEDIA_TP_AUTO:
1034 if (!(de->media_advertise & ADVERTISED_Autoneg))
1035 return 0;
1036 if (!(de->media_advertise & (ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full)))
1037 return 0;
1038 break;
1039 case DE_MEDIA_BNC:
1040 if (!(de->media_advertise & ADVERTISED_BNC))
1041 return 0;
1042 break;
1043 case DE_MEDIA_AUI:
1044 if (!(de->media_advertise & ADVERTISED_AUI))
1045 return 0;
1046 break;
1047 case DE_MEDIA_TP:
1048 if (!(de->media_advertise & ADVERTISED_10baseT_Half))
1049 return 0;
1050 break;
1051 case DE_MEDIA_TP_FD:
1052 if (!(de->media_advertise & ADVERTISED_10baseT_Full))
1053 return 0;
1054 break;
1055 }
Jeff Garzikf3b197a2006-05-26 21:39:03 -04001056
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 return 1;
1058}
1059
1060static void de21041_media_timer (unsigned long data)
1061{
1062 struct de_private *de = (struct de_private *) data;
1063 struct net_device *dev = de->dev;
1064 u32 status = dr32(SIAStatus);
1065 unsigned int carrier;
1066 unsigned long flags;
Jeff Garzikf3b197a2006-05-26 21:39:03 -04001067
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 carrier = (status & NetCxnErr) ? 0 : 1;
Jeff Garzikf3b197a2006-05-26 21:39:03 -04001069
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070 if (carrier) {
1071 if ((de->media_type == DE_MEDIA_TP_AUTO ||
1072 de->media_type == DE_MEDIA_TP ||
1073 de->media_type == DE_MEDIA_TP_FD) &&
1074 (status & LinkFailStatus))
1075 goto no_link_yet;
1076
1077 de->media_timer.expires = jiffies + DE_TIMER_LINK;
1078 add_timer(&de->media_timer);
1079 if (!netif_carrier_ok(dev))
1080 de_link_up(de);
1081 else
1082 if (netif_msg_timer(de))
Joe Perchesf639dc72010-01-28 20:59:19 +00001083 dev_info(&dev->dev,
1084 "%s link ok, mode %x status %x\n",
1085 media_name[de->media_type],
1086 dr32(MacMode), status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087 return;
1088 }
1089
Jeff Garzikf3b197a2006-05-26 21:39:03 -04001090 de_link_down(de);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091
1092 /* if media type locked, don't switch media */
1093 if (de->media_lock)
1094 goto set_media;
1095
1096 /* if activity detected, use that as hint for new media type */
1097 if (status & NonselPortActive) {
1098 unsigned int have_media = 1;
1099
1100 /* if AUI/BNC selected, then activity is on TP port */
1101 if (de->media_type == DE_MEDIA_AUI ||
1102 de->media_type == DE_MEDIA_BNC) {
1103 if (de_ok_to_advertise(de, DE_MEDIA_TP_AUTO))
1104 de->media_type = DE_MEDIA_TP_AUTO;
1105 else
1106 have_media = 0;
1107 }
1108
1109 /* TP selected. If there is only TP and BNC, then it's BNC */
1110 else if (((de->media_supported & DE_AUI_BNC) == SUPPORTED_BNC) &&
1111 de_ok_to_advertise(de, DE_MEDIA_BNC))
1112 de->media_type = DE_MEDIA_BNC;
1113
1114 /* TP selected. If there is only TP and AUI, then it's AUI */
1115 else if (((de->media_supported & DE_AUI_BNC) == SUPPORTED_AUI) &&
1116 de_ok_to_advertise(de, DE_MEDIA_AUI))
1117 de->media_type = DE_MEDIA_AUI;
1118
1119 /* otherwise, ignore the hint */
1120 else
1121 have_media = 0;
1122
1123 if (have_media)
1124 goto set_media;
1125 }
1126
1127 /*
1128 * Absent or ambiguous activity hint, move to next advertised
1129 * media state. If de->media_type is left unchanged, this
1130 * simply resets the PHY and reloads the current media settings.
1131 */
1132 if (de->media_type == DE_MEDIA_AUI) {
1133 u32 next_states[] = { DE_MEDIA_BNC, DE_MEDIA_TP_AUTO };
1134 de_next_media(de, next_states, ARRAY_SIZE(next_states));
1135 } else if (de->media_type == DE_MEDIA_BNC) {
1136 u32 next_states[] = { DE_MEDIA_TP_AUTO, DE_MEDIA_AUI };
1137 de_next_media(de, next_states, ARRAY_SIZE(next_states));
1138 } else {
1139 u32 next_states[] = { DE_MEDIA_AUI, DE_MEDIA_BNC, DE_MEDIA_TP_AUTO };
1140 de_next_media(de, next_states, ARRAY_SIZE(next_states));
1141 }
Jeff Garzikf3b197a2006-05-26 21:39:03 -04001142
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143set_media:
1144 spin_lock_irqsave(&de->lock, flags);
1145 de_stop_rxtx(de);
1146 spin_unlock_irqrestore(&de->lock, flags);
1147 de_set_media(de);
1148 de_start_rxtx(de);
1149
1150no_link_yet:
1151 de->media_timer.expires = jiffies + DE_TIMER_NO_LINK;
1152 add_timer(&de->media_timer);
1153
1154 if (netif_msg_timer(de))
Joe Perchesf639dc72010-01-28 20:59:19 +00001155 dev_info(&dev->dev, "no link, trying media %s, status %x\n",
1156 media_name[de->media_type], status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157}
1158
1159static void de_media_interrupt (struct de_private *de, u32 status)
1160{
1161 if (status & LinkPass) {
1162 de_link_up(de);
1163 mod_timer(&de->media_timer, jiffies + DE_TIMER_LINK);
1164 return;
1165 }
Jeff Garzikf3b197a2006-05-26 21:39:03 -04001166
Eric Sesterhenn / snakebyte7e0b58f2006-01-26 22:02:43 +01001167 BUG_ON(!(status & LinkFail));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168
1169 if (netif_carrier_ok(de->dev)) {
1170 de_link_down(de);
1171 mod_timer(&de->media_timer, jiffies + DE_TIMER_NO_LINK);
1172 }
1173}
1174
1175static int de_reset_mac (struct de_private *de)
1176{
1177 u32 status, tmp;
1178
1179 /*
1180 * Reset MAC. de4x5.c and tulip.c examined for "advice"
1181 * in this area.
1182 */
1183
1184 if (dr32(BusMode) == 0xffffffff)
1185 return -EBUSY;
1186
1187 /* Reset the chip, holding bit 0 set at least 50 PCI cycles. */
1188 dw32 (BusMode, CmdReset);
1189 mdelay (1);
1190
1191 dw32 (BusMode, de_bus_mode);
1192 mdelay (1);
1193
1194 for (tmp = 0; tmp < 5; tmp++) {
1195 dr32 (BusMode);
1196 mdelay (1);
1197 }
1198
1199 mdelay (1);
1200
1201 status = dr32(MacStatus);
1202 if (status & (RxState | TxState))
1203 return -EBUSY;
1204 if (status == 0xffffffff)
1205 return -ENODEV;
1206 return 0;
1207}
1208
1209static void de_adapter_wake (struct de_private *de)
1210{
1211 u32 pmctl;
1212
1213 if (de->de21040)
1214 return;
1215
1216 pci_read_config_dword(de->pdev, PCIPM, &pmctl);
1217 if (pmctl & PM_Mask) {
1218 pmctl &= ~PM_Mask;
1219 pci_write_config_dword(de->pdev, PCIPM, pmctl);
1220
1221 /* de4x5.c delays, so we do too */
1222 msleep(10);
1223 }
1224}
1225
1226static void de_adapter_sleep (struct de_private *de)
1227{
1228 u32 pmctl;
1229
1230 if (de->de21040)
1231 return;
1232
1233 pci_read_config_dword(de->pdev, PCIPM, &pmctl);
1234 pmctl |= PM_Sleep;
1235 pci_write_config_dword(de->pdev, PCIPM, pmctl);
1236}
1237
1238static int de_init_hw (struct de_private *de)
1239{
1240 struct net_device *dev = de->dev;
1241 u32 macmode;
1242 int rc;
1243
1244 de_adapter_wake(de);
Jeff Garzikf3b197a2006-05-26 21:39:03 -04001245
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246 macmode = dr32(MacMode) & ~MacModeClear;
1247
1248 rc = de_reset_mac(de);
1249 if (rc)
1250 return rc;
1251
1252 de_set_media(de); /* reset phy */
1253
1254 dw32(RxRingAddr, de->ring_dma);
1255 dw32(TxRingAddr, de->ring_dma + (sizeof(struct de_desc) * DE_RX_RING_SIZE));
1256
1257 dw32(MacMode, RxTx | macmode);
1258
1259 dr32(RxMissed); /* self-clearing */
1260
1261 dw32(IntrMask, de_intr_mask);
1262
1263 de_set_rx_mode(dev);
1264
1265 return 0;
1266}
1267
1268static int de_refill_rx (struct de_private *de)
1269{
1270 unsigned i;
1271
1272 for (i = 0; i < DE_RX_RING_SIZE; i++) {
1273 struct sk_buff *skb;
1274
1275 skb = dev_alloc_skb(de->rx_buf_sz);
1276 if (!skb)
1277 goto err_out;
1278
1279 skb->dev = de->dev;
1280
1281 de->rx_skb[i].mapping = pci_map_single(de->pdev,
David S. Miller689be432005-06-28 15:25:31 -07001282 skb->data, de->rx_buf_sz, PCI_DMA_FROMDEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283 de->rx_skb[i].skb = skb;
1284
1285 de->rx_ring[i].opts1 = cpu_to_le32(DescOwn);
1286 if (i == (DE_RX_RING_SIZE - 1))
1287 de->rx_ring[i].opts2 =
1288 cpu_to_le32(RingEnd | de->rx_buf_sz);
1289 else
1290 de->rx_ring[i].opts2 = cpu_to_le32(de->rx_buf_sz);
1291 de->rx_ring[i].addr1 = cpu_to_le32(de->rx_skb[i].mapping);
1292 de->rx_ring[i].addr2 = 0;
1293 }
1294
1295 return 0;
1296
1297err_out:
1298 de_clean_rings(de);
1299 return -ENOMEM;
1300}
1301
1302static int de_init_rings (struct de_private *de)
1303{
1304 memset(de->tx_ring, 0, sizeof(struct de_desc) * DE_TX_RING_SIZE);
1305 de->tx_ring[DE_TX_RING_SIZE - 1].opts2 = cpu_to_le32(RingEnd);
1306
1307 de->rx_tail = 0;
1308 de->tx_head = de->tx_tail = 0;
1309
1310 return de_refill_rx (de);
1311}
1312
1313static int de_alloc_rings (struct de_private *de)
1314{
1315 de->rx_ring = pci_alloc_consistent(de->pdev, DE_RING_BYTES, &de->ring_dma);
1316 if (!de->rx_ring)
1317 return -ENOMEM;
1318 de->tx_ring = &de->rx_ring[DE_RX_RING_SIZE];
1319 return de_init_rings(de);
1320}
1321
1322static void de_clean_rings (struct de_private *de)
1323{
1324 unsigned i;
1325
1326 memset(de->rx_ring, 0, sizeof(struct de_desc) * DE_RX_RING_SIZE);
1327 de->rx_ring[DE_RX_RING_SIZE - 1].opts2 = cpu_to_le32(RingEnd);
1328 wmb();
1329 memset(de->tx_ring, 0, sizeof(struct de_desc) * DE_TX_RING_SIZE);
1330 de->tx_ring[DE_TX_RING_SIZE - 1].opts2 = cpu_to_le32(RingEnd);
1331 wmb();
1332
1333 for (i = 0; i < DE_RX_RING_SIZE; i++) {
1334 if (de->rx_skb[i].skb) {
1335 pci_unmap_single(de->pdev, de->rx_skb[i].mapping,
1336 de->rx_buf_sz, PCI_DMA_FROMDEVICE);
1337 dev_kfree_skb(de->rx_skb[i].skb);
1338 }
1339 }
1340
1341 for (i = 0; i < DE_TX_RING_SIZE; i++) {
1342 struct sk_buff *skb = de->tx_skb[i].skb;
1343 if ((skb) && (skb != DE_DUMMY_SKB)) {
1344 if (skb != DE_SETUP_SKB) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345 de->net_stats.tx_dropped++;
1346 pci_unmap_single(de->pdev,
1347 de->tx_skb[i].mapping,
1348 skb->len, PCI_DMA_TODEVICE);
Eric Sesterhenn5185c7c2006-03-22 22:30:34 +01001349 dev_kfree_skb(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350 } else {
1351 pci_unmap_single(de->pdev,
1352 de->tx_skb[i].mapping,
1353 sizeof(de->setup_frame),
1354 PCI_DMA_TODEVICE);
1355 }
1356 }
1357 }
1358
1359 memset(&de->rx_skb, 0, sizeof(struct ring_info) * DE_RX_RING_SIZE);
1360 memset(&de->tx_skb, 0, sizeof(struct ring_info) * DE_TX_RING_SIZE);
1361}
1362
1363static void de_free_rings (struct de_private *de)
1364{
1365 de_clean_rings(de);
1366 pci_free_consistent(de->pdev, DE_RING_BYTES, de->rx_ring, de->ring_dma);
1367 de->rx_ring = NULL;
1368 de->tx_ring = NULL;
1369}
1370
1371static int de_open (struct net_device *dev)
1372{
Wang Chen8f15ea42008-11-12 23:38:36 -08001373 struct de_private *de = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375
1376 if (netif_msg_ifup(de))
1377 printk(KERN_DEBUG "%s: enabling interface\n", dev->name);
1378
1379 de->rx_buf_sz = (dev->mtu <= 1500 ? PKT_BUF_SZ : dev->mtu + 32);
1380
1381 rc = de_alloc_rings(de);
1382 if (rc) {
Joe Perchesf639dc72010-01-28 20:59:19 +00001383 dev_err(&dev->dev, "ring allocation failure, err=%d\n", rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384 return rc;
1385 }
1386
Francois Romieu3f735b72006-03-08 22:41:15 +01001387 dw32(IntrMask, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388
Thomas Gleixner1fb9df52006-07-01 19:29:39 -07001389 rc = request_irq(dev->irq, de_interrupt, IRQF_SHARED, dev->name, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390 if (rc) {
Joe Perchesf639dc72010-01-28 20:59:19 +00001391 dev_err(&dev->dev, "IRQ %d request failure, err=%d\n",
1392 dev->irq, rc);
Francois Romieu3f735b72006-03-08 22:41:15 +01001393 goto err_out_free;
1394 }
1395
1396 rc = de_init_hw(de);
1397 if (rc) {
Joe Perchesf639dc72010-01-28 20:59:19 +00001398 dev_err(&dev->dev, "h/w init failure, err=%d\n", rc);
Francois Romieu3f735b72006-03-08 22:41:15 +01001399 goto err_out_free_irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400 }
1401
1402 netif_start_queue(dev);
1403 mod_timer(&de->media_timer, jiffies + DE_TIMER_NO_LINK);
1404
1405 return 0;
1406
Francois Romieu3f735b72006-03-08 22:41:15 +01001407err_out_free_irq:
1408 free_irq(dev->irq, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409err_out_free:
1410 de_free_rings(de);
1411 return rc;
1412}
1413
1414static int de_close (struct net_device *dev)
1415{
Wang Chen8f15ea42008-11-12 23:38:36 -08001416 struct de_private *de = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 unsigned long flags;
1418
1419 if (netif_msg_ifdown(de))
1420 printk(KERN_DEBUG "%s: disabling interface\n", dev->name);
1421
1422 del_timer_sync(&de->media_timer);
1423
1424 spin_lock_irqsave(&de->lock, flags);
1425 de_stop_hw(de);
1426 netif_stop_queue(dev);
1427 netif_carrier_off(dev);
1428 spin_unlock_irqrestore(&de->lock, flags);
Jeff Garzikf3b197a2006-05-26 21:39:03 -04001429
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 free_irq(dev->irq, dev);
1431
1432 de_free_rings(de);
1433 de_adapter_sleep(de);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434 return 0;
1435}
1436
1437static void de_tx_timeout (struct net_device *dev)
1438{
Wang Chen8f15ea42008-11-12 23:38:36 -08001439 struct de_private *de = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440
1441 printk(KERN_DEBUG "%s: NIC status %08x mode %08x sia %08x desc %u/%u/%u\n",
1442 dev->name, dr32(MacStatus), dr32(MacMode), dr32(SIAStatus),
1443 de->rx_tail, de->tx_head, de->tx_tail);
1444
1445 del_timer_sync(&de->media_timer);
1446
1447 disable_irq(dev->irq);
1448 spin_lock_irq(&de->lock);
1449
1450 de_stop_hw(de);
1451 netif_stop_queue(dev);
1452 netif_carrier_off(dev);
1453
1454 spin_unlock_irq(&de->lock);
1455 enable_irq(dev->irq);
Jeff Garzikf3b197a2006-05-26 21:39:03 -04001456
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457 /* Update the error counts. */
1458 __de_get_stats(de);
1459
1460 synchronize_irq(dev->irq);
1461 de_clean_rings(de);
1462
Francois Romieu39bf4292006-03-08 22:45:52 +01001463 de_init_rings(de);
1464
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465 de_init_hw(de);
Jeff Garzikf3b197a2006-05-26 21:39:03 -04001466
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467 netif_wake_queue(dev);
1468}
1469
1470static void __de_get_regs(struct de_private *de, u8 *buf)
1471{
1472 int i;
1473 u32 *rbuf = (u32 *)buf;
Jeff Garzikf3b197a2006-05-26 21:39:03 -04001474
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475 /* read all CSRs */
1476 for (i = 0; i < DE_NUM_REGS; i++)
1477 rbuf[i] = dr32(i * 8);
1478
1479 /* handle self-clearing RxMissed counter, CSR8 */
1480 de_rx_missed(de, rbuf[8]);
1481}
1482
1483static int __de_get_settings(struct de_private *de, struct ethtool_cmd *ecmd)
1484{
1485 ecmd->supported = de->media_supported;
1486 ecmd->transceiver = XCVR_INTERNAL;
1487 ecmd->phy_address = 0;
1488 ecmd->advertising = de->media_advertise;
Jeff Garzikf3b197a2006-05-26 21:39:03 -04001489
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490 switch (de->media_type) {
1491 case DE_MEDIA_AUI:
1492 ecmd->port = PORT_AUI;
1493 ecmd->speed = 5;
1494 break;
1495 case DE_MEDIA_BNC:
1496 ecmd->port = PORT_BNC;
1497 ecmd->speed = 2;
1498 break;
1499 default:
1500 ecmd->port = PORT_TP;
1501 ecmd->speed = SPEED_10;
1502 break;
1503 }
Jeff Garzikf3b197a2006-05-26 21:39:03 -04001504
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505 if (dr32(MacMode) & FullDuplex)
1506 ecmd->duplex = DUPLEX_FULL;
1507 else
1508 ecmd->duplex = DUPLEX_HALF;
1509
1510 if (de->media_lock)
1511 ecmd->autoneg = AUTONEG_DISABLE;
1512 else
1513 ecmd->autoneg = AUTONEG_ENABLE;
1514
1515 /* ignore maxtxpkt, maxrxpkt for now */
1516
1517 return 0;
1518}
1519
1520static int __de_set_settings(struct de_private *de, struct ethtool_cmd *ecmd)
1521{
1522 u32 new_media;
1523 unsigned int media_lock;
1524
1525 if (ecmd->speed != SPEED_10 && ecmd->speed != 5 && ecmd->speed != 2)
1526 return -EINVAL;
1527 if (de->de21040 && ecmd->speed == 2)
1528 return -EINVAL;
1529 if (ecmd->duplex != DUPLEX_HALF && ecmd->duplex != DUPLEX_FULL)
1530 return -EINVAL;
1531 if (ecmd->port != PORT_TP && ecmd->port != PORT_AUI && ecmd->port != PORT_BNC)
1532 return -EINVAL;
1533 if (de->de21040 && ecmd->port == PORT_BNC)
1534 return -EINVAL;
1535 if (ecmd->transceiver != XCVR_INTERNAL)
1536 return -EINVAL;
1537 if (ecmd->autoneg != AUTONEG_DISABLE && ecmd->autoneg != AUTONEG_ENABLE)
1538 return -EINVAL;
1539 if (ecmd->advertising & ~de->media_supported)
1540 return -EINVAL;
1541 if (ecmd->autoneg == AUTONEG_ENABLE &&
1542 (!(ecmd->advertising & ADVERTISED_Autoneg)))
1543 return -EINVAL;
Jeff Garzikf3b197a2006-05-26 21:39:03 -04001544
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545 switch (ecmd->port) {
1546 case PORT_AUI:
1547 new_media = DE_MEDIA_AUI;
1548 if (!(ecmd->advertising & ADVERTISED_AUI))
1549 return -EINVAL;
1550 break;
1551 case PORT_BNC:
1552 new_media = DE_MEDIA_BNC;
1553 if (!(ecmd->advertising & ADVERTISED_BNC))
1554 return -EINVAL;
1555 break;
1556 default:
1557 if (ecmd->autoneg == AUTONEG_ENABLE)
1558 new_media = DE_MEDIA_TP_AUTO;
1559 else if (ecmd->duplex == DUPLEX_FULL)
1560 new_media = DE_MEDIA_TP_FD;
1561 else
1562 new_media = DE_MEDIA_TP;
1563 if (!(ecmd->advertising & ADVERTISED_TP))
1564 return -EINVAL;
1565 if (!(ecmd->advertising & (ADVERTISED_10baseT_Full | ADVERTISED_10baseT_Half)))
1566 return -EINVAL;
1567 break;
1568 }
Jeff Garzikf3b197a2006-05-26 21:39:03 -04001569
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570 media_lock = (ecmd->autoneg == AUTONEG_ENABLE) ? 0 : 1;
Jeff Garzikf3b197a2006-05-26 21:39:03 -04001571
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572 if ((new_media == de->media_type) &&
1573 (media_lock == de->media_lock) &&
1574 (ecmd->advertising == de->media_advertise))
1575 return 0; /* nothing to change */
Jeff Garzikf3b197a2006-05-26 21:39:03 -04001576
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577 de_link_down(de);
1578 de_stop_rxtx(de);
Jeff Garzikf3b197a2006-05-26 21:39:03 -04001579
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580 de->media_type = new_media;
1581 de->media_lock = media_lock;
1582 de->media_advertise = ecmd->advertising;
1583 de_set_media(de);
Jeff Garzikf3b197a2006-05-26 21:39:03 -04001584
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585 return 0;
1586}
1587
1588static void de_get_drvinfo (struct net_device *dev,struct ethtool_drvinfo *info)
1589{
Wang Chen8f15ea42008-11-12 23:38:36 -08001590 struct de_private *de = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591
1592 strcpy (info->driver, DRV_NAME);
1593 strcpy (info->version, DRV_VERSION);
1594 strcpy (info->bus_info, pci_name(de->pdev));
1595 info->eedump_len = DE_EEPROM_SIZE;
1596}
1597
1598static int de_get_regs_len(struct net_device *dev)
1599{
1600 return DE_REGS_SIZE;
1601}
1602
1603static int de_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
1604{
Wang Chen8f15ea42008-11-12 23:38:36 -08001605 struct de_private *de = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606 int rc;
1607
1608 spin_lock_irq(&de->lock);
1609 rc = __de_get_settings(de, ecmd);
1610 spin_unlock_irq(&de->lock);
1611
1612 return rc;
1613}
1614
1615static int de_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
1616{
Wang Chen8f15ea42008-11-12 23:38:36 -08001617 struct de_private *de = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618 int rc;
1619
1620 spin_lock_irq(&de->lock);
1621 rc = __de_set_settings(de, ecmd);
1622 spin_unlock_irq(&de->lock);
1623
1624 return rc;
1625}
1626
1627static u32 de_get_msglevel(struct net_device *dev)
1628{
Wang Chen8f15ea42008-11-12 23:38:36 -08001629 struct de_private *de = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630
1631 return de->msg_enable;
1632}
1633
1634static void de_set_msglevel(struct net_device *dev, u32 msglvl)
1635{
Wang Chen8f15ea42008-11-12 23:38:36 -08001636 struct de_private *de = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637
1638 de->msg_enable = msglvl;
1639}
1640
1641static int de_get_eeprom(struct net_device *dev,
1642 struct ethtool_eeprom *eeprom, u8 *data)
1643{
Wang Chen8f15ea42008-11-12 23:38:36 -08001644 struct de_private *de = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645
1646 if (!de->ee_data)
1647 return -EOPNOTSUPP;
1648 if ((eeprom->offset != 0) || (eeprom->magic != 0) ||
1649 (eeprom->len != DE_EEPROM_SIZE))
1650 return -EINVAL;
1651 memcpy(data, de->ee_data, eeprom->len);
1652
1653 return 0;
1654}
1655
1656static int de_nway_reset(struct net_device *dev)
1657{
Wang Chen8f15ea42008-11-12 23:38:36 -08001658 struct de_private *de = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659 u32 status;
1660
1661 if (de->media_type != DE_MEDIA_TP_AUTO)
1662 return -EINVAL;
1663 if (netif_carrier_ok(de->dev))
1664 de_link_down(de);
1665
1666 status = dr32(SIAStatus);
1667 dw32(SIAStatus, (status & ~NWayState) | NWayRestart);
1668 if (netif_msg_link(de))
Joe Perchesf639dc72010-01-28 20:59:19 +00001669 dev_info(&de->dev->dev, "link nway restart, status %x,%x\n",
1670 status, dr32(SIAStatus));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671 return 0;
1672}
1673
1674static void de_get_regs(struct net_device *dev, struct ethtool_regs *regs,
1675 void *data)
1676{
Wang Chen8f15ea42008-11-12 23:38:36 -08001677 struct de_private *de = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678
1679 regs->version = (DE_REGS_VER << 2) | de->de21040;
1680
1681 spin_lock_irq(&de->lock);
1682 __de_get_regs(de, data);
1683 spin_unlock_irq(&de->lock);
1684}
1685
Jeff Garzik7282d492006-09-13 14:30:00 -04001686static const struct ethtool_ops de_ethtool_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687 .get_link = ethtool_op_get_link,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688 .get_drvinfo = de_get_drvinfo,
1689 .get_regs_len = de_get_regs_len,
1690 .get_settings = de_get_settings,
1691 .set_settings = de_set_settings,
1692 .get_msglevel = de_get_msglevel,
1693 .set_msglevel = de_set_msglevel,
1694 .get_eeprom = de_get_eeprom,
1695 .nway_reset = de_nway_reset,
1696 .get_regs = de_get_regs,
1697};
1698
Prarit Bhargava4c44fd02007-03-06 02:42:00 -08001699static void __devinit de21040_get_mac_address (struct de_private *de)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700{
1701 unsigned i;
1702
1703 dw32 (ROMCmd, 0); /* Reset the pointer with a dummy write. */
Martin Langerbc0da3f2008-10-13 18:49:38 -07001704 udelay(5);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705
1706 for (i = 0; i < 6; i++) {
1707 int value, boguscnt = 100000;
Hannes Ederec1d1ebb2008-12-26 00:07:45 -08001708 do {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709 value = dr32(ROMCmd);
Hannes Ederec1d1ebb2008-12-26 00:07:45 -08001710 } while (value < 0 && --boguscnt > 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711 de->dev->dev_addr[i] = value;
1712 udelay(1);
1713 if (boguscnt <= 0)
Joe Perchesf639dc72010-01-28 20:59:19 +00001714 pr_warning(PFX "timeout reading 21040 MAC address byte %u\n", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715 }
1716}
1717
Prarit Bhargava4c44fd02007-03-06 02:42:00 -08001718static void __devinit de21040_get_media_info(struct de_private *de)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719{
1720 unsigned int i;
1721
1722 de->media_type = DE_MEDIA_TP;
1723 de->media_supported |= SUPPORTED_TP | SUPPORTED_10baseT_Full |
1724 SUPPORTED_10baseT_Half | SUPPORTED_AUI;
1725 de->media_advertise = de->media_supported;
1726
1727 for (i = 0; i < DE_MAX_MEDIA; i++) {
1728 switch (i) {
1729 case DE_MEDIA_AUI:
1730 case DE_MEDIA_TP:
1731 case DE_MEDIA_TP_FD:
1732 de->media[i].type = i;
1733 de->media[i].csr13 = t21040_csr13[i];
1734 de->media[i].csr14 = t21040_csr14[i];
1735 de->media[i].csr15 = t21040_csr15[i];
1736 break;
1737 default:
1738 de->media[i].type = DE_MEDIA_INVALID;
1739 break;
1740 }
1741 }
1742}
1743
1744/* Note: this routine returns extra data bits for size detection. */
Helge Deller4a1d2d82006-10-06 12:12:34 -06001745static unsigned __devinit tulip_read_eeprom(void __iomem *regs, int location, int addr_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746{
1747 int i;
1748 unsigned retval = 0;
1749 void __iomem *ee_addr = regs + ROMCmd;
1750 int read_cmd = location | (EE_READ_CMD << addr_len);
1751
1752 writel(EE_ENB & ~EE_CS, ee_addr);
1753 writel(EE_ENB, ee_addr);
1754
1755 /* Shift the read command bits out. */
1756 for (i = 4 + addr_len; i >= 0; i--) {
1757 short dataval = (read_cmd & (1 << i)) ? EE_DATA_WRITE : 0;
1758 writel(EE_ENB | dataval, ee_addr);
1759 readl(ee_addr);
1760 writel(EE_ENB | dataval | EE_SHIFT_CLK, ee_addr);
1761 readl(ee_addr);
1762 retval = (retval << 1) | ((readl(ee_addr) & EE_DATA_READ) ? 1 : 0);
1763 }
1764 writel(EE_ENB, ee_addr);
1765 readl(ee_addr);
1766
1767 for (i = 16; i > 0; i--) {
1768 writel(EE_ENB | EE_SHIFT_CLK, ee_addr);
1769 readl(ee_addr);
1770 retval = (retval << 1) | ((readl(ee_addr) & EE_DATA_READ) ? 1 : 0);
1771 writel(EE_ENB, ee_addr);
1772 readl(ee_addr);
1773 }
1774
1775 /* Terminate the EEPROM access. */
1776 writel(EE_ENB & ~EE_CS, ee_addr);
1777 return retval;
1778}
1779
Prarit Bhargava4c44fd02007-03-06 02:42:00 -08001780static void __devinit de21041_get_srom_info (struct de_private *de)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781{
1782 unsigned i, sa_offset = 0, ofs;
1783 u8 ee_data[DE_EEPROM_SIZE + 6] = {};
1784 unsigned ee_addr_size = tulip_read_eeprom(de->regs, 0xff, 8) & 0x40000 ? 8 : 6;
1785 struct de_srom_info_leaf *il;
1786 void *bufp;
1787
1788 /* download entire eeprom */
1789 for (i = 0; i < DE_EEPROM_WORDS; i++)
Al Viroc559a5b2007-08-23 00:43:22 -04001790 ((__le16 *)ee_data)[i] =
1791 cpu_to_le16(tulip_read_eeprom(de->regs, i, ee_addr_size));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792
1793 /* DEC now has a specification but early board makers
1794 just put the address in the first EEPROM locations. */
1795 /* This does memcmp(eedata, eedata+16, 8) */
Ralf Baechlebc053d42005-10-10 14:50:46 +01001796
1797#ifndef CONFIG_MIPS_COBALT
1798
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799 for (i = 0; i < 8; i ++)
1800 if (ee_data[i] != ee_data[16+i])
1801 sa_offset = 20;
1802
Ralf Baechlebc053d42005-10-10 14:50:46 +01001803#endif
1804
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805 /* store MAC address */
1806 for (i = 0; i < 6; i ++)
1807 de->dev->dev_addr[i] = ee_data[i + sa_offset];
1808
1809 /* get offset of controller 0 info leaf. ignore 2nd byte. */
1810 ofs = ee_data[SROMC0InfoLeaf];
1811 if (ofs >= (sizeof(ee_data) - sizeof(struct de_srom_info_leaf) - sizeof(struct de_srom_media_block)))
1812 goto bad_srom;
1813
1814 /* get pointer to info leaf */
1815 il = (struct de_srom_info_leaf *) &ee_data[ofs];
1816
1817 /* paranoia checks */
1818 if (il->n_blocks == 0)
1819 goto bad_srom;
1820 if ((sizeof(ee_data) - ofs) <
1821 (sizeof(struct de_srom_info_leaf) + (sizeof(struct de_srom_media_block) * il->n_blocks)))
1822 goto bad_srom;
1823
1824 /* get default media type */
Harvey Harrison445854f2008-05-28 16:51:04 -07001825 switch (get_unaligned(&il->default_media)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826 case 0x0001: de->media_type = DE_MEDIA_BNC; break;
1827 case 0x0002: de->media_type = DE_MEDIA_AUI; break;
1828 case 0x0204: de->media_type = DE_MEDIA_TP_FD; break;
1829 default: de->media_type = DE_MEDIA_TP_AUTO; break;
1830 }
Jeff Garzikf3b197a2006-05-26 21:39:03 -04001831
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832 if (netif_msg_probe(de))
Joe Perchesf639dc72010-01-28 20:59:19 +00001833 pr_info("de%d: SROM leaf offset %u, default media %s\n",
1834 de->board_idx, ofs, media_name[de->media_type]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835
1836 /* init SIA register values to defaults */
1837 for (i = 0; i < DE_MAX_MEDIA; i++) {
1838 de->media[i].type = DE_MEDIA_INVALID;
1839 de->media[i].csr13 = 0xffff;
1840 de->media[i].csr14 = 0xffff;
1841 de->media[i].csr15 = 0xffff;
1842 }
1843
1844 /* parse media blocks to see what medias are supported,
1845 * and if any custom CSR values are provided
1846 */
1847 bufp = ((void *)il) + sizeof(*il);
1848 for (i = 0; i < il->n_blocks; i++) {
1849 struct de_srom_media_block *ib = bufp;
1850 unsigned idx;
1851
1852 /* index based on media type in media block */
1853 switch(ib->opts & MediaBlockMask) {
1854 case 0: /* 10baseT */
1855 de->media_supported |= SUPPORTED_TP | SUPPORTED_10baseT_Half
1856 | SUPPORTED_Autoneg;
1857 idx = DE_MEDIA_TP;
1858 de->media[DE_MEDIA_TP_AUTO].type = DE_MEDIA_TP_AUTO;
1859 break;
1860 case 1: /* BNC */
1861 de->media_supported |= SUPPORTED_BNC;
1862 idx = DE_MEDIA_BNC;
1863 break;
1864 case 2: /* AUI */
1865 de->media_supported |= SUPPORTED_AUI;
1866 idx = DE_MEDIA_AUI;
1867 break;
1868 case 4: /* 10baseT-FD */
1869 de->media_supported |= SUPPORTED_TP | SUPPORTED_10baseT_Full
1870 | SUPPORTED_Autoneg;
1871 idx = DE_MEDIA_TP_FD;
1872 de->media[DE_MEDIA_TP_AUTO].type = DE_MEDIA_TP_AUTO;
1873 break;
1874 default:
1875 goto bad_srom;
1876 }
1877
1878 de->media[idx].type = idx;
1879
1880 if (netif_msg_probe(de))
Joe Perchesf639dc72010-01-28 20:59:19 +00001881 pr_info("de%d: media block #%u: %s",
1882 de->board_idx, i,
1883 media_name[de->media[idx].type]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884
1885 bufp += sizeof (ib->opts);
1886
1887 if (ib->opts & MediaCustomCSRs) {
Harvey Harrison445854f2008-05-28 16:51:04 -07001888 de->media[idx].csr13 = get_unaligned(&ib->csr13);
1889 de->media[idx].csr14 = get_unaligned(&ib->csr14);
1890 de->media[idx].csr15 = get_unaligned(&ib->csr15);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891 bufp += sizeof(ib->csr13) + sizeof(ib->csr14) +
1892 sizeof(ib->csr15);
1893
1894 if (netif_msg_probe(de))
Joe Perchesf639dc72010-01-28 20:59:19 +00001895 pr_cont(" (%x,%x,%x)\n",
1896 de->media[idx].csr13,
1897 de->media[idx].csr14,
1898 de->media[idx].csr15);
Jeff Garzikf3b197a2006-05-26 21:39:03 -04001899
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900 } else if (netif_msg_probe(de))
Joe Perchesf639dc72010-01-28 20:59:19 +00001901 pr_cont("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902
1903 if (bufp > ((void *)&ee_data[DE_EEPROM_SIZE - 3]))
1904 break;
1905 }
1906
1907 de->media_advertise = de->media_supported;
1908
1909fill_defaults:
1910 /* fill in defaults, for cases where custom CSRs not used */
1911 for (i = 0; i < DE_MAX_MEDIA; i++) {
1912 if (de->media[i].csr13 == 0xffff)
1913 de->media[i].csr13 = t21041_csr13[i];
1914 if (de->media[i].csr14 == 0xffff)
1915 de->media[i].csr14 = t21041_csr14[i];
1916 if (de->media[i].csr15 == 0xffff)
1917 de->media[i].csr15 = t21041_csr15[i];
1918 }
1919
Eric Sesterhennc3a9392e2006-10-23 22:20:15 +02001920 de->ee_data = kmemdup(&ee_data[0], DE_EEPROM_SIZE, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921
1922 return;
1923
1924bad_srom:
1925 /* for error cases, it's ok to assume we support all these */
1926 for (i = 0; i < DE_MAX_MEDIA; i++)
1927 de->media[i].type = i;
1928 de->media_supported =
1929 SUPPORTED_10baseT_Half |
1930 SUPPORTED_10baseT_Full |
1931 SUPPORTED_Autoneg |
1932 SUPPORTED_TP |
1933 SUPPORTED_AUI |
1934 SUPPORTED_BNC;
1935 goto fill_defaults;
1936}
1937
Stephen Hemminger90d87432009-01-07 17:59:47 -08001938static const struct net_device_ops de_netdev_ops = {
1939 .ndo_open = de_open,
1940 .ndo_stop = de_close,
1941 .ndo_set_multicast_list = de_set_rx_mode,
1942 .ndo_start_xmit = de_start_xmit,
1943 .ndo_get_stats = de_get_stats,
1944 .ndo_tx_timeout = de_tx_timeout,
1945 .ndo_change_mtu = eth_change_mtu,
1946 .ndo_set_mac_address = eth_mac_addr,
1947 .ndo_validate_addr = eth_validate_addr,
1948};
1949
Helge Deller4a1d2d82006-10-06 12:12:34 -06001950static int __devinit de_init_one (struct pci_dev *pdev,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951 const struct pci_device_id *ent)
1952{
1953 struct net_device *dev;
1954 struct de_private *de;
1955 int rc;
1956 void __iomem *regs;
Jeff Garzikafc70972005-08-31 06:11:16 -04001957 unsigned long pciaddr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958 static int board_idx = -1;
1959
1960 board_idx++;
1961
1962#ifndef MODULE
1963 if (board_idx == 0)
1964 printk("%s", version);
1965#endif
1966
1967 /* allocate a new ethernet device structure, and fill in defaults */
1968 dev = alloc_etherdev(sizeof(struct de_private));
1969 if (!dev)
1970 return -ENOMEM;
1971
Stephen Hemminger90d87432009-01-07 17:59:47 -08001972 dev->netdev_ops = &de_netdev_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001973 SET_NETDEV_DEV(dev, &pdev->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001974 dev->ethtool_ops = &de_ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001975 dev->watchdog_timeo = TX_TIMEOUT;
1976
Wang Chen8f15ea42008-11-12 23:38:36 -08001977 de = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978 de->de21040 = ent->driver_data == 0 ? 1 : 0;
1979 de->pdev = pdev;
1980 de->dev = dev;
1981 de->msg_enable = (debug < 0 ? DE_DEF_MSG_ENABLE : debug);
1982 de->board_idx = board_idx;
1983 spin_lock_init (&de->lock);
1984 init_timer(&de->media_timer);
1985 if (de->de21040)
1986 de->media_timer.function = de21040_media_timer;
1987 else
1988 de->media_timer.function = de21041_media_timer;
1989 de->media_timer.data = (unsigned long) de;
1990
1991 netif_carrier_off(dev);
1992 netif_stop_queue(dev);
1993
1994 /* wake up device, assign resources */
1995 rc = pci_enable_device(pdev);
1996 if (rc)
1997 goto err_out_free;
1998
1999 /* reserve PCI resources to ensure driver atomicity */
2000 rc = pci_request_regions(pdev, DRV_NAME);
2001 if (rc)
2002 goto err_out_disable;
2003
2004 /* check for invalid IRQ value */
2005 if (pdev->irq < 2) {
2006 rc = -EIO;
Joe Perchesf639dc72010-01-28 20:59:19 +00002007 pr_err(PFX "invalid irq (%d) for pci dev %s\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008 pdev->irq, pci_name(pdev));
2009 goto err_out_res;
2010 }
2011
2012 dev->irq = pdev->irq;
2013
2014 /* obtain and check validity of PCI I/O address */
2015 pciaddr = pci_resource_start(pdev, 1);
2016 if (!pciaddr) {
2017 rc = -EIO;
Joe Perchesf639dc72010-01-28 20:59:19 +00002018 pr_err(PFX "no MMIO resource for pci dev %s\n", pci_name(pdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019 goto err_out_res;
2020 }
2021 if (pci_resource_len(pdev, 1) < DE_REGS_SIZE) {
2022 rc = -EIO;
Joe Perchesf639dc72010-01-28 20:59:19 +00002023 pr_err(PFX "MMIO resource (%llx) too small on pci dev %s\n",
2024 (unsigned long long)pci_resource_len(pdev, 1),
2025 pci_name(pdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026 goto err_out_res;
2027 }
2028
2029 /* remap CSR registers */
2030 regs = ioremap_nocache(pciaddr, DE_REGS_SIZE);
2031 if (!regs) {
2032 rc = -EIO;
Joe Perchesf639dc72010-01-28 20:59:19 +00002033 pr_err(PFX "Cannot map PCI MMIO (%llx@%lx) on pci dev %s\n",
2034 (unsigned long long)pci_resource_len(pdev, 1),
2035 pciaddr, pci_name(pdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002036 goto err_out_res;
2037 }
2038 dev->base_addr = (unsigned long) regs;
2039 de->regs = regs;
2040
2041 de_adapter_wake(de);
2042
2043 /* make sure hardware is not running */
2044 rc = de_reset_mac(de);
2045 if (rc) {
Joe Perchesf639dc72010-01-28 20:59:19 +00002046 pr_err(PFX "Cannot reset MAC, pci dev %s\n", pci_name(pdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047 goto err_out_iomap;
2048 }
2049
2050 /* get MAC address, initialize default media type and
2051 * get list of supported media
2052 */
2053 if (de->de21040) {
2054 de21040_get_mac_address(de);
2055 de21040_get_media_info(de);
2056 } else {
2057 de21041_get_srom_info(de);
2058 }
2059
2060 /* register new network interface with kernel */
2061 rc = register_netdev(dev);
2062 if (rc)
2063 goto err_out_iomap;
2064
2065 /* print info about board and interface just registered */
Joe Perchesf639dc72010-01-28 20:59:19 +00002066 dev_info(&dev->dev, "%s at 0x%lx, %pM, IRQ %d\n",
2067 de->de21040 ? "21040" : "21041",
2068 dev->base_addr,
2069 dev->dev_addr,
2070 dev->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071
2072 pci_set_drvdata(pdev, dev);
2073
2074 /* enable busmastering */
2075 pci_set_master(pdev);
2076
2077 /* put adapter to sleep */
2078 de_adapter_sleep(de);
2079
2080 return 0;
2081
2082err_out_iomap:
Jesper Juhlb4558ea2005-10-28 16:53:13 -04002083 kfree(de->ee_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084 iounmap(regs);
2085err_out_res:
2086 pci_release_regions(pdev);
2087err_out_disable:
2088 pci_disable_device(pdev);
2089err_out_free:
2090 free_netdev(dev);
2091 return rc;
2092}
2093
Helge Deller4a1d2d82006-10-06 12:12:34 -06002094static void __devexit de_remove_one (struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095{
2096 struct net_device *dev = pci_get_drvdata(pdev);
Wang Chen8f15ea42008-11-12 23:38:36 -08002097 struct de_private *de = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098
Eric Sesterhenn / snakebyte7e0b58f2006-01-26 22:02:43 +01002099 BUG_ON(!dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100 unregister_netdev(dev);
Jesper Juhlb4558ea2005-10-28 16:53:13 -04002101 kfree(de->ee_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102 iounmap(de->regs);
2103 pci_release_regions(pdev);
2104 pci_disable_device(pdev);
2105 pci_set_drvdata(pdev, NULL);
2106 free_netdev(dev);
2107}
2108
2109#ifdef CONFIG_PM
2110
Pavel Machek05adc3b2005-04-16 15:25:25 -07002111static int de_suspend (struct pci_dev *pdev, pm_message_t state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112{
2113 struct net_device *dev = pci_get_drvdata (pdev);
Wang Chen8f15ea42008-11-12 23:38:36 -08002114 struct de_private *de = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115
2116 rtnl_lock();
2117 if (netif_running (dev)) {
2118 del_timer_sync(&de->media_timer);
2119
2120 disable_irq(dev->irq);
2121 spin_lock_irq(&de->lock);
2122
2123 de_stop_hw(de);
2124 netif_stop_queue(dev);
2125 netif_device_detach(dev);
2126 netif_carrier_off(dev);
2127
2128 spin_unlock_irq(&de->lock);
2129 enable_irq(dev->irq);
Jeff Garzikf3b197a2006-05-26 21:39:03 -04002130
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131 /* Update the error counts. */
2132 __de_get_stats(de);
2133
2134 synchronize_irq(dev->irq);
2135 de_clean_rings(de);
2136
2137 de_adapter_sleep(de);
2138 pci_disable_device(pdev);
2139 } else {
2140 netif_device_detach(dev);
2141 }
2142 rtnl_unlock();
2143 return 0;
2144}
2145
2146static int de_resume (struct pci_dev *pdev)
2147{
2148 struct net_device *dev = pci_get_drvdata (pdev);
Wang Chen8f15ea42008-11-12 23:38:36 -08002149 struct de_private *de = netdev_priv(dev);
Valerie Henson9f486ae2006-09-08 11:15:41 -07002150 int retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151
2152 rtnl_lock();
2153 if (netif_device_present(dev))
2154 goto out;
Valerie Henson9f486ae2006-09-08 11:15:41 -07002155 if (!netif_running(dev))
2156 goto out_attach;
2157 if ((retval = pci_enable_device(pdev))) {
Joe Perchesf639dc72010-01-28 20:59:19 +00002158 dev_err(&dev->dev, "pci_enable_device failed in resume\n");
Valerie Henson9f486ae2006-09-08 11:15:41 -07002159 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160 }
Valerie Henson9f486ae2006-09-08 11:15:41 -07002161 de_init_hw(de);
2162out_attach:
2163 netif_device_attach(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164out:
2165 rtnl_unlock();
2166 return 0;
2167}
2168
2169#endif /* CONFIG_PM */
2170
2171static struct pci_driver de_driver = {
2172 .name = DRV_NAME,
2173 .id_table = de_pci_tbl,
2174 .probe = de_init_one,
Helge Deller4a1d2d82006-10-06 12:12:34 -06002175 .remove = __devexit_p(de_remove_one),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176#ifdef CONFIG_PM
2177 .suspend = de_suspend,
2178 .resume = de_resume,
2179#endif
2180};
2181
2182static int __init de_init (void)
2183{
2184#ifdef MODULE
2185 printk("%s", version);
2186#endif
Jeff Garzik29917622006-08-19 17:48:59 -04002187 return pci_register_driver(&de_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188}
2189
2190static void __exit de_exit (void)
2191{
2192 pci_unregister_driver (&de_driver);
2193}
2194
2195module_init(de_init);
2196module_exit(de_exit);