sysctl.c 5.9 KB

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