2 * I2O Configuration Interface Driver
4 * (C) Copyright 1999-2002 Red Hat
6 * Written by Alan Cox, Building Number Three Ltd
9 * Deepak Saxena (04/20/1999):
10 * Added basic ioctl() support
11 * Deepak Saxena (06/07/1999):
12 * Added software download ioctl (still testing)
13 * Auvo Häkkinen (09/10/1999):
14 * Changes to i2o_cfg_reply(), ioctl_parms()
15 * Added ioct_validate()
16 * Taneli Vähäkangas (09/30/1999):
18 * Taneli Vähäkangas (10/04/1999):
19 * Changed ioctl_swdl(), implemented ioctl_swul() and ioctl_swdel()
20 * Deepak Saxena (11/18/1999):
21 * Added event managmenet support
22 * Alan Cox <alan@lxorguk.ukuu.org.uk>:
23 * 2.4 rewrite ported to 2.5
24 * Markus Lidel <Markus.Lidel@shadowconnect.com>:
25 * Added pass-thru support for Adaptec's raidutils
27 * This program is free software; you can redistribute it and/or
28 * modify it under the terms of the GNU General Public License
29 * as published by the Free Software Foundation; either version
30 * 2 of the License, or (at your option) any later version.
33 #include <linux/miscdevice.h>
34 #include <linux/smp_lock.h>
35 #include <linux/compat.h>
36 #include <linux/slab.h>
38 #include <asm/uaccess.h>
42 #define SG_TABLESIZE 30
44 static long i2o_cfg_ioctl(struct file *, unsigned int, unsigned long);
46 static spinlock_t i2o_config_lock;
48 #define MODINC(x,y) ((x) = ((x) + 1) % (y))
50 struct sg_simple_element {
57 struct fasync_struct *fasync;
58 struct i2o_evt_info event_q[I2O_EVT_Q_LEN];
59 u16 q_in; // Queue head index
60 u16 q_out; // Queue tail index
61 u16 q_len; // Queue length
62 u16 q_lost; // Number of lost events
63 ulong q_id; // Event queue ID...used as tx_context
64 struct i2o_cfg_info *next;
66 static struct i2o_cfg_info *open_files = NULL;
67 static ulong i2o_cfg_info_id = 0;
69 static int i2o_cfg_getiops(unsigned long arg)
71 struct i2o_controller *c;
72 u8 __user *user_iop_table = (void __user *)arg;
73 u8 tmp[MAX_I2O_CONTROLLERS];
76 memset(tmp, 0, MAX_I2O_CONTROLLERS);
78 list_for_each_entry(c, &i2o_controllers, list)
81 if (copy_to_user(user_iop_table, tmp, MAX_I2O_CONTROLLERS))
87 static int i2o_cfg_gethrt(unsigned long arg)
89 struct i2o_controller *c;
90 struct i2o_cmd_hrtlct __user *cmd = (struct i2o_cmd_hrtlct __user *)arg;
91 struct i2o_cmd_hrtlct kcmd;
97 if (copy_from_user(&kcmd, cmd, sizeof(struct i2o_cmd_hrtlct)))
100 if (get_user(reslen, kcmd.reslen) < 0)
103 if (kcmd.resbuf == NULL)
106 c = i2o_find_iop(kcmd.iop);
110 hrt = (i2o_hrt *) c->hrt.virt;
112 len = 8 + ((hrt->entry_len * hrt->num_entries) << 2);
114 /* We did a get user...so assuming mem is ok...is this bad? */
115 put_user(len, kcmd.reslen);
118 if (copy_to_user(kcmd.resbuf, (void *)hrt, len))
124 static int i2o_cfg_getlct(unsigned long arg)
126 struct i2o_controller *c;
127 struct i2o_cmd_hrtlct __user *cmd = (struct i2o_cmd_hrtlct __user *)arg;
128 struct i2o_cmd_hrtlct kcmd;
134 if (copy_from_user(&kcmd, cmd, sizeof(struct i2o_cmd_hrtlct)))
137 if (get_user(reslen, kcmd.reslen) < 0)
140 if (kcmd.resbuf == NULL)
143 c = i2o_find_iop(kcmd.iop);
147 lct = (i2o_lct *) c->lct;
149 len = (unsigned int)lct->table_size << 2;
150 put_user(len, kcmd.reslen);
153 else if (copy_to_user(kcmd.resbuf, lct, len))
159 static int i2o_cfg_parms(unsigned long arg, unsigned int type)
162 struct i2o_controller *c;
163 struct i2o_device *dev;
164 struct i2o_cmd_psetget __user *cmd =
165 (struct i2o_cmd_psetget __user *)arg;
166 struct i2o_cmd_psetget kcmd;
172 u32 i2o_cmd = (type == I2OPARMGET ?
173 I2O_CMD_UTIL_PARAMS_GET : I2O_CMD_UTIL_PARAMS_SET);
175 if (copy_from_user(&kcmd, cmd, sizeof(struct i2o_cmd_psetget)))
178 if (get_user(reslen, kcmd.reslen))
181 c = i2o_find_iop(kcmd.iop);
185 dev = i2o_iop_find_device(c, kcmd.tid);
189 ops = kmalloc(kcmd.oplen, GFP_KERNEL);
193 if (copy_from_user(ops, kcmd.opbuf, kcmd.oplen)) {
199 * It's possible to have a _very_ large table
200 * and that the user asks for all of it at once...
202 res = kmalloc(65536, GFP_KERNEL);
208 len = i2o_parm_issue(dev, i2o_cmd, ops, kcmd.oplen, res, 65536);
216 put_user(len, kcmd.reslen);
219 else if (copy_to_user(kcmd.resbuf, res, len))
227 static int i2o_cfg_swdl(unsigned long arg)
229 struct i2o_sw_xfer kxfer;
230 struct i2o_sw_xfer __user *pxfer = (struct i2o_sw_xfer __user *)arg;
231 unsigned char maxfrag = 0, curfrag = 1;
232 struct i2o_dma buffer;
233 struct i2o_message *msg;
234 unsigned int status = 0, swlen = 0, fragsize = 8192;
235 struct i2o_controller *c;
237 if (copy_from_user(&kxfer, pxfer, sizeof(struct i2o_sw_xfer)))
240 if (get_user(swlen, kxfer.swlen) < 0)
243 if (get_user(maxfrag, kxfer.maxfrag) < 0)
246 if (get_user(curfrag, kxfer.curfrag) < 0)
249 if (curfrag == maxfrag)
250 fragsize = swlen - (maxfrag - 1) * 8192;
252 if (!kxfer.buf || !access_ok(VERIFY_READ, kxfer.buf, fragsize))
255 c = i2o_find_iop(kxfer.iop);
259 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
263 if (i2o_dma_alloc(&c->pdev->dev, &buffer, fragsize)) {
268 if (__copy_from_user(buffer.virt, kxfer.buf, fragsize)) {
270 i2o_dma_free(&c->pdev->dev, &buffer);
274 msg->u.head[0] = cpu_to_le32(NINE_WORD_MSG_SIZE | SGL_OFFSET_7);
276 cpu_to_le32(I2O_CMD_SW_DOWNLOAD << 24 | HOST_TID << 12 |
278 msg->u.head[2] = cpu_to_le32(i2o_config_driver.context);
279 msg->u.head[3] = cpu_to_le32(0);
281 cpu_to_le32((((u32) kxfer.flags) << 24) | (((u32) kxfer.
283 (((u32) maxfrag) << 8) | (((u32) curfrag)));
284 msg->body[1] = cpu_to_le32(swlen);
285 msg->body[2] = cpu_to_le32(kxfer.sw_id);
286 msg->body[3] = cpu_to_le32(0xD0000000 | fragsize);
287 msg->body[4] = cpu_to_le32(buffer.phys);
289 osm_debug("swdl frag %d/%d (size %d)\n", curfrag, maxfrag, fragsize);
290 status = i2o_msg_post_wait_mem(c, msg, 60, &buffer);
292 if (status != -ETIMEDOUT)
293 i2o_dma_free(&c->pdev->dev, &buffer);
295 if (status != I2O_POST_WAIT_OK) {
296 // it fails if you try and send frags out of order
297 // and for some yet unknown reasons too
298 osm_info("swdl failed, DetailedStatus = %d\n", status);
305 static int i2o_cfg_swul(unsigned long arg)
307 struct i2o_sw_xfer kxfer;
308 struct i2o_sw_xfer __user *pxfer = (struct i2o_sw_xfer __user *)arg;
309 unsigned char maxfrag = 0, curfrag = 1;
310 struct i2o_dma buffer;
311 struct i2o_message *msg;
312 unsigned int status = 0, swlen = 0, fragsize = 8192;
313 struct i2o_controller *c;
316 if (copy_from_user(&kxfer, pxfer, sizeof(struct i2o_sw_xfer)))
319 if (get_user(swlen, kxfer.swlen) < 0)
322 if (get_user(maxfrag, kxfer.maxfrag) < 0)
325 if (get_user(curfrag, kxfer.curfrag) < 0)
328 if (curfrag == maxfrag)
329 fragsize = swlen - (maxfrag - 1) * 8192;
334 c = i2o_find_iop(kxfer.iop);
338 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
342 if (i2o_dma_alloc(&c->pdev->dev, &buffer, fragsize)) {
347 msg->u.head[0] = cpu_to_le32(NINE_WORD_MSG_SIZE | SGL_OFFSET_7);
349 cpu_to_le32(I2O_CMD_SW_UPLOAD << 24 | HOST_TID << 12 | ADAPTER_TID);
350 msg->u.head[2] = cpu_to_le32(i2o_config_driver.context);
351 msg->u.head[3] = cpu_to_le32(0);
353 cpu_to_le32((u32) kxfer.flags << 24 | (u32) kxfer.
354 sw_type << 16 | (u32) maxfrag << 8 | (u32) curfrag);
355 msg->body[1] = cpu_to_le32(swlen);
356 msg->body[2] = cpu_to_le32(kxfer.sw_id);
357 msg->body[3] = cpu_to_le32(0xD0000000 | fragsize);
358 msg->body[4] = cpu_to_le32(buffer.phys);
360 osm_debug("swul frag %d/%d (size %d)\n", curfrag, maxfrag, fragsize);
361 status = i2o_msg_post_wait_mem(c, msg, 60, &buffer);
363 if (status != I2O_POST_WAIT_OK) {
364 if (status != -ETIMEDOUT)
365 i2o_dma_free(&c->pdev->dev, &buffer);
367 osm_info("swul failed, DetailedStatus = %d\n", status);
371 if (copy_to_user(kxfer.buf, buffer.virt, fragsize))
374 i2o_dma_free(&c->pdev->dev, &buffer);
379 static int i2o_cfg_swdel(unsigned long arg)
381 struct i2o_controller *c;
382 struct i2o_sw_xfer kxfer;
383 struct i2o_sw_xfer __user *pxfer = (struct i2o_sw_xfer __user *)arg;
384 struct i2o_message *msg;
388 if (copy_from_user(&kxfer, pxfer, sizeof(struct i2o_sw_xfer)))
391 if (get_user(swlen, kxfer.swlen) < 0)
394 c = i2o_find_iop(kxfer.iop);
398 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
402 msg->u.head[0] = cpu_to_le32(SEVEN_WORD_MSG_SIZE | SGL_OFFSET_0);
404 cpu_to_le32(I2O_CMD_SW_REMOVE << 24 | HOST_TID << 12 | ADAPTER_TID);
405 msg->u.head[2] = cpu_to_le32(i2o_config_driver.context);
406 msg->u.head[3] = cpu_to_le32(0);
408 cpu_to_le32((u32) kxfer.flags << 24 | (u32) kxfer.sw_type << 16);
409 msg->body[1] = cpu_to_le32(swlen);
410 msg->body[2] = cpu_to_le32(kxfer.sw_id);
412 token = i2o_msg_post_wait(c, msg, 10);
414 if (token != I2O_POST_WAIT_OK) {
415 osm_info("swdel failed, DetailedStatus = %d\n", token);
422 static int i2o_cfg_validate(unsigned long arg)
426 struct i2o_message *msg;
427 struct i2o_controller *c;
429 c = i2o_find_iop(iop);
433 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
437 msg->u.head[0] = cpu_to_le32(FOUR_WORD_MSG_SIZE | SGL_OFFSET_0);
439 cpu_to_le32(I2O_CMD_CONFIG_VALIDATE << 24 | HOST_TID << 12 | iop);
440 msg->u.head[2] = cpu_to_le32(i2o_config_driver.context);
441 msg->u.head[3] = cpu_to_le32(0);
443 token = i2o_msg_post_wait(c, msg, 10);
445 if (token != I2O_POST_WAIT_OK) {
446 osm_info("Can't validate configuration, ErrorStatus = %d\n",
454 static int i2o_cfg_evt_reg(unsigned long arg, struct file *fp)
456 struct i2o_message *msg;
457 struct i2o_evt_id __user *pdesc = (struct i2o_evt_id __user *)arg;
458 struct i2o_evt_id kdesc;
459 struct i2o_controller *c;
460 struct i2o_device *d;
462 if (copy_from_user(&kdesc, pdesc, sizeof(struct i2o_evt_id)))
466 c = i2o_find_iop(kdesc.iop);
471 d = i2o_iop_find_device(c, kdesc.tid);
475 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
479 msg->u.head[0] = cpu_to_le32(FOUR_WORD_MSG_SIZE | SGL_OFFSET_0);
481 cpu_to_le32(I2O_CMD_UTIL_EVT_REGISTER << 24 | HOST_TID << 12 |
483 msg->u.head[2] = cpu_to_le32(i2o_config_driver.context);
484 msg->u.head[3] = cpu_to_le32(i2o_cntxt_list_add(c, fp->private_data));
485 msg->body[0] = cpu_to_le32(kdesc.evt_mask);
487 i2o_msg_post(c, msg);
492 static int i2o_cfg_evt_get(unsigned long arg, struct file *fp)
494 struct i2o_cfg_info *p = NULL;
495 struct i2o_evt_get __user *uget = (struct i2o_evt_get __user *)arg;
496 struct i2o_evt_get kget;
499 for (p = open_files; p; p = p->next)
500 if (p->q_id == (ulong) fp->private_data)
506 memcpy(&kget.info, &p->event_q[p->q_out], sizeof(struct i2o_evt_info));
507 MODINC(p->q_out, I2O_EVT_Q_LEN);
508 spin_lock_irqsave(&i2o_config_lock, flags);
510 kget.pending = p->q_len;
511 kget.lost = p->q_lost;
512 spin_unlock_irqrestore(&i2o_config_lock, flags);
514 if (copy_to_user(uget, &kget, sizeof(struct i2o_evt_get)))
520 static int i2o_cfg_passthru32(struct file *file, unsigned cmnd,
523 struct i2o_cmd_passthru32 __user *cmd;
524 struct i2o_controller *c;
525 u32 __user *user_msg;
527 u32 __user *user_reply = NULL;
531 struct i2o_dma sg_list[SG_TABLESIZE];
536 i2o_status_block *sb;
537 struct i2o_message *msg;
540 cmd = (struct i2o_cmd_passthru32 __user *)arg;
542 if (get_user(iop, &cmd->iop) || get_user(i, &cmd->msg))
545 user_msg = compat_ptr(i);
547 c = i2o_find_iop(iop);
549 osm_debug("controller %d not found\n", iop);
553 sb = c->status_block.virt;
555 if (get_user(size, &user_msg[0])) {
556 osm_warn("unable to get size!\n");
561 if (size > sb->inbound_frame_size) {
562 osm_warn("size of message > inbound_frame_size");
566 user_reply = &user_msg[size];
568 size <<= 2; // Convert to bytes
570 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
575 /* Copy in the user's I2O command */
576 if (copy_from_user(msg, user_msg, size)) {
577 osm_warn("unable to copy user message\n");
580 i2o_dump_message(msg);
582 if (get_user(reply_size, &user_reply[0]) < 0)
589 reply = kzalloc(reply_size, GFP_KERNEL);
591 printk(KERN_WARNING "%s: Could not allocate reply buffer\n",
596 sg_offset = (msg->u.head[0] >> 4) & 0x0f;
598 memset(sg_list, 0, sizeof(sg_list[0]) * SG_TABLESIZE);
600 struct sg_simple_element *sg;
602 if (sg_offset * 4 >= size) {
607 sg = (struct sg_simple_element *)((&msg->u.head[0]) +
610 (size - sg_offset * 4) / sizeof(struct sg_simple_element);
611 if (sg_count > SG_TABLESIZE) {
612 printk(KERN_DEBUG "%s:IOCTL SG List too large (%u)\n",
618 for (i = 0; i < sg_count; i++) {
622 if (!(sg[i].flag_count & 0x10000000
623 /*I2O_SGL_FLAGS_SIMPLE_ADDRESS_ELEMENT */ )) {
625 "%s:Bad SG element %d - not simple (%x)\n",
626 c->name, i, sg[i].flag_count);
630 sg_size = sg[i].flag_count & 0xffffff;
631 p = &(sg_list[sg_index]);
632 /* Allocate memory for the transfer */
633 if (i2o_dma_alloc(&c->pdev->dev, p, sg_size)) {
635 "%s: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
636 c->name, sg_size, i, sg_count);
638 goto sg_list_cleanup;
641 /* Copy in the user's SG buffer if necessary */
643 flag_count & 0x04000000 /*I2O_SGL_FLAGS_DIR */ ) {
647 (void __user *)(unsigned long)sg[i].
648 addr_bus, sg_size)) {
650 "%s: Could not copy SG buf %d FROM user\n",
653 goto sg_list_cleanup;
657 sg[i].addr_bus = (u32) p->phys;
661 rcode = i2o_msg_post_wait(c, msg, 60);
664 reply[4] = ((u32) rcode) << 24;
665 goto sg_list_cleanup;
669 u32 rmsg[I2O_OUTBOUND_MSG_FRAME_SIZE];
670 /* Copy back the Scatter Gather buffers back to user space */
673 struct sg_simple_element *sg;
676 // re-acquire the original message to handle correctly the sg copy operation
677 memset(&rmsg, 0, I2O_OUTBOUND_MSG_FRAME_SIZE * 4);
678 // get user msg size in u32s
679 if (get_user(size, &user_msg[0])) {
681 goto sg_list_cleanup;
685 /* Copy in the user's I2O command */
686 if (copy_from_user(rmsg, user_msg, size)) {
688 goto sg_list_cleanup;
691 (size - sg_offset * 4) / sizeof(struct sg_simple_element);
694 sg = (struct sg_simple_element *)(rmsg + sg_offset);
695 for (j = 0; j < sg_count; j++) {
696 /* Copy out the SG list to user's buffer if necessary */
699 flag_count & 0x4000000 /*I2O_SGL_FLAGS_DIR */ )) {
700 sg_size = sg[j].flag_count & 0xffffff;
703 ((void __user *)(u64) sg[j].addr_bus,
704 sg_list[j].virt, sg_size)) {
706 "%s: Could not copy %p TO user %x\n",
707 c->name, sg_list[j].virt,
710 goto sg_list_cleanup;
717 /* Copy back the reply to user space */
719 // we wrote our own values for context - now restore the user supplied ones
720 if (copy_from_user(reply + 2, user_msg + 2, sizeof(u32) * 2)) {
722 "%s: Could not copy message context FROM user\n",
726 if (copy_to_user(user_reply, reply, reply_size)) {
728 "%s: Could not copy reply TO user\n", c->name);
732 for (i = 0; i < sg_index; i++)
733 i2o_dma_free(&c->pdev->dev, &sg_list[i]);
743 static long i2o_cfg_compat_ioctl(struct file *file, unsigned cmd,
750 ret = i2o_cfg_ioctl(file, cmd, arg);
753 ret = i2o_cfg_passthru32(file, cmd, arg);
765 #ifdef CONFIG_I2O_EXT_ADAPTEC
766 static int i2o_cfg_passthru(unsigned long arg)
768 struct i2o_cmd_passthru __user *cmd =
769 (struct i2o_cmd_passthru __user *)arg;
770 struct i2o_controller *c;
771 u32 __user *user_msg;
773 u32 __user *user_reply = NULL;
777 struct i2o_dma sg_list[SG_TABLESIZE];
782 i2o_status_block *sb;
783 struct i2o_message *msg;
786 if (get_user(iop, &cmd->iop) || get_user(user_msg, &cmd->msg))
789 c = i2o_find_iop(iop);
791 osm_warn("controller %d not found\n", iop);
795 sb = c->status_block.virt;
797 if (get_user(size, &user_msg[0]))
801 if (size > sb->inbound_frame_size) {
802 osm_warn("size of message > inbound_frame_size");
806 user_reply = &user_msg[size];
808 size <<= 2; // Convert to bytes
810 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
815 /* Copy in the user's I2O command */
816 if (copy_from_user(msg, user_msg, size))
819 if (get_user(reply_size, &user_reply[0]) < 0)
825 reply = kzalloc(reply_size, GFP_KERNEL);
827 printk(KERN_WARNING "%s: Could not allocate reply buffer\n",
833 sg_offset = (msg->u.head[0] >> 4) & 0x0f;
835 memset(sg_list, 0, sizeof(sg_list[0]) * SG_TABLESIZE);
837 struct sg_simple_element *sg;
840 if (sg_offset * 4 >= size) {
845 sg = (struct sg_simple_element *)((&msg->u.head[0]) +
848 (size - sg_offset * 4) / sizeof(struct sg_simple_element);
849 if (sg_count > SG_TABLESIZE) {
850 printk(KERN_DEBUG "%s:IOCTL SG List too large (%u)\n",
856 for (i = 0; i < sg_count; i++) {
859 if (!(sg[i].flag_count & 0x10000000
860 /*I2O_SGL_FLAGS_SIMPLE_ADDRESS_ELEMENT */ )) {
862 "%s:Bad SG element %d - not simple (%x)\n",
863 c->name, i, sg[i].flag_count);
865 goto sg_list_cleanup;
867 sg_size = sg[i].flag_count & 0xffffff;
868 p = &(sg_list[sg_index]);
869 if (i2o_dma_alloc(&c->pdev->dev, p, sg_size)) {
870 /* Allocate memory for the transfer */
872 "%s: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
873 c->name, sg_size, i, sg_count);
875 goto sg_list_cleanup;
878 /* Copy in the user's SG buffer if necessary */
880 flag_count & 0x04000000 /*I2O_SGL_FLAGS_DIR */ ) {
883 (p->virt, (void __user *)sg[i].addr_bus,
886 "%s: Could not copy SG buf %d FROM user\n",
889 goto sg_list_cleanup;
892 sg[i].addr_bus = p->phys;
896 rcode = i2o_msg_post_wait(c, msg, 60);
899 reply[4] = ((u32) rcode) << 24;
900 goto sg_list_cleanup;
904 u32 rmsg[I2O_OUTBOUND_MSG_FRAME_SIZE];
905 /* Copy back the Scatter Gather buffers back to user space */
908 struct sg_simple_element *sg;
911 // re-acquire the original message to handle correctly the sg copy operation
912 memset(&rmsg, 0, I2O_OUTBOUND_MSG_FRAME_SIZE * 4);
913 // get user msg size in u32s
914 if (get_user(size, &user_msg[0])) {
916 goto sg_list_cleanup;
920 /* Copy in the user's I2O command */
921 if (copy_from_user(rmsg, user_msg, size)) {
923 goto sg_list_cleanup;
926 (size - sg_offset * 4) / sizeof(struct sg_simple_element);
929 sg = (struct sg_simple_element *)(rmsg + sg_offset);
930 for (j = 0; j < sg_count; j++) {
931 /* Copy out the SG list to user's buffer if necessary */
934 flag_count & 0x4000000 /*I2O_SGL_FLAGS_DIR */ )) {
935 sg_size = sg[j].flag_count & 0xffffff;
938 ((void __user *)sg[j].addr_bus, sg_list[j].virt,
941 "%s: Could not copy %p TO user %x\n",
942 c->name, sg_list[j].virt,
945 goto sg_list_cleanup;
952 /* Copy back the reply to user space */
954 // we wrote our own values for context - now restore the user supplied ones
955 if (copy_from_user(reply + 2, user_msg + 2, sizeof(u32) * 2)) {
957 "%s: Could not copy message context FROM user\n",
961 if (copy_to_user(user_reply, reply, reply_size)) {
963 "%s: Could not copy reply TO user\n", c->name);
968 for (i = 0; i < sg_index; i++)
969 i2o_dma_free(&c->pdev->dev, &sg_list[i]);
983 static long i2o_cfg_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
990 ret = i2o_cfg_getiops(arg);
994 ret = i2o_cfg_gethrt(arg);
998 ret = i2o_cfg_getlct(arg);
1002 ret = i2o_cfg_parms(arg, I2OPARMSET);
1006 ret = i2o_cfg_parms(arg, I2OPARMGET);
1010 ret = i2o_cfg_swdl(arg);
1014 ret = i2o_cfg_swul(arg);
1018 ret = i2o_cfg_swdel(arg);
1022 ret = i2o_cfg_validate(arg);
1026 ret = i2o_cfg_evt_reg(arg, fp);
1030 ret = i2o_cfg_evt_get(arg, fp);
1033 #ifdef CONFIG_I2O_EXT_ADAPTEC
1035 ret = i2o_cfg_passthru(arg);
1040 osm_debug("unknown ioctl called!\n");
1047 static int cfg_open(struct inode *inode, struct file *file)
1049 struct i2o_cfg_info *tmp =
1050 (struct i2o_cfg_info *)kmalloc(sizeof(struct i2o_cfg_info),
1052 unsigned long flags;
1058 file->private_data = (void *)(i2o_cfg_info_id++);
1061 tmp->q_id = (ulong) file->private_data;
1066 tmp->next = open_files;
1068 spin_lock_irqsave(&i2o_config_lock, flags);
1070 spin_unlock_irqrestore(&i2o_config_lock, flags);
1076 static int cfg_fasync(int fd, struct file *fp, int on)
1078 ulong id = (ulong) fp->private_data;
1079 struct i2o_cfg_info *p;
1083 for (p = open_files; p; p = p->next)
1088 ret = fasync_helper(fd, fp, on, &p->fasync);
1093 static int cfg_release(struct inode *inode, struct file *file)
1095 ulong id = (ulong) file->private_data;
1096 struct i2o_cfg_info *p, **q;
1097 unsigned long flags;
1100 spin_lock_irqsave(&i2o_config_lock, flags);
1101 for (q = &open_files; (p = *q) != NULL; q = &p->next) {
1102 if (p->q_id == id) {
1108 spin_unlock_irqrestore(&i2o_config_lock, flags);
1114 static const struct file_operations config_fops = {
1115 .owner = THIS_MODULE,
1116 .llseek = no_llseek,
1117 .unlocked_ioctl = i2o_cfg_ioctl,
1118 #ifdef CONFIG_COMPAT
1119 .compat_ioctl = i2o_cfg_compat_ioctl,
1122 .release = cfg_release,
1123 .fasync = cfg_fasync,
1126 static struct miscdevice i2o_miscdev = {
1132 static int __init i2o_config_old_init(void)
1134 spin_lock_init(&i2o_config_lock);
1136 if (misc_register(&i2o_miscdev) < 0) {
1137 osm_err("can't register device.\n");
1144 static void i2o_config_old_exit(void)
1146 misc_deregister(&i2o_miscdev);
1149 MODULE_AUTHOR("Red Hat Software");