Merge tag 'usb-ci-v5.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/peter...
[linux-block.git] / drivers / staging / wfx / hif_tx.c
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Implementation of host-to-chip commands (aka request/confirmation) of WFxxx
4  * Split Mac (WSM) API.
5  *
6  * Copyright (c) 2017-2019, Silicon Laboratories, Inc.
7  * Copyright (c) 2010, ST-Ericsson
8  */
9 #include <linux/etherdevice.h>
10
11 #include "hif_tx.h"
12 #include "wfx.h"
13 #include "bh.h"
14 #include "hwio.h"
15 #include "debug.h"
16 #include "sta.h"
17
18 void wfx_init_hif_cmd(struct wfx_hif_cmd *hif_cmd)
19 {
20         init_completion(&hif_cmd->ready);
21         init_completion(&hif_cmd->done);
22         mutex_init(&hif_cmd->lock);
23         mutex_init(&hif_cmd->key_renew_lock);
24 }
25
26 static void wfx_fill_header(struct hif_msg *hif, int if_id,
27                             unsigned int cmd, size_t size)
28 {
29         if (if_id == -1)
30                 if_id = 2;
31
32         WARN(cmd > 0x3f, "invalid WSM command %#.2x", cmd);
33         WARN(size > 0xFFF, "requested buffer is too large: %zu bytes", size);
34         WARN(if_id > 0x3, "invalid interface ID %d", if_id);
35
36         hif->len = cpu_to_le16(size + 4);
37         hif->id = cmd;
38         hif->interface = if_id;
39 }
40
41 static void *wfx_alloc_hif(size_t body_len, struct hif_msg **hif)
42 {
43         *hif = kzalloc(sizeof(struct hif_msg) + body_len, GFP_KERNEL);
44         if (*hif)
45                 return (*hif)->body;
46         else
47                 return NULL;
48 }
49
50 int wfx_cmd_send(struct wfx_dev *wdev, struct hif_msg *request,
51                  void *reply, size_t reply_len, bool async)
52 {
53         const char *mib_name = "";
54         const char *mib_sep = "";
55         int cmd = request->id;
56         int vif = request->interface;
57         int ret;
58
59         WARN(wdev->hif_cmd.buf_recv && wdev->hif_cmd.async, "API usage error");
60
61         // Do not wait for any reply if chip is frozen
62         if (wdev->chip_frozen)
63                 return -ETIMEDOUT;
64
65         if (cmd != HIF_REQ_ID_SL_EXCHANGE_PUB_KEYS)
66                 mutex_lock(&wdev->hif_cmd.key_renew_lock);
67
68         mutex_lock(&wdev->hif_cmd.lock);
69         WARN(wdev->hif_cmd.buf_send, "data locking error");
70
71         // Note: call to complete() below has an implicit memory barrier that
72         // hopefully protect buf_send
73         wdev->hif_cmd.buf_send = request;
74         wdev->hif_cmd.buf_recv = reply;
75         wdev->hif_cmd.len_recv = reply_len;
76         wdev->hif_cmd.async = async;
77         complete(&wdev->hif_cmd.ready);
78
79         wfx_bh_request_tx(wdev);
80
81         // NOTE: no timeout is catched async is enabled
82         if (async)
83                 return 0;
84
85         if (wdev->poll_irq)
86                 wfx_bh_poll_irq(wdev);
87
88         ret = wait_for_completion_timeout(&wdev->hif_cmd.done, 1 * HZ);
89         if (!ret) {
90                 dev_err(wdev->dev, "chip is abnormally long to answer\n");
91                 reinit_completion(&wdev->hif_cmd.ready);
92                 ret = wait_for_completion_timeout(&wdev->hif_cmd.done, 3 * HZ);
93         }
94         if (!ret) {
95                 dev_err(wdev->dev, "chip did not answer\n");
96                 wfx_pending_dump_old_frames(wdev, 3000);
97                 wdev->chip_frozen = true;
98                 reinit_completion(&wdev->hif_cmd.done);
99                 ret = -ETIMEDOUT;
100         } else {
101                 ret = wdev->hif_cmd.ret;
102         }
103
104         wdev->hif_cmd.buf_send = NULL;
105         mutex_unlock(&wdev->hif_cmd.lock);
106
107         if (ret &&
108             (cmd == HIF_REQ_ID_READ_MIB || cmd == HIF_REQ_ID_WRITE_MIB)) {
109                 mib_name = get_mib_name(((u16 *)request)[2]);
110                 mib_sep = "/";
111         }
112         if (ret < 0)
113                 dev_err(wdev->dev,
114                         "WSM request %s%s%s (%#.2x) on vif %d returned error %d\n",
115                         get_hif_name(cmd), mib_sep, mib_name, cmd, vif, ret);
116         if (ret > 0)
117                 dev_warn(wdev->dev,
118                          "WSM request %s%s%s (%#.2x) on vif %d returned status %d\n",
119                          get_hif_name(cmd), mib_sep, mib_name, cmd, vif, ret);
120
121         if (cmd != HIF_REQ_ID_SL_EXCHANGE_PUB_KEYS)
122                 mutex_unlock(&wdev->hif_cmd.key_renew_lock);
123         return ret;
124 }
125
126 // This function is special. After HIF_REQ_ID_SHUT_DOWN, chip won't reply to any
127 // request anymore. We need to slightly hack struct wfx_hif_cmd for that job. Be
128 // carefull to only call this funcion during device unregister.
129 int hif_shutdown(struct wfx_dev *wdev)
130 {
131         int ret;
132         struct hif_msg *hif;
133
134         if (wdev->chip_frozen)
135                 return 0;
136         wfx_alloc_hif(0, &hif);
137         if (!hif)
138                 return -ENOMEM;
139         wfx_fill_header(hif, -1, HIF_REQ_ID_SHUT_DOWN, 0);
140         ret = wfx_cmd_send(wdev, hif, NULL, 0, true);
141         // After this command, chip won't reply. Be sure to give enough time to
142         // bh to send buffer:
143         msleep(100);
144         wdev->hif_cmd.buf_send = NULL;
145         if (wdev->pdata.gpio_wakeup)
146                 gpiod_set_value(wdev->pdata.gpio_wakeup, 0);
147         else
148                 control_reg_write(wdev, 0);
149         mutex_unlock(&wdev->hif_cmd.lock);
150         mutex_unlock(&wdev->hif_cmd.key_renew_lock);
151         kfree(hif);
152         return ret;
153 }
154
155 int hif_configuration(struct wfx_dev *wdev, const u8 *conf, size_t len)
156 {
157         int ret;
158         size_t buf_len = sizeof(struct hif_req_configuration) + len;
159         struct hif_msg *hif;
160         struct hif_req_configuration *body = wfx_alloc_hif(buf_len, &hif);
161
162         if (!hif)
163                 return -ENOMEM;
164         body->length = cpu_to_le16(len);
165         memcpy(body->pds_data, conf, len);
166         wfx_fill_header(hif, -1, HIF_REQ_ID_CONFIGURATION, buf_len);
167         ret = wfx_cmd_send(wdev, hif, NULL, 0, false);
168         kfree(hif);
169         return ret;
170 }
171
172 int hif_reset(struct wfx_vif *wvif, bool reset_stat)
173 {
174         int ret;
175         struct hif_msg *hif;
176         struct hif_req_reset *body = wfx_alloc_hif(sizeof(*body), &hif);
177
178         if (!hif)
179                 return -ENOMEM;
180         body->reset_flags.reset_stat = reset_stat;
181         wfx_fill_header(hif, wvif->id, HIF_REQ_ID_RESET, sizeof(*body));
182         ret = wfx_cmd_send(wvif->wdev, hif, NULL, 0, false);
183         kfree(hif);
184         return ret;
185 }
186
187 int hif_read_mib(struct wfx_dev *wdev, int vif_id, u16 mib_id,
188                  void *val, size_t val_len)
189 {
190         int ret;
191         struct hif_msg *hif;
192         int buf_len = sizeof(struct hif_cnf_read_mib) + val_len;
193         struct hif_req_read_mib *body = wfx_alloc_hif(sizeof(*body), &hif);
194         struct hif_cnf_read_mib *reply = kmalloc(buf_len, GFP_KERNEL);
195
196         if (!body || !reply) {
197                 ret = -ENOMEM;
198                 goto out;
199         }
200         body->mib_id = cpu_to_le16(mib_id);
201         wfx_fill_header(hif, vif_id, HIF_REQ_ID_READ_MIB, sizeof(*body));
202         ret = wfx_cmd_send(wdev, hif, reply, buf_len, false);
203
204         if (!ret && mib_id != le16_to_cpu(reply->mib_id)) {
205                 dev_warn(wdev->dev, "%s: confirmation mismatch request\n",
206                          __func__);
207                 ret = -EIO;
208         }
209         if (ret == -ENOMEM)
210                 dev_err(wdev->dev, "buffer is too small to receive %s (%zu < %d)\n",
211                         get_mib_name(mib_id), val_len,
212                         le16_to_cpu(reply->length));
213         if (!ret)
214                 memcpy(val, &reply->mib_data, le16_to_cpu(reply->length));
215         else
216                 memset(val, 0xFF, val_len);
217 out:
218         kfree(hif);
219         kfree(reply);
220         return ret;
221 }
222
223 int hif_write_mib(struct wfx_dev *wdev, int vif_id, u16 mib_id,
224                   void *val, size_t val_len)
225 {
226         int ret;
227         struct hif_msg *hif;
228         int buf_len = sizeof(struct hif_req_write_mib) + val_len;
229         struct hif_req_write_mib *body = wfx_alloc_hif(buf_len, &hif);
230
231         if (!hif)
232                 return -ENOMEM;
233         body->mib_id = cpu_to_le16(mib_id);
234         body->length = cpu_to_le16(val_len);
235         memcpy(&body->mib_data, val, val_len);
236         wfx_fill_header(hif, vif_id, HIF_REQ_ID_WRITE_MIB, buf_len);
237         ret = wfx_cmd_send(wdev, hif, NULL, 0, false);
238         kfree(hif);
239         return ret;
240 }
241
242 int hif_scan(struct wfx_vif *wvif, struct cfg80211_scan_request *req,
243              int chan_start_idx, int chan_num, int *timeout)
244 {
245         int ret, i;
246         struct hif_msg *hif;
247         size_t buf_len =
248                 sizeof(struct hif_req_start_scan_alt) + chan_num * sizeof(u8);
249         struct hif_req_start_scan_alt *body = wfx_alloc_hif(buf_len, &hif);
250         int tmo_chan_fg, tmo_chan_bg, tmo;
251
252         WARN(chan_num > HIF_API_MAX_NB_CHANNELS, "invalid params");
253         WARN(req->n_ssids > HIF_API_MAX_NB_SSIDS, "invalid params");
254
255         compiletime_assert(IEEE80211_MAX_SSID_LEN == HIF_API_SSID_SIZE,
256                            "API inconsistency");
257         if (!hif)
258                 return -ENOMEM;
259         for (i = 0; i < req->n_ssids; i++) {
260                 memcpy(body->ssid_def[i].ssid, req->ssids[i].ssid,
261                        IEEE80211_MAX_SSID_LEN);
262                 body->ssid_def[i].ssid_length =
263                         cpu_to_le32(req->ssids[i].ssid_len);
264         }
265         body->num_of_ssids = HIF_API_MAX_NB_SSIDS;
266         // Background scan is always a good idea
267         body->scan_type.type = 1;
268         body->scan_flags.fbg = 1;
269         body->tx_power_level =
270                 cpu_to_le32(req->channels[chan_start_idx]->max_power);
271         body->num_of_channels = chan_num;
272         for (i = 0; i < chan_num; i++)
273                 body->channel_list[i] =
274                         req->channels[i + chan_start_idx]->hw_value;
275         if (req->no_cck)
276                 body->max_transmit_rate = API_RATE_INDEX_G_6MBPS;
277         else
278                 body->max_transmit_rate = API_RATE_INDEX_B_1MBPS;
279         if (req->channels[chan_start_idx]->flags & IEEE80211_CHAN_NO_IR) {
280                 body->min_channel_time = cpu_to_le32(50);
281                 body->max_channel_time = cpu_to_le32(150);
282         } else {
283                 body->min_channel_time = cpu_to_le32(10);
284                 body->max_channel_time = cpu_to_le32(50);
285                 body->num_of_probe_requests = 2;
286                 body->probe_delay = 100;
287         }
288         tmo_chan_bg = le32_to_cpu(body->max_channel_time) * USEC_PER_TU;
289         tmo_chan_fg = 512 * USEC_PER_TU + body->probe_delay;
290         tmo_chan_fg *= body->num_of_probe_requests;
291         tmo = chan_num * max(tmo_chan_bg, tmo_chan_fg) + 512 * USEC_PER_TU;
292         if (timeout)
293                 *timeout = usecs_to_jiffies(tmo);
294
295         wfx_fill_header(hif, wvif->id, HIF_REQ_ID_START_SCAN, buf_len);
296         ret = wfx_cmd_send(wvif->wdev, hif, NULL, 0, false);
297         kfree(hif);
298         return ret;
299 }
300
301 int hif_stop_scan(struct wfx_vif *wvif)
302 {
303         int ret;
304         struct hif_msg *hif;
305         // body associated to HIF_REQ_ID_STOP_SCAN is empty
306         wfx_alloc_hif(0, &hif);
307
308         if (!hif)
309                 return -ENOMEM;
310         wfx_fill_header(hif, wvif->id, HIF_REQ_ID_STOP_SCAN, 0);
311         ret = wfx_cmd_send(wvif->wdev, hif, NULL, 0, false);
312         kfree(hif);
313         return ret;
314 }
315
316 int hif_join(struct wfx_vif *wvif, const struct ieee80211_bss_conf *conf,
317              struct ieee80211_channel *channel, const u8 *ssid, int ssidlen)
318 {
319         int ret;
320         struct hif_msg *hif;
321         struct hif_req_join *body = wfx_alloc_hif(sizeof(*body), &hif);
322
323         WARN_ON(!conf->beacon_int);
324         WARN_ON(!conf->basic_rates);
325         WARN_ON(sizeof(body->ssid) < ssidlen);
326         WARN(!conf->ibss_joined && !ssidlen, "joining an unknown BSS");
327         if (!hif)
328                 return -ENOMEM;
329         body->infrastructure_bss_mode = !conf->ibss_joined;
330         body->short_preamble = conf->use_short_preamble;
331         if (channel && channel->flags & IEEE80211_CHAN_NO_IR)
332                 body->probe_for_join = 0;
333         else
334                 body->probe_for_join = 1;
335         body->channel_number = channel->hw_value;
336         body->beacon_interval = cpu_to_le32(conf->beacon_int);
337         body->basic_rate_set =
338                 cpu_to_le32(wfx_rate_mask_to_hw(wvif->wdev, conf->basic_rates));
339         memcpy(body->bssid, conf->bssid, sizeof(body->bssid));
340         if (ssid) {
341                 body->ssid_length = cpu_to_le32(ssidlen);
342                 memcpy(body->ssid, ssid, ssidlen);
343         }
344         wfx_fill_header(hif, wvif->id, HIF_REQ_ID_JOIN, sizeof(*body));
345         ret = wfx_cmd_send(wvif->wdev, hif, NULL, 0, false);
346         kfree(hif);
347         return ret;
348 }
349
350 int hif_set_bss_params(struct wfx_vif *wvif, int aid, int beacon_lost_count)
351 {
352         int ret;
353         struct hif_msg *hif;
354         struct hif_req_set_bss_params *body =
355                 wfx_alloc_hif(sizeof(*body), &hif);
356
357         if (!hif)
358                 return -ENOMEM;
359         body->aid = cpu_to_le16(aid);
360         body->beacon_lost_count = beacon_lost_count;
361         wfx_fill_header(hif, wvif->id, HIF_REQ_ID_SET_BSS_PARAMS,
362                         sizeof(*body));
363         ret = wfx_cmd_send(wvif->wdev, hif, NULL, 0, false);
364         kfree(hif);
365         return ret;
366 }
367
368 int hif_add_key(struct wfx_dev *wdev, const struct hif_req_add_key *arg)
369 {
370         int ret;
371         struct hif_msg *hif;
372         // FIXME: only send necessary bits
373         struct hif_req_add_key *body = wfx_alloc_hif(sizeof(*body), &hif);
374
375         if (!hif)
376                 return -ENOMEM;
377         // FIXME: swap bytes as necessary in body
378         memcpy(body, arg, sizeof(*body));
379         if (wfx_api_older_than(wdev, 1, 5))
380                 // Legacy firmwares expect that add_key to be sent on right
381                 // interface.
382                 wfx_fill_header(hif, arg->int_id, HIF_REQ_ID_ADD_KEY,
383                                 sizeof(*body));
384         else
385                 wfx_fill_header(hif, -1, HIF_REQ_ID_ADD_KEY, sizeof(*body));
386         ret = wfx_cmd_send(wdev, hif, NULL, 0, false);
387         kfree(hif);
388         return ret;
389 }
390
391 int hif_remove_key(struct wfx_dev *wdev, int idx)
392 {
393         int ret;
394         struct hif_msg *hif;
395         struct hif_req_remove_key *body = wfx_alloc_hif(sizeof(*body), &hif);
396
397         if (!hif)
398                 return -ENOMEM;
399         body->entry_index = idx;
400         wfx_fill_header(hif, -1, HIF_REQ_ID_REMOVE_KEY, sizeof(*body));
401         ret = wfx_cmd_send(wdev, hif, NULL, 0, false);
402         kfree(hif);
403         return ret;
404 }
405
406 int hif_set_edca_queue_params(struct wfx_vif *wvif, u16 queue,
407                               const struct ieee80211_tx_queue_params *arg)
408 {
409         int ret;
410         struct hif_msg *hif;
411         struct hif_req_edca_queue_params *body = wfx_alloc_hif(sizeof(*body),
412                                                                &hif);
413
414         if (!body)
415                 return -ENOMEM;
416
417         WARN_ON(arg->aifs > 255);
418         if (!hif)
419                 return -ENOMEM;
420         body->aifsn = arg->aifs;
421         body->cw_min = cpu_to_le16(arg->cw_min);
422         body->cw_max = cpu_to_le16(arg->cw_max);
423         body->tx_op_limit = cpu_to_le16(arg->txop * USEC_PER_TXOP);
424         body->queue_id = 3 - queue;
425         // API 2.0 has changed queue IDs values
426         if (wfx_api_older_than(wvif->wdev, 2, 0) && queue == IEEE80211_AC_BE)
427                 body->queue_id = HIF_QUEUE_ID_BACKGROUND;
428         if (wfx_api_older_than(wvif->wdev, 2, 0) && queue == IEEE80211_AC_BK)
429                 body->queue_id = HIF_QUEUE_ID_BESTEFFORT;
430         wfx_fill_header(hif, wvif->id, HIF_REQ_ID_EDCA_QUEUE_PARAMS,
431                         sizeof(*body));
432         ret = wfx_cmd_send(wvif->wdev, hif, NULL, 0, false);
433         kfree(hif);
434         return ret;
435 }
436
437 int hif_set_pm(struct wfx_vif *wvif, bool ps, int dynamic_ps_timeout)
438 {
439         int ret;
440         struct hif_msg *hif;
441         struct hif_req_set_pm_mode *body = wfx_alloc_hif(sizeof(*body), &hif);
442
443         if (!body)
444                 return -ENOMEM;
445
446         if (!hif)
447                 return -ENOMEM;
448         if (ps) {
449                 body->pm_mode.enter_psm = 1;
450                 // Firmware does not support more than 128ms
451                 body->fast_psm_idle_period = min(dynamic_ps_timeout * 2, 255);
452                 if (body->fast_psm_idle_period)
453                         body->pm_mode.fast_psm = 1;
454         }
455         wfx_fill_header(hif, wvif->id, HIF_REQ_ID_SET_PM_MODE, sizeof(*body));
456         ret = wfx_cmd_send(wvif->wdev, hif, NULL, 0, false);
457         kfree(hif);
458         return ret;
459 }
460
461 int hif_start(struct wfx_vif *wvif, const struct ieee80211_bss_conf *conf,
462               const struct ieee80211_channel *channel)
463 {
464         int ret;
465         struct hif_msg *hif;
466         struct hif_req_start *body = wfx_alloc_hif(sizeof(*body), &hif);
467
468         WARN_ON(!conf->beacon_int);
469         if (!hif)
470                 return -ENOMEM;
471         body->dtim_period = conf->dtim_period;
472         body->short_preamble = conf->use_short_preamble;
473         body->channel_number = channel->hw_value;
474         body->beacon_interval = cpu_to_le32(conf->beacon_int);
475         body->basic_rate_set =
476                 cpu_to_le32(wfx_rate_mask_to_hw(wvif->wdev, conf->basic_rates));
477         body->ssid_length = conf->ssid_len;
478         memcpy(body->ssid, conf->ssid, conf->ssid_len);
479         wfx_fill_header(hif, wvif->id, HIF_REQ_ID_START, sizeof(*body));
480         ret = wfx_cmd_send(wvif->wdev, hif, NULL, 0, false);
481         kfree(hif);
482         return ret;
483 }
484
485 int hif_beacon_transmit(struct wfx_vif *wvif, bool enable)
486 {
487         int ret;
488         struct hif_msg *hif;
489         struct hif_req_beacon_transmit *body = wfx_alloc_hif(sizeof(*body),
490                                                              &hif);
491
492         if (!hif)
493                 return -ENOMEM;
494         body->enable_beaconing = enable ? 1 : 0;
495         wfx_fill_header(hif, wvif->id, HIF_REQ_ID_BEACON_TRANSMIT,
496                         sizeof(*body));
497         ret = wfx_cmd_send(wvif->wdev, hif, NULL, 0, false);
498         kfree(hif);
499         return ret;
500 }
501
502 int hif_map_link(struct wfx_vif *wvif, u8 *mac_addr, int flags, int sta_id)
503 {
504         int ret;
505         struct hif_msg *hif;
506         struct hif_req_map_link *body = wfx_alloc_hif(sizeof(*body), &hif);
507
508         if (!hif)
509                 return -ENOMEM;
510         if (mac_addr)
511                 ether_addr_copy(body->mac_addr, mac_addr);
512         body->map_link_flags = *(struct hif_map_link_flags *)&flags;
513         body->peer_sta_id = sta_id;
514         wfx_fill_header(hif, wvif->id, HIF_REQ_ID_MAP_LINK, sizeof(*body));
515         ret = wfx_cmd_send(wvif->wdev, hif, NULL, 0, false);
516         kfree(hif);
517         return ret;
518 }
519
520 int hif_update_ie_beacon(struct wfx_vif *wvif, const u8 *ies, size_t ies_len)
521 {
522         int ret;
523         struct hif_msg *hif;
524         int buf_len = sizeof(struct hif_req_update_ie) + ies_len;
525         struct hif_req_update_ie *body = wfx_alloc_hif(buf_len, &hif);
526
527         if (!hif)
528                 return -ENOMEM;
529         body->ie_flags.beacon = 1;
530         body->num_ies = cpu_to_le16(1);
531         memcpy(body->ie, ies, ies_len);
532         wfx_fill_header(hif, wvif->id, HIF_REQ_ID_UPDATE_IE, buf_len);
533         ret = wfx_cmd_send(wvif->wdev, hif, NULL, 0, false);
534         kfree(hif);
535         return ret;
536 }
537
538 int hif_sl_send_pub_keys(struct wfx_dev *wdev,
539                          const u8 *pubkey, const u8 *pubkey_hmac)
540 {
541         int ret;
542         struct hif_msg *hif;
543         struct hif_req_sl_exchange_pub_keys *body = wfx_alloc_hif(sizeof(*body),
544                                                                   &hif);
545
546         if (!hif)
547                 return -ENOMEM;
548         body->algorithm = HIF_SL_CURVE25519;
549         memcpy(body->host_pub_key, pubkey, sizeof(body->host_pub_key));
550         memcpy(body->host_pub_key_mac, pubkey_hmac,
551                sizeof(body->host_pub_key_mac));
552         wfx_fill_header(hif, -1, HIF_REQ_ID_SL_EXCHANGE_PUB_KEYS,
553                         sizeof(*body));
554         ret = wfx_cmd_send(wdev, hif, NULL, 0, false);
555         kfree(hif);
556         // Compatibility with legacy secure link
557         if (ret == le32_to_cpu(HIF_STATUS_SLK_NEGO_SUCCESS))
558                 ret = 0;
559         return ret;
560 }
561
562 int hif_sl_config(struct wfx_dev *wdev, const unsigned long *bitmap)
563 {
564         int ret;
565         struct hif_msg *hif;
566         struct hif_req_sl_configure *body = wfx_alloc_hif(sizeof(*body), &hif);
567
568         if (!hif)
569                 return -ENOMEM;
570         memcpy(body->encr_bmp, bitmap, sizeof(body->encr_bmp));
571         wfx_fill_header(hif, -1, HIF_REQ_ID_SL_CONFIGURE, sizeof(*body));
572         ret = wfx_cmd_send(wdev, hif, NULL, 0, false);
573         kfree(hif);
574         return ret;
575 }
576
577 int hif_sl_set_mac_key(struct wfx_dev *wdev, const u8 *slk_key, int destination)
578 {
579         int ret;
580         struct hif_msg *hif;
581         struct hif_req_set_sl_mac_key *body = wfx_alloc_hif(sizeof(*body),
582                                                             &hif);
583
584         if (!hif)
585                 return -ENOMEM;
586         memcpy(body->key_value, slk_key, sizeof(body->key_value));
587         body->otp_or_ram = destination;
588         wfx_fill_header(hif, -1, HIF_REQ_ID_SET_SL_MAC_KEY, sizeof(*body));
589         ret = wfx_cmd_send(wdev, hif, NULL, 0, false);
590         kfree(hif);
591         // Compatibility with legacy secure link
592         if (ret == le32_to_cpu(HIF_STATUS_SLK_SET_KEY_SUCCESS))
593                 ret = 0;
594         return ret;
595 }