cmdevt.c 50 KB

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