Make gpxe build.
[gpxe/hramrach.git] / src / drivers / net / smc9000.c
blobcd5242e7671df1914c63155820d4d2f79ac31cfc
1 #ifdef ALLMULTI
2 #error multicast support is not yet implemented
3 #endif
4 /*------------------------------------------------------------------------
5 * smc9000.c
6 * This is a Etherboot driver for SMC's 9000 series of Ethernet cards.
8 * Copyright (C) 1998 Daniel Engström <daniel.engstrom@riksnett.no>
9 * Based on the Linux SMC9000 driver, smc9194.c by Eric Stahlman
10 * Copyright (C) 1996 by Erik Stahlman <eric@vt.edu>
12 * This software may be used and distributed according to the terms
13 * of the GNU Public License, incorporated herein by reference.
15 * "Features" of the SMC chip:
16 * 4608 byte packet memory. ( for the 91C92/4. Others have more )
17 * EEPROM for configuration
18 * AUI/TP selection
20 * Authors
21 * Erik Stahlman <erik@vt.edu>
22 * Daniel Engström <daniel.engstrom@riksnett.no>
24 * History
25 * 98-09-25 Daniel Engström Etherboot driver crated from Eric's
26 * Linux driver.
28 *---------------------------------------------------------------------------*/
30 FILE_LICENCE ( GPL_ANY );
32 #define LINUX_OUT_MACROS 1
33 #define SMC9000_DEBUG 0
35 #if SMC9000_DEBUG > 1
36 #define PRINTK2 printf
37 #else
38 #define PRINTK2(args...)
39 #endif
41 #include <gpxe/ethernet.h>
42 #include <errno.h>
43 #include "etherboot.h"
44 #include "nic.h"
45 #include <gpxe/isa.h>
46 #include "smc9000.h"
48 # define _outb outb
49 # define _outw outw
51 static const char smc9000_version[] = "Version 0.99 98-09-30";
52 static const char *interfaces[ 2 ] = { "TP", "AUI" };
53 static const char *chip_ids[ 15 ] = {
54 NULL, NULL, NULL,
55 /* 3 */ "SMC91C90/91C92",
56 /* 4 */ "SMC91C94",
57 /* 5 */ "SMC91C95",
58 NULL,
59 /* 7 */ "SMC91C100",
60 /* 8 */ "SMC91C100FD",
61 /* 9 */ "SMC91C11xFD",
62 NULL, NULL,
63 NULL, NULL, NULL
65 static const char smc91c96_id[] = "SMC91C96";
67 /*------------------------------------------------------------
68 . Reads a register from the MII Management serial interface
69 .-------------------------------------------------------------*/
70 static word smc_read_phy_register(int ioaddr, byte phyaddr, byte phyreg)
72 int oldBank;
73 unsigned int i;
74 byte mask;
75 word mii_reg;
76 byte bits[64];
77 int clk_idx = 0;
78 int input_idx;
79 word phydata;
81 // 32 consecutive ones on MDO to establish sync
82 for (i = 0; i < 32; ++i)
83 bits[clk_idx++] = MII_MDOE | MII_MDO;
85 // Start code <01>
86 bits[clk_idx++] = MII_MDOE;
87 bits[clk_idx++] = MII_MDOE | MII_MDO;
89 // Read command <10>
90 bits[clk_idx++] = MII_MDOE | MII_MDO;
91 bits[clk_idx++] = MII_MDOE;
93 // Output the PHY address, msb first
94 mask = (byte)0x10;
95 for (i = 0; i < 5; ++i)
97 if (phyaddr & mask)
98 bits[clk_idx++] = MII_MDOE | MII_MDO;
99 else
100 bits[clk_idx++] = MII_MDOE;
102 // Shift to next lowest bit
103 mask >>= 1;
106 // Output the phy register number, msb first
107 mask = (byte)0x10;
108 for (i = 0; i < 5; ++i)
110 if (phyreg & mask)
111 bits[clk_idx++] = MII_MDOE | MII_MDO;
112 else
113 bits[clk_idx++] = MII_MDOE;
115 // Shift to next lowest bit
116 mask >>= 1;
119 // Tristate and turnaround (2 bit times)
120 bits[clk_idx++] = 0;
121 //bits[clk_idx++] = 0;
123 // Input starts at this bit time
124 input_idx = clk_idx;
126 // Will input 16 bits
127 for (i = 0; i < 16; ++i)
128 bits[clk_idx++] = 0;
130 // Final clock bit
131 bits[clk_idx++] = 0;
133 // Save the current bank
134 oldBank = inw( ioaddr+BANK_SELECT );
136 // Select bank 3
137 SMC_SELECT_BANK(ioaddr, 3);
139 // Get the current MII register value
140 mii_reg = inw( ioaddr+MII_REG );
142 // Turn off all MII Interface bits
143 mii_reg &= ~(MII_MDOE|MII_MCLK|MII_MDI|MII_MDO);
145 // Clock all 64 cycles
146 for (i = 0; i < sizeof(bits); ++i)
148 // Clock Low - output data
149 outw( mii_reg | bits[i], ioaddr+MII_REG );
150 udelay(50);
153 // Clock Hi - input data
154 outw( mii_reg | bits[i] | MII_MCLK, ioaddr+MII_REG );
155 udelay(50);
156 bits[i] |= inw( ioaddr+MII_REG ) & MII_MDI;
159 // Return to idle state
160 // Set clock to low, data to low, and output tristated
161 outw( mii_reg, ioaddr+MII_REG );
162 udelay(50);
164 // Restore original bank select
165 SMC_SELECT_BANK(ioaddr, oldBank);
167 // Recover input data
168 phydata = 0;
169 for (i = 0; i < 16; ++i)
171 phydata <<= 1;
173 if (bits[input_idx++] & MII_MDI)
174 phydata |= 0x0001;
177 #if (SMC_DEBUG > 2 )
178 printf("smc_read_phy_register(): phyaddr=%x,phyreg=%x,phydata=%x\n",
179 phyaddr, phyreg, phydata);
180 #endif
182 return(phydata);
186 /*------------------------------------------------------------
187 . Writes a register to the MII Management serial interface
188 .-------------------------------------------------------------*/
189 static void smc_write_phy_register(int ioaddr,
190 byte phyaddr, byte phyreg, word phydata)
192 int oldBank;
193 unsigned int i;
194 word mask;
195 word mii_reg;
196 byte bits[65];
197 int clk_idx = 0;
199 // 32 consecutive ones on MDO to establish sync
200 for (i = 0; i < 32; ++i)
201 bits[clk_idx++] = MII_MDOE | MII_MDO;
203 // Start code <01>
204 bits[clk_idx++] = MII_MDOE;
205 bits[clk_idx++] = MII_MDOE | MII_MDO;
207 // Write command <01>
208 bits[clk_idx++] = MII_MDOE;
209 bits[clk_idx++] = MII_MDOE | MII_MDO;
211 // Output the PHY address, msb first
212 mask = (byte)0x10;
213 for (i = 0; i < 5; ++i)
215 if (phyaddr & mask)
216 bits[clk_idx++] = MII_MDOE | MII_MDO;
217 else
218 bits[clk_idx++] = MII_MDOE;
220 // Shift to next lowest bit
221 mask >>= 1;
224 // Output the phy register number, msb first
225 mask = (byte)0x10;
226 for (i = 0; i < 5; ++i)
228 if (phyreg & mask)
229 bits[clk_idx++] = MII_MDOE | MII_MDO;
230 else
231 bits[clk_idx++] = MII_MDOE;
233 // Shift to next lowest bit
234 mask >>= 1;
237 // Tristate and turnaround (2 bit times)
238 bits[clk_idx++] = 0;
239 bits[clk_idx++] = 0;
241 // Write out 16 bits of data, msb first
242 mask = 0x8000;
243 for (i = 0; i < 16; ++i)
245 if (phydata & mask)
246 bits[clk_idx++] = MII_MDOE | MII_MDO;
247 else
248 bits[clk_idx++] = MII_MDOE;
250 // Shift to next lowest bit
251 mask >>= 1;
254 // Final clock bit (tristate)
255 bits[clk_idx++] = 0;
257 // Save the current bank
258 oldBank = inw( ioaddr+BANK_SELECT );
260 // Select bank 3
261 SMC_SELECT_BANK(ioaddr, 3);
263 // Get the current MII register value
264 mii_reg = inw( ioaddr+MII_REG );
266 // Turn off all MII Interface bits
267 mii_reg &= ~(MII_MDOE|MII_MCLK|MII_MDI|MII_MDO);
269 // Clock all cycles
270 for (i = 0; i < sizeof(bits); ++i)
272 // Clock Low - output data
273 outw( mii_reg | bits[i], ioaddr+MII_REG );
274 udelay(50);
277 // Clock Hi - input data
278 outw( mii_reg | bits[i] | MII_MCLK, ioaddr+MII_REG );
279 udelay(50);
280 bits[i] |= inw( ioaddr+MII_REG ) & MII_MDI;
283 // Return to idle state
284 // Set clock to low, data to low, and output tristated
285 outw( mii_reg, ioaddr+MII_REG );
286 udelay(50);
288 // Restore original bank select
289 SMC_SELECT_BANK(ioaddr, oldBank);
291 #if (SMC_DEBUG > 2 )
292 printf("smc_write_phy_register(): phyaddr=%x,phyreg=%x,phydata=%x\n",
293 phyaddr, phyreg, phydata);
294 #endif
298 /*------------------------------------------------------------
299 . Finds and reports the PHY address
300 .-------------------------------------------------------------*/
301 static int smc_detect_phy(int ioaddr, byte *pphyaddr)
303 word phy_id1;
304 word phy_id2;
305 int phyaddr;
306 int found = 0;
308 // Scan all 32 PHY addresses if necessary
309 for (phyaddr = 0; phyaddr < 32; ++phyaddr)
311 // Read the PHY identifiers
312 phy_id1 = smc_read_phy_register(ioaddr, phyaddr, PHY_ID1_REG);
313 phy_id2 = smc_read_phy_register(ioaddr, phyaddr, PHY_ID2_REG);
315 // Make sure it is a valid identifier
316 if ((phy_id2 > 0x0000) && (phy_id2 < 0xffff) &&
317 (phy_id1 > 0x0000) && (phy_id1 < 0xffff))
319 if ((phy_id1 != 0x8000) && (phy_id2 != 0x8000))
321 // Save the PHY's address
322 *pphyaddr = phyaddr;
323 found = 1;
324 break;
329 if (!found)
331 printf("No PHY found\n");
332 return(0);
335 // Set the PHY type
336 if ( (phy_id1 == 0x0016) && ((phy_id2 & 0xFFF0) == 0xF840 ) )
338 printf("PHY=LAN83C183 (LAN91C111 Internal)\n");
341 if ( (phy_id1 == 0x0282) && ((phy_id2 & 0xFFF0) == 0x1C50) )
343 printf("PHY=LAN83C180\n");
346 return(1);
349 /*------------------------------------------------------------
350 . Configures the specified PHY using Autonegotiation. Calls
351 . smc_phy_fixed() if the user has requested a certain config.
352 .-------------------------------------------------------------*/
353 static void smc_phy_configure(int ioaddr)
355 int timeout;
356 byte phyaddr;
357 word my_phy_caps; // My PHY capabilities
358 word my_ad_caps; // My Advertised capabilities
359 word status;
360 int failed = 0;
361 int rpc_cur_mode = RPC_DEFAULT;
362 int lastPhy18;
364 // Find the address and type of our phy
365 if (!smc_detect_phy(ioaddr, &phyaddr))
367 return;
370 // Reset the PHY, setting all other bits to zero
371 smc_write_phy_register(ioaddr, phyaddr, PHY_CNTL_REG, PHY_CNTL_RST);
373 // Wait for the reset to complete, or time out
374 timeout = 6; // Wait up to 3 seconds
375 while (timeout--)
377 if (!(smc_read_phy_register(ioaddr, phyaddr, PHY_CNTL_REG)
378 & PHY_CNTL_RST))
380 // reset complete
381 break;
384 mdelay(500); // wait 500 millisecs
387 if (timeout < 1)
389 PRINTK2("PHY reset timed out\n");
390 return;
393 // Read PHY Register 18, Status Output
394 lastPhy18 = smc_read_phy_register(ioaddr, phyaddr, PHY_INT_REG);
396 // Enable PHY Interrupts (for register 18)
397 // Interrupts listed here are disabled
398 smc_write_phy_register(ioaddr, phyaddr, PHY_MASK_REG,
399 PHY_INT_LOSSSYNC | PHY_INT_CWRD | PHY_INT_SSD |
400 PHY_INT_ESD | PHY_INT_RPOL | PHY_INT_JAB |
401 PHY_INT_SPDDET | PHY_INT_DPLXDET);
403 /* Configure the Receive/Phy Control register */
404 SMC_SELECT_BANK(ioaddr, 0);
405 outw( rpc_cur_mode, ioaddr + RPC_REG );
407 // Copy our capabilities from PHY_STAT_REG to PHY_AD_REG
408 my_phy_caps = smc_read_phy_register(ioaddr, phyaddr, PHY_STAT_REG);
409 my_ad_caps = PHY_AD_CSMA; // I am CSMA capable
411 if (my_phy_caps & PHY_STAT_CAP_T4)
412 my_ad_caps |= PHY_AD_T4;
414 if (my_phy_caps & PHY_STAT_CAP_TXF)
415 my_ad_caps |= PHY_AD_TX_FDX;
417 if (my_phy_caps & PHY_STAT_CAP_TXH)
418 my_ad_caps |= PHY_AD_TX_HDX;
420 if (my_phy_caps & PHY_STAT_CAP_TF)
421 my_ad_caps |= PHY_AD_10_FDX;
423 if (my_phy_caps & PHY_STAT_CAP_TH)
424 my_ad_caps |= PHY_AD_10_HDX;
426 // Update our Auto-Neg Advertisement Register
427 smc_write_phy_register(ioaddr, phyaddr, PHY_AD_REG, my_ad_caps);
429 PRINTK2("phy caps=%x\n", my_phy_caps);
430 PRINTK2("phy advertised caps=%x\n", my_ad_caps);
432 // Restart auto-negotiation process in order to advertise my caps
433 smc_write_phy_register( ioaddr, phyaddr, PHY_CNTL_REG,
434 PHY_CNTL_ANEG_EN | PHY_CNTL_ANEG_RST );
436 // Wait for the auto-negotiation to complete. This may take from
437 // 2 to 3 seconds.
438 // Wait for the reset to complete, or time out
439 timeout = 20; // Wait up to 10 seconds
440 while (timeout--)
442 status = smc_read_phy_register(ioaddr, phyaddr, PHY_STAT_REG);
443 if (status & PHY_STAT_ANEG_ACK)
445 // auto-negotiate complete
446 break;
449 mdelay(500); // wait 500 millisecs
451 // Restart auto-negotiation if remote fault
452 if (status & PHY_STAT_REM_FLT)
454 PRINTK2("PHY remote fault detected\n");
456 // Restart auto-negotiation
457 PRINTK2("PHY restarting auto-negotiation\n");
458 smc_write_phy_register( ioaddr, phyaddr, PHY_CNTL_REG,
459 PHY_CNTL_ANEG_EN | PHY_CNTL_ANEG_RST |
460 PHY_CNTL_SPEED | PHY_CNTL_DPLX);
464 if (timeout < 1)
466 PRINTK2("PHY auto-negotiate timed out\n");
467 failed = 1;
470 // Fail if we detected an auto-negotiate remote fault
471 if (status & PHY_STAT_REM_FLT)
473 PRINTK2("PHY remote fault detected\n");
474 failed = 1;
477 // Set our sysctl parameters to match auto-negotiation results
478 if ( lastPhy18 & PHY_INT_SPDDET )
480 PRINTK2("PHY 100BaseT\n");
481 rpc_cur_mode |= RPC_SPEED;
483 else
485 PRINTK2("PHY 10BaseT\n");
486 rpc_cur_mode &= ~RPC_SPEED;
489 if ( lastPhy18 & PHY_INT_DPLXDET )
491 PRINTK2("PHY Full Duplex\n");
492 rpc_cur_mode |= RPC_DPLX;
494 else
496 PRINTK2("PHY Half Duplex\n");
497 rpc_cur_mode &= ~RPC_DPLX;
500 // Re-Configure the Receive/Phy Control register
501 outw( rpc_cur_mode, ioaddr + RPC_REG );
502 return (void) failed;
506 * Function: smc_reset( int ioaddr )
507 * Purpose:
508 * This sets the SMC91xx chip to its normal state, hopefully from whatever
509 * mess that any other DOS driver has put it in.
511 * Maybe I should reset more registers to defaults in here? SOFTRESET should
512 * do that for me.
514 * Method:
515 * 1. send a SOFT RESET
516 * 2. wait for it to finish
517 * 3. reset the memory management unit
518 * 4. clear all interrupts
521 static void smc_reset(int ioaddr)
523 /* This resets the registers mostly to defaults, but doesn't
524 * affect EEPROM. That seems unnecessary */
525 SMC_SELECT_BANK(ioaddr, 0);
526 _outw( RCR_SOFTRESET, ioaddr + RCR );
528 /* this should pause enough for the chip to be happy */
529 SMC_DELAY(ioaddr);
531 /* Set the transmit and receive configuration registers to
532 * default values */
533 _outw(RCR_CLEAR, ioaddr + RCR);
534 _outw(TCR_CLEAR, ioaddr + TCR);
536 /* Reset the MMU */
537 SMC_SELECT_BANK(ioaddr, 2);
538 _outw( MC_RESET, ioaddr + MMU_CMD );
540 /* Note: It doesn't seem that waiting for the MMU busy is needed here,
541 * but this is a place where future chipsets _COULD_ break. Be wary
542 * of issuing another MMU command right after this */
543 _outb(0, ioaddr + INT_MASK);
547 /*----------------------------------------------------------------------
548 * Function: smc9000_probe_addr( int ioaddr )
550 * Purpose:
551 * Tests to see if a given ioaddr points to an SMC9xxx chip.
552 * Returns a 1 on success
554 * Algorithm:
555 * (1) see if the high byte of BANK_SELECT is 0x33
556 * (2) compare the ioaddr with the base register's address
557 * (3) see if I recognize the chip ID in the appropriate register
559 * ---------------------------------------------------------------------
561 static int smc9000_probe_addr( isa_probe_addr_t ioaddr )
563 word bank;
564 word revision_register;
565 word base_address_register;
567 /* First, see if the high byte is 0x33 */
568 bank = inw(ioaddr + BANK_SELECT);
569 if ((bank & 0xFF00) != 0x3300) {
570 return 0;
572 /* The above MIGHT indicate a device, but I need to write to further
573 * test this. */
574 _outw(0x0, ioaddr + BANK_SELECT);
575 bank = inw(ioaddr + BANK_SELECT);
576 if ((bank & 0xFF00) != 0x3300) {
577 return 0;
580 /* well, we've already written once, so hopefully another time won't
581 * hurt. This time, I need to switch the bank register to bank 1,
582 * so I can access the base address register */
583 SMC_SELECT_BANK(ioaddr, 1);
584 base_address_register = inw(ioaddr + BASE);
586 if (ioaddr != (base_address_register >> 3 & 0x3E0)) {
587 DBG("SMC9000: IOADDR %hX doesn't match configuration (%hX)."
588 "Probably not a SMC chip\n",
589 ioaddr, base_address_register >> 3 & 0x3E0);
590 /* well, the base address register didn't match. Must not have
591 * been a SMC chip after all. */
592 return 0;
596 /* check if the revision register is something that I recognize.
597 * These might need to be added to later, as future revisions
598 * could be added. */
599 SMC_SELECT_BANK(ioaddr, 3);
600 revision_register = inw(ioaddr + REVISION);
601 if (!chip_ids[(revision_register >> 4) & 0xF]) {
602 /* I don't recognize this chip, so... */
603 DBG( "SMC9000: IO %hX: Unrecognized revision register:"
604 " %hX, Contact author.\n", ioaddr, revision_register );
605 return 0;
608 /* at this point I'll assume that the chip is an SMC9xxx.
609 * It might be prudent to check a listing of MAC addresses
610 * against the hardware address, or do some other tests. */
611 return 1;
615 /**************************************************************************
616 * ETH_TRANSMIT - Transmit a frame
617 ***************************************************************************/
618 static void smc9000_transmit(
619 struct nic *nic,
620 const char *d, /* Destination */
621 unsigned int t, /* Type */
622 unsigned int s, /* size */
623 const char *p) /* Packet */
625 word length; /* real, length incl. header */
626 word numPages;
627 unsigned long time_out;
628 byte packet_no;
629 word status;
630 int i;
632 /* We dont pad here since we can have the hardware doing it for us */
633 length = (s + ETH_HLEN + 1)&~1;
635 /* convert to MMU pages */
636 numPages = length / 256;
638 if (numPages > 7 ) {
639 DBG("SMC9000: Far too big packet error. \n");
640 return;
643 /* dont try more than, say 30 times */
644 for (i=0;i<30;i++) {
645 /* now, try to allocate the memory */
646 SMC_SELECT_BANK(nic->ioaddr, 2);
647 _outw(MC_ALLOC | numPages, nic->ioaddr + MMU_CMD);
649 status = 0;
650 /* wait for the memory allocation to finnish */
651 for (time_out = currticks() + 5*TICKS_PER_SEC; currticks() < time_out; ) {
652 status = inb(nic->ioaddr + INTERRUPT);
653 if ( status & IM_ALLOC_INT ) {
654 /* acknowledge the interrupt */
655 _outb(IM_ALLOC_INT, nic->ioaddr + INTERRUPT);
656 break;
660 if ((status & IM_ALLOC_INT) != 0 ) {
661 /* We've got the memory */
662 break;
663 } else {
664 printf("SMC9000: Memory allocation timed out, resetting MMU.\n");
665 _outw(MC_RESET, nic->ioaddr + MMU_CMD);
669 /* If I get here, I _know_ there is a packet slot waiting for me */
670 packet_no = inb(nic->ioaddr + PNR_ARR + 1);
671 if (packet_no & 0x80) {
672 /* or isn't there? BAD CHIP! */
673 printf("SMC9000: Memory allocation failed. \n");
674 return;
677 /* we have a packet address, so tell the card to use it */
678 _outb(packet_no, nic->ioaddr + PNR_ARR);
680 /* point to the beginning of the packet */
681 _outw(PTR_AUTOINC, nic->ioaddr + POINTER);
683 #if SMC9000_DEBUG > 2
684 printf("Trying to xmit packet of length %hX\n", length );
685 #endif
687 /* send the packet length ( +6 for status, length and ctl byte )
688 * and the status word ( set to zeros ) */
689 _outw(0, nic->ioaddr + DATA_1 );
691 /* send the packet length ( +6 for status words, length, and ctl) */
692 _outb((length+6) & 0xFF, nic->ioaddr + DATA_1);
693 _outb((length+6) >> 8 , nic->ioaddr + DATA_1);
695 /* Write the contents of the packet */
697 /* The ethernet header first... */
698 outsw(nic->ioaddr + DATA_1, d, ETH_ALEN >> 1);
699 outsw(nic->ioaddr + DATA_1, nic->node_addr, ETH_ALEN >> 1);
700 _outw(htons(t), nic->ioaddr + DATA_1);
702 /* ... the data ... */
703 outsw(nic->ioaddr + DATA_1 , p, s >> 1);
705 /* ... and the last byte, if there is one. */
706 if ((s & 1) == 0) {
707 _outw(0, nic->ioaddr + DATA_1);
708 } else {
709 _outb(p[s-1], nic->ioaddr + DATA_1);
710 _outb(0x20, nic->ioaddr + DATA_1);
713 /* and let the chipset deal with it */
714 _outw(MC_ENQUEUE , nic->ioaddr + MMU_CMD);
716 status = 0; time_out = currticks() + 5*TICKS_PER_SEC;
717 do {
718 status = inb(nic->ioaddr + INTERRUPT);
720 if ((status & IM_TX_INT ) != 0) {
721 word tx_status;
723 /* ack interrupt */
724 _outb(IM_TX_INT, nic->ioaddr + INTERRUPT);
726 packet_no = inw(nic->ioaddr + FIFO_PORTS);
727 packet_no &= 0x7F;
729 /* select this as the packet to read from */
730 _outb( packet_no, nic->ioaddr + PNR_ARR );
732 /* read the first word from this packet */
733 _outw( PTR_AUTOINC | PTR_READ, nic->ioaddr + POINTER );
735 tx_status = inw( nic->ioaddr + DATA_1 );
737 if (0 == (tx_status & TS_SUCCESS)) {
738 DBG("SMC9000: TX FAIL STATUS: %hX \n", tx_status);
739 /* re-enable transmit */
740 SMC_SELECT_BANK(nic->ioaddr, 0);
741 _outw(inw(nic->ioaddr + TCR ) | TCR_ENABLE, nic->ioaddr + TCR );
744 /* kill the packet */
745 SMC_SELECT_BANK(nic->ioaddr, 2);
746 _outw(MC_FREEPKT, nic->ioaddr + MMU_CMD);
748 return;
750 }while(currticks() < time_out);
752 printf("SMC9000: TX timed out, resetting board\n");
753 smc_reset(nic->ioaddr);
754 return;
757 /**************************************************************************
758 * ETH_POLL - Wait for a frame
759 ***************************************************************************/
760 static int smc9000_poll(struct nic *nic, int retrieve)
762 SMC_SELECT_BANK(nic->ioaddr, 2);
763 if (inw(nic->ioaddr + FIFO_PORTS) & FP_RXEMPTY)
764 return 0;
766 if ( ! retrieve ) return 1;
768 /* start reading from the start of the packet */
769 _outw(PTR_READ | PTR_RCV | PTR_AUTOINC, nic->ioaddr + POINTER);
771 /* First read the status and check that we're ok */
772 if (!(inw(nic->ioaddr + DATA_1) & RS_ERRORS)) {
773 /* Next: read the packet length and mask off the top bits */
774 nic->packetlen = (inw(nic->ioaddr + DATA_1) & 0x07ff);
776 /* the packet length includes the 3 extra words */
777 nic->packetlen -= 6;
778 #if SMC9000_DEBUG > 2
779 printf(" Reading %d words (and %d byte(s))\n",
780 (nic->packetlen >> 1), nic->packetlen & 1);
781 #endif
782 /* read the packet (and the last "extra" word) */
783 insw(nic->ioaddr + DATA_1, nic->packet, (nic->packetlen+2) >> 1);
784 /* is there an odd last byte ? */
785 if (nic->packet[nic->packetlen+1] & 0x20)
786 nic->packetlen++;
788 /* error or good, tell the card to get rid of this packet */
789 _outw(MC_RELEASE, nic->ioaddr + MMU_CMD);
790 return 1;
793 printf("SMC9000: RX error\n");
794 /* error or good, tell the card to get rid of this packet */
795 _outw(MC_RELEASE, nic->ioaddr + MMU_CMD);
796 return 0;
799 static void smc9000_disable ( struct nic *nic, struct isa_device *isa __unused ) {
801 smc_reset(nic->ioaddr);
803 /* no more interrupts for me */
804 SMC_SELECT_BANK(nic->ioaddr, 2);
805 _outb( 0, nic->ioaddr + INT_MASK);
807 /* and tell the card to stay away from that nasty outside world */
808 SMC_SELECT_BANK(nic->ioaddr, 0);
809 _outb( RCR_CLEAR, nic->ioaddr + RCR );
810 _outb( TCR_CLEAR, nic->ioaddr + TCR );
813 static void smc9000_irq(struct nic *nic __unused, irq_action_t action __unused)
815 switch ( action ) {
816 case DISABLE :
817 break;
818 case ENABLE :
819 break;
820 case FORCE :
821 break;
825 static struct nic_operations smc9000_operations = {
826 .connect = dummy_connect,
827 .poll = smc9000_poll,
828 .transmit = smc9000_transmit,
829 .irq = smc9000_irq,
833 /**************************************************************************
834 * ETH_PROBE - Look for an adapter
835 ***************************************************************************/
837 static int smc9000_probe ( struct nic *nic, struct isa_device *isa ) {
839 unsigned short revision;
840 int memory;
841 int media;
842 const char * version_string;
843 const char * if_string;
844 int i;
846 nic->irqno = 0;
847 nic->ioaddr = isa->ioaddr;
850 * Get the MAC address ( bank 1, regs 4 - 9 )
852 SMC_SELECT_BANK(nic->ioaddr, 1);
853 for ( i = 0; i < 6; i += 2 ) {
854 word address;
856 address = inw(nic->ioaddr + ADDR0 + i);
857 nic->node_addr[i+1] = address >> 8;
858 nic->node_addr[i] = address & 0xFF;
861 /* get the memory information */
862 SMC_SELECT_BANK(nic->ioaddr, 0);
863 memory = ( inw(nic->ioaddr + MCR) >> 9 ) & 0x7; /* multiplier */
864 memory *= 256 * (inw(nic->ioaddr + MIR) & 0xFF);
867 * Now, I want to find out more about the chip. This is sort of
868 * redundant, but it's cleaner to have it in both, rather than having
869 * one VERY long probe procedure.
871 SMC_SELECT_BANK(nic->ioaddr, 3);
872 revision = inw(nic->ioaddr + REVISION);
873 version_string = chip_ids[(revision >> 4) & 0xF];
875 if (((revision & 0xF0) >> 4 == CHIP_9196) &&
876 ((revision & 0x0F) >= REV_9196)) {
877 /* This is a 91c96. 'c96 has the same chip id as 'c94 (4) but
878 * a revision starting at 6 */
879 version_string = smc91c96_id;
882 if ( !version_string ) {
883 /* I shouldn't get here because this call was done before.... */
884 return 0;
887 /* is it using AUI or 10BaseT ? */
888 SMC_SELECT_BANK(nic->ioaddr, 1);
889 if (inw(nic->ioaddr + CONFIG) & CFG_AUI_SELECT)
890 media = 2;
891 else
892 media = 1;
894 if_string = interfaces[media - 1];
896 /* now, reset the chip, and put it into a known state */
897 smc_reset(nic->ioaddr);
899 printf("SMC9000 %s\n", smc9000_version);
900 DBG("Copyright (C) 1998 Daniel Engstr\x94m\n");
901 DBG("Copyright (C) 1996 Eric Stahlman\n");
903 printf("%s rev:%d I/O port:%hX Interface:%s RAM:%d bytes \n",
904 version_string, revision & 0xF,
905 nic->ioaddr, if_string, memory );
907 DBG ( "Ethernet MAC address: %s\n", eth_ntoa ( nic->node_addr ) );
909 SMC_SELECT_BANK(nic->ioaddr, 0);
911 /* see the header file for options in TCR/RCR NORMAL*/
912 _outw(TCR_NORMAL, nic->ioaddr + TCR);
913 _outw(RCR_NORMAL, nic->ioaddr + RCR);
915 /* Select which interface to use */
916 SMC_SELECT_BANK(nic->ioaddr, 1);
917 if ( media == 1 ) {
918 _outw( inw( nic->ioaddr + CONFIG ) & ~CFG_AUI_SELECT,
919 nic->ioaddr + CONFIG );
921 else if ( media == 2 ) {
922 _outw( inw( nic->ioaddr + CONFIG ) | CFG_AUI_SELECT,
923 nic->ioaddr + CONFIG );
926 smc_phy_configure(nic->ioaddr);
928 nic->nic_op = &smc9000_operations;
929 return 1;
933 * The SMC9000 can be at any of the following port addresses. To
934 * change for a slightly different card, you can add it to the array.
937 static isa_probe_addr_t smc9000_probe_addrs[] = {
938 0x200, 0x220, 0x240, 0x260, 0x280, 0x2A0, 0x2C0, 0x2E0,
939 0x300, 0x320, 0x340, 0x360, 0x380, 0x3A0, 0x3C0, 0x3E0,
942 ISA_DRIVER ( smc9000_driver, smc9000_probe_addrs, smc9000_probe_addr,
943 GENERIC_ISAPNP_VENDOR, 0x8228 );
945 DRIVER ( "SMC9000", nic_driver, isa_driver, smc9000_driver,
946 smc9000_probe, smc9000_disable );
948 ISA_ROM ( "smc9000", "SMC9000" );
951 * Local variables:
952 * c-basic-offset: 8
953 * c-indent-level: 8
954 * tab-width: 8
955 * End: