cmdevt.c 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * NXP Wireless LAN device driver: commands and events
  4. *
  5. * Copyright 2011-2020 NXP
  6. */
  7. #include <asm/unaligned.h>
  8. #include "decl.h"
  9. #include "ioctl.h"
  10. #include "util.h"
  11. #include "fw.h"
  12. #include "main.h"
  13. #include "wmm.h"
  14. #include "11n.h"
  15. static void mwifiex_cancel_pending_ioctl(struct mwifiex_adapter *adapter);
  16. /*
  17. * This function initializes a command node.
  18. *
  19. * The actual allocation of the node is not done by this function. It only
  20. * initiates a node by filling it with default parameters. Similarly,
  21. * allocation of the different buffers used (IOCTL buffer, data buffer) are
  22. * not done by this function either.
  23. */
  24. static void
  25. mwifiex_init_cmd_node(struct mwifiex_private *priv,
  26. struct cmd_ctrl_node *cmd_node,
  27. u32 cmd_no, void *data_buf, bool sync)
  28. {
  29. cmd_node->priv = priv;
  30. cmd_node->cmd_no = cmd_no;
  31. if (sync) {
  32. cmd_node->wait_q_enabled = true;
  33. cmd_node->cmd_wait_q_woken = false;
  34. cmd_node->condition = &cmd_node->cmd_wait_q_woken;
  35. }
  36. cmd_node->data_buf = data_buf;
  37. cmd_node->cmd_skb = cmd_node->skb;
  38. }
  39. /*
  40. * This function returns a command node from the free queue depending upon
  41. * availability.
  42. */
  43. static struct cmd_ctrl_node *
  44. mwifiex_get_cmd_node(struct mwifiex_adapter *adapter)
  45. {
  46. struct cmd_ctrl_node *cmd_node;
  47. spin_lock_bh(&adapter->cmd_free_q_lock);
  48. if (list_empty(&adapter->cmd_free_q)) {
  49. mwifiex_dbg(adapter, ERROR,
  50. "GET_CMD_NODE: cmd node not available\n");
  51. spin_unlock_bh(&adapter->cmd_free_q_lock);
  52. return NULL;
  53. }
  54. cmd_node = list_first_entry(&adapter->cmd_free_q,
  55. struct cmd_ctrl_node, list);
  56. list_del(&cmd_node->list);
  57. spin_unlock_bh(&adapter->cmd_free_q_lock);
  58. return cmd_node;
  59. }
  60. /*
  61. * This function cleans up a command node.
  62. *
  63. * The function resets the fields including the buffer pointers.
  64. * This function does not try to free the buffers. They must be
  65. * freed before calling this function.
  66. *
  67. * This function will however call the receive completion callback
  68. * in case a response buffer is still available before resetting
  69. * the pointer.
  70. */
  71. static void
  72. mwifiex_clean_cmd_node(struct mwifiex_adapter *adapter,
  73. struct cmd_ctrl_node *cmd_node)
  74. {
  75. cmd_node->cmd_no = 0;
  76. cmd_node->cmd_flag = 0;
  77. cmd_node->data_buf = NULL;
  78. cmd_node->wait_q_enabled = false;
  79. if (cmd_node->cmd_skb)
  80. skb_trim(cmd_node->cmd_skb, 0);
  81. if (cmd_node->resp_skb) {
  82. adapter->if_ops.cmdrsp_complete(adapter, cmd_node->resp_skb);
  83. cmd_node->resp_skb = NULL;
  84. }
  85. }
  86. /*
  87. * This function returns a command to the command free queue.
  88. *
  89. * The function also calls the completion callback if required, before
  90. * cleaning the command node and re-inserting it into the free queue.
  91. */
  92. static void
  93. mwifiex_insert_cmd_to_free_q(struct mwifiex_adapter *adapter,
  94. struct cmd_ctrl_node *cmd_node)
  95. {
  96. if (!cmd_node)
  97. return;
  98. if (cmd_node->wait_q_enabled)
  99. mwifiex_complete_cmd(adapter, cmd_node);
  100. /* Clean the node */
  101. mwifiex_clean_cmd_node(adapter, cmd_node);
  102. /* Insert node into cmd_free_q */
  103. spin_lock_bh(&adapter->cmd_free_q_lock);
  104. list_add_tail(&cmd_node->list, &adapter->cmd_free_q);
  105. spin_unlock_bh(&adapter->cmd_free_q_lock);
  106. }
  107. /* This function reuses a command node. */
  108. void mwifiex_recycle_cmd_node(struct mwifiex_adapter *adapter,
  109. struct cmd_ctrl_node *cmd_node)
  110. {
  111. struct host_cmd_ds_command *host_cmd = (void *)cmd_node->cmd_skb->data;
  112. mwifiex_insert_cmd_to_free_q(adapter, cmd_node);
  113. atomic_dec(&adapter->cmd_pending);
  114. mwifiex_dbg(adapter, CMD,
  115. "cmd: FREE_CMD: cmd=%#x, cmd_pending=%d\n",
  116. le16_to_cpu(host_cmd->command),
  117. atomic_read(&adapter->cmd_pending));
  118. }
  119. /*
  120. * This function sends a host command to the firmware.
  121. *
  122. * The function copies the host command into the driver command
  123. * buffer, which will be transferred to the firmware later by the
  124. * main thread.
  125. */
  126. static int mwifiex_cmd_host_cmd(struct mwifiex_private *priv,
  127. struct host_cmd_ds_command *cmd,
  128. struct mwifiex_ds_misc_cmd *pcmd_ptr)
  129. {
  130. /* Copy the HOST command to command buffer */
  131. memcpy(cmd, pcmd_ptr->cmd, pcmd_ptr->len);
  132. mwifiex_dbg(priv->adapter, CMD,
  133. "cmd: host cmd size = %d\n", pcmd_ptr->len);
  134. return 0;
  135. }
  136. /*
  137. * This function downloads a command to the firmware.
  138. *
  139. * The function performs sanity tests, sets the command sequence
  140. * number and size, converts the header fields to CPU format before
  141. * sending. Afterwards, it logs the command ID and action for debugging
  142. * and sets up the command timeout timer.
  143. */
  144. static int mwifiex_dnld_cmd_to_fw(struct mwifiex_private *priv,
  145. struct cmd_ctrl_node *cmd_node)
  146. {
  147. struct mwifiex_adapter *adapter = priv->adapter;
  148. int ret;
  149. struct host_cmd_ds_command *host_cmd;
  150. uint16_t cmd_code;
  151. uint16_t cmd_size;
  152. if (!adapter || !cmd_node)
  153. return -1;
  154. host_cmd = (struct host_cmd_ds_command *) (cmd_node->cmd_skb->data);
  155. /* Sanity test */
  156. if (host_cmd->size == 0) {
  157. mwifiex_dbg(adapter, ERROR,
  158. "DNLD_CMD: host_cmd is null\t"
  159. "or cmd size is 0, not sending\n");
  160. if (cmd_node->wait_q_enabled)
  161. adapter->cmd_wait_q.status = -1;
  162. mwifiex_recycle_cmd_node(adapter, cmd_node);
  163. return -1;
  164. }
  165. cmd_code = le16_to_cpu(host_cmd->command);
  166. cmd_node->cmd_no = cmd_code;
  167. cmd_size = le16_to_cpu(host_cmd->size);
  168. if (adapter->hw_status == MWIFIEX_HW_STATUS_RESET &&
  169. cmd_code != HostCmd_CMD_FUNC_SHUTDOWN &&
  170. cmd_code != HostCmd_CMD_FUNC_INIT) {
  171. mwifiex_dbg(adapter, ERROR,
  172. "DNLD_CMD: FW in reset state, ignore cmd %#x\n",
  173. cmd_code);
  174. mwifiex_recycle_cmd_node(adapter, cmd_node);
  175. queue_work(adapter->workqueue, &adapter->main_work);
  176. return -1;
  177. }
  178. /* Set command sequence number */
  179. adapter->seq_num++;
  180. host_cmd->seq_num = cpu_to_le16(HostCmd_SET_SEQ_NO_BSS_INFO
  181. (adapter->seq_num,
  182. cmd_node->priv->bss_num,
  183. cmd_node->priv->bss_type));
  184. spin_lock_bh(&adapter->mwifiex_cmd_lock);
  185. adapter->curr_cmd = cmd_node;
  186. spin_unlock_bh(&adapter->mwifiex_cmd_lock);
  187. /* Adjust skb length */
  188. if (cmd_node->cmd_skb->len > cmd_size)
  189. /*
  190. * cmd_size is less than sizeof(struct host_cmd_ds_command).
  191. * Trim off the unused portion.
  192. */
  193. skb_trim(cmd_node->cmd_skb, cmd_size);
  194. else if (cmd_node->cmd_skb->len < cmd_size)
  195. /*
  196. * cmd_size is larger than sizeof(struct host_cmd_ds_command)
  197. * because we have appended custom IE TLV. Increase skb length
  198. * accordingly.
  199. */
  200. skb_put(cmd_node->cmd_skb, cmd_size - cmd_node->cmd_skb->len);
  201. mwifiex_dbg(adapter, CMD,
  202. "cmd: DNLD_CMD: %#x, act %#x, len %d, seqno %#x\n",
  203. cmd_code,
  204. get_unaligned_le16((u8 *)host_cmd + S_DS_GEN),
  205. cmd_size, le16_to_cpu(host_cmd->seq_num));
  206. mwifiex_dbg_dump(adapter, CMD_D, "cmd buffer:", host_cmd, cmd_size);
  207. if (adapter->iface_type == MWIFIEX_USB) {
  208. skb_push(cmd_node->cmd_skb, MWIFIEX_TYPE_LEN);
  209. put_unaligned_le32(MWIFIEX_USB_TYPE_CMD,
  210. cmd_node->cmd_skb->data);
  211. adapter->cmd_sent = true;
  212. ret = adapter->if_ops.host_to_card(adapter,
  213. MWIFIEX_USB_EP_CMD_EVENT,
  214. cmd_node->cmd_skb, NULL);
  215. skb_pull(cmd_node->cmd_skb, MWIFIEX_TYPE_LEN);
  216. if (ret == -EBUSY)
  217. cmd_node->cmd_skb = NULL;
  218. } else {
  219. skb_push(cmd_node->cmd_skb, adapter->intf_hdr_len);
  220. ret = adapter->if_ops.host_to_card(adapter, MWIFIEX_TYPE_CMD,
  221. cmd_node->cmd_skb, NULL);
  222. skb_pull(cmd_node->cmd_skb, adapter->intf_hdr_len);
  223. }
  224. if (ret == -1) {
  225. mwifiex_dbg(adapter, ERROR,
  226. "DNLD_CMD: host to card failed\n");
  227. if (adapter->iface_type == MWIFIEX_USB)
  228. adapter->cmd_sent = false;
  229. if (cmd_node->wait_q_enabled)
  230. adapter->cmd_wait_q.status = -1;
  231. mwifiex_recycle_cmd_node(adapter, adapter->curr_cmd);
  232. spin_lock_bh(&adapter->mwifiex_cmd_lock);
  233. adapter->curr_cmd = NULL;
  234. spin_unlock_bh(&adapter->mwifiex_cmd_lock);
  235. adapter->dbg.num_cmd_host_to_card_failure++;
  236. return -1;
  237. }
  238. /* Save the last command id and action to debug log */
  239. adapter->dbg.last_cmd_index =
  240. (adapter->dbg.last_cmd_index + 1) % DBG_CMD_NUM;
  241. adapter->dbg.last_cmd_id[adapter->dbg.last_cmd_index] = cmd_code;
  242. adapter->dbg.last_cmd_act[adapter->dbg.last_cmd_index] =
  243. get_unaligned_le16((u8 *)host_cmd + S_DS_GEN);
  244. /* Setup the timer after transmit command, except that specific
  245. * command might not have command response.
  246. */
  247. if (cmd_code != HostCmd_CMD_FW_DUMP_EVENT)
  248. mod_timer(&adapter->cmd_timer,
  249. jiffies + msecs_to_jiffies(MWIFIEX_TIMER_10S));
  250. /* Clear BSS_NO_BITS from HostCmd */
  251. cmd_code &= HostCmd_CMD_ID_MASK;
  252. return 0;
  253. }
  254. /*
  255. * This function downloads a sleep confirm command to the firmware.
  256. *
  257. * The function performs sanity tests, sets the command sequence
  258. * number and size, converts the header fields to CPU format before
  259. * sending.
  260. *
  261. * No responses are needed for sleep confirm command.
  262. */
  263. static int mwifiex_dnld_sleep_confirm_cmd(struct mwifiex_adapter *adapter)
  264. {
  265. int ret;
  266. struct mwifiex_private *priv;
  267. struct mwifiex_opt_sleep_confirm *sleep_cfm_buf =
  268. (struct mwifiex_opt_sleep_confirm *)
  269. adapter->sleep_cfm->data;
  270. struct sk_buff *sleep_cfm_tmp;
  271. priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
  272. adapter->seq_num++;
  273. sleep_cfm_buf->seq_num =
  274. cpu_to_le16(HostCmd_SET_SEQ_NO_BSS_INFO
  275. (adapter->seq_num, priv->bss_num,
  276. priv->bss_type));
  277. mwifiex_dbg(adapter, CMD,
  278. "cmd: DNLD_CMD: %#x, act %#x, len %d, seqno %#x\n",
  279. le16_to_cpu(sleep_cfm_buf->command),
  280. le16_to_cpu(sleep_cfm_buf->action),
  281. le16_to_cpu(sleep_cfm_buf->size),
  282. le16_to_cpu(sleep_cfm_buf->seq_num));
  283. mwifiex_dbg_dump(adapter, CMD_D, "SLEEP_CFM buffer: ", sleep_cfm_buf,
  284. le16_to_cpu(sleep_cfm_buf->size));
  285. if (adapter->iface_type == MWIFIEX_USB) {
  286. sleep_cfm_tmp =
  287. dev_alloc_skb(sizeof(struct mwifiex_opt_sleep_confirm)
  288. + MWIFIEX_TYPE_LEN);
  289. if (!sleep_cfm_tmp) {
  290. mwifiex_dbg(adapter, ERROR,
  291. "SLEEP_CFM: dev_alloc_skb failed\n");
  292. return -ENOMEM;
  293. }
  294. skb_put(sleep_cfm_tmp, sizeof(struct mwifiex_opt_sleep_confirm)
  295. + MWIFIEX_TYPE_LEN);
  296. put_unaligned_le32(MWIFIEX_USB_TYPE_CMD, sleep_cfm_tmp->data);
  297. memcpy(sleep_cfm_tmp->data + MWIFIEX_TYPE_LEN,
  298. adapter->sleep_cfm->data,
  299. sizeof(struct mwifiex_opt_sleep_confirm));
  300. ret = adapter->if_ops.host_to_card(adapter,
  301. MWIFIEX_USB_EP_CMD_EVENT,
  302. sleep_cfm_tmp, NULL);
  303. if (ret != -EBUSY)
  304. dev_kfree_skb_any(sleep_cfm_tmp);
  305. } else {
  306. skb_push(adapter->sleep_cfm, adapter->intf_hdr_len);
  307. ret = adapter->if_ops.host_to_card(adapter, MWIFIEX_TYPE_CMD,
  308. adapter->sleep_cfm, NULL);
  309. skb_pull(adapter->sleep_cfm, adapter->intf_hdr_len);
  310. }
  311. if (ret == -1) {
  312. mwifiex_dbg(adapter, ERROR, "SLEEP_CFM: failed\n");
  313. adapter->dbg.num_cmd_sleep_cfm_host_to_card_failure++;
  314. return -1;
  315. }
  316. if (!le16_to_cpu(sleep_cfm_buf->resp_ctrl))
  317. /* Response is not needed for sleep confirm command */
  318. adapter->ps_state = PS_STATE_SLEEP;
  319. else
  320. adapter->ps_state = PS_STATE_SLEEP_CFM;
  321. if (!le16_to_cpu(sleep_cfm_buf->resp_ctrl) &&
  322. (test_bit(MWIFIEX_IS_HS_CONFIGURED, &adapter->work_flags) &&
  323. !adapter->sleep_period.period)) {
  324. adapter->pm_wakeup_card_req = true;
  325. mwifiex_hs_activated_event(mwifiex_get_priv
  326. (adapter, MWIFIEX_BSS_ROLE_ANY), true);
  327. }
  328. return ret;
  329. }
  330. /*
  331. * This function allocates the command buffers and links them to
  332. * the command free queue.
  333. *
  334. * The driver uses a pre allocated number of command buffers, which
  335. * are created at driver initializations and freed at driver cleanup.
  336. * Every command needs to obtain a command buffer from this pool before
  337. * it can be issued. The command free queue lists the command buffers
  338. * currently free to use, while the command pending queue lists the
  339. * command buffers already in use and awaiting handling. Command buffers
  340. * are returned to the free queue after use.
  341. */
  342. int mwifiex_alloc_cmd_buffer(struct mwifiex_adapter *adapter)
  343. {
  344. struct cmd_ctrl_node *cmd_array;
  345. u32 i;
  346. /* Allocate and initialize struct cmd_ctrl_node */
  347. cmd_array = kcalloc(MWIFIEX_NUM_OF_CMD_BUFFER,
  348. sizeof(struct cmd_ctrl_node), GFP_KERNEL);
  349. if (!cmd_array)
  350. return -ENOMEM;
  351. adapter->cmd_pool = cmd_array;
  352. /* Allocate and initialize command buffers */
  353. for (i = 0; i < MWIFIEX_NUM_OF_CMD_BUFFER; i++) {
  354. cmd_array[i].skb = dev_alloc_skb(MWIFIEX_SIZE_OF_CMD_BUFFER);
  355. if (!cmd_array[i].skb) {
  356. mwifiex_dbg(adapter, ERROR,
  357. "unable to allocate command buffer\n");
  358. return -ENOMEM;
  359. }
  360. }
  361. for (i = 0; i < MWIFIEX_NUM_OF_CMD_BUFFER; i++)
  362. mwifiex_insert_cmd_to_free_q(adapter, &cmd_array[i]);
  363. return 0;
  364. }
  365. /*
  366. * This function frees the command buffers.
  367. *
  368. * The function calls the completion callback for all the command
  369. * buffers that still have response buffers associated with them.
  370. */
  371. void mwifiex_free_cmd_buffer(struct mwifiex_adapter *adapter)
  372. {
  373. struct cmd_ctrl_node *cmd_array;
  374. u32 i;
  375. /* Need to check if cmd pool is allocated or not */
  376. if (!adapter->cmd_pool) {
  377. mwifiex_dbg(adapter, FATAL,
  378. "info: FREE_CMD_BUF: cmd_pool is null\n");
  379. return;
  380. }
  381. cmd_array = adapter->cmd_pool;
  382. /* Release shared memory buffers */
  383. for (i = 0; i < MWIFIEX_NUM_OF_CMD_BUFFER; i++) {
  384. if (cmd_array[i].skb) {
  385. mwifiex_dbg(adapter, CMD,
  386. "cmd: free cmd buffer %d\n", i);
  387. dev_kfree_skb_any(cmd_array[i].skb);
  388. }
  389. if (!cmd_array[i].resp_skb)
  390. continue;
  391. if (adapter->iface_type == MWIFIEX_USB)
  392. adapter->if_ops.cmdrsp_complete(adapter,
  393. cmd_array[i].resp_skb);
  394. else
  395. dev_kfree_skb_any(cmd_array[i].resp_skb);
  396. }
  397. /* Release struct cmd_ctrl_node */
  398. if (adapter->cmd_pool) {
  399. mwifiex_dbg(adapter, CMD,
  400. "cmd: free cmd pool\n");
  401. kfree(adapter->cmd_pool);
  402. adapter->cmd_pool = NULL;
  403. }
  404. }
  405. /*
  406. * This function handles events generated by firmware.
  407. *
  408. * Event body of events received from firmware are not used (though they are
  409. * saved), only the event ID is used. Some events are re-invoked by
  410. * the driver, with a new event body.
  411. *
  412. * After processing, the function calls the completion callback
  413. * for cleanup.
  414. */
  415. int mwifiex_process_event(struct mwifiex_adapter *adapter)
  416. {
  417. int ret, i;
  418. struct mwifiex_private *priv =
  419. mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
  420. struct sk_buff *skb = adapter->event_skb;
  421. u32 eventcause;
  422. struct mwifiex_rxinfo *rx_info;
  423. if ((adapter->event_cause & EVENT_ID_MASK) == EVENT_RADAR_DETECTED) {
  424. for (i = 0; i < adapter->priv_num; i++) {
  425. priv = adapter->priv[i];
  426. if (priv && mwifiex_is_11h_active(priv)) {
  427. adapter->event_cause |=
  428. ((priv->bss_num & 0xff) << 16) |
  429. ((priv->bss_type & 0xff) << 24);
  430. break;
  431. }
  432. }
  433. }
  434. eventcause = adapter->event_cause;
  435. /* Save the last event to debug log */
  436. adapter->dbg.last_event_index =
  437. (adapter->dbg.last_event_index + 1) % DBG_CMD_NUM;
  438. adapter->dbg.last_event[adapter->dbg.last_event_index] =
  439. (u16) eventcause;
  440. /* Get BSS number and corresponding priv */
  441. priv = mwifiex_get_priv_by_id(adapter, EVENT_GET_BSS_NUM(eventcause),
  442. EVENT_GET_BSS_TYPE(eventcause));
  443. if (!priv)
  444. priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
  445. /* Clear BSS_NO_BITS from event */
  446. eventcause &= EVENT_ID_MASK;
  447. adapter->event_cause = eventcause;
  448. if (skb) {
  449. rx_info = MWIFIEX_SKB_RXCB(skb);
  450. memset(rx_info, 0, sizeof(*rx_info));
  451. rx_info->bss_num = priv->bss_num;
  452. rx_info->bss_type = priv->bss_type;
  453. mwifiex_dbg_dump(adapter, EVT_D, "Event Buf:",
  454. skb->data, skb->len);
  455. }
  456. mwifiex_dbg(adapter, EVENT, "EVENT: cause: %#x\n", eventcause);
  457. if (priv->bss_role == MWIFIEX_BSS_ROLE_UAP)
  458. ret = mwifiex_process_uap_event(priv);
  459. else
  460. ret = mwifiex_process_sta_event(priv);
  461. adapter->event_cause = 0;
  462. adapter->event_skb = NULL;
  463. adapter->if_ops.event_complete(adapter, skb);
  464. return ret;
  465. }
  466. /*
  467. * This function prepares a command and send it to the firmware.
  468. *
  469. * Preparation includes -
  470. * - Sanity tests to make sure the card is still present or the FW
  471. * is not reset
  472. * - Getting a new command node from the command free queue
  473. * - Initializing the command node for default parameters
  474. * - Fill up the non-default parameters and buffer pointers
  475. * - Add the command to pending queue
  476. */
  477. int mwifiex_send_cmd(struct mwifiex_private *priv, u16 cmd_no,
  478. u16 cmd_action, u32 cmd_oid, void *data_buf, bool sync)
  479. {
  480. int ret;
  481. struct mwifiex_adapter *adapter = priv->adapter;
  482. struct cmd_ctrl_node *cmd_node;
  483. struct host_cmd_ds_command *cmd_ptr;
  484. if (!adapter) {
  485. pr_err("PREP_CMD: adapter is NULL\n");
  486. return -1;
  487. }
  488. if (test_bit(MWIFIEX_IS_SUSPENDED, &adapter->work_flags)) {
  489. mwifiex_dbg(adapter, ERROR,
  490. "PREP_CMD: device in suspended state\n");
  491. return -1;
  492. }
  493. if (test_bit(MWIFIEX_IS_HS_ENABLING, &adapter->work_flags) &&
  494. cmd_no != HostCmd_CMD_802_11_HS_CFG_ENH) {
  495. mwifiex_dbg(adapter, ERROR,
  496. "PREP_CMD: host entering sleep state\n");
  497. return -1;
  498. }
  499. if (test_bit(MWIFIEX_SURPRISE_REMOVED, &adapter->work_flags)) {
  500. mwifiex_dbg(adapter, ERROR,
  501. "PREP_CMD: card is removed\n");
  502. return -1;
  503. }
  504. if (test_bit(MWIFIEX_IS_CMD_TIMEDOUT, &adapter->work_flags)) {
  505. mwifiex_dbg(adapter, ERROR,
  506. "PREP_CMD: FW is in bad state\n");
  507. return -1;
  508. }
  509. if (adapter->hw_status == MWIFIEX_HW_STATUS_RESET) {
  510. if (cmd_no != HostCmd_CMD_FUNC_INIT) {
  511. mwifiex_dbg(adapter, ERROR,
  512. "PREP_CMD: FW in reset state\n");
  513. return -1;
  514. }
  515. }
  516. /* We don't expect commands in manufacturing mode. They are cooked
  517. * in application and ready to download buffer is passed to the driver
  518. */
  519. if (adapter->mfg_mode && cmd_no) {
  520. dev_dbg(adapter->dev, "Ignoring commands in manufacturing mode\n");
  521. return -1;
  522. }
  523. if (priv->adapter->hs_activated_manually &&
  524. cmd_no != HostCmd_CMD_802_11_HS_CFG_ENH) {
  525. mwifiex_cancel_hs(priv, MWIFIEX_ASYNC_CMD);
  526. priv->adapter->hs_activated_manually = false;
  527. }
  528. /* Get a new command node */
  529. cmd_node = mwifiex_get_cmd_node(adapter);
  530. if (!cmd_node) {
  531. mwifiex_dbg(adapter, ERROR,
  532. "PREP_CMD: no free cmd node\n");
  533. return -1;
  534. }
  535. /* Initialize the command node */
  536. mwifiex_init_cmd_node(priv, cmd_node, cmd_no, data_buf, sync);
  537. if (!cmd_node->cmd_skb) {
  538. mwifiex_dbg(adapter, ERROR,
  539. "PREP_CMD: no free cmd buf\n");
  540. return -1;
  541. }
  542. skb_put_zero(cmd_node->cmd_skb, sizeof(struct host_cmd_ds_command));
  543. cmd_ptr = (struct host_cmd_ds_command *) (cmd_node->cmd_skb->data);
  544. cmd_ptr->command = cpu_to_le16(cmd_no);
  545. cmd_ptr->result = 0;
  546. /* Prepare command */
  547. if (cmd_no) {
  548. switch (cmd_no) {
  549. case HostCmd_CMD_UAP_SYS_CONFIG:
  550. case HostCmd_CMD_UAP_BSS_START:
  551. case HostCmd_CMD_UAP_BSS_STOP:
  552. case HostCmd_CMD_UAP_STA_DEAUTH:
  553. case HOST_CMD_APCMD_SYS_RESET:
  554. case HOST_CMD_APCMD_STA_LIST:
  555. ret = mwifiex_uap_prepare_cmd(priv, cmd_no, cmd_action,
  556. cmd_oid, data_buf,
  557. cmd_ptr);
  558. break;
  559. default:
  560. ret = mwifiex_sta_prepare_cmd(priv, cmd_no, cmd_action,
  561. cmd_oid, data_buf,
  562. cmd_ptr);
  563. break;
  564. }
  565. } else {
  566. ret = mwifiex_cmd_host_cmd(priv, cmd_ptr, data_buf);
  567. cmd_node->cmd_flag |= CMD_F_HOSTCMD;
  568. }
  569. /* Return error, since the command preparation failed */
  570. if (ret) {
  571. mwifiex_dbg(adapter, ERROR,
  572. "PREP_CMD: cmd %#x preparation failed\n",
  573. cmd_no);
  574. mwifiex_insert_cmd_to_free_q(adapter, cmd_node);
  575. return -1;
  576. }
  577. /* Send command */
  578. if (cmd_no == HostCmd_CMD_802_11_SCAN ||
  579. cmd_no == HostCmd_CMD_802_11_SCAN_EXT) {
  580. mwifiex_queue_scan_cmd(priv, cmd_node);
  581. } else {
  582. mwifiex_insert_cmd_to_pending_q(adapter, cmd_node);
  583. queue_work(adapter->workqueue, &adapter->main_work);
  584. if (cmd_node->wait_q_enabled)
  585. ret = mwifiex_wait_queue_complete(adapter, cmd_node);
  586. }
  587. return ret;
  588. }
  589. /*
  590. * This function queues a command to the command pending queue.
  591. *
  592. * This in effect adds the command to the command list to be executed.
  593. * Exit PS command is handled specially, by placing it always to the
  594. * front of the command queue.
  595. */
  596. void
  597. mwifiex_insert_cmd_to_pending_q(struct mwifiex_adapter *adapter,
  598. struct cmd_ctrl_node *cmd_node)
  599. {
  600. struct host_cmd_ds_command *host_cmd = NULL;
  601. u16 command;
  602. bool add_tail = true;
  603. host_cmd = (struct host_cmd_ds_command *) (cmd_node->cmd_skb->data);
  604. if (!host_cmd) {
  605. mwifiex_dbg(adapter, ERROR, "QUEUE_CMD: host_cmd is NULL\n");
  606. return;
  607. }
  608. command = le16_to_cpu(host_cmd->command);
  609. /* Exit_PS command needs to be queued in the header always. */
  610. if (command == HostCmd_CMD_802_11_PS_MODE_ENH) {
  611. struct host_cmd_ds_802_11_ps_mode_enh *pm =
  612. &host_cmd->params.psmode_enh;
  613. if ((le16_to_cpu(pm->action) == DIS_PS) ||
  614. (le16_to_cpu(pm->action) == DIS_AUTO_PS)) {
  615. if (adapter->ps_state != PS_STATE_AWAKE)
  616. add_tail = false;
  617. }
  618. }
  619. /* Same with exit host sleep cmd, luckily that can't happen at the same time as EXIT_PS */
  620. if (command == HostCmd_CMD_802_11_HS_CFG_ENH) {
  621. struct host_cmd_ds_802_11_hs_cfg_enh *hs_cfg =
  622. &host_cmd->params.opt_hs_cfg;
  623. if (le16_to_cpu(hs_cfg->action) == HS_ACTIVATE)
  624. add_tail = false;
  625. }
  626. spin_lock_bh(&adapter->cmd_pending_q_lock);
  627. if (add_tail)
  628. list_add_tail(&cmd_node->list, &adapter->cmd_pending_q);
  629. else
  630. list_add(&cmd_node->list, &adapter->cmd_pending_q);
  631. spin_unlock_bh(&adapter->cmd_pending_q_lock);
  632. atomic_inc(&adapter->cmd_pending);
  633. mwifiex_dbg(adapter, CMD,
  634. "cmd: QUEUE_CMD: cmd=%#x, cmd_pending=%d\n",
  635. command, atomic_read(&adapter->cmd_pending));
  636. }
  637. /*
  638. * This function executes the next command in command pending queue.
  639. *
  640. * This function will fail if a command is already in processing stage,
  641. * otherwise it will dequeue the first command from the command pending
  642. * queue and send to the firmware.
  643. *
  644. * If the device is currently in host sleep mode, any commands, except the
  645. * host sleep configuration command will de-activate the host sleep. For PS
  646. * mode, the function will put the firmware back to sleep if applicable.
  647. */
  648. int mwifiex_exec_next_cmd(struct mwifiex_adapter *adapter)
  649. {
  650. struct mwifiex_private *priv;
  651. struct cmd_ctrl_node *cmd_node;
  652. int ret = 0;
  653. struct host_cmd_ds_command *host_cmd;
  654. /* Check if already in processing */
  655. if (adapter->curr_cmd) {
  656. mwifiex_dbg(adapter, FATAL,
  657. "EXEC_NEXT_CMD: cmd in processing\n");
  658. return -1;
  659. }
  660. spin_lock_bh(&adapter->mwifiex_cmd_lock);
  661. /* Check if any command is pending */
  662. spin_lock_bh(&adapter->cmd_pending_q_lock);
  663. if (list_empty(&adapter->cmd_pending_q)) {
  664. spin_unlock_bh(&adapter->cmd_pending_q_lock);
  665. spin_unlock_bh(&adapter->mwifiex_cmd_lock);
  666. return 0;
  667. }
  668. cmd_node = list_first_entry(&adapter->cmd_pending_q,
  669. struct cmd_ctrl_node, list);
  670. host_cmd = (struct host_cmd_ds_command *) (cmd_node->cmd_skb->data);
  671. priv = cmd_node->priv;
  672. if (adapter->ps_state != PS_STATE_AWAKE) {
  673. mwifiex_dbg(adapter, ERROR,
  674. "%s: cannot send cmd in sleep state,\t"
  675. "this should not happen\n", __func__);
  676. spin_unlock_bh(&adapter->cmd_pending_q_lock);
  677. spin_unlock_bh(&adapter->mwifiex_cmd_lock);
  678. return ret;
  679. }
  680. list_del(&cmd_node->list);
  681. spin_unlock_bh(&adapter->cmd_pending_q_lock);
  682. spin_unlock_bh(&adapter->mwifiex_cmd_lock);
  683. ret = mwifiex_dnld_cmd_to_fw(priv, cmd_node);
  684. priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
  685. /* Any command sent to the firmware when host is in sleep
  686. * mode should de-configure host sleep. We should skip the
  687. * host sleep configuration command itself though
  688. */
  689. if (priv && (host_cmd->command !=
  690. cpu_to_le16(HostCmd_CMD_802_11_HS_CFG_ENH))) {
  691. if (adapter->hs_activated) {
  692. clear_bit(MWIFIEX_IS_HS_CONFIGURED,
  693. &adapter->work_flags);
  694. mwifiex_hs_activated_event(priv, false);
  695. }
  696. }
  697. return ret;
  698. }
  699. /*
  700. * This function handles the command response.
  701. *
  702. * After processing, the function cleans the command node and puts
  703. * it back to the command free queue.
  704. */
  705. int mwifiex_process_cmdresp(struct mwifiex_adapter *adapter)
  706. {
  707. struct host_cmd_ds_command *resp;
  708. struct mwifiex_private *priv =
  709. mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
  710. int ret = 0;
  711. uint16_t orig_cmdresp_no;
  712. uint16_t cmdresp_no;
  713. uint16_t cmdresp_result;
  714. if (!adapter->curr_cmd || !adapter->curr_cmd->resp_skb) {
  715. resp = (struct host_cmd_ds_command *) adapter->upld_buf;
  716. mwifiex_dbg(adapter, ERROR,
  717. "CMD_RESP: NULL curr_cmd, %#x\n",
  718. le16_to_cpu(resp->command));
  719. return -1;
  720. }
  721. resp = (struct host_cmd_ds_command *)adapter->curr_cmd->resp_skb->data;
  722. orig_cmdresp_no = le16_to_cpu(resp->command);
  723. cmdresp_no = (orig_cmdresp_no & HostCmd_CMD_ID_MASK);
  724. if (adapter->curr_cmd->cmd_no != cmdresp_no) {
  725. mwifiex_dbg(adapter, ERROR,
  726. "cmdresp error: cmd=0x%x cmd_resp=0x%x\n",
  727. adapter->curr_cmd->cmd_no, cmdresp_no);
  728. return -1;
  729. }
  730. /* Now we got response from FW, cancel the command timer */
  731. del_timer_sync(&adapter->cmd_timer);
  732. clear_bit(MWIFIEX_IS_CMD_TIMEDOUT, &adapter->work_flags);
  733. if (adapter->curr_cmd->cmd_flag & CMD_F_HOSTCMD) {
  734. /* Copy original response back to response buffer */
  735. struct mwifiex_ds_misc_cmd *hostcmd;
  736. uint16_t size = le16_to_cpu(resp->size);
  737. mwifiex_dbg(adapter, INFO,
  738. "info: host cmd resp size = %d\n", size);
  739. size = min_t(u16, size, MWIFIEX_SIZE_OF_CMD_BUFFER);
  740. if (adapter->curr_cmd->data_buf) {
  741. hostcmd = adapter->curr_cmd->data_buf;
  742. hostcmd->len = size;
  743. memcpy(hostcmd->cmd, resp, size);
  744. }
  745. }
  746. /* Get BSS number and corresponding priv */
  747. priv = mwifiex_get_priv_by_id(adapter,
  748. HostCmd_GET_BSS_NO(le16_to_cpu(resp->seq_num)),
  749. HostCmd_GET_BSS_TYPE(le16_to_cpu(resp->seq_num)));
  750. if (!priv)
  751. priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
  752. /* Clear RET_BIT from HostCmd */
  753. resp->command = cpu_to_le16(orig_cmdresp_no & HostCmd_CMD_ID_MASK);
  754. cmdresp_no = le16_to_cpu(resp->command);
  755. cmdresp_result = le16_to_cpu(resp->result);
  756. /* Save the last command response to debug log */
  757. adapter->dbg.last_cmd_resp_index =
  758. (adapter->dbg.last_cmd_resp_index + 1) % DBG_CMD_NUM;
  759. adapter->dbg.last_cmd_resp_id[adapter->dbg.last_cmd_resp_index] =
  760. orig_cmdresp_no;
  761. mwifiex_dbg(adapter, CMD,
  762. "cmd: CMD_RESP: 0x%x, result %d, len %d, seqno 0x%x\n",
  763. orig_cmdresp_no, cmdresp_result,
  764. le16_to_cpu(resp->size), le16_to_cpu(resp->seq_num));
  765. mwifiex_dbg_dump(adapter, CMD_D, "CMD_RESP buffer:", resp,
  766. le16_to_cpu(resp->size));
  767. if (!(orig_cmdresp_no & HostCmd_RET_BIT)) {
  768. mwifiex_dbg(adapter, ERROR, "CMD_RESP: invalid cmd resp\n");
  769. if (adapter->curr_cmd->wait_q_enabled)
  770. adapter->cmd_wait_q.status = -1;
  771. mwifiex_recycle_cmd_node(adapter, adapter->curr_cmd);
  772. spin_lock_bh(&adapter->mwifiex_cmd_lock);
  773. adapter->curr_cmd = NULL;
  774. spin_unlock_bh(&adapter->mwifiex_cmd_lock);
  775. return -1;
  776. }
  777. if (adapter->curr_cmd->cmd_flag & CMD_F_HOSTCMD) {
  778. adapter->curr_cmd->cmd_flag &= ~CMD_F_HOSTCMD;
  779. if ((cmdresp_result == HostCmd_RESULT_OK) &&
  780. (cmdresp_no == HostCmd_CMD_802_11_HS_CFG_ENH))
  781. ret = mwifiex_ret_802_11_hs_cfg(priv, resp);
  782. } else {
  783. /* handle response */
  784. ret = mwifiex_process_sta_cmdresp(priv, cmdresp_no, resp);
  785. }
  786. /* Check init command response */
  787. if (adapter->hw_status == MWIFIEX_HW_STATUS_INITIALIZING) {
  788. if (ret) {
  789. mwifiex_dbg(adapter, ERROR,
  790. "%s: cmd %#x failed during\t"
  791. "initialization\n", __func__, cmdresp_no);
  792. mwifiex_init_fw_complete(adapter);
  793. return -1;
  794. } else if (adapter->last_init_cmd == cmdresp_no)
  795. adapter->hw_status = MWIFIEX_HW_STATUS_INIT_DONE;
  796. }
  797. if (adapter->curr_cmd) {
  798. if (adapter->curr_cmd->wait_q_enabled)
  799. adapter->cmd_wait_q.status = ret;
  800. mwifiex_recycle_cmd_node(adapter, adapter->curr_cmd);
  801. spin_lock_bh(&adapter->mwifiex_cmd_lock);
  802. adapter->curr_cmd = NULL;
  803. spin_unlock_bh(&adapter->mwifiex_cmd_lock);
  804. }
  805. return ret;
  806. }
  807. /*
  808. * This function handles the timeout of command sending.
  809. *
  810. * It will re-send the same command again.
  811. */
  812. void
  813. mwifiex_cmd_timeout_func(struct timer_list *t)
  814. {
  815. struct mwifiex_adapter *adapter = from_timer(adapter, t, cmd_timer);
  816. struct cmd_ctrl_node *cmd_node;
  817. set_bit(MWIFIEX_IS_CMD_TIMEDOUT, &adapter->work_flags);
  818. if (!adapter->curr_cmd) {
  819. mwifiex_dbg(adapter, ERROR,
  820. "cmd: empty curr_cmd\n");
  821. return;
  822. }
  823. cmd_node = adapter->curr_cmd;
  824. if (cmd_node) {
  825. adapter->dbg.timeout_cmd_id =
  826. adapter->dbg.last_cmd_id[adapter->dbg.last_cmd_index];
  827. adapter->dbg.timeout_cmd_act =
  828. adapter->dbg.last_cmd_act[adapter->dbg.last_cmd_index];
  829. mwifiex_dbg(adapter, MSG,
  830. "%s: Timeout cmd id = %#x, act = %#x\n", __func__,
  831. adapter->dbg.timeout_cmd_id,
  832. adapter->dbg.timeout_cmd_act);
  833. mwifiex_dbg(adapter, MSG,
  834. "num_data_h2c_failure = %d\n",
  835. adapter->dbg.num_tx_host_to_card_failure);
  836. mwifiex_dbg(adapter, MSG,
  837. "num_cmd_h2c_failure = %d\n",
  838. adapter->dbg.num_cmd_host_to_card_failure);
  839. mwifiex_dbg(adapter, MSG,
  840. "is_cmd_timedout = %d\n",
  841. test_bit(MWIFIEX_IS_CMD_TIMEDOUT,
  842. &adapter->work_flags));
  843. mwifiex_dbg(adapter, MSG,
  844. "num_tx_timeout = %d\n",
  845. adapter->dbg.num_tx_timeout);
  846. mwifiex_dbg(adapter, MSG,
  847. "last_cmd_index = %d\n",
  848. adapter->dbg.last_cmd_index);
  849. mwifiex_dbg(adapter, MSG,
  850. "last_cmd_id: %*ph\n",
  851. (int)sizeof(adapter->dbg.last_cmd_id),
  852. adapter->dbg.last_cmd_id);
  853. mwifiex_dbg(adapter, MSG,
  854. "last_cmd_act: %*ph\n",
  855. (int)sizeof(adapter->dbg.last_cmd_act),
  856. adapter->dbg.last_cmd_act);
  857. mwifiex_dbg(adapter, MSG,
  858. "last_cmd_resp_index = %d\n",
  859. adapter->dbg.last_cmd_resp_index);
  860. mwifiex_dbg(adapter, MSG,
  861. "last_cmd_resp_id: %*ph\n",
  862. (int)sizeof(adapter->dbg.last_cmd_resp_id),
  863. adapter->dbg.last_cmd_resp_id);
  864. mwifiex_dbg(adapter, MSG,
  865. "last_event_index = %d\n",
  866. adapter->dbg.last_event_index);
  867. mwifiex_dbg(adapter, MSG,
  868. "last_event: %*ph\n",
  869. (int)sizeof(adapter->dbg.last_event),
  870. adapter->dbg.last_event);
  871. mwifiex_dbg(adapter, MSG,
  872. "data_sent=%d cmd_sent=%d\n",
  873. adapter->data_sent, adapter->cmd_sent);
  874. mwifiex_dbg(adapter, MSG,
  875. "ps_mode=%d ps_state=%d\n",
  876. adapter->ps_mode, adapter->ps_state);
  877. if (cmd_node->wait_q_enabled) {
  878. adapter->cmd_wait_q.status = -ETIMEDOUT;
  879. mwifiex_cancel_pending_ioctl(adapter);
  880. }
  881. }
  882. if (adapter->hw_status == MWIFIEX_HW_STATUS_INITIALIZING) {
  883. mwifiex_init_fw_complete(adapter);
  884. return;
  885. }
  886. if (adapter->if_ops.device_dump)
  887. adapter->if_ops.device_dump(adapter);
  888. if (adapter->if_ops.card_reset)
  889. adapter->if_ops.card_reset(adapter);
  890. }
  891. void
  892. mwifiex_cancel_pending_scan_cmd(struct mwifiex_adapter *adapter)
  893. {
  894. struct cmd_ctrl_node *cmd_node = NULL, *tmp_node;
  895. /* Cancel all pending scan command */
  896. spin_lock_bh(&adapter->scan_pending_q_lock);
  897. list_for_each_entry_safe(cmd_node, tmp_node,
  898. &adapter->scan_pending_q, list) {
  899. list_del(&cmd_node->list);
  900. cmd_node->wait_q_enabled = false;
  901. mwifiex_insert_cmd_to_free_q(adapter, cmd_node);
  902. }
  903. spin_unlock_bh(&adapter->scan_pending_q_lock);
  904. }
  905. /*
  906. * This function cancels all the pending commands.
  907. *
  908. * The current command, all commands in command pending queue and all scan
  909. * commands in scan pending queue are cancelled. All the completion callbacks
  910. * are called with failure status to ensure cleanup.
  911. */
  912. void
  913. mwifiex_cancel_all_pending_cmd(struct mwifiex_adapter *adapter)
  914. {
  915. struct cmd_ctrl_node *cmd_node = NULL, *tmp_node;
  916. spin_lock_bh(&adapter->mwifiex_cmd_lock);
  917. /* Cancel current cmd */
  918. if ((adapter->curr_cmd) && (adapter->curr_cmd->wait_q_enabled)) {
  919. adapter->cmd_wait_q.status = -1;
  920. mwifiex_complete_cmd(adapter, adapter->curr_cmd);
  921. adapter->curr_cmd->wait_q_enabled = false;
  922. /* no recycle probably wait for response */
  923. }
  924. /* Cancel all pending command */
  925. spin_lock_bh(&adapter->cmd_pending_q_lock);
  926. list_for_each_entry_safe(cmd_node, tmp_node,
  927. &adapter->cmd_pending_q, list) {
  928. list_del(&cmd_node->list);
  929. if (cmd_node->wait_q_enabled)
  930. adapter->cmd_wait_q.status = -1;
  931. mwifiex_recycle_cmd_node(adapter, cmd_node);
  932. }
  933. spin_unlock_bh(&adapter->cmd_pending_q_lock);
  934. spin_unlock_bh(&adapter->mwifiex_cmd_lock);
  935. mwifiex_cancel_scan(adapter);
  936. }
  937. /*
  938. * This function cancels all pending commands that matches with
  939. * the given IOCTL request.
  940. *
  941. * Both the current command buffer and the pending command queue are
  942. * searched for matching IOCTL request. The completion callback of
  943. * the matched command is called with failure status to ensure cleanup.
  944. * In case of scan commands, all pending commands in scan pending queue
  945. * are cancelled.
  946. */
  947. static void
  948. mwifiex_cancel_pending_ioctl(struct mwifiex_adapter *adapter)
  949. {
  950. struct cmd_ctrl_node *cmd_node = NULL;
  951. if ((adapter->curr_cmd) &&
  952. (adapter->curr_cmd->wait_q_enabled)) {
  953. spin_lock_bh(&adapter->mwifiex_cmd_lock);
  954. cmd_node = adapter->curr_cmd;
  955. /* setting curr_cmd to NULL is quite dangerous, because
  956. * mwifiex_process_cmdresp checks curr_cmd to be != NULL
  957. * at the beginning then relies on it and dereferences
  958. * it at will
  959. * this probably works since mwifiex_cmd_timeout_func
  960. * is the only caller of this function and responses
  961. * at that point
  962. */
  963. adapter->curr_cmd = NULL;
  964. spin_unlock_bh(&adapter->mwifiex_cmd_lock);
  965. mwifiex_recycle_cmd_node(adapter, cmd_node);
  966. }
  967. mwifiex_cancel_scan(adapter);
  968. }
  969. /*
  970. * This function sends the sleep confirm command to firmware, if
  971. * possible.
  972. *
  973. * The sleep confirm command cannot be issued if command response,
  974. * data response or event response is awaiting handling, or if we
  975. * are in the middle of sending a command, or expecting a command
  976. * response.
  977. */
  978. void
  979. mwifiex_check_ps_cond(struct mwifiex_adapter *adapter)
  980. {
  981. if (!adapter->cmd_sent && !atomic_read(&adapter->tx_hw_pending) &&
  982. !adapter->curr_cmd && !IS_CARD_RX_RCVD(adapter))
  983. mwifiex_dnld_sleep_confirm_cmd(adapter);
  984. else
  985. mwifiex_dbg(adapter, CMD,
  986. "cmd: Delay Sleep Confirm (%s%s%s%s)\n",
  987. (adapter->cmd_sent) ? "D" : "",
  988. atomic_read(&adapter->tx_hw_pending) ? "T" : "",
  989. (adapter->curr_cmd) ? "C" : "",
  990. (IS_CARD_RX_RCVD(adapter)) ? "R" : "");
  991. }
  992. /*
  993. * This function sends a Host Sleep activated event to applications.
  994. *
  995. * This event is generated by the driver, with a blank event body.
  996. */
  997. void
  998. mwifiex_hs_activated_event(struct mwifiex_private *priv, u8 activated)
  999. {
  1000. if (activated) {
  1001. if (test_bit(MWIFIEX_IS_HS_CONFIGURED,
  1002. &priv->adapter->work_flags)) {
  1003. priv->adapter->hs_activated = true;
  1004. mwifiex_update_rxreor_flags(priv->adapter,
  1005. RXREOR_FORCE_NO_DROP);
  1006. mwifiex_dbg(priv->adapter, EVENT,
  1007. "event: hs_activated\n");
  1008. priv->adapter->hs_activate_wait_q_woken = true;
  1009. wake_up_interruptible(
  1010. &priv->adapter->hs_activate_wait_q);
  1011. } else {
  1012. mwifiex_dbg(priv->adapter, EVENT,
  1013. "event: HS not configured\n");
  1014. }
  1015. } else {
  1016. mwifiex_dbg(priv->adapter, EVENT,
  1017. "event: hs_deactivated\n");
  1018. priv->adapter->hs_activated = false;
  1019. }
  1020. }
  1021. /*
  1022. * This function handles the command response of a Host Sleep configuration
  1023. * command.
  1024. *
  1025. * Handling includes changing the header fields into CPU format
  1026. * and setting the current host sleep activation status in driver.
  1027. *
  1028. * In case host sleep status change, the function generates an event to
  1029. * notify the applications.
  1030. */
  1031. int mwifiex_ret_802_11_hs_cfg(struct mwifiex_private *priv,
  1032. struct host_cmd_ds_command *resp)
  1033. {
  1034. struct mwifiex_adapter *adapter = priv->adapter;
  1035. struct host_cmd_ds_802_11_hs_cfg_enh *phs_cfg =
  1036. &resp->params.opt_hs_cfg;
  1037. uint32_t conditions = le32_to_cpu(phs_cfg->params.hs_config.conditions);
  1038. if (phs_cfg->action == cpu_to_le16(HS_ACTIVATE) &&
  1039. adapter->iface_type != MWIFIEX_USB) {
  1040. mwifiex_hs_activated_event(priv, true);
  1041. return 0;
  1042. } else {
  1043. mwifiex_dbg(adapter, CMD,
  1044. "cmd: CMD_RESP: HS_CFG cmd reply\t"
  1045. " result=%#x, conditions=0x%x gpio=0x%x gap=0x%x\n",
  1046. resp->result, conditions,
  1047. phs_cfg->params.hs_config.gpio,
  1048. phs_cfg->params.hs_config.gap);
  1049. }
  1050. if (conditions != HS_CFG_CANCEL) {
  1051. set_bit(MWIFIEX_IS_HS_CONFIGURED, &adapter->work_flags);
  1052. if (adapter->iface_type == MWIFIEX_USB)
  1053. mwifiex_hs_activated_event(priv, true);
  1054. } else {
  1055. clear_bit(MWIFIEX_IS_HS_CONFIGURED, &adapter->work_flags);
  1056. if (adapter->hs_activated)
  1057. mwifiex_hs_activated_event(priv, false);
  1058. }
  1059. return 0;
  1060. }
  1061. /*
  1062. * This function wakes up the adapter and generates a Host Sleep
  1063. * cancel event on receiving the power up interrupt.
  1064. */
  1065. void
  1066. mwifiex_process_hs_config(struct mwifiex_adapter *adapter)
  1067. {
  1068. mwifiex_dbg(adapter, INFO,
  1069. "info: %s: auto cancelling host sleep\t"
  1070. "since there is interrupt from the firmware\n",
  1071. __func__);
  1072. adapter->if_ops.wakeup(adapter);
  1073. if (adapter->hs_activated_manually) {
  1074. mwifiex_cancel_hs(mwifiex_get_priv (adapter, MWIFIEX_BSS_ROLE_ANY),
  1075. MWIFIEX_ASYNC_CMD);
  1076. adapter->hs_activated_manually = false;
  1077. }
  1078. adapter->hs_activated = false;
  1079. clear_bit(MWIFIEX_IS_HS_CONFIGURED, &adapter->work_flags);
  1080. clear_bit(MWIFIEX_IS_SUSPENDED, &adapter->work_flags);
  1081. mwifiex_hs_activated_event(mwifiex_get_priv(adapter,
  1082. MWIFIEX_BSS_ROLE_ANY),
  1083. false);
  1084. }
  1085. EXPORT_SYMBOL_GPL(mwifiex_process_hs_config);
  1086. /*
  1087. * This function handles the command response of a sleep confirm command.
  1088. *
  1089. * The function sets the card state to SLEEP if the response indicates success.
  1090. */
  1091. void
  1092. mwifiex_process_sleep_confirm_resp(struct mwifiex_adapter *adapter,
  1093. u8 *pbuf, u32 upld_len)
  1094. {
  1095. struct host_cmd_ds_command *cmd = (struct host_cmd_ds_command *) pbuf;
  1096. struct mwifiex_private *priv =
  1097. mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
  1098. uint16_t result = le16_to_cpu(cmd->result);
  1099. uint16_t command = le16_to_cpu(cmd->command);
  1100. uint16_t seq_num = le16_to_cpu(cmd->seq_num);
  1101. if (!upld_len) {
  1102. mwifiex_dbg(adapter, ERROR,
  1103. "%s: cmd size is 0\n", __func__);
  1104. return;
  1105. }
  1106. mwifiex_dbg(adapter, CMD,
  1107. "cmd: CMD_RESP: 0x%x, result %d, len %d, seqno 0x%x\n",
  1108. command, result, le16_to_cpu(cmd->size), seq_num);
  1109. /* Get BSS number and corresponding priv */
  1110. priv = mwifiex_get_priv_by_id(adapter, HostCmd_GET_BSS_NO(seq_num),
  1111. HostCmd_GET_BSS_TYPE(seq_num));
  1112. if (!priv)
  1113. priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
  1114. /* Update sequence number */
  1115. seq_num = HostCmd_GET_SEQ_NO(seq_num);
  1116. /* Clear RET_BIT from HostCmd */
  1117. command &= HostCmd_CMD_ID_MASK;
  1118. if (command != HostCmd_CMD_802_11_PS_MODE_ENH) {
  1119. mwifiex_dbg(adapter, ERROR,
  1120. "%s: rcvd unexpected resp for cmd %#x, result = %x\n",
  1121. __func__, command, result);
  1122. return;
  1123. }
  1124. if (result) {
  1125. mwifiex_dbg(adapter, ERROR,
  1126. "%s: sleep confirm cmd failed\n",
  1127. __func__);
  1128. adapter->pm_wakeup_card_req = false;
  1129. adapter->ps_state = PS_STATE_AWAKE;
  1130. return;
  1131. }
  1132. adapter->pm_wakeup_card_req = true;
  1133. if (test_bit(MWIFIEX_IS_HS_CONFIGURED, &adapter->work_flags))
  1134. mwifiex_hs_activated_event(mwifiex_get_priv
  1135. (adapter, MWIFIEX_BSS_ROLE_ANY),
  1136. true);
  1137. adapter->ps_state = PS_STATE_SLEEP;
  1138. cmd->command = cpu_to_le16(command);
  1139. cmd->seq_num = cpu_to_le16(seq_num);
  1140. }
  1141. EXPORT_SYMBOL_GPL(mwifiex_process_sleep_confirm_resp);
  1142. /*
  1143. * This function prepares an enhanced power mode command.
  1144. *
  1145. * This function can be used to disable power save or to configure
  1146. * power save with auto PS or STA PS or auto deep sleep.
  1147. *
  1148. * Preparation includes -
  1149. * - Setting command ID, action and proper size
  1150. * - Setting Power Save bitmap, PS parameters TLV, PS mode TLV,
  1151. * auto deep sleep TLV (as required)
  1152. * - Ensuring correct endian-ness
  1153. */
  1154. int mwifiex_cmd_enh_power_mode(struct mwifiex_private *priv,
  1155. struct host_cmd_ds_command *cmd,
  1156. u16 cmd_action, uint16_t ps_bitmap,
  1157. struct mwifiex_ds_auto_ds *auto_ds)
  1158. {
  1159. struct host_cmd_ds_802_11_ps_mode_enh *psmode_enh =
  1160. &cmd->params.psmode_enh;
  1161. u8 *tlv;
  1162. u16 cmd_size = 0;
  1163. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_PS_MODE_ENH);
  1164. if (cmd_action == DIS_AUTO_PS) {
  1165. psmode_enh->action = cpu_to_le16(DIS_AUTO_PS);
  1166. psmode_enh->params.ps_bitmap = cpu_to_le16(ps_bitmap);
  1167. cmd->size = cpu_to_le16(S_DS_GEN + sizeof(psmode_enh->action) +
  1168. sizeof(psmode_enh->params.ps_bitmap));
  1169. } else if (cmd_action == GET_PS) {
  1170. psmode_enh->action = cpu_to_le16(GET_PS);
  1171. psmode_enh->params.ps_bitmap = cpu_to_le16(ps_bitmap);
  1172. cmd->size = cpu_to_le16(S_DS_GEN + sizeof(psmode_enh->action) +
  1173. sizeof(psmode_enh->params.ps_bitmap));
  1174. } else if (cmd_action == EN_AUTO_PS) {
  1175. psmode_enh->action = cpu_to_le16(EN_AUTO_PS);
  1176. psmode_enh->params.ps_bitmap = cpu_to_le16(ps_bitmap);
  1177. cmd_size = S_DS_GEN + sizeof(psmode_enh->action) +
  1178. sizeof(psmode_enh->params.ps_bitmap);
  1179. tlv = (u8 *) cmd + cmd_size;
  1180. if (ps_bitmap & BITMAP_STA_PS) {
  1181. struct mwifiex_adapter *adapter = priv->adapter;
  1182. struct mwifiex_ie_types_ps_param *ps_tlv =
  1183. (struct mwifiex_ie_types_ps_param *) tlv;
  1184. struct mwifiex_ps_param *ps_mode = &ps_tlv->param;
  1185. ps_tlv->header.type = cpu_to_le16(TLV_TYPE_PS_PARAM);
  1186. ps_tlv->header.len = cpu_to_le16(sizeof(*ps_tlv) -
  1187. sizeof(struct mwifiex_ie_types_header));
  1188. cmd_size += sizeof(*ps_tlv);
  1189. tlv += sizeof(*ps_tlv);
  1190. mwifiex_dbg(priv->adapter, CMD,
  1191. "cmd: PS Command: Enter PS\n");
  1192. ps_mode->null_pkt_interval =
  1193. cpu_to_le16(adapter->null_pkt_interval);
  1194. ps_mode->multiple_dtims =
  1195. cpu_to_le16(adapter->multiple_dtim);
  1196. ps_mode->bcn_miss_timeout =
  1197. cpu_to_le16(adapter->bcn_miss_time_out);
  1198. ps_mode->local_listen_interval =
  1199. cpu_to_le16(adapter->local_listen_interval);
  1200. ps_mode->adhoc_wake_period =
  1201. cpu_to_le16(adapter->adhoc_awake_period);
  1202. ps_mode->delay_to_ps =
  1203. cpu_to_le16(adapter->delay_to_ps);
  1204. ps_mode->mode = cpu_to_le16(adapter->enhanced_ps_mode);
  1205. }
  1206. if (ps_bitmap & BITMAP_AUTO_DS) {
  1207. struct mwifiex_ie_types_auto_ds_param *auto_ds_tlv =
  1208. (struct mwifiex_ie_types_auto_ds_param *) tlv;
  1209. u16 idletime = 0;
  1210. auto_ds_tlv->header.type =
  1211. cpu_to_le16(TLV_TYPE_AUTO_DS_PARAM);
  1212. auto_ds_tlv->header.len =
  1213. cpu_to_le16(sizeof(*auto_ds_tlv) -
  1214. sizeof(struct mwifiex_ie_types_header));
  1215. cmd_size += sizeof(*auto_ds_tlv);
  1216. tlv += sizeof(*auto_ds_tlv);
  1217. if (auto_ds)
  1218. idletime = auto_ds->idle_time;
  1219. mwifiex_dbg(priv->adapter, CMD,
  1220. "cmd: PS Command: Enter Auto Deep Sleep\n");
  1221. auto_ds_tlv->deep_sleep_timeout = cpu_to_le16(idletime);
  1222. }
  1223. cmd->size = cpu_to_le16(cmd_size);
  1224. }
  1225. return 0;
  1226. }
  1227. /*
  1228. * This function handles the command response of an enhanced power mode
  1229. * command.
  1230. *
  1231. * Handling includes changing the header fields into CPU format
  1232. * and setting the current enhanced power mode in driver.
  1233. */
  1234. int mwifiex_ret_enh_power_mode(struct mwifiex_private *priv,
  1235. struct host_cmd_ds_command *resp,
  1236. struct mwifiex_ds_pm_cfg *pm_cfg)
  1237. {
  1238. struct mwifiex_adapter *adapter = priv->adapter;
  1239. struct host_cmd_ds_802_11_ps_mode_enh *ps_mode =
  1240. &resp->params.psmode_enh;
  1241. uint16_t action = le16_to_cpu(ps_mode->action);
  1242. uint16_t ps_bitmap = le16_to_cpu(ps_mode->params.ps_bitmap);
  1243. uint16_t auto_ps_bitmap =
  1244. le16_to_cpu(ps_mode->params.ps_bitmap);
  1245. mwifiex_dbg(adapter, INFO,
  1246. "info: %s: PS_MODE cmd reply result=%#x action=%#X\n",
  1247. __func__, resp->result, action);
  1248. if (action == EN_AUTO_PS) {
  1249. if (auto_ps_bitmap & BITMAP_AUTO_DS) {
  1250. mwifiex_dbg(adapter, CMD,
  1251. "cmd: Enabled auto deep sleep\n");
  1252. priv->adapter->is_deep_sleep = true;
  1253. }
  1254. if (auto_ps_bitmap & BITMAP_STA_PS) {
  1255. mwifiex_dbg(adapter, CMD,
  1256. "cmd: Enabled STA power save\n");
  1257. if (adapter->sleep_period.period)
  1258. mwifiex_dbg(adapter, CMD,
  1259. "cmd: set to uapsd/pps mode\n");
  1260. }
  1261. } else if (action == DIS_AUTO_PS) {
  1262. if (ps_bitmap & BITMAP_AUTO_DS) {
  1263. priv->adapter->is_deep_sleep = false;
  1264. mwifiex_dbg(adapter, CMD,
  1265. "cmd: Disabled auto deep sleep\n");
  1266. }
  1267. if (ps_bitmap & BITMAP_STA_PS) {
  1268. mwifiex_dbg(adapter, CMD,
  1269. "cmd: Disabled STA power save\n");
  1270. if (adapter->sleep_period.period) {
  1271. adapter->delay_null_pkt = false;
  1272. adapter->tx_lock_flag = false;
  1273. adapter->pps_uapsd_mode = false;
  1274. }
  1275. }
  1276. } else if (action == GET_PS) {
  1277. if (ps_bitmap & BITMAP_STA_PS)
  1278. adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
  1279. else
  1280. adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM;
  1281. mwifiex_dbg(adapter, CMD,
  1282. "cmd: ps_bitmap=%#x\n", ps_bitmap);
  1283. if (pm_cfg) {
  1284. /* This section is for get power save mode */
  1285. if (ps_bitmap & BITMAP_STA_PS)
  1286. pm_cfg->param.ps_mode = 1;
  1287. else
  1288. pm_cfg->param.ps_mode = 0;
  1289. }
  1290. }
  1291. return 0;
  1292. }
  1293. /*
  1294. * This function prepares command to get hardware specifications.
  1295. *
  1296. * Preparation includes -
  1297. * - Setting command ID, action and proper size
  1298. * - Setting permanent address parameter
  1299. * - Ensuring correct endian-ness
  1300. */
  1301. int mwifiex_cmd_get_hw_spec(struct mwifiex_private *priv,
  1302. struct host_cmd_ds_command *cmd)
  1303. {
  1304. struct host_cmd_ds_get_hw_spec *hw_spec = &cmd->params.hw_spec;
  1305. cmd->command = cpu_to_le16(HostCmd_CMD_GET_HW_SPEC);
  1306. cmd->size =
  1307. cpu_to_le16(sizeof(struct host_cmd_ds_get_hw_spec) + S_DS_GEN);
  1308. memcpy(hw_spec->permanent_addr, priv->curr_addr, ETH_ALEN);
  1309. return 0;
  1310. }
  1311. /*
  1312. * This function handles the command response of get hardware
  1313. * specifications.
  1314. *
  1315. * Handling includes changing the header fields into CPU format
  1316. * and saving/updating the following parameters in driver -
  1317. * - Firmware capability information
  1318. * - Firmware band settings
  1319. * - Ad-hoc start band and channel
  1320. * - Ad-hoc 11n activation status
  1321. * - Firmware release number
  1322. * - Number of antennas
  1323. * - Hardware address
  1324. * - Hardware interface version
  1325. * - Firmware version
  1326. * - Region code
  1327. * - 11n capabilities
  1328. * - MCS support fields
  1329. * - MP end port
  1330. */
  1331. int mwifiex_ret_get_hw_spec(struct mwifiex_private *priv,
  1332. struct host_cmd_ds_command *resp)
  1333. {
  1334. struct host_cmd_ds_get_hw_spec *hw_spec = &resp->params.hw_spec;
  1335. struct mwifiex_adapter *adapter = priv->adapter;
  1336. struct mwifiex_ie_types_header *tlv;
  1337. struct hw_spec_api_rev *api_rev;
  1338. struct hw_spec_max_conn *max_conn;
  1339. u16 resp_size, api_id;
  1340. int i, left_len, parsed_len = 0;
  1341. adapter->fw_cap_info = le32_to_cpu(hw_spec->fw_cap_info);
  1342. if (IS_SUPPORT_MULTI_BANDS(adapter))
  1343. adapter->fw_bands = (u8) GET_FW_DEFAULT_BANDS(adapter);
  1344. else
  1345. adapter->fw_bands = BAND_B;
  1346. adapter->config_bands = adapter->fw_bands;
  1347. if (adapter->fw_bands & BAND_A) {
  1348. if (adapter->fw_bands & BAND_GN) {
  1349. adapter->config_bands |= BAND_AN;
  1350. adapter->fw_bands |= BAND_AN;
  1351. }
  1352. if (adapter->fw_bands & BAND_AN) {
  1353. adapter->adhoc_start_band = BAND_A | BAND_AN;
  1354. adapter->adhoc_11n_enabled = true;
  1355. } else {
  1356. adapter->adhoc_start_band = BAND_A;
  1357. }
  1358. priv->adhoc_channel = DEFAULT_AD_HOC_CHANNEL_A;
  1359. } else if (adapter->fw_bands & BAND_GN) {
  1360. adapter->adhoc_start_band = BAND_G | BAND_B | BAND_GN;
  1361. priv->adhoc_channel = DEFAULT_AD_HOC_CHANNEL;
  1362. adapter->adhoc_11n_enabled = true;
  1363. } else if (adapter->fw_bands & BAND_G) {
  1364. adapter->adhoc_start_band = BAND_G | BAND_B;
  1365. priv->adhoc_channel = DEFAULT_AD_HOC_CHANNEL;
  1366. } else if (adapter->fw_bands & BAND_B) {
  1367. adapter->adhoc_start_band = BAND_B;
  1368. priv->adhoc_channel = DEFAULT_AD_HOC_CHANNEL;
  1369. }
  1370. adapter->fw_release_number = le32_to_cpu(hw_spec->fw_release_number);
  1371. adapter->fw_api_ver = (adapter->fw_release_number >> 16) & 0xff;
  1372. adapter->number_of_antenna =
  1373. le16_to_cpu(hw_spec->number_of_antenna) & 0xf;
  1374. if (le32_to_cpu(hw_spec->dot_11ac_dev_cap)) {
  1375. adapter->is_hw_11ac_capable = true;
  1376. /* Copy 11AC cap */
  1377. adapter->hw_dot_11ac_dev_cap =
  1378. le32_to_cpu(hw_spec->dot_11ac_dev_cap);
  1379. adapter->usr_dot_11ac_dev_cap_bg = adapter->hw_dot_11ac_dev_cap
  1380. & ~MWIFIEX_DEF_11AC_CAP_BF_RESET_MASK;
  1381. adapter->usr_dot_11ac_dev_cap_a = adapter->hw_dot_11ac_dev_cap
  1382. & ~MWIFIEX_DEF_11AC_CAP_BF_RESET_MASK;
  1383. /* Copy 11AC mcs */
  1384. adapter->hw_dot_11ac_mcs_support =
  1385. le32_to_cpu(hw_spec->dot_11ac_mcs_support);
  1386. adapter->usr_dot_11ac_mcs_support =
  1387. adapter->hw_dot_11ac_mcs_support;
  1388. } else {
  1389. adapter->is_hw_11ac_capable = false;
  1390. }
  1391. resp_size = le16_to_cpu(resp->size) - S_DS_GEN;
  1392. if (resp_size > sizeof(struct host_cmd_ds_get_hw_spec)) {
  1393. /* we have variable HW SPEC information */
  1394. left_len = resp_size - sizeof(struct host_cmd_ds_get_hw_spec);
  1395. while (left_len > sizeof(struct mwifiex_ie_types_header)) {
  1396. tlv = (void *)&hw_spec->tlvs + parsed_len;
  1397. switch (le16_to_cpu(tlv->type)) {
  1398. case TLV_TYPE_API_REV:
  1399. api_rev = (struct hw_spec_api_rev *)tlv;
  1400. api_id = le16_to_cpu(api_rev->api_id);
  1401. switch (api_id) {
  1402. case KEY_API_VER_ID:
  1403. adapter->key_api_major_ver =
  1404. api_rev->major_ver;
  1405. adapter->key_api_minor_ver =
  1406. api_rev->minor_ver;
  1407. mwifiex_dbg(adapter, INFO,
  1408. "key_api v%d.%d\n",
  1409. adapter->key_api_major_ver,
  1410. adapter->key_api_minor_ver);
  1411. break;
  1412. case FW_API_VER_ID:
  1413. adapter->fw_api_ver =
  1414. api_rev->major_ver;
  1415. mwifiex_dbg(adapter, INFO,
  1416. "Firmware api version %d.%d\n",
  1417. adapter->fw_api_ver,
  1418. api_rev->minor_ver);
  1419. break;
  1420. case UAP_FW_API_VER_ID:
  1421. mwifiex_dbg(adapter, INFO,
  1422. "uAP api version %d.%d\n",
  1423. api_rev->major_ver,
  1424. api_rev->minor_ver);
  1425. break;
  1426. case CHANRPT_API_VER_ID:
  1427. mwifiex_dbg(adapter, INFO,
  1428. "channel report api version %d.%d\n",
  1429. api_rev->major_ver,
  1430. api_rev->minor_ver);
  1431. break;
  1432. default:
  1433. mwifiex_dbg(adapter, FATAL,
  1434. "Unknown api_id: %d\n",
  1435. api_id);
  1436. break;
  1437. }
  1438. break;
  1439. case TLV_TYPE_MAX_CONN:
  1440. max_conn = (struct hw_spec_max_conn *)tlv;
  1441. adapter->max_p2p_conn = max_conn->max_p2p_conn;
  1442. adapter->max_sta_conn = max_conn->max_sta_conn;
  1443. mwifiex_dbg(adapter, INFO,
  1444. "max p2p connections: %u\n",
  1445. adapter->max_p2p_conn);
  1446. mwifiex_dbg(adapter, INFO,
  1447. "max sta connections: %u\n",
  1448. adapter->max_sta_conn);
  1449. break;
  1450. default:
  1451. mwifiex_dbg(adapter, FATAL,
  1452. "Unknown GET_HW_SPEC TLV type: %#x\n",
  1453. le16_to_cpu(tlv->type));
  1454. break;
  1455. }
  1456. parsed_len += le16_to_cpu(tlv->len) +
  1457. sizeof(struct mwifiex_ie_types_header);
  1458. left_len -= le16_to_cpu(tlv->len) +
  1459. sizeof(struct mwifiex_ie_types_header);
  1460. }
  1461. }
  1462. mwifiex_dbg(adapter, INFO,
  1463. "info: GET_HW_SPEC: fw_release_number- %#x\n",
  1464. adapter->fw_release_number);
  1465. mwifiex_dbg(adapter, INFO,
  1466. "info: GET_HW_SPEC: permanent addr: %pM\n",
  1467. hw_spec->permanent_addr);
  1468. mwifiex_dbg(adapter, INFO,
  1469. "info: GET_HW_SPEC: hw_if_version=%#x version=%#x\n",
  1470. le16_to_cpu(hw_spec->hw_if_version),
  1471. le16_to_cpu(hw_spec->version));
  1472. ether_addr_copy(priv->adapter->perm_addr, hw_spec->permanent_addr);
  1473. adapter->region_code = le16_to_cpu(hw_spec->region_code);
  1474. for (i = 0; i < MWIFIEX_MAX_REGION_CODE; i++)
  1475. /* Use the region code to search for the index */
  1476. if (adapter->region_code == region_code_index[i])
  1477. break;
  1478. /* If it's unidentified region code, use the default (world) */
  1479. if (i >= MWIFIEX_MAX_REGION_CODE) {
  1480. adapter->region_code = 0x00;
  1481. mwifiex_dbg(adapter, WARN,
  1482. "cmd: unknown region code, use default (USA)\n");
  1483. }
  1484. adapter->hw_dot_11n_dev_cap = le32_to_cpu(hw_spec->dot_11n_dev_cap);
  1485. adapter->hw_dev_mcs_support = hw_spec->dev_mcs_support;
  1486. adapter->user_dev_mcs_support = adapter->hw_dev_mcs_support;
  1487. if (adapter->if_ops.update_mp_end_port)
  1488. adapter->if_ops.update_mp_end_port(adapter,
  1489. le16_to_cpu(hw_spec->mp_end_port));
  1490. if (adapter->fw_api_ver == MWIFIEX_FW_V15)
  1491. adapter->scan_chan_gap_enabled = true;
  1492. return 0;
  1493. }
  1494. /* This function handles the command response of hs wakeup reason
  1495. * command.
  1496. */
  1497. int mwifiex_ret_wakeup_reason(struct mwifiex_private *priv,
  1498. struct host_cmd_ds_command *resp,
  1499. struct host_cmd_ds_wakeup_reason *wakeup_reason)
  1500. {
  1501. wakeup_reason->wakeup_reason =
  1502. resp->params.hs_wakeup_reason.wakeup_reason;
  1503. return 0;
  1504. }