]> asedeno.scripts.mit.edu Git - linux.git/blob - drivers/staging/wfx/hif_tx_mib.h
Merge tag 'platform-drivers-x86-v5.5-3' of git://git.infradead.org/linux-platform...
[linux.git] / drivers / staging / wfx / hif_tx_mib.h
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-2019, Silicon Laboratories, Inc.
6  * Copyright (c) 2010, ST-Ericsson
7  * Copyright (C) 2010, ST-Ericsson SA
8  */
9 #ifndef WFX_HIF_TX_MIB_H
10 #define WFX_HIF_TX_MIB_H
11
12 #include <linux/etherdevice.h>
13
14 #include "wfx.h"
15 #include "hif_tx.h"
16 #include "hif_api_mib.h"
17
18 static inline int hif_set_output_power(struct wfx_vif *wvif, int power_level)
19 {
20         __le32 val = cpu_to_le32(power_level);
21
22         return hif_write_mib(wvif->wdev, wvif->id,
23                              HIF_MIB_ID_CURRENT_TX_POWER_LEVEL,
24                              &val, sizeof(val));
25 }
26
27 static inline int hif_set_beacon_wakeup_period(struct wfx_vif *wvif,
28                                                unsigned int dtim_interval,
29                                                unsigned int listen_interval)
30 {
31         struct hif_mib_beacon_wake_up_period val = {
32                 .wakeup_period_min = dtim_interval,
33                 .receive_dtim = 0,
34                 .wakeup_period_max = cpu_to_le16(listen_interval),
35         };
36
37         if (dtim_interval > 0xFF || listen_interval > 0xFFFF)
38                 return -EINVAL;
39         return hif_write_mib(wvif->wdev, wvif->id,
40                              HIF_MIB_ID_BEACON_WAKEUP_PERIOD,
41                              &val, sizeof(val));
42 }
43
44 static inline int hif_set_rcpi_rssi_threshold(struct wfx_vif *wvif,
45                                               struct hif_mib_rcpi_rssi_threshold *arg)
46 {
47         return hif_write_mib(wvif->wdev, wvif->id,
48                              HIF_MIB_ID_RCPI_RSSI_THRESHOLD, arg, sizeof(*arg));
49 }
50
51 static inline int hif_get_counters_table(struct wfx_dev *wdev,
52                                          struct hif_mib_extended_count_table *arg)
53 {
54         if (wfx_api_older_than(wdev, 1, 3)) {
55                 // extended_count_table is wider than count_table
56                 memset(arg, 0xFF, sizeof(*arg));
57                 return hif_read_mib(wdev, 0, HIF_MIB_ID_COUNTERS_TABLE,
58                                     arg, sizeof(struct hif_mib_count_table));
59         } else {
60                 return hif_read_mib(wdev, 0,
61                                     HIF_MIB_ID_EXTENDED_COUNTERS_TABLE, arg,
62                                 sizeof(struct hif_mib_extended_count_table));
63         }
64 }
65
66 static inline int hif_set_macaddr(struct wfx_vif *wvif, u8 *mac)
67 {
68         struct hif_mib_mac_address msg = { };
69
70         if (mac)
71                 ether_addr_copy(msg.mac_addr, mac);
72         return hif_write_mib(wvif->wdev, wvif->id, HIF_MIB_ID_DOT11_MAC_ADDRESS,
73                              &msg, sizeof(msg));
74 }
75
76 static inline int hif_set_rx_filter(struct wfx_vif *wvif, bool filter_bssid,
77                                     bool fwd_probe_req)
78 {
79         struct hif_mib_rx_filter val = { };
80
81         if (filter_bssid)
82                 val.bssid_filter = 1;
83         if (fwd_probe_req)
84                 val.fwd_probe_req = 1;
85         return hif_write_mib(wvif->wdev, wvif->id, HIF_MIB_ID_RX_FILTER,
86                              &val, sizeof(val));
87 }
88
89 static inline int hif_set_beacon_filter_table(struct wfx_vif *wvif,
90                                               int tbl_len,
91                                               struct hif_ie_table_entry *tbl)
92 {
93         int ret;
94         struct hif_mib_bcn_filter_table *val;
95         int buf_len = struct_size(val, ie_table, tbl_len);
96
97         val = kzalloc(buf_len, GFP_KERNEL);
98         if (!val)
99                 return -ENOMEM;
100         val->num_of_info_elmts = cpu_to_le32(tbl_len);
101         memcpy(val->ie_table, tbl, tbl_len * sizeof(*tbl));
102         ret = hif_write_mib(wvif->wdev, wvif->id,
103                             HIF_MIB_ID_BEACON_FILTER_TABLE, val, buf_len);
104         kfree(val);
105         return ret;
106 }
107
108 static inline int hif_beacon_filter_control(struct wfx_vif *wvif,
109                                             int enable, int beacon_count)
110 {
111         struct hif_mib_bcn_filter_enable arg = {
112                 .enable = cpu_to_le32(enable),
113                 .bcn_count = cpu_to_le32(beacon_count),
114         };
115         return hif_write_mib(wvif->wdev, wvif->id,
116                              HIF_MIB_ID_BEACON_FILTER_ENABLE,
117                              &arg, sizeof(arg));
118 }
119
120 static inline int hif_set_operational_mode(struct wfx_dev *wdev,
121                                            enum hif_op_power_mode mode)
122 {
123         struct hif_mib_gl_operational_power_mode val = {
124                 .power_mode = mode,
125                 .wup_ind_activation = 1,
126         };
127
128         return hif_write_mib(wdev, -1, HIF_MIB_ID_GL_OPERATIONAL_POWER_MODE,
129                              &val, sizeof(val));
130 }
131
132 static inline int hif_set_template_frame(struct wfx_vif *wvif,
133                                          struct hif_mib_template_frame *arg)
134 {
135         return hif_write_mib(wvif->wdev, wvif->id, HIF_MIB_ID_TEMPLATE_FRAME,
136                              arg, sizeof(*arg));
137 }
138
139 static inline int hif_set_mfp(struct wfx_vif *wvif, bool capable, bool required)
140 {
141         struct hif_mib_protected_mgmt_policy val = { };
142
143         WARN(required && !capable, "incoherent arguments");
144         if (capable) {
145                 val.pmf_enable = 1;
146                 val.host_enc_auth_frames = 1;
147         }
148         if (!required)
149                 val.unpmf_allowed = 1;
150         return hif_write_mib(wvif->wdev, wvif->id,
151                              HIF_MIB_ID_PROTECTED_MGMT_POLICY,
152                              &val, sizeof(val));
153 }
154
155 static inline int hif_set_block_ack_policy(struct wfx_vif *wvif,
156                                            u8 tx_tid_policy, u8 rx_tid_policy)
157 {
158         struct hif_mib_block_ack_policy val = {
159                 .block_ack_tx_tid_policy = tx_tid_policy,
160                 .block_ack_rx_tid_policy = rx_tid_policy,
161         };
162
163         return hif_write_mib(wvif->wdev, wvif->id, HIF_MIB_ID_BLOCK_ACK_POLICY,
164                              &val, sizeof(val));
165 }
166
167 static inline int hif_set_association_mode(struct wfx_vif *wvif,
168                                            struct hif_mib_set_association_mode *arg)
169 {
170         return hif_write_mib(wvif->wdev, wvif->id,
171                              HIF_MIB_ID_SET_ASSOCIATION_MODE, arg, sizeof(*arg));
172 }
173
174 static inline int hif_set_tx_rate_retry_policy(struct wfx_vif *wvif,
175                                                struct hif_mib_set_tx_rate_retry_policy *arg)
176 {
177         size_t size = struct_size(arg, tx_rate_retry_policy,
178                                   arg->num_tx_rate_policies);
179
180         return hif_write_mib(wvif->wdev, wvif->id,
181                              HIF_MIB_ID_SET_TX_RATE_RETRY_POLICY, arg, size);
182 }
183
184 static inline int hif_set_mac_addr_condition(struct wfx_vif *wvif,
185                                              struct hif_mib_mac_addr_data_frame_condition *arg)
186 {
187         return hif_write_mib(wvif->wdev, wvif->id,
188                              HIF_MIB_ID_MAC_ADDR_DATAFRAME_CONDITION,
189                              arg, sizeof(*arg));
190 }
191
192 static inline int hif_set_uc_mc_bc_condition(struct wfx_vif *wvif,
193                                              struct hif_mib_uc_mc_bc_data_frame_condition *arg)
194 {
195         return hif_write_mib(wvif->wdev, wvif->id,
196                              HIF_MIB_ID_UC_MC_BC_DATAFRAME_CONDITION,
197                              arg, sizeof(*arg));
198 }
199
200 static inline int hif_set_config_data_filter(struct wfx_vif *wvif,
201                                              struct hif_mib_config_data_filter *arg)
202 {
203         return hif_write_mib(wvif->wdev, wvif->id,
204                              HIF_MIB_ID_CONFIG_DATA_FILTER, arg, sizeof(*arg));
205 }
206
207 static inline int hif_set_data_filtering(struct wfx_vif *wvif,
208                                          struct hif_mib_set_data_filtering *arg)
209 {
210         return hif_write_mib(wvif->wdev, wvif->id,
211                              HIF_MIB_ID_SET_DATA_FILTERING, arg, sizeof(*arg));
212 }
213
214 static inline int hif_keep_alive_period(struct wfx_vif *wvif, int period)
215 {
216         struct hif_mib_keep_alive_period arg = {
217                 .keep_alive_period = cpu_to_le16(period),
218         };
219
220         return hif_write_mib(wvif->wdev, wvif->id, HIF_MIB_ID_KEEP_ALIVE_PERIOD,
221                              &arg, sizeof(arg));
222 };
223
224 static inline int hif_set_arp_ipv4_filter(struct wfx_vif *wvif,
225                                           struct hif_mib_arp_ip_addr_table *fp)
226 {
227         return hif_write_mib(wvif->wdev, wvif->id,
228                              HIF_MIB_ID_ARP_IP_ADDRESSES_TABLE,
229                              fp, sizeof(*fp));
230 }
231
232 static inline int hif_use_multi_tx_conf(struct wfx_dev *wdev,
233                                         bool enabled)
234 {
235         __le32 arg = enabled ? cpu_to_le32(1) : 0;
236
237         return hif_write_mib(wdev, -1, HIF_MIB_ID_GL_SET_MULTI_MSG,
238                              &arg, sizeof(arg));
239 }
240
241 static inline int hif_set_uapsd_info(struct wfx_vif *wvif,
242                                      struct hif_mib_set_uapsd_information *arg)
243 {
244         return hif_write_mib(wvif->wdev, wvif->id,
245                              HIF_MIB_ID_SET_UAPSD_INFORMATION,
246                              arg, sizeof(*arg));
247 }
248
249 static inline int hif_erp_use_protection(struct wfx_vif *wvif, bool enable)
250 {
251         __le32 arg = enable ? cpu_to_le32(1) : 0;
252
253         return hif_write_mib(wvif->wdev, wvif->id,
254                              HIF_MIB_ID_NON_ERP_PROTECTION, &arg, sizeof(arg));
255 }
256
257 static inline int hif_slot_time(struct wfx_vif *wvif, int val)
258 {
259         __le32 arg = cpu_to_le32(val);
260
261         return hif_write_mib(wvif->wdev, wvif->id, HIF_MIB_ID_SLOT_TIME,
262                              &arg, sizeof(arg));
263 }
264
265 static inline int hif_dual_cts_protection(struct wfx_vif *wvif, bool val)
266 {
267         struct hif_mib_set_ht_protection arg = {
268                 .dual_cts_prot = val,
269         };
270
271         return hif_write_mib(wvif->wdev, wvif->id, HIF_MIB_ID_SET_HT_PROTECTION,
272                              &arg, sizeof(arg));
273 }
274
275 static inline int hif_wep_default_key_id(struct wfx_vif *wvif, int val)
276 {
277         __le32 arg = cpu_to_le32(val);
278
279         return hif_write_mib(wvif->wdev, wvif->id,
280                              HIF_MIB_ID_DOT11_WEP_DEFAULT_KEY_ID,
281                              &arg, sizeof(arg));
282 }
283
284 static inline int hif_rts_threshold(struct wfx_vif *wvif, int val)
285 {
286         __le32 arg = cpu_to_le32(val > 0 ? val : 0xFFFF);
287
288         return hif_write_mib(wvif->wdev, wvif->id,
289                              HIF_MIB_ID_DOT11_RTS_THRESHOLD, &arg, sizeof(arg));
290 }
291
292 #endif