-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathcommand.c
More file actions
2567 lines (2102 loc) · 77.2 KB
/
command.c
File metadata and controls
2567 lines (2102 loc) · 77.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright 2017-2023 Morse Micro
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
*/
#include <linux/types.h>
#include <linux/atomic.h>
#include <linux/slab.h>
#include <linux/atomic.h>
#include <linux/workqueue.h>
#include "debug.h"
#include "command.h"
#include "skbq.h"
#include "mac.h"
#include "skb_header.h"
#include "watchdog.h"
#include "ps.h"
#include "raw.h"
#include "twt.h"
#include "cac.h"
#include "operations.h"
#include "vendor_ie.h"
#include "ocs.h"
#include "mbssid.h"
#include "mesh.h"
#include "morse_commands.h"
#include "wiphy.h"
#define MM_BA_TIMEOUT (5000)
#define MM_MAX_COMMAND_RETRY 2
/*
* These timeouts (in msecs) must be kept in sync with the same definitions in the driver.
*/
#define MM_CMD_DEFAULT_TIMEOUT_MS 600
#define MM_CMD_POWERSAVE_TIMEOUT_MS 2000
#define MM_CMD_HEALTH_CHECK_TIMEOUT_MS 1000
enum morse_interface_type {
MORSE_INTERFACE_TYPE_INVALID = 0,
MORSE_INTERFACE_TYPE_STA = 1,
MORSE_INTERFACE_TYPE_AP = 2,
MORSE_INTERFACE_TYPE_MON = 3,
MORSE_INTERFACE_TYPE_ADHOC = 4,
MORSE_INTERFACE_TYPE_MESH = 5,
MORSE_INTERFACE_TYPE_LAST = MORSE_INTERFACE_TYPE_MESH,
MORSE_INTERFACE_TYPE_MAX = INT_MAX,
};
struct morse_cmd_resp_cb {
int ret;
u32 length;
struct morse_cmd_resp *dest_resp;
};
/* Set driver to chip command timeout: max to wait (in ms) before failing the command */
static u32 default_cmd_timeout_ms __read_mostly = MM_CMD_DEFAULT_TIMEOUT_MS;
module_param(default_cmd_timeout_ms, uint, 0644);
MODULE_PARM_DESC(default_cmd_timeout_ms, "Default command timeout (in ms)");
static void morse_cmd_init(struct morse *mors, struct morse_cmd_header *hdr,
enum morse_cmd_id cmd, u16 vif_id, u16 len)
{
if (len < sizeof(*hdr)) {
MORSE_ERR_RATELIMITED(mors, "Invalid cmd len %d\n", len);
return;
}
hdr->message_id = cpu_to_le16(cmd);
hdr->len = cpu_to_le16(len - sizeof(*hdr));
hdr->vif_id = cpu_to_le16(vif_id);
}
/**
* morse_cmd_standby_exit_reason_to_str() - Convert standby exit reason to string
*
* @reason: Reason for failure
*
* return string representing failure
*/
static const char *morse_cmd_standby_exit_reason_to_str(enum
morse_cmd_standby_mode_exit_reason reason)
{
switch (reason) {
case MORSE_CMD_STANDBY_MODE_EXIT_REASON_NONE:
return "none";
case MORSE_CMD_STANDBY_MODE_EXIT_REASON_WAKEUP_FRAME:
return "wake-up frame";
case MORSE_CMD_STANDBY_MODE_EXIT_REASON_ASSOCIATE:
return "associate";
case MORSE_CMD_STANDBY_MODE_EXIT_REASON_EXT_INPUT:
return "external input";
case MORSE_CMD_STANDBY_MODE_EXIT_REASON_WHITELIST_PKT:
return "whitelist pkt";
case MORSE_CMD_STANDBY_MODE_EXIT_REASON_TCP_CONNECTION_LOST:
return "tcp connection lost";
case MORSE_CMD_STANDBY_MODE_EXIT_REASON_HW_SCAN_NOT_ENABLED:
return "hw scan not enabled";
case MORSE_CMD_STANDBY_MODE_EXIT_REASON_HW_SCAN_FAILED_TO_START:
return "hw scan failed to start";
default:
return "unknown";
}
}
static int morse_cmd_tx(struct morse *mors, struct morse_cmd_resp *resp,
struct morse_cmd_req *req, u32 length, u32 timeout, const char *func)
{
int cmd_len;
int ret = 0;
u16 host_id;
int retry = 0;
unsigned long wait_ret = 0;
struct sk_buff *skb;
struct morse_skbq *cmd_q = mors->cfg->ops->skbq_cmd_tc_q(mors);
struct morse_cmd_resp_cb *resp_cb;
DECLARE_COMPLETION_ONSTACK(cmd_comp);
BUILD_BUG_ON(sizeof(struct morse_cmd_resp_cb) > IEEE80211_TX_INFO_DRIVER_DATA_SIZE);
if (!cmd_q)
/* No control pageset, not supported by FW */
return -ENODEV;
cmd_len = sizeof(*req) + le16_to_cpu(req->hdr.len);
req->hdr.flags = cpu_to_le16(MORSE_CMD_TYPE_REQ);
mutex_lock(&mors->cmd_wait);
mors->cmd_seq++;
if (mors->cmd_seq > MORSE_CMD_HOST_ID_SEQ_MAX)
mors->cmd_seq = 1;
host_id = mors->cmd_seq << MORSE_CMD_HOST_ID_SEQ_SHIFT;
/* Make sure no one enables PS until the command is responded to or timed out */
morse_ps_disable(mors);
do {
req->hdr.host_id = cpu_to_le16(host_id | retry);
skb = morse_skbq_alloc_skb(cmd_q, cmd_len);
if (!skb) {
ret = -ENOMEM;
break;
}
memcpy(skb->data, req, cmd_len);
resp_cb = (struct morse_cmd_resp_cb *)IEEE80211_SKB_CB(skb)->driver_data;
resp_cb->length = length;
resp_cb->dest_resp = resp;
MORSE_DBG(mors, "CMD 0x%04x:%04x\n", le16_to_cpu(req->hdr.message_id),
le16_to_cpu(req->hdr.host_id));
mutex_lock(&mors->cmd_lock);
mors->cmd_comp = &cmd_comp;
if (retry > 0)
reinit_completion(&cmd_comp);
timeout = timeout ? timeout : default_cmd_timeout_ms;
ret = morse_skbq_skb_tx(cmd_q, &skb, NULL, MORSE_SKB_CHAN_COMMAND);
mutex_unlock(&mors->cmd_lock);
if (ret) {
MORSE_ERR(mors, "morse_skbq_tx fail: %d\n", ret);
break;
}
wait_ret = wait_for_completion_timeout(&cmd_comp, msecs_to_jiffies(timeout));
mutex_lock(&mors->cmd_lock);
mors->cmd_comp = NULL;
if (!wait_ret) {
MORSE_INFO(mors, "Try:%d Command %04x:%04x timeout after %u ms\n",
retry, le16_to_cpu(req->hdr.message_id),
le16_to_cpu(req->hdr.host_id), timeout);
ret = -ETIMEDOUT;
} else {
ret = (length && resp) ? le32_to_cpu(resp->status) : resp_cb->ret;
MORSE_DBG(mors, "Command 0x%04x:%04x status 0x%08x\n",
le16_to_cpu(req->hdr.message_id),
le16_to_cpu(req->hdr.host_id), ret);
if (ret)
MORSE_ERR(mors, "Command 0x%04x:%04x error %d\n",
le16_to_cpu(req->hdr.message_id),
le16_to_cpu(req->hdr.host_id), ret);
}
/* Free the command request */
spin_lock_bh(&cmd_q->lock);
morse_skbq_skb_finish(cmd_q, skb, NULL);
spin_unlock_bh(&cmd_q->lock);
mutex_unlock(&mors->cmd_lock);
retry++;
} while ((ret == -ETIMEDOUT) && retry < MM_MAX_COMMAND_RETRY);
morse_ps_enable(mors);
mutex_unlock(&mors->cmd_wait);
if (ret == -ETIMEDOUT)
MORSE_ERR(mors, "Command %s %02x:%02x timed out\n",
func, le16_to_cpu(req->hdr.message_id), le16_to_cpu(req->hdr.host_id));
else if (ret != 0)
MORSE_ERR(mors, "Command %s %02x:%02x failed with rc %d (0x%x)\n",
func, le16_to_cpu(req->hdr.message_id),
le16_to_cpu(req->hdr.host_id), ret, ret);
return ret;
}
static int morse_cmd_ocs_req(struct morse_vif *mors_vif, struct morse_cmd_resp_ocs_driver *drv_resp,
struct morse_cmd_req_ocs_driver *drv_req)
{
int ret;
struct morse_cmd_req_ocs req;
struct morse *mors = morse_vif_to_morse(mors_vif);
if (sizeof(struct morse_cmd_resp_ocs) != sizeof(*drv_resp)) {
MORSE_ERR(mors,
"%s: OCS req failed - reason: inconsistent response size, firmware: %ld, driver:%ld\n",
__func__, (unsigned long)sizeof(struct morse_cmd_resp_ocs),
(unsigned long)sizeof(*drv_resp));
return -EINVAL;
}
/* Prepare request */
req.hdr = drv_req->hdr;
morse_cmd_init(mors, &req.hdr, MORSE_CMD_ID_OCS, 0, sizeof(req));
req.subcmd = drv_req->subcmd;
req.config.op_channel_freq_hz = drv_req->config.op_channel_freq_hz;
req.config.op_channel_bw_mhz = drv_req->config.op_channel_bw_mhz;
req.config.pri_channel_bw_mhz = drv_req->config.pri_channel_bw_mhz;
req.config.pri_1mhz_channel_index = drv_req->config.pri_1mhz_channel_index;
req.config.aid = cpu_to_le16(MORSE_OCS_AID);
req.config.type = ocs_type;
ret = morse_cmd_tx(mors, (struct morse_cmd_resp *)drv_resp,
(struct morse_cmd_req *)&req, sizeof(*drv_resp), 0, __func__);
if (ret)
return ret;
return morse_ocs_cmd_post_process(mors_vif, drv_resp, &req);
}
/**
* morse_cmd_send_wake_action_frame() - Execute command to send wake action frame
*
* @mors Morse chip struct
* @req Command from morsectrl
*/
static int morse_cmd_send_wake_action_frame(struct morse *mors, struct morse_cmd_req *req)
{
struct morse_cmd_req_send_wake_action_frame *cmd_action =
(struct morse_cmd_req_send_wake_action_frame *)req;
return morse_mac_send_vendor_wake_action_frame(mors, cmd_action->dest_addr,
cmd_action->payload,
le32_to_cpu(cmd_action->payload_size));
}
/**
* morse_cmd_coredump() - Schedule the restart work, coredump, and wait for
* chip reload.
*
* @mors Morse chip struct
*/
static int morse_cmd_coredump(struct morse *mors)
{
int ret;
unsigned long rem;
/* A core dump typically takes ~30s, applying a x2 buffer for completion */
const int timeout_ms = 60000;
DECLARE_COMPLETION_ONSTACK(user_coredump_comp);
lockdep_assert_held(&mors->lock);
ret = morse_coredump_new(mors, MORSE_COREDUMP_REASON_USER_REQUEST);
if (ret)
return ret;
mors->user_coredump_comp = &user_coredump_comp;
set_bit(MORSE_STATE_FLAG_DO_COREDUMP, &mors->state_flags);
schedule_work(&mors->driver_restart);
mutex_unlock(&mors->lock);
rem = wait_for_completion_timeout(&user_coredump_comp, msecs_to_jiffies(timeout_ms));
mutex_lock(&mors->lock);
mors->user_coredump_comp = NULL;
/* A value of zero indicates that wait_for_completion_timeout timed out
* waiting for completion
*/
return rem ? 0 : -1;
}
static void morse_cmd_cac_cfg_get(struct morse *mors, struct morse_vif *mors_vif,
struct morse_cmd_resp_cac *resp)
{
struct cac_threshold_change_rules rules;
int i;
BUILD_BUG_ON(ARRAY_SIZE(resp->rule) < ARRAY_SIZE(rules.rule));
morse_cac_get_rules(mors_vif, &rules, &resp->rule_tot);
resp->rule_tot = rules.rule_tot;
memset(&resp->rule, 0, sizeof(resp->rule));
for (i = 0; i < resp->rule_tot && i < ARRAY_SIZE(resp->rule); i++) {
struct cac_threshold_change_rule *rule = &rules.rule[i];
struct morse_cmd_cac_change_rule *cfm_rule = &resp->rule[i];
cfm_rule->arfs = cpu_to_le16(rule->arfs);
cfm_rule->threshold_change =
cpu_to_le16(cac_threshold_val2pc(rule->threshold_change));
}
}
static int morse_cmd_cac_cfg_set(struct morse *mors, struct morse_vif *mors_vif,
struct morse_cmd_req_cac *req)
{
struct cac_threshold_change_rules rules;
int i;
if (req->rule_tot > ARRAY_SIZE(rules.rule))
return -E2BIG;
if (req->rule_tot == 0)
return -EINVAL;
memset(&rules, 0, sizeof(rules));
rules.rule_tot = req->rule_tot;
for (i = 0; i < req->rule_tot; i++) {
struct cac_threshold_change_rule *rule = &rules.rule[i];
rule->arfs = le16_to_cpu(req->rule[i].arfs);
rule->threshold_change =
cac_threshold_pc2val(le16_to_cpu(req->rule[i].threshold_change));
}
morse_cac_set_rules(mors_vif, &rules);
return 0;
}
static int morse_process_cac_cmd(struct morse *mors, struct morse_vif *mors_vif,
struct morse_cmd_req *req, struct morse_cmd_resp *resp)
{
struct morse_cmd_req_cac *cac_req = (struct morse_cmd_req_cac *)req;
struct morse_cmd_resp_cac *cac_resp = (struct morse_cmd_resp_cac *)resp;
resp->hdr.len = cpu_to_le16(4);
switch (cac_req->opcode) {
case MORSE_CMD_CAC_OP_DISABLE:
return morse_cac_deinit(mors_vif);
case MORSE_CMD_CAC_OP_ENABLE:
return morse_cac_init(mors, mors_vif);
case MORSE_CMD_CAC_OP_CFG_GET:
resp->hdr.len = cpu_to_le16(sizeof(*cac_resp) - sizeof(cac_resp->hdr));
morse_cmd_cac_cfg_get(mors, mors_vif, cac_resp);
return 0;
case MORSE_CMD_CAC_OP_CFG_SET:
return morse_cmd_cac_cfg_set(mors, mors_vif, cac_req);
default:
return -EINVAL;
}
}
static void morse_cmd_resp_init(struct morse_cmd_resp *resp, u16 len, int status)
{
resp->hdr.len = cpu_to_le16(len);
resp->status = cpu_to_le32(status);
}
static int morse_cmd_drv(struct morse *mors, struct ieee80211_vif *vif, struct morse_cmd_resp *resp,
struct morse_cmd_req *req, u32 length, u32 timeout)
{
int ret;
struct morse_vif *mors_vif = ieee80211_vif_to_morse_vif(vif);
switch (le16_to_cpu(req->hdr.message_id)) {
case MORSE_CMD_ID_SET_STA_TYPE:
if (mors_vif) {
struct morse_cmd_req_set_sta_type *req_sta =
(struct morse_cmd_req_set_sta_type *)req;
mors->custom_configs.sta_type = req_sta->sta_type;
ret = 0;
morse_cmd_resp_init(resp, 4, ret);
} else {
ret = -EFAULT;
}
break;
case MORSE_CMD_ID_SET_ENC_MODE:
if (mors_vif) {
struct morse_cmd_req_set_enc_mode *req_enc =
(struct morse_cmd_req_set_enc_mode *)req;
mors->custom_configs.enc_mode = req_enc->enc_mode;
ret = 0;
morse_cmd_resp_init(resp, 4, ret);
} else {
ret = -EFAULT;
}
break;
case MORSE_CMD_ID_SET_LISTEN_INTERVAL:
if (mors_vif) {
struct morse_cmd_req_set_listen_interval *cmd_li =
(struct morse_cmd_req_set_listen_interval *)req;
mors->custom_configs.listen_interval = le16_to_cpu(cmd_li->listen_interval);
mors->custom_configs.listen_interval_ovr = true;
MORSE_DBG(mors, "Listen Interval %d\n",
mors->custom_configs.listen_interval);
ret = 0;
morse_cmd_resp_init(resp, 4, ret);
} else {
ret = -EFAULT;
}
break;
case MORSE_CMD_ID_SET_AMPDU: {
struct morse_cmd_req_set_ampdu *req_ampdu =
(struct morse_cmd_req_set_ampdu *)req;
mors->custom_configs.enable_ampdu = (req_ampdu->ampdu_enabled > 0);
ret = 0;
morse_cmd_resp_init(resp, 4, ret);
break;
}
case MORSE_CMD_ID_CONFIG_RAW:
if (mors_vif) {
struct morse_cmd_req_config_raw *req_raw =
(struct morse_cmd_req_config_raw *)req;
ret = morse_raw_process_cmd(mors_vif, req_raw);
morse_cmd_resp_init(resp, 4, ret);
} else {
ret = -EFAULT;
}
break;
case MORSE_CMD_ID_TEST_BA:
if (mors_vif) {
struct ieee80211_sta *sta;
struct morse_cmd_req_test_ba *test_ba = (struct morse_cmd_req_test_ba *)req;
ret = -EINVAL;
if (test_ba->tx) {
/* Must be held while finding and dereferencing sta */
rcu_read_lock();
sta = ieee80211_find_sta(vif, test_ba->addr);
if (!sta) {
rcu_read_unlock();
break;
}
if (test_ba->start)
ret = ieee80211_start_tx_ba_session(sta,
le32_to_cpu(test_ba->tid),
MM_BA_TIMEOUT);
else
ret = ieee80211_stop_tx_ba_session(sta,
le32_to_cpu(test_ba->tid));
rcu_read_unlock();
} else {
if (test_ba->start)
break;
ieee80211_stop_rx_ba_session(vif,
le32_to_cpu(test_ba->tid),
test_ba->addr);
ret = 0;
}
} else {
ret = -EFAULT;
}
break;
case MORSE_CMD_ID_SET_S1G_OP_CLASS: {
struct morse_cmd_req_set_s1g_op_class *req_op =
(struct morse_cmd_req_set_s1g_op_class *)req;
mors->custom_configs.channel_info.s1g_operating_class = req_op->opclass;
mors->custom_configs.channel_info.pri_global_operating_class = req_op->prim_opclass;
ret = 0;
morse_cmd_resp_init(resp, 4, ret);
break;
}
case MORSE_CMD_ID_SEND_WAKE_ACTION_FRAME:
ret = morse_cmd_send_wake_action_frame(mors, req);
morse_cmd_resp_init(resp, 4, ret);
break;
case MORSE_CMD_ID_DRIVER_SET_DUTY_CYCLE: {
struct morse_cmd_req_set_duty_cycle *duty_req =
(struct morse_cmd_req_set_duty_cycle *)req;
mors->custom_configs.duty_cycle = le32_to_cpu(duty_req->config.duty_cycle);
/*
* When a disable duty cycle command is executed via morsectrl it sends a
* duty cycle value of 100%. When this happens set the duty cycle value in
* custom config as 0. This enables the driver to use the duty cycle value
* mentioned in the regdom.
*/
if (le32_to_cpu(duty_req->config.duty_cycle) == 10000)
mors->custom_configs.duty_cycle = 0;
mors->duty_cycle = le32_to_cpu(duty_req->config.duty_cycle);
req->hdr.message_id = cpu_to_le16(MORSE_CMD_ID_SET_DUTY_CYCLE);
ret = morse_cmd_tx(mors, resp, req, le16_to_cpu(resp->hdr.len), 0, __func__);
morse_cmd_resp_init(resp, 4, ret);
break;
}
case MORSE_CMD_ID_SET_TWT_CONF:
ret = morse_process_twt_cmd(mors, mors_vif, req);
morse_cmd_resp_init(resp, 4, ret);
break;
case MORSE_CMD_ID_CAC:
ret = morse_process_cac_cmd(mors, mors_vif, req, resp);
resp->status = cpu_to_le32(ret);
break;
case MORSE_CMD_ID_GET_AVAILABLE_CHANNELS:
ret = morse_cmd_get_available_channels(mors, resp);
resp->status = cpu_to_le32(ret);
break;
case MORSE_CMD_ID_SET_ECSA_S1G_INFO:
if (mors_vif) {
struct morse_cmd_req_set_ecsa_s1g_info *req_ecsa =
(struct morse_cmd_req_set_ecsa_s1g_info *)req;
MORSE_INFO(mors, "ECSA channel info :\n"
" * s1g_global_operating_class : %d\n"
" * s1g_primary_bandwidth : %d\n"
" * s1g_operating_frequency : %u\n"
" * s1g_operating_bandwidth : %d\n"
" * s1g_primary_1MHz_chan_idx : %d\n"
" * primary_global_op_class : %d\n"
" * s1g_cap0 : %d\n",
req_ecsa->opclass,
req_ecsa->primary_channel_bw_mhz,
req_ecsa->operating_channel_freq_hz,
req_ecsa->operating_channel_bw_mhz,
req_ecsa->prim_1mhz_ch_idx,
req_ecsa->prim_opclass,
req_ecsa->s1g_cap0);
mors_vif->ecsa_channel_info.op_chan_freq_hz =
le32_to_cpu(req_ecsa->operating_channel_freq_hz);
mors_vif->ecsa_channel_info.op_bw_mhz = req_ecsa->operating_channel_bw_mhz;
mors_vif->ecsa_channel_info.pri_1mhz_chan_idx =
req_ecsa->prim_1mhz_ch_idx;
mors_vif->ecsa_channel_info.pri_bw_mhz = req_ecsa->primary_channel_bw_mhz;
mors_vif->ecsa_channel_info.s1g_operating_class = req_ecsa->opclass;
mors_vif->ecsa_channel_info.pri_global_operating_class =
req_ecsa->prim_opclass;
mors_vif->ecsa_channel_info.s1g_cap0 = req_ecsa->s1g_cap0;
mors_vif->ecsa_channel_info.s1g_cap1 = req_ecsa->s1g_cap1;
mors_vif->ecsa_channel_info.s1g_cap2 = req_ecsa->s1g_cap2;
mors_vif->ecsa_channel_info.s1g_cap3 = req_ecsa->s1g_cap3;
mors_vif->mask_ecsa_info_in_beacon = false;
ret = 0;
} else {
ret = -EFAULT;
}
morse_cmd_resp_init(resp, 4, ret);
break;
case MORSE_CMD_ID_MBSSID:
ret = morse_command_process_bssid_info(mors_vif,
(struct morse_cmd_req_mbssid *)req);
morse_cmd_resp_init(resp, 4, ret);
break;
case MORSE_CMD_ID_OCS_DRIVER:
ret = morse_cmd_ocs_req(mors_vif,
(struct morse_cmd_resp_ocs_driver *)resp,
(struct morse_cmd_req_ocs_driver *)req);
resp->status = cpu_to_le32(ret);
break;
case MORSE_CMD_ID_SET_MESH_CONFIG:
ret = morse_cmd_set_mesh_config(mors_vif,
(struct morse_cmd_req_set_mesh_config *)req,
NULL);
morse_cmd_resp_init(resp, 4, ret);
break;
case MORSE_CMD_ID_SET_MCBA_CONF:
ret = morse_cmd_process_mbca_conf(mors_vif,
(struct morse_cmd_req_set_mcba_conf *)req);
morse_cmd_resp_init(resp, 4, ret);
break;
case MORSE_CMD_ID_DYNAMIC_PEERING_CONFIG:
ret = morse_cmd_process_dynamic_peering_conf(mors_vif,
(struct morse_cmd_req_dynamic_peering_config *)req);
morse_cmd_resp_init(resp, 4, ret);
break;
case MORSE_CMD_ID_CONFIG_BSS_STATS:
ret = morse_cmd_process_bss_stats_conf(mors_vif,
(struct morse_cmd_req_config_bss_stats *)req);
morse_cmd_resp_init(resp, 4, ret);
break;
default:
ret = -EINVAL;
}
return ret;
}
int morse_cmd_resp_process(struct morse *mors, struct sk_buff *skb)
{
int length, ret = -ESRCH; /* No such process */
struct morse_skbq *cmd_q = mors->cfg->ops->skbq_cmd_tc_q(mors);
struct morse_cmd_resp *src_resp = (struct morse_cmd_resp *)(skb->data);
struct sk_buff *cmd_skb = NULL;
struct morse_cmd_resp_cb *resp_cb;
struct morse_cmd_resp *dest_resp;
struct morse_cmd_req *req;
u16 message_id = 0;
u16 host_id = 0;
u16 resp_message_id = le16_to_cpu(src_resp->hdr.message_id);
u16 resp_host_id = le16_to_cpu(src_resp->hdr.host_id);
bool is_late_response = false;
MORSE_DBG(mors, "EVT 0x%04x:0x%04x\n", resp_message_id, resp_host_id);
if (!MORSE_CMD_IS_RESP(src_resp)) {
ret = morse_mac_event_recv(mors, skb);
goto exit_free;
}
mutex_lock(&mors->cmd_lock);
cmd_skb = morse_skbq_tx_pending(cmd_q);
if (cmd_skb) {
morse_skb_remove_hdr_after_sent_to_chip(cmd_skb);
req = (struct morse_cmd_req *)cmd_skb->data;
message_id = le16_to_cpu(req->hdr.message_id);
host_id = le16_to_cpu(req->hdr.host_id);
}
/*
* If there is no pending command or the sequence ID does not match, this is a late response
* for a timed out command which has been cleaned up, so just free up the response.
* If a command was retried, the response may be from the retry or from the original
* command (late response) but not from both because the firmware will silently drop
* a retry if it received the initial request. So a mismatched retry counter is treated
* as a matched command and response.
*/
if (!cmd_skb || message_id != resp_message_id ||
(host_id & MORSE_CMD_HOST_ID_SEQ_MASK) != (resp_host_id & MORSE_CMD_HOST_ID_SEQ_MASK)) {
MORSE_ERR(mors,
"Late response for timed out req 0x%04x:%04x have 0x%04x:%04x 0x%04x\n",
resp_message_id, resp_host_id, message_id, host_id, mors->cmd_seq);
is_late_response = true;
goto exit;
}
if ((host_id & MORSE_CMD_HOST_ID_RETRY_MASK) !=
(resp_host_id & MORSE_CMD_HOST_ID_RETRY_MASK))
MORSE_INFO(mors, "Command retry mismatch 0x%04x:%04x 0x%04x:%04x\n",
message_id, host_id, resp_message_id, resp_host_id);
resp_cb = (struct morse_cmd_resp_cb *)IEEE80211_SKB_CB(cmd_skb)->driver_data;
length = resp_cb->length;
dest_resp = resp_cb->dest_resp;
if (length >= sizeof(struct morse_cmd_resp) && dest_resp) {
ret = 0;
length = min_t(int, length, le16_to_cpu(src_resp->hdr.len) +
sizeof(struct morse_cmd_header));
memcpy(dest_resp, src_resp, length);
} else {
ret = le32_to_cpu(src_resp->status);
}
resp_cb->ret = ret;
exit:
if (cmd_skb && !is_late_response) {
/* Complete if not already timed out */
if (mors->cmd_comp)
complete(mors->cmd_comp);
}
mutex_unlock(&mors->cmd_lock);
exit_free:
dev_kfree_skb(skb);
return 0;
}
int morse_cmd_set_channel(struct morse *mors, u32 op_chan_freq_hz,
u8 pri_1mhz_chan_idx, u8 op_bw_mhz, u8 pri_bw_mhz, s32 *power_mbm)
{
int ret;
struct morse_cmd_req_set_channel req;
struct morse_cmd_resp_set_channel resp;
morse_cmd_init(mors, &req.hdr, MORSE_CMD_ID_SET_CHANNEL, 0, sizeof(req));
/* May be 0xFFFF/0xFFFFFFFF to indicate no change */
req.op_chan_freq_hz = cpu_to_le32(op_chan_freq_hz);
req.op_bw_mhz = op_bw_mhz;
req.pri_bw_mhz = pri_bw_mhz;
req.pri_1mhz_chan_idx = pri_1mhz_chan_idx;
/* TODO: add other modes as necessary */
req.dot11_mode = MORSE_CMD_DOT11_PROTO_MODE_AH;
ret = morse_cmd_tx(mors, (struct morse_cmd_resp *)&resp,
(struct morse_cmd_req *)&req, sizeof(resp), 0, __func__);
if (!ret)
*power_mbm = QDBM_TO_MBM(le32_to_cpu(resp.power_qdbm));
return ret;
}
int morse_cmd_get_current_channel(struct morse *mors, u32 *op_chan_freq_hz,
u8 *pri_1mhz_chan_idx, u8 *op_bw_mhz, u8 *pri_bw_mhz)
{
struct morse_cmd_req_get_channel req;
struct morse_cmd_resp_get_channel resp;
int ret;
morse_cmd_init(mors, &req.hdr, MORSE_CMD_ID_GET_CHANNEL, 0, sizeof(req));
ret = morse_cmd_tx(mors, (struct morse_cmd_resp *)&resp, (struct morse_cmd_req *)&req,
sizeof(resp), 0, __func__);
if (ret)
return ret;
*op_chan_freq_hz = le32_to_cpu(resp.op_chan_freq_hz);
*pri_1mhz_chan_idx = resp.pri_1mhz_chan_idx;
*op_bw_mhz = resp.op_chan_bw_mhz;
*pri_bw_mhz = resp.pri_chan_bw_mhz;
return 0;
}
int morse_cmd_set_txpower(struct morse *mors, s32 *out_power_mbm, int txpower_mbm)
{
int ret;
struct morse_cmd_req_set_txpower req;
struct morse_cmd_resp_set_txpower resp;
morse_cmd_init(mors, &req.hdr, MORSE_CMD_ID_SET_TXPOWER, 0, sizeof(req));
req.power_qdbm = cpu_to_le32(MBM_TO_QDBM(txpower_mbm));
ret = morse_cmd_tx(mors, (struct morse_cmd_resp *)&resp,
(struct morse_cmd_req *)&req, sizeof(resp), 0, __func__);
if (ret == 0)
*out_power_mbm = QDBM_TO_MBM(le32_to_cpu(resp.power_qdbm));
return ret;
}
int morse_cmd_get_max_txpower(struct morse *mors, s32 *out_power_mbm)
{
int ret;
struct morse_cmd_req_get_max_txpower req;
struct morse_cmd_resp_get_max_txpower resp;
morse_cmd_init(mors, &req.hdr, MORSE_CMD_ID_GET_MAX_TXPOWER, 0, sizeof(req));
ret = morse_cmd_tx(mors, (struct morse_cmd_resp *)&resp,
(struct morse_cmd_req *)&req, sizeof(resp), 0, __func__);
if (ret == 0)
*out_power_mbm = QDBM_TO_MBM(le32_to_cpu(resp.power_qdbm));
return ret;
}
int morse_cmd_set_ps(struct morse *mors, bool enabled, bool enable_dynamic_ps_offload)
{
int ret;
struct morse_cmd_req_config_ps req;
morse_cmd_init(mors, &req.hdr, MORSE_CMD_ID_CONFIG_PS, 0, sizeof(req));
req.enabled = (u8)enabled;
req.dynamic_ps_offload = (u8)enable_dynamic_ps_offload;
ret = morse_cmd_tx(mors, NULL, (struct morse_cmd_req *)&req, 0,
default_cmd_timeout_ms > MM_CMD_POWERSAVE_TIMEOUT_MS ?
default_cmd_timeout_ms : MM_CMD_POWERSAVE_TIMEOUT_MS, __func__);
return ret;
}
int morse_cmd_config_beacon_timer(struct morse *mors, struct morse_vif *morse_vif, bool enabled)
{
int ret;
struct morse_cmd_req_bss_beacon_config req;
struct morse_cmd_resp_bss_beacon_config resp;
morse_cmd_init(mors, &req.hdr, MORSE_CMD_ID_BSS_BEACON_CONFIG, morse_vif->id, sizeof(req));
req.enable = enabled;
ret = morse_cmd_tx(mors, (struct morse_cmd_resp *)&resp,
(struct morse_cmd_req *)&req, 0, 0, __func__);
return ret;
}
int morse_cmd_store_pv1_hc_data(struct morse *mors, struct morse_vif *mors_vif,
struct ieee80211_sta *sta, u8 *a3, u8 *a4, bool is_store_in_rx)
{
int ret;
struct morse_cmd_req_pv1_store_hc req;
struct morse_cmd_resp_pv1_store_hc resp;
struct morse_sta *mors_sta = (struct morse_sta *)sta->drv_priv;
memset(&req, 0, sizeof(req));
if (a3 || a4)
req.opcode = MORSE_CMD_PV1_HC_OPCODE_A3_A4;
if (a3) {
req.pv1_hc_store |= MORSE_PV1_CMD_STORE_A3;
memcpy(req.a3, a3, sizeof(req.a3));
}
if (a4) {
req.pv1_hc_store |= MORSE_PV1_CMD_STORE_A4;
memcpy(req.a4, a4, sizeof(req.a4));
}
if (is_store_in_rx)
req.pv1_hc_store |= MORSE_PV1_CMD_STORE_RX;
memcpy(req.sta_addr, mors_sta->addr, sizeof(req.sta_addr));
morse_cmd_init(mors, &req.hdr, MORSE_CMD_ID_PV1_STORE_HC, mors_vif->id, sizeof(req));
ret = morse_cmd_tx(mors, (struct morse_cmd_resp *)&resp,
(struct morse_cmd_req *)&req, sizeof(resp), 0, __func__);
return ret;
}
int morse_cmd_add_if(struct morse *mors, u16 *vif_id, const u8 *addr, enum nl80211_iftype type)
{
int ret;
struct morse_cmd_req_add_interface req;
struct morse_cmd_resp_add_interface resp;
morse_cmd_init(mors, &req.hdr, MORSE_CMD_ID_ADD_INTERFACE, 0, sizeof(req));
switch (type) {
case NL80211_IFTYPE_STATION:
req.interface_type = cpu_to_le32(MORSE_CMD_INTERFACE_TYPE_STA);
break;
case NL80211_IFTYPE_ADHOC:
req.interface_type = cpu_to_le32(MORSE_CMD_INTERFACE_TYPE_ADHOC);
break;
case NL80211_IFTYPE_AP:
req.interface_type = cpu_to_le32(MORSE_CMD_INTERFACE_TYPE_AP);
break;
case NL80211_IFTYPE_MONITOR:
req.interface_type = cpu_to_le32(MORSE_CMD_INTERFACE_TYPE_MON);
break;
case NL80211_IFTYPE_MESH_POINT:
req.interface_type = cpu_to_le32(MORSE_CMD_INTERFACE_TYPE_MESH);
break;
default:
return -EOPNOTSUPP;
}
memcpy(req.addr.octet, addr, sizeof(req.addr.octet));
ret = morse_cmd_tx(mors, (struct morse_cmd_resp *)&resp,
(struct morse_cmd_req *)&req, sizeof(resp), 0, __func__);
if (ret == 0)
*vif_id = le16_to_cpu(resp.hdr.vif_id);
return ret;
}
int morse_cmd_rm_if(struct morse *mors, u16 vif_id)
{
int ret;
struct morse_cmd_req_remove_interface req;
morse_cmd_init(mors, &req.hdr, MORSE_CMD_ID_REMOVE_INTERFACE, vif_id, sizeof(req));
ret = morse_cmd_tx(mors, NULL, (struct morse_cmd_req *)&req, 0, 0, __func__);
return ret;
}
int morse_cmd_cfg_bss(struct morse *mors, u16 vif_id, u16 beacon_int, u16 dtim_period, u32 cssid)
{
int ret;
struct morse_cmd_req_bss_config req;
morse_cmd_init(mors, &req.hdr, MORSE_CMD_ID_BSS_CONFIG, vif_id, sizeof(req));
req.beacon_interval_tu = cpu_to_le16(beacon_int);
req.cssid = cpu_to_le32(cssid);
req.dtim_period = cpu_to_le16(dtim_period);
ret = morse_cmd_tx(mors, NULL, (struct morse_cmd_req *)&req, 0, 0, __func__);
return ret;
}
int morse_cmd_sta_state(struct morse *mors, struct morse_vif *mors_vif,
u16 aid, struct ieee80211_sta *sta, enum ieee80211_sta_state state)
{
int ret;
struct morse_cmd_req_set_sta_state req;
struct morse_cmd_resp_set_sta_state resp;
struct morse_sta *mors_sta = (struct morse_sta *)sta->drv_priv;
memset(&req, 0, sizeof(req));
morse_cmd_init(mors, &req.hdr, MORSE_CMD_ID_SET_STA_STATE, mors_vif->id, sizeof(req));
memcpy(req.sta_addr, sta->addr, sizeof(req.sta_addr));
req.aid = cpu_to_le16(aid);
req.state = cpu_to_le16(state);
req.uapsd_queues = sta->uapsd_queues;
if (mors_vif->enable_pv1 && mors_sta->pv1_frame_support)
req.flags = cpu_to_le32(MORSE_CMD_STA_FLAG_S1G_PV1);
ret = morse_cmd_tx(mors, (struct morse_cmd_resp *)&resp,
(struct morse_cmd_req *)&req, sizeof(resp), 0, __func__);
return ret;
}
int morse_cmd_disable_key(struct morse *mors, struct morse_vif *mors_vif,
u16 aid, struct ieee80211_key_conf *key)
{
int ret;
struct morse_cmd_req_disable_key req;
MORSE_DBG(mors, "%s Disabling key for vif (%d):\n"
"\tkey->hw_key_idx: %d\n"
"\taid (optional): %d\n", __func__, mors_vif->id, key->hw_key_idx, aid);
morse_cmd_init(mors, &req.hdr, MORSE_CMD_ID_DISABLE_KEY, mors_vif->id, sizeof(req));
req.aid = cpu_to_le32(aid);
req.key_idx = key->hw_key_idx;
req.key_type = cpu_to_le32((key->flags & IEEE80211_KEY_FLAG_PAIRWISE) ?
MORSE_CMD_TEMPORAL_KEY_TYPE_PTK : MORSE_CMD_TEMPORAL_KEY_TYPE_GTK);
ret = morse_cmd_tx(mors, NULL, (struct morse_cmd_req *)&req, 0, 0, __func__);
return ret;
}
int morse_cmd_install_key(struct morse *mors, struct morse_vif *mors_vif,
u16 aid, struct ieee80211_key_conf *key, enum morse_cmd_key_cipher cipher,
enum morse_cmd_aes_key_len length)
{
int ret;
struct morse_cmd_req_install_key req;
struct morse_cmd_resp_install_key resp;
MORSE_DBG(mors, "%s Installing key for vif (%d):\n"
"\tkey->idx: %d\n"
"\tkey->cipher: 0x%08x\n"
"\tkey->pn: %lld\n"
"\tkey->len: %d\n"
"\tkey->flags: 0x%08x\n"
"\taid (optional): %d\n",
__func__,
mors_vif->id,
key->keyidx,
key->cipher, (u64)atomic64_read(&key->tx_pn), key->keylen, key->flags, aid);
morse_cmd_init(mors, &req.hdr, MORSE_CMD_ID_INSTALL_KEY, mors_vif->id, sizeof(req));
req.pn = cpu_to_le64(atomic64_read(&key->tx_pn));
req.aid = cpu_to_le32(aid);
req.cipher = cipher;
req.key_length = length;
req.key_type = (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) ?
MORSE_CMD_TEMPORAL_KEY_TYPE_PTK : MORSE_CMD_TEMPORAL_KEY_TYPE_GTK;
req.key_idx = key->keyidx;
memcpy(&req.key[0], &key->key[0], sizeof(req.key));
ret = morse_cmd_tx(mors, (struct morse_cmd_resp *)&resp,
(struct morse_cmd_req *)&req, sizeof(resp), 0, __func__);
if (ret == 0) {
key->hw_key_idx = resp.key_idx;
MORSE_DBG(mors, "%s Installed key @ hw index: %d\n", __func__, resp.key_idx);
}
return ret;
}
int morse_cmd_get_version(struct morse *mors)
{
int ret;
struct morse_cmd_req_get_version req;
struct morse_cmd_resp_get_version *resp = NULL;
/* Allocate space for the resp, the max version str len and a null character */
u32 max_version_resp_size = sizeof(*resp) +
sizeof(resp->version[0]) * MORSE_CMD_MAX_VERSION_LEN + 1;