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/config.h>
24 #include <linux/module.h>
25 #include <linux/sysctl.h>
26 #include <linux/stddef.h>
27 #include <linux/init.h>
29 #include <linux/ctype.h>
30 #include <linux/string.h>
31 #include <linux/net.h>
32 #include <linux/inet.h>
33 #include <linux/mutex.h>
34 #include <asm/uaccess.h>
39 static DEFINE_MUTEX(lasat_info_mutex
);
41 /* Strategy function to write EEPROM after changing string entry */
42 int sysctl_lasatstring(ctl_table
*table
, int *name
, int nlen
,
43 void *oldval
, size_t *oldlenp
,
44 void *newval
, size_t newlen
, void **context
)
47 mutex_lock(&lasat_info_mutex
);
48 r
= sysctl_string(table
, name
,
49 nlen
, oldval
, oldlenp
, newval
, newlen
, context
);
51 mutex_unlock(&lasat_info_mutex
);
54 if (newval
&& newlen
) {
55 lasat_write_eeprom_info();
57 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
)
67 mutex_lock(&lasat_info_mutex
);
68 r
= proc_dostring(table
, write
, filp
, buffer
, lenp
, ppos
);
70 mutex_unlock(&lasat_info_mutex
);
73 lasat_write_eeprom_info();
74 mutex_unlock(&lasat_info_mutex
);
78 /* proc function to write EEPROM after changing int entry */
79 int proc_dolasatint(ctl_table
*table
, int write
, struct file
*filp
,
80 void *buffer
, size_t *lenp
, loff_t
*ppos
)
83 mutex_lock(&lasat_info_mutex
);
84 r
= proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
);
86 mutex_unlock(&lasat_info_mutex
);
89 lasat_write_eeprom_info();
90 mutex_unlock(&lasat_info_mutex
);
97 /* proc function to read/write RealTime Clock */
98 int proc_dolasatrtc(ctl_table
*table
, int write
, struct file
*filp
,
99 void *buffer
, size_t *lenp
, loff_t
*ppos
)
102 mutex_lock(&lasat_info_mutex
);
104 rtctmp
= ds1603_read();
105 /* check for time < 0 and set to 0 */
109 r
= proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
);
110 if ( (!write
) || r
) {
111 mutex_unlock(&lasat_info_mutex
);
115 mutex_unlock(&lasat_info_mutex
);
120 /* Sysctl for setting the IP addresses */
121 int sysctl_lasat_intvec(ctl_table
*table
, int *name
, int nlen
,
122 void *oldval
, size_t *oldlenp
,
123 void *newval
, size_t newlen
, void **context
)
126 mutex_lock(&lasat_info_mutex
);
127 r
= sysctl_intvec(table
, name
, nlen
, oldval
, oldlenp
, newval
, newlen
, context
);
129 mutex_unlock(&lasat_info_mutex
);
132 if (newval
&& newlen
) {
133 lasat_write_eeprom_info();
135 mutex_unlock(&lasat_info_mutex
);
141 int sysctl_lasat_rtc(ctl_table
*table
, int *name
, int nlen
,
142 void *oldval
, size_t *oldlenp
,
143 void *newval
, size_t newlen
, void **context
)
146 mutex_lock(&lasat_info_mutex
);
147 rtctmp
= ds1603_read();
150 r
= sysctl_intvec(table
, name
, nlen
, oldval
, oldlenp
, newval
, newlen
, context
);
152 mutex_unlock(&lasat_info_mutex
);
155 if (newval
&& newlen
) {
158 mutex_unlock(&lasat_info_mutex
);
164 static char lasat_bcastaddr
[16];
166 void update_bcastaddr(void)
170 ip
= (lasat_board_info
.li_eeprom_info
.ipaddr
&
171 lasat_board_info
.li_eeprom_info
.netmask
) |
172 ~lasat_board_info
.li_eeprom_info
.netmask
;
174 sprintf(lasat_bcastaddr
, "%d.%d.%d.%d",
181 static char proc_lasat_ipbuf
[32];
182 /* Parsing of IP address */
183 int proc_lasat_ip(ctl_table
*table
, int write
, struct file
*filp
,
184 void *buffer
, size_t *lenp
, loff_t
*ppos
)
190 if (!table
->data
|| !table
->maxlen
|| !*lenp
||
196 mutex_lock(&lasat_info_mutex
);
200 while (len
< *lenp
) {
201 if(get_user(c
, p
++)) {
202 mutex_unlock(&lasat_info_mutex
);
205 if (c
== 0 || c
== '\n')
209 if (len
>= sizeof(proc_lasat_ipbuf
)-1)
210 len
= sizeof(proc_lasat_ipbuf
) - 1;
211 if (copy_from_user(proc_lasat_ipbuf
, buffer
, len
))
213 mutex_unlock(&lasat_info_mutex
);
216 proc_lasat_ipbuf
[len
] = 0;
218 /* Now see if we can convert it to a valid IP */
219 ip
= in_aton(proc_lasat_ipbuf
);
220 *(unsigned int *)(table
->data
) = ip
;
221 lasat_write_eeprom_info();
223 ip
= *(unsigned int *)(table
->data
);
224 sprintf(proc_lasat_ipbuf
, "%d.%d.%d.%d",
229 len
= strlen(proc_lasat_ipbuf
);
233 if(copy_to_user(buffer
, proc_lasat_ipbuf
, len
)) {
234 mutex_unlock(&lasat_info_mutex
);
238 if(put_user('\n', ((char *) buffer
) + len
)) {
239 mutex_unlock(&lasat_info_mutex
);
248 mutex_unlock(&lasat_info_mutex
);
251 #endif /* defined(CONFIG_INET) */
253 static int sysctl_lasat_eeprom_value(ctl_table
*table
, int *name
, int nlen
,
254 void *oldval
, size_t *oldlenp
,
255 void *newval
, size_t newlen
,
260 mutex_lock(&lasat_info_mutex
);
261 r
= sysctl_intvec(table
, name
, nlen
, oldval
, oldlenp
, newval
, newlen
, context
);
263 mutex_unlock(&lasat_info_mutex
);
267 if (newval
&& newlen
)
269 if (name
&& *name
== LASAT_PRID
)
270 lasat_board_info
.li_eeprom_info
.prid
= *(int*)newval
;
272 lasat_write_eeprom_info();
273 lasat_init_board_info();
275 mutex_unlock(&lasat_info_mutex
);
280 int proc_lasat_eeprom_value(ctl_table
*table
, int write
, struct file
*filp
,
281 void *buffer
, size_t *lenp
, loff_t
*ppos
)
284 mutex_lock(&lasat_info_mutex
);
285 r
= proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
);
286 if ( (!write
) || r
) {
287 mutex_unlock(&lasat_info_mutex
);
290 if (filp
&& filp
->f_dentry
)
292 if (!strcmp(filp
->f_dentry
->d_name
.name
, "prid"))
293 lasat_board_info
.li_eeprom_info
.prid
= lasat_board_info
.li_prid
;
294 if (!strcmp(filp
->f_dentry
->d_name
.name
, "debugaccess"))
295 lasat_board_info
.li_eeprom_info
.debugaccess
= lasat_board_info
.li_debugaccess
;
297 lasat_write_eeprom_info();
298 mutex_unlock(&lasat_info_mutex
);
302 extern int lasat_boot_to_service
;
306 static ctl_table lasat_table
[] = {
307 {LASAT_CPU_HZ
, "cpu-hz", &lasat_board_info
.li_cpu_hz
, sizeof(int),
308 0444, NULL
, &proc_dointvec
, &sysctl_intvec
},
309 {LASAT_BUS_HZ
, "bus-hz", &lasat_board_info
.li_bus_hz
, sizeof(int),
310 0444, NULL
, &proc_dointvec
, &sysctl_intvec
},
311 {LASAT_MODEL
, "bmid", &lasat_board_info
.li_bmid
, sizeof(int),
312 0444, NULL
, &proc_dointvec
, &sysctl_intvec
},
313 {LASAT_PRID
, "prid", &lasat_board_info
.li_prid
, sizeof(int),
314 0644, NULL
, &proc_lasat_eeprom_value
, &sysctl_lasat_eeprom_value
},
316 {LASAT_IPADDR
, "ipaddr", &lasat_board_info
.li_eeprom_info
.ipaddr
, sizeof(int),
317 0644, NULL
, &proc_lasat_ip
, &sysctl_lasat_intvec
},
318 {LASAT_NETMASK
, "netmask", &lasat_board_info
.li_eeprom_info
.netmask
, sizeof(int),
319 0644, NULL
, &proc_lasat_ip
, &sysctl_lasat_intvec
},
320 {LASAT_BCAST
, "bcastaddr", &lasat_bcastaddr
,
321 sizeof(lasat_bcastaddr
), 0600, NULL
,
322 &proc_dostring
, &sysctl_string
},
324 {LASAT_PASSWORD
, "passwd_hash", &lasat_board_info
.li_eeprom_info
.passwd_hash
, sizeof(lasat_board_info
.li_eeprom_info
.passwd_hash
),
325 0600, NULL
, &proc_dolasatstring
, &sysctl_lasatstring
},
326 {LASAT_SBOOT
, "boot-service", &lasat_boot_to_service
, sizeof(int),
327 0644, NULL
, &proc_dointvec
, &sysctl_intvec
},
329 {LASAT_RTC
, "rtc", &rtctmp
, sizeof(int),
330 0644, NULL
, &proc_dolasatrtc
, &sysctl_lasat_rtc
},
332 {LASAT_NAMESTR
, "namestr", &lasat_board_info
.li_namestr
, sizeof(lasat_board_info
.li_namestr
),
333 0444, NULL
, &proc_dostring
, &sysctl_string
},
334 {LASAT_TYPESTR
, "typestr", &lasat_board_info
.li_typestr
, sizeof(lasat_board_info
.li_typestr
),
335 0444, NULL
, &proc_dostring
, &sysctl_string
},
339 #define CTL_LASAT 1 // CTL_ANY ???
340 static ctl_table lasat_root_table
[] = {
341 { CTL_LASAT
, "lasat", NULL
, 0, 0555, lasat_table
},
345 static int __init
lasat_register_sysctl(void)
347 struct ctl_table_header
*lasat_table_header
;
350 register_sysctl_table(lasat_root_table
, 0);
355 __initcall(lasat_register_sysctl
);
356 #endif /* CONFIG_SYSCTL */