12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025 |
-
-
- #include "etherboot.h"
- #include "nic.h"
- #include <gpxe/pci.h>
- #include <gpxe/ethernet.h>
- #include "mii.h"
-
-
-
-
- #define drv_version "v1.3"
- #define drv_date "03-29-2004"
-
- static u32 ioaddr;
- static struct nic_operations pcnet32_operations;
-
- #ifdef EDEBUG
- #define dprintf(x) printf x
- #else
- #define dprintf(x)
- #endif
-
-
- #define virt_to_le32desc(addr) cpu_to_le32(virt_to_bus(addr))
- #define le32desc_to_virt(addr) bus_to_virt(le32_to_cpu(addr))
-
-
-
- static int cards_found = 0 ;
-
- #ifdef REMOVE
-
-
-
- static unsigned int pcnet32_portlist[] =
- { 0x300, 0x320, 0x340, 0x360, 0 };
-
- static int pcnet32_debug = 1;
- static int tx_start = 1;
- static int pcnet32vlb;
-
- static struct net_device *pcnet32_dev;
-
- static int max_interrupt_work = 80;
- static int rx_copybreak = 200;
- #endif
- #define PCNET32_PORT_AUI 0x00
- #define PCNET32_PORT_10BT 0x01
- #define PCNET32_PORT_GPSI 0x02
- #define PCNET32_PORT_MII 0x03
-
- #define PCNET32_PORT_PORTSEL 0x03
- #define PCNET32_PORT_ASEL 0x04
- #define PCNET32_PORT_100 0x40
- #define PCNET32_PORT_FD 0x80
-
- #define PCNET32_DMA_MASK 0xffffffff
-
-
- static unsigned char options_mapping[] = {
- PCNET32_PORT_ASEL,
- PCNET32_PORT_AUI,
- PCNET32_PORT_AUI,
- PCNET32_PORT_ASEL,
- PCNET32_PORT_10BT | PCNET32_PORT_FD,
- PCNET32_PORT_ASEL,
- PCNET32_PORT_ASEL,
- PCNET32_PORT_ASEL,
- PCNET32_PORT_ASEL,
- PCNET32_PORT_MII,
- PCNET32_PORT_MII | PCNET32_PORT_FD,
- PCNET32_PORT_MII,
- PCNET32_PORT_10BT,
- PCNET32_PORT_MII | PCNET32_PORT_100,
- PCNET32_PORT_MII | PCNET32_PORT_100 | PCNET32_PORT_FD,
- PCNET32_PORT_ASEL
- };
-
- #define MAX_UNITS 8
- static int options[MAX_UNITS];
- static int full_duplex[MAX_UNITS];
-
-
-
-
-
-
- #ifndef PCNET32_LOG_TX_BUFFERS
- #define PCNET32_LOG_TX_BUFFERS 1
- #define PCNET32_LOG_RX_BUFFERS 2
- #endif
-
- #define TX_RING_SIZE (1 << (PCNET32_LOG_TX_BUFFERS))
- #define TX_RING_MOD_MASK (TX_RING_SIZE - 1)
-
- #define TX_RING_LEN_BITS 0x0000
-
- #define RX_RING_SIZE (1 << (PCNET32_LOG_RX_BUFFERS))
- #define RX_RING_MOD_MASK (RX_RING_SIZE - 1)
- #define RX_RING_LEN_BITS ((PCNET32_LOG_RX_BUFFERS) << 4)
-
- #define PKT_BUF_SZ 1544
-
-
- #define PCNET32_WIO_RDP 0x10
- #define PCNET32_WIO_RAP 0x12
- #define PCNET32_WIO_RESET 0x14
- #define PCNET32_WIO_BDP 0x16
-
- #define PCNET32_DWIO_RDP 0x10
- #define PCNET32_DWIO_RAP 0x14
- #define PCNET32_DWIO_RESET 0x18
- #define PCNET32_DWIO_BDP 0x1C
-
- #define PCNET32_TOTAL_SIZE 0x20
-
-
- struct pcnet32_rx_head {
- u32 base;
- s16 buf_length;
- s16 status;
- u32 msg_length;
- u32 reserved;
- };
-
- struct pcnet32_tx_head {
- u32 base;
- s16 length;
- s16 status;
- u32 misc;
- u32 reserved;
- };
-
-
- struct pcnet32_init_block {
- u16 mode;
- u16 tlen_rlen;
- u8 phys_addr[6];
- u16 reserved;
- u32 filter[2];
-
- u32 rx_ring;
- u32 tx_ring;
- };
-
- struct pcnet32_access {
- u16(*read_csr) (unsigned long, int);
- void (*write_csr) (unsigned long, int, u16);
- u16(*read_bcr) (unsigned long, int);
- void (*write_bcr) (unsigned long, int, u16);
- u16(*read_rap) (unsigned long);
- void (*write_rap) (unsigned long, u16);
- void (*reset) (unsigned long);
- };
-
-
- struct {
- struct pcnet32_tx_head tx_ring[TX_RING_SIZE]
- __attribute__ ((aligned(16)));
- struct pcnet32_rx_head rx_ring[RX_RING_SIZE]
- __attribute__ ((aligned(16)));
- unsigned char txb[TX_RING_SIZE][PKT_BUF_SZ];
- unsigned char rxb[RX_RING_SIZE][PKT_BUF_SZ];
- } pcnet32_bufs __shared;
-
-
- struct mii_if_info {
- int phy_id;
- int advertising;
- unsigned int full_duplex:1;
- };
-
-
- #define MII_CNT 4
- struct pcnet32_private {
- struct pcnet32_init_block init_block;
- struct pci_dev *pci_dev;
- const char *name;
-
- struct sk_buff *tx_skbuff[TX_RING_SIZE];
- struct sk_buff *rx_skbuff[RX_RING_SIZE];
- struct pcnet32_access a;
- unsigned int cur_rx, cur_tx;
- char tx_full;
- int options;
- int shared_irq:1,
- ltint:1,
- dxsuflo:1,
- mii:1;
- struct mii_if_info mii_if;
- unsigned char phys[MII_CNT];
- struct net_device *next;
- int full_duplex:1;
- } lpx;
-
- static struct pcnet32_private *lp;
-
- static int mdio_read(struct nic *nic __unused, int phy_id, int reg_num);
- #if 0
- static void mdio_write(struct nic *nic __unused, int phy_id, int reg_num,
- int val);
- #endif
- enum pci_flags_bit {
- PCI_USES_IO = 1, PCI_USES_MEM = 2, PCI_USES_MASTER = 4,
- PCI_ADDR0 = 0x10 << 0, PCI_ADDR1 = 0x10 << 1, PCI_ADDR2 =
- 0x10 << 2, PCI_ADDR3 = 0x10 << 3,
- };
-
-
- static u16 pcnet32_wio_read_csr(unsigned long addr, int index)
- {
- outw(index, addr + PCNET32_WIO_RAP);
- return inw(addr + PCNET32_WIO_RDP);
- }
-
- static void pcnet32_wio_write_csr(unsigned long addr, int index, u16 val)
- {
- outw(index, addr + PCNET32_WIO_RAP);
- outw(val, addr + PCNET32_WIO_RDP);
- }
-
- static u16 pcnet32_wio_read_bcr(unsigned long addr, int index)
- {
- outw(index, addr + PCNET32_WIO_RAP);
- return inw(addr + PCNET32_WIO_BDP);
- }
-
- static void pcnet32_wio_write_bcr(unsigned long addr, int index, u16 val)
- {
- outw(index, addr + PCNET32_WIO_RAP);
- outw(val, addr + PCNET32_WIO_BDP);
- }
-
- static u16 pcnet32_wio_read_rap(unsigned long addr)
- {
- return inw(addr + PCNET32_WIO_RAP);
- }
-
- static void pcnet32_wio_write_rap(unsigned long addr, u16 val)
- {
- outw(val, addr + PCNET32_WIO_RAP);
- }
-
- static void pcnet32_wio_reset(unsigned long addr)
- {
- inw(addr + PCNET32_WIO_RESET);
- }
-
- static int pcnet32_wio_check(unsigned long addr)
- {
- outw(88, addr + PCNET32_WIO_RAP);
- return (inw(addr + PCNET32_WIO_RAP) == 88);
- }
-
- static struct pcnet32_access pcnet32_wio = {
- read_csr:pcnet32_wio_read_csr,
- write_csr:pcnet32_wio_write_csr,
- read_bcr:pcnet32_wio_read_bcr,
- write_bcr:pcnet32_wio_write_bcr,
- read_rap:pcnet32_wio_read_rap,
- write_rap:pcnet32_wio_write_rap,
- reset:pcnet32_wio_reset
- };
-
- static u16 pcnet32_dwio_read_csr(unsigned long addr, int index)
- {
- outl(index, addr + PCNET32_DWIO_RAP);
- return (inl(addr + PCNET32_DWIO_RDP) & 0xffff);
- }
-
- static void pcnet32_dwio_write_csr(unsigned long addr, int index, u16 val)
- {
- outl(index, addr + PCNET32_DWIO_RAP);
- outl(val, addr + PCNET32_DWIO_RDP);
- }
-
- static u16 pcnet32_dwio_read_bcr(unsigned long addr, int index)
- {
- outl(index, addr + PCNET32_DWIO_RAP);
- return (inl(addr + PCNET32_DWIO_BDP) & 0xffff);
- }
-
- static void pcnet32_dwio_write_bcr(unsigned long addr, int index, u16 val)
- {
- outl(index, addr + PCNET32_DWIO_RAP);
- outl(val, addr + PCNET32_DWIO_BDP);
- }
-
- static u16 pcnet32_dwio_read_rap(unsigned long addr)
- {
- return (inl(addr + PCNET32_DWIO_RAP) & 0xffff);
- }
-
- static void pcnet32_dwio_write_rap(unsigned long addr, u16 val)
- {
- outl(val, addr + PCNET32_DWIO_RAP);
- }
-
- static void pcnet32_dwio_reset(unsigned long addr)
- {
- inl(addr + PCNET32_DWIO_RESET);
- }
-
- static int pcnet32_dwio_check(unsigned long addr)
- {
- outl(88, addr + PCNET32_DWIO_RAP);
- return ((inl(addr + PCNET32_DWIO_RAP) & 0xffff) == 88);
- }
-
- static struct pcnet32_access pcnet32_dwio = {
- read_csr:pcnet32_dwio_read_csr,
- write_csr:pcnet32_dwio_write_csr,
- read_bcr:pcnet32_dwio_read_bcr,
- write_bcr:pcnet32_dwio_write_bcr,
- read_rap:pcnet32_dwio_read_rap,
- write_rap:pcnet32_dwio_write_rap,
- reset:pcnet32_dwio_reset
- };
-
-
-
- static int pcnet32_init_ring(struct nic *nic)
- {
- int i;
-
- lp->tx_full = 0;
- lp->cur_rx = lp->cur_tx = 0;
-
- for (i = 0; i < RX_RING_SIZE; i++) {
- pcnet32_bufs.rx_ring[i].base =
- virt_to_le32desc(&pcnet32_bufs.rxb[i]);
- pcnet32_bufs.rx_ring[i].buf_length = le16_to_cpu(-PKT_BUF_SZ);
- pcnet32_bufs.rx_ring[i].status = le16_to_cpu(0x8000);
- }
-
-
-
- for (i = 0; i < TX_RING_SIZE; i++) {
- pcnet32_bufs.tx_ring[i].base = 0;
- pcnet32_bufs.tx_ring[i].status = 0;
- }
-
-
- lp->init_block.tlen_rlen =
- le16_to_cpu(TX_RING_LEN_BITS | RX_RING_LEN_BITS);
- for (i = 0; i < 6; i++)
- lp->init_block.phys_addr[i] = nic->node_addr[i];
- lp->init_block.rx_ring = virt_to_le32desc(&pcnet32_bufs.rx_ring[0]);
- lp->init_block.tx_ring = virt_to_le32desc(&pcnet32_bufs.tx_ring[0]);
- return 0;
- }
-
-
- static void pcnet32_reset(struct nic *nic)
- {
-
- u16 val;
- int i;
-
-
- lp->a.reset(ioaddr);
-
-
- lp->a.write_bcr(ioaddr, 20, 2);
-
-
- val = lp->a.read_bcr(ioaddr, 2) & ~2;
- if (lp->options & PCNET32_PORT_ASEL)
- val |= 2;
- lp->a.write_bcr(ioaddr, 2, val);
-
-
- if (lp->full_duplex) {
- val = lp->a.read_bcr(ioaddr, 9) & ~3;
- if (lp->options & PCNET32_PORT_FD) {
- val |= 1;
- if (lp->options ==
- (PCNET32_PORT_FD | PCNET32_PORT_AUI))
- val |= 2;
- } else if (lp->options & PCNET32_PORT_ASEL) {
-
- i = ((lp->a.
- read_csr(ioaddr,
- 88) | (lp->a.read_csr(ioaddr,
- 89) << 16)) >>
- 12) & 0xffff;
- if (i == 0x2627)
- val |= 3;
- }
- lp->a.write_bcr(ioaddr, 9, val);
- }
-
-
- val = lp->a.read_csr(ioaddr, 124) & ~0x10;
- if ((lp->options & PCNET32_PORT_PORTSEL) == PCNET32_PORT_GPSI)
- val |= 0x10;
- lp->a.write_csr(ioaddr, 124, val);
-
- if (lp->mii && !(lp->options & PCNET32_PORT_ASEL)) {
- val = lp->a.read_bcr(ioaddr, 32) & ~0x38;
- if (lp->options & PCNET32_PORT_FD)
- val |= 0x10;
- if (lp->options & PCNET32_PORT_100)
- val |= 0x08;
- lp->a.write_bcr(ioaddr, 32, val);
- } else {
- if (lp->options & PCNET32_PORT_ASEL) {
- val = lp->a.read_bcr(ioaddr, 32) & ~0x98;
- val |= 0x20;
- lp->a.write_bcr(ioaddr, 32, val);
- }
- }
-
- #ifdef DO_DXSUFLO
- if (lp->dxsuflo) {
- val = lp->a.read_csr(ioaddr, 3);
- val |= 0x40;
- lp->a.write_csr(ioaddr, 3, val);
- }
- #endif
- if (1)
- {
-
- val = lp->a.read_csr(ioaddr, 3);
- val = val
- | (1 << 14)
- | (1 << 12)
- | (1 << 10)
- | (1 << 9)
- | (1 << 8)
- ;
- lp->a.write_csr(ioaddr, 3, val);
- }
-
- if (lp->ltint) {
- val = lp->a.read_csr(ioaddr, 5);
- val |= (1 << 14);
- lp->a.write_csr(ioaddr, 5, val);
- }
- lp->init_block.mode =
- le16_to_cpu((lp->options & PCNET32_PORT_PORTSEL) << 7);
- lp->init_block.filter[0] = 0xffffffff;
- lp->init_block.filter[1] = 0xffffffff;
-
- pcnet32_init_ring(nic);
-
-
-
- lp->a.write_csr(ioaddr, 1,
- (virt_to_bus(&lp->init_block)) & 0xffff);
- lp->a.write_csr(ioaddr, 2, (virt_to_bus(&lp->init_block)) >> 16);
- lp->a.write_csr(ioaddr, 4, 0x0915);
- lp->a.write_csr(ioaddr, 0, 0x0001);
-
-
- i = 0;
- while (i++ < 100)
- if (lp->a.read_csr(ioaddr, 0) & 0x0100)
- break;
-
-
- lp->a.write_csr(ioaddr, 0, 0x0042);
-
- dprintf(("pcnet32 open, csr0 %hX.\n", lp->a.read_csr(ioaddr, 0)));
-
- }
-
-
- static int pcnet32_poll(struct nic *nic __unused, int retrieve)
- {
-
-
-
-
- signed char status;
- int entry;
-
- entry = lp->cur_rx & RX_RING_MOD_MASK;
- status = (le16_to_cpu(pcnet32_bufs.rx_ring[entry].status) >> 8);
-
- if (status < 0)
- return 0;
-
- if ( ! retrieve ) return 1;
-
- if (status == 0x03) {
- nic->packetlen =
- (le32_to_cpu(pcnet32_bufs.rx_ring[entry].msg_length)
- & 0xfff) - 4;
- memcpy(nic->packet, &pcnet32_bufs.rxb[entry], nic->packetlen);
-
-
-
- pcnet32_bufs.rx_ring[entry].buf_length
- = le16_to_cpu(-PKT_BUF_SZ);
-
- pcnet32_bufs.rx_ring[entry].status |= le16_to_cpu(0x8000);
-
- lp->cur_rx++;
-
- } else {
- return 0;
- }
-
- return 1;
- }
-
-
- static void pcnet32_transmit(struct nic *nic __unused, const char *d,
- unsigned int t,
- unsigned int s,
- const char *p)
- {
-
- unsigned long time;
- u8 *ptxb;
- u16 nstype;
- u16 status;
- int entry = 0;
-
- status = 0x8300;
-
- ptxb = pcnet32_bufs.txb[lp->cur_tx];
-
-
- memcpy(ptxb, d, ETH_ALEN);
- memcpy(ptxb + ETH_ALEN, nic->node_addr, ETH_ALEN);
- nstype = htons((u16) t);
- memcpy(ptxb + 2 * ETH_ALEN, (u8 *) & nstype, 2);
- memcpy(ptxb + ETH_HLEN, p, s);
-
- s += ETH_HLEN;
- while (s < ETH_ZLEN)
- ptxb[s++] = '\0';
-
- pcnet32_bufs.tx_ring[entry].length = le16_to_cpu(-s);
- pcnet32_bufs.tx_ring[entry].misc = 0x00000000;
- pcnet32_bufs.tx_ring[entry].base = (u32) virt_to_le32desc(ptxb);
-
-
- pcnet32_bufs.tx_ring[entry].status = le16_to_cpu(status);
-
-
-
- lp->a.write_csr(ioaddr, 0, 0x0048);
-
-
- lp->cur_tx = 0;
- time = currticks() + TICKS_PER_SEC;
- while (currticks() < time &&
- ((short) le16_to_cpu(pcnet32_bufs.tx_ring[entry].status) < 0));
-
- if ((short) le16_to_cpu(pcnet32_bufs.tx_ring[entry].status) < 0)
- printf("PCNET32 timed out on transmit\n");
-
-
-
- pcnet32_bufs.tx_ring[entry].base = 0;
-
- }
-
-
- static void pcnet32_disable ( struct nic *nic __unused ) {
-
- lp->a.write_csr(ioaddr, 0, 0x0004);
-
-
-
- lp->a.write_bcr(ioaddr, 20, 0);
- }
-
-
- static void pcnet32_irq(struct nic *nic __unused, irq_action_t action __unused)
- {
- switch ( action ) {
- case DISABLE :
- break;
- case ENABLE :
- break;
- case FORCE :
- break;
- }
- }
-
-
-
- static int pcnet32_probe ( struct nic *nic, struct pci_device *pci ) {
-
- int i, media;
- int fdx, mii, fset, dxsuflo, ltint;
- int chip_version;
- struct pcnet32_access *a = NULL;
- char *chipname;
- u8 promaddr[6];
- int shared = 1;
-
- if (pci->ioaddr == 0)
- return 0;
-
-
- ioaddr = pci->ioaddr;
- printf("pcnet32.c: Found %s, Vendor=0x%hX Device=0x%hX\n",
- pci->driver_name, pci->vendor, pci->device);
-
- nic->irqno = 0;
- nic->ioaddr = pci->ioaddr & ~3;
-
-
- pcnet32_wio_reset(ioaddr);
-
-
- if (pcnet32_wio_read_csr(ioaddr, 0) == 4
- && pcnet32_wio_check(ioaddr)) {
- a = &pcnet32_wio;
- } else {
- pcnet32_dwio_reset(ioaddr);
- if (pcnet32_dwio_read_csr(ioaddr, 0) == 4
- && pcnet32_dwio_check(ioaddr)) {
- a = &pcnet32_dwio;
- } else
- return 0;
- }
-
- chip_version =
- a->read_csr(ioaddr, 88) | (a->read_csr(ioaddr, 89) << 16);
-
- dprintf(("PCnet chip version is 0x%X\n", chip_version));
- if ((chip_version & 0xfff) != 0x003)
- return 0;
-
-
- fdx = mii = fset = dxsuflo = ltint = 0;
- chip_version = (chip_version >> 12) & 0xffff;
-
- switch (chip_version) {
- case 0x2420:
- chipname = "PCnet/PCI 79C970";
- break;
- case 0x2430:
- if (shared)
- chipname = "PCnet/PCI 79C970";
- else
- chipname = "PCnet/32 79C965";
- break;
- case 0x2621:
- chipname = "PCnet/PCI II 79C970A";
- fdx = 1;
- break;
- case 0x2623:
- chipname = "PCnet/FAST 79C971";
- fdx = 1;
- mii = 1;
- fset = 1;
- ltint = 1;
- break;
- case 0x2624:
- chipname = "PCnet/FAST+ 79C972";
- fdx = 1;
- mii = 1;
- fset = 1;
- break;
- case 0x2625:
- chipname = "PCnet/FAST III 79C973";
- fdx = 1;
- mii = 1;
- break;
- case 0x2626:
- chipname = "PCnet/Home 79C978";
- fdx = 1;
-
-
-
- media = a->read_bcr(ioaddr, 49);
-
- printf("media reset to %#x.\n", media);
- a->write_bcr(ioaddr, 49, media);
- break;
- case 0x2627:
- chipname = "PCnet/FAST III 79C975";
- fdx = 1;
- mii = 1;
- break;
- default:
- chipname = "UNKNOWN";
- printf("PCnet version %#x, no PCnet32 chip.\n",
- chip_version);
- return 0;
- }
-
-
-
-
- if (fset) {
- a->write_bcr(ioaddr, 18,
- (a->read_bcr(ioaddr, 18) | 0x0800));
- a->write_csr(ioaddr, 80,
- (a->read_csr(ioaddr, 80) & 0x0C00) | 0x0c00);
- dxsuflo = 1;
- ltint = 1;
- }
-
- DBG ( "%s at %hX,", chipname, (unsigned int) ioaddr );
-
-
- for (i = 0; i < 6; i++)
- promaddr[i] = inb(ioaddr + i);
-
-
- for (i = 0; i < ETH_ALEN; i++) {
- nic->node_addr[i] = promaddr[i];
- }
-
-
- DBG ( "%s: IO Addr 0x%hX, MAC Addr %s\n ", chipname, (unsigned int) ioaddr,
- eth_ntoa ( nic->node_addr ) );
-
-
- adjust_pci_device(pci);
-
-
- lp = &lpx;
-
- #if EBDEBUG
- if (((chip_version + 1) & 0xfffe) == 0x2624) {
- i = a->read_csr(ioaddr, 80) & 0x0C00;
- dprintf((" tx_start_pt(0x%hX):", i));
- switch (i >> 10) {
- case 0:
- dprintf((" 20 bytes,"));
- break;
- case 1:
- dprintf((" 64 bytes,"));
- break;
- case 2:
- dprintf((" 128 bytes,"));
- break;
- case 3:
- dprintf(("~220 bytes,"));
- break;
- }
- i = a->read_bcr(ioaddr, 18);
- dprintf((" BCR18(%hX):", i & 0xffff));
- if (i & (1 << 5))
- dprintf(("BurstWrEn "));
- if (i & (1 << 6))
- dprintf(("BurstRdEn "));
- if (i & (1 << 7))
- dprintf(("DWordIO "));
- if (i & (1 << 11))
- dprintf(("NoUFlow "));
- i = a->read_bcr(ioaddr, 25);
- dprintf((" SRAMSIZE=0x%hX,", i << 8));
- i = a->read_bcr(ioaddr, 26);
- dprintf((" SRAM_BND=0x%hX,", i << 8));
- i = a->read_bcr(ioaddr, 27);
- if (i & (1 << 14))
- dprintf(("LowLatRx"));
- }
- #endif
- lp->name = chipname;
- lp->shared_irq = shared;
- lp->full_duplex = fdx;
- lp->dxsuflo = dxsuflo;
- lp->ltint = ltint;
- lp->mii = mii;
-
- if ((cards_found >= MAX_UNITS)
- || ((unsigned int) options[cards_found] > sizeof(options_mapping)))
- lp->options = PCNET32_PORT_ASEL;
- else
- lp->options = options_mapping[options[cards_found]];
-
- if (fdx && !(lp->options & PCNET32_PORT_ASEL) &&
- ((cards_found >= MAX_UNITS) || full_duplex[cards_found]))
- lp->options |= PCNET32_PORT_FD;
-
- if (!a) {
- printf("No access methods\n");
- return 0;
- }
-
-
-
-
-
-
-
- memcpy ( &lp->a, a, sizeof ( lp->a ) );
-
-
-
- if (nic->node_addr[0] == 0x00 && nic->node_addr[1] == 0xe0
- && nic->node_addr[2] == 0x75)
- lp->options = PCNET32_PORT_FD | PCNET32_PORT_GPSI;
-
- lp->init_block.mode = le16_to_cpu(0x0003);
- lp->init_block.tlen_rlen =
- le16_to_cpu(TX_RING_LEN_BITS | RX_RING_LEN_BITS);
- for (i = 0; i < 6; i++)
- lp->init_block.phys_addr[i] = nic->node_addr[i];
- lp->init_block.filter[0] = 0xffffffff;
- lp->init_block.filter[1] = 0xffffffff;
- lp->init_block.rx_ring = virt_to_bus(&pcnet32_bufs.rx_ring);
- lp->init_block.tx_ring = virt_to_bus(&pcnet32_bufs.tx_ring);
-
-
- a->write_bcr(ioaddr, 20, 2);
-
- a->write_csr(ioaddr, 1, (virt_to_bus(&lp->init_block)) & 0xffff);
- a->write_csr(ioaddr, 2, (virt_to_bus(&lp->init_block)) >> 16);
-
-
-
-
-
-
-
-
-
- cards_found++;
-
-
- pcnet32_reset(nic);
- if (mii) {
- int tmp;
- int phy, phy_idx = 0;
- u16 mii_lpa;
- lp->phys[0] = 1;
- for (phy = 1; phy < 32 && phy_idx < MII_CNT; phy++) {
- int mii_status = mdio_read(nic, phy, MII_BMSR);
- if (mii_status != 0xffff && mii_status != 0x0000) {
- lp->phys[phy_idx++] = phy;
- lp->mii_if.advertising =
- mdio_read(nic, phy, MII_ADVERTISE);
- if ((mii_status & 0x0040) == 0) {
- tmp = phy;
- dprintf (("MII PHY found at address %d, status "
- "%hX advertising %hX\n", phy, mii_status,
- lp->mii_if.advertising));
- }
- }
- }
- if (phy_idx == 0)
- printf("No MII transceiver found!\n");
- lp->mii_if.phy_id = lp->phys[0];
-
- lp->mii_if.advertising =
- mdio_read(nic, lp->phys[0], MII_ADVERTISE);
-
- mii_lpa = mdio_read(nic, lp->phys[0], MII_LPA);
- lp->mii_if.advertising &= mii_lpa;
- if (lp->mii_if.advertising & ADVERTISE_100FULL)
- printf("100Mbps Full-Duplex\n");
- else if (lp->mii_if.advertising & ADVERTISE_100HALF)
- printf("100Mbps Half-Duplex\n");
- else if (lp->mii_if.advertising & ADVERTISE_10FULL)
- printf("10Mbps Full-Duplex\n");
- else if (lp->mii_if.advertising & ADVERTISE_10HALF)
- printf("10Mbps Half-Duplex\n");
- else
- printf("\n");
- } else {
-
-
- if (fdx)
- printf("10Mbps Full-Duplex\n");
- else
- printf("10Mbps Half-Duplex\n");
- }
-
- nic->nic_op = &pcnet32_operations;
-
- return 1;
- }
- static int mdio_read(struct nic *nic __unused, int phy_id, int reg_num)
- {
- u16 val_out;
- int phyaddr;
-
- if (!lp->mii)
- return 0;
-
- phyaddr = lp->a.read_bcr(ioaddr, 33);
-
- lp->a.write_bcr(ioaddr, 33,
- ((phy_id & 0x1f) << 5) | (reg_num & 0x1f));
- val_out = lp->a.read_bcr(ioaddr, 34);
- lp->a.write_bcr(ioaddr, 33, phyaddr);
-
- return val_out;
- }
-
- #if 0
- static void mdio_write(struct nic *nic __unused, int phy_id, int reg_num,
- int val)
- {
- int phyaddr;
-
- if (!lp->mii)
- return;
-
- phyaddr = lp->a.read_bcr(ioaddr, 33);
-
- lp->a.write_bcr(ioaddr, 33,
- ((phy_id & 0x1f) << 5) | (reg_num & 0x1f));
- lp->a.write_bcr(ioaddr, 34, val);
- lp->a.write_bcr(ioaddr, 33, phyaddr);
- }
- #endif
-
- static struct nic_operations pcnet32_operations = {
- .connect = dummy_connect,
- .poll = pcnet32_poll,
- .transmit = pcnet32_transmit,
- .irq = pcnet32_irq,
-
- };
-
- static struct pci_device_id pcnet32_nics[] = {
- PCI_ROM(0x1022, 0x2000, "pcnet32", "AMD PCnet/PCI", 0),
- PCI_ROM(0x1022, 0x2625, "pcnetfastiii", "AMD PCNet FAST III", 0),
- PCI_ROM(0x1022, 0x2001, "amdhomepna", "AMD PCnet/HomePNA", 0),
- };
-
- PCI_DRIVER ( pcnet32_driver, pcnet32_nics, PCI_NO_CLASS );
-
- DRIVER ( "PCNET32/PCI", nic_driver, pci_driver, pcnet32_driver,
- pcnet32_probe, pcnet32_disable );
-
|