wl1271_main.c 48 KB

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