init.c 46 KB

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