wl3501_cs.c 62 KB

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