blob: c710d969938d74b57e7d0b31f1c8a270b546a00f [file] [log] [blame]
Brian Murphy1f21d2b2007-08-21 22:34:16 +02001/*
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/module.h>
24#include <linux/sysctl.h>
25#include <linux/stddef.h>
26#include <linux/init.h>
27#include <linux/fs.h>
28#include <linux/ctype.h>
29#include <linux/string.h>
30#include <linux/net.h>
31#include <linux/inet.h>
Brian Murphy1f21d2b2007-08-21 22:34:16 +020032#include <linux/uaccess.h>
33
Ralf Baechle4b550482007-10-11 23:46:08 +010034#include <asm/time.h>
35
Thomas Horsten1f34f2e2008-06-15 02:17:11 +010036#ifdef CONFIG_DS1603
Brian Murphy1f21d2b2007-08-21 22:34:16 +020037#include "ds1603.h"
Thomas Horsten1f34f2e2008-06-15 02:17:11 +010038#endif
Brian Murphy1f21d2b2007-08-21 22:34:16 +020039
Brian Murphy1f21d2b2007-08-21 22:34:16 +020040
41/* And the same for proc */
Joe Perchesd3478d52013-06-14 01:37:29 +000042int proc_dolasatstring(struct ctl_table *table, int write,
Brian Murphy1f21d2b2007-08-21 22:34:16 +020043 void *buffer, size_t *lenp, loff_t *ppos)
44{
45 int r;
46
Alexey Dobriyan8d65af72009-09-23 15:57:19 -070047 r = proc_dostring(table, write, buffer, lenp, ppos);
Thomas Horsten1f34f2e2008-06-15 02:17:11 +010048 if ((!write) || r)
Brian Murphy1f21d2b2007-08-21 22:34:16 +020049 return r;
Thomas Horsten1f34f2e2008-06-15 02:17:11 +010050
Brian Murphy1f21d2b2007-08-21 22:34:16 +020051 lasat_write_eeprom_info();
Brian Murphy1f21d2b2007-08-21 22:34:16 +020052
53 return 0;
54}
55
Thomas Horsten1f34f2e2008-06-15 02:17:11 +010056#ifdef CONFIG_DS1603
Brian Murphy1f21d2b2007-08-21 22:34:16 +020057static int rtctmp;
58
Brian Murphy1f21d2b2007-08-21 22:34:16 +020059/* proc function to read/write RealTime Clock */
Joe Perchesd3478d52013-06-14 01:37:29 +000060int proc_dolasatrtc(struct ctl_table *table, int write,
Brian Murphy1f21d2b2007-08-21 22:34:16 +020061 void *buffer, size_t *lenp, loff_t *ppos)
62{
Xunlei Pang2ee96632015-04-01 20:34:22 -070063 struct timespec64 ts;
Brian Murphy1f21d2b2007-08-21 22:34:16 +020064 int r;
65
Brian Murphy1f21d2b2007-08-21 22:34:16 +020066 if (!write) {
Xunlei Pang2ee96632015-04-01 20:34:22 -070067 read_persistent_clock64(&ts);
Martin Schwidefskyd4f587c2009-08-14 15:47:31 +020068 rtctmp = ts.tv_sec;
Brian Murphy1f21d2b2007-08-21 22:34:16 +020069 /* check for time < 0 and set to 0 */
70 if (rtctmp < 0)
71 rtctmp = 0;
72 }
Alexey Dobriyan8d65af72009-09-23 15:57:19 -070073 r = proc_dointvec(table, write, buffer, lenp, ppos);
Thomas Horsten1f34f2e2008-06-15 02:17:11 +010074 if (r)
Brian Murphy1f21d2b2007-08-21 22:34:16 +020075 return r;
Thomas Horsten1f34f2e2008-06-15 02:17:11 +010076
77 if (write)
78 rtc_mips_set_mmss(rtctmp);
Brian Murphy1f21d2b2007-08-21 22:34:16 +020079
80 return 0;
81}
82#endif
83
Brian Murphy1f21d2b2007-08-21 22:34:16 +020084#ifdef CONFIG_INET
Joe Perchesd3478d52013-06-14 01:37:29 +000085int proc_lasat_ip(struct ctl_table *table, int write,
Brian Murphy1f21d2b2007-08-21 22:34:16 +020086 void *buffer, size_t *lenp, loff_t *ppos)
87{
88 unsigned int ip;
89 char *p, c;
90 int len;
Thomas Horsten1f34f2e2008-06-15 02:17:11 +010091 char ipbuf[32];
Brian Murphy1f21d2b2007-08-21 22:34:16 +020092
93 if (!table->data || !table->maxlen || !*lenp ||
94 (*ppos && !write)) {
95 *lenp = 0;
96 return 0;
97 }
98
Brian Murphy1f21d2b2007-08-21 22:34:16 +020099 if (write) {
100 len = 0;
101 p = buffer;
102 while (len < *lenp) {
Thomas Horsten1f34f2e2008-06-15 02:17:11 +0100103 if (get_user(c, p++))
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200104 return -EFAULT;
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200105 if (c == 0 || c == '\n')
106 break;
107 len++;
108 }
Thomas Horsten1f34f2e2008-06-15 02:17:11 +0100109 if (len >= sizeof(ipbuf)-1)
110 len = sizeof(ipbuf) - 1;
111 if (copy_from_user(ipbuf, buffer, len))
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200112 return -EFAULT;
Thomas Horsten1f34f2e2008-06-15 02:17:11 +0100113 ipbuf[len] = 0;
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200114 *ppos += *lenp;
115 /* Now see if we can convert it to a valid IP */
Thomas Horsten1f34f2e2008-06-15 02:17:11 +0100116 ip = in_aton(ipbuf);
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200117 *(unsigned int *)(table->data) = ip;
118 lasat_write_eeprom_info();
119 } else {
120 ip = *(unsigned int *)(table->data);
Thomas Horsten1f34f2e2008-06-15 02:17:11 +0100121 sprintf(ipbuf, "%d.%d.%d.%d",
Ralf Baechle70342282013-01-22 12:59:30 +0100122 (ip) & 0xff,
123 (ip >> 8) & 0xff,
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200124 (ip >> 16) & 0xff,
125 (ip >> 24) & 0xff);
Thomas Horsten1f34f2e2008-06-15 02:17:11 +0100126 len = strlen(ipbuf);
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200127 if (len > *lenp)
128 len = *lenp;
129 if (len)
Thomas Horsten1f34f2e2008-06-15 02:17:11 +0100130 if (copy_to_user(buffer, ipbuf, len))
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200131 return -EFAULT;
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200132 if (len < *lenp) {
Thomas Horsten1f34f2e2008-06-15 02:17:11 +0100133 if (put_user('\n', ((char *) buffer) + len))
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200134 return -EFAULT;
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200135 len++;
136 }
137 *lenp = len;
138 *ppos += len;
139 }
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200140
141 return 0;
142}
Thomas Horsten1f34f2e2008-06-15 02:17:11 +0100143#endif
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200144
Joe Perchesd3478d52013-06-14 01:37:29 +0000145int proc_lasat_prid(struct ctl_table *table, int write,
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200146 void *buffer, size_t *lenp, loff_t *ppos)
147{
148 int r;
149
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700150 r = proc_dointvec(table, write, buffer, lenp, ppos);
Thomas Horsten1f34f2e2008-06-15 02:17:11 +0100151 if (r < 0)
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200152 return r;
Thomas Horsten1f34f2e2008-06-15 02:17:11 +0100153 if (write) {
154 lasat_board_info.li_eeprom_info.prid =
155 lasat_board_info.li_prid;
156 lasat_write_eeprom_info();
157 lasat_init_board_info();
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200158 }
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200159 return 0;
160}
161
162extern int lasat_boot_to_service;
163
Joe Perchesd3478d52013-06-14 01:37:29 +0000164static struct ctl_table lasat_table[] = {
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200165 {
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200166 .procname = "cpu-hz",
167 .data = &lasat_board_info.li_cpu_hz,
168 .maxlen = sizeof(int),
169 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800170 .proc_handler = proc_dointvec,
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200171 },
172 {
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200173 .procname = "bus-hz",
174 .data = &lasat_board_info.li_bus_hz,
175 .maxlen = sizeof(int),
176 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800177 .proc_handler = proc_dointvec,
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200178 },
179 {
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200180 .procname = "bmid",
181 .data = &lasat_board_info.li_bmid,
182 .maxlen = sizeof(int),
183 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800184 .proc_handler = proc_dointvec,
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200185 },
186 {
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200187 .procname = "prid",
188 .data = &lasat_board_info.li_prid,
189 .maxlen = sizeof(int),
190 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800191 .proc_handler = proc_lasat_prid,
Ralf Baechle606d62f2009-12-17 01:57:37 +0000192 },
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200193#ifdef CONFIG_INET
194 {
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200195 .procname = "ipaddr",
196 .data = &lasat_board_info.li_eeprom_info.ipaddr,
197 .maxlen = sizeof(int),
198 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800199 .proc_handler = proc_lasat_ip,
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200200 },
201 {
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200202 .procname = "netmask",
203 .data = &lasat_board_info.li_eeprom_info.netmask,
204 .maxlen = sizeof(int),
205 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800206 .proc_handler = proc_lasat_ip,
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200207 },
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200208#endif
209 {
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200210 .procname = "passwd_hash",
211 .data = &lasat_board_info.li_eeprom_info.passwd_hash,
212 .maxlen =
213 sizeof(lasat_board_info.li_eeprom_info.passwd_hash),
214 .mode = 0600,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800215 .proc_handler = proc_dolasatstring,
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200216 },
217 {
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200218 .procname = "boot-service",
219 .data = &lasat_boot_to_service,
220 .maxlen = sizeof(int),
221 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800222 .proc_handler = proc_dointvec,
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200223 },
224#ifdef CONFIG_DS1603
225 {
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200226 .procname = "rtc",
227 .data = &rtctmp,
228 .maxlen = sizeof(int),
229 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800230 .proc_handler = proc_dolasatrtc,
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200231 },
232#endif
233 {
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200234 .procname = "namestr",
235 .data = &lasat_board_info.li_namestr,
236 .maxlen = sizeof(lasat_board_info.li_namestr),
237 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800238 .proc_handler = proc_dostring,
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200239 },
240 {
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200241 .procname = "typestr",
242 .data = &lasat_board_info.li_typestr,
243 .maxlen = sizeof(lasat_board_info.li_typestr),
244 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800245 .proc_handler = proc_dostring,
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200246 },
247 {}
248};
249
Joe Perchesd3478d52013-06-14 01:37:29 +0000250static struct ctl_table lasat_root_table[] = {
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200251 {
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200252 .procname = "lasat",
253 .mode = 0555,
254 .child = lasat_table
255 },
256 {}
257};
258
259static int __init lasat_register_sysctl(void)
260{
261 struct ctl_table_header *lasat_table_header;
262
263 lasat_table_header =
264 register_sysctl_table(lasat_root_table);
Thomas Horsten1f34f2e2008-06-15 02:17:11 +0100265 if (!lasat_table_header) {
266 printk(KERN_ERR "Unable to register LASAT sysctl\n");
267 return -ENOMEM;
268 }
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200269
270 return 0;
271}
272
Ralf Baechle1bab0b62015-07-20 09:09:40 +0200273arch_initcall(lasat_register_sysctl);