init.c 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917
  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 = reject_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. /*(DEBLOBBED)*/
  589. static bool check_device_tree(struct ath6kl *ar)
  590. {
  591. static const char *board_id_prop = "atheros,board-id";
  592. struct device_node *node;
  593. char board_filename[64];
  594. const char *board_id;
  595. int ret;
  596. for_each_compatible_node(node, NULL, "atheros,ath6kl") {
  597. board_id = of_get_property(node, board_id_prop, NULL);
  598. if (board_id == NULL) {
  599. ath6kl_warn("No \"%s\" property on %s node.\n",
  600. board_id_prop, node->name);
  601. continue;
  602. }
  603. snprintf(board_filename, sizeof(board_filename),
  604. "/*(DEBLOBBED)*/", ar->hw.fw.dir, board_id);
  605. ret = ath6kl_get_fw(ar, board_filename, &ar->fw_board,
  606. &ar->fw_board_len);
  607. if (ret) {
  608. ath6kl_err("Failed to get DT board file %s: %d\n",
  609. board_filename, ret);
  610. continue;
  611. }
  612. return true;
  613. }
  614. return false;
  615. }
  616. #else
  617. static bool check_device_tree(struct ath6kl *ar)
  618. {
  619. return false;
  620. }
  621. #endif /* CONFIG_OF */
  622. static int ath6kl_fetch_board_file(struct ath6kl *ar)
  623. {
  624. const char *filename;
  625. int ret;
  626. if (ar->fw_board != NULL)
  627. return 0;
  628. if (WARN_ON(ar->hw.fw_board == NULL))
  629. return -EINVAL;
  630. filename = ar->hw.fw_board;
  631. ret = ath6kl_get_fw(ar, filename, &ar->fw_board,
  632. &ar->fw_board_len);
  633. if (ret == 0) {
  634. /* managed to get proper board file */
  635. return 0;
  636. }
  637. if (check_device_tree(ar)) {
  638. /* got board file from device tree */
  639. return 0;
  640. }
  641. /* there was no proper board file, try to use default instead */
  642. ath6kl_warn("Failed to get board file %s (%d), trying to find default board file.\n",
  643. filename, ret);
  644. filename = ar->hw.fw_default_board;
  645. ret = ath6kl_get_fw(ar, filename, &ar->fw_board,
  646. &ar->fw_board_len);
  647. if (ret) {
  648. ath6kl_err("Failed to get default board file %s: %d\n",
  649. filename, ret);
  650. return ret;
  651. }
  652. ath6kl_warn("WARNING! No proper board file was not found, instead using a default board file.\n");
  653. ath6kl_warn("Most likely your hardware won't work as specified. Install correct board file!\n");
  654. return 0;
  655. }
  656. static int ath6kl_fetch_otp_file(struct ath6kl *ar)
  657. {
  658. char filename[100];
  659. int ret;
  660. if (ar->fw_otp != NULL)
  661. return 0;
  662. if (ar->hw.fw.otp == NULL) {
  663. ath6kl_dbg(ATH6KL_DBG_BOOT,
  664. "no OTP file configured for this hw\n");
  665. return 0;
  666. }
  667. snprintf(filename, sizeof(filename), "%s/%s",
  668. ar->hw.fw.dir, ar->hw.fw.otp);
  669. ret = ath6kl_get_fw(ar, filename, &ar->fw_otp,
  670. &ar->fw_otp_len);
  671. if (ret) {
  672. ath6kl_err("Failed to get OTP file %s: %d\n",
  673. filename, ret);
  674. return ret;
  675. }
  676. return 0;
  677. }
  678. static int ath6kl_fetch_testmode_file(struct ath6kl *ar)
  679. {
  680. char filename[100];
  681. int ret;
  682. if (ar->testmode == 0)
  683. return 0;
  684. ath6kl_dbg(ATH6KL_DBG_BOOT, "testmode %d\n", ar->testmode);
  685. if (ar->testmode == 2) {
  686. if (ar->hw.fw.utf == NULL) {
  687. ath6kl_warn("testmode 2 not supported\n");
  688. return -EOPNOTSUPP;
  689. }
  690. snprintf(filename, sizeof(filename), "%s/%s",
  691. ar->hw.fw.dir, ar->hw.fw.utf);
  692. } else {
  693. if (ar->hw.fw.tcmd == NULL) {
  694. ath6kl_warn("testmode 1 not supported\n");
  695. return -EOPNOTSUPP;
  696. }
  697. snprintf(filename, sizeof(filename), "%s/%s",
  698. ar->hw.fw.dir, ar->hw.fw.tcmd);
  699. }
  700. set_bit(TESTMODE, &ar->flag);
  701. ret = ath6kl_get_fw(ar, filename, &ar->fw, &ar->fw_len);
  702. if (ret) {
  703. ath6kl_err("Failed to get testmode %d firmware file %s: %d\n",
  704. ar->testmode, filename, ret);
  705. return ret;
  706. }
  707. return 0;
  708. }
  709. static int ath6kl_fetch_fw_file(struct ath6kl *ar)
  710. {
  711. char filename[100];
  712. int ret;
  713. if (ar->fw != NULL)
  714. return 0;
  715. /* FIXME: remove WARN_ON() as we won't support FW API 1 for long */
  716. if (WARN_ON(ar->hw.fw.fw == NULL))
  717. return -EINVAL;
  718. snprintf(filename, sizeof(filename), "%s/%s",
  719. ar->hw.fw.dir, ar->hw.fw.fw);
  720. ret = ath6kl_get_fw(ar, filename, &ar->fw, &ar->fw_len);
  721. if (ret) {
  722. ath6kl_err("Failed to get firmware file %s: %d\n",
  723. filename, ret);
  724. return ret;
  725. }
  726. return 0;
  727. }
  728. static int ath6kl_fetch_patch_file(struct ath6kl *ar)
  729. {
  730. char filename[100];
  731. int ret;
  732. if (ar->fw_patch != NULL)
  733. return 0;
  734. if (ar->hw.fw.patch == NULL)
  735. return 0;
  736. snprintf(filename, sizeof(filename), "%s/%s",
  737. ar->hw.fw.dir, ar->hw.fw.patch);
  738. ret = ath6kl_get_fw(ar, filename, &ar->fw_patch,
  739. &ar->fw_patch_len);
  740. if (ret) {
  741. ath6kl_err("Failed to get patch file %s: %d\n",
  742. filename, ret);
  743. return ret;
  744. }
  745. return 0;
  746. }
  747. static int ath6kl_fetch_testscript_file(struct ath6kl *ar)
  748. {
  749. char filename[100];
  750. int ret;
  751. if (ar->testmode != 2)
  752. return 0;
  753. if (ar->fw_testscript != NULL)
  754. return 0;
  755. if (ar->hw.fw.testscript == NULL)
  756. return 0;
  757. snprintf(filename, sizeof(filename), "%s/%s",
  758. ar->hw.fw.dir, ar->hw.fw.testscript);
  759. ret = ath6kl_get_fw(ar, filename, &ar->fw_testscript,
  760. &ar->fw_testscript_len);
  761. if (ret) {
  762. ath6kl_err("Failed to get testscript file %s: %d\n",
  763. filename, ret);
  764. return ret;
  765. }
  766. return 0;
  767. }
  768. static int ath6kl_fetch_fw_api1(struct ath6kl *ar)
  769. {
  770. int ret;
  771. ret = ath6kl_fetch_otp_file(ar);
  772. if (ret)
  773. return ret;
  774. ret = ath6kl_fetch_fw_file(ar);
  775. if (ret)
  776. return ret;
  777. ret = ath6kl_fetch_patch_file(ar);
  778. if (ret)
  779. return ret;
  780. ret = ath6kl_fetch_testscript_file(ar);
  781. if (ret)
  782. return ret;
  783. return 0;
  784. }
  785. static int ath6kl_fetch_fw_apin(struct ath6kl *ar, const char *name)
  786. {
  787. size_t magic_len, len, ie_len;
  788. const struct firmware *fw;
  789. struct ath6kl_fw_ie *hdr;
  790. char filename[100];
  791. const u8 *data;
  792. int ret, ie_id, i, index, bit;
  793. __le32 *val;
  794. snprintf(filename, sizeof(filename), "%s/%s", ar->hw.fw.dir, name);
  795. ret = reject_firmware(&fw, filename, ar->dev);
  796. if (ret)
  797. return ret;
  798. data = fw->data;
  799. len = fw->size;
  800. /* magic also includes the null byte, check that as well */
  801. magic_len = strlen(ATH6KL_FIRMWARE_MAGIC) + 1;
  802. if (len < magic_len) {
  803. ret = -EINVAL;
  804. goto out;
  805. }
  806. if (memcmp(data, ATH6KL_FIRMWARE_MAGIC, magic_len) != 0) {
  807. ret = -EINVAL;
  808. goto out;
  809. }
  810. len -= magic_len;
  811. data += magic_len;
  812. /* loop elements */
  813. while (len > sizeof(struct ath6kl_fw_ie)) {
  814. /* hdr is unaligned! */
  815. hdr = (struct ath6kl_fw_ie *) data;
  816. ie_id = le32_to_cpup(&hdr->id);
  817. ie_len = le32_to_cpup(&hdr->len);
  818. len -= sizeof(*hdr);
  819. data += sizeof(*hdr);
  820. if (len < ie_len) {
  821. ret = -EINVAL;
  822. goto out;
  823. }
  824. switch (ie_id) {
  825. case ATH6KL_FW_IE_FW_VERSION:
  826. strlcpy(ar->wiphy->fw_version, data,
  827. sizeof(ar->wiphy->fw_version));
  828. ath6kl_dbg(ATH6KL_DBG_BOOT,
  829. "found fw version %s\n",
  830. ar->wiphy->fw_version);
  831. break;
  832. case ATH6KL_FW_IE_OTP_IMAGE:
  833. ath6kl_dbg(ATH6KL_DBG_BOOT, "found otp image ie (%zd B)\n",
  834. ie_len);
  835. ar->fw_otp = kmemdup(data, ie_len, GFP_KERNEL);
  836. if (ar->fw_otp == NULL) {
  837. ret = -ENOMEM;
  838. goto out;
  839. }
  840. ar->fw_otp_len = ie_len;
  841. break;
  842. case ATH6KL_FW_IE_FW_IMAGE:
  843. ath6kl_dbg(ATH6KL_DBG_BOOT, "found fw image ie (%zd B)\n",
  844. ie_len);
  845. /* in testmode we already might have a fw file */
  846. if (ar->fw != NULL)
  847. break;
  848. ar->fw = vmalloc(ie_len);
  849. if (ar->fw == NULL) {
  850. ret = -ENOMEM;
  851. goto out;
  852. }
  853. memcpy(ar->fw, data, ie_len);
  854. ar->fw_len = ie_len;
  855. break;
  856. case ATH6KL_FW_IE_PATCH_IMAGE:
  857. ath6kl_dbg(ATH6KL_DBG_BOOT, "found patch image ie (%zd B)\n",
  858. ie_len);
  859. ar->fw_patch = kmemdup(data, ie_len, GFP_KERNEL);
  860. if (ar->fw_patch == NULL) {
  861. ret = -ENOMEM;
  862. goto out;
  863. }
  864. ar->fw_patch_len = ie_len;
  865. break;
  866. case ATH6KL_FW_IE_RESERVED_RAM_SIZE:
  867. val = (__le32 *) data;
  868. ar->hw.reserved_ram_size = le32_to_cpup(val);
  869. ath6kl_dbg(ATH6KL_DBG_BOOT,
  870. "found reserved ram size ie %d\n",
  871. ar->hw.reserved_ram_size);
  872. break;
  873. case ATH6KL_FW_IE_CAPABILITIES:
  874. ath6kl_dbg(ATH6KL_DBG_BOOT,
  875. "found firmware capabilities ie (%zd B)\n",
  876. ie_len);
  877. for (i = 0; i < ATH6KL_FW_CAPABILITY_MAX; i++) {
  878. index = i / 8;
  879. bit = i % 8;
  880. if (index == ie_len)
  881. break;
  882. if (data[index] & (1 << bit))
  883. __set_bit(i, ar->fw_capabilities);
  884. }
  885. ath6kl_dbg_dump(ATH6KL_DBG_BOOT, "capabilities", "",
  886. ar->fw_capabilities,
  887. sizeof(ar->fw_capabilities));
  888. break;
  889. case ATH6KL_FW_IE_PATCH_ADDR:
  890. if (ie_len != sizeof(*val))
  891. break;
  892. val = (__le32 *) data;
  893. ar->hw.dataset_patch_addr = le32_to_cpup(val);
  894. ath6kl_dbg(ATH6KL_DBG_BOOT,
  895. "found patch address ie 0x%x\n",
  896. ar->hw.dataset_patch_addr);
  897. break;
  898. case ATH6KL_FW_IE_BOARD_ADDR:
  899. if (ie_len != sizeof(*val))
  900. break;
  901. val = (__le32 *) data;
  902. ar->hw.board_addr = le32_to_cpup(val);
  903. ath6kl_dbg(ATH6KL_DBG_BOOT,
  904. "found board address ie 0x%x\n",
  905. ar->hw.board_addr);
  906. break;
  907. case ATH6KL_FW_IE_VIF_MAX:
  908. if (ie_len != sizeof(*val))
  909. break;
  910. val = (__le32 *) data;
  911. ar->vif_max = min_t(unsigned int, le32_to_cpup(val),
  912. ATH6KL_VIF_MAX);
  913. if (ar->vif_max > 1 && !ar->p2p)
  914. ar->max_norm_iface = 2;
  915. ath6kl_dbg(ATH6KL_DBG_BOOT,
  916. "found vif max ie %d\n", ar->vif_max);
  917. break;
  918. default:
  919. ath6kl_dbg(ATH6KL_DBG_BOOT, "Unknown fw ie: %u\n",
  920. le32_to_cpup(&hdr->id));
  921. break;
  922. }
  923. len -= ie_len;
  924. data += ie_len;
  925. };
  926. ret = 0;
  927. out:
  928. release_firmware(fw);
  929. return ret;
  930. }
  931. int ath6kl_init_fetch_firmwares(struct ath6kl *ar)
  932. {
  933. int ret;
  934. ret = ath6kl_fetch_board_file(ar);
  935. if (ret)
  936. return ret;
  937. ret = ath6kl_fetch_testmode_file(ar);
  938. if (ret)
  939. return ret;
  940. ret = ath6kl_fetch_fw_apin(ar, ATH6KL_FW_API5_FILE);
  941. if (ret == 0) {
  942. ar->fw_api = 5;
  943. goto out;
  944. }
  945. ret = ath6kl_fetch_fw_apin(ar, ATH6KL_FW_API4_FILE);
  946. if (ret == 0) {
  947. ar->fw_api = 4;
  948. goto out;
  949. }
  950. ret = ath6kl_fetch_fw_apin(ar, ATH6KL_FW_API3_FILE);
  951. if (ret == 0) {
  952. ar->fw_api = 3;
  953. goto out;
  954. }
  955. ret = ath6kl_fetch_fw_apin(ar, ATH6KL_FW_API2_FILE);
  956. if (ret == 0) {
  957. ar->fw_api = 2;
  958. goto out;
  959. }
  960. ret = ath6kl_fetch_fw_api1(ar);
  961. if (ret)
  962. return ret;
  963. ar->fw_api = 1;
  964. out:
  965. ath6kl_dbg(ATH6KL_DBG_BOOT, "using fw api %d\n", ar->fw_api);
  966. return 0;
  967. }
  968. static int ath6kl_upload_board_file(struct ath6kl *ar)
  969. {
  970. u32 board_address, board_ext_address, param;
  971. u32 board_data_size, board_ext_data_size;
  972. int ret;
  973. if (WARN_ON(ar->fw_board == NULL))
  974. return -ENOENT;
  975. /*
  976. * Determine where in Target RAM to write Board Data.
  977. * For AR6004, host determine Target RAM address for
  978. * writing board data.
  979. */
  980. if (ar->hw.board_addr != 0) {
  981. board_address = ar->hw.board_addr;
  982. ath6kl_bmi_write_hi32(ar, hi_board_data,
  983. board_address);
  984. } else {
  985. ret = ath6kl_bmi_read_hi32(ar, hi_board_data, &board_address);
  986. if (ret) {
  987. ath6kl_err("Failed to get board file target address.\n");
  988. return ret;
  989. }
  990. }
  991. /* determine where in target ram to write extended board data */
  992. ret = ath6kl_bmi_read_hi32(ar, hi_board_ext_data, &board_ext_address);
  993. if (ret) {
  994. ath6kl_err("Failed to get extended board file target address.\n");
  995. return ret;
  996. }
  997. if (ar->target_type == TARGET_TYPE_AR6003 &&
  998. board_ext_address == 0) {
  999. ath6kl_err("Failed to get board file target address.\n");
  1000. return -EINVAL;
  1001. }
  1002. switch (ar->target_type) {
  1003. case TARGET_TYPE_AR6003:
  1004. board_data_size = AR6003_BOARD_DATA_SZ;
  1005. board_ext_data_size = AR6003_BOARD_EXT_DATA_SZ;
  1006. if (ar->fw_board_len > (board_data_size + board_ext_data_size))
  1007. board_ext_data_size = AR6003_BOARD_EXT_DATA_SZ_V2;
  1008. break;
  1009. case TARGET_TYPE_AR6004:
  1010. board_data_size = AR6004_BOARD_DATA_SZ;
  1011. board_ext_data_size = AR6004_BOARD_EXT_DATA_SZ;
  1012. break;
  1013. default:
  1014. WARN_ON(1);
  1015. return -EINVAL;
  1016. }
  1017. if (board_ext_address &&
  1018. ar->fw_board_len == (board_data_size + board_ext_data_size)) {
  1019. /* write extended board data */
  1020. ath6kl_dbg(ATH6KL_DBG_BOOT,
  1021. "writing extended board data to 0x%x (%d B)\n",
  1022. board_ext_address, board_ext_data_size);
  1023. ret = ath6kl_bmi_write(ar, board_ext_address,
  1024. ar->fw_board + board_data_size,
  1025. board_ext_data_size);
  1026. if (ret) {
  1027. ath6kl_err("Failed to write extended board data: %d\n",
  1028. ret);
  1029. return ret;
  1030. }
  1031. /* record that extended board data is initialized */
  1032. param = (board_ext_data_size << 16) | 1;
  1033. ath6kl_bmi_write_hi32(ar, hi_board_ext_data_config, param);
  1034. }
  1035. if (ar->fw_board_len < board_data_size) {
  1036. ath6kl_err("Too small board file: %zu\n", ar->fw_board_len);
  1037. ret = -EINVAL;
  1038. return ret;
  1039. }
  1040. ath6kl_dbg(ATH6KL_DBG_BOOT, "writing board file to 0x%x (%d B)\n",
  1041. board_address, board_data_size);
  1042. ret = ath6kl_bmi_write(ar, board_address, ar->fw_board,
  1043. board_data_size);
  1044. if (ret) {
  1045. ath6kl_err("Board file bmi write failed: %d\n", ret);
  1046. return ret;
  1047. }
  1048. /* record the fact that Board Data IS initialized */
  1049. if ((ar->version.target_ver == AR6004_HW_1_3_VERSION) ||
  1050. (ar->version.target_ver == AR6004_HW_3_0_VERSION))
  1051. param = board_data_size;
  1052. else
  1053. param = 1;
  1054. ath6kl_bmi_write_hi32(ar, hi_board_data_initialized, param);
  1055. return ret;
  1056. }
  1057. static int ath6kl_upload_otp(struct ath6kl *ar)
  1058. {
  1059. u32 address, param;
  1060. bool from_hw = false;
  1061. int ret;
  1062. if (ar->fw_otp == NULL)
  1063. return 0;
  1064. address = ar->hw.app_load_addr;
  1065. ath6kl_dbg(ATH6KL_DBG_BOOT, "writing otp to 0x%x (%zd B)\n", address,
  1066. ar->fw_otp_len);
  1067. ret = ath6kl_bmi_fast_download(ar, address, ar->fw_otp,
  1068. ar->fw_otp_len);
  1069. if (ret) {
  1070. ath6kl_err("Failed to upload OTP file: %d\n", ret);
  1071. return ret;
  1072. }
  1073. /* read firmware start address */
  1074. ret = ath6kl_bmi_read_hi32(ar, hi_app_start, &address);
  1075. if (ret) {
  1076. ath6kl_err("Failed to read hi_app_start: %d\n", ret);
  1077. return ret;
  1078. }
  1079. if (ar->hw.app_start_override_addr == 0) {
  1080. ar->hw.app_start_override_addr = address;
  1081. from_hw = true;
  1082. }
  1083. ath6kl_dbg(ATH6KL_DBG_BOOT, "app_start_override_addr%s 0x%x\n",
  1084. from_hw ? " (from hw)" : "",
  1085. ar->hw.app_start_override_addr);
  1086. /* execute the OTP code */
  1087. ath6kl_dbg(ATH6KL_DBG_BOOT, "executing OTP at 0x%x\n",
  1088. ar->hw.app_start_override_addr);
  1089. param = 0;
  1090. ath6kl_bmi_execute(ar, ar->hw.app_start_override_addr, &param);
  1091. return ret;
  1092. }
  1093. static int ath6kl_upload_firmware(struct ath6kl *ar)
  1094. {
  1095. u32 address;
  1096. int ret;
  1097. if (WARN_ON(ar->fw == NULL))
  1098. return 0;
  1099. address = ar->hw.app_load_addr;
  1100. ath6kl_dbg(ATH6KL_DBG_BOOT, "writing firmware to 0x%x (%zd B)\n",
  1101. address, ar->fw_len);
  1102. ret = ath6kl_bmi_fast_download(ar, address, ar->fw, ar->fw_len);
  1103. if (ret) {
  1104. ath6kl_err("Failed to write firmware: %d\n", ret);
  1105. return ret;
  1106. }
  1107. /*
  1108. * Set starting address for firmware
  1109. * Don't need to setup app_start override addr on AR6004
  1110. */
  1111. if (ar->target_type != TARGET_TYPE_AR6004) {
  1112. address = ar->hw.app_start_override_addr;
  1113. ath6kl_bmi_set_app_start(ar, address);
  1114. }
  1115. return ret;
  1116. }
  1117. static int ath6kl_upload_patch(struct ath6kl *ar)
  1118. {
  1119. u32 address;
  1120. int ret;
  1121. if (ar->fw_patch == NULL)
  1122. return 0;
  1123. address = ar->hw.dataset_patch_addr;
  1124. ath6kl_dbg(ATH6KL_DBG_BOOT, "writing patch to 0x%x (%zd B)\n",
  1125. address, ar->fw_patch_len);
  1126. ret = ath6kl_bmi_write(ar, address, ar->fw_patch, ar->fw_patch_len);
  1127. if (ret) {
  1128. ath6kl_err("Failed to write patch file: %d\n", ret);
  1129. return ret;
  1130. }
  1131. ath6kl_bmi_write_hi32(ar, hi_dset_list_head, address);
  1132. return 0;
  1133. }
  1134. static int ath6kl_upload_testscript(struct ath6kl *ar)
  1135. {
  1136. u32 address;
  1137. int ret;
  1138. if (ar->testmode != 2)
  1139. return 0;
  1140. if (ar->fw_testscript == NULL)
  1141. return 0;
  1142. address = ar->hw.testscript_addr;
  1143. ath6kl_dbg(ATH6KL_DBG_BOOT, "writing testscript to 0x%x (%zd B)\n",
  1144. address, ar->fw_testscript_len);
  1145. ret = ath6kl_bmi_write(ar, address, ar->fw_testscript,
  1146. ar->fw_testscript_len);
  1147. if (ret) {
  1148. ath6kl_err("Failed to write testscript file: %d\n", ret);
  1149. return ret;
  1150. }
  1151. ath6kl_bmi_write_hi32(ar, hi_ota_testscript, address);
  1152. if ((ar->version.target_ver != AR6004_HW_1_3_VERSION) &&
  1153. (ar->version.target_ver != AR6004_HW_3_0_VERSION))
  1154. ath6kl_bmi_write_hi32(ar, hi_end_ram_reserve_sz, 4096);
  1155. ath6kl_bmi_write_hi32(ar, hi_test_apps_related, 1);
  1156. return 0;
  1157. }
  1158. static int ath6kl_init_upload(struct ath6kl *ar)
  1159. {
  1160. u32 param, options, sleep, address;
  1161. int status = 0;
  1162. if (ar->target_type != TARGET_TYPE_AR6003 &&
  1163. ar->target_type != TARGET_TYPE_AR6004)
  1164. return -EINVAL;
  1165. /* temporarily disable system sleep */
  1166. address = MBOX_BASE_ADDRESS + LOCAL_SCRATCH_ADDRESS;
  1167. status = ath6kl_bmi_reg_read(ar, address, &param);
  1168. if (status)
  1169. return status;
  1170. options = param;
  1171. param |= ATH6KL_OPTION_SLEEP_DISABLE;
  1172. status = ath6kl_bmi_reg_write(ar, address, param);
  1173. if (status)
  1174. return status;
  1175. address = RTC_BASE_ADDRESS + SYSTEM_SLEEP_ADDRESS;
  1176. status = ath6kl_bmi_reg_read(ar, address, &param);
  1177. if (status)
  1178. return status;
  1179. sleep = param;
  1180. param |= SM(SYSTEM_SLEEP_DISABLE, 1);
  1181. status = ath6kl_bmi_reg_write(ar, address, param);
  1182. if (status)
  1183. return status;
  1184. ath6kl_dbg(ATH6KL_DBG_TRC, "old options: %d, old sleep: %d\n",
  1185. options, sleep);
  1186. /* program analog PLL register */
  1187. /* no need to control 40/44MHz clock on AR6004 */
  1188. if (ar->target_type != TARGET_TYPE_AR6004) {
  1189. status = ath6kl_bmi_reg_write(ar, ATH6KL_ANALOG_PLL_REGISTER,
  1190. 0xF9104001);
  1191. if (status)
  1192. return status;
  1193. /* Run at 80/88MHz by default */
  1194. param = SM(CPU_CLOCK_STANDARD, 1);
  1195. address = RTC_BASE_ADDRESS + CPU_CLOCK_ADDRESS;
  1196. status = ath6kl_bmi_reg_write(ar, address, param);
  1197. if (status)
  1198. return status;
  1199. }
  1200. param = 0;
  1201. address = RTC_BASE_ADDRESS + LPO_CAL_ADDRESS;
  1202. param = SM(LPO_CAL_ENABLE, 1);
  1203. status = ath6kl_bmi_reg_write(ar, address, param);
  1204. if (status)
  1205. return status;
  1206. /* WAR to avoid SDIO CRC err */
  1207. if (ar->hw.flags & ATH6KL_HW_SDIO_CRC_ERROR_WAR) {
  1208. ath6kl_err("temporary war to avoid sdio crc error\n");
  1209. param = 0x28;
  1210. address = GPIO_BASE_ADDRESS + GPIO_PIN9_ADDRESS;
  1211. status = ath6kl_bmi_reg_write(ar, address, param);
  1212. if (status)
  1213. return status;
  1214. param = 0x20;
  1215. address = GPIO_BASE_ADDRESS + GPIO_PIN10_ADDRESS;
  1216. status = ath6kl_bmi_reg_write(ar, address, param);
  1217. if (status)
  1218. return status;
  1219. address = GPIO_BASE_ADDRESS + GPIO_PIN11_ADDRESS;
  1220. status = ath6kl_bmi_reg_write(ar, address, param);
  1221. if (status)
  1222. return status;
  1223. address = GPIO_BASE_ADDRESS + GPIO_PIN12_ADDRESS;
  1224. status = ath6kl_bmi_reg_write(ar, address, param);
  1225. if (status)
  1226. return status;
  1227. address = GPIO_BASE_ADDRESS + GPIO_PIN13_ADDRESS;
  1228. status = ath6kl_bmi_reg_write(ar, address, param);
  1229. if (status)
  1230. return status;
  1231. }
  1232. /* write EEPROM data to Target RAM */
  1233. status = ath6kl_upload_board_file(ar);
  1234. if (status)
  1235. return status;
  1236. /* transfer One time Programmable data */
  1237. status = ath6kl_upload_otp(ar);
  1238. if (status)
  1239. return status;
  1240. /* Download Target firmware */
  1241. status = ath6kl_upload_firmware(ar);
  1242. if (status)
  1243. return status;
  1244. status = ath6kl_upload_patch(ar);
  1245. if (status)
  1246. return status;
  1247. /* Download the test script */
  1248. status = ath6kl_upload_testscript(ar);
  1249. if (status)
  1250. return status;
  1251. /* Restore system sleep */
  1252. address = RTC_BASE_ADDRESS + SYSTEM_SLEEP_ADDRESS;
  1253. status = ath6kl_bmi_reg_write(ar, address, sleep);
  1254. if (status)
  1255. return status;
  1256. address = MBOX_BASE_ADDRESS + LOCAL_SCRATCH_ADDRESS;
  1257. param = options | 0x20;
  1258. status = ath6kl_bmi_reg_write(ar, address, param);
  1259. if (status)
  1260. return status;
  1261. return status;
  1262. }
  1263. int ath6kl_init_hw_params(struct ath6kl *ar)
  1264. {
  1265. const struct ath6kl_hw *uninitialized_var(hw);
  1266. int i;
  1267. for (i = 0; i < ARRAY_SIZE(hw_list); i++) {
  1268. hw = &hw_list[i];
  1269. if (hw->id == ar->version.target_ver)
  1270. break;
  1271. }
  1272. if (i == ARRAY_SIZE(hw_list)) {
  1273. ath6kl_err("Unsupported hardware version: 0x%x\n",
  1274. ar->version.target_ver);
  1275. return -EINVAL;
  1276. }
  1277. ar->hw = *hw;
  1278. ath6kl_dbg(ATH6KL_DBG_BOOT,
  1279. "target_ver 0x%x target_type 0x%x dataset_patch 0x%x app_load_addr 0x%x\n",
  1280. ar->version.target_ver, ar->target_type,
  1281. ar->hw.dataset_patch_addr, ar->hw.app_load_addr);
  1282. ath6kl_dbg(ATH6KL_DBG_BOOT,
  1283. "app_start_override_addr 0x%x board_ext_data_addr 0x%x reserved_ram_size 0x%x",
  1284. ar->hw.app_start_override_addr, ar->hw.board_ext_data_addr,
  1285. ar->hw.reserved_ram_size);
  1286. ath6kl_dbg(ATH6KL_DBG_BOOT,
  1287. "refclk_hz %d uarttx_pin %d",
  1288. ar->hw.refclk_hz, ar->hw.uarttx_pin);
  1289. return 0;
  1290. }
  1291. static const char *ath6kl_init_get_hif_name(enum ath6kl_hif_type type)
  1292. {
  1293. switch (type) {
  1294. case ATH6KL_HIF_TYPE_SDIO:
  1295. return "sdio";
  1296. case ATH6KL_HIF_TYPE_USB:
  1297. return "usb";
  1298. }
  1299. return NULL;
  1300. }
  1301. static const struct fw_capa_str_map {
  1302. int id;
  1303. const char *name;
  1304. } fw_capa_map[] = {
  1305. { ATH6KL_FW_CAPABILITY_HOST_P2P, "host-p2p" },
  1306. { ATH6KL_FW_CAPABILITY_SCHED_SCAN, "sched-scan" },
  1307. { ATH6KL_FW_CAPABILITY_STA_P2PDEV_DUPLEX, "sta-p2pdev-duplex" },
  1308. { ATH6KL_FW_CAPABILITY_INACTIVITY_TIMEOUT, "inactivity-timeout" },
  1309. { ATH6KL_FW_CAPABILITY_RSN_CAP_OVERRIDE, "rsn-cap-override" },
  1310. { ATH6KL_FW_CAPABILITY_WOW_MULTICAST_FILTER, "wow-mc-filter" },
  1311. { ATH6KL_FW_CAPABILITY_BMISS_ENHANCE, "bmiss-enhance" },
  1312. { ATH6KL_FW_CAPABILITY_SCHED_SCAN_MATCH_LIST, "sscan-match-list" },
  1313. { ATH6KL_FW_CAPABILITY_RSSI_SCAN_THOLD, "rssi-scan-thold" },
  1314. { ATH6KL_FW_CAPABILITY_CUSTOM_MAC_ADDR, "custom-mac-addr" },
  1315. { ATH6KL_FW_CAPABILITY_TX_ERR_NOTIFY, "tx-err-notify" },
  1316. { ATH6KL_FW_CAPABILITY_REGDOMAIN, "regdomain" },
  1317. { ATH6KL_FW_CAPABILITY_SCHED_SCAN_V2, "sched-scan-v2" },
  1318. { ATH6KL_FW_CAPABILITY_HEART_BEAT_POLL, "hb-poll" },
  1319. { ATH6KL_FW_CAPABILITY_64BIT_RATES, "64bit-rates" },
  1320. { ATH6KL_FW_CAPABILITY_AP_INACTIVITY_MINS, "ap-inactivity-mins" },
  1321. { ATH6KL_FW_CAPABILITY_MAP_LP_ENDPOINT, "map-lp-endpoint" },
  1322. { ATH6KL_FW_CAPABILITY_RATETABLE_MCS15, "ratetable-mcs15" },
  1323. { ATH6KL_FW_CAPABILITY_NO_IP_CHECKSUM, "no-ip-checksum" },
  1324. };
  1325. static const char *ath6kl_init_get_fw_capa_name(unsigned int id)
  1326. {
  1327. int i;
  1328. for (i = 0; i < ARRAY_SIZE(fw_capa_map); i++) {
  1329. if (fw_capa_map[i].id == id)
  1330. return fw_capa_map[i].name;
  1331. }
  1332. return "<unknown>";
  1333. }
  1334. static void ath6kl_init_get_fwcaps(struct ath6kl *ar, char *buf, size_t buf_len)
  1335. {
  1336. u8 *data = (u8 *) ar->fw_capabilities;
  1337. size_t trunc_len, len = 0;
  1338. int i, index, bit;
  1339. char *trunc = "...";
  1340. for (i = 0; i < ATH6KL_FW_CAPABILITY_MAX; i++) {
  1341. index = i / 8;
  1342. bit = i % 8;
  1343. if (index >= sizeof(ar->fw_capabilities) * 4)
  1344. break;
  1345. if (buf_len - len < 4) {
  1346. ath6kl_warn("firmware capability buffer too small!\n");
  1347. /* add "..." to the end of string */
  1348. trunc_len = strlen(trunc) + 1;
  1349. strncpy(buf + buf_len - trunc_len, trunc, trunc_len);
  1350. return;
  1351. }
  1352. if (data[index] & (1 << bit)) {
  1353. len += scnprintf(buf + len, buf_len - len, "%s,",
  1354. ath6kl_init_get_fw_capa_name(i));
  1355. }
  1356. }
  1357. /* overwrite the last comma */
  1358. if (len > 0)
  1359. len--;
  1360. buf[len] = '\0';
  1361. }
  1362. static int ath6kl_init_hw_reset(struct ath6kl *ar)
  1363. {
  1364. ath6kl_dbg(ATH6KL_DBG_BOOT, "cold resetting the device");
  1365. return ath6kl_diag_write32(ar, RESET_CONTROL_ADDRESS,
  1366. cpu_to_le32(RESET_CONTROL_COLD_RST));
  1367. }
  1368. static int __ath6kl_init_hw_start(struct ath6kl *ar)
  1369. {
  1370. long timeleft;
  1371. int ret, i;
  1372. char buf[200];
  1373. ath6kl_dbg(ATH6KL_DBG_BOOT, "hw start\n");
  1374. ret = ath6kl_hif_power_on(ar);
  1375. if (ret)
  1376. return ret;
  1377. ret = ath6kl_configure_target(ar);
  1378. if (ret)
  1379. goto err_power_off;
  1380. ret = ath6kl_init_upload(ar);
  1381. if (ret)
  1382. goto err_power_off;
  1383. /* Do we need to finish the BMI phase */
  1384. ret = ath6kl_bmi_done(ar);
  1385. if (ret)
  1386. goto err_power_off;
  1387. /*
  1388. * The reason we have to wait for the target here is that the
  1389. * driver layer has to init BMI in order to set the host block
  1390. * size.
  1391. */
  1392. ret = ath6kl_htc_wait_target(ar->htc_target);
  1393. if (ret == -ETIMEDOUT) {
  1394. /*
  1395. * Most likely USB target is in odd state after reboot and
  1396. * needs a reset. A cold reset makes the whole device
  1397. * disappear from USB bus and initialisation starts from
  1398. * beginning.
  1399. */
  1400. ath6kl_warn("htc wait target timed out, resetting device\n");
  1401. ath6kl_init_hw_reset(ar);
  1402. goto err_power_off;
  1403. } else if (ret) {
  1404. ath6kl_err("htc wait target failed: %d\n", ret);
  1405. goto err_power_off;
  1406. }
  1407. ret = ath6kl_init_service_ep(ar);
  1408. if (ret) {
  1409. ath6kl_err("Endpoint service initilisation failed: %d\n", ret);
  1410. goto err_cleanup_scatter;
  1411. }
  1412. /* setup credit distribution */
  1413. ath6kl_htc_credit_setup(ar->htc_target, &ar->credit_state_info);
  1414. /* start HTC */
  1415. ret = ath6kl_htc_start(ar->htc_target);
  1416. if (ret) {
  1417. /* FIXME: call this */
  1418. ath6kl_cookie_cleanup(ar);
  1419. goto err_cleanup_scatter;
  1420. }
  1421. /* Wait for Wmi event to be ready */
  1422. timeleft = wait_event_interruptible_timeout(ar->event_wq,
  1423. test_bit(WMI_READY,
  1424. &ar->flag),
  1425. WMI_TIMEOUT);
  1426. if (timeleft <= 0) {
  1427. clear_bit(WMI_READY, &ar->flag);
  1428. ath6kl_err("wmi is not ready or wait was interrupted: %ld\n",
  1429. timeleft);
  1430. ret = -EIO;
  1431. goto err_htc_stop;
  1432. }
  1433. ath6kl_dbg(ATH6KL_DBG_BOOT, "firmware booted\n");
  1434. if (test_and_clear_bit(FIRST_BOOT, &ar->flag)) {
  1435. ath6kl_info("%s %s fw %s api %d%s\n",
  1436. ar->hw.name,
  1437. ath6kl_init_get_hif_name(ar->hif_type),
  1438. ar->wiphy->fw_version,
  1439. ar->fw_api,
  1440. test_bit(TESTMODE, &ar->flag) ? " testmode" : "");
  1441. ath6kl_init_get_fwcaps(ar, buf, sizeof(buf));
  1442. ath6kl_info("firmware supports: %s\n", buf);
  1443. }
  1444. if (ar->version.abi_ver != ATH6KL_ABI_VERSION) {
  1445. ath6kl_err("abi version mismatch: host(0x%x), target(0x%x)\n",
  1446. ATH6KL_ABI_VERSION, ar->version.abi_ver);
  1447. ret = -EIO;
  1448. goto err_htc_stop;
  1449. }
  1450. ath6kl_dbg(ATH6KL_DBG_TRC, "%s: wmi is ready\n", __func__);
  1451. /* communicate the wmi protocol verision to the target */
  1452. /* FIXME: return error */
  1453. if ((ath6kl_set_host_app_area(ar)) != 0)
  1454. ath6kl_err("unable to set the host app area\n");
  1455. for (i = 0; i < ar->vif_max; i++) {
  1456. ret = ath6kl_target_config_wlan_params(ar, i);
  1457. if (ret)
  1458. goto err_htc_stop;
  1459. }
  1460. return 0;
  1461. err_htc_stop:
  1462. ath6kl_htc_stop(ar->htc_target);
  1463. err_cleanup_scatter:
  1464. ath6kl_hif_cleanup_scatter(ar);
  1465. err_power_off:
  1466. ath6kl_hif_power_off(ar);
  1467. return ret;
  1468. }
  1469. int ath6kl_init_hw_start(struct ath6kl *ar)
  1470. {
  1471. int err;
  1472. err = __ath6kl_init_hw_start(ar);
  1473. if (err)
  1474. return err;
  1475. ar->state = ATH6KL_STATE_ON;
  1476. return 0;
  1477. }
  1478. static int __ath6kl_init_hw_stop(struct ath6kl *ar)
  1479. {
  1480. int ret;
  1481. ath6kl_dbg(ATH6KL_DBG_BOOT, "hw stop\n");
  1482. ath6kl_htc_stop(ar->htc_target);
  1483. ath6kl_hif_stop(ar);
  1484. ath6kl_bmi_reset(ar);
  1485. ret = ath6kl_hif_power_off(ar);
  1486. if (ret)
  1487. ath6kl_warn("failed to power off hif: %d\n", ret);
  1488. return 0;
  1489. }
  1490. int ath6kl_init_hw_stop(struct ath6kl *ar)
  1491. {
  1492. int err;
  1493. err = __ath6kl_init_hw_stop(ar);
  1494. if (err)
  1495. return err;
  1496. ar->state = ATH6KL_STATE_OFF;
  1497. return 0;
  1498. }
  1499. void ath6kl_init_hw_restart(struct ath6kl *ar)
  1500. {
  1501. clear_bit(WMI_READY, &ar->flag);
  1502. ath6kl_cfg80211_stop_all(ar);
  1503. if (__ath6kl_init_hw_stop(ar)) {
  1504. ath6kl_dbg(ATH6KL_DBG_RECOVERY, "Failed to stop during fw error recovery\n");
  1505. return;
  1506. }
  1507. if (__ath6kl_init_hw_start(ar)) {
  1508. ath6kl_dbg(ATH6KL_DBG_RECOVERY, "Failed to restart during fw error recovery\n");
  1509. return;
  1510. }
  1511. }
  1512. void ath6kl_stop_txrx(struct ath6kl *ar)
  1513. {
  1514. struct ath6kl_vif *vif, *tmp_vif;
  1515. int i;
  1516. set_bit(DESTROY_IN_PROGRESS, &ar->flag);
  1517. if (down_interruptible(&ar->sem)) {
  1518. ath6kl_err("down_interruptible failed\n");
  1519. return;
  1520. }
  1521. for (i = 0; i < AP_MAX_NUM_STA; i++)
  1522. aggr_reset_state(ar->sta_list[i].aggr_conn);
  1523. spin_lock_bh(&ar->list_lock);
  1524. list_for_each_entry_safe(vif, tmp_vif, &ar->vif_list, list) {
  1525. list_del(&vif->list);
  1526. spin_unlock_bh(&ar->list_lock);
  1527. ath6kl_cfg80211_vif_stop(vif, test_bit(WMI_READY, &ar->flag));
  1528. rtnl_lock();
  1529. ath6kl_cfg80211_vif_cleanup(vif);
  1530. rtnl_unlock();
  1531. spin_lock_bh(&ar->list_lock);
  1532. }
  1533. spin_unlock_bh(&ar->list_lock);
  1534. clear_bit(WMI_READY, &ar->flag);
  1535. if (ar->fw_recovery.enable)
  1536. del_timer_sync(&ar->fw_recovery.hb_timer);
  1537. /*
  1538. * After wmi_shudown all WMI events will be dropped. We
  1539. * need to cleanup the buffers allocated in AP mode and
  1540. * give disconnect notification to stack, which usually
  1541. * happens in the disconnect_event. Simulate the disconnect
  1542. * event by calling the function directly. Sometimes
  1543. * disconnect_event will be received when the debug logs
  1544. * are collected.
  1545. */
  1546. ath6kl_wmi_shutdown(ar->wmi);
  1547. clear_bit(WMI_ENABLED, &ar->flag);
  1548. if (ar->htc_target) {
  1549. ath6kl_dbg(ATH6KL_DBG_TRC, "%s: shut down htc\n", __func__);
  1550. ath6kl_htc_stop(ar->htc_target);
  1551. }
  1552. /*
  1553. * Try to reset the device if we can. The driver may have been
  1554. * configure NOT to reset the target during a debug session.
  1555. */
  1556. ath6kl_init_hw_reset(ar);
  1557. up(&ar->sem);
  1558. }
  1559. EXPORT_SYMBOL(ath6kl_stop_txrx);