ewrk3.c 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965
  1. /* ewrk3.c: A DIGITAL EtherWORKS 3 ethernet driver for Linux.
  2. Written 1994 by David C. Davies.
  3. Copyright 1994 Digital Equipment Corporation.
  4. This software may be used and distributed according to the terms of
  5. the GNU General Public License, incorporated herein by reference.
  6. This driver is written for the Digital Equipment Corporation series
  7. of EtherWORKS ethernet cards:
  8. DE203 Turbo (BNC)
  9. DE204 Turbo (TP)
  10. DE205 Turbo (TP BNC)
  11. The driver has been tested on a relatively busy network using the DE205
  12. card and benchmarked with 'ttcp': it transferred 16M of data at 975kB/s
  13. (7.8Mb/s) to a DECstation 5000/200.
  14. The author may be reached at davies@maniac.ultranet.com.
  15. =========================================================================
  16. This driver has been written substantially from scratch, although its
  17. inheritance of style and stack interface from 'depca.c' and in turn from
  18. Donald Becker's 'lance.c' should be obvious.
  19. The DE203/4/5 boards all use a new proprietary chip in place of the
  20. LANCE chip used in prior cards (DEPCA, DE100, DE200/1/2, DE210, DE422).
  21. Use the depca.c driver in the standard distribution for the LANCE based
  22. cards from DIGITAL; this driver will not work with them.
  23. The DE203/4/5 cards have 2 main modes: shared memory and I/O only. I/O
  24. only makes all the card accesses through I/O transactions and no high
  25. (shared) memory is used. This mode provides a >48% performance penalty
  26. and is deprecated in this driver, although allowed to provide initial
  27. setup when hardstrapped.
  28. The shared memory mode comes in 3 flavours: 2kB, 32kB and 64kB. There is
  29. no point in using any mode other than the 2kB mode - their performances
  30. are virtually identical, although the driver has been tested in the 2kB
  31. and 32kB modes. I would suggest you uncomment the line:
  32. FORCE_2K_MODE;
  33. to allow the driver to configure the card as a 2kB card at your current
  34. base address, thus leaving more room to clutter your system box with
  35. other memory hungry boards.
  36. As many ISA and EISA cards can be supported under this driver as you
  37. wish, limited primarily by the available IRQ lines, rather than by the
  38. available I/O addresses (24 ISA, 16 EISA). I have checked different
  39. configurations of multiple depca cards and ewrk3 cards and have not
  40. found a problem yet (provided you have at least depca.c v0.38) ...
  41. The board IRQ setting must be at an unused IRQ which is auto-probed
  42. using Donald Becker's autoprobe routines. All these cards are at
  43. {5,10,11,15}.
  44. No 16MB memory limitation should exist with this driver as DMA is not
  45. used and the common memory area is in low memory on the network card (my
  46. current system has 20MB and I've not had problems yet).
  47. The ability to load this driver as a loadable module has been included
  48. and used extensively during the driver development (to save those long
  49. reboot sequences). To utilise this ability, you have to do 8 things:
  50. 0) have a copy of the loadable modules code installed on your system.
  51. 1) copy ewrk3.c from the /linux/drivers/net directory to your favourite
  52. temporary directory.
  53. 2) edit the source code near line 1898 to reflect the I/O address and
  54. IRQ you're using.
  55. 3) compile ewrk3.c, but include -DMODULE in the command line to ensure
  56. that the correct bits are compiled (see end of source code).
  57. 4) if you are wanting to add a new card, goto 5. Otherwise, recompile a
  58. kernel with the ewrk3 configuration turned off and reboot.
  59. 5) insmod ewrk3.o
  60. [Alan Cox: Changed this so you can insmod ewrk3.o irq=x io=y]
  61. [Adam Kropelin: now accepts irq=x1,x2 io=y1,y2 for multiple cards]
  62. 6) run the net startup bits for your new eth?? interface manually
  63. (usually /etc/rc.inet[12] at boot time).
  64. 7) enjoy!
  65. Note that autoprobing is not allowed in loadable modules - the system is
  66. already up and running and you're messing with interrupts.
  67. To unload a module, turn off the associated interface
  68. 'ifconfig eth?? down' then 'rmmod ewrk3'.
  69. Promiscuous mode has been turned off in this driver, but all the
  70. multicast address bits have been turned on. This improved the send
  71. performance on a busy network by about 13%.
  72. Ioctl's have now been provided (primarily because I wanted to grab some
  73. packet size statistics). They are patterned after 'plipconfig.c' from a
  74. suggestion by Alan Cox. Using these ioctls, you can enable promiscuous
  75. mode, add/delete multicast addresses, change the hardware address, get
  76. packet size distribution statistics and muck around with the control and
  77. status register. I'll add others if and when the need arises.
  78. TO DO:
  79. ------
  80. Revision History
  81. ----------------
  82. Version Date Description
  83. 0.1 26-aug-94 Initial writing. ALPHA code release.
  84. 0.11 31-aug-94 Fixed: 2k mode memory base calc.,
  85. LeMAC version calc.,
  86. IRQ vector assignments during autoprobe.
  87. 0.12 31-aug-94 Tested working on LeMAC2 (DE20[345]-AC) card.
  88. Fixed up MCA hash table algorithm.
  89. 0.20 4-sep-94 Added IOCTL functionality.
  90. 0.21 14-sep-94 Added I/O mode.
  91. 0.21axp 15-sep-94 Special version for ALPHA AXP Linux V1.0.
  92. 0.22 16-sep-94 Added more IOCTLs & tidied up.
  93. 0.23 21-sep-94 Added transmit cut through.
  94. 0.24 31-oct-94 Added uid checks in some ioctls.
  95. 0.30 1-nov-94 BETA code release.
  96. 0.31 5-dec-94 Added check/allocate region code.
  97. 0.32 16-jan-95 Broadcast packet fix.
  98. 0.33 10-Feb-95 Fix recognition bug reported by <bkm@star.rl.ac.uk>.
  99. 0.40 27-Dec-95 Rationalise MODULE and autoprobe code.
  100. Rewrite for portability & updated.
  101. ALPHA support from <jestabro@amt.tay1.dec.com>
  102. Added verify_area() calls in ewrk3_ioctl() from
  103. suggestion by <heiko@colossus.escape.de>.
  104. Add new multicasting code.
  105. 0.41 20-Jan-96 Fix IRQ set up problem reported by
  106. <kenneth@bbs.sas.ntu.ac.sg>.
  107. 0.42 22-Apr-96 Fix alloc_device() bug <jari@markkus2.fimr.fi>
  108. 0.43 16-Aug-96 Update alloc_device() to conform to de4x5.c
  109. 0.44 08-Nov-01 use library crc32 functions <Matt_Domsch@dell.com>
  110. 0.45 19-Jul-02 fix unaligned access on alpha <martin@bruli.net>
  111. 0.46 10-Oct-02 Multiple NIC support when module <akropel1@rochester.rr.com>
  112. 0.47 18-Oct-02 ethtool support <akropel1@rochester.rr.com>
  113. 0.48 18-Oct-02 cli/sti removal for 2.5 <vda@port.imtp.ilyichevsk.odessa.ua>
  114. ioctl locking, signature search cleanup <akropel1@rochester.rr.com>
  115. =========================================================================
  116. */
  117. #include <linux/module.h>
  118. #include <linux/kernel.h>
  119. #include <linux/sched.h>
  120. #include <linux/string.h>
  121. #include <linux/errno.h>
  122. #include <linux/ioport.h>
  123. #include <linux/slab.h>
  124. #include <linux/interrupt.h>
  125. #include <linux/delay.h>
  126. #include <linux/init.h>
  127. #include <linux/crc32.h>
  128. #include <linux/netdevice.h>
  129. #include <linux/etherdevice.h>
  130. #include <linux/skbuff.h>
  131. #include <linux/ethtool.h>
  132. #include <linux/time.h>
  133. #include <linux/types.h>
  134. #include <linux/unistd.h>
  135. #include <linux/ctype.h>
  136. #include <linux/bitops.h>
  137. #include <asm/io.h>
  138. #include <asm/dma.h>
  139. #include <asm/uaccess.h>
  140. #include "ewrk3.h"
  141. #define DRV_NAME "ewrk3"
  142. #define DRV_VERSION "0.48"
  143. static char version[] __initdata =
  144. DRV_NAME ":v" DRV_VERSION " 2002/10/18 davies@maniac.ultranet.com\n";
  145. #ifdef EWRK3_DEBUG
  146. static int ewrk3_debug = EWRK3_DEBUG;
  147. #else
  148. static int ewrk3_debug = 1;
  149. #endif
  150. #define EWRK3_NDA 0xffe0 /* No Device Address */
  151. #define PROBE_LENGTH 32
  152. #define ETH_PROM_SIG 0xAA5500FFUL
  153. #ifndef EWRK3_SIGNATURE
  154. #define EWRK3_SIGNATURE {"DE203","DE204","DE205",""}
  155. #define EWRK3_STRLEN 8
  156. #endif
  157. #ifndef EWRK3_RAM_BASE_ADDRESSES
  158. #define EWRK3_RAM_BASE_ADDRESSES {0xc0000,0xd0000,0x00000}
  159. #endif
  160. /*
  161. ** Sets up the I/O area for the autoprobe.
  162. */
  163. #define EWRK3_IO_BASE 0x100 /* Start address for probe search */
  164. #define EWRK3_IOP_INC 0x20 /* I/O address increment */
  165. #define EWRK3_TOTAL_SIZE 0x20 /* required I/O address length */
  166. #ifndef MAX_NUM_EWRK3S
  167. #define MAX_NUM_EWRK3S 21
  168. #endif
  169. #ifndef EWRK3_EISA_IO_PORTS
  170. #define EWRK3_EISA_IO_PORTS 0x0c00 /* I/O port base address, slot 0 */
  171. #endif
  172. #ifndef MAX_EISA_SLOTS
  173. #define MAX_EISA_SLOTS 16
  174. #define EISA_SLOT_INC 0x1000
  175. #endif
  176. #define QUEUE_PKT_TIMEOUT (1*HZ) /* Jiffies */
  177. /*
  178. ** EtherWORKS 3 shared memory window sizes
  179. */
  180. #define IO_ONLY 0x00
  181. #define SHMEM_2K 0x800
  182. #define SHMEM_32K 0x8000
  183. #define SHMEM_64K 0x10000
  184. /*
  185. ** EtherWORKS 3 IRQ ENABLE/DISABLE
  186. */
  187. #define ENABLE_IRQs { \
  188. icr |= lp->irq_mask;\
  189. outb(icr, EWRK3_ICR); /* Enable the IRQs */\
  190. }
  191. #define DISABLE_IRQs { \
  192. icr = inb(EWRK3_ICR);\
  193. icr &= ~lp->irq_mask;\
  194. outb(icr, EWRK3_ICR); /* Disable the IRQs */\
  195. }
  196. /*
  197. ** EtherWORKS 3 START/STOP
  198. */
  199. #define START_EWRK3 { \
  200. csr = inb(EWRK3_CSR);\
  201. csr &= ~(CSR_TXD|CSR_RXD);\
  202. outb(csr, EWRK3_CSR); /* Enable the TX and/or RX */\
  203. }
  204. #define STOP_EWRK3 { \
  205. csr = (CSR_TXD|CSR_RXD);\
  206. outb(csr, EWRK3_CSR); /* Disable the TX and/or RX */\
  207. }
  208. /*
  209. ** The EtherWORKS 3 private structure
  210. */
  211. #define EWRK3_PKT_STAT_SZ 16
  212. #define EWRK3_PKT_BIN_SZ 128 /* Should be >=100 unless you
  213. increase EWRK3_PKT_STAT_SZ */
  214. struct ewrk3_stats {
  215. u32 bins[EWRK3_PKT_STAT_SZ];
  216. u32 unicast;
  217. u32 multicast;
  218. u32 broadcast;
  219. u32 excessive_collisions;
  220. u32 tx_underruns;
  221. u32 excessive_underruns;
  222. };
  223. struct ewrk3_private {
  224. char adapter_name[80]; /* Name exported to /proc/ioports */
  225. u_long shmem_base; /* Shared memory start address */
  226. void __iomem *shmem;
  227. u_long shmem_length; /* Shared memory window length */
  228. struct ewrk3_stats pktStats; /* Private stats counters */
  229. u_char irq_mask; /* Adapter IRQ mask bits */
  230. u_char mPage; /* Maximum 2kB Page number */
  231. u_char lemac; /* Chip rev. level */
  232. u_char hard_strapped; /* Don't allow a full open */
  233. u_char txc; /* Transmit cut through */
  234. void __iomem *mctbl; /* Pointer to the multicast table */
  235. u_char led_mask; /* Used to reserve LED access for ethtool */
  236. spinlock_t hw_lock;
  237. };
  238. /*
  239. ** Force the EtherWORKS 3 card to be in 2kB MODE
  240. */
  241. #define FORCE_2K_MODE { \
  242. shmem_length = SHMEM_2K;\
  243. outb(((mem_start - 0x80000) >> 11), EWRK3_MBR);\
  244. }
  245. /*
  246. ** Public Functions
  247. */
  248. static int ewrk3_open(struct net_device *dev);
  249. static netdev_tx_t ewrk3_queue_pkt(struct sk_buff *skb, struct net_device *dev);
  250. static irqreturn_t ewrk3_interrupt(int irq, void *dev_id);
  251. static int ewrk3_close(struct net_device *dev);
  252. static void set_multicast_list(struct net_device *dev);
  253. static int ewrk3_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
  254. static const struct ethtool_ops ethtool_ops_203;
  255. static const struct ethtool_ops ethtool_ops;
  256. /*
  257. ** Private functions
  258. */
  259. static int ewrk3_hw_init(struct net_device *dev, u_long iobase);
  260. static void ewrk3_init(struct net_device *dev);
  261. static int ewrk3_rx(struct net_device *dev);
  262. static int ewrk3_tx(struct net_device *dev);
  263. static void ewrk3_timeout(struct net_device *dev);
  264. static void EthwrkSignature(char *name, char *eeprom_image);
  265. static int DevicePresent(u_long iobase);
  266. static void SetMulticastFilter(struct net_device *dev);
  267. static int EISA_signature(char *name, s32 eisa_id);
  268. static int Read_EEPROM(u_long iobase, u_char eaddr);
  269. static int Write_EEPROM(short data, u_long iobase, u_char eaddr);
  270. static u_char get_hw_addr(struct net_device *dev, u_char * eeprom_image, char chipType);
  271. static int ewrk3_probe1(struct net_device *dev, u_long iobase, int irq);
  272. static int isa_probe(struct net_device *dev, u_long iobase);
  273. static int eisa_probe(struct net_device *dev, u_long iobase);
  274. static u_char irq[MAX_NUM_EWRK3S+1] = {5, 0, 10, 3, 11, 9, 15, 12};
  275. static char name[EWRK3_STRLEN + 1];
  276. static int num_ewrks3s;
  277. /*
  278. ** Miscellaneous defines...
  279. */
  280. #define INIT_EWRK3 {\
  281. outb(EEPROM_INIT, EWRK3_IOPR);\
  282. mdelay(1);\
  283. }
  284. #ifndef MODULE
  285. struct net_device * __init ewrk3_probe(int unit)
  286. {
  287. struct net_device *dev = alloc_etherdev(sizeof(struct ewrk3_private));
  288. int err;
  289. if (!dev)
  290. return ERR_PTR(-ENOMEM);
  291. if (unit >= 0) {
  292. sprintf(dev->name, "eth%d", unit);
  293. netdev_boot_setup_check(dev);
  294. }
  295. err = ewrk3_probe1(dev, dev->base_addr, dev->irq);
  296. if (err)
  297. goto out;
  298. return dev;
  299. out:
  300. free_netdev(dev);
  301. return ERR_PTR(err);
  302. }
  303. #endif
  304. static int __init ewrk3_probe1(struct net_device *dev, u_long iobase, int irq)
  305. {
  306. int err;
  307. dev->base_addr = iobase;
  308. dev->irq = irq;
  309. /* Address PROM pattern */
  310. err = isa_probe(dev, iobase);
  311. if (err != 0)
  312. err = eisa_probe(dev, iobase);
  313. if (err)
  314. return err;
  315. err = register_netdev(dev);
  316. if (err)
  317. release_region(dev->base_addr, EWRK3_TOTAL_SIZE);
  318. return err;
  319. }
  320. static const struct net_device_ops ewrk3_netdev_ops = {
  321. .ndo_open = ewrk3_open,
  322. .ndo_start_xmit = ewrk3_queue_pkt,
  323. .ndo_stop = ewrk3_close,
  324. .ndo_set_multicast_list = set_multicast_list,
  325. .ndo_do_ioctl = ewrk3_ioctl,
  326. .ndo_tx_timeout = ewrk3_timeout,
  327. .ndo_change_mtu = eth_change_mtu,
  328. .ndo_set_mac_address = eth_mac_addr,
  329. .ndo_validate_addr = eth_validate_addr,
  330. };
  331. static int __init
  332. ewrk3_hw_init(struct net_device *dev, u_long iobase)
  333. {
  334. struct ewrk3_private *lp;
  335. int i, status = 0;
  336. u_long mem_start, shmem_length;
  337. u_char cr, cmr, icr, nicsr, lemac, hard_strapped = 0;
  338. u_char eeprom_image[EEPROM_MAX], chksum, eisa_cr = 0;
  339. /*
  340. ** Stop the EWRK3. Enable the DBR ROM. Disable interrupts and remote boot.
  341. ** This also disables the EISA_ENABLE bit in the EISA Control Register.
  342. */
  343. if (iobase > 0x400)
  344. eisa_cr = inb(EISA_CR);
  345. INIT_EWRK3;
  346. nicsr = inb(EWRK3_CSR);
  347. icr = inb(EWRK3_ICR);
  348. icr &= 0x70;
  349. outb(icr, EWRK3_ICR); /* Disable all the IRQs */
  350. if (nicsr != (CSR_TXD | CSR_RXD))
  351. return -ENXIO;
  352. /* Check that the EEPROM is alive and well and not living on Pluto... */
  353. for (chksum = 0, i = 0; i < EEPROM_MAX; i += 2) {
  354. union {
  355. short val;
  356. char c[2];
  357. } tmp;
  358. tmp.val = (short) Read_EEPROM(iobase, (i >> 1));
  359. eeprom_image[i] = tmp.c[0];
  360. eeprom_image[i + 1] = tmp.c[1];
  361. chksum += eeprom_image[i] + eeprom_image[i + 1];
  362. }
  363. if (chksum != 0) { /* Bad EEPROM Data! */
  364. printk("%s: Device has a bad on-board EEPROM.\n", dev->name);
  365. return -ENXIO;
  366. }
  367. EthwrkSignature(name, eeprom_image);
  368. if (*name == '\0')
  369. return -ENXIO;
  370. dev->base_addr = iobase;
  371. if (iobase > 0x400) {
  372. outb(eisa_cr, EISA_CR); /* Rewrite the EISA CR */
  373. }
  374. lemac = eeprom_image[EEPROM_CHIPVER];
  375. cmr = inb(EWRK3_CMR);
  376. if (((lemac == LeMAC) && ((cmr & CMR_NO_EEPROM) != CMR_NO_EEPROM)) ||
  377. ((lemac == LeMAC2) && !(cmr & CMR_HS))) {
  378. printk("%s: %s at %#4lx", dev->name, name, iobase);
  379. hard_strapped = 1;
  380. } else if ((iobase & 0x0fff) == EWRK3_EISA_IO_PORTS) {
  381. /* EISA slot address */
  382. printk("%s: %s at %#4lx (EISA slot %ld)",
  383. dev->name, name, iobase, ((iobase >> 12) & 0x0f));
  384. } else { /* ISA port address */
  385. printk("%s: %s at %#4lx", dev->name, name, iobase);
  386. }
  387. printk(", h/w address ");
  388. if (lemac != LeMAC2)
  389. DevicePresent(iobase); /* need after EWRK3_INIT */
  390. status = get_hw_addr(dev, eeprom_image, lemac);
  391. printk("%pM\n", dev->dev_addr);
  392. if (status) {
  393. printk(" which has an EEPROM CRC error.\n");
  394. return -ENXIO;
  395. }
  396. if (lemac == LeMAC2) { /* Special LeMAC2 CMR things */
  397. cmr &= ~(CMR_RA | CMR_WB | CMR_LINK | CMR_POLARITY | CMR_0WS);
  398. if (eeprom_image[EEPROM_MISC0] & READ_AHEAD)
  399. cmr |= CMR_RA;
  400. if (eeprom_image[EEPROM_MISC0] & WRITE_BEHIND)
  401. cmr |= CMR_WB;
  402. if (eeprom_image[EEPROM_NETMAN0] & NETMAN_POL)
  403. cmr |= CMR_POLARITY;
  404. if (eeprom_image[EEPROM_NETMAN0] & NETMAN_LINK)
  405. cmr |= CMR_LINK;
  406. if (eeprom_image[EEPROM_MISC0] & _0WS_ENA)
  407. cmr |= CMR_0WS;
  408. }
  409. if (eeprom_image[EEPROM_SETUP] & SETUP_DRAM)
  410. cmr |= CMR_DRAM;
  411. outb(cmr, EWRK3_CMR);
  412. cr = inb(EWRK3_CR); /* Set up the Control Register */
  413. cr |= eeprom_image[EEPROM_SETUP] & SETUP_APD;
  414. if (cr & SETUP_APD)
  415. cr |= eeprom_image[EEPROM_SETUP] & SETUP_PS;
  416. cr |= eeprom_image[EEPROM_MISC0] & FAST_BUS;
  417. cr |= eeprom_image[EEPROM_MISC0] & ENA_16;
  418. outb(cr, EWRK3_CR);
  419. /*
  420. ** Determine the base address and window length for the EWRK3
  421. ** RAM from the memory base register.
  422. */
  423. mem_start = inb(EWRK3_MBR);
  424. shmem_length = 0;
  425. if (mem_start != 0) {
  426. if ((mem_start >= 0x0a) && (mem_start <= 0x0f)) {
  427. mem_start *= SHMEM_64K;
  428. shmem_length = SHMEM_64K;
  429. } else if ((mem_start >= 0x14) && (mem_start <= 0x1f)) {
  430. mem_start *= SHMEM_32K;
  431. shmem_length = SHMEM_32K;
  432. } else if ((mem_start >= 0x40) && (mem_start <= 0xff)) {
  433. mem_start = mem_start * SHMEM_2K + 0x80000;
  434. shmem_length = SHMEM_2K;
  435. } else {
  436. return -ENXIO;
  437. }
  438. }
  439. /*
  440. ** See the top of this source code for comments about
  441. ** uncommenting this line.
  442. */
  443. /* FORCE_2K_MODE; */
  444. if (hard_strapped) {
  445. printk(" is hard strapped.\n");
  446. } else if (mem_start) {
  447. printk(" has a %dk RAM window", (int) (shmem_length >> 10));
  448. printk(" at 0x%.5lx", mem_start);
  449. } else {
  450. printk(" is in I/O only mode");
  451. }
  452. lp = netdev_priv(dev);
  453. lp->shmem_base = mem_start;
  454. lp->shmem = ioremap(mem_start, shmem_length);
  455. if (!lp->shmem)
  456. return -ENOMEM;
  457. lp->shmem_length = shmem_length;
  458. lp->lemac = lemac;
  459. lp->hard_strapped = hard_strapped;
  460. lp->led_mask = CR_LED;
  461. spin_lock_init(&lp->hw_lock);
  462. lp->mPage = 64;
  463. if (cmr & CMR_DRAM)
  464. lp->mPage <<= 1; /* 2 DRAMS on module */
  465. sprintf(lp->adapter_name, "%s (%s)", name, dev->name);
  466. lp->irq_mask = ICR_TNEM | ICR_TXDM | ICR_RNEM | ICR_RXDM;
  467. if (!hard_strapped) {
  468. /*
  469. ** Enable EWRK3 board interrupts for autoprobing
  470. */
  471. icr |= ICR_IE; /* Enable interrupts */
  472. outb(icr, EWRK3_ICR);
  473. /* The DMA channel may be passed in on this parameter. */
  474. dev->dma = 0;
  475. /* To auto-IRQ we enable the initialization-done and DMA err,
  476. interrupts. For now we will always get a DMA error. */
  477. if (dev->irq < 2) {
  478. #ifndef MODULE
  479. u_char irqnum;
  480. unsigned long irq_mask;
  481. irq_mask = probe_irq_on();
  482. /*
  483. ** Trigger a TNE interrupt.
  484. */
  485. icr |= ICR_TNEM;
  486. outb(1, EWRK3_TDQ); /* Write to the TX done queue */
  487. outb(icr, EWRK3_ICR); /* Unmask the TXD interrupt */
  488. irqnum = irq[((icr & IRQ_SEL) >> 4)];
  489. mdelay(20);
  490. dev->irq = probe_irq_off(irq_mask);
  491. if ((dev->irq) && (irqnum == dev->irq)) {
  492. printk(" and uses IRQ%d.\n", dev->irq);
  493. } else {
  494. if (!dev->irq) {
  495. printk(" and failed to detect IRQ line.\n");
  496. } else if ((irqnum == 1) && (lemac == LeMAC2)) {
  497. printk(" and an illegal IRQ line detected.\n");
  498. } else {
  499. printk(", but incorrect IRQ line detected.\n");
  500. }
  501. iounmap(lp->shmem);
  502. return -ENXIO;
  503. }
  504. DISABLE_IRQs; /* Mask all interrupts */
  505. #endif /* MODULE */
  506. } else {
  507. printk(" and requires IRQ%d.\n", dev->irq);
  508. }
  509. }
  510. if (ewrk3_debug > 1) {
  511. printk(version);
  512. }
  513. /* The EWRK3-specific entries in the device structure. */
  514. dev->netdev_ops = &ewrk3_netdev_ops;
  515. if (lp->adapter_name[4] == '3')
  516. SET_ETHTOOL_OPS(dev, &ethtool_ops_203);
  517. else
  518. SET_ETHTOOL_OPS(dev, &ethtool_ops);
  519. dev->watchdog_timeo = QUEUE_PKT_TIMEOUT;
  520. dev->mem_start = 0;
  521. return 0;
  522. }
  523. static int ewrk3_open(struct net_device *dev)
  524. {
  525. struct ewrk3_private *lp = netdev_priv(dev);
  526. u_long iobase = dev->base_addr;
  527. int status = 0;
  528. u_char icr, csr;
  529. /*
  530. ** Stop the TX and RX...
  531. */
  532. STOP_EWRK3;
  533. if (!lp->hard_strapped) {
  534. if (request_irq(dev->irq, (void *) ewrk3_interrupt, 0, "ewrk3", dev)) {
  535. printk("ewrk3_open(): Requested IRQ%d is busy\n", dev->irq);
  536. status = -EAGAIN;
  537. } else {
  538. /*
  539. ** Re-initialize the EWRK3...
  540. */
  541. ewrk3_init(dev);
  542. if (ewrk3_debug > 1) {
  543. printk("%s: ewrk3 open with irq %d\n", dev->name, dev->irq);
  544. printk(" physical address: %pM\n", dev->dev_addr);
  545. if (lp->shmem_length == 0) {
  546. printk(" no shared memory, I/O only mode\n");
  547. } else {
  548. printk(" start of shared memory: 0x%08lx\n", lp->shmem_base);
  549. printk(" window length: 0x%04lx\n", lp->shmem_length);
  550. }
  551. printk(" # of DRAMS: %d\n", ((inb(EWRK3_CMR) & 0x02) ? 2 : 1));
  552. printk(" csr: 0x%02x\n", inb(EWRK3_CSR));
  553. printk(" cr: 0x%02x\n", inb(EWRK3_CR));
  554. printk(" icr: 0x%02x\n", inb(EWRK3_ICR));
  555. printk(" cmr: 0x%02x\n", inb(EWRK3_CMR));
  556. printk(" fmqc: 0x%02x\n", inb(EWRK3_FMQC));
  557. }
  558. netif_start_queue(dev);
  559. /*
  560. ** Unmask EWRK3 board interrupts
  561. */
  562. icr = inb(EWRK3_ICR);
  563. ENABLE_IRQs;
  564. }
  565. } else {
  566. printk(KERN_ERR "%s: ewrk3 available for hard strapped set up only.\n", dev->name);
  567. printk(KERN_ERR " Run the 'ewrk3setup' utility or remove the hard straps.\n");
  568. return -EINVAL;
  569. }
  570. return status;
  571. }
  572. /*
  573. ** Initialize the EtherWORKS 3 operating conditions
  574. */
  575. static void ewrk3_init(struct net_device *dev)
  576. {
  577. struct ewrk3_private *lp = netdev_priv(dev);
  578. u_char csr, page;
  579. u_long iobase = dev->base_addr;
  580. int i;
  581. /*
  582. ** Enable any multicasts
  583. */
  584. set_multicast_list(dev);
  585. /*
  586. ** Set hardware MAC address. Address is initialized from the EEPROM
  587. ** during startup but may have since been changed by the user.
  588. */
  589. for (i=0; i<ETH_ALEN; i++)
  590. outb(dev->dev_addr[i], EWRK3_PAR0 + i);
  591. /*
  592. ** Clean out any remaining entries in all the queues here
  593. */
  594. while (inb(EWRK3_TQ));
  595. while (inb(EWRK3_TDQ));
  596. while (inb(EWRK3_RQ));
  597. while (inb(EWRK3_FMQ));
  598. /*
  599. ** Write a clean free memory queue
  600. */
  601. for (page = 1; page < lp->mPage; page++) { /* Write the free page numbers */
  602. outb(page, EWRK3_FMQ); /* to the Free Memory Queue */
  603. }
  604. START_EWRK3; /* Enable the TX and/or RX */
  605. }
  606. /*
  607. * Transmit timeout
  608. */
  609. static void ewrk3_timeout(struct net_device *dev)
  610. {
  611. struct ewrk3_private *lp = netdev_priv(dev);
  612. u_char icr, csr;
  613. u_long iobase = dev->base_addr;
  614. if (!lp->hard_strapped)
  615. {
  616. printk(KERN_WARNING"%s: transmit timed/locked out, status %04x, resetting.\n",
  617. dev->name, inb(EWRK3_CSR));
  618. /*
  619. ** Mask all board interrupts
  620. */
  621. DISABLE_IRQs;
  622. /*
  623. ** Stop the TX and RX...
  624. */
  625. STOP_EWRK3;
  626. ewrk3_init(dev);
  627. /*
  628. ** Unmask EWRK3 board interrupts
  629. */
  630. ENABLE_IRQs;
  631. dev->trans_start = jiffies; /* prevent tx timeout */
  632. netif_wake_queue(dev);
  633. }
  634. }
  635. /*
  636. ** Writes a socket buffer to the free page queue
  637. */
  638. static netdev_tx_t ewrk3_queue_pkt(struct sk_buff *skb, struct net_device *dev)
  639. {
  640. struct ewrk3_private *lp = netdev_priv(dev);
  641. u_long iobase = dev->base_addr;
  642. void __iomem *buf = NULL;
  643. u_char icr;
  644. u_char page;
  645. spin_lock_irq (&lp->hw_lock);
  646. DISABLE_IRQs;
  647. /* if no resources available, exit, request packet be queued */
  648. if (inb (EWRK3_FMQC) == 0) {
  649. printk (KERN_WARNING "%s: ewrk3_queue_pkt(): No free resources...\n",
  650. dev->name);
  651. printk (KERN_WARNING "%s: ewrk3_queue_pkt(): CSR: %02x ICR: %02x FMQC: %02x\n",
  652. dev->name, inb (EWRK3_CSR), inb (EWRK3_ICR),
  653. inb (EWRK3_FMQC));
  654. goto err_out;
  655. }
  656. /*
  657. ** Get a free page from the FMQ
  658. */
  659. if ((page = inb (EWRK3_FMQ)) >= lp->mPage) {
  660. printk ("ewrk3_queue_pkt(): Invalid free memory page (%d).\n",
  661. (u_char) page);
  662. goto err_out;
  663. }
  664. /*
  665. ** Set up shared memory window and pointer into the window
  666. */
  667. if (lp->shmem_length == IO_ONLY) {
  668. outb (page, EWRK3_IOPR);
  669. } else if (lp->shmem_length == SHMEM_2K) {
  670. buf = lp->shmem;
  671. outb (page, EWRK3_MPR);
  672. } else if (lp->shmem_length == SHMEM_32K) {
  673. buf = (((short) page << 11) & 0x7800) + lp->shmem;
  674. outb ((page >> 4), EWRK3_MPR);
  675. } else if (lp->shmem_length == SHMEM_64K) {
  676. buf = (((short) page << 11) & 0xf800) + lp->shmem;
  677. outb ((page >> 5), EWRK3_MPR);
  678. } else {
  679. printk (KERN_ERR "%s: Oops - your private data area is hosed!\n",
  680. dev->name);
  681. BUG ();
  682. }
  683. /*
  684. ** Set up the buffer control structures and copy the data from
  685. ** the socket buffer to the shared memory .
  686. */
  687. if (lp->shmem_length == IO_ONLY) {
  688. int i;
  689. u_char *p = skb->data;
  690. outb ((char) (TCR_QMODE | TCR_PAD | TCR_IFC), EWRK3_DATA);
  691. outb ((char) (skb->len & 0xff), EWRK3_DATA);
  692. outb ((char) ((skb->len >> 8) & 0xff), EWRK3_DATA);
  693. outb ((char) 0x04, EWRK3_DATA);
  694. for (i = 0; i < skb->len; i++) {
  695. outb (*p++, EWRK3_DATA);
  696. }
  697. outb (page, EWRK3_TQ); /* Start sending pkt */
  698. } else {
  699. writeb ((char) (TCR_QMODE | TCR_PAD | TCR_IFC), buf); /* ctrl byte */
  700. buf += 1;
  701. writeb ((char) (skb->len & 0xff), buf); /* length (16 bit xfer) */
  702. buf += 1;
  703. if (lp->txc) {
  704. writeb(((skb->len >> 8) & 0xff) | XCT, buf);
  705. buf += 1;
  706. writeb (0x04, buf); /* index byte */
  707. buf += 1;
  708. writeb (0x00, (buf + skb->len)); /* Write the XCT flag */
  709. memcpy_toio (buf, skb->data, PRELOAD); /* Write PRELOAD bytes */
  710. outb (page, EWRK3_TQ); /* Start sending pkt */
  711. memcpy_toio (buf + PRELOAD,
  712. skb->data + PRELOAD,
  713. skb->len - PRELOAD);
  714. writeb (0xff, (buf + skb->len)); /* Write the XCT flag */
  715. } else {
  716. writeb ((skb->len >> 8) & 0xff, buf);
  717. buf += 1;
  718. writeb (0x04, buf); /* index byte */
  719. buf += 1;
  720. memcpy_toio (buf, skb->data, skb->len); /* Write data bytes */
  721. outb (page, EWRK3_TQ); /* Start sending pkt */
  722. }
  723. }
  724. ENABLE_IRQs;
  725. spin_unlock_irq (&lp->hw_lock);
  726. dev->stats.tx_bytes += skb->len;
  727. dev_kfree_skb (skb);
  728. /* Check for free resources: stop Tx queue if there are none */
  729. if (inb (EWRK3_FMQC) == 0)
  730. netif_stop_queue (dev);
  731. return NETDEV_TX_OK;
  732. err_out:
  733. ENABLE_IRQs;
  734. spin_unlock_irq (&lp->hw_lock);
  735. return NETDEV_TX_BUSY;
  736. }
  737. /*
  738. ** The EWRK3 interrupt handler.
  739. */
  740. static irqreturn_t ewrk3_interrupt(int irq, void *dev_id)
  741. {
  742. struct net_device *dev = dev_id;
  743. struct ewrk3_private *lp;
  744. u_long iobase;
  745. u_char icr, cr, csr;
  746. lp = netdev_priv(dev);
  747. iobase = dev->base_addr;
  748. /* get the interrupt information */
  749. csr = inb(EWRK3_CSR);
  750. /*
  751. ** Mask the EWRK3 board interrupts and turn on the LED
  752. */
  753. spin_lock(&lp->hw_lock);
  754. DISABLE_IRQs;
  755. cr = inb(EWRK3_CR);
  756. cr |= lp->led_mask;
  757. outb(cr, EWRK3_CR);
  758. if (csr & CSR_RNE) /* Rx interrupt (packet[s] arrived) */
  759. ewrk3_rx(dev);
  760. if (csr & CSR_TNE) /* Tx interrupt (packet sent) */
  761. ewrk3_tx(dev);
  762. /*
  763. ** Now deal with the TX/RX disable flags. These are set when there
  764. ** are no more resources. If resources free up then enable these
  765. ** interrupts, otherwise mask them - failure to do this will result
  766. ** in the system hanging in an interrupt loop.
  767. */
  768. if (inb(EWRK3_FMQC)) { /* any resources available? */
  769. lp->irq_mask |= ICR_TXDM | ICR_RXDM; /* enable the interrupt source */
  770. csr &= ~(CSR_TXD | CSR_RXD); /* ensure restart of a stalled TX or RX */
  771. outb(csr, EWRK3_CSR);
  772. netif_wake_queue(dev);
  773. } else {
  774. lp->irq_mask &= ~(ICR_TXDM | ICR_RXDM); /* disable the interrupt source */
  775. }
  776. /* Unmask the EWRK3 board interrupts and turn off the LED */
  777. cr &= ~(lp->led_mask);
  778. outb(cr, EWRK3_CR);
  779. ENABLE_IRQs;
  780. spin_unlock(&lp->hw_lock);
  781. return IRQ_HANDLED;
  782. }
  783. /* Called with lp->hw_lock held */
  784. static int ewrk3_rx(struct net_device *dev)
  785. {
  786. struct ewrk3_private *lp = netdev_priv(dev);
  787. u_long iobase = dev->base_addr;
  788. int i, status = 0;
  789. u_char page;
  790. void __iomem *buf = NULL;
  791. while (inb(EWRK3_RQC) && !status) { /* Whilst there's incoming data */
  792. if ((page = inb(EWRK3_RQ)) < lp->mPage) { /* Get next entry's buffer page */
  793. /*
  794. ** Set up shared memory window and pointer into the window
  795. */
  796. if (lp->shmem_length == IO_ONLY) {
  797. outb(page, EWRK3_IOPR);
  798. } else if (lp->shmem_length == SHMEM_2K) {
  799. buf = lp->shmem;
  800. outb(page, EWRK3_MPR);
  801. } else if (lp->shmem_length == SHMEM_32K) {
  802. buf = (((short) page << 11) & 0x7800) + lp->shmem;
  803. outb((page >> 4), EWRK3_MPR);
  804. } else if (lp->shmem_length == SHMEM_64K) {
  805. buf = (((short) page << 11) & 0xf800) + lp->shmem;
  806. outb((page >> 5), EWRK3_MPR);
  807. } else {
  808. status = -1;
  809. printk("%s: Oops - your private data area is hosed!\n", dev->name);
  810. }
  811. if (!status) {
  812. char rx_status;
  813. int pkt_len;
  814. if (lp->shmem_length == IO_ONLY) {
  815. rx_status = inb(EWRK3_DATA);
  816. pkt_len = inb(EWRK3_DATA);
  817. pkt_len |= ((u_short) inb(EWRK3_DATA) << 8);
  818. } else {
  819. rx_status = readb(buf);
  820. buf += 1;
  821. pkt_len = readw(buf);
  822. buf += 3;
  823. }
  824. if (!(rx_status & R_ROK)) { /* There was an error. */
  825. dev->stats.rx_errors++; /* Update the error stats. */
  826. if (rx_status & R_DBE)
  827. dev->stats.rx_frame_errors++;
  828. if (rx_status & R_CRC)
  829. dev->stats.rx_crc_errors++;
  830. if (rx_status & R_PLL)
  831. dev->stats.rx_fifo_errors++;
  832. } else {
  833. struct sk_buff *skb;
  834. if ((skb = dev_alloc_skb(pkt_len + 2)) != NULL) {
  835. unsigned char *p;
  836. skb_reserve(skb, 2); /* Align to 16 bytes */
  837. p = skb_put(skb, pkt_len);
  838. if (lp->shmem_length == IO_ONLY) {
  839. *p = inb(EWRK3_DATA); /* dummy read */
  840. for (i = 0; i < pkt_len; i++) {
  841. *p++ = inb(EWRK3_DATA);
  842. }
  843. } else {
  844. memcpy_fromio(p, buf, pkt_len);
  845. }
  846. for (i = 1; i < EWRK3_PKT_STAT_SZ - 1; i++) {
  847. if (pkt_len < i * EWRK3_PKT_BIN_SZ) {
  848. lp->pktStats.bins[i]++;
  849. i = EWRK3_PKT_STAT_SZ;
  850. }
  851. }
  852. p = skb->data; /* Look at the dest addr */
  853. if (p[0] & 0x01) { /* Multicast/Broadcast */
  854. if ((*(s16 *) & p[0] == -1) && (*(s16 *) & p[2] == -1) && (*(s16 *) & p[4] == -1)) {
  855. lp->pktStats.broadcast++;
  856. } else {
  857. lp->pktStats.multicast++;
  858. }
  859. } else if ((*(s16 *) & p[0] == *(s16 *) & dev->dev_addr[0]) &&
  860. (*(s16 *) & p[2] == *(s16 *) & dev->dev_addr[2]) &&
  861. (*(s16 *) & p[4] == *(s16 *) & dev->dev_addr[4])) {
  862. lp->pktStats.unicast++;
  863. }
  864. lp->pktStats.bins[0]++; /* Duplicates stats.rx_packets */
  865. if (lp->pktStats.bins[0] == 0) { /* Reset counters */
  866. memset(&lp->pktStats, 0, sizeof(lp->pktStats));
  867. }
  868. /*
  869. ** Notify the upper protocol layers that there is another
  870. ** packet to handle
  871. */
  872. skb->protocol = eth_type_trans(skb, dev);
  873. netif_rx(skb);
  874. /*
  875. ** Update stats
  876. */
  877. dev->stats.rx_packets++;
  878. dev->stats.rx_bytes += pkt_len;
  879. } else {
  880. printk("%s: Insufficient memory; nuking packet.\n", dev->name);
  881. dev->stats.rx_dropped++; /* Really, deferred. */
  882. break;
  883. }
  884. }
  885. }
  886. /*
  887. ** Return the received buffer to the free memory queue
  888. */
  889. outb(page, EWRK3_FMQ);
  890. } else {
  891. printk("ewrk3_rx(): Illegal page number, page %d\n", page);
  892. printk("ewrk3_rx(): CSR: %02x ICR: %02x FMQC: %02x\n", inb(EWRK3_CSR), inb(EWRK3_ICR), inb(EWRK3_FMQC));
  893. }
  894. }
  895. return status;
  896. }
  897. /*
  898. ** Buffer sent - check for TX buffer errors.
  899. ** Called with lp->hw_lock held
  900. */
  901. static int ewrk3_tx(struct net_device *dev)
  902. {
  903. struct ewrk3_private *lp = netdev_priv(dev);
  904. u_long iobase = dev->base_addr;
  905. u_char tx_status;
  906. while ((tx_status = inb(EWRK3_TDQ)) > 0) { /* Whilst there's old buffers */
  907. if (tx_status & T_VSTS) { /* The status is valid */
  908. if (tx_status & T_TXE) {
  909. dev->stats.tx_errors++;
  910. if (tx_status & T_NCL)
  911. dev->stats.tx_carrier_errors++;
  912. if (tx_status & T_LCL)
  913. dev->stats.tx_window_errors++;
  914. if (tx_status & T_CTU) {
  915. if ((tx_status & T_COLL) ^ T_XUR) {
  916. lp->pktStats.tx_underruns++;
  917. } else {
  918. lp->pktStats.excessive_underruns++;
  919. }
  920. } else if (tx_status & T_COLL) {
  921. if ((tx_status & T_COLL) ^ T_XCOLL) {
  922. dev->stats.collisions++;
  923. } else {
  924. lp->pktStats.excessive_collisions++;
  925. }
  926. }
  927. } else {
  928. dev->stats.tx_packets++;
  929. }
  930. }
  931. }
  932. return 0;
  933. }
  934. static int ewrk3_close(struct net_device *dev)
  935. {
  936. struct ewrk3_private *lp = netdev_priv(dev);
  937. u_long iobase = dev->base_addr;
  938. u_char icr, csr;
  939. netif_stop_queue(dev);
  940. if (ewrk3_debug > 1) {
  941. printk("%s: Shutting down ethercard, status was %2.2x.\n",
  942. dev->name, inb(EWRK3_CSR));
  943. }
  944. /*
  945. ** We stop the EWRK3 here... mask interrupts and stop TX & RX
  946. */
  947. DISABLE_IRQs;
  948. STOP_EWRK3;
  949. /*
  950. ** Clean out the TX and RX queues here (note that one entry
  951. ** may get added to either the TXD or RX queues if the TX or RX
  952. ** just starts processing a packet before the STOP_EWRK3 command
  953. ** is received. This will be flushed in the ewrk3_open() call).
  954. */
  955. while (inb(EWRK3_TQ));
  956. while (inb(EWRK3_TDQ));
  957. while (inb(EWRK3_RQ));
  958. if (!lp->hard_strapped) {
  959. free_irq(dev->irq, dev);
  960. }
  961. return 0;
  962. }
  963. /*
  964. ** Set or clear the multicast filter for this adapter.
  965. */
  966. static void set_multicast_list(struct net_device *dev)
  967. {
  968. struct ewrk3_private *lp = netdev_priv(dev);
  969. u_long iobase = dev->base_addr;
  970. u_char csr;
  971. csr = inb(EWRK3_CSR);
  972. if (lp->shmem_length == IO_ONLY) {
  973. lp->mctbl = NULL;
  974. } else {
  975. lp->mctbl = lp->shmem + PAGE0_HTE;
  976. }
  977. csr &= ~(CSR_PME | CSR_MCE);
  978. if (dev->flags & IFF_PROMISC) { /* set promiscuous mode */
  979. csr |= CSR_PME;
  980. outb(csr, EWRK3_CSR);
  981. } else {
  982. SetMulticastFilter(dev);
  983. csr |= CSR_MCE;
  984. outb(csr, EWRK3_CSR);
  985. }
  986. }
  987. /*
  988. ** Calculate the hash code and update the logical address filter
  989. ** from a list of ethernet multicast addresses.
  990. ** Little endian crc one liner from Matt Thomas, DEC.
  991. **
  992. ** Note that when clearing the table, the broadcast bit must remain asserted
  993. ** to receive broadcast messages.
  994. */
  995. static void SetMulticastFilter(struct net_device *dev)
  996. {
  997. struct ewrk3_private *lp = netdev_priv(dev);
  998. struct netdev_hw_addr *ha;
  999. u_long iobase = dev->base_addr;
  1000. int i;
  1001. char *addrs, bit, byte;
  1002. short __iomem *p = lp->mctbl;
  1003. u16 hashcode;
  1004. u32 crc;
  1005. spin_lock_irq(&lp->hw_lock);
  1006. if (lp->shmem_length == IO_ONLY) {
  1007. outb(0, EWRK3_IOPR);
  1008. outw(PAGE0_HTE, EWRK3_PIR1);
  1009. } else {
  1010. outb(0, EWRK3_MPR);
  1011. }
  1012. if (dev->flags & IFF_ALLMULTI) {
  1013. for (i = 0; i < (HASH_TABLE_LEN >> 3); i++) {
  1014. if (lp->shmem_length == IO_ONLY) {
  1015. outb(0xff, EWRK3_DATA);
  1016. } else { /* memset didn't work here */
  1017. writew(0xffff, p);
  1018. p++;
  1019. i++;
  1020. }
  1021. }
  1022. } else {
  1023. /* Clear table except for broadcast bit */
  1024. if (lp->shmem_length == IO_ONLY) {
  1025. for (i = 0; i < (HASH_TABLE_LEN >> 4) - 1; i++) {
  1026. outb(0x00, EWRK3_DATA);
  1027. }
  1028. outb(0x80, EWRK3_DATA);
  1029. i++; /* insert the broadcast bit */
  1030. for (; i < (HASH_TABLE_LEN >> 3); i++) {
  1031. outb(0x00, EWRK3_DATA);
  1032. }
  1033. } else {
  1034. memset_io(lp->mctbl, 0, HASH_TABLE_LEN >> 3);
  1035. writeb(0x80, lp->mctbl + (HASH_TABLE_LEN >> 4) - 1);
  1036. }
  1037. /* Update table */
  1038. netdev_for_each_mc_addr(ha, dev) {
  1039. addrs = ha->addr;
  1040. if ((*addrs & 0x01) == 1) { /* multicast address? */
  1041. crc = ether_crc_le(ETH_ALEN, addrs);
  1042. hashcode = crc & ((1 << 9) - 1); /* hashcode is 9 LSb of CRC */
  1043. byte = hashcode >> 3; /* bit[3-8] -> byte in filter */
  1044. bit = 1 << (hashcode & 0x07); /* bit[0-2] -> bit in byte */
  1045. if (lp->shmem_length == IO_ONLY) {
  1046. u_char tmp;
  1047. outw(PAGE0_HTE + byte, EWRK3_PIR1);
  1048. tmp = inb(EWRK3_DATA);
  1049. tmp |= bit;
  1050. outw(PAGE0_HTE + byte, EWRK3_PIR1);
  1051. outb(tmp, EWRK3_DATA);
  1052. } else {
  1053. writeb(readb(lp->mctbl + byte) | bit, lp->mctbl + byte);
  1054. }
  1055. }
  1056. }
  1057. }
  1058. spin_unlock_irq(&lp->hw_lock);
  1059. }
  1060. /*
  1061. ** ISA bus I/O device probe
  1062. */
  1063. static int __init isa_probe(struct net_device *dev, u_long ioaddr)
  1064. {
  1065. int i = num_ewrks3s, maxSlots;
  1066. int ret = -ENODEV;
  1067. u_long iobase;
  1068. if (ioaddr >= 0x400)
  1069. goto out;
  1070. if (ioaddr == 0) { /* Autoprobing */
  1071. iobase = EWRK3_IO_BASE; /* Get the first slot address */
  1072. maxSlots = 24;
  1073. } else { /* Probe a specific location */
  1074. iobase = ioaddr;
  1075. maxSlots = i + 1;
  1076. }
  1077. for (; (i < maxSlots) && (dev != NULL);
  1078. iobase += EWRK3_IOP_INC, i++)
  1079. {
  1080. if (request_region(iobase, EWRK3_TOTAL_SIZE, DRV_NAME)) {
  1081. if (DevicePresent(iobase) == 0) {
  1082. int irq = dev->irq;
  1083. ret = ewrk3_hw_init(dev, iobase);
  1084. if (!ret)
  1085. break;
  1086. dev->irq = irq;
  1087. }
  1088. release_region(iobase, EWRK3_TOTAL_SIZE);
  1089. }
  1090. }
  1091. out:
  1092. return ret;
  1093. }
  1094. /*
  1095. ** EISA bus I/O device probe. Probe from slot 1 since slot 0 is usually
  1096. ** the motherboard.
  1097. */
  1098. static int __init eisa_probe(struct net_device *dev, u_long ioaddr)
  1099. {
  1100. int i, maxSlots;
  1101. u_long iobase;
  1102. int ret = -ENODEV;
  1103. if (ioaddr < 0x1000)
  1104. goto out;
  1105. iobase = ioaddr;
  1106. i = (ioaddr >> 12);
  1107. maxSlots = i + 1;
  1108. for (i = 1; (i < maxSlots) && (dev != NULL); i++, iobase += EISA_SLOT_INC) {
  1109. if (EISA_signature(name, EISA_ID) == 0) {
  1110. if (request_region(iobase, EWRK3_TOTAL_SIZE, DRV_NAME) &&
  1111. DevicePresent(iobase) == 0) {
  1112. int irq = dev->irq;
  1113. ret = ewrk3_hw_init(dev, iobase);
  1114. if (!ret)
  1115. break;
  1116. dev->irq = irq;
  1117. }
  1118. release_region(iobase, EWRK3_TOTAL_SIZE);
  1119. }
  1120. }
  1121. out:
  1122. return ret;
  1123. }
  1124. /*
  1125. ** Read the EWRK3 EEPROM using this routine
  1126. */
  1127. static int Read_EEPROM(u_long iobase, u_char eaddr)
  1128. {
  1129. int i;
  1130. outb((eaddr & 0x3f), EWRK3_PIR1); /* set up 6 bits of address info */
  1131. outb(EEPROM_RD, EWRK3_IOPR); /* issue read command */
  1132. for (i = 0; i < 5000; i++)
  1133. inb(EWRK3_CSR); /* wait 1msec */
  1134. return inw(EWRK3_EPROM1); /* 16 bits data return */
  1135. }
  1136. /*
  1137. ** Write the EWRK3 EEPROM using this routine
  1138. */
  1139. static int Write_EEPROM(short data, u_long iobase, u_char eaddr)
  1140. {
  1141. int i;
  1142. outb(EEPROM_WR_EN, EWRK3_IOPR); /* issue write enable command */
  1143. for (i = 0; i < 5000; i++)
  1144. inb(EWRK3_CSR); /* wait 1msec */
  1145. outw(data, EWRK3_EPROM1); /* write data to register */
  1146. outb((eaddr & 0x3f), EWRK3_PIR1); /* set up 6 bits of address info */
  1147. outb(EEPROM_WR, EWRK3_IOPR); /* issue write command */
  1148. for (i = 0; i < 75000; i++)
  1149. inb(EWRK3_CSR); /* wait 15msec */
  1150. outb(EEPROM_WR_DIS, EWRK3_IOPR); /* issue write disable command */
  1151. for (i = 0; i < 5000; i++)
  1152. inb(EWRK3_CSR); /* wait 1msec */
  1153. return 0;
  1154. }
  1155. /*
  1156. ** Look for a particular board name in the on-board EEPROM.
  1157. */
  1158. static void __init EthwrkSignature(char *name, char *eeprom_image)
  1159. {
  1160. int i;
  1161. char *signatures[] = EWRK3_SIGNATURE;
  1162. for (i=0; *signatures[i] != '\0'; i++)
  1163. if( !strncmp(eeprom_image+EEPROM_PNAME7, signatures[i], strlen(signatures[i])) )
  1164. break;
  1165. if (*signatures[i] != '\0') {
  1166. memcpy(name, eeprom_image+EEPROM_PNAME7, EWRK3_STRLEN);
  1167. name[EWRK3_STRLEN] = '\0';
  1168. } else
  1169. name[0] = '\0';
  1170. }
  1171. /*
  1172. ** Look for a special sequence in the Ethernet station address PROM that
  1173. ** is common across all EWRK3 products.
  1174. **
  1175. ** Search the Ethernet address ROM for the signature. Since the ROM address
  1176. ** counter can start at an arbitrary point, the search must include the entire
  1177. ** probe sequence length plus the (length_of_the_signature - 1).
  1178. ** Stop the search IMMEDIATELY after the signature is found so that the
  1179. ** PROM address counter is correctly positioned at the start of the
  1180. ** ethernet address for later read out.
  1181. */
  1182. static int __init DevicePresent(u_long iobase)
  1183. {
  1184. union {
  1185. struct {
  1186. u32 a;
  1187. u32 b;
  1188. } llsig;
  1189. char Sig[sizeof(u32) << 1];
  1190. }
  1191. dev;
  1192. short sigLength;
  1193. char data;
  1194. int i, j, status = 0;
  1195. dev.llsig.a = ETH_PROM_SIG;
  1196. dev.llsig.b = ETH_PROM_SIG;
  1197. sigLength = sizeof(u32) << 1;
  1198. for (i = 0, j = 0; j < sigLength && i < PROBE_LENGTH + sigLength - 1; i++) {
  1199. data = inb(EWRK3_APROM);
  1200. if (dev.Sig[j] == data) { /* track signature */
  1201. j++;
  1202. } else { /* lost signature; begin search again */
  1203. if (data == dev.Sig[0]) {
  1204. j = 1;
  1205. } else {
  1206. j = 0;
  1207. }
  1208. }
  1209. }
  1210. if (j != sigLength) {
  1211. status = -ENODEV; /* search failed */
  1212. }
  1213. return status;
  1214. }
  1215. static u_char __init get_hw_addr(struct net_device *dev, u_char * eeprom_image, char chipType)
  1216. {
  1217. int i, j, k;
  1218. u_short chksum;
  1219. u_char crc, lfsr, sd, status = 0;
  1220. u_long iobase = dev->base_addr;
  1221. u16 tmp;
  1222. if (chipType == LeMAC2) {
  1223. for (crc = 0x6a, j = 0; j < ETH_ALEN; j++) {
  1224. sd = dev->dev_addr[j] = eeprom_image[EEPROM_PADDR0 + j];
  1225. outb(dev->dev_addr[j], EWRK3_PAR0 + j);
  1226. for (k = 0; k < 8; k++, sd >>= 1) {
  1227. lfsr = ((((crc & 0x02) >> 1) ^ (crc & 0x01)) ^ (sd & 0x01)) << 7;
  1228. crc = (crc >> 1) + lfsr;
  1229. }
  1230. }
  1231. if (crc != eeprom_image[EEPROM_PA_CRC])
  1232. status = -1;
  1233. } else {
  1234. for (i = 0, k = 0; i < ETH_ALEN;) {
  1235. k <<= 1;
  1236. if (k > 0xffff)
  1237. k -= 0xffff;
  1238. k += (u_char) (tmp = inb(EWRK3_APROM));
  1239. dev->dev_addr[i] = (u_char) tmp;
  1240. outb(dev->dev_addr[i], EWRK3_PAR0 + i);
  1241. i++;
  1242. k += (u_short) ((tmp = inb(EWRK3_APROM)) << 8);
  1243. dev->dev_addr[i] = (u_char) tmp;
  1244. outb(dev->dev_addr[i], EWRK3_PAR0 + i);
  1245. i++;
  1246. if (k > 0xffff)
  1247. k -= 0xffff;
  1248. }
  1249. if (k == 0xffff)
  1250. k = 0;
  1251. chksum = inb(EWRK3_APROM);
  1252. chksum |= (inb(EWRK3_APROM) << 8);
  1253. if (k != chksum)
  1254. status = -1;
  1255. }
  1256. return status;
  1257. }
  1258. /*
  1259. ** Look for a particular board name in the EISA configuration space
  1260. */
  1261. static int __init EISA_signature(char *name, s32 eisa_id)
  1262. {
  1263. u_long i;
  1264. char *signatures[] = EWRK3_SIGNATURE;
  1265. char ManCode[EWRK3_STRLEN];
  1266. union {
  1267. s32 ID;
  1268. char Id[4];
  1269. } Eisa;
  1270. int status = 0;
  1271. *name = '\0';
  1272. for (i = 0; i < 4; i++) {
  1273. Eisa.Id[i] = inb(eisa_id + i);
  1274. }
  1275. ManCode[0] = (((Eisa.Id[0] >> 2) & 0x1f) + 0x40);
  1276. ManCode[1] = (((Eisa.Id[1] & 0xe0) >> 5) + ((Eisa.Id[0] & 0x03) << 3) + 0x40);
  1277. ManCode[2] = (((Eisa.Id[2] >> 4) & 0x0f) + 0x30);
  1278. ManCode[3] = ((Eisa.Id[2] & 0x0f) + 0x30);
  1279. ManCode[4] = (((Eisa.Id[3] >> 4) & 0x0f) + 0x30);
  1280. ManCode[5] = '\0';
  1281. for (i = 0; (*signatures[i] != '\0') && (*name == '\0'); i++) {
  1282. if (strstr(ManCode, signatures[i]) != NULL) {
  1283. strcpy(name, ManCode);
  1284. status = 1;
  1285. }
  1286. }
  1287. return status; /* return the device name string */
  1288. }
  1289. static void ewrk3_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
  1290. {
  1291. int fwrev = Read_EEPROM(dev->base_addr, EEPROM_REVLVL);
  1292. strcpy(info->driver, DRV_NAME);
  1293. strcpy(info->version, DRV_VERSION);
  1294. sprintf(info->fw_version, "%d", fwrev);
  1295. strcpy(info->bus_info, "N/A");
  1296. info->eedump_len = EEPROM_MAX;
  1297. }
  1298. static int ewrk3_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
  1299. {
  1300. struct ewrk3_private *lp = netdev_priv(dev);
  1301. unsigned long iobase = dev->base_addr;
  1302. u8 cr = inb(EWRK3_CR);
  1303. switch (lp->adapter_name[4]) {
  1304. case '3': /* DE203 */
  1305. ecmd->supported = SUPPORTED_BNC;
  1306. ecmd->port = PORT_BNC;
  1307. break;
  1308. case '4': /* DE204 */
  1309. ecmd->supported = SUPPORTED_TP;
  1310. ecmd->port = PORT_TP;
  1311. break;
  1312. case '5': /* DE205 */
  1313. ecmd->supported = SUPPORTED_TP | SUPPORTED_BNC | SUPPORTED_AUI;
  1314. ecmd->autoneg = !(cr & CR_APD);
  1315. /*
  1316. ** Port is only valid if autoneg is disabled
  1317. ** and even then we don't know if AUI is jumpered.
  1318. */
  1319. if (!ecmd->autoneg)
  1320. ecmd->port = (cr & CR_PSEL) ? PORT_BNC : PORT_TP;
  1321. break;
  1322. }
  1323. ecmd->supported |= SUPPORTED_10baseT_Half;
  1324. ethtool_cmd_speed_set(ecmd, SPEED_10);
  1325. ecmd->duplex = DUPLEX_HALF;
  1326. return 0;
  1327. }
  1328. static int ewrk3_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
  1329. {
  1330. struct ewrk3_private *lp = netdev_priv(dev);
  1331. unsigned long iobase = dev->base_addr;
  1332. unsigned long flags;
  1333. u8 cr;
  1334. /* DE205 is the only card with anything to set */
  1335. if (lp->adapter_name[4] != '5')
  1336. return -EOPNOTSUPP;
  1337. /* Sanity-check parameters */
  1338. if (ecmd->speed != SPEED_10)
  1339. return -EINVAL;
  1340. if (ecmd->port != PORT_TP && ecmd->port != PORT_BNC)
  1341. return -EINVAL; /* AUI is not software-selectable */
  1342. if (ecmd->transceiver != XCVR_INTERNAL)
  1343. return -EINVAL;
  1344. if (ecmd->duplex != DUPLEX_HALF)
  1345. return -EINVAL;
  1346. if (ecmd->phy_address != 0)
  1347. return -EINVAL;
  1348. spin_lock_irqsave(&lp->hw_lock, flags);
  1349. cr = inb(EWRK3_CR);
  1350. /* If Autoneg is set, change to Auto Port mode */
  1351. /* Otherwise, disable Auto Port and set port explicitly */
  1352. if (ecmd->autoneg) {
  1353. cr &= ~CR_APD;
  1354. } else {
  1355. cr |= CR_APD;
  1356. if (ecmd->port == PORT_TP)
  1357. cr &= ~CR_PSEL; /* Force TP */
  1358. else
  1359. cr |= CR_PSEL; /* Force BNC */
  1360. }
  1361. /* Commit the changes */
  1362. outb(cr, EWRK3_CR);
  1363. spin_unlock_irqrestore(&lp->hw_lock, flags);
  1364. return 0;
  1365. }
  1366. static u32 ewrk3_get_link(struct net_device *dev)
  1367. {
  1368. unsigned long iobase = dev->base_addr;
  1369. u8 cmr = inb(EWRK3_CMR);
  1370. /* DE203 has BNC only and link status does not apply */
  1371. /* On DE204 this is always valid since TP is the only port. */
  1372. /* On DE205 this reflects TP status even if BNC or AUI is selected. */
  1373. return !(cmr & CMR_LINK);
  1374. }
  1375. static int ewrk3_set_phys_id(struct net_device *dev,
  1376. enum ethtool_phys_id_state state)
  1377. {
  1378. struct ewrk3_private *lp = netdev_priv(dev);
  1379. unsigned long iobase = dev->base_addr;
  1380. u8 cr;
  1381. spin_lock_irq(&lp->hw_lock);
  1382. switch (state) {
  1383. case ETHTOOL_ID_ACTIVE:
  1384. /* Prevent ISR from twiddling the LED */
  1385. lp->led_mask = 0;
  1386. spin_unlock_irq(&lp->hw_lock);
  1387. return 2; /* cycle on/off twice per second */
  1388. case ETHTOOL_ID_ON:
  1389. cr = inb(EWRK3_CR);
  1390. outb(cr | CR_LED, EWRK3_CR);
  1391. break;
  1392. case ETHTOOL_ID_OFF:
  1393. cr = inb(EWRK3_CR);
  1394. outb(cr & ~CR_LED, EWRK3_CR);
  1395. break;
  1396. case ETHTOOL_ID_INACTIVE:
  1397. lp->led_mask = CR_LED;
  1398. cr = inb(EWRK3_CR);
  1399. outb(cr & ~CR_LED, EWRK3_CR);
  1400. }
  1401. spin_unlock_irq(&lp->hw_lock);
  1402. return 0;
  1403. }
  1404. static const struct ethtool_ops ethtool_ops_203 = {
  1405. .get_drvinfo = ewrk3_get_drvinfo,
  1406. .get_settings = ewrk3_get_settings,
  1407. .set_settings = ewrk3_set_settings,
  1408. .set_phys_id = ewrk3_set_phys_id,
  1409. };
  1410. static const struct ethtool_ops ethtool_ops = {
  1411. .get_drvinfo = ewrk3_get_drvinfo,
  1412. .get_settings = ewrk3_get_settings,
  1413. .set_settings = ewrk3_set_settings,
  1414. .get_link = ewrk3_get_link,
  1415. .set_phys_id = ewrk3_set_phys_id,
  1416. };
  1417. /*
  1418. ** Perform IOCTL call functions here. Some are privileged operations and the
  1419. ** effective uid is checked in those cases.
  1420. */
  1421. static int ewrk3_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  1422. {
  1423. struct ewrk3_private *lp = netdev_priv(dev);
  1424. struct ewrk3_ioctl *ioc = (struct ewrk3_ioctl *) &rq->ifr_ifru;
  1425. u_long iobase = dev->base_addr;
  1426. int i, j, status = 0;
  1427. u_char csr;
  1428. unsigned long flags;
  1429. union ewrk3_addr {
  1430. u_char addr[HASH_TABLE_LEN * ETH_ALEN];
  1431. u_short val[(HASH_TABLE_LEN * ETH_ALEN) >> 1];
  1432. };
  1433. union ewrk3_addr *tmp;
  1434. /* All we handle are private IOCTLs */
  1435. if (cmd != EWRK3IOCTL)
  1436. return -EOPNOTSUPP;
  1437. tmp = kmalloc(sizeof(union ewrk3_addr), GFP_KERNEL);
  1438. if(tmp==NULL)
  1439. return -ENOMEM;
  1440. switch (ioc->cmd) {
  1441. case EWRK3_GET_HWADDR: /* Get the hardware address */
  1442. for (i = 0; i < ETH_ALEN; i++) {
  1443. tmp->addr[i] = dev->dev_addr[i];
  1444. }
  1445. ioc->len = ETH_ALEN;
  1446. if (copy_to_user(ioc->data, tmp->addr, ioc->len))
  1447. status = -EFAULT;
  1448. break;
  1449. case EWRK3_SET_HWADDR: /* Set the hardware address */
  1450. if (capable(CAP_NET_ADMIN)) {
  1451. spin_lock_irqsave(&lp->hw_lock, flags);
  1452. csr = inb(EWRK3_CSR);
  1453. csr |= (CSR_TXD | CSR_RXD);
  1454. outb(csr, EWRK3_CSR); /* Disable the TX and RX */
  1455. spin_unlock_irqrestore(&lp->hw_lock, flags);
  1456. if (copy_from_user(tmp->addr, ioc->data, ETH_ALEN)) {
  1457. status = -EFAULT;
  1458. break;
  1459. }
  1460. spin_lock_irqsave(&lp->hw_lock, flags);
  1461. for (i = 0; i < ETH_ALEN; i++) {
  1462. dev->dev_addr[i] = tmp->addr[i];
  1463. outb(tmp->addr[i], EWRK3_PAR0 + i);
  1464. }
  1465. csr = inb(EWRK3_CSR);
  1466. csr &= ~(CSR_TXD | CSR_RXD); /* Enable the TX and RX */
  1467. outb(csr, EWRK3_CSR);
  1468. spin_unlock_irqrestore(&lp->hw_lock, flags);
  1469. } else {
  1470. status = -EPERM;
  1471. }
  1472. break;
  1473. case EWRK3_SET_PROM: /* Set Promiscuous Mode */
  1474. if (capable(CAP_NET_ADMIN)) {
  1475. spin_lock_irqsave(&lp->hw_lock, flags);
  1476. csr = inb(EWRK3_CSR);
  1477. csr |= CSR_PME;
  1478. csr &= ~CSR_MCE;
  1479. outb(csr, EWRK3_CSR);
  1480. spin_unlock_irqrestore(&lp->hw_lock, flags);
  1481. } else {
  1482. status = -EPERM;
  1483. }
  1484. break;
  1485. case EWRK3_CLR_PROM: /* Clear Promiscuous Mode */
  1486. if (capable(CAP_NET_ADMIN)) {
  1487. spin_lock_irqsave(&lp->hw_lock, flags);
  1488. csr = inb(EWRK3_CSR);
  1489. csr &= ~CSR_PME;
  1490. outb(csr, EWRK3_CSR);
  1491. spin_unlock_irqrestore(&lp->hw_lock, flags);
  1492. } else {
  1493. status = -EPERM;
  1494. }
  1495. break;
  1496. case EWRK3_GET_MCA: /* Get the multicast address table */
  1497. spin_lock_irqsave(&lp->hw_lock, flags);
  1498. if (lp->shmem_length == IO_ONLY) {
  1499. outb(0, EWRK3_IOPR);
  1500. outw(PAGE0_HTE, EWRK3_PIR1);
  1501. for (i = 0; i < (HASH_TABLE_LEN >> 3); i++) {
  1502. tmp->addr[i] = inb(EWRK3_DATA);
  1503. }
  1504. } else {
  1505. outb(0, EWRK3_MPR);
  1506. memcpy_fromio(tmp->addr, lp->shmem + PAGE0_HTE, (HASH_TABLE_LEN >> 3));
  1507. }
  1508. spin_unlock_irqrestore(&lp->hw_lock, flags);
  1509. ioc->len = (HASH_TABLE_LEN >> 3);
  1510. if (copy_to_user(ioc->data, tmp->addr, ioc->len))
  1511. status = -EFAULT;
  1512. break;
  1513. case EWRK3_SET_MCA: /* Set a multicast address */
  1514. if (capable(CAP_NET_ADMIN)) {
  1515. if (ioc->len > HASH_TABLE_LEN) {
  1516. status = -EINVAL;
  1517. break;
  1518. }
  1519. if (copy_from_user(tmp->addr, ioc->data, ETH_ALEN * ioc->len)) {
  1520. status = -EFAULT;
  1521. break;
  1522. }
  1523. set_multicast_list(dev);
  1524. } else {
  1525. status = -EPERM;
  1526. }
  1527. break;
  1528. case EWRK3_CLR_MCA: /* Clear all multicast addresses */
  1529. if (capable(CAP_NET_ADMIN)) {
  1530. set_multicast_list(dev);
  1531. } else {
  1532. status = -EPERM;
  1533. }
  1534. break;
  1535. case EWRK3_MCA_EN: /* Enable multicast addressing */
  1536. if (capable(CAP_NET_ADMIN)) {
  1537. spin_lock_irqsave(&lp->hw_lock, flags);
  1538. csr = inb(EWRK3_CSR);
  1539. csr |= CSR_MCE;
  1540. csr &= ~CSR_PME;
  1541. outb(csr, EWRK3_CSR);
  1542. spin_unlock_irqrestore(&lp->hw_lock, flags);
  1543. } else {
  1544. status = -EPERM;
  1545. }
  1546. break;
  1547. case EWRK3_GET_STATS: { /* Get the driver statistics */
  1548. struct ewrk3_stats *tmp_stats =
  1549. kmalloc(sizeof(lp->pktStats), GFP_KERNEL);
  1550. if (!tmp_stats) {
  1551. status = -ENOMEM;
  1552. break;
  1553. }
  1554. spin_lock_irqsave(&lp->hw_lock, flags);
  1555. memcpy(tmp_stats, &lp->pktStats, sizeof(lp->pktStats));
  1556. spin_unlock_irqrestore(&lp->hw_lock, flags);
  1557. ioc->len = sizeof(lp->pktStats);
  1558. if (copy_to_user(ioc->data, tmp_stats, sizeof(lp->pktStats)))
  1559. status = -EFAULT;
  1560. kfree(tmp_stats);
  1561. break;
  1562. }
  1563. case EWRK3_CLR_STATS: /* Zero out the driver statistics */
  1564. if (capable(CAP_NET_ADMIN)) {
  1565. spin_lock_irqsave(&lp->hw_lock, flags);
  1566. memset(&lp->pktStats, 0, sizeof(lp->pktStats));
  1567. spin_unlock_irqrestore(&lp->hw_lock,flags);
  1568. } else {
  1569. status = -EPERM;
  1570. }
  1571. break;
  1572. case EWRK3_GET_CSR: /* Get the CSR Register contents */
  1573. tmp->addr[0] = inb(EWRK3_CSR);
  1574. ioc->len = 1;
  1575. if (copy_to_user(ioc->data, tmp->addr, ioc->len))
  1576. status = -EFAULT;
  1577. break;
  1578. case EWRK3_SET_CSR: /* Set the CSR Register contents */
  1579. if (capable(CAP_NET_ADMIN)) {
  1580. if (copy_from_user(tmp->addr, ioc->data, 1)) {
  1581. status = -EFAULT;
  1582. break;
  1583. }
  1584. outb(tmp->addr[0], EWRK3_CSR);
  1585. } else {
  1586. status = -EPERM;
  1587. }
  1588. break;
  1589. case EWRK3_GET_EEPROM: /* Get the EEPROM contents */
  1590. if (capable(CAP_NET_ADMIN)) {
  1591. for (i = 0; i < (EEPROM_MAX >> 1); i++) {
  1592. tmp->val[i] = (short) Read_EEPROM(iobase, i);
  1593. }
  1594. i = EEPROM_MAX;
  1595. tmp->addr[i++] = inb(EWRK3_CMR); /* Config/Management Reg. */
  1596. for (j = 0; j < ETH_ALEN; j++) {
  1597. tmp->addr[i++] = inb(EWRK3_PAR0 + j);
  1598. }
  1599. ioc->len = EEPROM_MAX + 1 + ETH_ALEN;
  1600. if (copy_to_user(ioc->data, tmp->addr, ioc->len))
  1601. status = -EFAULT;
  1602. } else {
  1603. status = -EPERM;
  1604. }
  1605. break;
  1606. case EWRK3_SET_EEPROM: /* Set the EEPROM contents */
  1607. if (capable(CAP_NET_ADMIN)) {
  1608. if (copy_from_user(tmp->addr, ioc->data, EEPROM_MAX)) {
  1609. status = -EFAULT;
  1610. break;
  1611. }
  1612. for (i = 0; i < (EEPROM_MAX >> 1); i++) {
  1613. Write_EEPROM(tmp->val[i], iobase, i);
  1614. }
  1615. } else {
  1616. status = -EPERM;
  1617. }
  1618. break;
  1619. case EWRK3_GET_CMR: /* Get the CMR Register contents */
  1620. tmp->addr[0] = inb(EWRK3_CMR);
  1621. ioc->len = 1;
  1622. if (copy_to_user(ioc->data, tmp->addr, ioc->len))
  1623. status = -EFAULT;
  1624. break;
  1625. case EWRK3_SET_TX_CUT_THRU: /* Set TX cut through mode */
  1626. if (capable(CAP_NET_ADMIN)) {
  1627. lp->txc = 1;
  1628. } else {
  1629. status = -EPERM;
  1630. }
  1631. break;
  1632. case EWRK3_CLR_TX_CUT_THRU: /* Clear TX cut through mode */
  1633. if (capable(CAP_NET_ADMIN)) {
  1634. lp->txc = 0;
  1635. } else {
  1636. status = -EPERM;
  1637. }
  1638. break;
  1639. default:
  1640. status = -EOPNOTSUPP;
  1641. }
  1642. kfree(tmp);
  1643. return status;
  1644. }
  1645. #ifdef MODULE
  1646. static struct net_device *ewrk3_devs[MAX_NUM_EWRK3S];
  1647. static int ndevs;
  1648. static int io[MAX_NUM_EWRK3S+1] = { 0x300, 0, };
  1649. /* '21' below should really be 'MAX_NUM_EWRK3S' */
  1650. module_param_array(io, int, NULL, 0);
  1651. module_param_array(irq, int, NULL, 0);
  1652. MODULE_PARM_DESC(io, "EtherWORKS 3 I/O base address(es)");
  1653. MODULE_PARM_DESC(irq, "EtherWORKS 3 IRQ number(s)");
  1654. static __exit void ewrk3_exit_module(void)
  1655. {
  1656. int i;
  1657. for( i=0; i<ndevs; i++ ) {
  1658. struct net_device *dev = ewrk3_devs[i];
  1659. struct ewrk3_private *lp = netdev_priv(dev);
  1660. ewrk3_devs[i] = NULL;
  1661. unregister_netdev(dev);
  1662. release_region(dev->base_addr, EWRK3_TOTAL_SIZE);
  1663. iounmap(lp->shmem);
  1664. free_netdev(dev);
  1665. }
  1666. }
  1667. static __init int ewrk3_init_module(void)
  1668. {
  1669. int i=0;
  1670. while( io[i] && irq[i] ) {
  1671. struct net_device *dev
  1672. = alloc_etherdev(sizeof(struct ewrk3_private));
  1673. if (!dev)
  1674. break;
  1675. if (ewrk3_probe1(dev, io[i], irq[i]) != 0) {
  1676. free_netdev(dev);
  1677. break;
  1678. }
  1679. ewrk3_devs[ndevs++] = dev;
  1680. i++;
  1681. }
  1682. return ndevs ? 0 : -EIO;
  1683. }
  1684. /* Hack for breakage in new module stuff */
  1685. module_exit(ewrk3_exit_module);
  1686. module_init(ewrk3_init_module);
  1687. #endif /* MODULE */
  1688. MODULE_LICENSE("GPL");