wl3501_cs.c 62 KB

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