main.c 63 KB

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