cmdevt.c 50 KB

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