Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

3c90x.c 34KB

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