Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1 | #include <linux/module.h> |
| 2 | #include <linux/dcache.h> |
| 3 | #include <linux/debugfs.h> |
| 4 | #include <linux/delay.h> |
| 5 | #include <linux/mm.h> |
Geert Uytterhoeven | d8b0fb5 | 2007-10-08 09:43:02 +0200 | [diff] [blame] | 6 | #include <linux/string.h> |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 7 | #include <net/iw_handler.h> |
John W. Linville | 7e272fc | 2008-09-24 18:13:14 -0400 | [diff] [blame] | 8 | #include <net/lib80211.h> |
Holger Schurig | 4686820 | 2007-05-25 00:37:28 -0400 | [diff] [blame] | 9 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 10 | #include "dev.h" |
| 11 | #include "decl.h" |
| 12 | #include "host.h" |
Dan Williams | 5bdb3ef | 2007-05-10 23:08:05 -0400 | [diff] [blame] | 13 | #include "debugfs.h" |
David Woodhouse | 3fbe104 | 2007-12-17 23:48:31 -0500 | [diff] [blame] | 14 | #include "cmd.h" |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 15 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 16 | static struct dentry *lbs_dir; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 17 | static char *szStates[] = { |
| 18 | "Connected", |
| 19 | "Disconnected" |
| 20 | }; |
| 21 | |
Holger Schurig | 4686820 | 2007-05-25 00:37:28 -0400 | [diff] [blame] | 22 | #ifdef PROC_DEBUG |
Holger Schurig | e98a88d | 2008-03-19 14:25:58 +0100 | [diff] [blame] | 23 | static void lbs_debug_init(struct lbs_private *priv); |
Holger Schurig | 4686820 | 2007-05-25 00:37:28 -0400 | [diff] [blame] | 24 | #endif |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 25 | |
| 26 | static int open_file_generic(struct inode *inode, struct file *file) |
| 27 | { |
| 28 | file->private_data = inode->i_private; |
| 29 | return 0; |
| 30 | } |
| 31 | |
| 32 | static ssize_t write_file_dummy(struct file *file, const char __user *buf, |
| 33 | size_t count, loff_t *ppos) |
| 34 | { |
| 35 | return -EINVAL; |
| 36 | } |
| 37 | |
| 38 | static const size_t len = PAGE_SIZE; |
| 39 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 40 | static ssize_t lbs_dev_info(struct file *file, char __user *userbuf, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 41 | size_t count, loff_t *ppos) |
| 42 | { |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 43 | struct lbs_private *priv = file->private_data; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 44 | size_t pos = 0; |
| 45 | unsigned long addr = get_zeroed_page(GFP_KERNEL); |
| 46 | char *buf = (char *)addr; |
| 47 | ssize_t res; |
| 48 | |
| 49 | pos += snprintf(buf+pos, len-pos, "state = %s\n", |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 50 | szStates[priv->connect_status]); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 51 | pos += snprintf(buf+pos, len-pos, "region_code = %02x\n", |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 52 | (u32) priv->regioncode); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 53 | |
| 54 | res = simple_read_from_buffer(userbuf, count, ppos, buf, pos); |
| 55 | |
| 56 | free_page(addr); |
| 57 | return res; |
| 58 | } |
| 59 | |
| 60 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 61 | static ssize_t lbs_getscantable(struct file *file, char __user *userbuf, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 62 | size_t count, loff_t *ppos) |
| 63 | { |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 64 | struct lbs_private *priv = file->private_data; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 65 | size_t pos = 0; |
| 66 | int numscansdone = 0, res; |
| 67 | unsigned long addr = get_zeroed_page(GFP_KERNEL); |
| 68 | char *buf = (char *)addr; |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 69 | DECLARE_SSID_BUF(ssid); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 70 | struct bss_descriptor * iter_bss; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 71 | |
| 72 | pos += snprintf(buf+pos, len-pos, |
Holger Schurig | a2235ed | 2007-08-02 13:12:45 -0400 | [diff] [blame] | 73 | "# | ch | rssi | bssid | cap | Qual | SSID \n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 74 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 75 | mutex_lock(&priv->lock); |
| 76 | list_for_each_entry (iter_bss, &priv->network_list, list) { |
Dan Williams | 0c9ca690 | 2007-08-02 10:43:44 -0400 | [diff] [blame] | 77 | u16 ibss = (iter_bss->capability & WLAN_CAPABILITY_IBSS); |
| 78 | u16 privacy = (iter_bss->capability & WLAN_CAPABILITY_PRIVACY); |
| 79 | u16 spectrum_mgmt = (iter_bss->capability & WLAN_CAPABILITY_SPECTRUM_MGMT); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 80 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 81 | pos += snprintf(buf+pos, len-pos, "%02u| %03d | %04d | %pM |", |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 82 | numscansdone, iter_bss->channel, iter_bss->rssi, |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 83 | iter_bss->bssid); |
Dan Williams | 0c9ca690 | 2007-08-02 10:43:44 -0400 | [diff] [blame] | 84 | pos += snprintf(buf+pos, len-pos, " %04x-", iter_bss->capability); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 85 | pos += snprintf(buf+pos, len-pos, "%c%c%c |", |
Dan Williams | 0c9ca690 | 2007-08-02 10:43:44 -0400 | [diff] [blame] | 86 | ibss ? 'A' : 'I', privacy ? 'P' : ' ', |
| 87 | spectrum_mgmt ? 'S' : ' '); |
Holger Schurig | a2235ed | 2007-08-02 13:12:45 -0400 | [diff] [blame] | 88 | pos += snprintf(buf+pos, len-pos, " %04d |", SCAN_RSSI(iter_bss->rssi)); |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 89 | pos += snprintf(buf+pos, len-pos, " %s\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 90 | print_ssid(ssid, iter_bss->ssid, |
| 91 | iter_bss->ssid_len)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 92 | |
| 93 | numscansdone++; |
| 94 | } |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 95 | mutex_unlock(&priv->lock); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 96 | |
| 97 | res = simple_read_from_buffer(userbuf, count, ppos, buf, pos); |
| 98 | |
| 99 | free_page(addr); |
| 100 | return res; |
| 101 | } |
| 102 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 103 | static ssize_t lbs_sleepparams_write(struct file *file, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 104 | const char __user *user_buf, size_t count, |
| 105 | loff_t *ppos) |
| 106 | { |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 107 | struct lbs_private *priv = file->private_data; |
David Woodhouse | 3fbe104 | 2007-12-17 23:48:31 -0500 | [diff] [blame] | 108 | ssize_t buf_size, ret; |
| 109 | struct sleep_params sp; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 110 | int p1, p2, p3, p4, p5, p6; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 111 | unsigned long addr = get_zeroed_page(GFP_KERNEL); |
| 112 | char *buf = (char *)addr; |
| 113 | |
| 114 | buf_size = min(count, len - 1); |
| 115 | if (copy_from_user(buf, user_buf, buf_size)) { |
David Woodhouse | 3fbe104 | 2007-12-17 23:48:31 -0500 | [diff] [blame] | 116 | ret = -EFAULT; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 117 | goto out_unlock; |
| 118 | } |
David Woodhouse | 3fbe104 | 2007-12-17 23:48:31 -0500 | [diff] [blame] | 119 | ret = sscanf(buf, "%d %d %d %d %d %d", &p1, &p2, &p3, &p4, &p5, &p6); |
| 120 | if (ret != 6) { |
| 121 | ret = -EINVAL; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 122 | goto out_unlock; |
| 123 | } |
David Woodhouse | 3fbe104 | 2007-12-17 23:48:31 -0500 | [diff] [blame] | 124 | sp.sp_error = p1; |
| 125 | sp.sp_offset = p2; |
| 126 | sp.sp_stabletime = p3; |
| 127 | sp.sp_calcontrol = p4; |
| 128 | sp.sp_extsleepclk = p5; |
| 129 | sp.sp_reserved = p6; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 130 | |
David Woodhouse | 3fbe104 | 2007-12-17 23:48:31 -0500 | [diff] [blame] | 131 | ret = lbs_cmd_802_11_sleep_params(priv, CMD_ACT_SET, &sp); |
| 132 | if (!ret) |
| 133 | ret = count; |
| 134 | else if (ret > 0) |
| 135 | ret = -EINVAL; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 136 | |
| 137 | out_unlock: |
| 138 | free_page(addr); |
David Woodhouse | 3fbe104 | 2007-12-17 23:48:31 -0500 | [diff] [blame] | 139 | return ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 140 | } |
| 141 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 142 | static ssize_t lbs_sleepparams_read(struct file *file, char __user *userbuf, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 143 | size_t count, loff_t *ppos) |
| 144 | { |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 145 | struct lbs_private *priv = file->private_data; |
David Woodhouse | 3fbe104 | 2007-12-17 23:48:31 -0500 | [diff] [blame] | 146 | ssize_t ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 147 | size_t pos = 0; |
David Woodhouse | 3fbe104 | 2007-12-17 23:48:31 -0500 | [diff] [blame] | 148 | struct sleep_params sp; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 149 | unsigned long addr = get_zeroed_page(GFP_KERNEL); |
| 150 | char *buf = (char *)addr; |
| 151 | |
David Woodhouse | 3fbe104 | 2007-12-17 23:48:31 -0500 | [diff] [blame] | 152 | ret = lbs_cmd_802_11_sleep_params(priv, CMD_ACT_GET, &sp); |
| 153 | if (ret) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 154 | goto out_unlock; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 155 | |
David Woodhouse | 3fbe104 | 2007-12-17 23:48:31 -0500 | [diff] [blame] | 156 | pos += snprintf(buf, len, "%d %d %d %d %d %d\n", sp.sp_error, |
| 157 | sp.sp_offset, sp.sp_stabletime, |
| 158 | sp.sp_calcontrol, sp.sp_extsleepclk, |
| 159 | sp.sp_reserved); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 160 | |
David Woodhouse | 3fbe104 | 2007-12-17 23:48:31 -0500 | [diff] [blame] | 161 | ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 162 | |
| 163 | out_unlock: |
| 164 | free_page(addr); |
David Woodhouse | 3fbe104 | 2007-12-17 23:48:31 -0500 | [diff] [blame] | 165 | return ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 166 | } |
| 167 | |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 168 | /* |
| 169 | * When calling CMD_802_11_SUBSCRIBE_EVENT with CMD_ACT_GET, me might |
| 170 | * get a bunch of vendor-specific TLVs (a.k.a. IEs) back from the |
| 171 | * firmware. Here's an example: |
| 172 | * 04 01 02 00 00 00 05 01 02 00 00 00 06 01 02 00 |
| 173 | * 00 00 07 01 02 00 3c 00 00 00 00 00 00 00 03 03 |
| 174 | * 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |
| 175 | * |
| 176 | * The 04 01 is the TLV type (here TLV_TYPE_RSSI_LOW), 02 00 is the length, |
| 177 | * 00 00 are the data bytes of this TLV. For this TLV, their meaning is |
| 178 | * defined in mrvlietypes_thresholds |
| 179 | * |
| 180 | * This function searches in this TLV data chunk for a given TLV type |
| 181 | * and returns a pointer to the first data byte of the TLV, or to NULL |
| 182 | * if the TLV hasn't been found. |
| 183 | */ |
David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 184 | static void *lbs_tlv_find(uint16_t tlv_type, const uint8_t *tlv, uint16_t size) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 185 | { |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 186 | struct mrvlietypesheader *tlv_h; |
David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 187 | uint16_t length; |
| 188 | ssize_t pos = 0; |
| 189 | |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 190 | while (pos < size) { |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 191 | tlv_h = (struct mrvlietypesheader *) tlv; |
David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 192 | if (!tlv_h->len) |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 193 | return NULL; |
David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 194 | if (tlv_h->type == cpu_to_le16(tlv_type)) |
| 195 | return tlv_h; |
| 196 | length = le16_to_cpu(tlv_h->len) + sizeof(*tlv_h); |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 197 | pos += length; |
| 198 | tlv += length; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 199 | } |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 200 | return NULL; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 201 | } |
| 202 | |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 203 | |
David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 204 | static ssize_t lbs_threshold_read(uint16_t tlv_type, uint16_t event_mask, |
| 205 | struct file *file, char __user *userbuf, |
| 206 | size_t count, loff_t *ppos) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 207 | { |
David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 208 | struct cmd_ds_802_11_subscribe_event *subscribed; |
| 209 | struct mrvlietypes_thresholds *got; |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 210 | struct lbs_private *priv = file->private_data; |
David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 211 | ssize_t ret = 0; |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 212 | size_t pos = 0; |
David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 213 | char *buf; |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 214 | u8 value; |
| 215 | u8 freq; |
Holger Schurig | b6b8abe | 2007-12-10 12:19:55 +0100 | [diff] [blame] | 216 | int events = 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 217 | |
David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 218 | buf = (char *)get_zeroed_page(GFP_KERNEL); |
| 219 | if (!buf) |
| 220 | return -ENOMEM; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 221 | |
David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 222 | subscribed = kzalloc(sizeof(*subscribed), GFP_KERNEL); |
| 223 | if (!subscribed) { |
| 224 | ret = -ENOMEM; |
| 225 | goto out_page; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 226 | } |
| 227 | |
David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 228 | subscribed->hdr.size = cpu_to_le16(sizeof(*subscribed)); |
| 229 | subscribed->action = cpu_to_le16(CMD_ACT_GET); |
| 230 | |
| 231 | ret = lbs_cmd_with_response(priv, CMD_802_11_SUBSCRIBE_EVENT, subscribed); |
| 232 | if (ret) |
| 233 | goto out_cmd; |
| 234 | |
Holger Schurig | b6b8abe | 2007-12-10 12:19:55 +0100 | [diff] [blame] | 235 | got = lbs_tlv_find(tlv_type, subscribed->tlv, sizeof(subscribed->tlv)); |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 236 | if (got) { |
| 237 | value = got->value; |
| 238 | freq = got->freq; |
Holger Schurig | b6b8abe | 2007-12-10 12:19:55 +0100 | [diff] [blame] | 239 | events = le16_to_cpu(subscribed->events); |
David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 240 | |
| 241 | pos += snprintf(buf, len, "%d %d %d\n", value, freq, |
| 242 | !!(events & event_mask)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 243 | } |
David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 244 | |
| 245 | ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos); |
| 246 | |
| 247 | out_cmd: |
Holger Schurig | b6b8abe | 2007-12-10 12:19:55 +0100 | [diff] [blame] | 248 | kfree(subscribed); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 249 | |
David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 250 | out_page: |
| 251 | free_page((unsigned long)buf); |
| 252 | return ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 253 | } |
| 254 | |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 255 | |
David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 256 | static ssize_t lbs_threshold_write(uint16_t tlv_type, uint16_t event_mask, |
| 257 | struct file *file, |
| 258 | const char __user *userbuf, size_t count, |
| 259 | loff_t *ppos) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 260 | { |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 261 | struct cmd_ds_802_11_subscribe_event *events; |
David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 262 | struct mrvlietypes_thresholds *tlv; |
| 263 | struct lbs_private *priv = file->private_data; |
| 264 | ssize_t buf_size; |
| 265 | int value, freq, new_mask; |
| 266 | uint16_t curr_mask; |
| 267 | char *buf; |
| 268 | int ret; |
| 269 | |
| 270 | buf = (char *)get_zeroed_page(GFP_KERNEL); |
| 271 | if (!buf) |
| 272 | return -ENOMEM; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 273 | |
| 274 | buf_size = min(count, len - 1); |
| 275 | if (copy_from_user(buf, userbuf, buf_size)) { |
David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 276 | ret = -EFAULT; |
| 277 | goto out_page; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 278 | } |
David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 279 | ret = sscanf(buf, "%d %d %d", &value, &freq, &new_mask); |
| 280 | if (ret != 3) { |
| 281 | ret = -EINVAL; |
| 282 | goto out_page; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 283 | } |
David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 284 | events = kzalloc(sizeof(*events), GFP_KERNEL); |
| 285 | if (!events) { |
| 286 | ret = -ENOMEM; |
| 287 | goto out_page; |
| 288 | } |
| 289 | |
| 290 | events->hdr.size = cpu_to_le16(sizeof(*events)); |
| 291 | events->action = cpu_to_le16(CMD_ACT_GET); |
| 292 | |
| 293 | ret = lbs_cmd_with_response(priv, CMD_802_11_SUBSCRIBE_EVENT, events); |
| 294 | if (ret) |
| 295 | goto out_events; |
| 296 | |
| 297 | curr_mask = le16_to_cpu(events->events); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 298 | |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 299 | if (new_mask) |
| 300 | new_mask = curr_mask | event_mask; |
| 301 | else |
| 302 | new_mask = curr_mask & ~event_mask; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 303 | |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 304 | /* Now everything is set and we can send stuff down to the firmware */ |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 305 | |
David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 306 | tlv = (void *)events->tlv; |
| 307 | |
| 308 | events->action = cpu_to_le16(CMD_ACT_SET); |
| 309 | events->events = cpu_to_le16(new_mask); |
| 310 | tlv->header.type = cpu_to_le16(tlv_type); |
| 311 | tlv->header.len = cpu_to_le16(sizeof(*tlv) - sizeof(tlv->header)); |
| 312 | tlv->value = value; |
| 313 | if (tlv_type != TLV_TYPE_BCNMISS) |
| 314 | tlv->freq = freq; |
| 315 | |
Holger Schurig | a75eda4 | 2008-05-30 14:53:22 +0200 | [diff] [blame] | 316 | /* The command header, the action, the event mask, and one TLV */ |
| 317 | events->hdr.size = cpu_to_le16(sizeof(events->hdr) + 4 + sizeof(*tlv)); |
David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 318 | |
| 319 | ret = lbs_cmd_with_response(priv, CMD_802_11_SUBSCRIBE_EVENT, events); |
| 320 | |
| 321 | if (!ret) |
| 322 | ret = count; |
| 323 | out_events: |
| 324 | kfree(events); |
| 325 | out_page: |
| 326 | free_page((unsigned long)buf); |
| 327 | return ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 328 | } |
| 329 | |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 330 | |
David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 331 | static ssize_t lbs_lowrssi_read(struct file *file, char __user *userbuf, |
| 332 | size_t count, loff_t *ppos) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 333 | { |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 334 | return lbs_threshold_read(TLV_TYPE_RSSI_LOW, CMD_SUBSCRIBE_RSSI_LOW, |
David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 335 | file, userbuf, count, ppos); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 336 | } |
| 337 | |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 338 | |
David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 339 | static ssize_t lbs_lowrssi_write(struct file *file, const char __user *userbuf, |
| 340 | size_t count, loff_t *ppos) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 341 | { |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 342 | return lbs_threshold_write(TLV_TYPE_RSSI_LOW, CMD_SUBSCRIBE_RSSI_LOW, |
David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 343 | file, userbuf, count, ppos); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 344 | } |
| 345 | |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 346 | |
David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 347 | static ssize_t lbs_lowsnr_read(struct file *file, char __user *userbuf, |
| 348 | size_t count, loff_t *ppos) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 349 | { |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 350 | return lbs_threshold_read(TLV_TYPE_SNR_LOW, CMD_SUBSCRIBE_SNR_LOW, |
David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 351 | file, userbuf, count, ppos); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 352 | } |
| 353 | |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 354 | |
David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 355 | static ssize_t lbs_lowsnr_write(struct file *file, const char __user *userbuf, |
| 356 | size_t count, loff_t *ppos) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 357 | { |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 358 | return lbs_threshold_write(TLV_TYPE_SNR_LOW, CMD_SUBSCRIBE_SNR_LOW, |
David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 359 | file, userbuf, count, ppos); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 360 | } |
| 361 | |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 362 | |
David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 363 | static ssize_t lbs_failcount_read(struct file *file, char __user *userbuf, |
| 364 | size_t count, loff_t *ppos) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 365 | { |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 366 | return lbs_threshold_read(TLV_TYPE_FAILCOUNT, CMD_SUBSCRIBE_FAILCOUNT, |
David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 367 | file, userbuf, count, ppos); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 368 | } |
| 369 | |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 370 | |
David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 371 | static ssize_t lbs_failcount_write(struct file *file, const char __user *userbuf, |
| 372 | size_t count, loff_t *ppos) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 373 | { |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 374 | return lbs_threshold_write(TLV_TYPE_FAILCOUNT, CMD_SUBSCRIBE_FAILCOUNT, |
David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 375 | file, userbuf, count, ppos); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 376 | } |
| 377 | |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 378 | |
David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 379 | static ssize_t lbs_highrssi_read(struct file *file, char __user *userbuf, |
| 380 | size_t count, loff_t *ppos) |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 381 | { |
| 382 | return lbs_threshold_read(TLV_TYPE_RSSI_HIGH, CMD_SUBSCRIBE_RSSI_HIGH, |
David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 383 | file, userbuf, count, ppos); |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | |
David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 387 | static ssize_t lbs_highrssi_write(struct file *file, const char __user *userbuf, |
| 388 | size_t count, loff_t *ppos) |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 389 | { |
| 390 | return lbs_threshold_write(TLV_TYPE_RSSI_HIGH, CMD_SUBSCRIBE_RSSI_HIGH, |
David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 391 | file, userbuf, count, ppos); |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | |
David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 395 | static ssize_t lbs_highsnr_read(struct file *file, char __user *userbuf, |
| 396 | size_t count, loff_t *ppos) |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 397 | { |
| 398 | return lbs_threshold_read(TLV_TYPE_SNR_HIGH, CMD_SUBSCRIBE_SNR_HIGH, |
David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 399 | file, userbuf, count, ppos); |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | |
David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 403 | static ssize_t lbs_highsnr_write(struct file *file, const char __user *userbuf, |
| 404 | size_t count, loff_t *ppos) |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 405 | { |
| 406 | return lbs_threshold_write(TLV_TYPE_SNR_HIGH, CMD_SUBSCRIBE_SNR_HIGH, |
David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 407 | file, userbuf, count, ppos); |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 408 | } |
| 409 | |
David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 410 | static ssize_t lbs_bcnmiss_read(struct file *file, char __user *userbuf, |
| 411 | size_t count, loff_t *ppos) |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 412 | { |
| 413 | return lbs_threshold_read(TLV_TYPE_BCNMISS, CMD_SUBSCRIBE_BCNMISS, |
David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 414 | file, userbuf, count, ppos); |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | |
David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 418 | static ssize_t lbs_bcnmiss_write(struct file *file, const char __user *userbuf, |
| 419 | size_t count, loff_t *ppos) |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 420 | { |
| 421 | return lbs_threshold_write(TLV_TYPE_BCNMISS, CMD_SUBSCRIBE_BCNMISS, |
David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 422 | file, userbuf, count, ppos); |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | |
| 426 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 427 | static ssize_t lbs_rdmac_read(struct file *file, char __user *userbuf, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 428 | size_t count, loff_t *ppos) |
| 429 | { |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 430 | struct lbs_private *priv = file->private_data; |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 431 | struct lbs_offset_value offval; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 432 | ssize_t pos = 0; |
| 433 | int ret; |
| 434 | unsigned long addr = get_zeroed_page(GFP_KERNEL); |
| 435 | char *buf = (char *)addr; |
| 436 | |
| 437 | offval.offset = priv->mac_offset; |
| 438 | offval.value = 0; |
| 439 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 440 | ret = lbs_prepare_and_send_command(priv, |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 441 | CMD_MAC_REG_ACCESS, 0, |
| 442 | CMD_OPTION_WAITFORRSP, 0, &offval); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 443 | mdelay(10); |
| 444 | pos += snprintf(buf+pos, len-pos, "MAC[0x%x] = 0x%08x\n", |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 445 | priv->mac_offset, priv->offsetvalue.value); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 446 | |
| 447 | ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos); |
| 448 | free_page(addr); |
| 449 | return ret; |
| 450 | } |
| 451 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 452 | static ssize_t lbs_rdmac_write(struct file *file, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 453 | const char __user *userbuf, |
| 454 | size_t count, loff_t *ppos) |
| 455 | { |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 456 | struct lbs_private *priv = file->private_data; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 457 | ssize_t res, buf_size; |
| 458 | unsigned long addr = get_zeroed_page(GFP_KERNEL); |
| 459 | char *buf = (char *)addr; |
| 460 | |
| 461 | buf_size = min(count, len - 1); |
| 462 | if (copy_from_user(buf, userbuf, buf_size)) { |
| 463 | res = -EFAULT; |
| 464 | goto out_unlock; |
| 465 | } |
| 466 | priv->mac_offset = simple_strtoul((char *)buf, NULL, 16); |
| 467 | res = count; |
| 468 | out_unlock: |
| 469 | free_page(addr); |
| 470 | return res; |
| 471 | } |
| 472 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 473 | static ssize_t lbs_wrmac_write(struct file *file, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 474 | const char __user *userbuf, |
| 475 | size_t count, loff_t *ppos) |
| 476 | { |
| 477 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 478 | struct lbs_private *priv = file->private_data; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 479 | ssize_t res, buf_size; |
| 480 | u32 offset, value; |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 481 | struct lbs_offset_value offval; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 482 | unsigned long addr = get_zeroed_page(GFP_KERNEL); |
| 483 | char *buf = (char *)addr; |
| 484 | |
| 485 | buf_size = min(count, len - 1); |
| 486 | if (copy_from_user(buf, userbuf, buf_size)) { |
| 487 | res = -EFAULT; |
| 488 | goto out_unlock; |
| 489 | } |
| 490 | res = sscanf(buf, "%x %x", &offset, &value); |
| 491 | if (res != 2) { |
| 492 | res = -EFAULT; |
| 493 | goto out_unlock; |
| 494 | } |
| 495 | |
| 496 | offval.offset = offset; |
| 497 | offval.value = value; |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 498 | res = lbs_prepare_and_send_command(priv, |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 499 | CMD_MAC_REG_ACCESS, 1, |
| 500 | CMD_OPTION_WAITFORRSP, 0, &offval); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 501 | mdelay(10); |
| 502 | |
| 503 | res = count; |
| 504 | out_unlock: |
| 505 | free_page(addr); |
| 506 | return res; |
| 507 | } |
| 508 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 509 | static ssize_t lbs_rdbbp_read(struct file *file, char __user *userbuf, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 510 | size_t count, loff_t *ppos) |
| 511 | { |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 512 | struct lbs_private *priv = file->private_data; |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 513 | struct lbs_offset_value offval; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 514 | ssize_t pos = 0; |
| 515 | int ret; |
| 516 | unsigned long addr = get_zeroed_page(GFP_KERNEL); |
| 517 | char *buf = (char *)addr; |
| 518 | |
| 519 | offval.offset = priv->bbp_offset; |
| 520 | offval.value = 0; |
| 521 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 522 | ret = lbs_prepare_and_send_command(priv, |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 523 | CMD_BBP_REG_ACCESS, 0, |
| 524 | CMD_OPTION_WAITFORRSP, 0, &offval); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 525 | mdelay(10); |
| 526 | pos += snprintf(buf+pos, len-pos, "BBP[0x%x] = 0x%08x\n", |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 527 | priv->bbp_offset, priv->offsetvalue.value); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 528 | |
| 529 | ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos); |
| 530 | free_page(addr); |
| 531 | |
| 532 | return ret; |
| 533 | } |
| 534 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 535 | static ssize_t lbs_rdbbp_write(struct file *file, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 536 | const char __user *userbuf, |
| 537 | size_t count, loff_t *ppos) |
| 538 | { |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 539 | struct lbs_private *priv = file->private_data; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 540 | ssize_t res, buf_size; |
| 541 | unsigned long addr = get_zeroed_page(GFP_KERNEL); |
| 542 | char *buf = (char *)addr; |
| 543 | |
| 544 | buf_size = min(count, len - 1); |
| 545 | if (copy_from_user(buf, userbuf, buf_size)) { |
| 546 | res = -EFAULT; |
| 547 | goto out_unlock; |
| 548 | } |
| 549 | priv->bbp_offset = simple_strtoul((char *)buf, NULL, 16); |
| 550 | res = count; |
| 551 | out_unlock: |
| 552 | free_page(addr); |
| 553 | return res; |
| 554 | } |
| 555 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 556 | static ssize_t lbs_wrbbp_write(struct file *file, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 557 | const char __user *userbuf, |
| 558 | size_t count, loff_t *ppos) |
| 559 | { |
| 560 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 561 | struct lbs_private *priv = file->private_data; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 562 | ssize_t res, buf_size; |
| 563 | u32 offset, value; |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 564 | struct lbs_offset_value offval; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 565 | unsigned long addr = get_zeroed_page(GFP_KERNEL); |
| 566 | char *buf = (char *)addr; |
| 567 | |
| 568 | buf_size = min(count, len - 1); |
| 569 | if (copy_from_user(buf, userbuf, buf_size)) { |
| 570 | res = -EFAULT; |
| 571 | goto out_unlock; |
| 572 | } |
| 573 | res = sscanf(buf, "%x %x", &offset, &value); |
| 574 | if (res != 2) { |
| 575 | res = -EFAULT; |
| 576 | goto out_unlock; |
| 577 | } |
| 578 | |
| 579 | offval.offset = offset; |
| 580 | offval.value = value; |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 581 | res = lbs_prepare_and_send_command(priv, |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 582 | CMD_BBP_REG_ACCESS, 1, |
| 583 | CMD_OPTION_WAITFORRSP, 0, &offval); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 584 | mdelay(10); |
| 585 | |
| 586 | res = count; |
| 587 | out_unlock: |
| 588 | free_page(addr); |
| 589 | return res; |
| 590 | } |
| 591 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 592 | static ssize_t lbs_rdrf_read(struct file *file, char __user *userbuf, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 593 | size_t count, loff_t *ppos) |
| 594 | { |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 595 | struct lbs_private *priv = file->private_data; |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 596 | struct lbs_offset_value offval; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 597 | ssize_t pos = 0; |
| 598 | int ret; |
| 599 | unsigned long addr = get_zeroed_page(GFP_KERNEL); |
| 600 | char *buf = (char *)addr; |
| 601 | |
| 602 | offval.offset = priv->rf_offset; |
| 603 | offval.value = 0; |
| 604 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 605 | ret = lbs_prepare_and_send_command(priv, |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 606 | CMD_RF_REG_ACCESS, 0, |
| 607 | CMD_OPTION_WAITFORRSP, 0, &offval); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 608 | mdelay(10); |
| 609 | pos += snprintf(buf+pos, len-pos, "RF[0x%x] = 0x%08x\n", |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 610 | priv->rf_offset, priv->offsetvalue.value); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 611 | |
| 612 | ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos); |
| 613 | free_page(addr); |
| 614 | |
| 615 | return ret; |
| 616 | } |
| 617 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 618 | static ssize_t lbs_rdrf_write(struct file *file, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 619 | const char __user *userbuf, |
| 620 | size_t count, loff_t *ppos) |
| 621 | { |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 622 | struct lbs_private *priv = file->private_data; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 623 | ssize_t res, buf_size; |
| 624 | unsigned long addr = get_zeroed_page(GFP_KERNEL); |
| 625 | char *buf = (char *)addr; |
| 626 | |
| 627 | buf_size = min(count, len - 1); |
| 628 | if (copy_from_user(buf, userbuf, buf_size)) { |
| 629 | res = -EFAULT; |
| 630 | goto out_unlock; |
| 631 | } |
| 632 | priv->rf_offset = simple_strtoul((char *)buf, NULL, 16); |
| 633 | res = count; |
| 634 | out_unlock: |
| 635 | free_page(addr); |
| 636 | return res; |
| 637 | } |
| 638 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 639 | static ssize_t lbs_wrrf_write(struct file *file, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 640 | const char __user *userbuf, |
| 641 | size_t count, loff_t *ppos) |
| 642 | { |
| 643 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 644 | struct lbs_private *priv = file->private_data; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 645 | ssize_t res, buf_size; |
| 646 | u32 offset, value; |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 647 | struct lbs_offset_value offval; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 648 | unsigned long addr = get_zeroed_page(GFP_KERNEL); |
| 649 | char *buf = (char *)addr; |
| 650 | |
| 651 | buf_size = min(count, len - 1); |
| 652 | if (copy_from_user(buf, userbuf, buf_size)) { |
| 653 | res = -EFAULT; |
| 654 | goto out_unlock; |
| 655 | } |
| 656 | res = sscanf(buf, "%x %x", &offset, &value); |
| 657 | if (res != 2) { |
| 658 | res = -EFAULT; |
| 659 | goto out_unlock; |
| 660 | } |
| 661 | |
| 662 | offval.offset = offset; |
| 663 | offval.value = value; |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 664 | res = lbs_prepare_and_send_command(priv, |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 665 | CMD_RF_REG_ACCESS, 1, |
| 666 | CMD_OPTION_WAITFORRSP, 0, &offval); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 667 | mdelay(10); |
| 668 | |
| 669 | res = count; |
| 670 | out_unlock: |
| 671 | free_page(addr); |
| 672 | return res; |
| 673 | } |
| 674 | |
| 675 | #define FOPS(fread, fwrite) { \ |
| 676 | .owner = THIS_MODULE, \ |
| 677 | .open = open_file_generic, \ |
| 678 | .read = (fread), \ |
| 679 | .write = (fwrite), \ |
| 680 | } |
| 681 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 682 | struct lbs_debugfs_files { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 683 | char *name; |
| 684 | int perm; |
| 685 | struct file_operations fops; |
| 686 | }; |
| 687 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 688 | static struct lbs_debugfs_files debugfs_files[] = { |
| 689 | { "info", 0444, FOPS(lbs_dev_info, write_file_dummy), }, |
| 690 | { "getscantable", 0444, FOPS(lbs_getscantable, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 691 | write_file_dummy), }, |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 692 | { "sleepparams", 0644, FOPS(lbs_sleepparams_read, |
| 693 | lbs_sleepparams_write), }, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 694 | }; |
| 695 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 696 | static struct lbs_debugfs_files debugfs_events_files[] = { |
| 697 | {"low_rssi", 0644, FOPS(lbs_lowrssi_read, |
| 698 | lbs_lowrssi_write), }, |
| 699 | {"low_snr", 0644, FOPS(lbs_lowsnr_read, |
| 700 | lbs_lowsnr_write), }, |
| 701 | {"failure_count", 0644, FOPS(lbs_failcount_read, |
| 702 | lbs_failcount_write), }, |
| 703 | {"beacon_missed", 0644, FOPS(lbs_bcnmiss_read, |
| 704 | lbs_bcnmiss_write), }, |
| 705 | {"high_rssi", 0644, FOPS(lbs_highrssi_read, |
| 706 | lbs_highrssi_write), }, |
| 707 | {"high_snr", 0644, FOPS(lbs_highsnr_read, |
| 708 | lbs_highsnr_write), }, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 709 | }; |
| 710 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 711 | static struct lbs_debugfs_files debugfs_regs_files[] = { |
| 712 | {"rdmac", 0644, FOPS(lbs_rdmac_read, lbs_rdmac_write), }, |
| 713 | {"wrmac", 0600, FOPS(NULL, lbs_wrmac_write), }, |
| 714 | {"rdbbp", 0644, FOPS(lbs_rdbbp_read, lbs_rdbbp_write), }, |
| 715 | {"wrbbp", 0600, FOPS(NULL, lbs_wrbbp_write), }, |
| 716 | {"rdrf", 0644, FOPS(lbs_rdrf_read, lbs_rdrf_write), }, |
| 717 | {"wrrf", 0600, FOPS(NULL, lbs_wrrf_write), }, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 718 | }; |
| 719 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 720 | void lbs_debugfs_init(void) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 721 | { |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 722 | if (!lbs_dir) |
| 723 | lbs_dir = debugfs_create_dir("lbs_wireless", NULL); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 724 | |
| 725 | return; |
| 726 | } |
| 727 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 728 | void lbs_debugfs_remove(void) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 729 | { |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 730 | if (lbs_dir) |
| 731 | debugfs_remove(lbs_dir); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 732 | return; |
| 733 | } |
| 734 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 735 | void lbs_debugfs_init_one(struct lbs_private *priv, struct net_device *dev) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 736 | { |
| 737 | int i; |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 738 | struct lbs_debugfs_files *files; |
| 739 | if (!lbs_dir) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 740 | goto exit; |
| 741 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 742 | priv->debugfs_dir = debugfs_create_dir(dev->name, lbs_dir); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 743 | if (!priv->debugfs_dir) |
| 744 | goto exit; |
| 745 | |
| 746 | for (i=0; i<ARRAY_SIZE(debugfs_files); i++) { |
| 747 | files = &debugfs_files[i]; |
| 748 | priv->debugfs_files[i] = debugfs_create_file(files->name, |
| 749 | files->perm, |
| 750 | priv->debugfs_dir, |
| 751 | priv, |
| 752 | &files->fops); |
| 753 | } |
| 754 | |
| 755 | priv->events_dir = debugfs_create_dir("subscribed_events", priv->debugfs_dir); |
| 756 | if (!priv->events_dir) |
| 757 | goto exit; |
| 758 | |
| 759 | for (i=0; i<ARRAY_SIZE(debugfs_events_files); i++) { |
| 760 | files = &debugfs_events_files[i]; |
| 761 | priv->debugfs_events_files[i] = debugfs_create_file(files->name, |
| 762 | files->perm, |
| 763 | priv->events_dir, |
| 764 | priv, |
| 765 | &files->fops); |
| 766 | } |
| 767 | |
| 768 | priv->regs_dir = debugfs_create_dir("registers", priv->debugfs_dir); |
| 769 | if (!priv->regs_dir) |
| 770 | goto exit; |
| 771 | |
| 772 | for (i=0; i<ARRAY_SIZE(debugfs_regs_files); i++) { |
| 773 | files = &debugfs_regs_files[i]; |
| 774 | priv->debugfs_regs_files[i] = debugfs_create_file(files->name, |
| 775 | files->perm, |
| 776 | priv->regs_dir, |
| 777 | priv, |
| 778 | &files->fops); |
| 779 | } |
| 780 | |
| 781 | #ifdef PROC_DEBUG |
Holger Schurig | e98a88d | 2008-03-19 14:25:58 +0100 | [diff] [blame] | 782 | lbs_debug_init(priv); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 783 | #endif |
| 784 | exit: |
| 785 | return; |
| 786 | } |
| 787 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 788 | void lbs_debugfs_remove_one(struct lbs_private *priv) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 789 | { |
| 790 | int i; |
| 791 | |
| 792 | for(i=0; i<ARRAY_SIZE(debugfs_regs_files); i++) |
| 793 | debugfs_remove(priv->debugfs_regs_files[i]); |
| 794 | |
| 795 | debugfs_remove(priv->regs_dir); |
| 796 | |
Holger Schurig | 0b7db95 | 2007-05-24 23:47:34 -0400 | [diff] [blame] | 797 | for(i=0; i<ARRAY_SIZE(debugfs_events_files); i++) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 798 | debugfs_remove(priv->debugfs_events_files[i]); |
| 799 | |
| 800 | debugfs_remove(priv->events_dir); |
| 801 | #ifdef PROC_DEBUG |
| 802 | debugfs_remove(priv->debugfs_debug); |
| 803 | #endif |
| 804 | for(i=0; i<ARRAY_SIZE(debugfs_files); i++) |
| 805 | debugfs_remove(priv->debugfs_files[i]); |
Holger Schurig | 0b7db95 | 2007-05-24 23:47:34 -0400 | [diff] [blame] | 806 | debugfs_remove(priv->debugfs_dir); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 807 | } |
| 808 | |
Holger Schurig | 4686820 | 2007-05-25 00:37:28 -0400 | [diff] [blame] | 809 | |
| 810 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 811 | /* debug entry */ |
| 812 | |
Holger Schurig | 4686820 | 2007-05-25 00:37:28 -0400 | [diff] [blame] | 813 | #ifdef PROC_DEBUG |
| 814 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 815 | #define item_size(n) (FIELD_SIZEOF(struct lbs_private, n)) |
| 816 | #define item_addr(n) (offsetof(struct lbs_private, n)) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 817 | |
Holger Schurig | 4686820 | 2007-05-25 00:37:28 -0400 | [diff] [blame] | 818 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 819 | struct debug_data { |
| 820 | char name[32]; |
| 821 | u32 size; |
Dan Williams | 4269e2a | 2007-05-10 23:10:18 -0400 | [diff] [blame] | 822 | size_t addr; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 823 | }; |
| 824 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 825 | /* To debug any member of struct lbs_private, simply add one line here. |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 826 | */ |
| 827 | static struct debug_data items[] = { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 828 | {"psmode", item_size(psmode), item_addr(psmode)}, |
| 829 | {"psstate", item_size(psstate), item_addr(psstate)}, |
| 830 | }; |
| 831 | |
Tony Breeds | d2f11e0 | 2007-03-09 13:11:46 +1100 | [diff] [blame] | 832 | static int num_of_items = ARRAY_SIZE(items); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 833 | |
| 834 | /** |
| 835 | * @brief proc read function |
| 836 | * |
| 837 | * @param page pointer to buffer |
| 838 | * @param s read data starting position |
| 839 | * @param off offset |
| 840 | * @param cnt counter |
| 841 | * @param eof end of file flag |
| 842 | * @param data data to output |
| 843 | * @return number of output data |
| 844 | */ |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 845 | static ssize_t lbs_debugfs_read(struct file *file, char __user *userbuf, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 846 | size_t count, loff_t *ppos) |
| 847 | { |
| 848 | int val = 0; |
| 849 | size_t pos = 0; |
| 850 | ssize_t res; |
| 851 | char *p; |
| 852 | int i; |
| 853 | struct debug_data *d; |
| 854 | unsigned long addr = get_zeroed_page(GFP_KERNEL); |
| 855 | char *buf = (char *)addr; |
| 856 | |
| 857 | p = buf; |
| 858 | |
| 859 | d = (struct debug_data *)file->private_data; |
| 860 | |
| 861 | for (i = 0; i < num_of_items; i++) { |
| 862 | if (d[i].size == 1) |
| 863 | val = *((u8 *) d[i].addr); |
| 864 | else if (d[i].size == 2) |
| 865 | val = *((u16 *) d[i].addr); |
| 866 | else if (d[i].size == 4) |
| 867 | val = *((u32 *) d[i].addr); |
Dan Williams | 4269e2a | 2007-05-10 23:10:18 -0400 | [diff] [blame] | 868 | else if (d[i].size == 8) |
| 869 | val = *((u64 *) d[i].addr); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 870 | |
| 871 | pos += sprintf(p + pos, "%s=%d\n", d[i].name, val); |
| 872 | } |
| 873 | |
| 874 | res = simple_read_from_buffer(userbuf, count, ppos, p, pos); |
| 875 | |
| 876 | free_page(addr); |
| 877 | return res; |
| 878 | } |
| 879 | |
| 880 | /** |
| 881 | * @brief proc write function |
| 882 | * |
| 883 | * @param f file pointer |
| 884 | * @param buf pointer to data buffer |
| 885 | * @param cnt data number to write |
| 886 | * @param data data to write |
| 887 | * @return number of data |
| 888 | */ |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 889 | static ssize_t lbs_debugfs_write(struct file *f, const char __user *buf, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 890 | size_t cnt, loff_t *ppos) |
| 891 | { |
| 892 | int r, i; |
| 893 | char *pdata; |
| 894 | char *p; |
| 895 | char *p0; |
| 896 | char *p1; |
| 897 | char *p2; |
| 898 | struct debug_data *d = (struct debug_data *)f->private_data; |
| 899 | |
Jesper Juhl | 655b4d1 | 2007-08-24 11:48:16 -0400 | [diff] [blame] | 900 | pdata = kmalloc(cnt, GFP_KERNEL); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 901 | if (pdata == NULL) |
| 902 | return 0; |
| 903 | |
| 904 | if (copy_from_user(pdata, buf, cnt)) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 905 | lbs_deb_debugfs("Copy from user failed\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 906 | kfree(pdata); |
| 907 | return 0; |
| 908 | } |
| 909 | |
| 910 | p0 = pdata; |
| 911 | for (i = 0; i < num_of_items; i++) { |
| 912 | do { |
| 913 | p = strstr(p0, d[i].name); |
| 914 | if (p == NULL) |
| 915 | break; |
| 916 | p1 = strchr(p, '\n'); |
| 917 | if (p1 == NULL) |
| 918 | break; |
| 919 | p0 = p1++; |
| 920 | p2 = strchr(p, '='); |
| 921 | if (!p2) |
| 922 | break; |
| 923 | p2++; |
Tony Breeds | d2f11e0 | 2007-03-09 13:11:46 +1100 | [diff] [blame] | 924 | r = simple_strtoul(p2, NULL, 0); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 925 | if (d[i].size == 1) |
| 926 | *((u8 *) d[i].addr) = (u8) r; |
| 927 | else if (d[i].size == 2) |
| 928 | *((u16 *) d[i].addr) = (u16) r; |
| 929 | else if (d[i].size == 4) |
| 930 | *((u32 *) d[i].addr) = (u32) r; |
Dan Williams | 4269e2a | 2007-05-10 23:10:18 -0400 | [diff] [blame] | 931 | else if (d[i].size == 8) |
| 932 | *((u64 *) d[i].addr) = (u64) r; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 933 | break; |
| 934 | } while (1); |
| 935 | } |
| 936 | kfree(pdata); |
| 937 | |
Dan Williams | 4269e2a | 2007-05-10 23:10:18 -0400 | [diff] [blame] | 938 | return (ssize_t)cnt; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 939 | } |
| 940 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 941 | static struct file_operations lbs_debug_fops = { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 942 | .owner = THIS_MODULE, |
| 943 | .open = open_file_generic, |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 944 | .write = lbs_debugfs_write, |
| 945 | .read = lbs_debugfs_read, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 946 | }; |
| 947 | |
| 948 | /** |
| 949 | * @brief create debug proc file |
| 950 | * |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 951 | * @param priv pointer struct lbs_private |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 952 | * @param dev pointer net_device |
| 953 | * @return N/A |
| 954 | */ |
Holger Schurig | e98a88d | 2008-03-19 14:25:58 +0100 | [diff] [blame] | 955 | static void lbs_debug_init(struct lbs_private *priv) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 956 | { |
| 957 | int i; |
| 958 | |
| 959 | if (!priv->debugfs_dir) |
| 960 | return; |
| 961 | |
| 962 | for (i = 0; i < num_of_items; i++) |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 963 | items[i].addr += (size_t) priv; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 964 | |
| 965 | priv->debugfs_debug = debugfs_create_file("debug", 0644, |
| 966 | priv->debugfs_dir, &items[0], |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 967 | &lbs_debug_fops); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 968 | } |
Holger Schurig | 4686820 | 2007-05-25 00:37:28 -0400 | [diff] [blame] | 969 | #endif |