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