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_COMMAND_H__
30 #define __WIFI_HAL_WIFILOGGER_COMMAND_H__
31 
32 #include "common.h"
33 #include "cpp_bindings.h"
34 #include "qca-vendor.h"
35 #include "wifi_logger.h"
36 #include "wifilogger_diag.h"
37 #include "vendor_definitions.h"
38 
39 #ifdef __cplusplus
40 extern "C"
41 {
42 #endif /* __cplusplus */
43 
44 #define POWER_EVENTS_RB_BUF_SIZE 2048
45 #define POWER_EVENTS_NUM_BUFS    4
46 
47 #define CONNECTIVITY_EVENTS_RB_BUF_SIZE 4096
48 #define CONNECTIVITY_EVENTS_NUM_BUFS    4
49 
50 #define PKT_STATS_RB_BUF_SIZE 4096
51 #define PKT_STATS_NUM_BUFS    32
52 
53 #define DRIVER_PRINTS_RB_BUF_SIZE 4096
54 #define DRIVER_PRINTS_NUM_BUFS    128
55 
56 #define FIRMWARE_PRINTS_RB_BUF_SIZE 4096
57 #define FIRMWARE_PRINTS_NUM_BUFS    128
58 
59 enum rb_info_indices {
60     POWER_EVENTS_RB_ID = 0,
61     CONNECTIVITY_EVENTS_RB_ID = 1,
62     PKT_STATS_RB_ID = 2,
63     DRIVER_PRINTS_RB_ID = 3,
64     FIRMWARE_PRINTS_RB_ID = 4,
65 };
66 
67 typedef struct {
68   void (*on_firmware_memory_dump) (char *buffer,
69                                    int buffer_size);
70 
71 } WifiLoggerCallbackHandler;
72 
73 
74 class WifiLoggerCommand : public WifiVendorCommand
75 {
76 private:
77     WifiLoggerCallbackHandler mHandler;
78     char                      *mVersion;
79     int                       mVersionLen;
80     u32                       *mSupportedSet;
81     int                       mRequestId;
82     bool                      mWaitforRsp;
83     bool                      mMoreData;
84     WLAN_DRIVER_WAKE_REASON_CNT *mGetWakeStats;
85 public:
86 
87     WifiLoggerCommand(wifi_handle handle, int id, u32 vendor_id, u32 subcmd);
88 
89     static WifiLoggerCommand* instance(wifi_handle handle);
90     virtual ~WifiLoggerCommand();
91 
92     // This function implements creation of WifiLogger specific Request
93     // based on  the request type
94     virtual int create();
95     virtual int requestEvent();
96     virtual int requestResponse();
97     virtual int handleResponse(WifiEvent &reply);
98     virtual int handleEvent(WifiEvent &event);
99     int setCallbackHandler(WifiLoggerCallbackHandler nHandler);
100     virtual void unregisterHandler(u32 subCmd);
101 
102     /* Takes wait time in seconds. */
103     virtual int timed_wait(u16 wait_time);
104     virtual void waitForRsp(bool wait);
105     virtual void setVersionInfo(char *buffer, int buffer_size);
106     virtual void setFeatureSet(u32 *support);
107     virtual void getWakeStatsRspParams(
108                     WLAN_DRIVER_WAKE_REASON_CNT *wifi_wake_reason_cnt);
109 };
110 void rb_timerhandler(hal_info *info);
111 wifi_error wifi_logger_ring_buffers_init(hal_info *info);
112 void wifi_logger_ring_buffers_deinit(hal_info *info);
113 void push_out_all_ring_buffers(hal_info *info);
114 void send_alert(hal_info *info, int reason_code);
115 #ifdef __cplusplus
116 }
117 #endif /* __cplusplus */
118 #endif /* __WIFI_HAL_WIFILOGGER_COMMAND_H__ */
119