util.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757
  1. /*
  2. * Marvell Wireless LAN device driver: utility functions
  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. static struct mwifiex_debug_data items[] = {
  27. {"debug_mask", item_size(debug_mask),
  28. item_addr(debug_mask), 1},
  29. {"int_counter", item_size(int_counter),
  30. item_addr(int_counter), 1},
  31. {"wmm_ac_vo", item_size(packets_out[WMM_AC_VO]),
  32. item_addr(packets_out[WMM_AC_VO]), 1},
  33. {"wmm_ac_vi", item_size(packets_out[WMM_AC_VI]),
  34. item_addr(packets_out[WMM_AC_VI]), 1},
  35. {"wmm_ac_be", item_size(packets_out[WMM_AC_BE]),
  36. item_addr(packets_out[WMM_AC_BE]), 1},
  37. {"wmm_ac_bk", item_size(packets_out[WMM_AC_BK]),
  38. item_addr(packets_out[WMM_AC_BK]), 1},
  39. {"tx_buf_size", item_size(tx_buf_size),
  40. item_addr(tx_buf_size), 1},
  41. {"curr_tx_buf_size", item_size(curr_tx_buf_size),
  42. item_addr(curr_tx_buf_size), 1},
  43. {"ps_mode", item_size(ps_mode),
  44. item_addr(ps_mode), 1},
  45. {"ps_state", item_size(ps_state),
  46. item_addr(ps_state), 1},
  47. {"is_deep_sleep", item_size(is_deep_sleep),
  48. item_addr(is_deep_sleep), 1},
  49. {"wakeup_dev_req", item_size(pm_wakeup_card_req),
  50. item_addr(pm_wakeup_card_req), 1},
  51. {"wakeup_tries", item_size(pm_wakeup_fw_try),
  52. item_addr(pm_wakeup_fw_try), 1},
  53. {"hs_configured", item_size(is_hs_configured),
  54. item_addr(is_hs_configured), 1},
  55. {"hs_activated", item_size(hs_activated),
  56. item_addr(hs_activated), 1},
  57. {"num_tx_timeout", item_size(num_tx_timeout),
  58. item_addr(num_tx_timeout), 1},
  59. {"is_cmd_timedout", item_size(is_cmd_timedout),
  60. item_addr(is_cmd_timedout), 1},
  61. {"timeout_cmd_id", item_size(timeout_cmd_id),
  62. item_addr(timeout_cmd_id), 1},
  63. {"timeout_cmd_act", item_size(timeout_cmd_act),
  64. item_addr(timeout_cmd_act), 1},
  65. {"last_cmd_id", item_size(last_cmd_id),
  66. item_addr(last_cmd_id), DBG_CMD_NUM},
  67. {"last_cmd_act", item_size(last_cmd_act),
  68. item_addr(last_cmd_act), DBG_CMD_NUM},
  69. {"last_cmd_index", item_size(last_cmd_index),
  70. item_addr(last_cmd_index), 1},
  71. {"last_cmd_resp_id", item_size(last_cmd_resp_id),
  72. item_addr(last_cmd_resp_id), DBG_CMD_NUM},
  73. {"last_cmd_resp_index", item_size(last_cmd_resp_index),
  74. item_addr(last_cmd_resp_index), 1},
  75. {"last_event", item_size(last_event),
  76. item_addr(last_event), DBG_CMD_NUM},
  77. {"last_event_index", item_size(last_event_index),
  78. item_addr(last_event_index), 1},
  79. {"last_mp_wr_bitmap", item_size(last_mp_wr_bitmap),
  80. item_addr(last_mp_wr_bitmap), MWIFIEX_DBG_SDIO_MP_NUM},
  81. {"last_mp_wr_ports", item_size(last_mp_wr_ports),
  82. item_addr(last_mp_wr_ports), MWIFIEX_DBG_SDIO_MP_NUM},
  83. {"last_mp_wr_len", item_size(last_mp_wr_len),
  84. item_addr(last_mp_wr_len), MWIFIEX_DBG_SDIO_MP_NUM},
  85. {"last_mp_curr_wr_port", item_size(last_mp_curr_wr_port),
  86. item_addr(last_mp_curr_wr_port), MWIFIEX_DBG_SDIO_MP_NUM},
  87. {"last_sdio_mp_index", item_size(last_sdio_mp_index),
  88. item_addr(last_sdio_mp_index), 1},
  89. {"num_cmd_h2c_fail", item_size(num_cmd_host_to_card_failure),
  90. item_addr(num_cmd_host_to_card_failure), 1},
  91. {"num_cmd_sleep_cfm_fail",
  92. item_size(num_cmd_sleep_cfm_host_to_card_failure),
  93. item_addr(num_cmd_sleep_cfm_host_to_card_failure), 1},
  94. {"num_tx_h2c_fail", item_size(num_tx_host_to_card_failure),
  95. item_addr(num_tx_host_to_card_failure), 1},
  96. {"num_evt_deauth", item_size(num_event_deauth),
  97. item_addr(num_event_deauth), 1},
  98. {"num_evt_disassoc", item_size(num_event_disassoc),
  99. item_addr(num_event_disassoc), 1},
  100. {"num_evt_link_lost", item_size(num_event_link_lost),
  101. item_addr(num_event_link_lost), 1},
  102. {"num_cmd_deauth", item_size(num_cmd_deauth),
  103. item_addr(num_cmd_deauth), 1},
  104. {"num_cmd_assoc_ok", item_size(num_cmd_assoc_success),
  105. item_addr(num_cmd_assoc_success), 1},
  106. {"num_cmd_assoc_fail", item_size(num_cmd_assoc_failure),
  107. item_addr(num_cmd_assoc_failure), 1},
  108. {"cmd_sent", item_size(cmd_sent),
  109. item_addr(cmd_sent), 1},
  110. {"data_sent", item_size(data_sent),
  111. item_addr(data_sent), 1},
  112. {"cmd_resp_received", item_size(cmd_resp_received),
  113. item_addr(cmd_resp_received), 1},
  114. {"event_received", item_size(event_received),
  115. item_addr(event_received), 1},
  116. /* variables defined in struct mwifiex_adapter */
  117. {"cmd_pending", adapter_item_size(cmd_pending),
  118. adapter_item_addr(cmd_pending), 1},
  119. {"tx_pending", adapter_item_size(tx_pending),
  120. adapter_item_addr(tx_pending), 1},
  121. {"rx_pending", adapter_item_size(rx_pending),
  122. adapter_item_addr(rx_pending), 1},
  123. };
  124. static int num_of_items = ARRAY_SIZE(items);
  125. /*
  126. * Firmware initialization complete callback handler.
  127. *
  128. * This function wakes up the function waiting on the init
  129. * wait queue for the firmware initialization to complete.
  130. */
  131. int mwifiex_init_fw_complete(struct mwifiex_adapter *adapter)
  132. {
  133. if (adapter->hw_status == MWIFIEX_HW_STATUS_READY)
  134. if (adapter->if_ops.init_fw_port)
  135. adapter->if_ops.init_fw_port(adapter);
  136. adapter->init_wait_q_woken = true;
  137. wake_up_interruptible(&adapter->init_wait_q);
  138. return 0;
  139. }
  140. /*
  141. * This function sends init/shutdown command
  142. * to firmware.
  143. */
  144. int mwifiex_init_shutdown_fw(struct mwifiex_private *priv,
  145. u32 func_init_shutdown)
  146. {
  147. u16 cmd;
  148. if (func_init_shutdown == MWIFIEX_FUNC_INIT) {
  149. cmd = HostCmd_CMD_FUNC_INIT;
  150. } else if (func_init_shutdown == MWIFIEX_FUNC_SHUTDOWN) {
  151. cmd = HostCmd_CMD_FUNC_SHUTDOWN;
  152. } else {
  153. mwifiex_dbg(priv->adapter, ERROR,
  154. "unsupported parameter\n");
  155. return -1;
  156. }
  157. return mwifiex_send_cmd(priv, cmd, HostCmd_ACT_GEN_SET, 0, NULL, true);
  158. }
  159. EXPORT_SYMBOL_GPL(mwifiex_init_shutdown_fw);
  160. /*
  161. * IOCTL request handler to set/get debug information.
  162. *
  163. * This function collates/sets the information from/to different driver
  164. * structures.
  165. */
  166. int mwifiex_get_debug_info(struct mwifiex_private *priv,
  167. struct mwifiex_debug_info *info)
  168. {
  169. struct mwifiex_adapter *adapter = priv->adapter;
  170. if (info) {
  171. info->debug_mask = adapter->debug_mask;
  172. memcpy(info->packets_out,
  173. priv->wmm.packets_out,
  174. sizeof(priv->wmm.packets_out));
  175. info->curr_tx_buf_size = (u32) adapter->curr_tx_buf_size;
  176. info->tx_buf_size = (u32) adapter->tx_buf_size;
  177. info->rx_tbl_num = mwifiex_get_rx_reorder_tbl(priv,
  178. info->rx_tbl);
  179. info->tx_tbl_num = mwifiex_get_tx_ba_stream_tbl(priv,
  180. info->tx_tbl);
  181. info->tdls_peer_num = mwifiex_get_tdls_list(priv,
  182. info->tdls_list);
  183. info->ps_mode = adapter->ps_mode;
  184. info->ps_state = adapter->ps_state;
  185. info->is_deep_sleep = adapter->is_deep_sleep;
  186. info->pm_wakeup_card_req = adapter->pm_wakeup_card_req;
  187. info->pm_wakeup_fw_try = adapter->pm_wakeup_fw_try;
  188. info->is_hs_configured = adapter->is_hs_configured;
  189. info->hs_activated = adapter->hs_activated;
  190. info->is_cmd_timedout = adapter->is_cmd_timedout;
  191. info->num_cmd_host_to_card_failure
  192. = adapter->dbg.num_cmd_host_to_card_failure;
  193. info->num_cmd_sleep_cfm_host_to_card_failure
  194. = adapter->dbg.num_cmd_sleep_cfm_host_to_card_failure;
  195. info->num_tx_host_to_card_failure
  196. = adapter->dbg.num_tx_host_to_card_failure;
  197. info->num_event_deauth = adapter->dbg.num_event_deauth;
  198. info->num_event_disassoc = adapter->dbg.num_event_disassoc;
  199. info->num_event_link_lost = adapter->dbg.num_event_link_lost;
  200. info->num_cmd_deauth = adapter->dbg.num_cmd_deauth;
  201. info->num_cmd_assoc_success =
  202. adapter->dbg.num_cmd_assoc_success;
  203. info->num_cmd_assoc_failure =
  204. adapter->dbg.num_cmd_assoc_failure;
  205. info->num_tx_timeout = adapter->dbg.num_tx_timeout;
  206. info->timeout_cmd_id = adapter->dbg.timeout_cmd_id;
  207. info->timeout_cmd_act = adapter->dbg.timeout_cmd_act;
  208. memcpy(info->last_cmd_id, adapter->dbg.last_cmd_id,
  209. sizeof(adapter->dbg.last_cmd_id));
  210. memcpy(info->last_cmd_act, adapter->dbg.last_cmd_act,
  211. sizeof(adapter->dbg.last_cmd_act));
  212. info->last_cmd_index = adapter->dbg.last_cmd_index;
  213. memcpy(info->last_cmd_resp_id, adapter->dbg.last_cmd_resp_id,
  214. sizeof(adapter->dbg.last_cmd_resp_id));
  215. info->last_cmd_resp_index = adapter->dbg.last_cmd_resp_index;
  216. memcpy(info->last_event, adapter->dbg.last_event,
  217. sizeof(adapter->dbg.last_event));
  218. info->last_event_index = adapter->dbg.last_event_index;
  219. memcpy(info->last_mp_wr_bitmap, adapter->dbg.last_mp_wr_bitmap,
  220. sizeof(adapter->dbg.last_mp_wr_bitmap));
  221. memcpy(info->last_mp_wr_ports, adapter->dbg.last_mp_wr_ports,
  222. sizeof(adapter->dbg.last_mp_wr_ports));
  223. memcpy(info->last_mp_curr_wr_port,
  224. adapter->dbg.last_mp_curr_wr_port,
  225. sizeof(adapter->dbg.last_mp_curr_wr_port));
  226. memcpy(info->last_mp_wr_len, adapter->dbg.last_mp_wr_len,
  227. sizeof(adapter->dbg.last_mp_wr_len));
  228. info->last_sdio_mp_index = adapter->dbg.last_sdio_mp_index;
  229. info->data_sent = adapter->data_sent;
  230. info->cmd_sent = adapter->cmd_sent;
  231. info->cmd_resp_received = adapter->cmd_resp_received;
  232. }
  233. return 0;
  234. }
  235. int mwifiex_debug_info_to_buffer(struct mwifiex_private *priv, char *buf,
  236. struct mwifiex_debug_info *info)
  237. {
  238. char *p = buf;
  239. struct mwifiex_debug_data *d = &items[0];
  240. size_t size, addr;
  241. long val;
  242. int i, j;
  243. if (!info)
  244. return 0;
  245. for (i = 0; i < num_of_items; i++) {
  246. p += sprintf(p, "%s=", d[i].name);
  247. size = d[i].size / d[i].num;
  248. if (i < (num_of_items - 3))
  249. addr = d[i].addr + (size_t)info;
  250. else /* The last 3 items are struct mwifiex_adapter variables */
  251. addr = d[i].addr + (size_t)priv->adapter;
  252. for (j = 0; j < d[i].num; j++) {
  253. switch (size) {
  254. case 1:
  255. val = *((u8 *)addr);
  256. break;
  257. case 2:
  258. val = get_unaligned((u16 *)addr);
  259. break;
  260. case 4:
  261. val = get_unaligned((u32 *)addr);
  262. break;
  263. case 8:
  264. val = get_unaligned((long long *)addr);
  265. break;
  266. default:
  267. val = -1;
  268. break;
  269. }
  270. p += sprintf(p, "%#lx ", val);
  271. addr += size;
  272. }
  273. p += sprintf(p, "\n");
  274. }
  275. if (info->tx_tbl_num) {
  276. p += sprintf(p, "Tx BA stream table:\n");
  277. for (i = 0; i < info->tx_tbl_num; i++)
  278. p += sprintf(p, "tid = %d, ra = %pM\n",
  279. info->tx_tbl[i].tid, info->tx_tbl[i].ra);
  280. }
  281. if (info->rx_tbl_num) {
  282. p += sprintf(p, "Rx reorder table:\n");
  283. for (i = 0; i < info->rx_tbl_num; i++) {
  284. p += sprintf(p, "tid = %d, ta = %pM, ",
  285. info->rx_tbl[i].tid,
  286. info->rx_tbl[i].ta);
  287. p += sprintf(p, "start_win = %d, ",
  288. info->rx_tbl[i].start_win);
  289. p += sprintf(p, "win_size = %d, buffer: ",
  290. info->rx_tbl[i].win_size);
  291. for (j = 0; j < info->rx_tbl[i].win_size; j++)
  292. p += sprintf(p, "%c ",
  293. info->rx_tbl[i].buffer[j] ?
  294. '1' : '0');
  295. p += sprintf(p, "\n");
  296. }
  297. }
  298. if (info->tdls_peer_num) {
  299. p += sprintf(p, "TDLS peer table:\n");
  300. for (i = 0; i < info->tdls_peer_num; i++) {
  301. p += sprintf(p, "peer = %pM",
  302. info->tdls_list[i].peer_addr);
  303. p += sprintf(p, "\n");
  304. }
  305. }
  306. return p - buf;
  307. }
  308. static int
  309. mwifiex_parse_mgmt_packet(struct mwifiex_private *priv, u8 *payload, u16 len,
  310. struct rxpd *rx_pd)
  311. {
  312. u16 stype;
  313. u8 category, action_code, *addr2;
  314. struct ieee80211_hdr *ieee_hdr = (void *)payload;
  315. stype = (le16_to_cpu(ieee_hdr->frame_control) & IEEE80211_FCTL_STYPE);
  316. switch (stype) {
  317. case IEEE80211_STYPE_ACTION:
  318. category = *(payload + sizeof(struct ieee80211_hdr));
  319. switch (category) {
  320. case WLAN_CATEGORY_PUBLIC:
  321. action_code = *(payload + sizeof(struct ieee80211_hdr)
  322. + 1);
  323. if (action_code == WLAN_PUB_ACTION_TDLS_DISCOVER_RES) {
  324. addr2 = ieee_hdr->addr2;
  325. mwifiex_dbg(priv->adapter, INFO,
  326. "TDLS discovery response %pM nf=%d, snr=%d\n",
  327. addr2, rx_pd->nf, rx_pd->snr);
  328. mwifiex_auto_tdls_update_peer_signal(priv,
  329. addr2,
  330. rx_pd->snr,
  331. rx_pd->nf);
  332. }
  333. break;
  334. case WLAN_CATEGORY_BACK:
  335. /*we dont indicate BACK action frames to cfg80211*/
  336. mwifiex_dbg(priv->adapter, INFO,
  337. "drop BACK action frames");
  338. return -1;
  339. default:
  340. mwifiex_dbg(priv->adapter, INFO,
  341. "unknown public action frame category %d\n",
  342. category);
  343. }
  344. break;
  345. default:
  346. mwifiex_dbg(priv->adapter, INFO,
  347. "unknown mgmt frame subtype %#x\n", stype);
  348. return 0;
  349. }
  350. return 0;
  351. }
  352. /*
  353. * This function processes the received management packet and send it
  354. * to the kernel.
  355. */
  356. int
  357. mwifiex_process_mgmt_packet(struct mwifiex_private *priv,
  358. struct sk_buff *skb)
  359. {
  360. struct rxpd *rx_pd;
  361. u16 pkt_len;
  362. struct ieee80211_hdr *ieee_hdr;
  363. if (!skb)
  364. return -1;
  365. if (!priv->mgmt_frame_mask ||
  366. priv->wdev.iftype == NL80211_IFTYPE_UNSPECIFIED) {
  367. mwifiex_dbg(priv->adapter, ERROR,
  368. "do not receive mgmt frames on uninitialized intf");
  369. return -1;
  370. }
  371. rx_pd = (struct rxpd *)skb->data;
  372. skb_pull(skb, le16_to_cpu(rx_pd->rx_pkt_offset));
  373. skb_pull(skb, sizeof(pkt_len));
  374. pkt_len = le16_to_cpu(rx_pd->rx_pkt_length);
  375. ieee_hdr = (void *)skb->data;
  376. if (ieee80211_is_mgmt(ieee_hdr->frame_control)) {
  377. if (mwifiex_parse_mgmt_packet(priv, (u8 *)ieee_hdr,
  378. pkt_len, rx_pd))
  379. return -1;
  380. }
  381. /* Remove address4 */
  382. memmove(skb->data + sizeof(struct ieee80211_hdr_3addr),
  383. skb->data + sizeof(struct ieee80211_hdr),
  384. pkt_len - sizeof(struct ieee80211_hdr));
  385. pkt_len -= ETH_ALEN + sizeof(pkt_len);
  386. rx_pd->rx_pkt_length = cpu_to_le16(pkt_len);
  387. cfg80211_rx_mgmt(&priv->wdev, priv->roc_cfg.chan.center_freq,
  388. CAL_RSSI(rx_pd->snr, rx_pd->nf), skb->data, pkt_len,
  389. 0);
  390. return 0;
  391. }
  392. /*
  393. * This function processes the received packet before sending it to the
  394. * kernel.
  395. *
  396. * It extracts the SKB from the received buffer and sends it to kernel.
  397. * In case the received buffer does not contain the data in SKB format,
  398. * the function creates a blank SKB, fills it with the data from the
  399. * received buffer and then sends this new SKB to the kernel.
  400. */
  401. int mwifiex_recv_packet(struct mwifiex_private *priv, struct sk_buff *skb)
  402. {
  403. struct mwifiex_sta_node *src_node;
  404. struct ethhdr *p_ethhdr;
  405. if (!skb)
  406. return -1;
  407. priv->stats.rx_bytes += skb->len;
  408. priv->stats.rx_packets++;
  409. if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) {
  410. p_ethhdr = (void *)skb->data;
  411. src_node = mwifiex_get_sta_entry(priv, p_ethhdr->h_source);
  412. if (src_node) {
  413. src_node->stats.last_rx = jiffies;
  414. src_node->stats.rx_bytes += skb->len;
  415. src_node->stats.rx_packets++;
  416. }
  417. }
  418. skb->dev = priv->netdev;
  419. skb->protocol = eth_type_trans(skb, priv->netdev);
  420. skb->ip_summed = CHECKSUM_NONE;
  421. /* This is required only in case of 11n and USB/PCIE as we alloc
  422. * a buffer of 4K only if its 11N (to be able to receive 4K
  423. * AMSDU packets). In case of SD we allocate buffers based
  424. * on the size of packet and hence this is not needed.
  425. *
  426. * Modifying the truesize here as our allocation for each
  427. * skb is 4K but we only receive 2K packets and this cause
  428. * the kernel to start dropping packets in case where
  429. * application has allocated buffer based on 2K size i.e.
  430. * if there a 64K packet received (in IP fragments and
  431. * application allocates 64K to receive this packet but
  432. * this packet would almost double up because we allocate
  433. * each 1.5K fragment in 4K and pass it up. As soon as the
  434. * 64K limit hits kernel will start to drop rest of the
  435. * fragments. Currently we fail the Filesndl-ht.scr script
  436. * for UDP, hence this fix
  437. */
  438. if ((priv->adapter->iface_type == MWIFIEX_USB ||
  439. priv->adapter->iface_type == MWIFIEX_PCIE) &&
  440. (skb->truesize > MWIFIEX_RX_DATA_BUF_SIZE))
  441. skb->truesize += (skb->len - MWIFIEX_RX_DATA_BUF_SIZE);
  442. if (in_interrupt())
  443. netif_rx(skb);
  444. else
  445. netif_rx_ni(skb);
  446. return 0;
  447. }
  448. /*
  449. * IOCTL completion callback handler.
  450. *
  451. * This function is called when a pending IOCTL is completed.
  452. *
  453. * If work queue support is enabled, the function wakes up the
  454. * corresponding waiting function. Otherwise, it processes the
  455. * IOCTL response and frees the response buffer.
  456. */
  457. int mwifiex_complete_cmd(struct mwifiex_adapter *adapter,
  458. struct cmd_ctrl_node *cmd_node)
  459. {
  460. WARN_ON(!cmd_node->wait_q_enabled);
  461. mwifiex_dbg(adapter, CMD, "cmd completed: status=%d\n",
  462. adapter->cmd_wait_q.status);
  463. *cmd_node->condition = true;
  464. wake_up_interruptible(&adapter->cmd_wait_q.wait);
  465. return 0;
  466. }
  467. /* This function will return the pointer to station entry in station list
  468. * table which matches specified mac address.
  469. * This function should be called after acquiring RA list spinlock.
  470. * NULL is returned if station entry is not found in associated STA list.
  471. */
  472. struct mwifiex_sta_node *
  473. mwifiex_get_sta_entry(struct mwifiex_private *priv, const u8 *mac)
  474. {
  475. struct mwifiex_sta_node *node;
  476. if (!mac)
  477. return NULL;
  478. list_for_each_entry(node, &priv->sta_list, list) {
  479. if (!memcmp(node->mac_addr, mac, ETH_ALEN))
  480. return node;
  481. }
  482. return NULL;
  483. }
  484. static struct mwifiex_sta_node *
  485. mwifiex_get_tdls_sta_entry(struct mwifiex_private *priv, u8 status)
  486. {
  487. struct mwifiex_sta_node *node;
  488. list_for_each_entry(node, &priv->sta_list, list) {
  489. if (node->tdls_status == status)
  490. return node;
  491. }
  492. return NULL;
  493. }
  494. /* If tdls channel switching is on-going, tx data traffic should be
  495. * blocked until the switching stage completed.
  496. */
  497. u8 mwifiex_is_tdls_chan_switching(struct mwifiex_private *priv)
  498. {
  499. struct mwifiex_sta_node *sta_ptr;
  500. if (!priv || !ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info))
  501. return false;
  502. sta_ptr = mwifiex_get_tdls_sta_entry(priv, TDLS_CHAN_SWITCHING);
  503. if (sta_ptr)
  504. return true;
  505. return false;
  506. }
  507. u8 mwifiex_is_tdls_off_chan(struct mwifiex_private *priv)
  508. {
  509. struct mwifiex_sta_node *sta_ptr;
  510. if (!priv || !ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info))
  511. return false;
  512. sta_ptr = mwifiex_get_tdls_sta_entry(priv, TDLS_IN_OFF_CHAN);
  513. if (sta_ptr)
  514. return true;
  515. return false;
  516. }
  517. /* If tdls channel switching is on-going or tdls operate on off-channel,
  518. * cmd path should be blocked until tdls switched to base-channel.
  519. */
  520. u8 mwifiex_is_send_cmd_allowed(struct mwifiex_private *priv)
  521. {
  522. if (!priv || !ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info))
  523. return true;
  524. if (mwifiex_is_tdls_chan_switching(priv) ||
  525. mwifiex_is_tdls_off_chan(priv))
  526. return false;
  527. return true;
  528. }
  529. /* This function will add a sta_node entry to associated station list
  530. * table with the given mac address.
  531. * If entry exist already, existing entry is returned.
  532. * If received mac address is NULL, NULL is returned.
  533. */
  534. struct mwifiex_sta_node *
  535. mwifiex_add_sta_entry(struct mwifiex_private *priv, const u8 *mac)
  536. {
  537. struct mwifiex_sta_node *node;
  538. unsigned long flags;
  539. if (!mac)
  540. return NULL;
  541. spin_lock_irqsave(&priv->sta_list_spinlock, flags);
  542. node = mwifiex_get_sta_entry(priv, mac);
  543. if (node)
  544. goto done;
  545. node = kzalloc(sizeof(*node), GFP_ATOMIC);
  546. if (!node)
  547. goto done;
  548. memcpy(node->mac_addr, mac, ETH_ALEN);
  549. list_add_tail(&node->list, &priv->sta_list);
  550. done:
  551. spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
  552. return node;
  553. }
  554. /* This function will search for HT IE in association request IEs
  555. * and set station HT parameters accordingly.
  556. */
  557. void
  558. mwifiex_set_sta_ht_cap(struct mwifiex_private *priv, const u8 *ies,
  559. int ies_len, struct mwifiex_sta_node *node)
  560. {
  561. struct ieee_types_header *ht_cap_ie;
  562. const struct ieee80211_ht_cap *ht_cap;
  563. if (!ies)
  564. return;
  565. ht_cap_ie = (void *)cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies,
  566. ies_len);
  567. if (ht_cap_ie) {
  568. ht_cap = (void *)(ht_cap_ie + 1);
  569. node->is_11n_enabled = 1;
  570. node->max_amsdu = le16_to_cpu(ht_cap->cap_info) &
  571. IEEE80211_HT_CAP_MAX_AMSDU ?
  572. MWIFIEX_TX_DATA_BUF_SIZE_8K :
  573. MWIFIEX_TX_DATA_BUF_SIZE_4K;
  574. } else {
  575. node->is_11n_enabled = 0;
  576. }
  577. return;
  578. }
  579. /* This function will delete a station entry from station list */
  580. void mwifiex_del_sta_entry(struct mwifiex_private *priv, const u8 *mac)
  581. {
  582. struct mwifiex_sta_node *node;
  583. unsigned long flags;
  584. spin_lock_irqsave(&priv->sta_list_spinlock, flags);
  585. node = mwifiex_get_sta_entry(priv, mac);
  586. if (node) {
  587. list_del(&node->list);
  588. kfree(node);
  589. }
  590. spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
  591. return;
  592. }
  593. /* This function will delete all stations from associated station list. */
  594. void mwifiex_del_all_sta_list(struct mwifiex_private *priv)
  595. {
  596. struct mwifiex_sta_node *node, *tmp;
  597. unsigned long flags;
  598. spin_lock_irqsave(&priv->sta_list_spinlock, flags);
  599. list_for_each_entry_safe(node, tmp, &priv->sta_list, list) {
  600. list_del(&node->list);
  601. kfree(node);
  602. }
  603. INIT_LIST_HEAD(&priv->sta_list);
  604. spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
  605. return;
  606. }
  607. /* This function adds histogram data to histogram array*/
  608. void mwifiex_hist_data_add(struct mwifiex_private *priv,
  609. u8 rx_rate, s8 snr, s8 nflr)
  610. {
  611. struct mwifiex_histogram_data *phist_data = priv->hist_data;
  612. if (atomic_read(&phist_data->num_samples) > MWIFIEX_HIST_MAX_SAMPLES)
  613. mwifiex_hist_data_reset(priv);
  614. mwifiex_hist_data_set(priv, rx_rate, snr, nflr);
  615. }
  616. /* function to add histogram record */
  617. void mwifiex_hist_data_set(struct mwifiex_private *priv, u8 rx_rate, s8 snr,
  618. s8 nflr)
  619. {
  620. struct mwifiex_histogram_data *phist_data = priv->hist_data;
  621. atomic_inc(&phist_data->num_samples);
  622. atomic_inc(&phist_data->rx_rate[rx_rate]);
  623. atomic_inc(&phist_data->snr[snr]);
  624. atomic_inc(&phist_data->noise_flr[128 + nflr]);
  625. atomic_inc(&phist_data->sig_str[nflr - snr]);
  626. }
  627. /* function to reset histogram data during init/reset */
  628. void mwifiex_hist_data_reset(struct mwifiex_private *priv)
  629. {
  630. int ix;
  631. struct mwifiex_histogram_data *phist_data = priv->hist_data;
  632. atomic_set(&phist_data->num_samples, 0);
  633. for (ix = 0; ix < MWIFIEX_MAX_AC_RX_RATES; ix++)
  634. atomic_set(&phist_data->rx_rate[ix], 0);
  635. for (ix = 0; ix < MWIFIEX_MAX_SNR; ix++)
  636. atomic_set(&phist_data->snr[ix], 0);
  637. for (ix = 0; ix < MWIFIEX_MAX_NOISE_FLR; ix++)
  638. atomic_set(&phist_data->noise_flr[ix], 0);
  639. for (ix = 0; ix < MWIFIEX_MAX_SIG_STRENGTH; ix++)
  640. atomic_set(&phist_data->sig_str[ix], 0);
  641. }
  642. void *mwifiex_alloc_dma_align_buf(int rx_len, gfp_t flags)
  643. {
  644. struct sk_buff *skb;
  645. int buf_len, pad;
  646. buf_len = rx_len + MWIFIEX_RX_HEADROOM + MWIFIEX_DMA_ALIGN_SZ;
  647. skb = __dev_alloc_skb(buf_len, flags);
  648. if (!skb)
  649. return NULL;
  650. skb_reserve(skb, MWIFIEX_RX_HEADROOM);
  651. pad = MWIFIEX_ALIGN_ADDR(skb->data, MWIFIEX_DMA_ALIGN_SZ) -
  652. (long)skb->data;
  653. skb_reserve(skb, pad);
  654. return skb;
  655. }
  656. EXPORT_SYMBOL_GPL(mwifiex_alloc_dma_align_buf);