Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

smc9000.c 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  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 nic *nic __unused ) {
  308. if(!smc9000_base)
  309. return;
  310. smc_reset(smc9000_base);
  311. /* no more interrupts for me */
  312. SMC_SELECT_BANK(smc9000_base, 2);
  313. _outb( 0, smc9000_base + INT_MASK);
  314. /* and tell the card to stay away from that nasty outside world */
  315. SMC_SELECT_BANK(smc9000_base, 0);
  316. _outb( RCR_CLEAR, smc9000_base + RCR );
  317. _outb( TCR_CLEAR, smc9000_base + TCR );
  318. }
  319. static void smc9000_irq(struct nic *nic __unused, irq_action_t action __unused)
  320. {
  321. switch ( action ) {
  322. case DISABLE :
  323. break;
  324. case ENABLE :
  325. break;
  326. case FORCE :
  327. break;
  328. }
  329. }
  330. /**************************************************************************
  331. * ETH_PROBE - Look for an adapter
  332. ***************************************************************************/
  333. static int smc9000_probe(struct dev *dev, unsigned short *probe_addrs)
  334. {
  335. struct nic *nic = (struct nic *)dev;
  336. unsigned short revision;
  337. int memory;
  338. int media;
  339. const char * version_string;
  340. const char * if_string;
  341. int i;
  342. /*
  343. * the SMC9000 can be at any of the following port addresses. To change,
  344. * for a slightly different card, you can add it to the array. Keep in
  345. * mind that the array must end in zero.
  346. */
  347. static unsigned short portlist[] = {
  348. #ifdef SMC9000_SCAN
  349. SMC9000_SCAN,
  350. #else
  351. 0x200, 0x220, 0x240, 0x260, 0x280, 0x2A0, 0x2C0, 0x2E0,
  352. 0x300, 0x320, 0x340, 0x360, 0x380, 0x3A0, 0x3C0, 0x3E0,
  353. #endif
  354. 0 };
  355. /* if no addresses supplied, fall back on defaults */
  356. if (probe_addrs == 0 || probe_addrs[0] == 0)
  357. probe_addrs = portlist;
  358. /* check every ethernet address */
  359. for (i = 0; probe_addrs[i]; i++) {
  360. /* check this specific address */
  361. if (smc_probe(probe_addrs[i]) == 0)
  362. smc9000_base = probe_addrs[i];
  363. }
  364. /* couldn't find anything */
  365. if(0 == smc9000_base)
  366. goto out;
  367. nic->irqno = 0;
  368. nic->ioaddr = smc9000_base;
  369. /*
  370. * Get the MAC address ( bank 1, regs 4 - 9 )
  371. */
  372. SMC_SELECT_BANK(smc9000_base, 1);
  373. for ( i = 0; i < 6; i += 2 ) {
  374. word address;
  375. address = inw(smc9000_base + ADDR0 + i);
  376. nic->node_addr[i+1] = address >> 8;
  377. nic->node_addr[i] = address & 0xFF;
  378. }
  379. /* get the memory information */
  380. SMC_SELECT_BANK(smc9000_base, 0);
  381. memory = ( inw(smc9000_base + MCR) >> 9 ) & 0x7; /* multiplier */
  382. memory *= 256 * (inw(smc9000_base + MIR) & 0xFF);
  383. /*
  384. * Now, I want to find out more about the chip. This is sort of
  385. * redundant, but it's cleaner to have it in both, rather than having
  386. * one VERY long probe procedure.
  387. */
  388. SMC_SELECT_BANK(smc9000_base, 3);
  389. revision = inw(smc9000_base + REVISION);
  390. version_string = chip_ids[(revision >> 4) & 0xF];
  391. if (((revision & 0xF0) >> 4 == CHIP_9196) &&
  392. ((revision & 0x0F) >= REV_9196)) {
  393. /* This is a 91c96. 'c96 has the same chip id as 'c94 (4) but
  394. * a revision starting at 6 */
  395. version_string = smc91c96_id;
  396. }
  397. if ( !version_string ) {
  398. /* I shouldn't get here because this call was done before.... */
  399. goto out;
  400. }
  401. /* is it using AUI or 10BaseT ? */
  402. SMC_SELECT_BANK(smc9000_base, 1);
  403. if (inw(smc9000_base + CONFIG) & CFG_AUI_SELECT)
  404. media = 2;
  405. else
  406. media = 1;
  407. if_string = interfaces[media - 1];
  408. /* now, reset the chip, and put it into a known state */
  409. smc_reset(smc9000_base);
  410. printf("SMC9000 %s\n", smc9000_version);
  411. #ifdef SMC9000_VERBOSE
  412. printf("Copyright (C) 1998 Daniel Engstr\x94m\n");
  413. printf("Copyright (C) 1996 Eric Stahlman\n");
  414. #endif
  415. printf("%s rev:%d I/O port:%hX Interface:%s RAM:%d bytes \n",
  416. version_string, revision & 0xF,
  417. smc9000_base, if_string, memory );
  418. /*
  419. * Print the Ethernet address
  420. */
  421. printf("Ethernet MAC address: %!\n", nic->node_addr);
  422. SMC_SELECT_BANK(smc9000_base, 0);
  423. /* see the header file for options in TCR/RCR NORMAL*/
  424. _outw(TCR_NORMAL, smc9000_base + TCR);
  425. _outw(RCR_NORMAL, smc9000_base + RCR);
  426. /* Select which interface to use */
  427. SMC_SELECT_BANK(smc9000_base, 1);
  428. if ( media == 1 ) {
  429. _outw( inw( smc9000_base + CONFIG ) & ~CFG_AUI_SELECT,
  430. smc9000_base + CONFIG );
  431. }
  432. else if ( media == 2 ) {
  433. _outw( inw( smc9000_base + CONFIG ) | CFG_AUI_SELECT,
  434. smc9000_base + CONFIG );
  435. }
  436. static struct nic_operations smc9000_operations;
  437. static struct nic_operations smc9000_operations = {
  438. .connect = dummy_connect,
  439. .poll = smc9000_poll,
  440. .transmit = smc9000_transmit,
  441. .irq = smc9000_irq,
  442. .disable = smc9000_disable,
  443. };
  444. nic->nic_op = &smc9000_operations;
  445. /* Based on PnP ISA map */
  446. dev->devid.vendor_id = htons(GENERIC_ISAPNP_VENDOR);
  447. dev->devid.device_id = htons(0x8228);
  448. return 1;
  449. out:
  450. #ifdef SMC9000_VERBOSE
  451. /* printf("No SMC9000 adapters found\n"); */
  452. #endif
  453. smc9000_base = 0;
  454. return (0);
  455. }
  456. static struct isa_driver smc9000_driver __isa_driver = {
  457. .type = NIC_DRIVER,
  458. .name = "SMC9000",
  459. .probe = smc9000_probe,
  460. .ioaddrs = 0,
  461. };
  462. ISA_ROM("smc9000","SMC9000");