123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161 |
-
-
- FILE_LICENCE ( GPL2_OR_LATER );
-
- #include <stdint.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <unistd.h>
- #include <assert.h>
- #include <byteswap.h>
- #include <errno.h>
- #include <ipxe/ethernet.h>
- #include <ipxe/if_ether.h>
- #include <ipxe/io.h>
- #include <ipxe/iobuf.h>
- #include <ipxe/malloc.h>
- #include <ipxe/netdevice.h>
- #include <ipxe/pci.h>
- #include <ipxe/timer.h>
- #include <mii.h>
- #include "pcnet32.h"
-
- 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_mdio_read ( struct net_device *netdev, int phy, int reg )
- {
- struct pcnet32_private *priv = netdev->priv;
- unsigned long ioaddr = priv->pci_dev->ioaddr;
- u16 val_out;
-
- if ( ! priv->mii )
- return 0;
-
-
- priv->a->write_bcr ( ioaddr, 33,
- ( ( phy & 0x1f ) << 5 ) | ( reg & 0x1f ) );
-
-
- val_out = priv->a->read_bcr ( ioaddr, 34 );
-
- return val_out;
- }
-
- static void
- __unused pcnet32_mdio_write ( struct net_device *netdev, int phy, int reg, int val )
- {
- struct pcnet32_private *priv = netdev->priv;
- unsigned long ioaddr = priv->pci_dev->ioaddr;
-
- if ( ! priv->mii )
- return;
-
-
- priv->a->write_bcr ( ioaddr, 33,
- ( ( phy & 0x1f ) << 5 ) | ( reg & 0x1f ) );
-
-
- priv->a->write_bcr ( ioaddr, 34, val );
- }
-
-
-
- static void
- pcnet32_refill_rx_ring ( struct pcnet32_private *priv )
- {
- struct pcnet32_rx_desc *rx_curr_desc;
- u16 status;
- int i;
-
- DBGP ( "pcnet32_refill_rx_ring\n" );
-
- for ( i = 0; i < RX_RING_SIZE; i++ ) {
- rx_curr_desc = priv->rx_base + i;
-
- status = le16_to_cpu ( rx_curr_desc->status );
-
-
- if ( status & DescOwn )
- continue;
-
-
- if ( priv->rx_iobuf[i] != NULL )
- continue;
-
-
- if ( ! ( priv->rx_iobuf[i] = alloc_iob ( PKT_BUF_SIZE ) ) ) {
- DBG ( "Refill rx ring failed\n" );
- break;
- }
-
- rx_curr_desc->base =
- cpu_to_le32 ( virt_to_bus ( priv->rx_iobuf[i]->data ) );
- rx_curr_desc->buf_length = cpu_to_le16 ( -PKT_BUF_SIZE );
- rx_curr_desc->msg_length = rx_curr_desc->reserved = 0;
-
-
- wmb();
- rx_curr_desc->status = cpu_to_le16 ( DescOwn );
- }
-
- }
-
-
- static int
- pcnet32_setup_rx_resources ( struct pcnet32_private *priv )
- {
- DBGP ( "pcnet32_setup_rx_resources\n" );
-
- priv->rx_base = malloc_dma ( RX_RING_BYTES, RX_RING_ALIGN );
-
- DBG ( "priv->rx_base = %#08lx\n", virt_to_bus ( priv->rx_base ) );
-
- if ( ! priv->rx_base ) {
- return -ENOMEM;
- }
-
- memset ( priv->rx_base, 0, RX_RING_BYTES );
-
- pcnet32_refill_rx_ring ( priv );
-
- priv->rx_curr = 0;
-
- return 0;
- }
-
- static void
- pcnet32_free_rx_resources ( struct pcnet32_private *priv )
- {
- int i;
-
- DBGP ( "pcnet32_free_rx_resources\n" );
-
- free_dma ( priv->rx_base, RX_RING_BYTES );
-
- for ( i = 0; i < RX_RING_SIZE; i++ ) {
- free_iob ( priv->rx_iobuf[i] );
- priv->rx_iobuf[i] = NULL;
- }
- }
-
-
- static int
- pcnet32_setup_tx_resources ( struct pcnet32_private *priv )
- {
- DBGP ( "pcnet32_setup_tx_resources\n" );
-
- priv->tx_base = malloc_dma ( TX_RING_BYTES, TX_RING_ALIGN );
-
- if ( ! priv->tx_base ) {
- return -ENOMEM;
- }
-
- memset ( priv->tx_base, 0, TX_RING_BYTES );
-
- DBG ( "priv->tx_base = %#08lx\n", virt_to_bus ( priv->tx_base ) );
-
- priv->tx_curr = 0;
- priv->tx_fill_ctr = 0;
- priv->tx_tail = 0;
-
- return 0;
- }
-
- static void
- pcnet32_free_tx_resources ( struct pcnet32_private *priv )
- {
- DBGP ( "pcnet32_free_tx_resources\n" );
-
- free_dma ( priv->tx_base, TX_RING_BYTES );
- }
-
- static int
- pcnet32_chip_detect ( struct pcnet32_private *priv )
- {
- int fdx, mii, fset;
- int media;
- int rc;
- unsigned long ioaddr;
- struct pcnet32_access *a;
- int chip_version;
- char *chipname;
-
- ioaddr = priv->pci_dev->ioaddr;
- a = priv->a;
-
- chip_version = a->read_csr ( ioaddr, 88 )
- | ( a->read_csr ( ioaddr, 89 ) << 16 );
-
- rc = -ENODEV;
-
- DBG ( "PCnet chip version is 0x%X\n", chip_version );
- if ( ( chip_version & 0xfff ) != 0x003 )
- goto err_unsupported;
-
- fdx = mii = fset = 0;
- chip_version = ( chip_version >> 12 ) & 0xffff;
-
- switch (chip_version) {
- case 0x2420:
- chipname = "PCnet/PCI 79C970";
- break;
- case 0x2430:
-
- chipname = "PCnet/PCI 79C970";
- break;
- case 0x2621:
- chipname = "PCnet/PCI II 79C970A";
- fdx = 1;
- break;
- case 0x2623:
- chipname = "PCnet/FAST 79C971";
- fdx = 1;
- mii = 1;
- fset = 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);
-
- DBG ( "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;
- case 0x2628:
- chipname = "PCnet/PRO 79C976";
- fdx = 1;
- mii = 1;
- break;
- default:
- chipname = "UNKNOWN";
- DBG ( "PCnet version %#x, no PCnet32 chip.\n", chip_version );
- goto err_unsupported;
- }
-
- DBG ( "PCnet chipname %s\n", chipname );
-
-
-
- if (fset) {
- a->write_bcr ( ioaddr, 18,
- ( a->read_bcr ( ioaddr, 18 ) | 0x0860 ) );
- a->write_csr ( ioaddr, 80,
- ( a->read_csr ( ioaddr, 80 ) & 0x0C00) | 0x0C00 );
- }
-
- priv->full_duplex = fdx;
- priv->mii = mii;
-
- return 0;
-
- err_unsupported:
- return rc;
- }
-
-
- static int
- pcnet32_set_ops ( struct pcnet32_private *priv )
- {
- int rc;
- unsigned long ioaddr;
-
- ioaddr = priv->pci_dev->ioaddr;
-
-
-
- rc = -ENODEV;
-
- if ( pcnet32_wio_read_csr ( ioaddr, 0 ) == 4 &&
- pcnet32_wio_check ( ioaddr ) ) {
- priv->a = &pcnet32_wio;
- } else {
- pcnet32_dwio_reset ( ioaddr );
- if ( pcnet32_dwio_read_csr ( ioaddr, 0 ) == 4 &&
- pcnet32_dwio_check ( ioaddr ) ) {
- priv->a = &pcnet32_dwio;
- } else {
- goto err_unsupported;
- }
- }
-
- return 0;
-
- err_unsupported:
- return rc;
- }
-
-
- static void
- pcnet32_setup_init_block ( struct pcnet32_private *priv )
- {
- int i;
-
-
- priv->init_block.mode =
- cpu_to_le16 ( ( priv->options & PCNET32_PORT_PORTSEL ) << 7 );
-
-
- priv->init_block.tlen_rlen =
- cpu_to_le16 ( ( PCNET32_LOG_RX_BUFFERS << 4 ) |
- ( PCNET32_LOG_TX_BUFFERS << 12 ) );
-
-
- for ( i = 0; i < ETH_ALEN; i++)
- priv->init_block.phys_addr[i] = priv->netdev->hw_addr[i];
-
-
- priv->init_block.filter[0] = 0xffffffff;
- priv->init_block.filter[1] = 0xffffffff;
-
- priv->init_block.rx_ring =
- cpu_to_le32 ( virt_to_bus ( priv->rx_base ) );
- priv->init_block.tx_ring =
- cpu_to_le32 ( virt_to_bus ( priv->tx_base ) );
-
-
- wmb();
- }
-
-
- static void
- pcnet32_setup_probe_phy ( struct pcnet32_private *priv )
- {
- unsigned long ioaddr = priv->pci_dev->ioaddr;
- unsigned int phycount = 0;
- int phy_id;
- int i;
-
- if ( priv->mii ) {
- phy_id = ( ( priv->a->read_bcr ( ioaddr, 33 ) ) >> 5 ) & 0x1f;
- for ( i = 0; i < PCNET32_MAX_PHYS; i++ ) {
- unsigned short id1, id2;
- id1 = pcnet32_mdio_read ( priv->netdev, i, MII_PHYSID1 );
- if ( id1 == 0xffff )
- continue;
- id2 = pcnet32_mdio_read ( priv->netdev, i, MII_PHYSID2 );
- if ( id2 == 0xffff )
- continue;
- if ( i == 31 && ( ( priv->chip_version + 1 ) & 0xfffe ) == 0x2624 )
- continue;
-
- phycount++;
- phy_id = i;
- }
- priv->a->write_bcr ( ioaddr, 33, phy_id << 5 );
- if ( phycount > 1 )
- priv->options |= PCNET32_PORT_MII;
- }
- }
-
-
- static int
- pcnet32_setup_mac_addr ( struct pcnet32_private *priv )
- {
- int i;
- u8 promaddr[ETH_ALEN];
- unsigned long ioaddr = priv->pci_dev->ioaddr;
-
-
-
- for ( i = 0; i < 3; i++ ) {
- unsigned int val;
- val = priv->a->read_csr ( ioaddr, i + 12 ) & 0x0ffff;
-
- priv->netdev->hw_addr[2 * i] = val & 0x0ff;
- priv->netdev->hw_addr[2 * i + 1] = ( val >> 8 ) & 0x0ff;
- }
-
- for ( i = 0; i < ETH_ALEN; i++ )
- promaddr[i] = inb ( ioaddr + i );
-
- if ( memcmp ( promaddr, priv->netdev->hw_addr, ETH_ALEN ) ||
- ! is_valid_ether_addr ( priv->netdev->hw_addr ) ) {
- if ( is_valid_ether_addr ( promaddr ) ) {
- DBG ( "CSR address is invalid, using PROM addr\n" );
- memcpy ( priv->netdev->hw_addr, promaddr, ETH_ALEN );
- }
- }
-
-
- if ( ! is_valid_ether_addr ( priv->netdev->hw_addr ) )
- return -EADDRNOTAVAIL;
-
- return 0;
- }
-
-
- static void
- pcnet32_setup_if_duplex ( struct pcnet32_private *priv )
- {
- unsigned long ioaddr = priv->pci_dev->ioaddr;
- u16 val;
-
-
- val = priv->a->read_bcr ( ioaddr, 2 ) & ~2;
- if ( priv->options & PCNET32_PORT_ASEL )
- val |= 2;
- priv->a->write_bcr ( ioaddr, 2, val );
-
-
- if ( priv->full_duplex ) {
- val = priv->a->read_bcr ( ioaddr, 9 ) & ~3;
- if ( priv->options & PCNET32_PORT_FD ) {
- val |= 1;
- if ( priv->options == ( PCNET32_PORT_FD | PCNET32_PORT_AUI ) )
- val |= 2;
- } else if ( priv->options & PCNET32_PORT_ASEL ) {
-
- if ( priv->chip_version == 0x2627 )
- val |= 3;
- }
- priv->a->write_bcr ( ioaddr, 9, val );
- }
-
-
- val = priv->a->read_csr ( ioaddr, 124 ) & ~0x10;
- if ( ( priv->options & PCNET32_PORT_PORTSEL ) == PCNET32_PORT_GPSI )
- val |= 0x10;
- priv->a->write_bcr ( ioaddr, 124, val );
-
-
- u16 subsys_vend_id, subsys_dev_id;
- pci_read_config_word ( priv->pci_dev,
- PCI_SUBSYSTEM_VENDOR_ID,
- &subsys_vend_id );
- pci_read_config_word ( priv->pci_dev,
- PCI_SUBSYSTEM_ID,
- &subsys_dev_id );
- if ( subsys_vend_id == PCI_VENDOR_ID_AT &&
- ( ( subsys_dev_id == PCI_SUBDEVICE_ID_AT_2700FX ) ||
- ( subsys_dev_id == PCI_SUBDEVICE_ID_AT_2701FX ) ) ) {
- priv->options = PCNET32_PORT_FD | PCNET32_PORT_100;
- }
-
- if ( priv->mii && ! ( priv->options & PCNET32_PORT_ASEL ) ) {
-
- val = priv->a->read_bcr ( ioaddr, 32 ) & ~0x38;
- if ( priv->options & PCNET32_PORT_FD )
- val |= 0x10;
- if ( priv->options & PCNET32_PORT_100 )
- val |= 0x08;
- priv->a->write_bcr ( ioaddr, 32, val );
- } else if ( priv->options & PCNET32_PORT_ASEL ) {
-
- if ( ( priv->chip_version != 0x2420 ) &&
- ( priv->chip_version != 0x2621 ) ) {
-
- val = priv->a->read_bcr ( ioaddr, 32 ) & ~0x98;
- val |= 0x20;
- priv->a->write_bcr ( ioaddr, 32, val );
- }
- }
- }
-
-
- static void
- pcnet32_hw_start ( struct pcnet32_private *priv )
- {
- unsigned long ioaddr = priv->pci_dev->ioaddr;
- int i;
-
-
- priv->a->write_csr ( ioaddr, 0, Init );
-
-
- i = 0;
- while ( i++ < 100 )
- if ( priv->a->read_csr ( ioaddr, 0 ) & InitDone )
- break;
-
-
- priv->a->write_csr ( ioaddr, 0, Strt );
- }
-
-
- static int
- pcnet32_open ( struct net_device *netdev )
- {
- struct pcnet32_private *priv = netdev_priv ( netdev );
- unsigned long ioaddr = priv->pci_dev->ioaddr;
- int rc;
- u16 val;
-
-
- if ( ( rc = pcnet32_setup_tx_resources ( priv ) ) != 0 ) {
- DBG ( "Error setting up TX resources\n" );
- goto err_setup_tx;
- }
-
- if ( ( rc = pcnet32_setup_rx_resources ( priv ) ) != 0 ) {
- DBG ( "Error setting up RX resources\n" );
- goto err_setup_rx;
- }
-
-
- priv->a->reset ( ioaddr );
-
-
- priv->a->write_bcr ( ioaddr, 20, PCNET32_SWSTYLE_PCNET32 );
-
-
- pcnet32_setup_if_duplex ( priv );
-
-
- val = priv->a->read_csr ( ioaddr, 3 );
- val |= BablMask | MissFrameMask | RxIntMask | TxIntMask | InitDoneMask;
- priv->a->write_csr ( ioaddr, 3, val );
-
-
- pcnet32_setup_init_block ( priv );
-
-
- priv->a->write_csr ( ioaddr, 1,
- ( virt_to_bus ( &priv->init_block ) ) & 0xffff );
- priv->a->write_csr ( ioaddr, 2,
- ( virt_to_bus ( &priv->init_block ) ) >> 16 );
-
-
- priv->a->write_csr ( ioaddr, 4, 0x0915 );
-
- pcnet32_hw_start ( priv );
-
- return 0;
-
- err_setup_rx:
- pcnet32_free_tx_resources ( priv );
- err_setup_tx:
- priv->a->reset( priv->pci_dev->ioaddr );
- return rc;
- }
-
-
- static int
- pcnet32_transmit ( struct net_device *netdev, struct io_buffer *iobuf )
- {
- struct pcnet32_private *priv = netdev_priv ( netdev );
- unsigned long ioaddr = priv->pci_dev->ioaddr;
- uint32_t tx_len = iob_len ( iobuf );
- struct pcnet32_tx_desc *tx_curr_desc;
-
- DBGP ( "pcnet32_transmit\n" );
-
- if ( priv->tx_fill_ctr == TX_RING_SIZE ) {
- DBG ( "Tx overflow\n" );
- return -ENOTSUP;
- }
-
- priv->tx_iobuf[priv->tx_curr] = iobuf;
-
- tx_curr_desc = priv->tx_base + priv->tx_curr;
-
-
- tx_curr_desc->length = cpu_to_le16 ( -tx_len );
- tx_curr_desc->misc = 0x00000000;
- tx_curr_desc->base = cpu_to_le32 ( virt_to_bus ( iobuf->data ) );
-
-
- wmb();
- tx_curr_desc->status =
- cpu_to_le16 ( DescOwn | StartOfPacket | EndOfPacket );
-
-
- priv->a->write_csr ( ioaddr, 0,
- ( priv->irq_enabled ? IntEnable : 0 ) | TxDemand );
-
-
- priv->tx_curr = ( priv->tx_curr + 1 ) % TX_RING_SIZE;
-
-
- priv->tx_fill_ctr++;
-
- return 0;
- }
-
-
- static void
- pcnet32_process_tx_packets ( struct net_device *netdev )
- {
- struct pcnet32_private *priv = netdev_priv ( netdev );
- struct pcnet32_tx_desc *tx_curr_desc;
-
- DBGP ( "pcnet32_process_tx_packets\n" );
-
- while ( priv->tx_tail != priv->tx_curr ) {
- tx_curr_desc = priv->tx_base + priv->tx_tail;
-
- u16 status = le16_to_cpu ( tx_curr_desc->status );
-
- DBG ( "Before OWN bit check, status: %#08x\n", status );
-
-
- if ( status & DescOwn )
- break;
-
- DBG ( "Transmitted packet.\n" );
- DBG ( "priv->tx_fill_ctr= %d\n", priv->tx_fill_ctr );
- DBG ( "priv->tx_tail = %d\n", priv->tx_tail );
- DBG ( "priv->tx_curr = %d\n", priv->tx_curr );
- DBG ( "tx_curr_desc = %#08lx\n", virt_to_bus ( tx_curr_desc ) );
-
-
- netdev_tx_complete ( netdev, priv->tx_iobuf[priv->tx_tail]);
-
-
- memset ( tx_curr_desc, 0, sizeof(*tx_curr_desc) );
-
-
- priv->tx_fill_ctr--;
-
-
- priv->tx_tail = ( priv->tx_tail + 1 ) % TX_RING_SIZE;
- }
- }
-
-
- static void
- pcnet32_process_rx_packets ( struct net_device *netdev )
- {
- struct pcnet32_private *priv = netdev_priv ( netdev );
- struct pcnet32_rx_desc *rx_curr_desc;
- u16 status;
- u32 len;
- int i;
-
- DBGP ( "pcnet32_process_rx_packets\n" );
-
- for ( i = 0; i < RX_RING_SIZE; i++ ) {
- rx_curr_desc = priv->rx_base + priv->rx_curr;
-
- status = le16_to_cpu ( rx_curr_desc->status );
- rmb();
-
- DBG ( "Before OWN bit check, status: %#08x\n", status );
-
-
- if ( status & DescOwn )
- break;
-
-
- if ( priv->rx_iobuf[priv->rx_curr] == NULL )
- break;
-
- DBG ( "Received packet.\n" );
- DBG ( "priv->rx_curr = %d\n", priv->rx_curr );
- DBG ( "rx_len = %d\n",
- ( le32_to_cpu ( rx_curr_desc->msg_length ) & 0xfff ) - 4 );
- DBG ( "rx_curr_desc = %#08lx\n",
- virt_to_bus ( rx_curr_desc ) );
-
-
- if ( status & 0x4000 ) {
- netdev_rx_err ( netdev, priv->rx_iobuf[priv->rx_curr],
- -EINVAL );
- DBG ( "Corrupted packet received!\n");
- } else {
-
- len = ( le32_to_cpu ( rx_curr_desc->msg_length ) & 0xfff ) - 4;
- iob_put ( priv->rx_iobuf[priv->rx_curr], len );
-
-
- netdev_rx ( netdev, priv->rx_iobuf[priv->rx_curr] );
- }
-
-
- priv->rx_iobuf[priv->rx_curr] = NULL;
- memset ( rx_curr_desc, 0, sizeof(*rx_curr_desc) );
-
-
- priv->rx_curr = ( priv->rx_curr + 1 ) % RX_RING_SIZE;
- }
-
-
- pcnet32_refill_rx_ring ( priv );
- }
-
-
- static void
- pcnet32_poll ( struct net_device *netdev )
- {
- struct pcnet32_private *priv = netdev_priv ( netdev );
- unsigned long ioaddr = priv->pci_dev->ioaddr;
- u16 status;
-
- DBGP ( "pcnet32_poll\n" );
-
- status = priv->a->read_csr ( ioaddr, 0 );
-
-
- priv->a->write_csr ( ioaddr, 0, status );
-
- DBG ( "pcnet32_poll: mask = %#04x, status = %#04x\n",
- priv->a->read_csr ( ioaddr, 3 ), status );
-
-
- if ( ( status & 0x0500 ) == 0x0000 )
- return;
-
-
- pcnet32_process_tx_packets ( netdev );
-
-
- pcnet32_process_rx_packets ( netdev );
- }
-
-
- static void
- pcnet32_close ( struct net_device *netdev )
- {
- struct pcnet32_private *priv = netdev_priv ( netdev );
- unsigned long ioaddr = priv->pci_dev->ioaddr;
-
- DBGP ( "pcnet32_close\n" );
-
-
- pcnet32_wio_reset ( ioaddr );
-
-
- priv->a->write_csr ( ioaddr, 0, Stop );
-
-
-
- priv->a->write_bcr ( ioaddr, 20, PCNET32_SWSTYLE_LANCE );
-
- pcnet32_free_rx_resources ( priv );
- pcnet32_free_tx_resources ( priv );
- }
-
- static void pcnet32_irq_enable ( struct pcnet32_private *priv )
- {
- unsigned long ioaddr = priv->pci_dev->ioaddr;
- u16 val;
-
- DBGP ( "pcnet32_irq_enable\n" );
-
-
- val = priv->a->read_csr ( ioaddr, 3 );
- val &= ~( RxIntMask | TxIntMask );
- priv->a->write_csr ( ioaddr, 3, val );
-
-
- priv->a->write_csr ( ioaddr, 0, IntEnable );
-
- priv->irq_enabled = 1;
- }
-
- static void pcnet32_irq_disable ( struct pcnet32_private *priv )
- {
- unsigned long ioaddr = priv->pci_dev->ioaddr;
-
- DBGP ( "pcnet32_irq_disable\n" );
-
- priv->a->write_csr ( ioaddr, 0, 0x0000 );
-
- priv->irq_enabled = 0;
- }
-
-
- static void
- pcnet32_irq ( struct net_device *netdev, int action )
- {
- struct pcnet32_private *priv = netdev_priv ( netdev );
-
- DBGP ( "pcnet32_irq\n" );
-
- switch ( action ) {
- case 0:
- pcnet32_irq_disable ( priv );
- break;
- default:
- pcnet32_irq_enable ( priv );
- break;
- }
- }
-
- static struct net_device_operations pcnet32_operations = {
- .open = pcnet32_open,
- .transmit = pcnet32_transmit,
- .poll = pcnet32_poll,
- .close = pcnet32_close,
- .irq = pcnet32_irq,
- };
-
-
- static int
- pcnet32_probe ( struct pci_device *pdev )
- {
- struct net_device *netdev;
- struct pcnet32_private *priv;
- unsigned long ioaddr;
- int rc;
-
- DBGP ( "pcnet32_probe\n" );
-
- DBG ( "Found %s, vendor = %#04x, device = %#04x\n",
- pdev->id->name, pdev->id->vendor, pdev->id->device );
-
-
- netdev = alloc_etherdev ( sizeof ( *priv ) );
- if ( ! netdev ) {
- rc = -ENOMEM;
- goto err_alloc_etherdev;
- }
-
-
- netdev_init ( netdev, &pcnet32_operations );
-
-
- pci_set_drvdata ( pdev, netdev );
- netdev->dev = &pdev->dev;
-
-
- priv = netdev_priv ( netdev );
-
-
- priv->pci_dev = pdev;
- priv->netdev = netdev;
-
- ioaddr = pdev->ioaddr;
-
-
- priv->irq_enabled = 0;
-
-
- pcnet32_wio_reset ( ioaddr );
-
- if ( ( rc = pcnet32_set_ops ( priv ) ) != 0 ) {
- DBG ( "Setting driver operations failed\n");
- goto err_set_ops;
- }
-
- if ( ( rc = pcnet32_chip_detect ( priv ) ) != 0 ) {
- DBG ( "pcnet32_chip_detect failed\n" );
- goto err_chip_detect;
- }
-
-
- adjust_pci_device ( pdev );
-
-
- if ( ( rc = pcnet32_setup_mac_addr ( priv ) ) != 0 ) {
- DBG ( "Setting MAC address failed\n" );
- goto err_mac_addr;
- }
-
- DBG ( "IO Addr 0x%lX, MAC Addr %s\n", ioaddr,
- eth_ntoa ( netdev->hw_addr ) );
-
- priv->options = PCNET32_PORT_ASEL;
-
-
- if ( netdev->hw_addr[0] == 0x00 &&
- netdev->hw_addr[1] == 0xE0 &&
- netdev->hw_addr[2] == 0x75 )
- priv->options = PCNET32_PORT_FD | PCNET32_PORT_GPSI;
-
-
- pcnet32_setup_probe_phy ( priv );
-
- if ( ( rc = register_netdev ( netdev ) ) != 0 ) {
- DBG ( "Error registering netdev\n" );
- goto err_register;
- }
-
- netdev_link_up ( netdev );
-
- return 0;
-
- err_register:
- netdev_put ( netdev );
- err_chip_detect:
- err_set_ops:
- err_alloc_etherdev:
- err_mac_addr:
- return rc;
- }
-
-
- static void
- pcnet32_remove ( struct pci_device *pdev )
- {
- struct net_device *netdev = pci_get_drvdata ( pdev );
- unsigned long ioaddr = pdev->ioaddr;
-
- DBGP ( "pcnet32_remove\n" );
-
-
- pcnet32_wio_reset ( ioaddr );
-
- unregister_netdev ( netdev );
- netdev_nullify ( netdev );
- netdev_put ( netdev );
- }
-
- 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),
- };
-
- struct pci_driver pcnet32_driver __pci_driver = {
- .ids = pcnet32_nics,
- .id_count = ARRAY_SIZE ( pcnet32_nics ),
- .probe = pcnet32_probe,
- .remove = pcnet32_remove,
- };
|