lan91c96.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855
  1. /*------------------------------------------------------------------------
  2. * lan91c96.c
  3. * This is a driver for SMSC's LAN91C96 single-chip Ethernet device, based
  4. * on the SMC91111 driver from U-boot.
  5. *
  6. * (C) Copyright 2002
  7. * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  8. * Rolf Offermanns <rof@sysgo.de>
  9. *
  10. * Copyright (C) 2001 Standard Microsystems Corporation (SMSC)
  11. * Developed by Simple Network Magic Corporation (SNMC)
  12. * Copyright (C) 1996 by Erik Stahlman (ES)
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 2 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  27. *
  28. * Information contained in this file was obtained from the LAN91C96
  29. * manual from SMC. To get a copy, if you really want one, you can find
  30. * information under www.smsc.com.
  31. *
  32. *
  33. * "Features" of the SMC chip:
  34. * 6144 byte packet memory. ( for the 91C96 )
  35. * EEPROM for configuration
  36. * AUI/TP selection ( mine has 10Base2/10BaseT select )
  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 LAN91C96 databook (www.smsc.com)
  51. * o smc91111.c (u-boot driver)
  52. * o smc9194.c (linux kernel driver)
  53. * o lan91c96.c (Intel Diagnostic Manager driver)
  54. *
  55. * History:
  56. * 04/30/03 Mathijs Haarman Modified smc91111.c (u-boot version)
  57. * for lan91c96
  58. *---------------------------------------------------------------------------
  59. */
  60. #include <common.h>
  61. #include <command.h>
  62. #include "lan91c96.h"
  63. #include <net.h>
  64. #ifdef CONFIG_DRIVER_LAN91C96
  65. #if (CONFIG_COMMANDS & CFG_CMD_NET)
  66. /*------------------------------------------------------------------------
  67. *
  68. * Configuration options, for the experienced user to change.
  69. *
  70. -------------------------------------------------------------------------*/
  71. /* Use power-down feature of the chip */
  72. #define POWER_DOWN 0
  73. /*
  74. * Wait time for memory to be free. This probably shouldn't be
  75. * tuned that much, as waiting for this means nothing else happens
  76. * in the system
  77. */
  78. #define MEMORY_WAIT_TIME 16
  79. #define SMC_DEBUG 0
  80. #if (SMC_DEBUG > 2 )
  81. #define PRINTK3(args...) printf(args)
  82. #else
  83. #define PRINTK3(args...)
  84. #endif
  85. #if SMC_DEBUG > 1
  86. #define PRINTK2(args...) printf(args)
  87. #else
  88. #define PRINTK2(args...)
  89. #endif
  90. #ifdef SMC_DEBUG
  91. #define PRINTK(args...) printf(args)
  92. #else
  93. #define PRINTK(args...)
  94. #endif
  95. /*------------------------------------------------------------------------
  96. *
  97. * The internal workings of the driver. If you are changing anything
  98. * here with the SMC stuff, you should have the datasheet and know
  99. * what you are doing.
  100. *
  101. *------------------------------------------------------------------------
  102. */
  103. #define CARDNAME "LAN91C96"
  104. #define SMC_BASE_ADDRESS CONFIG_LAN91C96_BASE
  105. #define SMC_DEV_NAME "LAN91C96"
  106. #define SMC_ALLOC_MAX_TRY 5
  107. #define SMC_TX_TIMEOUT 30
  108. #define ETH_ZLEN 60
  109. #ifdef CONFIG_LAN91C96_USE_32_BIT
  110. #define USE_32_BIT 1
  111. #else
  112. #undef USE_32_BIT
  113. #endif
  114. /*-----------------------------------------------------------------
  115. *
  116. * The driver can be entered at any of the following entry points.
  117. *
  118. *-----------------------------------------------------------------
  119. */
  120. extern int eth_init (bd_t * bd);
  121. extern void eth_halt (void);
  122. extern int eth_rx (void);
  123. extern int eth_send (volatile void *packet, int length);
  124. static int smc_hw_init (void);
  125. /*
  126. * This is called by register_netdev(). It is responsible for
  127. * checking the portlist for the SMC9000 series chipset. If it finds
  128. * one, then it will initialize the device, find the hardware information,
  129. * and sets up the appropriate device parameters.
  130. * NOTE: Interrupts are *OFF* when this procedure is called.
  131. *
  132. * NB:This shouldn't be static since it is referred to externally.
  133. */
  134. int smc_init (void);
  135. /*
  136. * This is called by unregister_netdev(). It is responsible for
  137. * cleaning up before the driver is finally unregistered and discarded.
  138. */
  139. void smc_destructor (void);
  140. /*
  141. * The kernel calls this function when someone wants to use the device,
  142. * typically 'ifconfig ethX up'.
  143. */
  144. static int smc_open (void);
  145. /*
  146. * This is called by the kernel in response to 'ifconfig ethX down'. It
  147. * is responsible for cleaning up everything that the open routine
  148. * does, and maybe putting the card into a powerdown state.
  149. */
  150. static int smc_close (void);
  151. /*
  152. * This is a separate procedure to handle the receipt of a packet, to
  153. * leave the interrupt code looking slightly cleaner
  154. */
  155. static int smc_rcv (void);
  156. /* ------------------------------------------------------------
  157. * Internal routines
  158. * ------------------------------------------------------------
  159. */
  160. static char smc_mac_addr[] = { 0xc0, 0x00, 0x00, 0x1b, 0x62, 0x9c };
  161. /*
  162. * This function must be called before smc_open() if you want to override
  163. * the default mac address.
  164. */
  165. void smc_set_mac_addr (const char *addr)
  166. {
  167. int i;
  168. for (i = 0; i < sizeof (smc_mac_addr); i++) {
  169. smc_mac_addr[i] = addr[i];
  170. }
  171. }
  172. /*
  173. * smc_get_macaddr is no longer used. If you want to override the default
  174. * mac address, call smc_get_mac_addr as a part of the board initialisation.
  175. */
  176. #if 0
  177. void smc_get_macaddr (byte * addr)
  178. {
  179. /* MAC ADDRESS AT FLASHBLOCK 1 / OFFSET 0x10 */
  180. unsigned char *dnp1110_mac = (unsigned char *) (0xE8000000 + 0x20010);
  181. int i;
  182. for (i = 0; i < 6; i++) {
  183. addr[0] = *(dnp1110_mac + 0);
  184. addr[1] = *(dnp1110_mac + 1);
  185. addr[2] = *(dnp1110_mac + 2);
  186. addr[3] = *(dnp1110_mac + 3);
  187. addr[4] = *(dnp1110_mac + 4);
  188. addr[5] = *(dnp1110_mac + 5);
  189. }
  190. }
  191. #endif /* 0 */
  192. /***********************************************
  193. * Show available memory *
  194. ***********************************************/
  195. void dump_memory_info (void)
  196. {
  197. word mem_info;
  198. word old_bank;
  199. old_bank = SMC_inw (LAN91C96_BANK_SELECT) & 0xF;
  200. SMC_SELECT_BANK (0);
  201. mem_info = SMC_inw (LAN91C96_MIR);
  202. PRINTK2 ("Memory: %4d available\n", (mem_info >> 8) * 2048);
  203. SMC_SELECT_BANK (old_bank);
  204. }
  205. /*
  206. * A rather simple routine to print out a packet for debugging purposes.
  207. */
  208. #if SMC_DEBUG > 2
  209. static void print_packet (byte *, int);
  210. #endif
  211. /* #define tx_done(dev) 1 */
  212. /* this does a soft reset on the device */
  213. static void smc_reset (void);
  214. /* Enable Interrupts, Receive, and Transmit */
  215. static void smc_enable (void);
  216. /* this puts the device in an inactive state */
  217. static void smc_shutdown (void);
  218. static int poll4int (byte mask, int timeout)
  219. {
  220. int tmo = get_timer (0) + timeout * CFG_HZ;
  221. int is_timeout = 0;
  222. word old_bank = SMC_inw (LAN91C96_BANK_SELECT);
  223. PRINTK2 ("Polling...\n");
  224. SMC_SELECT_BANK (2);
  225. while ((SMC_inw (LAN91C96_INT_STATS) & mask) == 0) {
  226. if (get_timer (0) >= tmo) {
  227. is_timeout = 1;
  228. break;
  229. }
  230. }
  231. /* restore old bank selection */
  232. SMC_SELECT_BANK (old_bank);
  233. if (is_timeout)
  234. return 1;
  235. else
  236. return 0;
  237. }
  238. /*
  239. * Function: smc_reset( void )
  240. * Purpose:
  241. * This sets the SMC91111 chip to its normal state, hopefully from whatever
  242. * mess that any other DOS driver has put it in.
  243. *
  244. * Maybe I should reset more registers to defaults in here? SOFTRST should
  245. * do that for me.
  246. *
  247. * Method:
  248. * 1. send a SOFT RESET
  249. * 2. wait for it to finish
  250. * 3. enable autorelease mode
  251. * 4. reset the memory management unit
  252. * 5. clear all interrupts
  253. *
  254. */
  255. static void smc_reset (void)
  256. {
  257. PRINTK2 ("%s:smc_reset\n", SMC_DEV_NAME);
  258. /* This resets the registers mostly to defaults, but doesn't
  259. affect EEPROM. That seems unnecessary */
  260. SMC_SELECT_BANK (0);
  261. SMC_outw (LAN91C96_RCR_SOFT_RST, LAN91C96_RCR);
  262. udelay (10);
  263. /* Disable transmit and receive functionality */
  264. SMC_outw (0, LAN91C96_RCR);
  265. SMC_outw (0, LAN91C96_TCR);
  266. /* set the control register */
  267. SMC_SELECT_BANK (1);
  268. SMC_outw (SMC_inw (LAN91C96_CONTROL) | LAN91C96_CTR_BIT_8,
  269. LAN91C96_CONTROL);
  270. /* Disable all interrupts */
  271. SMC_outb (0, LAN91C96_INT_MASK);
  272. }
  273. /*
  274. * Function: smc_enable
  275. * Purpose: let the chip talk to the outside work
  276. * Method:
  277. * 1. Initialize the Memory Configuration Register
  278. * 2. Enable the transmitter
  279. * 3. Enable the receiver
  280. */
  281. static void smc_enable ()
  282. {
  283. PRINTK2 ("%s:smc_enable\n", SMC_DEV_NAME);
  284. SMC_SELECT_BANK (0);
  285. /* Initialize the Memory Configuration Register. See page
  286. 49 of the LAN91C96 data sheet for details. */
  287. SMC_outw (LAN91C96_MCR_TRANSMIT_PAGES, LAN91C96_MCR);
  288. /* Initialize the Transmit Control Register */
  289. SMC_outw (LAN91C96_TCR_TXENA, LAN91C96_TCR);
  290. /* Initialize the Receive Control Register
  291. * FIXME:
  292. * The promiscuous bit set because I could not receive ARP reply
  293. * packets from the server when I send a ARP request. It only works
  294. * when I set the promiscuous bit
  295. */
  296. SMC_outw (LAN91C96_RCR_RXEN | LAN91C96_RCR_PRMS, LAN91C96_RCR);
  297. }
  298. /*
  299. * Function: smc_shutdown
  300. * Purpose: closes down the SMC91xxx chip.
  301. * Method:
  302. * 1. zero the interrupt mask
  303. * 2. clear the enable receive flag
  304. * 3. clear the enable xmit flags
  305. *
  306. * TODO:
  307. * (1) maybe utilize power down mode.
  308. * Why not yet? Because while the chip will go into power down mode,
  309. * the manual says that it will wake up in response to any I/O requests
  310. * in the register space. Empirical results do not show this working.
  311. */
  312. static void smc_shutdown ()
  313. {
  314. PRINTK2 (CARDNAME ":smc_shutdown\n");
  315. /* no more interrupts for me */
  316. SMC_SELECT_BANK (2);
  317. SMC_outb (0, LAN91C96_INT_MASK);
  318. /* and tell the card to stay away from that nasty outside world */
  319. SMC_SELECT_BANK (0);
  320. SMC_outb (0, LAN91C96_RCR);
  321. SMC_outb (0, LAN91C96_TCR);
  322. }
  323. /*
  324. * Function: smc_hardware_send_packet(struct net_device * )
  325. * Purpose:
  326. * This sends the actual packet to the SMC9xxx chip.
  327. *
  328. * Algorithm:
  329. * First, see if a saved_skb is available.
  330. * ( this should NOT be called if there is no 'saved_skb'
  331. * Now, find the packet number that the chip allocated
  332. * Point the data pointers at it in memory
  333. * Set the length word in the chip's memory
  334. * Dump the packet to chip memory
  335. * Check if a last byte is needed ( odd length packet )
  336. * if so, set the control flag right
  337. * Tell the card to send it
  338. * Enable the transmit interrupt, so I know if it failed
  339. * Free the kernel data if I actually sent it.
  340. */
  341. static int smc_send_packet (volatile void *packet, int packet_length)
  342. {
  343. byte packet_no;
  344. unsigned long ioaddr;
  345. byte *buf;
  346. int length;
  347. int numPages;
  348. int try = 0;
  349. int time_out;
  350. byte status;
  351. PRINTK3 ("%s:smc_hardware_send_packet\n", SMC_DEV_NAME);
  352. length = ETH_ZLEN < packet_length ? packet_length : ETH_ZLEN;
  353. /* allocate memory
  354. ** The MMU wants the number of pages to be the number of 256 bytes
  355. ** 'pages', minus 1 ( since a packet can't ever have 0 pages :) )
  356. **
  357. ** The 91C111 ignores the size bits, but the code is left intact
  358. ** for backwards and future compatibility.
  359. **
  360. ** Pkt size for allocating is data length +6 (for additional status
  361. ** words, length and ctl!)
  362. **
  363. ** If odd size then last byte is included in this header.
  364. */
  365. numPages = ((length & 0xfffe) + 6);
  366. numPages >>= 8; /* Divide by 256 */
  367. if (numPages > 7) {
  368. printf ("%s: Far too big packet error. \n", SMC_DEV_NAME);
  369. return 0;
  370. }
  371. /* now, try to allocate the memory */
  372. SMC_SELECT_BANK (2);
  373. SMC_outw (LAN91C96_MMUCR_ALLOC_TX | numPages, LAN91C96_MMU);
  374. again:
  375. try++;
  376. time_out = MEMORY_WAIT_TIME;
  377. do {
  378. status = SMC_inb (LAN91C96_INT_STATS);
  379. if (status & LAN91C96_IST_ALLOC_INT) {
  380. SMC_outb (LAN91C96_IST_ALLOC_INT, LAN91C96_INT_STATS);
  381. break;
  382. }
  383. } while (--time_out);
  384. if (!time_out) {
  385. PRINTK2 ("%s: memory allocation, try %d failed ...\n",
  386. SMC_DEV_NAME, try);
  387. if (try < SMC_ALLOC_MAX_TRY)
  388. goto again;
  389. else
  390. return 0;
  391. }
  392. PRINTK2 ("%s: memory allocation, try %d succeeded ...\n",
  393. SMC_DEV_NAME, try);
  394. /* I can send the packet now.. */
  395. ioaddr = SMC_BASE_ADDRESS;
  396. buf = (byte *) packet;
  397. /* If I get here, I _know_ there is a packet slot waiting for me */
  398. packet_no = SMC_inb (LAN91C96_ARR);
  399. if (packet_no & LAN91C96_ARR_FAILED) {
  400. /* or isn't there? BAD CHIP! */
  401. printf ("%s: Memory allocation failed. \n", SMC_DEV_NAME);
  402. return 0;
  403. }
  404. /* we have a packet address, so tell the card to use it */
  405. SMC_outb (packet_no, LAN91C96_PNR);
  406. /* point to the beginning of the packet */
  407. SMC_outw (LAN91C96_PTR_AUTO_INCR, LAN91C96_POINTER);
  408. PRINTK3 ("%s: Trying to xmit packet of length %x\n",
  409. SMC_DEV_NAME, length);
  410. #if SMC_DEBUG > 2
  411. printf ("Transmitting Packet\n");
  412. print_packet (buf, length);
  413. #endif
  414. /* send the packet length ( +6 for status, length and ctl byte )
  415. and the status word ( set to zeros ) */
  416. #ifdef USE_32_BIT
  417. SMC_outl ((length + 6) << 16, LAN91C96_DATA_HIGH);
  418. #else
  419. SMC_outw (0, LAN91C96_DATA_HIGH);
  420. /* send the packet length ( +6 for status words, length, and ctl */
  421. SMC_outw ((length + 6), LAN91C96_DATA_HIGH);
  422. #endif /* USE_32_BIT */
  423. /* send the actual data
  424. * I _think_ it's faster to send the longs first, and then
  425. * mop up by sending the last word. It depends heavily
  426. * on alignment, at least on the 486. Maybe it would be
  427. * a good idea to check which is optimal? But that could take
  428. * almost as much time as is saved?
  429. */
  430. #ifdef USE_32_BIT
  431. SMC_outsl (LAN91C96_DATA_HIGH, buf, length >> 2);
  432. if (length & 0x2)
  433. SMC_outw (*((word *) (buf + (length & 0xFFFFFFFC))),
  434. LAN91C96_DATA_HIGH);
  435. #else
  436. SMC_outsw (LAN91C96_DATA_HIGH, buf, (length) >> 1);
  437. #endif /* USE_32_BIT */
  438. /* Send the last byte, if there is one. */
  439. if ((length & 1) == 0) {
  440. SMC_outw (0, LAN91C96_DATA_HIGH);
  441. } else {
  442. SMC_outw (buf[length - 1] | 0x2000, LAN91C96_DATA_HIGH);
  443. }
  444. /* and let the chipset deal with it */
  445. SMC_outw (LAN91C96_MMUCR_ENQUEUE, LAN91C96_MMU);
  446. /* poll for TX INT */
  447. if (poll4int (LAN91C96_MSK_TX_INT, SMC_TX_TIMEOUT)) {
  448. /* sending failed */
  449. PRINTK2 ("%s: TX timeout, sending failed...\n", SMC_DEV_NAME);
  450. /* release packet */
  451. SMC_outw (LAN91C96_MMUCR_RELEASE_TX, LAN91C96_MMU);
  452. /* wait for MMU getting ready (low) */
  453. while (SMC_inw (LAN91C96_MMU) & LAN91C96_MMUCR_NO_BUSY) {
  454. udelay (10);
  455. }
  456. PRINTK2 ("MMU ready\n");
  457. return 0;
  458. } else {
  459. /* ack. int */
  460. SMC_outw (LAN91C96_IST_TX_INT, LAN91C96_INT_STATS);
  461. PRINTK2 ("%s: Sent packet of length %d \n", SMC_DEV_NAME, length);
  462. /* release packet */
  463. SMC_outw (LAN91C96_MMUCR_RELEASE_TX, LAN91C96_MMU);
  464. /* wait for MMU getting ready (low) */
  465. while (SMC_inw (LAN91C96_MMU) & LAN91C96_MMUCR_NO_BUSY) {
  466. udelay (10);
  467. }
  468. PRINTK2 ("MMU ready\n");
  469. }
  470. return length;
  471. }
  472. /*-------------------------------------------------------------------------
  473. * smc_destructor( struct net_device * dev )
  474. * Input parameters:
  475. * dev, pointer to the device structure
  476. *
  477. * Output:
  478. * None.
  479. *--------------------------------------------------------------------------
  480. */
  481. void smc_destructor ()
  482. {
  483. PRINTK2 (CARDNAME ":smc_destructor\n");
  484. }
  485. /*
  486. * Open and Initialize the board
  487. *
  488. * Set up everything, reset the card, etc ..
  489. *
  490. */
  491. static int smc_open ()
  492. {
  493. int i; /* used to set hw ethernet address */
  494. PRINTK2 ("%s:smc_open\n", SMC_DEV_NAME);
  495. /* reset the hardware */
  496. smc_reset ();
  497. smc_enable ();
  498. SMC_SELECT_BANK (1);
  499. for (i = 0; i < 6; i += 2) {
  500. word address;
  501. address = smc_mac_addr[i + 1] << 8;
  502. address |= smc_mac_addr[i];
  503. SMC_outw (address, LAN91C96_IA0 + i);
  504. }
  505. return 0;
  506. }
  507. /*-------------------------------------------------------------
  508. *
  509. * smc_rcv - receive a packet from the card
  510. *
  511. * There is ( at least ) a packet waiting to be read from
  512. * chip-memory.
  513. *
  514. * o Read the status
  515. * o If an error, record it
  516. * o otherwise, read in the packet
  517. *-------------------------------------------------------------
  518. */
  519. static int smc_rcv ()
  520. {
  521. int packet_number;
  522. word status;
  523. word packet_length;
  524. int is_error = 0;
  525. #ifdef USE_32_BIT
  526. dword stat_len;
  527. #endif
  528. SMC_SELECT_BANK (2);
  529. packet_number = SMC_inw (LAN91C96_FIFO);
  530. if (packet_number & LAN91C96_FIFO_RXEMPTY) {
  531. return 0;
  532. }
  533. PRINTK3 ("%s:smc_rcv\n", SMC_DEV_NAME);
  534. /* start reading from the start of the packet */
  535. SMC_outw (LAN91C96_PTR_READ | LAN91C96_PTR_RCV |
  536. LAN91C96_PTR_AUTO_INCR, LAN91C96_POINTER);
  537. /* First two words are status and packet_length */
  538. #ifdef USE_32_BIT
  539. stat_len = SMC_inl (LAN91C96_DATA_HIGH);
  540. status = stat_len & 0xffff;
  541. packet_length = stat_len >> 16;
  542. #else
  543. status = SMC_inw (LAN91C96_DATA_HIGH);
  544. packet_length = SMC_inw (LAN91C96_DATA_HIGH);
  545. #endif
  546. packet_length &= 0x07ff; /* mask off top bits */
  547. PRINTK2 ("RCV: STATUS %4x LENGTH %4x\n", status, packet_length);
  548. if (!(status & FRAME_FILTER)) {
  549. /* Adjust for having already read the first two words */
  550. packet_length -= 4; /*4; */
  551. /* set odd length for bug in LAN91C111, */
  552. /* which never sets RS_ODDFRAME */
  553. /* TODO ? */
  554. #ifdef USE_32_BIT
  555. PRINTK3 (" Reading %d dwords (and %d bytes) \n",
  556. packet_length >> 2, packet_length & 3);
  557. /* QUESTION: Like in the TX routine, do I want
  558. to send the DWORDs or the bytes first, or some
  559. mixture. A mixture might improve already slow PIO
  560. performance */
  561. SMC_insl (LAN91C96_DATA_HIGH, NetRxPackets[0], packet_length >> 2);
  562. /* read the left over bytes */
  563. if (packet_length & 3) {
  564. int i;
  565. byte *tail = (byte *) (NetRxPackets[0] + (packet_length & ~3));
  566. dword leftover = SMC_inl (LAN91C96_DATA_HIGH);
  567. for (i = 0; i < (packet_length & 3); i++)
  568. *tail++ = (byte) (leftover >> (8 * i)) & 0xff;
  569. }
  570. #else
  571. PRINTK3 (" Reading %d words and %d byte(s) \n",
  572. (packet_length >> 1), packet_length & 1);
  573. SMC_insw (LAN91C96_DATA_HIGH, NetRxPackets[0], packet_length >> 1);
  574. #endif /* USE_32_BIT */
  575. #if SMC_DEBUG > 2
  576. printf ("Receiving Packet\n");
  577. print_packet (NetRxPackets[0], packet_length);
  578. #endif
  579. } else {
  580. /* error ... */
  581. /* TODO ? */
  582. is_error = 1;
  583. }
  584. while (SMC_inw (LAN91C96_MMU) & LAN91C96_MMUCR_NO_BUSY)
  585. udelay (1); /* Wait until not busy */
  586. /* error or good, tell the card to get rid of this packet */
  587. SMC_outw (LAN91C96_MMUCR_RELEASE_RX, LAN91C96_MMU);
  588. while (SMC_inw (LAN91C96_MMU) & LAN91C96_MMUCR_NO_BUSY)
  589. udelay (1); /* Wait until not busy */
  590. if (!is_error) {
  591. /* Pass the packet up to the protocol layers. */
  592. NetReceive (NetRxPackets[0], packet_length);
  593. return packet_length;
  594. } else {
  595. return 0;
  596. }
  597. }
  598. /*----------------------------------------------------
  599. * smc_close
  600. *
  601. * this makes the board clean up everything that it can
  602. * and not talk to the outside world. Caused by
  603. * an 'ifconfig ethX down'
  604. *
  605. -----------------------------------------------------*/
  606. static int smc_close ()
  607. {
  608. PRINTK2 ("%s:smc_close\n", SMC_DEV_NAME);
  609. /* clear everything */
  610. smc_shutdown ();
  611. return 0;
  612. }
  613. #if SMC_DEBUG > 2
  614. static void print_packet (byte * buf, int length)
  615. {
  616. #if 0
  617. int i;
  618. int remainder;
  619. int lines;
  620. printf ("Packet of length %d \n", length);
  621. lines = length / 16;
  622. remainder = length % 16;
  623. for (i = 0; i < lines; i++) {
  624. int cur;
  625. for (cur = 0; cur < 8; cur++) {
  626. byte a, b;
  627. a = *(buf++);
  628. b = *(buf++);
  629. printf ("%02x%02x ", a, b);
  630. }
  631. printf ("\n");
  632. }
  633. for (i = 0; i < remainder / 2; i++) {
  634. byte a, b;
  635. a = *(buf++);
  636. b = *(buf++);
  637. printf ("%02x%02x ", a, b);
  638. }
  639. printf ("\n");
  640. #endif /* 0 */
  641. }
  642. #endif /* SMC_DEBUG > 2 */
  643. int eth_init (bd_t * bd)
  644. {
  645. smc_open ();
  646. return 0;
  647. }
  648. void eth_halt ()
  649. {
  650. smc_close ();
  651. }
  652. int eth_rx ()
  653. {
  654. return smc_rcv ();
  655. }
  656. int eth_send (volatile void *packet, int length)
  657. {
  658. return smc_send_packet (packet, length);
  659. }
  660. int eth_hw_init ()
  661. {
  662. return smc_hw_init ();
  663. }
  664. /*-------------------------------------------------------------------------
  665. * smc_hw_init()
  666. *
  667. * Function:
  668. * Reset and enable the device, check if the I/O space location
  669. * is correct
  670. *
  671. * Input parameters:
  672. * None
  673. *
  674. * Output:
  675. * 0 --> success
  676. * 1 --> error
  677. *--------------------------------------------------------------------------
  678. */
  679. static int smc_hw_init ()
  680. {
  681. unsigned short status_test;
  682. /* The attribute register of the LAN91C96 is located at address
  683. 0x0e000000 on the lubbock platform */
  684. volatile unsigned *attaddr = (unsigned *) (0x0e000000);
  685. /* first reset, then enable the device. Sequence is critical */
  686. attaddr[LAN91C96_ECOR] |= LAN91C96_ECOR_SRESET;
  687. udelay (100);
  688. attaddr[LAN91C96_ECOR] &= ~LAN91C96_ECOR_SRESET;
  689. attaddr[LAN91C96_ECOR] |= LAN91C96_ECOR_ENABLE;
  690. /* force 16-bit mode */
  691. attaddr[LAN91C96_ECSR] &= ~LAN91C96_ECSR_IOIS8;
  692. udelay (100);
  693. /* check if the I/O address is correct, the upper byte of the
  694. bank select register should read 0x33 */
  695. status_test = SMC_inw (LAN91C96_BANK_SELECT);
  696. if ((status_test & 0xFF00) != 0x3300) {
  697. printf ("Failed to initialize ethernetchip\n");
  698. return 1;
  699. }
  700. return 0;
  701. }
  702. #endif /* COMMANDS & CFG_NET */
  703. #endif /* CONFIG_DRIVER_LAN91C96 */