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