smc91111.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369
  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, void *packet, int packet_length)
  366. {
  367. byte packet_no;
  368. byte *buf;
  369. int length;
  370. int numPages;
  371. int try = 0;
  372. int time_out;
  373. byte status;
  374. byte saved_pnr;
  375. word saved_ptr;
  376. /* save PTR and PNR registers before manipulation */
  377. SMC_SELECT_BANK (dev, 2);
  378. saved_pnr = SMC_inb( dev, PN_REG );
  379. saved_ptr = SMC_inw( dev, PTR_REG );
  380. PRINTK3 ("%s: smc_hardware_send_packet\n", SMC_DEV_NAME);
  381. length = ETH_ZLEN < packet_length ? packet_length : ETH_ZLEN;
  382. /* allocate memory
  383. ** The MMU wants the number of pages to be the number of 256 bytes
  384. ** 'pages', minus 1 ( since a packet can't ever have 0 pages :) )
  385. **
  386. ** The 91C111 ignores the size bits, but the code is left intact
  387. ** for backwards and future compatibility.
  388. **
  389. ** Pkt size for allocating is data length +6 (for additional status
  390. ** words, length and ctl!)
  391. **
  392. ** If odd size then last byte is included in this header.
  393. */
  394. numPages = ((length & 0xfffe) + 6);
  395. numPages >>= 8; /* Divide by 256 */
  396. if (numPages > 7) {
  397. printf ("%s: Far too big packet error. \n", SMC_DEV_NAME);
  398. return 0;
  399. }
  400. /* now, try to allocate the memory */
  401. SMC_SELECT_BANK (dev, 2);
  402. SMC_outw (dev, MC_ALLOC | numPages, MMU_CMD_REG);
  403. /* FIXME: the ALLOC_INT bit never gets set *
  404. * so the following will always give a *
  405. * memory allocation error. *
  406. * same code works in armboot though *
  407. * -ro
  408. */
  409. again:
  410. try++;
  411. time_out = MEMORY_WAIT_TIME;
  412. do {
  413. status = SMC_inb (dev, SMC91111_INT_REG);
  414. if (status & IM_ALLOC_INT) {
  415. /* acknowledge the interrupt */
  416. SMC_outb (dev, IM_ALLOC_INT, SMC91111_INT_REG);
  417. break;
  418. }
  419. } while (--time_out);
  420. if (!time_out) {
  421. PRINTK2 ("%s: memory allocation, try %d failed ...\n",
  422. SMC_DEV_NAME, try);
  423. if (try < SMC_ALLOC_MAX_TRY)
  424. goto again;
  425. else
  426. return 0;
  427. }
  428. PRINTK2 ("%s: memory allocation, try %d succeeded ...\n",
  429. SMC_DEV_NAME, try);
  430. buf = (byte *) packet;
  431. /* If I get here, I _know_ there is a packet slot waiting for me */
  432. packet_no = SMC_inb (dev, AR_REG);
  433. if (packet_no & AR_FAILED) {
  434. /* or isn't there? BAD CHIP! */
  435. printf ("%s: Memory allocation failed. \n", SMC_DEV_NAME);
  436. return 0;
  437. }
  438. /* we have a packet address, so tell the card to use it */
  439. #ifndef CONFIG_XAENIAX
  440. SMC_outb (dev, packet_no, PN_REG);
  441. #else
  442. /* On Xaeniax board, we can't use SMC_outb here because that way
  443. * the Allocate MMU command will end up written to the command register
  444. * as well, which will lead to a problem.
  445. */
  446. SMC_outl (dev, packet_no << 16, 0);
  447. #endif
  448. /* do not write new ptr value if Write data fifo not empty */
  449. while ( saved_ptr & PTR_NOTEMPTY )
  450. printf ("Write data fifo not empty!\n");
  451. /* point to the beginning of the packet */
  452. SMC_outw (dev, PTR_AUTOINC, PTR_REG);
  453. PRINTK3 ("%s: Trying to xmit packet of length %x\n",
  454. SMC_DEV_NAME, length);
  455. #if SMC_DEBUG > 2
  456. printf ("Transmitting Packet\n");
  457. print_packet (buf, length);
  458. #endif
  459. /* send the packet length ( +6 for status, length and ctl byte )
  460. and the status word ( set to zeros ) */
  461. #ifdef USE_32_BIT
  462. SMC_outl (dev, (length + 6) << 16, SMC91111_DATA_REG);
  463. #else
  464. SMC_outw (dev, 0, SMC91111_DATA_REG);
  465. /* send the packet length ( +6 for status words, length, and ctl */
  466. SMC_outw (dev, (length + 6), SMC91111_DATA_REG);
  467. #endif
  468. /* send the actual data
  469. . I _think_ it's faster to send the longs first, and then
  470. . mop up by sending the last word. It depends heavily
  471. . on alignment, at least on the 486. Maybe it would be
  472. . a good idea to check which is optimal? But that could take
  473. . almost as much time as is saved?
  474. */
  475. #ifdef USE_32_BIT
  476. SMC_outsl (dev, SMC91111_DATA_REG, buf, length >> 2);
  477. #ifndef CONFIG_XAENIAX
  478. if (length & 0x2)
  479. SMC_outw (dev, *((word *) (buf + (length & 0xFFFFFFFC))),
  480. SMC91111_DATA_REG);
  481. #else
  482. /* On XANEIAX, we can only use 32-bit writes, so we need to handle
  483. * unaligned tail part specially. The standard code doesn't work.
  484. */
  485. if ((length & 3) == 3) {
  486. u16 * ptr = (u16*) &buf[length-3];
  487. SMC_outl(dev, (*ptr) | ((0x2000 | buf[length-1]) << 16),
  488. SMC91111_DATA_REG);
  489. } else if ((length & 2) == 2) {
  490. u16 * ptr = (u16*) &buf[length-2];
  491. SMC_outl(dev, *ptr, SMC91111_DATA_REG);
  492. } else if (length & 1) {
  493. SMC_outl(dev, (0x2000 | buf[length-1]), SMC91111_DATA_REG);
  494. } else {
  495. SMC_outl(dev, 0, SMC91111_DATA_REG);
  496. }
  497. #endif
  498. #else
  499. SMC_outsw (dev, SMC91111_DATA_REG, buf, (length) >> 1);
  500. #endif /* USE_32_BIT */
  501. #ifndef CONFIG_XAENIAX
  502. /* Send the last byte, if there is one. */
  503. if ((length & 1) == 0) {
  504. SMC_outw (dev, 0, SMC91111_DATA_REG);
  505. } else {
  506. SMC_outw (dev, buf[length - 1] | 0x2000, SMC91111_DATA_REG);
  507. }
  508. #endif
  509. /* and let the chipset deal with it */
  510. SMC_outw (dev, MC_ENQUEUE, MMU_CMD_REG);
  511. /* poll for TX INT */
  512. /* if (poll4int (dev, IM_TX_INT, SMC_TX_TIMEOUT)) { */
  513. /* poll for TX_EMPTY INT - autorelease enabled */
  514. if (poll4int(dev, IM_TX_EMPTY_INT, SMC_TX_TIMEOUT)) {
  515. /* sending failed */
  516. PRINTK2 ("%s: TX timeout, sending failed...\n", SMC_DEV_NAME);
  517. /* release packet */
  518. /* no need to release, MMU does that now */
  519. #ifdef CONFIG_XAENIAX
  520. SMC_outw (dev, MC_FREEPKT, MMU_CMD_REG);
  521. #endif
  522. /* wait for MMU getting ready (low) */
  523. while (SMC_inw (dev, MMU_CMD_REG) & MC_BUSY) {
  524. udelay (10);
  525. }
  526. PRINTK2 ("MMU ready\n");
  527. return 0;
  528. } else {
  529. /* ack. int */
  530. SMC_outb (dev, IM_TX_EMPTY_INT, SMC91111_INT_REG);
  531. /* SMC_outb (IM_TX_INT, SMC91111_INT_REG); */
  532. PRINTK2 ("%s: Sent packet of length %d \n", SMC_DEV_NAME,
  533. length);
  534. /* release packet */
  535. /* no need to release, MMU does that now */
  536. #ifdef CONFIG_XAENIAX
  537. SMC_outw (dev, MC_FREEPKT, MMU_CMD_REG);
  538. #endif
  539. /* wait for MMU getting ready (low) */
  540. while (SMC_inw (dev, MMU_CMD_REG) & MC_BUSY) {
  541. udelay (10);
  542. }
  543. PRINTK2 ("MMU ready\n");
  544. }
  545. /* restore previously saved registers */
  546. #ifndef CONFIG_XAENIAX
  547. SMC_outb( dev, saved_pnr, PN_REG );
  548. #else
  549. /* On Xaeniax board, we can't use SMC_outb here because that way
  550. * the Allocate MMU command will end up written to the command register
  551. * as well, which will lead to a problem.
  552. */
  553. SMC_outl(dev, saved_pnr << 16, 0);
  554. #endif
  555. SMC_outw( dev, saved_ptr, PTR_REG );
  556. return length;
  557. }
  558. static int smc_write_hwaddr(struct eth_device *dev)
  559. {
  560. int i;
  561. swap_to(ETHERNET);
  562. SMC_SELECT_BANK (dev, 1);
  563. #ifdef USE_32_BIT
  564. for (i = 0; i < 6; i += 2) {
  565. word address;
  566. address = dev->enetaddr[i + 1] << 8;
  567. address |= dev->enetaddr[i];
  568. SMC_outw(dev, address, (ADDR0_REG + i));
  569. }
  570. #else
  571. for (i = 0; i < 6; i++)
  572. SMC_outb(dev, dev->enetaddr[i], (ADDR0_REG + i));
  573. #endif
  574. swap_to(FLASH);
  575. return 0;
  576. }
  577. /*
  578. * Open and Initialize the board
  579. *
  580. * Set up everything, reset the card, etc ..
  581. *
  582. */
  583. static int smc_init(struct eth_device *dev, bd_t *bd)
  584. {
  585. swap_to(ETHERNET);
  586. PRINTK2 ("%s: smc_init\n", SMC_DEV_NAME);
  587. /* reset the hardware */
  588. smc_reset (dev);
  589. smc_enable (dev);
  590. /* Configure the PHY */
  591. #ifndef CONFIG_SMC91111_EXT_PHY
  592. smc_phy_configure (dev);
  593. #endif
  594. /* conservative setting (10Mbps, HalfDuplex, no AutoNeg.) */
  595. /* SMC_SELECT_BANK(dev, 0); */
  596. /* SMC_outw(dev, 0, RPC_REG); */
  597. printf(SMC_DEV_NAME ": MAC %pM\n", dev->enetaddr);
  598. return 0;
  599. }
  600. /*-------------------------------------------------------------
  601. .
  602. . smc_rcv - receive a packet from the card
  603. .
  604. . There is ( at least ) a packet waiting to be read from
  605. . chip-memory.
  606. .
  607. . o Read the status
  608. . o If an error, record it
  609. . o otherwise, read in the packet
  610. --------------------------------------------------------------
  611. */
  612. static int smc_rcv(struct eth_device *dev)
  613. {
  614. int packet_number;
  615. word status;
  616. word packet_length;
  617. int is_error = 0;
  618. #ifdef USE_32_BIT
  619. dword stat_len;
  620. #endif
  621. byte saved_pnr;
  622. word saved_ptr;
  623. SMC_SELECT_BANK(dev, 2);
  624. /* save PTR and PTR registers */
  625. saved_pnr = SMC_inb( dev, PN_REG );
  626. saved_ptr = SMC_inw( dev, PTR_REG );
  627. packet_number = SMC_inw( dev, RXFIFO_REG );
  628. if ( packet_number & RXFIFO_REMPTY ) {
  629. return 0;
  630. }
  631. PRINTK3("%s: smc_rcv\n", SMC_DEV_NAME);
  632. /* start reading from the start of the packet */
  633. SMC_outw( dev, PTR_READ | PTR_RCV | PTR_AUTOINC, PTR_REG );
  634. /* First two words are status and packet_length */
  635. #ifdef USE_32_BIT
  636. stat_len = SMC_inl(dev, SMC91111_DATA_REG);
  637. status = stat_len & 0xffff;
  638. packet_length = stat_len >> 16;
  639. #else
  640. status = SMC_inw( dev, SMC91111_DATA_REG );
  641. packet_length = SMC_inw( dev, SMC91111_DATA_REG );
  642. #endif
  643. packet_length &= 0x07ff; /* mask off top bits */
  644. PRINTK2("RCV: STATUS %4x LENGTH %4x\n", status, packet_length );
  645. if ( !(status & RS_ERRORS ) ){
  646. /* Adjust for having already read the first two words */
  647. packet_length -= 4; /*4; */
  648. /* set odd length for bug in LAN91C111, */
  649. /* which never sets RS_ODDFRAME */
  650. /* TODO ? */
  651. #ifdef USE_32_BIT
  652. PRINTK3(" Reading %d dwords (and %d bytes) \n",
  653. packet_length >> 2, packet_length & 3 );
  654. /* QUESTION: Like in the TX routine, do I want
  655. to send the DWORDs or the bytes first, or some
  656. mixture. A mixture might improve already slow PIO
  657. performance */
  658. SMC_insl( dev, SMC91111_DATA_REG, NetRxPackets[0],
  659. packet_length >> 2 );
  660. /* read the left over bytes */
  661. if (packet_length & 3) {
  662. int i;
  663. byte *tail = (byte *)(NetRxPackets[0] +
  664. (packet_length & ~3));
  665. dword leftover = SMC_inl(dev, SMC91111_DATA_REG);
  666. for (i=0; i<(packet_length & 3); i++)
  667. *tail++ = (byte) (leftover >> (8*i)) & 0xff;
  668. }
  669. #else
  670. PRINTK3(" Reading %d words and %d byte(s) \n",
  671. (packet_length >> 1 ), packet_length & 1 );
  672. SMC_insw(dev, SMC91111_DATA_REG , NetRxPackets[0],
  673. packet_length >> 1);
  674. #endif /* USE_32_BIT */
  675. #if SMC_DEBUG > 2
  676. printf("Receiving Packet\n");
  677. print_packet( NetRxPackets[0], packet_length );
  678. #endif
  679. } else {
  680. /* error ... */
  681. /* TODO ? */
  682. is_error = 1;
  683. }
  684. while ( SMC_inw( dev, MMU_CMD_REG ) & MC_BUSY )
  685. udelay(1); /* Wait until not busy */
  686. /* error or good, tell the card to get rid of this packet */
  687. SMC_outw( dev, MC_RELEASE, MMU_CMD_REG );
  688. while ( SMC_inw( dev, MMU_CMD_REG ) & MC_BUSY )
  689. udelay(1); /* Wait until not busy */
  690. /* restore saved registers */
  691. #ifndef CONFIG_XAENIAX
  692. SMC_outb( dev, saved_pnr, PN_REG );
  693. #else
  694. /* On Xaeniax board, we can't use SMC_outb here because that way
  695. * the Allocate MMU command will end up written to the command register
  696. * as well, which will lead to a problem.
  697. */
  698. SMC_outl( dev, saved_pnr << 16, 0);
  699. #endif
  700. SMC_outw( dev, saved_ptr, PTR_REG );
  701. if (!is_error) {
  702. /* Pass the packet up to the protocol layers. */
  703. NetReceive(NetRxPackets[0], packet_length);
  704. return packet_length;
  705. } else {
  706. return 0;
  707. }
  708. }
  709. #if 0
  710. /*------------------------------------------------------------
  711. . Modify a bit in the LAN91C111 register set
  712. .-------------------------------------------------------------*/
  713. static word smc_modify_regbit(struct eth_device *dev, int bank, int ioaddr, int reg,
  714. unsigned int bit, int val)
  715. {
  716. word regval;
  717. SMC_SELECT_BANK( dev, bank );
  718. regval = SMC_inw( dev, reg );
  719. if (val)
  720. regval |= bit;
  721. else
  722. regval &= ~bit;
  723. SMC_outw( dev, regval, 0 );
  724. return(regval);
  725. }
  726. /*------------------------------------------------------------
  727. . Retrieve a bit in the LAN91C111 register set
  728. .-------------------------------------------------------------*/
  729. static int smc_get_regbit(struct eth_device *dev, int bank, int ioaddr, int reg, unsigned int bit)
  730. {
  731. SMC_SELECT_BANK( dev, bank );
  732. if ( SMC_inw( dev, reg ) & bit)
  733. return(1);
  734. else
  735. return(0);
  736. }
  737. /*------------------------------------------------------------
  738. . Modify a LAN91C111 register (word access only)
  739. .-------------------------------------------------------------*/
  740. static void smc_modify_reg(struct eth_device *dev, int bank, int ioaddr, int reg, word val)
  741. {
  742. SMC_SELECT_BANK( dev, bank );
  743. SMC_outw( dev, val, reg );
  744. }
  745. /*------------------------------------------------------------
  746. . Retrieve a LAN91C111 register (word access only)
  747. .-------------------------------------------------------------*/
  748. static int smc_get_reg(struct eth_device *dev, int bank, int ioaddr, int reg)
  749. {
  750. SMC_SELECT_BANK( dev, bank );
  751. return(SMC_inw( dev, reg ));
  752. }
  753. #endif /* 0 */
  754. /*---PHY CONTROL AND CONFIGURATION----------------------------------------- */
  755. #if (SMC_DEBUG > 2 )
  756. /*------------------------------------------------------------
  757. . Debugging function for viewing MII Management serial bitstream
  758. .-------------------------------------------------------------*/
  759. static void smc_dump_mii_stream (byte * bits, int size)
  760. {
  761. int i;
  762. printf ("BIT#:");
  763. for (i = 0; i < size; ++i) {
  764. printf ("%d", i % 10);
  765. }
  766. printf ("\nMDOE:");
  767. for (i = 0; i < size; ++i) {
  768. if (bits[i] & MII_MDOE)
  769. printf ("1");
  770. else
  771. printf ("0");
  772. }
  773. printf ("\nMDO :");
  774. for (i = 0; i < size; ++i) {
  775. if (bits[i] & MII_MDO)
  776. printf ("1");
  777. else
  778. printf ("0");
  779. }
  780. printf ("\nMDI :");
  781. for (i = 0; i < size; ++i) {
  782. if (bits[i] & MII_MDI)
  783. printf ("1");
  784. else
  785. printf ("0");
  786. }
  787. printf ("\n");
  788. }
  789. #endif
  790. /*------------------------------------------------------------
  791. . Reads a register from the MII Management serial interface
  792. .-------------------------------------------------------------*/
  793. #ifndef CONFIG_SMC91111_EXT_PHY
  794. static word smc_read_phy_register (struct eth_device *dev, byte phyreg)
  795. {
  796. int oldBank;
  797. int i;
  798. byte mask;
  799. word mii_reg;
  800. byte bits[64];
  801. int clk_idx = 0;
  802. int input_idx;
  803. word phydata;
  804. byte phyaddr = SMC_PHY_ADDR;
  805. /* 32 consecutive ones on MDO to establish sync */
  806. for (i = 0; i < 32; ++i)
  807. bits[clk_idx++] = MII_MDOE | MII_MDO;
  808. /* Start code <01> */
  809. bits[clk_idx++] = MII_MDOE;
  810. bits[clk_idx++] = MII_MDOE | MII_MDO;
  811. /* Read command <10> */
  812. bits[clk_idx++] = MII_MDOE | MII_MDO;
  813. bits[clk_idx++] = MII_MDOE;
  814. /* Output the PHY address, msb first */
  815. mask = (byte) 0x10;
  816. for (i = 0; i < 5; ++i) {
  817. if (phyaddr & mask)
  818. bits[clk_idx++] = MII_MDOE | MII_MDO;
  819. else
  820. bits[clk_idx++] = MII_MDOE;
  821. /* Shift to next lowest bit */
  822. mask >>= 1;
  823. }
  824. /* Output the phy register number, msb first */
  825. mask = (byte) 0x10;
  826. for (i = 0; i < 5; ++i) {
  827. if (phyreg & mask)
  828. bits[clk_idx++] = MII_MDOE | MII_MDO;
  829. else
  830. bits[clk_idx++] = MII_MDOE;
  831. /* Shift to next lowest bit */
  832. mask >>= 1;
  833. }
  834. /* Tristate and turnaround (2 bit times) */
  835. bits[clk_idx++] = 0;
  836. /*bits[clk_idx++] = 0; */
  837. /* Input starts at this bit time */
  838. input_idx = clk_idx;
  839. /* Will input 16 bits */
  840. for (i = 0; i < 16; ++i)
  841. bits[clk_idx++] = 0;
  842. /* Final clock bit */
  843. bits[clk_idx++] = 0;
  844. /* Save the current bank */
  845. oldBank = SMC_inw (dev, BANK_SELECT);
  846. /* Select bank 3 */
  847. SMC_SELECT_BANK (dev, 3);
  848. /* Get the current MII register value */
  849. mii_reg = SMC_inw (dev, MII_REG);
  850. /* Turn off all MII Interface bits */
  851. mii_reg &= ~(MII_MDOE | MII_MCLK | MII_MDI | MII_MDO);
  852. /* Clock all 64 cycles */
  853. for (i = 0; i < sizeof bits; ++i) {
  854. /* Clock Low - output data */
  855. SMC_outw (dev, mii_reg | bits[i], MII_REG);
  856. udelay (SMC_PHY_CLOCK_DELAY);
  857. /* Clock Hi - input data */
  858. SMC_outw (dev, mii_reg | bits[i] | MII_MCLK, MII_REG);
  859. udelay (SMC_PHY_CLOCK_DELAY);
  860. bits[i] |= SMC_inw (dev, MII_REG) & MII_MDI;
  861. }
  862. /* Return to idle state */
  863. /* Set clock to low, data to low, and output tristated */
  864. SMC_outw (dev, mii_reg, MII_REG);
  865. udelay (SMC_PHY_CLOCK_DELAY);
  866. /* Restore original bank select */
  867. SMC_SELECT_BANK (dev, oldBank);
  868. /* Recover input data */
  869. phydata = 0;
  870. for (i = 0; i < 16; ++i) {
  871. phydata <<= 1;
  872. if (bits[input_idx++] & MII_MDI)
  873. phydata |= 0x0001;
  874. }
  875. #if (SMC_DEBUG > 2 )
  876. printf ("smc_read_phy_register(): phyaddr=%x,phyreg=%x,phydata=%x\n",
  877. phyaddr, phyreg, phydata);
  878. smc_dump_mii_stream (bits, sizeof bits);
  879. #endif
  880. return (phydata);
  881. }
  882. /*------------------------------------------------------------
  883. . Writes a register to the MII Management serial interface
  884. .-------------------------------------------------------------*/
  885. static void smc_write_phy_register (struct eth_device *dev, byte phyreg,
  886. word phydata)
  887. {
  888. int oldBank;
  889. int i;
  890. word mask;
  891. word mii_reg;
  892. byte bits[65];
  893. int clk_idx = 0;
  894. byte phyaddr = SMC_PHY_ADDR;
  895. /* 32 consecutive ones on MDO to establish sync */
  896. for (i = 0; i < 32; ++i)
  897. bits[clk_idx++] = MII_MDOE | MII_MDO;
  898. /* Start code <01> */
  899. bits[clk_idx++] = MII_MDOE;
  900. bits[clk_idx++] = MII_MDOE | MII_MDO;
  901. /* Write command <01> */
  902. bits[clk_idx++] = MII_MDOE;
  903. bits[clk_idx++] = MII_MDOE | MII_MDO;
  904. /* Output the PHY address, msb first */
  905. mask = (byte) 0x10;
  906. for (i = 0; i < 5; ++i) {
  907. if (phyaddr & mask)
  908. bits[clk_idx++] = MII_MDOE | MII_MDO;
  909. else
  910. bits[clk_idx++] = MII_MDOE;
  911. /* Shift to next lowest bit */
  912. mask >>= 1;
  913. }
  914. /* Output the phy register number, msb first */
  915. mask = (byte) 0x10;
  916. for (i = 0; i < 5; ++i) {
  917. if (phyreg & mask)
  918. bits[clk_idx++] = MII_MDOE | MII_MDO;
  919. else
  920. bits[clk_idx++] = MII_MDOE;
  921. /* Shift to next lowest bit */
  922. mask >>= 1;
  923. }
  924. /* Tristate and turnaround (2 bit times) */
  925. bits[clk_idx++] = 0;
  926. bits[clk_idx++] = 0;
  927. /* Write out 16 bits of data, msb first */
  928. mask = 0x8000;
  929. for (i = 0; i < 16; ++i) {
  930. if (phydata & mask)
  931. bits[clk_idx++] = MII_MDOE | MII_MDO;
  932. else
  933. bits[clk_idx++] = MII_MDOE;
  934. /* Shift to next lowest bit */
  935. mask >>= 1;
  936. }
  937. /* Final clock bit (tristate) */
  938. bits[clk_idx++] = 0;
  939. /* Save the current bank */
  940. oldBank = SMC_inw (dev, BANK_SELECT);
  941. /* Select bank 3 */
  942. SMC_SELECT_BANK (dev, 3);
  943. /* Get the current MII register value */
  944. mii_reg = SMC_inw (dev, MII_REG);
  945. /* Turn off all MII Interface bits */
  946. mii_reg &= ~(MII_MDOE | MII_MCLK | MII_MDI | MII_MDO);
  947. /* Clock all cycles */
  948. for (i = 0; i < sizeof bits; ++i) {
  949. /* Clock Low - output data */
  950. SMC_outw (dev, mii_reg | bits[i], MII_REG);
  951. udelay (SMC_PHY_CLOCK_DELAY);
  952. /* Clock Hi - input data */
  953. SMC_outw (dev, mii_reg | bits[i] | MII_MCLK, MII_REG);
  954. udelay (SMC_PHY_CLOCK_DELAY);
  955. bits[i] |= SMC_inw (dev, MII_REG) & MII_MDI;
  956. }
  957. /* Return to idle state */
  958. /* Set clock to low, data to low, and output tristated */
  959. SMC_outw (dev, mii_reg, MII_REG);
  960. udelay (SMC_PHY_CLOCK_DELAY);
  961. /* Restore original bank select */
  962. SMC_SELECT_BANK (dev, oldBank);
  963. #if (SMC_DEBUG > 2 )
  964. printf ("smc_write_phy_register(): phyaddr=%x,phyreg=%x,phydata=%x\n",
  965. phyaddr, phyreg, phydata);
  966. smc_dump_mii_stream (bits, sizeof bits);
  967. #endif
  968. }
  969. #endif /* !CONFIG_SMC91111_EXT_PHY */
  970. /*------------------------------------------------------------
  971. . Configures the specified PHY using Autonegotiation. Calls
  972. . smc_phy_fixed() if the user has requested a certain config.
  973. .-------------------------------------------------------------*/
  974. #ifndef CONFIG_SMC91111_EXT_PHY
  975. static void smc_phy_configure (struct eth_device *dev)
  976. {
  977. int timeout;
  978. word my_phy_caps; /* My PHY capabilities */
  979. word my_ad_caps; /* My Advertised capabilities */
  980. word status = 0; /*;my status = 0 */
  981. PRINTK3 ("%s: smc_program_phy()\n", SMC_DEV_NAME);
  982. /* Reset the PHY, setting all other bits to zero */
  983. smc_write_phy_register (dev, PHY_CNTL_REG, PHY_CNTL_RST);
  984. /* Wait for the reset to complete, or time out */
  985. timeout = 6; /* Wait up to 3 seconds */
  986. while (timeout--) {
  987. if (!(smc_read_phy_register (dev, PHY_CNTL_REG)
  988. & PHY_CNTL_RST)) {
  989. /* reset complete */
  990. break;
  991. }
  992. mdelay(500); /* wait 500 millisecs */
  993. }
  994. if (timeout < 1) {
  995. printf ("%s:PHY reset timed out\n", SMC_DEV_NAME);
  996. goto smc_phy_configure_exit;
  997. }
  998. /* Read PHY Register 18, Status Output */
  999. /* lp->lastPhy18 = smc_read_phy_register(PHY_INT_REG); */
  1000. /* Enable PHY Interrupts (for register 18) */
  1001. /* Interrupts listed here are disabled */
  1002. smc_write_phy_register (dev, PHY_MASK_REG, 0xffff);
  1003. /* Configure the Receive/Phy Control register */
  1004. SMC_SELECT_BANK (dev, 0);
  1005. SMC_outw (dev, RPC_DEFAULT, RPC_REG);
  1006. /* Copy our capabilities from PHY_STAT_REG to PHY_AD_REG */
  1007. my_phy_caps = smc_read_phy_register (dev, PHY_STAT_REG);
  1008. my_ad_caps = PHY_AD_CSMA; /* I am CSMA capable */
  1009. if (my_phy_caps & PHY_STAT_CAP_T4)
  1010. my_ad_caps |= PHY_AD_T4;
  1011. if (my_phy_caps & PHY_STAT_CAP_TXF)
  1012. my_ad_caps |= PHY_AD_TX_FDX;
  1013. if (my_phy_caps & PHY_STAT_CAP_TXH)
  1014. my_ad_caps |= PHY_AD_TX_HDX;
  1015. if (my_phy_caps & PHY_STAT_CAP_TF)
  1016. my_ad_caps |= PHY_AD_10_FDX;
  1017. if (my_phy_caps & PHY_STAT_CAP_TH)
  1018. my_ad_caps |= PHY_AD_10_HDX;
  1019. /* Update our Auto-Neg Advertisement Register */
  1020. smc_write_phy_register (dev, PHY_AD_REG, my_ad_caps);
  1021. /* Read the register back. Without this, it appears that when */
  1022. /* auto-negotiation is restarted, sometimes it isn't ready and */
  1023. /* the link does not come up. */
  1024. smc_read_phy_register(dev, PHY_AD_REG);
  1025. PRINTK2 ("%s: phy caps=%x\n", SMC_DEV_NAME, my_phy_caps);
  1026. PRINTK2 ("%s: phy advertised caps=%x\n", SMC_DEV_NAME, my_ad_caps);
  1027. /* Restart auto-negotiation process in order to advertise my caps */
  1028. smc_write_phy_register (dev, PHY_CNTL_REG,
  1029. PHY_CNTL_ANEG_EN | PHY_CNTL_ANEG_RST);
  1030. /* Wait for the auto-negotiation to complete. This may take from */
  1031. /* 2 to 3 seconds. */
  1032. /* Wait for the reset to complete, or time out */
  1033. timeout = CONFIG_SMC_AUTONEG_TIMEOUT * 2;
  1034. while (timeout--) {
  1035. status = smc_read_phy_register (dev, PHY_STAT_REG);
  1036. if (status & PHY_STAT_ANEG_ACK) {
  1037. /* auto-negotiate complete */
  1038. break;
  1039. }
  1040. mdelay(500); /* wait 500 millisecs */
  1041. /* Restart auto-negotiation if remote fault */
  1042. if (status & PHY_STAT_REM_FLT) {
  1043. printf ("%s: PHY remote fault detected\n",
  1044. SMC_DEV_NAME);
  1045. /* Restart auto-negotiation */
  1046. printf ("%s: PHY restarting auto-negotiation\n",
  1047. SMC_DEV_NAME);
  1048. smc_write_phy_register (dev, PHY_CNTL_REG,
  1049. PHY_CNTL_ANEG_EN |
  1050. PHY_CNTL_ANEG_RST |
  1051. PHY_CNTL_SPEED |
  1052. PHY_CNTL_DPLX);
  1053. }
  1054. }
  1055. if (timeout < 1) {
  1056. printf ("%s: PHY auto-negotiate timed out\n", SMC_DEV_NAME);
  1057. }
  1058. /* Fail if we detected an auto-negotiate remote fault */
  1059. if (status & PHY_STAT_REM_FLT) {
  1060. printf ("%s: PHY remote fault detected\n", SMC_DEV_NAME);
  1061. }
  1062. /* Re-Configure the Receive/Phy Control register */
  1063. SMC_outw (dev, RPC_DEFAULT, RPC_REG);
  1064. smc_phy_configure_exit: ;
  1065. }
  1066. #endif /* !CONFIG_SMC91111_EXT_PHY */
  1067. #if SMC_DEBUG > 2
  1068. static void print_packet( byte * buf, int length )
  1069. {
  1070. int i;
  1071. int remainder;
  1072. int lines;
  1073. printf("Packet of length %d \n", length );
  1074. #if SMC_DEBUG > 3
  1075. lines = length / 16;
  1076. remainder = length % 16;
  1077. for ( i = 0; i < lines ; i ++ ) {
  1078. int cur;
  1079. for ( cur = 0; cur < 8; cur ++ ) {
  1080. byte a, b;
  1081. a = *(buf ++ );
  1082. b = *(buf ++ );
  1083. printf("%02x%02x ", a, b );
  1084. }
  1085. printf("\n");
  1086. }
  1087. for ( i = 0; i < remainder/2 ; i++ ) {
  1088. byte a, b;
  1089. a = *(buf ++ );
  1090. b = *(buf ++ );
  1091. printf("%02x%02x ", a, b );
  1092. }
  1093. printf("\n");
  1094. #endif
  1095. }
  1096. #endif
  1097. int smc91111_initialize(u8 dev_num, int base_addr)
  1098. {
  1099. struct smc91111_priv *priv;
  1100. struct eth_device *dev;
  1101. int i;
  1102. priv = malloc(sizeof(*priv));
  1103. if (!priv)
  1104. return 0;
  1105. dev = malloc(sizeof(*dev));
  1106. if (!dev) {
  1107. free(priv);
  1108. return 0;
  1109. }
  1110. memset(dev, 0, sizeof(*dev));
  1111. priv->dev_num = dev_num;
  1112. dev->priv = priv;
  1113. dev->iobase = base_addr;
  1114. swap_to(ETHERNET);
  1115. SMC_SELECT_BANK(dev, 1);
  1116. for (i = 0; i < 6; ++i)
  1117. dev->enetaddr[i] = SMC_inb(dev, (ADDR0_REG + i));
  1118. swap_to(FLASH);
  1119. dev->init = smc_init;
  1120. dev->halt = smc_halt;
  1121. dev->send = smc_send;
  1122. dev->recv = smc_rcv;
  1123. dev->write_hwaddr = smc_write_hwaddr;
  1124. sprintf(dev->name, "%s-%hu", SMC_DEV_NAME, dev_num);
  1125. eth_register(dev);
  1126. return 0;
  1127. }