cmdevt.c 50 KB

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