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 16KB

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