Tomas Winkler | 712b6cf | 2008-03-12 16:58:52 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * GPL LICENSE SUMMARY |
| 4 | * |
| 5 | * Copyright(c) 2008 Intel Corporation. All rights reserved. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of version 2 of the GNU General Public License as |
| 9 | * published by the Free Software Foundation. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, but |
| 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, |
| 19 | * USA |
| 20 | * |
| 21 | * The full GNU General Public License is included in this distribution |
| 22 | * in the file called LICENSE.GPL. |
| 23 | * |
| 24 | * Contact Information: |
| 25 | * Tomas Winkler <tomas.winkler@intel.com> |
| 26 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 27 | *****************************************************************************/ |
| 28 | |
| 29 | #include <linux/kernel.h> |
| 30 | #include <linux/module.h> |
| 31 | #include <linux/debugfs.h> |
| 32 | |
| 33 | #include <linux/ieee80211.h> |
| 34 | #include <net/mac80211.h> |
| 35 | |
| 36 | |
| 37 | #include "iwl-4965.h" |
| 38 | #include "iwl-debug.h" |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 39 | #include "iwl-core.h" |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 40 | #include "iwl-io.h" |
Tomas Winkler | 712b6cf | 2008-03-12 16:58:52 -0700 | [diff] [blame] | 41 | |
| 42 | |
| 43 | /* create and remove of files */ |
| 44 | #define DEBUGFS_ADD_DIR(name, parent) do { \ |
| 45 | dbgfs->dir_##name = debugfs_create_dir(#name, parent); \ |
| 46 | if (!(dbgfs->dir_##name)) \ |
| 47 | goto err; \ |
| 48 | } while (0) |
| 49 | |
| 50 | #define DEBUGFS_ADD_FILE(name, parent) do { \ |
| 51 | dbgfs->dbgfs_##parent##_files.file_##name = \ |
| 52 | debugfs_create_file(#name, 0644, dbgfs->dir_##parent, priv, \ |
| 53 | &iwl_dbgfs_##name##_ops); \ |
| 54 | if (!(dbgfs->dbgfs_##parent##_files.file_##name)) \ |
| 55 | goto err; \ |
| 56 | } while (0) |
| 57 | |
| 58 | #define DEBUGFS_REMOVE(name) do { \ |
| 59 | debugfs_remove(name); \ |
| 60 | name = NULL; \ |
| 61 | } while (0); |
| 62 | |
| 63 | /* file operation */ |
| 64 | #define DEBUGFS_READ_FUNC(name) \ |
| 65 | static ssize_t iwl_dbgfs_##name##_read(struct file *file, \ |
| 66 | char __user *user_buf, \ |
| 67 | size_t count, loff_t *ppos); |
| 68 | |
| 69 | #define DEBUGFS_WRITE_FUNC(name) \ |
| 70 | static ssize_t iwl_dbgfs_##name##_write(struct file *file, \ |
| 71 | const char __user *user_buf, \ |
| 72 | size_t count, loff_t *ppos); |
| 73 | |
| 74 | |
| 75 | static int iwl_dbgfs_open_file_generic(struct inode *inode, struct file *file) |
| 76 | { |
| 77 | file->private_data = inode->i_private; |
| 78 | return 0; |
| 79 | } |
| 80 | |
| 81 | #define DEBUGFS_READ_FILE_OPS(name) \ |
| 82 | DEBUGFS_READ_FUNC(name); \ |
| 83 | static const struct file_operations iwl_dbgfs_##name##_ops = { \ |
| 84 | .read = iwl_dbgfs_##name##_read, \ |
| 85 | .open = iwl_dbgfs_open_file_generic, \ |
| 86 | }; |
| 87 | |
| 88 | #define DEBUGFS_READ_WRITE_FILE_OPS(name) \ |
| 89 | DEBUGFS_READ_FUNC(name); \ |
| 90 | DEBUGFS_WRITE_FUNC(name); \ |
| 91 | static const struct file_operations iwl_dbgfs_##name##_ops = { \ |
| 92 | .write = iwl_dbgfs_##name##_write, \ |
| 93 | .read = iwl_dbgfs_##name##_read, \ |
| 94 | .open = iwl_dbgfs_open_file_generic, \ |
| 95 | }; |
| 96 | |
| 97 | |
| 98 | static ssize_t iwl_dbgfs_tx_statistics_read(struct file *file, |
| 99 | char __user *user_buf, |
| 100 | size_t count, loff_t *ppos) { |
| 101 | |
| 102 | struct iwl_priv *priv = (struct iwl_priv *)file->private_data; |
| 103 | char buf[256]; |
| 104 | int pos = 0; |
Abhijeet Kolekar | db0589f | 2008-04-14 21:16:04 -0700 | [diff] [blame] | 105 | const size_t bufsz = sizeof(buf); |
Tomas Winkler | 712b6cf | 2008-03-12 16:58:52 -0700 | [diff] [blame] | 106 | |
Abhijeet Kolekar | db0589f | 2008-04-14 21:16:04 -0700 | [diff] [blame] | 107 | pos += scnprintf(buf + pos, bufsz - pos, "mgmt: %u\n", |
| 108 | priv->tx_stats[0].cnt); |
| 109 | pos += scnprintf(buf + pos, bufsz - pos, "ctrl: %u\n", |
| 110 | priv->tx_stats[1].cnt); |
| 111 | pos += scnprintf(buf + pos, bufsz - pos, "data: %u\n", |
| 112 | priv->tx_stats[2].cnt); |
Tomas Winkler | 712b6cf | 2008-03-12 16:58:52 -0700 | [diff] [blame] | 113 | |
| 114 | return simple_read_from_buffer(user_buf, count, ppos, buf, pos); |
| 115 | } |
| 116 | |
| 117 | static ssize_t iwl_dbgfs_rx_statistics_read(struct file *file, |
| 118 | char __user *user_buf, |
| 119 | size_t count, loff_t *ppos) { |
| 120 | |
| 121 | struct iwl_priv *priv = (struct iwl_priv *)file->private_data; |
| 122 | char buf[256]; |
| 123 | int pos = 0; |
Abhijeet Kolekar | db0589f | 2008-04-14 21:16:04 -0700 | [diff] [blame] | 124 | const size_t bufsz = sizeof(buf); |
Tomas Winkler | 712b6cf | 2008-03-12 16:58:52 -0700 | [diff] [blame] | 125 | |
Abhijeet Kolekar | db0589f | 2008-04-14 21:16:04 -0700 | [diff] [blame] | 126 | pos += scnprintf(buf + pos, bufsz - pos, "mgmt: %u\n", |
| 127 | priv->rx_stats[0].cnt); |
| 128 | pos += scnprintf(buf + pos, bufsz - pos, "ctrl: %u\n", |
| 129 | priv->rx_stats[1].cnt); |
| 130 | pos += scnprintf(buf + pos, bufsz - pos, "data: %u\n", |
| 131 | priv->rx_stats[2].cnt); |
Tomas Winkler | 712b6cf | 2008-03-12 16:58:52 -0700 | [diff] [blame] | 132 | |
| 133 | return simple_read_from_buffer(user_buf, count, ppos, buf, pos); |
| 134 | } |
| 135 | |
| 136 | #define BYTE1_MASK 0x000000ff; |
| 137 | #define BYTE2_MASK 0x0000ffff; |
| 138 | #define BYTE3_MASK 0x00ffffff; |
| 139 | static ssize_t iwl_dbgfs_sram_read(struct file *file, |
| 140 | char __user *user_buf, |
| 141 | size_t count, loff_t *ppos) |
| 142 | { |
| 143 | u32 val; |
| 144 | char buf[1024]; |
| 145 | ssize_t ret; |
| 146 | int i; |
| 147 | int pos = 0; |
| 148 | struct iwl_priv *priv = (struct iwl_priv *)file->private_data; |
Abhijeet Kolekar | db0589f | 2008-04-14 21:16:04 -0700 | [diff] [blame] | 149 | const size_t bufsz = sizeof(buf); |
Tomas Winkler | 712b6cf | 2008-03-12 16:58:52 -0700 | [diff] [blame] | 150 | |
| 151 | printk(KERN_DEBUG "offset is: 0x%x\tlen is: 0x%x\n", |
| 152 | priv->dbgfs->sram_offset, priv->dbgfs->sram_len); |
| 153 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 154 | iwl_grab_nic_access(priv); |
Tomas Winkler | 712b6cf | 2008-03-12 16:58:52 -0700 | [diff] [blame] | 155 | for (i = priv->dbgfs->sram_len; i > 0; i -= 4) { |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 156 | val = iwl_read_targ_mem(priv, priv->dbgfs->sram_offset + \ |
Tomas Winkler | 712b6cf | 2008-03-12 16:58:52 -0700 | [diff] [blame] | 157 | priv->dbgfs->sram_len - i); |
| 158 | if (i < 4) { |
| 159 | switch (i) { |
| 160 | case 1: |
| 161 | val &= BYTE1_MASK; |
| 162 | break; |
| 163 | case 2: |
| 164 | val &= BYTE2_MASK; |
| 165 | break; |
| 166 | case 3: |
| 167 | val &= BYTE3_MASK; |
| 168 | break; |
| 169 | } |
| 170 | } |
Abhijeet Kolekar | db0589f | 2008-04-14 21:16:04 -0700 | [diff] [blame] | 171 | pos += scnprintf(buf + pos, bufsz - pos, "0x%08x ", val); |
Tomas Winkler | 712b6cf | 2008-03-12 16:58:52 -0700 | [diff] [blame] | 172 | } |
Abhijeet Kolekar | db0589f | 2008-04-14 21:16:04 -0700 | [diff] [blame] | 173 | pos += scnprintf(buf + pos, bufsz - pos, "\n"); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 174 | iwl_release_nic_access(priv); |
Tomas Winkler | 712b6cf | 2008-03-12 16:58:52 -0700 | [diff] [blame] | 175 | |
| 176 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); |
| 177 | return ret; |
| 178 | } |
| 179 | |
| 180 | static ssize_t iwl_dbgfs_sram_write(struct file *file, |
| 181 | const char __user *user_buf, |
| 182 | size_t count, loff_t *ppos) |
| 183 | { |
| 184 | struct iwl_priv *priv = file->private_data; |
| 185 | char buf[64]; |
| 186 | int buf_size; |
| 187 | u32 offset, len; |
| 188 | |
| 189 | memset(buf, 0, sizeof(buf)); |
| 190 | buf_size = min(count, sizeof(buf) - 1); |
| 191 | if (copy_from_user(buf, user_buf, buf_size)) |
| 192 | return -EFAULT; |
| 193 | |
| 194 | if (sscanf(buf, "%x,%x", &offset, &len) == 2) { |
| 195 | priv->dbgfs->sram_offset = offset; |
| 196 | priv->dbgfs->sram_len = len; |
| 197 | } else { |
| 198 | priv->dbgfs->sram_offset = 0; |
| 199 | priv->dbgfs->sram_len = 0; |
| 200 | } |
| 201 | |
| 202 | return count; |
| 203 | } |
| 204 | |
| 205 | static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf, |
| 206 | size_t count, loff_t *ppos) |
| 207 | { |
| 208 | struct iwl_priv *priv = (struct iwl_priv *)file->private_data; |
| 209 | struct iwl4965_station_entry *station; |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame^] | 210 | int max_sta = priv->hw_params.max_stations; |
Tomas Winkler | 712b6cf | 2008-03-12 16:58:52 -0700 | [diff] [blame] | 211 | char *buf; |
| 212 | int i, j, pos = 0; |
| 213 | ssize_t ret; |
| 214 | /* Add 30 for initial string */ |
| 215 | const size_t bufsz = 30 + sizeof(char) * 500 * (priv->num_stations); |
| 216 | DECLARE_MAC_BUF(mac); |
| 217 | |
| 218 | buf = kmalloc(bufsz, GFP_KERNEL); |
| 219 | if(!buf) |
| 220 | return -ENOMEM; |
| 221 | |
Abhijeet Kolekar | db0589f | 2008-04-14 21:16:04 -0700 | [diff] [blame] | 222 | pos += scnprintf(buf + pos, bufsz - pos, "num of stations: %d\n\n", |
Tomas Winkler | 712b6cf | 2008-03-12 16:58:52 -0700 | [diff] [blame] | 223 | priv->num_stations); |
| 224 | |
| 225 | for (i = 0; i < max_sta; i++) { |
| 226 | station = &priv->stations[i]; |
| 227 | if (station->used) { |
Abhijeet Kolekar | db0589f | 2008-04-14 21:16:04 -0700 | [diff] [blame] | 228 | pos += scnprintf(buf + pos, bufsz - pos, |
| 229 | "station %d:\ngeneral data:\n", i+1); |
Tomas Winkler | 712b6cf | 2008-03-12 16:58:52 -0700 | [diff] [blame] | 230 | print_mac(mac, station->sta.sta.addr); |
Abhijeet Kolekar | db0589f | 2008-04-14 21:16:04 -0700 | [diff] [blame] | 231 | pos += scnprintf(buf + pos, bufsz - pos, "id: %u\n", |
Tomas Winkler | 712b6cf | 2008-03-12 16:58:52 -0700 | [diff] [blame] | 232 | station->sta.sta.sta_id); |
Abhijeet Kolekar | db0589f | 2008-04-14 21:16:04 -0700 | [diff] [blame] | 233 | pos += scnprintf(buf + pos, bufsz - pos, "mode: %u\n", |
Tomas Winkler | 712b6cf | 2008-03-12 16:58:52 -0700 | [diff] [blame] | 234 | station->sta.mode); |
Abhijeet Kolekar | db0589f | 2008-04-14 21:16:04 -0700 | [diff] [blame] | 235 | pos += scnprintf(buf + pos, bufsz - pos, |
| 236 | "flags: 0x%x\n", |
Tomas Winkler | 712b6cf | 2008-03-12 16:58:52 -0700 | [diff] [blame] | 237 | station->sta.station_flags_msk); |
Abhijeet Kolekar | db0589f | 2008-04-14 21:16:04 -0700 | [diff] [blame] | 238 | pos += scnprintf(buf + pos, bufsz - pos, |
| 239 | "ps_status: %u\n", station->ps_status); |
| 240 | pos += scnprintf(buf + pos, bufsz - pos, "tid data:\n"); |
| 241 | pos += scnprintf(buf + pos, bufsz - pos, |
| 242 | "seq_num\t\ttxq_id\t"); |
| 243 | pos += scnprintf(buf + pos, bufsz - pos, |
| 244 | "frame_count\twait_for_ba\t"); |
| 245 | pos += scnprintf(buf + pos, bufsz - pos, |
| 246 | "start_idx\tbitmap0\t"); |
| 247 | pos += scnprintf(buf + pos, bufsz - pos, |
| 248 | "bitmap1\trate_n_flags\n"); |
Tomas Winkler | 712b6cf | 2008-03-12 16:58:52 -0700 | [diff] [blame] | 249 | |
| 250 | for (j = 0; j < MAX_TID_COUNT; j++) { |
Abhijeet Kolekar | db0589f | 2008-04-14 21:16:04 -0700 | [diff] [blame] | 251 | pos += scnprintf(buf + pos, bufsz - pos, |
| 252 | "[%d]:\t\t%u\t", j, |
| 253 | station->tid[j].seq_number); |
| 254 | pos += scnprintf(buf + pos, bufsz - pos, |
| 255 | "%u\t\t%u\t\t%u\t\t", |
Tomas Winkler | 712b6cf | 2008-03-12 16:58:52 -0700 | [diff] [blame] | 256 | station->tid[j].agg.txq_id, |
| 257 | station->tid[j].agg.frame_count, |
| 258 | station->tid[j].agg.wait_for_ba); |
Abhijeet Kolekar | db0589f | 2008-04-14 21:16:04 -0700 | [diff] [blame] | 259 | pos += scnprintf(buf + pos, bufsz - pos, |
| 260 | "%u\t%llu\t%u\n", |
Tomas Winkler | 712b6cf | 2008-03-12 16:58:52 -0700 | [diff] [blame] | 261 | station->tid[j].agg.start_idx, |
John W. Linville | 1678859 | 2008-04-01 20:59:32 -0400 | [diff] [blame] | 262 | (unsigned long long)station->tid[j].agg.bitmap, |
Tomas Winkler | 712b6cf | 2008-03-12 16:58:52 -0700 | [diff] [blame] | 263 | station->tid[j].agg.rate_n_flags); |
| 264 | } |
Abhijeet Kolekar | db0589f | 2008-04-14 21:16:04 -0700 | [diff] [blame] | 265 | pos += scnprintf(buf + pos, bufsz - pos, "\n"); |
Tomas Winkler | 712b6cf | 2008-03-12 16:58:52 -0700 | [diff] [blame] | 266 | } |
| 267 | } |
| 268 | |
| 269 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); |
| 270 | kfree(buf); |
| 271 | return ret; |
| 272 | } |
| 273 | |
| 274 | |
| 275 | DEBUGFS_READ_WRITE_FILE_OPS(sram); |
| 276 | DEBUGFS_READ_FILE_OPS(stations); |
| 277 | DEBUGFS_READ_FILE_OPS(rx_statistics); |
| 278 | DEBUGFS_READ_FILE_OPS(tx_statistics); |
| 279 | |
| 280 | /* |
| 281 | * Create the debugfs files and directories |
| 282 | * |
| 283 | */ |
| 284 | int iwl_dbgfs_register(struct iwl_priv *priv, const char *name) |
| 285 | { |
| 286 | struct iwl_debugfs *dbgfs; |
| 287 | |
| 288 | dbgfs = kzalloc(sizeof(struct iwl_debugfs), GFP_KERNEL); |
| 289 | if (!dbgfs) { |
| 290 | goto err; |
| 291 | } |
| 292 | |
| 293 | priv->dbgfs = dbgfs; |
| 294 | dbgfs->name = name; |
| 295 | dbgfs->dir_drv = debugfs_create_dir(name, NULL); |
| 296 | if (!dbgfs->dir_drv || IS_ERR(dbgfs->dir_drv)){ |
| 297 | goto err; |
| 298 | } |
| 299 | |
| 300 | DEBUGFS_ADD_DIR(data, dbgfs->dir_drv); |
| 301 | DEBUGFS_ADD_FILE(sram, data); |
| 302 | DEBUGFS_ADD_FILE(stations, data); |
| 303 | DEBUGFS_ADD_FILE(rx_statistics, data); |
| 304 | DEBUGFS_ADD_FILE(tx_statistics, data); |
| 305 | |
| 306 | return 0; |
| 307 | |
| 308 | err: |
| 309 | IWL_ERROR("Can't open the debugfs directory\n"); |
| 310 | iwl_dbgfs_unregister(priv); |
| 311 | return -ENOENT; |
| 312 | } |
| 313 | EXPORT_SYMBOL(iwl_dbgfs_register); |
| 314 | |
| 315 | /** |
| 316 | * Remove the debugfs files and directories |
| 317 | * |
| 318 | */ |
| 319 | void iwl_dbgfs_unregister(struct iwl_priv *priv) |
| 320 | { |
| 321 | if (!(priv->dbgfs)) |
| 322 | return; |
| 323 | |
| 324 | DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_rx_statistics); |
| 325 | DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_tx_statistics); |
| 326 | DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_sram); |
| 327 | DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_stations); |
| 328 | DEBUGFS_REMOVE(priv->dbgfs->dir_data); |
| 329 | DEBUGFS_REMOVE(priv->dbgfs->dir_drv); |
| 330 | kfree(priv->dbgfs); |
| 331 | priv->dbgfs = NULL; |
| 332 | } |
| 333 | EXPORT_SYMBOL(iwl_dbgfs_unregister); |
| 334 | |
| 335 | |