blob: d8d8f0d0899faaebb5f2efa857267c3259f27612 [file] [log] [blame]
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001#include <linux/dcache.h>
2#include <linux/debugfs.h>
3#include <linux/delay.h>
Alexey Dobriyana6b7a402011-06-06 10:43:46 +00004#include <linux/hardirq.h>
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02005#include <linux/mm.h>
Geert Uytterhoevend8b0fb52007-10-08 09:43:02 +02006#include <linux/string.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09007#include <linux/slab.h>
Paul Gortmakeree40fa02011-05-27 16:14:23 -04008#include <linux/export.h>
Holger Schurig46868202007-05-25 00:37:28 -04009
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020010#include "decl.h"
David Woodhouse3fbe1042007-12-17 23:48:31 -050011#include "cmd.h"
Kiran Divekare86dc1c2010-06-14 22:01:26 +053012#include "debugfs.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020013
Holger Schurig10078322007-11-15 18:05:47 -050014static struct dentry *lbs_dir;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020015static char *szStates[] = {
16 "Connected",
17 "Disconnected"
18};
19
Holger Schurig46868202007-05-25 00:37:28 -040020#ifdef PROC_DEBUG
Holger Schurige98a88d2008-03-19 14:25:58 +010021static void lbs_debug_init(struct lbs_private *priv);
Holger Schurig46868202007-05-25 00:37:28 -040022#endif
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020023
24static int open_file_generic(struct inode *inode, struct file *file)
25{
26 file->private_data = inode->i_private;
27 return 0;
28}
29
30static ssize_t write_file_dummy(struct file *file, const char __user *buf,
31 size_t count, loff_t *ppos)
32{
33 return -EINVAL;
34}
35
36static const size_t len = PAGE_SIZE;
37
Holger Schurig10078322007-11-15 18:05:47 -050038static ssize_t lbs_dev_info(struct file *file, char __user *userbuf,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020039 size_t count, loff_t *ppos)
40{
Holger Schurig69f90322007-11-23 15:43:44 +010041 struct lbs_private *priv = file->private_data;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020042 size_t pos = 0;
43 unsigned long addr = get_zeroed_page(GFP_KERNEL);
44 char *buf = (char *)addr;
45 ssize_t res;
Kiran Divekarad43f8b2009-08-28 17:47:59 +053046 if (!buf)
47 return -ENOMEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020048
49 pos += snprintf(buf+pos, len-pos, "state = %s\n",
David Woodhouseaa21c002007-12-08 20:04:36 +000050 szStates[priv->connect_status]);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020051 pos += snprintf(buf+pos, len-pos, "region_code = %02x\n",
David Woodhouseaa21c002007-12-08 20:04:36 +000052 (u32) priv->regioncode);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020053
54 res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
55
56 free_page(addr);
57 return res;
58}
59
Holger Schurig10078322007-11-15 18:05:47 -050060static ssize_t lbs_sleepparams_write(struct file *file,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020061 const char __user *user_buf, size_t count,
62 loff_t *ppos)
63{
Holger Schurig69f90322007-11-23 15:43:44 +010064 struct lbs_private *priv = file->private_data;
David Woodhouse3fbe1042007-12-17 23:48:31 -050065 ssize_t buf_size, ret;
66 struct sleep_params sp;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020067 int p1, p2, p3, p4, p5, p6;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020068 unsigned long addr = get_zeroed_page(GFP_KERNEL);
69 char *buf = (char *)addr;
Kiran Divekarad43f8b2009-08-28 17:47:59 +053070 if (!buf)
71 return -ENOMEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020072
73 buf_size = min(count, len - 1);
74 if (copy_from_user(buf, user_buf, buf_size)) {
David Woodhouse3fbe1042007-12-17 23:48:31 -050075 ret = -EFAULT;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020076 goto out_unlock;
77 }
David Woodhouse3fbe1042007-12-17 23:48:31 -050078 ret = sscanf(buf, "%d %d %d %d %d %d", &p1, &p2, &p3, &p4, &p5, &p6);
79 if (ret != 6) {
80 ret = -EINVAL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020081 goto out_unlock;
82 }
David Woodhouse3fbe1042007-12-17 23:48:31 -050083 sp.sp_error = p1;
84 sp.sp_offset = p2;
85 sp.sp_stabletime = p3;
86 sp.sp_calcontrol = p4;
87 sp.sp_extsleepclk = p5;
88 sp.sp_reserved = p6;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020089
David Woodhouse3fbe1042007-12-17 23:48:31 -050090 ret = lbs_cmd_802_11_sleep_params(priv, CMD_ACT_SET, &sp);
91 if (!ret)
92 ret = count;
93 else if (ret > 0)
94 ret = -EINVAL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020095
96out_unlock:
97 free_page(addr);
David Woodhouse3fbe1042007-12-17 23:48:31 -050098 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020099}
100
Holger Schurig10078322007-11-15 18:05:47 -0500101static ssize_t lbs_sleepparams_read(struct file *file, char __user *userbuf,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200102 size_t count, loff_t *ppos)
103{
Holger Schurig69f90322007-11-23 15:43:44 +0100104 struct lbs_private *priv = file->private_data;
David Woodhouse3fbe1042007-12-17 23:48:31 -0500105 ssize_t ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200106 size_t pos = 0;
David Woodhouse3fbe1042007-12-17 23:48:31 -0500107 struct sleep_params sp;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200108 unsigned long addr = get_zeroed_page(GFP_KERNEL);
109 char *buf = (char *)addr;
Kiran Divekarad43f8b2009-08-28 17:47:59 +0530110 if (!buf)
111 return -ENOMEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200112
David Woodhouse3fbe1042007-12-17 23:48:31 -0500113 ret = lbs_cmd_802_11_sleep_params(priv, CMD_ACT_GET, &sp);
114 if (ret)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200115 goto out_unlock;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200116
David Woodhouse3fbe1042007-12-17 23:48:31 -0500117 pos += snprintf(buf, len, "%d %d %d %d %d %d\n", sp.sp_error,
118 sp.sp_offset, sp.sp_stabletime,
119 sp.sp_calcontrol, sp.sp_extsleepclk,
120 sp.sp_reserved);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200121
David Woodhouse3fbe1042007-12-17 23:48:31 -0500122 ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200123
124out_unlock:
125 free_page(addr);
David Woodhouse3fbe1042007-12-17 23:48:31 -0500126 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200127}
128
Amitkumar Karwar13118432010-07-08 06:43:48 +0530129static ssize_t lbs_host_sleep_write(struct file *file,
130 const char __user *user_buf, size_t count,
131 loff_t *ppos)
132{
133 struct lbs_private *priv = file->private_data;
134 ssize_t buf_size, ret;
135 int host_sleep;
136 unsigned long addr = get_zeroed_page(GFP_KERNEL);
137 char *buf = (char *)addr;
138 if (!buf)
139 return -ENOMEM;
140
141 buf_size = min(count, len - 1);
142 if (copy_from_user(buf, user_buf, buf_size)) {
143 ret = -EFAULT;
144 goto out_unlock;
145 }
146 ret = sscanf(buf, "%d", &host_sleep);
147 if (ret != 1) {
148 ret = -EINVAL;
149 goto out_unlock;
150 }
151
152 if (host_sleep == 0)
153 ret = lbs_set_host_sleep(priv, 0);
154 else if (host_sleep == 1) {
155 if (priv->wol_criteria == EHS_REMOVE_WAKEUP) {
Joe Perchesf3a57fd2011-05-02 16:49:15 -0700156 netdev_info(priv->dev,
157 "wake parameters not configured\n");
Amitkumar Karwar13118432010-07-08 06:43:48 +0530158 ret = -EINVAL;
159 goto out_unlock;
160 }
161 ret = lbs_set_host_sleep(priv, 1);
162 } else {
Joe Perchesf3a57fd2011-05-02 16:49:15 -0700163 netdev_err(priv->dev, "invalid option\n");
Amitkumar Karwar13118432010-07-08 06:43:48 +0530164 ret = -EINVAL;
165 }
166
167 if (!ret)
168 ret = count;
169
170out_unlock:
171 free_page(addr);
172 return ret;
173}
174
175static ssize_t lbs_host_sleep_read(struct file *file, char __user *userbuf,
176 size_t count, loff_t *ppos)
177{
178 struct lbs_private *priv = file->private_data;
179 ssize_t ret;
180 size_t pos = 0;
181 unsigned long addr = get_zeroed_page(GFP_KERNEL);
182 char *buf = (char *)addr;
183 if (!buf)
184 return -ENOMEM;
185
186 pos += snprintf(buf, len, "%d\n", priv->is_host_sleep_activated);
187
188 ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
189
190 free_page(addr);
191 return ret;
192}
193
Holger Schurig3a188642007-11-26 10:07:14 +0100194/*
195 * When calling CMD_802_11_SUBSCRIBE_EVENT with CMD_ACT_GET, me might
196 * get a bunch of vendor-specific TLVs (a.k.a. IEs) back from the
197 * firmware. Here's an example:
198 * 04 01 02 00 00 00 05 01 02 00 00 00 06 01 02 00
199 * 00 00 07 01 02 00 3c 00 00 00 00 00 00 00 03 03
200 * 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
201 *
202 * The 04 01 is the TLV type (here TLV_TYPE_RSSI_LOW), 02 00 is the length,
203 * 00 00 are the data bytes of this TLV. For this TLV, their meaning is
204 * defined in mrvlietypes_thresholds
205 *
206 * This function searches in this TLV data chunk for a given TLV type
207 * and returns a pointer to the first data byte of the TLV, or to NULL
208 * if the TLV hasn't been found.
209 */
David Woodhouse5844d122007-12-18 02:01:37 -0500210static void *lbs_tlv_find(uint16_t tlv_type, const uint8_t *tlv, uint16_t size)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200211{
Dan Williams75b6a612009-05-22 20:03:09 -0400212 struct mrvl_ie_header *tlv_h;
David Woodhouse5844d122007-12-18 02:01:37 -0500213 uint16_t length;
214 ssize_t pos = 0;
215
Holger Schurig3a188642007-11-26 10:07:14 +0100216 while (pos < size) {
Dan Williams75b6a612009-05-22 20:03:09 -0400217 tlv_h = (struct mrvl_ie_header *) tlv;
David Woodhouse5844d122007-12-18 02:01:37 -0500218 if (!tlv_h->len)
Holger Schurig3a188642007-11-26 10:07:14 +0100219 return NULL;
David Woodhouse5844d122007-12-18 02:01:37 -0500220 if (tlv_h->type == cpu_to_le16(tlv_type))
221 return tlv_h;
222 length = le16_to_cpu(tlv_h->len) + sizeof(*tlv_h);
Holger Schurig3a188642007-11-26 10:07:14 +0100223 pos += length;
224 tlv += length;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200225 }
Holger Schurig3a188642007-11-26 10:07:14 +0100226 return NULL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200227}
228
Holger Schurig3a188642007-11-26 10:07:14 +0100229
David Woodhouse5844d122007-12-18 02:01:37 -0500230static ssize_t lbs_threshold_read(uint16_t tlv_type, uint16_t event_mask,
231 struct file *file, char __user *userbuf,
232 size_t count, loff_t *ppos)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200233{
David Woodhouse5844d122007-12-18 02:01:37 -0500234 struct cmd_ds_802_11_subscribe_event *subscribed;
Dan Williams75b6a612009-05-22 20:03:09 -0400235 struct mrvl_ie_thresholds *got;
Holger Schurig69f90322007-11-23 15:43:44 +0100236 struct lbs_private *priv = file->private_data;
David Woodhouse5844d122007-12-18 02:01:37 -0500237 ssize_t ret = 0;
Holger Schurig3a188642007-11-26 10:07:14 +0100238 size_t pos = 0;
David Woodhouse5844d122007-12-18 02:01:37 -0500239 char *buf;
Holger Schurig3a188642007-11-26 10:07:14 +0100240 u8 value;
241 u8 freq;
Holger Schurigb6b8abe2007-12-10 12:19:55 +0100242 int events = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200243
David Woodhouse5844d122007-12-18 02:01:37 -0500244 buf = (char *)get_zeroed_page(GFP_KERNEL);
245 if (!buf)
246 return -ENOMEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200247
David Woodhouse5844d122007-12-18 02:01:37 -0500248 subscribed = kzalloc(sizeof(*subscribed), GFP_KERNEL);
249 if (!subscribed) {
250 ret = -ENOMEM;
251 goto out_page;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200252 }
253
David Woodhouse5844d122007-12-18 02:01:37 -0500254 subscribed->hdr.size = cpu_to_le16(sizeof(*subscribed));
255 subscribed->action = cpu_to_le16(CMD_ACT_GET);
256
257 ret = lbs_cmd_with_response(priv, CMD_802_11_SUBSCRIBE_EVENT, subscribed);
258 if (ret)
259 goto out_cmd;
260
Holger Schurigb6b8abe2007-12-10 12:19:55 +0100261 got = lbs_tlv_find(tlv_type, subscribed->tlv, sizeof(subscribed->tlv));
Holger Schurig3a188642007-11-26 10:07:14 +0100262 if (got) {
263 value = got->value;
264 freq = got->freq;
Holger Schurigb6b8abe2007-12-10 12:19:55 +0100265 events = le16_to_cpu(subscribed->events);
David Woodhouse5844d122007-12-18 02:01:37 -0500266
267 pos += snprintf(buf, len, "%d %d %d\n", value, freq,
268 !!(events & event_mask));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200269 }
David Woodhouse5844d122007-12-18 02:01:37 -0500270
271 ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
272
273 out_cmd:
Holger Schurigb6b8abe2007-12-10 12:19:55 +0100274 kfree(subscribed);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200275
David Woodhouse5844d122007-12-18 02:01:37 -0500276 out_page:
277 free_page((unsigned long)buf);
278 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200279}
280
Holger Schurig3a188642007-11-26 10:07:14 +0100281
David Woodhouse5844d122007-12-18 02:01:37 -0500282static ssize_t lbs_threshold_write(uint16_t tlv_type, uint16_t event_mask,
283 struct file *file,
284 const char __user *userbuf, size_t count,
285 loff_t *ppos)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200286{
Holger Schurig3a188642007-11-26 10:07:14 +0100287 struct cmd_ds_802_11_subscribe_event *events;
Dan Williams75b6a612009-05-22 20:03:09 -0400288 struct mrvl_ie_thresholds *tlv;
David Woodhouse5844d122007-12-18 02:01:37 -0500289 struct lbs_private *priv = file->private_data;
290 ssize_t buf_size;
291 int value, freq, new_mask;
292 uint16_t curr_mask;
293 char *buf;
294 int ret;
295
296 buf = (char *)get_zeroed_page(GFP_KERNEL);
297 if (!buf)
298 return -ENOMEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200299
300 buf_size = min(count, len - 1);
301 if (copy_from_user(buf, userbuf, buf_size)) {
David Woodhouse5844d122007-12-18 02:01:37 -0500302 ret = -EFAULT;
303 goto out_page;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200304 }
David Woodhouse5844d122007-12-18 02:01:37 -0500305 ret = sscanf(buf, "%d %d %d", &value, &freq, &new_mask);
306 if (ret != 3) {
307 ret = -EINVAL;
308 goto out_page;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200309 }
David Woodhouse5844d122007-12-18 02:01:37 -0500310 events = kzalloc(sizeof(*events), GFP_KERNEL);
311 if (!events) {
312 ret = -ENOMEM;
313 goto out_page;
314 }
315
316 events->hdr.size = cpu_to_le16(sizeof(*events));
317 events->action = cpu_to_le16(CMD_ACT_GET);
318
319 ret = lbs_cmd_with_response(priv, CMD_802_11_SUBSCRIBE_EVENT, events);
320 if (ret)
321 goto out_events;
322
323 curr_mask = le16_to_cpu(events->events);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200324
Holger Schurig3a188642007-11-26 10:07:14 +0100325 if (new_mask)
326 new_mask = curr_mask | event_mask;
327 else
328 new_mask = curr_mask & ~event_mask;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200329
Holger Schurig3a188642007-11-26 10:07:14 +0100330 /* Now everything is set and we can send stuff down to the firmware */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200331
David Woodhouse5844d122007-12-18 02:01:37 -0500332 tlv = (void *)events->tlv;
333
334 events->action = cpu_to_le16(CMD_ACT_SET);
335 events->events = cpu_to_le16(new_mask);
336 tlv->header.type = cpu_to_le16(tlv_type);
337 tlv->header.len = cpu_to_le16(sizeof(*tlv) - sizeof(tlv->header));
338 tlv->value = value;
339 if (tlv_type != TLV_TYPE_BCNMISS)
340 tlv->freq = freq;
341
Holger Schuriga75eda42008-05-30 14:53:22 +0200342 /* The command header, the action, the event mask, and one TLV */
343 events->hdr.size = cpu_to_le16(sizeof(events->hdr) + 4 + sizeof(*tlv));
David Woodhouse5844d122007-12-18 02:01:37 -0500344
345 ret = lbs_cmd_with_response(priv, CMD_802_11_SUBSCRIBE_EVENT, events);
346
347 if (!ret)
348 ret = count;
349 out_events:
350 kfree(events);
351 out_page:
352 free_page((unsigned long)buf);
353 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200354}
355
Holger Schurig3a188642007-11-26 10:07:14 +0100356
David Woodhouse5844d122007-12-18 02:01:37 -0500357static ssize_t lbs_lowrssi_read(struct file *file, char __user *userbuf,
358 size_t count, loff_t *ppos)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200359{
Holger Schurig3a188642007-11-26 10:07:14 +0100360 return lbs_threshold_read(TLV_TYPE_RSSI_LOW, CMD_SUBSCRIBE_RSSI_LOW,
David Woodhouse5844d122007-12-18 02:01:37 -0500361 file, userbuf, count, ppos);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200362}
363
Holger Schurig3a188642007-11-26 10:07:14 +0100364
David Woodhouse5844d122007-12-18 02:01:37 -0500365static ssize_t lbs_lowrssi_write(struct file *file, const char __user *userbuf,
366 size_t count, loff_t *ppos)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200367{
Holger Schurig3a188642007-11-26 10:07:14 +0100368 return lbs_threshold_write(TLV_TYPE_RSSI_LOW, CMD_SUBSCRIBE_RSSI_LOW,
David Woodhouse5844d122007-12-18 02:01:37 -0500369 file, userbuf, count, ppos);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200370}
371
Holger Schurig3a188642007-11-26 10:07:14 +0100372
David Woodhouse5844d122007-12-18 02:01:37 -0500373static ssize_t lbs_lowsnr_read(struct file *file, char __user *userbuf,
374 size_t count, loff_t *ppos)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200375{
Holger Schurig3a188642007-11-26 10:07:14 +0100376 return lbs_threshold_read(TLV_TYPE_SNR_LOW, CMD_SUBSCRIBE_SNR_LOW,
David Woodhouse5844d122007-12-18 02:01:37 -0500377 file, userbuf, count, ppos);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200378}
379
Holger Schurig3a188642007-11-26 10:07:14 +0100380
David Woodhouse5844d122007-12-18 02:01:37 -0500381static ssize_t lbs_lowsnr_write(struct file *file, const char __user *userbuf,
382 size_t count, loff_t *ppos)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200383{
Holger Schurig3a188642007-11-26 10:07:14 +0100384 return lbs_threshold_write(TLV_TYPE_SNR_LOW, CMD_SUBSCRIBE_SNR_LOW,
David Woodhouse5844d122007-12-18 02:01:37 -0500385 file, userbuf, count, ppos);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200386}
387
Holger Schurig3a188642007-11-26 10:07:14 +0100388
David Woodhouse5844d122007-12-18 02:01:37 -0500389static ssize_t lbs_failcount_read(struct file *file, char __user *userbuf,
390 size_t count, loff_t *ppos)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200391{
Holger Schurig3a188642007-11-26 10:07:14 +0100392 return lbs_threshold_read(TLV_TYPE_FAILCOUNT, CMD_SUBSCRIBE_FAILCOUNT,
David Woodhouse5844d122007-12-18 02:01:37 -0500393 file, userbuf, count, ppos);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200394}
395
Holger Schurig3a188642007-11-26 10:07:14 +0100396
David Woodhouse5844d122007-12-18 02:01:37 -0500397static ssize_t lbs_failcount_write(struct file *file, const char __user *userbuf,
398 size_t count, loff_t *ppos)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200399{
Holger Schurig3a188642007-11-26 10:07:14 +0100400 return lbs_threshold_write(TLV_TYPE_FAILCOUNT, CMD_SUBSCRIBE_FAILCOUNT,
David Woodhouse5844d122007-12-18 02:01:37 -0500401 file, userbuf, count, ppos);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200402}
403
Holger Schurig3a188642007-11-26 10:07:14 +0100404
David Woodhouse5844d122007-12-18 02:01:37 -0500405static ssize_t lbs_highrssi_read(struct file *file, char __user *userbuf,
406 size_t count, loff_t *ppos)
Holger Schurig3a188642007-11-26 10:07:14 +0100407{
408 return lbs_threshold_read(TLV_TYPE_RSSI_HIGH, CMD_SUBSCRIBE_RSSI_HIGH,
David Woodhouse5844d122007-12-18 02:01:37 -0500409 file, userbuf, count, ppos);
Holger Schurig3a188642007-11-26 10:07:14 +0100410}
411
412
David Woodhouse5844d122007-12-18 02:01:37 -0500413static ssize_t lbs_highrssi_write(struct file *file, const char __user *userbuf,
414 size_t count, loff_t *ppos)
Holger Schurig3a188642007-11-26 10:07:14 +0100415{
416 return lbs_threshold_write(TLV_TYPE_RSSI_HIGH, CMD_SUBSCRIBE_RSSI_HIGH,
David Woodhouse5844d122007-12-18 02:01:37 -0500417 file, userbuf, count, ppos);
Holger Schurig3a188642007-11-26 10:07:14 +0100418}
419
420
David Woodhouse5844d122007-12-18 02:01:37 -0500421static ssize_t lbs_highsnr_read(struct file *file, char __user *userbuf,
422 size_t count, loff_t *ppos)
Holger Schurig3a188642007-11-26 10:07:14 +0100423{
424 return lbs_threshold_read(TLV_TYPE_SNR_HIGH, CMD_SUBSCRIBE_SNR_HIGH,
David Woodhouse5844d122007-12-18 02:01:37 -0500425 file, userbuf, count, ppos);
Holger Schurig3a188642007-11-26 10:07:14 +0100426}
427
428
David Woodhouse5844d122007-12-18 02:01:37 -0500429static ssize_t lbs_highsnr_write(struct file *file, const char __user *userbuf,
430 size_t count, loff_t *ppos)
Holger Schurig3a188642007-11-26 10:07:14 +0100431{
432 return lbs_threshold_write(TLV_TYPE_SNR_HIGH, CMD_SUBSCRIBE_SNR_HIGH,
David Woodhouse5844d122007-12-18 02:01:37 -0500433 file, userbuf, count, ppos);
Holger Schurig3a188642007-11-26 10:07:14 +0100434}
435
David Woodhouse5844d122007-12-18 02:01:37 -0500436static ssize_t lbs_bcnmiss_read(struct file *file, char __user *userbuf,
437 size_t count, loff_t *ppos)
Holger Schurig3a188642007-11-26 10:07:14 +0100438{
439 return lbs_threshold_read(TLV_TYPE_BCNMISS, CMD_SUBSCRIBE_BCNMISS,
David Woodhouse5844d122007-12-18 02:01:37 -0500440 file, userbuf, count, ppos);
Holger Schurig3a188642007-11-26 10:07:14 +0100441}
442
443
David Woodhouse5844d122007-12-18 02:01:37 -0500444static ssize_t lbs_bcnmiss_write(struct file *file, const char __user *userbuf,
445 size_t count, loff_t *ppos)
Holger Schurig3a188642007-11-26 10:07:14 +0100446{
447 return lbs_threshold_write(TLV_TYPE_BCNMISS, CMD_SUBSCRIBE_BCNMISS,
David Woodhouse5844d122007-12-18 02:01:37 -0500448 file, userbuf, count, ppos);
Holger Schurig3a188642007-11-26 10:07:14 +0100449}
450
451
Holger Schurig10078322007-11-15 18:05:47 -0500452static ssize_t lbs_rdmac_read(struct file *file, char __user *userbuf,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200453 size_t count, loff_t *ppos)
454{
Holger Schurig69f90322007-11-23 15:43:44 +0100455 struct lbs_private *priv = file->private_data;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200456 ssize_t pos = 0;
457 int ret;
458 unsigned long addr = get_zeroed_page(GFP_KERNEL);
459 char *buf = (char *)addr;
Dan Williams4c7c6e002010-07-27 13:01:07 -0700460 u32 val = 0;
461
Kiran Divekarad43f8b2009-08-28 17:47:59 +0530462 if (!buf)
463 return -ENOMEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200464
Dan Williams4c7c6e002010-07-27 13:01:07 -0700465 ret = lbs_get_reg(priv, CMD_MAC_REG_ACCESS, priv->mac_offset, &val);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200466 mdelay(10);
Amitkumar Karwarc0bbd572009-10-08 19:38:45 -0700467 if (!ret) {
Dan Williams4c7c6e002010-07-27 13:01:07 -0700468 pos = snprintf(buf, len, "MAC[0x%x] = 0x%08x\n",
469 priv->mac_offset, val);
Amitkumar Karwarc0bbd572009-10-08 19:38:45 -0700470 ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
471 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200472 free_page(addr);
473 return ret;
474}
475
Holger Schurig10078322007-11-15 18:05:47 -0500476static ssize_t lbs_rdmac_write(struct file *file,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200477 const char __user *userbuf,
478 size_t count, loff_t *ppos)
479{
Holger Schurig69f90322007-11-23 15:43:44 +0100480 struct lbs_private *priv = file->private_data;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200481 ssize_t res, buf_size;
482 unsigned long addr = get_zeroed_page(GFP_KERNEL);
483 char *buf = (char *)addr;
Kiran Divekarad43f8b2009-08-28 17:47:59 +0530484 if (!buf)
485 return -ENOMEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200486
487 buf_size = min(count, len - 1);
488 if (copy_from_user(buf, userbuf, buf_size)) {
489 res = -EFAULT;
490 goto out_unlock;
491 }
492 priv->mac_offset = simple_strtoul((char *)buf, NULL, 16);
493 res = count;
494out_unlock:
495 free_page(addr);
496 return res;
497}
498
Holger Schurig10078322007-11-15 18:05:47 -0500499static ssize_t lbs_wrmac_write(struct file *file,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200500 const char __user *userbuf,
501 size_t count, loff_t *ppos)
502{
503
Holger Schurig69f90322007-11-23 15:43:44 +0100504 struct lbs_private *priv = file->private_data;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200505 ssize_t res, buf_size;
506 u32 offset, value;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200507 unsigned long addr = get_zeroed_page(GFP_KERNEL);
508 char *buf = (char *)addr;
Kiran Divekarad43f8b2009-08-28 17:47:59 +0530509 if (!buf)
510 return -ENOMEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200511
512 buf_size = min(count, len - 1);
513 if (copy_from_user(buf, userbuf, buf_size)) {
514 res = -EFAULT;
515 goto out_unlock;
516 }
517 res = sscanf(buf, "%x %x", &offset, &value);
518 if (res != 2) {
519 res = -EFAULT;
520 goto out_unlock;
521 }
522
Dan Williams4c7c6e002010-07-27 13:01:07 -0700523 res = lbs_set_reg(priv, CMD_MAC_REG_ACCESS, offset, value);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200524 mdelay(10);
525
Amitkumar Karwarc0bbd572009-10-08 19:38:45 -0700526 if (!res)
527 res = count;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200528out_unlock:
529 free_page(addr);
530 return res;
531}
532
Holger Schurig10078322007-11-15 18:05:47 -0500533static ssize_t lbs_rdbbp_read(struct file *file, char __user *userbuf,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200534 size_t count, loff_t *ppos)
535{
Holger Schurig69f90322007-11-23 15:43:44 +0100536 struct lbs_private *priv = file->private_data;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200537 ssize_t pos = 0;
538 int ret;
539 unsigned long addr = get_zeroed_page(GFP_KERNEL);
540 char *buf = (char *)addr;
Dan Williams4c7c6e002010-07-27 13:01:07 -0700541 u32 val;
542
Kiran Divekarad43f8b2009-08-28 17:47:59 +0530543 if (!buf)
544 return -ENOMEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200545
Dan Williams4c7c6e002010-07-27 13:01:07 -0700546 ret = lbs_get_reg(priv, CMD_BBP_REG_ACCESS, priv->bbp_offset, &val);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200547 mdelay(10);
Amitkumar Karwarc0bbd572009-10-08 19:38:45 -0700548 if (!ret) {
Dan Williams4c7c6e002010-07-27 13:01:07 -0700549 pos = snprintf(buf, len, "BBP[0x%x] = 0x%08x\n",
550 priv->bbp_offset, val);
Amitkumar Karwarc0bbd572009-10-08 19:38:45 -0700551 ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
552 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200553 free_page(addr);
554
555 return ret;
556}
557
Holger Schurig10078322007-11-15 18:05:47 -0500558static ssize_t lbs_rdbbp_write(struct file *file,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200559 const char __user *userbuf,
560 size_t count, loff_t *ppos)
561{
Holger Schurig69f90322007-11-23 15:43:44 +0100562 struct lbs_private *priv = file->private_data;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200563 ssize_t res, buf_size;
564 unsigned long addr = get_zeroed_page(GFP_KERNEL);
565 char *buf = (char *)addr;
Kiran Divekarad43f8b2009-08-28 17:47:59 +0530566 if (!buf)
567 return -ENOMEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200568
569 buf_size = min(count, len - 1);
570 if (copy_from_user(buf, userbuf, buf_size)) {
571 res = -EFAULT;
572 goto out_unlock;
573 }
574 priv->bbp_offset = simple_strtoul((char *)buf, NULL, 16);
575 res = count;
576out_unlock:
577 free_page(addr);
578 return res;
579}
580
Holger Schurig10078322007-11-15 18:05:47 -0500581static ssize_t lbs_wrbbp_write(struct file *file,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200582 const char __user *userbuf,
583 size_t count, loff_t *ppos)
584{
585
Holger Schurig69f90322007-11-23 15:43:44 +0100586 struct lbs_private *priv = file->private_data;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200587 ssize_t res, buf_size;
588 u32 offset, value;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200589 unsigned long addr = get_zeroed_page(GFP_KERNEL);
590 char *buf = (char *)addr;
Kiran Divekarad43f8b2009-08-28 17:47:59 +0530591 if (!buf)
592 return -ENOMEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200593
594 buf_size = min(count, len - 1);
595 if (copy_from_user(buf, userbuf, buf_size)) {
596 res = -EFAULT;
597 goto out_unlock;
598 }
599 res = sscanf(buf, "%x %x", &offset, &value);
600 if (res != 2) {
601 res = -EFAULT;
602 goto out_unlock;
603 }
604
Dan Williams4c7c6e002010-07-27 13:01:07 -0700605 res = lbs_set_reg(priv, CMD_BBP_REG_ACCESS, offset, value);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200606 mdelay(10);
607
Amitkumar Karwarc0bbd572009-10-08 19:38:45 -0700608 if (!res)
609 res = count;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200610out_unlock:
611 free_page(addr);
612 return res;
613}
614
Holger Schurig10078322007-11-15 18:05:47 -0500615static ssize_t lbs_rdrf_read(struct file *file, char __user *userbuf,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200616 size_t count, loff_t *ppos)
617{
Holger Schurig69f90322007-11-23 15:43:44 +0100618 struct lbs_private *priv = file->private_data;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200619 ssize_t pos = 0;
620 int ret;
621 unsigned long addr = get_zeroed_page(GFP_KERNEL);
622 char *buf = (char *)addr;
Dan Williams4c7c6e002010-07-27 13:01:07 -0700623 u32 val;
624
Kiran Divekarad43f8b2009-08-28 17:47:59 +0530625 if (!buf)
626 return -ENOMEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200627
Dan Williams4c7c6e002010-07-27 13:01:07 -0700628 ret = lbs_get_reg(priv, CMD_RF_REG_ACCESS, priv->rf_offset, &val);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200629 mdelay(10);
Amitkumar Karwarc0bbd572009-10-08 19:38:45 -0700630 if (!ret) {
Dan Williams4c7c6e002010-07-27 13:01:07 -0700631 pos = snprintf(buf, len, "RF[0x%x] = 0x%08x\n",
632 priv->rf_offset, val);
Amitkumar Karwarc0bbd572009-10-08 19:38:45 -0700633 ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
634 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200635 free_page(addr);
636
637 return ret;
638}
639
Holger Schurig10078322007-11-15 18:05:47 -0500640static ssize_t lbs_rdrf_write(struct file *file,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200641 const char __user *userbuf,
642 size_t count, loff_t *ppos)
643{
Holger Schurig69f90322007-11-23 15:43:44 +0100644 struct lbs_private *priv = file->private_data;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200645 ssize_t res, buf_size;
646 unsigned long addr = get_zeroed_page(GFP_KERNEL);
647 char *buf = (char *)addr;
Kiran Divekarad43f8b2009-08-28 17:47:59 +0530648 if (!buf)
649 return -ENOMEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200650
651 buf_size = min(count, len - 1);
652 if (copy_from_user(buf, userbuf, buf_size)) {
653 res = -EFAULT;
654 goto out_unlock;
655 }
Jan Engelhardt4101dec2009-01-14 13:52:18 -0800656 priv->rf_offset = simple_strtoul(buf, NULL, 16);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200657 res = count;
658out_unlock:
659 free_page(addr);
660 return res;
661}
662
Holger Schurig10078322007-11-15 18:05:47 -0500663static ssize_t lbs_wrrf_write(struct file *file,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200664 const char __user *userbuf,
665 size_t count, loff_t *ppos)
666{
667
Holger Schurig69f90322007-11-23 15:43:44 +0100668 struct lbs_private *priv = file->private_data;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200669 ssize_t res, buf_size;
670 u32 offset, value;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200671 unsigned long addr = get_zeroed_page(GFP_KERNEL);
672 char *buf = (char *)addr;
Kiran Divekarad43f8b2009-08-28 17:47:59 +0530673 if (!buf)
674 return -ENOMEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200675
676 buf_size = min(count, len - 1);
677 if (copy_from_user(buf, userbuf, buf_size)) {
678 res = -EFAULT;
679 goto out_unlock;
680 }
681 res = sscanf(buf, "%x %x", &offset, &value);
682 if (res != 2) {
683 res = -EFAULT;
684 goto out_unlock;
685 }
686
Dan Williams4c7c6e002010-07-27 13:01:07 -0700687 res = lbs_set_reg(priv, CMD_RF_REG_ACCESS, offset, value);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200688 mdelay(10);
689
Amitkumar Karwarc0bbd572009-10-08 19:38:45 -0700690 if (!res)
691 res = count;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200692out_unlock:
693 free_page(addr);
694 return res;
695}
696
697#define FOPS(fread, fwrite) { \
698 .owner = THIS_MODULE, \
699 .open = open_file_generic, \
700 .read = (fread), \
701 .write = (fwrite), \
Arnd Bergmann2b18ab362010-07-06 19:05:31 +0200702 .llseek = generic_file_llseek, \
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200703}
704
Holger Schurig10078322007-11-15 18:05:47 -0500705struct lbs_debugfs_files {
Jan Engelhardt4101dec2009-01-14 13:52:18 -0800706 const char *name;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200707 int perm;
708 struct file_operations fops;
709};
710
Jan Engelhardt4101dec2009-01-14 13:52:18 -0800711static const struct lbs_debugfs_files debugfs_files[] = {
Holger Schurig10078322007-11-15 18:05:47 -0500712 { "info", 0444, FOPS(lbs_dev_info, write_file_dummy), },
Holger Schurig10078322007-11-15 18:05:47 -0500713 { "sleepparams", 0644, FOPS(lbs_sleepparams_read,
714 lbs_sleepparams_write), },
Amitkumar Karwar13118432010-07-08 06:43:48 +0530715 { "hostsleep", 0644, FOPS(lbs_host_sleep_read,
716 lbs_host_sleep_write), },
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200717};
718
Jan Engelhardt4101dec2009-01-14 13:52:18 -0800719static const struct lbs_debugfs_files debugfs_events_files[] = {
Holger Schurig10078322007-11-15 18:05:47 -0500720 {"low_rssi", 0644, FOPS(lbs_lowrssi_read,
721 lbs_lowrssi_write), },
722 {"low_snr", 0644, FOPS(lbs_lowsnr_read,
723 lbs_lowsnr_write), },
724 {"failure_count", 0644, FOPS(lbs_failcount_read,
725 lbs_failcount_write), },
726 {"beacon_missed", 0644, FOPS(lbs_bcnmiss_read,
727 lbs_bcnmiss_write), },
728 {"high_rssi", 0644, FOPS(lbs_highrssi_read,
729 lbs_highrssi_write), },
730 {"high_snr", 0644, FOPS(lbs_highsnr_read,
731 lbs_highsnr_write), },
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200732};
733
Jan Engelhardt4101dec2009-01-14 13:52:18 -0800734static const struct lbs_debugfs_files debugfs_regs_files[] = {
Holger Schurig10078322007-11-15 18:05:47 -0500735 {"rdmac", 0644, FOPS(lbs_rdmac_read, lbs_rdmac_write), },
736 {"wrmac", 0600, FOPS(NULL, lbs_wrmac_write), },
737 {"rdbbp", 0644, FOPS(lbs_rdbbp_read, lbs_rdbbp_write), },
738 {"wrbbp", 0600, FOPS(NULL, lbs_wrbbp_write), },
739 {"rdrf", 0644, FOPS(lbs_rdrf_read, lbs_rdrf_write), },
740 {"wrrf", 0600, FOPS(NULL, lbs_wrrf_write), },
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200741};
742
Holger Schurig10078322007-11-15 18:05:47 -0500743void lbs_debugfs_init(void)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200744{
Holger Schurig10078322007-11-15 18:05:47 -0500745 if (!lbs_dir)
746 lbs_dir = debugfs_create_dir("lbs_wireless", NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200747}
748
Holger Schurig10078322007-11-15 18:05:47 -0500749void lbs_debugfs_remove(void)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200750{
Holger Schurig10078322007-11-15 18:05:47 -0500751 if (lbs_dir)
752 debugfs_remove(lbs_dir);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200753}
754
Holger Schurig69f90322007-11-23 15:43:44 +0100755void lbs_debugfs_init_one(struct lbs_private *priv, struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200756{
757 int i;
Jan Engelhardt4101dec2009-01-14 13:52:18 -0800758 const struct lbs_debugfs_files *files;
Holger Schurig10078322007-11-15 18:05:47 -0500759 if (!lbs_dir)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200760 goto exit;
761
Holger Schurig10078322007-11-15 18:05:47 -0500762 priv->debugfs_dir = debugfs_create_dir(dev->name, lbs_dir);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200763 if (!priv->debugfs_dir)
764 goto exit;
765
766 for (i=0; i<ARRAY_SIZE(debugfs_files); i++) {
767 files = &debugfs_files[i];
768 priv->debugfs_files[i] = debugfs_create_file(files->name,
769 files->perm,
770 priv->debugfs_dir,
771 priv,
772 &files->fops);
773 }
774
775 priv->events_dir = debugfs_create_dir("subscribed_events", priv->debugfs_dir);
776 if (!priv->events_dir)
777 goto exit;
778
779 for (i=0; i<ARRAY_SIZE(debugfs_events_files); i++) {
780 files = &debugfs_events_files[i];
781 priv->debugfs_events_files[i] = debugfs_create_file(files->name,
782 files->perm,
783 priv->events_dir,
784 priv,
785 &files->fops);
786 }
787
788 priv->regs_dir = debugfs_create_dir("registers", priv->debugfs_dir);
789 if (!priv->regs_dir)
790 goto exit;
791
792 for (i=0; i<ARRAY_SIZE(debugfs_regs_files); i++) {
793 files = &debugfs_regs_files[i];
794 priv->debugfs_regs_files[i] = debugfs_create_file(files->name,
795 files->perm,
796 priv->regs_dir,
797 priv,
798 &files->fops);
799 }
800
801#ifdef PROC_DEBUG
Holger Schurige98a88d2008-03-19 14:25:58 +0100802 lbs_debug_init(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200803#endif
804exit:
805 return;
806}
807
Holger Schurig69f90322007-11-23 15:43:44 +0100808void lbs_debugfs_remove_one(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200809{
810 int i;
811
812 for(i=0; i<ARRAY_SIZE(debugfs_regs_files); i++)
813 debugfs_remove(priv->debugfs_regs_files[i]);
814
815 debugfs_remove(priv->regs_dir);
816
Holger Schurig0b7db952007-05-24 23:47:34 -0400817 for(i=0; i<ARRAY_SIZE(debugfs_events_files); i++)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200818 debugfs_remove(priv->debugfs_events_files[i]);
819
820 debugfs_remove(priv->events_dir);
821#ifdef PROC_DEBUG
822 debugfs_remove(priv->debugfs_debug);
823#endif
824 for(i=0; i<ARRAY_SIZE(debugfs_files); i++)
825 debugfs_remove(priv->debugfs_files[i]);
Holger Schurig0b7db952007-05-24 23:47:34 -0400826 debugfs_remove(priv->debugfs_dir);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200827}
828
Holger Schurig46868202007-05-25 00:37:28 -0400829
830
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200831/* debug entry */
832
Holger Schurig46868202007-05-25 00:37:28 -0400833#ifdef PROC_DEBUG
834
David Woodhouseaa21c002007-12-08 20:04:36 +0000835#define item_size(n) (FIELD_SIZEOF(struct lbs_private, n))
836#define item_addr(n) (offsetof(struct lbs_private, n))
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200837
Holger Schurig46868202007-05-25 00:37:28 -0400838
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200839struct debug_data {
840 char name[32];
841 u32 size;
Dan Williams4269e2a2007-05-10 23:10:18 -0400842 size_t addr;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200843};
844
David Woodhouseaa21c002007-12-08 20:04:36 +0000845/* To debug any member of struct lbs_private, simply add one line here.
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200846 */
847static struct debug_data items[] = {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200848 {"psmode", item_size(psmode), item_addr(psmode)},
849 {"psstate", item_size(psstate), item_addr(psstate)},
850};
851
Tony Breedsd2f11e02007-03-09 13:11:46 +1100852static int num_of_items = ARRAY_SIZE(items);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200853
854/**
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700855 * lbs_debugfs_read - proc read function
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200856 *
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700857 * @file: file to read
858 * @userbuf: pointer to buffer
859 * @count: number of bytes to read
860 * @ppos: read data starting position
861 *
862 * returns: amount of data read or negative error code
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200863 */
Holger Schurig10078322007-11-15 18:05:47 -0500864static ssize_t lbs_debugfs_read(struct file *file, char __user *userbuf,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200865 size_t count, loff_t *ppos)
866{
867 int val = 0;
868 size_t pos = 0;
869 ssize_t res;
870 char *p;
871 int i;
872 struct debug_data *d;
873 unsigned long addr = get_zeroed_page(GFP_KERNEL);
874 char *buf = (char *)addr;
Kiran Divekarad43f8b2009-08-28 17:47:59 +0530875 if (!buf)
876 return -ENOMEM;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200877
878 p = buf;
879
Joe Perches57674302010-07-12 13:50:06 -0700880 d = file->private_data;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200881
882 for (i = 0; i < num_of_items; i++) {
883 if (d[i].size == 1)
884 val = *((u8 *) d[i].addr);
885 else if (d[i].size == 2)
886 val = *((u16 *) d[i].addr);
887 else if (d[i].size == 4)
888 val = *((u32 *) d[i].addr);
Dan Williams4269e2a2007-05-10 23:10:18 -0400889 else if (d[i].size == 8)
890 val = *((u64 *) d[i].addr);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200891
892 pos += sprintf(p + pos, "%s=%d\n", d[i].name, val);
893 }
894
895 res = simple_read_from_buffer(userbuf, count, ppos, p, pos);
896
897 free_page(addr);
898 return res;
899}
900
901/**
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700902 * lbs_debugfs_write - proc write function
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200903 *
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700904 * @f: file pointer
905 * @buf: pointer to data buffer
906 * @cnt: data number to write
907 * @ppos: file position
908 *
909 * returns: amount of data written
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200910 */
Holger Schurig10078322007-11-15 18:05:47 -0500911static ssize_t lbs_debugfs_write(struct file *f, const char __user *buf,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200912 size_t cnt, loff_t *ppos)
913{
914 int r, i;
915 char *pdata;
916 char *p;
917 char *p0;
918 char *p1;
919 char *p2;
Joe Perches57674302010-07-12 13:50:06 -0700920 struct debug_data *d = f->private_data;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200921
Jesper Juhl655b4d12007-08-24 11:48:16 -0400922 pdata = kmalloc(cnt, GFP_KERNEL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200923 if (pdata == NULL)
924 return 0;
925
926 if (copy_from_user(pdata, buf, cnt)) {
Holger Schurig9012b282007-05-25 11:27:16 -0400927 lbs_deb_debugfs("Copy from user failed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200928 kfree(pdata);
929 return 0;
930 }
931
932 p0 = pdata;
933 for (i = 0; i < num_of_items; i++) {
934 do {
935 p = strstr(p0, d[i].name);
936 if (p == NULL)
937 break;
938 p1 = strchr(p, '\n');
939 if (p1 == NULL)
940 break;
941 p0 = p1++;
942 p2 = strchr(p, '=');
943 if (!p2)
944 break;
945 p2++;
Tony Breedsd2f11e02007-03-09 13:11:46 +1100946 r = simple_strtoul(p2, NULL, 0);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200947 if (d[i].size == 1)
948 *((u8 *) d[i].addr) = (u8) r;
949 else if (d[i].size == 2)
950 *((u16 *) d[i].addr) = (u16) r;
951 else if (d[i].size == 4)
952 *((u32 *) d[i].addr) = (u32) r;
Dan Williams4269e2a2007-05-10 23:10:18 -0400953 else if (d[i].size == 8)
954 *((u64 *) d[i].addr) = (u64) r;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200955 break;
956 } while (1);
957 }
958 kfree(pdata);
959
Dan Williams4269e2a2007-05-10 23:10:18 -0400960 return (ssize_t)cnt;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200961}
962
Jan Engelhardt4101dec2009-01-14 13:52:18 -0800963static const struct file_operations lbs_debug_fops = {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200964 .owner = THIS_MODULE,
965 .open = open_file_generic,
Holger Schurig10078322007-11-15 18:05:47 -0500966 .write = lbs_debugfs_write,
967 .read = lbs_debugfs_read,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200968 .llseek = default_llseek,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200969};
970
971/**
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700972 * lbs_debug_init - create debug proc file
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200973 *
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700974 * @priv: pointer to &struct lbs_private
975 *
976 * returns: N/A
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200977 */
Holger Schurige98a88d2008-03-19 14:25:58 +0100978static void lbs_debug_init(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200979{
980 int i;
981
982 if (!priv->debugfs_dir)
983 return;
984
985 for (i = 0; i < num_of_items; i++)
David Woodhouseaa21c002007-12-08 20:04:36 +0000986 items[i].addr += (size_t) priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200987
988 priv->debugfs_debug = debugfs_create_file("debug", 0644,
989 priv->debugfs_dir, &items[0],
Holger Schurig10078322007-11-15 18:05:47 -0500990 &lbs_debug_fops);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200991}
Holger Schurig46868202007-05-25 00:37:28 -0400992#endif