cmdevt.c 50 KB

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