• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Thomas Horsten <thh@lasat.com>
3  * Copyright (C) 2000 LASAT Networks A/S.
4  *
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.
8  *
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
12  *  for more details.
13  *
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.
17  *
18  * Routines specific to the LASAT boards
19  */
20 #include <linux/types.h>
21 #include <asm/lasat/lasat.h>
22 
23 #include <linux/sysctl.h>
24 #include <linux/stddef.h>
25 #include <linux/init.h>
26 #include <linux/fs.h>
27 #include <linux/ctype.h>
28 #include <linux/string.h>
29 #include <linux/net.h>
30 #include <linux/inet.h>
31 #include <linux/uaccess.h>
32 
33 #include <asm/time.h>
34 
35 #ifdef CONFIG_DS1603
36 #include "ds1603.h"
37 #endif
38 
39 
40 /* And the same for proc */
proc_dolasatstring(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)41 int proc_dolasatstring(struct ctl_table *table, int write,
42 		       void *buffer, size_t *lenp, loff_t *ppos)
43 {
44 	int r;
45 
46 	r = proc_dostring(table, write, buffer, lenp, ppos);
47 	if ((!write) || r)
48 		return r;
49 
50 	lasat_write_eeprom_info();
51 
52 	return 0;
53 }
54 
55 #ifdef CONFIG_DS1603
56 static int rtctmp;
57 
58 /* proc function to read/write RealTime Clock */
proc_dolasatrtc(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)59 int proc_dolasatrtc(struct ctl_table *table, int write,
60 		       void *buffer, size_t *lenp, loff_t *ppos)
61 {
62 	struct timespec64 ts;
63 	int r;
64 
65 	if (!write) {
66 		read_persistent_clock64(&ts);
67 		rtctmp = ts.tv_sec;
68 		/* check for time < 0 and set to 0 */
69 		if (rtctmp < 0)
70 			rtctmp = 0;
71 	}
72 	r = proc_dointvec(table, write, buffer, lenp, ppos);
73 	if (r)
74 		return r;
75 
76 	if (write)
77 		rtc_mips_set_mmss(rtctmp);
78 
79 	return 0;
80 }
81 #endif
82 
83 #ifdef CONFIG_INET
proc_lasat_ip(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)84 int proc_lasat_ip(struct ctl_table *table, int write,
85 		       void *buffer, size_t *lenp, loff_t *ppos)
86 {
87 	unsigned int ip;
88 	char *p, c;
89 	int len;
90 	char ipbuf[32];
91 
92 	if (!table->data || !table->maxlen || !*lenp ||
93 	    (*ppos && !write)) {
94 		*lenp = 0;
95 		return 0;
96 	}
97 
98 	if (write) {
99 		len = 0;
100 		p = buffer;
101 		while (len < *lenp) {
102 			if (get_user(c, p++))
103 				return -EFAULT;
104 			if (c == 0 || c == '\n')
105 				break;
106 			len++;
107 		}
108 		if (len >= sizeof(ipbuf)-1)
109 			len = sizeof(ipbuf) - 1;
110 		if (copy_from_user(ipbuf, buffer, len))
111 			return -EFAULT;
112 		ipbuf[len] = 0;
113 		*ppos += *lenp;
114 		/* Now see if we can convert it to a valid IP */
115 		ip = in_aton(ipbuf);
116 		*(unsigned int *)(table->data) = ip;
117 		lasat_write_eeprom_info();
118 	} else {
119 		ip = *(unsigned int *)(table->data);
120 		sprintf(ipbuf, "%d.%d.%d.%d",
121 			(ip)	   & 0xff,
122 			(ip >>	8) & 0xff,
123 			(ip >> 16) & 0xff,
124 			(ip >> 24) & 0xff);
125 		len = strlen(ipbuf);
126 		if (len > *lenp)
127 			len = *lenp;
128 		if (len)
129 			if (copy_to_user(buffer, ipbuf, len))
130 				return -EFAULT;
131 		if (len < *lenp) {
132 			if (put_user('\n', ((char *) buffer) + len))
133 				return -EFAULT;
134 			len++;
135 		}
136 		*lenp = len;
137 		*ppos += len;
138 	}
139 
140 	return 0;
141 }
142 #endif
143 
proc_lasat_prid(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)144 int proc_lasat_prid(struct ctl_table *table, int write,
145 		       void *buffer, size_t *lenp, loff_t *ppos)
146 {
147 	int r;
148 
149 	r = proc_dointvec(table, write, buffer, lenp, ppos);
150 	if (r < 0)
151 		return r;
152 	if (write) {
153 		lasat_board_info.li_eeprom_info.prid =
154 			lasat_board_info.li_prid;
155 		lasat_write_eeprom_info();
156 		lasat_init_board_info();
157 	}
158 	return 0;
159 }
160 
161 extern int lasat_boot_to_service;
162 
163 static struct ctl_table lasat_table[] = {
164 	{
165 		.procname	= "cpu-hz",
166 		.data		= &lasat_board_info.li_cpu_hz,
167 		.maxlen		= sizeof(int),
168 		.mode		= 0444,
169 		.proc_handler	= proc_dointvec,
170 	},
171 	{
172 		.procname	= "bus-hz",
173 		.data		= &lasat_board_info.li_bus_hz,
174 		.maxlen		= sizeof(int),
175 		.mode		= 0444,
176 		.proc_handler	= proc_dointvec,
177 	},
178 	{
179 		.procname	= "bmid",
180 		.data		= &lasat_board_info.li_bmid,
181 		.maxlen		= sizeof(int),
182 		.mode		= 0444,
183 		.proc_handler	= proc_dointvec,
184 	},
185 	{
186 		.procname	= "prid",
187 		.data		= &lasat_board_info.li_prid,
188 		.maxlen		= sizeof(int),
189 		.mode		= 0644,
190 		.proc_handler	= proc_lasat_prid,
191 	},
192 #ifdef CONFIG_INET
193 	{
194 		.procname	= "ipaddr",
195 		.data		= &lasat_board_info.li_eeprom_info.ipaddr,
196 		.maxlen		= sizeof(int),
197 		.mode		= 0644,
198 		.proc_handler	= proc_lasat_ip,
199 	},
200 	{
201 		.procname	= "netmask",
202 		.data		= &lasat_board_info.li_eeprom_info.netmask,
203 		.maxlen		= sizeof(int),
204 		.mode		= 0644,
205 		.proc_handler	= proc_lasat_ip,
206 	},
207 #endif
208 	{
209 		.procname	= "passwd_hash",
210 		.data		= &lasat_board_info.li_eeprom_info.passwd_hash,
211 		.maxlen		=
212 			sizeof(lasat_board_info.li_eeprom_info.passwd_hash),
213 		.mode		= 0600,
214 		.proc_handler	= proc_dolasatstring,
215 	},
216 	{
217 		.procname	= "boot-service",
218 		.data		= &lasat_boot_to_service,
219 		.maxlen		= sizeof(int),
220 		.mode		= 0644,
221 		.proc_handler	= proc_dointvec,
222 	},
223 #ifdef CONFIG_DS1603
224 	{
225 		.procname	= "rtc",
226 		.data		= &rtctmp,
227 		.maxlen		= sizeof(int),
228 		.mode		= 0644,
229 		.proc_handler	= proc_dolasatrtc,
230 	},
231 #endif
232 	{
233 		.procname	= "namestr",
234 		.data		= &lasat_board_info.li_namestr,
235 		.maxlen		= sizeof(lasat_board_info.li_namestr),
236 		.mode		= 0444,
237 		.proc_handler	= proc_dostring,
238 	},
239 	{
240 		.procname	= "typestr",
241 		.data		= &lasat_board_info.li_typestr,
242 		.maxlen		= sizeof(lasat_board_info.li_typestr),
243 		.mode		= 0444,
244 		.proc_handler	= proc_dostring,
245 	},
246 	{}
247 };
248 
249 static struct ctl_table lasat_root_table[] = {
250 	{
251 		.procname	= "lasat",
252 		.mode		=  0555,
253 		.child		= lasat_table
254 	},
255 	{}
256 };
257 
lasat_register_sysctl(void)258 static int __init lasat_register_sysctl(void)
259 {
260 	struct ctl_table_header *lasat_table_header;
261 
262 	lasat_table_header =
263 		register_sysctl_table(lasat_root_table);
264 	if (!lasat_table_header) {
265 		printk(KERN_ERR "Unable to register LASAT sysctl\n");
266 		return -ENOMEM;
267 	}
268 
269 	return 0;
270 }
271 
272 arch_initcall(lasat_register_sysctl);
273