main.c 62 KB

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