smc9194.c 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602
  1. /*------------------------------------------------------------------------
  2. . smc9194.c
  3. . This is a driver for SMC's 9000 series of Ethernet cards.
  4. .
  5. . Copyright (C) 1996 by Erik Stahlman
  6. . This software may be used and distributed according to the terms
  7. . of the GNU General Public License, incorporated herein by reference.
  8. .
  9. . "Features" of the SMC chip:
  10. . 4608 byte packet memory. ( for the 91C92. Others have more )
  11. . EEPROM for configuration
  12. . AUI/TP selection ( mine has 10Base2/10BaseT select )
  13. .
  14. . Arguments:
  15. . io = for the base address
  16. . irq = for the IRQ
  17. . ifport = 0 for autodetect, 1 for TP, 2 for AUI ( or 10base2 )
  18. .
  19. . author:
  20. . Erik Stahlman ( erik@vt.edu )
  21. . contributors:
  22. . Arnaldo Carvalho de Melo <acme@conectiva.com.br>
  23. .
  24. . Hardware multicast code from Peter Cammaert ( pc@denkart.be )
  25. .
  26. . Sources:
  27. . o SMC databook
  28. . o skeleton.c by Donald Becker ( becker@scyld.com )
  29. . o ( a LOT of advice from Becker as well )
  30. .
  31. . History:
  32. . 12/07/95 Erik Stahlman written, got receive/xmit handled
  33. . 01/03/96 Erik Stahlman worked out some bugs, actually usable!!! :-)
  34. . 01/06/96 Erik Stahlman cleaned up some, better testing, etc
  35. . 01/29/96 Erik Stahlman fixed autoirq, added multicast
  36. . 02/01/96 Erik Stahlman 1. disabled all interrupts in smc_reset
  37. . 2. got rid of post-decrementing bug -- UGH.
  38. . 02/13/96 Erik Stahlman Tried to fix autoirq failure. Added more
  39. . descriptive error messages.
  40. . 02/15/96 Erik Stahlman Fixed typo that caused detection failure
  41. . 02/23/96 Erik Stahlman Modified it to fit into kernel tree
  42. . Added support to change hardware address
  43. . Cleared stats on opens
  44. . 02/26/96 Erik Stahlman Trial support for Kernel 1.2.13
  45. . Kludge for automatic IRQ detection
  46. . 03/04/96 Erik Stahlman Fixed kernel 1.3.70 +
  47. . Fixed bug reported by Gardner Buchanan in
  48. . smc_enable, with outw instead of outb
  49. . 03/06/96 Erik Stahlman Added hardware multicast from Peter Cammaert
  50. . 04/14/00 Heiko Pruessing (SMA Regelsysteme) Fixed bug in chip memory
  51. . allocation
  52. . 08/20/00 Arnaldo Melo fix kfree(skb) in smc_hardware_send_packet
  53. . 12/15/00 Christian Jullien fix "Warning: kfree_skb on hard IRQ"
  54. . 11/08/01 Matt Domsch Use common crc32 function
  55. ----------------------------------------------------------------------------*/
  56. static const char version[] =
  57. "smc9194.c:v0.14 12/15/00 by Erik Stahlman (erik@vt.edu)\n";
  58. #include <linux/module.h>
  59. #include <linux/kernel.h>
  60. #include <linux/types.h>
  61. #include <linux/fcntl.h>
  62. #include <linux/interrupt.h>
  63. #include <linux/ioport.h>
  64. #include <linux/in.h>
  65. #include <linux/slab.h>
  66. #include <linux/string.h>
  67. #include <linux/init.h>
  68. #include <linux/crc32.h>
  69. #include <linux/errno.h>
  70. #include <linux/netdevice.h>
  71. #include <linux/etherdevice.h>
  72. #include <linux/skbuff.h>
  73. #include <linux/bitops.h>
  74. #include <asm/io.h>
  75. #include "smc9194.h"
  76. #define DRV_NAME "smc9194"
  77. /*------------------------------------------------------------------------
  78. .
  79. . Configuration options, for the experienced user to change.
  80. .
  81. -------------------------------------------------------------------------*/
  82. /*
  83. . Do you want to use 32 bit xfers? This should work on all chips, as
  84. . the chipset is designed to accommodate them.
  85. */
  86. #ifdef __sh__
  87. #undef USE_32_BIT
  88. #else
  89. #define USE_32_BIT 1
  90. #endif
  91. #if defined(__H8300H__) || defined(__H8300S__)
  92. #define NO_AUTOPROBE
  93. #undef insl
  94. #undef outsl
  95. #define insl(a,b,l) io_insl_noswap(a,b,l)
  96. #define outsl(a,b,l) io_outsl_noswap(a,b,l)
  97. #endif
  98. /*
  99. .the SMC9194 can be at any of the following port addresses. To change,
  100. .for a slightly different card, you can add it to the array. Keep in
  101. .mind that the array must end in zero.
  102. */
  103. struct devlist {
  104. unsigned int port;
  105. unsigned int irq;
  106. };
  107. #if defined(CONFIG_H8S_EDOSK2674)
  108. static struct devlist smc_devlist[] __initdata = {
  109. {.port = 0xf80000, .irq = 16},
  110. {.port = 0, .irq = 0 },
  111. };
  112. #else
  113. static struct devlist smc_devlist[] __initdata = {
  114. {.port = 0x200, .irq = 0},
  115. {.port = 0x220, .irq = 0},
  116. {.port = 0x240, .irq = 0},
  117. {.port = 0x260, .irq = 0},
  118. {.port = 0x280, .irq = 0},
  119. {.port = 0x2A0, .irq = 0},
  120. {.port = 0x2C0, .irq = 0},
  121. {.port = 0x2E0, .irq = 0},
  122. {.port = 0x300, .irq = 0},
  123. {.port = 0x320, .irq = 0},
  124. {.port = 0x340, .irq = 0},
  125. {.port = 0x360, .irq = 0},
  126. {.port = 0x380, .irq = 0},
  127. {.port = 0x3A0, .irq = 0},
  128. {.port = 0x3C0, .irq = 0},
  129. {.port = 0x3E0, .irq = 0},
  130. {.port = 0, .irq = 0},
  131. };
  132. #endif
  133. /*
  134. . Wait time for memory to be free. This probably shouldn't be
  135. . tuned that much, as waiting for this means nothing else happens
  136. . in the system
  137. */
  138. #define MEMORY_WAIT_TIME 16
  139. /*
  140. . DEBUGGING LEVELS
  141. .
  142. . 0 for normal operation
  143. . 1 for slightly more details
  144. . >2 for various levels of increasingly useless information
  145. . 2 for interrupt tracking, status flags
  146. . 3 for packet dumps, etc.
  147. */
  148. #define SMC_DEBUG 0
  149. #if (SMC_DEBUG > 2 )
  150. #define PRINTK3(x) printk x
  151. #else
  152. #define PRINTK3(x)
  153. #endif
  154. #if SMC_DEBUG > 1
  155. #define PRINTK2(x) printk x
  156. #else
  157. #define PRINTK2(x)
  158. #endif
  159. #ifdef SMC_DEBUG
  160. #define PRINTK(x) printk x
  161. #else
  162. #define PRINTK(x)
  163. #endif
  164. /*------------------------------------------------------------------------
  165. .
  166. . The internal workings of the driver. If you are changing anything
  167. . here with the SMC stuff, you should have the datasheet and known
  168. . what you are doing.
  169. .
  170. -------------------------------------------------------------------------*/
  171. #define CARDNAME "SMC9194"
  172. /* store this information for the driver.. */
  173. struct smc_local {
  174. /*
  175. If I have to wait until memory is available to send
  176. a packet, I will store the skbuff here, until I get the
  177. desired memory. Then, I'll send it out and free it.
  178. */
  179. struct sk_buff * saved_skb;
  180. /*
  181. . This keeps track of how many packets that I have
  182. . sent out. When an TX_EMPTY interrupt comes, I know
  183. . that all of these have been sent.
  184. */
  185. int packets_waiting;
  186. };
  187. /*-----------------------------------------------------------------
  188. .
  189. . The driver can be entered at any of the following entry points.
  190. .
  191. .------------------------------------------------------------------ */
  192. /*
  193. . This is called by register_netdev(). It is responsible for
  194. . checking the portlist for the SMC9000 series chipset. If it finds
  195. . one, then it will initialize the device, find the hardware information,
  196. . and sets up the appropriate device parameters.
  197. . NOTE: Interrupts are *OFF* when this procedure is called.
  198. .
  199. . NB:This shouldn't be static since it is referred to externally.
  200. */
  201. struct net_device *smc_init(int unit);
  202. /*
  203. . The kernel calls this function when someone wants to use the device,
  204. . typically 'ifconfig ethX up'.
  205. */
  206. static int smc_open(struct net_device *dev);
  207. /*
  208. . Our watchdog timed out. Called by the networking layer
  209. */
  210. static void smc_timeout(struct net_device *dev);
  211. /*
  212. . This is called by the kernel in response to 'ifconfig ethX down'. It
  213. . is responsible for cleaning up everything that the open routine
  214. . does, and maybe putting the card into a powerdown state.
  215. */
  216. static int smc_close(struct net_device *dev);
  217. /*
  218. . Finally, a call to set promiscuous mode ( for TCPDUMP and related
  219. . programs ) and multicast modes.
  220. */
  221. static void smc_set_multicast_list(struct net_device *dev);
  222. /*---------------------------------------------------------------
  223. .
  224. . Interrupt level calls..
  225. .
  226. ----------------------------------------------------------------*/
  227. /*
  228. . Handles the actual interrupt
  229. */
  230. static irqreturn_t smc_interrupt(int irq, void *);
  231. /*
  232. . This is a separate procedure to handle the receipt of a packet, to
  233. . leave the interrupt code looking slightly cleaner
  234. */
  235. static inline void smc_rcv( struct net_device *dev );
  236. /*
  237. . This handles a TX interrupt, which is only called when an error
  238. . relating to a packet is sent.
  239. */
  240. static inline void smc_tx( struct net_device * dev );
  241. /*
  242. ------------------------------------------------------------
  243. .
  244. . Internal routines
  245. .
  246. ------------------------------------------------------------
  247. */
  248. /*
  249. . Test if a given location contains a chip, trying to cause as
  250. . little damage as possible if it's not a SMC chip.
  251. */
  252. static int smc_probe(struct net_device *dev, int ioaddr);
  253. /*
  254. . A rather simple routine to print out a packet for debugging purposes.
  255. */
  256. #if SMC_DEBUG > 2
  257. static void print_packet( byte *, int );
  258. #endif
  259. #define tx_done(dev) 1
  260. /* this is called to actually send the packet to the chip */
  261. static void smc_hardware_send_packet( struct net_device * dev );
  262. /* Since I am not sure if I will have enough room in the chip's ram
  263. . to store the packet, I call this routine, which either sends it
  264. . now, or generates an interrupt when the card is ready for the
  265. . packet */
  266. static int smc_wait_to_send_packet( struct sk_buff * skb, struct net_device *dev );
  267. /* this does a soft reset on the device */
  268. static void smc_reset( int ioaddr );
  269. /* Enable Interrupts, Receive, and Transmit */
  270. static void smc_enable( int ioaddr );
  271. /* this puts the device in an inactive state */
  272. static void smc_shutdown( int ioaddr );
  273. /* This routine will find the IRQ of the driver if one is not
  274. . specified in the input to the device. */
  275. static int smc_findirq( int ioaddr );
  276. /*
  277. . Function: smc_reset( int ioaddr )
  278. . Purpose:
  279. . This sets the SMC91xx chip to its normal state, hopefully from whatever
  280. . mess that any other DOS driver has put it in.
  281. .
  282. . Maybe I should reset more registers to defaults in here? SOFTRESET should
  283. . do that for me.
  284. .
  285. . Method:
  286. . 1. send a SOFT RESET
  287. . 2. wait for it to finish
  288. . 3. enable autorelease mode
  289. . 4. reset the memory management unit
  290. . 5. clear all interrupts
  291. .
  292. */
  293. static void smc_reset( int ioaddr )
  294. {
  295. /* This resets the registers mostly to defaults, but doesn't
  296. affect EEPROM. That seems unnecessary */
  297. SMC_SELECT_BANK( 0 );
  298. outw( RCR_SOFTRESET, ioaddr + RCR );
  299. /* this should pause enough for the chip to be happy */
  300. SMC_DELAY( );
  301. /* Set the transmit and receive configuration registers to
  302. default values */
  303. outw( RCR_CLEAR, ioaddr + RCR );
  304. outw( TCR_CLEAR, ioaddr + TCR );
  305. /* set the control register to automatically
  306. release successfully transmitted packets, to make the best
  307. use out of our limited memory */
  308. SMC_SELECT_BANK( 1 );
  309. outw( inw( ioaddr + CONTROL ) | CTL_AUTO_RELEASE , ioaddr + CONTROL );
  310. /* Reset the MMU */
  311. SMC_SELECT_BANK( 2 );
  312. outw( MC_RESET, ioaddr + MMU_CMD );
  313. /* Note: It doesn't seem that waiting for the MMU busy is needed here,
  314. but this is a place where future chipsets _COULD_ break. Be wary
  315. of issuing another MMU command right after this */
  316. outb( 0, ioaddr + INT_MASK );
  317. }
  318. /*
  319. . Function: smc_enable
  320. . Purpose: let the chip talk to the outside work
  321. . Method:
  322. . 1. Enable the transmitter
  323. . 2. Enable the receiver
  324. . 3. Enable interrupts
  325. */
  326. static void smc_enable( int ioaddr )
  327. {
  328. SMC_SELECT_BANK( 0 );
  329. /* see the header file for options in TCR/RCR NORMAL*/
  330. outw( TCR_NORMAL, ioaddr + TCR );
  331. outw( RCR_NORMAL, ioaddr + RCR );
  332. /* now, enable interrupts */
  333. SMC_SELECT_BANK( 2 );
  334. outb( SMC_INTERRUPT_MASK, ioaddr + INT_MASK );
  335. }
  336. /*
  337. . Function: smc_shutdown
  338. . Purpose: closes down the SMC91xxx chip.
  339. . Method:
  340. . 1. zero the interrupt mask
  341. . 2. clear the enable receive flag
  342. . 3. clear the enable xmit flags
  343. .
  344. . TODO:
  345. . (1) maybe utilize power down mode.
  346. . Why not yet? Because while the chip will go into power down mode,
  347. . the manual says that it will wake up in response to any I/O requests
  348. . in the register space. Empirical results do not show this working.
  349. */
  350. static void smc_shutdown( int ioaddr )
  351. {
  352. /* no more interrupts for me */
  353. SMC_SELECT_BANK( 2 );
  354. outb( 0, ioaddr + INT_MASK );
  355. /* and tell the card to stay away from that nasty outside world */
  356. SMC_SELECT_BANK( 0 );
  357. outb( RCR_CLEAR, ioaddr + RCR );
  358. outb( TCR_CLEAR, ioaddr + TCR );
  359. #if 0
  360. /* finally, shut the chip down */
  361. SMC_SELECT_BANK( 1 );
  362. outw( inw( ioaddr + CONTROL ), CTL_POWERDOWN, ioaddr + CONTROL );
  363. #endif
  364. }
  365. /*
  366. . Function: smc_setmulticast( int ioaddr, int count, dev_mc_list * adds )
  367. . Purpose:
  368. . This sets the internal hardware table to filter out unwanted multicast
  369. . packets before they take up memory.
  370. .
  371. . The SMC chip uses a hash table where the high 6 bits of the CRC of
  372. . address are the offset into the table. If that bit is 1, then the
  373. . multicast packet is accepted. Otherwise, it's dropped silently.
  374. .
  375. . To use the 6 bits as an offset into the table, the high 3 bits are the
  376. . number of the 8 bit register, while the low 3 bits are the bit within
  377. . that register.
  378. .
  379. . This routine is based very heavily on the one provided by Peter Cammaert.
  380. */
  381. static void smc_setmulticast( int ioaddr, int count, struct dev_mc_list * addrs ) {
  382. int i;
  383. unsigned char multicast_table[ 8 ];
  384. struct dev_mc_list * cur_addr;
  385. /* table for flipping the order of 3 bits */
  386. unsigned char invert3[] = { 0, 4, 2, 6, 1, 5, 3, 7 };
  387. /* start with a table of all zeros: reject all */
  388. memset( multicast_table, 0, sizeof( multicast_table ) );
  389. cur_addr = addrs;
  390. for ( i = 0; i < count ; i ++, cur_addr = cur_addr->next ) {
  391. int position;
  392. /* do we have a pointer here? */
  393. if ( !cur_addr )
  394. break;
  395. /* make sure this is a multicast address - shouldn't this
  396. be a given if we have it here ? */
  397. if ( !( *cur_addr->dmi_addr & 1 ) )
  398. continue;
  399. /* only use the low order bits */
  400. position = ether_crc_le(6, cur_addr->dmi_addr) & 0x3f;
  401. /* do some messy swapping to put the bit in the right spot */
  402. multicast_table[invert3[position&7]] |=
  403. (1<<invert3[(position>>3)&7]);
  404. }
  405. /* now, the table can be loaded into the chipset */
  406. SMC_SELECT_BANK( 3 );
  407. for ( i = 0; i < 8 ; i++ ) {
  408. outb( multicast_table[i], ioaddr + MULTICAST1 + i );
  409. }
  410. }
  411. /*
  412. . Function: smc_wait_to_send_packet( struct sk_buff * skb, struct net_device * )
  413. . Purpose:
  414. . Attempt to allocate memory for a packet, if chip-memory is not
  415. . available, then tell the card to generate an interrupt when it
  416. . is available.
  417. .
  418. . Algorithm:
  419. .
  420. . o if the saved_skb is not currently null, then drop this packet
  421. . on the floor. This should never happen, because of TBUSY.
  422. . o if the saved_skb is null, then replace it with the current packet,
  423. . o See if I can sending it now.
  424. . o (NO): Enable interrupts and let the interrupt handler deal with it.
  425. . o (YES):Send it now.
  426. */
  427. static int smc_wait_to_send_packet( struct sk_buff * skb, struct net_device * dev )
  428. {
  429. struct smc_local *lp = netdev_priv(dev);
  430. unsigned int ioaddr = dev->base_addr;
  431. word length;
  432. unsigned short numPages;
  433. word time_out;
  434. netif_stop_queue(dev);
  435. /* Well, I want to send the packet.. but I don't know
  436. if I can send it right now... */
  437. if ( lp->saved_skb) {
  438. /* THIS SHOULD NEVER HAPPEN. */
  439. dev->stats.tx_aborted_errors++;
  440. printk(CARDNAME": Bad Craziness - sent packet while busy.\n" );
  441. return 1;
  442. }
  443. lp->saved_skb = skb;
  444. length = skb->len;
  445. if (length < ETH_ZLEN) {
  446. if (skb_padto(skb, ETH_ZLEN)) {
  447. netif_wake_queue(dev);
  448. return 0;
  449. }
  450. length = ETH_ZLEN;
  451. }
  452. /*
  453. ** The MMU wants the number of pages to be the number of 256 bytes
  454. ** 'pages', minus 1 ( since a packet can't ever have 0 pages :) )
  455. **
  456. ** Pkt size for allocating is data length +6 (for additional status words,
  457. ** length and ctl!) If odd size last byte is included in this header.
  458. */
  459. numPages = ((length & 0xfffe) + 6) / 256;
  460. if (numPages > 7 ) {
  461. printk(CARDNAME": Far too big packet error. \n");
  462. /* freeing the packet is a good thing here... but should
  463. . any packets of this size get down here? */
  464. dev_kfree_skb (skb);
  465. lp->saved_skb = NULL;
  466. /* this IS an error, but, i don't want the skb saved */
  467. netif_wake_queue(dev);
  468. return 0;
  469. }
  470. /* either way, a packet is waiting now */
  471. lp->packets_waiting++;
  472. /* now, try to allocate the memory */
  473. SMC_SELECT_BANK( 2 );
  474. outw( MC_ALLOC | numPages, ioaddr + MMU_CMD );
  475. /*
  476. . Performance Hack
  477. .
  478. . wait a short amount of time.. if I can send a packet now, I send
  479. . it now. Otherwise, I enable an interrupt and wait for one to be
  480. . available.
  481. .
  482. . I could have handled this a slightly different way, by checking to
  483. . see if any memory was available in the FREE MEMORY register. However,
  484. . either way, I need to generate an allocation, and the allocation works
  485. . no matter what, so I saw no point in checking free memory.
  486. */
  487. time_out = MEMORY_WAIT_TIME;
  488. do {
  489. word status;
  490. status = inb( ioaddr + INTERRUPT );
  491. if ( status & IM_ALLOC_INT ) {
  492. /* acknowledge the interrupt */
  493. outb( IM_ALLOC_INT, ioaddr + INTERRUPT );
  494. break;
  495. }
  496. } while ( -- time_out );
  497. if ( !time_out ) {
  498. /* oh well, wait until the chip finds memory later */
  499. SMC_ENABLE_INT( IM_ALLOC_INT );
  500. PRINTK2((CARDNAME": memory allocation deferred. \n"));
  501. /* it's deferred, but I'll handle it later */
  502. return 0;
  503. }
  504. /* or YES! I can send the packet now.. */
  505. smc_hardware_send_packet(dev);
  506. netif_wake_queue(dev);
  507. return 0;
  508. }
  509. /*
  510. . Function: smc_hardware_send_packet(struct net_device * )
  511. . Purpose:
  512. . This sends the actual packet to the SMC9xxx chip.
  513. .
  514. . Algorithm:
  515. . First, see if a saved_skb is available.
  516. . ( this should NOT be called if there is no 'saved_skb'
  517. . Now, find the packet number that the chip allocated
  518. . Point the data pointers at it in memory
  519. . Set the length word in the chip's memory
  520. . Dump the packet to chip memory
  521. . Check if a last byte is needed ( odd length packet )
  522. . if so, set the control flag right
  523. . Tell the card to send it
  524. . Enable the transmit interrupt, so I know if it failed
  525. . Free the kernel data if I actually sent it.
  526. */
  527. static void smc_hardware_send_packet( struct net_device * dev )
  528. {
  529. struct smc_local *lp = netdev_priv(dev);
  530. byte packet_no;
  531. struct sk_buff * skb = lp->saved_skb;
  532. word length;
  533. unsigned int ioaddr;
  534. byte * buf;
  535. ioaddr = dev->base_addr;
  536. if ( !skb ) {
  537. PRINTK((CARDNAME": In XMIT with no packet to send \n"));
  538. return;
  539. }
  540. length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
  541. buf = skb->data;
  542. /* If I get here, I _know_ there is a packet slot waiting for me */
  543. packet_no = inb( ioaddr + PNR_ARR + 1 );
  544. if ( packet_no & 0x80 ) {
  545. /* or isn't there? BAD CHIP! */
  546. printk(KERN_DEBUG CARDNAME": Memory allocation failed. \n");
  547. dev_kfree_skb_any(skb);
  548. lp->saved_skb = NULL;
  549. netif_wake_queue(dev);
  550. return;
  551. }
  552. /* we have a packet address, so tell the card to use it */
  553. outb( packet_no, ioaddr + PNR_ARR );
  554. /* point to the beginning of the packet */
  555. outw( PTR_AUTOINC , ioaddr + POINTER );
  556. PRINTK3((CARDNAME": Trying to xmit packet of length %x\n", length ));
  557. #if SMC_DEBUG > 2
  558. print_packet( buf, length );
  559. #endif
  560. /* send the packet length ( +6 for status, length and ctl byte )
  561. and the status word ( set to zeros ) */
  562. #ifdef USE_32_BIT
  563. outl( (length +6 ) << 16 , ioaddr + DATA_1 );
  564. #else
  565. outw( 0, ioaddr + DATA_1 );
  566. /* send the packet length ( +6 for status words, length, and ctl*/
  567. outb( (length+6) & 0xFF,ioaddr + DATA_1 );
  568. outb( (length+6) >> 8 , ioaddr + DATA_1 );
  569. #endif
  570. /* send the actual data
  571. . I _think_ it's faster to send the longs first, and then
  572. . mop up by sending the last word. It depends heavily
  573. . on alignment, at least on the 486. Maybe it would be
  574. . a good idea to check which is optimal? But that could take
  575. . almost as much time as is saved?
  576. */
  577. #ifdef USE_32_BIT
  578. if ( length & 0x2 ) {
  579. outsl(ioaddr + DATA_1, buf, length >> 2 );
  580. #if !defined(__H8300H__) && !defined(__H8300S__)
  581. outw( *((word *)(buf + (length & 0xFFFFFFFC))),ioaddr +DATA_1);
  582. #else
  583. ctrl_outw( *((word *)(buf + (length & 0xFFFFFFFC))),ioaddr +DATA_1);
  584. #endif
  585. }
  586. else
  587. outsl(ioaddr + DATA_1, buf, length >> 2 );
  588. #else
  589. outsw(ioaddr + DATA_1 , buf, (length ) >> 1);
  590. #endif
  591. /* Send the last byte, if there is one. */
  592. if ( (length & 1) == 0 ) {
  593. outw( 0, ioaddr + DATA_1 );
  594. } else {
  595. outb( buf[length -1 ], ioaddr + DATA_1 );
  596. outb( 0x20, ioaddr + DATA_1);
  597. }
  598. /* enable the interrupts */
  599. SMC_ENABLE_INT( (IM_TX_INT | IM_TX_EMPTY_INT) );
  600. /* and let the chipset deal with it */
  601. outw( MC_ENQUEUE , ioaddr + MMU_CMD );
  602. PRINTK2((CARDNAME": Sent packet of length %d \n",length));
  603. lp->saved_skb = NULL;
  604. dev_kfree_skb_any (skb);
  605. dev->trans_start = jiffies;
  606. /* we can send another packet */
  607. netif_wake_queue(dev);
  608. return;
  609. }
  610. /*-------------------------------------------------------------------------
  611. |
  612. | smc_init(int unit)
  613. | Input parameters:
  614. | dev->base_addr == 0, try to find all possible locations
  615. | dev->base_addr == 1, return failure code
  616. | dev->base_addr == 2, always allocate space, and return success
  617. | dev->base_addr == <anything else> this is the address to check
  618. |
  619. | Output:
  620. | pointer to net_device or ERR_PTR(error)
  621. |
  622. ---------------------------------------------------------------------------
  623. */
  624. static int io;
  625. static int irq;
  626. static int ifport;
  627. struct net_device * __init smc_init(int unit)
  628. {
  629. struct net_device *dev = alloc_etherdev(sizeof(struct smc_local));
  630. struct devlist *smcdev = smc_devlist;
  631. int err = 0;
  632. if (!dev)
  633. return ERR_PTR(-ENODEV);
  634. if (unit >= 0) {
  635. sprintf(dev->name, "eth%d", unit);
  636. netdev_boot_setup_check(dev);
  637. io = dev->base_addr;
  638. irq = dev->irq;
  639. }
  640. if (io > 0x1ff) { /* Check a single specified location. */
  641. err = smc_probe(dev, io);
  642. } else if (io != 0) { /* Don't probe at all. */
  643. err = -ENXIO;
  644. } else {
  645. for (;smcdev->port; smcdev++) {
  646. if (smc_probe(dev, smcdev->port) == 0)
  647. break;
  648. }
  649. if (!smcdev->port)
  650. err = -ENODEV;
  651. }
  652. if (err)
  653. goto out;
  654. err = register_netdev(dev);
  655. if (err)
  656. goto out1;
  657. return dev;
  658. out1:
  659. free_irq(dev->irq, dev);
  660. release_region(dev->base_addr, SMC_IO_EXTENT);
  661. out:
  662. free_netdev(dev);
  663. return ERR_PTR(err);
  664. }
  665. /*----------------------------------------------------------------------
  666. . smc_findirq
  667. .
  668. . This routine has a simple purpose -- make the SMC chip generate an
  669. . interrupt, so an auto-detect routine can detect it, and find the IRQ,
  670. ------------------------------------------------------------------------
  671. */
  672. static int __init smc_findirq(int ioaddr)
  673. {
  674. #ifndef NO_AUTOPROBE
  675. int timeout = 20;
  676. unsigned long cookie;
  677. cookie = probe_irq_on();
  678. /*
  679. * What I try to do here is trigger an ALLOC_INT. This is done
  680. * by allocating a small chunk of memory, which will give an interrupt
  681. * when done.
  682. */
  683. SMC_SELECT_BANK(2);
  684. /* enable ALLOCation interrupts ONLY */
  685. outb( IM_ALLOC_INT, ioaddr + INT_MASK );
  686. /*
  687. . Allocate 512 bytes of memory. Note that the chip was just
  688. . reset so all the memory is available
  689. */
  690. outw( MC_ALLOC | 1, ioaddr + MMU_CMD );
  691. /*
  692. . Wait until positive that the interrupt has been generated
  693. */
  694. while ( timeout ) {
  695. byte int_status;
  696. int_status = inb( ioaddr + INTERRUPT );
  697. if ( int_status & IM_ALLOC_INT )
  698. break; /* got the interrupt */
  699. timeout--;
  700. }
  701. /* there is really nothing that I can do here if timeout fails,
  702. as probe_irq_off will return a 0 anyway, which is what I
  703. want in this case. Plus, the clean up is needed in both
  704. cases. */
  705. /* DELAY HERE!
  706. On a fast machine, the status might change before the interrupt
  707. is given to the processor. This means that the interrupt was
  708. never detected, and probe_irq_off fails to report anything.
  709. This should fix probe_irq_* problems.
  710. */
  711. SMC_DELAY();
  712. SMC_DELAY();
  713. /* and disable all interrupts again */
  714. outb( 0, ioaddr + INT_MASK );
  715. /* and return what I found */
  716. return probe_irq_off(cookie);
  717. #else /* NO_AUTOPROBE */
  718. struct devlist *smcdev;
  719. for (smcdev = smc_devlist; smcdev->port; smcdev++) {
  720. if (smcdev->port == ioaddr)
  721. return smcdev->irq;
  722. }
  723. return 0;
  724. #endif
  725. }
  726. static const struct net_device_ops smc_netdev_ops = {
  727. .ndo_open = smc_open,
  728. .ndo_stop = smc_close,
  729. .ndo_start_xmit = smc_wait_to_send_packet,
  730. .ndo_tx_timeout = smc_timeout,
  731. .ndo_set_multicast_list = smc_set_multicast_list,
  732. .ndo_change_mtu = eth_change_mtu,
  733. .ndo_set_mac_address = eth_mac_addr,
  734. .ndo_validate_addr = eth_validate_addr,
  735. };
  736. /*----------------------------------------------------------------------
  737. . Function: smc_probe( int ioaddr )
  738. .
  739. . Purpose:
  740. . Tests to see if a given ioaddr points to an SMC9xxx chip.
  741. . Returns a 0 on success
  742. .
  743. . Algorithm:
  744. . (1) see if the high byte of BANK_SELECT is 0x33
  745. . (2) compare the ioaddr with the base register's address
  746. . (3) see if I recognize the chip ID in the appropriate register
  747. .
  748. .---------------------------------------------------------------------
  749. */
  750. /*---------------------------------------------------------------
  751. . Here I do typical initialization tasks.
  752. .
  753. . o Initialize the structure if needed
  754. . o print out my vanity message if not done so already
  755. . o print out what type of hardware is detected
  756. . o print out the ethernet address
  757. . o find the IRQ
  758. . o set up my private data
  759. . o configure the dev structure with my subroutines
  760. . o actually GRAB the irq.
  761. . o GRAB the region
  762. .-----------------------------------------------------------------
  763. */
  764. static int __init smc_probe(struct net_device *dev, int ioaddr)
  765. {
  766. int i, memory, retval;
  767. static unsigned version_printed;
  768. unsigned int bank;
  769. const char *version_string;
  770. const char *if_string;
  771. /* registers */
  772. word revision_register;
  773. word base_address_register;
  774. word configuration_register;
  775. word memory_info_register;
  776. word memory_cfg_register;
  777. /* Grab the region so that no one else tries to probe our ioports. */
  778. if (!request_region(ioaddr, SMC_IO_EXTENT, DRV_NAME))
  779. return -EBUSY;
  780. dev->irq = irq;
  781. dev->if_port = ifport;
  782. /* First, see if the high byte is 0x33 */
  783. bank = inw( ioaddr + BANK_SELECT );
  784. if ( (bank & 0xFF00) != 0x3300 ) {
  785. retval = -ENODEV;
  786. goto err_out;
  787. }
  788. /* The above MIGHT indicate a device, but I need to write to further
  789. test this. */
  790. outw( 0x0, ioaddr + BANK_SELECT );
  791. bank = inw( ioaddr + BANK_SELECT );
  792. if ( (bank & 0xFF00 ) != 0x3300 ) {
  793. retval = -ENODEV;
  794. goto err_out;
  795. }
  796. #if !defined(CONFIG_H8S_EDOSK2674)
  797. /* well, we've already written once, so hopefully another time won't
  798. hurt. This time, I need to switch the bank register to bank 1,
  799. so I can access the base address register */
  800. SMC_SELECT_BANK(1);
  801. base_address_register = inw( ioaddr + BASE );
  802. if ( ioaddr != ( base_address_register >> 3 & 0x3E0 ) ) {
  803. printk(CARDNAME ": IOADDR %x doesn't match configuration (%x). "
  804. "Probably not a SMC chip\n",
  805. ioaddr, base_address_register >> 3 & 0x3E0 );
  806. /* well, the base address register didn't match. Must not have
  807. been a SMC chip after all. */
  808. retval = -ENODEV;
  809. goto err_out;
  810. }
  811. #else
  812. (void)base_address_register; /* Warning suppression */
  813. #endif
  814. /* check if the revision register is something that I recognize.
  815. These might need to be added to later, as future revisions
  816. could be added. */
  817. SMC_SELECT_BANK(3);
  818. revision_register = inw( ioaddr + REVISION );
  819. if ( !chip_ids[ ( revision_register >> 4 ) & 0xF ] ) {
  820. /* I don't recognize this chip, so... */
  821. printk(CARDNAME ": IO %x: Unrecognized revision register:"
  822. " %x, Contact author. \n", ioaddr, revision_register );
  823. retval = -ENODEV;
  824. goto err_out;
  825. }
  826. /* at this point I'll assume that the chip is an SMC9xxx.
  827. It might be prudent to check a listing of MAC addresses
  828. against the hardware address, or do some other tests. */
  829. if (version_printed++ == 0)
  830. printk("%s", version);
  831. /* fill in some of the fields */
  832. dev->base_addr = ioaddr;
  833. /*
  834. . Get the MAC address ( bank 1, regs 4 - 9 )
  835. */
  836. SMC_SELECT_BANK( 1 );
  837. for ( i = 0; i < 6; i += 2 ) {
  838. word address;
  839. address = inw( ioaddr + ADDR0 + i );
  840. dev->dev_addr[ i + 1] = address >> 8;
  841. dev->dev_addr[ i ] = address & 0xFF;
  842. }
  843. /* get the memory information */
  844. SMC_SELECT_BANK( 0 );
  845. memory_info_register = inw( ioaddr + MIR );
  846. memory_cfg_register = inw( ioaddr + MCR );
  847. memory = ( memory_cfg_register >> 9 ) & 0x7; /* multiplier */
  848. memory *= 256 * ( memory_info_register & 0xFF );
  849. /*
  850. Now, I want to find out more about the chip. This is sort of
  851. redundant, but it's cleaner to have it in both, rather than having
  852. one VERY long probe procedure.
  853. */
  854. SMC_SELECT_BANK(3);
  855. revision_register = inw( ioaddr + REVISION );
  856. version_string = chip_ids[ ( revision_register >> 4 ) & 0xF ];
  857. if ( !version_string ) {
  858. /* I shouldn't get here because this call was done before.... */
  859. retval = -ENODEV;
  860. goto err_out;
  861. }
  862. /* is it using AUI or 10BaseT ? */
  863. if ( dev->if_port == 0 ) {
  864. SMC_SELECT_BANK(1);
  865. configuration_register = inw( ioaddr + CONFIG );
  866. if ( configuration_register & CFG_AUI_SELECT )
  867. dev->if_port = 2;
  868. else
  869. dev->if_port = 1;
  870. }
  871. if_string = interfaces[ dev->if_port - 1 ];
  872. /* now, reset the chip, and put it into a known state */
  873. smc_reset( ioaddr );
  874. /*
  875. . If dev->irq is 0, then the device has to be banged on to see
  876. . what the IRQ is.
  877. .
  878. . This banging doesn't always detect the IRQ, for unknown reasons.
  879. . a workaround is to reset the chip and try again.
  880. .
  881. . Interestingly, the DOS packet driver *SETS* the IRQ on the card to
  882. . be what is requested on the command line. I don't do that, mostly
  883. . because the card that I have uses a non-standard method of accessing
  884. . the IRQs, and because this _should_ work in most configurations.
  885. .
  886. . Specifying an IRQ is done with the assumption that the user knows
  887. . what (s)he is doing. No checking is done!!!!
  888. .
  889. */
  890. if ( dev->irq < 2 ) {
  891. int trials;
  892. trials = 3;
  893. while ( trials-- ) {
  894. dev->irq = smc_findirq( ioaddr );
  895. if ( dev->irq )
  896. break;
  897. /* kick the card and try again */
  898. smc_reset( ioaddr );
  899. }
  900. }
  901. if (dev->irq == 0 ) {
  902. printk(CARDNAME": Couldn't autodetect your IRQ. Use irq=xx.\n");
  903. retval = -ENODEV;
  904. goto err_out;
  905. }
  906. /* now, print out the card info, in a short format.. */
  907. printk("%s: %s(r:%d) at %#3x IRQ:%d INTF:%s MEM:%db ", dev->name,
  908. version_string, revision_register & 0xF, ioaddr, dev->irq,
  909. if_string, memory );
  910. /*
  911. . Print the Ethernet address
  912. */
  913. printk("ADDR: %pM\n", dev->dev_addr);
  914. /* set the private data to zero by default */
  915. memset(netdev_priv(dev), 0, sizeof(struct smc_local));
  916. /* Grab the IRQ */
  917. retval = request_irq(dev->irq, &smc_interrupt, 0, DRV_NAME, dev);
  918. if (retval) {
  919. printk("%s: unable to get IRQ %d (irqval=%d).\n", DRV_NAME,
  920. dev->irq, retval);
  921. goto err_out;
  922. }
  923. dev->netdev_ops = &smc_netdev_ops;
  924. dev->watchdog_timeo = HZ/20;
  925. return 0;
  926. err_out:
  927. release_region(ioaddr, SMC_IO_EXTENT);
  928. return retval;
  929. }
  930. #if SMC_DEBUG > 2
  931. static void print_packet( byte * buf, int length )
  932. {
  933. #if 0
  934. int i;
  935. int remainder;
  936. int lines;
  937. printk("Packet of length %d \n", length );
  938. lines = length / 16;
  939. remainder = length % 16;
  940. for ( i = 0; i < lines ; i ++ ) {
  941. int cur;
  942. for ( cur = 0; cur < 8; cur ++ ) {
  943. byte a, b;
  944. a = *(buf ++ );
  945. b = *(buf ++ );
  946. printk("%02x%02x ", a, b );
  947. }
  948. printk("\n");
  949. }
  950. for ( i = 0; i < remainder/2 ; i++ ) {
  951. byte a, b;
  952. a = *(buf ++ );
  953. b = *(buf ++ );
  954. printk("%02x%02x ", a, b );
  955. }
  956. printk("\n");
  957. #endif
  958. }
  959. #endif
  960. /*
  961. * Open and Initialize the board
  962. *
  963. * Set up everything, reset the card, etc ..
  964. *
  965. */
  966. static int smc_open(struct net_device *dev)
  967. {
  968. int ioaddr = dev->base_addr;
  969. int i; /* used to set hw ethernet address */
  970. /* clear out all the junk that was put here before... */
  971. memset(netdev_priv(dev), 0, sizeof(struct smc_local));
  972. /* reset the hardware */
  973. smc_reset( ioaddr );
  974. smc_enable( ioaddr );
  975. /* Select which interface to use */
  976. SMC_SELECT_BANK( 1 );
  977. if ( dev->if_port == 1 ) {
  978. outw( inw( ioaddr + CONFIG ) & ~CFG_AUI_SELECT,
  979. ioaddr + CONFIG );
  980. }
  981. else if ( dev->if_port == 2 ) {
  982. outw( inw( ioaddr + CONFIG ) | CFG_AUI_SELECT,
  983. ioaddr + CONFIG );
  984. }
  985. /*
  986. According to Becker, I have to set the hardware address
  987. at this point, because the (l)user can set it with an
  988. ioctl. Easily done...
  989. */
  990. SMC_SELECT_BANK( 1 );
  991. for ( i = 0; i < 6; i += 2 ) {
  992. word address;
  993. address = dev->dev_addr[ i + 1 ] << 8 ;
  994. address |= dev->dev_addr[ i ];
  995. outw( address, ioaddr + ADDR0 + i );
  996. }
  997. netif_start_queue(dev);
  998. return 0;
  999. }
  1000. /*--------------------------------------------------------
  1001. . Called by the kernel to send a packet out into the void
  1002. . of the net. This routine is largely based on
  1003. . skeleton.c, from Becker.
  1004. .--------------------------------------------------------
  1005. */
  1006. static void smc_timeout(struct net_device *dev)
  1007. {
  1008. /* If we get here, some higher level has decided we are broken.
  1009. There should really be a "kick me" function call instead. */
  1010. printk(KERN_WARNING CARDNAME": transmit timed out, %s?\n",
  1011. tx_done(dev) ? "IRQ conflict" :
  1012. "network cable problem");
  1013. /* "kick" the adaptor */
  1014. smc_reset( dev->base_addr );
  1015. smc_enable( dev->base_addr );
  1016. dev->trans_start = jiffies;
  1017. /* clear anything saved */
  1018. ((struct smc_local *)netdev_priv(dev))->saved_skb = NULL;
  1019. netif_wake_queue(dev);
  1020. }
  1021. /*-------------------------------------------------------------
  1022. .
  1023. . smc_rcv - receive a packet from the card
  1024. .
  1025. . There is ( at least ) a packet waiting to be read from
  1026. . chip-memory.
  1027. .
  1028. . o Read the status
  1029. . o If an error, record it
  1030. . o otherwise, read in the packet
  1031. --------------------------------------------------------------
  1032. */
  1033. static void smc_rcv(struct net_device *dev)
  1034. {
  1035. int ioaddr = dev->base_addr;
  1036. int packet_number;
  1037. word status;
  1038. word packet_length;
  1039. /* assume bank 2 */
  1040. packet_number = inw( ioaddr + FIFO_PORTS );
  1041. if ( packet_number & FP_RXEMPTY ) {
  1042. /* we got called , but nothing was on the FIFO */
  1043. PRINTK((CARDNAME ": WARNING: smc_rcv with nothing on FIFO. \n"));
  1044. /* don't need to restore anything */
  1045. return;
  1046. }
  1047. /* start reading from the start of the packet */
  1048. outw( PTR_READ | PTR_RCV | PTR_AUTOINC, ioaddr + POINTER );
  1049. /* First two words are status and packet_length */
  1050. status = inw( ioaddr + DATA_1 );
  1051. packet_length = inw( ioaddr + DATA_1 );
  1052. packet_length &= 0x07ff; /* mask off top bits */
  1053. PRINTK2(("RCV: STATUS %4x LENGTH %4x\n", status, packet_length ));
  1054. /*
  1055. . the packet length contains 3 extra words :
  1056. . status, length, and an extra word with an odd byte .
  1057. */
  1058. packet_length -= 6;
  1059. if ( !(status & RS_ERRORS ) ){
  1060. /* do stuff to make a new packet */
  1061. struct sk_buff * skb;
  1062. byte * data;
  1063. /* read one extra byte */
  1064. if ( status & RS_ODDFRAME )
  1065. packet_length++;
  1066. /* set multicast stats */
  1067. if ( status & RS_MULTICAST )
  1068. dev->stats.multicast++;
  1069. skb = dev_alloc_skb( packet_length + 5);
  1070. if ( skb == NULL ) {
  1071. printk(KERN_NOTICE CARDNAME ": Low memory, packet dropped.\n");
  1072. dev->stats.rx_dropped++;
  1073. goto done;
  1074. }
  1075. /*
  1076. ! This should work without alignment, but it could be
  1077. ! in the worse case
  1078. */
  1079. skb_reserve( skb, 2 ); /* 16 bit alignment */
  1080. data = skb_put( skb, packet_length);
  1081. #ifdef USE_32_BIT
  1082. /* QUESTION: Like in the TX routine, do I want
  1083. to send the DWORDs or the bytes first, or some
  1084. mixture. A mixture might improve already slow PIO
  1085. performance */
  1086. PRINTK3((" Reading %d dwords (and %d bytes) \n",
  1087. packet_length >> 2, packet_length & 3 ));
  1088. insl(ioaddr + DATA_1 , data, packet_length >> 2 );
  1089. /* read the left over bytes */
  1090. insb( ioaddr + DATA_1, data + (packet_length & 0xFFFFFC),
  1091. packet_length & 0x3 );
  1092. #else
  1093. PRINTK3((" Reading %d words and %d byte(s) \n",
  1094. (packet_length >> 1 ), packet_length & 1 ));
  1095. insw(ioaddr + DATA_1 , data, packet_length >> 1);
  1096. if ( packet_length & 1 ) {
  1097. data += packet_length & ~1;
  1098. *(data++) = inb( ioaddr + DATA_1 );
  1099. }
  1100. #endif
  1101. #if SMC_DEBUG > 2
  1102. print_packet( data, packet_length );
  1103. #endif
  1104. skb->protocol = eth_type_trans(skb, dev );
  1105. netif_rx(skb);
  1106. dev->stats.rx_packets++;
  1107. dev->stats.rx_bytes += packet_length;
  1108. } else {
  1109. /* error ... */
  1110. dev->stats.rx_errors++;
  1111. if ( status & RS_ALGNERR ) dev->stats.rx_frame_errors++;
  1112. if ( status & (RS_TOOSHORT | RS_TOOLONG ) )
  1113. dev->stats.rx_length_errors++;
  1114. if ( status & RS_BADCRC) dev->stats.rx_crc_errors++;
  1115. }
  1116. done:
  1117. /* error or good, tell the card to get rid of this packet */
  1118. outw( MC_RELEASE, ioaddr + MMU_CMD );
  1119. }
  1120. /*************************************************************************
  1121. . smc_tx
  1122. .
  1123. . Purpose: Handle a transmit error message. This will only be called
  1124. . when an error, because of the AUTO_RELEASE mode.
  1125. .
  1126. . Algorithm:
  1127. . Save pointer and packet no
  1128. . Get the packet no from the top of the queue
  1129. . check if it's valid ( if not, is this an error??? )
  1130. . read the status word
  1131. . record the error
  1132. . ( resend? Not really, since we don't want old packets around )
  1133. . Restore saved values
  1134. ************************************************************************/
  1135. static void smc_tx( struct net_device * dev )
  1136. {
  1137. int ioaddr = dev->base_addr;
  1138. struct smc_local *lp = netdev_priv(dev);
  1139. byte saved_packet;
  1140. byte packet_no;
  1141. word tx_status;
  1142. /* assume bank 2 */
  1143. saved_packet = inb( ioaddr + PNR_ARR );
  1144. packet_no = inw( ioaddr + FIFO_PORTS );
  1145. packet_no &= 0x7F;
  1146. /* select this as the packet to read from */
  1147. outb( packet_no, ioaddr + PNR_ARR );
  1148. /* read the first word from this packet */
  1149. outw( PTR_AUTOINC | PTR_READ, ioaddr + POINTER );
  1150. tx_status = inw( ioaddr + DATA_1 );
  1151. PRINTK3((CARDNAME": TX DONE STATUS: %4x \n", tx_status ));
  1152. dev->stats.tx_errors++;
  1153. if ( tx_status & TS_LOSTCAR ) dev->stats.tx_carrier_errors++;
  1154. if ( tx_status & TS_LATCOL ) {
  1155. printk(KERN_DEBUG CARDNAME
  1156. ": Late collision occurred on last xmit.\n");
  1157. dev->stats.tx_window_errors++;
  1158. }
  1159. #if 0
  1160. if ( tx_status & TS_16COL ) { ... }
  1161. #endif
  1162. if ( tx_status & TS_SUCCESS ) {
  1163. printk(CARDNAME": Successful packet caused interrupt \n");
  1164. }
  1165. /* re-enable transmit */
  1166. SMC_SELECT_BANK( 0 );
  1167. outw( inw( ioaddr + TCR ) | TCR_ENABLE, ioaddr + TCR );
  1168. /* kill the packet */
  1169. SMC_SELECT_BANK( 2 );
  1170. outw( MC_FREEPKT, ioaddr + MMU_CMD );
  1171. /* one less packet waiting for me */
  1172. lp->packets_waiting--;
  1173. outb( saved_packet, ioaddr + PNR_ARR );
  1174. return;
  1175. }
  1176. /*--------------------------------------------------------------------
  1177. .
  1178. . This is the main routine of the driver, to handle the device when
  1179. . it needs some attention.
  1180. .
  1181. . So:
  1182. . first, save state of the chipset
  1183. . branch off into routines to handle each case, and acknowledge
  1184. . each to the interrupt register
  1185. . and finally restore state.
  1186. .
  1187. ---------------------------------------------------------------------*/
  1188. static irqreturn_t smc_interrupt(int irq, void * dev_id)
  1189. {
  1190. struct net_device *dev = dev_id;
  1191. int ioaddr = dev->base_addr;
  1192. struct smc_local *lp = netdev_priv(dev);
  1193. byte status;
  1194. word card_stats;
  1195. byte mask;
  1196. int timeout;
  1197. /* state registers */
  1198. word saved_bank;
  1199. word saved_pointer;
  1200. int handled = 0;
  1201. PRINTK3((CARDNAME": SMC interrupt started \n"));
  1202. saved_bank = inw( ioaddr + BANK_SELECT );
  1203. SMC_SELECT_BANK(2);
  1204. saved_pointer = inw( ioaddr + POINTER );
  1205. mask = inb( ioaddr + INT_MASK );
  1206. /* clear all interrupts */
  1207. outb( 0, ioaddr + INT_MASK );
  1208. /* set a timeout value, so I don't stay here forever */
  1209. timeout = 4;
  1210. PRINTK2((KERN_WARNING CARDNAME ": MASK IS %x \n", mask ));
  1211. do {
  1212. /* read the status flag, and mask it */
  1213. status = inb( ioaddr + INTERRUPT ) & mask;
  1214. if (!status )
  1215. break;
  1216. handled = 1;
  1217. PRINTK3((KERN_WARNING CARDNAME
  1218. ": Handling interrupt status %x \n", status ));
  1219. if (status & IM_RCV_INT) {
  1220. /* Got a packet(s). */
  1221. PRINTK2((KERN_WARNING CARDNAME
  1222. ": Receive Interrupt\n"));
  1223. smc_rcv(dev);
  1224. } else if (status & IM_TX_INT ) {
  1225. PRINTK2((KERN_WARNING CARDNAME
  1226. ": TX ERROR handled\n"));
  1227. smc_tx(dev);
  1228. outb(IM_TX_INT, ioaddr + INTERRUPT );
  1229. } else if (status & IM_TX_EMPTY_INT ) {
  1230. /* update stats */
  1231. SMC_SELECT_BANK( 0 );
  1232. card_stats = inw( ioaddr + COUNTER );
  1233. /* single collisions */
  1234. dev->stats.collisions += card_stats & 0xF;
  1235. card_stats >>= 4;
  1236. /* multiple collisions */
  1237. dev->stats.collisions += card_stats & 0xF;
  1238. /* these are for when linux supports these statistics */
  1239. SMC_SELECT_BANK( 2 );
  1240. PRINTK2((KERN_WARNING CARDNAME
  1241. ": TX_BUFFER_EMPTY handled\n"));
  1242. outb( IM_TX_EMPTY_INT, ioaddr + INTERRUPT );
  1243. mask &= ~IM_TX_EMPTY_INT;
  1244. dev->stats.tx_packets += lp->packets_waiting;
  1245. lp->packets_waiting = 0;
  1246. } else if (status & IM_ALLOC_INT ) {
  1247. PRINTK2((KERN_DEBUG CARDNAME
  1248. ": Allocation interrupt \n"));
  1249. /* clear this interrupt so it doesn't happen again */
  1250. mask &= ~IM_ALLOC_INT;
  1251. smc_hardware_send_packet( dev );
  1252. /* enable xmit interrupts based on this */
  1253. mask |= ( IM_TX_EMPTY_INT | IM_TX_INT );
  1254. /* and let the card send more packets to me */
  1255. netif_wake_queue(dev);
  1256. PRINTK2((CARDNAME": Handoff done successfully.\n"));
  1257. } else if (status & IM_RX_OVRN_INT ) {
  1258. dev->stats.rx_errors++;
  1259. dev->stats.rx_fifo_errors++;
  1260. outb( IM_RX_OVRN_INT, ioaddr + INTERRUPT );
  1261. } else if (status & IM_EPH_INT ) {
  1262. PRINTK((CARDNAME ": UNSUPPORTED: EPH INTERRUPT \n"));
  1263. } else if (status & IM_ERCV_INT ) {
  1264. PRINTK((CARDNAME ": UNSUPPORTED: ERCV INTERRUPT \n"));
  1265. outb( IM_ERCV_INT, ioaddr + INTERRUPT );
  1266. }
  1267. } while ( timeout -- );
  1268. /* restore state register */
  1269. SMC_SELECT_BANK( 2 );
  1270. outb( mask, ioaddr + INT_MASK );
  1271. PRINTK3(( KERN_WARNING CARDNAME ": MASK is now %x \n", mask ));
  1272. outw( saved_pointer, ioaddr + POINTER );
  1273. SMC_SELECT_BANK( saved_bank );
  1274. PRINTK3((CARDNAME ": Interrupt done\n"));
  1275. return IRQ_RETVAL(handled);
  1276. }
  1277. /*----------------------------------------------------
  1278. . smc_close
  1279. .
  1280. . this makes the board clean up everything that it can
  1281. . and not talk to the outside world. Caused by
  1282. . an 'ifconfig ethX down'
  1283. .
  1284. -----------------------------------------------------*/
  1285. static int smc_close(struct net_device *dev)
  1286. {
  1287. netif_stop_queue(dev);
  1288. /* clear everything */
  1289. smc_shutdown( dev->base_addr );
  1290. /* Update the statistics here. */
  1291. return 0;
  1292. }
  1293. /*-----------------------------------------------------------
  1294. . smc_set_multicast_list
  1295. .
  1296. . This routine will, depending on the values passed to it,
  1297. . either make it accept multicast packets, go into
  1298. . promiscuous mode ( for TCPDUMP and cousins ) or accept
  1299. . a select set of multicast packets
  1300. */
  1301. static void smc_set_multicast_list(struct net_device *dev)
  1302. {
  1303. short ioaddr = dev->base_addr;
  1304. SMC_SELECT_BANK(0);
  1305. if ( dev->flags & IFF_PROMISC )
  1306. outw( inw(ioaddr + RCR ) | RCR_PROMISC, ioaddr + RCR );
  1307. /* BUG? I never disable promiscuous mode if multicasting was turned on.
  1308. Now, I turn off promiscuous mode, but I don't do anything to multicasting
  1309. when promiscuous mode is turned on.
  1310. */
  1311. /* Here, I am setting this to accept all multicast packets.
  1312. I don't need to zero the multicast table, because the flag is
  1313. checked before the table is
  1314. */
  1315. else if (dev->flags & IFF_ALLMULTI)
  1316. outw( inw(ioaddr + RCR ) | RCR_ALMUL, ioaddr + RCR );
  1317. /* We just get all multicast packets even if we only want them
  1318. . from one source. This will be changed at some future
  1319. . point. */
  1320. else if (dev->mc_count ) {
  1321. /* support hardware multicasting */
  1322. /* be sure I get rid of flags I might have set */
  1323. outw( inw( ioaddr + RCR ) & ~(RCR_PROMISC | RCR_ALMUL),
  1324. ioaddr + RCR );
  1325. /* NOTE: this has to set the bank, so make sure it is the
  1326. last thing called. The bank is set to zero at the top */
  1327. smc_setmulticast( ioaddr, dev->mc_count, dev->mc_list );
  1328. }
  1329. else {
  1330. outw( inw( ioaddr + RCR ) & ~(RCR_PROMISC | RCR_ALMUL),
  1331. ioaddr + RCR );
  1332. /*
  1333. since I'm disabling all multicast entirely, I need to
  1334. clear the multicast list
  1335. */
  1336. SMC_SELECT_BANK( 3 );
  1337. outw( 0, ioaddr + MULTICAST1 );
  1338. outw( 0, ioaddr + MULTICAST2 );
  1339. outw( 0, ioaddr + MULTICAST3 );
  1340. outw( 0, ioaddr + MULTICAST4 );
  1341. }
  1342. }
  1343. #ifdef MODULE
  1344. static struct net_device *devSMC9194;
  1345. MODULE_LICENSE("GPL");
  1346. module_param(io, int, 0);
  1347. module_param(irq, int, 0);
  1348. module_param(ifport, int, 0);
  1349. MODULE_PARM_DESC(io, "SMC 99194 I/O base address");
  1350. MODULE_PARM_DESC(irq, "SMC 99194 IRQ number");
  1351. MODULE_PARM_DESC(ifport, "SMC 99194 interface port (0-default, 1-TP, 2-AUI)");
  1352. int __init init_module(void)
  1353. {
  1354. if (io == 0)
  1355. printk(KERN_WARNING
  1356. CARDNAME": You shouldn't use auto-probing with insmod!\n" );
  1357. /* copy the parameters from insmod into the device structure */
  1358. devSMC9194 = smc_init(-1);
  1359. if (IS_ERR(devSMC9194))
  1360. return PTR_ERR(devSMC9194);
  1361. return 0;
  1362. }
  1363. void __exit cleanup_module(void)
  1364. {
  1365. unregister_netdev(devSMC9194);
  1366. free_irq(devSMC9194->irq, devSMC9194);
  1367. release_region(devSMC9194->base_addr, SMC_IO_EXTENT);
  1368. free_netdev(devSMC9194);
  1369. }
  1370. #endif /* MODULE */