123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506 |
- #ifdef ALLMULTI
- #error multicast support is not yet implemented
- #endif
-
-
- #define LINUX_OUT_MACROS 1
- #define SMC9000_DEBUG 0
-
- #include "etherboot.h"
- #include "nic.h"
- #include "isa.h"
- #include "smc9000.h"
-
- # define _outb outb
- # define _outw outw
-
- static const char smc9000_version[] = "Version 0.99 98-09-30";
- static const char *interfaces[ 2 ] = { "TP", "AUI" };
- static const char *chip_ids[ 15 ] = {
- NULL, NULL, NULL,
- "SMC91C90/91C92",
- "SMC91C94",
- "SMC91C95",
- NULL,
- "SMC91C100",
- "SMC91C100FD",
- NULL, NULL, NULL,
- NULL, NULL, NULL
- };
- static const char smc91c96_id[] = "SMC91C96";
-
-
- static void smc_reset(int ioaddr)
- {
-
-
- SMC_SELECT_BANK(ioaddr, 0);
- _outw( RCR_SOFTRESET, ioaddr + RCR );
-
-
- SMC_DELAY(ioaddr);
-
-
-
- _outw(RCR_CLEAR, ioaddr + RCR);
- _outw(TCR_CLEAR, ioaddr + TCR);
-
-
- SMC_SELECT_BANK(ioaddr, 2);
- _outw( MC_RESET, ioaddr + MMU_CMD );
-
-
-
- _outb(0, ioaddr + INT_MASK);
- }
-
-
-
- static int smc9000_probe_addr( isa_probe_addr_t ioaddr )
- {
- word bank;
- word revision_register;
- word base_address_register;
-
-
- bank = inw(ioaddr + BANK_SELECT);
- if ((bank & 0xFF00) != 0x3300) {
- return 0;
- }
-
-
- _outw(0x0, ioaddr + BANK_SELECT);
- bank = inw(ioaddr + BANK_SELECT);
- if ((bank & 0xFF00) != 0x3300) {
- return 0;
- }
-
-
-
- SMC_SELECT_BANK(ioaddr, 1);
- base_address_register = inw(ioaddr + BASE);
-
- if (ioaddr != (base_address_register >> 3 & 0x3E0)) {
- DBG("SMC9000: IOADDR %hX doesn't match configuration (%hX)."
- "Probably not a SMC chip\n",
- ioaddr, base_address_register >> 3 & 0x3E0);
-
-
- return 0;
- }
-
-
-
-
- SMC_SELECT_BANK(ioaddr, 3);
- revision_register = inw(ioaddr + REVISION);
- if (!chip_ids[(revision_register >> 4) & 0xF]) {
-
- DBG( "SMC9000: IO %hX: Unrecognized revision register:"
- " %hX, Contact author.\n", ioaddr, revision_register );
- return 0;
- }
-
-
-
- return 1;
- }
-
-
-
- static void smc9000_transmit(
- struct nic *nic,
- const char *d,
- unsigned int t,
- unsigned int s,
- const char *p)
- {
- word length;
- word numPages;
- unsigned long time_out;
- byte packet_no;
- word status;
- int i;
-
-
- length = (s + ETH_HLEN + 1)&~1;
-
-
- numPages = length / 256;
-
- if (numPages > 7 ) {
- DBG("SMC9000: Far too big packet error. \n");
- return;
- }
-
-
- for (i=0;i<30;i++) {
-
- SMC_SELECT_BANK(nic->ioaddr, 2);
- _outw(MC_ALLOC | numPages, nic->ioaddr + MMU_CMD);
-
- status = 0;
-
- for (time_out = currticks() + 5*TICKS_PER_SEC; currticks() < time_out; ) {
- status = inb(nic->ioaddr + INTERRUPT);
- if ( status & IM_ALLOC_INT ) {
-
- _outb(IM_ALLOC_INT, nic->ioaddr + INTERRUPT);
- break;
- }
- }
-
- if ((status & IM_ALLOC_INT) != 0 ) {
-
- break;
- } else {
- printf("SMC9000: Memory allocation timed out, resetting MMU.\n");
- _outw(MC_RESET, nic->ioaddr + MMU_CMD);
- }
- }
-
-
- packet_no = inb(nic->ioaddr + PNR_ARR + 1);
- if (packet_no & 0x80) {
-
- printf("SMC9000: Memory allocation failed. \n");
- return;
- }
-
-
- _outb(packet_no, nic->ioaddr + PNR_ARR);
-
-
- _outw(PTR_AUTOINC, nic->ioaddr + POINTER);
-
- #if SMC9000_DEBUG > 2
- printf("Trying to xmit packet of length %hX\n", length );
- #endif
-
-
-
- _outw(0, nic->ioaddr + DATA_1 );
-
-
- _outb((length+6) & 0xFF, nic->ioaddr + DATA_1);
- _outb((length+6) >> 8 , nic->ioaddr + 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);
-
-
- outsw(nic->ioaddr + DATA_1 , p, s >> 1);
-
-
- if ((s & 1) == 0) {
- _outw(0, nic->ioaddr + DATA_1);
- } else {
- _outb(p[s-1], nic->ioaddr + DATA_1);
- _outb(0x20, nic->ioaddr + DATA_1);
- }
-
-
- _outw(MC_ENQUEUE , nic->ioaddr + MMU_CMD);
-
- status = 0; time_out = currticks() + 5*TICKS_PER_SEC;
- do {
- status = inb(nic->ioaddr + INTERRUPT);
-
- if ((status & IM_TX_INT ) != 0) {
- word tx_status;
-
-
- _outb(IM_TX_INT, nic->ioaddr + INTERRUPT);
-
- packet_no = inw(nic->ioaddr + FIFO_PORTS);
- packet_no &= 0x7F;
-
-
- _outb( packet_no, nic->ioaddr + PNR_ARR );
-
-
- _outw( PTR_AUTOINC | PTR_READ, nic->ioaddr + POINTER );
-
- tx_status = inw( nic->ioaddr + DATA_1 );
-
- if (0 == (tx_status & TS_SUCCESS)) {
- DBG("SMC9000: TX FAIL STATUS: %hX \n", tx_status);
-
- SMC_SELECT_BANK(nic->ioaddr, 0);
- _outw(inw(nic->ioaddr + TCR ) | TCR_ENABLE, nic->ioaddr + TCR );
- }
-
-
- SMC_SELECT_BANK(nic->ioaddr, 2);
- _outw(MC_FREEPKT, nic->ioaddr + MMU_CMD);
-
- return;
- }
- }while(currticks() < time_out);
-
- printf("SMC9000: TX timed out, resetting board\n");
- smc_reset(nic->ioaddr);
- return;
- }
-
-
- static int smc9000_poll(struct nic *nic, int retrieve)
- {
- SMC_SELECT_BANK(nic->ioaddr, 2);
- if (inw(nic->ioaddr + FIFO_PORTS) & FP_RXEMPTY)
- return 0;
-
- if ( ! retrieve ) return 1;
-
-
- _outw(PTR_READ | PTR_RCV | PTR_AUTOINC, nic->ioaddr + POINTER);
-
-
- if (!(inw(nic->ioaddr + DATA_1) & RS_ERRORS)) {
-
- nic->packetlen = (inw(nic->ioaddr + DATA_1) & 0x07ff);
-
-
- nic->packetlen -= 6;
- #if SMC9000_DEBUG > 2
- printf(" Reading %d words (and %d byte(s))\n",
- (nic->packetlen >> 1), nic->packetlen & 1);
- #endif
-
- insw(nic->ioaddr + DATA_1, nic->packet, (nic->packetlen+2) >> 1);
-
- if (nic->packet[nic->packetlen+1] & 0x20)
- nic->packetlen++;
-
-
- _outw(MC_RELEASE, nic->ioaddr + MMU_CMD);
- return 1;
- }
-
- printf("SMC9000: RX error\n");
-
- _outw(MC_RELEASE, nic->ioaddr + MMU_CMD);
- return 0;
- }
-
- static void smc9000_disable ( struct nic *nic, struct isa_device *isa __unused ) {
- nic_disable ( nic );
- smc_reset(nic->ioaddr);
-
-
- SMC_SELECT_BANK(nic->ioaddr, 2);
- _outb( 0, nic->ioaddr + INT_MASK);
-
-
- 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)
- {
- switch ( action ) {
- case DISABLE :
- break;
- case ENABLE :
- break;
- case FORCE :
- break;
- }
- }
-
- static struct nic_operations smc9000_operations = {
- .connect = dummy_connect,
- .poll = smc9000_poll,
- .transmit = smc9000_transmit,
- .irq = smc9000_irq,
-
- };
-
-
-
- static int smc9000_probe ( struct nic *nic, struct isa_device *isa ) {
-
- unsigned short revision;
- int memory;
- int media;
- const char * version_string;
- const char * if_string;
- int i;
-
- nic->irqno = 0;
- isa_fill_nic ( nic, isa );
- nic->ioaddr = isa->ioaddr;
-
-
-
- SMC_SELECT_BANK(nic->ioaddr, 1);
- for ( i = 0; i < 6; i += 2 ) {
- word address;
-
- address = inw(nic->ioaddr + ADDR0 + i);
- nic->node_addr[i+1] = address >> 8;
- nic->node_addr[i] = address & 0xFF;
- }
-
-
- SMC_SELECT_BANK(nic->ioaddr, 0);
- memory = ( inw(nic->ioaddr + MCR) >> 9 ) & 0x7;
- memory *= 256 * (inw(nic->ioaddr + MIR) & 0xFF);
-
-
-
- SMC_SELECT_BANK(nic->ioaddr, 3);
- revision = inw(nic->ioaddr + REVISION);
- version_string = chip_ids[(revision >> 4) & 0xF];
-
- if (((revision & 0xF0) >> 4 == CHIP_9196) &&
- ((revision & 0x0F) >= REV_9196)) {
-
-
- version_string = smc91c96_id;
- }
-
- if ( !version_string ) {
-
- return 0;
- }
-
-
- SMC_SELECT_BANK(nic->ioaddr, 1);
- if (inw(nic->ioaddr + CONFIG) & CFG_AUI_SELECT)
- media = 2;
- else
- media = 1;
-
- if_string = interfaces[media - 1];
-
-
- smc_reset(nic->ioaddr);
-
- printf("SMC9000 %s\n", smc9000_version);
- 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,
- nic->ioaddr, if_string, memory );
-
-
- printf("Ethernet MAC address: %!\n", nic->node_addr);
-
- SMC_SELECT_BANK(nic->ioaddr, 0);
-
-
- _outw(TCR_NORMAL, nic->ioaddr + TCR);
- _outw(RCR_NORMAL, nic->ioaddr + RCR);
-
-
- SMC_SELECT_BANK(nic->ioaddr, 1);
- if ( media == 1 ) {
- _outw( inw( nic->ioaddr + CONFIG ) & ~CFG_AUI_SELECT,
- nic->ioaddr + CONFIG );
- }
- else if ( media == 2 ) {
- _outw( inw( nic->ioaddr + CONFIG ) | CFG_AUI_SELECT,
- nic->ioaddr + CONFIG );
- }
-
- nic->nic_op = &smc9000_operations;
- return 1;
- }
-
-
- static isa_probe_addr_t smc9000_probe_addrs[] = {
- 0x200, 0x220, 0x240, 0x260, 0x280, 0x2A0, 0x2C0, 0x2E0,
- 0x300, 0x320, 0x340, 0x360, 0x380, 0x3A0, 0x3C0, 0x3E0,
- };
-
- static struct isa_driver smc9000_driver =
- ISA_DRIVER ( smc9000_probe_addrs, smc9000_probe_addr,
- GENERIC_ISAPNP_VENDOR, 0x8228 );
-
- DRIVER ( "SMC9000", nic_driver, isa_driver, smc9000_driver,
- smc9000_probe, smc9000_disable );
-
- ISA_ROM ( "smc9000", "SMC9000" );
-
|