36 #include <linux/slab.h>
38 #include <asm/uaccess.h>
42 #define SG_TABLESIZE 30
45 static long i2o_cfg_ioctl(
struct file *,
unsigned int,
unsigned long);
49 #define MODINC(x,y) ((x) = ((x) + 1) % (y))
68 static ulong i2o_cfg_info_id = 0;
70 static int i2o_cfg_getiops(
unsigned long arg)
88 static int i2o_cfg_gethrt(
unsigned long arg)
101 if (
get_user(reslen, kcmd.reslen) < 0)
104 if (kcmd.resbuf ==
NULL)
113 len = 8 + ((hrt->entry_len * hrt->num_entries) << 2);
117 else if (len > reslen)
125 static int i2o_cfg_getlct(
unsigned long arg)
138 if (
get_user(reslen, kcmd.reslen) < 0)
141 if (kcmd.resbuf ==
NULL)
153 else if (len > reslen)
161 static int i2o_cfg_parms(
unsigned long arg,
unsigned int type)
195 if (kcmd.oplen > 65536)
222 else if (len > reslen)
232 static int i2o_cfg_swdl(
unsigned long arg)
239 unsigned int status = 0, swlen = 0, fragsize = 8192;
245 if (
get_user(swlen, kxfer.swlen) < 0)
248 if (
get_user(maxfrag, kxfer.maxfrag) < 0)
251 if (
get_user(curfrag, kxfer.curfrag) < 0)
254 if (curfrag == maxfrag)
255 fragsize = swlen - (maxfrag - 1) * 8192;
288 (((
u32) maxfrag) << 8) | (((
u32) curfrag)));
294 osm_debug(
"swdl frag %d/%d (size %d)\n", curfrag, maxfrag, fragsize);
303 osm_info(
"swdl failed, DetailedStatus = %d\n", status);
310 static int i2o_cfg_swul(
unsigned long arg)
314 unsigned char maxfrag = 0,
curfrag = 1;
317 unsigned int status = 0, swlen = 0, fragsize = 8192;
324 if (
get_user(swlen, kxfer.swlen) < 0)
327 if (
get_user(maxfrag, kxfer.maxfrag) < 0)
330 if (
get_user(curfrag, kxfer.curfrag) < 0)
333 if (curfrag == maxfrag)
334 fragsize = swlen - (maxfrag - 1) * 8192;
359 sw_type << 16 | (
u32) maxfrag << 8 | (
u32) curfrag);
365 osm_debug(
"swul frag %d/%d (size %d)\n", curfrag, maxfrag, fragsize);
372 osm_info(
"swul failed, DetailedStatus = %d\n", status);
384 static int i2o_cfg_swdel(
unsigned long arg)
396 if (
get_user(swlen, kxfer.swlen) < 0)
417 token = i2o_msg_post_wait(c, msg, 10);
420 osm_info(
"swdel failed, DetailedStatus = %d\n", token);
427 static int i2o_cfg_validate(
unsigned long arg)
448 token = i2o_msg_post_wait(c, msg, 10);
451 osm_info(
"Can't validate configuration, ErrorStatus = %d\n",
459 static int i2o_cfg_evt_reg(
unsigned long arg,
struct file *
fp)
492 i2o_msg_post(c, msg);
497 static int i2o_cfg_evt_get(
unsigned long arg,
struct file *fp)
504 for (p = open_files;
p; p = p->
next)
515 kget.pending = p->
q_len;
517 spin_unlock_irqrestore(&i2o_config_lock, flags);
525 static int i2o_cfg_passthru32(
struct file *
file,
unsigned cmnd,
550 user_msg = compat_ptr(i);
554 osm_debug(
"controller %d not found\n", iop);
567 osm_warn(
"size of message > inbound_frame_size");
571 user_reply = &user_msg[
size];
582 osm_warn(
"unable to copy user message\n");
587 if (
get_user(reply_size, &user_reply[0]) < 0)
601 sg_offset = (msg->
u.
head[0] >> 4) & 0x0f;
607 if (sg_offset * 4 >= size) {
627 if (!(sg[i].flag_count & 0x10000000
630 "%s:Bad SG element %d - not simple (%x)\n",
640 "%s: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
641 c->
name, sg_size, i, sg_count);
643 goto sg_list_cleanup;
648 flag_count & 0x04000000 ) {
652 (
void __user *)(
unsigned long)sg[i].
653 addr_bus, sg_size)) {
655 "%s: Could not copy SG buf %d FROM user\n",
658 goto sg_list_cleanup;
666 rcode = i2o_msg_post_wait(c, msg, 60);
669 reply[4] = ((
u32) rcode) << 24;
670 goto sg_list_cleanup;
686 goto sg_list_cleanup;
693 goto sg_list_cleanup;
711 "%s: Could not copy %p TO user %x\n",
715 goto sg_list_cleanup;
727 "%s: Could not copy message context FROM user\n",
733 "%s: Could not copy reply TO user\n", c->
name);
737 for (i = 0; i < sg_index; i++)
748 static long i2o_cfg_compat_ioctl(
struct file *file,
unsigned cmd,
755 ret = i2o_cfg_ioctl(file, cmd, arg);
758 ret = i2o_cfg_passthru32(file, cmd, arg);
770 #ifdef CONFIG_I2O_EXT_ADAPTEC
771 static int i2o_cfg_passthru(
unsigned long arg)
796 osm_warn(
"controller %d not found\n", iop);
807 osm_warn(
"size of message > inbound_frame_size");
811 user_reply = &user_msg[
size];
824 if (
get_user(reply_size, &user_reply[0]) < 0)
838 sg_offset = (msg->
u.
head[0] >> 4) & 0x0f;
845 if (sg_offset * 4 >= size) {
867 "%s:Bad SG element %d - not simple (%x)\n",
870 goto sg_list_cleanup;
877 "%s: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
878 c->
name, sg_size, i, sg_count);
880 goto sg_list_cleanup;
891 "%s: Could not copy SG buf %d FROM user\n",
894 goto sg_list_cleanup;
901 rcode = i2o_msg_post_wait(c, msg, 60);
904 reply[4] = ((
u32) rcode) << 24;
905 goto sg_list_cleanup;
921 goto sg_list_cleanup;
928 goto sg_list_cleanup;
946 "%s: Could not copy %p TO user %x\n",
950 goto sg_list_cleanup;
962 "%s: Could not copy message context FROM user\n",
968 "%s: Could not copy reply TO user\n", c->
name);
973 for (i = 0; i < sg_index; i++)
988 static long i2o_cfg_ioctl(
struct file *fp,
unsigned int cmd,
unsigned long arg)
995 ret = i2o_cfg_getiops(arg);
999 ret = i2o_cfg_gethrt(arg);
1003 ret = i2o_cfg_getlct(arg);
1015 ret = i2o_cfg_swdl(arg);
1019 ret = i2o_cfg_swul(arg);
1023 ret = i2o_cfg_swdel(arg);
1027 ret = i2o_cfg_validate(arg);
1031 ret = i2o_cfg_evt_reg(arg, fp);
1035 ret = i2o_cfg_evt_get(arg, fp);
1038 #ifdef CONFIG_I2O_EXT_ADAPTEC
1040 ret = i2o_cfg_passthru(arg);
1052 static int cfg_open(
struct inode *
inode,
struct file *file)
1056 unsigned long flags;
1070 tmp->
next = open_files;
1074 spin_unlock_irqrestore(&i2o_config_lock, flags);
1080 static int cfg_fasync(
int fd,
struct file *fp,
int on)
1087 for (p = open_files;
p; p = p->next)
1097 static int cfg_release(
struct inode *inode,
struct file *file)
1101 unsigned long flags;
1105 for (
q = &open_files; (p = *
q) !=
NULL;
q = &p->
next) {
1106 if (p->
q_id ==
id) {
1112 spin_unlock_irqrestore(&i2o_config_lock, flags);
1121 .unlocked_ioctl = i2o_cfg_ioctl,
1122 #ifdef CONFIG_COMPAT
1123 .compat_ioctl = i2o_cfg_compat_ioctl,
1126 .release = cfg_release,
1127 .fasync = cfg_fasync,
1136 static int __init i2o_config_old_init(
void)
1141 osm_err(
"can't register device.\n");
1148 static void i2o_config_old_exit(
void)