util.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769
  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 = test_bit(MWIFIEX_IS_HS_CONFIGURED,
  189. &adapter->work_flags);
  190. info->hs_activated = adapter->hs_activated;
  191. info->is_cmd_timedout = test_bit(MWIFIEX_IS_CMD_TIMEDOUT,
  192. &adapter->work_flags);
  193. info->num_cmd_host_to_card_failure
  194. = adapter->dbg.num_cmd_host_to_card_failure;
  195. info->num_cmd_sleep_cfm_host_to_card_failure
  196. = adapter->dbg.num_cmd_sleep_cfm_host_to_card_failure;
  197. info->num_tx_host_to_card_failure
  198. = adapter->dbg.num_tx_host_to_card_failure;
  199. info->num_event_deauth = adapter->dbg.num_event_deauth;
  200. info->num_event_disassoc = adapter->dbg.num_event_disassoc;
  201. info->num_event_link_lost = adapter->dbg.num_event_link_lost;
  202. info->num_cmd_deauth = adapter->dbg.num_cmd_deauth;
  203. info->num_cmd_assoc_success =
  204. adapter->dbg.num_cmd_assoc_success;
  205. info->num_cmd_assoc_failure =
  206. adapter->dbg.num_cmd_assoc_failure;
  207. info->num_tx_timeout = adapter->dbg.num_tx_timeout;
  208. info->timeout_cmd_id = adapter->dbg.timeout_cmd_id;
  209. info->timeout_cmd_act = adapter->dbg.timeout_cmd_act;
  210. memcpy(info->last_cmd_id, adapter->dbg.last_cmd_id,
  211. sizeof(adapter->dbg.last_cmd_id));
  212. memcpy(info->last_cmd_act, adapter->dbg.last_cmd_act,
  213. sizeof(adapter->dbg.last_cmd_act));
  214. info->last_cmd_index = adapter->dbg.last_cmd_index;
  215. memcpy(info->last_cmd_resp_id, adapter->dbg.last_cmd_resp_id,
  216. sizeof(adapter->dbg.last_cmd_resp_id));
  217. info->last_cmd_resp_index = adapter->dbg.last_cmd_resp_index;
  218. memcpy(info->last_event, adapter->dbg.last_event,
  219. sizeof(adapter->dbg.last_event));
  220. info->last_event_index = adapter->dbg.last_event_index;
  221. memcpy(info->last_mp_wr_bitmap, adapter->dbg.last_mp_wr_bitmap,
  222. sizeof(adapter->dbg.last_mp_wr_bitmap));
  223. memcpy(info->last_mp_wr_ports, adapter->dbg.last_mp_wr_ports,
  224. sizeof(adapter->dbg.last_mp_wr_ports));
  225. memcpy(info->last_mp_curr_wr_port,
  226. adapter->dbg.last_mp_curr_wr_port,
  227. sizeof(adapter->dbg.last_mp_curr_wr_port));
  228. memcpy(info->last_mp_wr_len, adapter->dbg.last_mp_wr_len,
  229. sizeof(adapter->dbg.last_mp_wr_len));
  230. info->last_sdio_mp_index = adapter->dbg.last_sdio_mp_index;
  231. info->data_sent = adapter->data_sent;
  232. info->cmd_sent = adapter->cmd_sent;
  233. info->cmd_resp_received = adapter->cmd_resp_received;
  234. }
  235. return 0;
  236. }
  237. int mwifiex_debug_info_to_buffer(struct mwifiex_private *priv, char *buf,
  238. struct mwifiex_debug_info *info)
  239. {
  240. char *p = buf;
  241. struct mwifiex_debug_data *d = &items[0];
  242. size_t size, addr;
  243. long val;
  244. int i, j;
  245. if (!info)
  246. return 0;
  247. for (i = 0; i < num_of_items; i++) {
  248. p += sprintf(p, "%s=", d[i].name);
  249. size = d[i].size / d[i].num;
  250. if (i < (num_of_items - 3))
  251. addr = d[i].addr + (size_t)info;
  252. else /* The last 3 items are struct mwifiex_adapter variables */
  253. addr = d[i].addr + (size_t)priv->adapter;
  254. for (j = 0; j < d[i].num; j++) {
  255. switch (size) {
  256. case 1:
  257. val = *((u8 *)addr);
  258. break;
  259. case 2:
  260. val = get_unaligned((u16 *)addr);
  261. break;
  262. case 4:
  263. val = get_unaligned((u32 *)addr);
  264. break;
  265. case 8:
  266. val = get_unaligned((long long *)addr);
  267. break;
  268. default:
  269. val = -1;
  270. break;
  271. }
  272. p += sprintf(p, "%#lx ", val);
  273. addr += size;
  274. }
  275. p += sprintf(p, "\n");
  276. }
  277. if (info->tx_tbl_num) {
  278. p += sprintf(p, "Tx BA stream table:\n");
  279. for (i = 0; i < info->tx_tbl_num; i++)
  280. p += sprintf(p, "tid = %d, ra = %pM\n",
  281. info->tx_tbl[i].tid, info->tx_tbl[i].ra);
  282. }
  283. if (info->rx_tbl_num) {
  284. p += sprintf(p, "Rx reorder table:\n");
  285. for (i = 0; i < info->rx_tbl_num; i++) {
  286. p += sprintf(p, "tid = %d, ta = %pM, ",
  287. info->rx_tbl[i].tid,
  288. info->rx_tbl[i].ta);
  289. p += sprintf(p, "start_win = %d, ",
  290. info->rx_tbl[i].start_win);
  291. p += sprintf(p, "win_size = %d, buffer: ",
  292. info->rx_tbl[i].win_size);
  293. for (j = 0; j < info->rx_tbl[i].win_size; j++)
  294. p += sprintf(p, "%c ",
  295. info->rx_tbl[i].buffer[j] ?
  296. '1' : '0');
  297. p += sprintf(p, "\n");
  298. }
  299. }
  300. if (info->tdls_peer_num) {
  301. p += sprintf(p, "TDLS peer table:\n");
  302. for (i = 0; i < info->tdls_peer_num; i++) {
  303. p += sprintf(p, "peer = %pM",
  304. info->tdls_list[i].peer_addr);
  305. p += sprintf(p, "\n");
  306. }
  307. }
  308. return p - buf;
  309. }
  310. static int
  311. mwifiex_parse_mgmt_packet(struct mwifiex_private *priv, u8 *payload, u16 len,
  312. struct rxpd *rx_pd)
  313. {
  314. u16 stype;
  315. u8 category, action_code, *addr2;
  316. struct ieee80211_hdr *ieee_hdr = (void *)payload;
  317. stype = (le16_to_cpu(ieee_hdr->frame_control) & IEEE80211_FCTL_STYPE);
  318. switch (stype) {
  319. case IEEE80211_STYPE_ACTION:
  320. category = *(payload + sizeof(struct ieee80211_hdr));
  321. switch (category) {
  322. case WLAN_CATEGORY_PUBLIC:
  323. action_code = *(payload + sizeof(struct ieee80211_hdr)
  324. + 1);
  325. if (action_code == WLAN_PUB_ACTION_TDLS_DISCOVER_RES) {
  326. addr2 = ieee_hdr->addr2;
  327. mwifiex_dbg(priv->adapter, INFO,
  328. "TDLS discovery response %pM nf=%d, snr=%d\n",
  329. addr2, rx_pd->nf, rx_pd->snr);
  330. mwifiex_auto_tdls_update_peer_signal(priv,
  331. addr2,
  332. rx_pd->snr,
  333. rx_pd->nf);
  334. }
  335. break;
  336. case WLAN_CATEGORY_BACK:
  337. /*we dont indicate BACK action frames to cfg80211*/
  338. mwifiex_dbg(priv->adapter, INFO,
  339. "drop BACK action frames");
  340. return -1;
  341. default:
  342. mwifiex_dbg(priv->adapter, INFO,
  343. "unknown public action frame category %d\n",
  344. category);
  345. }
  346. break;
  347. default:
  348. mwifiex_dbg(priv->adapter, INFO,
  349. "unknown mgmt frame subtype %#x\n", stype);
  350. return 0;
  351. }
  352. return 0;
  353. }
  354. /*
  355. * This function processes the received management packet and send it
  356. * to the kernel.
  357. */
  358. int
  359. mwifiex_process_mgmt_packet(struct mwifiex_private *priv,
  360. struct sk_buff *skb)
  361. {
  362. struct rxpd *rx_pd;
  363. u16 pkt_len;
  364. struct ieee80211_hdr *ieee_hdr;
  365. if (!skb)
  366. return -1;
  367. if (!priv->mgmt_frame_mask ||
  368. priv->wdev.iftype == NL80211_IFTYPE_UNSPECIFIED) {
  369. mwifiex_dbg(priv->adapter, ERROR,
  370. "do not receive mgmt frames on uninitialized intf");
  371. return -1;
  372. }
  373. rx_pd = (struct rxpd *)skb->data;
  374. skb_pull(skb, le16_to_cpu(rx_pd->rx_pkt_offset));
  375. skb_pull(skb, sizeof(pkt_len));
  376. pkt_len = le16_to_cpu(rx_pd->rx_pkt_length);
  377. ieee_hdr = (void *)skb->data;
  378. if (ieee80211_is_mgmt(ieee_hdr->frame_control)) {
  379. if (mwifiex_parse_mgmt_packet(priv, (u8 *)ieee_hdr,
  380. pkt_len, rx_pd))
  381. return -1;
  382. }
  383. /* Remove address4 */
  384. memmove(skb->data + sizeof(struct ieee80211_hdr_3addr),
  385. skb->data + sizeof(struct ieee80211_hdr),
  386. pkt_len - sizeof(struct ieee80211_hdr));
  387. pkt_len -= ETH_ALEN + sizeof(pkt_len);
  388. rx_pd->rx_pkt_length = cpu_to_le16(pkt_len);
  389. cfg80211_rx_mgmt(&priv->wdev, priv->roc_cfg.chan.center_freq,
  390. CAL_RSSI(rx_pd->snr, rx_pd->nf), skb->data, pkt_len,
  391. 0);
  392. return 0;
  393. }
  394. /*
  395. * This function processes the received packet before sending it to the
  396. * kernel.
  397. *
  398. * It extracts the SKB from the received buffer and sends it to kernel.
  399. * In case the received buffer does not contain the data in SKB format,
  400. * the function creates a blank SKB, fills it with the data from the
  401. * received buffer and then sends this new SKB to the kernel.
  402. */
  403. int mwifiex_recv_packet(struct mwifiex_private *priv, struct sk_buff *skb)
  404. {
  405. struct mwifiex_sta_node *src_node;
  406. struct ethhdr *p_ethhdr;
  407. if (!skb)
  408. return -1;
  409. priv->stats.rx_bytes += skb->len;
  410. priv->stats.rx_packets++;
  411. if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) {
  412. p_ethhdr = (void *)skb->data;
  413. src_node = mwifiex_get_sta_entry(priv, p_ethhdr->h_source);
  414. if (src_node) {
  415. src_node->stats.last_rx = jiffies;
  416. src_node->stats.rx_bytes += skb->len;
  417. src_node->stats.rx_packets++;
  418. }
  419. }
  420. skb->dev = priv->netdev;
  421. skb->protocol = eth_type_trans(skb, priv->netdev);
  422. skb->ip_summed = CHECKSUM_NONE;
  423. /* This is required only in case of 11n and USB/PCIE as we alloc
  424. * a buffer of 4K only if its 11N (to be able to receive 4K
  425. * AMSDU packets). In case of SD we allocate buffers based
  426. * on the size of packet and hence this is not needed.
  427. *
  428. * Modifying the truesize here as our allocation for each
  429. * skb is 4K but we only receive 2K packets and this cause
  430. * the kernel to start dropping packets in case where
  431. * application has allocated buffer based on 2K size i.e.
  432. * if there a 64K packet received (in IP fragments and
  433. * application allocates 64K to receive this packet but
  434. * this packet would almost double up because we allocate
  435. * each 1.5K fragment in 4K and pass it up. As soon as the
  436. * 64K limit hits kernel will start to drop rest of the
  437. * fragments. Currently we fail the Filesndl-ht.scr script
  438. * for UDP, hence this fix
  439. */
  440. if ((priv->adapter->iface_type == MWIFIEX_USB ||
  441. priv->adapter->iface_type == MWIFIEX_PCIE) &&
  442. (skb->truesize > MWIFIEX_RX_DATA_BUF_SIZE))
  443. skb->truesize += (skb->len - MWIFIEX_RX_DATA_BUF_SIZE);
  444. if (in_interrupt())
  445. netif_rx(skb);
  446. else
  447. netif_rx_ni(skb);
  448. return 0;
  449. }
  450. /*
  451. * IOCTL completion callback handler.
  452. *
  453. * This function is called when a pending IOCTL is completed.
  454. *
  455. * If work queue support is enabled, the function wakes up the
  456. * corresponding waiting function. Otherwise, it processes the
  457. * IOCTL response and frees the response buffer.
  458. */
  459. int mwifiex_complete_cmd(struct mwifiex_adapter *adapter,
  460. struct cmd_ctrl_node *cmd_node)
  461. {
  462. WARN_ON(!cmd_node->wait_q_enabled);
  463. mwifiex_dbg(adapter, CMD, "cmd completed: status=%d\n",
  464. adapter->cmd_wait_q.status);
  465. *cmd_node->condition = true;
  466. wake_up_interruptible(&adapter->cmd_wait_q.wait);
  467. return 0;
  468. }
  469. /* This function will return the pointer to station entry in station list
  470. * table which matches specified mac address.
  471. * This function should be called after acquiring RA list spinlock.
  472. * NULL is returned if station entry is not found in associated STA list.
  473. */
  474. struct mwifiex_sta_node *
  475. mwifiex_get_sta_entry(struct mwifiex_private *priv, const u8 *mac)
  476. {
  477. struct mwifiex_sta_node *node;
  478. if (!mac)
  479. return NULL;
  480. list_for_each_entry(node, &priv->sta_list, list) {
  481. if (!memcmp(node->mac_addr, mac, ETH_ALEN))
  482. return node;
  483. }
  484. return NULL;
  485. }
  486. static struct mwifiex_sta_node *
  487. mwifiex_get_tdls_sta_entry(struct mwifiex_private *priv, u8 status)
  488. {
  489. struct mwifiex_sta_node *node;
  490. list_for_each_entry(node, &priv->sta_list, list) {
  491. if (node->tdls_status == status)
  492. return node;
  493. }
  494. return NULL;
  495. }
  496. /* If tdls channel switching is on-going, tx data traffic should be
  497. * blocked until the switching stage completed.
  498. */
  499. u8 mwifiex_is_tdls_chan_switching(struct mwifiex_private *priv)
  500. {
  501. struct mwifiex_sta_node *sta_ptr;
  502. if (!priv || !ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info))
  503. return false;
  504. sta_ptr = mwifiex_get_tdls_sta_entry(priv, TDLS_CHAN_SWITCHING);
  505. if (sta_ptr)
  506. return true;
  507. return false;
  508. }
  509. u8 mwifiex_is_tdls_off_chan(struct mwifiex_private *priv)
  510. {
  511. struct mwifiex_sta_node *sta_ptr;
  512. if (!priv || !ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info))
  513. return false;
  514. sta_ptr = mwifiex_get_tdls_sta_entry(priv, TDLS_IN_OFF_CHAN);
  515. if (sta_ptr)
  516. return true;
  517. return false;
  518. }
  519. /* If tdls channel switching is on-going or tdls operate on off-channel,
  520. * cmd path should be blocked until tdls switched to base-channel.
  521. */
  522. u8 mwifiex_is_send_cmd_allowed(struct mwifiex_private *priv)
  523. {
  524. if (!priv || !ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info))
  525. return true;
  526. if (mwifiex_is_tdls_chan_switching(priv) ||
  527. mwifiex_is_tdls_off_chan(priv))
  528. return false;
  529. return true;
  530. }
  531. /* This function will add a sta_node entry to associated station list
  532. * table with the given mac address.
  533. * If entry exist already, existing entry is returned.
  534. * If received mac address is NULL, NULL is returned.
  535. */
  536. struct mwifiex_sta_node *
  537. mwifiex_add_sta_entry(struct mwifiex_private *priv, const u8 *mac)
  538. {
  539. struct mwifiex_sta_node *node;
  540. unsigned long flags;
  541. if (!mac)
  542. return NULL;
  543. spin_lock_irqsave(&priv->sta_list_spinlock, flags);
  544. node = mwifiex_get_sta_entry(priv, mac);
  545. if (node)
  546. goto done;
  547. node = kzalloc(sizeof(*node), GFP_ATOMIC);
  548. if (!node)
  549. goto done;
  550. memcpy(node->mac_addr, mac, ETH_ALEN);
  551. list_add_tail(&node->list, &priv->sta_list);
  552. done:
  553. spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
  554. return node;
  555. }
  556. /* This function will search for HT IE in association request IEs
  557. * and set station HT parameters accordingly.
  558. */
  559. void
  560. mwifiex_set_sta_ht_cap(struct mwifiex_private *priv, const u8 *ies,
  561. int ies_len, struct mwifiex_sta_node *node)
  562. {
  563. struct ieee_types_header *ht_cap_ie;
  564. const struct ieee80211_ht_cap *ht_cap;
  565. if (!ies)
  566. return;
  567. ht_cap_ie = (void *)cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies,
  568. ies_len);
  569. if (ht_cap_ie) {
  570. ht_cap = (void *)(ht_cap_ie + 1);
  571. node->is_11n_enabled = 1;
  572. node->max_amsdu = le16_to_cpu(ht_cap->cap_info) &
  573. IEEE80211_HT_CAP_MAX_AMSDU ?
  574. MWIFIEX_TX_DATA_BUF_SIZE_8K :
  575. MWIFIEX_TX_DATA_BUF_SIZE_4K;
  576. } else {
  577. node->is_11n_enabled = 0;
  578. }
  579. return;
  580. }
  581. /* This function will delete a station entry from station list */
  582. void mwifiex_del_sta_entry(struct mwifiex_private *priv, const u8 *mac)
  583. {
  584. struct mwifiex_sta_node *node;
  585. unsigned long flags;
  586. spin_lock_irqsave(&priv->sta_list_spinlock, flags);
  587. node = mwifiex_get_sta_entry(priv, mac);
  588. if (node) {
  589. list_del(&node->list);
  590. kfree(node);
  591. }
  592. spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
  593. return;
  594. }
  595. /* This function will delete all stations from associated station list. */
  596. void mwifiex_del_all_sta_list(struct mwifiex_private *priv)
  597. {
  598. struct mwifiex_sta_node *node, *tmp;
  599. unsigned long flags;
  600. spin_lock_irqsave(&priv->sta_list_spinlock, flags);
  601. list_for_each_entry_safe(node, tmp, &priv->sta_list, list) {
  602. list_del(&node->list);
  603. kfree(node);
  604. }
  605. INIT_LIST_HEAD(&priv->sta_list);
  606. spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
  607. return;
  608. }
  609. /* This function adds histogram data to histogram array*/
  610. void mwifiex_hist_data_add(struct mwifiex_private *priv,
  611. u8 rx_rate, s8 snr, s8 nflr)
  612. {
  613. struct mwifiex_histogram_data *phist_data = priv->hist_data;
  614. if (atomic_read(&phist_data->num_samples) > MWIFIEX_HIST_MAX_SAMPLES)
  615. mwifiex_hist_data_reset(priv);
  616. mwifiex_hist_data_set(priv, rx_rate, snr, nflr);
  617. }
  618. /* function to add histogram record */
  619. void mwifiex_hist_data_set(struct mwifiex_private *priv, u8 rx_rate, s8 snr,
  620. s8 nflr)
  621. {
  622. struct mwifiex_histogram_data *phist_data = priv->hist_data;
  623. s8 nf = -nflr;
  624. s8 rssi = snr - nflr;
  625. atomic_inc(&phist_data->num_samples);
  626. atomic_inc(&phist_data->rx_rate[rx_rate]);
  627. atomic_inc(&phist_data->snr[snr + 128]);
  628. atomic_inc(&phist_data->noise_flr[nf + 128]);
  629. atomic_inc(&phist_data->sig_str[rssi + 128]);
  630. }
  631. /* function to reset histogram data during init/reset */
  632. void mwifiex_hist_data_reset(struct mwifiex_private *priv)
  633. {
  634. int ix;
  635. struct mwifiex_histogram_data *phist_data = priv->hist_data;
  636. atomic_set(&phist_data->num_samples, 0);
  637. for (ix = 0; ix < MWIFIEX_MAX_AC_RX_RATES; ix++)
  638. atomic_set(&phist_data->rx_rate[ix], 0);
  639. for (ix = 0; ix < MWIFIEX_MAX_SNR; ix++)
  640. atomic_set(&phist_data->snr[ix], 0);
  641. for (ix = 0; ix < MWIFIEX_MAX_NOISE_FLR; ix++)
  642. atomic_set(&phist_data->noise_flr[ix], 0);
  643. for (ix = 0; ix < MWIFIEX_MAX_SIG_STRENGTH; ix++)
  644. atomic_set(&phist_data->sig_str[ix], 0);
  645. }
  646. void *mwifiex_alloc_dma_align_buf(int rx_len, gfp_t flags)
  647. {
  648. struct sk_buff *skb;
  649. int buf_len, pad;
  650. buf_len = rx_len + MWIFIEX_RX_HEADROOM + MWIFIEX_DMA_ALIGN_SZ;
  651. skb = __dev_alloc_skb(buf_len, flags);
  652. if (!skb)
  653. return NULL;
  654. skb_reserve(skb, MWIFIEX_RX_HEADROOM);
  655. pad = MWIFIEX_ALIGN_ADDR(skb->data, MWIFIEX_DMA_ALIGN_SZ) -
  656. (long)skb->data;
  657. skb_reserve(skb, pad);
  658. return skb;
  659. }
  660. EXPORT_SYMBOL_GPL(mwifiex_alloc_dma_align_buf);
  661. void mwifiex_fw_dump_event(struct mwifiex_private *priv)
  662. {
  663. mwifiex_send_cmd(priv, HostCmd_CMD_FW_DUMP_EVENT, HostCmd_ACT_GEN_SET,
  664. 0, NULL, true);
  665. }
  666. EXPORT_SYMBOL_GPL(mwifiex_fw_dump_event);