main.c 50 KB

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