smc91111.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389
  1. /*------------------------------------------------------------------------
  2. . smc91111.c
  3. . This is a driver for SMSC's 91C111 single-chip Ethernet device.
  4. .
  5. . (C) Copyright 2002
  6. . Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  7. . Rolf Offermanns <rof@sysgo.de>
  8. .
  9. . Copyright (C) 2001 Standard Microsystems Corporation (SMSC)
  10. . Developed by Simple Network Magic Corporation (SNMC)
  11. . Copyright (C) 1996 by Erik Stahlman (ES)
  12. .
  13. . This program is free software; you can redistribute it and/or modify
  14. . it under the terms of the GNU General Public License as published by
  15. . the Free Software Foundation; either version 2 of the License, or
  16. . (at your option) any later version.
  17. .
  18. . This program is distributed in the hope that it will be useful,
  19. . but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. . MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. . GNU General Public License for more details.
  22. .
  23. . You should have received a copy of the GNU General Public License
  24. . along with this program; if not, write to the Free Software
  25. . Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  26. .
  27. . Information contained in this file was obtained from the LAN91C111
  28. . manual from SMC. To get a copy, if you really want one, you can find
  29. . information under www.smsc.com.
  30. .
  31. .
  32. . "Features" of the SMC chip:
  33. . Integrated PHY/MAC for 10/100BaseT Operation
  34. . Supports internal and external MII
  35. . Integrated 8K packet memory
  36. . EEPROM interface for configuration
  37. .
  38. . Arguments:
  39. . io = for the base address
  40. . irq = for the IRQ
  41. .
  42. . author:
  43. . Erik Stahlman ( erik@vt.edu )
  44. . Daris A Nevil ( dnevil@snmc.com )
  45. .
  46. .
  47. . Hardware multicast code from Peter Cammaert ( pc@denkart.be )
  48. .
  49. . Sources:
  50. . o SMSC LAN91C111 databook (www.smsc.com)
  51. . o smc9194.c by Erik Stahlman
  52. . o skeleton.c by Donald Becker ( becker@cesdis.gsfc.nasa.gov )
  53. .
  54. . History:
  55. . 06/19/03 Richard Woodruff Made u-boot environment aware and added mac addr checks.
  56. . 10/17/01 Marco Hasewinkel Modify for DNP/1110
  57. . 07/25/01 Woojung Huh Modify for ADS Bitsy
  58. . 04/25/01 Daris A Nevil Initial public release through SMSC
  59. . 03/16/01 Daris A Nevil Modified smc9194.c for use with LAN91C111
  60. ----------------------------------------------------------------------------*/
  61. #include <common.h>
  62. #include <command.h>
  63. #include <config.h>
  64. #include <malloc.h>
  65. #include "smc91111.h"
  66. #include <net.h>
  67. /* Use power-down feature of the chip */
  68. #define POWER_DOWN 0
  69. #define NO_AUTOPROBE
  70. #define SMC_DEBUG 0
  71. #if SMC_DEBUG > 1
  72. static const char version[] =
  73. "smc91111.c:v1.0 04/25/01 by Daris A Nevil (dnevil@snmc.com)\n";
  74. #endif
  75. /* Autonegotiation timeout in seconds */
  76. #ifndef CONFIG_SMC_AUTONEG_TIMEOUT
  77. #define CONFIG_SMC_AUTONEG_TIMEOUT 10
  78. #endif
  79. /*------------------------------------------------------------------------
  80. .
  81. . Configuration options, for the experienced user to change.
  82. .
  83. -------------------------------------------------------------------------*/
  84. /*
  85. . Wait time for memory to be free. This probably shouldn't be
  86. . tuned that much, as waiting for this means nothing else happens
  87. . in the system
  88. */
  89. #define MEMORY_WAIT_TIME 16
  90. #if (SMC_DEBUG > 2 )
  91. #define PRINTK3(args...) printf(args)
  92. #else
  93. #define PRINTK3(args...)
  94. #endif
  95. #if SMC_DEBUG > 1
  96. #define PRINTK2(args...) printf(args)
  97. #else
  98. #define PRINTK2(args...)
  99. #endif
  100. #ifdef SMC_DEBUG
  101. #define PRINTK(args...) printf(args)
  102. #else
  103. #define PRINTK(args...)
  104. #endif
  105. /*------------------------------------------------------------------------
  106. .
  107. . The internal workings of the driver. If you are changing anything
  108. . here with the SMC stuff, you should have the datasheet and know
  109. . what you are doing.
  110. .
  111. -------------------------------------------------------------------------*/
  112. /* Memory sizing constant */
  113. #define LAN91C111_MEMORY_MULTIPLIER (1024*2)
  114. #ifndef CONFIG_SMC91111_BASE
  115. #error "SMC91111 Base address must be passed to initialization funciton"
  116. /* #define CONFIG_SMC91111_BASE 0x20000300 */
  117. #endif
  118. #define SMC_DEV_NAME "SMC91111"
  119. #define SMC_PHY_ADDR 0x0000
  120. #define SMC_ALLOC_MAX_TRY 5
  121. #define SMC_TX_TIMEOUT 30
  122. #define SMC_PHY_CLOCK_DELAY 1000
  123. #define ETH_ZLEN 60
  124. #ifdef CONFIG_SMC_USE_32_BIT
  125. #define USE_32_BIT 1
  126. #else
  127. #undef USE_32_BIT
  128. #endif
  129. #ifdef SHARED_RESOURCES
  130. extern void swap_to(int device_id);
  131. #else
  132. # define swap_to(x)
  133. #endif
  134. #ifndef CONFIG_SMC91111_EXT_PHY
  135. static void smc_phy_configure(struct eth_device *dev);
  136. #endif /* !CONFIG_SMC91111_EXT_PHY */
  137. /*
  138. ------------------------------------------------------------
  139. .
  140. . Internal routines
  141. .
  142. ------------------------------------------------------------
  143. */
  144. #ifdef CONFIG_SMC_USE_IOFUNCS
  145. /*
  146. * input and output functions
  147. *
  148. * Implemented due to inx,outx macros accessing the device improperly
  149. * and putting the device into an unkown state.
  150. *
  151. * For instance, on Sharp LPD7A400 SDK, affects were chip memory
  152. * could not be free'd (hence the alloc failures), duplicate packets,
  153. * packets being corrupt (shifted) on the wire, etc. Switching to the
  154. * inx,outx functions fixed this problem.
  155. */
  156. #define barrier() __asm__ __volatile__("": : :"memory")
  157. static inline word SMC_inw(struct eth_device *dev, dword offset)
  158. {
  159. word v;
  160. v = *((volatile word*)(dev->iobase + offset));
  161. barrier(); *(volatile u32*)(0xc0000000);
  162. return v;
  163. }
  164. static inline void SMC_outw(struct eth_device *dev, word value, dword offset)
  165. {
  166. *((volatile word*)(dev->iobase + offset)) = value;
  167. barrier(); *(volatile u32*)(0xc0000000);
  168. }
  169. static inline byte SMC_inb(struct eth_device *dev, dword offset)
  170. {
  171. word _w;
  172. _w = SMC_inw(dev, offset & ~((dword)1));
  173. return (offset & 1) ? (byte)(_w >> 8) : (byte)(_w);
  174. }
  175. static inline void SMC_outb(struct eth_device *dev, byte value, dword offset)
  176. {
  177. word _w;
  178. _w = SMC_inw(dev, offset & ~((dword)1));
  179. if (offset & 1)
  180. *((volatile word*)(dev->iobase + (offset & ~((dword)1)))) =
  181. (value<<8) | (_w & 0x00ff);
  182. else
  183. *((volatile word*)(dev->iobase + offset)) =
  184. value | (_w & 0xff00);
  185. }
  186. static inline void SMC_insw(struct eth_device *dev, dword offset,
  187. volatile uchar* buf, dword len)
  188. {
  189. volatile word *p = (volatile word *)buf;
  190. while (len-- > 0) {
  191. *p++ = SMC_inw(dev, offset);
  192. barrier();
  193. *((volatile u32*)(0xc0000000));
  194. }
  195. }
  196. static inline void SMC_outsw(struct eth_device *dev, dword offset,
  197. uchar* buf, dword len)
  198. {
  199. volatile word *p = (volatile word *)buf;
  200. while (len-- > 0) {
  201. SMC_outw(dev, *p++, offset);
  202. barrier();
  203. *(volatile u32*)(0xc0000000);
  204. }
  205. }
  206. #endif /* CONFIG_SMC_USE_IOFUNCS */
  207. /*
  208. . A rather simple routine to print out a packet for debugging purposes.
  209. */
  210. #if SMC_DEBUG > 2
  211. static void print_packet( byte *, int );
  212. #endif
  213. #define tx_done(dev) 1
  214. static int poll4int (struct eth_device *dev, byte mask, int timeout)
  215. {
  216. int tmo = get_timer (0) + timeout * CONFIG_SYS_HZ;
  217. int is_timeout = 0;
  218. word old_bank = SMC_inw (dev, BSR_REG);
  219. PRINTK2 ("Polling...\n");
  220. SMC_SELECT_BANK (dev, 2);
  221. while ((SMC_inw (dev, SMC91111_INT_REG) & mask) == 0) {
  222. if (get_timer (0) >= tmo) {
  223. is_timeout = 1;
  224. break;
  225. }
  226. }
  227. /* restore old bank selection */
  228. SMC_SELECT_BANK (dev, old_bank);
  229. if (is_timeout)
  230. return 1;
  231. else
  232. return 0;
  233. }
  234. /* Only one release command at a time, please */
  235. static inline void smc_wait_mmu_release_complete (struct eth_device *dev)
  236. {
  237. int count = 0;
  238. /* assume bank 2 selected */
  239. while (SMC_inw (dev, MMU_CMD_REG) & MC_BUSY) {
  240. udelay (1); /* Wait until not busy */
  241. if (++count > 200)
  242. break;
  243. }
  244. }
  245. /*
  246. . Function: smc_reset( void )
  247. . Purpose:
  248. . This sets the SMC91111 chip to its normal state, hopefully from whatever
  249. . mess that any other DOS driver has put it in.
  250. .
  251. . Maybe I should reset more registers to defaults in here? SOFTRST should
  252. . do that for me.
  253. .
  254. . Method:
  255. . 1. send a SOFT RESET
  256. . 2. wait for it to finish
  257. . 3. enable autorelease mode
  258. . 4. reset the memory management unit
  259. . 5. clear all interrupts
  260. .
  261. */
  262. static void smc_reset (struct eth_device *dev)
  263. {
  264. PRINTK2 ("%s: smc_reset\n", SMC_DEV_NAME);
  265. /* This resets the registers mostly to defaults, but doesn't
  266. affect EEPROM. That seems unnecessary */
  267. SMC_SELECT_BANK (dev, 0);
  268. SMC_outw (dev, RCR_SOFTRST, RCR_REG);
  269. /* Setup the Configuration Register */
  270. /* This is necessary because the CONFIG_REG is not affected */
  271. /* by a soft reset */
  272. SMC_SELECT_BANK (dev, 1);
  273. #if defined(CONFIG_SMC91111_EXT_PHY)
  274. SMC_outw (dev, CONFIG_DEFAULT | CONFIG_EXT_PHY, CONFIG_REG);
  275. #else
  276. SMC_outw (dev, CONFIG_DEFAULT, CONFIG_REG);
  277. #endif
  278. /* Release from possible power-down state */
  279. /* Configuration register is not affected by Soft Reset */
  280. SMC_outw (dev, SMC_inw (dev, CONFIG_REG) | CONFIG_EPH_POWER_EN,
  281. CONFIG_REG);
  282. SMC_SELECT_BANK (dev, 0);
  283. /* this should pause enough for the chip to be happy */
  284. udelay (10);
  285. /* Disable transmit and receive functionality */
  286. SMC_outw (dev, RCR_CLEAR, RCR_REG);
  287. SMC_outw (dev, TCR_CLEAR, TCR_REG);
  288. /* set the control register */
  289. SMC_SELECT_BANK (dev, 1);
  290. SMC_outw (dev, CTL_DEFAULT, CTL_REG);
  291. /* Reset the MMU */
  292. SMC_SELECT_BANK (dev, 2);
  293. smc_wait_mmu_release_complete (dev);
  294. SMC_outw (dev, MC_RESET, MMU_CMD_REG);
  295. while (SMC_inw (dev, MMU_CMD_REG) & MC_BUSY)
  296. udelay (1); /* Wait until not busy */
  297. /* Note: It doesn't seem that waiting for the MMU busy is needed here,
  298. but this is a place where future chipsets _COULD_ break. Be wary
  299. of issuing another MMU command right after this */
  300. /* Disable all interrupts */
  301. SMC_outb (dev, 0, IM_REG);
  302. }
  303. /*
  304. . Function: smc_enable
  305. . Purpose: let the chip talk to the outside work
  306. . Method:
  307. . 1. Enable the transmitter
  308. . 2. Enable the receiver
  309. . 3. Enable interrupts
  310. */
  311. static void smc_enable(struct eth_device *dev)
  312. {
  313. PRINTK2("%s: smc_enable\n", SMC_DEV_NAME);
  314. SMC_SELECT_BANK( dev, 0 );
  315. /* see the header file for options in TCR/RCR DEFAULT*/
  316. SMC_outw( dev, TCR_DEFAULT, TCR_REG );
  317. SMC_outw( dev, RCR_DEFAULT, RCR_REG );
  318. /* clear MII_DIS */
  319. /* smc_write_phy_register(PHY_CNTL_REG, 0x0000); */
  320. }
  321. /*
  322. . Function: smc_halt
  323. . Purpose: closes down the SMC91xxx chip.
  324. . Method:
  325. . 1. zero the interrupt mask
  326. . 2. clear the enable receive flag
  327. . 3. clear the enable xmit flags
  328. .
  329. . TODO:
  330. . (1) maybe utilize power down mode.
  331. . Why not yet? Because while the chip will go into power down mode,
  332. . the manual says that it will wake up in response to any I/O requests
  333. . in the register space. Empirical results do not show this working.
  334. */
  335. static void smc_halt(struct eth_device *dev)
  336. {
  337. PRINTK2("%s: smc_halt\n", SMC_DEV_NAME);
  338. /* no more interrupts for me */
  339. SMC_SELECT_BANK( dev, 2 );
  340. SMC_outb( dev, 0, IM_REG );
  341. /* and tell the card to stay away from that nasty outside world */
  342. SMC_SELECT_BANK( dev, 0 );
  343. SMC_outb( dev, RCR_CLEAR, RCR_REG );
  344. SMC_outb( dev, TCR_CLEAR, TCR_REG );
  345. swap_to(FLASH);
  346. }
  347. /*
  348. . Function: smc_send(struct net_device * )
  349. . Purpose:
  350. . This sends the actual packet to the SMC9xxx chip.
  351. .
  352. . Algorithm:
  353. . First, see if a saved_skb is available.
  354. . ( this should NOT be called if there is no 'saved_skb'
  355. . Now, find the packet number that the chip allocated
  356. . Point the data pointers at it in memory
  357. . Set the length word in the chip's memory
  358. . Dump the packet to chip memory
  359. . Check if a last byte is needed ( odd length packet )
  360. . if so, set the control flag right
  361. . Tell the card to send it
  362. . Enable the transmit interrupt, so I know if it failed
  363. . Free the kernel data if I actually sent it.
  364. */
  365. static int smc_send(struct eth_device *dev, volatile void *packet,
  366. int packet_length)
  367. {
  368. byte packet_no;
  369. byte *buf;
  370. int length;
  371. int numPages;
  372. int try = 0;
  373. int time_out;
  374. byte status;
  375. byte saved_pnr;
  376. word saved_ptr;
  377. /* save PTR and PNR registers before manipulation */
  378. SMC_SELECT_BANK (dev, 2);
  379. saved_pnr = SMC_inb( dev, PN_REG );
  380. saved_ptr = SMC_inw( dev, PTR_REG );
  381. PRINTK3 ("%s: smc_hardware_send_packet\n", SMC_DEV_NAME);
  382. length = ETH_ZLEN < packet_length ? packet_length : ETH_ZLEN;
  383. /* allocate memory
  384. ** The MMU wants the number of pages to be the number of 256 bytes
  385. ** 'pages', minus 1 ( since a packet can't ever have 0 pages :) )
  386. **
  387. ** The 91C111 ignores the size bits, but the code is left intact
  388. ** for backwards and future compatibility.
  389. **
  390. ** Pkt size for allocating is data length +6 (for additional status
  391. ** words, length and ctl!)
  392. **
  393. ** If odd size then last byte is included in this header.
  394. */
  395. numPages = ((length & 0xfffe) + 6);
  396. numPages >>= 8; /* Divide by 256 */
  397. if (numPages > 7) {
  398. printf ("%s: Far too big packet error. \n", SMC_DEV_NAME);
  399. return 0;
  400. }
  401. /* now, try to allocate the memory */
  402. SMC_SELECT_BANK (dev, 2);
  403. SMC_outw (dev, MC_ALLOC | numPages, MMU_CMD_REG);
  404. /* FIXME: the ALLOC_INT bit never gets set *
  405. * so the following will always give a *
  406. * memory allocation error. *
  407. * same code works in armboot though *
  408. * -ro
  409. */
  410. again:
  411. try++;
  412. time_out = MEMORY_WAIT_TIME;
  413. do {
  414. status = SMC_inb (dev, SMC91111_INT_REG);
  415. if (status & IM_ALLOC_INT) {
  416. /* acknowledge the interrupt */
  417. SMC_outb (dev, IM_ALLOC_INT, SMC91111_INT_REG);
  418. break;
  419. }
  420. } while (--time_out);
  421. if (!time_out) {
  422. PRINTK2 ("%s: memory allocation, try %d failed ...\n",
  423. SMC_DEV_NAME, try);
  424. if (try < SMC_ALLOC_MAX_TRY)
  425. goto again;
  426. else
  427. return 0;
  428. }
  429. PRINTK2 ("%s: memory allocation, try %d succeeded ...\n",
  430. SMC_DEV_NAME, try);
  431. buf = (byte *) packet;
  432. /* If I get here, I _know_ there is a packet slot waiting for me */
  433. packet_no = SMC_inb (dev, AR_REG);
  434. if (packet_no & AR_FAILED) {
  435. /* or isn't there? BAD CHIP! */
  436. printf ("%s: Memory allocation failed. \n", SMC_DEV_NAME);
  437. return 0;
  438. }
  439. /* we have a packet address, so tell the card to use it */
  440. #ifndef CONFIG_XAENIAX
  441. SMC_outb (dev, packet_no, PN_REG);
  442. #else
  443. /* On Xaeniax board, we can't use SMC_outb here because that way
  444. * the Allocate MMU command will end up written to the command register
  445. * as well, which will lead to a problem.
  446. */
  447. SMC_outl (dev, packet_no << 16, 0);
  448. #endif
  449. /* do not write new ptr value if Write data fifo not empty */
  450. while ( saved_ptr & PTR_NOTEMPTY )
  451. printf ("Write data fifo not empty!\n");
  452. /* point to the beginning of the packet */
  453. SMC_outw (dev, PTR_AUTOINC, PTR_REG);
  454. PRINTK3 ("%s: Trying to xmit packet of length %x\n",
  455. SMC_DEV_NAME, length);
  456. #if SMC_DEBUG > 2
  457. printf ("Transmitting Packet\n");
  458. print_packet (buf, length);
  459. #endif
  460. /* send the packet length ( +6 for status, length and ctl byte )
  461. and the status word ( set to zeros ) */
  462. #ifdef USE_32_BIT
  463. SMC_outl (dev, (length + 6) << 16, SMC91111_DATA_REG);
  464. #else
  465. SMC_outw (dev, 0, SMC91111_DATA_REG);
  466. /* send the packet length ( +6 for status words, length, and ctl */
  467. SMC_outw (dev, (length + 6), SMC91111_DATA_REG);
  468. #endif
  469. /* send the actual data
  470. . I _think_ it's faster to send the longs first, and then
  471. . mop up by sending the last word. It depends heavily
  472. . on alignment, at least on the 486. Maybe it would be
  473. . a good idea to check which is optimal? But that could take
  474. . almost as much time as is saved?
  475. */
  476. #ifdef USE_32_BIT
  477. SMC_outsl (dev, SMC91111_DATA_REG, buf, length >> 2);
  478. #ifndef CONFIG_XAENIAX
  479. if (length & 0x2)
  480. SMC_outw (dev, *((word *) (buf + (length & 0xFFFFFFFC))),
  481. SMC91111_DATA_REG);
  482. #else
  483. /* On XANEIAX, we can only use 32-bit writes, so we need to handle
  484. * unaligned tail part specially. The standard code doesn't work.
  485. */
  486. if ((length & 3) == 3) {
  487. u16 * ptr = (u16*) &buf[length-3];
  488. SMC_outl(dev, (*ptr) | ((0x2000 | buf[length-1]) << 16),
  489. SMC91111_DATA_REG);
  490. } else if ((length & 2) == 2) {
  491. u16 * ptr = (u16*) &buf[length-2];
  492. SMC_outl(dev, *ptr, SMC91111_DATA_REG);
  493. } else if (length & 1) {
  494. SMC_outl(dev, (0x2000 | buf[length-1]), SMC91111_DATA_REG);
  495. } else {
  496. SMC_outl(dev, 0, SMC91111_DATA_REG);
  497. }
  498. #endif
  499. #else
  500. SMC_outsw (dev, SMC91111_DATA_REG, buf, (length) >> 1);
  501. #endif /* USE_32_BIT */
  502. #ifndef CONFIG_XAENIAX
  503. /* Send the last byte, if there is one. */
  504. if ((length & 1) == 0) {
  505. SMC_outw (dev, 0, SMC91111_DATA_REG);
  506. } else {
  507. SMC_outw (dev, buf[length - 1] | 0x2000, SMC91111_DATA_REG);
  508. }
  509. #endif
  510. /* and let the chipset deal with it */
  511. SMC_outw (dev, MC_ENQUEUE, MMU_CMD_REG);
  512. /* poll for TX INT */
  513. /* if (poll4int (dev, IM_TX_INT, SMC_TX_TIMEOUT)) { */
  514. /* poll for TX_EMPTY INT - autorelease enabled */
  515. if (poll4int(dev, IM_TX_EMPTY_INT, SMC_TX_TIMEOUT)) {
  516. /* sending failed */
  517. PRINTK2 ("%s: TX timeout, sending failed...\n", SMC_DEV_NAME);
  518. /* release packet */
  519. /* no need to release, MMU does that now */
  520. #ifdef CONFIG_XAENIAX
  521. SMC_outw (dev, MC_FREEPKT, MMU_CMD_REG);
  522. #endif
  523. /* wait for MMU getting ready (low) */
  524. while (SMC_inw (dev, MMU_CMD_REG) & MC_BUSY) {
  525. udelay (10);
  526. }
  527. PRINTK2 ("MMU ready\n");
  528. return 0;
  529. } else {
  530. /* ack. int */
  531. SMC_outb (dev, IM_TX_EMPTY_INT, SMC91111_INT_REG);
  532. /* SMC_outb (IM_TX_INT, SMC91111_INT_REG); */
  533. PRINTK2 ("%s: Sent packet of length %d \n", SMC_DEV_NAME,
  534. length);
  535. /* release packet */
  536. /* no need to release, MMU does that now */
  537. #ifdef CONFIG_XAENIAX
  538. SMC_outw (dev, MC_FREEPKT, MMU_CMD_REG);
  539. #endif
  540. /* wait for MMU getting ready (low) */
  541. while (SMC_inw (dev, MMU_CMD_REG) & MC_BUSY) {
  542. udelay (10);
  543. }
  544. PRINTK2 ("MMU ready\n");
  545. }
  546. /* restore previously saved registers */
  547. #ifndef CONFIG_XAENIAX
  548. SMC_outb( dev, saved_pnr, PN_REG );
  549. #else
  550. /* On Xaeniax board, we can't use SMC_outb here because that way
  551. * the Allocate MMU command will end up written to the command register
  552. * as well, which will lead to a problem.
  553. */
  554. SMC_outl(dev, saved_pnr << 16, 0);
  555. #endif
  556. SMC_outw( dev, saved_ptr, PTR_REG );
  557. return length;
  558. }
  559. static int smc_write_hwaddr(struct eth_device *dev)
  560. {
  561. int i;
  562. swap_to(ETHERNET);
  563. SMC_SELECT_BANK (dev, 1);
  564. #ifdef USE_32_BIT
  565. for (i = 0; i < 6; i += 2) {
  566. word address;
  567. address = dev->enetaddr[i + 1] << 8;
  568. address |= dev->enetaddr[i];
  569. SMC_outw(dev, address, (ADDR0_REG + i));
  570. }
  571. #else
  572. for (i = 0; i < 6; i++)
  573. SMC_outb(dev, dev->enetaddr[i], (ADDR0_REG + i));
  574. #endif
  575. swap_to(FLASH);
  576. return 0;
  577. }
  578. /*
  579. * Open and Initialize the board
  580. *
  581. * Set up everything, reset the card, etc ..
  582. *
  583. */
  584. static int smc_init(struct eth_device *dev, bd_t *bd)
  585. {
  586. swap_to(ETHERNET);
  587. PRINTK2 ("%s: smc_init\n", SMC_DEV_NAME);
  588. /* reset the hardware */
  589. smc_reset (dev);
  590. smc_enable (dev);
  591. /* Configure the PHY */
  592. #ifndef CONFIG_SMC91111_EXT_PHY
  593. smc_phy_configure (dev);
  594. #endif
  595. /* conservative setting (10Mbps, HalfDuplex, no AutoNeg.) */
  596. /* SMC_SELECT_BANK(dev, 0); */
  597. /* SMC_outw(dev, 0, RPC_REG); */
  598. printf(SMC_DEV_NAME ": MAC %pM\n", dev->enetaddr);
  599. return 0;
  600. }
  601. /*-------------------------------------------------------------
  602. .
  603. . smc_rcv - receive a packet from the card
  604. .
  605. . There is ( at least ) a packet waiting to be read from
  606. . chip-memory.
  607. .
  608. . o Read the status
  609. . o If an error, record it
  610. . o otherwise, read in the packet
  611. --------------------------------------------------------------
  612. */
  613. static int smc_rcv(struct eth_device *dev)
  614. {
  615. int packet_number;
  616. word status;
  617. word packet_length;
  618. int is_error = 0;
  619. #ifdef USE_32_BIT
  620. dword stat_len;
  621. #endif
  622. byte saved_pnr;
  623. word saved_ptr;
  624. SMC_SELECT_BANK(dev, 2);
  625. /* save PTR and PTR registers */
  626. saved_pnr = SMC_inb( dev, PN_REG );
  627. saved_ptr = SMC_inw( dev, PTR_REG );
  628. packet_number = SMC_inw( dev, RXFIFO_REG );
  629. if ( packet_number & RXFIFO_REMPTY ) {
  630. return 0;
  631. }
  632. PRINTK3("%s: smc_rcv\n", SMC_DEV_NAME);
  633. /* start reading from the start of the packet */
  634. SMC_outw( dev, PTR_READ | PTR_RCV | PTR_AUTOINC, PTR_REG );
  635. /* First two words are status and packet_length */
  636. #ifdef USE_32_BIT
  637. stat_len = SMC_inl(dev, SMC91111_DATA_REG);
  638. status = stat_len & 0xffff;
  639. packet_length = stat_len >> 16;
  640. #else
  641. status = SMC_inw( dev, SMC91111_DATA_REG );
  642. packet_length = SMC_inw( dev, SMC91111_DATA_REG );
  643. #endif
  644. packet_length &= 0x07ff; /* mask off top bits */
  645. PRINTK2("RCV: STATUS %4x LENGTH %4x\n", status, packet_length );
  646. if ( !(status & RS_ERRORS ) ){
  647. /* Adjust for having already read the first two words */
  648. packet_length -= 4; /*4; */
  649. /* set odd length for bug in LAN91C111, */
  650. /* which never sets RS_ODDFRAME */
  651. /* TODO ? */
  652. #ifdef USE_32_BIT
  653. PRINTK3(" Reading %d dwords (and %d bytes) \n",
  654. packet_length >> 2, packet_length & 3 );
  655. /* QUESTION: Like in the TX routine, do I want
  656. to send the DWORDs or the bytes first, or some
  657. mixture. A mixture might improve already slow PIO
  658. performance */
  659. SMC_insl( dev, SMC91111_DATA_REG, NetRxPackets[0],
  660. packet_length >> 2 );
  661. /* read the left over bytes */
  662. if (packet_length & 3) {
  663. int i;
  664. byte *tail = (byte *)(NetRxPackets[0] +
  665. (packet_length & ~3));
  666. dword leftover = SMC_inl(dev, SMC91111_DATA_REG);
  667. for (i=0; i<(packet_length & 3); i++)
  668. *tail++ = (byte) (leftover >> (8*i)) & 0xff;
  669. }
  670. #else
  671. PRINTK3(" Reading %d words and %d byte(s) \n",
  672. (packet_length >> 1 ), packet_length & 1 );
  673. SMC_insw(dev, SMC91111_DATA_REG , NetRxPackets[0],
  674. packet_length >> 1);
  675. #endif /* USE_32_BIT */
  676. #if SMC_DEBUG > 2
  677. printf("Receiving Packet\n");
  678. print_packet( NetRxPackets[0], packet_length );
  679. #endif
  680. } else {
  681. /* error ... */
  682. /* TODO ? */
  683. is_error = 1;
  684. }
  685. while ( SMC_inw( dev, MMU_CMD_REG ) & MC_BUSY )
  686. udelay(1); /* Wait until not busy */
  687. /* error or good, tell the card to get rid of this packet */
  688. SMC_outw( dev, MC_RELEASE, MMU_CMD_REG );
  689. while ( SMC_inw( dev, MMU_CMD_REG ) & MC_BUSY )
  690. udelay(1); /* Wait until not busy */
  691. /* restore saved registers */
  692. #ifndef CONFIG_XAENIAX
  693. SMC_outb( dev, saved_pnr, PN_REG );
  694. #else
  695. /* On Xaeniax board, we can't use SMC_outb here because that way
  696. * the Allocate MMU command will end up written to the command register
  697. * as well, which will lead to a problem.
  698. */
  699. SMC_outl( dev, saved_pnr << 16, 0);
  700. #endif
  701. SMC_outw( dev, saved_ptr, PTR_REG );
  702. if (!is_error) {
  703. /* Pass the packet up to the protocol layers. */
  704. NetReceive(NetRxPackets[0], packet_length);
  705. return packet_length;
  706. } else {
  707. return 0;
  708. }
  709. }
  710. #if 0
  711. /*------------------------------------------------------------
  712. . Modify a bit in the LAN91C111 register set
  713. .-------------------------------------------------------------*/
  714. static word smc_modify_regbit(struct eth_device *dev, int bank, int ioaddr, int reg,
  715. unsigned int bit, int val)
  716. {
  717. word regval;
  718. SMC_SELECT_BANK( dev, bank );
  719. regval = SMC_inw( dev, reg );
  720. if (val)
  721. regval |= bit;
  722. else
  723. regval &= ~bit;
  724. SMC_outw( dev, regval, 0 );
  725. return(regval);
  726. }
  727. /*------------------------------------------------------------
  728. . Retrieve a bit in the LAN91C111 register set
  729. .-------------------------------------------------------------*/
  730. static int smc_get_regbit(struct eth_device *dev, int bank, int ioaddr, int reg, unsigned int bit)
  731. {
  732. SMC_SELECT_BANK( dev, bank );
  733. if ( SMC_inw( dev, reg ) & bit)
  734. return(1);
  735. else
  736. return(0);
  737. }
  738. /*------------------------------------------------------------
  739. . Modify a LAN91C111 register (word access only)
  740. .-------------------------------------------------------------*/
  741. static void smc_modify_reg(struct eth_device *dev, int bank, int ioaddr, int reg, word val)
  742. {
  743. SMC_SELECT_BANK( dev, bank );
  744. SMC_outw( dev, val, reg );
  745. }
  746. /*------------------------------------------------------------
  747. . Retrieve a LAN91C111 register (word access only)
  748. .-------------------------------------------------------------*/
  749. static int smc_get_reg(struct eth_device *dev, int bank, int ioaddr, int reg)
  750. {
  751. SMC_SELECT_BANK( dev, bank );
  752. return(SMC_inw( dev, reg ));
  753. }
  754. #endif /* 0 */
  755. /*---PHY CONTROL AND CONFIGURATION----------------------------------------- */
  756. #if (SMC_DEBUG > 2 )
  757. /*------------------------------------------------------------
  758. . Debugging function for viewing MII Management serial bitstream
  759. .-------------------------------------------------------------*/
  760. static void smc_dump_mii_stream (byte * bits, int size)
  761. {
  762. int i;
  763. printf ("BIT#:");
  764. for (i = 0; i < size; ++i) {
  765. printf ("%d", i % 10);
  766. }
  767. printf ("\nMDOE:");
  768. for (i = 0; i < size; ++i) {
  769. if (bits[i] & MII_MDOE)
  770. printf ("1");
  771. else
  772. printf ("0");
  773. }
  774. printf ("\nMDO :");
  775. for (i = 0; i < size; ++i) {
  776. if (bits[i] & MII_MDO)
  777. printf ("1");
  778. else
  779. printf ("0");
  780. }
  781. printf ("\nMDI :");
  782. for (i = 0; i < size; ++i) {
  783. if (bits[i] & MII_MDI)
  784. printf ("1");
  785. else
  786. printf ("0");
  787. }
  788. printf ("\n");
  789. }
  790. #endif
  791. /*------------------------------------------------------------
  792. . Reads a register from the MII Management serial interface
  793. .-------------------------------------------------------------*/
  794. #ifndef CONFIG_SMC91111_EXT_PHY
  795. static word smc_read_phy_register (struct eth_device *dev, byte phyreg)
  796. {
  797. int oldBank;
  798. int i;
  799. byte mask;
  800. word mii_reg;
  801. byte bits[64];
  802. int clk_idx = 0;
  803. int input_idx;
  804. word phydata;
  805. byte phyaddr = SMC_PHY_ADDR;
  806. /* 32 consecutive ones on MDO to establish sync */
  807. for (i = 0; i < 32; ++i)
  808. bits[clk_idx++] = MII_MDOE | MII_MDO;
  809. /* Start code <01> */
  810. bits[clk_idx++] = MII_MDOE;
  811. bits[clk_idx++] = MII_MDOE | MII_MDO;
  812. /* Read command <10> */
  813. bits[clk_idx++] = MII_MDOE | MII_MDO;
  814. bits[clk_idx++] = MII_MDOE;
  815. /* Output the PHY address, msb first */
  816. mask = (byte) 0x10;
  817. for (i = 0; i < 5; ++i) {
  818. if (phyaddr & mask)
  819. bits[clk_idx++] = MII_MDOE | MII_MDO;
  820. else
  821. bits[clk_idx++] = MII_MDOE;
  822. /* Shift to next lowest bit */
  823. mask >>= 1;
  824. }
  825. /* Output the phy register number, msb first */
  826. mask = (byte) 0x10;
  827. for (i = 0; i < 5; ++i) {
  828. if (phyreg & mask)
  829. bits[clk_idx++] = MII_MDOE | MII_MDO;
  830. else
  831. bits[clk_idx++] = MII_MDOE;
  832. /* Shift to next lowest bit */
  833. mask >>= 1;
  834. }
  835. /* Tristate and turnaround (2 bit times) */
  836. bits[clk_idx++] = 0;
  837. /*bits[clk_idx++] = 0; */
  838. /* Input starts at this bit time */
  839. input_idx = clk_idx;
  840. /* Will input 16 bits */
  841. for (i = 0; i < 16; ++i)
  842. bits[clk_idx++] = 0;
  843. /* Final clock bit */
  844. bits[clk_idx++] = 0;
  845. /* Save the current bank */
  846. oldBank = SMC_inw (dev, BANK_SELECT);
  847. /* Select bank 3 */
  848. SMC_SELECT_BANK (dev, 3);
  849. /* Get the current MII register value */
  850. mii_reg = SMC_inw (dev, MII_REG);
  851. /* Turn off all MII Interface bits */
  852. mii_reg &= ~(MII_MDOE | MII_MCLK | MII_MDI | MII_MDO);
  853. /* Clock all 64 cycles */
  854. for (i = 0; i < sizeof bits; ++i) {
  855. /* Clock Low - output data */
  856. SMC_outw (dev, mii_reg | bits[i], MII_REG);
  857. udelay (SMC_PHY_CLOCK_DELAY);
  858. /* Clock Hi - input data */
  859. SMC_outw (dev, mii_reg | bits[i] | MII_MCLK, MII_REG);
  860. udelay (SMC_PHY_CLOCK_DELAY);
  861. bits[i] |= SMC_inw (dev, MII_REG) & MII_MDI;
  862. }
  863. /* Return to idle state */
  864. /* Set clock to low, data to low, and output tristated */
  865. SMC_outw (dev, mii_reg, MII_REG);
  866. udelay (SMC_PHY_CLOCK_DELAY);
  867. /* Restore original bank select */
  868. SMC_SELECT_BANK (dev, oldBank);
  869. /* Recover input data */
  870. phydata = 0;
  871. for (i = 0; i < 16; ++i) {
  872. phydata <<= 1;
  873. if (bits[input_idx++] & MII_MDI)
  874. phydata |= 0x0001;
  875. }
  876. #if (SMC_DEBUG > 2 )
  877. printf ("smc_read_phy_register(): phyaddr=%x,phyreg=%x,phydata=%x\n",
  878. phyaddr, phyreg, phydata);
  879. smc_dump_mii_stream (bits, sizeof bits);
  880. #endif
  881. return (phydata);
  882. }
  883. /*------------------------------------------------------------
  884. . Writes a register to the MII Management serial interface
  885. .-------------------------------------------------------------*/
  886. static void smc_write_phy_register (struct eth_device *dev, byte phyreg,
  887. word phydata)
  888. {
  889. int oldBank;
  890. int i;
  891. word mask;
  892. word mii_reg;
  893. byte bits[65];
  894. int clk_idx = 0;
  895. byte phyaddr = SMC_PHY_ADDR;
  896. /* 32 consecutive ones on MDO to establish sync */
  897. for (i = 0; i < 32; ++i)
  898. bits[clk_idx++] = MII_MDOE | MII_MDO;
  899. /* Start code <01> */
  900. bits[clk_idx++] = MII_MDOE;
  901. bits[clk_idx++] = MII_MDOE | MII_MDO;
  902. /* Write command <01> */
  903. bits[clk_idx++] = MII_MDOE;
  904. bits[clk_idx++] = MII_MDOE | MII_MDO;
  905. /* Output the PHY address, msb first */
  906. mask = (byte) 0x10;
  907. for (i = 0; i < 5; ++i) {
  908. if (phyaddr & mask)
  909. bits[clk_idx++] = MII_MDOE | MII_MDO;
  910. else
  911. bits[clk_idx++] = MII_MDOE;
  912. /* Shift to next lowest bit */
  913. mask >>= 1;
  914. }
  915. /* Output the phy register number, msb first */
  916. mask = (byte) 0x10;
  917. for (i = 0; i < 5; ++i) {
  918. if (phyreg & mask)
  919. bits[clk_idx++] = MII_MDOE | MII_MDO;
  920. else
  921. bits[clk_idx++] = MII_MDOE;
  922. /* Shift to next lowest bit */
  923. mask >>= 1;
  924. }
  925. /* Tristate and turnaround (2 bit times) */
  926. bits[clk_idx++] = 0;
  927. bits[clk_idx++] = 0;
  928. /* Write out 16 bits of data, msb first */
  929. mask = 0x8000;
  930. for (i = 0; i < 16; ++i) {
  931. if (phydata & mask)
  932. bits[clk_idx++] = MII_MDOE | MII_MDO;
  933. else
  934. bits[clk_idx++] = MII_MDOE;
  935. /* Shift to next lowest bit */
  936. mask >>= 1;
  937. }
  938. /* Final clock bit (tristate) */
  939. bits[clk_idx++] = 0;
  940. /* Save the current bank */
  941. oldBank = SMC_inw (dev, BANK_SELECT);
  942. /* Select bank 3 */
  943. SMC_SELECT_BANK (dev, 3);
  944. /* Get the current MII register value */
  945. mii_reg = SMC_inw (dev, MII_REG);
  946. /* Turn off all MII Interface bits */
  947. mii_reg &= ~(MII_MDOE | MII_MCLK | MII_MDI | MII_MDO);
  948. /* Clock all cycles */
  949. for (i = 0; i < sizeof bits; ++i) {
  950. /* Clock Low - output data */
  951. SMC_outw (dev, mii_reg | bits[i], MII_REG);
  952. udelay (SMC_PHY_CLOCK_DELAY);
  953. /* Clock Hi - input data */
  954. SMC_outw (dev, mii_reg | bits[i] | MII_MCLK, MII_REG);
  955. udelay (SMC_PHY_CLOCK_DELAY);
  956. bits[i] |= SMC_inw (dev, MII_REG) & MII_MDI;
  957. }
  958. /* Return to idle state */
  959. /* Set clock to low, data to low, and output tristated */
  960. SMC_outw (dev, mii_reg, MII_REG);
  961. udelay (SMC_PHY_CLOCK_DELAY);
  962. /* Restore original bank select */
  963. SMC_SELECT_BANK (dev, oldBank);
  964. #if (SMC_DEBUG > 2 )
  965. printf ("smc_write_phy_register(): phyaddr=%x,phyreg=%x,phydata=%x\n",
  966. phyaddr, phyreg, phydata);
  967. smc_dump_mii_stream (bits, sizeof bits);
  968. #endif
  969. }
  970. #endif /* !CONFIG_SMC91111_EXT_PHY */
  971. /*------------------------------------------------------------
  972. . Waits the specified number of milliseconds - kernel friendly
  973. .-------------------------------------------------------------*/
  974. #ifndef CONFIG_SMC91111_EXT_PHY
  975. static void smc_wait_ms(unsigned int ms)
  976. {
  977. udelay(ms*1000);
  978. }
  979. #endif /* !CONFIG_SMC91111_EXT_PHY */
  980. /*------------------------------------------------------------
  981. . Configures the specified PHY using Autonegotiation. Calls
  982. . smc_phy_fixed() if the user has requested a certain config.
  983. .-------------------------------------------------------------*/
  984. #ifndef CONFIG_SMC91111_EXT_PHY
  985. static void smc_phy_configure (struct eth_device *dev)
  986. {
  987. int timeout;
  988. byte phyaddr;
  989. word my_phy_caps; /* My PHY capabilities */
  990. word my_ad_caps; /* My Advertised capabilities */
  991. word status = 0; /*;my status = 0 */
  992. int failed = 0;
  993. PRINTK3 ("%s: smc_program_phy()\n", SMC_DEV_NAME);
  994. /* Get the detected phy address */
  995. phyaddr = SMC_PHY_ADDR;
  996. /* Reset the PHY, setting all other bits to zero */
  997. smc_write_phy_register (dev, PHY_CNTL_REG, PHY_CNTL_RST);
  998. /* Wait for the reset to complete, or time out */
  999. timeout = 6; /* Wait up to 3 seconds */
  1000. while (timeout--) {
  1001. if (!(smc_read_phy_register (dev, PHY_CNTL_REG)
  1002. & PHY_CNTL_RST)) {
  1003. /* reset complete */
  1004. break;
  1005. }
  1006. smc_wait_ms (500); /* wait 500 millisecs */
  1007. }
  1008. if (timeout < 1) {
  1009. printf ("%s:PHY reset timed out\n", SMC_DEV_NAME);
  1010. goto smc_phy_configure_exit;
  1011. }
  1012. /* Read PHY Register 18, Status Output */
  1013. /* lp->lastPhy18 = smc_read_phy_register(PHY_INT_REG); */
  1014. /* Enable PHY Interrupts (for register 18) */
  1015. /* Interrupts listed here are disabled */
  1016. smc_write_phy_register (dev, PHY_MASK_REG, 0xffff);
  1017. /* Configure the Receive/Phy Control register */
  1018. SMC_SELECT_BANK (dev, 0);
  1019. SMC_outw (dev, RPC_DEFAULT, RPC_REG);
  1020. /* Copy our capabilities from PHY_STAT_REG to PHY_AD_REG */
  1021. my_phy_caps = smc_read_phy_register (dev, PHY_STAT_REG);
  1022. my_ad_caps = PHY_AD_CSMA; /* I am CSMA capable */
  1023. if (my_phy_caps & PHY_STAT_CAP_T4)
  1024. my_ad_caps |= PHY_AD_T4;
  1025. if (my_phy_caps & PHY_STAT_CAP_TXF)
  1026. my_ad_caps |= PHY_AD_TX_FDX;
  1027. if (my_phy_caps & PHY_STAT_CAP_TXH)
  1028. my_ad_caps |= PHY_AD_TX_HDX;
  1029. if (my_phy_caps & PHY_STAT_CAP_TF)
  1030. my_ad_caps |= PHY_AD_10_FDX;
  1031. if (my_phy_caps & PHY_STAT_CAP_TH)
  1032. my_ad_caps |= PHY_AD_10_HDX;
  1033. /* Update our Auto-Neg Advertisement Register */
  1034. smc_write_phy_register (dev, PHY_AD_REG, my_ad_caps);
  1035. /* Read the register back. Without this, it appears that when */
  1036. /* auto-negotiation is restarted, sometimes it isn't ready and */
  1037. /* the link does not come up. */
  1038. smc_read_phy_register(dev, PHY_AD_REG);
  1039. PRINTK2 ("%s: phy caps=%x\n", SMC_DEV_NAME, my_phy_caps);
  1040. PRINTK2 ("%s: phy advertised caps=%x\n", SMC_DEV_NAME, my_ad_caps);
  1041. /* Restart auto-negotiation process in order to advertise my caps */
  1042. smc_write_phy_register (dev, PHY_CNTL_REG,
  1043. PHY_CNTL_ANEG_EN | PHY_CNTL_ANEG_RST);
  1044. /* Wait for the auto-negotiation to complete. This may take from */
  1045. /* 2 to 3 seconds. */
  1046. /* Wait for the reset to complete, or time out */
  1047. timeout = CONFIG_SMC_AUTONEG_TIMEOUT * 2;
  1048. while (timeout--) {
  1049. status = smc_read_phy_register (dev, PHY_STAT_REG);
  1050. if (status & PHY_STAT_ANEG_ACK) {
  1051. /* auto-negotiate complete */
  1052. break;
  1053. }
  1054. smc_wait_ms (500); /* wait 500 millisecs */
  1055. /* Restart auto-negotiation if remote fault */
  1056. if (status & PHY_STAT_REM_FLT) {
  1057. printf ("%s: PHY remote fault detected\n",
  1058. SMC_DEV_NAME);
  1059. /* Restart auto-negotiation */
  1060. printf ("%s: PHY restarting auto-negotiation\n",
  1061. SMC_DEV_NAME);
  1062. smc_write_phy_register (dev, PHY_CNTL_REG,
  1063. PHY_CNTL_ANEG_EN |
  1064. PHY_CNTL_ANEG_RST |
  1065. PHY_CNTL_SPEED |
  1066. PHY_CNTL_DPLX);
  1067. }
  1068. }
  1069. if (timeout < 1) {
  1070. printf ("%s: PHY auto-negotiate timed out\n", SMC_DEV_NAME);
  1071. failed = 1;
  1072. }
  1073. /* Fail if we detected an auto-negotiate remote fault */
  1074. if (status & PHY_STAT_REM_FLT) {
  1075. printf ("%s: PHY remote fault detected\n", SMC_DEV_NAME);
  1076. failed = 1;
  1077. }
  1078. /* Re-Configure the Receive/Phy Control register */
  1079. SMC_outw (dev, RPC_DEFAULT, RPC_REG);
  1080. smc_phy_configure_exit: ;
  1081. }
  1082. #endif /* !CONFIG_SMC91111_EXT_PHY */
  1083. #if SMC_DEBUG > 2
  1084. static void print_packet( byte * buf, int length )
  1085. {
  1086. int i;
  1087. int remainder;
  1088. int lines;
  1089. printf("Packet of length %d \n", length );
  1090. #if SMC_DEBUG > 3
  1091. lines = length / 16;
  1092. remainder = length % 16;
  1093. for ( i = 0; i < lines ; i ++ ) {
  1094. int cur;
  1095. for ( cur = 0; cur < 8; cur ++ ) {
  1096. byte a, b;
  1097. a = *(buf ++ );
  1098. b = *(buf ++ );
  1099. printf("%02x%02x ", a, b );
  1100. }
  1101. printf("\n");
  1102. }
  1103. for ( i = 0; i < remainder/2 ; i++ ) {
  1104. byte a, b;
  1105. a = *(buf ++ );
  1106. b = *(buf ++ );
  1107. printf("%02x%02x ", a, b );
  1108. }
  1109. printf("\n");
  1110. #endif
  1111. }
  1112. #endif
  1113. int smc91111_initialize(u8 dev_num, int base_addr)
  1114. {
  1115. struct smc91111_priv *priv;
  1116. struct eth_device *dev;
  1117. int i;
  1118. priv = malloc(sizeof(*priv));
  1119. if (!priv)
  1120. return 0;
  1121. dev = malloc(sizeof(*dev));
  1122. if (!dev) {
  1123. free(priv);
  1124. return 0;
  1125. }
  1126. memset(dev, 0, sizeof(*dev));
  1127. priv->dev_num = dev_num;
  1128. dev->priv = priv;
  1129. dev->iobase = base_addr;
  1130. swap_to(ETHERNET);
  1131. SMC_SELECT_BANK(dev, 1);
  1132. for (i = 0; i < 6; ++i)
  1133. dev->enetaddr[i] = SMC_inb(dev, (ADDR0_REG + i));
  1134. swap_to(FLASH);
  1135. dev->init = smc_init;
  1136. dev->halt = smc_halt;
  1137. dev->send = smc_send;
  1138. dev->recv = smc_rcv;
  1139. dev->write_hwaddr = smc_write_hwaddr;
  1140. sprintf(dev->name, "%s-%hu", SMC_DEV_NAME, dev_num);
  1141. eth_register(dev);
  1142. return 0;
  1143. }