You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3c90x.c 34KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992
  1. /*
  2. * 3c90x.c -- This file implements the 3c90x driver for etherboot. Written
  3. * by Greg Beeley, Greg.Beeley@LightSys.org. Modified by Steve Smith,
  4. * Steve.Smith@Juno.Com. Alignment bug fix Neil Newell (nn@icenoir.net).
  5. *
  6. * This program Copyright (C) 1999 LightSys Technology Services, Inc.
  7. * Portions Copyright (C) 1999 Steve Smith
  8. *
  9. * This program may be re-distributed in source or binary form, modified,
  10. * sold, or copied for any purpose, provided that the above copyright message
  11. * and this text are included with all source copies or derivative works, and
  12. * provided that the above copyright message and this text are included in the
  13. * documentation of any binary-only distributions. This program is distributed
  14. * WITHOUT ANY WARRANTY, without even the warranty of FITNESS FOR A PARTICULAR
  15. * PURPOSE or MERCHANTABILITY. Please read the associated documentation
  16. * "3c90x.txt" before compiling and using this driver.
  17. *
  18. * --------
  19. *
  20. * Program written with the assistance of the 3com documentation for
  21. * the 3c905B-TX card, as well as with some assistance from the 3c59x
  22. * driver Donald Becker wrote for the Linux kernel, and with some assistance
  23. * from the remainder of the Etherboot distribution.
  24. *
  25. * REVISION HISTORY:
  26. *
  27. * v0.10 1-26-1998 GRB Initial implementation.
  28. * v0.90 1-27-1998 GRB System works.
  29. * v1.00pre1 2-11-1998 GRB Got prom boot issue fixed.
  30. * v2.0 9-24-1999 SCS Modified for 3c905 (from 3c905b code)
  31. * Re-wrote poll and transmit for
  32. * better error recovery and heavy
  33. * network traffic operation
  34. * v2.01 5-26-2003 NN Fixed driver alignment issue which
  35. * caused system lockups if driver structures
  36. * not 8-byte aligned.
  37. *
  38. */
  39. #include "etherboot.h"
  40. #include "nic.h"
  41. #include "pci.h"
  42. #include "timer.h"
  43. #define XCVR_MAGIC (0x5A00)
  44. /** any single transmission fails after 16 collisions or other errors
  45. ** this is the number of times to retry the transmission -- this should
  46. ** be plenty
  47. **/
  48. #define XMIT_RETRIES 250
  49. /*** Register definitions for the 3c905 ***/
  50. enum Registers
  51. {
  52. regPowerMgmtCtrl_w = 0x7c, /** 905B Revision Only **/
  53. regUpMaxBurst_w = 0x7a, /** 905B Revision Only **/
  54. regDnMaxBurst_w = 0x78, /** 905B Revision Only **/
  55. regDebugControl_w = 0x74, /** 905B Revision Only **/
  56. regDebugData_l = 0x70, /** 905B Revision Only **/
  57. regRealTimeCnt_l = 0x40, /** Universal **/
  58. regUpBurstThresh_b = 0x3e, /** 905B Revision Only **/
  59. regUpPoll_b = 0x3d, /** 905B Revision Only **/
  60. regUpPriorityThresh_b = 0x3c, /** 905B Revision Only **/
  61. regUpListPtr_l = 0x38, /** Universal **/
  62. regCountdown_w = 0x36, /** Universal **/
  63. regFreeTimer_w = 0x34, /** Universal **/
  64. regUpPktStatus_l = 0x30, /** Universal with Exception, pg 130 **/
  65. regTxFreeThresh_b = 0x2f, /** 90X Revision Only **/
  66. regDnPoll_b = 0x2d, /** 905B Revision Only **/
  67. regDnPriorityThresh_b = 0x2c, /** 905B Revision Only **/
  68. regDnBurstThresh_b = 0x2a, /** 905B Revision Only **/
  69. regDnListPtr_l = 0x24, /** Universal with Exception, pg 107 **/
  70. regDmaCtrl_l = 0x20, /** Universal with Exception, pg 106 **/
  71. /** **/
  72. regIntStatusAuto_w = 0x1e, /** 905B Revision Only **/
  73. regTxStatus_b = 0x1b, /** Universal with Exception, pg 113 **/
  74. regTimer_b = 0x1a, /** Universal **/
  75. regTxPktId_b = 0x18, /** 905B Revision Only **/
  76. regCommandIntStatus_w = 0x0e, /** Universal (Command Variations) **/
  77. };
  78. /** following are windowed registers **/
  79. enum Registers7
  80. {
  81. regPowerMgmtEvent_7_w = 0x0c, /** 905B Revision Only **/
  82. regVlanEtherType_7_w = 0x04, /** 905B Revision Only **/
  83. regVlanMask_7_w = 0x00, /** 905B Revision Only **/
  84. };
  85. enum Registers6
  86. {
  87. regBytesXmittedOk_6_w = 0x0c, /** Universal **/
  88. regBytesRcvdOk_6_w = 0x0a, /** Universal **/
  89. regUpperFramesOk_6_b = 0x09, /** Universal **/
  90. regFramesDeferred_6_b = 0x08, /** Universal **/
  91. regFramesRecdOk_6_b = 0x07, /** Universal with Exceptions, pg 142 **/
  92. regFramesXmittedOk_6_b = 0x06, /** Universal **/
  93. regRxOverruns_6_b = 0x05, /** Universal **/
  94. regLateCollisions_6_b = 0x04, /** Universal **/
  95. regSingleCollisions_6_b = 0x03, /** Universal **/
  96. regMultipleCollisions_6_b = 0x02, /** Universal **/
  97. regSqeErrors_6_b = 0x01, /** Universal **/
  98. regCarrierLost_6_b = 0x00, /** Universal **/
  99. };
  100. enum Registers5
  101. {
  102. regIndicationEnable_5_w = 0x0c, /** Universal **/
  103. regInterruptEnable_5_w = 0x0a, /** Universal **/
  104. regTxReclaimThresh_5_b = 0x09, /** 905B Revision Only **/
  105. regRxFilter_5_b = 0x08, /** Universal **/
  106. regRxEarlyThresh_5_w = 0x06, /** Universal **/
  107. regTxStartThresh_5_w = 0x00, /** Universal **/
  108. };
  109. enum Registers4
  110. {
  111. regUpperBytesOk_4_b = 0x0d, /** Universal **/
  112. regBadSSD_4_b = 0x0c, /** Universal **/
  113. regMediaStatus_4_w = 0x0a, /** Universal with Exceptions, pg 201 **/
  114. regPhysicalMgmt_4_w = 0x08, /** Universal **/
  115. regNetworkDiagnostic_4_w = 0x06, /** Universal with Exceptions, pg 203 **/
  116. regFifoDiagnostic_4_w = 0x04, /** Universal with Exceptions, pg 196 **/
  117. regVcoDiagnostic_4_w = 0x02, /** Undocumented? **/
  118. };
  119. enum Registers3
  120. {
  121. regTxFree_3_w = 0x0c, /** Universal **/
  122. regRxFree_3_w = 0x0a, /** Universal with Exceptions, pg 125 **/
  123. regResetMediaOptions_3_w = 0x08, /** Media Options on B Revision, **/
  124. /** Reset Options on Non-B Revision **/
  125. regMacControl_3_w = 0x06, /** Universal with Exceptions, pg 199 **/
  126. regMaxPktSize_3_w = 0x04, /** 905B Revision Only **/
  127. regInternalConfig_3_l = 0x00, /** Universal, different bit **/
  128. /** definitions, pg 59 **/
  129. };
  130. enum Registers2
  131. {
  132. regResetOptions_2_w = 0x0c, /** 905B Revision Only **/
  133. regStationMask_2_3w = 0x06, /** Universal with Exceptions, pg 127 **/
  134. regStationAddress_2_3w = 0x00, /** Universal with Exceptions, pg 127 **/
  135. };
  136. enum Registers1
  137. {
  138. regRxStatus_1_w = 0x0a, /** 90X Revision Only, Pg 126 **/
  139. };
  140. enum Registers0
  141. {
  142. regEepromData_0_w = 0x0c, /** Universal **/
  143. regEepromCommand_0_w = 0x0a, /** Universal **/
  144. regBiosRomData_0_b = 0x08, /** 905B Revision Only **/
  145. regBiosRomAddr_0_l = 0x04, /** 905B Revision Only **/
  146. };
  147. /*** The names for the eight register windows ***/
  148. enum Windows
  149. {
  150. winPowerVlan7 = 0x07,
  151. winStatistics6 = 0x06,
  152. winTxRxControl5 = 0x05,
  153. winDiagnostics4 = 0x04,
  154. winTxRxOptions3 = 0x03,
  155. winAddressing2 = 0x02,
  156. winUnused1 = 0x01,
  157. winEepromBios0 = 0x00,
  158. };
  159. /*** Command definitions for the 3c90X ***/
  160. enum Commands
  161. {
  162. cmdGlobalReset = 0x00, /** Universal with Exceptions, pg 151 **/
  163. cmdSelectRegisterWindow = 0x01, /** Universal **/
  164. cmdEnableDcConverter = 0x02, /** **/
  165. cmdRxDisable = 0x03, /** **/
  166. cmdRxEnable = 0x04, /** Universal **/
  167. cmdRxReset = 0x05, /** Universal **/
  168. cmdStallCtl = 0x06, /** Universal **/
  169. cmdTxEnable = 0x09, /** Universal **/
  170. cmdTxDisable = 0x0A, /** **/
  171. cmdTxReset = 0x0B, /** Universal **/
  172. cmdRequestInterrupt = 0x0C, /** **/
  173. cmdAcknowledgeInterrupt = 0x0D, /** Universal **/
  174. cmdSetInterruptEnable = 0x0E, /** Universal **/
  175. cmdSetIndicationEnable = 0x0F, /** Universal **/
  176. cmdSetRxFilter = 0x10, /** Universal **/
  177. cmdSetRxEarlyThresh = 0x11, /** **/
  178. cmdSetTxStartThresh = 0x13, /** **/
  179. cmdStatisticsEnable = 0x15, /** **/
  180. cmdStatisticsDisable = 0x16, /** **/
  181. cmdDisableDcConverter = 0x17, /** **/
  182. cmdSetTxReclaimThresh = 0x18, /** **/
  183. cmdSetHashFilterBit = 0x19, /** **/
  184. };
  185. /*** Values for int status register bitmask **/
  186. #define INT_INTERRUPTLATCH (1<<0)
  187. #define INT_HOSTERROR (1<<1)
  188. #define INT_TXCOMPLETE (1<<2)
  189. #define INT_RXCOMPLETE (1<<4)
  190. #define INT_RXEARLY (1<<5)
  191. #define INT_INTREQUESTED (1<<6)
  192. #define INT_UPDATESTATS (1<<7)
  193. #define INT_LINKEVENT (1<<8)
  194. #define INT_DNCOMPLETE (1<<9)
  195. #define INT_UPCOMPLETE (1<<10)
  196. #define INT_CMDINPROGRESS (1<<12)
  197. #define INT_WINDOWNUMBER (7<<13)
  198. /*** TX descriptor ***/
  199. typedef struct
  200. {
  201. unsigned int DnNextPtr;
  202. unsigned int FrameStartHeader;
  203. unsigned int HdrAddr;
  204. unsigned int HdrLength;
  205. unsigned int DataAddr;
  206. unsigned int DataLength;
  207. }
  208. TXD __attribute__ ((aligned(8))); /* 64-bit aligned for bus mastering */
  209. /*** RX descriptor ***/
  210. typedef struct
  211. {
  212. unsigned int UpNextPtr;
  213. unsigned int UpPktStatus;
  214. unsigned int DataAddr;
  215. unsigned int DataLength;
  216. }
  217. RXD __attribute__ ((aligned(8))); /* 64-bit aligned for bus mastering */
  218. /*** Global variables ***/
  219. static struct
  220. {
  221. unsigned char isBrev;
  222. unsigned char CurrentWindow;
  223. unsigned int IOAddr;
  224. unsigned char HWAddr[ETH_ALEN];
  225. TXD TransmitDPD;
  226. RXD ReceiveUPD;
  227. }
  228. INF_3C90X;
  229. /*** a3c90x_internal_IssueCommand: sends a command to the 3c90x card
  230. ***/
  231. static int
  232. a3c90x_internal_IssueCommand(int ioaddr, int cmd, int param)
  233. {
  234. unsigned int val;
  235. /** Build the cmd. **/
  236. val = cmd;
  237. val <<= 11;
  238. val |= param;
  239. /** Send the cmd to the cmd register **/
  240. outw(val, ioaddr + regCommandIntStatus_w);
  241. /** Wait for the cmd to complete, if necessary **/
  242. while (inw(ioaddr + regCommandIntStatus_w) & INT_CMDINPROGRESS);
  243. return 0;
  244. }
  245. /*** a3c90x_internal_SetWindow: selects a register window set.
  246. ***/
  247. static int
  248. a3c90x_internal_SetWindow(int ioaddr, int window)
  249. {
  250. /** Window already as set? **/
  251. if (INF_3C90X.CurrentWindow == window) return 0;
  252. /** Issue the window command. **/
  253. a3c90x_internal_IssueCommand(ioaddr, cmdSelectRegisterWindow, window);
  254. INF_3C90X.CurrentWindow = window;
  255. return 0;
  256. }
  257. /*** a3c90x_internal_ReadEeprom - read data from the serial eeprom.
  258. ***/
  259. static unsigned short
  260. a3c90x_internal_ReadEeprom(int ioaddr, int address)
  261. {
  262. unsigned short val;
  263. /** Select correct window **/
  264. a3c90x_internal_SetWindow(INF_3C90X.IOAddr, winEepromBios0);
  265. /** Make sure the eeprom isn't busy **/
  266. while((1<<15) & inw(ioaddr + regEepromCommand_0_w));
  267. /** Read the value. **/
  268. outw(address + ((0x02)<<6), ioaddr + regEepromCommand_0_w);
  269. while((1<<15) & inw(ioaddr + regEepromCommand_0_w));
  270. val = inw(ioaddr + regEepromData_0_w);
  271. return val;
  272. }
  273. #if 0
  274. /*** a3c90x_internal_WriteEepromWord - write a physical word of
  275. *** data to the onboard serial eeprom (not the BIOS prom, but the
  276. *** nvram in the card that stores, among other things, the MAC
  277. *** address).
  278. ***/
  279. static int
  280. a3c90x_internal_WriteEepromWord(int ioaddr, int address, unsigned short value)
  281. {
  282. /** Select register window **/
  283. a3c90x_internal_SetWindow(ioaddr, winEepromBios0);
  284. /** Verify Eeprom not busy **/
  285. while((1<<15) & inw(ioaddr + regEepromCommand_0_w));
  286. /** Issue WriteEnable, and wait for completion. **/
  287. outw(0x30, ioaddr + regEepromCommand_0_w);
  288. while((1<<15) & inw(ioaddr + regEepromCommand_0_w));
  289. /** Issue EraseRegister, and wait for completion. **/
  290. outw(address + ((0x03)<<6), ioaddr + regEepromCommand_0_w);
  291. while((1<<15) & inw(ioaddr + regEepromCommand_0_w));
  292. /** Send the new data to the eeprom, and wait for completion. **/
  293. outw(value, ioaddr + regEepromData_0_w);
  294. outw(0x30, ioaddr + regEepromCommand_0_w);
  295. while((1<<15) & inw(ioaddr + regEepromCommand_0_w));
  296. /** Burn the new data into the eeprom, and wait for completion. **/
  297. outw(address + ((0x01)<<6), ioaddr + regEepromCommand_0_w);
  298. while((1<<15) & inw(ioaddr + regEepromCommand_0_w));
  299. return 0;
  300. }
  301. #endif
  302. #if 0
  303. /*** a3c90x_internal_WriteEeprom - write data to the serial eeprom,
  304. *** and re-compute the eeprom checksum.
  305. ***/
  306. static int
  307. a3c90x_internal_WriteEeprom(int ioaddr, int address, unsigned short value)
  308. {
  309. int cksum = 0,v;
  310. int i;
  311. int maxAddress, cksumAddress;
  312. if (INF_3C90X.isBrev)
  313. {
  314. maxAddress=0x1f;
  315. cksumAddress=0x20;
  316. }
  317. else
  318. {
  319. maxAddress=0x16;
  320. cksumAddress=0x17;
  321. }
  322. /** Write the value. **/
  323. if (a3c90x_internal_WriteEepromWord(ioaddr, address, value) == -1)
  324. return -1;
  325. /** Recompute the checksum. **/
  326. for(i=0;i<=maxAddress;i++)
  327. {
  328. v = a3c90x_internal_ReadEeprom(ioaddr, i);
  329. cksum ^= (v & 0xFF);
  330. cksum ^= ((v>>8) & 0xFF);
  331. }
  332. /** Write the checksum to the location in the eeprom **/
  333. if (a3c90x_internal_WriteEepromWord(ioaddr, cksumAddress, cksum) == -1)
  334. return -1;
  335. return 0;
  336. }
  337. #endif
  338. /*** a3c90x_reset: exported function that resets the card to its default
  339. *** state. This is so the Linux driver can re-set the card up the way
  340. *** it wants to. If CFG_3C90X_PRESERVE_XCVR is defined, then the reset will
  341. *** not alter the selected transceiver that we used to download the boot
  342. *** image.
  343. ***/
  344. static void a3c90x_reset(void)
  345. {
  346. #ifdef CFG_3C90X_PRESERVE_XCVR
  347. int cfg;
  348. /** Read the current InternalConfig value. **/
  349. a3c90x_internal_SetWindow(INF_3C90X.IOAddr, winTxRxOptions3);
  350. cfg = inl(INF_3C90X.IOAddr + regInternalConfig_3_l);
  351. #endif
  352. /** Send the reset command to the card **/
  353. printf("Issuing RESET:\n");
  354. a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdGlobalReset, 0);
  355. /** wait for reset command to complete **/
  356. while (inw(INF_3C90X.IOAddr + regCommandIntStatus_w) & INT_CMDINPROGRESS);
  357. /** global reset command resets station mask, non-B revision cards
  358. ** require explicit reset of values
  359. **/
  360. a3c90x_internal_SetWindow(INF_3C90X.IOAddr, winAddressing2);
  361. outw(0, INF_3C90X.IOAddr + regStationMask_2_3w+0);
  362. outw(0, INF_3C90X.IOAddr + regStationMask_2_3w+2);
  363. outw(0, INF_3C90X.IOAddr + regStationMask_2_3w+4);
  364. #ifdef CFG_3C90X_PRESERVE_XCVR
  365. /** Re-set the original InternalConfig value from before reset **/
  366. a3c90x_internal_SetWindow(INF_3C90X.IOAddr, winTxRxOptions3);
  367. outl(cfg, INF_3C90X.IOAddr + regInternalConfig_3_l);
  368. /** enable DC converter for 10-Base-T **/
  369. if ((cfg&0x0300) == 0x0300)
  370. {
  371. a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdEnableDcConverter, 0);
  372. }
  373. #endif
  374. /** Issue transmit reset, wait for command completion **/
  375. a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdTxReset, 0);
  376. while (inw(INF_3C90X.IOAddr + regCommandIntStatus_w) & INT_CMDINPROGRESS)
  377. ;
  378. if (! INF_3C90X.isBrev)
  379. outb(0x01, INF_3C90X.IOAddr + regTxFreeThresh_b);
  380. a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdTxEnable, 0);
  381. /**
  382. ** reset of the receiver on B-revision cards re-negotiates the link
  383. ** takes several seconds (a computer eternity)
  384. **/
  385. if (INF_3C90X.isBrev)
  386. a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdRxReset, 0x04);
  387. else
  388. a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdRxReset, 0x00);
  389. while (inw(INF_3C90X.IOAddr + regCommandIntStatus_w) & INT_CMDINPROGRESS);
  390. ;
  391. a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdRxEnable, 0);
  392. a3c90x_internal_IssueCommand(INF_3C90X.IOAddr,
  393. cmdSetInterruptEnable, 0);
  394. /** enable rxComplete and txComplete **/
  395. a3c90x_internal_IssueCommand(INF_3C90X.IOAddr,
  396. cmdSetIndicationEnable, 0x0014);
  397. /** acknowledge any pending status flags **/
  398. a3c90x_internal_IssueCommand(INF_3C90X.IOAddr,
  399. cmdAcknowledgeInterrupt, 0x661);
  400. return;
  401. }
  402. /*** a3c90x_transmit: exported function that transmits a packet. Does not
  403. *** return any particular status. Parameters are:
  404. *** d[6] - destination address, ethernet;
  405. *** t - protocol type (ARP, IP, etc);
  406. *** s - size of the non-header part of the packet that needs transmitted;
  407. *** p - the pointer to the packet data itself.
  408. ***/
  409. static void
  410. a3c90x_transmit(struct nic *nic __unused, const char *d, unsigned int t,
  411. unsigned int s, const char *p)
  412. {
  413. struct eth_hdr
  414. {
  415. unsigned char dst_addr[ETH_ALEN];
  416. unsigned char src_addr[ETH_ALEN];
  417. unsigned short type;
  418. } hdr;
  419. unsigned char status;
  420. unsigned i, retries;
  421. for (retries=0; retries < XMIT_RETRIES ; retries++)
  422. {
  423. /** Stall the download engine **/
  424. a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdStallCtl, 2);
  425. /** Make sure the card is not waiting on us **/
  426. inw(INF_3C90X.IOAddr + regCommandIntStatus_w);
  427. inw(INF_3C90X.IOAddr + regCommandIntStatus_w);
  428. while (inw(INF_3C90X.IOAddr+regCommandIntStatus_w) &
  429. INT_CMDINPROGRESS)
  430. ;
  431. /** Set the ethernet packet type **/
  432. hdr.type = htons(t);
  433. /** Copy the destination address **/
  434. memcpy(hdr.dst_addr, d, ETH_ALEN);
  435. /** Copy our MAC address **/
  436. memcpy(hdr.src_addr, INF_3C90X.HWAddr, ETH_ALEN);
  437. /** Setup the DPD (download descriptor) **/
  438. INF_3C90X.TransmitDPD.DnNextPtr = 0;
  439. /** set notification for transmission completion (bit 15) **/
  440. INF_3C90X.TransmitDPD.FrameStartHeader = (s + sizeof(hdr)) | 0x8000;
  441. INF_3C90X.TransmitDPD.HdrAddr = virt_to_bus(&hdr);
  442. INF_3C90X.TransmitDPD.HdrLength = sizeof(hdr);
  443. INF_3C90X.TransmitDPD.DataAddr = virt_to_bus(p);
  444. INF_3C90X.TransmitDPD.DataLength = s + (1<<31);
  445. /** Send the packet **/
  446. outl(virt_to_bus(&(INF_3C90X.TransmitDPD)),
  447. INF_3C90X.IOAddr + regDnListPtr_l);
  448. /** End Stall and Wait for upload to complete. **/
  449. a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdStallCtl, 3);
  450. while(inl(INF_3C90X.IOAddr + regDnListPtr_l) != 0)
  451. ;
  452. /** Wait for NIC Transmit to Complete **/
  453. load_timer2(10*TICKS_PER_MS); /* Give it 10 ms */
  454. while (!(inw(INF_3C90X.IOAddr + regCommandIntStatus_w)&0x0004) &&
  455. timer2_running())
  456. ;
  457. if (!(inw(INF_3C90X.IOAddr + regCommandIntStatus_w)&0x0004))
  458. {
  459. printf("3C90X: Tx Timeout\n");
  460. continue;
  461. }
  462. status = inb(INF_3C90X.IOAddr + regTxStatus_b);
  463. /** acknowledge transmit interrupt by writing status **/
  464. outb(0x00, INF_3C90X.IOAddr + regTxStatus_b);
  465. /** successful completion (sans "interrupt Requested" bit) **/
  466. if ((status & 0xbf) == 0x80)
  467. return;
  468. printf("3C90X: Status (%hhX)\n", status);
  469. /** check error codes **/
  470. if (status & 0x02)
  471. {
  472. printf("3C90X: Tx Reclaim Error (%hhX)\n", status);
  473. a3c90x_reset();
  474. }
  475. else if (status & 0x04)
  476. {
  477. printf("3C90X: Tx Status Overflow (%hhX)\n", status);
  478. for (i=0; i<32; i++)
  479. outb(0x00, INF_3C90X.IOAddr + regTxStatus_b);
  480. /** must re-enable after max collisions before re-issuing tx **/
  481. a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdTxEnable, 0);
  482. }
  483. else if (status & 0x08)
  484. {
  485. printf("3C90X: Tx Max Collisions (%hhX)\n", status);
  486. /** must re-enable after max collisions before re-issuing tx **/
  487. a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdTxEnable, 0);
  488. }
  489. else if (status & 0x10)
  490. {
  491. printf("3C90X: Tx Underrun (%hhX)\n", status);
  492. a3c90x_reset();
  493. }
  494. else if (status & 0x20)
  495. {
  496. printf("3C90X: Tx Jabber (%hhX)\n", status);
  497. a3c90x_reset();
  498. }
  499. else if ((status & 0x80) != 0x80)
  500. {
  501. printf("3C90X: Internal Error - Incomplete Transmission (%hhX)\n",
  502. status);
  503. a3c90x_reset();
  504. }
  505. }
  506. /** failed after RETRY attempts **/
  507. printf("Failed to send after %d retries\n", retries);
  508. return;
  509. }
  510. /*** a3c90x_poll: exported routine that waits for a certain length of time
  511. *** for a packet, and if it sees none, returns 0. This routine should
  512. *** copy the packet to nic->packet if it gets a packet and set the size
  513. *** in nic->packetlen. Return 1 if a packet was found.
  514. ***/
  515. static int
  516. a3c90x_poll(struct nic *nic, int retrieve)
  517. {
  518. int i, errcode;
  519. if (!(inw(INF_3C90X.IOAddr + regCommandIntStatus_w)&0x0010))
  520. {
  521. return 0;
  522. }
  523. if ( ! retrieve ) return 1;
  524. /** we don't need to acknowledge rxComplete -- the upload engine
  525. ** does it for us.
  526. **/
  527. /** Build the up-load descriptor **/
  528. INF_3C90X.ReceiveUPD.UpNextPtr = 0;
  529. INF_3C90X.ReceiveUPD.UpPktStatus = 0;
  530. INF_3C90X.ReceiveUPD.DataAddr = virt_to_bus(nic->packet);
  531. INF_3C90X.ReceiveUPD.DataLength = 1536 + (1<<31);
  532. /** Submit the upload descriptor to the NIC **/
  533. outl(virt_to_bus(&(INF_3C90X.ReceiveUPD)),
  534. INF_3C90X.IOAddr + regUpListPtr_l);
  535. /** Wait for upload completion (upComplete(15) or upError (14)) **/
  536. for(i=0;i<40000;i++);
  537. while((INF_3C90X.ReceiveUPD.UpPktStatus & ((1<<14) | (1<<15))) == 0)
  538. for(i=0;i<40000;i++);
  539. /** Check for Error (else we have good packet) **/
  540. if (INF_3C90X.ReceiveUPD.UpPktStatus & (1<<14))
  541. {
  542. errcode = INF_3C90X.ReceiveUPD.UpPktStatus;
  543. if (errcode & (1<<16))
  544. printf("3C90X: Rx Overrun (%hX)\n",errcode>>16);
  545. else if (errcode & (1<<17))
  546. printf("3C90X: Runt Frame (%hX)\n",errcode>>16);
  547. else if (errcode & (1<<18))
  548. printf("3C90X: Alignment Error (%hX)\n",errcode>>16);
  549. else if (errcode & (1<<19))
  550. printf("3C90X: CRC Error (%hX)\n",errcode>>16);
  551. else if (errcode & (1<<20))
  552. printf("3C90X: Oversized Frame (%hX)\n",errcode>>16);
  553. else
  554. printf("3C90X: Packet error (%hX)\n",errcode>>16);
  555. return 0;
  556. }
  557. /** Ok, got packet. Set length in nic->packetlen. **/
  558. nic->packetlen = (INF_3C90X.ReceiveUPD.UpPktStatus & 0x1FFF);
  559. return 1;
  560. }
  561. /*** a3c90x_disable: exported routine to disable the card. What's this for?
  562. *** the eepro100.c driver didn't have one, so I just left this one empty too.
  563. *** Ideas anyone?
  564. *** Must turn off receiver at least so stray packets will not corrupt memory
  565. *** [Ken]
  566. ***/
  567. static void
  568. a3c90x_disable(struct dev *dev __unused)
  569. {
  570. /* reset and disable merge */
  571. a3c90x_reset();
  572. /* Disable the receiver and transmitter. */
  573. outw(cmdRxDisable, INF_3C90X.IOAddr + regCommandIntStatus_w);
  574. outw(cmdTxDisable, INF_3C90X.IOAddr + regCommandIntStatus_w);
  575. }
  576. static void a3c90x_irq(struct nic *nic __unused, irq_action_t action __unused)
  577. {
  578. switch ( action ) {
  579. case DISABLE :
  580. break;
  581. case ENABLE :
  582. break;
  583. case FORCE :
  584. break;
  585. }
  586. }
  587. /*** a3c90x_probe: exported routine to probe for the 3c905 card and perform
  588. *** initialization. If this routine is called, the pci functions did find the
  589. *** card. We just have to init it here.
  590. ***/
  591. static int a3c90x_probe(struct dev *dev, struct pci_device *pci)
  592. {
  593. struct nic *nic = (struct nic *)dev;
  594. int i, c;
  595. unsigned short eeprom[0x21];
  596. unsigned int cfg;
  597. unsigned int mopt;
  598. unsigned int mstat;
  599. unsigned short linktype;
  600. #define HWADDR_OFFSET 10
  601. if (pci->ioaddr == 0)
  602. return 0;
  603. adjust_pci_device(pci);
  604. nic->ioaddr = pci->ioaddr & ~3;
  605. nic->irqno = 0;
  606. INF_3C90X.IOAddr = pci->ioaddr & ~3;
  607. INF_3C90X.CurrentWindow = 255;
  608. switch (a3c90x_internal_ReadEeprom(INF_3C90X.IOAddr, 0x03))
  609. {
  610. case 0x9000: /** 10 Base TPO **/
  611. case 0x9001: /** 10/100 T4 **/
  612. case 0x9050: /** 10/100 TPO **/
  613. case 0x9051: /** 10 Base Combo **/
  614. INF_3C90X.isBrev = 0;
  615. break;
  616. case 0x9004: /** 10 Base TPO **/
  617. case 0x9005: /** 10 Base Combo **/
  618. case 0x9006: /** 10 Base TPO and Base2 **/
  619. case 0x900A: /** 10 Base FL **/
  620. case 0x9055: /** 10/100 TPO **/
  621. case 0x9056: /** 10/100 T4 **/
  622. case 0x905A: /** 10 Base FX **/
  623. default:
  624. INF_3C90X.isBrev = 1;
  625. break;
  626. }
  627. /** Load the EEPROM contents **/
  628. if (INF_3C90X.isBrev)
  629. {
  630. for(i=0;i<=0x20;i++)
  631. {
  632. eeprom[i] = a3c90x_internal_ReadEeprom(INF_3C90X.IOAddr, i);
  633. }
  634. #ifdef CFG_3C90X_BOOTROM_FIX
  635. /** Set xcvrSelect in InternalConfig in eeprom. **/
  636. /* only necessary for 3c905b revision cards with boot PROM bug!!! */
  637. a3c90x_internal_WriteEeprom(INF_3C90X.IOAddr, 0x13, 0x0160);
  638. #endif
  639. #ifdef CFG_3C90X_XCVR
  640. if (CFG_3C90X_XCVR == 255)
  641. {
  642. /** Clear the LanWorks register **/
  643. a3c90x_internal_WriteEeprom(INF_3C90X.IOAddr, 0x16, 0);
  644. }
  645. else
  646. {
  647. /** Set the selected permanent-xcvrSelect in the
  648. ** LanWorks register
  649. **/
  650. a3c90x_internal_WriteEeprom(INF_3C90X.IOAddr, 0x16,
  651. XCVR_MAGIC + ((CFG_3C90X_XCVR) & 0x000F));
  652. }
  653. #endif
  654. }
  655. else
  656. {
  657. for(i=0;i<=0x17;i++)
  658. {
  659. eeprom[i] = a3c90x_internal_ReadEeprom(INF_3C90X.IOAddr, i);
  660. }
  661. }
  662. /** Print identification message **/
  663. printf("\n\n3C90X Driver 2.00 "
  664. "Copyright 1999 LightSys Technology Services, Inc.\n"
  665. "Portions Copyright 1999 Steve Smith\n");
  666. printf("Provided with ABSOLUTELY NO WARRANTY.\n");
  667. #ifdef CFG_3C90X_BOOTROM_FIX
  668. if (INF_3C90X.isBrev)
  669. {
  670. printf("NOTE: 3c905b bootrom fix enabled; has side "
  671. "effects. See 3c90x.txt for info.\n");
  672. }
  673. #endif
  674. printf("-------------------------------------------------------"
  675. "------------------------\n");
  676. /** Retrieve the Hardware address and print it on the screen. **/
  677. INF_3C90X.HWAddr[0] = eeprom[HWADDR_OFFSET + 0]>>8;
  678. INF_3C90X.HWAddr[1] = eeprom[HWADDR_OFFSET + 0]&0xFF;
  679. INF_3C90X.HWAddr[2] = eeprom[HWADDR_OFFSET + 1]>>8;
  680. INF_3C90X.HWAddr[3] = eeprom[HWADDR_OFFSET + 1]&0xFF;
  681. INF_3C90X.HWAddr[4] = eeprom[HWADDR_OFFSET + 2]>>8;
  682. INF_3C90X.HWAddr[5] = eeprom[HWADDR_OFFSET + 2]&0xFF;
  683. printf("MAC Address = %!\n", INF_3C90X.HWAddr);
  684. /* Test if the link is good, if not continue */
  685. a3c90x_internal_SetWindow(INF_3C90X.IOAddr, winDiagnostics4);
  686. mstat = inw(INF_3C90X.IOAddr + regMediaStatus_4_w);
  687. if((mstat & (1<<11)) == 0) {
  688. printf("Valid link not established\n");
  689. return 0;
  690. }
  691. /** Program the MAC address into the station address registers **/
  692. a3c90x_internal_SetWindow(INF_3C90X.IOAddr, winAddressing2);
  693. outw(htons(eeprom[HWADDR_OFFSET + 0]), INF_3C90X.IOAddr + regStationAddress_2_3w);
  694. outw(htons(eeprom[HWADDR_OFFSET + 1]), INF_3C90X.IOAddr + regStationAddress_2_3w+2);
  695. outw(htons(eeprom[HWADDR_OFFSET + 2]), INF_3C90X.IOAddr + regStationAddress_2_3w+4);
  696. outw(0, INF_3C90X.IOAddr + regStationMask_2_3w+0);
  697. outw(0, INF_3C90X.IOAddr + regStationMask_2_3w+2);
  698. outw(0, INF_3C90X.IOAddr + regStationMask_2_3w+4);
  699. /** Fill in our entry in the etherboot arp table **/
  700. for(i=0;i<ETH_ALEN;i++)
  701. nic->node_addr[i] = (eeprom[HWADDR_OFFSET + i/2] >> (8*((i&1)^1))) & 0xff;
  702. /** Read the media options register, print a message and set default
  703. ** xcvr.
  704. **
  705. ** Uses Media Option command on B revision, Reset Option on non-B
  706. ** revision cards -- same register address
  707. **/
  708. a3c90x_internal_SetWindow(INF_3C90X.IOAddr, winTxRxOptions3);
  709. mopt = inw(INF_3C90X.IOAddr + regResetMediaOptions_3_w);
  710. /** mask out VCO bit that is defined as 10baseFL bit on B-rev cards **/
  711. if (! INF_3C90X.isBrev)
  712. {
  713. mopt &= 0x7F;
  714. }
  715. printf("Connectors present: ");
  716. c = 0;
  717. linktype = 0x0008;
  718. if (mopt & 0x01)
  719. {
  720. printf("%s100Base-T4",(c++)?", ":"");
  721. linktype = 0x0006;
  722. }
  723. if (mopt & 0x04)
  724. {
  725. printf("%s100Base-FX",(c++)?", ":"");
  726. linktype = 0x0005;
  727. }
  728. if (mopt & 0x10)
  729. {
  730. printf("%s10Base-2",(c++)?", ":"");
  731. linktype = 0x0003;
  732. }
  733. if (mopt & 0x20)
  734. {
  735. printf("%sAUI",(c++)?", ":"");
  736. linktype = 0x0001;
  737. }
  738. if (mopt & 0x40)
  739. {
  740. printf("%sMII",(c++)?", ":"");
  741. linktype = 0x0006;
  742. }
  743. if ((mopt & 0xA) == 0xA)
  744. {
  745. printf("%s10Base-T / 100Base-TX",(c++)?", ":"");
  746. linktype = 0x0008;
  747. }
  748. else if ((mopt & 0xA) == 0x2)
  749. {
  750. printf("%s100Base-TX",(c++)?", ":"");
  751. linktype = 0x0008;
  752. }
  753. else if ((mopt & 0xA) == 0x8)
  754. {
  755. printf("%s10Base-T",(c++)?", ":"");
  756. linktype = 0x0008;
  757. }
  758. printf(".\n");
  759. /** Determine transceiver type to use, depending on value stored in
  760. ** eeprom 0x16
  761. **/
  762. if (INF_3C90X.isBrev)
  763. {
  764. if ((eeprom[0x16] & 0xFF00) == XCVR_MAGIC)
  765. {
  766. /** User-defined **/
  767. linktype = eeprom[0x16] & 0x000F;
  768. }
  769. }
  770. else
  771. {
  772. #ifdef CFG_3C90X_XCVR
  773. if (CFG_3C90X_XCVR != 255)
  774. linktype = CFG_3C90X_XCVR;
  775. #endif /* CFG_3C90X_XCVR */
  776. /** I don't know what MII MAC only mode is!!! **/
  777. if (linktype == 0x0009)
  778. {
  779. if (INF_3C90X.isBrev)
  780. printf("WARNING: MII External MAC Mode only supported on B-revision "
  781. "cards!!!!\nFalling Back to MII Mode\n");
  782. linktype = 0x0006;
  783. }
  784. }
  785. /** enable DC converter for 10-Base-T **/
  786. if (linktype == 0x0003)
  787. {
  788. a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdEnableDcConverter, 0);
  789. }
  790. /** Set the link to the type we just determined. **/
  791. a3c90x_internal_SetWindow(INF_3C90X.IOAddr, winTxRxOptions3);
  792. cfg = inl(INF_3C90X.IOAddr + regInternalConfig_3_l);
  793. cfg &= ~(0xF<<20);
  794. cfg |= (linktype<<20);
  795. outl(cfg, INF_3C90X.IOAddr + regInternalConfig_3_l);
  796. /** Now that we set the xcvr type, reset the Tx and Rx, re-enable. **/
  797. a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdTxReset, 0x00);
  798. while (inw(INF_3C90X.IOAddr + regCommandIntStatus_w) & INT_CMDINPROGRESS)
  799. ;
  800. if (!INF_3C90X.isBrev)
  801. outb(0x01, INF_3C90X.IOAddr + regTxFreeThresh_b);
  802. a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdTxEnable, 0);
  803. /**
  804. ** reset of the receiver on B-revision cards re-negotiates the link
  805. ** takes several seconds (a computer eternity)
  806. **/
  807. if (INF_3C90X.isBrev)
  808. a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdRxReset, 0x04);
  809. else
  810. a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdRxReset, 0x00);
  811. while (inw(INF_3C90X.IOAddr + regCommandIntStatus_w) & INT_CMDINPROGRESS)
  812. ;
  813. /** Set the RX filter = receive only individual pkts & multicast & bcast. **/
  814. a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdSetRxFilter, 0x01 + 0x02 + 0x04);
  815. a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdRxEnable, 0);
  816. /**
  817. ** set Indication and Interrupt flags , acknowledge any IRQ's
  818. **/
  819. a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdSetInterruptEnable, 0);
  820. a3c90x_internal_IssueCommand(INF_3C90X.IOAddr,
  821. cmdSetIndicationEnable, 0x0014);
  822. a3c90x_internal_IssueCommand(INF_3C90X.IOAddr,
  823. cmdAcknowledgeInterrupt, 0x661);
  824. /** Set our exported functions **/
  825. dev->disable = a3c90x_disable;
  826. nic->poll = a3c90x_poll;
  827. nic->transmit = a3c90x_transmit;
  828. nic->irq = a3c90x_irq;
  829. return 1;
  830. }
  831. static struct pci_id a3c90x_nics[] = {
  832. /* Original 90x revisions: */
  833. PCI_ROM(0x10b7, 0x9000, "3c905-tpo", "3Com900-TPO"), /* 10 Base TPO */
  834. PCI_ROM(0x10b7, 0x9001, "3c905-t4", "3Com900-Combo"), /* 10/100 T4 */
  835. PCI_ROM(0x10b7, 0x9050, "3c905-tpo100", "3Com905-TX"), /* 100 Base TX / 10/100 TPO */
  836. PCI_ROM(0x10b7, 0x9051, "3c905-combo", "3Com905-T4"), /* 100 Base T4 / 10 Base Combo */
  837. /* Newer 90xB revisions: */
  838. PCI_ROM(0x10b7, 0x9004, "3c905b-tpo", "3Com900B-TPO"), /* 10 Base TPO */
  839. PCI_ROM(0x10b7, 0x9005, "3c905b-combo", "3Com900B-Combo"), /* 10 Base Combo */
  840. PCI_ROM(0x10b7, 0x9006, "3c905b-tpb2", "3Com900B-2/T"), /* 10 Base TP and Base2 */
  841. PCI_ROM(0x10b7, 0x900a, "3c905b-fl", "3Com900B-FL"), /* 10 Base FL */
  842. PCI_ROM(0x10b7, 0x9055, "3c905b-tpo100", "3Com905B-TX"), /* 10/100 TPO */
  843. PCI_ROM(0x10b7, 0x9056, "3c905b-t4", "3Com905B-T4"), /* 10/100 T4 */
  844. PCI_ROM(0x10b7, 0x9058, "3c905b-9058", "3Com905B-9058"), /* Cyclone 10/100/BNC */
  845. PCI_ROM(0x10b7, 0x905a, "3c905b-fx", "3Com905B-FL"), /* 100 Base FX / 10 Base FX */
  846. /* Newer 90xC revision: */
  847. PCI_ROM(0x10b7, 0x9200, "3c905c-tpo", "3Com905C-TXM"), /* 10/100 TPO (3C905C-TXM) */
  848. PCI_ROM(0x10b7, 0x9202, "3c920b-emb-ati", "3c920B-EMB-WNM (ATI Radeon 9100 IGP)"), /* 3c920B-EMB-WNM (ATI Radeon 9100 IGP) */
  849. PCI_ROM(0x10b7, 0x9210, "3c920b-emb-wnm","3Com20B-EMB WNM"),
  850. PCI_ROM(0x10b7, 0x9800, "3c980", "3Com980-Cyclone"), /* Cyclone */
  851. PCI_ROM(0x10b7, 0x9805, "3c9805", "3Com9805"), /* Dual Port Server Cyclone */
  852. PCI_ROM(0x10b7, 0x7646, "3csoho100-tx", "3CSOHO100-TX"), /* Hurricane */
  853. PCI_ROM(0x10b7, 0x4500, "3c450", "3Com450 HomePNA Tornado"),
  854. PCI_ROM(0x10b7, 0x1201, "3c982a", "3Com982A"),
  855. PCI_ROM(0x10b7, 0x1202, "3c982b", "3Com982B"),
  856. };
  857. static struct pci_driver a3c90x_driver =
  858. PCI_DRIVER ( "3C90X", a3c90x_nics, PCI_NO_CLASS );
  859. BOOT_DRIVER ( "3C90X", a3c90x_probe );