sysctl.c 5.7 KB

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