Warnings purge of drivers (continued)
[gpxe.git] / src / drivers / net / pcnet32.c
blob0328cf2c3f032be145f1e68a99b2a82a01b45b12
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
32 * REVISION HISTORY:
33 * ================
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"
43 #include "nic.h"
44 #include <gpxe/pci.h>
45 #include <gpxe/ethernet.h>
46 #include "timer.h"
47 #include "mii.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;
58 #ifdef EDEBUG
59 #define dprintf(x) printf x
60 #else
61 #define dprintf(x)
62 #endif
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 */ ;
72 #ifdef REMOVE
73 /* FIXME: Remove these they are probably pointless */
75 /*
76 * VLB I/O addresses
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;
89 #endif
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
149 #endif
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 {
177 u32 base;
178 s16 buf_length;
179 s16 status;
180 u32 msg_length;
181 u32 reserved;
184 struct pcnet32_tx_head {
185 u32 base;
186 s16 length;
187 s16 status;
188 u32 misc;
189 u32 reserved;
192 /* The PCNET32 32-Bit initialization block, described in databook. */
193 struct pcnet32_init_block {
194 u16 mode;
195 u16 tlen_rlen;
196 u8 phys_addr[6];
197 u16 reserved;
198 u32 filter[2];
199 /* Receive and transmit ring base, along with extra bits. */
200 u32 rx_ring;
201 u32 tx_ring;
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 */
215 struct {
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 */
225 struct mii_if_info {
226 int phy_id;
227 int advertising;
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().
235 #define MII_CNT 4
236 struct pcnet32_private {
237 struct pcnet32_init_block init_block;
238 struct pci_dev *pci_dev; /* Pointer to the associated pci device structure */
239 const char *name;
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 */
245 char tx_full;
246 int options;
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;
254 int full_duplex:1;
255 } lpx;
257 static struct pcnet32_private *lp;
259 static int mdio_read(struct nic *nic __unused, int phy_id, int reg_num);
260 #if 0
261 static void mdio_write(struct nic *nic __unused, int phy_id, int reg_num,
262 int val);
263 #endif
264 enum pci_flags_bit {
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)
385 int i;
387 lp->tx_full = 0;
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]);
411 return 0;
414 /**************************************************************************
415 RESET - Reset adapter
416 ***************************************************************************/
417 static void pcnet32_reset(struct nic *nic)
419 /* put the card in its initial state */
420 u16 val;
421 int i;
423 /* Reset the PCNET32 */
424 lp->a.reset(ioaddr);
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)
432 val |= 2;
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) {
439 val |= 1;
440 if (lp->options ==
441 (PCNET32_PORT_FD | PCNET32_PORT_AUI))
442 val |= 2;
443 } else if (lp->options & PCNET32_PORT_ASEL) {
444 /* workaround of xSeries250, turn on for 79C975 only */
445 i = ((lp->a.
446 read_csr(ioaddr,
447 88) | (lp->a.read_csr(ioaddr,
448 89) << 16)) >>
449 12) & 0xffff;
450 if (i == 0x2627)
451 val |= 3;
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)
459 val |= 0x10;
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)
465 val |= 0x10;
466 if (lp->options & PCNET32_PORT_100)
467 val |= 0x08;
468 lp->a.write_bcr(ioaddr, 32, val);
469 } else {
470 if (lp->options & PCNET32_PORT_ASEL) { /* enable auto negotiate, setup, disable fd */
471 val = lp->a.read_bcr(ioaddr, 32) & ~0x98;
472 val |= 0x20;
473 lp->a.write_bcr(ioaddr, 32, val);
477 #ifdef DO_DXSUFLO
478 if (lp->dxsuflo) { /* Disable transmit stop on underflow */
479 val = lp->a.read_csr(ioaddr, 3);
480 val |= 0x40;
481 lp->a.write_csr(ioaddr, 3, val);
483 #endif
484 if (1)
486 //disable interrupts
487 val = lp->a.read_csr(ioaddr, 3);
488 val = val
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);
500 val |= (1 << 14);
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);
519 i = 0;
520 while (i++ < 100)
521 if (lp->a.read_csr(ioaddr, 0) & 0x0100)
522 break;
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 */
542 signed char status;
543 int entry;
545 entry = lp->cur_rx & RX_RING_MOD_MASK;
546 status = (le16_to_cpu(pcnet32_bufs.rx_ring[entry].status) >> 8);
548 if (status < 0)
549 return 0;
551 if ( ! retrieve ) return 1;
553 if (status == 0x03) {
554 nic->packetlen =
555 (le32_to_cpu(pcnet32_bufs.rx_ring[entry].msg_length)
556 & 0xfff) - 4;
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 */
566 lp->cur_rx++;
568 } else {
569 return 0;
572 return 1;
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 */
581 const char *p)
582 { /* Packet */
583 /* send the packet to destination */
584 unsigned long time;
585 u8 *ptxb;
586 u16 nstype;
587 u16 status;
588 int entry = 0; /*lp->cur_tx & TX_RING_MOD_MASK; */
590 status = 0x8300;
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);
601 s += ETH_HLEN;
602 while (s < ETH_ZLEN) /* pad to min length */
603 ptxb[s++] = '\0';
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)
650 switch ( action ) {
651 case DISABLE :
652 break;
653 case ENABLE :
654 break;
655 case FORCE :
656 break;
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 ) {
667 int i, media;
668 int fdx, mii, fset, dxsuflo, ltint;
669 int chip_version;
670 struct pcnet32_access *a = NULL;
671 char *chipname;
672 u8 promaddr[6];
673 int shared = 1;
675 if (pci->ioaddr == 0)
676 return 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);
683 nic->irqno = 0;
684 pci_fill_nic ( nic, pci );
685 nic->ioaddr = pci->ioaddr & ~3;
687 /* reset the chip */
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)) {
693 a = &pcnet32_wio;
694 } else {
695 pcnet32_dwio_reset(ioaddr);
696 if (pcnet32_dwio_read_csr(ioaddr, 0) == 4
697 && pcnet32_dwio_check(ioaddr)) {
698 a = &pcnet32_dwio;
699 } else
700 return 0;
703 chip_version =
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)
708 return 0;
710 /* initialize variables */
711 fdx = mii = fset = dxsuflo = ltint = 0;
712 chip_version = (chip_version >> 12) & 0xffff;
714 switch (chip_version) {
715 case 0x2420:
716 chipname = "PCnet/PCI 79C970"; /* PCI */
717 break;
718 case 0x2430:
719 if (shared)
720 chipname = "PCnet/PCI 79C970"; /* 970 gives the wrong chip id back */
721 else
722 chipname = "PCnet/32 79C965"; /* 486/VL bus */
723 break;
724 case 0x2621:
725 chipname = "PCnet/PCI II 79C970A"; /* PCI */
726 fdx = 1;
727 break;
728 case 0x2623:
729 chipname = "PCnet/FAST 79C971"; /* PCI */
730 fdx = 1;
731 mii = 1;
732 fset = 1;
733 ltint = 1;
734 break;
735 case 0x2624:
736 chipname = "PCnet/FAST+ 79C972"; /* PCI */
737 fdx = 1;
738 mii = 1;
739 fset = 1;
740 break;
741 case 0x2625:
742 chipname = "PCnet/FAST III 79C973"; /* PCI */
743 fdx = 1;
744 mii = 1;
745 break;
746 case 0x2626:
747 chipname = "PCnet/Home 79C978"; /* PCI */
748 fdx = 1;
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);
761 break;
762 case 0x2627:
763 chipname = "PCnet/FAST III 79C975"; /* PCI */
764 fdx = 1;
765 mii = 1;
766 break;
767 default:
768 chipname = "UNKNOWN";
769 printf("PCnet version %#x, no PCnet32 chip.\n",
770 chip_version);
771 return 0;
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.
781 if (fset) {
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);
786 dxsuflo = 1;
787 ltint = 1;
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 */
809 lp = &lpx;
811 #if EBDEBUG
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));
815 switch (i >> 10) {
816 case 0:
817 dprintf((" 20 bytes,"));
818 break;
819 case 1:
820 dprintf((" 64 bytes,"));
821 break;
822 case 2:
823 dprintf((" 128 bytes,"));
824 break;
825 case 3:
826 dprintf(("~220 bytes,"));
827 break;
829 i = a->read_bcr(ioaddr, 18); /* Check Burst/Bus control */
830 dprintf((" BCR18(%hX):", i & 0xffff));
831 if (i & (1 << 5))
832 dprintf(("BurstWrEn "));
833 if (i & (1 << 6))
834 dprintf(("BurstRdEn "));
835 if (i & (1 << 7))
836 dprintf(("DWordIO "));
837 if (i & (1 << 11))
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);
844 if (i & (1 << 14))
845 dprintf(("LowLatRx"));
847 #endif
848 lp->name = chipname;
849 lp->shared_irq = shared;
850 lp->full_duplex = fdx;
851 lp->dxsuflo = dxsuflo;
852 lp->ltint = ltint;
853 lp->mii = mii;
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;
858 else
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;
865 if (!a) {
866 printf("No access methods\n");
867 return 0;
870 // lp->a = *a;
871 // Causes a loader:
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
875 // So we do:
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
903 * boards will work.
905 /* Trigger an initialization just for the interrupt. */
908 // a->write_csr(ioaddr, 0, 0x41);
909 // mdelay(1);
911 cards_found++;
913 /* point to NIC specific routines */
914 pcnet32_reset(nic);
915 if (mii) {
916 int tmp;
917 int phy, phy_idx = 0;
918 u16 mii_lpa;
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) {
927 tmp = phy;
928 dprintf (("MII PHY found at address %d, status "
929 "%hX advertising %hX\n", phy, mii_status,
930 lp->mii_if.advertising));
934 if (phy_idx == 0)
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");
951 else
952 printf("\n");
953 } else {
954 /* The older chips are fixed 10Mbps, and some support full duplex,
955 * although not via autonegotiation, but only via configuration. */
956 if (fdx)
957 printf("10Mbps Full-Duplex\n");
958 else
959 printf("10Mbps Half-Duplex\n");
962 nic->nic_op = &pcnet32_operations;
964 return 1;
966 static int mdio_read(struct nic *nic __unused, int phy_id, int reg_num)
968 u16 val_out;
969 int phyaddr;
971 if (!lp->mii)
972 return 0;
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);
981 return val_out;
984 #if 0
985 static void mdio_write(struct nic *nic __unused, int phy_id, int reg_num,
986 int val)
988 int phyaddr;
990 if (!lp->mii)
991 return;
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);
1000 #endif
1002 static struct nic_operations pcnet32_operations = {
1003 .connect = dummy_connect,
1004 .poll = pcnet32_poll,
1005 .transmit = pcnet32_transmit,
1006 .irq = pcnet32_irq,
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 );