1 /* 2 * Copyright (c) 2012-2020 The Linux Foundation. All rights reserved. 3 * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. 4 * 5 * Permission to use, copy, modify, and/or distribute this software for 6 * any purpose with or without fee is hereby granted, provided that the 7 * above copyright notice and this permission notice appear in all 8 * copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 11 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 12 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE 13 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 14 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 15 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 16 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 17 * PERFORMANCE OF THIS SOFTWARE. 18 */ 19 20 #ifndef _PKTLOG_AC_H_ 21 #define _PKTLOG_AC_H_ 22 23 #include "hif.h" 24 #if defined(CONNECTIVITY_PKTLOG) || !defined(REMOVE_PKT_LOG) 25 #include "ol_if_athvar.h" 26 #include "osdep.h" 27 #include <wmi_unified.h> 28 #include <wmi_unified_api.h> 29 #include <wdi_event_api.h> 30 #include <ol_defines.h> 31 #include <pktlog_ac_api.h> 32 #include <pktlog_ac_fmt.h> 33 34 #define NO_REG_FUNCS 4 35 36 /* Locking interface for pktlog */ 37 #define PKTLOG_LOCK_INIT(_pl_info) qdf_spinlock_create(&(_pl_info)->log_lock) 38 #define PKTLOG_LOCK_DESTROY(_pl_info) \ 39 qdf_spinlock_destroy(&(_pl_info)->log_lock) 40 #define PKTLOG_LOCK(_pl_info) qdf_spin_lock_bh(&(_pl_info)->log_lock) 41 #define PKTLOG_UNLOCK(_pl_info) qdf_spin_unlock_bh(&(_pl_info)->log_lock) 42 43 #define PKTLOG_MODE_SYSTEM 1 44 #define PKTLOG_MODE_ADAPTER 2 45 46 /* 47 * The proc entry starts with magic number and version field which will be 48 * used by post processing scripts. These fields are not needed by applications 49 * that do not use these scripts. This is skipped using the offset value. 50 */ 51 #define PKTLOG_READ_OFFSET 8 52 53 /* forward declaration for cdp_pdev */ 54 struct cdp_pdev; 55 56 /* Opaque softc */ 57 struct ol_ath_generic_softc_t; 58 typedef struct ol_ath_generic_softc_t *ol_ath_generic_softc_handle; 59 extern void pktlog_disable_adapter_logging(struct hif_opaque_softc *scn); 60 extern int pktlog_alloc_buf(struct hif_opaque_softc *scn); 61 extern void pktlog_release_buf(struct hif_opaque_softc *scn); 62 63 ssize_t pktlog_read_proc_entry(char *buf, size_t nbytes, loff_t *ppos, 64 struct ath_pktlog_info *pl_info, bool *read_complete); 65 66 /** 67 * wdi_pktlog_unsubscribe() - Unsubscribe pktlog callbacks 68 * @pdev_id: pdev id 69 * @log_state: Pktlog registration 70 * 71 * Return: zero on success, non-zero on failure 72 */ 73 A_STATUS wdi_pktlog_unsubscribe(uint8_t pdev_id, uint32_t log_state); 74 75 struct ol_pl_arch_dep_funcs { 76 void (*pktlog_init)(struct hif_opaque_softc *scn); 77 int (*pktlog_enable)(struct hif_opaque_softc *scn, int32_t log_state, 78 bool ini, uint8_t user, 79 uint32_t is_iwpriv_command); 80 int (*pktlog_setsize)(struct hif_opaque_softc *scn, int32_t log_state); 81 int (*pktlog_disable)(struct hif_opaque_softc *scn); 82 }; 83 84 struct ol_pl_os_dep_funcs { 85 int (*pktlog_attach)(struct hif_opaque_softc *scn); 86 void (*pktlog_detach)(struct hif_opaque_softc *scn); 87 88 }; 89 90 struct ath_pktlog_wmi_params { 91 WMI_PKTLOG_EVENT pktlog_event; 92 WMI_CMD_ID cmd_id; 93 bool ini_triggered; 94 uint8_t user_triggered; 95 }; 96 97 extern struct ol_pl_arch_dep_funcs ol_pl_funcs; 98 extern struct ol_pl_os_dep_funcs *g_ol_pl_os_dep_funcs; 99 100 /* Pktlog handler to save the state of the pktlogs */ 101 struct pktlog_dev_t { 102 struct ol_pl_arch_dep_funcs *pl_funcs; 103 struct ath_pktlog_info *pl_info; 104 ol_ath_generic_softc_handle scn; 105 uint8_t pdev_id; 106 char *name; 107 bool tgt_pktlog_alloced; 108 bool is_pktlog_cb_subscribed; 109 bool mt_pktlog_enabled; 110 uint32_t htc_err_cnt; 111 uint8_t htc_endpoint; 112 void *htc_pdev; 113 bool vendor_cmd_send; 114 uint8_t callback_type; 115 uint32_t invalid_packets; 116 }; 117 118 #define PKTLOG_SYSCTL_SIZE 14 119 #define PKTLOG_MAX_SEND_QUEUE_DEPTH 64 120 121 /* 122 * Linux specific pktlog state information 123 */ 124 struct ath_pktlog_info_lnx { 125 struct ath_pktlog_info info; 126 struct ctl_table sysctls[PKTLOG_SYSCTL_SIZE]; 127 struct proc_dir_entry *proc_entry; 128 struct ctl_table_header *sysctl_header; 129 }; 130 131 #define PL_INFO_LNX(_pl_info) ((struct ath_pktlog_info_lnx *)(_pl_info)) 132 133 extern struct ol_pktlog_dev_t ol_pl_dev; 134 135 /* 136 * WDI related data and functions 137 * Callback function to the WDI events 138 */ 139 void pktlog_callback(void *pdev, enum WDI_EVENT event, void *log_data, 140 u_int16_t peer_id, uint32_t status); 141 142 void pktlog_init(struct hif_opaque_softc *scn); 143 int pktlog_enable(struct hif_opaque_softc *scn, int32_t log_state, 144 bool, uint8_t, uint32_t); 145 int __pktlog_enable(struct hif_opaque_softc *scn, int32_t log_state, 146 bool ini_triggered, uint8_t user_triggered, 147 uint32_t is_iwpriv_command); 148 int pktlog_setsize(struct hif_opaque_softc *scn, int32_t log_state); 149 int pktlog_clearbuff(struct hif_opaque_softc *scn, bool clear_buff); 150 int pktlog_disable(struct hif_opaque_softc *scn); 151 int pktlogmod_init(void *context); 152 void pktlogmod_exit(void *context); 153 int pktlog_htc_attach(void); 154 155 /** 156 * pktlog_process_fw_msg() - process packetlog message 157 * @pdev_id: physical device instance id 158 * @msg_word: message buffer 159 * @msg_len: message length 160 * 161 * Return: None 162 */ 163 void pktlog_process_fw_msg(uint8_t pdev_id, uint32_t *msg_word, 164 uint32_t msg_len); 165 void lit_pktlog_callback(void *context, enum WDI_EVENT event, void *log_data, 166 u_int16_t peer_id, uint32_t status); 167 168 #define ol_pktlog_attach(_scn) \ 169 do { \ 170 if (g_ol_pl_os_dep_funcs) { \ 171 g_ol_pl_os_dep_funcs->pktlog_attach(_scn); \ 172 } \ 173 } while (0) 174 175 #define ol_pktlog_detach(_scn) \ 176 do { \ 177 if (g_ol_pl_os_dep_funcs) { \ 178 g_ol_pl_os_dep_funcs->pktlog_detach(_scn); \ 179 } \ 180 } while (0) 181 182 #else /* REMOVE_PKT_LOG */ 183 #define ol_pktlog_attach(_scn) ({ (void)_scn; }) 184 #define ol_pktlog_detach(_scn) ({ (void)_scn; }) 185 static inline void pktlog_init(struct hif_opaque_softc *scn) 186 { 187 return; 188 } 189 190 static inline int pktlog_enable(struct hif_opaque_softc *scn, int32_t log_state, 191 bool ini, uint8_t user, 192 uint32_t is_iwpriv_command) 193 { 194 return 0; 195 } 196 197 static inline 198 int __pktlog_enable(struct hif_opaque_softc *scn, int32_t log_state, 199 bool ini_triggered, uint8_t user_triggered, 200 uint32_t is_iwpriv_command) 201 { 202 return 0; 203 } 204 205 static inline int pktlog_setsize(struct hif_opaque_softc *scn, 206 int32_t log_state) 207 { 208 return 0; 209 } 210 211 static inline int pktlog_clearbuff(struct hif_opaque_softc *scn, 212 bool clear_buff) 213 { 214 return 0; 215 } 216 217 static inline int pktlog_disable(struct hif_opaque_softc *scn) 218 { 219 return 0; 220 } 221 222 static inline int pktlog_htc_attach(void) 223 { 224 return 0; 225 } 226 227 static inline void pktlog_process_fw_msg(uint8_t pdev_id, uint32_t *msg_word, 228 uint32_t msg_len) 229 { } 230 #endif /* REMOVE_PKT_LOG */ 231 #endif /* _PKTLOG_AC_H_ */ 232