Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Marvell Wireless LAN device driver: debugfs |
| 3 | * |
| 4 | * Copyright (C) 2011, Marvell International Ltd. |
| 5 | * |
| 6 | * This software file (the "File") is distributed by Marvell International |
| 7 | * Ltd. under the terms of the GNU General Public License Version 2, June 1991 |
| 8 | * (the "License"). You may use, redistribute and/or modify this File in |
| 9 | * accordance with the terms and conditions of the License, a copy of which |
| 10 | * is available by writing to the Free Software Foundation, Inc., |
| 11 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the |
| 12 | * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. |
| 13 | * |
| 14 | * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE |
| 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE |
| 16 | * ARE EXPRESSLY DISCLAIMED. The License provides additional details about |
| 17 | * this warranty disclaimer. |
| 18 | */ |
| 19 | |
| 20 | #include <linux/debugfs.h> |
| 21 | |
| 22 | #include "main.h" |
| 23 | #include "11n.h" |
| 24 | |
| 25 | |
| 26 | static struct dentry *mwifiex_dfs_dir; |
| 27 | |
| 28 | static char *bss_modes[] = { |
| 29 | "Unknown", |
| 30 | "Managed", |
| 31 | "Ad-hoc", |
| 32 | "Auto" |
| 33 | }; |
| 34 | |
| 35 | /* size/addr for mwifiex_debug_info */ |
| 36 | #define item_size(n) (FIELD_SIZEOF(struct mwifiex_debug_info, n)) |
| 37 | #define item_addr(n) (offsetof(struct mwifiex_debug_info, n)) |
| 38 | |
| 39 | /* size/addr for struct mwifiex_adapter */ |
| 40 | #define adapter_item_size(n) (FIELD_SIZEOF(struct mwifiex_adapter, n)) |
| 41 | #define adapter_item_addr(n) (offsetof(struct mwifiex_adapter, n)) |
| 42 | |
| 43 | struct mwifiex_debug_data { |
| 44 | char name[32]; /* variable/array name */ |
| 45 | u32 size; /* size of the variable/array */ |
| 46 | size_t addr; /* address of the variable/array */ |
| 47 | int num; /* number of variables in an array */ |
| 48 | }; |
| 49 | |
| 50 | static struct mwifiex_debug_data items[] = { |
| 51 | {"int_counter", item_size(int_counter), |
| 52 | item_addr(int_counter), 1}, |
| 53 | {"wmm_ac_vo", item_size(packets_out[WMM_AC_VO]), |
| 54 | item_addr(packets_out[WMM_AC_VO]), 1}, |
| 55 | {"wmm_ac_vi", item_size(packets_out[WMM_AC_VI]), |
| 56 | item_addr(packets_out[WMM_AC_VI]), 1}, |
| 57 | {"wmm_ac_be", item_size(packets_out[WMM_AC_BE]), |
| 58 | item_addr(packets_out[WMM_AC_BE]), 1}, |
| 59 | {"wmm_ac_bk", item_size(packets_out[WMM_AC_BK]), |
| 60 | item_addr(packets_out[WMM_AC_BK]), 1}, |
| 61 | {"max_tx_buf_size", item_size(max_tx_buf_size), |
| 62 | item_addr(max_tx_buf_size), 1}, |
| 63 | {"tx_buf_size", item_size(tx_buf_size), |
| 64 | item_addr(tx_buf_size), 1}, |
| 65 | {"curr_tx_buf_size", item_size(curr_tx_buf_size), |
| 66 | item_addr(curr_tx_buf_size), 1}, |
| 67 | {"ps_mode", item_size(ps_mode), |
| 68 | item_addr(ps_mode), 1}, |
| 69 | {"ps_state", item_size(ps_state), |
| 70 | item_addr(ps_state), 1}, |
| 71 | {"is_deep_sleep", item_size(is_deep_sleep), |
| 72 | item_addr(is_deep_sleep), 1}, |
| 73 | {"wakeup_dev_req", item_size(pm_wakeup_card_req), |
| 74 | item_addr(pm_wakeup_card_req), 1}, |
| 75 | {"wakeup_tries", item_size(pm_wakeup_fw_try), |
| 76 | item_addr(pm_wakeup_fw_try), 1}, |
| 77 | {"hs_configured", item_size(is_hs_configured), |
| 78 | item_addr(is_hs_configured), 1}, |
| 79 | {"hs_activated", item_size(hs_activated), |
| 80 | item_addr(hs_activated), 1}, |
| 81 | {"num_tx_timeout", item_size(num_tx_timeout), |
| 82 | item_addr(num_tx_timeout), 1}, |
| 83 | {"num_cmd_timeout", item_size(num_cmd_timeout), |
| 84 | item_addr(num_cmd_timeout), 1}, |
| 85 | {"timeout_cmd_id", item_size(timeout_cmd_id), |
| 86 | item_addr(timeout_cmd_id), 1}, |
| 87 | {"timeout_cmd_act", item_size(timeout_cmd_act), |
| 88 | item_addr(timeout_cmd_act), 1}, |
| 89 | {"last_cmd_id", item_size(last_cmd_id), |
| 90 | item_addr(last_cmd_id), DBG_CMD_NUM}, |
| 91 | {"last_cmd_act", item_size(last_cmd_act), |
| 92 | item_addr(last_cmd_act), DBG_CMD_NUM}, |
| 93 | {"last_cmd_index", item_size(last_cmd_index), |
| 94 | item_addr(last_cmd_index), 1}, |
| 95 | {"last_cmd_resp_id", item_size(last_cmd_resp_id), |
| 96 | item_addr(last_cmd_resp_id), DBG_CMD_NUM}, |
| 97 | {"last_cmd_resp_index", item_size(last_cmd_resp_index), |
| 98 | item_addr(last_cmd_resp_index), 1}, |
| 99 | {"last_event", item_size(last_event), |
| 100 | item_addr(last_event), DBG_CMD_NUM}, |
| 101 | {"last_event_index", item_size(last_event_index), |
| 102 | item_addr(last_event_index), 1}, |
| 103 | {"num_cmd_h2c_fail", item_size(num_cmd_host_to_card_failure), |
| 104 | item_addr(num_cmd_host_to_card_failure), 1}, |
| 105 | {"num_cmd_sleep_cfm_fail", |
| 106 | item_size(num_cmd_sleep_cfm_host_to_card_failure), |
| 107 | item_addr(num_cmd_sleep_cfm_host_to_card_failure), 1}, |
| 108 | {"num_tx_h2c_fail", item_size(num_tx_host_to_card_failure), |
| 109 | item_addr(num_tx_host_to_card_failure), 1}, |
| 110 | {"num_evt_deauth", item_size(num_event_deauth), |
| 111 | item_addr(num_event_deauth), 1}, |
| 112 | {"num_evt_disassoc", item_size(num_event_disassoc), |
| 113 | item_addr(num_event_disassoc), 1}, |
| 114 | {"num_evt_link_lost", item_size(num_event_link_lost), |
| 115 | item_addr(num_event_link_lost), 1}, |
| 116 | {"num_cmd_deauth", item_size(num_cmd_deauth), |
| 117 | item_addr(num_cmd_deauth), 1}, |
| 118 | {"num_cmd_assoc_ok", item_size(num_cmd_assoc_success), |
| 119 | item_addr(num_cmd_assoc_success), 1}, |
| 120 | {"num_cmd_assoc_fail", item_size(num_cmd_assoc_failure), |
| 121 | item_addr(num_cmd_assoc_failure), 1}, |
| 122 | {"cmd_sent", item_size(cmd_sent), |
| 123 | item_addr(cmd_sent), 1}, |
| 124 | {"data_sent", item_size(data_sent), |
| 125 | item_addr(data_sent), 1}, |
| 126 | {"cmd_resp_received", item_size(cmd_resp_received), |
| 127 | item_addr(cmd_resp_received), 1}, |
| 128 | {"event_received", item_size(event_received), |
| 129 | item_addr(event_received), 1}, |
| 130 | |
| 131 | /* variables defined in struct mwifiex_adapter */ |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame^] | 132 | {"cmd_pending", adapter_item_size(cmd_pending), |
| 133 | adapter_item_addr(cmd_pending), 1}, |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 134 | {"tx_pending", adapter_item_size(tx_pending), |
| 135 | adapter_item_addr(tx_pending), 1}, |
| 136 | {"rx_pending", adapter_item_size(rx_pending), |
| 137 | adapter_item_addr(rx_pending), 1}, |
| 138 | }; |
| 139 | |
| 140 | static int num_of_items = ARRAY_SIZE(items); |
| 141 | |
| 142 | /* |
| 143 | * Generic proc file open handler. |
| 144 | * |
| 145 | * This function is called every time a file is accessed for read or write. |
| 146 | */ |
| 147 | static int |
| 148 | mwifiex_open_generic(struct inode *inode, struct file *file) |
| 149 | { |
| 150 | file->private_data = inode->i_private; |
| 151 | return 0; |
| 152 | } |
| 153 | |
| 154 | /* |
| 155 | * Proc info file read handler. |
| 156 | * |
| 157 | * This function is called when the 'info' file is opened for reading. |
| 158 | * It prints the following driver related information - |
| 159 | * - Driver name |
| 160 | * - Driver version |
| 161 | * - Driver extended version |
| 162 | * - Interface name |
| 163 | * - BSS mode |
| 164 | * - Media state (connected or disconnected) |
| 165 | * - MAC address |
| 166 | * - Total number of Tx bytes |
| 167 | * - Total number of Rx bytes |
| 168 | * - Total number of Tx packets |
| 169 | * - Total number of Rx packets |
| 170 | * - Total number of dropped Tx packets |
| 171 | * - Total number of dropped Rx packets |
| 172 | * - Total number of corrupted Tx packets |
| 173 | * - Total number of corrupted Rx packets |
| 174 | * - Carrier status (on or off) |
| 175 | * - Tx queue status (started or stopped) |
| 176 | * |
| 177 | * For STA mode drivers, it also prints the following extra - |
| 178 | * - ESSID |
| 179 | * - BSSID |
| 180 | * - Channel |
| 181 | * - Region code |
| 182 | * - Multicast count |
| 183 | * - Multicast addresses |
| 184 | */ |
| 185 | static ssize_t |
| 186 | mwifiex_info_read(struct file *file, char __user *ubuf, |
| 187 | size_t count, loff_t *ppos) |
| 188 | { |
| 189 | struct mwifiex_private *priv = |
| 190 | (struct mwifiex_private *) file->private_data; |
| 191 | struct net_device *netdev = priv->netdev; |
| 192 | struct netdev_hw_addr *ha; |
| 193 | unsigned long page = get_zeroed_page(GFP_KERNEL); |
| 194 | char *p = (char *) page, fmt[64]; |
| 195 | struct mwifiex_bss_info info; |
| 196 | ssize_t ret = 0; |
| 197 | int i = 0; |
| 198 | |
| 199 | if (!p) |
| 200 | return -ENOMEM; |
| 201 | |
| 202 | memset(&info, 0, sizeof(info)); |
| 203 | ret = mwifiex_get_bss_info(priv, &info); |
| 204 | if (ret) |
| 205 | goto free_and_exit; |
| 206 | |
| 207 | mwifiex_drv_get_driver_version(priv->adapter, fmt, sizeof(fmt) - 1); |
| 208 | |
| 209 | if (!priv->version_str[0]) |
| 210 | mwifiex_get_ver_ext(priv); |
| 211 | |
| 212 | p += sprintf(p, "driver_name = " "\"mwifiex\"\n"); |
| 213 | p += sprintf(p, "driver_version = %s", fmt); |
| 214 | p += sprintf(p, "\nverext = %s", priv->version_str); |
| 215 | p += sprintf(p, "\ninterface_name=\"%s\"\n", netdev->name); |
| 216 | p += sprintf(p, "bss_mode=\"%s\"\n", bss_modes[info.bss_mode]); |
| 217 | p += sprintf(p, "media_state=\"%s\"\n", |
| 218 | (!priv->media_connected ? "Disconnected" : "Connected")); |
| 219 | p += sprintf(p, "mac_address=\"%02x:%02x:%02x:%02x:%02x:%02x\"\n", |
| 220 | netdev->dev_addr[0], netdev->dev_addr[1], |
| 221 | netdev->dev_addr[2], netdev->dev_addr[3], |
| 222 | netdev->dev_addr[4], netdev->dev_addr[5]); |
| 223 | |
| 224 | if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) { |
| 225 | p += sprintf(p, "multicast_count=\"%d\"\n", |
| 226 | netdev_mc_count(netdev)); |
| 227 | p += sprintf(p, "essid=\"%s\"\n", info.ssid.ssid); |
| 228 | p += sprintf(p, "bssid=\"%02x:%02x:%02x:%02x:%02x:%02x\"\n", |
| 229 | info.bssid[0], info.bssid[1], |
| 230 | info.bssid[2], info.bssid[3], |
| 231 | info.bssid[4], info.bssid[5]); |
| 232 | p += sprintf(p, "channel=\"%d\"\n", (int) info.bss_chan); |
| 233 | p += sprintf(p, "region_code = \"%02x\"\n", info.region_code); |
| 234 | |
| 235 | netdev_for_each_mc_addr(ha, netdev) |
| 236 | p += sprintf(p, "multicast_address[%d]=" |
| 237 | "\"%02x:%02x:%02x:%02x:%02x:%02x\"\n", i++, |
| 238 | ha->addr[0], ha->addr[1], |
| 239 | ha->addr[2], ha->addr[3], |
| 240 | ha->addr[4], ha->addr[5]); |
| 241 | } |
| 242 | |
| 243 | p += sprintf(p, "num_tx_bytes = %lu\n", priv->stats.tx_bytes); |
| 244 | p += sprintf(p, "num_rx_bytes = %lu\n", priv->stats.rx_bytes); |
| 245 | p += sprintf(p, "num_tx_pkts = %lu\n", priv->stats.tx_packets); |
| 246 | p += sprintf(p, "num_rx_pkts = %lu\n", priv->stats.rx_packets); |
| 247 | p += sprintf(p, "num_tx_pkts_dropped = %lu\n", priv->stats.tx_dropped); |
| 248 | p += sprintf(p, "num_rx_pkts_dropped = %lu\n", priv->stats.rx_dropped); |
| 249 | p += sprintf(p, "num_tx_pkts_err = %lu\n", priv->stats.tx_errors); |
| 250 | p += sprintf(p, "num_rx_pkts_err = %lu\n", priv->stats.rx_errors); |
| 251 | p += sprintf(p, "carrier %s\n", ((netif_carrier_ok(priv->netdev)) |
| 252 | ? "on" : "off")); |
| 253 | p += sprintf(p, "tx queue %s\n", ((netif_queue_stopped(priv->netdev)) |
| 254 | ? "stopped" : "started")); |
| 255 | |
| 256 | ret = simple_read_from_buffer(ubuf, count, ppos, (char *) page, |
| 257 | (unsigned long) p - page); |
| 258 | |
| 259 | free_and_exit: |
| 260 | free_page(page); |
| 261 | return ret; |
| 262 | } |
| 263 | |
| 264 | /* |
| 265 | * Proc getlog file read handler. |
| 266 | * |
| 267 | * This function is called when the 'getlog' file is opened for reading |
| 268 | * It prints the following log information - |
| 269 | * - Number of multicast Tx frames |
| 270 | * - Number of failed packets |
| 271 | * - Number of Tx retries |
| 272 | * - Number of multicast Tx retries |
| 273 | * - Number of duplicate frames |
| 274 | * - Number of RTS successes |
| 275 | * - Number of RTS failures |
| 276 | * - Number of ACK failures |
| 277 | * - Number of fragmented Rx frames |
| 278 | * - Number of multicast Rx frames |
| 279 | * - Number of FCS errors |
| 280 | * - Number of Tx frames |
| 281 | * - WEP ICV error counts |
| 282 | */ |
| 283 | static ssize_t |
| 284 | mwifiex_getlog_read(struct file *file, char __user *ubuf, |
| 285 | size_t count, loff_t *ppos) |
| 286 | { |
| 287 | struct mwifiex_private *priv = |
| 288 | (struct mwifiex_private *) file->private_data; |
| 289 | unsigned long page = get_zeroed_page(GFP_KERNEL); |
| 290 | char *p = (char *) page; |
| 291 | ssize_t ret = 0; |
| 292 | struct mwifiex_ds_get_stats stats; |
| 293 | |
| 294 | if (!p) |
| 295 | return -ENOMEM; |
| 296 | |
| 297 | memset(&stats, 0, sizeof(stats)); |
| 298 | ret = mwifiex_get_stats_info(priv, &stats); |
| 299 | if (ret) |
| 300 | goto free_and_exit; |
| 301 | |
| 302 | p += sprintf(p, "\n" |
| 303 | "mcasttxframe %u\n" |
| 304 | "failed %u\n" |
| 305 | "retry %u\n" |
| 306 | "multiretry %u\n" |
| 307 | "framedup %u\n" |
| 308 | "rtssuccess %u\n" |
| 309 | "rtsfailure %u\n" |
| 310 | "ackfailure %u\n" |
| 311 | "rxfrag %u\n" |
| 312 | "mcastrxframe %u\n" |
| 313 | "fcserror %u\n" |
| 314 | "txframe %u\n" |
| 315 | "wepicverrcnt-1 %u\n" |
| 316 | "wepicverrcnt-2 %u\n" |
| 317 | "wepicverrcnt-3 %u\n" |
| 318 | "wepicverrcnt-4 %u\n", |
| 319 | stats.mcast_tx_frame, |
| 320 | stats.failed, |
| 321 | stats.retry, |
| 322 | stats.multi_retry, |
| 323 | stats.frame_dup, |
| 324 | stats.rts_success, |
| 325 | stats.rts_failure, |
| 326 | stats.ack_failure, |
| 327 | stats.rx_frag, |
| 328 | stats.mcast_rx_frame, |
| 329 | stats.fcs_error, |
| 330 | stats.tx_frame, |
| 331 | stats.wep_icv_error[0], |
| 332 | stats.wep_icv_error[1], |
| 333 | stats.wep_icv_error[2], |
| 334 | stats.wep_icv_error[3]); |
| 335 | |
| 336 | |
| 337 | ret = simple_read_from_buffer(ubuf, count, ppos, (char *) page, |
| 338 | (unsigned long) p - page); |
| 339 | |
| 340 | free_and_exit: |
| 341 | free_page(page); |
| 342 | return ret; |
| 343 | } |
| 344 | |
| 345 | static struct mwifiex_debug_info info; |
| 346 | |
| 347 | /* |
| 348 | * Proc debug file read handler. |
| 349 | * |
| 350 | * This function is called when the 'debug' file is opened for reading |
| 351 | * It prints the following log information - |
| 352 | * - Interrupt count |
| 353 | * - WMM AC VO packets count |
| 354 | * - WMM AC VI packets count |
| 355 | * - WMM AC BE packets count |
| 356 | * - WMM AC BK packets count |
| 357 | * - Maximum Tx buffer size |
| 358 | * - Tx buffer size |
| 359 | * - Current Tx buffer size |
| 360 | * - Power Save mode |
| 361 | * - Power Save state |
| 362 | * - Deep Sleep status |
| 363 | * - Device wakeup required status |
| 364 | * - Number of wakeup tries |
| 365 | * - Host Sleep configured status |
| 366 | * - Host Sleep activated status |
| 367 | * - Number of Tx timeouts |
| 368 | * - Number of command timeouts |
| 369 | * - Last timed out command ID |
| 370 | * - Last timed out command action |
| 371 | * - Last command ID |
| 372 | * - Last command action |
| 373 | * - Last command index |
| 374 | * - Last command response ID |
| 375 | * - Last command response index |
| 376 | * - Last event |
| 377 | * - Last event index |
| 378 | * - Number of host to card command failures |
| 379 | * - Number of sleep confirm command failures |
| 380 | * - Number of host to card data failure |
| 381 | * - Number of deauthentication events |
| 382 | * - Number of disassociation events |
| 383 | * - Number of link lost events |
| 384 | * - Number of deauthentication commands |
| 385 | * - Number of association success commands |
| 386 | * - Number of association failure commands |
| 387 | * - Number of commands sent |
| 388 | * - Number of data packets sent |
| 389 | * - Number of command responses received |
| 390 | * - Number of events received |
| 391 | * - Tx BA stream table (TID, RA) |
| 392 | * - Rx reorder table (TID, TA, Start window, Window size, Buffer) |
| 393 | */ |
| 394 | static ssize_t |
| 395 | mwifiex_debug_read(struct file *file, char __user *ubuf, |
| 396 | size_t count, loff_t *ppos) |
| 397 | { |
| 398 | struct mwifiex_private *priv = |
| 399 | (struct mwifiex_private *) file->private_data; |
| 400 | struct mwifiex_debug_data *d = &items[0]; |
| 401 | unsigned long page = get_zeroed_page(GFP_KERNEL); |
| 402 | char *p = (char *) page; |
| 403 | ssize_t ret = 0; |
| 404 | size_t size, addr; |
| 405 | long val; |
| 406 | int i, j; |
| 407 | |
| 408 | if (!p) |
| 409 | return -ENOMEM; |
| 410 | |
| 411 | ret = mwifiex_get_debug_info(priv, &info); |
| 412 | if (ret) |
| 413 | goto free_and_exit; |
| 414 | |
| 415 | for (i = 0; i < num_of_items; i++) { |
| 416 | p += sprintf(p, "%s=", d[i].name); |
| 417 | |
| 418 | size = d[i].size / d[i].num; |
| 419 | |
| 420 | if (i < (num_of_items - 3)) |
| 421 | addr = d[i].addr + (size_t) &info; |
| 422 | else /* The last 3 items are struct mwifiex_adapter variables */ |
| 423 | addr = d[i].addr + (size_t) priv->adapter; |
| 424 | |
| 425 | for (j = 0; j < d[i].num; j++) { |
| 426 | switch (size) { |
| 427 | case 1: |
| 428 | val = *((u8 *) addr); |
| 429 | break; |
| 430 | case 2: |
| 431 | val = *((u16 *) addr); |
| 432 | break; |
| 433 | case 4: |
| 434 | val = *((u32 *) addr); |
| 435 | break; |
| 436 | case 8: |
| 437 | val = *((long long *) addr); |
| 438 | break; |
| 439 | default: |
| 440 | val = -1; |
| 441 | break; |
| 442 | } |
| 443 | |
| 444 | p += sprintf(p, "%#lx ", val); |
| 445 | addr += size; |
| 446 | } |
| 447 | |
| 448 | p += sprintf(p, "\n"); |
| 449 | } |
| 450 | |
| 451 | if (info.tx_tbl_num) { |
| 452 | p += sprintf(p, "Tx BA stream table:\n"); |
| 453 | for (i = 0; i < info.tx_tbl_num; i++) |
| 454 | p += sprintf(p, "tid = %d, " |
| 455 | "ra = %02x:%02x:%02x:%02x:%02x:%02x\n", |
| 456 | info.tx_tbl[i].tid, info.tx_tbl[i].ra[0], |
| 457 | info.tx_tbl[i].ra[1], info.tx_tbl[i].ra[2], |
| 458 | info.tx_tbl[i].ra[3], info.tx_tbl[i].ra[4], |
| 459 | info.tx_tbl[i].ra[5]); |
| 460 | } |
| 461 | |
| 462 | if (info.rx_tbl_num) { |
| 463 | p += sprintf(p, "Rx reorder table:\n"); |
| 464 | for (i = 0; i < info.rx_tbl_num; i++) { |
| 465 | |
| 466 | p += sprintf(p, "tid = %d, " |
| 467 | "ta = %02x:%02x:%02x:%02x:%02x:%02x, " |
| 468 | "start_win = %d, " |
| 469 | "win_size = %d, buffer: ", |
| 470 | info.rx_tbl[i].tid, |
| 471 | info.rx_tbl[i].ta[0], info.rx_tbl[i].ta[1], |
| 472 | info.rx_tbl[i].ta[2], info.rx_tbl[i].ta[3], |
| 473 | info.rx_tbl[i].ta[4], info.rx_tbl[i].ta[5], |
| 474 | info.rx_tbl[i].start_win, |
| 475 | info.rx_tbl[i].win_size); |
| 476 | |
| 477 | for (j = 0; j < info.rx_tbl[i].win_size; j++) |
| 478 | p += sprintf(p, "%c ", |
| 479 | info.rx_tbl[i].buffer[j] ? |
| 480 | '1' : '0'); |
| 481 | |
| 482 | p += sprintf(p, "\n"); |
| 483 | } |
| 484 | } |
| 485 | |
| 486 | ret = simple_read_from_buffer(ubuf, count, ppos, (char *) page, |
| 487 | (unsigned long) p - page); |
| 488 | |
| 489 | free_and_exit: |
| 490 | free_page(page); |
| 491 | return ret; |
| 492 | } |
| 493 | |
| 494 | static u32 saved_reg_type, saved_reg_offset, saved_reg_value; |
| 495 | |
| 496 | /* |
| 497 | * Proc regrdwr file write handler. |
| 498 | * |
| 499 | * This function is called when the 'regrdwr' file is opened for writing |
| 500 | * |
| 501 | * This function can be used to write to a register. |
| 502 | */ |
| 503 | static ssize_t |
| 504 | mwifiex_regrdwr_write(struct file *file, |
| 505 | const char __user *ubuf, size_t count, loff_t *ppos) |
| 506 | { |
| 507 | unsigned long addr = get_zeroed_page(GFP_KERNEL); |
| 508 | char *buf = (char *) addr; |
| 509 | size_t buf_size = min(count, (size_t) (PAGE_SIZE - 1)); |
| 510 | int ret = 0; |
| 511 | u32 reg_type = 0, reg_offset = 0, reg_value = UINT_MAX; |
| 512 | |
| 513 | if (!buf) |
| 514 | return -ENOMEM; |
| 515 | |
| 516 | |
| 517 | if (copy_from_user(buf, ubuf, buf_size)) { |
| 518 | ret = -EFAULT; |
| 519 | goto done; |
| 520 | } |
| 521 | |
| 522 | sscanf(buf, "%u %x %x", ®_type, ®_offset, ®_value); |
| 523 | |
| 524 | if (reg_type == 0 || reg_offset == 0) { |
| 525 | ret = -EINVAL; |
| 526 | goto done; |
| 527 | } else { |
| 528 | saved_reg_type = reg_type; |
| 529 | saved_reg_offset = reg_offset; |
| 530 | saved_reg_value = reg_value; |
| 531 | ret = count; |
| 532 | } |
| 533 | done: |
| 534 | free_page(addr); |
| 535 | return ret; |
| 536 | } |
| 537 | |
| 538 | /* |
| 539 | * Proc regrdwr file read handler. |
| 540 | * |
| 541 | * This function is called when the 'regrdwr' file is opened for reading |
| 542 | * |
| 543 | * This function can be used to read from a register. |
| 544 | */ |
| 545 | static ssize_t |
| 546 | mwifiex_regrdwr_read(struct file *file, char __user *ubuf, |
| 547 | size_t count, loff_t *ppos) |
| 548 | { |
| 549 | struct mwifiex_private *priv = |
| 550 | (struct mwifiex_private *) file->private_data; |
| 551 | unsigned long addr = get_zeroed_page(GFP_KERNEL); |
| 552 | char *buf = (char *) addr; |
| 553 | int pos = 0, ret = 0; |
| 554 | u32 reg_value; |
| 555 | |
| 556 | if (!buf) |
| 557 | return -ENOMEM; |
| 558 | |
| 559 | if (!saved_reg_type) { |
| 560 | /* No command has been given */ |
| 561 | pos += snprintf(buf, PAGE_SIZE, "0"); |
| 562 | goto done; |
| 563 | } |
| 564 | /* Set command has been given */ |
| 565 | if (saved_reg_value != UINT_MAX) { |
| 566 | ret = mwifiex_reg_write(priv, saved_reg_type, saved_reg_offset, |
| 567 | saved_reg_value); |
| 568 | |
| 569 | pos += snprintf(buf, PAGE_SIZE, "%u 0x%x 0x%x\n", |
| 570 | saved_reg_type, saved_reg_offset, |
| 571 | saved_reg_value); |
| 572 | |
| 573 | ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos); |
| 574 | |
| 575 | goto done; |
| 576 | } |
| 577 | /* Get command has been given */ |
| 578 | ret = mwifiex_reg_read(priv, saved_reg_type, |
| 579 | saved_reg_offset, ®_value); |
| 580 | if (ret) { |
| 581 | ret = -EINVAL; |
| 582 | goto done; |
| 583 | } |
| 584 | |
| 585 | pos += snprintf(buf, PAGE_SIZE, "%u 0x%x 0x%x\n", saved_reg_type, |
| 586 | saved_reg_offset, reg_value); |
| 587 | |
| 588 | ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos); |
| 589 | |
| 590 | done: |
| 591 | free_page(addr); |
| 592 | return ret; |
| 593 | } |
| 594 | |
| 595 | static u32 saved_offset = -1, saved_bytes = -1; |
| 596 | |
| 597 | /* |
| 598 | * Proc rdeeprom file write handler. |
| 599 | * |
| 600 | * This function is called when the 'rdeeprom' file is opened for writing |
| 601 | * |
| 602 | * This function can be used to write to a RDEEPROM location. |
| 603 | */ |
| 604 | static ssize_t |
| 605 | mwifiex_rdeeprom_write(struct file *file, |
| 606 | const char __user *ubuf, size_t count, loff_t *ppos) |
| 607 | { |
| 608 | unsigned long addr = get_zeroed_page(GFP_KERNEL); |
| 609 | char *buf = (char *) addr; |
| 610 | size_t buf_size = min(count, (size_t) (PAGE_SIZE - 1)); |
| 611 | int ret = 0; |
| 612 | int offset = -1, bytes = -1; |
| 613 | |
| 614 | if (!buf) |
| 615 | return -ENOMEM; |
| 616 | |
| 617 | |
| 618 | if (copy_from_user(buf, ubuf, buf_size)) { |
| 619 | ret = -EFAULT; |
| 620 | goto done; |
| 621 | } |
| 622 | |
| 623 | sscanf(buf, "%d %d", &offset, &bytes); |
| 624 | |
| 625 | if (offset == -1 || bytes == -1) { |
| 626 | ret = -EINVAL; |
| 627 | goto done; |
| 628 | } else { |
| 629 | saved_offset = offset; |
| 630 | saved_bytes = bytes; |
| 631 | ret = count; |
| 632 | } |
| 633 | done: |
| 634 | free_page(addr); |
| 635 | return ret; |
| 636 | } |
| 637 | |
| 638 | /* |
| 639 | * Proc rdeeprom read write handler. |
| 640 | * |
| 641 | * This function is called when the 'rdeeprom' file is opened for reading |
| 642 | * |
| 643 | * This function can be used to read from a RDEEPROM location. |
| 644 | */ |
| 645 | static ssize_t |
| 646 | mwifiex_rdeeprom_read(struct file *file, char __user *ubuf, |
| 647 | size_t count, loff_t *ppos) |
| 648 | { |
| 649 | struct mwifiex_private *priv = |
| 650 | (struct mwifiex_private *) file->private_data; |
| 651 | unsigned long addr = get_zeroed_page(GFP_KERNEL); |
| 652 | char *buf = (char *) addr; |
| 653 | int pos = 0, ret = 0, i = 0; |
| 654 | u8 value[MAX_EEPROM_DATA]; |
| 655 | |
| 656 | if (!buf) |
| 657 | return -ENOMEM; |
| 658 | |
| 659 | if (saved_offset == -1) { |
| 660 | /* No command has been given */ |
| 661 | pos += snprintf(buf, PAGE_SIZE, "0"); |
| 662 | goto done; |
| 663 | } |
| 664 | |
| 665 | /* Get command has been given */ |
| 666 | ret = mwifiex_eeprom_read(priv, (u16) saved_offset, |
| 667 | (u16) saved_bytes, value); |
| 668 | if (ret) { |
| 669 | ret = -EINVAL; |
| 670 | goto done; |
| 671 | } |
| 672 | |
| 673 | pos += snprintf(buf, PAGE_SIZE, "%d %d ", saved_offset, saved_bytes); |
| 674 | |
| 675 | for (i = 0; i < saved_bytes; i++) |
| 676 | pos += snprintf(buf + strlen(buf), PAGE_SIZE, "%d ", value[i]); |
| 677 | |
| 678 | ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos); |
| 679 | |
| 680 | done: |
| 681 | free_page(addr); |
| 682 | return ret; |
| 683 | } |
| 684 | |
| 685 | |
| 686 | #define MWIFIEX_DFS_ADD_FILE(name) do { \ |
| 687 | if (!debugfs_create_file(#name, 0644, priv->dfs_dev_dir, \ |
| 688 | priv, &mwifiex_dfs_##name##_fops)) \ |
| 689 | return; \ |
| 690 | } while (0); |
| 691 | |
| 692 | #define MWIFIEX_DFS_FILE_OPS(name) \ |
| 693 | static const struct file_operations mwifiex_dfs_##name##_fops = { \ |
| 694 | .read = mwifiex_##name##_read, \ |
| 695 | .write = mwifiex_##name##_write, \ |
| 696 | .open = mwifiex_open_generic, \ |
| 697 | }; |
| 698 | |
| 699 | #define MWIFIEX_DFS_FILE_READ_OPS(name) \ |
| 700 | static const struct file_operations mwifiex_dfs_##name##_fops = { \ |
| 701 | .read = mwifiex_##name##_read, \ |
| 702 | .open = mwifiex_open_generic, \ |
| 703 | }; |
| 704 | |
| 705 | #define MWIFIEX_DFS_FILE_WRITE_OPS(name) \ |
| 706 | static const struct file_operations mwifiex_dfs_##name##_fops = { \ |
| 707 | .write = mwifiex_##name##_write, \ |
| 708 | .open = mwifiex_open_generic, \ |
| 709 | }; |
| 710 | |
| 711 | |
| 712 | MWIFIEX_DFS_FILE_READ_OPS(info); |
| 713 | MWIFIEX_DFS_FILE_READ_OPS(debug); |
| 714 | MWIFIEX_DFS_FILE_READ_OPS(getlog); |
| 715 | MWIFIEX_DFS_FILE_OPS(regrdwr); |
| 716 | MWIFIEX_DFS_FILE_OPS(rdeeprom); |
| 717 | |
| 718 | /* |
| 719 | * This function creates the debug FS directory structure and the files. |
| 720 | */ |
| 721 | void |
| 722 | mwifiex_dev_debugfs_init(struct mwifiex_private *priv) |
| 723 | { |
| 724 | if (!mwifiex_dfs_dir || !priv) |
| 725 | return; |
| 726 | |
| 727 | priv->dfs_dev_dir = debugfs_create_dir(priv->netdev->name, |
| 728 | mwifiex_dfs_dir); |
| 729 | |
| 730 | if (!priv->dfs_dev_dir) |
| 731 | return; |
| 732 | |
| 733 | MWIFIEX_DFS_ADD_FILE(info); |
| 734 | MWIFIEX_DFS_ADD_FILE(debug); |
| 735 | MWIFIEX_DFS_ADD_FILE(getlog); |
| 736 | MWIFIEX_DFS_ADD_FILE(regrdwr); |
| 737 | MWIFIEX_DFS_ADD_FILE(rdeeprom); |
| 738 | |
| 739 | return; |
| 740 | } |
| 741 | |
| 742 | /* |
| 743 | * This function removes the debug FS directory structure and the files. |
| 744 | */ |
| 745 | void |
| 746 | mwifiex_dev_debugfs_remove(struct mwifiex_private *priv) |
| 747 | { |
| 748 | if (!priv) |
| 749 | return; |
| 750 | |
| 751 | debugfs_remove_recursive(priv->dfs_dev_dir); |
| 752 | return; |
| 753 | } |
| 754 | |
| 755 | /* |
| 756 | * This function creates the top level proc directory. |
| 757 | */ |
| 758 | void |
| 759 | mwifiex_debugfs_init(void) |
| 760 | { |
| 761 | if (!mwifiex_dfs_dir) |
| 762 | mwifiex_dfs_dir = debugfs_create_dir("mwifiex", NULL); |
| 763 | } |
| 764 | |
| 765 | /* |
| 766 | * This function removes the top level proc directory. |
| 767 | */ |
| 768 | void |
| 769 | mwifiex_debugfs_remove(void) |
| 770 | { |
| 771 | if (mwifiex_dfs_dir) |
| 772 | debugfs_remove(mwifiex_dfs_dir); |
| 773 | } |