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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027
  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. static struct nic_operations a3c90x_operations;
  46. #define XCVR_MAGIC (0x5A00)
  47. /** any single transmission fails after 16 collisions or other errors
  48. ** this is the number of times to retry the transmission -- this should
  49. ** be plenty
  50. **/
  51. #define XMIT_RETRIES 250
  52. /*** Register definitions for the 3c905 ***/
  53. enum Registers
  54. {
  55. regPowerMgmtCtrl_w = 0x7c, /** 905B Revision Only **/
  56. regUpMaxBurst_w = 0x7a, /** 905B Revision Only **/
  57. regDnMaxBurst_w = 0x78, /** 905B Revision Only **/
  58. regDebugControl_w = 0x74, /** 905B Revision Only **/
  59. regDebugData_l = 0x70, /** 905B Revision Only **/
  60. regRealTimeCnt_l = 0x40, /** Universal **/
  61. regUpBurstThresh_b = 0x3e, /** 905B Revision Only **/
  62. regUpPoll_b = 0x3d, /** 905B Revision Only **/
  63. regUpPriorityThresh_b = 0x3c, /** 905B Revision Only **/
  64. regUpListPtr_l = 0x38, /** Universal **/
  65. regCountdown_w = 0x36, /** Universal **/
  66. regFreeTimer_w = 0x34, /** Universal **/
  67. regUpPktStatus_l = 0x30, /** Universal with Exception, pg 130 **/
  68. regTxFreeThresh_b = 0x2f, /** 90X Revision Only **/
  69. regDnPoll_b = 0x2d, /** 905B Revision Only **/
  70. regDnPriorityThresh_b = 0x2c, /** 905B Revision Only **/
  71. regDnBurstThresh_b = 0x2a, /** 905B Revision Only **/
  72. regDnListPtr_l = 0x24, /** Universal with Exception, pg 107 **/
  73. regDmaCtrl_l = 0x20, /** Universal with Exception, pg 106 **/
  74. /** **/
  75. regIntStatusAuto_w = 0x1e, /** 905B Revision Only **/
  76. regTxStatus_b = 0x1b, /** Universal with Exception, pg 113 **/
  77. regTimer_b = 0x1a, /** Universal **/
  78. regTxPktId_b = 0x18, /** 905B Revision Only **/
  79. regCommandIntStatus_w = 0x0e, /** Universal (Command Variations) **/
  80. };
  81. /** following are windowed registers **/
  82. enum Registers7
  83. {
  84. regPowerMgmtEvent_7_w = 0x0c, /** 905B Revision Only **/
  85. regVlanEtherType_7_w = 0x04, /** 905B Revision Only **/
  86. regVlanMask_7_w = 0x00, /** 905B Revision Only **/
  87. };
  88. enum Registers6
  89. {
  90. regBytesXmittedOk_6_w = 0x0c, /** Universal **/
  91. regBytesRcvdOk_6_w = 0x0a, /** Universal **/
  92. regUpperFramesOk_6_b = 0x09, /** Universal **/
  93. regFramesDeferred_6_b = 0x08, /** Universal **/
  94. regFramesRecdOk_6_b = 0x07, /** Universal with Exceptions, pg 142 **/
  95. regFramesXmittedOk_6_b = 0x06, /** Universal **/
  96. regRxOverruns_6_b = 0x05, /** Universal **/
  97. regLateCollisions_6_b = 0x04, /** Universal **/
  98. regSingleCollisions_6_b = 0x03, /** Universal **/
  99. regMultipleCollisions_6_b = 0x02, /** Universal **/
  100. regSqeErrors_6_b = 0x01, /** Universal **/
  101. regCarrierLost_6_b = 0x00, /** Universal **/
  102. };
  103. enum Registers5
  104. {
  105. regIndicationEnable_5_w = 0x0c, /** Universal **/
  106. regInterruptEnable_5_w = 0x0a, /** Universal **/
  107. regTxReclaimThresh_5_b = 0x09, /** 905B Revision Only **/
  108. regRxFilter_5_b = 0x08, /** Universal **/
  109. regRxEarlyThresh_5_w = 0x06, /** Universal **/
  110. regTxStartThresh_5_w = 0x00, /** Universal **/
  111. };
  112. enum Registers4
  113. {
  114. regUpperBytesOk_4_b = 0x0d, /** Universal **/
  115. regBadSSD_4_b = 0x0c, /** Universal **/
  116. regMediaStatus_4_w = 0x0a, /** Universal with Exceptions, pg 201 **/
  117. regPhysicalMgmt_4_w = 0x08, /** Universal **/
  118. regNetworkDiagnostic_4_w = 0x06, /** Universal with Exceptions, pg 203 **/
  119. regFifoDiagnostic_4_w = 0x04, /** Universal with Exceptions, pg 196 **/
  120. regVcoDiagnostic_4_w = 0x02, /** Undocumented? **/
  121. };
  122. enum Registers3
  123. {
  124. regTxFree_3_w = 0x0c, /** Universal **/
  125. regRxFree_3_w = 0x0a, /** Universal with Exceptions, pg 125 **/
  126. regResetMediaOptions_3_w = 0x08, /** Media Options on B Revision, **/
  127. /** Reset Options on Non-B Revision **/
  128. regMacControl_3_w = 0x06, /** Universal with Exceptions, pg 199 **/
  129. regMaxPktSize_3_w = 0x04, /** 905B Revision Only **/
  130. regInternalConfig_3_l = 0x00, /** Universal, different bit **/
  131. /** definitions, pg 59 **/
  132. };
  133. enum Registers2
  134. {
  135. regResetOptions_2_w = 0x0c, /** 905B Revision Only **/
  136. regStationMask_2_3w = 0x06, /** Universal with Exceptions, pg 127 **/
  137. regStationAddress_2_3w = 0x00, /** Universal with Exceptions, pg 127 **/
  138. };
  139. enum Registers1
  140. {
  141. regRxStatus_1_w = 0x0a, /** 90X Revision Only, Pg 126 **/
  142. };
  143. enum Registers0
  144. {
  145. regEepromData_0_w = 0x0c, /** Universal **/
  146. regEepromCommand_0_w = 0x0a, /** Universal **/
  147. regBiosRomData_0_b = 0x08, /** 905B Revision Only **/
  148. regBiosRomAddr_0_l = 0x04, /** 905B Revision Only **/
  149. };
  150. /*** The names for the eight register windows ***/
  151. enum Windows
  152. {
  153. winPowerVlan7 = 0x07,
  154. winStatistics6 = 0x06,
  155. winTxRxControl5 = 0x05,
  156. winDiagnostics4 = 0x04,
  157. winTxRxOptions3 = 0x03,
  158. winAddressing2 = 0x02,
  159. winUnused1 = 0x01,
  160. winEepromBios0 = 0x00,
  161. };
  162. /*** Command definitions for the 3c90X ***/
  163. enum Commands
  164. {
  165. cmdGlobalReset = 0x00, /** Universal with Exceptions, pg 151 **/
  166. cmdSelectRegisterWindow = 0x01, /** Universal **/
  167. cmdEnableDcConverter = 0x02, /** **/
  168. cmdRxDisable = 0x03, /** **/
  169. cmdRxEnable = 0x04, /** Universal **/
  170. cmdRxReset = 0x05, /** Universal **/
  171. cmdStallCtl = 0x06, /** Universal **/
  172. cmdTxEnable = 0x09, /** Universal **/
  173. cmdTxDisable = 0x0A, /** **/
  174. cmdTxReset = 0x0B, /** Universal **/
  175. cmdRequestInterrupt = 0x0C, /** **/
  176. cmdAcknowledgeInterrupt = 0x0D, /** Universal **/
  177. cmdSetInterruptEnable = 0x0E, /** Universal **/
  178. cmdSetIndicationEnable = 0x0F, /** Universal **/
  179. cmdSetRxFilter = 0x10, /** Universal **/
  180. cmdSetRxEarlyThresh = 0x11, /** **/
  181. cmdSetTxStartThresh = 0x13, /** **/
  182. cmdStatisticsEnable = 0x15, /** **/
  183. cmdStatisticsDisable = 0x16, /** **/
  184. cmdDisableDcConverter = 0x17, /** **/
  185. cmdSetTxReclaimThresh = 0x18, /** **/
  186. cmdSetHashFilterBit = 0x19, /** **/
  187. };
  188. /*** Values for int status register bitmask **/
  189. #define INT_INTERRUPTLATCH (1<<0)
  190. #define INT_HOSTERROR (1<<1)
  191. #define INT_TXCOMPLETE (1<<2)
  192. #define INT_RXCOMPLETE (1<<4)
  193. #define INT_RXEARLY (1<<5)
  194. #define INT_INTREQUESTED (1<<6)
  195. #define INT_UPDATESTATS (1<<7)
  196. #define INT_LINKEVENT (1<<8)
  197. #define INT_DNCOMPLETE (1<<9)
  198. #define INT_UPCOMPLETE (1<<10)
  199. #define INT_CMDINPROGRESS (1<<12)
  200. #define INT_WINDOWNUMBER (7<<13)
  201. /*** TX descriptor ***/
  202. typedef struct
  203. {
  204. unsigned int DnNextPtr;
  205. unsigned int FrameStartHeader;
  206. unsigned int HdrAddr;
  207. unsigned int HdrLength;
  208. unsigned int DataAddr;
  209. unsigned int DataLength;
  210. }
  211. TXD __attribute__ ((aligned(8))); /* 64-bit aligned for bus mastering */
  212. /*** RX descriptor ***/
  213. typedef struct
  214. {
  215. unsigned int UpNextPtr;
  216. unsigned int UpPktStatus;
  217. unsigned int DataAddr;
  218. unsigned int DataLength;
  219. }
  220. RXD __attribute__ ((aligned(8))); /* 64-bit aligned for bus mastering */
  221. /*** Global variables ***/
  222. static struct
  223. {
  224. unsigned int is3c556;
  225. unsigned char isBrev;
  226. unsigned char CurrentWindow;
  227. unsigned int IOAddr;
  228. unsigned char HWAddr[ETH_ALEN];
  229. TXD TransmitDPD;
  230. RXD ReceiveUPD;
  231. }
  232. INF_3C90X;
  233. /*** a3c90x_internal_IssueCommand: sends a command to the 3c90x card
  234. ***/
  235. static int
  236. a3c90x_internal_IssueCommand(int ioaddr, int cmd, int param)
  237. {
  238. unsigned int val;
  239. /** Build the cmd. **/
  240. val = cmd;
  241. val <<= 11;
  242. val |= param;
  243. /** Send the cmd to the cmd register **/
  244. outw(val, ioaddr + regCommandIntStatus_w);
  245. /** Wait for the cmd to complete, if necessary **/
  246. while (inw(ioaddr + regCommandIntStatus_w) & INT_CMDINPROGRESS);
  247. return 0;
  248. }
  249. /*** a3c90x_internal_SetWindow: selects a register window set.
  250. ***/
  251. static int
  252. a3c90x_internal_SetWindow(int ioaddr, int window)
  253. {
  254. /** Window already as set? **/
  255. if (INF_3C90X.CurrentWindow == window) return 0;
  256. /** Issue the window command. **/
  257. a3c90x_internal_IssueCommand(ioaddr, cmdSelectRegisterWindow, window);
  258. INF_3C90X.CurrentWindow = window;
  259. return 0;
  260. }
  261. /*** a3c90x_internal_ReadEeprom - read data from the serial eeprom.
  262. ***/
  263. static unsigned short
  264. a3c90x_internal_ReadEeprom(int ioaddr, int address)
  265. {
  266. unsigned short val;
  267. /** Select correct window **/
  268. a3c90x_internal_SetWindow(INF_3C90X.IOAddr, winEepromBios0);
  269. /** Make sure the eeprom isn't busy **/
  270. while((1<<15) & inw(ioaddr + regEepromCommand_0_w));
  271. /** Read the value. **/
  272. if (INF_3C90X.is3c556)
  273. {
  274. outw(address + (0x230), ioaddr + regEepromCommand_0_w);
  275. }
  276. else
  277. {
  278. outw(address + ((0x02)<<6), ioaddr + regEepromCommand_0_w);
  279. }
  280. while((1<<15) & inw(ioaddr + regEepromCommand_0_w));
  281. val = inw(ioaddr + regEepromData_0_w);
  282. return val;
  283. }
  284. #if 0
  285. /*** a3c90x_internal_WriteEepromWord - write a physical word of
  286. *** data to the onboard serial eeprom (not the BIOS prom, but the
  287. *** nvram in the card that stores, among other things, the MAC
  288. *** address).
  289. ***/
  290. static int
  291. a3c90x_internal_WriteEepromWord(int ioaddr, int address, unsigned short value)
  292. {
  293. /** Select register window **/
  294. a3c90x_internal_SetWindow(ioaddr, winEepromBios0);
  295. /** Verify Eeprom not busy **/
  296. while((1<<15) & inw(ioaddr + regEepromCommand_0_w));
  297. /** Issue WriteEnable, and wait for completion. **/
  298. outw(0x30, ioaddr + regEepromCommand_0_w);
  299. while((1<<15) & inw(ioaddr + regEepromCommand_0_w));
  300. /** Issue EraseRegister, and wait for completion. **/
  301. outw(address + ((0x03)<<6), ioaddr + regEepromCommand_0_w);
  302. while((1<<15) & inw(ioaddr + regEepromCommand_0_w));
  303. /** Send the new data to the eeprom, and wait for completion. **/
  304. outw(value, ioaddr + regEepromData_0_w);
  305. outw(0x30, ioaddr + regEepromCommand_0_w);
  306. while((1<<15) & inw(ioaddr + regEepromCommand_0_w));
  307. /** Burn the new data into the eeprom, and wait for completion. **/
  308. outw(address + ((0x01)<<6), ioaddr + regEepromCommand_0_w);
  309. while((1<<15) & inw(ioaddr + regEepromCommand_0_w));
  310. return 0;
  311. }
  312. #endif
  313. #if 0
  314. /*** a3c90x_internal_WriteEeprom - write data to the serial eeprom,
  315. *** and re-compute the eeprom checksum.
  316. ***/
  317. static int
  318. a3c90x_internal_WriteEeprom(int ioaddr, int address, unsigned short value)
  319. {
  320. int cksum = 0,v;
  321. int i;
  322. int maxAddress, cksumAddress;
  323. if (INF_3C90X.isBrev)
  324. {
  325. maxAddress=0x1f;
  326. cksumAddress=0x20;
  327. }
  328. else
  329. {
  330. maxAddress=0x16;
  331. cksumAddress=0x17;
  332. }
  333. /** Write the value. **/
  334. if (a3c90x_internal_WriteEepromWord(ioaddr, address, value) == -1)
  335. return -1;
  336. /** Recompute the checksum. **/
  337. for(i=0;i<=maxAddress;i++)
  338. {
  339. v = a3c90x_internal_ReadEeprom(ioaddr, i);
  340. cksum ^= (v & 0xFF);
  341. cksum ^= ((v>>8) & 0xFF);
  342. }
  343. /** Write the checksum to the location in the eeprom **/
  344. if (a3c90x_internal_WriteEepromWord(ioaddr, cksumAddress, cksum) == -1)
  345. return -1;
  346. return 0;
  347. }
  348. #endif
  349. /*** a3c90x_reset: exported function that resets the card to its default
  350. *** state. This is so the Linux driver can re-set the card up the way
  351. *** it wants to. If CFG_3C90X_PRESERVE_XCVR is defined, then the reset will
  352. *** not alter the selected transceiver that we used to download the boot
  353. *** image.
  354. ***/
  355. static void a3c90x_reset(void)
  356. {
  357. #ifdef CFG_3C90X_PRESERVE_XCVR
  358. int cfg;
  359. /** Read the current InternalConfig value. **/
  360. a3c90x_internal_SetWindow(INF_3C90X.IOAddr, winTxRxOptions3);
  361. cfg = inl(INF_3C90X.IOAddr + regInternalConfig_3_l);
  362. #endif
  363. /** Send the reset command to the card **/
  364. printf("Issuing RESET:\n");
  365. a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdGlobalReset, 0);
  366. /** wait for reset command to complete **/
  367. while (inw(INF_3C90X.IOAddr + regCommandIntStatus_w) & INT_CMDINPROGRESS);
  368. /** global reset command resets station mask, non-B revision cards
  369. ** require explicit reset of values
  370. **/
  371. a3c90x_internal_SetWindow(INF_3C90X.IOAddr, winAddressing2);
  372. outw(0, INF_3C90X.IOAddr + regStationMask_2_3w+0);
  373. outw(0, INF_3C90X.IOAddr + regStationMask_2_3w+2);
  374. outw(0, INF_3C90X.IOAddr + regStationMask_2_3w+4);
  375. #ifdef CFG_3C90X_PRESERVE_XCVR
  376. /** Re-set the original InternalConfig value from before reset **/
  377. a3c90x_internal_SetWindow(INF_3C90X.IOAddr, winTxRxOptions3);
  378. outl(cfg, INF_3C90X.IOAddr + regInternalConfig_3_l);
  379. /** enable DC converter for 10-Base-T **/
  380. if ((cfg&0x0300) == 0x0300)
  381. {
  382. a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdEnableDcConverter, 0);
  383. }
  384. #endif
  385. /** Issue transmit reset, wait for command completion **/
  386. a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdTxReset, 0);
  387. while (inw(INF_3C90X.IOAddr + regCommandIntStatus_w) & INT_CMDINPROGRESS)
  388. ;
  389. if (! INF_3C90X.isBrev)
  390. outb(0x01, INF_3C90X.IOAddr + regTxFreeThresh_b);
  391. a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdTxEnable, 0);
  392. /**
  393. ** reset of the receiver on B-revision cards re-negotiates the link
  394. ** takes several seconds (a computer eternity)
  395. **/
  396. if (INF_3C90X.isBrev)
  397. a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdRxReset, 0x04);
  398. else
  399. a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdRxReset, 0x00);
  400. while (inw(INF_3C90X.IOAddr + regCommandIntStatus_w) & INT_CMDINPROGRESS);
  401. ;
  402. a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdRxEnable, 0);
  403. a3c90x_internal_IssueCommand(INF_3C90X.IOAddr,
  404. cmdSetInterruptEnable, 0);
  405. /** enable rxComplete and txComplete **/
  406. a3c90x_internal_IssueCommand(INF_3C90X.IOAddr,
  407. cmdSetIndicationEnable, 0x0014);
  408. /** acknowledge any pending status flags **/
  409. a3c90x_internal_IssueCommand(INF_3C90X.IOAddr,
  410. cmdAcknowledgeInterrupt, 0x661);
  411. return;
  412. }
  413. /*** a3c90x_transmit: exported function that transmits a packet. Does not
  414. *** return any particular status. Parameters are:
  415. *** d[6] - destination address, ethernet;
  416. *** t - protocol type (ARP, IP, etc);
  417. *** s - size of the non-header part of the packet that needs transmitted;
  418. *** p - the pointer to the packet data itself.
  419. ***/
  420. static void
  421. a3c90x_transmit(struct nic *nic __unused, const char *d, unsigned int t,
  422. unsigned int s, const char *p)
  423. {
  424. struct eth_hdr
  425. {
  426. unsigned char dst_addr[ETH_ALEN];
  427. unsigned char src_addr[ETH_ALEN];
  428. unsigned short type;
  429. } hdr;
  430. unsigned char status;
  431. unsigned i, retries;
  432. tick_t ct;
  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. ct = currticks();
  466. while (!(inw(INF_3C90X.IOAddr + regCommandIntStatus_w)&0x0004) &&
  467. ct + 10*USECS_IN_MSEC < currticks());
  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. */