4 * Thomas Horsten <thh@lasat.com>
5 * Copyright (C) 2000 LASAT Networks A/S.
7 * ########################################################################
9 * This program is free software; you can distribute it and/or modify it
10 * under the terms of the GNU General Public License (Version 2) as
11 * published by the Free Software Foundation.
13 * This program is distributed in the hope it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
22 * ########################################################################
24 * Routines specific to the LASAT boards
26 #include <linux/types.h>
27 #include <asm/lasat/lasat.h>
29 #include <linux/config.h>
30 #include <linux/module.h>
31 #include <linux/sysctl.h>
32 #include <linux/stddef.h>
33 #include <linux/init.h>
34 #include <linux/ctype.h>
35 #include <linux/string.h>
36 #include <linux/net.h>
37 #include <linux/inet.h>
38 #include <asm/uaccess.h>
43 static DECLARE_MUTEX(lasat_info_sem);
45 /* Strategy function to write EEPROM after changing string entry */
46 int sysctl_lasatstring(ctl_table *table, int *name, int nlen,
47 void *oldval, size_t *oldlenp,
48 void *newval, size_t newlen, void **context)
51 down(&lasat_info_sem);
52 r = sysctl_string(table, name,
53 nlen, oldval, oldlenp, newval, newlen, context);
58 if (newval && newlen) {
59 lasat_write_eeprom_info();
66 /* And the same for proc */
67 int proc_dolasatstring(ctl_table *table, int write, struct file *filp,
68 void *buffer, size_t *lenp)
71 down(&lasat_info_sem);
72 r = proc_dostring(table, write, filp, buffer, lenp);
77 lasat_write_eeprom_info();
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)
87 down(&lasat_info_sem);
88 r = proc_dointvec(table, write, filp, buffer, lenp);
93 lasat_write_eeprom_info();
98 /* Sysctl for setting the IP addresses */
99 int sysctl_lasat_intvec(ctl_table *table, int *name, int nlen,
100 void *oldval, size_t *oldlenp,
101 void *newval, size_t newlen, void **context)
104 down(&lasat_info_sem);
105 r = sysctl_intvec(table, name, nlen, oldval, oldlenp, newval, newlen, context);
110 if (newval && newlen) {
111 lasat_write_eeprom_info();
118 static char lasat_bcastaddr[16];
120 void update_bcastaddr(void)
124 ip = lasat_board_info.li_eeprom_info.ipaddr |
125 ~lasat_board_info.li_eeprom_info.netmask;
127 sprintf(lasat_bcastaddr, "%d.%d.%d.%d",
134 static char proc_lasat_ipbuf[32];
135 /* Parsing of IP address */
136 int proc_lasat_ip(ctl_table *table, int write, struct file *filp,
137 void *buffer, size_t *lenp)
143 if (!table->data || !table->maxlen || !*lenp ||
144 (filp->f_pos && !write)) {
149 down(&lasat_info_sem);
153 while (len < *lenp) {
154 if(get_user(c, p++)) {
158 if (c == 0 || c == '\n')
162 if (len >= sizeof(proc_lasat_ipbuf)-1)
163 len = sizeof(proc_lasat_ipbuf) - 1;
164 if (copy_from_user(proc_lasat_ipbuf, buffer, len))
169 proc_lasat_ipbuf[len] = 0;
170 filp->f_pos += *lenp;
171 /* Now see if we can convert it to a valid IP */
172 ip = in_aton(proc_lasat_ipbuf);
173 *(unsigned int *)(table->data) = ip;
174 lasat_write_eeprom_info();
176 ip = *(unsigned int *)(table->data);
177 sprintf(proc_lasat_ipbuf, "%d.%d.%d.%d",
182 len = strlen(proc_lasat_ipbuf);
186 if(copy_to_user(buffer, proc_lasat_ipbuf, len)) {
191 if(put_user('\n', ((char *) buffer) + len)) {
204 #endif /* defined(CONFIG_INET) */
206 static int sysctl_lasat_eeprom_value(ctl_table *table, int *name, int nlen,
207 void *oldval, size_t *oldlenp,
208 void *newval, size_t newlen,
213 down(&lasat_info_sem);
214 r = sysctl_intvec(table, name, nlen, oldval, oldlenp, newval, newlen, context);
220 if (newval && newlen)
222 if (name && *name == LASAT_PRID)
223 lasat_board_info.li_eeprom_info.prid = *(int*)newval;
225 lasat_write_eeprom_info();
226 lasat_init_board_info();
233 int proc_lasat_eeprom_value(ctl_table *table, int write, struct file *filp,
234 void *buffer, size_t *lenp)
237 down(&lasat_info_sem);
238 r = proc_dointvec(table, write, filp, buffer, lenp);
239 if ( (!write) || r) {
243 if (filp && filp->f_dentry)
245 if (!strcmp(filp->f_dentry->d_name.name, "prid"))
246 lasat_board_info.li_eeprom_info.prid = lasat_board_info.li_prid;
247 if (!strcmp(filp->f_dentry->d_name.name, "debugaccess"))
248 lasat_board_info.li_eeprom_info.debugaccess = lasat_board_info.li_debugaccess;
250 lasat_write_eeprom_info();
255 extern int lasat_boot_to_service;
259 static ctl_table lasat_table[] = {
260 {LASAT_CPU_HZ, "cpu-hz", &lasat_board_info.li_cpu_hz, sizeof(int),
261 0444, NULL, &proc_dointvec, &sysctl_intvec},
262 {LASAT_BUS_HZ, "bus-hz", &lasat_board_info.li_bus_hz, sizeof(int),
263 0444, NULL, &proc_dointvec, &sysctl_intvec},
264 {LASAT_MODEL, "bmid", &lasat_board_info.li_bmid, sizeof(int),
265 0444, NULL, &proc_dointvec, &sysctl_intvec},
266 {LASAT_PRID, "prid", &lasat_board_info.li_prid, sizeof(int),
267 0644, NULL, &proc_lasat_eeprom_value, &sysctl_lasat_eeprom_value},
269 {LASAT_IPADDR, "ipaddr", &lasat_board_info.li_eeprom_info.ipaddr, sizeof(int),
270 0644, NULL, &proc_lasat_ip, &sysctl_lasat_intvec},
271 {LASAT_NETMASK, "netmask", &lasat_board_info.li_eeprom_info.netmask, sizeof(int),
272 0644, NULL, &proc_lasat_ip, &sysctl_lasat_intvec},
273 {LASAT_BCAST, "bcastaddr", &lasat_bcastaddr,
274 sizeof(lasat_bcastaddr), 0600, NULL,
275 &proc_dostring, &sysctl_string},
277 {LASAT_PASSWORD, "passwd_hash", &lasat_board_info.li_eeprom_info.passwd_hash, sizeof(lasat_board_info.li_eeprom_info.passwd_hash),
278 0600, NULL, &proc_dolasatstring, &sysctl_lasatstring},
279 {LASAT_SBOOT, "boot-service", &lasat_boot_to_service, sizeof(int),
280 0644, NULL, &proc_dointvec, &sysctl_intvec},
281 {LASAT_NAMESTR, "namestr", &lasat_board_info.li_namestr, sizeof(lasat_board_info.li_namestr),
282 0444, NULL, &proc_dostring, &sysctl_string},
283 {LASAT_TYPESTR, "typestr", &lasat_board_info.li_typestr, sizeof(lasat_board_info.li_typestr),
284 0444, NULL, &proc_dostring, &sysctl_string},
288 #define CTL_LASAT 1 // CTL_ANY ???
289 static ctl_table lasat_root_table[] = {
290 { CTL_LASAT, "lasat", NULL, 0, 0555, lasat_table },
294 static int __init lasat_register_sysctl(void)
296 struct ctl_table_header *lasat_table_header;
299 register_sysctl_table(lasat_root_table, 0);
304 __initcall(lasat_register_sysctl);
305 #endif /* CONFIG_SYSCTL */