wl3501_cs.c 54 KB

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