1 /** 2 * Copyright (c) 2014 Redpine Signals Inc. 3 * 4 * Permission to use, copy, modify, and/or distribute this software for any 5 * purpose with or without fee is hereby granted, provided that the above 6 * copyright notice and this permission notice appear in all copies. 7 * 8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 */ 16 17 #include "rsi_debugfs.h" 18 #include "rsi_sdio.h" 19 20 /** 21 * rsi_sdio_stats_read() - This function returns the sdio status of the driver. 22 * @seq: Pointer to the sequence file structure. 23 * @data: Pointer to the data. 24 * 25 * Return: 0 on success, -1 on failure. 26 */ 27 static int rsi_sdio_stats_read(struct seq_file *seq, void *data) 28 { 29 struct rsi_common *common = seq->private; 30 struct rsi_hw *adapter = common->priv; 31 struct rsi_91x_sdiodev *dev = 32 (struct rsi_91x_sdiodev *)adapter->rsi_dev; 33 34 seq_printf(seq, "total_sdio_interrupts: %d\n", 35 dev->rx_info.sdio_int_counter); 36 seq_printf(seq, "sdio_msdu_pending_intr_count: %d\n", 37 dev->rx_info.total_sdio_msdu_pending_intr); 38 seq_printf(seq, "sdio_buff_full_count : %d\n", 39 dev->rx_info.buf_full_counter); 40 seq_printf(seq, "sdio_buf_semi_full_count %d\n", 41 dev->rx_info.buf_semi_full_counter); 42 seq_printf(seq, "sdio_unknown_intr_count: %d\n", 43 dev->rx_info.total_sdio_unknown_intr); 44 /* RX Path Stats */ 45 seq_printf(seq, "BUFFER FULL STATUS : %d\n", 46 dev->rx_info.buffer_full); 47 seq_printf(seq, "SEMI BUFFER FULL STATUS : %d\n", 48 dev->rx_info.semi_buffer_full); 49 seq_printf(seq, "MGMT BUFFER FULL STATUS : %d\n", 50 dev->rx_info.mgmt_buffer_full); 51 seq_printf(seq, "BUFFER FULL COUNTER : %d\n", 52 dev->rx_info.buf_full_counter); 53 seq_printf(seq, "BUFFER SEMI FULL COUNTER : %d\n", 54 dev->rx_info.buf_semi_full_counter); 55 seq_printf(seq, "MGMT BUFFER FULL COUNTER : %d\n", 56 dev->rx_info.mgmt_buf_full_counter); 57 58 return 0; 59 } 60 61 /** 62 * rsi_sdio_stats_open() - This funtion calls single open function of seq_file 63 * to open file and read contents from it. 64 * @inode: Pointer to the inode structure. 65 * @file: Pointer to the file structure. 66 * 67 * Return: Pointer to the opened file status: 0 on success, ENOMEM on failure. 68 */ 69 static int rsi_sdio_stats_open(struct inode *inode, 70 struct file *file) 71 { 72 return single_open(file, rsi_sdio_stats_read, inode->i_private); 73 } 74 75 /** 76 * rsi_version_read() - This function gives driver and firmware version number. 77 * @seq: Pointer to the sequence file structure. 78 * @data: Pointer to the data. 79 * 80 * Return: 0 on success, -1 on failure. 81 */ 82 static int rsi_version_read(struct seq_file *seq, void *data) 83 { 84 struct rsi_common *common = seq->private; 85 86 seq_printf(seq, "LMAC : %d.%d.%d.%d\n", 87 common->lmac_ver.major, 88 common->lmac_ver.minor, 89 common->lmac_ver.release_num, 90 common->lmac_ver.patch_num); 91 92 return 0; 93 } 94 95 /** 96 * rsi_version_open() - This funtion calls single open function of seq_file to 97 * open file and read contents from it. 98 * @inode: Pointer to the inode structure. 99 * @file: Pointer to the file structure. 100 * 101 * Return: Pointer to the opened file status: 0 on success, ENOMEM on failure. 102 */ 103 static int rsi_version_open(struct inode *inode, 104 struct file *file) 105 { 106 return single_open(file, rsi_version_read, inode->i_private); 107 } 108 109 /** 110 * rsi_stats_read() - This function return the status of the driver. 111 * @seq: Pointer to the sequence file structure. 112 * @data: Pointer to the data. 113 * 114 * Return: 0 on success, -1 on failure. 115 */ 116 static int rsi_stats_read(struct seq_file *seq, void *data) 117 { 118 struct rsi_common *common = seq->private; 119 120 unsigned char fsm_state[][32] = { 121 "FSM_FW_NOT_LOADED", 122 "FSM_CARD_NOT_READY", 123 "FSM_COMMON_DEV_PARAMS_SENT", 124 "FSM_BOOT_PARAMS_SENT", 125 "FSM_EEPROM_READ_MAC_ADDR", 126 "FSM_EEPROM_READ_RF_TYPE", 127 "FSM_RESET_MAC_SENT", 128 "FSM_RADIO_CAPS_SENT", 129 "FSM_BB_RF_PROG_SENT", 130 "FSM_MAC_INIT_DONE" 131 }; 132 seq_puts(seq, "==> RSI STA DRIVER STATUS <==\n"); 133 seq_puts(seq, "DRIVER_FSM_STATE: "); 134 135 BUILD_BUG_ON(ARRAY_SIZE(fsm_state) != NUM_FSM_STATES); 136 137 if (common->fsm_state <= FSM_MAC_INIT_DONE) 138 seq_printf(seq, "%s", fsm_state[common->fsm_state]); 139 140 seq_printf(seq, "(%d)\n\n", common->fsm_state); 141 142 /* Mgmt TX Path Stats */ 143 seq_printf(seq, "total_mgmt_pkt_send : %d\n", 144 common->tx_stats.total_tx_pkt_send[MGMT_SOFT_Q]); 145 seq_printf(seq, "total_mgmt_pkt_queued : %d\n", 146 skb_queue_len(&common->tx_queue[MGMT_SOFT_Q])); 147 seq_printf(seq, "total_mgmt_pkt_freed : %d\n", 148 common->tx_stats.total_tx_pkt_freed[MGMT_SOFT_Q]); 149 150 /* Data TX Path Stats */ 151 seq_printf(seq, "total_data_vo_pkt_send: %8d\t", 152 common->tx_stats.total_tx_pkt_send[VO_Q]); 153 seq_printf(seq, "total_data_vo_pkt_queued: %8d\t", 154 skb_queue_len(&common->tx_queue[VO_Q])); 155 seq_printf(seq, "total_vo_pkt_freed: %8d\n", 156 common->tx_stats.total_tx_pkt_freed[VO_Q]); 157 seq_printf(seq, "total_data_vi_pkt_send: %8d\t", 158 common->tx_stats.total_tx_pkt_send[VI_Q]); 159 seq_printf(seq, "total_data_vi_pkt_queued: %8d\t", 160 skb_queue_len(&common->tx_queue[VI_Q])); 161 seq_printf(seq, "total_vi_pkt_freed: %8d\n", 162 common->tx_stats.total_tx_pkt_freed[VI_Q]); 163 seq_printf(seq, "total_data_be_pkt_send: %8d\t", 164 common->tx_stats.total_tx_pkt_send[BE_Q]); 165 seq_printf(seq, "total_data_be_pkt_queued: %8d\t", 166 skb_queue_len(&common->tx_queue[BE_Q])); 167 seq_printf(seq, "total_be_pkt_freed: %8d\n", 168 common->tx_stats.total_tx_pkt_freed[BE_Q]); 169 seq_printf(seq, "total_data_bk_pkt_send: %8d\t", 170 common->tx_stats.total_tx_pkt_send[BK_Q]); 171 seq_printf(seq, "total_data_bk_pkt_queued: %8d\t", 172 skb_queue_len(&common->tx_queue[BK_Q])); 173 seq_printf(seq, "total_bk_pkt_freed: %8d\n", 174 common->tx_stats.total_tx_pkt_freed[BK_Q]); 175 176 seq_puts(seq, "\n"); 177 return 0; 178 } 179 180 /** 181 * rsi_stats_open() - This funtion calls single open function of seq_file to 182 * open file and read contents from it. 183 * @inode: Pointer to the inode structure. 184 * @file: Pointer to the file structure. 185 * 186 * Return: Pointer to the opened file status: 0 on success, ENOMEM on failure. 187 */ 188 static int rsi_stats_open(struct inode *inode, 189 struct file *file) 190 { 191 return single_open(file, rsi_stats_read, inode->i_private); 192 } 193 194 /** 195 * rsi_debug_zone_read() - This function display the currently enabled debug zones. 196 * @seq: Pointer to the sequence file structure. 197 * @data: Pointer to the data. 198 * 199 * Return: 0 on success, -1 on failure. 200 */ 201 static int rsi_debug_zone_read(struct seq_file *seq, void *data) 202 { 203 rsi_dbg(FSM_ZONE, "%x: rsi_enabled zone", rsi_zone_enabled); 204 seq_printf(seq, "The zones available are %#x\n", 205 rsi_zone_enabled); 206 return 0; 207 } 208 209 /** 210 * rsi_debug_read() - This funtion calls single open function of seq_file to 211 * open file and read contents from it. 212 * @inode: Pointer to the inode structure. 213 * @file: Pointer to the file structure. 214 * 215 * Return: Pointer to the opened file status: 0 on success, ENOMEM on failure. 216 */ 217 static int rsi_debug_read(struct inode *inode, 218 struct file *file) 219 { 220 return single_open(file, rsi_debug_zone_read, inode->i_private); 221 } 222 223 /** 224 * rsi_debug_zone_write() - This function writes into hal queues as per user 225 * requirement. 226 * @filp: Pointer to the file structure. 227 * @buff: Pointer to the character buffer. 228 * @len: Length of the data to be written into buffer. 229 * @data: Pointer to the data. 230 * 231 * Return: len: Number of bytes read. 232 */ 233 static ssize_t rsi_debug_zone_write(struct file *filp, 234 const char __user *buff, 235 size_t len, 236 loff_t *data) 237 { 238 unsigned long dbg_zone; 239 int ret; 240 241 if (!len) 242 return 0; 243 244 ret = kstrtoul_from_user(buff, len, 16, &dbg_zone); 245 246 if (ret) 247 return ret; 248 249 rsi_zone_enabled = dbg_zone; 250 return len; 251 } 252 253 #define FOPS(fopen) { \ 254 .owner = THIS_MODULE, \ 255 .open = (fopen), \ 256 .read = seq_read, \ 257 .llseek = seq_lseek, \ 258 } 259 260 #define FOPS_RW(fopen, fwrite) { \ 261 .owner = THIS_MODULE, \ 262 .open = (fopen), \ 263 .read = seq_read, \ 264 .llseek = seq_lseek, \ 265 .write = (fwrite), \ 266 } 267 268 static const struct rsi_dbg_files dev_debugfs_files[] = { 269 {"version", 0644, FOPS(rsi_version_open),}, 270 {"stats", 0644, FOPS(rsi_stats_open),}, 271 {"debug_zone", 0666, FOPS_RW(rsi_debug_read, rsi_debug_zone_write),}, 272 {"sdio_stats", 0644, FOPS(rsi_sdio_stats_open),}, 273 }; 274 275 /** 276 * rsi_init_dbgfs() - This function initializes the dbgfs entry. 277 * @adapter: Pointer to the adapter structure. 278 * 279 * Return: 0 on success, -1 on failure. 280 */ 281 int rsi_init_dbgfs(struct rsi_hw *adapter) 282 { 283 struct rsi_common *common = adapter->priv; 284 struct rsi_debugfs *dev_dbgfs; 285 char devdir[6]; 286 int ii; 287 const struct rsi_dbg_files *files; 288 289 dev_dbgfs = kzalloc(sizeof(*dev_dbgfs), GFP_KERNEL); 290 if (!dev_dbgfs) 291 return -ENOMEM; 292 293 adapter->dfsentry = dev_dbgfs; 294 295 snprintf(devdir, sizeof(devdir), "%s", 296 wiphy_name(adapter->hw->wiphy)); 297 298 dev_dbgfs->subdir = debugfs_create_dir(devdir, NULL); 299 300 if (!dev_dbgfs->subdir) { 301 kfree(dev_dbgfs); 302 return -ENOMEM; 303 } 304 305 for (ii = 0; ii < adapter->num_debugfs_entries; ii++) { 306 files = &dev_debugfs_files[ii]; 307 dev_dbgfs->rsi_files[ii] = 308 debugfs_create_file(files->name, 309 files->perms, 310 dev_dbgfs->subdir, 311 common, 312 &files->fops); 313 } 314 return 0; 315 } 316 EXPORT_SYMBOL_GPL(rsi_init_dbgfs); 317 318 /** 319 * rsi_remove_dbgfs() - Removes the previously created dbgfs file entries 320 * in the reverse order of creation. 321 * @adapter: Pointer to the adapter structure. 322 * 323 * Return: None. 324 */ 325 void rsi_remove_dbgfs(struct rsi_hw *adapter) 326 { 327 struct rsi_debugfs *dev_dbgfs = adapter->dfsentry; 328 329 if (!dev_dbgfs) 330 return; 331 332 debugfs_remove_recursive(dev_dbgfs->subdir); 333 } 334 EXPORT_SYMBOL_GPL(rsi_remove_dbgfs); 335