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