smc9194.c 42 KB

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