wl1271_main.c 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057
  1. /*
  2. * This file is part of wl1271
  3. *
  4. * Copyright (C) 2008-2009 Nokia Corporation
  5. *
  6. * Contact: Luciano Coelho <luciano.coelho@nokia.com>
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * version 2 as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA
  21. *
  22. */
  23. #include <linux/module.h>
  24. #include <linux/platform_device.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/firmware.h>
  27. #include <linux/delay.h>
  28. #include <linux/irq.h>
  29. #include <linux/spi/spi.h>
  30. #include <linux/crc32.h>
  31. #include <linux/etherdevice.h>
  32. #include <linux/vmalloc.h>
  33. #include <linux/spi/wl12xx.h>
  34. #include <linux/inetdevice.h>
  35. #include "wl1271.h"
  36. #include "wl12xx_80211.h"
  37. #include "wl1271_reg.h"
  38. #include "wl1271_spi.h"
  39. #include "wl1271_event.h"
  40. #include "wl1271_tx.h"
  41. #include "wl1271_rx.h"
  42. #include "wl1271_ps.h"
  43. #include "wl1271_init.h"
  44. #include "wl1271_debugfs.h"
  45. #include "wl1271_cmd.h"
  46. #include "wl1271_boot.h"
  47. static struct conf_drv_settings default_conf = {
  48. .sg = {
  49. .per_threshold = 7500,
  50. .max_scan_compensation_time = 120000,
  51. .nfs_sample_interval = 400,
  52. .load_ratio = 50,
  53. .auto_ps_mode = 0,
  54. .probe_req_compensation = 170,
  55. .scan_window_compensation = 50,
  56. .antenna_config = 0,
  57. .beacon_miss_threshold = 60,
  58. .rate_adaptation_threshold = CONF_HW_BIT_RATE_12MBPS,
  59. .rate_adaptation_snr = 0
  60. },
  61. .rx = {
  62. .rx_msdu_life_time = 512000,
  63. .packet_detection_threshold = 0,
  64. .ps_poll_timeout = 15,
  65. .upsd_timeout = 15,
  66. .rts_threshold = 2347,
  67. .rx_cca_threshold = 0,
  68. .irq_blk_threshold = 0xFFFF,
  69. .irq_pkt_threshold = 0,
  70. .irq_timeout = 600,
  71. .queue_type = CONF_RX_QUEUE_TYPE_LOW_PRIORITY,
  72. },
  73. .tx = {
  74. .tx_energy_detection = 0,
  75. .rc_conf = {
  76. .enabled_rates = CONF_TX_RATE_MASK_UNSPECIFIED,
  77. .short_retry_limit = 10,
  78. .long_retry_limit = 10,
  79. .aflags = 0
  80. },
  81. .ac_conf_count = 4,
  82. .ac_conf = {
  83. [0] = {
  84. .ac = CONF_TX_AC_BE,
  85. .cw_min = 15,
  86. .cw_max = 63,
  87. .aifsn = 3,
  88. .tx_op_limit = 0,
  89. },
  90. [1] = {
  91. .ac = CONF_TX_AC_BK,
  92. .cw_min = 15,
  93. .cw_max = 63,
  94. .aifsn = 7,
  95. .tx_op_limit = 0,
  96. },
  97. [2] = {
  98. .ac = CONF_TX_AC_VI,
  99. .cw_min = 15,
  100. .cw_max = 63,
  101. .aifsn = CONF_TX_AIFS_PIFS,
  102. .tx_op_limit = 3008,
  103. },
  104. [3] = {
  105. .ac = CONF_TX_AC_VO,
  106. .cw_min = 15,
  107. .cw_max = 63,
  108. .aifsn = CONF_TX_AIFS_PIFS,
  109. .tx_op_limit = 1504,
  110. },
  111. },
  112. .tid_conf_count = 7,
  113. .tid_conf = {
  114. [0] = {
  115. .queue_id = 0,
  116. .channel_type = CONF_CHANNEL_TYPE_DCF,
  117. .tsid = CONF_TX_AC_BE,
  118. .ps_scheme = CONF_PS_SCHEME_LEGACY,
  119. .ack_policy = CONF_ACK_POLICY_LEGACY,
  120. .apsd_conf = {0, 0},
  121. },
  122. [1] = {
  123. .queue_id = 1,
  124. .channel_type = CONF_CHANNEL_TYPE_DCF,
  125. .tsid = CONF_TX_AC_BE,
  126. .ps_scheme = CONF_PS_SCHEME_LEGACY,
  127. .ack_policy = CONF_ACK_POLICY_LEGACY,
  128. .apsd_conf = {0, 0},
  129. },
  130. [2] = {
  131. .queue_id = 2,
  132. .channel_type = CONF_CHANNEL_TYPE_DCF,
  133. .tsid = CONF_TX_AC_BE,
  134. .ps_scheme = CONF_PS_SCHEME_LEGACY,
  135. .ack_policy = CONF_ACK_POLICY_LEGACY,
  136. .apsd_conf = {0, 0},
  137. },
  138. [3] = {
  139. .queue_id = 3,
  140. .channel_type = CONF_CHANNEL_TYPE_DCF,
  141. .tsid = CONF_TX_AC_BE,
  142. .ps_scheme = CONF_PS_SCHEME_LEGACY,
  143. .ack_policy = CONF_ACK_POLICY_LEGACY,
  144. .apsd_conf = {0, 0},
  145. },
  146. [4] = {
  147. .queue_id = 4,
  148. .channel_type = CONF_CHANNEL_TYPE_DCF,
  149. .tsid = CONF_TX_AC_BE,
  150. .ps_scheme = CONF_PS_SCHEME_LEGACY,
  151. .ack_policy = CONF_ACK_POLICY_LEGACY,
  152. .apsd_conf = {0, 0},
  153. },
  154. [5] = {
  155. .queue_id = 5,
  156. .channel_type = CONF_CHANNEL_TYPE_DCF,
  157. .tsid = CONF_TX_AC_BE,
  158. .ps_scheme = CONF_PS_SCHEME_LEGACY,
  159. .ack_policy = CONF_ACK_POLICY_LEGACY,
  160. .apsd_conf = {0, 0},
  161. },
  162. [6] = {
  163. .queue_id = 6,
  164. .channel_type = CONF_CHANNEL_TYPE_DCF,
  165. .tsid = CONF_TX_AC_BE,
  166. .ps_scheme = CONF_PS_SCHEME_LEGACY,
  167. .ack_policy = CONF_ACK_POLICY_LEGACY,
  168. .apsd_conf = {0, 0},
  169. }
  170. },
  171. .frag_threshold = IEEE80211_MAX_FRAG_THRESHOLD,
  172. .tx_compl_timeout = 700,
  173. .tx_compl_threshold = 4
  174. },
  175. .conn = {
  176. .wake_up_event = CONF_WAKE_UP_EVENT_DTIM,
  177. .listen_interval = 0,
  178. .bcn_filt_mode = CONF_BCN_FILT_MODE_ENABLED,
  179. .bcn_filt_ie_count = 1,
  180. .bcn_filt_ie = {
  181. [0] = {
  182. .ie = WLAN_EID_CHANNEL_SWITCH,
  183. .rule = CONF_BCN_RULE_PASS_ON_APPEARANCE,
  184. }
  185. },
  186. .synch_fail_thold = 10,
  187. .bss_lose_timeout = 100,
  188. .beacon_rx_timeout = 10000,
  189. .broadcast_timeout = 20000,
  190. .rx_broadcast_in_ps = 1,
  191. .ps_poll_threshold = 20,
  192. .sig_trigger_count = 2,
  193. .sig_trigger = {
  194. [0] = {
  195. .threshold = -75,
  196. .pacing = 500,
  197. .metric = CONF_TRIG_METRIC_RSSI_BEACON,
  198. .type = CONF_TRIG_EVENT_TYPE_EDGE,
  199. .direction = CONF_TRIG_EVENT_DIR_LOW,
  200. .hysteresis = 2,
  201. .index = 0,
  202. .enable = 1
  203. },
  204. [1] = {
  205. .threshold = -75,
  206. .pacing = 500,
  207. .metric = CONF_TRIG_METRIC_RSSI_BEACON,
  208. .type = CONF_TRIG_EVENT_TYPE_EDGE,
  209. .direction = CONF_TRIG_EVENT_DIR_HIGH,
  210. .hysteresis = 2,
  211. .index = 1,
  212. .enable = 1
  213. }
  214. },
  215. .sig_weights = {
  216. .rssi_bcn_avg_weight = 10,
  217. .rssi_pkt_avg_weight = 10,
  218. .snr_bcn_avg_weight = 10,
  219. .snr_pkt_avg_weight = 10
  220. },
  221. .bet_enable = CONF_BET_MODE_ENABLE,
  222. .bet_max_consecutive = 10,
  223. .psm_entry_retries = 3
  224. },
  225. .init = {
  226. .genparam = {
  227. .ref_clk = CONF_REF_CLK_38_4_E,
  228. .settling_time = 5,
  229. .clk_valid_on_wakeup = 0,
  230. .dc2dcmode = 0,
  231. .single_dual_band = CONF_SINGLE_BAND,
  232. .tx_bip_fem_autodetect = 1,
  233. .tx_bip_fem_manufacturer = 1,
  234. .settings = 1,
  235. .sr_state = 1,
  236. .srf1 = { 0x07, 0x03, 0x18, 0x10, 0x05, 0xfb, 0xf0,
  237. 0xe8, 0, 0, 0, 0, 0, 0, 0, 0 },
  238. .srf2 = { 0x07, 0x03, 0x18, 0x10, 0x05, 0xfb, 0xf0,
  239. 0xe8, 0, 0, 0, 0, 0, 0, 0, 0 },
  240. .srf3 = { 0x07, 0x03, 0x18, 0x10, 0x05, 0xfb, 0xf0,
  241. 0xe8, 0, 0, 0, 0, 0, 0, 0, 0 },
  242. .sr_debug_table = { 0, 0, 0, 0, 0, 0, 0, 0,
  243. 0, 0, 0, 0, 0, 0, 0, 0 },
  244. .sr_sen_n_p = 0,
  245. .sr_sen_n_p_gain = 0,
  246. .sr_sen_nrn = 0,
  247. .sr_sen_prn = 0,
  248. },
  249. .radioparam = {
  250. .rx_trace_loss = 0x24,
  251. .tx_trace_loss = 0x0,
  252. .rx_rssi_and_proc_compens = {
  253. 0xec, 0xf6, 0x00, 0x0c, 0x18, 0xf8,
  254. 0xfc, 0x00, 0x80, 0x10, 0xf0, 0xf8,
  255. 0x00, 0x0a, 0x14 },
  256. .rx_trace_loss_5 = { 0, 0, 0, 0, 0, 0, 0 },
  257. .tx_trace_loss_5 = { 0, 0, 0, 0, 0, 0, 0 },
  258. .rx_rssi_and_proc_compens_5 = {
  259. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  260. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  261. 0x00, 0x00, 0x00 },
  262. .tx_ref_pd_voltage = 0x1a9,
  263. .tx_ref_power = 0x80,
  264. .tx_offset_db = 0x0,
  265. .tx_rate_limits_normal = {
  266. 0x1d, 0x1f, 0x24, 0x28, 0x28, 0x29 },
  267. .tx_rate_limits_degraded = {
  268. 0x19, 0x1f, 0x22, 0x23, 0x27, 0x28 },
  269. .tx_rate_limits_extreme = {
  270. 0x19, 0x1c, 0x1e, 0x20, 0x24, 0x25 },
  271. .tx_channel_limits_11b = {
  272. 0x22, 0x50, 0x50, 0x50, 0x50, 0x50,
  273. 0x50, 0x50, 0x50, 0x50, 0x22, 0x50,
  274. 0x22, 0x50 },
  275. .tx_channel_limits_ofdm = {
  276. 0x20, 0x50, 0x50, 0x50, 0x50, 0x50,
  277. 0x50, 0x50, 0x50, 0x50, 0x20, 0x50,
  278. 0x20, 0x50 },
  279. .tx_pdv_rate_offsets = {
  280. 0x07, 0x08, 0x04, 0x02, 0x02, 0x00 },
  281. .tx_ibias = {
  282. 0x11, 0x11, 0x15, 0x11, 0x15, 0x0f },
  283. .rx_fem_insertion_loss = 0x0e,
  284. .degraded_low_to_normal_threshold = 0x1e,
  285. .degraded_normal_to_high_threshold = 0x2d,
  286. .tx_ref_pd_voltage_5 = {
  287. 0x0190, 0x01a4, 0x01c3, 0x01d8,
  288. 0x020a, 0x021c },
  289. .tx_ref_power_5 = {
  290. 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80 },
  291. .tx_offset_db_5 = {
  292. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
  293. .tx_rate_limits_normal_5 = {
  294. 0x1b, 0x1e, 0x21, 0x23, 0x27, 0x00 },
  295. .tx_rate_limits_degraded_5 = {
  296. 0x1b, 0x1e, 0x21, 0x23, 0x27, 0x00 },
  297. .tx_rate_limits_extreme_5 = {
  298. 0x1b, 0x1e, 0x21, 0x23, 0x27, 0x00 },
  299. .tx_channel_limits_ofdm_5 = {
  300. 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50,
  301. 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50,
  302. 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50,
  303. 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50,
  304. 0x50, 0x50, 0x50 },
  305. .tx_pdv_rate_offsets_5 = {
  306. 0x01, 0x02, 0x02, 0x02, 0x02, 0x00 },
  307. .tx_ibias_5 = {
  308. 0x10, 0x10, 0x10, 0x10, 0x10, 0x10 },
  309. .rx_fem_insertion_loss_5 = {
  310. 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10 },
  311. .degraded_low_to_normal_threshold_5 = 0x00,
  312. .degraded_normal_to_high_threshold_5 = 0x00
  313. }
  314. },
  315. .itrim = {
  316. .enable = false,
  317. .timeout = 50000,
  318. }
  319. };
  320. static LIST_HEAD(wl_list);
  321. static void wl1271_conf_init(struct wl1271 *wl)
  322. {
  323. /*
  324. * This function applies the default configuration to the driver. This
  325. * function is invoked upon driver load (spi probe.)
  326. *
  327. * The configuration is stored in a run-time structure in order to
  328. * facilitate for run-time adjustment of any of the parameters. Making
  329. * changes to the configuration structure will apply the new values on
  330. * the next interface up (wl1271_op_start.)
  331. */
  332. /* apply driver default configuration */
  333. memcpy(&wl->conf, &default_conf, sizeof(default_conf));
  334. if (wl1271_11a_enabled())
  335. wl->conf.init.genparam.single_dual_band = CONF_DUAL_BAND;
  336. }
  337. static int wl1271_plt_init(struct wl1271 *wl)
  338. {
  339. int ret;
  340. ret = wl1271_cmd_general_parms(wl);
  341. if (ret < 0)
  342. return ret;
  343. ret = wl1271_cmd_radio_parms(wl);
  344. if (ret < 0)
  345. return ret;
  346. ret = wl1271_acx_init_mem_config(wl);
  347. if (ret < 0)
  348. return ret;
  349. ret = wl1271_cmd_data_path(wl, 1);
  350. if (ret < 0)
  351. return ret;
  352. return 0;
  353. }
  354. static void wl1271_disable_interrupts(struct wl1271 *wl)
  355. {
  356. disable_irq(wl->irq);
  357. }
  358. static void wl1271_power_off(struct wl1271 *wl)
  359. {
  360. wl->set_power(false);
  361. wl->gpio_power = false;
  362. }
  363. static void wl1271_power_on(struct wl1271 *wl)
  364. {
  365. wl->set_power(true);
  366. wl->gpio_power = true;
  367. }
  368. static void wl1271_fw_status(struct wl1271 *wl,
  369. struct wl1271_fw_status *status)
  370. {
  371. u32 total = 0;
  372. int i;
  373. wl1271_spi_read(wl, FW_STATUS_ADDR, status,
  374. sizeof(*status), false);
  375. wl1271_debug(DEBUG_IRQ, "intr: 0x%x (fw_rx_counter = %d, "
  376. "drv_rx_counter = %d, tx_results_counter = %d)",
  377. status->intr,
  378. status->fw_rx_counter,
  379. status->drv_rx_counter,
  380. status->tx_results_counter);
  381. /* update number of available TX blocks */
  382. for (i = 0; i < NUM_TX_QUEUES; i++) {
  383. u32 cnt = le32_to_cpu(status->tx_released_blks[i]) -
  384. wl->tx_blocks_freed[i];
  385. wl->tx_blocks_freed[i] =
  386. le32_to_cpu(status->tx_released_blks[i]);
  387. wl->tx_blocks_available += cnt;
  388. total += cnt;
  389. }
  390. /* if more blocks are available now, schedule some tx work */
  391. if (total && !skb_queue_empty(&wl->tx_queue))
  392. ieee80211_queue_work(wl->hw, &wl->tx_work);
  393. /* update the host-chipset time offset */
  394. wl->time_offset = jiffies_to_usecs(jiffies) -
  395. le32_to_cpu(status->fw_localtime);
  396. }
  397. static void wl1271_irq_work(struct work_struct *work)
  398. {
  399. int ret;
  400. u32 intr;
  401. struct wl1271 *wl =
  402. container_of(work, struct wl1271, irq_work);
  403. mutex_lock(&wl->mutex);
  404. wl1271_debug(DEBUG_IRQ, "IRQ work");
  405. if (wl->state == WL1271_STATE_OFF)
  406. goto out;
  407. ret = wl1271_ps_elp_wakeup(wl, true);
  408. if (ret < 0)
  409. goto out;
  410. wl1271_spi_write32(wl, ACX_REG_INTERRUPT_MASK, WL1271_ACX_INTR_ALL);
  411. wl1271_fw_status(wl, wl->fw_status);
  412. intr = le32_to_cpu(wl->fw_status->intr);
  413. if (!intr) {
  414. wl1271_debug(DEBUG_IRQ, "Zero interrupt received.");
  415. goto out_sleep;
  416. }
  417. intr &= WL1271_INTR_MASK;
  418. if (intr & WL1271_ACX_INTR_EVENT_A) {
  419. bool do_ack = (intr & WL1271_ACX_INTR_EVENT_B) ? false : true;
  420. wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_EVENT_A");
  421. wl1271_event_handle(wl, 0, do_ack);
  422. }
  423. if (intr & WL1271_ACX_INTR_EVENT_B) {
  424. wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_EVENT_B");
  425. wl1271_event_handle(wl, 1, true);
  426. }
  427. if (intr & WL1271_ACX_INTR_INIT_COMPLETE)
  428. wl1271_debug(DEBUG_IRQ,
  429. "WL1271_ACX_INTR_INIT_COMPLETE");
  430. if (intr & WL1271_ACX_INTR_HW_AVAILABLE)
  431. wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_HW_AVAILABLE");
  432. if (intr & WL1271_ACX_INTR_DATA) {
  433. u8 tx_res_cnt = wl->fw_status->tx_results_counter -
  434. wl->tx_results_count;
  435. wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_DATA");
  436. /* check for tx results */
  437. if (tx_res_cnt)
  438. wl1271_tx_complete(wl, tx_res_cnt);
  439. wl1271_rx(wl, wl->fw_status);
  440. }
  441. out_sleep:
  442. wl1271_spi_write32(wl, ACX_REG_INTERRUPT_MASK,
  443. WL1271_ACX_INTR_ALL & ~(WL1271_INTR_MASK));
  444. wl1271_ps_elp_sleep(wl);
  445. out:
  446. mutex_unlock(&wl->mutex);
  447. }
  448. static irqreturn_t wl1271_irq(int irq, void *cookie)
  449. {
  450. struct wl1271 *wl;
  451. unsigned long flags;
  452. wl1271_debug(DEBUG_IRQ, "IRQ");
  453. wl = cookie;
  454. /* complete the ELP completion */
  455. spin_lock_irqsave(&wl->wl_lock, flags);
  456. if (wl->elp_compl) {
  457. complete(wl->elp_compl);
  458. wl->elp_compl = NULL;
  459. }
  460. ieee80211_queue_work(wl->hw, &wl->irq_work);
  461. spin_unlock_irqrestore(&wl->wl_lock, flags);
  462. return IRQ_HANDLED;
  463. }
  464. static int wl1271_fetch_firmware(struct wl1271 *wl)
  465. {
  466. const struct firmware *fw;
  467. int ret;
  468. ret = request_firmware(&fw, WL1271_FW_NAME, &wl->spi->dev);
  469. if (ret < 0) {
  470. wl1271_error("could not get firmware: %d", ret);
  471. return ret;
  472. }
  473. if (fw->size % 4) {
  474. wl1271_error("firmware size is not multiple of 32 bits: %zu",
  475. fw->size);
  476. ret = -EILSEQ;
  477. goto out;
  478. }
  479. wl->fw_len = fw->size;
  480. wl->fw = vmalloc(wl->fw_len);
  481. if (!wl->fw) {
  482. wl1271_error("could not allocate memory for the firmware");
  483. ret = -ENOMEM;
  484. goto out;
  485. }
  486. memcpy(wl->fw, fw->data, wl->fw_len);
  487. ret = 0;
  488. out:
  489. release_firmware(fw);
  490. return ret;
  491. }
  492. static int wl1271_fetch_nvs(struct wl1271 *wl)
  493. {
  494. const struct firmware *fw;
  495. int ret;
  496. ret = request_firmware(&fw, WL1271_NVS_NAME, &wl->spi->dev);
  497. if (ret < 0) {
  498. wl1271_error("could not get nvs file: %d", ret);
  499. return ret;
  500. }
  501. if (fw->size % 4) {
  502. wl1271_error("nvs size is not multiple of 32 bits: %zu",
  503. fw->size);
  504. ret = -EILSEQ;
  505. goto out;
  506. }
  507. wl->nvs_len = fw->size;
  508. wl->nvs = kmalloc(wl->nvs_len, GFP_KERNEL);
  509. if (!wl->nvs) {
  510. wl1271_error("could not allocate memory for the nvs file");
  511. ret = -ENOMEM;
  512. goto out;
  513. }
  514. memcpy(wl->nvs, fw->data, wl->nvs_len);
  515. ret = 0;
  516. out:
  517. release_firmware(fw);
  518. return ret;
  519. }
  520. static void wl1271_fw_wakeup(struct wl1271 *wl)
  521. {
  522. u32 elp_reg;
  523. elp_reg = ELPCTRL_WAKE_UP;
  524. wl1271_raw_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, elp_reg);
  525. }
  526. static int wl1271_setup(struct wl1271 *wl)
  527. {
  528. wl->fw_status = kmalloc(sizeof(*wl->fw_status), GFP_KERNEL);
  529. if (!wl->fw_status)
  530. return -ENOMEM;
  531. wl->tx_res_if = kmalloc(sizeof(*wl->tx_res_if), GFP_KERNEL);
  532. if (!wl->tx_res_if) {
  533. kfree(wl->fw_status);
  534. return -ENOMEM;
  535. }
  536. INIT_WORK(&wl->irq_work, wl1271_irq_work);
  537. INIT_WORK(&wl->tx_work, wl1271_tx_work);
  538. return 0;
  539. }
  540. static int wl1271_chip_wakeup(struct wl1271 *wl)
  541. {
  542. struct wl1271_partition_set partition;
  543. int ret = 0;
  544. wl1271_power_on(wl);
  545. msleep(WL1271_POWER_ON_SLEEP);
  546. wl1271_spi_reset(wl);
  547. wl1271_spi_init(wl);
  548. /* We don't need a real memory partition here, because we only want
  549. * to use the registers at this point. */
  550. memset(&partition, 0, sizeof(partition));
  551. partition.reg.start = REGISTERS_BASE;
  552. partition.reg.size = REGISTERS_DOWN_SIZE;
  553. wl1271_set_partition(wl, &partition);
  554. /* ELP module wake up */
  555. wl1271_fw_wakeup(wl);
  556. /* whal_FwCtrl_BootSm() */
  557. /* 0. read chip id from CHIP_ID */
  558. wl->chip.id = wl1271_spi_read32(wl, CHIP_ID_B);
  559. /* 1. check if chip id is valid */
  560. switch (wl->chip.id) {
  561. case CHIP_ID_1271_PG10:
  562. wl1271_warning("chip id 0x%x (1271 PG10) support is obsolete",
  563. wl->chip.id);
  564. ret = wl1271_setup(wl);
  565. if (ret < 0)
  566. goto out_power_off;
  567. break;
  568. case CHIP_ID_1271_PG20:
  569. wl1271_debug(DEBUG_BOOT, "chip id 0x%x (1271 PG20)",
  570. wl->chip.id);
  571. ret = wl1271_setup(wl);
  572. if (ret < 0)
  573. goto out_power_off;
  574. break;
  575. default:
  576. wl1271_error("unsupported chip id: 0x%x", wl->chip.id);
  577. ret = -ENODEV;
  578. goto out_power_off;
  579. }
  580. if (wl->fw == NULL) {
  581. ret = wl1271_fetch_firmware(wl);
  582. if (ret < 0)
  583. goto out_power_off;
  584. }
  585. /* No NVS from netlink, try to get it from the filesystem */
  586. if (wl->nvs == NULL) {
  587. ret = wl1271_fetch_nvs(wl);
  588. if (ret < 0)
  589. goto out_power_off;
  590. }
  591. goto out;
  592. out_power_off:
  593. wl1271_power_off(wl);
  594. out:
  595. return ret;
  596. }
  597. int wl1271_plt_start(struct wl1271 *wl)
  598. {
  599. int ret;
  600. mutex_lock(&wl->mutex);
  601. wl1271_notice("power up");
  602. if (wl->state != WL1271_STATE_OFF) {
  603. wl1271_error("cannot go into PLT state because not "
  604. "in off state: %d", wl->state);
  605. ret = -EBUSY;
  606. goto out;
  607. }
  608. wl->state = WL1271_STATE_PLT;
  609. ret = wl1271_chip_wakeup(wl);
  610. if (ret < 0)
  611. goto out;
  612. ret = wl1271_boot(wl);
  613. if (ret < 0)
  614. goto out_power_off;
  615. wl1271_notice("firmware booted in PLT mode (%s)", wl->chip.fw_ver);
  616. ret = wl1271_plt_init(wl);
  617. if (ret < 0)
  618. goto out_irq_disable;
  619. /* Make sure power saving is disabled */
  620. ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM);
  621. if (ret < 0)
  622. goto out_irq_disable;
  623. goto out;
  624. out_irq_disable:
  625. wl1271_disable_interrupts(wl);
  626. out_power_off:
  627. wl1271_power_off(wl);
  628. out:
  629. mutex_unlock(&wl->mutex);
  630. return ret;
  631. }
  632. int wl1271_plt_stop(struct wl1271 *wl)
  633. {
  634. int ret = 0;
  635. mutex_lock(&wl->mutex);
  636. wl1271_notice("power down");
  637. if (wl->state != WL1271_STATE_PLT) {
  638. wl1271_error("cannot power down because not in PLT "
  639. "state: %d", wl->state);
  640. ret = -EBUSY;
  641. goto out;
  642. }
  643. wl1271_disable_interrupts(wl);
  644. wl1271_power_off(wl);
  645. wl->state = WL1271_STATE_OFF;
  646. wl->rx_counter = 0;
  647. out:
  648. mutex_unlock(&wl->mutex);
  649. return ret;
  650. }
  651. static int wl1271_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
  652. {
  653. struct wl1271 *wl = hw->priv;
  654. skb_queue_tail(&wl->tx_queue, skb);
  655. /*
  656. * The chip specific setup must run before the first TX packet -
  657. * before that, the tx_work will not be initialized!
  658. */
  659. ieee80211_queue_work(wl->hw, &wl->tx_work);
  660. /*
  661. * The workqueue is slow to process the tx_queue and we need stop
  662. * the queue here, otherwise the queue will get too long.
  663. */
  664. if (skb_queue_len(&wl->tx_queue) >= WL1271_TX_QUEUE_MAX_LENGTH) {
  665. ieee80211_stop_queues(wl->hw);
  666. /*
  667. * FIXME: this is racy, the variable is not properly
  668. * protected. Maybe fix this by removing the stupid
  669. * variable altogether and checking the real queue state?
  670. */
  671. wl->tx_queue_stopped = true;
  672. }
  673. return NETDEV_TX_OK;
  674. }
  675. static int wl1271_dev_notify(struct notifier_block *me, unsigned long what,
  676. void *arg)
  677. {
  678. struct net_device *dev;
  679. struct wireless_dev *wdev;
  680. struct wiphy *wiphy;
  681. struct ieee80211_hw *hw;
  682. struct wl1271 *wl;
  683. struct wl1271 *wl_temp;
  684. struct in_device *idev;
  685. struct in_ifaddr *ifa = arg;
  686. int ret = 0;
  687. /* FIXME: this ugly function should probably be implemented in the
  688. * mac80211, and here should only be a simple callback handling actual
  689. * setting of the filters. Now we need to dig up references to
  690. * various structures to gain access to what we need.
  691. * Also, because of this, there is no "initial" setting of the filter
  692. * in "op_start", because we don't want to dig up struct net_device
  693. * there - the filter will be set upon first change of the interface
  694. * IP address. */
  695. dev = ifa->ifa_dev->dev;
  696. wdev = dev->ieee80211_ptr;
  697. if (wdev == NULL)
  698. return NOTIFY_DONE;
  699. wiphy = wdev->wiphy;
  700. if (wiphy == NULL)
  701. return NOTIFY_DONE;
  702. hw = wiphy_priv(wiphy);
  703. if (hw == NULL)
  704. return NOTIFY_DONE;
  705. /* Check that the interface is one supported by this driver. */
  706. wl_temp = hw->priv;
  707. list_for_each_entry(wl, &wl_list, list) {
  708. if (wl == wl_temp)
  709. break;
  710. }
  711. if (wl == NULL)
  712. return NOTIFY_DONE;
  713. /* Get the interface IP address for the device. "ifa" will become
  714. NULL if:
  715. - there is no IPV4 protocol address configured
  716. - there are multiple (virtual) IPV4 addresses configured
  717. When "ifa" is NULL, filtering will be disabled.
  718. */
  719. ifa = NULL;
  720. idev = dev->ip_ptr;
  721. if (idev)
  722. ifa = idev->ifa_list;
  723. if (ifa && ifa->ifa_next)
  724. ifa = NULL;
  725. mutex_lock(&wl->mutex);
  726. if (wl->state == WL1271_STATE_OFF)
  727. goto out;
  728. ret = wl1271_ps_elp_wakeup(wl, false);
  729. if (ret < 0)
  730. goto out;
  731. if (ifa)
  732. ret = wl1271_acx_arp_ip_filter(wl, true,
  733. (u8 *)&ifa->ifa_address,
  734. ACX_IPV4_VERSION);
  735. else
  736. ret = wl1271_acx_arp_ip_filter(wl, false, NULL,
  737. ACX_IPV4_VERSION);
  738. wl1271_ps_elp_sleep(wl);
  739. out:
  740. mutex_unlock(&wl->mutex);
  741. return NOTIFY_OK;
  742. }
  743. static struct notifier_block wl1271_dev_notifier = {
  744. .notifier_call = wl1271_dev_notify,
  745. };
  746. static int wl1271_op_start(struct ieee80211_hw *hw)
  747. {
  748. struct wl1271 *wl = hw->priv;
  749. int ret = 0;
  750. wl1271_debug(DEBUG_MAC80211, "mac80211 start");
  751. mutex_lock(&wl->mutex);
  752. if (wl->state != WL1271_STATE_OFF) {
  753. wl1271_error("cannot start because not in off state: %d",
  754. wl->state);
  755. ret = -EBUSY;
  756. goto out;
  757. }
  758. ret = wl1271_chip_wakeup(wl);
  759. if (ret < 0)
  760. goto out;
  761. ret = wl1271_boot(wl);
  762. if (ret < 0)
  763. goto out_power_off;
  764. ret = wl1271_hw_init(wl);
  765. if (ret < 0)
  766. goto out_irq_disable;
  767. wl->state = WL1271_STATE_ON;
  768. wl1271_info("firmware booted (%s)", wl->chip.fw_ver);
  769. goto out;
  770. out_irq_disable:
  771. wl1271_disable_interrupts(wl);
  772. out_power_off:
  773. wl1271_power_off(wl);
  774. out:
  775. mutex_unlock(&wl->mutex);
  776. if (!ret) {
  777. list_add(&wl->list, &wl_list);
  778. register_inetaddr_notifier(&wl1271_dev_notifier);
  779. }
  780. return ret;
  781. }
  782. static void wl1271_op_stop(struct ieee80211_hw *hw)
  783. {
  784. struct wl1271 *wl = hw->priv;
  785. int i;
  786. wl1271_info("down");
  787. wl1271_debug(DEBUG_MAC80211, "mac80211 stop");
  788. unregister_inetaddr_notifier(&wl1271_dev_notifier);
  789. list_del(&wl->list);
  790. mutex_lock(&wl->mutex);
  791. WARN_ON(wl->state != WL1271_STATE_ON);
  792. if (wl->scanning) {
  793. mutex_unlock(&wl->mutex);
  794. ieee80211_scan_completed(wl->hw, true);
  795. mutex_lock(&wl->mutex);
  796. wl->scanning = false;
  797. }
  798. wl->state = WL1271_STATE_OFF;
  799. wl1271_disable_interrupts(wl);
  800. mutex_unlock(&wl->mutex);
  801. cancel_work_sync(&wl->irq_work);
  802. cancel_work_sync(&wl->tx_work);
  803. mutex_lock(&wl->mutex);
  804. /* let's notify MAC80211 about the remaining pending TX frames */
  805. wl1271_tx_flush(wl);
  806. wl1271_power_off(wl);
  807. memset(wl->bssid, 0, ETH_ALEN);
  808. memset(wl->ssid, 0, IW_ESSID_MAX_SIZE + 1);
  809. wl->ssid_len = 0;
  810. wl->bss_type = MAX_BSS_TYPE;
  811. wl->band = IEEE80211_BAND_2GHZ;
  812. wl->rx_counter = 0;
  813. wl->elp = false;
  814. wl->psm = 0;
  815. wl->psm_entry_retry = 0;
  816. wl->tx_queue_stopped = false;
  817. wl->power_level = WL1271_DEFAULT_POWER_LEVEL;
  818. wl->tx_blocks_available = 0;
  819. wl->tx_results_count = 0;
  820. wl->tx_packets_count = 0;
  821. wl->tx_security_last_seq = 0;
  822. wl->tx_security_seq_16 = 0;
  823. wl->tx_security_seq_32 = 0;
  824. wl->time_offset = 0;
  825. wl->session_counter = 0;
  826. wl->joined = false;
  827. for (i = 0; i < NUM_TX_QUEUES; i++)
  828. wl->tx_blocks_freed[i] = 0;
  829. wl1271_debugfs_reset(wl);
  830. mutex_unlock(&wl->mutex);
  831. }
  832. static int wl1271_op_add_interface(struct ieee80211_hw *hw,
  833. struct ieee80211_if_init_conf *conf)
  834. {
  835. struct wl1271 *wl = hw->priv;
  836. int ret = 0;
  837. wl1271_debug(DEBUG_MAC80211, "mac80211 add interface type %d mac %pM",
  838. conf->type, conf->mac_addr);
  839. mutex_lock(&wl->mutex);
  840. if (wl->vif) {
  841. ret = -EBUSY;
  842. goto out;
  843. }
  844. wl->vif = conf->vif;
  845. switch (conf->type) {
  846. case NL80211_IFTYPE_STATION:
  847. wl->bss_type = BSS_TYPE_STA_BSS;
  848. break;
  849. case NL80211_IFTYPE_ADHOC:
  850. wl->bss_type = BSS_TYPE_IBSS;
  851. break;
  852. default:
  853. ret = -EOPNOTSUPP;
  854. goto out;
  855. }
  856. /* FIXME: what if conf->mac_addr changes? */
  857. out:
  858. mutex_unlock(&wl->mutex);
  859. return ret;
  860. }
  861. static void wl1271_op_remove_interface(struct ieee80211_hw *hw,
  862. struct ieee80211_if_init_conf *conf)
  863. {
  864. struct wl1271 *wl = hw->priv;
  865. mutex_lock(&wl->mutex);
  866. wl1271_debug(DEBUG_MAC80211, "mac80211 remove interface");
  867. wl->vif = NULL;
  868. mutex_unlock(&wl->mutex);
  869. }
  870. #if 0
  871. static int wl1271_op_config_interface(struct ieee80211_hw *hw,
  872. struct ieee80211_vif *vif,
  873. struct ieee80211_if_conf *conf)
  874. {
  875. struct wl1271 *wl = hw->priv;
  876. struct sk_buff *beacon;
  877. int ret;
  878. wl1271_debug(DEBUG_MAC80211, "mac80211 config_interface bssid %pM",
  879. conf->bssid);
  880. wl1271_dump_ascii(DEBUG_MAC80211, "ssid: ", conf->ssid,
  881. conf->ssid_len);
  882. mutex_lock(&wl->mutex);
  883. ret = wl1271_ps_elp_wakeup(wl, false);
  884. if (ret < 0)
  885. goto out;
  886. if (memcmp(wl->bssid, conf->bssid, ETH_ALEN)) {
  887. wl1271_debug(DEBUG_MAC80211, "bssid changed");
  888. memcpy(wl->bssid, conf->bssid, ETH_ALEN);
  889. ret = wl1271_cmd_join(wl);
  890. if (ret < 0)
  891. goto out_sleep;
  892. ret = wl1271_cmd_build_null_data(wl);
  893. if (ret < 0)
  894. goto out_sleep;
  895. }
  896. wl->ssid_len = conf->ssid_len;
  897. if (wl->ssid_len)
  898. memcpy(wl->ssid, conf->ssid, wl->ssid_len);
  899. if (conf->changed & IEEE80211_IFCC_BEACON) {
  900. beacon = ieee80211_beacon_get(hw, vif);
  901. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_BEACON,
  902. beacon->data, beacon->len);
  903. if (ret < 0) {
  904. dev_kfree_skb(beacon);
  905. goto out_sleep;
  906. }
  907. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PROBE_RESPONSE,
  908. beacon->data, beacon->len);
  909. dev_kfree_skb(beacon);
  910. if (ret < 0)
  911. goto out_sleep;
  912. }
  913. out_sleep:
  914. wl1271_ps_elp_sleep(wl);
  915. out:
  916. mutex_unlock(&wl->mutex);
  917. return ret;
  918. }
  919. #endif
  920. static int wl1271_join_channel(struct wl1271 *wl, int channel)
  921. {
  922. int ret;
  923. /* we need to use a dummy BSSID for now */
  924. static const u8 dummy_bssid[ETH_ALEN] = { 0x0b, 0xad, 0xde,
  925. 0xad, 0xbe, 0xef };
  926. /* disable mac filter, so we hear everything */
  927. wl->rx_config &= ~CFG_BSSID_FILTER_EN;
  928. wl->channel = channel;
  929. memcpy(wl->bssid, dummy_bssid, ETH_ALEN);
  930. ret = wl1271_cmd_join(wl);
  931. if (ret < 0)
  932. goto out;
  933. wl->joined = true;
  934. out:
  935. return ret;
  936. }
  937. static int wl1271_unjoin_channel(struct wl1271 *wl)
  938. {
  939. int ret;
  940. /* to stop listening to a channel, we disconnect */
  941. ret = wl1271_cmd_disconnect(wl);
  942. if (ret < 0)
  943. goto out;
  944. wl->joined = false;
  945. wl->channel = 0;
  946. memset(wl->bssid, 0, ETH_ALEN);
  947. wl->rx_config = WL1271_DEFAULT_RX_CONFIG;
  948. out:
  949. return ret;
  950. }
  951. static int wl1271_op_config(struct ieee80211_hw *hw, u32 changed)
  952. {
  953. struct wl1271 *wl = hw->priv;
  954. struct ieee80211_conf *conf = &hw->conf;
  955. int channel, ret = 0;
  956. channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
  957. wl1271_debug(DEBUG_MAC80211, "mac80211 config ch %d psm %s power %d %s",
  958. channel,
  959. conf->flags & IEEE80211_CONF_PS ? "on" : "off",
  960. conf->power_level,
  961. conf->flags & IEEE80211_CONF_IDLE ? "idle" : "in use");
  962. mutex_lock(&wl->mutex);
  963. wl->band = conf->channel->band;
  964. ret = wl1271_ps_elp_wakeup(wl, false);
  965. if (ret < 0)
  966. goto out;
  967. if (changed & IEEE80211_CONF_CHANGE_IDLE) {
  968. if (conf->flags & IEEE80211_CONF_IDLE && wl->joined)
  969. wl1271_unjoin_channel(wl);
  970. else
  971. wl1271_join_channel(wl, channel);
  972. if (conf->flags & IEEE80211_CONF_IDLE) {
  973. wl->basic_rate_set = CONF_TX_RATE_MASK_BASIC;
  974. wl1271_acx_rate_policies(wl, CONF_TX_RATE_MASK_BASIC);
  975. }
  976. }
  977. /* if the channel changes while joined, join again */
  978. if (channel != wl->channel && wl->joined)
  979. wl1271_join_channel(wl, channel);
  980. if (conf->flags & IEEE80211_CONF_PS && !wl->psm_requested) {
  981. wl1271_info("psm enabled");
  982. wl->psm_requested = true;
  983. /*
  984. * We enter PSM only if we're already associated.
  985. * If we're not, we'll enter it when joining an SSID,
  986. * through the bss_info_changed() hook.
  987. */
  988. ret = wl1271_ps_set_mode(wl, STATION_POWER_SAVE_MODE);
  989. } else if (!(conf->flags & IEEE80211_CONF_PS) &&
  990. wl->psm_requested) {
  991. wl1271_info("psm disabled");
  992. wl->psm_requested = false;
  993. if (wl->psm)
  994. ret = wl1271_ps_set_mode(wl, STATION_ACTIVE_MODE);
  995. }
  996. if (conf->power_level != wl->power_level) {
  997. ret = wl1271_acx_tx_power(wl, conf->power_level);
  998. if (ret < 0)
  999. goto out_sleep;
  1000. wl->power_level = conf->power_level;
  1001. }
  1002. out_sleep:
  1003. wl1271_ps_elp_sleep(wl);
  1004. out:
  1005. mutex_unlock(&wl->mutex);
  1006. return ret;
  1007. }
  1008. struct wl1271_filter_params {
  1009. bool enabled;
  1010. int mc_list_length;
  1011. u8 mc_list[ACX_MC_ADDRESS_GROUP_MAX][ETH_ALEN];
  1012. };
  1013. static u64 wl1271_op_prepare_multicast(struct ieee80211_hw *hw, int mc_count,
  1014. struct dev_addr_list *mc_list)
  1015. {
  1016. struct wl1271_filter_params *fp;
  1017. int i;
  1018. fp = kzalloc(sizeof(*fp), GFP_ATOMIC);
  1019. if (!fp) {
  1020. wl1271_error("Out of memory setting filters.");
  1021. return 0;
  1022. }
  1023. /* update multicast filtering parameters */
  1024. fp->enabled = true;
  1025. if (mc_count > ACX_MC_ADDRESS_GROUP_MAX) {
  1026. mc_count = 0;
  1027. fp->enabled = false;
  1028. }
  1029. fp->mc_list_length = 0;
  1030. for (i = 0; i < mc_count; i++) {
  1031. if (mc_list->da_addrlen == ETH_ALEN) {
  1032. memcpy(fp->mc_list[fp->mc_list_length],
  1033. mc_list->da_addr, ETH_ALEN);
  1034. fp->mc_list_length++;
  1035. } else
  1036. wl1271_warning("Unknown mc address length.");
  1037. mc_list = mc_list->next;
  1038. }
  1039. return (u64)(unsigned long)fp;
  1040. }
  1041. #define WL1271_SUPPORTED_FILTERS (FIF_PROMISC_IN_BSS | \
  1042. FIF_ALLMULTI | \
  1043. FIF_FCSFAIL | \
  1044. FIF_BCN_PRBRESP_PROMISC | \
  1045. FIF_CONTROL | \
  1046. FIF_OTHER_BSS)
  1047. static void wl1271_op_configure_filter(struct ieee80211_hw *hw,
  1048. unsigned int changed,
  1049. unsigned int *total, u64 multicast)
  1050. {
  1051. struct wl1271_filter_params *fp = (void *)(unsigned long)multicast;
  1052. struct wl1271 *wl = hw->priv;
  1053. int ret;
  1054. wl1271_debug(DEBUG_MAC80211, "mac80211 configure filter");
  1055. mutex_lock(&wl->mutex);
  1056. if (wl->state == WL1271_STATE_OFF)
  1057. goto out;
  1058. ret = wl1271_ps_elp_wakeup(wl, false);
  1059. if (ret < 0)
  1060. goto out;
  1061. *total &= WL1271_SUPPORTED_FILTERS;
  1062. changed &= WL1271_SUPPORTED_FILTERS;
  1063. if (*total & FIF_ALLMULTI)
  1064. ret = wl1271_acx_group_address_tbl(wl, false, NULL, 0);
  1065. else if (fp)
  1066. ret = wl1271_acx_group_address_tbl(wl, fp->enabled,
  1067. fp->mc_list,
  1068. fp->mc_list_length);
  1069. if (ret < 0)
  1070. goto out_sleep;
  1071. kfree(fp);
  1072. /* FIXME: We still need to set our filters properly */
  1073. /* determine, whether supported filter values have changed */
  1074. if (changed == 0)
  1075. goto out_sleep;
  1076. /* apply configured filters */
  1077. ret = wl1271_acx_rx_config(wl, wl->rx_config, wl->rx_filter);
  1078. if (ret < 0)
  1079. goto out_sleep;
  1080. out_sleep:
  1081. wl1271_ps_elp_sleep(wl);
  1082. out:
  1083. mutex_unlock(&wl->mutex);
  1084. }
  1085. static int wl1271_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  1086. struct ieee80211_vif *vif,
  1087. struct ieee80211_sta *sta,
  1088. struct ieee80211_key_conf *key_conf)
  1089. {
  1090. struct wl1271 *wl = hw->priv;
  1091. const u8 *addr;
  1092. int ret;
  1093. u32 tx_seq_32 = 0;
  1094. u16 tx_seq_16 = 0;
  1095. u8 key_type;
  1096. static const u8 bcast_addr[ETH_ALEN] =
  1097. { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
  1098. wl1271_debug(DEBUG_MAC80211, "mac80211 set key");
  1099. addr = sta ? sta->addr : bcast_addr;
  1100. wl1271_debug(DEBUG_CRYPT, "CMD: 0x%x", cmd);
  1101. wl1271_dump(DEBUG_CRYPT, "ADDR: ", addr, ETH_ALEN);
  1102. wl1271_debug(DEBUG_CRYPT, "Key: algo:0x%x, id:%d, len:%d flags 0x%x",
  1103. key_conf->alg, key_conf->keyidx,
  1104. key_conf->keylen, key_conf->flags);
  1105. wl1271_dump(DEBUG_CRYPT, "KEY: ", key_conf->key, key_conf->keylen);
  1106. if (is_zero_ether_addr(addr)) {
  1107. /* We dont support TX only encryption */
  1108. ret = -EOPNOTSUPP;
  1109. goto out;
  1110. }
  1111. mutex_lock(&wl->mutex);
  1112. ret = wl1271_ps_elp_wakeup(wl, false);
  1113. if (ret < 0)
  1114. goto out_unlock;
  1115. switch (key_conf->alg) {
  1116. case ALG_WEP:
  1117. key_type = KEY_WEP;
  1118. key_conf->hw_key_idx = key_conf->keyidx;
  1119. break;
  1120. case ALG_TKIP:
  1121. key_type = KEY_TKIP;
  1122. key_conf->hw_key_idx = key_conf->keyidx;
  1123. tx_seq_32 = wl->tx_security_seq_32;
  1124. tx_seq_16 = wl->tx_security_seq_16;
  1125. break;
  1126. case ALG_CCMP:
  1127. key_type = KEY_AES;
  1128. key_conf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  1129. tx_seq_32 = wl->tx_security_seq_32;
  1130. tx_seq_16 = wl->tx_security_seq_16;
  1131. break;
  1132. default:
  1133. wl1271_error("Unknown key algo 0x%x", key_conf->alg);
  1134. ret = -EOPNOTSUPP;
  1135. goto out_sleep;
  1136. }
  1137. switch (cmd) {
  1138. case SET_KEY:
  1139. ret = wl1271_cmd_set_key(wl, KEY_ADD_OR_REPLACE,
  1140. key_conf->keyidx, key_type,
  1141. key_conf->keylen, key_conf->key,
  1142. addr, tx_seq_32, tx_seq_16);
  1143. if (ret < 0) {
  1144. wl1271_error("Could not add or replace key");
  1145. goto out_sleep;
  1146. }
  1147. break;
  1148. case DISABLE_KEY:
  1149. ret = wl1271_cmd_set_key(wl, KEY_REMOVE,
  1150. key_conf->keyidx, key_type,
  1151. key_conf->keylen, key_conf->key,
  1152. addr, 0, 0);
  1153. if (ret < 0) {
  1154. wl1271_error("Could not remove key");
  1155. goto out_sleep;
  1156. }
  1157. break;
  1158. default:
  1159. wl1271_error("Unsupported key cmd 0x%x", cmd);
  1160. ret = -EOPNOTSUPP;
  1161. goto out_sleep;
  1162. break;
  1163. }
  1164. out_sleep:
  1165. wl1271_ps_elp_sleep(wl);
  1166. out_unlock:
  1167. mutex_unlock(&wl->mutex);
  1168. out:
  1169. return ret;
  1170. }
  1171. static int wl1271_op_hw_scan(struct ieee80211_hw *hw,
  1172. struct cfg80211_scan_request *req)
  1173. {
  1174. struct wl1271 *wl = hw->priv;
  1175. int ret;
  1176. u8 *ssid = NULL;
  1177. size_t len = 0;
  1178. wl1271_debug(DEBUG_MAC80211, "mac80211 hw scan");
  1179. if (req->n_ssids) {
  1180. ssid = req->ssids[0].ssid;
  1181. len = req->ssids[0].ssid_len;
  1182. }
  1183. mutex_lock(&wl->mutex);
  1184. ret = wl1271_ps_elp_wakeup(wl, false);
  1185. if (ret < 0)
  1186. goto out;
  1187. if (wl1271_11a_enabled())
  1188. ret = wl1271_cmd_scan(hw->priv, ssid, len, 1, 0,
  1189. WL1271_SCAN_BAND_DUAL, 3);
  1190. else
  1191. ret = wl1271_cmd_scan(hw->priv, ssid, len, 1, 0,
  1192. WL1271_SCAN_BAND_2_4_GHZ, 3);
  1193. wl1271_ps_elp_sleep(wl);
  1194. out:
  1195. mutex_unlock(&wl->mutex);
  1196. return ret;
  1197. }
  1198. static int wl1271_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
  1199. {
  1200. struct wl1271 *wl = hw->priv;
  1201. int ret;
  1202. mutex_lock(&wl->mutex);
  1203. ret = wl1271_ps_elp_wakeup(wl, false);
  1204. if (ret < 0)
  1205. goto out;
  1206. ret = wl1271_acx_rts_threshold(wl, (u16) value);
  1207. if (ret < 0)
  1208. wl1271_warning("wl1271_op_set_rts_threshold failed: %d", ret);
  1209. wl1271_ps_elp_sleep(wl);
  1210. out:
  1211. mutex_unlock(&wl->mutex);
  1212. return ret;
  1213. }
  1214. static u32 wl1271_enabled_rates_get(struct wl1271 *wl, u64 basic_rate_set)
  1215. {
  1216. struct ieee80211_supported_band *band;
  1217. u32 enabled_rates = 0;
  1218. int bit;
  1219. band = wl->hw->wiphy->bands[wl->band];
  1220. for (bit = 0; bit < band->n_bitrates; bit++) {
  1221. if (basic_rate_set & 0x1)
  1222. enabled_rates |= band->bitrates[bit].hw_value;
  1223. basic_rate_set >>= 1;
  1224. }
  1225. return enabled_rates;
  1226. }
  1227. static void wl1271_op_bss_info_changed(struct ieee80211_hw *hw,
  1228. struct ieee80211_vif *vif,
  1229. struct ieee80211_bss_conf *bss_conf,
  1230. u32 changed)
  1231. {
  1232. enum wl1271_cmd_ps_mode mode;
  1233. struct wl1271 *wl = hw->priv;
  1234. int ret;
  1235. wl1271_debug(DEBUG_MAC80211, "mac80211 bss info changed");
  1236. mutex_lock(&wl->mutex);
  1237. ret = wl1271_ps_elp_wakeup(wl, false);
  1238. if (ret < 0)
  1239. goto out;
  1240. if ((changed & BSS_CHANGED_BSSID) &&
  1241. /*
  1242. * Now we know the correct bssid, so we send a new join command
  1243. * and enable the BSSID filter
  1244. */
  1245. memcmp(wl->bssid, bss_conf->bssid, ETH_ALEN)) {
  1246. wl->rx_config |= CFG_BSSID_FILTER_EN;
  1247. memcpy(wl->bssid, bss_conf->bssid, ETH_ALEN);
  1248. ret = wl1271_cmd_build_null_data(wl);
  1249. if (ret < 0) {
  1250. wl1271_warning("cmd buld null data failed %d",
  1251. ret);
  1252. goto out_sleep;
  1253. }
  1254. ret = wl1271_cmd_join(wl);
  1255. if (ret < 0) {
  1256. wl1271_warning("cmd join failed %d", ret);
  1257. goto out_sleep;
  1258. }
  1259. wl->joined = true;
  1260. }
  1261. if (changed & BSS_CHANGED_ASSOC) {
  1262. if (bss_conf->assoc) {
  1263. wl->aid = bss_conf->aid;
  1264. /*
  1265. * with wl1271, we don't need to update the
  1266. * beacon_int and dtim_period, because the firmware
  1267. * updates it by itself when the first beacon is
  1268. * received after a join.
  1269. */
  1270. ret = wl1271_cmd_build_ps_poll(wl, wl->aid);
  1271. if (ret < 0)
  1272. goto out_sleep;
  1273. ret = wl1271_acx_aid(wl, wl->aid);
  1274. if (ret < 0)
  1275. goto out_sleep;
  1276. /* If we want to go in PSM but we're not there yet */
  1277. if (wl->psm_requested && !wl->psm) {
  1278. mode = STATION_POWER_SAVE_MODE;
  1279. ret = wl1271_ps_set_mode(wl, mode);
  1280. if (ret < 0)
  1281. goto out_sleep;
  1282. }
  1283. } else {
  1284. /* use defaults when not associated */
  1285. wl->aid = 0;
  1286. }
  1287. }
  1288. if (changed & BSS_CHANGED_ERP_SLOT) {
  1289. if (bss_conf->use_short_slot)
  1290. ret = wl1271_acx_slot(wl, SLOT_TIME_SHORT);
  1291. else
  1292. ret = wl1271_acx_slot(wl, SLOT_TIME_LONG);
  1293. if (ret < 0) {
  1294. wl1271_warning("Set slot time failed %d", ret);
  1295. goto out_sleep;
  1296. }
  1297. }
  1298. if (changed & BSS_CHANGED_ERP_PREAMBLE) {
  1299. if (bss_conf->use_short_preamble)
  1300. wl1271_acx_set_preamble(wl, ACX_PREAMBLE_SHORT);
  1301. else
  1302. wl1271_acx_set_preamble(wl, ACX_PREAMBLE_LONG);
  1303. }
  1304. if (changed & BSS_CHANGED_ERP_CTS_PROT) {
  1305. if (bss_conf->use_cts_prot)
  1306. ret = wl1271_acx_cts_protect(wl, CTSPROTECT_ENABLE);
  1307. else
  1308. ret = wl1271_acx_cts_protect(wl, CTSPROTECT_DISABLE);
  1309. if (ret < 0) {
  1310. wl1271_warning("Set ctsprotect failed %d", ret);
  1311. goto out_sleep;
  1312. }
  1313. }
  1314. if (changed & BSS_CHANGED_BASIC_RATES) {
  1315. wl->basic_rate_set = wl1271_enabled_rates_get(
  1316. wl, bss_conf->basic_rates);
  1317. ret = wl1271_acx_rate_policies(wl, wl->basic_rate_set);
  1318. if (ret < 0) {
  1319. wl1271_warning("Set rate policies failed %d", ret);
  1320. goto out_sleep;
  1321. }
  1322. }
  1323. out_sleep:
  1324. wl1271_ps_elp_sleep(wl);
  1325. out:
  1326. mutex_unlock(&wl->mutex);
  1327. }
  1328. /* can't be const, mac80211 writes to this */
  1329. static struct ieee80211_rate wl1271_rates[] = {
  1330. { .bitrate = 10,
  1331. .hw_value = CONF_HW_BIT_RATE_1MBPS,
  1332. .hw_value_short = CONF_HW_BIT_RATE_1MBPS, },
  1333. { .bitrate = 20,
  1334. .hw_value = CONF_HW_BIT_RATE_2MBPS,
  1335. .hw_value_short = CONF_HW_BIT_RATE_2MBPS,
  1336. .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  1337. { .bitrate = 55,
  1338. .hw_value = CONF_HW_BIT_RATE_5_5MBPS,
  1339. .hw_value_short = CONF_HW_BIT_RATE_5_5MBPS,
  1340. .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  1341. { .bitrate = 110,
  1342. .hw_value = CONF_HW_BIT_RATE_11MBPS,
  1343. .hw_value_short = CONF_HW_BIT_RATE_11MBPS,
  1344. .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  1345. { .bitrate = 60,
  1346. .hw_value = CONF_HW_BIT_RATE_6MBPS,
  1347. .hw_value_short = CONF_HW_BIT_RATE_6MBPS, },
  1348. { .bitrate = 90,
  1349. .hw_value = CONF_HW_BIT_RATE_9MBPS,
  1350. .hw_value_short = CONF_HW_BIT_RATE_9MBPS, },
  1351. { .bitrate = 120,
  1352. .hw_value = CONF_HW_BIT_RATE_12MBPS,
  1353. .hw_value_short = CONF_HW_BIT_RATE_12MBPS, },
  1354. { .bitrate = 180,
  1355. .hw_value = CONF_HW_BIT_RATE_18MBPS,
  1356. .hw_value_short = CONF_HW_BIT_RATE_18MBPS, },
  1357. { .bitrate = 240,
  1358. .hw_value = CONF_HW_BIT_RATE_24MBPS,
  1359. .hw_value_short = CONF_HW_BIT_RATE_24MBPS, },
  1360. { .bitrate = 360,
  1361. .hw_value = CONF_HW_BIT_RATE_36MBPS,
  1362. .hw_value_short = CONF_HW_BIT_RATE_36MBPS, },
  1363. { .bitrate = 480,
  1364. .hw_value = CONF_HW_BIT_RATE_48MBPS,
  1365. .hw_value_short = CONF_HW_BIT_RATE_48MBPS, },
  1366. { .bitrate = 540,
  1367. .hw_value = CONF_HW_BIT_RATE_54MBPS,
  1368. .hw_value_short = CONF_HW_BIT_RATE_54MBPS, },
  1369. };
  1370. /* can't be const, mac80211 writes to this */
  1371. static struct ieee80211_channel wl1271_channels[] = {
  1372. { .hw_value = 1, .center_freq = 2412, .max_power = 25 },
  1373. { .hw_value = 2, .center_freq = 2417, .max_power = 25 },
  1374. { .hw_value = 3, .center_freq = 2422, .max_power = 25 },
  1375. { .hw_value = 4, .center_freq = 2427, .max_power = 25 },
  1376. { .hw_value = 5, .center_freq = 2432, .max_power = 25 },
  1377. { .hw_value = 6, .center_freq = 2437, .max_power = 25 },
  1378. { .hw_value = 7, .center_freq = 2442, .max_power = 25 },
  1379. { .hw_value = 8, .center_freq = 2447, .max_power = 25 },
  1380. { .hw_value = 9, .center_freq = 2452, .max_power = 25 },
  1381. { .hw_value = 10, .center_freq = 2457, .max_power = 25 },
  1382. { .hw_value = 11, .center_freq = 2462, .max_power = 25 },
  1383. { .hw_value = 12, .center_freq = 2467, .max_power = 25 },
  1384. { .hw_value = 13, .center_freq = 2472, .max_power = 25 },
  1385. };
  1386. /* can't be const, mac80211 writes to this */
  1387. static struct ieee80211_supported_band wl1271_band_2ghz = {
  1388. .channels = wl1271_channels,
  1389. .n_channels = ARRAY_SIZE(wl1271_channels),
  1390. .bitrates = wl1271_rates,
  1391. .n_bitrates = ARRAY_SIZE(wl1271_rates),
  1392. };
  1393. /* 5 GHz data rates for WL1273 */
  1394. static struct ieee80211_rate wl1271_rates_5ghz[] = {
  1395. { .bitrate = 60,
  1396. .hw_value = CONF_HW_BIT_RATE_6MBPS,
  1397. .hw_value_short = CONF_HW_BIT_RATE_6MBPS, },
  1398. { .bitrate = 90,
  1399. .hw_value = CONF_HW_BIT_RATE_9MBPS,
  1400. .hw_value_short = CONF_HW_BIT_RATE_9MBPS, },
  1401. { .bitrate = 120,
  1402. .hw_value = CONF_HW_BIT_RATE_12MBPS,
  1403. .hw_value_short = CONF_HW_BIT_RATE_12MBPS, },
  1404. { .bitrate = 180,
  1405. .hw_value = CONF_HW_BIT_RATE_18MBPS,
  1406. .hw_value_short = CONF_HW_BIT_RATE_18MBPS, },
  1407. { .bitrate = 240,
  1408. .hw_value = CONF_HW_BIT_RATE_24MBPS,
  1409. .hw_value_short = CONF_HW_BIT_RATE_24MBPS, },
  1410. { .bitrate = 360,
  1411. .hw_value = CONF_HW_BIT_RATE_36MBPS,
  1412. .hw_value_short = CONF_HW_BIT_RATE_36MBPS, },
  1413. { .bitrate = 480,
  1414. .hw_value = CONF_HW_BIT_RATE_48MBPS,
  1415. .hw_value_short = CONF_HW_BIT_RATE_48MBPS, },
  1416. { .bitrate = 540,
  1417. .hw_value = CONF_HW_BIT_RATE_54MBPS,
  1418. .hw_value_short = CONF_HW_BIT_RATE_54MBPS, },
  1419. };
  1420. /* 5 GHz band channels for WL1273 */
  1421. static struct ieee80211_channel wl1271_channels_5ghz[] = {
  1422. { .hw_value = 183, .center_freq = 4915},
  1423. { .hw_value = 184, .center_freq = 4920},
  1424. { .hw_value = 185, .center_freq = 4925},
  1425. { .hw_value = 187, .center_freq = 4935},
  1426. { .hw_value = 188, .center_freq = 4940},
  1427. { .hw_value = 189, .center_freq = 4945},
  1428. { .hw_value = 192, .center_freq = 4960},
  1429. { .hw_value = 196, .center_freq = 4980},
  1430. { .hw_value = 7, .center_freq = 5035},
  1431. { .hw_value = 8, .center_freq = 5040},
  1432. { .hw_value = 9, .center_freq = 5045},
  1433. { .hw_value = 11, .center_freq = 5055},
  1434. { .hw_value = 12, .center_freq = 5060},
  1435. { .hw_value = 16, .center_freq = 5080},
  1436. { .hw_value = 34, .center_freq = 5170},
  1437. { .hw_value = 36, .center_freq = 5180},
  1438. { .hw_value = 38, .center_freq = 5190},
  1439. { .hw_value = 40, .center_freq = 5200},
  1440. { .hw_value = 42, .center_freq = 5210},
  1441. { .hw_value = 44, .center_freq = 5220},
  1442. { .hw_value = 46, .center_freq = 5230},
  1443. { .hw_value = 48, .center_freq = 5240},
  1444. { .hw_value = 52, .center_freq = 5260},
  1445. { .hw_value = 56, .center_freq = 5280},
  1446. { .hw_value = 60, .center_freq = 5300},
  1447. { .hw_value = 64, .center_freq = 5320},
  1448. { .hw_value = 100, .center_freq = 5500},
  1449. { .hw_value = 104, .center_freq = 5520},
  1450. { .hw_value = 108, .center_freq = 5540},
  1451. { .hw_value = 112, .center_freq = 5560},
  1452. { .hw_value = 116, .center_freq = 5580},
  1453. { .hw_value = 120, .center_freq = 5600},
  1454. { .hw_value = 124, .center_freq = 5620},
  1455. { .hw_value = 128, .center_freq = 5640},
  1456. { .hw_value = 132, .center_freq = 5660},
  1457. { .hw_value = 136, .center_freq = 5680},
  1458. { .hw_value = 140, .center_freq = 5700},
  1459. { .hw_value = 149, .center_freq = 5745},
  1460. { .hw_value = 153, .center_freq = 5765},
  1461. { .hw_value = 157, .center_freq = 5785},
  1462. { .hw_value = 161, .center_freq = 5805},
  1463. { .hw_value = 165, .center_freq = 5825},
  1464. };
  1465. static struct ieee80211_supported_band wl1271_band_5ghz = {
  1466. .channels = wl1271_channels_5ghz,
  1467. .n_channels = ARRAY_SIZE(wl1271_channels_5ghz),
  1468. .bitrates = wl1271_rates_5ghz,
  1469. .n_bitrates = ARRAY_SIZE(wl1271_rates_5ghz),
  1470. };
  1471. static const struct ieee80211_ops wl1271_ops = {
  1472. .start = wl1271_op_start,
  1473. .stop = wl1271_op_stop,
  1474. .add_interface = wl1271_op_add_interface,
  1475. .remove_interface = wl1271_op_remove_interface,
  1476. .config = wl1271_op_config,
  1477. /* .config_interface = wl1271_op_config_interface, */
  1478. .prepare_multicast = wl1271_op_prepare_multicast,
  1479. .configure_filter = wl1271_op_configure_filter,
  1480. .tx = wl1271_op_tx,
  1481. .set_key = wl1271_op_set_key,
  1482. .hw_scan = wl1271_op_hw_scan,
  1483. .bss_info_changed = wl1271_op_bss_info_changed,
  1484. .set_rts_threshold = wl1271_op_set_rts_threshold,
  1485. };
  1486. static int wl1271_register_hw(struct wl1271 *wl)
  1487. {
  1488. int ret;
  1489. if (wl->mac80211_registered)
  1490. return 0;
  1491. SET_IEEE80211_PERM_ADDR(wl->hw, wl->mac_addr);
  1492. ret = ieee80211_register_hw(wl->hw);
  1493. if (ret < 0) {
  1494. wl1271_error("unable to register mac80211 hw: %d", ret);
  1495. return ret;
  1496. }
  1497. wl->mac80211_registered = true;
  1498. wl1271_notice("loaded");
  1499. return 0;
  1500. }
  1501. static int wl1271_init_ieee80211(struct wl1271 *wl)
  1502. {
  1503. /* The tx descriptor buffer and the TKIP space. */
  1504. wl->hw->extra_tx_headroom = WL1271_TKIP_IV_SPACE +
  1505. sizeof(struct wl1271_tx_hw_descr);
  1506. /* unit us */
  1507. /* FIXME: find a proper value */
  1508. wl->hw->channel_change_time = 10000;
  1509. wl->hw->flags = IEEE80211_HW_SIGNAL_DBM |
  1510. IEEE80211_HW_NOISE_DBM |
  1511. IEEE80211_HW_BEACON_FILTER |
  1512. IEEE80211_HW_SUPPORTS_PS;
  1513. wl->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
  1514. wl->hw->wiphy->max_scan_ssids = 1;
  1515. wl->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &wl1271_band_2ghz;
  1516. if (wl1271_11a_enabled())
  1517. wl->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = &wl1271_band_5ghz;
  1518. SET_IEEE80211_DEV(wl->hw, &wl->spi->dev);
  1519. return 0;
  1520. }
  1521. static void wl1271_device_release(struct device *dev)
  1522. {
  1523. }
  1524. static struct platform_device wl1271_device = {
  1525. .name = "wl1271",
  1526. .id = -1,
  1527. /* device model insists to have a release function */
  1528. .dev = {
  1529. .release = wl1271_device_release,
  1530. },
  1531. };
  1532. #define WL1271_DEFAULT_CHANNEL 0
  1533. static int __devinit wl1271_probe(struct spi_device *spi)
  1534. {
  1535. struct wl12xx_platform_data *pdata;
  1536. struct ieee80211_hw *hw;
  1537. struct wl1271 *wl;
  1538. int ret, i;
  1539. static const u8 nokia_oui[3] = {0x00, 0x1f, 0xdf};
  1540. pdata = spi->dev.platform_data;
  1541. if (!pdata) {
  1542. wl1271_error("no platform data");
  1543. return -ENODEV;
  1544. }
  1545. hw = ieee80211_alloc_hw(sizeof(*wl), &wl1271_ops);
  1546. if (!hw) {
  1547. wl1271_error("could not alloc ieee80211_hw");
  1548. return -ENOMEM;
  1549. }
  1550. wl = hw->priv;
  1551. memset(wl, 0, sizeof(*wl));
  1552. INIT_LIST_HEAD(&wl->list);
  1553. wl->hw = hw;
  1554. dev_set_drvdata(&spi->dev, wl);
  1555. wl->spi = spi;
  1556. skb_queue_head_init(&wl->tx_queue);
  1557. INIT_DELAYED_WORK(&wl->elp_work, wl1271_elp_work);
  1558. wl->channel = WL1271_DEFAULT_CHANNEL;
  1559. wl->scanning = false;
  1560. wl->default_key = 0;
  1561. wl->rx_counter = 0;
  1562. wl->rx_config = WL1271_DEFAULT_RX_CONFIG;
  1563. wl->rx_filter = WL1271_DEFAULT_RX_FILTER;
  1564. wl->elp = false;
  1565. wl->psm = 0;
  1566. wl->psm_requested = false;
  1567. wl->psm_entry_retry = 0;
  1568. wl->tx_queue_stopped = false;
  1569. wl->power_level = WL1271_DEFAULT_POWER_LEVEL;
  1570. wl->basic_rate_set = CONF_TX_RATE_MASK_BASIC;
  1571. wl->band = IEEE80211_BAND_2GHZ;
  1572. wl->vif = NULL;
  1573. wl->joined = false;
  1574. wl->gpio_power = false;
  1575. for (i = 0; i < ACX_TX_DESCRIPTORS; i++)
  1576. wl->tx_frames[i] = NULL;
  1577. spin_lock_init(&wl->wl_lock);
  1578. /*
  1579. * In case our MAC address is not correctly set,
  1580. * we use a random but Nokia MAC.
  1581. */
  1582. memcpy(wl->mac_addr, nokia_oui, 3);
  1583. get_random_bytes(wl->mac_addr + 3, 3);
  1584. wl->state = WL1271_STATE_OFF;
  1585. mutex_init(&wl->mutex);
  1586. /* This is the only SPI value that we need to set here, the rest
  1587. * comes from the board-peripherals file */
  1588. spi->bits_per_word = 32;
  1589. ret = spi_setup(spi);
  1590. if (ret < 0) {
  1591. wl1271_error("spi_setup failed");
  1592. goto out_free;
  1593. }
  1594. wl->set_power = pdata->set_power;
  1595. if (!wl->set_power) {
  1596. wl1271_error("set power function missing in platform data");
  1597. ret = -ENODEV;
  1598. goto out_free;
  1599. }
  1600. wl->irq = spi->irq;
  1601. if (wl->irq < 0) {
  1602. wl1271_error("irq missing in platform data");
  1603. ret = -ENODEV;
  1604. goto out_free;
  1605. }
  1606. ret = request_irq(wl->irq, wl1271_irq, 0, DRIVER_NAME, wl);
  1607. if (ret < 0) {
  1608. wl1271_error("request_irq() failed: %d", ret);
  1609. goto out_free;
  1610. }
  1611. set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
  1612. disable_irq(wl->irq);
  1613. ret = platform_device_register(&wl1271_device);
  1614. if (ret) {
  1615. wl1271_error("couldn't register platform device");
  1616. goto out_irq;
  1617. }
  1618. dev_set_drvdata(&wl1271_device.dev, wl);
  1619. /* Apply default driver configuration. */
  1620. wl1271_conf_init(wl);
  1621. ret = wl1271_init_ieee80211(wl);
  1622. if (ret)
  1623. goto out_platform;
  1624. ret = wl1271_register_hw(wl);
  1625. if (ret)
  1626. goto out_platform;
  1627. wl1271_debugfs_init(wl);
  1628. wl1271_notice("initialized");
  1629. return 0;
  1630. out_platform:
  1631. platform_device_unregister(&wl1271_device);
  1632. out_irq:
  1633. free_irq(wl->irq, wl);
  1634. out_free:
  1635. ieee80211_free_hw(hw);
  1636. return ret;
  1637. }
  1638. static int __devexit wl1271_remove(struct spi_device *spi)
  1639. {
  1640. struct wl1271 *wl = dev_get_drvdata(&spi->dev);
  1641. ieee80211_unregister_hw(wl->hw);
  1642. wl1271_debugfs_exit(wl);
  1643. platform_device_unregister(&wl1271_device);
  1644. free_irq(wl->irq, wl);
  1645. kfree(wl->target_mem_map);
  1646. vfree(wl->fw);
  1647. wl->fw = NULL;
  1648. kfree(wl->nvs);
  1649. wl->nvs = NULL;
  1650. kfree(wl->fw_status);
  1651. kfree(wl->tx_res_if);
  1652. ieee80211_free_hw(wl->hw);
  1653. return 0;
  1654. }
  1655. static struct spi_driver wl1271_spi_driver = {
  1656. .driver = {
  1657. .name = "wl1271",
  1658. .bus = &spi_bus_type,
  1659. .owner = THIS_MODULE,
  1660. },
  1661. .probe = wl1271_probe,
  1662. .remove = __devexit_p(wl1271_remove),
  1663. };
  1664. static int __init wl1271_init(void)
  1665. {
  1666. int ret;
  1667. ret = spi_register_driver(&wl1271_spi_driver);
  1668. if (ret < 0) {
  1669. wl1271_error("failed to register spi driver: %d", ret);
  1670. goto out;
  1671. }
  1672. out:
  1673. return ret;
  1674. }
  1675. static void __exit wl1271_exit(void)
  1676. {
  1677. spi_unregister_driver(&wl1271_spi_driver);
  1678. wl1271_notice("unloaded");
  1679. }
  1680. module_init(wl1271_init);
  1681. module_exit(wl1271_exit);
  1682. MODULE_LICENSE("GPL");
  1683. MODULE_AUTHOR("Luciano Coelho <luciano.coelho@nokia.com>");
  1684. MODULE_AUTHOR("Juuso Oikarinen <juuso.oikarinen@nokia.com>");
  1685. MODULE_FIRMWARE(WL1271_FW_NAME);