Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 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 | |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 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> |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 31 | #include <linux/uaccess.h> |
| 32 | |
Ralf Baechle | 4b55048 | 2007-10-11 23:46:08 +0100 | [diff] [blame] | 33 | #include <asm/time.h> |
| 34 | |
Thomas Horsten | 1f34f2e | 2008-06-15 02:17:11 +0100 | [diff] [blame] | 35 | #ifdef CONFIG_DS1603 |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 36 | #include "ds1603.h" |
Thomas Horsten | 1f34f2e | 2008-06-15 02:17:11 +0100 | [diff] [blame] | 37 | #endif |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 38 | |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 39 | |
| 40 | /* And the same for proc */ |
Joe Perches | d3478d5 | 2013-06-14 01:37:29 +0000 | [diff] [blame] | 41 | int proc_dolasatstring(struct ctl_table *table, int write, |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 42 | void *buffer, size_t *lenp, loff_t *ppos) |
| 43 | { |
| 44 | int r; |
| 45 | |
Alexey Dobriyan | 8d65af7 | 2009-09-23 15:57:19 -0700 | [diff] [blame] | 46 | r = proc_dostring(table, write, buffer, lenp, ppos); |
Thomas Horsten | 1f34f2e | 2008-06-15 02:17:11 +0100 | [diff] [blame] | 47 | if ((!write) || r) |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 48 | return r; |
Thomas Horsten | 1f34f2e | 2008-06-15 02:17:11 +0100 | [diff] [blame] | 49 | |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 50 | lasat_write_eeprom_info(); |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 51 | |
| 52 | return 0; |
| 53 | } |
| 54 | |
Thomas Horsten | 1f34f2e | 2008-06-15 02:17:11 +0100 | [diff] [blame] | 55 | #ifdef CONFIG_DS1603 |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 56 | static int rtctmp; |
| 57 | |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 58 | /* proc function to read/write RealTime Clock */ |
Joe Perches | d3478d5 | 2013-06-14 01:37:29 +0000 | [diff] [blame] | 59 | int proc_dolasatrtc(struct ctl_table *table, int write, |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 60 | void *buffer, size_t *lenp, loff_t *ppos) |
| 61 | { |
Xunlei Pang | 2ee9663 | 2015-04-01 20:34:22 -0700 | [diff] [blame] | 62 | struct timespec64 ts; |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 63 | int r; |
| 64 | |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 65 | if (!write) { |
Xunlei Pang | 2ee9663 | 2015-04-01 20:34:22 -0700 | [diff] [blame] | 66 | read_persistent_clock64(&ts); |
Martin Schwidefsky | d4f587c | 2009-08-14 15:47:31 +0200 | [diff] [blame] | 67 | rtctmp = ts.tv_sec; |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 68 | /* check for time < 0 and set to 0 */ |
| 69 | if (rtctmp < 0) |
| 70 | rtctmp = 0; |
| 71 | } |
Alexey Dobriyan | 8d65af7 | 2009-09-23 15:57:19 -0700 | [diff] [blame] | 72 | r = proc_dointvec(table, write, buffer, lenp, ppos); |
Thomas Horsten | 1f34f2e | 2008-06-15 02:17:11 +0100 | [diff] [blame] | 73 | if (r) |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 74 | return r; |
Thomas Horsten | 1f34f2e | 2008-06-15 02:17:11 +0100 | [diff] [blame] | 75 | |
| 76 | if (write) |
| 77 | rtc_mips_set_mmss(rtctmp); |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 78 | |
| 79 | return 0; |
| 80 | } |
| 81 | #endif |
| 82 | |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 83 | #ifdef CONFIG_INET |
Joe Perches | d3478d5 | 2013-06-14 01:37:29 +0000 | [diff] [blame] | 84 | int proc_lasat_ip(struct ctl_table *table, int write, |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 85 | void *buffer, size_t *lenp, loff_t *ppos) |
| 86 | { |
| 87 | unsigned int ip; |
| 88 | char *p, c; |
| 89 | int len; |
Thomas Horsten | 1f34f2e | 2008-06-15 02:17:11 +0100 | [diff] [blame] | 90 | char ipbuf[32]; |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 91 | |
| 92 | if (!table->data || !table->maxlen || !*lenp || |
| 93 | (*ppos && !write)) { |
| 94 | *lenp = 0; |
| 95 | return 0; |
| 96 | } |
| 97 | |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 98 | if (write) { |
| 99 | len = 0; |
| 100 | p = buffer; |
| 101 | while (len < *lenp) { |
Thomas Horsten | 1f34f2e | 2008-06-15 02:17:11 +0100 | [diff] [blame] | 102 | if (get_user(c, p++)) |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 103 | return -EFAULT; |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 104 | if (c == 0 || c == '\n') |
| 105 | break; |
| 106 | len++; |
| 107 | } |
Thomas Horsten | 1f34f2e | 2008-06-15 02:17:11 +0100 | [diff] [blame] | 108 | if (len >= sizeof(ipbuf)-1) |
| 109 | len = sizeof(ipbuf) - 1; |
| 110 | if (copy_from_user(ipbuf, buffer, len)) |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 111 | return -EFAULT; |
Thomas Horsten | 1f34f2e | 2008-06-15 02:17:11 +0100 | [diff] [blame] | 112 | ipbuf[len] = 0; |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 113 | *ppos += *lenp; |
| 114 | /* Now see if we can convert it to a valid IP */ |
Thomas Horsten | 1f34f2e | 2008-06-15 02:17:11 +0100 | [diff] [blame] | 115 | ip = in_aton(ipbuf); |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 116 | *(unsigned int *)(table->data) = ip; |
| 117 | lasat_write_eeprom_info(); |
| 118 | } else { |
| 119 | ip = *(unsigned int *)(table->data); |
Thomas Horsten | 1f34f2e | 2008-06-15 02:17:11 +0100 | [diff] [blame] | 120 | sprintf(ipbuf, "%d.%d.%d.%d", |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 121 | (ip) & 0xff, |
| 122 | (ip >> 8) & 0xff, |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 123 | (ip >> 16) & 0xff, |
| 124 | (ip >> 24) & 0xff); |
Thomas Horsten | 1f34f2e | 2008-06-15 02:17:11 +0100 | [diff] [blame] | 125 | len = strlen(ipbuf); |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 126 | if (len > *lenp) |
| 127 | len = *lenp; |
| 128 | if (len) |
Thomas Horsten | 1f34f2e | 2008-06-15 02:17:11 +0100 | [diff] [blame] | 129 | if (copy_to_user(buffer, ipbuf, len)) |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 130 | return -EFAULT; |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 131 | if (len < *lenp) { |
Thomas Horsten | 1f34f2e | 2008-06-15 02:17:11 +0100 | [diff] [blame] | 132 | if (put_user('\n', ((char *) buffer) + len)) |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 133 | return -EFAULT; |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 134 | len++; |
| 135 | } |
| 136 | *lenp = len; |
| 137 | *ppos += len; |
| 138 | } |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 139 | |
| 140 | return 0; |
| 141 | } |
Thomas Horsten | 1f34f2e | 2008-06-15 02:17:11 +0100 | [diff] [blame] | 142 | #endif |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 143 | |
Joe Perches | d3478d5 | 2013-06-14 01:37:29 +0000 | [diff] [blame] | 144 | int proc_lasat_prid(struct ctl_table *table, int write, |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 145 | void *buffer, size_t *lenp, loff_t *ppos) |
| 146 | { |
| 147 | int r; |
| 148 | |
Alexey Dobriyan | 8d65af7 | 2009-09-23 15:57:19 -0700 | [diff] [blame] | 149 | r = proc_dointvec(table, write, buffer, lenp, ppos); |
Thomas Horsten | 1f34f2e | 2008-06-15 02:17:11 +0100 | [diff] [blame] | 150 | if (r < 0) |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 151 | return r; |
Thomas Horsten | 1f34f2e | 2008-06-15 02:17:11 +0100 | [diff] [blame] | 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(); |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 157 | } |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 158 | return 0; |
| 159 | } |
| 160 | |
| 161 | extern int lasat_boot_to_service; |
| 162 | |
Joe Perches | d3478d5 | 2013-06-14 01:37:29 +0000 | [diff] [blame] | 163 | static struct ctl_table lasat_table[] = { |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 164 | { |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 165 | .procname = "cpu-hz", |
| 166 | .data = &lasat_board_info.li_cpu_hz, |
| 167 | .maxlen = sizeof(int), |
| 168 | .mode = 0444, |
Eric W. Biederman | 6d45611 | 2009-11-16 03:11:48 -0800 | [diff] [blame] | 169 | .proc_handler = proc_dointvec, |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 170 | }, |
| 171 | { |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 172 | .procname = "bus-hz", |
| 173 | .data = &lasat_board_info.li_bus_hz, |
| 174 | .maxlen = sizeof(int), |
| 175 | .mode = 0444, |
Eric W. Biederman | 6d45611 | 2009-11-16 03:11:48 -0800 | [diff] [blame] | 176 | .proc_handler = proc_dointvec, |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 177 | }, |
| 178 | { |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 179 | .procname = "bmid", |
| 180 | .data = &lasat_board_info.li_bmid, |
| 181 | .maxlen = sizeof(int), |
| 182 | .mode = 0444, |
Eric W. Biederman | 6d45611 | 2009-11-16 03:11:48 -0800 | [diff] [blame] | 183 | .proc_handler = proc_dointvec, |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 184 | }, |
| 185 | { |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 186 | .procname = "prid", |
| 187 | .data = &lasat_board_info.li_prid, |
| 188 | .maxlen = sizeof(int), |
| 189 | .mode = 0644, |
Eric W. Biederman | 6d45611 | 2009-11-16 03:11:48 -0800 | [diff] [blame] | 190 | .proc_handler = proc_lasat_prid, |
Ralf Baechle | 606d62f | 2009-12-17 01:57:37 +0000 | [diff] [blame] | 191 | }, |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 192 | #ifdef CONFIG_INET |
| 193 | { |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 194 | .procname = "ipaddr", |
| 195 | .data = &lasat_board_info.li_eeprom_info.ipaddr, |
| 196 | .maxlen = sizeof(int), |
| 197 | .mode = 0644, |
Eric W. Biederman | 6d45611 | 2009-11-16 03:11:48 -0800 | [diff] [blame] | 198 | .proc_handler = proc_lasat_ip, |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 199 | }, |
| 200 | { |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 201 | .procname = "netmask", |
| 202 | .data = &lasat_board_info.li_eeprom_info.netmask, |
| 203 | .maxlen = sizeof(int), |
| 204 | .mode = 0644, |
Eric W. Biederman | 6d45611 | 2009-11-16 03:11:48 -0800 | [diff] [blame] | 205 | .proc_handler = proc_lasat_ip, |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 206 | }, |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 207 | #endif |
| 208 | { |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 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, |
Eric W. Biederman | 6d45611 | 2009-11-16 03:11:48 -0800 | [diff] [blame] | 214 | .proc_handler = proc_dolasatstring, |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 215 | }, |
| 216 | { |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 217 | .procname = "boot-service", |
| 218 | .data = &lasat_boot_to_service, |
| 219 | .maxlen = sizeof(int), |
| 220 | .mode = 0644, |
Eric W. Biederman | 6d45611 | 2009-11-16 03:11:48 -0800 | [diff] [blame] | 221 | .proc_handler = proc_dointvec, |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 222 | }, |
| 223 | #ifdef CONFIG_DS1603 |
| 224 | { |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 225 | .procname = "rtc", |
| 226 | .data = &rtctmp, |
| 227 | .maxlen = sizeof(int), |
| 228 | .mode = 0644, |
Eric W. Biederman | 6d45611 | 2009-11-16 03:11:48 -0800 | [diff] [blame] | 229 | .proc_handler = proc_dolasatrtc, |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 230 | }, |
| 231 | #endif |
| 232 | { |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 233 | .procname = "namestr", |
| 234 | .data = &lasat_board_info.li_namestr, |
| 235 | .maxlen = sizeof(lasat_board_info.li_namestr), |
| 236 | .mode = 0444, |
Eric W. Biederman | 6d45611 | 2009-11-16 03:11:48 -0800 | [diff] [blame] | 237 | .proc_handler = proc_dostring, |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 238 | }, |
| 239 | { |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 240 | .procname = "typestr", |
| 241 | .data = &lasat_board_info.li_typestr, |
| 242 | .maxlen = sizeof(lasat_board_info.li_typestr), |
| 243 | .mode = 0444, |
Eric W. Biederman | 6d45611 | 2009-11-16 03:11:48 -0800 | [diff] [blame] | 244 | .proc_handler = proc_dostring, |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 245 | }, |
| 246 | {} |
| 247 | }; |
| 248 | |
Joe Perches | d3478d5 | 2013-06-14 01:37:29 +0000 | [diff] [blame] | 249 | static struct ctl_table lasat_root_table[] = { |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 250 | { |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 251 | .procname = "lasat", |
| 252 | .mode = 0555, |
| 253 | .child = lasat_table |
| 254 | }, |
| 255 | {} |
| 256 | }; |
| 257 | |
| 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); |
Thomas Horsten | 1f34f2e | 2008-06-15 02:17:11 +0100 | [diff] [blame] | 264 | if (!lasat_table_header) { |
| 265 | printk(KERN_ERR "Unable to register LASAT sysctl\n"); |
| 266 | return -ENOMEM; |
| 267 | } |
Brian Murphy | 1f21d2b | 2007-08-21 22:34:16 +0200 | [diff] [blame] | 268 | |
| 269 | return 0; |
| 270 | } |
| 271 | |
Ralf Baechle | 1bab0b6 | 2015-07-20 09:09:40 +0200 | [diff] [blame] | 272 | arch_initcall(lasat_register_sysctl); |