hif_tx_mib.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Implementation of host-to-chip MIBs of WFxxx Split Mac (WSM) 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 hif_set_output_power(struct wfx_vif *wvif, int val)
  15. {
  16. struct hif_mib_current_tx_power_level arg = {
  17. .power_level = cpu_to_le32(val * 10),
  18. };
  19. return hif_write_mib(wvif->wdev, wvif->id,
  20. HIF_MIB_ID_CURRENT_TX_POWER_LEVEL,
  21. &arg, sizeof(arg));
  22. }
  23. int hif_set_beacon_wakeup_period(struct wfx_vif *wvif,
  24. unsigned int dtim_interval,
  25. unsigned int listen_interval)
  26. {
  27. struct hif_mib_beacon_wake_up_period arg = {
  28. .wakeup_period_min = dtim_interval,
  29. .receive_dtim = 0,
  30. .wakeup_period_max = listen_interval,
  31. };
  32. if (dtim_interval > 0xFF || listen_interval > 0xFFFF)
  33. return -EINVAL;
  34. return hif_write_mib(wvif->wdev, wvif->id,
  35. HIF_MIB_ID_BEACON_WAKEUP_PERIOD,
  36. &arg, sizeof(arg));
  37. }
  38. int hif_set_rcpi_rssi_threshold(struct wfx_vif *wvif,
  39. int rssi_thold, int rssi_hyst)
  40. {
  41. struct hif_mib_rcpi_rssi_threshold arg = {
  42. .rolling_average_count = 8,
  43. .detection = 1,
  44. };
  45. if (!rssi_thold && !rssi_hyst) {
  46. arg.upperthresh = 1;
  47. arg.lowerthresh = 1;
  48. } else {
  49. arg.upper_threshold = rssi_thold + rssi_hyst;
  50. arg.upper_threshold = (arg.upper_threshold + 110) * 2;
  51. arg.lower_threshold = rssi_thold;
  52. arg.lower_threshold = (arg.lower_threshold + 110) * 2;
  53. }
  54. return hif_write_mib(wvif->wdev, wvif->id,
  55. HIF_MIB_ID_RCPI_RSSI_THRESHOLD, &arg, sizeof(arg));
  56. }
  57. int hif_get_counters_table(struct wfx_dev *wdev, int vif_id,
  58. struct hif_mib_extended_count_table *arg)
  59. {
  60. if (wfx_api_older_than(wdev, 1, 3)) {
  61. // extended_count_table is wider than count_table
  62. memset(arg, 0xFF, sizeof(*arg));
  63. return hif_read_mib(wdev, vif_id, HIF_MIB_ID_COUNTERS_TABLE,
  64. arg, sizeof(struct hif_mib_count_table));
  65. } else {
  66. return hif_read_mib(wdev, vif_id,
  67. HIF_MIB_ID_EXTENDED_COUNTERS_TABLE, arg,
  68. sizeof(struct hif_mib_extended_count_table));
  69. }
  70. }
  71. int hif_set_macaddr(struct wfx_vif *wvif, u8 *mac)
  72. {
  73. struct hif_mib_mac_address msg = { };
  74. if (mac)
  75. ether_addr_copy(msg.mac_addr, mac);
  76. return hif_write_mib(wvif->wdev, wvif->id, HIF_MIB_ID_DOT11_MAC_ADDRESS,
  77. &msg, sizeof(msg));
  78. }
  79. int hif_set_rx_filter(struct wfx_vif *wvif,
  80. bool filter_bssid, bool filter_prbreq)
  81. {
  82. struct hif_mib_rx_filter arg = { };
  83. if (filter_bssid)
  84. arg.bssid_filter = 1;
  85. if (!filter_prbreq)
  86. arg.fwd_probe_req = 1;
  87. return hif_write_mib(wvif->wdev, wvif->id, HIF_MIB_ID_RX_FILTER,
  88. &arg, sizeof(arg));
  89. }
  90. int hif_set_beacon_filter_table(struct wfx_vif *wvif, int tbl_len,
  91. const struct hif_ie_table_entry *tbl)
  92. {
  93. int ret;
  94. struct hif_mib_bcn_filter_table *arg;
  95. int buf_len = struct_size(arg, ie_table, tbl_len);
  96. arg = kzalloc(buf_len, GFP_KERNEL);
  97. if (!arg)
  98. return -ENOMEM;
  99. arg->num_of_info_elmts = cpu_to_le32(tbl_len);
  100. memcpy(arg->ie_table, tbl, flex_array_size(arg, ie_table, tbl_len));
  101. ret = hif_write_mib(wvif->wdev, wvif->id,
  102. HIF_MIB_ID_BEACON_FILTER_TABLE, arg, buf_len);
  103. kfree(arg);
  104. return ret;
  105. }
  106. int hif_beacon_filter_control(struct wfx_vif *wvif,
  107. int enable, int beacon_count)
  108. {
  109. struct hif_mib_bcn_filter_enable arg = {
  110. .enable = cpu_to_le32(enable),
  111. .bcn_count = cpu_to_le32(beacon_count),
  112. };
  113. return hif_write_mib(wvif->wdev, wvif->id,
  114. HIF_MIB_ID_BEACON_FILTER_ENABLE,
  115. &arg, sizeof(arg));
  116. }
  117. int hif_set_operational_mode(struct wfx_dev *wdev, enum hif_op_power_mode mode)
  118. {
  119. struct hif_mib_gl_operational_power_mode arg = {
  120. .power_mode = mode,
  121. .wup_ind_activation = 1,
  122. };
  123. return hif_write_mib(wdev, -1, HIF_MIB_ID_GL_OPERATIONAL_POWER_MODE,
  124. &arg, sizeof(arg));
  125. }
  126. int hif_set_template_frame(struct wfx_vif *wvif, struct sk_buff *skb,
  127. u8 frame_type, int init_rate)
  128. {
  129. struct hif_mib_template_frame *arg;
  130. WARN(skb->len > HIF_API_MAX_TEMPLATE_FRAME_SIZE, "frame is too big");
  131. skb_push(skb, 4);
  132. arg = (struct hif_mib_template_frame *)skb->data;
  133. skb_pull(skb, 4);
  134. arg->init_rate = init_rate;
  135. arg->frame_type = frame_type;
  136. arg->frame_length = cpu_to_le16(skb->len);
  137. return hif_write_mib(wvif->wdev, wvif->id, HIF_MIB_ID_TEMPLATE_FRAME,
  138. arg, sizeof(*arg) + skb->len);
  139. }
  140. int hif_set_mfp(struct wfx_vif *wvif, bool capable, bool required)
  141. {
  142. struct hif_mib_protected_mgmt_policy arg = { };
  143. WARN(required && !capable, "incoherent arguments");
  144. if (capable) {
  145. arg.pmf_enable = 1;
  146. arg.host_enc_auth_frames = 1;
  147. }
  148. if (!required)
  149. arg.unpmf_allowed = 1;
  150. return hif_write_mib(wvif->wdev, wvif->id,
  151. HIF_MIB_ID_PROTECTED_MGMT_POLICY,
  152. &arg, sizeof(arg));
  153. }
  154. int hif_set_block_ack_policy(struct wfx_vif *wvif,
  155. u8 tx_tid_policy, u8 rx_tid_policy)
  156. {
  157. struct hif_mib_block_ack_policy arg = {
  158. .block_ack_tx_tid_policy = tx_tid_policy,
  159. .block_ack_rx_tid_policy = rx_tid_policy,
  160. };
  161. return hif_write_mib(wvif->wdev, wvif->id, HIF_MIB_ID_BLOCK_ACK_POLICY,
  162. &arg, sizeof(arg));
  163. }
  164. int hif_set_association_mode(struct wfx_vif *wvif, int ampdu_density,
  165. bool greenfield, bool short_preamble)
  166. {
  167. struct hif_mib_set_association_mode arg = {
  168. .preambtype_use = 1,
  169. .mode = 1,
  170. .spacing = 1,
  171. .short_preamble = short_preamble,
  172. .greenfield = greenfield,
  173. .mpdu_start_spacing = ampdu_density,
  174. };
  175. return hif_write_mib(wvif->wdev, wvif->id,
  176. HIF_MIB_ID_SET_ASSOCIATION_MODE, &arg, sizeof(arg));
  177. }
  178. int hif_set_tx_rate_retry_policy(struct wfx_vif *wvif,
  179. int policy_index, u8 *rates)
  180. {
  181. struct hif_mib_set_tx_rate_retry_policy *arg;
  182. size_t size = struct_size(arg, tx_rate_retry_policy, 1);
  183. int ret;
  184. arg = kzalloc(size, GFP_KERNEL);
  185. if (!arg)
  186. return -ENOMEM;
  187. arg->num_tx_rate_policies = 1;
  188. arg->tx_rate_retry_policy[0].policy_index = policy_index;
  189. arg->tx_rate_retry_policy[0].short_retry_count = 255;
  190. arg->tx_rate_retry_policy[0].long_retry_count = 255;
  191. arg->tx_rate_retry_policy[0].first_rate_sel = 1;
  192. arg->tx_rate_retry_policy[0].terminate = 1;
  193. arg->tx_rate_retry_policy[0].count_init = 1;
  194. memcpy(&arg->tx_rate_retry_policy[0].rates, rates,
  195. sizeof(arg->tx_rate_retry_policy[0].rates));
  196. ret = hif_write_mib(wvif->wdev, wvif->id,
  197. HIF_MIB_ID_SET_TX_RATE_RETRY_POLICY, arg, size);
  198. kfree(arg);
  199. return ret;
  200. }
  201. int hif_keep_alive_period(struct wfx_vif *wvif, int period)
  202. {
  203. struct hif_mib_keep_alive_period arg = {
  204. .keep_alive_period = cpu_to_le16(period),
  205. };
  206. return hif_write_mib(wvif->wdev, wvif->id, HIF_MIB_ID_KEEP_ALIVE_PERIOD,
  207. &arg, sizeof(arg));
  208. };
  209. int hif_set_arp_ipv4_filter(struct wfx_vif *wvif, int idx, __be32 *addr)
  210. {
  211. struct hif_mib_arp_ip_addr_table arg = {
  212. .condition_idx = idx,
  213. .arp_enable = HIF_ARP_NS_FILTERING_DISABLE,
  214. };
  215. if (addr) {
  216. // Caution: type of addr is __be32
  217. memcpy(arg.ipv4_address, addr, sizeof(arg.ipv4_address));
  218. arg.arp_enable = HIF_ARP_NS_FILTERING_ENABLE;
  219. }
  220. return hif_write_mib(wvif->wdev, wvif->id,
  221. HIF_MIB_ID_ARP_IP_ADDRESSES_TABLE,
  222. &arg, sizeof(arg));
  223. }
  224. int hif_use_multi_tx_conf(struct wfx_dev *wdev, bool enable)
  225. {
  226. struct hif_mib_gl_set_multi_msg arg = {
  227. .enable_multi_tx_conf = enable,
  228. };
  229. return hif_write_mib(wdev, -1, HIF_MIB_ID_GL_SET_MULTI_MSG,
  230. &arg, sizeof(arg));
  231. }
  232. int hif_set_uapsd_info(struct wfx_vif *wvif, unsigned long val)
  233. {
  234. struct hif_mib_set_uapsd_information arg = { };
  235. if (val & BIT(IEEE80211_AC_VO))
  236. arg.trig_voice = 1;
  237. if (val & BIT(IEEE80211_AC_VI))
  238. arg.trig_video = 1;
  239. if (val & BIT(IEEE80211_AC_BE))
  240. arg.trig_be = 1;
  241. if (val & BIT(IEEE80211_AC_BK))
  242. arg.trig_bckgrnd = 1;
  243. return hif_write_mib(wvif->wdev, wvif->id,
  244. HIF_MIB_ID_SET_UAPSD_INFORMATION,
  245. &arg, sizeof(arg));
  246. }
  247. int hif_erp_use_protection(struct wfx_vif *wvif, bool enable)
  248. {
  249. struct hif_mib_non_erp_protection arg = {
  250. .use_cts_to_self = enable,
  251. };
  252. return hif_write_mib(wvif->wdev, wvif->id,
  253. HIF_MIB_ID_NON_ERP_PROTECTION, &arg, sizeof(arg));
  254. }
  255. int hif_slot_time(struct wfx_vif *wvif, int val)
  256. {
  257. struct hif_mib_slot_time arg = {
  258. .slot_time = cpu_to_le32(val),
  259. };
  260. return hif_write_mib(wvif->wdev, wvif->id, HIF_MIB_ID_SLOT_TIME,
  261. &arg, sizeof(arg));
  262. }
  263. int hif_wep_default_key_id(struct wfx_vif *wvif, int val)
  264. {
  265. struct hif_mib_wep_default_key_id arg = {
  266. .wep_default_key_id = val,
  267. };
  268. return hif_write_mib(wvif->wdev, wvif->id,
  269. HIF_MIB_ID_DOT11_WEP_DEFAULT_KEY_ID,
  270. &arg, sizeof(arg));
  271. }
  272. int hif_rts_threshold(struct wfx_vif *wvif, int val)
  273. {
  274. struct hif_mib_dot11_rts_threshold arg = {
  275. .threshold = cpu_to_le32(val >= 0 ? val : 0xFFFF),
  276. };
  277. return hif_write_mib(wvif->wdev, wvif->id,
  278. HIF_MIB_ID_DOT11_RTS_THRESHOLD, &arg, sizeof(arg));
  279. }