linux/arch/mips/lasat/sysctl.c
<<
>>
Prefs
   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/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>
  32#include <linux/uaccess.h>
  33
  34#include <asm/time.h>
  35
  36#ifdef CONFIG_DS1603
  37#include "ds1603.h"
  38#endif
  39
  40/* Strategy function to write EEPROM after changing string entry */
  41int sysctl_lasatstring(ctl_table *table,
  42                void *oldval, size_t *oldlenp,
  43                void *newval, size_t newlen)
  44{
  45        int r;
  46
  47        r = sysctl_string(table, oldval, oldlenp, newval, newlen);
  48        if (r < 0)
  49                return r;
  50
  51        if (newval && newlen)
  52                lasat_write_eeprom_info();
  53
  54        return 0;
  55}
  56
  57
  58/* And the same for proc */
  59int proc_dolasatstring(ctl_table *table, int write, struct file *filp,
  60                       void *buffer, size_t *lenp, loff_t *ppos)
  61{
  62        int r;
  63
  64        r = proc_dostring(table, write, filp, buffer, lenp, ppos);
  65        if ((!write) || r)
  66                return r;
  67
  68        lasat_write_eeprom_info();
  69
  70        return 0;
  71}
  72
  73/* proc function to write EEPROM after changing int entry */
  74int proc_dolasatint(ctl_table *table, int write, struct file *filp,
  75                       void *buffer, size_t *lenp, loff_t *ppos)
  76{
  77        int r;
  78
  79        r = proc_dointvec(table, write, filp, buffer, lenp, ppos);
  80        if ((!write) || r)
  81                return r;
  82
  83        lasat_write_eeprom_info();
  84
  85        return 0;
  86}
  87
  88#ifdef CONFIG_DS1603
  89static int rtctmp;
  90
  91/* proc function to read/write RealTime Clock */
  92int proc_dolasatrtc(ctl_table *table, int write, struct file *filp,
  93                       void *buffer, size_t *lenp, loff_t *ppos)
  94{
  95        int r;
  96
  97        if (!write) {
  98                rtctmp = read_persistent_clock();
  99                /* check for time < 0 and set to 0 */
 100                if (rtctmp < 0)
 101                        rtctmp = 0;
 102        }
 103        r = proc_dointvec(table, write, filp, buffer, lenp, ppos);
 104        if (r)
 105                return r;
 106
 107        if (write)
 108                rtc_mips_set_mmss(rtctmp);
 109
 110        return 0;
 111}
 112#endif
 113
 114/* Sysctl for setting the IP addresses */
 115int sysctl_lasat_intvec(ctl_table *table,
 116                    void *oldval, size_t *oldlenp,
 117                    void *newval, size_t newlen)
 118{
 119        int r;
 120
 121        r = sysctl_intvec(table, oldval, oldlenp, newval, newlen);
 122        if (r < 0)
 123                return r;
 124
 125        if (newval && newlen)
 126                lasat_write_eeprom_info();
 127
 128        return 0;
 129}
 130
 131#ifdef CONFIG_DS1603
 132/* Same for RTC */
 133int sysctl_lasat_rtc(ctl_table *table,
 134                    void *oldval, size_t *oldlenp,
 135                    void *newval, size_t newlen)
 136{
 137        int r;
 138
 139        rtctmp = read_persistent_clock();
 140        if (rtctmp < 0)
 141                rtctmp = 0;
 142        r = sysctl_intvec(table, oldval, oldlenp, newval, newlen);
 143        if (r < 0)
 144                return r;
 145        if (newval && newlen)
 146                rtc_mips_set_mmss(rtctmp);
 147
 148        return r;
 149}
 150#endif
 151
 152#ifdef CONFIG_INET
 153int proc_lasat_ip(ctl_table *table, int write, struct file *filp,
 154                       void *buffer, size_t *lenp, loff_t *ppos)
 155{
 156        unsigned int ip;
 157        char *p, c;
 158        int len;
 159        char ipbuf[32];
 160
 161        if (!table->data || !table->maxlen || !*lenp ||
 162            (*ppos && !write)) {
 163                *lenp = 0;
 164                return 0;
 165        }
 166
 167        if (write) {
 168                len = 0;
 169                p = buffer;
 170                while (len < *lenp) {
 171                        if (get_user(c, p++))
 172                                return -EFAULT;
 173                        if (c == 0 || c == '\n')
 174                                break;
 175                        len++;
 176                }
 177                if (len >= sizeof(ipbuf)-1)
 178                        len = sizeof(ipbuf) - 1;
 179                if (copy_from_user(ipbuf, buffer, len))
 180                        return -EFAULT;
 181                ipbuf[len] = 0;
 182                *ppos += *lenp;
 183                /* Now see if we can convert it to a valid IP */
 184                ip = in_aton(ipbuf);
 185                *(unsigned int *)(table->data) = ip;
 186                lasat_write_eeprom_info();
 187        } else {
 188                ip = *(unsigned int *)(table->data);
 189                sprintf(ipbuf, "%d.%d.%d.%d",
 190                        (ip)       & 0xff,
 191                        (ip >>  8) & 0xff,
 192                        (ip >> 16) & 0xff,
 193                        (ip >> 24) & 0xff);
 194                len = strlen(ipbuf);
 195                if (len > *lenp)
 196                        len = *lenp;
 197                if (len)
 198                        if (copy_to_user(buffer, ipbuf, len))
 199                                return -EFAULT;
 200                if (len < *lenp) {
 201                        if (put_user('\n', ((char *) buffer) + len))
 202                                return -EFAULT;
 203                        len++;
 204                }
 205                *lenp = len;
 206                *ppos += len;
 207        }
 208
 209        return 0;
 210}
 211#endif
 212
 213static int sysctl_lasat_prid(ctl_table *table,
 214                                     void *oldval, size_t *oldlenp,
 215                                     void *newval, size_t newlen)
 216{
 217        int r;
 218
 219        r = sysctl_intvec(table, oldval, oldlenp, newval, newlen);
 220        if (r < 0)
 221                return r;
 222        if (newval && newlen) {
 223                lasat_board_info.li_eeprom_info.prid = *(int *)newval;
 224                lasat_write_eeprom_info();
 225                lasat_init_board_info();
 226        }
 227        return 0;
 228}
 229
 230int proc_lasat_prid(ctl_table *table, int write, struct file *filp,
 231                       void *buffer, size_t *lenp, loff_t *ppos)
 232{
 233        int r;
 234
 235        r = proc_dointvec(table, write, filp, buffer, lenp, ppos);
 236        if (r < 0)
 237                return r;
 238        if (write) {
 239                lasat_board_info.li_eeprom_info.prid =
 240                        lasat_board_info.li_prid;
 241                lasat_write_eeprom_info();
 242                lasat_init_board_info();
 243        }
 244        return 0;
 245}
 246
 247extern int lasat_boot_to_service;
 248
 249static ctl_table lasat_table[] = {
 250        {
 251                .ctl_name       = CTL_UNNUMBERED,
 252                .procname       = "cpu-hz",
 253                .data           = &lasat_board_info.li_cpu_hz,
 254                .maxlen         = sizeof(int),
 255                .mode           = 0444,
 256                .proc_handler   = &proc_dointvec,
 257                .strategy       = &sysctl_intvec
 258        },
 259        {
 260                .ctl_name       = CTL_UNNUMBERED,
 261                .procname       = "bus-hz",
 262                .data           = &lasat_board_info.li_bus_hz,
 263                .maxlen         = sizeof(int),
 264                .mode           = 0444,
 265                .proc_handler   = &proc_dointvec,
 266                .strategy       = &sysctl_intvec
 267        },
 268        {
 269                .ctl_name       = CTL_UNNUMBERED,
 270                .procname       = "bmid",
 271                .data           = &lasat_board_info.li_bmid,
 272                .maxlen         = sizeof(int),
 273                .mode           = 0444,
 274                .proc_handler   = &proc_dointvec,
 275                .strategy       = &sysctl_intvec
 276        },
 277        {
 278                .ctl_name       = CTL_UNNUMBERED,
 279                .procname       = "prid",
 280                .data           = &lasat_board_info.li_prid,
 281                .maxlen         = sizeof(int),
 282                .mode           = 0644,
 283                .proc_handler   = &proc_lasat_prid,
 284                .strategy       = &sysctl_lasat_prid
 285        },
 286#ifdef CONFIG_INET
 287        {
 288                .ctl_name       = CTL_UNNUMBERED,
 289                .procname       = "ipaddr",
 290                .data           = &lasat_board_info.li_eeprom_info.ipaddr,
 291                .maxlen         = sizeof(int),
 292                .mode           = 0644,
 293                .proc_handler   = &proc_lasat_ip,
 294                .strategy       = &sysctl_lasat_intvec
 295        },
 296        {
 297                .ctl_name       = CTL_UNNUMBERED,
 298                .procname       = "netmask",
 299                .data           = &lasat_board_info.li_eeprom_info.netmask,
 300                .maxlen         = sizeof(int),
 301                .mode           = 0644,
 302                .proc_handler   = &proc_lasat_ip,
 303                .strategy       = &sysctl_lasat_intvec
 304        },
 305#endif
 306        {
 307                .ctl_name       = CTL_UNNUMBERED,
 308                .procname       = "passwd_hash",
 309                .data           = &lasat_board_info.li_eeprom_info.passwd_hash,
 310                .maxlen         =
 311                        sizeof(lasat_board_info.li_eeprom_info.passwd_hash),
 312                .mode           = 0600,
 313                .proc_handler   = &proc_dolasatstring,
 314                .strategy       = &sysctl_lasatstring
 315        },
 316        {
 317                .ctl_name       = CTL_UNNUMBERED,
 318                .procname       = "boot-service",
 319                .data           = &lasat_boot_to_service,
 320                .maxlen         = sizeof(int),
 321                .mode           = 0644,
 322                .proc_handler   = &proc_dointvec,
 323                .strategy       = &sysctl_intvec
 324        },
 325#ifdef CONFIG_DS1603
 326        {
 327                .ctl_name       = CTL_UNNUMBERED,
 328                .procname       = "rtc",
 329                .data           = &rtctmp,
 330                .maxlen         = sizeof(int),
 331                .mode           = 0644,
 332                .proc_handler   = &proc_dolasatrtc,
 333                .strategy       = &sysctl_lasat_rtc
 334        },
 335#endif
 336        {
 337                .ctl_name       = CTL_UNNUMBERED,
 338                .procname       = "namestr",
 339                .data           = &lasat_board_info.li_namestr,
 340                .maxlen         = sizeof(lasat_board_info.li_namestr),
 341                .mode           = 0444,
 342                .proc_handler   = &proc_dostring,
 343                .strategy       = &sysctl_string
 344        },
 345        {
 346                .ctl_name       = CTL_UNNUMBERED,
 347                .procname       = "typestr",
 348                .data           = &lasat_board_info.li_typestr,
 349                .maxlen         = sizeof(lasat_board_info.li_typestr),
 350                .mode           = 0444,
 351                .proc_handler   = &proc_dostring,
 352                .strategy       = &sysctl_string
 353        },
 354        {}
 355};
 356
 357static ctl_table lasat_root_table[] = {
 358        {
 359                .ctl_name       = CTL_UNNUMBERED,
 360                .procname       = "lasat",
 361                .mode           =  0555,
 362                .child          = lasat_table
 363        },
 364        {}
 365};
 366
 367static int __init lasat_register_sysctl(void)
 368{
 369        struct ctl_table_header *lasat_table_header;
 370
 371        lasat_table_header =
 372                register_sysctl_table(lasat_root_table);
 373        if (!lasat_table_header) {
 374                printk(KERN_ERR "Unable to register LASAT sysctl\n");
 375                return -ENOMEM;
 376        }
 377
 378        return 0;
 379}
 380
 381__initcall(lasat_register_sysctl);
 382
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.