wl3501_cs.c 62 KB

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