Merge branch 'modules-next' of git://git.kernel.org/pub/scm/linux/kernel/git/rusty...
[deliverable/linux.git] / drivers / staging / silicom / bp_proc.c
1 /******************************************************************************/
2 /* */
3 /* Copyright (c) 2004-2006 Silicom, Ltd */
4 /* All rights reserved. */
5 /* */
6 /* This program is free software; you can redistribute it and/or modify */
7 /* it under the terms of the GNU General Public License as published by */
8 /* the Free Software Foundation, located in the file LICENSE. */
9 /* */
10 /* */
11 /******************************************************************************/
12
13 #include <linux/version.h>
14 #if defined(CONFIG_SMP) && ! defined(__SMP__)
15 #define __SMP__
16 #endif
17
18 #include <linux/proc_fs.h>
19 #include <linux/netdevice.h>
20 #include <asm/uaccess.h>
21 //#include <linux/smp_lock.h>
22 #include "bp_mod.h"
23
24 #define BP_PROC_DIR "bypass"
25 //#define BYPASS_SUPPORT "bypass"
26
27 #ifdef BYPASS_SUPPORT
28
29 #define GPIO6_SET_ENTRY_SD "gpio6_set"
30 #define GPIO6_CLEAR_ENTRY_SD "gpio6_clear"
31
32 #define GPIO7_SET_ENTRY_SD "gpio7_set"
33 #define GPIO7_CLEAR_ENTRY_SD "gpio7_clear"
34
35 #define PULSE_SET_ENTRY_SD "pulse_set"
36 #define ZERO_SET_ENTRY_SD "zero_set"
37 #define PULSE_GET1_ENTRY_SD "pulse_get1"
38 #define PULSE_GET2_ENTRY_SD "pulse_get2"
39
40 #define CMND_ON_ENTRY_SD "cmnd_on"
41 #define CMND_OFF_ENTRY_SD "cmnd_off"
42 #define RESET_CONT_ENTRY_SD "reset_cont"
43
44 /*COMMANDS*/
45 #define BYPASS_INFO_ENTRY_SD "bypass_info"
46 #define BYPASS_SLAVE_ENTRY_SD "bypass_slave"
47 #define BYPASS_CAPS_ENTRY_SD "bypass_caps"
48 #define WD_SET_CAPS_ENTRY_SD "wd_set_caps"
49 #define BYPASS_ENTRY_SD "bypass"
50 #define BYPASS_CHANGE_ENTRY_SD "bypass_change"
51 #define BYPASS_WD_ENTRY_SD "bypass_wd"
52 #define WD_EXPIRE_TIME_ENTRY_SD "wd_expire_time"
53 #define RESET_BYPASS_WD_ENTRY_SD "reset_bypass_wd"
54 #define DIS_BYPASS_ENTRY_SD "dis_bypass"
55 #define BYPASS_PWUP_ENTRY_SD "bypass_pwup"
56 #define BYPASS_PWOFF_ENTRY_SD "bypass_pwoff"
57 #define STD_NIC_ENTRY_SD "std_nic"
58 #define STD_NIC_ENTRY_SD "std_nic"
59 #define TAP_ENTRY_SD "tap"
60 #define TAP_CHANGE_ENTRY_SD "tap_change"
61 #define DIS_TAP_ENTRY_SD "dis_tap"
62 #define TAP_PWUP_ENTRY_SD "tap_pwup"
63 #define TWO_PORT_LINK_ENTRY_SD "two_port_link"
64 #define WD_EXP_MODE_ENTRY_SD "wd_exp_mode"
65 #define WD_AUTORESET_ENTRY_SD "wd_autoreset"
66 #define TPL_ENTRY_SD "tpl"
67 #define WAIT_AT_PWUP_ENTRY_SD "wait_at_pwup"
68 #define HW_RESET_ENTRY_SD "hw_reset"
69 #define DISC_ENTRY_SD "disc"
70 #define DISC_CHANGE_ENTRY_SD "disc_change"
71 #define DIS_DISC_ENTRY_SD "dis_disc"
72 #define DISC_PWUP_ENTRY_SD "disc_pwup"
73 #endif //bypass_support
74 static struct proc_dir_entry *bp_procfs_dir;
75
76 static struct proc_dir_entry *proc_getdir(char *name,
77 struct proc_dir_entry *proc_dir)
78 {
79 struct proc_dir_entry *pde = proc_dir;
80 for (pde = pde->subdir; pde; pde = pde->next) {
81 if (pde->namelen && (strcmp(name, pde->name) == 0)) {
82 /* directory exists */
83 break;
84 }
85 }
86 if (pde == (struct proc_dir_entry *)0) {
87 /* create the directory */
88 pde = create_proc_entry(name, S_IFDIR, proc_dir);
89 if (pde == (struct proc_dir_entry *)0) {
90 return (pde);
91 }
92 }
93 return (pde);
94 }
95
96 #ifdef BYPASS_SUPPORT
97
98 int
99 bypass_proc_create_entry_sd(struct pfs_unit *pfs_unit_curr,
100 char *proc_name,
101 write_proc_t * write_proc,
102 read_proc_t * read_proc,
103 struct proc_dir_entry *parent_pfs, void *data)
104 {
105 strcpy(pfs_unit_curr->proc_name, proc_name);
106 pfs_unit_curr->proc_entry = create_proc_entry(pfs_unit_curr->proc_name,
107 S_IFREG | S_IRUSR |
108 S_IWUSR | S_IRGRP |
109 S_IROTH, parent_pfs);
110 if (pfs_unit_curr->proc_entry == 0) {
111
112 return -1;
113 }
114
115 pfs_unit_curr->proc_entry->read_proc = read_proc;
116 pfs_unit_curr->proc_entry->write_proc = write_proc;
117 pfs_unit_curr->proc_entry->data = data;
118
119 return 0;
120
121 }
122
123 int
124 get_bypass_info_pfs(char *page, char **start, off_t off, int count,
125 int *eof, void *data)
126 {
127 bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data;
128 int len = 0;
129
130 len += sprintf(page, "Name\t\t\t%s\n", pbp_device_block->bp_name);
131 len +=
132 sprintf(page + len, "Firmware version\t0x%x\n",
133 pbp_device_block->bp_fw_ver);
134
135 *eof = 1;
136 return len;
137 }
138
139 int
140 get_bypass_slave_pfs(char *page, char **start, off_t off, int count,
141 int *eof, void *data)
142 {
143 bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data;
144
145 struct pci_dev *pci_slave_dev = pbp_device_block->bp_slave;
146 struct net_device *net_slave_dev;
147 int len = 0;
148
149 if (is_bypass_fn(pbp_device_block)) {
150 net_slave_dev = pci_get_drvdata(pci_slave_dev);
151 if (net_slave_dev)
152 len = sprintf(page, "%s\n", net_slave_dev->name);
153 else
154 len = sprintf(page, "fail\n");
155 } else
156 len = sprintf(page, "fail\n");
157
158 *eof = 1;
159 return len;
160 }
161
162 int
163 get_bypass_caps_pfs(char *page, char **start, off_t off, int count,
164 int *eof, void *data)
165 {
166 bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data;
167
168 int len = 0, ret = 0;
169
170 ret = get_bypass_caps_fn(pbp_device_block);
171 if (ret == BP_NOT_CAP)
172 len = sprintf(page, "-1\n");
173 else
174 len = sprintf(page, "0x%x\n", ret);
175 *eof = 1;
176 return len;
177
178 }
179
180 int
181 get_wd_set_caps_pfs(char *page, char **start, off_t off, int count,
182 int *eof, void *data)
183 {
184 bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data;
185
186 int len = 0, ret = 0;
187
188 ret = get_wd_set_caps_fn(pbp_device_block);
189 if (ret == BP_NOT_CAP)
190 len = sprintf(page, "-1\n");
191 else
192 len = sprintf(page, "0x%x\n", ret);
193 *eof = 1;
194 return len;
195 }
196
197 int
198 set_bypass_pfs(struct file *file, const char *buffer,
199 unsigned long count, void *data)
200 {
201
202 char kbuf[256];
203 bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data;
204
205 int bypass_param = 0, length = 0;
206
207 if (count > (sizeof(kbuf) - 1))
208 return -1;
209
210 if (copy_from_user(&kbuf, buffer, count)) {
211 return -1;
212 }
213
214 kbuf[count] = '\0';
215 length = strlen(kbuf);
216 if (kbuf[length - 1] == '\n')
217 kbuf[--length] = '\0';
218
219 if (strcmp(kbuf, "on") == 0)
220 bypass_param = 1;
221 else if (strcmp(kbuf, "off") == 0)
222 bypass_param = 0;
223
224 set_bypass_fn(pbp_device_block, bypass_param);
225
226 return count;
227 }
228
229 int
230 set_tap_pfs(struct file *file, const char *buffer,
231 unsigned long count, void *data)
232 {
233
234 char kbuf[256];
235 bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data;
236
237 int tap_param = 0, length = 0;
238
239 if (count > (sizeof(kbuf) - 1))
240 return -1;
241
242 if (copy_from_user(&kbuf, buffer, count)) {
243 return -1;
244 }
245
246 kbuf[count] = '\0';
247 length = strlen(kbuf);
248 if (kbuf[length - 1] == '\n')
249 kbuf[--length] = '\0';
250
251 if (strcmp(kbuf, "on") == 0)
252 tap_param = 1;
253 else if (strcmp(kbuf, "off") == 0)
254 tap_param = 0;
255
256 set_tap_fn(pbp_device_block, tap_param);
257
258 return count;
259 }
260
261 int
262 set_disc_pfs(struct file *file, const char *buffer,
263 unsigned long count, void *data)
264 {
265
266 char kbuf[256];
267 bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data;
268
269 int tap_param = 0, length = 0;
270
271 if (count > (sizeof(kbuf) - 1))
272 return -1;
273
274 if (copy_from_user(&kbuf, buffer, count)) {
275 return -1;
276 }
277
278 kbuf[count] = '\0';
279 length = strlen(kbuf);
280 if (kbuf[length - 1] == '\n')
281 kbuf[--length] = '\0';
282
283 if (strcmp(kbuf, "on") == 0)
284 tap_param = 1;
285 else if (strcmp(kbuf, "off") == 0)
286 tap_param = 0;
287
288 set_disc_fn(pbp_device_block, tap_param);
289
290 return count;
291 }
292
293 int
294 get_bypass_pfs(char *page, char **start, off_t off, int count,
295 int *eof, void *data)
296 {
297 bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data;
298
299 int len = 0, ret = 0;
300
301 ret = get_bypass_fn(pbp_device_block);
302 if (ret == BP_NOT_CAP)
303 len = sprintf(page, "fail\n");
304 else if (ret == 1)
305 len = sprintf(page, "on\n");
306 else if (ret == 0)
307 len = sprintf(page, "off\n");
308
309 *eof = 1;
310 return len;
311 }
312
313 int
314 get_tap_pfs(char *page, char **start, off_t off, int count,
315 int *eof, void *data)
316 {
317 bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data;
318
319 int len = 0, ret = 0;
320
321 ret = get_tap_fn(pbp_device_block);
322 if (ret == BP_NOT_CAP)
323 len = sprintf(page, "fail\n");
324 else if (ret == 1)
325 len = sprintf(page, "on\n");
326 else if (ret == 0)
327 len = sprintf(page, "off\n");
328
329 *eof = 1;
330 return len;
331 }
332
333 int
334 get_disc_pfs(char *page, char **start, off_t off, int count,
335 int *eof, void *data)
336 {
337 bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data;
338
339 int len = 0, ret = 0;
340
341 ret = get_disc_fn(pbp_device_block);
342 if (ret == BP_NOT_CAP)
343 len = sprintf(page, "fail\n");
344 else if (ret == 1)
345 len = sprintf(page, "on\n");
346 else if (ret == 0)
347 len = sprintf(page, "off\n");
348
349 *eof = 1;
350 return len;
351 }
352
353 int
354 get_bypass_change_pfs(char *page, char **start, off_t off, int count,
355 int *eof, void *data)
356 {
357 bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data;
358
359 int len = 0, ret = 0;
360
361 ret = get_bypass_change_fn(pbp_device_block);
362 if (ret == 1)
363 len = sprintf(page, "on\n");
364 else if (ret == 0)
365 len = sprintf(page, "off\n");
366 else
367 len = sprintf(page, "fail\n");
368
369 *eof = 1;
370 return len;
371 }
372
373 int
374 get_tap_change_pfs(char *page, char **start, off_t off, int count,
375 int *eof, void *data)
376 {
377 bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data;
378
379 int len = 0, ret = 0;
380
381 ret = get_tap_change_fn(pbp_device_block);
382 if (ret == 1)
383 len = sprintf(page, "on\n");
384 else if (ret == 0)
385 len = sprintf(page, "off\n");
386 else
387 len = sprintf(page, "fail\n");
388
389 *eof = 1;
390 return len;
391 }
392
393 int
394 get_disc_change_pfs(char *page, char **start, off_t off, int count,
395 int *eof, void *data)
396 {
397 bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data;
398
399 int len = 0, ret = 0;
400
401 ret = get_disc_change_fn(pbp_device_block);
402 if (ret == 1)
403 len = sprintf(page, "on\n");
404 else if (ret == 0)
405 len = sprintf(page, "off\n");
406 else
407 len = sprintf(page, "fail\n");
408
409 *eof = 1;
410 return len;
411 }
412
413 int
414 set_bypass_wd_pfs(struct file *file, const char *buffer,
415 unsigned long count, void *data)
416 {
417
418 char kbuf[256];
419 bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data;
420
421 unsigned int timeout = 0;
422 char *timeout_ptr = kbuf;
423
424 if (copy_from_user(&kbuf, buffer, count)) {
425 return -1;
426 }
427
428 timeout_ptr = kbuf;
429 timeout = atoi(&timeout_ptr);
430
431 set_bypass_wd_fn(pbp_device_block, timeout);
432
433 return count;
434 }
435
436 int
437 get_bypass_wd_pfs(char *page, char **start, off_t off, int count,
438 int *eof, void *data)
439 {
440 bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data;
441
442 int len = 0, ret = 0, timeout = 0;
443
444 ret = get_bypass_wd_fn(pbp_device_block, &timeout);
445 if (ret == BP_NOT_CAP)
446 len = sprintf(page, "fail\n");
447 else if (timeout == -1)
448 len = sprintf(page, "unknown\n");
449 else if (timeout == 0)
450 len = sprintf(page, "disable\n");
451 else
452 len = sprintf(page, "%d\n", timeout);
453
454 *eof = 1;
455 return len;
456 }
457
458 int
459 get_wd_expire_time_pfs(char *page, char **start, off_t off, int count,
460 int *eof, void *data)
461 {
462 bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data;
463
464 int len = 0, ret = 0, timeout = 0;
465
466 ret = get_wd_expire_time_fn(pbp_device_block, &timeout);
467 if (ret == BP_NOT_CAP)
468 len = sprintf(page, "fail\n");
469 else if (timeout == -1)
470 len = sprintf(page, "expire\n");
471 else if (timeout == 0)
472 len = sprintf(page, "disable\n");
473
474 else
475 len = sprintf(page, "%d\n", timeout);
476 *eof = 1;
477 return len;
478 }
479
480 int
481 get_tpl_pfs(char *page, char **start, off_t off, int count,
482 int *eof, void *data)
483 {
484 bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data;
485
486 int len = 0, ret = 0;
487
488 ret = get_tpl_fn(pbp_device_block);
489 if (ret == BP_NOT_CAP)
490 len = sprintf(page, "fail\n");
491 else if (ret == 1)
492 len = sprintf(page, "on\n");
493 else if (ret == 0)
494 len = sprintf(page, "off\n");
495
496 *eof = 1;
497 return len;
498 }
499
500 #ifdef PMC_FIX_FLAG
501 int
502 get_wait_at_pwup_pfs(char *page, char **start, off_t off, int count,
503 int *eof, void *data)
504 {
505 bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data;
506
507 int len = 0, ret = 0;
508
509 ret = get_bp_wait_at_pwup_fn(pbp_device_block);
510 if (ret == BP_NOT_CAP)
511 len = sprintf(page, "fail\n");
512 else if (ret == 1)
513 len = sprintf(page, "on\n");
514 else if (ret == 0)
515 len = sprintf(page, "off\n");
516
517 *eof = 1;
518 return len;
519 }
520
521 int
522 get_hw_reset_pfs(char *page, char **start, off_t off, int count,
523 int *eof, void *data)
524 {
525 bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data;
526
527 int len = 0, ret = 0;
528
529 ret = get_bp_hw_reset_fn(pbp_device_block);
530 if (ret == BP_NOT_CAP)
531 len = sprintf(page, "fail\n");
532 else if (ret == 1)
533 len = sprintf(page, "on\n");
534 else if (ret == 0)
535 len = sprintf(page, "off\n");
536
537 *eof = 1;
538 return len;
539 }
540
541 #endif /*PMC_WAIT_FLAG */
542
543 int
544 reset_bypass_wd_pfs(char *page, char **start, off_t off, int count,
545 int *eof, void *data)
546 {
547 bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data;
548
549 int len = 0, ret = 0;
550
551 ret = reset_bypass_wd_timer_fn(pbp_device_block);
552 if (ret == BP_NOT_CAP)
553 len = sprintf(page, "fail\n");
554 else if (ret == 0)
555 len = sprintf(page, "disable\n");
556 else if (ret == 1)
557 len = sprintf(page, "success\n");
558
559 *eof = 1;
560 return len;
561 }
562
563 int
564 set_dis_bypass_pfs(struct file *file, const char *buffer,
565 unsigned long count, void *data)
566 {
567
568 char kbuf[256];
569 bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data;
570
571 int bypass_param = 0, length = 0;
572
573 if (copy_from_user(&kbuf, buffer, count)) {
574 return -1;
575 }
576
577 kbuf[count] = '\0';
578 length = strlen(kbuf);
579 if (kbuf[length - 1] == '\n')
580 kbuf[--length] = '\0';
581
582 if (strcmp(kbuf, "on") == 0)
583 bypass_param = 1;
584 else if (strcmp(kbuf, "off") == 0)
585 bypass_param = 0;
586
587 set_dis_bypass_fn(pbp_device_block, bypass_param);
588
589 return count;
590 }
591
592 int
593 set_dis_tap_pfs(struct file *file, const char *buffer,
594 unsigned long count, void *data)
595 {
596
597 char kbuf[256];
598 bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data;
599
600 int tap_param = 0, length = 0;
601
602 if (copy_from_user(&kbuf, buffer, count)) {
603 return -1;
604 }
605
606 kbuf[count] = '\0';
607 length = strlen(kbuf);
608 if (kbuf[length - 1] == '\n')
609 kbuf[--length] = '\0';
610
611 if (strcmp(kbuf, "on") == 0)
612 tap_param = 1;
613 else if (strcmp(kbuf, "off") == 0)
614 tap_param = 0;
615
616 set_dis_tap_fn(pbp_device_block, tap_param);
617
618 return count;
619 }
620
621 int
622 set_dis_disc_pfs(struct file *file, const char *buffer,
623 unsigned long count, void *data)
624 {
625
626 char kbuf[256];
627 bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data;
628
629 int tap_param = 0, length = 0;
630
631 if (copy_from_user(&kbuf, buffer, count)) {
632 return -1;
633 }
634
635 kbuf[count] = '\0';
636 length = strlen(kbuf);
637 if (kbuf[length - 1] == '\n')
638 kbuf[--length] = '\0';
639
640 if (strcmp(kbuf, "on") == 0)
641 tap_param = 1;
642 else if (strcmp(kbuf, "off") == 0)
643 tap_param = 0;
644
645 set_dis_disc_fn(pbp_device_block, tap_param);
646
647 return count;
648 }
649
650 int
651 get_dis_bypass_pfs(char *page, char **start, off_t off, int count,
652 int *eof, void *data)
653 {
654 bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data;
655
656 int len = 0, ret = 0;
657
658 ret = get_dis_bypass_fn(pbp_device_block);
659 if (ret == BP_NOT_CAP)
660 len = sprintf(page, "fail\n");
661 else if (ret == 0)
662 len = sprintf(page, "off\n");
663 else
664 len = sprintf(page, "on\n");
665
666 *eof = 1;
667 return len;
668 }
669
670 int
671 get_dis_tap_pfs(char *page, char **start, off_t off, int count,
672 int *eof, void *data)
673 {
674 bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data;
675
676 int len = 0, ret = 0;
677
678 ret = get_dis_tap_fn(pbp_device_block);
679 if (ret == BP_NOT_CAP)
680 len = sprintf(page, "fail\n");
681 else if (ret == 0)
682 len = sprintf(page, "off\n");
683 else
684 len = sprintf(page, "on\n");
685
686 *eof = 1;
687 return len;
688 }
689
690 int
691 get_dis_disc_pfs(char *page, char **start, off_t off, int count,
692 int *eof, void *data)
693 {
694 bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data;
695
696 int len = 0, ret = 0;
697
698 ret = get_dis_disc_fn(pbp_device_block);
699 if (ret == BP_NOT_CAP)
700 len = sprintf(page, "fail\n");
701 else if (ret == 0)
702 len = sprintf(page, "off\n");
703 else
704 len = sprintf(page, "on\n");
705
706 *eof = 1;
707 return len;
708 }
709
710 int
711 set_bypass_pwup_pfs(struct file *file, const char *buffer,
712 unsigned long count, void *data)
713 {
714
715 char kbuf[256];
716 bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data;
717
718 int bypass_param = 0, length = 0;
719
720 if (copy_from_user(&kbuf, buffer, count)) {
721 return -1;
722 }
723
724 kbuf[count] = '\0';
725 length = strlen(kbuf);
726 if (kbuf[length - 1] == '\n')
727 kbuf[--length] = '\0';
728
729 if (strcmp(kbuf, "on") == 0)
730 bypass_param = 1;
731 else if (strcmp(kbuf, "off") == 0)
732 bypass_param = 0;
733
734 set_bypass_pwup_fn(pbp_device_block, bypass_param);
735
736 return count;
737 }
738
739 int
740 set_bypass_pwoff_pfs(struct file *file, const char *buffer,
741 unsigned long count, void *data)
742 {
743
744 char kbuf[256];
745 bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data;
746
747 int bypass_param = 0, length = 0;
748
749 if (copy_from_user(&kbuf, buffer, count)) {
750 return -1;
751 }
752
753 kbuf[count] = '\0';
754 length = strlen(kbuf);
755 if (kbuf[length - 1] == '\n')
756 kbuf[--length] = '\0';
757
758 if (strcmp(kbuf, "on") == 0)
759 bypass_param = 1;
760 else if (strcmp(kbuf, "off") == 0)
761 bypass_param = 0;
762
763 set_bypass_pwoff_fn(pbp_device_block, bypass_param);
764
765 return count;
766 }
767
768 int
769 set_tap_pwup_pfs(struct file *file, const char *buffer,
770 unsigned long count, void *data)
771 {
772
773 char kbuf[256];
774 bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data;
775
776 int tap_param = 0, length = 0;
777
778 if (copy_from_user(&kbuf, buffer, count)) {
779 return -1;
780 }
781
782 kbuf[count] = '\0';
783 length = strlen(kbuf);
784 if (kbuf[length - 1] == '\n')
785 kbuf[--length] = '\0';
786
787 if (strcmp(kbuf, "on") == 0)
788 tap_param = 1;
789 else if (strcmp(kbuf, "off") == 0)
790 tap_param = 0;
791
792 set_tap_pwup_fn(pbp_device_block, tap_param);
793
794 return count;
795 }
796
797 int
798 set_disc_pwup_pfs(struct file *file, const char *buffer,
799 unsigned long count, void *data)
800 {
801
802 char kbuf[256];
803 bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data;
804
805 int tap_param = 0, length = 0;
806
807 if (copy_from_user(&kbuf, buffer, count)) {
808 return -1;
809 }
810
811 kbuf[count] = '\0';
812 length = strlen(kbuf);
813 if (kbuf[length - 1] == '\n')
814 kbuf[--length] = '\0';
815
816 if (strcmp(kbuf, "on") == 0)
817 tap_param = 1;
818 else if (strcmp(kbuf, "off") == 0)
819 tap_param = 0;
820
821 set_disc_pwup_fn(pbp_device_block, tap_param);
822
823 return count;
824 }
825
826 int
827 get_bypass_pwup_pfs(char *page, char **start, off_t off, int count,
828 int *eof, void *data)
829 {
830 bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data;
831
832 int len = 0, ret = 0;
833
834 ret = get_bypass_pwup_fn(pbp_device_block);
835 if (ret == BP_NOT_CAP)
836 len = sprintf(page, "fail\n");
837 else if (ret == 0)
838 len = sprintf(page, "off\n");
839 else
840 len = sprintf(page, "on\n");
841
842 *eof = 1;
843 return len;
844 }
845
846 int
847 get_bypass_pwoff_pfs(char *page, char **start, off_t off, int count,
848 int *eof, void *data)
849 {
850 bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data;
851
852 int len = 0, ret = 0;
853
854 ret = get_bypass_pwoff_fn(pbp_device_block);
855 if (ret == BP_NOT_CAP)
856 len = sprintf(page, "fail\n");
857 else if (ret == 0)
858 len = sprintf(page, "off\n");
859 else
860 len = sprintf(page, "on\n");
861
862 *eof = 1;
863 return len;
864 }
865
866 int
867 get_tap_pwup_pfs(char *page, char **start, off_t off, int count,
868 int *eof, void *data)
869 {
870 bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data;
871
872 int len = 0, ret = 0;
873
874 ret = get_tap_pwup_fn(pbp_device_block);
875 if (ret == BP_NOT_CAP)
876 len = sprintf(page, "fail\n");
877 else if (ret == 0)
878 len = sprintf(page, "off\n");
879 else
880 len = sprintf(page, "on\n");
881
882 *eof = 1;
883 return len;
884 }
885
886 int
887 get_disc_pwup_pfs(char *page, char **start, off_t off, int count,
888 int *eof, void *data)
889 {
890 bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data;
891
892 int len = 0, ret = 0;
893
894 ret = get_disc_pwup_fn(pbp_device_block);
895 if (ret == BP_NOT_CAP)
896 len = sprintf(page, "fail\n");
897 else if (ret == 0)
898 len = sprintf(page, "off\n");
899 else
900 len = sprintf(page, "on\n");
901
902 *eof = 1;
903 return len;
904 }
905
906 int
907 set_std_nic_pfs(struct file *file, const char *buffer,
908 unsigned long count, void *data)
909 {
910
911 char kbuf[256];
912 bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data;
913
914 int bypass_param = 0, length = 0;
915
916 if (copy_from_user(&kbuf, buffer, count)) {
917 return -1;
918 }
919
920 kbuf[count] = '\0';
921 length = strlen(kbuf);
922 if (kbuf[length - 1] == '\n')
923 kbuf[--length] = '\0';
924
925 if (strcmp(kbuf, "on") == 0)
926 bypass_param = 1;
927 else if (strcmp(kbuf, "off") == 0)
928 bypass_param = 0;
929
930 set_std_nic_fn(pbp_device_block, bypass_param);
931
932 return count;
933 }
934
935 int
936 get_std_nic_pfs(char *page, char **start, off_t off, int count,
937 int *eof, void *data)
938 {
939 bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data;
940
941 int len = 0, ret = 0;
942
943 ret = get_std_nic_fn(pbp_device_block);
944 if (ret == BP_NOT_CAP)
945 len = sprintf(page, "fail\n");
946 else if (ret == 0)
947 len = sprintf(page, "off\n");
948 else
949 len = sprintf(page, "on\n");
950
951 *eof = 1;
952 return len;
953 }
954
955 int
956 get_wd_exp_mode_pfs(char *page, char **start, off_t off, int count,
957 int *eof, void *data)
958 {
959 bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data;
960
961 int len = 0, ret = 0;
962
963 ret = get_wd_exp_mode_fn(pbp_device_block);
964 if (ret == 1)
965 len = sprintf(page, "tap\n");
966 else if (ret == 0)
967 len = sprintf(page, "bypass\n");
968 else if (ret == 2)
969 len = sprintf(page, "disc\n");
970
971 else
972 len = sprintf(page, "fail\n");
973
974 *eof = 1;
975 return len;
976 }
977
978 int
979 set_wd_exp_mode_pfs(struct file *file, const char *buffer,
980 unsigned long count, void *data)
981 {
982
983 char kbuf[256];
984 bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data;
985
986 int bypass_param = 0, length = 0;
987
988 if (count > (sizeof(kbuf) - 1))
989 return -1;
990
991 if (copy_from_user(&kbuf, buffer, count)) {
992 return -1;
993 }
994
995 kbuf[count] = '\0';
996 length = strlen(kbuf);
997 if (kbuf[length - 1] == '\n')
998 kbuf[--length] = '\0';
999
1000 if (strcmp(kbuf, "tap") == 0)
1001 bypass_param = 1;
1002 else if (strcmp(kbuf, "bypass") == 0)
1003 bypass_param = 0;
1004 else if (strcmp(kbuf, "disc") == 0)
1005 bypass_param = 2;
1006
1007 set_wd_exp_mode_fn(pbp_device_block, bypass_param);
1008
1009 return count;
1010 }
1011
1012 int
1013 get_wd_autoreset_pfs(char *page, char **start, off_t off, int count,
1014 int *eof, void *data)
1015 {
1016 bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data;
1017
1018 int len = 0, ret = 0;
1019
1020 ret = get_wd_autoreset_fn(pbp_device_block);
1021 if (ret >= 0)
1022 len = sprintf(page, "%d\n", ret);
1023 else
1024 len = sprintf(page, "fail\n");
1025
1026 *eof = 1;
1027 return len;
1028 }
1029
1030 int
1031 set_wd_autoreset_pfs(struct file *file, const char *buffer,
1032 unsigned long count, void *data)
1033 {
1034 char kbuf[256];
1035 bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data;
1036 u32 timeout = 0;
1037 char *timeout_ptr = kbuf;
1038
1039 if (copy_from_user(&kbuf, buffer, count)) {
1040 return -1;
1041 }
1042
1043 timeout_ptr = kbuf;
1044 timeout = atoi(&timeout_ptr);
1045
1046 set_wd_autoreset_fn(pbp_device_block, timeout);
1047
1048 return count;
1049 }
1050
1051 int
1052 set_tpl_pfs(struct file *file, const char *buffer,
1053 unsigned long count, void *data)
1054 {
1055
1056 char kbuf[256];
1057 bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data;
1058
1059 int tpl_param = 0, length = 0;
1060
1061 if (count > (sizeof(kbuf) - 1))
1062 return -1;
1063
1064 if (copy_from_user(&kbuf, buffer, count)) {
1065 return -1;
1066 }
1067
1068 kbuf[count] = '\0';
1069 length = strlen(kbuf);
1070 if (kbuf[length - 1] == '\n')
1071 kbuf[--length] = '\0';
1072
1073 if (strcmp(kbuf, "on") == 0)
1074 tpl_param = 1;
1075 else if (strcmp(kbuf, "off") == 0)
1076 tpl_param = 0;
1077
1078 set_tpl_fn(pbp_device_block, tpl_param);
1079
1080 return count;
1081 }
1082
1083 #ifdef PMC_FIX_FLAG
1084 int
1085 set_wait_at_pwup_pfs(struct file *file, const char *buffer,
1086 unsigned long count, void *data)
1087 {
1088
1089 char kbuf[256];
1090 bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data;
1091
1092 int tpl_param = 0, length = 0;
1093
1094 if (count > (sizeof(kbuf) - 1))
1095 return -1;
1096
1097 if (copy_from_user(&kbuf, buffer, count)) {
1098 return -1;
1099 }
1100
1101 kbuf[count] = '\0';
1102 length = strlen(kbuf);
1103 if (kbuf[length - 1] == '\n')
1104 kbuf[--length] = '\0';
1105
1106 if (strcmp(kbuf, "on") == 0)
1107 tpl_param = 1;
1108 else if (strcmp(kbuf, "off") == 0)
1109 tpl_param = 0;
1110
1111 set_bp_wait_at_pwup_fn(pbp_device_block, tpl_param);
1112
1113 return count;
1114 }
1115
1116 int
1117 set_hw_reset_pfs(struct file *file, const char *buffer,
1118 unsigned long count, void *data)
1119 {
1120
1121 char kbuf[256];
1122 bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data;
1123
1124 int tpl_param = 0, length = 0;
1125
1126 if (count > (sizeof(kbuf) - 1))
1127 return -1;
1128
1129 if (copy_from_user(&kbuf, buffer, count)) {
1130 return -1;
1131 }
1132
1133 kbuf[count] = '\0';
1134 length = strlen(kbuf);
1135 if (kbuf[length - 1] == '\n')
1136 kbuf[--length] = '\0';
1137
1138 if (strcmp(kbuf, "on") == 0)
1139 tpl_param = 1;
1140 else if (strcmp(kbuf, "off") == 0)
1141 tpl_param = 0;
1142
1143 set_bp_hw_reset_fn(pbp_device_block, tpl_param);
1144
1145 return count;
1146 }
1147
1148 #endif /*PMC_FIX_FLAG */
1149
1150 int bypass_proc_create_dev_sd(bpctl_dev_t * pbp_device_block)
1151 {
1152 struct bypass_pfs_sd *current_pfs = &(pbp_device_block->bypass_pfs_set);
1153 static struct proc_dir_entry *procfs_dir = NULL;
1154 int ret = 0;
1155
1156 sprintf(current_pfs->dir_name, "bypass_%s", dev->name);
1157
1158 if (!bp_procfs_dir)
1159 return -1;
1160
1161 /* create device proc dir */
1162 procfs_dir = proc_getdir(current_pfs->dir_name, bp_procfs_dir);
1163 if (procfs_dir == 0) {
1164 printk(KERN_DEBUG "Could not create procfs directory %s\n",
1165 current_pfs->dir_name);
1166 return -1;
1167 }
1168 current_pfs->bypass_entry = procfs_dir;
1169
1170 if (bypass_proc_create_entry(&(current_pfs->bypass_info), BYPASS_INFO_ENTRY_SD, NULL, /* write */
1171 get_bypass_info_pfs, /* read */
1172 procfs_dir, pbp_device_block))
1173 ret = -1;
1174
1175 if (pbp_device_block->bp_caps & SW_CTL_CAP) {
1176
1177 /* Create set param proc's */
1178 if (bypass_proc_create_entry_sd(&(current_pfs->bypass_slave), BYPASS_SLAVE_ENTRY_SD, NULL, /* write */
1179 get_bypass_slave_pfs, /* read */
1180 procfs_dir, pbp_device_block))
1181 ret = -1;
1182
1183 if (bypass_proc_create_entry_sd(&(current_pfs->bypass_caps), BYPASS_CAPS_ENTRY_SD, NULL, /* write */
1184 get_bypass_caps_pfs, /* read */
1185 procfs_dir, pbp_device_block))
1186 ret = -1;
1187
1188 if (bypass_proc_create_entry_sd(&(current_pfs->wd_set_caps), WD_SET_CAPS_ENTRY_SD, NULL, /* write */
1189 get_wd_set_caps_pfs, /* read */
1190 procfs_dir, pbp_device_block))
1191 ret = -1;
1192 if (bypass_proc_create_entry_sd(&(current_pfs->bypass_wd), BYPASS_WD_ENTRY_SD, set_bypass_wd_pfs, /* write */
1193 get_bypass_wd_pfs, /* read */
1194 procfs_dir, pbp_device_block))
1195 ret = -1;
1196
1197 if (bypass_proc_create_entry_sd(&(current_pfs->wd_expire_time), WD_EXPIRE_TIME_ENTRY_SD, NULL, /* write */
1198 get_wd_expire_time_pfs, /* read */
1199 procfs_dir, pbp_device_block))
1200 ret = -1;
1201
1202 if (bypass_proc_create_entry_sd(&(current_pfs->reset_bypass_wd), RESET_BYPASS_WD_ENTRY_SD, NULL, /* write */
1203 reset_bypass_wd_pfs, /* read */
1204 procfs_dir, pbp_device_block))
1205 ret = -1;
1206
1207 if (bypass_proc_create_entry_sd(&(current_pfs->std_nic), STD_NIC_ENTRY_SD, set_std_nic_pfs, /* write */
1208 get_std_nic_pfs, /* read */
1209 procfs_dir, pbp_device_block))
1210 ret = -1;
1211
1212 if (pbp_device_block->bp_caps & BP_CAP) {
1213 if (bypass_proc_create_entry_sd(&(current_pfs->bypass), BYPASS_ENTRY_SD, set_bypass_pfs, /* write */
1214 get_bypass_pfs, /* read */
1215 procfs_dir,
1216 pbp_device_block))
1217 ret = -1;
1218
1219 if (bypass_proc_create_entry_sd(&(current_pfs->dis_bypass), DIS_BYPASS_ENTRY_SD, set_dis_bypass_pfs, /* write */
1220 get_dis_bypass_pfs, /* read */
1221 procfs_dir,
1222 pbp_device_block))
1223 ret = -1;
1224
1225 if (bypass_proc_create_entry_sd(&(current_pfs->bypass_pwup), BYPASS_PWUP_ENTRY_SD, set_bypass_pwup_pfs, /* write */
1226 get_bypass_pwup_pfs, /* read */
1227 procfs_dir,
1228 pbp_device_block))
1229 ret = -1;
1230 if (bypass_proc_create_entry_sd(&(current_pfs->bypass_pwoff), BYPASS_PWOFF_ENTRY_SD, set_bypass_pwoff_pfs, /* write */
1231 get_bypass_pwoff_pfs, /* read */
1232 procfs_dir,
1233 pbp_device_block))
1234 ret = -1;
1235
1236 if (bypass_proc_create_entry_sd(&(current_pfs->bypass_change), BYPASS_CHANGE_ENTRY_SD, NULL, /* write */
1237 get_bypass_change_pfs, /* read */
1238 procfs_dir,
1239 pbp_device_block))
1240 ret = -1;
1241 }
1242
1243 if (pbp_device_block->bp_caps & TAP_CAP) {
1244
1245 if (bypass_proc_create_entry_sd(&(current_pfs->tap), TAP_ENTRY_SD, set_tap_pfs, /* write */
1246 get_tap_pfs, /* read */
1247 procfs_dir,
1248 pbp_device_block))
1249 ret = -1;
1250
1251 if (bypass_proc_create_entry_sd(&(current_pfs->dis_tap), DIS_TAP_ENTRY_SD, set_dis_tap_pfs, /* write */
1252 get_dis_tap_pfs, /* read */
1253 procfs_dir,
1254 pbp_device_block))
1255 ret = -1;
1256
1257 if (bypass_proc_create_entry_sd(&(current_pfs->tap_pwup), TAP_PWUP_ENTRY_SD, set_tap_pwup_pfs, /* write */
1258 get_tap_pwup_pfs, /* read */
1259 procfs_dir,
1260 pbp_device_block))
1261 ret = -1;
1262
1263 if (bypass_proc_create_entry_sd(&(current_pfs->tap_change), TAP_CHANGE_ENTRY_SD, NULL, /* write */
1264 get_tap_change_pfs, /* read */
1265 procfs_dir,
1266 pbp_device_block))
1267 ret = -1;
1268 }
1269 if (pbp_device_block->bp_caps & DISC_CAP) {
1270
1271 if (bypass_proc_create_entry_sd(&(current_pfs->tap), DISC_ENTRY_SD, set_disc_pfs, /* write */
1272 get_disc_pfs, /* read */
1273 procfs_dir,
1274 pbp_device_block))
1275 ret = -1;
1276 #if 1
1277
1278 if (bypass_proc_create_entry_sd(&(current_pfs->dis_tap), DIS_DISC_ENTRY_SD, set_dis_disc_pfs, /* write */
1279 get_dis_disc_pfs, /* read */
1280 procfs_dir,
1281 pbp_device_block))
1282 ret = -1;
1283 #endif
1284
1285 if (bypass_proc_create_entry_sd(&(current_pfs->tap_pwup), DISC_PWUP_ENTRY_SD, set_disc_pwup_pfs, /* write */
1286 get_disc_pwup_pfs, /* read */
1287 procfs_dir,
1288 pbp_device_block))
1289 ret = -1;
1290
1291 if (bypass_proc_create_entry_sd(&(current_pfs->tap_change), DISC_CHANGE_ENTRY_SD, NULL, /* write */
1292 get_disc_change_pfs, /* read */
1293 procfs_dir,
1294 pbp_device_block))
1295 ret = -1;
1296 }
1297
1298 if (bypass_proc_create_entry_sd(&(current_pfs->wd_exp_mode), WD_EXP_MODE_ENTRY_SD, set_wd_exp_mode_pfs, /* write */
1299 get_wd_exp_mode_pfs, /* read */
1300 procfs_dir, pbp_device_block))
1301 ret = -1;
1302
1303 if (bypass_proc_create_entry_sd(&(current_pfs->wd_autoreset), WD_AUTORESET_ENTRY_SD, set_wd_autoreset_pfs, /* write */
1304 get_wd_autoreset_pfs, /* read */
1305 procfs_dir, pbp_device_block))
1306 ret = -1;
1307 if (bypass_proc_create_entry_sd(&(current_pfs->tpl), TPL_ENTRY_SD, set_tpl_pfs, /* write */
1308 get_tpl_pfs, /* read */
1309 procfs_dir, pbp_device_block))
1310 ret = -1;
1311 #ifdef PMC_FIX_FLAG
1312 if (bypass_proc_create_entry_sd(&(current_pfs->tpl), WAIT_AT_PWUP_ENTRY_SD, set_wait_at_pwup_pfs, /* write */
1313 get_wait_at_pwup_pfs, /* read */
1314 procfs_dir, pbp_device_block))
1315 ret = -1;
1316 if (bypass_proc_create_entry_sd(&(current_pfs->tpl), HW_RESET_ENTRY_SD, set_hw_reset_pfs, /* write */
1317 get_hw_reset_pfs, /* read */
1318 procfs_dir, pbp_device_block))
1319 ret = -1;
1320
1321 #endif
1322
1323 }
1324 if (ret < 0)
1325 printk(KERN_DEBUG "Create proc entry failed\n");
1326
1327 return ret;
1328 }
1329
1330 int bypass_proc_remove_dev_sd(bpctl_dev_t * pbp_device_block)
1331 {
1332
1333 struct bypass_pfs_sd *current_pfs = &pbp_device_block->bypass_pfs_set;
1334 struct proc_dir_entry *pde = current_pfs->bypass_entry, *pde_curr =
1335 NULL;
1336 char name[256];
1337
1338 for (pde = pde->subdir; pde;) {
1339 strcpy(name, pde->name);
1340 pde_curr = pde;
1341 pde = pde->next;
1342 remove_proc_entry(name, current_pfs->bypass_entry);
1343 }
1344 if (!pde)
1345 remove_proc_entry(current_pfs->dir_name, bp_procfs_dir);
1346
1347 return 0;
1348 }
1349
1350 #endif /* BYPASS_SUPPORT */
This page took 0.060156 seconds and 6 git commands to generate.