cmdevt.c 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546
  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 + (MWIFIEX_TIMER_10S * HZ) / 1000);
  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. ret = mwifiex_uap_prepare_cmd(priv, cmd_no, cmd_action,
  502. cmd_oid, data_buf,
  503. cmd_ptr);
  504. break;
  505. default:
  506. ret = mwifiex_sta_prepare_cmd(priv, cmd_no, cmd_action,
  507. cmd_oid, data_buf,
  508. cmd_ptr);
  509. break;
  510. }
  511. } else {
  512. ret = mwifiex_cmd_host_cmd(priv, cmd_ptr, data_buf);
  513. cmd_node->cmd_flag |= CMD_F_HOSTCMD;
  514. }
  515. /* Return error, since the command preparation failed */
  516. if (ret) {
  517. dev_err(adapter->dev, "PREP_CMD: cmd %#x preparation failed\n",
  518. cmd_no);
  519. mwifiex_insert_cmd_to_free_q(adapter, cmd_node);
  520. return -1;
  521. }
  522. /* Send command */
  523. if (cmd_no == HostCmd_CMD_802_11_SCAN) {
  524. mwifiex_queue_scan_cmd(priv, cmd_node);
  525. } else {
  526. mwifiex_insert_cmd_to_pending_q(adapter, cmd_node, true);
  527. queue_work(adapter->workqueue, &adapter->main_work);
  528. if (cmd_node->wait_q_enabled)
  529. ret = mwifiex_wait_queue_complete(adapter, cmd_node);
  530. }
  531. return ret;
  532. }
  533. /*
  534. * This function returns a command to the command free queue.
  535. *
  536. * The function also calls the completion callback if required, before
  537. * cleaning the command node and re-inserting it into the free queue.
  538. */
  539. void
  540. mwifiex_insert_cmd_to_free_q(struct mwifiex_adapter *adapter,
  541. struct cmd_ctrl_node *cmd_node)
  542. {
  543. unsigned long flags;
  544. if (!cmd_node)
  545. return;
  546. if (cmd_node->wait_q_enabled)
  547. mwifiex_complete_cmd(adapter, cmd_node);
  548. /* Clean the node */
  549. mwifiex_clean_cmd_node(adapter, cmd_node);
  550. /* Insert node into cmd_free_q */
  551. spin_lock_irqsave(&adapter->cmd_free_q_lock, flags);
  552. list_add_tail(&cmd_node->list, &adapter->cmd_free_q);
  553. spin_unlock_irqrestore(&adapter->cmd_free_q_lock, flags);
  554. }
  555. /* This function reuses a command node. */
  556. void mwifiex_recycle_cmd_node(struct mwifiex_adapter *adapter,
  557. struct cmd_ctrl_node *cmd_node)
  558. {
  559. struct host_cmd_ds_command *host_cmd = (void *)cmd_node->cmd_skb->data;
  560. mwifiex_insert_cmd_to_free_q(adapter, cmd_node);
  561. atomic_dec(&adapter->cmd_pending);
  562. dev_dbg(adapter->dev, "cmd: FREE_CMD: cmd=%#x, cmd_pending=%d\n",
  563. le16_to_cpu(host_cmd->command),
  564. atomic_read(&adapter->cmd_pending));
  565. }
  566. /*
  567. * This function queues a command to the command pending queue.
  568. *
  569. * This in effect adds the command to the command list to be executed.
  570. * Exit PS command is handled specially, by placing it always to the
  571. * front of the command queue.
  572. */
  573. void
  574. mwifiex_insert_cmd_to_pending_q(struct mwifiex_adapter *adapter,
  575. struct cmd_ctrl_node *cmd_node, u32 add_tail)
  576. {
  577. struct host_cmd_ds_command *host_cmd = NULL;
  578. u16 command;
  579. unsigned long flags;
  580. host_cmd = (struct host_cmd_ds_command *) (cmd_node->cmd_skb->data);
  581. if (!host_cmd) {
  582. dev_err(adapter->dev, "QUEUE_CMD: host_cmd is NULL\n");
  583. return;
  584. }
  585. command = le16_to_cpu(host_cmd->command);
  586. /* Exit_PS command needs to be queued in the header always. */
  587. if (command == HostCmd_CMD_802_11_PS_MODE_ENH) {
  588. struct host_cmd_ds_802_11_ps_mode_enh *pm =
  589. &host_cmd->params.psmode_enh;
  590. if ((le16_to_cpu(pm->action) == DIS_PS) ||
  591. (le16_to_cpu(pm->action) == DIS_AUTO_PS)) {
  592. if (adapter->ps_state != PS_STATE_AWAKE)
  593. add_tail = false;
  594. }
  595. }
  596. spin_lock_irqsave(&adapter->cmd_pending_q_lock, flags);
  597. if (add_tail)
  598. list_add_tail(&cmd_node->list, &adapter->cmd_pending_q);
  599. else
  600. list_add(&cmd_node->list, &adapter->cmd_pending_q);
  601. spin_unlock_irqrestore(&adapter->cmd_pending_q_lock, flags);
  602. atomic_inc(&adapter->cmd_pending);
  603. dev_dbg(adapter->dev, "cmd: QUEUE_CMD: cmd=%#x, cmd_pending=%d\n",
  604. command, atomic_read(&adapter->cmd_pending));
  605. }
  606. /*
  607. * This function executes the next command in command pending queue.
  608. *
  609. * This function will fail if a command is already in processing stage,
  610. * otherwise it will dequeue the first command from the command pending
  611. * queue and send to the firmware.
  612. *
  613. * If the device is currently in host sleep mode, any commands, except the
  614. * host sleep configuration command will de-activate the host sleep. For PS
  615. * mode, the function will put the firmware back to sleep if applicable.
  616. */
  617. int mwifiex_exec_next_cmd(struct mwifiex_adapter *adapter)
  618. {
  619. struct mwifiex_private *priv;
  620. struct cmd_ctrl_node *cmd_node;
  621. int ret = 0;
  622. struct host_cmd_ds_command *host_cmd;
  623. unsigned long cmd_flags;
  624. unsigned long cmd_pending_q_flags;
  625. /* Check if already in processing */
  626. if (adapter->curr_cmd) {
  627. dev_err(adapter->dev, "EXEC_NEXT_CMD: cmd in processing\n");
  628. return -1;
  629. }
  630. spin_lock_irqsave(&adapter->mwifiex_cmd_lock, cmd_flags);
  631. /* Check if any command is pending */
  632. spin_lock_irqsave(&adapter->cmd_pending_q_lock, cmd_pending_q_flags);
  633. if (list_empty(&adapter->cmd_pending_q)) {
  634. spin_unlock_irqrestore(&adapter->cmd_pending_q_lock,
  635. cmd_pending_q_flags);
  636. spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, cmd_flags);
  637. return 0;
  638. }
  639. cmd_node = list_first_entry(&adapter->cmd_pending_q,
  640. struct cmd_ctrl_node, list);
  641. spin_unlock_irqrestore(&adapter->cmd_pending_q_lock,
  642. cmd_pending_q_flags);
  643. host_cmd = (struct host_cmd_ds_command *) (cmd_node->cmd_skb->data);
  644. priv = cmd_node->priv;
  645. if (adapter->ps_state != PS_STATE_AWAKE) {
  646. dev_err(adapter->dev, "%s: cannot send cmd in sleep state,"
  647. " this should not happen\n", __func__);
  648. spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, cmd_flags);
  649. return ret;
  650. }
  651. spin_lock_irqsave(&adapter->cmd_pending_q_lock, cmd_pending_q_flags);
  652. list_del(&cmd_node->list);
  653. spin_unlock_irqrestore(&adapter->cmd_pending_q_lock,
  654. cmd_pending_q_flags);
  655. spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, cmd_flags);
  656. ret = mwifiex_dnld_cmd_to_fw(priv, cmd_node);
  657. priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
  658. /* Any command sent to the firmware when host is in sleep
  659. * mode should de-configure host sleep. We should skip the
  660. * host sleep configuration command itself though
  661. */
  662. if (priv && (host_cmd->command !=
  663. cpu_to_le16(HostCmd_CMD_802_11_HS_CFG_ENH))) {
  664. if (adapter->hs_activated) {
  665. adapter->is_hs_configured = false;
  666. mwifiex_hs_activated_event(priv, false);
  667. }
  668. }
  669. return ret;
  670. }
  671. /*
  672. * This function handles the command response.
  673. *
  674. * After processing, the function cleans the command node and puts
  675. * it back to the command free queue.
  676. */
  677. int mwifiex_process_cmdresp(struct mwifiex_adapter *adapter)
  678. {
  679. struct host_cmd_ds_command *resp;
  680. struct mwifiex_private *priv =
  681. mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
  682. int ret = 0;
  683. uint16_t orig_cmdresp_no;
  684. uint16_t cmdresp_no;
  685. uint16_t cmdresp_result;
  686. struct timeval tstamp;
  687. unsigned long flags;
  688. /* Now we got response from FW, cancel the command timer */
  689. del_timer(&adapter->cmd_timer);
  690. if (!adapter->curr_cmd || !adapter->curr_cmd->resp_skb) {
  691. resp = (struct host_cmd_ds_command *) adapter->upld_buf;
  692. dev_err(adapter->dev, "CMD_RESP: NULL curr_cmd, %#x\n",
  693. le16_to_cpu(resp->command));
  694. return -1;
  695. }
  696. adapter->num_cmd_timeout = 0;
  697. resp = (struct host_cmd_ds_command *) adapter->curr_cmd->resp_skb->data;
  698. if (adapter->curr_cmd->cmd_flag & CMD_F_CANCELED) {
  699. dev_err(adapter->dev, "CMD_RESP: %#x been canceled\n",
  700. le16_to_cpu(resp->command));
  701. mwifiex_recycle_cmd_node(adapter, adapter->curr_cmd);
  702. spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
  703. adapter->curr_cmd = NULL;
  704. spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
  705. return -1;
  706. }
  707. if (adapter->curr_cmd->cmd_flag & CMD_F_HOSTCMD) {
  708. /* Copy original response back to response buffer */
  709. struct mwifiex_ds_misc_cmd *hostcmd;
  710. uint16_t size = le16_to_cpu(resp->size);
  711. dev_dbg(adapter->dev, "info: host cmd resp size = %d\n", size);
  712. size = min_t(u16, size, MWIFIEX_SIZE_OF_CMD_BUFFER);
  713. if (adapter->curr_cmd->data_buf) {
  714. hostcmd = adapter->curr_cmd->data_buf;
  715. hostcmd->len = size;
  716. memcpy(hostcmd->cmd, resp, size);
  717. }
  718. }
  719. orig_cmdresp_no = le16_to_cpu(resp->command);
  720. /* Get BSS number and corresponding priv */
  721. priv = mwifiex_get_priv_by_id(adapter,
  722. HostCmd_GET_BSS_NO(le16_to_cpu(resp->seq_num)),
  723. HostCmd_GET_BSS_TYPE(le16_to_cpu(resp->seq_num)));
  724. if (!priv)
  725. priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
  726. /* Clear RET_BIT from HostCmd */
  727. resp->command = cpu_to_le16(orig_cmdresp_no & HostCmd_CMD_ID_MASK);
  728. cmdresp_no = le16_to_cpu(resp->command);
  729. cmdresp_result = le16_to_cpu(resp->result);
  730. /* Save the last command response to debug log */
  731. adapter->dbg.last_cmd_resp_index =
  732. (adapter->dbg.last_cmd_resp_index + 1) % DBG_CMD_NUM;
  733. adapter->dbg.last_cmd_resp_id[adapter->dbg.last_cmd_resp_index] =
  734. orig_cmdresp_no;
  735. do_gettimeofday(&tstamp);
  736. dev_dbg(adapter->dev, "cmd: CMD_RESP: (%lu.%lu): 0x%x, result %d,"
  737. " len %d, seqno 0x%x\n",
  738. tstamp.tv_sec, tstamp.tv_usec, orig_cmdresp_no, cmdresp_result,
  739. le16_to_cpu(resp->size), le16_to_cpu(resp->seq_num));
  740. if (!(orig_cmdresp_no & HostCmd_RET_BIT)) {
  741. dev_err(adapter->dev, "CMD_RESP: invalid cmd resp\n");
  742. if (adapter->curr_cmd->wait_q_enabled)
  743. adapter->cmd_wait_q.status = -1;
  744. mwifiex_recycle_cmd_node(adapter, adapter->curr_cmd);
  745. spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
  746. adapter->curr_cmd = NULL;
  747. spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
  748. return -1;
  749. }
  750. if (adapter->curr_cmd->cmd_flag & CMD_F_HOSTCMD) {
  751. adapter->curr_cmd->cmd_flag &= ~CMD_F_HOSTCMD;
  752. if ((cmdresp_result == HostCmd_RESULT_OK) &&
  753. (cmdresp_no == HostCmd_CMD_802_11_HS_CFG_ENH))
  754. ret = mwifiex_ret_802_11_hs_cfg(priv, resp);
  755. } else {
  756. /* handle response */
  757. ret = mwifiex_process_sta_cmdresp(priv, cmdresp_no, resp);
  758. }
  759. /* Check init command response */
  760. if (adapter->hw_status == MWIFIEX_HW_STATUS_INITIALIZING) {
  761. if (ret) {
  762. dev_err(adapter->dev, "%s: cmd %#x failed during "
  763. "initialization\n", __func__, cmdresp_no);
  764. mwifiex_init_fw_complete(adapter);
  765. return -1;
  766. } else if (adapter->last_init_cmd == cmdresp_no)
  767. adapter->hw_status = MWIFIEX_HW_STATUS_INIT_DONE;
  768. }
  769. if (adapter->curr_cmd) {
  770. if (adapter->curr_cmd->wait_q_enabled)
  771. adapter->cmd_wait_q.status = ret;
  772. mwifiex_recycle_cmd_node(adapter, adapter->curr_cmd);
  773. spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
  774. adapter->curr_cmd = NULL;
  775. spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
  776. }
  777. return ret;
  778. }
  779. /*
  780. * This function handles the timeout of command sending.
  781. *
  782. * It will re-send the same command again.
  783. */
  784. void
  785. mwifiex_cmd_timeout_func(unsigned long function_context)
  786. {
  787. struct mwifiex_adapter *adapter =
  788. (struct mwifiex_adapter *) function_context;
  789. struct cmd_ctrl_node *cmd_node;
  790. struct timeval tstamp;
  791. adapter->num_cmd_timeout++;
  792. adapter->dbg.num_cmd_timeout++;
  793. if (!adapter->curr_cmd) {
  794. dev_dbg(adapter->dev, "cmd: empty curr_cmd\n");
  795. return;
  796. }
  797. cmd_node = adapter->curr_cmd;
  798. if (cmd_node) {
  799. adapter->dbg.timeout_cmd_id =
  800. adapter->dbg.last_cmd_id[adapter->dbg.last_cmd_index];
  801. adapter->dbg.timeout_cmd_act =
  802. adapter->dbg.last_cmd_act[adapter->dbg.last_cmd_index];
  803. do_gettimeofday(&tstamp);
  804. dev_err(adapter->dev,
  805. "%s: Timeout cmd id (%lu.%lu) = %#x, act = %#x\n",
  806. __func__, tstamp.tv_sec, tstamp.tv_usec,
  807. adapter->dbg.timeout_cmd_id,
  808. adapter->dbg.timeout_cmd_act);
  809. dev_err(adapter->dev, "num_data_h2c_failure = %d\n",
  810. adapter->dbg.num_tx_host_to_card_failure);
  811. dev_err(adapter->dev, "num_cmd_h2c_failure = %d\n",
  812. adapter->dbg.num_cmd_host_to_card_failure);
  813. dev_err(adapter->dev, "num_cmd_timeout = %d\n",
  814. adapter->dbg.num_cmd_timeout);
  815. dev_err(adapter->dev, "num_tx_timeout = %d\n",
  816. adapter->dbg.num_tx_timeout);
  817. dev_err(adapter->dev, "last_cmd_index = %d\n",
  818. adapter->dbg.last_cmd_index);
  819. dev_err(adapter->dev, "last_cmd_id: %*ph\n",
  820. (int)sizeof(adapter->dbg.last_cmd_id),
  821. adapter->dbg.last_cmd_id);
  822. dev_err(adapter->dev, "last_cmd_act: %*ph\n",
  823. (int)sizeof(adapter->dbg.last_cmd_act),
  824. adapter->dbg.last_cmd_act);
  825. dev_err(adapter->dev, "last_cmd_resp_index = %d\n",
  826. adapter->dbg.last_cmd_resp_index);
  827. dev_err(adapter->dev, "last_cmd_resp_id: %*ph\n",
  828. (int)sizeof(adapter->dbg.last_cmd_resp_id),
  829. adapter->dbg.last_cmd_resp_id);
  830. dev_err(adapter->dev, "last_event_index = %d\n",
  831. adapter->dbg.last_event_index);
  832. dev_err(adapter->dev, "last_event: %*ph\n",
  833. (int)sizeof(adapter->dbg.last_event),
  834. adapter->dbg.last_event);
  835. dev_err(adapter->dev, "data_sent=%d cmd_sent=%d\n",
  836. adapter->data_sent, adapter->cmd_sent);
  837. dev_err(adapter->dev, "ps_mode=%d ps_state=%d\n",
  838. adapter->ps_mode, adapter->ps_state);
  839. if (cmd_node->wait_q_enabled) {
  840. adapter->cmd_wait_q.status = -ETIMEDOUT;
  841. wake_up_interruptible(&adapter->cmd_wait_q.wait);
  842. mwifiex_cancel_pending_ioctl(adapter);
  843. /* reset cmd_sent flag to unblock new commands */
  844. adapter->cmd_sent = false;
  845. }
  846. }
  847. if (adapter->hw_status == MWIFIEX_HW_STATUS_INITIALIZING)
  848. mwifiex_init_fw_complete(adapter);
  849. if (adapter->if_ops.card_reset)
  850. adapter->if_ops.card_reset(adapter);
  851. }
  852. /*
  853. * This function cancels all the pending commands.
  854. *
  855. * The current command, all commands in command pending queue and all scan
  856. * commands in scan pending queue are cancelled. All the completion callbacks
  857. * are called with failure status to ensure cleanup.
  858. */
  859. void
  860. mwifiex_cancel_all_pending_cmd(struct mwifiex_adapter *adapter)
  861. {
  862. struct cmd_ctrl_node *cmd_node = NULL, *tmp_node;
  863. unsigned long flags;
  864. /* Cancel current cmd */
  865. if ((adapter->curr_cmd) && (adapter->curr_cmd->wait_q_enabled)) {
  866. spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
  867. adapter->curr_cmd->wait_q_enabled = false;
  868. spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
  869. adapter->cmd_wait_q.status = -1;
  870. mwifiex_complete_cmd(adapter, adapter->curr_cmd);
  871. }
  872. /* Cancel all pending command */
  873. spin_lock_irqsave(&adapter->cmd_pending_q_lock, flags);
  874. list_for_each_entry_safe(cmd_node, tmp_node,
  875. &adapter->cmd_pending_q, list) {
  876. list_del(&cmd_node->list);
  877. spin_unlock_irqrestore(&adapter->cmd_pending_q_lock, flags);
  878. if (cmd_node->wait_q_enabled) {
  879. adapter->cmd_wait_q.status = -1;
  880. mwifiex_complete_cmd(adapter, cmd_node);
  881. cmd_node->wait_q_enabled = false;
  882. }
  883. mwifiex_recycle_cmd_node(adapter, cmd_node);
  884. spin_lock_irqsave(&adapter->cmd_pending_q_lock, flags);
  885. }
  886. spin_unlock_irqrestore(&adapter->cmd_pending_q_lock, flags);
  887. /* Cancel all pending scan command */
  888. spin_lock_irqsave(&adapter->scan_pending_q_lock, flags);
  889. list_for_each_entry_safe(cmd_node, tmp_node,
  890. &adapter->scan_pending_q, list) {
  891. list_del(&cmd_node->list);
  892. spin_unlock_irqrestore(&adapter->scan_pending_q_lock, flags);
  893. cmd_node->wait_q_enabled = false;
  894. mwifiex_insert_cmd_to_free_q(adapter, cmd_node);
  895. spin_lock_irqsave(&adapter->scan_pending_q_lock, flags);
  896. }
  897. spin_unlock_irqrestore(&adapter->scan_pending_q_lock, flags);
  898. spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
  899. adapter->scan_processing = false;
  900. spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
  901. }
  902. /*
  903. * This function cancels all pending commands that matches with
  904. * the given IOCTL request.
  905. *
  906. * Both the current command buffer and the pending command queue are
  907. * searched for matching IOCTL request. The completion callback of
  908. * the matched command is called with failure status to ensure cleanup.
  909. * In case of scan commands, all pending commands in scan pending queue
  910. * are cancelled.
  911. */
  912. void
  913. mwifiex_cancel_pending_ioctl(struct mwifiex_adapter *adapter)
  914. {
  915. struct cmd_ctrl_node *cmd_node = NULL, *tmp_node = NULL;
  916. unsigned long cmd_flags;
  917. unsigned long scan_pending_q_flags;
  918. uint16_t cancel_scan_cmd = false;
  919. if ((adapter->curr_cmd) &&
  920. (adapter->curr_cmd->wait_q_enabled)) {
  921. spin_lock_irqsave(&adapter->mwifiex_cmd_lock, cmd_flags);
  922. cmd_node = adapter->curr_cmd;
  923. cmd_node->wait_q_enabled = false;
  924. cmd_node->cmd_flag |= CMD_F_CANCELED;
  925. mwifiex_recycle_cmd_node(adapter, cmd_node);
  926. mwifiex_complete_cmd(adapter, adapter->curr_cmd);
  927. adapter->curr_cmd = NULL;
  928. spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, cmd_flags);
  929. }
  930. /* Cancel all pending scan command */
  931. spin_lock_irqsave(&adapter->scan_pending_q_lock,
  932. scan_pending_q_flags);
  933. list_for_each_entry_safe(cmd_node, tmp_node,
  934. &adapter->scan_pending_q, list) {
  935. list_del(&cmd_node->list);
  936. spin_unlock_irqrestore(&adapter->scan_pending_q_lock,
  937. scan_pending_q_flags);
  938. cmd_node->wait_q_enabled = false;
  939. mwifiex_insert_cmd_to_free_q(adapter, cmd_node);
  940. spin_lock_irqsave(&adapter->scan_pending_q_lock,
  941. scan_pending_q_flags);
  942. cancel_scan_cmd = true;
  943. }
  944. spin_unlock_irqrestore(&adapter->scan_pending_q_lock,
  945. scan_pending_q_flags);
  946. if (cancel_scan_cmd) {
  947. spin_lock_irqsave(&adapter->mwifiex_cmd_lock, cmd_flags);
  948. adapter->scan_processing = false;
  949. spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, cmd_flags);
  950. }
  951. adapter->cmd_wait_q.status = -1;
  952. }
  953. /*
  954. * This function sends the sleep confirm command to firmware, if
  955. * possible.
  956. *
  957. * The sleep confirm command cannot be issued if command response,
  958. * data response or event response is awaiting handling, or if we
  959. * are in the middle of sending a command, or expecting a command
  960. * response.
  961. */
  962. void
  963. mwifiex_check_ps_cond(struct mwifiex_adapter *adapter)
  964. {
  965. if (!adapter->cmd_sent &&
  966. !adapter->curr_cmd && !IS_CARD_RX_RCVD(adapter))
  967. mwifiex_dnld_sleep_confirm_cmd(adapter);
  968. else
  969. dev_dbg(adapter->dev,
  970. "cmd: Delay Sleep Confirm (%s%s%s)\n",
  971. (adapter->cmd_sent) ? "D" : "",
  972. (adapter->curr_cmd) ? "C" : "",
  973. (IS_CARD_RX_RCVD(adapter)) ? "R" : "");
  974. }
  975. /*
  976. * This function sends a Host Sleep activated event to applications.
  977. *
  978. * This event is generated by the driver, with a blank event body.
  979. */
  980. void
  981. mwifiex_hs_activated_event(struct mwifiex_private *priv, u8 activated)
  982. {
  983. if (activated) {
  984. if (priv->adapter->is_hs_configured) {
  985. priv->adapter->hs_activated = true;
  986. mwifiex_update_rxreor_flags(priv->adapter,
  987. RXREOR_FORCE_NO_DROP);
  988. dev_dbg(priv->adapter->dev, "event: hs_activated\n");
  989. priv->adapter->hs_activate_wait_q_woken = true;
  990. wake_up_interruptible(
  991. &priv->adapter->hs_activate_wait_q);
  992. } else {
  993. dev_dbg(priv->adapter->dev, "event: HS not configured\n");
  994. }
  995. } else {
  996. dev_dbg(priv->adapter->dev, "event: hs_deactivated\n");
  997. priv->adapter->hs_activated = false;
  998. }
  999. }
  1000. /*
  1001. * This function handles the command response of a Host Sleep configuration
  1002. * command.
  1003. *
  1004. * Handling includes changing the header fields into CPU format
  1005. * and setting the current host sleep activation status in driver.
  1006. *
  1007. * In case host sleep status change, the function generates an event to
  1008. * notify the applications.
  1009. */
  1010. int mwifiex_ret_802_11_hs_cfg(struct mwifiex_private *priv,
  1011. struct host_cmd_ds_command *resp)
  1012. {
  1013. struct mwifiex_adapter *adapter = priv->adapter;
  1014. struct host_cmd_ds_802_11_hs_cfg_enh *phs_cfg =
  1015. &resp->params.opt_hs_cfg;
  1016. uint32_t conditions = le32_to_cpu(phs_cfg->params.hs_config.conditions);
  1017. if (phs_cfg->action == cpu_to_le16(HS_ACTIVATE) &&
  1018. adapter->iface_type == MWIFIEX_SDIO) {
  1019. mwifiex_hs_activated_event(priv, true);
  1020. return 0;
  1021. } else {
  1022. dev_dbg(adapter->dev, "cmd: CMD_RESP: HS_CFG cmd reply"
  1023. " result=%#x, conditions=0x%x gpio=0x%x gap=0x%x\n",
  1024. resp->result, conditions,
  1025. phs_cfg->params.hs_config.gpio,
  1026. phs_cfg->params.hs_config.gap);
  1027. }
  1028. if (conditions != HS_CFG_CANCEL) {
  1029. adapter->is_hs_configured = true;
  1030. if (adapter->iface_type == MWIFIEX_USB ||
  1031. adapter->iface_type == MWIFIEX_PCIE)
  1032. mwifiex_hs_activated_event(priv, true);
  1033. } else {
  1034. adapter->is_hs_configured = false;
  1035. if (adapter->hs_activated)
  1036. mwifiex_hs_activated_event(priv, false);
  1037. }
  1038. return 0;
  1039. }
  1040. /*
  1041. * This function wakes up the adapter and generates a Host Sleep
  1042. * cancel event on receiving the power up interrupt.
  1043. */
  1044. void
  1045. mwifiex_process_hs_config(struct mwifiex_adapter *adapter)
  1046. {
  1047. dev_dbg(adapter->dev, "info: %s: auto cancelling host sleep"
  1048. " since there is interrupt from the firmware\n", __func__);
  1049. adapter->if_ops.wakeup(adapter);
  1050. adapter->hs_activated = false;
  1051. adapter->is_hs_configured = false;
  1052. mwifiex_hs_activated_event(mwifiex_get_priv(adapter,
  1053. MWIFIEX_BSS_ROLE_ANY),
  1054. false);
  1055. }
  1056. EXPORT_SYMBOL_GPL(mwifiex_process_hs_config);
  1057. /*
  1058. * This function handles the command response of a sleep confirm command.
  1059. *
  1060. * The function sets the card state to SLEEP if the response indicates success.
  1061. */
  1062. void
  1063. mwifiex_process_sleep_confirm_resp(struct mwifiex_adapter *adapter,
  1064. u8 *pbuf, u32 upld_len)
  1065. {
  1066. struct host_cmd_ds_command *cmd = (struct host_cmd_ds_command *) pbuf;
  1067. struct mwifiex_private *priv =
  1068. mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
  1069. uint16_t result = le16_to_cpu(cmd->result);
  1070. uint16_t command = le16_to_cpu(cmd->command);
  1071. uint16_t seq_num = le16_to_cpu(cmd->seq_num);
  1072. if (!upld_len) {
  1073. dev_err(adapter->dev, "%s: cmd size is 0\n", __func__);
  1074. return;
  1075. }
  1076. /* Get BSS number and corresponding priv */
  1077. priv = mwifiex_get_priv_by_id(adapter, HostCmd_GET_BSS_NO(seq_num),
  1078. HostCmd_GET_BSS_TYPE(seq_num));
  1079. if (!priv)
  1080. priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
  1081. /* Update sequence number */
  1082. seq_num = HostCmd_GET_SEQ_NO(seq_num);
  1083. /* Clear RET_BIT from HostCmd */
  1084. command &= HostCmd_CMD_ID_MASK;
  1085. if (command != HostCmd_CMD_802_11_PS_MODE_ENH) {
  1086. dev_err(adapter->dev,
  1087. "%s: rcvd unexpected resp for cmd %#x, result = %x\n",
  1088. __func__, command, result);
  1089. return;
  1090. }
  1091. if (result) {
  1092. dev_err(adapter->dev, "%s: sleep confirm cmd failed\n",
  1093. __func__);
  1094. adapter->pm_wakeup_card_req = false;
  1095. adapter->ps_state = PS_STATE_AWAKE;
  1096. return;
  1097. }
  1098. adapter->pm_wakeup_card_req = true;
  1099. if (adapter->is_hs_configured)
  1100. mwifiex_hs_activated_event(mwifiex_get_priv
  1101. (adapter, MWIFIEX_BSS_ROLE_ANY),
  1102. true);
  1103. adapter->ps_state = PS_STATE_SLEEP;
  1104. cmd->command = cpu_to_le16(command);
  1105. cmd->seq_num = cpu_to_le16(seq_num);
  1106. }
  1107. EXPORT_SYMBOL_GPL(mwifiex_process_sleep_confirm_resp);
  1108. /*
  1109. * This function prepares an enhanced power mode command.
  1110. *
  1111. * This function can be used to disable power save or to configure
  1112. * power save with auto PS or STA PS or auto deep sleep.
  1113. *
  1114. * Preparation includes -
  1115. * - Setting command ID, action and proper size
  1116. * - Setting Power Save bitmap, PS parameters TLV, PS mode TLV,
  1117. * auto deep sleep TLV (as required)
  1118. * - Ensuring correct endian-ness
  1119. */
  1120. int mwifiex_cmd_enh_power_mode(struct mwifiex_private *priv,
  1121. struct host_cmd_ds_command *cmd,
  1122. u16 cmd_action, uint16_t ps_bitmap,
  1123. struct mwifiex_ds_auto_ds *auto_ds)
  1124. {
  1125. struct host_cmd_ds_802_11_ps_mode_enh *psmode_enh =
  1126. &cmd->params.psmode_enh;
  1127. u8 *tlv;
  1128. u16 cmd_size = 0;
  1129. cmd->command = cpu_to_le16(HostCmd_CMD_802_11_PS_MODE_ENH);
  1130. if (cmd_action == DIS_AUTO_PS) {
  1131. psmode_enh->action = cpu_to_le16(DIS_AUTO_PS);
  1132. psmode_enh->params.ps_bitmap = cpu_to_le16(ps_bitmap);
  1133. cmd->size = cpu_to_le16(S_DS_GEN + sizeof(psmode_enh->action) +
  1134. sizeof(psmode_enh->params.ps_bitmap));
  1135. } else if (cmd_action == GET_PS) {
  1136. psmode_enh->action = cpu_to_le16(GET_PS);
  1137. psmode_enh->params.ps_bitmap = cpu_to_le16(ps_bitmap);
  1138. cmd->size = cpu_to_le16(S_DS_GEN + sizeof(psmode_enh->action) +
  1139. sizeof(psmode_enh->params.ps_bitmap));
  1140. } else if (cmd_action == EN_AUTO_PS) {
  1141. psmode_enh->action = cpu_to_le16(EN_AUTO_PS);
  1142. psmode_enh->params.ps_bitmap = cpu_to_le16(ps_bitmap);
  1143. cmd_size = S_DS_GEN + sizeof(psmode_enh->action) +
  1144. sizeof(psmode_enh->params.ps_bitmap);
  1145. tlv = (u8 *) cmd + cmd_size;
  1146. if (ps_bitmap & BITMAP_STA_PS) {
  1147. struct mwifiex_adapter *adapter = priv->adapter;
  1148. struct mwifiex_ie_types_ps_param *ps_tlv =
  1149. (struct mwifiex_ie_types_ps_param *) tlv;
  1150. struct mwifiex_ps_param *ps_mode = &ps_tlv->param;
  1151. ps_tlv->header.type = cpu_to_le16(TLV_TYPE_PS_PARAM);
  1152. ps_tlv->header.len = cpu_to_le16(sizeof(*ps_tlv) -
  1153. sizeof(struct mwifiex_ie_types_header));
  1154. cmd_size += sizeof(*ps_tlv);
  1155. tlv += sizeof(*ps_tlv);
  1156. dev_dbg(adapter->dev, "cmd: PS Command: Enter PS\n");
  1157. ps_mode->null_pkt_interval =
  1158. cpu_to_le16(adapter->null_pkt_interval);
  1159. ps_mode->multiple_dtims =
  1160. cpu_to_le16(adapter->multiple_dtim);
  1161. ps_mode->bcn_miss_timeout =
  1162. cpu_to_le16(adapter->bcn_miss_time_out);
  1163. ps_mode->local_listen_interval =
  1164. cpu_to_le16(adapter->local_listen_interval);
  1165. ps_mode->adhoc_wake_period =
  1166. cpu_to_le16(adapter->adhoc_awake_period);
  1167. ps_mode->delay_to_ps =
  1168. cpu_to_le16(adapter->delay_to_ps);
  1169. ps_mode->mode = cpu_to_le16(adapter->enhanced_ps_mode);
  1170. }
  1171. if (ps_bitmap & BITMAP_AUTO_DS) {
  1172. struct mwifiex_ie_types_auto_ds_param *auto_ds_tlv =
  1173. (struct mwifiex_ie_types_auto_ds_param *) tlv;
  1174. u16 idletime = 0;
  1175. auto_ds_tlv->header.type =
  1176. cpu_to_le16(TLV_TYPE_AUTO_DS_PARAM);
  1177. auto_ds_tlv->header.len =
  1178. cpu_to_le16(sizeof(*auto_ds_tlv) -
  1179. sizeof(struct mwifiex_ie_types_header));
  1180. cmd_size += sizeof(*auto_ds_tlv);
  1181. tlv += sizeof(*auto_ds_tlv);
  1182. if (auto_ds)
  1183. idletime = auto_ds->idle_time;
  1184. dev_dbg(priv->adapter->dev,
  1185. "cmd: PS Command: Enter Auto Deep Sleep\n");
  1186. auto_ds_tlv->deep_sleep_timeout = cpu_to_le16(idletime);
  1187. }
  1188. cmd->size = cpu_to_le16(cmd_size);
  1189. }
  1190. return 0;
  1191. }
  1192. /*
  1193. * This function handles the command response of an enhanced power mode
  1194. * command.
  1195. *
  1196. * Handling includes changing the header fields into CPU format
  1197. * and setting the current enhanced power mode in driver.
  1198. */
  1199. int mwifiex_ret_enh_power_mode(struct mwifiex_private *priv,
  1200. struct host_cmd_ds_command *resp,
  1201. struct mwifiex_ds_pm_cfg *pm_cfg)
  1202. {
  1203. struct mwifiex_adapter *adapter = priv->adapter;
  1204. struct host_cmd_ds_802_11_ps_mode_enh *ps_mode =
  1205. &resp->params.psmode_enh;
  1206. uint16_t action = le16_to_cpu(ps_mode->action);
  1207. uint16_t ps_bitmap = le16_to_cpu(ps_mode->params.ps_bitmap);
  1208. uint16_t auto_ps_bitmap =
  1209. le16_to_cpu(ps_mode->params.ps_bitmap);
  1210. dev_dbg(adapter->dev,
  1211. "info: %s: PS_MODE cmd reply result=%#x action=%#X\n",
  1212. __func__, resp->result, action);
  1213. if (action == EN_AUTO_PS) {
  1214. if (auto_ps_bitmap & BITMAP_AUTO_DS) {
  1215. dev_dbg(adapter->dev, "cmd: Enabled auto deep sleep\n");
  1216. priv->adapter->is_deep_sleep = true;
  1217. }
  1218. if (auto_ps_bitmap & BITMAP_STA_PS) {
  1219. dev_dbg(adapter->dev, "cmd: Enabled STA power save\n");
  1220. if (adapter->sleep_period.period)
  1221. dev_dbg(adapter->dev,
  1222. "cmd: set to uapsd/pps mode\n");
  1223. }
  1224. } else if (action == DIS_AUTO_PS) {
  1225. if (ps_bitmap & BITMAP_AUTO_DS) {
  1226. priv->adapter->is_deep_sleep = false;
  1227. dev_dbg(adapter->dev, "cmd: Disabled auto deep sleep\n");
  1228. }
  1229. if (ps_bitmap & BITMAP_STA_PS) {
  1230. dev_dbg(adapter->dev, "cmd: Disabled STA power save\n");
  1231. if (adapter->sleep_period.period) {
  1232. adapter->delay_null_pkt = false;
  1233. adapter->tx_lock_flag = false;
  1234. adapter->pps_uapsd_mode = false;
  1235. }
  1236. }
  1237. } else if (action == GET_PS) {
  1238. if (ps_bitmap & BITMAP_STA_PS)
  1239. adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
  1240. else
  1241. adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM;
  1242. dev_dbg(adapter->dev, "cmd: ps_bitmap=%#x\n", ps_bitmap);
  1243. if (pm_cfg) {
  1244. /* This section is for get power save mode */
  1245. if (ps_bitmap & BITMAP_STA_PS)
  1246. pm_cfg->param.ps_mode = 1;
  1247. else
  1248. pm_cfg->param.ps_mode = 0;
  1249. }
  1250. }
  1251. return 0;
  1252. }
  1253. /*
  1254. * This function prepares command to get hardware specifications.
  1255. *
  1256. * Preparation includes -
  1257. * - Setting command ID, action and proper size
  1258. * - Setting permanent address parameter
  1259. * - Ensuring correct endian-ness
  1260. */
  1261. int mwifiex_cmd_get_hw_spec(struct mwifiex_private *priv,
  1262. struct host_cmd_ds_command *cmd)
  1263. {
  1264. struct host_cmd_ds_get_hw_spec *hw_spec = &cmd->params.hw_spec;
  1265. cmd->command = cpu_to_le16(HostCmd_CMD_GET_HW_SPEC);
  1266. cmd->size =
  1267. cpu_to_le16(sizeof(struct host_cmd_ds_get_hw_spec) + S_DS_GEN);
  1268. memcpy(hw_spec->permanent_addr, priv->curr_addr, ETH_ALEN);
  1269. return 0;
  1270. }
  1271. /*
  1272. * This function handles the command response of get hardware
  1273. * specifications.
  1274. *
  1275. * Handling includes changing the header fields into CPU format
  1276. * and saving/updating the following parameters in driver -
  1277. * - Firmware capability information
  1278. * - Firmware band settings
  1279. * - Ad-hoc start band and channel
  1280. * - Ad-hoc 11n activation status
  1281. * - Firmware release number
  1282. * - Number of antennas
  1283. * - Hardware address
  1284. * - Hardware interface version
  1285. * - Firmware version
  1286. * - Region code
  1287. * - 11n capabilities
  1288. * - MCS support fields
  1289. * - MP end port
  1290. */
  1291. int mwifiex_ret_get_hw_spec(struct mwifiex_private *priv,
  1292. struct host_cmd_ds_command *resp)
  1293. {
  1294. struct host_cmd_ds_get_hw_spec *hw_spec = &resp->params.hw_spec;
  1295. struct mwifiex_adapter *adapter = priv->adapter;
  1296. int i;
  1297. adapter->fw_cap_info = le32_to_cpu(hw_spec->fw_cap_info);
  1298. if (IS_SUPPORT_MULTI_BANDS(adapter))
  1299. adapter->fw_bands = (u8) GET_FW_DEFAULT_BANDS(adapter);
  1300. else
  1301. adapter->fw_bands = BAND_B;
  1302. adapter->config_bands = adapter->fw_bands;
  1303. if (adapter->fw_bands & BAND_A) {
  1304. if (adapter->fw_bands & BAND_GN) {
  1305. adapter->config_bands |= BAND_AN;
  1306. adapter->fw_bands |= BAND_AN;
  1307. }
  1308. if (adapter->fw_bands & BAND_AN) {
  1309. adapter->adhoc_start_band = BAND_A | BAND_AN;
  1310. adapter->adhoc_11n_enabled = true;
  1311. } else {
  1312. adapter->adhoc_start_band = BAND_A;
  1313. }
  1314. priv->adhoc_channel = DEFAULT_AD_HOC_CHANNEL_A;
  1315. } else if (adapter->fw_bands & BAND_GN) {
  1316. adapter->adhoc_start_band = BAND_G | BAND_B | BAND_GN;
  1317. priv->adhoc_channel = DEFAULT_AD_HOC_CHANNEL;
  1318. adapter->adhoc_11n_enabled = true;
  1319. } else if (adapter->fw_bands & BAND_G) {
  1320. adapter->adhoc_start_band = BAND_G | BAND_B;
  1321. priv->adhoc_channel = DEFAULT_AD_HOC_CHANNEL;
  1322. } else if (adapter->fw_bands & BAND_B) {
  1323. adapter->adhoc_start_band = BAND_B;
  1324. priv->adhoc_channel = DEFAULT_AD_HOC_CHANNEL;
  1325. }
  1326. adapter->fw_release_number = le32_to_cpu(hw_spec->fw_release_number);
  1327. adapter->number_of_antenna = le16_to_cpu(hw_spec->number_of_antenna);
  1328. if (le32_to_cpu(hw_spec->dot_11ac_dev_cap)) {
  1329. adapter->is_hw_11ac_capable = true;
  1330. /* Copy 11AC cap */
  1331. adapter->hw_dot_11ac_dev_cap =
  1332. le32_to_cpu(hw_spec->dot_11ac_dev_cap);
  1333. adapter->usr_dot_11ac_dev_cap_bg = adapter->hw_dot_11ac_dev_cap;
  1334. adapter->usr_dot_11ac_dev_cap_a = adapter->hw_dot_11ac_dev_cap;
  1335. /* Copy 11AC mcs */
  1336. adapter->hw_dot_11ac_mcs_support =
  1337. le32_to_cpu(hw_spec->dot_11ac_mcs_support);
  1338. adapter->usr_dot_11ac_mcs_support =
  1339. adapter->hw_dot_11ac_mcs_support;
  1340. } else {
  1341. adapter->is_hw_11ac_capable = false;
  1342. }
  1343. dev_dbg(adapter->dev, "info: GET_HW_SPEC: fw_release_number- %#x\n",
  1344. adapter->fw_release_number);
  1345. dev_dbg(adapter->dev, "info: GET_HW_SPEC: permanent addr: %pM\n",
  1346. hw_spec->permanent_addr);
  1347. dev_dbg(adapter->dev,
  1348. "info: GET_HW_SPEC: hw_if_version=%#x version=%#x\n",
  1349. le16_to_cpu(hw_spec->hw_if_version),
  1350. le16_to_cpu(hw_spec->version));
  1351. if (priv->curr_addr[0] == 0xff)
  1352. memmove(priv->curr_addr, hw_spec->permanent_addr, ETH_ALEN);
  1353. adapter->region_code = le16_to_cpu(hw_spec->region_code);
  1354. for (i = 0; i < MWIFIEX_MAX_REGION_CODE; i++)
  1355. /* Use the region code to search for the index */
  1356. if (adapter->region_code == region_code_index[i])
  1357. break;
  1358. /* If it's unidentified region code, use the default (USA) */
  1359. if (i >= MWIFIEX_MAX_REGION_CODE) {
  1360. adapter->region_code = 0x10;
  1361. dev_dbg(adapter->dev,
  1362. "cmd: unknown region code, use default (USA)\n");
  1363. }
  1364. adapter->hw_dot_11n_dev_cap = le32_to_cpu(hw_spec->dot_11n_dev_cap);
  1365. adapter->hw_dev_mcs_support = hw_spec->dev_mcs_support;
  1366. if (adapter->if_ops.update_mp_end_port)
  1367. adapter->if_ops.update_mp_end_port(adapter,
  1368. le16_to_cpu(hw_spec->mp_end_port));
  1369. return 0;
  1370. }