hif_tx_mib.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Implementation of the host-to-chip MIBs of the hardware API.
  4. *
  5. * Copyright (c) 2017-2020, Silicon Laboratories, Inc.
  6. * Copyright (c) 2010, ST-Ericsson
  7. * Copyright (C) 2010, ST-Ericsson SA
  8. */
  9. #include <linux/etherdevice.h>
  10. #include "wfx.h"
  11. #include "hif_tx.h"
  12. #include "hif_tx_mib.h"
  13. #include "hif_api_mib.h"
  14. int wfx_hif_set_output_power(struct wfx_vif *wvif, int val)
  15. {
  16. struct wfx_hif_mib_current_tx_power_level arg = {
  17. .power_level = cpu_to_le32(val * 10),
  18. };
  19. return wfx_hif_write_mib(wvif->wdev, wvif->id, HIF_MIB_ID_CURRENT_TX_POWER_LEVEL,
  20. &arg, sizeof(arg));
  21. }
  22. int wfx_hif_set_beacon_wakeup_period(struct wfx_vif *wvif,
  23. unsigned int dtim_interval, unsigned int listen_interval)
  24. {
  25. struct wfx_hif_mib_beacon_wake_up_period arg = {
  26. .wakeup_period_min = dtim_interval,
  27. .receive_dtim = 0,
  28. .wakeup_period_max = listen_interval,
  29. };
  30. if (dtim_interval > 0xFF || listen_interval > 0xFFFF)
  31. return -EINVAL;
  32. return wfx_hif_write_mib(wvif->wdev, wvif->id, HIF_MIB_ID_BEACON_WAKEUP_PERIOD,
  33. &arg, sizeof(arg));
  34. }
  35. int wfx_hif_set_rcpi_rssi_threshold(struct wfx_vif *wvif, int rssi_thold, int rssi_hyst)
  36. {
  37. struct wfx_hif_mib_rcpi_rssi_threshold arg = {
  38. .rolling_average_count = 8,
  39. .detection = 1,
  40. };
  41. if (!rssi_thold && !rssi_hyst) {
  42. arg.upperthresh = 1;
  43. arg.lowerthresh = 1;
  44. } else {
  45. arg.upper_threshold = rssi_thold + rssi_hyst;
  46. arg.upper_threshold = (arg.upper_threshold + 110) * 2;
  47. arg.lower_threshold = rssi_thold;
  48. arg.lower_threshold = (arg.lower_threshold + 110) * 2;
  49. }
  50. return wfx_hif_write_mib(wvif->wdev, wvif->id, HIF_MIB_ID_RCPI_RSSI_THRESHOLD,
  51. &arg, sizeof(arg));
  52. }
  53. int wfx_hif_get_counters_table(struct wfx_dev *wdev, int vif_id,
  54. struct wfx_hif_mib_extended_count_table *arg)
  55. {
  56. if (wfx_api_older_than(wdev, 1, 3)) {
  57. /* extended_count_table is wider than count_table */
  58. memset(arg, 0xFF, sizeof(*arg));
  59. return wfx_hif_read_mib(wdev, vif_id, HIF_MIB_ID_COUNTERS_TABLE,
  60. arg, sizeof(struct wfx_hif_mib_count_table));
  61. } else {
  62. return wfx_hif_read_mib(wdev, vif_id, HIF_MIB_ID_EXTENDED_COUNTERS_TABLE,
  63. arg, sizeof(struct wfx_hif_mib_extended_count_table));
  64. }
  65. }
  66. int wfx_hif_set_macaddr(struct wfx_vif *wvif, u8 *mac)
  67. {
  68. struct wfx_hif_mib_mac_address arg = { };
  69. if (mac)
  70. ether_addr_copy(arg.mac_addr, mac);
  71. return wfx_hif_write_mib(wvif->wdev, wvif->id, HIF_MIB_ID_DOT11_MAC_ADDRESS,
  72. &arg, sizeof(arg));
  73. }
  74. int wfx_hif_set_rx_filter(struct wfx_vif *wvif, bool filter_bssid, bool filter_prbreq)
  75. {
  76. struct wfx_hif_mib_rx_filter arg = { };
  77. if (filter_bssid)
  78. arg.bssid_filter = 1;
  79. if (!filter_prbreq)
  80. arg.fwd_probe_req = 1;
  81. return wfx_hif_write_mib(wvif->wdev, wvif->id, HIF_MIB_ID_RX_FILTER, &arg, sizeof(arg));
  82. }
  83. int wfx_hif_set_beacon_filter_table(struct wfx_vif *wvif, int tbl_len,
  84. const struct wfx_hif_ie_table_entry *tbl)
  85. {
  86. int ret;
  87. struct wfx_hif_mib_bcn_filter_table *arg;
  88. int buf_len = struct_size(arg, ie_table, tbl_len);
  89. arg = kzalloc(buf_len, GFP_KERNEL);
  90. if (!arg)
  91. return -ENOMEM;
  92. arg->num_of_info_elmts = cpu_to_le32(tbl_len);
  93. memcpy(arg->ie_table, tbl, flex_array_size(arg, ie_table, tbl_len));
  94. ret = wfx_hif_write_mib(wvif->wdev, wvif->id, HIF_MIB_ID_BEACON_FILTER_TABLE,
  95. arg, buf_len);
  96. kfree(arg);
  97. return ret;
  98. }
  99. int wfx_hif_beacon_filter_control(struct wfx_vif *wvif, int enable, int beacon_count)
  100. {
  101. struct wfx_hif_mib_bcn_filter_enable arg = {
  102. .enable = cpu_to_le32(enable),
  103. .bcn_count = cpu_to_le32(beacon_count),
  104. };
  105. return wfx_hif_write_mib(wvif->wdev, wvif->id, HIF_MIB_ID_BEACON_FILTER_ENABLE,
  106. &arg, sizeof(arg));
  107. }
  108. int wfx_hif_set_operational_mode(struct wfx_dev *wdev, enum wfx_hif_op_power_mode mode)
  109. {
  110. struct wfx_hif_mib_gl_operational_power_mode arg = {
  111. .power_mode = mode,
  112. .wup_ind_activation = 1,
  113. };
  114. return wfx_hif_write_mib(wdev, -1, HIF_MIB_ID_GL_OPERATIONAL_POWER_MODE,
  115. &arg, sizeof(arg));
  116. }
  117. int wfx_hif_set_template_frame(struct wfx_vif *wvif, struct sk_buff *skb,
  118. u8 frame_type, int init_rate)
  119. {
  120. struct wfx_hif_mib_template_frame *arg;
  121. WARN(skb->len > HIF_API_MAX_TEMPLATE_FRAME_SIZE, "frame is too big");
  122. skb_push(skb, 4);
  123. arg = (struct wfx_hif_mib_template_frame *)skb->data;
  124. skb_pull(skb, 4);
  125. arg->init_rate = init_rate;
  126. arg->frame_type = frame_type;
  127. arg->frame_length = cpu_to_le16(skb->len);
  128. return wfx_hif_write_mib(wvif->wdev, wvif->id, HIF_MIB_ID_TEMPLATE_FRAME,
  129. arg, sizeof(*arg) + skb->len);
  130. }
  131. int wfx_hif_set_mfp(struct wfx_vif *wvif, bool capable, bool required)
  132. {
  133. struct wfx_hif_mib_protected_mgmt_policy arg = { };
  134. WARN(required && !capable, "incoherent arguments");
  135. if (capable) {
  136. arg.pmf_enable = 1;
  137. arg.host_enc_auth_frames = 1;
  138. }
  139. if (!required)
  140. arg.unpmf_allowed = 1;
  141. return wfx_hif_write_mib(wvif->wdev, wvif->id, HIF_MIB_ID_PROTECTED_MGMT_POLICY,
  142. &arg, sizeof(arg));
  143. }
  144. int wfx_hif_set_block_ack_policy(struct wfx_vif *wvif, u8 tx_tid_policy, u8 rx_tid_policy)
  145. {
  146. struct wfx_hif_mib_block_ack_policy arg = {
  147. .block_ack_tx_tid_policy = tx_tid_policy,
  148. .block_ack_rx_tid_policy = rx_tid_policy,
  149. };
  150. return wfx_hif_write_mib(wvif->wdev, wvif->id, HIF_MIB_ID_BLOCK_ACK_POLICY,
  151. &arg, sizeof(arg));
  152. }
  153. int wfx_hif_set_association_mode(struct wfx_vif *wvif, int ampdu_density,
  154. bool greenfield, bool short_preamble)
  155. {
  156. struct wfx_hif_mib_set_association_mode arg = {
  157. .preambtype_use = 1,
  158. .mode = 1,
  159. .spacing = 1,
  160. .short_preamble = short_preamble,
  161. .greenfield = greenfield,
  162. .mpdu_start_spacing = ampdu_density,
  163. };
  164. return wfx_hif_write_mib(wvif->wdev, wvif->id, HIF_MIB_ID_SET_ASSOCIATION_MODE,
  165. &arg, sizeof(arg));
  166. }
  167. int wfx_hif_set_tx_rate_retry_policy(struct wfx_vif *wvif, int policy_index, u8 *rates)
  168. {
  169. struct wfx_hif_mib_set_tx_rate_retry_policy *arg;
  170. size_t size = struct_size(arg, tx_rate_retry_policy, 1);
  171. int ret;
  172. arg = kzalloc(size, GFP_KERNEL);
  173. if (!arg)
  174. return -ENOMEM;
  175. arg->num_tx_rate_policies = 1;
  176. arg->tx_rate_retry_policy[0].policy_index = policy_index;
  177. arg->tx_rate_retry_policy[0].short_retry_count = 255;
  178. arg->tx_rate_retry_policy[0].long_retry_count = 255;
  179. arg->tx_rate_retry_policy[0].first_rate_sel = 1;
  180. arg->tx_rate_retry_policy[0].terminate = 1;
  181. arg->tx_rate_retry_policy[0].count_init = 1;
  182. memcpy(&arg->tx_rate_retry_policy[0].rates, rates,
  183. sizeof(arg->tx_rate_retry_policy[0].rates));
  184. ret = wfx_hif_write_mib(wvif->wdev, wvif->id, HIF_MIB_ID_SET_TX_RATE_RETRY_POLICY,
  185. arg, size);
  186. kfree(arg);
  187. return ret;
  188. }
  189. int wfx_hif_keep_alive_period(struct wfx_vif *wvif, int period)
  190. {
  191. struct wfx_hif_mib_keep_alive_period arg = {
  192. .keep_alive_period = cpu_to_le16(period),
  193. };
  194. return wfx_hif_write_mib(wvif->wdev, wvif->id, HIF_MIB_ID_KEEP_ALIVE_PERIOD,
  195. &arg, sizeof(arg));
  196. };
  197. int wfx_hif_set_arp_ipv4_filter(struct wfx_vif *wvif, int idx, __be32 *addr)
  198. {
  199. struct wfx_hif_mib_arp_ip_addr_table arg = {
  200. .condition_idx = idx,
  201. .arp_enable = HIF_ARP_NS_FILTERING_DISABLE,
  202. };
  203. if (addr) {
  204. /* Caution: type of addr is __be32 */
  205. memcpy(arg.ipv4_address, addr, sizeof(arg.ipv4_address));
  206. arg.arp_enable = HIF_ARP_NS_FILTERING_ENABLE;
  207. }
  208. return wfx_hif_write_mib(wvif->wdev, wvif->id, HIF_MIB_ID_ARP_IP_ADDRESSES_TABLE,
  209. &arg, sizeof(arg));
  210. }
  211. int wfx_hif_use_multi_tx_conf(struct wfx_dev *wdev, bool enable)
  212. {
  213. struct wfx_hif_mib_gl_set_multi_msg arg = {
  214. .enable_multi_tx_conf = enable,
  215. };
  216. return wfx_hif_write_mib(wdev, -1, HIF_MIB_ID_GL_SET_MULTI_MSG, &arg, sizeof(arg));
  217. }
  218. int wfx_hif_set_uapsd_info(struct wfx_vif *wvif, unsigned long val)
  219. {
  220. struct wfx_hif_mib_set_uapsd_information arg = { };
  221. if (val & BIT(IEEE80211_AC_VO))
  222. arg.trig_voice = 1;
  223. if (val & BIT(IEEE80211_AC_VI))
  224. arg.trig_video = 1;
  225. if (val & BIT(IEEE80211_AC_BE))
  226. arg.trig_be = 1;
  227. if (val & BIT(IEEE80211_AC_BK))
  228. arg.trig_bckgrnd = 1;
  229. return wfx_hif_write_mib(wvif->wdev, wvif->id, HIF_MIB_ID_SET_UAPSD_INFORMATION,
  230. &arg, sizeof(arg));
  231. }
  232. int wfx_hif_erp_use_protection(struct wfx_vif *wvif, bool enable)
  233. {
  234. struct wfx_hif_mib_non_erp_protection arg = {
  235. .use_cts_to_self = enable,
  236. };
  237. return wfx_hif_write_mib(wvif->wdev, wvif->id, HIF_MIB_ID_NON_ERP_PROTECTION,
  238. &arg, sizeof(arg));
  239. }
  240. int wfx_hif_slot_time(struct wfx_vif *wvif, int val)
  241. {
  242. struct wfx_hif_mib_slot_time arg = {
  243. .slot_time = cpu_to_le32(val),
  244. };
  245. return wfx_hif_write_mib(wvif->wdev, wvif->id, HIF_MIB_ID_SLOT_TIME, &arg, sizeof(arg));
  246. }
  247. int wfx_hif_wep_default_key_id(struct wfx_vif *wvif, int val)
  248. {
  249. struct wfx_hif_mib_wep_default_key_id arg = {
  250. .wep_default_key_id = val,
  251. };
  252. return wfx_hif_write_mib(wvif->wdev, wvif->id, HIF_MIB_ID_DOT11_WEP_DEFAULT_KEY_ID,
  253. &arg, sizeof(arg));
  254. }
  255. int wfx_hif_rts_threshold(struct wfx_vif *wvif, int val)
  256. {
  257. struct wfx_hif_mib_dot11_rts_threshold arg = {
  258. .threshold = cpu_to_le32(val >= 0 ? val : 0xFFFF),
  259. };
  260. return wfx_hif_write_mib(wvif->wdev, wvif->id, HIF_MIB_ID_DOT11_RTS_THRESHOLD,
  261. &arg, sizeof(arg));
  262. }