main.c 53 KB

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