1 /* Copyright (c) 2015, The Linux Foundation. All rights reserved.
2  *
3  * Redistribution and use in source and binary forms, with or without
4  * modification, are permitted provided that the following conditions
5  * are met:
6  *  * Redistributions of source code must retain the above copyright
7  *    notice, this list of conditions and the following disclaimer.
8  *  * Redistributions in binary form must reproduce the above
9  *    copyright notice, this list of conditions and the following
10  *    disclaimer in the documentation and/or other materials provided
11  *    with the distribution.
12  *  * Neither the name of The Linux Foundation nor the names of its
13  *    contributors may be used to endorse or promote products derived
14  *    from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #ifndef __WIFI_HAL_WIFILOGGER_DIAG_H__
30 #define __WIFI_HAL_WIFILOGGER_DIAG_H__
31 
32 #include "common.h"
33 #include "wifi_hal.h"
34 #include "wifilogger_event_defs.h"
35 
36 #include <netlink/genl/genl.h>
37 #include <netlink/genl/family.h>
38 #include <netlink/genl/ctrl.h>
39 #include <linux/rtnetlink.h>
40 
41 #define ANI_NL_MSG_BASE     0x10    /* Some arbitrary base */
42 #define WIFI_HAL_USER_SOCK_PORT    646
43 #define WLAN_NL_MSG_CNSS_HOST_EVENT_LOG    17
44 #define ANI_NL_MSG_LOG_HOST_EVENT_LOG_TYPE 0x5050
45 #define ANI_NL_MSG_LOG_HOST_PRINT_TYPE 89
46 #define ANI_NL_MSG_LOG_FW_MSG_TYPE 92
47 
48 #define WLAN_PKT_LOG_STATS            0x18E0
49 #define FEATURE_NOT_SUPPORTED         0xFF
50 
51 #define DATA_STALL_OFFSET_REASON_CODE 256
52 /*
53  *  - verbose_level 0 corresponds to no collection
54  *  - verbose_level 1 correspond to normal log level, with minimal user impact.
55  *    this is the default value
56  *  - verbose_level 2 are enabled when user is lazily trying to reproduce a
57  problem, wifi performances and power
58  *     can be impacted but device should not otherwise be significantly impacted
59  *  - verbose_level 3+ are used when trying to actively debug a problem
60  */
61 
62 enum wifilogger_verbose_level {
63    VERBOSE_NO_COLLECTION,
64    VERBOSE_NORMAL_LOG,
65    VERBOSE_REPRO_PROBLEM,
66    VERBOSE_DEBUG_PROBLEM
67 };
68 
69 enum wifilogger_fw_diag_type {
70    DIAG_TYPE_FW_EVENT,     /* send fw event- to diag*/
71    DIAG_TYPE_FW_LOG,       /* send log event- to diag*/
72    DIAG_TYPE_FW_DEBUG_MSG, /* send dbg message- to diag*/
73    DIAG_TYPE_FW_MSG = 4,   /* send fw message- to diag*/
74 };
75 
76 enum wifilogger_host_diag_type {
77    DIAG_TYPE_HOST_LOG_MSGS=1,
78    DIAG_TYPE_HOST_EVENTS=2,
79 };
80 
81 enum wlan_diag_frame_type {
82     WLAN_DIAG_TYPE_CONFIG,
83     WLAN_DIAG_TYPE_EVENT, /* Diag Events */
84     WLAN_DIAG_TYPE_LOG, /* Diag Logs */
85     WLAN_DIAG_TYPE_MSG, /* F3 messages */
86     WLAN_DIAG_TYPE_LEGACY_MSG,
87     WLAN_DIAG_TYPE_EVENT_V2,
88     WLAN_DIAG_TYPE_LOG_V2,
89     WLAN_DIAG_TYPE_MSG_V2,
90 };
91 
92 typedef struct event_remap {
93     int q_event;
94     int g_event;
95 } event_remap_t;
96 
97 typedef struct {
98     u32 diag_type;
99     u32 timestamp;
100     u32 length;
101     u32 dropped;
102     /* max ATH6KL_FWLOG_PAYLOAD_SIZE bytes */
103     u_int8_t payload[0];
104 }__attribute__((packed)) dbglog_slot;
105 
106 typedef enum eAniNlModuleTypes {
107     ANI_NL_MSG_PUMAC = ANI_NL_MSG_BASE + 0x01,// PTT Socket App
108     ANI_NL_MSG_PTT = ANI_NL_MSG_BASE + 0x07,// Quarky GUI
109     WLAN_NL_MSG_BTC,
110     WLAN_NL_MSG_OEM,
111     ANI_NL_MSG_CNSS_DIAG = ANI_NL_MSG_BASE + 0x0B,
112     ANI_NL_MSG_LOG,
113     ANI_NL_MSG_MAX
114 } tAniNlModTypes;
115 
116 //All Netlink messages must contain this header
117 typedef struct sAniHdr {
118    unsigned short type;
119    unsigned short length;
120 } tAniHdr, tAniMsgHdr;
121 
122 typedef struct sAniCLDMsg {
123    int radio;          // unit number of the radio
124    tAniHdr wmsg;       // Airgo Message Header
125 } tAniCLDHdr;
126 
127 /*
128  * This msg hdr will always follow tAniHdr in all the messages exchanged
129  * between the Applications in userspace the Pseudo Driver, in either
130  * direction.
131  */
132 typedef struct sAniNlMsg {
133     struct  nlmsghdr nlh;   // Netlink Header
134     tAniCLDHdr clh;
135 } tAniNlHdr;
136 
137 typedef struct sAniAppRegReq {
138     tAniNlModTypes type;    /* The module id that the application is
139                     registering for */
140     int pid;            /* Pid returned in the nl_sockaddr structure
141                     in the call getsockbyname after the
142                     application opens and binds a netlink
143                     socket */
144 } tAniNlAppRegReq;
145 
146 typedef struct host_event_hdr_s
147 {
148     u16 event_id;
149     u16 length;
150 } host_event_hdr_t;
151 
152 typedef struct fw_event_hdr_s
153 {
154     u16 diag_type;
155     u16 length;
156 } fw_event_hdr_t;
157 
158 typedef struct
159 {
160     u32 reserved:24;
161     u32 diag_event_type:8;
162 }__attribute__((packed)) fw_diag_msg_fixed_hdr_t;
163 
164 typedef struct
165 {
166     u32 timestamp:24;
167     u32 diag_event_type:8;
168     /* Below 16-bit field has different formats based on event type */
169     union {
170         u16 payload_len;
171         struct {
172             u8 payload_len;
173             u8 vdev_level:3;
174             u8 vdev_id:5;
175         }__attribute__((packed)) msg_hdr;
176     }__attribute__((packed)) u;
177     u16 diag_id;
178     u8  payload[0];
179 }__attribute__((packed)) fw_diag_msg_hdr_t;
180 
181 typedef struct
182 {
183     u32 unused:24;
184     u32 diag_event_type:8;
185     u32 timestamp;
186     /* Below 16-bit field has different formats based on event type */
187     union {
188         u16 payload_len;
189         struct {
190             u8 payload_len;
191             u8 vdev_level:3;
192             u8 vdev_id:5;
193         }__attribute__((packed)) msg_hdr;
194     }__attribute__((packed)) u;
195     u16 diag_id;
196     u8  payload[0];
197 }__attribute__((packed)) fw_diag_msg_hdr_v2_t;
198 
199 typedef struct wlan_wake_lock_event {
200     u32 status;
201     u32 reason;
202     u32 timeout;
203     u32 name_len;
204     char name[];
205 } wlan_wake_lock_event_t;
206 
207 enum log_event_type {
208     WLAN_LOG_TYPE_NON_FATAL,
209     WLAN_LOG_TYPE_FATAL,
210 };
211 
212 enum log_event_indicator {
213     WLAN_LOG_INDICATOR_UNUSED,
214     WLAN_LOG_INDICATOR_FRAMEWORK,
215     WLAN_LOG_INDICATOR_HOST_DRIVER,
216     WLAN_LOG_INDICATOR_FIRMWARE,
217 };
218 
219 enum log_event_host_reason_code {
220     WLAN_LOG_REASON_CODE_UNUSED,
221     WLAN_LOG_REASON_COMMAND_UNSUCCESSFUL,
222     WLAN_LOG_REASON_ROAM_FAIL,
223     WLAN_LOG_REASON_THREAD_STUCK,
224     WLAN_LOG_REASON_DATA_STALL,
225     WLAN_LOG_REASON_SME_COMMAND_STUCK,
226     WLAN_LOG_REASON_ZERO_SCAN_RESULTS,
227     WLAN_LOG_REASON_QUEUE_FULL,
228     WLAN_LOG_REASON_POWER_COLLAPSE_FAIL,
229     WLAN_LOG_REASON_SSR_FAIL,
230     WLAN_LOG_REASON_DISCONNECT_FAIL,
231     WLAN_LOG_REASON_CLEAN_UP_FAIL,
232     WLAN_LOG_REASON_MALLOC_FAIL,
233     WLAN_LOG_REASON_VOS_MSG_UNDER_RUN,
234     WLAN_LOG_REASON_MSG_POST_FAIL,
235 };
236 
237 typedef struct {
238     u32 is_fatal;
239     u32 indicator;
240     u32 reason_code;
241     u32 reserved;
242 } wlan_log_complete_event_t;
243 
244 typedef struct {
245     u32 reason;
246 } wlan_data_stall_event_t;
247 
248 wifi_error diag_message_handler(hal_info *info, nl_msg *msg);
249 
250 #endif /* __WIFI_HAL_WIFILOGGER_DIAG_H__ */
251