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 #include "etherboot.h"
45 #include <gpxe/ethernet.h>
49 /* void hex_dump(const char *data, const unsigned int len); */
51 /* Etherboot Specific definations */
52 #define drv_version "v1.3"
53 #define drv_date "03-29-2004"
55 static u32 ioaddr
; /* Globally used for the card's io address */
56 static struct nic_operations pcnet32_operations
;
59 #define dprintf(x) printf x
64 /* Condensed operations for readability. */
65 #define virt_to_le32desc(addr) cpu_to_le32(virt_to_bus(addr))
66 #define le32desc_to_virt(addr) bus_to_virt(le32_to_cpu(addr))
68 /* End Etherboot Specific */
70 int cards_found
/* __initdata */ ;
73 /* FIXME: Remove these they are probably pointless */
78 static unsigned int pcnet32_portlist
[] /*__initdata */ =
79 { 0x300, 0x320, 0x340, 0x360, 0 };
81 static int pcnet32_debug
= 1;
82 static int tx_start
= 1; /* Mapping -- 0:20, 1:64, 2:128, 3:~220 (depends on chip vers) */
83 static int pcnet32vlb
; /* check for VLB cards ? */
85 static struct net_device
*pcnet32_dev
;
87 static int max_interrupt_work
= 80;
88 static int rx_copybreak
= 200;
90 #define PCNET32_PORT_AUI 0x00
91 #define PCNET32_PORT_10BT 0x01
92 #define PCNET32_PORT_GPSI 0x02
93 #define PCNET32_PORT_MII 0x03
95 #define PCNET32_PORT_PORTSEL 0x03
96 #define PCNET32_PORT_ASEL 0x04
97 #define PCNET32_PORT_100 0x40
98 #define PCNET32_PORT_FD 0x80
100 #define PCNET32_DMA_MASK 0xffffffff
103 * table to translate option values from tulip
104 * to internal options
106 static unsigned char options_mapping
[] = {
107 PCNET32_PORT_ASEL
, /* 0 Auto-select */
108 PCNET32_PORT_AUI
, /* 1 BNC/AUI */
109 PCNET32_PORT_AUI
, /* 2 AUI/BNC */
110 PCNET32_PORT_ASEL
, /* 3 not supported */
111 PCNET32_PORT_10BT
| PCNET32_PORT_FD
, /* 4 10baseT-FD */
112 PCNET32_PORT_ASEL
, /* 5 not supported */
113 PCNET32_PORT_ASEL
, /* 6 not supported */
114 PCNET32_PORT_ASEL
, /* 7 not supported */
115 PCNET32_PORT_ASEL
, /* 8 not supported */
116 PCNET32_PORT_MII
, /* 9 MII 10baseT */
117 PCNET32_PORT_MII
| PCNET32_PORT_FD
, /* 10 MII 10baseT-FD */
118 PCNET32_PORT_MII
, /* 11 MII (autosel) */
119 PCNET32_PORT_10BT
, /* 12 10BaseT */
120 PCNET32_PORT_MII
| PCNET32_PORT_100
, /* 13 MII 100BaseTx */
121 PCNET32_PORT_MII
| PCNET32_PORT_100
| PCNET32_PORT_FD
, /* 14 MII 100BaseTx-FD */
122 PCNET32_PORT_ASEL
/* 15 not supported */
125 #define MAX_UNITS 8 /* More are supported, limit only on options */
126 static int options
[MAX_UNITS
];
127 static int full_duplex
[MAX_UNITS
];
130 * Theory of Operation
132 * This driver uses the same software structure as the normal lance
133 * driver. So look for a verbose description in lance.c. The differences
134 * to the normal lance driver is the use of the 32bit mode of PCnet32
135 * and PCnetPCI chips. Because these chips are 32bit chips, there is no
136 * 16MB limitation and we don't need bounce buffers.
142 * Set the number of Tx and Rx buffers, using Log_2(# buffers).
143 * Reasonable default values are 4 Tx buffers, and 16 Rx buffers.
144 * That translates to 2 (4 == 2^^2) and 4 (16 == 2^^4).
146 #ifndef PCNET32_LOG_TX_BUFFERS
147 #define PCNET32_LOG_TX_BUFFERS 1
148 #define PCNET32_LOG_RX_BUFFERS 2
151 #define TX_RING_SIZE (1 << (PCNET32_LOG_TX_BUFFERS))
152 #define TX_RING_MOD_MASK (TX_RING_SIZE - 1)
153 /* FIXME: Fix this to allow multiple tx_ring descriptors */
154 #define TX_RING_LEN_BITS 0x0000 /*PCNET32_LOG_TX_BUFFERS) << 12) */
156 #define RX_RING_SIZE (1 << (PCNET32_LOG_RX_BUFFERS))
157 #define RX_RING_MOD_MASK (RX_RING_SIZE - 1)
158 #define RX_RING_LEN_BITS ((PCNET32_LOG_RX_BUFFERS) << 4)
160 #define PKT_BUF_SZ 1544
162 /* Offsets from base I/O address. */
163 #define PCNET32_WIO_RDP 0x10
164 #define PCNET32_WIO_RAP 0x12
165 #define PCNET32_WIO_RESET 0x14
166 #define PCNET32_WIO_BDP 0x16
168 #define PCNET32_DWIO_RDP 0x10
169 #define PCNET32_DWIO_RAP 0x14
170 #define PCNET32_DWIO_RESET 0x18
171 #define PCNET32_DWIO_BDP 0x1C
173 #define PCNET32_TOTAL_SIZE 0x20
175 /* The PCNET32 Rx and Tx ring descriptors. */
176 struct pcnet32_rx_head
{
184 struct pcnet32_tx_head
{
192 /* The PCNET32 32-Bit initialization block, described in databook. */
193 struct pcnet32_init_block
{
199 /* Receive and transmit ring base, along with extra bits. */
203 /* PCnet32 access functions */
204 struct pcnet32_access
{
205 u16(*read_csr
) (unsigned long, int);
206 void (*write_csr
) (unsigned long, int, u16
);
207 u16(*read_bcr
) (unsigned long, int);
208 void (*write_bcr
) (unsigned long, int, u16
);
209 u16(*read_rap
) (unsigned long);
210 void (*write_rap
) (unsigned long, u16
);
211 void (*reset
) (unsigned long);
214 /* Define the TX and RX Descriptors and Rings */
216 struct pcnet32_tx_head tx_ring
[TX_RING_SIZE
]
217 __attribute__ ((aligned(16)));
218 struct pcnet32_rx_head rx_ring
[RX_RING_SIZE
]
219 __attribute__ ((aligned(16)));
220 unsigned char txb
[PKT_BUF_SZ
* TX_RING_SIZE
];
221 unsigned char rxb
[RX_RING_SIZE
* PKT_BUF_SZ
];
222 } pcnet32_bufs __shared
;
224 /* May need to be moved to mii.h */
228 unsigned int full_duplex
:1; /* is full duplex? */
232 * The first three fields of pcnet32_private are read by the ethernet device
233 * so we allocate the structure should be allocated by pci_alloc_consistent().
236 struct pcnet32_private
{
237 struct pcnet32_init_block init_block
;
238 struct pci_dev
*pci_dev
; /* Pointer to the associated pci device structure */
240 /* The saved address of a sent-in-place packet/buffer, for skfree(). */
241 struct sk_buff
*tx_skbuff
[TX_RING_SIZE
];
242 struct sk_buff
*rx_skbuff
[RX_RING_SIZE
];
243 struct pcnet32_access a
;
244 unsigned int cur_rx
, cur_tx
; /* The next free ring entry */
247 int shared_irq
:1, /* shared irq possible */
248 ltint
:1, /* enable TxDone-intr inhibitor */
249 dxsuflo
:1, /* disable transmit stop on uflo */
250 mii
:1; /* mii port available */
251 struct mii_if_info mii_if
;
252 unsigned char phys
[MII_CNT
];
253 struct net_device
*next
;
257 static struct pcnet32_private
*lp
;
259 static int mdio_read(struct nic
*nic __unused
, int phy_id
, int reg_num
);
261 static void mdio_write(struct nic
*nic __unused
, int phy_id
, int reg_num
,
265 PCI_USES_IO
= 1, PCI_USES_MEM
= 2, PCI_USES_MASTER
= 4,
266 PCI_ADDR0
= 0x10 << 0, PCI_ADDR1
= 0x10 << 1, PCI_ADDR2
=
267 0x10 << 2, PCI_ADDR3
= 0x10 << 3,
271 static u16
pcnet32_wio_read_csr(unsigned long addr
, int index
)
273 outw(index
, addr
+ PCNET32_WIO_RAP
);
274 return inw(addr
+ PCNET32_WIO_RDP
);
277 static void pcnet32_wio_write_csr(unsigned long addr
, int index
, u16 val
)
279 outw(index
, addr
+ PCNET32_WIO_RAP
);
280 outw(val
, addr
+ PCNET32_WIO_RDP
);
283 static u16
pcnet32_wio_read_bcr(unsigned long addr
, int index
)
285 outw(index
, addr
+ PCNET32_WIO_RAP
);
286 return inw(addr
+ PCNET32_WIO_BDP
);
289 static void pcnet32_wio_write_bcr(unsigned long addr
, int index
, u16 val
)
291 outw(index
, addr
+ PCNET32_WIO_RAP
);
292 outw(val
, addr
+ PCNET32_WIO_BDP
);
295 static u16
pcnet32_wio_read_rap(unsigned long addr
)
297 return inw(addr
+ PCNET32_WIO_RAP
);
300 static void pcnet32_wio_write_rap(unsigned long addr
, u16 val
)
302 outw(val
, addr
+ PCNET32_WIO_RAP
);
305 static void pcnet32_wio_reset(unsigned long addr
)
307 inw(addr
+ PCNET32_WIO_RESET
);
310 static int pcnet32_wio_check(unsigned long addr
)
312 outw(88, addr
+ PCNET32_WIO_RAP
);
313 return (inw(addr
+ PCNET32_WIO_RAP
) == 88);
316 static struct pcnet32_access pcnet32_wio
= {
317 read_csr
:pcnet32_wio_read_csr
,
318 write_csr
:pcnet32_wio_write_csr
,
319 read_bcr
:pcnet32_wio_read_bcr
,
320 write_bcr
:pcnet32_wio_write_bcr
,
321 read_rap
:pcnet32_wio_read_rap
,
322 write_rap
:pcnet32_wio_write_rap
,
323 reset
:pcnet32_wio_reset
326 static u16
pcnet32_dwio_read_csr(unsigned long addr
, int index
)
328 outl(index
, addr
+ PCNET32_DWIO_RAP
);
329 return (inl(addr
+ PCNET32_DWIO_RDP
) & 0xffff);
332 static void pcnet32_dwio_write_csr(unsigned long addr
, int index
, u16 val
)
334 outl(index
, addr
+ PCNET32_DWIO_RAP
);
335 outl(val
, addr
+ PCNET32_DWIO_RDP
);
338 static u16
pcnet32_dwio_read_bcr(unsigned long addr
, int index
)
340 outl(index
, addr
+ PCNET32_DWIO_RAP
);
341 return (inl(addr
+ PCNET32_DWIO_BDP
) & 0xffff);
344 static void pcnet32_dwio_write_bcr(unsigned long addr
, int index
, u16 val
)
346 outl(index
, addr
+ PCNET32_DWIO_RAP
);
347 outl(val
, addr
+ PCNET32_DWIO_BDP
);
350 static u16
pcnet32_dwio_read_rap(unsigned long addr
)
352 return (inl(addr
+ PCNET32_DWIO_RAP
) & 0xffff);
355 static void pcnet32_dwio_write_rap(unsigned long addr
, u16 val
)
357 outl(val
, addr
+ PCNET32_DWIO_RAP
);
360 static void pcnet32_dwio_reset(unsigned long addr
)
362 inl(addr
+ PCNET32_DWIO_RESET
);
365 static int pcnet32_dwio_check(unsigned long addr
)
367 outl(88, addr
+ PCNET32_DWIO_RAP
);
368 return ((inl(addr
+ PCNET32_DWIO_RAP
) & 0xffff) == 88);
371 static struct pcnet32_access pcnet32_dwio
= {
372 read_csr
:pcnet32_dwio_read_csr
,
373 write_csr
:pcnet32_dwio_write_csr
,
374 read_bcr
:pcnet32_dwio_read_bcr
,
375 write_bcr
:pcnet32_dwio_write_bcr
,
376 read_rap
:pcnet32_dwio_read_rap
,
377 write_rap
:pcnet32_dwio_write_rap
,
378 reset
:pcnet32_dwio_reset
382 /* Initialize the PCNET32 Rx and Tx rings. */
383 static int pcnet32_init_ring(struct nic
*nic
)
388 lp
->cur_rx
= lp
->cur_tx
= 0;
390 for (i
= 0; i
< RX_RING_SIZE
; i
++) {
391 pcnet32_bufs
.rx_ring
[i
].base
=
392 virt_to_le32desc(&pcnet32_bufs
.rxb
[i
]);
393 pcnet32_bufs
.rx_ring
[i
].buf_length
= le16_to_cpu(-PKT_BUF_SZ
);
394 pcnet32_bufs
.rx_ring
[i
].status
= le16_to_cpu(0x8000);
397 /* The Tx buffer address is filled in as needed, but we do need to clear
398 the upper ownership bit. */
399 for (i
= 0; i
< TX_RING_SIZE
; i
++) {
400 pcnet32_bufs
.tx_ring
[i
].base
= 0;
401 pcnet32_bufs
.tx_ring
[i
].status
= 0;
405 lp
->init_block
.tlen_rlen
=
406 le16_to_cpu(TX_RING_LEN_BITS
| RX_RING_LEN_BITS
);
407 for (i
= 0; i
< 6; i
++)
408 lp
->init_block
.phys_addr
[i
] = nic
->node_addr
[i
];
409 lp
->init_block
.rx_ring
= virt_to_le32desc(&pcnet32_bufs
.rx_ring
[0]);
410 lp
->init_block
.tx_ring
= virt_to_le32desc(&pcnet32_bufs
.tx_ring
[0]);
414 /**************************************************************************
415 RESET - Reset adapter
416 ***************************************************************************/
417 static void pcnet32_reset(struct nic
*nic
)
419 /* put the card in its initial state */
423 /* Reset the PCNET32 */
426 /* switch pcnet32 to 32bit mode */
427 lp
->a
.write_bcr(ioaddr
, 20, 2);
429 /* set/reset autoselect bit */
430 val
= lp
->a
.read_bcr(ioaddr
, 2) & ~2;
431 if (lp
->options
& PCNET32_PORT_ASEL
)
433 lp
->a
.write_bcr(ioaddr
, 2, val
);
435 /* handle full duplex setting */
436 if (lp
->full_duplex
) {
437 val
= lp
->a
.read_bcr(ioaddr
, 9) & ~3;
438 if (lp
->options
& PCNET32_PORT_FD
) {
441 (PCNET32_PORT_FD
| PCNET32_PORT_AUI
))
443 } else if (lp
->options
& PCNET32_PORT_ASEL
) {
444 /* workaround of xSeries250, turn on for 79C975 only */
447 88) | (lp
->a
.read_csr(ioaddr
,
453 lp
->a
.write_bcr(ioaddr
, 9, val
);
456 /* set/reset GPSI bit in test register */
457 val
= lp
->a
.read_csr(ioaddr
, 124) & ~0x10;
458 if ((lp
->options
& PCNET32_PORT_PORTSEL
) == PCNET32_PORT_GPSI
)
460 lp
->a
.write_csr(ioaddr
, 124, val
);
462 if (lp
->mii
&& !(lp
->options
& PCNET32_PORT_ASEL
)) {
463 val
= lp
->a
.read_bcr(ioaddr
, 32) & ~0x38; /* disable Auto Negotiation, set 10Mpbs, HD */
464 if (lp
->options
& PCNET32_PORT_FD
)
466 if (lp
->options
& PCNET32_PORT_100
)
468 lp
->a
.write_bcr(ioaddr
, 32, val
);
470 if (lp
->options
& PCNET32_PORT_ASEL
) { /* enable auto negotiate, setup, disable fd */
471 val
= lp
->a
.read_bcr(ioaddr
, 32) & ~0x98;
473 lp
->a
.write_bcr(ioaddr
, 32, val
);
478 if (lp
->dxsuflo
) { /* Disable transmit stop on underflow */
479 val
= lp
->a
.read_csr(ioaddr
, 3);
481 lp
->a
.write_csr(ioaddr
, 3, val
);
487 val
= lp
->a
.read_csr(ioaddr
, 3);
489 | (1 << 14) //BABLM intr disabled
490 | (1 << 12) //MISSM missed frame mask intr disabled
491 | (1 << 10) //RINTM receive intr disabled
492 | (1 << 9) //TINTM transmit intr disabled
493 | (1 << 8) //IDONM init done intr disabled
495 lp
->a
.write_csr(ioaddr
, 3, val
);
498 if (lp
->ltint
) { /* Enable TxDone-intr inhibitor */
499 val
= lp
->a
.read_csr(ioaddr
, 5);
501 lp
->a
.write_csr(ioaddr
, 5, val
);
503 lp
->init_block
.mode
=
504 le16_to_cpu((lp
->options
& PCNET32_PORT_PORTSEL
) << 7);
505 lp
->init_block
.filter
[0] = 0xffffffff;
506 lp
->init_block
.filter
[1] = 0xffffffff;
508 pcnet32_init_ring(nic
);
511 /* Re-initialize the PCNET32, and start it when done. */
512 lp
->a
.write_csr(ioaddr
, 1,
513 (virt_to_bus(&lp
->init_block
)) & 0xffff);
514 lp
->a
.write_csr(ioaddr
, 2, (virt_to_bus(&lp
->init_block
)) >> 16);
515 lp
->a
.write_csr(ioaddr
, 4, 0x0915);
516 lp
->a
.write_csr(ioaddr
, 0, 0x0001);
521 if (lp
->a
.read_csr(ioaddr
, 0) & 0x0100)
524 * We used to clear the InitDone bit, 0x0100, here but Mark Stockton
525 * reports that doing so triggers a bug in the '974.
527 lp
->a
.write_csr(ioaddr
, 0, 0x0042);
529 dprintf(("pcnet32 open, csr0 %hX.\n", lp
->a
.read_csr(ioaddr
, 0)));
533 /**************************************************************************
534 POLL - Wait for a frame
535 ***************************************************************************/
536 static int pcnet32_poll(struct nic
*nic __unused
, int retrieve
)
538 /* return true if there's an ethernet packet ready to read */
539 /* nic->packet should contain data on return */
540 /* nic->packetlen should contain length of data */
545 entry
= lp
->cur_rx
& RX_RING_MOD_MASK
;
546 status
= (le16_to_cpu(pcnet32_bufs
.rx_ring
[entry
].status
) >> 8);
551 if ( ! retrieve
) return 1;
553 if (status
== 0x03) {
555 (le32_to_cpu(pcnet32_bufs
.rx_ring
[entry
].msg_length
)
557 memcpy(nic
->packet
, &pcnet32_bufs
.rxb
[entry
], nic
->packetlen
);
559 /* Andrew Boyd of QNX reports that some revs of the 79C765
560 * clear the buffer length */
561 pcnet32_bufs
.rx_ring
[entry
].buf_length
562 = le16_to_cpu(-PKT_BUF_SZ
);
563 /* prime for next receive */
564 pcnet32_bufs
.rx_ring
[entry
].status
|= le16_to_cpu(0x8000);
565 /* Switch to the next Rx ring buffer */
575 /**************************************************************************
576 TRANSMIT - Transmit a frame
577 ***************************************************************************/
578 static void pcnet32_transmit(struct nic
*nic __unused
, const char *d
, /* Destination */
579 unsigned int t
, /* Type */
580 unsigned int s
, /* size */
583 /* send the packet to destination */
588 int entry
= 0; /*lp->cur_tx & TX_RING_MOD_MASK; */
591 /* point to the current txb incase multiple tx_rings are used */
592 ptxb
= pcnet32_bufs
.txb
+ (lp
->cur_tx
* PKT_BUF_SZ
);
594 /* copy the packet to ring buffer */
595 memcpy(ptxb
, d
, ETH_ALEN
); /* dst */
596 memcpy(ptxb
+ ETH_ALEN
, nic
->node_addr
, ETH_ALEN
); /* src */
597 nstype
= htons((u16
) t
); /* type */
598 memcpy(ptxb
+ 2 * ETH_ALEN
, (u8
*) & nstype
, 2); /* type */
599 memcpy(ptxb
+ ETH_HLEN
, p
, s
);
602 while (s
< ETH_ZLEN
) /* pad to min length */
605 pcnet32_bufs
.tx_ring
[entry
].length
= le16_to_cpu(-s
);
606 pcnet32_bufs
.tx_ring
[entry
].misc
= 0x00000000;
607 pcnet32_bufs
.tx_ring
[entry
].base
= (u32
) virt_to_le32desc(ptxb
);
609 /* we set the top byte as the very last thing */
610 pcnet32_bufs
.tx_ring
[entry
].status
= le16_to_cpu(status
);
613 /* Trigger an immediate send poll */
614 lp
->a
.write_csr(ioaddr
, 0, 0x0048);
616 /* wait for transmit complete */
617 lp
->cur_tx
= 0; /* (lp->cur_tx + 1); */
618 time
= currticks() + TICKS_PER_SEC
; /* wait one second */
619 while (currticks() < time
&&
620 ((short) le16_to_cpu(pcnet32_bufs
.tx_ring
[entry
].status
) < 0));
622 if ((short) le16_to_cpu(pcnet32_bufs
.tx_ring
[entry
].status
) < 0)
623 printf("PCNET32 timed out on transmit\n");
625 /* Stop pointing at the current txb
626 * otherwise the card continues to send the packet */
627 pcnet32_bufs
.tx_ring
[entry
].base
= 0;
631 /**************************************************************************
632 DISABLE - Turn off ethernet interface
633 ***************************************************************************/
634 static void pcnet32_disable ( struct nic
*nic __unused
) {
635 /* Stop the PCNET32 here -- it ocassionally polls memory if we don't */
636 lp
->a
.write_csr(ioaddr
, 0, 0x0004);
639 * Switch back to 16-bit mode to avoid problems with dumb
640 * DOS packet driver after a warm reboot
642 lp
->a
.write_bcr(ioaddr
, 20, 0);
645 /**************************************************************************
646 IRQ - Enable, Disable, or Force interrupts
647 ***************************************************************************/
648 static void pcnet32_irq(struct nic
*nic __unused
, irq_action_t action __unused
)
661 /**************************************************************************
662 PROBE - Look for an adapter, this routine's visible to the outside
663 You should omit the last argument struct pci_device * for a non-PCI NIC
664 ***************************************************************************/
665 static int pcnet32_probe ( struct nic
*nic
, struct pci_device
*pci
) {
668 int fdx
, mii
, fset
, dxsuflo
, ltint
;
670 struct pcnet32_access
*a
= NULL
;
675 if (pci
->ioaddr
== 0)
678 /* BASE is used throughout to address the card */
679 ioaddr
= pci
->ioaddr
;
680 printf("pcnet32.c: Found %s, Vendor=0x%hX Device=0x%hX\n",
681 pci
->driver_name
, pci
->vendor
, pci
->device
);
684 pci_fill_nic ( nic
, pci
);
685 nic
->ioaddr
= pci
->ioaddr
& ~3;
688 pcnet32_wio_reset(ioaddr
);
690 /* NOTE: 16-bit check is first, otherwise some older PCnet chips fail */
691 if (pcnet32_wio_read_csr(ioaddr
, 0) == 4
692 && pcnet32_wio_check(ioaddr
)) {
695 pcnet32_dwio_reset(ioaddr
);
696 if (pcnet32_dwio_read_csr(ioaddr
, 0) == 4
697 && pcnet32_dwio_check(ioaddr
)) {
704 a
->read_csr(ioaddr
, 88) | (a
->read_csr(ioaddr
, 89) << 16);
706 dprintf(("PCnet chip version is 0x%X\n", chip_version
));
707 if ((chip_version
& 0xfff) != 0x003)
710 /* initialize variables */
711 fdx
= mii
= fset
= dxsuflo
= ltint
= 0;
712 chip_version
= (chip_version
>> 12) & 0xffff;
714 switch (chip_version
) {
716 chipname
= "PCnet/PCI 79C970"; /* PCI */
720 chipname
= "PCnet/PCI 79C970"; /* 970 gives the wrong chip id back */
722 chipname
= "PCnet/32 79C965"; /* 486/VL bus */
725 chipname
= "PCnet/PCI II 79C970A"; /* PCI */
729 chipname
= "PCnet/FAST 79C971"; /* PCI */
736 chipname
= "PCnet/FAST+ 79C972"; /* PCI */
742 chipname
= "PCnet/FAST III 79C973"; /* PCI */
747 chipname
= "PCnet/Home 79C978"; /* PCI */
750 * This is based on specs published at www.amd.com. This section
751 * assumes that a card with a 79C978 wants to go into 1Mb HomePNA
752 * mode. The 79C978 can also go into standard ethernet, and there
753 * probably should be some sort of module option to select the
754 * mode by which the card should operate
756 /* switch to home wiring mode */
757 media
= a
->read_bcr(ioaddr
, 49);
759 printf("media reset to %#x.\n", media
);
760 a
->write_bcr(ioaddr
, 49, media
);
763 chipname
= "PCnet/FAST III 79C975"; /* PCI */
768 chipname
= "UNKNOWN";
769 printf("PCnet version %#x, no PCnet32 chip.\n",
775 * On selected chips turn on the BCR18:NOUFLO bit. This stops transmit
776 * starting until the packet is loaded. Strike one for reliability, lose
777 * one for latency - although on PCI this isnt a big loss. Older chips
778 * have FIFO's smaller than a packet, so you can't do this.
782 a
->write_bcr(ioaddr
, 18,
783 (a
->read_bcr(ioaddr
, 18) | 0x0800));
784 a
->write_csr(ioaddr
, 80,
785 (a
->read_csr(ioaddr
, 80) & 0x0C00) | 0x0c00);
790 DBG ( "%s at %hX,", chipname
, (unsigned int) ioaddr
);
792 /* read PROM address */
793 for (i
= 0; i
< 6; i
++)
794 promaddr
[i
] = inb(ioaddr
+ i
);
796 /* Update the nic structure with the MAC Address */
797 for (i
= 0; i
< ETH_ALEN
; i
++) {
798 nic
->node_addr
[i
] = promaddr
[i
];
801 /* Print out some hardware info */
802 DBG ( "%s: IO Addr 0x%hX, MAC Addr %s\n ", chipname
, (unsigned int) ioaddr
,
803 eth_ntoa ( nic
->node_addr
) );
805 /* Set to pci bus master */
806 adjust_pci_device(pci
);
808 /* point to private storage */
812 if (((chip_version
+ 1) & 0xfffe) == 0x2624) { /* Version 0x2623 or 0x2624 */
813 i
= a
->read_csr(ioaddr
, 80) & 0x0C00; /* Check tx_start_pt */
814 dprintf((" tx_start_pt(0x%hX):", i
));
817 dprintf((" 20 bytes,"));
820 dprintf((" 64 bytes,"));
823 dprintf((" 128 bytes,"));
826 dprintf(("~220 bytes,"));
829 i
= a
->read_bcr(ioaddr
, 18); /* Check Burst/Bus control */
830 dprintf((" BCR18(%hX):", i
& 0xffff));
832 dprintf(("BurstWrEn "));
834 dprintf(("BurstRdEn "));
836 dprintf(("DWordIO "));
838 dprintf(("NoUFlow "));
839 i
= a
->read_bcr(ioaddr
, 25);
840 dprintf((" SRAMSIZE=0x%hX,", i
<< 8));
841 i
= a
->read_bcr(ioaddr
, 26);
842 dprintf((" SRAM_BND=0x%hX,", i
<< 8));
843 i
= a
->read_bcr(ioaddr
, 27);
845 dprintf(("LowLatRx"));
849 lp
->shared_irq
= shared
;
850 lp
->full_duplex
= fdx
;
851 lp
->dxsuflo
= dxsuflo
;
854 /* FIXME: Fix Options for only one card */
855 if ((cards_found
>= MAX_UNITS
)
856 || ((unsigned int) options
[cards_found
] > sizeof(options_mapping
)))
857 lp
->options
= PCNET32_PORT_ASEL
;
859 lp
->options
= options_mapping
[options
[cards_found
]];
861 if (fdx
&& !(lp
->options
& PCNET32_PORT_ASEL
) &&
862 ((cards_found
>= MAX_UNITS
) || full_duplex
[cards_found
]))
863 lp
->options
|= PCNET32_PORT_FD
;
866 printf("No access methods\n");
872 // bin/blib.a(pcnet32.o)(.text+0x6b6): In function `pcnet32_probe':
873 // drivers/net/pcnet32.c:871: undefined reference to `memcpy'
874 // make: *** [bin/pcnet32.dsk.tmp] Error 1
876 memcpy ( &lp
->a
, a
, sizeof ( lp
->a
) );
877 // To explicity call memcpy.
879 /* detect special T1/E1 WAN card by checking for MAC address */
880 if (nic
->node_addr
[0] == 0x00 && nic
->node_addr
[1] == 0xe0
881 && nic
->node_addr
[2] == 0x75)
882 lp
->options
= PCNET32_PORT_FD
| PCNET32_PORT_GPSI
;
884 lp
->init_block
.mode
= le16_to_cpu(0x0003); /* Disable Rx and Tx. */
885 lp
->init_block
.tlen_rlen
=
886 le16_to_cpu(TX_RING_LEN_BITS
| RX_RING_LEN_BITS
);
887 for (i
= 0; i
< 6; i
++)
888 lp
->init_block
.phys_addr
[i
] = nic
->node_addr
[i
];
889 lp
->init_block
.filter
[0] = 0xffffffff;
890 lp
->init_block
.filter
[1] = 0xffffffff;
891 lp
->init_block
.rx_ring
= virt_to_bus(&pcnet32_bufs
.rx_ring
);
892 lp
->init_block
.tx_ring
= virt_to_bus(&pcnet32_bufs
.tx_ring
);
894 /* switch pcnet32 to 32bit mode */
895 a
->write_bcr(ioaddr
, 20, 2);
897 a
->write_csr(ioaddr
, 1, (virt_to_bus(&lp
->init_block
)) & 0xffff);
898 a
->write_csr(ioaddr
, 2, (virt_to_bus(&lp
->init_block
)) >> 16);
901 * To auto-IRQ we enable the initialization-done and DMA error
902 * interrupts. For ISA boards we get a DMA error, but VLB and PCI
905 /* Trigger an initialization just for the interrupt. */
908 // a->write_csr(ioaddr, 0, 0x41);
913 /* point to NIC specific routines */
917 int phy
, phy_idx
= 0;
919 lp
->phys
[0] = 1; /* Default Setting */
920 for (phy
= 1; phy
< 32 && phy_idx
< MII_CNT
; phy
++) {
921 int mii_status
= mdio_read(nic
, phy
, MII_BMSR
);
922 if (mii_status
!= 0xffff && mii_status
!= 0x0000) {
923 lp
->phys
[phy_idx
++] = phy
;
924 lp
->mii_if
.advertising
=
925 mdio_read(nic
, phy
, MII_ADVERTISE
);
926 if ((mii_status
& 0x0040) == 0) {
928 dprintf (("MII PHY found at address %d, status "
929 "%hX advertising %hX\n", phy
, mii_status
,
930 lp
->mii_if
.advertising
));
935 printf("No MII transceiver found!\n");
936 lp
->mii_if
.phy_id
= lp
->phys
[0];
938 lp
->mii_if
.advertising
=
939 mdio_read(nic
, lp
->phys
[0], MII_ADVERTISE
);
941 mii_lpa
= mdio_read(nic
, lp
->phys
[0], MII_LPA
);
942 lp
->mii_if
.advertising
&= mii_lpa
;
943 if (lp
->mii_if
.advertising
& ADVERTISE_100FULL
)
944 printf("100Mbps Full-Duplex\n");
945 else if (lp
->mii_if
.advertising
& ADVERTISE_100HALF
)
946 printf("100Mbps Half-Duplex\n");
947 else if (lp
->mii_if
.advertising
& ADVERTISE_10FULL
)
948 printf("10Mbps Full-Duplex\n");
949 else if (lp
->mii_if
.advertising
& ADVERTISE_10HALF
)
950 printf("10Mbps Half-Duplex\n");
954 /* The older chips are fixed 10Mbps, and some support full duplex,
955 * although not via autonegotiation, but only via configuration. */
957 printf("10Mbps Full-Duplex\n");
959 printf("10Mbps Half-Duplex\n");
962 nic
->nic_op
= &pcnet32_operations
;
966 static int mdio_read(struct nic
*nic __unused
, int phy_id
, int reg_num
)
974 phyaddr
= lp
->a
.read_bcr(ioaddr
, 33);
976 lp
->a
.write_bcr(ioaddr
, 33,
977 ((phy_id
& 0x1f) << 5) | (reg_num
& 0x1f));
978 val_out
= lp
->a
.read_bcr(ioaddr
, 34);
979 lp
->a
.write_bcr(ioaddr
, 33, phyaddr
);
985 static void mdio_write(struct nic
*nic __unused
, int phy_id
, int reg_num
,
993 phyaddr
= lp
->a
.read_bcr(ioaddr
, 33);
995 lp
->a
.write_bcr(ioaddr
, 33,
996 ((phy_id
& 0x1f) << 5) | (reg_num
& 0x1f));
997 lp
->a
.write_bcr(ioaddr
, 34, val
);
998 lp
->a
.write_bcr(ioaddr
, 33, phyaddr
);
1002 static struct nic_operations pcnet32_operations
= {
1003 .connect
= dummy_connect
,
1004 .poll
= pcnet32_poll
,
1005 .transmit
= pcnet32_transmit
,
1010 static struct pci_device_id pcnet32_nics
[] = {
1011 PCI_ROM(0x1022, 0x2000, "pcnet32", "AMD PCnet/PCI"),
1012 PCI_ROM(0x1022, 0x2625, "pcnetfastiii", "AMD PCNet FAST III"),
1013 PCI_ROM(0x1022, 0x2001, "amdhomepna", "AMD PCnet/HomePNA"),
1016 PCI_DRIVER ( pcnet32_driver
, pcnet32_nics
, PCI_NO_CLASS
);
1018 DRIVER ( "PCNET32/PCI", nic_driver
, pci_driver
, pcnet32_driver
,
1019 pcnet32_probe
, pcnet32_disable
);