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@redhat.com>:
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>
37 #include <asm/uaccess.h>
39 #define SG_TABLESIZE 30
41 extern int i2o_parm_issue(struct i2o_device *, int, void *, int, void *, int);
43 static int i2o_cfg_ioctl(struct inode *inode, struct file *fp, unsigned int cmd,
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 = (u8 *) 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 = (u8 *) 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 __iomem *msg;
235 unsigned int status = 0, swlen = 0, fragsize = 8192;
236 struct i2o_controller *c;
238 if (copy_from_user(&kxfer, pxfer, sizeof(struct i2o_sw_xfer)))
241 if (get_user(swlen, kxfer.swlen) < 0)
244 if (get_user(maxfrag, kxfer.maxfrag) < 0)
247 if (get_user(curfrag, kxfer.curfrag) < 0)
250 if (curfrag == maxfrag)
251 fragsize = swlen - (maxfrag - 1) * 8192;
253 if (!kxfer.buf || !access_ok(VERIFY_READ, kxfer.buf, fragsize))
256 c = i2o_find_iop(kxfer.iop);
260 m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_MESSAGE_GET);
261 if (m == I2O_QUEUE_EMPTY)
264 if (i2o_dma_alloc(&c->pdev->dev, &buffer, fragsize, GFP_KERNEL)) {
269 __copy_from_user(buffer.virt, kxfer.buf, fragsize);
271 writel(NINE_WORD_MSG_SIZE | SGL_OFFSET_7, &msg->u.head[0]);
272 writel(I2O_CMD_SW_DOWNLOAD << 24 | HOST_TID << 12 | ADAPTER_TID,
274 writel(i2o_config_driver.context, &msg->u.head[2]);
275 writel(0, &msg->u.head[3]);
276 writel((((u32) kxfer.flags) << 24) | (((u32) kxfer.sw_type) << 16) |
277 (((u32) maxfrag) << 8) | (((u32) curfrag)), &msg->body[0]);
278 writel(swlen, &msg->body[1]);
279 writel(kxfer.sw_id, &msg->body[2]);
280 writel(0xD0000000 | fragsize, &msg->body[3]);
281 writel(buffer.phys, &msg->body[4]);
283 osm_debug("swdl frag %d/%d (size %d)\n", curfrag, maxfrag, fragsize);
284 status = i2o_msg_post_wait_mem(c, m, 60, &buffer);
286 if (status != -ETIMEDOUT)
287 i2o_dma_free(&c->pdev->dev, &buffer);
289 if (status != I2O_POST_WAIT_OK) {
290 // it fails if you try and send frags out of order
291 // and for some yet unknown reasons too
292 osm_info("swdl failed, DetailedStatus = %d\n", status);
299 static int i2o_cfg_swul(unsigned long arg)
301 struct i2o_sw_xfer kxfer;
302 struct i2o_sw_xfer __user *pxfer = (struct i2o_sw_xfer __user *)arg;
303 unsigned char maxfrag = 0, curfrag = 1;
304 struct i2o_dma buffer;
305 struct i2o_message __iomem *msg;
307 unsigned int status = 0, swlen = 0, fragsize = 8192;
308 struct i2o_controller *c;
311 if (copy_from_user(&kxfer, pxfer, sizeof(struct i2o_sw_xfer)))
314 if (get_user(swlen, kxfer.swlen) < 0)
317 if (get_user(maxfrag, kxfer.maxfrag) < 0)
320 if (get_user(curfrag, kxfer.curfrag) < 0)
323 if (curfrag == maxfrag)
324 fragsize = swlen - (maxfrag - 1) * 8192;
329 c = i2o_find_iop(kxfer.iop);
333 m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_MESSAGE_GET);
334 if (m == I2O_QUEUE_EMPTY)
337 if (i2o_dma_alloc(&c->pdev->dev, &buffer, fragsize, GFP_KERNEL)) {
342 writel(NINE_WORD_MSG_SIZE | SGL_OFFSET_7, &msg->u.head[0]);
343 writel(I2O_CMD_SW_UPLOAD << 24 | HOST_TID << 12 | ADAPTER_TID,
345 writel(i2o_config_driver.context, &msg->u.head[2]);
346 writel(0, &msg->u.head[3]);
347 writel((u32) kxfer.flags << 24 | (u32) kxfer.
348 sw_type << 16 | (u32) maxfrag << 8 | (u32) curfrag,
350 writel(swlen, &msg->body[1]);
351 writel(kxfer.sw_id, &msg->body[2]);
352 writel(0xD0000000 | fragsize, &msg->body[3]);
353 writel(buffer.phys, &msg->body[4]);
355 osm_debug("swul frag %d/%d (size %d)\n", curfrag, maxfrag, fragsize);
356 status = i2o_msg_post_wait_mem(c, m, 60, &buffer);
358 if (status != I2O_POST_WAIT_OK) {
359 if (status != -ETIMEDOUT)
360 i2o_dma_free(&c->pdev->dev, &buffer);
362 osm_info("swul failed, DetailedStatus = %d\n", status);
366 if (copy_to_user(kxfer.buf, buffer.virt, fragsize))
369 i2o_dma_free(&c->pdev->dev, &buffer);
378 static int i2o_cfg_swdel(unsigned long arg)
380 struct i2o_controller *c;
381 struct i2o_sw_xfer kxfer;
382 struct i2o_sw_xfer __user *pxfer = (struct i2o_sw_xfer __user *)arg;
383 struct i2o_message __iomem *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 m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_MESSAGE_GET);
399 if (m == I2O_QUEUE_EMPTY)
402 writel(SEVEN_WORD_MSG_SIZE | SGL_OFFSET_0, &msg->u.head[0]);
403 writel(I2O_CMD_SW_REMOVE << 24 | HOST_TID << 12 | ADAPTER_TID,
405 writel(i2o_config_driver.context, &msg->u.head[2]);
406 writel(0, &msg->u.head[3]);
407 writel((u32) kxfer.flags << 24 | (u32) kxfer.sw_type << 16,
409 writel(swlen, &msg->body[1]);
410 writel(kxfer.sw_id, &msg->body[2]);
412 token = i2o_msg_post_wait(c, m, 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 __iomem *msg;
428 struct i2o_controller *c;
430 c = i2o_find_iop(iop);
434 m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_MESSAGE_GET);
435 if (m == I2O_QUEUE_EMPTY)
438 writel(FOUR_WORD_MSG_SIZE | SGL_OFFSET_0, &msg->u.head[0]);
439 writel(I2O_CMD_CONFIG_VALIDATE << 24 | HOST_TID << 12 | iop,
441 writel(i2o_config_driver.context, &msg->u.head[2]);
442 writel(0, &msg->u.head[3]);
444 token = i2o_msg_post_wait(c, m, 10);
446 if (token != I2O_POST_WAIT_OK) {
447 osm_info("Can't validate configuration, ErrorStatus = %d\n",
455 static int i2o_cfg_evt_reg(unsigned long arg, struct file *fp)
457 struct i2o_message __iomem *msg;
459 struct i2o_evt_id __user *pdesc = (struct i2o_evt_id __user *)arg;
460 struct i2o_evt_id kdesc;
461 struct i2o_controller *c;
462 struct i2o_device *d;
464 if (copy_from_user(&kdesc, pdesc, sizeof(struct i2o_evt_id)))
468 c = i2o_find_iop(kdesc.iop);
473 d = i2o_iop_find_device(c, kdesc.tid);
477 m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_MESSAGE_GET);
478 if (m == I2O_QUEUE_EMPTY)
481 writel(FOUR_WORD_MSG_SIZE | SGL_OFFSET_0, &msg->u.head[0]);
482 writel(I2O_CMD_UTIL_EVT_REGISTER << 24 | HOST_TID << 12 | kdesc.tid,
484 writel(i2o_config_driver.context, &msg->u.head[2]);
485 writel(i2o_cntxt_list_add(c, fp->private_data), &msg->u.head[3]);
486 writel(kdesc.evt_mask, &msg->body[0]);
493 static int i2o_cfg_evt_get(unsigned long arg, struct file *fp)
495 struct i2o_cfg_info *p = NULL;
496 struct i2o_evt_get __user *uget = (struct i2o_evt_get __user *)arg;
497 struct i2o_evt_get kget;
500 for (p = open_files; p; p = p->next)
501 if (p->q_id == (ulong) fp->private_data)
507 memcpy(&kget.info, &p->event_q[p->q_out], sizeof(struct i2o_evt_info));
508 MODINC(p->q_out, I2O_EVT_Q_LEN);
509 spin_lock_irqsave(&i2o_config_lock, flags);
511 kget.pending = p->q_len;
512 kget.lost = p->q_lost;
513 spin_unlock_irqrestore(&i2o_config_lock, flags);
515 if (copy_to_user(uget, &kget, sizeof(struct i2o_evt_get)))
520 #ifdef CONFIG_I2O_EXT_ADAPTEC
522 static int i2o_cfg_passthru32(struct file *file, unsigned cmnd, unsigned long arg)
524 struct i2o_cmd_passthru32 __user *cmd;
525 struct i2o_controller *c;
526 u32 __user *user_msg;
528 u32 __user *user_reply = NULL;
532 struct i2o_dma sg_list[SG_TABLESIZE];
537 i2o_status_block *sb;
538 struct i2o_message *msg;
542 cmd = (struct i2o_cmd_passthru32 __user *)arg;
544 if (get_user(iop, &cmd->iop) || get_user(i, &cmd->msg))
547 user_msg = compat_ptr(i);
549 c = i2o_find_iop(iop);
551 osm_debug("controller %d not found\n", iop);
555 m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_MESSAGE_GET);
557 sb = c->status_block.virt;
559 if (get_user(size, &user_msg[0])) {
560 osm_warn("unable to get size!\n");
565 if (size > sb->inbound_frame_size) {
566 osm_warn("size of message > inbound_frame_size");
570 user_reply = &user_msg[size];
572 size <<= 2; // Convert to bytes
574 /* Copy in the user's I2O command */
575 if (copy_from_user(msg, user_msg, size)) {
576 osm_warn("unable to copy user message\n");
579 i2o_dump_message(msg);
581 if (get_user(reply_size, &user_reply[0]) < 0)
587 reply = kmalloc(reply_size, GFP_KERNEL);
589 printk(KERN_WARNING "%s: Could not allocate reply buffer\n",
593 memset(reply, 0, reply_size);
595 sg_offset = (msg->u.head[0] >> 4) & 0x0f;
597 writel(i2o_config_driver.context, &msg->u.s.icntxt);
598 writel(i2o_cntxt_list_add(c, reply), &msg->u.s.tcntxt);
600 memset(sg_list, 0, sizeof(sg_list[0]) * SG_TABLESIZE);
602 struct sg_simple_element *sg;
604 if (sg_offset * 4 >= size) {
609 sg = (struct sg_simple_element *)((&msg->u.head[0]) +
612 (size - sg_offset * 4) / sizeof(struct sg_simple_element);
613 if (sg_count > SG_TABLESIZE) {
614 printk(KERN_DEBUG "%s:IOCTL SG List too large (%u)\n",
620 for (i = 0; i < sg_count; i++) {
624 if (!(sg[i].flag_count & 0x10000000
625 /*I2O_SGL_FLAGS_SIMPLE_ADDRESS_ELEMENT */ )) {
627 "%s:Bad SG element %d - not simple (%x)\n",
628 c->name, i, sg[i].flag_count);
632 sg_size = sg[i].flag_count & 0xffffff;
633 p = &(sg_list[sg_index++]);
634 /* Allocate memory for the transfer */
636 (&c->pdev->dev, p, sg_size,
637 PCI_DMA_BIDIRECTIONAL)) {
639 "%s: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
640 c->name, sg_size, i, sg_count);
642 goto sg_list_cleanup;
644 /* Copy in the user's SG buffer if necessary */
646 flag_count & 0x04000000 /*I2O_SGL_FLAGS_DIR */ ) {
649 (p->virt, (void __user *)(unsigned long)sg[i].addr_bus,
652 "%s: Could not copy SG buf %d FROM user\n",
655 goto sg_list_cleanup;
659 sg[i].addr_bus = (u32) p->phys;
663 rcode = i2o_msg_post_wait(c, m, 60);
665 goto sg_list_cleanup;
668 u32 msg[I2O_OUTBOUND_MSG_FRAME_SIZE];
669 /* Copy back the Scatter Gather buffers back to user space */
672 struct sg_simple_element *sg;
675 // re-acquire the original message to handle correctly the sg copy operation
676 memset(&msg, 0, I2O_OUTBOUND_MSG_FRAME_SIZE * 4);
677 // get user msg size in u32s
678 if (get_user(size, &user_msg[0])) {
680 goto sg_list_cleanup;
684 /* Copy in the user's I2O command */
685 if (copy_from_user(msg, user_msg, size)) {
687 goto sg_list_cleanup;
690 (size - sg_offset * 4) / sizeof(struct sg_simple_element);
693 sg = (struct sg_simple_element *)(msg + sg_offset);
694 for (j = 0; j < sg_count; j++) {
695 /* Copy out the SG list to user's buffer if necessary */
698 flag_count & 0x4000000 /*I2O_SGL_FLAGS_DIR */ )) {
699 sg_size = sg[j].flag_count & 0xffffff;
702 ((void __user *)(u64) sg[j].addr_bus,
703 sg_list[j].virt, sg_size)) {
705 "%s: Could not copy %p TO user %x\n",
706 c->name, sg_list[j].virt,
709 goto sg_list_cleanup;
715 /* Copy back the reply to user space */
717 // we wrote our own values for context - now restore the user supplied ones
718 if (copy_from_user(reply + 2, user_msg + 2, sizeof(u32) * 2)) {
720 "%s: Could not copy message context FROM user\n",
723 goto sg_list_cleanup;
725 if (copy_to_user(user_reply, reply, reply_size)) {
727 "%s: Could not copy reply TO user\n", c->name);
733 for (i = 0; i < sg_index; i++)
734 i2o_dma_free(&c->pdev->dev, &sg_list[i]);
741 static long i2o_cfg_compat_ioctl(struct file *file, unsigned cmd, unsigned long arg)
747 ret = i2o_cfg_ioctl(NULL, file, cmd, arg);
750 ret = i2o_cfg_passthru32(file, cmd, arg);
762 static int i2o_cfg_passthru(unsigned long arg)
764 struct i2o_cmd_passthru __user *cmd =
765 (struct i2o_cmd_passthru __user *)arg;
766 struct i2o_controller *c;
767 u32 __user *user_msg;
769 u32 __user *user_reply = NULL;
773 void *sg_list[SG_TABLESIZE];
779 i2o_status_block *sb;
780 struct i2o_message __iomem *msg;
784 if (get_user(iop, &cmd->iop) || get_user(user_msg, &cmd->msg))
787 c = i2o_find_iop(iop);
789 osm_warn("controller %d not found\n", iop);
793 m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_MESSAGE_GET);
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 /* Copy in the user's I2O command */
811 if (copy_from_user(msg, user_msg, size))
814 if (get_user(reply_size, &user_reply[0]) < 0)
820 reply = kmalloc(reply_size, GFP_KERNEL);
822 printk(KERN_WARNING "%s: Could not allocate reply buffer\n",
826 memset(reply, 0, reply_size);
828 sg_offset = (msg->u.head[0] >> 4) & 0x0f;
830 writel(i2o_config_driver.context, &msg->u.s.icntxt);
831 writel(i2o_cntxt_list_add(c, reply), &msg->u.s.tcntxt);
833 memset(sg_list, 0, sizeof(sg_list[0]) * SG_TABLESIZE);
835 struct sg_simple_element *sg;
837 if (sg_offset * 4 >= size) {
842 sg = (struct sg_simple_element *)((&msg->u.head[0]) +
845 (size - sg_offset * 4) / sizeof(struct sg_simple_element);
846 if (sg_count > SG_TABLESIZE) {
847 printk(KERN_DEBUG "%s:IOCTL SG List too large (%u)\n",
853 for (i = 0; i < sg_count; i++) {
856 if (!(sg[i].flag_count & 0x10000000
857 /*I2O_SGL_FLAGS_SIMPLE_ADDRESS_ELEMENT */ )) {
859 "%s:Bad SG element %d - not simple (%x)\n",
860 c->name, i, sg[i].flag_count);
862 goto sg_list_cleanup;
864 sg_size = sg[i].flag_count & 0xffffff;
865 /* Allocate memory for the transfer */
866 p = kmalloc(sg_size, GFP_KERNEL);
869 "%s: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
870 c->name, sg_size, i, sg_count);
872 goto sg_list_cleanup;
874 sg_list[sg_index++] = p; // sglist indexed with input frame, not our internal frame.
875 /* Copy in the user's SG buffer if necessary */
877 flag_count & 0x04000000 /*I2O_SGL_FLAGS_DIR */ ) {
880 (p, (void __user *)sg[i].addr_bus,
883 "%s: Could not copy SG buf %d FROM user\n",
886 goto sg_list_cleanup;
890 sg[i].addr_bus = virt_to_bus(p);
894 rcode = i2o_msg_post_wait(c, m, 60);
896 goto sg_list_cleanup;
900 /* Copy back the Scatter Gather buffers back to user space */
903 struct sg_simple_element *sg;
906 // re-acquire the original message to handle correctly the sg copy operation
907 memset(&msg, 0, I2O_OUTBOUND_MSG_FRAME_SIZE * 4);
908 // get user msg size in u32s
909 if (get_user(size, &user_msg[0])) {
911 goto sg_list_cleanup;
915 /* Copy in the user's I2O command */
916 if (copy_from_user(msg, user_msg, size)) {
918 goto sg_list_cleanup;
921 (size - sg_offset * 4) / sizeof(struct sg_simple_element);
924 sg = (struct sg_simple_element *)(msg + sg_offset);
925 for (j = 0; j < sg_count; j++) {
926 /* Copy out the SG list to user's buffer if necessary */
929 flag_count & 0x4000000 /*I2O_SGL_FLAGS_DIR */ )) {
930 sg_size = sg[j].flag_count & 0xffffff;
933 ((void __user *)sg[j].addr_bus, sg_list[j],
936 "%s: Could not copy %p TO user %x\n",
940 goto sg_list_cleanup;
946 /* Copy back the reply to user space */
948 // we wrote our own values for context - now restore the user supplied ones
949 if (copy_from_user(reply + 2, user_msg + 2, sizeof(u32) * 2)) {
951 "%s: Could not copy message context FROM user\n",
955 if (copy_to_user(user_reply, reply, reply_size)) {
957 "%s: Could not copy reply TO user\n", c->name);
963 for (i = 0; i < sg_index; i++)
975 static int i2o_cfg_ioctl(struct inode *inode, struct file *fp, unsigned int cmd,
982 ret = i2o_cfg_getiops(arg);
986 ret = i2o_cfg_gethrt(arg);
990 ret = i2o_cfg_getlct(arg);
994 ret = i2o_cfg_parms(arg, I2OPARMSET);
998 ret = i2o_cfg_parms(arg, I2OPARMGET);
1002 ret = i2o_cfg_swdl(arg);
1006 ret = i2o_cfg_swul(arg);
1010 ret = i2o_cfg_swdel(arg);
1014 ret = i2o_cfg_validate(arg);
1018 ret = i2o_cfg_evt_reg(arg, fp);
1022 ret = i2o_cfg_evt_get(arg, fp);
1025 #ifdef CONFIG_I2O_EXT_ADAPTEC
1027 ret = i2o_cfg_passthru(arg);
1032 osm_debug("unknown ioctl called!\n");
1039 static int cfg_open(struct inode *inode, struct file *file)
1041 struct i2o_cfg_info *tmp =
1042 (struct i2o_cfg_info *)kmalloc(sizeof(struct i2o_cfg_info),
1044 unsigned long flags;
1049 file->private_data = (void *)(i2o_cfg_info_id++);
1052 tmp->q_id = (ulong) file->private_data;
1057 tmp->next = open_files;
1059 spin_lock_irqsave(&i2o_config_lock, flags);
1061 spin_unlock_irqrestore(&i2o_config_lock, flags);
1066 static int cfg_fasync(int fd, struct file *fp, int on)
1068 ulong id = (ulong) fp->private_data;
1069 struct i2o_cfg_info *p;
1071 for (p = open_files; p; p = p->next)
1078 return fasync_helper(fd, fp, on, &p->fasync);
1081 static int cfg_release(struct inode *inode, struct file *file)
1083 ulong id = (ulong) file->private_data;
1084 struct i2o_cfg_info *p1, *p2;
1085 unsigned long flags;
1090 spin_lock_irqsave(&i2o_config_lock, flags);
1091 for (p1 = open_files; p1;) {
1092 if (p1->q_id == id) {
1095 cfg_fasync(-1, file, 0);
1097 p2->next = p1->next;
1099 open_files = p1->next;
1107 spin_unlock_irqrestore(&i2o_config_lock, flags);
1113 static struct file_operations config_fops = {
1114 .owner = THIS_MODULE,
1115 .llseek = no_llseek,
1116 .ioctl = i2o_cfg_ioctl,
1117 #ifdef CONFIG_COMPAT
1118 .compat_ioctl = i2o_cfg_compat_ioctl,
1121 .release = cfg_release,
1122 .fasync = cfg_fasync,
1125 static struct miscdevice i2o_miscdev = {
1131 static int __init i2o_config_old_init(void)
1133 spin_lock_init(&i2o_config_lock);
1135 if (misc_register(&i2o_miscdev) < 0) {
1136 osm_err("can't register device.\n");
1142 static void i2o_config_old_exit(void)
1144 misc_deregister(&i2o_miscdev);
1147 MODULE_AUTHOR("Red Hat Software");