17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * 3c90x.c -- This file implements the 3c90x driver for etherboot.  Written
37c478bd9Sstevel@tonic-gate  * by Greg Beeley, Greg.Beeley@LightSys.org.  Modified by Steve Smith,
47c478bd9Sstevel@tonic-gate  * Steve.Smith@Juno.Com. Alignment bug fix Neil Newell (nn@icenoir.net).
57c478bd9Sstevel@tonic-gate  *
67c478bd9Sstevel@tonic-gate  * This program Copyright (C) 1999 LightSys Technology Services, Inc.
77c478bd9Sstevel@tonic-gate  * Portions Copyright (C) 1999 Steve Smith
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * This program may be re-distributed in source or binary form, modified,
107c478bd9Sstevel@tonic-gate  * sold, or copied for any purpose, provided that the above copyright message
117c478bd9Sstevel@tonic-gate  * and this text are included with all source copies or derivative works, and
127c478bd9Sstevel@tonic-gate  * provided that the above copyright message and this text are included in the
137c478bd9Sstevel@tonic-gate  * documentation of any binary-only distributions.  This program is distributed
147c478bd9Sstevel@tonic-gate  * WITHOUT ANY WARRANTY, without even the warranty of FITNESS FOR A PARTICULAR
157c478bd9Sstevel@tonic-gate  * PURPOSE or MERCHANTABILITY.  Please read the associated documentation
167c478bd9Sstevel@tonic-gate  * "3c90x.txt" before compiling and using this driver.
177c478bd9Sstevel@tonic-gate  *
187c478bd9Sstevel@tonic-gate  * --------
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * Program written with the assistance of the 3com documentation for
217c478bd9Sstevel@tonic-gate  * the 3c905B-TX card, as well as with some assistance from the 3c59x
227c478bd9Sstevel@tonic-gate  * driver Donald Becker wrote for the Linux kernel, and with some assistance
237c478bd9Sstevel@tonic-gate  * from the remainder of the Etherboot distribution.
247c478bd9Sstevel@tonic-gate  *
257c478bd9Sstevel@tonic-gate  * REVISION HISTORY:
267c478bd9Sstevel@tonic-gate  *
277c478bd9Sstevel@tonic-gate  * v0.10	1-26-1998	GRB	Initial implementation.
287c478bd9Sstevel@tonic-gate  * v0.90	1-27-1998	GRB	System works.
297c478bd9Sstevel@tonic-gate  * v1.00pre1	2-11-1998	GRB	Got prom boot issue fixed.
307c478bd9Sstevel@tonic-gate  * v2.0		9-24-1999	SCS	Modified for 3c905 (from 3c905b code)
317c478bd9Sstevel@tonic-gate  *					Re-wrote poll and transmit for
327c478bd9Sstevel@tonic-gate  *					better error recovery and heavy
337c478bd9Sstevel@tonic-gate  *					network traffic operation
347c478bd9Sstevel@tonic-gate  * v2.01    5-26-2003 NN Fixed driver alignment issue which
357c478bd9Sstevel@tonic-gate  *                  caused system lockups if driver structures
367c478bd9Sstevel@tonic-gate  *                  not 8-byte aligned.
377c478bd9Sstevel@tonic-gate  *
387c478bd9Sstevel@tonic-gate  */
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate #include "etherboot.h"
417c478bd9Sstevel@tonic-gate #include "nic.h"
427c478bd9Sstevel@tonic-gate #include "pci.h"
437c478bd9Sstevel@tonic-gate #include "timer.h"
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate #define	XCVR_MAGIC	(0x5A00)
467c478bd9Sstevel@tonic-gate /** any single transmission fails after 16 collisions or other errors
477c478bd9Sstevel@tonic-gate  ** this is the number of times to retry the transmission -- this should
487c478bd9Sstevel@tonic-gate  ** be plenty
497c478bd9Sstevel@tonic-gate  **/
507c478bd9Sstevel@tonic-gate #define	XMIT_RETRIES	250
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate /*** Register definitions for the 3c905 ***/
537c478bd9Sstevel@tonic-gate enum Registers
547c478bd9Sstevel@tonic-gate     {
557c478bd9Sstevel@tonic-gate     regPowerMgmtCtrl_w = 0x7c,        /** 905B Revision Only                 **/
567c478bd9Sstevel@tonic-gate     regUpMaxBurst_w = 0x7a,           /** 905B Revision Only                 **/
577c478bd9Sstevel@tonic-gate     regDnMaxBurst_w = 0x78,           /** 905B Revision Only                 **/
587c478bd9Sstevel@tonic-gate     regDebugControl_w = 0x74,         /** 905B Revision Only                 **/
597c478bd9Sstevel@tonic-gate     regDebugData_l = 0x70,            /** 905B Revision Only                 **/
607c478bd9Sstevel@tonic-gate     regRealTimeCnt_l = 0x40,          /** Universal                          **/
617c478bd9Sstevel@tonic-gate     regUpBurstThresh_b = 0x3e,        /** 905B Revision Only                 **/
627c478bd9Sstevel@tonic-gate     regUpPoll_b = 0x3d,               /** 905B Revision Only                 **/
637c478bd9Sstevel@tonic-gate     regUpPriorityThresh_b = 0x3c,     /** 905B Revision Only                 **/
647c478bd9Sstevel@tonic-gate     regUpListPtr_l = 0x38,            /** Universal                          **/
657c478bd9Sstevel@tonic-gate     regCountdown_w = 0x36,            /** Universal                          **/
667c478bd9Sstevel@tonic-gate     regFreeTimer_w = 0x34,            /** Universal                          **/
677c478bd9Sstevel@tonic-gate     regUpPktStatus_l = 0x30,          /** Universal with Exception, pg 130   **/
687c478bd9Sstevel@tonic-gate     regTxFreeThresh_b = 0x2f,         /** 90X Revision Only                  **/
697c478bd9Sstevel@tonic-gate     regDnPoll_b = 0x2d,               /** 905B Revision Only                 **/
707c478bd9Sstevel@tonic-gate     regDnPriorityThresh_b = 0x2c,     /** 905B Revision Only                 **/
717c478bd9Sstevel@tonic-gate     regDnBurstThresh_b = 0x2a,        /** 905B Revision Only                 **/
727c478bd9Sstevel@tonic-gate     regDnListPtr_l = 0x24,            /** Universal with Exception, pg 107   **/
737c478bd9Sstevel@tonic-gate     regDmaCtrl_l = 0x20,              /** Universal with Exception, pg 106   **/
747c478bd9Sstevel@tonic-gate                                       /**                                    **/
757c478bd9Sstevel@tonic-gate     regIntStatusAuto_w = 0x1e,        /** 905B Revision Only                 **/
767c478bd9Sstevel@tonic-gate     regTxStatus_b = 0x1b,             /** Universal with Exception, pg 113   **/
777c478bd9Sstevel@tonic-gate     regTimer_b = 0x1a,                /** Universal                          **/
787c478bd9Sstevel@tonic-gate     regTxPktId_b = 0x18,              /** 905B Revision Only                 **/
797c478bd9Sstevel@tonic-gate     regCommandIntStatus_w = 0x0e,     /** Universal (Command Variations)     **/
807c478bd9Sstevel@tonic-gate     };
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate /** following are windowed registers **/
837c478bd9Sstevel@tonic-gate enum Registers7
847c478bd9Sstevel@tonic-gate     {
857c478bd9Sstevel@tonic-gate     regPowerMgmtEvent_7_w = 0x0c,     /** 905B Revision Only                 **/
867c478bd9Sstevel@tonic-gate     regVlanEtherType_7_w = 0x04,      /** 905B Revision Only                 **/
877c478bd9Sstevel@tonic-gate     regVlanMask_7_w = 0x00,           /** 905B Revision Only                 **/
887c478bd9Sstevel@tonic-gate     };
897c478bd9Sstevel@tonic-gate 
907c478bd9Sstevel@tonic-gate enum Registers6
917c478bd9Sstevel@tonic-gate     {
927c478bd9Sstevel@tonic-gate     regBytesXmittedOk_6_w = 0x0c,     /** Universal                          **/
937c478bd9Sstevel@tonic-gate     regBytesRcvdOk_6_w = 0x0a,        /** Universal                          **/
947c478bd9Sstevel@tonic-gate     regUpperFramesOk_6_b = 0x09,      /** Universal                          **/
957c478bd9Sstevel@tonic-gate     regFramesDeferred_6_b = 0x08,     /** Universal                          **/
967c478bd9Sstevel@tonic-gate     regFramesRecdOk_6_b = 0x07,       /** Universal with Exceptions, pg 142  **/
977c478bd9Sstevel@tonic-gate     regFramesXmittedOk_6_b = 0x06,    /** Universal                          **/
987c478bd9Sstevel@tonic-gate     regRxOverruns_6_b = 0x05,         /** Universal                          **/
997c478bd9Sstevel@tonic-gate     regLateCollisions_6_b = 0x04,     /** Universal                          **/
1007c478bd9Sstevel@tonic-gate     regSingleCollisions_6_b = 0x03,   /** Universal                          **/
1017c478bd9Sstevel@tonic-gate     regMultipleCollisions_6_b = 0x02, /** Universal                          **/
1027c478bd9Sstevel@tonic-gate     regSqeErrors_6_b = 0x01,          /** Universal                          **/
1037c478bd9Sstevel@tonic-gate     regCarrierLost_6_b = 0x00,        /** Universal                          **/
1047c478bd9Sstevel@tonic-gate     };
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate enum Registers5
1077c478bd9Sstevel@tonic-gate     {
1087c478bd9Sstevel@tonic-gate     regIndicationEnable_5_w = 0x0c,   /** Universal                          **/
1097c478bd9Sstevel@tonic-gate     regInterruptEnable_5_w = 0x0a,    /** Universal                          **/
1107c478bd9Sstevel@tonic-gate     regTxReclaimThresh_5_b = 0x09,    /** 905B Revision Only                 **/
1117c478bd9Sstevel@tonic-gate     regRxFilter_5_b = 0x08,           /** Universal                          **/
1127c478bd9Sstevel@tonic-gate     regRxEarlyThresh_5_w = 0x06,      /** Universal                          **/
1137c478bd9Sstevel@tonic-gate     regTxStartThresh_5_w = 0x00,      /** Universal                          **/
1147c478bd9Sstevel@tonic-gate     };
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate enum Registers4
1177c478bd9Sstevel@tonic-gate     {
1187c478bd9Sstevel@tonic-gate     regUpperBytesOk_4_b = 0x0d,       /** Universal                          **/
1197c478bd9Sstevel@tonic-gate     regBadSSD_4_b = 0x0c,             /** Universal                          **/
1207c478bd9Sstevel@tonic-gate     regMediaStatus_4_w = 0x0a,        /** Universal with Exceptions, pg 201  **/
1217c478bd9Sstevel@tonic-gate     regPhysicalMgmt_4_w = 0x08,       /** Universal                          **/
1227c478bd9Sstevel@tonic-gate     regNetworkDiagnostic_4_w = 0x06,  /** Universal with Exceptions, pg 203  **/
1237c478bd9Sstevel@tonic-gate     regFifoDiagnostic_4_w = 0x04,     /** Universal with Exceptions, pg 196  **/
1247c478bd9Sstevel@tonic-gate     regVcoDiagnostic_4_w = 0x02,      /** Undocumented?                      **/
1257c478bd9Sstevel@tonic-gate     };
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate enum Registers3
1287c478bd9Sstevel@tonic-gate     {
1297c478bd9Sstevel@tonic-gate     regTxFree_3_w = 0x0c,             /** Universal                          **/
1307c478bd9Sstevel@tonic-gate     regRxFree_3_w = 0x0a,             /** Universal with Exceptions, pg 125  **/
1317c478bd9Sstevel@tonic-gate     regResetMediaOptions_3_w = 0x08,  /** Media Options on B Revision,       **/
1327c478bd9Sstevel@tonic-gate                                       /** Reset Options on Non-B Revision    **/
1337c478bd9Sstevel@tonic-gate     regMacControl_3_w = 0x06,         /** Universal with Exceptions, pg 199  **/
1347c478bd9Sstevel@tonic-gate     regMaxPktSize_3_w = 0x04,         /** 905B Revision Only                 **/
1357c478bd9Sstevel@tonic-gate     regInternalConfig_3_l = 0x00,     /** Universal, different bit           **/
1367c478bd9Sstevel@tonic-gate                                       /** definitions, pg 59                 **/
1377c478bd9Sstevel@tonic-gate     };
1387c478bd9Sstevel@tonic-gate 
1397c478bd9Sstevel@tonic-gate enum Registers2
1407c478bd9Sstevel@tonic-gate     {
1417c478bd9Sstevel@tonic-gate     regResetOptions_2_w = 0x0c,       /** 905B Revision Only                 **/
1427c478bd9Sstevel@tonic-gate     regStationMask_2_3w = 0x06,       /** Universal with Exceptions, pg 127  **/
1437c478bd9Sstevel@tonic-gate     regStationAddress_2_3w = 0x00,    /** Universal with Exceptions, pg 127  **/
1447c478bd9Sstevel@tonic-gate     };
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate enum Registers1
1477c478bd9Sstevel@tonic-gate     {
1487c478bd9Sstevel@tonic-gate     regRxStatus_1_w = 0x0a,           /** 90X Revision Only, Pg 126          **/
1497c478bd9Sstevel@tonic-gate     };
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate enum Registers0
1527c478bd9Sstevel@tonic-gate     {
1537c478bd9Sstevel@tonic-gate     regEepromData_0_w = 0x0c,         /** Universal                          **/
1547c478bd9Sstevel@tonic-gate     regEepromCommand_0_w = 0x0a,      /** Universal                          **/
1557c478bd9Sstevel@tonic-gate     regBiosRomData_0_b = 0x08,        /** 905B Revision Only                 **/
1567c478bd9Sstevel@tonic-gate     regBiosRomAddr_0_l = 0x04,        /** 905B Revision Only                 **/
1577c478bd9Sstevel@tonic-gate     };
1587c478bd9Sstevel@tonic-gate 
1597c478bd9Sstevel@tonic-gate 
1607c478bd9Sstevel@tonic-gate /*** The names for the eight register windows ***/
1617c478bd9Sstevel@tonic-gate enum Windows
1627c478bd9Sstevel@tonic-gate     {
1637c478bd9Sstevel@tonic-gate     winPowerVlan7 = 0x07,
1647c478bd9Sstevel@tonic-gate     winStatistics6 = 0x06,
1657c478bd9Sstevel@tonic-gate     winTxRxControl5 = 0x05,
1667c478bd9Sstevel@tonic-gate     winDiagnostics4 = 0x04,
1677c478bd9Sstevel@tonic-gate     winTxRxOptions3 = 0x03,
1687c478bd9Sstevel@tonic-gate     winAddressing2 = 0x02,
1697c478bd9Sstevel@tonic-gate     winUnused1 = 0x01,
1707c478bd9Sstevel@tonic-gate     winEepromBios0 = 0x00,
1717c478bd9Sstevel@tonic-gate     };
1727c478bd9Sstevel@tonic-gate 
1737c478bd9Sstevel@tonic-gate 
1747c478bd9Sstevel@tonic-gate /*** Command definitions for the 3c90X ***/
1757c478bd9Sstevel@tonic-gate enum Commands
1767c478bd9Sstevel@tonic-gate     {
1777c478bd9Sstevel@tonic-gate     cmdGlobalReset = 0x00,             /** Universal with Exceptions, pg 151 **/
1787c478bd9Sstevel@tonic-gate     cmdSelectRegisterWindow = 0x01,    /** Universal                         **/
1797c478bd9Sstevel@tonic-gate     cmdEnableDcConverter = 0x02,       /**                                   **/
1807c478bd9Sstevel@tonic-gate     cmdRxDisable = 0x03,               /**                                   **/
1817c478bd9Sstevel@tonic-gate     cmdRxEnable = 0x04,                /** Universal                         **/
1827c478bd9Sstevel@tonic-gate     cmdRxReset = 0x05,                 /** Universal                         **/
1837c478bd9Sstevel@tonic-gate     cmdStallCtl = 0x06,                /** Universal                         **/
1847c478bd9Sstevel@tonic-gate     cmdTxEnable = 0x09,                /** Universal                         **/
1857c478bd9Sstevel@tonic-gate     cmdTxDisable = 0x0A,               /**                                   **/
1867c478bd9Sstevel@tonic-gate     cmdTxReset = 0x0B,                 /** Universal                         **/
1877c478bd9Sstevel@tonic-gate     cmdRequestInterrupt = 0x0C,        /**                                   **/
1887c478bd9Sstevel@tonic-gate     cmdAcknowledgeInterrupt = 0x0D,    /** Universal                         **/
1897c478bd9Sstevel@tonic-gate     cmdSetInterruptEnable = 0x0E,      /** Universal                         **/
1907c478bd9Sstevel@tonic-gate     cmdSetIndicationEnable = 0x0F,     /** Universal                         **/
1917c478bd9Sstevel@tonic-gate     cmdSetRxFilter = 0x10,             /** Universal                         **/
1927c478bd9Sstevel@tonic-gate     cmdSetRxEarlyThresh = 0x11,        /**                                   **/
1937c478bd9Sstevel@tonic-gate     cmdSetTxStartThresh = 0x13,        /**                                   **/
1947c478bd9Sstevel@tonic-gate     cmdStatisticsEnable = 0x15,        /**                                   **/
1957c478bd9Sstevel@tonic-gate     cmdStatisticsDisable = 0x16,       /**                                   **/
1967c478bd9Sstevel@tonic-gate     cmdDisableDcConverter = 0x17,      /**                                   **/
1977c478bd9Sstevel@tonic-gate     cmdSetTxReclaimThresh = 0x18,      /**                                   **/
1987c478bd9Sstevel@tonic-gate     cmdSetHashFilterBit = 0x19,        /**                                   **/
1997c478bd9Sstevel@tonic-gate     };
2007c478bd9Sstevel@tonic-gate 
2017c478bd9Sstevel@tonic-gate 
2027c478bd9Sstevel@tonic-gate /*** Values for int status register bitmask **/
2037c478bd9Sstevel@tonic-gate #define	INT_INTERRUPTLATCH	(1<<0)
2047c478bd9Sstevel@tonic-gate #define INT_HOSTERROR		(1<<1)
2057c478bd9Sstevel@tonic-gate #define INT_TXCOMPLETE		(1<<2)
2067c478bd9Sstevel@tonic-gate #define INT_RXCOMPLETE		(1<<4)
2077c478bd9Sstevel@tonic-gate #define INT_RXEARLY		(1<<5)
2087c478bd9Sstevel@tonic-gate #define INT_INTREQUESTED	(1<<6)
2097c478bd9Sstevel@tonic-gate #define INT_UPDATESTATS		(1<<7)
2107c478bd9Sstevel@tonic-gate #define INT_LINKEVENT		(1<<8)
2117c478bd9Sstevel@tonic-gate #define INT_DNCOMPLETE		(1<<9)
2127c478bd9Sstevel@tonic-gate #define INT_UPCOMPLETE		(1<<10)
2137c478bd9Sstevel@tonic-gate #define INT_CMDINPROGRESS	(1<<12)
2147c478bd9Sstevel@tonic-gate #define INT_WINDOWNUMBER	(7<<13)
2157c478bd9Sstevel@tonic-gate 
2167c478bd9Sstevel@tonic-gate 
2177c478bd9Sstevel@tonic-gate /*** TX descriptor ***/
2187c478bd9Sstevel@tonic-gate typedef struct
2197c478bd9Sstevel@tonic-gate     {
2207c478bd9Sstevel@tonic-gate     unsigned int	DnNextPtr;
2217c478bd9Sstevel@tonic-gate     unsigned int	FrameStartHeader;
2227c478bd9Sstevel@tonic-gate     unsigned int	HdrAddr;
2237c478bd9Sstevel@tonic-gate     unsigned int	HdrLength;
2247c478bd9Sstevel@tonic-gate     unsigned int	DataAddr;
2257c478bd9Sstevel@tonic-gate     unsigned int	DataLength;
2267c478bd9Sstevel@tonic-gate     }
2277c478bd9Sstevel@tonic-gate     TXD __attribute__ ((aligned(8))); /* 64-bit aligned for bus mastering */
2287c478bd9Sstevel@tonic-gate 
2297c478bd9Sstevel@tonic-gate /*** RX descriptor ***/
2307c478bd9Sstevel@tonic-gate typedef struct
2317c478bd9Sstevel@tonic-gate     {
2327c478bd9Sstevel@tonic-gate     unsigned int	UpNextPtr;
2337c478bd9Sstevel@tonic-gate     unsigned int	UpPktStatus;
2347c478bd9Sstevel@tonic-gate     unsigned int	DataAddr;
2357c478bd9Sstevel@tonic-gate     unsigned int	DataLength;
2367c478bd9Sstevel@tonic-gate     }
2377c478bd9Sstevel@tonic-gate     RXD __attribute__ ((aligned(8))); /* 64-bit aligned for bus mastering */
2387c478bd9Sstevel@tonic-gate 
2397c478bd9Sstevel@tonic-gate /*** Global variables ***/
2407c478bd9Sstevel@tonic-gate static struct
2417c478bd9Sstevel@tonic-gate     {
2427c478bd9Sstevel@tonic-gate     unsigned char	isBrev;
2437c478bd9Sstevel@tonic-gate     unsigned char	CurrentWindow;
2447c478bd9Sstevel@tonic-gate     unsigned int	IOAddr;
2457c478bd9Sstevel@tonic-gate     unsigned char	HWAddr[ETH_ALEN];
2467c478bd9Sstevel@tonic-gate     TXD			TransmitDPD;
2477c478bd9Sstevel@tonic-gate     RXD			ReceiveUPD;
2487c478bd9Sstevel@tonic-gate     }
2497c478bd9Sstevel@tonic-gate     INF_3C90X;
2507c478bd9Sstevel@tonic-gate 
2517c478bd9Sstevel@tonic-gate 
2527c478bd9Sstevel@tonic-gate /*** a3c90x_internal_IssueCommand: sends a command to the 3c90x card
2537c478bd9Sstevel@tonic-gate  ***/
2547c478bd9Sstevel@tonic-gate static int
a3c90x_internal_IssueCommand(int ioaddr,int cmd,int param)2557c478bd9Sstevel@tonic-gate a3c90x_internal_IssueCommand(int ioaddr, int cmd, int param)
2567c478bd9Sstevel@tonic-gate     {
2577c478bd9Sstevel@tonic-gate     unsigned int val;
2587c478bd9Sstevel@tonic-gate 
2597c478bd9Sstevel@tonic-gate 	/** Build the cmd. **/
2607c478bd9Sstevel@tonic-gate 	val = cmd;
2617c478bd9Sstevel@tonic-gate 	val <<= 11;
2627c478bd9Sstevel@tonic-gate 	val |= param;
2637c478bd9Sstevel@tonic-gate 
2647c478bd9Sstevel@tonic-gate 	/** Send the cmd to the cmd register **/
2657c478bd9Sstevel@tonic-gate 	outw(val, ioaddr + regCommandIntStatus_w);
2667c478bd9Sstevel@tonic-gate 
2677c478bd9Sstevel@tonic-gate 	/** Wait for the cmd to complete, if necessary **/
2687c478bd9Sstevel@tonic-gate 	while (inw(ioaddr + regCommandIntStatus_w) & INT_CMDINPROGRESS);
2697c478bd9Sstevel@tonic-gate 
2707c478bd9Sstevel@tonic-gate     return 0;
2717c478bd9Sstevel@tonic-gate     }
2727c478bd9Sstevel@tonic-gate 
2737c478bd9Sstevel@tonic-gate 
2747c478bd9Sstevel@tonic-gate /*** a3c90x_internal_SetWindow: selects a register window set.
2757c478bd9Sstevel@tonic-gate  ***/
2767c478bd9Sstevel@tonic-gate static int
a3c90x_internal_SetWindow(int ioaddr,int window)2777c478bd9Sstevel@tonic-gate a3c90x_internal_SetWindow(int ioaddr, int window)
2787c478bd9Sstevel@tonic-gate     {
2797c478bd9Sstevel@tonic-gate 
2807c478bd9Sstevel@tonic-gate 	/** Window already as set? **/
2817c478bd9Sstevel@tonic-gate 	if (INF_3C90X.CurrentWindow == window) return 0;
2827c478bd9Sstevel@tonic-gate 
2837c478bd9Sstevel@tonic-gate 	/** Issue the window command. **/
2847c478bd9Sstevel@tonic-gate 	a3c90x_internal_IssueCommand(ioaddr, cmdSelectRegisterWindow, window);
2857c478bd9Sstevel@tonic-gate 	INF_3C90X.CurrentWindow = window;
2867c478bd9Sstevel@tonic-gate 
2877c478bd9Sstevel@tonic-gate     return 0;
2887c478bd9Sstevel@tonic-gate     }
2897c478bd9Sstevel@tonic-gate 
2907c478bd9Sstevel@tonic-gate 
2917c478bd9Sstevel@tonic-gate /*** a3c90x_internal_ReadEeprom - read data from the serial eeprom.
2927c478bd9Sstevel@tonic-gate  ***/
2937c478bd9Sstevel@tonic-gate static unsigned short
a3c90x_internal_ReadEeprom(int ioaddr,int address)2947c478bd9Sstevel@tonic-gate a3c90x_internal_ReadEeprom(int ioaddr, int address)
2957c478bd9Sstevel@tonic-gate     {
2967c478bd9Sstevel@tonic-gate     unsigned short val;
2977c478bd9Sstevel@tonic-gate 
2987c478bd9Sstevel@tonic-gate 	/** Select correct window **/
2997c478bd9Sstevel@tonic-gate         a3c90x_internal_SetWindow(INF_3C90X.IOAddr, winEepromBios0);
3007c478bd9Sstevel@tonic-gate 
3017c478bd9Sstevel@tonic-gate 	/** Make sure the eeprom isn't busy **/
3027c478bd9Sstevel@tonic-gate 	while((1<<15) & inw(ioaddr + regEepromCommand_0_w));
3037c478bd9Sstevel@tonic-gate 
3047c478bd9Sstevel@tonic-gate 	/** Read the value. **/
3057c478bd9Sstevel@tonic-gate 	outw(address + ((0x02)<<6), ioaddr + regEepromCommand_0_w);
3067c478bd9Sstevel@tonic-gate 	while((1<<15) & inw(ioaddr + regEepromCommand_0_w));
3077c478bd9Sstevel@tonic-gate 	val = inw(ioaddr + regEepromData_0_w);
3087c478bd9Sstevel@tonic-gate 
3097c478bd9Sstevel@tonic-gate     return val;
3107c478bd9Sstevel@tonic-gate     }
3117c478bd9Sstevel@tonic-gate 
3127c478bd9Sstevel@tonic-gate 
3137c478bd9Sstevel@tonic-gate #if 0
3147c478bd9Sstevel@tonic-gate /*** a3c90x_internal_WriteEepromWord - write a physical word of
3157c478bd9Sstevel@tonic-gate  *** data to the onboard serial eeprom (not the BIOS prom, but the
3167c478bd9Sstevel@tonic-gate  *** nvram in the card that stores, among other things, the MAC
3177c478bd9Sstevel@tonic-gate  *** address).
3187c478bd9Sstevel@tonic-gate  ***/
3197c478bd9Sstevel@tonic-gate static int
3207c478bd9Sstevel@tonic-gate a3c90x_internal_WriteEepromWord(int ioaddr, int address, unsigned short value)
3217c478bd9Sstevel@tonic-gate     {
3227c478bd9Sstevel@tonic-gate 	/** Select register window **/
3237c478bd9Sstevel@tonic-gate         a3c90x_internal_SetWindow(ioaddr, winEepromBios0);
3247c478bd9Sstevel@tonic-gate 
3257c478bd9Sstevel@tonic-gate 	/** Verify Eeprom not busy **/
3267c478bd9Sstevel@tonic-gate 	while((1<<15) & inw(ioaddr + regEepromCommand_0_w));
3277c478bd9Sstevel@tonic-gate 
3287c478bd9Sstevel@tonic-gate 	/** Issue WriteEnable, and wait for completion. **/
3297c478bd9Sstevel@tonic-gate 	outw(0x30, ioaddr + regEepromCommand_0_w);
3307c478bd9Sstevel@tonic-gate 	while((1<<15) & inw(ioaddr + regEepromCommand_0_w));
3317c478bd9Sstevel@tonic-gate 
3327c478bd9Sstevel@tonic-gate 	/** Issue EraseRegister, and wait for completion. **/
3337c478bd9Sstevel@tonic-gate 	outw(address + ((0x03)<<6), ioaddr + regEepromCommand_0_w);
3347c478bd9Sstevel@tonic-gate 	while((1<<15) & inw(ioaddr + regEepromCommand_0_w));
3357c478bd9Sstevel@tonic-gate 
3367c478bd9Sstevel@tonic-gate 	/** Send the new data to the eeprom, and wait for completion. **/
3377c478bd9Sstevel@tonic-gate 	outw(value, ioaddr + regEepromData_0_w);
3387c478bd9Sstevel@tonic-gate 	outw(0x30, ioaddr + regEepromCommand_0_w);
3397c478bd9Sstevel@tonic-gate 	while((1<<15) & inw(ioaddr + regEepromCommand_0_w));
3407c478bd9Sstevel@tonic-gate 
3417c478bd9Sstevel@tonic-gate 	/** Burn the new data into the eeprom, and wait for completion. **/
3427c478bd9Sstevel@tonic-gate 	outw(address + ((0x01)<<6), ioaddr + regEepromCommand_0_w);
3437c478bd9Sstevel@tonic-gate 	while((1<<15) & inw(ioaddr + regEepromCommand_0_w));
3447c478bd9Sstevel@tonic-gate 
3457c478bd9Sstevel@tonic-gate     return 0;
3467c478bd9Sstevel@tonic-gate     }
3477c478bd9Sstevel@tonic-gate #endif
3487c478bd9Sstevel@tonic-gate 
3497c478bd9Sstevel@tonic-gate #if 0
3507c478bd9Sstevel@tonic-gate /*** a3c90x_internal_WriteEeprom - write data to the serial eeprom,
3517c478bd9Sstevel@tonic-gate  *** and re-compute the eeprom checksum.
3527c478bd9Sstevel@tonic-gate  ***/
3537c478bd9Sstevel@tonic-gate static int
3547c478bd9Sstevel@tonic-gate a3c90x_internal_WriteEeprom(int ioaddr, int address, unsigned short value)
3557c478bd9Sstevel@tonic-gate     {
3567c478bd9Sstevel@tonic-gate     int cksum = 0,v;
3577c478bd9Sstevel@tonic-gate     int i;
3587c478bd9Sstevel@tonic-gate     int maxAddress, cksumAddress;
3597c478bd9Sstevel@tonic-gate 
3607c478bd9Sstevel@tonic-gate 	if (INF_3C90X.isBrev)
3617c478bd9Sstevel@tonic-gate 	    {
3627c478bd9Sstevel@tonic-gate 	    maxAddress=0x1f;
3637c478bd9Sstevel@tonic-gate 	    cksumAddress=0x20;
3647c478bd9Sstevel@tonic-gate 	    }
3657c478bd9Sstevel@tonic-gate 	else
3667c478bd9Sstevel@tonic-gate 	    {
3677c478bd9Sstevel@tonic-gate 	    maxAddress=0x16;
3687c478bd9Sstevel@tonic-gate 	    cksumAddress=0x17;
3697c478bd9Sstevel@tonic-gate 	    }
3707c478bd9Sstevel@tonic-gate 
3717c478bd9Sstevel@tonic-gate 	/** Write the value. **/
3727c478bd9Sstevel@tonic-gate 	if (a3c90x_internal_WriteEepromWord(ioaddr, address, value) == -1)
3737c478bd9Sstevel@tonic-gate 	    return -1;
3747c478bd9Sstevel@tonic-gate 
3757c478bd9Sstevel@tonic-gate 	/** Recompute the checksum. **/
3767c478bd9Sstevel@tonic-gate 	for(i=0;i<=maxAddress;i++)
3777c478bd9Sstevel@tonic-gate 	    {
3787c478bd9Sstevel@tonic-gate 	    v = a3c90x_internal_ReadEeprom(ioaddr, i);
3797c478bd9Sstevel@tonic-gate 	    cksum ^= (v & 0xFF);
3807c478bd9Sstevel@tonic-gate 	    cksum ^= ((v>>8) & 0xFF);
3817c478bd9Sstevel@tonic-gate 	    }
3827c478bd9Sstevel@tonic-gate 	/** Write the checksum to the location in the eeprom **/
3837c478bd9Sstevel@tonic-gate 	if (a3c90x_internal_WriteEepromWord(ioaddr, cksumAddress, cksum) == -1)
3847c478bd9Sstevel@tonic-gate 	    return -1;
3857c478bd9Sstevel@tonic-gate 
3867c478bd9Sstevel@tonic-gate     return 0;
3877c478bd9Sstevel@tonic-gate     }
3887c478bd9Sstevel@tonic-gate #endif
3897c478bd9Sstevel@tonic-gate 
3907c478bd9Sstevel@tonic-gate /*** a3c90x_reset: exported function that resets the card to its default
3917c478bd9Sstevel@tonic-gate  *** state.  This is so the Linux driver can re-set the card up the way
3927c478bd9Sstevel@tonic-gate  *** it wants to.  If CFG_3C90X_PRESERVE_XCVR is defined, then the reset will
3937c478bd9Sstevel@tonic-gate  *** not alter the selected transceiver that we used to download the boot
3947c478bd9Sstevel@tonic-gate  *** image.
3957c478bd9Sstevel@tonic-gate  ***/
a3c90x_reset(void)3967c478bd9Sstevel@tonic-gate static void a3c90x_reset(void)
3977c478bd9Sstevel@tonic-gate     {
3987c478bd9Sstevel@tonic-gate #ifdef	CFG_3C90X_PRESERVE_XCVR
3997c478bd9Sstevel@tonic-gate     int cfg;
4007c478bd9Sstevel@tonic-gate     /** Read the current InternalConfig value. **/
4017c478bd9Sstevel@tonic-gate     a3c90x_internal_SetWindow(INF_3C90X.IOAddr, winTxRxOptions3);
4027c478bd9Sstevel@tonic-gate     cfg = inl(INF_3C90X.IOAddr + regInternalConfig_3_l);
4037c478bd9Sstevel@tonic-gate #endif
4047c478bd9Sstevel@tonic-gate 
4057c478bd9Sstevel@tonic-gate     /** Send the reset command to the card **/
4067c478bd9Sstevel@tonic-gate     printf("Issuing RESET:\n");
4077c478bd9Sstevel@tonic-gate     a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdGlobalReset, 0);
4087c478bd9Sstevel@tonic-gate 
4097c478bd9Sstevel@tonic-gate     /** wait for reset command to complete **/
4107c478bd9Sstevel@tonic-gate     while (inw(INF_3C90X.IOAddr + regCommandIntStatus_w) & INT_CMDINPROGRESS);
4117c478bd9Sstevel@tonic-gate 
4127c478bd9Sstevel@tonic-gate     /** global reset command resets station mask, non-B revision cards
4137c478bd9Sstevel@tonic-gate      ** require explicit reset of values
4147c478bd9Sstevel@tonic-gate      **/
4157c478bd9Sstevel@tonic-gate     a3c90x_internal_SetWindow(INF_3C90X.IOAddr, winAddressing2);
4167c478bd9Sstevel@tonic-gate     outw(0, INF_3C90X.IOAddr + regStationMask_2_3w+0);
4177c478bd9Sstevel@tonic-gate     outw(0, INF_3C90X.IOAddr + regStationMask_2_3w+2);
4187c478bd9Sstevel@tonic-gate     outw(0, INF_3C90X.IOAddr + regStationMask_2_3w+4);
4197c478bd9Sstevel@tonic-gate 
4207c478bd9Sstevel@tonic-gate #ifdef	CFG_3C90X_PRESERVE_XCVR
4217c478bd9Sstevel@tonic-gate     /** Re-set the original InternalConfig value from before reset **/
4227c478bd9Sstevel@tonic-gate     a3c90x_internal_SetWindow(INF_3C90X.IOAddr, winTxRxOptions3);
4237c478bd9Sstevel@tonic-gate     outl(cfg, INF_3C90X.IOAddr + regInternalConfig_3_l);
4247c478bd9Sstevel@tonic-gate 
4257c478bd9Sstevel@tonic-gate     /** enable DC converter for 10-Base-T **/
4267c478bd9Sstevel@tonic-gate     if ((cfg&0x0300) == 0x0300)
4277c478bd9Sstevel@tonic-gate 	{
4287c478bd9Sstevel@tonic-gate 	a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdEnableDcConverter, 0);
4297c478bd9Sstevel@tonic-gate 	}
4307c478bd9Sstevel@tonic-gate #endif
4317c478bd9Sstevel@tonic-gate 
4327c478bd9Sstevel@tonic-gate     /** Issue transmit reset, wait for command completion **/
4337c478bd9Sstevel@tonic-gate     a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdTxReset, 0);
4347c478bd9Sstevel@tonic-gate     while (inw(INF_3C90X.IOAddr + regCommandIntStatus_w) & INT_CMDINPROGRESS)
4357c478bd9Sstevel@tonic-gate 	;
4367c478bd9Sstevel@tonic-gate     if (! INF_3C90X.isBrev)
4377c478bd9Sstevel@tonic-gate 	outb(0x01, INF_3C90X.IOAddr + regTxFreeThresh_b);
4387c478bd9Sstevel@tonic-gate     a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdTxEnable, 0);
4397c478bd9Sstevel@tonic-gate 
4407c478bd9Sstevel@tonic-gate     /**
4417c478bd9Sstevel@tonic-gate      ** reset of the receiver on B-revision cards re-negotiates the link
4427c478bd9Sstevel@tonic-gate      ** takes several seconds (a computer eternity)
4437c478bd9Sstevel@tonic-gate      **/
4447c478bd9Sstevel@tonic-gate     if (INF_3C90X.isBrev)
4457c478bd9Sstevel@tonic-gate 	a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdRxReset, 0x04);
4467c478bd9Sstevel@tonic-gate     else
4477c478bd9Sstevel@tonic-gate 	a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdRxReset, 0x00);
4487c478bd9Sstevel@tonic-gate     while (inw(INF_3C90X.IOAddr + regCommandIntStatus_w) & INT_CMDINPROGRESS);
4497c478bd9Sstevel@tonic-gate 	;
4507c478bd9Sstevel@tonic-gate     a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdRxEnable, 0);
4517c478bd9Sstevel@tonic-gate 
4527c478bd9Sstevel@tonic-gate     a3c90x_internal_IssueCommand(INF_3C90X.IOAddr,
4537c478bd9Sstevel@tonic-gate                                  cmdSetInterruptEnable, 0);
4547c478bd9Sstevel@tonic-gate     /** enable rxComplete and txComplete **/
4557c478bd9Sstevel@tonic-gate     a3c90x_internal_IssueCommand(INF_3C90X.IOAddr,
4567c478bd9Sstevel@tonic-gate                                  cmdSetIndicationEnable, 0x0014);
4577c478bd9Sstevel@tonic-gate     /** acknowledge any pending status flags **/
4587c478bd9Sstevel@tonic-gate     a3c90x_internal_IssueCommand(INF_3C90X.IOAddr,
4597c478bd9Sstevel@tonic-gate                                  cmdAcknowledgeInterrupt, 0x661);
4607c478bd9Sstevel@tonic-gate 
4617c478bd9Sstevel@tonic-gate     return;
4627c478bd9Sstevel@tonic-gate     }
4637c478bd9Sstevel@tonic-gate 
4647c478bd9Sstevel@tonic-gate 
4657c478bd9Sstevel@tonic-gate 
4667c478bd9Sstevel@tonic-gate /*** a3c90x_transmit: exported function that transmits a packet.  Does not
4677c478bd9Sstevel@tonic-gate  *** return any particular status.  Parameters are:
4687c478bd9Sstevel@tonic-gate  *** d[6] - destination address, ethernet;
4697c478bd9Sstevel@tonic-gate  *** t - protocol type (ARP, IP, etc);
4707c478bd9Sstevel@tonic-gate  *** s - size of the non-header part of the packet that needs transmitted;
4717c478bd9Sstevel@tonic-gate  *** p - the pointer to the packet data itself.
4727c478bd9Sstevel@tonic-gate  ***/
4737c478bd9Sstevel@tonic-gate static void
a3c90x_transmit(struct nic * nic __unused,const char * d,unsigned int t,unsigned int s,const char * p)4747c478bd9Sstevel@tonic-gate a3c90x_transmit(struct nic *nic __unused, const char *d, unsigned int t,
4757c478bd9Sstevel@tonic-gate                 unsigned int s, const char *p)
4767c478bd9Sstevel@tonic-gate     {
4777c478bd9Sstevel@tonic-gate 
4787c478bd9Sstevel@tonic-gate     struct eth_hdr
4797c478bd9Sstevel@tonic-gate 	{
4807c478bd9Sstevel@tonic-gate 	unsigned char dst_addr[ETH_ALEN];
4817c478bd9Sstevel@tonic-gate 	unsigned char src_addr[ETH_ALEN];
4827c478bd9Sstevel@tonic-gate 	unsigned short type;
4837c478bd9Sstevel@tonic-gate 	} hdr;
4847c478bd9Sstevel@tonic-gate 
4857c478bd9Sstevel@tonic-gate     unsigned char status;
4867c478bd9Sstevel@tonic-gate     unsigned i, retries;
4877c478bd9Sstevel@tonic-gate 
4887c478bd9Sstevel@tonic-gate     for (retries=0; retries < XMIT_RETRIES ; retries++)
4897c478bd9Sstevel@tonic-gate 	{
4907c478bd9Sstevel@tonic-gate 	/** Stall the download engine **/
4917c478bd9Sstevel@tonic-gate 	a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdStallCtl, 2);
4927c478bd9Sstevel@tonic-gate 
4937c478bd9Sstevel@tonic-gate 	/** Make sure the card is not waiting on us **/
4947c478bd9Sstevel@tonic-gate 	inw(INF_3C90X.IOAddr + regCommandIntStatus_w);
4957c478bd9Sstevel@tonic-gate 	inw(INF_3C90X.IOAddr + regCommandIntStatus_w);
4967c478bd9Sstevel@tonic-gate 
4977c478bd9Sstevel@tonic-gate 	while (inw(INF_3C90X.IOAddr+regCommandIntStatus_w) &
4987c478bd9Sstevel@tonic-gate 	       INT_CMDINPROGRESS)
4997c478bd9Sstevel@tonic-gate 	    ;
5007c478bd9Sstevel@tonic-gate 
5017c478bd9Sstevel@tonic-gate 	/** Set the ethernet packet type **/
5027c478bd9Sstevel@tonic-gate 	hdr.type = htons(t);
5037c478bd9Sstevel@tonic-gate 
5047c478bd9Sstevel@tonic-gate 	/** Copy the destination address **/
5057c478bd9Sstevel@tonic-gate 	memcpy(hdr.dst_addr, d, ETH_ALEN);
5067c478bd9Sstevel@tonic-gate 
5077c478bd9Sstevel@tonic-gate 	/** Copy our MAC address **/
5087c478bd9Sstevel@tonic-gate 	memcpy(hdr.src_addr, INF_3C90X.HWAddr, ETH_ALEN);
5097c478bd9Sstevel@tonic-gate 
5107c478bd9Sstevel@tonic-gate 	/** Setup the DPD (download descriptor) **/
5117c478bd9Sstevel@tonic-gate 	INF_3C90X.TransmitDPD.DnNextPtr = 0;
5127c478bd9Sstevel@tonic-gate 	/** set notification for transmission completion (bit 15) **/
5137c478bd9Sstevel@tonic-gate 	INF_3C90X.TransmitDPD.FrameStartHeader = (s + sizeof(hdr)) | 0x8000;
5147c478bd9Sstevel@tonic-gate 	INF_3C90X.TransmitDPD.HdrAddr = virt_to_bus(&hdr);
5157c478bd9Sstevel@tonic-gate 	INF_3C90X.TransmitDPD.HdrLength = sizeof(hdr);
5167c478bd9Sstevel@tonic-gate 	INF_3C90X.TransmitDPD.DataAddr = virt_to_bus(p);
5177c478bd9Sstevel@tonic-gate 	INF_3C90X.TransmitDPD.DataLength = s + (1<<31);
5187c478bd9Sstevel@tonic-gate 
5197c478bd9Sstevel@tonic-gate 	/** Send the packet **/
5207c478bd9Sstevel@tonic-gate 	outl(virt_to_bus(&(INF_3C90X.TransmitDPD)),
5217c478bd9Sstevel@tonic-gate 	     INF_3C90X.IOAddr + regDnListPtr_l);
5227c478bd9Sstevel@tonic-gate 
5237c478bd9Sstevel@tonic-gate 	/** End Stall and Wait for upload to complete. **/
5247c478bd9Sstevel@tonic-gate 	a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdStallCtl, 3);
5257c478bd9Sstevel@tonic-gate 	while(inl(INF_3C90X.IOAddr + regDnListPtr_l) != 0)
5267c478bd9Sstevel@tonic-gate 	    ;
5277c478bd9Sstevel@tonic-gate 
5287c478bd9Sstevel@tonic-gate 	/** Wait for NIC Transmit to Complete **/
5297c478bd9Sstevel@tonic-gate 	load_timer2(10*TICKS_PER_MS);	/* Give it 10 ms */
5307c478bd9Sstevel@tonic-gate 	while (!(inw(INF_3C90X.IOAddr + regCommandIntStatus_w)&0x0004) &&
5317c478bd9Sstevel@tonic-gate 		timer2_running())
5327c478bd9Sstevel@tonic-gate 		;
5337c478bd9Sstevel@tonic-gate 
5347c478bd9Sstevel@tonic-gate 	if (!(inw(INF_3C90X.IOAddr + regCommandIntStatus_w)&0x0004))
5357c478bd9Sstevel@tonic-gate 	    {
5367c478bd9Sstevel@tonic-gate 	    printf("3C90X: Tx Timeout\n");
5377c478bd9Sstevel@tonic-gate 	    continue;
5387c478bd9Sstevel@tonic-gate 	    }
5397c478bd9Sstevel@tonic-gate 
5407c478bd9Sstevel@tonic-gate 	status = inb(INF_3C90X.IOAddr + regTxStatus_b);
5417c478bd9Sstevel@tonic-gate 
5427c478bd9Sstevel@tonic-gate 	/** acknowledge transmit interrupt by writing status **/
5437c478bd9Sstevel@tonic-gate 	outb(0x00, INF_3C90X.IOAddr + regTxStatus_b);
5447c478bd9Sstevel@tonic-gate 
5457c478bd9Sstevel@tonic-gate 	/** successful completion (sans "interrupt Requested" bit) **/
5467c478bd9Sstevel@tonic-gate 	if ((status & 0xbf) == 0x80)
5477c478bd9Sstevel@tonic-gate 	    return;
5487c478bd9Sstevel@tonic-gate 
5497c478bd9Sstevel@tonic-gate 	   printf("3C90X: Status (%hhX)\n", status);
5507c478bd9Sstevel@tonic-gate 	/** check error codes **/
5517c478bd9Sstevel@tonic-gate 	if (status & 0x02)
5527c478bd9Sstevel@tonic-gate 	    {
5537c478bd9Sstevel@tonic-gate 	    printf("3C90X: Tx Reclaim Error (%hhX)\n", status);
5547c478bd9Sstevel@tonic-gate 	    a3c90x_reset();
5557c478bd9Sstevel@tonic-gate 	    }
5567c478bd9Sstevel@tonic-gate 	else if (status & 0x04)
5577c478bd9Sstevel@tonic-gate 	    {
5587c478bd9Sstevel@tonic-gate 	    printf("3C90X: Tx Status Overflow (%hhX)\n", status);
5597c478bd9Sstevel@tonic-gate 	    for (i=0; i<32; i++)
5607c478bd9Sstevel@tonic-gate 		outb(0x00, INF_3C90X.IOAddr + regTxStatus_b);
5617c478bd9Sstevel@tonic-gate 	    /** must re-enable after max collisions before re-issuing tx **/
5627c478bd9Sstevel@tonic-gate 	    a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdTxEnable, 0);
5637c478bd9Sstevel@tonic-gate 	    }
5647c478bd9Sstevel@tonic-gate 	else if (status & 0x08)
5657c478bd9Sstevel@tonic-gate 	    {
5667c478bd9Sstevel@tonic-gate 	    printf("3C90X: Tx Max Collisions (%hhX)\n", status);
5677c478bd9Sstevel@tonic-gate 	    /** must re-enable after max collisions before re-issuing tx **/
5687c478bd9Sstevel@tonic-gate 	    a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdTxEnable, 0);
5697c478bd9Sstevel@tonic-gate 	    }
5707c478bd9Sstevel@tonic-gate 	else if (status & 0x10)
5717c478bd9Sstevel@tonic-gate 	    {
5727c478bd9Sstevel@tonic-gate 	    printf("3C90X: Tx Underrun (%hhX)\n", status);
5737c478bd9Sstevel@tonic-gate 	    a3c90x_reset();
5747c478bd9Sstevel@tonic-gate 	    }
5757c478bd9Sstevel@tonic-gate 	else if (status & 0x20)
5767c478bd9Sstevel@tonic-gate 	    {
5777c478bd9Sstevel@tonic-gate 	    printf("3C90X: Tx Jabber (%hhX)\n", status);
5787c478bd9Sstevel@tonic-gate 	    a3c90x_reset();
5797c478bd9Sstevel@tonic-gate 	    }
5807c478bd9Sstevel@tonic-gate 	else if ((status & 0x80) != 0x80)
5817c478bd9Sstevel@tonic-gate 	    {
5827c478bd9Sstevel@tonic-gate 	    printf("3C90X: Internal Error - Incomplete Transmission (%hhX)\n",
5837c478bd9Sstevel@tonic-gate 	           status);
5847c478bd9Sstevel@tonic-gate 	    a3c90x_reset();
5857c478bd9Sstevel@tonic-gate 	    }
5867c478bd9Sstevel@tonic-gate 	}
5877c478bd9Sstevel@tonic-gate 
5887c478bd9Sstevel@tonic-gate     /** failed after RETRY attempts **/
5897c478bd9Sstevel@tonic-gate     printf("Failed to send after %d retries\n", retries);
5907c478bd9Sstevel@tonic-gate     return;
5917c478bd9Sstevel@tonic-gate 
5927c478bd9Sstevel@tonic-gate     }
5937c478bd9Sstevel@tonic-gate 
5947c478bd9Sstevel@tonic-gate 
5957c478bd9Sstevel@tonic-gate 
5967c478bd9Sstevel@tonic-gate /*** a3c90x_poll: exported routine that waits for a certain length of time
5977c478bd9Sstevel@tonic-gate  *** for a packet, and if it sees none, returns 0.  This routine should
5987c478bd9Sstevel@tonic-gate  *** copy the packet to nic->packet if it gets a packet and set the size
5997c478bd9Sstevel@tonic-gate  *** in nic->packetlen.  Return 1 if a packet was found.
6007c478bd9Sstevel@tonic-gate  ***/
6017c478bd9Sstevel@tonic-gate static int
a3c90x_poll(struct nic * nic,int retrieve)6027c478bd9Sstevel@tonic-gate a3c90x_poll(struct nic *nic, int retrieve)
6037c478bd9Sstevel@tonic-gate     {
6047c478bd9Sstevel@tonic-gate     int i, errcode;
6057c478bd9Sstevel@tonic-gate 
6067c478bd9Sstevel@tonic-gate     if (!(inw(INF_3C90X.IOAddr + regCommandIntStatus_w)&0x0010))
6077c478bd9Sstevel@tonic-gate 	{
6087c478bd9Sstevel@tonic-gate 	return 0;
6097c478bd9Sstevel@tonic-gate 	}
6107c478bd9Sstevel@tonic-gate 
6117c478bd9Sstevel@tonic-gate     if ( ! retrieve ) return 1;
6127c478bd9Sstevel@tonic-gate 
6137c478bd9Sstevel@tonic-gate     /** we don't need to acknowledge rxComplete -- the upload engine
6147c478bd9Sstevel@tonic-gate      ** does it for us.
6157c478bd9Sstevel@tonic-gate      **/
6167c478bd9Sstevel@tonic-gate 
6177c478bd9Sstevel@tonic-gate     /** Build the up-load descriptor **/
6187c478bd9Sstevel@tonic-gate     INF_3C90X.ReceiveUPD.UpNextPtr = 0;
6197c478bd9Sstevel@tonic-gate     INF_3C90X.ReceiveUPD.UpPktStatus = 0;
6207c478bd9Sstevel@tonic-gate     INF_3C90X.ReceiveUPD.DataAddr = virt_to_bus(nic->packet);
6217c478bd9Sstevel@tonic-gate     INF_3C90X.ReceiveUPD.DataLength = 1536 + (1<<31);
6227c478bd9Sstevel@tonic-gate 
6237c478bd9Sstevel@tonic-gate     /** Submit the upload descriptor to the NIC **/
6247c478bd9Sstevel@tonic-gate     outl(virt_to_bus(&(INF_3C90X.ReceiveUPD)),
6257c478bd9Sstevel@tonic-gate          INF_3C90X.IOAddr + regUpListPtr_l);
6267c478bd9Sstevel@tonic-gate 
6277c478bd9Sstevel@tonic-gate     /** Wait for upload completion (upComplete(15) or upError (14)) **/
6287c478bd9Sstevel@tonic-gate     for(i=0;i<40000;i++);
6297c478bd9Sstevel@tonic-gate     while((INF_3C90X.ReceiveUPD.UpPktStatus & ((1<<14) | (1<<15))) == 0)
6307c478bd9Sstevel@tonic-gate 	for(i=0;i<40000;i++);
6317c478bd9Sstevel@tonic-gate 
6327c478bd9Sstevel@tonic-gate     /** Check for Error (else we have good packet) **/
6337c478bd9Sstevel@tonic-gate     if (INF_3C90X.ReceiveUPD.UpPktStatus & (1<<14))
6347c478bd9Sstevel@tonic-gate 	{
6357c478bd9Sstevel@tonic-gate 	errcode = INF_3C90X.ReceiveUPD.UpPktStatus;
6367c478bd9Sstevel@tonic-gate 	if (errcode & (1<<16))
6377c478bd9Sstevel@tonic-gate 	    printf("3C90X: Rx Overrun (%hX)\n",errcode>>16);
6387c478bd9Sstevel@tonic-gate 	else if (errcode & (1<<17))
6397c478bd9Sstevel@tonic-gate 	    printf("3C90X: Runt Frame (%hX)\n",errcode>>16);
6407c478bd9Sstevel@tonic-gate 	else if (errcode & (1<<18))
6417c478bd9Sstevel@tonic-gate 	    printf("3C90X: Alignment Error (%hX)\n",errcode>>16);
6427c478bd9Sstevel@tonic-gate 	else if (errcode & (1<<19))
6437c478bd9Sstevel@tonic-gate 	    printf("3C90X: CRC Error (%hX)\n",errcode>>16);
6447c478bd9Sstevel@tonic-gate 	else if (errcode & (1<<20))
6457c478bd9Sstevel@tonic-gate 	    printf("3C90X: Oversized Frame (%hX)\n",errcode>>16);
6467c478bd9Sstevel@tonic-gate 	else
6477c478bd9Sstevel@tonic-gate 	    printf("3C90X: Packet error (%hX)\n",errcode>>16);
6487c478bd9Sstevel@tonic-gate 	return 0;
6497c478bd9Sstevel@tonic-gate 	}
6507c478bd9Sstevel@tonic-gate 
6517c478bd9Sstevel@tonic-gate     /** Ok, got packet.  Set length in nic->packetlen. **/
6527c478bd9Sstevel@tonic-gate     nic->packetlen = (INF_3C90X.ReceiveUPD.UpPktStatus & 0x1FFF);
6537c478bd9Sstevel@tonic-gate 
6547c478bd9Sstevel@tonic-gate     return 1;
6557c478bd9Sstevel@tonic-gate     }
6567c478bd9Sstevel@tonic-gate 
6577c478bd9Sstevel@tonic-gate 
6587c478bd9Sstevel@tonic-gate 
6597c478bd9Sstevel@tonic-gate /*** a3c90x_disable: exported routine to disable the card.  What's this for?
6607c478bd9Sstevel@tonic-gate  *** the eepro100.c driver didn't have one, so I just left this one empty too.
6617c478bd9Sstevel@tonic-gate  *** Ideas anyone?
6627c478bd9Sstevel@tonic-gate  *** Must turn off receiver at least so stray packets will not corrupt memory
6637c478bd9Sstevel@tonic-gate  *** [Ken]
6647c478bd9Sstevel@tonic-gate  ***/
6657c478bd9Sstevel@tonic-gate static void
a3c90x_disable(struct dev * dev __unused)6667c478bd9Sstevel@tonic-gate a3c90x_disable(struct dev *dev __unused)
6677c478bd9Sstevel@tonic-gate {
6687c478bd9Sstevel@tonic-gate 	/* reset and disable merge */
6697c478bd9Sstevel@tonic-gate 	a3c90x_reset();
6707c478bd9Sstevel@tonic-gate 	/* Disable the receiver and transmitter. */
6717c478bd9Sstevel@tonic-gate 	outw(cmdRxDisable, INF_3C90X.IOAddr + regCommandIntStatus_w);
6727c478bd9Sstevel@tonic-gate 	outw(cmdTxDisable, INF_3C90X.IOAddr + regCommandIntStatus_w);
6737c478bd9Sstevel@tonic-gate }
6747c478bd9Sstevel@tonic-gate 
a3c90x_irq(struct nic * nic __unused,irq_action_t action __unused)6757c478bd9Sstevel@tonic-gate static void a3c90x_irq(struct nic *nic __unused, irq_action_t action __unused)
6767c478bd9Sstevel@tonic-gate {
6777c478bd9Sstevel@tonic-gate   switch ( action ) {
6787c478bd9Sstevel@tonic-gate   case DISABLE :
6797c478bd9Sstevel@tonic-gate     break;
6807c478bd9Sstevel@tonic-gate   case ENABLE :
6817c478bd9Sstevel@tonic-gate     break;
6827c478bd9Sstevel@tonic-gate   case FORCE :
6837c478bd9Sstevel@tonic-gate     break;
6847c478bd9Sstevel@tonic-gate   }
6857c478bd9Sstevel@tonic-gate }
6867c478bd9Sstevel@tonic-gate 
6877c478bd9Sstevel@tonic-gate /*** a3c90x_probe: exported routine to probe for the 3c905 card and perform
6887c478bd9Sstevel@tonic-gate  *** initialization.  If this routine is called, the pci functions did find the
6897c478bd9Sstevel@tonic-gate  *** card.  We just have to init it here.
6907c478bd9Sstevel@tonic-gate  ***/
a3c90x_probe(struct dev * dev,struct pci_device * pci)6917c478bd9Sstevel@tonic-gate static int a3c90x_probe(struct dev *dev, struct pci_device *pci)
6927c478bd9Sstevel@tonic-gate {
6937c478bd9Sstevel@tonic-gate     struct nic *nic = (struct nic *)dev;
6947c478bd9Sstevel@tonic-gate     int i, c;
6957c478bd9Sstevel@tonic-gate     unsigned short eeprom[0x21];
6967c478bd9Sstevel@tonic-gate     unsigned int cfg;
6977c478bd9Sstevel@tonic-gate     unsigned int mopt;
6987c478bd9Sstevel@tonic-gate     unsigned int mstat;
6997c478bd9Sstevel@tonic-gate     unsigned short linktype;
7007c478bd9Sstevel@tonic-gate #define	HWADDR_OFFSET	10
7017c478bd9Sstevel@tonic-gate 
7027c478bd9Sstevel@tonic-gate     if (pci->ioaddr == 0)
7037c478bd9Sstevel@tonic-gate           return 0;
7047c478bd9Sstevel@tonic-gate 
7057c478bd9Sstevel@tonic-gate     adjust_pci_device(pci);
7067c478bd9Sstevel@tonic-gate 
7077c478bd9Sstevel@tonic-gate     nic->ioaddr = pci->ioaddr & ~3;
7087c478bd9Sstevel@tonic-gate     nic->irqno = 0;
7097c478bd9Sstevel@tonic-gate 
7107c478bd9Sstevel@tonic-gate     INF_3C90X.IOAddr = pci->ioaddr & ~3;
7117c478bd9Sstevel@tonic-gate     INF_3C90X.CurrentWindow = 255;
7127c478bd9Sstevel@tonic-gate     switch (a3c90x_internal_ReadEeprom(INF_3C90X.IOAddr, 0x03))
7137c478bd9Sstevel@tonic-gate 	{
7147c478bd9Sstevel@tonic-gate 	case 0x9000: /** 10 Base TPO             **/
7157c478bd9Sstevel@tonic-gate 	case 0x9001: /** 10/100 T4               **/
7167c478bd9Sstevel@tonic-gate 	case 0x9050: /** 10/100 TPO              **/
7177c478bd9Sstevel@tonic-gate 	case 0x9051: /** 10 Base Combo           **/
7187c478bd9Sstevel@tonic-gate 		INF_3C90X.isBrev = 0;
7197c478bd9Sstevel@tonic-gate 		break;
7207c478bd9Sstevel@tonic-gate 
7217c478bd9Sstevel@tonic-gate 	case 0x9004: /** 10 Base TPO             **/
7227c478bd9Sstevel@tonic-gate 	case 0x9005: /** 10 Base Combo           **/
7237c478bd9Sstevel@tonic-gate 	case 0x9006: /** 10 Base TPO and Base2   **/
7247c478bd9Sstevel@tonic-gate 	case 0x900A: /** 10 Base FL              **/
7257c478bd9Sstevel@tonic-gate 	case 0x9055: /** 10/100 TPO              **/
7267c478bd9Sstevel@tonic-gate 	case 0x9056: /** 10/100 T4               **/
7277c478bd9Sstevel@tonic-gate 	case 0x905A: /** 10 Base FX              **/
7287c478bd9Sstevel@tonic-gate 	default:
7297c478bd9Sstevel@tonic-gate 		INF_3C90X.isBrev = 1;
7307c478bd9Sstevel@tonic-gate 		break;
7317c478bd9Sstevel@tonic-gate 	}
7327c478bd9Sstevel@tonic-gate 
7337c478bd9Sstevel@tonic-gate     /** Load the EEPROM contents **/
7347c478bd9Sstevel@tonic-gate     if (INF_3C90X.isBrev)
7357c478bd9Sstevel@tonic-gate 	{
7367c478bd9Sstevel@tonic-gate 	for(i=0;i<=0x20;i++)
7377c478bd9Sstevel@tonic-gate 	    {
7387c478bd9Sstevel@tonic-gate 	    eeprom[i] = a3c90x_internal_ReadEeprom(INF_3C90X.IOAddr, i);
7397c478bd9Sstevel@tonic-gate 	    }
7407c478bd9Sstevel@tonic-gate 
7417c478bd9Sstevel@tonic-gate #ifdef	CFG_3C90X_BOOTROM_FIX
7427c478bd9Sstevel@tonic-gate 	/** Set xcvrSelect in InternalConfig in eeprom. **/
7437c478bd9Sstevel@tonic-gate 	/* only necessary for 3c905b revision cards with boot PROM bug!!! */
7447c478bd9Sstevel@tonic-gate 	a3c90x_internal_WriteEeprom(INF_3C90X.IOAddr, 0x13, 0x0160);
7457c478bd9Sstevel@tonic-gate #endif
7467c478bd9Sstevel@tonic-gate 
7477c478bd9Sstevel@tonic-gate #ifdef	CFG_3C90X_XCVR
7487c478bd9Sstevel@tonic-gate 	if (CFG_3C90X_XCVR == 255)
7497c478bd9Sstevel@tonic-gate 	    {
7507c478bd9Sstevel@tonic-gate 	    /** Clear the LanWorks register **/
7517c478bd9Sstevel@tonic-gate 	    a3c90x_internal_WriteEeprom(INF_3C90X.IOAddr, 0x16, 0);
7527c478bd9Sstevel@tonic-gate 	    }
7537c478bd9Sstevel@tonic-gate 	else
7547c478bd9Sstevel@tonic-gate 	    {
7557c478bd9Sstevel@tonic-gate 	    /** Set the selected permanent-xcvrSelect in the
7567c478bd9Sstevel@tonic-gate 	     ** LanWorks register
7577c478bd9Sstevel@tonic-gate 	     **/
7587c478bd9Sstevel@tonic-gate 	    a3c90x_internal_WriteEeprom(INF_3C90X.IOAddr, 0x16,
7597c478bd9Sstevel@tonic-gate 	                    XCVR_MAGIC + ((CFG_3C90X_XCVR) & 0x000F));
7607c478bd9Sstevel@tonic-gate 	    }
7617c478bd9Sstevel@tonic-gate #endif
7627c478bd9Sstevel@tonic-gate 	}
7637c478bd9Sstevel@tonic-gate     else
7647c478bd9Sstevel@tonic-gate 	{
7657c478bd9Sstevel@tonic-gate 	for(i=0;i<=0x17;i++)
7667c478bd9Sstevel@tonic-gate 	    {
7677c478bd9Sstevel@tonic-gate 	    eeprom[i] = a3c90x_internal_ReadEeprom(INF_3C90X.IOAddr, i);
7687c478bd9Sstevel@tonic-gate 	    }
7697c478bd9Sstevel@tonic-gate 	}
7707c478bd9Sstevel@tonic-gate 
7717c478bd9Sstevel@tonic-gate     /** Print identification message **/
7727c478bd9Sstevel@tonic-gate     printf("\n\n3C90X Driver 2.00 "
7737c478bd9Sstevel@tonic-gate            "Copyright 1999 LightSys Technology Services, Inc.\n"
7747c478bd9Sstevel@tonic-gate            "Portions Copyright 1999 Steve Smith\n");
7757c478bd9Sstevel@tonic-gate     printf("Provided with ABSOLUTELY NO WARRANTY.\n");
7767c478bd9Sstevel@tonic-gate #ifdef	CFG_3C90X_BOOTROM_FIX
7777c478bd9Sstevel@tonic-gate     if (INF_3C90X.isBrev)
7787c478bd9Sstevel@tonic-gate         {
7797c478bd9Sstevel@tonic-gate         printf("NOTE: 3c905b bootrom fix enabled; has side "
7807c478bd9Sstevel@tonic-gate 	   "effects.  See 3c90x.txt for info.\n");
7817c478bd9Sstevel@tonic-gate 	}
7827c478bd9Sstevel@tonic-gate #endif
7837c478bd9Sstevel@tonic-gate     printf("-------------------------------------------------------"
7847c478bd9Sstevel@tonic-gate            "------------------------\n");
7857c478bd9Sstevel@tonic-gate 
7867c478bd9Sstevel@tonic-gate     /** Retrieve the Hardware address and print it on the screen. **/
7877c478bd9Sstevel@tonic-gate     INF_3C90X.HWAddr[0] = eeprom[HWADDR_OFFSET + 0]>>8;
7887c478bd9Sstevel@tonic-gate     INF_3C90X.HWAddr[1] = eeprom[HWADDR_OFFSET + 0]&0xFF;
7897c478bd9Sstevel@tonic-gate     INF_3C90X.HWAddr[2] = eeprom[HWADDR_OFFSET + 1]>>8;
7907c478bd9Sstevel@tonic-gate     INF_3C90X.HWAddr[3] = eeprom[HWADDR_OFFSET + 1]&0xFF;
7917c478bd9Sstevel@tonic-gate     INF_3C90X.HWAddr[4] = eeprom[HWADDR_OFFSET + 2]>>8;
7927c478bd9Sstevel@tonic-gate     INF_3C90X.HWAddr[5] = eeprom[HWADDR_OFFSET + 2]&0xFF;
7937c478bd9Sstevel@tonic-gate     printf("MAC Address = %!\n", INF_3C90X.HWAddr);
7947c478bd9Sstevel@tonic-gate 
7957c478bd9Sstevel@tonic-gate     /* Test if the link is good, if not continue */
7967c478bd9Sstevel@tonic-gate     a3c90x_internal_SetWindow(INF_3C90X.IOAddr, winDiagnostics4);
7977c478bd9Sstevel@tonic-gate     mstat = inw(INF_3C90X.IOAddr + regMediaStatus_4_w);
7987c478bd9Sstevel@tonic-gate     if((mstat & (1<<11)) == 0) {
7997c478bd9Sstevel@tonic-gate 	printf("Valid link not established\n");
8007c478bd9Sstevel@tonic-gate 	return 0;
8017c478bd9Sstevel@tonic-gate     }
8027c478bd9Sstevel@tonic-gate 
8037c478bd9Sstevel@tonic-gate     /** Program the MAC address into the station address registers **/
8047c478bd9Sstevel@tonic-gate     a3c90x_internal_SetWindow(INF_3C90X.IOAddr, winAddressing2);
8057c478bd9Sstevel@tonic-gate     outw(htons(eeprom[HWADDR_OFFSET + 0]), INF_3C90X.IOAddr + regStationAddress_2_3w);
8067c478bd9Sstevel@tonic-gate     outw(htons(eeprom[HWADDR_OFFSET + 1]), INF_3C90X.IOAddr + regStationAddress_2_3w+2);
8077c478bd9Sstevel@tonic-gate     outw(htons(eeprom[HWADDR_OFFSET + 2]), INF_3C90X.IOAddr + regStationAddress_2_3w+4);
8087c478bd9Sstevel@tonic-gate     outw(0, INF_3C90X.IOAddr + regStationMask_2_3w+0);
8097c478bd9Sstevel@tonic-gate     outw(0, INF_3C90X.IOAddr + regStationMask_2_3w+2);
8107c478bd9Sstevel@tonic-gate     outw(0, INF_3C90X.IOAddr + regStationMask_2_3w+4);
8117c478bd9Sstevel@tonic-gate 
8127c478bd9Sstevel@tonic-gate     /** Fill in our entry in the etherboot arp table **/
8137c478bd9Sstevel@tonic-gate     for(i=0;i<ETH_ALEN;i++)
8147c478bd9Sstevel@tonic-gate 	nic->node_addr[i] = (eeprom[HWADDR_OFFSET + i/2] >> (8*((i&1)^1))) & 0xff;
8157c478bd9Sstevel@tonic-gate 
8167c478bd9Sstevel@tonic-gate     /** Read the media options register, print a message and set default
8177c478bd9Sstevel@tonic-gate      ** xcvr.
8187c478bd9Sstevel@tonic-gate      **
8197c478bd9Sstevel@tonic-gate      ** Uses Media Option command on B revision, Reset Option on non-B
8207c478bd9Sstevel@tonic-gate      ** revision cards -- same register address
8217c478bd9Sstevel@tonic-gate      **/
8227c478bd9Sstevel@tonic-gate     a3c90x_internal_SetWindow(INF_3C90X.IOAddr, winTxRxOptions3);
8237c478bd9Sstevel@tonic-gate     mopt = inw(INF_3C90X.IOAddr + regResetMediaOptions_3_w);
8247c478bd9Sstevel@tonic-gate 
8257c478bd9Sstevel@tonic-gate     /** mask out VCO bit that is defined as 10baseFL bit on B-rev cards **/
8267c478bd9Sstevel@tonic-gate     if (! INF_3C90X.isBrev)
8277c478bd9Sstevel@tonic-gate 	{
8287c478bd9Sstevel@tonic-gate 	mopt &= 0x7F;
8297c478bd9Sstevel@tonic-gate 	}
8307c478bd9Sstevel@tonic-gate 
8317c478bd9Sstevel@tonic-gate     printf("Connectors present: ");
8327c478bd9Sstevel@tonic-gate     c = 0;
8337c478bd9Sstevel@tonic-gate     linktype = 0x0008;
8347c478bd9Sstevel@tonic-gate     if (mopt & 0x01)
8357c478bd9Sstevel@tonic-gate 	{
8367c478bd9Sstevel@tonic-gate 	printf("%s100Base-T4",(c++)?", ":"");
8377c478bd9Sstevel@tonic-gate 	linktype = 0x0006;
8387c478bd9Sstevel@tonic-gate 	}
8397c478bd9Sstevel@tonic-gate     if (mopt & 0x04)
8407c478bd9Sstevel@tonic-gate 	{
8417c478bd9Sstevel@tonic-gate 	printf("%s100Base-FX",(c++)?", ":"");
8427c478bd9Sstevel@tonic-gate 	linktype = 0x0005;
8437c478bd9Sstevel@tonic-gate 	}
8447c478bd9Sstevel@tonic-gate     if (mopt & 0x10)
8457c478bd9Sstevel@tonic-gate 	{
8467c478bd9Sstevel@tonic-gate 	printf("%s10Base-2",(c++)?", ":"");
8477c478bd9Sstevel@tonic-gate 	linktype = 0x0003;
8487c478bd9Sstevel@tonic-gate 	}
8497c478bd9Sstevel@tonic-gate     if (mopt & 0x20)
8507c478bd9Sstevel@tonic-gate 	{
8517c478bd9Sstevel@tonic-gate 	printf("%sAUI",(c++)?", ":"");
8527c478bd9Sstevel@tonic-gate 	linktype = 0x0001;
8537c478bd9Sstevel@tonic-gate 	}
8547c478bd9Sstevel@tonic-gate     if (mopt & 0x40)
8557c478bd9Sstevel@tonic-gate 	{
8567c478bd9Sstevel@tonic-gate 	printf("%sMII",(c++)?", ":"");
8577c478bd9Sstevel@tonic-gate 	linktype = 0x0006;
8587c478bd9Sstevel@tonic-gate 	}
8597c478bd9Sstevel@tonic-gate     if ((mopt & 0xA) == 0xA)
8607c478bd9Sstevel@tonic-gate 	{
8617c478bd9Sstevel@tonic-gate 	printf("%s10Base-T / 100Base-TX",(c++)?", ":"");
8627c478bd9Sstevel@tonic-gate 	linktype = 0x0008;
8637c478bd9Sstevel@tonic-gate 	}
8647c478bd9Sstevel@tonic-gate     else if ((mopt & 0xA) == 0x2)
8657c478bd9Sstevel@tonic-gate 	{
8667c478bd9Sstevel@tonic-gate 	printf("%s100Base-TX",(c++)?", ":"");
8677c478bd9Sstevel@tonic-gate 	linktype = 0x0008;
8687c478bd9Sstevel@tonic-gate 	}
8697c478bd9Sstevel@tonic-gate     else if ((mopt & 0xA) == 0x8)
8707c478bd9Sstevel@tonic-gate 	{
8717c478bd9Sstevel@tonic-gate 	printf("%s10Base-T",(c++)?", ":"");
8727c478bd9Sstevel@tonic-gate 	linktype = 0x0008;
8737c478bd9Sstevel@tonic-gate 	}
8747c478bd9Sstevel@tonic-gate     printf(".\n");
8757c478bd9Sstevel@tonic-gate 
8767c478bd9Sstevel@tonic-gate     /** Determine transceiver type to use, depending on value stored in
8777c478bd9Sstevel@tonic-gate      ** eeprom 0x16
8787c478bd9Sstevel@tonic-gate      **/
8797c478bd9Sstevel@tonic-gate     if (INF_3C90X.isBrev)
8807c478bd9Sstevel@tonic-gate 	{
8817c478bd9Sstevel@tonic-gate 	if ((eeprom[0x16] & 0xFF00) == XCVR_MAGIC)
8827c478bd9Sstevel@tonic-gate 	    {
8837c478bd9Sstevel@tonic-gate 	    /** User-defined **/
8847c478bd9Sstevel@tonic-gate 	    linktype = eeprom[0x16] & 0x000F;
8857c478bd9Sstevel@tonic-gate 	    }
8867c478bd9Sstevel@tonic-gate 	}
8877c478bd9Sstevel@tonic-gate     else
8887c478bd9Sstevel@tonic-gate 	{
8897c478bd9Sstevel@tonic-gate #ifdef	CFG_3C90X_XCVR
8907c478bd9Sstevel@tonic-gate 	    if (CFG_3C90X_XCVR != 255)
8917c478bd9Sstevel@tonic-gate 		linktype = CFG_3C90X_XCVR;
8927c478bd9Sstevel@tonic-gate #endif	/* CFG_3C90X_XCVR */
8937c478bd9Sstevel@tonic-gate 
8947c478bd9Sstevel@tonic-gate 	    /** I don't know what MII MAC only mode is!!! **/
8957c478bd9Sstevel@tonic-gate 	    if (linktype == 0x0009)
8967c478bd9Sstevel@tonic-gate 		{
8977c478bd9Sstevel@tonic-gate 		if (INF_3C90X.isBrev)
8987c478bd9Sstevel@tonic-gate 			printf("WARNING: MII External MAC Mode only supported on B-revision "
8997c478bd9Sstevel@tonic-gate 			       "cards!!!!\nFalling Back to MII Mode\n");
9007c478bd9Sstevel@tonic-gate 		linktype = 0x0006;
9017c478bd9Sstevel@tonic-gate 		}
9027c478bd9Sstevel@tonic-gate 	}
9037c478bd9Sstevel@tonic-gate 
9047c478bd9Sstevel@tonic-gate     /** enable DC converter for 10-Base-T **/
9057c478bd9Sstevel@tonic-gate     if (linktype == 0x0003)
9067c478bd9Sstevel@tonic-gate 	{
9077c478bd9Sstevel@tonic-gate 	a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdEnableDcConverter, 0);
9087c478bd9Sstevel@tonic-gate 	}
9097c478bd9Sstevel@tonic-gate 
9107c478bd9Sstevel@tonic-gate     /** Set the link to the type we just determined. **/
9117c478bd9Sstevel@tonic-gate     a3c90x_internal_SetWindow(INF_3C90X.IOAddr, winTxRxOptions3);
9127c478bd9Sstevel@tonic-gate     cfg = inl(INF_3C90X.IOAddr + regInternalConfig_3_l);
9137c478bd9Sstevel@tonic-gate     cfg &= ~(0xF<<20);
9147c478bd9Sstevel@tonic-gate     cfg |= (linktype<<20);
9157c478bd9Sstevel@tonic-gate     outl(cfg, INF_3C90X.IOAddr + regInternalConfig_3_l);
9167c478bd9Sstevel@tonic-gate 
9177c478bd9Sstevel@tonic-gate     /** Now that we set the xcvr type, reset the Tx and Rx, re-enable. **/
9187c478bd9Sstevel@tonic-gate     a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdTxReset, 0x00);
9197c478bd9Sstevel@tonic-gate     while (inw(INF_3C90X.IOAddr + regCommandIntStatus_w) & INT_CMDINPROGRESS)
9207c478bd9Sstevel@tonic-gate 	;
9217c478bd9Sstevel@tonic-gate 
9227c478bd9Sstevel@tonic-gate     if (!INF_3C90X.isBrev)
9237c478bd9Sstevel@tonic-gate 	outb(0x01, INF_3C90X.IOAddr + regTxFreeThresh_b);
9247c478bd9Sstevel@tonic-gate 
9257c478bd9Sstevel@tonic-gate     a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdTxEnable, 0);
9267c478bd9Sstevel@tonic-gate 
9277c478bd9Sstevel@tonic-gate     /**
9287c478bd9Sstevel@tonic-gate      ** reset of the receiver on B-revision cards re-negotiates the link
9297c478bd9Sstevel@tonic-gate      ** takes several seconds (a computer eternity)
9307c478bd9Sstevel@tonic-gate      **/
9317c478bd9Sstevel@tonic-gate     if (INF_3C90X.isBrev)
9327c478bd9Sstevel@tonic-gate 	a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdRxReset, 0x04);
9337c478bd9Sstevel@tonic-gate     else
9347c478bd9Sstevel@tonic-gate 	a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdRxReset, 0x00);
9357c478bd9Sstevel@tonic-gate     while (inw(INF_3C90X.IOAddr + regCommandIntStatus_w) & INT_CMDINPROGRESS)
9367c478bd9Sstevel@tonic-gate 	;
9377c478bd9Sstevel@tonic-gate 
9387c478bd9Sstevel@tonic-gate     /** Set the RX filter = receive only individual pkts & multicast & bcast. **/
9397c478bd9Sstevel@tonic-gate     a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdSetRxFilter, 0x01 + 0x02 + 0x04);
9407c478bd9Sstevel@tonic-gate     a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdRxEnable, 0);
9417c478bd9Sstevel@tonic-gate 
9427c478bd9Sstevel@tonic-gate 
9437c478bd9Sstevel@tonic-gate     /**
9447c478bd9Sstevel@tonic-gate      ** set Indication and Interrupt flags , acknowledge any IRQ's
9457c478bd9Sstevel@tonic-gate      **/
9467c478bd9Sstevel@tonic-gate     a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdSetInterruptEnable, 0);
9477c478bd9Sstevel@tonic-gate     a3c90x_internal_IssueCommand(INF_3C90X.IOAddr,
9487c478bd9Sstevel@tonic-gate                                  cmdSetIndicationEnable, 0x0014);
9497c478bd9Sstevel@tonic-gate     a3c90x_internal_IssueCommand(INF_3C90X.IOAddr,
9507c478bd9Sstevel@tonic-gate                                  cmdAcknowledgeInterrupt, 0x661);
9517c478bd9Sstevel@tonic-gate 
9527c478bd9Sstevel@tonic-gate     /** Set our exported functions **/
9537c478bd9Sstevel@tonic-gate     dev->disable  = a3c90x_disable;
9547c478bd9Sstevel@tonic-gate     nic->poll     = a3c90x_poll;
9557c478bd9Sstevel@tonic-gate     nic->transmit = a3c90x_transmit;
9567c478bd9Sstevel@tonic-gate     nic->irq      = a3c90x_irq;
9577c478bd9Sstevel@tonic-gate 
9587c478bd9Sstevel@tonic-gate     return 1;
9597c478bd9Sstevel@tonic-gate }
9607c478bd9Sstevel@tonic-gate 
9617c478bd9Sstevel@tonic-gate 
9627c478bd9Sstevel@tonic-gate static struct pci_id a3c90x_nics[] = {
9637c478bd9Sstevel@tonic-gate /* Original 90x revisions: */
9647c478bd9Sstevel@tonic-gate PCI_ROM(0x10b7, 0x9000, "3c905-tpo",     "3Com900-TPO"),	/* 10 Base TPO */
9657c478bd9Sstevel@tonic-gate PCI_ROM(0x10b7, 0x9001, "3c905-t4",      "3Com900-Combo"),	/* 10/100 T4 */
9667c478bd9Sstevel@tonic-gate PCI_ROM(0x10b7, 0x9050, "3c905-tpo100",  "3Com905-TX"),		/* 100 Base TX / 10/100 TPO */
9677c478bd9Sstevel@tonic-gate PCI_ROM(0x10b7, 0x9051, "3c905-combo",   "3Com905-T4"),		/* 100 Base T4 / 10 Base Combo */
9687c478bd9Sstevel@tonic-gate /* Newer 90xB revisions: */
9697c478bd9Sstevel@tonic-gate PCI_ROM(0x10b7, 0x9004, "3c905b-tpo",    "3Com900B-TPO"),	/* 10 Base TPO */
9707c478bd9Sstevel@tonic-gate PCI_ROM(0x10b7, 0x9005, "3c905b-combo",  "3Com900B-Combo"),	/* 10 Base Combo */
9717c478bd9Sstevel@tonic-gate PCI_ROM(0x10b7, 0x9006, "3c905b-tpb2",   "3Com900B-2/T"),	/* 10 Base TP and Base2 */
9727c478bd9Sstevel@tonic-gate PCI_ROM(0x10b7, 0x900a, "3c905b-fl",     "3Com900B-FL"),	/* 10 Base FL */
9737c478bd9Sstevel@tonic-gate PCI_ROM(0x10b7, 0x9055, "3c905b-tpo100", "3Com905B-TX"),	/* 10/100 TPO */
9747c478bd9Sstevel@tonic-gate PCI_ROM(0x10b7, 0x9056, "3c905b-t4",     "3Com905B-T4"),	/* 10/100 T4 */
9757c478bd9Sstevel@tonic-gate PCI_ROM(0x10b7, 0x9058, "3c905b-9058",   "3Com905B-9058"),	/* Cyclone 10/100/BNC */
9767c478bd9Sstevel@tonic-gate PCI_ROM(0x10b7, 0x905a, "3c905b-fx",     "3Com905B-FL"),	/* 100 Base FX / 10 Base FX */
9777c478bd9Sstevel@tonic-gate /* Newer 90xC revision: */
9787c478bd9Sstevel@tonic-gate PCI_ROM(0x10b7, 0x9200, "3c905c-tpo",    "3Com905C-TXM"),	/* 10/100 TPO (3C905C-TXM) */
9797c478bd9Sstevel@tonic-gate PCI_ROM(0x10b7, 0x9210, "3c920b-emb-wnm","3Com20B-EMB WNM"),
9807c478bd9Sstevel@tonic-gate PCI_ROM(0x10b7, 0x9800, "3c980",         "3Com980-Cyclone"),	/* Cyclone */
9817c478bd9Sstevel@tonic-gate PCI_ROM(0x10b7, 0x9805, "3c9805",        "3Com9805"),		/* Dual Port Server Cyclone */
9827c478bd9Sstevel@tonic-gate PCI_ROM(0x10b7, 0x7646, "3csoho100-tx",  "3CSOHO100-TX"),	/* Hurricane */
9837c478bd9Sstevel@tonic-gate PCI_ROM(0x10b7, 0x4500, "3c450",         "3Com450 HomePNA Tornado"),
9847c478bd9Sstevel@tonic-gate PCI_ROM(0x10b7, 0x1201, "3c982a",        "3Com982A"),
9857c478bd9Sstevel@tonic-gate PCI_ROM(0x10b7, 0x1202, "3c982b",        "3Com982B"),
9867c478bd9Sstevel@tonic-gate };
9877c478bd9Sstevel@tonic-gate 
9887c478bd9Sstevel@tonic-gate struct pci_driver a3c90x_driver = {
9897c478bd9Sstevel@tonic-gate 	.type     = NIC_DRIVER,
9907c478bd9Sstevel@tonic-gate 	.name     = "3C90X",
9917c478bd9Sstevel@tonic-gate 	.probe    = a3c90x_probe,
9927c478bd9Sstevel@tonic-gate 	.ids      = a3c90x_nics,
9937c478bd9Sstevel@tonic-gate 	.id_count = sizeof(a3c90x_nics)/sizeof(a3c90x_nics[0]),
9947c478bd9Sstevel@tonic-gate 	.class    = 0,
9957c478bd9Sstevel@tonic-gate };
996