main.c 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282
  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 "../wlcore/wlcore.h"
  25. #include "../wlcore/debug.h"
  26. #include "../wlcore/io.h"
  27. #include "../wlcore/acx.h"
  28. #include "../wlcore/tx.h"
  29. #include "../wlcore/rx.h"
  30. #include "../wlcore/io.h"
  31. #include "../wlcore/boot.h"
  32. #include "reg.h"
  33. #include "conf.h"
  34. #include "acx.h"
  35. #include "tx.h"
  36. #include "wl18xx.h"
  37. #include "io.h"
  38. #include "debugfs.h"
  39. #define WL18XX_RX_CHECKSUM_MASK 0x40
  40. static char *ht_mode_param = "wide";
  41. static char *board_type_param = "hdk";
  42. static bool dc2dc_param = false;
  43. static int n_antennas_2_param = 1;
  44. static int n_antennas_5_param = 1;
  45. static bool checksum_param = true;
  46. static bool enable_11a_param = true;
  47. static int low_band_component = -1;
  48. static int low_band_component_type = -1;
  49. static int high_band_component = -1;
  50. static int high_band_component_type = -1;
  51. static int pwr_limit_reference_11_abg = -1;
  52. static const u8 wl18xx_rate_to_idx_2ghz[] = {
  53. /* MCS rates are used only with 11n */
  54. 15, /* WL18XX_CONF_HW_RXTX_RATE_MCS15 */
  55. 14, /* WL18XX_CONF_HW_RXTX_RATE_MCS14 */
  56. 13, /* WL18XX_CONF_HW_RXTX_RATE_MCS13 */
  57. 12, /* WL18XX_CONF_HW_RXTX_RATE_MCS12 */
  58. 11, /* WL18XX_CONF_HW_RXTX_RATE_MCS11 */
  59. 10, /* WL18XX_CONF_HW_RXTX_RATE_MCS10 */
  60. 9, /* WL18XX_CONF_HW_RXTX_RATE_MCS9 */
  61. 8, /* WL18XX_CONF_HW_RXTX_RATE_MCS8 */
  62. 7, /* WL18XX_CONF_HW_RXTX_RATE_MCS7 */
  63. 6, /* WL18XX_CONF_HW_RXTX_RATE_MCS6 */
  64. 5, /* WL18XX_CONF_HW_RXTX_RATE_MCS5 */
  65. 4, /* WL18XX_CONF_HW_RXTX_RATE_MCS4 */
  66. 3, /* WL18XX_CONF_HW_RXTX_RATE_MCS3 */
  67. 2, /* WL18XX_CONF_HW_RXTX_RATE_MCS2 */
  68. 1, /* WL18XX_CONF_HW_RXTX_RATE_MCS1 */
  69. 0, /* WL18XX_CONF_HW_RXTX_RATE_MCS0 */
  70. 11, /* WL18XX_CONF_HW_RXTX_RATE_54 */
  71. 10, /* WL18XX_CONF_HW_RXTX_RATE_48 */
  72. 9, /* WL18XX_CONF_HW_RXTX_RATE_36 */
  73. 8, /* WL18XX_CONF_HW_RXTX_RATE_24 */
  74. /* TI-specific rate */
  75. CONF_HW_RXTX_RATE_UNSUPPORTED, /* WL18XX_CONF_HW_RXTX_RATE_22 */
  76. 7, /* WL18XX_CONF_HW_RXTX_RATE_18 */
  77. 6, /* WL18XX_CONF_HW_RXTX_RATE_12 */
  78. 3, /* WL18XX_CONF_HW_RXTX_RATE_11 */
  79. 5, /* WL18XX_CONF_HW_RXTX_RATE_9 */
  80. 4, /* WL18XX_CONF_HW_RXTX_RATE_6 */
  81. 2, /* WL18XX_CONF_HW_RXTX_RATE_5_5 */
  82. 1, /* WL18XX_CONF_HW_RXTX_RATE_2 */
  83. 0 /* WL18XX_CONF_HW_RXTX_RATE_1 */
  84. };
  85. static const u8 wl18xx_rate_to_idx_5ghz[] = {
  86. /* MCS rates are used only with 11n */
  87. 15, /* WL18XX_CONF_HW_RXTX_RATE_MCS15 */
  88. 14, /* WL18XX_CONF_HW_RXTX_RATE_MCS14 */
  89. 13, /* WL18XX_CONF_HW_RXTX_RATE_MCS13 */
  90. 12, /* WL18XX_CONF_HW_RXTX_RATE_MCS12 */
  91. 11, /* WL18XX_CONF_HW_RXTX_RATE_MCS11 */
  92. 10, /* WL18XX_CONF_HW_RXTX_RATE_MCS10 */
  93. 9, /* WL18XX_CONF_HW_RXTX_RATE_MCS9 */
  94. 8, /* WL18XX_CONF_HW_RXTX_RATE_MCS8 */
  95. 7, /* WL18XX_CONF_HW_RXTX_RATE_MCS7 */
  96. 6, /* WL18XX_CONF_HW_RXTX_RATE_MCS6 */
  97. 5, /* WL18XX_CONF_HW_RXTX_RATE_MCS5 */
  98. 4, /* WL18XX_CONF_HW_RXTX_RATE_MCS4 */
  99. 3, /* WL18XX_CONF_HW_RXTX_RATE_MCS3 */
  100. 2, /* WL18XX_CONF_HW_RXTX_RATE_MCS2 */
  101. 1, /* WL18XX_CONF_HW_RXTX_RATE_MCS1 */
  102. 0, /* WL18XX_CONF_HW_RXTX_RATE_MCS0 */
  103. 7, /* WL18XX_CONF_HW_RXTX_RATE_54 */
  104. 6, /* WL18XX_CONF_HW_RXTX_RATE_48 */
  105. 5, /* WL18XX_CONF_HW_RXTX_RATE_36 */
  106. 4, /* WL18XX_CONF_HW_RXTX_RATE_24 */
  107. /* TI-specific rate */
  108. CONF_HW_RXTX_RATE_UNSUPPORTED, /* WL18XX_CONF_HW_RXTX_RATE_22 */
  109. 3, /* WL18XX_CONF_HW_RXTX_RATE_18 */
  110. 2, /* WL18XX_CONF_HW_RXTX_RATE_12 */
  111. CONF_HW_RXTX_RATE_UNSUPPORTED, /* WL18XX_CONF_HW_RXTX_RATE_11 */
  112. 1, /* WL18XX_CONF_HW_RXTX_RATE_9 */
  113. 0, /* WL18XX_CONF_HW_RXTX_RATE_6 */
  114. CONF_HW_RXTX_RATE_UNSUPPORTED, /* WL18XX_CONF_HW_RXTX_RATE_5_5 */
  115. CONF_HW_RXTX_RATE_UNSUPPORTED, /* WL18XX_CONF_HW_RXTX_RATE_2 */
  116. CONF_HW_RXTX_RATE_UNSUPPORTED, /* WL18XX_CONF_HW_RXTX_RATE_1 */
  117. };
  118. static const u8 *wl18xx_band_rate_to_idx[] = {
  119. [IEEE80211_BAND_2GHZ] = wl18xx_rate_to_idx_2ghz,
  120. [IEEE80211_BAND_5GHZ] = wl18xx_rate_to_idx_5ghz
  121. };
  122. enum wl18xx_hw_rates {
  123. WL18XX_CONF_HW_RXTX_RATE_MCS15 = 0,
  124. WL18XX_CONF_HW_RXTX_RATE_MCS14,
  125. WL18XX_CONF_HW_RXTX_RATE_MCS13,
  126. WL18XX_CONF_HW_RXTX_RATE_MCS12,
  127. WL18XX_CONF_HW_RXTX_RATE_MCS11,
  128. WL18XX_CONF_HW_RXTX_RATE_MCS10,
  129. WL18XX_CONF_HW_RXTX_RATE_MCS9,
  130. WL18XX_CONF_HW_RXTX_RATE_MCS8,
  131. WL18XX_CONF_HW_RXTX_RATE_MCS7,
  132. WL18XX_CONF_HW_RXTX_RATE_MCS6,
  133. WL18XX_CONF_HW_RXTX_RATE_MCS5,
  134. WL18XX_CONF_HW_RXTX_RATE_MCS4,
  135. WL18XX_CONF_HW_RXTX_RATE_MCS3,
  136. WL18XX_CONF_HW_RXTX_RATE_MCS2,
  137. WL18XX_CONF_HW_RXTX_RATE_MCS1,
  138. WL18XX_CONF_HW_RXTX_RATE_MCS0,
  139. WL18XX_CONF_HW_RXTX_RATE_54,
  140. WL18XX_CONF_HW_RXTX_RATE_48,
  141. WL18XX_CONF_HW_RXTX_RATE_36,
  142. WL18XX_CONF_HW_RXTX_RATE_24,
  143. WL18XX_CONF_HW_RXTX_RATE_22,
  144. WL18XX_CONF_HW_RXTX_RATE_18,
  145. WL18XX_CONF_HW_RXTX_RATE_12,
  146. WL18XX_CONF_HW_RXTX_RATE_11,
  147. WL18XX_CONF_HW_RXTX_RATE_9,
  148. WL18XX_CONF_HW_RXTX_RATE_6,
  149. WL18XX_CONF_HW_RXTX_RATE_5_5,
  150. WL18XX_CONF_HW_RXTX_RATE_2,
  151. WL18XX_CONF_HW_RXTX_RATE_1,
  152. WL18XX_CONF_HW_RXTX_RATE_MAX,
  153. };
  154. static struct wlcore_conf wl18xx_conf = {
  155. .sg = {
  156. .params = {
  157. [CONF_SG_ACL_BT_MASTER_MIN_BR] = 10,
  158. [CONF_SG_ACL_BT_MASTER_MAX_BR] = 180,
  159. [CONF_SG_ACL_BT_SLAVE_MIN_BR] = 10,
  160. [CONF_SG_ACL_BT_SLAVE_MAX_BR] = 180,
  161. [CONF_SG_ACL_BT_MASTER_MIN_EDR] = 10,
  162. [CONF_SG_ACL_BT_MASTER_MAX_EDR] = 80,
  163. [CONF_SG_ACL_BT_SLAVE_MIN_EDR] = 10,
  164. [CONF_SG_ACL_BT_SLAVE_MAX_EDR] = 80,
  165. [CONF_SG_ACL_WLAN_PS_MASTER_BR] = 8,
  166. [CONF_SG_ACL_WLAN_PS_SLAVE_BR] = 8,
  167. [CONF_SG_ACL_WLAN_PS_MASTER_EDR] = 20,
  168. [CONF_SG_ACL_WLAN_PS_SLAVE_EDR] = 20,
  169. [CONF_SG_ACL_WLAN_ACTIVE_MASTER_MIN_BR] = 20,
  170. [CONF_SG_ACL_WLAN_ACTIVE_MASTER_MAX_BR] = 35,
  171. [CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MIN_BR] = 16,
  172. [CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MAX_BR] = 35,
  173. [CONF_SG_ACL_WLAN_ACTIVE_MASTER_MIN_EDR] = 32,
  174. [CONF_SG_ACL_WLAN_ACTIVE_MASTER_MAX_EDR] = 50,
  175. [CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MIN_EDR] = 28,
  176. [CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MAX_EDR] = 50,
  177. [CONF_SG_ACL_ACTIVE_SCAN_WLAN_BR] = 10,
  178. [CONF_SG_ACL_ACTIVE_SCAN_WLAN_EDR] = 20,
  179. [CONF_SG_ACL_PASSIVE_SCAN_BT_BR] = 75,
  180. [CONF_SG_ACL_PASSIVE_SCAN_WLAN_BR] = 15,
  181. [CONF_SG_ACL_PASSIVE_SCAN_BT_EDR] = 27,
  182. [CONF_SG_ACL_PASSIVE_SCAN_WLAN_EDR] = 17,
  183. /* active scan params */
  184. [CONF_SG_AUTO_SCAN_PROBE_REQ] = 170,
  185. [CONF_SG_ACTIVE_SCAN_DURATION_FACTOR_HV3] = 50,
  186. [CONF_SG_ACTIVE_SCAN_DURATION_FACTOR_A2DP] = 100,
  187. /* passive scan params */
  188. [CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_A2DP_BR] = 800,
  189. [CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_A2DP_EDR] = 200,
  190. [CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_HV3] = 200,
  191. /* passive scan in dual antenna params */
  192. [CONF_SG_CONSECUTIVE_HV3_IN_PASSIVE_SCAN] = 0,
  193. [CONF_SG_BCN_HV3_COLLISION_THRESH_IN_PASSIVE_SCAN] = 0,
  194. [CONF_SG_TX_RX_PROTECTION_BWIDTH_IN_PASSIVE_SCAN] = 0,
  195. /* general params */
  196. [CONF_SG_STA_FORCE_PS_IN_BT_SCO] = 1,
  197. [CONF_SG_ANTENNA_CONFIGURATION] = 0,
  198. [CONF_SG_BEACON_MISS_PERCENT] = 60,
  199. [CONF_SG_DHCP_TIME] = 5000,
  200. [CONF_SG_RXT] = 1200,
  201. [CONF_SG_TXT] = 1000,
  202. [CONF_SG_ADAPTIVE_RXT_TXT] = 1,
  203. [CONF_SG_GENERAL_USAGE_BIT_MAP] = 3,
  204. [CONF_SG_HV3_MAX_SERVED] = 6,
  205. [CONF_SG_PS_POLL_TIMEOUT] = 10,
  206. [CONF_SG_UPSD_TIMEOUT] = 10,
  207. [CONF_SG_CONSECUTIVE_CTS_THRESHOLD] = 2,
  208. [CONF_SG_STA_RX_WINDOW_AFTER_DTIM] = 5,
  209. [CONF_SG_STA_CONNECTION_PROTECTION_TIME] = 30,
  210. /* AP params */
  211. [CONF_AP_BEACON_MISS_TX] = 3,
  212. [CONF_AP_RX_WINDOW_AFTER_BEACON] = 10,
  213. [CONF_AP_BEACON_WINDOW_INTERVAL] = 2,
  214. [CONF_AP_CONNECTION_PROTECTION_TIME] = 0,
  215. [CONF_AP_BT_ACL_VAL_BT_SERVE_TIME] = 25,
  216. [CONF_AP_BT_ACL_VAL_WL_SERVE_TIME] = 25,
  217. /* CTS Diluting params */
  218. [CONF_SG_CTS_DILUTED_BAD_RX_PACKETS_TH] = 0,
  219. [CONF_SG_CTS_CHOP_IN_DUAL_ANT_SCO_MASTER] = 0,
  220. },
  221. .state = CONF_SG_PROTECTIVE,
  222. },
  223. .rx = {
  224. .rx_msdu_life_time = 512000,
  225. .packet_detection_threshold = 0,
  226. .ps_poll_timeout = 15,
  227. .upsd_timeout = 15,
  228. .rts_threshold = IEEE80211_MAX_RTS_THRESHOLD,
  229. .rx_cca_threshold = 0,
  230. .irq_blk_threshold = 0xFFFF,
  231. .irq_pkt_threshold = 0,
  232. .irq_timeout = 600,
  233. .queue_type = CONF_RX_QUEUE_TYPE_LOW_PRIORITY,
  234. },
  235. .tx = {
  236. .tx_energy_detection = 0,
  237. .sta_rc_conf = {
  238. .enabled_rates = 0,
  239. .short_retry_limit = 10,
  240. .long_retry_limit = 10,
  241. .aflags = 0,
  242. },
  243. .ac_conf_count = 4,
  244. .ac_conf = {
  245. [CONF_TX_AC_BE] = {
  246. .ac = CONF_TX_AC_BE,
  247. .cw_min = 15,
  248. .cw_max = 63,
  249. .aifsn = 3,
  250. .tx_op_limit = 0,
  251. },
  252. [CONF_TX_AC_BK] = {
  253. .ac = CONF_TX_AC_BK,
  254. .cw_min = 15,
  255. .cw_max = 63,
  256. .aifsn = 7,
  257. .tx_op_limit = 0,
  258. },
  259. [CONF_TX_AC_VI] = {
  260. .ac = CONF_TX_AC_VI,
  261. .cw_min = 15,
  262. .cw_max = 63,
  263. .aifsn = CONF_TX_AIFS_PIFS,
  264. .tx_op_limit = 3008,
  265. },
  266. [CONF_TX_AC_VO] = {
  267. .ac = CONF_TX_AC_VO,
  268. .cw_min = 15,
  269. .cw_max = 63,
  270. .aifsn = CONF_TX_AIFS_PIFS,
  271. .tx_op_limit = 1504,
  272. },
  273. },
  274. .max_tx_retries = 100,
  275. .ap_aging_period = 300,
  276. .tid_conf_count = 4,
  277. .tid_conf = {
  278. [CONF_TX_AC_BE] = {
  279. .queue_id = CONF_TX_AC_BE,
  280. .channel_type = CONF_CHANNEL_TYPE_EDCF,
  281. .tsid = CONF_TX_AC_BE,
  282. .ps_scheme = CONF_PS_SCHEME_LEGACY,
  283. .ack_policy = CONF_ACK_POLICY_LEGACY,
  284. .apsd_conf = {0, 0},
  285. },
  286. [CONF_TX_AC_BK] = {
  287. .queue_id = CONF_TX_AC_BK,
  288. .channel_type = CONF_CHANNEL_TYPE_EDCF,
  289. .tsid = CONF_TX_AC_BK,
  290. .ps_scheme = CONF_PS_SCHEME_LEGACY,
  291. .ack_policy = CONF_ACK_POLICY_LEGACY,
  292. .apsd_conf = {0, 0},
  293. },
  294. [CONF_TX_AC_VI] = {
  295. .queue_id = CONF_TX_AC_VI,
  296. .channel_type = CONF_CHANNEL_TYPE_EDCF,
  297. .tsid = CONF_TX_AC_VI,
  298. .ps_scheme = CONF_PS_SCHEME_LEGACY,
  299. .ack_policy = CONF_ACK_POLICY_LEGACY,
  300. .apsd_conf = {0, 0},
  301. },
  302. [CONF_TX_AC_VO] = {
  303. .queue_id = CONF_TX_AC_VO,
  304. .channel_type = CONF_CHANNEL_TYPE_EDCF,
  305. .tsid = CONF_TX_AC_VO,
  306. .ps_scheme = CONF_PS_SCHEME_LEGACY,
  307. .ack_policy = CONF_ACK_POLICY_LEGACY,
  308. .apsd_conf = {0, 0},
  309. },
  310. },
  311. .frag_threshold = IEEE80211_MAX_FRAG_THRESHOLD,
  312. .tx_compl_timeout = 350,
  313. .tx_compl_threshold = 10,
  314. .basic_rate = CONF_HW_BIT_RATE_1MBPS,
  315. .basic_rate_5 = CONF_HW_BIT_RATE_6MBPS,
  316. .tmpl_short_retry_limit = 10,
  317. .tmpl_long_retry_limit = 10,
  318. .tx_watchdog_timeout = 5000,
  319. },
  320. .conn = {
  321. .wake_up_event = CONF_WAKE_UP_EVENT_DTIM,
  322. .listen_interval = 1,
  323. .suspend_wake_up_event = CONF_WAKE_UP_EVENT_N_DTIM,
  324. .suspend_listen_interval = 3,
  325. .bcn_filt_mode = CONF_BCN_FILT_MODE_ENABLED,
  326. .bcn_filt_ie_count = 2,
  327. .bcn_filt_ie = {
  328. [0] = {
  329. .ie = WLAN_EID_CHANNEL_SWITCH,
  330. .rule = CONF_BCN_RULE_PASS_ON_APPEARANCE,
  331. },
  332. [1] = {
  333. .ie = WLAN_EID_HT_OPERATION,
  334. .rule = CONF_BCN_RULE_PASS_ON_CHANGE,
  335. },
  336. },
  337. .synch_fail_thold = 10,
  338. .bss_lose_timeout = 100,
  339. .beacon_rx_timeout = 10000,
  340. .broadcast_timeout = 20000,
  341. .rx_broadcast_in_ps = 1,
  342. .ps_poll_threshold = 10,
  343. .bet_enable = CONF_BET_MODE_ENABLE,
  344. .bet_max_consecutive = 50,
  345. .psm_entry_retries = 8,
  346. .psm_exit_retries = 16,
  347. .psm_entry_nullfunc_retries = 3,
  348. .dynamic_ps_timeout = 40,
  349. .forced_ps = false,
  350. .keep_alive_interval = 55000,
  351. .max_listen_interval = 20,
  352. },
  353. .itrim = {
  354. .enable = false,
  355. .timeout = 50000,
  356. },
  357. .pm_config = {
  358. .host_clk_settling_time = 5000,
  359. .host_fast_wakeup_support = false
  360. },
  361. .roam_trigger = {
  362. .trigger_pacing = 1,
  363. .avg_weight_rssi_beacon = 20,
  364. .avg_weight_rssi_data = 10,
  365. .avg_weight_snr_beacon = 20,
  366. .avg_weight_snr_data = 10,
  367. },
  368. .scan = {
  369. .min_dwell_time_active = 7500,
  370. .max_dwell_time_active = 30000,
  371. .min_dwell_time_passive = 100000,
  372. .max_dwell_time_passive = 100000,
  373. .num_probe_reqs = 2,
  374. .split_scan_timeout = 50000,
  375. },
  376. .sched_scan = {
  377. /*
  378. * Values are in TU/1000 but since sched scan FW command
  379. * params are in TUs rounding up may occur.
  380. */
  381. .base_dwell_time = 7500,
  382. .max_dwell_time_delta = 22500,
  383. /* based on 250bits per probe @1Mbps */
  384. .dwell_time_delta_per_probe = 2000,
  385. /* based on 250bits per probe @6Mbps (plus a bit more) */
  386. .dwell_time_delta_per_probe_5 = 350,
  387. .dwell_time_passive = 100000,
  388. .dwell_time_dfs = 150000,
  389. .num_probe_reqs = 2,
  390. .rssi_threshold = -90,
  391. .snr_threshold = 0,
  392. },
  393. .ht = {
  394. .rx_ba_win_size = 10,
  395. .tx_ba_win_size = 10,
  396. .inactivity_timeout = 10000,
  397. .tx_ba_tid_bitmap = CONF_TX_BA_ENABLED_TID_BITMAP,
  398. },
  399. .mem = {
  400. .num_stations = 1,
  401. .ssid_profiles = 1,
  402. .rx_block_num = 40,
  403. .tx_min_block_num = 40,
  404. .dynamic_memory = 1,
  405. .min_req_tx_blocks = 45,
  406. .min_req_rx_blocks = 22,
  407. .tx_min = 27,
  408. },
  409. .fm_coex = {
  410. .enable = true,
  411. .swallow_period = 5,
  412. .n_divider_fref_set_1 = 0xff, /* default */
  413. .n_divider_fref_set_2 = 12,
  414. .m_divider_fref_set_1 = 148,
  415. .m_divider_fref_set_2 = 0xffff, /* default */
  416. .coex_pll_stabilization_time = 0xffffffff, /* default */
  417. .ldo_stabilization_time = 0xffff, /* default */
  418. .fm_disturbed_band_margin = 0xff, /* default */
  419. .swallow_clk_diff = 0xff, /* default */
  420. },
  421. .rx_streaming = {
  422. .duration = 150,
  423. .queues = 0x1,
  424. .interval = 20,
  425. .always = 0,
  426. },
  427. .fwlog = {
  428. .mode = WL12XX_FWLOG_ON_DEMAND,
  429. .mem_blocks = 2,
  430. .severity = 0,
  431. .timestamp = WL12XX_FWLOG_TIMESTAMP_DISABLED,
  432. .output = WL12XX_FWLOG_OUTPUT_HOST,
  433. .threshold = 0,
  434. },
  435. .rate = {
  436. .rate_retry_score = 32000,
  437. .per_add = 8192,
  438. .per_th1 = 2048,
  439. .per_th2 = 4096,
  440. .max_per = 8100,
  441. .inverse_curiosity_factor = 5,
  442. .tx_fail_low_th = 4,
  443. .tx_fail_high_th = 10,
  444. .per_alpha_shift = 4,
  445. .per_add_shift = 13,
  446. .per_beta1_shift = 10,
  447. .per_beta2_shift = 8,
  448. .rate_check_up = 2,
  449. .rate_check_down = 12,
  450. .rate_retry_policy = {
  451. 0x00, 0x00, 0x00, 0x00, 0x00,
  452. 0x00, 0x00, 0x00, 0x00, 0x00,
  453. 0x00, 0x00, 0x00,
  454. },
  455. },
  456. .hangover = {
  457. .recover_time = 0,
  458. .hangover_period = 20,
  459. .dynamic_mode = 1,
  460. .early_termination_mode = 1,
  461. .max_period = 20,
  462. .min_period = 1,
  463. .increase_delta = 1,
  464. .decrease_delta = 2,
  465. .quiet_time = 4,
  466. .increase_time = 1,
  467. .window_size = 16,
  468. },
  469. };
  470. static struct wl18xx_priv_conf wl18xx_default_priv_conf = {
  471. .phy = {
  472. .phy_standalone = 0x00,
  473. .primary_clock_setting_time = 0x05,
  474. .clock_valid_on_wake_up = 0x00,
  475. .secondary_clock_setting_time = 0x05,
  476. .rdl = 0x01,
  477. .auto_detect = 0x00,
  478. .dedicated_fem = FEM_NONE,
  479. .low_band_component = COMPONENT_2_WAY_SWITCH,
  480. .low_band_component_type = 0x05,
  481. .high_band_component = COMPONENT_2_WAY_SWITCH,
  482. .high_band_component_type = 0x09,
  483. .tcxo_ldo_voltage = 0x00,
  484. .xtal_itrim_val = 0x04,
  485. .srf_state = 0x00,
  486. .io_configuration = 0x01,
  487. .sdio_configuration = 0x00,
  488. .settings = 0x00,
  489. .enable_clpc = 0x00,
  490. .enable_tx_low_pwr_on_siso_rdl = 0x00,
  491. .rx_profile = 0x00,
  492. .pwr_limit_reference_11_abg = 0xc8,
  493. },
  494. };
  495. static const struct wlcore_partition_set wl18xx_ptable[PART_TABLE_LEN] = {
  496. [PART_TOP_PRCM_ELP_SOC] = {
  497. .mem = { .start = 0x00A02000, .size = 0x00010000 },
  498. .reg = { .start = 0x00807000, .size = 0x00005000 },
  499. .mem2 = { .start = 0x00800000, .size = 0x0000B000 },
  500. .mem3 = { .start = 0x00000000, .size = 0x00000000 },
  501. },
  502. [PART_DOWN] = {
  503. .mem = { .start = 0x00000000, .size = 0x00014000 },
  504. .reg = { .start = 0x00810000, .size = 0x0000BFFF },
  505. .mem2 = { .start = 0x00000000, .size = 0x00000000 },
  506. .mem3 = { .start = 0x00000000, .size = 0x00000000 },
  507. },
  508. [PART_BOOT] = {
  509. .mem = { .start = 0x00700000, .size = 0x0000030c },
  510. .reg = { .start = 0x00802000, .size = 0x00014578 },
  511. .mem2 = { .start = 0x00B00404, .size = 0x00001000 },
  512. .mem3 = { .start = 0x00C00000, .size = 0x00000400 },
  513. },
  514. [PART_WORK] = {
  515. .mem = { .start = 0x00800000, .size = 0x000050FC },
  516. .reg = { .start = 0x00B00404, .size = 0x00001000 },
  517. .mem2 = { .start = 0x00C00000, .size = 0x00000400 },
  518. .mem3 = { .start = 0x00000000, .size = 0x00000000 },
  519. },
  520. [PART_PHY_INIT] = {
  521. /* TODO: use the phy_conf struct size here */
  522. .mem = { .start = 0x80926000, .size = 252 },
  523. .reg = { .start = 0x00000000, .size = 0x00000000 },
  524. .mem2 = { .start = 0x00000000, .size = 0x00000000 },
  525. .mem3 = { .start = 0x00000000, .size = 0x00000000 },
  526. },
  527. };
  528. static const int wl18xx_rtable[REG_TABLE_LEN] = {
  529. [REG_ECPU_CONTROL] = WL18XX_REG_ECPU_CONTROL,
  530. [REG_INTERRUPT_NO_CLEAR] = WL18XX_REG_INTERRUPT_NO_CLEAR,
  531. [REG_INTERRUPT_ACK] = WL18XX_REG_INTERRUPT_ACK,
  532. [REG_COMMAND_MAILBOX_PTR] = WL18XX_REG_COMMAND_MAILBOX_PTR,
  533. [REG_EVENT_MAILBOX_PTR] = WL18XX_REG_EVENT_MAILBOX_PTR,
  534. [REG_INTERRUPT_TRIG] = WL18XX_REG_INTERRUPT_TRIG_H,
  535. [REG_INTERRUPT_MASK] = WL18XX_REG_INTERRUPT_MASK,
  536. [REG_PC_ON_RECOVERY] = WL18XX_SCR_PAD4,
  537. [REG_CHIP_ID_B] = WL18XX_REG_CHIP_ID_B,
  538. [REG_CMD_MBOX_ADDRESS] = WL18XX_CMD_MBOX_ADDRESS,
  539. /* data access memory addresses, used with partition translation */
  540. [REG_SLV_MEM_DATA] = WL18XX_SLV_MEM_DATA,
  541. [REG_SLV_REG_DATA] = WL18XX_SLV_REG_DATA,
  542. /* raw data access memory addresses */
  543. [REG_RAW_FW_STATUS_ADDR] = WL18XX_FW_STATUS_ADDR,
  544. };
  545. static const struct wl18xx_clk_cfg wl18xx_clk_table[NUM_CLOCK_CONFIGS] = {
  546. [CLOCK_CONFIG_16_2_M] = { 7, 104, 801, 4, true },
  547. [CLOCK_CONFIG_16_368_M] = { 9, 132, 3751, 4, true },
  548. [CLOCK_CONFIG_16_8_M] = { 7, 100, 0, 0, false },
  549. [CLOCK_CONFIG_19_2_M] = { 8, 100, 0, 0, false },
  550. [CLOCK_CONFIG_26_M] = { 13, 120, 0, 0, false },
  551. [CLOCK_CONFIG_32_736_M] = { 9, 132, 3751, 4, true },
  552. [CLOCK_CONFIG_33_6_M] = { 7, 100, 0, 0, false },
  553. [CLOCK_CONFIG_38_468_M] = { 8, 100, 0, 0, false },
  554. [CLOCK_CONFIG_52_M] = { 13, 120, 0, 0, false },
  555. };
  556. /* TODO: maybe move to a new header file? */
  557. #define WL18XX_FW_NAME "ti-connectivity/wl18xx-fw.bin"
  558. static int wl18xx_identify_chip(struct wl1271 *wl)
  559. {
  560. int ret = 0;
  561. switch (wl->chip.id) {
  562. case CHIP_ID_185x_PG10:
  563. wl1271_debug(DEBUG_BOOT, "chip id 0x%x (185x PG10)",
  564. wl->chip.id);
  565. wl->sr_fw_name = WL18XX_FW_NAME;
  566. /* wl18xx uses the same firmware for PLT */
  567. wl->plt_fw_name = WL18XX_FW_NAME;
  568. wl->quirks |= WLCORE_QUIRK_NO_ELP |
  569. WLCORE_QUIRK_FWLOG_NOT_IMPLEMENTED |
  570. WLCORE_QUIRK_RX_BLOCKSIZE_ALIGN;
  571. /* PG 1.0 has some problems with MCS_13, so disable it */
  572. wl->ht_cap.mcs.rx_mask[1] &= ~BIT(5);
  573. /* TODO: need to blocksize alignment for RX/TX separately? */
  574. break;
  575. default:
  576. wl1271_warning("unsupported chip id: 0x%x", wl->chip.id);
  577. ret = -ENODEV;
  578. goto out;
  579. }
  580. out:
  581. return ret;
  582. }
  583. static void wl18xx_set_clk(struct wl1271 *wl)
  584. {
  585. u32 clk_freq;
  586. wlcore_set_partition(wl, &wl->ptable[PART_TOP_PRCM_ELP_SOC]);
  587. /* TODO: PG2: apparently we need to read the clk type */
  588. clk_freq = wl18xx_top_reg_read(wl, PRIMARY_CLK_DETECT);
  589. wl1271_debug(DEBUG_BOOT, "clock freq %d (%d, %d, %d, %d, %s)", clk_freq,
  590. wl18xx_clk_table[clk_freq].n, wl18xx_clk_table[clk_freq].m,
  591. wl18xx_clk_table[clk_freq].p, wl18xx_clk_table[clk_freq].q,
  592. wl18xx_clk_table[clk_freq].swallow ? "swallow" : "spit");
  593. wl18xx_top_reg_write(wl, PLLSH_WCS_PLL_N, wl18xx_clk_table[clk_freq].n);
  594. wl18xx_top_reg_write(wl, PLLSH_WCS_PLL_M, wl18xx_clk_table[clk_freq].m);
  595. if (wl18xx_clk_table[clk_freq].swallow) {
  596. /* first the 16 lower bits */
  597. wl18xx_top_reg_write(wl, PLLSH_WCS_PLL_Q_FACTOR_CFG_1,
  598. wl18xx_clk_table[clk_freq].q &
  599. PLLSH_WCS_PLL_Q_FACTOR_CFG_1_MASK);
  600. /* then the 16 higher bits, masked out */
  601. wl18xx_top_reg_write(wl, PLLSH_WCS_PLL_Q_FACTOR_CFG_2,
  602. (wl18xx_clk_table[clk_freq].q >> 16) &
  603. PLLSH_WCS_PLL_Q_FACTOR_CFG_2_MASK);
  604. /* first the 16 lower bits */
  605. wl18xx_top_reg_write(wl, PLLSH_WCS_PLL_P_FACTOR_CFG_1,
  606. wl18xx_clk_table[clk_freq].p &
  607. PLLSH_WCS_PLL_P_FACTOR_CFG_1_MASK);
  608. /* then the 16 higher bits, masked out */
  609. wl18xx_top_reg_write(wl, PLLSH_WCS_PLL_P_FACTOR_CFG_2,
  610. (wl18xx_clk_table[clk_freq].p >> 16) &
  611. PLLSH_WCS_PLL_P_FACTOR_CFG_2_MASK);
  612. } else {
  613. wl18xx_top_reg_write(wl, PLLSH_WCS_PLL_SWALLOW_EN,
  614. PLLSH_WCS_PLL_SWALLOW_EN_VAL2);
  615. }
  616. }
  617. static void wl18xx_boot_soft_reset(struct wl1271 *wl)
  618. {
  619. /* disable Rx/Tx */
  620. wl1271_write32(wl, WL18XX_ENABLE, 0x0);
  621. /* disable auto calibration on start*/
  622. wl1271_write32(wl, WL18XX_SPARE_A2, 0xffff);
  623. }
  624. static int wl18xx_pre_boot(struct wl1271 *wl)
  625. {
  626. wl18xx_set_clk(wl);
  627. /* Continue the ELP wake up sequence */
  628. wl1271_write32(wl, WL18XX_WELP_ARM_COMMAND, WELP_ARM_COMMAND_VAL);
  629. udelay(500);
  630. wlcore_set_partition(wl, &wl->ptable[PART_BOOT]);
  631. /* Disable interrupts */
  632. wlcore_write_reg(wl, REG_INTERRUPT_MASK, WL1271_ACX_INTR_ALL);
  633. wl18xx_boot_soft_reset(wl);
  634. return 0;
  635. }
  636. static void wl18xx_pre_upload(struct wl1271 *wl)
  637. {
  638. u32 tmp;
  639. wlcore_set_partition(wl, &wl->ptable[PART_BOOT]);
  640. /* TODO: check if this is all needed */
  641. wl1271_write32(wl, WL18XX_EEPROMLESS_IND, WL18XX_EEPROMLESS_IND);
  642. tmp = wlcore_read_reg(wl, REG_CHIP_ID_B);
  643. wl1271_debug(DEBUG_BOOT, "chip id 0x%x", tmp);
  644. tmp = wl1271_read32(wl, WL18XX_SCR_PAD2);
  645. }
  646. static void wl18xx_set_mac_and_phy(struct wl1271 *wl)
  647. {
  648. struct wl18xx_priv *priv = wl->priv;
  649. struct wl18xx_conf_phy *phy = &priv->conf.phy;
  650. struct wl18xx_mac_and_phy_params params;
  651. memset(&params, 0, sizeof(params));
  652. params.phy_standalone = phy->phy_standalone;
  653. params.rdl = phy->rdl;
  654. params.enable_clpc = phy->enable_clpc;
  655. params.enable_tx_low_pwr_on_siso_rdl =
  656. phy->enable_tx_low_pwr_on_siso_rdl;
  657. params.auto_detect = phy->auto_detect;
  658. params.dedicated_fem = phy->dedicated_fem;
  659. params.low_band_component = phy->low_band_component;
  660. params.low_band_component_type =
  661. phy->low_band_component_type;
  662. params.high_band_component = phy->high_band_component;
  663. params.high_band_component_type =
  664. phy->high_band_component_type;
  665. params.number_of_assembled_ant2_4 =
  666. n_antennas_2_param;
  667. params.number_of_assembled_ant5 =
  668. n_antennas_5_param;
  669. params.external_pa_dc2dc = dc2dc_param;
  670. params.tcxo_ldo_voltage = phy->tcxo_ldo_voltage;
  671. params.xtal_itrim_val = phy->xtal_itrim_val;
  672. params.srf_state = phy->srf_state;
  673. params.io_configuration = phy->io_configuration;
  674. params.sdio_configuration = phy->sdio_configuration;
  675. params.settings = phy->settings;
  676. params.rx_profile = phy->rx_profile;
  677. params.primary_clock_setting_time =
  678. phy->primary_clock_setting_time;
  679. params.clock_valid_on_wake_up =
  680. phy->clock_valid_on_wake_up;
  681. params.secondary_clock_setting_time =
  682. phy->secondary_clock_setting_time;
  683. params.pwr_limit_reference_11_abg =
  684. phy->pwr_limit_reference_11_abg;
  685. params.board_type = priv->board_type;
  686. wlcore_set_partition(wl, &wl->ptable[PART_PHY_INIT]);
  687. wl1271_write(wl, WL18XX_PHY_INIT_MEM_ADDR, (u8 *)&params,
  688. sizeof(params), false);
  689. }
  690. static void wl18xx_enable_interrupts(struct wl1271 *wl)
  691. {
  692. wlcore_write_reg(wl, REG_INTERRUPT_MASK, WL1271_ACX_ALL_EVENTS_VECTOR);
  693. wlcore_enable_interrupts(wl);
  694. wlcore_write_reg(wl, REG_INTERRUPT_MASK,
  695. WL1271_ACX_INTR_ALL & ~(WL1271_INTR_MASK));
  696. }
  697. static int wl18xx_boot(struct wl1271 *wl)
  698. {
  699. int ret;
  700. ret = wl18xx_pre_boot(wl);
  701. if (ret < 0)
  702. goto out;
  703. wl18xx_pre_upload(wl);
  704. ret = wlcore_boot_upload_firmware(wl);
  705. if (ret < 0)
  706. goto out;
  707. wl18xx_set_mac_and_phy(wl);
  708. ret = wlcore_boot_run_firmware(wl);
  709. if (ret < 0)
  710. goto out;
  711. wl18xx_enable_interrupts(wl);
  712. out:
  713. return ret;
  714. }
  715. static void wl18xx_trigger_cmd(struct wl1271 *wl, int cmd_box_addr,
  716. void *buf, size_t len)
  717. {
  718. struct wl18xx_priv *priv = wl->priv;
  719. memcpy(priv->cmd_buf, buf, len);
  720. memset(priv->cmd_buf + len, 0, WL18XX_CMD_MAX_SIZE - len);
  721. wl1271_write(wl, cmd_box_addr, priv->cmd_buf, WL18XX_CMD_MAX_SIZE,
  722. false);
  723. }
  724. static void wl18xx_ack_event(struct wl1271 *wl)
  725. {
  726. wlcore_write_reg(wl, REG_INTERRUPT_TRIG, WL18XX_INTR_TRIG_EVENT_ACK);
  727. }
  728. static u32 wl18xx_calc_tx_blocks(struct wl1271 *wl, u32 len, u32 spare_blks)
  729. {
  730. u32 blk_size = WL18XX_TX_HW_BLOCK_SIZE;
  731. return (len + blk_size - 1) / blk_size + spare_blks;
  732. }
  733. static void
  734. wl18xx_set_tx_desc_blocks(struct wl1271 *wl, struct wl1271_tx_hw_descr *desc,
  735. u32 blks, u32 spare_blks)
  736. {
  737. desc->wl18xx_mem.total_mem_blocks = blks;
  738. desc->wl18xx_mem.reserved = 0;
  739. }
  740. static void
  741. wl18xx_set_tx_desc_data_len(struct wl1271 *wl, struct wl1271_tx_hw_descr *desc,
  742. struct sk_buff *skb)
  743. {
  744. desc->length = cpu_to_le16(skb->len);
  745. wl1271_debug(DEBUG_TX, "tx_fill_hdr: hlid: %d "
  746. "len: %d life: %d mem: %d", desc->hlid,
  747. le16_to_cpu(desc->length),
  748. le16_to_cpu(desc->life_time),
  749. desc->wl18xx_mem.total_mem_blocks);
  750. }
  751. static enum wl_rx_buf_align
  752. wl18xx_get_rx_buf_align(struct wl1271 *wl, u32 rx_desc)
  753. {
  754. if (rx_desc & RX_BUF_PADDED_PAYLOAD)
  755. return WLCORE_RX_BUF_PADDED;
  756. return WLCORE_RX_BUF_ALIGNED;
  757. }
  758. static u32 wl18xx_get_rx_packet_len(struct wl1271 *wl, void *rx_data,
  759. u32 data_len)
  760. {
  761. struct wl1271_rx_descriptor *desc = rx_data;
  762. /* invalid packet */
  763. if (data_len < sizeof(*desc))
  764. return 0;
  765. return data_len - sizeof(*desc);
  766. }
  767. static void wl18xx_tx_immediate_completion(struct wl1271 *wl)
  768. {
  769. wl18xx_tx_immediate_complete(wl);
  770. }
  771. static int wl18xx_hw_init(struct wl1271 *wl)
  772. {
  773. int ret;
  774. struct wl18xx_priv *priv = wl->priv;
  775. u32 host_cfg_bitmap = HOST_IF_CFG_RX_FIFO_ENABLE |
  776. HOST_IF_CFG_ADD_RX_ALIGNMENT;
  777. u32 sdio_align_size = 0;
  778. /* (re)init private structures. Relevant on recovery as well. */
  779. priv->last_fw_rls_idx = 0;
  780. /* Enable Tx SDIO padding */
  781. if (wl->quirks & WLCORE_QUIRK_TX_BLOCKSIZE_ALIGN) {
  782. host_cfg_bitmap |= HOST_IF_CFG_TX_PAD_TO_SDIO_BLK;
  783. sdio_align_size = WL12XX_BUS_BLOCK_SIZE;
  784. }
  785. /* Enable Rx SDIO padding */
  786. if (wl->quirks & WLCORE_QUIRK_RX_BLOCKSIZE_ALIGN) {
  787. host_cfg_bitmap |= HOST_IF_CFG_RX_PAD_TO_SDIO_BLK;
  788. sdio_align_size = WL12XX_BUS_BLOCK_SIZE;
  789. }
  790. ret = wl18xx_acx_host_if_cfg_bitmap(wl, host_cfg_bitmap,
  791. sdio_align_size,
  792. WL18XX_TX_HW_BLOCK_SPARE,
  793. WL18XX_HOST_IF_LEN_SIZE_FIELD);
  794. if (ret < 0)
  795. return ret;
  796. if (checksum_param) {
  797. ret = wl18xx_acx_set_checksum_state(wl);
  798. if (ret != 0)
  799. return ret;
  800. }
  801. return ret;
  802. }
  803. static void wl18xx_set_tx_desc_csum(struct wl1271 *wl,
  804. struct wl1271_tx_hw_descr *desc,
  805. struct sk_buff *skb)
  806. {
  807. u32 ip_hdr_offset;
  808. struct iphdr *ip_hdr;
  809. if (!checksum_param) {
  810. desc->wl18xx_checksum_data = 0;
  811. return;
  812. }
  813. if (skb->ip_summed != CHECKSUM_PARTIAL) {
  814. desc->wl18xx_checksum_data = 0;
  815. return;
  816. }
  817. ip_hdr_offset = skb_network_header(skb) - skb_mac_header(skb);
  818. if (WARN_ON(ip_hdr_offset >= (1<<7))) {
  819. desc->wl18xx_checksum_data = 0;
  820. return;
  821. }
  822. desc->wl18xx_checksum_data = ip_hdr_offset << 1;
  823. /* FW is interested only in the LSB of the protocol TCP=0 UDP=1 */
  824. ip_hdr = (void *)skb_network_header(skb);
  825. desc->wl18xx_checksum_data |= (ip_hdr->protocol & 0x01);
  826. }
  827. static void wl18xx_set_rx_csum(struct wl1271 *wl,
  828. struct wl1271_rx_descriptor *desc,
  829. struct sk_buff *skb)
  830. {
  831. if (desc->status & WL18XX_RX_CHECKSUM_MASK)
  832. skb->ip_summed = CHECKSUM_UNNECESSARY;
  833. }
  834. /*
  835. * TODO: instead of having these two functions to get the rate mask,
  836. * we should modify the wlvif->rate_set instead
  837. */
  838. static u32 wl18xx_sta_get_ap_rate_mask(struct wl1271 *wl,
  839. struct wl12xx_vif *wlvif)
  840. {
  841. u32 hw_rate_set = wlvif->rate_set;
  842. if (wlvif->channel_type == NL80211_CHAN_HT40MINUS ||
  843. wlvif->channel_type == NL80211_CHAN_HT40PLUS) {
  844. wl1271_debug(DEBUG_ACX, "using wide channel rate mask");
  845. hw_rate_set |= CONF_TX_RATE_USE_WIDE_CHAN;
  846. /* we don't support MIMO in wide-channel mode */
  847. hw_rate_set &= ~CONF_TX_MIMO_RATES;
  848. }
  849. return hw_rate_set;
  850. }
  851. static u32 wl18xx_ap_get_mimo_wide_rate_mask(struct wl1271 *wl,
  852. struct wl12xx_vif *wlvif)
  853. {
  854. if ((wlvif->channel_type == NL80211_CHAN_HT40MINUS ||
  855. wlvif->channel_type == NL80211_CHAN_HT40PLUS) &&
  856. !strcmp(ht_mode_param, "wide")) {
  857. wl1271_debug(DEBUG_ACX, "using wide channel rate mask");
  858. return CONF_TX_RATE_USE_WIDE_CHAN;
  859. } else if (!strcmp(ht_mode_param, "mimo")) {
  860. wl1271_debug(DEBUG_ACX, "using MIMO rate mask");
  861. /*
  862. * PG 1.0 has some problems with MCS_13, so disable it
  863. *
  864. * TODO: instead of hacking this in here, we should
  865. * make it more general and change a bit in the
  866. * wlvif->rate_set instead.
  867. */
  868. if (wl->chip.id == CHIP_ID_185x_PG10)
  869. return CONF_TX_MIMO_RATES & ~CONF_HW_BIT_RATE_MCS_13;
  870. return CONF_TX_MIMO_RATES;
  871. } else {
  872. return 0;
  873. }
  874. }
  875. static s8 wl18xx_get_pg_ver(struct wl1271 *wl)
  876. {
  877. u32 fuse;
  878. wlcore_set_partition(wl, &wl->ptable[PART_TOP_PRCM_ELP_SOC]);
  879. fuse = wl1271_read32(wl, WL18XX_REG_FUSE_DATA_1_3);
  880. fuse = (fuse & WL18XX_PG_VER_MASK) >> WL18XX_PG_VER_OFFSET;
  881. wlcore_set_partition(wl, &wl->ptable[PART_BOOT]);
  882. return (s8)fuse;
  883. }
  884. static void wl18xx_conf_init(struct wl1271 *wl)
  885. {
  886. struct wl18xx_priv *priv = wl->priv;
  887. /* apply driver default configuration */
  888. memcpy(&wl->conf, &wl18xx_conf, sizeof(wl18xx_conf));
  889. /* apply default private configuration */
  890. memcpy(&priv->conf, &wl18xx_default_priv_conf, sizeof(priv->conf));
  891. }
  892. static int wl18xx_plt_init(struct wl1271 *wl)
  893. {
  894. wl1271_write32(wl, WL18XX_SCR_PAD8, WL18XX_SCR_PAD8_PLT);
  895. return wl->ops->boot(wl);
  896. }
  897. static void wl18xx_get_mac(struct wl1271 *wl)
  898. {
  899. u32 mac1, mac2;
  900. wlcore_set_partition(wl, &wl->ptable[PART_TOP_PRCM_ELP_SOC]);
  901. mac1 = wl1271_read32(wl, WL18XX_REG_FUSE_BD_ADDR_1);
  902. mac2 = wl1271_read32(wl, WL18XX_REG_FUSE_BD_ADDR_2);
  903. /* these are the two parts of the BD_ADDR */
  904. wl->fuse_oui_addr = ((mac2 & 0xffff) << 8) +
  905. ((mac1 & 0xff000000) >> 24);
  906. wl->fuse_nic_addr = (mac1 & 0xffffff);
  907. wlcore_set_partition(wl, &wl->ptable[PART_DOWN]);
  908. }
  909. static int wl18xx_handle_static_data(struct wl1271 *wl,
  910. struct wl1271_static_data *static_data)
  911. {
  912. struct wl18xx_static_data_priv *static_data_priv =
  913. (struct wl18xx_static_data_priv *) static_data->priv;
  914. wl1271_info("PHY firmware version: %s", static_data_priv->phy_version);
  915. return 0;
  916. }
  917. static struct wlcore_ops wl18xx_ops = {
  918. .identify_chip = wl18xx_identify_chip,
  919. .boot = wl18xx_boot,
  920. .plt_init = wl18xx_plt_init,
  921. .trigger_cmd = wl18xx_trigger_cmd,
  922. .ack_event = wl18xx_ack_event,
  923. .calc_tx_blocks = wl18xx_calc_tx_blocks,
  924. .set_tx_desc_blocks = wl18xx_set_tx_desc_blocks,
  925. .set_tx_desc_data_len = wl18xx_set_tx_desc_data_len,
  926. .get_rx_buf_align = wl18xx_get_rx_buf_align,
  927. .get_rx_packet_len = wl18xx_get_rx_packet_len,
  928. .tx_immediate_compl = wl18xx_tx_immediate_completion,
  929. .tx_delayed_compl = NULL,
  930. .hw_init = wl18xx_hw_init,
  931. .set_tx_desc_csum = wl18xx_set_tx_desc_csum,
  932. .get_pg_ver = wl18xx_get_pg_ver,
  933. .set_rx_csum = wl18xx_set_rx_csum,
  934. .sta_get_ap_rate_mask = wl18xx_sta_get_ap_rate_mask,
  935. .ap_get_mimo_wide_rate_mask = wl18xx_ap_get_mimo_wide_rate_mask,
  936. .get_mac = wl18xx_get_mac,
  937. .debugfs_init = wl18xx_debugfs_add_files,
  938. .handle_static_data = wl18xx_handle_static_data,
  939. };
  940. /* HT cap appropriate for wide channels */
  941. static struct ieee80211_sta_ht_cap wl18xx_siso40_ht_cap = {
  942. .cap = IEEE80211_HT_CAP_SGI_20 | IEEE80211_HT_CAP_SGI_40 |
  943. IEEE80211_HT_CAP_SUP_WIDTH_20_40 | IEEE80211_HT_CAP_DSSSCCK40,
  944. .ht_supported = true,
  945. .ampdu_factor = IEEE80211_HT_MAX_AMPDU_16K,
  946. .ampdu_density = IEEE80211_HT_MPDU_DENSITY_16,
  947. .mcs = {
  948. .rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
  949. .rx_highest = cpu_to_le16(150),
  950. .tx_params = IEEE80211_HT_MCS_TX_DEFINED,
  951. },
  952. };
  953. /* HT cap appropriate for SISO 20 */
  954. static struct ieee80211_sta_ht_cap wl18xx_siso20_ht_cap = {
  955. .cap = IEEE80211_HT_CAP_SGI_20,
  956. .ht_supported = true,
  957. .ampdu_factor = IEEE80211_HT_MAX_AMPDU_16K,
  958. .ampdu_density = IEEE80211_HT_MPDU_DENSITY_16,
  959. .mcs = {
  960. .rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
  961. .rx_highest = cpu_to_le16(72),
  962. .tx_params = IEEE80211_HT_MCS_TX_DEFINED,
  963. },
  964. };
  965. /* HT cap appropriate for MIMO rates in 20mhz channel */
  966. static struct ieee80211_sta_ht_cap wl18xx_mimo_ht_cap = {
  967. .cap = IEEE80211_HT_CAP_SGI_20,
  968. .ht_supported = true,
  969. .ampdu_factor = IEEE80211_HT_MAX_AMPDU_16K,
  970. .ampdu_density = IEEE80211_HT_MPDU_DENSITY_16,
  971. .mcs = {
  972. .rx_mask = { 0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0, },
  973. .rx_highest = cpu_to_le16(144),
  974. .tx_params = IEEE80211_HT_MCS_TX_DEFINED,
  975. },
  976. };
  977. int __devinit wl18xx_probe(struct platform_device *pdev)
  978. {
  979. struct wl1271 *wl;
  980. struct ieee80211_hw *hw;
  981. struct wl18xx_priv *priv;
  982. hw = wlcore_alloc_hw(sizeof(*priv));
  983. if (IS_ERR(hw)) {
  984. wl1271_error("can't allocate hw");
  985. return PTR_ERR(hw);
  986. }
  987. wl = hw->priv;
  988. priv = wl->priv;
  989. wl->ops = &wl18xx_ops;
  990. wl->ptable = wl18xx_ptable;
  991. wl->rtable = wl18xx_rtable;
  992. wl->num_tx_desc = 32;
  993. wl->num_rx_desc = 16;
  994. wl->normal_tx_spare = WL18XX_TX_HW_BLOCK_SPARE;
  995. wl->gem_tx_spare = WL18XX_TX_HW_GEM_BLOCK_SPARE;
  996. wl->band_rate_to_idx = wl18xx_band_rate_to_idx;
  997. wl->hw_tx_rate_tbl_size = WL18XX_CONF_HW_RXTX_RATE_MAX;
  998. wl->hw_min_ht_rate = WL18XX_CONF_HW_RXTX_RATE_MCS0;
  999. wl->fw_status_priv_len = sizeof(struct wl18xx_fw_status_priv);
  1000. wl->stats.fw_stats_len = sizeof(struct wl18xx_acx_statistics);
  1001. wl->static_data_priv_len = sizeof(struct wl18xx_static_data_priv);
  1002. if (!strcmp(ht_mode_param, "wide")) {
  1003. memcpy(&wl->ht_cap, &wl18xx_siso40_ht_cap,
  1004. sizeof(wl18xx_siso40_ht_cap));
  1005. } else if (!strcmp(ht_mode_param, "mimo")) {
  1006. memcpy(&wl->ht_cap, &wl18xx_mimo_ht_cap,
  1007. sizeof(wl18xx_mimo_ht_cap));
  1008. } else if (!strcmp(ht_mode_param, "siso20")) {
  1009. memcpy(&wl->ht_cap, &wl18xx_siso20_ht_cap,
  1010. sizeof(wl18xx_siso20_ht_cap));
  1011. } else {
  1012. wl1271_error("invalid ht_mode '%s'", ht_mode_param);
  1013. goto out_free;
  1014. }
  1015. wl18xx_conf_init(wl);
  1016. if (!strcmp(board_type_param, "fpga")) {
  1017. priv->board_type = BOARD_TYPE_FPGA_18XX;
  1018. } else if (!strcmp(board_type_param, "hdk")) {
  1019. priv->board_type = BOARD_TYPE_HDK_18XX;
  1020. /* HACK! Just for now we hardcode HDK to 0x06 */
  1021. priv->conf.phy.low_band_component_type = 0x06;
  1022. } else if (!strcmp(board_type_param, "dvp")) {
  1023. priv->board_type = BOARD_TYPE_DVP_18XX;
  1024. } else if (!strcmp(board_type_param, "evb")) {
  1025. priv->board_type = BOARD_TYPE_EVB_18XX;
  1026. } else if (!strcmp(board_type_param, "com8")) {
  1027. priv->board_type = BOARD_TYPE_COM8_18XX;
  1028. /* HACK! Just for now we hardcode COM8 to 0x06 */
  1029. priv->conf.phy.low_band_component_type = 0x06;
  1030. } else {
  1031. wl1271_error("invalid board type '%s'", board_type_param);
  1032. goto out_free;
  1033. }
  1034. /*
  1035. * If the module param is not set, update it with the one from
  1036. * conf. If it is set, overwrite conf with it.
  1037. */
  1038. if (low_band_component == -1)
  1039. low_band_component = priv->conf.phy.low_band_component;
  1040. else
  1041. priv->conf.phy.low_band_component = low_band_component;
  1042. if (low_band_component_type == -1)
  1043. low_band_component_type =
  1044. priv->conf.phy.low_band_component_type;
  1045. else
  1046. priv->conf.phy.low_band_component_type =
  1047. low_band_component_type;
  1048. if (high_band_component == -1)
  1049. high_band_component = priv->conf.phy.high_band_component;
  1050. else
  1051. priv->conf.phy.high_band_component = high_band_component;
  1052. if (high_band_component_type == -1)
  1053. high_band_component_type =
  1054. priv->conf.phy.high_band_component_type;
  1055. else
  1056. priv->conf.phy.high_band_component_type =
  1057. high_band_component_type;
  1058. if (pwr_limit_reference_11_abg == -1)
  1059. pwr_limit_reference_11_abg =
  1060. priv->conf.phy.pwr_limit_reference_11_abg;
  1061. else
  1062. priv->conf.phy.pwr_limit_reference_11_abg =
  1063. pwr_limit_reference_11_abg;
  1064. if (!checksum_param) {
  1065. wl18xx_ops.set_rx_csum = NULL;
  1066. wl18xx_ops.init_vif = NULL;
  1067. }
  1068. wl->enable_11a = enable_11a_param;
  1069. return wlcore_probe(wl, pdev);
  1070. out_free:
  1071. wlcore_free_hw(wl);
  1072. return -EINVAL;
  1073. }
  1074. static const struct platform_device_id wl18xx_id_table[] __devinitconst = {
  1075. { "wl18xx", 0 },
  1076. { } /* Terminating Entry */
  1077. };
  1078. MODULE_DEVICE_TABLE(platform, wl18xx_id_table);
  1079. static struct platform_driver wl18xx_driver = {
  1080. .probe = wl18xx_probe,
  1081. .remove = __devexit_p(wlcore_remove),
  1082. .id_table = wl18xx_id_table,
  1083. .driver = {
  1084. .name = "wl18xx_driver",
  1085. .owner = THIS_MODULE,
  1086. }
  1087. };
  1088. static int __init wl18xx_init(void)
  1089. {
  1090. return platform_driver_register(&wl18xx_driver);
  1091. }
  1092. module_init(wl18xx_init);
  1093. static void __exit wl18xx_exit(void)
  1094. {
  1095. platform_driver_unregister(&wl18xx_driver);
  1096. }
  1097. module_exit(wl18xx_exit);
  1098. module_param_named(ht_mode, ht_mode_param, charp, S_IRUSR);
  1099. MODULE_PARM_DESC(ht_mode, "Force HT mode: wide (default), mimo or siso20");
  1100. module_param_named(board_type, board_type_param, charp, S_IRUSR);
  1101. MODULE_PARM_DESC(board_type, "Board type: fpga, hdk (default), evb, com8 or "
  1102. "dvp");
  1103. module_param_named(dc2dc, dc2dc_param, bool, S_IRUSR);
  1104. MODULE_PARM_DESC(dc2dc, "External DC2DC: boolean (defaults to false)");
  1105. module_param_named(n_antennas_2, n_antennas_2_param, uint, S_IRUSR);
  1106. MODULE_PARM_DESC(n_antennas_2, "Number of installed 2.4GHz antennas: 1 (default) or 2");
  1107. module_param_named(n_antennas_5, n_antennas_5_param, uint, S_IRUSR);
  1108. MODULE_PARM_DESC(n_antennas_5, "Number of installed 5GHz antennas: 1 (default) or 2");
  1109. module_param_named(checksum, checksum_param, bool, S_IRUSR);
  1110. MODULE_PARM_DESC(checksum, "Enable TCP checksum: boolean (defaults to true)");
  1111. module_param_named(enable_11a, enable_11a_param, bool, S_IRUSR);
  1112. MODULE_PARM_DESC(enable_11a, "Enable 11a (5GHz): boolean (defaults to true)");
  1113. module_param(low_band_component, uint, S_IRUSR);
  1114. MODULE_PARM_DESC(low_band_component, "Low band component: u8 "
  1115. "(default is 0x01)");
  1116. module_param(low_band_component_type, uint, S_IRUSR);
  1117. MODULE_PARM_DESC(low_band_component_type, "Low band component type: u8 "
  1118. "(default is 0x05 or 0x06 depending on the board_type)");
  1119. module_param(high_band_component, uint, S_IRUSR);
  1120. MODULE_PARM_DESC(high_band_component, "High band component: u8, "
  1121. "(default is 0x01)");
  1122. module_param(high_band_component_type, uint, S_IRUSR);
  1123. MODULE_PARM_DESC(high_band_component_type, "High band component type: u8 "
  1124. "(default is 0x09)");
  1125. module_param(pwr_limit_reference_11_abg, uint, S_IRUSR);
  1126. MODULE_PARM_DESC(pwr_limit_reference_11_abg, "Power limit reference: u8 "
  1127. "(default is 0xc8)");
  1128. MODULE_LICENSE("GPL v2");
  1129. MODULE_AUTHOR("Luciano Coelho <coelho@ti.com>");
  1130. MODULE_FIRMWARE(WL18XX_FW_NAME);