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
,
60 void *buffer
, size_t *lenp
, loff_t
*ppos
)
64 r
= proc_dostring(table
, write
, 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
,
75 void *buffer
, size_t *lenp
, loff_t
*ppos
)
79 r
= proc_dointvec(table
, write
, 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
,
93 void *buffer
, size_t *lenp
, loff_t
*ppos
)
99 read_persistent_clock(&ts
);
101 /* check for time < 0 and set to 0 */
105 r
= proc_dointvec(table
, write
, buffer
, lenp
, ppos
);
110 rtc_mips_set_mmss(rtctmp
);
116 /* Sysctl for setting the IP addresses */
117 int sysctl_lasat_intvec(ctl_table
*table
,
118 void *oldval
, size_t *oldlenp
,
119 void *newval
, size_t newlen
)
123 r
= sysctl_intvec(table
, oldval
, oldlenp
, newval
, newlen
);
127 if (newval
&& newlen
)
128 lasat_write_eeprom_info();
135 int sysctl_lasat_rtc(ctl_table
*table
,
136 void *oldval
, size_t *oldlenp
,
137 void *newval
, size_t newlen
)
142 read_persistent_clock(&ts
);
146 r
= sysctl_intvec(table
, oldval
, oldlenp
, newval
, newlen
);
149 if (newval
&& newlen
)
150 rtc_mips_set_mmss(rtctmp
);
157 int proc_lasat_ip(ctl_table
*table
, int write
,
158 void *buffer
, size_t *lenp
, loff_t
*ppos
)
165 if (!table
->data
|| !table
->maxlen
|| !*lenp
||
174 while (len
< *lenp
) {
175 if (get_user(c
, p
++))
177 if (c
== 0 || c
== '\n')
181 if (len
>= sizeof(ipbuf
)-1)
182 len
= sizeof(ipbuf
) - 1;
183 if (copy_from_user(ipbuf
, buffer
, len
))
187 /* Now see if we can convert it to a valid IP */
189 *(unsigned int *)(table
->data
) = ip
;
190 lasat_write_eeprom_info();
192 ip
= *(unsigned int *)(table
->data
);
193 sprintf(ipbuf
, "%d.%d.%d.%d",
202 if (copy_to_user(buffer
, ipbuf
, len
))
205 if (put_user('\n', ((char *) buffer
) + len
))
217 static int sysctl_lasat_prid(ctl_table
*table
,
218 void *oldval
, size_t *oldlenp
,
219 void *newval
, size_t newlen
)
223 r
= sysctl_intvec(table
, oldval
, oldlenp
, newval
, newlen
);
226 if (newval
&& newlen
) {
227 lasat_board_info
.li_eeprom_info
.prid
= *(int *)newval
;
228 lasat_write_eeprom_info();
229 lasat_init_board_info();
234 int proc_lasat_prid(ctl_table
*table
, int write
,
235 void *buffer
, size_t *lenp
, loff_t
*ppos
)
239 r
= proc_dointvec(table
, write
, buffer
, lenp
, ppos
);
243 lasat_board_info
.li_eeprom_info
.prid
=
244 lasat_board_info
.li_prid
;
245 lasat_write_eeprom_info();
246 lasat_init_board_info();
251 extern int lasat_boot_to_service
;
253 static ctl_table lasat_table
[] = {
255 .ctl_name
= CTL_UNNUMBERED
,
256 .procname
= "cpu-hz",
257 .data
= &lasat_board_info
.li_cpu_hz
,
258 .maxlen
= sizeof(int),
260 .proc_handler
= &proc_dointvec
,
261 .strategy
= &sysctl_intvec
264 .ctl_name
= CTL_UNNUMBERED
,
265 .procname
= "bus-hz",
266 .data
= &lasat_board_info
.li_bus_hz
,
267 .maxlen
= sizeof(int),
269 .proc_handler
= &proc_dointvec
,
270 .strategy
= &sysctl_intvec
273 .ctl_name
= CTL_UNNUMBERED
,
275 .data
= &lasat_board_info
.li_bmid
,
276 .maxlen
= sizeof(int),
278 .proc_handler
= &proc_dointvec
,
279 .strategy
= &sysctl_intvec
282 .ctl_name
= CTL_UNNUMBERED
,
284 .data
= &lasat_board_info
.li_prid
,
285 .maxlen
= sizeof(int),
287 .proc_handler
= &proc_lasat_prid
,
288 .strategy
= &sysctl_lasat_prid
292 .ctl_name
= CTL_UNNUMBERED
,
293 .procname
= "ipaddr",
294 .data
= &lasat_board_info
.li_eeprom_info
.ipaddr
,
295 .maxlen
= sizeof(int),
297 .proc_handler
= &proc_lasat_ip
,
298 .strategy
= &sysctl_lasat_intvec
301 .ctl_name
= CTL_UNNUMBERED
,
302 .procname
= "netmask",
303 .data
= &lasat_board_info
.li_eeprom_info
.netmask
,
304 .maxlen
= sizeof(int),
306 .proc_handler
= &proc_lasat_ip
,
307 .strategy
= &sysctl_lasat_intvec
311 .ctl_name
= CTL_UNNUMBERED
,
312 .procname
= "passwd_hash",
313 .data
= &lasat_board_info
.li_eeprom_info
.passwd_hash
,
315 sizeof(lasat_board_info
.li_eeprom_info
.passwd_hash
),
317 .proc_handler
= &proc_dolasatstring
,
318 .strategy
= &sysctl_lasatstring
321 .ctl_name
= CTL_UNNUMBERED
,
322 .procname
= "boot-service",
323 .data
= &lasat_boot_to_service
,
324 .maxlen
= sizeof(int),
326 .proc_handler
= &proc_dointvec
,
327 .strategy
= &sysctl_intvec
331 .ctl_name
= CTL_UNNUMBERED
,
334 .maxlen
= sizeof(int),
336 .proc_handler
= &proc_dolasatrtc
,
337 .strategy
= &sysctl_lasat_rtc
341 .ctl_name
= CTL_UNNUMBERED
,
342 .procname
= "namestr",
343 .data
= &lasat_board_info
.li_namestr
,
344 .maxlen
= sizeof(lasat_board_info
.li_namestr
),
346 .proc_handler
= &proc_dostring
,
347 .strategy
= &sysctl_string
350 .ctl_name
= CTL_UNNUMBERED
,
351 .procname
= "typestr",
352 .data
= &lasat_board_info
.li_typestr
,
353 .maxlen
= sizeof(lasat_board_info
.li_typestr
),
355 .proc_handler
= &proc_dostring
,
356 .strategy
= &sysctl_string
361 static ctl_table lasat_root_table
[] = {
363 .ctl_name
= CTL_UNNUMBERED
,
371 static int __init
lasat_register_sysctl(void)
373 struct ctl_table_header
*lasat_table_header
;
376 register_sysctl_table(lasat_root_table
);
377 if (!lasat_table_header
) {
378 printk(KERN_ERR
"Unable to register LASAT sysctl\n");
385 __initcall(lasat_register_sysctl
);