Warnings purge for via-velocity.[ch]
[gpxe.git] / src / drivers / net / smc9000.c
blobc7893e6f901ccdfa4026be704dd5a43d76c4de00
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 *---------------------------------------------------------------------------*/
29 #define LINUX_OUT_MACROS 1
30 #define SMC9000_DEBUG 0
32 #if SMC9000_DEBUG > 1
33 #define PRINTK2 printf
34 #else
35 #define PRINTK2(args...)
36 #endif
38 #include <gpxe/ethernet.h>
39 #include "etherboot.h"
40 #include "nic.h"
41 #include <gpxe/isa.h>
42 #include "timer.h"
43 #include "smc9000.h"
45 # define _outb outb
46 # define _outw outw
48 static const char smc9000_version[] = "Version 0.99 98-09-30";
49 static const char *interfaces[ 2 ] = { "TP", "AUI" };
50 static const char *chip_ids[ 15 ] = {
51 NULL, NULL, NULL,
52 /* 3 */ "SMC91C90/91C92",
53 /* 4 */ "SMC91C94",
54 /* 5 */ "SMC91C95",
55 NULL,
56 /* 7 */ "SMC91C100",
57 /* 8 */ "SMC91C100FD",
58 /* 9 */ "SMC91C11xFD",
59 NULL, NULL,
60 NULL, NULL, NULL
62 static const char smc91c96_id[] = "SMC91C96";
64 /*------------------------------------------------------------
65 . Reads a register from the MII Management serial interface
66 .-------------------------------------------------------------*/
67 static word smc_read_phy_register(int ioaddr, byte phyaddr, byte phyreg)
69 int oldBank;
70 unsigned int i;
71 byte mask;
72 word mii_reg;
73 byte bits[64];
74 int clk_idx = 0;
75 int input_idx;
76 word phydata;
78 // 32 consecutive ones on MDO to establish sync
79 for (i = 0; i < 32; ++i)
80 bits[clk_idx++] = MII_MDOE | MII_MDO;
82 // Start code <01>
83 bits[clk_idx++] = MII_MDOE;
84 bits[clk_idx++] = MII_MDOE | MII_MDO;
86 // Read command <10>
87 bits[clk_idx++] = MII_MDOE | MII_MDO;
88 bits[clk_idx++] = MII_MDOE;
90 // Output the PHY address, msb first
91 mask = (byte)0x10;
92 for (i = 0; i < 5; ++i)
94 if (phyaddr & mask)
95 bits[clk_idx++] = MII_MDOE | MII_MDO;
96 else
97 bits[clk_idx++] = MII_MDOE;
99 // Shift to next lowest bit
100 mask >>= 1;
103 // Output the phy register number, msb first
104 mask = (byte)0x10;
105 for (i = 0; i < 5; ++i)
107 if (phyreg & mask)
108 bits[clk_idx++] = MII_MDOE | MII_MDO;
109 else
110 bits[clk_idx++] = MII_MDOE;
112 // Shift to next lowest bit
113 mask >>= 1;
116 // Tristate and turnaround (2 bit times)
117 bits[clk_idx++] = 0;
118 //bits[clk_idx++] = 0;
120 // Input starts at this bit time
121 input_idx = clk_idx;
123 // Will input 16 bits
124 for (i = 0; i < 16; ++i)
125 bits[clk_idx++] = 0;
127 // Final clock bit
128 bits[clk_idx++] = 0;
130 // Save the current bank
131 oldBank = inw( ioaddr+BANK_SELECT );
133 // Select bank 3
134 SMC_SELECT_BANK(ioaddr, 3);
136 // Get the current MII register value
137 mii_reg = inw( ioaddr+MII_REG );
139 // Turn off all MII Interface bits
140 mii_reg &= ~(MII_MDOE|MII_MCLK|MII_MDI|MII_MDO);
142 // Clock all 64 cycles
143 for (i = 0; i < sizeof(bits); ++i)
145 // Clock Low - output data
146 outw( mii_reg | bits[i], ioaddr+MII_REG );
147 udelay(50);
150 // Clock Hi - input data
151 outw( mii_reg | bits[i] | MII_MCLK, ioaddr+MII_REG );
152 udelay(50);
153 bits[i] |= inw( ioaddr+MII_REG ) & MII_MDI;
156 // Return to idle state
157 // Set clock to low, data to low, and output tristated
158 outw( mii_reg, ioaddr+MII_REG );
159 udelay(50);
161 // Restore original bank select
162 SMC_SELECT_BANK(ioaddr, oldBank);
164 // Recover input data
165 phydata = 0;
166 for (i = 0; i < 16; ++i)
168 phydata <<= 1;
170 if (bits[input_idx++] & MII_MDI)
171 phydata |= 0x0001;
174 #if (SMC_DEBUG > 2 )
175 printf("smc_read_phy_register(): phyaddr=%x,phyreg=%x,phydata=%x\n",
176 phyaddr, phyreg, phydata);
177 #endif
179 return(phydata);
183 /*------------------------------------------------------------
184 . Writes a register to the MII Management serial interface
185 .-------------------------------------------------------------*/
186 static void smc_write_phy_register(int ioaddr,
187 byte phyaddr, byte phyreg, word phydata)
189 int oldBank;
190 unsigned int i;
191 word mask;
192 word mii_reg;
193 byte bits[65];
194 int clk_idx = 0;
196 // 32 consecutive ones on MDO to establish sync
197 for (i = 0; i < 32; ++i)
198 bits[clk_idx++] = MII_MDOE | MII_MDO;
200 // Start code <01>
201 bits[clk_idx++] = MII_MDOE;
202 bits[clk_idx++] = MII_MDOE | MII_MDO;
204 // Write command <01>
205 bits[clk_idx++] = MII_MDOE;
206 bits[clk_idx++] = MII_MDOE | MII_MDO;
208 // Output the PHY address, msb first
209 mask = (byte)0x10;
210 for (i = 0; i < 5; ++i)
212 if (phyaddr & mask)
213 bits[clk_idx++] = MII_MDOE | MII_MDO;
214 else
215 bits[clk_idx++] = MII_MDOE;
217 // Shift to next lowest bit
218 mask >>= 1;
221 // Output the phy register number, msb first
222 mask = (byte)0x10;
223 for (i = 0; i < 5; ++i)
225 if (phyreg & mask)
226 bits[clk_idx++] = MII_MDOE | MII_MDO;
227 else
228 bits[clk_idx++] = MII_MDOE;
230 // Shift to next lowest bit
231 mask >>= 1;
234 // Tristate and turnaround (2 bit times)
235 bits[clk_idx++] = 0;
236 bits[clk_idx++] = 0;
238 // Write out 16 bits of data, msb first
239 mask = 0x8000;
240 for (i = 0; i < 16; ++i)
242 if (phydata & mask)
243 bits[clk_idx++] = MII_MDOE | MII_MDO;
244 else
245 bits[clk_idx++] = MII_MDOE;
247 // Shift to next lowest bit
248 mask >>= 1;
251 // Final clock bit (tristate)
252 bits[clk_idx++] = 0;
254 // Save the current bank
255 oldBank = inw( ioaddr+BANK_SELECT );
257 // Select bank 3
258 SMC_SELECT_BANK(ioaddr, 3);
260 // Get the current MII register value
261 mii_reg = inw( ioaddr+MII_REG );
263 // Turn off all MII Interface bits
264 mii_reg &= ~(MII_MDOE|MII_MCLK|MII_MDI|MII_MDO);
266 // Clock all cycles
267 for (i = 0; i < sizeof(bits); ++i)
269 // Clock Low - output data
270 outw( mii_reg | bits[i], ioaddr+MII_REG );
271 udelay(50);
274 // Clock Hi - input data
275 outw( mii_reg | bits[i] | MII_MCLK, ioaddr+MII_REG );
276 udelay(50);
277 bits[i] |= inw( ioaddr+MII_REG ) & MII_MDI;
280 // Return to idle state
281 // Set clock to low, data to low, and output tristated
282 outw( mii_reg, ioaddr+MII_REG );
283 udelay(50);
285 // Restore original bank select
286 SMC_SELECT_BANK(ioaddr, oldBank);
288 #if (SMC_DEBUG > 2 )
289 printf("smc_write_phy_register(): phyaddr=%x,phyreg=%x,phydata=%x\n",
290 phyaddr, phyreg, phydata);
291 #endif
295 /*------------------------------------------------------------
296 . Finds and reports the PHY address
297 .-------------------------------------------------------------*/
298 static int smc_detect_phy(int ioaddr, byte *pphyaddr)
300 word phy_id1;
301 word phy_id2;
302 int phyaddr;
303 int found = 0;
305 // Scan all 32 PHY addresses if necessary
306 for (phyaddr = 0; phyaddr < 32; ++phyaddr)
308 // Read the PHY identifiers
309 phy_id1 = smc_read_phy_register(ioaddr, phyaddr, PHY_ID1_REG);
310 phy_id2 = smc_read_phy_register(ioaddr, phyaddr, PHY_ID2_REG);
312 // Make sure it is a valid identifier
313 if ((phy_id2 > 0x0000) && (phy_id2 < 0xffff) &&
314 (phy_id1 > 0x0000) && (phy_id1 < 0xffff))
316 if ((phy_id1 != 0x8000) && (phy_id2 != 0x8000))
318 // Save the PHY's address
319 *pphyaddr = phyaddr;
320 found = 1;
321 break;
326 if (!found)
328 printf("No PHY found\n");
329 return(0);
332 // Set the PHY type
333 if ( (phy_id1 == 0x0016) && ((phy_id2 & 0xFFF0) == 0xF840 ) )
335 printf("PHY=LAN83C183 (LAN91C111 Internal)\n");
338 if ( (phy_id1 == 0x0282) && ((phy_id2 & 0xFFF0) == 0x1C50) )
340 printf("PHY=LAN83C180\n");
343 return(1);
346 /*------------------------------------------------------------
347 . Configures the specified PHY using Autonegotiation. Calls
348 . smc_phy_fixed() if the user has requested a certain config.
349 .-------------------------------------------------------------*/
350 static void smc_phy_configure(int ioaddr)
352 int timeout;
353 byte phyaddr;
354 word my_phy_caps; // My PHY capabilities
355 word my_ad_caps; // My Advertised capabilities
356 word status;
357 int failed = 0;
358 int rpc_cur_mode = RPC_DEFAULT;
359 int lastPhy18;
361 // Find the address and type of our phy
362 if (!smc_detect_phy(ioaddr, &phyaddr))
364 return;
367 // Reset the PHY, setting all other bits to zero
368 smc_write_phy_register(ioaddr, phyaddr, PHY_CNTL_REG, PHY_CNTL_RST);
370 // Wait for the reset to complete, or time out
371 timeout = 6; // Wait up to 3 seconds
372 while (timeout--)
374 if (!(smc_read_phy_register(ioaddr, phyaddr, PHY_CNTL_REG)
375 & PHY_CNTL_RST))
377 // reset complete
378 break;
381 mdelay(500); // wait 500 millisecs
384 if (timeout < 1)
386 PRINTK2("PHY reset timed out\n");
387 return;
390 // Read PHY Register 18, Status Output
391 lastPhy18 = smc_read_phy_register(ioaddr, phyaddr, PHY_INT_REG);
393 // Enable PHY Interrupts (for register 18)
394 // Interrupts listed here are disabled
395 smc_write_phy_register(ioaddr, phyaddr, PHY_MASK_REG,
396 PHY_INT_LOSSSYNC | PHY_INT_CWRD | PHY_INT_SSD |
397 PHY_INT_ESD | PHY_INT_RPOL | PHY_INT_JAB |
398 PHY_INT_SPDDET | PHY_INT_DPLXDET);
400 /* Configure the Receive/Phy Control register */
401 SMC_SELECT_BANK(ioaddr, 0);
402 outw( rpc_cur_mode, ioaddr + RPC_REG );
404 // Copy our capabilities from PHY_STAT_REG to PHY_AD_REG
405 my_phy_caps = smc_read_phy_register(ioaddr, phyaddr, PHY_STAT_REG);
406 my_ad_caps = PHY_AD_CSMA; // I am CSMA capable
408 if (my_phy_caps & PHY_STAT_CAP_T4)
409 my_ad_caps |= PHY_AD_T4;
411 if (my_phy_caps & PHY_STAT_CAP_TXF)
412 my_ad_caps |= PHY_AD_TX_FDX;
414 if (my_phy_caps & PHY_STAT_CAP_TXH)
415 my_ad_caps |= PHY_AD_TX_HDX;
417 if (my_phy_caps & PHY_STAT_CAP_TF)
418 my_ad_caps |= PHY_AD_10_FDX;
420 if (my_phy_caps & PHY_STAT_CAP_TH)
421 my_ad_caps |= PHY_AD_10_HDX;
423 // Update our Auto-Neg Advertisement Register
424 smc_write_phy_register(ioaddr, phyaddr, PHY_AD_REG, my_ad_caps);
426 PRINTK2("phy caps=%x\n", my_phy_caps);
427 PRINTK2("phy advertised caps=%x\n", my_ad_caps);
429 // Restart auto-negotiation process in order to advertise my caps
430 smc_write_phy_register( ioaddr, phyaddr, PHY_CNTL_REG,
431 PHY_CNTL_ANEG_EN | PHY_CNTL_ANEG_RST );
433 // Wait for the auto-negotiation to complete. This may take from
434 // 2 to 3 seconds.
435 // Wait for the reset to complete, or time out
436 timeout = 20; // Wait up to 10 seconds
437 while (timeout--)
439 status = smc_read_phy_register(ioaddr, phyaddr, PHY_STAT_REG);
440 if (status & PHY_STAT_ANEG_ACK)
442 // auto-negotiate complete
443 break;
446 mdelay(500); // wait 500 millisecs
448 // Restart auto-negotiation if remote fault
449 if (status & PHY_STAT_REM_FLT)
451 PRINTK2("PHY remote fault detected\n");
453 // Restart auto-negotiation
454 PRINTK2("PHY restarting auto-negotiation\n");
455 smc_write_phy_register( ioaddr, phyaddr, PHY_CNTL_REG,
456 PHY_CNTL_ANEG_EN | PHY_CNTL_ANEG_RST |
457 PHY_CNTL_SPEED | PHY_CNTL_DPLX);
461 if (timeout < 1)
463 PRINTK2("PHY auto-negotiate timed out\n");
464 failed = 1;
467 // Fail if we detected an auto-negotiate remote fault
468 if (status & PHY_STAT_REM_FLT)
470 PRINTK2("PHY remote fault detected\n");
471 failed = 1;
474 // Set our sysctl parameters to match auto-negotiation results
475 if ( lastPhy18 & PHY_INT_SPDDET )
477 PRINTK2("PHY 100BaseT\n");
478 rpc_cur_mode |= RPC_SPEED;
480 else
482 PRINTK2("PHY 10BaseT\n");
483 rpc_cur_mode &= ~RPC_SPEED;
486 if ( lastPhy18 & PHY_INT_DPLXDET )
488 PRINTK2("PHY Full Duplex\n");
489 rpc_cur_mode |= RPC_DPLX;
491 else
493 PRINTK2("PHY Half Duplex\n");
494 rpc_cur_mode &= ~RPC_DPLX;
497 // Re-Configure the Receive/Phy Control register
498 outw( rpc_cur_mode, ioaddr + RPC_REG );
502 * Function: smc_reset( int ioaddr )
503 * Purpose:
504 * This sets the SMC91xx chip to its normal state, hopefully from whatever
505 * mess that any other DOS driver has put it in.
507 * Maybe I should reset more registers to defaults in here? SOFTRESET should
508 * do that for me.
510 * Method:
511 * 1. send a SOFT RESET
512 * 2. wait for it to finish
513 * 3. reset the memory management unit
514 * 4. clear all interrupts
517 static void smc_reset(int ioaddr)
519 /* This resets the registers mostly to defaults, but doesn't
520 * affect EEPROM. That seems unnecessary */
521 SMC_SELECT_BANK(ioaddr, 0);
522 _outw( RCR_SOFTRESET, ioaddr + RCR );
524 /* this should pause enough for the chip to be happy */
525 SMC_DELAY(ioaddr);
527 /* Set the transmit and receive configuration registers to
528 * default values */
529 _outw(RCR_CLEAR, ioaddr + RCR);
530 _outw(TCR_CLEAR, ioaddr + TCR);
532 /* Reset the MMU */
533 SMC_SELECT_BANK(ioaddr, 2);
534 _outw( MC_RESET, ioaddr + MMU_CMD );
536 /* Note: It doesn't seem that waiting for the MMU busy is needed here,
537 * but this is a place where future chipsets _COULD_ break. Be wary
538 * of issuing another MMU command right after this */
539 _outb(0, ioaddr + INT_MASK);
543 /*----------------------------------------------------------------------
544 * Function: smc9000_probe_addr( int ioaddr )
546 * Purpose:
547 * Tests to see if a given ioaddr points to an SMC9xxx chip.
548 * Returns a 1 on success
550 * Algorithm:
551 * (1) see if the high byte of BANK_SELECT is 0x33
552 * (2) compare the ioaddr with the base register's address
553 * (3) see if I recognize the chip ID in the appropriate register
555 * ---------------------------------------------------------------------
557 static int smc9000_probe_addr( isa_probe_addr_t ioaddr )
559 word bank;
560 word revision_register;
561 word base_address_register;
563 /* First, see if the high byte is 0x33 */
564 bank = inw(ioaddr + BANK_SELECT);
565 if ((bank & 0xFF00) != 0x3300) {
566 return 0;
568 /* The above MIGHT indicate a device, but I need to write to further
569 * test this. */
570 _outw(0x0, ioaddr + BANK_SELECT);
571 bank = inw(ioaddr + BANK_SELECT);
572 if ((bank & 0xFF00) != 0x3300) {
573 return 0;
576 /* well, we've already written once, so hopefully another time won't
577 * hurt. This time, I need to switch the bank register to bank 1,
578 * so I can access the base address register */
579 SMC_SELECT_BANK(ioaddr, 1);
580 base_address_register = inw(ioaddr + BASE);
582 if (ioaddr != (base_address_register >> 3 & 0x3E0)) {
583 DBG("SMC9000: IOADDR %hX doesn't match configuration (%hX)."
584 "Probably not a SMC chip\n",
585 ioaddr, base_address_register >> 3 & 0x3E0);
586 /* well, the base address register didn't match. Must not have
587 * been a SMC chip after all. */
588 return 0;
592 /* check if the revision register is something that I recognize.
593 * These might need to be added to later, as future revisions
594 * could be added. */
595 SMC_SELECT_BANK(ioaddr, 3);
596 revision_register = inw(ioaddr + REVISION);
597 if (!chip_ids[(revision_register >> 4) & 0xF]) {
598 /* I don't recognize this chip, so... */
599 DBG( "SMC9000: IO %hX: Unrecognized revision register:"
600 " %hX, Contact author.\n", ioaddr, revision_register );
601 return 0;
604 /* at this point I'll assume that the chip is an SMC9xxx.
605 * It might be prudent to check a listing of MAC addresses
606 * against the hardware address, or do some other tests. */
607 return 1;
611 /**************************************************************************
612 * ETH_TRANSMIT - Transmit a frame
613 ***************************************************************************/
614 static void smc9000_transmit(
615 struct nic *nic,
616 const char *d, /* Destination */
617 unsigned int t, /* Type */
618 unsigned int s, /* size */
619 const char *p) /* Packet */
621 word length; /* real, length incl. header */
622 word numPages;
623 unsigned long time_out;
624 byte packet_no;
625 word status;
626 int i;
628 /* We dont pad here since we can have the hardware doing it for us */
629 length = (s + ETH_HLEN + 1)&~1;
631 /* convert to MMU pages */
632 numPages = length / 256;
634 if (numPages > 7 ) {
635 DBG("SMC9000: Far too big packet error. \n");
636 return;
639 /* dont try more than, say 30 times */
640 for (i=0;i<30;i++) {
641 /* now, try to allocate the memory */
642 SMC_SELECT_BANK(nic->ioaddr, 2);
643 _outw(MC_ALLOC | numPages, nic->ioaddr + MMU_CMD);
645 status = 0;
646 /* wait for the memory allocation to finnish */
647 for (time_out = currticks() + 5*TICKS_PER_SEC; currticks() < time_out; ) {
648 status = inb(nic->ioaddr + INTERRUPT);
649 if ( status & IM_ALLOC_INT ) {
650 /* acknowledge the interrupt */
651 _outb(IM_ALLOC_INT, nic->ioaddr + INTERRUPT);
652 break;
656 if ((status & IM_ALLOC_INT) != 0 ) {
657 /* We've got the memory */
658 break;
659 } else {
660 printf("SMC9000: Memory allocation timed out, resetting MMU.\n");
661 _outw(MC_RESET, nic->ioaddr + MMU_CMD);
665 /* If I get here, I _know_ there is a packet slot waiting for me */
666 packet_no = inb(nic->ioaddr + PNR_ARR + 1);
667 if (packet_no & 0x80) {
668 /* or isn't there? BAD CHIP! */
669 printf("SMC9000: Memory allocation failed. \n");
670 return;
673 /* we have a packet address, so tell the card to use it */
674 _outb(packet_no, nic->ioaddr + PNR_ARR);
676 /* point to the beginning of the packet */
677 _outw(PTR_AUTOINC, nic->ioaddr + POINTER);
679 #if SMC9000_DEBUG > 2
680 printf("Trying to xmit packet of length %hX\n", length );
681 #endif
683 /* send the packet length ( +6 for status, length and ctl byte )
684 * and the status word ( set to zeros ) */
685 _outw(0, nic->ioaddr + DATA_1 );
687 /* send the packet length ( +6 for status words, length, and ctl) */
688 _outb((length+6) & 0xFF, nic->ioaddr + DATA_1);
689 _outb((length+6) >> 8 , nic->ioaddr + DATA_1);
691 /* Write the contents of the packet */
693 /* The ethernet header first... */
694 outsw(nic->ioaddr + DATA_1, d, ETH_ALEN >> 1);
695 outsw(nic->ioaddr + DATA_1, nic->node_addr, ETH_ALEN >> 1);
696 _outw(htons(t), nic->ioaddr + DATA_1);
698 /* ... the data ... */
699 outsw(nic->ioaddr + DATA_1 , p, s >> 1);
701 /* ... and the last byte, if there is one. */
702 if ((s & 1) == 0) {
703 _outw(0, nic->ioaddr + DATA_1);
704 } else {
705 _outb(p[s-1], nic->ioaddr + DATA_1);
706 _outb(0x20, nic->ioaddr + DATA_1);
709 /* and let the chipset deal with it */
710 _outw(MC_ENQUEUE , nic->ioaddr + MMU_CMD);
712 status = 0; time_out = currticks() + 5*TICKS_PER_SEC;
713 do {
714 status = inb(nic->ioaddr + INTERRUPT);
716 if ((status & IM_TX_INT ) != 0) {
717 word tx_status;
719 /* ack interrupt */
720 _outb(IM_TX_INT, nic->ioaddr + INTERRUPT);
722 packet_no = inw(nic->ioaddr + FIFO_PORTS);
723 packet_no &= 0x7F;
725 /* select this as the packet to read from */
726 _outb( packet_no, nic->ioaddr + PNR_ARR );
728 /* read the first word from this packet */
729 _outw( PTR_AUTOINC | PTR_READ, nic->ioaddr + POINTER );
731 tx_status = inw( nic->ioaddr + DATA_1 );
733 if (0 == (tx_status & TS_SUCCESS)) {
734 DBG("SMC9000: TX FAIL STATUS: %hX \n", tx_status);
735 /* re-enable transmit */
736 SMC_SELECT_BANK(nic->ioaddr, 0);
737 _outw(inw(nic->ioaddr + TCR ) | TCR_ENABLE, nic->ioaddr + TCR );
740 /* kill the packet */
741 SMC_SELECT_BANK(nic->ioaddr, 2);
742 _outw(MC_FREEPKT, nic->ioaddr + MMU_CMD);
744 return;
746 }while(currticks() < time_out);
748 printf("SMC9000: TX timed out, resetting board\n");
749 smc_reset(nic->ioaddr);
750 return;
753 /**************************************************************************
754 * ETH_POLL - Wait for a frame
755 ***************************************************************************/
756 static int smc9000_poll(struct nic *nic, int retrieve)
758 SMC_SELECT_BANK(nic->ioaddr, 2);
759 if (inw(nic->ioaddr + FIFO_PORTS) & FP_RXEMPTY)
760 return 0;
762 if ( ! retrieve ) return 1;
764 /* start reading from the start of the packet */
765 _outw(PTR_READ | PTR_RCV | PTR_AUTOINC, nic->ioaddr + POINTER);
767 /* First read the status and check that we're ok */
768 if (!(inw(nic->ioaddr + DATA_1) & RS_ERRORS)) {
769 /* Next: read the packet length and mask off the top bits */
770 nic->packetlen = (inw(nic->ioaddr + DATA_1) & 0x07ff);
772 /* the packet length includes the 3 extra words */
773 nic->packetlen -= 6;
774 #if SMC9000_DEBUG > 2
775 printf(" Reading %d words (and %d byte(s))\n",
776 (nic->packetlen >> 1), nic->packetlen & 1);
777 #endif
778 /* read the packet (and the last "extra" word) */
779 insw(nic->ioaddr + DATA_1, nic->packet, (nic->packetlen+2) >> 1);
780 /* is there an odd last byte ? */
781 if (nic->packet[nic->packetlen+1] & 0x20)
782 nic->packetlen++;
784 /* error or good, tell the card to get rid of this packet */
785 _outw(MC_RELEASE, nic->ioaddr + MMU_CMD);
786 return 1;
789 printf("SMC9000: RX error\n");
790 /* error or good, tell the card to get rid of this packet */
791 _outw(MC_RELEASE, nic->ioaddr + MMU_CMD);
792 return 0;
795 static void smc9000_disable ( struct nic *nic, struct isa_device *isa __unused ) {
797 smc_reset(nic->ioaddr);
799 /* no more interrupts for me */
800 SMC_SELECT_BANK(nic->ioaddr, 2);
801 _outb( 0, nic->ioaddr + INT_MASK);
803 /* and tell the card to stay away from that nasty outside world */
804 SMC_SELECT_BANK(nic->ioaddr, 0);
805 _outb( RCR_CLEAR, nic->ioaddr + RCR );
806 _outb( TCR_CLEAR, nic->ioaddr + TCR );
809 static void smc9000_irq(struct nic *nic __unused, irq_action_t action __unused)
811 switch ( action ) {
812 case DISABLE :
813 break;
814 case ENABLE :
815 break;
816 case FORCE :
817 break;
821 static struct nic_operations smc9000_operations = {
822 .connect = dummy_connect,
823 .poll = smc9000_poll,
824 .transmit = smc9000_transmit,
825 .irq = smc9000_irq,
829 /**************************************************************************
830 * ETH_PROBE - Look for an adapter
831 ***************************************************************************/
833 static int smc9000_probe ( struct nic *nic, struct isa_device *isa ) {
835 unsigned short revision;
836 int memory;
837 int media;
838 const char * version_string;
839 const char * if_string;
840 int i;
842 nic->irqno = 0;
843 isa_fill_nic ( nic, isa );
844 nic->ioaddr = isa->ioaddr;
847 * Get the MAC address ( bank 1, regs 4 - 9 )
849 SMC_SELECT_BANK(nic->ioaddr, 1);
850 for ( i = 0; i < 6; i += 2 ) {
851 word address;
853 address = inw(nic->ioaddr + ADDR0 + i);
854 nic->node_addr[i+1] = address >> 8;
855 nic->node_addr[i] = address & 0xFF;
858 /* get the memory information */
859 SMC_SELECT_BANK(nic->ioaddr, 0);
860 memory = ( inw(nic->ioaddr + MCR) >> 9 ) & 0x7; /* multiplier */
861 memory *= 256 * (inw(nic->ioaddr + MIR) & 0xFF);
864 * Now, I want to find out more about the chip. This is sort of
865 * redundant, but it's cleaner to have it in both, rather than having
866 * one VERY long probe procedure.
868 SMC_SELECT_BANK(nic->ioaddr, 3);
869 revision = inw(nic->ioaddr + REVISION);
870 version_string = chip_ids[(revision >> 4) & 0xF];
872 if (((revision & 0xF0) >> 4 == CHIP_9196) &&
873 ((revision & 0x0F) >= REV_9196)) {
874 /* This is a 91c96. 'c96 has the same chip id as 'c94 (4) but
875 * a revision starting at 6 */
876 version_string = smc91c96_id;
879 if ( !version_string ) {
880 /* I shouldn't get here because this call was done before.... */
881 return 0;
884 /* is it using AUI or 10BaseT ? */
885 SMC_SELECT_BANK(nic->ioaddr, 1);
886 if (inw(nic->ioaddr + CONFIG) & CFG_AUI_SELECT)
887 media = 2;
888 else
889 media = 1;
891 if_string = interfaces[media - 1];
893 /* now, reset the chip, and put it into a known state */
894 smc_reset(nic->ioaddr);
896 printf("SMC9000 %s\n", smc9000_version);
897 DBG("Copyright (C) 1998 Daniel Engstr\x94m\n");
898 DBG("Copyright (C) 1996 Eric Stahlman\n");
900 printf("%s rev:%d I/O port:%hX Interface:%s RAM:%d bytes \n",
901 version_string, revision & 0xF,
902 nic->ioaddr, if_string, memory );
904 DBG ( "Ethernet MAC address: %s\n", eth_ntoa ( nic->node_addr ) );
906 SMC_SELECT_BANK(nic->ioaddr, 0);
908 /* see the header file for options in TCR/RCR NORMAL*/
909 _outw(TCR_NORMAL, nic->ioaddr + TCR);
910 _outw(RCR_NORMAL, nic->ioaddr + RCR);
912 /* Select which interface to use */
913 SMC_SELECT_BANK(nic->ioaddr, 1);
914 if ( media == 1 ) {
915 _outw( inw( nic->ioaddr + CONFIG ) & ~CFG_AUI_SELECT,
916 nic->ioaddr + CONFIG );
918 else if ( media == 2 ) {
919 _outw( inw( nic->ioaddr + CONFIG ) | CFG_AUI_SELECT,
920 nic->ioaddr + CONFIG );
923 smc_phy_configure(nic->ioaddr);
925 nic->nic_op = &smc9000_operations;
926 return 1;
930 * The SMC9000 can be at any of the following port addresses. To
931 * change for a slightly different card, you can add it to the array.
934 static isa_probe_addr_t smc9000_probe_addrs[] = {
935 0x200, 0x220, 0x240, 0x260, 0x280, 0x2A0, 0x2C0, 0x2E0,
936 0x300, 0x320, 0x340, 0x360, 0x380, 0x3A0, 0x3C0, 0x3E0,
939 ISA_DRIVER ( smc9000_driver, smc9000_probe_addrs, smc9000_probe_addr,
940 GENERIC_ISAPNP_VENDOR, 0x8228 );
942 DRIVER ( "SMC9000", nic_driver, isa_driver, smc9000_driver,
943 smc9000_probe, smc9000_disable );
945 ISA_ROM ( "smc9000", "SMC9000" );
948 * Local variables:
949 * c-basic-offset: 3
950 * End: