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.

smc9000.c 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  1. #ifdef ALLMULTI
  2. #error multicast support is not yet implemented
  3. #endif
  4. /*------------------------------------------------------------------------
  5. * smc9000.c
  6. * This is a Etherboot driver for SMC's 9000 series of Ethernet cards.
  7. *
  8. * Copyright (C) 1998 Daniel Engström <daniel.engstrom@riksnett.no>
  9. * Based on the Linux SMC9000 driver, smc9194.c by Eric Stahlman
  10. * Copyright (C) 1996 by Erik Stahlman <eric@vt.edu>
  11. *
  12. * This software may be used and distributed according to the terms
  13. * of the GNU Public License, incorporated herein by reference.
  14. *
  15. * "Features" of the SMC chip:
  16. * 4608 byte packet memory. ( for the 91C92/4. Others have more )
  17. * EEPROM for configuration
  18. * AUI/TP selection
  19. *
  20. * Authors
  21. * Erik Stahlman <erik@vt.edu>
  22. * Daniel Engström <daniel.engstrom@riksnett.no>
  23. *
  24. * History
  25. * 98-09-25 Daniel Engström Etherboot driver crated from Eric's
  26. * Linux driver.
  27. *
  28. *---------------------------------------------------------------------------*/
  29. #define LINUX_OUT_MACROS 1
  30. #define SMC9000_DEBUG 0
  31. #include "etherboot.h"
  32. #include "nic.h"
  33. #include "isa.h"
  34. #include "smc9000.h"
  35. # define _outb outb
  36. # define _outw outw
  37. static const char smc9000_version[] = "Version 0.99 98-09-30";
  38. static const char *interfaces[ 2 ] = { "TP", "AUI" };
  39. static const char *chip_ids[ 15 ] = {
  40. NULL, NULL, NULL,
  41. /* 3 */ "SMC91C90/91C92",
  42. /* 4 */ "SMC91C94",
  43. /* 5 */ "SMC91C95",
  44. NULL,
  45. /* 7 */ "SMC91C100",
  46. /* 8 */ "SMC91C100FD",
  47. NULL, NULL, NULL,
  48. NULL, NULL, NULL
  49. };
  50. static const char smc91c96_id[] = "SMC91C96";
  51. /*
  52. * Function: smc_reset( int ioaddr )
  53. * Purpose:
  54. * This sets the SMC91xx chip to its normal state, hopefully from whatever
  55. * mess that any other DOS driver has put it in.
  56. *
  57. * Maybe I should reset more registers to defaults in here? SOFTRESET should
  58. * do that for me.
  59. *
  60. * Method:
  61. * 1. send a SOFT RESET
  62. * 2. wait for it to finish
  63. * 3. reset the memory management unit
  64. * 4. clear all interrupts
  65. *
  66. */
  67. static void smc_reset(int ioaddr)
  68. {
  69. /* This resets the registers mostly to defaults, but doesn't
  70. * affect EEPROM. That seems unnecessary */
  71. SMC_SELECT_BANK(ioaddr, 0);
  72. _outw( RCR_SOFTRESET, ioaddr + RCR );
  73. /* this should pause enough for the chip to be happy */
  74. SMC_DELAY(ioaddr);
  75. /* Set the transmit and receive configuration registers to
  76. * default values */
  77. _outw(RCR_CLEAR, ioaddr + RCR);
  78. _outw(TCR_CLEAR, ioaddr + TCR);
  79. /* Reset the MMU */
  80. SMC_SELECT_BANK(ioaddr, 2);
  81. _outw( MC_RESET, ioaddr + MMU_CMD );
  82. /* Note: It doesn't seem that waiting for the MMU busy is needed here,
  83. * but this is a place where future chipsets _COULD_ break. Be wary
  84. * of issuing another MMU command right after this */
  85. _outb(0, ioaddr + INT_MASK);
  86. }
  87. /*----------------------------------------------------------------------
  88. * Function: smc9000_probe_addr( int ioaddr )
  89. *
  90. * Purpose:
  91. * Tests to see if a given ioaddr points to an SMC9xxx chip.
  92. * Returns a 1 on success
  93. *
  94. * Algorithm:
  95. * (1) see if the high byte of BANK_SELECT is 0x33
  96. * (2) compare the ioaddr with the base register's address
  97. * (3) see if I recognize the chip ID in the appropriate register
  98. *
  99. * ---------------------------------------------------------------------
  100. */
  101. static int smc9000_probe_addr( unsigned short ioaddr )
  102. {
  103. word bank;
  104. word revision_register;
  105. word base_address_register;
  106. /* First, see if the high byte is 0x33 */
  107. bank = inw(ioaddr + BANK_SELECT);
  108. if ((bank & 0xFF00) != 0x3300) {
  109. return 0;
  110. }
  111. /* The above MIGHT indicate a device, but I need to write to further
  112. * test this. */
  113. _outw(0x0, ioaddr + BANK_SELECT);
  114. bank = inw(ioaddr + BANK_SELECT);
  115. if ((bank & 0xFF00) != 0x3300) {
  116. return 0;
  117. }
  118. /* well, we've already written once, so hopefully another time won't
  119. * hurt. This time, I need to switch the bank register to bank 1,
  120. * so I can access the base address register */
  121. SMC_SELECT_BANK(ioaddr, 1);
  122. base_address_register = inw(ioaddr + BASE);
  123. if (ioaddr != (base_address_register >> 3 & 0x3E0)) {
  124. DBG("SMC9000: IOADDR %hX doesn't match configuration (%hX)."
  125. "Probably not a SMC chip\n",
  126. ioaddr, base_address_register >> 3 & 0x3E0);
  127. /* well, the base address register didn't match. Must not have
  128. * been a SMC chip after all. */
  129. return 0;
  130. }
  131. /* check if the revision register is something that I recognize.
  132. * These might need to be added to later, as future revisions
  133. * could be added. */
  134. SMC_SELECT_BANK(ioaddr, 3);
  135. revision_register = inw(ioaddr + REVISION);
  136. if (!chip_ids[(revision_register >> 4) & 0xF]) {
  137. /* I don't recognize this chip, so... */
  138. DBG( "SMC9000: IO %hX: Unrecognized revision register:"
  139. " %hX, Contact author.\n", ioaddr, revision_register );
  140. return 0;
  141. }
  142. /* at this point I'll assume that the chip is an SMC9xxx.
  143. * It might be prudent to check a listing of MAC addresses
  144. * against the hardware address, or do some other tests. */
  145. return 1;
  146. }
  147. /**************************************************************************
  148. * ETH_TRANSMIT - Transmit a frame
  149. ***************************************************************************/
  150. static void smc9000_transmit(
  151. struct nic *nic,
  152. const char *d, /* Destination */
  153. unsigned int t, /* Type */
  154. unsigned int s, /* size */
  155. const char *p) /* Packet */
  156. {
  157. word length; /* real, length incl. header */
  158. word numPages;
  159. unsigned long time_out;
  160. byte packet_no;
  161. word status;
  162. int i;
  163. /* We dont pad here since we can have the hardware doing it for us */
  164. length = (s + ETH_HLEN + 1)&~1;
  165. /* convert to MMU pages */
  166. numPages = length / 256;
  167. if (numPages > 7 ) {
  168. DBG("SMC9000: Far too big packet error. \n");
  169. return;
  170. }
  171. /* dont try more than, say 30 times */
  172. for (i=0;i<30;i++) {
  173. /* now, try to allocate the memory */
  174. SMC_SELECT_BANK(nic->ioaddr, 2);
  175. _outw(MC_ALLOC | numPages, nic->ioaddr + MMU_CMD);
  176. status = 0;
  177. /* wait for the memory allocation to finnish */
  178. for (time_out = currticks() + 5*TICKS_PER_SEC; currticks() < time_out; ) {
  179. status = inb(nic->ioaddr + INTERRUPT);
  180. if ( status & IM_ALLOC_INT ) {
  181. /* acknowledge the interrupt */
  182. _outb(IM_ALLOC_INT, nic->ioaddr + INTERRUPT);
  183. break;
  184. }
  185. }
  186. if ((status & IM_ALLOC_INT) != 0 ) {
  187. /* We've got the memory */
  188. break;
  189. } else {
  190. printf("SMC9000: Memory allocation timed out, resetting MMU.\n");
  191. _outw(MC_RESET, nic->ioaddr + MMU_CMD);
  192. }
  193. }
  194. /* If I get here, I _know_ there is a packet slot waiting for me */
  195. packet_no = inb(nic->ioaddr + PNR_ARR + 1);
  196. if (packet_no & 0x80) {
  197. /* or isn't there? BAD CHIP! */
  198. printf("SMC9000: Memory allocation failed. \n");
  199. return;
  200. }
  201. /* we have a packet address, so tell the card to use it */
  202. _outb(packet_no, nic->ioaddr + PNR_ARR);
  203. /* point to the beginning of the packet */
  204. _outw(PTR_AUTOINC, nic->ioaddr + POINTER);
  205. #if SMC9000_DEBUG > 2
  206. printf("Trying to xmit packet of length %hX\n", length );
  207. #endif
  208. /* send the packet length ( +6 for status, length and ctl byte )
  209. * and the status word ( set to zeros ) */
  210. _outw(0, nic->ioaddr + DATA_1 );
  211. /* send the packet length ( +6 for status words, length, and ctl) */
  212. _outb((length+6) & 0xFF, nic->ioaddr + DATA_1);
  213. _outb((length+6) >> 8 , nic->ioaddr + DATA_1);
  214. /* Write the contents of the packet */
  215. /* The ethernet header first... */
  216. outsw(nic->ioaddr + DATA_1, d, ETH_ALEN >> 1);
  217. outsw(nic->ioaddr + DATA_1, nic->node_addr, ETH_ALEN >> 1);
  218. _outw(htons(t), nic->ioaddr + DATA_1);
  219. /* ... the data ... */
  220. outsw(nic->ioaddr + DATA_1 , p, s >> 1);
  221. /* ... and the last byte, if there is one. */
  222. if ((s & 1) == 0) {
  223. _outw(0, nic->ioaddr + DATA_1);
  224. } else {
  225. _outb(p[s-1], nic->ioaddr + DATA_1);
  226. _outb(0x20, nic->ioaddr + DATA_1);
  227. }
  228. /* and let the chipset deal with it */
  229. _outw(MC_ENQUEUE , nic->ioaddr + MMU_CMD);
  230. status = 0; time_out = currticks() + 5*TICKS_PER_SEC;
  231. do {
  232. status = inb(nic->ioaddr + INTERRUPT);
  233. if ((status & IM_TX_INT ) != 0) {
  234. word tx_status;
  235. /* ack interrupt */
  236. _outb(IM_TX_INT, nic->ioaddr + INTERRUPT);
  237. packet_no = inw(nic->ioaddr + FIFO_PORTS);
  238. packet_no &= 0x7F;
  239. /* select this as the packet to read from */
  240. _outb( packet_no, nic->ioaddr + PNR_ARR );
  241. /* read the first word from this packet */
  242. _outw( PTR_AUTOINC | PTR_READ, nic->ioaddr + POINTER );
  243. tx_status = inw( nic->ioaddr + DATA_1 );
  244. if (0 == (tx_status & TS_SUCCESS)) {
  245. DBG("SMC9000: TX FAIL STATUS: %hX \n", tx_status);
  246. /* re-enable transmit */
  247. SMC_SELECT_BANK(nic->ioaddr, 0);
  248. _outw(inw(nic->ioaddr + TCR ) | TCR_ENABLE, nic->ioaddr + TCR );
  249. }
  250. /* kill the packet */
  251. SMC_SELECT_BANK(nic->ioaddr, 2);
  252. _outw(MC_FREEPKT, nic->ioaddr + MMU_CMD);
  253. return;
  254. }
  255. }while(currticks() < time_out);
  256. printf("SMC9000: TX timed out, resetting board\n");
  257. smc_reset(nic->ioaddr);
  258. return;
  259. }
  260. /**************************************************************************
  261. * ETH_POLL - Wait for a frame
  262. ***************************************************************************/
  263. static int smc9000_poll(struct nic *nic, int retrieve)
  264. {
  265. SMC_SELECT_BANK(nic->ioaddr, 2);
  266. if (inw(nic->ioaddr + FIFO_PORTS) & FP_RXEMPTY)
  267. return 0;
  268. if ( ! retrieve ) return 1;
  269. /* start reading from the start of the packet */
  270. _outw(PTR_READ | PTR_RCV | PTR_AUTOINC, nic->ioaddr + POINTER);
  271. /* First read the status and check that we're ok */
  272. if (!(inw(nic->ioaddr + DATA_1) & RS_ERRORS)) {
  273. /* Next: read the packet length and mask off the top bits */
  274. nic->packetlen = (inw(nic->ioaddr + DATA_1) & 0x07ff);
  275. /* the packet length includes the 3 extra words */
  276. nic->packetlen -= 6;
  277. #if SMC9000_DEBUG > 2
  278. printf(" Reading %d words (and %d byte(s))\n",
  279. (nic->packetlen >> 1), nic->packetlen & 1);
  280. #endif
  281. /* read the packet (and the last "extra" word) */
  282. insw(nic->ioaddr + DATA_1, nic->packet, (nic->packetlen+2) >> 1);
  283. /* is there an odd last byte ? */
  284. if (nic->packet[nic->packetlen+1] & 0x20)
  285. nic->packetlen++;
  286. /* error or good, tell the card to get rid of this packet */
  287. _outw(MC_RELEASE, nic->ioaddr + MMU_CMD);
  288. return 1;
  289. }
  290. printf("SMC9000: RX error\n");
  291. /* error or good, tell the card to get rid of this packet */
  292. _outw(MC_RELEASE, nic->ioaddr + MMU_CMD);
  293. return 0;
  294. }
  295. static void smc9000_disable ( struct nic *nic ) {
  296. smc_reset(nic->ioaddr);
  297. /* no more interrupts for me */
  298. SMC_SELECT_BANK(nic->ioaddr, 2);
  299. _outb( 0, nic->ioaddr + INT_MASK);
  300. /* and tell the card to stay away from that nasty outside world */
  301. SMC_SELECT_BANK(nic->ioaddr, 0);
  302. _outb( RCR_CLEAR, nic->ioaddr + RCR );
  303. _outb( TCR_CLEAR, nic->ioaddr + TCR );
  304. }
  305. static void smc9000_irq(struct nic *nic __unused, irq_action_t action __unused)
  306. {
  307. switch ( action ) {
  308. case DISABLE :
  309. break;
  310. case ENABLE :
  311. break;
  312. case FORCE :
  313. break;
  314. }
  315. }
  316. static struct nic_operations smc9000_operations = {
  317. .connect = dummy_connect,
  318. .poll = smc9000_poll,
  319. .transmit = smc9000_transmit,
  320. .irq = smc9000_irq,
  321. .disable = smc9000_disable,
  322. };
  323. /**************************************************************************
  324. * ETH_PROBE - Look for an adapter
  325. ***************************************************************************/
  326. static int smc9000_probe ( struct dev *dev, struct isa_device *isa ) {
  327. struct nic *nic = nic_device ( dev );
  328. unsigned short revision;
  329. int memory;
  330. int media;
  331. const char * version_string;
  332. const char * if_string;
  333. int i;
  334. nic->irqno = 0;
  335. nic->ioaddr = isa->ioaddr;
  336. /*
  337. * Get the MAC address ( bank 1, regs 4 - 9 )
  338. */
  339. SMC_SELECT_BANK(nic->ioaddr, 1);
  340. for ( i = 0; i < 6; i += 2 ) {
  341. word address;
  342. address = inw(nic->ioaddr + ADDR0 + i);
  343. nic->node_addr[i+1] = address >> 8;
  344. nic->node_addr[i] = address & 0xFF;
  345. }
  346. /* get the memory information */
  347. SMC_SELECT_BANK(nic->ioaddr, 0);
  348. memory = ( inw(nic->ioaddr + MCR) >> 9 ) & 0x7; /* multiplier */
  349. memory *= 256 * (inw(nic->ioaddr + MIR) & 0xFF);
  350. /*
  351. * Now, I want to find out more about the chip. This is sort of
  352. * redundant, but it's cleaner to have it in both, rather than having
  353. * one VERY long probe procedure.
  354. */
  355. SMC_SELECT_BANK(nic->ioaddr, 3);
  356. revision = inw(nic->ioaddr + REVISION);
  357. version_string = chip_ids[(revision >> 4) & 0xF];
  358. if (((revision & 0xF0) >> 4 == CHIP_9196) &&
  359. ((revision & 0x0F) >= REV_9196)) {
  360. /* This is a 91c96. 'c96 has the same chip id as 'c94 (4) but
  361. * a revision starting at 6 */
  362. version_string = smc91c96_id;
  363. }
  364. if ( !version_string ) {
  365. /* I shouldn't get here because this call was done before.... */
  366. return 0;
  367. }
  368. /* is it using AUI or 10BaseT ? */
  369. SMC_SELECT_BANK(nic->ioaddr, 1);
  370. if (inw(nic->ioaddr + CONFIG) & CFG_AUI_SELECT)
  371. media = 2;
  372. else
  373. media = 1;
  374. if_string = interfaces[media - 1];
  375. /* now, reset the chip, and put it into a known state */
  376. smc_reset(nic->ioaddr);
  377. printf("SMC9000 %s\n", smc9000_version);
  378. DBG("Copyright (C) 1998 Daniel Engstr\x94m\n");
  379. DBG("Copyright (C) 1996 Eric Stahlman\n");
  380. printf("%s rev:%d I/O port:%hX Interface:%s RAM:%d bytes \n",
  381. version_string, revision & 0xF,
  382. nic->ioaddr, if_string, memory );
  383. /*
  384. * Print the Ethernet address
  385. */
  386. printf("Ethernet MAC address: %!\n", nic->node_addr);
  387. SMC_SELECT_BANK(nic->ioaddr, 0);
  388. /* see the header file for options in TCR/RCR NORMAL*/
  389. _outw(TCR_NORMAL, nic->ioaddr + TCR);
  390. _outw(RCR_NORMAL, nic->ioaddr + RCR);
  391. /* Select which interface to use */
  392. SMC_SELECT_BANK(nic->ioaddr, 1);
  393. if ( media == 1 ) {
  394. _outw( inw( nic->ioaddr + CONFIG ) & ~CFG_AUI_SELECT,
  395. nic->ioaddr + CONFIG );
  396. }
  397. else if ( media == 2 ) {
  398. _outw( inw( nic->ioaddr + CONFIG ) | CFG_AUI_SELECT,
  399. nic->ioaddr + CONFIG );
  400. }
  401. nic->nic_op = &smc9000_operations;
  402. return 1;
  403. }
  404. /*
  405. * The SMC9000 can be at any of the following port addresses. To
  406. * change for a slightly different card, you can add it to the array.
  407. *
  408. */
  409. static struct isa_probe_addr smc9000_probe_addrs[] = {
  410. { 0x200 }, { 0x220 }, { 0x240 }, { 0x260 },
  411. { 0x280 }, { 0x2A0 }, { 0x2C0 }, { 0x2E0 },
  412. { 0x300 }, { 0x320 }, { 0x340 }, { 0x360 },
  413. { 0x380 }, { 0x3A0 }, { 0x3C0 }, { 0x3E0 },
  414. };
  415. static struct isa_driver smc9000_driver =
  416. ISA_DRIVER ( "SMC9000", smc9000_probe_addrs, smc9000_probe_addr,
  417. GENERIC_ISAPNP_VENDOR, 0x8228 );
  418. BOOT_DRIVER ( "SMC9000", find_isa_boot_device, smc9000_driver, smc9000_probe );
  419. ISA_ROM ( "smc9000", "SMC9000" );
  420. /*
  421. * Local variables:
  422. * c-basic-offset: 3
  423. * End:
  424. */