util.c 23 KB

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