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/uaccess.h>
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 r = sysctl_string(table, name,
48 nlen, oldval, oldlenp, newval, newlen);
53 lasat_write_eeprom_info();
59 /* And the same for proc */
60 int proc_dolasatstring(ctl_table *table, int write, struct file *filp,
61 void *buffer, size_t *lenp, loff_t *ppos)
65 r = proc_dostring(table, write, filp, buffer, lenp, ppos);
69 lasat_write_eeprom_info();
74 /* proc function to write EEPROM after changing int entry */
75 int proc_dolasatint(ctl_table *table, int write, struct file *filp,
76 void *buffer, size_t *lenp, loff_t *ppos)
80 r = proc_dointvec(table, write, filp, buffer, lenp, ppos);
84 lasat_write_eeprom_info();
92 /* proc function to read/write RealTime Clock */
93 int proc_dolasatrtc(ctl_table *table, int write, struct file *filp,
94 void *buffer, size_t *lenp, loff_t *ppos)
99 rtctmp = read_persistent_clock();
100 /* check for time < 0 and set to 0 */
104 r = proc_dointvec(table, write, filp, buffer, lenp, ppos);
109 rtc_mips_set_mmss(rtctmp);
115 /* Sysctl for setting the IP addresses */
116 int sysctl_lasat_intvec(ctl_table *table, int *name, int nlen,
117 void *oldval, size_t *oldlenp,
118 void *newval, size_t newlen)
122 r = sysctl_intvec(table, name, nlen, oldval, oldlenp, newval, newlen);
126 if (newval && newlen)
127 lasat_write_eeprom_info();
134 int sysctl_lasat_rtc(ctl_table *table, int *name, int nlen,
135 void *oldval, size_t *oldlenp,
136 void *newval, size_t newlen)
140 rtctmp = read_persistent_clock();
143 r = sysctl_intvec(table, name, nlen, oldval, oldlenp, newval, newlen);
146 if (newval && newlen)
147 rtc_mips_set_mmss(rtctmp);
154 int proc_lasat_ip(ctl_table *table, int write, struct file *filp,
155 void *buffer, size_t *lenp, loff_t *ppos)
162 if (!table->data || !table->maxlen || !*lenp ||
171 while (len < *lenp) {
172 if (get_user(c, p++))
174 if (c == 0 || c == '\n')
178 if (len >= sizeof(ipbuf)-1)
179 len = sizeof(ipbuf) - 1;
180 if (copy_from_user(ipbuf, buffer, len))
184 /* Now see if we can convert it to a valid IP */
186 *(unsigned int *)(table->data) = ip;
187 lasat_write_eeprom_info();
189 ip = *(unsigned int *)(table->data);
190 sprintf(ipbuf, "%d.%d.%d.%d",
199 if (copy_to_user(buffer, ipbuf, len))
202 if (put_user('\n', ((char *) buffer) + len))
214 static int sysctl_lasat_prid(ctl_table *table, int *name, int nlen,
215 void *oldval, size_t *oldlenp,
216 void *newval, size_t newlen)
220 r = sysctl_intvec(table, name, nlen, oldval, oldlenp, newval, newlen);
223 if (newval && newlen) {
224 lasat_board_info.li_eeprom_info.prid = *(int *)newval;
225 lasat_write_eeprom_info();
226 lasat_init_board_info();
231 int proc_lasat_prid(ctl_table *table, int write, struct file *filp,
232 void *buffer, size_t *lenp, loff_t *ppos)
236 r = proc_dointvec(table, write, filp, buffer, lenp, ppos);
240 lasat_board_info.li_eeprom_info.prid =
241 lasat_board_info.li_prid;
242 lasat_write_eeprom_info();
243 lasat_init_board_info();
248 extern int lasat_boot_to_service;
250 static ctl_table lasat_table[] = {
252 .ctl_name = CTL_UNNUMBERED,
253 .procname = "cpu-hz",
254 .data = &lasat_board_info.li_cpu_hz,
255 .maxlen = sizeof(int),
257 .proc_handler = &proc_dointvec,
258 .strategy = &sysctl_intvec
261 .ctl_name = CTL_UNNUMBERED,
262 .procname = "bus-hz",
263 .data = &lasat_board_info.li_bus_hz,
264 .maxlen = sizeof(int),
266 .proc_handler = &proc_dointvec,
267 .strategy = &sysctl_intvec
270 .ctl_name = CTL_UNNUMBERED,
272 .data = &lasat_board_info.li_bmid,
273 .maxlen = sizeof(int),
275 .proc_handler = &proc_dointvec,
276 .strategy = &sysctl_intvec
279 .ctl_name = CTL_UNNUMBERED,
281 .data = &lasat_board_info.li_prid,
282 .maxlen = sizeof(int),
284 .proc_handler = &proc_lasat_prid,
285 .strategy = &sysctl_lasat_prid
289 .ctl_name = CTL_UNNUMBERED,
290 .procname = "ipaddr",
291 .data = &lasat_board_info.li_eeprom_info.ipaddr,
292 .maxlen = sizeof(int),
294 .proc_handler = &proc_lasat_ip,
295 .strategy = &sysctl_lasat_intvec
298 .ctl_name = CTL_UNNUMBERED,
299 .procname = "netmask",
300 .data = &lasat_board_info.li_eeprom_info.netmask,
301 .maxlen = sizeof(int),
303 .proc_handler = &proc_lasat_ip,
304 .strategy = &sysctl_lasat_intvec
308 .ctl_name = CTL_UNNUMBERED,
309 .procname = "passwd_hash",
310 .data = &lasat_board_info.li_eeprom_info.passwd_hash,
312 sizeof(lasat_board_info.li_eeprom_info.passwd_hash),
314 .proc_handler = &proc_dolasatstring,
315 .strategy = &sysctl_lasatstring
318 .ctl_name = CTL_UNNUMBERED,
319 .procname = "boot-service",
320 .data = &lasat_boot_to_service,
321 .maxlen = sizeof(int),
323 .proc_handler = &proc_dointvec,
324 .strategy = &sysctl_intvec
328 .ctl_name = CTL_UNNUMBERED,
331 .maxlen = sizeof(int),
333 .proc_handler = &proc_dolasatrtc,
334 .strategy = &sysctl_lasat_rtc
338 .ctl_name = CTL_UNNUMBERED,
339 .procname = "namestr",
340 .data = &lasat_board_info.li_namestr,
341 .maxlen = sizeof(lasat_board_info.li_namestr),
343 .proc_handler = &proc_dostring,
344 .strategy = &sysctl_string
347 .ctl_name = CTL_UNNUMBERED,
348 .procname = "typestr",
349 .data = &lasat_board_info.li_typestr,
350 .maxlen = sizeof(lasat_board_info.li_typestr),
352 .proc_handler = &proc_dostring,
353 .strategy = &sysctl_string
358 static ctl_table lasat_root_table[] = {
360 .ctl_name = CTL_UNNUMBERED,
368 static int __init lasat_register_sysctl(void)
370 struct ctl_table_header *lasat_table_header;
373 register_sysctl_table(lasat_root_table);
374 if (!lasat_table_header) {
375 printk(KERN_ERR "Unable to register LASAT sysctl\n");
382 __initcall(lasat_register_sysctl);