util.c 22 KB

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