init.c 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764
  1. /*
  2. * Copyright (c) 2011 Atheros Communications Inc.
  3. * Copyright (c) 2011-2012 Qualcomm Atheros, Inc.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  18. #include <linux/moduleparam.h>
  19. #include <linux/errno.h>
  20. #include <linux/export.h>
  21. #include <linux/of.h>
  22. #include <linux/mmc/sdio_func.h>
  23. #include <linux/vmalloc.h>
  24. #include "core.h"
  25. #include "cfg80211.h"
  26. #include "target.h"
  27. #include "debug.h"
  28. #include "hif-ops.h"
  29. #include "htc-ops.h"
  30. static const struct ath6kl_hw hw_list[] = {
  31. {
  32. .id = AR6003_HW_2_0_VERSION,
  33. .name = "ar6003 hw 2.0",
  34. .dataset_patch_addr = 0x57e884,
  35. .app_load_addr = 0x543180,
  36. .board_ext_data_addr = 0x57e500,
  37. .reserved_ram_size = 6912,
  38. .refclk_hz = 26000000,
  39. .uarttx_pin = 8,
  40. .flags = 0,
  41. /* hw2.0 needs override address hardcoded */
  42. .app_start_override_addr = 0x944C00,
  43. .fw = {
  44. .dir = AR6003_HW_2_0_FW_DIR,
  45. .otp = AR6003_HW_2_0_OTP_FILE,
  46. .fw = AR6003_HW_2_0_FIRMWARE_FILE,
  47. .tcmd = AR6003_HW_2_0_TCMD_FIRMWARE_FILE,
  48. .patch = AR6003_HW_2_0_PATCH_FILE,
  49. },
  50. .fw_board = AR6003_HW_2_0_BOARD_DATA_FILE,
  51. .fw_default_board = AR6003_HW_2_0_DEFAULT_BOARD_DATA_FILE,
  52. },
  53. {
  54. .id = AR6003_HW_2_1_1_VERSION,
  55. .name = "ar6003 hw 2.1.1",
  56. .dataset_patch_addr = 0x57ff74,
  57. .app_load_addr = 0x1234,
  58. .board_ext_data_addr = 0x542330,
  59. .reserved_ram_size = 512,
  60. .refclk_hz = 26000000,
  61. .uarttx_pin = 8,
  62. .testscript_addr = 0x57ef74,
  63. .flags = 0,
  64. .fw = {
  65. .dir = AR6003_HW_2_1_1_FW_DIR,
  66. .otp = AR6003_HW_2_1_1_OTP_FILE,
  67. .fw = AR6003_HW_2_1_1_FIRMWARE_FILE,
  68. .tcmd = AR6003_HW_2_1_1_TCMD_FIRMWARE_FILE,
  69. .patch = AR6003_HW_2_1_1_PATCH_FILE,
  70. .utf = AR6003_HW_2_1_1_UTF_FIRMWARE_FILE,
  71. .testscript = AR6003_HW_2_1_1_TESTSCRIPT_FILE,
  72. },
  73. .fw_board = AR6003_HW_2_1_1_BOARD_DATA_FILE,
  74. .fw_default_board = AR6003_HW_2_1_1_DEFAULT_BOARD_DATA_FILE,
  75. },
  76. {
  77. .id = AR6004_HW_1_0_VERSION,
  78. .name = "ar6004 hw 1.0",
  79. .dataset_patch_addr = 0x57e884,
  80. .app_load_addr = 0x1234,
  81. .board_ext_data_addr = 0x437000,
  82. .reserved_ram_size = 19456,
  83. .board_addr = 0x433900,
  84. .refclk_hz = 26000000,
  85. .uarttx_pin = 11,
  86. .flags = ATH6KL_HW_FLAG_64BIT_RATES,
  87. .fw = {
  88. .dir = AR6004_HW_1_0_FW_DIR,
  89. .fw = AR6004_HW_1_0_FIRMWARE_FILE,
  90. },
  91. .fw_board = AR6004_HW_1_0_BOARD_DATA_FILE,
  92. .fw_default_board = AR6004_HW_1_0_DEFAULT_BOARD_DATA_FILE,
  93. },
  94. {
  95. .id = AR6004_HW_1_1_VERSION,
  96. .name = "ar6004 hw 1.1",
  97. .dataset_patch_addr = 0x57e884,
  98. .app_load_addr = 0x1234,
  99. .board_ext_data_addr = 0x437000,
  100. .reserved_ram_size = 11264,
  101. .board_addr = 0x43d400,
  102. .refclk_hz = 40000000,
  103. .uarttx_pin = 11,
  104. .flags = ATH6KL_HW_FLAG_64BIT_RATES,
  105. .fw = {
  106. .dir = AR6004_HW_1_1_FW_DIR,
  107. .fw = AR6004_HW_1_1_FIRMWARE_FILE,
  108. },
  109. .fw_board = AR6004_HW_1_1_BOARD_DATA_FILE,
  110. .fw_default_board = AR6004_HW_1_1_DEFAULT_BOARD_DATA_FILE,
  111. },
  112. {
  113. .id = AR6004_HW_1_2_VERSION,
  114. .name = "ar6004 hw 1.2",
  115. .dataset_patch_addr = 0x436ecc,
  116. .app_load_addr = 0x1234,
  117. .board_ext_data_addr = 0x437000,
  118. .reserved_ram_size = 9216,
  119. .board_addr = 0x435c00,
  120. .refclk_hz = 40000000,
  121. .uarttx_pin = 11,
  122. .flags = ATH6KL_HW_FLAG_64BIT_RATES,
  123. .fw = {
  124. .dir = AR6004_HW_1_2_FW_DIR,
  125. .fw = AR6004_HW_1_2_FIRMWARE_FILE,
  126. },
  127. .fw_board = AR6004_HW_1_2_BOARD_DATA_FILE,
  128. .fw_default_board = AR6004_HW_1_2_DEFAULT_BOARD_DATA_FILE,
  129. },
  130. {
  131. .id = AR6004_HW_1_3_VERSION,
  132. .name = "ar6004 hw 1.3",
  133. .dataset_patch_addr = 0x437860,
  134. .app_load_addr = 0x1234,
  135. .board_ext_data_addr = 0x437000,
  136. .reserved_ram_size = 7168,
  137. .board_addr = 0x436400,
  138. .refclk_hz = 40000000,
  139. .uarttx_pin = 11,
  140. .flags = ATH6KL_HW_FLAG_64BIT_RATES,
  141. .fw = {
  142. .dir = AR6004_HW_1_3_FW_DIR,
  143. .fw = AR6004_HW_1_3_FIRMWARE_FILE,
  144. },
  145. .fw_board = AR6004_HW_1_3_BOARD_DATA_FILE,
  146. .fw_default_board = AR6004_HW_1_3_DEFAULT_BOARD_DATA_FILE,
  147. },
  148. };
  149. /*
  150. * Include definitions here that can be used to tune the WLAN module
  151. * behavior. Different customers can tune the behavior as per their needs,
  152. * here.
  153. */
  154. /*
  155. * This configuration item enable/disable keepalive support.
  156. * Keepalive support: In the absence of any data traffic to AP, null
  157. * frames will be sent to the AP at periodic interval, to keep the association
  158. * active. This configuration item defines the periodic interval.
  159. * Use value of zero to disable keepalive support
  160. * Default: 60 seconds
  161. */
  162. #define WLAN_CONFIG_KEEP_ALIVE_INTERVAL 60
  163. /*
  164. * This configuration item sets the value of disconnect timeout
  165. * Firmware delays sending the disconnec event to the host for this
  166. * timeout after is gets disconnected from the current AP.
  167. * If the firmware successly roams within the disconnect timeout
  168. * it sends a new connect event
  169. */
  170. #define WLAN_CONFIG_DISCONNECT_TIMEOUT 10
  171. #define ATH6KL_DATA_OFFSET 64
  172. struct sk_buff *ath6kl_buf_alloc(int size)
  173. {
  174. struct sk_buff *skb;
  175. u16 reserved;
  176. /* Add chacheline space at front and back of buffer */
  177. reserved = (2 * L1_CACHE_BYTES) + ATH6KL_DATA_OFFSET +
  178. sizeof(struct htc_packet) + ATH6KL_HTC_ALIGN_BYTES;
  179. skb = dev_alloc_skb(size + reserved);
  180. if (skb)
  181. skb_reserve(skb, reserved - L1_CACHE_BYTES);
  182. return skb;
  183. }
  184. void ath6kl_init_profile_info(struct ath6kl_vif *vif)
  185. {
  186. vif->ssid_len = 0;
  187. memset(vif->ssid, 0, sizeof(vif->ssid));
  188. vif->dot11_auth_mode = OPEN_AUTH;
  189. vif->auth_mode = NONE_AUTH;
  190. vif->prwise_crypto = NONE_CRYPT;
  191. vif->prwise_crypto_len = 0;
  192. vif->grp_crypto = NONE_CRYPT;
  193. vif->grp_crypto_len = 0;
  194. memset(vif->wep_key_list, 0, sizeof(vif->wep_key_list));
  195. memset(vif->req_bssid, 0, sizeof(vif->req_bssid));
  196. memset(vif->bssid, 0, sizeof(vif->bssid));
  197. vif->bss_ch = 0;
  198. }
  199. static int ath6kl_set_host_app_area(struct ath6kl *ar)
  200. {
  201. u32 address, data;
  202. struct host_app_area host_app_area;
  203. /* Fetch the address of the host_app_area_s
  204. * instance in the host interest area */
  205. address = ath6kl_get_hi_item_addr(ar, HI_ITEM(hi_app_host_interest));
  206. address = TARG_VTOP(ar->target_type, address);
  207. if (ath6kl_diag_read32(ar, address, &data))
  208. return -EIO;
  209. address = TARG_VTOP(ar->target_type, data);
  210. host_app_area.wmi_protocol_ver = cpu_to_le32(WMI_PROTOCOL_VERSION);
  211. if (ath6kl_diag_write(ar, address, (u8 *) &host_app_area,
  212. sizeof(struct host_app_area)))
  213. return -EIO;
  214. return 0;
  215. }
  216. static inline void set_ac2_ep_map(struct ath6kl *ar,
  217. u8 ac,
  218. enum htc_endpoint_id ep)
  219. {
  220. ar->ac2ep_map[ac] = ep;
  221. ar->ep2ac_map[ep] = ac;
  222. }
  223. /* connect to a service */
  224. static int ath6kl_connectservice(struct ath6kl *ar,
  225. struct htc_service_connect_req *con_req,
  226. char *desc)
  227. {
  228. int status;
  229. struct htc_service_connect_resp response;
  230. memset(&response, 0, sizeof(response));
  231. status = ath6kl_htc_conn_service(ar->htc_target, con_req, &response);
  232. if (status) {
  233. ath6kl_err("failed to connect to %s service status:%d\n",
  234. desc, status);
  235. return status;
  236. }
  237. switch (con_req->svc_id) {
  238. case WMI_CONTROL_SVC:
  239. if (test_bit(WMI_ENABLED, &ar->flag))
  240. ath6kl_wmi_set_control_ep(ar->wmi, response.endpoint);
  241. ar->ctrl_ep = response.endpoint;
  242. break;
  243. case WMI_DATA_BE_SVC:
  244. set_ac2_ep_map(ar, WMM_AC_BE, response.endpoint);
  245. break;
  246. case WMI_DATA_BK_SVC:
  247. set_ac2_ep_map(ar, WMM_AC_BK, response.endpoint);
  248. break;
  249. case WMI_DATA_VI_SVC:
  250. set_ac2_ep_map(ar, WMM_AC_VI, response.endpoint);
  251. break;
  252. case WMI_DATA_VO_SVC:
  253. set_ac2_ep_map(ar, WMM_AC_VO, response.endpoint);
  254. break;
  255. default:
  256. ath6kl_err("service id is not mapped %d\n", con_req->svc_id);
  257. return -EINVAL;
  258. }
  259. return 0;
  260. }
  261. static int ath6kl_init_service_ep(struct ath6kl *ar)
  262. {
  263. struct htc_service_connect_req connect;
  264. memset(&connect, 0, sizeof(connect));
  265. /* these fields are the same for all service endpoints */
  266. connect.ep_cb.tx_comp_multi = ath6kl_tx_complete;
  267. connect.ep_cb.rx = ath6kl_rx;
  268. connect.ep_cb.rx_refill = ath6kl_rx_refill;
  269. connect.ep_cb.tx_full = ath6kl_tx_queue_full;
  270. /*
  271. * Set the max queue depth so that our ath6kl_tx_queue_full handler
  272. * gets called.
  273. */
  274. connect.max_txq_depth = MAX_DEFAULT_SEND_QUEUE_DEPTH;
  275. connect.ep_cb.rx_refill_thresh = ATH6KL_MAX_RX_BUFFERS / 4;
  276. if (!connect.ep_cb.rx_refill_thresh)
  277. connect.ep_cb.rx_refill_thresh++;
  278. /* connect to control service */
  279. connect.svc_id = WMI_CONTROL_SVC;
  280. if (ath6kl_connectservice(ar, &connect, "WMI CONTROL"))
  281. return -EIO;
  282. connect.flags |= HTC_FLGS_TX_BNDL_PAD_EN;
  283. /*
  284. * Limit the HTC message size on the send path, although e can
  285. * receive A-MSDU frames of 4K, we will only send ethernet-sized
  286. * (802.3) frames on the send path.
  287. */
  288. connect.max_rxmsg_sz = WMI_MAX_TX_DATA_FRAME_LENGTH;
  289. /*
  290. * To reduce the amount of committed memory for larger A_MSDU
  291. * frames, use the recv-alloc threshold mechanism for larger
  292. * packets.
  293. */
  294. connect.ep_cb.rx_alloc_thresh = ATH6KL_BUFFER_SIZE;
  295. connect.ep_cb.rx_allocthresh = ath6kl_alloc_amsdu_rxbuf;
  296. /*
  297. * For the remaining data services set the connection flag to
  298. * reduce dribbling, if configured to do so.
  299. */
  300. connect.conn_flags |= HTC_CONN_FLGS_REDUCE_CRED_DRIB;
  301. connect.conn_flags &= ~HTC_CONN_FLGS_THRESH_MASK;
  302. connect.conn_flags |= HTC_CONN_FLGS_THRESH_LVL_HALF;
  303. connect.svc_id = WMI_DATA_BE_SVC;
  304. if (ath6kl_connectservice(ar, &connect, "WMI DATA BE"))
  305. return -EIO;
  306. /* connect to back-ground map this to WMI LOW_PRI */
  307. connect.svc_id = WMI_DATA_BK_SVC;
  308. if (ath6kl_connectservice(ar, &connect, "WMI DATA BK"))
  309. return -EIO;
  310. /* connect to Video service, map this to to HI PRI */
  311. connect.svc_id = WMI_DATA_VI_SVC;
  312. if (ath6kl_connectservice(ar, &connect, "WMI DATA VI"))
  313. return -EIO;
  314. /*
  315. * Connect to VO service, this is currently not mapped to a WMI
  316. * priority stream due to historical reasons. WMI originally
  317. * defined 3 priorities over 3 mailboxes We can change this when
  318. * WMI is reworked so that priorities are not dependent on
  319. * mailboxes.
  320. */
  321. connect.svc_id = WMI_DATA_VO_SVC;
  322. if (ath6kl_connectservice(ar, &connect, "WMI DATA VO"))
  323. return -EIO;
  324. return 0;
  325. }
  326. void ath6kl_init_control_info(struct ath6kl_vif *vif)
  327. {
  328. ath6kl_init_profile_info(vif);
  329. vif->def_txkey_index = 0;
  330. memset(vif->wep_key_list, 0, sizeof(vif->wep_key_list));
  331. vif->ch_hint = 0;
  332. }
  333. /*
  334. * Set HTC/Mbox operational parameters, this can only be called when the
  335. * target is in the BMI phase.
  336. */
  337. static int ath6kl_set_htc_params(struct ath6kl *ar, u32 mbox_isr_yield_val,
  338. u8 htc_ctrl_buf)
  339. {
  340. int status;
  341. u32 blk_size;
  342. blk_size = ar->mbox_info.block_size;
  343. if (htc_ctrl_buf)
  344. blk_size |= ((u32)htc_ctrl_buf) << 16;
  345. /* set the host interest area for the block size */
  346. status = ath6kl_bmi_write_hi32(ar, hi_mbox_io_block_sz, blk_size);
  347. if (status) {
  348. ath6kl_err("bmi_write_memory for IO block size failed\n");
  349. goto out;
  350. }
  351. ath6kl_dbg(ATH6KL_DBG_TRC, "block size set: %d (target addr:0x%X)\n",
  352. blk_size,
  353. ath6kl_get_hi_item_addr(ar, HI_ITEM(hi_mbox_io_block_sz)));
  354. if (mbox_isr_yield_val) {
  355. /* set the host interest area for the mbox ISR yield limit */
  356. status = ath6kl_bmi_write_hi32(ar, hi_mbox_isr_yield_limit,
  357. mbox_isr_yield_val);
  358. if (status) {
  359. ath6kl_err("bmi_write_memory for yield limit failed\n");
  360. goto out;
  361. }
  362. }
  363. out:
  364. return status;
  365. }
  366. static int ath6kl_target_config_wlan_params(struct ath6kl *ar, int idx)
  367. {
  368. int ret;
  369. /*
  370. * Configure the device for rx dot11 header rules. "0,0" are the
  371. * default values. Required if checksum offload is needed. Set
  372. * RxMetaVersion to 2.
  373. */
  374. ret = ath6kl_wmi_set_rx_frame_format_cmd(ar->wmi, idx,
  375. ar->rx_meta_ver, 0, 0);
  376. if (ret) {
  377. ath6kl_err("unable to set the rx frame format: %d\n", ret);
  378. return ret;
  379. }
  380. if (ar->conf_flags & ATH6KL_CONF_IGNORE_PS_FAIL_EVT_IN_SCAN) {
  381. ret = ath6kl_wmi_pmparams_cmd(ar->wmi, idx, 0, 1, 0, 0, 1,
  382. IGNORE_PS_FAIL_DURING_SCAN);
  383. if (ret) {
  384. ath6kl_err("unable to set power save fail event policy: %d\n",
  385. ret);
  386. return ret;
  387. }
  388. }
  389. if (!(ar->conf_flags & ATH6KL_CONF_IGNORE_ERP_BARKER)) {
  390. ret = ath6kl_wmi_set_lpreamble_cmd(ar->wmi, idx, 0,
  391. WMI_FOLLOW_BARKER_IN_ERP);
  392. if (ret) {
  393. ath6kl_err("unable to set barker preamble policy: %d\n",
  394. ret);
  395. return ret;
  396. }
  397. }
  398. ret = ath6kl_wmi_set_keepalive_cmd(ar->wmi, idx,
  399. WLAN_CONFIG_KEEP_ALIVE_INTERVAL);
  400. if (ret) {
  401. ath6kl_err("unable to set keep alive interval: %d\n", ret);
  402. return ret;
  403. }
  404. ret = ath6kl_wmi_disctimeout_cmd(ar->wmi, idx,
  405. WLAN_CONFIG_DISCONNECT_TIMEOUT);
  406. if (ret) {
  407. ath6kl_err("unable to set disconnect timeout: %d\n", ret);
  408. return ret;
  409. }
  410. if (!(ar->conf_flags & ATH6KL_CONF_ENABLE_TX_BURST)) {
  411. ret = ath6kl_wmi_set_wmm_txop(ar->wmi, idx, WMI_TXOP_DISABLED);
  412. if (ret) {
  413. ath6kl_err("unable to set txop bursting: %d\n", ret);
  414. return ret;
  415. }
  416. }
  417. if (ar->p2p && (ar->vif_max == 1 || idx)) {
  418. ret = ath6kl_wmi_info_req_cmd(ar->wmi, idx,
  419. P2P_FLAG_CAPABILITIES_REQ |
  420. P2P_FLAG_MACADDR_REQ |
  421. P2P_FLAG_HMODEL_REQ);
  422. if (ret) {
  423. ath6kl_dbg(ATH6KL_DBG_TRC,
  424. "failed to request P2P capabilities (%d) - assuming P2P not supported\n",
  425. ret);
  426. ar->p2p = false;
  427. }
  428. }
  429. if (ar->p2p && (ar->vif_max == 1 || idx)) {
  430. /* Enable Probe Request reporting for P2P */
  431. ret = ath6kl_wmi_probe_report_req_cmd(ar->wmi, idx, true);
  432. if (ret) {
  433. ath6kl_dbg(ATH6KL_DBG_TRC,
  434. "failed to enable Probe Request reporting (%d)\n",
  435. ret);
  436. }
  437. }
  438. return ret;
  439. }
  440. int ath6kl_configure_target(struct ath6kl *ar)
  441. {
  442. u32 param, ram_reserved_size;
  443. u8 fw_iftype, fw_mode = 0, fw_submode = 0;
  444. int i, status;
  445. param = !!(ar->conf_flags & ATH6KL_CONF_UART_DEBUG);
  446. if (ath6kl_bmi_write_hi32(ar, hi_serial_enable, param)) {
  447. ath6kl_err("bmi_write_memory for uart debug failed\n");
  448. return -EIO;
  449. }
  450. /*
  451. * Note: Even though the firmware interface type is
  452. * chosen as BSS_STA for all three interfaces, can
  453. * be configured to IBSS/AP as long as the fw submode
  454. * remains normal mode (0 - AP, STA and IBSS). But
  455. * due to an target assert in firmware only one interface is
  456. * configured for now.
  457. */
  458. fw_iftype = HI_OPTION_FW_MODE_BSS_STA;
  459. for (i = 0; i < ar->vif_max; i++)
  460. fw_mode |= fw_iftype << (i * HI_OPTION_FW_MODE_BITS);
  461. /*
  462. * Submodes when fw does not support dynamic interface
  463. * switching:
  464. * vif[0] - AP/STA/IBSS
  465. * vif[1] - "P2P dev"/"P2P GO"/"P2P Client"
  466. * vif[2] - "P2P dev"/"P2P GO"/"P2P Client"
  467. * Otherwise, All the interface are initialized to p2p dev.
  468. */
  469. if (test_bit(ATH6KL_FW_CAPABILITY_STA_P2PDEV_DUPLEX,
  470. ar->fw_capabilities)) {
  471. for (i = 0; i < ar->vif_max; i++)
  472. fw_submode |= HI_OPTION_FW_SUBMODE_P2PDEV <<
  473. (i * HI_OPTION_FW_SUBMODE_BITS);
  474. } else {
  475. for (i = 0; i < ar->max_norm_iface; i++)
  476. fw_submode |= HI_OPTION_FW_SUBMODE_NONE <<
  477. (i * HI_OPTION_FW_SUBMODE_BITS);
  478. for (i = ar->max_norm_iface; i < ar->vif_max; i++)
  479. fw_submode |= HI_OPTION_FW_SUBMODE_P2PDEV <<
  480. (i * HI_OPTION_FW_SUBMODE_BITS);
  481. if (ar->p2p && ar->vif_max == 1)
  482. fw_submode = HI_OPTION_FW_SUBMODE_P2PDEV;
  483. }
  484. if (ath6kl_bmi_write_hi32(ar, hi_app_host_interest,
  485. HTC_PROTOCOL_VERSION) != 0) {
  486. ath6kl_err("bmi_write_memory for htc version failed\n");
  487. return -EIO;
  488. }
  489. /* set the firmware mode to STA/IBSS/AP */
  490. param = 0;
  491. if (ath6kl_bmi_read_hi32(ar, hi_option_flag, &param) != 0) {
  492. ath6kl_err("bmi_read_memory for setting fwmode failed\n");
  493. return -EIO;
  494. }
  495. param |= (ar->vif_max << HI_OPTION_NUM_DEV_SHIFT);
  496. param |= fw_mode << HI_OPTION_FW_MODE_SHIFT;
  497. param |= fw_submode << HI_OPTION_FW_SUBMODE_SHIFT;
  498. param |= (0 << HI_OPTION_MAC_ADDR_METHOD_SHIFT);
  499. param |= (0 << HI_OPTION_FW_BRIDGE_SHIFT);
  500. if (ath6kl_bmi_write_hi32(ar, hi_option_flag, param) != 0) {
  501. ath6kl_err("bmi_write_memory for setting fwmode failed\n");
  502. return -EIO;
  503. }
  504. ath6kl_dbg(ATH6KL_DBG_TRC, "firmware mode set\n");
  505. /*
  506. * Hardcode the address use for the extended board data
  507. * Ideally this should be pre-allocate by the OS at boot time
  508. * But since it is a new feature and board data is loaded
  509. * at init time, we have to workaround this from host.
  510. * It is difficult to patch the firmware boot code,
  511. * but possible in theory.
  512. */
  513. if (ar->target_type == TARGET_TYPE_AR6003) {
  514. param = ar->hw.board_ext_data_addr;
  515. ram_reserved_size = ar->hw.reserved_ram_size;
  516. if (ath6kl_bmi_write_hi32(ar, hi_board_ext_data, param) != 0) {
  517. ath6kl_err("bmi_write_memory for hi_board_ext_data failed\n");
  518. return -EIO;
  519. }
  520. if (ath6kl_bmi_write_hi32(ar, hi_end_ram_reserve_sz,
  521. ram_reserved_size) != 0) {
  522. ath6kl_err("bmi_write_memory for hi_end_ram_reserve_sz failed\n");
  523. return -EIO;
  524. }
  525. }
  526. /* set the block size for the target */
  527. if (ath6kl_set_htc_params(ar, MBOX_YIELD_LIMIT, 0))
  528. /* use default number of control buffers */
  529. return -EIO;
  530. /* Configure GPIO AR600x UART */
  531. status = ath6kl_bmi_write_hi32(ar, hi_dbg_uart_txpin,
  532. ar->hw.uarttx_pin);
  533. if (status)
  534. return status;
  535. /* Configure target refclk_hz */
  536. status = ath6kl_bmi_write_hi32(ar, hi_refclk_hz, ar->hw.refclk_hz);
  537. if (status)
  538. return status;
  539. return 0;
  540. }
  541. /* firmware upload */
  542. static int ath6kl_get_fw(struct ath6kl *ar, const char *filename,
  543. u8 **fw, size_t *fw_len)
  544. {
  545. const struct firmware *fw_entry;
  546. int ret;
  547. ret = request_firmware(&fw_entry, filename, ar->dev);
  548. if (ret)
  549. return ret;
  550. *fw_len = fw_entry->size;
  551. *fw = kmemdup(fw_entry->data, fw_entry->size, GFP_KERNEL);
  552. if (*fw == NULL)
  553. ret = -ENOMEM;
  554. release_firmware(fw_entry);
  555. return ret;
  556. }
  557. #ifdef CONFIG_OF
  558. /*
  559. * Check the device tree for a board-id and use it to construct
  560. * the pathname to the firmware file. Used (for now) to find a
  561. * fallback to the "bdata.bin" file--typically a symlink to the
  562. * appropriate board-specific file.
  563. */
  564. static bool check_device_tree(struct ath6kl *ar)
  565. {
  566. static const char *board_id_prop = "atheros,board-id";
  567. struct device_node *node;
  568. char board_filename[64];
  569. const char *board_id;
  570. int ret;
  571. for_each_compatible_node(node, NULL, "atheros,ath6kl") {
  572. board_id = of_get_property(node, board_id_prop, NULL);
  573. if (board_id == NULL) {
  574. ath6kl_warn("No \"%s\" property on %s node.\n",
  575. board_id_prop, node->name);
  576. continue;
  577. }
  578. snprintf(board_filename, sizeof(board_filename),
  579. "%s/bdata.%s.bin", ar->hw.fw.dir, board_id);
  580. ret = ath6kl_get_fw(ar, board_filename, &ar->fw_board,
  581. &ar->fw_board_len);
  582. if (ret) {
  583. ath6kl_err("Failed to get DT board file %s: %d\n",
  584. board_filename, ret);
  585. continue;
  586. }
  587. return true;
  588. }
  589. return false;
  590. }
  591. #else
  592. static bool check_device_tree(struct ath6kl *ar)
  593. {
  594. return false;
  595. }
  596. #endif /* CONFIG_OF */
  597. static int ath6kl_fetch_board_file(struct ath6kl *ar)
  598. {
  599. const char *filename;
  600. int ret;
  601. if (ar->fw_board != NULL)
  602. return 0;
  603. if (WARN_ON(ar->hw.fw_board == NULL))
  604. return -EINVAL;
  605. filename = ar->hw.fw_board;
  606. ret = ath6kl_get_fw(ar, filename, &ar->fw_board,
  607. &ar->fw_board_len);
  608. if (ret == 0) {
  609. /* managed to get proper board file */
  610. return 0;
  611. }
  612. if (check_device_tree(ar)) {
  613. /* got board file from device tree */
  614. return 0;
  615. }
  616. /* there was no proper board file, try to use default instead */
  617. ath6kl_warn("Failed to get board file %s (%d), trying to find default board file.\n",
  618. filename, ret);
  619. filename = ar->hw.fw_default_board;
  620. ret = ath6kl_get_fw(ar, filename, &ar->fw_board,
  621. &ar->fw_board_len);
  622. if (ret) {
  623. ath6kl_err("Failed to get default board file %s: %d\n",
  624. filename, ret);
  625. return ret;
  626. }
  627. ath6kl_warn("WARNING! No proper board file was not found, instead using a default board file.\n");
  628. ath6kl_warn("Most likely your hardware won't work as specified. Install correct board file!\n");
  629. return 0;
  630. }
  631. static int ath6kl_fetch_otp_file(struct ath6kl *ar)
  632. {
  633. char filename[100];
  634. int ret;
  635. if (ar->fw_otp != NULL)
  636. return 0;
  637. if (ar->hw.fw.otp == NULL) {
  638. ath6kl_dbg(ATH6KL_DBG_BOOT,
  639. "no OTP file configured for this hw\n");
  640. return 0;
  641. }
  642. snprintf(filename, sizeof(filename), "%s/%s",
  643. ar->hw.fw.dir, ar->hw.fw.otp);
  644. ret = ath6kl_get_fw(ar, filename, &ar->fw_otp,
  645. &ar->fw_otp_len);
  646. if (ret) {
  647. ath6kl_err("Failed to get OTP file %s: %d\n",
  648. filename, ret);
  649. return ret;
  650. }
  651. return 0;
  652. }
  653. static int ath6kl_fetch_testmode_file(struct ath6kl *ar)
  654. {
  655. char filename[100];
  656. int ret;
  657. if (ar->testmode == 0)
  658. return 0;
  659. ath6kl_dbg(ATH6KL_DBG_BOOT, "testmode %d\n", ar->testmode);
  660. if (ar->testmode == 2) {
  661. if (ar->hw.fw.utf == NULL) {
  662. ath6kl_warn("testmode 2 not supported\n");
  663. return -EOPNOTSUPP;
  664. }
  665. snprintf(filename, sizeof(filename), "%s/%s",
  666. ar->hw.fw.dir, ar->hw.fw.utf);
  667. } else {
  668. if (ar->hw.fw.tcmd == NULL) {
  669. ath6kl_warn("testmode 1 not supported\n");
  670. return -EOPNOTSUPP;
  671. }
  672. snprintf(filename, sizeof(filename), "%s/%s",
  673. ar->hw.fw.dir, ar->hw.fw.tcmd);
  674. }
  675. set_bit(TESTMODE, &ar->flag);
  676. ret = ath6kl_get_fw(ar, filename, &ar->fw, &ar->fw_len);
  677. if (ret) {
  678. ath6kl_err("Failed to get testmode %d firmware file %s: %d\n",
  679. ar->testmode, filename, ret);
  680. return ret;
  681. }
  682. return 0;
  683. }
  684. static int ath6kl_fetch_fw_file(struct ath6kl *ar)
  685. {
  686. char filename[100];
  687. int ret;
  688. if (ar->fw != NULL)
  689. return 0;
  690. /* FIXME: remove WARN_ON() as we won't support FW API 1 for long */
  691. if (WARN_ON(ar->hw.fw.fw == NULL))
  692. return -EINVAL;
  693. snprintf(filename, sizeof(filename), "%s/%s",
  694. ar->hw.fw.dir, ar->hw.fw.fw);
  695. ret = ath6kl_get_fw(ar, filename, &ar->fw, &ar->fw_len);
  696. if (ret) {
  697. ath6kl_err("Failed to get firmware file %s: %d\n",
  698. filename, ret);
  699. return ret;
  700. }
  701. return 0;
  702. }
  703. static int ath6kl_fetch_patch_file(struct ath6kl *ar)
  704. {
  705. char filename[100];
  706. int ret;
  707. if (ar->fw_patch != NULL)
  708. return 0;
  709. if (ar->hw.fw.patch == NULL)
  710. return 0;
  711. snprintf(filename, sizeof(filename), "%s/%s",
  712. ar->hw.fw.dir, ar->hw.fw.patch);
  713. ret = ath6kl_get_fw(ar, filename, &ar->fw_patch,
  714. &ar->fw_patch_len);
  715. if (ret) {
  716. ath6kl_err("Failed to get patch file %s: %d\n",
  717. filename, ret);
  718. return ret;
  719. }
  720. return 0;
  721. }
  722. static int ath6kl_fetch_testscript_file(struct ath6kl *ar)
  723. {
  724. char filename[100];
  725. int ret;
  726. if (ar->testmode != 2)
  727. return 0;
  728. if (ar->fw_testscript != NULL)
  729. return 0;
  730. if (ar->hw.fw.testscript == NULL)
  731. return 0;
  732. snprintf(filename, sizeof(filename), "%s/%s",
  733. ar->hw.fw.dir, ar->hw.fw.testscript);
  734. ret = ath6kl_get_fw(ar, filename, &ar->fw_testscript,
  735. &ar->fw_testscript_len);
  736. if (ret) {
  737. ath6kl_err("Failed to get testscript file %s: %d\n",
  738. filename, ret);
  739. return ret;
  740. }
  741. return 0;
  742. }
  743. static int ath6kl_fetch_fw_api1(struct ath6kl *ar)
  744. {
  745. int ret;
  746. ret = ath6kl_fetch_otp_file(ar);
  747. if (ret)
  748. return ret;
  749. ret = ath6kl_fetch_fw_file(ar);
  750. if (ret)
  751. return ret;
  752. ret = ath6kl_fetch_patch_file(ar);
  753. if (ret)
  754. return ret;
  755. ret = ath6kl_fetch_testscript_file(ar);
  756. if (ret)
  757. return ret;
  758. return 0;
  759. }
  760. static int ath6kl_fetch_fw_apin(struct ath6kl *ar, const char *name)
  761. {
  762. size_t magic_len, len, ie_len;
  763. const struct firmware *fw;
  764. struct ath6kl_fw_ie *hdr;
  765. char filename[100];
  766. const u8 *data;
  767. int ret, ie_id, i, index, bit;
  768. __le32 *val;
  769. snprintf(filename, sizeof(filename), "%s/%s", ar->hw.fw.dir, name);
  770. ret = request_firmware(&fw, filename, ar->dev);
  771. if (ret)
  772. return ret;
  773. data = fw->data;
  774. len = fw->size;
  775. /* magic also includes the null byte, check that as well */
  776. magic_len = strlen(ATH6KL_FIRMWARE_MAGIC) + 1;
  777. if (len < magic_len) {
  778. ret = -EINVAL;
  779. goto out;
  780. }
  781. if (memcmp(data, ATH6KL_FIRMWARE_MAGIC, magic_len) != 0) {
  782. ret = -EINVAL;
  783. goto out;
  784. }
  785. len -= magic_len;
  786. data += magic_len;
  787. /* loop elements */
  788. while (len > sizeof(struct ath6kl_fw_ie)) {
  789. /* hdr is unaligned! */
  790. hdr = (struct ath6kl_fw_ie *) data;
  791. ie_id = le32_to_cpup(&hdr->id);
  792. ie_len = le32_to_cpup(&hdr->len);
  793. len -= sizeof(*hdr);
  794. data += sizeof(*hdr);
  795. if (len < ie_len) {
  796. ret = -EINVAL;
  797. goto out;
  798. }
  799. switch (ie_id) {
  800. case ATH6KL_FW_IE_FW_VERSION:
  801. strlcpy(ar->wiphy->fw_version, data,
  802. sizeof(ar->wiphy->fw_version));
  803. ath6kl_dbg(ATH6KL_DBG_BOOT,
  804. "found fw version %s\n",
  805. ar->wiphy->fw_version);
  806. break;
  807. case ATH6KL_FW_IE_OTP_IMAGE:
  808. ath6kl_dbg(ATH6KL_DBG_BOOT, "found otp image ie (%zd B)\n",
  809. ie_len);
  810. ar->fw_otp = kmemdup(data, ie_len, GFP_KERNEL);
  811. if (ar->fw_otp == NULL) {
  812. ret = -ENOMEM;
  813. goto out;
  814. }
  815. ar->fw_otp_len = ie_len;
  816. break;
  817. case ATH6KL_FW_IE_FW_IMAGE:
  818. ath6kl_dbg(ATH6KL_DBG_BOOT, "found fw image ie (%zd B)\n",
  819. ie_len);
  820. /* in testmode we already might have a fw file */
  821. if (ar->fw != NULL)
  822. break;
  823. ar->fw = vmalloc(ie_len);
  824. if (ar->fw == NULL) {
  825. ret = -ENOMEM;
  826. goto out;
  827. }
  828. memcpy(ar->fw, data, ie_len);
  829. ar->fw_len = ie_len;
  830. break;
  831. case ATH6KL_FW_IE_PATCH_IMAGE:
  832. ath6kl_dbg(ATH6KL_DBG_BOOT, "found patch image ie (%zd B)\n",
  833. ie_len);
  834. ar->fw_patch = kmemdup(data, ie_len, GFP_KERNEL);
  835. if (ar->fw_patch == NULL) {
  836. ret = -ENOMEM;
  837. goto out;
  838. }
  839. ar->fw_patch_len = ie_len;
  840. break;
  841. case ATH6KL_FW_IE_RESERVED_RAM_SIZE:
  842. val = (__le32 *) data;
  843. ar->hw.reserved_ram_size = le32_to_cpup(val);
  844. ath6kl_dbg(ATH6KL_DBG_BOOT,
  845. "found reserved ram size ie 0x%d\n",
  846. ar->hw.reserved_ram_size);
  847. break;
  848. case ATH6KL_FW_IE_CAPABILITIES:
  849. ath6kl_dbg(ATH6KL_DBG_BOOT,
  850. "found firmware capabilities ie (%zd B)\n",
  851. ie_len);
  852. for (i = 0; i < ATH6KL_FW_CAPABILITY_MAX; i++) {
  853. index = i / 8;
  854. bit = i % 8;
  855. if (index == ie_len)
  856. break;
  857. if (data[index] & (1 << bit))
  858. __set_bit(i, ar->fw_capabilities);
  859. }
  860. ath6kl_dbg_dump(ATH6KL_DBG_BOOT, "capabilities", "",
  861. ar->fw_capabilities,
  862. sizeof(ar->fw_capabilities));
  863. break;
  864. case ATH6KL_FW_IE_PATCH_ADDR:
  865. if (ie_len != sizeof(*val))
  866. break;
  867. val = (__le32 *) data;
  868. ar->hw.dataset_patch_addr = le32_to_cpup(val);
  869. ath6kl_dbg(ATH6KL_DBG_BOOT,
  870. "found patch address ie 0x%x\n",
  871. ar->hw.dataset_patch_addr);
  872. break;
  873. case ATH6KL_FW_IE_BOARD_ADDR:
  874. if (ie_len != sizeof(*val))
  875. break;
  876. val = (__le32 *) data;
  877. ar->hw.board_addr = le32_to_cpup(val);
  878. ath6kl_dbg(ATH6KL_DBG_BOOT,
  879. "found board address ie 0x%x\n",
  880. ar->hw.board_addr);
  881. break;
  882. case ATH6KL_FW_IE_VIF_MAX:
  883. if (ie_len != sizeof(*val))
  884. break;
  885. val = (__le32 *) data;
  886. ar->vif_max = min_t(unsigned int, le32_to_cpup(val),
  887. ATH6KL_VIF_MAX);
  888. if (ar->vif_max > 1 && !ar->p2p)
  889. ar->max_norm_iface = 2;
  890. ath6kl_dbg(ATH6KL_DBG_BOOT,
  891. "found vif max ie %d\n", ar->vif_max);
  892. break;
  893. default:
  894. ath6kl_dbg(ATH6KL_DBG_BOOT, "Unknown fw ie: %u\n",
  895. le32_to_cpup(&hdr->id));
  896. break;
  897. }
  898. len -= ie_len;
  899. data += ie_len;
  900. };
  901. ret = 0;
  902. out:
  903. release_firmware(fw);
  904. return ret;
  905. }
  906. int ath6kl_init_fetch_firmwares(struct ath6kl *ar)
  907. {
  908. int ret;
  909. ret = ath6kl_fetch_board_file(ar);
  910. if (ret)
  911. return ret;
  912. ret = ath6kl_fetch_testmode_file(ar);
  913. if (ret)
  914. return ret;
  915. ret = ath6kl_fetch_fw_apin(ar, ATH6KL_FW_API3_FILE);
  916. if (ret == 0) {
  917. ar->fw_api = 3;
  918. goto out;
  919. }
  920. ret = ath6kl_fetch_fw_apin(ar, ATH6KL_FW_API2_FILE);
  921. if (ret == 0) {
  922. ar->fw_api = 2;
  923. goto out;
  924. }
  925. ret = ath6kl_fetch_fw_api1(ar);
  926. if (ret)
  927. return ret;
  928. ar->fw_api = 1;
  929. out:
  930. ath6kl_dbg(ATH6KL_DBG_BOOT, "using fw api %d\n", ar->fw_api);
  931. return 0;
  932. }
  933. static int ath6kl_upload_board_file(struct ath6kl *ar)
  934. {
  935. u32 board_address, board_ext_address, param;
  936. u32 board_data_size, board_ext_data_size;
  937. int ret;
  938. if (WARN_ON(ar->fw_board == NULL))
  939. return -ENOENT;
  940. /*
  941. * Determine where in Target RAM to write Board Data.
  942. * For AR6004, host determine Target RAM address for
  943. * writing board data.
  944. */
  945. if (ar->hw.board_addr != 0) {
  946. board_address = ar->hw.board_addr;
  947. ath6kl_bmi_write_hi32(ar, hi_board_data,
  948. board_address);
  949. } else {
  950. ath6kl_bmi_read_hi32(ar, hi_board_data, &board_address);
  951. }
  952. /* determine where in target ram to write extended board data */
  953. ath6kl_bmi_read_hi32(ar, hi_board_ext_data, &board_ext_address);
  954. if (ar->target_type == TARGET_TYPE_AR6003 &&
  955. board_ext_address == 0) {
  956. ath6kl_err("Failed to get board file target address.\n");
  957. return -EINVAL;
  958. }
  959. switch (ar->target_type) {
  960. case TARGET_TYPE_AR6003:
  961. board_data_size = AR6003_BOARD_DATA_SZ;
  962. board_ext_data_size = AR6003_BOARD_EXT_DATA_SZ;
  963. if (ar->fw_board_len > (board_data_size + board_ext_data_size))
  964. board_ext_data_size = AR6003_BOARD_EXT_DATA_SZ_V2;
  965. break;
  966. case TARGET_TYPE_AR6004:
  967. board_data_size = AR6004_BOARD_DATA_SZ;
  968. board_ext_data_size = AR6004_BOARD_EXT_DATA_SZ;
  969. break;
  970. default:
  971. WARN_ON(1);
  972. return -EINVAL;
  973. break;
  974. }
  975. if (board_ext_address &&
  976. ar->fw_board_len == (board_data_size + board_ext_data_size)) {
  977. /* write extended board data */
  978. ath6kl_dbg(ATH6KL_DBG_BOOT,
  979. "writing extended board data to 0x%x (%d B)\n",
  980. board_ext_address, board_ext_data_size);
  981. ret = ath6kl_bmi_write(ar, board_ext_address,
  982. ar->fw_board + board_data_size,
  983. board_ext_data_size);
  984. if (ret) {
  985. ath6kl_err("Failed to write extended board data: %d\n",
  986. ret);
  987. return ret;
  988. }
  989. /* record that extended board data is initialized */
  990. param = (board_ext_data_size << 16) | 1;
  991. ath6kl_bmi_write_hi32(ar, hi_board_ext_data_config, param);
  992. }
  993. if (ar->fw_board_len < board_data_size) {
  994. ath6kl_err("Too small board file: %zu\n", ar->fw_board_len);
  995. ret = -EINVAL;
  996. return ret;
  997. }
  998. ath6kl_dbg(ATH6KL_DBG_BOOT, "writing board file to 0x%x (%d B)\n",
  999. board_address, board_data_size);
  1000. ret = ath6kl_bmi_write(ar, board_address, ar->fw_board,
  1001. board_data_size);
  1002. if (ret) {
  1003. ath6kl_err("Board file bmi write failed: %d\n", ret);
  1004. return ret;
  1005. }
  1006. /* record the fact that Board Data IS initialized */
  1007. ath6kl_bmi_write_hi32(ar, hi_board_data_initialized, 1);
  1008. return ret;
  1009. }
  1010. static int ath6kl_upload_otp(struct ath6kl *ar)
  1011. {
  1012. u32 address, param;
  1013. bool from_hw = false;
  1014. int ret;
  1015. if (ar->fw_otp == NULL)
  1016. return 0;
  1017. address = ar->hw.app_load_addr;
  1018. ath6kl_dbg(ATH6KL_DBG_BOOT, "writing otp to 0x%x (%zd B)\n", address,
  1019. ar->fw_otp_len);
  1020. ret = ath6kl_bmi_fast_download(ar, address, ar->fw_otp,
  1021. ar->fw_otp_len);
  1022. if (ret) {
  1023. ath6kl_err("Failed to upload OTP file: %d\n", ret);
  1024. return ret;
  1025. }
  1026. /* read firmware start address */
  1027. ret = ath6kl_bmi_read_hi32(ar, hi_app_start, &address);
  1028. if (ret) {
  1029. ath6kl_err("Failed to read hi_app_start: %d\n", ret);
  1030. return ret;
  1031. }
  1032. if (ar->hw.app_start_override_addr == 0) {
  1033. ar->hw.app_start_override_addr = address;
  1034. from_hw = true;
  1035. }
  1036. ath6kl_dbg(ATH6KL_DBG_BOOT, "app_start_override_addr%s 0x%x\n",
  1037. from_hw ? " (from hw)" : "",
  1038. ar->hw.app_start_override_addr);
  1039. /* execute the OTP code */
  1040. ath6kl_dbg(ATH6KL_DBG_BOOT, "executing OTP at 0x%x\n",
  1041. ar->hw.app_start_override_addr);
  1042. param = 0;
  1043. ath6kl_bmi_execute(ar, ar->hw.app_start_override_addr, &param);
  1044. return ret;
  1045. }
  1046. static int ath6kl_upload_firmware(struct ath6kl *ar)
  1047. {
  1048. u32 address;
  1049. int ret;
  1050. if (WARN_ON(ar->fw == NULL))
  1051. return 0;
  1052. address = ar->hw.app_load_addr;
  1053. ath6kl_dbg(ATH6KL_DBG_BOOT, "writing firmware to 0x%x (%zd B)\n",
  1054. address, ar->fw_len);
  1055. ret = ath6kl_bmi_fast_download(ar, address, ar->fw, ar->fw_len);
  1056. if (ret) {
  1057. ath6kl_err("Failed to write firmware: %d\n", ret);
  1058. return ret;
  1059. }
  1060. /*
  1061. * Set starting address for firmware
  1062. * Don't need to setup app_start override addr on AR6004
  1063. */
  1064. if (ar->target_type != TARGET_TYPE_AR6004) {
  1065. address = ar->hw.app_start_override_addr;
  1066. ath6kl_bmi_set_app_start(ar, address);
  1067. }
  1068. return ret;
  1069. }
  1070. static int ath6kl_upload_patch(struct ath6kl *ar)
  1071. {
  1072. u32 address;
  1073. int ret;
  1074. if (ar->fw_patch == NULL)
  1075. return 0;
  1076. address = ar->hw.dataset_patch_addr;
  1077. ath6kl_dbg(ATH6KL_DBG_BOOT, "writing patch to 0x%x (%zd B)\n",
  1078. address, ar->fw_patch_len);
  1079. ret = ath6kl_bmi_write(ar, address, ar->fw_patch, ar->fw_patch_len);
  1080. if (ret) {
  1081. ath6kl_err("Failed to write patch file: %d\n", ret);
  1082. return ret;
  1083. }
  1084. ath6kl_bmi_write_hi32(ar, hi_dset_list_head, address);
  1085. return 0;
  1086. }
  1087. static int ath6kl_upload_testscript(struct ath6kl *ar)
  1088. {
  1089. u32 address;
  1090. int ret;
  1091. if (ar->testmode != 2)
  1092. return 0;
  1093. if (ar->fw_testscript == NULL)
  1094. return 0;
  1095. address = ar->hw.testscript_addr;
  1096. ath6kl_dbg(ATH6KL_DBG_BOOT, "writing testscript to 0x%x (%zd B)\n",
  1097. address, ar->fw_testscript_len);
  1098. ret = ath6kl_bmi_write(ar, address, ar->fw_testscript,
  1099. ar->fw_testscript_len);
  1100. if (ret) {
  1101. ath6kl_err("Failed to write testscript file: %d\n", ret);
  1102. return ret;
  1103. }
  1104. ath6kl_bmi_write_hi32(ar, hi_ota_testscript, address);
  1105. ath6kl_bmi_write_hi32(ar, hi_end_ram_reserve_sz, 4096);
  1106. ath6kl_bmi_write_hi32(ar, hi_test_apps_related, 1);
  1107. return 0;
  1108. }
  1109. static int ath6kl_init_upload(struct ath6kl *ar)
  1110. {
  1111. u32 param, options, sleep, address;
  1112. int status = 0;
  1113. if (ar->target_type != TARGET_TYPE_AR6003 &&
  1114. ar->target_type != TARGET_TYPE_AR6004)
  1115. return -EINVAL;
  1116. /* temporarily disable system sleep */
  1117. address = MBOX_BASE_ADDRESS + LOCAL_SCRATCH_ADDRESS;
  1118. status = ath6kl_bmi_reg_read(ar, address, &param);
  1119. if (status)
  1120. return status;
  1121. options = param;
  1122. param |= ATH6KL_OPTION_SLEEP_DISABLE;
  1123. status = ath6kl_bmi_reg_write(ar, address, param);
  1124. if (status)
  1125. return status;
  1126. address = RTC_BASE_ADDRESS + SYSTEM_SLEEP_ADDRESS;
  1127. status = ath6kl_bmi_reg_read(ar, address, &param);
  1128. if (status)
  1129. return status;
  1130. sleep = param;
  1131. param |= SM(SYSTEM_SLEEP_DISABLE, 1);
  1132. status = ath6kl_bmi_reg_write(ar, address, param);
  1133. if (status)
  1134. return status;
  1135. ath6kl_dbg(ATH6KL_DBG_TRC, "old options: %d, old sleep: %d\n",
  1136. options, sleep);
  1137. /* program analog PLL register */
  1138. /* no need to control 40/44MHz clock on AR6004 */
  1139. if (ar->target_type != TARGET_TYPE_AR6004) {
  1140. status = ath6kl_bmi_reg_write(ar, ATH6KL_ANALOG_PLL_REGISTER,
  1141. 0xF9104001);
  1142. if (status)
  1143. return status;
  1144. /* Run at 80/88MHz by default */
  1145. param = SM(CPU_CLOCK_STANDARD, 1);
  1146. address = RTC_BASE_ADDRESS + CPU_CLOCK_ADDRESS;
  1147. status = ath6kl_bmi_reg_write(ar, address, param);
  1148. if (status)
  1149. return status;
  1150. }
  1151. param = 0;
  1152. address = RTC_BASE_ADDRESS + LPO_CAL_ADDRESS;
  1153. param = SM(LPO_CAL_ENABLE, 1);
  1154. status = ath6kl_bmi_reg_write(ar, address, param);
  1155. if (status)
  1156. return status;
  1157. /* WAR to avoid SDIO CRC err */
  1158. if (ar->version.target_ver == AR6003_HW_2_0_VERSION ||
  1159. ar->version.target_ver == AR6003_HW_2_1_1_VERSION) {
  1160. ath6kl_err("temporary war to avoid sdio crc error\n");
  1161. param = 0x28;
  1162. address = GPIO_BASE_ADDRESS + GPIO_PIN9_ADDRESS;
  1163. status = ath6kl_bmi_reg_write(ar, address, param);
  1164. if (status)
  1165. return status;
  1166. param = 0x20;
  1167. address = GPIO_BASE_ADDRESS + GPIO_PIN10_ADDRESS;
  1168. status = ath6kl_bmi_reg_write(ar, address, param);
  1169. if (status)
  1170. return status;
  1171. address = GPIO_BASE_ADDRESS + GPIO_PIN11_ADDRESS;
  1172. status = ath6kl_bmi_reg_write(ar, address, param);
  1173. if (status)
  1174. return status;
  1175. address = GPIO_BASE_ADDRESS + GPIO_PIN12_ADDRESS;
  1176. status = ath6kl_bmi_reg_write(ar, address, param);
  1177. if (status)
  1178. return status;
  1179. address = GPIO_BASE_ADDRESS + GPIO_PIN13_ADDRESS;
  1180. status = ath6kl_bmi_reg_write(ar, address, param);
  1181. if (status)
  1182. return status;
  1183. }
  1184. /* write EEPROM data to Target RAM */
  1185. status = ath6kl_upload_board_file(ar);
  1186. if (status)
  1187. return status;
  1188. /* transfer One time Programmable data */
  1189. status = ath6kl_upload_otp(ar);
  1190. if (status)
  1191. return status;
  1192. /* Download Target firmware */
  1193. status = ath6kl_upload_firmware(ar);
  1194. if (status)
  1195. return status;
  1196. status = ath6kl_upload_patch(ar);
  1197. if (status)
  1198. return status;
  1199. /* Download the test script */
  1200. status = ath6kl_upload_testscript(ar);
  1201. if (status)
  1202. return status;
  1203. /* Restore system sleep */
  1204. address = RTC_BASE_ADDRESS + SYSTEM_SLEEP_ADDRESS;
  1205. status = ath6kl_bmi_reg_write(ar, address, sleep);
  1206. if (status)
  1207. return status;
  1208. address = MBOX_BASE_ADDRESS + LOCAL_SCRATCH_ADDRESS;
  1209. param = options | 0x20;
  1210. status = ath6kl_bmi_reg_write(ar, address, param);
  1211. if (status)
  1212. return status;
  1213. return status;
  1214. }
  1215. int ath6kl_init_hw_params(struct ath6kl *ar)
  1216. {
  1217. const struct ath6kl_hw *uninitialized_var(hw);
  1218. int i;
  1219. for (i = 0; i < ARRAY_SIZE(hw_list); i++) {
  1220. hw = &hw_list[i];
  1221. if (hw->id == ar->version.target_ver)
  1222. break;
  1223. }
  1224. if (i == ARRAY_SIZE(hw_list)) {
  1225. ath6kl_err("Unsupported hardware version: 0x%x\n",
  1226. ar->version.target_ver);
  1227. return -EINVAL;
  1228. }
  1229. ar->hw = *hw;
  1230. ath6kl_dbg(ATH6KL_DBG_BOOT,
  1231. "target_ver 0x%x target_type 0x%x dataset_patch 0x%x app_load_addr 0x%x\n",
  1232. ar->version.target_ver, ar->target_type,
  1233. ar->hw.dataset_patch_addr, ar->hw.app_load_addr);
  1234. ath6kl_dbg(ATH6KL_DBG_BOOT,
  1235. "app_start_override_addr 0x%x board_ext_data_addr 0x%x reserved_ram_size 0x%x",
  1236. ar->hw.app_start_override_addr, ar->hw.board_ext_data_addr,
  1237. ar->hw.reserved_ram_size);
  1238. ath6kl_dbg(ATH6KL_DBG_BOOT,
  1239. "refclk_hz %d uarttx_pin %d",
  1240. ar->hw.refclk_hz, ar->hw.uarttx_pin);
  1241. return 0;
  1242. }
  1243. static const char *ath6kl_init_get_hif_name(enum ath6kl_hif_type type)
  1244. {
  1245. switch (type) {
  1246. case ATH6KL_HIF_TYPE_SDIO:
  1247. return "sdio";
  1248. case ATH6KL_HIF_TYPE_USB:
  1249. return "usb";
  1250. }
  1251. return NULL;
  1252. }
  1253. int ath6kl_init_hw_start(struct ath6kl *ar)
  1254. {
  1255. long timeleft;
  1256. int ret, i;
  1257. ath6kl_dbg(ATH6KL_DBG_BOOT, "hw start\n");
  1258. ret = ath6kl_hif_power_on(ar);
  1259. if (ret)
  1260. return ret;
  1261. ret = ath6kl_configure_target(ar);
  1262. if (ret)
  1263. goto err_power_off;
  1264. ret = ath6kl_init_upload(ar);
  1265. if (ret)
  1266. goto err_power_off;
  1267. /* Do we need to finish the BMI phase */
  1268. /* FIXME: return error from ath6kl_bmi_done() */
  1269. if (ath6kl_bmi_done(ar)) {
  1270. ret = -EIO;
  1271. goto err_power_off;
  1272. }
  1273. /*
  1274. * The reason we have to wait for the target here is that the
  1275. * driver layer has to init BMI in order to set the host block
  1276. * size.
  1277. */
  1278. if (ath6kl_htc_wait_target(ar->htc_target)) {
  1279. ret = -EIO;
  1280. goto err_power_off;
  1281. }
  1282. if (ath6kl_init_service_ep(ar)) {
  1283. ret = -EIO;
  1284. goto err_cleanup_scatter;
  1285. }
  1286. /* setup credit distribution */
  1287. ath6kl_htc_credit_setup(ar->htc_target, &ar->credit_state_info);
  1288. /* start HTC */
  1289. ret = ath6kl_htc_start(ar->htc_target);
  1290. if (ret) {
  1291. /* FIXME: call this */
  1292. ath6kl_cookie_cleanup(ar);
  1293. goto err_cleanup_scatter;
  1294. }
  1295. /* Wait for Wmi event to be ready */
  1296. timeleft = wait_event_interruptible_timeout(ar->event_wq,
  1297. test_bit(WMI_READY,
  1298. &ar->flag),
  1299. WMI_TIMEOUT);
  1300. ath6kl_dbg(ATH6KL_DBG_BOOT, "firmware booted\n");
  1301. if (test_and_clear_bit(FIRST_BOOT, &ar->flag)) {
  1302. ath6kl_info("%s %s fw %s api %d%s\n",
  1303. ar->hw.name,
  1304. ath6kl_init_get_hif_name(ar->hif_type),
  1305. ar->wiphy->fw_version,
  1306. ar->fw_api,
  1307. test_bit(TESTMODE, &ar->flag) ? " testmode" : "");
  1308. }
  1309. if (ar->version.abi_ver != ATH6KL_ABI_VERSION) {
  1310. ath6kl_err("abi version mismatch: host(0x%x), target(0x%x)\n",
  1311. ATH6KL_ABI_VERSION, ar->version.abi_ver);
  1312. ret = -EIO;
  1313. goto err_htc_stop;
  1314. }
  1315. if (!timeleft || signal_pending(current)) {
  1316. ath6kl_err("wmi is not ready or wait was interrupted\n");
  1317. ret = -EIO;
  1318. goto err_htc_stop;
  1319. }
  1320. ath6kl_dbg(ATH6KL_DBG_TRC, "%s: wmi is ready\n", __func__);
  1321. /* communicate the wmi protocol verision to the target */
  1322. /* FIXME: return error */
  1323. if ((ath6kl_set_host_app_area(ar)) != 0)
  1324. ath6kl_err("unable to set the host app area\n");
  1325. for (i = 0; i < ar->vif_max; i++) {
  1326. ret = ath6kl_target_config_wlan_params(ar, i);
  1327. if (ret)
  1328. goto err_htc_stop;
  1329. }
  1330. ar->state = ATH6KL_STATE_ON;
  1331. return 0;
  1332. err_htc_stop:
  1333. ath6kl_htc_stop(ar->htc_target);
  1334. err_cleanup_scatter:
  1335. ath6kl_hif_cleanup_scatter(ar);
  1336. err_power_off:
  1337. ath6kl_hif_power_off(ar);
  1338. return ret;
  1339. }
  1340. int ath6kl_init_hw_stop(struct ath6kl *ar)
  1341. {
  1342. int ret;
  1343. ath6kl_dbg(ATH6KL_DBG_BOOT, "hw stop\n");
  1344. ath6kl_htc_stop(ar->htc_target);
  1345. ath6kl_hif_stop(ar);
  1346. ath6kl_bmi_reset(ar);
  1347. ret = ath6kl_hif_power_off(ar);
  1348. if (ret)
  1349. ath6kl_warn("failed to power off hif: %d\n", ret);
  1350. ar->state = ATH6KL_STATE_OFF;
  1351. return 0;
  1352. }
  1353. /* FIXME: move this to cfg80211.c and rename to ath6kl_cfg80211_vif_stop() */
  1354. void ath6kl_cleanup_vif(struct ath6kl_vif *vif, bool wmi_ready)
  1355. {
  1356. static u8 bcast_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  1357. bool discon_issued;
  1358. netif_stop_queue(vif->ndev);
  1359. clear_bit(WLAN_ENABLED, &vif->flags);
  1360. if (wmi_ready) {
  1361. discon_issued = test_bit(CONNECTED, &vif->flags) ||
  1362. test_bit(CONNECT_PEND, &vif->flags);
  1363. ath6kl_disconnect(vif);
  1364. del_timer(&vif->disconnect_timer);
  1365. if (discon_issued)
  1366. ath6kl_disconnect_event(vif, DISCONNECT_CMD,
  1367. (vif->nw_type & AP_NETWORK) ?
  1368. bcast_mac : vif->bssid,
  1369. 0, NULL, 0);
  1370. }
  1371. if (vif->scan_req) {
  1372. cfg80211_scan_done(vif->scan_req, true);
  1373. vif->scan_req = NULL;
  1374. }
  1375. /* need to clean up enhanced bmiss detection fw state */
  1376. ath6kl_cfg80211_sta_bmiss_enhance(vif, false);
  1377. }
  1378. void ath6kl_stop_txrx(struct ath6kl *ar)
  1379. {
  1380. struct ath6kl_vif *vif, *tmp_vif;
  1381. int i;
  1382. set_bit(DESTROY_IN_PROGRESS, &ar->flag);
  1383. if (down_interruptible(&ar->sem)) {
  1384. ath6kl_err("down_interruptible failed\n");
  1385. return;
  1386. }
  1387. for (i = 0; i < AP_MAX_NUM_STA; i++)
  1388. aggr_reset_state(ar->sta_list[i].aggr_conn);
  1389. spin_lock_bh(&ar->list_lock);
  1390. list_for_each_entry_safe(vif, tmp_vif, &ar->vif_list, list) {
  1391. list_del(&vif->list);
  1392. spin_unlock_bh(&ar->list_lock);
  1393. ath6kl_cleanup_vif(vif, test_bit(WMI_READY, &ar->flag));
  1394. rtnl_lock();
  1395. ath6kl_cfg80211_vif_cleanup(vif);
  1396. rtnl_unlock();
  1397. spin_lock_bh(&ar->list_lock);
  1398. }
  1399. spin_unlock_bh(&ar->list_lock);
  1400. clear_bit(WMI_READY, &ar->flag);
  1401. /*
  1402. * After wmi_shudown all WMI events will be dropped. We
  1403. * need to cleanup the buffers allocated in AP mode and
  1404. * give disconnect notification to stack, which usually
  1405. * happens in the disconnect_event. Simulate the disconnect
  1406. * event by calling the function directly. Sometimes
  1407. * disconnect_event will be received when the debug logs
  1408. * are collected.
  1409. */
  1410. ath6kl_wmi_shutdown(ar->wmi);
  1411. clear_bit(WMI_ENABLED, &ar->flag);
  1412. if (ar->htc_target) {
  1413. ath6kl_dbg(ATH6KL_DBG_TRC, "%s: shut down htc\n", __func__);
  1414. ath6kl_htc_stop(ar->htc_target);
  1415. }
  1416. /*
  1417. * Try to reset the device if we can. The driver may have been
  1418. * configure NOT to reset the target during a debug session.
  1419. */
  1420. ath6kl_dbg(ATH6KL_DBG_TRC,
  1421. "attempting to reset target on instance destroy\n");
  1422. ath6kl_reset_device(ar, ar->target_type, true, true);
  1423. clear_bit(WLAN_ENABLED, &ar->flag);
  1424. up(&ar->sem);
  1425. }
  1426. EXPORT_SYMBOL(ath6kl_stop_txrx);