-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
5744 lines (4808 loc) · 149 KB
/
Copy pathmain.c
File metadata and controls
5744 lines (4808 loc) · 149 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
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (c) 2016-2021, The Linux Foundation. All rights reserved.
* Copyright (c) 2021-2024 Qualcomm Innovation Center, Inc. All rights reserved.
*/
#include <linux/delay.h>
#include <linux/devcoredump.h>
#include <linux/elf.h>
#include <linux/jiffies.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_device.h>
#include <linux/of_gpio.h>
#include <linux/pm_wakeup.h>
#include <linux/reboot.h>
#include <linux/rwsem.h>
#include <linux/suspend.h>
#include <linux/timer.h>
#include <linux/thermal.h>
#include <linux/version.h>
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 14, 0))
#include <linux/panic_notifier.h>
#endif
#if IS_ENABLED(CONFIG_QCOM_MINIDUMP)
#include <soc/qcom/minidump.h>
#endif
#include "cnss_plat_ipc_qmi.h"
#include "cnss_utils.h"
#include "main.h"
#include "bus.h"
#include "debug.h"
#include "genl.h"
#include "reg.h"
#ifdef CONFIG_CNSS_HW_SECURE_DISABLE
#ifdef CONFIG_CNSS_HW_SECURE_SMEM
#include <linux/soc/qcom/smem.h>
#define PERISEC_SMEM_ID 651
#define HW_WIFI_UID 0x508
#else
#include "smcinvoke.h"
#include "smcinvoke_object.h"
#include "IClientEnv.h"
#define HW_STATE_UID 0x108
#define HW_OP_GET_STATE 1
#define HW_WIFI_UID 0x508
#define FEATURE_NOT_SUPPORTED 12
#define PERIPHERAL_NOT_FOUND 10
#endif
#endif
#define CNSS_DUMP_FORMAT_VER 0x11
#define CNSS_DUMP_FORMAT_VER_V2 0x22
#define CNSS_DUMP_MAGIC_VER_V2 0x42445953
#define CNSS_DUMP_NAME "CNSS_WLAN"
#define CNSS_DUMP_DESC_SIZE 0x1000
#define CNSS_DUMP_SEG_VER 0x1
#define FILE_SYSTEM_READY 1
#define FW_READY_TIMEOUT 20000
#define FW_ASSERT_TIMEOUT 5000
#define CNSS_EVENT_PENDING 2989
#define POWER_RESET_MIN_DELAY_MS 100
#define MAX_NAME_LEN 12
#define CNSS_QUIRKS_DEFAULT 0
#ifdef CONFIG_CNSS_EMULATION
#define CNSS_MHI_TIMEOUT_DEFAULT 90000
#define CNSS_MHI_M2_TIMEOUT_DEFAULT 2000
#define CNSS_QMI_TIMEOUT_DEFAULT 90000
#else
#define CNSS_MHI_TIMEOUT_DEFAULT 0
#define CNSS_MHI_M2_TIMEOUT_DEFAULT 25
#define CNSS_QMI_TIMEOUT_DEFAULT 10000
#endif
#define CNSS_BDF_TYPE_DEFAULT CNSS_BDF_ELF
#define CNSS_TIME_SYNC_PERIOD_DEFAULT 900000
#define CNSS_MIN_TIME_SYNC_PERIOD 2000
#define CNSS_DMS_QMI_CONNECTION_WAIT_MS 50
#define CNSS_DMS_QMI_CONNECTION_WAIT_RETRY 200
#define CNSS_DAEMON_CONNECT_TIMEOUT_MS 30000
#define CNSS_CAL_DB_FILE_NAME "wlfw_cal_db.bin"
#define CNSS_CAL_START_PROBE_WAIT_RETRY_MAX 100
#define CNSS_CAL_START_PROBE_WAIT_MS 500
#define CNSS_TIME_SYNC_PERIOD_INVALID 0xFFFFFFFF
enum cnss_cal_db_op {
CNSS_CAL_DB_UPLOAD,
CNSS_CAL_DB_DOWNLOAD,
CNSS_CAL_DB_INVALID_OP,
};
enum cnss_recovery_type {
CNSS_WLAN_RECOVERY = 0x1,
CNSS_PCSS_RECOVERY = 0x2,
};
#ifdef CONFIG_CNSS_SUPPORT_DUAL_DEV
#define CNSS_MAX_DEV_NUM 2
static struct cnss_plat_data *plat_env[CNSS_MAX_DEV_NUM];
static atomic_t plat_env_count;
#else
static struct cnss_plat_data *plat_env;
#endif
static bool cnss_allow_driver_loading;
static struct cnss_fw_files FW_FILES_QCA6174_FW_3_0 = {
"qwlan30.bin", "bdwlan30.bin", "otp30.bin", "utf30.bin",
"utfbd30.bin", "epping30.bin", "evicted30.bin"
};
static struct cnss_fw_files FW_FILES_DEFAULT = {
"qwlan.bin", "bdwlan.bin", "otp.bin", "utf.bin",
"utfbd.bin", "epping.bin", "evicted.bin"
};
struct cnss_driver_event {
struct list_head list;
enum cnss_driver_event_type type;
bool sync;
struct completion complete;
int ret;
void *data;
};
bool cnss_check_driver_loading_allowed(void)
{
return cnss_allow_driver_loading;
}
#ifdef CONFIG_CNSS_SUPPORT_DUAL_DEV
static void cnss_init_plat_env_count(void)
{
atomic_set(&plat_env_count, 0);
}
static void cnss_inc_plat_env_count(void)
{
atomic_inc(&plat_env_count);
}
static void cnss_dec_plat_env_count(void)
{
atomic_dec(&plat_env_count);
}
static int cnss_get_plat_env_count(void)
{
return atomic_read(&plat_env_count);
}
int cnss_get_max_plat_env_count(void)
{
return CNSS_MAX_DEV_NUM;
}
static void cnss_set_plat_priv(struct platform_device *plat_dev,
struct cnss_plat_data *plat_priv)
{
int env_count = cnss_get_plat_env_count();
cnss_pr_dbg("Set plat_priv at %d", env_count);
if (plat_priv) {
plat_priv->plat_idx = env_count;
plat_env[plat_priv->plat_idx] = plat_priv;
cnss_inc_plat_env_count();
}
}
struct cnss_plat_data *cnss_get_plat_priv(struct platform_device
*plat_dev)
{
int i;
if (!plat_dev)
return NULL;
for (i = 0; i < CNSS_MAX_DEV_NUM; i++) {
if (plat_env[i] && plat_env[i]->plat_dev == plat_dev)
return plat_env[i];
}
return NULL;
}
struct cnss_plat_data *cnss_get_first_plat_priv(struct platform_device
*plat_dev)
{
int i;
if (!plat_dev) {
for (i = 0; i < CNSS_MAX_DEV_NUM; i++) {
if (plat_env[i])
return plat_env[i];
}
}
return NULL;
}
static void cnss_clear_plat_priv(struct cnss_plat_data *plat_priv)
{
cnss_pr_dbg("Clear plat_priv at %d", plat_priv->plat_idx);
plat_env[plat_priv->plat_idx] = NULL;
cnss_dec_plat_env_count();
}
static int cnss_set_device_name(struct cnss_plat_data *plat_priv)
{
snprintf(plat_priv->device_name, sizeof(plat_priv->device_name),
"wlan_%d", plat_priv->plat_idx);
return 0;
}
static int cnss_plat_env_available(void)
{
int ret = 0;
int env_count = cnss_get_plat_env_count();
if (env_count >= CNSS_MAX_DEV_NUM) {
cnss_pr_err("ERROR: No space to store plat_priv\n");
ret = -ENOMEM;
}
return ret;
}
struct cnss_plat_data *cnss_get_plat_env(int index)
{
return plat_env[index];
}
struct cnss_plat_data *cnss_get_plat_priv_by_rc_num(int rc_num)
{
int i;
for (i = 0; i < CNSS_MAX_DEV_NUM; i++) {
if (plat_env[i] && plat_env[i]->rc_num == rc_num)
return plat_env[i];
}
return NULL;
}
static inline int
cnss_get_qrtr_node_id(struct cnss_plat_data *plat_priv)
{
return of_property_read_u32(plat_priv->dev_node,
"qcom,qrtr_node_id", &plat_priv->qrtr_node_id);
}
void cnss_get_qrtr_info(struct cnss_plat_data *plat_priv)
{
int ret = 0;
ret = cnss_get_qrtr_node_id(plat_priv);
if (ret) {
cnss_pr_warn("Failed to find qrtr_node_id err=%d\n", ret);
plat_priv->qrtr_node_id = 0;
plat_priv->wlfw_service_instance_id = 0;
} else {
plat_priv->wlfw_service_instance_id = plat_priv->qrtr_node_id +
QRTR_NODE_FW_ID_BASE;
cnss_pr_dbg("service_instance_id=0x%x\n",
plat_priv->wlfw_service_instance_id);
}
}
static inline int
cnss_get_pld_bus_ops_name(struct cnss_plat_data *plat_priv)
{
return of_property_read_string(plat_priv->plat_dev->dev.of_node,
"qcom,pld_bus_ops_name",
&plat_priv->pld_bus_ops_name);
}
#else
static void cnss_init_plat_env_count(void)
{
}
static void cnss_set_plat_priv(struct platform_device *plat_dev,
struct cnss_plat_data *plat_priv)
{
plat_env = plat_priv;
}
struct cnss_plat_data *cnss_get_plat_priv(struct platform_device *plat_dev)
{
return plat_env;
}
static void cnss_clear_plat_priv(struct cnss_plat_data *plat_priv)
{
plat_env = NULL;
}
static int cnss_set_device_name(struct cnss_plat_data *plat_priv)
{
snprintf(plat_priv->device_name, sizeof(plat_priv->device_name),
"wlan");
return 0;
}
static int cnss_plat_env_available(void)
{
return 0;
}
struct cnss_plat_data *cnss_get_plat_priv_by_rc_num(int rc_num)
{
return cnss_bus_dev_to_plat_priv(NULL);
}
void cnss_get_qrtr_info(struct cnss_plat_data *plat_priv)
{
}
static int
cnss_get_pld_bus_ops_name(struct cnss_plat_data *plat_priv)
{
return 0;
}
#endif
void cnss_get_sleep_clk_supported(struct cnss_plat_data *plat_priv)
{
plat_priv->sleep_clk = of_property_read_bool(plat_priv->dev_node,
"qcom,sleep-clk-support");
cnss_pr_dbg("qcom,sleep-clk-support is %d\n",
plat_priv->sleep_clk);
}
void cnss_get_bwscal_info(struct cnss_plat_data *plat_priv)
{
plat_priv->no_bwscale = of_property_read_bool(plat_priv->dev_node,
"qcom,no-bwscale");
}
static inline int
cnss_get_rc_num(struct cnss_plat_data *plat_priv)
{
return of_property_read_u32(plat_priv->plat_dev->dev.of_node,
"qcom,wlan-rc-num", &plat_priv->rc_num);
}
bool cnss_is_dual_wlan_enabled(void)
{
return IS_ENABLED(CONFIG_CNSS_SUPPORT_DUAL_DEV);
}
/**
* cnss_get_mem_seg_count - Get segment count of memory
* @type: memory type
* @seg: segment count
*
* Return: 0 on success, negative value on failure
*/
int cnss_get_mem_seg_count(enum cnss_remote_mem_type type, u32 *seg)
{
struct cnss_plat_data *plat_priv;
plat_priv = cnss_get_plat_priv(NULL);
if (!plat_priv)
return -ENODEV;
switch (type) {
case CNSS_REMOTE_MEM_TYPE_FW:
*seg = plat_priv->fw_mem_seg_len;
break;
case CNSS_REMOTE_MEM_TYPE_QDSS:
*seg = plat_priv->qdss_mem_seg_len;
break;
default:
return -EINVAL;
}
return 0;
}
EXPORT_SYMBOL(cnss_get_mem_seg_count);
/**
* cnss_get_wifi_kobject -return wifi kobject
* Return: Null, to maintain driver comnpatibilty
*/
struct kobject *cnss_get_wifi_kobj(struct device *dev)
{
struct cnss_plat_data *plat_priv;
plat_priv = cnss_get_plat_priv(NULL);
if (!plat_priv)
return NULL;
return plat_priv->wifi_kobj;
}
EXPORT_SYMBOL(cnss_get_wifi_kobj);
/**
* cnss_get_mem_segment_info - Get memory info of different type
* @type: memory type
* @segment: array to save the segment info
* @seg: segment count
*
* Return: 0 on success, negative value on failure
*/
int cnss_get_mem_segment_info(enum cnss_remote_mem_type type,
struct cnss_mem_segment segment[],
u32 segment_count)
{
struct cnss_plat_data *plat_priv;
u32 i;
plat_priv = cnss_get_plat_priv(NULL);
if (!plat_priv)
return -ENODEV;
switch (type) {
case CNSS_REMOTE_MEM_TYPE_FW:
if (segment_count > plat_priv->fw_mem_seg_len)
segment_count = plat_priv->fw_mem_seg_len;
for (i = 0; i < segment_count; i++) {
segment[i].size = plat_priv->fw_mem[i].size;
segment[i].va = plat_priv->fw_mem[i].va;
segment[i].pa = plat_priv->fw_mem[i].pa;
}
break;
case CNSS_REMOTE_MEM_TYPE_QDSS:
if (segment_count > plat_priv->qdss_mem_seg_len)
segment_count = plat_priv->qdss_mem_seg_len;
for (i = 0; i < segment_count; i++) {
segment[i].size = plat_priv->qdss_mem[i].size;
segment[i].va = plat_priv->qdss_mem[i].va;
segment[i].pa = plat_priv->qdss_mem[i].pa;
}
break;
default:
return -EINVAL;
}
return 0;
}
EXPORT_SYMBOL(cnss_get_mem_segment_info);
static int cnss_get_audio_iommu_domain(struct cnss_plat_data *plat_priv)
{
struct device_node *audio_ion_node;
struct platform_device *audio_ion_pdev;
audio_ion_node = of_find_compatible_node(NULL, NULL,
"qcom,msm-audio-ion");
if (!audio_ion_node) {
cnss_pr_err("Unable to get Audio ion node");
return -EINVAL;
}
audio_ion_pdev = of_find_device_by_node(audio_ion_node);
of_node_put(audio_ion_node);
if (!audio_ion_pdev) {
cnss_pr_err("Unable to get Audio ion platform device");
return -EINVAL;
}
plat_priv->audio_iommu_domain =
iommu_get_domain_for_dev(&audio_ion_pdev->dev);
put_device(&audio_ion_pdev->dev);
if (!plat_priv->audio_iommu_domain) {
cnss_pr_err("Unable to get Audio ion iommu domain");
return -EINVAL;
}
return 0;
}
bool cnss_get_audio_shared_iommu_group_cap(struct device *dev)
{
struct cnss_plat_data *plat_priv = cnss_bus_dev_to_plat_priv(dev);
struct device_node *audio_ion_node;
struct device_node *cnss_iommu_group_node;
struct device_node *audio_iommu_group_node;
if (!plat_priv)
return false;
audio_ion_node = of_find_compatible_node(NULL, NULL,
"qcom,msm-audio-ion");
if (!audio_ion_node) {
cnss_pr_err("Unable to get Audio ion node");
return false;
}
audio_iommu_group_node = of_parse_phandle(audio_ion_node,
"qcom,iommu-group", 0);
of_node_put(audio_ion_node);
if (!audio_iommu_group_node) {
cnss_pr_err("Unable to get audio iommu group phandle");
return false;
}
of_node_put(audio_iommu_group_node);
cnss_iommu_group_node = of_parse_phandle(dev->of_node,
"qcom,iommu-group", 0);
if (!cnss_iommu_group_node) {
cnss_pr_err("Unable to get cnss iommu group phandle");
return false;
}
of_node_put(cnss_iommu_group_node);
if (cnss_iommu_group_node == audio_iommu_group_node) {
plat_priv->is_audio_shared_iommu_group = true;
cnss_pr_info("CNSS and Audio share IOMMU group");
} else {
cnss_pr_info("CNSS and Audio do not share IOMMU group");
}
return plat_priv->is_audio_shared_iommu_group;
}
EXPORT_SYMBOL(cnss_get_audio_shared_iommu_group_cap);
int cnss_set_feature_list(struct cnss_plat_data *plat_priv,
enum cnss_feature_v01 feature)
{
if (unlikely(!plat_priv || feature >= CNSS_MAX_FEATURE_V01))
return -EINVAL;
plat_priv->feature_list |= 1 << feature;
return 0;
}
int cnss_clear_feature_list(struct cnss_plat_data *plat_priv,
enum cnss_feature_v01 feature)
{
if (unlikely(!plat_priv || feature >= CNSS_MAX_FEATURE_V01))
return -EINVAL;
plat_priv->feature_list &= ~(1 << feature);
return 0;
}
int cnss_get_feature_list(struct cnss_plat_data *plat_priv,
u64 *feature_list)
{
if (unlikely(!plat_priv))
return -EINVAL;
*feature_list = plat_priv->feature_list;
return 0;
}
size_t cnss_get_platform_name(struct cnss_plat_data *plat_priv,
char *buf, const size_t buf_len)
{
if (unlikely(!plat_priv || !buf || !buf_len))
return 0;
if (of_property_read_bool(plat_priv->plat_dev->dev.of_node,
"platform-name-required")) {
struct device_node *root;
root = of_find_node_by_path("/");
if (root) {
const char *model;
size_t model_len;
model = of_get_property(root, "model", NULL);
if (model) {
model_len = strlcpy(buf, model, buf_len);
cnss_pr_dbg("Platform name: %s (%zu)\n",
buf, model_len);
return model_len;
}
}
}
return 0;
}
void cnss_pm_stay_awake(struct cnss_plat_data *plat_priv)
{
if (atomic_inc_return(&plat_priv->pm_count) != 1)
return;
cnss_pr_dbg("PM stay awake, state: 0x%lx, count: %d\n",
plat_priv->driver_state,
atomic_read(&plat_priv->pm_count));
pm_stay_awake(&plat_priv->plat_dev->dev);
}
void cnss_pm_relax(struct cnss_plat_data *plat_priv)
{
int r = atomic_dec_return(&plat_priv->pm_count);
WARN_ON(r < 0);
if (r != 0)
return;
cnss_pr_dbg("PM relax, state: 0x%lx, count: %d\n",
plat_priv->driver_state,
atomic_read(&plat_priv->pm_count));
pm_relax(&plat_priv->plat_dev->dev);
}
int cnss_get_fw_files_for_target(struct device *dev,
struct cnss_fw_files *pfw_files,
u32 target_type, u32 target_version)
{
if (!pfw_files)
return -ENODEV;
switch (target_version) {
case QCA6174_REV3_VERSION:
case QCA6174_REV3_2_VERSION:
memcpy(pfw_files, &FW_FILES_QCA6174_FW_3_0, sizeof(*pfw_files));
break;
default:
memcpy(pfw_files, &FW_FILES_DEFAULT, sizeof(*pfw_files));
cnss_pr_err("Unknown target version, type: 0x%X, version: 0x%X",
target_type, target_version);
break;
}
return 0;
}
EXPORT_SYMBOL(cnss_get_fw_files_for_target);
int cnss_get_platform_cap(struct device *dev, struct cnss_platform_cap *cap)
{
struct cnss_plat_data *plat_priv = cnss_bus_dev_to_plat_priv(dev);
if (!plat_priv)
return -ENODEV;
if (!cap)
return -EINVAL;
*cap = plat_priv->cap;
cnss_pr_dbg("Platform cap_flag is 0x%x\n", cap->cap_flag);
return 0;
}
EXPORT_SYMBOL(cnss_get_platform_cap);
/**
* cnss_get_fw_cap - Check whether FW supports specific capability or not
* @dev: Device
* @fw_cap: FW Capability which needs to be checked
*
* Return: TRUE if supported, FALSE on failure or if not supported
*/
bool cnss_get_fw_cap(struct device *dev, enum cnss_fw_caps fw_cap)
{
struct cnss_plat_data *plat_priv = cnss_bus_dev_to_plat_priv(dev);
bool is_supported = false;
if (!plat_priv)
return is_supported;
if (!plat_priv->fw_caps)
return is_supported;
switch (fw_cap) {
case CNSS_FW_CAP_DIRECT_LINK_SUPPORT:
is_supported = !!(plat_priv->fw_caps &
QMI_WLFW_DIRECT_LINK_SUPPORT_V01);
break;
case CNSS_FW_CAP_CALDB_SEG_DDR_SUPPORT:
is_supported = !!(plat_priv->fw_caps &
QMI_WLFW_CALDB_SEG_DDR_SUPPORT_V01);
break;
default:
cnss_pr_err("Invalid FW Capability: 0x%x\n", fw_cap);
}
cnss_pr_dbg("FW Capability 0x%x is %s\n", fw_cap,
is_supported ? "supported" : "not supported");
return is_supported;
}
EXPORT_SYMBOL(cnss_get_fw_cap);
/**
* cnss_audio_is_direct_link_supported - Check whether Audio can be used for direct link support
* @dev: Device
*
* Return: TRUE if supported, FALSE on failure or if not supported
*/
bool cnss_audio_is_direct_link_supported(struct device *dev)
{
struct cnss_plat_data *plat_priv = cnss_bus_dev_to_plat_priv(dev);
bool is_supported = false;
if (!plat_priv) {
cnss_pr_err("plat_priv not available to check audio direct link cap\n");
return is_supported;
}
if (cnss_get_audio_iommu_domain(plat_priv) == 0)
is_supported = true;
return is_supported;
}
EXPORT_SYMBOL(cnss_audio_is_direct_link_supported);
void cnss_request_pm_qos(struct device *dev, u32 qos_val)
{
struct cnss_plat_data *plat_priv = cnss_bus_dev_to_plat_priv(dev);
if (!plat_priv)
return;
cpu_latency_qos_add_request(&plat_priv->qos_request, qos_val);
}
EXPORT_SYMBOL(cnss_request_pm_qos);
void cnss_remove_pm_qos(struct device *dev)
{
struct cnss_plat_data *plat_priv = cnss_bus_dev_to_plat_priv(dev);
if (!plat_priv)
return;
cpu_latency_qos_remove_request(&plat_priv->qos_request);
}
EXPORT_SYMBOL(cnss_remove_pm_qos);
int cnss_wlan_enable(struct device *dev,
struct cnss_wlan_enable_cfg *config,
enum cnss_driver_mode mode,
const char *host_version)
{
int ret = 0;
struct cnss_plat_data *plat_priv;
if (!dev) {
cnss_pr_err("Invalid dev pointer\n");
return -EINVAL;
}
plat_priv = cnss_bus_dev_to_plat_priv(dev);
if (!plat_priv)
return -ENODEV;
if (plat_priv->device_id == QCA6174_DEVICE_ID)
return 0;
if (test_bit(QMI_BYPASS, &plat_priv->ctrl_params.quirks))
return 0;
if (!config || !host_version) {
cnss_pr_err("Invalid config or host_version pointer\n");
return -EINVAL;
}
cnss_pr_dbg("Mode: %d, config: %pK, host_version: %s\n",
mode, config, host_version);
if (mode == CNSS_WALTEST || mode == CNSS_CCPM)
goto skip_cfg;
if (plat_priv->device_id == QCN7605_DEVICE_ID)
config->send_msi_ce = true;
ret = cnss_wlfw_wlan_cfg_send_sync(plat_priv, config, host_version);
if (ret)
goto out;
skip_cfg:
ret = cnss_wlfw_wlan_mode_send_sync(plat_priv, mode);
out:
return ret;
}
EXPORT_SYMBOL(cnss_wlan_enable);
int cnss_wlan_disable(struct device *dev, enum cnss_driver_mode mode)
{
int ret = 0;
struct cnss_plat_data *plat_priv;
if (!dev) {
cnss_pr_err("Invalid dev pointer\n");
return -EINVAL;
}
plat_priv = cnss_bus_dev_to_plat_priv(dev);
if (!plat_priv)
return -ENODEV;
if (plat_priv->device_id == QCA6174_DEVICE_ID)
return 0;
if (test_bit(QMI_BYPASS, &plat_priv->ctrl_params.quirks))
return 0;
ret = cnss_wlfw_wlan_mode_send_sync(plat_priv, CNSS_OFF);
cnss_bus_free_qdss_mem(plat_priv);
return ret;
}
EXPORT_SYMBOL(cnss_wlan_disable);
#if (LINUX_VERSION_CODE < KERNEL_VERSION(6, 2, 0))
int cnss_iommu_map(struct iommu_domain *domain,
unsigned long iova, phys_addr_t paddr, size_t size, int prot)
{
return iommu_map(domain, iova, paddr, size, prot);
}
#else
int cnss_iommu_map(struct iommu_domain *domain,
unsigned long iova, phys_addr_t paddr, size_t size, int prot)
{
return iommu_map(domain, iova, paddr, size, prot, GFP_KERNEL);
}
#endif
int cnss_audio_smmu_map(struct device *dev, phys_addr_t paddr,
dma_addr_t iova, size_t size)
{
struct cnss_plat_data *plat_priv = cnss_bus_dev_to_plat_priv(dev);
uint32_t page_offset;
if (!plat_priv)
return -ENODEV;
if (!plat_priv->audio_iommu_domain)
return -EINVAL;
if (plat_priv->is_audio_shared_iommu_group)
return 0;
page_offset = iova & (PAGE_SIZE - 1);
if (page_offset + size > PAGE_SIZE)
size += PAGE_SIZE;
iova -= page_offset;
paddr -= page_offset;
return cnss_iommu_map(plat_priv->audio_iommu_domain, iova, paddr,
roundup(size, PAGE_SIZE), IOMMU_READ |
IOMMU_WRITE | IOMMU_CACHE);
}
EXPORT_SYMBOL(cnss_audio_smmu_map);
void cnss_audio_smmu_unmap(struct device *dev, dma_addr_t iova, size_t size)
{
struct cnss_plat_data *plat_priv = cnss_bus_dev_to_plat_priv(dev);
uint32_t page_offset;
if (!plat_priv || !plat_priv->audio_iommu_domain ||
plat_priv->is_audio_shared_iommu_group)
return;
page_offset = iova & (PAGE_SIZE - 1);
if (page_offset + size > PAGE_SIZE)
size += PAGE_SIZE;
iova -= page_offset;
iommu_unmap(plat_priv->audio_iommu_domain, iova,
roundup(size, PAGE_SIZE));
}
EXPORT_SYMBOL(cnss_audio_smmu_unmap);
int cnss_get_fw_lpass_shared_mem(struct device *dev, dma_addr_t *iova,
size_t *size)
{
struct cnss_plat_data *plat_priv = cnss_bus_dev_to_plat_priv(dev);
uint8_t i;
if (!plat_priv)
return -EINVAL;
for (i = 0; i < plat_priv->fw_mem_seg_len; i++) {
if (plat_priv->fw_mem[i].type ==
QMI_WLFW_MEM_LPASS_SHARED_V01) {
*iova = plat_priv->fw_mem[i].pa;
*size = plat_priv->fw_mem[i].size;
return 0;
}
}
return -EINVAL;
}
EXPORT_SYMBOL(cnss_get_fw_lpass_shared_mem);
int cnss_athdiag_read(struct device *dev, u32 offset, u32 mem_type,
u32 data_len, u8 *output)
{
struct cnss_plat_data *plat_priv = cnss_bus_dev_to_plat_priv(dev);
int ret = 0;
if (!plat_priv) {
cnss_pr_err("plat_priv is NULL!\n");
return -EINVAL;
}
if (plat_priv->device_id == QCA6174_DEVICE_ID)
return 0;
if (!test_bit(CNSS_FW_READY, &plat_priv->driver_state)) {
cnss_pr_err("Invalid state for athdiag read: 0x%lx\n",
plat_priv->driver_state);
ret = -EINVAL;
goto out;
}
ret = cnss_wlfw_athdiag_read_send_sync(plat_priv, offset, mem_type,
data_len, output);
out:
return ret;
}
EXPORT_SYMBOL(cnss_athdiag_read);
int cnss_athdiag_write(struct device *dev, u32 offset, u32 mem_type,
u32 data_len, u8 *input)
{
struct cnss_plat_data *plat_priv = cnss_bus_dev_to_plat_priv(dev);
int ret = 0;
if (!plat_priv) {
cnss_pr_err("plat_priv is NULL!\n");
return -EINVAL;
}
if (plat_priv->device_id == QCA6174_DEVICE_ID)
return 0;
if (!test_bit(CNSS_FW_READY, &plat_priv->driver_state)) {
cnss_pr_err("Invalid state for athdiag write: 0x%lx\n",
plat_priv->driver_state);
ret = -EINVAL;
goto out;
}
ret = cnss_wlfw_athdiag_write_send_sync(plat_priv, offset, mem_type,
data_len, input);
out:
return ret;
}
EXPORT_SYMBOL(cnss_athdiag_write);
int cnss_set_fw_log_mode(struct device *dev, u8 fw_log_mode)
{
struct cnss_plat_data *plat_priv;
if (!dev) {
cnss_pr_err("Invalid dev pointer\n");
return -EINVAL;
}
plat_priv = cnss_bus_dev_to_plat_priv(dev);
if (!plat_priv)
return -ENODEV;
if (plat_priv->device_id == QCA6174_DEVICE_ID)
return 0;
return cnss_wlfw_ini_send_sync(plat_priv, fw_log_mode);
}
EXPORT_SYMBOL(cnss_set_fw_log_mode);
int cnss_set_pcie_gen_speed(struct device *dev, u8 pcie_gen_speed)
{
struct cnss_plat_data *plat_priv = cnss_bus_dev_to_plat_priv(dev);
if (!plat_priv)
return -EINVAL;
if (!plat_priv->fw_pcie_gen_switch) {
cnss_pr_err("Firmware does not support PCIe gen switch\n");
return -EOPNOTSUPP;
}
if (pcie_gen_speed < QMI_PCIE_GEN_SPEED_1_V01 ||
pcie_gen_speed > QMI_PCIE_GEN_SPEED_3_V01)
return -EINVAL;
cnss_pr_dbg("WLAN provided PCIE gen speed: %d\n", pcie_gen_speed);
plat_priv->pcie_gen_speed = pcie_gen_speed;
return 0;
}
EXPORT_SYMBOL(cnss_set_pcie_gen_speed);
static bool cnss_is_aux_support_enabled(struct cnss_plat_data *plat_priv)
{
switch (plat_priv->device_id) {
case PEACH_DEVICE_ID:
if (!plat_priv->fw_aux_uc_support) {
cnss_pr_dbg("FW does not support aux uc capability\n");
return false;
}
break;
default:
cnss_pr_dbg("Host does not support aux uc capability\n");
return false;
}
return true;
}