init.c 40 KB

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