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