main.c 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926
  1. /*
  2. * This file is part of wl18xx
  3. *
  4. * Copyright (C) 2011 Texas Instruments
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * version 2 as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  18. * 02110-1301 USA
  19. *
  20. */
  21. #include <linux/module.h>
  22. #include <linux/platform_device.h>
  23. #include <linux/ip.h>
  24. #include <linux/firmware.h>
  25. #include <linux/etherdevice.h>
  26. #include "../wlcore/wlcore.h"
  27. #include "../wlcore/debug.h"
  28. #include "../wlcore/io.h"
  29. #include "../wlcore/acx.h"
  30. #include "../wlcore/tx.h"
  31. #include "../wlcore/rx.h"
  32. #include "../wlcore/boot.h"
  33. #include "reg.h"
  34. #include "conf.h"
  35. #include "cmd.h"
  36. #include "acx.h"
  37. #include "tx.h"
  38. #include "wl18xx.h"
  39. #include "io.h"
  40. #include "scan.h"
  41. #include "event.h"
  42. #include "debugfs.h"
  43. #define WL18XX_RX_CHECKSUM_MASK 0x40
  44. static char *ht_mode_param = NULL;
  45. static char *board_type_param = NULL;
  46. static bool checksum_param = false;
  47. static int num_rx_desc_param = -1;
  48. /* phy paramters */
  49. static int dc2dc_param = -1;
  50. static int n_antennas_2_param = -1;
  51. static int n_antennas_5_param = -1;
  52. static int low_band_component_param = -1;
  53. static int low_band_component_type_param = -1;
  54. static int high_band_component_param = -1;
  55. static int high_band_component_type_param = -1;
  56. static int pwr_limit_reference_11_abg_param = -1;
  57. static const u8 wl18xx_rate_to_idx_2ghz[] = {
  58. /* MCS rates are used only with 11n */
  59. 15, /* WL18XX_CONF_HW_RXTX_RATE_MCS15 */
  60. 14, /* WL18XX_CONF_HW_RXTX_RATE_MCS14 */
  61. 13, /* WL18XX_CONF_HW_RXTX_RATE_MCS13 */
  62. 12, /* WL18XX_CONF_HW_RXTX_RATE_MCS12 */
  63. 11, /* WL18XX_CONF_HW_RXTX_RATE_MCS11 */
  64. 10, /* WL18XX_CONF_HW_RXTX_RATE_MCS10 */
  65. 9, /* WL18XX_CONF_HW_RXTX_RATE_MCS9 */
  66. 8, /* WL18XX_CONF_HW_RXTX_RATE_MCS8 */
  67. 7, /* WL18XX_CONF_HW_RXTX_RATE_MCS7 */
  68. 6, /* WL18XX_CONF_HW_RXTX_RATE_MCS6 */
  69. 5, /* WL18XX_CONF_HW_RXTX_RATE_MCS5 */
  70. 4, /* WL18XX_CONF_HW_RXTX_RATE_MCS4 */
  71. 3, /* WL18XX_CONF_HW_RXTX_RATE_MCS3 */
  72. 2, /* WL18XX_CONF_HW_RXTX_RATE_MCS2 */
  73. 1, /* WL18XX_CONF_HW_RXTX_RATE_MCS1 */
  74. 0, /* WL18XX_CONF_HW_RXTX_RATE_MCS0 */
  75. 11, /* WL18XX_CONF_HW_RXTX_RATE_54 */
  76. 10, /* WL18XX_CONF_HW_RXTX_RATE_48 */
  77. 9, /* WL18XX_CONF_HW_RXTX_RATE_36 */
  78. 8, /* WL18XX_CONF_HW_RXTX_RATE_24 */
  79. /* TI-specific rate */
  80. CONF_HW_RXTX_RATE_UNSUPPORTED, /* WL18XX_CONF_HW_RXTX_RATE_22 */
  81. 7, /* WL18XX_CONF_HW_RXTX_RATE_18 */
  82. 6, /* WL18XX_CONF_HW_RXTX_RATE_12 */
  83. 3, /* WL18XX_CONF_HW_RXTX_RATE_11 */
  84. 5, /* WL18XX_CONF_HW_RXTX_RATE_9 */
  85. 4, /* WL18XX_CONF_HW_RXTX_RATE_6 */
  86. 2, /* WL18XX_CONF_HW_RXTX_RATE_5_5 */
  87. 1, /* WL18XX_CONF_HW_RXTX_RATE_2 */
  88. 0 /* WL18XX_CONF_HW_RXTX_RATE_1 */
  89. };
  90. static const u8 wl18xx_rate_to_idx_5ghz[] = {
  91. /* MCS rates are used only with 11n */
  92. 15, /* WL18XX_CONF_HW_RXTX_RATE_MCS15 */
  93. 14, /* WL18XX_CONF_HW_RXTX_RATE_MCS14 */
  94. 13, /* WL18XX_CONF_HW_RXTX_RATE_MCS13 */
  95. 12, /* WL18XX_CONF_HW_RXTX_RATE_MCS12 */
  96. 11, /* WL18XX_CONF_HW_RXTX_RATE_MCS11 */
  97. 10, /* WL18XX_CONF_HW_RXTX_RATE_MCS10 */
  98. 9, /* WL18XX_CONF_HW_RXTX_RATE_MCS9 */
  99. 8, /* WL18XX_CONF_HW_RXTX_RATE_MCS8 */
  100. 7, /* WL18XX_CONF_HW_RXTX_RATE_MCS7 */
  101. 6, /* WL18XX_CONF_HW_RXTX_RATE_MCS6 */
  102. 5, /* WL18XX_CONF_HW_RXTX_RATE_MCS5 */
  103. 4, /* WL18XX_CONF_HW_RXTX_RATE_MCS4 */
  104. 3, /* WL18XX_CONF_HW_RXTX_RATE_MCS3 */
  105. 2, /* WL18XX_CONF_HW_RXTX_RATE_MCS2 */
  106. 1, /* WL18XX_CONF_HW_RXTX_RATE_MCS1 */
  107. 0, /* WL18XX_CONF_HW_RXTX_RATE_MCS0 */
  108. 7, /* WL18XX_CONF_HW_RXTX_RATE_54 */
  109. 6, /* WL18XX_CONF_HW_RXTX_RATE_48 */
  110. 5, /* WL18XX_CONF_HW_RXTX_RATE_36 */
  111. 4, /* WL18XX_CONF_HW_RXTX_RATE_24 */
  112. /* TI-specific rate */
  113. CONF_HW_RXTX_RATE_UNSUPPORTED, /* WL18XX_CONF_HW_RXTX_RATE_22 */
  114. 3, /* WL18XX_CONF_HW_RXTX_RATE_18 */
  115. 2, /* WL18XX_CONF_HW_RXTX_RATE_12 */
  116. CONF_HW_RXTX_RATE_UNSUPPORTED, /* WL18XX_CONF_HW_RXTX_RATE_11 */
  117. 1, /* WL18XX_CONF_HW_RXTX_RATE_9 */
  118. 0, /* WL18XX_CONF_HW_RXTX_RATE_6 */
  119. CONF_HW_RXTX_RATE_UNSUPPORTED, /* WL18XX_CONF_HW_RXTX_RATE_5_5 */
  120. CONF_HW_RXTX_RATE_UNSUPPORTED, /* WL18XX_CONF_HW_RXTX_RATE_2 */
  121. CONF_HW_RXTX_RATE_UNSUPPORTED, /* WL18XX_CONF_HW_RXTX_RATE_1 */
  122. };
  123. static const u8 *wl18xx_band_rate_to_idx[] = {
  124. [IEEE80211_BAND_2GHZ] = wl18xx_rate_to_idx_2ghz,
  125. [IEEE80211_BAND_5GHZ] = wl18xx_rate_to_idx_5ghz
  126. };
  127. enum wl18xx_hw_rates {
  128. WL18XX_CONF_HW_RXTX_RATE_MCS15 = 0,
  129. WL18XX_CONF_HW_RXTX_RATE_MCS14,
  130. WL18XX_CONF_HW_RXTX_RATE_MCS13,
  131. WL18XX_CONF_HW_RXTX_RATE_MCS12,
  132. WL18XX_CONF_HW_RXTX_RATE_MCS11,
  133. WL18XX_CONF_HW_RXTX_RATE_MCS10,
  134. WL18XX_CONF_HW_RXTX_RATE_MCS9,
  135. WL18XX_CONF_HW_RXTX_RATE_MCS8,
  136. WL18XX_CONF_HW_RXTX_RATE_MCS7,
  137. WL18XX_CONF_HW_RXTX_RATE_MCS6,
  138. WL18XX_CONF_HW_RXTX_RATE_MCS5,
  139. WL18XX_CONF_HW_RXTX_RATE_MCS4,
  140. WL18XX_CONF_HW_RXTX_RATE_MCS3,
  141. WL18XX_CONF_HW_RXTX_RATE_MCS2,
  142. WL18XX_CONF_HW_RXTX_RATE_MCS1,
  143. WL18XX_CONF_HW_RXTX_RATE_MCS0,
  144. WL18XX_CONF_HW_RXTX_RATE_54,
  145. WL18XX_CONF_HW_RXTX_RATE_48,
  146. WL18XX_CONF_HW_RXTX_RATE_36,
  147. WL18XX_CONF_HW_RXTX_RATE_24,
  148. WL18XX_CONF_HW_RXTX_RATE_22,
  149. WL18XX_CONF_HW_RXTX_RATE_18,
  150. WL18XX_CONF_HW_RXTX_RATE_12,
  151. WL18XX_CONF_HW_RXTX_RATE_11,
  152. WL18XX_CONF_HW_RXTX_RATE_9,
  153. WL18XX_CONF_HW_RXTX_RATE_6,
  154. WL18XX_CONF_HW_RXTX_RATE_5_5,
  155. WL18XX_CONF_HW_RXTX_RATE_2,
  156. WL18XX_CONF_HW_RXTX_RATE_1,
  157. WL18XX_CONF_HW_RXTX_RATE_MAX,
  158. };
  159. static struct wlcore_conf wl18xx_conf = {
  160. .sg = {
  161. .params = {
  162. [CONF_SG_ACL_BT_MASTER_MIN_BR] = 10,
  163. [CONF_SG_ACL_BT_MASTER_MAX_BR] = 180,
  164. [CONF_SG_ACL_BT_SLAVE_MIN_BR] = 10,
  165. [CONF_SG_ACL_BT_SLAVE_MAX_BR] = 180,
  166. [CONF_SG_ACL_BT_MASTER_MIN_EDR] = 10,
  167. [CONF_SG_ACL_BT_MASTER_MAX_EDR] = 80,
  168. [CONF_SG_ACL_BT_SLAVE_MIN_EDR] = 10,
  169. [CONF_SG_ACL_BT_SLAVE_MAX_EDR] = 80,
  170. [CONF_SG_ACL_WLAN_PS_MASTER_BR] = 8,
  171. [CONF_SG_ACL_WLAN_PS_SLAVE_BR] = 8,
  172. [CONF_SG_ACL_WLAN_PS_MASTER_EDR] = 20,
  173. [CONF_SG_ACL_WLAN_PS_SLAVE_EDR] = 20,
  174. [CONF_SG_ACL_WLAN_ACTIVE_MASTER_MIN_BR] = 20,
  175. [CONF_SG_ACL_WLAN_ACTIVE_MASTER_MAX_BR] = 35,
  176. [CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MIN_BR] = 16,
  177. [CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MAX_BR] = 35,
  178. [CONF_SG_ACL_WLAN_ACTIVE_MASTER_MIN_EDR] = 32,
  179. [CONF_SG_ACL_WLAN_ACTIVE_MASTER_MAX_EDR] = 50,
  180. [CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MIN_EDR] = 28,
  181. [CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MAX_EDR] = 50,
  182. [CONF_SG_ACL_ACTIVE_SCAN_WLAN_BR] = 10,
  183. [CONF_SG_ACL_ACTIVE_SCAN_WLAN_EDR] = 20,
  184. [CONF_SG_ACL_PASSIVE_SCAN_BT_BR] = 75,
  185. [CONF_SG_ACL_PASSIVE_SCAN_WLAN_BR] = 15,
  186. [CONF_SG_ACL_PASSIVE_SCAN_BT_EDR] = 27,
  187. [CONF_SG_ACL_PASSIVE_SCAN_WLAN_EDR] = 17,
  188. /* active scan params */
  189. [CONF_SG_AUTO_SCAN_PROBE_REQ] = 170,
  190. [CONF_SG_ACTIVE_SCAN_DURATION_FACTOR_HV3] = 50,
  191. [CONF_SG_ACTIVE_SCAN_DURATION_FACTOR_A2DP] = 100,
  192. /* passive scan params */
  193. [CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_A2DP_BR] = 800,
  194. [CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_A2DP_EDR] = 200,
  195. [CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_HV3] = 200,
  196. /* passive scan in dual antenna params */
  197. [CONF_SG_CONSECUTIVE_HV3_IN_PASSIVE_SCAN] = 0,
  198. [CONF_SG_BCN_HV3_COLLISION_THRESH_IN_PASSIVE_SCAN] = 0,
  199. [CONF_SG_TX_RX_PROTECTION_BWIDTH_IN_PASSIVE_SCAN] = 0,
  200. /* general params */
  201. [CONF_SG_STA_FORCE_PS_IN_BT_SCO] = 1,
  202. [CONF_SG_ANTENNA_CONFIGURATION] = 0,
  203. [CONF_SG_BEACON_MISS_PERCENT] = 60,
  204. [CONF_SG_DHCP_TIME] = 5000,
  205. [CONF_SG_RXT] = 1200,
  206. [CONF_SG_TXT] = 1000,
  207. [CONF_SG_ADAPTIVE_RXT_TXT] = 1,
  208. [CONF_SG_GENERAL_USAGE_BIT_MAP] = 3,
  209. [CONF_SG_HV3_MAX_SERVED] = 6,
  210. [CONF_SG_PS_POLL_TIMEOUT] = 10,
  211. [CONF_SG_UPSD_TIMEOUT] = 10,
  212. [CONF_SG_CONSECUTIVE_CTS_THRESHOLD] = 2,
  213. [CONF_SG_STA_RX_WINDOW_AFTER_DTIM] = 5,
  214. [CONF_SG_STA_CONNECTION_PROTECTION_TIME] = 30,
  215. /* AP params */
  216. [CONF_AP_BEACON_MISS_TX] = 3,
  217. [CONF_AP_RX_WINDOW_AFTER_BEACON] = 10,
  218. [CONF_AP_BEACON_WINDOW_INTERVAL] = 2,
  219. [CONF_AP_CONNECTION_PROTECTION_TIME] = 0,
  220. [CONF_AP_BT_ACL_VAL_BT_SERVE_TIME] = 25,
  221. [CONF_AP_BT_ACL_VAL_WL_SERVE_TIME] = 25,
  222. /* CTS Diluting params */
  223. [CONF_SG_CTS_DILUTED_BAD_RX_PACKETS_TH] = 0,
  224. [CONF_SG_CTS_CHOP_IN_DUAL_ANT_SCO_MASTER] = 0,
  225. },
  226. .state = CONF_SG_PROTECTIVE,
  227. },
  228. .rx = {
  229. .rx_msdu_life_time = 512000,
  230. .packet_detection_threshold = 0,
  231. .ps_poll_timeout = 15,
  232. .upsd_timeout = 15,
  233. .rts_threshold = IEEE80211_MAX_RTS_THRESHOLD,
  234. .rx_cca_threshold = 0,
  235. .irq_blk_threshold = 0xFFFF,
  236. .irq_pkt_threshold = 0,
  237. .irq_timeout = 600,
  238. .queue_type = CONF_RX_QUEUE_TYPE_LOW_PRIORITY,
  239. },
  240. .tx = {
  241. .tx_energy_detection = 0,
  242. .sta_rc_conf = {
  243. .enabled_rates = 0,
  244. .short_retry_limit = 10,
  245. .long_retry_limit = 10,
  246. .aflags = 0,
  247. },
  248. .ac_conf_count = 4,
  249. .ac_conf = {
  250. [CONF_TX_AC_BE] = {
  251. .ac = CONF_TX_AC_BE,
  252. .cw_min = 15,
  253. .cw_max = 63,
  254. .aifsn = 3,
  255. .tx_op_limit = 0,
  256. },
  257. [CONF_TX_AC_BK] = {
  258. .ac = CONF_TX_AC_BK,
  259. .cw_min = 15,
  260. .cw_max = 63,
  261. .aifsn = 7,
  262. .tx_op_limit = 0,
  263. },
  264. [CONF_TX_AC_VI] = {
  265. .ac = CONF_TX_AC_VI,
  266. .cw_min = 15,
  267. .cw_max = 63,
  268. .aifsn = CONF_TX_AIFS_PIFS,
  269. .tx_op_limit = 3008,
  270. },
  271. [CONF_TX_AC_VO] = {
  272. .ac = CONF_TX_AC_VO,
  273. .cw_min = 15,
  274. .cw_max = 63,
  275. .aifsn = CONF_TX_AIFS_PIFS,
  276. .tx_op_limit = 1504,
  277. },
  278. },
  279. .max_tx_retries = 100,
  280. .ap_aging_period = 300,
  281. .tid_conf_count = 4,
  282. .tid_conf = {
  283. [CONF_TX_AC_BE] = {
  284. .queue_id = CONF_TX_AC_BE,
  285. .channel_type = CONF_CHANNEL_TYPE_EDCF,
  286. .tsid = CONF_TX_AC_BE,
  287. .ps_scheme = CONF_PS_SCHEME_LEGACY,
  288. .ack_policy = CONF_ACK_POLICY_LEGACY,
  289. .apsd_conf = {0, 0},
  290. },
  291. [CONF_TX_AC_BK] = {
  292. .queue_id = CONF_TX_AC_BK,
  293. .channel_type = CONF_CHANNEL_TYPE_EDCF,
  294. .tsid = CONF_TX_AC_BK,
  295. .ps_scheme = CONF_PS_SCHEME_LEGACY,
  296. .ack_policy = CONF_ACK_POLICY_LEGACY,
  297. .apsd_conf = {0, 0},
  298. },
  299. [CONF_TX_AC_VI] = {
  300. .queue_id = CONF_TX_AC_VI,
  301. .channel_type = CONF_CHANNEL_TYPE_EDCF,
  302. .tsid = CONF_TX_AC_VI,
  303. .ps_scheme = CONF_PS_SCHEME_LEGACY,
  304. .ack_policy = CONF_ACK_POLICY_LEGACY,
  305. .apsd_conf = {0, 0},
  306. },
  307. [CONF_TX_AC_VO] = {
  308. .queue_id = CONF_TX_AC_VO,
  309. .channel_type = CONF_CHANNEL_TYPE_EDCF,
  310. .tsid = CONF_TX_AC_VO,
  311. .ps_scheme = CONF_PS_SCHEME_LEGACY,
  312. .ack_policy = CONF_ACK_POLICY_LEGACY,
  313. .apsd_conf = {0, 0},
  314. },
  315. },
  316. .frag_threshold = IEEE80211_MAX_FRAG_THRESHOLD,
  317. .tx_compl_timeout = 350,
  318. .tx_compl_threshold = 10,
  319. .basic_rate = CONF_HW_BIT_RATE_1MBPS,
  320. .basic_rate_5 = CONF_HW_BIT_RATE_6MBPS,
  321. .tmpl_short_retry_limit = 10,
  322. .tmpl_long_retry_limit = 10,
  323. .tx_watchdog_timeout = 5000,
  324. .slow_link_thold = 3,
  325. .fast_link_thold = 30,
  326. },
  327. .conn = {
  328. .wake_up_event = CONF_WAKE_UP_EVENT_DTIM,
  329. .listen_interval = 1,
  330. .suspend_wake_up_event = CONF_WAKE_UP_EVENT_N_DTIM,
  331. .suspend_listen_interval = 3,
  332. .bcn_filt_mode = CONF_BCN_FILT_MODE_ENABLED,
  333. .bcn_filt_ie_count = 3,
  334. .bcn_filt_ie = {
  335. [0] = {
  336. .ie = WLAN_EID_CHANNEL_SWITCH,
  337. .rule = CONF_BCN_RULE_PASS_ON_APPEARANCE,
  338. },
  339. [1] = {
  340. .ie = WLAN_EID_HT_OPERATION,
  341. .rule = CONF_BCN_RULE_PASS_ON_CHANGE,
  342. },
  343. [2] = {
  344. .ie = WLAN_EID_ERP_INFO,
  345. .rule = CONF_BCN_RULE_PASS_ON_CHANGE,
  346. },
  347. },
  348. .synch_fail_thold = 12,
  349. .bss_lose_timeout = 400,
  350. .beacon_rx_timeout = 10000,
  351. .broadcast_timeout = 20000,
  352. .rx_broadcast_in_ps = 1,
  353. .ps_poll_threshold = 10,
  354. .bet_enable = CONF_BET_MODE_ENABLE,
  355. .bet_max_consecutive = 50,
  356. .psm_entry_retries = 8,
  357. .psm_exit_retries = 16,
  358. .psm_entry_nullfunc_retries = 3,
  359. .dynamic_ps_timeout = 1500,
  360. .forced_ps = false,
  361. .keep_alive_interval = 55000,
  362. .max_listen_interval = 20,
  363. .sta_sleep_auth = WL1271_PSM_ILLEGAL,
  364. },
  365. .itrim = {
  366. .enable = false,
  367. .timeout = 50000,
  368. },
  369. .pm_config = {
  370. .host_clk_settling_time = 5000,
  371. .host_fast_wakeup_support = CONF_FAST_WAKEUP_DISABLE,
  372. },
  373. .roam_trigger = {
  374. .trigger_pacing = 1,
  375. .avg_weight_rssi_beacon = 20,
  376. .avg_weight_rssi_data = 10,
  377. .avg_weight_snr_beacon = 20,
  378. .avg_weight_snr_data = 10,
  379. },
  380. .scan = {
  381. .min_dwell_time_active = 7500,
  382. .max_dwell_time_active = 30000,
  383. .min_dwell_time_active_long = 25000,
  384. .max_dwell_time_active_long = 50000,
  385. .dwell_time_passive = 100000,
  386. .dwell_time_dfs = 150000,
  387. .num_probe_reqs = 2,
  388. .split_scan_timeout = 50000,
  389. },
  390. .sched_scan = {
  391. /*
  392. * Values are in TU/1000 but since sched scan FW command
  393. * params are in TUs rounding up may occur.
  394. */
  395. .base_dwell_time = 7500,
  396. .max_dwell_time_delta = 22500,
  397. /* based on 250bits per probe @1Mbps */
  398. .dwell_time_delta_per_probe = 2000,
  399. /* based on 250bits per probe @6Mbps (plus a bit more) */
  400. .dwell_time_delta_per_probe_5 = 350,
  401. .dwell_time_passive = 100000,
  402. .dwell_time_dfs = 150000,
  403. .num_probe_reqs = 2,
  404. .rssi_threshold = -90,
  405. .snr_threshold = 0,
  406. },
  407. .ht = {
  408. .rx_ba_win_size = 32,
  409. .tx_ba_win_size = 64,
  410. .inactivity_timeout = 10000,
  411. .tx_ba_tid_bitmap = CONF_TX_BA_ENABLED_TID_BITMAP,
  412. },
  413. .mem = {
  414. .num_stations = 1,
  415. .ssid_profiles = 1,
  416. .rx_block_num = 40,
  417. .tx_min_block_num = 40,
  418. .dynamic_memory = 1,
  419. .min_req_tx_blocks = 45,
  420. .min_req_rx_blocks = 22,
  421. .tx_min = 27,
  422. },
  423. .fm_coex = {
  424. .enable = true,
  425. .swallow_period = 5,
  426. .n_divider_fref_set_1 = 0xff, /* default */
  427. .n_divider_fref_set_2 = 12,
  428. .m_divider_fref_set_1 = 0xffff,
  429. .m_divider_fref_set_2 = 148, /* default */
  430. .coex_pll_stabilization_time = 0xffffffff, /* default */
  431. .ldo_stabilization_time = 0xffff, /* default */
  432. .fm_disturbed_band_margin = 0xff, /* default */
  433. .swallow_clk_diff = 0xff, /* default */
  434. },
  435. .rx_streaming = {
  436. .duration = 150,
  437. .queues = 0x1,
  438. .interval = 20,
  439. .always = 0,
  440. },
  441. .fwlog = {
  442. .mode = WL12XX_FWLOG_ON_DEMAND,
  443. .mem_blocks = 2,
  444. .severity = 0,
  445. .timestamp = WL12XX_FWLOG_TIMESTAMP_DISABLED,
  446. .output = WL12XX_FWLOG_OUTPUT_HOST,
  447. .threshold = 0,
  448. },
  449. .rate = {
  450. .rate_retry_score = 32000,
  451. .per_add = 8192,
  452. .per_th1 = 2048,
  453. .per_th2 = 4096,
  454. .max_per = 8100,
  455. .inverse_curiosity_factor = 5,
  456. .tx_fail_low_th = 4,
  457. .tx_fail_high_th = 10,
  458. .per_alpha_shift = 4,
  459. .per_add_shift = 13,
  460. .per_beta1_shift = 10,
  461. .per_beta2_shift = 8,
  462. .rate_check_up = 2,
  463. .rate_check_down = 12,
  464. .rate_retry_policy = {
  465. 0x00, 0x00, 0x00, 0x00, 0x00,
  466. 0x00, 0x00, 0x00, 0x00, 0x00,
  467. 0x00, 0x00, 0x00,
  468. },
  469. },
  470. .hangover = {
  471. .recover_time = 0,
  472. .hangover_period = 20,
  473. .dynamic_mode = 1,
  474. .early_termination_mode = 1,
  475. .max_period = 20,
  476. .min_period = 1,
  477. .increase_delta = 1,
  478. .decrease_delta = 2,
  479. .quiet_time = 4,
  480. .increase_time = 1,
  481. .window_size = 16,
  482. },
  483. .recovery = {
  484. .bug_on_recovery = 0,
  485. .no_recovery = 0,
  486. },
  487. };
  488. static struct wl18xx_priv_conf wl18xx_default_priv_conf = {
  489. .ht = {
  490. .mode = HT_MODE_DEFAULT,
  491. },
  492. .phy = {
  493. .phy_standalone = 0x00,
  494. .primary_clock_setting_time = 0x05,
  495. .clock_valid_on_wake_up = 0x00,
  496. .secondary_clock_setting_time = 0x05,
  497. .board_type = BOARD_TYPE_HDK_18XX,
  498. .auto_detect = 0x00,
  499. .dedicated_fem = FEM_NONE,
  500. .low_band_component = COMPONENT_3_WAY_SWITCH,
  501. .low_band_component_type = 0x04,
  502. .high_band_component = COMPONENT_2_WAY_SWITCH,
  503. .high_band_component_type = 0x09,
  504. .tcxo_ldo_voltage = 0x00,
  505. .xtal_itrim_val = 0x04,
  506. .srf_state = 0x00,
  507. .io_configuration = 0x01,
  508. .sdio_configuration = 0x00,
  509. .settings = 0x00,
  510. .enable_clpc = 0x00,
  511. .enable_tx_low_pwr_on_siso_rdl = 0x00,
  512. .rx_profile = 0x00,
  513. .pwr_limit_reference_11_abg = 0x64,
  514. .per_chan_pwr_limit_arr_11abg = {
  515. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  516. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  517. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  518. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  519. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  520. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  521. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  522. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  523. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  524. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  525. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  526. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  527. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  528. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  529. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  530. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  531. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
  532. .pwr_limit_reference_11p = 0x64,
  533. .per_chan_bo_mode_11_abg = { 0x00, 0x00, 0x00, 0x00,
  534. 0x00, 0x00, 0x00, 0x00,
  535. 0x00, 0x00, 0x00, 0x00,
  536. 0x00 },
  537. .per_chan_bo_mode_11_p = { 0x00, 0x00, 0x00, 0x00 },
  538. .per_chan_pwr_limit_arr_11p = { 0xff, 0xff, 0xff, 0xff,
  539. 0xff, 0xff, 0xff },
  540. .psat = 0,
  541. .low_power_val = 0x08,
  542. .med_power_val = 0x12,
  543. .high_power_val = 0x18,
  544. .low_power_val_2nd = 0x05,
  545. .med_power_val_2nd = 0x0a,
  546. .high_power_val_2nd = 0x14,
  547. .external_pa_dc2dc = 0,
  548. .number_of_assembled_ant2_4 = 2,
  549. .number_of_assembled_ant5 = 1,
  550. .tx_rf_margin = 1,
  551. },
  552. };
  553. static const struct wlcore_partition_set wl18xx_ptable[PART_TABLE_LEN] = {
  554. [PART_TOP_PRCM_ELP_SOC] = {
  555. .mem = { .start = 0x00A02000, .size = 0x00010000 },
  556. .reg = { .start = 0x00807000, .size = 0x00005000 },
  557. .mem2 = { .start = 0x00800000, .size = 0x0000B000 },
  558. .mem3 = { .start = 0x00000000, .size = 0x00000000 },
  559. },
  560. [PART_DOWN] = {
  561. .mem = { .start = 0x00000000, .size = 0x00014000 },
  562. .reg = { .start = 0x00810000, .size = 0x0000BFFF },
  563. .mem2 = { .start = 0x00000000, .size = 0x00000000 },
  564. .mem3 = { .start = 0x00000000, .size = 0x00000000 },
  565. },
  566. [PART_BOOT] = {
  567. .mem = { .start = 0x00700000, .size = 0x0000030c },
  568. .reg = { .start = 0x00802000, .size = 0x00014578 },
  569. .mem2 = { .start = 0x00B00404, .size = 0x00001000 },
  570. .mem3 = { .start = 0x00C00000, .size = 0x00000400 },
  571. },
  572. [PART_WORK] = {
  573. .mem = { .start = 0x00800000, .size = 0x000050FC },
  574. .reg = { .start = 0x00B00404, .size = 0x00001000 },
  575. .mem2 = { .start = 0x00C00000, .size = 0x00000400 },
  576. .mem3 = { .start = 0x00000000, .size = 0x00000000 },
  577. },
  578. [PART_PHY_INIT] = {
  579. .mem = { .start = WL18XX_PHY_INIT_MEM_ADDR,
  580. .size = WL18XX_PHY_INIT_MEM_SIZE },
  581. .reg = { .start = 0x00000000, .size = 0x00000000 },
  582. .mem2 = { .start = 0x00000000, .size = 0x00000000 },
  583. .mem3 = { .start = 0x00000000, .size = 0x00000000 },
  584. },
  585. };
  586. static const int wl18xx_rtable[REG_TABLE_LEN] = {
  587. [REG_ECPU_CONTROL] = WL18XX_REG_ECPU_CONTROL,
  588. [REG_INTERRUPT_NO_CLEAR] = WL18XX_REG_INTERRUPT_NO_CLEAR,
  589. [REG_INTERRUPT_ACK] = WL18XX_REG_INTERRUPT_ACK,
  590. [REG_COMMAND_MAILBOX_PTR] = WL18XX_REG_COMMAND_MAILBOX_PTR,
  591. [REG_EVENT_MAILBOX_PTR] = WL18XX_REG_EVENT_MAILBOX_PTR,
  592. [REG_INTERRUPT_TRIG] = WL18XX_REG_INTERRUPT_TRIG_H,
  593. [REG_INTERRUPT_MASK] = WL18XX_REG_INTERRUPT_MASK,
  594. [REG_PC_ON_RECOVERY] = WL18XX_SCR_PAD4,
  595. [REG_CHIP_ID_B] = WL18XX_REG_CHIP_ID_B,
  596. [REG_CMD_MBOX_ADDRESS] = WL18XX_CMD_MBOX_ADDRESS,
  597. /* data access memory addresses, used with partition translation */
  598. [REG_SLV_MEM_DATA] = WL18XX_SLV_MEM_DATA,
  599. [REG_SLV_REG_DATA] = WL18XX_SLV_REG_DATA,
  600. /* raw data access memory addresses */
  601. [REG_RAW_FW_STATUS_ADDR] = WL18XX_FW_STATUS_ADDR,
  602. };
  603. static const struct wl18xx_clk_cfg wl18xx_clk_table_coex[NUM_CLOCK_CONFIGS] = {
  604. [CLOCK_CONFIG_16_2_M] = { 8, 121, 0, 0, false },
  605. [CLOCK_CONFIG_16_368_M] = { 8, 120, 0, 0, false },
  606. [CLOCK_CONFIG_16_8_M] = { 8, 117, 0, 0, false },
  607. [CLOCK_CONFIG_19_2_M] = { 10, 128, 0, 0, false },
  608. [CLOCK_CONFIG_26_M] = { 11, 104, 0, 0, false },
  609. [CLOCK_CONFIG_32_736_M] = { 8, 120, 0, 0, false },
  610. [CLOCK_CONFIG_33_6_M] = { 8, 117, 0, 0, false },
  611. [CLOCK_CONFIG_38_468_M] = { 10, 128, 0, 0, false },
  612. [CLOCK_CONFIG_52_M] = { 11, 104, 0, 0, false },
  613. };
  614. static const struct wl18xx_clk_cfg wl18xx_clk_table[NUM_CLOCK_CONFIGS] = {
  615. [CLOCK_CONFIG_16_2_M] = { 7, 104, 801, 4, true },
  616. [CLOCK_CONFIG_16_368_M] = { 9, 132, 3751, 4, true },
  617. [CLOCK_CONFIG_16_8_M] = { 7, 100, 0, 0, false },
  618. [CLOCK_CONFIG_19_2_M] = { 8, 100, 0, 0, false },
  619. [CLOCK_CONFIG_26_M] = { 13, 120, 0, 0, false },
  620. [CLOCK_CONFIG_32_736_M] = { 9, 132, 3751, 4, true },
  621. [CLOCK_CONFIG_33_6_M] = { 7, 100, 0, 0, false },
  622. [CLOCK_CONFIG_38_468_M] = { 8, 100, 0, 0, false },
  623. [CLOCK_CONFIG_52_M] = { 13, 120, 0, 0, false },
  624. };
  625. /* TODO: maybe move to a new header file? */
  626. #define WL18XX_FW_NAME "ti-connectivity/wl18xx-fw-2.bin"
  627. static int wl18xx_identify_chip(struct wl1271 *wl)
  628. {
  629. int ret = 0;
  630. switch (wl->chip.id) {
  631. case CHIP_ID_185x_PG20:
  632. wl1271_debug(DEBUG_BOOT, "chip id 0x%x (185x PG20)",
  633. wl->chip.id);
  634. wl->sr_fw_name = WL18XX_FW_NAME;
  635. /* wl18xx uses the same firmware for PLT */
  636. wl->plt_fw_name = WL18XX_FW_NAME;
  637. wl->quirks |= WLCORE_QUIRK_RX_BLOCKSIZE_ALIGN |
  638. WLCORE_QUIRK_TX_BLOCKSIZE_ALIGN |
  639. WLCORE_QUIRK_NO_SCHED_SCAN_WHILE_CONN |
  640. WLCORE_QUIRK_TX_PAD_LAST_FRAME |
  641. WLCORE_QUIRK_REGDOMAIN_CONF |
  642. WLCORE_QUIRK_DUAL_PROBE_TMPL;
  643. wlcore_set_min_fw_ver(wl, WL18XX_CHIP_VER,
  644. WL18XX_IFTYPE_VER, WL18XX_MAJOR_VER,
  645. WL18XX_SUBTYPE_VER, WL18XX_MINOR_VER,
  646. /* there's no separate multi-role FW */
  647. 0, 0, 0, 0);
  648. break;
  649. case CHIP_ID_185x_PG10:
  650. wl1271_warning("chip id 0x%x (185x PG10) is deprecated",
  651. wl->chip.id);
  652. ret = -ENODEV;
  653. goto out;
  654. default:
  655. wl1271_warning("unsupported chip id: 0x%x", wl->chip.id);
  656. ret = -ENODEV;
  657. goto out;
  658. }
  659. wl->scan_templ_id_2_4 = CMD_TEMPL_CFG_PROBE_REQ_2_4;
  660. wl->scan_templ_id_5 = CMD_TEMPL_CFG_PROBE_REQ_5;
  661. wl->sched_scan_templ_id_2_4 = CMD_TEMPL_PROBE_REQ_2_4_PERIODIC;
  662. wl->sched_scan_templ_id_5 = CMD_TEMPL_PROBE_REQ_5_PERIODIC;
  663. wl->max_channels_5 = WL18XX_MAX_CHANNELS_5GHZ;
  664. wl->ba_rx_session_count_max = WL18XX_RX_BA_MAX_SESSIONS;
  665. out:
  666. return ret;
  667. }
  668. static int wl18xx_set_clk(struct wl1271 *wl)
  669. {
  670. u16 clk_freq;
  671. int ret;
  672. ret = wlcore_set_partition(wl, &wl->ptable[PART_TOP_PRCM_ELP_SOC]);
  673. if (ret < 0)
  674. goto out;
  675. /* TODO: PG2: apparently we need to read the clk type */
  676. ret = wl18xx_top_reg_read(wl, PRIMARY_CLK_DETECT, &clk_freq);
  677. if (ret < 0)
  678. goto out;
  679. wl1271_debug(DEBUG_BOOT, "clock freq %d (%d, %d, %d, %d, %s)", clk_freq,
  680. wl18xx_clk_table[clk_freq].n, wl18xx_clk_table[clk_freq].m,
  681. wl18xx_clk_table[clk_freq].p, wl18xx_clk_table[clk_freq].q,
  682. wl18xx_clk_table[clk_freq].swallow ? "swallow" : "spit");
  683. /* coex PLL configuration */
  684. ret = wl18xx_top_reg_write(wl, PLLSH_COEX_PLL_N,
  685. wl18xx_clk_table_coex[clk_freq].n);
  686. if (ret < 0)
  687. goto out;
  688. ret = wl18xx_top_reg_write(wl, PLLSH_COEX_PLL_M,
  689. wl18xx_clk_table_coex[clk_freq].m);
  690. if (ret < 0)
  691. goto out;
  692. /* bypass the swallowing logic */
  693. ret = wl18xx_top_reg_write(wl, PLLSH_COEX_PLL_SWALLOW_EN,
  694. PLLSH_COEX_PLL_SWALLOW_EN_VAL1);
  695. if (ret < 0)
  696. goto out;
  697. ret = wl18xx_top_reg_write(wl, PLLSH_WCS_PLL_N,
  698. wl18xx_clk_table[clk_freq].n);
  699. if (ret < 0)
  700. goto out;
  701. ret = wl18xx_top_reg_write(wl, PLLSH_WCS_PLL_M,
  702. wl18xx_clk_table[clk_freq].m);
  703. if (ret < 0)
  704. goto out;
  705. if (wl18xx_clk_table[clk_freq].swallow) {
  706. /* first the 16 lower bits */
  707. ret = wl18xx_top_reg_write(wl, PLLSH_WCS_PLL_Q_FACTOR_CFG_1,
  708. wl18xx_clk_table[clk_freq].q &
  709. PLLSH_WCS_PLL_Q_FACTOR_CFG_1_MASK);
  710. if (ret < 0)
  711. goto out;
  712. /* then the 16 higher bits, masked out */
  713. ret = wl18xx_top_reg_write(wl, PLLSH_WCS_PLL_Q_FACTOR_CFG_2,
  714. (wl18xx_clk_table[clk_freq].q >> 16) &
  715. PLLSH_WCS_PLL_Q_FACTOR_CFG_2_MASK);
  716. if (ret < 0)
  717. goto out;
  718. /* first the 16 lower bits */
  719. ret = wl18xx_top_reg_write(wl, PLLSH_WCS_PLL_P_FACTOR_CFG_1,
  720. wl18xx_clk_table[clk_freq].p &
  721. PLLSH_WCS_PLL_P_FACTOR_CFG_1_MASK);
  722. if (ret < 0)
  723. goto out;
  724. /* then the 16 higher bits, masked out */
  725. ret = wl18xx_top_reg_write(wl, PLLSH_WCS_PLL_P_FACTOR_CFG_2,
  726. (wl18xx_clk_table[clk_freq].p >> 16) &
  727. PLLSH_WCS_PLL_P_FACTOR_CFG_2_MASK);
  728. } else {
  729. ret = wl18xx_top_reg_write(wl, PLLSH_WCS_PLL_SWALLOW_EN,
  730. PLLSH_WCS_PLL_SWALLOW_EN_VAL2);
  731. }
  732. /* choose WCS PLL */
  733. ret = wl18xx_top_reg_write(wl, PLLSH_WL_PLL_SEL,
  734. PLLSH_WL_PLL_SEL_WCS_PLL);
  735. if (ret < 0)
  736. goto out;
  737. /* enable both PLLs */
  738. ret = wl18xx_top_reg_write(wl, PLLSH_WL_PLL_EN, PLLSH_WL_PLL_EN_VAL1);
  739. if (ret < 0)
  740. goto out;
  741. udelay(1000);
  742. /* disable coex PLL */
  743. ret = wl18xx_top_reg_write(wl, PLLSH_WL_PLL_EN, PLLSH_WL_PLL_EN_VAL2);
  744. if (ret < 0)
  745. goto out;
  746. /* reset the swallowing logic */
  747. ret = wl18xx_top_reg_write(wl, PLLSH_COEX_PLL_SWALLOW_EN,
  748. PLLSH_COEX_PLL_SWALLOW_EN_VAL2);
  749. if (ret < 0)
  750. goto out;
  751. out:
  752. return ret;
  753. }
  754. static int wl18xx_boot_soft_reset(struct wl1271 *wl)
  755. {
  756. int ret;
  757. /* disable Rx/Tx */
  758. ret = wlcore_write32(wl, WL18XX_ENABLE, 0x0);
  759. if (ret < 0)
  760. goto out;
  761. /* disable auto calibration on start*/
  762. ret = wlcore_write32(wl, WL18XX_SPARE_A2, 0xffff);
  763. out:
  764. return ret;
  765. }
  766. static int wl18xx_pre_boot(struct wl1271 *wl)
  767. {
  768. int ret;
  769. ret = wl18xx_set_clk(wl);
  770. if (ret < 0)
  771. goto out;
  772. /* Continue the ELP wake up sequence */
  773. ret = wlcore_write32(wl, WL18XX_WELP_ARM_COMMAND, WELP_ARM_COMMAND_VAL);
  774. if (ret < 0)
  775. goto out;
  776. udelay(500);
  777. ret = wlcore_set_partition(wl, &wl->ptable[PART_BOOT]);
  778. if (ret < 0)
  779. goto out;
  780. /* Disable interrupts */
  781. ret = wlcore_write_reg(wl, REG_INTERRUPT_MASK, WL1271_ACX_INTR_ALL);
  782. if (ret < 0)
  783. goto out;
  784. ret = wl18xx_boot_soft_reset(wl);
  785. out:
  786. return ret;
  787. }
  788. static int wl18xx_pre_upload(struct wl1271 *wl)
  789. {
  790. u32 tmp;
  791. int ret;
  792. BUILD_BUG_ON(sizeof(struct wl18xx_mac_and_phy_params) >
  793. WL18XX_PHY_INIT_MEM_SIZE);
  794. ret = wlcore_set_partition(wl, &wl->ptable[PART_BOOT]);
  795. if (ret < 0)
  796. goto out;
  797. /* TODO: check if this is all needed */
  798. ret = wlcore_write32(wl, WL18XX_EEPROMLESS_IND, WL18XX_EEPROMLESS_IND);
  799. if (ret < 0)
  800. goto out;
  801. ret = wlcore_read_reg(wl, REG_CHIP_ID_B, &tmp);
  802. if (ret < 0)
  803. goto out;
  804. wl1271_debug(DEBUG_BOOT, "chip id 0x%x", tmp);
  805. ret = wlcore_read32(wl, WL18XX_SCR_PAD2, &tmp);
  806. if (ret < 0)
  807. goto out;
  808. /*
  809. * Workaround for FDSP code RAM corruption (needed for PG2.1
  810. * and newer; for older chips it's a NOP). Change FDSP clock
  811. * settings so that it's muxed to the ATGP clock instead of
  812. * its own clock.
  813. */
  814. ret = wlcore_set_partition(wl, &wl->ptable[PART_PHY_INIT]);
  815. if (ret < 0)
  816. goto out;
  817. /* disable FDSP clock */
  818. ret = wlcore_write32(wl, WL18XX_PHY_FPGA_SPARE_1,
  819. MEM_FDSP_CLK_120_DISABLE);
  820. if (ret < 0)
  821. goto out;
  822. /* set ATPG clock toward FDSP Code RAM rather than its own clock */
  823. ret = wlcore_write32(wl, WL18XX_PHY_FPGA_SPARE_1,
  824. MEM_FDSP_CODERAM_FUNC_CLK_SEL);
  825. if (ret < 0)
  826. goto out;
  827. /* re-enable FDSP clock */
  828. ret = wlcore_write32(wl, WL18XX_PHY_FPGA_SPARE_1,
  829. MEM_FDSP_CLK_120_ENABLE);
  830. out:
  831. return ret;
  832. }
  833. static int wl18xx_set_mac_and_phy(struct wl1271 *wl)
  834. {
  835. struct wl18xx_priv *priv = wl->priv;
  836. struct wl18xx_mac_and_phy_params *params;
  837. int ret;
  838. params = kmemdup(&priv->conf.phy, sizeof(*params), GFP_KERNEL);
  839. if (!params) {
  840. ret = -ENOMEM;
  841. goto out;
  842. }
  843. ret = wlcore_set_partition(wl, &wl->ptable[PART_PHY_INIT]);
  844. if (ret < 0)
  845. goto out;
  846. ret = wlcore_write(wl, WL18XX_PHY_INIT_MEM_ADDR, params,
  847. sizeof(*params), false);
  848. out:
  849. kfree(params);
  850. return ret;
  851. }
  852. static int wl18xx_enable_interrupts(struct wl1271 *wl)
  853. {
  854. u32 event_mask, intr_mask;
  855. int ret;
  856. event_mask = WL18XX_ACX_EVENTS_VECTOR;
  857. intr_mask = WL18XX_INTR_MASK;
  858. ret = wlcore_write_reg(wl, REG_INTERRUPT_MASK, event_mask);
  859. if (ret < 0)
  860. goto out;
  861. wlcore_enable_interrupts(wl);
  862. ret = wlcore_write_reg(wl, REG_INTERRUPT_MASK,
  863. WL1271_ACX_INTR_ALL & ~intr_mask);
  864. if (ret < 0)
  865. goto disable_interrupts;
  866. return ret;
  867. disable_interrupts:
  868. wlcore_disable_interrupts(wl);
  869. out:
  870. return ret;
  871. }
  872. static int wl18xx_boot(struct wl1271 *wl)
  873. {
  874. int ret;
  875. ret = wl18xx_pre_boot(wl);
  876. if (ret < 0)
  877. goto out;
  878. ret = wl18xx_pre_upload(wl);
  879. if (ret < 0)
  880. goto out;
  881. ret = wlcore_boot_upload_firmware(wl);
  882. if (ret < 0)
  883. goto out;
  884. ret = wl18xx_set_mac_and_phy(wl);
  885. if (ret < 0)
  886. goto out;
  887. wl->event_mask = BSS_LOSS_EVENT_ID |
  888. SCAN_COMPLETE_EVENT_ID |
  889. RSSI_SNR_TRIGGER_0_EVENT_ID |
  890. PERIODIC_SCAN_COMPLETE_EVENT_ID |
  891. PERIODIC_SCAN_REPORT_EVENT_ID |
  892. DUMMY_PACKET_EVENT_ID |
  893. PEER_REMOVE_COMPLETE_EVENT_ID |
  894. BA_SESSION_RX_CONSTRAINT_EVENT_ID |
  895. REMAIN_ON_CHANNEL_COMPLETE_EVENT_ID |
  896. INACTIVE_STA_EVENT_ID |
  897. MAX_TX_FAILURE_EVENT_ID |
  898. CHANNEL_SWITCH_COMPLETE_EVENT_ID |
  899. DFS_CHANNELS_CONFIG_COMPLETE_EVENT;
  900. ret = wlcore_boot_run_firmware(wl);
  901. if (ret < 0)
  902. goto out;
  903. ret = wl18xx_enable_interrupts(wl);
  904. out:
  905. return ret;
  906. }
  907. static int wl18xx_trigger_cmd(struct wl1271 *wl, int cmd_box_addr,
  908. void *buf, size_t len)
  909. {
  910. struct wl18xx_priv *priv = wl->priv;
  911. memcpy(priv->cmd_buf, buf, len);
  912. memset(priv->cmd_buf + len, 0, WL18XX_CMD_MAX_SIZE - len);
  913. return wlcore_write(wl, cmd_box_addr, priv->cmd_buf,
  914. WL18XX_CMD_MAX_SIZE, false);
  915. }
  916. static int wl18xx_ack_event(struct wl1271 *wl)
  917. {
  918. return wlcore_write_reg(wl, REG_INTERRUPT_TRIG,
  919. WL18XX_INTR_TRIG_EVENT_ACK);
  920. }
  921. static u32 wl18xx_calc_tx_blocks(struct wl1271 *wl, u32 len, u32 spare_blks)
  922. {
  923. u32 blk_size = WL18XX_TX_HW_BLOCK_SIZE;
  924. return (len + blk_size - 1) / blk_size + spare_blks;
  925. }
  926. static void
  927. wl18xx_set_tx_desc_blocks(struct wl1271 *wl, struct wl1271_tx_hw_descr *desc,
  928. u32 blks, u32 spare_blks)
  929. {
  930. desc->wl18xx_mem.total_mem_blocks = blks;
  931. }
  932. static void
  933. wl18xx_set_tx_desc_data_len(struct wl1271 *wl, struct wl1271_tx_hw_descr *desc,
  934. struct sk_buff *skb)
  935. {
  936. desc->length = cpu_to_le16(skb->len);
  937. /* if only the last frame is to be padded, we unset this bit on Tx */
  938. if (wl->quirks & WLCORE_QUIRK_TX_PAD_LAST_FRAME)
  939. desc->wl18xx_mem.ctrl = WL18XX_TX_CTRL_NOT_PADDED;
  940. else
  941. desc->wl18xx_mem.ctrl = 0;
  942. wl1271_debug(DEBUG_TX, "tx_fill_hdr: hlid: %d "
  943. "len: %d life: %d mem: %d", desc->hlid,
  944. le16_to_cpu(desc->length),
  945. le16_to_cpu(desc->life_time),
  946. desc->wl18xx_mem.total_mem_blocks);
  947. }
  948. static enum wl_rx_buf_align
  949. wl18xx_get_rx_buf_align(struct wl1271 *wl, u32 rx_desc)
  950. {
  951. if (rx_desc & RX_BUF_PADDED_PAYLOAD)
  952. return WLCORE_RX_BUF_PADDED;
  953. return WLCORE_RX_BUF_ALIGNED;
  954. }
  955. static u32 wl18xx_get_rx_packet_len(struct wl1271 *wl, void *rx_data,
  956. u32 data_len)
  957. {
  958. struct wl1271_rx_descriptor *desc = rx_data;
  959. /* invalid packet */
  960. if (data_len < sizeof(*desc))
  961. return 0;
  962. return data_len - sizeof(*desc);
  963. }
  964. static void wl18xx_tx_immediate_completion(struct wl1271 *wl)
  965. {
  966. wl18xx_tx_immediate_complete(wl);
  967. }
  968. static int wl18xx_set_host_cfg_bitmap(struct wl1271 *wl, u32 extra_mem_blk)
  969. {
  970. int ret;
  971. u32 sdio_align_size = 0;
  972. u32 host_cfg_bitmap = HOST_IF_CFG_RX_FIFO_ENABLE |
  973. HOST_IF_CFG_ADD_RX_ALIGNMENT;
  974. /* Enable Tx SDIO padding */
  975. if (wl->quirks & WLCORE_QUIRK_TX_BLOCKSIZE_ALIGN) {
  976. host_cfg_bitmap |= HOST_IF_CFG_TX_PAD_TO_SDIO_BLK;
  977. sdio_align_size = WL12XX_BUS_BLOCK_SIZE;
  978. }
  979. /* Enable Rx SDIO padding */
  980. if (wl->quirks & WLCORE_QUIRK_RX_BLOCKSIZE_ALIGN) {
  981. host_cfg_bitmap |= HOST_IF_CFG_RX_PAD_TO_SDIO_BLK;
  982. sdio_align_size = WL12XX_BUS_BLOCK_SIZE;
  983. }
  984. ret = wl18xx_acx_host_if_cfg_bitmap(wl, host_cfg_bitmap,
  985. sdio_align_size, extra_mem_blk,
  986. WL18XX_HOST_IF_LEN_SIZE_FIELD);
  987. if (ret < 0)
  988. return ret;
  989. return 0;
  990. }
  991. static int wl18xx_hw_init(struct wl1271 *wl)
  992. {
  993. int ret;
  994. struct wl18xx_priv *priv = wl->priv;
  995. /* (re)init private structures. Relevant on recovery as well. */
  996. priv->last_fw_rls_idx = 0;
  997. priv->extra_spare_key_count = 0;
  998. /* set the default amount of spare blocks in the bitmap */
  999. ret = wl18xx_set_host_cfg_bitmap(wl, WL18XX_TX_HW_BLOCK_SPARE);
  1000. if (ret < 0)
  1001. return ret;
  1002. if (checksum_param) {
  1003. ret = wl18xx_acx_set_checksum_state(wl);
  1004. if (ret != 0)
  1005. return ret;
  1006. }
  1007. return ret;
  1008. }
  1009. static void wl18xx_set_tx_desc_csum(struct wl1271 *wl,
  1010. struct wl1271_tx_hw_descr *desc,
  1011. struct sk_buff *skb)
  1012. {
  1013. u32 ip_hdr_offset;
  1014. struct iphdr *ip_hdr;
  1015. if (!checksum_param) {
  1016. desc->wl18xx_checksum_data = 0;
  1017. return;
  1018. }
  1019. if (skb->ip_summed != CHECKSUM_PARTIAL) {
  1020. desc->wl18xx_checksum_data = 0;
  1021. return;
  1022. }
  1023. ip_hdr_offset = skb_network_header(skb) - skb_mac_header(skb);
  1024. if (WARN_ON(ip_hdr_offset >= (1<<7))) {
  1025. desc->wl18xx_checksum_data = 0;
  1026. return;
  1027. }
  1028. desc->wl18xx_checksum_data = ip_hdr_offset << 1;
  1029. /* FW is interested only in the LSB of the protocol TCP=0 UDP=1 */
  1030. ip_hdr = (void *)skb_network_header(skb);
  1031. desc->wl18xx_checksum_data |= (ip_hdr->protocol & 0x01);
  1032. }
  1033. static void wl18xx_set_rx_csum(struct wl1271 *wl,
  1034. struct wl1271_rx_descriptor *desc,
  1035. struct sk_buff *skb)
  1036. {
  1037. if (desc->status & WL18XX_RX_CHECKSUM_MASK)
  1038. skb->ip_summed = CHECKSUM_UNNECESSARY;
  1039. }
  1040. static bool wl18xx_is_mimo_supported(struct wl1271 *wl)
  1041. {
  1042. struct wl18xx_priv *priv = wl->priv;
  1043. /* only support MIMO with multiple antennas, and when SISO
  1044. * is not forced through config
  1045. */
  1046. return (priv->conf.phy.number_of_assembled_ant2_4 >= 2) &&
  1047. (priv->conf.ht.mode != HT_MODE_WIDE) &&
  1048. (priv->conf.ht.mode != HT_MODE_SISO20);
  1049. }
  1050. /*
  1051. * TODO: instead of having these two functions to get the rate mask,
  1052. * we should modify the wlvif->rate_set instead
  1053. */
  1054. static u32 wl18xx_sta_get_ap_rate_mask(struct wl1271 *wl,
  1055. struct wl12xx_vif *wlvif)
  1056. {
  1057. u32 hw_rate_set = wlvif->rate_set;
  1058. if (wlvif->channel_type == NL80211_CHAN_HT40MINUS ||
  1059. wlvif->channel_type == NL80211_CHAN_HT40PLUS) {
  1060. wl1271_debug(DEBUG_ACX, "using wide channel rate mask");
  1061. hw_rate_set |= CONF_TX_RATE_USE_WIDE_CHAN;
  1062. /* we don't support MIMO in wide-channel mode */
  1063. hw_rate_set &= ~CONF_TX_MIMO_RATES;
  1064. } else if (wl18xx_is_mimo_supported(wl)) {
  1065. wl1271_debug(DEBUG_ACX, "using MIMO channel rate mask");
  1066. hw_rate_set |= CONF_TX_MIMO_RATES;
  1067. }
  1068. return hw_rate_set;
  1069. }
  1070. static u32 wl18xx_ap_get_mimo_wide_rate_mask(struct wl1271 *wl,
  1071. struct wl12xx_vif *wlvif)
  1072. {
  1073. if (wlvif->channel_type == NL80211_CHAN_HT40MINUS ||
  1074. wlvif->channel_type == NL80211_CHAN_HT40PLUS) {
  1075. wl1271_debug(DEBUG_ACX, "using wide channel rate mask");
  1076. /* sanity check - we don't support this */
  1077. if (WARN_ON(wlvif->band != IEEE80211_BAND_5GHZ))
  1078. return 0;
  1079. return CONF_TX_RATE_USE_WIDE_CHAN;
  1080. } else if (wl18xx_is_mimo_supported(wl) &&
  1081. wlvif->band == IEEE80211_BAND_2GHZ) {
  1082. wl1271_debug(DEBUG_ACX, "using MIMO rate mask");
  1083. /*
  1084. * we don't care about HT channel here - if a peer doesn't
  1085. * support MIMO, we won't enable it in its rates
  1086. */
  1087. return CONF_TX_MIMO_RATES;
  1088. } else {
  1089. return 0;
  1090. }
  1091. }
  1092. static const char *wl18xx_rdl_name(enum wl18xx_rdl_num rdl_num)
  1093. {
  1094. switch (rdl_num) {
  1095. case RDL_1_HP:
  1096. return "183xH";
  1097. case RDL_2_SP:
  1098. return "183x or 180x";
  1099. case RDL_3_HP:
  1100. return "187xH";
  1101. case RDL_4_SP:
  1102. return "187x";
  1103. case RDL_5_SP:
  1104. return "RDL11 - Not Supported";
  1105. case RDL_6_SP:
  1106. return "180xD";
  1107. case RDL_7_SP:
  1108. return "RDL13 - Not Supported (1893Q)";
  1109. case RDL_8_SP:
  1110. return "18xxQ";
  1111. case RDL_NONE:
  1112. return "UNTRIMMED";
  1113. default:
  1114. return "UNKNOWN";
  1115. }
  1116. }
  1117. static int wl18xx_get_pg_ver(struct wl1271 *wl, s8 *ver)
  1118. {
  1119. u32 fuse;
  1120. s8 rom = 0, metal = 0, pg_ver = 0, rdl_ver = 0, package_type = 0;
  1121. int ret;
  1122. ret = wlcore_set_partition(wl, &wl->ptable[PART_TOP_PRCM_ELP_SOC]);
  1123. if (ret < 0)
  1124. goto out;
  1125. ret = wlcore_read32(wl, WL18XX_REG_FUSE_DATA_2_3, &fuse);
  1126. if (ret < 0)
  1127. goto out;
  1128. package_type = (fuse >> WL18XX_PACKAGE_TYPE_OFFSET) & 1;
  1129. ret = wlcore_read32(wl, WL18XX_REG_FUSE_DATA_1_3, &fuse);
  1130. if (ret < 0)
  1131. goto out;
  1132. pg_ver = (fuse & WL18XX_PG_VER_MASK) >> WL18XX_PG_VER_OFFSET;
  1133. rom = (fuse & WL18XX_ROM_VER_MASK) >> WL18XX_ROM_VER_OFFSET;
  1134. if ((rom <= 0xE) && (package_type == WL18XX_PACKAGE_TYPE_WSP))
  1135. metal = (fuse & WL18XX_METAL_VER_MASK) >>
  1136. WL18XX_METAL_VER_OFFSET;
  1137. else
  1138. metal = (fuse & WL18XX_NEW_METAL_VER_MASK) >>
  1139. WL18XX_NEW_METAL_VER_OFFSET;
  1140. ret = wlcore_read32(wl, WL18XX_REG_FUSE_DATA_2_3, &fuse);
  1141. if (ret < 0)
  1142. goto out;
  1143. rdl_ver = (fuse & WL18XX_RDL_VER_MASK) >> WL18XX_RDL_VER_OFFSET;
  1144. wl1271_info("wl18xx HW: %s, PG %d.%d (ROM 0x%x)",
  1145. wl18xx_rdl_name(rdl_ver), pg_ver, metal, rom);
  1146. if (ver)
  1147. *ver = pg_ver;
  1148. ret = wlcore_set_partition(wl, &wl->ptable[PART_BOOT]);
  1149. out:
  1150. return ret;
  1151. }
  1152. #define WL18XX_CONF_FILE_NAME "ti-connectivity/wl18xx-conf.bin"
  1153. static int wl18xx_conf_init(struct wl1271 *wl, struct device *dev)
  1154. {
  1155. struct wl18xx_priv *priv = wl->priv;
  1156. struct wlcore_conf_file *conf_file;
  1157. const struct firmware *fw;
  1158. int ret;
  1159. ret = request_firmware(&fw, WL18XX_CONF_FILE_NAME, dev);
  1160. if (ret < 0) {
  1161. wl1271_error("could not get configuration binary %s: %d",
  1162. WL18XX_CONF_FILE_NAME, ret);
  1163. goto out_fallback;
  1164. }
  1165. if (fw->size != WL18XX_CONF_SIZE) {
  1166. wl1271_error("configuration binary file size is wrong, expected %zu got %zu",
  1167. WL18XX_CONF_SIZE, fw->size);
  1168. ret = -EINVAL;
  1169. goto out;
  1170. }
  1171. conf_file = (struct wlcore_conf_file *) fw->data;
  1172. if (conf_file->header.magic != cpu_to_le32(WL18XX_CONF_MAGIC)) {
  1173. wl1271_error("configuration binary file magic number mismatch, "
  1174. "expected 0x%0x got 0x%0x", WL18XX_CONF_MAGIC,
  1175. conf_file->header.magic);
  1176. ret = -EINVAL;
  1177. goto out;
  1178. }
  1179. if (conf_file->header.version != cpu_to_le32(WL18XX_CONF_VERSION)) {
  1180. wl1271_error("configuration binary file version not supported, "
  1181. "expected 0x%08x got 0x%08x",
  1182. WL18XX_CONF_VERSION, conf_file->header.version);
  1183. ret = -EINVAL;
  1184. goto out;
  1185. }
  1186. memcpy(&wl->conf, &conf_file->core, sizeof(wl18xx_conf));
  1187. memcpy(&priv->conf, &conf_file->priv, sizeof(priv->conf));
  1188. goto out;
  1189. out_fallback:
  1190. wl1271_warning("falling back to default config");
  1191. /* apply driver default configuration */
  1192. memcpy(&wl->conf, &wl18xx_conf, sizeof(wl18xx_conf));
  1193. /* apply default private configuration */
  1194. memcpy(&priv->conf, &wl18xx_default_priv_conf, sizeof(priv->conf));
  1195. /* For now we just fallback */
  1196. return 0;
  1197. out:
  1198. release_firmware(fw);
  1199. return ret;
  1200. }
  1201. static int wl18xx_plt_init(struct wl1271 *wl)
  1202. {
  1203. int ret;
  1204. /* calibrator based auto/fem detect not supported for 18xx */
  1205. if (wl->plt_mode == PLT_FEM_DETECT) {
  1206. wl1271_error("wl18xx_plt_init: PLT FEM_DETECT not supported");
  1207. return -EINVAL;
  1208. }
  1209. ret = wlcore_write32(wl, WL18XX_SCR_PAD8, WL18XX_SCR_PAD8_PLT);
  1210. if (ret < 0)
  1211. return ret;
  1212. return wl->ops->boot(wl);
  1213. }
  1214. static int wl18xx_get_mac(struct wl1271 *wl)
  1215. {
  1216. u32 mac1, mac2;
  1217. int ret;
  1218. ret = wlcore_set_partition(wl, &wl->ptable[PART_TOP_PRCM_ELP_SOC]);
  1219. if (ret < 0)
  1220. goto out;
  1221. ret = wlcore_read32(wl, WL18XX_REG_FUSE_BD_ADDR_1, &mac1);
  1222. if (ret < 0)
  1223. goto out;
  1224. ret = wlcore_read32(wl, WL18XX_REG_FUSE_BD_ADDR_2, &mac2);
  1225. if (ret < 0)
  1226. goto out;
  1227. /* these are the two parts of the BD_ADDR */
  1228. wl->fuse_oui_addr = ((mac2 & 0xffff) << 8) +
  1229. ((mac1 & 0xff000000) >> 24);
  1230. wl->fuse_nic_addr = (mac1 & 0xffffff);
  1231. if (!wl->fuse_oui_addr && !wl->fuse_nic_addr) {
  1232. u8 mac[ETH_ALEN];
  1233. eth_random_addr(mac);
  1234. wl->fuse_oui_addr = (mac[0] << 16) + (mac[1] << 8) + mac[2];
  1235. wl->fuse_nic_addr = (mac[3] << 16) + (mac[4] << 8) + mac[5];
  1236. wl1271_warning("MAC address from fuse not available, using random locally administered addresses.");
  1237. }
  1238. ret = wlcore_set_partition(wl, &wl->ptable[PART_DOWN]);
  1239. out:
  1240. return ret;
  1241. }
  1242. static int wl18xx_handle_static_data(struct wl1271 *wl,
  1243. struct wl1271_static_data *static_data)
  1244. {
  1245. struct wl18xx_static_data_priv *static_data_priv =
  1246. (struct wl18xx_static_data_priv *) static_data->priv;
  1247. strncpy(wl->chip.phy_fw_ver_str, static_data_priv->phy_version,
  1248. sizeof(wl->chip.phy_fw_ver_str));
  1249. /* make sure the string is NULL-terminated */
  1250. wl->chip.phy_fw_ver_str[sizeof(wl->chip.phy_fw_ver_str) - 1] = '\0';
  1251. wl1271_info("PHY firmware version: %s", static_data_priv->phy_version);
  1252. return 0;
  1253. }
  1254. static int wl18xx_get_spare_blocks(struct wl1271 *wl, bool is_gem)
  1255. {
  1256. struct wl18xx_priv *priv = wl->priv;
  1257. /* If we have keys requiring extra spare, indulge them */
  1258. if (priv->extra_spare_key_count)
  1259. return WL18XX_TX_HW_EXTRA_BLOCK_SPARE;
  1260. return WL18XX_TX_HW_BLOCK_SPARE;
  1261. }
  1262. static int wl18xx_set_key(struct wl1271 *wl, enum set_key_cmd cmd,
  1263. struct ieee80211_vif *vif,
  1264. struct ieee80211_sta *sta,
  1265. struct ieee80211_key_conf *key_conf)
  1266. {
  1267. struct wl18xx_priv *priv = wl->priv;
  1268. bool change_spare = false, special_enc;
  1269. int ret;
  1270. wl1271_debug(DEBUG_CRYPT, "extra spare keys before: %d",
  1271. priv->extra_spare_key_count);
  1272. special_enc = key_conf->cipher == WL1271_CIPHER_SUITE_GEM ||
  1273. key_conf->cipher == WLAN_CIPHER_SUITE_TKIP;
  1274. ret = wlcore_set_key(wl, cmd, vif, sta, key_conf);
  1275. if (ret < 0)
  1276. goto out;
  1277. /*
  1278. * when adding the first or removing the last GEM/TKIP key,
  1279. * we have to adjust the number of spare blocks.
  1280. */
  1281. if (special_enc) {
  1282. if (cmd == SET_KEY) {
  1283. /* first key */
  1284. change_spare = (priv->extra_spare_key_count == 0);
  1285. priv->extra_spare_key_count++;
  1286. } else if (cmd == DISABLE_KEY) {
  1287. /* last key */
  1288. change_spare = (priv->extra_spare_key_count == 1);
  1289. priv->extra_spare_key_count--;
  1290. }
  1291. }
  1292. wl1271_debug(DEBUG_CRYPT, "extra spare keys after: %d",
  1293. priv->extra_spare_key_count);
  1294. if (!change_spare)
  1295. goto out;
  1296. /* key is now set, change the spare blocks */
  1297. if (priv->extra_spare_key_count)
  1298. ret = wl18xx_set_host_cfg_bitmap(wl,
  1299. WL18XX_TX_HW_EXTRA_BLOCK_SPARE);
  1300. else
  1301. ret = wl18xx_set_host_cfg_bitmap(wl,
  1302. WL18XX_TX_HW_BLOCK_SPARE);
  1303. out:
  1304. return ret;
  1305. }
  1306. static u32 wl18xx_pre_pkt_send(struct wl1271 *wl,
  1307. u32 buf_offset, u32 last_len)
  1308. {
  1309. if (wl->quirks & WLCORE_QUIRK_TX_PAD_LAST_FRAME) {
  1310. struct wl1271_tx_hw_descr *last_desc;
  1311. /* get the last TX HW descriptor written to the aggr buf */
  1312. last_desc = (struct wl1271_tx_hw_descr *)(wl->aggr_buf +
  1313. buf_offset - last_len);
  1314. /* the last frame is padded up to an SDIO block */
  1315. last_desc->wl18xx_mem.ctrl &= ~WL18XX_TX_CTRL_NOT_PADDED;
  1316. return ALIGN(buf_offset, WL12XX_BUS_BLOCK_SIZE);
  1317. }
  1318. /* no modifications */
  1319. return buf_offset;
  1320. }
  1321. static void wl18xx_sta_rc_update(struct wl1271 *wl,
  1322. struct wl12xx_vif *wlvif,
  1323. struct ieee80211_sta *sta,
  1324. u32 changed)
  1325. {
  1326. bool wide = sta->bandwidth >= IEEE80211_STA_RX_BW_40;
  1327. wl1271_debug(DEBUG_MAC80211, "mac80211 sta_rc_update wide %d", wide);
  1328. if (!(changed & IEEE80211_RC_BW_CHANGED))
  1329. return;
  1330. mutex_lock(&wl->mutex);
  1331. /* sanity */
  1332. if (WARN_ON(wlvif->bss_type != BSS_TYPE_STA_BSS))
  1333. goto out;
  1334. /* ignore the change before association */
  1335. if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
  1336. goto out;
  1337. /*
  1338. * If we started out as wide, we can change the operation mode. If we
  1339. * thought this was a 20mhz AP, we have to reconnect
  1340. */
  1341. if (wlvif->sta.role_chan_type == NL80211_CHAN_HT40MINUS ||
  1342. wlvif->sta.role_chan_type == NL80211_CHAN_HT40PLUS)
  1343. wl18xx_acx_peer_ht_operation_mode(wl, wlvif->sta.hlid, wide);
  1344. else
  1345. ieee80211_connection_loss(wl12xx_wlvif_to_vif(wlvif));
  1346. out:
  1347. mutex_unlock(&wl->mutex);
  1348. }
  1349. static int wl18xx_set_peer_cap(struct wl1271 *wl,
  1350. struct ieee80211_sta_ht_cap *ht_cap,
  1351. bool allow_ht_operation,
  1352. u32 rate_set, u8 hlid)
  1353. {
  1354. return wl18xx_acx_set_peer_cap(wl, ht_cap, allow_ht_operation,
  1355. rate_set, hlid);
  1356. }
  1357. static bool wl18xx_lnk_high_prio(struct wl1271 *wl, u8 hlid,
  1358. struct wl1271_link *lnk)
  1359. {
  1360. u8 thold;
  1361. struct wl18xx_fw_status_priv *status_priv =
  1362. (struct wl18xx_fw_status_priv *)wl->fw_status_2->priv;
  1363. u32 suspend_bitmap = le32_to_cpu(status_priv->link_suspend_bitmap);
  1364. /* suspended links are never high priority */
  1365. if (test_bit(hlid, (unsigned long *)&suspend_bitmap))
  1366. return false;
  1367. /* the priority thresholds are taken from FW */
  1368. if (test_bit(hlid, (unsigned long *)&wl->fw_fast_lnk_map) &&
  1369. !test_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map))
  1370. thold = status_priv->tx_fast_link_prio_threshold;
  1371. else
  1372. thold = status_priv->tx_slow_link_prio_threshold;
  1373. return lnk->allocated_pkts < thold;
  1374. }
  1375. static bool wl18xx_lnk_low_prio(struct wl1271 *wl, u8 hlid,
  1376. struct wl1271_link *lnk)
  1377. {
  1378. u8 thold;
  1379. struct wl18xx_fw_status_priv *status_priv =
  1380. (struct wl18xx_fw_status_priv *)wl->fw_status_2->priv;
  1381. u32 suspend_bitmap = le32_to_cpu(status_priv->link_suspend_bitmap);
  1382. if (test_bit(hlid, (unsigned long *)&suspend_bitmap))
  1383. thold = status_priv->tx_suspend_threshold;
  1384. else if (test_bit(hlid, (unsigned long *)&wl->fw_fast_lnk_map) &&
  1385. !test_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map))
  1386. thold = status_priv->tx_fast_stop_threshold;
  1387. else
  1388. thold = status_priv->tx_slow_stop_threshold;
  1389. return lnk->allocated_pkts < thold;
  1390. }
  1391. static int wl18xx_setup(struct wl1271 *wl);
  1392. static struct wlcore_ops wl18xx_ops = {
  1393. .setup = wl18xx_setup,
  1394. .identify_chip = wl18xx_identify_chip,
  1395. .boot = wl18xx_boot,
  1396. .plt_init = wl18xx_plt_init,
  1397. .trigger_cmd = wl18xx_trigger_cmd,
  1398. .ack_event = wl18xx_ack_event,
  1399. .wait_for_event = wl18xx_wait_for_event,
  1400. .process_mailbox_events = wl18xx_process_mailbox_events,
  1401. .calc_tx_blocks = wl18xx_calc_tx_blocks,
  1402. .set_tx_desc_blocks = wl18xx_set_tx_desc_blocks,
  1403. .set_tx_desc_data_len = wl18xx_set_tx_desc_data_len,
  1404. .get_rx_buf_align = wl18xx_get_rx_buf_align,
  1405. .get_rx_packet_len = wl18xx_get_rx_packet_len,
  1406. .tx_immediate_compl = wl18xx_tx_immediate_completion,
  1407. .tx_delayed_compl = NULL,
  1408. .hw_init = wl18xx_hw_init,
  1409. .set_tx_desc_csum = wl18xx_set_tx_desc_csum,
  1410. .get_pg_ver = wl18xx_get_pg_ver,
  1411. .set_rx_csum = wl18xx_set_rx_csum,
  1412. .sta_get_ap_rate_mask = wl18xx_sta_get_ap_rate_mask,
  1413. .ap_get_mimo_wide_rate_mask = wl18xx_ap_get_mimo_wide_rate_mask,
  1414. .get_mac = wl18xx_get_mac,
  1415. .debugfs_init = wl18xx_debugfs_add_files,
  1416. .scan_start = wl18xx_scan_start,
  1417. .scan_stop = wl18xx_scan_stop,
  1418. .sched_scan_start = wl18xx_sched_scan_start,
  1419. .sched_scan_stop = wl18xx_scan_sched_scan_stop,
  1420. .handle_static_data = wl18xx_handle_static_data,
  1421. .get_spare_blocks = wl18xx_get_spare_blocks,
  1422. .set_key = wl18xx_set_key,
  1423. .channel_switch = wl18xx_cmd_channel_switch,
  1424. .pre_pkt_send = wl18xx_pre_pkt_send,
  1425. .sta_rc_update = wl18xx_sta_rc_update,
  1426. .set_peer_cap = wl18xx_set_peer_cap,
  1427. .lnk_high_prio = wl18xx_lnk_high_prio,
  1428. .lnk_low_prio = wl18xx_lnk_low_prio,
  1429. };
  1430. /* HT cap appropriate for wide channels in 2Ghz */
  1431. static struct ieee80211_sta_ht_cap wl18xx_siso40_ht_cap_2ghz = {
  1432. .cap = IEEE80211_HT_CAP_SGI_20 | IEEE80211_HT_CAP_SGI_40 |
  1433. IEEE80211_HT_CAP_SUP_WIDTH_20_40 | IEEE80211_HT_CAP_DSSSCCK40 |
  1434. IEEE80211_HT_CAP_GRN_FLD,
  1435. .ht_supported = true,
  1436. .ampdu_factor = IEEE80211_HT_MAX_AMPDU_16K,
  1437. .ampdu_density = IEEE80211_HT_MPDU_DENSITY_16,
  1438. .mcs = {
  1439. .rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
  1440. .rx_highest = cpu_to_le16(150),
  1441. .tx_params = IEEE80211_HT_MCS_TX_DEFINED,
  1442. },
  1443. };
  1444. /* HT cap appropriate for wide channels in 5Ghz */
  1445. static struct ieee80211_sta_ht_cap wl18xx_siso40_ht_cap_5ghz = {
  1446. .cap = IEEE80211_HT_CAP_SGI_20 | IEEE80211_HT_CAP_SGI_40 |
  1447. IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
  1448. IEEE80211_HT_CAP_GRN_FLD,
  1449. .ht_supported = true,
  1450. .ampdu_factor = IEEE80211_HT_MAX_AMPDU_16K,
  1451. .ampdu_density = IEEE80211_HT_MPDU_DENSITY_16,
  1452. .mcs = {
  1453. .rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
  1454. .rx_highest = cpu_to_le16(150),
  1455. .tx_params = IEEE80211_HT_MCS_TX_DEFINED,
  1456. },
  1457. };
  1458. /* HT cap appropriate for SISO 20 */
  1459. static struct ieee80211_sta_ht_cap wl18xx_siso20_ht_cap = {
  1460. .cap = IEEE80211_HT_CAP_SGI_20 |
  1461. IEEE80211_HT_CAP_GRN_FLD,
  1462. .ht_supported = true,
  1463. .ampdu_factor = IEEE80211_HT_MAX_AMPDU_16K,
  1464. .ampdu_density = IEEE80211_HT_MPDU_DENSITY_16,
  1465. .mcs = {
  1466. .rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
  1467. .rx_highest = cpu_to_le16(72),
  1468. .tx_params = IEEE80211_HT_MCS_TX_DEFINED,
  1469. },
  1470. };
  1471. /* HT cap appropriate for MIMO rates in 20mhz channel */
  1472. static struct ieee80211_sta_ht_cap wl18xx_mimo_ht_cap_2ghz = {
  1473. .cap = IEEE80211_HT_CAP_SGI_20 |
  1474. IEEE80211_HT_CAP_GRN_FLD,
  1475. .ht_supported = true,
  1476. .ampdu_factor = IEEE80211_HT_MAX_AMPDU_16K,
  1477. .ampdu_density = IEEE80211_HT_MPDU_DENSITY_16,
  1478. .mcs = {
  1479. .rx_mask = { 0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0, },
  1480. .rx_highest = cpu_to_le16(144),
  1481. .tx_params = IEEE80211_HT_MCS_TX_DEFINED,
  1482. },
  1483. };
  1484. static int wl18xx_setup(struct wl1271 *wl)
  1485. {
  1486. struct wl18xx_priv *priv = wl->priv;
  1487. int ret;
  1488. wl->rtable = wl18xx_rtable;
  1489. wl->num_tx_desc = WL18XX_NUM_TX_DESCRIPTORS;
  1490. wl->num_rx_desc = WL18XX_NUM_RX_DESCRIPTORS;
  1491. wl->num_channels = 2;
  1492. wl->num_mac_addr = WL18XX_NUM_MAC_ADDRESSES;
  1493. wl->band_rate_to_idx = wl18xx_band_rate_to_idx;
  1494. wl->hw_tx_rate_tbl_size = WL18XX_CONF_HW_RXTX_RATE_MAX;
  1495. wl->hw_min_ht_rate = WL18XX_CONF_HW_RXTX_RATE_MCS0;
  1496. wl->fw_status_priv_len = sizeof(struct wl18xx_fw_status_priv);
  1497. wl->stats.fw_stats_len = sizeof(struct wl18xx_acx_statistics);
  1498. wl->static_data_priv_len = sizeof(struct wl18xx_static_data_priv);
  1499. if (num_rx_desc_param != -1)
  1500. wl->num_rx_desc = num_rx_desc_param;
  1501. ret = wl18xx_conf_init(wl, wl->dev);
  1502. if (ret < 0)
  1503. return ret;
  1504. /* If the module param is set, update it in conf */
  1505. if (board_type_param) {
  1506. if (!strcmp(board_type_param, "fpga")) {
  1507. priv->conf.phy.board_type = BOARD_TYPE_FPGA_18XX;
  1508. } else if (!strcmp(board_type_param, "hdk")) {
  1509. priv->conf.phy.board_type = BOARD_TYPE_HDK_18XX;
  1510. } else if (!strcmp(board_type_param, "dvp")) {
  1511. priv->conf.phy.board_type = BOARD_TYPE_DVP_18XX;
  1512. } else if (!strcmp(board_type_param, "evb")) {
  1513. priv->conf.phy.board_type = BOARD_TYPE_EVB_18XX;
  1514. } else if (!strcmp(board_type_param, "com8")) {
  1515. priv->conf.phy.board_type = BOARD_TYPE_COM8_18XX;
  1516. } else {
  1517. wl1271_error("invalid board type '%s'",
  1518. board_type_param);
  1519. return -EINVAL;
  1520. }
  1521. }
  1522. if (priv->conf.phy.board_type >= NUM_BOARD_TYPES) {
  1523. wl1271_error("invalid board type '%d'",
  1524. priv->conf.phy.board_type);
  1525. return -EINVAL;
  1526. }
  1527. if (low_band_component_param != -1)
  1528. priv->conf.phy.low_band_component = low_band_component_param;
  1529. if (low_band_component_type_param != -1)
  1530. priv->conf.phy.low_band_component_type =
  1531. low_band_component_type_param;
  1532. if (high_band_component_param != -1)
  1533. priv->conf.phy.high_band_component = high_band_component_param;
  1534. if (high_band_component_type_param != -1)
  1535. priv->conf.phy.high_band_component_type =
  1536. high_band_component_type_param;
  1537. if (pwr_limit_reference_11_abg_param != -1)
  1538. priv->conf.phy.pwr_limit_reference_11_abg =
  1539. pwr_limit_reference_11_abg_param;
  1540. if (n_antennas_2_param != -1)
  1541. priv->conf.phy.number_of_assembled_ant2_4 = n_antennas_2_param;
  1542. if (n_antennas_5_param != -1)
  1543. priv->conf.phy.number_of_assembled_ant5 = n_antennas_5_param;
  1544. if (dc2dc_param != -1)
  1545. priv->conf.phy.external_pa_dc2dc = dc2dc_param;
  1546. if (ht_mode_param) {
  1547. if (!strcmp(ht_mode_param, "default"))
  1548. priv->conf.ht.mode = HT_MODE_DEFAULT;
  1549. else if (!strcmp(ht_mode_param, "wide"))
  1550. priv->conf.ht.mode = HT_MODE_WIDE;
  1551. else if (!strcmp(ht_mode_param, "siso20"))
  1552. priv->conf.ht.mode = HT_MODE_SISO20;
  1553. else {
  1554. wl1271_error("invalid ht_mode '%s'", ht_mode_param);
  1555. return -EINVAL;
  1556. }
  1557. }
  1558. if (priv->conf.ht.mode == HT_MODE_DEFAULT) {
  1559. /*
  1560. * Only support mimo with multiple antennas. Fall back to
  1561. * siso40.
  1562. */
  1563. if (wl18xx_is_mimo_supported(wl))
  1564. wlcore_set_ht_cap(wl, IEEE80211_BAND_2GHZ,
  1565. &wl18xx_mimo_ht_cap_2ghz);
  1566. else
  1567. wlcore_set_ht_cap(wl, IEEE80211_BAND_2GHZ,
  1568. &wl18xx_siso40_ht_cap_2ghz);
  1569. /* 5Ghz is always wide */
  1570. wlcore_set_ht_cap(wl, IEEE80211_BAND_5GHZ,
  1571. &wl18xx_siso40_ht_cap_5ghz);
  1572. } else if (priv->conf.ht.mode == HT_MODE_WIDE) {
  1573. wlcore_set_ht_cap(wl, IEEE80211_BAND_2GHZ,
  1574. &wl18xx_siso40_ht_cap_2ghz);
  1575. wlcore_set_ht_cap(wl, IEEE80211_BAND_5GHZ,
  1576. &wl18xx_siso40_ht_cap_5ghz);
  1577. } else if (priv->conf.ht.mode == HT_MODE_SISO20) {
  1578. wlcore_set_ht_cap(wl, IEEE80211_BAND_2GHZ,
  1579. &wl18xx_siso20_ht_cap);
  1580. wlcore_set_ht_cap(wl, IEEE80211_BAND_5GHZ,
  1581. &wl18xx_siso20_ht_cap);
  1582. }
  1583. if (!checksum_param) {
  1584. wl18xx_ops.set_rx_csum = NULL;
  1585. wl18xx_ops.init_vif = NULL;
  1586. }
  1587. /* Enable 11a Band only if we have 5G antennas */
  1588. wl->enable_11a = (priv->conf.phy.number_of_assembled_ant5 != 0);
  1589. return 0;
  1590. }
  1591. static int wl18xx_probe(struct platform_device *pdev)
  1592. {
  1593. struct wl1271 *wl;
  1594. struct ieee80211_hw *hw;
  1595. int ret;
  1596. hw = wlcore_alloc_hw(sizeof(struct wl18xx_priv),
  1597. WL18XX_AGGR_BUFFER_SIZE,
  1598. sizeof(struct wl18xx_event_mailbox));
  1599. if (IS_ERR(hw)) {
  1600. wl1271_error("can't allocate hw");
  1601. ret = PTR_ERR(hw);
  1602. goto out;
  1603. }
  1604. wl = hw->priv;
  1605. wl->ops = &wl18xx_ops;
  1606. wl->ptable = wl18xx_ptable;
  1607. ret = wlcore_probe(wl, pdev);
  1608. if (ret)
  1609. goto out_free;
  1610. return ret;
  1611. out_free:
  1612. wlcore_free_hw(wl);
  1613. out:
  1614. return ret;
  1615. }
  1616. static const struct platform_device_id wl18xx_id_table[] = {
  1617. { "wl18xx", 0 },
  1618. { } /* Terminating Entry */
  1619. };
  1620. MODULE_DEVICE_TABLE(platform, wl18xx_id_table);
  1621. static struct platform_driver wl18xx_driver = {
  1622. .probe = wl18xx_probe,
  1623. .remove = wlcore_remove,
  1624. .id_table = wl18xx_id_table,
  1625. .driver = {
  1626. .name = "wl18xx_driver",
  1627. .owner = THIS_MODULE,
  1628. }
  1629. };
  1630. module_platform_driver(wl18xx_driver);
  1631. module_param_named(ht_mode, ht_mode_param, charp, S_IRUSR);
  1632. MODULE_PARM_DESC(ht_mode, "Force HT mode: wide or siso20");
  1633. module_param_named(board_type, board_type_param, charp, S_IRUSR);
  1634. MODULE_PARM_DESC(board_type, "Board type: fpga, hdk (default), evb, com8 or "
  1635. "dvp");
  1636. module_param_named(checksum, checksum_param, bool, S_IRUSR);
  1637. MODULE_PARM_DESC(checksum, "Enable TCP checksum: boolean (defaults to false)");
  1638. module_param_named(dc2dc, dc2dc_param, int, S_IRUSR);
  1639. MODULE_PARM_DESC(dc2dc, "External DC2DC: u8 (defaults to 0)");
  1640. module_param_named(n_antennas_2, n_antennas_2_param, int, S_IRUSR);
  1641. MODULE_PARM_DESC(n_antennas_2,
  1642. "Number of installed 2.4GHz antennas: 1 (default) or 2");
  1643. module_param_named(n_antennas_5, n_antennas_5_param, int, S_IRUSR);
  1644. MODULE_PARM_DESC(n_antennas_5,
  1645. "Number of installed 5GHz antennas: 1 (default) or 2");
  1646. module_param_named(low_band_component, low_band_component_param, int,
  1647. S_IRUSR);
  1648. MODULE_PARM_DESC(low_band_component, "Low band component: u8 "
  1649. "(default is 0x01)");
  1650. module_param_named(low_band_component_type, low_band_component_type_param,
  1651. int, S_IRUSR);
  1652. MODULE_PARM_DESC(low_band_component_type, "Low band component type: u8 "
  1653. "(default is 0x05 or 0x06 depending on the board_type)");
  1654. module_param_named(high_band_component, high_band_component_param, int,
  1655. S_IRUSR);
  1656. MODULE_PARM_DESC(high_band_component, "High band component: u8, "
  1657. "(default is 0x01)");
  1658. module_param_named(high_band_component_type, high_band_component_type_param,
  1659. int, S_IRUSR);
  1660. MODULE_PARM_DESC(high_band_component_type, "High band component type: u8 "
  1661. "(default is 0x09)");
  1662. module_param_named(pwr_limit_reference_11_abg,
  1663. pwr_limit_reference_11_abg_param, int, S_IRUSR);
  1664. MODULE_PARM_DESC(pwr_limit_reference_11_abg, "Power limit reference: u8 "
  1665. "(default is 0xc8)");
  1666. module_param_named(num_rx_desc,
  1667. num_rx_desc_param, int, S_IRUSR);
  1668. MODULE_PARM_DESC(num_rx_desc_param,
  1669. "Number of Rx descriptors: u8 (default is 32)");
  1670. MODULE_LICENSE("GPL v2");
  1671. MODULE_AUTHOR("Luciano Coelho <coelho@ti.com>");
  1672. MODULE_FIRMWARE(WL18XX_FW_NAME);