init.c 41 KB

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