core.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774
  1. /*
  2. * Copyright (c) 2015-2016 Quantenna Communications, Inc.
  3. * All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation; either version 2
  8. * of the License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. */
  16. #include <linux/kernel.h>
  17. #include <linux/module.h>
  18. #include <linux/if_ether.h>
  19. #include "core.h"
  20. #include "bus.h"
  21. #include "trans.h"
  22. #include "commands.h"
  23. #include "cfg80211.h"
  24. #include "event.h"
  25. #include "util.h"
  26. #define QTNF_DMP_MAX_LEN 48
  27. #define QTNF_PRIMARY_VIF_IDX 0
  28. struct qtnf_frame_meta_info {
  29. u8 magic_s;
  30. u8 ifidx;
  31. u8 macid;
  32. u8 magic_e;
  33. } __packed;
  34. struct qtnf_wmac *qtnf_core_get_mac(const struct qtnf_bus *bus, u8 macid)
  35. {
  36. struct qtnf_wmac *mac = NULL;
  37. if (unlikely(macid >= QTNF_MAX_MAC)) {
  38. pr_err("invalid MAC index %u\n", macid);
  39. return NULL;
  40. }
  41. mac = bus->mac[macid];
  42. if (unlikely(!mac)) {
  43. pr_err("MAC%u: not initialized\n", macid);
  44. return NULL;
  45. }
  46. return mac;
  47. }
  48. /* Netdev handler for open.
  49. */
  50. static int qtnf_netdev_open(struct net_device *ndev)
  51. {
  52. netif_carrier_off(ndev);
  53. qtnf_netdev_updown(ndev, 1);
  54. return 0;
  55. }
  56. /* Netdev handler for close.
  57. */
  58. static int qtnf_netdev_close(struct net_device *ndev)
  59. {
  60. netif_carrier_off(ndev);
  61. qtnf_virtual_intf_cleanup(ndev);
  62. qtnf_netdev_updown(ndev, 0);
  63. return 0;
  64. }
  65. /* Netdev handler for data transmission.
  66. */
  67. static netdev_tx_t
  68. qtnf_netdev_hard_start_xmit(struct sk_buff *skb, struct net_device *ndev)
  69. {
  70. struct qtnf_vif *vif;
  71. struct qtnf_wmac *mac;
  72. vif = qtnf_netdev_get_priv(ndev);
  73. if (unlikely(skb->dev != ndev)) {
  74. pr_err_ratelimited("invalid skb->dev");
  75. dev_kfree_skb_any(skb);
  76. return 0;
  77. }
  78. if (unlikely(vif->wdev.iftype == NL80211_IFTYPE_UNSPECIFIED)) {
  79. pr_err_ratelimited("%s: VIF not initialized\n", ndev->name);
  80. dev_kfree_skb_any(skb);
  81. return 0;
  82. }
  83. mac = vif->mac;
  84. if (unlikely(!mac)) {
  85. pr_err_ratelimited("%s: NULL mac pointer", ndev->name);
  86. dev_kfree_skb_any(skb);
  87. return 0;
  88. }
  89. if (!skb->len || (skb->len > ETH_FRAME_LEN)) {
  90. pr_err_ratelimited("%s: invalid skb len %d\n", ndev->name,
  91. skb->len);
  92. dev_kfree_skb_any(skb);
  93. ndev->stats.tx_dropped++;
  94. return 0;
  95. }
  96. /* tx path is enabled: reset vif timeout */
  97. vif->cons_tx_timeout_cnt = 0;
  98. return qtnf_bus_data_tx(mac->bus, skb);
  99. }
  100. /* Netdev handler for getting stats.
  101. */
  102. static void qtnf_netdev_get_stats64(struct net_device *ndev,
  103. struct rtnl_link_stats64 *stats)
  104. {
  105. struct qtnf_vif *vif = qtnf_netdev_get_priv(ndev);
  106. unsigned int start;
  107. int cpu;
  108. netdev_stats_to_stats64(stats, &ndev->stats);
  109. if (!vif->stats64)
  110. return;
  111. for_each_possible_cpu(cpu) {
  112. struct pcpu_sw_netstats *stats64;
  113. u64 rx_packets, rx_bytes;
  114. u64 tx_packets, tx_bytes;
  115. stats64 = per_cpu_ptr(vif->stats64, cpu);
  116. do {
  117. start = u64_stats_fetch_begin_irq(&stats64->syncp);
  118. rx_packets = stats64->rx_packets;
  119. rx_bytes = stats64->rx_bytes;
  120. tx_packets = stats64->tx_packets;
  121. tx_bytes = stats64->tx_bytes;
  122. } while (u64_stats_fetch_retry_irq(&stats64->syncp, start));
  123. stats->rx_packets += rx_packets;
  124. stats->rx_bytes += rx_bytes;
  125. stats->tx_packets += tx_packets;
  126. stats->tx_bytes += tx_bytes;
  127. }
  128. }
  129. /* Netdev handler for transmission timeout.
  130. */
  131. static void qtnf_netdev_tx_timeout(struct net_device *ndev)
  132. {
  133. struct qtnf_vif *vif = qtnf_netdev_get_priv(ndev);
  134. struct qtnf_wmac *mac;
  135. struct qtnf_bus *bus;
  136. if (unlikely(!vif || !vif->mac || !vif->mac->bus))
  137. return;
  138. mac = vif->mac;
  139. bus = mac->bus;
  140. pr_warn("VIF%u.%u: Tx timeout- %lu\n", mac->macid, vif->vifid, jiffies);
  141. qtnf_bus_data_tx_timeout(bus, ndev);
  142. ndev->stats.tx_errors++;
  143. if (++vif->cons_tx_timeout_cnt > QTNF_TX_TIMEOUT_TRSHLD) {
  144. pr_err("Tx timeout threshold exceeded !\n");
  145. pr_err("schedule interface %s reset !\n", netdev_name(ndev));
  146. queue_work(bus->workqueue, &vif->reset_work);
  147. }
  148. }
  149. /* Network device ops handlers */
  150. const struct net_device_ops qtnf_netdev_ops = {
  151. .ndo_open = qtnf_netdev_open,
  152. .ndo_stop = qtnf_netdev_close,
  153. .ndo_start_xmit = qtnf_netdev_hard_start_xmit,
  154. .ndo_tx_timeout = qtnf_netdev_tx_timeout,
  155. .ndo_get_stats64 = qtnf_netdev_get_stats64,
  156. };
  157. static int qtnf_mac_init_single_band(struct wiphy *wiphy,
  158. struct qtnf_wmac *mac,
  159. enum nl80211_band band)
  160. {
  161. int ret;
  162. wiphy->bands[band] = kzalloc(sizeof(*wiphy->bands[band]), GFP_KERNEL);
  163. if (!wiphy->bands[band])
  164. return -ENOMEM;
  165. wiphy->bands[band]->band = band;
  166. ret = qtnf_cmd_band_info_get(mac, wiphy->bands[band]);
  167. if (ret) {
  168. pr_err("MAC%u: band %u: failed to get chans info: %d\n",
  169. mac->macid, band, ret);
  170. return ret;
  171. }
  172. qtnf_band_init_rates(wiphy->bands[band]);
  173. return 0;
  174. }
  175. static int qtnf_mac_init_bands(struct qtnf_wmac *mac)
  176. {
  177. struct wiphy *wiphy = priv_to_wiphy(mac);
  178. int ret = 0;
  179. if (mac->macinfo.bands_cap & QLINK_BAND_2GHZ) {
  180. ret = qtnf_mac_init_single_band(wiphy, mac, NL80211_BAND_2GHZ);
  181. if (ret)
  182. goto out;
  183. }
  184. if (mac->macinfo.bands_cap & QLINK_BAND_5GHZ) {
  185. ret = qtnf_mac_init_single_band(wiphy, mac, NL80211_BAND_5GHZ);
  186. if (ret)
  187. goto out;
  188. }
  189. if (mac->macinfo.bands_cap & QLINK_BAND_60GHZ)
  190. ret = qtnf_mac_init_single_band(wiphy, mac, NL80211_BAND_60GHZ);
  191. out:
  192. return ret;
  193. }
  194. struct qtnf_vif *qtnf_mac_get_free_vif(struct qtnf_wmac *mac)
  195. {
  196. struct qtnf_vif *vif;
  197. int i;
  198. for (i = 0; i < QTNF_MAX_INTF; i++) {
  199. vif = &mac->iflist[i];
  200. if (vif->wdev.iftype == NL80211_IFTYPE_UNSPECIFIED)
  201. return vif;
  202. }
  203. return NULL;
  204. }
  205. struct qtnf_vif *qtnf_mac_get_base_vif(struct qtnf_wmac *mac)
  206. {
  207. struct qtnf_vif *vif;
  208. vif = &mac->iflist[QTNF_PRIMARY_VIF_IDX];
  209. if (vif->wdev.iftype == NL80211_IFTYPE_UNSPECIFIED)
  210. return NULL;
  211. return vif;
  212. }
  213. void qtnf_mac_iface_comb_free(struct qtnf_wmac *mac)
  214. {
  215. struct ieee80211_iface_combination *comb;
  216. int i;
  217. if (mac->macinfo.if_comb) {
  218. for (i = 0; i < mac->macinfo.n_if_comb; i++) {
  219. comb = &mac->macinfo.if_comb[i];
  220. kfree(comb->limits);
  221. comb->limits = NULL;
  222. }
  223. kfree(mac->macinfo.if_comb);
  224. mac->macinfo.if_comb = NULL;
  225. }
  226. }
  227. static void qtnf_vif_reset_handler(struct work_struct *work)
  228. {
  229. struct qtnf_vif *vif = container_of(work, struct qtnf_vif, reset_work);
  230. rtnl_lock();
  231. if (vif->wdev.iftype == NL80211_IFTYPE_UNSPECIFIED) {
  232. rtnl_unlock();
  233. return;
  234. }
  235. /* stop tx completely */
  236. netif_tx_stop_all_queues(vif->netdev);
  237. if (netif_carrier_ok(vif->netdev))
  238. netif_carrier_off(vif->netdev);
  239. qtnf_cfg80211_vif_reset(vif);
  240. rtnl_unlock();
  241. }
  242. static void qtnf_mac_init_primary_intf(struct qtnf_wmac *mac)
  243. {
  244. struct qtnf_vif *vif = &mac->iflist[QTNF_PRIMARY_VIF_IDX];
  245. vif->wdev.iftype = NL80211_IFTYPE_STATION;
  246. vif->bss_priority = QTNF_DEF_BSS_PRIORITY;
  247. vif->wdev.wiphy = priv_to_wiphy(mac);
  248. INIT_WORK(&vif->reset_work, qtnf_vif_reset_handler);
  249. vif->cons_tx_timeout_cnt = 0;
  250. }
  251. static void qtnf_mac_scan_finish(struct qtnf_wmac *mac, bool aborted)
  252. {
  253. struct cfg80211_scan_info info = {
  254. .aborted = aborted,
  255. };
  256. mutex_lock(&mac->mac_lock);
  257. if (mac->scan_req) {
  258. cfg80211_scan_done(mac->scan_req, &info);
  259. mac->scan_req = NULL;
  260. }
  261. mutex_unlock(&mac->mac_lock);
  262. }
  263. void qtnf_scan_done(struct qtnf_wmac *mac, bool aborted)
  264. {
  265. cancel_delayed_work_sync(&mac->scan_timeout);
  266. qtnf_mac_scan_finish(mac, aborted);
  267. }
  268. static void qtnf_mac_scan_timeout(struct work_struct *work)
  269. {
  270. struct qtnf_wmac *mac =
  271. container_of(work, struct qtnf_wmac, scan_timeout.work);
  272. pr_warn("MAC%d: scan timed out\n", mac->macid);
  273. qtnf_mac_scan_finish(mac, true);
  274. }
  275. static struct qtnf_wmac *qtnf_core_mac_alloc(struct qtnf_bus *bus,
  276. unsigned int macid)
  277. {
  278. struct wiphy *wiphy;
  279. struct qtnf_wmac *mac;
  280. unsigned int i;
  281. wiphy = qtnf_wiphy_allocate(bus);
  282. if (!wiphy)
  283. return ERR_PTR(-ENOMEM);
  284. mac = wiphy_priv(wiphy);
  285. mac->macid = macid;
  286. mac->bus = bus;
  287. for (i = 0; i < QTNF_MAX_INTF; i++) {
  288. memset(&mac->iflist[i], 0, sizeof(struct qtnf_vif));
  289. mac->iflist[i].wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
  290. mac->iflist[i].mac = mac;
  291. mac->iflist[i].vifid = i;
  292. qtnf_sta_list_init(&mac->iflist[i].sta_list);
  293. mutex_init(&mac->mac_lock);
  294. INIT_DELAYED_WORK(&mac->scan_timeout, qtnf_mac_scan_timeout);
  295. mac->iflist[i].stats64 =
  296. netdev_alloc_pcpu_stats(struct pcpu_sw_netstats);
  297. if (!mac->iflist[i].stats64)
  298. pr_warn("VIF%u.%u: per cpu stats allocation failed\n",
  299. macid, i);
  300. }
  301. qtnf_mac_init_primary_intf(mac);
  302. bus->mac[macid] = mac;
  303. return mac;
  304. }
  305. static const struct ethtool_ops qtnf_ethtool_ops = {
  306. .get_drvinfo = cfg80211_get_drvinfo,
  307. };
  308. int qtnf_core_net_attach(struct qtnf_wmac *mac, struct qtnf_vif *vif,
  309. const char *name, unsigned char name_assign_type)
  310. {
  311. struct wiphy *wiphy = priv_to_wiphy(mac);
  312. struct net_device *dev;
  313. void *qdev_vif;
  314. int ret;
  315. dev = alloc_netdev_mqs(sizeof(struct qtnf_vif *), name,
  316. name_assign_type, ether_setup, 1, 1);
  317. if (!dev) {
  318. vif->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
  319. return -ENOMEM;
  320. }
  321. vif->netdev = dev;
  322. dev->netdev_ops = &qtnf_netdev_ops;
  323. dev->needs_free_netdev = true;
  324. dev_net_set(dev, wiphy_net(wiphy));
  325. dev->ieee80211_ptr = &vif->wdev;
  326. ether_addr_copy(dev->dev_addr, vif->mac_addr);
  327. SET_NETDEV_DEV(dev, wiphy_dev(wiphy));
  328. dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
  329. dev->watchdog_timeo = QTNF_DEF_WDOG_TIMEOUT;
  330. dev->tx_queue_len = 100;
  331. dev->ethtool_ops = &qtnf_ethtool_ops;
  332. qdev_vif = netdev_priv(dev);
  333. *((void **)qdev_vif) = vif;
  334. SET_NETDEV_DEV(dev, mac->bus->dev);
  335. ret = register_netdevice(dev);
  336. if (ret) {
  337. free_netdev(dev);
  338. vif->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
  339. }
  340. return ret;
  341. }
  342. static void qtnf_core_mac_detach(struct qtnf_bus *bus, unsigned int macid)
  343. {
  344. struct qtnf_wmac *mac;
  345. struct wiphy *wiphy;
  346. struct qtnf_vif *vif;
  347. unsigned int i;
  348. enum nl80211_band band;
  349. mac = bus->mac[macid];
  350. if (!mac)
  351. return;
  352. wiphy = priv_to_wiphy(mac);
  353. for (i = 0; i < QTNF_MAX_INTF; i++) {
  354. vif = &mac->iflist[i];
  355. rtnl_lock();
  356. if (vif->netdev &&
  357. vif->wdev.iftype != NL80211_IFTYPE_UNSPECIFIED) {
  358. qtnf_virtual_intf_cleanup(vif->netdev);
  359. qtnf_del_virtual_intf(wiphy, &vif->wdev);
  360. }
  361. rtnl_unlock();
  362. qtnf_sta_list_free(&vif->sta_list);
  363. free_percpu(vif->stats64);
  364. }
  365. if (mac->wiphy_registered)
  366. wiphy_unregister(wiphy);
  367. for (band = NL80211_BAND_2GHZ; band < NUM_NL80211_BANDS; ++band) {
  368. if (!wiphy->bands[band])
  369. continue;
  370. kfree(wiphy->bands[band]->channels);
  371. wiphy->bands[band]->n_channels = 0;
  372. kfree(wiphy->bands[band]);
  373. wiphy->bands[band] = NULL;
  374. }
  375. qtnf_mac_iface_comb_free(mac);
  376. kfree(mac->macinfo.extended_capabilities);
  377. kfree(mac->macinfo.extended_capabilities_mask);
  378. wiphy_free(wiphy);
  379. bus->mac[macid] = NULL;
  380. }
  381. static int qtnf_core_mac_attach(struct qtnf_bus *bus, unsigned int macid)
  382. {
  383. struct qtnf_wmac *mac;
  384. struct qtnf_vif *vif;
  385. int ret;
  386. if (!(bus->hw_info.mac_bitmap & BIT(macid))) {
  387. pr_info("MAC%u is not active in FW\n", macid);
  388. return 0;
  389. }
  390. mac = qtnf_core_mac_alloc(bus, macid);
  391. if (IS_ERR(mac)) {
  392. pr_err("MAC%u allocation failed\n", macid);
  393. return PTR_ERR(mac);
  394. }
  395. ret = qtnf_cmd_get_mac_info(mac);
  396. if (ret) {
  397. pr_err("MAC%u: failed to get info\n", macid);
  398. goto error;
  399. }
  400. vif = qtnf_mac_get_base_vif(mac);
  401. if (!vif) {
  402. pr_err("MAC%u: primary VIF is not ready\n", macid);
  403. ret = -EFAULT;
  404. goto error;
  405. }
  406. ret = qtnf_cmd_send_add_intf(vif, vif->wdev.iftype, vif->mac_addr);
  407. if (ret) {
  408. pr_err("MAC%u: failed to add VIF\n", macid);
  409. goto error;
  410. }
  411. ret = qtnf_cmd_send_get_phy_params(mac);
  412. if (ret) {
  413. pr_err("MAC%u: failed to get PHY settings\n", macid);
  414. goto error;
  415. }
  416. ret = qtnf_mac_init_bands(mac);
  417. if (ret) {
  418. pr_err("MAC%u: failed to init bands\n", macid);
  419. goto error;
  420. }
  421. ret = qtnf_wiphy_register(&bus->hw_info, mac);
  422. if (ret) {
  423. pr_err("MAC%u: wiphy registration failed\n", macid);
  424. goto error;
  425. }
  426. mac->wiphy_registered = 1;
  427. rtnl_lock();
  428. ret = qtnf_core_net_attach(mac, vif, "wlan%d", NET_NAME_ENUM);
  429. rtnl_unlock();
  430. if (ret) {
  431. pr_err("MAC%u: failed to attach netdev\n", macid);
  432. vif->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
  433. vif->netdev = NULL;
  434. goto error;
  435. }
  436. pr_debug("MAC%u initialized\n", macid);
  437. return 0;
  438. error:
  439. qtnf_core_mac_detach(bus, macid);
  440. return ret;
  441. }
  442. int qtnf_core_attach(struct qtnf_bus *bus)
  443. {
  444. unsigned int i;
  445. int ret;
  446. qtnf_trans_init(bus);
  447. bus->fw_state = QTNF_FW_STATE_BOOT_DONE;
  448. qtnf_bus_data_rx_start(bus);
  449. bus->workqueue = alloc_ordered_workqueue("QTNF_BUS", 0);
  450. if (!bus->workqueue) {
  451. pr_err("failed to alloc main workqueue\n");
  452. ret = -ENOMEM;
  453. goto error;
  454. }
  455. INIT_WORK(&bus->event_work, qtnf_event_work_handler);
  456. ret = qtnf_cmd_send_init_fw(bus);
  457. if (ret) {
  458. pr_err("failed to init FW: %d\n", ret);
  459. goto error;
  460. }
  461. bus->fw_state = QTNF_FW_STATE_ACTIVE;
  462. ret = qtnf_cmd_get_hw_info(bus);
  463. if (ret) {
  464. pr_err("failed to get HW info: %d\n", ret);
  465. goto error;
  466. }
  467. if (bus->hw_info.ql_proto_ver != QLINK_PROTO_VER) {
  468. pr_err("qlink version mismatch %u != %u\n",
  469. QLINK_PROTO_VER, bus->hw_info.ql_proto_ver);
  470. ret = -EPROTONOSUPPORT;
  471. goto error;
  472. }
  473. if (bus->hw_info.num_mac > QTNF_MAX_MAC) {
  474. pr_err("no support for number of MACs=%u\n",
  475. bus->hw_info.num_mac);
  476. ret = -ERANGE;
  477. goto error;
  478. }
  479. for (i = 0; i < bus->hw_info.num_mac; i++) {
  480. ret = qtnf_core_mac_attach(bus, i);
  481. if (ret) {
  482. pr_err("MAC%u: attach failed: %d\n", i, ret);
  483. goto error;
  484. }
  485. }
  486. return 0;
  487. error:
  488. qtnf_core_detach(bus);
  489. return ret;
  490. }
  491. EXPORT_SYMBOL_GPL(qtnf_core_attach);
  492. void qtnf_core_detach(struct qtnf_bus *bus)
  493. {
  494. unsigned int macid;
  495. qtnf_bus_data_rx_stop(bus);
  496. for (macid = 0; macid < QTNF_MAX_MAC; macid++)
  497. qtnf_core_mac_detach(bus, macid);
  498. if (bus->fw_state == QTNF_FW_STATE_ACTIVE)
  499. qtnf_cmd_send_deinit_fw(bus);
  500. bus->fw_state = QTNF_FW_STATE_DETACHED;
  501. if (bus->workqueue) {
  502. flush_workqueue(bus->workqueue);
  503. destroy_workqueue(bus->workqueue);
  504. }
  505. kfree(bus->hw_info.rd);
  506. bus->hw_info.rd = NULL;
  507. qtnf_trans_free(bus);
  508. }
  509. EXPORT_SYMBOL_GPL(qtnf_core_detach);
  510. static inline int qtnf_is_frame_meta_magic_valid(struct qtnf_frame_meta_info *m)
  511. {
  512. return m->magic_s == 0xAB && m->magic_e == 0xBA;
  513. }
  514. struct net_device *qtnf_classify_skb(struct qtnf_bus *bus, struct sk_buff *skb)
  515. {
  516. struct qtnf_frame_meta_info *meta;
  517. struct net_device *ndev = NULL;
  518. struct qtnf_wmac *mac;
  519. struct qtnf_vif *vif;
  520. meta = (struct qtnf_frame_meta_info *)
  521. (skb_tail_pointer(skb) - sizeof(*meta));
  522. if (unlikely(!qtnf_is_frame_meta_magic_valid(meta))) {
  523. pr_err_ratelimited("invalid magic 0x%x:0x%x\n",
  524. meta->magic_s, meta->magic_e);
  525. goto out;
  526. }
  527. if (unlikely(meta->macid >= QTNF_MAX_MAC)) {
  528. pr_err_ratelimited("invalid mac(%u)\n", meta->macid);
  529. goto out;
  530. }
  531. if (unlikely(meta->ifidx >= QTNF_MAX_INTF)) {
  532. pr_err_ratelimited("invalid vif(%u)\n", meta->ifidx);
  533. goto out;
  534. }
  535. mac = bus->mac[meta->macid];
  536. if (unlikely(!mac)) {
  537. pr_err_ratelimited("mac(%d) does not exist\n", meta->macid);
  538. goto out;
  539. }
  540. vif = &mac->iflist[meta->ifidx];
  541. if (unlikely(vif->wdev.iftype == NL80211_IFTYPE_UNSPECIFIED)) {
  542. pr_err_ratelimited("vif(%u) does not exists\n", meta->ifidx);
  543. goto out;
  544. }
  545. ndev = vif->netdev;
  546. if (unlikely(!ndev)) {
  547. pr_err_ratelimited("netdev for wlan%u.%u does not exists\n",
  548. meta->macid, meta->ifidx);
  549. goto out;
  550. }
  551. __skb_trim(skb, skb->len - sizeof(*meta));
  552. out:
  553. return ndev;
  554. }
  555. EXPORT_SYMBOL_GPL(qtnf_classify_skb);
  556. void qtnf_wake_all_queues(struct net_device *ndev)
  557. {
  558. struct qtnf_vif *vif = qtnf_netdev_get_priv(ndev);
  559. struct qtnf_wmac *mac;
  560. struct qtnf_bus *bus;
  561. int macid;
  562. int i;
  563. if (unlikely(!vif || !vif->mac || !vif->mac->bus))
  564. return;
  565. bus = vif->mac->bus;
  566. for (macid = 0; macid < QTNF_MAX_MAC; macid++) {
  567. if (!(bus->hw_info.mac_bitmap & BIT(macid)))
  568. continue;
  569. mac = bus->mac[macid];
  570. for (i = 0; i < QTNF_MAX_INTF; i++) {
  571. vif = &mac->iflist[i];
  572. if (vif->netdev && netif_queue_stopped(vif->netdev))
  573. netif_tx_wake_all_queues(vif->netdev);
  574. }
  575. }
  576. }
  577. EXPORT_SYMBOL_GPL(qtnf_wake_all_queues);
  578. void qtnf_update_rx_stats(struct net_device *ndev, const struct sk_buff *skb)
  579. {
  580. struct qtnf_vif *vif = qtnf_netdev_get_priv(ndev);
  581. struct pcpu_sw_netstats *stats64;
  582. if (unlikely(!vif || !vif->stats64)) {
  583. ndev->stats.rx_packets++;
  584. ndev->stats.rx_bytes += skb->len;
  585. return;
  586. }
  587. stats64 = this_cpu_ptr(vif->stats64);
  588. u64_stats_update_begin(&stats64->syncp);
  589. stats64->rx_packets++;
  590. stats64->rx_bytes += skb->len;
  591. u64_stats_update_end(&stats64->syncp);
  592. }
  593. EXPORT_SYMBOL_GPL(qtnf_update_rx_stats);
  594. void qtnf_update_tx_stats(struct net_device *ndev, const struct sk_buff *skb)
  595. {
  596. struct qtnf_vif *vif = qtnf_netdev_get_priv(ndev);
  597. struct pcpu_sw_netstats *stats64;
  598. if (unlikely(!vif || !vif->stats64)) {
  599. ndev->stats.tx_packets++;
  600. ndev->stats.tx_bytes += skb->len;
  601. return;
  602. }
  603. stats64 = this_cpu_ptr(vif->stats64);
  604. u64_stats_update_begin(&stats64->syncp);
  605. stats64->tx_packets++;
  606. stats64->tx_bytes += skb->len;
  607. u64_stats_update_end(&stats64->syncp);
  608. }
  609. EXPORT_SYMBOL_GPL(qtnf_update_tx_stats);
  610. MODULE_AUTHOR("Quantenna Communications");
  611. MODULE_DESCRIPTION("Quantenna 802.11 wireless LAN FullMAC driver.");
  612. MODULE_LICENSE("GPL");