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

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