init.c 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410
  1. /*
  2. * Copyright (c) 2011 Atheros Communications Inc.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include <linux/mmc/sdio_func.h>
  17. #include "core.h"
  18. #include "cfg80211.h"
  19. #include "target.h"
  20. #include "debug.h"
  21. #include "hif-ops.h"
  22. unsigned int debug_mask;
  23. static unsigned int testmode;
  24. module_param(debug_mask, uint, 0644);
  25. module_param(testmode, uint, 0644);
  26. /*
  27. * Include definitions here that can be used to tune the WLAN module
  28. * behavior. Different customers can tune the behavior as per their needs,
  29. * here.
  30. */
  31. /*
  32. * This configuration item enable/disable keepalive support.
  33. * Keepalive support: In the absence of any data traffic to AP, null
  34. * frames will be sent to the AP at periodic interval, to keep the association
  35. * active. This configuration item defines the periodic interval.
  36. * Use value of zero to disable keepalive support
  37. * Default: 60 seconds
  38. */
  39. #define WLAN_CONFIG_KEEP_ALIVE_INTERVAL 60
  40. /*
  41. * This configuration item sets the value of disconnect timeout
  42. * Firmware delays sending the disconnec event to the host for this
  43. * timeout after is gets disconnected from the current AP.
  44. * If the firmware successly roams within the disconnect timeout
  45. * it sends a new connect event
  46. */
  47. #define WLAN_CONFIG_DISCONNECT_TIMEOUT 10
  48. #define CONFIG_AR600x_DEBUG_UART_TX_PIN 8
  49. enum addr_type {
  50. DATASET_PATCH_ADDR,
  51. APP_LOAD_ADDR,
  52. APP_START_OVERRIDE_ADDR,
  53. };
  54. #define ATH6KL_DATA_OFFSET 64
  55. struct sk_buff *ath6kl_buf_alloc(int size)
  56. {
  57. struct sk_buff *skb;
  58. u16 reserved;
  59. /* Add chacheline space at front and back of buffer */
  60. reserved = (2 * L1_CACHE_BYTES) + ATH6KL_DATA_OFFSET +
  61. sizeof(struct htc_packet) + ATH6KL_HTC_ALIGN_BYTES;
  62. skb = dev_alloc_skb(size + reserved);
  63. if (skb)
  64. skb_reserve(skb, reserved - L1_CACHE_BYTES);
  65. return skb;
  66. }
  67. void ath6kl_init_profile_info(struct ath6kl *ar)
  68. {
  69. ar->ssid_len = 0;
  70. memset(ar->ssid, 0, sizeof(ar->ssid));
  71. ar->dot11_auth_mode = OPEN_AUTH;
  72. ar->auth_mode = NONE_AUTH;
  73. ar->prwise_crypto = NONE_CRYPT;
  74. ar->prwise_crypto_len = 0;
  75. ar->grp_crypto = NONE_CRYPT;
  76. ar->grp_crypto_len = 0;
  77. memset(ar->wep_key_list, 0, sizeof(ar->wep_key_list));
  78. memset(ar->req_bssid, 0, sizeof(ar->req_bssid));
  79. memset(ar->bssid, 0, sizeof(ar->bssid));
  80. ar->bss_ch = 0;
  81. ar->nw_type = ar->next_mode = INFRA_NETWORK;
  82. }
  83. static u8 ath6kl_get_fw_iftype(struct ath6kl *ar)
  84. {
  85. switch (ar->nw_type) {
  86. case INFRA_NETWORK:
  87. return HI_OPTION_FW_MODE_BSS_STA;
  88. case ADHOC_NETWORK:
  89. return HI_OPTION_FW_MODE_IBSS;
  90. case AP_NETWORK:
  91. return HI_OPTION_FW_MODE_AP;
  92. default:
  93. ath6kl_err("Unsupported interface type :%d\n", ar->nw_type);
  94. return 0xff;
  95. }
  96. }
  97. static int ath6kl_set_host_app_area(struct ath6kl *ar)
  98. {
  99. u32 address, data;
  100. struct host_app_area host_app_area;
  101. /* Fetch the address of the host_app_area_s
  102. * instance in the host interest area */
  103. address = ath6kl_get_hi_item_addr(ar, HI_ITEM(hi_app_host_interest));
  104. address = TARG_VTOP(ar->target_type, address);
  105. if (ath6kl_diag_read32(ar, address, &data))
  106. return -EIO;
  107. address = TARG_VTOP(ar->target_type, data);
  108. host_app_area.wmi_protocol_ver = WMI_PROTOCOL_VERSION;
  109. if (ath6kl_diag_write(ar, address, (u8 *) &host_app_area,
  110. sizeof(struct host_app_area)))
  111. return -EIO;
  112. return 0;
  113. }
  114. static inline void set_ac2_ep_map(struct ath6kl *ar,
  115. u8 ac,
  116. enum htc_endpoint_id ep)
  117. {
  118. ar->ac2ep_map[ac] = ep;
  119. ar->ep2ac_map[ep] = ac;
  120. }
  121. /* connect to a service */
  122. static int ath6kl_connectservice(struct ath6kl *ar,
  123. struct htc_service_connect_req *con_req,
  124. char *desc)
  125. {
  126. int status;
  127. struct htc_service_connect_resp response;
  128. memset(&response, 0, sizeof(response));
  129. status = ath6kl_htc_conn_service(ar->htc_target, con_req, &response);
  130. if (status) {
  131. ath6kl_err("failed to connect to %s service status:%d\n",
  132. desc, status);
  133. return status;
  134. }
  135. switch (con_req->svc_id) {
  136. case WMI_CONTROL_SVC:
  137. if (test_bit(WMI_ENABLED, &ar->flag))
  138. ath6kl_wmi_set_control_ep(ar->wmi, response.endpoint);
  139. ar->ctrl_ep = response.endpoint;
  140. break;
  141. case WMI_DATA_BE_SVC:
  142. set_ac2_ep_map(ar, WMM_AC_BE, response.endpoint);
  143. break;
  144. case WMI_DATA_BK_SVC:
  145. set_ac2_ep_map(ar, WMM_AC_BK, response.endpoint);
  146. break;
  147. case WMI_DATA_VI_SVC:
  148. set_ac2_ep_map(ar, WMM_AC_VI, response.endpoint);
  149. break;
  150. case WMI_DATA_VO_SVC:
  151. set_ac2_ep_map(ar, WMM_AC_VO, response.endpoint);
  152. break;
  153. default:
  154. ath6kl_err("service id is not mapped %d\n", con_req->svc_id);
  155. return -EINVAL;
  156. }
  157. return 0;
  158. }
  159. static int ath6kl_init_service_ep(struct ath6kl *ar)
  160. {
  161. struct htc_service_connect_req connect;
  162. memset(&connect, 0, sizeof(connect));
  163. /* these fields are the same for all service endpoints */
  164. connect.ep_cb.rx = ath6kl_rx;
  165. connect.ep_cb.rx_refill = ath6kl_rx_refill;
  166. connect.ep_cb.tx_full = ath6kl_tx_queue_full;
  167. /*
  168. * Set the max queue depth so that our ath6kl_tx_queue_full handler
  169. * gets called.
  170. */
  171. connect.max_txq_depth = MAX_DEFAULT_SEND_QUEUE_DEPTH;
  172. connect.ep_cb.rx_refill_thresh = ATH6KL_MAX_RX_BUFFERS / 4;
  173. if (!connect.ep_cb.rx_refill_thresh)
  174. connect.ep_cb.rx_refill_thresh++;
  175. /* connect to control service */
  176. connect.svc_id = WMI_CONTROL_SVC;
  177. if (ath6kl_connectservice(ar, &connect, "WMI CONTROL"))
  178. return -EIO;
  179. connect.flags |= HTC_FLGS_TX_BNDL_PAD_EN;
  180. /*
  181. * Limit the HTC message size on the send path, although e can
  182. * receive A-MSDU frames of 4K, we will only send ethernet-sized
  183. * (802.3) frames on the send path.
  184. */
  185. connect.max_rxmsg_sz = WMI_MAX_TX_DATA_FRAME_LENGTH;
  186. /*
  187. * To reduce the amount of committed memory for larger A_MSDU
  188. * frames, use the recv-alloc threshold mechanism for larger
  189. * packets.
  190. */
  191. connect.ep_cb.rx_alloc_thresh = ATH6KL_BUFFER_SIZE;
  192. connect.ep_cb.rx_allocthresh = ath6kl_alloc_amsdu_rxbuf;
  193. /*
  194. * For the remaining data services set the connection flag to
  195. * reduce dribbling, if configured to do so.
  196. */
  197. connect.conn_flags |= HTC_CONN_FLGS_REDUCE_CRED_DRIB;
  198. connect.conn_flags &= ~HTC_CONN_FLGS_THRESH_MASK;
  199. connect.conn_flags |= HTC_CONN_FLGS_THRESH_LVL_HALF;
  200. connect.svc_id = WMI_DATA_BE_SVC;
  201. if (ath6kl_connectservice(ar, &connect, "WMI DATA BE"))
  202. return -EIO;
  203. /* connect to back-ground map this to WMI LOW_PRI */
  204. connect.svc_id = WMI_DATA_BK_SVC;
  205. if (ath6kl_connectservice(ar, &connect, "WMI DATA BK"))
  206. return -EIO;
  207. /* connect to Video service, map this to to HI PRI */
  208. connect.svc_id = WMI_DATA_VI_SVC;
  209. if (ath6kl_connectservice(ar, &connect, "WMI DATA VI"))
  210. return -EIO;
  211. /*
  212. * Connect to VO service, this is currently not mapped to a WMI
  213. * priority stream due to historical reasons. WMI originally
  214. * defined 3 priorities over 3 mailboxes We can change this when
  215. * WMI is reworked so that priorities are not dependent on
  216. * mailboxes.
  217. */
  218. connect.svc_id = WMI_DATA_VO_SVC;
  219. if (ath6kl_connectservice(ar, &connect, "WMI DATA VO"))
  220. return -EIO;
  221. return 0;
  222. }
  223. static void ath6kl_init_control_info(struct ath6kl *ar)
  224. {
  225. u8 ctr;
  226. clear_bit(WMI_ENABLED, &ar->flag);
  227. ath6kl_init_profile_info(ar);
  228. ar->def_txkey_index = 0;
  229. memset(ar->wep_key_list, 0, sizeof(ar->wep_key_list));
  230. ar->ch_hint = 0;
  231. ar->listen_intvl_t = A_DEFAULT_LISTEN_INTERVAL;
  232. ar->listen_intvl_b = 0;
  233. ar->tx_pwr = 0;
  234. clear_bit(SKIP_SCAN, &ar->flag);
  235. set_bit(WMM_ENABLED, &ar->flag);
  236. ar->intra_bss = 1;
  237. memset(&ar->sc_params, 0, sizeof(ar->sc_params));
  238. ar->sc_params.short_scan_ratio = WMI_SHORTSCANRATIO_DEFAULT;
  239. ar->sc_params.scan_ctrl_flags = DEFAULT_SCAN_CTRL_FLAGS;
  240. ar->lrssi_roam_threshold = DEF_LRSSI_ROAM_THRESHOLD;
  241. memset((u8 *)ar->sta_list, 0,
  242. AP_MAX_NUM_STA * sizeof(struct ath6kl_sta));
  243. spin_lock_init(&ar->mcastpsq_lock);
  244. /* Init the PS queues */
  245. for (ctr = 0; ctr < AP_MAX_NUM_STA; ctr++) {
  246. spin_lock_init(&ar->sta_list[ctr].psq_lock);
  247. skb_queue_head_init(&ar->sta_list[ctr].psq);
  248. }
  249. skb_queue_head_init(&ar->mcastpsq);
  250. memcpy(ar->ap_country_code, DEF_AP_COUNTRY_CODE, 3);
  251. }
  252. /*
  253. * Set HTC/Mbox operational parameters, this can only be called when the
  254. * target is in the BMI phase.
  255. */
  256. static int ath6kl_set_htc_params(struct ath6kl *ar, u32 mbox_isr_yield_val,
  257. u8 htc_ctrl_buf)
  258. {
  259. int status;
  260. u32 blk_size;
  261. blk_size = ar->mbox_info.block_size;
  262. if (htc_ctrl_buf)
  263. blk_size |= ((u32)htc_ctrl_buf) << 16;
  264. /* set the host interest area for the block size */
  265. status = ath6kl_bmi_write(ar,
  266. ath6kl_get_hi_item_addr(ar,
  267. HI_ITEM(hi_mbox_io_block_sz)),
  268. (u8 *)&blk_size,
  269. 4);
  270. if (status) {
  271. ath6kl_err("bmi_write_memory for IO block size failed\n");
  272. goto out;
  273. }
  274. ath6kl_dbg(ATH6KL_DBG_TRC, "block size set: %d (target addr:0x%X)\n",
  275. blk_size,
  276. ath6kl_get_hi_item_addr(ar, HI_ITEM(hi_mbox_io_block_sz)));
  277. if (mbox_isr_yield_val) {
  278. /* set the host interest area for the mbox ISR yield limit */
  279. status = ath6kl_bmi_write(ar,
  280. ath6kl_get_hi_item_addr(ar,
  281. HI_ITEM(hi_mbox_isr_yield_limit)),
  282. (u8 *)&mbox_isr_yield_val,
  283. 4);
  284. if (status) {
  285. ath6kl_err("bmi_write_memory for yield limit failed\n");
  286. goto out;
  287. }
  288. }
  289. out:
  290. return status;
  291. }
  292. #define REG_DUMP_COUNT_AR6003 60
  293. #define REGISTER_DUMP_LEN_MAX 60
  294. static void ath6kl_dump_target_assert_info(struct ath6kl *ar)
  295. {
  296. u32 address;
  297. u32 regdump_loc = 0;
  298. int status;
  299. u32 regdump_val[REGISTER_DUMP_LEN_MAX];
  300. u32 i;
  301. if (ar->target_type != TARGET_TYPE_AR6003)
  302. return;
  303. /* the reg dump pointer is copied to the host interest area */
  304. address = ath6kl_get_hi_item_addr(ar, HI_ITEM(hi_failure_state));
  305. address = TARG_VTOP(ar->target_type, address);
  306. /* read RAM location through diagnostic window */
  307. status = ath6kl_diag_read32(ar, address, &regdump_loc);
  308. if (status || !regdump_loc) {
  309. ath6kl_err("failed to get ptr to register dump area\n");
  310. return;
  311. }
  312. ath6kl_dbg(ATH6KL_DBG_TRC, "location of register dump data: 0x%X\n",
  313. regdump_loc);
  314. regdump_loc = TARG_VTOP(ar->target_type, regdump_loc);
  315. /* fetch register dump data */
  316. status = ath6kl_diag_read(ar, regdump_loc, (u8 *)&regdump_val[0],
  317. REG_DUMP_COUNT_AR6003 * (sizeof(u32)));
  318. if (status) {
  319. ath6kl_err("failed to get register dump\n");
  320. return;
  321. }
  322. ath6kl_dbg(ATH6KL_DBG_TRC, "Register Dump:\n");
  323. for (i = 0; i < REG_DUMP_COUNT_AR6003; i++)
  324. ath6kl_dbg(ATH6KL_DBG_TRC, " %d : 0x%8.8X\n",
  325. i, regdump_val[i]);
  326. }
  327. void ath6kl_target_failure(struct ath6kl *ar)
  328. {
  329. ath6kl_err("target asserted\n");
  330. /* try dumping target assertion information (if any) */
  331. ath6kl_dump_target_assert_info(ar);
  332. }
  333. static int ath6kl_target_config_wlan_params(struct ath6kl *ar)
  334. {
  335. int status = 0;
  336. int ret;
  337. /*
  338. * Configure the device for rx dot11 header rules. "0,0" are the
  339. * default values. Required if checksum offload is needed. Set
  340. * RxMetaVersion to 2.
  341. */
  342. if (ath6kl_wmi_set_rx_frame_format_cmd(ar->wmi,
  343. ar->rx_meta_ver, 0, 0)) {
  344. ath6kl_err("unable to set the rx frame format\n");
  345. status = -EIO;
  346. }
  347. if (ar->conf_flags & ATH6KL_CONF_IGNORE_PS_FAIL_EVT_IN_SCAN)
  348. if ((ath6kl_wmi_pmparams_cmd(ar->wmi, 0, 1, 0, 0, 1,
  349. IGNORE_POWER_SAVE_FAIL_EVENT_DURING_SCAN)) != 0) {
  350. ath6kl_err("unable to set power save fail event policy\n");
  351. status = -EIO;
  352. }
  353. if (!(ar->conf_flags & ATH6KL_CONF_IGNORE_ERP_BARKER))
  354. if ((ath6kl_wmi_set_lpreamble_cmd(ar->wmi, 0,
  355. WMI_DONOT_IGNORE_BARKER_IN_ERP)) != 0) {
  356. ath6kl_err("unable to set barker preamble policy\n");
  357. status = -EIO;
  358. }
  359. if (ath6kl_wmi_set_keepalive_cmd(ar->wmi,
  360. WLAN_CONFIG_KEEP_ALIVE_INTERVAL)) {
  361. ath6kl_err("unable to set keep alive interval\n");
  362. status = -EIO;
  363. }
  364. if (ath6kl_wmi_disctimeout_cmd(ar->wmi,
  365. WLAN_CONFIG_DISCONNECT_TIMEOUT)) {
  366. ath6kl_err("unable to set disconnect timeout\n");
  367. status = -EIO;
  368. }
  369. if (!(ar->conf_flags & ATH6KL_CONF_ENABLE_TX_BURST))
  370. if (ath6kl_wmi_set_wmm_txop(ar->wmi, WMI_TXOP_DISABLED)) {
  371. ath6kl_err("unable to set txop bursting\n");
  372. status = -EIO;
  373. }
  374. if (ar->p2p) {
  375. ret = ath6kl_wmi_info_req_cmd(ar->wmi,
  376. P2P_FLAG_CAPABILITIES_REQ |
  377. P2P_FLAG_MACADDR_REQ |
  378. P2P_FLAG_HMODEL_REQ);
  379. if (ret) {
  380. ath6kl_dbg(ATH6KL_DBG_TRC, "failed to request P2P "
  381. "capabilities (%d) - assuming P2P not "
  382. "supported\n", ret);
  383. ar->p2p = 0;
  384. }
  385. }
  386. if (ar->p2p) {
  387. /* Enable Probe Request reporting for P2P */
  388. ret = ath6kl_wmi_probe_report_req_cmd(ar->wmi, true);
  389. if (ret) {
  390. ath6kl_dbg(ATH6KL_DBG_TRC, "failed to enable Probe "
  391. "Request reporting (%d)\n", ret);
  392. }
  393. }
  394. return status;
  395. }
  396. int ath6kl_configure_target(struct ath6kl *ar)
  397. {
  398. u32 param, ram_reserved_size;
  399. u8 fw_iftype;
  400. fw_iftype = ath6kl_get_fw_iftype(ar);
  401. if (fw_iftype == 0xff)
  402. return -EINVAL;
  403. /* Tell target which HTC version it is used*/
  404. param = HTC_PROTOCOL_VERSION;
  405. if (ath6kl_bmi_write(ar,
  406. ath6kl_get_hi_item_addr(ar,
  407. HI_ITEM(hi_app_host_interest)),
  408. (u8 *)&param, 4) != 0) {
  409. ath6kl_err("bmi_write_memory for htc version failed\n");
  410. return -EIO;
  411. }
  412. /* set the firmware mode to STA/IBSS/AP */
  413. param = 0;
  414. if (ath6kl_bmi_read(ar,
  415. ath6kl_get_hi_item_addr(ar,
  416. HI_ITEM(hi_option_flag)),
  417. (u8 *)&param, 4) != 0) {
  418. ath6kl_err("bmi_read_memory for setting fwmode failed\n");
  419. return -EIO;
  420. }
  421. param |= (1 << HI_OPTION_NUM_DEV_SHIFT);
  422. param |= (fw_iftype << HI_OPTION_FW_MODE_SHIFT);
  423. if (ar->p2p && fw_iftype == HI_OPTION_FW_MODE_BSS_STA) {
  424. param |= HI_OPTION_FW_SUBMODE_P2PDEV <<
  425. HI_OPTION_FW_SUBMODE_SHIFT;
  426. }
  427. param |= (0 << HI_OPTION_MAC_ADDR_METHOD_SHIFT);
  428. param |= (0 << HI_OPTION_FW_BRIDGE_SHIFT);
  429. if (ath6kl_bmi_write(ar,
  430. ath6kl_get_hi_item_addr(ar,
  431. HI_ITEM(hi_option_flag)),
  432. (u8 *)&param,
  433. 4) != 0) {
  434. ath6kl_err("bmi_write_memory for setting fwmode failed\n");
  435. return -EIO;
  436. }
  437. ath6kl_dbg(ATH6KL_DBG_TRC, "firmware mode set\n");
  438. /*
  439. * Hardcode the address use for the extended board data
  440. * Ideally this should be pre-allocate by the OS at boot time
  441. * But since it is a new feature and board data is loaded
  442. * at init time, we have to workaround this from host.
  443. * It is difficult to patch the firmware boot code,
  444. * but possible in theory.
  445. */
  446. if (ar->target_type == TARGET_TYPE_AR6003 ||
  447. ar->target_type == TARGET_TYPE_AR6004) {
  448. if (ar->version.target_ver == AR6003_REV2_VERSION) {
  449. param = AR6003_REV2_BOARD_EXT_DATA_ADDRESS;
  450. ram_reserved_size = AR6003_REV2_RAM_RESERVE_SIZE;
  451. } else if (ar->version.target_ver == AR6004_REV1_VERSION) {
  452. param = AR6004_REV1_BOARD_EXT_DATA_ADDRESS;
  453. ram_reserved_size = AR6004_REV1_RAM_RESERVE_SIZE;
  454. } else {
  455. param = AR6003_REV3_BOARD_EXT_DATA_ADDRESS;
  456. ram_reserved_size = AR6003_REV3_RAM_RESERVE_SIZE;
  457. }
  458. if (ath6kl_bmi_write(ar,
  459. ath6kl_get_hi_item_addr(ar,
  460. HI_ITEM(hi_board_ext_data)),
  461. (u8 *)&param, 4) != 0) {
  462. ath6kl_err("bmi_write_memory for hi_board_ext_data failed\n");
  463. return -EIO;
  464. }
  465. if (ath6kl_bmi_write(ar,
  466. ath6kl_get_hi_item_addr(ar,
  467. HI_ITEM(hi_end_ram_reserve_sz)),
  468. (u8 *)&ram_reserved_size, 4) != 0) {
  469. ath6kl_err("bmi_write_memory for hi_end_ram_reserve_sz failed\n");
  470. return -EIO;
  471. }
  472. }
  473. /* set the block size for the target */
  474. if (ath6kl_set_htc_params(ar, MBOX_YIELD_LIMIT, 0))
  475. /* use default number of control buffers */
  476. return -EIO;
  477. return 0;
  478. }
  479. struct ath6kl *ath6kl_core_alloc(struct device *sdev)
  480. {
  481. struct net_device *dev;
  482. struct ath6kl *ar;
  483. struct wireless_dev *wdev;
  484. wdev = ath6kl_cfg80211_init(sdev);
  485. if (!wdev) {
  486. ath6kl_err("ath6kl_cfg80211_init failed\n");
  487. return NULL;
  488. }
  489. ar = wdev_priv(wdev);
  490. ar->dev = sdev;
  491. ar->wdev = wdev;
  492. wdev->iftype = NL80211_IFTYPE_STATION;
  493. if (ath6kl_debug_init(ar)) {
  494. ath6kl_err("Failed to initialize debugfs\n");
  495. ath6kl_cfg80211_deinit(ar);
  496. return NULL;
  497. }
  498. dev = alloc_netdev(0, "wlan%d", ether_setup);
  499. if (!dev) {
  500. ath6kl_err("no memory for network device instance\n");
  501. ath6kl_cfg80211_deinit(ar);
  502. return NULL;
  503. }
  504. dev->ieee80211_ptr = wdev;
  505. SET_NETDEV_DEV(dev, wiphy_dev(wdev->wiphy));
  506. wdev->netdev = dev;
  507. ar->sme_state = SME_DISCONNECTED;
  508. ar->auto_auth_stage = AUTH_IDLE;
  509. init_netdev(dev);
  510. ar->net_dev = dev;
  511. set_bit(WLAN_ENABLED, &ar->flag);
  512. ar->wlan_pwr_state = WLAN_POWER_STATE_ON;
  513. spin_lock_init(&ar->lock);
  514. ath6kl_init_control_info(ar);
  515. init_waitqueue_head(&ar->event_wq);
  516. sema_init(&ar->sem, 1);
  517. clear_bit(DESTROY_IN_PROGRESS, &ar->flag);
  518. INIT_LIST_HEAD(&ar->amsdu_rx_buffer_queue);
  519. setup_timer(&ar->disconnect_timer, disconnect_timer_handler,
  520. (unsigned long) dev);
  521. return ar;
  522. }
  523. int ath6kl_unavail_ev(struct ath6kl *ar)
  524. {
  525. ath6kl_destroy(ar->net_dev, 1);
  526. return 0;
  527. }
  528. /* firmware upload */
  529. static u32 ath6kl_get_load_address(u32 target_ver, enum addr_type type)
  530. {
  531. WARN_ON(target_ver != AR6003_REV2_VERSION &&
  532. target_ver != AR6003_REV3_VERSION &&
  533. target_ver != AR6004_REV1_VERSION);
  534. switch (type) {
  535. case DATASET_PATCH_ADDR:
  536. return (target_ver == AR6003_REV2_VERSION) ?
  537. AR6003_REV2_DATASET_PATCH_ADDRESS :
  538. AR6003_REV3_DATASET_PATCH_ADDRESS;
  539. case APP_LOAD_ADDR:
  540. return (target_ver == AR6003_REV2_VERSION) ?
  541. AR6003_REV2_APP_LOAD_ADDRESS :
  542. 0x1234;
  543. case APP_START_OVERRIDE_ADDR:
  544. return (target_ver == AR6003_REV2_VERSION) ?
  545. AR6003_REV2_APP_START_OVERRIDE :
  546. AR6003_REV3_APP_START_OVERRIDE;
  547. default:
  548. return 0;
  549. }
  550. }
  551. static int ath6kl_get_fw(struct ath6kl *ar, const char *filename,
  552. u8 **fw, size_t *fw_len)
  553. {
  554. const struct firmware *fw_entry;
  555. int ret;
  556. ret = request_firmware(&fw_entry, filename, ar->dev);
  557. if (ret)
  558. return ret;
  559. *fw_len = fw_entry->size;
  560. *fw = kmemdup(fw_entry->data, fw_entry->size, GFP_KERNEL);
  561. if (*fw == NULL)
  562. ret = -ENOMEM;
  563. release_firmware(fw_entry);
  564. return ret;
  565. }
  566. static int ath6kl_fetch_board_file(struct ath6kl *ar)
  567. {
  568. const char *filename;
  569. int ret;
  570. switch (ar->version.target_ver) {
  571. case AR6003_REV2_VERSION:
  572. filename = AR6003_REV2_BOARD_DATA_FILE;
  573. break;
  574. case AR6004_REV1_VERSION:
  575. filename = AR6004_REV1_BOARD_DATA_FILE;
  576. break;
  577. default:
  578. filename = AR6003_REV3_BOARD_DATA_FILE;
  579. break;
  580. }
  581. ret = ath6kl_get_fw(ar, filename, &ar->fw_board,
  582. &ar->fw_board_len);
  583. if (ret == 0) {
  584. /* managed to get proper board file */
  585. return 0;
  586. }
  587. /* there was no proper board file, try to use default instead */
  588. ath6kl_warn("Failed to get board file %s (%d), trying to find default board file.\n",
  589. filename, ret);
  590. switch (ar->version.target_ver) {
  591. case AR6003_REV2_VERSION:
  592. filename = AR6003_REV2_DEFAULT_BOARD_DATA_FILE;
  593. break;
  594. case AR6004_REV1_VERSION:
  595. filename = AR6004_REV1_DEFAULT_BOARD_DATA_FILE;
  596. break;
  597. default:
  598. filename = AR6003_REV3_DEFAULT_BOARD_DATA_FILE;
  599. break;
  600. }
  601. ret = ath6kl_get_fw(ar, filename, &ar->fw_board,
  602. &ar->fw_board_len);
  603. if (ret) {
  604. ath6kl_err("Failed to get default board file %s: %d\n",
  605. filename, ret);
  606. return ret;
  607. }
  608. ath6kl_warn("WARNING! No proper board file was not found, instead using a default board file.\n");
  609. ath6kl_warn("Most likely your hardware won't work as specified. Install correct board file!\n");
  610. return 0;
  611. }
  612. static int ath6kl_upload_board_file(struct ath6kl *ar)
  613. {
  614. u32 board_address, board_ext_address, param;
  615. u32 board_data_size, board_ext_data_size;
  616. int ret;
  617. if (ar->fw_board == NULL) {
  618. ret = ath6kl_fetch_board_file(ar);
  619. if (ret)
  620. return ret;
  621. }
  622. /*
  623. * Determine where in Target RAM to write Board Data.
  624. * For AR6004, host determine Target RAM address for
  625. * writing board data.
  626. */
  627. if (ar->target_type == TARGET_TYPE_AR6004) {
  628. board_address = AR6004_REV1_BOARD_DATA_ADDRESS;
  629. ath6kl_bmi_write(ar,
  630. ath6kl_get_hi_item_addr(ar,
  631. HI_ITEM(hi_board_data)),
  632. (u8 *) &board_address, 4);
  633. } else {
  634. ath6kl_bmi_read(ar,
  635. ath6kl_get_hi_item_addr(ar,
  636. HI_ITEM(hi_board_data)),
  637. (u8 *) &board_address, 4);
  638. }
  639. ath6kl_dbg(ATH6KL_DBG_TRC, "board data download addr: 0x%x\n",
  640. board_address);
  641. /* determine where in target ram to write extended board data */
  642. ath6kl_bmi_read(ar,
  643. ath6kl_get_hi_item_addr(ar,
  644. HI_ITEM(hi_board_ext_data)),
  645. (u8 *) &board_ext_address, 4);
  646. ath6kl_dbg(ATH6KL_DBG_TRC, "board file download addr: 0x%x\n",
  647. board_ext_address);
  648. if (board_ext_address == 0) {
  649. ath6kl_err("Failed to get board file target address.\n");
  650. return -EINVAL;
  651. }
  652. switch (ar->target_type) {
  653. case TARGET_TYPE_AR6003:
  654. board_data_size = AR6003_BOARD_DATA_SZ;
  655. board_ext_data_size = AR6003_BOARD_EXT_DATA_SZ;
  656. break;
  657. case TARGET_TYPE_AR6004:
  658. board_data_size = AR6004_BOARD_DATA_SZ;
  659. board_ext_data_size = AR6004_BOARD_EXT_DATA_SZ;
  660. break;
  661. default:
  662. WARN_ON(1);
  663. return -EINVAL;
  664. break;
  665. }
  666. if (ar->fw_board_len == (board_data_size +
  667. board_ext_data_size)) {
  668. /* write extended board data */
  669. ret = ath6kl_bmi_write(ar, board_ext_address,
  670. ar->fw_board + board_data_size,
  671. board_ext_data_size);
  672. if (ret) {
  673. ath6kl_err("Failed to write extended board data: %d\n",
  674. ret);
  675. return ret;
  676. }
  677. /* record that extended board data is initialized */
  678. param = (board_ext_data_size << 16) | 1;
  679. ath6kl_bmi_write(ar,
  680. ath6kl_get_hi_item_addr(ar,
  681. HI_ITEM(hi_board_ext_data_config)),
  682. (unsigned char *) &param, 4);
  683. }
  684. if (ar->fw_board_len < board_data_size) {
  685. ath6kl_err("Too small board file: %zu\n", ar->fw_board_len);
  686. ret = -EINVAL;
  687. return ret;
  688. }
  689. ret = ath6kl_bmi_write(ar, board_address, ar->fw_board,
  690. board_data_size);
  691. if (ret) {
  692. ath6kl_err("Board file bmi write failed: %d\n", ret);
  693. return ret;
  694. }
  695. /* record the fact that Board Data IS initialized */
  696. param = 1;
  697. ath6kl_bmi_write(ar,
  698. ath6kl_get_hi_item_addr(ar,
  699. HI_ITEM(hi_board_data_initialized)),
  700. (u8 *)&param, 4);
  701. return ret;
  702. }
  703. static int ath6kl_upload_otp(struct ath6kl *ar)
  704. {
  705. const char *filename;
  706. u32 address, param;
  707. int ret;
  708. switch (ar->version.target_ver) {
  709. case AR6003_REV2_VERSION:
  710. filename = AR6003_REV2_OTP_FILE;
  711. break;
  712. case AR6004_REV1_VERSION:
  713. ath6kl_dbg(ATH6KL_DBG_TRC, "AR6004 doesn't need OTP file\n");
  714. return 0;
  715. break;
  716. default:
  717. filename = AR6003_REV3_OTP_FILE;
  718. break;
  719. }
  720. if (ar->fw_otp == NULL) {
  721. ret = ath6kl_get_fw(ar, filename, &ar->fw_otp,
  722. &ar->fw_otp_len);
  723. if (ret) {
  724. ath6kl_err("Failed to get OTP file %s: %d\n",
  725. filename, ret);
  726. return ret;
  727. }
  728. }
  729. address = ath6kl_get_load_address(ar->version.target_ver,
  730. APP_LOAD_ADDR);
  731. ret = ath6kl_bmi_fast_download(ar, address, ar->fw_otp,
  732. ar->fw_otp_len);
  733. if (ret) {
  734. ath6kl_err("Failed to upload OTP file: %d\n", ret);
  735. return ret;
  736. }
  737. /* execute the OTP code */
  738. param = 0;
  739. address = ath6kl_get_load_address(ar->version.target_ver,
  740. APP_START_OVERRIDE_ADDR);
  741. ath6kl_bmi_execute(ar, address, &param);
  742. return ret;
  743. }
  744. static int ath6kl_upload_firmware(struct ath6kl *ar)
  745. {
  746. const char *filename;
  747. u32 address;
  748. int ret;
  749. if (testmode) {
  750. switch (ar->version.target_ver) {
  751. case AR6003_REV2_VERSION:
  752. filename = AR6003_REV2_TCMD_FIRMWARE_FILE;
  753. break;
  754. case AR6003_REV3_VERSION:
  755. filename = AR6003_REV3_TCMD_FIRMWARE_FILE;
  756. break;
  757. case AR6004_REV1_VERSION:
  758. ath6kl_warn("testmode not supported with ar6004\n");
  759. return -EOPNOTSUPP;
  760. default:
  761. ath6kl_warn("unknown target version: 0x%x\n",
  762. ar->version.target_ver);
  763. return -EINVAL;
  764. }
  765. set_bit(TESTMODE, &ar->flag);
  766. goto get_fw;
  767. }
  768. switch (ar->version.target_ver) {
  769. case AR6003_REV2_VERSION:
  770. filename = AR6003_REV2_FIRMWARE_FILE;
  771. break;
  772. case AR6004_REV1_VERSION:
  773. filename = AR6004_REV1_FIRMWARE_FILE;
  774. break;
  775. default:
  776. filename = AR6003_REV3_FIRMWARE_FILE;
  777. break;
  778. }
  779. get_fw:
  780. if (ar->fw == NULL) {
  781. ret = ath6kl_get_fw(ar, filename, &ar->fw, &ar->fw_len);
  782. if (ret) {
  783. ath6kl_err("Failed to get firmware file %s: %d\n",
  784. filename, ret);
  785. return ret;
  786. }
  787. }
  788. address = ath6kl_get_load_address(ar->version.target_ver,
  789. APP_LOAD_ADDR);
  790. ret = ath6kl_bmi_fast_download(ar, address, ar->fw, ar->fw_len);
  791. if (ret) {
  792. ath6kl_err("Failed to write firmware: %d\n", ret);
  793. return ret;
  794. }
  795. /*
  796. * Set starting address for firmware
  797. * Don't need to setup app_start override addr on AR6004
  798. */
  799. if (ar->target_type != TARGET_TYPE_AR6004) {
  800. address = ath6kl_get_load_address(ar->version.target_ver,
  801. APP_START_OVERRIDE_ADDR);
  802. ath6kl_bmi_set_app_start(ar, address);
  803. }
  804. return ret;
  805. }
  806. static int ath6kl_upload_patch(struct ath6kl *ar)
  807. {
  808. const char *filename;
  809. u32 address, param;
  810. int ret;
  811. switch (ar->version.target_ver) {
  812. case AR6003_REV2_VERSION:
  813. filename = AR6003_REV2_PATCH_FILE;
  814. break;
  815. case AR6004_REV1_VERSION:
  816. /* FIXME: implement for AR6004 */
  817. return 0;
  818. break;
  819. default:
  820. filename = AR6003_REV3_PATCH_FILE;
  821. break;
  822. }
  823. if (ar->fw_patch == NULL) {
  824. ret = ath6kl_get_fw(ar, filename, &ar->fw_patch,
  825. &ar->fw_patch_len);
  826. if (ret) {
  827. ath6kl_err("Failed to get patch file %s: %d\n",
  828. filename, ret);
  829. return ret;
  830. }
  831. }
  832. address = ath6kl_get_load_address(ar->version.target_ver,
  833. DATASET_PATCH_ADDR);
  834. ret = ath6kl_bmi_write(ar, address, ar->fw_patch, ar->fw_patch_len);
  835. if (ret) {
  836. ath6kl_err("Failed to write patch file: %d\n", ret);
  837. return ret;
  838. }
  839. param = address;
  840. ath6kl_bmi_write(ar,
  841. ath6kl_get_hi_item_addr(ar,
  842. HI_ITEM(hi_dset_list_head)),
  843. (unsigned char *) &param, 4);
  844. return 0;
  845. }
  846. static int ath6kl_init_upload(struct ath6kl *ar)
  847. {
  848. u32 param, options, sleep, address;
  849. int status = 0;
  850. if (ar->target_type != TARGET_TYPE_AR6003 &&
  851. ar->target_type != TARGET_TYPE_AR6004)
  852. return -EINVAL;
  853. /* temporarily disable system sleep */
  854. address = MBOX_BASE_ADDRESS + LOCAL_SCRATCH_ADDRESS;
  855. status = ath6kl_bmi_reg_read(ar, address, &param);
  856. if (status)
  857. return status;
  858. options = param;
  859. param |= ATH6KL_OPTION_SLEEP_DISABLE;
  860. status = ath6kl_bmi_reg_write(ar, address, param);
  861. if (status)
  862. return status;
  863. address = RTC_BASE_ADDRESS + SYSTEM_SLEEP_ADDRESS;
  864. status = ath6kl_bmi_reg_read(ar, address, &param);
  865. if (status)
  866. return status;
  867. sleep = param;
  868. param |= SM(SYSTEM_SLEEP_DISABLE, 1);
  869. status = ath6kl_bmi_reg_write(ar, address, param);
  870. if (status)
  871. return status;
  872. ath6kl_dbg(ATH6KL_DBG_TRC, "old options: %d, old sleep: %d\n",
  873. options, sleep);
  874. /* program analog PLL register */
  875. /* no need to control 40/44MHz clock on AR6004 */
  876. if (ar->target_type != TARGET_TYPE_AR6004) {
  877. status = ath6kl_bmi_reg_write(ar, ATH6KL_ANALOG_PLL_REGISTER,
  878. 0xF9104001);
  879. if (status)
  880. return status;
  881. /* Run at 80/88MHz by default */
  882. param = SM(CPU_CLOCK_STANDARD, 1);
  883. address = RTC_BASE_ADDRESS + CPU_CLOCK_ADDRESS;
  884. status = ath6kl_bmi_reg_write(ar, address, param);
  885. if (status)
  886. return status;
  887. }
  888. param = 0;
  889. address = RTC_BASE_ADDRESS + LPO_CAL_ADDRESS;
  890. param = SM(LPO_CAL_ENABLE, 1);
  891. status = ath6kl_bmi_reg_write(ar, address, param);
  892. if (status)
  893. return status;
  894. /* WAR to avoid SDIO CRC err */
  895. if (ar->version.target_ver == AR6003_REV2_VERSION) {
  896. ath6kl_err("temporary war to avoid sdio crc error\n");
  897. param = 0x20;
  898. address = GPIO_BASE_ADDRESS + GPIO_PIN10_ADDRESS;
  899. status = ath6kl_bmi_reg_write(ar, address, param);
  900. if (status)
  901. return status;
  902. address = GPIO_BASE_ADDRESS + GPIO_PIN11_ADDRESS;
  903. status = ath6kl_bmi_reg_write(ar, address, param);
  904. if (status)
  905. return status;
  906. address = GPIO_BASE_ADDRESS + GPIO_PIN12_ADDRESS;
  907. status = ath6kl_bmi_reg_write(ar, address, param);
  908. if (status)
  909. return status;
  910. address = GPIO_BASE_ADDRESS + GPIO_PIN13_ADDRESS;
  911. status = ath6kl_bmi_reg_write(ar, address, param);
  912. if (status)
  913. return status;
  914. }
  915. /* write EEPROM data to Target RAM */
  916. status = ath6kl_upload_board_file(ar);
  917. if (status)
  918. return status;
  919. /* transfer One time Programmable data */
  920. status = ath6kl_upload_otp(ar);
  921. if (status)
  922. return status;
  923. /* Download Target firmware */
  924. status = ath6kl_upload_firmware(ar);
  925. if (status)
  926. return status;
  927. status = ath6kl_upload_patch(ar);
  928. if (status)
  929. return status;
  930. /* Restore system sleep */
  931. address = RTC_BASE_ADDRESS + SYSTEM_SLEEP_ADDRESS;
  932. status = ath6kl_bmi_reg_write(ar, address, sleep);
  933. if (status)
  934. return status;
  935. address = MBOX_BASE_ADDRESS + LOCAL_SCRATCH_ADDRESS;
  936. param = options | 0x20;
  937. status = ath6kl_bmi_reg_write(ar, address, param);
  938. if (status)
  939. return status;
  940. /* Configure GPIO AR6003 UART */
  941. param = CONFIG_AR600x_DEBUG_UART_TX_PIN;
  942. status = ath6kl_bmi_write(ar,
  943. ath6kl_get_hi_item_addr(ar,
  944. HI_ITEM(hi_dbg_uart_txpin)),
  945. (u8 *)&param, 4);
  946. return status;
  947. }
  948. static int ath6kl_init(struct net_device *dev)
  949. {
  950. struct ath6kl *ar = ath6kl_priv(dev);
  951. int status = 0;
  952. s32 timeleft;
  953. if (!ar)
  954. return -EIO;
  955. /* Do we need to finish the BMI phase */
  956. if (ath6kl_bmi_done(ar)) {
  957. status = -EIO;
  958. goto ath6kl_init_done;
  959. }
  960. /* Indicate that WMI is enabled (although not ready yet) */
  961. set_bit(WMI_ENABLED, &ar->flag);
  962. ar->wmi = ath6kl_wmi_init(ar);
  963. if (!ar->wmi) {
  964. ath6kl_err("failed to initialize wmi\n");
  965. status = -EIO;
  966. goto ath6kl_init_done;
  967. }
  968. ath6kl_dbg(ATH6KL_DBG_TRC, "%s: got wmi @ 0x%p.\n", __func__, ar->wmi);
  969. wlan_node_table_init(&ar->scan_table);
  970. /*
  971. * The reason we have to wait for the target here is that the
  972. * driver layer has to init BMI in order to set the host block
  973. * size.
  974. */
  975. if (ath6kl_htc_wait_target(ar->htc_target)) {
  976. status = -EIO;
  977. goto err_node_cleanup;
  978. }
  979. if (ath6kl_init_service_ep(ar)) {
  980. status = -EIO;
  981. goto err_cleanup_scatter;
  982. }
  983. /* setup access class priority mappings */
  984. ar->ac_stream_pri_map[WMM_AC_BK] = 0; /* lowest */
  985. ar->ac_stream_pri_map[WMM_AC_BE] = 1;
  986. ar->ac_stream_pri_map[WMM_AC_VI] = 2;
  987. ar->ac_stream_pri_map[WMM_AC_VO] = 3; /* highest */
  988. /* give our connected endpoints some buffers */
  989. ath6kl_rx_refill(ar->htc_target, ar->ctrl_ep);
  990. ath6kl_rx_refill(ar->htc_target, ar->ac2ep_map[WMM_AC_BE]);
  991. /* allocate some buffers that handle larger AMSDU frames */
  992. ath6kl_refill_amsdu_rxbufs(ar, ATH6KL_MAX_AMSDU_RX_BUFFERS);
  993. /* setup credit distribution */
  994. ath6k_setup_credit_dist(ar->htc_target, &ar->credit_state_info);
  995. ath6kl_cookie_init(ar);
  996. /* start HTC */
  997. status = ath6kl_htc_start(ar->htc_target);
  998. if (status) {
  999. ath6kl_cookie_cleanup(ar);
  1000. goto err_rxbuf_cleanup;
  1001. }
  1002. /* Wait for Wmi event to be ready */
  1003. timeleft = wait_event_interruptible_timeout(ar->event_wq,
  1004. test_bit(WMI_READY,
  1005. &ar->flag),
  1006. WMI_TIMEOUT);
  1007. if (ar->version.abi_ver != ATH6KL_ABI_VERSION) {
  1008. ath6kl_err("abi version mismatch: host(0x%x), target(0x%x)\n",
  1009. ATH6KL_ABI_VERSION, ar->version.abi_ver);
  1010. status = -EIO;
  1011. goto err_htc_stop;
  1012. }
  1013. if (!timeleft || signal_pending(current)) {
  1014. ath6kl_err("wmi is not ready or wait was interrupted\n");
  1015. status = -EIO;
  1016. goto err_htc_stop;
  1017. }
  1018. ath6kl_dbg(ATH6KL_DBG_TRC, "%s: wmi is ready\n", __func__);
  1019. /* communicate the wmi protocol verision to the target */
  1020. if ((ath6kl_set_host_app_area(ar)) != 0)
  1021. ath6kl_err("unable to set the host app area\n");
  1022. ar->conf_flags = ATH6KL_CONF_IGNORE_ERP_BARKER |
  1023. ATH6KL_CONF_ENABLE_11N | ATH6KL_CONF_ENABLE_TX_BURST;
  1024. status = ath6kl_target_config_wlan_params(ar);
  1025. if (!status)
  1026. goto ath6kl_init_done;
  1027. err_htc_stop:
  1028. ath6kl_htc_stop(ar->htc_target);
  1029. err_rxbuf_cleanup:
  1030. ath6kl_htc_flush_rx_buf(ar->htc_target);
  1031. ath6kl_cleanup_amsdu_rxbufs(ar);
  1032. err_cleanup_scatter:
  1033. ath6kl_hif_cleanup_scatter(ar);
  1034. err_node_cleanup:
  1035. wlan_node_table_cleanup(&ar->scan_table);
  1036. ath6kl_wmi_shutdown(ar->wmi);
  1037. clear_bit(WMI_ENABLED, &ar->flag);
  1038. ar->wmi = NULL;
  1039. ath6kl_init_done:
  1040. return status;
  1041. }
  1042. int ath6kl_core_init(struct ath6kl *ar)
  1043. {
  1044. int ret = 0;
  1045. struct ath6kl_bmi_target_info targ_info;
  1046. ar->ath6kl_wq = create_singlethread_workqueue("ath6kl");
  1047. if (!ar->ath6kl_wq)
  1048. return -ENOMEM;
  1049. ret = ath6kl_bmi_init(ar);
  1050. if (ret)
  1051. goto err_wq;
  1052. ret = ath6kl_bmi_get_target_info(ar, &targ_info);
  1053. if (ret)
  1054. goto err_bmi_cleanup;
  1055. ar->version.target_ver = le32_to_cpu(targ_info.version);
  1056. ar->target_type = le32_to_cpu(targ_info.type);
  1057. ar->wdev->wiphy->hw_version = le32_to_cpu(targ_info.version);
  1058. ret = ath6kl_configure_target(ar);
  1059. if (ret)
  1060. goto err_bmi_cleanup;
  1061. ar->htc_target = ath6kl_htc_create(ar);
  1062. if (!ar->htc_target) {
  1063. ret = -ENOMEM;
  1064. goto err_bmi_cleanup;
  1065. }
  1066. ar->aggr_cntxt = aggr_init(ar->net_dev);
  1067. if (!ar->aggr_cntxt) {
  1068. ath6kl_err("failed to initialize aggr\n");
  1069. ret = -ENOMEM;
  1070. goto err_htc_cleanup;
  1071. }
  1072. ret = ath6kl_init_upload(ar);
  1073. if (ret)
  1074. goto err_htc_cleanup;
  1075. ret = ath6kl_init(ar->net_dev);
  1076. if (ret)
  1077. goto err_htc_cleanup;
  1078. /* This runs the init function if registered */
  1079. ret = register_netdev(ar->net_dev);
  1080. if (ret) {
  1081. ath6kl_err("register_netdev failed\n");
  1082. ath6kl_destroy(ar->net_dev, 0);
  1083. return ret;
  1084. }
  1085. set_bit(NETDEV_REGISTERED, &ar->flag);
  1086. ath6kl_dbg(ATH6KL_DBG_TRC, "%s: name=%s dev=0x%p, ar=0x%p\n",
  1087. __func__, ar->net_dev->name, ar->net_dev, ar);
  1088. return ret;
  1089. err_htc_cleanup:
  1090. ath6kl_htc_cleanup(ar->htc_target);
  1091. err_bmi_cleanup:
  1092. ath6kl_bmi_cleanup(ar);
  1093. err_wq:
  1094. destroy_workqueue(ar->ath6kl_wq);
  1095. return ret;
  1096. }
  1097. void ath6kl_stop_txrx(struct ath6kl *ar)
  1098. {
  1099. struct net_device *ndev = ar->net_dev;
  1100. if (!ndev)
  1101. return;
  1102. set_bit(DESTROY_IN_PROGRESS, &ar->flag);
  1103. if (down_interruptible(&ar->sem)) {
  1104. ath6kl_err("down_interruptible failed\n");
  1105. return;
  1106. }
  1107. if (ar->wlan_pwr_state != WLAN_POWER_STATE_CUT_PWR)
  1108. ath6kl_stop_endpoint(ndev, false, true);
  1109. clear_bit(WLAN_ENABLED, &ar->flag);
  1110. }
  1111. /*
  1112. * We need to differentiate between the surprise and planned removal of the
  1113. * device because of the following consideration:
  1114. *
  1115. * - In case of surprise removal, the hcd already frees up the pending
  1116. * for the device and hence there is no need to unregister the function
  1117. * driver inorder to get these requests. For planned removal, the function
  1118. * driver has to explicitly unregister itself to have the hcd return all the
  1119. * pending requests before the data structures for the devices are freed up.
  1120. * Note that as per the current implementation, the function driver will
  1121. * end up releasing all the devices since there is no API to selectively
  1122. * release a particular device.
  1123. *
  1124. * - Certain commands issued to the target can be skipped for surprise
  1125. * removal since they will anyway not go through.
  1126. */
  1127. void ath6kl_destroy(struct net_device *dev, unsigned int unregister)
  1128. {
  1129. struct ath6kl *ar;
  1130. if (!dev || !ath6kl_priv(dev)) {
  1131. ath6kl_err("failed to get device structure\n");
  1132. return;
  1133. }
  1134. ar = ath6kl_priv(dev);
  1135. destroy_workqueue(ar->ath6kl_wq);
  1136. if (ar->htc_target)
  1137. ath6kl_htc_cleanup(ar->htc_target);
  1138. aggr_module_destroy(ar->aggr_cntxt);
  1139. ath6kl_cookie_cleanup(ar);
  1140. ath6kl_cleanup_amsdu_rxbufs(ar);
  1141. ath6kl_bmi_cleanup(ar);
  1142. ath6kl_debug_cleanup(ar);
  1143. if (unregister && test_bit(NETDEV_REGISTERED, &ar->flag)) {
  1144. unregister_netdev(dev);
  1145. clear_bit(NETDEV_REGISTERED, &ar->flag);
  1146. }
  1147. free_netdev(dev);
  1148. wlan_node_table_cleanup(&ar->scan_table);
  1149. kfree(ar->fw_board);
  1150. kfree(ar->fw_otp);
  1151. kfree(ar->fw);
  1152. kfree(ar->fw_patch);
  1153. ath6kl_cfg80211_deinit(ar);
  1154. }