cmdevt.c 50 KB

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