init.c 47 KB

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