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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
|
/*
* Copyright (c) 2014-2017 The Linux Foundation. All rights reserved.
*
* Previously licensed under the ISC license by Qualcomm Atheros, Inc.
*
*
* Permission to use, copy, modify, and/or distribute this software for
* any purpose with or without fee is hereby granted, provided that the
* above copyright notice and this permission notice appear in all
* copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
* WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
* AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
/*
* This file was originally distributed by Qualcomm Atheros, Inc.
* under proprietary terms before Copyright ownership was assigned
* to the Linux Foundation.
*/
/**
* DOC: qdf_trace
* QCA driver framework (QDF) trace APIs
* Trace, logging, and debugging definitions and APIs
*/
/* Include Files */
#include <qdf_trace.h>
#include <wlan_logging_sock_svc.h>
#include "qdf_time.h"
#include "qdf_mc_timer.h"
#include <qdf_module.h>
/* Preprocessor definitions and constants */
#define QDF_TRACE_BUFFER_SIZE (512)
enum qdf_timestamp_unit qdf_log_timestamp_type = QDF_LOG_TIMESTAMP_UNIT;
/* macro to map qdf trace levels into the bitmask */
#define QDF_TRACE_LEVEL_TO_MODULE_BITMASK(_level) ((1 << (_level)))
/**
* typedef struct module_trace_info - Trace level for a module, as a bitmask.
* The bits in this mask are ordered by QDF_TRACE_LEVEL. For example,
* each bit represents one of the bits in QDF_TRACE_LEVEL that may be turned
* on to have traces at that level logged, i.e. if QDF_TRACE_LEVEL_ERROR is
* == 2, then if bit 2 (low order) is turned ON, then ERROR traces will be
* printed to the trace log. Note that all bits turned OFF means no traces
* @module_trace_level: trace level
* @module_name_str: 3 character string name for the module
*/
typedef struct {
uint16_t module_trace_level;
unsigned char module_name_str[4];
} module_trace_info;
#define QDF_DEFAULT_TRACE_LEVEL \
((1 << QDF_TRACE_LEVEL_FATAL) | (1 << QDF_TRACE_LEVEL_ERROR))
/* Array of static data that contains all of the per module trace
* information. This includes the trace level for the module and
* the 3 character 'name' of the module for marking the trace logs
*/
module_trace_info g_qdf_trace_info[QDF_MODULE_ID_MAX] = {
[QDF_MODULE_ID_TLSHIM] = {QDF_DEFAULT_TRACE_LEVEL, "DP"},
[QDF_MODULE_ID_WMI] = {QDF_DEFAULT_TRACE_LEVEL, "WMI"},
[QDF_MODULE_ID_HDD] = {QDF_DEFAULT_TRACE_LEVEL, "HDD"},
[QDF_MODULE_ID_SME] = {QDF_DEFAULT_TRACE_LEVEL, "SME"},
[QDF_MODULE_ID_PE] = {QDF_DEFAULT_TRACE_LEVEL, "PE "},
[QDF_MODULE_ID_WMA] = {QDF_DEFAULT_TRACE_LEVEL, "WMA"},
[QDF_MODULE_ID_SYS] = {QDF_DEFAULT_TRACE_LEVEL, "SYS"},
[QDF_MODULE_ID_QDF] = {QDF_DEFAULT_TRACE_LEVEL, "QDF"},
[QDF_MODULE_ID_SAP] = {QDF_DEFAULT_TRACE_LEVEL, "SAP"},
[QDF_MODULE_ID_HDD_SOFTAP] = {QDF_DEFAULT_TRACE_LEVEL, "HSP"},
[QDF_MODULE_ID_HDD_DATA] = {QDF_DEFAULT_TRACE_LEVEL, "HDP"},
[QDF_MODULE_ID_HDD_SAP_DATA] = {QDF_DEFAULT_TRACE_LEVEL, "SDP"},
[QDF_MODULE_ID_BMI] = {QDF_DEFAULT_TRACE_LEVEL, "BMI"},
[QDF_MODULE_ID_HIF] = {QDF_DEFAULT_TRACE_LEVEL, "HIF"},
[QDF_MODULE_ID_TXRX] = {QDF_DEFAULT_TRACE_LEVEL, "TRX"},
[QDF_MODULE_ID_HTT] = {QDF_DEFAULT_TRACE_LEVEL, "HTT"},
};
/* Static and Global variables */
static spinlock_t ltrace_lock;
static qdf_trace_record_t g_qdf_trace_tbl[MAX_QDF_TRACE_RECORDS];
/* global qdf trace data */
static t_qdf_trace_data g_qdf_trace_data;
/*
* all the call back functions for dumping MTRACE messages from ring buffer
* are stored in qdf_trace_cb_table,these callbacks are initialized during init
* only so, we will make a copy of these call back functions and maintain in to
* qdf_trace_restore_cb_table. Incase if we make modifications to
* qdf_trace_cb_table, we can certainly retrieve all the call back functions
* back from Restore Table
*/
static tp_qdf_trace_cb qdf_trace_cb_table[QDF_MODULE_ID_MAX];
static tp_qdf_trace_cb qdf_trace_restore_cb_table[QDF_MODULE_ID_MAX];
static tp_qdf_state_info_cb qdf_state_info_table[QDF_MODULE_ID_MAX];
#ifdef FEATURE_DP_TRACE
/* Static and Global variables */
static spinlock_t l_dp_trace_lock;
static struct qdf_dp_trace_record_s
g_qdf_dp_trace_tbl[MAX_QDF_DP_TRACE_RECORDS];
/*
* all the options to configure/control DP trace are
* defined in this structure
*/
static struct s_qdf_dp_trace_data g_qdf_dp_trace_data;
/*
* all the call back functions for dumping DPTRACE messages from ring buffer
* are stored in qdf_dp_trace_cb_table, callbacks are initialized during init
*/
static tp_qdf_dp_trace_cb qdf_dp_trace_cb_table[QDF_DP_TRACE_MAX+1];
#endif
/**
* qdf_trace_set_level() - Set the trace level for a particular module
* @module: Module id
* @level : trace level
*
* Trace level is a member of the QDF_TRACE_LEVEL enumeration indicating
* the severity of the condition causing the trace message to be issued.
* More severe conditions are more likely to be logged.
*
* This is an external API that allows trace levels to be set for each module.
*
* Return: None
*/
void qdf_trace_set_level(QDF_MODULE_ID module, QDF_TRACE_LEVEL level)
{
/* make sure the caller is passing in a valid LEVEL */
if (level >= QDF_TRACE_LEVEL_MAX) {
pr_err("%s: Invalid trace level %d passed in!\n", __func__,
level);
return;
}
/* Treat 'none' differently. NONE means we have to run off all
* the bits in the bit mask so none of the traces appear. Anything
* other than 'none' means we need to turn ON a bit in the bitmask
*/
if (QDF_TRACE_LEVEL_NONE == level)
g_qdf_trace_info[module].module_trace_level =
QDF_TRACE_LEVEL_NONE;
else
/* set the desired bit in the bit mask for the module trace
* level */
g_qdf_trace_info[module].module_trace_level |=
QDF_TRACE_LEVEL_TO_MODULE_BITMASK(level);
}
qdf_export_symbol(qdf_trace_set_level);
/**
* qdf_trace_set_module_trace_level() - Set module trace level
* @module: Module id
* @level: Trace level for a module, as a bitmask as per 'module_trace_info'
*
* Sets the module trace level where the trace level is given as a bit mask
*
* Return: None
*/
void qdf_trace_set_module_trace_level(QDF_MODULE_ID module, uint32_t level)
{
if (module < 0 || module >= QDF_MODULE_ID_MAX) {
pr_err("%s: Invalid module id %d passed\n", __func__, module);
return;
}
g_qdf_trace_info[module].module_trace_level = level;
}
qdf_export_symbol(qdf_trace_set_module_trace_level);
/**
* qdf_trace_set_value() - Set module trace value
* @module: Module id
* @level: Trace level for a module, as a bitmask as per 'module_trace_info'
* @on: set/clear the desired bit in the bit mask
*
* Return: None
*/
void qdf_trace_set_value(QDF_MODULE_ID module, QDF_TRACE_LEVEL level,
uint8_t on)
{
/* make sure the caller is passing in a valid LEVEL */
if (level < 0 || level >= QDF_TRACE_LEVEL_MAX) {
pr_err("%s: Invalid trace level %d passed in!\n", __func__,
level);
return;
}
/* make sure the caller is passing in a valid module */
if (module < 0 || module >= QDF_MODULE_ID_MAX) {
pr_err("%s: Invalid module id %d passed in!\n", __func__,
module);
return;
}
/* Treat 'none' differently. NONE means we have to turn off all
the bits in the bit mask so none of the traces appear */
if (QDF_TRACE_LEVEL_NONE == level) {
g_qdf_trace_info[module].module_trace_level =
QDF_TRACE_LEVEL_NONE;
}
/* Treat 'All' differently. All means we have to turn on all
the bits in the bit mask so all of the traces appear */
else if (QDF_TRACE_LEVEL_ALL == level) {
g_qdf_trace_info[module].module_trace_level = 0xFFFF;
} else {
if (on)
/* set the desired bit in the bit mask for the module
trace level */
g_qdf_trace_info[module].module_trace_level |=
QDF_TRACE_LEVEL_TO_MODULE_BITMASK(level);
else
/* clear the desired bit in the bit mask for the module
trace level */
g_qdf_trace_info[module].module_trace_level &=
~(QDF_TRACE_LEVEL_TO_MODULE_BITMASK(level));
}
}
qdf_export_symbol(qdf_trace_set_value);
/**
* qdf_trace_get_level() - get the trace level
* @module: module Id
* @level: trace level
*
* This is an external API that returns a bool value to signify if a
* particular trace level is set for the specified module.
* A member of the QDF_TRACE_LEVEL enumeration indicating the severity
* of the condition causing the trace message to be issued.
*
* Note that individual trace levels are the only valid values
* for this API. QDF_TRACE_LEVEL_NONE and QDF_TRACE_LEVEL_ALL
* are not valid input and will return false
*
* Return:
* false - the specified trace level for the specified module is OFF
* true - the specified trace level for the specified module is ON
*/
bool qdf_trace_get_level(QDF_MODULE_ID module, QDF_TRACE_LEVEL level)
{
bool trace_on = false;
if ((QDF_TRACE_LEVEL_NONE == level) ||
(QDF_TRACE_LEVEL_ALL == level) || (level >= QDF_TRACE_LEVEL_MAX)) {
trace_on = false;
} else {
trace_on = (level & g_qdf_trace_info[module].module_trace_level)
? true : false;
}
return trace_on;
}
qdf_export_symbol(qdf_trace_get_level);
/**
* qdf_snprintf() - wrapper function to snprintf
* @str_buffer: string Buffer
* @size: defines the size of the data record
* @str_format: Format string in which the message to be logged. This format
* string contains printf-like replacement parameters, which follow
* this parameter in the variable argument list.
*
* Return: None
*/
void qdf_snprintf(char *str_buffer, unsigned int size, char *str_format, ...)
{
va_list val;
va_start(val, str_format);
snprintf(str_buffer, size, str_format, val);
va_end(val);
}
qdf_export_symbol(qdf_snprintf);
#ifdef QDF_ENABLE_TRACING
/**
* qdf_trace_msg() - externally called trace function
* @module: Module identifier a member of the QDF_MODULE_ID
* enumeration that identifies the module issuing the trace message.
* @level: Trace level a member of the QDF_TRACE_LEVEL enumeration
* indicating the severity of the condition causing the trace message
* to be issued. More severe conditions are more likely to be logged.
* @str_format: Format string in which the message to be logged. This format
* string contains printf-like replacement parameters, which follow
* this parameter in the variable argument list.
*
* Checks the level of severity and accordingly prints the trace messages
*
* Return: None
*/
void qdf_trace_msg(QDF_MODULE_ID module, QDF_TRACE_LEVEL level,
char *str_format, ...)
{
char str_buffer[QDF_TRACE_BUFFER_SIZE];
int n;
/* Print the trace message when the desired level bit is set in
the module tracel level mask */
if (g_qdf_trace_info[module].module_trace_level &
QDF_TRACE_LEVEL_TO_MODULE_BITMASK(level)) {
/* the trace level strings in an array. these are ordered in
* the same order as the trace levels are defined in the enum
* (see QDF_TRACE_LEVEL) so we can index into this array with
* the level and get the right string. The qdf trace levels
* are... none, Fatal, Error, Warning, Info, info_high, info_med,
* info_low, Debug
*/
static const char *TRACE_LEVEL_STR[] = { " ", "F ", "E ", "W ",
"I ", "IH", "IM", "IL", "D" };
va_list val;
va_start(val, str_format);
/* print the prefix string into the string buffer... */
n = snprintf(str_buffer, QDF_TRACE_BUFFER_SIZE,
"wlan: [%d:%2s:%3s] ",
in_interrupt() ? 0 : current->pid,
(char *)TRACE_LEVEL_STR[level],
(char *)g_qdf_trace_info[module].module_name_str);
/* print the formatted log message after the prefix string */
if ((n >= 0) && (n < QDF_TRACE_BUFFER_SIZE)) {
vsnprintf(str_buffer + n, QDF_TRACE_BUFFER_SIZE - n,
str_format, val);
#if defined(WLAN_LOGGING_SOCK_SVC_ENABLE)
wlan_log_to_user(level, (char *)str_buffer,
strlen(str_buffer));
#else
pr_err("%s\n", str_buffer);
#endif
}
va_end(val);
}
}
qdf_export_symbol(qdf_trace_msg);
/**
* qdf_trace_display() - Display trace
*
* Return: None
*/
void qdf_trace_display(void)
{
QDF_MODULE_ID module_id;
pr_err
(" 1)FATAL 2)ERROR 3)WARN 4)INFO 5)INFO_H 6)INFO_M 7)INFO_L 8)DEBUG\n");
for (module_id = 0; module_id < QDF_MODULE_ID_MAX; ++module_id) {
pr_err
("%2d)%s %s %s %s %s %s %s %s %s\n",
(int)module_id, g_qdf_trace_info[module_id].module_name_str,
(g_qdf_trace_info[module_id].
module_trace_level & (1 << QDF_TRACE_LEVEL_FATAL)) ? "X" :
" ",
(g_qdf_trace_info[module_id].
module_trace_level & (1 << QDF_TRACE_LEVEL_ERROR)) ? "X" :
" ",
(g_qdf_trace_info[module_id].
module_trace_level & (1 << QDF_TRACE_LEVEL_WARN)) ? "X" :
" ",
(g_qdf_trace_info[module_id].
module_trace_level & (1 << QDF_TRACE_LEVEL_INFO)) ? "X" :
" ",
(g_qdf_trace_info[module_id].
module_trace_level & (1 << QDF_TRACE_LEVEL_INFO_HIGH)) ? "X"
: " ",
(g_qdf_trace_info[module_id].
module_trace_level & (1 << QDF_TRACE_LEVEL_INFO_MED)) ? "X"
: " ",
(g_qdf_trace_info[module_id].
module_trace_level & (1 << QDF_TRACE_LEVEL_INFO_LOW)) ? "X"
: " ",
(g_qdf_trace_info[module_id].
module_trace_level & (1 << QDF_TRACE_LEVEL_DEBUG)) ? "X" :
" ");
}
}
qdf_export_symbol(qdf_trace_display);
#define ROW_SIZE 16
/* Buffer size = data bytes(2 hex chars plus space) + NULL */
#define BUFFER_SIZE ((ROW_SIZE * 3) + 1)
/**
* qdf_trace_hex_dump() - externally called hex dump function
* @module: Module identifier a member of the QDF_MODULE_ID enumeration that
* identifies the module issuing the trace message.
* @level: Trace level a member of the QDF_TRACE_LEVEL enumeration indicating
* the severity of the condition causing the trace message to be
* issued. More severe conditions are more likely to be logged.
* @data: The base address of the buffer to be logged.
* @buf_len: The size of the buffer to be logged.
*
* Checks the level of severity and accordingly prints the trace messages
*
* Return: None
*/
void qdf_trace_hex_dump(QDF_MODULE_ID module, QDF_TRACE_LEVEL level,
void *data, int buf_len)
{
const u8 *ptr = data;
int i, linelen, remaining = buf_len;
unsigned char linebuf[BUFFER_SIZE];
if (!(g_qdf_trace_info[module].module_trace_level &
QDF_TRACE_LEVEL_TO_MODULE_BITMASK(level)))
return;
for (i = 0; i < buf_len; i += ROW_SIZE) {
linelen = min(remaining, ROW_SIZE);
remaining -= ROW_SIZE;
hex_dump_to_buffer(ptr + i, linelen, ROW_SIZE, 1,
linebuf, sizeof(linebuf), false);
qdf_trace_msg(module, level, "%.8x: %s", i, linebuf);
}
}
qdf_export_symbol(qdf_trace_hex_dump);
#endif
/**
* qdf_trace_enable() - Enable MTRACE for specific modules
* @bitmask_of_module_id: Bitmask according to enum of the modules.
* 32[dec] = 0010 0000 [bin] <enum of HDD is 5>
* 64[dec] = 0100 0000 [bin] <enum of SME is 6>
* 128[dec] = 1000 0000 [bin] <enum of PE is 7>
* @enable: can be true or false true implies enabling MTRACE false implies
* disabling MTRACE.
*
* Enable MTRACE for specific modules whose bits are set in bitmask and enable
* is true. if enable is false it disables MTRACE for that module. set the
* bitmask according to enum value of the modules.
* This functions will be called when you issue ioctl as mentioned following
* [iwpriv wlan0 setdumplog <value> <enable>].
* <value> - Decimal number, i.e. 64 decimal value shows only SME module,
* 128 decimal value shows only PE module, 192 decimal value shows PE and SME.
*
* Return: None
*/
void qdf_trace_enable(uint32_t bitmask_of_module_id, uint8_t enable)
{
int i;
if (bitmask_of_module_id) {
for (i = 0; i < QDF_MODULE_ID_MAX; i++) {
if (((bitmask_of_module_id >> i) & 1)) {
if (enable) {
if (NULL !=
qdf_trace_restore_cb_table[i]) {
qdf_trace_cb_table[i] =
qdf_trace_restore_cb_table[i];
}
} else {
qdf_trace_restore_cb_table[i] =
qdf_trace_cb_table[i];
qdf_trace_cb_table[i] = NULL;
}
}
}
} else {
if (enable) {
for (i = 0; i < QDF_MODULE_ID_MAX; i++) {
if (NULL != qdf_trace_restore_cb_table[i]) {
qdf_trace_cb_table[i] =
qdf_trace_restore_cb_table[i];
}
}
} else {
for (i = 0; i < QDF_MODULE_ID_MAX; i++) {
qdf_trace_restore_cb_table[i] =
qdf_trace_cb_table[i];
qdf_trace_cb_table[i] = NULL;
}
}
}
}
qdf_export_symbol(qdf_trace_enable);
/**
* qdf_trace_init() - initializes qdf trace structures and variables
*
* Called immediately after cds_preopen, so that we can start recording HDD
* events ASAP.
*
* Return: None
*/
void qdf_trace_init(void)
{
uint8_t i;
g_qdf_trace_data.head = INVALID_QDF_TRACE_ADDR;
g_qdf_trace_data.tail = INVALID_QDF_TRACE_ADDR;
g_qdf_trace_data.num = 0;
g_qdf_trace_data.enable = true;
g_qdf_trace_data.dump_count = DEFAULT_QDF_TRACE_DUMP_COUNT;
g_qdf_trace_data.num_since_last_dump = 0;
for (i = 0; i < QDF_MODULE_ID_MAX; i++) {
qdf_trace_cb_table[i] = NULL;
qdf_trace_restore_cb_table[i] = NULL;
}
}
qdf_export_symbol(qdf_trace_init);
/**
* qdf_trace() - puts the messages in to ring-buffer
* @module: Enum of module, basically module id.
* @param: Code to be recorded
* @session: Session ID of the log
* @data: Actual message contents
*
* This function will be called from each module who wants record the messages
* in circular queue. Before calling this functions make sure you have
* registered your module with qdf through qdf_trace_register function.
*
* Return: None
*/
void qdf_trace(uint8_t module, uint8_t code, uint16_t session, uint32_t data)
{
tp_qdf_trace_record rec = NULL;
unsigned long flags;
char time[18];
if (!g_qdf_trace_data.enable)
return;
/* if module is not registered, don't record for that module */
if (NULL == qdf_trace_cb_table[module])
return;
qdf_get_time_of_the_day_in_hr_min_sec_usec(time, sizeof(time));
/* Aquire the lock so that only one thread at a time can fill the ring
* buffer
*/
spin_lock_irqsave(<race_lock, flags);
g_qdf_trace_data.num++;
if (g_qdf_trace_data.num > MAX_QDF_TRACE_RECORDS)
g_qdf_trace_data.num = MAX_QDF_TRACE_RECORDS;
if (INVALID_QDF_TRACE_ADDR == g_qdf_trace_data.head) {
/* first record */
g_qdf_trace_data.head = 0;
g_qdf_trace_data.tail = 0;
} else {
/* queue is not empty */
uint32_t tail = g_qdf_trace_data.tail + 1;
if (MAX_QDF_TRACE_RECORDS == tail)
tail = 0;
if (g_qdf_trace_data.head == tail) {
/* full */
if (MAX_QDF_TRACE_RECORDS == ++g_qdf_trace_data.head)
g_qdf_trace_data.head = 0;
}
g_qdf_trace_data.tail = tail;
}
rec = &g_qdf_trace_tbl[g_qdf_trace_data.tail];
rec->code = code;
rec->session = session;
rec->data = data;
rec->qtime = qdf_get_log_timestamp();
scnprintf(rec->time, sizeof(rec->time), "%s", time);
rec->module = module;
rec->pid = (in_interrupt() ? 0 : current->pid);
g_qdf_trace_data.num_since_last_dump++;
spin_unlock_irqrestore(<race_lock, flags);
}
qdf_export_symbol(qdf_trace);
/**
* qdf_trace_spin_lock_init() - initializes the lock variable before use
*
* This function will be called from cds_alloc_global_context, we will have lock
* available to use ASAP
*
* Return: None
*/
QDF_STATUS qdf_trace_spin_lock_init(void)
{
spin_lock_init(<race_lock);
return QDF_STATUS_SUCCESS;
}
qdf_export_symbol(qdf_trace_spin_lock_init);
/**
* qdf_trace_register() - registers the call back functions
* @module_iD: enum value of module
* @qdf_trace_callback: call back functions to display the messages in
* particular format.
*
* Registers the call back functions to display the messages in particular
* format mentioned in these call back functions. This functions should be
* called by interested module in their init part as we will be ready to
* register as soon as modules are up.
*
* Return: None
*/
void qdf_trace_register(QDF_MODULE_ID module_iD,
tp_qdf_trace_cb qdf_trace_callback)
{
qdf_trace_cb_table[module_iD] = qdf_trace_callback;
}
qdf_export_symbol(qdf_trace_register);
/**
* qdf_trace_dump_all() - Dump data from ring buffer via call back functions
* registered with QDF
* @p_mac: Context of particular module
* @code: Reason code
* @session: Session id of log
* @count: Number of lines to dump starting from tail to head
*
* This function will be called up on issueing ioctl call as mentioned following
* [iwpriv wlan0 dumplog 0 0 <n> <bitmask_of_module>]
*
* <n> - number lines to dump starting from tail to head.
*
* <bitmask_of_module> - if anybody wants to know how many messages were
* recorded for particular module/s mentioned by setbit in bitmask from last
* <n> messages. It is optional, if you don't provide then it will dump
* everything from buffer.
*
* Return: None
*/
void qdf_trace_dump_all(void *p_mac, uint8_t code, uint8_t session,
uint32_t count, uint32_t bitmask_of_module)
{
qdf_trace_record_t p_record;
int32_t i, tail;
if (!g_qdf_trace_data.enable) {
QDF_TRACE(QDF_MODULE_ID_SYS,
QDF_TRACE_LEVEL_ERROR, "Tracing Disabled");
return;
}
QDF_TRACE(QDF_MODULE_ID_SYS, QDF_TRACE_LEVEL_INFO,
"Total Records: %d, Head: %d, Tail: %d",
g_qdf_trace_data.num, g_qdf_trace_data.head,
g_qdf_trace_data.tail);
/* aquire the lock so that only one thread at a time can read
* the ring buffer
*/
spin_lock(<race_lock);
if (g_qdf_trace_data.head != INVALID_QDF_TRACE_ADDR) {
i = g_qdf_trace_data.head;
tail = g_qdf_trace_data.tail;
if (count) {
if (count > g_qdf_trace_data.num)
count = g_qdf_trace_data.num;
if (tail >= (count - 1))
i = tail - count + 1;
else if (count != MAX_QDF_TRACE_RECORDS)
i = MAX_QDF_TRACE_RECORDS - ((count - 1) -
tail);
}
p_record = g_qdf_trace_tbl[i];
/* right now we are not using num_since_last_dump member but
* in future we might re-visit and use this member to track
* how many latest messages got added while we were dumping
* from ring buffer
*/
g_qdf_trace_data.num_since_last_dump = 0;
spin_unlock(<race_lock);
for (;; ) {
if ((code == 0 || (code == p_record.code)) &&
(qdf_trace_cb_table[p_record.module] != NULL)) {
if (0 == bitmask_of_module) {
qdf_trace_cb_table[p_record.
module] (p_mac,
&p_record,
(uint16_t)
i);
} else {
if (bitmask_of_module &
(1 << p_record.module)) {
qdf_trace_cb_table[p_record.
module]
(p_mac, &p_record,
(uint16_t) i);
}
}
}
if (i == tail)
break;
i += 1;
spin_lock(<race_lock);
if (MAX_QDF_TRACE_RECORDS == i) {
i = 0;
p_record = g_qdf_trace_tbl[0];
} else {
p_record = g_qdf_trace_tbl[i];
}
spin_unlock(<race_lock);
}
} else {
spin_unlock(<race_lock);
}
}
qdf_export_symbol(qdf_trace_dump_all);
/**
* qdf_register_debugcb_init() - initializes debug callbacks
* to NULL
*
* Return: None
*/
void qdf_register_debugcb_init(void)
{
uint8_t i;
for (i = 0; i < QDF_MODULE_ID_MAX; i++)
qdf_state_info_table[i] = NULL;
}
qdf_export_symbol(qdf_register_debugcb_init);
/**
* qdf_register_debug_callback() - stores callback handlers to print
* state information
* @module_id: module id of layer
* @qdf_state_infocb: callback to be registered
*
* This function is used to store callback handlers to print
* state information
*
* Return: None
*/
void qdf_register_debug_callback(QDF_MODULE_ID module_id,
tp_qdf_state_info_cb qdf_state_infocb)
{
qdf_state_info_table[module_id] = qdf_state_infocb;
}
qdf_export_symbol(qdf_register_debug_callback);
/**
* qdf_state_info_dump_all() - it invokes callback of layer which registered
* its callback to print its state information.
* @buf: buffer pointer to be passed
* @size: size of buffer to be filled
* @driver_dump_size: actual size of buffer used
*
* Return: QDF_STATUS_SUCCESS on success
*/
QDF_STATUS qdf_state_info_dump_all(char *buf, uint16_t size,
uint16_t *driver_dump_size)
{
uint8_t module, ret = QDF_STATUS_SUCCESS;
uint16_t buf_len = size;
char *buf_ptr = buf;
for (module = 0; module < QDF_MODULE_ID_MAX; module++) {
if (NULL != qdf_state_info_table[module]) {
qdf_state_info_table[module](&buf_ptr, &buf_len);
if (!buf_len) {
ret = QDF_STATUS_E_NOMEM;
break;
}
}
}
*driver_dump_size = size - buf_len;
return ret;
}
qdf_export_symbol(qdf_state_info_dump_all);
#ifdef FEATURE_DP_TRACE
static void qdf_dp_unused(struct qdf_dp_trace_record_s *record,
uint16_t index)
{
qdf_print("%s: QDF_DP_TRACE_MAX event should not be generated",
__func__);
}
/**
* qdf_dp_trace_init() - enables the DP trace
* Called during driver load and it enables DP trace
*
* Return: None
*/
void qdf_dp_trace_init(void)
{
uint8_t i;
qdf_dp_trace_spin_lock_init();
g_qdf_dp_trace_data.head = INVALID_QDF_DP_TRACE_ADDR;
g_qdf_dp_trace_data.tail = INVALID_QDF_DP_TRACE_ADDR;
g_qdf_dp_trace_data.num = 0;
g_qdf_dp_trace_data.proto_bitmap = QDF_NBUF_PKT_TRAC_TYPE_EAPOL |
QDF_NBUF_PKT_TRAC_TYPE_DHCP |
QDF_NBUF_PKT_TRAC_TYPE_MGMT_ACTION |
QDF_NBUF_PKT_TRAC_TYPE_ARP;
g_qdf_dp_trace_data.no_of_record = 0;
g_qdf_dp_trace_data.verbosity = QDF_DP_TRACE_VERBOSITY_HIGH;
g_qdf_dp_trace_data.enable = true;
g_qdf_dp_trace_data.tx_count = 0;
g_qdf_dp_trace_data.rx_count = 0;
g_qdf_dp_trace_data.live_mode = 0;
for (i = 0; i < ARRAY_SIZE(qdf_dp_trace_cb_table); i++)
qdf_dp_trace_cb_table[i] = qdf_dp_display_record;
qdf_dp_trace_cb_table[QDF_DP_TRACE_TXRX_PACKET_PTR_RECORD] =
qdf_dp_trace_cb_table[QDF_DP_TRACE_TXRX_FAST_PACKET_PTR_RECORD] =
qdf_dp_trace_cb_table[QDF_DP_TRACE_FREE_PACKET_PTR_RECORD] =
qdf_dp_display_ptr_record;
qdf_dp_trace_cb_table[QDF_DP_TRACE_EAPOL_PACKET_RECORD] =
qdf_dp_trace_cb_table[QDF_DP_TRACE_DHCP_PACKET_RECORD] =
qdf_dp_trace_cb_table[QDF_DP_TRACE_ARP_PACKET_RECORD] =
qdf_dp_display_proto_pkt;
qdf_dp_trace_cb_table[QDF_DP_TRACE_MGMT_PACKET_RECORD] =
qdf_dp_display_mgmt_pkt;
qdf_dp_trace_cb_table[QDF_DP_TRACE_EVENT_RECORD] =
qdf_dp_display_event_record;
qdf_dp_trace_cb_table[QDF_DP_TRACE_MAX] = qdf_dp_unused;
}
qdf_export_symbol(qdf_dp_trace_init);
/**
* qdf_dp_trace_set_value() - Configure the value to control DP trace
* @proto_bitmap: defines the protocol to be tracked
* @no_of_records: defines the nth packet which is traced
* @verbosity: defines the verbosity level
*
* Return: None
*/
void qdf_dp_trace_set_value(uint8_t proto_bitmap, uint8_t no_of_record,
uint8_t verbosity)
{
g_qdf_dp_trace_data.proto_bitmap = proto_bitmap;
g_qdf_dp_trace_data.no_of_record = no_of_record;
g_qdf_dp_trace_data.verbosity = verbosity;
return;
}
qdf_export_symbol(qdf_dp_trace_set_value);
/**
* qdf_dp_trace_enable_track() - enable the tracing for netbuf
* @code: defines the event
*
* In High verbosity all codes are logged.
* For Med/Low and Default case code which has
* less value than corresponding verbosity codes
* are logged.
*
* Return: true or false depends on whether tracing enabled
*/
static bool qdf_dp_trace_enable_track(enum QDF_DP_TRACE_ID code)
{
switch (g_qdf_dp_trace_data.verbosity) {
case QDF_DP_TRACE_VERBOSITY_HIGH:
return true;
case QDF_DP_TRACE_VERBOSITY_MEDIUM:
if (code <= QDF_DP_TRACE_MED_VERBOSITY)
return true;
return false;
case QDF_DP_TRACE_VERBOSITY_LOW:
if (code <= QDF_DP_TRACE_LOW_VERBOSITY)
return true;
return false;
case QDF_DP_TRACE_VERBOSITY_DEFAULT:
if (code <= QDF_DP_TRACE_DEFAULT_VERBOSITY)
return true;
return false;
default:
return false;
}
}
qdf_export_symbol(qdf_dp_trace_enable_track);
/**
* qdf_dp_get_proto_bitmap() - get dp trace proto bitmap
*
* Return: proto bitmap
*/
uint8_t qdf_dp_get_proto_bitmap(void)
{
if (g_qdf_dp_trace_data.enable)
return g_qdf_dp_trace_data.proto_bitmap;
else
return 0;
}
/**
* qdf_dp_trace_set_track() - Marks whether the packet needs to be traced
* @nbuf: defines the netbuf
* @dir: direction
*
* Return: None
*/
void qdf_dp_trace_set_track(qdf_nbuf_t nbuf, enum qdf_proto_dir dir)
{
uint32_t count = 0;
spin_lock_bh(&l_dp_trace_lock);
if (QDF_TX == dir)
count = ++g_qdf_dp_trace_data.tx_count;
else if (QDF_RX == dir)
count = ++g_qdf_dp_trace_data.rx_count;
if ((g_qdf_dp_trace_data.no_of_record != 0) &&
(count % g_qdf_dp_trace_data.no_of_record == 0)) {
if (QDF_TX == dir)
QDF_NBUF_CB_TX_DP_TRACE(nbuf) = 1;
else if (QDF_RX == dir)
QDF_NBUF_CB_RX_DP_TRACE(nbuf) = 1;
}
spin_unlock_bh(&l_dp_trace_lock);
return;
}
qdf_export_symbol(qdf_dp_trace_set_track);
#define DPTRACE_PRINT(args...) \
QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_INFO, ## args)
/**
* dump_hex_trace() - Display the data in buffer
* @str: string to prepend the hexdump with.
* @buf: buffer which contains data to be displayed
* @buf_len: defines the size of the data to be displayed
*
* Return: None
*/
static void dump_hex_trace(char *str, uint8_t *buf, uint8_t buf_len)
{
unsigned char linebuf[BUFFER_SIZE];
const u8 *ptr = buf;
int i, linelen, remaining = buf_len;
/* Dump the bytes in the last line */
for (i = 0; i < buf_len; i += ROW_SIZE) {
linelen = min(remaining, ROW_SIZE);
remaining -= ROW_SIZE;
hex_dump_to_buffer(ptr + i, linelen, ROW_SIZE, 1,
linebuf, sizeof(linebuf), false);
DPTRACE_PRINT("DPT: %s: %s", str, linebuf);
}
}
/**
* qdf_dp_code_to_string() - convert dptrace code to string
* @code: dptrace code
*
* Return: string version of code
*/
static
const char *qdf_dp_code_to_string(enum QDF_DP_TRACE_ID code)
{
switch (code) {
case QDF_DP_TRACE_DROP_PACKET_RECORD:
return "DROP:";
case QDF_DP_TRACE_EAPOL_PACKET_RECORD:
return "EAPOL:";
case QDF_DP_TRACE_DHCP_PACKET_RECORD:
return "DHCP:";
case QDF_DP_TRACE_ARP_PACKET_RECORD:
return "ARP:";
case QDF_DP_TRACE_MGMT_PACKET_RECORD:
return "MGMT:";
case QDF_DP_TRACE_EVENT_RECORD:
return "EVENT:";
case QDF_DP_TRACE_HDD_TX_PACKET_PTR_RECORD:
return "HDD: TX: PTR:";
case QDF_DP_TRACE_HDD_TX_PACKET_RECORD:
return "HDD: TX: DATA:";
case QDF_DP_TRACE_CE_PACKET_PTR_RECORD:
return "CE: TX: PTR:";
case QDF_DP_TRACE_CE_FAST_PACKET_PTR_RECORD:
return "CE: TX: FAST: PTR:";
case QDF_DP_TRACE_FREE_PACKET_PTR_RECORD:
return "FREE: TX: PTR:";
case QDF_DP_TRACE_RX_HTT_PACKET_PTR_RECORD:
return "HTT: RX: PTR:";
case QDF_DP_TRACE_RX_OFFLOAD_HTT_PACKET_PTR_RECORD:
return "HTT: RX: OF: PTR:";
case QDF_DP_TRACE_RX_HDD_PACKET_PTR_RECORD:
return "HDD: RX: PTR:";
case QDF_DP_TRACE_HDD_RX_PACKET_RECORD:
return "HDD: RX: DATA:";
case QDF_DP_TRACE_TXRX_QUEUE_PACKET_PTR_RECORD:
return "TXRX: TX: Q: PTR:";
case QDF_DP_TRACE_TXRX_PACKET_PTR_RECORD:
return "TXRX: TX: PTR:";
case QDF_DP_TRACE_TXRX_FAST_PACKET_PTR_RECORD:
return "TXRX: TX: FAST: PTR:";
case QDF_DP_TRACE_HTT_PACKET_PTR_RECORD:
return "HTT: TX: PTR:";
case QDF_DP_TRACE_HTC_PACKET_PTR_RECORD:
return "HTC: TX: PTR:";
case QDF_DP_TRACE_HIF_PACKET_PTR_RECORD:
return "HIF: TX: PTR:";
case QDF_DP_TRACE_RX_TXRX_PACKET_PTR_RECORD:
return "TXRX: RX: PTR:";
case QDF_DP_TRACE_HDD_TX_TIMEOUT:
return "HDD: STA: TO:";
case QDF_DP_TRACE_HDD_SOFTAP_TX_TIMEOUT:
return "HDD: SAP: TO:";
default:
return "Invalid";
}
}
/**
* qdf_dp_dir_to_str() - convert direction to string
* @dir: direction
*
* Return: string version of direction
*/
static const char *qdf_dp_dir_to_str(enum qdf_proto_dir dir)
{
switch (dir) {
case QDF_TX:
return " --> ";
case QDF_RX:
return " <-- ";
default:
return "invalid";
}
}
/**
* qdf_dp_type_to_str() - convert packet type to string
* @type: type
*
* Return: string version of packet type
*/
static const char *qdf_dp_type_to_str(enum qdf_proto_type type)
{
switch (type) {
case QDF_PROTO_TYPE_DHCP:
return "DHCP";
case QDF_PROTO_TYPE_EAPOL:
return "EAPOL";
case QDF_PROTO_TYPE_ARP:
return "ARP";
case QDF_PROTO_TYPE_MGMT:
return "MGMT";
case QDF_PROTO_TYPE_EVENT:
return "EVENT";
default:
return "invalid";
}
}
/**
* qdf_dp_subtype_to_str() - convert packet subtype to string
* @type: type
*
* Return: string version of packet subtype
*/
static const char *qdf_dp_subtype_to_str(enum qdf_proto_subtype subtype)
{
switch (subtype) {
case QDF_PROTO_EAPOL_M1:
return "M1";
case QDF_PROTO_EAPOL_M2:
return "M2";
case QDF_PROTO_EAPOL_M3:
return "M3";
case QDF_PROTO_EAPOL_M4:
return "M4";
case QDF_PROTO_DHCP_DISCOVER:
return "DISCOVER";
case QDF_PROTO_DHCP_REQUEST:
return "REQUEST";
case QDF_PROTO_DHCP_OFFER:
return "OFFER";
case QDF_PROTO_DHCP_ACK:
return "ACK";
case QDF_PROTO_DHCP_NACK:
return "NACK";
case QDF_PROTO_DHCP_RELEASE:
return "RELEASE";
case QDF_PROTO_DHCP_INFORM:
return "INFORM";
case QDF_PROTO_DHCP_DECLINE:
return "DECLINE";
case QDF_PROTO_ARP_REQ:
return "REQUEST";
case QDF_PROTO_ARP_RES:
return "RESPONSE";
case QDF_PROTO_MGMT_ASSOC:
return "ASSOC";
case QDF_PROTO_MGMT_DISASSOC:
return "DISASSOC";
case QDF_PROTO_MGMT_AUTH:
return "AUTH";
case QDF_PROTO_MGMT_DEAUTH:
return "DEAUTH";
case QDF_ROAM_SYNCH:
return "ROAM SYNCH";
case QDF_ROAM_COMPLETE:
return "ROAM COMPLETE";
case QDF_ROAM_EVENTID:
return "ROAM EVENTID";
default:
return "invalid";
}
}
/**
* qdf_dp_enable_check() - check if dptrace is enable or not
* @nbuf: nbuf
* @code: dptrace code
*
* Return: true/false
*/
static bool qdf_dp_enable_check(qdf_nbuf_t nbuf, enum QDF_DP_TRACE_ID code,
enum qdf_proto_dir dir)
{
/* Return when Dp trace is not enabled */
if (!g_qdf_dp_trace_data.enable)
return false;
if (qdf_dp_trace_enable_track(code) == false)
return false;
if ((nbuf) && ((QDF_NBUF_CB_TX_PACKET_TRACK(nbuf) !=
QDF_NBUF_TX_PKT_DATA_TRACK) ||
((dir == QDF_TX) && (QDF_NBUF_CB_TX_DP_TRACE(nbuf) == 0)) ||
((dir == QDF_RX) && (QDF_NBUF_CB_RX_DP_TRACE(nbuf) == 0))))
return false;
return true;
}
/**
* qdf_dp_add_record() - add dp trace record
* @code: dptrace code
* @data: data pointer
* @size: size of buffer
* @print: true to print it in kmsg
*
* Return: none
*/
static void qdf_dp_add_record(enum QDF_DP_TRACE_ID code,
uint8_t *data, uint8_t size, bool print)
{
struct qdf_dp_trace_record_s *rec = NULL;
int index;
spin_lock_bh(&l_dp_trace_lock);
g_qdf_dp_trace_data.num++;
if (g_qdf_dp_trace_data.num > MAX_QDF_DP_TRACE_RECORDS)
g_qdf_dp_trace_data.num = MAX_QDF_DP_TRACE_RECORDS;
if (INVALID_QDF_DP_TRACE_ADDR == g_qdf_dp_trace_data.head) {
/* first record */
g_qdf_dp_trace_data.head = 0;
g_qdf_dp_trace_data.tail = 0;
} else {
/* queue is not empty */
g_qdf_dp_trace_data.tail++;
if (MAX_QDF_DP_TRACE_RECORDS == g_qdf_dp_trace_data.tail)
g_qdf_dp_trace_data.tail = 0;
if (g_qdf_dp_trace_data.head == g_qdf_dp_trace_data.tail) {
/* full */
if (MAX_QDF_DP_TRACE_RECORDS ==
++g_qdf_dp_trace_data.head)
g_qdf_dp_trace_data.head = 0;
}
}
rec = &g_qdf_dp_trace_tbl[g_qdf_dp_trace_data.tail];
index = g_qdf_dp_trace_data.tail;
rec->code = code;
rec->size = 0;
if (data != NULL && size > 0) {
if (size > QDF_DP_TRACE_RECORD_SIZE)
size = QDF_DP_TRACE_RECORD_SIZE;
rec->size = size;
qdf_mem_copy(rec->data, data, size);
}
qdf_get_time_of_the_day_in_hr_min_sec_usec(rec->time,
sizeof(rec->time));
rec->pid = (in_interrupt() ? 0 : current->pid);
spin_unlock_bh(&l_dp_trace_lock);
if ((g_qdf_dp_trace_data.live_mode || (print == true)) &&
(rec->code < QDF_DP_TRACE_MAX))
qdf_dp_trace_cb_table[rec->code] (rec, index);
}
/**
* qdf_log_eapol_pkt() - log EAPOL packet
* @session_id: vdev_id
* @skb: skb pointer
* @dir: direction
*
* Return: true/false
*/
static bool qdf_log_eapol_pkt(uint8_t session_id, struct sk_buff *skb,
enum qdf_proto_dir dir)
{
enum qdf_proto_subtype subtype;
if ((qdf_dp_get_proto_bitmap() & QDF_NBUF_PKT_TRAC_TYPE_EAPOL) &&
((dir == QDF_TX && QDF_NBUF_CB_PACKET_TYPE_EAPOL ==
QDF_NBUF_CB_GET_PACKET_TYPE(skb)) ||
(dir == QDF_RX && qdf_nbuf_is_ipv4_eapol_pkt(skb) == true))) {
subtype = qdf_nbuf_get_eapol_subtype(skb);
DPTRACE(qdf_dp_trace_proto_pkt(QDF_DP_TRACE_EAPOL_PACKET_RECORD,
session_id, (skb->data + QDF_NBUF_SRC_MAC_OFFSET),
(skb->data + QDF_NBUF_DEST_MAC_OFFSET),
QDF_PROTO_TYPE_EAPOL, subtype, dir));
if (QDF_TX == dir)
QDF_NBUF_CB_TX_DP_TRACE(skb) = 1;
else if (QDF_RX == dir)
QDF_NBUF_CB_RX_DP_TRACE(skb) = 1;
QDF_NBUF_CB_DP_TRACE_PRINT(skb) = true;
return true;
}
return false;
}
/**
* qdf_log_dhcp_pkt() - log DHCP packet
* @session_id: vdev_id
* @skb: skb pointer
* @dir: direction
*
* Return: true/false
*/
static bool qdf_log_dhcp_pkt(uint8_t session_id, struct sk_buff *skb,
enum qdf_proto_dir dir)
{
enum qdf_proto_subtype subtype = QDF_PROTO_INVALID;
if ((qdf_dp_get_proto_bitmap() & QDF_NBUF_PKT_TRAC_TYPE_DHCP) &&
((dir == QDF_TX && QDF_NBUF_CB_PACKET_TYPE_DHCP ==
QDF_NBUF_CB_GET_PACKET_TYPE(skb)) ||
(dir == QDF_RX && qdf_nbuf_is_ipv4_dhcp_pkt(skb) == true))) {
subtype = qdf_nbuf_get_dhcp_subtype(skb);
DPTRACE(qdf_dp_trace_proto_pkt(QDF_DP_TRACE_DHCP_PACKET_RECORD,
session_id, (skb->data + QDF_NBUF_SRC_MAC_OFFSET),
(skb->data + QDF_NBUF_DEST_MAC_OFFSET),
QDF_PROTO_TYPE_DHCP, subtype, dir));
if (QDF_TX == dir)
QDF_NBUF_CB_TX_DP_TRACE(skb) = 1;
else if (QDF_RX == dir)
QDF_NBUF_CB_RX_DP_TRACE(skb) = 1;
QDF_NBUF_CB_DP_TRACE_PRINT(skb) = true;
return true;
}
return false;
}
/**
* qdf_log_arp_pkt() - log ARP packet
* @session_id: vdev_id
* @skb: skb pointer
* @dir: direction
*
* Return: true/false
*/
static bool qdf_log_arp_pkt(uint8_t session_id, struct sk_buff *skb,
enum qdf_proto_dir dir)
{
enum qdf_proto_subtype proto_subtype;
if ((qdf_dp_get_proto_bitmap() & QDF_NBUF_PKT_TRAC_TYPE_ARP) &&
((dir == QDF_TX && QDF_NBUF_CB_PACKET_TYPE_ARP ==
QDF_NBUF_CB_GET_PACKET_TYPE(skb)) ||
(dir == QDF_RX && qdf_nbuf_is_ipv4_arp_pkt(skb) == true))) {
proto_subtype = qdf_nbuf_get_arp_subtype(skb);
DPTRACE(qdf_dp_trace_proto_pkt(QDF_DP_TRACE_ARP_PACKET_RECORD,
session_id, (skb->data + QDF_NBUF_SRC_MAC_OFFSET),
(skb->data + QDF_NBUF_DEST_MAC_OFFSET),
QDF_PROTO_TYPE_ARP, proto_subtype, dir));
if (QDF_TX == dir)
QDF_NBUF_CB_TX_DP_TRACE(skb) = 1;
else if (QDF_RX == dir)
QDF_NBUF_CB_RX_DP_TRACE(skb) = 1;
QDF_NBUF_CB_DP_TRACE_PRINT(skb) = true;
return true;
}
return false;
}
/**
* qdf_dp_trace_log_pkt() - log packet type enabled through iwpriv
* @session_id: vdev_id
* @skb: skb pointer
* @dir: direction
*
* Return: none
*/
void qdf_dp_trace_log_pkt(uint8_t session_id, struct sk_buff *skb,
enum qdf_proto_dir dir)
{
if (qdf_dp_get_proto_bitmap()) {
if (qdf_log_arp_pkt(session_id,
skb, dir) == false) {
if (qdf_log_dhcp_pkt(session_id,
skb, dir) == false) {
if (qdf_log_eapol_pkt(session_id,
skb, dir) == false) {
return;
}
}
}
}
}
qdf_export_symbol(qdf_dp_trace_log_pkt);
/**
* qdf_dp_display_mgmt_pkt() - display proto packet
* @record: dptrace record
* @index: index
*
* Return: none
*/
void qdf_dp_display_mgmt_pkt(struct qdf_dp_trace_record_s *record,
uint16_t index)
{
struct qdf_dp_trace_mgmt_buf *buf =
(struct qdf_dp_trace_mgmt_buf *)record->data;
DPTRACE_PRINT("DPT: %04d: %s: %s vdev_id %d", index,
record->time, qdf_dp_code_to_string(record->code),
buf->vdev_id);
DPTRACE_PRINT("DPT: Type %s Subtype %s", qdf_dp_type_to_str(buf->type),
qdf_dp_subtype_to_str(buf->subtype));
}
qdf_export_symbol(qdf_dp_display_mgmt_pkt);
/**
* qdf_dp_trace_mgmt_pkt() - record mgmt packet
* @code: dptrace code
* @vdev_id: vdev id
* @type: proto type
* @subtype: proto subtype
*
* Return: none
*/
void qdf_dp_trace_mgmt_pkt(enum QDF_DP_TRACE_ID code, uint8_t vdev_id,
enum qdf_proto_type type, enum qdf_proto_subtype subtype)
{
struct qdf_dp_trace_mgmt_buf buf;
int buf_size = sizeof(struct qdf_dp_trace_mgmt_buf);
if (qdf_dp_enable_check(NULL, code, QDF_NA) == false)
return;
if (buf_size > QDF_DP_TRACE_RECORD_SIZE)
QDF_BUG(0);
buf.type = type;
buf.subtype = subtype;
buf.vdev_id = vdev_id;
qdf_dp_add_record(code, (uint8_t *)&buf, buf_size, true);
}
qdf_export_symbol(qdf_dp_trace_mgmt_pkt);
/**
* qdf_dp_display_event_record() - display event records
* @record: dptrace record
* @index: index
*
* Return: none
*/
void qdf_dp_display_event_record(struct qdf_dp_trace_record_s *record,
uint16_t index)
{
struct qdf_dp_trace_event_buf *buf =
(struct qdf_dp_trace_event_buf *)record->data;
DPTRACE_PRINT("DPT: %04d: %s: %s vdev_id %d", index,
record->time, qdf_dp_code_to_string(record->code),
buf->vdev_id);
DPTRACE_PRINT("DPT: Type %s Subtype %s", qdf_dp_type_to_str(buf->type),
qdf_dp_subtype_to_str(buf->subtype));
}
qdf_export_symbol(qdf_dp_display_event_record);
/**
* qdf_dp_trace_record_event() - record events
* @code: dptrace code
* @vdev_id: vdev id
* @type: proto type
* @subtype: proto subtype
*
* Return: none
*/
void qdf_dp_trace_record_event(enum QDF_DP_TRACE_ID code, uint8_t vdev_id,
enum qdf_proto_type type, enum qdf_proto_subtype subtype)
{
struct qdf_dp_trace_event_buf buf;
int buf_size = sizeof(struct qdf_dp_trace_event_buf);
if (qdf_dp_enable_check(NULL, code, QDF_NA) == false)
return;
if (buf_size > QDF_DP_TRACE_RECORD_SIZE)
QDF_BUG(0);
buf.type = type;
buf.subtype = subtype;
buf.vdev_id = vdev_id;
qdf_dp_add_record(code, (uint8_t *)&buf, buf_size, true);
}
qdf_export_symbol(qdf_dp_trace_record_event);
/**
* qdf_dp_display_proto_pkt() - display proto packet
* @record: dptrace record
* @index: index
*
* Return: none
*/
void qdf_dp_display_proto_pkt(struct qdf_dp_trace_record_s *record,
uint16_t index)
{
struct qdf_dp_trace_proto_buf *buf =
(struct qdf_dp_trace_proto_buf *)record->data;
DPTRACE_PRINT("DPT: %04d: %s: %s vdev_id %d", index,
record->time, qdf_dp_code_to_string(record->code),
buf->vdev_id);
DPTRACE_PRINT("DPT: SA: " QDF_MAC_ADDRESS_STR " %s DA: "
QDF_MAC_ADDRESS_STR " Type %s Subtype %s",
QDF_MAC_ADDR_ARRAY(buf->sa.bytes), qdf_dp_dir_to_str(buf->dir),
QDF_MAC_ADDR_ARRAY(buf->da.bytes),
qdf_dp_type_to_str(buf->type),
qdf_dp_subtype_to_str(buf->subtype));
}
qdf_export_symbol(qdf_dp_display_proto_pkt);
/**
* qdf_dp_trace_proto_pkt() - record proto packet
* @code: dptrace code
* @vdev_id: vdev id
* @sa: source mac address
* @da: destination mac address
* @type: proto type
* @subtype: proto subtype
* @dir: direction
*
* Return: none
*/
void qdf_dp_trace_proto_pkt(enum QDF_DP_TRACE_ID code, uint8_t vdev_id,
uint8_t *sa, uint8_t *da, enum qdf_proto_type type,
enum qdf_proto_subtype subtype, enum qdf_proto_dir dir)
{
struct qdf_dp_trace_proto_buf buf;
int buf_size = sizeof(struct qdf_dp_trace_ptr_buf);
if (qdf_dp_enable_check(NULL, code, dir) == false)
return;
if (buf_size > QDF_DP_TRACE_RECORD_SIZE)
QDF_BUG(0);
memcpy(&buf.sa, sa, QDF_NET_ETH_LEN);
memcpy(&buf.da, da, QDF_NET_ETH_LEN);
buf.dir = dir;
buf.type = type;
buf.subtype = subtype;
buf.vdev_id = vdev_id;
qdf_dp_add_record(code, (uint8_t *)&buf, buf_size, true);
}
qdf_export_symbol(qdf_dp_trace_proto_pkt);
/**
* qdf_dp_display_ptr_record() - display record
* @record: dptrace record
* @index: index
*
* Return: none
*/
void qdf_dp_display_ptr_record(struct qdf_dp_trace_record_s *record,
uint16_t index)
{
struct qdf_dp_trace_ptr_buf *buf =
(struct qdf_dp_trace_ptr_buf *)record->data;
if (record->code == QDF_DP_TRACE_FREE_PACKET_PTR_RECORD)
DPTRACE_PRINT("DPT: %04d: %s: %s msdu_id: %d, status: %d",
index, record->time,
qdf_dp_code_to_string(record->code), buf->msdu_id,
buf->status);
else
DPTRACE_PRINT("DPT: %04d: %s: %s msdu_id: %d, vdev_id: %d",
index,
record->time, qdf_dp_code_to_string(record->code),
buf->msdu_id, buf->status);
dump_hex_trace("cookie", (uint8_t *)&buf->cookie, sizeof(buf->cookie));
}
qdf_export_symbol(qdf_dp_display_ptr_record);
/**
* qdf_dp_trace_ptr() - record dptrace
* @code: dptrace code
* @data: data
* @size: size of data
* @msdu_id: msdu_id
* @status: return status
*
* Return: none
*/
void qdf_dp_trace_ptr(qdf_nbuf_t nbuf, enum QDF_DP_TRACE_ID code,
uint8_t *data, uint8_t size, uint16_t msdu_id, uint16_t status)
{
struct qdf_dp_trace_ptr_buf buf;
int buf_size = sizeof(struct qdf_dp_trace_ptr_buf);
if (qdf_dp_enable_check(nbuf, code, QDF_TX) == false)
return;
if (buf_size > QDF_DP_TRACE_RECORD_SIZE)
QDF_BUG(0);
qdf_mem_copy(&buf.cookie, data, size);
buf.msdu_id = msdu_id;
buf.status = status;
qdf_dp_add_record(code, (uint8_t *)&buf, buf_size,
QDF_NBUF_CB_DP_TRACE_PRINT(nbuf));
}
qdf_export_symbol(qdf_dp_trace_ptr);
/**
* qdf_dp_display_trace() - Displays a record in DP trace
* @pRecord : pointer to a record in DP trace
* @recIndex : record index
*
* Return: None
*/
void qdf_dp_display_record(struct qdf_dp_trace_record_s *pRecord,
uint16_t recIndex)
{
DPTRACE_PRINT("DPT: %04d: %s: %s", recIndex,
pRecord->time, qdf_dp_code_to_string(pRecord->code));
switch (pRecord->code) {
case QDF_DP_TRACE_HDD_TX_TIMEOUT:
DPTRACE_PRINT("DPT: HDD TX Timeout\n");
break;
case QDF_DP_TRACE_HDD_SOFTAP_TX_TIMEOUT:
DPTRACE_PRINT("DPT: HDD SoftAP TX Timeout\n");
break;
case QDF_DP_TRACE_HDD_TX_PACKET_RECORD:
case QDF_DP_TRACE_HDD_RX_PACKET_RECORD:
dump_hex_trace("DATA", pRecord->data, pRecord->size);
break;
default:
dump_hex_trace("cookie", pRecord->data, pRecord->size);
}
}
qdf_export_symbol(qdf_dp_display_record);
/**
* qdf_dp_trace() - Stores the data in buffer
* @nbuf : defines the netbuf
* @code : defines the event
* @data : defines the data to be stored
* @size : defines the size of the data record
*
* Return: None
*/
void qdf_dp_trace(qdf_nbuf_t nbuf, enum QDF_DP_TRACE_ID code,
uint8_t *data, uint8_t size, enum qdf_proto_dir dir)
{
if (qdf_dp_enable_check(nbuf, code, dir) == false)
return;
qdf_dp_add_record(code, data, size,
(nbuf != NULL) ? QDF_NBUF_CB_DP_TRACE_PRINT(nbuf) : false);
}
qdf_export_symbol(qdf_dp_trace);
/**
* qdf_dp_trace_spin_lock_init() - initializes the lock variable before use
* This function will be called from cds_alloc_global_context, we will have lock
* available to use ASAP
*
* Return: None
*/
void qdf_dp_trace_spin_lock_init(void)
{
spin_lock_init(&l_dp_trace_lock);
}
qdf_export_symbol(qdf_dp_trace_spin_lock_init);
/**
* qdf_dp_trace_enable_live_mode() - enable live mode for dptrace
*
* Return: none
*/
void qdf_dp_trace_enable_live_mode(void)
{
g_qdf_dp_trace_data.live_mode = 1;
}
qdf_export_symbol(qdf_dp_trace_enable_live_mode);
/**
* qdf_dp_trace_clear_buffer() - clear dp trace buffer
*
* Return: none
*/
void qdf_dp_trace_clear_buffer(void)
{
g_qdf_dp_trace_data.head = INVALID_QDF_DP_TRACE_ADDR;
g_qdf_dp_trace_data.tail = INVALID_QDF_DP_TRACE_ADDR;
g_qdf_dp_trace_data.num = 0;
g_qdf_dp_trace_data.proto_bitmap = QDF_NBUF_PKT_TRAC_TYPE_EAPOL |
QDF_NBUF_PKT_TRAC_TYPE_DHCP |
QDF_NBUF_PKT_TRAC_TYPE_MGMT_ACTION |
QDF_NBUF_PKT_TRAC_TYPE_ARP;
g_qdf_dp_trace_data.no_of_record = 0;
g_qdf_dp_trace_data.verbosity = QDF_DP_TRACE_VERBOSITY_HIGH;
g_qdf_dp_trace_data.enable = true;
g_qdf_dp_trace_data.tx_count = 0;
g_qdf_dp_trace_data.rx_count = 0;
g_qdf_dp_trace_data.live_mode = 0;
memset(g_qdf_dp_trace_tbl, 0,
MAX_QDF_DP_TRACE_RECORDS * sizeof(struct qdf_dp_trace_record_s));
}
qdf_export_symbol(qdf_dp_trace_clear_buffer);
/**
* qdf_dp_trace_dump_all() - Dump data from ring buffer via call back functions
* registered with QDF
* @code: Reason code
* @count: Number of lines to dump starting from tail to head
*
* Return: None
*/
void qdf_dp_trace_dump_all(uint32_t count)
{
struct qdf_dp_trace_record_s p_record;
int32_t i, tail;
if (!g_qdf_dp_trace_data.enable) {
QDF_TRACE(QDF_MODULE_ID_SYS,
QDF_TRACE_LEVEL_ERROR, "Tracing Disabled");
return;
}
QDF_TRACE(QDF_MODULE_ID_SYS, QDF_TRACE_LEVEL_ERROR,
"Total Records: %d, Head: %d, Tail: %d",
g_qdf_dp_trace_data.num, g_qdf_dp_trace_data.head,
g_qdf_dp_trace_data.tail);
/* aquire the lock so that only one thread at a time can read
* the ring buffer
*/
spin_lock_bh(&l_dp_trace_lock);
if (g_qdf_dp_trace_data.head != INVALID_QDF_DP_TRACE_ADDR) {
i = g_qdf_dp_trace_data.head;
tail = g_qdf_dp_trace_data.tail;
if (count) {
if (count > g_qdf_dp_trace_data.num)
count = g_qdf_dp_trace_data.num;
if (tail >= (count - 1))
i = tail - count + 1;
else if (count != MAX_QDF_DP_TRACE_RECORDS)
i = MAX_QDF_DP_TRACE_RECORDS - ((count - 1) -
tail);
}
p_record = g_qdf_dp_trace_tbl[i];
spin_unlock_bh(&l_dp_trace_lock);
for (;; ) {
qdf_dp_trace_cb_table[p_record.
code] (&p_record, (uint16_t)i);
if (i == tail)
break;
i += 1;
spin_lock_bh(&l_dp_trace_lock);
if (MAX_QDF_DP_TRACE_RECORDS == i)
i = 0;
p_record = g_qdf_dp_trace_tbl[i];
spin_unlock_bh(&l_dp_trace_lock);
}
} else {
spin_unlock_bh(&l_dp_trace_lock);
}
}
qdf_export_symbol(qdf_dp_trace_dump_all);
#endif
|