Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
[linux-drm-fsl-dcu.git] / net / irda / irsysctl.c
1 /*********************************************************************
2  *
3  * Filename:      irsysctl.c
4  * Version:       1.0
5  * Description:   Sysctl interface for IrDA
6  * Status:        Experimental.
7  * Author:        Dag Brattli <dagb@cs.uit.no>
8  * Created at:    Sun May 24 22:12:06 1998
9  * Modified at:   Fri Jun  4 02:50:15 1999
10  * Modified by:   Dag Brattli <dagb@cs.uit.no>
11  *
12  *     Copyright (c) 1997, 1999 Dag Brattli, All Rights Reserved.
13  *     Copyright (c) 2000-2001 Jean Tourrilhes <jt@hpl.hp.com>
14  *
15  *     This program is free software; you can redistribute it and/or
16  *     modify it under the terms of the GNU General Public License as
17  *     published by the Free Software Foundation; either version 2 of
18  *     the License, or (at your option) any later version.
19  *
20  *     Neither Dag Brattli nor University of Tromsø admit liability nor
21  *     provide warranty for any of this software. This material is
22  *     provided "AS-IS" and at no charge.
23  *
24  ********************************************************************/
25
26 #include <linux/mm.h>
27 #include <linux/ctype.h>
28 #include <linux/sysctl.h>
29 #include <linux/init.h>
30
31 #include <net/irda/irda.h>              /* irda_debug */
32 #include <net/irda/irias_object.h>
33
34 #define NET_IRDA 412 /* Random number */
35 enum { DISCOVERY=1, DEVNAME, DEBUG, FAST_POLL, DISCOVERY_SLOTS,
36        DISCOVERY_TIMEOUT, SLOT_TIMEOUT, MAX_BAUD_RATE, MIN_TX_TURN_TIME,
37        MAX_TX_DATA_SIZE, MAX_TX_WINDOW, MAX_NOREPLY_TIME, WARN_NOREPLY_TIME,
38        LAP_KEEPALIVE_TIME };
39
40 extern int  sysctl_discovery;
41 extern int  sysctl_discovery_slots;
42 extern int  sysctl_discovery_timeout;
43 extern int  sysctl_slot_timeout;
44 extern int  sysctl_fast_poll_increase;
45 extern char sysctl_devname[];
46 extern int  sysctl_max_baud_rate;
47 extern int  sysctl_min_tx_turn_time;
48 extern int  sysctl_max_tx_data_size;
49 extern int  sysctl_max_tx_window;
50 extern int  sysctl_max_noreply_time;
51 extern int  sysctl_warn_noreply_time;
52 extern int  sysctl_lap_keepalive_time;
53
54 /* this is needed for the proc_dointvec_minmax - Jean II */
55 static int max_discovery_slots = 16;            /* ??? */
56 static int min_discovery_slots = 1;
57 /* IrLAP 6.13.2 says 25ms to 10+70ms - allow higher since some devices
58  * seems to require it. (from Dag's comment) */
59 static int max_slot_timeout = 160;
60 static int min_slot_timeout = 20;
61 static int max_max_baud_rate = 16000000;        /* See qos.c - IrLAP spec */
62 static int min_max_baud_rate = 2400;
63 static int max_min_tx_turn_time = 10000;        /* See qos.c - IrLAP spec */
64 static int min_min_tx_turn_time;
65 static int max_max_tx_data_size = 2048;         /* See qos.c - IrLAP spec */
66 static int min_max_tx_data_size = 64;
67 static int max_max_tx_window = 7;               /* See qos.c - IrLAP spec */
68 static int min_max_tx_window = 1;
69 static int max_max_noreply_time = 40;           /* See qos.c - IrLAP spec */
70 static int min_max_noreply_time = 3;
71 static int max_warn_noreply_time = 3;           /* 3s == standard */
72 static int min_warn_noreply_time = 1;           /* 1s == min WD_TIMER */
73 static int max_lap_keepalive_time = 10000;      /* 10s */
74 static int min_lap_keepalive_time = 100;        /* 100us */
75 /* For other sysctl, I've no idea of the range. Maybe Dag could help
76  * us on that - Jean II */
77
78 static int do_devname(ctl_table *table, int write, struct file *filp,
79                       void __user *buffer, size_t *lenp, loff_t *ppos)
80 {
81         int ret;
82
83         ret = proc_dostring(table, write, filp, buffer, lenp, ppos);
84         if (ret == 0 && write) {
85                 struct ias_value *val;
86
87                 val = irias_new_string_value(sysctl_devname);
88                 if (val)
89                         irias_object_change_attribute("Device", "DeviceName", val);
90         }
91         return ret;
92 }
93
94 /* One file */
95 static ctl_table irda_table[] = {
96         {
97                 .ctl_name       = DISCOVERY,
98                 .procname       = "discovery",
99                 .data           = &sysctl_discovery,
100                 .maxlen         = sizeof(int),
101                 .mode           = 0644,
102                 .proc_handler   = &proc_dointvec
103         },
104         {
105                 .ctl_name       = DEVNAME,
106                 .procname       = "devname",
107                 .data           = sysctl_devname,
108                 .maxlen         = 65,
109                 .mode           = 0644,
110                 .proc_handler   = &do_devname,
111                 .strategy       = &sysctl_string
112         },
113 #ifdef CONFIG_IRDA_DEBUG
114         {
115                 .ctl_name       = DEBUG,
116                 .procname       = "debug",
117                 .data           = &irda_debug,
118                 .maxlen         = sizeof(int),
119                 .mode           = 0644,
120                 .proc_handler   = &proc_dointvec
121         },
122 #endif
123 #ifdef CONFIG_IRDA_FAST_RR
124         {
125                 .ctl_name       = FAST_POLL,
126                 .procname       = "fast_poll_increase",
127                 .data           = &sysctl_fast_poll_increase,
128                 .maxlen         = sizeof(int),
129                 .mode           = 0644,
130                 .proc_handler   = &proc_dointvec
131         },
132 #endif
133         {
134                 .ctl_name       = DISCOVERY_SLOTS,
135                 .procname       = "discovery_slots",
136                 .data           = &sysctl_discovery_slots,
137                 .maxlen         = sizeof(int),
138                 .mode           = 0644,
139                 .proc_handler   = &proc_dointvec_minmax,
140                 .strategy       = &sysctl_intvec,
141                 .extra1         = &min_discovery_slots,
142                 .extra2         = &max_discovery_slots
143         },
144         {
145                 .ctl_name       = DISCOVERY_TIMEOUT,
146                 .procname       = "discovery_timeout",
147                 .data           = &sysctl_discovery_timeout,
148                 .maxlen         = sizeof(int),
149                 .mode           = 0644,
150                 .proc_handler   = &proc_dointvec
151         },
152         {
153                 .ctl_name       = SLOT_TIMEOUT,
154                 .procname       = "slot_timeout",
155                 .data           = &sysctl_slot_timeout,
156                 .maxlen         = sizeof(int),
157                 .mode           = 0644,
158                 .proc_handler   = &proc_dointvec_minmax,
159                 .strategy       = &sysctl_intvec,
160                 .extra1         = &min_slot_timeout,
161                 .extra2         = &max_slot_timeout
162         },
163         {
164                 .ctl_name       = MAX_BAUD_RATE,
165                 .procname       = "max_baud_rate",
166                 .data           = &sysctl_max_baud_rate,
167                 .maxlen         = sizeof(int),
168                 .mode           = 0644,
169                 .proc_handler   = &proc_dointvec_minmax,
170                 .strategy       = &sysctl_intvec,
171                 .extra1         = &min_max_baud_rate,
172                 .extra2         = &max_max_baud_rate
173         },
174         {
175                 .ctl_name       = MIN_TX_TURN_TIME,
176                 .procname       = "min_tx_turn_time",
177                 .data           = &sysctl_min_tx_turn_time,
178                 .maxlen         = sizeof(int),
179                 .mode           = 0644,
180                 .proc_handler   = &proc_dointvec_minmax,
181                 .strategy       = &sysctl_intvec,
182                 .extra1         = &min_min_tx_turn_time,
183                 .extra2         = &max_min_tx_turn_time
184         },
185         {
186                 .ctl_name       = MAX_TX_DATA_SIZE,
187                 .procname       = "max_tx_data_size",
188                 .data           = &sysctl_max_tx_data_size,
189                 .maxlen         = sizeof(int),
190                 .mode           = 0644,
191                 .proc_handler   = &proc_dointvec_minmax,
192                 .strategy       = &sysctl_intvec,
193                 .extra1         = &min_max_tx_data_size,
194                 .extra2         = &max_max_tx_data_size
195         },
196         {
197                 .ctl_name       = MAX_TX_WINDOW,
198                 .procname       = "max_tx_window",
199                 .data           = &sysctl_max_tx_window,
200                 .maxlen         = sizeof(int),
201                 .mode           = 0644,
202                 .proc_handler   = &proc_dointvec_minmax,
203                 .strategy       = &sysctl_intvec,
204                 .extra1         = &min_max_tx_window,
205                 .extra2         = &max_max_tx_window
206         },
207         {
208                 .ctl_name       = MAX_NOREPLY_TIME,
209                 .procname       = "max_noreply_time",
210                 .data           = &sysctl_max_noreply_time,
211                 .maxlen         = sizeof(int),
212                 .mode           = 0644,
213                 .proc_handler   = &proc_dointvec_minmax,
214                 .strategy       = &sysctl_intvec,
215                 .extra1         = &min_max_noreply_time,
216                 .extra2         = &max_max_noreply_time
217         },
218         {
219                 .ctl_name       = WARN_NOREPLY_TIME,
220                 .procname       = "warn_noreply_time",
221                 .data           = &sysctl_warn_noreply_time,
222                 .maxlen         = sizeof(int),
223                 .mode           = 0644,
224                 .proc_handler   = &proc_dointvec_minmax,
225                 .strategy       = &sysctl_intvec,
226                 .extra1         = &min_warn_noreply_time,
227                 .extra2         = &max_warn_noreply_time
228         },
229         {
230                 .ctl_name       = LAP_KEEPALIVE_TIME,
231                 .procname       = "lap_keepalive_time",
232                 .data           = &sysctl_lap_keepalive_time,
233                 .maxlen         = sizeof(int),
234                 .mode           = 0644,
235                 .proc_handler   = &proc_dointvec_minmax,
236                 .strategy       = &sysctl_intvec,
237                 .extra1         = &min_lap_keepalive_time,
238                 .extra2         = &max_lap_keepalive_time
239         },
240         { .ctl_name = 0 }
241 };
242
243 /* One directory */
244 static ctl_table irda_net_table[] = {
245         {
246                 .ctl_name       = NET_IRDA,
247                 .procname       = "irda",
248                 .maxlen         = 0,
249                 .mode           = 0555,
250                 .child          = irda_table
251         },
252         { .ctl_name = 0 }
253 };
254
255 /* The parent directory */
256 static ctl_table irda_root_table[] = {
257         {
258                 .ctl_name       = CTL_NET,
259                 .procname       = "net",
260                 .maxlen         = 0,
261                 .mode           = 0555,
262                 .child          = irda_net_table
263         },
264         { .ctl_name = 0 }
265 };
266
267 static struct ctl_table_header *irda_table_header;
268
269 /*
270  * Function irda_sysctl_register (void)
271  *
272  *    Register our sysctl interface
273  *
274  */
275 int __init irda_sysctl_register(void)
276 {
277         irda_table_header = register_sysctl_table(irda_root_table, 0);
278         if (!irda_table_header)
279                 return -ENOMEM;
280
281         return 0;
282 }
283
284 /*
285  * Function irda_sysctl_unregister (void)
286  *
287  *    Unregister our sysctl interface
288  *
289  */
290 void __exit irda_sysctl_unregister(void)
291 {
292         unregister_sysctl_table(irda_table_header);
293 }
294
295
296