2007-08-21 20:34:16 +00:00
|
|
|
/*
|
|
|
|
* Thomas Horsten <thh@lasat.com>
|
|
|
|
* Copyright (C) 2000 LASAT Networks A/S.
|
|
|
|
*
|
|
|
|
* This program is free software; you can distribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License (Version 2) as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* Routines specific to the LASAT boards
|
|
|
|
*/
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <asm/lasat/lasat.h>
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/sysctl.h>
|
|
|
|
#include <linux/stddef.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/ctype.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/net.h>
|
|
|
|
#include <linux/inet.h>
|
|
|
|
#include <linux/uaccess.h>
|
|
|
|
|
2007-10-11 22:46:08 +00:00
|
|
|
#include <asm/time.h>
|
|
|
|
|
2008-06-15 01:17:11 +00:00
|
|
|
#ifdef CONFIG_DS1603
|
2007-08-21 20:34:16 +00:00
|
|
|
#include "ds1603.h"
|
2008-06-15 01:17:11 +00:00
|
|
|
#endif
|
2007-08-21 20:34:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* And the same for proc */
|
2009-09-23 22:57:19 +00:00
|
|
|
int proc_dolasatstring(ctl_table *table, int write,
|
2007-08-21 20:34:16 +00:00
|
|
|
void *buffer, size_t *lenp, loff_t *ppos)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
|
2009-09-23 22:57:19 +00:00
|
|
|
r = proc_dostring(table, write, buffer, lenp, ppos);
|
2008-06-15 01:17:11 +00:00
|
|
|
if ((!write) || r)
|
2007-08-21 20:34:16 +00:00
|
|
|
return r;
|
2008-06-15 01:17:11 +00:00
|
|
|
|
2007-08-21 20:34:16 +00:00
|
|
|
lasat_write_eeprom_info();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* proc function to write EEPROM after changing int entry */
|
2009-09-23 22:57:19 +00:00
|
|
|
int proc_dolasatint(ctl_table *table, int write,
|
2007-08-21 20:34:16 +00:00
|
|
|
void *buffer, size_t *lenp, loff_t *ppos)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
|
2009-09-23 22:57:19 +00:00
|
|
|
r = proc_dointvec(table, write, buffer, lenp, ppos);
|
2008-06-15 01:17:11 +00:00
|
|
|
if ((!write) || r)
|
2007-08-21 20:34:16 +00:00
|
|
|
return r;
|
2008-06-15 01:17:11 +00:00
|
|
|
|
2007-08-21 20:34:16 +00:00
|
|
|
lasat_write_eeprom_info();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-06-15 01:17:11 +00:00
|
|
|
#ifdef CONFIG_DS1603
|
2007-08-21 20:34:16 +00:00
|
|
|
static int rtctmp;
|
|
|
|
|
|
|
|
/* proc function to read/write RealTime Clock */
|
2009-09-23 22:57:19 +00:00
|
|
|
int proc_dolasatrtc(ctl_table *table, int write,
|
2007-08-21 20:34:16 +00:00
|
|
|
void *buffer, size_t *lenp, loff_t *ppos)
|
|
|
|
{
|
2009-08-14 13:47:31 +00:00
|
|
|
struct timespec ts;
|
2007-08-21 20:34:16 +00:00
|
|
|
int r;
|
|
|
|
|
|
|
|
if (!write) {
|
2009-08-14 13:47:31 +00:00
|
|
|
read_persistent_clock(&ts);
|
|
|
|
rtctmp = ts.tv_sec;
|
2007-08-21 20:34:16 +00:00
|
|
|
/* check for time < 0 and set to 0 */
|
|
|
|
if (rtctmp < 0)
|
|
|
|
rtctmp = 0;
|
|
|
|
}
|
2009-09-23 22:57:19 +00:00
|
|
|
r = proc_dointvec(table, write, buffer, lenp, ppos);
|
2008-06-15 01:17:11 +00:00
|
|
|
if (r)
|
2007-08-21 20:34:16 +00:00
|
|
|
return r;
|
2008-06-15 01:17:11 +00:00
|
|
|
|
|
|
|
if (write)
|
|
|
|
rtc_mips_set_mmss(rtctmp);
|
2007-08-21 20:34:16 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_INET
|
2009-09-23 22:57:19 +00:00
|
|
|
int proc_lasat_ip(ctl_table *table, int write,
|
2007-08-21 20:34:16 +00:00
|
|
|
void *buffer, size_t *lenp, loff_t *ppos)
|
|
|
|
{
|
|
|
|
unsigned int ip;
|
|
|
|
char *p, c;
|
|
|
|
int len;
|
2008-06-15 01:17:11 +00:00
|
|
|
char ipbuf[32];
|
2007-08-21 20:34:16 +00:00
|
|
|
|
|
|
|
if (!table->data || !table->maxlen || !*lenp ||
|
|
|
|
(*ppos && !write)) {
|
|
|
|
*lenp = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (write) {
|
|
|
|
len = 0;
|
|
|
|
p = buffer;
|
|
|
|
while (len < *lenp) {
|
2008-06-15 01:17:11 +00:00
|
|
|
if (get_user(c, p++))
|
2007-08-21 20:34:16 +00:00
|
|
|
return -EFAULT;
|
|
|
|
if (c == 0 || c == '\n')
|
|
|
|
break;
|
|
|
|
len++;
|
|
|
|
}
|
2008-06-15 01:17:11 +00:00
|
|
|
if (len >= sizeof(ipbuf)-1)
|
|
|
|
len = sizeof(ipbuf) - 1;
|
|
|
|
if (copy_from_user(ipbuf, buffer, len))
|
2007-08-21 20:34:16 +00:00
|
|
|
return -EFAULT;
|
2008-06-15 01:17:11 +00:00
|
|
|
ipbuf[len] = 0;
|
2007-08-21 20:34:16 +00:00
|
|
|
*ppos += *lenp;
|
|
|
|
/* Now see if we can convert it to a valid IP */
|
2008-06-15 01:17:11 +00:00
|
|
|
ip = in_aton(ipbuf);
|
2007-08-21 20:34:16 +00:00
|
|
|
*(unsigned int *)(table->data) = ip;
|
|
|
|
lasat_write_eeprom_info();
|
|
|
|
} else {
|
|
|
|
ip = *(unsigned int *)(table->data);
|
2008-06-15 01:17:11 +00:00
|
|
|
sprintf(ipbuf, "%d.%d.%d.%d",
|
2007-08-21 20:34:16 +00:00
|
|
|
(ip) & 0xff,
|
|
|
|
(ip >> 8) & 0xff,
|
|
|
|
(ip >> 16) & 0xff,
|
|
|
|
(ip >> 24) & 0xff);
|
2008-06-15 01:17:11 +00:00
|
|
|
len = strlen(ipbuf);
|
2007-08-21 20:34:16 +00:00
|
|
|
if (len > *lenp)
|
|
|
|
len = *lenp;
|
|
|
|
if (len)
|
2008-06-15 01:17:11 +00:00
|
|
|
if (copy_to_user(buffer, ipbuf, len))
|
2007-08-21 20:34:16 +00:00
|
|
|
return -EFAULT;
|
|
|
|
if (len < *lenp) {
|
2008-06-15 01:17:11 +00:00
|
|
|
if (put_user('\n', ((char *) buffer) + len))
|
2007-08-21 20:34:16 +00:00
|
|
|
return -EFAULT;
|
|
|
|
len++;
|
|
|
|
}
|
|
|
|
*lenp = len;
|
|
|
|
*ppos += len;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2008-06-15 01:17:11 +00:00
|
|
|
#endif
|
2007-08-21 20:34:16 +00:00
|
|
|
|
2009-09-23 22:57:19 +00:00
|
|
|
int proc_lasat_prid(ctl_table *table, int write,
|
2007-08-21 20:34:16 +00:00
|
|
|
void *buffer, size_t *lenp, loff_t *ppos)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
|
2009-09-23 22:57:19 +00:00
|
|
|
r = proc_dointvec(table, write, buffer, lenp, ppos);
|
2008-06-15 01:17:11 +00:00
|
|
|
if (r < 0)
|
2007-08-21 20:34:16 +00:00
|
|
|
return r;
|
2008-06-15 01:17:11 +00:00
|
|
|
if (write) {
|
|
|
|
lasat_board_info.li_eeprom_info.prid =
|
|
|
|
lasat_board_info.li_prid;
|
|
|
|
lasat_write_eeprom_info();
|
|
|
|
lasat_init_board_info();
|
2007-08-21 20:34:16 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern int lasat_boot_to_service;
|
|
|
|
|
|
|
|
static ctl_table lasat_table[] = {
|
|
|
|
{
|
|
|
|
.procname = "cpu-hz",
|
|
|
|
.data = &lasat_board_info.li_cpu_hz,
|
|
|
|
.maxlen = sizeof(int),
|
|
|
|
.mode = 0444,
|
2009-11-16 11:11:48 +00:00
|
|
|
.proc_handler = proc_dointvec,
|
2007-08-21 20:34:16 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.procname = "bus-hz",
|
|
|
|
.data = &lasat_board_info.li_bus_hz,
|
|
|
|
.maxlen = sizeof(int),
|
|
|
|
.mode = 0444,
|
2009-11-16 11:11:48 +00:00
|
|
|
.proc_handler = proc_dointvec,
|
2007-08-21 20:34:16 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.procname = "bmid",
|
|
|
|
.data = &lasat_board_info.li_bmid,
|
|
|
|
.maxlen = sizeof(int),
|
|
|
|
.mode = 0444,
|
2009-11-16 11:11:48 +00:00
|
|
|
.proc_handler = proc_dointvec,
|
2007-08-21 20:34:16 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.procname = "prid",
|
|
|
|
.data = &lasat_board_info.li_prid,
|
|
|
|
.maxlen = sizeof(int),
|
|
|
|
.mode = 0644,
|
2009-11-16 11:11:48 +00:00
|
|
|
.proc_handler = proc_lasat_prid,
|
2009-12-17 01:57:37 +00:00
|
|
|
},
|
2007-08-21 20:34:16 +00:00
|
|
|
#ifdef CONFIG_INET
|
|
|
|
{
|
|
|
|
.procname = "ipaddr",
|
|
|
|
.data = &lasat_board_info.li_eeprom_info.ipaddr,
|
|
|
|
.maxlen = sizeof(int),
|
|
|
|
.mode = 0644,
|
2009-11-16 11:11:48 +00:00
|
|
|
.proc_handler = proc_lasat_ip,
|
2007-08-21 20:34:16 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.procname = "netmask",
|
|
|
|
.data = &lasat_board_info.li_eeprom_info.netmask,
|
|
|
|
.maxlen = sizeof(int),
|
|
|
|
.mode = 0644,
|
2009-11-16 11:11:48 +00:00
|
|
|
.proc_handler = proc_lasat_ip,
|
2007-08-21 20:34:16 +00:00
|
|
|
},
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
.procname = "passwd_hash",
|
|
|
|
.data = &lasat_board_info.li_eeprom_info.passwd_hash,
|
|
|
|
.maxlen =
|
|
|
|
sizeof(lasat_board_info.li_eeprom_info.passwd_hash),
|
|
|
|
.mode = 0600,
|
2009-11-16 11:11:48 +00:00
|
|
|
.proc_handler = proc_dolasatstring,
|
2007-08-21 20:34:16 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.procname = "boot-service",
|
|
|
|
.data = &lasat_boot_to_service,
|
|
|
|
.maxlen = sizeof(int),
|
|
|
|
.mode = 0644,
|
2009-11-16 11:11:48 +00:00
|
|
|
.proc_handler = proc_dointvec,
|
2007-08-21 20:34:16 +00:00
|
|
|
},
|
|
|
|
#ifdef CONFIG_DS1603
|
|
|
|
{
|
|
|
|
.procname = "rtc",
|
|
|
|
.data = &rtctmp,
|
|
|
|
.maxlen = sizeof(int),
|
|
|
|
.mode = 0644,
|
2009-11-16 11:11:48 +00:00
|
|
|
.proc_handler = proc_dolasatrtc,
|
2007-08-21 20:34:16 +00:00
|
|
|
},
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
.procname = "namestr",
|
|
|
|
.data = &lasat_board_info.li_namestr,
|
|
|
|
.maxlen = sizeof(lasat_board_info.li_namestr),
|
|
|
|
.mode = 0444,
|
2009-11-16 11:11:48 +00:00
|
|
|
.proc_handler = proc_dostring,
|
2007-08-21 20:34:16 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.procname = "typestr",
|
|
|
|
.data = &lasat_board_info.li_typestr,
|
|
|
|
.maxlen = sizeof(lasat_board_info.li_typestr),
|
|
|
|
.mode = 0444,
|
2009-11-16 11:11:48 +00:00
|
|
|
.proc_handler = proc_dostring,
|
2007-08-21 20:34:16 +00:00
|
|
|
},
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
static ctl_table lasat_root_table[] = {
|
|
|
|
{
|
|
|
|
.procname = "lasat",
|
|
|
|
.mode = 0555,
|
|
|
|
.child = lasat_table
|
|
|
|
},
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init lasat_register_sysctl(void)
|
|
|
|
{
|
|
|
|
struct ctl_table_header *lasat_table_header;
|
|
|
|
|
|
|
|
lasat_table_header =
|
|
|
|
register_sysctl_table(lasat_root_table);
|
2008-06-15 01:17:11 +00:00
|
|
|
if (!lasat_table_header) {
|
|
|
|
printk(KERN_ERR "Unable to register LASAT sysctl\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2007-08-21 20:34:16 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
__initcall(lasat_register_sysctl);
|