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>
40 static DEFINE_MUTEX(lasat_info_mutex);
42 /* Strategy function to write EEPROM after changing string entry */
43 int sysctl_lasatstring(ctl_table *table, int *name, int nlen,
44 void *oldval, size_t *oldlenp,
45 void *newval, size_t newlen)
49 mutex_lock(&lasat_info_mutex);
50 r = sysctl_string(table, name,
51 nlen, oldval, oldlenp, newval, newlen);
53 mutex_unlock(&lasat_info_mutex);
57 lasat_write_eeprom_info();
58 mutex_unlock(&lasat_info_mutex);
64 /* And the same for proc */
65 int proc_dolasatstring(ctl_table *table, int write, struct file *filp,
66 void *buffer, size_t *lenp, loff_t *ppos)
70 mutex_lock(&lasat_info_mutex);
71 r = proc_dostring(table, write, filp, buffer, lenp, ppos);
73 mutex_unlock(&lasat_info_mutex);
76 lasat_write_eeprom_info();
77 mutex_unlock(&lasat_info_mutex);
82 /* proc function to write EEPROM after changing int entry */
83 int proc_dolasatint(ctl_table *table, int write, struct file *filp,
84 void *buffer, size_t *lenp, loff_t *ppos)
88 mutex_lock(&lasat_info_mutex);
89 r = proc_dointvec(table, write, filp, buffer, lenp, ppos);
91 mutex_unlock(&lasat_info_mutex);
94 lasat_write_eeprom_info();
95 mutex_unlock(&lasat_info_mutex);
103 /* proc function to read/write RealTime Clock */
104 int proc_dolasatrtc(ctl_table *table, int write, struct file *filp,
105 void *buffer, size_t *lenp, loff_t *ppos)
109 mutex_lock(&lasat_info_mutex);
111 rtctmp = read_persistent_clock();
112 /* check for time < 0 and set to 0 */
116 r = proc_dointvec(table, write, filp, buffer, lenp, ppos);
118 mutex_unlock(&lasat_info_mutex);
121 rtc_mips_set_mmss(rtctmp);
122 mutex_unlock(&lasat_info_mutex);
128 /* Sysctl for setting the IP addresses */
129 int sysctl_lasat_intvec(ctl_table *table, int *name, int nlen,
130 void *oldval, size_t *oldlenp,
131 void *newval, size_t newlen)
135 mutex_lock(&lasat_info_mutex);
136 r = sysctl_intvec(table, name, nlen, oldval, oldlenp, newval, newlen);
138 mutex_unlock(&lasat_info_mutex);
141 if (newval && newlen)
142 lasat_write_eeprom_info();
143 mutex_unlock(&lasat_info_mutex);
150 int sysctl_lasat_rtc(ctl_table *table, int *name, int nlen,
151 void *oldval, size_t *oldlenp,
152 void *newval, size_t newlen)
156 mutex_lock(&lasat_info_mutex);
157 rtctmp = read_persistent_clock();
160 r = sysctl_intvec(table, name, nlen, oldval, oldlenp, newval, newlen);
162 mutex_unlock(&lasat_info_mutex);
165 if (newval && newlen)
166 rtc_mips_set_mmss(rtctmp);
167 mutex_unlock(&lasat_info_mutex);
174 static char lasat_bcastaddr[16];
176 void update_bcastaddr(void)
180 ip = (lasat_board_info.li_eeprom_info.ipaddr &
181 lasat_board_info.li_eeprom_info.netmask) |
182 ~lasat_board_info.li_eeprom_info.netmask;
184 sprintf(lasat_bcastaddr, "%d.%d.%d.%d",
191 static char proc_lasat_ipbuf[32];
193 /* Parsing of IP address */
194 int proc_lasat_ip(ctl_table *table, int write, struct file *filp,
195 void *buffer, size_t *lenp, loff_t *ppos)
201 if (!table->data || !table->maxlen || !*lenp ||
207 mutex_lock(&lasat_info_mutex);
211 while (len < *lenp) {
212 if (get_user(c, p++)) {
213 mutex_unlock(&lasat_info_mutex);
216 if (c == 0 || c == '\n')
220 if (len >= sizeof(proc_lasat_ipbuf)-1)
221 len = sizeof(proc_lasat_ipbuf) - 1;
222 if (copy_from_user(proc_lasat_ipbuf, buffer, len)) {
223 mutex_unlock(&lasat_info_mutex);
226 proc_lasat_ipbuf[len] = 0;
228 /* Now see if we can convert it to a valid IP */
229 ip = in_aton(proc_lasat_ipbuf);
230 *(unsigned int *)(table->data) = ip;
231 lasat_write_eeprom_info();
233 ip = *(unsigned int *)(table->data);
234 sprintf(proc_lasat_ipbuf, "%d.%d.%d.%d",
239 len = strlen(proc_lasat_ipbuf);
243 if (copy_to_user(buffer, proc_lasat_ipbuf, len)) {
244 mutex_unlock(&lasat_info_mutex);
248 if (put_user('\n', ((char *) buffer) + len)) {
249 mutex_unlock(&lasat_info_mutex);
258 mutex_unlock(&lasat_info_mutex);
262 #endif /* defined(CONFIG_INET) */
264 static int sysctl_lasat_eeprom_value(ctl_table *table, int *name, int nlen,
265 void *oldval, size_t *oldlenp,
266 void *newval, size_t newlen)
270 mutex_lock(&lasat_info_mutex);
271 r = sysctl_intvec(table, name, nlen, oldval, oldlenp, newval, newlen);
273 mutex_unlock(&lasat_info_mutex);
277 if (newval && newlen) {
278 if (name && *name == LASAT_PRID)
279 lasat_board_info.li_eeprom_info.prid = *(int *)newval;
281 lasat_write_eeprom_info();
282 lasat_init_board_info();
284 mutex_unlock(&lasat_info_mutex);
289 int proc_lasat_eeprom_value(ctl_table *table, int write, struct file *filp,
290 void *buffer, size_t *lenp, loff_t *ppos)
294 mutex_lock(&lasat_info_mutex);
295 r = proc_dointvec(table, write, filp, buffer, lenp, ppos);
297 mutex_unlock(&lasat_info_mutex);
300 if (filp && filp->f_path.dentry) {
301 if (!strcmp(filp->f_path.dentry->d_name.name, "prid"))
302 lasat_board_info.li_eeprom_info.prid =
303 lasat_board_info.li_prid;
304 if (!strcmp(filp->f_path.dentry->d_name.name, "debugaccess"))
305 lasat_board_info.li_eeprom_info.debugaccess =
306 lasat_board_info.li_debugaccess;
308 lasat_write_eeprom_info();
309 mutex_unlock(&lasat_info_mutex);
314 extern int lasat_boot_to_service;
318 static ctl_table lasat_table[] = {
320 .ctl_name = CTL_UNNUMBERED,
321 .procname = "cpu-hz",
322 .data = &lasat_board_info.li_cpu_hz,
323 .maxlen = sizeof(int),
325 .proc_handler = &proc_dointvec,
326 .strategy = &sysctl_intvec
329 .ctl_name = CTL_UNNUMBERED,
330 .procname = "bus-hz",
331 .data = &lasat_board_info.li_bus_hz,
332 .maxlen = sizeof(int),
334 .proc_handler = &proc_dointvec,
335 .strategy = &sysctl_intvec
338 .ctl_name = CTL_UNNUMBERED,
340 .data = &lasat_board_info.li_bmid,
341 .maxlen = sizeof(int),
343 .proc_handler = &proc_dointvec,
344 .strategy = &sysctl_intvec
347 .ctl_name = CTL_UNNUMBERED,
349 .data = &lasat_board_info.li_prid,
350 .maxlen = sizeof(int),
352 .proc_handler = &proc_lasat_eeprom_value,
353 .strategy = &sysctl_lasat_eeprom_value
357 .ctl_name = CTL_UNNUMBERED,
358 .procname = "ipaddr",
359 .data = &lasat_board_info.li_eeprom_info.ipaddr,
360 .maxlen = sizeof(int),
362 .proc_handler = &proc_lasat_ip,
363 .strategy = &sysctl_lasat_intvec
366 .ctl_name = LASAT_NETMASK,
367 .procname = "netmask",
368 .data = &lasat_board_info.li_eeprom_info.netmask,
369 .maxlen = sizeof(int),
371 .proc_handler = &proc_lasat_ip,
372 .strategy = &sysctl_lasat_intvec
375 .ctl_name = CTL_UNNUMBERED,
376 .procname = "bcastaddr",
377 .data = &lasat_bcastaddr,
378 .maxlen = sizeof(lasat_bcastaddr),
380 .proc_handler = &proc_dostring,
381 .strategy = &sysctl_string
385 .ctl_name = CTL_UNNUMBERED,
386 .procname = "passwd_hash",
387 .data = &lasat_board_info.li_eeprom_info.passwd_hash,
389 sizeof(lasat_board_info.li_eeprom_info.passwd_hash),
391 .proc_handler = &proc_dolasatstring,
392 .strategy = &sysctl_lasatstring
395 .ctl_name = CTL_UNNUMBERED,
396 .procname = "boot-service",
397 .data = &lasat_boot_to_service,
398 .maxlen = sizeof(int),
400 .proc_handler = &proc_dointvec,
401 .strategy = &sysctl_intvec
405 .ctl_name = CTL_UNNUMBERED,
408 .maxlen = sizeof(int),
410 .proc_handler = &proc_dolasatrtc,
411 .strategy = &sysctl_lasat_rtc
415 .ctl_name = CTL_UNNUMBERED,
416 .procname = "namestr",
417 .data = &lasat_board_info.li_namestr,
418 .maxlen = sizeof(lasat_board_info.li_namestr),
420 .proc_handler = &proc_dostring,
421 .strategy = &sysctl_string
424 .ctl_name = CTL_UNNUMBERED,
425 .procname = "typestr",
426 .data = &lasat_board_info.li_typestr,
427 .maxlen = sizeof(lasat_board_info.li_typestr),
429 .proc_handler = &proc_dostring,
430 .strategy = &sysctl_string
435 static ctl_table lasat_root_table[] = {
437 .ctl_name = CTL_UNNUMBERED,
445 static int __init lasat_register_sysctl(void)
447 struct ctl_table_header *lasat_table_header;
450 register_sysctl_table(lasat_root_table);
455 __initcall(lasat_register_sysctl);
456 #endif /* CONFIG_SYSCTL */