core.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. #ifndef _QTN_FMAC_CORE_H_
  17. #define _QTN_FMAC_CORE_H_
  18. #include <linux/kernel.h>
  19. #include <linux/module.h>
  20. #include <linux/sched.h>
  21. #include <linux/semaphore.h>
  22. #include <linux/ip.h>
  23. #include <linux/skbuff.h>
  24. #include <linux/if_arp.h>
  25. #include <linux/etherdevice.h>
  26. #include <net/sock.h>
  27. #include <net/lib80211.h>
  28. #include <net/cfg80211.h>
  29. #include <linux/vmalloc.h>
  30. #include <linux/firmware.h>
  31. #include <linux/ctype.h>
  32. #include <linux/workqueue.h>
  33. #include <linux/slab.h>
  34. #include "qlink.h"
  35. #include "trans.h"
  36. #undef pr_fmt
  37. #define pr_fmt(fmt) KBUILD_MODNAME ": %s: " fmt, __func__
  38. #define QTNF_MAX_SSID_LIST_LENGTH 2
  39. #define QTNF_MAX_VSIE_LEN 255
  40. #define QTNF_MAX_INTF 8
  41. #define QTNF_MAX_EVENT_QUEUE_LEN 255
  42. #define QTNF_DEFAULT_BG_SCAN_PERIOD 300
  43. #define QTNF_MAX_BG_SCAN_PERIOD 0xffff
  44. #define QTNF_SCAN_TIMEOUT_SEC 15
  45. #define QTNF_DEF_BSS_PRIORITY 0
  46. #define QTNF_DEF_WDOG_TIMEOUT 5
  47. #define QTNF_TX_TIMEOUT_TRSHLD 100
  48. #define QTNF_STATE_AP_CONFIG BIT(2)
  49. #define QTNF_STATE_AP_START BIT(1)
  50. extern const struct net_device_ops qtnf_netdev_ops;
  51. struct qtnf_bus;
  52. struct qtnf_vif;
  53. struct qtnf_bss_config {
  54. u8 ssid[IEEE80211_MAX_SSID_LEN];
  55. u8 bssid[ETH_ALEN];
  56. size_t ssid_len;
  57. u8 dtim;
  58. u16 bcn_period;
  59. u16 auth_type;
  60. bool privacy;
  61. enum nl80211_mfp mfp;
  62. struct cfg80211_crypto_settings crypto;
  63. u16 bg_scan_period;
  64. u32 connect_flags;
  65. };
  66. struct qtnf_sta_node {
  67. struct list_head list;
  68. u8 mac_addr[ETH_ALEN];
  69. };
  70. struct qtnf_sta_list {
  71. struct list_head head;
  72. atomic_t size;
  73. };
  74. enum qtnf_sta_state {
  75. QTNF_STA_DISCONNECTED,
  76. QTNF_STA_CONNECTING,
  77. QTNF_STA_CONNECTED
  78. };
  79. enum qtnf_mac_status {
  80. QTNF_MAC_CSA_ACTIVE = BIT(0)
  81. };
  82. struct qtnf_vif {
  83. struct wireless_dev wdev;
  84. u8 vifid;
  85. u8 bss_priority;
  86. u8 bss_status;
  87. enum qtnf_sta_state sta_state;
  88. u16 mgmt_frames_bitmask;
  89. struct net_device *netdev;
  90. struct qtnf_wmac *mac;
  91. u8 mac_addr[ETH_ALEN];
  92. struct work_struct reset_work;
  93. struct qtnf_bss_config bss_cfg;
  94. struct qtnf_sta_list sta_list;
  95. unsigned long cons_tx_timeout_cnt;
  96. };
  97. struct qtnf_mac_info {
  98. u8 bands_cap;
  99. u8 phymode_cap;
  100. u8 dev_mac[ETH_ALEN];
  101. u8 num_tx_chain;
  102. u8 num_rx_chain;
  103. u16 max_ap_assoc_sta;
  104. u32 frag_thr;
  105. u32 rts_thr;
  106. u8 lretry_limit;
  107. u8 sretry_limit;
  108. u8 coverage_class;
  109. u8 radar_detect_widths;
  110. struct ieee80211_ht_cap ht_cap;
  111. struct ieee80211_vht_cap vht_cap;
  112. struct ieee80211_iface_limit *limits;
  113. size_t n_limits;
  114. };
  115. struct qtnf_chan_stats {
  116. u32 chan_num;
  117. u32 cca_tx;
  118. u32 cca_rx;
  119. u32 cca_busy;
  120. u32 cca_try;
  121. s8 chan_noise;
  122. };
  123. struct qtnf_wmac {
  124. u8 macid;
  125. u8 wiphy_registered;
  126. u8 macaddr[ETH_ALEN];
  127. u32 status;
  128. struct qtnf_bus *bus;
  129. struct qtnf_mac_info macinfo;
  130. struct qtnf_vif iflist[QTNF_MAX_INTF];
  131. struct cfg80211_scan_request *scan_req;
  132. struct cfg80211_chan_def chandef;
  133. struct cfg80211_chan_def csa_chandef;
  134. struct mutex mac_lock; /* lock during wmac speicific ops */
  135. struct timer_list scan_timeout;
  136. };
  137. struct qtnf_hw_info {
  138. u16 ql_proto_ver;
  139. u8 num_mac;
  140. u8 mac_bitmap;
  141. u32 fw_ver;
  142. u32 hw_capab;
  143. struct ieee80211_regdomain *rd;
  144. u8 total_tx_chain;
  145. u8 total_rx_chain;
  146. };
  147. struct qtnf_vif *qtnf_mac_get_free_vif(struct qtnf_wmac *mac);
  148. struct qtnf_vif *qtnf_mac_get_base_vif(struct qtnf_wmac *mac);
  149. struct wiphy *qtnf_wiphy_allocate(struct qtnf_bus *bus);
  150. int qtnf_core_net_attach(struct qtnf_wmac *mac, struct qtnf_vif *priv,
  151. const char *name, unsigned char name_assign_type,
  152. enum nl80211_iftype iftype);
  153. void qtnf_main_work_queue(struct work_struct *work);
  154. int qtnf_cmd_send_update_phy_params(struct qtnf_wmac *mac, u32 changed);
  155. int qtnf_cmd_send_get_phy_params(struct qtnf_wmac *mac);
  156. struct qtnf_wmac *qtnf_core_get_mac(const struct qtnf_bus *bus, u8 macid);
  157. struct net_device *qtnf_classify_skb(struct qtnf_bus *bus, struct sk_buff *skb);
  158. struct net_device *qtnf_classify_skb_no_mbss(struct qtnf_bus *bus,
  159. struct sk_buff *skb);
  160. void qtnf_virtual_intf_cleanup(struct net_device *ndev);
  161. void qtnf_netdev_updown(struct net_device *ndev, bool up);
  162. static inline struct qtnf_vif *qtnf_netdev_get_priv(struct net_device *dev)
  163. {
  164. return *((void **)netdev_priv(dev));
  165. }
  166. #endif /* _QTN_FMAC_CORE_H_ */