init.c 41 KB

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