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