2 * Thomas Horsten <thh@lasat.com>
3 * Copyright (C) 2000 LASAT Networks A/S.
5 * This program is free software; you can distribute it and/or modify it
6 * under the terms of the GNU General Public License (Version 2) as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
18 * Routines specific to the LASAT boards
20 #include <linux/types.h>
21 #include <asm/lasat/lasat.h>
23 #include <linux/module.h>
24 #include <linux/sysctl.h>
25 #include <linux/stddef.h>
26 #include <linux/init.h>
28 #include <linux/ctype.h>
29 #include <linux/string.h>
30 #include <linux/net.h>
31 #include <linux/inet.h>
32 #include <linux/mutex.h>
33 #include <asm/uaccess.h>
38 static DEFINE_MUTEX(lasat_info_mutex
);
40 /* Strategy function to write EEPROM after changing string entry */
41 int sysctl_lasatstring(ctl_table
*table
, int *name
, int nlen
,
42 void *oldval
, size_t *oldlenp
,
43 void *newval
, size_t newlen
)
46 mutex_lock(&lasat_info_mutex
);
47 r
= sysctl_string(table
, name
,
48 nlen
, oldval
, oldlenp
, newval
, newlen
);
50 mutex_unlock(&lasat_info_mutex
);
53 if (newval
&& newlen
) {
54 lasat_write_eeprom_info();
56 mutex_unlock(&lasat_info_mutex
);
61 /* And the same for proc */
62 int proc_dolasatstring(ctl_table
*table
, int write
, struct file
*filp
,
63 void *buffer
, size_t *lenp
, loff_t
*ppos
)
66 mutex_lock(&lasat_info_mutex
);
67 r
= proc_dostring(table
, write
, filp
, buffer
, lenp
, ppos
);
69 mutex_unlock(&lasat_info_mutex
);
72 lasat_write_eeprom_info();
73 mutex_unlock(&lasat_info_mutex
);
77 /* proc function to write EEPROM after changing int entry */
78 int proc_dolasatint(ctl_table
*table
, int write
, struct file
*filp
,
79 void *buffer
, size_t *lenp
, loff_t
*ppos
)
82 mutex_lock(&lasat_info_mutex
);
83 r
= proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
);
85 mutex_unlock(&lasat_info_mutex
);
88 lasat_write_eeprom_info();
89 mutex_unlock(&lasat_info_mutex
);
96 /* proc function to read/write RealTime Clock */
97 int proc_dolasatrtc(ctl_table
*table
, int write
, struct file
*filp
,
98 void *buffer
, size_t *lenp
, loff_t
*ppos
)
101 mutex_lock(&lasat_info_mutex
);
103 rtctmp
= ds1603_read();
104 /* check for time < 0 and set to 0 */
108 r
= proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
);
109 if ( (!write
) || r
) {
110 mutex_unlock(&lasat_info_mutex
);
114 mutex_unlock(&lasat_info_mutex
);
119 /* Sysctl for setting the IP addresses */
120 int sysctl_lasat_intvec(ctl_table
*table
, int *name
, int nlen
,
121 void *oldval
, size_t *oldlenp
,
122 void *newval
, size_t newlen
)
125 mutex_lock(&lasat_info_mutex
);
126 r
= sysctl_intvec(table
, name
, nlen
, oldval
, oldlenp
, newval
, newlen
);
128 mutex_unlock(&lasat_info_mutex
);
131 if (newval
&& newlen
) {
132 lasat_write_eeprom_info();
134 mutex_unlock(&lasat_info_mutex
);
140 int sysctl_lasat_rtc(ctl_table
*table
, int *name
, int nlen
,
141 void *oldval
, size_t *oldlenp
,
142 void *newval
, size_t newlen
)
145 mutex_lock(&lasat_info_mutex
);
146 rtctmp
= ds1603_read();
149 r
= sysctl_intvec(table
, name
, nlen
, oldval
, oldlenp
, newval
, newlen
);
151 mutex_unlock(&lasat_info_mutex
);
154 if (newval
&& newlen
) {
157 mutex_unlock(&lasat_info_mutex
);
163 static char lasat_bcastaddr
[16];
165 void update_bcastaddr(void)
169 ip
= (lasat_board_info
.li_eeprom_info
.ipaddr
&
170 lasat_board_info
.li_eeprom_info
.netmask
) |
171 ~lasat_board_info
.li_eeprom_info
.netmask
;
173 sprintf(lasat_bcastaddr
, "%d.%d.%d.%d",
180 static char proc_lasat_ipbuf
[32];
181 /* Parsing of IP address */
182 int proc_lasat_ip(ctl_table
*table
, int write
, struct file
*filp
,
183 void *buffer
, size_t *lenp
, loff_t
*ppos
)
189 if (!table
->data
|| !table
->maxlen
|| !*lenp
||
195 mutex_lock(&lasat_info_mutex
);
199 while (len
< *lenp
) {
200 if(get_user(c
, p
++)) {
201 mutex_unlock(&lasat_info_mutex
);
204 if (c
== 0 || c
== '\n')
208 if (len
>= sizeof(proc_lasat_ipbuf
)-1)
209 len
= sizeof(proc_lasat_ipbuf
) - 1;
210 if (copy_from_user(proc_lasat_ipbuf
, buffer
, len
))
212 mutex_unlock(&lasat_info_mutex
);
215 proc_lasat_ipbuf
[len
] = 0;
217 /* Now see if we can convert it to a valid IP */
218 ip
= in_aton(proc_lasat_ipbuf
);
219 *(unsigned int *)(table
->data
) = ip
;
220 lasat_write_eeprom_info();
222 ip
= *(unsigned int *)(table
->data
);
223 sprintf(proc_lasat_ipbuf
, "%d.%d.%d.%d",
228 len
= strlen(proc_lasat_ipbuf
);
232 if(copy_to_user(buffer
, proc_lasat_ipbuf
, len
)) {
233 mutex_unlock(&lasat_info_mutex
);
237 if(put_user('\n', ((char *) buffer
) + len
)) {
238 mutex_unlock(&lasat_info_mutex
);
247 mutex_unlock(&lasat_info_mutex
);
250 #endif /* defined(CONFIG_INET) */
252 static int sysctl_lasat_eeprom_value(ctl_table
*table
, int *name
, int nlen
,
253 void *oldval
, size_t *oldlenp
,
254 void *newval
, size_t newlen
)
258 mutex_lock(&lasat_info_mutex
);
259 r
= sysctl_intvec(table
, name
, nlen
, oldval
, oldlenp
, newval
, newlen
);
261 mutex_unlock(&lasat_info_mutex
);
265 if (newval
&& newlen
)
267 if (name
&& *name
== LASAT_PRID
)
268 lasat_board_info
.li_eeprom_info
.prid
= *(int*)newval
;
270 lasat_write_eeprom_info();
271 lasat_init_board_info();
273 mutex_unlock(&lasat_info_mutex
);
278 int proc_lasat_eeprom_value(ctl_table
*table
, int write
, struct file
*filp
,
279 void *buffer
, size_t *lenp
, loff_t
*ppos
)
282 mutex_lock(&lasat_info_mutex
);
283 r
= proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
);
284 if ( (!write
) || r
) {
285 mutex_unlock(&lasat_info_mutex
);
288 if (filp
&& filp
->f_path
.dentry
)
290 if (!strcmp(filp
->f_path
.dentry
->d_name
.name
, "prid"))
291 lasat_board_info
.li_eeprom_info
.prid
= lasat_board_info
.li_prid
;
292 if (!strcmp(filp
->f_path
.dentry
->d_name
.name
, "debugaccess"))
293 lasat_board_info
.li_eeprom_info
.debugaccess
= lasat_board_info
.li_debugaccess
;
295 lasat_write_eeprom_info();
296 mutex_unlock(&lasat_info_mutex
);
300 extern int lasat_boot_to_service
;
304 static ctl_table lasat_table
[] = {
306 .ctl_name
= CTL_UNNUMBERED
,
307 .procname
= "cpu-hz",
308 .data
= &lasat_board_info
.li_cpu_hz
,
309 .maxlen
= sizeof(int),
311 .proc_handler
= &proc_dointvec
,
312 .strategy
= &sysctl_intvec
315 .ctl_name
= CTL_UNNUMBERED
,
316 .procname
= "bus-hz",
317 .data
= &lasat_board_info
.li_bus_hz
,
318 .maxlen
= sizeof(int),
320 .proc_handler
= &proc_dointvec
,
321 .strategy
= &sysctl_intvec
324 .ctl_name
= CTL_UNNUMBERED
,
326 .data
= &lasat_board_info
.li_bmid
,
327 .maxlen
= sizeof(int),
329 .proc_handler
= &proc_dointvec
,
330 .strategy
= &sysctl_intvec
333 .ctl_name
= CTL_UNNUMBERED
,
335 .data
= &lasat_board_info
.li_prid
,
336 .maxlen
= sizeof(int),
338 .proc_handler
= &proc_lasat_eeprom_value
,
339 .strategy
= &sysctl_lasat_eeprom_value
343 .ctl_name
= CTL_UNNUMBERED
,
344 .procname
= "ipaddr",
345 .data
= &lasat_board_info
.li_eeprom_info
.ipaddr
,
346 .maxlen
= sizeof(int),
348 .proc_handler
= &proc_lasat_ip
,
349 .strategy
= &sysctl_lasat_intvec
352 .ctl_name
= LASAT_NETMASK
,
353 .procname
= "netmask",
354 .data
= &lasat_board_info
.li_eeprom_info
.netmask
,
355 .maxlen
= sizeof(int),
357 .proc_handler
= &proc_lasat_ip
,
358 .strategy
= &sysctl_lasat_intvec
361 .ctl_name
= CTL_UNNUMBERED
,
362 .procname
= "bcastaddr",
363 .data
= &lasat_bcastaddr
,
364 .maxlen
= sizeof(lasat_bcastaddr
),
366 .proc_handler
= &proc_dostring
,
367 .strategy
= &sysctl_string
371 .ctl_name
= CTL_UNNUMBERED
,
372 .procname
= "passwd_hash",
373 .data
= &lasat_board_info
.li_eeprom_info
.passwd_hash
,
374 .maxlen
= sizeof(lasat_board_info
.li_eeprom_info
.passwd_hash
),
376 .proc_handler
= &proc_dolasatstring
,
377 .strategy
= &sysctl_lasatstring
380 .ctl_name
= CTL_UNNUMBERED
,
381 .procname
= "boot-service",
382 .data
= &lasat_boot_to_service
,
383 .maxlen
= sizeof(int),
385 .proc_handler
= &proc_dointvec
,
386 .strategy
= &sysctl_intvec
390 .ctl_name
= CTL_UNNUMBERED
,
393 .maxlen
= sizeof(int),
395 .proc_handler
= &proc_dolasatrtc
,
396 .strategy
= &sysctl_lasat_rtc
400 .ctl_name
= CTL_UNNUMBERED
,
401 .procname
= "namestr",
402 .data
= &lasat_board_info
.li_namestr
,
403 .maxlen
= sizeof(lasat_board_info
.li_namestr
),
405 .proc_handler
= &proc_dostring
,
406 .strategy
= &sysctl_string
409 .ctl_name
= CTL_UNNUMBERED
,
410 .procname
= "typestr",
411 .data
= &lasat_board_info
.li_typestr
,
412 .maxlen
= sizeof(lasat_board_info
.li_typestr
),
414 .proc_handler
= &proc_dostring
,
415 .strategy
= &sysctl_string
420 static ctl_table lasat_root_table
[] = {
422 .ctl_name
= CTL_UNNUMBERED
,
430 static int __init
lasat_register_sysctl(void)
432 struct ctl_table_header
*lasat_table_header
;
435 register_sysctl_table(lasat_root_table
);
440 __initcall(lasat_register_sysctl
);
441 #endif /* CONFIG_SYSCTL */