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 <linux/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)
47 mutex_lock(&lasat_info_mutex);
48 r = sysctl_string(table, name,
49 nlen, oldval, oldlenp, newval, newlen);
51 mutex_unlock(&lasat_info_mutex);
55 lasat_write_eeprom_info();
56 mutex_unlock(&lasat_info_mutex);
62 /* And the same for proc */
63 int proc_dolasatstring(ctl_table *table, int write, struct file *filp,
64 void *buffer, size_t *lenp, loff_t *ppos)
68 mutex_lock(&lasat_info_mutex);
69 r = proc_dostring(table, write, filp, buffer, lenp, ppos);
71 mutex_unlock(&lasat_info_mutex);
74 lasat_write_eeprom_info();
75 mutex_unlock(&lasat_info_mutex);
80 /* proc function to write EEPROM after changing int entry */
81 int proc_dolasatint(ctl_table *table, int write, struct file *filp,
82 void *buffer, size_t *lenp, loff_t *ppos)
86 mutex_lock(&lasat_info_mutex);
87 r = proc_dointvec(table, write, filp, buffer, lenp, ppos);
89 mutex_unlock(&lasat_info_mutex);
92 lasat_write_eeprom_info();
93 mutex_unlock(&lasat_info_mutex);
101 /* proc function to read/write RealTime Clock */
102 int proc_dolasatrtc(ctl_table *table, int write, struct file *filp,
103 void *buffer, size_t *lenp, loff_t *ppos)
107 mutex_lock(&lasat_info_mutex);
109 rtctmp = ds1603_read();
110 /* check for time < 0 and set to 0 */
114 r = proc_dointvec(table, write, filp, buffer, lenp, ppos);
116 mutex_unlock(&lasat_info_mutex);
120 mutex_unlock(&lasat_info_mutex);
126 /* Sysctl for setting the IP addresses */
127 int sysctl_lasat_intvec(ctl_table *table, int *name, int nlen,
128 void *oldval, size_t *oldlenp,
129 void *newval, size_t newlen)
133 mutex_lock(&lasat_info_mutex);
134 r = sysctl_intvec(table, name, nlen, oldval, oldlenp, newval, newlen);
136 mutex_unlock(&lasat_info_mutex);
139 if (newval && newlen)
140 lasat_write_eeprom_info();
141 mutex_unlock(&lasat_info_mutex);
148 int sysctl_lasat_rtc(ctl_table *table, int *name, int nlen,
149 void *oldval, size_t *oldlenp,
150 void *newval, size_t newlen)
154 mutex_lock(&lasat_info_mutex);
155 rtctmp = ds1603_read();
158 r = sysctl_intvec(table, name, nlen, oldval, oldlenp, newval, newlen);
160 mutex_unlock(&lasat_info_mutex);
163 if (newval && newlen)
165 mutex_unlock(&lasat_info_mutex);
172 static char lasat_bcastaddr[16];
174 void update_bcastaddr(void)
178 ip = (lasat_board_info.li_eeprom_info.ipaddr &
179 lasat_board_info.li_eeprom_info.netmask) |
180 ~lasat_board_info.li_eeprom_info.netmask;
182 sprintf(lasat_bcastaddr, "%d.%d.%d.%d",
189 static char proc_lasat_ipbuf[32];
191 /* Parsing of IP address */
192 int proc_lasat_ip(ctl_table *table, int write, struct file *filp,
193 void *buffer, size_t *lenp, loff_t *ppos)
199 if (!table->data || !table->maxlen || !*lenp ||
205 mutex_lock(&lasat_info_mutex);
209 while (len < *lenp) {
210 if (get_user(c, p++)) {
211 mutex_unlock(&lasat_info_mutex);
214 if (c == 0 || c == '\n')
218 if (len >= sizeof(proc_lasat_ipbuf)-1)
219 len = sizeof(proc_lasat_ipbuf) - 1;
220 if (copy_from_user(proc_lasat_ipbuf, buffer, len)) {
221 mutex_unlock(&lasat_info_mutex);
224 proc_lasat_ipbuf[len] = 0;
226 /* Now see if we can convert it to a valid IP */
227 ip = in_aton(proc_lasat_ipbuf);
228 *(unsigned int *)(table->data) = ip;
229 lasat_write_eeprom_info();
231 ip = *(unsigned int *)(table->data);
232 sprintf(proc_lasat_ipbuf, "%d.%d.%d.%d",
237 len = strlen(proc_lasat_ipbuf);
241 if (copy_to_user(buffer, proc_lasat_ipbuf, len)) {
242 mutex_unlock(&lasat_info_mutex);
246 if (put_user('\n', ((char *) buffer) + len)) {
247 mutex_unlock(&lasat_info_mutex);
256 mutex_unlock(&lasat_info_mutex);
260 #endif /* defined(CONFIG_INET) */
262 static int sysctl_lasat_eeprom_value(ctl_table *table, int *name, int nlen,
263 void *oldval, size_t *oldlenp,
264 void *newval, size_t newlen)
268 mutex_lock(&lasat_info_mutex);
269 r = sysctl_intvec(table, name, nlen, oldval, oldlenp, newval, newlen);
271 mutex_unlock(&lasat_info_mutex);
275 if (newval && newlen) {
276 if (name && *name == LASAT_PRID)
277 lasat_board_info.li_eeprom_info.prid = *(int *)newval;
279 lasat_write_eeprom_info();
280 lasat_init_board_info();
282 mutex_unlock(&lasat_info_mutex);
287 int proc_lasat_eeprom_value(ctl_table *table, int write, struct file *filp,
288 void *buffer, size_t *lenp, loff_t *ppos)
292 mutex_lock(&lasat_info_mutex);
293 r = proc_dointvec(table, write, filp, buffer, lenp, ppos);
295 mutex_unlock(&lasat_info_mutex);
298 if (filp && filp->f_path.dentry) {
299 if (!strcmp(filp->f_path.dentry->d_name.name, "prid"))
300 lasat_board_info.li_eeprom_info.prid =
301 lasat_board_info.li_prid;
302 if (!strcmp(filp->f_path.dentry->d_name.name, "debugaccess"))
303 lasat_board_info.li_eeprom_info.debugaccess =
304 lasat_board_info.li_debugaccess;
306 lasat_write_eeprom_info();
307 mutex_unlock(&lasat_info_mutex);
312 extern int lasat_boot_to_service;
316 static ctl_table lasat_table[] = {
318 .ctl_name = CTL_UNNUMBERED,
319 .procname = "cpu-hz",
320 .data = &lasat_board_info.li_cpu_hz,
321 .maxlen = sizeof(int),
323 .proc_handler = &proc_dointvec,
324 .strategy = &sysctl_intvec
327 .ctl_name = CTL_UNNUMBERED,
328 .procname = "bus-hz",
329 .data = &lasat_board_info.li_bus_hz,
330 .maxlen = sizeof(int),
332 .proc_handler = &proc_dointvec,
333 .strategy = &sysctl_intvec
336 .ctl_name = CTL_UNNUMBERED,
338 .data = &lasat_board_info.li_bmid,
339 .maxlen = sizeof(int),
341 .proc_handler = &proc_dointvec,
342 .strategy = &sysctl_intvec
345 .ctl_name = CTL_UNNUMBERED,
347 .data = &lasat_board_info.li_prid,
348 .maxlen = sizeof(int),
350 .proc_handler = &proc_lasat_eeprom_value,
351 .strategy = &sysctl_lasat_eeprom_value
355 .ctl_name = CTL_UNNUMBERED,
356 .procname = "ipaddr",
357 .data = &lasat_board_info.li_eeprom_info.ipaddr,
358 .maxlen = sizeof(int),
360 .proc_handler = &proc_lasat_ip,
361 .strategy = &sysctl_lasat_intvec
364 .ctl_name = LASAT_NETMASK,
365 .procname = "netmask",
366 .data = &lasat_board_info.li_eeprom_info.netmask,
367 .maxlen = sizeof(int),
369 .proc_handler = &proc_lasat_ip,
370 .strategy = &sysctl_lasat_intvec
373 .ctl_name = CTL_UNNUMBERED,
374 .procname = "bcastaddr",
375 .data = &lasat_bcastaddr,
376 .maxlen = sizeof(lasat_bcastaddr),
378 .proc_handler = &proc_dostring,
379 .strategy = &sysctl_string
383 .ctl_name = CTL_UNNUMBERED,
384 .procname = "passwd_hash",
385 .data = &lasat_board_info.li_eeprom_info.passwd_hash,
387 sizeof(lasat_board_info.li_eeprom_info.passwd_hash),
389 .proc_handler = &proc_dolasatstring,
390 .strategy = &sysctl_lasatstring
393 .ctl_name = CTL_UNNUMBERED,
394 .procname = "boot-service",
395 .data = &lasat_boot_to_service,
396 .maxlen = sizeof(int),
398 .proc_handler = &proc_dointvec,
399 .strategy = &sysctl_intvec
403 .ctl_name = CTL_UNNUMBERED,
406 .maxlen = sizeof(int),
408 .proc_handler = &proc_dolasatrtc,
409 .strategy = &sysctl_lasat_rtc
413 .ctl_name = CTL_UNNUMBERED,
414 .procname = "namestr",
415 .data = &lasat_board_info.li_namestr,
416 .maxlen = sizeof(lasat_board_info.li_namestr),
418 .proc_handler = &proc_dostring,
419 .strategy = &sysctl_string
422 .ctl_name = CTL_UNNUMBERED,
423 .procname = "typestr",
424 .data = &lasat_board_info.li_typestr,
425 .maxlen = sizeof(lasat_board_info.li_typestr),
427 .proc_handler = &proc_dostring,
428 .strategy = &sysctl_string
433 static ctl_table lasat_root_table[] = {
435 .ctl_name = CTL_UNNUMBERED,
443 static int __init lasat_register_sysctl(void)
445 struct ctl_table_header *lasat_table_header;
448 register_sysctl_table(lasat_root_table);
453 __initcall(lasat_register_sysctl);
454 #endif /* CONFIG_SYSCTL */