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
,
42 void *oldval
, size_t *oldlenp
,
43 void *newval
, size_t newlen
)
47 r
= sysctl_string(table
, oldval
, oldlenp
, newval
, newlen
);
52 lasat_write_eeprom_info();
58 /* And the same for proc */
59 int proc_dolasatstring(ctl_table
*table
, int write
, struct file
*filp
,
60 void *buffer
, size_t *lenp
, loff_t
*ppos
)
64 r
= proc_dostring(table
, write
, filp
, buffer
, lenp
, ppos
);
68 lasat_write_eeprom_info();
73 /* proc function to write EEPROM after changing int entry */
74 int proc_dolasatint(ctl_table
*table
, int write
, struct file
*filp
,
75 void *buffer
, size_t *lenp
, loff_t
*ppos
)
79 r
= proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
);
83 lasat_write_eeprom_info();
91 /* proc function to read/write RealTime Clock */
92 int proc_dolasatrtc(ctl_table
*table
, int write
, struct file
*filp
,
93 void *buffer
, size_t *lenp
, loff_t
*ppos
)
98 rtctmp
= read_persistent_clock();
99 /* check for time < 0 and set to 0 */
103 r
= proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
);
108 rtc_mips_set_mmss(rtctmp
);
114 /* Sysctl for setting the IP addresses */
115 int sysctl_lasat_intvec(ctl_table
*table
,
116 void *oldval
, size_t *oldlenp
,
117 void *newval
, size_t newlen
)
121 r
= sysctl_intvec(table
, oldval
, oldlenp
, newval
, newlen
);
125 if (newval
&& newlen
)
126 lasat_write_eeprom_info();
133 int sysctl_lasat_rtc(ctl_table
*table
,
134 void *oldval
, size_t *oldlenp
,
135 void *newval
, size_t newlen
)
139 rtctmp
= read_persistent_clock();
142 r
= sysctl_intvec(table
, oldval
, oldlenp
, newval
, newlen
);
145 if (newval
&& newlen
)
146 rtc_mips_set_mmss(rtctmp
);
153 int proc_lasat_ip(ctl_table
*table
, int write
, struct file
*filp
,
154 void *buffer
, size_t *lenp
, loff_t
*ppos
)
161 if (!table
->data
|| !table
->maxlen
|| !*lenp
||
170 while (len
< *lenp
) {
171 if (get_user(c
, p
++))
173 if (c
== 0 || c
== '\n')
177 if (len
>= sizeof(ipbuf
)-1)
178 len
= sizeof(ipbuf
) - 1;
179 if (copy_from_user(ipbuf
, buffer
, len
))
183 /* Now see if we can convert it to a valid IP */
185 *(unsigned int *)(table
->data
) = ip
;
186 lasat_write_eeprom_info();
188 ip
= *(unsigned int *)(table
->data
);
189 sprintf(ipbuf
, "%d.%d.%d.%d",
198 if (copy_to_user(buffer
, ipbuf
, len
))
201 if (put_user('\n', ((char *) buffer
) + len
))
213 static int sysctl_lasat_prid(ctl_table
*table
,
214 void *oldval
, size_t *oldlenp
,
215 void *newval
, size_t newlen
)
219 r
= sysctl_intvec(table
, oldval
, oldlenp
, newval
, newlen
);
222 if (newval
&& newlen
) {
223 lasat_board_info
.li_eeprom_info
.prid
= *(int *)newval
;
224 lasat_write_eeprom_info();
225 lasat_init_board_info();
230 int proc_lasat_prid(ctl_table
*table
, int write
, struct file
*filp
,
231 void *buffer
, size_t *lenp
, loff_t
*ppos
)
235 r
= proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
);
239 lasat_board_info
.li_eeprom_info
.prid
=
240 lasat_board_info
.li_prid
;
241 lasat_write_eeprom_info();
242 lasat_init_board_info();
247 extern int lasat_boot_to_service
;
249 static ctl_table lasat_table
[] = {
251 .ctl_name
= CTL_UNNUMBERED
,
252 .procname
= "cpu-hz",
253 .data
= &lasat_board_info
.li_cpu_hz
,
254 .maxlen
= sizeof(int),
256 .proc_handler
= &proc_dointvec
,
257 .strategy
= &sysctl_intvec
260 .ctl_name
= CTL_UNNUMBERED
,
261 .procname
= "bus-hz",
262 .data
= &lasat_board_info
.li_bus_hz
,
263 .maxlen
= sizeof(int),
265 .proc_handler
= &proc_dointvec
,
266 .strategy
= &sysctl_intvec
269 .ctl_name
= CTL_UNNUMBERED
,
271 .data
= &lasat_board_info
.li_bmid
,
272 .maxlen
= sizeof(int),
274 .proc_handler
= &proc_dointvec
,
275 .strategy
= &sysctl_intvec
278 .ctl_name
= CTL_UNNUMBERED
,
280 .data
= &lasat_board_info
.li_prid
,
281 .maxlen
= sizeof(int),
283 .proc_handler
= &proc_lasat_prid
,
284 .strategy
= &sysctl_lasat_prid
288 .ctl_name
= CTL_UNNUMBERED
,
289 .procname
= "ipaddr",
290 .data
= &lasat_board_info
.li_eeprom_info
.ipaddr
,
291 .maxlen
= sizeof(int),
293 .proc_handler
= &proc_lasat_ip
,
294 .strategy
= &sysctl_lasat_intvec
297 .ctl_name
= CTL_UNNUMBERED
,
298 .procname
= "netmask",
299 .data
= &lasat_board_info
.li_eeprom_info
.netmask
,
300 .maxlen
= sizeof(int),
302 .proc_handler
= &proc_lasat_ip
,
303 .strategy
= &sysctl_lasat_intvec
307 .ctl_name
= CTL_UNNUMBERED
,
308 .procname
= "passwd_hash",
309 .data
= &lasat_board_info
.li_eeprom_info
.passwd_hash
,
311 sizeof(lasat_board_info
.li_eeprom_info
.passwd_hash
),
313 .proc_handler
= &proc_dolasatstring
,
314 .strategy
= &sysctl_lasatstring
317 .ctl_name
= CTL_UNNUMBERED
,
318 .procname
= "boot-service",
319 .data
= &lasat_boot_to_service
,
320 .maxlen
= sizeof(int),
322 .proc_handler
= &proc_dointvec
,
323 .strategy
= &sysctl_intvec
327 .ctl_name
= CTL_UNNUMBERED
,
330 .maxlen
= sizeof(int),
332 .proc_handler
= &proc_dolasatrtc
,
333 .strategy
= &sysctl_lasat_rtc
337 .ctl_name
= CTL_UNNUMBERED
,
338 .procname
= "namestr",
339 .data
= &lasat_board_info
.li_namestr
,
340 .maxlen
= sizeof(lasat_board_info
.li_namestr
),
342 .proc_handler
= &proc_dostring
,
343 .strategy
= &sysctl_string
346 .ctl_name
= CTL_UNNUMBERED
,
347 .procname
= "typestr",
348 .data
= &lasat_board_info
.li_typestr
,
349 .maxlen
= sizeof(lasat_board_info
.li_typestr
),
351 .proc_handler
= &proc_dostring
,
352 .strategy
= &sysctl_string
357 static ctl_table lasat_root_table
[] = {
359 .ctl_name
= CTL_UNNUMBERED
,
367 static int __init
lasat_register_sysctl(void)
369 struct ctl_table_header
*lasat_table_header
;
372 register_sysctl_table(lasat_root_table
);
373 if (!lasat_table_header
) {
374 printk(KERN_ERR
"Unable to register LASAT sysctl\n");
381 __initcall(lasat_register_sysctl
);