init.c 46 KB

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