diff --git a/src/drivers/net/smc9000.c b/src/drivers/net/smc9000.c index a67c1be4..cd394d43 100644 --- a/src/drivers/net/smc9000.c +++ b/src/drivers/net/smc9000.c @@ -27,7 +27,6 @@ * *---------------------------------------------------------------------------*/ #define LINUX_OUT_MACROS 1 -#define SMC9000_VERBOSE 1 #define SMC9000_DEBUG 0 #include "etherboot.h" @@ -39,7 +38,6 @@ # define _outw outw static const char smc9000_version[] = "Version 0.99 98-09-30"; -static unsigned int smc9000_base=0; static const char *interfaces[ 2 ] = { "TP", "AUI" }; static const char *chip_ids[ 15 ] = { NULL, NULL, NULL, @@ -97,11 +95,11 @@ static void smc_reset(int ioaddr) /*---------------------------------------------------------------------- - * Function: smc_probe( int ioaddr ) + * Function: smc9000_probe_addr( int ioaddr ) * * Purpose: * Tests to see if a given ioaddr points to an SMC9xxx chip. - * Returns a 0 on success + * Returns a 1 on success * * Algorithm: * (1) see if the high byte of BANK_SELECT is 0x33 @@ -110,7 +108,7 @@ static void smc_reset(int ioaddr) * * --------------------------------------------------------------------- */ -static int smc_probe( int ioaddr ) +static int smc9000_probe_addr( unsigned short ioaddr ) { word bank; word revision_register; @@ -119,14 +117,14 @@ static int smc_probe( int ioaddr ) /* First, see if the high byte is 0x33 */ bank = inw(ioaddr + BANK_SELECT); if ((bank & 0xFF00) != 0x3300) { - return -1; + return 0; } /* The above MIGHT indicate a device, but I need to write to further * test this. */ _outw(0x0, ioaddr + BANK_SELECT); bank = inw(ioaddr + BANK_SELECT); if ((bank & 0xFF00) != 0x3300) { - return -1; + return 0; } /* well, we've already written once, so hopefully another time won't @@ -136,14 +134,12 @@ static int smc_probe( int ioaddr ) base_address_register = inw(ioaddr + BASE); if (ioaddr != (base_address_register >> 3 & 0x3E0)) { -#ifdef SMC9000_VERBOSE - printf("SMC9000: IOADDR %hX doesn't match configuration (%hX)." - "Probably not a SMC chip\n", - ioaddr, base_address_register >> 3 & 0x3E0); -#endif + DBG("SMC9000: IOADDR %hX doesn't match configuration (%hX)." + "Probably not a SMC chip\n", + ioaddr, base_address_register >> 3 & 0x3E0); /* well, the base address register didn't match. Must not have * been a SMC chip after all. */ - return -1; + return 0; } @@ -154,17 +150,15 @@ static int smc_probe( int ioaddr ) revision_register = inw(ioaddr + REVISION); if (!chip_ids[(revision_register >> 4) & 0xF]) { /* I don't recognize this chip, so... */ -#ifdef SMC9000_VERBOSE - printf("SMC9000: IO %hX: Unrecognized revision register:" - " %hX, Contact author.\n", ioaddr, revision_register); -#endif - return -1; + DBG( "SMC9000: IO %hX: Unrecognized revision register:" + " %hX, Contact author.\n", ioaddr, revision_register ); + return 0; } /* at this point I'll assume that the chip is an SMC9xxx. * It might be prudent to check a listing of MAC addresses * against the hardware address, or do some other tests. */ - return 0; + return 1; } @@ -192,25 +186,23 @@ static void smc9000_transmit( numPages = length / 256; if (numPages > 7 ) { -#ifdef SMC9000_VERBOSE - printf("SMC9000: Far too big packet error. \n"); -#endif + DBG("SMC9000: Far too big packet error. \n"); return; } /* dont try more than, say 30 times */ for (i=0;i<30;i++) { /* now, try to allocate the memory */ - SMC_SELECT_BANK(smc9000_base, 2); - _outw(MC_ALLOC | numPages, smc9000_base + MMU_CMD); + SMC_SELECT_BANK(nic->ioaddr, 2); + _outw(MC_ALLOC | numPages, nic->ioaddr + MMU_CMD); status = 0; /* wait for the memory allocation to finnish */ for (time_out = currticks() + 5*TICKS_PER_SEC; currticks() < time_out; ) { - status = inb(smc9000_base + INTERRUPT); + status = inb(nic->ioaddr + INTERRUPT); if ( status & IM_ALLOC_INT ) { /* acknowledge the interrupt */ - _outb(IM_ALLOC_INT, smc9000_base + INTERRUPT); + _outb(IM_ALLOC_INT, nic->ioaddr + INTERRUPT); break; } } @@ -220,12 +212,12 @@ static void smc9000_transmit( break; } else { printf("SMC9000: Memory allocation timed out, resetting MMU.\n"); - _outw(MC_RESET, smc9000_base + MMU_CMD); + _outw(MC_RESET, nic->ioaddr + MMU_CMD); } } /* If I get here, I _know_ there is a packet slot waiting for me */ - packet_no = inb(smc9000_base + PNR_ARR + 1); + packet_no = inb(nic->ioaddr + PNR_ARR + 1); if (packet_no & 0x80) { /* or isn't there? BAD CHIP! */ printf("SMC9000: Memory allocation failed. \n"); @@ -233,10 +225,10 @@ static void smc9000_transmit( } /* we have a packet address, so tell the card to use it */ - _outb(packet_no, smc9000_base + PNR_ARR); + _outb(packet_no, nic->ioaddr + PNR_ARR); /* point to the beginning of the packet */ - _outw(PTR_AUTOINC, smc9000_base + POINTER); + _outw(PTR_AUTOINC, nic->ioaddr + POINTER); #if SMC9000_DEBUG > 2 printf("Trying to xmit packet of length %hX\n", length ); @@ -244,73 +236,71 @@ static void smc9000_transmit( /* send the packet length ( +6 for status, length and ctl byte ) * and the status word ( set to zeros ) */ - _outw(0, smc9000_base + DATA_1 ); + _outw(0, nic->ioaddr + DATA_1 ); /* send the packet length ( +6 for status words, length, and ctl) */ - _outb((length+6) & 0xFF, smc9000_base + DATA_1); - _outb((length+6) >> 8 , smc9000_base + DATA_1); + _outb((length+6) & 0xFF, nic->ioaddr + DATA_1); + _outb((length+6) >> 8 , nic->ioaddr + DATA_1); /* Write the contents of the packet */ /* The ethernet header first... */ - outsw(smc9000_base + DATA_1, d, ETH_ALEN >> 1); - outsw(smc9000_base + DATA_1, nic->node_addr, ETH_ALEN >> 1); - _outw(htons(t), smc9000_base + DATA_1); + outsw(nic->ioaddr + DATA_1, d, ETH_ALEN >> 1); + outsw(nic->ioaddr + DATA_1, nic->node_addr, ETH_ALEN >> 1); + _outw(htons(t), nic->ioaddr + DATA_1); /* ... the data ... */ - outsw(smc9000_base + DATA_1 , p, s >> 1); + outsw(nic->ioaddr + DATA_1 , p, s >> 1); /* ... and the last byte, if there is one. */ if ((s & 1) == 0) { - _outw(0, smc9000_base + DATA_1); + _outw(0, nic->ioaddr + DATA_1); } else { - _outb(p[s-1], smc9000_base + DATA_1); - _outb(0x20, smc9000_base + DATA_1); + _outb(p[s-1], nic->ioaddr + DATA_1); + _outb(0x20, nic->ioaddr + DATA_1); } /* and let the chipset deal with it */ - _outw(MC_ENQUEUE , smc9000_base + MMU_CMD); + _outw(MC_ENQUEUE , nic->ioaddr + MMU_CMD); status = 0; time_out = currticks() + 5*TICKS_PER_SEC; do { - status = inb(smc9000_base + INTERRUPT); + status = inb(nic->ioaddr + INTERRUPT); if ((status & IM_TX_INT ) != 0) { word tx_status; /* ack interrupt */ - _outb(IM_TX_INT, smc9000_base + INTERRUPT); + _outb(IM_TX_INT, nic->ioaddr + INTERRUPT); - packet_no = inw(smc9000_base + FIFO_PORTS); + packet_no = inw(nic->ioaddr + FIFO_PORTS); packet_no &= 0x7F; /* select this as the packet to read from */ - _outb( packet_no, smc9000_base + PNR_ARR ); + _outb( packet_no, nic->ioaddr + PNR_ARR ); /* read the first word from this packet */ - _outw( PTR_AUTOINC | PTR_READ, smc9000_base + POINTER ); + _outw( PTR_AUTOINC | PTR_READ, nic->ioaddr + POINTER ); - tx_status = inw( smc9000_base + DATA_1 ); + tx_status = inw( nic->ioaddr + DATA_1 ); if (0 == (tx_status & TS_SUCCESS)) { -#ifdef SMC9000_VERBOSE - printf("SMC9000: TX FAIL STATUS: %hX \n", tx_status); -#endif + DBG("SMC9000: TX FAIL STATUS: %hX \n", tx_status); /* re-enable transmit */ - SMC_SELECT_BANK(smc9000_base, 0); - _outw(inw(smc9000_base + TCR ) | TCR_ENABLE, smc9000_base + TCR ); + SMC_SELECT_BANK(nic->ioaddr, 0); + _outw(inw(nic->ioaddr + TCR ) | TCR_ENABLE, nic->ioaddr + TCR ); } /* kill the packet */ - SMC_SELECT_BANK(smc9000_base, 2); - _outw(MC_FREEPKT, smc9000_base + MMU_CMD); + SMC_SELECT_BANK(nic->ioaddr, 2); + _outw(MC_FREEPKT, nic->ioaddr + MMU_CMD); return; } }while(currticks() < time_out); - printf("SMC9000: Waring TX timed out, resetting board\n"); - smc_reset(smc9000_base); + printf("SMC9000: TX timed out, resetting board\n"); + smc_reset(nic->ioaddr); return; } @@ -319,22 +309,19 @@ static void smc9000_transmit( ***************************************************************************/ static int smc9000_poll(struct nic *nic, int retrieve) { - if(!smc9000_base) - return 0; - - SMC_SELECT_BANK(smc9000_base, 2); - if (inw(smc9000_base + FIFO_PORTS) & FP_RXEMPTY) + SMC_SELECT_BANK(nic->ioaddr, 2); + if (inw(nic->ioaddr + FIFO_PORTS) & FP_RXEMPTY) return 0; if ( ! retrieve ) return 1; /* start reading from the start of the packet */ - _outw(PTR_READ | PTR_RCV | PTR_AUTOINC, smc9000_base + POINTER); + _outw(PTR_READ | PTR_RCV | PTR_AUTOINC, nic->ioaddr + POINTER); /* First read the status and check that we're ok */ - if (!(inw(smc9000_base + DATA_1) & RS_ERRORS)) { + if (!(inw(nic->ioaddr + DATA_1) & RS_ERRORS)) { /* Next: read the packet length and mask off the top bits */ - nic->packetlen = (inw(smc9000_base + DATA_1) & 0x07ff); + nic->packetlen = (inw(nic->ioaddr + DATA_1) & 0x07ff); /* the packet length includes the 3 extra words */ nic->packetlen -= 6; @@ -343,36 +330,33 @@ static int smc9000_poll(struct nic *nic, int retrieve) (nic->packetlen >> 1), nic->packetlen & 1); #endif /* read the packet (and the last "extra" word) */ - insw(smc9000_base + DATA_1, nic->packet, (nic->packetlen+2) >> 1); + insw(nic->ioaddr + DATA_1, nic->packet, (nic->packetlen+2) >> 1); /* is there an odd last byte ? */ if (nic->packet[nic->packetlen+1] & 0x20) nic->packetlen++; /* error or good, tell the card to get rid of this packet */ - _outw(MC_RELEASE, smc9000_base + MMU_CMD); + _outw(MC_RELEASE, nic->ioaddr + MMU_CMD); return 1; } printf("SMC9000: RX error\n"); /* error or good, tell the card to get rid of this packet */ - _outw(MC_RELEASE, smc9000_base + MMU_CMD); + _outw(MC_RELEASE, nic->ioaddr + MMU_CMD); return 0; } -static void smc9000_disable ( struct nic *nic __unused ) { - if(!smc9000_base) - return; - - smc_reset(smc9000_base); +static void smc9000_disable ( struct nic *nic ) { + smc_reset(nic->ioaddr); /* no more interrupts for me */ - SMC_SELECT_BANK(smc9000_base, 2); - _outb( 0, smc9000_base + INT_MASK); + SMC_SELECT_BANK(nic->ioaddr, 2); + _outb( 0, nic->ioaddr + INT_MASK); /* and tell the card to stay away from that nasty outside world */ - SMC_SELECT_BANK(smc9000_base, 0); - _outb( RCR_CLEAR, smc9000_base + RCR ); - _outb( TCR_CLEAR, smc9000_base + TCR ); + SMC_SELECT_BANK(nic->ioaddr, 0); + _outb( RCR_CLEAR, nic->ioaddr + RCR ); + _outb( TCR_CLEAR, nic->ioaddr + TCR ); } static void smc9000_irq(struct nic *nic __unused, irq_action_t action __unused) @@ -387,13 +371,20 @@ static void smc9000_irq(struct nic *nic __unused, irq_action_t action __unused) } } +static struct nic_operations smc9000_operations = { + .connect = dummy_connect, + .poll = smc9000_poll, + .transmit = smc9000_transmit, + .irq = smc9000_irq, + .disable = smc9000_disable, +}; + /************************************************************************** * ETH_PROBE - Look for an adapter ***************************************************************************/ -static int smc9000_probe(struct dev *dev, unsigned short *probe_addrs) -{ - struct nic *nic = (struct nic *)dev; +static int smc9000_probe ( struct dev *dev, struct isa_device *isa ) { + struct nic *nic = nic_device ( dev ); unsigned short revision; int memory; int media; @@ -401,63 +392,33 @@ static int smc9000_probe(struct dev *dev, unsigned short *probe_addrs) const char * if_string; int i; - /* - * the SMC9000 can be at any of the following port addresses. To change, - * for a slightly different card, you can add it to the array. Keep in - * mind that the array must end in zero. - */ - static unsigned short portlist[] = { -#ifdef SMC9000_SCAN - SMC9000_SCAN, -#else - 0x200, 0x220, 0x240, 0x260, 0x280, 0x2A0, 0x2C0, 0x2E0, - 0x300, 0x320, 0x340, 0x360, 0x380, 0x3A0, 0x3C0, 0x3E0, -#endif - 0 }; - - /* if no addresses supplied, fall back on defaults */ - if (probe_addrs == 0 || probe_addrs[0] == 0) - probe_addrs = portlist; - - /* check every ethernet address */ - for (i = 0; probe_addrs[i]; i++) { - /* check this specific address */ - if (smc_probe(probe_addrs[i]) == 0) - smc9000_base = probe_addrs[i]; - } - - /* couldn't find anything */ - if(0 == smc9000_base) - goto out; - nic->irqno = 0; - nic->ioaddr = smc9000_base; + nic->ioaddr = isa->ioaddr; /* * Get the MAC address ( bank 1, regs 4 - 9 ) */ - SMC_SELECT_BANK(smc9000_base, 1); + SMC_SELECT_BANK(nic->ioaddr, 1); for ( i = 0; i < 6; i += 2 ) { word address; - address = inw(smc9000_base + ADDR0 + i); + address = inw(nic->ioaddr + ADDR0 + i); nic->node_addr[i+1] = address >> 8; nic->node_addr[i] = address & 0xFF; } - /* get the memory information */ - SMC_SELECT_BANK(smc9000_base, 0); - memory = ( inw(smc9000_base + MCR) >> 9 ) & 0x7; /* multiplier */ - memory *= 256 * (inw(smc9000_base + MIR) & 0xFF); + SMC_SELECT_BANK(nic->ioaddr, 0); + memory = ( inw(nic->ioaddr + MCR) >> 9 ) & 0x7; /* multiplier */ + memory *= 256 * (inw(nic->ioaddr + MIR) & 0xFF); /* * Now, I want to find out more about the chip. This is sort of * redundant, but it's cleaner to have it in both, rather than having * one VERY long probe procedure. */ - SMC_SELECT_BANK(smc9000_base, 3); - revision = inw(smc9000_base + REVISION); + SMC_SELECT_BANK(nic->ioaddr, 3); + revision = inw(nic->ioaddr + REVISION); version_string = chip_ids[(revision >> 4) & 0xF]; if (((revision & 0xF0) >> 4 == CHIP_9196) && @@ -469,12 +430,12 @@ static int smc9000_probe(struct dev *dev, unsigned short *probe_addrs) if ( !version_string ) { /* I shouldn't get here because this call was done before.... */ - goto out; + return 0; } /* is it using AUI or 10BaseT ? */ - SMC_SELECT_BANK(smc9000_base, 1); - if (inw(smc9000_base + CONFIG) & CFG_AUI_SELECT) + SMC_SELECT_BANK(nic->ioaddr, 1); + if (inw(nic->ioaddr + CONFIG) & CFG_AUI_SELECT) media = 2; else media = 1; @@ -482,67 +443,63 @@ static int smc9000_probe(struct dev *dev, unsigned short *probe_addrs) if_string = interfaces[media - 1]; /* now, reset the chip, and put it into a known state */ - smc_reset(smc9000_base); + smc_reset(nic->ioaddr); printf("SMC9000 %s\n", smc9000_version); -#ifdef SMC9000_VERBOSE - printf("Copyright (C) 1998 Daniel Engstr\x94m\n"); - printf("Copyright (C) 1996 Eric Stahlman\n"); -#endif + DBG("Copyright (C) 1998 Daniel Engstr\x94m\n"); + DBG("Copyright (C) 1996 Eric Stahlman\n"); printf("%s rev:%d I/O port:%hX Interface:%s RAM:%d bytes \n", version_string, revision & 0xF, - smc9000_base, if_string, memory ); + nic->ioaddr, if_string, memory ); /* * Print the Ethernet address */ printf("Ethernet MAC address: %!\n", nic->node_addr); - SMC_SELECT_BANK(smc9000_base, 0); + SMC_SELECT_BANK(nic->ioaddr, 0); /* see the header file for options in TCR/RCR NORMAL*/ - _outw(TCR_NORMAL, smc9000_base + TCR); - _outw(RCR_NORMAL, smc9000_base + RCR); + _outw(TCR_NORMAL, nic->ioaddr + TCR); + _outw(RCR_NORMAL, nic->ioaddr + RCR); /* Select which interface to use */ - SMC_SELECT_BANK(smc9000_base, 1); + SMC_SELECT_BANK(nic->ioaddr, 1); if ( media == 1 ) { - _outw( inw( smc9000_base + CONFIG ) & ~CFG_AUI_SELECT, - smc9000_base + CONFIG ); + _outw( inw( nic->ioaddr + CONFIG ) & ~CFG_AUI_SELECT, + nic->ioaddr + CONFIG ); } else if ( media == 2 ) { - _outw( inw( smc9000_base + CONFIG ) | CFG_AUI_SELECT, - smc9000_base + CONFIG ); + _outw( inw( nic->ioaddr + CONFIG ) | CFG_AUI_SELECT, + nic->ioaddr + CONFIG ); } -static struct nic_operations smc9000_operations; -static struct nic_operations smc9000_operations = { - .connect = dummy_connect, - .poll = smc9000_poll, - .transmit = smc9000_transmit, - .irq = smc9000_irq, - .disable = smc9000_disable, -}; + nic->nic_op = &smc9000_operations; - - /* Based on PnP ISA map */ - dev->devid.vendor_id = htons(GENERIC_ISAPNP_VENDOR); - dev->devid.device_id = htons(0x8228); - return 1; - -out: -#ifdef SMC9000_VERBOSE - /* printf("No SMC9000 adapters found\n"); */ -#endif - smc9000_base = 0; - - return (0); } -static struct isa_driver smc9000_driver __isa_driver = { - .type = NIC_DRIVER, - .name = "SMC9000", - .probe = smc9000_probe, - .ioaddrs = 0, +/* + * The SMC9000 can be at any of the following port addresses. To + * change for a slightly different card, you can add it to the array. + * + */ +static struct isa_probe_addr smc9000_probe_addrs[] = { + { 0x200 }, { 0x220 }, { 0x240 }, { 0x260 }, + { 0x280 }, { 0x2A0 }, { 0x2C0 }, { 0x2E0 }, + { 0x300 }, { 0x320 }, { 0x340 }, { 0x360 }, + { 0x380 }, { 0x3A0 }, { 0x3C0 }, { 0x3E0 }, }; -ISA_ROM("smc9000","SMC9000"); + +static struct isa_driver smc9000_driver = +ISA_DRIVER ( "SMC9000", smc9000_probe_addrs, smc9000_probe_addr, + GENERIC_ISAPNP_VENDOR, 0x8228 ); + +BOOT_DRIVER ( "SMC9000", find_isa_boot_device, smc9000_driver, smc9000_probe ); + +ISA_ROM( "smc9000", "SMC9000" ); + +/* + * Local variables: + * c-basic-offset: 3 + * End: + */