cmdevt.c 48 KB

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