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>
48 /* void hex_dump(const char *data, const unsigned int len); */
50 /* Etherboot Specific definations */
51 #define drv_version "v1.3"
52 #define drv_date "03-29-2004"
54 static u32 ioaddr; /* Globally used for the card's io address */
55 static struct nic_operations pcnet32_operations;
58 #define dprintf(x) printf x
63 /* Condensed operations for readability. */
64 #define virt_to_le32desc(addr) cpu_to_le32(virt_to_bus(addr))
65 #define le32desc_to_virt(addr) bus_to_virt(le32_to_cpu(addr))
67 /* End Etherboot Specific */
69 static int cards_found = 0 /* __initdata */ ;
72 /* FIXME: Remove these they are probably pointless */
77 static unsigned int pcnet32_portlist[] /*__initdata */ =
78 { 0x300, 0x320, 0x340, 0x360, 0 };
80 static int pcnet32_debug = 1;
81 static int tx_start = 1; /* Mapping -- 0:20, 1:64, 2:128, 3:~220 (depends on chip vers) */
82 static int pcnet32vlb; /* check for VLB cards ? */
84 static struct net_device *pcnet32_dev;
86 static int max_interrupt_work = 80;
87 static int rx_copybreak = 200;
89 #define PCNET32_PORT_AUI 0x00
90 #define PCNET32_PORT_10BT 0x01
91 #define PCNET32_PORT_GPSI 0x02
92 #define PCNET32_PORT_MII 0x03
94 #define PCNET32_PORT_PORTSEL 0x03
95 #define PCNET32_PORT_ASEL 0x04
96 #define PCNET32_PORT_100 0x40
97 #define PCNET32_PORT_FD 0x80
99 #define PCNET32_DMA_MASK 0xffffffff
102 * table to translate option values from tulip
103 * to internal options
105 static unsigned char options_mapping[] = {
106 PCNET32_PORT_ASEL, /* 0 Auto-select */
107 PCNET32_PORT_AUI, /* 1 BNC/AUI */
108 PCNET32_PORT_AUI, /* 2 AUI/BNC */
109 PCNET32_PORT_ASEL, /* 3 not supported */
110 PCNET32_PORT_10BT | PCNET32_PORT_FD, /* 4 10baseT-FD */
111 PCNET32_PORT_ASEL, /* 5 not supported */
112 PCNET32_PORT_ASEL, /* 6 not supported */
113 PCNET32_PORT_ASEL, /* 7 not supported */
114 PCNET32_PORT_ASEL, /* 8 not supported */
115 PCNET32_PORT_MII, /* 9 MII 10baseT */
116 PCNET32_PORT_MII | PCNET32_PORT_FD, /* 10 MII 10baseT-FD */
117 PCNET32_PORT_MII, /* 11 MII (autosel) */
118 PCNET32_PORT_10BT, /* 12 10BaseT */
119 PCNET32_PORT_MII | PCNET32_PORT_100, /* 13 MII 100BaseTx */
120 PCNET32_PORT_MII | PCNET32_PORT_100 | PCNET32_PORT_FD, /* 14 MII 100BaseTx-FD */
121 PCNET32_PORT_ASEL /* 15 not supported */
124 #define MAX_UNITS 8 /* More are supported, limit only on options */
125 static int options[MAX_UNITS];
126 static int full_duplex[MAX_UNITS];
129 * Theory of Operation
131 * This driver uses the same software structure as the normal lance
132 * driver. So look for a verbose description in lance.c. The differences
133 * to the normal lance driver is the use of the 32bit mode of PCnet32
134 * and PCnetPCI chips. Because these chips are 32bit chips, there is no
135 * 16MB limitation and we don't need bounce buffers.
141 * Set the number of Tx and Rx buffers, using Log_2(# buffers).
142 * Reasonable default values are 4 Tx buffers, and 16 Rx buffers.
143 * That translates to 2 (4 == 2^^2) and 4 (16 == 2^^4).
145 #ifndef PCNET32_LOG_TX_BUFFERS
146 #define PCNET32_LOG_TX_BUFFERS 1
147 #define PCNET32_LOG_RX_BUFFERS 2
150 #define TX_RING_SIZE (1 << (PCNET32_LOG_TX_BUFFERS))
151 #define TX_RING_MOD_MASK (TX_RING_SIZE - 1)
152 /* FIXME: Fix this to allow multiple tx_ring descriptors */
153 #define TX_RING_LEN_BITS 0x0000 /*PCNET32_LOG_TX_BUFFERS) << 12) */
155 #define RX_RING_SIZE (1 << (PCNET32_LOG_RX_BUFFERS))
156 #define RX_RING_MOD_MASK (RX_RING_SIZE - 1)
157 #define RX_RING_LEN_BITS ((PCNET32_LOG_RX_BUFFERS) << 4)
159 #define PKT_BUF_SZ 1544
161 /* Offsets from base I/O address. */
162 #define PCNET32_WIO_RDP 0x10
163 #define PCNET32_WIO_RAP 0x12
164 #define PCNET32_WIO_RESET 0x14
165 #define PCNET32_WIO_BDP 0x16
167 #define PCNET32_DWIO_RDP 0x10
168 #define PCNET32_DWIO_RAP 0x14
169 #define PCNET32_DWIO_RESET 0x18
170 #define PCNET32_DWIO_BDP 0x1C
172 #define PCNET32_TOTAL_SIZE 0x20
174 /* The PCNET32 Rx and Tx ring descriptors. */
175 struct pcnet32_rx_head {
183 struct pcnet32_tx_head {
191 /* The PCNET32 32-Bit initialization block, described in databook. */
192 struct pcnet32_init_block {
198 /* Receive and transmit ring base, along with extra bits. */
202 /* PCnet32 access functions */
203 struct pcnet32_access {
204 u16(*read_csr) (unsigned long, int);
205 void (*write_csr) (unsigned long, int, u16);
206 u16(*read_bcr) (unsigned long, int);
207 void (*write_bcr) (unsigned long, int, u16);
208 u16(*read_rap) (unsigned long);
209 void (*write_rap) (unsigned long, u16);
210 void (*reset) (unsigned long);
213 /* Define the TX and RX Descriptors and Rings */
215 struct pcnet32_tx_head tx_ring[TX_RING_SIZE]
216 __attribute__ ((aligned(16)));
217 struct pcnet32_rx_head rx_ring[RX_RING_SIZE]
218 __attribute__ ((aligned(16)));
219 unsigned char txb[TX_RING_SIZE][PKT_BUF_SZ];
220 unsigned char rxb[RX_RING_SIZE][PKT_BUF_SZ];
221 } pcnet32_bufs __shared;
223 /* May need to be moved to mii.h */
227 unsigned int full_duplex:1; /* is full duplex? */
231 * The first three fields of pcnet32_private are read by the ethernet device
232 * so we allocate the structure should be allocated by pci_alloc_consistent().
235 struct pcnet32_private {
236 struct pcnet32_init_block init_block;
237 struct pci_dev *pci_dev; /* Pointer to the associated pci device structure */
239 /* The saved address of a sent-in-place packet/buffer, for skfree(). */
240 struct sk_buff *tx_skbuff[TX_RING_SIZE];
241 struct sk_buff *rx_skbuff[RX_RING_SIZE];
242 struct pcnet32_access a;
243 unsigned int cur_rx, cur_tx; /* The next free ring entry */
246 int shared_irq:1, /* shared irq possible */
247 ltint:1, /* enable TxDone-intr inhibitor */
248 dxsuflo:1, /* disable transmit stop on uflo */
249 mii:1; /* mii port available */
250 struct mii_if_info mii_if;
251 unsigned char phys[MII_CNT];
252 struct net_device *next;
256 static struct pcnet32_private *lp;
258 static int mdio_read(struct nic *nic __unused, int phy_id, int reg_num);
260 static void mdio_write(struct nic *nic __unused, int phy_id, int reg_num,
264 PCI_USES_IO = 1, PCI_USES_MEM = 2, PCI_USES_MASTER = 4,
265 PCI_ADDR0 = 0x10 << 0, PCI_ADDR1 = 0x10 << 1, PCI_ADDR2 =
266 0x10 << 2, PCI_ADDR3 = 0x10 << 3,
270 static u16 pcnet32_wio_read_csr(unsigned long addr, int index)
272 outw(index, addr + PCNET32_WIO_RAP);
273 return inw(addr + PCNET32_WIO_RDP);
276 static void pcnet32_wio_write_csr(unsigned long addr, int index, u16 val)
278 outw(index, addr + PCNET32_WIO_RAP);
279 outw(val, addr + PCNET32_WIO_RDP);
282 static u16 pcnet32_wio_read_bcr(unsigned long addr, int index)
284 outw(index, addr + PCNET32_WIO_RAP);
285 return inw(addr + PCNET32_WIO_BDP);
288 static void pcnet32_wio_write_bcr(unsigned long addr, int index, u16 val)
290 outw(index, addr + PCNET32_WIO_RAP);
291 outw(val, addr + PCNET32_WIO_BDP);
294 static u16 pcnet32_wio_read_rap(unsigned long addr)
296 return inw(addr + PCNET32_WIO_RAP);
299 static void pcnet32_wio_write_rap(unsigned long addr, u16 val)
301 outw(val, addr + PCNET32_WIO_RAP);
304 static void pcnet32_wio_reset(unsigned long addr)
306 inw(addr + PCNET32_WIO_RESET);
309 static int pcnet32_wio_check(unsigned long addr)
311 outw(88, addr + PCNET32_WIO_RAP);
312 return (inw(addr + PCNET32_WIO_RAP) == 88);
315 static struct pcnet32_access pcnet32_wio = {
316 read_csr:pcnet32_wio_read_csr,
317 write_csr:pcnet32_wio_write_csr,
318 read_bcr:pcnet32_wio_read_bcr,
319 write_bcr:pcnet32_wio_write_bcr,
320 read_rap:pcnet32_wio_read_rap,
321 write_rap:pcnet32_wio_write_rap,
322 reset:pcnet32_wio_reset
325 static u16 pcnet32_dwio_read_csr(unsigned long addr, int index)
327 outl(index, addr + PCNET32_DWIO_RAP);
328 return (inl(addr + PCNET32_DWIO_RDP) & 0xffff);
331 static void pcnet32_dwio_write_csr(unsigned long addr, int index, u16 val)
333 outl(index, addr + PCNET32_DWIO_RAP);
334 outl(val, addr + PCNET32_DWIO_RDP);
337 static u16 pcnet32_dwio_read_bcr(unsigned long addr, int index)
339 outl(index, addr + PCNET32_DWIO_RAP);
340 return (inl(addr + PCNET32_DWIO_BDP) & 0xffff);
343 static void pcnet32_dwio_write_bcr(unsigned long addr, int index, u16 val)
345 outl(index, addr + PCNET32_DWIO_RAP);
346 outl(val, addr + PCNET32_DWIO_BDP);
349 static u16 pcnet32_dwio_read_rap(unsigned long addr)
351 return (inl(addr + PCNET32_DWIO_RAP) & 0xffff);
354 static void pcnet32_dwio_write_rap(unsigned long addr, u16 val)
356 outl(val, addr + PCNET32_DWIO_RAP);
359 static void pcnet32_dwio_reset(unsigned long addr)
361 inl(addr + PCNET32_DWIO_RESET);
364 static int pcnet32_dwio_check(unsigned long addr)
366 outl(88, addr + PCNET32_DWIO_RAP);
367 return ((inl(addr + PCNET32_DWIO_RAP) & 0xffff) == 88);
370 static struct pcnet32_access pcnet32_dwio = {
371 read_csr:pcnet32_dwio_read_csr,
372 write_csr:pcnet32_dwio_write_csr,
373 read_bcr:pcnet32_dwio_read_bcr,
374 write_bcr:pcnet32_dwio_write_bcr,
375 read_rap:pcnet32_dwio_read_rap,
376 write_rap:pcnet32_dwio_write_rap,
377 reset:pcnet32_dwio_reset
381 /* Initialize the PCNET32 Rx and Tx rings. */
382 static int pcnet32_init_ring(struct nic *nic)
387 lp->cur_rx = lp->cur_tx = 0;
389 for (i = 0; i < RX_RING_SIZE; i++) {
390 pcnet32_bufs.rx_ring[i].base =
391 virt_to_le32desc(&pcnet32_bufs.rxb[i]);
392 pcnet32_bufs.rx_ring[i].buf_length = le16_to_cpu(-PKT_BUF_SZ);
393 pcnet32_bufs.rx_ring[i].status = le16_to_cpu(0x8000);
396 /* The Tx buffer address is filled in as needed, but we do need to clear
397 the upper ownership bit. */
398 for (i = 0; i < TX_RING_SIZE; i++) {
399 pcnet32_bufs.tx_ring[i].base = 0;
400 pcnet32_bufs.tx_ring[i].status = 0;
404 lp->init_block.tlen_rlen =
405 le16_to_cpu(TX_RING_LEN_BITS | RX_RING_LEN_BITS);
406 for (i = 0; i < 6; i++)
407 lp->init_block.phys_addr[i] = nic->node_addr[i];
408 lp->init_block.rx_ring = virt_to_le32desc(&pcnet32_bufs.rx_ring[0]);
409 lp->init_block.tx_ring = virt_to_le32desc(&pcnet32_bufs.tx_ring[0]);
413 /**************************************************************************
414 RESET - Reset adapter
415 ***************************************************************************/
416 static void pcnet32_reset(struct nic *nic)
418 /* put the card in its initial state */
422 /* Reset the PCNET32 */
425 /* switch pcnet32 to 32bit mode */
426 lp->a.write_bcr(ioaddr, 20, 2);
428 /* set/reset autoselect bit */
429 val = lp->a.read_bcr(ioaddr, 2) & ~2;
430 if (lp->options & PCNET32_PORT_ASEL)
432 lp->a.write_bcr(ioaddr, 2, val);
434 /* handle full duplex setting */
435 if (lp->full_duplex) {
436 val = lp->a.read_bcr(ioaddr, 9) & ~3;
437 if (lp->options & PCNET32_PORT_FD) {
440 (PCNET32_PORT_FD | PCNET32_PORT_AUI))
442 } else if (lp->options & PCNET32_PORT_ASEL) {
443 /* workaround of xSeries250, turn on for 79C975 only */
446 88) | (lp->a.read_csr(ioaddr,
452 lp->a.write_bcr(ioaddr, 9, val);
455 /* set/reset GPSI bit in test register */
456 val = lp->a.read_csr(ioaddr, 124) & ~0x10;
457 if ((lp->options & PCNET32_PORT_PORTSEL) == PCNET32_PORT_GPSI)
459 lp->a.write_csr(ioaddr, 124, val);
461 if (lp->mii && !(lp->options & PCNET32_PORT_ASEL)) {
462 val = lp->a.read_bcr(ioaddr, 32) & ~0x38; /* disable Auto Negotiation, set 10Mpbs, HD */
463 if (lp->options & PCNET32_PORT_FD)
465 if (lp->options & PCNET32_PORT_100)
467 lp->a.write_bcr(ioaddr, 32, val);
469 if (lp->options & PCNET32_PORT_ASEL) { /* enable auto negotiate, setup, disable fd */
470 val = lp->a.read_bcr(ioaddr, 32) & ~0x98;
472 lp->a.write_bcr(ioaddr, 32, val);
477 if (lp->dxsuflo) { /* Disable transmit stop on underflow */
478 val = lp->a.read_csr(ioaddr, 3);
480 lp->a.write_csr(ioaddr, 3, val);
486 val = lp->a.read_csr(ioaddr, 3);
488 | (1 << 14) //BABLM intr disabled
489 | (1 << 12) //MISSM missed frame mask intr disabled
490 | (1 << 10) //RINTM receive intr disabled
491 | (1 << 9) //TINTM transmit intr disabled
492 | (1 << 8) //IDONM init done intr disabled
494 lp->a.write_csr(ioaddr, 3, val);
497 if (lp->ltint) { /* Enable TxDone-intr inhibitor */
498 val = lp->a.read_csr(ioaddr, 5);
500 lp->a.write_csr(ioaddr, 5, val);
502 lp->init_block.mode =
503 le16_to_cpu((lp->options & PCNET32_PORT_PORTSEL) << 7);
504 lp->init_block.filter[0] = 0xffffffff;
505 lp->init_block.filter[1] = 0xffffffff;
507 pcnet32_init_ring(nic);
510 /* Re-initialize the PCNET32, and start it when done. */
511 lp->a.write_csr(ioaddr, 1,
512 (virt_to_bus(&lp->init_block)) & 0xffff);
513 lp->a.write_csr(ioaddr, 2, (virt_to_bus(&lp->init_block)) >> 16);
514 lp->a.write_csr(ioaddr, 4, 0x0915);
515 lp->a.write_csr(ioaddr, 0, 0x0001);
520 if (lp->a.read_csr(ioaddr, 0) & 0x0100)
523 * We used to clear the InitDone bit, 0x0100, here but Mark Stockton
524 * reports that doing so triggers a bug in the '974.
526 lp->a.write_csr(ioaddr, 0, 0x0042);
528 dprintf(("pcnet32 open, csr0 %hX.\n", lp->a.read_csr(ioaddr, 0)));
532 /**************************************************************************
533 POLL - Wait for a frame
534 ***************************************************************************/
535 static int pcnet32_poll(struct nic *nic __unused, int retrieve)
537 /* return true if there's an ethernet packet ready to read */
538 /* nic->packet should contain data on return */
539 /* nic->packetlen should contain length of data */
544 entry = lp->cur_rx & RX_RING_MOD_MASK;
545 status = (le16_to_cpu(pcnet32_bufs.rx_ring[entry].status) >> 8);
550 if ( ! retrieve ) return 1;
552 if (status == 0x03) {
554 (le32_to_cpu(pcnet32_bufs.rx_ring[entry].msg_length)
556 memcpy(nic->packet, &pcnet32_bufs.rxb[entry], nic->packetlen);
558 /* Andrew Boyd of QNX reports that some revs of the 79C765
559 * clear the buffer length */
560 pcnet32_bufs.rx_ring[entry].buf_length
561 = le16_to_cpu(-PKT_BUF_SZ);
562 /* prime for next receive */
563 pcnet32_bufs.rx_ring[entry].status |= le16_to_cpu(0x8000);
564 /* Switch to the next Rx ring buffer */
574 /**************************************************************************
575 TRANSMIT - Transmit a frame
576 ***************************************************************************/
577 static void pcnet32_transmit(struct nic *nic __unused, const char *d, /* Destination */
578 unsigned int t, /* Type */
579 unsigned int s, /* size */
582 /* send the packet to destination */
587 int entry = 0; /*lp->cur_tx & TX_RING_MOD_MASK; */
590 /* point to the current txb incase multiple tx_rings are used */
591 ptxb = pcnet32_bufs.txb[lp->cur_tx];
593 /* copy the packet to ring buffer */
594 memcpy(ptxb, d, ETH_ALEN); /* dst */
595 memcpy(ptxb + ETH_ALEN, nic->node_addr, ETH_ALEN); /* src */
596 nstype = htons((u16) t); /* type */
597 memcpy(ptxb + 2 * ETH_ALEN, (u8 *) & nstype, 2); /* type */
598 memcpy(ptxb + ETH_HLEN, p, s);
601 while (s < ETH_ZLEN) /* pad to min length */
604 pcnet32_bufs.tx_ring[entry].length = le16_to_cpu(-s);
605 pcnet32_bufs.tx_ring[entry].misc = 0x00000000;
606 pcnet32_bufs.tx_ring[entry].base = (u32) virt_to_le32desc(ptxb);
608 /* we set the top byte as the very last thing */
609 pcnet32_bufs.tx_ring[entry].status = le16_to_cpu(status);
612 /* Trigger an immediate send poll */
613 lp->a.write_csr(ioaddr, 0, 0x0048);
615 /* wait for transmit complete */
616 lp->cur_tx = 0; /* (lp->cur_tx + 1); */
617 time = currticks() + TICKS_PER_SEC; /* wait one second */
618 while (currticks() < time &&
619 ((short) le16_to_cpu(pcnet32_bufs.tx_ring[entry].status) < 0));
621 if ((short) le16_to_cpu(pcnet32_bufs.tx_ring[entry].status) < 0)
622 printf("PCNET32 timed out on transmit\n");
624 /* Stop pointing at the current txb
625 * otherwise the card continues to send the packet */
626 pcnet32_bufs.tx_ring[entry].base = 0;
630 /**************************************************************************
631 DISABLE - Turn off ethernet interface
632 ***************************************************************************/
633 static void pcnet32_disable ( struct nic *nic __unused ) {
634 /* Stop the PCNET32 here -- it ocassionally polls memory if we don't */
635 lp->a.write_csr(ioaddr, 0, 0x0004);
638 * Switch back to 16-bit mode to avoid problems with dumb
639 * DOS packet driver after a warm reboot
641 lp->a.write_bcr(ioaddr, 20, 0);
644 /**************************************************************************
645 IRQ - Enable, Disable, or Force interrupts
646 ***************************************************************************/
647 static void pcnet32_irq(struct nic *nic __unused, irq_action_t action __unused)
660 /**************************************************************************
661 PROBE - Look for an adapter, this routine's visible to the outside
662 You should omit the last argument struct pci_device * for a non-PCI NIC
663 ***************************************************************************/
664 static int pcnet32_probe ( struct nic *nic, struct pci_device *pci ) {
667 int fdx, mii, fset, dxsuflo, ltint;
669 struct pcnet32_access *a = NULL;
674 if (pci->ioaddr == 0)
677 /* BASE is used throughout to address the card */
678 ioaddr = pci->ioaddr;
679 printf("pcnet32.c: Found %s, Vendor=0x%hX Device=0x%hX\n",
680 pci->driver_name, pci->vendor, pci->device);
683 nic->ioaddr = pci->ioaddr & ~3;
686 pcnet32_wio_reset(ioaddr);
688 /* NOTE: 16-bit check is first, otherwise some older PCnet chips fail */
689 if (pcnet32_wio_read_csr(ioaddr, 0) == 4
690 && pcnet32_wio_check(ioaddr)) {
693 pcnet32_dwio_reset(ioaddr);
694 if (pcnet32_dwio_read_csr(ioaddr, 0) == 4
695 && pcnet32_dwio_check(ioaddr)) {
702 a->read_csr(ioaddr, 88) | (a->read_csr(ioaddr, 89) << 16);
704 dprintf(("PCnet chip version is 0x%X\n", chip_version));
705 if ((chip_version & 0xfff) != 0x003)
708 /* initialize variables */
709 fdx = mii = fset = dxsuflo = ltint = 0;
710 chip_version = (chip_version >> 12) & 0xffff;
712 switch (chip_version) {
714 chipname = "PCnet/PCI 79C970"; /* PCI */
718 chipname = "PCnet/PCI 79C970"; /* 970 gives the wrong chip id back */
720 chipname = "PCnet/32 79C965"; /* 486/VL bus */
723 chipname = "PCnet/PCI II 79C970A"; /* PCI */
727 chipname = "PCnet/FAST 79C971"; /* PCI */
734 chipname = "PCnet/FAST+ 79C972"; /* PCI */
740 chipname = "PCnet/FAST III 79C973"; /* PCI */
745 chipname = "PCnet/Home 79C978"; /* PCI */
748 * This is based on specs published at www.amd.com. This section
749 * assumes that a card with a 79C978 wants to go into 1Mb HomePNA
750 * mode. The 79C978 can also go into standard ethernet, and there
751 * probably should be some sort of module option to select the
752 * mode by which the card should operate
754 /* switch to home wiring mode */
755 media = a->read_bcr(ioaddr, 49);
757 printf("media reset to %#x.\n", media);
758 a->write_bcr(ioaddr, 49, media);
761 chipname = "PCnet/FAST III 79C975"; /* PCI */
766 chipname = "UNKNOWN";
767 printf("PCnet version %#x, no PCnet32 chip.\n",
773 * On selected chips turn on the BCR18:NOUFLO bit. This stops transmit
774 * starting until the packet is loaded. Strike one for reliability, lose
775 * one for latency - although on PCI this isnt a big loss. Older chips
776 * have FIFO's smaller than a packet, so you can't do this.
780 a->write_bcr(ioaddr, 18,
781 (a->read_bcr(ioaddr, 18) | 0x0800));
782 a->write_csr(ioaddr, 80,
783 (a->read_csr(ioaddr, 80) & 0x0C00) | 0x0c00);
788 DBG ( "%s at %hX,", chipname, (unsigned int) ioaddr );
790 /* read PROM address */
791 for (i = 0; i < 6; i++)
792 promaddr[i] = inb(ioaddr + i);
794 /* Update the nic structure with the MAC Address */
795 for (i = 0; i < ETH_ALEN; i++) {
796 nic->node_addr[i] = promaddr[i];
799 /* Print out some hardware info */
800 DBG ( "%s: IO Addr 0x%hX, MAC Addr %s\n ", chipname, (unsigned int) ioaddr,
801 eth_ntoa ( nic->node_addr ) );
803 /* Set to pci bus master */
804 adjust_pci_device(pci);
806 /* point to private storage */
810 if (((chip_version + 1) & 0xfffe) == 0x2624) { /* Version 0x2623 or 0x2624 */
811 i = a->read_csr(ioaddr, 80) & 0x0C00; /* Check tx_start_pt */
812 dprintf((" tx_start_pt(0x%hX):", i));
815 dprintf((" 20 bytes,"));
818 dprintf((" 64 bytes,"));
821 dprintf((" 128 bytes,"));
824 dprintf(("~220 bytes,"));
827 i = a->read_bcr(ioaddr, 18); /* Check Burst/Bus control */
828 dprintf((" BCR18(%hX):", i & 0xffff));
830 dprintf(("BurstWrEn "));
832 dprintf(("BurstRdEn "));
834 dprintf(("DWordIO "));
836 dprintf(("NoUFlow "));
837 i = a->read_bcr(ioaddr, 25);
838 dprintf((" SRAMSIZE=0x%hX,", i << 8));
839 i = a->read_bcr(ioaddr, 26);
840 dprintf((" SRAM_BND=0x%hX,", i << 8));
841 i = a->read_bcr(ioaddr, 27);
843 dprintf(("LowLatRx"));
847 lp->shared_irq = shared;
848 lp->full_duplex = fdx;
849 lp->dxsuflo = dxsuflo;
852 /* FIXME: Fix Options for only one card */
853 if ((cards_found >= MAX_UNITS)
854 || ((unsigned int) options[cards_found] > sizeof(options_mapping)))
855 lp->options = PCNET32_PORT_ASEL;
857 lp->options = options_mapping[options[cards_found]];
859 if (fdx && !(lp->options & PCNET32_PORT_ASEL) &&
860 ((cards_found >= MAX_UNITS) || full_duplex[cards_found]))
861 lp->options |= PCNET32_PORT_FD;
864 printf("No access methods\n");
870 // bin/blib.a(pcnet32.o)(.text+0x6b6): In function `pcnet32_probe':
871 // drivers/net/pcnet32.c:871: undefined reference to `memcpy'
872 // make: *** [bin/pcnet32.dsk.tmp] Error 1
874 memcpy ( &lp->a, a, sizeof ( lp->a ) );
875 // To explicity call memcpy.
877 /* detect special T1/E1 WAN card by checking for MAC address */
878 if (nic->node_addr[0] == 0x00 && nic->node_addr[1] == 0xe0
879 && nic->node_addr[2] == 0x75)
880 lp->options = PCNET32_PORT_FD | PCNET32_PORT_GPSI;
882 lp->init_block.mode = le16_to_cpu(0x0003); /* Disable Rx and Tx. */
883 lp->init_block.tlen_rlen =
884 le16_to_cpu(TX_RING_LEN_BITS | RX_RING_LEN_BITS);
885 for (i = 0; i < 6; i++)
886 lp->init_block.phys_addr[i] = nic->node_addr[i];
887 lp->init_block.filter[0] = 0xffffffff;
888 lp->init_block.filter[1] = 0xffffffff;
889 lp->init_block.rx_ring = virt_to_bus(&pcnet32_bufs.rx_ring);
890 lp->init_block.tx_ring = virt_to_bus(&pcnet32_bufs.tx_ring);
892 /* switch pcnet32 to 32bit mode */
893 a->write_bcr(ioaddr, 20, 2);
895 a->write_csr(ioaddr, 1, (virt_to_bus(&lp->init_block)) & 0xffff);
896 a->write_csr(ioaddr, 2, (virt_to_bus(&lp->init_block)) >> 16);
899 * To auto-IRQ we enable the initialization-done and DMA error
900 * interrupts. For ISA boards we get a DMA error, but VLB and PCI
903 /* Trigger an initialization just for the interrupt. */
906 // a->write_csr(ioaddr, 0, 0x41);
911 /* point to NIC specific routines */
915 int phy, phy_idx = 0;
917 lp->phys[0] = 1; /* Default Setting */
918 for (phy = 1; phy < 32 && phy_idx < MII_CNT; phy++) {
919 int mii_status = mdio_read(nic, phy, MII_BMSR);
920 if (mii_status != 0xffff && mii_status != 0x0000) {
921 lp->phys[phy_idx++] = phy;
922 lp->mii_if.advertising =
923 mdio_read(nic, phy, MII_ADVERTISE);
924 if ((mii_status & 0x0040) == 0) {
926 dprintf (("MII PHY found at address %d, status "
927 "%hX advertising %hX\n", phy, mii_status,
928 lp->mii_if.advertising));
933 printf("No MII transceiver found!\n");
934 lp->mii_if.phy_id = lp->phys[0];
936 lp->mii_if.advertising =
937 mdio_read(nic, lp->phys[0], MII_ADVERTISE);
939 mii_lpa = mdio_read(nic, lp->phys[0], MII_LPA);
940 lp->mii_if.advertising &= mii_lpa;
941 if (lp->mii_if.advertising & ADVERTISE_100FULL)
942 printf("100Mbps Full-Duplex\n");
943 else if (lp->mii_if.advertising & ADVERTISE_100HALF)
944 printf("100Mbps Half-Duplex\n");
945 else if (lp->mii_if.advertising & ADVERTISE_10FULL)
946 printf("10Mbps Full-Duplex\n");
947 else if (lp->mii_if.advertising & ADVERTISE_10HALF)
948 printf("10Mbps Half-Duplex\n");
952 /* The older chips are fixed 10Mbps, and some support full duplex,
953 * although not via autonegotiation, but only via configuration. */
955 printf("10Mbps Full-Duplex\n");
957 printf("10Mbps Half-Duplex\n");
960 nic->nic_op = &pcnet32_operations;
964 static int mdio_read(struct nic *nic __unused, int phy_id, int reg_num)
972 phyaddr = lp->a.read_bcr(ioaddr, 33);
974 lp->a.write_bcr(ioaddr, 33,
975 ((phy_id & 0x1f) << 5) | (reg_num & 0x1f));
976 val_out = lp->a.read_bcr(ioaddr, 34);
977 lp->a.write_bcr(ioaddr, 33, phyaddr);
983 static void mdio_write(struct nic *nic __unused, int phy_id, int reg_num,
991 phyaddr = lp->a.read_bcr(ioaddr, 33);
993 lp->a.write_bcr(ioaddr, 33,
994 ((phy_id & 0x1f) << 5) | (reg_num & 0x1f));
995 lp->a.write_bcr(ioaddr, 34, val);
996 lp->a.write_bcr(ioaddr, 33, phyaddr);
1000 static struct nic_operations pcnet32_operations = {
1001 .connect = dummy_connect,
1002 .poll = pcnet32_poll,
1003 .transmit = pcnet32_transmit,
1008 static struct pci_device_id pcnet32_nics[] = {
1009 PCI_ROM(0x1022, 0x2000, "pcnet32", "AMD PCnet/PCI", 0),
1010 PCI_ROM(0x1022, 0x2625, "pcnetfastiii", "AMD PCNet FAST III", 0),
1011 PCI_ROM(0x1022, 0x2001, "amdhomepna", "AMD PCnet/HomePNA", 0),
1014 PCI_DRIVER ( pcnet32_driver, pcnet32_nics, PCI_NO_CLASS );
1016 DRIVER ( "PCNET32/PCI", nic_driver, pci_driver, pcnet32_driver,
1017 pcnet32_probe, pcnet32_disable );