netwave_cs.c 41 KB

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