1 /**************************************************************************
3 * pcnet32.c -- Etherboot device driver for the AMD PCnet32
4 * Written 2003-2003 by Timothy Legge <tlegge@rogers.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 * Portions of this code based on:
21 * pcnet32.c: An AMD PCnet32 ethernet driver for linux:
23 * (C) 1996-1999 Thomas Bogendoerfer
24 * See Linux Driver for full information
26 * The transmit and poll functions were written with reference to:
27 * lance.c - LANCE NIC driver for Etherboot written by Ken Yap
29 * Linux Driver Version 1.27a, 10.02.2002
34 * v1.0 08-06-2003 timlegge Initial port of Linux driver
35 * v1.1 08-23-2003 timlegge Add multicast support
36 * v1.2 01-17-2004 timlegge Initial driver output cleanup
37 * v1.3 03-29-2004 timlegge More driver cleanup
39 * Indent Options: indent -kr -i8
40 ***************************************************************************/
42 /* to get some global routines like printf */
43 #include "etherboot.h"
44 /* to get the interface to the body of the program */
46 /* to get the PCI support functions, if this is a PCI NIC */
48 /* Include the time functions */
51 /* void hex_dump(const char *data, const unsigned int len); */
53 /* Etherboot Specific definations */
54 #define drv_version "v1.3"
55 #define drv_date "03-29-2004"
57 typedef unsigned char u8
;
58 typedef signed char s8
;
59 typedef unsigned short u16
;
60 typedef signed short s16
;
61 typedef unsigned int u32
;
62 typedef signed int s32
;
64 static u32 ioaddr
; /* Globally used for the card's io address */
67 #define dprintf(x) printf x
72 /* Condensed operations for readability. */
73 #define virt_to_le32desc(addr) cpu_to_le32(virt_to_bus(addr))
74 #define le32desc_to_virt(addr) bus_to_virt(le32_to_cpu(addr))
76 /* End Etherboot Specific */
78 int cards_found
/* __initdata */ ;
81 /* FIXME: Remove these they are probably pointless */
86 static unsigned int pcnet32_portlist
[] /*__initdata */ =
87 { 0x300, 0x320, 0x340, 0x360, 0 };
89 static int pcnet32_debug
= 1;
90 static int tx_start
= 1; /* Mapping -- 0:20, 1:64, 2:128, 3:~220 (depends on chip vers) */
91 static int pcnet32vlb
; /* check for VLB cards ? */
93 static struct net_device
*pcnet32_dev
;
95 static int max_interrupt_work
= 80;
96 static int rx_copybreak
= 200;
98 #define PCNET32_PORT_AUI 0x00
99 #define PCNET32_PORT_10BT 0x01
100 #define PCNET32_PORT_GPSI 0x02
101 #define PCNET32_PORT_MII 0x03
103 #define PCNET32_PORT_PORTSEL 0x03
104 #define PCNET32_PORT_ASEL 0x04
105 #define PCNET32_PORT_100 0x40
106 #define PCNET32_PORT_FD 0x80
108 #define PCNET32_DMA_MASK 0xffffffff
111 * table to translate option values from tulip
112 * to internal options
114 static unsigned char options_mapping
[] = {
115 PCNET32_PORT_ASEL
, /* 0 Auto-select */
116 PCNET32_PORT_AUI
, /* 1 BNC/AUI */
117 PCNET32_PORT_AUI
, /* 2 AUI/BNC */
118 PCNET32_PORT_ASEL
, /* 3 not supported */
119 PCNET32_PORT_10BT
| PCNET32_PORT_FD
, /* 4 10baseT-FD */
120 PCNET32_PORT_ASEL
, /* 5 not supported */
121 PCNET32_PORT_ASEL
, /* 6 not supported */
122 PCNET32_PORT_ASEL
, /* 7 not supported */
123 PCNET32_PORT_ASEL
, /* 8 not supported */
124 PCNET32_PORT_MII
, /* 9 MII 10baseT */
125 PCNET32_PORT_MII
| PCNET32_PORT_FD
, /* 10 MII 10baseT-FD */
126 PCNET32_PORT_MII
, /* 11 MII (autosel) */
127 PCNET32_PORT_10BT
, /* 12 10BaseT */
128 PCNET32_PORT_MII
| PCNET32_PORT_100
, /* 13 MII 100BaseTx */
129 PCNET32_PORT_MII
| PCNET32_PORT_100
| PCNET32_PORT_FD
, /* 14 MII 100BaseTx-FD */
130 PCNET32_PORT_ASEL
/* 15 not supported */
133 #define MAX_UNITS 8 /* More are supported, limit only on options */
134 static int options
[MAX_UNITS
];
135 static int full_duplex
[MAX_UNITS
];
138 * Theory of Operation
140 * This driver uses the same software structure as the normal lance
141 * driver. So look for a verbose description in lance.c. The differences
142 * to the normal lance driver is the use of the 32bit mode of PCnet32
143 * and PCnetPCI chips. Because these chips are 32bit chips, there is no
144 * 16MB limitation and we don't need bounce buffers.
150 * Set the number of Tx and Rx buffers, using Log_2(# buffers).
151 * Reasonable default values are 4 Tx buffers, and 16 Rx buffers.
152 * That translates to 2 (4 == 2^^2) and 4 (16 == 2^^4).
154 #ifndef PCNET32_LOG_TX_BUFFERS
155 #define PCNET32_LOG_TX_BUFFERS 1
156 #define PCNET32_LOG_RX_BUFFERS 2
159 #define TX_RING_SIZE (1 << (PCNET32_LOG_TX_BUFFERS))
160 #define TX_RING_MOD_MASK (TX_RING_SIZE - 1)
161 /* FIXME: Fix this to allow multiple tx_ring descriptors */
162 #define TX_RING_LEN_BITS 0x0000 /*PCNET32_LOG_TX_BUFFERS) << 12) */
164 #define RX_RING_SIZE (1 << (PCNET32_LOG_RX_BUFFERS))
165 #define RX_RING_MOD_MASK (RX_RING_SIZE - 1)
166 #define RX_RING_LEN_BITS ((PCNET32_LOG_RX_BUFFERS) << 4)
168 #define PKT_BUF_SZ 1544
170 /* Offsets from base I/O address. */
171 #define PCNET32_WIO_RDP 0x10
172 #define PCNET32_WIO_RAP 0x12
173 #define PCNET32_WIO_RESET 0x14
174 #define PCNET32_WIO_BDP 0x16
176 #define PCNET32_DWIO_RDP 0x10
177 #define PCNET32_DWIO_RAP 0x14
178 #define PCNET32_DWIO_RESET 0x18
179 #define PCNET32_DWIO_BDP 0x1C
181 #define PCNET32_TOTAL_SIZE 0x20
183 /* Buffers for the tx and Rx */
185 /* Create a static buffer of size PKT_BUF_SZ for each
186 TX Descriptor. All descriptors point to a
187 part of this buffer */
188 static unsigned char txb
[PKT_BUF_SZ
* TX_RING_SIZE
];
189 // __attribute__ ((aligned(16)));
191 /* Create a static buffer of size PKT_BUF_SZ for each
192 RX Descriptor All descriptors point to a
193 part of this buffer */
194 static unsigned char rxb
[RX_RING_SIZE
* PKT_BUF_SZ
];
195 // __attribute__ ((aligned(16)));
197 /* The PCNET32 Rx and Tx ring descriptors. */
198 struct pcnet32_rx_head
{
206 struct pcnet32_tx_head
{
214 /* The PCNET32 32-Bit initialization block, described in databook. */
215 struct pcnet32_init_block
{
221 /* Receive and transmit ring base, along with extra bits. */
225 /* PCnet32 access functions */
226 struct pcnet32_access
{
227 u16(*read_csr
) (unsigned long, int);
228 void (*write_csr
) (unsigned long, int, u16
);
229 u16(*read_bcr
) (unsigned long, int);
230 void (*write_bcr
) (unsigned long, int, u16
);
231 u16(*read_rap
) (unsigned long);
232 void (*write_rap
) (unsigned long, u16
);
233 void (*reset
) (unsigned long);
236 /* Define the TX Descriptor */
237 static struct pcnet32_tx_head tx_ring
[TX_RING_SIZE
]
238 __attribute__ ((aligned(16)));
241 /* Define the RX Descriptor */
242 static struct pcnet32_rx_head rx_ring
[RX_RING_SIZE
]
243 __attribute__ ((aligned(16)));
245 /* May need to be moved to mii.h */
249 unsigned int full_duplex
:1; /* is full duplex? */
253 * The first three fields of pcnet32_private are read by the ethernet device
254 * so we allocate the structure should be allocated by pci_alloc_consistent().
257 struct pcnet32_private
{
258 struct pcnet32_init_block init_block
;
259 struct pci_dev
*pci_dev
; /* Pointer to the associated pci device structure */
261 /* The saved address of a sent-in-place packet/buffer, for skfree(). */
262 struct sk_buff
*tx_skbuff
[TX_RING_SIZE
];
263 struct sk_buff
*rx_skbuff
[RX_RING_SIZE
];
264 struct pcnet32_access a
;
265 unsigned int cur_rx
, cur_tx
; /* The next free ring entry */
268 int shared_irq
:1, /* shared irq possible */
269 ltint
:1, /* enable TxDone-intr inhibitor */
270 dxsuflo
:1, /* disable transmit stop on uflo */
271 mii
:1; /* mii port available */
272 struct mii_if_info mii_if
;
273 unsigned char phys
[MII_CNT
];
274 struct net_device
*next
;
278 static struct pcnet32_private
*lp
;
280 static int mdio_read(struct nic
*nic __unused
, int phy_id
, int reg_num
);
282 static void mdio_write(struct nic
*nic __unused
, int phy_id
, int reg_num
,
286 PCI_USES_IO
= 1, PCI_USES_MEM
= 2, PCI_USES_MASTER
= 4,
287 PCI_ADDR0
= 0x10 << 0, PCI_ADDR1
= 0x10 << 1, PCI_ADDR2
=
288 0x10 << 2, PCI_ADDR3
= 0x10 << 3,
292 static u16
pcnet32_wio_read_csr(unsigned long addr
, int index
)
294 outw(index
, addr
+ PCNET32_WIO_RAP
);
295 return inw(addr
+ PCNET32_WIO_RDP
);
298 static void pcnet32_wio_write_csr(unsigned long addr
, int index
, u16 val
)
300 outw(index
, addr
+ PCNET32_WIO_RAP
);
301 outw(val
, addr
+ PCNET32_WIO_RDP
);
304 static u16
pcnet32_wio_read_bcr(unsigned long addr
, int index
)
306 outw(index
, addr
+ PCNET32_WIO_RAP
);
307 return inw(addr
+ PCNET32_WIO_BDP
);
310 static void pcnet32_wio_write_bcr(unsigned long addr
, int index
, u16 val
)
312 outw(index
, addr
+ PCNET32_WIO_RAP
);
313 outw(val
, addr
+ PCNET32_WIO_BDP
);
316 static u16
pcnet32_wio_read_rap(unsigned long addr
)
318 return inw(addr
+ PCNET32_WIO_RAP
);
321 static void pcnet32_wio_write_rap(unsigned long addr
, u16 val
)
323 outw(val
, addr
+ PCNET32_WIO_RAP
);
326 static void pcnet32_wio_reset(unsigned long addr
)
328 inw(addr
+ PCNET32_WIO_RESET
);
331 static int pcnet32_wio_check(unsigned long addr
)
333 outw(88, addr
+ PCNET32_WIO_RAP
);
334 return (inw(addr
+ PCNET32_WIO_RAP
) == 88);
337 static struct pcnet32_access pcnet32_wio
= {
338 read_csr
:pcnet32_wio_read_csr
,
339 write_csr
:pcnet32_wio_write_csr
,
340 read_bcr
:pcnet32_wio_read_bcr
,
341 write_bcr
:pcnet32_wio_write_bcr
,
342 read_rap
:pcnet32_wio_read_rap
,
343 write_rap
:pcnet32_wio_write_rap
,
344 reset
:pcnet32_wio_reset
347 static u16
pcnet32_dwio_read_csr(unsigned long addr
, int index
)
349 outl(index
, addr
+ PCNET32_DWIO_RAP
);
350 return (inl(addr
+ PCNET32_DWIO_RDP
) & 0xffff);
353 static void pcnet32_dwio_write_csr(unsigned long addr
, int index
, u16 val
)
355 outl(index
, addr
+ PCNET32_DWIO_RAP
);
356 outl(val
, addr
+ PCNET32_DWIO_RDP
);
359 static u16
pcnet32_dwio_read_bcr(unsigned long addr
, int index
)
361 outl(index
, addr
+ PCNET32_DWIO_RAP
);
362 return (inl(addr
+ PCNET32_DWIO_BDP
) & 0xffff);
365 static void pcnet32_dwio_write_bcr(unsigned long addr
, int index
, u16 val
)
367 outl(index
, addr
+ PCNET32_DWIO_RAP
);
368 outl(val
, addr
+ PCNET32_DWIO_BDP
);
371 static u16
pcnet32_dwio_read_rap(unsigned long addr
)
373 return (inl(addr
+ PCNET32_DWIO_RAP
) & 0xffff);
376 static void pcnet32_dwio_write_rap(unsigned long addr
, u16 val
)
378 outl(val
, addr
+ PCNET32_DWIO_RAP
);
381 static void pcnet32_dwio_reset(unsigned long addr
)
383 inl(addr
+ PCNET32_DWIO_RESET
);
386 static int pcnet32_dwio_check(unsigned long addr
)
388 outl(88, addr
+ PCNET32_DWIO_RAP
);
389 return ((inl(addr
+ PCNET32_DWIO_RAP
) & 0xffff) == 88);
392 static struct pcnet32_access pcnet32_dwio
= {
393 read_csr
:pcnet32_dwio_read_csr
,
394 write_csr
:pcnet32_dwio_write_csr
,
395 read_bcr
:pcnet32_dwio_read_bcr
,
396 write_bcr
:pcnet32_dwio_write_bcr
,
397 read_rap
:pcnet32_dwio_read_rap
,
398 write_rap
:pcnet32_dwio_write_rap
,
399 reset
:pcnet32_dwio_reset
403 /* Initialize the PCNET32 Rx and Tx rings. */
404 static int pcnet32_init_ring(struct nic
*nic
)
409 lp
->cur_rx
= lp
->cur_tx
= 0;
411 for (i
= 0; i
< RX_RING_SIZE
; i
++) {
412 rx_ring
[i
].base
= (u32
) virt_to_le32desc(&rxb
[i
]);
413 rx_ring
[i
].buf_length
= le16_to_cpu(-PKT_BUF_SZ
);
414 rx_ring
[i
].status
= le16_to_cpu(0x8000);
417 /* The Tx buffer address is filled in as needed, but we do need to clear
418 the upper ownership bit. */
419 for (i
= 0; i
< TX_RING_SIZE
; i
++) {
421 tx_ring
[i
].status
= 0;
425 lp
->init_block
.tlen_rlen
=
426 le16_to_cpu(TX_RING_LEN_BITS
| RX_RING_LEN_BITS
);
427 for (i
= 0; i
< 6; i
++)
428 lp
->init_block
.phys_addr
[i
] = nic
->node_addr
[i
];
429 lp
->init_block
.rx_ring
= (u32
) virt_to_le32desc(&rx_ring
[0]);
430 lp
->init_block
.tx_ring
= (u32
) virt_to_le32desc(&tx_ring
[0]);
434 /**************************************************************************
435 RESET - Reset adapter
436 ***************************************************************************/
437 static void pcnet32_reset(struct nic
*nic
)
439 /* put the card in its initial state */
443 /* Reset the PCNET32 */
446 /* switch pcnet32 to 32bit mode */
447 lp
->a
.write_bcr(ioaddr
, 20, 2);
449 /* set/reset autoselect bit */
450 val
= lp
->a
.read_bcr(ioaddr
, 2) & ~2;
451 if (lp
->options
& PCNET32_PORT_ASEL
)
453 lp
->a
.write_bcr(ioaddr
, 2, val
);
454 /* handle full duplex setting */
455 if (lp
->full_duplex
) {
456 val
= lp
->a
.read_bcr(ioaddr
, 9) & ~3;
457 if (lp
->options
& PCNET32_PORT_FD
) {
460 (PCNET32_PORT_FD
| PCNET32_PORT_AUI
))
462 } else if (lp
->options
& PCNET32_PORT_ASEL
) {
463 /* workaround of xSeries250, turn on for 79C975 only */
466 88) | (lp
->a
.read_csr(ioaddr
,
472 lp
->a
.write_bcr(ioaddr
, 9, val
);
475 /* set/reset GPSI bit in test register */
476 val
= lp
->a
.read_csr(ioaddr
, 124) & ~0x10;
477 if ((lp
->options
& PCNET32_PORT_PORTSEL
) == PCNET32_PORT_GPSI
)
479 lp
->a
.write_csr(ioaddr
, 124, val
);
481 if (lp
->mii
&& !(lp
->options
& PCNET32_PORT_ASEL
)) {
482 val
= lp
->a
.read_bcr(ioaddr
, 32) & ~0x38; /* disable Auto Negotiation, set 10Mbps, HD */
483 if (lp
->options
& PCNET32_PORT_FD
)
485 if (lp
->options
& PCNET32_PORT_100
)
487 lp
->a
.write_bcr(ioaddr
, 32, val
);
489 if (lp
->options
& PCNET32_PORT_ASEL
) { /* enable auto negotiate, setup, disable fd */
490 val
= lp
->a
.read_bcr(ioaddr
, 32) & ~0x98;
492 lp
->a
.write_bcr(ioaddr
, 32, val
);
497 if (lp
->dxsuflo
) { /* Disable transmit stop on underflow */
498 val
= lp
->a
.read_csr(ioaddr
, 3);
500 lp
->a
.write_csr(ioaddr
, 3, val
);
504 if (lp
->ltint
) { /* Enable TxDone-intr inhibitor */
505 val
= lp
->a
.read_csr(ioaddr
, 5);
507 lp
->a
.write_csr(ioaddr
, 5, val
);
509 lp
->init_block
.mode
=
510 le16_to_cpu((lp
->options
& PCNET32_PORT_PORTSEL
) << 7);
511 lp
->init_block
.filter
[0] = 0xffffffff;
512 lp
->init_block
.filter
[1] = 0xffffffff;
514 pcnet32_init_ring(nic
);
517 /* Re-initialize the PCNET32, and start it when done. */
518 lp
->a
.write_csr(ioaddr
, 1,
519 (virt_to_bus(&lp
->init_block
)) & 0xffff);
520 lp
->a
.write_csr(ioaddr
, 2, (virt_to_bus(&lp
->init_block
)) >> 16);
521 lp
->a
.write_csr(ioaddr
, 4, 0x0915);
522 lp
->a
.write_csr(ioaddr
, 0, 0x0001);
527 if (lp
->a
.read_csr(ioaddr
, 0) & 0x0100)
530 * We used to clear the InitDone bit, 0x0100, here but Mark Stockton
531 * reports that doing so triggers a bug in the '974.
533 lp
->a
.write_csr(ioaddr
, 0, 0x0042);
535 dprintf(("pcnet32 open, csr0 %hX.\n", lp
->a
.read_csr(ioaddr
, 0)));
539 /**************************************************************************
540 POLL - Wait for a frame
541 ***************************************************************************/
542 static int pcnet32_poll(struct nic
*nic __unused
, int retrieve
)
544 /* return true if there's an ethernet packet ready to read */
545 /* nic->packet should contain data on return */
546 /* nic->packetlen should contain length of data */
551 entry
= lp
->cur_rx
& RX_RING_MOD_MASK
;
552 status
= ((short) le16_to_cpu(rx_ring
[entry
].status
) >> 8);
557 if ( ! retrieve
) return 1;
559 if (status
== 0x03) {
561 (le32_to_cpu(rx_ring
[entry
].msg_length
) & 0xfff) - 4;
562 memcpy(nic
->packet
, &rxb
[entry
], nic
->packetlen
);
564 /* Andrew Boyd of QNX reports that some revs of the 79C765
565 * clear the buffer length */
566 rx_ring
[entry
].buf_length
= le16_to_cpu(-PKT_BUF_SZ
);
567 rx_ring
[entry
].status
|= le16_to_cpu(0x8000); /* prime for next receive */
568 /* Switch to the next Rx ring buffer */
578 /**************************************************************************
579 TRANSMIT - Transmit a frame
580 ***************************************************************************/
581 static void pcnet32_transmit(struct nic
*nic __unused
, const char *d
, /* Destination */
582 unsigned int t
, /* Type */
583 unsigned int s
, /* size */
586 /* send the packet to destination */
591 int entry
= 0; /*lp->cur_tx & TX_RING_MOD_MASK; */
594 /* point to the current txb incase multiple tx_rings are used */
595 ptxb
= txb
+ (lp
->cur_tx
* PKT_BUF_SZ
);
597 /* copy the packet to ring buffer */
598 memcpy(ptxb
, d
, ETH_ALEN
); /* dst */
599 memcpy(ptxb
+ ETH_ALEN
, nic
->node_addr
, ETH_ALEN
); /* src */
600 nstype
= htons((u16
) t
); /* type */
601 memcpy(ptxb
+ 2 * ETH_ALEN
, (u8
*) & nstype
, 2); /* type */
602 memcpy(ptxb
+ ETH_HLEN
, p
, s
);
605 while (s
< ETH_ZLEN
) /* pad to min length */
608 tx_ring
[entry
].length
= le16_to_cpu(-s
);
609 tx_ring
[entry
].misc
= 0x00000000;
610 tx_ring
[entry
].base
= (u32
) virt_to_le32desc(ptxb
);
612 /* we set the top byte as the very last thing */
613 tx_ring
[entry
].status
= le16_to_cpu(status
);
616 /* Trigger an immediate send poll */
617 lp
->a
.write_csr(ioaddr
, 0, 0x0048);
619 /* wait for transmit complete */
620 lp
->cur_tx
= 0; /* (lp->cur_tx + 1); */
621 time
= currticks() + TICKS_PER_SEC
; /* wait one second */
622 while (currticks() < time
&&
623 ((short) le16_to_cpu(tx_ring
[entry
].status
) < 0));
625 if ((short) le16_to_cpu(tx_ring
[entry
].status
) < 0)
626 printf("PCNET32 timed out on transmit\n");
628 /* Stop pointing at the current txb
629 * otherwise the card continues to send the packet */
630 tx_ring
[entry
].base
= 0;
634 /**************************************************************************
635 DISABLE - Turn off ethernet interface
636 ***************************************************************************/
637 static void pcnet32_disable(struct dev
*dev __unused
)
639 /* Stop the PCNET32 here -- it ocassionally polls memory if we don't */
640 lp
->a
.write_csr(ioaddr
, 0, 0x0004);
643 * Switch back to 16-bit mode to avoid problesm with dumb
644 * DOS packet driver after a warm reboot
646 lp
->a
.write_bcr(ioaddr
, 20, 4);
649 /**************************************************************************
650 IRQ - Enable, Disable, or Force interrupts
651 ***************************************************************************/
652 static void pcnet32_irq(struct nic
*nic __unused
, irq_action_t action __unused
)
664 /**************************************************************************
665 PROBE - Look for an adapter, this routine's visible to the outside
666 You should omit the last argument struct pci_device * for a non-PCI NIC
667 ***************************************************************************/
668 static int pcnet32_probe(struct dev
*dev
, struct pci_device
*pci
)
670 struct nic
*nic
= (struct nic
*) dev
;
672 int fdx
, mii
, fset
, dxsuflo
, ltint
;
675 struct pcnet32_access
*a
= NULL
;
679 if (pci
->ioaddr
== 0)
682 /* BASE is used throughout to address the card */
683 ioaddr
= pci
->ioaddr
;
684 printf("pcnet32.c: Found %s, Vendor=0x%hX Device=0x%hX\n",
685 pci
->name
, pci
->vendor
, pci
->dev_id
);
688 nic
->ioaddr
= pci
->ioaddr
& ~3;
691 pcnet32_wio_reset(ioaddr
);
693 /* NOTE: 16-bit check is first, otherwise some older PCnet chips fail */
694 if (pcnet32_wio_read_csr(ioaddr
, 0) == 4
695 && pcnet32_wio_check(ioaddr
)) {
698 pcnet32_dwio_reset(ioaddr
);
699 if (pcnet32_dwio_read_csr(ioaddr
, 0) == 4
700 && pcnet32_dwio_check(ioaddr
)) {
707 a
->read_csr(ioaddr
, 88) | (a
->read_csr(ioaddr
, 89) << 16);
709 dprintf(("PCnet chip version is %0xhX\n", chip_version
));
710 if ((chip_version
& 0xfff) != 0x003)
713 /* initialize variables */
714 fdx
= mii
= fset
= dxsuflo
= ltint
= 0;
715 chip_version
= (chip_version
>> 12) & 0xffff;
717 switch (chip_version
) {
719 chipname
= "PCnet/PCI 79C970"; /* PCI */
723 chipname
= "PCnet/PCI 79C970"; /* 970 gives the wrong chip id back */
725 chipname
= "PCnet/32 79C965"; /* 486/VL bus */
728 chipname
= "PCnet/PCI II 79C970A"; /* PCI */
732 chipname
= "PCnet/FAST 79C971"; /* PCI */
739 chipname
= "PCnet/FAST+ 79C972"; /* PCI */
745 chipname
= "PCnet/FAST III 79C973"; /* PCI */
750 chipname
= "PCnet/Home 79C978"; /* PCI */
753 * This is based on specs published at www.amd.com. This section
754 * assumes that a card with a 79C978 wants to go into 1Mb HomePNA
755 * mode. The 79C978 can also go into standard ethernet, and there
756 * probably should be some sort of module option to select the
757 * mode by which the card should operate
759 /* switch to home wiring mode */
760 media
= a
->read_bcr(ioaddr
, 49);
762 printf("media reset to %#x.\n", media
);
763 a
->write_bcr(ioaddr
, 49, media
);
766 chipname
= "PCnet/FAST III 79C975"; /* PCI */
771 printf("PCnet version %#x, no PCnet32 chip.\n",
777 * On selected chips turn on the BCR18:NOUFLO bit. This stops transmit
778 * starting until the packet is loaded. Strike one for reliability, lose
779 * one for latency - although on PCI this isnt a big loss. Older chips
780 * have FIFO's smaller than a packet, so you can't do this.
784 a
->write_bcr(ioaddr
, 18,
785 (a
->read_bcr(ioaddr
, 18) | 0x0800));
786 a
->write_csr(ioaddr
, 80,
787 (a
->read_csr(ioaddr
, 80) & 0x0C00) | 0x0c00);
792 dprintf(("%s at %hX,", chipname
, ioaddr
));
794 /* read PROM address */
795 for (i
= 0; i
< 6; i
++)
796 promaddr
[i
] = inb(ioaddr
+ i
);
798 /* Update the nic structure with the MAC Address */
799 for (i
= 0; i
< ETH_ALEN
; i
++) {
800 nic
->node_addr
[i
] = promaddr
[i
];
802 /* Print out some hardware info */
803 printf("%s: %! at ioaddr %hX, ", pci
->name
, nic
->node_addr
,
806 /* Set to pci bus master */
807 adjust_pci_device(pci
);
809 /* point to private storage */
813 if (((chip_version
+ 1) & 0xfffe) == 0x2624) { /* Version 0x2623 or 0x2624 */
814 i
= a
->read_csr(ioaddr
, 80) & 0x0C00; /* Check tx_start_pt */
815 dprintf((" tx_start_pt(0x%hX):", i
));
818 dprintf((" 20 bytes,"));
821 dprintf((" 64 bytes,"));
824 dprintf((" 128 bytes,"));
827 dprintf(("~220 bytes,"));
830 i
= a
->read_bcr(ioaddr
, 18); /* Check Burst/Bus control */
831 dprintf((" BCR18(%hX):", i
& 0xffff));
833 dprintf(("BurstWrEn "));
835 dprintf(("BurstRdEn "));
837 dprintf(("DWordIO "));
839 dprintf(("NoUFlow "));
840 i
= a
->read_bcr(ioaddr
, 25);
841 dprintf((" SRAMSIZE=0x%hX,", i
<< 8));
842 i
= a
->read_bcr(ioaddr
, 26);
843 dprintf((" SRAM_BND=0x%hX,", i
<< 8));
844 i
= a
->read_bcr(ioaddr
, 27);
846 dprintf(("LowLatRx"));
850 lp
->shared_irq
= shared
;
851 lp
->full_duplex
= fdx
;
852 lp
->dxsuflo
= dxsuflo
;
855 /* FIXME: Fix Options for only one card */
856 if ((cards_found
>= MAX_UNITS
)
857 || ((unsigned int) options
[cards_found
] > sizeof(options_mapping
)))
858 lp
->options
= PCNET32_PORT_ASEL
;
860 lp
->options
= options_mapping
[options
[cards_found
]];
862 if (fdx
&& !(lp
->options
& PCNET32_PORT_ASEL
) &&
863 ((cards_found
>= MAX_UNITS
) || full_duplex
[cards_found
]))
864 lp
->options
|= PCNET32_PORT_FD
;
867 printf("No access methods\n");
872 /* detect special T1/E1 WAN card by checking for MAC address */
873 if (nic
->node_addr
[0] == 0x00 && nic
->node_addr
[1] == 0xe0
874 && nic
->node_addr
[2] == 0x75)
875 lp
->options
= PCNET32_PORT_FD
| PCNET32_PORT_GPSI
;
877 lp
->init_block
.mode
= le16_to_cpu(0x0003); /* Disable Rx and Tx. */
878 lp
->init_block
.tlen_rlen
=
879 le16_to_cpu(TX_RING_LEN_BITS
| RX_RING_LEN_BITS
);
880 for (i
= 0; i
< 6; i
++)
881 lp
->init_block
.phys_addr
[i
] = nic
->node_addr
[i
];
882 lp
->init_block
.filter
[0] = 0xffffffff;
883 lp
->init_block
.filter
[1] = 0xffffffff;
884 lp
->init_block
.rx_ring
= virt_to_bus(&rx_ring
);
885 lp
->init_block
.tx_ring
= virt_to_bus(&tx_ring
);
887 /* switch pcnet32 to 32bit mode */
888 a
->write_bcr(ioaddr
, 20, 2);
891 a
->write_csr(ioaddr
, 1, (virt_to_bus(&lp
->init_block
)) & 0xffff);
892 a
->write_csr(ioaddr
, 2, (virt_to_bus(&lp
->init_block
)) >> 16);
895 * To auto-IRQ we enable the initialization-done and DMA error
896 * interrupts. For ISA boards we get a DMA error, but VLB and PCI
899 /* Trigger an initialization just for the interrupt. */
901 a
->write_csr(ioaddr
, 0, 0x41);
906 /* point to NIC specific routines */
910 int phy
, phy_idx
= 0;
912 lp
->phys
[0] = 1; /* Default Setting */
913 for (phy
= 1; phy
< 32 && phy_idx
< MII_CNT
; phy
++) {
914 int mii_status
= mdio_read(nic
, phy
, MII_BMSR
);
915 if (mii_status
!= 0xffff && mii_status
!= 0x0000) {
916 lp
->phys
[phy_idx
++] = phy
;
917 lp
->mii_if
.advertising
=
918 mdio_read(nic
, phy
, MII_ADVERTISE
);
919 if ((mii_status
& 0x0040) == 0) {
921 dprintf (("MII PHY found at address %d, status "
922 "%hX advertising %hX\n", phy
, mii_status
,
923 lp
->mii_if
.advertising
));
928 printf("No MII transceiver found!\n");
929 lp
->mii_if
.phy_id
= lp
->phys
[0];
931 lp
->mii_if
.advertising
=
932 mdio_read(nic
, lp
->phys
[0], MII_ADVERTISE
);
934 mii_lpa
= mdio_read(nic
, lp
->phys
[0], MII_LPA
);
935 lp
->mii_if
.advertising
&= mii_lpa
;
936 if (lp
->mii_if
.advertising
& ADVERTISE_100FULL
)
937 printf("100Mbps Full-Duplex\n");
938 else if (lp
->mii_if
.advertising
& ADVERTISE_100HALF
)
939 printf("100Mbps Half-Duplex\n");
940 else if (lp
->mii_if
.advertising
& ADVERTISE_10FULL
)
941 printf("10Mbps Full-Duplex\n");
942 else if (lp
->mii_if
.advertising
& ADVERTISE_10HALF
)
943 printf("10Mbps Half-Duplex\n");
948 nic
->poll
= pcnet32_poll
;
949 nic
->transmit
= pcnet32_transmit
;
950 dev
->disable
= pcnet32_disable
;
951 nic
->irq
= pcnet32_irq
;
955 static int mdio_read(struct nic
*nic __unused
, int phy_id
, int reg_num
)
963 phyaddr
= lp
->a
.read_bcr(ioaddr
, 33);
965 lp
->a
.write_bcr(ioaddr
, 33,
966 ((phy_id
& 0x1f) << 5) | (reg_num
& 0x1f));
967 val_out
= lp
->a
.read_bcr(ioaddr
, 34);
968 lp
->a
.write_bcr(ioaddr
, 33, phyaddr
);
974 static void mdio_write(struct nic
*nic __unused
, int phy_id
, int reg_num
,
982 phyaddr
= lp
->a
.read_bcr(ioaddr
, 33);
984 lp
->a
.write_bcr(ioaddr
, 33,
985 ((phy_id
& 0x1f) << 5) | (reg_num
& 0x1f));
986 lp
->a
.write_bcr(ioaddr
, 34, val
);
987 lp
->a
.write_bcr(ioaddr
, 33, phyaddr
);
991 static struct pci_id pcnet32_nics
[] = {
992 PCI_ROM(0x1022, 0x2000, "lancepci", "AMD Lance/PCI"),
993 PCI_ROM(0x1022, 0x2625, "pcnetfastiii", "AMD Lance/PCI PCNet/32"),
994 PCI_ROM(0x1022, 0x2001, "amdhomepna", "AMD Lance/HomePNA"),
997 struct pci_driver pcnet32_driver
= {
999 .name
= "PCNET32/PCI",
1000 .probe
= pcnet32_probe
,
1001 .ids
= pcnet32_nics
,
1002 .id_count
= sizeof(pcnet32_nics
) / sizeof(pcnet32_nics
[0]),