wl1271_main.c 48 KB

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