netwave_cs.c 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452
  1. /*********************************************************************
  2. *
  3. * Filename: netwave_cs.c
  4. * Version: 0.4.1
  5. * Description: Netwave AirSurfer Wireless LAN PC Card driver
  6. * Status: Experimental.
  7. * Authors: John Markus Bjørndalen <johnm@cs.uit.no>
  8. * Dag Brattli <dagb@cs.uit.no>
  9. * David Hinds <dahinds@users.sourceforge.net>
  10. * Created at: A long time ago!
  11. * Modified at: Mon Nov 10 11:54:37 1997
  12. * Modified by: Dag Brattli <dagb@cs.uit.no>
  13. *
  14. * Copyright (c) 1997 University of Tromsø, Norway
  15. *
  16. * Revision History:
  17. *
  18. * 08-Nov-97 15:14:47 John Markus Bjørndalen <johnm@cs.uit.no>
  19. * - Fixed some bugs in netwave_rx and cleaned it up a bit.
  20. * (One of the bugs would have destroyed packets when receiving
  21. * multiple packets per interrupt).
  22. * - Cleaned up parts of newave_hw_xmit.
  23. * - A few general cleanups.
  24. * 24-Oct-97 13:17:36 Dag Brattli <dagb@cs.uit.no>
  25. * - Fixed netwave_rx receive function (got updated docs)
  26. * Others:
  27. * - Changed name from xircnw to netwave, take a look at
  28. * http://www.netwave-wireless.com
  29. * - Some reorganizing of the code
  30. * - Removed possible race condition between interrupt handler and transmit
  31. * function
  32. * - Started to add wireless extensions, but still needs some coding
  33. * - Added watchdog for better handling of transmission timeouts
  34. * (hopefully this works better)
  35. ********************************************************************/
  36. /* To have statistics (just packets sent) define this */
  37. #undef NETWAVE_STATS
  38. #include <linux/config.h>
  39. #include <linux/module.h>
  40. #include <linux/kernel.h>
  41. #include <linux/init.h>
  42. #include <linux/types.h>
  43. #include <linux/fcntl.h>
  44. #include <linux/interrupt.h>
  45. #include <linux/ptrace.h>
  46. #include <linux/ioport.h>
  47. #include <linux/in.h>
  48. #include <linux/slab.h>
  49. #include <linux/string.h>
  50. #include <linux/timer.h>
  51. #include <linux/errno.h>
  52. #include <linux/netdevice.h>
  53. #include <linux/etherdevice.h>
  54. #include <linux/skbuff.h>
  55. #include <linux/bitops.h>
  56. #include <linux/wireless.h>
  57. #include <net/iw_handler.h>
  58. #include <pcmcia/cs_types.h>
  59. #include <pcmcia/cs.h>
  60. #include <pcmcia/cistpl.h>
  61. #include <pcmcia/cisreg.h>
  62. #include <pcmcia/ds.h>
  63. #include <pcmcia/mem_op.h>
  64. #include <asm/system.h>
  65. #include <asm/io.h>
  66. #include <asm/dma.h>
  67. #define NETWAVE_REGOFF 0x8000
  68. /* The Netwave IO registers, offsets to iobase */
  69. #define NETWAVE_REG_COR 0x0
  70. #define NETWAVE_REG_CCSR 0x2
  71. #define NETWAVE_REG_ASR 0x4
  72. #define NETWAVE_REG_IMR 0xa
  73. #define NETWAVE_REG_PMR 0xc
  74. #define NETWAVE_REG_IOLOW 0x6
  75. #define NETWAVE_REG_IOHI 0x7
  76. #define NETWAVE_REG_IOCONTROL 0x8
  77. #define NETWAVE_REG_DATA 0xf
  78. /* The Netwave Extended IO registers, offsets to RamBase */
  79. #define NETWAVE_EREG_ASCC 0x114
  80. #define NETWAVE_EREG_RSER 0x120
  81. #define NETWAVE_EREG_RSERW 0x124
  82. #define NETWAVE_EREG_TSER 0x130
  83. #define NETWAVE_EREG_TSERW 0x134
  84. #define NETWAVE_EREG_CB 0x100
  85. #define NETWAVE_EREG_SPCQ 0x154
  86. #define NETWAVE_EREG_SPU 0x155
  87. #define NETWAVE_EREG_LIF 0x14e
  88. #define NETWAVE_EREG_ISPLQ 0x156
  89. #define NETWAVE_EREG_HHC 0x158
  90. #define NETWAVE_EREG_NI 0x16e
  91. #define NETWAVE_EREG_MHS 0x16b
  92. #define NETWAVE_EREG_TDP 0x140
  93. #define NETWAVE_EREG_RDP 0x150
  94. #define NETWAVE_EREG_PA 0x160
  95. #define NETWAVE_EREG_EC 0x180
  96. #define NETWAVE_EREG_CRBP 0x17a
  97. #define NETWAVE_EREG_ARW 0x166
  98. /*
  99. * Commands used in the extended command buffer
  100. * NETWAVE_EREG_CB (0x100-0x10F)
  101. */
  102. #define NETWAVE_CMD_NOP 0x00
  103. #define NETWAVE_CMD_SRC 0x01
  104. #define NETWAVE_CMD_STC 0x02
  105. #define NETWAVE_CMD_AMA 0x03
  106. #define NETWAVE_CMD_DMA 0x04
  107. #define NETWAVE_CMD_SAMA 0x05
  108. #define NETWAVE_CMD_ER 0x06
  109. #define NETWAVE_CMD_DR 0x07
  110. #define NETWAVE_CMD_TL 0x08
  111. #define NETWAVE_CMD_SRP 0x09
  112. #define NETWAVE_CMD_SSK 0x0a
  113. #define NETWAVE_CMD_SMD 0x0b
  114. #define NETWAVE_CMD_SAPD 0x0c
  115. #define NETWAVE_CMD_SSS 0x11
  116. /* End of Command marker */
  117. #define NETWAVE_CMD_EOC 0x00
  118. /* ASR register bits */
  119. #define NETWAVE_ASR_RXRDY 0x80
  120. #define NETWAVE_ASR_TXBA 0x01
  121. #define TX_TIMEOUT ((32*HZ)/100)
  122. static const unsigned int imrConfRFU1 = 0x10; /* RFU interrupt mask, keep high */
  123. static const unsigned int imrConfIENA = 0x02; /* Interrupt enable */
  124. static const unsigned int corConfIENA = 0x01; /* Interrupt enable */
  125. static const unsigned int corConfLVLREQ = 0x40; /* Keep high */
  126. static const unsigned int rxConfRxEna = 0x80; /* Receive Enable */
  127. static const unsigned int rxConfMAC = 0x20; /* MAC host receive mode*/
  128. static const unsigned int rxConfPro = 0x10; /* Promiscuous */
  129. static const unsigned int rxConfAMP = 0x08; /* Accept Multicast Packets */
  130. static const unsigned int rxConfBcast = 0x04; /* Accept Broadcast Packets */
  131. static const unsigned int txConfTxEna = 0x80; /* Transmit Enable */
  132. static const unsigned int txConfMAC = 0x20; /* Host sends MAC mode */
  133. static const unsigned int txConfEUD = 0x10; /* Enable Uni-Data packets */
  134. static const unsigned int txConfKey = 0x02; /* Scramble data packets */
  135. static const unsigned int txConfLoop = 0x01; /* Loopback mode */
  136. /*
  137. All the PCMCIA modules use PCMCIA_DEBUG to control debugging. If
  138. you do not define PCMCIA_DEBUG at all, all the debug code will be
  139. left out. If you compile with PCMCIA_DEBUG=0, the debug code will
  140. be present but disabled -- but it can then be enabled for specific
  141. modules at load time with a 'pc_debug=#' option to insmod.
  142. */
  143. #ifdef PCMCIA_DEBUG
  144. static int pc_debug = PCMCIA_DEBUG;
  145. module_param(pc_debug, int, 0);
  146. #define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)
  147. static char *version =
  148. "netwave_cs.c 0.3.0 Thu Jul 17 14:36:02 1997 (John Markus Bjørndalen)\n";
  149. #else
  150. #define DEBUG(n, args...)
  151. #endif
  152. /*====================================================================*/
  153. /* Parameters that can be set with 'insmod' */
  154. /* Choose the domain, default is 0x100 */
  155. static u_int domain = 0x100;
  156. /* Scramble key, range from 0x0 to 0xffff.
  157. * 0x0 is no scrambling.
  158. */
  159. static u_int scramble_key = 0x0;
  160. /* Shared memory speed, in ns. The documentation states that
  161. * the card should not be read faster than every 400ns.
  162. * This timing should be provided by the HBA. If it becomes a
  163. * problem, try setting mem_speed to 400.
  164. */
  165. static int mem_speed;
  166. module_param(domain, int, 0);
  167. module_param(scramble_key, int, 0);
  168. module_param(mem_speed, int, 0);
  169. /*====================================================================*/
  170. /* PCMCIA (Card Services) related functions */
  171. static void netwave_release(struct pcmcia_device *link); /* Card removal */
  172. static void netwave_pcmcia_config(struct pcmcia_device *arg); /* Runs after card
  173. insertion */
  174. static void netwave_detach(struct pcmcia_device *p_dev); /* Destroy instance */
  175. /* Hardware configuration */
  176. static void netwave_doreset(kio_addr_t iobase, u_char __iomem *ramBase);
  177. static void netwave_reset(struct net_device *dev);
  178. /* Misc device stuff */
  179. static int netwave_open(struct net_device *dev); /* Open the device */
  180. static int netwave_close(struct net_device *dev); /* Close the device */
  181. /* Packet transmission and Packet reception */
  182. static int netwave_start_xmit( struct sk_buff *skb, struct net_device *dev);
  183. static int netwave_rx( struct net_device *dev);
  184. /* Interrupt routines */
  185. static irqreturn_t netwave_interrupt(int irq, void *dev_id, struct pt_regs *regs);
  186. static void netwave_watchdog(struct net_device *);
  187. /* Statistics */
  188. static void update_stats(struct net_device *dev);
  189. static struct net_device_stats *netwave_get_stats(struct net_device *dev);
  190. /* Wireless extensions */
  191. static struct iw_statistics* netwave_get_wireless_stats(struct net_device *dev);
  192. static void set_multicast_list(struct net_device *dev);
  193. /*
  194. A struct pcmcia_device structure has fields for most things that are needed
  195. to keep track of a socket, but there will usually be some device
  196. specific information that also needs to be kept track of. The
  197. 'priv' pointer in a struct pcmcia_device structure can be used to point to
  198. a device-specific private data structure, like this.
  199. A driver needs to provide a dev_node_t structure for each device
  200. on a card. In some cases, there is only one device per card (for
  201. example, ethernet cards, modems). In other cases, there may be
  202. many actual or logical devices (SCSI adapters, memory cards with
  203. multiple partitions). The dev_node_t structures need to be kept
  204. in a linked list starting at the 'dev' field of a struct pcmcia_device
  205. structure. We allocate them in the card's private data structure,
  206. because they generally can't be allocated dynamically.
  207. */
  208. static const struct iw_handler_def netwave_handler_def;
  209. #define SIOCGIPSNAP SIOCIWFIRSTPRIV + 1 /* Site Survey Snapshot */
  210. #define MAX_ESA 10
  211. typedef struct net_addr {
  212. u_char addr48[6];
  213. } net_addr;
  214. struct site_survey {
  215. u_short length;
  216. u_char struct_revision;
  217. u_char roaming_state;
  218. u_char sp_existsFlag;
  219. u_char sp_link_quality;
  220. u_char sp_max_link_quality;
  221. u_char linkQualityGoodFairBoundary;
  222. u_char linkQualityFairPoorBoundary;
  223. u_char sp_utilization;
  224. u_char sp_goodness;
  225. u_char sp_hotheadcount;
  226. u_char roaming_condition;
  227. net_addr sp;
  228. u_char numAPs;
  229. net_addr nearByAccessPoints[MAX_ESA];
  230. };
  231. typedef struct netwave_private {
  232. struct pcmcia_device *p_dev;
  233. spinlock_t spinlock; /* Serialize access to the hardware (SMP) */
  234. dev_node_t node;
  235. u_char __iomem *ramBase;
  236. int timeoutCounter;
  237. int lastExec;
  238. struct timer_list watchdog; /* To avoid blocking state */
  239. struct site_survey nss;
  240. struct net_device_stats stats;
  241. struct iw_statistics iw_stats; /* Wireless stats */
  242. } netwave_private;
  243. #ifdef NETWAVE_STATS
  244. static struct net_device_stats *netwave_get_stats(struct net_device *dev);
  245. #endif
  246. /*
  247. * The Netwave card is little-endian, so won't work for big endian
  248. * systems.
  249. */
  250. static inline unsigned short get_uint16(u_char __iomem *staddr)
  251. {
  252. return readw(staddr); /* Return only 16 bits */
  253. }
  254. static inline short get_int16(u_char __iomem * staddr)
  255. {
  256. return readw(staddr);
  257. }
  258. /*
  259. * Wait until the WOC (Write Operation Complete) bit in the
  260. * ASR (Adapter Status Register) is asserted.
  261. * This should have aborted if it takes too long time.
  262. */
  263. static inline void wait_WOC(unsigned int iobase)
  264. {
  265. /* Spin lock */
  266. while ((inb(iobase + NETWAVE_REG_ASR) & 0x8) != 0x8) ;
  267. }
  268. static void netwave_snapshot(netwave_private *priv, u_char __iomem *ramBase,
  269. kio_addr_t iobase) {
  270. u_short resultBuffer;
  271. /* if time since last snapshot is > 1 sec. (100 jiffies?) then take
  272. * new snapshot, else return cached data. This is the recommended rate.
  273. */
  274. if ( jiffies - priv->lastExec > 100) {
  275. /* Take site survey snapshot */
  276. /*printk( KERN_DEBUG "Taking new snapshot. %ld\n", jiffies -
  277. priv->lastExec); */
  278. wait_WOC(iobase);
  279. writeb(NETWAVE_CMD_SSS, ramBase + NETWAVE_EREG_CB + 0);
  280. writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 1);
  281. wait_WOC(iobase);
  282. /* Get result and copy to cach */
  283. resultBuffer = readw(ramBase + NETWAVE_EREG_CRBP);
  284. copy_from_pc( &priv->nss, ramBase+resultBuffer,
  285. sizeof(struct site_survey));
  286. }
  287. }
  288. /*
  289. * Function netwave_get_wireless_stats (dev)
  290. *
  291. * Wireless extensions statistics
  292. *
  293. */
  294. static struct iw_statistics *netwave_get_wireless_stats(struct net_device *dev)
  295. {
  296. unsigned long flags;
  297. kio_addr_t iobase = dev->base_addr;
  298. netwave_private *priv = netdev_priv(dev);
  299. u_char __iomem *ramBase = priv->ramBase;
  300. struct iw_statistics* wstats;
  301. wstats = &priv->iw_stats;
  302. spin_lock_irqsave(&priv->spinlock, flags);
  303. netwave_snapshot( priv, ramBase, iobase);
  304. wstats->status = priv->nss.roaming_state;
  305. wstats->qual.qual = readb( ramBase + NETWAVE_EREG_SPCQ);
  306. wstats->qual.level = readb( ramBase + NETWAVE_EREG_ISPLQ);
  307. wstats->qual.noise = readb( ramBase + NETWAVE_EREG_SPU) & 0x3f;
  308. wstats->discard.nwid = 0L;
  309. wstats->discard.code = 0L;
  310. wstats->discard.misc = 0L;
  311. spin_unlock_irqrestore(&priv->spinlock, flags);
  312. return &priv->iw_stats;
  313. }
  314. /*
  315. * Function netwave_attach (void)
  316. *
  317. * Creates an "instance" of the driver, allocating local data
  318. * structures for one device. The device is registered with Card
  319. * Services.
  320. *
  321. * The dev_link structure is initialized, but we don't actually
  322. * configure the card at this point -- we wait until we receive a
  323. * card insertion event.
  324. */
  325. static int netwave_attach(struct pcmcia_device *link)
  326. {
  327. struct net_device *dev;
  328. netwave_private *priv;
  329. DEBUG(0, "netwave_attach()\n");
  330. /* Initialize the struct pcmcia_device structure */
  331. dev = alloc_etherdev(sizeof(netwave_private));
  332. if (!dev)
  333. return -ENOMEM;
  334. priv = netdev_priv(dev);
  335. priv->p_dev = link;
  336. link->priv = dev;
  337. /* The io structure describes IO port mapping */
  338. link->io.NumPorts1 = 16;
  339. link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
  340. /* link->io.NumPorts2 = 16;
  341. link->io.Attributes2 = IO_DATA_PATH_WIDTH_16; */
  342. link->io.IOAddrLines = 5;
  343. /* Interrupt setup */
  344. link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
  345. link->irq.IRQInfo1 = IRQ_LEVEL_ID;
  346. link->irq.Handler = &netwave_interrupt;
  347. /* General socket configuration */
  348. link->conf.Attributes = CONF_ENABLE_IRQ;
  349. link->conf.IntType = INT_MEMORY_AND_IO;
  350. link->conf.ConfigIndex = 1;
  351. link->conf.Present = PRESENT_OPTION;
  352. /* Netwave private struct init. link/dev/node already taken care of,
  353. * other stuff zero'd - Jean II */
  354. spin_lock_init(&priv->spinlock);
  355. /* Netwave specific entries in the device structure */
  356. SET_MODULE_OWNER(dev);
  357. dev->hard_start_xmit = &netwave_start_xmit;
  358. dev->get_stats = &netwave_get_stats;
  359. dev->set_multicast_list = &set_multicast_list;
  360. /* wireless extensions */
  361. dev->wireless_handlers = (struct iw_handler_def *)&netwave_handler_def;
  362. dev->tx_timeout = &netwave_watchdog;
  363. dev->watchdog_timeo = TX_TIMEOUT;
  364. dev->open = &netwave_open;
  365. dev->stop = &netwave_close;
  366. link->irq.Instance = dev;
  367. link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
  368. netwave_pcmcia_config( link);
  369. return 0;
  370. } /* netwave_attach */
  371. /*
  372. * Function netwave_detach (link)
  373. *
  374. * This deletes a driver "instance". The device is de-registered
  375. * with Card Services. If it has been released, all local data
  376. * structures are freed. Otherwise, the structures will be freed
  377. * when the device is released.
  378. */
  379. static void netwave_detach(struct pcmcia_device *link)
  380. {
  381. struct net_device *dev = link->priv;
  382. DEBUG(0, "netwave_detach(0x%p)\n", link);
  383. if (link->state & DEV_CONFIG)
  384. netwave_release(link);
  385. if (link->dev_node)
  386. unregister_netdev(dev);
  387. free_netdev(dev);
  388. } /* netwave_detach */
  389. /*
  390. * Wireless Handler : get protocol name
  391. */
  392. static int netwave_get_name(struct net_device *dev,
  393. struct iw_request_info *info,
  394. union iwreq_data *wrqu,
  395. char *extra)
  396. {
  397. strcpy(wrqu->name, "Netwave");
  398. return 0;
  399. }
  400. /*
  401. * Wireless Handler : set Network ID
  402. */
  403. static int netwave_set_nwid(struct net_device *dev,
  404. struct iw_request_info *info,
  405. union iwreq_data *wrqu,
  406. char *extra)
  407. {
  408. unsigned long flags;
  409. kio_addr_t iobase = dev->base_addr;
  410. netwave_private *priv = netdev_priv(dev);
  411. u_char __iomem *ramBase = priv->ramBase;
  412. /* Disable interrupts & save flags */
  413. spin_lock_irqsave(&priv->spinlock, flags);
  414. if(!wrqu->nwid.disabled) {
  415. domain = wrqu->nwid.value;
  416. printk( KERN_DEBUG "Setting domain to 0x%x%02x\n",
  417. (domain >> 8) & 0x01, domain & 0xff);
  418. wait_WOC(iobase);
  419. writeb(NETWAVE_CMD_SMD, ramBase + NETWAVE_EREG_CB + 0);
  420. writeb( domain & 0xff, ramBase + NETWAVE_EREG_CB + 1);
  421. writeb((domain >>8 ) & 0x01,ramBase + NETWAVE_EREG_CB+2);
  422. writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 3);
  423. }
  424. /* ReEnable interrupts & restore flags */
  425. spin_unlock_irqrestore(&priv->spinlock, flags);
  426. return 0;
  427. }
  428. /*
  429. * Wireless Handler : get Network ID
  430. */
  431. static int netwave_get_nwid(struct net_device *dev,
  432. struct iw_request_info *info,
  433. union iwreq_data *wrqu,
  434. char *extra)
  435. {
  436. wrqu->nwid.value = domain;
  437. wrqu->nwid.disabled = 0;
  438. wrqu->nwid.fixed = 1;
  439. return 0;
  440. }
  441. /*
  442. * Wireless Handler : set scramble key
  443. */
  444. static int netwave_set_scramble(struct net_device *dev,
  445. struct iw_request_info *info,
  446. union iwreq_data *wrqu,
  447. char *key)
  448. {
  449. unsigned long flags;
  450. kio_addr_t iobase = dev->base_addr;
  451. netwave_private *priv = netdev_priv(dev);
  452. u_char __iomem *ramBase = priv->ramBase;
  453. /* Disable interrupts & save flags */
  454. spin_lock_irqsave(&priv->spinlock, flags);
  455. scramble_key = (key[0] << 8) | key[1];
  456. wait_WOC(iobase);
  457. writeb(NETWAVE_CMD_SSK, ramBase + NETWAVE_EREG_CB + 0);
  458. writeb(scramble_key & 0xff, ramBase + NETWAVE_EREG_CB + 1);
  459. writeb((scramble_key>>8) & 0xff, ramBase + NETWAVE_EREG_CB + 2);
  460. writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 3);
  461. /* ReEnable interrupts & restore flags */
  462. spin_unlock_irqrestore(&priv->spinlock, flags);
  463. return 0;
  464. }
  465. /*
  466. * Wireless Handler : get scramble key
  467. */
  468. static int netwave_get_scramble(struct net_device *dev,
  469. struct iw_request_info *info,
  470. union iwreq_data *wrqu,
  471. char *key)
  472. {
  473. key[1] = scramble_key & 0xff;
  474. key[0] = (scramble_key>>8) & 0xff;
  475. wrqu->encoding.flags = IW_ENCODE_ENABLED;
  476. wrqu->encoding.length = 2;
  477. return 0;
  478. }
  479. /*
  480. * Wireless Handler : get mode
  481. */
  482. static int netwave_get_mode(struct net_device *dev,
  483. struct iw_request_info *info,
  484. union iwreq_data *wrqu,
  485. char *extra)
  486. {
  487. if(domain & 0x100)
  488. wrqu->mode = IW_MODE_INFRA;
  489. else
  490. wrqu->mode = IW_MODE_ADHOC;
  491. return 0;
  492. }
  493. /*
  494. * Wireless Handler : get range info
  495. */
  496. static int netwave_get_range(struct net_device *dev,
  497. struct iw_request_info *info,
  498. union iwreq_data *wrqu,
  499. char *extra)
  500. {
  501. struct iw_range *range = (struct iw_range *) extra;
  502. int ret = 0;
  503. /* Set the length (very important for backward compatibility) */
  504. wrqu->data.length = sizeof(struct iw_range);
  505. /* Set all the info we don't care or don't know about to zero */
  506. memset(range, 0, sizeof(struct iw_range));
  507. /* Set the Wireless Extension versions */
  508. range->we_version_compiled = WIRELESS_EXT;
  509. range->we_version_source = 9; /* Nothing for us in v10 and v11 */
  510. /* Set information in the range struct */
  511. range->throughput = 450 * 1000; /* don't argue on this ! */
  512. range->min_nwid = 0x0000;
  513. range->max_nwid = 0x01FF;
  514. range->num_channels = range->num_frequency = 0;
  515. range->sensitivity = 0x3F;
  516. range->max_qual.qual = 255;
  517. range->max_qual.level = 255;
  518. range->max_qual.noise = 0;
  519. range->num_bitrates = 1;
  520. range->bitrate[0] = 1000000; /* 1 Mb/s */
  521. range->encoding_size[0] = 2; /* 16 bits scrambling */
  522. range->num_encoding_sizes = 1;
  523. range->max_encoding_tokens = 1; /* Only one key possible */
  524. return ret;
  525. }
  526. /*
  527. * Wireless Private Handler : get snapshot
  528. */
  529. static int netwave_get_snap(struct net_device *dev,
  530. struct iw_request_info *info,
  531. union iwreq_data *wrqu,
  532. char *extra)
  533. {
  534. unsigned long flags;
  535. kio_addr_t iobase = dev->base_addr;
  536. netwave_private *priv = netdev_priv(dev);
  537. u_char __iomem *ramBase = priv->ramBase;
  538. /* Disable interrupts & save flags */
  539. spin_lock_irqsave(&priv->spinlock, flags);
  540. /* Take snapshot of environment */
  541. netwave_snapshot( priv, ramBase, iobase);
  542. wrqu->data.length = priv->nss.length;
  543. memcpy(extra, (u_char *) &priv->nss, sizeof( struct site_survey));
  544. priv->lastExec = jiffies;
  545. /* ReEnable interrupts & restore flags */
  546. spin_unlock_irqrestore(&priv->spinlock, flags);
  547. return(0);
  548. }
  549. /*
  550. * Structures to export the Wireless Handlers
  551. * This is the stuff that are treated the wireless extensions (iwconfig)
  552. */
  553. static const struct iw_priv_args netwave_private_args[] = {
  554. /*{ cmd, set_args, get_args, name } */
  555. { SIOCGIPSNAP, 0,
  556. IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | sizeof(struct site_survey),
  557. "getsitesurvey" },
  558. };
  559. static const iw_handler netwave_handler[] =
  560. {
  561. NULL, /* SIOCSIWNAME */
  562. netwave_get_name, /* SIOCGIWNAME */
  563. netwave_set_nwid, /* SIOCSIWNWID */
  564. netwave_get_nwid, /* SIOCGIWNWID */
  565. NULL, /* SIOCSIWFREQ */
  566. NULL, /* SIOCGIWFREQ */
  567. NULL, /* SIOCSIWMODE */
  568. netwave_get_mode, /* SIOCGIWMODE */
  569. NULL, /* SIOCSIWSENS */
  570. NULL, /* SIOCGIWSENS */
  571. NULL, /* SIOCSIWRANGE */
  572. netwave_get_range, /* SIOCGIWRANGE */
  573. NULL, /* SIOCSIWPRIV */
  574. NULL, /* SIOCGIWPRIV */
  575. NULL, /* SIOCSIWSTATS */
  576. NULL, /* SIOCGIWSTATS */
  577. NULL, /* SIOCSIWSPY */
  578. NULL, /* SIOCGIWSPY */
  579. NULL, /* -- hole -- */
  580. NULL, /* -- hole -- */
  581. NULL, /* SIOCSIWAP */
  582. NULL, /* SIOCGIWAP */
  583. NULL, /* -- hole -- */
  584. NULL, /* SIOCGIWAPLIST */
  585. NULL, /* -- hole -- */
  586. NULL, /* -- hole -- */
  587. NULL, /* SIOCSIWESSID */
  588. NULL, /* SIOCGIWESSID */
  589. NULL, /* SIOCSIWNICKN */
  590. NULL, /* SIOCGIWNICKN */
  591. NULL, /* -- hole -- */
  592. NULL, /* -- hole -- */
  593. NULL, /* SIOCSIWRATE */
  594. NULL, /* SIOCGIWRATE */
  595. NULL, /* SIOCSIWRTS */
  596. NULL, /* SIOCGIWRTS */
  597. NULL, /* SIOCSIWFRAG */
  598. NULL, /* SIOCGIWFRAG */
  599. NULL, /* SIOCSIWTXPOW */
  600. NULL, /* SIOCGIWTXPOW */
  601. NULL, /* SIOCSIWRETRY */
  602. NULL, /* SIOCGIWRETRY */
  603. netwave_set_scramble, /* SIOCSIWENCODE */
  604. netwave_get_scramble, /* SIOCGIWENCODE */
  605. };
  606. static const iw_handler netwave_private_handler[] =
  607. {
  608. NULL, /* SIOCIWFIRSTPRIV */
  609. netwave_get_snap, /* SIOCIWFIRSTPRIV + 1 */
  610. };
  611. static const struct iw_handler_def netwave_handler_def =
  612. {
  613. .num_standard = sizeof(netwave_handler)/sizeof(iw_handler),
  614. .num_private = sizeof(netwave_private_handler)/sizeof(iw_handler),
  615. .num_private_args = sizeof(netwave_private_args)/sizeof(struct iw_priv_args),
  616. .standard = (iw_handler *) netwave_handler,
  617. .private = (iw_handler *) netwave_private_handler,
  618. .private_args = (struct iw_priv_args *) netwave_private_args,
  619. .get_wireless_stats = netwave_get_wireless_stats,
  620. };
  621. /*
  622. * Function netwave_pcmcia_config (link)
  623. *
  624. * netwave_pcmcia_config() is scheduled to run after a CARD_INSERTION
  625. * event is received, to configure the PCMCIA socket, and to make the
  626. * device available to the system.
  627. *
  628. */
  629. #define CS_CHECK(fn, ret) \
  630. do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
  631. static void netwave_pcmcia_config(struct pcmcia_device *link) {
  632. struct net_device *dev = link->priv;
  633. netwave_private *priv = netdev_priv(dev);
  634. tuple_t tuple;
  635. cisparse_t parse;
  636. int i, j, last_ret, last_fn;
  637. u_char buf[64];
  638. win_req_t req;
  639. memreq_t mem;
  640. u_char __iomem *ramBase = NULL;
  641. DEBUG(0, "netwave_pcmcia_config(0x%p)\n", link);
  642. /*
  643. This reads the card's CONFIG tuple to find its configuration
  644. registers.
  645. */
  646. tuple.Attributes = 0;
  647. tuple.TupleData = (cisdata_t *) buf;
  648. tuple.TupleDataMax = 64;
  649. tuple.TupleOffset = 0;
  650. tuple.DesiredTuple = CISTPL_CONFIG;
  651. CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
  652. CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
  653. CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
  654. link->conf.ConfigBase = parse.config.base;
  655. link->conf.Present = parse.config.rmask[0];
  656. /* Configure card */
  657. link->state |= DEV_CONFIG;
  658. /*
  659. * Try allocating IO ports. This tries a few fixed addresses.
  660. * If you want, you can also read the card's config table to
  661. * pick addresses -- see the serial driver for an example.
  662. */
  663. for (i = j = 0x0; j < 0x400; j += 0x20) {
  664. link->io.BasePort1 = j ^ 0x300;
  665. i = pcmcia_request_io(link, &link->io);
  666. if (i == CS_SUCCESS) break;
  667. }
  668. if (i != CS_SUCCESS) {
  669. cs_error(link, RequestIO, i);
  670. goto failed;
  671. }
  672. /*
  673. * Now allocate an interrupt line. Note that this does not
  674. * actually assign a handler to the interrupt.
  675. */
  676. CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
  677. /*
  678. * This actually configures the PCMCIA socket -- setting up
  679. * the I/O windows and the interrupt mapping.
  680. */
  681. CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
  682. /*
  683. * Allocate a 32K memory window. Note that the struct pcmcia_device
  684. * structure provides space for one window handle -- if your
  685. * device needs several windows, you'll need to keep track of
  686. * the handles in your private data structure, dev->priv.
  687. */
  688. DEBUG(1, "Setting mem speed of %d\n", mem_speed);
  689. req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_CM|WIN_ENABLE;
  690. req.Base = 0; req.Size = 0x8000;
  691. req.AccessSpeed = mem_speed;
  692. CS_CHECK(RequestWindow, pcmcia_request_window(&link, &req, &link->win));
  693. mem.CardOffset = 0x20000; mem.Page = 0;
  694. CS_CHECK(MapMemPage, pcmcia_map_mem_page(link->win, &mem));
  695. /* Store base address of the common window frame */
  696. ramBase = ioremap(req.Base, 0x8000);
  697. priv->ramBase = ramBase;
  698. dev->irq = link->irq.AssignedIRQ;
  699. dev->base_addr = link->io.BasePort1;
  700. SET_NETDEV_DEV(dev, &handle_to_dev(link));
  701. if (register_netdev(dev) != 0) {
  702. printk(KERN_DEBUG "netwave_cs: register_netdev() failed\n");
  703. goto failed;
  704. }
  705. strcpy(priv->node.dev_name, dev->name);
  706. link->dev_node = &priv->node;
  707. link->state &= ~DEV_CONFIG_PENDING;
  708. /* Reset card before reading physical address */
  709. netwave_doreset(dev->base_addr, ramBase);
  710. /* Read the ethernet address and fill in the Netwave registers. */
  711. for (i = 0; i < 6; i++)
  712. dev->dev_addr[i] = readb(ramBase + NETWAVE_EREG_PA + i);
  713. printk(KERN_INFO "%s: Netwave: port %#3lx, irq %d, mem %lx id "
  714. "%c%c, hw_addr ", dev->name, dev->base_addr, dev->irq,
  715. (u_long) ramBase, (int) readb(ramBase+NETWAVE_EREG_NI),
  716. (int) readb(ramBase+NETWAVE_EREG_NI+1));
  717. for (i = 0; i < 6; i++)
  718. printk("%02X%s", dev->dev_addr[i], ((i<5) ? ":" : "\n"));
  719. /* get revision words */
  720. printk(KERN_DEBUG "Netwave_reset: revision %04x %04x\n",
  721. get_uint16(ramBase + NETWAVE_EREG_ARW),
  722. get_uint16(ramBase + NETWAVE_EREG_ARW+2));
  723. return;
  724. cs_failed:
  725. cs_error(link, last_fn, last_ret);
  726. failed:
  727. netwave_release(link);
  728. } /* netwave_pcmcia_config */
  729. /*
  730. * Function netwave_release (arg)
  731. *
  732. * After a card is removed, netwave_release() will unregister the net
  733. * device, and release the PCMCIA configuration. If the device is
  734. * still open, this will be postponed until it is closed.
  735. */
  736. static void netwave_release(struct pcmcia_device *link)
  737. {
  738. struct net_device *dev = link->priv;
  739. netwave_private *priv = netdev_priv(dev);
  740. DEBUG(0, "netwave_release(0x%p)\n", link);
  741. pcmcia_disable_device(link);
  742. if (link->win)
  743. iounmap(priv->ramBase);
  744. }
  745. static int netwave_suspend(struct pcmcia_device *link)
  746. {
  747. struct net_device *dev = link->priv;
  748. if ((link->state & DEV_CONFIG) && (link->open))
  749. netif_device_detach(dev);
  750. return 0;
  751. }
  752. static int netwave_resume(struct pcmcia_device *link)
  753. {
  754. struct net_device *dev = link->priv;
  755. if ((link->state & DEV_CONFIG) && (link->open)) {
  756. netwave_reset(dev);
  757. netif_device_attach(dev);
  758. }
  759. return 0;
  760. }
  761. /*
  762. * Function netwave_doreset (ioBase, ramBase)
  763. *
  764. * Proper hardware reset of the card.
  765. */
  766. static void netwave_doreset(kio_addr_t ioBase, u_char __iomem *ramBase)
  767. {
  768. /* Reset card */
  769. wait_WOC(ioBase);
  770. outb(0x80, ioBase + NETWAVE_REG_PMR);
  771. writeb(0x08, ramBase + NETWAVE_EREG_ASCC); /* Bit 3 is WOC */
  772. outb(0x0, ioBase + NETWAVE_REG_PMR); /* release reset */
  773. }
  774. /*
  775. * Function netwave_reset (dev)
  776. *
  777. * Reset and restore all of the netwave registers
  778. */
  779. static void netwave_reset(struct net_device *dev) {
  780. /* u_char state; */
  781. netwave_private *priv = netdev_priv(dev);
  782. u_char __iomem *ramBase = priv->ramBase;
  783. kio_addr_t iobase = dev->base_addr;
  784. DEBUG(0, "netwave_reset: Done with hardware reset\n");
  785. priv->timeoutCounter = 0;
  786. /* Reset card */
  787. netwave_doreset(iobase, ramBase);
  788. printk(KERN_DEBUG "netwave_reset: Done with hardware reset\n");
  789. /* Write a NOP to check the card */
  790. wait_WOC(iobase);
  791. writeb(NETWAVE_CMD_NOP, ramBase + NETWAVE_EREG_CB + 0);
  792. writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 1);
  793. /* Set receive conf */
  794. wait_WOC(iobase);
  795. writeb(NETWAVE_CMD_SRC, ramBase + NETWAVE_EREG_CB + 0);
  796. writeb(rxConfRxEna + rxConfBcast, ramBase + NETWAVE_EREG_CB + 1);
  797. writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 2);
  798. /* Set transmit conf */
  799. wait_WOC(iobase);
  800. writeb(NETWAVE_CMD_STC, ramBase + NETWAVE_EREG_CB + 0);
  801. writeb(txConfTxEna, ramBase + NETWAVE_EREG_CB + 1);
  802. writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 2);
  803. /* Now set the MU Domain */
  804. printk(KERN_DEBUG "Setting domain to 0x%x%02x\n", (domain >> 8) & 0x01, domain & 0xff);
  805. wait_WOC(iobase);
  806. writeb(NETWAVE_CMD_SMD, ramBase + NETWAVE_EREG_CB + 0);
  807. writeb(domain & 0xff, ramBase + NETWAVE_EREG_CB + 1);
  808. writeb((domain>>8) & 0x01, ramBase + NETWAVE_EREG_CB + 2);
  809. writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 3);
  810. /* Set scramble key */
  811. printk(KERN_DEBUG "Setting scramble key to 0x%x\n", scramble_key);
  812. wait_WOC(iobase);
  813. writeb(NETWAVE_CMD_SSK, ramBase + NETWAVE_EREG_CB + 0);
  814. writeb(scramble_key & 0xff, ramBase + NETWAVE_EREG_CB + 1);
  815. writeb((scramble_key>>8) & 0xff, ramBase + NETWAVE_EREG_CB + 2);
  816. writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 3);
  817. /* Enable interrupts, bit 4 high to keep unused
  818. * source from interrupting us, bit 2 high to
  819. * set interrupt enable, 567 to enable TxDN,
  820. * RxErr and RxRdy
  821. */
  822. wait_WOC(iobase);
  823. outb(imrConfIENA+imrConfRFU1, iobase + NETWAVE_REG_IMR);
  824. /* Hent 4 bytes fra 0x170. Skal vaere 0a,29,88,36
  825. * waitWOC
  826. * skriv 80 til d000:3688
  827. * sjekk om det ble 80
  828. */
  829. /* Enable Receiver */
  830. wait_WOC(iobase);
  831. writeb(NETWAVE_CMD_ER, ramBase + NETWAVE_EREG_CB + 0);
  832. writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 1);
  833. /* Set the IENA bit in COR */
  834. wait_WOC(iobase);
  835. outb(corConfIENA + corConfLVLREQ, iobase + NETWAVE_REG_COR);
  836. }
  837. /*
  838. * Function netwave_hw_xmit (data, len, dev)
  839. */
  840. static int netwave_hw_xmit(unsigned char* data, int len,
  841. struct net_device* dev) {
  842. unsigned long flags;
  843. unsigned int TxFreeList,
  844. curBuff,
  845. MaxData,
  846. DataOffset;
  847. int tmpcount;
  848. netwave_private *priv = netdev_priv(dev);
  849. u_char __iomem * ramBase = priv->ramBase;
  850. kio_addr_t iobase = dev->base_addr;
  851. /* Disable interrupts & save flags */
  852. spin_lock_irqsave(&priv->spinlock, flags);
  853. /* Check if there are transmit buffers available */
  854. wait_WOC(iobase);
  855. if ((inb(iobase+NETWAVE_REG_ASR) & NETWAVE_ASR_TXBA) == 0) {
  856. /* No buffers available */
  857. printk(KERN_DEBUG "netwave_hw_xmit: %s - no xmit buffers available.\n",
  858. dev->name);
  859. spin_unlock_irqrestore(&priv->spinlock, flags);
  860. return 1;
  861. }
  862. priv->stats.tx_bytes += len;
  863. DEBUG(3, "Transmitting with SPCQ %x SPU %x LIF %x ISPLQ %x\n",
  864. readb(ramBase + NETWAVE_EREG_SPCQ),
  865. readb(ramBase + NETWAVE_EREG_SPU),
  866. readb(ramBase + NETWAVE_EREG_LIF),
  867. readb(ramBase + NETWAVE_EREG_ISPLQ));
  868. /* Now try to insert it into the adapters free memory */
  869. wait_WOC(iobase);
  870. TxFreeList = get_uint16(ramBase + NETWAVE_EREG_TDP);
  871. MaxData = get_uint16(ramBase + NETWAVE_EREG_TDP+2);
  872. DataOffset = get_uint16(ramBase + NETWAVE_EREG_TDP+4);
  873. DEBUG(3, "TxFreeList %x, MaxData %x, DataOffset %x\n",
  874. TxFreeList, MaxData, DataOffset);
  875. /* Copy packet to the adapter fragment buffers */
  876. curBuff = TxFreeList;
  877. tmpcount = 0;
  878. while (tmpcount < len) {
  879. int tmplen = len - tmpcount;
  880. copy_to_pc(ramBase + curBuff + DataOffset, data + tmpcount,
  881. (tmplen < MaxData) ? tmplen : MaxData);
  882. tmpcount += MaxData;
  883. /* Advance to next buffer */
  884. curBuff = get_uint16(ramBase + curBuff);
  885. }
  886. /* Now issue transmit list */
  887. wait_WOC(iobase);
  888. writeb(NETWAVE_CMD_TL, ramBase + NETWAVE_EREG_CB + 0);
  889. writeb(len & 0xff, ramBase + NETWAVE_EREG_CB + 1);
  890. writeb((len>>8) & 0xff, ramBase + NETWAVE_EREG_CB + 2);
  891. writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 3);
  892. spin_unlock_irqrestore(&priv->spinlock, flags);
  893. return 0;
  894. }
  895. static int netwave_start_xmit(struct sk_buff *skb, struct net_device *dev) {
  896. /* This flag indicate that the hardware can't perform a transmission.
  897. * Theoritically, NET3 check it before sending a packet to the driver,
  898. * but in fact it never do that and pool continuously.
  899. * As the watchdog will abort too long transmissions, we are quite safe...
  900. */
  901. netif_stop_queue(dev);
  902. {
  903. short length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
  904. unsigned char* buf = skb->data;
  905. if (netwave_hw_xmit( buf, length, dev) == 1) {
  906. /* Some error, let's make them call us another time? */
  907. netif_start_queue(dev);
  908. }
  909. dev->trans_start = jiffies;
  910. }
  911. dev_kfree_skb(skb);
  912. return 0;
  913. } /* netwave_start_xmit */
  914. /*
  915. * Function netwave_interrupt (irq, dev_id, regs)
  916. *
  917. * This function is the interrupt handler for the Netwave card. This
  918. * routine will be called whenever:
  919. * 1. A packet is received.
  920. * 2. A packet has successfully been transferred and the unit is
  921. * ready to transmit another packet.
  922. * 3. A command has completed execution.
  923. */
  924. static irqreturn_t netwave_interrupt(int irq, void* dev_id, struct pt_regs *regs)
  925. {
  926. kio_addr_t iobase;
  927. u_char __iomem *ramBase;
  928. struct net_device *dev = (struct net_device *)dev_id;
  929. struct netwave_private *priv = netdev_priv(dev);
  930. struct pcmcia_device *link = priv->p_dev;
  931. int i;
  932. if (!netif_device_present(dev))
  933. return IRQ_NONE;
  934. iobase = dev->base_addr;
  935. ramBase = priv->ramBase;
  936. /* Now find what caused the interrupt, check while interrupts ready */
  937. for (i = 0; i < 10; i++) {
  938. u_char status;
  939. wait_WOC(iobase);
  940. if (!(inb(iobase+NETWAVE_REG_CCSR) & 0x02))
  941. break; /* None of the interrupt sources asserted (normal exit) */
  942. status = inb(iobase + NETWAVE_REG_ASR);
  943. if (!DEV_OK(link)) {
  944. DEBUG(1, "netwave_interrupt: Interrupt with status 0x%x "
  945. "from removed or suspended card!\n", status);
  946. break;
  947. }
  948. /* RxRdy */
  949. if (status & 0x80) {
  950. netwave_rx(dev);
  951. /* wait_WOC(iobase); */
  952. /* RxRdy cannot be reset directly by the host */
  953. }
  954. /* RxErr */
  955. if (status & 0x40) {
  956. u_char rser;
  957. rser = readb(ramBase + NETWAVE_EREG_RSER);
  958. if (rser & 0x04) {
  959. ++priv->stats.rx_dropped;
  960. ++priv->stats.rx_crc_errors;
  961. }
  962. if (rser & 0x02)
  963. ++priv->stats.rx_frame_errors;
  964. /* Clear the RxErr bit in RSER. RSER+4 is the
  965. * write part. Also clear the RxCRC (0x04) and
  966. * RxBig (0x02) bits if present */
  967. wait_WOC(iobase);
  968. writeb(0x40 | (rser & 0x06), ramBase + NETWAVE_EREG_RSER + 4);
  969. /* Write bit 6 high to ASCC to clear RxErr in ASR,
  970. * WOC must be set first!
  971. */
  972. wait_WOC(iobase);
  973. writeb(0x40, ramBase + NETWAVE_EREG_ASCC);
  974. /* Remember to count up priv->stats on error packets */
  975. ++priv->stats.rx_errors;
  976. }
  977. /* TxDN */
  978. if (status & 0x20) {
  979. int txStatus;
  980. txStatus = readb(ramBase + NETWAVE_EREG_TSER);
  981. DEBUG(3, "Transmit done. TSER = %x id %x\n",
  982. txStatus, readb(ramBase + NETWAVE_EREG_TSER + 1));
  983. if (txStatus & 0x20) {
  984. /* Transmitting was okay, clear bits */
  985. wait_WOC(iobase);
  986. writeb(0x2f, ramBase + NETWAVE_EREG_TSER + 4);
  987. ++priv->stats.tx_packets;
  988. }
  989. if (txStatus & 0xd0) {
  990. if (txStatus & 0x80) {
  991. ++priv->stats.collisions; /* Because of /proc/net/dev*/
  992. /* ++priv->stats.tx_aborted_errors; */
  993. /* printk("Collision. %ld\n", jiffies - dev->trans_start); */
  994. }
  995. if (txStatus & 0x40)
  996. ++priv->stats.tx_carrier_errors;
  997. /* 0x80 TxGU Transmit giveup - nine times and no luck
  998. * 0x40 TxNOAP No access point. Discarded packet.
  999. * 0x10 TxErr Transmit error. Always set when
  1000. * TxGU and TxNOAP is set. (Those are the only ones
  1001. * to set TxErr).
  1002. */
  1003. DEBUG(3, "netwave_interrupt: TxDN with error status %x\n",
  1004. txStatus);
  1005. /* Clear out TxGU, TxNOAP, TxErr and TxTrys */
  1006. wait_WOC(iobase);
  1007. writeb(0xdf & txStatus, ramBase+NETWAVE_EREG_TSER+4);
  1008. ++priv->stats.tx_errors;
  1009. }
  1010. DEBUG(3, "New status is TSER %x ASR %x\n",
  1011. readb(ramBase + NETWAVE_EREG_TSER),
  1012. inb(iobase + NETWAVE_REG_ASR));
  1013. netif_wake_queue(dev);
  1014. }
  1015. /* TxBA, this would trigger on all error packets received */
  1016. /* if (status & 0x01) {
  1017. DEBUG(4, "Transmit buffers available, %x\n", status);
  1018. }
  1019. */
  1020. }
  1021. /* Handled if we looped at least one time - Jean II */
  1022. return IRQ_RETVAL(i);
  1023. } /* netwave_interrupt */
  1024. /*
  1025. * Function netwave_watchdog (a)
  1026. *
  1027. * Watchdog : when we start a transmission, we set a timer in the
  1028. * kernel. If the transmission complete, this timer is disabled. If
  1029. * it expire, we reset the card.
  1030. *
  1031. */
  1032. static void netwave_watchdog(struct net_device *dev) {
  1033. DEBUG(1, "%s: netwave_watchdog: watchdog timer expired\n", dev->name);
  1034. netwave_reset(dev);
  1035. dev->trans_start = jiffies;
  1036. netif_wake_queue(dev);
  1037. } /* netwave_watchdog */
  1038. static struct net_device_stats *netwave_get_stats(struct net_device *dev) {
  1039. netwave_private *priv = netdev_priv(dev);
  1040. update_stats(dev);
  1041. DEBUG(2, "netwave: SPCQ %x SPU %x LIF %x ISPLQ %x MHS %x rxtx %x"
  1042. " %x tx %x %x %x %x\n",
  1043. readb(priv->ramBase + NETWAVE_EREG_SPCQ),
  1044. readb(priv->ramBase + NETWAVE_EREG_SPU),
  1045. readb(priv->ramBase + NETWAVE_EREG_LIF),
  1046. readb(priv->ramBase + NETWAVE_EREG_ISPLQ),
  1047. readb(priv->ramBase + NETWAVE_EREG_MHS),
  1048. readb(priv->ramBase + NETWAVE_EREG_EC + 0xe),
  1049. readb(priv->ramBase + NETWAVE_EREG_EC + 0xf),
  1050. readb(priv->ramBase + NETWAVE_EREG_EC + 0x18),
  1051. readb(priv->ramBase + NETWAVE_EREG_EC + 0x19),
  1052. readb(priv->ramBase + NETWAVE_EREG_EC + 0x1a),
  1053. readb(priv->ramBase + NETWAVE_EREG_EC + 0x1b));
  1054. return &priv->stats;
  1055. }
  1056. static void update_stats(struct net_device *dev) {
  1057. //unsigned long flags;
  1058. /* netwave_private *priv = netdev_priv(dev); */
  1059. //spin_lock_irqsave(&priv->spinlock, flags);
  1060. /* priv->stats.rx_packets = readb(priv->ramBase + 0x18e);
  1061. priv->stats.tx_packets = readb(priv->ramBase + 0x18f); */
  1062. //spin_unlock_irqrestore(&priv->spinlock, flags);
  1063. }
  1064. static int netwave_rx(struct net_device *dev)
  1065. {
  1066. netwave_private *priv = netdev_priv(dev);
  1067. u_char __iomem *ramBase = priv->ramBase;
  1068. kio_addr_t iobase = dev->base_addr;
  1069. u_char rxStatus;
  1070. struct sk_buff *skb = NULL;
  1071. unsigned int curBuffer,
  1072. rcvList;
  1073. int rcvLen;
  1074. int tmpcount = 0;
  1075. int dataCount, dataOffset;
  1076. int i;
  1077. u_char *ptr;
  1078. DEBUG(3, "xinw_rx: Receiving ... \n");
  1079. /* Receive max 10 packets for now. */
  1080. for (i = 0; i < 10; i++) {
  1081. /* Any packets? */
  1082. wait_WOC(iobase);
  1083. rxStatus = readb(ramBase + NETWAVE_EREG_RSER);
  1084. if ( !( rxStatus & 0x80)) /* No more packets */
  1085. break;
  1086. /* Check if multicast/broadcast or other */
  1087. /* multicast = (rxStatus & 0x20); */
  1088. /* The receive list pointer and length of the packet */
  1089. wait_WOC(iobase);
  1090. rcvLen = get_int16( ramBase + NETWAVE_EREG_RDP);
  1091. rcvList = get_uint16( ramBase + NETWAVE_EREG_RDP + 2);
  1092. if (rcvLen < 0) {
  1093. printk(KERN_DEBUG "netwave_rx: Receive packet with len %d\n",
  1094. rcvLen);
  1095. return 0;
  1096. }
  1097. skb = dev_alloc_skb(rcvLen+5);
  1098. if (skb == NULL) {
  1099. DEBUG(1, "netwave_rx: Could not allocate an sk_buff of "
  1100. "length %d\n", rcvLen);
  1101. ++priv->stats.rx_dropped;
  1102. /* Tell the adapter to skip the packet */
  1103. wait_WOC(iobase);
  1104. writeb(NETWAVE_CMD_SRP, ramBase + NETWAVE_EREG_CB + 0);
  1105. writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 1);
  1106. return 0;
  1107. }
  1108. skb_reserve( skb, 2); /* Align IP on 16 byte */
  1109. skb_put( skb, rcvLen);
  1110. skb->dev = dev;
  1111. /* Copy packet fragments to the skb data area */
  1112. ptr = (u_char*) skb->data;
  1113. curBuffer = rcvList;
  1114. tmpcount = 0;
  1115. while ( tmpcount < rcvLen) {
  1116. /* Get length and offset of current buffer */
  1117. dataCount = get_uint16( ramBase+curBuffer+2);
  1118. dataOffset = get_uint16( ramBase+curBuffer+4);
  1119. copy_from_pc( ptr + tmpcount,
  1120. ramBase+curBuffer+dataOffset, dataCount);
  1121. tmpcount += dataCount;
  1122. /* Point to next buffer */
  1123. curBuffer = get_uint16(ramBase + curBuffer);
  1124. }
  1125. skb->protocol = eth_type_trans(skb,dev);
  1126. /* Queue packet for network layer */
  1127. netif_rx(skb);
  1128. dev->last_rx = jiffies;
  1129. priv->stats.rx_packets++;
  1130. priv->stats.rx_bytes += rcvLen;
  1131. /* Got the packet, tell the adapter to skip it */
  1132. wait_WOC(iobase);
  1133. writeb(NETWAVE_CMD_SRP, ramBase + NETWAVE_EREG_CB + 0);
  1134. writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 1);
  1135. DEBUG(3, "Packet reception ok\n");
  1136. }
  1137. return 0;
  1138. }
  1139. static int netwave_open(struct net_device *dev) {
  1140. netwave_private *priv = netdev_priv(dev);
  1141. struct pcmcia_device *link = priv->p_dev;
  1142. DEBUG(1, "netwave_open: starting.\n");
  1143. if (!DEV_OK(link))
  1144. return -ENODEV;
  1145. link->open++;
  1146. netif_start_queue(dev);
  1147. netwave_reset(dev);
  1148. return 0;
  1149. }
  1150. static int netwave_close(struct net_device *dev) {
  1151. netwave_private *priv = netdev_priv(dev);
  1152. struct pcmcia_device *link = priv->p_dev;
  1153. DEBUG(1, "netwave_close: finishing.\n");
  1154. link->open--;
  1155. netif_stop_queue(dev);
  1156. return 0;
  1157. }
  1158. static struct pcmcia_device_id netwave_ids[] = {
  1159. PCMCIA_DEVICE_PROD_ID12("Xircom", "CreditCard Netwave", 0x2e3ee845, 0x54e28a28),
  1160. PCMCIA_DEVICE_NULL,
  1161. };
  1162. MODULE_DEVICE_TABLE(pcmcia, netwave_ids);
  1163. static struct pcmcia_driver netwave_driver = {
  1164. .owner = THIS_MODULE,
  1165. .drv = {
  1166. .name = "netwave_cs",
  1167. },
  1168. .probe = netwave_attach,
  1169. .remove = netwave_detach,
  1170. .id_table = netwave_ids,
  1171. .suspend = netwave_suspend,
  1172. .resume = netwave_resume,
  1173. };
  1174. static int __init init_netwave_cs(void)
  1175. {
  1176. return pcmcia_register_driver(&netwave_driver);
  1177. }
  1178. static void __exit exit_netwave_cs(void)
  1179. {
  1180. pcmcia_unregister_driver(&netwave_driver);
  1181. }
  1182. module_init(init_netwave_cs);
  1183. module_exit(exit_netwave_cs);
  1184. /* Set or clear the multicast filter for this adaptor.
  1185. num_addrs == -1 Promiscuous mode, receive all packets
  1186. num_addrs == 0 Normal mode, clear multicast list
  1187. num_addrs > 0 Multicast mode, receive normal and MC packets, and do
  1188. best-effort filtering.
  1189. */
  1190. static void set_multicast_list(struct net_device *dev)
  1191. {
  1192. kio_addr_t iobase = dev->base_addr;
  1193. netwave_private *priv = netdev_priv(dev);
  1194. u_char __iomem * ramBase = priv->ramBase;
  1195. u_char rcvMode = 0;
  1196. #ifdef PCMCIA_DEBUG
  1197. if (pc_debug > 2) {
  1198. static int old;
  1199. if (old != dev->mc_count) {
  1200. old = dev->mc_count;
  1201. DEBUG(0, "%s: setting Rx mode to %d addresses.\n",
  1202. dev->name, dev->mc_count);
  1203. }
  1204. }
  1205. #endif
  1206. if (dev->mc_count || (dev->flags & IFF_ALLMULTI)) {
  1207. /* Multicast Mode */
  1208. rcvMode = rxConfRxEna + rxConfAMP + rxConfBcast;
  1209. } else if (dev->flags & IFF_PROMISC) {
  1210. /* Promiscous mode */
  1211. rcvMode = rxConfRxEna + rxConfPro + rxConfAMP + rxConfBcast;
  1212. } else {
  1213. /* Normal mode */
  1214. rcvMode = rxConfRxEna + rxConfBcast;
  1215. }
  1216. /* printk("netwave set_multicast_list: rcvMode to %x\n", rcvMode);*/
  1217. /* Now set receive mode */
  1218. wait_WOC(iobase);
  1219. writeb(NETWAVE_CMD_SRC, ramBase + NETWAVE_EREG_CB + 0);
  1220. writeb(rcvMode, ramBase + NETWAVE_EREG_CB + 1);
  1221. writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 2);
  1222. }
  1223. MODULE_LICENSE("GPL");