wl3501_cs.c 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236
  1. /*
  2. * WL3501 Wireless LAN PCMCIA Card Driver for Linux
  3. * Written originally for Linux 2.0.30 by Fox Chen, mhchen@golf.ccl.itri.org.tw
  4. * Ported to 2.2, 2.4 & 2.5 by Arnaldo Carvalho de Melo <acme@conectiva.com.br>
  5. * Wireless extensions in 2.4 by Gustavo Niemeyer <niemeyer@conectiva.com>
  6. *
  7. * References used by Fox Chen while writing the original driver for 2.0.30:
  8. *
  9. * 1. WL24xx packet drivers (tooasm.asm)
  10. * 2. Access Point Firmware Interface Specification for IEEE 802.11 SUTRO
  11. * 3. IEEE 802.11
  12. * 4. Linux network driver (/usr/src/linux/drivers/net)
  13. * 5. ISA card driver - wl24.c
  14. * 6. Linux PCMCIA skeleton driver - skeleton.c
  15. * 7. Linux PCMCIA 3c589 network driver - 3c589_cs.c
  16. *
  17. * Tested with WL2400 firmware 1.2, Linux 2.0.30, and pcmcia-cs-2.9.12
  18. * 1. Performance: about 165 Kbytes/sec in TCP/IP with Ad-Hoc mode.
  19. * rsh 192.168.1.3 "dd if=/dev/zero bs=1k count=1000" > /dev/null
  20. * (Specification 2M bits/sec. is about 250 Kbytes/sec., but we must deduct
  21. * ETHER/IP/UDP/TCP header, and acknowledgement overhead)
  22. *
  23. * Tested with Planet AP in 2.4.17, 184 Kbytes/s in UDP in Infrastructure mode,
  24. * 173 Kbytes/s in TCP.
  25. *
  26. * Tested with Planet AP in 2.5.73-bk, 216 Kbytes/s in Infrastructure mode
  27. * with a SMP machine (dual pentium 100), using pktgen, 432 pps (pkt_size = 60)
  28. */
  29. #undef REALLY_SLOW_IO /* most systems can safely undef this */
  30. #include <linux/config.h>
  31. #include <linux/delay.h>
  32. #include <linux/types.h>
  33. #include <linux/ethtool.h>
  34. #include <linux/init.h>
  35. #include <linux/interrupt.h>
  36. #include <linux/in.h>
  37. #include <linux/kernel.h>
  38. #include <linux/module.h>
  39. #include <linux/fcntl.h>
  40. #include <linux/if_arp.h>
  41. #include <linux/ioport.h>
  42. #include <linux/netdevice.h>
  43. #include <linux/etherdevice.h>
  44. #include <linux/skbuff.h>
  45. #include <linux/slab.h>
  46. #include <linux/string.h>
  47. #include <linux/wireless.h>
  48. #include <net/iw_handler.h>
  49. #include <pcmcia/cs_types.h>
  50. #include <pcmcia/cs.h>
  51. #include <pcmcia/cistpl.h>
  52. #include <pcmcia/cisreg.h>
  53. #include <pcmcia/ds.h>
  54. #include <asm/io.h>
  55. #include <asm/uaccess.h>
  56. #include <asm/system.h>
  57. #include "wl3501.h"
  58. #ifndef __i386__
  59. #define slow_down_io()
  60. #endif
  61. /* For rough constant delay */
  62. #define WL3501_NOPLOOP(n) { int x = 0; while (x++ < n) slow_down_io(); }
  63. /*
  64. * All the PCMCIA modules use PCMCIA_DEBUG to control debugging. If you do not
  65. * define PCMCIA_DEBUG at all, all the debug code will be left out. If you
  66. * compile with PCMCIA_DEBUG=0, the debug code will be present but disabled --
  67. * but it can then be enabled for specific modules at load time with a
  68. * 'pc_debug=#' option to insmod.
  69. */
  70. #define PCMCIA_DEBUG 0
  71. #ifdef PCMCIA_DEBUG
  72. static int pc_debug = PCMCIA_DEBUG;
  73. module_param(pc_debug, int, 0);
  74. #define dprintk(n, format, args...) \
  75. { if (pc_debug > (n)) \
  76. printk(KERN_INFO "%s: " format "\n", __FUNCTION__ , ##args); }
  77. #else
  78. #define dprintk(n, format, args...)
  79. #endif
  80. #define wl3501_outb(a, b) { outb(a, b); slow_down_io(); }
  81. #define wl3501_outb_p(a, b) { outb_p(a, b); slow_down_io(); }
  82. #define wl3501_outsb(a, b, c) { outsb(a, b, c); slow_down_io(); }
  83. #define WL3501_RELEASE_TIMEOUT (25 * HZ)
  84. #define WL3501_MAX_ADHOC_TRIES 16
  85. #define WL3501_RESUME 0
  86. #define WL3501_SUSPEND 1
  87. /*
  88. * The event() function is this driver's Card Services event handler. It will
  89. * be called by Card Services when an appropriate card status event is
  90. * received. The config() and release() entry points are used to configure or
  91. * release a socket, in response to card insertion and ejection events. They
  92. * are invoked from the wl24 event handler.
  93. */
  94. static void wl3501_config(dev_link_t *link);
  95. static void wl3501_release(dev_link_t *link);
  96. /*
  97. * The dev_info variable is the "key" that is used to match up this
  98. * device driver with appropriate cards, through the card configuration
  99. * database.
  100. */
  101. static dev_info_t wl3501_dev_info = "wl3501_cs";
  102. static int wl3501_chan2freq[] = {
  103. [0] = 2412, [1] = 2417, [2] = 2422, [3] = 2427, [4] = 2432,
  104. [5] = 2437, [6] = 2442, [7] = 2447, [8] = 2452, [9] = 2457,
  105. [10] = 2462, [11] = 2467, [12] = 2472, [13] = 2477,
  106. };
  107. static const struct {
  108. int reg_domain;
  109. int min, max, deflt;
  110. } iw_channel_table[] = {
  111. {
  112. .reg_domain = IW_REG_DOMAIN_FCC,
  113. .min = 1,
  114. .max = 11,
  115. .deflt = 1,
  116. },
  117. {
  118. .reg_domain = IW_REG_DOMAIN_DOC,
  119. .min = 1,
  120. .max = 11,
  121. .deflt = 1,
  122. },
  123. {
  124. .reg_domain = IW_REG_DOMAIN_ETSI,
  125. .min = 1,
  126. .max = 13,
  127. .deflt = 1,
  128. },
  129. {
  130. .reg_domain = IW_REG_DOMAIN_SPAIN,
  131. .min = 10,
  132. .max = 11,
  133. .deflt = 10,
  134. },
  135. {
  136. .reg_domain = IW_REG_DOMAIN_FRANCE,
  137. .min = 10,
  138. .max = 13,
  139. .deflt = 10,
  140. },
  141. {
  142. .reg_domain = IW_REG_DOMAIN_MKK,
  143. .min = 14,
  144. .max = 14,
  145. .deflt = 14,
  146. },
  147. {
  148. .reg_domain = IW_REG_DOMAIN_MKK1,
  149. .min = 1,
  150. .max = 14,
  151. .deflt = 1,
  152. },
  153. {
  154. .reg_domain = IW_REG_DOMAIN_ISRAEL,
  155. .min = 3,
  156. .max = 9,
  157. .deflt = 9,
  158. },
  159. };
  160. /**
  161. * iw_valid_channel - validate channel in regulatory domain
  162. * @reg_comain - regulatory domain
  163. * @channel - channel to validate
  164. *
  165. * Returns 0 if invalid in the specified regulatory domain, non-zero if valid.
  166. */
  167. static int iw_valid_channel(int reg_domain, int channel)
  168. {
  169. int i, rc = 0;
  170. for (i = 0; i < ARRAY_SIZE(iw_channel_table); i++)
  171. if (reg_domain == iw_channel_table[i].reg_domain) {
  172. rc = channel >= iw_channel_table[i].min &&
  173. channel <= iw_channel_table[i].max;
  174. break;
  175. }
  176. return rc;
  177. }
  178. /**
  179. * iw_default_channel - get default channel for a regulatory domain
  180. * @reg_comain - regulatory domain
  181. *
  182. * Returns the default channel for a regulatory domain
  183. */
  184. static int iw_default_channel(int reg_domain)
  185. {
  186. int i, rc = 1;
  187. for (i = 0; i < ARRAY_SIZE(iw_channel_table); i++)
  188. if (reg_domain == iw_channel_table[i].reg_domain) {
  189. rc = iw_channel_table[i].deflt;
  190. break;
  191. }
  192. return rc;
  193. }
  194. static void iw_set_mgmt_info_element(enum iw_mgmt_info_element_ids id,
  195. struct iw_mgmt_info_element *el,
  196. void *value, int len)
  197. {
  198. el->id = id;
  199. el->len = len;
  200. memcpy(el->data, value, len);
  201. }
  202. static void iw_copy_mgmt_info_element(struct iw_mgmt_info_element *to,
  203. struct iw_mgmt_info_element *from)
  204. {
  205. iw_set_mgmt_info_element(from->id, to, from->data, from->len);
  206. }
  207. /*
  208. * A linked list of "instances" of the wl24 device. Each actual PCMCIA card
  209. * corresponds to one device instance, and is described by one dev_link_t
  210. * structure (defined in ds.h).
  211. *
  212. * You may not want to use a linked list for this -- for example, the memory
  213. * card driver uses an array of dev_link_t pointers, where minor device numbers
  214. * are used to derive the corresponding array index.
  215. */
  216. static dev_link_t *wl3501_dev_list;
  217. static inline void wl3501_switch_page(struct wl3501_card *this, u8 page)
  218. {
  219. wl3501_outb(page, this->base_addr + WL3501_NIC_BSS);
  220. }
  221. /*
  222. * Get Ethernet MAC addresss.
  223. *
  224. * WARNING: We switch to FPAGE0 and switc back again.
  225. * Making sure there is no other WL function beening called by ISR.
  226. */
  227. static int wl3501_get_flash_mac_addr(struct wl3501_card *this)
  228. {
  229. int base_addr = this->base_addr;
  230. /* get MAC addr */
  231. wl3501_outb(WL3501_BSS_FPAGE3, base_addr + WL3501_NIC_BSS); /* BSS */
  232. wl3501_outb(0x00, base_addr + WL3501_NIC_LMAL); /* LMAL */
  233. wl3501_outb(0x40, base_addr + WL3501_NIC_LMAH); /* LMAH */
  234. /* wait for reading EEPROM */
  235. WL3501_NOPLOOP(100);
  236. this->mac_addr[0] = inb(base_addr + WL3501_NIC_IODPA);
  237. WL3501_NOPLOOP(100);
  238. this->mac_addr[1] = inb(base_addr + WL3501_NIC_IODPA);
  239. WL3501_NOPLOOP(100);
  240. this->mac_addr[2] = inb(base_addr + WL3501_NIC_IODPA);
  241. WL3501_NOPLOOP(100);
  242. this->mac_addr[3] = inb(base_addr + WL3501_NIC_IODPA);
  243. WL3501_NOPLOOP(100);
  244. this->mac_addr[4] = inb(base_addr + WL3501_NIC_IODPA);
  245. WL3501_NOPLOOP(100);
  246. this->mac_addr[5] = inb(base_addr + WL3501_NIC_IODPA);
  247. WL3501_NOPLOOP(100);
  248. this->reg_domain = inb(base_addr + WL3501_NIC_IODPA);
  249. WL3501_NOPLOOP(100);
  250. wl3501_outb(WL3501_BSS_FPAGE0, base_addr + WL3501_NIC_BSS);
  251. wl3501_outb(0x04, base_addr + WL3501_NIC_LMAL);
  252. wl3501_outb(0x40, base_addr + WL3501_NIC_LMAH);
  253. WL3501_NOPLOOP(100);
  254. this->version[0] = inb(base_addr + WL3501_NIC_IODPA);
  255. WL3501_NOPLOOP(100);
  256. this->version[1] = inb(base_addr + WL3501_NIC_IODPA);
  257. /* switch to SRAM Page 0 (for safety) */
  258. wl3501_switch_page(this, WL3501_BSS_SPAGE0);
  259. /* The MAC addr should be 00:60:... */
  260. return this->mac_addr[0] == 0x00 && this->mac_addr[1] == 0x60;
  261. }
  262. /**
  263. * wl3501_set_to_wla - Move 'size' bytes from PC to card
  264. * @dest: Card addressing space
  265. * @src: PC addressing space
  266. * @size: Bytes to move
  267. *
  268. * Move 'size' bytes from PC to card. (Shouldn't be interrupted)
  269. */
  270. static void wl3501_set_to_wla(struct wl3501_card *this, u16 dest, void *src,
  271. int size)
  272. {
  273. /* switch to SRAM Page 0 */
  274. wl3501_switch_page(this, (dest & 0x8000) ? WL3501_BSS_SPAGE1 :
  275. WL3501_BSS_SPAGE0);
  276. /* set LMAL and LMAH */
  277. wl3501_outb(dest & 0xff, this->base_addr + WL3501_NIC_LMAL);
  278. wl3501_outb(((dest >> 8) & 0x7f), this->base_addr + WL3501_NIC_LMAH);
  279. /* rep out to Port A */
  280. wl3501_outsb(this->base_addr + WL3501_NIC_IODPA, src, size);
  281. }
  282. /**
  283. * wl3501_get_from_wla - Move 'size' bytes from card to PC
  284. * @src: Card addressing space
  285. * @dest: PC addressing space
  286. * @size: Bytes to move
  287. *
  288. * Move 'size' bytes from card to PC. (Shouldn't be interrupted)
  289. */
  290. static void wl3501_get_from_wla(struct wl3501_card *this, u16 src, void *dest,
  291. int size)
  292. {
  293. /* switch to SRAM Page 0 */
  294. wl3501_switch_page(this, (src & 0x8000) ? WL3501_BSS_SPAGE1 :
  295. WL3501_BSS_SPAGE0);
  296. /* set LMAL and LMAH */
  297. wl3501_outb(src & 0xff, this->base_addr + WL3501_NIC_LMAL);
  298. wl3501_outb((src >> 8) & 0x7f, this->base_addr + WL3501_NIC_LMAH);
  299. /* rep get from Port A */
  300. insb(this->base_addr + WL3501_NIC_IODPA, dest, size);
  301. }
  302. /*
  303. * Get/Allocate a free Tx Data Buffer
  304. *
  305. * *--------------*-----------------*----------------------------------*
  306. * | PLCP | MAC Header | DST SRC Data ... |
  307. * | (24 bytes) | (30 bytes) | (6) (6) (Ethernet Row Data) |
  308. * *--------------*-----------------*----------------------------------*
  309. * \ \- IEEE 802.11 -/ \-------------- len --------------/
  310. * \-struct wl3501_80211_tx_hdr--/ \-------- Ethernet Frame -------/
  311. *
  312. * Return = Postion in Card
  313. */
  314. static u16 wl3501_get_tx_buffer(struct wl3501_card *this, u16 len)
  315. {
  316. u16 next, blk_cnt = 0, zero = 0;
  317. u16 full_len = sizeof(struct wl3501_80211_tx_hdr) + len;
  318. u16 ret = 0;
  319. if (full_len > this->tx_buffer_cnt * 254)
  320. goto out;
  321. ret = this->tx_buffer_head;
  322. while (full_len) {
  323. if (full_len < 254)
  324. full_len = 0;
  325. else
  326. full_len -= 254;
  327. wl3501_get_from_wla(this, this->tx_buffer_head, &next,
  328. sizeof(next));
  329. if (!full_len)
  330. wl3501_set_to_wla(this, this->tx_buffer_head, &zero,
  331. sizeof(zero));
  332. this->tx_buffer_head = next;
  333. blk_cnt++;
  334. /* if buffer is not enough */
  335. if (!next && full_len) {
  336. this->tx_buffer_head = ret;
  337. ret = 0;
  338. goto out;
  339. }
  340. }
  341. this->tx_buffer_cnt -= blk_cnt;
  342. out:
  343. return ret;
  344. }
  345. /*
  346. * Free an allocated Tx Buffer. ptr must be correct position.
  347. */
  348. static void wl3501_free_tx_buffer(struct wl3501_card *this, u16 ptr)
  349. {
  350. /* check if all space is not free */
  351. if (!this->tx_buffer_head)
  352. this->tx_buffer_head = ptr;
  353. else
  354. wl3501_set_to_wla(this, this->tx_buffer_tail,
  355. &ptr, sizeof(ptr));
  356. while (ptr) {
  357. u16 next;
  358. this->tx_buffer_cnt++;
  359. wl3501_get_from_wla(this, ptr, &next, sizeof(next));
  360. this->tx_buffer_tail = ptr;
  361. ptr = next;
  362. }
  363. }
  364. static int wl3501_esbq_req_test(struct wl3501_card *this)
  365. {
  366. u8 tmp;
  367. wl3501_get_from_wla(this, this->esbq_req_head + 3, &tmp, sizeof(tmp));
  368. return tmp & 0x80;
  369. }
  370. static void wl3501_esbq_req(struct wl3501_card *this, u16 *ptr)
  371. {
  372. u16 tmp = 0;
  373. wl3501_set_to_wla(this, this->esbq_req_head, ptr, 2);
  374. wl3501_set_to_wla(this, this->esbq_req_head + 2, &tmp, sizeof(tmp));
  375. this->esbq_req_head += 4;
  376. if (this->esbq_req_head >= this->esbq_req_end)
  377. this->esbq_req_head = this->esbq_req_start;
  378. }
  379. static int wl3501_esbq_exec(struct wl3501_card *this, void *sig, int sig_size)
  380. {
  381. int rc = -EIO;
  382. if (wl3501_esbq_req_test(this)) {
  383. u16 ptr = wl3501_get_tx_buffer(this, sig_size);
  384. if (ptr) {
  385. wl3501_set_to_wla(this, ptr, sig, sig_size);
  386. wl3501_esbq_req(this, &ptr);
  387. rc = 0;
  388. }
  389. }
  390. return rc;
  391. }
  392. static int wl3501_get_mib_value(struct wl3501_card *this, u8 index,
  393. void *bf, int size)
  394. {
  395. struct wl3501_get_req sig = {
  396. .sig_id = WL3501_SIG_GET_REQ,
  397. .mib_attrib = index,
  398. };
  399. unsigned long flags;
  400. int rc = -EIO;
  401. spin_lock_irqsave(&this->lock, flags);
  402. if (wl3501_esbq_req_test(this)) {
  403. u16 ptr = wl3501_get_tx_buffer(this, sizeof(sig));
  404. if (ptr) {
  405. wl3501_set_to_wla(this, ptr, &sig, sizeof(sig));
  406. wl3501_esbq_req(this, &ptr);
  407. this->sig_get_confirm.mib_status = 255;
  408. spin_unlock_irqrestore(&this->lock, flags);
  409. rc = wait_event_interruptible(this->wait,
  410. this->sig_get_confirm.mib_status != 255);
  411. if (!rc)
  412. memcpy(bf, this->sig_get_confirm.mib_value,
  413. size);
  414. goto out;
  415. }
  416. }
  417. spin_unlock_irqrestore(&this->lock, flags);
  418. out:
  419. return rc;
  420. }
  421. static int wl3501_pwr_mgmt(struct wl3501_card *this, int suspend)
  422. {
  423. struct wl3501_pwr_mgmt_req sig = {
  424. .sig_id = WL3501_SIG_PWR_MGMT_REQ,
  425. .pwr_save = suspend,
  426. .wake_up = !suspend,
  427. .receive_dtims = 10,
  428. };
  429. unsigned long flags;
  430. int rc = -EIO;
  431. spin_lock_irqsave(&this->lock, flags);
  432. if (wl3501_esbq_req_test(this)) {
  433. u16 ptr = wl3501_get_tx_buffer(this, sizeof(sig));
  434. if (ptr) {
  435. wl3501_set_to_wla(this, ptr, &sig, sizeof(sig));
  436. wl3501_esbq_req(this, &ptr);
  437. this->sig_pwr_mgmt_confirm.status = 255;
  438. spin_unlock_irqrestore(&this->lock, flags);
  439. rc = wait_event_interruptible(this->wait,
  440. this->sig_pwr_mgmt_confirm.status != 255);
  441. printk(KERN_INFO "%s: %s status=%d\n", __FUNCTION__,
  442. suspend ? "suspend" : "resume",
  443. this->sig_pwr_mgmt_confirm.status);
  444. goto out;
  445. }
  446. }
  447. spin_unlock_irqrestore(&this->lock, flags);
  448. out:
  449. return rc;
  450. }
  451. /**
  452. * wl3501_send_pkt - Send a packet.
  453. * @this - card
  454. *
  455. * Send a packet.
  456. *
  457. * data = Ethernet raw frame. (e.g. data[0] - data[5] is Dest MAC Addr,
  458. * data[6] - data[11] is Src MAC Addr)
  459. * Ref: IEEE 802.11
  460. */
  461. static int wl3501_send_pkt(struct wl3501_card *this, u8 *data, u16 len)
  462. {
  463. u16 bf, sig_bf, next, tmplen, pktlen;
  464. struct wl3501_md_req sig = {
  465. .sig_id = WL3501_SIG_MD_REQ,
  466. };
  467. u8 *pdata = (char *)data;
  468. int rc = -EIO;
  469. if (wl3501_esbq_req_test(this)) {
  470. sig_bf = wl3501_get_tx_buffer(this, sizeof(sig));
  471. rc = -ENOMEM;
  472. if (!sig_bf) /* No free buffer available */
  473. goto out;
  474. bf = wl3501_get_tx_buffer(this, len + 26 + 24);
  475. if (!bf) {
  476. /* No free buffer available */
  477. wl3501_free_tx_buffer(this, sig_bf);
  478. goto out;
  479. }
  480. rc = 0;
  481. memcpy(&sig.daddr[0], pdata, 12);
  482. pktlen = len - 12;
  483. pdata += 12;
  484. sig.data = bf;
  485. if (((*pdata) * 256 + (*(pdata + 1))) > 1500) {
  486. u8 addr4[ETH_ALEN] = {
  487. [0] = 0xAA, [1] = 0xAA, [2] = 0x03, [4] = 0x00,
  488. };
  489. wl3501_set_to_wla(this, bf + 2 +
  490. offsetof(struct wl3501_tx_hdr, addr4),
  491. addr4, sizeof(addr4));
  492. sig.size = pktlen + 24 + 4 + 6;
  493. if (pktlen > (254 - sizeof(struct wl3501_tx_hdr))) {
  494. tmplen = 254 - sizeof(struct wl3501_tx_hdr);
  495. pktlen -= tmplen;
  496. } else {
  497. tmplen = pktlen;
  498. pktlen = 0;
  499. }
  500. wl3501_set_to_wla(this,
  501. bf + 2 + sizeof(struct wl3501_tx_hdr),
  502. pdata, tmplen);
  503. pdata += tmplen;
  504. wl3501_get_from_wla(this, bf, &next, sizeof(next));
  505. bf = next;
  506. } else {
  507. sig.size = pktlen + 24 + 4 - 2;
  508. pdata += 2;
  509. pktlen -= 2;
  510. if (pktlen > (254 - sizeof(struct wl3501_tx_hdr) + 6)) {
  511. tmplen = 254 - sizeof(struct wl3501_tx_hdr) + 6;
  512. pktlen -= tmplen;
  513. } else {
  514. tmplen = pktlen;
  515. pktlen = 0;
  516. }
  517. wl3501_set_to_wla(this, bf + 2 +
  518. offsetof(struct wl3501_tx_hdr, addr4),
  519. pdata, tmplen);
  520. pdata += tmplen;
  521. wl3501_get_from_wla(this, bf, &next, sizeof(next));
  522. bf = next;
  523. }
  524. while (pktlen > 0) {
  525. if (pktlen > 254) {
  526. tmplen = 254;
  527. pktlen -= 254;
  528. } else {
  529. tmplen = pktlen;
  530. pktlen = 0;
  531. }
  532. wl3501_set_to_wla(this, bf + 2, pdata, tmplen);
  533. pdata += tmplen;
  534. wl3501_get_from_wla(this, bf, &next, sizeof(next));
  535. bf = next;
  536. }
  537. wl3501_set_to_wla(this, sig_bf, &sig, sizeof(sig));
  538. wl3501_esbq_req(this, &sig_bf);
  539. }
  540. out:
  541. return rc;
  542. }
  543. static int wl3501_mgmt_resync(struct wl3501_card *this)
  544. {
  545. struct wl3501_resync_req sig = {
  546. .sig_id = WL3501_SIG_RESYNC_REQ,
  547. };
  548. return wl3501_esbq_exec(this, &sig, sizeof(sig));
  549. }
  550. static inline int wl3501_fw_bss_type(struct wl3501_card *this)
  551. {
  552. return this->net_type == IW_MODE_INFRA ? WL3501_NET_TYPE_INFRA :
  553. WL3501_NET_TYPE_ADHOC;
  554. }
  555. static inline int wl3501_fw_cap_info(struct wl3501_card *this)
  556. {
  557. return this->net_type == IW_MODE_INFRA ? WL3501_MGMT_CAPABILITY_ESS :
  558. WL3501_MGMT_CAPABILITY_IBSS;
  559. }
  560. static int wl3501_mgmt_scan(struct wl3501_card *this, u16 chan_time)
  561. {
  562. struct wl3501_scan_req sig = {
  563. .sig_id = WL3501_SIG_SCAN_REQ,
  564. .scan_type = WL3501_SCAN_TYPE_ACTIVE,
  565. .probe_delay = 0x10,
  566. .min_chan_time = chan_time,
  567. .max_chan_time = chan_time,
  568. .bss_type = wl3501_fw_bss_type(this),
  569. };
  570. this->bss_cnt = this->join_sta_bss = 0;
  571. return wl3501_esbq_exec(this, &sig, sizeof(sig));
  572. }
  573. static int wl3501_mgmt_join(struct wl3501_card *this, u16 stas)
  574. {
  575. struct wl3501_join_req sig = {
  576. .sig_id = WL3501_SIG_JOIN_REQ,
  577. .timeout = 10,
  578. .ds_pset = {
  579. .el = {
  580. .id = IW_MGMT_INFO_ELEMENT_DS_PARAMETER_SET,
  581. .len = 1,
  582. },
  583. .chan = this->chan,
  584. },
  585. };
  586. memcpy(&sig.beacon_period, &this->bss_set[stas].beacon_period, 72);
  587. return wl3501_esbq_exec(this, &sig, sizeof(sig));
  588. }
  589. static int wl3501_mgmt_start(struct wl3501_card *this)
  590. {
  591. struct wl3501_start_req sig = {
  592. .sig_id = WL3501_SIG_START_REQ,
  593. .beacon_period = 400,
  594. .dtim_period = 1,
  595. .ds_pset = {
  596. .el = {
  597. .id = IW_MGMT_INFO_ELEMENT_DS_PARAMETER_SET,
  598. .len = 1,
  599. },
  600. .chan = this->chan,
  601. },
  602. .bss_basic_rset = {
  603. .el = {
  604. .id = IW_MGMT_INFO_ELEMENT_SUPPORTED_RATES,
  605. .len = 2,
  606. },
  607. .data_rate_labels = {
  608. [0] = IW_MGMT_RATE_LABEL_MANDATORY |
  609. IW_MGMT_RATE_LABEL_1MBIT,
  610. [1] = IW_MGMT_RATE_LABEL_MANDATORY |
  611. IW_MGMT_RATE_LABEL_2MBIT,
  612. },
  613. },
  614. .operational_rset = {
  615. .el = {
  616. .id = IW_MGMT_INFO_ELEMENT_SUPPORTED_RATES,
  617. .len = 2,
  618. },
  619. .data_rate_labels = {
  620. [0] = IW_MGMT_RATE_LABEL_MANDATORY |
  621. IW_MGMT_RATE_LABEL_1MBIT,
  622. [1] = IW_MGMT_RATE_LABEL_MANDATORY |
  623. IW_MGMT_RATE_LABEL_2MBIT,
  624. },
  625. },
  626. .ibss_pset = {
  627. .el = {
  628. .id = IW_MGMT_INFO_ELEMENT_IBSS_PARAMETER_SET,
  629. .len = 2,
  630. },
  631. .atim_window = 10,
  632. },
  633. .bss_type = wl3501_fw_bss_type(this),
  634. .cap_info = wl3501_fw_cap_info(this),
  635. };
  636. iw_copy_mgmt_info_element(&sig.ssid.el, &this->essid.el);
  637. iw_copy_mgmt_info_element(&this->keep_essid.el, &this->essid.el);
  638. return wl3501_esbq_exec(this, &sig, sizeof(sig));
  639. }
  640. static void wl3501_mgmt_scan_confirm(struct wl3501_card *this, u16 addr)
  641. {
  642. u16 i = 0;
  643. int matchflag = 0;
  644. struct wl3501_scan_confirm sig;
  645. dprintk(3, "entry");
  646. wl3501_get_from_wla(this, addr, &sig, sizeof(sig));
  647. if (sig.status == WL3501_STATUS_SUCCESS) {
  648. dprintk(3, "success");
  649. if ((this->net_type == IW_MODE_INFRA &&
  650. (sig.cap_info & WL3501_MGMT_CAPABILITY_ESS)) ||
  651. (this->net_type == IW_MODE_ADHOC &&
  652. (sig.cap_info & WL3501_MGMT_CAPABILITY_IBSS)) ||
  653. this->net_type == IW_MODE_AUTO) {
  654. if (!this->essid.el.len)
  655. matchflag = 1;
  656. else if (this->essid.el.len == 3 &&
  657. !memcmp(this->essid.essid, "ANY", 3))
  658. matchflag = 1;
  659. else if (this->essid.el.len != sig.ssid.el.len)
  660. matchflag = 0;
  661. else if (memcmp(this->essid.essid, sig.ssid.essid,
  662. this->essid.el.len))
  663. matchflag = 0;
  664. else
  665. matchflag = 1;
  666. if (matchflag) {
  667. for (i = 0; i < this->bss_cnt; i++) {
  668. if (!memcmp(this->bss_set[i].bssid,
  669. sig.bssid, ETH_ALEN)) {
  670. matchflag = 0;
  671. break;
  672. }
  673. }
  674. }
  675. if (matchflag && (i < 20)) {
  676. memcpy(&this->bss_set[i].beacon_period,
  677. &sig.beacon_period, 73);
  678. this->bss_cnt++;
  679. this->rssi = sig.rssi;
  680. }
  681. }
  682. } else if (sig.status == WL3501_STATUS_TIMEOUT) {
  683. dprintk(3, "timeout");
  684. this->join_sta_bss = 0;
  685. for (i = this->join_sta_bss; i < this->bss_cnt; i++)
  686. if (!wl3501_mgmt_join(this, i))
  687. break;
  688. this->join_sta_bss = i;
  689. if (this->join_sta_bss == this->bss_cnt) {
  690. if (this->net_type == IW_MODE_INFRA)
  691. wl3501_mgmt_scan(this, 100);
  692. else {
  693. this->adhoc_times++;
  694. if (this->adhoc_times > WL3501_MAX_ADHOC_TRIES)
  695. wl3501_mgmt_start(this);
  696. else
  697. wl3501_mgmt_scan(this, 100);
  698. }
  699. }
  700. }
  701. }
  702. /**
  703. * wl3501_block_interrupt - Mask interrupt from SUTRO
  704. * @this - card
  705. *
  706. * Mask interrupt from SUTRO. (i.e. SUTRO cannot interrupt the HOST)
  707. * Return: 1 if interrupt is originally enabled
  708. */
  709. static int wl3501_block_interrupt(struct wl3501_card *this)
  710. {
  711. u8 old = inb(this->base_addr + WL3501_NIC_GCR);
  712. u8 new = old & (~(WL3501_GCR_ECINT | WL3501_GCR_INT2EC |
  713. WL3501_GCR_ENECINT));
  714. wl3501_outb(new, this->base_addr + WL3501_NIC_GCR);
  715. return old & WL3501_GCR_ENECINT;
  716. }
  717. /**
  718. * wl3501_unblock_interrupt - Enable interrupt from SUTRO
  719. * @this - card
  720. *
  721. * Enable interrupt from SUTRO. (i.e. SUTRO can interrupt the HOST)
  722. * Return: 1 if interrupt is originally enabled
  723. */
  724. static int wl3501_unblock_interrupt(struct wl3501_card *this)
  725. {
  726. u8 old = inb(this->base_addr + WL3501_NIC_GCR);
  727. u8 new = (old & ~(WL3501_GCR_ECINT | WL3501_GCR_INT2EC)) |
  728. WL3501_GCR_ENECINT;
  729. wl3501_outb(new, this->base_addr + WL3501_NIC_GCR);
  730. return old & WL3501_GCR_ENECINT;
  731. }
  732. /**
  733. * wl3501_receive - Receive data from Receive Queue.
  734. *
  735. * Receive data from Receive Queue.
  736. *
  737. * @this: card
  738. * @bf: address of host
  739. * @size: size of buffer.
  740. */
  741. static u16 wl3501_receive(struct wl3501_card *this, u8 *bf, u16 size)
  742. {
  743. u16 next_addr, next_addr1;
  744. u8 *data = bf + 12;
  745. size -= 12;
  746. wl3501_get_from_wla(this, this->start_seg + 2,
  747. &next_addr, sizeof(next_addr));
  748. if (size > WL3501_BLKSZ - sizeof(struct wl3501_rx_hdr)) {
  749. wl3501_get_from_wla(this,
  750. this->start_seg +
  751. sizeof(struct wl3501_rx_hdr), data,
  752. WL3501_BLKSZ -
  753. sizeof(struct wl3501_rx_hdr));
  754. size -= WL3501_BLKSZ - sizeof(struct wl3501_rx_hdr);
  755. data += WL3501_BLKSZ - sizeof(struct wl3501_rx_hdr);
  756. } else {
  757. wl3501_get_from_wla(this,
  758. this->start_seg +
  759. sizeof(struct wl3501_rx_hdr),
  760. data, size);
  761. size = 0;
  762. }
  763. while (size > 0) {
  764. if (size > WL3501_BLKSZ - 5) {
  765. wl3501_get_from_wla(this, next_addr + 5, data,
  766. WL3501_BLKSZ - 5);
  767. size -= WL3501_BLKSZ - 5;
  768. data += WL3501_BLKSZ - 5;
  769. wl3501_get_from_wla(this, next_addr + 2, &next_addr1,
  770. sizeof(next_addr1));
  771. next_addr = next_addr1;
  772. } else {
  773. wl3501_get_from_wla(this, next_addr + 5, data, size);
  774. size = 0;
  775. }
  776. }
  777. return 0;
  778. }
  779. static void wl3501_esbq_req_free(struct wl3501_card *this)
  780. {
  781. u8 tmp;
  782. u16 addr;
  783. if (this->esbq_req_head == this->esbq_req_tail)
  784. goto out;
  785. wl3501_get_from_wla(this, this->esbq_req_tail + 3, &tmp, sizeof(tmp));
  786. if (!(tmp & 0x80))
  787. goto out;
  788. wl3501_get_from_wla(this, this->esbq_req_tail, &addr, sizeof(addr));
  789. wl3501_free_tx_buffer(this, addr);
  790. this->esbq_req_tail += 4;
  791. if (this->esbq_req_tail >= this->esbq_req_end)
  792. this->esbq_req_tail = this->esbq_req_start;
  793. out:
  794. return;
  795. }
  796. static int wl3501_esbq_confirm(struct wl3501_card *this)
  797. {
  798. u8 tmp;
  799. wl3501_get_from_wla(this, this->esbq_confirm + 3, &tmp, sizeof(tmp));
  800. return tmp & 0x80;
  801. }
  802. static void wl3501_online(struct net_device *dev)
  803. {
  804. struct wl3501_card *this = dev->priv;
  805. printk(KERN_INFO "%s: Wireless LAN online. BSSID: "
  806. "%02X %02X %02X %02X %02X %02X\n", dev->name,
  807. this->bssid[0], this->bssid[1], this->bssid[2],
  808. this->bssid[3], this->bssid[4], this->bssid[5]);
  809. netif_wake_queue(dev);
  810. }
  811. static void wl3501_esbq_confirm_done(struct wl3501_card *this)
  812. {
  813. u8 tmp = 0;
  814. wl3501_set_to_wla(this, this->esbq_confirm + 3, &tmp, sizeof(tmp));
  815. this->esbq_confirm += 4;
  816. if (this->esbq_confirm >= this->esbq_confirm_end)
  817. this->esbq_confirm = this->esbq_confirm_start;
  818. }
  819. static int wl3501_mgmt_auth(struct wl3501_card *this)
  820. {
  821. struct wl3501_auth_req sig = {
  822. .sig_id = WL3501_SIG_AUTH_REQ,
  823. .type = WL3501_SYS_TYPE_OPEN,
  824. .timeout = 1000,
  825. };
  826. dprintk(3, "entry");
  827. memcpy(sig.mac_addr, this->bssid, ETH_ALEN);
  828. return wl3501_esbq_exec(this, &sig, sizeof(sig));
  829. }
  830. static int wl3501_mgmt_association(struct wl3501_card *this)
  831. {
  832. struct wl3501_assoc_req sig = {
  833. .sig_id = WL3501_SIG_ASSOC_REQ,
  834. .timeout = 1000,
  835. .listen_interval = 5,
  836. .cap_info = this->cap_info,
  837. };
  838. dprintk(3, "entry");
  839. memcpy(sig.mac_addr, this->bssid, ETH_ALEN);
  840. return wl3501_esbq_exec(this, &sig, sizeof(sig));
  841. }
  842. static void wl3501_mgmt_join_confirm(struct net_device *dev, u16 addr)
  843. {
  844. struct wl3501_card *this = dev->priv;
  845. struct wl3501_join_confirm sig;
  846. dprintk(3, "entry");
  847. wl3501_get_from_wla(this, addr, &sig, sizeof(sig));
  848. if (sig.status == WL3501_STATUS_SUCCESS) {
  849. if (this->net_type == IW_MODE_INFRA) {
  850. if (this->join_sta_bss < this->bss_cnt) {
  851. const int i = this->join_sta_bss;
  852. memcpy(this->bssid,
  853. this->bss_set[i].bssid, ETH_ALEN);
  854. this->chan = this->bss_set[i].ds_pset.chan;
  855. iw_copy_mgmt_info_element(&this->keep_essid.el,
  856. &this->bss_set[i].ssid.el);
  857. wl3501_mgmt_auth(this);
  858. }
  859. } else {
  860. const int i = this->join_sta_bss;
  861. memcpy(&this->bssid, &this->bss_set[i].bssid, ETH_ALEN);
  862. this->chan = this->bss_set[i].ds_pset.chan;
  863. iw_copy_mgmt_info_element(&this->keep_essid.el,
  864. &this->bss_set[i].ssid.el);
  865. wl3501_online(dev);
  866. }
  867. } else {
  868. int i;
  869. this->join_sta_bss++;
  870. for (i = this->join_sta_bss; i < this->bss_cnt; i++)
  871. if (!wl3501_mgmt_join(this, i))
  872. break;
  873. this->join_sta_bss = i;
  874. if (this->join_sta_bss == this->bss_cnt) {
  875. if (this->net_type == IW_MODE_INFRA)
  876. wl3501_mgmt_scan(this, 100);
  877. else {
  878. this->adhoc_times++;
  879. if (this->adhoc_times > WL3501_MAX_ADHOC_TRIES)
  880. wl3501_mgmt_start(this);
  881. else
  882. wl3501_mgmt_scan(this, 100);
  883. }
  884. }
  885. }
  886. }
  887. static inline void wl3501_alarm_interrupt(struct net_device *dev,
  888. struct wl3501_card *this)
  889. {
  890. if (this->net_type == IW_MODE_INFRA) {
  891. printk(KERN_INFO "Wireless LAN offline\n");
  892. netif_stop_queue(dev);
  893. wl3501_mgmt_resync(this);
  894. }
  895. }
  896. static inline void wl3501_md_confirm_interrupt(struct net_device *dev,
  897. struct wl3501_card *this,
  898. u16 addr)
  899. {
  900. struct wl3501_md_confirm sig;
  901. dprintk(3, "entry");
  902. wl3501_get_from_wla(this, addr, &sig, sizeof(sig));
  903. wl3501_free_tx_buffer(this, sig.data);
  904. if (netif_queue_stopped(dev))
  905. netif_wake_queue(dev);
  906. }
  907. static inline void wl3501_md_ind_interrupt(struct net_device *dev,
  908. struct wl3501_card *this, u16 addr)
  909. {
  910. struct wl3501_md_ind sig;
  911. struct sk_buff *skb;
  912. u8 rssi, addr4[ETH_ALEN];
  913. u16 pkt_len;
  914. wl3501_get_from_wla(this, addr, &sig, sizeof(sig));
  915. this->start_seg = sig.data;
  916. wl3501_get_from_wla(this,
  917. sig.data + offsetof(struct wl3501_rx_hdr, rssi),
  918. &rssi, sizeof(rssi));
  919. this->rssi = rssi <= 63 ? (rssi * 100) / 64 : 255;
  920. wl3501_get_from_wla(this,
  921. sig.data +
  922. offsetof(struct wl3501_rx_hdr, addr4),
  923. &addr4, sizeof(addr4));
  924. if (!(addr4[0] == 0xAA && addr4[1] == 0xAA &&
  925. addr4[2] == 0x03 && addr4[4] == 0x00)) {
  926. printk(KERN_INFO "Insupported packet type!\n");
  927. return;
  928. }
  929. pkt_len = sig.size + 12 - 24 - 4 - 6;
  930. skb = dev_alloc_skb(pkt_len + 5);
  931. if (!skb) {
  932. printk(KERN_WARNING "%s: Can't alloc a sk_buff of size %d.\n",
  933. dev->name, pkt_len);
  934. this->stats.rx_dropped++;
  935. } else {
  936. skb->dev = dev;
  937. skb_reserve(skb, 2); /* IP headers on 16 bytes boundaries */
  938. eth_copy_and_sum(skb, (unsigned char *)&sig.daddr, 12, 0);
  939. wl3501_receive(this, skb->data, pkt_len);
  940. skb_put(skb, pkt_len);
  941. skb->protocol = eth_type_trans(skb, dev);
  942. dev->last_rx = jiffies;
  943. this->stats.rx_packets++;
  944. this->stats.rx_bytes += skb->len;
  945. netif_rx(skb);
  946. }
  947. }
  948. static inline void wl3501_get_confirm_interrupt(struct wl3501_card *this,
  949. u16 addr, void *sig, int size)
  950. {
  951. dprintk(3, "entry");
  952. wl3501_get_from_wla(this, addr, &this->sig_get_confirm,
  953. sizeof(this->sig_get_confirm));
  954. wake_up(&this->wait);
  955. }
  956. static inline void wl3501_start_confirm_interrupt(struct net_device *dev,
  957. struct wl3501_card *this,
  958. u16 addr)
  959. {
  960. struct wl3501_start_confirm sig;
  961. dprintk(3, "entry");
  962. wl3501_get_from_wla(this, addr, &sig, sizeof(sig));
  963. if (sig.status == WL3501_STATUS_SUCCESS)
  964. netif_wake_queue(dev);
  965. }
  966. static inline void wl3501_assoc_confirm_interrupt(struct net_device *dev,
  967. u16 addr)
  968. {
  969. struct wl3501_card *this = dev->priv;
  970. struct wl3501_assoc_confirm sig;
  971. dprintk(3, "entry");
  972. wl3501_get_from_wla(this, addr, &sig, sizeof(sig));
  973. if (sig.status == WL3501_STATUS_SUCCESS)
  974. wl3501_online(dev);
  975. }
  976. static inline void wl3501_auth_confirm_interrupt(struct wl3501_card *this,
  977. u16 addr)
  978. {
  979. struct wl3501_auth_confirm sig;
  980. dprintk(3, "entry");
  981. wl3501_get_from_wla(this, addr, &sig, sizeof(sig));
  982. if (sig.status == WL3501_STATUS_SUCCESS)
  983. wl3501_mgmt_association(this);
  984. else
  985. wl3501_mgmt_resync(this);
  986. }
  987. static inline void wl3501_rx_interrupt(struct net_device *dev)
  988. {
  989. int morepkts;
  990. u16 addr;
  991. u8 sig_id;
  992. struct wl3501_card *this = dev->priv;
  993. dprintk(3, "entry");
  994. loop:
  995. morepkts = 0;
  996. if (!wl3501_esbq_confirm(this))
  997. goto free;
  998. wl3501_get_from_wla(this, this->esbq_confirm, &addr, sizeof(addr));
  999. wl3501_get_from_wla(this, addr + 2, &sig_id, sizeof(sig_id));
  1000. switch (sig_id) {
  1001. case WL3501_SIG_DEAUTH_IND:
  1002. case WL3501_SIG_DISASSOC_IND:
  1003. case WL3501_SIG_ALARM:
  1004. wl3501_alarm_interrupt(dev, this);
  1005. break;
  1006. case WL3501_SIG_MD_CONFIRM:
  1007. wl3501_md_confirm_interrupt(dev, this, addr);
  1008. break;
  1009. case WL3501_SIG_MD_IND:
  1010. wl3501_md_ind_interrupt(dev, this, addr);
  1011. break;
  1012. case WL3501_SIG_GET_CONFIRM:
  1013. wl3501_get_confirm_interrupt(this, addr,
  1014. &this->sig_get_confirm,
  1015. sizeof(this->sig_get_confirm));
  1016. break;
  1017. case WL3501_SIG_PWR_MGMT_CONFIRM:
  1018. wl3501_get_confirm_interrupt(this, addr,
  1019. &this->sig_pwr_mgmt_confirm,
  1020. sizeof(this->sig_pwr_mgmt_confirm));
  1021. break;
  1022. case WL3501_SIG_START_CONFIRM:
  1023. wl3501_start_confirm_interrupt(dev, this, addr);
  1024. break;
  1025. case WL3501_SIG_SCAN_CONFIRM:
  1026. wl3501_mgmt_scan_confirm(this, addr);
  1027. break;
  1028. case WL3501_SIG_JOIN_CONFIRM:
  1029. wl3501_mgmt_join_confirm(dev, addr);
  1030. break;
  1031. case WL3501_SIG_ASSOC_CONFIRM:
  1032. wl3501_assoc_confirm_interrupt(dev, addr);
  1033. break;
  1034. case WL3501_SIG_AUTH_CONFIRM:
  1035. wl3501_auth_confirm_interrupt(this, addr);
  1036. break;
  1037. case WL3501_SIG_RESYNC_CONFIRM:
  1038. wl3501_mgmt_resync(this); /* FIXME: should be resync_confirm */
  1039. break;
  1040. }
  1041. wl3501_esbq_confirm_done(this);
  1042. morepkts = 1;
  1043. /* free request if necessary */
  1044. free:
  1045. wl3501_esbq_req_free(this);
  1046. if (morepkts)
  1047. goto loop;
  1048. }
  1049. static inline void wl3501_ack_interrupt(struct wl3501_card *this)
  1050. {
  1051. wl3501_outb(WL3501_GCR_ECINT, this->base_addr + WL3501_NIC_GCR);
  1052. }
  1053. /**
  1054. * wl3501_interrupt - Hardware interrupt from card.
  1055. * @irq - Interrupt number
  1056. * @dev_id - net_device
  1057. * @regs - registers
  1058. *
  1059. * We must acknowledge the interrupt as soon as possible, and block the
  1060. * interrupt from the same card immediately to prevent re-entry.
  1061. *
  1062. * Before accessing the Control_Status_Block, we must lock SUTRO first.
  1063. * On the other hand, to prevent SUTRO from malfunctioning, we must
  1064. * unlock the SUTRO as soon as possible.
  1065. */
  1066. static irqreturn_t wl3501_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  1067. {
  1068. struct net_device *dev = (struct net_device *)dev_id;
  1069. struct wl3501_card *this;
  1070. int handled = 1;
  1071. if (!dev)
  1072. goto unknown;
  1073. this = dev->priv;
  1074. spin_lock(&this->lock);
  1075. wl3501_ack_interrupt(this);
  1076. wl3501_block_interrupt(this);
  1077. wl3501_rx_interrupt(dev);
  1078. wl3501_unblock_interrupt(this);
  1079. spin_unlock(&this->lock);
  1080. out:
  1081. return IRQ_RETVAL(handled);
  1082. unknown:
  1083. handled = 0;
  1084. printk(KERN_ERR "%s: irq %d for unknown device.\n", __FUNCTION__, irq);
  1085. goto out;
  1086. }
  1087. static int wl3501_reset_board(struct wl3501_card *this)
  1088. {
  1089. u8 tmp = 0;
  1090. int i, rc = 0;
  1091. /* Coreset */
  1092. wl3501_outb_p(WL3501_GCR_CORESET, this->base_addr + WL3501_NIC_GCR);
  1093. wl3501_outb_p(0, this->base_addr + WL3501_NIC_GCR);
  1094. wl3501_outb_p(WL3501_GCR_CORESET, this->base_addr + WL3501_NIC_GCR);
  1095. /* Reset SRAM 0x480 to zero */
  1096. wl3501_set_to_wla(this, 0x480, &tmp, sizeof(tmp));
  1097. /* Start up */
  1098. wl3501_outb_p(0, this->base_addr + WL3501_NIC_GCR);
  1099. WL3501_NOPLOOP(1024 * 50);
  1100. wl3501_unblock_interrupt(this); /* acme: was commented */
  1101. /* Polling Self_Test_Status */
  1102. for (i = 0; i < 10000; i++) {
  1103. wl3501_get_from_wla(this, 0x480, &tmp, sizeof(tmp));
  1104. if (tmp == 'W') {
  1105. /* firmware complete all test successfully */
  1106. tmp = 'A';
  1107. wl3501_set_to_wla(this, 0x480, &tmp, sizeof(tmp));
  1108. goto out;
  1109. }
  1110. WL3501_NOPLOOP(10);
  1111. }
  1112. printk(KERN_WARNING "%s: failed to reset the board!\n", __FUNCTION__);
  1113. rc = -ENODEV;
  1114. out:
  1115. return rc;
  1116. }
  1117. static int wl3501_init_firmware(struct wl3501_card *this)
  1118. {
  1119. u16 ptr, next;
  1120. int rc = wl3501_reset_board(this);
  1121. if (rc)
  1122. goto fail;
  1123. this->card_name[0] = '\0';
  1124. wl3501_get_from_wla(this, 0x1a00,
  1125. this->card_name, sizeof(this->card_name));
  1126. this->card_name[sizeof(this->card_name) - 1] = '\0';
  1127. this->firmware_date[0] = '\0';
  1128. wl3501_get_from_wla(this, 0x1a40,
  1129. this->firmware_date, sizeof(this->firmware_date));
  1130. this->firmware_date[sizeof(this->firmware_date) - 1] = '\0';
  1131. /* Switch to SRAM Page 0 */
  1132. wl3501_switch_page(this, WL3501_BSS_SPAGE0);
  1133. /* Read parameter from card */
  1134. wl3501_get_from_wla(this, 0x482, &this->esbq_req_start, 2);
  1135. wl3501_get_from_wla(this, 0x486, &this->esbq_req_end, 2);
  1136. wl3501_get_from_wla(this, 0x488, &this->esbq_confirm_start, 2);
  1137. wl3501_get_from_wla(this, 0x48c, &this->esbq_confirm_end, 2);
  1138. wl3501_get_from_wla(this, 0x48e, &this->tx_buffer_head, 2);
  1139. wl3501_get_from_wla(this, 0x492, &this->tx_buffer_size, 2);
  1140. this->esbq_req_tail = this->esbq_req_head = this->esbq_req_start;
  1141. this->esbq_req_end += this->esbq_req_start;
  1142. this->esbq_confirm = this->esbq_confirm_start;
  1143. this->esbq_confirm_end += this->esbq_confirm_start;
  1144. /* Initial Tx Buffer */
  1145. this->tx_buffer_cnt = 1;
  1146. ptr = this->tx_buffer_head;
  1147. next = ptr + WL3501_BLKSZ;
  1148. while ((next - this->tx_buffer_head) < this->tx_buffer_size) {
  1149. this->tx_buffer_cnt++;
  1150. wl3501_set_to_wla(this, ptr, &next, sizeof(next));
  1151. ptr = next;
  1152. next = ptr + WL3501_BLKSZ;
  1153. }
  1154. rc = 0;
  1155. next = 0;
  1156. wl3501_set_to_wla(this, ptr, &next, sizeof(next));
  1157. this->tx_buffer_tail = ptr;
  1158. out:
  1159. return rc;
  1160. fail:
  1161. printk(KERN_WARNING "%s: failed!\n", __FUNCTION__);
  1162. goto out;
  1163. }
  1164. static int wl3501_close(struct net_device *dev)
  1165. {
  1166. struct wl3501_card *this = dev->priv;
  1167. int rc = -ENODEV;
  1168. unsigned long flags;
  1169. dev_link_t *link;
  1170. spin_lock_irqsave(&this->lock, flags);
  1171. /* Check if the device is in wl3501_dev_list */
  1172. for (link = wl3501_dev_list; link; link = link->next)
  1173. if (link->priv == dev)
  1174. break;
  1175. if (!link)
  1176. goto out;
  1177. link->open--;
  1178. /* Stop wl3501_hard_start_xmit() from now on */
  1179. netif_stop_queue(dev);
  1180. wl3501_ack_interrupt(this);
  1181. /* Mask interrupts from the SUTRO */
  1182. wl3501_block_interrupt(this);
  1183. rc = 0;
  1184. printk(KERN_INFO "%s: WL3501 closed\n", dev->name);
  1185. out:
  1186. spin_unlock_irqrestore(&this->lock, flags);
  1187. return rc;
  1188. }
  1189. /**
  1190. * wl3501_reset - Reset the SUTRO.
  1191. * @dev - network device
  1192. *
  1193. * It is almost the same as wl3501_open(). In fact, we may just wl3501_close()
  1194. * and wl3501_open() again, but I wouldn't like to free_irq() when the driver
  1195. * is running. It seems to be dangerous.
  1196. */
  1197. static int wl3501_reset(struct net_device *dev)
  1198. {
  1199. struct wl3501_card *this = dev->priv;
  1200. int rc = -ENODEV;
  1201. wl3501_block_interrupt(this);
  1202. if (wl3501_init_firmware(this)) {
  1203. printk(KERN_WARNING "%s: Can't initialize Firmware!\n",
  1204. dev->name);
  1205. /* Free IRQ, and mark IRQ as unused */
  1206. free_irq(dev->irq, dev);
  1207. goto out;
  1208. }
  1209. /*
  1210. * Queue has to be started only when the Card is Started
  1211. */
  1212. netif_stop_queue(dev);
  1213. this->adhoc_times = 0;
  1214. wl3501_ack_interrupt(this);
  1215. wl3501_unblock_interrupt(this);
  1216. wl3501_mgmt_scan(this, 100);
  1217. dprintk(1, "%s: device reset", dev->name);
  1218. rc = 0;
  1219. out:
  1220. return rc;
  1221. }
  1222. static void wl3501_tx_timeout(struct net_device *dev)
  1223. {
  1224. struct wl3501_card *this = dev->priv;
  1225. struct net_device_stats *stats = &this->stats;
  1226. unsigned long flags;
  1227. int rc;
  1228. stats->tx_errors++;
  1229. spin_lock_irqsave(&this->lock, flags);
  1230. rc = wl3501_reset(dev);
  1231. spin_unlock_irqrestore(&this->lock, flags);
  1232. if (rc)
  1233. printk(KERN_ERR "%s: Error %d resetting card on Tx timeout!\n",
  1234. dev->name, rc);
  1235. else {
  1236. dev->trans_start = jiffies;
  1237. netif_wake_queue(dev);
  1238. }
  1239. }
  1240. /*
  1241. * Return : 0 - OK
  1242. * 1 - Could not transmit (dev_queue_xmit will queue it)
  1243. * and try to sent it later
  1244. */
  1245. static int wl3501_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
  1246. {
  1247. int enabled, rc;
  1248. struct wl3501_card *this = dev->priv;
  1249. unsigned long flags;
  1250. spin_lock_irqsave(&this->lock, flags);
  1251. enabled = wl3501_block_interrupt(this);
  1252. dev->trans_start = jiffies;
  1253. rc = wl3501_send_pkt(this, skb->data, skb->len);
  1254. if (enabled)
  1255. wl3501_unblock_interrupt(this);
  1256. if (rc) {
  1257. ++this->stats.tx_dropped;
  1258. netif_stop_queue(dev);
  1259. } else {
  1260. ++this->stats.tx_packets;
  1261. this->stats.tx_bytes += skb->len;
  1262. kfree_skb(skb);
  1263. if (this->tx_buffer_cnt < 2)
  1264. netif_stop_queue(dev);
  1265. }
  1266. spin_unlock_irqrestore(&this->lock, flags);
  1267. return rc;
  1268. }
  1269. static int wl3501_open(struct net_device *dev)
  1270. {
  1271. int rc = -ENODEV;
  1272. struct wl3501_card *this = dev->priv;
  1273. unsigned long flags;
  1274. dev_link_t *link;
  1275. spin_lock_irqsave(&this->lock, flags);
  1276. /* Check if the device is in wl3501_dev_list */
  1277. for (link = wl3501_dev_list; link; link = link->next)
  1278. if (link->priv == dev)
  1279. break;
  1280. if (!DEV_OK(link))
  1281. goto out;
  1282. netif_device_attach(dev);
  1283. link->open++;
  1284. /* Initial WL3501 firmware */
  1285. dprintk(1, "%s: Initialize WL3501 firmware...", dev->name);
  1286. if (wl3501_init_firmware(this))
  1287. goto fail;
  1288. /* Initial device variables */
  1289. this->adhoc_times = 0;
  1290. /* Acknowledge Interrupt, for cleaning last state */
  1291. wl3501_ack_interrupt(this);
  1292. /* Enable interrupt from card after all */
  1293. wl3501_unblock_interrupt(this);
  1294. wl3501_mgmt_scan(this, 100);
  1295. rc = 0;
  1296. dprintk(1, "%s: WL3501 opened", dev->name);
  1297. printk(KERN_INFO "%s: Card Name: %s\n"
  1298. "%s: Firmware Date: %s\n",
  1299. dev->name, this->card_name,
  1300. dev->name, this->firmware_date);
  1301. out:
  1302. spin_unlock_irqrestore(&this->lock, flags);
  1303. return rc;
  1304. fail:
  1305. printk(KERN_WARNING "%s: Can't initialize firmware!\n", dev->name);
  1306. goto out;
  1307. }
  1308. static struct net_device_stats *wl3501_get_stats(struct net_device *dev)
  1309. {
  1310. struct wl3501_card *this = dev->priv;
  1311. return &this->stats;
  1312. }
  1313. static struct iw_statistics *wl3501_get_wireless_stats(struct net_device *dev)
  1314. {
  1315. struct wl3501_card *this = dev->priv;
  1316. struct iw_statistics *wstats = &this->wstats;
  1317. u32 value; /* size checked: it is u32 */
  1318. memset(wstats, 0, sizeof(*wstats));
  1319. wstats->status = netif_running(dev);
  1320. if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_WEP_ICV_ERROR_COUNT,
  1321. &value, sizeof(value)))
  1322. wstats->discard.code += value;
  1323. if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_WEP_UNDECRYPTABLE_COUNT,
  1324. &value, sizeof(value)))
  1325. wstats->discard.code += value;
  1326. if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_WEP_EXCLUDED_COUNT,
  1327. &value, sizeof(value)))
  1328. wstats->discard.code += value;
  1329. if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_RETRY_COUNT,
  1330. &value, sizeof(value)))
  1331. wstats->discard.retries = value;
  1332. if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_FAILED_COUNT,
  1333. &value, sizeof(value)))
  1334. wstats->discard.misc += value;
  1335. if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_RTS_FAILURE_COUNT,
  1336. &value, sizeof(value)))
  1337. wstats->discard.misc += value;
  1338. if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_ACK_FAILURE_COUNT,
  1339. &value, sizeof(value)))
  1340. wstats->discard.misc += value;
  1341. if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_FRAME_DUPLICATE_COUNT,
  1342. &value, sizeof(value)))
  1343. wstats->discard.misc += value;
  1344. return wstats;
  1345. }
  1346. static void wl3501_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
  1347. {
  1348. strlcpy(info->driver, wl3501_dev_info, sizeof(info->driver));
  1349. }
  1350. static struct ethtool_ops ops = {
  1351. .get_drvinfo = wl3501_get_drvinfo
  1352. };
  1353. /**
  1354. * wl3501_detach - deletes a driver "instance"
  1355. * @link - FILL_IN
  1356. *
  1357. * This deletes a driver "instance". The device is de-registered with Card
  1358. * Services. If it has been released, all local data structures are freed.
  1359. * Otherwise, the structures will be freed when the device is released.
  1360. */
  1361. static void wl3501_detach(struct pcmcia_device *p_dev)
  1362. {
  1363. dev_link_t *link = dev_to_instance(p_dev);
  1364. dev_link_t **linkp;
  1365. struct net_device *dev = link->priv;
  1366. /* Locate device structure */
  1367. for (linkp = &wl3501_dev_list; *linkp; linkp = &(*linkp)->next)
  1368. if (*linkp == link)
  1369. break;
  1370. if (!*linkp)
  1371. goto out;
  1372. /* If the device is currently configured and active, we won't actually
  1373. * delete it yet. Instead, it is marked so that when the release()
  1374. * function is called, that will trigger a proper detach(). */
  1375. if (link->state & DEV_CONFIG) {
  1376. while (link->open > 0)
  1377. wl3501_close(dev);
  1378. netif_device_detach(dev);
  1379. wl3501_release(link);
  1380. }
  1381. /* Unlink device structure, free pieces */
  1382. *linkp = link->next;
  1383. if (link->priv)
  1384. free_netdev(link->priv);
  1385. kfree(link);
  1386. out:
  1387. return;
  1388. }
  1389. static int wl3501_get_name(struct net_device *dev, struct iw_request_info *info,
  1390. union iwreq_data *wrqu, char *extra)
  1391. {
  1392. strlcpy(wrqu->name, "IEEE 802.11-DS", sizeof(wrqu->name));
  1393. return 0;
  1394. }
  1395. static int wl3501_set_freq(struct net_device *dev, struct iw_request_info *info,
  1396. union iwreq_data *wrqu, char *extra)
  1397. {
  1398. struct wl3501_card *this = dev->priv;
  1399. int channel = wrqu->freq.m;
  1400. int rc = -EINVAL;
  1401. if (iw_valid_channel(this->reg_domain, channel)) {
  1402. this->chan = channel;
  1403. rc = wl3501_reset(dev);
  1404. }
  1405. return rc;
  1406. }
  1407. static int wl3501_get_freq(struct net_device *dev, struct iw_request_info *info,
  1408. union iwreq_data *wrqu, char *extra)
  1409. {
  1410. struct wl3501_card *this = dev->priv;
  1411. wrqu->freq.m = wl3501_chan2freq[this->chan - 1] * 100000;
  1412. wrqu->freq.e = 1;
  1413. return 0;
  1414. }
  1415. static int wl3501_set_mode(struct net_device *dev, struct iw_request_info *info,
  1416. union iwreq_data *wrqu, char *extra)
  1417. {
  1418. int rc = -EINVAL;
  1419. if (wrqu->mode == IW_MODE_INFRA ||
  1420. wrqu->mode == IW_MODE_ADHOC ||
  1421. wrqu->mode == IW_MODE_AUTO) {
  1422. struct wl3501_card *this = dev->priv;
  1423. this->net_type = wrqu->mode;
  1424. rc = wl3501_reset(dev);
  1425. }
  1426. return rc;
  1427. }
  1428. static int wl3501_get_mode(struct net_device *dev, struct iw_request_info *info,
  1429. union iwreq_data *wrqu, char *extra)
  1430. {
  1431. struct wl3501_card *this = dev->priv;
  1432. wrqu->mode = this->net_type;
  1433. return 0;
  1434. }
  1435. static int wl3501_get_sens(struct net_device *dev, struct iw_request_info *info,
  1436. union iwreq_data *wrqu, char *extra)
  1437. {
  1438. struct wl3501_card *this = dev->priv;
  1439. wrqu->sens.value = this->rssi;
  1440. wrqu->sens.disabled = !wrqu->sens.value;
  1441. wrqu->sens.fixed = 1;
  1442. return 0;
  1443. }
  1444. static int wl3501_get_range(struct net_device *dev,
  1445. struct iw_request_info *info,
  1446. union iwreq_data *wrqu, char *extra)
  1447. {
  1448. struct iw_range *range = (struct iw_range *)extra;
  1449. /* Set the length (very important for backward compatibility) */
  1450. wrqu->data.length = sizeof(*range);
  1451. /* Set all the info we don't care or don't know about to zero */
  1452. memset(range, 0, sizeof(*range));
  1453. /* Set the Wireless Extension versions */
  1454. range->we_version_compiled = WIRELESS_EXT;
  1455. range->we_version_source = 1;
  1456. range->throughput = 2 * 1000 * 1000; /* ~2 Mb/s */
  1457. /* FIXME: study the code to fill in more fields... */
  1458. return 0;
  1459. }
  1460. static int wl3501_set_wap(struct net_device *dev, struct iw_request_info *info,
  1461. union iwreq_data *wrqu, char *extra)
  1462. {
  1463. struct wl3501_card *this = dev->priv;
  1464. static const u8 bcast[ETH_ALEN] = { 255, 255, 255, 255, 255, 255 };
  1465. int rc = -EINVAL;
  1466. /* FIXME: we support other ARPHRDs...*/
  1467. if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
  1468. goto out;
  1469. if (!memcmp(bcast, wrqu->ap_addr.sa_data, ETH_ALEN)) {
  1470. /* FIXME: rescan? */
  1471. } else
  1472. memcpy(this->bssid, wrqu->ap_addr.sa_data, ETH_ALEN);
  1473. /* FIXME: rescan? deassoc & scan? */
  1474. rc = 0;
  1475. out:
  1476. return rc;
  1477. }
  1478. static int wl3501_get_wap(struct net_device *dev, struct iw_request_info *info,
  1479. union iwreq_data *wrqu, char *extra)
  1480. {
  1481. struct wl3501_card *this = dev->priv;
  1482. wrqu->ap_addr.sa_family = ARPHRD_ETHER;
  1483. memcpy(wrqu->ap_addr.sa_data, this->bssid, ETH_ALEN);
  1484. return 0;
  1485. }
  1486. static int wl3501_set_scan(struct net_device *dev, struct iw_request_info *info,
  1487. union iwreq_data *wrqu, char *extra)
  1488. {
  1489. /*
  1490. * FIXME: trigger scanning with a reset, yes, I'm lazy
  1491. */
  1492. return wl3501_reset(dev);
  1493. }
  1494. static int wl3501_get_scan(struct net_device *dev, struct iw_request_info *info,
  1495. union iwreq_data *wrqu, char *extra)
  1496. {
  1497. struct wl3501_card *this = dev->priv;
  1498. int i;
  1499. char *current_ev = extra;
  1500. struct iw_event iwe;
  1501. for (i = 0; i < this->bss_cnt; ++i) {
  1502. iwe.cmd = SIOCGIWAP;
  1503. iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
  1504. memcpy(iwe.u.ap_addr.sa_data, this->bss_set[i].bssid, ETH_ALEN);
  1505. current_ev = iwe_stream_add_event(current_ev,
  1506. extra + IW_SCAN_MAX_DATA,
  1507. &iwe, IW_EV_ADDR_LEN);
  1508. iwe.cmd = SIOCGIWESSID;
  1509. iwe.u.data.flags = 1;
  1510. iwe.u.data.length = this->bss_set[i].ssid.el.len;
  1511. current_ev = iwe_stream_add_point(current_ev,
  1512. extra + IW_SCAN_MAX_DATA,
  1513. &iwe,
  1514. this->bss_set[i].ssid.essid);
  1515. iwe.cmd = SIOCGIWMODE;
  1516. iwe.u.mode = this->bss_set[i].bss_type;
  1517. current_ev = iwe_stream_add_event(current_ev,
  1518. extra + IW_SCAN_MAX_DATA,
  1519. &iwe, IW_EV_UINT_LEN);
  1520. iwe.cmd = SIOCGIWFREQ;
  1521. iwe.u.freq.m = this->bss_set[i].ds_pset.chan;
  1522. iwe.u.freq.e = 0;
  1523. current_ev = iwe_stream_add_event(current_ev,
  1524. extra + IW_SCAN_MAX_DATA,
  1525. &iwe, IW_EV_FREQ_LEN);
  1526. iwe.cmd = SIOCGIWENCODE;
  1527. if (this->bss_set[i].cap_info & WL3501_MGMT_CAPABILITY_PRIVACY)
  1528. iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
  1529. else
  1530. iwe.u.data.flags = IW_ENCODE_DISABLED;
  1531. iwe.u.data.length = 0;
  1532. current_ev = iwe_stream_add_point(current_ev,
  1533. extra + IW_SCAN_MAX_DATA,
  1534. &iwe, NULL);
  1535. }
  1536. /* Length of data */
  1537. wrqu->data.length = (current_ev - extra);
  1538. wrqu->data.flags = 0; /* FIXME: set properly these flags */
  1539. return 0;
  1540. }
  1541. static int wl3501_set_essid(struct net_device *dev,
  1542. struct iw_request_info *info,
  1543. union iwreq_data *wrqu, char *extra)
  1544. {
  1545. struct wl3501_card *this = dev->priv;
  1546. if (wrqu->data.flags) {
  1547. iw_set_mgmt_info_element(IW_MGMT_INFO_ELEMENT_SSID,
  1548. &this->essid.el,
  1549. extra, wrqu->data.length);
  1550. } else { /* We accept any ESSID */
  1551. iw_set_mgmt_info_element(IW_MGMT_INFO_ELEMENT_SSID,
  1552. &this->essid.el, "ANY", 3);
  1553. }
  1554. return wl3501_reset(dev);
  1555. }
  1556. static int wl3501_get_essid(struct net_device *dev,
  1557. struct iw_request_info *info,
  1558. union iwreq_data *wrqu, char *extra)
  1559. {
  1560. struct wl3501_card *this = dev->priv;
  1561. unsigned long flags;
  1562. spin_lock_irqsave(&this->lock, flags);
  1563. wrqu->essid.flags = 1;
  1564. wrqu->essid.length = this->essid.el.len;
  1565. memcpy(extra, this->essid.essid, this->essid.el.len);
  1566. spin_unlock_irqrestore(&this->lock, flags);
  1567. return 0;
  1568. }
  1569. static int wl3501_set_nick(struct net_device *dev, struct iw_request_info *info,
  1570. union iwreq_data *wrqu, char *extra)
  1571. {
  1572. struct wl3501_card *this = dev->priv;
  1573. if (wrqu->data.length > sizeof(this->nick))
  1574. return -E2BIG;
  1575. strlcpy(this->nick, extra, wrqu->data.length);
  1576. return 0;
  1577. }
  1578. static int wl3501_get_nick(struct net_device *dev, struct iw_request_info *info,
  1579. union iwreq_data *wrqu, char *extra)
  1580. {
  1581. struct wl3501_card *this = dev->priv;
  1582. strlcpy(extra, this->nick, 32);
  1583. wrqu->data.length = strlen(extra);
  1584. return 0;
  1585. }
  1586. static int wl3501_get_rate(struct net_device *dev, struct iw_request_info *info,
  1587. union iwreq_data *wrqu, char *extra)
  1588. {
  1589. /*
  1590. * FIXME: have to see from where to get this info, perhaps this card
  1591. * works at 1 Mbit/s too... for now leave at 2 Mbit/s that is the most
  1592. * common with the Planet Access Points. -acme
  1593. */
  1594. wrqu->bitrate.value = 2000000;
  1595. wrqu->bitrate.fixed = 1;
  1596. return 0;
  1597. }
  1598. static int wl3501_get_rts_threshold(struct net_device *dev,
  1599. struct iw_request_info *info,
  1600. union iwreq_data *wrqu, char *extra)
  1601. {
  1602. u16 threshold; /* size checked: it is u16 */
  1603. struct wl3501_card *this = dev->priv;
  1604. int rc = wl3501_get_mib_value(this, WL3501_MIB_ATTR_RTS_THRESHOLD,
  1605. &threshold, sizeof(threshold));
  1606. if (!rc) {
  1607. wrqu->rts.value = threshold;
  1608. wrqu->rts.disabled = threshold >= 2347;
  1609. wrqu->rts.fixed = 1;
  1610. }
  1611. return rc;
  1612. }
  1613. static int wl3501_get_frag_threshold(struct net_device *dev,
  1614. struct iw_request_info *info,
  1615. union iwreq_data *wrqu, char *extra)
  1616. {
  1617. u16 threshold; /* size checked: it is u16 */
  1618. struct wl3501_card *this = dev->priv;
  1619. int rc = wl3501_get_mib_value(this, WL3501_MIB_ATTR_FRAG_THRESHOLD,
  1620. &threshold, sizeof(threshold));
  1621. if (!rc) {
  1622. wrqu->frag.value = threshold;
  1623. wrqu->frag.disabled = threshold >= 2346;
  1624. wrqu->frag.fixed = 1;
  1625. }
  1626. return rc;
  1627. }
  1628. static int wl3501_get_txpow(struct net_device *dev,
  1629. struct iw_request_info *info,
  1630. union iwreq_data *wrqu, char *extra)
  1631. {
  1632. u16 txpow;
  1633. struct wl3501_card *this = dev->priv;
  1634. int rc = wl3501_get_mib_value(this,
  1635. WL3501_MIB_ATTR_CURRENT_TX_PWR_LEVEL,
  1636. &txpow, sizeof(txpow));
  1637. if (!rc) {
  1638. wrqu->txpower.value = txpow;
  1639. wrqu->txpower.disabled = 0;
  1640. /*
  1641. * From the MIB values I think this can be configurable,
  1642. * as it lists several tx power levels -acme
  1643. */
  1644. wrqu->txpower.fixed = 0;
  1645. wrqu->txpower.flags = IW_TXPOW_MWATT;
  1646. }
  1647. return rc;
  1648. }
  1649. static int wl3501_get_retry(struct net_device *dev,
  1650. struct iw_request_info *info,
  1651. union iwreq_data *wrqu, char *extra)
  1652. {
  1653. u8 retry; /* size checked: it is u8 */
  1654. struct wl3501_card *this = dev->priv;
  1655. int rc = wl3501_get_mib_value(this,
  1656. WL3501_MIB_ATTR_LONG_RETRY_LIMIT,
  1657. &retry, sizeof(retry));
  1658. if (rc)
  1659. goto out;
  1660. if (wrqu->retry.flags & IW_RETRY_MAX) {
  1661. wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
  1662. goto set_value;
  1663. }
  1664. rc = wl3501_get_mib_value(this, WL3501_MIB_ATTR_SHORT_RETRY_LIMIT,
  1665. &retry, sizeof(retry));
  1666. if (rc)
  1667. goto out;
  1668. wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MIN;
  1669. set_value:
  1670. wrqu->retry.value = retry;
  1671. wrqu->retry.disabled = 0;
  1672. out:
  1673. return rc;
  1674. }
  1675. static int wl3501_get_encode(struct net_device *dev,
  1676. struct iw_request_info *info,
  1677. union iwreq_data *wrqu, char *extra)
  1678. {
  1679. u8 implemented, restricted, keys[100], len_keys, tocopy;
  1680. struct wl3501_card *this = dev->priv;
  1681. int rc = wl3501_get_mib_value(this,
  1682. WL3501_MIB_ATTR_PRIV_OPT_IMPLEMENTED,
  1683. &implemented, sizeof(implemented));
  1684. if (rc)
  1685. goto out;
  1686. if (!implemented) {
  1687. wrqu->encoding.flags = IW_ENCODE_DISABLED;
  1688. goto out;
  1689. }
  1690. rc = wl3501_get_mib_value(this, WL3501_MIB_ATTR_EXCLUDE_UNENCRYPTED,
  1691. &restricted, sizeof(restricted));
  1692. if (rc)
  1693. goto out;
  1694. wrqu->encoding.flags = restricted ? IW_ENCODE_RESTRICTED :
  1695. IW_ENCODE_OPEN;
  1696. rc = wl3501_get_mib_value(this, WL3501_MIB_ATTR_WEP_KEY_MAPPINGS_LEN,
  1697. &len_keys, sizeof(len_keys));
  1698. if (rc)
  1699. goto out;
  1700. rc = wl3501_get_mib_value(this, WL3501_MIB_ATTR_WEP_KEY_MAPPINGS,
  1701. keys, len_keys);
  1702. if (rc)
  1703. goto out;
  1704. tocopy = min_t(u8, len_keys, wrqu->encoding.length);
  1705. tocopy = min_t(u8, tocopy, 100);
  1706. wrqu->encoding.length = tocopy;
  1707. memset(extra, 0, tocopy);
  1708. memcpy(extra, keys, tocopy);
  1709. out:
  1710. return rc;
  1711. }
  1712. static int wl3501_get_power(struct net_device *dev,
  1713. struct iw_request_info *info,
  1714. union iwreq_data *wrqu, char *extra)
  1715. {
  1716. u8 pwr_state;
  1717. struct wl3501_card *this = dev->priv;
  1718. int rc = wl3501_get_mib_value(this,
  1719. WL3501_MIB_ATTR_CURRENT_PWR_STATE,
  1720. &pwr_state, sizeof(pwr_state));
  1721. if (rc)
  1722. goto out;
  1723. wrqu->power.disabled = !pwr_state;
  1724. wrqu->power.flags = IW_POWER_ON;
  1725. out:
  1726. return rc;
  1727. }
  1728. static const iw_handler wl3501_handler[] = {
  1729. [SIOCGIWNAME - SIOCIWFIRST] = wl3501_get_name,
  1730. [SIOCSIWFREQ - SIOCIWFIRST] = wl3501_set_freq,
  1731. [SIOCGIWFREQ - SIOCIWFIRST] = wl3501_get_freq,
  1732. [SIOCSIWMODE - SIOCIWFIRST] = wl3501_set_mode,
  1733. [SIOCGIWMODE - SIOCIWFIRST] = wl3501_get_mode,
  1734. [SIOCGIWSENS - SIOCIWFIRST] = wl3501_get_sens,
  1735. [SIOCGIWRANGE - SIOCIWFIRST] = wl3501_get_range,
  1736. [SIOCSIWSPY - SIOCIWFIRST] = iw_handler_set_spy,
  1737. [SIOCGIWSPY - SIOCIWFIRST] = iw_handler_get_spy,
  1738. [SIOCSIWTHRSPY - SIOCIWFIRST] = iw_handler_set_thrspy,
  1739. [SIOCGIWTHRSPY - SIOCIWFIRST] = iw_handler_get_thrspy,
  1740. [SIOCSIWAP - SIOCIWFIRST] = wl3501_set_wap,
  1741. [SIOCGIWAP - SIOCIWFIRST] = wl3501_get_wap,
  1742. [SIOCSIWSCAN - SIOCIWFIRST] = wl3501_set_scan,
  1743. [SIOCGIWSCAN - SIOCIWFIRST] = wl3501_get_scan,
  1744. [SIOCSIWESSID - SIOCIWFIRST] = wl3501_set_essid,
  1745. [SIOCGIWESSID - SIOCIWFIRST] = wl3501_get_essid,
  1746. [SIOCSIWNICKN - SIOCIWFIRST] = wl3501_set_nick,
  1747. [SIOCGIWNICKN - SIOCIWFIRST] = wl3501_get_nick,
  1748. [SIOCGIWRATE - SIOCIWFIRST] = wl3501_get_rate,
  1749. [SIOCGIWRTS - SIOCIWFIRST] = wl3501_get_rts_threshold,
  1750. [SIOCGIWFRAG - SIOCIWFIRST] = wl3501_get_frag_threshold,
  1751. [SIOCGIWTXPOW - SIOCIWFIRST] = wl3501_get_txpow,
  1752. [SIOCGIWRETRY - SIOCIWFIRST] = wl3501_get_retry,
  1753. [SIOCGIWENCODE - SIOCIWFIRST] = wl3501_get_encode,
  1754. [SIOCGIWPOWER - SIOCIWFIRST] = wl3501_get_power,
  1755. };
  1756. static const struct iw_handler_def wl3501_handler_def = {
  1757. .num_standard = sizeof(wl3501_handler) / sizeof(iw_handler),
  1758. .standard = (iw_handler *)wl3501_handler,
  1759. .get_wireless_stats = wl3501_get_wireless_stats,
  1760. };
  1761. /**
  1762. * wl3501_attach - creates an "instance" of the driver
  1763. *
  1764. * Creates an "instance" of the driver, allocating local data structures for
  1765. * one device. The device is registered with Card Services.
  1766. *
  1767. * The dev_link structure is initialized, but we don't actually configure the
  1768. * card at this point -- we wait until we receive a card insertion event.
  1769. */
  1770. static int wl3501_attach(struct pcmcia_device *p_dev)
  1771. {
  1772. dev_link_t *link;
  1773. struct net_device *dev;
  1774. struct wl3501_card *this;
  1775. /* Initialize the dev_link_t structure */
  1776. link = kzalloc(sizeof(*link), GFP_KERNEL);
  1777. if (!link)
  1778. return -ENOMEM;
  1779. /* The io structure describes IO port mapping */
  1780. link->io.NumPorts1 = 16;
  1781. link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
  1782. link->io.IOAddrLines = 5;
  1783. /* Interrupt setup */
  1784. link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
  1785. link->irq.IRQInfo1 = IRQ_LEVEL_ID;
  1786. link->irq.Handler = wl3501_interrupt;
  1787. /* General socket configuration */
  1788. link->conf.Attributes = CONF_ENABLE_IRQ;
  1789. link->conf.Vcc = 50;
  1790. link->conf.IntType = INT_MEMORY_AND_IO;
  1791. link->conf.ConfigIndex = 1;
  1792. link->conf.Present = PRESENT_OPTION;
  1793. dev = alloc_etherdev(sizeof(struct wl3501_card));
  1794. if (!dev)
  1795. goto out_link;
  1796. dev->open = wl3501_open;
  1797. dev->stop = wl3501_close;
  1798. dev->hard_start_xmit = wl3501_hard_start_xmit;
  1799. dev->tx_timeout = wl3501_tx_timeout;
  1800. dev->watchdog_timeo = 5 * HZ;
  1801. dev->get_stats = wl3501_get_stats;
  1802. this = dev->priv;
  1803. this->wireless_data.spy_data = &this->spy_data;
  1804. dev->wireless_data = &this->wireless_data;
  1805. dev->wireless_handlers = (struct iw_handler_def *)&wl3501_handler_def;
  1806. SET_ETHTOOL_OPS(dev, &ops);
  1807. netif_stop_queue(dev);
  1808. link->priv = link->irq.Instance = dev;
  1809. link->handle = p_dev;
  1810. p_dev->instance = link;
  1811. link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
  1812. wl3501_config(link);
  1813. return 0;
  1814. out_link:
  1815. kfree(link);
  1816. link = NULL;
  1817. return -ENOMEM;
  1818. }
  1819. #define CS_CHECK(fn, ret) \
  1820. do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
  1821. /**
  1822. * wl3501_config - configure the PCMCIA socket and make eth device available
  1823. * @link - FILL_IN
  1824. *
  1825. * wl3501_config() is scheduled to run after a CARD_INSERTION event is
  1826. * received, to configure the PCMCIA socket, and to make the ethernet device
  1827. * available to the system.
  1828. */
  1829. static void wl3501_config(dev_link_t *link)
  1830. {
  1831. tuple_t tuple;
  1832. cisparse_t parse;
  1833. client_handle_t handle = link->handle;
  1834. struct net_device *dev = link->priv;
  1835. int i = 0, j, last_fn, last_ret;
  1836. unsigned char bf[64];
  1837. struct wl3501_card *this;
  1838. /* This reads the card's CONFIG tuple to find its config registers. */
  1839. tuple.Attributes = 0;
  1840. tuple.DesiredTuple = CISTPL_CONFIG;
  1841. CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple));
  1842. tuple.TupleData = bf;
  1843. tuple.TupleDataMax = sizeof(bf);
  1844. tuple.TupleOffset = 0;
  1845. CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple));
  1846. CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse));
  1847. link->conf.ConfigBase = parse.config.base;
  1848. link->conf.Present = parse.config.rmask[0];
  1849. /* Configure card */
  1850. link->state |= DEV_CONFIG;
  1851. /* Try allocating IO ports. This tries a few fixed addresses. If you
  1852. * want, you can also read the card's config table to pick addresses --
  1853. * see the serial driver for an example. */
  1854. for (j = 0x280; j < 0x400; j += 0x20) {
  1855. /* The '^0x300' is so that we probe 0x300-0x3ff first, then
  1856. * 0x200-0x2ff, and so on, because this seems safer */
  1857. link->io.BasePort1 = j;
  1858. link->io.BasePort2 = link->io.BasePort1 + 0x10;
  1859. i = pcmcia_request_io(link->handle, &link->io);
  1860. if (i == CS_SUCCESS)
  1861. break;
  1862. }
  1863. if (i != CS_SUCCESS) {
  1864. cs_error(link->handle, RequestIO, i);
  1865. goto failed;
  1866. }
  1867. /* Now allocate an interrupt line. Note that this does not actually
  1868. * assign a handler to the interrupt. */
  1869. CS_CHECK(RequestIRQ, pcmcia_request_irq(link->handle, &link->irq));
  1870. /* This actually configures the PCMCIA socket -- setting up the I/O
  1871. * windows and the interrupt mapping. */
  1872. CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link->handle, &link->conf));
  1873. dev->irq = link->irq.AssignedIRQ;
  1874. dev->base_addr = link->io.BasePort1;
  1875. SET_NETDEV_DEV(dev, &handle_to_dev(handle));
  1876. if (register_netdev(dev)) {
  1877. printk(KERN_NOTICE "wl3501_cs: register_netdev() failed\n");
  1878. goto failed;
  1879. }
  1880. SET_MODULE_OWNER(dev);
  1881. this = dev->priv;
  1882. /*
  1883. * At this point, the dev_node_t structure(s) should be initialized and
  1884. * arranged in a linked list at link->dev.
  1885. */
  1886. link->dev = &this->node;
  1887. link->state &= ~DEV_CONFIG_PENDING;
  1888. this->base_addr = dev->base_addr;
  1889. if (!wl3501_get_flash_mac_addr(this)) {
  1890. printk(KERN_WARNING "%s: Cant read MAC addr in flash ROM?\n",
  1891. dev->name);
  1892. goto failed;
  1893. }
  1894. strcpy(this->node.dev_name, dev->name);
  1895. /* print probe information */
  1896. printk(KERN_INFO "%s: wl3501 @ 0x%3.3x, IRQ %d, MAC addr in flash ROM:",
  1897. dev->name, this->base_addr, (int)dev->irq);
  1898. for (i = 0; i < 6; i++) {
  1899. dev->dev_addr[i] = ((char *)&this->mac_addr)[i];
  1900. printk("%c%02x", i ? ':' : ' ', dev->dev_addr[i]);
  1901. }
  1902. printk("\n");
  1903. /*
  1904. * Initialize card parameters - added by jss
  1905. */
  1906. this->net_type = IW_MODE_INFRA;
  1907. this->bss_cnt = 0;
  1908. this->join_sta_bss = 0;
  1909. this->adhoc_times = 0;
  1910. iw_set_mgmt_info_element(IW_MGMT_INFO_ELEMENT_SSID, &this->essid.el,
  1911. "ANY", 3);
  1912. this->card_name[0] = '\0';
  1913. this->firmware_date[0] = '\0';
  1914. this->rssi = 255;
  1915. this->chan = iw_default_channel(this->reg_domain);
  1916. strlcpy(this->nick, "Planet WL3501", sizeof(this->nick));
  1917. spin_lock_init(&this->lock);
  1918. init_waitqueue_head(&this->wait);
  1919. netif_start_queue(dev);
  1920. goto out;
  1921. cs_failed:
  1922. cs_error(link->handle, last_fn, last_ret);
  1923. failed:
  1924. wl3501_release(link);
  1925. out:
  1926. return;
  1927. }
  1928. /**
  1929. * wl3501_release - unregister the net, release PCMCIA configuration
  1930. * @arg - link
  1931. *
  1932. * After a card is removed, wl3501_release() will unregister the net device,
  1933. * and release the PCMCIA configuration. If the device is still open, this
  1934. * will be postponed until it is closed.
  1935. */
  1936. static void wl3501_release(dev_link_t *link)
  1937. {
  1938. struct net_device *dev = link->priv;
  1939. /* Unlink the device chain */
  1940. if (link->dev) {
  1941. unregister_netdev(dev);
  1942. link->dev = NULL;
  1943. }
  1944. /* Don't bother checking to see if these succeed or not */
  1945. pcmcia_release_configuration(link->handle);
  1946. pcmcia_release_io(link->handle, &link->io);
  1947. pcmcia_release_irq(link->handle, &link->irq);
  1948. link->state &= ~DEV_CONFIG;
  1949. }
  1950. static int wl3501_suspend(struct pcmcia_device *p_dev)
  1951. {
  1952. dev_link_t *link = dev_to_instance(p_dev);
  1953. struct net_device *dev = link->priv;
  1954. link->state |= DEV_SUSPEND;
  1955. wl3501_pwr_mgmt(dev->priv, WL3501_SUSPEND);
  1956. if (link->state & DEV_CONFIG) {
  1957. if (link->open)
  1958. netif_device_detach(dev);
  1959. pcmcia_release_configuration(link->handle);
  1960. }
  1961. return 0;
  1962. }
  1963. static int wl3501_resume(struct pcmcia_device *p_dev)
  1964. {
  1965. dev_link_t *link = dev_to_instance(p_dev);
  1966. struct net_device *dev = link->priv;
  1967. wl3501_pwr_mgmt(dev->priv, WL3501_RESUME);
  1968. if (link->state & DEV_CONFIG) {
  1969. pcmcia_request_configuration(link->handle, &link->conf);
  1970. if (link->open) {
  1971. wl3501_reset(dev);
  1972. netif_device_attach(dev);
  1973. }
  1974. }
  1975. return 0;
  1976. }
  1977. static struct pcmcia_device_id wl3501_ids[] = {
  1978. PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0001),
  1979. PCMCIA_DEVICE_NULL
  1980. };
  1981. MODULE_DEVICE_TABLE(pcmcia, wl3501_ids);
  1982. static struct pcmcia_driver wl3501_driver = {
  1983. .owner = THIS_MODULE,
  1984. .drv = {
  1985. .name = "wl3501_cs",
  1986. },
  1987. .probe = wl3501_attach,
  1988. .remove = wl3501_detach,
  1989. .id_table = wl3501_ids,
  1990. .suspend = wl3501_suspend,
  1991. .resume = wl3501_resume,
  1992. };
  1993. static int __init wl3501_init_module(void)
  1994. {
  1995. return pcmcia_register_driver(&wl3501_driver);
  1996. }
  1997. static void __exit wl3501_exit_module(void)
  1998. {
  1999. dprintk(0, ": unloading");
  2000. pcmcia_unregister_driver(&wl3501_driver);
  2001. BUG_ON(wl3501_dev_list != NULL);
  2002. }
  2003. module_init(wl3501_init_module);
  2004. module_exit(wl3501_exit_module);
  2005. MODULE_AUTHOR("Fox Chen <mhchen@golf.ccl.itri.org.tw>, "
  2006. "Arnaldo Carvalho de Melo <acme@conectiva.com.br>,"
  2007. "Gustavo Niemeyer <niemeyer@conectiva.com>");
  2008. MODULE_DESCRIPTION("Planet wl3501 wireless driver");
  2009. MODULE_LICENSE("GPL");