smc91111.c 34 KB

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