main.c 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * This file is part of wl18xx
  4. *
  5. * Copyright (C) 2011 Texas Instruments
  6. */
  7. #include <linux/module.h>
  8. #include <linux/mod_devicetable.h>
  9. #include <linux/platform_device.h>
  10. #include <linux/ip.h>
  11. #include <linux/firmware.h>
  12. #include <linux/etherdevice.h>
  13. #include <linux/irq.h>
  14. #include "../wlcore/wlcore.h"
  15. #include "../wlcore/debug.h"
  16. #include "../wlcore/io.h"
  17. #include "../wlcore/acx.h"
  18. #include "../wlcore/tx.h"
  19. #include "../wlcore/rx.h"
  20. #include "../wlcore/boot.h"
  21. #include "reg.h"
  22. #include "conf.h"
  23. #include "cmd.h"
  24. #include "acx.h"
  25. #include "tx.h"
  26. #include "wl18xx.h"
  27. #include "io.h"
  28. #include "scan.h"
  29. #include "event.h"
  30. #include "debugfs.h"
  31. #define WL18XX_RX_CHECKSUM_MASK 0x40
  32. static char *ht_mode_param = NULL;
  33. static char *board_type_param = NULL;
  34. static bool checksum_param = false;
  35. static int num_rx_desc_param = -1;
  36. /* phy paramters */
  37. static int dc2dc_param = -1;
  38. static int n_antennas_2_param = -1;
  39. static int n_antennas_5_param = -1;
  40. static int low_band_component_param = -1;
  41. static int low_band_component_type_param = -1;
  42. static int high_band_component_param = -1;
  43. static int high_band_component_type_param = -1;
  44. static int pwr_limit_reference_11_abg_param = -1;
  45. static const u8 wl18xx_rate_to_idx_2ghz[] = {
  46. /* MCS rates are used only with 11n */
  47. 15, /* WL18XX_CONF_HW_RXTX_RATE_MCS15 */
  48. 14, /* WL18XX_CONF_HW_RXTX_RATE_MCS14 */
  49. 13, /* WL18XX_CONF_HW_RXTX_RATE_MCS13 */
  50. 12, /* WL18XX_CONF_HW_RXTX_RATE_MCS12 */
  51. 11, /* WL18XX_CONF_HW_RXTX_RATE_MCS11 */
  52. 10, /* WL18XX_CONF_HW_RXTX_RATE_MCS10 */
  53. 9, /* WL18XX_CONF_HW_RXTX_RATE_MCS9 */
  54. 8, /* WL18XX_CONF_HW_RXTX_RATE_MCS8 */
  55. 7, /* WL18XX_CONF_HW_RXTX_RATE_MCS7 */
  56. 6, /* WL18XX_CONF_HW_RXTX_RATE_MCS6 */
  57. 5, /* WL18XX_CONF_HW_RXTX_RATE_MCS5 */
  58. 4, /* WL18XX_CONF_HW_RXTX_RATE_MCS4 */
  59. 3, /* WL18XX_CONF_HW_RXTX_RATE_MCS3 */
  60. 2, /* WL18XX_CONF_HW_RXTX_RATE_MCS2 */
  61. 1, /* WL18XX_CONF_HW_RXTX_RATE_MCS1 */
  62. 0, /* WL18XX_CONF_HW_RXTX_RATE_MCS0 */
  63. 11, /* WL18XX_CONF_HW_RXTX_RATE_54 */
  64. 10, /* WL18XX_CONF_HW_RXTX_RATE_48 */
  65. 9, /* WL18XX_CONF_HW_RXTX_RATE_36 */
  66. 8, /* WL18XX_CONF_HW_RXTX_RATE_24 */
  67. /* TI-specific rate */
  68. CONF_HW_RXTX_RATE_UNSUPPORTED, /* WL18XX_CONF_HW_RXTX_RATE_22 */
  69. 7, /* WL18XX_CONF_HW_RXTX_RATE_18 */
  70. 6, /* WL18XX_CONF_HW_RXTX_RATE_12 */
  71. 3, /* WL18XX_CONF_HW_RXTX_RATE_11 */
  72. 5, /* WL18XX_CONF_HW_RXTX_RATE_9 */
  73. 4, /* WL18XX_CONF_HW_RXTX_RATE_6 */
  74. 2, /* WL18XX_CONF_HW_RXTX_RATE_5_5 */
  75. 1, /* WL18XX_CONF_HW_RXTX_RATE_2 */
  76. 0 /* WL18XX_CONF_HW_RXTX_RATE_1 */
  77. };
  78. static const u8 wl18xx_rate_to_idx_5ghz[] = {
  79. /* MCS rates are used only with 11n */
  80. 15, /* WL18XX_CONF_HW_RXTX_RATE_MCS15 */
  81. 14, /* WL18XX_CONF_HW_RXTX_RATE_MCS14 */
  82. 13, /* WL18XX_CONF_HW_RXTX_RATE_MCS13 */
  83. 12, /* WL18XX_CONF_HW_RXTX_RATE_MCS12 */
  84. 11, /* WL18XX_CONF_HW_RXTX_RATE_MCS11 */
  85. 10, /* WL18XX_CONF_HW_RXTX_RATE_MCS10 */
  86. 9, /* WL18XX_CONF_HW_RXTX_RATE_MCS9 */
  87. 8, /* WL18XX_CONF_HW_RXTX_RATE_MCS8 */
  88. 7, /* WL18XX_CONF_HW_RXTX_RATE_MCS7 */
  89. 6, /* WL18XX_CONF_HW_RXTX_RATE_MCS6 */
  90. 5, /* WL18XX_CONF_HW_RXTX_RATE_MCS5 */
  91. 4, /* WL18XX_CONF_HW_RXTX_RATE_MCS4 */
  92. 3, /* WL18XX_CONF_HW_RXTX_RATE_MCS3 */
  93. 2, /* WL18XX_CONF_HW_RXTX_RATE_MCS2 */
  94. 1, /* WL18XX_CONF_HW_RXTX_RATE_MCS1 */
  95. 0, /* WL18XX_CONF_HW_RXTX_RATE_MCS0 */
  96. 7, /* WL18XX_CONF_HW_RXTX_RATE_54 */
  97. 6, /* WL18XX_CONF_HW_RXTX_RATE_48 */
  98. 5, /* WL18XX_CONF_HW_RXTX_RATE_36 */
  99. 4, /* WL18XX_CONF_HW_RXTX_RATE_24 */
  100. /* TI-specific rate */
  101. CONF_HW_RXTX_RATE_UNSUPPORTED, /* WL18XX_CONF_HW_RXTX_RATE_22 */
  102. 3, /* WL18XX_CONF_HW_RXTX_RATE_18 */
  103. 2, /* WL18XX_CONF_HW_RXTX_RATE_12 */
  104. CONF_HW_RXTX_RATE_UNSUPPORTED, /* WL18XX_CONF_HW_RXTX_RATE_11 */
  105. 1, /* WL18XX_CONF_HW_RXTX_RATE_9 */
  106. 0, /* WL18XX_CONF_HW_RXTX_RATE_6 */
  107. CONF_HW_RXTX_RATE_UNSUPPORTED, /* WL18XX_CONF_HW_RXTX_RATE_5_5 */
  108. CONF_HW_RXTX_RATE_UNSUPPORTED, /* WL18XX_CONF_HW_RXTX_RATE_2 */
  109. CONF_HW_RXTX_RATE_UNSUPPORTED, /* WL18XX_CONF_HW_RXTX_RATE_1 */
  110. };
  111. static const u8 *wl18xx_band_rate_to_idx[] = {
  112. [NL80211_BAND_2GHZ] = wl18xx_rate_to_idx_2ghz,
  113. [NL80211_BAND_5GHZ] = wl18xx_rate_to_idx_5ghz
  114. };
  115. enum wl18xx_hw_rates {
  116. WL18XX_CONF_HW_RXTX_RATE_MCS15 = 0,
  117. WL18XX_CONF_HW_RXTX_RATE_MCS14,
  118. WL18XX_CONF_HW_RXTX_RATE_MCS13,
  119. WL18XX_CONF_HW_RXTX_RATE_MCS12,
  120. WL18XX_CONF_HW_RXTX_RATE_MCS11,
  121. WL18XX_CONF_HW_RXTX_RATE_MCS10,
  122. WL18XX_CONF_HW_RXTX_RATE_MCS9,
  123. WL18XX_CONF_HW_RXTX_RATE_MCS8,
  124. WL18XX_CONF_HW_RXTX_RATE_MCS7,
  125. WL18XX_CONF_HW_RXTX_RATE_MCS6,
  126. WL18XX_CONF_HW_RXTX_RATE_MCS5,
  127. WL18XX_CONF_HW_RXTX_RATE_MCS4,
  128. WL18XX_CONF_HW_RXTX_RATE_MCS3,
  129. WL18XX_CONF_HW_RXTX_RATE_MCS2,
  130. WL18XX_CONF_HW_RXTX_RATE_MCS1,
  131. WL18XX_CONF_HW_RXTX_RATE_MCS0,
  132. WL18XX_CONF_HW_RXTX_RATE_54,
  133. WL18XX_CONF_HW_RXTX_RATE_48,
  134. WL18XX_CONF_HW_RXTX_RATE_36,
  135. WL18XX_CONF_HW_RXTX_RATE_24,
  136. WL18XX_CONF_HW_RXTX_RATE_22,
  137. WL18XX_CONF_HW_RXTX_RATE_18,
  138. WL18XX_CONF_HW_RXTX_RATE_12,
  139. WL18XX_CONF_HW_RXTX_RATE_11,
  140. WL18XX_CONF_HW_RXTX_RATE_9,
  141. WL18XX_CONF_HW_RXTX_RATE_6,
  142. WL18XX_CONF_HW_RXTX_RATE_5_5,
  143. WL18XX_CONF_HW_RXTX_RATE_2,
  144. WL18XX_CONF_HW_RXTX_RATE_1,
  145. WL18XX_CONF_HW_RXTX_RATE_MAX,
  146. };
  147. static struct wlcore_conf wl18xx_conf = {
  148. .sg = {
  149. .params = {
  150. [WL18XX_CONF_SG_PARAM_0] = 0,
  151. /* Configuration Parameters */
  152. [WL18XX_CONF_SG_ANTENNA_CONFIGURATION] = 0,
  153. [WL18XX_CONF_SG_ZIGBEE_COEX] = 0,
  154. [WL18XX_CONF_SG_TIME_SYNC] = 0,
  155. [WL18XX_CONF_SG_PARAM_4] = 0,
  156. [WL18XX_CONF_SG_PARAM_5] = 0,
  157. [WL18XX_CONF_SG_PARAM_6] = 0,
  158. [WL18XX_CONF_SG_PARAM_7] = 0,
  159. [WL18XX_CONF_SG_PARAM_8] = 0,
  160. [WL18XX_CONF_SG_PARAM_9] = 0,
  161. [WL18XX_CONF_SG_PARAM_10] = 0,
  162. [WL18XX_CONF_SG_PARAM_11] = 0,
  163. [WL18XX_CONF_SG_PARAM_12] = 0,
  164. [WL18XX_CONF_SG_PARAM_13] = 0,
  165. [WL18XX_CONF_SG_PARAM_14] = 0,
  166. [WL18XX_CONF_SG_PARAM_15] = 0,
  167. [WL18XX_CONF_SG_PARAM_16] = 0,
  168. [WL18XX_CONF_SG_PARAM_17] = 0,
  169. [WL18XX_CONF_SG_PARAM_18] = 0,
  170. [WL18XX_CONF_SG_PARAM_19] = 0,
  171. [WL18XX_CONF_SG_PARAM_20] = 0,
  172. [WL18XX_CONF_SG_PARAM_21] = 0,
  173. [WL18XX_CONF_SG_PARAM_22] = 0,
  174. [WL18XX_CONF_SG_PARAM_23] = 0,
  175. [WL18XX_CONF_SG_PARAM_24] = 0,
  176. [WL18XX_CONF_SG_PARAM_25] = 0,
  177. /* Active Scan Parameters */
  178. [WL18XX_CONF_SG_AUTO_SCAN_PROBE_REQ] = 170,
  179. [WL18XX_CONF_SG_ACTIVE_SCAN_DURATION_FACTOR_HV3] = 50,
  180. [WL18XX_CONF_SG_PARAM_28] = 0,
  181. /* Passive Scan Parameters */
  182. [WL18XX_CONF_SG_PARAM_29] = 0,
  183. [WL18XX_CONF_SG_PARAM_30] = 0,
  184. [WL18XX_CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_HV3] = 200,
  185. /* Passive Scan in Dual Antenna Parameters */
  186. [WL18XX_CONF_SG_CONSECUTIVE_HV3_IN_PASSIVE_SCAN] = 0,
  187. [WL18XX_CONF_SG_BEACON_HV3_COLL_TH_IN_PASSIVE_SCAN] = 0,
  188. [WL18XX_CONF_SG_TX_RX_PROTECT_BW_IN_PASSIVE_SCAN] = 0,
  189. /* General Parameters */
  190. [WL18XX_CONF_SG_STA_FORCE_PS_IN_BT_SCO] = 1,
  191. [WL18XX_CONF_SG_PARAM_36] = 0,
  192. [WL18XX_CONF_SG_BEACON_MISS_PERCENT] = 60,
  193. [WL18XX_CONF_SG_PARAM_38] = 0,
  194. [WL18XX_CONF_SG_RXT] = 1200,
  195. [WL18XX_CONF_SG_UNUSED] = 0,
  196. [WL18XX_CONF_SG_ADAPTIVE_RXT_TXT] = 1,
  197. [WL18XX_CONF_SG_GENERAL_USAGE_BIT_MAP] = 3,
  198. [WL18XX_CONF_SG_HV3_MAX_SERVED] = 6,
  199. [WL18XX_CONF_SG_PARAM_44] = 0,
  200. [WL18XX_CONF_SG_PARAM_45] = 0,
  201. [WL18XX_CONF_SG_CONSECUTIVE_CTS_THRESHOLD] = 2,
  202. [WL18XX_CONF_SG_GEMINI_PARAM_47] = 0,
  203. [WL18XX_CONF_SG_STA_CONNECTION_PROTECTION_TIME] = 0,
  204. /* AP Parameters */
  205. [WL18XX_CONF_SG_AP_BEACON_MISS_TX] = 3,
  206. [WL18XX_CONF_SG_PARAM_50] = 0,
  207. [WL18XX_CONF_SG_AP_BEACON_WINDOW_INTERVAL] = 2,
  208. [WL18XX_CONF_SG_AP_CONNECTION_PROTECTION_TIME] = 30,
  209. [WL18XX_CONF_SG_PARAM_53] = 0,
  210. [WL18XX_CONF_SG_PARAM_54] = 0,
  211. /* CTS Diluting Parameters */
  212. [WL18XX_CONF_SG_CTS_DILUTED_BAD_RX_PACKETS_TH] = 0,
  213. [WL18XX_CONF_SG_CTS_CHOP_IN_DUAL_ANT_SCO_MASTER] = 0,
  214. [WL18XX_CONF_SG_TEMP_PARAM_1] = 0,
  215. [WL18XX_CONF_SG_TEMP_PARAM_2] = 0,
  216. [WL18XX_CONF_SG_TEMP_PARAM_3] = 0,
  217. [WL18XX_CONF_SG_TEMP_PARAM_4] = 0,
  218. [WL18XX_CONF_SG_TEMP_PARAM_5] = 0,
  219. [WL18XX_CONF_SG_TEMP_PARAM_6] = 0,
  220. [WL18XX_CONF_SG_TEMP_PARAM_7] = 0,
  221. [WL18XX_CONF_SG_TEMP_PARAM_8] = 0,
  222. [WL18XX_CONF_SG_TEMP_PARAM_9] = 0,
  223. [WL18XX_CONF_SG_TEMP_PARAM_10] = 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. .slow_link_thold = 3,
  324. .fast_link_thold = 30,
  325. },
  326. .conn = {
  327. .wake_up_event = CONF_WAKE_UP_EVENT_DTIM,
  328. .listen_interval = 1,
  329. .suspend_wake_up_event = CONF_WAKE_UP_EVENT_N_DTIM,
  330. .suspend_listen_interval = 3,
  331. .bcn_filt_mode = CONF_BCN_FILT_MODE_ENABLED,
  332. .bcn_filt_ie_count = 3,
  333. .bcn_filt_ie = {
  334. [0] = {
  335. .ie = WLAN_EID_CHANNEL_SWITCH,
  336. .rule = CONF_BCN_RULE_PASS_ON_APPEARANCE,
  337. },
  338. [1] = {
  339. .ie = WLAN_EID_HT_OPERATION,
  340. .rule = CONF_BCN_RULE_PASS_ON_CHANGE,
  341. },
  342. [2] = {
  343. .ie = WLAN_EID_ERP_INFO,
  344. .rule = CONF_BCN_RULE_PASS_ON_CHANGE,
  345. },
  346. },
  347. .synch_fail_thold = 12,
  348. .bss_lose_timeout = 400,
  349. .beacon_rx_timeout = 10000,
  350. .broadcast_timeout = 20000,
  351. .rx_broadcast_in_ps = 1,
  352. .ps_poll_threshold = 10,
  353. .bet_enable = CONF_BET_MODE_ENABLE,
  354. .bet_max_consecutive = 50,
  355. .psm_entry_retries = 8,
  356. .psm_exit_retries = 16,
  357. .psm_entry_nullfunc_retries = 3,
  358. .dynamic_ps_timeout = 1500,
  359. .forced_ps = false,
  360. .keep_alive_interval = 55000,
  361. .max_listen_interval = 20,
  362. .sta_sleep_auth = WL1271_PSM_ILLEGAL,
  363. .suspend_rx_ba_activity = 0,
  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. .num_short_intervals = SCAN_MAX_SHORT_INTERVALS,
  407. .long_interval = 30000,
  408. },
  409. .ht = {
  410. .rx_ba_win_size = 32,
  411. .tx_ba_win_size = 64,
  412. .inactivity_timeout = 10000,
  413. .tx_ba_tid_bitmap = CONF_TX_BA_ENABLED_TID_BITMAP,
  414. },
  415. .mem = {
  416. .num_stations = 1,
  417. .ssid_profiles = 1,
  418. .rx_block_num = 40,
  419. .tx_min_block_num = 40,
  420. .dynamic_memory = 1,
  421. .min_req_tx_blocks = 45,
  422. .min_req_rx_blocks = 22,
  423. .tx_min = 27,
  424. },
  425. .fm_coex = {
  426. .enable = true,
  427. .swallow_period = 5,
  428. .n_divider_fref_set_1 = 0xff, /* default */
  429. .n_divider_fref_set_2 = 12,
  430. .m_divider_fref_set_1 = 0xffff,
  431. .m_divider_fref_set_2 = 148, /* default */
  432. .coex_pll_stabilization_time = 0xffffffff, /* default */
  433. .ldo_stabilization_time = 0xffff, /* default */
  434. .fm_disturbed_band_margin = 0xff, /* default */
  435. .swallow_clk_diff = 0xff, /* default */
  436. },
  437. .rx_streaming = {
  438. .duration = 150,
  439. .queues = 0x1,
  440. .interval = 20,
  441. .always = 0,
  442. },
  443. .fwlog = {
  444. .mode = WL12XX_FWLOG_CONTINUOUS,
  445. .mem_blocks = 0,
  446. .severity = 0,
  447. .timestamp = WL12XX_FWLOG_TIMESTAMP_DISABLED,
  448. .output = WL12XX_FWLOG_OUTPUT_DBG_PINS,
  449. .threshold = 0,
  450. },
  451. .rate = {
  452. .rate_retry_score = 32000,
  453. .per_add = 8192,
  454. .per_th1 = 2048,
  455. .per_th2 = 4096,
  456. .max_per = 8100,
  457. .inverse_curiosity_factor = 5,
  458. .tx_fail_low_th = 4,
  459. .tx_fail_high_th = 10,
  460. .per_alpha_shift = 4,
  461. .per_add_shift = 13,
  462. .per_beta1_shift = 10,
  463. .per_beta2_shift = 8,
  464. .rate_check_up = 2,
  465. .rate_check_down = 12,
  466. .rate_retry_policy = {
  467. 0x00, 0x00, 0x00, 0x00, 0x00,
  468. 0x00, 0x00, 0x00, 0x00, 0x00,
  469. 0x00, 0x00, 0x00,
  470. },
  471. },
  472. .hangover = {
  473. .recover_time = 0,
  474. .hangover_period = 20,
  475. .dynamic_mode = 1,
  476. .early_termination_mode = 1,
  477. .max_period = 20,
  478. .min_period = 1,
  479. .increase_delta = 1,
  480. .decrease_delta = 2,
  481. .quiet_time = 4,
  482. .increase_time = 1,
  483. .window_size = 16,
  484. },
  485. .recovery = {
  486. .bug_on_recovery = 0,
  487. .no_recovery = 0,
  488. },
  489. };
  490. static struct wl18xx_priv_conf wl18xx_default_priv_conf = {
  491. .ht = {
  492. .mode = HT_MODE_WIDE,
  493. },
  494. .phy = {
  495. .phy_standalone = 0x00,
  496. .primary_clock_setting_time = 0x05,
  497. .clock_valid_on_wake_up = 0x00,
  498. .secondary_clock_setting_time = 0x05,
  499. .board_type = BOARD_TYPE_HDK_18XX,
  500. .auto_detect = 0x00,
  501. .dedicated_fem = FEM_NONE,
  502. .low_band_component = COMPONENT_3_WAY_SWITCH,
  503. .low_band_component_type = 0x05,
  504. .high_band_component = COMPONENT_2_WAY_SWITCH,
  505. .high_band_component_type = 0x09,
  506. .tcxo_ldo_voltage = 0x00,
  507. .xtal_itrim_val = 0x04,
  508. .srf_state = 0x00,
  509. .io_configuration = 0x01,
  510. .sdio_configuration = 0x00,
  511. .settings = 0x00,
  512. .enable_clpc = 0x00,
  513. .enable_tx_low_pwr_on_siso_rdl = 0x00,
  514. .rx_profile = 0x00,
  515. .pwr_limit_reference_11_abg = 0x64,
  516. .per_chan_pwr_limit_arr_11abg = {
  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, 0xff, 0xff, 0xff,
  532. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  533. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
  534. .pwr_limit_reference_11p = 0x64,
  535. .per_chan_bo_mode_11_abg = { 0x00, 0x00, 0x00, 0x00,
  536. 0x00, 0x00, 0x00, 0x00,
  537. 0x00, 0x00, 0x00, 0x00,
  538. 0x00 },
  539. .per_chan_bo_mode_11_p = { 0x00, 0x00, 0x00, 0x00 },
  540. .per_chan_pwr_limit_arr_11p = { 0xff, 0xff, 0xff, 0xff,
  541. 0xff, 0xff, 0xff },
  542. .psat = 0,
  543. .external_pa_dc2dc = 0,
  544. .number_of_assembled_ant2_4 = 2,
  545. .number_of_assembled_ant5 = 1,
  546. .low_power_val = 0xff,
  547. .med_power_val = 0xff,
  548. .high_power_val = 0xff,
  549. .low_power_val_2nd = 0xff,
  550. .med_power_val_2nd = 0xff,
  551. .high_power_val_2nd = 0xff,
  552. .tx_rf_margin = 1,
  553. },
  554. .ap_sleep = { /* disabled by default */
  555. .idle_duty_cycle = 0,
  556. .connected_duty_cycle = 0,
  557. .max_stations_thresh = 0,
  558. .idle_conn_thresh = 0,
  559. },
  560. };
  561. static const struct wlcore_partition_set wl18xx_ptable[PART_TABLE_LEN] = {
  562. [PART_TOP_PRCM_ELP_SOC] = {
  563. .mem = { .start = 0x00A00000, .size = 0x00012000 },
  564. .reg = { .start = 0x00807000, .size = 0x00005000 },
  565. .mem2 = { .start = 0x00800000, .size = 0x0000B000 },
  566. .mem3 = { .start = 0x00401594, .size = 0x00001020 },
  567. },
  568. [PART_DOWN] = {
  569. .mem = { .start = 0x00000000, .size = 0x00014000 },
  570. .reg = { .start = 0x00810000, .size = 0x0000BFFF },
  571. .mem2 = { .start = 0x00000000, .size = 0x00000000 },
  572. .mem3 = { .start = 0x00000000, .size = 0x00000000 },
  573. },
  574. [PART_BOOT] = {
  575. .mem = { .start = 0x00700000, .size = 0x0000030c },
  576. .reg = { .start = 0x00802000, .size = 0x00014578 },
  577. .mem2 = { .start = 0x00B00404, .size = 0x00001000 },
  578. .mem3 = { .start = 0x00C00000, .size = 0x00000400 },
  579. },
  580. [PART_WORK] = {
  581. .mem = { .start = 0x00800000, .size = 0x000050FC },
  582. .reg = { .start = 0x00B00404, .size = 0x00001000 },
  583. .mem2 = { .start = 0x00C00000, .size = 0x00000400 },
  584. .mem3 = { .start = 0x00401594, .size = 0x00001020 },
  585. },
  586. [PART_PHY_INIT] = {
  587. .mem = { .start = WL18XX_PHY_INIT_MEM_ADDR,
  588. .size = WL18XX_PHY_INIT_MEM_SIZE },
  589. .reg = { .start = 0x00000000, .size = 0x00000000 },
  590. .mem2 = { .start = 0x00000000, .size = 0x00000000 },
  591. .mem3 = { .start = 0x00000000, .size = 0x00000000 },
  592. },
  593. };
  594. static const int wl18xx_rtable[REG_TABLE_LEN] = {
  595. [REG_ECPU_CONTROL] = WL18XX_REG_ECPU_CONTROL,
  596. [REG_INTERRUPT_NO_CLEAR] = WL18XX_REG_INTERRUPT_NO_CLEAR,
  597. [REG_INTERRUPT_ACK] = WL18XX_REG_INTERRUPT_ACK,
  598. [REG_COMMAND_MAILBOX_PTR] = WL18XX_REG_COMMAND_MAILBOX_PTR,
  599. [REG_EVENT_MAILBOX_PTR] = WL18XX_REG_EVENT_MAILBOX_PTR,
  600. [REG_INTERRUPT_TRIG] = WL18XX_REG_INTERRUPT_TRIG_H,
  601. [REG_INTERRUPT_MASK] = WL18XX_REG_INTERRUPT_MASK,
  602. [REG_PC_ON_RECOVERY] = WL18XX_SCR_PAD4,
  603. [REG_CHIP_ID_B] = WL18XX_REG_CHIP_ID_B,
  604. [REG_CMD_MBOX_ADDRESS] = WL18XX_CMD_MBOX_ADDRESS,
  605. /* data access memory addresses, used with partition translation */
  606. [REG_SLV_MEM_DATA] = WL18XX_SLV_MEM_DATA,
  607. [REG_SLV_REG_DATA] = WL18XX_SLV_REG_DATA,
  608. /* raw data access memory addresses */
  609. [REG_RAW_FW_STATUS_ADDR] = WL18XX_FW_STATUS_ADDR,
  610. };
  611. static const struct wl18xx_clk_cfg wl18xx_clk_table_coex[NUM_CLOCK_CONFIGS] = {
  612. [CLOCK_CONFIG_16_2_M] = { 8, 121, 0, 0, false },
  613. [CLOCK_CONFIG_16_368_M] = { 8, 120, 0, 0, false },
  614. [CLOCK_CONFIG_16_8_M] = { 8, 117, 0, 0, false },
  615. [CLOCK_CONFIG_19_2_M] = { 10, 128, 0, 0, false },
  616. [CLOCK_CONFIG_26_M] = { 11, 104, 0, 0, false },
  617. [CLOCK_CONFIG_32_736_M] = { 8, 120, 0, 0, false },
  618. [CLOCK_CONFIG_33_6_M] = { 8, 117, 0, 0, false },
  619. [CLOCK_CONFIG_38_468_M] = { 10, 128, 0, 0, false },
  620. [CLOCK_CONFIG_52_M] = { 11, 104, 0, 0, false },
  621. };
  622. static const struct wl18xx_clk_cfg wl18xx_clk_table[NUM_CLOCK_CONFIGS] = {
  623. [CLOCK_CONFIG_16_2_M] = { 7, 104, 801, 4, true },
  624. [CLOCK_CONFIG_16_368_M] = { 9, 132, 3751, 4, true },
  625. [CLOCK_CONFIG_16_8_M] = { 7, 100, 0, 0, false },
  626. [CLOCK_CONFIG_19_2_M] = { 8, 100, 0, 0, false },
  627. [CLOCK_CONFIG_26_M] = { 13, 120, 0, 0, false },
  628. [CLOCK_CONFIG_32_736_M] = { 9, 132, 3751, 4, true },
  629. [CLOCK_CONFIG_33_6_M] = { 7, 100, 0, 0, false },
  630. [CLOCK_CONFIG_38_468_M] = { 8, 100, 0, 0, false },
  631. [CLOCK_CONFIG_52_M] = { 13, 120, 0, 0, false },
  632. };
  633. /* TODO: maybe move to a new header file? */
  634. #define WL18XX_FW_NAME "ti-connectivity/wl18xx-fw-4.bin"
  635. static int wl18xx_identify_chip(struct wl1271 *wl)
  636. {
  637. int ret = 0;
  638. switch (wl->chip.id) {
  639. case CHIP_ID_185x_PG20:
  640. wl1271_debug(DEBUG_BOOT, "chip id 0x%x (185x PG20)",
  641. wl->chip.id);
  642. wl->sr_fw_name = WL18XX_FW_NAME;
  643. /* wl18xx uses the same firmware for PLT */
  644. wl->plt_fw_name = WL18XX_FW_NAME;
  645. wl->quirks |= WLCORE_QUIRK_RX_BLOCKSIZE_ALIGN |
  646. WLCORE_QUIRK_TX_BLOCKSIZE_ALIGN |
  647. WLCORE_QUIRK_NO_SCHED_SCAN_WHILE_CONN |
  648. WLCORE_QUIRK_TX_PAD_LAST_FRAME |
  649. WLCORE_QUIRK_REGDOMAIN_CONF |
  650. WLCORE_QUIRK_DUAL_PROBE_TMPL;
  651. wlcore_set_min_fw_ver(wl, WL18XX_CHIP_VER,
  652. WL18XX_IFTYPE_VER, WL18XX_MAJOR_VER,
  653. WL18XX_SUBTYPE_VER, WL18XX_MINOR_VER,
  654. /* there's no separate multi-role FW */
  655. 0, 0, 0, 0);
  656. break;
  657. case CHIP_ID_185x_PG10:
  658. wl1271_warning("chip id 0x%x (185x PG10) is deprecated",
  659. wl->chip.id);
  660. ret = -ENODEV;
  661. goto out;
  662. default:
  663. wl1271_warning("unsupported chip id: 0x%x", wl->chip.id);
  664. ret = -ENODEV;
  665. goto out;
  666. }
  667. wl->fw_mem_block_size = 272;
  668. wl->fwlog_end = 0x40000000;
  669. wl->scan_templ_id_2_4 = CMD_TEMPL_CFG_PROBE_REQ_2_4;
  670. wl->scan_templ_id_5 = CMD_TEMPL_CFG_PROBE_REQ_5;
  671. wl->sched_scan_templ_id_2_4 = CMD_TEMPL_PROBE_REQ_2_4_PERIODIC;
  672. wl->sched_scan_templ_id_5 = CMD_TEMPL_PROBE_REQ_5_PERIODIC;
  673. wl->max_channels_5 = WL18XX_MAX_CHANNELS_5GHZ;
  674. wl->ba_rx_session_count_max = WL18XX_RX_BA_MAX_SESSIONS;
  675. out:
  676. return ret;
  677. }
  678. static int wl18xx_set_clk(struct wl1271 *wl)
  679. {
  680. u16 clk_freq;
  681. int ret;
  682. ret = wlcore_set_partition(wl, &wl->ptable[PART_TOP_PRCM_ELP_SOC]);
  683. if (ret < 0)
  684. goto out;
  685. /* TODO: PG2: apparently we need to read the clk type */
  686. ret = wl18xx_top_reg_read(wl, PRIMARY_CLK_DETECT, &clk_freq);
  687. if (ret < 0)
  688. goto out;
  689. wl1271_debug(DEBUG_BOOT, "clock freq %d (%d, %d, %d, %d, %s)", clk_freq,
  690. wl18xx_clk_table[clk_freq].n, wl18xx_clk_table[clk_freq].m,
  691. wl18xx_clk_table[clk_freq].p, wl18xx_clk_table[clk_freq].q,
  692. wl18xx_clk_table[clk_freq].swallow ? "swallow" : "spit");
  693. /* coex PLL configuration */
  694. ret = wl18xx_top_reg_write(wl, PLLSH_COEX_PLL_N,
  695. wl18xx_clk_table_coex[clk_freq].n);
  696. if (ret < 0)
  697. goto out;
  698. ret = wl18xx_top_reg_write(wl, PLLSH_COEX_PLL_M,
  699. wl18xx_clk_table_coex[clk_freq].m);
  700. if (ret < 0)
  701. goto out;
  702. /* bypass the swallowing logic */
  703. ret = wl18xx_top_reg_write(wl, PLLSH_COEX_PLL_SWALLOW_EN,
  704. PLLSH_COEX_PLL_SWALLOW_EN_VAL1);
  705. if (ret < 0)
  706. goto out;
  707. ret = wl18xx_top_reg_write(wl, PLLSH_WCS_PLL_N,
  708. wl18xx_clk_table[clk_freq].n);
  709. if (ret < 0)
  710. goto out;
  711. ret = wl18xx_top_reg_write(wl, PLLSH_WCS_PLL_M,
  712. wl18xx_clk_table[clk_freq].m);
  713. if (ret < 0)
  714. goto out;
  715. if (wl18xx_clk_table[clk_freq].swallow) {
  716. /* first the 16 lower bits */
  717. ret = wl18xx_top_reg_write(wl, PLLSH_WCS_PLL_Q_FACTOR_CFG_1,
  718. wl18xx_clk_table[clk_freq].q &
  719. PLLSH_WCS_PLL_Q_FACTOR_CFG_1_MASK);
  720. if (ret < 0)
  721. goto out;
  722. /* then the 16 higher bits, masked out */
  723. ret = wl18xx_top_reg_write(wl, PLLSH_WCS_PLL_Q_FACTOR_CFG_2,
  724. (wl18xx_clk_table[clk_freq].q >> 16) &
  725. PLLSH_WCS_PLL_Q_FACTOR_CFG_2_MASK);
  726. if (ret < 0)
  727. goto out;
  728. /* first the 16 lower bits */
  729. ret = wl18xx_top_reg_write(wl, PLLSH_WCS_PLL_P_FACTOR_CFG_1,
  730. wl18xx_clk_table[clk_freq].p &
  731. PLLSH_WCS_PLL_P_FACTOR_CFG_1_MASK);
  732. if (ret < 0)
  733. goto out;
  734. /* then the 16 higher bits, masked out */
  735. ret = wl18xx_top_reg_write(wl, PLLSH_WCS_PLL_P_FACTOR_CFG_2,
  736. (wl18xx_clk_table[clk_freq].p >> 16) &
  737. PLLSH_WCS_PLL_P_FACTOR_CFG_2_MASK);
  738. if (ret < 0)
  739. goto out;
  740. } else {
  741. ret = wl18xx_top_reg_write(wl, PLLSH_WCS_PLL_SWALLOW_EN,
  742. PLLSH_WCS_PLL_SWALLOW_EN_VAL2);
  743. if (ret < 0)
  744. goto out;
  745. }
  746. /* choose WCS PLL */
  747. ret = wl18xx_top_reg_write(wl, PLLSH_WL_PLL_SEL,
  748. PLLSH_WL_PLL_SEL_WCS_PLL);
  749. if (ret < 0)
  750. goto out;
  751. /* enable both PLLs */
  752. ret = wl18xx_top_reg_write(wl, PLLSH_WL_PLL_EN, PLLSH_WL_PLL_EN_VAL1);
  753. if (ret < 0)
  754. goto out;
  755. udelay(1000);
  756. /* disable coex PLL */
  757. ret = wl18xx_top_reg_write(wl, PLLSH_WL_PLL_EN, PLLSH_WL_PLL_EN_VAL2);
  758. if (ret < 0)
  759. goto out;
  760. /* reset the swallowing logic */
  761. ret = wl18xx_top_reg_write(wl, PLLSH_COEX_PLL_SWALLOW_EN,
  762. PLLSH_COEX_PLL_SWALLOW_EN_VAL2);
  763. out:
  764. return ret;
  765. }
  766. static int wl18xx_boot_soft_reset(struct wl1271 *wl)
  767. {
  768. int ret;
  769. /* disable Rx/Tx */
  770. ret = wlcore_write32(wl, WL18XX_ENABLE, 0x0);
  771. if (ret < 0)
  772. goto out;
  773. /* disable auto calibration on start*/
  774. ret = wlcore_write32(wl, WL18XX_SPARE_A2, 0xffff);
  775. out:
  776. return ret;
  777. }
  778. static int wl18xx_pre_boot(struct wl1271 *wl)
  779. {
  780. int ret;
  781. ret = wl18xx_set_clk(wl);
  782. if (ret < 0)
  783. goto out;
  784. /* Continue the ELP wake up sequence */
  785. ret = wlcore_write32(wl, WL18XX_WELP_ARM_COMMAND, WELP_ARM_COMMAND_VAL);
  786. if (ret < 0)
  787. goto out;
  788. udelay(500);
  789. ret = wlcore_set_partition(wl, &wl->ptable[PART_BOOT]);
  790. if (ret < 0)
  791. goto out;
  792. /* Disable interrupts */
  793. ret = wlcore_write_reg(wl, REG_INTERRUPT_MASK, WL1271_ACX_INTR_ALL);
  794. if (ret < 0)
  795. goto out;
  796. ret = wl18xx_boot_soft_reset(wl);
  797. out:
  798. return ret;
  799. }
  800. static int wl18xx_pre_upload(struct wl1271 *wl)
  801. {
  802. u32 tmp;
  803. int ret;
  804. u16 irq_invert;
  805. BUILD_BUG_ON(sizeof(struct wl18xx_mac_and_phy_params) >
  806. WL18XX_PHY_INIT_MEM_SIZE);
  807. ret = wlcore_set_partition(wl, &wl->ptable[PART_BOOT]);
  808. if (ret < 0)
  809. goto out;
  810. /* TODO: check if this is all needed */
  811. ret = wlcore_write32(wl, WL18XX_EEPROMLESS_IND, WL18XX_EEPROMLESS_IND);
  812. if (ret < 0)
  813. goto out;
  814. ret = wlcore_read_reg(wl, REG_CHIP_ID_B, &tmp);
  815. if (ret < 0)
  816. goto out;
  817. wl1271_debug(DEBUG_BOOT, "chip id 0x%x", tmp);
  818. ret = wlcore_read32(wl, WL18XX_SCR_PAD2, &tmp);
  819. if (ret < 0)
  820. goto out;
  821. /*
  822. * Workaround for FDSP code RAM corruption (needed for PG2.1
  823. * and newer; for older chips it's a NOP). Change FDSP clock
  824. * settings so that it's muxed to the ATGP clock instead of
  825. * its own clock.
  826. */
  827. ret = wlcore_set_partition(wl, &wl->ptable[PART_PHY_INIT]);
  828. if (ret < 0)
  829. goto out;
  830. /* disable FDSP clock */
  831. ret = wlcore_write32(wl, WL18XX_PHY_FPGA_SPARE_1,
  832. MEM_FDSP_CLK_120_DISABLE);
  833. if (ret < 0)
  834. goto out;
  835. /* set ATPG clock toward FDSP Code RAM rather than its own clock */
  836. ret = wlcore_write32(wl, WL18XX_PHY_FPGA_SPARE_1,
  837. MEM_FDSP_CODERAM_FUNC_CLK_SEL);
  838. if (ret < 0)
  839. goto out;
  840. /* re-enable FDSP clock */
  841. ret = wlcore_write32(wl, WL18XX_PHY_FPGA_SPARE_1,
  842. MEM_FDSP_CLK_120_ENABLE);
  843. if (ret < 0)
  844. goto out;
  845. ret = irq_get_trigger_type(wl->irq);
  846. if ((ret == IRQ_TYPE_LEVEL_LOW) || (ret == IRQ_TYPE_EDGE_FALLING)) {
  847. wl1271_info("using inverted interrupt logic: %d", ret);
  848. ret = wlcore_set_partition(wl,
  849. &wl->ptable[PART_TOP_PRCM_ELP_SOC]);
  850. if (ret < 0)
  851. goto out;
  852. ret = wl18xx_top_reg_read(wl, TOP_FN0_CCCR_REG_32, &irq_invert);
  853. if (ret < 0)
  854. goto out;
  855. irq_invert |= BIT(1);
  856. ret = wl18xx_top_reg_write(wl, TOP_FN0_CCCR_REG_32, irq_invert);
  857. if (ret < 0)
  858. goto out;
  859. ret = wlcore_set_partition(wl, &wl->ptable[PART_PHY_INIT]);
  860. }
  861. out:
  862. return ret;
  863. }
  864. static int wl18xx_set_mac_and_phy(struct wl1271 *wl)
  865. {
  866. struct wl18xx_priv *priv = wl->priv;
  867. struct wl18xx_mac_and_phy_params *params;
  868. int ret;
  869. params = kmemdup(&priv->conf.phy, sizeof(*params), GFP_KERNEL);
  870. if (!params) {
  871. ret = -ENOMEM;
  872. goto out;
  873. }
  874. ret = wlcore_set_partition(wl, &wl->ptable[PART_PHY_INIT]);
  875. if (ret < 0)
  876. goto out;
  877. ret = wlcore_write(wl, WL18XX_PHY_INIT_MEM_ADDR, params,
  878. sizeof(*params), false);
  879. out:
  880. kfree(params);
  881. return ret;
  882. }
  883. static int wl18xx_enable_interrupts(struct wl1271 *wl)
  884. {
  885. u32 event_mask, intr_mask;
  886. int ret;
  887. event_mask = WL18XX_ACX_EVENTS_VECTOR;
  888. intr_mask = WL18XX_INTR_MASK;
  889. ret = wlcore_write_reg(wl, REG_INTERRUPT_MASK, event_mask);
  890. if (ret < 0)
  891. goto out;
  892. wlcore_enable_interrupts(wl);
  893. ret = wlcore_write_reg(wl, REG_INTERRUPT_MASK,
  894. WL1271_ACX_INTR_ALL & ~intr_mask);
  895. if (ret < 0)
  896. goto disable_interrupts;
  897. return ret;
  898. disable_interrupts:
  899. wlcore_disable_interrupts(wl);
  900. out:
  901. return ret;
  902. }
  903. static int wl18xx_boot(struct wl1271 *wl)
  904. {
  905. int ret;
  906. ret = wl18xx_pre_boot(wl);
  907. if (ret < 0)
  908. goto out;
  909. ret = wl18xx_pre_upload(wl);
  910. if (ret < 0)
  911. goto out;
  912. ret = wlcore_boot_upload_firmware(wl);
  913. if (ret < 0)
  914. goto out;
  915. ret = wl18xx_set_mac_and_phy(wl);
  916. if (ret < 0)
  917. goto out;
  918. wl->event_mask = BSS_LOSS_EVENT_ID |
  919. SCAN_COMPLETE_EVENT_ID |
  920. RADAR_DETECTED_EVENT_ID |
  921. RSSI_SNR_TRIGGER_0_EVENT_ID |
  922. PERIODIC_SCAN_COMPLETE_EVENT_ID |
  923. PERIODIC_SCAN_REPORT_EVENT_ID |
  924. DUMMY_PACKET_EVENT_ID |
  925. PEER_REMOVE_COMPLETE_EVENT_ID |
  926. BA_SESSION_RX_CONSTRAINT_EVENT_ID |
  927. REMAIN_ON_CHANNEL_COMPLETE_EVENT_ID |
  928. INACTIVE_STA_EVENT_ID |
  929. CHANNEL_SWITCH_COMPLETE_EVENT_ID |
  930. DFS_CHANNELS_CONFIG_COMPLETE_EVENT |
  931. SMART_CONFIG_SYNC_EVENT_ID |
  932. SMART_CONFIG_DECODE_EVENT_ID |
  933. TIME_SYNC_EVENT_ID |
  934. FW_LOGGER_INDICATION |
  935. RX_BA_WIN_SIZE_CHANGE_EVENT_ID;
  936. wl->ap_event_mask = MAX_TX_FAILURE_EVENT_ID;
  937. ret = wlcore_boot_run_firmware(wl);
  938. if (ret < 0)
  939. goto out;
  940. ret = wl18xx_enable_interrupts(wl);
  941. out:
  942. return ret;
  943. }
  944. static int wl18xx_trigger_cmd(struct wl1271 *wl, int cmd_box_addr,
  945. void *buf, size_t len)
  946. {
  947. struct wl18xx_priv *priv = wl->priv;
  948. memcpy(priv->cmd_buf, buf, len);
  949. memset(priv->cmd_buf + len, 0, WL18XX_CMD_MAX_SIZE - len);
  950. return wlcore_write(wl, cmd_box_addr, priv->cmd_buf,
  951. WL18XX_CMD_MAX_SIZE, false);
  952. }
  953. static int wl18xx_ack_event(struct wl1271 *wl)
  954. {
  955. return wlcore_write_reg(wl, REG_INTERRUPT_TRIG,
  956. WL18XX_INTR_TRIG_EVENT_ACK);
  957. }
  958. static u32 wl18xx_calc_tx_blocks(struct wl1271 *wl, u32 len, u32 spare_blks)
  959. {
  960. u32 blk_size = WL18XX_TX_HW_BLOCK_SIZE;
  961. return (len + blk_size - 1) / blk_size + spare_blks;
  962. }
  963. static void
  964. wl18xx_set_tx_desc_blocks(struct wl1271 *wl, struct wl1271_tx_hw_descr *desc,
  965. u32 blks, u32 spare_blks)
  966. {
  967. desc->wl18xx_mem.total_mem_blocks = blks;
  968. }
  969. static void
  970. wl18xx_set_tx_desc_data_len(struct wl1271 *wl, struct wl1271_tx_hw_descr *desc,
  971. struct sk_buff *skb)
  972. {
  973. desc->length = cpu_to_le16(skb->len);
  974. /* if only the last frame is to be padded, we unset this bit on Tx */
  975. if (wl->quirks & WLCORE_QUIRK_TX_PAD_LAST_FRAME)
  976. desc->wl18xx_mem.ctrl = WL18XX_TX_CTRL_NOT_PADDED;
  977. else
  978. desc->wl18xx_mem.ctrl = 0;
  979. wl1271_debug(DEBUG_TX, "tx_fill_hdr: hlid: %d "
  980. "len: %d life: %d mem: %d", desc->hlid,
  981. le16_to_cpu(desc->length),
  982. le16_to_cpu(desc->life_time),
  983. desc->wl18xx_mem.total_mem_blocks);
  984. }
  985. static enum wl_rx_buf_align
  986. wl18xx_get_rx_buf_align(struct wl1271 *wl, u32 rx_desc)
  987. {
  988. if (rx_desc & RX_BUF_PADDED_PAYLOAD)
  989. return WLCORE_RX_BUF_PADDED;
  990. return WLCORE_RX_BUF_ALIGNED;
  991. }
  992. static u32 wl18xx_get_rx_packet_len(struct wl1271 *wl, void *rx_data,
  993. u32 data_len)
  994. {
  995. struct wl1271_rx_descriptor *desc = rx_data;
  996. /* invalid packet */
  997. if (data_len < sizeof(*desc))
  998. return 0;
  999. return data_len - sizeof(*desc);
  1000. }
  1001. static void wl18xx_tx_immediate_completion(struct wl1271 *wl)
  1002. {
  1003. wl18xx_tx_immediate_complete(wl);
  1004. }
  1005. static int wl18xx_set_host_cfg_bitmap(struct wl1271 *wl, u32 extra_mem_blk)
  1006. {
  1007. int ret;
  1008. u32 sdio_align_size = 0;
  1009. u32 host_cfg_bitmap = HOST_IF_CFG_RX_FIFO_ENABLE |
  1010. HOST_IF_CFG_ADD_RX_ALIGNMENT;
  1011. /* Enable Tx SDIO padding */
  1012. if (wl->quirks & WLCORE_QUIRK_TX_BLOCKSIZE_ALIGN) {
  1013. host_cfg_bitmap |= HOST_IF_CFG_TX_PAD_TO_SDIO_BLK;
  1014. sdio_align_size = WL12XX_BUS_BLOCK_SIZE;
  1015. }
  1016. /* Enable Rx SDIO padding */
  1017. if (wl->quirks & WLCORE_QUIRK_RX_BLOCKSIZE_ALIGN) {
  1018. host_cfg_bitmap |= HOST_IF_CFG_RX_PAD_TO_SDIO_BLK;
  1019. sdio_align_size = WL12XX_BUS_BLOCK_SIZE;
  1020. }
  1021. ret = wl18xx_acx_host_if_cfg_bitmap(wl, host_cfg_bitmap,
  1022. sdio_align_size, extra_mem_blk,
  1023. WL18XX_HOST_IF_LEN_SIZE_FIELD);
  1024. if (ret < 0)
  1025. return ret;
  1026. return 0;
  1027. }
  1028. static int wl18xx_hw_init(struct wl1271 *wl)
  1029. {
  1030. int ret;
  1031. struct wl18xx_priv *priv = wl->priv;
  1032. /* (re)init private structures. Relevant on recovery as well. */
  1033. priv->last_fw_rls_idx = 0;
  1034. priv->extra_spare_key_count = 0;
  1035. /* set the default amount of spare blocks in the bitmap */
  1036. ret = wl18xx_set_host_cfg_bitmap(wl, WL18XX_TX_HW_BLOCK_SPARE);
  1037. if (ret < 0)
  1038. return ret;
  1039. /* set the dynamic fw traces bitmap */
  1040. ret = wl18xx_acx_dynamic_fw_traces(wl);
  1041. if (ret < 0)
  1042. return ret;
  1043. if (checksum_param) {
  1044. ret = wl18xx_acx_set_checksum_state(wl);
  1045. if (ret != 0)
  1046. return ret;
  1047. }
  1048. return ret;
  1049. }
  1050. static void wl18xx_convert_fw_status(struct wl1271 *wl, void *raw_fw_status,
  1051. struct wl_fw_status *fw_status)
  1052. {
  1053. struct wl18xx_fw_status *int_fw_status = raw_fw_status;
  1054. fw_status->intr = le32_to_cpu(int_fw_status->intr);
  1055. fw_status->fw_rx_counter = int_fw_status->fw_rx_counter;
  1056. fw_status->drv_rx_counter = int_fw_status->drv_rx_counter;
  1057. fw_status->tx_results_counter = int_fw_status->tx_results_counter;
  1058. fw_status->rx_pkt_descs = int_fw_status->rx_pkt_descs;
  1059. fw_status->fw_localtime = le32_to_cpu(int_fw_status->fw_localtime);
  1060. fw_status->link_ps_bitmap = le32_to_cpu(int_fw_status->link_ps_bitmap);
  1061. fw_status->link_fast_bitmap =
  1062. le32_to_cpu(int_fw_status->link_fast_bitmap);
  1063. fw_status->total_released_blks =
  1064. le32_to_cpu(int_fw_status->total_released_blks);
  1065. fw_status->tx_total = le32_to_cpu(int_fw_status->tx_total);
  1066. fw_status->counters.tx_released_pkts =
  1067. int_fw_status->counters.tx_released_pkts;
  1068. fw_status->counters.tx_lnk_free_pkts =
  1069. int_fw_status->counters.tx_lnk_free_pkts;
  1070. fw_status->counters.tx_voice_released_blks =
  1071. int_fw_status->counters.tx_voice_released_blks;
  1072. fw_status->counters.tx_last_rate =
  1073. int_fw_status->counters.tx_last_rate;
  1074. fw_status->counters.tx_last_rate_mbps =
  1075. int_fw_status->counters.tx_last_rate_mbps;
  1076. fw_status->counters.hlid =
  1077. int_fw_status->counters.hlid;
  1078. fw_status->log_start_addr = le32_to_cpu(int_fw_status->log_start_addr);
  1079. fw_status->priv = &int_fw_status->priv;
  1080. }
  1081. static void wl18xx_set_tx_desc_csum(struct wl1271 *wl,
  1082. struct wl1271_tx_hw_descr *desc,
  1083. struct sk_buff *skb)
  1084. {
  1085. u32 ip_hdr_offset;
  1086. struct iphdr *ip_hdr;
  1087. if (!checksum_param) {
  1088. desc->wl18xx_checksum_data = 0;
  1089. return;
  1090. }
  1091. if (skb->ip_summed != CHECKSUM_PARTIAL) {
  1092. desc->wl18xx_checksum_data = 0;
  1093. return;
  1094. }
  1095. ip_hdr_offset = skb_network_header(skb) - skb_mac_header(skb);
  1096. if (WARN_ON(ip_hdr_offset >= (1<<7))) {
  1097. desc->wl18xx_checksum_data = 0;
  1098. return;
  1099. }
  1100. desc->wl18xx_checksum_data = ip_hdr_offset << 1;
  1101. /* FW is interested only in the LSB of the protocol TCP=0 UDP=1 */
  1102. ip_hdr = (void *)skb_network_header(skb);
  1103. desc->wl18xx_checksum_data |= (ip_hdr->protocol & 0x01);
  1104. }
  1105. static void wl18xx_set_rx_csum(struct wl1271 *wl,
  1106. struct wl1271_rx_descriptor *desc,
  1107. struct sk_buff *skb)
  1108. {
  1109. if (desc->status & WL18XX_RX_CHECKSUM_MASK)
  1110. skb->ip_summed = CHECKSUM_UNNECESSARY;
  1111. }
  1112. static bool wl18xx_is_mimo_supported(struct wl1271 *wl)
  1113. {
  1114. struct wl18xx_priv *priv = wl->priv;
  1115. /* only support MIMO with multiple antennas, and when SISO
  1116. * is not forced through config
  1117. */
  1118. return (priv->conf.phy.number_of_assembled_ant2_4 >= 2) &&
  1119. (priv->conf.ht.mode != HT_MODE_WIDE) &&
  1120. (priv->conf.ht.mode != HT_MODE_SISO20);
  1121. }
  1122. /*
  1123. * TODO: instead of having these two functions to get the rate mask,
  1124. * we should modify the wlvif->rate_set instead
  1125. */
  1126. static u32 wl18xx_sta_get_ap_rate_mask(struct wl1271 *wl,
  1127. struct wl12xx_vif *wlvif)
  1128. {
  1129. u32 hw_rate_set = wlvif->rate_set;
  1130. if (wlvif->channel_type == NL80211_CHAN_HT40MINUS ||
  1131. wlvif->channel_type == NL80211_CHAN_HT40PLUS) {
  1132. wl1271_debug(DEBUG_ACX, "using wide channel rate mask");
  1133. hw_rate_set |= CONF_TX_RATE_USE_WIDE_CHAN;
  1134. /* we don't support MIMO in wide-channel mode */
  1135. hw_rate_set &= ~CONF_TX_MIMO_RATES;
  1136. } else if (wl18xx_is_mimo_supported(wl)) {
  1137. wl1271_debug(DEBUG_ACX, "using MIMO channel rate mask");
  1138. hw_rate_set |= CONF_TX_MIMO_RATES;
  1139. }
  1140. return hw_rate_set;
  1141. }
  1142. static u32 wl18xx_ap_get_mimo_wide_rate_mask(struct wl1271 *wl,
  1143. struct wl12xx_vif *wlvif)
  1144. {
  1145. if (wlvif->channel_type == NL80211_CHAN_HT40MINUS ||
  1146. wlvif->channel_type == NL80211_CHAN_HT40PLUS) {
  1147. wl1271_debug(DEBUG_ACX, "using wide channel rate mask");
  1148. /* sanity check - we don't support this */
  1149. if (WARN_ON(wlvif->band != NL80211_BAND_5GHZ))
  1150. return 0;
  1151. return CONF_TX_RATE_USE_WIDE_CHAN;
  1152. } else if (wl18xx_is_mimo_supported(wl) &&
  1153. wlvif->band == NL80211_BAND_2GHZ) {
  1154. wl1271_debug(DEBUG_ACX, "using MIMO rate mask");
  1155. /*
  1156. * we don't care about HT channel here - if a peer doesn't
  1157. * support MIMO, we won't enable it in its rates
  1158. */
  1159. return CONF_TX_MIMO_RATES;
  1160. } else {
  1161. return 0;
  1162. }
  1163. }
  1164. static const char *wl18xx_rdl_name(enum wl18xx_rdl_num rdl_num)
  1165. {
  1166. switch (rdl_num) {
  1167. case RDL_1_HP:
  1168. return "183xH";
  1169. case RDL_2_SP:
  1170. return "183x or 180x";
  1171. case RDL_3_HP:
  1172. return "187xH";
  1173. case RDL_4_SP:
  1174. return "187x";
  1175. case RDL_5_SP:
  1176. return "RDL11 - Not Supported";
  1177. case RDL_6_SP:
  1178. return "180xD";
  1179. case RDL_7_SP:
  1180. return "RDL13 - Not Supported (1893Q)";
  1181. case RDL_8_SP:
  1182. return "18xxQ";
  1183. case RDL_NONE:
  1184. return "UNTRIMMED";
  1185. default:
  1186. return "UNKNOWN";
  1187. }
  1188. }
  1189. static int wl18xx_get_pg_ver(struct wl1271 *wl, s8 *ver)
  1190. {
  1191. u32 fuse;
  1192. s8 rom = 0, metal = 0, pg_ver = 0, rdl_ver = 0, package_type = 0;
  1193. int ret;
  1194. ret = wlcore_set_partition(wl, &wl->ptable[PART_TOP_PRCM_ELP_SOC]);
  1195. if (ret < 0)
  1196. goto out;
  1197. ret = wlcore_read32(wl, WL18XX_REG_FUSE_DATA_2_3, &fuse);
  1198. if (ret < 0)
  1199. goto out;
  1200. package_type = (fuse >> WL18XX_PACKAGE_TYPE_OFFSET) & 1;
  1201. ret = wlcore_read32(wl, WL18XX_REG_FUSE_DATA_1_3, &fuse);
  1202. if (ret < 0)
  1203. goto out;
  1204. pg_ver = (fuse & WL18XX_PG_VER_MASK) >> WL18XX_PG_VER_OFFSET;
  1205. rom = (fuse & WL18XX_ROM_VER_MASK) >> WL18XX_ROM_VER_OFFSET;
  1206. if ((rom <= 0xE) && (package_type == WL18XX_PACKAGE_TYPE_WSP))
  1207. metal = (fuse & WL18XX_METAL_VER_MASK) >>
  1208. WL18XX_METAL_VER_OFFSET;
  1209. else
  1210. metal = (fuse & WL18XX_NEW_METAL_VER_MASK) >>
  1211. WL18XX_NEW_METAL_VER_OFFSET;
  1212. ret = wlcore_read32(wl, WL18XX_REG_FUSE_DATA_2_3, &fuse);
  1213. if (ret < 0)
  1214. goto out;
  1215. rdl_ver = (fuse & WL18XX_RDL_VER_MASK) >> WL18XX_RDL_VER_OFFSET;
  1216. wl1271_info("wl18xx HW: %s, PG %d.%d (ROM 0x%x)",
  1217. wl18xx_rdl_name(rdl_ver), pg_ver, metal, rom);
  1218. if (ver)
  1219. *ver = pg_ver;
  1220. ret = wlcore_set_partition(wl, &wl->ptable[PART_BOOT]);
  1221. out:
  1222. return ret;
  1223. }
  1224. static int wl18xx_load_conf_file(struct device *dev, struct wlcore_conf *conf,
  1225. struct wl18xx_priv_conf *priv_conf,
  1226. const char *file)
  1227. {
  1228. struct wlcore_conf_file *conf_file;
  1229. const struct firmware *fw;
  1230. int ret;
  1231. ret = request_firmware(&fw, file, dev);
  1232. if (ret < 0) {
  1233. wl1271_error("could not get configuration binary %s: %d",
  1234. file, ret);
  1235. return ret;
  1236. }
  1237. if (fw->size != WL18XX_CONF_SIZE) {
  1238. wl1271_error("%s configuration binary size is wrong, expected %zu got %zu",
  1239. file, WL18XX_CONF_SIZE, fw->size);
  1240. ret = -EINVAL;
  1241. goto out_release;
  1242. }
  1243. conf_file = (struct wlcore_conf_file *) fw->data;
  1244. if (conf_file->header.magic != cpu_to_le32(WL18XX_CONF_MAGIC)) {
  1245. wl1271_error("configuration binary file magic number mismatch, "
  1246. "expected 0x%0x got 0x%0x", WL18XX_CONF_MAGIC,
  1247. conf_file->header.magic);
  1248. ret = -EINVAL;
  1249. goto out_release;
  1250. }
  1251. if (conf_file->header.version != cpu_to_le32(WL18XX_CONF_VERSION)) {
  1252. wl1271_error("configuration binary file version not supported, "
  1253. "expected 0x%08x got 0x%08x",
  1254. WL18XX_CONF_VERSION, conf_file->header.version);
  1255. ret = -EINVAL;
  1256. goto out_release;
  1257. }
  1258. memcpy(conf, &conf_file->core, sizeof(*conf));
  1259. memcpy(priv_conf, &conf_file->priv, sizeof(*priv_conf));
  1260. out_release:
  1261. release_firmware(fw);
  1262. return ret;
  1263. }
  1264. static int wl18xx_conf_init(struct wl1271 *wl, struct device *dev)
  1265. {
  1266. struct platform_device *pdev = wl->pdev;
  1267. struct wlcore_platdev_data *pdata = dev_get_platdata(&pdev->dev);
  1268. struct wl18xx_priv *priv = wl->priv;
  1269. if (wl18xx_load_conf_file(dev, &wl->conf, &priv->conf,
  1270. pdata->family->cfg_name) < 0) {
  1271. wl1271_warning("falling back to default config");
  1272. /* apply driver default configuration */
  1273. memcpy(&wl->conf, &wl18xx_conf, sizeof(wl->conf));
  1274. /* apply default private configuration */
  1275. memcpy(&priv->conf, &wl18xx_default_priv_conf,
  1276. sizeof(priv->conf));
  1277. }
  1278. return 0;
  1279. }
  1280. static int wl18xx_plt_init(struct wl1271 *wl)
  1281. {
  1282. int ret;
  1283. /* calibrator based auto/fem detect not supported for 18xx */
  1284. if (wl->plt_mode == PLT_FEM_DETECT) {
  1285. wl1271_error("wl18xx_plt_init: PLT FEM_DETECT not supported");
  1286. return -EINVAL;
  1287. }
  1288. ret = wlcore_write32(wl, WL18XX_SCR_PAD8, WL18XX_SCR_PAD8_PLT);
  1289. if (ret < 0)
  1290. return ret;
  1291. return wl->ops->boot(wl);
  1292. }
  1293. static int wl18xx_get_mac(struct wl1271 *wl)
  1294. {
  1295. u32 mac1, mac2;
  1296. int ret;
  1297. ret = wlcore_set_partition(wl, &wl->ptable[PART_TOP_PRCM_ELP_SOC]);
  1298. if (ret < 0)
  1299. goto out;
  1300. ret = wlcore_read32(wl, WL18XX_REG_FUSE_BD_ADDR_1, &mac1);
  1301. if (ret < 0)
  1302. goto out;
  1303. ret = wlcore_read32(wl, WL18XX_REG_FUSE_BD_ADDR_2, &mac2);
  1304. if (ret < 0)
  1305. goto out;
  1306. /* these are the two parts of the BD_ADDR */
  1307. wl->fuse_oui_addr = ((mac2 & 0xffff) << 8) +
  1308. ((mac1 & 0xff000000) >> 24);
  1309. wl->fuse_nic_addr = (mac1 & 0xffffff);
  1310. if (!wl->fuse_oui_addr && !wl->fuse_nic_addr) {
  1311. u8 mac[ETH_ALEN];
  1312. eth_random_addr(mac);
  1313. wl->fuse_oui_addr = (mac[0] << 16) + (mac[1] << 8) + mac[2];
  1314. wl->fuse_nic_addr = (mac[3] << 16) + (mac[4] << 8) + mac[5];
  1315. wl1271_warning("MAC address from fuse not available, using random locally administered addresses.");
  1316. }
  1317. ret = wlcore_set_partition(wl, &wl->ptable[PART_DOWN]);
  1318. out:
  1319. return ret;
  1320. }
  1321. static int wl18xx_handle_static_data(struct wl1271 *wl,
  1322. struct wl1271_static_data *static_data)
  1323. {
  1324. struct wl18xx_static_data_priv *static_data_priv =
  1325. (struct wl18xx_static_data_priv *) static_data->priv;
  1326. strncpy(wl->chip.phy_fw_ver_str, static_data_priv->phy_version,
  1327. sizeof(wl->chip.phy_fw_ver_str));
  1328. /* make sure the string is NULL-terminated */
  1329. wl->chip.phy_fw_ver_str[sizeof(wl->chip.phy_fw_ver_str) - 1] = '\0';
  1330. wl1271_info("PHY firmware version: %s", static_data_priv->phy_version);
  1331. return 0;
  1332. }
  1333. static int wl18xx_get_spare_blocks(struct wl1271 *wl, bool is_gem)
  1334. {
  1335. struct wl18xx_priv *priv = wl->priv;
  1336. /* If we have keys requiring extra spare, indulge them */
  1337. if (priv->extra_spare_key_count)
  1338. return WL18XX_TX_HW_EXTRA_BLOCK_SPARE;
  1339. return WL18XX_TX_HW_BLOCK_SPARE;
  1340. }
  1341. static int wl18xx_set_key(struct wl1271 *wl, enum set_key_cmd cmd,
  1342. struct ieee80211_vif *vif,
  1343. struct ieee80211_sta *sta,
  1344. struct ieee80211_key_conf *key_conf)
  1345. {
  1346. struct wl18xx_priv *priv = wl->priv;
  1347. bool change_spare = false, special_enc;
  1348. int ret;
  1349. wl1271_debug(DEBUG_CRYPT, "extra spare keys before: %d",
  1350. priv->extra_spare_key_count);
  1351. special_enc = key_conf->cipher == WL1271_CIPHER_SUITE_GEM ||
  1352. key_conf->cipher == WLAN_CIPHER_SUITE_TKIP;
  1353. ret = wlcore_set_key(wl, cmd, vif, sta, key_conf);
  1354. if (ret < 0)
  1355. goto out;
  1356. /*
  1357. * when adding the first or removing the last GEM/TKIP key,
  1358. * we have to adjust the number of spare blocks.
  1359. */
  1360. if (special_enc) {
  1361. if (cmd == SET_KEY) {
  1362. /* first key */
  1363. change_spare = (priv->extra_spare_key_count == 0);
  1364. priv->extra_spare_key_count++;
  1365. } else if (cmd == DISABLE_KEY) {
  1366. /* last key */
  1367. change_spare = (priv->extra_spare_key_count == 1);
  1368. priv->extra_spare_key_count--;
  1369. }
  1370. }
  1371. wl1271_debug(DEBUG_CRYPT, "extra spare keys after: %d",
  1372. priv->extra_spare_key_count);
  1373. if (!change_spare)
  1374. goto out;
  1375. /* key is now set, change the spare blocks */
  1376. if (priv->extra_spare_key_count)
  1377. ret = wl18xx_set_host_cfg_bitmap(wl,
  1378. WL18XX_TX_HW_EXTRA_BLOCK_SPARE);
  1379. else
  1380. ret = wl18xx_set_host_cfg_bitmap(wl,
  1381. WL18XX_TX_HW_BLOCK_SPARE);
  1382. out:
  1383. return ret;
  1384. }
  1385. static u32 wl18xx_pre_pkt_send(struct wl1271 *wl,
  1386. u32 buf_offset, u32 last_len)
  1387. {
  1388. if (wl->quirks & WLCORE_QUIRK_TX_PAD_LAST_FRAME) {
  1389. struct wl1271_tx_hw_descr *last_desc;
  1390. /* get the last TX HW descriptor written to the aggr buf */
  1391. last_desc = (struct wl1271_tx_hw_descr *)(wl->aggr_buf +
  1392. buf_offset - last_len);
  1393. /* the last frame is padded up to an SDIO block */
  1394. last_desc->wl18xx_mem.ctrl &= ~WL18XX_TX_CTRL_NOT_PADDED;
  1395. return ALIGN(buf_offset, WL12XX_BUS_BLOCK_SIZE);
  1396. }
  1397. /* no modifications */
  1398. return buf_offset;
  1399. }
  1400. static void wl18xx_sta_rc_update(struct wl1271 *wl,
  1401. struct wl12xx_vif *wlvif)
  1402. {
  1403. bool wide = wlvif->rc_update_bw >= IEEE80211_STA_RX_BW_40;
  1404. wl1271_debug(DEBUG_MAC80211, "mac80211 sta_rc_update wide %d", wide);
  1405. /* sanity */
  1406. if (WARN_ON(wlvif->bss_type != BSS_TYPE_STA_BSS))
  1407. return;
  1408. /* ignore the change before association */
  1409. if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
  1410. return;
  1411. /*
  1412. * If we started out as wide, we can change the operation mode. If we
  1413. * thought this was a 20mhz AP, we have to reconnect
  1414. */
  1415. if (wlvif->sta.role_chan_type == NL80211_CHAN_HT40MINUS ||
  1416. wlvif->sta.role_chan_type == NL80211_CHAN_HT40PLUS)
  1417. wl18xx_acx_peer_ht_operation_mode(wl, wlvif->sta.hlid, wide);
  1418. else
  1419. ieee80211_connection_loss(wl12xx_wlvif_to_vif(wlvif));
  1420. }
  1421. static int wl18xx_set_peer_cap(struct wl1271 *wl,
  1422. struct ieee80211_sta_ht_cap *ht_cap,
  1423. bool allow_ht_operation,
  1424. u32 rate_set, u8 hlid)
  1425. {
  1426. return wl18xx_acx_set_peer_cap(wl, ht_cap, allow_ht_operation,
  1427. rate_set, hlid);
  1428. }
  1429. static bool wl18xx_lnk_high_prio(struct wl1271 *wl, u8 hlid,
  1430. struct wl1271_link *lnk)
  1431. {
  1432. u8 thold;
  1433. struct wl18xx_fw_status_priv *status_priv =
  1434. (struct wl18xx_fw_status_priv *)wl->fw_status->priv;
  1435. unsigned long suspend_bitmap;
  1436. /* if we don't have the link map yet, assume they all low prio */
  1437. if (!status_priv)
  1438. return false;
  1439. /* suspended links are never high priority */
  1440. suspend_bitmap = le32_to_cpu(status_priv->link_suspend_bitmap);
  1441. if (test_bit(hlid, &suspend_bitmap))
  1442. return false;
  1443. /* the priority thresholds are taken from FW */
  1444. if (test_bit(hlid, &wl->fw_fast_lnk_map) &&
  1445. !test_bit(hlid, &wl->ap_fw_ps_map))
  1446. thold = status_priv->tx_fast_link_prio_threshold;
  1447. else
  1448. thold = status_priv->tx_slow_link_prio_threshold;
  1449. return lnk->allocated_pkts < thold;
  1450. }
  1451. static bool wl18xx_lnk_low_prio(struct wl1271 *wl, u8 hlid,
  1452. struct wl1271_link *lnk)
  1453. {
  1454. u8 thold;
  1455. struct wl18xx_fw_status_priv *status_priv =
  1456. (struct wl18xx_fw_status_priv *)wl->fw_status->priv;
  1457. unsigned long suspend_bitmap;
  1458. /* if we don't have the link map yet, assume they all low prio */
  1459. if (!status_priv)
  1460. return true;
  1461. suspend_bitmap = le32_to_cpu(status_priv->link_suspend_bitmap);
  1462. if (test_bit(hlid, &suspend_bitmap))
  1463. thold = status_priv->tx_suspend_threshold;
  1464. else if (test_bit(hlid, &wl->fw_fast_lnk_map) &&
  1465. !test_bit(hlid, &wl->ap_fw_ps_map))
  1466. thold = status_priv->tx_fast_stop_threshold;
  1467. else
  1468. thold = status_priv->tx_slow_stop_threshold;
  1469. return lnk->allocated_pkts < thold;
  1470. }
  1471. static u32 wl18xx_convert_hwaddr(struct wl1271 *wl, u32 hwaddr)
  1472. {
  1473. return hwaddr & ~0x80000000;
  1474. }
  1475. static int wl18xx_setup(struct wl1271 *wl);
  1476. static struct wlcore_ops wl18xx_ops = {
  1477. .setup = wl18xx_setup,
  1478. .identify_chip = wl18xx_identify_chip,
  1479. .boot = wl18xx_boot,
  1480. .plt_init = wl18xx_plt_init,
  1481. .trigger_cmd = wl18xx_trigger_cmd,
  1482. .ack_event = wl18xx_ack_event,
  1483. .wait_for_event = wl18xx_wait_for_event,
  1484. .process_mailbox_events = wl18xx_process_mailbox_events,
  1485. .calc_tx_blocks = wl18xx_calc_tx_blocks,
  1486. .set_tx_desc_blocks = wl18xx_set_tx_desc_blocks,
  1487. .set_tx_desc_data_len = wl18xx_set_tx_desc_data_len,
  1488. .get_rx_buf_align = wl18xx_get_rx_buf_align,
  1489. .get_rx_packet_len = wl18xx_get_rx_packet_len,
  1490. .tx_immediate_compl = wl18xx_tx_immediate_completion,
  1491. .tx_delayed_compl = NULL,
  1492. .hw_init = wl18xx_hw_init,
  1493. .convert_fw_status = wl18xx_convert_fw_status,
  1494. .set_tx_desc_csum = wl18xx_set_tx_desc_csum,
  1495. .get_pg_ver = wl18xx_get_pg_ver,
  1496. .set_rx_csum = wl18xx_set_rx_csum,
  1497. .sta_get_ap_rate_mask = wl18xx_sta_get_ap_rate_mask,
  1498. .ap_get_mimo_wide_rate_mask = wl18xx_ap_get_mimo_wide_rate_mask,
  1499. .get_mac = wl18xx_get_mac,
  1500. .debugfs_init = wl18xx_debugfs_add_files,
  1501. .scan_start = wl18xx_scan_start,
  1502. .scan_stop = wl18xx_scan_stop,
  1503. .sched_scan_start = wl18xx_sched_scan_start,
  1504. .sched_scan_stop = wl18xx_scan_sched_scan_stop,
  1505. .handle_static_data = wl18xx_handle_static_data,
  1506. .get_spare_blocks = wl18xx_get_spare_blocks,
  1507. .set_key = wl18xx_set_key,
  1508. .channel_switch = wl18xx_cmd_channel_switch,
  1509. .pre_pkt_send = wl18xx_pre_pkt_send,
  1510. .sta_rc_update = wl18xx_sta_rc_update,
  1511. .set_peer_cap = wl18xx_set_peer_cap,
  1512. .convert_hwaddr = wl18xx_convert_hwaddr,
  1513. .lnk_high_prio = wl18xx_lnk_high_prio,
  1514. .lnk_low_prio = wl18xx_lnk_low_prio,
  1515. .smart_config_start = wl18xx_cmd_smart_config_start,
  1516. .smart_config_stop = wl18xx_cmd_smart_config_stop,
  1517. .smart_config_set_group_key = wl18xx_cmd_smart_config_set_group_key,
  1518. .interrupt_notify = wl18xx_acx_interrupt_notify_config,
  1519. .rx_ba_filter = wl18xx_acx_rx_ba_filter,
  1520. .ap_sleep = wl18xx_acx_ap_sleep,
  1521. .set_cac = wl18xx_cmd_set_cac,
  1522. .dfs_master_restart = wl18xx_cmd_dfs_master_restart,
  1523. };
  1524. /* HT cap appropriate for wide channels in 2Ghz */
  1525. static struct ieee80211_sta_ht_cap wl18xx_siso40_ht_cap_2ghz = {
  1526. .cap = IEEE80211_HT_CAP_SGI_20 | IEEE80211_HT_CAP_SGI_40 |
  1527. IEEE80211_HT_CAP_SUP_WIDTH_20_40 | IEEE80211_HT_CAP_DSSSCCK40 |
  1528. IEEE80211_HT_CAP_GRN_FLD,
  1529. .ht_supported = true,
  1530. .ampdu_factor = IEEE80211_HT_MAX_AMPDU_16K,
  1531. .ampdu_density = IEEE80211_HT_MPDU_DENSITY_16,
  1532. .mcs = {
  1533. .rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
  1534. .rx_highest = cpu_to_le16(150),
  1535. .tx_params = IEEE80211_HT_MCS_TX_DEFINED,
  1536. },
  1537. };
  1538. /* HT cap appropriate for wide channels in 5Ghz */
  1539. static struct ieee80211_sta_ht_cap wl18xx_siso40_ht_cap_5ghz = {
  1540. .cap = IEEE80211_HT_CAP_SGI_20 | IEEE80211_HT_CAP_SGI_40 |
  1541. IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
  1542. IEEE80211_HT_CAP_GRN_FLD,
  1543. .ht_supported = true,
  1544. .ampdu_factor = IEEE80211_HT_MAX_AMPDU_16K,
  1545. .ampdu_density = IEEE80211_HT_MPDU_DENSITY_16,
  1546. .mcs = {
  1547. .rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
  1548. .rx_highest = cpu_to_le16(150),
  1549. .tx_params = IEEE80211_HT_MCS_TX_DEFINED,
  1550. },
  1551. };
  1552. /* HT cap appropriate for SISO 20 */
  1553. static struct ieee80211_sta_ht_cap wl18xx_siso20_ht_cap = {
  1554. .cap = IEEE80211_HT_CAP_SGI_20 |
  1555. IEEE80211_HT_CAP_GRN_FLD,
  1556. .ht_supported = true,
  1557. .ampdu_factor = IEEE80211_HT_MAX_AMPDU_16K,
  1558. .ampdu_density = IEEE80211_HT_MPDU_DENSITY_16,
  1559. .mcs = {
  1560. .rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
  1561. .rx_highest = cpu_to_le16(72),
  1562. .tx_params = IEEE80211_HT_MCS_TX_DEFINED,
  1563. },
  1564. };
  1565. /* HT cap appropriate for MIMO rates in 20mhz channel */
  1566. static struct ieee80211_sta_ht_cap wl18xx_mimo_ht_cap_2ghz = {
  1567. .cap = IEEE80211_HT_CAP_SGI_20 |
  1568. IEEE80211_HT_CAP_GRN_FLD,
  1569. .ht_supported = true,
  1570. .ampdu_factor = IEEE80211_HT_MAX_AMPDU_16K,
  1571. .ampdu_density = IEEE80211_HT_MPDU_DENSITY_16,
  1572. .mcs = {
  1573. .rx_mask = { 0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0, },
  1574. .rx_highest = cpu_to_le16(144),
  1575. .tx_params = IEEE80211_HT_MCS_TX_DEFINED,
  1576. },
  1577. };
  1578. static const struct ieee80211_iface_limit wl18xx_iface_limits[] = {
  1579. {
  1580. .max = 2,
  1581. .types = BIT(NL80211_IFTYPE_STATION),
  1582. },
  1583. {
  1584. .max = 1,
  1585. .types = BIT(NL80211_IFTYPE_AP)
  1586. | BIT(NL80211_IFTYPE_P2P_GO)
  1587. | BIT(NL80211_IFTYPE_P2P_CLIENT)
  1588. #ifdef CONFIG_MAC80211_MESH
  1589. | BIT(NL80211_IFTYPE_MESH_POINT)
  1590. #endif
  1591. },
  1592. {
  1593. .max = 1,
  1594. .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
  1595. },
  1596. };
  1597. static const struct ieee80211_iface_limit wl18xx_iface_ap_limits[] = {
  1598. {
  1599. .max = 2,
  1600. .types = BIT(NL80211_IFTYPE_AP),
  1601. },
  1602. #ifdef CONFIG_MAC80211_MESH
  1603. {
  1604. .max = 1,
  1605. .types = BIT(NL80211_IFTYPE_MESH_POINT),
  1606. },
  1607. #endif
  1608. {
  1609. .max = 1,
  1610. .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
  1611. },
  1612. };
  1613. static const struct ieee80211_iface_combination
  1614. wl18xx_iface_combinations[] = {
  1615. {
  1616. .max_interfaces = 3,
  1617. .limits = wl18xx_iface_limits,
  1618. .n_limits = ARRAY_SIZE(wl18xx_iface_limits),
  1619. .num_different_channels = 2,
  1620. },
  1621. {
  1622. .max_interfaces = 2,
  1623. .limits = wl18xx_iface_ap_limits,
  1624. .n_limits = ARRAY_SIZE(wl18xx_iface_ap_limits),
  1625. .num_different_channels = 1,
  1626. .radar_detect_widths = BIT(NL80211_CHAN_NO_HT) |
  1627. BIT(NL80211_CHAN_HT20) |
  1628. BIT(NL80211_CHAN_HT40MINUS) |
  1629. BIT(NL80211_CHAN_HT40PLUS),
  1630. }
  1631. };
  1632. static int wl18xx_setup(struct wl1271 *wl)
  1633. {
  1634. struct wl18xx_priv *priv = wl->priv;
  1635. int ret;
  1636. BUILD_BUG_ON(WL18XX_MAX_LINKS > WLCORE_MAX_LINKS);
  1637. BUILD_BUG_ON(WL18XX_MAX_AP_STATIONS > WL18XX_MAX_LINKS);
  1638. BUILD_BUG_ON(WL18XX_CONF_SG_PARAMS_MAX > WLCORE_CONF_SG_PARAMS_MAX);
  1639. wl->rtable = wl18xx_rtable;
  1640. wl->num_tx_desc = WL18XX_NUM_TX_DESCRIPTORS;
  1641. wl->num_rx_desc = WL18XX_NUM_RX_DESCRIPTORS;
  1642. wl->num_links = WL18XX_MAX_LINKS;
  1643. wl->max_ap_stations = WL18XX_MAX_AP_STATIONS;
  1644. wl->iface_combinations = wl18xx_iface_combinations;
  1645. wl->n_iface_combinations = ARRAY_SIZE(wl18xx_iface_combinations);
  1646. wl->num_mac_addr = WL18XX_NUM_MAC_ADDRESSES;
  1647. wl->band_rate_to_idx = wl18xx_band_rate_to_idx;
  1648. wl->hw_tx_rate_tbl_size = WL18XX_CONF_HW_RXTX_RATE_MAX;
  1649. wl->hw_min_ht_rate = WL18XX_CONF_HW_RXTX_RATE_MCS0;
  1650. wl->fw_status_len = sizeof(struct wl18xx_fw_status);
  1651. wl->fw_status_priv_len = sizeof(struct wl18xx_fw_status_priv);
  1652. wl->stats.fw_stats_len = sizeof(struct wl18xx_acx_statistics);
  1653. wl->static_data_priv_len = sizeof(struct wl18xx_static_data_priv);
  1654. if (num_rx_desc_param != -1)
  1655. wl->num_rx_desc = num_rx_desc_param;
  1656. ret = wl18xx_conf_init(wl, wl->dev);
  1657. if (ret < 0)
  1658. return ret;
  1659. /* If the module param is set, update it in conf */
  1660. if (board_type_param) {
  1661. if (!strcmp(board_type_param, "fpga")) {
  1662. priv->conf.phy.board_type = BOARD_TYPE_FPGA_18XX;
  1663. } else if (!strcmp(board_type_param, "hdk")) {
  1664. priv->conf.phy.board_type = BOARD_TYPE_HDK_18XX;
  1665. } else if (!strcmp(board_type_param, "dvp")) {
  1666. priv->conf.phy.board_type = BOARD_TYPE_DVP_18XX;
  1667. } else if (!strcmp(board_type_param, "evb")) {
  1668. priv->conf.phy.board_type = BOARD_TYPE_EVB_18XX;
  1669. } else if (!strcmp(board_type_param, "com8")) {
  1670. priv->conf.phy.board_type = BOARD_TYPE_COM8_18XX;
  1671. } else {
  1672. wl1271_error("invalid board type '%s'",
  1673. board_type_param);
  1674. return -EINVAL;
  1675. }
  1676. }
  1677. if (priv->conf.phy.board_type >= NUM_BOARD_TYPES) {
  1678. wl1271_error("invalid board type '%d'",
  1679. priv->conf.phy.board_type);
  1680. return -EINVAL;
  1681. }
  1682. if (low_band_component_param != -1)
  1683. priv->conf.phy.low_band_component = low_band_component_param;
  1684. if (low_band_component_type_param != -1)
  1685. priv->conf.phy.low_band_component_type =
  1686. low_band_component_type_param;
  1687. if (high_band_component_param != -1)
  1688. priv->conf.phy.high_band_component = high_band_component_param;
  1689. if (high_band_component_type_param != -1)
  1690. priv->conf.phy.high_band_component_type =
  1691. high_band_component_type_param;
  1692. if (pwr_limit_reference_11_abg_param != -1)
  1693. priv->conf.phy.pwr_limit_reference_11_abg =
  1694. pwr_limit_reference_11_abg_param;
  1695. if (n_antennas_2_param != -1)
  1696. priv->conf.phy.number_of_assembled_ant2_4 = n_antennas_2_param;
  1697. if (n_antennas_5_param != -1)
  1698. priv->conf.phy.number_of_assembled_ant5 = n_antennas_5_param;
  1699. if (dc2dc_param != -1)
  1700. priv->conf.phy.external_pa_dc2dc = dc2dc_param;
  1701. if (ht_mode_param) {
  1702. if (!strcmp(ht_mode_param, "default"))
  1703. priv->conf.ht.mode = HT_MODE_DEFAULT;
  1704. else if (!strcmp(ht_mode_param, "wide"))
  1705. priv->conf.ht.mode = HT_MODE_WIDE;
  1706. else if (!strcmp(ht_mode_param, "siso20"))
  1707. priv->conf.ht.mode = HT_MODE_SISO20;
  1708. else {
  1709. wl1271_error("invalid ht_mode '%s'", ht_mode_param);
  1710. return -EINVAL;
  1711. }
  1712. }
  1713. if (priv->conf.ht.mode == HT_MODE_DEFAULT) {
  1714. /*
  1715. * Only support mimo with multiple antennas. Fall back to
  1716. * siso40.
  1717. */
  1718. if (wl18xx_is_mimo_supported(wl))
  1719. wlcore_set_ht_cap(wl, NL80211_BAND_2GHZ,
  1720. &wl18xx_mimo_ht_cap_2ghz);
  1721. else
  1722. wlcore_set_ht_cap(wl, NL80211_BAND_2GHZ,
  1723. &wl18xx_siso40_ht_cap_2ghz);
  1724. /* 5Ghz is always wide */
  1725. wlcore_set_ht_cap(wl, NL80211_BAND_5GHZ,
  1726. &wl18xx_siso40_ht_cap_5ghz);
  1727. } else if (priv->conf.ht.mode == HT_MODE_WIDE) {
  1728. wlcore_set_ht_cap(wl, NL80211_BAND_2GHZ,
  1729. &wl18xx_siso40_ht_cap_2ghz);
  1730. wlcore_set_ht_cap(wl, NL80211_BAND_5GHZ,
  1731. &wl18xx_siso40_ht_cap_5ghz);
  1732. } else if (priv->conf.ht.mode == HT_MODE_SISO20) {
  1733. wlcore_set_ht_cap(wl, NL80211_BAND_2GHZ,
  1734. &wl18xx_siso20_ht_cap);
  1735. wlcore_set_ht_cap(wl, NL80211_BAND_5GHZ,
  1736. &wl18xx_siso20_ht_cap);
  1737. }
  1738. if (!checksum_param) {
  1739. wl18xx_ops.set_rx_csum = NULL;
  1740. wl18xx_ops.init_vif = NULL;
  1741. }
  1742. /* Enable 11a Band only if we have 5G antennas */
  1743. wl->enable_11a = (priv->conf.phy.number_of_assembled_ant5 != 0);
  1744. return 0;
  1745. }
  1746. static int wl18xx_probe(struct platform_device *pdev)
  1747. {
  1748. struct wl1271 *wl;
  1749. struct ieee80211_hw *hw;
  1750. int ret;
  1751. hw = wlcore_alloc_hw(sizeof(struct wl18xx_priv),
  1752. WL18XX_AGGR_BUFFER_SIZE,
  1753. sizeof(struct wl18xx_event_mailbox));
  1754. if (IS_ERR(hw)) {
  1755. wl1271_error("can't allocate hw");
  1756. ret = PTR_ERR(hw);
  1757. goto out;
  1758. }
  1759. wl = hw->priv;
  1760. wl->ops = &wl18xx_ops;
  1761. wl->ptable = wl18xx_ptable;
  1762. ret = wlcore_probe(wl, pdev);
  1763. if (ret)
  1764. goto out_free;
  1765. return ret;
  1766. out_free:
  1767. wlcore_free_hw(wl);
  1768. out:
  1769. return ret;
  1770. }
  1771. static const struct platform_device_id wl18xx_id_table[] = {
  1772. { "wl18xx", 0 },
  1773. { } /* Terminating Entry */
  1774. };
  1775. MODULE_DEVICE_TABLE(platform, wl18xx_id_table);
  1776. static struct platform_driver wl18xx_driver = {
  1777. .probe = wl18xx_probe,
  1778. .remove = wlcore_remove,
  1779. .id_table = wl18xx_id_table,
  1780. .driver = {
  1781. .name = "wl18xx_driver",
  1782. }
  1783. };
  1784. module_platform_driver(wl18xx_driver);
  1785. module_param_named(ht_mode, ht_mode_param, charp, 0400);
  1786. MODULE_PARM_DESC(ht_mode, "Force HT mode: wide or siso20");
  1787. module_param_named(board_type, board_type_param, charp, 0400);
  1788. MODULE_PARM_DESC(board_type, "Board type: fpga, hdk (default), evb, com8 or "
  1789. "dvp");
  1790. module_param_named(checksum, checksum_param, bool, 0400);
  1791. MODULE_PARM_DESC(checksum, "Enable TCP checksum: boolean (defaults to false)");
  1792. module_param_named(dc2dc, dc2dc_param, int, 0400);
  1793. MODULE_PARM_DESC(dc2dc, "External DC2DC: u8 (defaults to 0)");
  1794. module_param_named(n_antennas_2, n_antennas_2_param, int, 0400);
  1795. MODULE_PARM_DESC(n_antennas_2,
  1796. "Number of installed 2.4GHz antennas: 1 (default) or 2");
  1797. module_param_named(n_antennas_5, n_antennas_5_param, int, 0400);
  1798. MODULE_PARM_DESC(n_antennas_5,
  1799. "Number of installed 5GHz antennas: 1 (default) or 2");
  1800. module_param_named(low_band_component, low_band_component_param, int, 0400);
  1801. MODULE_PARM_DESC(low_band_component, "Low band component: u8 "
  1802. "(default is 0x01)");
  1803. module_param_named(low_band_component_type, low_band_component_type_param,
  1804. int, 0400);
  1805. MODULE_PARM_DESC(low_band_component_type, "Low band component type: u8 "
  1806. "(default is 0x05 or 0x06 depending on the board_type)");
  1807. module_param_named(high_band_component, high_band_component_param, int, 0400);
  1808. MODULE_PARM_DESC(high_band_component, "High band component: u8, "
  1809. "(default is 0x01)");
  1810. module_param_named(high_band_component_type, high_band_component_type_param,
  1811. int, 0400);
  1812. MODULE_PARM_DESC(high_band_component_type, "High band component type: u8 "
  1813. "(default is 0x09)");
  1814. module_param_named(pwr_limit_reference_11_abg,
  1815. pwr_limit_reference_11_abg_param, int, 0400);
  1816. MODULE_PARM_DESC(pwr_limit_reference_11_abg, "Power limit reference: u8 "
  1817. "(default is 0xc8)");
  1818. module_param_named(num_rx_desc, num_rx_desc_param, int, 0400);
  1819. MODULE_PARM_DESC(num_rx_desc_param,
  1820. "Number of Rx descriptors: u8 (default is 32)");
  1821. MODULE_LICENSE("GPL v2");
  1822. MODULE_AUTHOR("Luciano Coelho <[email protected]>");
  1823. MODULE_FIRMWARE(WL18XX_FW_NAME);