netwave_cs.c 51 KB

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