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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952
  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. FILE_LICENCE ( GPL_ANY );
  30. #define LINUX_OUT_MACROS 1
  31. #define SMC9000_DEBUG 0
  32. #if SMC9000_DEBUG > 1
  33. #define PRINTK2 printf
  34. #else
  35. #define PRINTK2(args...)
  36. #endif
  37. #include <ipxe/ethernet.h>
  38. #include <errno.h>
  39. #include "etherboot.h"
  40. #include "nic.h"
  41. #include <ipxe/isa.h>
  42. #include "smc9000.h"
  43. # define _outb outb
  44. # define _outw outw
  45. static const char smc9000_version[] = "Version 0.99 98-09-30";
  46. static const char *interfaces[ 2 ] = { "TP", "AUI" };
  47. static const char *chip_ids[ 15 ] = {
  48. NULL, NULL, NULL,
  49. /* 3 */ "SMC91C90/91C92",
  50. /* 4 */ "SMC91C94",
  51. /* 5 */ "SMC91C95",
  52. NULL,
  53. /* 7 */ "SMC91C100",
  54. /* 8 */ "SMC91C100FD",
  55. /* 9 */ "SMC91C11xFD",
  56. NULL, NULL,
  57. NULL, NULL, NULL
  58. };
  59. static const char smc91c96_id[] = "SMC91C96";
  60. /*------------------------------------------------------------
  61. . Reads a register from the MII Management serial interface
  62. .-------------------------------------------------------------*/
  63. static word smc_read_phy_register(int ioaddr, byte phyaddr, byte phyreg)
  64. {
  65. int oldBank;
  66. unsigned int i;
  67. byte mask;
  68. word mii_reg;
  69. byte bits[64];
  70. int clk_idx = 0;
  71. int input_idx;
  72. word phydata;
  73. // 32 consecutive ones on MDO to establish sync
  74. for (i = 0; i < 32; ++i)
  75. bits[clk_idx++] = MII_MDOE | MII_MDO;
  76. // Start code <01>
  77. bits[clk_idx++] = MII_MDOE;
  78. bits[clk_idx++] = MII_MDOE | MII_MDO;
  79. // Read command <10>
  80. bits[clk_idx++] = MII_MDOE | MII_MDO;
  81. bits[clk_idx++] = MII_MDOE;
  82. // Output the PHY address, msb first
  83. mask = (byte)0x10;
  84. for (i = 0; i < 5; ++i)
  85. {
  86. if (phyaddr & mask)
  87. bits[clk_idx++] = MII_MDOE | MII_MDO;
  88. else
  89. bits[clk_idx++] = MII_MDOE;
  90. // Shift to next lowest bit
  91. mask >>= 1;
  92. }
  93. // Output the phy register number, msb first
  94. mask = (byte)0x10;
  95. for (i = 0; i < 5; ++i)
  96. {
  97. if (phyreg & mask)
  98. bits[clk_idx++] = MII_MDOE | MII_MDO;
  99. else
  100. bits[clk_idx++] = MII_MDOE;
  101. // Shift to next lowest bit
  102. mask >>= 1;
  103. }
  104. // Tristate and turnaround (2 bit times)
  105. bits[clk_idx++] = 0;
  106. //bits[clk_idx++] = 0;
  107. // Input starts at this bit time
  108. input_idx = clk_idx;
  109. // Will input 16 bits
  110. for (i = 0; i < 16; ++i)
  111. bits[clk_idx++] = 0;
  112. // Final clock bit
  113. bits[clk_idx++] = 0;
  114. // Save the current bank
  115. oldBank = inw( ioaddr+BANK_SELECT );
  116. // Select bank 3
  117. SMC_SELECT_BANK(ioaddr, 3);
  118. // Get the current MII register value
  119. mii_reg = inw( ioaddr+MII_REG );
  120. // Turn off all MII Interface bits
  121. mii_reg &= ~(MII_MDOE|MII_MCLK|MII_MDI|MII_MDO);
  122. // Clock all 64 cycles
  123. for (i = 0; i < sizeof(bits); ++i)
  124. {
  125. // Clock Low - output data
  126. outw( mii_reg | bits[i], ioaddr+MII_REG );
  127. udelay(50);
  128. // Clock Hi - input data
  129. outw( mii_reg | bits[i] | MII_MCLK, ioaddr+MII_REG );
  130. udelay(50);
  131. bits[i] |= inw( ioaddr+MII_REG ) & MII_MDI;
  132. }
  133. // Return to idle state
  134. // Set clock to low, data to low, and output tristated
  135. outw( mii_reg, ioaddr+MII_REG );
  136. udelay(50);
  137. // Restore original bank select
  138. SMC_SELECT_BANK(ioaddr, oldBank);
  139. // Recover input data
  140. phydata = 0;
  141. for (i = 0; i < 16; ++i)
  142. {
  143. phydata <<= 1;
  144. if (bits[input_idx++] & MII_MDI)
  145. phydata |= 0x0001;
  146. }
  147. #if (SMC_DEBUG > 2 )
  148. printf("smc_read_phy_register(): phyaddr=%x,phyreg=%x,phydata=%x\n",
  149. phyaddr, phyreg, phydata);
  150. #endif
  151. return(phydata);
  152. }
  153. /*------------------------------------------------------------
  154. . Writes a register to the MII Management serial interface
  155. .-------------------------------------------------------------*/
  156. static void smc_write_phy_register(int ioaddr,
  157. byte phyaddr, byte phyreg, word phydata)
  158. {
  159. int oldBank;
  160. unsigned int i;
  161. word mask;
  162. word mii_reg;
  163. byte bits[65];
  164. int clk_idx = 0;
  165. // 32 consecutive ones on MDO to establish sync
  166. for (i = 0; i < 32; ++i)
  167. bits[clk_idx++] = MII_MDOE | MII_MDO;
  168. // Start code <01>
  169. bits[clk_idx++] = MII_MDOE;
  170. bits[clk_idx++] = MII_MDOE | MII_MDO;
  171. // Write command <01>
  172. bits[clk_idx++] = MII_MDOE;
  173. bits[clk_idx++] = MII_MDOE | MII_MDO;
  174. // Output the PHY address, msb first
  175. mask = (byte)0x10;
  176. for (i = 0; i < 5; ++i)
  177. {
  178. if (phyaddr & mask)
  179. bits[clk_idx++] = MII_MDOE | MII_MDO;
  180. else
  181. bits[clk_idx++] = MII_MDOE;
  182. // Shift to next lowest bit
  183. mask >>= 1;
  184. }
  185. // Output the phy register number, msb first
  186. mask = (byte)0x10;
  187. for (i = 0; i < 5; ++i)
  188. {
  189. if (phyreg & mask)
  190. bits[clk_idx++] = MII_MDOE | MII_MDO;
  191. else
  192. bits[clk_idx++] = MII_MDOE;
  193. // Shift to next lowest bit
  194. mask >>= 1;
  195. }
  196. // Tristate and turnaround (2 bit times)
  197. bits[clk_idx++] = 0;
  198. bits[clk_idx++] = 0;
  199. // Write out 16 bits of data, msb first
  200. mask = 0x8000;
  201. for (i = 0; i < 16; ++i)
  202. {
  203. if (phydata & mask)
  204. bits[clk_idx++] = MII_MDOE | MII_MDO;
  205. else
  206. bits[clk_idx++] = MII_MDOE;
  207. // Shift to next lowest bit
  208. mask >>= 1;
  209. }
  210. // Final clock bit (tristate)
  211. bits[clk_idx++] = 0;
  212. // Save the current bank
  213. oldBank = inw( ioaddr+BANK_SELECT );
  214. // Select bank 3
  215. SMC_SELECT_BANK(ioaddr, 3);
  216. // Get the current MII register value
  217. mii_reg = inw( ioaddr+MII_REG );
  218. // Turn off all MII Interface bits
  219. mii_reg &= ~(MII_MDOE|MII_MCLK|MII_MDI|MII_MDO);
  220. // Clock all cycles
  221. for (i = 0; i < sizeof(bits); ++i)
  222. {
  223. // Clock Low - output data
  224. outw( mii_reg | bits[i], ioaddr+MII_REG );
  225. udelay(50);
  226. // Clock Hi - input data
  227. outw( mii_reg | bits[i] | MII_MCLK, ioaddr+MII_REG );
  228. udelay(50);
  229. bits[i] |= inw( ioaddr+MII_REG ) & MII_MDI;
  230. }
  231. // Return to idle state
  232. // Set clock to low, data to low, and output tristated
  233. outw( mii_reg, ioaddr+MII_REG );
  234. udelay(50);
  235. // Restore original bank select
  236. SMC_SELECT_BANK(ioaddr, oldBank);
  237. #if (SMC_DEBUG > 2 )
  238. printf("smc_write_phy_register(): phyaddr=%x,phyreg=%x,phydata=%x\n",
  239. phyaddr, phyreg, phydata);
  240. #endif
  241. }
  242. /*------------------------------------------------------------
  243. . Finds and reports the PHY address
  244. .-------------------------------------------------------------*/
  245. static int smc_detect_phy(int ioaddr, byte *pphyaddr)
  246. {
  247. word phy_id1;
  248. word phy_id2;
  249. int phyaddr;
  250. int found = 0;
  251. // Scan all 32 PHY addresses if necessary
  252. for (phyaddr = 0; phyaddr < 32; ++phyaddr)
  253. {
  254. // Read the PHY identifiers
  255. phy_id1 = smc_read_phy_register(ioaddr, phyaddr, PHY_ID1_REG);
  256. phy_id2 = smc_read_phy_register(ioaddr, phyaddr, PHY_ID2_REG);
  257. // Make sure it is a valid identifier
  258. if ((phy_id2 > 0x0000) && (phy_id2 < 0xffff) &&
  259. (phy_id1 > 0x0000) && (phy_id1 < 0xffff))
  260. {
  261. if ((phy_id1 != 0x8000) && (phy_id2 != 0x8000))
  262. {
  263. // Save the PHY's address
  264. *pphyaddr = phyaddr;
  265. found = 1;
  266. break;
  267. }
  268. }
  269. }
  270. if (!found)
  271. {
  272. printf("No PHY found\n");
  273. return(0);
  274. }
  275. // Set the PHY type
  276. if ( (phy_id1 == 0x0016) && ((phy_id2 & 0xFFF0) == 0xF840 ) )
  277. {
  278. printf("PHY=LAN83C183 (LAN91C111 Internal)\n");
  279. }
  280. if ( (phy_id1 == 0x0282) && ((phy_id2 & 0xFFF0) == 0x1C50) )
  281. {
  282. printf("PHY=LAN83C180\n");
  283. }
  284. return(1);
  285. }
  286. /*------------------------------------------------------------
  287. . Configures the specified PHY using Autonegotiation. Calls
  288. . smc_phy_fixed() if the user has requested a certain config.
  289. .-------------------------------------------------------------*/
  290. static void smc_phy_configure(int ioaddr)
  291. {
  292. int timeout;
  293. byte phyaddr;
  294. word my_phy_caps; // My PHY capabilities
  295. word my_ad_caps; // My Advertised capabilities
  296. word status;
  297. int rpc_cur_mode = RPC_DEFAULT;
  298. int lastPhy18;
  299. // Find the address and type of our phy
  300. if (!smc_detect_phy(ioaddr, &phyaddr))
  301. {
  302. return;
  303. }
  304. // Reset the PHY, setting all other bits to zero
  305. smc_write_phy_register(ioaddr, phyaddr, PHY_CNTL_REG, PHY_CNTL_RST);
  306. // Wait for the reset to complete, or time out
  307. timeout = 6; // Wait up to 3 seconds
  308. while (timeout--)
  309. {
  310. if (!(smc_read_phy_register(ioaddr, phyaddr, PHY_CNTL_REG)
  311. & PHY_CNTL_RST))
  312. {
  313. // reset complete
  314. break;
  315. }
  316. mdelay(500); // wait 500 millisecs
  317. }
  318. if (timeout < 1)
  319. {
  320. PRINTK2("PHY reset timed out\n");
  321. return;
  322. }
  323. // Read PHY Register 18, Status Output
  324. lastPhy18 = smc_read_phy_register(ioaddr, phyaddr, PHY_INT_REG);
  325. // Enable PHY Interrupts (for register 18)
  326. // Interrupts listed here are disabled
  327. smc_write_phy_register(ioaddr, phyaddr, PHY_MASK_REG,
  328. PHY_INT_LOSSSYNC | PHY_INT_CWRD | PHY_INT_SSD |
  329. PHY_INT_ESD | PHY_INT_RPOL | PHY_INT_JAB |
  330. PHY_INT_SPDDET | PHY_INT_DPLXDET);
  331. /* Configure the Receive/Phy Control register */
  332. SMC_SELECT_BANK(ioaddr, 0);
  333. outw( rpc_cur_mode, ioaddr + RPC_REG );
  334. // Copy our capabilities from PHY_STAT_REG to PHY_AD_REG
  335. my_phy_caps = smc_read_phy_register(ioaddr, phyaddr, PHY_STAT_REG);
  336. my_ad_caps = PHY_AD_CSMA; // I am CSMA capable
  337. if (my_phy_caps & PHY_STAT_CAP_T4)
  338. my_ad_caps |= PHY_AD_T4;
  339. if (my_phy_caps & PHY_STAT_CAP_TXF)
  340. my_ad_caps |= PHY_AD_TX_FDX;
  341. if (my_phy_caps & PHY_STAT_CAP_TXH)
  342. my_ad_caps |= PHY_AD_TX_HDX;
  343. if (my_phy_caps & PHY_STAT_CAP_TF)
  344. my_ad_caps |= PHY_AD_10_FDX;
  345. if (my_phy_caps & PHY_STAT_CAP_TH)
  346. my_ad_caps |= PHY_AD_10_HDX;
  347. // Update our Auto-Neg Advertisement Register
  348. smc_write_phy_register(ioaddr, phyaddr, PHY_AD_REG, my_ad_caps);
  349. PRINTK2("phy caps=%x\n", my_phy_caps);
  350. PRINTK2("phy advertised caps=%x\n", my_ad_caps);
  351. // Restart auto-negotiation process in order to advertise my caps
  352. smc_write_phy_register( ioaddr, phyaddr, PHY_CNTL_REG,
  353. PHY_CNTL_ANEG_EN | PHY_CNTL_ANEG_RST );
  354. // Wait for the auto-negotiation to complete. This may take from
  355. // 2 to 3 seconds.
  356. // Wait for the reset to complete, or time out
  357. timeout = 20; // Wait up to 10 seconds
  358. while (timeout--)
  359. {
  360. status = smc_read_phy_register(ioaddr, phyaddr, PHY_STAT_REG);
  361. if (status & PHY_STAT_ANEG_ACK)
  362. {
  363. // auto-negotiate complete
  364. break;
  365. }
  366. mdelay(500); // wait 500 millisecs
  367. // Restart auto-negotiation if remote fault
  368. if (status & PHY_STAT_REM_FLT)
  369. {
  370. PRINTK2("PHY remote fault detected\n");
  371. // Restart auto-negotiation
  372. PRINTK2("PHY restarting auto-negotiation\n");
  373. smc_write_phy_register( ioaddr, phyaddr, PHY_CNTL_REG,
  374. PHY_CNTL_ANEG_EN | PHY_CNTL_ANEG_RST |
  375. PHY_CNTL_SPEED | PHY_CNTL_DPLX);
  376. }
  377. }
  378. if (timeout < 1)
  379. {
  380. PRINTK2("PHY auto-negotiate timed out\n");
  381. }
  382. // Fail if we detected an auto-negotiate remote fault
  383. if (status & PHY_STAT_REM_FLT)
  384. {
  385. PRINTK2("PHY remote fault detected\n");
  386. }
  387. // Set our sysctl parameters to match auto-negotiation results
  388. if ( lastPhy18 & PHY_INT_SPDDET )
  389. {
  390. PRINTK2("PHY 100BaseT\n");
  391. rpc_cur_mode |= RPC_SPEED;
  392. }
  393. else
  394. {
  395. PRINTK2("PHY 10BaseT\n");
  396. rpc_cur_mode &= ~RPC_SPEED;
  397. }
  398. if ( lastPhy18 & PHY_INT_DPLXDET )
  399. {
  400. PRINTK2("PHY Full Duplex\n");
  401. rpc_cur_mode |= RPC_DPLX;
  402. }
  403. else
  404. {
  405. PRINTK2("PHY Half Duplex\n");
  406. rpc_cur_mode &= ~RPC_DPLX;
  407. }
  408. // Re-Configure the Receive/Phy Control register
  409. outw( rpc_cur_mode, ioaddr + RPC_REG );
  410. }
  411. /*
  412. * Function: smc_reset( int ioaddr )
  413. * Purpose:
  414. * This sets the SMC91xx chip to its normal state, hopefully from whatever
  415. * mess that any other DOS driver has put it in.
  416. *
  417. * Maybe I should reset more registers to defaults in here? SOFTRESET should
  418. * do that for me.
  419. *
  420. * Method:
  421. * 1. send a SOFT RESET
  422. * 2. wait for it to finish
  423. * 3. reset the memory management unit
  424. * 4. clear all interrupts
  425. *
  426. */
  427. static void smc_reset(int ioaddr)
  428. {
  429. /* This resets the registers mostly to defaults, but doesn't
  430. * affect EEPROM. That seems unnecessary */
  431. SMC_SELECT_BANK(ioaddr, 0);
  432. _outw( RCR_SOFTRESET, ioaddr + RCR );
  433. /* this should pause enough for the chip to be happy */
  434. SMC_DELAY(ioaddr);
  435. /* Set the transmit and receive configuration registers to
  436. * default values */
  437. _outw(RCR_CLEAR, ioaddr + RCR);
  438. _outw(TCR_CLEAR, ioaddr + TCR);
  439. /* Reset the MMU */
  440. SMC_SELECT_BANK(ioaddr, 2);
  441. _outw( MC_RESET, ioaddr + MMU_CMD );
  442. /* Note: It doesn't seem that waiting for the MMU busy is needed here,
  443. * but this is a place where future chipsets _COULD_ break. Be wary
  444. * of issuing another MMU command right after this */
  445. _outb(0, ioaddr + INT_MASK);
  446. }
  447. /*----------------------------------------------------------------------
  448. * Function: smc9000_probe_addr( int ioaddr )
  449. *
  450. * Purpose:
  451. * Tests to see if a given ioaddr points to an SMC9xxx chip.
  452. * Returns a 1 on success
  453. *
  454. * Algorithm:
  455. * (1) see if the high byte of BANK_SELECT is 0x33
  456. * (2) compare the ioaddr with the base register's address
  457. * (3) see if I recognize the chip ID in the appropriate register
  458. *
  459. * ---------------------------------------------------------------------
  460. */
  461. static int smc9000_probe_addr( isa_probe_addr_t ioaddr )
  462. {
  463. word bank;
  464. word revision_register;
  465. word base_address_register;
  466. /* First, see if the high byte is 0x33 */
  467. bank = inw(ioaddr + BANK_SELECT);
  468. if ((bank & 0xFF00) != 0x3300) {
  469. return 0;
  470. }
  471. /* The above MIGHT indicate a device, but I need to write to further
  472. * test this. */
  473. _outw(0x0, ioaddr + BANK_SELECT);
  474. bank = inw(ioaddr + BANK_SELECT);
  475. if ((bank & 0xFF00) != 0x3300) {
  476. return 0;
  477. }
  478. /* well, we've already written once, so hopefully another time won't
  479. * hurt. This time, I need to switch the bank register to bank 1,
  480. * so I can access the base address register */
  481. SMC_SELECT_BANK(ioaddr, 1);
  482. base_address_register = inw(ioaddr + BASE);
  483. if (ioaddr != (base_address_register >> 3 & 0x3E0)) {
  484. DBG("SMC9000: IOADDR %hX doesn't match configuration (%hX)."
  485. "Probably not a SMC chip\n",
  486. ioaddr, base_address_register >> 3 & 0x3E0);
  487. /* well, the base address register didn't match. Must not have
  488. * been a SMC chip after all. */
  489. return 0;
  490. }
  491. /* check if the revision register is something that I recognize.
  492. * These might need to be added to later, as future revisions
  493. * could be added. */
  494. SMC_SELECT_BANK(ioaddr, 3);
  495. revision_register = inw(ioaddr + REVISION);
  496. if (!chip_ids[(revision_register >> 4) & 0xF]) {
  497. /* I don't recognize this chip, so... */
  498. DBG( "SMC9000: IO %hX: Unrecognized revision register:"
  499. " %hX, Contact author.\n", ioaddr, revision_register );
  500. return 0;
  501. }
  502. /* at this point I'll assume that the chip is an SMC9xxx.
  503. * It might be prudent to check a listing of MAC addresses
  504. * against the hardware address, or do some other tests. */
  505. return 1;
  506. }
  507. /**************************************************************************
  508. * ETH_TRANSMIT - Transmit a frame
  509. ***************************************************************************/
  510. static void smc9000_transmit(
  511. struct nic *nic,
  512. const char *d, /* Destination */
  513. unsigned int t, /* Type */
  514. unsigned int s, /* size */
  515. const char *p) /* Packet */
  516. {
  517. word length; /* real, length incl. header */
  518. word numPages;
  519. unsigned long time_out;
  520. byte packet_no;
  521. word status;
  522. int i;
  523. /* We dont pad here since we can have the hardware doing it for us */
  524. length = (s + ETH_HLEN + 1)&~1;
  525. /* convert to MMU pages */
  526. numPages = length / 256;
  527. if (numPages > 7 ) {
  528. DBG("SMC9000: Far too big packet error. \n");
  529. return;
  530. }
  531. /* dont try more than, say 30 times */
  532. for (i=0;i<30;i++) {
  533. /* now, try to allocate the memory */
  534. SMC_SELECT_BANK(nic->ioaddr, 2);
  535. _outw(MC_ALLOC | numPages, nic->ioaddr + MMU_CMD);
  536. status = 0;
  537. /* wait for the memory allocation to finnish */
  538. for (time_out = currticks() + 5*TICKS_PER_SEC; currticks() < time_out; ) {
  539. status = inb(nic->ioaddr + INTERRUPT);
  540. if ( status & IM_ALLOC_INT ) {
  541. /* acknowledge the interrupt */
  542. _outb(IM_ALLOC_INT, nic->ioaddr + INTERRUPT);
  543. break;
  544. }
  545. }
  546. if ((status & IM_ALLOC_INT) != 0 ) {
  547. /* We've got the memory */
  548. break;
  549. } else {
  550. printf("SMC9000: Memory allocation timed out, resetting MMU.\n");
  551. _outw(MC_RESET, nic->ioaddr + MMU_CMD);
  552. }
  553. }
  554. /* If I get here, I _know_ there is a packet slot waiting for me */
  555. packet_no = inb(nic->ioaddr + PNR_ARR + 1);
  556. if (packet_no & 0x80) {
  557. /* or isn't there? BAD CHIP! */
  558. printf("SMC9000: Memory allocation failed. \n");
  559. return;
  560. }
  561. /* we have a packet address, so tell the card to use it */
  562. _outb(packet_no, nic->ioaddr + PNR_ARR);
  563. /* point to the beginning of the packet */
  564. _outw(PTR_AUTOINC, nic->ioaddr + POINTER);
  565. #if SMC9000_DEBUG > 2
  566. printf("Trying to xmit packet of length %hX\n", length );
  567. #endif
  568. /* send the packet length ( +6 for status, length and ctl byte )
  569. * and the status word ( set to zeros ) */
  570. _outw(0, nic->ioaddr + DATA_1 );
  571. /* send the packet length ( +6 for status words, length, and ctl) */
  572. _outb((length+6) & 0xFF, nic->ioaddr + DATA_1);
  573. _outb((length+6) >> 8 , nic->ioaddr + DATA_1);
  574. /* Write the contents of the packet */
  575. /* The ethernet header first... */
  576. outsw(nic->ioaddr + DATA_1, d, ETH_ALEN >> 1);
  577. outsw(nic->ioaddr + DATA_1, nic->node_addr, ETH_ALEN >> 1);
  578. _outw(htons(t), nic->ioaddr + DATA_1);
  579. /* ... the data ... */
  580. outsw(nic->ioaddr + DATA_1 , p, s >> 1);
  581. /* ... and the last byte, if there is one. */
  582. if ((s & 1) == 0) {
  583. _outw(0, nic->ioaddr + DATA_1);
  584. } else {
  585. _outb(p[s-1], nic->ioaddr + DATA_1);
  586. _outb(0x20, nic->ioaddr + DATA_1);
  587. }
  588. /* and let the chipset deal with it */
  589. _outw(MC_ENQUEUE , nic->ioaddr + MMU_CMD);
  590. status = 0; time_out = currticks() + 5*TICKS_PER_SEC;
  591. do {
  592. status = inb(nic->ioaddr + INTERRUPT);
  593. if ((status & IM_TX_INT ) != 0) {
  594. word tx_status;
  595. /* ack interrupt */
  596. _outb(IM_TX_INT, nic->ioaddr + INTERRUPT);
  597. packet_no = inw(nic->ioaddr + FIFO_PORTS);
  598. packet_no &= 0x7F;
  599. /* select this as the packet to read from */
  600. _outb( packet_no, nic->ioaddr + PNR_ARR );
  601. /* read the first word from this packet */
  602. _outw( PTR_AUTOINC | PTR_READ, nic->ioaddr + POINTER );
  603. tx_status = inw( nic->ioaddr + DATA_1 );
  604. if (0 == (tx_status & TS_SUCCESS)) {
  605. DBG("SMC9000: TX FAIL STATUS: %hX \n", tx_status);
  606. /* re-enable transmit */
  607. SMC_SELECT_BANK(nic->ioaddr, 0);
  608. _outw(inw(nic->ioaddr + TCR ) | TCR_ENABLE, nic->ioaddr + TCR );
  609. }
  610. /* kill the packet */
  611. SMC_SELECT_BANK(nic->ioaddr, 2);
  612. _outw(MC_FREEPKT, nic->ioaddr + MMU_CMD);
  613. return;
  614. }
  615. }while(currticks() < time_out);
  616. printf("SMC9000: TX timed out, resetting board\n");
  617. smc_reset(nic->ioaddr);
  618. return;
  619. }
  620. /**************************************************************************
  621. * ETH_POLL - Wait for a frame
  622. ***************************************************************************/
  623. static int smc9000_poll(struct nic *nic, int retrieve)
  624. {
  625. SMC_SELECT_BANK(nic->ioaddr, 2);
  626. if (inw(nic->ioaddr + FIFO_PORTS) & FP_RXEMPTY)
  627. return 0;
  628. if ( ! retrieve ) return 1;
  629. /* start reading from the start of the packet */
  630. _outw(PTR_READ | PTR_RCV | PTR_AUTOINC, nic->ioaddr + POINTER);
  631. /* First read the status and check that we're ok */
  632. if (!(inw(nic->ioaddr + DATA_1) & RS_ERRORS)) {
  633. /* Next: read the packet length and mask off the top bits */
  634. nic->packetlen = (inw(nic->ioaddr + DATA_1) & 0x07ff);
  635. /* the packet length includes the 3 extra words */
  636. nic->packetlen -= 6;
  637. #if SMC9000_DEBUG > 2
  638. printf(" Reading %d words (and %d byte(s))\n",
  639. (nic->packetlen >> 1), nic->packetlen & 1);
  640. #endif
  641. /* read the packet (and the last "extra" word) */
  642. insw(nic->ioaddr + DATA_1, nic->packet, (nic->packetlen+2) >> 1);
  643. /* is there an odd last byte ? */
  644. if (nic->packet[nic->packetlen+1] & 0x20)
  645. nic->packetlen++;
  646. /* error or good, tell the card to get rid of this packet */
  647. _outw(MC_RELEASE, nic->ioaddr + MMU_CMD);
  648. return 1;
  649. }
  650. printf("SMC9000: RX error\n");
  651. /* error or good, tell the card to get rid of this packet */
  652. _outw(MC_RELEASE, nic->ioaddr + MMU_CMD);
  653. return 0;
  654. }
  655. static void smc9000_disable ( struct nic *nic, struct isa_device *isa __unused ) {
  656. smc_reset(nic->ioaddr);
  657. /* no more interrupts for me */
  658. SMC_SELECT_BANK(nic->ioaddr, 2);
  659. _outb( 0, nic->ioaddr + INT_MASK);
  660. /* and tell the card to stay away from that nasty outside world */
  661. SMC_SELECT_BANK(nic->ioaddr, 0);
  662. _outb( RCR_CLEAR, nic->ioaddr + RCR );
  663. _outb( TCR_CLEAR, nic->ioaddr + TCR );
  664. }
  665. static void smc9000_irq(struct nic *nic __unused, irq_action_t action __unused)
  666. {
  667. switch ( action ) {
  668. case DISABLE :
  669. break;
  670. case ENABLE :
  671. break;
  672. case FORCE :
  673. break;
  674. }
  675. }
  676. static struct nic_operations smc9000_operations = {
  677. .connect = dummy_connect,
  678. .poll = smc9000_poll,
  679. .transmit = smc9000_transmit,
  680. .irq = smc9000_irq,
  681. };
  682. /**************************************************************************
  683. * ETH_PROBE - Look for an adapter
  684. ***************************************************************************/
  685. static int smc9000_probe ( struct nic *nic, struct isa_device *isa ) {
  686. unsigned short revision;
  687. int memory;
  688. int media;
  689. const char * version_string;
  690. const char * if_string;
  691. int i;
  692. nic->irqno = 0;
  693. nic->ioaddr = isa->ioaddr;
  694. /*
  695. * Get the MAC address ( bank 1, regs 4 - 9 )
  696. */
  697. SMC_SELECT_BANK(nic->ioaddr, 1);
  698. for ( i = 0; i < 6; i += 2 ) {
  699. word address;
  700. address = inw(nic->ioaddr + ADDR0 + i);
  701. nic->node_addr[i+1] = address >> 8;
  702. nic->node_addr[i] = address & 0xFF;
  703. }
  704. /* get the memory information */
  705. SMC_SELECT_BANK(nic->ioaddr, 0);
  706. memory = ( inw(nic->ioaddr + MCR) >> 9 ) & 0x7; /* multiplier */
  707. memory *= 256 * (inw(nic->ioaddr + MIR) & 0xFF);
  708. /*
  709. * Now, I want to find out more about the chip. This is sort of
  710. * redundant, but it's cleaner to have it in both, rather than having
  711. * one VERY long probe procedure.
  712. */
  713. SMC_SELECT_BANK(nic->ioaddr, 3);
  714. revision = inw(nic->ioaddr + REVISION);
  715. version_string = chip_ids[(revision >> 4) & 0xF];
  716. if (((revision & 0xF0) >> 4 == CHIP_9196) &&
  717. ((revision & 0x0F) >= REV_9196)) {
  718. /* This is a 91c96. 'c96 has the same chip id as 'c94 (4) but
  719. * a revision starting at 6 */
  720. version_string = smc91c96_id;
  721. }
  722. if ( !version_string ) {
  723. /* I shouldn't get here because this call was done before.... */
  724. return 0;
  725. }
  726. /* is it using AUI or 10BaseT ? */
  727. SMC_SELECT_BANK(nic->ioaddr, 1);
  728. if (inw(nic->ioaddr + CFG) & CFG_AUI_SELECT)
  729. media = 2;
  730. else
  731. media = 1;
  732. if_string = interfaces[media - 1];
  733. /* now, reset the chip, and put it into a known state */
  734. smc_reset(nic->ioaddr);
  735. printf("SMC9000 %s\n", smc9000_version);
  736. DBG("Copyright (C) 1998 Daniel Engstr\x94m\n");
  737. DBG("Copyright (C) 1996 Eric Stahlman\n");
  738. printf("%s rev:%d I/O port:%hX Interface:%s RAM:%d bytes \n",
  739. version_string, revision & 0xF,
  740. nic->ioaddr, if_string, memory );
  741. DBG ( "Ethernet MAC address: %s\n", eth_ntoa ( nic->node_addr ) );
  742. SMC_SELECT_BANK(nic->ioaddr, 0);
  743. /* see the header file for options in TCR/RCR NORMAL*/
  744. _outw(TCR_NORMAL, nic->ioaddr + TCR);
  745. _outw(RCR_NORMAL, nic->ioaddr + RCR);
  746. /* Select which interface to use */
  747. SMC_SELECT_BANK(nic->ioaddr, 1);
  748. if ( media == 1 ) {
  749. _outw( inw( nic->ioaddr + CFG ) & ~CFG_AUI_SELECT,
  750. nic->ioaddr + CFG );
  751. }
  752. else if ( media == 2 ) {
  753. _outw( inw( nic->ioaddr + CFG ) | CFG_AUI_SELECT,
  754. nic->ioaddr + CFG );
  755. }
  756. smc_phy_configure(nic->ioaddr);
  757. nic->nic_op = &smc9000_operations;
  758. return 1;
  759. }
  760. /*
  761. * The SMC9000 can be at any of the following port addresses. To
  762. * change for a slightly different card, you can add it to the array.
  763. *
  764. */
  765. static isa_probe_addr_t smc9000_probe_addrs[] = {
  766. 0x200, 0x220, 0x240, 0x260, 0x280, 0x2A0, 0x2C0, 0x2E0,
  767. 0x300, 0x320, 0x340, 0x360, 0x380, 0x3A0, 0x3C0, 0x3E0,
  768. };
  769. ISA_DRIVER ( smc9000_driver, smc9000_probe_addrs, smc9000_probe_addr,
  770. GENERIC_ISAPNP_VENDOR, 0x8228 );
  771. DRIVER ( "SMC9000", nic_driver, isa_driver, smc9000_driver,
  772. smc9000_probe, smc9000_disable );
  773. ISA_ROM ( "smc9000", "SMC9000" );
  774. /*
  775. * Local variables:
  776. * c-basic-offset: 8
  777. * c-indent-level: 8
  778. * tab-width: 8
  779. * End:
  780. */