smc91111.c 33 KB

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