00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 FILE_LICENCE ( GPL2_OR_LATER );
00043
00044 #include "etherboot.h"
00045 #include "nic.h"
00046 #include <gpxe/pci.h>
00047 #include <gpxe/ethernet.h>
00048 #include "mii.h"
00049
00050
00051
00052
00053 #define drv_version "v1.3"
00054 #define drv_date "03-29-2004"
00055
00056 static u32 ioaddr;
00057 static struct nic_operations pcnet32_operations;
00058
00059 #ifdef EDEBUG
00060 #define dprintf(x) printf x
00061 #else
00062 #define dprintf(x)
00063 #endif
00064
00065
00066 #define virt_to_le32desc(addr) cpu_to_le32(virt_to_bus(addr))
00067 #define le32desc_to_virt(addr) bus_to_virt(le32_to_cpu(addr))
00068
00069
00070
00071 static int cards_found = 0 ;
00072
00073 #ifdef REMOVE
00074
00075
00076
00077
00078
00079 static unsigned int pcnet32_portlist[] =
00080 { 0x300, 0x320, 0x340, 0x360, 0 };
00081
00082 static int pcnet32_debug = 1;
00083 static int tx_start = 1;
00084 static int pcnet32vlb;
00085
00086 static struct net_device *pcnet32_dev;
00087
00088 static int max_interrupt_work = 80;
00089 static int rx_copybreak = 200;
00090 #endif
00091 #define PCNET32_PORT_AUI 0x00
00092 #define PCNET32_PORT_10BT 0x01
00093 #define PCNET32_PORT_GPSI 0x02
00094 #define PCNET32_PORT_MII 0x03
00095
00096 #define PCNET32_PORT_PORTSEL 0x03
00097 #define PCNET32_PORT_ASEL 0x04
00098 #define PCNET32_PORT_100 0x40
00099 #define PCNET32_PORT_FD 0x80
00100
00101 #define PCNET32_DMA_MASK 0xffffffff
00102
00103
00104
00105
00106
00107 static unsigned char options_mapping[] = {
00108 PCNET32_PORT_ASEL,
00109 PCNET32_PORT_AUI,
00110 PCNET32_PORT_AUI,
00111 PCNET32_PORT_ASEL,
00112 PCNET32_PORT_10BT | PCNET32_PORT_FD,
00113 PCNET32_PORT_ASEL,
00114 PCNET32_PORT_ASEL,
00115 PCNET32_PORT_ASEL,
00116 PCNET32_PORT_ASEL,
00117 PCNET32_PORT_MII,
00118 PCNET32_PORT_MII | PCNET32_PORT_FD,
00119 PCNET32_PORT_MII,
00120 PCNET32_PORT_10BT,
00121 PCNET32_PORT_MII | PCNET32_PORT_100,
00122 PCNET32_PORT_MII | PCNET32_PORT_100 | PCNET32_PORT_FD,
00123 PCNET32_PORT_ASEL
00124 };
00125
00126 #define MAX_UNITS 8
00127 static int options[MAX_UNITS];
00128 static int full_duplex[MAX_UNITS];
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147 #ifndef PCNET32_LOG_TX_BUFFERS
00148 #define PCNET32_LOG_TX_BUFFERS 1
00149 #define PCNET32_LOG_RX_BUFFERS 2
00150 #endif
00151
00152 #define TX_RING_SIZE (1 << (PCNET32_LOG_TX_BUFFERS))
00153 #define TX_RING_MOD_MASK (TX_RING_SIZE - 1)
00154
00155 #define TX_RING_LEN_BITS 0x0000
00156
00157 #define RX_RING_SIZE (1 << (PCNET32_LOG_RX_BUFFERS))
00158 #define RX_RING_MOD_MASK (RX_RING_SIZE - 1)
00159 #define RX_RING_LEN_BITS ((PCNET32_LOG_RX_BUFFERS) << 4)
00160
00161 #define PKT_BUF_SZ 1544
00162
00163
00164 #define PCNET32_WIO_RDP 0x10
00165 #define PCNET32_WIO_RAP 0x12
00166 #define PCNET32_WIO_RESET 0x14
00167 #define PCNET32_WIO_BDP 0x16
00168
00169 #define PCNET32_DWIO_RDP 0x10
00170 #define PCNET32_DWIO_RAP 0x14
00171 #define PCNET32_DWIO_RESET 0x18
00172 #define PCNET32_DWIO_BDP 0x1C
00173
00174 #define PCNET32_TOTAL_SIZE 0x20
00175
00176
00177 struct pcnet32_rx_head {
00178 u32 base;
00179 s16 buf_length;
00180 s16 status;
00181 u32 msg_length;
00182 u32 reserved;
00183 };
00184
00185 struct pcnet32_tx_head {
00186 u32 base;
00187 s16 length;
00188 s16 status;
00189 u32 misc;
00190 u32 reserved;
00191 };
00192
00193
00194 struct pcnet32_init_block {
00195 u16 mode;
00196 u16 tlen_rlen;
00197 u8 phys_addr[6];
00198 u16 reserved;
00199 u32 filter[2];
00200
00201 u32 rx_ring;
00202 u32 tx_ring;
00203 };
00204
00205 struct pcnet32_access {
00206 u16(*read_csr) (unsigned long, int);
00207 void (*write_csr) (unsigned long, int, u16);
00208 u16(*read_bcr) (unsigned long, int);
00209 void (*write_bcr) (unsigned long, int, u16);
00210 u16(*read_rap) (unsigned long);
00211 void (*write_rap) (unsigned long, u16);
00212 void (*reset) (unsigned long);
00213 };
00214
00215
00216 struct {
00217 struct pcnet32_tx_head tx_ring[TX_RING_SIZE]
00218 __attribute__ ((aligned(16)));
00219 struct pcnet32_rx_head rx_ring[RX_RING_SIZE]
00220 __attribute__ ((aligned(16)));
00221 unsigned char txb[TX_RING_SIZE][PKT_BUF_SZ];
00222 unsigned char rxb[RX_RING_SIZE][PKT_BUF_SZ];
00223 } pcnet32_bufs __shared;
00224
00225
00226
00227
00228
00229
00230 #define MII_CNT 4
00231 struct pcnet32_private {
00232 struct pcnet32_init_block init_block;
00233 struct pci_dev *pci_dev;
00234 const char *name;
00235
00236 struct sk_buff *tx_skbuff[TX_RING_SIZE];
00237 struct sk_buff *rx_skbuff[RX_RING_SIZE];
00238 struct pcnet32_access a;
00239 unsigned int cur_rx, cur_tx;
00240 char tx_full;
00241 int options;
00242 int shared_irq:1,
00243 ltint:1,
00244 dxsuflo:1,
00245 mii:1;
00246 struct mii_if_info mii_if;
00247 unsigned char phys[MII_CNT];
00248 struct net_device *next;
00249 int full_duplex:1;
00250 } lpx;
00251
00252 static struct pcnet32_private *lp;
00253
00254 static int mdio_read(struct nic *nic __unused, int phy_id, int reg_num);
00255 #if 0
00256 static void mdio_write(struct nic *nic __unused, int phy_id, int reg_num,
00257 int val);
00258 #endif
00259 enum pci_flags_bit {
00260 PCI_USES_IO = 1, PCI_USES_MEM = 2, PCI_USES_MASTER = 4,
00261 PCI_ADDR0 = 0x10 << 0, PCI_ADDR1 = 0x10 << 1, PCI_ADDR2 =
00262 0x10 << 2, PCI_ADDR3 = 0x10 << 3,
00263 };
00264
00265
00266 static u16 pcnet32_wio_read_csr(unsigned long addr, int index)
00267 {
00268 outw(index, addr + PCNET32_WIO_RAP);
00269 return inw(addr + PCNET32_WIO_RDP);
00270 }
00271
00272 static void pcnet32_wio_write_csr(unsigned long addr, int index, u16 val)
00273 {
00274 outw(index, addr + PCNET32_WIO_RAP);
00275 outw(val, addr + PCNET32_WIO_RDP);
00276 }
00277
00278 static u16 pcnet32_wio_read_bcr(unsigned long addr, int index)
00279 {
00280 outw(index, addr + PCNET32_WIO_RAP);
00281 return inw(addr + PCNET32_WIO_BDP);
00282 }
00283
00284 static void pcnet32_wio_write_bcr(unsigned long addr, int index, u16 val)
00285 {
00286 outw(index, addr + PCNET32_WIO_RAP);
00287 outw(val, addr + PCNET32_WIO_BDP);
00288 }
00289
00290 static u16 pcnet32_wio_read_rap(unsigned long addr)
00291 {
00292 return inw(addr + PCNET32_WIO_RAP);
00293 }
00294
00295 static void pcnet32_wio_write_rap(unsigned long addr, u16 val)
00296 {
00297 outw(val, addr + PCNET32_WIO_RAP);
00298 }
00299
00300 static void pcnet32_wio_reset(unsigned long addr)
00301 {
00302 inw(addr + PCNET32_WIO_RESET);
00303 }
00304
00305 static int pcnet32_wio_check(unsigned long addr)
00306 {
00307 outw(88, addr + PCNET32_WIO_RAP);
00308 return (inw(addr + PCNET32_WIO_RAP) == 88);
00309 }
00310
00311 static struct pcnet32_access pcnet32_wio = {
00312 read_csr:pcnet32_wio_read_csr,
00313 write_csr:pcnet32_wio_write_csr,
00314 read_bcr:pcnet32_wio_read_bcr,
00315 write_bcr:pcnet32_wio_write_bcr,
00316 read_rap:pcnet32_wio_read_rap,
00317 write_rap:pcnet32_wio_write_rap,
00318 reset:pcnet32_wio_reset
00319 };
00320
00321 static u16 pcnet32_dwio_read_csr(unsigned long addr, int index)
00322 {
00323 outl(index, addr + PCNET32_DWIO_RAP);
00324 return (inl(addr + PCNET32_DWIO_RDP) & 0xffff);
00325 }
00326
00327 static void pcnet32_dwio_write_csr(unsigned long addr, int index, u16 val)
00328 {
00329 outl(index, addr + PCNET32_DWIO_RAP);
00330 outl(val, addr + PCNET32_DWIO_RDP);
00331 }
00332
00333 static u16 pcnet32_dwio_read_bcr(unsigned long addr, int index)
00334 {
00335 outl(index, addr + PCNET32_DWIO_RAP);
00336 return (inl(addr + PCNET32_DWIO_BDP) & 0xffff);
00337 }
00338
00339 static void pcnet32_dwio_write_bcr(unsigned long addr, int index, u16 val)
00340 {
00341 outl(index, addr + PCNET32_DWIO_RAP);
00342 outl(val, addr + PCNET32_DWIO_BDP);
00343 }
00344
00345 static u16 pcnet32_dwio_read_rap(unsigned long addr)
00346 {
00347 return (inl(addr + PCNET32_DWIO_RAP) & 0xffff);
00348 }
00349
00350 static void pcnet32_dwio_write_rap(unsigned long addr, u16 val)
00351 {
00352 outl(val, addr + PCNET32_DWIO_RAP);
00353 }
00354
00355 static void pcnet32_dwio_reset(unsigned long addr)
00356 {
00357 inl(addr + PCNET32_DWIO_RESET);
00358 }
00359
00360 static int pcnet32_dwio_check(unsigned long addr)
00361 {
00362 outl(88, addr + PCNET32_DWIO_RAP);
00363 return ((inl(addr + PCNET32_DWIO_RAP) & 0xffff) == 88);
00364 }
00365
00366 static struct pcnet32_access pcnet32_dwio = {
00367 read_csr:pcnet32_dwio_read_csr,
00368 write_csr:pcnet32_dwio_write_csr,
00369 read_bcr:pcnet32_dwio_read_bcr,
00370 write_bcr:pcnet32_dwio_write_bcr,
00371 read_rap:pcnet32_dwio_read_rap,
00372 write_rap:pcnet32_dwio_write_rap,
00373 reset:pcnet32_dwio_reset
00374 };
00375
00376
00377
00378 static int pcnet32_init_ring(struct nic *nic)
00379 {
00380 int i;
00381
00382 lp->tx_full = 0;
00383 lp->cur_rx = lp->cur_tx = 0;
00384
00385 for (i = 0; i < RX_RING_SIZE; i++) {
00386 pcnet32_bufs.rx_ring[i].base =
00387 virt_to_le32desc(&pcnet32_bufs.rxb[i]);
00388 pcnet32_bufs.rx_ring[i].buf_length = le16_to_cpu(-PKT_BUF_SZ);
00389 pcnet32_bufs.rx_ring[i].status = le16_to_cpu(0x8000);
00390 }
00391
00392
00393
00394 for (i = 0; i < TX_RING_SIZE; i++) {
00395 pcnet32_bufs.tx_ring[i].base = 0;
00396 pcnet32_bufs.tx_ring[i].status = 0;
00397 }
00398
00399
00400 lp->init_block.tlen_rlen =
00401 le16_to_cpu(TX_RING_LEN_BITS | RX_RING_LEN_BITS);
00402 for (i = 0; i < 6; i++)
00403 lp->init_block.phys_addr[i] = nic->node_addr[i];
00404 lp->init_block.rx_ring = virt_to_le32desc(&pcnet32_bufs.rx_ring[0]);
00405 lp->init_block.tx_ring = virt_to_le32desc(&pcnet32_bufs.tx_ring[0]);
00406 return 0;
00407 }
00408
00409
00410
00411
00412 static void pcnet32_reset(struct nic *nic)
00413 {
00414
00415 u16 val;
00416 int i;
00417
00418
00419 lp->a.reset(ioaddr);
00420
00421
00422 lp->a.write_bcr(ioaddr, 20, 2);
00423
00424
00425 val = lp->a.read_bcr(ioaddr, 2) & ~2;
00426 if (lp->options & PCNET32_PORT_ASEL)
00427 val |= 2;
00428 lp->a.write_bcr(ioaddr, 2, val);
00429
00430
00431 if (lp->full_duplex) {
00432 val = lp->a.read_bcr(ioaddr, 9) & ~3;
00433 if (lp->options & PCNET32_PORT_FD) {
00434 val |= 1;
00435 if (lp->options ==
00436 (PCNET32_PORT_FD | PCNET32_PORT_AUI))
00437 val |= 2;
00438 } else if (lp->options & PCNET32_PORT_ASEL) {
00439
00440 i = ((lp->a.
00441 read_csr(ioaddr,
00442 88) | (lp->a.read_csr(ioaddr,
00443 89) << 16)) >>
00444 12) & 0xffff;
00445 if (i == 0x2627)
00446 val |= 3;
00447 }
00448 lp->a.write_bcr(ioaddr, 9, val);
00449 }
00450
00451
00452 val = lp->a.read_csr(ioaddr, 124) & ~0x10;
00453 if ((lp->options & PCNET32_PORT_PORTSEL) == PCNET32_PORT_GPSI)
00454 val |= 0x10;
00455 lp->a.write_csr(ioaddr, 124, val);
00456
00457 if (lp->mii && !(lp->options & PCNET32_PORT_ASEL)) {
00458 val = lp->a.read_bcr(ioaddr, 32) & ~0x38;
00459 if (lp->options & PCNET32_PORT_FD)
00460 val |= 0x10;
00461 if (lp->options & PCNET32_PORT_100)
00462 val |= 0x08;
00463 lp->a.write_bcr(ioaddr, 32, val);
00464 } else {
00465 if (lp->options & PCNET32_PORT_ASEL) {
00466 val = lp->a.read_bcr(ioaddr, 32) & ~0x98;
00467 val |= 0x20;
00468 lp->a.write_bcr(ioaddr, 32, val);
00469 }
00470 }
00471
00472 #ifdef DO_DXSUFLO
00473 if (lp->dxsuflo) {
00474 val = lp->a.read_csr(ioaddr, 3);
00475 val |= 0x40;
00476 lp->a.write_csr(ioaddr, 3, val);
00477 }
00478 #endif
00479 if (1)
00480 {
00481
00482 val = lp->a.read_csr(ioaddr, 3);
00483 val = val
00484 | (1 << 14)
00485 | (1 << 12)
00486 | (1 << 10)
00487 | (1 << 9)
00488 | (1 << 8)
00489 ;
00490 lp->a.write_csr(ioaddr, 3, val);
00491 }
00492
00493 if (lp->ltint) {
00494 val = lp->a.read_csr(ioaddr, 5);
00495 val |= (1 << 14);
00496 lp->a.write_csr(ioaddr, 5, val);
00497 }
00498 lp->init_block.mode =
00499 le16_to_cpu((lp->options & PCNET32_PORT_PORTSEL) << 7);
00500 lp->init_block.filter[0] = 0xffffffff;
00501 lp->init_block.filter[1] = 0xffffffff;
00502
00503 pcnet32_init_ring(nic);
00504
00505
00506
00507 lp->a.write_csr(ioaddr, 1,
00508 (virt_to_bus(&lp->init_block)) & 0xffff);
00509 lp->a.write_csr(ioaddr, 2, (virt_to_bus(&lp->init_block)) >> 16);
00510 lp->a.write_csr(ioaddr, 4, 0x0915);
00511 lp->a.write_csr(ioaddr, 0, 0x0001);
00512
00513
00514 i = 0;
00515 while (i++ < 100)
00516 if (lp->a.read_csr(ioaddr, 0) & 0x0100)
00517 break;
00518
00519
00520
00521
00522 lp->a.write_csr(ioaddr, 0, 0x0042);
00523
00524 dprintf(("pcnet32 open, csr0 %hX.\n", lp->a.read_csr(ioaddr, 0)));
00525
00526 }
00527
00528
00529
00530
00531 static int pcnet32_poll(struct nic *nic __unused, int retrieve)
00532 {
00533
00534
00535
00536
00537 signed char status;
00538 int entry;
00539
00540 entry = lp->cur_rx & RX_RING_MOD_MASK;
00541 status = (le16_to_cpu(pcnet32_bufs.rx_ring[entry].status) >> 8);
00542
00543 if (status < 0)
00544 return 0;
00545
00546 if ( ! retrieve ) return 1;
00547
00548 if (status == 0x03) {
00549 nic->packetlen =
00550 (le32_to_cpu(pcnet32_bufs.rx_ring[entry].msg_length)
00551 & 0xfff) - 4;
00552 memcpy(nic->packet, &pcnet32_bufs.rxb[entry], nic->packetlen);
00553
00554
00555
00556 pcnet32_bufs.rx_ring[entry].buf_length
00557 = le16_to_cpu(-PKT_BUF_SZ);
00558
00559 pcnet32_bufs.rx_ring[entry].status |= le16_to_cpu(0x8000);
00560
00561 lp->cur_rx++;
00562
00563 } else {
00564 return 0;
00565 }
00566
00567 return 1;
00568 }
00569
00570
00571
00572
00573 static void pcnet32_transmit(struct nic *nic __unused, const char *d,
00574 unsigned int t,
00575 unsigned int s,
00576 const char *p)
00577 {
00578
00579 unsigned long time;
00580 u8 *ptxb;
00581 u16 nstype;
00582 u16 status;
00583 int entry = 0;
00584
00585 status = 0x8300;
00586
00587 ptxb = pcnet32_bufs.txb[lp->cur_tx];
00588
00589
00590 memcpy(ptxb, d, ETH_ALEN);
00591 memcpy(ptxb + ETH_ALEN, nic->node_addr, ETH_ALEN);
00592 nstype = htons((u16) t);
00593 memcpy(ptxb + 2 * ETH_ALEN, (u8 *) & nstype, 2);
00594 memcpy(ptxb + ETH_HLEN, p, s);
00595
00596 s += ETH_HLEN;
00597 while (s < ETH_ZLEN)
00598 ptxb[s++] = '\0';
00599
00600 pcnet32_bufs.tx_ring[entry].length = le16_to_cpu(-s);
00601 pcnet32_bufs.tx_ring[entry].misc = 0x00000000;
00602 pcnet32_bufs.tx_ring[entry].base = (u32) virt_to_le32desc(ptxb);
00603
00604
00605 pcnet32_bufs.tx_ring[entry].status = le16_to_cpu(status);
00606
00607
00608
00609 lp->a.write_csr(ioaddr, 0, 0x0048);
00610
00611
00612 lp->cur_tx = 0;
00613 time = currticks() + TICKS_PER_SEC;
00614 while (currticks() < time &&
00615 ((short) le16_to_cpu(pcnet32_bufs.tx_ring[entry].status) < 0));
00616
00617 if ((short) le16_to_cpu(pcnet32_bufs.tx_ring[entry].status) < 0)
00618 printf("PCNET32 timed out on transmit\n");
00619
00620
00621
00622 pcnet32_bufs.tx_ring[entry].base = 0;
00623
00624 }
00625
00626
00627
00628
00629 static void pcnet32_disable ( struct nic *nic __unused ) {
00630
00631 lp->a.write_csr(ioaddr, 0, 0x0004);
00632
00633
00634
00635
00636
00637 lp->a.write_bcr(ioaddr, 20, 0);
00638 }
00639
00640
00641
00642
00643 static void pcnet32_irq(struct nic *nic __unused, irq_action_t action __unused)
00644 {
00645 switch ( action ) {
00646 case DISABLE :
00647 break;
00648 case ENABLE :
00649 break;
00650 case FORCE :
00651 break;
00652 }
00653 }
00654
00655
00656
00657
00658
00659
00660 static int pcnet32_probe ( struct nic *nic, struct pci_device *pci ) {
00661
00662 int i, media;
00663 int fdx, mii, fset, dxsuflo, ltint;
00664 int chip_version;
00665 struct pcnet32_access *a = NULL;
00666 char *chipname;
00667 u8 promaddr[6];
00668 int shared = 1;
00669
00670 if (pci->ioaddr == 0)
00671 return 0;
00672
00673
00674 ioaddr = pci->ioaddr;
00675 printf("pcnet32.c: Found %s, Vendor=0x%hX Device=0x%hX\n",
00676 pci->driver_name, pci->vendor, pci->device);
00677
00678 nic->irqno = 0;
00679 nic->ioaddr = pci->ioaddr & ~3;
00680
00681
00682 pcnet32_wio_reset(ioaddr);
00683
00684
00685 if (pcnet32_wio_read_csr(ioaddr, 0) == 4
00686 && pcnet32_wio_check(ioaddr)) {
00687 a = &pcnet32_wio;
00688 } else {
00689 pcnet32_dwio_reset(ioaddr);
00690 if (pcnet32_dwio_read_csr(ioaddr, 0) == 4
00691 && pcnet32_dwio_check(ioaddr)) {
00692 a = &pcnet32_dwio;
00693 } else
00694 return 0;
00695 }
00696
00697 chip_version =
00698 a->read_csr(ioaddr, 88) | (a->read_csr(ioaddr, 89) << 16);
00699
00700 dprintf(("PCnet chip version is 0x%X\n", chip_version));
00701 if ((chip_version & 0xfff) != 0x003)
00702 return 0;
00703
00704
00705 fdx = mii = fset = dxsuflo = ltint = 0;
00706 chip_version = (chip_version >> 12) & 0xffff;
00707
00708 switch (chip_version) {
00709 case 0x2420:
00710 chipname = "PCnet/PCI 79C970";
00711 break;
00712 case 0x2430:
00713 if (shared)
00714 chipname = "PCnet/PCI 79C970";
00715 else
00716 chipname = "PCnet/32 79C965";
00717 break;
00718 case 0x2621:
00719 chipname = "PCnet/PCI II 79C970A";
00720 fdx = 1;
00721 break;
00722 case 0x2623:
00723 chipname = "PCnet/FAST 79C971";
00724 fdx = 1;
00725 mii = 1;
00726 fset = 1;
00727 ltint = 1;
00728 break;
00729 case 0x2624:
00730 chipname = "PCnet/FAST+ 79C972";
00731 fdx = 1;
00732 mii = 1;
00733 fset = 1;
00734 break;
00735 case 0x2625:
00736 chipname = "PCnet/FAST III 79C973";
00737 fdx = 1;
00738 mii = 1;
00739 break;
00740 case 0x2626:
00741 chipname = "PCnet/Home 79C978";
00742 fdx = 1;
00743
00744
00745
00746
00747
00748
00749
00750
00751 media = a->read_bcr(ioaddr, 49);
00752
00753 printf("media reset to %#x.\n", media);
00754 a->write_bcr(ioaddr, 49, media);
00755 break;
00756 case 0x2627:
00757 chipname = "PCnet/FAST III 79C975";
00758 fdx = 1;
00759 mii = 1;
00760 break;
00761 default:
00762 chipname = "UNKNOWN";
00763 printf("PCnet version %#x, no PCnet32 chip.\n",
00764 chip_version);
00765 return 0;
00766 }
00767
00768
00769
00770
00771
00772
00773
00774
00775 if (fset) {
00776 a->write_bcr(ioaddr, 18,
00777 (a->read_bcr(ioaddr, 18) | 0x0800));
00778 a->write_csr(ioaddr, 80,
00779 (a->read_csr(ioaddr, 80) & 0x0C00) | 0x0c00);
00780 dxsuflo = 1;
00781 ltint = 1;
00782 }
00783
00784 DBG ( "%s at %hX,", chipname, (unsigned int) ioaddr );
00785
00786
00787 for (i = 0; i < 6; i++)
00788 promaddr[i] = inb(ioaddr + i);
00789
00790
00791 for (i = 0; i < ETH_ALEN; i++) {
00792 nic->node_addr[i] = promaddr[i];
00793 }
00794
00795
00796 DBG ( "%s: IO Addr 0x%hX, MAC Addr %s\n ", chipname, (unsigned int) ioaddr,
00797 eth_ntoa ( nic->node_addr ) );
00798
00799
00800 adjust_pci_device(pci);
00801
00802
00803 lp = &lpx;
00804
00805 #if EBDEBUG
00806 if (((chip_version + 1) & 0xfffe) == 0x2624) {
00807 i = a->read_csr(ioaddr, 80) & 0x0C00;
00808 dprintf((" tx_start_pt(0x%hX):", i));
00809 switch (i >> 10) {
00810 case 0:
00811 dprintf((" 20 bytes,"));
00812 break;
00813 case 1:
00814 dprintf((" 64 bytes,"));
00815 break;
00816 case 2:
00817 dprintf((" 128 bytes,"));
00818 break;
00819 case 3:
00820 dprintf(("~220 bytes,"));
00821 break;
00822 }
00823 i = a->read_bcr(ioaddr, 18);
00824 dprintf((" BCR18(%hX):", i & 0xffff));
00825 if (i & (1 << 5))
00826 dprintf(("BurstWrEn "));
00827 if (i & (1 << 6))
00828 dprintf(("BurstRdEn "));
00829 if (i & (1 << 7))
00830 dprintf(("DWordIO "));
00831 if (i & (1 << 11))
00832 dprintf(("NoUFlow "));
00833 i = a->read_bcr(ioaddr, 25);
00834 dprintf((" SRAMSIZE=0x%hX,", i << 8));
00835 i = a->read_bcr(ioaddr, 26);
00836 dprintf((" SRAM_BND=0x%hX,", i << 8));
00837 i = a->read_bcr(ioaddr, 27);
00838 if (i & (1 << 14))
00839 dprintf(("LowLatRx"));
00840 }
00841 #endif
00842 lp->name = chipname;
00843 lp->shared_irq = shared;
00844 lp->full_duplex = fdx;
00845 lp->dxsuflo = dxsuflo;
00846 lp->ltint = ltint;
00847 lp->mii = mii;
00848
00849 if ((cards_found >= MAX_UNITS)
00850 || ((unsigned int) options[cards_found] > sizeof(options_mapping)))
00851 lp->options = PCNET32_PORT_ASEL;
00852 else
00853 lp->options = options_mapping[options[cards_found]];
00854
00855 if (fdx && !(lp->options & PCNET32_PORT_ASEL) &&
00856 ((cards_found >= MAX_UNITS) || full_duplex[cards_found]))
00857 lp->options |= PCNET32_PORT_FD;
00858
00859 if (!a) {
00860 printf("No access methods\n");
00861 return 0;
00862 }
00863
00864
00865
00866
00867
00868
00869
00870 memcpy ( &lp->a, a, sizeof ( lp->a ) );
00871
00872
00873
00874 if (nic->node_addr[0] == 0x00 && nic->node_addr[1] == 0xe0
00875 && nic->node_addr[2] == 0x75)
00876 lp->options = PCNET32_PORT_FD | PCNET32_PORT_GPSI;
00877
00878 lp->init_block.mode = le16_to_cpu(0x0003);
00879 lp->init_block.tlen_rlen =
00880 le16_to_cpu(TX_RING_LEN_BITS | RX_RING_LEN_BITS);
00881 for (i = 0; i < 6; i++)
00882 lp->init_block.phys_addr[i] = nic->node_addr[i];
00883 lp->init_block.filter[0] = 0xffffffff;
00884 lp->init_block.filter[1] = 0xffffffff;
00885 lp->init_block.rx_ring = virt_to_bus(&pcnet32_bufs.rx_ring);
00886 lp->init_block.tx_ring = virt_to_bus(&pcnet32_bufs.tx_ring);
00887
00888
00889 a->write_bcr(ioaddr, 20, 2);
00890
00891 a->write_csr(ioaddr, 1, (virt_to_bus(&lp->init_block)) & 0xffff);
00892 a->write_csr(ioaddr, 2, (virt_to_bus(&lp->init_block)) >> 16);
00893
00894
00895
00896
00897
00898
00899
00900
00901
00902
00903
00904
00905 cards_found++;
00906
00907
00908 pcnet32_reset(nic);
00909 if (mii) {
00910 int tmp;
00911 int phy, phy_idx = 0;
00912 u16 mii_lpa;
00913 lp->phys[0] = 1;
00914 for (phy = 1; phy < 32 && phy_idx < MII_CNT; phy++) {
00915 int mii_status = mdio_read(nic, phy, MII_BMSR);
00916 if (mii_status != 0xffff && mii_status != 0x0000) {
00917 lp->phys[phy_idx++] = phy;
00918 lp->mii_if.advertising =
00919 mdio_read(nic, phy, MII_ADVERTISE);
00920 if ((mii_status & 0x0040) == 0) {
00921 tmp = phy;
00922 dprintf (("MII PHY found at address %d, status "
00923 "%hX advertising %hX\n", phy, mii_status,
00924 lp->mii_if.advertising));
00925 }
00926 }
00927 }
00928 if (phy_idx == 0)
00929 printf("No MII transceiver found!\n");
00930 lp->mii_if.phy_id = lp->phys[0];
00931
00932 lp->mii_if.advertising =
00933 mdio_read(nic, lp->phys[0], MII_ADVERTISE);
00934
00935 mii_lpa = mdio_read(nic, lp->phys[0], MII_LPA);
00936 lp->mii_if.advertising &= mii_lpa;
00937 if (lp->mii_if.advertising & ADVERTISE_100FULL)
00938 printf("100Mbps Full-Duplex\n");
00939 else if (lp->mii_if.advertising & ADVERTISE_100HALF)
00940 printf("100Mbps Half-Duplex\n");
00941 else if (lp->mii_if.advertising & ADVERTISE_10FULL)
00942 printf("10Mbps Full-Duplex\n");
00943 else if (lp->mii_if.advertising & ADVERTISE_10HALF)
00944 printf("10Mbps Half-Duplex\n");
00945 else
00946 printf("\n");
00947 } else {
00948
00949
00950 if (fdx)
00951 printf("10Mbps Full-Duplex\n");
00952 else
00953 printf("10Mbps Half-Duplex\n");
00954 }
00955
00956 nic->nic_op = &pcnet32_operations;
00957
00958 return 1;
00959 }
00960 static int mdio_read(struct nic *nic __unused, int phy_id, int reg_num)
00961 {
00962 u16 val_out;
00963 int phyaddr;
00964
00965 if (!lp->mii)
00966 return 0;
00967
00968 phyaddr = lp->a.read_bcr(ioaddr, 33);
00969
00970 lp->a.write_bcr(ioaddr, 33,
00971 ((phy_id & 0x1f) << 5) | (reg_num & 0x1f));
00972 val_out = lp->a.read_bcr(ioaddr, 34);
00973 lp->a.write_bcr(ioaddr, 33, phyaddr);
00974
00975 return val_out;
00976 }
00977
00978 #if 0
00979 static void mdio_write(struct nic *nic __unused, int phy_id, int reg_num,
00980 int val)
00981 {
00982 int phyaddr;
00983
00984 if (!lp->mii)
00985 return;
00986
00987 phyaddr = lp->a.read_bcr(ioaddr, 33);
00988
00989 lp->a.write_bcr(ioaddr, 33,
00990 ((phy_id & 0x1f) << 5) | (reg_num & 0x1f));
00991 lp->a.write_bcr(ioaddr, 34, val);
00992 lp->a.write_bcr(ioaddr, 33, phyaddr);
00993 }
00994 #endif
00995
00996 static struct nic_operations pcnet32_operations = {
00997 .connect = dummy_connect,
00998 .poll = pcnet32_poll,
00999 .transmit = pcnet32_transmit,
01000 .irq = pcnet32_irq,
01001
01002 };
01003
01004 static struct pci_device_id pcnet32_nics[] = {
01005 PCI_ROM(0x1022, 0x2000, "pcnet32", "AMD PCnet/PCI", 0),
01006 PCI_ROM(0x1022, 0x2625, "pcnetfastiii", "AMD PCNet FAST III", 0),
01007 PCI_ROM(0x1022, 0x2001, "amdhomepna", "AMD PCnet/HomePNA", 0),
01008 };
01009
01010 PCI_DRIVER ( pcnet32_driver, pcnet32_nics, PCI_NO_CLASS );
01011
01012 DRIVER ( "PCNET32/PCI", nic_driver, pci_driver, pcnet32_driver,
01013 pcnet32_probe, pcnet32_disable );
01014
01015
01016
01017
01018
01019
01020
01021